aspineux / pyzmail

Pyzmail is a high level mail library for Python, providing functions to read, compose and send emails
60 stars 31 forks source link

Encoded attachment filenames are not correctly decoded #1

Closed wolever closed 11 years ago

wolever commented 11 years ago

To recreate:

>>> import pyzmail
>>> m = pyzmail.message_from_string("""Content-Type:application/pdf
Content-Transfer-Encoding: base64
Content-Disposition:attachment;
 filename="=?ISO-8859-1?B?RE9DMDkw?=
 =?ISO-8859-1?B?OTEzLTA5MDky?=
 =?ISO-8859-1?B?MDEzMTIyNTM0?=
 =?ISO-8859-1?B?LnBkZg==?="
""")
>>> m.get_filename()
'=?ISO-8859-1?B?RE9DMDkw?=\n =?ISO-8859-1?B?OTEzLTA5MDky?=\n =?ISO-8859-1?B?MDEzMTIyNTM0?=\n =?ISO-8859-1?B?LnBkZg==?='

The filename should be decoded:

>>> import email.header
>>> email.header.decode_header(m.get_filename())
[('DOC090913-09092013122534.pdf', 'iso-8859-1')]
aspineux commented 11 years ago

Hello You are not using the right interface, m.get_filename() is the original function from class email.message.Message that is not over written by pyzmail. The pyzmail's way to get the filename of one attachment is this one :

  for mailpart in m.mailparts:
      print mailpart.filename

other possibilities are :

print m.mailparts[0].filename
pyzmail.parse.get_filename(m)

Regard