summaryrefslogtreecommitdiff
path: root/src/leap/mail/mail.py
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2015-06-18 23:20:45 -0400
committerKali Kaneko <kali@leap.se>2015-06-22 11:39:20 -0400
commitc8dfed5b5f4ccb87003119f14e189566219365bb (patch)
tree54ac88958970358dc02c808c8f831d3cd254baaa /src/leap/mail/mail.py
parent1348798e88c6026f57ff938c59a2dce979a9a891 (diff)
[bug] fixes for display attachments and move between folders0.4.0-alpha
- Add errback handling to catch properly errors that were not allowing the complete insertion of the parts for a given message. Fixes blank attachments and moving of messages to different folders. - Force overwritting of mdoc when it is a copy. This was avoiding a message to be copied back to a folder from where it already had been copied to another (since the mdoc was already existing there, with the same doc_id, which was forbidding the creation of the new one). This case also needs special care in the indexer, since we have to delete the old hash entry first. Closes: #7178, #7158
Diffstat (limited to 'src/leap/mail/mail.py')
-rw-r--r--src/leap/mail/mail.py49
1 files changed, 45 insertions, 4 deletions
diff --git a/src/leap/mail/mail.py b/src/leap/mail/mail.py
index 8cb0b4a..bf5b34d 100644
--- a/src/leap/mail/mail.py
+++ b/src/leap/mail/mail.py
@@ -25,6 +25,7 @@ import time
import weakref
from twisted.internet import defer
+from twisted.python import log
from leap.common.check import leap_assert_type
from leap.common.events import emit, catalog
@@ -559,7 +560,7 @@ class MessageCollection(object):
"""
Add a message to this collection.
- :param raw_message: the raw message
+ :param raw_msg: the raw message
:param flags: tuple of flags for this message
:param tags: tuple of tags for this message
:param date:
@@ -619,7 +620,7 @@ class MessageCollection(object):
# so workaround is to make sure we always check for it before
# inserting the doc. I should debug into the real cause.
d = self.mbox_indexer.create_table(self.mbox_uuid)
- d.addCallback(lambda _: self.mbox_indexer.insert_doc(
+ d.addBoth(lambda _: self.mbox_indexer.insert_doc(
self.mbox_uuid, doc_id))
return d
@@ -664,12 +665,52 @@ class MessageCollection(object):
Copy the message to another collection. (it only makes sense for
mailbox collections)
"""
+ # TODO should CHECK first if the mdoc is present in the mailbox
+ # WITH a Deleted flag... and just simply remove the flag...
+ # Another option is to delete the previous mdoc if it already exists
+ # (so we get a new UID)
+
if not self.is_mailbox_collection():
raise NotImplementedError()
+ def delete_mdoc_entry_and_insert(failure, mbox_uuid, doc_id):
+ d = self.mbox_indexer.delete_doc_by_hash(mbox_uuid, doc_id)
+ d.addCallback(lambda _: self.mbox_indexer.insert_doc(
+ new_mbox_uuid, doc_id))
+ return d
+
def insert_copied_mdoc_id(wrapper_new_msg):
- return self.mbox_indexer.insert_doc(
- new_mbox_uuid, wrapper_new_msg.mdoc.doc_id)
+ # XXX FIXME -- since this is already saved, the future_doc_id
+ # should be already copied into the doc_id!
+ # Investigate why we are not receiving the already saved doc_id
+ doc_id = wrapper_new_msg.mdoc.doc_id
+ if not doc_id:
+ doc_id = wrapper_new_msg.mdoc._future_doc_id
+
+ def insert_conditionally(uid, mbox_uuid, doc_id):
+ indexer = self.mbox_indexer
+ if uid:
+ d = indexer.delete_doc_by_hash(mbox_uuid, doc_id)
+ d.addCallback(lambda _: indexer.insert_doc(
+ new_mbox_uuid, doc_id))
+ return d
+ else:
+ d = indexer.insert_doc(mbox_uuid, doc_id)
+ return d
+
+ def log_result(result):
+ return result
+
+ def insert_doc(_, mbox_uuid, doc_id):
+ d = self.mbox_indexer.get_uid_from_doc_id(mbox_uuid, doc_id)
+ d.addCallback(insert_conditionally, mbox_uuid, doc_id)
+ d.addErrback(lambda err: log.failure(err))
+ d.addCallback(log_result)
+ return d
+
+ d = self.mbox_indexer.create_table(new_mbox_uuid)
+ d.addBoth(insert_doc, new_mbox_uuid, doc_id)
+ return d
wrapper = msg.get_wrapper()