From 2780ade4907cc46fb18dff018f1e273df99fb13e Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 22 Jan 2024 17:45:23 +0100 Subject: [PATCH] correct html replacing --- commit_and_push.sh | 7 +++++++ modules/structs/mail.go | 15 +++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100755 commit_and_push.sh diff --git a/commit_and_push.sh b/commit_and_push.sh new file mode 100755 index 0000000..554786f --- /dev/null +++ b/commit_and_push.sh @@ -0,0 +1,7 @@ +git add * + +read -p "Commit message: " commit_message + +git commit -m "$commit_message" + +git push -u origin main \ No newline at end of file diff --git a/modules/structs/mail.go b/modules/structs/mail.go index d7f6a97..157cd71 100644 --- a/modules/structs/mail.go +++ b/modules/structs/mail.go @@ -56,7 +56,6 @@ func (m *Mail) Send(htmlBody, textBody string) error { return err } - gocnjhelper.LogDebugf("SEND MAIL %s", msg) return nil } @@ -120,6 +119,7 @@ func (m *Mail) RenderTemplate() (htmlBody, textBody string, err error) { } body.HTML = []byte(strings.Replace(string(body.HTML), "%"+key+"%", v, -1)) + body.PlainText = []byte(strings.Replace(string(body.PlainText), "%"+key+"%", v, -1)) } } @@ -136,15 +136,26 @@ func (m *Mail) RenderTemplate() (htmlBody, textBody string, err error) { htmlBuf := new(bytes.Buffer) textBuf := new(bytes.Buffer) + gocnjhelper.LogDebugf("BODY DATA %s ", m.BodyData) + if err := htmlTemplate.Execute(htmlBuf, m.BodyData); err != nil { return "", "", err } + // the execute function replaces all < and > with < and > in html body + // so we have to replace them back + // replace all < and > with < and > in html body + + htmlBody = strings.ReplaceAll(htmlBuf.String(), "<", "<") + htmlBody = strings.ReplaceAll(htmlBody, ">", ">") + + // Execute text template + if err := textTemplate.Execute(textBuf, m.BodyData); err != nil { return "", "", err } - return htmlBuf.String(), textBuf.String(), nil + return htmlBody, textBuf.String(), nil } /*