imap-client.c revision 8808ae64126694d020a4d454972d48e106ab829a
/* Copyright (c) 2002-2015 Dovecot authors, see the included COPYING file */
#include "imap-common.h"
#include "ioloop.h"
#include "llist.h"
#include "str.h"
#include "hostpid.h"
#include "net.h"
#include "istream.h"
#include "ostream.h"
#include "time-util.h"
#include "var-expand.h"
#include "master-service.h"
#include "imap-resp-code.h"
#include "imap-util.h"
#include "imap-urlauth.h"
#include "mail-error.h"
#include "mail-namespace.h"
#include "mail-storage-service.h"
#include "imap-search.h"
#include "imap-notify.h"
#include "imap-commands.h"
#include <stdlib.h>
#include <unistd.h>
extern struct mail_storage_callbacks mail_storage_callbacks;
extern struct imap_client_vfuncs imap_client_vfuncs;
struct imap_module_register imap_module_register = { 0 };
unsigned int imap_client_count = 0;
{
}
{
struct imap_urlauth_config config;
}
struct mail_storage_service_user *service_user,
const struct imap_settings *set)
{
const struct mail_storage_settings *mail_set;
const char *ident;
bool explicit_capability = FALSE;
/* always use nonblocking I/O */
client->v = imap_client_vfuncs;
} else {
}
/* Enable FUZZY capability only when it actually has
a chance of working */
}
/* NOTIFY is enabled only when mailbox list indexes are
enabled, although even that doesn't necessarily guarantee
it always */
}
/* Enable URLAUTH capability only when dict is
configured correctly */
if (!explicit_capability)
}
if (!explicit_capability)
}
if (ident != NULL) {
}
if (hook_client_created != NULL)
return client;
}
{
bool cmd_ret;
/* a bit kludgy check: cancel command only if it has context
set. currently only append command matches this check. all
other commands haven't even started the processing yet. */
break;
/* fall through */
break;
/* commands haven't started yet */
break;
i_unreached();
}
if (!cmd_ret) {
} else {
}
}
{
static struct var_expand_table static_tab[] = {
};
struct var_expand_table *tab;
}
{
return "Connection closed";
return t_strdup_printf("Connection closed: %s",
}
{
}
{
struct client_command_context *cmd;
if (!client->disconnected) {
}
/* finish off all the queued commands. */
}
/* handle the input_lock command last. it might have been waiting on
other queued commands (although we probably should just drop the
command at that point since it hasn't started running. but this may
change in future). */
}
if (client->anvil_sent) {
"\n", NULL));
}
}
{
}
{
if (client->disconnected)
return;
}
{
}
{
}
{
return -1;
return -1;
/* buffer full, try flushing */
}
return 1;
}
{
int time_msecs;
return;
tag = "*";
T_BEGIN {
&cmd->start_time);
if (time_msecs >= 0) {
}
}
} T_END;
}
const char *msg)
{
bool fatal;
if (fatal) {
return;
}
}
else {
}
"Too many invalid IMAP commands.");
}
/* client_read_args() failures rely on this being set, so that the
command processing is stopped even while command function returns
FALSE. */
}
{
}
{
int ret;
/* all parameters read successfully */
return TRUE;
} else if (ret == -2) {
/* need more data */
/* disconnected */
}
return FALSE;
} else {
/* error, or missing arguments */
"Missing arguments");
return FALSE;
}
}
unsigned int count, ...)
{
const char *str;
unsigned int i;
return FALSE;
for (i = 0; i < count; i++) {
if (IMAP_ARG_IS_EOL(&imap_args[i])) {
break;
}
break;
}
}
return i == count;
}
static struct client_command_context *
enum command_flags flags,
{
struct client_command_context *cmd;
return cmd;
}
return NULL;
}
{
enum command_flags flags;
enum client_command_state max_state =
bool broken_client = FALSE;
return TRUE;
if (cmd->search_save_result_used) {
/* if there are pending commands that update the search
save result, wait */
if (old_cmd->search_save_result)
return TRUE;
}
}
/* there must be no other command running that uses the
selected mailbox */
/* no existing command must be breaking sequences */
/* if existing command uses sequences, we'll have to block */
} else {
return FALSE;
}
/* don't do anything until syncing is finished */
return TRUE;
}
/* don't do anything until mailbox is fully
return TRUE;
}
return FALSE;
}
if (broken_client) {
"Command pipelining results in ambiguity.");
}
return TRUE;
}
{
struct client_command_context *cmd;
return cmd;
}
static struct client_command_context *
{
struct client_command_context *cmd;
} else {
}
return cmd;
}
{
}
{
/* reset input idle time because command output might have taken a
long time and we don't want to disconnect client immediately then */
}
if (!cmd->param_error)
client->bad_counter = 0;
}
/* no commands left in the queue, we can clear the pool */
}
/* if command finished from external event, check input for more
unhandled commands since we may not be executing from client_input
or client_output. */
if (state == CLIENT_COMMAND_STATE_WAIT_EXTERNAL &&
!client->disconnected) {
}
}
}
{
/* there's a command that has locked the input */
return;
/* the command is waiting for existing ambiguity causing
commands to finish. */
if (client_command_is_ambiguous(cmd)) {
/* we could be waiting for existing sync to finish */
if (!cmd_sync_delayed(client))
return;
return;
}
}
/* if there's unread data in buffer, handle it. */
!client->disconnected) {
if (client_handle_input(client))
}
}
/* Skip incoming data until newline is found,
returns TRUE if newline was found. */
{
const unsigned char *data;
for (i = 0; i < data_size; i++) {
if (data[i] == '\n') {
i++;
break;
}
}
return !client->input_skip_line;
}
{
"Disconnected for inactivity in reading our output");
}
{
/* need more input */
return FALSE;
}
/* waiting for something */
/* this is mainly for APPEND. */
}
return TRUE;
}
/* output is blocking, we can execute more commands */
/* disconnect sooner if client isn't reading our output */
}
return TRUE;
}
{
/* command is being executed - continue it */
if (command_exec(cmd)) {
/* command execution was finished */
return TRUE;
}
return client_handle_unfinished_cmd(cmd);
}
return FALSE; /* need more data */
}
return FALSE; /* need more data */
/* UID commands are a special case. better to handle them
here. */
return FALSE; /* need more data */
}
}
/* command not given - cmd->func is already NULL. */
if (client_command_is_ambiguous(cmd)) {
/* do nothing until existing commands are finished */
return FALSE;
}
}
/* unknown command */
return TRUE;
} else {
return client_command_input(cmd);
}
}
{
*remove_io_r = FALSE;
*remove_io_r = TRUE;
return FALSE;
}
}
if (client->input_skip_line) {
/* first eat the previous command line */
if (!client_skip_line(client))
return FALSE;
}
/* don't bother creating a new client command before there's at least
some input */
return FALSE;
/* beginning a new command */
/* wait for some of the commands to finish */
*remove_io_r = TRUE;
return FALSE;
}
}
{
do {
T_BEGIN {
} T_END;
if (ret)
if (remove_io)
else
if (!handled_commands)
return FALSE;
return TRUE;
}
{
struct client_command_context *cmd;
if (bytes == -1) {
/* disconnected */
return;
}
/* parameter word is longer than max. input buffer size.
this is most likely an error, so skip the new data
until newline is found. */
}
if (client->disconnected)
else
}
{
bool finished;
/* continue processing command */
if (!finished)
(void)client_handle_unfinished_cmd(cmd);
else {
/* command execution was finished */
}
}
{
struct client_command_context *cmd;
/* mark all commands non-executed */
}
/* go through the entire commands list every time in case
multiple commands were freed. temp_executed keeps track of
which messages we've called so far */
if (!cmd->temp_executed &&
break;
}
}
/* all commands executed */
break;
}
}
}
{
int ret;
return 1;
}
(void)cmd_sync_delayed(client);
if (client->disconnected)
else
return ret;
}
{
/* search only commands that were added before this command
(commands are prepended to the queue, so they're after ourself) */
if (old_cmd->search_save_result)
break;
}
return FALSE;
/* ambiguity, wait until it's over */
return TRUE;
}
{
struct mailbox_status status;
int ret;
return 0;
return 0;
/* CONDSTORE being enabled while mailbox is selected.
Notify client of the latest HIGHESTMODSEQ. */
if (ret == 0) {
"* OK [HIGHESTMODSEQ %llu] Highest",
(unsigned long long)status.highest_modseq));
}
}
if (ret < 0) {
}
return ret;
}
struct imap_search_update *
unsigned int *idx_r)
{
struct imap_search_update *updates;
unsigned int i, count;
return NULL;
for (i = 0; i < count; i++) {
*idx_r = i;
return &updates[i];
}
}
return NULL;
}
{
struct imap_search_update *update;
return;
}
{
while (imap_clients != NULL) {
}
}
struct imap_client_vfuncs imap_client_vfuncs = {
};