Decode base64 encoded e-mail attachment filename.

According to RFC 2231 the filename of e-mail attachments can be encoded,
e.g. with base64 (for example, the Brother ADS2800W Scanner does this).

Here an example how it looks like:

Content-Disposition: attachment; filename="=?UTF-8?B?QlJXMjg1NjVBOEI5RkQyXzIwMTcwNTIzXzIzMDMzN18wMDAzMDMucGRm?="

Signed-off-by: Cornelius Ludmann <dev@cornelius-ludmann.de>
This commit is contained in:
Cornelius Ludmann
2017-08-02 13:28:43 +02:00
committed by Roberto Rosario
parent 4b36c27e33
commit c29d7c6e5b

View File

@@ -617,6 +617,12 @@ class EmailBaseModel(IntervalBaseModel):
if raw_filename:
filename = collapse_rfc2231_value(raw_filename)
# Decode base64 encoded filename
# https://stackoverflow.com/a/21859258/1364435
if decode_header(filename)[0][1] is not None:
filename = str(decode_header(filename)[0][0]).decode(decode_header(filename)[0][1])
else:
filename = _('attachment-%i') % counter
counter += 1