New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
exception with Message.get_filename() #39414
Comments
The following scriptlet: import sys
import email
msg = email.message_from_file(sys.stdin)
for part in msg.walk():
print part.get_params()
print part.get_filename() gets an exception when fed the attached email $ python2 t.py <test1
[('multipart/mixed', ''), ('boundary',
'=-mkF0Ur/S0HaYfa60OEsM')]
None
[('multipart/alternative', ''), ('boundary',
'=-VowfKaQaEHb81enMCUlR')]
None
[('text/plain', '')]
None
[('text/html', ''), ('charset', 'utf-8')]
None
[('application/rtf', ''), ('name', (None, None, '14676
World Transportation Systems OF, from arrival TIA
terminal to door and from Durres port to TIA.rtf'))]
Traceback (most recent call last):
File "t.py", line 7, in ?
print part.get_filename()
File "/usr/lib/python2.2/email/Message.py", line 711,
in get_filename
return unicode(newvalue[2], newvalue[0])
TypeError: unicode() argument 2 must be string, not None |
Logged In: YES The documentation for the get_param method suggests the param = msg.get_param('foo')
if isinstance(param, tuple):
param = unicode(param[2], param[0]) The get_filename method follows this advice, but it doesn't I fixed this by changing Message.get_filename to this: def get_filename(self, failobj=None):
"""Return the filename associated with the payload if
present.
The filename is extracted from the Content-Disposition
header's
`filename' parameter, and it is unquoted.
"""
missing = []
filename = self.get_param('filename', missing,
'content-disposition')
if filename is missing:
return failobj
if isinstance(filename, TupleType):
# It's an RFC 2231 encoded parameter
newvalue = _unquotevalue(filename)
if newvalue[0]:
return unicode(newvalue[2], newvalue[0])
return unicode(newvalue[2])
else:
newvalue = _unquotevalue(filename.strip())
return newvalue |
Logged In: YES This has been fixed in cvs for Python 2.2.4 if that ever |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: