From 555a749ac61811b08d5a340202f4f73eb1aa7fc2 Mon Sep 17 00:00:00 2001
From: Stephan Bosch <stephan@rename-it.nl>
Date: Fri, 6 Aug 2010 16:17:31 +0200
Subject: [PATCH] ManageSieve: fixed SASL negotiation; mechanisms that need a
 roundtrip were broken.

---
 src/managesieve-login/client-authenticate.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/managesieve-login/client-authenticate.c b/src/managesieve-login/client-authenticate.c
index b3234a318..a81afe416 100644
--- a/src/managesieve-login/client-authenticate.c
+++ b/src/managesieve-login/client-authenticate.c
@@ -145,6 +145,12 @@ int managesieve_client_auth_parse_response(struct client *client)
 	const char *msg;
 	bool fatal;
 
+	if ( i_stream_read(client->input) == -1 ) {	
+		/* disconnected */
+		client_destroy(client, "Disconnected");
+		return -1;
+	}
+
 	if ( msieve_client->skip_line ) {
 		if ( i_stream_next_line(client->input) == NULL )
 			return 0;
@@ -159,15 +165,18 @@ int managesieve_client_auth_parse_response(struct client *client)
 		if (fatal) {
 			/* FIXME: What to do? */
 		}
-	  
+
+		if ( i_stream_next_line(client->input) == NULL )
+			msieve_client->skip_line = TRUE;
 		sasl_server_auth_failed(client, msg);
 		return -1;
 	case -2:
 		/* not enough data */
 		return 0;
 	}
-
-	msieve_client->skip_line = TRUE;
+	
+	if ( i_stream_next_line(client->input) == NULL )
+		msieve_client->skip_line = TRUE;
 
 	if ( args[0].type != MANAGESIEVE_ARG_STRING || 
 		args[1].type != MANAGESIEVE_ARG_EOL ) {
-- 
GitLab