From 6885f5283b2a944200bc3e4d7baf658fc57f492f Mon Sep 17 00:00:00 2001 From: Lucas Hoffmann Date: Fri, 23 Jun 2017 00:31:52 +0200 Subject: determine_sender: replace complicated break logic by return --- alot/commands/thread.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'alot/commands/thread.py') diff --git a/alot/commands/thread.py b/alot/commands/thread.py index c1743264..8f1ae039 100644 --- a/alot/commands/thread.py +++ b/alot/commands/thread.py @@ -52,9 +52,6 @@ def determine_sender(mail, action='reply'): :type action: str """ assert action in ['reply', 'forward', 'bounce'] - realname = None - address = None - matching_account = None # get accounts my_accounts = settings.get_accounts() @@ -68,8 +65,6 @@ def determine_sender(mail, action='reply'): # account X is the one selected and not account Y. candidate_headers = settings.get("reply_account_header_priority") for candidate_header in candidate_headers: - if matching_account is not None: - break candidate_addresses = getaddresses(mail.get_all(candidate_header, [])) logging.debug('candidate addresses: %s', candidate_addresses) @@ -80,8 +75,6 @@ def determine_sender(mail, action='reply'): if account.alias_regexp is not None: acc_addresses.append(account.alias_regexp) for alias in acc_addresses: - if matching_account is not None: - break regex = re.compile('^' + alias + '$', flags=re.IGNORECASE) for seen_name, seen_address in candidate_addresses: if regex.match(seen_address): @@ -94,18 +87,22 @@ def determine_sender(mail, action='reply'): address = account.address else: address = seen_address - matching_account = account + + logging.debug('using realname: "%s"', realname) + logging.debug('using address: %s', address) + + from_value = formataddr((realname, address)) + return from_value, account # revert to default account if nothing found - if matching_account is None: - matching_account = my_accounts[0] - realname = matching_account.realname - address = matching_account.address + account = my_accounts[0] + realname = account.realname + address = account.address logging.debug('using realname: "%s"', realname) logging.debug('using address: %s', address) from_value = formataddr((realname, address)) - return from_value, matching_account + return from_value, account @registerCommand(MODE, 'reply', arguments=[ -- cgit v1.2.3