From: Timo Sirainen Date: Tue, 17 Nov 2009 23:34:29 +0000 (-0500) Subject: mailbox_search_next*() API changed to return bool. X-Git-Tag: 2.0.beta1~132 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f3bb2fbe87425dc89a839908985af496f7f65702;p=thirdparty%2Fdovecot%2Fcore.git mailbox_search_next*() API changed to return bool. If search fails, it'll be noticed anyway by mailbox_search_deinit(). --HG-- branch : HEAD --- diff --git a/src/dsync/dsync-worker-local.c b/src/dsync/dsync-worker-local.c index 7487192858..55effc19eb 100644 --- a/src/dsync/dsync-worker-local.c +++ b/src/dsync/dsync-worker-local.c @@ -793,8 +793,7 @@ local_worker_msg_iter_next(struct dsync_worker_msg_iter *_iter, return -1; prev_uid = iter->mail->uid; - switch (mailbox_search_next(iter->search_ctx, iter->mail)) { - case 0: + if (!mailbox_search_next(iter->search_ctx, iter->mail)) { if (iter_local_mailbox_next_expunge(iter, prev_uid, msg_r)) { *mailbox_idx_r = iter->mailbox_idx; return 1; @@ -804,10 +803,6 @@ local_worker_msg_iter_next(struct dsync_worker_msg_iter *_iter, if (iter_local_mailbox_open(iter) < 0) return -1; return local_worker_msg_iter_next(_iter, mailbox_idx_r, msg_r); - case -1: - return -1; - default: - break; } *mailbox_idx_r = iter->mailbox_idx; diff --git a/src/imap/cmd-copy.c b/src/imap/cmd-copy.c index f37ed3c9da..0756a397d2 100644 --- a/src/imap/cmd-copy.c +++ b/src/imap/cmd-copy.c @@ -52,7 +52,7 @@ static int fetch_and_copy(struct client *client, mail = mail_alloc(src_trans, MAIL_FETCH_STREAM_HEADER | MAIL_FETCH_STREAM_BODY, NULL); ret = 1; - while (mailbox_search_next(search_ctx, mail) > 0 && ret > 0) { + while (mailbox_search_next(search_ctx, mail) && ret > 0) { if (mail->expunged) { ret = 0; break; diff --git a/src/imap/cmd-store.c b/src/imap/cmd-store.c index 20a5caa3b7..bfc97299b0 100644 --- a/src/imap/cmd-store.c +++ b/src/imap/cmd-store.c @@ -178,7 +178,7 @@ bool cmd_store(struct client_command_context *cmd) } mail = mail_alloc(t, MAIL_FETCH_FLAGS, NULL); - while (mailbox_search_next(search_ctx, mail) > 0) { + while (mailbox_search_next(search_ctx, mail)) { if (ctx.max_modseq < (uint64_t)-1) { /* check early so there's less work for transaction commit if something has to be cancelled */ diff --git a/src/imap/imap-expunge.c b/src/imap/imap-expunge.c index e31be4adc8..6812b08dbf 100644 --- a/src/imap/imap-expunge.c +++ b/src/imap/imap-expunge.c @@ -31,7 +31,7 @@ int imap_expunge(struct mailbox *box, struct mail_search_arg *next_search_arg) mail_search_args_unref(&search_args); mail = mail_alloc(t, 0, NULL); - while (mailbox_search_next(ctx, mail) > 0) { + while (mailbox_search_next(ctx, mail)) { mail_expunge(mail); expunges = TRUE; } diff --git a/src/imap/imap-fetch.c b/src/imap/imap-fetch.c index cc4c8c9591..19e8b79839 100644 --- a/src/imap/imap-fetch.c +++ b/src/imap/imap-fetch.c @@ -199,7 +199,7 @@ static int get_expunges_fallback(struct imap_fetch_context *ctx, search_ctx = mailbox_search_init(trans, search_args, NULL); mail_search_args_unref(&search_args); - while (mailbox_search_next(search_ctx, mail) > 0) { + while (mailbox_search_next(search_ctx, mail)) { if (mail->uid == next_uid) { if (next_uid < uid_filter[i].seq2) next_uid++; @@ -442,8 +442,7 @@ static int imap_fetch_more_int(struct imap_fetch_context *ctx) if (ctx->cmd->cancel) return 1; - if (mailbox_search_next(ctx->search_ctx, - ctx->mail) <= 0) + if (!mailbox_search_next(ctx->search_ctx, ctx->mail)) break; ctx->cur_mail = ctx->mail; diff --git a/src/imap/imap-search.c b/src/imap/imap-search.c index 63ab9ccde9..5d95ab8e9a 100644 --- a/src/imap/imap-search.c +++ b/src/imap/imap-search.c @@ -347,7 +347,7 @@ static bool cmd_search_more(struct client_command_context *cmd) (opts & ~(SEARCH_RETURN_NORESULTS | SEARCH_RETURN_MIN | SEARCH_RETURN_MAX)) == 0; while (mailbox_search_next_nonblock(ctx->search_ctx, ctx->mail, - &tryagain) > 0) { + &tryagain)) { id = cmd->uid ? ctx->mail->uid : ctx->mail->seq; ctx->result_count++; diff --git a/src/lib-storage/index/index-search-result.c b/src/lib-storage/index/index-search-result.c index c5a12a3065..32db0cfc2c 100644 --- a/src/lib-storage/index/index-search-result.c +++ b/src/lib-storage/index/index-search-result.c @@ -75,7 +75,7 @@ search_result_update_search(struct mail_search_result *result, search_ctx->update_result = result; mail = mail_alloc(t, 0, NULL); - while (mailbox_search_next(search_ctx, mail) > 0) { + while (mailbox_search_next(search_ctx, mail)) { i_assert(next_uid != 0); if (next_uid != mail->uid) { @@ -168,7 +168,7 @@ int index_search_result_update_appends(struct mail_search_result *result, search_ctx = mailbox_search_init(t, result->search_args, NULL); mail = mail_alloc(t, 0, NULL); - while (mailbox_search_next(search_ctx, mail) > 0) + while (mailbox_search_next(search_ctx, mail)) mailbox_search_result_add(result, mail->uid); mail_free(&mail); diff --git a/src/lib-storage/index/index-search.c b/src/lib-storage/index/index-search.c index 5d849bfdbf..50a0fe639f 100644 --- a/src/lib-storage/index/index-search.c +++ b/src/lib-storage/index/index-search.c @@ -1257,8 +1257,8 @@ static bool search_would_block(struct index_search_context *ctx) return ret; } -int index_storage_search_next_nonblock(struct mail_search_context *_ctx, - struct mail *mail, bool *tryagain_r) +bool index_storage_search_next_nonblock(struct mail_search_context *_ctx, + struct mail *mail, bool *tryagain_r) { struct index_search_context *ctx = (struct index_search_context *)_ctx; struct mailbox *box = _ctx->transaction->box; @@ -1272,15 +1272,15 @@ int index_storage_search_next_nonblock(struct mail_search_context *_ctx, /* everything searched at this point already. just returning matches from sort list */ if (!index_sort_list_next(ctx->mail_ctx.sort_program, mail)) - return 0; - return 1; + return FALSE; + return TRUE; } if (search_would_block(ctx)) { /* this lookup is useful when a large number of messages match */ *tryagain_r = TRUE; - return 0; + return FALSE; } ctx->mail = mail; @@ -1343,8 +1343,7 @@ int index_storage_search_next_nonblock(struct mail_search_context *_ctx, return index_storage_search_next_nonblock(_ctx, mail, tryagain_r); } - - return ctx->failed ? -1 : (match ? 1 : 0); + return !ctx->failed && match; } bool index_storage_search_next_update_seq(struct mail_search_context *_ctx) diff --git a/src/lib-storage/index/index-storage.h b/src/lib-storage/index/index-storage.h index 253df2e4a1..8a6a72e0ac 100644 --- a/src/lib-storage/index/index-storage.h +++ b/src/lib-storage/index/index-storage.h @@ -148,10 +148,8 @@ index_storage_search_init(struct mailbox_transaction_context *t, struct mail_search_args *args, const enum mail_sort_type *sort_program); int index_storage_search_deinit(struct mail_search_context *ctx); -int index_storage_search_next(struct mail_search_context *ctx, - struct mail *mail); -int index_storage_search_next_nonblock(struct mail_search_context *ctx, - struct mail *mail, bool *tryagain_r); +bool index_storage_search_next_nonblock(struct mail_search_context *ctx, + struct mail *mail, bool *tryagain_r); bool index_storage_search_next_update_seq(struct mail_search_context *ctx); void index_transaction_set_max_modseq(struct mailbox_transaction_context *_t, diff --git a/src/lib-storage/index/index-thread.c b/src/lib-storage/index/index-thread.c index 1549638fe5..6b9cb45a4e 100644 --- a/src/lib-storage/index/index-thread.c +++ b/src/lib-storage/index/index-thread.c @@ -340,7 +340,7 @@ static int mail_thread_index_map_build(struct mail_thread_context *ctx) mail = mail_alloc(ctx->t, 0, headers_ctx); mailbox_header_lookup_unref(&headers_ctx); - while (mailbox_search_next(search_ctx, mail) > 0) { + while (mailbox_search_next(search_ctx, mail)) { if (mail_thread_map_add_mail(ctx, mail) < 0) { ret = -1; break; @@ -533,7 +533,7 @@ static void mail_thread_cache_sync_add(struct mail_thread_mailbox *tbox, count - kind of kludgy) */ i_assert(msgid_map[count].uid == 0); i = 0; - while (i < count && mailbox_search_next(search_ctx, mail) > 0) { + while (i < count && mailbox_search_next(search_ctx, mail)) { while (msgid_map[i].uid < mail->uid) i++; i_assert(i < count); diff --git a/src/lib-storage/mail-storage-private.h b/src/lib-storage/mail-storage-private.h index b17111af3c..202bf6058c 100644 --- a/src/lib-storage/mail-storage-private.h +++ b/src/lib-storage/mail-storage-private.h @@ -189,8 +189,8 @@ struct mailbox_vfuncs { struct mail_search_args *args, const enum mail_sort_type *sort_program); int (*search_deinit)(struct mail_search_context *ctx); - int (*search_next_nonblock)(struct mail_search_context *ctx, - struct mail *mail, bool *tryagain_r); + bool (*search_next_nonblock)(struct mail_search_context *ctx, + struct mail *mail, bool *tryagain_r); /* Internal search function which updates ctx->seq */ bool (*search_next_update_seq)(struct mail_search_context *ctx); diff --git a/src/lib-storage/mail-storage.c b/src/lib-storage/mail-storage.c index b493dc7c13..b9dafb9deb 100644 --- a/src/lib-storage/mail-storage.c +++ b/src/lib-storage/mail-storage.c @@ -817,30 +817,28 @@ int mailbox_search_deinit(struct mail_search_context **_ctx) return ret; } -int mailbox_search_next(struct mail_search_context *ctx, struct mail *mail) +bool mailbox_search_next(struct mail_search_context *ctx, struct mail *mail) { bool tryagain; - int ret; - while ((ret = mailbox_search_next_nonblock(ctx, mail, - &tryagain)) == 0) { + while (!mailbox_search_next_nonblock(ctx, mail, &tryagain)) { if (!tryagain) - break; + return FALSE; } - - return ret; + return TRUE; } -int mailbox_search_next_nonblock(struct mail_search_context *ctx, - struct mail *mail, bool *tryagain_r) +bool mailbox_search_next_nonblock(struct mail_search_context *ctx, + struct mail *mail, bool *tryagain_r) { - int ret; + struct mailbox *box = ctx->transaction->box; - ret = ctx->transaction->box->v. - search_next_nonblock(ctx, mail, tryagain_r); - if (ret > 0) + if (!box->v.search_next_nonblock(ctx, mail, tryagain_r)) + return FALSE; + else { mailbox_search_results_add(ctx, mail->uid); - return ret; + return TRUE; + } } bool mailbox_search_seen_lost_data(struct mail_search_context *ctx) @@ -860,7 +858,7 @@ int mailbox_search_result_build(struct mailbox_transaction_context *t, ctx = mailbox_search_init(t, args, NULL); *result_r = mailbox_search_result_save(ctx, flags); mail = mail_alloc(t, 0, NULL); - while (mailbox_search_next(ctx, mail) > 0) ; + while (mailbox_search_next(ctx, mail)) ; mail_free(&mail); ret = mailbox_search_deinit(&ctx); diff --git a/src/lib-storage/mail-storage.h b/src/lib-storage/mail-storage.h index 3903581920..9862585301 100644 --- a/src/lib-storage/mail-storage.h +++ b/src/lib-storage/mail-storage.h @@ -491,12 +491,12 @@ mailbox_search_init(struct mailbox_transaction_context *t, const enum mail_sort_type *sort_program); /* Deinitialize search request. */ int mailbox_search_deinit(struct mail_search_context **ctx); -/* Search the next message. Returns 1 if found, 0 if not, -1 if failure. */ -int mailbox_search_next(struct mail_search_context *ctx, struct mail *mail); +/* Search the next message. Returns TRUE if found, FALSE if not. */ +bool mailbox_search_next(struct mail_search_context *ctx, struct mail *mail); /* Like mailbox_search_next(), but don't spend too much time searching. - Returns 1 if found, -1 if failure or 0 with tryagain_r=FALSE if - finished, and TRUE if more results will by calling the function again. */ -int mailbox_search_next_nonblock(struct mail_search_context *ctx, + Returns FALSE with tryagain_r=FALSE if finished, and tryagain_r=TRUE if + more results will be returned by calling the function again. */ +bool mailbox_search_next_nonblock(struct mail_search_context *ctx, struct mail *mail, bool *tryagain_r); /* Returns TRUE if some messages were already expunged and we couldn't determine correctly if those messages should have been returned in this diff --git a/src/lib-storage/test-mailbox.c b/src/lib-storage/test-mailbox.c index e037d72419..b367cb63d1 100644 --- a/src/lib-storage/test-mailbox.c +++ b/src/lib-storage/test-mailbox.c @@ -238,13 +238,13 @@ static int test_mailbox_search_deinit(struct mail_search_context *ctx) return 0; } -static int +static bool test_mailbox_search_next_nonblock(struct mail_search_context *ctx ATTR_UNUSED, struct mail *mail ATTR_UNUSED, bool *tryagain_r) { *tryagain_r = FALSE; - return 0; + return FALSE; } static bool diff --git a/src/plugins/convert/convert-storage.c b/src/plugins/convert/convert-storage.c index 4973073541..2f5849896f 100644 --- a/src/plugins/convert/convert-storage.c +++ b/src/plugins/convert/convert-storage.c @@ -59,7 +59,7 @@ static int mailbox_copy_mails(struct mailbox *srcbox, struct mailbox *destbox, MAIL_FETCH_FLAGS | MAIL_FETCH_RECEIVED_DATE | MAIL_FETCH_STREAM_HEADER | MAIL_FETCH_STREAM_BODY | MAIL_FETCH_FROM_ENVELOPE, NULL); - while (mailbox_search_next(ctx, mail) > 0) { + while (mailbox_search_next(ctx, mail)) { if ((mail->seq % 100) == 0) { /* touch the lock file so that if there are tons of mails another process won't override our lock. */ diff --git a/src/plugins/expire/expire-tool.c b/src/plugins/expire/expire-tool.c index 46c326d207..22c47b7321 100644 --- a/src/plugins/expire/expire-tool.c +++ b/src/plugins/expire/expire-tool.c @@ -133,8 +133,8 @@ mailbox_delete_old_mails(struct expire_context *ctx, const char *user, mail = mail_alloc(t, 0, NULL); - now = time(NULL); - while ((ret = mailbox_search_next(search_ctx, mail)) > 0) { + now = time(NULL); ret = 0; + while (mailbox_search_next(search_ctx, mail)) { if (mail_get_save_date(mail, &save_time) < 0) { /* maybe just got expunged. anyway try again later. */ if (ctx->testrun) { @@ -190,7 +190,7 @@ mailbox_delete_old_mails(struct expire_context *ctx, const char *user, ret = -1; mailbox_close(&box); - return ret < 0 ? -1 : 0; + return ret; } static void expire_run(struct master_service *service, bool testrun) diff --git a/src/plugins/fts-squat/fts-backend-squat.c b/src/plugins/fts-squat/fts-backend-squat.c index 48ebbdbb83..a18769366c 100644 --- a/src/plugins/fts-squat/fts-backend-squat.c +++ b/src/plugins/fts-squat/fts-backend-squat.c @@ -150,7 +150,7 @@ static int get_all_msg_uids(struct mailbox *box, ARRAY_TYPE(seq_range) *uids) struct mail_search_context *search_ctx; struct mail_search_args *search_args; struct mail *mail; - int ret = 0; + int ret; t = mailbox_transaction_begin(box, 0); mail = mail_alloc(t, 0, NULL); @@ -160,13 +160,12 @@ static int get_all_msg_uids(struct mailbox *box, ARRAY_TYPE(seq_range) *uids) search_ctx = mailbox_search_init(t, search_args, NULL); mail_search_args_unref(&search_args); - while ((ret = mailbox_search_next(search_ctx, mail)) > 0) { + while (mailbox_search_next(search_ctx, mail)) { /* *2 because even/odd is for body/header */ seq_range_array_add_range(uids, mail->uid * 2, mail->uid * 2 + 1); } - if (mailbox_search_deinit(&search_ctx) < 0) - ret = -1; + ret = mailbox_search_deinit(&search_ctx); mail_free(&mail); (void)mailbox_transaction_commit(&t); return ret; diff --git a/src/plugins/fts/fts-storage.c b/src/plugins/fts/fts-storage.c index 538831da9e..4a6704e759 100644 --- a/src/plugins/fts/fts-storage.c +++ b/src/plugins/fts/fts-storage.c @@ -529,7 +529,7 @@ static int fts_build_more(struct fts_storage_build_context *ctx) FTS_BUILD_NOTIFY_INTERVAL_SECS) fts_build_notify(ctx); - while (mailbox_search_next(ctx->search_ctx, ctx->mail) > 0) { + while (mailbox_search_next(ctx->search_ctx, ctx->mail)) { T_BEGIN { ret = fts_build_mail(ctx, ctx->mail->uid); } T_END; @@ -615,8 +615,9 @@ fts_mailbox_search_init(struct mailbox_transaction_context *t, return ctx; } -static int fts_mailbox_search_next_nonblock(struct mail_search_context *ctx, - struct mail *mail, bool *tryagain_r) +static bool +fts_mailbox_search_next_nonblock(struct mail_search_context *ctx, + struct mail *mail, bool *tryagain_r) { struct fts_mailbox *fbox = FTS_CONTEXT(ctx->transaction->box); struct fts_search_context *fctx = FTS_CONTEXT(ctx); @@ -627,7 +628,7 @@ static int fts_mailbox_search_next_nonblock(struct mail_search_context *ctx, to finish building the indexes */ if (!fts_try_build_init(ctx, fctx)) { *tryagain_r = TRUE; - return 0; + return FALSE; } } @@ -636,7 +637,7 @@ static int fts_mailbox_search_next_nonblock(struct mail_search_context *ctx, ret = fts_build_more(fctx->build_ctx); if (ret == 0) { *tryagain_r = TRUE; - return 0; + return FALSE; } /* finished / error */ diff --git a/src/plugins/mbox-snarf/mbox-snarf-plugin.c b/src/plugins/mbox-snarf/mbox-snarf-plugin.c index 6d85a02e49..aac7bfa389 100644 --- a/src/plugins/mbox-snarf/mbox-snarf-plugin.c +++ b/src/plugins/mbox-snarf/mbox-snarf-plugin.c @@ -56,9 +56,10 @@ static int mbox_snarf(struct mailbox *srcbox, struct mailbox *destbox) search_ctx = mailbox_search_init(src_trans, search_args, NULL); mail_search_args_unref(&search_args); + ret = 0; mail = mail_alloc(src_trans, MAIL_FETCH_STREAM_HEADER | MAIL_FETCH_STREAM_BODY, NULL); - while ((ret = mailbox_search_next(search_ctx, mail)) > 0) { + while (mailbox_search_next(search_ctx, mail)) { if (mail->expunged) continue; diff --git a/src/plugins/quota/quota-count.c b/src/plugins/quota/quota-count.c index 4f425621a7..cf01fdb16f 100644 --- a/src/plugins/quota/quota-count.c +++ b/src/plugins/quota/quota-count.c @@ -51,7 +51,7 @@ quota_count_mailbox(struct quota_root *root, struct mail_namespace *ns, ctx = mailbox_search_init(trans, search_args, NULL); mail_search_args_unref(&search_args); - while (mailbox_search_next(ctx, mail) > 0) { + while (mailbox_search_next(ctx, mail)) { if (mail_get_physical_size(mail, &size) == 0) *bytes_r += size; *count_r += 1; diff --git a/src/plugins/quota/quota-storage.c b/src/plugins/quota/quota-storage.c index 547a41bab7..a8225aa1a5 100644 --- a/src/plugins/quota/quota-storage.c +++ b/src/plugins/quota/quota-storage.c @@ -398,7 +398,7 @@ quota_mailbox_delete_shrink_quota(struct mailbox *box) mail_search_args_unref(&search_args); mail = mail_alloc(t, 0, NULL); - while (mailbox_search_next(ctx, mail) > 0) + while (mailbox_search_next(ctx, mail)) quota_free(qt, mail); mail_free(&mail); diff --git a/src/plugins/trash/trash-plugin.c b/src/plugins/trash/trash-plugin.c index 5dd0f1fbfc..a6a91f06c7 100644 --- a/src/plugins/trash/trash-plugin.c +++ b/src/plugins/trash/trash-plugin.c @@ -87,7 +87,7 @@ static int trash_clean_mailbox_get_next(struct trash_mailbox *trash, ret = trash_clean_mailbox_open(trash); else ret = mailbox_search_next(trash->search_ctx, - trash->mail); + trash->mail) ? 1 : 0; if (ret <= 0) { *received_time_r = 0; return ret; diff --git a/src/plugins/virtual/virtual-search.c b/src/plugins/virtual/virtual-search.c index 4923ca2b29..7d00579b70 100644 --- a/src/plugins/virtual/virtual-search.c +++ b/src/plugins/virtual/virtual-search.c @@ -9,7 +9,6 @@ #include enum virtual_search_state { - VIRTUAL_SEARCH_STATE_FAILED = -1, VIRTUAL_SEARCH_STATE_BUILD, VIRTUAL_SEARCH_STATE_RETURN, VIRTUAL_SEARCH_STATE_SORT, @@ -63,8 +62,8 @@ static int mail_search_get_result(struct mail_search_context *ctx) return ret; } -static int virtual_search_get_records(struct mail_search_context *ctx, - struct virtual_search_context *vctx) +static void virtual_search_get_records(struct mail_search_context *ctx, + struct virtual_search_context *vctx) { struct virtual_mailbox *mbox = (struct virtual_mailbox *)ctx->transaction->box; @@ -72,10 +71,10 @@ static int virtual_search_get_records(struct mail_search_context *ctx, struct virtual_search_record srec; const void *data; bool expunged; - int ret, result; + int result; memset(&srec, 0, sizeof(srec)); - while ((ret = index_storage_search_next_update_seq(ctx)) > 0) { + while (index_storage_search_next_update_seq(ctx)) { result = mail_search_get_result(ctx); i_assert(result != 0); if (result > 0) { @@ -98,7 +97,6 @@ static int virtual_search_get_records(struct mail_search_context *ctx, array_sort(&vctx->records, virtual_search_record_cmp); ctx->progress_max = array_count(&vctx->records); - return ret; } struct mail_search_context * @@ -117,9 +115,7 @@ virtual_search_init(struct mailbox_transaction_context *t, i_array_init(&vctx->records, 64); MODULE_CONTEXT_SET(ctx, virtual_storage_module, vctx); - if (virtual_search_get_records(ctx, vctx) < 0) - vctx->search_state = VIRTUAL_SEARCH_STATE_FAILED; - + virtual_search_get_records(ctx, vctx); seq_range_array_iter_init(&vctx->result_iter, &vctx->result); return ctx; } @@ -134,16 +130,13 @@ int virtual_search_deinit(struct mail_search_context *ctx) return index_storage_search_deinit(ctx); } -int virtual_search_next_nonblock(struct mail_search_context *ctx, - struct mail *mail, bool *tryagain_r) +bool virtual_search_next_nonblock(struct mail_search_context *ctx, + struct mail *mail, bool *tryagain_r) { struct virtual_search_context *vctx = VIRTUAL_CONTEXT(ctx); uint32_t seq; - int ret; switch (vctx->search_state) { - case VIRTUAL_SEARCH_STATE_FAILED: - return -1; case VIRTUAL_SEARCH_STATE_BUILD: if (ctx->sort_program == NULL) vctx->search_state = VIRTUAL_SEARCH_STATE_SORT; @@ -155,11 +148,10 @@ int virtual_search_next_nonblock(struct mail_search_context *ctx, case VIRTUAL_SEARCH_STATE_SORT: /* the messages won't be returned sorted, so we'll have to do it ourself */ - while ((ret = index_storage_search_next_nonblock(ctx, mail, - tryagain_r)) > 0) + while (index_storage_search_next_nonblock(ctx, mail, tryagain_r)) seq_range_array_add(&vctx->result, 0, mail->seq); - if (ret < 0 || *tryagain_r) - return ret; + if (*tryagain_r) + return FALSE; vctx->next_result_n = 0; vctx->search_state = VIRTUAL_SEARCH_STATE_SORT_DONE; @@ -168,10 +160,10 @@ int virtual_search_next_nonblock(struct mail_search_context *ctx, *tryagain_r = FALSE; if (!seq_range_array_iter_nth(&vctx->result_iter, vctx->next_result_n, &seq)) - return 0; + return FALSE; vctx->next_result_n++; mail_set_seq(mail, seq); - return 1; + return TRUE; } i_unreached(); } diff --git a/src/plugins/virtual/virtual-storage.h b/src/plugins/virtual/virtual-storage.h index 7d24884e95..4f8e3348fc 100644 --- a/src/plugins/virtual/virtual-storage.h +++ b/src/plugins/virtual/virtual-storage.h @@ -145,8 +145,8 @@ virtual_search_init(struct mailbox_transaction_context *t, struct mail_search_args *args, const enum mail_sort_type *sort_program); int virtual_search_deinit(struct mail_search_context *ctx); -int virtual_search_next_nonblock(struct mail_search_context *ctx, - struct mail *mail, bool *tryagain_r); +bool virtual_search_next_nonblock(struct mail_search_context *ctx, + struct mail *mail, bool *tryagain_r); bool virtual_search_next_update_seq(struct mail_search_context *ctx); struct mail * diff --git a/src/plugins/virtual/virtual-sync.c b/src/plugins/virtual/virtual-sync.c index 8a57495338..19e1b71cf4 100644 --- a/src/plugins/virtual/virtual-sync.c +++ b/src/plugins/virtual/virtual-sync.c @@ -484,7 +484,7 @@ static int virtual_sync_backend_box_init(struct virtual_backend_box *bbox) /* add the found UIDs to uidmap. virtual_uid gets assigned later. */ memset(&uidmap, 0, sizeof(uidmap)); array_clear(&bbox->uids); - while (mailbox_search_next(search_ctx, mail) > 0) { + while (mailbox_search_next(search_ctx, mail)) { uidmap.real_uid = mail->uid; array_append(&bbox->uids, &uidmap, 1); } diff --git a/src/pop3/pop3-client.c b/src/pop3/pop3-client.c index 9158d71bb3..b590bc5e48 100644 --- a/src/pop3/pop3-client.c +++ b/src/pop3/pop3-client.c @@ -100,7 +100,7 @@ static bool init_mailbox(struct client *client, const char **error_r) failed = FALSE; mail = mail_alloc(t, MAIL_FETCH_VIRTUAL_SIZE, NULL); - while (mailbox_search_next(ctx, mail) > 0) { + while (mailbox_search_next(ctx, mail)) { if (mail_get_virtual_size(mail, &size) < 0) { expunged = mail->expunged; failed = TRUE; diff --git a/src/pop3/pop3-commands.c b/src/pop3/pop3-commands.c index 9681ccef27..b6bbf6d1f0 100644 --- a/src/pop3/pop3-commands.c +++ b/src/pop3/pop3-commands.c @@ -213,7 +213,7 @@ bool client_update_mails(struct client *client) mail_search_args_unref(&search_args); mail = mail_alloc(client->trans, 0, NULL); - while (mailbox_search_next(ctx, mail) > 0) { + while (mailbox_search_next(ctx, mail)) { idx = mail->seq - 1; bit = 1 << (idx % CHAR_BIT); if (client->deleted_bitmask != NULL && @@ -402,7 +402,7 @@ static int fetch(struct client *client, unsigned int msgnum, uoff_t body_lines) ctx->mail = mail_alloc(client->trans, MAIL_FETCH_STREAM_HEADER | MAIL_FETCH_STREAM_BODY, NULL); - if (mailbox_search_next(ctx->search_ctx, ctx->mail) <= 0 || + if (!mailbox_search_next(ctx->search_ctx, ctx->mail) || mail_get_stream(ctx->mail, NULL, NULL, &ctx->stream) < 0) { ret = client_reply_msg_expunged(client, msgnum); fetch_deinit(ctx); @@ -476,7 +476,7 @@ static int cmd_rset(struct client *client, const char *args ATTR_UNUSED) mail_search_args_unref(&search_args); mail = mail_alloc(client->trans, 0, NULL); - while (mailbox_search_next(search_ctx, mail) > 0) + while (mailbox_search_next(search_ctx, mail)) mail_update_flags(mail, MODIFY_REMOVE, MAIL_SEEN); mail_free(&mail); (void)mailbox_search_deinit(&search_ctx); @@ -585,7 +585,7 @@ static bool list_uids_iter(struct client *client, struct cmd_uidl_context *ctx) tab[0].value = t_strdup_printf("%u", client->uid_validity); str = t_str_new(128); - while (mailbox_search_next(ctx->search_ctx, ctx->mail) > 0) { + while (mailbox_search_next(ctx->search_ctx, ctx->mail)) { if (client->deleted) { uint32_t idx = ctx->mail->seq - 1; if (client->deleted_bitmask[idx / CHAR_BIT] &