Skip to content

Commit

Permalink
autoexpunge: Consider last_rename_stamp on expunge
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cmouse authored and sirainen committed Jan 9, 2017
1 parent b88c159 commit 79a26b1
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/lib-storage/mail-autoexpunge.c
Expand Up @@ -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)
Expand Down Expand Up @@ -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);

Expand All @@ -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) {
Expand Down

0 comments on commit 79a26b1

Please sign in to comment.