aboutsummaryrefslogtreecommitdiff
path: root/worker/imap
diff options
context:
space:
mode:
authorYash Srivastav <yash111998@gmail.com>2019-06-07 13:56:14 +0530
committerDrew DeVault <sir@cmpwn.com>2019-06-07 09:20:24 -0400
commitb83e7c9fa6a0d187a0f20d98d522cff792053cdd (patch)
tree4c3765b41d216e26406d21d3b045f340edabbadc /worker/imap
parent2279ac3ab3d19cd233600907bc8e3e8b4e57b350 (diff)
implements ability to view headers in message view
Diffstat (limited to 'worker/imap')
-rw-r--r--worker/imap/fetch.go21
1 files changed, 20 insertions, 1 deletions
diff --git a/worker/imap/fetch.go b/worker/imap/fetch.go
index ac9d009..49c9ac5 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: