summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Totzke <patricktotzke@gmail.com>2012-03-11 14:54:48 +0000
committerPatrick Totzke <patricktotzke@gmail.com>2012-03-11 14:54:48 +0000
commit2fe56f7a11718d480b9e8dffea4ba873107fa42e (patch)
tree7023ef80202eaba8e8631c6589c846e8aeedf16c
parent42a0466cafa979513f4e0efe6d81bcec953bc711 (diff)
cleanup: moved addressbooks into separate file
-rw-r--r--alot/account.py80
-rw-r--r--alot/settings/__init__.py3
-rw-r--r--docs/source/api/settings.rst3
3 files changed, 6 insertions, 80 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
diff --git a/alot/settings/__init__.py b/alot/settings/__init__.py
index 86d4d9b4..1c0efa9b 100644
--- a/alot/settings/__init__.py
+++ b/alot/settings/__init__.py
@@ -7,7 +7,8 @@ import urwid
from urwid import AttrSpec, AttrSpecError
from configobj import ConfigObj, Section
-from alot.account import SendmailAccount, MatchSdtoutAddressbook, AbookAddressBook
+from alot.account import SendmailAccount
+from alot.addressbooks import MatchSdtoutAddressbook, AbookAddressBook
from errors import ConfigError
from utils import read_config
diff --git a/docs/source/api/settings.rst b/docs/source/api/settings.rst
index e1f674cf..00a64f83 100644
--- a/docs/source/api/settings.rst
+++ b/docs/source/api/settings.rst
@@ -32,6 +32,7 @@ Accounts
--------
.. module:: alot.account
+
.. autoclass:: Account
:members:
.. autoclass:: SendmailAccount
@@ -40,6 +41,8 @@ Accounts
Addressbooks
------------
+.. module:: alot.addressbooks
+
.. autoclass:: AddressBook
:members:
.. autoclass:: MatchSdtoutAddressbook