diff options
| author | Denis Ledoux <dle@openerp.com> | 2014-01-02 17:11:49 +0100 |
|---|---|---|
| committer | Denis Ledoux <dle@openerp.com> | 2014-01-02 17:11:49 +0100 |
| commit | bc50cd3558de6feec3e062d2da88dc4433ddbda3 (patch) | |
| tree | b1aa2d4123d8026cef78ebfb74a71a8e99176822 | |
| parent | e0951d6e18676ac0b6609ab5c16ee0cb86623369 (diff) | |
[FIX] mail: mails with attachments containing special chars (such as é) were not delivered properly
get_filename method from email lib returns sometimes decoded value, sometimes still encoded.
for instance, get_filename cannot decode iso encoded filename
Recently, decode method has been applied on filename string, to handle iso encoded file.
Sadly, one cannot decode already decoded values.
Therefore, decoding already decoded windows or utf-8 encoded filename with special chars failed.
bzr revid: dle@openerp.com-20140102161149-x268xj7bzvvsit2h
| -rw-r--r-- | addons/mail/mail_thread.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index 1c3b4dfa9fa..cf976981132 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -763,11 +763,23 @@ class mail_thread(osv.AbstractModel): alternative = True if part.get_content_maintype() == 'multipart': continue # skip container - filename = part.get_filename() # None if normal part + # part.get_filename returns decoded value if able to decode, coded otherwise. + # original get_filename is not able to decode iso-8859-1 (for instance). + # therefore, iso encoded attachements are not able to be decoded properly with get_filename + # code here partially copy the original get_filename method, but handle more encoding + filename=part.get_param('filename', None, 'content-disposition') + if not filename: + filename=part.get_param('name', None) + if filename: + if isinstance(filename, tuple): + # RFC2231 + filename=email.utils.collapse_rfc2231_value(filename).strip() + else: + filename=decode(filename) encoding = part.get_content_charset() # None if attachment # 1) Explicit Attachments -> attachments if filename or part.get('content-disposition', '').strip().startswith('attachment'): - attachments.append((decode(filename) or 'attachment', part.get_payload(decode=True))) + attachments.append((filename or 'attachment', part.get_payload(decode=True))) continue # 2) text/plain -> <pre/> if part.get_content_type() == 'text/plain' and (not alternative or not body): |
