feat: per-message extra headers in the mail envelope
This commit is contained in:
@@ -83,3 +83,30 @@ func TestEnvelopePartsAreQuotedPrintable(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnvelopeWritesExtraHeadersSanitised(t *testing.T) {
|
||||
s := Sender{From: "Vantage <updates@example.com>"}
|
||||
raw, err := s.envelope(message{
|
||||
To: "a@example.com", Subject: "s", Text: "t", HTML: "<p>h</p>",
|
||||
Headers: map[string]string{
|
||||
"List-Unsubscribe-Post": "List-Unsubscribe=One-Click",
|
||||
"List-Unsubscribe": "<https://x.example/u?t=1>\r\nBcc: evil@example.com",
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
msg, err := mail.ReadMessage(bytes.NewReader(raw))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := msg.Header.Get("List-Unsubscribe-Post"); got != "List-Unsubscribe=One-Click" {
|
||||
t.Fatalf("List-Unsubscribe-Post = %q", got)
|
||||
}
|
||||
if got := msg.Header.Get("Bcc"); got != "" {
|
||||
t.Fatalf("header injection: Bcc = %q", got)
|
||||
}
|
||||
if !strings.HasPrefix(msg.Header.Get("List-Unsubscribe"), "<https://x.example/u?t=1>") {
|
||||
t.Fatalf("List-Unsubscribe = %q", msg.Header.Get("List-Unsubscribe"))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user