Skip to content

Commit

Permalink
Handle non-ascii characters in parameter values.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
spang committed Oct 6, 2017
1 parent 271a241 commit c20b48d
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions flanker/mime/message/headers/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,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):
Expand Down

0 comments on commit c20b48d

Please sign in to comment.