This is an automated email from the ASF dual-hosted git repository. garydgregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-net.git
commit b8b5c3c61d1e4d44ec6dce76afeaf9b0ffa74f0d Author: Gary Gregory <[email protected]> AuthorDate: Mon Jun 1 12:19:52 2026 -0400 Sort members --- .../apache/commons/net/nntp/SimpleNNTPHeader.java | 14 +++---- .../apache/commons/net/smtp/SimpleSMTPHeader.java | 14 +++---- .../commons/net/smtp/SimpleSMTPHeaderTestCase.java | 44 +++++++++++----------- 3 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/main/java/org/apache/commons/net/nntp/SimpleNNTPHeader.java b/src/main/java/org/apache/commons/net/nntp/SimpleNNTPHeader.java index 47cd01ad..9c373ce9 100644 --- a/src/main/java/org/apache/commons/net/nntp/SimpleNNTPHeader.java +++ b/src/main/java/org/apache/commons/net/nntp/SimpleNNTPHeader.java @@ -43,10 +43,17 @@ package org.apache.commons.net.nntp; */ public class SimpleNNTPHeader { + private static String validate(final String value) { + if (value != null && (value.indexOf('\r') >= 0 || value.indexOf('\n') >= 0)) { + throw new IllegalArgumentException("Header value cannot contain CR or LF characters"); + } + return value; + } private final String subject; private final String from; private final StringBuilder newsgroups; private final StringBuilder headerFields; + private int newsgroupCount; /** @@ -63,13 +70,6 @@ public class SimpleNNTPHeader { this.newsgroupCount = 0; } - private static String validate(final String value) { - if (value != null && (value.indexOf('\r') >= 0 || value.indexOf('\n') >= 0)) { - throw new IllegalArgumentException("Header value cannot contain CR or LF characters"); - } - return value; - } - /** * Adds an arbitrary header field with the given value to the article header. * These headers will be written after the {@code From}, Newsgroups, and Subject fields diff --git a/src/main/java/org/apache/commons/net/smtp/SimpleSMTPHeader.java b/src/main/java/org/apache/commons/net/smtp/SimpleSMTPHeader.java index 30bd8f07..4d87ffaf 100644 --- a/src/main/java/org/apache/commons/net/smtp/SimpleSMTPHeader.java +++ b/src/main/java/org/apache/commons/net/smtp/SimpleSMTPHeader.java @@ -48,11 +48,18 @@ import java.util.Locale; */ public class SimpleSMTPHeader { + private static String validate(final String value) { + if (value != null && (value.indexOf('\r') >= 0 || value.indexOf('\n') >= 0)) { + throw new IllegalArgumentException("Header value cannot contain CR or LF characters"); + } + return value; + } private final String subject; private final String from; private final String to; private final StringBuffer headerFields; private boolean hasHeaderDate; + private StringBuffer cc; /** @@ -73,13 +80,6 @@ public class SimpleSMTPHeader { this.cc = null; } - private static String validate(final String value) { - if (value != null && (value.indexOf('\r') >= 0 || value.indexOf('\n') >= 0)) { - throw new IllegalArgumentException("Header value cannot contain CR or LF characters"); - } - return value; - } - /** * Add an email address to the CC (carbon copy or courtesy copy) list. * diff --git a/src/test/java/org/apache/commons/net/smtp/SimpleSMTPHeaderTestCase.java b/src/test/java/org/apache/commons/net/smtp/SimpleSMTPHeaderTestCase.java index d8cf2ed1..6119593c 100644 --- a/src/test/java/org/apache/commons/net/smtp/SimpleSMTPHeaderTestCase.java +++ b/src/test/java/org/apache/commons/net/smtp/SimpleSMTPHeaderTestCase.java @@ -79,6 +79,28 @@ class SimpleSMTPHeaderTestCase { beforeDate = new Date(); } + @Test + void testRejectCarriageReturnInConstructor() { + assertThrows(IllegalArgumentException.class, () -> new SimpleSMTPHeader("[email protected]", "[email protected]", "Subject\rInjected: header")); + } + + @Test + void testRejectLineFeedInAddCC() { + final SimpleSMTPHeader header = new SimpleSMTPHeader("[email protected]", null, null); + assertThrows(IllegalArgumentException.class, () -> header.addCC("[email protected]\nBcc: [email protected]")); + } + + @Test + void testRejectLineFeedInAddHeaderField() { + final SimpleSMTPHeader header = new SimpleSMTPHeader("[email protected]", null, null); + assertThrows(IllegalArgumentException.class, () -> header.addHeaderField("X-Header1", "value 1\nX-Injected: value 2")); + } + + @Test + void testRejectLineFeedInConstructor() { + assertThrows(IllegalArgumentException.class, () -> new SimpleSMTPHeader("[email protected]", "[email protected]", "Subject\nInjected: header")); + } + @Test void testToString() { // Note that the DotTerminatedMessageWriter converts LF to CRLF @@ -105,28 +127,6 @@ class SimpleSMTPHeaderTestCase { assertEquals("Date: dummy date\nFrom: [email protected]\n\n", header.toString()); } - @Test - void testRejectCarriageReturnInConstructor() { - assertThrows(IllegalArgumentException.class, () -> new SimpleSMTPHeader("[email protected]", "[email protected]", "Subject\rInjected: header")); - } - - @Test - void testRejectLineFeedInAddCC() { - final SimpleSMTPHeader header = new SimpleSMTPHeader("[email protected]", null, null); - assertThrows(IllegalArgumentException.class, () -> header.addCC("[email protected]\nBcc: [email protected]")); - } - - @Test - void testRejectLineFeedInAddHeaderField() { - final SimpleSMTPHeader header = new SimpleSMTPHeader("[email protected]", null, null); - assertThrows(IllegalArgumentException.class, () -> header.addHeaderField("X-Header1", "value 1\nX-Injected: value 2")); - } - - @Test - void testRejectLineFeedInConstructor() { - assertThrows(IllegalArgumentException.class, () -> new SimpleSMTPHeader("[email protected]", "[email protected]", "Subject\nInjected: header")); - } - @Test void testToStringNoFrom() { assertThrows(IllegalArgumentException.class, () -> new SimpleSMTPHeader(null, null, null));
