allthingssecurity opened a new pull request, #28200:
URL: https://github.com/apache/camel/pull/28200

   # Description
   
   [CAMEL-25808](https://issues.apache.org/jira/browse/CAMEL-25808)
   
   When the IMAP connection of the folder dropped while a mail of a poll was 
routed (a server idle timeout during a long exchange, a network failure), 
`MailConsumer.processCommit` opened the folder again and set SEEN or DELETED 
(and did the copy / move) on the mail object of the poll. An angus-mail 
`IMAPMessage` looks its message number up in the message cache of the current 
open of its folder, and the new open builds that cache from the mailbox as it 
is then. When mails were expunged between the two opens (another mail client, a 
second consumer on the same mailbox, a server that expunges deleted mails at 
once), the number designated another mail: that mail was marked instead. With 
`unseen=true` (the default) a mail marked SEEN before it was routed is never 
polled again; with `delete=true` or `moveTo` it is deleted or moved without 
being routed. The routed mail stayed unread and was routed again. Nothing was 
logged.
   
   Changes (`MailConsumer` only):
   - The UIDs of the mails of a poll are fetched when the mails are retrieved 
(one FETCH for the batch).
   - The consumer counts the opens of the folder. When the folder was opened 
again after the mails of the batch were retrieved, the mail to mark is looked 
up by its UID (same UIDVALIDITY). When it is no longer in the folder, nothing 
is marked and a WARN says so.
   - Once the folder was opened again, the rest of the batch is not routed: 
those mail objects are stale too. Their mails are given back as for a batch cut 
short by a stop (CAMEL-25710) and consumed by the next poll.
   - POP3 is unchanged: `processCommit` already finds a POP3 mail again by its 
key.
   
   What users can notice: after a dropped folder connection in the middle of a 
poll, the remaining mails of that poll are consumed by the next poll. No option 
changed, so no upgrade guide entry.
   
   Tests:
   - New `MailConsumerFolderReopenedTest`. It uses GreenMail and the real 
angus-mail client, as the other tests of the module, with a small TCP proxy 
that drops the consumer's connections. Three mails, `maxMessagesPerPoll=2`. 
While the second mail is routed, another client removes the first one and the 
proxy drops the connections. Without the change the third mail is marked SEEN 
by the commit of the second one: `Message with body Message 2 was expected but 
not found in [Message 1]` (2 runs, 2 failures). With the change all three mails 
are routed once.
   - With the change the camel-mail unit tests pass: 246 run, 0 failures, 0 
errors, 4 skipped.
   
   How it was found: deterministic simulation testing (the camel-test-dst 
harness of CAMEL-25738). The world runs the real consumer against a fake IMAP 
server and client with seeded connection drops, a second consumer, other 
clients that expunge, and a server that expunges at once. 384 of 5000 seeds 
marked a mail before its exchange completed on main, and 0 of 5000 with this 
change. The JUnit test above reproduces it with the real client.
   
   What was not run: a real IMAP server other than GreenMail; the full root 
build.
   
   # 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-25808](https://issues.apache.org/jira/browse/CAMEL-25808).
   
   # 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 and tested camel-mail, including the formatter and import-sort 
plugins. No option and no component page changed. 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]

Reply via email to