This is an automated email from the ASF dual-hosted git repository.

sebbASF pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-net.git


The following commit(s) were added to refs/heads/master by this push:
     new 0e58f419 reject CR/LF in IMAP quoteMailboxName (#399)
0e58f419 is described below

commit 0e58f4199852d2ad140af28a532b98fa7d9ef6b3
Author: Javid Khan <[email protected]>
AuthorDate: Fri Jun 26 04:00:43 2026 +0530

    reject CR/LF in IMAP quoteMailboxName (#399)
---
 src/main/java/org/apache/commons/net/imap/IMAP.java     |  3 +++
 src/test/java/org/apache/commons/net/imap/IMAPTest.java | 11 +++++++++++
 2 files changed, 14 insertions(+)

diff --git a/src/main/java/org/apache/commons/net/imap/IMAP.java 
b/src/main/java/org/apache/commons/net/imap/IMAP.java
index 94927a77..c100035a 100644
--- a/src/main/java/org/apache/commons/net/imap/IMAP.java
+++ b/src/main/java/org/apache/commons/net/imap/IMAP.java
@@ -106,6 +106,9 @@ public class IMAP extends SocketClient {
         if (input == null) { // Don't throw NPE here
             return null;
         }
+        if (input.indexOf('\r') >= 0 || input.indexOf('\n') >= 0) {
+            throw new IllegalArgumentException("Mailbox name cannot contain CR 
or LF characters");
+        }
         if (input.isEmpty()) {
             return "\"\""; // return the string ""
         }
diff --git a/src/test/java/org/apache/commons/net/imap/IMAPTest.java 
b/src/test/java/org/apache/commons/net/imap/IMAPTest.java
index 970586b1..51751efd 100644
--- a/src/test/java/org/apache/commons/net/imap/IMAPTest.java
+++ b/src/test/java/org/apache/commons/net/imap/IMAPTest.java
@@ -19,6 +19,7 @@ package org.apache.commons.net.imap;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.util.stream.Stream;
@@ -88,6 +89,16 @@ class IMAPTest {
         assertNull(IMAP.quoteMailboxName(null));
     }
 
+    @Test
+    void testQuoteMailboxNameRejectsLineFeed() {
+        assertThrows(IllegalArgumentException.class, () -> 
IMAP.quoteMailboxName("INBOX\nA001 DELETE Sent"));
+    }
+
+    @Test
+    void testQuoteMailboxNameRejectsCarriageReturn() {
+        assertThrows(IllegalArgumentException.class, () -> 
IMAP.quoteMailboxName("INBOX\r\nA001 DELETE Sent"));
+    }
+
     @Test
     void testQuoteMailboxNoQuotingIfNoSpacePresent() {
         final String stringToQuote = "Foobar\"";

Reply via email to