From f7c5b841568886be64695a14f341c4c7c58b3fba Mon Sep 17 00:00:00 2001 From: vrs Date: Sat, 8 Dec 2018 23:11:24 +0100 Subject: match addresses against accounts, not address lists fixes #1230, fixes an unfiled bug in clear_my_address() --- alot/account.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'alot/account.py') 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): """ -- cgit v1.2.3