From 0e9c411751c752eeef4e2132f778308689001388 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 24 Jun 2019 16:29:13 -0400 Subject: worker/imap: implement search --- worker/imap/list.go | 16 ++++++++++++++++ worker/types/messages.go | 10 ++++++++++ 2 files changed, 26 insertions(+) diff --git a/worker/imap/list.go b/worker/imap/list.go index a61ea06d..b9578ab0 100644 --- a/worker/imap/list.go +++ b/worker/imap/list.go @@ -60,3 +60,19 @@ func canOpen(mbox *imap.MailboxInfo) bool { } return true } + +func (imapw *IMAPWorker) handleSearchDirectory(msg *types.SearchDirectory) { + imapw.worker.Logger.Println("Executing search") + + if uids, err := imapw.client.UidSearch(msg.Criteria); err != nil { + imapw.worker.PostMessage(&types.Error{ + Message: types.RespondTo(msg), + Error: err, + }, nil) + } else { + imapw.worker.PostMessage(&types.SearchResults{ + Message: types.RespondTo(msg), + Uids: uids, + }, nil) + } +} diff --git a/worker/types/messages.go b/worker/types/messages.go index fa4b4e49..d9e911f1 100644 --- a/worker/types/messages.go +++ b/worker/types/messages.go @@ -82,6 +82,11 @@ type FetchDirectoryContents struct { Message } +type SearchDirectory struct { + Message + Criteria *imap.SearchCriteria +} + type CreateDirectory struct { Message Directory string @@ -152,6 +157,11 @@ type DirectoryContents struct { Uids []uint32 } +type SearchResults struct { + Message + Uids []uint32 +} + type MessageInfo struct { Message BodyStructure *imap.BodyStructure -- cgit