From: Timo Sirainen Date: Mon, 25 Dec 2017 18:21:40 +0000 (+0200) Subject: imapc: Move imapc_mailbox_fetch_state*() to imapc-mailbox.c X-Git-Tag: 2.2.34~128 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=17769f1f75b101c121c0a7adb026baf7e7043cf0;p=thirdparty%2Fdovecot%2Fcore.git imapc: Move imapc_mailbox_fetch_state*() to imapc-mailbox.c Mainly to make the next commit smaller. --- diff --git a/src/lib-storage/index/imapc/imapc-mailbox.c b/src/lib-storage/index/imapc/imapc-mailbox.c index 9d2dae2d92..7cf160af77 100644 --- a/src/lib-storage/index/imapc/imapc-mailbox.c +++ b/src/lib-storage/index/imapc/imapc-mailbox.c @@ -2,12 +2,14 @@ #include "lib.h" #include "ioloop.h" +#include "str.h" #include "mail-index-modseq.h" #include "imap-arg.h" #include "imap-seqset.h" #include "imap-util.h" #include "imapc-mail.h" #include "imapc-msgmap.h" +#include "imapc-list.h" #include "imapc-search.h" #include "imapc-sync.h" #include "imapc-storage.h" @@ -155,6 +157,59 @@ static void imapc_mailbox_idle_notify(struct imapc_mailbox *mbox) } } +void imapc_mailbox_fetch_state_finish(struct imapc_mailbox *mbox, + struct mail_index_view *sync_view, + struct mail_index_transaction *trans) +{ + uint32_t lseq, uid, msg_count; + + if (mbox->sync_next_lseq == 0) + return; + + /* if we haven't seen FETCH reply for some messages at the end of + mailbox they've been externally expunged. */ + msg_count = mail_index_view_get_messages_count(sync_view); + for (lseq = mbox->sync_next_lseq; lseq <= msg_count; lseq++) { + mail_index_lookup_uid(sync_view, lseq, &uid); + if (uid >= mbox->sync_uid_next) { + /* another process already added new messages to index + that our IMAP connection hasn't seen yet */ + break; + } + mail_index_expunge(trans, lseq); + } + + mbox->sync_next_lseq = 0; + mbox->sync_next_rseq = 0; +} + +void imapc_mailbox_fetch_state(struct imapc_mailbox *mbox, string_t *str, + uint32_t first_uid) +{ + str_printfa(str, "UID FETCH %u:* (FLAGS", first_uid); + if (imapc_mailbox_has_modseqs(mbox)) { + str_append(str, " MODSEQ"); + mail_index_modseq_enable(mbox->box.index); + } + if (IMAPC_BOX_HAS_FEATURE(mbox, IMAPC_FEATURE_GMAIL_MIGRATION)) { + enum mailbox_info_flags flags; + + if (first_uid == 1 && + !mail_index_is_in_memory(mbox->box.index)) { + /* these can be efficiently fetched among flags and + stored into cache */ + str_append(str, " X-GM-MSGID"); + } + /* do this only for the \All mailbox */ + if (imapc_list_get_mailbox_flags(mbox->box.list, + mbox->box.name, &flags) == 0 && + (flags & MAILBOX_SPECIALUSE_ALL) != 0) + str_append(str, " X-GM-LABELS"); + + } + str_append_c(str, ')'); +} + static void imapc_untagged_exists(const struct imapc_untagged_reply *reply, struct imapc_mailbox *mbox) diff --git a/src/lib-storage/index/imapc/imapc-storage.h b/src/lib-storage/index/imapc/imapc-storage.h index 84b5870d09..7856ba0773 100644 --- a/src/lib-storage/index/imapc/imapc-storage.h +++ b/src/lib-storage/index/imapc/imapc-storage.h @@ -195,6 +195,12 @@ void imapc_mailbox_set_corrupted(struct imapc_mailbox *mbox, const char *reason, ...) ATTR_FORMAT(2, 3); const char *imapc_mailbox_get_remote_name(struct imapc_mailbox *mbox); +void imapc_mailbox_fetch_state(struct imapc_mailbox *mbox, string_t *cmd, + uint32_t first_uid); +void imapc_mailbox_fetch_state_finish(struct imapc_mailbox *mbox, + struct mail_index_view *sync_view, + struct mail_index_transaction *trans); + void imapc_storage_client_register_untagged(struct imapc_storage_client *client, const char *name, imapc_storage_callback_t *callback); diff --git a/src/lib-storage/index/imapc/imapc-sync.c b/src/lib-storage/index/imapc/imapc-sync.c index 8f1975218e..1b097cd8c9 100644 --- a/src/lib-storage/index/imapc/imapc-sync.c +++ b/src/lib-storage/index/imapc/imapc-sync.c @@ -266,31 +266,6 @@ static void imapc_sync_expunge_finish(struct imapc_sync_context *ctx) imapc_sync_cmd(ctx, str_c(str)); } -static void imapc_sync_expunge_eom(struct imapc_sync_context *ctx) -{ - struct imapc_mailbox *mbox = ctx->mbox; - uint32_t lseq, uid, msg_count; - - if (mbox->sync_next_lseq == 0) - return; - - /* if we haven't seen FETCH reply for some messages at the end of - mailbox they've been externally expunged. */ - msg_count = mail_index_view_get_messages_count(ctx->sync_view); - for (lseq = mbox->sync_next_lseq; lseq <= msg_count; lseq++) { - mail_index_lookup_uid(ctx->sync_view, lseq, &uid); - if (uid >= mbox->sync_uid_next) { - /* another process already added new messages to index - that our IMAP connection hasn't seen yet */ - break; - } - mail_index_expunge(ctx->trans, lseq); - } - - mbox->sync_next_lseq = 0; - mbox->sync_next_rseq = 0; -} - static void imapc_sync_uid_next(struct imapc_sync_context *ctx) { struct imapc_mailbox *mbox = ctx->mbox; @@ -385,29 +360,7 @@ imapc_sync_send_commands(struct imapc_sync_context *ctx, uint32_t first_uid) /* empty mailbox - no point in fetching anything */ return; } - - str_printfa(cmd, "UID FETCH %u:* (FLAGS", first_uid); - if (imapc_mailbox_has_modseqs(ctx->mbox)) { - str_append(cmd, " MODSEQ"); - mail_index_modseq_enable(ctx->mbox->box.index); - } - if (IMAPC_BOX_HAS_FEATURE(ctx->mbox, IMAPC_FEATURE_GMAIL_MIGRATION)) { - enum mailbox_info_flags flags; - - if (first_uid == 1 && - !mail_index_is_in_memory(ctx->mbox->box.index)) { - /* these can be efficiently fetched among flags and - stored into cache */ - str_append(cmd, " X-GM-MSGID"); - } - /* do this only for the \All mailbox */ - if (imapc_list_get_mailbox_flags(ctx->mbox->box.list, - ctx->mbox->box.name, &flags) == 0 && - (flags & MAILBOX_SPECIALUSE_ALL) != 0) - str_append(cmd, " X-GM-LABELS"); - - } - str_append_c(cmd, ')'); + imapc_mailbox_fetch_state(ctx->mbox, cmd, first_uid); imapc_sync_cmd(ctx, str_c(cmd)); if (IMAPC_BOX_HAS_FEATURE(ctx->mbox, IMAPC_FEATURE_GMAIL_MIGRATION) && @@ -478,8 +431,10 @@ static void imapc_sync_index(struct imapc_sync_context *ctx) imapc_sync_uid_next(ctx); imapc_sync_highestmodseq(ctx); - if (!ctx->failed) - imapc_sync_expunge_eom(ctx); + if (!ctx->failed) { + imapc_mailbox_fetch_state_finish(ctx->mbox, ctx->sync_view, + ctx->trans); + } if (mbox->box.v.sync_notify != NULL) mbox->box.v.sync_notify(&mbox->box, 0, 0);