Make sure the attachment filename is text type.

If attachment filename is bytes type and contains non-ascii coded bytes,
then the following ASCII encoding process will trigger
UnicodeDecodeError exception.

Fix issue #2933.
This commit is contained in:
garenchan 2018-10-04 20:42:24 +08:00 committed by David Lord
parent 232e5c81bc
commit 40118e785f
No known key found for this signature in database
GPG key ID: 7A1C87E3F5BC42A8
3 changed files with 10 additions and 1 deletions

View file

@ -567,6 +567,9 @@ def send_file(filename_or_fp, mimetype=None, as_attachment=False,
raise TypeError('filename unavailable, required for '
'sending as attachment')
if not isinstance(attachment_filename, text_type):
attachment_filename = attachment_filename.decode('utf-8')
try:
attachment_filename = attachment_filename.encode('ascii')
except UnicodeEncodeError: