From 3c4a2651e7a642bc0f2305ec5ead4e4aa3a0f4c5 Mon Sep 17 00:00:00 2001 From: gutmet Date: Sat, 21 Nov 2020 10:25:27 +0100 Subject: [PATCH] set sender and reply-to only if dkim does not prevent it --- picolist.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/picolist.go b/picolist.go index 40caf0b..bd487c1 100644 --- a/picolist.go +++ b/picolist.go @@ -102,15 +102,25 @@ func isAllowed(mail *mail.Message, f flags, owners hashset) (bool, error) { } func setHeaderFields(mail *mail.Message, listname string, f flags) { + dkim := mail.Header.Get("DKIM-Signature") + canChange := func(headerName string) bool { + headerName = ":" + headerName + ":" + headerNameLower := strings.ToLower(headerName) + return dkim == "" || (!strings.Contains(dkim, headerName) && !strings.Contains(dkim, headerNameLower)) + } bounceAddress := []string{"<" + f.returnPath() + ">"} listAddress := []string{"<" + listname + ">"} mail.Header["Precedence"] = []string{"list"} - mail.Header["Sender"] = bounceAddress + if canChange("Sender") { + mail.Header["Sender"] = bounceAddress + } mail.Header["Errors-To"] = bounceAddress mail.Header["List-Id"] = listAddress if !f.newsletter { mail.Header["List-Post"] = []string{""} - mail.Header["Reply-To"] = listAddress + if canChange("Reply-To") { + mail.Header["Reply-To"] = listAddress + } } }