Skip to content

Commit

Permalink
Add case-insensitive flags to regex'es (#411)
Browse files Browse the repository at this point in the history
* Update smtpd.go: Adding case-insensitive flags to regex'es
* Update smtpd_test.go
  • Loading branch information
ThomasLandauer authored Dec 14, 2024
1 parent 13027bf commit 9f4908d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions internal/smtpd/smtpd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]=(.*)($|,| )`)
Expand Down
4 changes: 2 additions & 2 deletions internal/smtpd/smtpd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:<[email protected]>", "250")
cmdCode(t, conn, "RCPT TO:<[email protected]>", "250")
cmdCode(t, conn, "mail from:<[email protected]>", "250") // Also testing case-insensitivity
cmdCode(t, conn, "rcpt to:<[email protected]>", "250")
cmdCode(t, conn, "HELO host.example.com", "250")
cmdCode(t, conn, "DATA", "503")

Expand Down

0 comments on commit 9f4908d

Please sign in to comment.