From 9080acedf2281a37db8d1b70947836c4b5f54d05 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 7 Apr 2017 16:24:28 +0300 Subject: refactor: Split long method into two --- distixlib/plugins/import_mail_plugin.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/distixlib/plugins/import_mail_plugin.py b/distixlib/plugins/import_mail_plugin.py index dc13da8..6fc131b 100644 --- a/distixlib/plugins/import_mail_plugin.py +++ b/distixlib/plugins/import_mail_plugin.py @@ -172,20 +172,21 @@ class ImportMailPlugin(cliapp.Plugin): msg_ids = distixlib.get_ids_from_message(msg) for ticket_id in context.all_ticket_ids: - if ticket_id in context.cache: - other_ids = contex.cache.get_msg_ids_for_ticket_id(ticket_id) - else: - filenames = context.store.get_message_filenames(ticket_id) - for filename in filenames: - other_msg = self._read_mail_message(filename) - other_ids = distixlib.get_ids_from_message(other_msg) - context.cache.add_msg_ids_for_ticket_id( - ticket_id, other_ids) + other_ids = self._get_ticket_message_ids(context, ticket_id) if other_ids.intersection(msg_ids): ticket_ids.append(ticket_id) return ticket_ids + def _get_ticket_message_ids(self, context, ticket_id): + if ticket_id not in context.cache: + filenames = context.store.get_message_filenames(ticket_id) + for filename in filenames: + msg = self._read_mail_message(filename) + msg_ids = distixlib.get_ids_from_message(msg) + context.cache.add_msg_ids_for_ticket_id(ticket_id, msg_ids) + return context.cache.get_msg_ids_for_ticket_id(ticket_id) + def _create_ticket_from_msg(self, repo, msg): ticket_id = repo.invent_new_ticket_id() subject = self._get_header(msg, 'Subject') -- cgit v1.2.1