4491: Corrupted mail headers when using non ascii charachters in header values.

johro

What version of Djblets are you using?

python-djjblets-0.9.4-1.el7.noarch

Which module(s) have the problem?

djblets.mail.message

What steps will reproduce the problem?

  1. Creating a review in Review Board where one of the recipients have non ascii chars in their email, ie "John Döe jdoe@example.com"

What is the expected output? What do you see instead?

"Sender" mail header becomes: (recieved mail)
"=?uf-8?q?John_D=C3=B6e_=3Cjdoe=40example=2Ecom=3E@host.example.com"

Expected "Sender" mail header:
"=?uf-8?q?John_D=C3=B6e?= jdoe@example.com"

Mailer used:
Postfix

/etc/postfix/main.cf (modifications)
myhostname = host.example.com
mydomain = example.com
myorigin = $myhostname

What version of Python and Django?

python-2.7.5-39.el7_2.x86_64
python-django-1.6.11-5.el7.noarch

Other possible relevant versions

CentOS Linux release 7.2.1511 (core)
postfix-2.10.1-6.el7.x86_64
ReviewBoard-2.5.7-1.el7.noarch

Please provide any additional information below.

We worked around it by using a patch that uses djangos SafeMIMEText.setitem() to properly encode the headers.

--- djblets.orig/mail/message.py        2016-11-29 13:50:37.556695218 +0100
+++ djblets/mail/message.py     2016-11-29 14:34:54.687685391 +0100
@@ -246,7 +246,7 @@ class EmailMessage(EmailMultiAlternative
 
         for name, value_list in self._headers.iterlists():
             for value in value_list:
-                msg.add_header(six.binary_type(name), value)
+                msg[name] = value
 
         return msg