diff options
author | Drew DeVault <sir@cmpwn.com> | 2020-10-23 16:07:59 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2020-10-23 16:08:40 -0400 |
commit | 490420726952bb3834e6a1cdda7a26c90ba9a7cb (patch) | |
tree | 75ab8141411e9275eae29c4c858d7ca799f18416 /plugins | |
parent | 09d19169dae66c3ddfa3644090475b5cfd553684 (diff) | |
download | alps-490420726952bb3834e6a1cdda7a26c90ba9a7cb.tar.gz alps-490420726952bb3834e6a1cdda7a26c90ba9a7cb.zip |
Replace parts tree with attachment list
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/base/imap.go | 28 |
1 files changed, 23 insertions, 5 deletions
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(), } |