Mercurial > p > roundup > code
diff roundup/mailgw.py @ 6345:14c9284a8bad
Fix filename created from mail attachments
Fixes issue2551118
| author | Ralf Schlatterbeck <rsc@runtux.com> |
|---|---|
| date | Wed, 17 Mar 2021 10:54:14 +0100 |
| parents | ca0915457761 |
| children | 3e8f2104753b |
line wrap: on
line diff
--- a/roundup/mailgw.py Mon Mar 15 14:18:00 2021 -0400 +++ b/roundup/mailgw.py Wed Mar 17 10:54:14 2021 +0100 @@ -397,6 +397,23 @@ return part.as_attachment() return None + def get_filename(self): + """ Note: The get_filename of the Message class returns just the + encoded header as transmitted via email. We make an attempt + here to decode the information returned and return the real + filename here. + """ + # This should really use super() but doesn't work with python2 + # because it seems that email.message.Message isn't a new-style + # class in python2 + fn = email.message.Message.get_filename(self) + if not fn : + return fn + h = [] + for x, t in decode_header(fn): + h.append(x.decode(t) if t else x) + return ''.join(h) + def as_attachment(self): """Return this message as an attachment.""" filename = self.get_filename()
