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 --- plugins/base/imap.go | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'plugins/base') 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(), } -- cgit v1.2.3