diff options
author | Yash Srivastav <yash111998@gmail.com> | 2019-06-07 13:56:14 +0530 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-06-07 09:20:24 -0400 |
commit | b83e7c9fa6a0d187a0f20d98d522cff792053cdd (patch) | |
tree | 4c3765b41d216e26406d21d3b045f340edabbadc /worker | |
parent | 2279ac3ab3d19cd233600907bc8e3e8b4e57b350 (diff) | |
download | aerc-b83e7c9fa6a0d187a0f20d98d522cff792053cdd.tar.gz |
implements ability to view headers in message view
Diffstat (limited to 'worker')
-rw-r--r-- | worker/imap/fetch.go | 21 | ||||
-rw-r--r-- | worker/types/messages.go | 2 |
2 files changed, 22 insertions, 1 deletions
diff --git a/worker/imap/fetch.go b/worker/imap/fetch.go index ac9d0096..49c9ac53 100644 --- a/worker/imap/fetch.go +++ b/worker/imap/fetch.go @@ -1,7 +1,12 @@ package imap import ( + "bufio" + "github.com/emersion/go-imap" + "github.com/emersion/go-message" + "github.com/emersion/go-message/mail" + "github.com/emersion/go-message/textproto" "git.sr.ht/~sircmpwn/aerc/worker/types" ) @@ -10,15 +15,22 @@ func (imapw *IMAPWorker) handleFetchMessageHeaders( msg *types.FetchMessageHeaders) { imapw.worker.Logger.Printf("Fetching message headers") + section := &imap.BodySectionName{ + BodyPartName: imap.BodyPartName{ + Specifier: imap.HeaderSpecifier, + }, + } + items := []imap.FetchItem{ imap.FetchBodyStructure, imap.FetchEnvelope, imap.FetchInternalDate, imap.FetchFlags, imap.FetchUid, + section.FetchItem(), } - imapw.handleFetchMessages(msg, &msg.Uids, items, nil) + imapw.handleFetchMessages(msg, &msg.Uids, items, section) } func (imapw *IMAPWorker) handleFetchMessageBodyPart( @@ -54,12 +66,19 @@ func (imapw *IMAPWorker) handleFetchMessages( imapw.seqMap[_msg.SeqNum-1] = _msg.Uid switch msg.(type) { case *types.FetchMessageHeaders: + reader := _msg.GetBody(section) + textprotoHeader, err := textproto.ReadHeader(bufio.NewReader(reader)) + var header *mail.Header + if err == nil { + header = &mail.Header{message.Header{textprotoHeader}} + } imapw.worker.PostMessage(&types.MessageInfo{ Message: types.RespondTo(msg), BodyStructure: _msg.BodyStructure, Envelope: _msg.Envelope, Flags: _msg.Flags, InternalDate: _msg.InternalDate, + RFC822Headers: header, Uid: _msg.Uid, }, nil) case *types.FetchFullMessages: diff --git a/worker/types/messages.go b/worker/types/messages.go index 4e46cbf4..29d3d9f7 100644 --- a/worker/types/messages.go +++ b/worker/types/messages.go @@ -5,6 +5,7 @@ import ( "time" "github.com/emersion/go-imap" + "github.com/emersion/go-message/mail" "git.sr.ht/~sircmpwn/aerc/config" ) @@ -145,6 +146,7 @@ type MessageInfo struct { Envelope *imap.Envelope Flags []string InternalDate time.Time + RFC822Headers *mail.Header Size uint32 Uid uint32 } |