<p dir="ltr">On Dec 28, 2012 4:26 AM, "Helmut Jarausch" <<a href="mailto:jarausch@igpm.rwth-aachen.de">jarausch@igpm.rwth-aachen.de</a>> wrote:<br>
><br>
> Hi,<br>
><br>
> I'm trying to filter an mbox file by removing some messages.<br>
> For that I use<br>
> Parser= FeedParser(policy=policy.SMTP)<br>
> and 'feed' any lines to it.<br>
> If the mbox file contains a white line followed by '^From ',<br>
> I do<br>
><br>
> Msg= Parser.close()<br>
><br>
> (lateron I delete the Parser and create a new one by<br>
> Parser= FeedParser(policy=policy.SMTP)<br>
> )<br>
><br>
> I can access parts of the message by Msg['Message-ID'], e.g.<br>
> but even for the very first message, trying to print it or convert it to a string<br>
> by MsgStr=Msg.as_string(unixfrom=True)<br>
><br>
> lets Python (3.3.1_pre20121209) die with<br>
><br>
> Traceback (most recent call last):<br>
> File "Email_Parse.py", line 35, in <module><br>
> MsgStr=Msg.as_string(unixfrom=True)<br>
> File "/usr/lib64/python3.3/email/message.py", line 151, in as_string<br>
> g.flatten(self, unixfrom=unixfrom)<br>
> File "/usr/lib64/python3.3/email/generator.py", line 112, in flatten<br>
> self._write(msg)<br>
> File "/usr/lib64/python3.3/email/generator.py", line 171, in _write<br>
> self._write_headers(msg)<br>
> File "/usr/lib64/python3.3/email/generator.py", line 198, in _write_headers<br>
> self.write(self.policy.fold(h, v))<br>
> File "/usr/lib64/python3.3/email/policy.py", line 153, in fold<br>
> return self._fold(name, value, refold_binary=True)<br>
> File "/usr/lib64/python3.3/email/policy.py", line 176, in _fold<br>
> (len(lines[0])+len(name)+2 > maxlen or<br>
> IndexError: list index out of range<br>
><br>
><br>
> What am I missing?</p>
<p dir="ltr">Perhaps the message is malformed. What does Msg.defects give you?</p>
<p dir="ltr">Could you post the line strings you fed to the parser that together constitute the first message (redacted if necessary)?</p>
<p dir="ltr">P.S. Your naming conventions (with respect to capitalization) disagree with those of Python.</p>