From 53fd856ea8f9741ca6904fc2d1206fad9ea4df3e Mon Sep 17 00:00:00 2001 From: michaelxer <52305679+michaelxer@users.noreply.github.com> Date: Sat, 6 Jun 2026 03:59:35 +0700 Subject: [PATCH] fix: raise imaplib line limit for large mailboxes (#2895) Python's imaplib._MAXLINE defaults to 1 MB. Mailboxes with tens of thousands of messages exceed this on UID SEARCH ALL, crashing with 'got more than 1000000 bytes'. Set _MAXLINE to 50 MB after opening the connection so large mailboxes work without error. Fixes #2883 Co-authored-by: michaelxer --- routes/email_helpers.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/routes/email_helpers.py b/routes/email_helpers.py index fef29443d..43e73516f 100644 --- a/routes/email_helpers.py +++ b/routes/email_helpers.py @@ -714,6 +714,10 @@ def _open_imap_connection(host: str, port: int, *, starttls: bool, timeout: int conn.sock.settimeout(timeout) except Exception: pass + # Raise the IMAP line-length limit from the default 1 MB to 50 MB so that + # large mailboxes (tens of thousands of messages) don't crash with + # "got more than 1000000 bytes" on UID SEARCH ALL. (#2883) + imaplib._MAXLINE = 50_000_000 return conn def _imap_connect(account_id: str | None = None, owner: str = ""):