POP3 RETR drops the message body (returns empty message) #1

Closed
opened 2026-06-17 17:12:00 +01:00 by lyrathorpe · 0 comments
Owner

IMAPBackend.fetch_message (proxy_server.py:119) filters the imaplib FETCH response to top-level bytes only:

parts = [chunk for chunk in data if isinstance(chunk, bytes)]

Real imaplib returns the RFC822 literal inside a tuple, e.g.

[(b"1 (UID 1 RFC822 {N}", b"<raw message bytes>"), b")"]

The tuple is not bytes, so the body in tuple[1] is discarded and the client receives only the trailing b")". RETR is therefore broken against any real IMAP server.

The existing unit test passes only because DummyIMAP returns a flat list of bytes, which imaplib never produces.

Fix:

  • Extract the body from the tuple element (tuple[1]) of the FETCH response.
  • Update the test fixture to return the realistic tuple shape so the bug cannot regress.

Acceptance:

  • RETR returns the full message body against a tuple-shaped FETCH response.
  • Test fixture reflects real imaplib output.
IMAPBackend.fetch_message (proxy_server.py:119) filters the imaplib FETCH response to top-level bytes only: parts = [chunk for chunk in data if isinstance(chunk, bytes)] Real imaplib returns the RFC822 literal inside a tuple, e.g. [(b"1 (UID 1 RFC822 {N}", b"<raw message bytes>"), b")"] The tuple is not `bytes`, so the body in tuple[1] is discarded and the client receives only the trailing b")". RETR is therefore broken against any real IMAP server. The existing unit test passes only because DummyIMAP returns a flat list of bytes, which imaplib never produces. Fix: - Extract the body from the tuple element (tuple[1]) of the FETCH response. - Update the test fixture to return the realistic tuple shape so the bug cannot regress. Acceptance: - RETR returns the full message body against a tuple-shaped FETCH response. - Test fixture reflects real imaplib output.
lyrathorpe added the bug label 2026-06-17 17:12:00 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: lyrathorpe/legacy-email-proxy#1