imap-client.h revision 567b56c2d6a1063cad997c956f3ed1d9d735f14e
7ef5ca6fb59a318c821a852ae48a2edbb671d7ddTimo Sirainen/* Maximum number of CONTEXT=SEARCH UPDATEs. Clients probably won't need more
7ef5ca6fb59a318c821a852ae48a2edbb671d7ddTimo Sirainen than a few, so this is mainly to avoid more or less accidental pointless
cd56a23e21f1df3f79648cf07e2f4385e2fadebbTimo Sirainen resource usage. */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen /* All keyword names. The array itself exists in mail_index.
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainen Keywords are currently only appended, they're never removed. */
e0c3d5460d1cc0c440cb7723c8c2eef8d0afe9b9Timo Sirainen /* Number of keywords announced to client via FLAGS/PERMANENTFLAGS.
e0c3d5460d1cc0c440cb7723c8c2eef8d0afe9b9Timo Sirainen This relies on keywords not being removed while mailbox is
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen /* Waiting for more input */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen /* Waiting to be able to send more output */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen /* Waiting for external interaction */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen /* Wait for other commands to finish execution */
daf029d2a627daa39d05507140f385162828172eTimo Sirainen /* Waiting for other commands to finish so we can sync */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen /* Command is finished */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen /* time when command handling was started - typically this is after
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen reading all the parameters. */
9e095dd6a77097356aca8216356d4d71ef1bea45Timo Sirainen /* time when command handling was last finished. this is before
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen mailbox syncing is done. */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen /* io_loop_get_wait_usecs()'s value when the command was started */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen /* how many usecs this command itself has spent running */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen /* how many usecs this command itself has spent waiting for locks */
20344c0e814139e3c365fbb9287478f91512089eTimo Sirainen /* how many bytes of client input/output command has used */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen /* IMAP command tag */
20344c0e814139e3c365fbb9287478f91512089eTimo Sirainen const char *tag;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen /* Name of this command */
dd62b77c932d1b518f2a3e4bf80e36542becc256Timo Sirainen /* Parameters for this command. These are generated from parsed IMAP
dd62b77c932d1b518f2a3e4bf80e36542becc256Timo Sirainen arguments, so they may not be exactly the same as how client sent
35df1dd606c5ef21068ab4fe4be305859d4fad4bTimo Sirainen /* Module-specific contexts. */
601f5f14c6cde28f0e0c6ca7c5d735315d3d48dfTimo Sirainen ARRAY(union imap_module_context *) module_contexts;
602a0434db30d8e3292d1c161a803d96a879a74fTimo Sirainen bool cancel:1; /* command is wanted to be cancelled */
602a0434db30d8e3292d1c161a803d96a879a74fTimo Sirainen bool search_save_result:1; /* search result is being updated */
602a0434db30d8e3292d1c161a803d96a879a74fTimo Sirainen bool search_save_result_used:1; /* command uses search save */
602a0434db30d8e3292d1c161a803d96a879a74fTimo Sirainen bool temp_executed:1; /* temporary execution state tracking */
602a0434db30d8e3292d1c161a803d96a879a74fTimo Sirainen /* Export client state into buffer. Returns 1 if ok, 0 if some state
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen couldn't be preserved, -1 if temporary internal error occurred. */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen int (*state_export)(struct client *client, bool internal,
dd62b77c932d1b518f2a3e4bf80e36542becc256Timo Sirainen /* Import a single block of client state from the given data. Returns
dd62b77c932d1b518f2a3e4bf80e36542becc256Timo Sirainen number of bytes successfully imported from the block, or 0 if state
dd62b77c932d1b518f2a3e4bf80e36542becc256Timo Sirainen is corrupted or contains unknown data (e.g. some plugin is no longer
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainen loaded), -1 if temporary internal error occurred. */
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainen ssize_t (*state_import)(struct client *client, bool internal,
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainen const char **error_r);
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen void (*destroy)(struct client *client, const char *reason);
dd62b77c932d1b518f2a3e4bf80e36542becc256Timo Sirainen const char *const *userdb_fields; /* for internal session saving/restoring */
7e1f68ad71d3485f1882142837b01f7a98ca8467Timo Sirainen struct timeout *to_idle, *to_idle_output, *to_delayed_input;
e0c3d5460d1cc0c440cb7723c8c2eef8d0afe9b9Timo Sirainen struct mail_storage_service_user *service_user;
e0c3d5460d1cc0c440cb7723c8c2eef8d0afe9b9Timo Sirainen uint32_t messages_count, recent_count, uidvalidity;
e0c3d5460d1cc0c440cb7723c8c2eef8d0afe9b9Timo Sirainen /* one parser is kept here to be used for new commands */
e0c3d5460d1cc0c440cb7723c8c2eef8d0afe9b9Timo Sirainen /* command_pool is cleared when the command queue gets empty */
e0c3d5460d1cc0c440cb7723c8c2eef8d0afe9b9Timo Sirainen /* New commands are always prepended to the queue */
e0c3d5460d1cc0c440cb7723c8c2eef8d0afe9b9Timo Sirainen /* For imap_logout_format statistics: */
e0c3d5460d1cc0c440cb7723c8c2eef8d0afe9b9Timo Sirainen unsigned int fetch_hdr_count, fetch_body_count;
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen unsigned int deleted_count, expunged_count, trashed_count;
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen /* SEARCHRES extension: Last saved SEARCH result */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen /* SEARCH=CONTEXT extension: Searches that get updated */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen ARRAY(struct imap_search_update) search_updates;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen /* NOTIFY extension */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen /* client input/output is locked by this command */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen struct client_command_context *output_cmd_lock;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen /* command changing the mailbox */
8d80659e504ffb34bb0c6a633184fece35751b18Timo Sirainen struct client_command_context *mailbox_change_lock;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen /* IMAP URLAUTH context (RFC4467) */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen /* Module-specific contexts. */
3e25b17126e9536736d5da03697613e4c3af5f76Timo Sirainen ARRAY(union imap_module_context *) module_contexts;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen /* syncing marks this TRUE when it sees \Deleted flags. this is by
e0c3d5460d1cc0c440cb7723c8c2eef8d0afe9b9Timo Sirainen EXPUNGE for Outlook-workaround. */
89e195dfb5c4b0efd9b9f459771a4467674e5b1fTimo Sirainen bool input_skip_line:1; /* skip all the data until we've
89e195dfb5c4b0efd9b9f459771a4467674e5b1fTimo Sirainen found a new line */
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen unsigned int id;
c06f4017027263cf3a08becc551f5126409e2a83Timo Sirainenextern struct imap_module_register imap_module_register;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenextern unsigned int imap_client_count;
c06f4017027263cf3a08becc551f5126409e2a83Timo Sirainen/* Create new client with specified input/output handles. socket specifies
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen if the handle is a socket. */
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainenstruct client *client_create(int fd_in, int fd_out, const char *session_id,
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen struct mail_storage_service_user *service_user,
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenvoid client_destroy(struct client *client, const char *reason) ATTR_NULL(2);
c06f4017027263cf3a08becc551f5126409e2a83Timo Sirainen/* Disconnect client connection */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenvoid client_disconnect(struct client *client, const char *reason);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenvoid client_disconnect_with_error(struct client *client, const char *msg);
c06f4017027263cf3a08becc551f5126409e2a83Timo Sirainen/* Send a line of data to client. */
c06f4017027263cf3a08becc551f5126409e2a83Timo Sirainenvoid client_send_line(struct client *client, const char *data);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen/* Send a line of data to client. Returns 1 if ok, 0 if buffer is getting full,
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen -1 if error. This should be used when you're (potentially) sending a lot of
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen lines to client. */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenint client_send_line_next(struct client *client, const char *data);
37ab3cde96bfa4bc5304c0c348fc420aec79572dTimo Sirainen/* Send line of data to client, prefixed with client->tag. You need to prefix
c06f4017027263cf3a08becc551f5126409e2a83Timo Sirainen the data with "OK ", "NO " or "BAD ". */
c06f4017027263cf3a08becc551f5126409e2a83Timo Sirainenvoid client_send_tagline(struct client_command_context *cmd, const char *data);
37ab3cde96bfa4bc5304c0c348fc420aec79572dTimo Sirainen/* Send a BAD command reply to client via client_send_tagline(). If there have
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen been too many command errors, the client is disconnected. msg may be NULL,
f4bbeadda12fbd7c219063db68f3e78646d83c2cTimo Sirainen in which case the error is looked up from imap_parser. */
0b47e9f5e0181053b4d9ca7b426b0e5c185e820eTimo Sirainenvoid client_send_command_error(struct client_command_context *cmd,
0b47e9f5e0181053b4d9ca7b426b0e5c185e820eTimo Sirainen const char *msg);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen/* Send a NO command reply with the default internal error message to client
c06f4017027263cf3a08becc551f5126409e2a83Timo Sirainen via client_send_tagline(). */
c06f4017027263cf3a08becc551f5126409e2a83Timo Sirainenvoid client_send_internal_error(struct client_command_context *cmd);
c06f4017027263cf3a08becc551f5126409e2a83Timo Sirainen/* Read a number of arguments. Returns TRUE if everything was read or
c06f4017027263cf3a08becc551f5126409e2a83Timo Sirainen FALSE if either needs more data or error occurred. */
c06f4017027263cf3a08becc551f5126409e2a83Timo Sirainenbool client_read_args(struct client_command_context *cmd, unsigned int count,
c06f4017027263cf3a08becc551f5126409e2a83Timo Sirainen unsigned int flags, const struct imap_arg **args_r);
c06f4017027263cf3a08becc551f5126409e2a83Timo Sirainen/* Reads a number of string arguments. ... is a list of pointers where to
c06f4017027263cf3a08becc551f5126409e2a83Timo Sirainen store the arguments. */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenbool client_read_string_args(struct client_command_context *cmd,
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen unsigned int count, ...);
904f9d5654b9c39edcdf32883e5e88771faf4d69Timo Sirainen/* SEARCHRES extension: Call if $ is being used/updated, returns TRUE if we
904f9d5654b9c39edcdf32883e5e88771faf4d69Timo Sirainen have to wait for an existing SEARCH SAVE to finish. */
904f9d5654b9c39edcdf32883e5e88771faf4d69Timo Sirainenbool client_handle_search_save_ambiguity(struct client_command_context *cmd);
904f9d5654b9c39edcdf32883e5e88771faf4d69Timo Sirainenint client_enable(struct client *client, enum mailbox_feature features);
904f9d5654b9c39edcdf32883e5e88771faf4d69Timo Sirainen/* Send client processing to imap-idle process. If successful, returns TRUE
904f9d5654b9c39edcdf32883e5e88771faf4d69Timo Sirainen and destroys the client. */
904f9d5654b9c39edcdf32883e5e88771faf4d69Timo Sirainenbool imap_client_hibernate(struct client **client);
7ef5ca6fb59a318c821a852ae48a2edbb671d7ddTimo Sirainenclient_search_update_lookup(struct client *client, const char *tag,
7ef5ca6fb59a318c821a852ae48a2edbb671d7ddTimo Sirainen unsigned int *idx_r);
7ef5ca6fb59a318c821a852ae48a2edbb671d7ddTimo Sirainenvoid client_search_updates_free(struct client *client);
7ef5ca6fb59a318c821a852ae48a2edbb671d7ddTimo Sirainenstruct client_command_context *client_command_alloc(struct client *client);
7ef5ca6fb59a318c821a852ae48a2edbb671d7ddTimo Sirainenvoid client_command_cancel(struct client_command_context **cmd);
7ef5ca6fb59a318c821a852ae48a2edbb671d7ddTimo Sirainenvoid client_command_free(struct client_command_context **cmd);
7ef5ca6fb59a318c821a852ae48a2edbb671d7ddTimo Sirainenbool client_handle_unfinished_cmd(struct client_command_context *cmd);
7ef5ca6fb59a318c821a852ae48a2edbb671d7ddTimo Sirainen/* Handle any pending command input. This must be run at the end of all
7ef5ca6fb59a318c821a852ae48a2edbb671d7ddTimo Sirainen I/O callbacks after they've (potentially) finished some commands. */
7ef5ca6fb59a318c821a852ae48a2edbb671d7ddTimo Sirainenvoid client_continue_pending_input(struct client *client);
7ef5ca6fb59a318c821a852ae48a2edbb671d7ddTimo Sirainenvoid client_add_missing_io(struct client *client);
7ef5ca6fb59a318c821a852ae48a2edbb671d7ddTimo Sirainenconst char *client_stats(struct client *client);
7ef5ca6fb59a318c821a852ae48a2edbb671d7ddTimo Sirainenbool client_handle_input(struct client *client);