[evolution-data-server] Avoid camel_stream_printf().



commit 4d0d9ed3cc3c85af2707b575abfe4ac50a4939bb
Author: Matthew Barnes <mbarnes redhat com>
Date:   Tue Jul 5 16:43:59 2011 -0400

    Avoid camel_stream_printf().
    
    camel_stream_printf() is next on the chopping block.
    
    Use g_strdup_printf() or a GString to construct a formatted string in
    memory, pass to to camel_stream_write() in one go, and then check for
    errors (unless it's a memory stream).

 camel/camel-http-stream.c                  |   77 +++++++++++----------------
 camel/camel-mime-part.c                    |   22 +++++---
 camel/camel-multipart-signed.c             |   30 ++++++-----
 camel/camel-multipart.c                    |   27 ++++-----
 camel/camel-sasl-ntlm.c                    |   13 +++--
 camel/providers/imap/camel-imap-command.c  |   20 ++-----
 camel/providers/imapx/camel-imapx-server.c |   48 ++++++++++++++----
 camel/providers/imapx/camel-imapx-utils.c  |   53 +++++++++++++------
 camel/providers/local/camel-mh-store.c     |   48 +++++++++++++++---
 camel/providers/nntp/camel-nntp-store.c    |   38 ++++++++++----
 camel/providers/pop3/camel-pop3-store.c    |   18 +++++-
 camel/tests/folder/test9.c                 |    2 +-
 12 files changed, 245 insertions(+), 151 deletions(-)
---
diff --git a/camel/camel-http-stream.c b/camel/camel-http-stream.c
index e866d4d..ae2b64e 100644
--- a/camel/camel-http-stream.c
+++ b/camel/camel-http-stream.c
@@ -130,9 +130,13 @@ http_method_invoke (CamelHttpStream *http,
                     GCancellable *cancellable,
                     GError **error)
 {
+	GString *buffer;
 	const gchar *method = NULL, *use_url;
+	const gchar *user_agent;
 	gchar *url;
 
+	buffer = g_string_sized_new (1024);
+
 	switch (http->method) {
 	case CAMEL_HTTP_METHOD_GET:
 		method = "GET";
@@ -154,63 +158,44 @@ http_method_invoke (CamelHttpStream *http,
 		use_url = http->url->path;
 	}
 
-	d(printf("HTTP Stream Sending: %s %s HTTP/1.0\r\nUser-Agent: %s\r\nHost: %s\r\n",
-		 method,
-		 use_url,
-		 http->user_agent ? http->user_agent : "CamelHttpStream/1.0",
-		 http->url->host));
-	if (camel_stream_printf (
-		http->raw,
-		"%s %s HTTP/1.0\r\nUser-Agent: %s\r\nHost: %s\r\n",
-		method, use_url, http->user_agent ? http->user_agent :
-		"CamelHttpStream/1.0", http->url->host) == -1) {
-		g_set_error (
-			error, G_IO_ERROR,
-			g_io_error_from_errno (errno),
-			"%s", g_strerror (errno));
-		http_disconnect (http);
-		g_free (url);
-		return -1;
-	}
-	g_free (url);
+	user_agent = http->user_agent;
+	if (user_agent == NULL)
+		user_agent = "CamelHttpStream/1.0";
 
-	if (http->authrealm) {
-		d(printf("HTTP Stream Sending: WWW-Authenticate: %s\n", http->authrealm));
-	}
+	g_string_append_printf (
+		buffer, "%s %s HTTP/1.0\r\n", method, use_url);
 
-	if (http->authrealm && camel_stream_printf (
-		http->raw, "WWW-Authenticate: %s\r\n",
-		http->authrealm) == -1) {
-		g_set_error (
-			error, G_IO_ERROR,
-			g_io_error_from_errno (errno),
-			"%s", g_strerror (errno));
-		http_disconnect (http);
-		return -1;
-	}
+	g_string_append_printf (
+		buffer, "User-Agent: %s\r\n", user_agent);
 
-	if (http->authpass && http->proxy) {
-		d(printf("HTTP Stream Sending: Proxy-Aurhorization: Basic %s\n", http->authpass));
-	}
+	g_string_append_printf (
+		buffer, "Host: %s\r\n", http->url->host);
 
-	if (http->authpass && http->proxy && camel_stream_printf (
-		http->raw, "Proxy-Authorization: Basic %s\r\n",
-		http->authpass) == -1) {
-		g_set_error (
-			error, G_IO_ERROR,
-			g_io_error_from_errno (errno),
-			"%s", g_strerror (errno));
-		http_disconnect (http);
-		return -1;
-	}
+	g_free (url);
+
+	if (http->authrealm != NULL)
+		g_string_append_printf (
+			buffer, "WWW-Authenticate: %s\r\n",
+			http->authrealm);
+
+	if (http->authpass != NULL && http->proxy != NULL)
+		g_string_append_printf (
+			buffer, "Proxy-Authorization: Basic %s\r\n",
+			http->authpass);
+
+	g_string_append (buffer, "\r\n");
 
 	/* end the headers */
-	if (camel_stream_write (http->raw, "\r\n", 2, cancellable, error) == -1 ||
+	if (camel_stream_write (
+		http->raw, buffer->str, buffer->len, cancellable, error) == -1 ||
 		camel_stream_flush (http->raw, cancellable, error) == -1) {
+		g_string_free (buffer, TRUE);
 		http_disconnect (http);
 		return -1;
 	}
 
+	g_string_free (buffer, TRUE);
+
 	return 0;
 }
 
diff --git a/camel/camel-mime-part.c b/camel/camel-mime-part.c
index 57e2273..b4ceaac 100644
--- a/camel/camel-mime-part.c
+++ b/camel/camel-mime-part.c
@@ -592,6 +592,8 @@ mime_part_write_to_stream_sync (CamelDataWrapper *dw,
 		}
 
 		if (mp->priv->encoding != content->encoding) {
+			gchar *content;
+
 			switch (mp->priv->encoding) {
 			case CAMEL_TRANSFER_ENCODING_BASE64:
 				filter = camel_mime_filter_basic_new (CAMEL_MIME_FILTER_BASIC_BASE64_ENC);
@@ -601,16 +603,18 @@ mime_part_write_to_stream_sync (CamelDataWrapper *dw,
 				break;
 			case CAMEL_TRANSFER_ENCODING_UUENCODE:
 				filename = camel_mime_part_get_filename (mp);
-				count = camel_stream_printf (
-					ostream, "begin 644 %s\n",
-					filename ? filename : "untitled");
-				if (count == -1) {
-					g_set_error (
-						error, G_IO_ERROR,
-						g_io_error_from_errno (errno),
-						"%s", g_strerror (errno));
+				if (filename == NULL)
+					filename = "untitled";
+
+				content = g_strdup_printf (
+					"begin 644 %s\n", filename);
+				count = camel_stream_write_string (
+					ostream, content, cancellable, error);
+				g_free (content);
+
+				if (count == -1)
 					return -1;
-				}
+
 				total += count;
 				filter = camel_mime_filter_basic_new (CAMEL_MIME_FILTER_BASIC_UU_ENC);
 				break;
diff --git a/camel/camel-multipart-signed.c b/camel/camel-multipart-signed.c
index 4dea7d5..ad86916 100644
--- a/camel/camel-multipart-signed.c
+++ b/camel/camel-multipart-signed.c
@@ -307,6 +307,7 @@ multipart_signed_write_to_stream_sync (CamelDataWrapper *data_wrapper,
 	const gchar *boundary;
 	gssize total = 0;
 	gssize count;
+	gchar *content;
 
 	/* we have 3 basic cases:
 	   1. constructed, we write out the data wrapper stream we got
@@ -352,9 +353,12 @@ multipart_signed_write_to_stream_sync (CamelDataWrapper *data_wrapper,
 	}
 
 	/* first boundary */
-	count = camel_stream_printf (stream, "\n--%s\n", boundary);
+	content = g_strdup_printf ("\n--%s\n", boundary);
+	count = camel_stream_write_string (
+		stream, content, cancellable, error);
+	g_free (content);
 	if (count == -1)
-		goto file_error;
+		return -1;
 	total += count;
 
 	/* output content part */
@@ -369,9 +373,12 @@ multipart_signed_write_to_stream_sync (CamelDataWrapper *data_wrapper,
 	total += count;
 
 	/* boundary */
-	count = camel_stream_printf (stream, "\n--%s\n", boundary);
+	content = g_strdup_printf ("\n--%s\n", boundary);
+	count = camel_stream_write_string (
+		stream, content, cancellable, error);
+	g_free (content);
 	if (count == -1)
-		goto file_error;
+		return -1;
 	total += count;
 
 	/* signature */
@@ -383,9 +390,12 @@ multipart_signed_write_to_stream_sync (CamelDataWrapper *data_wrapper,
 	total += count;
 
 	/* write the terminating boudary delimiter */
-	count = camel_stream_printf (stream, "\n--%s--\n", boundary);
+	content = g_strdup_printf ("\n--%s--\n", boundary);
+	count = camel_stream_write_string (
+		stream, content, cancellable, error);
+	g_free (content);
 	if (count == -1)
-		goto file_error;
+		return -1;
 	total += count;
 
 	/* and finally the postface */
@@ -398,14 +408,6 @@ multipart_signed_write_to_stream_sync (CamelDataWrapper *data_wrapper,
 	}
 
 	return total;
-
-file_error:
-	g_set_error (
-		error, G_IO_ERROR,
-		g_io_error_from_errno (errno),
-		"%s", g_strerror (errno));
-
-	return -1;
 }
 
 static gboolean
diff --git a/camel/camel-multipart.c b/camel/camel-multipart.c
index ea14b33..8da13a6 100644
--- a/camel/camel-multipart.c
+++ b/camel/camel-multipart.c
@@ -91,9 +91,10 @@ multipart_write_to_stream_sync (CamelDataWrapper *data_wrapper,
 {
 	CamelMultipart *multipart = CAMEL_MULTIPART (data_wrapper);
 	const gchar *boundary;
+	GList *node;
+	gchar *content;
 	gssize total = 0;
 	gssize count;
-	GList *node;
 
 	/* get the bundary text */
 	boundary = camel_multipart_get_boundary (multipart);
@@ -120,10 +121,12 @@ multipart_write_to_stream_sync (CamelDataWrapper *data_wrapper,
 	 */
 	node = multipart->parts;
 	while (node) {
-		count = camel_stream_printf (
-			stream, "\n--%s\n", boundary);
+		content = g_strdup_printf ("\n--%s\n", boundary);
+		count = camel_stream_write_string (
+			stream, content, cancellable, error);
+		g_free (content);
 		if (count == -1)
-			goto file_error;
+			return -1;
 		total += count;
 
 		count = camel_data_wrapper_write_to_stream_sync (
@@ -136,10 +139,12 @@ multipart_write_to_stream_sync (CamelDataWrapper *data_wrapper,
 	}
 
 	/* write the terminating boudary delimiter */
-	count = camel_stream_printf (
-		stream, "\n--%s--\n", boundary);
+	content = g_strdup_printf ("\n--%s--\n", boundary);
+	count = camel_stream_write_string (
+		stream, content, cancellable, error);
+	g_free (content);
 	if (count == -1)
-		goto file_error;
+		return -1;
 	total += count;
 
 	/* and finally the postface */
@@ -152,14 +157,6 @@ multipart_write_to_stream_sync (CamelDataWrapper *data_wrapper,
 	}
 
 	return total;
-
-file_error:
-	g_set_error (
-		error, G_IO_ERROR,
-		g_io_error_from_errno (errno),
-		"%s", g_strerror (errno));
-
-	return -1;
 }
 
 static void
diff --git a/camel/camel-sasl-ntlm.c b/camel/camel-sasl-ntlm.c
index d03c9d0..17b1ee5 100644
--- a/camel/camel-sasl-ntlm.c
+++ b/camel/camel-sasl-ntlm.c
@@ -702,9 +702,13 @@ sasl_ntlm_challenge_sync (CamelSasl *sasl,
 			}
 			return ret;
 		} else {
-			gchar *type2 = g_base64_encode (token->data, token->len);
-			if (camel_stream_printf (priv->helper_stream, "TT %s\n",
-						 type2) >= 0 &&
+			gchar *type2;
+			gchar *string;
+
+			type2 = g_base64_encode (token->data, token->len);
+			string = g_strdup_printf ("TT %s\n", type2);
+			if (camel_stream_write_string (
+				priv->helper_stream, string, NULL, NULL) >= 0 &&
 			   (s = camel_stream_read (priv->helper_stream, buf,
 				   sizeof (buf), cancellable, NULL)) > 4 &&
 			   buf[0] == 'K' && buf[1] == 'K' && buf[2] == ' ' &&
@@ -716,6 +720,7 @@ sasl_ntlm_challenge_sync (CamelSasl *sasl,
 			} else
 				g_warning ("Didn't get valid response from ntlm_auth helper");
 
+			g_free (string);
 			g_free (type2);
 		}
 		/* On failure, we just return an empty string. Setting the
@@ -868,7 +873,7 @@ sasl_ntlm_try_empty_password_sync (CamelSasl *sasl,
 		g_object_unref (stream);
 		return FALSE;
 	}
-	if (camel_stream_printf (stream, "YR\n") < 0) {
+	if (camel_stream_write_string (stream, "YR\n", cancellable, error) < 0) {
 		g_object_unref (stream);
 		return FALSE;
 	}
diff --git a/camel/providers/imap/camel-imap-command.c b/camel/providers/imap/camel-imap-command.c
index 0bf5f9e..3aa0059 100644
--- a/camel/providers/imap/camel-imap-command.c
+++ b/camel/providers/imap/camel-imap-command.c
@@ -188,6 +188,7 @@ imap_command_start (CamelImapStore *store,
                     GCancellable *cancellable,
                     GError **error)
 {
+	gchar *content;
 	gssize nwritten;
 
 	if (!store->ostream) {
@@ -243,25 +244,16 @@ imap_command_start (CamelImapStore *store,
 		fprintf (stderr, "sending : %c%.5u %s\r\n", store->tag_prefix, store->command, mask);
 	}
 
-	nwritten = camel_stream_printf (
-		store->ostream, "%c%.5u %s\r\n",
+	content = g_strdup_printf (
+		"%c%.5u %s\r\n",
 		store->tag_prefix, store->command++, cmd);
+	nwritten = camel_stream_write_string (
+		store->ostream, content, cancellable, error);
+	g_free (content);
 
 	if (nwritten == -1) {
-		if (errno == EINTR)
-			g_set_error (
-				error, G_IO_ERROR,
-				G_IO_ERROR_CANCELLED,
-				_("Operation cancelled"));
-		else
-			g_set_error (
-				error, G_IO_ERROR,
-				g_io_error_from_errno (errno),
-				"%s", g_strerror (errno));
-
 		camel_service_disconnect_sync (
 			CAMEL_SERVICE (store), FALSE, NULL);
-
 		return FALSE;
 	}
 
diff --git a/camel/providers/imapx/camel-imapx-server.c b/camel/providers/imapx/camel-imapx-server.c
index f8bc7e4..340089b 100644
--- a/camel/providers/imapx/camel-imapx-server.c
+++ b/camel/providers/imapx/camel-imapx-server.c
@@ -496,7 +496,10 @@ imapx_command_add_part (CamelIMAPXCommand *ic, camel_imapx_command_part_t type,
 
 		/* we presume we'll need to get additional data only if we're not authenticated yet */
 		g_object_ref (ob);
-		camel_stream_printf((CamelStream *)ic->mem, "%s", camel_sasl_get_mechanism (CAMEL_SASL (ob)));
+		camel_stream_write_string (
+			(CamelStream *)ic->mem,
+			camel_sasl_get_mechanism (CAMEL_SASL (ob)),
+			NULL, NULL);
 		if (!camel_sasl_get_authenticated ((CamelSasl *) ob))
 			type |= CAMEL_IMAPX_COMMAND_CONTINUATION;
 		break;
@@ -524,13 +527,19 @@ imapx_command_add_part (CamelIMAPXCommand *ic, camel_imapx_command_part_t type,
 	}
 
 	if (type & CAMEL_IMAPX_COMMAND_LITERAL_PLUS) {
+		gchar *string;
+
 		if (ic->is->cinfo && ic->is->cinfo->capa & IMAPX_CAPABILITY_LITERALPLUS) {
-			camel_stream_printf((CamelStream *)ic->mem, "{%u+}", ob_size);
+			string = g_strdup_printf ("{%u+}", ob_size);
 		} else {
 			type &= ~CAMEL_IMAPX_COMMAND_LITERAL_PLUS;
 			type |= CAMEL_IMAPX_COMMAND_CONTINUATION;
-			camel_stream_printf((CamelStream *)ic->mem, "{%u}", ob_size);
+			string = g_strdup_printf ("{%u}", ob_size);
 		}
+
+		camel_stream_write_string ((CamelStream *)ic->mem, string, NULL, NULL);
+
+		g_free (string);
 	}
 
 	byte_array = camel_stream_mem_get_byte_array (ic->mem);
@@ -706,23 +715,32 @@ imapx_command_addv (CamelIMAPXCommand *ic, const gchar *fmt, va_list ap)
 				case 'd': /* int/unsigned */
 				case 'u':
 					if (llong == 1) {
+						gchar *string;
 						l = va_arg (ap, glong);
 						c(ic->is->tagprefix, "got glong '%d'\n", (gint)l);
 						memcpy (buffer, start, p-start);
 						buffer[p-start] = 0;
-						camel_stream_printf ((CamelStream *) ic->mem, buffer, l);
+						string = g_strdup_printf (buffer, l);
+						camel_stream_write_string ((CamelStream *) ic->mem, string, ic->cancellable, NULL);
+						g_free (string);
 					} else if (llong == 2) {
+						gchar *string;
 						guint64 i64 = va_arg (ap, guint64);
 						c(ic->is->tagprefix, "got guint64 '%d'\n", (gint)i64);
 						memcpy (buffer, start, p-start);
 						buffer[p-start] = 0;
-						camel_stream_printf ((CamelStream *) ic->mem, buffer, i64);
+						string = g_strdup_printf (buffer, i64);
+						camel_stream_write_string ((CamelStream *) ic->mem, string, ic->cancellable, NULL);
+						g_free (string);
 					} else {
+						gchar *string;
 						d = va_arg (ap, gint);
 						c(ic->is->tagprefix, "got gint '%d'\n", d);
 						memcpy (buffer, start, p-start);
 						buffer[p-start] = 0;
-						camel_stream_printf ((CamelStream *) ic->mem, buffer, d);
+						string = g_strdup_printf (buffer, d);
+						camel_stream_write_string ((CamelStream *) ic->mem, string, ic->cancellable, NULL);
+						g_free (string);
 					}
 					break;
 				}
@@ -849,6 +867,7 @@ static gboolean
 imapx_command_start (CamelIMAPXServer *imap, CamelIMAPXCommand *ic)
 {
 	CamelIMAPXCommandPart *cp;
+	gint retval;
 
 	camel_imapx_command_close (ic);
 	cp = (CamelIMAPXCommandPart *) ic->parts.head;
@@ -866,7 +885,15 @@ imapx_command_start (CamelIMAPXServer *imap, CamelIMAPXCommand *ic)
 	g_static_rec_mutex_lock (&imap->ostream_lock);
 
 	c(imap->tagprefix, "Starting command (active=%d,%s) %c%05u %s\r\n", camel_dlist_length(&imap->active), imap->literal?" literal":"", imap->tagprefix, ic->tag, cp->data);
-	if (!imap->stream || camel_stream_printf((CamelStream *)imap->stream, "%c%05u %s\r\n", imap->tagprefix, ic->tag, cp->data) == -1) {
+	if (imap->stream != NULL) {
+		gchar *string;
+
+		string = g_strdup_printf ("%c%05u %s\r\n", imap->tagprefix, ic->tag, cp->data);
+		retval = camel_stream_write_string ((CamelStream *) imap->stream, string, ic->cancellable, NULL);
+		g_free (string);
+	} else
+		retval = -1;
+	if (retval == -1) {
 		g_set_error (
 			&ic->error, CAMEL_IMAPX_ERROR, 1,
 			"Failed to issue the command");
@@ -1918,7 +1945,8 @@ imapx_continuation (CamelIMAPXServer *imap,
 	if (cp->next) {
 		ic->current = cp;
 		c(imap->tagprefix, "next part of command \"%c%05u: %s\"\n", imap->tagprefix, ic->tag, cp->data);
-		camel_stream_printf((CamelStream *)imap->stream, "%s\r\n", cp->data);
+		camel_stream_write_string ((CamelStream *) imap->stream, cp->data, cancellable, NULL);
+		camel_stream_write_string ((CamelStream *) imap->stream, "\r\n", cancellable, NULL);
 		if (cp->type & (CAMEL_IMAPX_COMMAND_CONTINUATION|CAMEL_IMAPX_COMMAND_LITERAL_PLUS)) {
 			newliteral = ic;
 		} else {
@@ -1926,7 +1954,7 @@ imapx_continuation (CamelIMAPXServer *imap,
 		}
 	} else {
 		c(imap->tagprefix, "%p: queueing continuation\n", ic);
-		camel_stream_printf((CamelStream *)imap->stream, "\r\n");
+		camel_stream_write_string((CamelStream *)imap->stream, "\r\n", cancellable, NULL);
 	}
 
 	QUEUE_LOCK (imap);
@@ -2199,7 +2227,7 @@ imapx_submit_job (CamelIMAPXServer *is,
 static gboolean
 imapx_command_idle_stop (CamelIMAPXServer *is, GError **error)
 {
-	if (!is->stream || camel_stream_printf((CamelStream *)is->stream, "%s", "DONE\r\n") == -1) {
+	if (!is->stream || camel_stream_write_string ((CamelStream *)is->stream, "DONE\r\n", NULL, NULL) == -1) {
 		g_set_error (
 			error, CAMEL_IMAPX_ERROR, 1,
 			"Unable to issue DONE");
diff --git a/camel/providers/imapx/camel-imapx-utils.c b/camel/providers/imapx/camel-imapx-utils.c
index 0580605..82ed237 100644
--- a/camel/providers/imapx/camel-imapx-utils.c
+++ b/camel/providers/imapx/camel-imapx-utils.c
@@ -1434,6 +1434,7 @@ void
 imapx_dump_fetch (struct _fetch_info *finfo)
 {
 	CamelStream *sout;
+	gchar *string;
 	gint fd;
 
 	d('?', "Fetch info:\n");
@@ -1445,46 +1446,64 @@ imapx_dump_fetch (struct _fetch_info *finfo)
 	fd = dup (1);
 	sout = camel_stream_fs_new_with_fd (fd);
 	if (finfo->body) {
-		camel_stream_printf(sout, "Body content:\n");
+		camel_stream_write_string (sout, "Body content:\n", NULL, NULL);
 		camel_stream_write_to_stream (finfo->body, sout, NULL, NULL);
 		g_seekable_seek (
 			G_SEEKABLE (finfo->body),
 			0, G_SEEK_SET, NULL, NULL);
 	}
 	if (finfo->text) {
-		camel_stream_printf(sout, "Text content:\n");
+		camel_stream_write_string (sout, "Text content:\n", NULL, NULL);
 		camel_stream_write_to_stream (finfo->text, sout, NULL, NULL);
 		g_seekable_seek (
 			G_SEEKABLE (finfo->text),
 			0, G_SEEK_SET, NULL, NULL);
 	}
 	if (finfo->header) {
-		camel_stream_printf(sout, "Header content:\n");
+		camel_stream_write_string (sout, "Header content:\n", NULL, NULL);
 		camel_stream_write_to_stream (finfo->header, sout, NULL, NULL);
 		g_seekable_seek (
 			G_SEEKABLE (finfo->header),
 			0, G_SEEK_SET, NULL, NULL);
 	}
 	if (finfo->minfo) {
-		camel_stream_printf(sout, "Message Info:\n");
+		camel_stream_write_string (sout, "Message Info:\n", NULL, NULL);
 		camel_message_info_dump (finfo->minfo);
 	}
 	if (finfo->cinfo) {
-		camel_stream_printf(sout, "Content Info:\n");
+		camel_stream_write_string (sout, "Content Info:\n", NULL, NULL);
 		//camel_content_info_dump (finfo->cinfo, 0);
 	}
-	if (finfo->got & FETCH_SIZE)
-		camel_stream_printf(sout, "Size: %d\n", (gint)finfo->size);
-	if (finfo->got & FETCH_BODY)
-		camel_stream_printf(sout, "Offset: %d\n", (gint)finfo->offset);
-	if (finfo->got & FETCH_FLAGS)
-		camel_stream_printf(sout, "Flags: %08x\n", (gint)finfo->flags);
-	if (finfo->date)
-		camel_stream_printf(sout, "Date: '%s'\n", finfo->date);
-	if (finfo->section)
-		camel_stream_printf(sout, "Section: '%s'\n", finfo->section);
-	if (finfo->date)
-		camel_stream_printf(sout, "UID: '%s'\n", finfo->uid);
+	if (finfo->got & FETCH_SIZE) {
+		string = g_strdup_printf ("Size: %d\n", (gint) finfo->size);
+		camel_stream_write_string (sout, string, NULL, NULL);
+		g_free (string);
+	}
+	if (finfo->got & FETCH_BODY) {
+		string = g_strdup_printf ("Offset: %d\n", (gint) finfo->offset);
+		camel_stream_write_string (sout, string, NULL, NULL);
+		g_free (string);
+	}
+	if (finfo->got & FETCH_FLAGS) {
+		string = g_strdup_printf ("Flags: %08x\n", (gint) finfo->flags);
+		camel_stream_write_string (sout, string, NULL, NULL);
+		g_free (string);
+	}
+	if (finfo->date) {
+		string = g_strdup_printf ("Data: '%s'\n", finfo->date);
+		camel_stream_write_string (sout, string, NULL, NULL);
+		g_free (string);
+	}
+	if (finfo->section) {
+		string = g_strdup_printf ("Section: '%s'\n", finfo->section);
+		camel_stream_write_string (sout, string, NULL, NULL);
+		g_free (string);
+	}
+	if (finfo->date) {
+		string = g_strdup_printf ("UID: '%s'\n", finfo->uid);
+		camel_stream_write_string (sout, string, NULL, NULL);
+		g_free (string);
+	}
 	g_object_unref (sout);
 }
 
diff --git a/camel/providers/local/camel-mh-store.c b/camel/providers/local/camel-mh-store.c
index 99d8382..8ecf629 100644
--- a/camel/providers/local/camel-mh-store.c
+++ b/camel/providers/local/camel-mh-store.c
@@ -57,8 +57,11 @@ folders_update (const gchar *root,
 {
 	gchar *tmp, *tmpnew, *line = NULL;
 	CamelStream *stream, *in = NULL, *out = NULL;
+	gchar *folder_newline;
 	gint flen = strlen (folder);
 
+	folder_newline = g_strdup_printf ("%s\n", folder);
+
 	tmpnew = g_alloca (strlen (root) + 16);
 	sprintf (tmpnew, "%s.folders~", root);
 
@@ -75,8 +78,15 @@ folders_update (const gchar *root,
 		g_object_unref (stream);
 	}
 	if (in == NULL || stream == NULL) {
-		if (mode == UPDATE_ADD && camel_stream_printf (out, "%s\n", folder) == -1)
-			goto fail;
+		if (mode == UPDATE_ADD) {
+			gint ret;
+
+			ret = camel_stream_write_string (
+				out, folder_newline, cancellable, NULL);
+
+			if (ret == -1)
+				goto fail;
+		}
 		goto done;
 	}
 
@@ -102,8 +112,13 @@ folders_update (const gchar *root,
 			gint cmp = strcmp (line, folder);
 
 			if (cmp > 0) {
+				gint ret;
+
 				/* found insertion point */
-				if (camel_stream_printf(out, "%s\n", folder) == -1)
+				ret = camel_stream_write_string (
+					out, folder_newline, cancellable, NULL);
+
+				if (ret == -1)
 					goto fail;
 				mode = UPDATE_NONE;
 			} else if (tmp == NULL) {
@@ -115,16 +130,33 @@ folders_update (const gchar *root,
 			break;
 		}
 
-		if (copy && camel_stream_printf(out, "%s\n", line) == -1)
-			goto fail;
+		if (copy) {
+			gchar *string;
+			gint ret;
+
+			string = g_strdup_printf ("%s\n", line);
+			ret = camel_stream_write_string (
+				out, string, cancellable, NULL);
+			g_free (string);
+
+			if (ret == -1)
+				goto fail;
+		}
 
 		g_free (line);
 		line = NULL;
 	}
 
 	/* add to end? */
-	if (mode == UPDATE_ADD && camel_stream_printf(out, "%s\n", folder) == -1)
-		goto fail;
+	if (mode == UPDATE_ADD) {
+		gint ret;
+
+		ret = camel_stream_write_string (
+			out, folder_newline, cancellable, NULL);
+
+		if (ret == -1)
+			goto fail;
+	}
 
 	if (camel_stream_close (out, cancellable, NULL) == -1)
 		goto fail;
@@ -139,6 +171,8 @@ fail:
 		g_object_unref (in);
 	if (out)
 		g_object_unref (out);
+
+	g_free (folder_newline);
 }
 
 static void
diff --git a/camel/providers/nntp/camel-nntp-store.c b/camel/providers/nntp/camel-nntp-store.c
index c1626e7..f9e8c8b 100644
--- a/camel/providers/nntp/camel-nntp-store.c
+++ b/camel/providers/nntp/camel-nntp-store.c
@@ -1479,6 +1479,7 @@ camel_nntp_raw_commandv (CamelNNTPStore *store,
                          const gchar *fmt,
                          va_list ap)
 {
+	CamelStream *stream;
 	GByteArray *byte_array;
 	const guchar *p, *ps;
 	guchar c;
@@ -1493,54 +1494,69 @@ camel_nntp_raw_commandv (CamelNNTPStore *store,
 	p = (const guchar *) fmt;
 	ps = (const guchar *) p;
 
+	stream = CAMEL_STREAM (store->mem);
+
 	while ((c = *p++)) {
+		gchar *strval;
+
 		switch (c) {
 		case '%':
 			c = *p++;
-			camel_stream_write ((CamelStream *) store->mem, (const gchar *) ps, p - ps - (c == '%' ? 1 : 2), NULL, NULL);
+			camel_stream_write (
+				stream, (const gchar *) ps,
+				p - ps - (c == '%' ? 1 : 2),
+				NULL, NULL);
 			ps = p;
 			switch (c) {
 			case 's':
 				s = va_arg (ap, gchar *);
-				camel_stream_write ((CamelStream *) store->mem, s, strlen (s), NULL, NULL);
+				strval = g_strdup (s);
 				break;
 			case 'd':
 				d = va_arg (ap, gint);
-				camel_stream_printf((CamelStream *)store->mem, "%d", d);
+				strval = g_strdup_printf ("%d", d);
 				break;
 			case 'u':
 				u = va_arg (ap, guint);
-				camel_stream_printf((CamelStream *)store->mem, "%u", u);
+				strval = g_strdup_printf ("%u", u);
 				break;
 			case 'm':
 				s = va_arg (ap, gchar *);
-				camel_stream_printf((CamelStream *)store->mem, "<%s>", s);
+				strval = g_strdup_printf ("<%s>", s);
 				break;
 			case 'r':
 				u = va_arg (ap, guint);
 				u2 = va_arg (ap, guint);
 				if (u == u2)
-					camel_stream_printf((CamelStream *)store->mem, "%u", u);
+					strval = g_strdup_printf ("%u", u);
 				else
-					camel_stream_printf((CamelStream *)store->mem, "%u-%u", u, u2);
+					strval = g_strdup_printf ("%u-%u", u, u2);
 				break;
 			default:
 				g_warning("Passing unknown format to nntp_command: %c\n", c);
 				g_assert (0);
 			}
+
+			camel_stream_write_string (stream, strval, NULL, NULL);
+
+			g_free (strval);
+			strval = NULL;
 		}
 	}
 
-	camel_stream_write ((CamelStream *) store->mem, (const gchar *) ps, p-ps-1, NULL, NULL);
-	camel_stream_write ((CamelStream *) store->mem, "\r\n", 2, NULL, NULL);
+	camel_stream_write (stream, (const gchar *) ps, p-ps-1, NULL, NULL);
+	camel_stream_write (stream, "\r\n", 2, NULL, NULL);
 
 	byte_array = camel_stream_mem_get_byte_array (store->mem);
 
-	if (camel_stream_write ((CamelStream *) store->stream, (const gchar *) byte_array->data, byte_array->len, cancellable, error) == -1)
+	if (camel_stream_write (
+		(CamelStream *) store->stream,
+		(const gchar *) byte_array->data,
+		byte_array->len, cancellable, error) == -1)
 		goto ioerror;
 
 	/* FIXME: hack */
-	g_seekable_seek (G_SEEKABLE (store->mem), 0, G_SEEK_SET, NULL, NULL);
+	g_seekable_seek (G_SEEKABLE (stream), 0, G_SEEK_SET, NULL, NULL);
 	g_byte_array_set_size (byte_array, 0);
 
 	if (camel_nntp_stream_line (store->stream, (guchar **) line, &u, cancellable, error) == -1)
diff --git a/camel/providers/pop3/camel-pop3-store.c b/camel/providers/pop3/camel-pop3-store.c
index bfb64df..6298bb6 100644
--- a/camel/providers/pop3/camel-pop3-store.c
+++ b/camel/providers/pop3/camel-pop3-store.c
@@ -314,6 +314,7 @@ try_sasl (CamelPOP3Store *store,
 	CamelURL *url;
 	guchar *line, *resp;
 	CamelSasl *sasl;
+	gchar *string;
 	guint len;
 	gint ret;
 
@@ -331,7 +332,12 @@ try_sasl (CamelPOP3Store *store,
 		return -1;
 	}
 
-	if (camel_stream_printf((CamelStream *)stream, "AUTH %s\r\n", mech) == -1)
+	string = g_strdup_printf ("AUTH %s\r\n", mech);
+	ret = camel_stream_write_string (
+		CAMEL_STREAM (stream), string, cancellable, error);
+	g_free (string);
+
+	if (ret == -1)
 		goto ioerror;
 
 	while (1) {
@@ -359,7 +365,8 @@ try_sasl (CamelPOP3Store *store,
 		if (strncmp((gchar *) line, "+ ", 2) != 0
 		    || camel_sasl_get_authenticated (sasl)
 		    || (resp = (guchar *) camel_sasl_challenge_base64_sync (sasl, (const gchar *) line+2, cancellable, NULL)) == NULL) {
-			camel_stream_printf((CamelStream *)stream, "*\r\n");
+			camel_stream_write_string (
+				CAMEL_STREAM (stream), "*\r\n", NULL, NULL);
 			camel_pop3_stream_line (stream, &line, &len, NULL, NULL);
 			g_set_error (
 				error, CAMEL_SERVICE_ERROR,
@@ -370,8 +377,13 @@ try_sasl (CamelPOP3Store *store,
 			goto done;
 		}
 
-		ret = camel_stream_printf((CamelStream *)stream, "%s\r\n", resp);
+		string = g_strdup_printf ("%s\r\n", resp);
+		ret = camel_stream_write_string (
+			CAMEL_STREAM (stream), string, cancellable, error);
+		g_free (string);
+
 		g_free (resp);
+
 		if (ret == -1)
 			goto ioerror;
 
diff --git a/camel/tests/folder/test9.c b/camel/tests/folder/test9.c
index 292b38f..6f5a2a3 100644
--- a/camel/tests/folder/test9.c
+++ b/camel/tests/folder/test9.c
@@ -149,7 +149,7 @@ gint main (gint argc, gchar **argv)
 		camel_mime_message_set_date (msg, j*60*24, 0);
 		pull ();
 
-		camel_stream_printf (mbox, "From \n");
+		camel_stream_write_string (mbox, "From \n", NULL, NULL);
 		check (camel_data_wrapper_write_to_stream_sync (
 			CAMEL_DATA_WRAPPER (msg), mbox, NULL, NULL) != -1);
 #if 0



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]