dovecot-2.2: imapc: If imapc_features has gmail-migration, fetch...

dovecot at dovecot.org dovecot at dovecot.org
Wed Mar 11 16:33:54 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/3effe57f223d
changeset: 18329:3effe57f223d
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Mar 11 18:30:19 2015 +0200
description:
imapc: If imapc_features has gmail-migration, fetch X-GM-MSGID at startup and cache it.
This works only if index files haven't been disabled.

diffstat:

 src/lib-storage/index/imapc/imapc-mailbox.c |  29 ++++++++++++++++++++++++++++-
 src/lib-storage/index/imapc/imapc-storage.h |   2 ++
 src/lib-storage/index/imapc/imapc-sync.c    |  18 +++++++++++++++++-
 3 files changed, 47 insertions(+), 2 deletions(-)

diffs (139 lines):

diff -r f32ddc04fce7 -r 3effe57f223d src/lib-storage/index/imapc/imapc-mailbox.c
--- a/src/lib-storage/index/imapc/imapc-mailbox.c	Wed Mar 11 17:54:27 2015 +0200
+++ b/src/lib-storage/index/imapc/imapc-mailbox.c	Wed Mar 11 18:30:19 2015 +0200
@@ -48,11 +48,20 @@
 	if (mbox->delayed_sync_trans != NULL)
 		return;
 
+	i_assert(mbox->delayed_sync_cache_view == NULL);
+	i_assert(mbox->delayed_sync_cache_trans == NULL);
+
 	mbox->delayed_sync_trans =
 		mail_index_transaction_begin(imapc_mailbox_get_sync_view(mbox),
 					MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL);
 	mbox->delayed_sync_view =
 		mail_index_transaction_open_updated_view(mbox->delayed_sync_trans);
+
+	mbox->delayed_sync_cache_view =
+		mail_cache_view_open(mbox->box.cache, mbox->delayed_sync_view);
+	mbox->delayed_sync_cache_trans =
+		mail_cache_get_transaction(mbox->delayed_sync_cache_view,
+					   mbox->delayed_sync_trans);
 }
 
 static int imapc_mailbox_commit_delayed_expunges(struct imapc_mailbox *mbox)
@@ -92,6 +101,9 @@
 		}
 		*changes_r = TRUE;
 	}
+	mbox->delayed_sync_cache_trans = NULL;
+	if (mbox->delayed_sync_cache_view != NULL)
+		mail_cache_view_close(&mbox->delayed_sync_cache_view);
 	if (mbox->sync_view != NULL)
 		mail_index_view_close(&mbox->sync_view);
 
@@ -259,7 +271,7 @@
 	struct imapc_fetch_request *const *fetch_requestp;
 	struct imapc_mail *const *mailp;
 	const struct imap_arg *list, *flags_list;
-	const char *atom;
+	const char *atom, *guid = NULL;
 	const struct mail_index_record *rec = NULL;
 	enum mail_flags flags;
 	uint32_t fetch_uid, uid;
@@ -295,6 +307,10 @@
 					array_append(&keywords, &atom, 1);
 				}
 			}
+		} else if (strcasecmp(atom, "X-GM-MSGID") == 0 &&
+			   !mbox->initial_sync_done) {
+			if (imap_arg_get_atom(&list[i+1], &atom))
+				guid = atom;
 		} else if (strcasecmp(atom, "X-GM-LABELS") == 0 &&
 			   IMAPC_BOX_HAS_FEATURE(mbox, IMAPC_FEATURE_GMAIL_MIGRATION)) {
 			if (!imap_arg_get_list(&list[i+1], &flags_list))
@@ -382,6 +398,17 @@
 		}
 		mail_index_keywords_unref(&kw);
 	}
+	if (guid != NULL) {
+		struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(&mbox->box);
+		const enum index_cache_field guid_cache_idx =
+			ibox->cache_fields[MAIL_CACHE_GUID].idx;
+
+		if (mail_cache_field_can_add(mbox->delayed_sync_cache_trans,
+					     lseq, guid_cache_idx)) {
+			mail_cache_add(mbox->delayed_sync_cache_trans, lseq,
+				       guid_cache_idx, guid, strlen(guid)+1);
+		}
+	}
 	imapc_mailbox_idle_notify(mbox);
 }
 
diff -r f32ddc04fce7 -r 3effe57f223d src/lib-storage/index/imapc/imapc-storage.h
--- a/src/lib-storage/index/imapc/imapc-storage.h	Wed Mar 11 17:54:27 2015 +0200
+++ b/src/lib-storage/index/imapc/imapc-storage.h	Wed Mar 11 18:30:19 2015 +0200
@@ -87,6 +87,8 @@
 
 	struct mail_index_transaction *delayed_sync_trans;
 	struct mail_index_view *sync_view, *delayed_sync_view;
+	struct mail_cache_view *delayed_sync_cache_view;
+	struct mail_cache_transaction_ctx *delayed_sync_cache_trans;
 	struct timeout *to_idle_check, *to_idle_delay;
 
 	ARRAY(struct imapc_fetch_request *) fetch_requests;
diff -r f32ddc04fce7 -r 3effe57f223d src/lib-storage/index/imapc/imapc-sync.c
--- a/src/lib-storage/index/imapc/imapc-sync.c	Wed Mar 11 17:54:27 2015 +0200
+++ b/src/lib-storage/index/imapc/imapc-sync.c	Wed Mar 11 18:30:19 2015 +0200
@@ -4,6 +4,7 @@
 #include "ioloop.h"
 #include "str.h"
 #include "imap-util.h"
+#include "mail-cache.h"
 #include "index-sync-private.h"
 #include "imapc-client.h"
 #include "imapc-msgmap.h"
@@ -282,13 +283,20 @@
 
 	str_printfa(cmd, "UID FETCH %u:* (FLAGS", first_uid);
 	if (IMAPC_BOX_HAS_FEATURE(ctx->mbox, IMAPC_FEATURE_GMAIL_MIGRATION)) {
-		/* do this only for the \All mailbox */
 		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_sync_cmd(ctx, str_c(cmd));
@@ -419,6 +427,11 @@
 	mbox->delayed_sync_view =
 		mail_index_transaction_open_updated_view(ctx->trans);
 	mbox->delayed_sync_trans = ctx->trans;
+	mbox->delayed_sync_cache_view =
+		mail_cache_view_open(mbox->box.cache, mbox->delayed_sync_view);
+	mbox->delayed_sync_cache_trans =
+		mail_cache_get_transaction(mbox->delayed_sync_cache_view,
+					   mbox->delayed_sync_trans);
 	mbox->min_append_uid = mail_index_get_header(ctx->sync_view)->next_uid;
 
 	mbox->syncing = TRUE;
@@ -455,6 +468,9 @@
 		i_free_and_null(ctx->mbox->sync_gmail_pop3_search_tag);
 		ret = -1;
 	}
+	mail_cache_view_close(&ctx->mbox->delayed_sync_cache_view);
+	ctx->mbox->delayed_sync_cache_trans = NULL;
+
 	ctx->mbox->syncing = FALSE;
 	ctx->mbox->sync_ctx = NULL;
 


More information about the dovecot-cvs mailing list