diff options
author | Patrick Totzke <patricktotzke@gmail.com> | 2016-12-06 14:46:50 +0000 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2016-12-06 14:46:50 +0000 |
commit | 50cd4588302eb430143144d7b61693c0460be11e (patch) | |
tree | b44aacf0c610387bb75b5fb17c2c837801375f50 | |
parent | ca60765745907b827229d73acb4e637511c046ca (diff) | |
parent | fdcd644135556b78733ead49b8f0210b553c94e2 (diff) |
Merge branch '0.3.8-reply_account_header_priority'
-rw-r--r-- | alot/commands/thread.py | 61 | ||||
-rw-r--r-- | alot/defaults/alot.rc.spec | 8 |
2 files changed, 39 insertions, 30 deletions
diff --git a/alot/commands/thread.py b/alot/commands/thread.py index e5ad72a4..3286786c 100644 --- a/alot/commands/thread.py +++ b/alot/commands/thread.py @@ -61,35 +61,38 @@ def determine_sender(mail, action='reply'): # extract list of addresses to check for my address # X-Envelope-To and Envelope-To are used to store the recipient address # if not included in other fields - candidate_addresses = getaddresses(mail.get_all('To', []) + - mail.get_all('Cc', []) + - mail.get_all('Delivered-To', []) + - mail.get_all('X-Envelope-To', []) + - mail.get_all('Envelope-To', []) + - mail.get_all('From', [])) - - logging.debug('candidate addresses: %s' % candidate_addresses) - # pick the most important account that has an address in candidates - # and use that accounts realname and the address found here - for account in my_accounts: - acc_addresses = map(re.escape, account.get_addresses()) - if account.alias_regexp is not None: - acc_addresses.append(account.alias_regexp) - for alias in acc_addresses: - if realname is not None: - break - regex = re.compile('^' + alias + '$', flags=re.IGNORECASE) - for seen_name, seen_address in candidate_addresses: - if regex.match(seen_address): - logging.debug("match!: '%s' '%s'" % (seen_address, alias)) - if settings.get(action + '_force_realname'): - realname = account.realname - else: - realname = seen_name - if settings.get(action + '_force_address'): - address = account.address - else: - address = seen_address + # Process the headers in order of importance: if a mail was sent with + # account X, with account Y in e.g. CC or delivered-to, make sure that + # 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 realname is not None: + break + candidate_addresses = getaddresses(mail.get_all(candidate_header, [])) + + logging.debug('candidate addresses: %s' % candidate_addresses) + # pick the most important account that has an address in candidates + # and use that accounts realname and the address found here + for account in my_accounts: + acc_addresses = map(re.escape, account.get_addresses()) + if account.alias_regexp is not None: + acc_addresses.append(account.alias_regexp) + for alias in acc_addresses: + if realname is not None: + break + regex = re.compile('^' + alias + '$', flags=re.IGNORECASE) + for seen_name, seen_address in candidate_addresses: + if regex.match(seen_address): + logging.debug("match!: '%s' '%s'" % (seen_address, + alias)) + if settings.get(action + '_force_realname'): + realname = account.realname + else: + realname = seen_name + if settings.get(action + '_force_address'): + address = account.address + else: + address = seen_address # revert to default account if nothing found if realname is None: diff --git a/alot/defaults/alot.rc.spec b/alot/defaults/alot.rc.spec index 0967bf4f..327bbc28 100644 --- a/alot/defaults/alot.rc.spec +++ b/alot/defaults/alot.rc.spec @@ -229,7 +229,13 @@ prefer_plaintext = boolean(default=False) # messages in that thread. msg_summary_hides_threadwide_tags = boolean(default=True) -# Key bindings +# The list of headers to match to determine sending account for a reply. +# Headers are searched in the order in which they are specified here, and the first header +# containing a match is used. If multiple accounts match in that header, the one defined +# first in the account block is used. +reply_account_header_priority = force_list(default=list(From,To,Cc,Envelope-To,X-Envelope-To,Delivered-To)) + +# Key bindings [bindings] __many__ = string(default=None) [[___many___]] |