From e2ce3d095549e4fd06c104a305a3b698d0c45187 Mon Sep 17 00:00:00 2001 From: Ruben Pollan Date: Thu, 24 Sep 2015 11:48:04 +0200 Subject: [bug] signal expired auth token to the GUI In case of InvalidAuthTokeError from soledad sync we need signal the GUI, so it will request her to log in again. - Resolves: #7430 --- src/leap/mail/incoming/service.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/leap/mail/incoming/service.py b/src/leap/mail/incoming/service.py index d554c51..d8b91ba 100644 --- a/src/leap/mail/incoming/service.py +++ b/src/leap/mail/incoming/service.py @@ -228,18 +228,18 @@ class IncomingMail(Service): def _log_synced(result): log.msg('FETCH soledad SYNCED.') return result - try: - log.msg('FETCH: syncing soledad...') - d = self._soledad.sync() - d.addCallback(_log_synced) - return d - # TODO is this still raised? or should we do failure.trap - # instead? - except InvalidAuthTokenError: + + def _signal_invalid_auth(failure): + failure.trap(InvalidAuthTokenError) # if the token is invalid, send an event so the GUI can # disable mail and show an error message. emit_async(catalog.SOLEDAD_INVALID_AUTH_TOKEN) + log.msg('FETCH: syncing soledad...') + d = self._soledad.sync() + d.addCallbacks(_log_synced, _signal_invalid_auth) + return d + def _signal_fetch_to_ui(self, doclist): """ Send leap events to ui. -- cgit v1.2.3 From 20273e82dfb66dcf1d2dac2df217ba835a622c38 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Mon, 28 Sep 2015 16:03:43 -0400 Subject: [bug] fail gracefully if fetch fails Related: #7495 --- src/leap/mail/adaptors/soledad.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src') diff --git a/src/leap/mail/adaptors/soledad.py b/src/leap/mail/adaptors/soledad.py index d114707..8de83f7 100644 --- a/src/leap/mail/adaptors/soledad.py +++ b/src/leap/mail/adaptors/soledad.py @@ -939,15 +939,33 @@ class SoledadMailAdaptor(SoledadIndexMixin): d = defer.gatherResults(d_docs) return d + def _err_log_failure_part_docs(failure): + # See https://leap.se/code/issues/7495. + # This avoids blocks, but the real cause still needs to be + # isolated (0.9.0rc3) -- kali + log.msg("BUG ---------------------------------------------------") + log.msg("BUG: Error while retrieving part docs for mdoc id %s" % + mdoc_id) + log.err(failure) + log.msg("BUG (please report above info) ------------------------") + return [] + + def _err_log_cannot_find_msg(failure): + log.msg("BUG: Error while getting msg (uid=%s)" % uid) + return None + if get_cdocs: d = store.get_doc(mdoc_id) d.addCallback(wrap_meta_doc) d.addCallback(get_part_docs_from_mdoc_wrapper) + d.addErrback(_err_log_failure_part_docs) + else: d = get_parts_doc_from_mdoc_id() d.addCallback(self._get_msg_from_variable_doc_list, msg_class=MessageClass, uid=uid) + d.addErrback(_err_log_cannot_find_msg) return d def _get_msg_from_variable_doc_list(self, doc_list, msg_class, uid=None): -- cgit v1.2.3 From 8fde125086c100434356c4413560871d9cbe8dfb Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Wed, 30 Sep 2015 22:44:57 -0400 Subject: [bug] fix slow appends we were adding listeners for each mailbox instance, which was making appends particularly slow, since the method that gets current count and recent count is expensive and was being called way too many times. --- src/leap/mail/imap/mailbox.py | 39 ++++++++++++++++++++++++++++++++++----- src/leap/mail/imap/server.py | 6 ------ 2 files changed, 34 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/leap/mail/imap/mailbox.py b/src/leap/mail/imap/mailbox.py index c7accbb..bfc0bfc 100644 --- a/src/leap/mail/imap/mailbox.py +++ b/src/leap/mail/imap/mailbox.py @@ -77,6 +77,32 @@ INIT_FLAGS = (MessageFlags.SEEN_FLAG, MessageFlags.ANSWERED_FLAG, MessageFlags.LIST_FLAG) +def make_collection_listener(mailbox): + """ + Wrap a mailbox in a class that can be hashed according to the mailbox name. + + This means that dicts or sets will use this new equality rule, so we won't + collect multiple instances of the same mailbox in collections like the + MessageCollection set where we keep track of listeners. + """ + + class HashableMailbox(object): + + def __init__(self, mbox): + self.mbox = mbox + + def __hash__(self): + return hash(self.mbox.mbox_name) + + def __eq__(self, other): + return self.mbox.mbox_name == other.mbox.mbox_name + + def notify_new(self): + self.mbox.notify_new() + + return HashableMailbox(mailbox) + + class IMAPMailbox(object): """ A Soledad-backed IMAP mailbox. @@ -118,7 +144,7 @@ class IMAPMailbox(object): self.rw = rw self._uidvalidity = None self.collection = collection - self.collection.addListener(self) + self.collection.addListener(make_collection_listener(self)) @property def mbox_name(self): @@ -383,6 +409,7 @@ class IMAPMailbox(object): def notify_new(self, *args): """ Notify of new messages to all the listeners. + This will be called indirectly by the underlying collection, that will notify this IMAPMailbox whenever there are changes in the number of messages in the collection, since we have added ourselves to the @@ -405,13 +432,15 @@ class IMAPMailbox(object): def _get_notify_count(self): """ - Get message count and recent count for this mailbox - Executed in a separate thread. Called from notify_new. + Get message count and recent count for this mailbox. :return: a deferred that will fire with a tuple, with number of messages and number of recent messages. :rtype: Deferred """ + # XXX this is way too expensive in cases like multiple APPENDS. + # We should have a way of keep a cache or do a self-increment for that + # kind of calls. d_exists = defer.maybeDeferred(self.getMessageCount) d_recent = defer.maybeDeferred(self.getRecentCount) d_list = [d_exists, d_recent] @@ -875,8 +904,8 @@ class IMAPMailbox(object): uid when the copy succeed. :rtype: Deferred """ - if PROFILE_CMD: - do_profile_cmd(d, "COPY") + # if PROFILE_CMD: + # do_profile_cmd(d, "COPY") # A better place for this would be the COPY/APPEND dispatcher # in server.py, but qtreactor hangs when I do that, so this seems diff --git a/src/leap/mail/imap/server.py b/src/leap/mail/imap/server.py index 8f14936..99e7174 100644 --- a/src/leap/mail/imap/server.py +++ b/src/leap/mail/imap/server.py @@ -269,12 +269,6 @@ class LEAPIMAPServer(imap4.IMAP4Server): select_FETCH = (do_FETCH, imap4.IMAP4Server.arg_seqset, imap4.IMAP4Server.arg_fetchatt) - def notifyNew(self, ignored=None): - """ - Notify new messages to listeners. - """ - reactor.callFromThread(self.mbox.notify_new) - def _cbSelectWork(self, mbox, cmdName, tag): """ Callback for selectWork -- cgit v1.2.3