summaryrefslogtreecommitdiff
path: root/service/pixelated/adapter/model
diff options
context:
space:
mode:
authorFolker Bernitt <fbernitt@thoughtworks.com>2015-09-01 11:13:09 +0200
committerFolker Bernitt <fbernitt@thoughtworks.com>2015-09-01 11:20:33 +0200
commit722edf3a306e495808c3ca751f6c74f5d6e5b138 (patch)
treef5a6b75f04c32ee87130608f0a4af0e330401e86 /service/pixelated/adapter/model
parent5c5500f91a520ee363c8e553718a5a0e763257e5 (diff)
Encode headers in InputMail when generating mime multipart from it.
- Issue #360
Diffstat (limited to 'service/pixelated/adapter/model')
-rw-r--r--service/pixelated/adapter/model/mail.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/service/pixelated/adapter/model/mail.py b/service/pixelated/adapter/model/mail.py
index 388263ca..733678db 100644
--- a/service/pixelated/adapter/model/mail.py
+++ b/service/pixelated/adapter/model/mail.py
@@ -21,7 +21,7 @@ import dateutil.parser as dateparser
from uuid import uuid4
from email import message_from_file
from email.mime.text import MIMEText
-from email.header import decode_header
+from email.header import decode_header, Header
from email.MIMEMultipart import MIMEMultipart
from pycryptopp.hash import sha256
from leap.mail.adaptors import soledad_indexes as fields
@@ -89,6 +89,15 @@ class Mail(object):
def bounced(self):
return False
+ def _encode_header_value_list(self, header_value_list):
+ return [self._encode_header_value(v) for v in header_value_list]
+
+ def _encode_header_value(self, header_value):
+ if isinstance(header_value, unicode):
+ return str(Header(header_value, 'utf-8'))
+ else:
+ return str(header_value)
+
@property
def _mime_multipart(self):
if self._mime:
@@ -96,9 +105,9 @@ class Mail(object):
mime = MIMEMultipart()
for key, value in self.headers.items():
if isinstance(value, list):
- mime[str(key)] = ', '.join(value)
+ mime[str(key)] = ', '.join(self._encode_header_value_list(value))
else:
- mime[str(key)] = str(value)
+ mime[str(key)] = self._encode_header_value(value)
try:
body_to_use = self.body