summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/pixelated/adapter/listeners/mailbox_indexer_listener.py8
-rw-r--r--service/pixelated/adapter/services/mail_service.py7
-rw-r--r--service/pixelated/config/services.py28
-rw-r--r--service/pixelated/resources/mails_resource.py10
-rw-r--r--service/test/support/integration/app_test_client.py19
-rw-r--r--service/test/unit/adapter/test_mail_service.py2
6 files changed, 31 insertions, 43 deletions
diff --git a/service/pixelated/adapter/listeners/mailbox_indexer_listener.py b/service/pixelated/adapter/listeners/mailbox_indexer_listener.py
index ce056a3c..8e7eca1a 100644
--- a/service/pixelated/adapter/listeners/mailbox_indexer_listener.py
+++ b/service/pixelated/adapter/listeners/mailbox_indexer_listener.py
@@ -52,3 +52,11 @@ class MailboxIndexerListener(object):
def __repr__(self):
return 'MailboxListener: ' + self.mailbox_name
+
+
+@defer.inlineCallbacks
+def listen_all_mailboxes(account, search_engine, mail_store):
+ MailboxIndexerListener.SEARCH_ENGINE = search_engine
+ mailboxes = yield account.account.list_all_mailbox_names()
+ for mailbox_name in mailboxes:
+ yield MailboxIndexerListener.listen(account, mailbox_name, mail_store)
diff --git a/service/pixelated/adapter/services/mail_service.py b/service/pixelated/adapter/services/mail_service.py
index 4623a5eb..d47bdd87 100644
--- a/service/pixelated/adapter/services/mail_service.py
+++ b/service/pixelated/adapter/services/mail_service.py
@@ -21,8 +21,7 @@ from pixelated.adapter.services.tag_service import extract_reserved_tags
class MailService(object):
- def __init__(self, mailboxes, mail_sender, mail_store, soledad_querier, search_engine):
- self.mailboxes = mailboxes
+ def __init__(self, mail_sender, mail_store, soledad_querier, search_engine):
self.mail_store = mail_store
self.querier = soledad_querier
self.search_engine = search_engine
@@ -122,9 +121,9 @@ class MailService(object):
else:
yield self.mail_store.move_mail_to_mailbox(mail_id, 'TRASH')
+ @defer.inlineCallbacks
def recover_mail(self, mail_id):
- recovered_mail = self.mailboxes.move_to_inbox(mail_id)
- self.search_engine.index_mail(recovered_mail)
+ yield self.mail_store.move_mail_to_mailbox(mail_id, 'INBOX')
@defer.inlineCallbacks
def delete_permanent(self, mail_id):
diff --git a/service/pixelated/config/services.py b/service/pixelated/config/services.py
index 2decaab1..4637a6f9 100644
--- a/service/pixelated/config/services.py
+++ b/service/pixelated/config/services.py
@@ -2,11 +2,10 @@ from pixelated.adapter.mailstore.searchable_mailstore import SearchableMailStore
from pixelated.adapter.services.mail_service import MailService
from pixelated.adapter.model.mail import InputMail
from pixelated.adapter.services.mail_sender import MailSender
-from pixelated.adapter.services.mailboxes import Mailboxes
from pixelated.adapter.soledad.soledad_querier import SoledadQuerier
from pixelated.adapter.search import SearchEngine
from pixelated.adapter.services.draft_service import DraftService
-from pixelated.adapter.listeners.mailbox_indexer_listener import MailboxIndexerListener
+from pixelated.adapter.listeners.mailbox_indexer_listener import listen_all_mailboxes
from twisted.internet import defer
@@ -26,18 +25,12 @@ class Services(object):
self.wrap_mail_store_with_indexing_mail_store(leap_session)
- pixelated_mailboxes = Mailboxes(
- leap_session.account,
- leap_session.mail_store,
- soledad_querier,
- self.search_engine)
- yield pixelated_mailboxes.index_mailboxes()
+ yield listen_all_mailboxes(leap_session.account, self.search_engine, leap_session.mail_store)
- self.mail_service = yield self.setup_mail_service(
+ self.mail_service = self.setup_mail_service(
leap_session,
soledad_querier,
- self.search_engine,
- pixelated_mailboxes)
+ self.search_engine)
self.keymanager = leap_session.nicknym
self.draft_service = self.setup_draft_service(leap_session.mail_store)
@@ -60,22 +53,19 @@ class Services(object):
key = yield soledad_querier.get_index_masterkey()
print 'The key len is: %s' % len(key)
search_engine = SearchEngine(key, agent_home=leap_home)
- MailboxIndexerListener.SEARCH_ENGINE = search_engine
self.search_engine = search_engine
- @defer.inlineCallbacks
- def setup_mail_service(self, leap_session, soledad_querier, search_engine, pixelated_mailboxes):
- if False: # FIXME
- yield pixelated_mailboxes.add_welcome_mail_for_fresh_user()
+ def setup_mail_service(self, leap_session, soledad_querier, search_engine):
+ # if False: FIXME
+ # yield pixelated_mailboxes.add_welcome_mail_for_fresh_user()
pixelated_mail_sender = MailSender(
leap_session.account_email(),
leap_session.smtp)
- defer.returnValue(MailService(
- pixelated_mailboxes,
+ return MailService(
pixelated_mail_sender,
leap_session.mail_store,
soledad_querier,
- search_engine))
+ search_engine)
def setup_draft_service(self, mail_store):
return DraftService(mail_store)
diff --git a/service/pixelated/resources/mails_resource.py b/service/pixelated/resources/mails_resource.py
index e18fe2c3..ce05ff3a 100644
--- a/service/pixelated/resources/mails_resource.py
+++ b/service/pixelated/resources/mails_resource.py
@@ -2,7 +2,7 @@ import json
from pixelated.adapter.services.mail_sender import SMTPDownException
from pixelated.adapter.model.mail import InputMail
from twisted.web.server import NOT_DONE_YET
-from pixelated.resources import respond_json, respond_json_deferred
+from pixelated.resources import respond_json_deferred
from twisted.web.resource import Resource
from twisted.web import server
from twisted.internet import defer
@@ -85,9 +85,13 @@ class MailsRecoverResource(Resource):
def render_POST(self, request):
idents = json.loads(request.content.read())['idents']
+ deferreds = []
for ident in idents:
- self._mail_service.recover_mail(ident)
- return respond_json(None, request)
+ deferreds.append(self._mail_service.recover_mail(ident))
+ d = defer.gatherResults(deferreds, consumeErrors=True)
+ d.addCallback(lambda _: respond_json_deferred(None, request))
+ d.addErrback(lambda _: respond_json_deferred(None, request, status_code=500))
+ return NOT_DONE_YET
class MailsResource(Resource):
diff --git a/service/test/support/integration/app_test_client.py b/service/test/support/integration/app_test_client.py
index f508109d..fe9eaffd 100644
--- a/service/test/support/integration/app_test_client.py
+++ b/service/test/support/integration/app_test_client.py
@@ -38,7 +38,6 @@ from pixelated.adapter.model.mail import PixelatedMail
from pixelated.adapter.search import SearchEngine
from pixelated.adapter.services.draft_service import DraftService
from pixelated.adapter.services.mail_service import MailService
-from pixelated.adapter.services.mailboxes import Mailboxes
from pixelated.adapter.soledad.soledad_querier import SoledadQuerier
from pixelated.resources.root_resource import RootResource
from test.support.integration.model import MailBuilder
@@ -77,10 +76,9 @@ class AppTestClient(object):
account_ready_cb = defer.Deferred()
self.account = IMAPAccount(self.ACCOUNT, self.soledad, account_ready_cb)
yield account_ready_cb
- self.mailboxes = Mailboxes(self.account, self.mail_store, self.soledad_querier, self.search_engine)
self.draft_service = DraftService(self.mail_store)
- self.mail_service = self._create_mail_service(self.mailboxes, self.mail_sender, self.mail_store, self.soledad_querier, self.search_engine)
+ self.mail_service = self._create_mail_service(self.mail_sender, self.mail_store, self.soledad_querier, self.search_engine)
mails = yield self.mail_service.all_mails()
self.search_engine.index_mails(mails)
@@ -143,11 +141,6 @@ class AppTestClient(object):
def add_mail_to_inbox(self, input_mail):
mail = yield self.mail_store.add_mail('INBOX', input_mail.raw)
defer.returnValue(mail)
- # inbox = yield self.mailboxes.inbox
- # mail = yield inbox.add(input_mail)
- # if input_mail.tags:
- # mail.update_tags(input_mail.tags)
- # self.search_engine.index_mail(mail)
@defer.inlineCallbacks
def add_multiple_to_mailbox(self, num, mailbox='', flags=[], tags=[], to='recipient@to.com', cc='recipient@cc.com', bcc='recipient@bcc.com'):
@@ -167,12 +160,6 @@ class AppTestClient(object):
yield self.mail_store.update_mail(mail)
mails.append(mail)
- # mbx = yield self.mailboxes._create_or_get(mailbox)
- # mail = yield mbx.add(input_mail)
- # mails.append(mail)
- # mail.update_tags(input_mail.tags) if tags else None
- # self.search_engine.index_mails(mails) if tags else None
-
defer.returnValue(mails)
def _create_soledad_querier(self, soledad, index_key):
@@ -185,8 +172,8 @@ class AppTestClient(object):
mail_sender.sendmail.side_effect = lambda mail: succeed(mail)
return mail_sender
- def _create_mail_service(self, mailboxes, mail_sender, mail_store, soledad_querier, search_engine):
- mail_service = MailService(mailboxes, mail_sender, mail_store, soledad_querier, search_engine)
+ def _create_mail_service(self, mail_sender, mail_store, soledad_querier, search_engine):
+ mail_service = MailService(mail_sender, mail_store, soledad_querier, search_engine)
return mail_service
def _generate_soledad_test_folder_name(self, soledad_test_folder='/tmp/soledad-test/test'):
diff --git a/service/test/unit/adapter/test_mail_service.py b/service/test/unit/adapter/test_mail_service.py
index 0f4ea032..43fd21d1 100644
--- a/service/test/unit/adapter/test_mail_service.py
+++ b/service/test/unit/adapter/test_mail_service.py
@@ -38,7 +38,7 @@ class TestMailService(unittest.TestCase):
self.mail_sender = mock()
self.search_engine = mock()
- self.mail_service = MailService(self.mailboxes, self.mail_sender, self.mail_store, self.querier, self.search_engine)
+ self.mail_service = MailService(self.mail_sender, self.mail_store, self.querier, self.search_engine)
def tearDown(self):
unstub()