From 40d3dce5bf3b4f20af154d82faf02577031af433 Mon Sep 17 00:00:00 2001 From: Abin Simon Date: Wed, 3 Apr 2024 17:09:33 +0530 Subject: [PATCH 1/2] Only call replaceCID if we have anything to replace --- message.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/message.go b/message.go index 828f7c1..5cdf233 100644 --- a/message.go +++ b/message.go @@ -83,7 +83,14 @@ func (msg *message) getCID(text string) (cid string) { // replaceCIDs replaces the CIDs found in a text string // with generated ones -func (msg *message) replaceCIDs(text string) string { +func (msg *message) replaceCIDs(input []byte) []byte { + if len(msg.cids) == 0 { + // One process replaceCIDs if we have anything to replace + return input + } + + text := string(input) + // regular expression to find cids re := regexp.MustCompile(`(src|href)="cid:(.*?)"`) // replace all of the found cids with generated ones @@ -92,7 +99,7 @@ func (msg *message) replaceCIDs(text string) string { text = strings.Replace(text, "cid:"+matches[2], "cid:"+cid, -1) } - return text + return []byte(text) } // openMultipart creates a new part of a multipart message @@ -211,7 +218,7 @@ func (msg *message) writeBody(body []byte, encoding encoding) { } func (msg *message) addBody(contentType string, body []byte) { - body = []byte(msg.replaceCIDs(string(body))) + body = msg.replaceCIDs(body) header := make(textproto.MIMEHeader) header.Set("Content-Type", contentType+"; charset="+msg.charset) From c5729f799877d04606a1142f0b8240873b21094f Mon Sep 17 00:00:00 2001 From: Abin Simon Date: Wed, 3 Apr 2024 17:10:37 +0530 Subject: [PATCH 2/2] Use contentID directly if provided --- message.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/message.go b/message.go index 5cdf233..ceb7fca 100644 --- a/message.go +++ b/message.go @@ -247,7 +247,7 @@ func (msg *message) addFiles(files []*File, inline bool) { if inline { header.Set("Content-Disposition", "inline;\n \tfilename=\""+encodedFilename+`"`) if len(file.ContentID) > 0 { - header.Set("Content-ID", "<"+msg.getCID(file.ContentID)+">") + header.Set("Content-ID", "<"+file.ContentID+">") } else { header.Set("Content-ID", "<"+msg.getCID(file.Name)+">") }