diff options
author | Patrick Totzke <patricktotzke@gmail.com> | 2011-10-20 10:57:17 +0100 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2011-10-20 10:57:17 +0100 |
commit | 456d06796b9e3d2bec9fdc2e151ff3962cdc42a5 (patch) | |
tree | 48183312a378952ce35d546e39b88152a2e48e2a /alot | |
parent | adbfd60ac05662f7a3cc62e3ed08701aa4938c1b (diff) |
fix separately handle name and address fields
this prevents strange stuff from hapening if name contans uft8 chars:
then the whole header, including the address would be encoded,
making the msg unreadable for the MTA
Diffstat (limited to 'alot')
-rw-r--r-- | alot/message.py | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/alot/message.py b/alot/message.py index e00d62df..71760ad5 100644 --- a/alot/message.py +++ b/alot/message.py @@ -260,18 +260,16 @@ def encode_header(key, value): rawentries = value.split(',') encodedentries = [] for entry in rawentries: - m = re.search('\s*(.*)\s+<(.*\@.*\.\w*)>$', entry) + m = re.search('\s*(.*)\s+<(.*\@.*\.\w*)>\s*$', entry) if m: # If a realname part is contained name, address = m.groups() # try to encode as ascii, if that fails, revert to utf-8 # name must be a unicode string here - header = Header(name) + namepart = Header(name) # append address part encoded as ascii - header.append('<%s>' % address, charset='ascii') - encodedentries.append(header.encode()) - else: # pure email address - encodedentries.append(entry) - value = Header(','.join(encodedentries)) + entry = '%s <%s>' % (namepart.encode(), address) + encodedentries.append(entry) + value = Header(', '.join(encodedentries)) else: value = Header(value) return value |