dovecot-2.2: dsync: Fixes for syncing without GUIDs.

dovecot at dovecot.org dovecot at dovecot.org
Mon Feb 11 01:11:04 EET 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/f58e7b386c6e
changeset: 15753:f58e7b386c6e
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Feb 11 01:10:57 2013 +0200
description:
dsync: Fixes for syncing without GUIDs.

diffstat:

 src/doveadm/dsync/dsync-brain-mailbox.c  |   3 +
 src/doveadm/dsync/dsync-mailbox-import.c |  49 +++++++++++++++++++++++--------
 src/doveadm/dsync/dsync-mailbox-import.h |   3 +-
 3 files changed, 41 insertions(+), 14 deletions(-)

diffs (162 lines):

diff -r d73d04e24eee -r f58e7b386c6e src/doveadm/dsync/dsync-brain-mailbox.c
--- a/src/doveadm/dsync/dsync-brain-mailbox.c	Mon Feb 11 01:07:53 2013 +0200
+++ b/src/doveadm/dsync/dsync-brain-mailbox.c	Mon Feb 11 01:10:57 2013 +0200
@@ -173,6 +173,9 @@
 		import_flags |= DSYNC_MAILBOX_IMPORT_FLAG_REVERT_LOCAL_CHANGES;
 	if (brain->debug)
 		import_flags |= DSYNC_MAILBOX_IMPORT_FLAG_DEBUG;
+	if (brain->local_dsync_box.have_guids &&
+	    remote_dsync_box->have_guids)
+		import_flags |= DSYNC_MAILBOX_IMPORT_FLAG_MAILS_HAVE_GUIDS;
 
 	brain->box_importer = brain->backup_send ? NULL :
 		dsync_mailbox_import_init(brain->box, brain->log_scan,
diff -r d73d04e24eee -r f58e7b386c6e src/doveadm/dsync/dsync-mailbox-import.c
--- a/src/doveadm/dsync/dsync-mailbox-import.c	Mon Feb 11 01:07:53 2013 +0200
+++ b/src/doveadm/dsync/dsync-mailbox-import.c	Mon Feb 11 01:10:57 2013 +0200
@@ -55,6 +55,7 @@
 
 	struct mail *cur_mail;
 	const char *cur_guid;
+	const char *cur_hdr_hash;
 
 	/* UID => struct dsync_mail_change */
 	HASH_TABLE_TYPE(dsync_uid_mail_change) local_changes;
@@ -86,6 +87,7 @@
 	unsigned int want_mail_requests:1;
 	unsigned int master_brain:1;
 	unsigned int revert_local_changes:1;
+	unsigned int mails_have_guids:1;
 };
 
 static void
@@ -168,6 +170,8 @@
 	importer->revert_local_changes =
 		(flags & DSYNC_MAILBOX_IMPORT_FLAG_REVERT_LOCAL_CHANGES) != 0;
 	importer->debug = (flags & DSYNC_MAILBOX_IMPORT_FLAG_DEBUG) != 0;
+	importer->mails_have_guids =
+		(flags & DSYNC_MAILBOX_IMPORT_FLAG_MAILS_HAVE_GUIDS) != 0;
 
 	mailbox_get_open_status(importer->box, STATUS_UIDNEXT |
 				STATUS_HIGHESTMODSEQ | STATUS_HIGHESTPVTMODSEQ,
@@ -214,6 +218,9 @@
 static bool
 importer_next_mail(struct dsync_mailbox_importer *importer, uint32_t wanted_uid)
 {
+	const char *hdr_hash;
+	int ret = 0;
+
 	if (importer->cur_mail == NULL) {
 		/* end of search */
 		return FALSE;
@@ -234,15 +241,32 @@
 					 &importer->cur_mail)) {
 			importer->cur_mail = NULL;
 			importer->cur_guid = NULL;
+			importer->cur_hdr_hash = NULL;
 			return FALSE;
 		}
 		importer->cur_uid_has_change = FALSE;
 	}
 	importer->cur_uid_has_change = importer->cur_mail != NULL &&
 		importer->cur_mail->uid == wanted_uid;
