summaryrefslogtreecommitdiff
path: root/mail
diff options
context:
space:
mode:
authorIvan Alejandro <ivanalejandro0@gmail.com>2013-10-23 10:18:34 -0300
committerIvan Alejandro <ivanalejandro0@gmail.com>2013-10-23 10:18:34 -0300
commit9033b183e95a49236b77f87034775a67db04533b (patch)
tree555ccf73206d46e58368eebed90ac35bc568a9ab /mail
parentdcaa9301694fba800ae46c22592d55b5347f988c (diff)
Add encoding exception catch to avoid crashes.
Diffstat (limited to 'mail')
-rw-r--r--mail/src/leap/mail/imap/server.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/mail/src/leap/mail/imap/server.py b/mail/src/leap/mail/imap/server.py
index b9a041d7..7ae3c45b 100644
--- a/mail/src/leap/mail/imap/server.py
+++ b/mail/src/leap/mail/imap/server.py
@@ -706,7 +706,13 @@ class LeapMessage(WithMsgFields):
"""
fd = cStringIO.StringIO()
charset = get_email_charset(self._doc.content.get(self.RAW_KEY, ''))
- fd.write(self._doc.content.get(self.RAW_KEY, '').encode(charset))
+ content = self._doc.content.get(self.RAW_KEY, '')
+ try:
+ content = content.encode(charset)
+ except (UnicodeEncodeError, UnicodeDecodeError) as e:
+ logger.error("Unicode error {0}".format(e))
+ content = content.encode(charset, 'replace')
+ fd.write(content)
fd.seek(0)
return fd
@@ -726,7 +732,13 @@ class LeapMessage(WithMsgFields):
"""
fd = StringIO.StringIO()
charset = get_email_charset(self._doc.content.get(self.RAW_KEY, ''))
- fd.write(self._doc.content.get(self.RAW_KEY, '').encode(charset))
+ content = self._doc.content.get(self.RAW_KEY, '')
+ try:
+ content = content.encode(charset)
+ except (UnicodeEncodeError, UnicodeDecodeError) as e:
+ logger.error("Unicode error {0}".format(e))
+ content = content.encode(charset, 'replace')
+ fd.write(content)
# SHOULD use a separate BODY FIELD ...
fd.seek(0)
return fd