summaryrefslogtreecommitdiff
path: root/mail/src
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2015-05-28 19:03:24 -0400
committerKali Kaneko <kali@leap.se>2015-06-05 16:50:46 -0400
commit16dedad1a467693aebf3c8f2a100bf8c8bef9ae3 (patch)
treeb949f2fa92a0556f56ad3e1892c3c6539d1a08d0 /mail/src
parentece1f50d25dd9810fedd7498557dd2048fba2540 (diff)
[refactor] move hooks to account
Diffstat (limited to 'mail/src')
-rw-r--r--mail/src/leap/mail/imap/account.py7
-rw-r--r--mail/src/leap/mail/imap/service/imap.py13
-rw-r--r--mail/src/leap/mail/incoming/service.py1
-rw-r--r--mail/src/leap/mail/mail.py22
-rw-r--r--mail/src/leap/mail/sync_hooks.py2
5 files changed, 30 insertions, 15 deletions
diff --git a/mail/src/leap/mail/imap/account.py b/mail/src/leap/mail/imap/account.py
index ccb4b75..cc56fff 100644
--- a/mail/src/leap/mail/imap/account.py
+++ b/mail/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/mail/src/leap/mail/imap/service/imap.py b/mail/src/leap/mail/imap/service/imap.py
index e401283..92d05cc 100644
--- a/mail/src/leap/mail/imap/service/imap.py
+++ b/mail/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!
diff --git a/mail/src/leap/mail/incoming/service.py b/mail/src/leap/mail/incoming/service.py
index be37396..23aff3d 100644
--- a/mail/src/leap/mail/incoming/service.py
+++ b/mail/src/leap/mail/incoming/service.py
@@ -246,6 +246,7 @@ class IncomingMail(Service):
:returns: doclist
:rtype: iterable
"""
+ # FIXME WTF len(doclist) is 69?
doclist = first(doclist) # gatherResults pass us a list
if doclist:
fetched_ts = time.mktime(time.gmtime())
diff --git a/mail/src/leap/mail/mail.py b/mail/src/leap/mail/mail.py
index bab73cb..fe8226e 100644
--- a/mail/src/leap/mail/mail.py
+++ b/mail/src/leap/mail/mail.py
@@ -34,6 +34,7 @@ from leap.mail.adaptors.soledad import SoledadMailAdaptor
from leap.mail.constants import INBOX_NAME
from leap.mail.constants import MessageFlags
from leap.mail.mailbox_indexer import MailboxIndexer
+from leap.mail.plugins import soledad_sync_hooks
from leap.mail.utils import find_charset, CaseInsensitiveDict
logger = logging.getLogger(name=__name__)
@@ -802,10 +803,17 @@ class Account(object):
self.adaptor = self.adaptor_class()
self.mbox_indexer = MailboxIndexer(self.store)
+ # This flag is only used from the imap service for the moment.
+ # In the future, we should prevent any public method to continue if
+ # this is set to True. Also, it would be good to plug to the
+ # authentication layer.
+ self.session_ended = False
+
self.deferred_initialization = defer.Deferred()
self._ready_cb = ready_cb
self._init_d = self._initialize_storage()
+ self._initialize_sync_hooks()
def _initialize_storage(self):
@@ -834,6 +842,14 @@ class Account(object):
self.deferred_initialization.addCallback(cb, *args, **kw)
return self.deferred_initialization
+ # Sync hooks
+
+ def _initialize_sync_hooks(self):
+ soledad_sync_hooks.post_sync_uid_reindexer.set_account(self)
+
+ def _teardown_sync_hooks(self):
+ soledad_sync_hooks.post_sync_uid_reindexer.set_account(None)
+
#
# Public API Starts
#
@@ -946,3 +962,9 @@ class Account(object):
:rtype: MessageCollection
"""
raise NotImplementedError()
+
+ # Session handling
+
+ def end_session(self):
+ self._teardown_sync_hooks()
+ self.session_ended = True
diff --git a/mail/src/leap/mail/sync_hooks.py b/mail/src/leap/mail/sync_hooks.py
index b5bded5..3cf858b 100644
--- a/mail/src/leap/mail/sync_hooks.py
+++ b/mail/src/leap/mail/sync_hooks.py
@@ -75,7 +75,7 @@ class MailProcessingPostSyncHook(object):
self._pending_docs.append(doc_id)
def _make_uid_index(self, mdoc_id):
- indexer = self._account.account.mbox_indexer
+ indexer = self._account.mbox_indexer
mbox_uuid = _get_mbox_uuid(mdoc_id)
if mbox_uuid:
chash = _get_chash_from_mdoc(mdoc_id)