summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2017-04-07 15:22:08 +0300
committerLars Wirzenius <liw@liw.fi>2017-04-07 15:22:08 +0300
commitc81c3cf691057107b439ed61f1f0b0885055f061 (patch)
tree6ac573671a7229f4560f03a494f5f8c9c4af91d5
parent5c5bb0cedca2e7c55168eb46bf2a18b50833fb8d (diff)
downloaddistix-c81c3cf691057107b439ed61f1f0b0885055f061.tar.gz
Change import plugin to use get_ids_from_message
-rw-r--r--distixlib/plugins/import_mail_plugin.py24
1 files changed, 4 insertions, 20 deletions
diff --git a/distixlib/plugins/import_mail_plugin.py b/distixlib/plugins/import_mail_plugin.py
index 6742ed2..c6ba426 100644
--- a/distixlib/plugins/import_mail_plugin.py
+++ b/distixlib/plugins/import_mail_plugin.py
@@ -124,7 +124,7 @@ class ImportMailPlugin(cliapp.Plugin):
referenced_ids = self._find_tickets_with_mails_referenced_by_msg(
ticket_store, all_ticket_ids, msg, cache)
- msg_ids = self._get_message_ids(msg)
+ msg_ids = distixlib.get_ids_from_message(msg)
filenames = []
if referenced_ids:
@@ -170,7 +170,7 @@ class ImportMailPlugin(cliapp.Plugin):
self, store, all_ticket_ids, msg, cache):
ticket_ids = []
- msg_ids = self._get_message_ids(msg)
+ msg_ids = distixlib.get_ids_from_message(msg)
for ticket_id in all_ticket_ids:
if ticket_id in cache:
@@ -180,35 +180,19 @@ class ImportMailPlugin(cliapp.Plugin):
for filename in filenames:
with open(filename) as f:
other_msg = email.message_from_file(f)
- other_ids = self._get_message_ids(other_msg)
+ other_ids = distixlib.get_ids_from_message(other_msg)
cache.add_msg_ids_for_ticket_id(ticket_id, other_ids)
if other_ids.intersection(msg_ids):
ticket_ids.append(ticket_id)
return ticket_ids
- def _get_message_ids(self, msg):
- header_names = ('Message-Id', 'In-Reply-To', 'References')
- msg_ids = set()
- for header_name in header_names:
- msg_ids = msg_ids.union(
- self._get_message_ids_from_header(msg, header_name))
- return msg_ids
-
- def _get_message_ids_from_header(self, msg, header_name):
- values = msg.get_all(header_name)
- if values is None:
- return []
- return set(
- msg_id
- for real_name, msg_id in email.utils.getaddresses(values))
-
def _get_message_ids_for_ticket(self, ticket, cache):
ticket_id = ticket.get_ticket_id()
if ticket_id not in cache:
for msg in ticket.get_messages():
- msg_ids = self._get_message_ids(msg)
+ msg_ids = distixlib.get_ids_from_message(msg)
cache.add_msg_ids_for_ticket_id(ticket_id, msg_ids)
return cache.get_msg_ids_for_ticket_id(ticket_id)