Skip to content

Commit

Permalink
imapc: Move imapc_mailbox_fetch_state*() to imapc-mailbox.c
Browse files Browse the repository at this point in the history
Mainly to make the next commit smaller.
  • Loading branch information
sirainen authored and villesavolainen committed Jan 18, 2018
1 parent f3ccac7 commit ddd79dd
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 50 deletions.
55 changes: 55 additions & 0 deletions src/lib-storage/index/imapc/imapc-mailbox.c
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions src/lib-storage/index/imapc/imapc-storage.h
Expand Up @@ -196,6 +196,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);
Expand Down
55 changes: 5 additions & 50 deletions src/lib-storage/index/imapc/imapc-sync.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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) &&
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit ddd79dd

Please sign in to comment.