From c81c3cf691057107b439ed61f1f0b0885055f061 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 7 Apr 2017 15:22:08 +0300 Subject: Change import plugin to use get_ids_from_message --- distixlib/plugins/import_mail_plugin.py | 24 ++++-------------------- 1 file 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) -- cgit v1.2.1