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


Groups > comp.lang.python > #35727

Re: email.message.Message - as_string fails

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'value,': 0.03; 'messages.': 0.04; 'msg': 0.07; 'parser': 0.07; 'missed': 0.09; 'python': 0.09; 'defined.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'terry': 0.09; 'bug': 0.10; 'index': 0.13; 'skip:f 30': 0.15; '3.3,': 0.16; 'doc,': 0.16; 'empty.': 0.16; 'fix,': 0.16; 'fold': 0.16; 'indexerror:': 0.16; 'opened.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'rewritten': 0.16; 'subject:fails': 0.16; 'tripped': 0.16; 'string': 0.17; 'wrote:': 0.17; 'jan': 0.18; 'followed': 0.20; 'skip:" 30': 0.20; 'skip:" 40': 0.20; 'tracker': 0.20; 'written': 0.20; 'trying': 0.21; 'doc': 0.22; 'lets': 0.22; 'trace': 0.22; 'visible': 0.22; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'skip:m 30': 0.26; '(most': 0.27; 'am,': 0.27; 'header:X-Complaints-To:1': 0.28; 'lines': 0.28; 'skip:( 20': 0.28; 'convert': 0.29; 'skip:_ 10': 0.29; "i'm": 0.29; 'e.g.': 0.30; 'code': 0.31; 'file': 0.32; 'could': 0.32; 'print': 0.32; 'skip:s 30': 0.33; 'traceback': 0.33; 'to:addr :python-list': 0.33; 'hi,': 0.33; 'list': 0.35; 'filter': 0.35; 'received:org': 0.36; 'but': 0.36; 'limitation': 0.36; 'possible': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'delete': 0.38; 'to:addr:python.org': 0.39; 'where': 0.40; 'skip:" 10': 0.40; 'header:Received:5': 0.40; 'range': 0.60; 'skip:u 10': 0.60; 'first': 0.61; 'back': 0.62; 'believe': 0.69; 'maxlen': 0.84; 'received:fios.verizon.net': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: email.message.Message - as_string fails
Date Fri, 28 Dec 2012 20:57:46 -0500
References <ak5h8rFqgagU1@mid.dfncis.de>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host pool-173-75-251-66.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/17.0 Thunderbird/17.0
In-Reply-To <ak5h8rFqgagU1@mid.dfncis.de>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1415.1356746310.29569.python-list@python.org> (permalink)
Lines 52
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1356746310 news.xs4all.nl 6867 [2001:888:2000:d::a6]:38534
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:35727

Show key headers only | View raw


On 12/28/2012 7:22 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

The only list index visible is 0 in lines[0]. If this raises, lines is 
empty. You could trace back to see where lines is defined. I suspect it 
is all or part of the Msg you started with.

I believe that some of email was rewritten for 3.3, so it is possible 
that you found a bug based on an untrue assumption. It is also possible 
that you missed a limitation in the doc, or tripped over an intended but 
not written limitation. So I hope you do the tracing, so if doc or code 
need a fix, a tracker issue can be opened.

-- 
Terry Jan Reedy

Back to comp.lang.python | Previous | NextPrevious in thread | Next 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