Issue 1218081: email.Utils.py: "'" in RFC2231 header (original) (raw)

A header like this one can cause ValueError in attempting to decode the RFC2231 format:

Content-Disposition: inline; filename0="Today's Headlines- C.I.A. Is Reviewing Its Security Policy for R"; filename1="ecruiting Translators.jpg"

Note that there is a ' in the filename. MUA should have escaped the ' by %27 but Python email library should be robust for such a violation.

Here is the traceback:

print p[4]['content-disposition'] inline; filename0="Today's Headlines- C.I.A. Is Reviewing Its Security Policy for R"; filename1="ecruiting Translators.jpg" p[4].get_filename() Traceback (most recent call last): File "", line 1, in ? File "/usr/local/lib/python2.4/email/Message.py", line 707, in get_filename filename = self.get_param('filename', missing, 'content-disposition') File "/usr/local/lib/python2.4/email/Message.py", line 590, in get_param for k, v in self._get_params_preserve(failobj, header): File "/usr/local/lib/python2.4/email/Message.py", line 537, in _get_params_pre serve params = Utils.decode_params(params) File "/usr/local/lib/python2.4/email/Utils.py", line 275, in decode_params charset, language, value = decode_rfc2231(EMPTYSTRING.join(value)) File "/usr/local/lib/python2.4/email/Utils.py", line 222, in decode_rfc2231 charset, language, s = parts ValueError: need more than 2 values to unpack