O'Reilly logo

XML Processing with Python by Sean McGrath

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required