summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2017-03-22 22:37:35 +0200
committerLars Wirzenius <liw@liw.fi>2017-03-22 22:37:35 +0200
commit509af82919256d2a519517ca5c1df3d1997ad61b (patch)
tree1eaa8b5cf2cec48aa50bb155d5d13b24f1e3ae3b
parent4f6ea9e99f1904ec6d864fd4ccf4bad0b08a5828 (diff)
downloaddistix-509af82919256d2a519517ca5c1df3d1997ad61b.tar.gz
Handle errors decoding headers
-rw-r--r--distixlib/plugins/import_mail_plugin.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/distixlib/plugins/import_mail_plugin.py b/distixlib/plugins/import_mail_plugin.py
index 080e663..6ed28e8 100644
--- a/distixlib/plugins/import_mail_plugin.py
+++ b/distixlib/plugins/import_mail_plugin.py
@@ -183,10 +183,18 @@ class ImportMailPlugin(cliapp.Plugin):
def _get_header(self, msg, name):
decoded = email.header.decode_header(msg[name])
combined = u' '.join(
- value.decode(encoding or 'us-ascii')
+ self._safe_decode(value, encoding)
for value, encoding in decoded)
return combined
+ def _safe_decode(self, text, encoding):
+ try:
+ return text.decode(encoding or 'us-ascii')
+ except LookupError:
+ return repr(text)
+ except UnicodeDecodeError:
+ return repr(text)
+
def _create_ticket(self, ticket_id, title):
ticket = distixlib.Ticket()
ticket.set_ticket_id(ticket_id)