[ python-Bugs-1403349 ] in email can't get attachments' filenames using get_filename

SourceForge.net noreply at sourceforge.net
Wed Jan 11 22:47:23 CET 2006


Bugs item #1403349, was opened at 2006-01-11 16:47
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1403349&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Michal P. (mpasniew)
Assigned to: Nobody/Anonymous (nobody)
Summary: in email can't get attachments' filenames using get_filename

Initial Comment:
in the email package (2.4.1) the get_filename() method
returns the MIME field "filename" but some messages
have 'name' field instead, for example:

USUALLY THE HEADER IS:
Content-Type: application/octet-stream;
        name="XX.pdf"
Content-Transfer-Encoding: base64
Content-Description: XX.pdf
Content-Disposition: attachment;
        filename="XX.pdf"

BUT SOMETIMES THE HEADER IS:
Content-type: application/octet-stream; name="XX.xls"
Content-transfer-encoding: base64

For this to work properly I had to code a hack along
these lines:
filename = part.get_filename()
if not filename:
   ct = part.get("Content-type")
   m = re.compile('name=\"(\S+)\"').search(ct, 1)
   if m: filename=m.group(1)

But it would be helpful to code this in the get_filename()

Michal

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1403349&group_id=5470


More information about the Python-bugs-list mailing list