cmd-append.c revision 00f2137588f4f2093290680df6885255d01cf873
/* Copyright (C) 2002 Timo Sirainen */
#include "common.h"
#include "ioloop.h"
#include "istream.h"
#include "ostream.h"
#include "str.h"
#include "commands.h"
#include "imap-parser.h"
#include "imap-date.h"
#include "mail-storage.h"
struct cmd_append_context {
struct client_command_context *cmd;
struct mail_storage *storage;
struct mailbox_transaction_context *t;
struct imap_parser *save_parser;
struct mail_save_context *save_ctx;
};
static void client_input(void *context)
{
case -1:
/* disconnected */
return;
case -2:
if (client->command_pending) {
/* message data, this is handled internally by
mailbox_save_continue() */
break;
}
/* parameter word is longer than max. input buffer size.
this is most likely an error, so skip the new data
until newline is found. */
return;
}
/* command execution was finished. Note that if cmd_sync()
didn't finish, we didn't get here but the input handler
has already been moved. So don't do anything important
here..
reset command once again to reset cmd_sync()'s changes. */
if (client->input_pending)
}
}
/* Returns -1 = error, 0 = need more data, 1 = successful. flags and
internal_date may be NULL as a result, but mailbox and msg_size are always
set when successful. */
bool *nonsync)
{
/* [<flags>] */
else {
args++;
}
/* [<internal date>] */
*internal_date = NULL;
else {
args++;
}
return FALSE;
}
return TRUE;
}
{
}
{
return TRUE;
}
return FALSE;
}
{
if (!nonsync) {
return TRUE;
}
/* we have to read the nonsynced literal so we don't treat the message
data as commands. */
}
{
struct imap_arg_list *flags_list;
enum mail_flags flags;
const char *const *keywords_list;
struct mail_keywords *keywords;
const char *internal_date_str;
int ret, timezone_offset;
bool nonsync;
/* if error occurs, the CRLF is already read. */
/* [<flags>] [<internal date>] <message literal> */
if (ret == -1) {
return TRUE;
}
if (ret < 0) {
/* need more data */
return FALSE;
}
/* last message */
enum mailbox_sync_flags sync_flags;
/* eat away the trailing CRLF */
/* we failed earlier, error message is sent */
return TRUE;
}
if (ret < 0) {
return TRUE;
}
}
}
/* we failed earlier, make sure we just eat nonsync-literal
if it's given. */
}
if (flags_list != NULL) {
&flags, &keywords_list))
} else {
flags = 0;
}
if (internal_date_str == NULL) {
/* no time given, default to now. */
timezone_offset = 0;
} else if (!imap_parse_datetime(internal_date_str,
&internal_date, &timezone_offset)) {
}
/* no message data, abort */
return TRUE;
}
/* save the mail */
if (ret < 0) {
/* save initialization failed */
}
/* after literal comes CRLF, if we fail make sure we eat it away */
if (!nonsync) {
}
return cmd_append_continue_message(cmd);
}
{
bool failed;
/* we still have to finish reading the message
from client */
}
}
}
/* finished */
/* failed above */
} else if (!all_written) {
/* client disconnected before it finished sending the
whole message. */
} else {
}
if (failed) {
return TRUE;
}
/* prepare for next message */
return cmd_append_continue_parsing(cmd);
}
return FALSE;
}
static struct mailbox *
{
struct mail_storage *storage;
return NULL;
return NULL;
return NULL;
}
return box;
}
{
struct cmd_append_context *ctx;
struct mailbox_status status;
const char *mailbox;
/* <mailbox> */
return FALSE;
&status) < 0) {
} else {
}
}
/* append is special because we're only waiting on client input, not
client output, so disable the standard output handler until we're
finished */
return cmd_append_continue_parsing(cmd);
}