On May 27, 2010, at 08:59 PM, Tres Seaver wrote:
>Barry Warsaw wrote:
>> On May 27, 2010, at 10:25 AM, Sridhar Ratnakumar wrote:
>>
>>> Is there a way to parse a RFC 822 message in Python 3?
>>
>> If it's ASCII, you should have no problems using email.parser.Parser.
>
>The issue is that its behavior is subtly different from the now-removed
>rfc822 parser::
>
> $ /opt/Python-2.6.5/bin/python
> Python 2.6.5 (r265:79063, Apr 6 2010, 14:45:18)
> [GCC 4.3.3] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> from StringIO import StringIO
> >>> with_multiline = StringIO("""\
> ... Description: this is a multiline RFC 822
> ... header.""")
> >>> from rfc822 import Message
> >>> rfc_msg = Message(with_multiline)
> >>> with_multiline.seek(0)
> >>> from email.parser import Parser
> >>> email_msg = Parser().parse(with_multiline)
> >>> rfc_msg.getheader('Description')
> 'this is a multiline RFC 822\n header.'
> >>> email_msg.get('Description')
> 'this is a multiline RFC 822\n header.'If I'm reading this correctly, the "problem" is that rfc822 collapses continuation whitespace and email.parser preserves it? Isn't the email package (more) correct, and what specific problem does that cause? Or is it just that it's different so tools have to catch up to that? -Barry
signature.asc
Description: PGP signature
_______________________________________________ Distutils-SIG maillist - [email protected] http://mail.python.org/mailman/listinfo/distutils-sig
