fix: display german umlauts correctly in emails
parent
5360b080b3
commit
5bd3403928
|
@ -0,0 +1,16 @@
|
||||||
|
package escaper
|
||||||
|
|
||||||
|
import "strings"
|
||||||
|
|
||||||
|
var htmlEntitesEscaper = strings.NewReplacer(
|
||||||
|
`Ä`, "Ä",
|
||||||
|
`ä`, "ä",
|
||||||
|
`Ö`, "Ö",
|
||||||
|
`ö`, "ö",
|
||||||
|
`Ü`, "Ü",
|
||||||
|
`ü`, "ü",
|
||||||
|
)
|
||||||
|
|
||||||
|
func EscapeHtmlEntites(s string) string {
|
||||||
|
return htmlEntitesEscaper.Replace(s)
|
||||||
|
}
|
|
@ -2,12 +2,14 @@ package structs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/base64"
|
||||||
"html/template"
|
"html/template"
|
||||||
"net/smtp"
|
"net/smtp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"clickandjoin.app/emailserver/modules/cache"
|
"clickandjoin.app/emailserver/modules/cache"
|
||||||
"clickandjoin.app/emailserver/modules/config"
|
"clickandjoin.app/emailserver/modules/config"
|
||||||
|
"clickandjoin.app/emailserver/modules/escaper"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -70,10 +72,21 @@ func (m *Mail) RenderTemplate() (string, error) {
|
||||||
v = value[config.Cfg.DefaultLanguageCode]
|
v = value[config.Cfg.DefaultLanguageCode]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// escaping so that umlauts are displayed correctly
|
||||||
|
if m.LanguageId == "de" {
|
||||||
|
v = escaper.EscapeHtmlEntites(v)
|
||||||
|
}
|
||||||
|
|
||||||
body = []byte(strings.Replace(string(body), "%"+key+"%", v, -1))
|
body = []byte(strings.Replace(string(body), "%"+key+"%", v, -1))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The subject line of an email is an independent header and utf 8 must be set for it
|
||||||
|
// https://ncona.com/2011/06/using-utf-8-characters-on-an-e-mail-subject/
|
||||||
|
if m.LanguageId == "de" {
|
||||||
|
m.Subject = "=?utf-8?B?" + base64.StdEncoding.EncodeToString([]byte(m.Subject)) + "?="
|
||||||
|
}
|
||||||
|
|
||||||
t := template.Must(template.New("").Parse(string(body)))
|
t := template.Must(template.New("").Parse(string(body)))
|
||||||
|
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
|
|
Loading…
Reference in New Issue