force <style></style> removal in html part of incoming emails

This commit is contained in:
Aine
2022-11-19 00:48:48 +02:00
parent 3ef6d2698e
commit ad83eab930
2 changed files with 5 additions and 49 deletions

View File

@@ -6,6 +6,7 @@ import (
"encoding/pem"
"fmt"
"net/mail"
"regexp"
"strings"
"time"
@@ -16,6 +17,8 @@ import (
"maunium.net/go/mautrix/id"
)
var styleRegex = regexp.MustCompile("<style((.|\n|\r)*?)<\\/style>")
// IncomingFilteringOptions for incoming mail
type IncomingFilteringOptions interface {
SpamcheckSMTP() bool
@@ -82,11 +85,8 @@ func NewEmail(messageID, inReplyTo, references, subject, from, to, text, html st
}
if html != "" {
var err error
html, err = StripHTMLTag(html, "style")
if err == nil {
email.HTML = html
}
html = styleRegex.ReplaceAllString(html, "")
email.HTML = html
}
return email