[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.
This commit is contained in:
@@ -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!
|
||||
|
||||
@@ -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 = []
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user