expire-tool.c revision 367e28a16854ee9f7247b2518f36f5e9163fcc10
/* Copyright (c) 2006-2009 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "env-util.h"
#include "dict.h"
#include "master-service.h"
#include "master-service-settings.h"
#include "mail-index.h"
#include "mail-search-build.h"
#include "mail-storage.h"
#include "mail-storage-service.h"
#include "mail-namespace.h"
#include "auth-client.h"
#include "auth-master.h"
#include "expire-env.h"
#include <stdlib.h>
struct expire_context {
struct mail_storage_service_multi_ctx *multi;
bool testrun;
};
static int
const char *mailbox,
unsigned int expunge_secs, unsigned int altmove_secs,
{
struct mail_namespace *ns;
struct mail_storage *storage;
struct mail_search_context *search_ctx;
struct mailbox_transaction_context *t;
struct mail_search_args *search_args;
const char *ns_mailbox, *errstr;
enum mail_error error;
enum mail_flags flags;
int ret;
*oldest_r = 0;
user));
&multi_user, &errstr);
if (ret <= 0) {
return ret;
}
if (ret < 0) {
return ret;
}
}
/* entire namespace no longer exists, remove the entry */
return 0;
}
if (error != MAIL_ERROR_NOTFOUND) {
i_error("%s: Opening mailbox %s failed: %s",
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/%s: seq=%u uid=%u: "
"Save date lookup failed",
}
ret = -1;
break;
}
expunge_secs != 0) {
else {
i_info("%s/%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/%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;
}
{
struct expire_context ctx;
const struct mail_user_settings *user_set;
void **sets;
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");
if (expire_dict == NULL)
i_fatal("expire_dict setting not set");
i_fatal("dict_init() failed");
/* We'll get the oldest values (timestamps) first */
/* key = DICT_EXPIRE_PREFIX<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 {
i_info("%s: mailbox '%s' removed from config",
}
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",
}
}
}
i_info("No entries in dictionary");
if (!testrun)
else
dict_deinit(&dict);
}
{
struct master_service *service;
const char *getopt_str;
int c;
switch (c) {
case 't':
break;
default:
i_fatal("Unknown parameter: -%c", c);
break;
}
}
return 0;
}