diff options
author | Kali Kaneko (leap communications) <kali@leap.se> | 2017-04-27 15:20:24 +0200 |
---|---|---|
committer | Ruben Pollan <meskio@sindominio.net> | 2017-05-16 19:28:35 +0200 |
commit | c980cae46d101c0def23bf3398b65b2e0c614d2a (patch) | |
tree | 6e421dc1d1a65572ab621f564b281ed1ffe5a0f3 /src/leap/bitmask/mua | |
parent | 401bf8067bf6eb1fd27477550a6edc0ab08647e4 (diff) |
[bug] fix notification for incoming mail with several listeners registered
When setting the listeners in the IMAP Folder, we avoid setting more
than one listener for the same imap mailbox (because in some situations
we were registering way too many listeners).
this was making the pixelated inbox registering the notification and
therefore the imap mailbox not being registered.
this MR also refactors the way pixelated is initialized, so that it
avoid creating a second Account instance. In this way, we make sure that
the pixelated mua and the imap server share the same collections for a
given mailbox, and therefore any of the two is able to get a
notification whenever the other adds a message to the mailbox.
- Resolves: #8846, #8798
Diffstat (limited to 'src/leap/bitmask/mua')
-rw-r--r-- | src/leap/bitmask/mua/pixelizer.py | 66 |
1 files changed, 45 insertions, 21 deletions
diff --git a/src/leap/bitmask/mua/pixelizer.py b/src/leap/bitmask/mua/pixelizer.py index ed69afb..c2dd714 100644 --- a/src/leap/bitmask/mua/pixelizer.py +++ b/src/leap/bitmask/mua/pixelizer.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# pix.py -# Copyright (C) 2016 LEAP +# pixelizer.py +# Copyright (C) 2016-2017 LEAP # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -14,9 +14,22 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. + """ -Pixelated plugin integration. +Pixelizer: the pixelated integrator. + +Right now this module is kind of hardcoded, but it should be possible for +bitmask to use this as an optional plugin. For the moment we fail gracefully if +we cannot find the pixelated modules in the import path. + +There's a lot of code duplication right now in this double game of adaptors for +pixelated adaptors. Refactoring pixelated and bitmask should be possible so +that we converge the mail apis and stop needing this nasty proliferation of +adaptors. + +However, some care has to be taken to avoid certain types of concurrency bugs. """ + import json import os import sys @@ -25,12 +38,10 @@ from twisted.internet import defer, reactor from twisted.logger import Logger from leap.common.config import get_path_prefix -from leap.bitmask.mail.mail import Account from leap.bitmask.keymanager import KeyNotFound try: from pixelated.adapter.mailstore import LeapMailStore - from pixelated.adapter.welcome_mail import add_welcome_mail from pixelated.application import SingleUserServicesFactory from pixelated.application import UserAgentMode from pixelated.application import start_site @@ -51,10 +62,13 @@ log = Logger() # [ ] pre-authenticate -def start_pixelated_user_agent(userid, soledad, keymanager): +def start_pixelated_user_agent(userid, soledad, keymanager, account): - leap_session = LeapSessionAdapter( - userid, soledad, keymanager) + try: + leap_session = LeapSessionAdapter( + userid, soledad, keymanager, account) + except Exception as exc: + log.error("Got error! %r" % exc) config = Config() leap_home = os.path.join(get_path_prefix(), 'leap') @@ -134,9 +148,23 @@ class NickNym(object): return self.keymanager.send_key() +class _LeapMailStore(LeapMailStore): + + 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) + + class LeapSessionAdapter(object): - def __init__(self, userid, soledad, keymanager): + def __init__(self, userid, soledad, keymanager, account): self.userid = userid self.soledad = soledad @@ -144,14 +172,16 @@ class LeapSessionAdapter(object): # XXX this needs to be converged with our public apis. _n = NickNym(keymanager, userid) self.nicknym = self.keymanager = _n - self.mail_store = LeapMailStore(soledad) + + self.mail_store = _LeapMailStore(soledad, account) + + self.account = account self.user_auth = Config() self.user_auth.uuid = soledad.uuid self.fresh_account = False self.incoming_mail_fetcher = None - self.account = Account(soledad, userid) username, provider = userid.split('@') smtp_client_cert = os.path.join( @@ -201,13 +231,7 @@ def _start_in_single_user_mode(leap_session, config, resource, services_factory): start_site(config, resource) reactor.callLater( - # workaround for #8798 - # we need to make pixelated initialization a bit behind - # the own leap initialization, because otherwise the inbox is created - # without the needed callbacks for IMAP compatibility. - # This should be better addressed at pixelated code, by using the mail - # api to create the collection. - 3, start_user_agent_in_single_user_mode, + 0, start_user_agent_in_single_user_mode, resource, services_factory, leap_session.config.leap_home, leap_session) @@ -221,10 +245,10 @@ def start_user_agent_in_single_user_mode(root_resource, _services = services.Services(leap_session) yield _services.setup() - if leap_session.fresh_account: - yield add_welcome_mail(leap_session.mail_store) + # TODO we might want to use a Bitmask specific mail + # if leap_session.fresh_account: + # yield add_welcome_mail(leap_session.mail_store) services_factory.add_session(leap_session.user_auth.uuid, _services) - root_resource.initialize(provider=leap_session.provider) log.info('Done, the Pixelated User Agent is ready to be used') |