summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2015-10-29 12:13:53 -0400
committerKali Kaneko <kali@leap.se>2015-10-29 12:13:53 -0400
commitfb33a21c23078ddc9cd4d71a7778126479fcaafd (patch)
treeef0129c20ee5f8df79e00efa787ed28921f901d6 /src
parente714515718cc36fa1e31f9cf90a9a9728d4a4fbd (diff)
parent9ba85bcc7724f1d9abc3ae200326e5f0a8597374 (diff)
Merge tag '0.4.0' into debian/experimental
Tag leap.mail version 0.4.0
Diffstat (limited to 'src')
-rw-r--r--src/leap/mail/adaptors/soledad.py18
-rw-r--r--src/leap/mail/imap/mailbox.py39
-rw-r--r--src/leap/mail/imap/server.py6
-rw-r--r--src/leap/mail/incoming/service.py16
4 files changed, 60 insertions, 19 deletions
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):
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
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.