Opened 13 years ago

Closed 13 years ago

#17536 closed Bug (duplicate)

Filename encoding broken for attachments in EmailMessage class

Reported by: alexey Owned by: nobody
Component: Core (Mail) Version: dev
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

Description

Message encoding broken if creating messages with EmailMessage class.

Test case:

subject = u"Тест"
body = u"Тест"
recepients = ["test@test.com"]

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

email = EmailMessage(subject,body,to=recepients)
email.attach(filename.encode("utf-8"),report)
email.send()

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 by alexey, 13 years ago

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
    object.
    """
    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 by anonymous, 13 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #14964

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