设置新增抄送列表,MIME 增加 Cc 头、envelope 同时投递主送与抄送,同一地址不得同时出现在两边。 确认后可保存统计看板 PNG(multipart/related + cid),发送时放在正文末尾内联显示;正文改动使确认失效后不再使用旧图。
This commit is contained in:
@@ -92,3 +92,30 @@ func TestMailerRefusesPlaintextServersWithoutSTARTTLS(t *testing.T) {
|
||||
t.Fatal("a server that cannot encrypt must be refused rather than sent in clear")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeRejectsACopyThatIsAlsoAPrimaryRecipient(t *testing.T) {
|
||||
_, err := normalize(SettingsInput{Host: "smtp.example.com", From: "kb@example.com", Recipients: []string{"a@example.com"}, Cc: []string{"A@example.com"}, Enabled: true})
|
||||
if err != ErrInvalid {
|
||||
t.Fatal("a person in both To and Cc would receive the report twice")
|
||||
}
|
||||
good, err := normalize(SettingsInput{Host: "smtp.example.com", From: "kb@example.com", Recipients: []string{"a@example.com"}, Cc: []string{"b@example.com", "c@example.com"}, Enabled: true})
|
||||
if err != nil || len(good.Cc) != 2 {
|
||||
t.Fatalf("valid cc list rejected: %+v %v", good.Cc, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildMIMEPlacesTheChartAfterTheBodyAsAnInlineImage(t *testing.T) {
|
||||
html, text := renderReport("# 周报\n\n正确率:90.66%\n")
|
||||
png := []byte("\x89PNG\r\n\x1a\nfixture-bytes")
|
||||
html = strings.Replace(html, "</body>", `<p><img src="cid:weekly-dashboard@knowledge-governance"></p></body>`, 1)
|
||||
raw := buildMIME(Message{From: "kb@example.com", To: []string{"a@example.com"}, Cc: []string{"b@example.com"}, Subject: "周报", HTML: html, Text: text,
|
||||
Images: []InlineImage{{Name: "dashboard.png", ContentType: "image/png", CID: "weekly-dashboard@knowledge-governance", Bytes: png}}}, "<id@example.com>", "BOUND")
|
||||
for _, want := range []string{"Cc: b@example.com", "multipart/related", "multipart/alternative", "Content-ID: <weekly-dashboard@knowledge-governance>", "Content-Disposition: inline; filename=\"dashboard.png\"", "image/png"} {
|
||||
if !strings.Contains(raw, want) {
|
||||
t.Fatalf("MIME payload missing %q", want)
|
||||
}
|
||||
}
|
||||
if !strings.Contains(html, "cid:weekly-dashboard@knowledge-governance") {
|
||||
t.Fatal("html body must reference the inline cid")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user