Add envelope metadata to message view

This commit is contained in:
Simon Ser 2019-12-17 11:28:47 +01:00
parent e78d2db3ea
commit 9404be1a32
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
3 changed files with 52 additions and 11 deletions

View file

@ -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)

View file

@ -30,6 +30,28 @@
<input type="submit" value="Delete">
</form>
<ul>
<li>
<strong>Date</strong>: {{.Message.Envelope.Date | formatdate}}
</li>
<li>
<strong>From</strong>: {{.Message.Envelope.From | formataddrlist}}
</li>
<li>
<strong>To</strong>: {{.Message.Envelope.To | formataddrlist}}
</li>
{{if .Message.Envelope.Cc}}
<li>
<strong>Cc</strong>: {{.Message.Envelope.Cc | formataddrlist}}
</li>
{{end}}
{{if .Message.Envelope.Bcc}}
<li>
<strong>Bcc</strong>: {{.Message.Envelope.Bcc | formataddrlist}}
</li>
{{end}}
</ul>
{{define "message-part-tree"}}
{{/* nested templates can't access the parent's context */}}
{{$ = index . 0}}

29
plugins/base/template.go Normal file
View file

@ -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")
},
}