tale of two attachments

TBS tedshab at gmail.com
Mon Jul 7 21:27:36 CEST 2008


Hi,

I have a script that is invoked by .forward on a Unix mailbox.

It works fine parsing an attachment and saving to disk when the email
is sent directly to the email address (header 1), but doesn't work
when the email is sent via a majordomo mailing list (header 2).  I've
looked at the mime files coming into mail, and they look the same.
I've attached the headers, and I don't see any major different,
although there is a warning on the mailing list that "X-Authentication-
Warning: lists...: pmx set sender to owner-list-report at ... using -f".

Here is the code fragment, it seems to fail on the second header on
the part.get_param call:

        parser=email.Parser.Parser()
        msg = parser.parsestr(raw_email)
        counter = 1
        for part in msg.walk():
                if part.get_main_type()== 'multipart':
                        continue
                log.write("gets here")  #gets to this point for
majordomo send
                filename = part.get_param("name")
                log.write("...but not here") #but not to this point
                if filename==None:
                        filename = "part-%1" % counter
                counter += 1
                fp = open(os.path.join(dir, filename), 'wb')
                fp.write(part.get_payload(decode=1))
                fp.close()

=============================
Header 1
=============================


>From tshab at ... Mon Jul  7 11:00:46 2008
Received: from nospam3...
 by mail... with ESMTP id m67I0jSg023687
 for <direct at ...; Mon, 7 Jul 2008 11:00:45 -0700 (PDT)
 (envelope-from tshab at whatever)
Received: from exch-mail...
 by nospam... with ESMTP id m67I0jfd014416
 for <direct at whatever>; Mon, 7 Jul 2008 11:00:45 -0700 (PDT)
 (envelope-from tshab at ...)
X-MimeOLE: Produced By Microsoft Exchange V6.5
Content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: application/vnd.ms-excel;
 name="po_test.xls"
Content-Transfer-Encoding: base64
Content-Description: po_test.xls
Content-Disposition: attachment;
 filename="po_test.xls"
Subject: test case
Date: Mon, 7 Jul 2008 11:00:44 -0700
Message-ID: <CFF3D7191F21B44FA906AAE979C66AEA022AFACC at ...>
In-Reply-To: <CFF3D7191F21B44FA906AAE979C66AEA022AFACB at ...>
X-MS-Has-Attach: yes
X-MS-TNEF-Correlator:
Thread-Topic: test case
thread-index: AcjgWxsfx8N1mNqFSOq9C/j/8FIZIQAADqBg
References: <CFF3D7191F21B44FA906AAE979C66AEA022AFACB at exch-mail...>
From: "Shab, Theodore" <tshab at ...>
To: "arf" <direct at ...>
Content-Length: 18675
Status: RO

=============================
Header 2
=============================

>From owner-list-report at ... Mon Jul  7 11:01:05 2008
Received: from list... (list...)
 by mail with ESMTP id m67I14uL023715;
 Mon, 7 Jul 2008 11:01:04 -0700 (PDT)
 (envelope-from owner-list-report at ...)
Received: from lists...
 by list... with ESMTP id m67I13bD017476
 for <list-report-outgoing at ...>; Mon, 7 Jul 2008 11:01:03 -0700 (PDT)
 (envelope-from owner-list-report at ...)
Received: (from pmx at localhost)
 by list.../Submit) id m67I13lG017475
 for list-report-outgoing; Mon, 7 Jul 2008 11:01:03 -0700 (PDT)
 (envelope-from owner-list-report at ...)
X-Authentication-Warning: lists...: pmx set sender to owner-list-
report at ... using -f
Received: from nospam... (nospam...)
 by lists... with ESMTP id m67I127h017471
 for <list-report at ...>; Mon, 7 Jul 2008 11:01:02 -0700 (PDT)
 (envelope-from tshab at ...)
Received: from exch-mai...)
 by nospam... with ESMTP id m67I11g2014193
 for <list-report at ...>; Mon, 7 Jul 2008 11:01:02 -0700
 (envelope-from tshab at ...)
X-MimeOLE: Produced By Microsoft Exchange V6.5
Content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: application/vnd.ms-excel;
 name="po_test.xls"
Content-Transfer-Encoding: base64
Content-Description: po_test.xls
Content-Disposition: attachment;
 filename="po_test.xls"
Subject: test case 2
Date: Mon, 7 Jul 2008 11:01:01 -0700
Message-ID: <CFF3D7191F21B44FA906AAE979C66AEA022AFACD at ...>
X-MS-Has-Attach: yes
X-MS-TNEF-Correlator:
Thread-Topic: test case 2
thread-index: AcjgW2qv6AWa1eUxTXGlSQ5a2g7OuA==
From: "Shab, Theodore" <tshab at ...>
To: "list-report" <list-report at ...>
Sender: owner-list-report at ...
Precedence: bulk
Content-Length: 18675
Status: O




More information about the Python-list mailing list