summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorFolker Bernitt <fbernitt@thoughtworks.com>2015-07-30 14:53:50 +0000
committerFolker Bernitt <fbernitt@thoughtworks.com>2015-08-11 17:00:30 +0200
commit1074ae5256ee296ec2efe5407a330a933e2e3b78 (patch)
treeee7d14c972df4199244368d06210e883666d79c9 /service
parentb00fd0c00b210ea0d23b9d097e9c68801a6506cb (diff)
Fixed load-mails for empty case.
- Issue #420
Diffstat (limited to 'service')
-rw-r--r--service/pixelated/maintenance.py25
-rw-r--r--service/test/unit/maintenance/test_commands.py7
2 files changed, 13 insertions, 19 deletions
diff --git a/service/pixelated/maintenance.py b/service/pixelated/maintenance.py
index 868c9e5b..bffc272f 100644
--- a/service/pixelated/maintenance.py
+++ b/service/pixelated/maintenance.py
@@ -22,12 +22,9 @@ from pixelated.config.leap import initialize_leap
from pixelated.config import logger, arguments
from leap.mail.constants import MessageFlags
-import time
-from twisted.mail import imap4
def initialize():
- import time
args = arguments.parse_maintenance_args()
logger.init(debug=args.debug)
@@ -121,16 +118,9 @@ def is_keep_file(mail):
@defer.inlineCallbacks
-def add_mail_folder(account, maildir, folder_name, deferreds):
- try:
- mbx = yield account.getMailbox(folder_name)
- except imap4.MailboxException:
- account.addMailbox(folder_name)
- mbx = yield account.getMailbox(folder_name)
- # if folder_name not in account.mailboxes:
- # account.addMailbox(folder_name)
-
- mbx = yield account.getMailbox(folder_name)
+def add_mail_folder(store, maildir, folder_name, deferreds):
+ store.add_mailbox(folder_name)
+
for mail in maildir:
if is_keep_file(mail):
continue
@@ -141,22 +131,23 @@ def add_mail_folder(account, maildir, folder_name, deferreds):
if 'R' in mail.get_flags():
flags = (MessageFlags.ANSWERED_FLAG,) + flags
- deferreds.append(mbx.addMessage(mail.as_string(), flags=flags, notify_just_mdoc=False))
+ deferreds.append(store.add_mail(folder_name, mail.as_string()))
+ # FIXME support flags
@defer.inlineCallbacks
def load_mails(args, mail_paths):
leap_session, soledad = args
- account = leap_session.account
+ store = leap_session.mail_store
deferreds = []
for path in mail_paths:
maildir = Maildir(path, factory=None)
- add_mail_folder(account, maildir, 'INBOX', deferreds)
+ add_mail_folder(store, maildir, 'INBOX', deferreds)
for mail_folder_name in maildir.list_folders():
mail_folder = maildir.get_folder(mail_folder_name)
- add_mail_folder(account, mail_folder, mail_folder_name, deferreds)
+ add_mail_folder(store, mail_folder, mail_folder_name, deferreds)
yield defer.DeferredList(deferreds)
defer.returnValue(args)
diff --git a/service/test/unit/maintenance/test_commands.py b/service/test/unit/maintenance/test_commands.py
index 6e097cea..8a573766 100644
--- a/service/test/unit/maintenance/test_commands.py
+++ b/service/test/unit/maintenance/test_commands.py
@@ -18,12 +18,13 @@ import email
from pixelated.maintenance import delete_all_mails, load_mails
from pixelated.bitmask_libraries.session import LeapSession
+from pixelated.adapter.mailstore import MailStore
from leap.mail.constants import MessageFlags
from leap.mail.imap.account import IMAPAccount
from leap.soledad.client import Soledad
from leap.soledad.common.document import SoledadDocument
from mock import MagicMock
-from os.path import join, dirname
+from os.path import join
from twisted.internet import defer, reactor
import pkg_resources
@@ -35,7 +36,9 @@ class TestCommands(unittest.TestCase):
self.soledad = MagicMock(spec=Soledad)
self.account = MagicMock(spec=IMAPAccount)
self.mailbox = MagicMock()
+ self.mail_store = MagicMock(spec=MailStore)
self.leap_session.account = self.account
+ self.leap_session.mail_store = self.mail_store
self.args = (self.leap_session, self.soledad)
@@ -77,7 +80,7 @@ class TestCommands(unittest.TestCase):
def test_load_mails_empty_path_list(self):
load_mails(self.args, [])
- self.assertFalse(self.mailbox.called)
+ self.assertFalse(self.mail_store.add_mailbox.called)
def test_load_mails_adds_mails(self):
# given