diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2018-03-12 11:03:11 -0700 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2018-03-12 11:03:11 -0700 |
commit | 10b46df578f08f54f879d561ccc7d061569fa7b4 (patch) | |
tree | d4e70e730211828084822a20b07c097d12cadeb0 /alot | |
parent | 02279e2abf5a28a4f983a720d3a33ed94a4e117b (diff) |
db/utils: decoded_headers will be passed str not bytes
I had made the assumption early on that this would get bytes, but when I
added `assert isinstance(header, bytes)` alot would crash on startup,
changing `bytes` to `str` fixed that. I noticed this when trying to fix
the warning generated in the logging call.
Diffstat (limited to 'alot')
-rw-r--r-- | alot/db/utils.py | 20 |
1 files changed, 5 insertions, 15 deletions
diff --git a/alot/db/utils.py b/alot/db/utils.py index 4f533306..5303320c 100644 --- a/alot/db/utils.py +++ b/alot/db/utils.py @@ -421,30 +421,20 @@ def decode_header(header, normalize=False): This turns it into a single unicode string :param header: the header value - :type header: bytes + :type header: str :param normalize: replace trailing spaces after newlines :type normalize: bool :rtype: str """ - # FIXME: this is just hacked until it works, mostly - - # If the value isn't ascii as RFC2822 prescribes, - # we just return the unicode bytestring as is - value = string_decode(header) # convert to unicode - try: - value = value.encode('ascii') - except UnicodeEncodeError: - return value - # some mailers send out incorrectly escaped headers # and double quote the escaped realname part again. remove those # RFC: 2047 - regex = br'"(=\?.+?\?.+?\?[^ ?]+\?=)"' - value = re.sub(regex, br'\1', value) - logging.debug(b"unquoted header: |%s|", value) + regex = r'"(=\?.+?\?.+?\?[^ ?]+\?=)"' + value = re.sub(regex, r'\1', header) + logging.debug("unquoted header: |%s|", value) # otherwise we interpret RFC2822 encoding escape sequences - valuelist = email.header.decode_header(value.decode('ascii')) + valuelist = email.header.decode_header(value) decoded_list = [] for v, enc in valuelist: v = string_decode(v, enc) |