trash-plugin.c revision e1601524250623c6fbcfc5ac39a800d569df83d2
/* Copyright (C) 2005 Timo Sirainen */
#include "lib.h"
#include "array.h"
#include "istream.h"
#include "home-expand.h"
#include "mail-search.h"
#include "quota-private.h"
#include "quota-plugin.h"
#include "trash-plugin.h"
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#define INIT_TRASH_MAILBOX_COUNT 4
#define MAX_RETRY_COUNT 3
struct trash_mailbox {
const char *name;
int priority; /* lower number = higher priority */
struct mail_storage *storage;
/* temporarily set while cleaning: */
struct mailbox_transaction_context *trans;
struct mail_search_arg search_arg;
struct mail_search_context *search_ctx;
unsigned int mail_set:1;
};
const char *trash_plugin_version = PACKAGE_VERSION;
static int (*trash_next_quota_test_alloc)(struct quota_transaction_context *,
uoff_t, bool *);
static pool_t config_pool;
/* trash_boxes ordered by priority, highest first */
{
struct mailbox_sync_context *ctx;
struct mailbox_sync_rec sync_rec;
;
}
{
return -1;
return -1;
}
{
int ret;
else
if (ret <= 0)
return ret;
}
return 1;
}
{
struct trash_mailbox *trashes;
unsigned int i, j, count, oldest_idx;
int ret = 0;
for (i = 0; i < count; ) {
/* FIXME: this is really ugly. it'll do however until
we get proper namespace support for lib-storage. */
struct mail_storage *const *storage;
}
/* expunge oldest mails first in all trash boxes with
same priority */
oldest_idx = count;
for (j = i; j < count; j++) {
break;
&received);
if (ret < 0)
goto __err;
if (ret > 0) {
oldest_idx = j;
}
}
}
if (oldest_idx < count) {
/* maybe expunged already? */
continue;
}
break;
size_expunged += size;
if (size_expunged >= size_needed)
break;
} else {
/* find more mails from next priority's mailbox */
i = j;
}
}
for (i = 0; i < count; i++) {
continue;
if (size_expunged >= size_needed) {
} else {
/* couldn't get enough space, don't expunge anything */
}
}
if (size_expunged < size_needed)
return FALSE;
return TRUE;
}
static int
{
int ret, i;
for (i = 0; ; i++) {
if (ret != 0 || *too_large_r)
return ret;
if (i == MAX_RETRY_COUNT) {
/* trash_try_clean_mails() should have returned 0 if
it couldn't get enough space, but allow retrying
it a couple of times if there was some extra space
that was needed.. */
break;
}
/* not enough space. try deleting some from mailbox. */
if (ret <= 0)
return 0;
}
return 0;
}
{
}
static int read_configuration(const char *path)
{
struct trash_mailbox *trash;
unsigned int count;
int fd;
if (fd == -1) {
return -1;
}
/* <priority> <mailbox name> */
continue;
}
return 0;
}
void trash_plugin_init(void)
{
const char *env;
return;
i_error("trash plugin: quota plugin not initialized");
return;
}
sizeof(trash_boxes) +
(sizeof(struct trash_mailbox) + 32));
if (read_configuration(env) < 0)
return;
}
void trash_plugin_deinit(void)
{
if (config_pool != NULL)
}