]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Return vsize=0 from mailbox list index for empty mailboxes.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 30 Nov 2016 22:56:11 +0000 (00:56 +0200)
committerGitLab <gitlab@git.dovecot.net>
Fri, 2 Dec 2016 20:35:28 +0000 (22:35 +0200)
If it's known that the mailbox has no mails, there's no reason to open the
mailbox to see that its size is 0.

src/lib-storage/list/mailbox-list-index-status.c

index a97369d18faabacf80058918174b6f0dae52a31c..ad1bf48549cb796c25a574eb825b66482848bfb1 100644 (file)
@@ -264,8 +264,13 @@ static int index_list_get_cached_vsize(struct mailbox *box, uoff_t *vsize_r)
        ret = mailbox_list_index_status(box->list, view, seq,
                                        STATUS_MESSAGES | STATUS_UIDNEXT,
                                        &status, NULL, &vsize) ? 1 : 0;
-       if (ret > 0 && (vsize.highest_uid + 1 != status.uidnext ||
-                       vsize.message_count != status.messages)) {
+       if (status.messages == 0 && status.uidnext > 0) {
+               /* mailbox is empty. its size has to be zero, regardless of
+                  what the vsize header says. */
+               vsize.vsize = 0;
+               ret = 1;
+       } else if (ret > 0 && (vsize.highest_uid + 1 != status.uidnext ||
+                              vsize.message_count != status.messages)) {
                /* out of date vsize info */
                ret = 0;
        }