Exemplo n.º 1
0
 def _process_single_node(self, node):
     """
     Extract the contents of a single XML dump node
     :param node: The XML node corresponding to a message
     :return: An EmailMessage instance containing the message contents
     """
     text = unicode(node.find('text').text)
     text = unicode.lstrip(text, u'>')  # remove leading char that got into the text somehow
     if use_full_parser(text):
         text = fix_broken_hotmail_headers(text)
         parser = Parser()
         mime_message = parser.parse(StringIO(text))
         return_message = get_nested_payload(mime_message)
     else:
         return_message = EmailMessage()
         subject_node = node.find('subject')
         from_node = node.find('from')
         to_node = node.find('to')
         date_node = node.find('receivedat')
         subject = unicode(subject_node.text, 'utf-8') if not subject_node is None else ''
         sender = clean_sender('{} <{}>'.format(from_node.find('name').text, from_node.find('email').text))
         recipient = clean_recipient('{} <{}>'.format(to_node.find('name').text, to_node.find('email').text))
         date_string = '{} {}'.format(date_node.find('date').text, date_node.find('time').text)
         return_message.append_body(unicode(text))
         return_message.subject = subject
         return_message.sender = sender
         return_message.recipient = recipient
         return_message.date = parse(date_string)
         return_message.date = normalize_to_utc(return_message.date, self._timezone)
     return_message.source = "XML File {} node {}".format(self._process_path, node.attrib)
     return return_message
 def process(self):
     """
     Processes EML file content found in the instance's directory.
     :return: A list of EmailMessage objects parsed from the directory contents
     """
     output_contents = []
     for file_name in os.listdir(self._process_directory):
         if file_name == '.DS_Store':
             continue  # Skip these files on OSX systems
         message = self._process_multipart_eml(os.path.join(self._process_directory, file_name))
         message.date = normalize_to_utc(message.date, self._timezone)
         output_contents.append(message)
         for callback in self._callbacks.values():
             callback(message)
     return output_contents
 def process(self):
     """
     Processes EML file content found in the instance's directory.
     :return: A list of EmailMessage objects parsed from the directory contents
     """
     output_contents = []
     for file_name in os.listdir(self._process_directory):
         if file_name == '.DS_Store':
             continue  # Skip these files on OSX systems
         message = self._process_multipart_eml(
             os.path.join(self._process_directory, file_name))
         message.date = normalize_to_utc(message.date, self._timezone)
         output_contents.append(message)
         for callback in self._callbacks.values():
             callback(message)
     return output_contents
Exemplo n.º 4
0
 def _process_single_node(self, node):
     """
     Extract the contents of a single XML dump node
     :param node: The XML node corresponding to a message
     :return: An EmailMessage instance containing the message contents
     """
     text = unicode(node.find('text').text)
     text = unicode.lstrip(
         text, u'>')  # remove leading char that got into the text somehow
     if use_full_parser(text):
         text = fix_broken_hotmail_headers(text)
         parser = Parser()
         mime_message = parser.parse(StringIO(text))
         return_message = get_nested_payload(mime_message)
     else:
         return_message = EmailMessage()
         subject_node = node.find('subject')
         from_node = node.find('from')
         to_node = node.find('to')
         date_node = node.find('receivedat')
         subject = unicode(subject_node.text,
                           'utf-8') if not subject_node is None else ''
         sender = clean_sender('{} <{}>'.format(
             from_node.find('name').text,
             from_node.find('email').text))
         recipient = clean_recipient('{} <{}>'.format(
             to_node.find('name').text,
             to_node.find('email').text))
         date_string = '{} {}'.format(
             date_node.find('date').text,
             date_node.find('time').text)
         return_message.append_body(unicode(text))
         return_message.subject = subject
         return_message.sender = sender
         return_message.recipient = recipient
         return_message.date = parse(date_string)
         return_message.date = normalize_to_utc(return_message.date,
                                                self._timezone)
     return_message.source = "XML File {} node {}".format(
         self._process_path, node.attrib)
     return return_message