[PATCH v6 1/2] parsemail: Convert to a management command
Daniel Axtens
dja at axtens.net
Tue Sep 20 10:03:03 AEST 2016
>
> I don't have the offending patch on hand, but isn't the issue with the
> headers. If so, would something like the below do (I haven't tested
> it - there could be typos).
This is a bit more general - it deals with UTF-8 characters in the body
for Py3 as well, which is broken even with the other patch I sent.
I'll send some tests which will make it a bit clearer.
Regards,
Daniel
>
> I'll review this if not.
>
> Stephen
>
> diff --git a/patchwork/parser.py b/patchwork/parser.py
> index 1805df8..7917e97 100644
> --- a/patchwork/parser.py
> +++ b/patchwork/parser.py
> @@ -21,7 +21,8 @@
>
> import codecs
> import datetime
> -from email.header import Header, decode_header
> +from email.header import decode_header
> +from email.header import make_header
> from email.utils import parsedate_tz, mktime_tz
> from fnmatch import fnmatch
> from functools import reduce
> @@ -155,10 +156,10 @@ def find_date(mail):
>
>
> def find_headers(mail):
> - return reduce(operator.__concat__,
> - ['%s: %s\n' % (k, Header(v, header_name=k,
> - continuation_ws='\t').encode())
> - for (k, v) in list(mail.items())])
> + headers = {key: decode_header(value) for key, value in list(mail.items())}
> + return '\n'.join(['%s: %s' % (key, make_header(value[0], header_name=key,
> + continuation_wd='\t'))
> + for key, value in headers])
>
>
> def find_references(mail):
More information about the Patchwork
mailing list