Opened 2 years ago

Closed 2 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.

Attachments (0)

Change History (2)

comment:1 Changed 2 years ago by alexey

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 2 years ago by anonymous

  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #14964

Add Comment

Modify Ticket

Change Properties
<Author field>
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.