doveadm-mail.h revision 0368f3b0ae3fc1ea892da5c5ec02c05c0c3989af
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen /* Parse one getopt() parameter. This is called for each parameter. */
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen bool (*parse_arg)(struct doveadm_mail_cmd_context *ctx, int c);
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen /* Usually not needed. The preinit() is called just after parsing all
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen parameters, but before any userdb lookups are done. This allows the
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen preinit() to alter the userdb lookup behavior (especially
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen service_flags). */
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen void (*preinit)(struct doveadm_mail_cmd_context *ctx);
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen /* Initialize the command. Most importantly if the function prints
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen anything, this should initialize the headers. It shouldn't however
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen do any actual work. The init() is called also when doveadm is
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen performing the work via doveadm-server, which could be running
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen remotely with completely different Dovecot configuration. */
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen void (*init)(struct doveadm_mail_cmd_context *ctx,
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen const char *const args[]);
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen /* Usually not needed. When iterating through multiple users, use this
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen function to get the next username. Overriding this is usually done
091a2dea9d89734a7c1225eed511b3851693a757Timo Sirainen only when there's a known username filter, such as the expire
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen int (*get_next_user)(struct doveadm_mail_cmd_context *ctx,
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen const char **username_r);
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen /* Usually not needed. This is called between
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen mail_storage_service_lookup() and mail_storage_service_next() for
a21f618de284dc22a480af1371d5f5cea50a39dfTimo Sirainen each user. */
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen int (*prerun)(struct doveadm_mail_cmd_context *ctx,
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen struct mail_storage_service_user *service_user,
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen const char **error_r);
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen /* This is the main function which performs all the work for the
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen command. This is called once per each user. */
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen int (*run)(struct doveadm_mail_cmd_context *ctx,
091a2dea9d89734a7c1225eed511b3851693a757Timo Sirainen /* Deinitialize the command. Called once at the end - even if
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen preinit() or init() was never called. */
091a2dea9d89734a7c1225eed511b3851693a757Timo Sirainen void (*deinit)(struct doveadm_mail_cmd_context *ctx);
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen unsigned int id;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen const char *const *args;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen /* args including -options */
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen const char *const *full_args;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen /* connection via doveadm-server */
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen enum mail_storage_service_flags service_flags;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen struct mail_storage_service_ctx *storage_service;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen struct mail_storage_service_input storage_service_input;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen /* search args aren't set for all mail commands */
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen struct mail_storage_service_user *cur_service_user;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen ARRAY(union doveadm_mail_cmd_module_context *) module_contexts;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen /* if non-zero, exit with this code */
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen /* This command is being called by a remote doveadm client. */
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen /* We're handling only a single user */
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen /* We're going through all users (not set for wildcard usernames) */
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen struct doveadm_mail_cmd_context *(*alloc)(void);
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo SirainenARRAY_DEFINE_TYPE(doveadm_mail_cmd, struct doveadm_mail_cmd);
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenextern ARRAY_TYPE(doveadm_mail_cmd) doveadm_mail_cmds;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenextern void (*hook_doveadm_mail_init)(struct doveadm_mail_cmd_context *ctx);
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenextern struct doveadm_mail_cmd_module_register doveadm_mail_cmd_module_register;
a5b64f1abb1cb0a9718d5bf7f0ae808072237259Timo Sirainenbool doveadm_mail_try_run(const char *cmd_name, int argc, char *argv[]);
a5b64f1abb1cb0a9718d5bf7f0ae808072237259Timo Sirainenvoid doveadm_mail_register_cmd(const struct doveadm_mail_cmd *cmd);
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenconst struct doveadm_mail_cmd *doveadm_mail_cmd_find(const char *cmd_name);
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenvoid doveadm_mail_help(const struct doveadm_mail_cmd *cmd) ATTR_NORETURN;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenvoid doveadm_mail_help_name(const char *cmd_name) ATTR_NORETURN;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenvoid doveadm_mail_try_help_name(const char *cmd_name);
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenbool doveadm_mail_has_subcommands(const char *cmd_name);
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainendoveadm_mail_cmd_find_from_argv(const char *cmd_name, int *argc,
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen const char *const **argv);
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainendoveadm_mail_cmd_init(const struct doveadm_mail_cmd *cmd,
fa33df8230c2f27ae863ff83d4251923428d53c7Aki Tuomiint doveadm_mail_single_user(struct doveadm_mail_cmd_context *ctx,
fa33df8230c2f27ae863ff83d4251923428d53c7Aki Tuomi const char **error_r);
fa33df8230c2f27ae863ff83d4251923428d53c7Aki Tuomiint doveadm_mail_server_user(struct doveadm_mail_cmd_context *ctx,
d48e40d6c77d673ad402d96571198d1cce4da225Timo Sirainen const char **error_r);
b78d8dbe4179aabcbf9fda41d282673558dae4d6Timo Sirainen/* Request input stream to be read (from stdin). This must be called from
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen the command's init() function. */
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenvoid doveadm_mail_get_input(struct doveadm_mail_cmd_context *ctx);
fa33df8230c2f27ae863ff83d4251923428d53c7Aki Tuomidoveadm_mailbox_find(struct mail_user *user, const char *mailbox);
fa33df8230c2f27ae863ff83d4251923428d53c7Aki Tuomidoveadm_mail_build_search_args(const char *const args[]);
fa33df8230c2f27ae863ff83d4251923428d53c7Aki Tuomivoid doveadm_mailbox_args_check(const char *const args[]);
8a4a0ef8264d95ffb2ba8f6f109f94ea7f3454e8Timo Sirainendoveadm_mail_mailbox_search_args_build(const char *const args[]);
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenvoid expunge_search_args_check(struct mail_search_args *args, const char *cmd);
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen (type *)doveadm_mail_cmd_alloc_size(sizeof(type))
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenvoid doveadm_mail_failed_error(struct doveadm_mail_cmd_context *ctx,
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenvoid doveadm_mail_failed_storage(struct doveadm_mail_cmd_context *ctx,
7db7fbea5d8a07463b625f93d69166d56018dadfTimo Sirainenvoid doveadm_mail_failed_mailbox(struct doveadm_mail_cmd_context *ctx,
7db7fbea5d8a07463b625f93d69166d56018dadfTimo Sirainenvoid doveadm_mail_failed_list(struct doveadm_mail_cmd_context *ctx,
7db7fbea5d8a07463b625f93d69166d56018dadfTimo Sirainenextern struct doveadm_mail_cmd cmd_flags_remove;
7db7fbea5d8a07463b625f93d69166d56018dadfTimo Sirainenextern struct doveadm_mail_cmd cmd_flags_replace;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenextern struct doveadm_mail_cmd cmd_deduplicate;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenextern struct doveadm_cmd_ver2 doveadm_cmd_mailbox_metadata_set_ver2;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenextern struct doveadm_cmd_ver2 doveadm_cmd_mailbox_metadata_unset_ver2;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenextern struct doveadm_cmd_ver2 doveadm_cmd_mailbox_metadata_get_ver2;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenextern struct doveadm_cmd_ver2 doveadm_cmd_mailbox_metadata_list_ver2;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenextern struct doveadm_cmd_ver2 doveadm_cmd_mailbox_status_ver2;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenextern struct doveadm_cmd_ver2 doveadm_cmd_mailbox_list_ver2;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenextern struct doveadm_cmd_ver2 doveadm_cmd_mailbox_create_ver2;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenextern struct doveadm_cmd_ver2 doveadm_cmd_mailbox_delete_ver2;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenextern struct doveadm_cmd_ver2 doveadm_cmd_mailbox_rename_ver2;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenextern struct doveadm_cmd_ver2 doveadm_cmd_mailbox_subscribe_ver2;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenextern struct doveadm_cmd_ver2 doveadm_cmd_mailbox_unsubscribe_ver2;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo SirainenDOVEADM_CMD_PARAM("A", "all-users", CMD_PARAM_BOOL, 0) \
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo SirainenDOVEADM_CMD_PARAM("S:", "socket-path", CMD_PARAM_STR, 0) \
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo SirainenDOVEADM_CMD_PARAM("u:", "user", CMD_PARAM_STR, 0) \
009217abb57a24a4076092e8e4e165545747839eStephan BoschDOVEADM_CMD_PARAM("F:", "user-file", CMD_PARAM_ISTREAM, 0)