Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/java/org/apache/commons/net/imap/IMAP.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ static String quoteMailboxName(final String input) {
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 ""
}
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/org/apache/commons/net/imap/IMAPTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

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;
Expand Down Expand Up @@ -88,6 +89,16 @@ void testQuoteMailboxNameNullInput() {
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\"";
Expand Down