--- ChangeLog	2006-06-21 21:36:43.000000000 +0530
+++ ChangeLog.new	2006-06-21 21:54:10.000000000 +0530
@@ -1,3 +1,13 @@
+2006-06-21  Arunprakash  <twizst@gmail.com>
+
+	* camel/camel-stub-marshal.c (do_read): Modified to return the
+	number of bytes actually read so that the read data can be used.
+	(marshal_read): marshal->inptr is set immediately after the byte
+	array size is changed. Also in case of read failure, the byte
+	array size is set to actual number of bytes read.
+
+	** Partial fix for #179566.
+	
 2006-06-17  Kjartan Maraas  <kmaraas@gnome.org>
 
 	* configure.in: Up intltool requirement to 0.35.
--- camel-stub-marshal.c	2006-06-20 23:41:53.000000000 +0530
+++ camel-stub-marshal.c.new	2006-06-20 23:41:45.000000000 +0530
@@ -84,22 +84,24 @@ camel_stub_marshal_free (CamelStubMarsha
 }
 
 static gboolean
-do_read (CamelStubMarshal *marshal, char *buf, size_t len)
+do_read (CamelStubMarshal *marshal, char *buf, size_t *len)
 {
 	size_t nread = 0;
 	ssize_t n;
 	
 	do {
-		if ((n = camel_read (marshal->fd, buf + nread, len - nread)) > 0)
+		if ((n = camel_read (marshal->fd, buf + nread, *len - nread)) > 0)
 			nread += n;
-	} while (n && nread < len && errno != EINTR);
-	
-	if (nread < len) {
+	} while (n && nread < *len && errno != EINTR);
+
+	if (nread < *len) {
 		close (marshal->fd);
 		marshal->fd = -1;
+		*len = nread;
 		return FALSE;
 	}
-	
+
+	*len = nread;
 	return TRUE;
 }
 
@@ -108,19 +110,27 @@ marshal_read (CamelStubMarshal *marshal,
 {
 	int avail = marshal->in->len - (marshal->inptr - (char *)marshal->in->data);
 	int nread;
+	size_t to_read = 4;
 
 	if (avail == 0) {
 		g_byte_array_set_size (marshal->in, 4);
-		if (!do_read (marshal, (char *)marshal->in->data, 4))
+		marshal->inptr = (char *)marshal->in->data + 4;
+		if (!do_read (marshal, (char *)marshal->in->data, &to_read))
 			return -1;
 		avail =  (int)marshal->in->data[0]        +
 			((int)marshal->in->data[1] <<  8) +
 			((int)marshal->in->data[2] << 16) +
 			((int)marshal->in->data[3] << 24) - 4;
+
+		to_read = avail;
 		g_byte_array_set_size (marshal->in, avail + 4);
-		if (!do_read (marshal, ((char *)marshal->in->data) + 4, avail))
-			return -1;
 		marshal->inptr = (char *)marshal->in->data + 4;
+		if (!do_read (marshal, ((char *)marshal->in->data) + 4, &to_read)) {
+			g_byte_array_set_size (marshal->in, to_read + 4);
+			marshal->inptr = (char *)marshal->in->data + 4;
+			if (!(avail = to_read))
+				return -1;
+		}
 	}
 
 	if (len <= avail)