-	if (mail_get_special(importer->cur_mail, MAIL_FETCH_GUID,
-			     &importer->cur_guid) < 0) {
-		dsync_mail_error(importer, importer->cur_mail, "GUID");
+	if (importer->mails_have_guids) {
+		if (mail_get_special(importer->cur_mail, MAIL_FETCH_GUID,
+				     &importer->cur_guid) < 0) {
+			dsync_mail_error(importer, importer->cur_mail, "GUID");
+			ret = -1;
+		}
+	} else {
+		if (dsync_mail_get_hdr_hash(importer->cur_mail,
+					    &hdr_hash) < 0) {
+			dsync_mail_error(importer, importer->cur_mail,
+					 "header hash");
+			ret = -1;
+		} else {
+			struct mail_private *pmail =
+				(struct mail_private *)importer->cur_mail;
+			importer->cur_hdr_hash = p_strdup(pmail->pool, hdr_hash);
+		}
+	}
+	if (ret < 0) {
 		importer->next_local_seq = importer->cur_mail->seq + 1;
 		return importer_next_mail(importer, wanted_uid);
 	}
@@ -288,7 +312,7 @@
 }
 
 static void newmail_link(struct dsync_mailbox_importer *importer,
-			 struct importer_new_mail *newmail)
+			 struct importer_new_mail *newmail, uint32_t remote_uid)
 {
 	struct importer_new_mail *first_mail, **last, *mail, *link = NULL;
 
@@ -303,16 +327,12 @@
 			return;
 		}
 	} else {
-		if (!newmail->uid_in_local) {
-			/* FIXME: ? */
-			return;
-		}
 		first_mail = hash_table_lookup(importer->import_uids,
-					       POINTER_CAST(newmail->uid));
+					       POINTER_CAST(remote_uid));
 		if (first_mail == NULL) {
 			/* first mail for this UID */
 			hash_table_insert(importer->import_uids,
-					  POINTER_CAST(newmail->uid), newmail);
+					  POINTER_CAST(remote_uid), newmail);
 			importer_mail_request(importer, newmail);
 			return;
 		}
@@ -345,12 +365,14 @@
 
 	memset(&m1, 0, sizeof(m1));
 	if (importer->cur_mail != NULL) {
-		m1.guid = importer->cur_guid;
+		m1.guid = importer->cur_guid != NULL ?
+			importer->cur_guid : importer->cur_hdr_hash;
 		m1.uid = importer->cur_mail->uid;
 	}
 	memset(&m2, 0, sizeof(m2));
 	if (save_change != NULL) {
-		m2.guid = save_change->guid;
+		m2.guid = save_change->hdr_hash != NULL ?
+			save_change->hdr_hash : save_change->guid;
 		m2.uid = save_change->uid;
 		i_assert(save_change->type != DSYNC_MAIL_CHANGE_TYPE_EXPUNGE);
 	}
@@ -403,7 +425,7 @@
 	}
 
 	array_append(&importer->newmails, &newmail, 1);
-	newmail_link(importer, newmail);
+	newmail_link(importer, newmail, save_change->uid);
 	return remote_saved;
 }
 
@@ -931,6 +953,7 @@
 
 	importer->cur_mail = NULL;
 	importer->cur_guid = NULL;
+	importer->cur_hdr_hash = NULL;
 	importer->next_local_seq = 0;
 
 	(void)mailbox_search_deinit(&importer->search_ctx);
diff -r d73d04e24eee -r f58e7b386c6e src/doveadm/dsync/dsync-mailbox-import.h
--- a/src/doveadm/dsync/dsync-mailbox-import.h	Mon Feb 11 01:07:53 2013 +0200
+++ b/src/doveadm/dsync/dsync-mailbox-import.h	Mon Feb 11 01:10:57 2013 +0200
@@ -5,7 +5,8 @@
 	DSYNC_MAILBOX_IMPORT_FLAG_MASTER_BRAIN		= 0x01,
 	DSYNC_MAILBOX_IMPORT_FLAG_WANT_MAIL_REQUESTS	= 0x02,
 	DSYNC_MAILBOX_IMPORT_FLAG_REVERT_LOCAL_CHANGES	= 0x04,
-	DSYNC_MAILBOX_IMPORT_FLAG_DEBUG			= 0x08
+	DSYNC_MAILBOX_IMPORT_FLAG_DEBUG			= 0x08,
+	DSYNC_MAILBOX_IMPORT_FLAG_MAILS_HAVE_GUIDS	= 0x10
 };
 
 struct mailbox;


More information about the dovecot-cvs mailing list