]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Initial implementation of doveadm tool.
authorTimo Sirainen <tss@iki.fi>
Fri, 10 Apr 2009 17:16:44 +0000 (13:16 -0400)
committerTimo Sirainen <tss@iki.fi>
Fri, 10 Apr 2009 17:16:44 +0000 (13:16 -0400)
--HG--
branch : HEAD

.hgignore
src/util/doveadm.c [new file with mode: 0644]

index e9ffb2b74ab628907163a95d7ece198f32feb224..7d7db71a1fbba4891fdf565838d18e6a5ce9061e 100644 (file)
--- 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 (file)
index 0000000..f0d6bb1
--- /dev/null
@@ -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 <stdlib.h>
+
+static struct mail_user *mail_user;
+
+static void ATTR_NORETURN
+usage(void)
+{
+       i_fatal("usage: doveadm purge <user>\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;
+}