aboutsummaryrefslogtreecommitdiff
path: root/plugins/viewhtml/viewer.go
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/viewhtml/viewer.go')
-rw-r--r--plugins/viewhtml/viewer.go11
1 files changed, 6 insertions, 5 deletions
diff --git a/plugins/viewhtml/viewer.go b/plugins/viewhtml/viewer.go
index 9734c37..47f5eea 100644
--- a/plugins/viewhtml/viewer.go
+++ b/plugins/viewhtml/viewer.go
@@ -12,7 +12,7 @@ import (
"github.com/emersion/go-message"
)
-const tpl = `
+const tplSrc = `
<!-- allow-same-origin is required to resize the frame with its content -->
<!-- allow-popups is required for target="_blank" links -->
<iframe id="email-frame" srcdoc="{{.}}" sandbox="allow-same-origin allow-popups"></iframe>
@@ -20,6 +20,8 @@ const tpl = `
<link rel="stylesheet" href="/plugins/viewhtml/assets/style.css">
`
+var tpl = template.Must(template.New("view-html.html").Parse(tplSrc))
+
type viewer struct{}
func (viewer) ViewMessagePart(ctx *koushin.Context, msg *koushinbase.IMAPMessage, part *message.Entity) (interface{}, error) {
@@ -36,15 +38,14 @@ func (viewer) ViewMessagePart(ctx *koushin.Context, msg *koushinbase.IMAPMessage
return nil, fmt.Errorf("failed to read part body: %v", err)
}
- body, err = sanitizeHTML(body)
+ san := sanitizer{msg}
+ body, err = san.sanitizeHTML(body)
if err != nil {
return nil, fmt.Errorf("failed to sanitize HTML part: %v", err)
}
- t := template.Must(template.New("view-html.html").Parse(tpl))
-
var buf bytes.Buffer
- err = t.Execute(&buf, string(body))
+ err = tpl.Execute(&buf, string(body))
if err != nil {
return nil, err
}