diff options
author | Anton Khirnov <anton@khirnov.net> | 2020-03-05 10:06:22 +0100 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2020-03-05 10:06:22 +0100 |
commit | 6e159d42ea4051b4997f55b06c3775c1ebab0f77 (patch) | |
tree | db6d7f04baadd86312cf4b3c1c4396b6826261e2 /alot/commands/thread.py | |
parent | 46bb3a3efe8614478559a9594880367a8a419e53 (diff) |
db/utils: move clear_my_address/ensure_unique_address to their usage place
They are only used in a single file, so there is no point in keeping
them elsewhere.
Diffstat (limited to 'alot/commands/thread.py')
-rw-r--r-- | alot/commands/thread.py | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/alot/commands/thread.py b/alot/commands/thread.py index 3c955c95..c5e2747e 100644 --- a/alot/commands/thread.py +++ b/alot/commands/thread.py @@ -27,8 +27,6 @@ from .envelope import SendCommand from ..completion.contacts import ContactsCompleter from ..completion.path import PathCompleter from ..db.utils import formataddr -from ..db.utils import clear_my_address -from ..db.utils import ensure_unique_address from ..db.envelope import Envelope from ..db.attachment import Attachment from ..db.errors import DatabaseROError @@ -39,6 +37,34 @@ from ..utils import argparse as cargparse MODE = 'thread' +def ensure_unique_address(recipients): + """ + clean up a list of name,address pairs so that + no address appears multiple times. + """ + res = dict() + for name, address in email.utils.getaddresses(recipients): + res[address] = name + logging.debug(res) + urecipients = [formataddr((n, a)) for a, n in res.items()] + return sorted(urecipients) + +def clear_my_address(my_account, value): + """return recipient header without the addresses in my_account + + :param my_account: my account + :type my_account: :class:`Account` + :param value: a list of recipient or sender strings (with or without + real names as taken from email headers) + :type value: list(str) + :returns: a new, potentially shortend list + :rtype: list(str) + """ + new_value = [] + for name, address in email.utils.getaddresses(value): + if not my_account.matches_address(address): + new_value.append(formataddr((name, address))) + return new_value def determine_sender(mail, action='reply'): """ |