aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Culverhouse <tim@timculverhouse.com>2023-06-20 11:07:12 -0500
committerRobin Jarry <robin@jarry.cc>2023-06-20 23:16:25 +0200
commitb4ae11b4ec20b61a18e1ce08ea65014bcebc2f16 (patch)
treed727e73704e49e797404cc2469bff1071cfb1bdb
parent08a0b5cbe56a8b64759282132e3dc304d24e4e7a (diff)
downloadaerc-b4ae11b4ec20b61a18e1ce08ea65014bcebc2f16.tar.gz
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 <tim@timculverhouse.com> Tested-by: Bence Ferdinandy <bence@ferdinandy.com> Acked-by: Robin Jarry <robin@jarry.cc>
-rw-r--r--worker/imap/fetch.go12
-rw-r--r--worker/imap/list.go14
2 files changed, 26 insertions, 0 deletions
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{
diff --git a/worker/imap/list.go b/worker/imap/list.go
index a3469c72..fc1d7e94 100644
--- a/worker/imap/list.go
+++ b/worker/imap/list.go
@@ -121,12 +121,26 @@ func (imapw *IMAPWorker) handleSearchDirectory(msg *types.SearchDirectory) {
return
}
+ if msg.Context.Err() != nil {
+ imapw.worker.PostMessage(&types.Cancelled{
+ Message: types.RespondTo(msg),
+ }, nil)
+ return
+ }
+
uids, err := imapw.client.UidSearch(criteria)
if err != nil {
emitError(err)
return
}
+ if msg.Context.Err() != nil {
+ imapw.worker.PostMessage(&types.Cancelled{
+ Message: types.RespondTo(msg),
+ }, nil)
+ return
+ }
+
imapw.worker.PostMessage(&types.SearchResults{
Message: types.RespondTo(msg),
Uids: uids,