diff --git a/pkg/notifications/mail.go b/pkg/notifications/mail.go index f346313d1..da7a9fd05 100644 --- a/pkg/notifications/mail.go +++ b/pkg/notifications/mail.go @@ -31,7 +31,7 @@ type Mail struct { } type mailLine struct { - text string + Text string isHTML bool } @@ -71,7 +71,7 @@ func (m *Mail) Action(text, url string) *Mail { return m } -// Line adds a line of text to the mail +// Line adds a line of Text to the mail func (m *Mail) Line(line string) *Mail { return m.appendLine(line, false) } @@ -83,14 +83,14 @@ func (m *Mail) HTML(line string) *Mail { func (m *Mail) appendLine(line string, isHTML bool) *Mail { if m.actionURL == "" { m.introLines = append(m.introLines, &mailLine{ - text: line, + Text: line, isHTML: isHTML, }) return m } m.outroLines = append(m.outroLines, &mailLine{ - text: line, + Text: line, isHTML: isHTML, }) diff --git a/pkg/notifications/mail_render.go b/pkg/notifications/mail_render.go index f06de283e..062bd9236 100644 --- a/pkg/notifications/mail_render.go +++ b/pkg/notifications/mail_render.go @@ -35,12 +35,12 @@ import ( const mailTemplatePlain = ` {{ .Greeting }} {{ range $line := .IntroLines}} -{{ $line }} +{{ $line.Text }} {{ end }} {{ if .ActionURL }}{{ .ActionText }}: {{ .ActionURL }}{{end}} {{ range $line := .OutroLines}} -{{ $line }} +{{ $line.Text }} {{ end }}` const mailTemplateHTML = ` @@ -50,9 +50,9 @@ const mailTemplateHTML = ` -
-
-

+
+
+

Vikunja

@@ -66,7 +66,7 @@ const mailTemplateHTML = ` {{ if .ActionURL }} + style="position: relative;Text-decoration:none;display: block;border-radius: 4px;cursor: pointer;padding-bottom: 8px;padding-left: 14px;padding-right: 14px;padding-top: 8px;width:280px;margin:10px auto;Text-align: center;white-space: nowrap;border: 0;Text-transform: uppercase;font-size: 14px;font-weight: 700;-webkit-box-shadow: 0 3px 6px rgba(107,114,128,.12),0 2px 4px rgba(107,114,128,.1);box-shadow: 0 3px 6px rgba(107,114,128,.12),0 2px 4px rgba(107,114,128,.1);background-color: #1973ff;border-color: transparent;color: #fff;"> {{ .ActionText }} {{end}} @@ -125,11 +125,11 @@ func RenderMail(m *Mail) (mailOpts *mail.Opts, err error) { for _, line := range m.introLines { if line.isHTML { // #nosec G203 -- the html is sanitized - introLinesHTML = append(introLinesHTML, templatehtml.HTML(p.Sanitize(line.text))) + introLinesHTML = append(introLinesHTML, templatehtml.HTML(p.Sanitize(line.Text))) continue } - md := []byte(templatehtml.HTMLEscapeString(line.text)) + md := []byte(templatehtml.HTMLEscapeString(line.Text)) var buf bytes.Buffer err = goldmark.Convert(md, &buf) if err != nil { @@ -144,11 +144,11 @@ func RenderMail(m *Mail) (mailOpts *mail.Opts, err error) { for _, line := range m.outroLines { if line.isHTML { // #nosec G203 -- the html is sanitized - outroLinesHTML = append(outroLinesHTML, templatehtml.HTML(p.Sanitize(line.text))) + outroLinesHTML = append(outroLinesHTML, templatehtml.HTML(p.Sanitize(line.Text))) continue } - md := []byte(templatehtml.HTMLEscapeString(line.text)) + md := []byte(templatehtml.HTMLEscapeString(line.Text)) var buf bytes.Buffer err = goldmark.Convert(md, &buf) if err != nil { diff --git a/pkg/notifications/mail_test.go b/pkg/notifications/mail_test.go index 4a8d3034f..c04d3be45 100644 --- a/pkg/notifications/mail_test.go +++ b/pkg/notifications/mail_test.go @@ -41,11 +41,15 @@ func TestNewMail(t *testing.T) { assert.Equal(t, "Testmail", mail.subject) assert.Equal(t, "Hi there,", mail.greeting) assert.Len(t, mail.introLines, 2) - assert.Equal(t, "This is a line", mail.introLines[0]) - assert.Equal(t, "And another one", mail.introLines[1]) + assert.Equal(t, "This is a line", mail.introLines[0].Text) + assert.False(t, mail.introLines[0].isHTML) + assert.Equal(t, "And another one", mail.introLines[1].Text) + assert.False(t, mail.introLines[1].isHTML) assert.Len(t, mail.outroLines, 2) - assert.Equal(t, "This should be an outro line", mail.outroLines[0]) - assert.Equal(t, "And one more, because why not?", mail.outroLines[1]) + assert.Equal(t, "This should be an outro line", mail.outroLines[0].Text) + assert.False(t, mail.outroLines[0].isHTML) + assert.Equal(t, "And one more, because why not?", mail.outroLines[1].Text) + assert.False(t, mail.outroLines[1].isHTML) }) t.Run("No greeting", func(t *testing.T) { mail := NewMail(). @@ -60,8 +64,8 @@ func TestNewMail(t *testing.T) { assert.Equal(t, "Testmail", mail.subject) assert.Equal(t, "", mail.greeting) assert.Len(t, mail.introLines, 2) - assert.Equal(t, "This is a line", mail.introLines[0]) - assert.Equal(t, "And another one", mail.introLines[1]) + assert.Equal(t, "This is a line", mail.introLines[0].Text) + assert.Equal(t, "And another one", mail.introLines[1].Text) }) t.Run("No action", func(t *testing.T) { mail := NewMail(). @@ -77,10 +81,10 @@ func TestNewMail(t *testing.T) { assert.Equal(t, "test@otherdomain.com", mail.to) assert.Equal(t, "Testmail", mail.subject) assert.Len(t, mail.introLines, 4) - assert.Equal(t, "This is a line", mail.introLines[0]) - assert.Equal(t, "And another one", mail.introLines[1]) - assert.Equal(t, "This should be an outro line", mail.introLines[2]) - assert.Equal(t, "And one more, because why not?", mail.introLines[3]) + assert.Equal(t, "This is a line", mail.introLines[0].Text) + assert.Equal(t, "And another one", mail.introLines[1].Text) + assert.Equal(t, "This should be an outro line", mail.introLines[2].Text) + assert.Equal(t, "And one more, because why not?", mail.introLines[3].Text) }) } @@ -125,9 +129,9 @@ And one more, because why not? -