Skip to content

Commit 24dcfef

Browse files
author
Sven Liebert
committed
Sanitize email body and remove special characters
1 parent dbfe3a9 commit 24dcfef

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

service/cmd/server/main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"github.com/emersion/go-imap"
77
"github.com/emersion/go-imap/client"
8+
_ "github.com/emersion/go-message/charset"
89
"github.com/emersion/go-message/mail"
910
"github.com/microcosm-cc/bluemonday"
1011
"github.com/robfig/cron/v3"
@@ -46,6 +47,13 @@ func getMailBody(p *mail.Part) string {
4647
body, _ := ioutil.ReadAll(p.Body)
4748
plainTextBody := strings.Replace(string(body), "\n", "\\n", -1)
4849
plainTextBody = strings.Replace(plainTextBody, "\r", "\\r", -1)
50+
51+
regex, err := regexp.Compile(`[^\w] && [\\]`)
52+
if err != nil {
53+
log.Fatal(err)
54+
}
55+
plainTextBody = regex.ReplaceAllString(plainTextBody, " ")
56+
4957
return sanitizePolicy.Sanitize(plainTextBody)
5058
}
5159

service/go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ go 1.14
55
require (
66
github.com/emersion/go-imap v1.2.1
77
github.com/emersion/go-message v0.15.0
8-
github.com/grokify/html-strip-tags-go v0.0.1
98
github.com/microcosm-cc/bluemonday v1.0.19
109
github.com/robfig/cron/v3 v3.0.1
1110
)

service/go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ github.com/emersion/go-textwrapper v0.0.0-20200911093747-65d896831594 h1:IbFBtwo
1010
github.com/emersion/go-textwrapper v0.0.0-20200911093747-65d896831594/go.mod h1:aqO8z8wPrjkscevZJFVE1wXJrLpC5LtJG7fqLOsPb2U=
1111
github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY=
1212
github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c=
13-
github.com/grokify/html-strip-tags-go v0.0.1 h1:0fThFwLbW7P/kOiTBs03FsJSV9RM2M/Q/MOnCQxKMo0=
14-
github.com/grokify/html-strip-tags-go v0.0.1/go.mod h1:2Su6romC5/1VXOQMaWL2yb618ARB8iVo6/DR99A6d78=
1513
github.com/microcosm-cc/bluemonday v1.0.19 h1:OI7hoF5FY4pFz2VA//RN8TfM0YJ2dJcl4P4APrCWy6c=
1614
github.com/microcosm-cc/bluemonday v1.0.19/go.mod h1:QNzV2UbLK2/53oIIwTOyLUSABMkjZ4tqiyC1g/DyqxE=
1715
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=

0 commit comments

Comments
 (0)