commit 23f1f186e569f596f8f00471284f7db76efa1cdb
parent 56fe5351ab3b12e225deef8a5969df356782d682
Author: Anders Damsgaard <anders.damsgaard@geo.au.dk>
Date: Mon, 7 Mar 2016 14:18:05 -0800
add support for gnome-keyring
Diffstat:
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/.mutt/offlineimap.py b/.mutt/offlineimap.py
@@ -4,6 +4,8 @@ import subprocess
import getpass
import os
import sys
+if sys.platform == 'linux2':
+ import gnomekeyring as gkey
user = getpass.getuser()
@@ -23,7 +25,24 @@ def get_keychain_pass(account=None, server=None):
return re.match(r'password: "(.*)"', outtext).group(1)
elif sys.platform == 'linux2':
- pass
+
+ attrs = {'server': server, 'protocol': 'http'}
+ items = gkey.find_items_sync(gkey.ITEM_NETWORK_PASSWORD, attrs)
+ return (items[0].attributes['user'], items[0].secret)
else:
raise Exception('Platform "' + sys.platform + '" not supported.')
+
+
+def set_keychain_pass(protocol, server, user, password):
+ if sys.platform != 'linux2':
+ raise Exception('Only Linux is supported for setting passwords.')
+
+ attrs = {'user': user,
+ 'server': server,
+ 'protocol': protocol}
+ name = 'offlineimap ' + server
+
+ gkey.item_create_sync(gkey.get_default_keyring_sync(),
+ gkey.ITEM_NETWORK_PASSWORD,
+ name, attrs, password, True)