summaryrefslogtreecommitdiff
path: root/alot/helper.py
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2020-03-05 10:22:52 +0100
committerAnton Khirnov <anton@khirnov.net>2020-03-05 10:24:12 +0100
commitd4b8a1ccacda08c29ad93cdb344c6fc1debcac30 (patch)
tree31b5ec80e45071b092feda3acf9ab233cc38f59c /alot/helper.py
parent8a6ce8a29d8d61385c4222b9018b936e658cfb24 (diff)
db/utils: move formataddr to helper
It has no relation to database, so helper seems like a better place for it. As there is nothing left in db/utils, it is removed.
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)