From 9f4908d11d8701da20c5cd024f45903a67512e60 Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Sat, 14 Dec 2024 19:56:20 +0100 Subject: [PATCH] Add case-insensitive flags to regex'es (#411) * Update smtpd.go: Adding case-insensitive flags to regex'es * Update smtpd_test.go --- internal/smtpd/smtpd.go | 4 ++-- internal/smtpd/smtpd_test.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/smtpd/smtpd.go b/internal/smtpd/smtpd.go index a240f6555..7eb863606 100644 --- a/internal/smtpd/smtpd.go +++ b/internal/smtpd/smtpd.go @@ -27,8 +27,8 @@ import ( var ( // Debug `true` enables verbose logging. Debug = false - rcptToRE = regexp.MustCompile(`[Tt][Oo]: ?<([^<>\v]+)>( |$)(.*)?`) - mailFromRE = regexp.MustCompile(`[Ff][Rr][Oo][Mm]: ?<(|[^<>\v]+)>( |$)(.*)?`) // Delivery Status Notifications are sent with "MAIL FROM:<>" + rcptToRE = regexp.MustCompile(`(?i)TO: ?<([^<>\v]+)>( |$)(.*)?`) + mailFromRE = regexp.MustCompile(`(?i)FROM: ?<(|[^<>\v]+)>( |$)(.*)?`) // Delivery Status Notifications are sent with "MAIL FROM:<>" // extract mail size from 'MAIL FROM' parameter mailFromSizeRE = regexp.MustCompile(`(?U)(^| |,)[Ss][Ii][Zz][Ee]=(.*)($|,| )`) diff --git a/internal/smtpd/smtpd_test.go b/internal/smtpd/smtpd_test.go index 6f8cf61b1..3dc9a1c8a 100644 --- a/internal/smtpd/smtpd_test.go +++ b/internal/smtpd/smtpd_test.go @@ -84,8 +84,8 @@ func TestCmdHELO(t *testing.T) { // Verify that HELO resets the current transaction state like RSET. // RFC 2821 section 4.1.4 says EHLO should cause a reset, so verify that HELO does it too. - cmdCode(t, conn, "MAIL FROM:", "250") - cmdCode(t, conn, "RCPT TO:", "250") + cmdCode(t, conn, "mail from:", "250") // Also testing case-insensitivity + cmdCode(t, conn, "rcpt to:", "250") cmdCode(t, conn, "HELO host.example.com", "250") cmdCode(t, conn, "DATA", "503")