expire-tool.c revision 1dc6f277f5ac6a3dd5cd6aa75a7ef691de9acb7a
/* Copyright (c) 2006-2008 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "ioloop.h"
#include "env-util.h"
#include "file-lock.h"
#include "randgen.h"
#include "lib-signals.h"
#include "dict-client.h"
#include "mail-index.h"
#include "mail-search-build.h"
#include "mail-storage.h"
#include "mail-namespace.h"
#include "auth-client.h"
#include "expire-env.h"
#include <stdlib.h>
/* ugly, but automake doesn't like having it built as both static and
dynamic object.. */
#include "expire-env.c"
struct expire_context {
struct auth_connection *auth_conn;
char *user;
bool testrun;
};
{
int ret;
env_clean();
if (ret < 0)
return ret;
/* user no longer exists */
return 0;
}
return -1;
return 1;
}
{
}
static int
const char *mailbox,
unsigned int expunge_secs, unsigned int altmove_secs,
{
struct mail_namespace *ns;
struct mail_search_context *search_ctx;
struct mailbox_transaction_context *t;
struct mail_search_args *search_args;
const char *ns_mailbox;
enum mail_error error;
enum mail_flags flags;
int ret;
*oldest_r = 0;
return ret;
}
}
/* entire namespace no longer exists, remove the entry */
return 0;
}
if (error != MAIL_ERROR_NOTFOUND)
return -1;
/* mailbox no longer exists, remove the entry */
return 0;
}
t = mailbox_transaction_begin(box, 0);
/* maybe just got expunged. anyway try again later. */
i_info("%s: seq=%u uid=%u: "
"Save date lookup failed",
}
ret = -1;
break;
}
expunge_secs != 0) {
else {
i_info("%s: seq=%u uid=%u: Expunge",
}
altmove_secs != 0) {
/* works only with dbox */
if ((flags & MAIL_INDEX_MAIL_FLAG_BACKEND) != 0) {
/* alread moved */
} else {
i_info("%s: seq=%u uid=%u: Move to alt dir",
}
} else {
/* first non-expired one. */
break;
}
}
if (mailbox_search_deinit(&search_ctx) < 0)
ret = -1;
if (mailbox_transaction_commit(&t) < 0)
ret = -1;
} else {
}
ret = -1;
mailbox_close(&box);
return ret < 0 ? -1 : 0;
}
static void expire_run(bool testrun)
{
struct expire_context ctx;
struct dict_transaction_context *trans;
struct dict_iterate_context *iter;
struct expire_env *env;
unsigned int expunge_secs, altmove_secs;
int ret;
i_fatal("expire and expire_altmove settings not set");
i_fatal("expire_dict setting not set");
if (auth_socket == NULL)
i_fatal("dict_init() failed");
/* We'll get the oldest values (timestamps) first */
/* key = DICT_PATH_SHARED<user>/<mailbox> */
if (p == NULL) {
i_error("Expire dictionary contains invalid key: %s",
key);
continue;
}
mailbox = p + 1;
&expunge_secs, &altmove_secs)) {
/* we're no longer expunging old messages from here */
if (!testrun)
else
continue;
}
/* this and the rest of the timestamps are in future,
so stop processing */
if (testrun) {
i_info("%s: stop, expire time in future: %s",
}
break;
}
T_BEGIN {
const char *username;
altmove_secs, &oldest);
} T_END;
if (ret < 0) {
/* failed to update */
} else if (oldest == 0) {
/* no more messages or mailbox deleted */
if (!testrun)
else
} else {
char new_value[MAX_INT_STRLEN];
oldest += altmove_secs != 0 ?
(unsigned long)oldest);
/* no change */
} else if (!testrun)
else {
i_info("%s: timestamp %s -> %s",
}
}
}
if (!testrun)
else
dict_deinit(&dict);
user_deinit(&ctx);
}
{
lib_init();
random_init();
else
argv++;
}
ioloop = io_loop_create();
lib_deinit();
return 0;
}