Opened 6 years ago

Closed 6 years ago

#17536 closed Bug (duplicate)

Filename encoding broken for attachments in EmailMessage class

Reported by: alexey Owned by: nobody
Component: Core (Mail) Version: master
Severity: Normal Keywords: EmailMessage, broken encoding, unicode, i18n
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Message encoding broken if creating messages with EmailMessage class.

Test case:

subject = u"Тест"
body = u"Тест"
recepients = [""]

filename = u"тест.txt"
report = "some binary data"

email = EmailMessage(subject,body,to=recepients)

filename will NOT be properly encoded and pushed into the message "as is". And some email clients such as MS Outlook will show broken stuff instead of filename.

Change History (2)

comment:1 Changed 6 years ago by alexey

It seems that bug is in _create_attachment method. I solved this by monkey-patching:

def _create_attachment(self, filename, content, mimetype=None):
    Converts the filename, content, mimetype triple into a MIME attachment
    if mimetype is None:
        mimetype, _ = mimetypes.guess_type(filename)
        if mimetype is None:
            mimetype = DEFAULT_ATTACHMENT_MIME_TYPE
    attachment = self._create_mime_attachment(content, mimetype)
    if filename:
        attachment.add_header('Content-Disposition', 'attachment',
            filename=('utf-8','',filename)) # Changed here!!! 
    return attachment

comment:2 Changed 6 years ago by anonymous

Resolution: duplicate
Status: newclosed

Duplicate of #14964

Note: See TracTickets for help on using tickets.
Back to Top