Skip to content

Commit 4f2fb53

Browse files
committed
fix: set max raw-message size to 25MB
1 parent 894cdb5 commit 4f2fb53

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

mail/api/outbound.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
from mail.utils.rate_limiter import dynamic_rate_limit
1414
from mail.utils.user import has_role
1515

16+
MAX_MESSAGE_SIZE = 25 * 1024 * 1024 # 25 MB
17+
1618

1719
@frappe.whitelist(methods=["POST"])
1820
@dynamic_rate_limit()
@@ -116,6 +118,9 @@ def send_raw(
116118
if not raw_message:
117119
frappe.throw(_("The raw message is required."), frappe.MandatoryError)
118120

121+
if len(raw_message.encode("utf-8")) > MAX_MESSAGE_SIZE:
122+
frappe.throw(_("The raw message exceeds the maximum allowed size of 25 MB."))
123+
119124
return _enqueue_mail(from_, to, raw_message, is_newsletter)
120125

121126

@@ -182,6 +187,11 @@ def _handle_chunked_upload(
182187
f.seek(offset)
183188
f.write(file.stream.read())
184189

190+
current_size = os.path.getsize(temp_path)
191+
if current_size > MAX_MESSAGE_SIZE:
192+
os.remove(temp_path)
193+
frappe.throw(_("The raw message exceeds the maximum allowed size of 25 MB."))
194+
185195
if chunk_index < total_chunks - 1:
186196
return f"Chunk {chunk_index + 1} of {total_chunks} received."
187197

mail/install.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def add_rate_limits() -> None:
4343
# mail.api.outbound
4444
{"method_path": "mail.api.outbound.upload_attachment", "limit": 60, "seconds": 60},
4545
{"method_path": "mail.api.outbound.send", "limit": 300, "seconds": 60},
46-
{"method_path": "mail.api.outbound.send_raw", "limit": 300, "seconds": 60},
46+
{"method_path": "mail.api.outbound.send_raw", "limit": 300, "seconds": 120},
4747
# mail.api.spamd
4848
{"method_path": "mail.api.spamd.scan", "limit": 60, "seconds": 60},
4949
{"method_path": "mail.api.spamd.get_spam_score", "limit": 60, "seconds": 60},

0 commit comments

Comments
 (0)