Sahana2524 opened a new pull request, #421:
URL: https://github.com/apache/commons-net/pull/421
`IMAP.getReply()` follows a `{n}` literal at the end of an untagged line,
but once that literal ends it never checks the rest of the line for another
one. When a FETCH returns more than one literal in the same response, the bytes
of the second literal are read as ordinary response lines, and the first of
them is taken as the tagged completion.
Ordinary requests hit this: `BODY.PEEK[HEADER] BODY.PEEK[TEXT]`,
`RFC822.HEADER RFC822.TEXT`, several `BODY[n]` parts, or ENVELOPE/BODYSTRUCTURE
strings that the server sends as literals (8-bit or CR/LF content). With
`BODY[TEXT]` the second literal is the message body, written by whoever sent
the mail. A body that starts with `x OK` ends the FETCH early, and the
remaining body lines stay in the stream and come back as the reply to the
client's next command. For example, a body of
```
x OK
* 2 FETCH (BODY[] {27}
Subject: forged by sender
)
y OK FETCH completed
```
makes a following `fetch("2", "BODY[]")` return `Subject: forged by sender`
instead of the real message 2, and the connection stays out of step after that.
A body whose first line does not look like a tagged reply makes the FETCH fail
with `MalformedServerReplyException`, so that message can't be fetched with
those items at all.
The change keeps the existing byte counting and adds the missing case: when
a literal ends on the current line, the remainder of that line is checked for a
following literal, so every literal is consumed before the tagged line is
looked for. A literal that ends exactly at the end of a line (for example a
mailbox name in a LIST response) is handled as before. This is the only place
in the code base that parses server literals.
The new `IMAPTest` case feeds a FETCH response with three literals, the last
of which imitates protocol lines. It fails on master with
`MalformedServerReplyException` and passes with this change. `mvn` (default
goal, with `-Ddoclint=all` as in CI) passes locally on Java 21.
- [x] Read the [contribution guidelines](CONTRIBUTING.md) for this project.
- [x] Read the [ASF Generative Tooling
Guidance](https://www.apache.org/legal/generative-tooling.html) if you use
Artificial Intelligence (AI).
- [x] I used AI to create any part of, or all of, this pull request. Which
AI tool was used to create this pull request, and to what extent did it
contribute?
- [x] Run a successful build using the default
[Maven](https://maven.apache.org/) goal with `mvn`; that's `mvn` on the command
line by itself.
- [x] Write unit tests that match behavioral changes, where the tests fail
if the changes to the runtime are not applied. This may not always be possible,
but it is a best practice.
- [x] Write a pull request description that is detailed enough to understand
what the pull request does, how, and why.
- [x] Each commit in the pull request should have a meaningful subject line
and body. Note that a maintainer may squash commits during the merge process.
--
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]