From: Timo Sirainen Date: Fri, 10 Apr 2009 17:16:44 +0000 (-0400) Subject: Initial implementation of doveadm tool. X-Git-Tag: 2.0.alpha1~990 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3a5342ae69be9cab488fcbf8939fc1a55da548a2;p=thirdparty%2Fdovecot%2Fcore.git Initial implementation of doveadm tool. --HG-- branch : HEAD --- diff --git a/.hgignore b/.hgignore index e9ffb2b74a..7d7db71a1f 100644 --- a/.hgignore +++ b/.hgignore @@ -75,6 +75,7 @@ src/pop3/pop3 src/tests/test-lib src/tests/test-mail src/tests/test-imap +src/util/doveadm src/util/dovecotpw src/util/gdbhelper src/util/idxview diff --git a/src/util/doveadm.c b/src/util/doveadm.c new file mode 100644 index 0000000000..f0d6bb10e3 --- /dev/null +++ b/src/util/doveadm.c @@ -0,0 +1,82 @@ +/* Copyright (c) 2009 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "env-util.h" +#include "master-service.h" +#include "mail-user.h" +#include "mail-namespace.h" +#include "mail-storage.h" +#include "mail-storage-settings.h" +#include "mail-storage-service.h" + +#include + +static struct mail_user *mail_user; + +static void ATTR_NORETURN +usage(void) +{ + i_fatal("usage: doveadm purge \n"); +} + +static int cmd_purge(struct mail_user *user) +{ + struct mail_namespace *ns; + int ret = 0; + + for (ns = user->namespaces; ns != NULL; ns = ns->next) { + if (ns->type == NAMESPACE_PRIVATE && ns->alias_for == NULL) { + if (mail_storage_purge(ns->storage) < 0) + ret = -1; + } + } + return ret; +} + +int main(int argc, char *argv[]) +{ + enum mail_storage_service_flags service_flags = 0; + struct master_service *service; + const char *getopt_str, *user; + int c, ret = 0; + + service = master_service_init("doveadm", MASTER_SERVICE_FLAG_STANDALONE, + argc, argv); + + user = getenv("USER"); + getopt_str = t_strconcat("u:v", master_service_getopt_string(), NULL); + while ((c = getopt(argc, argv, getopt_str)) > 0) { + switch (c) { + case 'u': + user = optarg; + service_flags |= MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP; + break; + case 'v': + service_flags |= MAIL_STORAGE_SERVICE_FLAG_DEBUG; + break; + default: + if (!master_service_parse_option(service, c, optarg)) + usage(); + } + } + if (optind == argc) + usage(); + + if (user == NULL) + i_fatal("USER environment is missing and -u option not used"); + + mail_user = mail_storage_service_init_user(service, user, NULL, + service_flags); + i_set_failure_prefix(t_strdup_printf("doveadm(%s): ", + mail_user->username)); + + if (strcmp(argv[optind], "purge") == 0) + ret = cmd_purge(mail_user); + else + usage(); + + mail_user_unref(&mail_user); + mail_storage_service_deinit_user(); + master_service_deinit(&service); + return ret < 0 ? 1 : 0; +}