From 490420726952bb3834e6a1cdda7a26c90ba9a7cb Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 23 Oct 2020 16:07:59 -0400 Subject: Replace parts tree with attachment list --- go.mod | 1 + go.sum | 2 ++ plugins/base/imap.go | 28 +++++++++++++++++++----- themes/alps/assets/style.css | 11 ++++++++-- themes/alps/message.html | 52 +++++++++++++++++++++----------------------- 5 files changed, 60 insertions(+), 34 deletions(-) diff --git a/go.mod b/go.mod index ea2b169..d784a48 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( git.sr.ht/~sircmpwn/dowork v0.0.0-20201013174036-53a05612a082 github.com/aymerick/douceur v0.2.0 github.com/chris-ramon/douceur v0.2.0 + github.com/dustin/go-humanize v1.0.0 github.com/emersion/go-ical v0.0.0-20200225233454-26ef720b8bf1 github.com/emersion/go-imap v1.0.4 github.com/emersion/go-imap-metadata v0.0.0-20200128185110-9d939d2a0915 diff --git a/go.sum b/go.sum index 3d180d4..12880bc 100644 --- a/go.sum +++ b/go.sum @@ -22,6 +22,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= +github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= +github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/emersion/go-ical v0.0.0-20200224201310-cd514449c39e h1:YGM1sI7edZOt8KAfX9Miq/X99d2QXdgjkJ7vN4HjxAA= github.com/emersion/go-ical v0.0.0-20200224201310-cd514449c39e/go.mod h1:4xVTBPcT43a1pp3vdaa+FuRdX5XhKCZPpWv7m0z9ByM= github.com/emersion/go-ical v0.0.0-20200225233454-26ef720b8bf1 h1:v0W797seT60q3pzrphQUKh22Nt8uS7rgZyD6lqYgM0E= diff --git a/plugins/base/imap.go b/plugins/base/imap.go index 07b69c7..f8065b0 100644 --- a/plugins/base/imap.go +++ b/plugins/base/imap.go @@ -10,11 +10,12 @@ import ( "strings" "time" + "github.com/dustin/go-humanize" "github.com/emersion/go-imap" - imapspecialuse "github.com/emersion/go-imap-specialuse" - imapclient "github.com/emersion/go-imap/client" "github.com/emersion/go-message" "github.com/emersion/go-message/textproto" + imapclient "github.com/emersion/go-imap/client" + imapspecialuse "github.com/emersion/go-imap-specialuse" ) type MailboxInfo struct { @@ -177,6 +178,7 @@ func newIMAPPartNode(msg *IMAPMessage, path []int, part *imap.BodyStructure) *IM MIMEType: strings.ToLower(part.MIMEType + "/" + part.MIMESubType), Filename: filename, Message: msg, + Size: part.Size, } } @@ -301,6 +303,7 @@ type IMAPPartNode struct { Filename string Children []IMAPPartNode Message *IMAPMessage + Size uint32 } func (node IMAPPartNode) PathString() string { @@ -308,10 +311,13 @@ func (node IMAPPartNode) PathString() string { for i, partNum := range node.Path { l[i] = strconv.Itoa(partNum) } - return strings.Join(l, ".") } +func (node IMAPPartNode) SizeString() string { + return humanize.IBytes(uint64(node.Size)) +} + func (node IMAPPartNode) URL(raw bool) *url.URL { u := node.Message.URL() if raw { @@ -348,6 +354,7 @@ func imapPartTree(msg *IMAPMessage, bs *imap.BodyStructure, path []int) *IMAPPar Filename: filename, Children: make([]IMAPPartNode, len(bs.Parts)), Message: msg, + Size: bs.Size, } for i, part := range bs.Parts { @@ -396,7 +403,12 @@ func listMessages(conn *imapclient.Client, mbox *MailboxStatus, page, messagesPe var seqSet imap.SeqSet seqSet.AddRange(uint32(from), uint32(to)) - fetch := []imap.FetchItem{imap.FetchFlags, imap.FetchEnvelope, imap.FetchUid, imap.FetchBodyStructure} + fetch := []imap.FetchItem{ + imap.FetchFlags, + imap.FetchEnvelope, + imap.FetchUid, + imap.FetchBodyStructure, + } ch := make(chan *imap.Message, 10) done := make(chan error, 1) @@ -452,7 +464,12 @@ func searchMessages(conn *imapclient.Client, mboxName, query string, page, messa var seqSet imap.SeqSet seqSet.AddNum(nums...) - fetch := []imap.FetchItem{imap.FetchEnvelope, imap.FetchFlags, imap.FetchUid, imap.FetchBodyStructure} + fetch := []imap.FetchItem{ + imap.FetchEnvelope, + imap.FetchFlags, + imap.FetchUid, + imap.FetchBodyStructure, + } ch := make(chan *imap.Message, 10) done := make(chan error, 1) @@ -506,6 +523,7 @@ func getMessagePart(conn *imapclient.Client, mboxName string, uid uint32, partPa imap.FetchUid, imap.FetchBodyStructure, imap.FetchFlags, + imap.FetchRFC822Size, partHeaderSection.FetchItem(), partBodySection.FetchItem(), } diff --git a/themes/alps/assets/style.css b/themes/alps/assets/style.css index 91435e0..77aaf3c 100644 --- a/themes/alps/assets/style.css +++ b/themes/alps/assets/style.css @@ -261,14 +261,21 @@ main.message .message-header { } main.message .message-header .parts { + width: 30%; margin-left: 0.3rem; - padding: 0.3rem 1rem; + padding: 0.3rem 0.5rem; background: white; border-top: 1px solid #f2f2f2; } main.message .message-header .parts ul { - margin-left: 1rem; + margin: 0; + padding: 0; + list-style: none; +} + +main.message .message-header .parts li { + margin-left: 0; } main.contact dl { diff --git a/themes/alps/message.html b/themes/alps/message.html index 74e2d0b..28287ab 100644 --- a/themes/alps/message.html +++ b/themes/alps/message.html @@ -2,32 +2,6 @@ {{template "nav.html" .}} {{template "util.html" .}} -{{define "message-part-tree"}} - {{/* nested templates can't access the parent's context */}} - {{$ = index . 0}} - {{with index . 1}} - - {{if eq $.Part.PathString .PathString}}{{end}} - {{.String}} - {{if eq $.Part.PathString .PathString}}{{end}} - - {{if gt (len .Children) 0}} - - {{end}} - {{end}} -{{end}} -
{{ $current := .Mailbox }} {{ template "aside" . }} @@ -162,9 +136,32 @@ {{end}} + {{ $attachments := .Message.Attachments }} + {{ if $attachments }}
- {{template "message-part-tree" (tuple $ .Message.PartTree)}} +

Attachments

+
+ {{ end }}
{{define "addr-list"}} @@ -197,6 +194,7 @@ {{ end }} Raw email + {{if .View}} {{.View}} {{else}} -- cgit v1.2.3