# Update quota correctly in sync_combine_commit(). Only normally triggered # when replicating unexpunged messages in normal use. # diff -udNr cyrus-imapd-2.3.14/imap/sync_commit.c cyrus-imapd/imap/sync_commit.c --- cyrus-imapd-2.3.14/imap/sync_commit.c 2008-03-24 17:09:20.000000000 +0000 +++ cyrus-imapd/imap/sync_commit.c 2009-03-26 20:13:14.000000000 +0000 @@ -398,7 +398,7 @@ FILE *newindex = NULL; FILE *newcache = NULL; FILE *newexpunge = NULL; - uquota_t original_quota = mailbox->quota_mailbox_used; + uquota_t original_mailbox_quota = 0; struct txn *tid = NULL; indexbuffer_t ibuf; unsigned char *buf = ibuf.buf; @@ -417,6 +417,13 @@ if (upload_list->count == 0) return(0); /* NOOP */ + /* Calculate mailbox quota. Should match mailbox->quota_mailbox_used */ + original_mailbox_quota = 0; + for (index_msgno = 1; index_msgno <= mailbox->exists; index_msgno++) { + mailbox_read_index_record(mailbox, index_msgno, &index_record); + original_mailbox_quota += index_record.size; + } + sync_counts_clear(&index); index.newhighestmodseq = mailbox->highestmodseq; @@ -631,9 +638,11 @@ /* Record quota addition */ if (!r && mailbox->quota.root) { + quota_t quota_delta = (index.newquota_used - original_mailbox_quota); + r = quota_read(&mailbox->quota, &tid, 1); if (!r) { - mailbox->quota.used = index.newquota_used; + mailbox->quota.used += quota_delta; r = quota_write(&mailbox->quota, &tid); if (!r) quota_commit(&tid); } @@ -642,8 +651,7 @@ if (r) { syslog(LOG_ERR, "LOSTQUOTA: unable to record add of " QUOTA_T_FMT - " bytes in quota %s", - index.newquota_used - original_quota, mailbox->quota.root); + " bytes in quota %s", quota_delta, mailbox->quota.root); } }