This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author HJarausch
Recipients HJarausch
Date 2012-12-29.10:23:14
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1356776594.55.0.534961583044.issue16811@psf.upfronthosting.co.za>
In-reply-to
Content
The following code triggers the bug:

#!/usr/bin/python3.3
#-*- coding: latin1 -*-
from email.message import Message
from email import policy
from email.parser import FeedParser

Parser= FeedParser(policy=policy.SMTP)
Parser.feed('From jarausch@igpm.rwth-aachen.de  Tue Apr 24 15:09:24 2012\n')
Parser.feed('X-Status:    \n')  # this triggers the bug
Parser.feed('From: Helmut Jarausch <jarausch@igpm.rwth-aachen.de>\n')

Msg= Parser.close()
Msg_as_str= Msg.as_string(unixfrom=True)

This triggers
  File "Email_Parse_Bug.py", line 13, in <module>
    Msg_as_str= Msg.as_string(unixfrom=True)
  File "/usr/lib64/python3.3/email/message.py", line 151, in as_string
    g.flatten(self, unixfrom=unixfrom)
  File "/usr/lib64/python3.3/email/generator.py", line 112, in flatten
    self._write(msg)
  File "/usr/lib64/python3.3/email/generator.py", line 171, in _write
    self._write_headers(msg)
  File "/usr/lib64/python3.3/email/generator.py", line 198, in _write_headers
    self.write(self.policy.fold(h, v))
  File "/usr/lib64/python3.3/email/policy.py", line 153, in fold
    return self._fold(name, value, refold_binary=True)
  File "/usr/lib64/python3.3/email/policy.py", line 176, in _fold
    (len(lines[0])+len(name)+2 > maxlen or
IndexError: list index out of range


If I strip the '\n' from the lines feeded to the Parser,
the bug does not occur.

Thanks for looking into it,
Helmut.

This is with  Python 3.3.0+ 3.3:ccc372b37fbb+
History
Date User Action Args
2012-12-29 10:23:14HJarauschsetrecipients: + HJarausch
2012-12-29 10:23:14HJarauschsetmessageid: <1356776594.55.0.534961583044.issue16811@psf.upfronthosting.co.za>
2012-12-29 10:23:14HJarauschlinkissue16811 messages
2012-12-29 10:23:14HJarauschcreate