Improve attachment filename normalization (#14)
Use `os.path.basename` instead of `urllib.parse.quote_plus` to improve filename normalization.
This commit is contained in:
+2
-2
@@ -13,11 +13,11 @@
|
|||||||
# https://blogs.msdn.microsoft.com/openspecification/2009/11/06/msg-file-format-part-1/
|
# https://blogs.msdn.microsoft.com/openspecification/2009/11/06/msg-file-format-part-1/
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
|
|
||||||
import urllib.parse
|
|
||||||
import email.message, email.parser, email.policy
|
import email.message, email.parser, email.policy
|
||||||
from email.utils import parsedate_to_datetime, formatdate, formataddr
|
from email.utils import parsedate_to_datetime, formatdate, formataddr
|
||||||
|
|
||||||
@@ -154,7 +154,7 @@ def process_attachment(msg, entry, doc):
|
|||||||
mime_type = props.get('ATTACH_MIME_TAG', 'application/octet-stream')
|
mime_type = props.get('ATTACH_MIME_TAG', 'application/octet-stream')
|
||||||
if isinstance(mime_type, bytes): mime_type = mime_type.decode("utf8")
|
if isinstance(mime_type, bytes): mime_type = mime_type.decode("utf8")
|
||||||
|
|
||||||
filename = urllib.parse.quote_plus(filename)
|
filename = os.path.basename(filename)
|
||||||
|
|
||||||
# Python 3.6.
|
# Python 3.6.
|
||||||
if isinstance(blob, str):
|
if isinstance(blob, str):
|
||||||
|
|||||||
Reference in New Issue
Block a user