Export: match a message the target holds under its own key #87

Merged
jcoffey-dev merged 2 commits from fix/export-parse-rematch into main 2026-11-17 15:50:32 +00:00
Owner

Refs #86.

The bug. A message with two Message-ID headers is keyed by both in the archive, while a JMAP server's messageId reflects one. Export never paired the two, so every rerun imported the message again. Shown live on inbuxa 27.1-rc.4: on main, the second export reports Email: created=1.

The fix. It's in src/sync/export/email.rs. While some target emails are still unpaired, each batch about to be imported is first parsed by the target (Email/parse, on blobs that were being uploaded anyway). A message the target already holds under the key it computes is then matched to that email, preferring an equal size. It gets the usual keyword and folder patch, so it stays in sync on later runs too.

  • When every target email is already paired (e.g. a first export into an empty account), no Email/parse call is made.
  • If the target refuses Email/parse, it isn't asked again that run; any other failure leaves only that batch unchecked. Either way the messages are imported as before.
  • The parsed key also settles a batch whose import ended without a clear answer, so a message that did arrive isn't sent twice.

Upstream fixed the same case in v1.0.17. This PR is written on our own code and tests, not ported from upstream.

Tests

  • tests/mock_sync.rs, 4 new tests (all failed on main): matched and not imported, matched and keywords synced, target can't parse so imported, parsed as a different message so imported.
  • tests/integration_inbuxa.rs: a_message_with_two_message_ids_is_not_exported_twice. It fails on main and passes here; all 5 live inbuxa tests pass.
  • cargo test --locked: 1731 passed, 0 failed, 71 ignored. cargo fmt --check and cargo clippy --all-targets are clean.
Refs #86. **The bug.** A message with two `Message-ID` headers is keyed by both in the archive, while a JMAP server's `messageId` reflects one. Export never paired the two, so every rerun imported the message again. Shown live on inbuxa 27.1-rc.4: on main, the second export reports `Email: created=1`. **The fix.** It's in `src/sync/export/email.rs`. While some target emails are still unpaired, each batch about to be imported is first parsed by the target (`Email/parse`, on blobs that were being uploaded anyway). A message the target already holds under the key it computes is then matched to that email, preferring an equal size. It gets the usual keyword and folder patch, so it stays in sync on later runs too. - When every target email is already paired (e.g. a first export into an empty account), no `Email/parse` call is made. - If the target refuses `Email/parse`, it isn't asked again that run; any other failure leaves only that batch unchecked. Either way the messages are imported as before. - The parsed key also settles a batch whose import ended without a clear answer, so a message that did arrive isn't sent twice. Upstream fixed the same case in v1.0.17. This PR is written on our own code and tests, not ported from upstream. **Tests** - `tests/mock_sync.rs`, 4 new tests (all failed on main): matched and not imported, matched and keywords synced, target can't parse so imported, parsed as a different message so imported. - `tests/integration_inbuxa.rs`: `a_message_with_two_message_ids_is_not_exported_twice`. It fails on main and passes here; all 5 live inbuxa tests pass. - `cargo test --locked`: 1731 passed, 0 failed, 71 ignored. `cargo fmt --check` and `cargo clippy --all-targets` are clean.
jcoffey-dev added 1 commit 2026-11-17 06:52:34 +00:00
Export: match a message the target holds under its own key
ci / test (pull_request) Skipped
github/ci (branch) GitHub Actions
ci / github (pull_request) Successful in 3m37s
ci / announce (pull_request) Skipped
34981475f2
A message with two Message-ID headers is keyed by both in the archive,
while a JMAP server's messageId reflects one, so export never paired it
and imported it again on every run (shown live on inbuxa 27.1-rc.4).

While target emails are left unpaired, a batch about to be imported is
parsed by the target first (Email/parse) and each message it already
holds under that key is matched, with its keywords and folders synced
like any other match. A target that refuses Email/parse is not asked
again; any other failure leaves that batch unchecked, imported as before.
The parsed key also settles an import that ended without a clear answer.

Upstream fixed the same case in v1.0.17 (#86); written here on our own
code and tests.
jcoffey-dev referenced this issue from a commit 2026-11-17 15:22:50 +00:00
jcoffey-dev added 1 commit 2026-11-17 15:44:56 +00:00
Merge remote-tracking branch 'origin/main' into fix/export-parse-rematch
ci / test (pull_request) Skipped
github/ci (branch) GitHub Actions
ci / github (pull_request) Successful in 5m32s
ci / announce (pull_request) Skipped
28e9ae1d58
# Conflicts:
#	CHANGELOG.md
jcoffey-dev merged commit d29c0c772d into main 2026-11-17 15:50:32 +00:00
jcoffey-dev deleted branch fix/export-parse-rematch 2026-11-17 15:50:33 +00:00
Sign in to join this conversation.