summaryrefslogtreecommitdiff
path: root/alot/helper.py
diff options
context:
space:
mode:
Diffstat (limited to 'alot/helper.py')
-rw-r--r--alot/helper.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/alot/helper.py b/alot/helper.py
index aab3242e..1d541d76 100644
--- a/alot/helper.py
+++ b/alot/helper.py
@@ -602,3 +602,16 @@ def get_xdg_env(env_name, fallback):
""" Used for XDG_* env variables to return fallback if unset *or* empty """
env = os.environ.get(env_name)
return env if env else fallback
+
+def formataddr(pair):
+ """ this is the inverse of email.utils.parseaddr:
+ other than email.utils.formataddr, this
+ - *will not* re-encode unicode strings, and
+ - *will* re-introduce quotes around real names containing commas
+ """
+ name, address = pair
+ if not name:
+ return address
+ elif ',' in name:
+ name = "\"" + name + "\""
+ return "{0} <{1}>".format(name, address)