Skip to content

Commit

Permalink
Improve parsing of MIME parameter part
Browse files Browse the repository at this point in the history
Fix problem where single encoded + unencoded MIME parameter
of same name get concatenated.
  • Loading branch information
stefanw committed Sep 12, 2017
1 parent 7a20d19 commit c38b320
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions flanker/mime/message/headers/parametrized.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ def concatenate(parts):
if is_old_style(part):
# old-style parameters do not support any continuations
return encodedword.mime_to_unicode(get_value(part))
elif is_single_part(part):
return decode_new_style(part)
else:
return u"".join(
decode_new_style(p) for p in partition(parts))
Expand Down Expand Up @@ -225,6 +227,10 @@ def is_encoded(part):
return part[1][2] == '*'


def is_single_part(part):
return part[1][1] is None


def get_key(parameter):
if is_old_style(parameter):
return parameter[1].lower()
Expand Down
7 changes: 6 additions & 1 deletion tests/mime/message/headers/parametrized_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,10 @@ def content_types_test():
eq_(('multipart/mixed', {'boundary': 'Alternative_Boundary_8dJn:mu0M2Yt5KaFZ8AdJn:mu0M2=Yt1KaFdA'}), parametrized.decode(''' multipart/mixed; \n\tboundary="Alternative_Boundary_8dJn:mu0M2Yt5KaFZ8AdJn:mu0M2=Yt1KaFdA"'''))
eq_(('multipart/mixed', {'boundary': '16819560-2078917053-688350843:#11603'}), parametrized.decode('''MULTIPART/MIXED;BOUNDARY="16819560-2078917053-688350843:#11603"'''))


def content_type_param_with_spaces_test():
eq_(('multipart/alternative',{'boundary':'nextPart'}), parametrized.decode("multipart/alternative; boundary = nextPart"))
eq_(('multipart/alternative', {'boundary': 'nextPart'}), parametrized.decode("multipart/alternative; boundary = nextPart"))


def content_type_same_param_name_encoded_unencoded_test():
eq_(('application/pdf', {'name': '30676_2015.pdf'}), parametrized.decode("application/pdf; name=30676_2015.pdf;name*=iso-8859-1''%33%30%36%37%36%5F%32%30%31%35%2E%70%64%66"))

0 comments on commit c38b320

Please sign in to comment.