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

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git


The following commit(s) were added to refs/heads/master by this push:
     new f6c7621bc3 JAMES-4066 EHLO should accept alphanumeric hostname (#2396)
f6c7621bc3 is described below

commit f6c7621bc3e0f6c4718e376080477c301a94a5d1
Author: Trần Hồng Quân <55171818+quantranhong1...@users.noreply.github.com>
AuthorDate: Fri Aug 30 15:50:42 2024 +0700

    JAMES-4066 EHLO should accept alphanumeric hostname (#2396)
---
 .../james/protocols/smtp/core/esmtp/EhloCmdHandler.java    | 12 +++++++++++-
 .../java/org/apache/james/smtpserver/SMTPServerTest.java   | 14 ++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git 
a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/EhloCmdHandler.java
 
b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/EhloCmdHandler.java
index 01e3b4a5e3..a68ba17e30 100644
--- 
a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/EhloCmdHandler.java
+++ 
b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/EhloCmdHandler.java
@@ -37,6 +37,7 @@ import org.apache.james.protocols.smtp.hook.HookResult;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.base.CharMatcher;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Sets;
@@ -57,6 +58,9 @@ public class EhloCmdHandler extends 
AbstractHookableCmdHandler<HeloHook> impleme
     private static final List<String> ESMTP_FEATURES = 
ImmutableList.of("PIPELINING", "ENHANCEDSTATUSCODES", "8BITMIME");
     private static final Response DOMAIN_ADDRESS_REQUIRED = new 
SMTPResponse(SMTPRetCode.SYNTAX_ERROR_ARGUMENTS, 
DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.DELIVERY_INVALID_ARG) + " 
Domain address required: " + COMMAND_NAME).immutable();
     private static final Logger LOGGER = 
LoggerFactory.getLogger(EhloCmdHandler.class);
+    private static final CharMatcher ALPHANUMERIC_MATCHER = 
CharMatcher.inRange('a', 'z')
+        .or(CharMatcher.inRange('A', 'Z'))
+        .or(CharMatcher.inRange('0', '9'));
 
     private List<EhloExtension> ehloExtensions;
 
@@ -102,7 +106,13 @@ public class EhloCmdHandler extends 
AbstractHookableCmdHandler<HeloHook> impleme
             // Guava tries parsing IPv6 if and only if wrapped by []
             || InetAddresses.isUriInetAddress("[" + 
removeEmIPV6Prefix(hostname) + "]")
             || InternetDomainName.isValid(hostname)
-            || emClientCompatibility(hostname);
+            || emClientCompatibility(hostname)
+            || isAlphanumeric(hostname);
+    }
+
+    // CF JAMES-4046 
https://issues.apache.org/jira/projects/JAMES/issues/JAMES-4066
+    private boolean isAlphanumeric(String hostname) {
+        return !hostname.isEmpty() && 
ALPHANUMERIC_MATCHER.matchesAllOf(hostname);
     }
 
     // CF JAMES-4040 IPv6v4-full https://datatracker.ietf.org/doc/html/rfc5321
diff --git 
a/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java
 
b/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java
index 4ad2487a08..147a3d097f 100644
--- 
a/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java
+++ 
b/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java
@@ -1423,6 +1423,20 @@ public class SMTPServerTest {
         assertThat(smtpProtocol.getReplyString()).contains("250");
     }
 
+    @Test
+    void ehloShouldAcceptAlphanumericHostname() throws Exception {
+        smtpConfiguration.setAuthorizedAddresses("128.0.0.1/8");
+        smtpConfiguration.setAuthorizingAnnounce();
+        init(smtpConfiguration);
+
+        SMTPClient smtpProtocol = new SMTPClient();
+        InetSocketAddress bindedAddress = testSystem.getBindedAddress();
+        smtpProtocol.connect(bindedAddress.getAddress().getHostAddress(), 
bindedAddress.getPort());
+
+        smtpProtocol.sendCommand("ehlo", "7kO2OrE");
+        assertThat(smtpProtocol.getReplyString()).contains("250");
+    }
+
     @Test
     public void testAuthSendMailFromDomainAlias() throws Exception {
         smtpConfiguration.setAuthorizedAddresses("128.0.0.1/8");


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@james.apache.org
For additional commands, e-mail: notifications-h...@james.apache.org

Reply via email to