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 the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.