[Email-SIG] fixing the current email module
Barry Warsaw
barry at python.org
Thu Oct 8 21:49:58 CEST 2009
On Oct 8, 2009, at 11:09 AM, Stephen J. Turnbull wrote:
> Barry Warsaw writes:
>
>>>>> from email import message_from_string
>>>>> with open('/dev/urandom') as wire:
>> ... data = wire.read(1024)
>> ...
>
> # insert A
>
>>>>> msg = message_from_string(data)
>>>>> # number of headers
>> ... len(msg)
>> 0
>>>>> len(msg.get_payload())
>> 1024
>>>>> msg.defects
>> []
>>
>> This actually makes perfect sense. A message with no headers and a
>> mass of 1024 bytes in its payload is RFC valid!
>
> If you insert at A
>
>>>> wire = "".join(chr(ord(ch) & 127) for ch in wire)
>>>> # optional with reasonably high probability:
>>>> wire = wire[0:512] + "\r\n" + wire[512:1024]
>
> or similar. Otherwise not. ;-)
Right! That makes it legal.
What's interesting of course is that the parser can (and I submit,
still should) handle the stream even without that.
-Barry
-------------- 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/58c71503/attachment-0001.pgp>
More information about the Email-SIG
mailing list