Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: email.message.Message - as_string fails

Reply
Thread Tools

Re: email.message.Message - as_string fails

 
 
Chris Rebert
Guest
Posts: n/a
 
      12-28-2012
On Dec 28, 2012 4:26 AM, "Helmut Jarausch" <>
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: email.message.Message - as_string fails Terry Reedy Python 0 12-29-2012 01:57 AM
Constant.t fails 240 of 272 tests and recurs.t fails 1 of 25 tests on HPUX using perl 5.8.7 dayo Perl Misc 11 12-16-2005 09:09 PM
slideshow fails, Firefox debugger also fails lkrubner@geocities.com Javascript 2 12-23-2004 06:22 PM
IAS fails with certs from Stand Alone CA Harrison Midkiff Wireless Networking 2 07-22-2004 09:45 PM
Forms Authentication Fails Between ASP.NET 1.0 and 1.1 Applications (Cookie Decryption Fails) John Saunders ASP .Net 1 11-18-2003 03:25 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57