summary refs log blame commit diff stats
path: root/worker/imap/open.go
blob: 3705bc0d1034c55dc9188e5f8b6df4517c5fa0f0 (plain) (tree)
1
2
3
4
5


            

                                     
















                                                                                        








                                                           
                                                                         







                                                              
                                                                              
                                                                







                                                                                        
package imap

import (
	"github.com/emersion/go-imap"

	"git.sr.ht/~sircmpwn/aerc2/worker/types"
)

func (imapw *IMAPWorker) handleOpenDirectory(msg *types.OpenDirectory) {
	imapw.worker.Logger.Printf("Opening %s", msg.Directory)
	go func() {
		_, err := imapw.client.Select(msg.Directory, false)
		if err != nil {
			imapw.worker.PostMessage(&types.Error{
				Message: types.RespondTo(msg),
				Error:   err,
			}, nil)
		} else {
			imapw.worker.PostMessage(&types.Done{types.RespondTo(msg)}, nil)
		}
	}()
}

func (imapw *IMAPWorker) handleFetchDirectoryContents(
	msg *types.FetchDirectoryContents) {

	imapw.worker.Logger.Printf("Fetching UID list")

	go func() {
		seqSet := &imap.SeqSet{}
		seqSet.AddRange(1, imapw.selected.Messages)
		uids, err := imapw.client.UidSearch(&imap.SearchCriteria{
			SeqNum: seqSet,
		})
		if err != nil {
			imapw.worker.PostMessage(&types.Error{
				Message: types.RespondTo(msg),
				Error:   err,
			}, nil)
		} else {
			imapw.worker.Logger.Printf("Found %d UIDs", len(uids))
			imapw.seqMap = make([]uint32, len(uids))
			imapw.worker.PostMessage(&types.DirectoryContents{
				Message: types.RespondTo(msg),
				Uids:    uids,
			}, nil)
			imapw.worker.PostMessage(&types.Done{types.RespondTo(msg)}, nil)
		}
	}()
}