summaryrefslogtreecommitdiff
path: root/src/leap/mail
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2015-01-27 14:13:55 -0400
committerKali Kaneko <kali@leap.se>2015-02-11 14:05:44 -0400
commit3e723f7a003f72a33d761874e64cbce0604d37a9 (patch)
tree4f1d4def836dbdfea9a9efb9787f06ac1535ea42 /src/leap/mail
parentd8b078504b522add8542ebe3bdbe4da39e4ffaac (diff)
implement copy interface
Diffstat (limited to 'src/leap/mail')
-rw-r--r--src/leap/mail/adaptors/soledad.py28
-rw-r--r--src/leap/mail/imap/mailbox.py4
-rw-r--r--src/leap/mail/mail.py18
3 files changed, 34 insertions, 16 deletions
diff --git a/src/leap/mail/adaptors/soledad.py b/src/leap/mail/adaptors/soledad.py
index 4dc02a1..721f25e 100644
--- a/src/leap/mail/adaptors/soledad.py
+++ b/src/leap/mail/adaptors/soledad.py
@@ -16,6 +16,7 @@
"""
Soledadad MailAdaptor module.
"""
+import logging
import re
from collections import defaultdict
from email import message_from_string
@@ -512,15 +513,30 @@ class MessageWrapper(object):
d.append(self.fdoc.delete(store))
return defer.gatherResults(d)
- def copy(self, store, newmailbox):
+ def copy(self, store, new_mbox_uuid):
"""
Return a copy of this MessageWrapper in a new mailbox.
+
+ :param store: an instance of Soledad, or anything that behaves alike.
+ :param new_mbox_uuid: the uuid of the mailbox where we are copying this
+ message to.
+ :type new_mbox_uuid: str
+ :rtype: MessageWrapper
"""
- # 1. copy the fdoc, mdoc
- # 2. remove the doc_id of that fdoc
- # 3. create it (with new doc_id)
- # 4. return new wrapper (new meta too!)
- raise NotImplementedError()
+ new_mdoc = self.mdoc.serialize()
+ new_fdoc = self.fdoc.serialize()
+
+ # the future doc_ids is properly set because we modified
+ # the pointers in mdoc, which has precedence.
+ new_wrapper = MessageWrapper(new_mdoc, new_fdoc, None, None)
+ new_wrapper.hdoc = self.hdoc
+ new_wrapper.cdocs = self.cdocs
+ new_wrapper.set_mbox_uuid(new_mbox_uuid)
+
+ # XXX could flag so that it only creates mdoc/fdoc...
+ d = new_wrapper.create(store)
+ d.addCallback(lambda result: new_wrapper)
+ return d
def set_mbox_uuid(self, mbox_uuid):
"""
diff --git a/src/leap/mail/imap/mailbox.py b/src/leap/mail/imap/mailbox.py
index c91f127..1bc530e 100644
--- a/src/leap/mail/imap/mailbox.py
+++ b/src/leap/mail/imap/mailbox.py
@@ -880,8 +880,8 @@ class IMAPMailbox(object):
#deferLater(self.reactor, 0, self._do_copy, message, d)
#return d
- # FIXME not implemented !!! ---
- return self.collection.copy_msg(message, self.mbox_name)
+ return self.collection.copy_msg(message.message,
+ self.collection.mbox_uuid)
# convenience fun
diff --git a/src/leap/mail/mail.py b/src/leap/mail/mail.py
index 4306ec3..b46d223 100644
--- a/src/leap/mail/mail.py
+++ b/src/leap/mail/mail.py
@@ -509,25 +509,27 @@ class MessageCollection(object):
return d
- def copy_msg(self, msg, newmailbox):
+ def copy_msg(self, msg, new_mbox_uuid):
"""
Copy the message to another collection. (it only makes sense for
mailbox collections)
"""
- # TODO currently broken ------------------FIXME-
if not self.is_mailbox_collection():
raise NotImplementedError()
- def insert_copied_mdoc_id(wrapper):
- # TODO this needs to be implemented before the copy
- # interface works.
- newmailbox_uuid = get_mbox_uuid_from_msg_wrapper(wrapper)
+ def insert_copied_mdoc_id(wrapper_new_msg):
return self.mbox_indexer.insert_doc(
- newmailbox_uuid, wrapper.mdoc.doc_id)
+ new_mbox_uuid, wrapper.mdoc.doc_id)
wrapper = msg.get_wrapper()
- d = wrapper.copy(self.store, newmailbox)
+
+ def print_result(result):
+ print "COPY CALLBACK:>>>", result
+ return result
+
+ d = wrapper.copy(self.store, new_mbox_uuid)
d.addCallback(insert_copied_mdoc_id)
+ d.addCallback(print_result)
return d
def delete_msg(self, msg):