[issue11401] email.header error during .flatten()

Steffen Daode Nurpmeso report at bugs.python.org
Sat Mar 5 14:01:09 CET 2011


Steffen Daode Nurpmeso <sdaoden at googlemail.com> added the comment:

> Changes by R. David Murray <rdmurray at bitdance.com>:
> assignee:  -> r.david.murray

David, i'm sending you data to reproduce the error on your local 
machine!

Please create a test directory and place the files therein 
(an output.mbox will be created).  Just do

  mkdir -p issue_11401/input.mdir/{cur,new,tmp}
  mv issue_11401_mail.txt "issue_11401/input.mdir/cur/test:2,S"
  mv issue_11401_runner.py issue_11401/
  cd issue_11401
  python3 issue_11401_runner.py

(I'm looking forward for a glass of red wine, just in case we'll 
ever meet.-)

----------
Added file: http://bugs.python.org/file21005/issue_11401_mail.txt
Added file: http://bugs.python.org/file21006/issue_11401_runner.py

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue11401>
_______________________________________
-------------- next part --------------
Return-Path: <mail-noreply at google.com>
X-Original-To: steffen
Delivered-To: steffen at sherwood.local
Received: by sherwood.local (Postfix, from userid 502)
	id 0302C6F8D01; Wed,  5 Jan 2011 16:07:15 +0100 (CET)
MIME-Version: 1.0
Received: from gmail-pop.l.google.com [74.125.79.109]
	by sherwood.local with POP3 (fetchmail-6.3.11)
	for <steffen at localhost> (single-drop); Wed, 05 Jan 2011 16:07:15 +0100 (CET)
Received: by 10.216.183.130; Mon, 25 Oct 2009 05:50:04 -0700 (PDT)
Date: Mon, 25 Oct 2009 05:50:04 -0700
Subject: Import your contacts and old email
From: Google Mail Team <mail-noreply at google.com>
To: Steffen Daode Nurpmeso <sdaoden at googlemail.com>
Content-Type: multipart/alternative; boundary=0016e6db7cbd62d15c0493706eea
Content-Length: 2490
Lines: 70
Status: RO
X-Status: 
X-Keywords: 
X-UID: 2

--0016e6db7cbd62d15c0493706eea
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

You can import your contacts and mail from Yahoo!, Hotmail, AOL, and many
other web mail or POP accounts. If you want, we'll even keep importing your
mail for the next 30 days.
     Import contacts and mail
=BB<https://mail.google.com/mail/#settings/accounts>

We know it can be a pain to switch email accounts, and we hope this makes
the transition to Google Mail a bit easier.

- The Google Mail Team

Please note that importing is not available if you're using Internet
Explorer 6.0. To take advantage of the latest Google Mail features,
please upgrade
to a fully supported
browser<http://mail.google.com/support/bin/answer.py?answer=3D6557&hl=3Den&=
utm_source=3Dwel-eml&utm_medium=3Deml&utm_campaign=3Den>
.

--0016e6db7cbd62d15c0493706eea
Content-Type: text/html; charset=ISO-8859-1

<html>
<font face="Arial, Helvetica, sans-serif">
<p>You can import your contacts and mail from Yahoo!, Hotmail, AOL, and many
other web mail or POP accounts. If you want, we'll even keep importing your
mail for the next 30 days.</p>

<table cellpadding="0" cellspacing="0">
<col style="width: 1px" /><col /><col style="width: 1px" />
<tr>
  <td></td>
  <td height="1px" style="background-color: #ddd"></td>
  <td></td>
</tr>
<tr>
  <td style="background-color: #ddd"></td>
  <td background="https://mail.google.com/mail/images/welcome-button-background.png"
      style="background-color: #ddd; background-repeat: repeat-x"
    ><a href="https://mail.google.com/mail/#settings/accounts"
        style="font-weight: bold; color: #000; text-decoration: none; display: block; padding: 0.5em 1em"
      >Import contacts and mail &#187;</a></td>
  <td style="background-color: #ddd"></td>
</tr>
<tr>
  <td></td>
  <td height="1px" style="background-color: #ddd"></td>
  <td></td>
</tr>
</table>

<p>We know it can be a pain to switch email accounts, and we hope this makes
the transition to Google Mail a bit easier.</p>

<p>- The Google Mail Team</p>

<p><font size="-2" color="#999">Please note that importing is not available if
you're using Internet Explorer 6.0. To take advantage of the latest Google Mail
features, please
<a href="http://mail.google.com/support/bin/answer.py?answer=6557&hl=en&utm_source=wel-eml&utm_medium=eml&utm_campaign=en"><font color="#999">
upgrade to a fully supported browser</font></a>.</font></p>

</font>
</html>

--0016e6db7cbd62d15c0493706eea--
-------------- next part --------------
import sys
import mailbox

VERBOSE = 1
def log(*args):
    if not VERBOSE:
        return
    print('| ' + ''.join(str(i) for i in args), file=sys.stderr)

class MailboxHelper:
    @staticmethod
    def open(path, type='mbox', create=False):
        log('Opening ', type, ' mailbox ', path)
        if type == 'mbox':
            mb = mailbox.mbox
        elif type == 'maildir':
            mb = mailbox.Maildir
        #try:
        mb = mb(path, create=create)
        #except Exception:
            # FIXME throws IOError (Errno 21) if dispatch specified a dir but
            # dod not set a dir-based type..
        #    panic('Failed to open ', path, extb=E())
        return mb

msg = None

inmb = MailboxHelper.open('input.mdir', type='maildir', create=False)
try:
    log('* Box has ', len(inmb),
        ' messages, filtering through rulesets')
    cnt = 0
    for k in inmb.iterkeys():
        cnt += 1
        log('({!s:>04})'.format(cnt))
        msg = inmb.get_message(k)
        if cnt == 1:
            break
except Exception as e:
    error('failed to handle box ', b, extb=E())


outmb = MailboxHelper.open('output.mbox', create=True)
try:
    outmb.add(msg)
    outmb.flush()
except Exception as e:
    log(': message-add failed.\n')
    raise
finally:
    outmb.unlock()



More information about the Python-bugs-list mailing list