#!/usr/bin/python
|
|
# coding=UTF-8
|
|
|
|
# macOS only supports Python 2.7
|
|
|
|
|
|
import sys
|
|
import enigmail
|
|
import pEp_JSON
|
|
import thunderbird
|
|
from enigmail import thunderbird_base
|
|
from base64 import b64encode
|
|
|
|
|
|
with pEp_JSON.Connection() as call:
|
|
|
|
# import keydata from own keys
|
|
|
|
own_pgp_keys = enigmail.own_pgp_keys()
|
|
|
|
for own_key in own_pgp_keys:
|
|
keydata = enigmail.secret(own_key['fpr'])
|
|
call('import_key', b64encode(keydata), 23, [ '42', ])
|
|
|
|
# import keydata from comm_partners
|
|
|
|
for keydata in enigmail.pubkey_iterator():
|
|
result = call('import_key', b64encode(keydata), 23, [ '42', ])
|
|
|
|
# if enigmail is not in p≡p mode create comm_partner's identities
|
|
|
|
if not thunderbird.enigmail_juniorMode(thunderbird_base):
|
|
|
|
# set own keys
|
|
|
|
for own_key in own_pgp_keys:
|
|
for uid in own_key['uids']:
|
|
me = {
|
|
'username': uid['name'],
|
|
'user_id': 'pEp_own_userId',
|
|
'address': uid['email'],
|
|
'fpr': own_key['fpr'],
|
|
}
|
|
|
|
call('set_own_key', me, own_key['fpr'])
|
|
|
|
# set own identities
|
|
|
|
for tbid, own_identity in enigmail.identities().iteritems():
|
|
me = {
|
|
'username': own_identity['fullName'],
|
|
'user_id': 'pEp_own_userId',
|
|
'address': own_identity['useremail'],
|
|
}
|
|
|
|
if own_identity['pgpkeyId'] and len(own_identity['pgpkeyId']) > 2:
|
|
call('set_own_key', me, own_identity['pgpkeyId'][2:])
|
|
|
|
call('myself', me)
|
|
|
|
# set comm partner's identities
|
|
|
|
if thunderbird.enigmail_assignKeysByRules(thunderbird_base) or \
|
|
thunderbird.enigmail_assignKeysByEmailAddr(thunderbird_base):
|
|
|
|
for pgpkey in enigmail.comm_partner_pgp_keys():
|
|
for uid in pgpkey['uids']:
|
|
if thunderbird.enigmail_assignKeysByRules(thunderbird_base):
|
|
result = enigmail.rules.test_address(uid['email'])
|
|
if result == False:
|
|
pass
|
|
elif result == True:
|
|
if thunderbird.enigmail_assignKeysByEmailAddr(thunderbird_base):
|
|
ident = {
|
|
'username': uid['name'],
|
|
'address': uid['email'],
|
|
}
|
|
ident = call('update_identity', ident)[u'outParams'][0]
|
|
ident[u'fpr'] = pgpkey['fpr']
|
|
call('set_identity', ident)
|
|
else:
|
|
ident = {
|
|
'username': uid['name'],
|
|
'address': uid['email'],
|
|
}
|
|
ident = call('update_identity', ident)[u'outParams'][0]
|
|
ident[u'fpr'] = result
|
|
call('set_identity', ident)
|
|
else:
|
|
ident = {
|
|
'username': uid['name'],
|
|
'address': uid['email'],
|
|
}
|
|
ident = call('update_identity', ident)[u'outParams'][0]
|
|
ident[u'fpr'] = pgpkey['fpr']
|
|
call('set_identity', ident)
|
|
|