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:14:37 -0400
committerDrew DeVault <sir@cmpwn.com>2019-03-31 12:14:37 -0400
commit27b25174e2f0249a6a1d4ba45b70f8504b63ffb1 (patch)
treeb8626c746e07d9a38f95a5a817a7094c9275bfd1 /worker
parent143289bbd0736d72553a3c2a080aa3d125366b38 (diff)
downloadaerc-27b25174e2f0249a6a1d4ba45b70f8504b63ffb1.tar.gz
Make the message viewer real, part one
Diffstat (limited to 'worker')
-rw-r--r--worker/imap/fetch.go32
-rw-r--r--worker/imap/worker.go2
2 files changed, 28 insertions, 6 deletions
diff --git a/worker/imap/fetch.go b/worker/imap/fetch.go
index 8052e13..feae462 100644
--- a/worker/imap/fetch.go
+++ b/worker/imap/fetch.go
@@ -30,6 +30,18 @@ func (imapw *IMAPWorker) handleFetchMessageBodies(
 	imapw.handleFetchMessages(msg, &msg.Uids, items)
 }
 
+func (imapw *IMAPWorker) handleFetchMessageBodyPart(
+	msg *types.FetchMessageBodyPart) {
+
+	imapw.worker.Logger.Printf("Fetching message part")
+	section := &imap.BodySectionName{}
+	section.Path = []int{msg.Part}
+	items := []imap.FetchItem{section.FetchItem()}
+	uids := imap.SeqSet{}
+	uids.AddNum(msg.Uid)
+	imapw.handleFetchMessages(msg, &uids, items)
+}
+
 func (imapw *IMAPWorker) handleFetchMessages(
 	msg types.WorkerMessage, uids *imap.SeqSet, items []imap.FetchItem) {
 
@@ -43,12 +55,8 @@ func (imapw *IMAPWorker) handleFetchMessages(
 			section := &imap.BodySectionName{}
 			for _msg := range messages {
 				imapw.seqMap[_msg.SeqNum-1] = _msg.Uid
-				if reader := _msg.GetBody(section); reader != nil {
-					imapw.worker.PostMessage(&types.MessageBody{
-						Reader: reader,
-						Uid:    _msg.Uid,
-					}, nil)
-				} else {
+				switch msg.(type) {
+				case *types.FetchMessageHeaders:
 					imapw.worker.PostMessage(&types.MessageInfo{
 						BodyStructure: _msg.BodyStructure,
 						Envelope:      _msg.Envelope,
@@ -56,6 +64,18 @@ func (imapw *IMAPWorker) handleFetchMessages(
 						InternalDate:  _msg.InternalDate,
 						Uid:           _msg.Uid,
 					}, nil)
+				case *types.FetchMessageBodies:
+					reader := _msg.GetBody(section)
+					imapw.worker.PostMessage(&types.MessageBody{
+						Reader: reader,
+						Uid:    _msg.Uid,
+					}, nil)
+				case *types.FetchMessageBodyPart:
+					reader := _msg.GetBody(section)
+					imapw.worker.PostMessage(&types.MessageBodyPart{
+						Reader: reader,
+						Uid:    _msg.Uid,
+					}, nil)
 				}
 			}
 			if err := <-done; err != nil {
diff --git a/worker/imap/worker.go b/worker/imap/worker.go
index 2f98595..a11d82b 100644
--- a/worker/imap/worker.go
+++ b/worker/imap/worker.go
@@ -160,6 +160,8 @@ func (w *IMAPWorker) handleMessage(msg types.WorkerMessage) error {
 		w.handleFetchMessageHeaders(msg)
 	case *types.FetchMessageBodies:
 		w.handleFetchMessageBodies(msg)
+	case *types.FetchMessageBodyPart:
+		w.handleFetchMessageBodyPart(msg)
 	case *types.DeleteMessages:
 		w.handleDeleteMessages(msg)
 	default: