summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2018-05-22 16:45:59 +0200
committerChristophe Simonis <chs@odoo.com>2018-05-22 16:45:59 +0200
commit3d7b238b8ee1139eeab0f6317f96dffc7dc0d423 (patch)
tree198ae072620277c41cd8d2a62d6582f01dc3fd22
parentea3385b41c4b08e4ac1e975cc210a5619e9cac5b (diff)
[FIX] core: correctly decode 8bit mail headers
When an header contains surrogates, an Header object is returned when read headers from Message objects. Also, correctly join header parts in python3.
-rw-r--r--odoo/tools/mail.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/odoo/tools/mail.py b/odoo/tools/mail.py
index 5c02b3aa3e3..96d8d5614ff 100644
--- a/odoo/tools/mail.py
+++ b/odoo/tools/mail.py
@@ -10,7 +10,7 @@ import socket
import threading
import time
-from email.header import decode_header
+from email.header import decode_header, Header
from email.utils import getaddresses, formataddr
from lxml import etree
@@ -524,11 +524,14 @@ def decode_smtp_header(smtp_header):
text. email.header decode_header method return a decoded string and its
charset for each decoded par of the header. This method unicodes the
decoded header and join them in a complete string. """
+ if isinstance(smtp_header, Header):
+ smtp_header = ustr(smtp_header)
if smtp_header:
text = decode_header(smtp_header.replace('\r', ''))
# The joining space will not be needed as of Python 3.3
- # See https://hg.python.org/cpython/rev/8c03fe231877
- return ' '.join([ustr(x[0], x[1]) for x in text])
+ # See https://github.com/python/cpython/commit/07ea53cb218812404cdbde820647ce6e4b2d0f8e
+ sep = ' ' if pycompat.PY2 else ''
+ return sep.join([ustr(x[0], x[1]) for x in text])
return u''
# was mail_thread.decode_header()