changeset 21363:cf8705ec586c

autoexpunge: Consider last_rename_stamp on expunge 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.
author Aki Tuomi <aki.tuomi@dovecot.fi>
date Tue, 27 Dec 2016 14:01:14 +0200
parents ef9c844a24bd
children 518bc42408d6
files src/lib-storage/mail-autoexpunge.c
diffstat 1 files changed, 10 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/mail-autoexpunge.c	Wed Dec 28 22:45:22 2016 +0200
+++ b/src/lib-storage/mail-autoexpunge.c	Tue Dec 27 14:01:14 2016 +0200
@@ -18,7 +18,9 @@
 	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 @@
 	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 @@
 			/* 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) {