fix: Remove newlines from filename in email attachment (#35151)
This commit is contained in:
parent
1bec823bb1
commit
ad443013ea
1 changed files with 4 additions and 2 deletions
|
|
@ -241,7 +241,8 @@ class EMail:
|
|||
part = MIMEText(message, _subtype=subtype, policy=policy.SMTP)
|
||||
|
||||
if as_attachment:
|
||||
part.add_header("Content-Disposition", "attachment", filename=filename)
|
||||
clean_filename = re.sub("[\r\n]", "", str(filename))
|
||||
part.add_header("Content-Disposition", "attachment", filename=clean_filename)
|
||||
|
||||
self.msg_root.attach(part)
|
||||
|
||||
|
|
@ -476,7 +477,8 @@ def add_attachment(fname, fcontent, content_type=None, parent=None, content_id=N
|
|||
# Set the filename parameter
|
||||
if fname:
|
||||
attachment_type = "inline" if inline else "attachment"
|
||||
part.add_header("Content-Disposition", attachment_type, filename=str(fname))
|
||||
clean_filename = re.sub("[\r\n]", "", str(fname))
|
||||
part.add_header("Content-Disposition", attachment_type, filename=clean_filename)
|
||||
if content_id:
|
||||
part.add_header("Content-ID", f"<{content_id}>")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue