allthingssecurity opened a new pull request, #27990: URL: https://github.com/apache/camel/pull/27990
# Description [CAMEL-25710](https://issues.apache.org/jira/browse/CAMEL-25710) With an `idempotentRepository` (documented as the way to let several consumers share one mailbox), `MailConsumer.retrieveMessages` adds the key of every mail of a poll to the repository before any of them is routed; the key is removed or confirmed when the exchange of the mail completes. Mails that the poll did not route kept their key, so every later poll, also on other consumers sharing the repository, skipped them as duplicates. They stayed unread on the server and were never routed, without a log line: - the rest of the batch when the consumer stops in the middle of it (graceful route or CamelContext stop, default `ShutdownRunningTask.CompleteCurrentTaskOnly`); those exchanges were not released either; - the mails retrieved before a mail whose exchange cannot be created (for example its attachments cannot be read), which fails the poll, and that mail itself: after the bad mail is removed, the others are still skipped. Changes (`MailConsumer` only): - `processBatch` gives back the exchanges it did not route: removes their key from the idempotent repository and releases them. The aws2-s3 consumer does the same with its in-progress keys since CAMEL-25521. - `retrieveMessages` does the same for the exchanges created so far, and removes the key of the failing mail, when creating an exchange throws; the exception is rethrown as before. What users can notice (upgrade guide note added, 4.24 guide, `camel-mail` section): with an `idempotentRepository` and the defaults `skipFailedMessage=false` / `handleFailedMessage=false`, a mail whose exchange cannot be created now fails every poll until it is removed, as it already does without an `idempotentRepository` and as the documentation of these options describes. Before, it failed only the first poll and was then skipped, together with the mails retrieved before it. `skipFailedMessage` or `handleFailedMessage` skip such a mail. Tests: - New `MailIdempotentRepositoryNotRoutedTest` (2 tests, GreenMail IMAP, `MemoryIdempotentRepository`): (1) 5 mails, the route is stopped while it routes the first one, then started again: all 5 must be routed; (2) 3 mails and a multipart mail without its boundary: the poll fails, the bad mail is deleted, the route is started again: the 3 mails must be routed. Bounded waits only, no sleeps. - Without the change both tests fail: `The keys of the mails that were not routed must be removed ==> expected: <0> but was: <4>`. - With the change: the camel-mail tests pass: 217 run, 0 failures, 0 errors, 3 skipped. What is not changed: - A mail skipped by `skipFailedMessage` / `handleFailedMessage`, or flagged DELETED, keeps its key, as before. - No option or default changes. What was not run: a persistent or shared idempotent repository, POP3 (the tests use IMAP). # Target - [x] I checked that the commit is targeting the correct branch (Camel 4 uses the `main` branch) # Tracking - [x] If this is a large change, bug fix, or code improvement, I checked there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it): [CAMEL-25710](https://issues.apache.org/jira/browse/CAMEL-25710). # Apache Camel coding standards and style - [x] I checked that each commit in the pull request has a meaningful subject line and body. - [ ] I have run `mvn clean install -DskipTests` locally from root folder and I have committed all auto-generated changes. (I built camel-mail and the modules it depends on, including the formatter and import-sort plugins, and ran the camel-mail tests. I did not run the full root build.) # AI-assisted contributions - [x] If this PR includes AI-generated code, commits have proper co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR description identifies the AI tool used. This PR was prepared with Claude Code (Claude Opus 5.5). The commit carries a `Co-Authored-By` trailer. _Claude Code on behalf of allthingssecurity_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- 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]
