diff options
author | vrs <none> | 2018-12-08 23:11:24 +0100 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2018-12-10 10:25:49 +0000 |
commit | f7c5b841568886be64695a14f341c4c7c58b3fba (patch) | |
tree | 415ff08c0d7a9b5e695c4c9e26ede7e000db1eba /alot/account.py | |
parent | b981bfe0c61d9aa55652b4b0a01b846aaa9c993a (diff) |
match addresses against accounts, not address lists
fixes #1230, fixes an unfiled bug in clear_my_address()
Diffstat (limited to 'alot/account.py')
-rw-r--r-- | alot/account.py | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/alot/account.py b/alot/account.py index c8f3c09a..116c3417 100644 --- a/alot/account.py +++ b/alot/account.py @@ -9,6 +9,7 @@ import logging import mailbox import operator import os +import re from .helper import call_cmd_async from .helper import split_commandstring @@ -176,7 +177,7 @@ class Account(object): """this accounts main email address""" aliases = [] """list of alternative addresses""" - alias_regexp = [] + alias_regexp = "" """regex matching alternative addresses""" realname = None """real name used to format from-headers""" @@ -243,12 +244,34 @@ class Account(object): encrypt_by_default = u"none" logging.info(msg) self.encrypt_by_default = encrypt_by_default + # cache alias_regexp regexes + if self.alias_regexp != "": + self._alias_regexp = re.compile( + u'^' + str(self.alias_regexp) + u'$', + flags=0 if case_sensitive_username else re.IGNORECASE) + def get_addresses(self): """return all email addresses connected to this account, in order of their importance""" return [self.address] + self.aliases + def matches_address(self, address): + """returns whether this account knows about an email address + + :param str address: address to look up + :rtype: bool + """ + if self.address == address: + return True + for alias in self.aliases: + if alias == address: + return True + if self._alias_regexp is not None: + if self._alias_regexp.match(address): + return True + return False + @staticmethod def store_mail(mbx, mail): """ |