Repository navigation
[FIX] Fix RFC compliance issues and race conditions across SMTP and JMAP RFC-8621 - #3236
Draft
prosgarz35 wants to merge 1 commit into
Draft
prosgarz35 wants to merge 1 commit into
prosgarz35 wants to merge 1 commit into
Conversation
prosgarz35
marked this pull request as ready for review
October 6, 2026 04:42
chibenwa
reviewed
Oct 6, 2026
| SMTPResponse resp = new SMTPResponse(SMTPRetCode.MAIL_OK, new StringBuilder(session.getConfiguration().getHelloName()).append(" Hello ").append(argument) | ||
| .append(" [") | ||
| .append(session.getRemoteAddress().getAddress().getHostAddress()).append("])")); | ||
| .append(session.getRemoteAddress().getAddress().getHostAddress()).append("]")); |
Contributor
There was a problem hiding this comment.
his isn't an RFC 5321 compliance issue: the text after the domain in an EHLO reply is free-form. It's a cosmetic fix, and still worth doing.
HeloCmdHandler has the same "])" at protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/HeloCmdHandler.java:85. Please fix it too.
| .map(list => list.reduce(_ ++ _)) | ||
| } | ||
|
|
||
| // RFC 8621 sec.4.1: Deterministically pick representative message copy across multiple mailboxes |
Contributor
There was a problem hiding this comment.
We aggregate flag and the rest of the message is immutable. Please drop this unneeded commit.
| textBody match { | ||
| case None => SMono.empty | ||
| case Some(text :: Nil) if !text.`type`.value.equals("text/plain") => SMono.error(new IllegalArgumentException("Expecting htmlBody type to be text/html")) | ||
| case Some(text :: Nil) if !text.`type`.value.equals("text/plain") => SMono.error(new IllegalArgumentException("Expecting textBody type to be text/plain")) |
| .doOnSuccess(_ => auditMove(Seq(messageId), mailboxIds.value, targetIds.value, session)) | ||
| .onErrorResume(e => SMono.just[EmailUpdateResult](EmailUpdateFailure(EmailSet.asUnparsed(messageId), e))) | ||
| .switchIfEmpty(SMono.just[EmailUpdateResult](EmailUpdateSuccess(messageId))) | ||
| } else { |
Contributor
There was a problem hiding this comment.
the race described doesn't exist
- The combined case is already handled. When both mailboxes and flags change, the code already calls the atomic updateEmail (JAMES-3728).
- The else branch only ever does one real operation. It's reached only when at most one of the two changes. One of updateFlags/updateMailboxIds then returns EmailUpdateSuccess
without touching the store. There was never a "partial update window" between two writes. - The refactor is equivalent but brings no benefit. It is a bit more explicit, at the cost of copy-pasting the flag computation (the fold over originalFlags), which now appears
twice. - Verdict: a cosmetic refactor sold as a race-condition fix. Drop it.
Contributor
|
Have tests for your changes please. |
chibenwa
marked this pull request as draft
October 6, 2026 19:53
Contributor
|
Hello @prosgarz35 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This pull request addresses several RFC compliance issues, race conditions, and determinism inconsistencies found during protocol verification of SMTP and JMAP RFC-8621 implementations.
Changes
1. SMTP: Remove extraneous trailing parenthesis in EHLO greeting (RFC 5321 §4.1.1.1)
protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/EhloCmdHandler.java])instead of]:.append("])")to.append("]"), conforming strictly to RFC 5321 §4.1.1.1 syntax.2. JMAP RFC-8621: Ensure atomicity in
Email/set updateand eliminate race window (RFC 8621 §3)server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailSetUpdatePerformer.scalaupdateSingleMessageonly used atomic execution when both mailbox IDs and flags were updated simultaneously (isMailboxUpdate && isFlagUpdate). In theelsebranch, flag updates and mailbox ID updates were executed in a chained non-atomic fashion (updateFlags(...).flatMap(... => updateMailboxIds(...))), introducing a partial-update failure window and potential data race between concurrent updates.messageIdManager.updateEmail(...)(single atomic operation).messageIdManager.setFlagsReactive(...)directly.messageIdManager.setInMailboxesReactive(...)directly.updateFlagsandupdateMailboxIds.3. JMAP RFC-8621: Deterministic message copy selection for multi-mailbox emails (RFC 8621 §4.1)
server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Email.scalamessage._2contains aSeq[MessageResult]whose order depends on the backend store driver and is not guaranteed. View factories (EmailMetadataViewFactory,EmailHeaderViewFactory,EmailFullViewFactory,EmailFastViewReader, andEmailFastViewWithAttachmentsMetadataReader) previously called.headOption, which could lead to non-deterministic selection of the representative message metadata (such assizeandreceivedAt).Email.pickFirstMessage(messages: Seq[MessageResult])which deterministically sorts the message results by internal date timestamp and mailbox ID (messages.sortBy(m => (m.getInternalDate.getTime, m.getMailboxId.serialize())).headOption). All view factories now use this deterministic selection helper.4. JMAP RFC-8621: Fix typo in
validateTextBodyerror messageserver/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/EmailSet.scalavalidateTextBodyraised anIllegalArgumentExceptionstating"Expecting htmlBody type to be text/html"when validating a non-text/plainpart due to copy-paste fromvalidateHtmlBody."Expecting textBody type to be text/plain".