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.
ImportFromEnigmail/pEp_JSON.py

53 lines
1.4 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 *
elif sys.platform == 'linux':
from platform_Linux import *
else:
sys.stderr.write("platform not supported\n")
sys.exit(1)
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):
self.http_connection.close()
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 = response.read()
else:
print response.status
return json.loads(data)['result']