diff options
Diffstat (limited to 'src/leap/mail/imap/fetch.py')
-rw-r--r-- | src/leap/mail/imap/fetch.py | 70 |
1 files changed, 16 insertions, 54 deletions
diff --git a/src/leap/mail/imap/fetch.py b/src/leap/mail/imap/fetch.py index bcd8901..60ae387 100644 --- a/src/leap/mail/imap/fetch.py +++ b/src/leap/mail/imap/fetch.py @@ -1,12 +1,8 @@ import json -import os -#import hmac - -from xdg import BaseDirectory from twisted.python import log -from leap.common.check import leap_assert +from leap.common.check import leap_assert, leap_assert_type from leap.soledad import Soledad from leap.common.keymanager import openpgp @@ -16,61 +12,30 @@ class LeapIncomingMail(object): """ Fetches mail from the incoming queue. """ - def __init__(self, keymanager, user_uuid, soledad_pass, server_url, - server_pemfile, token, imap_account, - **kwargs): + def __init__(self, keymanager, soledad, imap_account): + """ Initialize LeapIMAP. - :param user: The user adress in the form C{user@provider}. - :type user: str - - :param soledad_pass: The password for the local database replica. - :type soledad_pass: str - - :param server_url: The URL of the remote server to sync against. - :type couch_url: str - - :param server_pemfile: The pemfile for the remote sync server TLS - handshake. - :type server_pemfile: str - - :param token: a session token valid for this user. - :type token: str + :param keymanager: a keymanager instance + :type keymanager: keymanager.KeyManager - :param imap_account: a SoledadBackedAccount instance to which - the incoming mail will be saved to + :param soledad: a soledad instance + :type soledad: Soledad - :param **kwargs: Used to pass arguments to Soledad instance. Maybe - Soledad instantiation could be factored out from here, and maybe - we should have a standard for all client code. + :param imap_account: the account to fetch periodically + :type imap_account: SoledadBackedAccount """ - leap_assert(user_uuid, "need an user uuid to initialize") - self._keymanager = keymanager - self._user_uuid = user_uuid - self._server_url = server_url - self._soledad_pass = soledad_pass - - base_config = BaseDirectory.xdg_config_home - secret_path = os.path.join( - base_config, "leap", "soledad", "%s.secret" % user_uuid) - soledad_path = os.path.join( - base_config, "leap", "soledad", "%s-incoming.u1db" % user_uuid) + leap_assert(keymanager, "need a keymanager to initialize") + leap_assert_type(soledad, Soledad) + self._keymanager = keymanager + self._soledad = soledad self.imapAccount = imap_account - self._soledad = Soledad( - user_uuid, - soledad_pass, - secret_path, - soledad_path, - server_url, - server_pemfile, - token) self._pkey = self._keymanager.get_all_keys_in_local_db( private=True).pop() - log.msg('fetcher got soledad instance') def fetch(self): """ @@ -78,16 +43,12 @@ class LeapIncomingMail(object): user account, and remove from the incoming db. """ self._soledad.sync() - - #log.msg('getting all docs') gen, doclist = self._soledad.get_all_docs() #log.msg("there are %s docs" % (len(doclist),)) if doclist: inbox = self.imapAccount.getMailbox('inbox') - #import ipdb; ipdb.set_trace() - key = self._pkey for doc in doclist: keys = doc.content.keys() @@ -99,10 +60,11 @@ class LeapIncomingMail(object): encdata = doc.content['_enc_json'] decrdata = openpgp.decrypt_asym( encdata, key, - passphrase=self._soledad_pass) + # XXX get from public method instead + passphrase=self._soledad._passphrase) if decrdata: self.process_decrypted(doc, decrdata, inbox) - # XXX launch sync callback + # XXX launch sync callback / defer def process_decrypted(self, doc, data, inbox): """ |