From 9404be1a329fce746ac8c7376c889350da574ea8 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Tue, 17 Dec 2019 11:28:47 +0100 Subject: Add envelope metadata to message view --- plugins/base/plugin.go | 12 +----------- plugins/base/public/message.html | 22 ++++++++++++++++++++++ plugins/base/template.go | 29 +++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 11 deletions(-) create mode 100644 plugins/base/template.go diff --git a/plugins/base/plugin.go b/plugins/base/plugin.go index 1cee571..3673885 100644 --- a/plugins/base/plugin.go +++ b/plugins/base/plugin.go @@ -1,9 +1,6 @@ package koushinbase import ( - "html/template" - "net/url" - "git.sr.ht/~emersion/koushin" "github.com/labstack/echo/v4" ) @@ -13,14 +10,7 @@ const messagesPerPage = 50 func init() { p := koushin.GoPlugin{Name: "base"} - p.TemplateFuncs(template.FuncMap{ - "tuple": func(values ...interface{}) []interface{} { - return values - }, - "pathescape": func(s string) string { - return url.PathEscape(s) - }, - }) + p.TemplateFuncs(templateFuncs) p.GET("/mailbox/:mbox", handleGetMailbox) p.POST("/mailbox/:mbox", handleGetMailbox) diff --git a/plugins/base/public/message.html b/plugins/base/public/message.html index 11afa73..0b7a8d5 100644 --- a/plugins/base/public/message.html +++ b/plugins/base/public/message.html @@ -30,6 +30,28 @@ + + {{define "message-part-tree"}} {{/* nested templates can't access the parent's context */}} {{$ = index . 0}} diff --git a/plugins/base/template.go b/plugins/base/template.go new file mode 100644 index 0000000..84c4e21 --- /dev/null +++ b/plugins/base/template.go @@ -0,0 +1,29 @@ +package koushinbase + +import ( + "html/template" + "net/url" + "strings" + "time" + + "github.com/emersion/go-imap" +) + +var templateFuncs = template.FuncMap{ + "tuple": func(values ...interface{}) []interface{} { + return values + }, + "pathescape": func(s string) string { + return url.PathEscape(s) + }, + "formataddrlist": func(addrs []*imap.Address) string { + l := make([]string, len(addrs)) + for i, addr := range addrs { + l[i] = addr.PersonalName + " <" + addr.Address() + ">" + } + return strings.Join(l, ", ") + }, + "formatdate": func(t time.Time) string { + return t.Format("Mon Jan 02 15:04") + }, +} -- cgit v1.2.3