Re: email.message.Message - as_string fails

Discussion in 'Python' started by Chris Rebert, Dec 28, 2012.

  1. Chris Rebert

    Chris Rebert Guest

    On Dec 28, 2012 4:26 AM, "Helmut Jarausch" <-aachen.de>
    wrote:
    >
    > 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?


    Perhaps the message is malformed. What does Msg.defects give you?

    Could you post the line strings you fed to the parser that together
    constitute the first message (redacted if necessary)?

    P.S. Your naming conventions (with respect to capitalization) disagree with
    those of Python.
    Chris Rebert, Dec 28, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Saunders
    Replies:
    1
    Views:
    669
    John Saunders
    Nov 18, 2003
  2. Chuck Amadi
    Replies:
    2
    Views:
    399
    chuck amadi
    Jun 6, 2004
  3. David Stockwell
    Replies:
    1
    Views:
    619
    David Bolen
    Jun 17, 2004
  4. Rogério Brito
    Replies:
    1
    Views:
    660
    Sean DiZazzo
    Sep 9, 2009
  5. Terry Reedy
    Replies:
    0
    Views:
    153
    Terry Reedy
    Dec 29, 2012
Loading...

Share This Page