Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #35688

email.message.Message - as_string fails

From Helmut Jarausch <jarausch@igpm.rwth-aachen.de>
Newsgroups comp.lang.python
Subject email.message.Message - as_string fails
Date 2012-12-28 12:22 +0000
Message-ID <ak5h8rFqgagU1@mid.dfncis.de> (permalink)

Show all headers | View raw


Hi,

I'm trying to filter an mbox file by removing some messages.
For that I use 
Parser= FeedParser(policy=policy.SMTP)
and 'feed' any lines to it.
If the mbox file contains a white line followed by '^From ',
I do

Msg= Parser.close()

(lateron I delete the Parser and create a new one by
Parser= FeedParser(policy=policy.SMTP)
)

I can access parts of the message by  Msg['Message-ID'], e.g.
but even for the very first message, trying to print it or convert it to a string
by  MsgStr=Msg.as_string(unixfrom=True)

lets Python (3.3.1_pre20121209) die with

Traceback (most recent call last):
  File "Email_Parse.py", line 35, in <module>
    MsgStr=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


What am I missing?

Many thanks for a hint,
Helmut.

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

email.message.Message - as_string fails Helmut Jarausch <jarausch@igpm.rwth-aachen.de> - 2012-12-28 12:22 +0000
  Re: email.message.Message - as_string fails Chris Rebert <clp2@rebertia.com> - 2012-12-28 09:25 -0800
  Re: email.message.Message - as_string fails Terry Reedy <tjreedy@udel.edu> - 2012-12-28 20:57 -0500
    Re: email.message.Message - as_string fails Helmut Jarausch <jarausch@skynet.be> - 2012-12-29 10:26 +0000

csiph-web