imap-client.h revision 9ac30c648aebe0660f137af18749917e2b62b556
#ifndef IMAP_CLIENT_H
#define IMAP_CLIENT_H
#include "imap-commands.h"
#include "message-size.h"
#define CLIENT_COMMAND_QUEUE_MAX_SIZE 4
/* 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. */
#define CLIENT_MAX_SEARCH_UPDATES 10
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;
struct mail_search_result *result;
bool return_uids;
struct imap_fetch_context *fetch_ctx;
};
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_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;
enum command_flags cmd_flags;
const char *tagline_reply;
void *context;
/* Module-specific contexts. */
struct imap_parser *parser;
enum client_command_state state;
/* time when command handling was started - typically this is after
reading all the parameters. */
struct timeval start_time;
/* time when command handling was last finished. this is before
mailbox syncing is done. */
struct timeval last_run_timeval;
/* 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_sync_context *sync;
bool param_error:1;
bool tagline_sent:1;
bool executing:1;
};
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);
};
struct client {
struct imap_client_vfuncs v;
const char *session_id;
const char *const *userdb_fields; /* for internal session saving/restoring */
struct mail_storage_service_user *service_user;
const struct imap_settings *set;
const struct lda_settings *lda_set;
struct mailbox_keywords keywords;
unsigned int sync_counter;
unsigned int bad_counter;
/* one parser is kept here to be used for new commands */
struct imap_parser *free_parser;
/* command_pool is cleared when the command queue gets empty */
/* New commands are always prepended to the queue */
struct client_command_context *command_queue;
unsigned int command_queue_size;
/* For imap_logout_format statistics: */
unsigned int fetch_hdr_count, fetch_body_count;
/* SEARCHRES extension: Last saved SEARCH result */
/* SEARCH=CONTEXT extension: Searches that get updated */
/* NOTIFY extension */
struct imap_notify_context *notify_ctx;
struct client_command_context *input_lock;
struct client_command_context *output_cmd_lock;
/* command changing the mailbox */
/* IMAP URLAUTH context (RFC4467) */
struct imap_urlauth_context *urlauth_ctx;
/* Module-specific contexts. */
/* syncing marks this TRUE when it sees \Deleted flags. this is by
EXPUNGE for Outlook-workaround. */
bool sync_seen_deletes:1;
bool disconnected:1;
bool destroyed:1;
bool handling_input:1;
bool syncing:1;
bool id_logged:1;
bool mailbox_examined:1;
bool anvil_sent:1;
bool tls_compression:1;
found a new line */
bool modseqs_sent_since_sync:1;
bool notify_immediate_expunges:1;
bool notify_count_changes:1;
bool notify_flag_changes:1;
bool imap_metadata_enabled:1;
bool nonpermanent_modseqs:1;
bool state_import_bad_idle_done:1;
bool state_import_idle_continue:1;
};
struct imap_module_register {
unsigned int id;
};
union imap_module_context {
struct imap_client_vfuncs super;
struct imap_module_register *reg;
};
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 lda_settings *lda_set);
/* Disconnect client connection */
/* 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. */
#endif