summaryrefslogtreecommitdiff
path: root/alot/db/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'alot/db/utils.py')
-rw-r--r--alot/db/utils.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/alot/db/utils.py b/alot/db/utils.py
index 63260b22..49d5b6d2 100644
--- a/alot/db/utils.py
+++ b/alot/db/utils.py
@@ -561,3 +561,34 @@ def is_subdir_of(subpath, superpath):
# return true, if the common prefix of both is equal to directory
# e.g. /a/b/c/d.rst and directory is /a/b, the common prefix is /a/b
return os.path.commonprefix([subpath, superpath]) == superpath
+
+
+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 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)