gnodet opened a new pull request, #31170: URL: https://github.com/apache/camel/pull/31170
## Summary Fixes two independent bugs in `camel-mail`: 1. **Idempotent key leak** (`MailConsumer`): when a mail passes the idempotent repository check but `createExchange()` returns `null` (e.g. the mail was flagged DELETED between the search and its retrieval, or an attachment failed to load with `skipFailedMessage=true`), the key added to the repository was never removed. The mail was therefore permanently blacklisted and silently skipped by every subsequent poll. 2. **To default depends on option parse order** (`MailConfiguration`): `setUsername()` applied the default `To` address (`username@host`) only when `recipients.size() == 0`. When CC or BCC was configured first via URI option parsing, `recipients` was non-empty even though no `To` had been explicitly set, so the default was silently dropped. ## Root Cause **Bug 1:** `retrieveMessages()` sets `addedKey` before calling `createExchange()`, but only called `removeIdempotentKey()` in exception and SEEN-after-search branches — the `exchange == null` path had no cleanup. **Bug 2:** `setUsername()` guarded the default `To` with `recipients.size() == 0` instead of checking specifically for the presence of a `To` entry. Any other recipient (CC, BCC) in the map prevented the default from being applied. ## Fix - **`MailConsumer`**: add `removeIdempotentKey(addedKey)` in the `else` branch when `createExchange()` returns `null`. - **`MailConfiguration`**: replace `recipients.size() == 0` with `!recipients.containsKey(Message.RecipientType.TO)` so the default is applied whenever no explicit `To` is present, regardless of which other recipients were set first. ## Tests - `MailIdempotentRepositoryDeletedMessageTest`: verifies that the idempotent key is absent after a poll where `createExchange()` returns null, and that the mail is consumable on the next poll (not permanently blacklisted). - `MailConfigurationToDefaultTest`: 7 unit tests covering all order variants — username-only, explicit-to-after-username, explicit-to-before-username (must not be overridden), CC-before-username (default must still apply), BCC-before-username (default must still apply), no-username (no default). Fixes https://issues.apache.org/jira/browse/CAMEL-27895 --- _Hermes Agent (Claude Sonnet 4.6) on behalf of Guillaume Nodet_ -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
