summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/mua/pixelizer.py
diff options
context:
space:
mode:
authorKali Kaneko (leap communications) <kali@leap.se>2017-05-24 01:55:13 +0200
committerKali Kaneko (leap communications) <kali@leap.se>2017-05-24 14:35:43 +0200
commit0bba2d84a584396e888d1f4cd0d0011f5137ab8b (patch)
tree026e0b4dc16689d03899a6d31eeb5a0e49d7ebff /src/leap/bitmask/mua/pixelizer.py
parentba2ae87fa16f1f8aa56faa25b8ab1fdd1fd3b7d3 (diff)
[bug] fix sending mail error from pixelated
- Create the 'Sent folder' ourselves to avoid pixelated hitting a bug in mailbox creation. - I believe there's still a problem with bitmask desing for the adaptor (in get-or-create mailbox). This needs further tests. - Case manipualation to avoid having a 'Sent' and 'SENT' folder when Thunderbird and Pixelated write to those. - Further hacks to monkeypatch the leap-mail-adapter that Pixelated uses (make them reuse the account instance!). This is getting insane, I am really looking forward to the fork. - Duly note our technical debt in the area of Pixelated integration. Keeping the Pixelated codebase untouched for a long time will backfire. As far as I've noticed, we have a basic violation of the assumptions about a single-instance writes and notifications to all listeners. As commented in the commit, this should go either for a guarantee that only one account object is created per user (creating it in the bootstrapping process in bitmask), or for the opposite direction in which the listeners are communicated in some other way (zmq events, for instance). - In any case, it's strongly recommended to deduplicate the Pixelated libraries as soon as possible and make Pixelated use a better defined set of Bitmask's public apis. - Modify the wrapper create methods so that they return the modified wrapper itself. - Resolves: #8903, #8904
Diffstat (limited to 'src/leap/bitmask/mua/pixelizer.py')
-rw-r--r--src/leap/bitmask/mua/pixelizer.py64
1 files changed, 60 insertions, 4 deletions
diff --git a/src/leap/bitmask/mua/pixelizer.py b/src/leap/bitmask/mua/pixelizer.py
index b9ceac9..138774b 100644
--- a/src/leap/bitmask/mua/pixelizer.py
+++ b/src/leap/bitmask/mua/pixelizer.py
@@ -32,6 +32,7 @@ However, some care has to be taken to avoid certain types of concurrency bugs.
import json
import os
+import string
import sys
from twisted.internet import defer, reactor
@@ -54,16 +55,71 @@ try:
class _LeapMailStore(LeapMailStore):
+ # TODO We NEED TO rewrite the whole LeapMailStore in the coming
+ # pixelated fork so that we reuse the account instance.
+ # Otherwise, the current system for notifications will break.
+ # The other option is to have generic event listeners, using zmq, and
+ # allow the pixelated instance to have its own hierarchy of
+ # account-mailbox instances, only sharing soledad.
+ # However, this seems good enough since it's now better to wait until
+ # we depend on leap.pixelated fork to make changes on that codebase.
+ # When that refactor starts, we should try to internalize as much
+ # work/bugfixes was done in pixelated, and incorporate it into the
+ # public bitmask api. Let's learn from our mistakes.
+
def __init__(self, soledad, account):
self.account = account
super(_LeapMailStore, self).__init__(soledad)
- # We should rewrite the LeapMailStore in the coming pixelated fork so
- # that we reuse the account instance.
@defer.inlineCallbacks
def add_mail(self, mailbox_name, raw_msg):
- inbox = yield self.account.get_collection_by_mailbox(mailbox_name)
- yield inbox.add_msg(raw_msg, ('\\Recent',), notify_just_mdoc=False)
+ name = yield self._get_case_insensitive_mbox(mailbox_name)
+ mailbox = yield self.account.get_collection_by_mailbox(name)
+ flags = ['\\Recent']
+ if mailbox_name.lower() == 'sent':
+ flags += '\\Seen'
+ message = yield mailbox.add_msg(
+ raw_msg, tuple(flags), notify_just_mdoc=False)
+
+ # this still needs the pixelated interface because it does stuff
+ # like indexing the mail in whoosh, etc.
+ mail = yield self._leap_message_to_leap_mail(
+ message.get_wrapper().mdoc.doc_id, message, include_body=True)
+ defer.returnValue(mail)
+
+ def get_mailbox_names(self):
+ """returns: deferred"""
+ return self.account.list_all_mailbox_names()
+
+ @defer.inlineCallbacks
+ def _get_or_create_mailbox(self, mailbox_name):
+ """
+ Avoid creating variations of the case.
+ If there's already a 'Sent' folder, do not create 'SENT', just
+ return that.
+ """
+ name = yield self._get_case_insensitive_mbox(mailbox_name)
+ if name is None:
+ name = mailbox_name
+ yield self.account.add_mailbox(name)
+ mailbox = yield self.account.get_collection_by_mailbox(
+ name)
+
+ # Pixelated expects the mailbox wrapper;
+ # it should limit itself to the Mail API instead.
+ # This is also a smell that the collection-mailbox-wrapper
+ # distinction is not clearly cut.
+ defer.returnValue(mailbox.mbox_wrapper)
+
+ @defer.inlineCallbacks
+ def _get_case_insensitive_mbox(self, mailbox_name):
+ name = None
+ mailboxes = yield self.get_mailbox_names()
+ lower = mailbox_name.lower()
+ lower_mboxes = map(string.lower, mailboxes)
+ if lower in lower_mboxes:
+ name = mailboxes[lower_mboxes.index(lower)]
+ defer.returnValue(name)
except ImportError as exc: