42681892b206d13cb87a5f526d2bf4ff3f2f4af7Timo Sirainen /* Parse one getopt() parameter. This is called for each parameter. */
42681892b206d13cb87a5f526d2bf4ff3f2f4af7Timo Sirainen bool (*parse_arg)(struct doveadm_mail_cmd_context *ctx, int c);
42681892b206d13cb87a5f526d2bf4ff3f2f4af7Timo Sirainen /* Usually not needed. The preinit() is called just after parsing all
42681892b206d13cb87a5f526d2bf4ff3f2f4af7Timo Sirainen parameters, but before any userdb lookups are done. This allows the
42681892b206d13cb87a5f526d2bf4ff3f2f4af7Timo Sirainen preinit() to alter the userdb lookup behavior (especially
42681892b206d13cb87a5f526d2bf4ff3f2f4af7Timo Sirainen service_flags). */
885a3c2287ae3e5827aa580ea06b231de38abb47Timo Sirainen void (*preinit)(struct doveadm_mail_cmd_context *ctx);
42681892b206d13cb87a5f526d2bf4ff3f2f4af7Timo Sirainen /* Initialize the command. Most importantly if the function prints
42681892b206d13cb87a5f526d2bf4ff3f2f4af7Timo Sirainen anything, this should initialize the headers. It shouldn't however
42681892b206d13cb87a5f526d2bf4ff3f2f4af7Timo Sirainen do any actual work. The init() is called also when doveadm is
42681892b206d13cb87a5f526d2bf4ff3f2f4af7Timo Sirainen performing the work via doveadm-server, which could be running
42681892b206d13cb87a5f526d2bf4ff3f2f4af7Timo Sirainen remotely with completely different Dovecot configuration. */
23878bd03d1de531e3261a25598beec621351910Timo Sirainen void (*init)(struct doveadm_mail_cmd_context *ctx,
23878bd03d1de531e3261a25598beec621351910Timo Sirainen const char *const args[]);
42681892b206d13cb87a5f526d2bf4ff3f2f4af7Timo Sirainen /* Usually not needed. When iterating through multiple users, use this
42681892b206d13cb87a5f526d2bf4ff3f2f4af7Timo Sirainen function to get the next username. Overriding this is usually done
42681892b206d13cb87a5f526d2bf4ff3f2f4af7Timo Sirainen only when there's a known username filter, such as the expire
1db62753d9e3b5d71018889c8ef0a3722a307455Timo Sirainen int (*get_next_user)(struct doveadm_mail_cmd_context *ctx,
1db62753d9e3b5d71018889c8ef0a3722a307455Timo Sirainen const char **username_r);
42681892b206d13cb87a5f526d2bf4ff3f2f4af7Timo Sirainen /* Usually not needed. This is called between
42681892b206d13cb87a5f526d2bf4ff3f2f4af7Timo Sirainen mail_storage_service_lookup() and mail_storage_service_next() for
42681892b206d13cb87a5f526d2bf4ff3f2f4af7Timo Sirainen each user. */
62d0db14d2c5008758983c28d242ec158baabf9eTimo Sirainen int (*prerun)(struct doveadm_mail_cmd_context *ctx,
62d0db14d2c5008758983c28d242ec158baabf9eTimo Sirainen struct mail_storage_service_user *service_user,
62d0db14d2c5008758983c28d242ec158baabf9eTimo Sirainen const char **error_r);
42681892b206d13cb87a5f526d2bf4ff3f2f4af7Timo Sirainen /* This is the main function which performs all the work for the
42681892b206d13cb87a5f526d2bf4ff3f2f4af7Timo Sirainen command. This is called once per each user. */
5fbccc935e3f7b916aa7c6e302a212821072e83aTimo Sirainen int (*run)(struct doveadm_mail_cmd_context *ctx,
98e8f95ffee4eacca72b1bcf082f2c735592301bTimo Sirainen /* Deinitialize the command. Called once at the end - even if
98e8f95ffee4eacca72b1bcf082f2c735592301bTimo Sirainen preinit() or init() was never called. */
cf63dc8723b971cc80638fccbf494d961cbafc7fTimo Sirainen void (*deinit)(struct doveadm_mail_cmd_context *ctx);
10b8040903b1d1591f1d44552ff466c8789b8814Timo Sirainen /* args including -options */
885a3c2287ae3e5827aa580ea06b231de38abb47Timo Sirainen enum mail_storage_service_flags service_flags;
1db62753d9e3b5d71018889c8ef0a3722a307455Timo Sirainen struct mail_storage_service_ctx *storage_service;
cdfdb67422891a44fc7d9ace6bc1a00185fd3528Timo Sirainen struct mail_storage_service_input storage_service_input;
1db62753d9e3b5d71018889c8ef0a3722a307455Timo Sirainen /* search args aren't set for all mail commands */
885a3c2287ae3e5827aa580ea06b231de38abb47Timo Sirainen struct mail_storage_service_user *cur_service_user;
4ee00532a265bdfb38539d811fcd12d51210ac35Timo Sirainen ARRAY(union doveadm_mail_cmd_module_context *) module_contexts;
885a3c2287ae3e5827aa580ea06b231de38abb47Timo Sirainen /* if non-zero, exit with this code */
a8281b7c770f4a9a842b19303083fc7f6859e756Timo Sirainen /* This command is being called by a remote doveadm client. */
29f138b4b9bc037b21dfaa6b8e458943a99d5db2Timo Sirainen /* We're handling only a single user */
29f138b4b9bc037b21dfaa6b8e458943a99d5db2Timo Sirainen /* We're going through all users (not set for wildcard usernames) */
2593d6105ecd92f6cd874ed1e3c0faefb37e699bTimo Sirainen /* Add username header to all replies */
23878bd03d1de531e3261a25598beec621351910Timo Sirainen struct doveadm_mail_cmd_context *(*alloc)(void);
a6ab8f00351265e35b79f3a22b1f5a4978ae5c35Timo SirainenARRAY_DEFINE_TYPE(doveadm_mail_cmd, struct doveadm_mail_cmd);
a6ab8f00351265e35b79f3a22b1f5a4978ae5c35Timo Sirainenextern ARRAY_TYPE(doveadm_mail_cmd) doveadm_mail_cmds;
1db62753d9e3b5d71018889c8ef0a3722a307455Timo Sirainenextern void (*hook_doveadm_mail_init)(struct doveadm_mail_cmd_context *ctx);
1db62753d9e3b5d71018889c8ef0a3722a307455Timo Sirainenextern struct doveadm_mail_cmd_module_register doveadm_mail_cmd_module_register;
a6ab8f00351265e35b79f3a22b1f5a4978ae5c35Timo Sirainenbool doveadm_mail_try_run(const char *cmd_name, int argc, char *argv[]);
a6ab8f00351265e35b79f3a22b1f5a4978ae5c35Timo Sirainenvoid doveadm_mail_register_cmd(const struct doveadm_mail_cmd *cmd);
0779e926687b319fe1bcc0f1010ba7f88023e789Timo Sirainenconst struct doveadm_mail_cmd *doveadm_mail_cmd_find(const char *cmd_name);
a9efdb661eb7a8a33aacfdcc3486dcc675a21543Timo Sirainenvoid doveadm_mail_help(const struct doveadm_mail_cmd *cmd) ATTR_NORETURN;
a9efdb661eb7a8a33aacfdcc3486dcc675a21543Timo Sirainenvoid doveadm_mail_help_name(const char *cmd_name) ATTR_NORETURN;
fab850a6aee4aaef4f4795bd7946807a3ba45041Timo Sirainenvoid doveadm_mail_try_help_name(const char *cmd_name);
bd417d416988d11a6b555b9aa57779e7ed976951Timo Sirainenbool doveadm_mail_has_subcommands(const char *cmd_name);
5685e60e62a8e0d368bd28a1526056f97bbba022Timo Sirainendoveadm_mail_cmd_find_from_argv(const char *cmd_name, int *argc,
5685e60e62a8e0d368bd28a1526056f97bbba022Timo Sirainen const char *const **argv);
72bc08129fb0aaec8144cc183a998ccc426fef9eTimo Sirainendoveadm_mail_cmd_init(const struct doveadm_mail_cmd *cmd,
c14c5561e85853d91280235a7611b6050feaebb2Timo Sirainenint doveadm_mail_single_user(struct doveadm_mail_cmd_context *ctx,
c14c5561e85853d91280235a7611b6050feaebb2Timo Sirainen const char **error_r);
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainenint doveadm_mail_server_user(struct doveadm_mail_cmd_context *ctx,
72bc08129fb0aaec8144cc183a998ccc426fef9eTimo Sirainen const struct mail_storage_service_input *input,
2cc88ff507e244faa63683f804833b321a62c665Timo Sirainen const char **error_r);
32c779d5d0b3dabc697408e6b5d9d2e652180b33Timo Sirainen/* Request input stream to be read (from stdin). This must be called from
32c779d5d0b3dabc697408e6b5d9d2e652180b33Timo Sirainen the command's init() function. */
32c779d5d0b3dabc697408e6b5d9d2e652180b33Timo Sirainenvoid doveadm_mail_get_input(struct doveadm_mail_cmd_context *ctx);
51327f2489a4e0e615eb9f7d921473cf8512bb79Timo Sirainendoveadm_mailbox_find(struct mail_user *user, const char *mailbox);
97afa073e3e1e0301dc41173ec34beb08edcce50Timo Sirainendoveadm_mail_build_search_args(const char *const args[]);
636f017be100bce67d66fd3ae1544a47681efd33Timo Sirainenvoid doveadm_mailbox_args_check(const char *const args[]);
b8b085f7bc6f1c0367802a9f00062bbbd981690dTimo Sirainendoveadm_mail_mailbox_search_args_build(const char *const args[]);
b932ee7fbbec6e79b777dcc7ba613b9e99f8337bTimo Sirainenvoid expunge_search_args_check(struct mail_search_args *args, const char *cmd);
23878bd03d1de531e3261a25598beec621351910Timo Sirainen (type *)doveadm_mail_cmd_alloc_size(sizeof(type))
5fbccc935e3f7b916aa7c6e302a212821072e83aTimo Sirainenvoid doveadm_mail_failed_error(struct doveadm_mail_cmd_context *ctx,
5fbccc935e3f7b916aa7c6e302a212821072e83aTimo Sirainenvoid doveadm_mail_failed_storage(struct doveadm_mail_cmd_context *ctx,
5fbccc935e3f7b916aa7c6e302a212821072e83aTimo Sirainenvoid doveadm_mail_failed_mailbox(struct doveadm_mail_cmd_context *ctx,
bb25bed75eefd011138ebf1b8e033fc8ef55ca74Timo Sirainenvoid doveadm_mail_failed_list(struct doveadm_mail_cmd_context *ctx,
0368f3b0ae3fc1ea892da5c5ec02c05c0c3989afAki Tuomiextern struct doveadm_cmd_ver2 doveadm_cmd_mailbox_metadata_set_ver2;
0368f3b0ae3fc1ea892da5c5ec02c05c0c3989afAki Tuomiextern struct doveadm_cmd_ver2 doveadm_cmd_mailbox_metadata_unset_ver2;
0368f3b0ae3fc1ea892da5c5ec02c05c0c3989afAki Tuomiextern struct doveadm_cmd_ver2 doveadm_cmd_mailbox_metadata_get_ver2;
0368f3b0ae3fc1ea892da5c5ec02c05c0c3989afAki Tuomiextern struct doveadm_cmd_ver2 doveadm_cmd_mailbox_metadata_list_ver2;
0368f3b0ae3fc1ea892da5c5ec02c05c0c3989afAki Tuomiextern struct doveadm_cmd_ver2 doveadm_cmd_mailbox_status_ver2;
0368f3b0ae3fc1ea892da5c5ec02c05c0c3989afAki Tuomiextern struct doveadm_cmd_ver2 doveadm_cmd_mailbox_list_ver2;
0368f3b0ae3fc1ea892da5c5ec02c05c0c3989afAki Tuomiextern struct doveadm_cmd_ver2 doveadm_cmd_mailbox_create_ver2;
0368f3b0ae3fc1ea892da5c5ec02c05c0c3989afAki Tuomiextern struct doveadm_cmd_ver2 doveadm_cmd_mailbox_delete_ver2;
0368f3b0ae3fc1ea892da5c5ec02c05c0c3989afAki Tuomiextern struct doveadm_cmd_ver2 doveadm_cmd_mailbox_rename_ver2;
0368f3b0ae3fc1ea892da5c5ec02c05c0c3989afAki Tuomiextern struct doveadm_cmd_ver2 doveadm_cmd_mailbox_subscribe_ver2;
0368f3b0ae3fc1ea892da5c5ec02c05c0c3989afAki Tuomiextern struct doveadm_cmd_ver2 doveadm_cmd_mailbox_unsubscribe_ver2;
89d31290dab6e4bde08b8a118121f008154772e9Aki Tuomiextern struct doveadm_cmd_ver2 doveadm_cmd_fetch_ver2;
5ba6009f4e5493c4e6be9ffb3134525004a7975cAki Tuomiextern struct doveadm_cmd_ver2 doveadm_cmd_save_ver2;
71f4549303dc1691382748a096c2ada9d2a1a9feAki Tuomiextern struct doveadm_cmd_ver2 doveadm_cmd_index_ver2;
844929a7bd6e9d21f0a8cdb3a19f4620a17cdecaAki Tuomiextern struct doveadm_cmd_ver2 doveadm_cmd_altmove_ver2;
e1d08b1c39c63de92f0e914064a508bbf6c6fcc5Aki Tuomiextern struct doveadm_cmd_ver2 doveadm_cmd_deduplicate_ver2;
977f08d645b1779527c0938bbb848b61064839c3Aki Tuomiextern struct doveadm_cmd_ver2 doveadm_cmd_expunge_ver2;
a893aaa999856b1ba6e4541890016767aaa283c7Aki Tuomiextern struct doveadm_cmd_ver2 doveadm_cmd_flags_add_ver2;
a893aaa999856b1ba6e4541890016767aaa283c7Aki Tuomiextern struct doveadm_cmd_ver2 doveadm_cmd_flags_remove_ver2;
a893aaa999856b1ba6e4541890016767aaa283c7Aki Tuomiextern struct doveadm_cmd_ver2 doveadm_cmd_flags_replace_ver2;
ae8c89c81de5d867bd1359fb9c438dd8771210c7Aki Tuomiextern struct doveadm_cmd_ver2 doveadm_cmd_import_ver2;
c874dcb48156e0225ea13d4b66ecfbd32b4fd44dAki Tuomiextern struct doveadm_cmd_ver2 doveadm_cmd_search_ver2;
4ae632e126d92dca465870ad5d7f9341025d6ba4Aki Tuomiextern struct doveadm_cmd_ver2 doveadm_cmd_copy_ver2;
4ae632e126d92dca465870ad5d7f9341025d6ba4Aki Tuomiextern struct doveadm_cmd_ver2 doveadm_cmd_move_ver2;
c220c8cd341ee9ba78979397c5d33ccd98b5d19fAki Tuomiextern struct doveadm_cmd_ver2 doveadm_cmd_mailbox_update_ver2;
209d29ccf7550b0731147c53a0419749270fc501Timo Sirainenextern struct doveadm_cmd_ver2 doveadm_cmd_mailbox_path_ver2;
14102a0c5db8828ca8c7751ec96587fadc97a0bcTimo SirainenDOVEADM_CMD_PARAM('A', "all-users", CMD_PARAM_BOOL, 0) \
14102a0c5db8828ca8c7751ec96587fadc97a0bcTimo SirainenDOVEADM_CMD_PARAM('S', "socket-path", CMD_PARAM_STR, 0) \
14102a0c5db8828ca8c7751ec96587fadc97a0bcTimo SirainenDOVEADM_CMD_PARAM('u', "user", CMD_PARAM_STR, 0) \
14102a0c5db8828ca8c7751ec96587fadc97a0bcTimo SirainenDOVEADM_CMD_PARAM('F', "user-file", CMD_PARAM_ISTREAM, 0)
c45a841bee3f42ec6524b8f62c3fd457115c3f97Timo Sirainen "[-u <user>|-A] [-S <socket_path>] "