about summary refs log tree commit diff stats
path: root/worker
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-03-31 12:35:51 -0400
committerDrew DeVault <sir@cmpwn.com>2019-03-31 12:35:51 -0400
commit0abafa60e159f87595148c0d0fc4f5f46be2d400 (patch)
tree1f6cc2059c1d9d712dd60e00146b7a7caa9b1c59 /worker
parent95875b13f829919b3453763628d1dda97371fab0 (diff)
downloadaerc-0abafa60e159f87595148c0d0fc4f5f46be2d400.tar.gz
Make message viewer real, part two
Diffstat (limited to 'worker')
-rw-r--r--worker/imap/fetch.go25
1 files changed, 14 insertions, 11 deletions
diff --git a/worker/imap/fetch.go b/worker/imap/fetch.go
index 89c0d99..af9d3b1 100644
--- a/worker/imap/fetch.go
+++ b/worker/imap/fetch.go
@@ -18,7 +18,7 @@ func (imapw *IMAPWorker) handleFetchMessageHeaders(
 		imap.FetchUid,
 	}
 
-	imapw.handleFetchMessages(msg, &msg.Uids, items)
+	imapw.handleFetchMessages(msg, &msg.Uids, items, nil)
 }
 
 func (imapw *IMAPWorker) handleFetchMessageBodyPart(
@@ -26,11 +26,11 @@ func (imapw *IMAPWorker) handleFetchMessageBodyPart(
 
 	imapw.worker.Logger.Printf("Fetching message part")
 	section := &imap.BodySectionName{}
-	section.Path = []int{msg.Part}
+	section.Path = []int{msg.Part + 1}
 	items := []imap.FetchItem{section.FetchItem()}
 	uids := imap.SeqSet{}
 	uids.AddNum(msg.Uid)
-	imapw.handleFetchMessages(msg, &uids, items)
+	imapw.handleFetchMessages(msg, &uids, items, section)
 }
 
 func (imapw *IMAPWorker) handleFetchFullMessages(
@@ -39,11 +39,12 @@ func (imapw *IMAPWorker) handleFetchFullMessages(
 	imapw.worker.Logger.Printf("Fetching full messages")
 	section := &imap.BodySectionName{}
 	items := []imap.FetchItem{section.FetchItem()}
-	imapw.handleFetchMessages(msg, &msg.Uids, items)
+	imapw.handleFetchMessages(msg, &msg.Uids, items, section)
 }
 
 func (imapw *IMAPWorker) handleFetchMessages(
-	msg types.WorkerMessage, uids *imap.SeqSet, items []imap.FetchItem) {
+	msg types.WorkerMessage, uids *imap.SeqSet, items []imap.FetchItem,
+	section *imap.BodySectionName) {
 
 	go func() {
 		messages := make(chan *imap.Message)
@@ -52,12 +53,12 @@ func (imapw *IMAPWorker) handleFetchMessages(
 			done <- imapw.client.UidFetch(uids, items, messages)
 		}()
 		go func() {
-			section := &imap.BodySectionName{}
 			for _msg := range messages {
 				imapw.seqMap[_msg.SeqNum-1] = _msg.Uid
 				switch msg.(type) {
 				case *types.FetchMessageHeaders:
 					imapw.worker.PostMessage(&types.MessageInfo{
+						Message:       types.RespondTo(msg),
 						BodyStructure: _msg.BodyStructure,
 						Envelope:      _msg.Envelope,
 						Flags:         _msg.Flags,
@@ -66,15 +67,17 @@ func (imapw *IMAPWorker) handleFetchMessages(
 					}, nil)
 				case *types.FetchFullMessages:
 					reader := _msg.GetBody(section)
-					imapw.worker.PostMessage(&types.MessageBody{
-						Reader: reader,
-						Uid:    _msg.Uid,
+					imapw.worker.PostMessage(&types.FullMessage{
+						Message: types.RespondTo(msg),
+						Reader:  reader,
+						Uid:     _msg.Uid,
 					}, nil)
 				case *types.FetchMessageBodyPart:
 					reader := _msg.GetBody(section)
 					imapw.worker.PostMessage(&types.MessageBodyPart{
-						Reader: reader,
-						Uid:    _msg.Uid,
+						Message: types.RespondTo(msg),
+						Reader:  reader,
+						Uid:     _msg.Uid,
 					}, nil)
 				}
 			}