]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
doveadm: mail: Add trans-flags parameter to doveadm mail commands
authorMarkus Valentin <markus.valentin@open-xchange.com>
Tue, 26 Nov 2019 14:30:47 +0000 (15:30 +0100)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Wed, 4 Dec 2019 13:18:38 +0000 (13:18 +0000)
Add a trans-flags parameter to doveadm-mail calls. This allows to
run mail commands with specific mailbox transaction flags.
mail-storage.h enum mailbox_transaction_flags

All doveadm calls take the defined flag additionally to their orignal
flags. The flags can be set as decimal integer on the doveadm call.

12 files changed:
src/doveadm/doveadm-mail-copymove.c
src/doveadm/doveadm-mail-deduplicate.c
src/doveadm/doveadm-mail-import.c
src/doveadm/doveadm-mail-index.c
src/doveadm/doveadm-mail-iter.c
src/doveadm/doveadm-mail-mailbox-cache.c
src/doveadm/doveadm-mail-mailbox-metadata.c
src/doveadm/doveadm-mail-save.c
src/doveadm/doveadm-mail.c
src/doveadm/doveadm-mail.h
src/plugins/acl/doveadm-acl.c
src/plugins/mail-crypt/doveadm-mail-crypt.c

index 2485463df4e3a5fdef5d4aa0b999b9cc183b0d9a..0115ad0eefc3cafe6543b4117c27375c75ebf76c 100644 (file)
@@ -39,8 +39,8 @@ cmd_copy_box(struct copy_cmd_context *ctx, struct mailbox *destbox,
           this guarantees that mails aren't expunged without actually having
           been copied. */
        desttrans = mailbox_transaction_begin(destbox,
-                                       MAILBOX_TRANSACTION_FLAG_EXTERNAL,
-                                       __func__);
+                                       MAILBOX_TRANSACTION_FLAG_EXTERNAL |
+                                       ctx->ctx.transaction_flags, __func__);
 
        while (doveadm_mail_iter_next(iter, &mail)) {
                save_ctx = mailbox_save_alloc(desttrans);
index 660587f77ef94e590c0aad091ae106b73585b9af..55d747f50205bfbe324aa9030e7f907098285dbf 100644 (file)
@@ -42,7 +42,7 @@ static int cmd_deduplicate_uidlist(struct doveadm_mail_cmd_context *_ctx,
        arg = mail_search_build_add(search_args, SEARCH_UIDSET);
        arg->value.seqset = uids;
 
-       trans = mailbox_transaction_begin(box, 0, __func__);
+       trans = mailbox_transaction_begin(box, _ctx->transaction_flags, __func__);
        search_ctx = mailbox_search_init(trans, search_args, NULL, 0, NULL);
        mail_search_args_unref(&search_args);
 
index fc85202d81f4708c33ea4119405cbb2085047999..3b43c47fd320bbe9458f0c950046fe1d8ff31543 100644 (file)
@@ -91,7 +91,8 @@ dest_mailbox_open_or_create(struct import_cmd_context *ctx,
 }
 
 static int
-cmd_import_box_contents(struct doveadm_mail_iter *iter, struct mail *src_mail,
+cmd_import_box_contents(struct doveadm_mail_cmd_context *ctx,
+                       struct doveadm_mail_iter *iter, struct mail *src_mail,
                        struct mailbox *dest_box)
 {
        struct mail_save_context *save_ctx;
@@ -100,8 +101,8 @@ cmd_import_box_contents(struct doveadm_mail_iter *iter, struct mail *src_mail,
        int ret = 0;
 
        dest_trans = mailbox_transaction_begin(dest_box,
-                                       MAILBOX_TRANSACTION_FLAG_EXTERNAL,
-                                       __func__);
+                                       MAILBOX_TRANSACTION_FLAG_EXTERNAL |
+                                       ctx->transaction_flags, __func__);
        do {
                if (doveadm_debug) {
                        i_debug("import: box=%s uid=%u",
@@ -144,7 +145,7 @@ cmd_import_box(struct import_cmd_context *ctx, struct mail_user *dest_user,
                if (dest_mailbox_open_or_create(ctx, dest_user, info, &box) < 0)
                        ret = -1;
                else {
-                       if (cmd_import_box_contents(iter, mail, box) < 0) {
+                       if (cmd_import_box_contents(&ctx->ctx, iter, mail, box) < 0) {
                                doveadm_mail_failed_mailbox(&ctx->ctx, mail->box);
                                ret = -1;
                        }
index 427722ba6b67361602bfb7ec833e8eeebf2a52a8..bdf28b6236b11914514746d693e15a207ae0a7e5 100644 (file)
@@ -26,7 +26,8 @@ struct index_cmd_context {
        bool have_wildcards:1;
 };
 
-static int cmd_index_box_precache(struct mailbox *box)
+static int cmd_index_box_precache(struct doveadm_mail_cmd_context *dctx,
+                                 struct mailbox *box)
 {
        struct mailbox_status status;
        struct mailbox_transaction_context *trans;
@@ -65,8 +66,8 @@ static int cmd_index_box_precache(struct mailbox *box)
                       mailbox_get_vname(box), seq, status.messages);
        }
 
-       trans = mailbox_transaction_begin(box, MAILBOX_TRANSACTION_FLAG_NO_CACHE_DEC,
-                                         __func__);
+       trans = mailbox_transaction_begin(box, MAILBOX_TRANSACTION_FLAG_NO_CACHE_DEC |
+                                         dctx->transaction_flags, __func__);
        search_args = mail_search_build_init();
        mail_search_build_add_seqset(search_args, seq, status.messages);
        ctx = mailbox_search_init(trans, search_args, NULL,
@@ -133,7 +134,7 @@ cmd_index_box(struct index_cmd_context *ctx, const struct mailbox_info *info)
                doveadm_mail_failed_mailbox(&ctx->ctx, box);
                ret = -1;
        } else {
-               if (cmd_index_box_precache(box) < 0) {
+               if (cmd_index_box_precache(&ctx->ctx, box) < 0) {
                        doveadm_mail_failed_mailbox(&ctx->ctx, box);
                        ret = -1;
                }
index da03c1f6faf5cbec8dda6950939bd2a7d5241699..eb040aee147da9098d0402fb9850dbd55742dbdb 100644 (file)
@@ -58,7 +58,8 @@ int doveadm_mail_iter_init(struct doveadm_mail_cmd_context *ctx,
                NULL : mailbox_header_lookup_init(iter->box, wanted_headers);
 
        mail_search_args_init(search_args, iter->box, FALSE, NULL);
-       iter->t = mailbox_transaction_begin(iter->box, 0, ctx->cmd->name);
+       iter->t = mailbox_transaction_begin(iter->box, ctx->transaction_flags,
+                                           ctx->cmd->name);
        iter->search_ctx = mailbox_search_init(iter->t, search_args, NULL,
                                               wanted_fields, headers_ctx);
        mailbox_header_lookup_unref(&headers_ctx);
index f4d96db0128feaadb00e98f532023a35af8c7b22..da6fc41b7a9634ca03164d49e616ec38ba3f4967 100644 (file)
@@ -182,7 +182,8 @@ static int cmd_mailbox_cache_decision_run_box(struct mailbox_cache_cmd_context *
                                              struct mailbox *box)
 {
        struct mailbox_transaction_context *t =
-               mailbox_transaction_begin(box, 0, "mailbox cache decision");
+               mailbox_transaction_begin(box, ctx->ctx.transaction_flags,
+                                         "mailbox cache decision");
        struct mail_cache *cache = t->box->cache;
        struct mail_cache_view *view;
 
@@ -329,7 +330,8 @@ static int cmd_mailbox_cache_purge_run_box(struct mailbox_cache_cmd_context *ctx
 {
        struct mailbox_transaction_context *t =
                mailbox_transaction_begin(box,
-                                         MAILBOX_TRANSACTION_FLAG_EXTERNAL,
+                                         MAILBOX_TRANSACTION_FLAG_EXTERNAL |
+                                         ctx->ctx.transaction_flags,
                                          "mailbox cache purge");
        struct mail_cache *cache = t->box->cache;
        struct mail_cache_compress_lock *lock;
index 40da3266f83075ce7af02eaaa8308403027acb6e..c75123e9f7ba84528aed48d6eac4de84f6e5b526 100644 (file)
@@ -74,9 +74,9 @@ cmd_mailbox_metadata_set_run(struct doveadm_mail_cmd_context *_ctx,
        if (ret != 0)
                return ret;
 
-       trans = mailbox_transaction_begin(box, ctx->empty_mailbox_name ?
-                                         MAILBOX_TRANSACTION_FLAG_EXTERNAL : 0,
-                                         __func__);
+       trans = mailbox_transaction_begin(box, (ctx->empty_mailbox_name ?
+                                         MAILBOX_TRANSACTION_FLAG_EXTERNAL : 0) |
+                                         ctx->ctx.transaction_flags, __func__);
 
        ret = ctx->value.value == NULL ?
                mailbox_attribute_unset(trans, ctx->key_type, ctx->key) :
index b1c87a4ec05e7a6bd2c82f5d48be6372043a04a7..7b5e6ba13685896992591fe6e4c75c1874fe41c6 100644 (file)
@@ -36,8 +36,8 @@ cmd_save_to_mailbox(struct save_cmd_context *ctx, struct mailbox *box,
                return -1;
        }
 
-       trans = mailbox_transaction_begin(box, MAILBOX_TRANSACTION_FLAG_EXTERNAL,
-                                         __func__);
+       trans = mailbox_transaction_begin(box, MAILBOX_TRANSACTION_FLAG_EXTERNAL |
+                                         ctx->ctx.transaction_flags, __func__);
        save_ctx = mailbox_save_alloc(trans);
        if (mailbox_save_begin(&save_ctx, input) < 0) {
                i_error("Saving failed: %s",
index 2525087e0cb4f3434787d9cbda49cbe960f6faa5..5a50bdbe6c023d1157c395cb080183c5e71a29c2 100644 (file)
@@ -1081,6 +1081,11 @@ doveadm_cmd_ver2_to_mail_cmd_wrapper(struct doveadm_cmd_context *cctx)
                        mctx->cmd_input = arg->value.v_istream;
                        i_stream_ref(mctx->cmd_input);
 
+               } else if (strcmp(arg->name, "trans-flags") == 0) {
+                       /* This parameter allows to set additional
+                        * mailbox transaction flags. */
+                       mctx->transaction_flags = arg->value.v_int64;
+
                /* Keep all named special parameters above this line */
 
                } else if (mctx->v.parse_arg != NULL && arg->short_opt != '\0') {
index 9a2c68e74ce738d7613aa035ab5f4f8e3ac26e99..0292ead5c86955c69b71e68ad9d5c6a17eb48ad0 100644 (file)
@@ -6,6 +6,7 @@
 #include "doveadm-util.h"
 #include "module-context.h"
 #include "mail-error.h"
+#include "mail-storage.h"
 #include "mail-storage-service.h"
 
 struct mailbox;
@@ -70,6 +71,7 @@ struct doveadm_mail_cmd_context {
        const char *getopt_args;
        const struct doveadm_settings *set;
        enum mail_storage_service_flags service_flags;
+       enum mailbox_transaction_flags transaction_flags;
        struct mail_storage_service_ctx *storage_service;
        struct mail_storage_service_input storage_service_input;
        /* search args aren't set for all mail commands */
@@ -204,6 +206,7 @@ extern struct doveadm_cmd_ver2 doveadm_cmd_rebuild_attachments;
 DOVEADM_CMD_PARAM('A', "all-users", CMD_PARAM_BOOL, 0) \
 DOVEADM_CMD_PARAM('S', "socket-path", CMD_PARAM_STR, 0) \
 DOVEADM_CMD_PARAM('u', "user", CMD_PARAM_STR, 0) \
+DOVEADM_CMD_PARAM('\0', "trans-flags", CMD_PARAM_INT64, 0) \
 DOVEADM_CMD_PARAM('F', "user-file", CMD_PARAM_ISTREAM, 0)
 
 #define DOVEADM_CMD_MAIL_USAGE_PREFIX \
index 514dcd44a9f6f2b98f491ddd4c6787a627385e7f..0ab416a24657a6512dd9b936cb52f17743f34318 100644 (file)
@@ -201,14 +201,14 @@ cmd_acl_rights_alloc(void)
 }
 
 static int
-cmd_acl_mailbox_update(struct mailbox *box,
+cmd_acl_mailbox_update(struct doveadm_mail_cmd_context *ctx, struct mailbox *box,
                       const struct acl_rights_update *update)
 {
        struct mailbox_transaction_context *t;
        int ret;
 
-       t = mailbox_transaction_begin(box, MAILBOX_TRANSACTION_FLAG_EXTERNAL,
-                                     __func__);
+       t = mailbox_transaction_begin(box, MAILBOX_TRANSACTION_FLAG_EXTERNAL |
+                                     ctx->transaction_flags, __func__);
        ret = acl_mailbox_update_acl(t, update);
        if (mailbox_transaction_commit(&t) < 0)
                ret = -1;
@@ -235,7 +235,7 @@ cmd_acl_set_run(struct doveadm_mail_cmd_context *_ctx, struct mail_user *user)
        update.neg_modify_mode = ctx->modify_mode;
        if (acl_rights_update_import(&update, id, rights, &error) < 0)
                i_fatal_status(EX_USAGE, "%s", error);
-       if ((ret = cmd_acl_mailbox_update(box, &update)) < 0) {
+       if ((ret = cmd_acl_mailbox_update(&ctx->ctx, box, &update)) < 0) {
                i_error("Failed to set ACL: %s",
                        mailbox_get_last_internal_error(box, NULL));
                doveadm_mail_failed_error(_ctx, MAIL_ERROR_TEMP);
@@ -293,7 +293,7 @@ cmd_acl_delete_run(struct doveadm_mail_cmd_context *ctx, struct mail_user *user)
        i_zero(&update);
        if (acl_rights_update_import(&update, id, NULL, &error) < 0)
                i_fatal_status(EX_USAGE, "%s", error);
-       if ((ret = cmd_acl_mailbox_update(box, &update)) < 0) {
+       if ((ret = cmd_acl_mailbox_update(ctx, box, &update)) < 0) {
                i_error("Failed to delete ACL: %s",
                        mailbox_get_last_internal_error(box, NULL));
                doveadm_mail_failed_error(ctx, MAIL_ERROR_TEMP);
index 8c75a5e870be209cba1bff9bdcf4d58267c66ca4..78e66a2470a71db18926ad71c8af622932e33e70 100644 (file)
@@ -168,7 +168,8 @@ mcp_update_shared_key(struct mailbox_transaction_context *t,
        return ret;
 }
 
-static int mcp_update_shared_keys(struct mailbox *box, struct mail_user *user,
+static int mcp_update_shared_keys(struct doveadm_mail_cmd_context *ctx,
+                                 struct mailbox *box, struct mail_user *user,
                                  const char *pubid, struct dcrypt_private_key *key)
 {
        const char *error;
@@ -192,7 +193,7 @@ static int mcp_update_shared_keys(struct mailbox *box, struct mail_user *user,
        string_t *uid = t_str_new(64);
 
        struct mailbox_transaction_context *t =
-               mailbox_transaction_begin(box, 0, __func__);
+               mailbox_transaction_begin(box, ctx->transaction_flags, __func__);
        
        ret = 0;
 
@@ -423,7 +424,8 @@ static int mcp_keypair_generate_run(struct doveadm_mail_cmd_context *_ctx,
                        res->success = TRUE;
                        res->id = pubid;
                        T_BEGIN {
-                               mcp_update_shared_keys(box, user, pubid, pair.priv);
+                               mcp_update_shared_keys(&ctx->ctx, box, user,
+                                                      pubid, pair.priv);
                        } T_END;
                        if (pair.pub != NULL)
                                dcrypt_key_unref_public(&pair.pub);
@@ -794,7 +796,8 @@ static int cmd_mcp_key_password_run(struct doveadm_mail_cmd_context *_ctx,
 
        if (ret == 1) {
                struct mailbox_transaction_context *t =
-                       mailbox_transaction_begin(box, 0, __func__);
+                       mailbox_transaction_begin(box, _ctx->transaction_flags,
+                                                 __func__);
                struct dcrypt_private_key *key;
                const struct raw_key *raw_key;
                const char *algo = ctx->new_password != NULL ?