summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Totzke <patricktotzke@gmail.com>2012-09-16 13:55:18 +0200
committerPatrick Totzke <patricktotzke@gmail.com>2012-09-22 10:37:02 +0100
commitf669476d9afe8bdbe9d321e8adc96947e1d29926 (patch)
tree471b0e48aba129bdb1442ffe25d7bb9d1f798dc2
parentaaadf1728c58a5afbe43cfdac9bbb1ee5b151bd8 (diff)
use re instead of .startswith in Addessbook.lookup
This is inherited in AbookAddressbook and thus makes regexp-searches possible when completing abook type addressbooks. By default this uses the re.IGNORECASE flag.
-rw-r--r--alot/addressbooks.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/alot/addressbooks.py b/alot/addressbooks.py
index d2d134f2..a1491f29 100644
--- a/alot/addressbooks.py
+++ b/alot/addressbooks.py
@@ -23,12 +23,17 @@ class AddressBook(object):
"""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='', ignorecase=True):
+ """looks up all contacts where name or address match query"""
res = []
+ query = '.*%s.*' % query
+ flags = re.IGNORECASE if ignorecase else 0
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, flags) or re.match(query, email, flags):
+ res.append((name, email))
+ except:
+ pass
return res