Example #1
0
    def process(self, message):
        """Takes a mail message with one or more attachments and stores the attachments
        in a directory specified by config['whispher_storage_path']

        The message must be a multipart message with a 'text/plain' part and one or more attachments.
        The 'text/plain' part must begin with the correct carbon validation key.
        If the message is not in this format, it will be dropped."""

        whisper_file_handled = False

        # If message is multipart we only want the text version of the body,
        # this walks the message and gets the body.
        # multipart means dual html and text representations
        if message.get_content_maintype() == 'multipart':
            for part in message.walk():
                if part.get_content_type() == "text/plain":
                    body = part.get_payload(decode=True)
                    # Check if this is the relevant part of the message
                    if body.startswith(self.config['email_body_validation_key']):
                        # Re-walk the parts to retrieve the attachments
                        for p in message.walk():
                            if p.get('Content-Disposition') is None or p.get_content_maintype() == 'multipart':
                                continue

                            filename = p.get_filename()
                            file_data = p.get_payload(decode=True)
                            self.handle_whisper_file(filename, file_data)

                            whisper_file_handled = True
                        break
        if not whisper_file_handled:
            log.warning("Message is not in the correct format to be processed by CarbonEmailProcessor, even though it's subject line indicates that it ought to be. Dropping mail.")
Example #2
0
    def process(self, message):
        """Takes a mail message, parses the relevant part, and sends the parsed
        data to Sentry using the Raven client.

        The message must be a multipart message with a 'text/plain' part. This 'text/plain'
        part must begin with the correct sentry validation key, followed by json data.
        If the message is not in this format, it will be dropped."""

        raised = False

        # If message is multipart we only want the text version of the body,
        # this walks the message and gets the body.
        # multipart means dual html and text representations
        if message.get_content_maintype() == 'multipart':
            for part in message.walk():
                if part.get_content_type() == "text/plain":
                    body = part.get_payload(decode=True)
                    # Check if this is the relevant part of the message
                    if body.startswith(self.validation_key):
                        json_ = self.parse_json_message(body[self.validation_key.__len__()+1:])
                        self.raise_to_sentry(json_)
                        raised = True
                        break
        if not raised:
            log.warning("Message is not in the correct format to be processed by SentryEmailProcessor, even though it's subject line indicates that it ought to be. Dropping mail.")