summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/leap/mail/imap/mailbox.py42
-rw-r--r--src/leap/mail/incoming/service.py8
-rw-r--r--src/leap/mail/incoming/tests/test_incoming_mail.py2
-rw-r--r--src/leap/mail/mail.py53
4 files changed, 60 insertions, 45 deletions
diff --git a/src/leap/mail/imap/mailbox.py b/src/leap/mail/imap/mailbox.py
index 9ec6ea8..2f33aa0 100644
--- a/src/leap/mail/imap/mailbox.py
+++ b/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/src/leap/mail/incoming/service.py b/src/leap/mail/incoming/service.py
index fadfd9f..8b5c371 100644
--- a/src/leap/mail/incoming/service.py
+++ b/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/src/leap/mail/incoming/tests/test_incoming_mail.py b/src/leap/mail/incoming/tests/test_incoming_mail.py
index a932a95..f43f746 100644
--- a/src/leap/mail/incoming/tests/test_incoming_mail.py
+++ b/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/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