summaryrefslogtreecommitdiff
path: root/src/leap/mail/imap/service/imap-server.tac
blob: 8638be29aa05384d680fc5da4c83b966771fba43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import ConfigParser
import os

from xdg import BaseDirectory

from leap.soledad.client import Soledad
from leap.mail.imap.service import imap


config = ConfigParser.ConfigParser()
config.read([os.path.expanduser('~/.config/leap/mail/mail.conf')])

userID = config.get('mail', 'address')
privkey = open(os.path.expanduser('~/.config/leap/mail/privkey')).read()
nickserver_url = ""

d = {}

for key in ('uid', 'passphrase', 'server', 'pemfile', 'token'):
    d[key] = config.get('mail', key)


def initialize_soledad_mailbox(user_uuid, soledad_pass, server_url,
                               server_pemfile, token):
    """
    Initializes soledad by hand

    :param user_uuid:
    :param soledad_pass:
    :param server_url:
    :param server_pemfile:
    :param token:

    :rtype: Soledad instance
    """

    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-mailbox.db" % user_uuid)

    _soledad = Soledad(
        user_uuid,
        soledad_pass,
        secret_path,
        soledad_path,
        server_url,
        server_pemfile,
        token)

    return _soledad

soledad = initialize_soledad_mailbox(
    d['uid'],
    d['passphrase'],
    d['server'],
    d['pemfile'],
    d['token'])

# import the private key ---- should sync it from remote!
from leap.common.keymanager.openpgp import OpenPGPScheme
opgp = OpenPGPScheme(soledad)
opgp.put_ascii_key(privkey)

from leap.common.keymanager import KeyManager
keymanager = KeyManager(userID, nickserver_url, soledad, d['token'])

imap.run_service(soledad, keymanager)