[Email-SIG] fixing the current email module

Barry Warsaw barry at python.org
Thu Oct 8 15:14:05 CEST 2009

On Oct 8, 2009, at 5:18 AM, Oleg Broytman wrote:

>   Are you going to parse any garbage and create a Message (probably an
> empty Message) with one defect "cannot parse it at all"?

Yes, although the most pathological stream of bytes will probably  
produce a message with no headers and an undecodeable body of  
gibberish bytes, with a .defects list possible one or two items long.

>   What I disagree with is that if a parser cannot parse input  
> garbage at
> all it must raise an exception. And if a parser can raise an  
> exception any
> calling program must be prepared to catch such exceptions.

Python 2.6.3 (r263:75183, Oct  4 2009, 19:57:34)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> from email import message_from_string
 >>> with open('/dev/urandom') as wire:
...   data = wire.read(1024)
 >>> msg = message_from_string(data)
 >>> # number of headers
... len(msg)
 >>> len(msg.get_payload())
 >>> msg.defects

This actually makes perfect sense.  A message with no headers and a  
mass of 1024 bytes in its payload is RFC valid!


-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 832 bytes
Desc: This is a digitally signed message part
URL: <http://mail.python.org/pipermail/email-sig/attachments/20091008/c89d9243/attachment.pgp>

More information about the Email-SIG mailing list