trash-plugin.c revision f8b7943094756bfe85196fc1af2fe453a21f5337
/* 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 MAX_RETRY_COUNT 3
#define TRASH_CONTEXT(obj) \
struct trash_quota_root {
struct quota_backend_vfuncs super;
};
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_context *search_ctx;
unsigned int mail_set:1;
};
/* defined by imap, pop3, lda */
static unsigned int trash_quota_module_id;
static pool_t config_pool;
/* trash_boxes ordered by priority, highest first */
{
struct mail_search_arg search_arg;
trash->search_ctx =
}
{
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; ) {
/* 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) {
break;
if (size >= size_needed) {
size_needed = 0;
break;
}
size_needed -= size;
} else {
/* find more mails from next priority's mailbox */
i = j;
}
}
for (i = 0; i < count; i++) {
if (size_needed == 0) {
} else {
/* couldn't get enough space, don't expunge anything */
}
}
return size_needed == 0;
}
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;
}
{
}
{
struct trash_quota_root *troot;
}
{
}
static int read_configuration(const char *path)
{
struct trash_mailbox *trash;
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;
}
if (read_configuration(env) < 0)
return;
}
void trash_plugin_deinit(void)
{
if (config_pool != NULL)
}