diff options
author | Patrick Totzke <patricktotzke@gmail.com> | 2012-09-22 10:37:41 +0100 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2012-09-22 10:37:41 +0100 |
commit | fcf24cf739cdc788934869bdacf250780b04fd58 (patch) | |
tree | 4a5d751f4bc3713dc4165a648673358dca2176ed | |
parent | aaadf1728c58a5afbe43cfdac9bbb1ee5b151bd8 (diff) | |
parent | fd373623748c55eb5361eeb0700ed7f74db77455 (diff) |
Merge branch '0.3.3-feature-case-insensitive-abook'
-rw-r--r-- | alot/addressbooks.py | 22 | ||||
-rw-r--r-- | alot/defaults/alot.rc.spec | 4 | ||||
-rw-r--r-- | alot/settings/manager.py | 2 | ||||
-rw-r--r-- | docs/source/configuration/contacts_completion.rst | 4 |
4 files changed, 23 insertions, 9 deletions
diff --git a/alot/addressbooks.py b/alot/addressbooks.py index d2d134f2..7767e597 100644 --- a/alot/addressbooks.py +++ b/alot/addressbooks.py @@ -18,27 +18,34 @@ class AddressBook(object): unspecified. See :class:`AbookAddressBook` and :class:`MatchSdtoutAddressbook` for implementations. """ + def __init__(self, ignorecase=True): + self.reflags = re.IGNORECASE if ignorecase else 0 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)""" + def lookup(self, query=''): + """looks up all contacts where name or address match query""" res = [] + query = '.*%s.*' % query for name, email in self.get_contacts(): - if name.startswith(prefix) or email.startswith(prefix): - res.append((name, email)) + try: + if re.match(query, name, self.reflags) or re.match(query, email, self.reflags): + res.append((name, email)) + except: + pass return res class AbookAddressBook(AddressBook): """:class:`AddressBook` that parses abook's config/database files""" - def __init__(self, path='~/.abook/addressbook'): + def __init__(self, path='~/.abook/addressbook', **kwargs): """ :param path: path to theme file :type path: str """ + AddressBook.__init__(self, **kwargs) DEFAULTSPATH = os.path.join(os.path.dirname(__file__), 'defaults') self._spec = os.path.join(DEFAULTSPATH, 'abook_contacts.spec') path = os.path.expanduser(path) @@ -58,7 +65,7 @@ class AbookAddressBook(AddressBook): class MatchSdtoutAddressbook(AddressBook): """:class:`AddressBook` that parses a shell command's output for lookups""" - def __init__(self, command, match=None): + def __init__(self, command, match=None, **kwargs): """ :param command: lookup command :type command: str @@ -68,6 +75,7 @@ class MatchSdtoutAddressbook(AddressBook): :regexp:`^(?P<email>[^@]+@[^\t]+)\t+(?P<name>[^\t]+)`. :type match: str """ + AddressBook.__init__(self, **kwargs) self.command = command if not match: self.match = '^(?P<email>[^@]+@[^\t]+)\t+(?P<name>[^\t]+)' @@ -85,7 +93,7 @@ class MatchSdtoutAddressbook(AddressBook): lines = resultstring.splitlines() res = [] for l in lines: - m = re.match(self.match, l) + m = re.match(self.match, l, self.reflags) if m: info = m.groupdict() email = info['email'].strip() diff --git a/alot/defaults/alot.rc.spec b/alot/defaults/alot.rc.spec index 9506aa04..fabfd793 100644 --- a/alot/defaults/alot.rc.spec +++ b/alot/defaults/alot.rc.spec @@ -248,6 +248,10 @@ forward_subject_prefix = string(default='Fwd: ') [[[abook]]] # type identifier for address book type = option('shellcommand', 'abook', default=None) + + # make case-insensitive lookups + ignorecase = boolean(default=True) + # command to lookup contacts in shellcommand abooks # it will be called with the lookup prefix as only argument command = string(default=None) diff --git a/alot/settings/manager.py b/alot/settings/manager.py index 1d38ef82..dff367b2 100644 --- a/alot/settings/manager.py +++ b/alot/settings/manager.py @@ -130,7 +130,7 @@ class SettingsManager(object): raise ConfigError(msg) elif abook['type'] == 'abook': contacts_path = abook['abook_contacts_file'] - args['abook'] = AbookAddressBook(contacts_path) + args['abook'] = AbookAddressBook(contacts_path, ignorecase=abook['ignorecase']) else: del(args['abook']) diff --git a/docs/source/configuration/contacts_completion.rst b/docs/source/configuration/contacts_completion.rst index b1c9f313..6c6b62eb 100644 --- a/docs/source/configuration/contacts_completion.rst +++ b/docs/source/configuration/contacts_completion.rst @@ -4,7 +4,8 @@ Contacts Completion =================== For each :ref:`account <config.accounts>` you can define an address book by providing a subsection named `abook`. Crucially, this section needs an option `type` that specifies the type of the address book. -The only types supported at the moment are "shellcommand" and "abook": +The only types supported at the moment are "shellcommand" and "abook". +Both respect the `ignorecase` option which defaults to `True` and results in case insensitive lookups. .. describe:: shellcommand @@ -25,6 +26,7 @@ The only types supported at the moment are "shellcommand" and "abook": type = shellcommand command = abook --mutt-query regexp = '^(?P<email>[^@]+@[^\t]+)\t+(?P<name>[^\t]+)' + ignorecase = True See `here <http://notmuchmail.org/emacstips/#index12h2>`_ for alternative lookup commands. |