summaryrefslogtreecommitdiff
path: root/offlineimap
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2012-07-28 11:38:40 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2012-07-28 11:38:40 +0100
commit423ce84b1877b8efca404221b1fdb0488e6cb6db (patch)
tree4f47243e47f54cc571758af0ab66db6936af8585 /offlineimap
downloadresources-423ce84b1877b8efca404221b1fdb0488e6cb6db.tar.bz2
RES: Initial crud
Diffstat (limited to 'offlineimap')
-rw-r--r--offlineimap/extras.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/offlineimap/extras.py b/offlineimap/extras.py
new file mode 100644
index 0000000..fbc8836
--- /dev/null
+++ b/offlineimap/extras.py
@@ -0,0 +1,60 @@
+# Useful features for offlineimap
+
+
+prioritylist = [ "INBOX" ]
+
+def prioritycmp(x, y):
+ for prefix in prioritylist:
+ xsw = x.startswith(prefix)
+ ysw = y.startswith(prefix)
+ if xsw and ysw:
+ return cmp(x, y)
+ elif xsw:
+ return -1
+ elif ysw:
+ return 1
+ return cmp(x, y)
+
+
+import sys
+import gtk
+import gnomekeyring as gkey
+
+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)
+
+def get_username(server):
+ keyring = Keyring("offlineimap", server, "imap")
+ (username, password) = keyring.get_credentials()
+ return username
+
+def get_password(server):
+ keyring = Keyring("offlineimap", server, "imap")
+ (username, password) = keyring.get_credentials()
+ return password