Import data from Enigmail to pEp for Thunderbird
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

154 lines
4.5 KiB

# coding=UTF-8
import sys
import os
import json
from httplib import HTTPConnection
if sys.platform == 'darwin':
from platform_macOS import *
elif sys.platform == 'win32':
from platform_Windows import *
from platform_Linux import *
addon_text = """{
"id": "",
"version": "dummy",
"type": "extension",
"loader": null,
"updateURL": null,
"optionsURL": null,
"optionsType": null,
"optionsBrowserStyle": true,
"aboutURL": null,
"defaultLocale": {},
"visible": true,
"active": true,
"userDisabled": false,
"appDisabled": false,
"embedderDisabled": false,
"applyBackgroundUpdates": 1,
"skinnable": false,
"sourceURI": null,
"releaseNotesURI": null,
"softDisabled": false,
"foreignInstall": true,
"strictCompatibility": true,
"locales": [{"locales": ["en"]},{"locales": ["de"]}],
"targetPlatforms": [],
"signedState": 0,
"signedDate": null,
"seen": false,
"dependencies": [],
"incognito": "spanning",
"userPermissions": {"permissions": [],"origins": []},
"optionalPermissions": {"permissions": [],"origins": []},
"iconURL": null,
"blocklistState": 0,
"blocklistURL": null,
"startupData": null,
"hidden": false,
"installTelemetryInfo": {"source": "app-profile","method": "sideload"},
"recommendationState": null,
"location": "app-profile"
def enable_addon(profile):
print "--- enable pEp add-on in profile " + profile
print "--- 1. disable Thunderbird's OpenPGP extension"
print "--- read prefs.js"
with open(os.path.join(profile, 'prefs.js'), 'rU') as f:
prefs = f.readlines()
print '--- add or replace user_pref("mail.openpgp.enable", false);'
found = False
for i in xrange(len(prefs)):
line = prefs[i]
if line[:31] == 'user_pref("mail.openpgp.enable"':
found = True
prefs[i] = 'user_pref("mail.openpgp.enable", false);\n'
if not found:
prefs.append('user_pref("mail.openpgp.enable", false);\n')
# The values for extensions.startupScanScopes are explained here:
# The Thunderbird default is SCOPE_APPLICATION (4): Installed and owned by the application.
# We add SCOPE_PROFILE (1): Installed in this profile.
found = False
for i in xrange(len(prefs)):
line = prefs[i]
if line[:40] == 'user_pref("extensions.startupScanScopes"':
found = True
prefs[i] = 'user_pref("extensions.startupScanScopes", 5);\n'
if not found:
prefs.append('user_pref("extensions.startupScanScopes", 5);\n')
print "--- write prefs.js"
with open(os.path.join(profile, 'prefs.js'), 'w+') as f:
print "--- 2. enable pEp add-on"
print "--- read extensions.json"
with open(os.path.join(profile, 'extensions.json'), 'r') as f:
extensions = json.load(f)
print '--- add or replace "id": ""'
addons = extensions[u'addons']
found = False
for i in xrange(len(addons)):
if addons[i][u'id'] == u'':
found = True
addons[i] = json.loads(addon_text)
if not found:
print '--- write extensions.json'
with open(os.path.join(profile, 'extensions.json'), 'w+') as f:
json.dump(extensions, f)
class Connection:
def __init__(self):
filename = os.path.join(per_user_directory, 'json-token')
self.config = json.load(file(filename))
self.next_id = 1
def __enter__(self):
self.http_connection = HTTPConnection(str(self.config[u'address']), int(self.config[u'port']))
return self
def __exit__(self, type, value, traceback):
def __call__(self, method, *params):
func = {'method': method}
func['params'] = params
func['id'] = self.next_id
self.next_id += 1
func['jsonrpc'] = '2.0'
func['security_token'] = str(self.config[u'security_token'])
params = json.dumps(func)
headers = {"Connection": "Keep-Alive"}
self.http_connection.request("POST", str(self.config[u'path']) + "callFunction", params, headers)
response = self.http_connection.getresponse()
data = None
if response.status < 400:
data =
print response.status
return json.loads(data)['result']