From 8915db2e1c1a339cf36ae0e28da627bb1a8e040e Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Thu, 21 May 2015 12:47:27 -0400 Subject: [feature] post-sync mail processing hooks using the new soledad plugin capablity, mail hooks to the post-sync event by subscribing to the Meta-Doc type of documents. In this way, we can create the uid tables and the uid entries needed to keep local indexes for mail that has been processed in another instance. however, this won't prevent a conflict if a given mail is received and processed in two different instances. that is a problem that we still have to deal with. Resolves: #6996 Releases: 0.4.0 --- src/leap/mail/imap/service/imap.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/leap/mail/imap') diff --git a/src/leap/mail/imap/service/imap.py b/src/leap/mail/imap/service/imap.py index 370c513..e401283 100644 --- a/src/leap/mail/imap/service/imap.py +++ b/src/leap/mail/imap/service/imap.py @@ -35,6 +35,7 @@ from leap.common.events import emit, catalog from leap.common.check import leap_assert_type, leap_check from leap.mail.imap.account import IMAPAccount from leap.mail.imap.server import LEAPIMAPServer +from leap.mail.plugins import soledad_sync_hooks from leap.soledad.client import Soledad @@ -91,10 +92,17 @@ class LeapIMAPFactory(ServerFactory): theAccount = IMAPAccount(uuid, soledad) self.theAccount = theAccount + self._initialize_sync_hooks() self._connections = defaultdict() # XXX how to pass the store along? + def _initialize_sync_hooks(self): + soledad_sync_hooks.post_sync_uid_reindexer.set_account(self.theAccount) + + def _teardown_sync_hooks(self): + soledad_sync_hooks.post_sync_uid_reindexer.set_account(None) + def buildProtocol(self, addr): """ Return a protocol suitable for the job. @@ -128,6 +136,7 @@ class LeapIMAPFactory(ServerFactory): # mark account as unusable, so any imap command will fail # with unauth state. self.theAccount.end_session() + self._teardown_sync_hooks() # TODO should wait for all the pending deferreds, # the twisted way! -- cgit v1.2.3 From 4c12d05d063d42171808c432bee90de67c4042b6 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Thu, 28 May 2015 19:03:24 -0400 Subject: [refactor] move hooks to account --- src/leap/mail/imap/account.py | 7 +++++-- src/leap/mail/imap/service/imap.py | 13 +------------ 2 files changed, 6 insertions(+), 14 deletions(-) (limited to 'src/leap/mail/imap') diff --git a/src/leap/mail/imap/account.py b/src/leap/mail/imap/account.py index ccb4b75..cc56fff 100644 --- a/src/leap/mail/imap/account.py +++ b/src/leap/mail/imap/account.py @@ -58,7 +58,6 @@ class IMAPAccount(object): implements(imap4.IAccount, imap4.INamespacePresenter) selected = None - session_ended = False def __init__(self, user_id, store, d=defer.Deferred()): """ @@ -98,7 +97,11 @@ class IMAPAccount(object): Right now it's called from the client backend. """ # TODO move its use to the service shutdown in leap.mail - self.session_ended = True + self.account.end_session() + + @property + def session_ended(self): + return self.account.session_ended def callWhenReady(self, cb, *args, **kw): """ diff --git a/src/leap/mail/imap/service/imap.py b/src/leap/mail/imap/service/imap.py index e401283..92d05cc 100644 --- a/src/leap/mail/imap/service/imap.py +++ b/src/leap/mail/imap/service/imap.py @@ -32,11 +32,9 @@ from twisted.python import log logger = logging.getLogger(__name__) from leap.common.events import emit, catalog -from leap.common.check import leap_assert_type, leap_check +from leap.common.check import leap_check from leap.mail.imap.account import IMAPAccount from leap.mail.imap.server import LEAPIMAPServer -from leap.mail.plugins import soledad_sync_hooks -from leap.soledad.client import Soledad DO_MANHOLE = os.environ.get("LEAP_MAIL_MANHOLE", None) @@ -92,17 +90,9 @@ class LeapIMAPFactory(ServerFactory): theAccount = IMAPAccount(uuid, soledad) self.theAccount = theAccount - self._initialize_sync_hooks() - self._connections = defaultdict() # XXX how to pass the store along? - def _initialize_sync_hooks(self): - soledad_sync_hooks.post_sync_uid_reindexer.set_account(self.theAccount) - - def _teardown_sync_hooks(self): - soledad_sync_hooks.post_sync_uid_reindexer.set_account(None) - def buildProtocol(self, addr): """ Return a protocol suitable for the job. @@ -136,7 +126,6 @@ class LeapIMAPFactory(ServerFactory): # mark account as unusable, so any imap command will fail # with unauth state. self.theAccount.end_session() - self._teardown_sync_hooks() # TODO should wait for all the pending deferreds, # the twisted way! -- cgit v1.2.3