From 37ef3342edf2a3787ec1804ef8cb32fd0fd4eab3 Mon Sep 17 00:00:00 2001 From: Christine Spang Date: Mon, 11 May 2015 15:49:18 -0700 Subject: [PATCH] Handle non-ascii characters in parameter values. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When embedding inline emoji, Outlook Web App generates headers that look like this: Content-Type: image/png; name='OutlookEmoji-😊.png' It looks like handling parametrized headers containing non-ASCII characters was explicitly not supported previously. It's not clear to me why. The parameter-splitting code works just fine with values like these, though it would fail to correctly parse if e.g. the header name contained non-ascii characters. --- flanker/mime/message/headers/parsing.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/flanker/mime/message/headers/parsing.py b/flanker/mime/message/headers/parsing.py index ee517eb3..4a0290e7 100644 --- a/flanker/mime/message/headers/parsing.py +++ b/flanker/mime/message/headers/parsing.py @@ -32,20 +32,15 @@ def parse_header(header): def parse_header_value(name, val): - if not is_pure_ascii(val): - if parametrized.is_parametrized(name, val): - raise DecodingError("Unsupported value in content- header") - return to_unicode(val) - else: - if parametrized.is_parametrized(name, val): - val, params = parametrized.decode(val) - if name == 'Content-Type': - main, sub = parametrized.fix_content_type(val) - return ContentType(main, sub, params) - else: - return WithParams(val, params) + if parametrized.is_parametrized(name, val): + val, params = parametrized.decode(val) + if name == 'Content-Type': + main, sub = parametrized.fix_content_type(val) + return ContentType(main, sub, params) else: - return val + return WithParams(val, params) + else: + return val if is_pure_ascii(val) else to_unicode(val) def is_empty(line):