]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-imap-client: When server sends BYE before disconnection, log it as the reason.
authorTimo Sirainen <tss@iki.fi>
Thu, 6 Jun 2013 06:47:39 +0000 (09:47 +0300)
committerTimo Sirainen <tss@iki.fi>
Thu, 6 Jun 2013 06:47:39 +0000 (09:47 +0300)
src/lib-imap-client/imapc-connection.c

index de2177cbb384a79849508d3a8e1cd3e7bd5e6e52..886e7b9d815cf365ee7c1edcde68de38cf2d8a10 100644 (file)
@@ -92,6 +92,7 @@ struct imapc_connection {
 
        struct imapc_client_mailbox *selecting_box, *selected_box;
        enum imapc_connection_state state;
+       char *disconnect_reason;
 
        enum imapc_capability capabilities;
        char **capabilities_list;
@@ -159,6 +160,8 @@ static void imapc_connection_unref(struct imapc_connection **_conn)
        if (--conn->refcount > 0)
                return;
 
+       i_assert(conn->disconnect_reason == NULL);
+
        if (conn->capabilities_list != NULL)
                p_strsplit_free(default_pool, conn->capabilities_list);
        array_free(&conn->cmd_send_queue);
@@ -299,8 +302,13 @@ static void imapc_connection_set_state(struct imapc_connection *conn,
        case IMAPC_CONNECTION_STATE_DISCONNECTED:
                memset(&reply, 0, sizeof(reply));
                reply.state = IMAPC_COMMAND_STATE_DISCONNECTED;
-               reply.text_without_resp = reply.text_full =
-                       "Disconnected from server";
+               reply.text_full = "Disconnected from server";
+               if (conn->disconnect_reason != NULL) {
+                       reply.text_full = t_strdup_printf("%s: %s",
+                               reply.text_full, conn->disconnect_reason);
+                       i_free_and_null(conn->disconnect_reason);
+               }
+               reply.text_without_resp = reply.text_full;
                imapc_login_callback(conn, &reply);
 
                conn->idling = FALSE;
@@ -899,6 +907,9 @@ static int imapc_connection_input_untagged(struct imapc_connection *conn)
                value = imap_args_to_str(imap_args);
                if (imapc_connection_parse_capability(conn, value) < 0)
                        return -1;
+       } else if (strcasecmp(name, "BYE") == 0) {
+               i_free(conn->disconnect_reason);
+               conn->disconnect_reason = i_strdup(imap_args_to_str(imap_args));
        }
 
        reply.name = name;
@@ -1120,7 +1131,10 @@ static void imapc_connection_input(struct imapc_connection *conn)
 
        if (ret < 0) {
                /* disconnected */
-               if (conn->ssl_iostream == NULL) {
+               if (conn->disconnect_reason != NULL) {
+                       i_error("imapc(%s): Server disconnected with message: %s",
+                               conn->name, conn->disconnect_reason);
+               } else if (conn->ssl_iostream == NULL) {
                        i_error("imapc(%s): Server disconnected unexpectedly",
                                conn->name);
                } else {