From 9070090caaed318818130fcefe1aa9f565f7327d Mon Sep 17 00:00:00 2001 From: Maciej Sitarz Date: Fri, 11 Jan 2013 10:35:10 +0100 Subject: [PATCH] Set proper content type and encode attachment name Fixes Bug #1098478 --- src/calibre/utils/smtp.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/calibre/utils/smtp.py b/src/calibre/utils/smtp.py index 3e880a5347..be9627d5fb 100644 --- a/src/calibre/utils/smtp.py +++ b/src/calibre/utils/smtp.py @@ -37,16 +37,17 @@ def create_mail(from_, to, subject, text=None, attachment_data=None, if attachment_data is not None: from email.mime.base import MIMEBase + from email.header import Header assert attachment_data and attachment_name try: maintype, subtype = attachment_type.split('/', 1) except AttributeError: maintype, subtype = 'application', 'octet-stream' - msg = MIMEBase(maintype, subtype) + msg = MIMEBase(maintype, subtype, name=Header(attachment_name, 'utf-8').encode()) msg.set_payload(attachment_data) encoders.encode_base64(msg) msg.add_header('Content-Disposition', 'attachment', - filename=attachment_name) + filename=Header(attachment_name, 'utf-8').encode()) outer.attach(msg) return outer.as_string()