Author HJarausch
Recipients HJarausch
Date 2012-12-29.10:23:14
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
The following code triggers the bug:

#-*- coding: latin1 -*-
from email.message import Message
from email import policy
from email.parser import FeedParser

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

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

This triggers
  File "", line 13, in <module>
    Msg_as_str= Msg.as_string(unixfrom=True)
  File "/usr/lib64/python3.3/email/", line 151, in as_string
    g.flatten(self, unixfrom=unixfrom)
  File "/usr/lib64/python3.3/email/", line 112, in flatten
  File "/usr/lib64/python3.3/email/", line 171, in _write
  File "/usr/lib64/python3.3/email/", line 198, in _write_headers
    self.write(self.policy.fold(h, v))
  File "/usr/lib64/python3.3/email/", line 153, in fold
    return self._fold(name, value, refold_binary=True)
  File "/usr/lib64/python3.3/email/", 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,

This is with  Python 3.3.0+ 3.3:ccc372b37fbb+
Date User Action Args
2012-12-29 10:23:14HJarauschsetrecipients: + HJarausch
2012-12-29 10:23:14HJarauschsetmessageid: <>
2012-12-29 10:23:14HJarauschlinkissue16811 messages
2012-12-29 10:23:14HJarauschcreate