imap-commands.h revision 9b2e48654bdf2ad716051954afcf18608e1ab5c9
5f5870385cff47efd2f58e7892f251cf13761528Timo Sirainen#ifndef IMAP_COMMANDS_H
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen#define IMAP_COMMANDS_H
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen
0536ccb51d41e3078c3a9fa33e509fb4b2420f95Timo Sirainenstruct client_command_context;
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen#include "mail-storage.h"
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen#include "mail-namespace.h"
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen#include "imap-parser.h"
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen#include "imap-sync.h"
4fdf60e22b5340fe35f083b9ea5eb3fd1cf2e742Timo Sirainen#include "imap-commands-util.h"
4fdf60e22b5340fe35f083b9ea5eb3fd1cf2e742Timo Sirainen
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainentypedef bool command_func_t(struct client_command_context *cmd);
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainentypedef void command_hook_callback_t(struct client_command_context *ctx);
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen
252db51b6c0a605163326b3ea5d09e9936ca3b29Timo Sirainenenum command_flags {
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen /* Command uses sequences as its input parameters */
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen COMMAND_FLAG_USES_SEQS = 0x01,
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen /* Command may reply with EXPUNGE, causing sequences to break */
34435ce4a468dc13b23db69dbdd09fe20be88816Timo Sirainen COMMAND_FLAG_BREAKS_SEQS = 0x02,
34435ce4a468dc13b23db69dbdd09fe20be88816Timo Sirainen /* Command changes the mailbox */
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen COMMAND_FLAG_BREAKS_MAILBOX = 0x04 | COMMAND_FLAG_BREAKS_SEQS,
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen /* Command uses selected mailbox */
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen COMMAND_FLAG_USES_MAILBOX = COMMAND_FLAG_BREAKS_MAILBOX |
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen COMMAND_FLAG_USES_SEQS,
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen /* Command requires mailbox syncing before it can do its job. */
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen COMMAND_FLAG_REQUIRES_SYNC = 0x08,
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen /* Command allows replying with [NONEXISTENT] imap resp code.
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen Dovecot internally returns it for all kinds of commands,
4fdf60e22b5340fe35f083b9ea5eb3fd1cf2e742Timo Sirainen but unfortunately RFC 5530 specifies it only for "delete something"
4fdf60e22b5340fe35f083b9ea5eb3fd1cf2e742Timo Sirainen operations. */
4fdf60e22b5340fe35f083b9ea5eb3fd1cf2e742Timo Sirainen COMMAND_FLAG_USE_NONEXISTENT = 0x10
4fdf60e22b5340fe35f083b9ea5eb3fd1cf2e742Timo Sirainen};
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenstruct command {
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen const char *name;
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen command_func_t *func;
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen enum command_flags flags;
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen};
4334b9b032298defd4d3906f5357698ff016ead0Timo SirainenARRAY_DEFINE_TYPE(command, struct command);
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainen
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainenextern ARRAY_TYPE(command) imap_commands;
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainen
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainen/* Register command. Given name parameter must be permanently stored until
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen command is unregistered. */
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenvoid command_register(const char *name, command_func_t *func,
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen enum command_flags flags);
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenvoid command_unregister(const char *name);
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen/* Register array of commands. */
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenvoid command_register_array(const struct command *cmdarr, unsigned int count);
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenvoid command_unregister_array(const struct command *cmdarr, unsigned int count);
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen/* Register hook callbacks that are called before and after all commands */
4fdf60e22b5340fe35f083b9ea5eb3fd1cf2e742Timo Sirainenvoid command_hook_register(command_hook_callback_t *pre,
4fdf60e22b5340fe35f083b9ea5eb3fd1cf2e742Timo Sirainen command_hook_callback_t *post);
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenvoid command_hook_unregister(command_hook_callback_t *pre,
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen command_hook_callback_t *post);
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen/* Execute command and hooks */
4fdf60e22b5340fe35f083b9ea5eb3fd1cf2e742Timo Sirainenbool command_exec(struct client_command_context *cmd);
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen/* Starts counting command statistics. */
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenvoid command_stats_start(struct client_command_context *cmd);
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen/* Finish counting command statistics. This is called automatically when
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen command_exec() returns, but it should be called explicitly if the stats are
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen needed during command_exec(). */
a94936bafd127680184da114c6a177b37ff656e5Timo Sirainenvoid command_stats_flush(struct client_command_context *cmd);
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenstruct command *command_find(const char *name);
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenvoid commands_init(void);
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenvoid commands_deinit(void);
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen
a94936bafd127680184da114c6a177b37ff656e5Timo Sirainen/* IMAP4rev1 commands: */
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen/* Non-Authenticated State */
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenbool cmd_logout(struct client_command_context *cmd);
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenbool cmd_capability(struct client_command_context *cmd);
4fdf60e22b5340fe35f083b9ea5eb3fd1cf2e742Timo Sirainenbool cmd_noop(struct client_command_context *cmd);
4fdf60e22b5340fe35f083b9ea5eb3fd1cf2e742Timo Sirainen
4fdf60e22b5340fe35f083b9ea5eb3fd1cf2e742Timo Sirainen/* Authenticated State */
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenbool cmd_select(struct client_command_context *cmd);
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenbool cmd_examine(struct client_command_context *cmd);
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenbool cmd_create(struct client_command_context *cmd);
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenbool cmd_delete(struct client_command_context *cmd);
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenbool cmd_rename(struct client_command_context *cmd);
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenbool cmd_subscribe(struct client_command_context *cmd);
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainenbool cmd_unsubscribe(struct client_command_context *cmd);
4fdf60e22b5340fe35f083b9ea5eb3fd1cf2e742Timo Sirainen
4fdf60e22b5340fe35f083b9ea5eb3fd1cf2e742Timo Sirainenbool cmd_list(struct client_command_context *cmd);
4fdf60e22b5340fe35f083b9ea5eb3fd1cf2e742Timo Sirainenbool cmd_lsub(struct client_command_context *cmd);
4fdf60e22b5340fe35f083b9ea5eb3fd1cf2e742Timo Sirainen
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenbool cmd_status(struct client_command_context *cmd);
fe363b433b8038a69b55169da9dca27892ad7d18Timo Sirainenbool cmd_append(struct client_command_context *cmd);
4fdf60e22b5340fe35f083b9ea5eb3fd1cf2e742Timo Sirainen
4fdf60e22b5340fe35f083b9ea5eb3fd1cf2e742Timo Sirainen/* Selected state */
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenbool cmd_check(struct client_command_context *cmd);
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenbool cmd_close(struct client_command_context *cmd);
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenbool cmd_expunge(struct client_command_context *cmd);
252db51b6c0a605163326b3ea5d09e9936ca3b29Timo Sirainenbool cmd_search(struct client_command_context *cmd);
a94936bafd127680184da114c6a177b37ff656e5Timo Sirainenbool cmd_fetch(struct client_command_context *cmd);
a94936bafd127680184da114c6a177b37ff656e5Timo Sirainenbool cmd_store(struct client_command_context *cmd);
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenbool cmd_copy(struct client_command_context *cmd);
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenbool cmd_uid(struct client_command_context *cmd);
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen
597dba3488c648ffb375ee4a552bd52ac4346979Timo Sirainen/* IMAP extensions: */
74f810327aca91b3375d3fc963bce8076785b1cbTimo Sirainenbool cmd_cancelupdate(struct client_command_context *cmd);
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenbool cmd_enable(struct client_command_context *cmd);
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenbool cmd_id(struct client_command_context *cmd);
a94936bafd127680184da114c6a177b37ff656e5Timo Sirainenbool cmd_idle(struct client_command_context *cmd);
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenbool cmd_namespace(struct client_command_context *cmd);
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenbool cmd_getmetadata(struct client_command_context *cmd);
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenbool cmd_setmetadata(struct client_command_context *cmd);
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenbool cmd_notify(struct client_command_context *cmd);
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenbool cmd_sort(struct client_command_context *cmd);
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenbool cmd_thread(struct client_command_context *cmd);
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenbool cmd_uid_expunge(struct client_command_context *cmd);
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenbool cmd_move(struct client_command_context *cmd);
34435ce4a468dc13b23db69dbdd09fe20be88816Timo Sirainenbool cmd_unselect(struct client_command_context *cmd);
f8512649cd4db427a8dc5dc8f45c8e379ffd4d76Timo Sirainenbool cmd_x_cancel(struct client_command_context *cmd);
f8512649cd4db427a8dc5dc8f45c8e379ffd4d76Timo Sirainenbool cmd_x_state(struct client_command_context *cmd);
f8512649cd4db427a8dc5dc8f45c8e379ffd4d76Timo Sirainen
f8512649cd4db427a8dc5dc8f45c8e379ffd4d76Timo Sirainen/* IMAP URLAUTH (RFC4467): */
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenbool cmd_genurlauth(struct client_command_context *cmd);
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenbool cmd_resetkey(struct client_command_context *cmd);
f8512649cd4db427a8dc5dc8f45c8e379ffd4d76Timo Sirainenbool cmd_urlfetch(struct client_command_context *cmd);
f8512649cd4db427a8dc5dc8f45c8e379ffd4d76Timo Sirainen
f8512649cd4db427a8dc5dc8f45c8e379ffd4d76Timo Sirainen/* private: */
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenbool cmd_list_full(struct client_command_context *cmd, bool lsub);
f8512649cd4db427a8dc5dc8f45c8e379ffd4d76Timo Sirainenbool cmd_select_full(struct client_command_context *cmd, bool readonly);
63a2f941c1ad029061129ba6384d1d2a02382220Timo Sirainenbool cmd_subscribe_full(struct client_command_context *cmd, bool subscribe);
f8512649cd4db427a8dc5dc8f45c8e379ffd4d76Timo Sirainen
63a2f941c1ad029061129ba6384d1d2a02382220Timo Sirainen#endif
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen