diff options
author | Simon Ser <contact@emersion.fr> | 2020-02-12 14:42:51 +0100 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2020-02-12 15:41:00 +0100 |
commit | 8299617ebc24a4a5bd1dc03070e17713be7e1e1b (patch) | |
tree | 6f63bf506717b7348f625169885c68bd2c82a23e /plugins/base/routes.go | |
parent | 892f1fa581d853f0bc5e83f8b2e66169921330a2 (diff) | |
download | alps-8299617ebc24a4a5bd1dc03070e17713be7e1e1b.tar.gz alps-8299617ebc24a4a5bd1dc03070e17713be7e1e1b.zip |
Turn message part viewers into plugins
Diffstat (limited to 'plugins/base/routes.go')
-rw-r--r-- | plugins/base/routes.go | 24 |
1 files changed, 5 insertions, 19 deletions
diff --git a/plugins/base/routes.go b/plugins/base/routes.go index ec22d1b..ad4d121 100644 --- a/plugins/base/routes.go +++ b/plugins/base/routes.go @@ -176,8 +176,7 @@ type MessageRenderData struct { Mailboxes []*imap.MailboxInfo Mailbox *imap.MailboxStatus Message *IMAPMessage - Body string - IsHTML bool + View interface{} PartPath string MailboxPage int Flags map[string]bool @@ -255,21 +254,9 @@ func handleGetPart(ctx *koushin.Context, raw bool) error { } } - var body []byte - if strings.HasPrefix(strings.ToLower(mimeType), "text/") { - body, err = ioutil.ReadAll(part.Body) - if err != nil { - return fmt.Errorf("failed to read part body: %v", err) - } - } - - isHTML := false - if strings.EqualFold(mimeType, "text/html") { - body, err = sanitizeHTML(body) - if err != nil { - return fmt.Errorf("failed to sanitize HTML part: %v", err) - } - isHTML = true + view, err := viewMessagePart(ctx, msg, part) + if err == ErrViewUnsupported { + view = nil } flags := make(map[string]bool) @@ -286,8 +273,7 @@ func handleGetPart(ctx *koushin.Context, raw bool) error { Mailboxes: mailboxes, Mailbox: mbox, Message: msg, - Body: string(body), - IsHTML: isHTML, + View: view, PartPath: partPathString, MailboxPage: int(mbox.Messages-msg.SeqNum) / messagesPerPage, Flags: flags, |