summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/pixelated/application.py17
-rw-r--r--service/pixelated/bitmask_libraries/session.py11
-rw-r--r--service/pixelated/config/leap.py29
-rw-r--r--service/test/unit/bitmask_libraries/test_session.py14
-rw-r--r--service/test/unit/test_welcome_mail.py2
5 files changed, 36 insertions, 37 deletions
diff --git a/service/pixelated/application.py b/service/pixelated/application.py
index 082f45ee..bca4d5e5 100644
--- a/service/pixelated/application.py
+++ b/service/pixelated/application.py
@@ -14,12 +14,16 @@
# You should have received a copy of the GNU Affero General Public License
# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
+import os
+
+from email import message_from_file
from twisted.internet import reactor
from twisted.internet import defer
from twisted.internet import ssl
from OpenSSL import SSL
from OpenSSL import crypto
+from pixelated.adapter.model.mail import InputMail
from pixelated.config import arguments
from pixelated.config.services import Services
from pixelated.config.leap import initialize_leap
@@ -39,6 +43,9 @@ def start_user_agent(root_resource, leap_home, leap_session):
services = Services(leap_home, leap_session)
yield services.setup(leap_home, leap_session)
+ if leap_session.fresh_account:
+ yield add_welcome_mail(leap_session.mail_store)
+
root_resource.initialize(
services.keymanager,
services.search_engine,
@@ -104,3 +111,13 @@ def start_site(config, resource):
interface=config.host)
else:
reactor.listenTCP(config.port, PixelatedSite(resource), interface=config.host)
+
+
+def add_welcome_mail(mail_store):
+ current_path = os.path.dirname(os.path.abspath(__file__))
+ welcome_mail = os.path.join(current_path, 'assets', 'welcome.mail')
+ with open(welcome_mail) as mail_template_file:
+ mail_template = message_from_file(mail_template_file)
+
+ input_mail = InputMail.from_python_mail(mail_template)
+ mail_store.add_mail('INBOX', input_mail.raw)
diff --git a/service/pixelated/bitmask_libraries/session.py b/service/pixelated/bitmask_libraries/session.py
index 7abe2a63..da62b084 100644
--- a/service/pixelated/bitmask_libraries/session.py
+++ b/service/pixelated/bitmask_libraries/session.py
@@ -28,6 +28,12 @@ from .smtp import LeapSmtp
from leap.mail.imap.account import IMAPAccount
from twisted.internet import defer
+from leap.common.events import (
+ register,
+ catalog as events
+)
+
+
SESSIONS = {}
@@ -63,6 +69,8 @@ class LeapSession(object):
self.mail_store = mail_store
self.soledad_session = soledad_session
self.nicknym = nicknym
+ self.fresh_account = False
+ register(events.KEYMANAGER_FINISHED_KEY_GENERATION, self._set_fresh_account)
@defer.inlineCallbacks
def initial_sync(self):
@@ -85,6 +93,9 @@ class LeapSession(object):
account = IMAPAccount(user_mail, soledad_session.soledad)
return account
+ def _set_fresh_account(self, *args):
+ self.fresh_account = True
+
def account_email(self):
name = self.user_auth.username
return self.provider.address_for(name)
diff --git a/service/pixelated/config/leap.py b/service/pixelated/config/leap.py
index 0409e54f..00723224 100644
--- a/service/pixelated/config/leap.py
+++ b/service/pixelated/config/leap.py
@@ -1,21 +1,16 @@
from __future__ import absolute_import
from leap.common.events import (server as events_server,
register, catalog as events)
-from email import message_from_file
from pixelated.config import credentials
from pixelated.bitmask_libraries.config import LeapConfig
from pixelated.bitmask_libraries.certs import LeapCertificate
from pixelated.bitmask_libraries.provider import LeapProvider
from pixelated.bitmask_libraries.session import LeapSessionFactory
-from pixelated.adapter.model.mail import InputMail
from twisted.internet import defer
import os
import logging
-fresh_account = False
-
-
@defer.inlineCallbacks
def initialize_leap(leap_provider_cert,
leap_provider_cert_fingerprint,
@@ -25,8 +20,6 @@ def initialize_leap(leap_provider_cert,
initial_sync=True):
init_monkeypatches()
events_server.ensure_server()
- register(events.KEYMANAGER_FINISHED_KEY_GENERATION,
- set_fresh_account)
provider, username, password = credentials.read(organization_mode,
credentials_file)
LeapCertificate.set_cert_and_fingerprint(leap_provider_cert,
@@ -40,30 +33,8 @@ def initialize_leap(leap_provider_cert,
if initial_sync:
leap_session = yield leap_session.initial_sync()
- global fresh_account
- if fresh_account:
- add_welcome_mail(leap_session.mail_store)
-
defer.returnValue(leap_session)
-def add_welcome_mail(mail_store):
- current_path = os.path.dirname(os.path.abspath(__file__))
- with open(os.path.join(current_path,
- '..',
- 'assets',
- 'welcome.mail')) as mail_template_file:
- mail_template = message_from_file(mail_template_file)
-
- input_mail = InputMail.from_python_mail(mail_template)
- logging.getLogger('pixelated.config.leap').info('Adding the welcome mail')
- mail_store.add_mail('INBOX', input_mail.raw)
-
-
def init_monkeypatches():
import pixelated.extensions.requests_urllib3
-
-
-def set_fresh_account(_, x):
- global fresh_account
- fresh_account = True
diff --git a/service/test/unit/bitmask_libraries/test_session.py b/service/test/unit/bitmask_libraries/test_session.py
index e20f96f9..887da83e 100644
--- a/service/test/unit/bitmask_libraries/test_session.py
+++ b/service/test/unit/bitmask_libraries/test_session.py
@@ -32,7 +32,7 @@ class SessionTest(AbstractLeapTest):
with patch('pixelated.bitmask_libraries.session.LeapSession._create_incoming_mail_fetcher') as mail_fetcher_mock:
session = self._create_session()
yield session.initial_sync()
- mail_fetcher_mock.startService.assert_called_once_with()
+ mail_fetcher_mock.startService.assert_called_once()
def test_that_close_stops_background_jobs(self):
with patch('pixelated.bitmask_libraries.session.reactor.callFromThread', new=_execute_func) as _:
@@ -40,14 +40,14 @@ class SessionTest(AbstractLeapTest):
session = self._create_session()
yield session.initial_sync()
session.close()
- mail_fetcher_mock.stopService.assert_called_once_with()
+ mail_fetcher_mock.stopService.assert_called_once()
def test_that_sync_deferes_to_soledad(self):
- session = self._create_session()
-
- session.sync()
-
- self.soledad_session.sync.assert_called_once_with()
+ with patch('pixelated.bitmask_libraries.session.reactor.callFromThread', new=_execute_func) as _:
+ with patch('pixelated.bitmask_libraries.session.LeapSession._create_incoming_mail_fetcher') as mail_fetcher_mock:
+ session = self._create_session()
+ yield session.sync()
+ self.soledad_session.sync.assert_called_once()
def _create_session(self):
return LeapSession(self.provider, self.auth, self.mail_store, self.soledad_session, self.nicknym, self.smtp_mock)
diff --git a/service/test/unit/test_welcome_mail.py b/service/test/unit/test_welcome_mail.py
index 7e9ab0c9..b0162eec 100644
--- a/service/test/unit/test_welcome_mail.py
+++ b/service/test/unit/test_welcome_mail.py
@@ -19,7 +19,7 @@ import unittest
from mockito import verify, mock
from mockito.matchers import Matcher
from email import message_from_file
-from pixelated.config.leap import add_welcome_mail
+from pixelated.application import add_welcome_mail
from pixelated.adapter.model.mail import InputMail