Mirror messages whose FETCH response will not parse, and bump to 0.2.1 #33

Merged
svc-agent-writer merged 1 commit from fix/unparseable-fetch into main 2026-10-31 05:06:23 +00:00

Closes #32. Also bumps the version to 0.2.1 and pins the base at v0.2.1, so the release can be tagged from the merge commit.

The bug

An unescaped " inside an ENVELOPE or BODYSTRUCTURE string makes imapclient refuse the whole FETCH response, at response_lexer.py:104. The blade maps the error to server_error, not retryable. _backfill let that error end the mailbox's pass, and the next pass restarted at the same batch. On the affected instance, Inbox stopped after about 5,100 messages and Sent after about 800.

The fix (ingest.py)

  • _fetch_batch: on a failed batch, it first refetches the same UIDs with FLAGS only.
    • If the probe fails, the server is at fault and the error stands. A transient refusal therefore never skips mail.
    • If the probe parses, the batch is halved until each bad message is alone. A batch of 100 with one bad message costs about 14 extra fetches, once.
  • _raw_record: each bad message is mirrored from its raw bytes, which arrive as a literal and need no quoted-string parsing. The whole message is used when it fits store.max_text_bytes, otherwise only the header. It gets headers, addresses, threading ids, date, flags, body text and the attachment list, so it stays searchable.
  • Skipping: a message the fallback cannot read either is skipped, and the mailbox carries on.
  • Logs: they carry the fallback count and the skipped count only.
  • Blob upload: factored into _upload_blob, so both paths share it.

Parse-error text from imapclient can include message content. With this change it no longer reaches the stored sync error from the backfill path.

Tests

  • tests/test_unparseable.py:
    • The synthetic bad line goes through the blade's real AccountSession.fetch and yields the exact stored error string.
    • _fetch_batch isolates the bad UID after a FLAGS probe.
    • A mailbox with two bad messages mirrors all 10 in one pass, and the fallback records are searchable.
    • A server that refuses FLAGS too keeps the error and skips nothing.
    • A message the fallback cannot read is skipped.
  • make check: 84 unit tests pass. make test-integration: 7 pass against GreenMail.

🤖 Generated with Claude Code

Closes #32. Also bumps the version to 0.2.1 and pins the base at `v0.2.1`, so the release can be tagged from the merge commit. ## The bug An unescaped `"` inside an ENVELOPE or BODYSTRUCTURE string makes imapclient refuse the whole FETCH response, at `response_lexer.py:104`. The blade maps the error to `server_error`, not retryable. `_backfill` let that error end the mailbox's pass, and the next pass restarted at the same batch. On the affected instance, Inbox stopped after about 5,100 messages and Sent after about 800. ## The fix (`ingest.py`) - **`_fetch_batch`:** on a failed batch, it first refetches the same UIDs with FLAGS only. - If the probe fails, the server is at fault and the error stands. A transient refusal therefore never skips mail. - If the probe parses, the batch is halved until each bad message is alone. A batch of 100 with one bad message costs about 14 extra fetches, once. - **`_raw_record`:** each bad message is mirrored from its raw bytes, which arrive as a literal and need no quoted-string parsing. The whole message is used when it fits `store.max_text_bytes`, otherwise only the header. It gets headers, addresses, threading ids, date, flags, body text and the attachment list, so it stays searchable. - **Skipping:** a message the fallback cannot read either is skipped, and the mailbox carries on. - **Logs:** they carry the fallback count and the skipped count only. - **Blob upload:** factored into `_upload_blob`, so both paths share it. Parse-error text from imapclient can include message content. With this change it no longer reaches the stored sync error from the backfill path. ## Tests - `tests/test_unparseable.py`: - The synthetic bad line goes through the blade's real `AccountSession.fetch` and yields the exact stored error string. - `_fetch_batch` isolates the bad UID after a FLAGS probe. - A mailbox with two bad messages mirrors all 10 in one pass, and the fallback records are searchable. - A server that refuses FLAGS too keeps the error and skips nothing. - A message the fallback cannot read is skipped. - `make check`: 84 unit tests pass. `make test-integration`: 7 pass against GreenMail. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
An unescaped quote inside an iCloud ENVELOPE or BODYSTRUCTURE string
makes imapclient refuse the whole batch. The backfill restarted at
that batch on every pass, so the mailbox never moved past it.

- A failed batch is probed with FLAGS only. If that fails too, the
  error stands and nothing is skipped.
- Otherwise the batch is halved until each bad message is alone, and
  that message is mirrored from its raw bytes (the whole message up to
  store.max_text_bytes, else its header).
- A message the fallback cannot read either is skipped; logs carry
  counts only.

Closes #32

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign in to join this conversation.
No description provided.