diff options
Diffstat (limited to 'service/pixelated')
-rw-r--r-- | service/pixelated/adapter/listener.py | 9 | ||||
-rw-r--r-- | service/pixelated/adapter/mail_service.py | 6 | ||||
-rw-r--r-- | service/pixelated/adapter/pixelated_mail_sender.py | 1 | ||||
-rw-r--r-- | service/pixelated/adapter/pixelated_mailbox.py | 6 | ||||
-rw-r--r-- | service/pixelated/adapter/pixelated_mailboxes.py | 19 | ||||
-rw-r--r-- | service/pixelated/adapter/soledad_querier.py | 18 | ||||
-rw-r--r-- | service/pixelated/adapter/tag_index.py | 1 | ||||
-rw-r--r-- | service/pixelated/adapter/tag_service.py | 7 | ||||
-rw-r--r-- | service/pixelated/bitmask_libraries/config.py | 3 | ||||
-rw-r--r-- | service/pixelated/bitmask_libraries/leap_srp.py | 3 | ||||
-rw-r--r-- | service/pixelated/bitmask_libraries/provider.py | 1 | ||||
-rw-r--r-- | service/pixelated/bitmask_libraries/session.py | 7 | ||||
-rw-r--r-- | service/pixelated/bitmask_libraries/smtp.py | 1 | ||||
-rw-r--r-- | service/pixelated/bitmask_libraries/soledad.py | 8 | ||||
-rw-r--r-- | service/pixelated/reactor_manager.py | 3 | ||||
-rw-r--r-- | service/pixelated/support/date.py | 1 | ||||
-rw-r--r-- | service/pixelated/user_agent.py | 11 |
17 files changed, 38 insertions, 67 deletions
diff --git a/service/pixelated/adapter/listener.py b/service/pixelated/adapter/listener.py index 1ed546fd..67d75df7 100644 --- a/service/pixelated/adapter/listener.py +++ b/service/pixelated/adapter/listener.py @@ -13,7 +13,6 @@ # # You should have received a copy of the GNU Affero General Public License # along with Pixelated. If not, see <http://www.gnu.org/licenses/>. -from pixelated.adapter.soledad_querier import SoledadQuerier class MailboxListener(object): @@ -22,14 +21,14 @@ class MailboxListener(object): SEARCH_ENGINE = None @classmethod - def listen(cls, account, mailbox_name): - listener = MailboxListener(mailbox_name) + def listen(cls, account, mailbox_name, soledad_querier): + listener = MailboxListener(mailbox_name, soledad_querier) if listener not in account.getMailbox(mailbox_name).listeners: account.getMailbox(mailbox_name).addListener(listener) - def __init__(self, mailbox_name): + def __init__(self, mailbox_name, soledad_querier): self.mailbox_name = mailbox_name - self.querier = SoledadQuerier.get_instance() + self.querier = soledad_querier def newMessages(self, exists, recent): indexed_idents = set(self.SEARCH_ENGINE.search('tag:' + self.mailbox_name.lower())) diff --git a/service/pixelated/adapter/mail_service.py b/service/pixelated/adapter/mail_service.py index 9e29b0c3..e908feb7 100644 --- a/service/pixelated/adapter/mail_service.py +++ b/service/pixelated/adapter/mail_service.py @@ -13,17 +13,15 @@ # # You should have received a copy of the GNU Affero General Public License # along with Pixelated. If not, see <http://www.gnu.org/licenses/>. -from pixelated.adapter.tag_service import TagService -from pixelated.adapter.soledad_querier import SoledadQuerier class MailService: __slots__ = ['leap_session', 'account', 'mailbox_name'] - def __init__(self, mailboxes, mail_sender, tag_service=TagService.get_instance()): + def __init__(self, mailboxes, mail_sender, tag_service, soledad_querier): self.tag_service = tag_service self.mailboxes = mailboxes - self.querier = SoledadQuerier.get_instance() + self.querier = soledad_querier self.mail_sender = mail_sender def all_mails(self): diff --git a/service/pixelated/adapter/pixelated_mail_sender.py b/service/pixelated/adapter/pixelated_mail_sender.py index 4189517d..cf30779f 100644 --- a/service/pixelated/adapter/pixelated_mail_sender.py +++ b/service/pixelated/adapter/pixelated_mail_sender.py @@ -14,6 +14,7 @@ # 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 smtplib + from pixelated.support.functional import flatten diff --git a/service/pixelated/adapter/pixelated_mailbox.py b/service/pixelated/adapter/pixelated_mailbox.py index 0ad79b11..283567db 100644 --- a/service/pixelated/adapter/pixelated_mailbox.py +++ b/service/pixelated/adapter/pixelated_mailbox.py @@ -14,8 +14,6 @@ # You should have received a copy of the GNU Affero General Public License # along with Pixelated. If not, see <http://www.gnu.org/licenses/>. -from pixelated.adapter.soledad_querier import SoledadQuerier - class PixelatedMailbox: @@ -51,5 +49,5 @@ class PixelatedMailbox: self.querier.remove_mail(mail) @classmethod - def create(cls, mailbox_name='INBOX'): - return PixelatedMailbox(mailbox_name, SoledadQuerier.get_instance()) + def create(cls, mailbox_name, soledad_querier): + return PixelatedMailbox(mailbox_name, soledad_querier) diff --git a/service/pixelated/adapter/pixelated_mailboxes.py b/service/pixelated/adapter/pixelated_mailboxes.py index 1025f58e..79c007cb 100644 --- a/service/pixelated/adapter/pixelated_mailboxes.py +++ b/service/pixelated/adapter/pixelated_mailboxes.py @@ -14,24 +14,23 @@ # You should have received a copy of the GNU Affero General Public License # along with Pixelated. If not, see <http://www.gnu.org/licenses/>. from pixelated.adapter.pixelated_mailbox import PixelatedMailbox -from pixelated.adapter.soledad_querier import SoledadQuerier from pixelated.adapter.listener import MailboxListener class PixelatedMailBoxes(): - def __init__(self, account): + def __init__(self, account, soledad_querier): self.account = account - self.querier = SoledadQuerier.get_instance() + self.querier = soledad_querier for mailbox_name in account.mailboxes: - MailboxListener.listen(self.account, mailbox_name) + MailboxListener.listen(self.account, mailbox_name, soledad_querier) def _create_or_get(self, mailbox_name): mailbox_name = mailbox_name.upper() if mailbox_name not in self.account.mailboxes: self.account.addMailbox(mailbox_name) - MailboxListener.listen(self.account, mailbox_name) - return PixelatedMailbox.create(mailbox_name) + MailboxListener.listen(self.account, mailbox_name, self.querier) + return PixelatedMailbox.create(mailbox_name, self.querier) def inbox(self): return self._create_or_get('INBOX') @@ -45,14 +44,12 @@ class PixelatedMailBoxes(): def sent(self): return self._create_or_get('SENT') - @property def mailboxes(self): - return [PixelatedMailbox.create(leap_mailbox_name) for leap_mailbox_name in - self.account.mailboxes] + return [self._create_or_get(leap_mailbox_name) for leap_mailbox_name in self.account.mailboxes] def mails_by_tag(self, query_tags): mails = [] - for mailbox in self.mailboxes: + for mailbox in self.mailboxes(): mails.extend(mailbox.mails_by_tags(query_tags)) return mails @@ -65,7 +62,7 @@ class PixelatedMailBoxes(): return mail def mail(self, mail_id): - for mailbox in self.mailboxes: + for mailbox in self.mailboxes(): mail = mailbox.mail(mail_id) if mail: return mail diff --git a/service/pixelated/adapter/soledad_querier.py b/service/pixelated/adapter/soledad_querier.py index 35c8780f..f121a463 100644 --- a/service/pixelated/adapter/soledad_querier.py +++ b/service/pixelated/adapter/soledad_querier.py @@ -16,29 +16,11 @@ from pixelated.adapter.pixelated_mail import PixelatedMail -def get_soledad_querier_instance(cls, soledad=None): - if not cls.instance: - if not soledad: - raise Exception("Need a soledad for the first time you call this") - cls.instance = SoledadQuerier(soledad) - return cls.instance - - class SoledadQuerier: - instance = None - def __init__(self, soledad): self.soledad = soledad - @classmethod - def get_instance(cls, soledad=None): - return get_soledad_querier_instance(cls, soledad) - - @classmethod - def reset(cls): - cls.instance = None - def all_mails(self): fdocs_chash = [(fdoc, fdoc.content['chash']) for fdoc in self.soledad.get_from_index('by-type', 'flags')] if len(fdocs_chash) == 0: diff --git a/service/pixelated/adapter/tag_index.py b/service/pixelated/adapter/tag_index.py index 2a0955ef..5b9bda51 100644 --- a/service/pixelated/adapter/tag_index.py +++ b/service/pixelated/adapter/tag_index.py @@ -16,6 +16,7 @@ # import dbm import atexit + import os from pixelated.adapter.tag import Tag diff --git a/service/pixelated/adapter/tag_service.py b/service/pixelated/adapter/tag_service.py index fa70231e..54b88622 100644 --- a/service/pixelated/adapter/tag_service.py +++ b/service/pixelated/adapter/tag_service.py @@ -14,7 +14,6 @@ # You should have received a copy of the GNU Affero General Public License # along with Pixelated. If not, see <http://www.gnu.org/licenses/>. from pixelated.adapter.tag import Tag -from pixelated.adapter.tag_index import TagIndex class TagService: @@ -25,9 +24,3 @@ class TagService: @classmethod def extract_reserved(cls, tags): return {tag.name for tag in cls.SPECIAL_TAGS if tag.name in tags} - - @classmethod - def get_instance(cls): - if not cls.instance: - cls.instance = TagService() - return cls.instance diff --git a/service/pixelated/bitmask_libraries/config.py b/service/pixelated/bitmask_libraries/config.py index c1255060..1cc10523 100644 --- a/service/pixelated/bitmask_libraries/config.py +++ b/service/pixelated/bitmask_libraries/config.py @@ -13,9 +13,10 @@ # # You should have received a copy of the GNU Affero General Public License # along with Pixelated. If not, see <http://www.gnu.org/licenses/>. +from distutils.spawn import find_executable + import os from os.path import expanduser -from distutils.spawn import find_executable def discover_gpg_binary(): diff --git a/service/pixelated/bitmask_libraries/leap_srp.py b/service/pixelated/bitmask_libraries/leap_srp.py index 05e27a94..7a627c1d 100644 --- a/service/pixelated/bitmask_libraries/leap_srp.py +++ b/service/pixelated/bitmask_libraries/leap_srp.py @@ -15,13 +15,14 @@ # along with Pixelated. If not, see <http://www.gnu.org/licenses/>. import binascii import json -import requests +import requests from requests import Session from srp import User, srp, create_salted_verification_key from requests.exceptions import HTTPError, SSLError, Timeout from config import SYSTEM_CA_BUNDLE + REGISTER_USER_LOGIN_KEY = 'user[login]' REGISTER_USER_VERIFIER_KEY = 'user[password_verifier]' REGISTER_USER_SALT_KEY = 'user[password_salt]' diff --git a/service/pixelated/bitmask_libraries/provider.py b/service/pixelated/bitmask_libraries/provider.py index 6848dc6e..4fe5f17d 100644 --- a/service/pixelated/bitmask_libraries/provider.py +++ b/service/pixelated/bitmask_libraries/provider.py @@ -17,7 +17,6 @@ import json from leap.common.certs import get_digest import requests - from .certs import which_bundle diff --git a/service/pixelated/bitmask_libraries/session.py b/service/pixelated/bitmask_libraries/session.py index 7c195391..78219635 100644 --- a/service/pixelated/bitmask_libraries/session.py +++ b/service/pixelated/bitmask_libraries/session.py @@ -13,23 +13,24 @@ # # 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 import errno import traceback +import sys + +import os from leap.mail.imap.fetch import LeapIncomingMail from leap.mail.imap.account import SoledadBackedAccount -import sys from leap.mail.imap.memorystore import MemoryStore from leap.mail.imap.soledadstore import SoledadStore from pixelated.bitmask_libraries.config import LeapConfig from pixelated.bitmask_libraries.provider import LeapProvider from twisted.internet import reactor from .nicknym import NickNym - from .auth import LeapAuthenticator, LeapCredentials from .soledad import SoledadSessionFactory, SoledadSession from .smtp import LeapSmtp + SESSIONS = {} diff --git a/service/pixelated/bitmask_libraries/smtp.py b/service/pixelated/bitmask_libraries/smtp.py index a04fbf74..343cb655 100644 --- a/service/pixelated/bitmask_libraries/smtp.py +++ b/service/pixelated/bitmask_libraries/smtp.py @@ -17,7 +17,6 @@ import os import requests from .certs import which_bundle from leap.mail.smtp import setup_smtp_gateway -import random class LeapSmtp(object): diff --git a/service/pixelated/bitmask_libraries/soledad.py b/service/pixelated/bitmask_libraries/soledad.py index f274dfc1..cf71a727 100644 --- a/service/pixelated/bitmask_libraries/soledad.py +++ b/service/pixelated/bitmask_libraries/soledad.py @@ -13,17 +13,15 @@ # # 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 json -import os import errno + +import os from leap.keymanager import KeyManager from leap.soledad.client import Soledad from leap.soledad.common.crypto import WrongMac, UnknownMacMethod, MacMethods -import requests -import sys -import time from .certs import which_bundle + SOLEDAD_TIMEOUT = 120 SOLEDAD_CERT = '/tmp/ca.crt' diff --git a/service/pixelated/reactor_manager.py b/service/pixelated/reactor_manager.py index 488b0bc4..c9473400 100644 --- a/service/pixelated/reactor_manager.py +++ b/service/pixelated/reactor_manager.py @@ -16,9 +16,10 @@ import signal import sys from threading import Thread -from twisted.internet import reactor import logging +from twisted.internet import reactor + def signal_handler(signal, frame): stop_reactor_on_exit() diff --git a/service/pixelated/support/date.py b/service/pixelated/support/date.py index 1593022c..329b8bfe 100644 --- a/service/pixelated/support/date.py +++ b/service/pixelated/support/date.py @@ -14,6 +14,7 @@ # 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 datetime + from dateutil.tz import tzlocal diff --git a/service/pixelated/user_agent.py b/service/pixelated/user_agent.py index c20a29d8..64e639d0 100644 --- a/service/pixelated/user_agent.py +++ b/service/pixelated/user_agent.py @@ -19,7 +19,6 @@ import getpass import os import os.path -import re import crochet from flask import Flask from flask import request @@ -37,9 +36,9 @@ from pixelated.adapter.soledad_querier import SoledadQuerier from pixelated.adapter.search import SearchEngine from pixelated.adapter.draft_service import DraftService from pixelated.adapter.listener import MailboxListener - import dateutil.parser as dateparser + static_folder = os.path.abspath(os.path.join(os.path.abspath(__file__), "..", "..", "web-ui", "app")) # this is a workaround for packaging @@ -206,13 +205,15 @@ def register_new_user(username): def start_user_agent(debug_enabled): leap_session = LeapSession.open(app.config['LEAP_USERNAME'], app.config['LEAP_PASSWORD'], app.config['LEAP_SERVER_NAME']) - SoledadQuerier.get_instance(soledad=leap_session.account._soledad) + soledad_querier = SoledadQuerier(soledad=leap_session.account._soledad) + PixelatedMail.from_email_address = leap_session.account_email() pixelated_mailboxes = PixelatedMailBoxes(leap_session.account) pixelated_mail_sender = PixelatedMailSender(leap_session.account_email()) - + from pixelated.adapter.tag_service import TagService + tag_service = TagService() global mail_service - mail_service = MailService(pixelated_mailboxes, pixelated_mail_sender) + mail_service = MailService(pixelated_mailboxes, pixelated_mail_sender, tag_service, soledad_querier) global search_engine search_engine = SearchEngine() MailboxListener.SEARCH_ENGINE = search_engine |