From e007afe99c6081ba25626730d60d109168ed8747 Mon Sep 17 00:00:00 2001 From: Jefferson Stachelski Date: Wed, 29 Apr 2015 17:47:05 -0300 Subject: #337 Extracted a method to a new one --- service/pixelated/maintenance.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'service/pixelated/maintenance.py') diff --git a/service/pixelated/maintenance.py b/service/pixelated/maintenance.py index 55e92c37..8a5bac57 100644 --- a/service/pixelated/maintenance.py +++ b/service/pixelated/maintenance.py @@ -1,4 +1,4 @@ -# + # Copyright (c) 2014 ThoughtWorks, Inc. # # Pixelated is free software: you can redistribute it and/or modify @@ -156,12 +156,8 @@ def load_mails(args, mail_paths): for root, dirs, files in os.walk(path): mbx = account.getMailbox('INBOX') for file_name in files: - with open(join(root, file_name), 'r') as email_file: - m = email.message_from_file(email_file) - flags = ("\\RECENT",) - print 'Added message %s' % m.get('subject') - print m.as_string() - yield mbx.addMessage(m.as_string(), flags=flags, notify_on_disk=False) + if is_mail_file_name_valid(file_name): + yield add_message_into_mailbox(join(root, file_name), mbx) defer.returnValue(args) return @@ -186,6 +182,19 @@ def flush_to_soledad(args, finalize): return args +def add_message_into_mailbox(file_path, mbx): + with open(file_path, 'r') as email_file: + m = email.message_from_file(email_file) + flags = ("\\RECENT",) + print 'Added message %s' % m.get('subject') + print m.as_string() + return mbx.addMessage(m.as_string(), flags=flags, notify_on_disk=False) + + +def is_mail_file_name_valid(file_name): + return re.match('mbox[0-9]+$', file_name) + + def dump_soledad(args): leap_session, soledad = args -- cgit v1.2.3