summary refs log tree commit diff stats
path: root/python/code/1/1.txt
blob: 827a09a47f4d0b2b1cd368cf1cc0dc0f995d311a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
gt;  2019-03-10 23:45:00 -0400

Fetch valid UIDs from server after opening dir' href='/akspecs/aerc/commit/worker/imap/open.go?h=0.1.0&id=b3896476a0e6978c0d7f6fedfb64588934a78f1e'>b389647 ^

1
2
3
4
5
6
7
8
9
10


            

                                     




                                                                        









                                                                                
 





                                                       


















                                                                                
 
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)

	_, 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")

	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)
	}
}