[MERGE] merged the branch of dsh containing enhancement of attachments handling in mails

bzr revid: qdp-launchpad@openerp.com-20111110081037-j05v0myr58bwqgtb
This commit is contained in:
Quentin (OpenERP) 2011-11-10 09:10:37 +01:00
commit 4a48b9abad
2 changed files with 7 additions and 6 deletions

View File

@ -334,8 +334,8 @@ class mail_message(osv.osv):
'subtype': msg_mime_subtype,
'body_text': plaintext_body
'body_html': html_body,
'attachments': { 'file1': 'bytes',
'file2': 'bytes' }
'attachments': [('file1', 'bytes'),
('file2', 'bytes') }
# ...
'original': source_of_email,
}
@ -416,7 +416,7 @@ class mail_message(osv.osv):
body = tools.html2plaintext(body)
msg['body_text'] = tools.ustr(body, encoding)
attachments = {}
attachments = []
if msg_txt.is_multipart() or 'multipart/alternative' in msg.get('content-type', ''):
body = ""
if 'multipart/alternative' in msg.get('content-type', ''):
@ -432,7 +432,7 @@ class mail_message(osv.osv):
if part.get_content_maintype()=='text':
content = part.get_payload(decode=True)
if filename:
attachments[filename] = content
attachments.append((filename, content))
content = tools.ustr(content, encoding)
if part.get_content_subtype() == 'html':
msg['body_html'] = content
@ -442,7 +442,7 @@ class mail_message(osv.osv):
body = content
elif part.get_content_maintype() in ('application', 'image'):
if filename :
attachments[filename] = part.get_payload(decode=True)
attachments.append((filename,part.get_payload(decode=True)))
else:
res = part.get_payload(decode=True)
body += tools.ustr(res, encoding)

View File

@ -201,7 +201,8 @@ class mail_thread(osv.osv):
for thread in threads:
to_attach = []
for fname, fcontent in attachments.items():
for attachment in attachments:
fname, fcontent = attachment
if isinstance(fcontent, unicode):
fcontent = fcontent.encode('utf-8')
data_attach = {