Allow lowercase letters for MAIL FROM and RCPT TO#38
Merged
Conversation
SMTP protocol commands are now matched case-insensitively as per RFC 5321 Section 2.4, which states that command verbs are not case sensitive. Changes: - Implement custom containsFold() function for efficient case-insensitive matching without allocations (~10x faster than regex-only approach) - Update HELO/EHLO, MAIL FROM, and RCPT TO command parsing to be case-insensitive - Fix regex patterns to properly capture email addresses including '>' - Add comprehensive test cases for lowercase and mixed-case commands This fixes false protocol synchronization errors and ensures metadata is collected correctly regardless of command case. π€ Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Issue #35 reporter mentioned that real-world MTAs may send commands with variable spacing (e.g., "MAIL FROM: <address>"). To maintain transparent proxy behavior while collecting metadata, we now: Changes: - Relax regex patterns to accept spacing variations (MAIL FROM: <addr>) - Add RFC 5321 compliance checking with strict regex patterns - Log warnings for RFC violations while still extracting addresses - Maintain transparency: all packets forwarded regardless of compliance - Add comprehensive tests for RFC violation handling Example logs: RFC compliant: "MAIL FROM:<addr>" β address extracted, no warning RFC violation: "MAIL FROM: <addr>" β address extracted + warning: "RFC 5321 violation: \"MAIL FROM: <addr>\" (spaces not permitted around colon)" This allows operators to: - Collect metadata from non-compliant MTAs - Monitor RFC violations for troubleshooting - Let receiving MTA make final decision on acceptance π€ Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Add comprehensive tests for RFC-violating email address patterns that are actually used by some Japanese carriers. Test cases: - Consecutive dots in local part ([email protected]) - Dot before @ symbol ([email protected]) - Hyphen at start of local part ([email protected]) - Dot at start of local part ([email protected]) - Consecutive hyphens ([email protected]) - Multiple violations combined ([email protected]) References: - https://www.docomo.ne.jp/service/docomo_mail/rfc_add/ - https://www.sonoko.co.jp/user_data/oshirase10.php All tests pass, confirming that the current regex implementation already handles these real-world RFC violations correctly. π€ Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 fromorMail 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@domainusername.@domain-username@domain,.username@domainuser--name@domain-user..name.@domainAll 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