summaryrefslogtreecommitdiff
path: root/src/leap/mail/mail.py
diff options
context:
space:
mode:
authorRuben Pollan <meskio@sindominio.net>2015-02-18 11:33:42 -0600
committerRuben Pollan <meskio@sindominio.net>2015-02-18 17:30:29 -0600
commit2af7083d4543be9a1b1476de75fafb17bfe78b95 (patch)
treefc7a16d14e0be335240aacea41edc37cc76971aa /src/leap/mail/mail.py
parent87c15e3ec5c1ca607890bf72b0d90bb0f114cbb1 (diff)
Use MessageCollection instead of IMAPMailbox in IncomingMail
Diffstat (limited to 'src/leap/mail/mail.py')
-rw-r--r--src/leap/mail/mail.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/leap/mail/mail.py b/src/leap/mail/mail.py
index d74f6b8..b7b0981 100644
--- a/src/leap/mail/mail.py
+++ b/src/leap/mail/mail.py
@@ -20,7 +20,10 @@ Generic Access to Mail objects: Public LEAP Mail API.
import uuid
import logging
import StringIO
+import cStringIO
+import time
+from email.utils import formatdate
from twisted.internet import defer
from leap.common.check import leap_assert_type
@@ -522,6 +525,56 @@ class MessageCollection(object):
d.addErrback(lambda f: f.printTraceback())
return d
+ def add_raw_message(self, message, flags, date=None):
+ """
+ Adds a message to this collection.
+
+ :param message: the raw message
+ :type message: str
+
+ :param flags: flag list
+ :type flags: list of str
+
+ :param date: timestamp
+ :type date: str
+
+ :return: a deferred that will be triggered with the UID of the added
+ message.
+ """
+ # TODO should raise ReadOnlyMailbox if not rw.
+ # TODO have a look at the cases for internal date in the rfc
+ if isinstance(message, (cStringIO.OutputType, StringIO.StringIO)):
+ message = message.getvalue()
+
+ # XXX we could treat the message as an IMessage from here
+ leap_assert_type(message, basestring)
+
+ if flags is None:
+ flags = tuple()
+ else:
+ flags = tuple(str(flag) for flag in flags)
+
+ if date is None:
+ date = formatdate(time.time())
+
+ # A better place for this would be the COPY/APPEND dispatcher
+ # if PROFILE_CMD:
+ # do_profile_cmd(d, "APPEND")
+
+ # 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
+ # or patching imap server to support pipelining.
+
+ d = self.add_msg(message, flags=flags, date=date,
+ notify_just_mdoc=True)
+ d.addErrback(lambda f: logger.warning(f.getTraceback()))
+ return d
+
def copy_msg(self, msg, new_mbox_uuid):
"""
Copy the message to another collection. (it only makes sense for