You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2022/05/12 01:41:16 UTC
[james-project] 02/05: JAMES-3737 ImapRequestFrameDecoder: better manage framing
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 05c1e70025a7198fbe70b75a062500657bc80295
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Wed May 11 12:52:52 2022 +0700
JAMES-3737 ImapRequestFrameDecoder: better manage framing
---
.../imapserver/netty/ImapRequestFrameDecoder.java | 6 ++----
.../james/imapserver/netty/IMAPServerTest.java | 20 ++++++++++++++++++++
2 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java
index 9cd437eaf9..43ad58a086 100644
--- a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java
+++ b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java
@@ -267,15 +267,13 @@ public class ImapRequestFrameDecoder extends ByteToMessageDecoder implements Net
}
public void disableFraming(ChannelHandlerContext ctx) {
- if (framingEnabled.get()) {
+ if (framingEnabled.getAndSet(false)) {
ctx.channel().pipeline().remove(FRAMER);
- framingEnabled.set(false);
}
}
public void enableFraming(ChannelHandlerContext ctx) {
- if (!framingEnabled.get()) {
- framingEnabled.set(true);
+ if (!framingEnabled.getAndSet(true)) {
ctx.channel().pipeline().addBefore(REQUEST_DECODER, FRAMER,
new SwitchableLineBasedFrameDecoder(ctx.channel().pipeline(), maxFrameLength, false));
}
diff --git a/server/protocols/protocols-imap4/src/test/java/org/apache/james/imapserver/netty/IMAPServerTest.java b/server/protocols/protocols-imap4/src/test/java/org/apache/james/imapserver/netty/IMAPServerTest.java
index aea7bda099..ae12a8117c 100644
--- a/server/protocols/protocols-imap4/src/test/java/org/apache/james/imapserver/netty/IMAPServerTest.java
+++ b/server/protocols/protocols-imap4/src/test/java/org/apache/james/imapserver/netty/IMAPServerTest.java
@@ -380,6 +380,26 @@ class IMAPServerTest {
assertThat(new String(readBytes(clientConnection), StandardCharsets.US_ASCII)).contains("APPEND completed.");
}
+
+ @Test
+ void partialCommandAfterNonSynchronizedLiteralShouldNotFail() throws Exception {
+ clientConnection.write(ByteBuffer.wrap(String.format("a0 LOGIN %s %s\r\n", USER.asString(), USER_PASS).getBytes(StandardCharsets.UTF_8)));
+ readBytes(clientConnection);
+
+ String msg = "Date: Mon, 7 Feb 1994 21:52:25 -0800 (PST)\r\n" +
+ "From: Fred Foobar <fo...@Blurdybloop.COM>\r\n" +
+ "Subject: afternoon meeting 2\r\n" +
+ "To: mooch@owatagu.siam.edu\r\n" +
+ "Message-Id: <B2...@Blurdybloop.COM>\r\n" +
+ "MIME-Version: 1.0\r\n" +
+ "Content-Type: TEXT/PLAIN; CHARSET=US-ASCII\r\n" +
+ "C:\r\n" +
+ "Hello Joe, could we change that to 4:00pm tomorrow?\r\n";
+ clientConnection.write(ByteBuffer.wrap(("A004 APPEND INBOX {" + msg.length() + "+}\r\n" +
+ msg + "\r\nA005 NOOP").getBytes(StandardCharsets.UTF_8)));
+
+ assertThat(new String(readBytes(clientConnection), StandardCharsets.US_ASCII)).contains("APPEND completed.");
+ }
}
@Nested
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org