summaryrefslogtreecommitdiff
path: root/src/leap/mail/mail.py
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2015-06-25 10:45:46 -0400
committerKali Kaneko <kali@leap.se>2015-06-25 16:44:45 -0400
commitcc487c6bc77769079fc4cdc23b6ad2bdd7c22394 (patch)
tree3bef827ac8063874ec6678c53802ea1eb2ffeb02 /src/leap/mail/mail.py
parent9db1529e60cadff872cd3066e837e15413216b71 (diff)
[bug] avoid duplication of copies in draft folder
Although this draft-saving feature seems to be somehow brittle, since it breaks from time to time, the causes are different and subtle on each case. This time the bug is related to having the notify_just_mdoc (or fast_notifies as I'm tempted to call it in the future for more clarity) set to True by default in the APPENDS. Fast notifies break the "save draft" functionality because what Thunderbird does is an Append of the newest message, followed by deletion of the old message and a SEARCH by Message-ID. For this we need the headers-doc to be already inserted in the store. Since the fast-notify makes a *big* difference in terms of insertion times for serialized appends, I've opted for using a heuristic for detecting if it's the case of a Draft message, using a mozilla-specific header. If this is found, we set the notify_just_mdoc unconditionally to False. We'll deal with other MUAs on its due time. Releases: 0.4.0
Diffstat (limited to 'src/leap/mail/mail.py')
-rw-r--r--src/leap/mail/mail.py28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/leap/mail/mail.py b/src/leap/mail/mail.py
index b4602b3..faaabf6 100644
--- a/src/leap/mail/mail.py
+++ b/src/leap/mail/mail.py
@@ -37,6 +37,7 @@ 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
+from leap.mail.utils import lowerdict
logger = logging.getLogger(name=__name__)
@@ -570,11 +571,14 @@ class MessageCollection(object):
reflects when the message was received.
:type date: str
:param notify_just_mdoc:
- boolean passed to the wrapper.create method,
- to indicate whether we're interested in being notified when only
- the mdoc has been written (faster, but potentially unsafe), or we
- want to wait untill all the parts have been written.
+ 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), or on the contrary we want
+ to wait untill all the parts have been written.
Used by the imap mailbox implementation to get faster responses.
+ This will be ignored (and set to False) if a heuristic for a Draft
+ message is met, which currently is a specific mozilla header.
:type notify_just_mdoc: bool
:returns: a deferred that will fire with the UID of the inserted
@@ -590,8 +594,14 @@ class MessageCollection(object):
msg = self.adaptor.get_msg_from_string(Message, raw_msg)
wrapper = msg.get_wrapper()
+ headers = lowerdict(msg.get_headers())
+ moz_draft_hdr = "X-Mozilla-Draft-Info"
+ if moz_draft_hdr.lower() in headers:
+ log.msg("Setting fast notify to False, Draft detected")
+ notify_just_mdoc = False
+
if notify_just_mdoc:
- msgid = msg.get_headers()['message-id']
+ msgid = headers['message-id']
self._pending_inserts[msgid] = defer.Deferred()
if not self.is_mailbox_collection():
@@ -622,12 +632,6 @@ class MessageCollection(object):
d = self.mbox_indexer.create_table(self.mbox_uuid)
d.addBoth(lambda _: self.mbox_indexer.insert_doc(
self.mbox_uuid, doc_id))
- # XXX---------------------------------
- def print_inserted(r):
- print "INSERTED", r
- return r
- d.addCallback(print_inserted)
- # XXX---------------------------------
return d
d = wrapper.create(
@@ -636,7 +640,7 @@ class MessageCollection(object):
pending_inserts_dict=self._pending_inserts)
d.addCallback(insert_mdoc_id, wrapper)
d.addErrback(lambda failure: log.err(failure))
- #d.addCallback(self.cb_signal_unread_to_ui)
+ d.addCallback(self.cb_signal_unread_to_ui)
return d