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,17 +102,27 @@ func isAllowed(mail *mail.Message, f flags, owners hashset) (bool, error) {
} }
func setHeaderFields(mail *mail.Message, listname string, f flags) { 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() + ">"} bounceAddress := []string{"<" + f.returnPath() + ">"}
listAddress := []string{"<" + listname + ">"} listAddress := []string{"<" + listname + ">"}
mail.Header["Precedence"] = []string{"list"} mail.Header["Precedence"] = []string{"list"}
if canChange("Sender") {
mail.Header["Sender"] = bounceAddress mail.Header["Sender"] = bounceAddress
}
mail.Header["Errors-To"] = bounceAddress mail.Header["Errors-To"] = bounceAddress
mail.Header["List-Id"] = listAddress mail.Header["List-Id"] = listAddress
if !f.newsletter { if !f.newsletter {
mail.Header["List-Post"] = []string{"<mailto:" + listname + ">"} mail.Header["List-Post"] = []string{"<mailto:" + listname + ">"}
if canChange("Reply-To") {
mail.Header["Reply-To"] = listAddress mail.Header["Reply-To"] = listAddress
} }
} }
}
func recipients(members hashset) ([]bulkRecipients, error) { func recipients(members hashset) ([]bulkRecipients, error) {
rcpts := members.elements() rcpts := members.elements()