14.6. Processing an E-mail Message by Using the rfc822 Module

The two functions DoLinuxMailBox and DoEudoraMailBox chop up mailboxes into individual messages that are processed by the ProcessMessage function. This function uses the rfc822 module to separate the headers from the body of the message.

 CD-ROM reference=14007.txt def ProcessMessage(lines,out): """ Given the lines that make up an e-mail message, create an XML message element. Uses the rfc822 module to parse the e-mail headers. """ out.write("<message>\n") # Create a single string from these lines. MessageString = string.joinfields(lines,"") # Create a file object from the string for use # by the rfc822 module. fo = StringIO.StringIO(MessageString) m = rfc822.Message (fo) # The m object ...

Get XML Processing with Python now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.