From 2ea92d1b7e020c2286571ae2a23887369a441172 Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Sat, 14 Dec 2024 03:03:20 +0100 Subject: [PATCH] Chore: Stricter SMTP 'MAIL FROM' & 'RCPT TO' handling (#409) * Update lib.go: Changing `mailFromRE` and `rcptToRE` regex I don't know how to rebase so I started from scratch ;-) 2 changes compared to what you said at https://github.com/axllent/mailpit/pull/406#issuecomment-2540350780 * I did the same for `rcptToRE` * I replaced the `*` quantifier with `+`, for consistency * Update lib.go * Allow valid empty MAIL FROM value --------- Co-authored-by: Ralph Slooten --- server/smtpd/lib.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/smtpd/lib.go b/server/smtpd/lib.go index 20691eb..a240f65 100644 --- a/server/smtpd/lib.go +++ b/server/smtpd/lib.go @@ -27,8 +27,8 @@ import ( var ( // Debug `true` enables verbose logging. Debug = false - rcptToRE = regexp.MustCompile(`[Tt][Oo]:\s?<(.+)>`) - mailFromRE = regexp.MustCompile(`[Ff][Rr][Oo][Mm]:\s?<(.*)>(\s(.*))?`) // Delivery Status Notifications are sent with "MAIL FROM:<>" + rcptToRE = regexp.MustCompile(`[Tt][Oo]: ?<([^<>\v]+)>( |$)(.*)?`) + mailFromRE = regexp.MustCompile(`[Ff][Rr][Oo][Mm]: ?<(|[^<>\v]+)>( |$)(.*)?`) // Delivery Status Notifications are sent with "MAIL FROM:<>" // extract mail size from 'MAIL FROM' parameter mailFromSizeRE = regexp.MustCompile(`(?U)(^| |,)[Ss][Ii][Zz][Ee]=(.*)($|,| )`)