]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imap: If client disconnects in APPEND, log more about what it did before that.
authorTimo Sirainen <tss@iki.fi>
Mon, 16 May 2011 14:02:56 +0000 (17:02 +0300)
committerTimo Sirainen <tss@iki.fi>
Mon, 16 May 2011 14:02:56 +0000 (17:02 +0300)
src/imap/cmd-append.c

index 6fb4c9a35bfd5f6a3572d128a90ce8fef1a94c59..d1fecbe862196adbee6bb1b042e63f553b864f19 100644 (file)
@@ -24,6 +24,7 @@ struct cmd_append_context {
        struct mail_storage *storage;
        struct mailbox *box;
         struct mailbox_transaction_context *t;
+       time_t started;
 
        struct istream *input;
        uoff_t msg_size;
@@ -40,10 +41,26 @@ static void cmd_append_finish(struct cmd_append_context *ctx);
 static bool cmd_append_continue_message(struct client_command_context *cmd);
 static bool cmd_append_continue_parsing(struct client_command_context *cmd);
 
+static const char *get_disconnect_reason(struct cmd_append_context *ctx)
+{
+       string_t *str = t_str_new(128);
+       unsigned int secs = ioloop_time - ctx->started;
+
+       str_printfa(str, "Disconnected in APPEND (%u msgs, %u secs",
+                   ctx->count, secs);
+       if (ctx->input != NULL) {
+               str_printfa(str, ", %"PRIuUOFF_T"/%"PRIuUOFF_T" bytes",
+                           ctx->input->v_offset, ctx->msg_size);
+       }
+       str_append_c(str, ')');
+       return str_c(str);
+}
+
 static void client_input_append(struct client_command_context *cmd)
 {
        struct cmd_append_context *ctx = cmd->context;
        struct client *client = cmd->client;
+       const char *reason;
        bool finished;
 
        i_assert(!client->destroyed);
@@ -54,11 +71,12 @@ static void client_input_append(struct client_command_context *cmd)
        switch (i_stream_read(client->input)) {
        case -1:
                /* disconnected */
+               reason = get_disconnect_reason(ctx);
                cmd_append_finish(cmd->context);
                /* Reset command so that client_destroy() doesn't try to call
                   cmd_append_continue_message() anymore. */
                client_command_free(&cmd);
-               client_destroy(client, "Disconnected in APPEND");
+               client_destroy(client, reason);
                return;
        case -2:
                if (ctx->message_input) {
@@ -510,6 +528,7 @@ bool cmd_append(struct client_command_context *cmd)
        ctx->cmd = cmd;
        ctx->client = client;
        ctx->box = get_mailbox(cmd, mailbox);
+       ctx->started = ioloop_time;
        if (ctx->box == NULL)
                ctx->failed = TRUE;
        else {