summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomás Touceda <chiiph@leap.se>2013-11-07 07:26:27 -0300
committerTomás Touceda <chiiph@leap.se>2013-11-07 07:26:27 -0300
commitacaca84e6749e2d2ffed46a8480ab0bf22fde670 (patch)
tree8be6b308d4034de44f187e8062830a532c1e5a57
parentceac28a86773034a184f56b1611933a1ae59e1dd (diff)
parent8369307bf67821e847ccfe607470380f43e72feb (diff)
Merge remote-tracking branch 'kali/bug/4394_update_pkey' into develop
-rw-r--r--changes/bug_4394-update-pkey1
-rw-r--r--pkg/requirements.pip1
-rw-r--r--src/leap/mail/imap/fetch.py19
-rw-r--r--src/leap/mail/imap/service/imap.py7
4 files changed, 22 insertions, 6 deletions
diff --git a/changes/bug_4394-update-pkey b/changes/bug_4394-update-pkey
new file mode 100644
index 0000000..d0a60b1
--- /dev/null
+++ b/changes/bug_4394-update-pkey
@@ -0,0 +1 @@
+ o Update pkey to allow multiple accounts. Solves: #4394
diff --git a/pkg/requirements.pip b/pkg/requirements.pip
index 13d04f9..7ed5087 100644
--- a/pkg/requirements.pip
+++ b/pkg/requirements.pip
@@ -3,3 +3,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/src/leap/mail/imap/fetch.py b/src/leap/mail/imap/fetch.py
index dd65def..4d47408 100644
--- a/src/leap/mail/imap/fetch.py
+++ b/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/src/leap/mail/imap/service/imap.py b/src/leap/mail/imap/service/imap.py
index 5f7322a..984ad04 100644
--- a/src/leap/mail/imap/service/imap.py
+++ b/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,))