Make the text/* part content a []byte
This commit is contained in:
parent
8d248bc32f
commit
a66ef1059b
2 changed files with 5 additions and 6 deletions
|
@ -234,13 +234,12 @@ func handleGetPart(ctx *koushin.Context, raw bool) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var body string
|
var body []byte
|
||||||
if strings.HasPrefix(strings.ToLower(mimeType), "text/") {
|
if strings.HasPrefix(strings.ToLower(mimeType), "text/") {
|
||||||
b, err := ioutil.ReadAll(part.Body)
|
body, err = ioutil.ReadAll(part.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to read part body: %v", err)
|
return fmt.Errorf("failed to read part body: %v", err)
|
||||||
}
|
}
|
||||||
body = string(b)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isHTML := false
|
isHTML := false
|
||||||
|
@ -263,7 +262,7 @@ func handleGetPart(ctx *koushin.Context, raw bool) error {
|
||||||
Mailboxes: mailboxes,
|
Mailboxes: mailboxes,
|
||||||
Mailbox: mbox,
|
Mailbox: mbox,
|
||||||
Message: msg,
|
Message: msg,
|
||||||
Body: body,
|
Body: string(body),
|
||||||
IsHTML: isHTML,
|
IsHTML: isHTML,
|
||||||
PartPath: partPathString,
|
PartPath: partPathString,
|
||||||
MailboxPage: int(mbox.Messages-msg.SeqNum) / messagesPerPage,
|
MailboxPage: int(mbox.Messages-msg.SeqNum) / messagesPerPage,
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"github.com/microcosm-cc/bluemonday"
|
"github.com/microcosm-cc/bluemonday"
|
||||||
)
|
)
|
||||||
|
|
||||||
func sanitizeHTML(b string) string {
|
func sanitizeHTML(b []byte) []byte {
|
||||||
p := bluemonday.UGCPolicy()
|
p := bluemonday.UGCPolicy()
|
||||||
|
|
||||||
// TODO: be more strict
|
// TODO: be more strict
|
||||||
|
@ -14,5 +14,5 @@ func sanitizeHTML(b string) string {
|
||||||
p.AddTargetBlankToFullyQualifiedLinks(true)
|
p.AddTargetBlankToFullyQualifiedLinks(true)
|
||||||
p.RequireNoFollowOnLinks(true)
|
p.RequireNoFollowOnLinks(true)
|
||||||
|
|
||||||
return p.Sanitize(b)
|
return p.SanitizeBytes(b)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue