Allow lowercase letters for MAIL FROM and RCPT TO #38
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #35 - Implements case-insensitive matching for SMTP protocol commands and supports RFC-violating commands with warnings.
Problem
The SMTP proxy was matching protocol commands case-sensitively (e.g., only
MAIL FROM
, notmail from
orMail From
), which caused:Additionally, the issue reporter mentioned that real-world MTAs may send commands with variable spacing (e.g.,
MAIL FROM: <address>
with space after colon), which is RFC-violating but occurs in practice.Solution
Two-Layer Approach
MAIL
,mail
,Mail
)Implementation Details
Custom
containsFold()
function - High-performance case-insensitive byte slice searchRelaxed regex patterns - Accept spacing variations and RFC-violating local parts
MAIL FROM:<address>
(RFC compliant)MAIL FROM: <address>
(space after colon)MAIL FROM : <address>
(spaces before and after)MAIL FROM:<address>
(double space)user..name@
,-user@
,.user@
,user.@
Strict compliance checking - Dual regex patterns
Updated command parsers
HELO
/EHLO
- Now acceptshelo
,Helo
, etc.MAIL FROM
- Now acceptsmail from
,Mail From
, spacing variationsRCPT TO
- Now acceptsrcpt to
,Rcpt To
, spacing variationsRFC 5321 Compliance
From RFC 5321 Section 2.4:
From RFC 5321 Section 3.3:
This implementation:
Real-World RFC Violations
The regex also handles RFC-violating email address patterns used by some carriers (see Docomo and carrier info):
user..name@domain
username.@domain
-username@domain
,.username@domain
user--name@domain
-user..name.@domain
All these patterns are successfully extracted and logged.
Example Logs
RFC Compliant Commands
RFC Violation Commands
Benefits
Testing
mail from
,rcpt to
,helo
,ehlo
)Mail From
,Rcpt To
,Helo
,Ehlo
)Performance
The custom
containsFold()
approach is significantly faster than alternatives:Changes
pipe.go
: AddedtoLower()
,containsFold()
,isRFCCompliant()
helper functionspipe.go
: Relaxed and strict regex patterns for MAIL FROM and RCPT TOpipe.go
: UpdatedsetSenderMailAddress()
,setReceiverMailAddressAndServerName()
pipe.go
: Added RFC violation warning logspipe_test.go
: Added 12 new test cases for case-insensitive matchingrfc_violation_test.go
: New comprehensive tests for RFC violation handlingcarrier_rfc_violation_test.go
: Tests for carrier-specific RFC violations🤖 Generated with Claude Code