diff options
author | Kali Kaneko <kali@leap.se> | 2013-11-06 11:09:19 -0200 |
---|---|---|
committer | Kali Kaneko <kali@leap.se> | 2013-11-06 11:09:19 -0200 |
commit | 9a47ffa709eff203aeb4a0d37f8e6d30045d2d58 (patch) | |
tree | 613471f4324f9bcff3351100160a1c0dcb73a5cd /mail | |
parent | fa4bcae3bd8b4ff823051bb0868bd9eae468f0fc (diff) |
Make the pkey a property
so we can allow multiple accounts in the imap fetcher.
Diffstat (limited to 'mail')
-rw-r--r-- | mail/changes/bug_4394-update-pkey | 1 | ||||
-rw-r--r-- | mail/pkg/requirements.pip | 1 | ||||
-rw-r--r-- | mail/src/leap/mail/imap/fetch.py | 19 | ||||
-rw-r--r-- | mail/src/leap/mail/imap/service/imap.py | 7 |
4 files changed, 22 insertions, 6 deletions
diff --git a/mail/changes/bug_4394-update-pkey b/mail/changes/bug_4394-update-pkey new file mode 100644 index 00000000..d0a60b11 --- /dev/null +++ b/mail/changes/bug_4394-update-pkey @@ -0,0 +1 @@ + o Update pkey to allow multiple accounts. Solves: #4394 diff --git a/mail/pkg/requirements.pip b/mail/pkg/requirements.pip index 4780b5c7..ae1a38b5 100644 --- a/mail/pkg/requirements.pip +++ b/mail/pkg/requirements.pip @@ -2,3 +2,4 @@ leap.soledad.client>=0.3.0 leap.common>=0.3.5 leap.keymanager>=0.3.4 twisted # >= 12.0.3 ?? +zope.proxy diff --git a/mail/src/leap/mail/imap/fetch.py b/mail/src/leap/mail/imap/fetch.py index dd65def2..4d474089 100644 --- a/mail/src/leap/mail/imap/fetch.py +++ b/mail/src/leap/mail/imap/fetch.py @@ -28,6 +28,7 @@ from email.parser import Parser from twisted.python import log from twisted.internet.task import LoopingCall from twisted.internet.threads import deferToThread +from zope.proxy import sameProxiedObjects from leap.common import events as leap_events from leap.common.check import leap_assert, leap_assert_type @@ -39,6 +40,7 @@ from leap.common.events.events_pb2 import IMAP_MSG_DELETED_INCOMING from leap.common.events.events_pb2 import IMAP_UNREAD_MAIL from leap.common.mail import get_email_charset from leap.keymanager import errors as keymanager_errors +from leap.keymanager.openpgp import OpenPGPKey from leap.soledad.client import Soledad from leap.soledad.common.crypto import ENC_SCHEME_KEY, ENC_JSON_KEY @@ -66,7 +68,7 @@ class LeapIncomingMail(object): fetching_lock = threading.Lock() def __init__(self, keymanager, soledad, imap_account, - check_period): + check_period, userid): """ Initialize LeapIMAP. @@ -88,14 +90,14 @@ class LeapIncomingMail(object): leap_assert_type(soledad, Soledad) leap_assert(check_period, "need a period to check incoming mail") leap_assert_type(check_period, int) + leap_assert(userid, "need a userid to initialize") self._keymanager = keymanager self._soledad = soledad self.imapAccount = imap_account self._inbox = self.imapAccount.getMailbox('inbox') + self._userid = userid - self._pkey = self._keymanager.get_all_keys_in_local_db( - private=True).pop() self._loop = None self._check_period = check_period @@ -107,6 +109,13 @@ class LeapIncomingMail(object): """ self._soledad.create_index("just-mail", "incoming") + @property + def _pkey(self): + if sameProxiedObjects(self._keymanager, None): + logger.warning('tried to get key, but null keymanager found') + return None + return self._keymanager.get_key(self._userid, OpenPGPKey, private=True) + # # Public API: fetch, start_loop, stop. # @@ -118,6 +127,8 @@ class LeapIncomingMail(object): Calls a deferred that will execute the fetch callback in a separate thread """ + logger.debug("fetching mail for: %s %s" % ( + self._soledad.uuid, self._userid)) if not self.fetching_lock.locked(): d = deferToThread(self._sync_soledad) d.addCallbacks(self._signal_fetch_to_ui, self._sync_soledad_error) @@ -334,6 +345,7 @@ class LeapIncomingMail(object): :return: data, possibly descrypted. :rtype: str """ + # TODO split this method leap_assert_type(data, unicode) parser = Parser() @@ -417,7 +429,6 @@ class LeapIncomingMail(object): incoming message :type msgtuple: (SoledadDocument, str) """ - print "adding message locally....." doc, data = msgtuple self._inbox.addMessage(data, (self.RECENT_FLAG,)) leap_events.signal(IMAP_MSG_SAVED_LOCALLY) diff --git a/mail/src/leap/mail/imap/service/imap.py b/mail/src/leap/mail/imap/service/imap.py index 5f7322a9..984ad041 100644 --- a/mail/src/leap/mail/imap/service/imap.py +++ b/mail/src/leap/mail/imap/service/imap.py @@ -29,7 +29,7 @@ from twisted.python import log logger = logging.getLogger(__name__) from leap.common import events as leap_events -from leap.common.check import leap_assert, leap_assert_type +from leap.common.check import leap_assert, leap_assert_type, leap_check from leap.keymanager import KeyManager from leap.mail.imap.server import SoledadBackedAccount from leap.mail.imap.fetch import LeapIncomingMail @@ -152,6 +152,8 @@ def run_service(*args, **kwargs): port = kwargs.get('port', IMAP_PORT) check_period = kwargs.get('check_period', INCOMING_CHECK_PERIOD) + userid = kwargs.get('userid', None) + leap_check(userid is not None, "need an user id") uuid = soledad._get_uuid() factory = LeapIMAPFactory(uuid, soledad) @@ -165,7 +167,8 @@ def run_service(*args, **kwargs): keymanager, soledad, factory.theAccount, - check_period) + check_period, + userid) except CannotListenError: logger.error("IMAP Service failed to start: " "cannot listen in port %s" % (port,)) |