summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--alot/commands/globals.py3
-rw-r--r--alot/commands/thread.py13
2 files changed, 6 insertions, 10 deletions
diff --git a/alot/commands/globals.py b/alot/commands/globals.py
index d05bdfcc..ef085259 100644
--- a/alot/commands/globals.py
+++ b/alot/commands/globals.py
@@ -6,6 +6,7 @@ from __future__ import absolute_import
import argparse
import code
import email
+import email.utils
import glob
import logging
import os
@@ -805,7 +806,7 @@ class ComposeCommand(Command):
accounts = settings.get_accounts()
if len(accounts) == 1:
a = accounts[0]
- fromstring = "%s <%s>" % (a.realname, a.address)
+ fromstring = email.utils.formataddr((a.realname, a.address))
self.envelope.add('From', fromstring)
else:
cmpl = AccountCompleter()
diff --git a/alot/commands/thread.py b/alot/commands/thread.py
index 79fb8415..59adc3e5 100644
--- a/alot/commands/thread.py
+++ b/alot/commands/thread.py
@@ -10,7 +10,7 @@ import os
import re
import subprocess
import tempfile
-from email.utils import getaddresses, parseaddr
+from email.utils import getaddresses, parseaddr, formataddr
from email.message import Message
from twisted.internet.defer import inlineCallbacks
@@ -102,7 +102,7 @@ def determine_sender(mail, action='reply'):
logging.debug('using realname: "%s"', realname)
logging.debug('using address: %s', address)
- from_value = address if realname == '' else '%s <%s>' % (realname, address)
+ from_value = formataddr((realname, address))
return from_value, account
@@ -291,10 +291,7 @@ class ReplyCommand(Command):
new_value = []
for name, address in getaddresses(value):
if address not in my_addresses:
- if name != '':
- new_value.append('"%s" <%s>' % (name, address))
- else:
- new_value.append(address)
+ new_value.append(formataddr((name, address)))
return new_value
@staticmethod
@@ -306,9 +303,7 @@ class ReplyCommand(Command):
res = dict()
for name, address in getaddresses(recipients):
res[address] = name
- urecipients = ['"{}" <{}>'.format(n, a) if n != ''
- else a
- for a, n in res.iteritems()]
+ urecipients = [formataddr((n, a)) for a, n in res.iteritems()]
return sorted(urecipients)