summaryrefslogtreecommitdiff
path: root/alot/account.py
diff options
context:
space:
mode:
authorPatrick Totzke <patricktotzke@gmail.com>2011-08-17 23:03:43 +0100
committerPatrick Totzke <patricktotzke@gmail.com>2011-08-17 23:03:43 +0100
commitc71aca4f5479600a9a9c20ccc12cf8fc2b67f694 (patch)
treec30874415fb85b46e3bf6399484113e2f00aafb5 /alot/account.py
parent185f33acf251cc03b9e9682fd8c5ee9bcf9134a0 (diff)
addressbook class and abook parser
Diffstat (limited to 'alot/account.py')
-rw-r--r--alot/account.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/alot/account.py b/alot/account.py
index 720d3878..bcb69db0 100644
--- a/alot/account.py
+++ b/alot/account.py
@@ -23,6 +23,8 @@ import subprocess
import logging
import time
import email
+import os
+from ConfigParser import SafeConfigParser
from urlparse import urlparse
@@ -220,3 +222,32 @@ class AccountManager:
def get_addresses(self):
"""returns addresses of known accounts including all their aliases"""
return self.accountmap.keys()
+
+
+class AddressBook:
+ def get_contacts(self):
+ return []
+
+ def lookup(self, prefix=''):
+ res = []
+ for name, email in self.get_contacts():
+ if name.startswith(prefix) or email.startswith(prefix):
+ res.append("%s <%s>" % (name, email))
+ return res
+
+
+class AbookAddressBook(AddressBook):
+ def __init__(self, config=None):
+ self.abook = SafeConfigParser()
+ if not config:
+ config = os.environ["HOME"] + "/.abook/addressbook"
+ self.abook.read(config)
+
+ def get_contacts(self):
+ res = []
+ for s in self.abook.sections():
+ if s.isdigit():
+ name = self.abook.get(s, 'name')
+ email = self.abook.get(s, 'email')
+ res.append((name,email))
+ return res