summaryrefslogtreecommitdiff
path: root/src/leap/mail/imap
diff options
context:
space:
mode:
Diffstat (limited to 'src/leap/mail/imap')
-rw-r--r--src/leap/mail/imap/mailbox.py41
1 files changed, 26 insertions, 15 deletions
diff --git a/src/leap/mail/imap/mailbox.py b/src/leap/mail/imap/mailbox.py
index 72f5a43..139ae66 100644
--- a/src/leap/mail/imap/mailbox.py
+++ b/src/leap/mail/imap/mailbox.py
@@ -320,6 +320,24 @@ class IMAPMailbox(object):
:param date: timestamp
:type date: str, or None
+ :param notify_just_mdoc:
+ boolean passed to the wrapper.create method, to indicate whether
+ we're insterested in being notified right after the mdoc has been
+ written (as it's the first doc to be written, and quite small, this
+ is faster, though potentially unsafe).
+ Setting it to True improves a *lot* the responsiveness of the
+ APPENDS: we just need to be notified when the mdoc is saved, and
+ let's just expect that the other parts are doing just fine. This
+ will not catch any errors when the inserts of the other parts
+ fail, but on the other hand allows us to return very quickly,
+ which seems a good compromise given that we have to serialize the
+ appends.
+ However, some operations like the saving of drafts need to wait for
+ all the parts to be saved, so if some heuristics are met down in
+ the call chain a Draft message will unconditionally set this flag
+ to False, and therefore ignoring the setting of this flag here.
+ :type notify_just_mdoc: bool
+
:return: a deferred that will be triggered with the UID of the added
message.
"""
@@ -327,18 +345,14 @@ class IMAPMailbox(object):
# TODO have a look at the cases for internal date in the rfc
# XXX we could treat the message as an IMessage from here
+ # TODO change notify_just_mdoc to something more meaningful, like
+ # fast_insert_notify?
+
# TODO notify_just_mdoc *sometimes* make the append tests fail.
# have to find a better solution for this. A workaround could probably
# be to have a list of the ongoing deferreds related to append, so that
# we queue for later all the requests having to do with these.
- # notify_just_mdoc=True: feels HACKY, but improves a *lot* the
- # responsiveness of the APPENDS: we just need to be notified when the
- # mdoc is saved, and let's hope that the other parts are doing just
- # fine. This will not catch any errors when the inserts of the other
- # parts fail, but on the other hand allows us to return very quickly,
- # which seems a good compromise given that we have to serialize the
- # appends.
# A better solution will probably involve implementing MULTIAPPEND
# extension or patching imap server to support pipelining.
@@ -355,9 +369,11 @@ class IMAPMailbox(object):
if date is None:
date = formatdate(time.time())
- # TODO add notify_new as a callback here...
- return self.collection.add_msg(message, flags, date=date,
- notify_just_mdoc=notify_just_mdoc)
+ d = self.collection.add_msg(message, flags, date=date,
+ notify_just_mdoc=notify_just_mdoc)
+ d.addCallback(self.notify_new)
+ d.addErrback(lambda failure: log.err(failure))
+ return d
def notify_new(self, *args):
"""
@@ -504,13 +520,8 @@ class IMAPMailbox(object):
getimapmsg = self.get_imap_message
def get_imap_messages_for_range(msg_range):
- print
- print
- print
- print "GETTING FOR RANGE", msg_range
def _get_imap_msg(messages):
- print "GETTING IMAP MSG FOR", messages
d_imapmsg = []
for msg in messages:
d_imapmsg.append(getimapmsg(msg))