]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
autoexpunge: Consider last_rename_stamp on expunge
authorAki Tuomi <aki.tuomi@dovecot.fi>
Tue, 27 Dec 2016 12:01:14 +0000 (14:01 +0200)
committerAki Tuomi <aki.tuomi@dovecot.fi>
Tue, 3 Jan 2017 10:43:34 +0000 (12:43 +0200)
When expunging by saved date, see if last_rename_stamp
is more recent than saved date, and use that instead.

This prevents mails getting deleted on a folder that
was just renamed, the user probably expects autoexpunge
to consider these emails as fresh.

src/lib-storage/mail-autoexpunge.c

index b871f4a41ad11021b4ab00bd049d2b910cfdf426..95477216a17f3d0e7175fb5e01bce8eb74738142 100644 (file)
@@ -18,7 +18,9 @@ mailbox_autoexpunge(struct mailbox *box, unsigned int interval_time,
        const struct mail_index_header *hdr;
        struct mailbox_status status;
        uint32_t seq;
-       time_t timestamp, expire_time;
+       time_t timestamp, expire_time, last_rename_stamp = 0;
+       const void *data;
+       size_t size;
        int ret = 0;
 
        if ((unsigned int)ioloop_time < interval_time)
@@ -50,6 +52,12 @@ mailbox_autoexpunge(struct mailbox *box, unsigned int interval_time,
        if (mailbox_sync(box, MAILBOX_SYNC_FLAG_FAST) < 0)
                return -1;
 
+       mail_index_get_header_ext(box->view, box->box_last_rename_stamp_ext_id,
+                                 &data, &size);
+
+       if (size >= sizeof(uint32_t))
+               last_rename_stamp = *(const uint32_t*)data;
+
        t = mailbox_transaction_begin(box, 0);
        mail = mail_alloc(t, 0, NULL);
 
@@ -65,7 +73,7 @@ mailbox_autoexpunge(struct mailbox *box, unsigned int interval_time,
                        /* only max_mails is used. nothing further to do. */
                        break;
                } else if (mail_get_save_date(mail, &timestamp) == 0) {
-                       if (timestamp > expire_time)
+                       if (I_MAX(last_rename_stamp, timestamp) > expire_time)
                                break;
                        mail_expunge(mail);
                } else if (mailbox_get_last_mail_error(box) == MAIL_ERROR_EXPUNGED) {