From 9342cd5c579abfd53145a1db95219b8525fa5749 Mon Sep 17 00:00:00 2001 From: Jeremy Kersten Date: Wed, 19 Apr 2017 00:40:34 +0200 Subject: [PATCH] [FIX] base, mail, calendar: respect mimetype in email for attachemnt With this commit, the mimetype will be sent with the attachment. That will allow some Mail Client (e.g. thunderbird) to 'understand' the purpose of the attachemnt. E.g. when you sent a text/calendar mimetype, thunderbird propose you to add automatically the event into your calendar. --- addons/calendar/models/calendar.py | 1 + addons/mail/models/mail_mail.py | 4 ++-- odoo/addons/base/ir/ir_mail_server.py | 8 ++++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/addons/calendar/models/calendar.py b/addons/calendar/models/calendar.py index c543f5ea830..7245f4943fd 100644 --- a/addons/calendar/models/calendar.py +++ b/addons/calendar/models/calendar.py @@ -170,6 +170,7 @@ class Attendee(models.Model): vals = {} if ics_file: vals['attachment_ids'] = [(0, 0, {'name': 'invitation.ics', + 'mimetype': 'text/calendar', 'datas_fname': 'invitation.ics', 'datas': str(ics_file).encode('base64')})] vals['model'] = None # We don't want to have the mail in the tchatter while in queue! diff --git a/addons/mail/models/mail_mail.py b/addons/mail/models/mail_mail.py index ff25c60f04a..3ac2285fab3 100644 --- a/addons/mail/models/mail_mail.py +++ b/addons/mail/models/mail_mail.py @@ -270,8 +270,8 @@ class MailMail(models.Model): # load attachment binary data with a separate read(), as prefetching all # `datas` (binary field) could bloat the browse cache, triggerring # soft/hard mem limits with temporary data. - attachments = [(a['datas_fname'], base64.b64decode(a['datas'])) - for a in mail.attachment_ids.sudo().read(['datas_fname', 'datas'])] + attachments = [(a['datas_fname'], base64.b64decode(a['datas']), a['mimetype']) + for a in mail.attachment_ids.sudo().read(['datas_fname', 'datas', 'mimetype'])] # specific behavior to customize the send email for notified partners email_list = [] diff --git a/odoo/addons/base/ir/ir_mail_server.py b/odoo/addons/base/ir/ir_mail_server.py index 37a8126aaac..c061b56f625 100644 --- a/odoo/addons/base/ir/ir_mail_server.py +++ b/odoo/addons/base/ir/ir_mail_server.py @@ -355,9 +355,13 @@ class IrMailServer(models.Model): msg.attach(email_text_part) if attachments: - for (fname, fcontent) in attachments: + for (fname, fcontent, mime) in attachments: filename_rfc2047 = encode_header_param(fname) - part = MIMEBase('application', "octet-stream") + if mime and '/' in mime: + maintype, subtype = mime.split('/', 1) + part = MIMEBase(maintype, subtype) + else: + part = MIMEBase('application', "octet-stream") # The default RFC2231 encoding of Message.add_header() works in Thunderbird but not GMail # so we fix it by using RFC2047 encoding for the filename instead.