-
Notifications
You must be signed in to change notification settings - Fork 1
/
gnome-keyring-add-imap-password.py
43 lines (35 loc) · 1.32 KB
/
gnome-keyring-add-imap-password.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/python
import gtk
import gnomekeyring as gkey
import getpass
class Keyring(object):
def __init__(self, name, server, protocol):
self._name = name
self._server = server
self._protocol = protocol
self._keyring = gkey.get_default_keyring_sync()
def has_credentials(self):
try:
attrs = {"server": self._server, "protocol": self._protocol}
items = gkey.find_items_sync(gkey.ITEM_NETWORK_PASSWORD, attrs)
return len(items) > 0
except gkey.DeniedError:
return False
def get_credentials(self):
attrs = {"server": self._server, "protocol": self._protocol}
items = gkey.find_items_sync(gkey.ITEM_NETWORK_PASSWORD, attrs)
return (items[0].attributes["user"], items[0].secret)
def set_credentials(self, (user, pw)):
attrs = {
"user": user,
"server": self._server,
"protocol": self._protocol,
}
gkey.item_create_sync(gkey.get_default_keyring_sync(),
gkey.ITEM_NETWORK_PASSWORD, self._name, attrs, pw, True)
server = raw_input("Server: ")
username = raw_input("Username: ")
password = getpass.getpass(prompt="Password: ")
print
keyring = Keyring("offlineimap", server, "imap")
keyring.set_credentials((username, password))