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.
 

74 lines
2.2 KiB

# coding=UTF-8
import os
import re
from fileinput import input
class ThunderbirdNotFound(LookupError):
pass
def profile_path(thunderbird_base):
from ConfigParser import SafeConfigParser
config = SafeConfigParser()
filename = os.path.join(thunderbird_base, 'profiles.ini')
config.read(filename)
for section in config.sections():
try:
if config.get(section, 'Name') == 'default-release':
return os.path.join(thunderbird_base, config.get(section, 'Path'))
except: pass
raise ThunderbirdNotFound()
def prefs(thunderbird_base, key):
c = re.compile(r'user_pref\(["\']' + key + '["\'],\s*["\']?(?P<value>[^"\']*)["\']?\);', re.UNICODE)
filename = os.path.join(profile_path(thunderbird_base), 'prefs.js')
finput = input(files=(filename,))
for line in finput:
m = c.search(line)
if m:
finput.close()
return m.group('value')
return None
def enigmail_agentPath(thunderbird_base):
return prefs(thunderbird_base, r'extensions\.enigmail\.agentPath')
def enigmail_juniorMode(thunderbird_base):
result = prefs(thunderbird_base, r'extensions\.enigmail\.juniorMode')
if result == '0':
return False
else:
return True
def enigmail_assignKeysByRules(thunderbird_base):
result = prefs(thunderbird_base, r'extensions\.enigmail\.assignKeysByRules')
if result == 'false':
return False
else:
return True
def enigmail_assignKeysByEmailAddr(thunderbird_base):
result = prefs(thunderbird_base, r'extensions\.enigmail\.assignKeysByEmailAddr')
if result == 'false':
return False
else:
return True
def identities(thunderbird_base):
result = {}
c = re.compile(r'user_pref\(["\']mail\.identity\.(?P<name>\w+)\.(?P<field>\w+)["\'],\s*["\'](?P<value>[^"\']*)["\']\);', re.UNICODE)
filename = os.path.join(profile_path(thunderbird_base), 'prefs.js')
for line in input(files=(filename,)):
m = c.search(line)
if m:
if not m.group('name') in result:
result[m.group('name')] = {}
result[m.group('name')][m.group('field')] = m.group('value')
return result