correct html replacing

alpha
alex 2024-01-22 17:45:23 +01:00
parent 0e632d00f7
commit 2780ade490
2 changed files with 20 additions and 2 deletions

7
commit_and_push.sh Executable file
View File

@ -0,0 +1,7 @@
git add *
read -p "Commit message: " commit_message
git commit -m "$commit_message"
git push -u origin main

View File

@ -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 &lt; and &gt; in html body
// so we have to replace them back
// replace all &lt; and &gt; with < and > in html body
htmlBody = strings.ReplaceAll(htmlBuf.String(), "&lt;", "<")
htmlBody = strings.ReplaceAll(htmlBody, "&gt;", ">")
// 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
}
/*