summaryrefslogtreecommitdiff
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
commitce94b34c75e133808cdeee7ab33edb6caa535ddf (patch)
tree60260a1d5bf7c733dfb3790db2e9e006e1e82ab2
parentba240ab67f753ed39f1fdd0467c835a887a7d148 (diff)
Use MessageCollection instead of IMAPMailbox in IncomingMail
-rw-r--r--mail/src/leap/mail/imap/mailbox.py42
-rw-r--r--mail/src/leap/mail/incoming/service.py8
-rw-r--r--mail/src/leap/mail/incoming/tests/test_incoming_mail.py2
-rw-r--r--mail/src/leap/mail/mail.py53
4 files changed, 60 insertions, 45 deletions
diff --git a/mail/src/leap/mail/imap/mailbox.py b/mail/src/leap/mail/imap/mailbox.py
index 9ec6ea8b..2f33aa03 100644
--- a/mail/src/leap/mail/imap/mailbox.py
+++ b/mail/src/leap/mail/imap/mailbox.py
@@ -19,13 +19,9 @@ IMAP Mailbox.
"""
import re
import logging
-import StringIO
-import cStringIO
-import time
import os
from collections import defaultdict
-from email.utils import formatdate
from twisted.internet import defer
from twisted.internet import reactor
@@ -36,7 +32,7 @@ from zope.interface import implements
from leap.common import events as leap_events
from leap.common.events.events_pb2 import IMAP_UNREAD_MAIL
-from leap.common.check import leap_assert, leap_assert_type
+from leap.common.check import leap_assert
from leap.mail.constants import INBOX_NAME, MessageFlags
from leap.mail.imap.messages import IMAPMessage
@@ -326,41 +322,7 @@ class IMAPMailbox(object):
: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.collection.add_msg(message, flags=flags, date=date,
- notify_just_mdoc=True)
-
- # XXX signal to UI? --- should do it only if INBOX...
- d.addErrback(lambda f: log.msg(f.getTraceback()))
- return d
+ return self.collection.add_raw_msg(message, flags, date)
def notify_new(self, *args):
"""
diff --git a/mail/src/leap/mail/incoming/service.py b/mail/src/leap/mail/incoming/service.py
index fadfd9f6..8b5c3713 100644
--- a/mail/src/leap/mail/incoming/service.py
+++ b/mail/src/leap/mail/incoming/service.py
@@ -97,7 +97,7 @@ class IncomingMail(Service):
LEAP_SIGNATURE_HEADER = 'X-Leap-Signature'
"""
- Header added to messages when they are decrypted by the IMAP fetcher,
+ Header added to messages when they are decrypted by the fetcher,
which states the validity of an eventual signature that might be included
in the encrypted blob.
"""
@@ -118,7 +118,7 @@ class IncomingMail(Service):
:type soledad: Soledad
:param inbox: the inbox where the new emails will be stored
- :type inbox: IMAPMailbox
+ :type inbox: MessageCollection
:param check_period: the period to fetch new mail, in seconds.
:type check_period: int
@@ -266,7 +266,7 @@ class IncomingMail(Service):
Sends unread event to ui.
"""
leap_events.signal(
- IMAP_UNREAD_MAIL, str(self._inbox.getUnseenCount()))
+ IMAP_UNREAD_MAIL, str(self._inbox.count_unseen()))
# process incoming mail.
@@ -729,7 +729,7 @@ class IncomingMail(Service):
d.addCallback(signal_deleted)
return d
- d = self._inbox.addMessage(data, (self.RECENT_FLAG,))
+ d = self._inbox.add_raw_message(data, (self.RECENT_FLAG,))
d.addCallbacks(msgSavedCallback, self._errback)
return d
diff --git a/mail/src/leap/mail/incoming/tests/test_incoming_mail.py b/mail/src/leap/mail/incoming/tests/test_incoming_mail.py
index a932a959..f43f746e 100644
--- a/mail/src/leap/mail/incoming/tests/test_incoming_mail.py
+++ b/mail/src/leap/mail/incoming/tests/test_incoming_mail.py
@@ -91,7 +91,7 @@ subject: independence of cyberspace
self.fetcher = IncomingMail(
self._km,
self._soledad,
- inbox,
+ inbox.collection,
ADDRESS)
# The messages don't exist on soledad will fail on deletion
diff --git a/mail/src/leap/mail/mail.py b/mail/src/leap/mail/mail.py
index d74f6b8c..b7b09818 100644
--- a/mail/src/leap/mail/mail.py
+++ b/mail/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