imap-client.h revision 4ee00532a265bdfb38539d811fcd12d51210ac35
#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 imap_parser;
struct imap_arg;
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 */
/* 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;
void *context;
/* Module-specific contexts. */
struct imap_parser *parser;
enum client_command_state state;
struct client_sync_context *sync;
unsigned int param_error:1;
};
struct imap_client_vfuncs {
};
struct client {
struct imap_client_vfuncs v;
const char *session_id;
struct mail_storage_service_user *service_user;
const struct imap_settings *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;
/* 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 */
/* Module-specific contexts. */
/* syncing marks this TRUE when it sees \Deleted flags. this is by
EXPUNGE for Outlook-workaround. */
unsigned int sync_seen_deletes:1;
unsigned int sync_seen_expunges:1;
unsigned int disconnected:1;
unsigned int destroyed:1;
unsigned int handling_input:1;
unsigned int syncing:1;
unsigned int id_logged:1;
unsigned int mailbox_examined:1;
unsigned int anvil_sent:1;
unsigned int tls_compression:1;
unsigned int output_locked:1;
found a new line */
unsigned int modseqs_sent_since_sync:1;
unsigned int notify_immediate_expunges:1;
unsigned int notify_count_changes:1;
unsigned int notify_flag_changes: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);
/* 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);
/* 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. */
struct imap_search_update *
unsigned int *idx_r);
void clients_destroy_all(void);
#endif