set sender and reply-to only if dkim does not prevent it

This commit is contained in:
gutmet 2020-11-21 10:25:27 +01:00
parent e06ebb4d30
commit 3c4a2651e7

View File

@ -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{"<mailto:" + listname + ">"}
mail.Header["Reply-To"] = listAddress
if canChange("Reply-To") {
mail.Header["Reply-To"] = listAddress
}
}
}