From ad443013ea7d442e79abd8beb6d3363446bd7e6d Mon Sep 17 00:00:00 2001 From: Corentin Forler <10946971+cogk@users.noreply.github.com> Date: Mon, 29 Dec 2025 11:48:13 +0100 Subject: [PATCH] fix: Remove newlines from filename in email attachment (#35151) --- frappe/email/email_body.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/frappe/email/email_body.py b/frappe/email/email_body.py index e02ae105b0..707d301546 100755 --- a/frappe/email/email_body.py +++ b/frappe/email/email_body.py @@ -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}>")