[FIX] mail: missing spaces in email subjects composed of several encoding

sometimes some blank spaces are lost in subject of some incoming messages

There is a bug in `decode_header` in Python < 3.3,
which leads to lost some spaces in the email subjects
when several encodings are used in this subject.

See
- Issue: http://bugs.python.org/issue1079
- Fix: https://hg.python.org/cpython/rev/8c03fe231877

Joining the strings returned in the result of `decode_header`
solves most cases. Only extreme cases, like having
a subject with several different encodings following
each other without white spaces between them could lead
to have extra spaces in the subject. It won't happen
most of the time.

Closes #6629
This commit is contained in:
Olivier LAURENT 2015-05-12 17:51:29 +02:00 committed by Denis Ledoux
parent d1c4d16a3a
commit 242e61796b
2 changed files with 4 additions and 2 deletions

View File

@ -16,7 +16,7 @@
claim_ids = self.search(cr, uid, [('email_from','=', 'Mr. John Right <info@customer.com>')])
assert claim_ids and len(claim_ids), "Claim is not created after getting request"
claim = self.browse(cr, uid, claim_ids[0], context=context)
assert claim.name == tools.ustr("demande derèglement de votre produit."), "Subject does not match"
assert claim.name == tools.ustr("demande de règlement de votre produit."), "Subject does not match"
-
I open customer claim.
-

View File

@ -41,7 +41,9 @@ def decode(text):
"""Returns unicode() string conversion of the the given encoded smtp header text"""
if text:
text = decode_header(text.replace('\r', ''))
return ''.join([tools.ustr(x[0], x[1]) for x in text])
# The joining space will not be needed as of Python 3.3
# See https://hg.python.org/cpython/rev/8c03fe231877
return ' '.join([tools.ustr(x[0], x[1]) for x in text])
class mail_message(osv.Model):