]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imapc: Move imapc_mailbox_fetch_state*() to imapc-mailbox.c
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 25 Dec 2017 18:21:40 +0000 (20:21 +0200)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Thu, 18 Jan 2018 10:07:06 +0000 (12:07 +0200)
Mainly to make the next commit smaller.

src/lib-storage/index/imapc/imapc-mailbox.c
src/lib-storage/index/imapc/imapc-storage.h
src/lib-storage/index/imapc/imapc-sync.c

index 9d2dae2d922c858062deef3d2d9b59d3d5d71f48..7cf160af77fada459b6b8bb4cad6ee3ca20143ae 100644 (file)
@@ -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)
index 84b5870d098cf5d4fa172dfe8b36c1268562f622..7856ba0773de836e15a617da7d8755e33ba7a525 100644 (file)
@@ -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);
index 8f1975218e46fed1efb59306743e6bbf75d832f1..1b097cd8c985ef3c5b73046dd625ed0acf2cb7c7 100644 (file)
@@ -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);