diff options
author | Lars Wirzenius <liw@liw.fi> | 2016-03-25 14:38:54 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2016-03-25 14:40:27 +0200 |
commit | ba260c901379f3a6b56f8b6c989b0692366f9064 (patch) | |
tree | fbf30d5a9617e7c002900081042ae2258b90c6c7 | |
parent | 95e317569c80c3fd7eed628ee973976b98039fff (diff) | |
download | distix-ba260c901379f3a6b56f8b6c989b0692366f9064.tar.gz |
import: Decode header encoding in subjects
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | distixlib/plugins/import_mail_plugin.py | 10 |
2 files changed, 12 insertions, 1 deletions
@@ -13,6 +13,9 @@ Version 0.5+git, not yet released * New command `distix html` generates a static HTML website to show the contents of a repository. The site is read-only. +* Mail importing now decodes the Subject header when setting the title + for a new ticket. + Version 0.5, released 2016-03-08 --------------------------------- diff --git a/distixlib/plugins/import_mail_plugin.py b/distixlib/plugins/import_mail_plugin.py index 5dc6b2b..d75f63c 100644 --- a/distixlib/plugins/import_mail_plugin.py +++ b/distixlib/plugins/import_mail_plugin.py @@ -141,10 +141,18 @@ class ImportMailPlugin(cliapp.Plugin): def _create_ticket_from_msg(self, repo, msg): ticket_id = repo.invent_new_ticket_id() - ticket = self._create_ticket(ticket_id, msg['Subject']) + subject = self._get_header(msg, 'Subject') + ticket = self._create_ticket(ticket_id, subject) ticket.add_message(msg) return ticket + def _get_header(self, msg, name): + decoded = email.header.decode_header(msg[name]) + combined = u' '.join( + value.decode(encoding or 'us-ascii') + for value, encoding in decoded) + return combined + def _create_ticket(self, ticket_id, title): ticket = distixlib.Ticket() ticket.set_ticket_id(ticket_id) |