diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2018-08-03 10:21:11 -0700 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2018-08-04 16:21:31 +0100 |
commit | 1240eba9cd31e81ea364cdab038685fabb7eab2e (patch) | |
tree | 1fdef1fb9de1f8d30e9530506a8cf5df1cd112a7 /alot/db | |
parent | 273f4143626020321b6cf15f94ff0a5ec71d642d (diff) |
db/utils: Replace encode_header with Message.add_header
Which appears to be capable of doing all the same things, but is in the
stdlib instead of something we hand rolled.
Diffstat (limited to 'alot/db')
-rw-r--r-- | alot/db/envelope.py | 3 | ||||
-rw-r--r-- | alot/db/utils.py | 26 |
2 files changed, 1 insertions, 28 deletions
diff --git a/alot/db/envelope.py b/alot/db/envelope.py index 4c2e5cd9..44da6f71 100644 --- a/alot/db/envelope.py +++ b/alot/db/envelope.py @@ -15,7 +15,6 @@ import email.charset as charset import gpg from .attachment import Attachment -from .utils import encode_header from .. import __version__ from .. import helper from .. import crypto @@ -282,7 +281,7 @@ class Envelope(object): # copy headers from envelope to mail for k, vlist in headers.items(): for v in vlist: - outer_msg[k] = encode_header(k, v) + outer_msg.add_header(k, v) return outer_msg diff --git a/alot/db/utils.py b/alot/db/utils.py index 33330f72..399b7df1 100644 --- a/alot/db/utils.py +++ b/alot/db/utils.py @@ -508,32 +508,6 @@ def decode_header(header, normalize=False): return value -def encode_header(key, value): - """ - encodes a unicode string as a valid header value - - :param key: the header field this value will be stored in - :type key: str - :param value: the value to be encoded - :type value: unicode - """ - # handle list of "realname <email>" entries separately - if key.lower() in ['from', 'to', 'cc', 'bcc']: - rawentries = email.utils.getaddresses([value]) - encodedentries = [] - for name, address in rawentries: - # try to encode as ascii, if that fails, revert to utf-8 - # name must be a unicode string here - namepart = Header(name) - # append address part encoded as ascii - entry = email.utils.formataddr((namepart.encode(), address)) - encodedentries.append(entry) - value = Header(', '.join(encodedentries)) - else: - value = Header(value) - return value.encode() - - def is_subdir_of(subpath, superpath): # make both absolute superpath = os.path.realpath(superpath) |