From 5825a749c1fa0382e8c5f5973bc09fd8a58705f4 Mon Sep 17 00:00:00 2001 From: Robert Stepanek Date: Tue, 27 Jun 2023 14:39:02 +0200 Subject: [PATCH] jmap_calendar: return unsupportedFilter for too large SQL queries Signed-off-by: Robert Stepanek --- imap/jmap_calendar.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/imap/jmap_calendar.c b/imap/jmap_calendar.c index 631c738b4d3..25dc9662248 100644 --- a/imap/jmap_calendar.c +++ b/imap/jmap_calendar.c @@ -7119,7 +7119,7 @@ static int eventquery_run(jmap_req_t *req, { time_t before = caldav_eternity; time_t after = caldav_epoch; - int r = HTTP_NOT_IMPLEMENTED; + int r = 0, r_db = 0; enum caldav_sort *sort = NULL; struct buf buf = BUF_INITIALIZER; size_t nsort = 0; @@ -7176,7 +7176,7 @@ static int eventquery_run(jmap_req_t *req, struct eventquery_fastpath_rock rock = { req, query, is_sharee, BUF_INITIALIZER }; - r = caldav_foreach_jscal(db, req->userid, jscal_filter, NULL, + r_db = caldav_foreach_jscal(db, req->userid, jscal_filter, NULL, sort, nsort, eventquery_fastpath_cb, &rock); buf_free(&rock.buf); is_fastpath = 1; @@ -7197,11 +7197,12 @@ static int eventquery_run(jmap_req_t *req, }; enum caldav_sort mboxsort = CAL_SORT_MAILBOX; - r = caldav_foreach_jscal(db, req->userid, jscal_filter, NULL, + r_db = caldav_foreach_jscal(db, req->userid, jscal_filter, NULL, args.expandrecur ? &mboxsort : sort, args.expandrecur ? 1 : nsort, eventquery_cb, &rock); jmap_closembox(req, &rock.mailbox); + if (r_db) goto done; } if (args.expandrecur) { @@ -7311,6 +7312,12 @@ static int eventquery_run(jmap_req_t *req, eventquery_match_free(&match); } } + if (r_db == SQLDB_ERR_LIMIT && !*err) { + *err = json_pack("{s:s}", "type", "unsupportedFilter"); + } + else if (r_db) { + r = HTTP_SERVER_ERROR; + } ptrarray_fini(&matches); caldav_jscal_filter_fini(jscal_filter); free(jscal_filter);