maildir-expunge.c revision 10ffe25023df7de97803cd94cc3ad97ff1c986a7
/* Copyright (C) 2002 Timo Sirainen */
#include "lib.h"
#include "maildir-storage.h"
#include <unistd.h>
static int expunge_msg(IndexMailbox *ibox, MailIndexRecord *rec,
unsigned int seq)
{
const char *fname;
char path[1024];
fname = ibox->index->lookup_field(ibox->index, rec,
FIELD_TYPE_LOCATION);
if (fname != NULL) {
i_snprintf(path, sizeof(path), "%s/cur/%s",
ibox->index->dir, fname);
if (unlink(path) < 0) {
/* if it didn't exist, someone just had either
deleted it or changed it's flags */
mail_storage_set_error(ibox->box.storage,
"unlink() failed for "
"message file %s: %m", path);
return FALSE;
}
}
return ibox->index->expunge(ibox->index, rec, seq, FALSE);
}
int maildir_expunge_locked(IndexMailbox *ibox, int notify)
{
MailIndexRecord *rec;
unsigned int seq, uid;
if (!index_expunge_seek_first(ibox, &seq, &rec))
return FALSE;
while (rec != NULL) {
if (rec->msg_flags & MAIL_DELETED) {
/* save UID before deletion */
uid = rec->uid;
if (!expunge_msg(ibox, rec, seq))
return FALSE;
if (notify) {
ibox->sync_callbacks.expunge(
&ibox->box, seq, uid,
ibox->sync_context);
}
ibox->synced_messages_count--;
seq--;
}
rec = ibox->index->next(ibox->index, rec);
seq++;
}
return TRUE;
}