From b4ae11b4ec20b61a18e1ce08ea65014bcebc2f16 Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Tue, 20 Jun 2023 11:07:12 -0500 Subject: imap: implement cancellation of searching and fetching Check for cancelled contexts before and after performing headers or flag fetches and any directory searching. Signed-off-by: Tim Culverhouse Tested-by: Bence Ferdinandy Acked-by: Robin Jarry --- worker/imap/fetch.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'worker/imap/fetch.go') diff --git a/worker/imap/fetch.go b/worker/imap/fetch.go index 74108135..0c923bf0 100644 --- a/worker/imap/fetch.go +++ b/worker/imap/fetch.go @@ -19,6 +19,12 @@ import ( func (imapw *IMAPWorker) handleFetchMessageHeaders( msg *types.FetchMessageHeaders, ) { + if msg.Context.Err() != nil { + imapw.worker.PostMessage(&types.Cancelled{ + Message: types.RespondTo(msg), + }, nil) + return + } toFetch := msg.Uids if imapw.config.cacheEnabled && imapw.cache != nil { toFetch = imapw.getCachedHeaders(msg) @@ -210,6 +216,12 @@ func (imapw *IMAPWorker) handleFetchMessageFlags(msg *types.FetchMessageFlags) { imap.FetchFlags, imap.FetchUid, } + if msg.Context.Err() != nil { + imapw.worker.PostMessage(&types.Cancelled{ + Message: types.RespondTo(msg), + }, nil) + return + } imapw.handleFetchMessages(msg, msg.Uids, items, func(_msg *imap.Message) error { imapw.worker.PostMessage(&types.MessageInfo{ -- cgit