#ifndef IMAP_CLIENT_H
#define IMAP_CLIENT_H
#include "imap-commands.h"
#include "message-size.h"
/* Maximum number of CONTEXT=SEARCH UPDATEs. Clients probably won't need more
than a few, so this is mainly to avoid more or less accidental pointless
resource usage. */
struct client;
struct mail_storage;
struct mail_storage_service_ctx;
struct lda_settings;
struct imap_parser;
struct imap_arg;
struct imap_urlauth_context;
struct mailbox_keywords {
/* All keyword names. The array itself exists in mail_index.
Keywords are currently only appended, they're never removed. */
/* Number of keywords announced to client via FLAGS/PERMANENTFLAGS.
This relies on keywords not being removed while mailbox is
selected. */
unsigned int announce_count;
};
struct imap_search_update {
char *tag;
bool return_uids;
};
enum client_command_state {
/* Waiting for more input */
/* Waiting to be able to send more output */
/* Waiting for external interaction */
/* Wait for other commands to finish execution */
/* Waiting for other commands to finish so we can sync */
/* Command is finished */
};
struct client_command_stats {
/* time when command handling was started - typically this is after
reading all the parameters. */
/* time when command handling was last finished. this is before
mailbox syncing is done. */
/* io_loop_get_wait_usecs()'s value when the command was started */
/* how many usecs this command itself has spent running */
/* how many usecs this command itself has spent waiting for locks */
};
struct client_command_stats_start {
};
struct client_command_context {
/* IMAP command tag */
const char *tag;
/* Name of this command */
const char *name;
/* Parameters for this command. These are generated from parsed IMAP
arguments, so they may not be exactly the same as how client sent
them. */
const char *args;
/* Parameters for this command generated with
imap_write_args_for_human(), so it's suitable for logging. */
const char *human_args;
const char *tagline_reply;
void *context;
/* Module-specific contexts. */
};
struct imap_client_vfuncs {
/* Export client state into buffer. Returns 1 if ok, 0 if some state
couldn't be preserved, -1 if temporary internal error occurred. */
/* Import a single block of client state from the given data. Returns
number of bytes successfully imported from the block, or 0 if state
is corrupted or contains unknown data (e.g. some plugin is no longer
loaded), -1 if temporary internal error occurred. */
const char **error_r);
const char *data);
/* Run "mailbox syncing". This can send any unsolicited untagged
replies. Returns 1 = done, 0 = wait for more space in output buffer,
-1 = failed. */
};
struct client {
struct imap_client_vfuncs v;
const char *session_id;
const char *disconnect_reason;
unsigned int sync_counter;
unsigned int bad_counter;
/* one parser is kept here to be used for new commands */
/* command_pool is cleared when the command queue gets empty */
/* New commands are always prepended to the queue */
unsigned int command_queue_size;
char *last_cmd_name;
/* For imap_logout_format statistics: */
/* SEARCHRES extension: Last saved SEARCH result */
/* SEARCH=CONTEXT extension: Searches that get updated */
/* NOTIFY extension */
/* command changing the mailbox */
/* IMAP URLAUTH context (RFC4467) */
/* Module-specific contexts. */
/* syncing marks this TRUE when it sees \Deleted flags. this is by
EXPUNGE for Outlook-workaround. */
found a new line */
};
struct imap_module_register {
unsigned int id;
};
union imap_module_context {
};
extern struct imap_module_register imap_module_register;
extern struct client *imap_clients;
extern unsigned int imap_client_count;
if the handle is a socket. */
struct mail_storage_service_user *service_user,
const struct imap_settings *set,
const struct smtp_submit_settings *smtp_set);
/* Finish creating the client. Returns 0 if ok, -1 if there's an error. */
/* Disconnect client connection */
/* Add the given capability to the CAPABILITY reply. If imap_capability setting
has an explicit capability, nothing is changed. */
/* Send a line of data to client. */
/* Send a line of data to client. Returns 1 if ok, 0 if buffer is getting full,
-1 if error. This should be used when you're (potentially) sending a lot of
lines to client. */
/* Send line of data to client, prefixed with client->tag. You need to prefix
the data with "OK ", "NO " or "BAD ". */
/* Send a BAD command reply to client via client_send_tagline(). If there have
been too many command errors, the client is disconnected. msg may be NULL,
in which case the error is looked up from imap_parser. */
const char *msg);
/* Send a NO command reply with the default internal error message to client
via client_send_tagline(). */
/* Read a number of arguments. Returns TRUE if everything was read or
FALSE if either needs more data or error occurred. */
/* Reads a number of string arguments. ... is a list of pointers where to
store the arguments. */
unsigned int count, ...);
have to wait for an existing SEARCH SAVE to finish. */
/* Send client processing to imap-idle process. If successful, returns TRUE
and destroys the client. */
struct imap_search_update *
unsigned int *idx_r);
/* Handle any pending command input. This must be run at the end of all
I/O callbacks after they've (potentially) finished some commands. */
void clients_destroy_all(void);
#endif