From a2e0569c4100d5bef79a61f18e7b4742a5d7ab4d Mon Sep 17 00:00:00 2001 From: Bron Gondwana Date: Wed, 24 Dec 2008 23:30:38 +1100 Subject: [PATCH] Warn on mismatched GUID instead of overwriting This is part of our "make replication safe" initiative which you can read more about here: http://lists.andrew.cmu.edu/pipermail/cyrus-devel/2007-October/000525.html In particular, this one addresses point (a): a) MUST never lose a message that's been accepted for delivery except in the case of total drive failure. By making sure we don't overwrite a message delivered when the now replica machine was the master but not yet replicated. --- imap/sync_client.c | 36 ++++++++++++++++++++++++------------ 1 files changed, 24 insertions(+), 12 deletions(-) diff --git a/imap/sync_client.c b/imap/sync_client.c index 2877e26..b80f085 100644 --- a/imap/sync_client.c +++ b/imap/sync_client.c @@ -256,11 +256,15 @@ static int find_reserve_messages(struct mailbox *mailbox, while (msg && (record.uid > msg->uid)) msg = msg->next; - if (msg && (record.uid == msg->uid) && - message_guid_compare_allow_null(&record.guid, &msg->guid)) { - msg = msg->next; /* Ignore exact match */ - continue; - } + if (msg && (record.uid == msg->uid)) { + if (!message_guid_compare_allow_null(&record.guid, &msg->guid)) { + syslog(LOG_NOTICE, + "GUID MISMATCH: %lu of %s: %m", + record.uid, mailbox->name); + } + msg = msg->next; /* Ignore exact match */ + continue; + } /* Want to upload this message; does the server have a copy? */ if (sync_msgid_lookup(server_msgid_list, &record.guid)) @@ -1214,11 +1218,15 @@ static int check_upload_messages(struct mailbox *mailbox, while (msg && (record.uid > msg->uid)) msg = msg->next; - if (msg && (record.uid == msg->uid) && - message_guid_compare_allow_null(&record.guid, &msg->guid)) { - msg = msg->next; /* Ignore exact match */ - continue; - } + if (msg && (record.uid == msg->uid)) { + if (!message_guid_compare_allow_null(&record.guid, &msg->guid)) { + syslog(LOG_NOTICE, + "GUID MISMATCH: %lu of %s: %m", + record.uid, mailbox->name); + } + msg = msg->next; /* Ignore exact match */ + continue; + } /* Found a message on the client which doesn't exist on the server */ return(1); @@ -1407,8 +1415,12 @@ static int upload_messages_list(struct mailbox *mailbox, while (msg && (record.uid > msg->uid)) msg = msg->next; - if (msg && (record.uid == msg->uid) && - message_guid_compare_allow_null(&record.guid, &msg->guid)) { + if (msg && (record.uid == msg->uid)) { + if (!message_guid_compare_allow_null(&record.guid, &msg->guid)) { + syslog(LOG_NOTICE, + "GUID MISMATCH: %lu of %s: %m", + record.uid, mailbox->name); + } msg = msg->next; /* Ignore exact match */ continue; } -- 1.5.6.5