diff options
author | Patrick Totzke <patricktotzke@gmail.com> | 2012-03-11 14:54:48 +0000 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2012-03-11 14:54:48 +0000 |
commit | 2fe56f7a11718d480b9e8dffea4ba873107fa42e (patch) | |
tree | 7023ef80202eaba8e8631c6589c846e8aeedf16c /alot/account.py | |
parent | 42a0466cafa979513f4e0efe6d81bcec953bc711 (diff) |
cleanup: moved addressbooks into separate file
Diffstat (limited to 'alot/account.py')
-rw-r--r-- | alot/account.py | 80 |
1 files changed, 1 insertions, 79 deletions
diff --git a/alot/account.py b/alot/account.py index 8faee595..d8373580 100644 --- a/alot/account.py +++ b/alot/account.py @@ -41,7 +41,7 @@ class Account(object): signature_as_attachment = None """attach signature file instead of appending its content to body text""" abook = None - """addressbook (:class:`AddressBook`) managing this accounts contacts""" + """addressbook (:class:`addressbooks.AddressBook`) managing this accounts contacts""" def __init__(self, address=None, aliases=None, realname=None, gpg_key=None, signature=None, signature_filename=None, @@ -168,81 +168,3 @@ class SendmailAccount(Account): return d -class AddressBook(object): - """can look up email addresses and realnames for contacts. - - .. note:: - - This is an abstract class that leaves :meth:`get_contacts` - unspecified. See :class:`AbookAddressBook` and - :class:`MatchSdtoutAddressbook` for implementations. - """ - - def get_contacts(self): - """list all contacts tuples in this abook as (name, email) tuples""" - return [] - - def lookup(self, prefix=''): - """looks up all contacts with given prefix (in name or address)""" - res = [] - for name, email in self.get_contacts(): - if name.startswith(prefix) or email.startswith(prefix): - res.append((name, email)) - return res - - -class AbookAddressBook(AddressBook): - """:class:`AddressBook` that parses abook's config/database files""" - def __init__(self, path='~/.abook/addressbook'): - """ - :param path: path to theme file - :type path: str - """ - DEFAULTSPATH = os.path.join(os.path.dirname(__file__), 'defaults') - self._spec = os.path.join(DEFAULTSPATH, 'abook_contacts.spec') - path = os.path.expanduser(path) - self._config = read_config(path, self._spec) - del(self._config['format']) - - def get_contacts(self): - c = self._config - return [(c[id]['name'], c[id]['email']) for id in c.sections if \ - c[id]['email'] is not None] - - -class MatchSdtoutAddressbook(AddressBook): - """:class:`AddressBook` that parses a shell command's output for lookups""" - def __init__(self, command, match=None): - """ - :param command: lookup command - :type command: str - :param match: regular expression used to match contacts in `commands` - output to stdout. Must define subparts named "email" and - "name". Defaults to - :regexp:`^(?P<email>[^@]+@[^\t]+)\t+(?P<name>[^\t]+)`. - :type match: str - """ - self.command = command - if not match: - self.match = '^(?P<email>[^@]+@[^\t]+)\t+(?P<name>[^\t]+)' - else: - self.match = match - - def get_contacts(self): - return self.lookup('\'\'') - - def lookup(self, prefix): - cmdlist = shlex.split(self.command.encode('utf-8', errors='ignore')) - resultstring, errmsg, retval = helper.call_cmd(cmdlist + [prefix]) - if not resultstring: - return [] - lines = resultstring.splitlines() - res = [] - for l in lines: - m = re.match(self.match, l) - if m: - info = m.groupdict() - email = info['email'].strip() - name = info['name'] - res.append((name, email)) - return res |