[evolution-data-server] Prefer g_seekable_seek() over camel_stream_reset().



commit b0ffef9c9da333986f99bb11fb14f456342336ea
Author: Matthew Barnes <mbarnes redhat com>
Date:   Tue Jul 5 09:20:47 2011 -0400

    Prefer g_seekable_seek() over camel_stream_reset().
    
    When a stream is obviously a file or memory stream (both of which
    implement the GSeekable interface), use g_seekable_seek() instead of
    camel_stream_reset().
    
    This is helping me discover if it's safe to remove camel_stream_reset().
    We want to eventually move to GIO streams, which have no reset method.

 camel/camel-cipher-context.c                    |    7 +++-
 camel/camel-data-wrapper.c                      |   16 ++++++--
 camel/camel-filter-driver.c                     |    3 +-
 camel/camel-gpg-context.c                       |   34 ++++++++++------
 camel/camel-mime-part-utils.c                   |    5 ++-
 camel/camel-multipart-signed.c                  |   48 +++++++++++++++++------
 camel/camel-smime-context.c                     |   27 ++++++++----
 camel/providers/imap/camel-imap-message-cache.c |    6 ++-
 camel/providers/imapx/camel-imapx-server.c      |    7 ++-
 camel/providers/imapx/camel-imapx-stream.c      |    6 ++-
 camel/providers/imapx/camel-imapx-utils.c       |   12 ++++-
 camel/providers/nntp/camel-nntp-folder.c        |    8 +++-
 camel/providers/nntp/camel-nntp-store.c         |    2 +-
 camel/providers/pop3/camel-pop3-folder.c        |    7 ++-
 camel/tests/lib/messages.c                      |    6 +-
 camel/tests/message/test4.c                     |    3 +-
 camel/tests/mime-filter/test-tohtml.c           |    3 +-
 camel/tests/smime/pgp.c                         |    6 +-
 camel/tests/smime/pkcs7.c                       |   10 ++--
 19 files changed, 149 insertions(+), 67 deletions(-)
---
diff --git a/camel/camel-cipher-context.c b/camel/camel-cipher-context.c
index ee9442b..5fa9802 100644
--- a/camel/camel-cipher-context.c
+++ b/camel/camel-cipher-context.c
@@ -1831,7 +1831,12 @@ camel_cipher_canonical_to_stream (CamelMimePart *part,
 		res = 0;
 
 	g_object_unref (filter);
-	camel_stream_reset (ostream, NULL);
+
+	/* Reset stream position to beginning. */
+	if (G_IS_SEEKABLE (ostream))
+		g_seekable_seek (
+			G_SEEKABLE (ostream), 0,
+			G_SEEK_SET, NULL, NULL);
 
 	return res;
 }
diff --git a/camel/camel-data-wrapper.c b/camel/camel-data-wrapper.c
index 58e9704..59dc6fe 100644
--- a/camel/camel-data-wrapper.c
+++ b/camel/camel-data-wrapper.c
@@ -153,10 +153,18 @@ data_wrapper_write_to_stream_sync (CamelDataWrapper *data_wrapper,
 		return -1;
 	}
 
-	if (camel_stream_reset (data_wrapper->stream, error) == -1) {
-		camel_data_wrapper_unlock (
-			data_wrapper, CAMEL_DATA_WRAPPER_STREAM_LOCK);
-		return -1;
+	if (G_IS_SEEKABLE (data_wrapper->stream)) {
+		gboolean success;
+
+		success = g_seekable_seek (
+			G_SEEKABLE (data_wrapper->stream),
+			0, G_SEEK_SET, cancellable, error);
+
+		if (!success) {
+			camel_data_wrapper_unlock (
+				data_wrapper, CAMEL_DATA_WRAPPER_STREAM_LOCK);
+			return -1;
+		}
 	}
 
 	ret = camel_stream_write_to_stream (
diff --git a/camel/camel-filter-driver.c b/camel/camel-filter-driver.c
index 017b417..3de4569 100644
--- a/camel/camel-filter-driver.c
+++ b/camel/camel-filter-driver.c
@@ -848,7 +848,8 @@ pipe_to_system (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFi
 	}
 
 	g_object_unref (stream);
-	camel_stream_reset (mem, NULL);
+
+	g_seekable_seek (G_SEEKABLE (mem), 0, G_SEEK_SET, NULL, NULL);
 
 	parser = camel_mime_parser_new ();
 	camel_mime_parser_init_with_stream (parser, mem, NULL);
diff --git a/camel/camel-gpg-context.c b/camel/camel-gpg-context.c
index 703ff46..86a33d2 100644
--- a/camel/camel-gpg-context.c
+++ b/camel/camel-gpg-context.c
@@ -1546,7 +1546,9 @@ gpg_sign_sync (CamelCipherContext *context,
 		if (out) {
 			printf("Writing gpg signing data to '%s'\n", name);
 			camel_stream_write_to_stream (istream, out);
-			camel_stream_reset (istream);
+			g_seekable_seek (
+				G_SEEKABLE (istream), 0,
+				G_SEEK_SET, NULL, NULL);
 			g_object_unref (out);
 		}
 		g_free (name);
@@ -1587,7 +1589,7 @@ gpg_sign_sync (CamelCipherContext *context,
 	success = TRUE;
 
 	dw = camel_data_wrapper_new ();
-	camel_stream_reset (ostream, NULL);
+	g_seekable_seek (G_SEEKABLE (ostream), 0, G_SEEK_SET, NULL, NULL);
 	camel_data_wrapper_construct_from_stream_sync (
 		dw, ostream, NULL, NULL);
 
@@ -1611,9 +1613,8 @@ gpg_sign_sync (CamelCipherContext *context,
 	camel_multipart_set_boundary ((CamelMultipart *) mps, NULL);
 
 	mps->signature = sigpart;
-	mps->contentraw = istream;
-	camel_stream_reset (istream, NULL);
-	g_object_ref (istream);
+	mps->contentraw = g_object_ref (istream);
+	g_seekable_seek (G_SEEKABLE (istream), 0, G_SEEK_SET, NULL, NULL);
 
 	camel_medium_set_content ((CamelMedium *) opart, (CamelDataWrapper *) mps);
 fail:
@@ -1688,7 +1689,8 @@ gpg_verify_sync (CamelCipherContext *context,
 		if (!camel_data_wrapper_decode_to_stream_sync (
 			content, istream, cancellable, error))
 			goto exception;
-		camel_stream_reset (istream, NULL);
+		g_seekable_seek (
+			G_SEEKABLE (istream), 0, G_SEEK_SET, NULL, NULL);
 		sigpart = NULL;
 	} else {
 		/* Invalid Mimetype */
@@ -1710,7 +1712,9 @@ gpg_verify_sync (CamelCipherContext *context,
 		if (out) {
 			printf("Writing gpg verify data to '%s'\n", name);
 			camel_stream_write_to_stream (istream, out);
-			camel_stream_reset (istream);
+			g_seekable_seek (
+				G_SEEKABLE (istream),
+				0, G_SEEK_SET, NULL, NULL);
 			g_object_unref (out);
 		}
 
@@ -1739,7 +1743,8 @@ gpg_verify_sync (CamelCipherContext *context,
 		}
 	}
 
-	camel_stream_reset (istream, NULL);
+	g_seekable_seek (G_SEEKABLE (istream), 0, G_SEEK_SET, NULL, NULL);
+
 	canon_stream = camel_stream_mem_new ();
 
 	/* strip trailing white-spaces */
@@ -1751,9 +1756,10 @@ gpg_verify_sync (CamelCipherContext *context,
 	camel_stream_write_to_stream (istream, filter, NULL, NULL);
 
 	g_object_unref (filter);
-	camel_stream_reset (istream, NULL);
 
-	camel_stream_reset (canon_stream, NULL);
+	g_seekable_seek (G_SEEKABLE (istream), 0, G_SEEK_SET, NULL, NULL);
+
+	g_seekable_seek (G_SEEKABLE (canon_stream), 0, G_SEEK_SET, NULL, NULL);
 
 	gpg = gpg_ctx_new (context);
 	gpg_ctx_set_mode (gpg, GPG_CTX_MODE_VERIFY);
@@ -1912,7 +1918,7 @@ gpg_encrypt_sync (CamelCipherContext *context,
 
 	vstream = camel_stream_mem_new ();
 	camel_stream_write_string (vstream, "Version: 1\n", NULL, NULL);
-	camel_stream_reset (vstream, NULL);
+	g_seekable_seek (G_SEEKABLE (vstream), 0, G_SEEK_SET, NULL, NULL);
 
 	verpart = camel_mime_part_new ();
 	dw = camel_data_wrapper_new ();
@@ -2008,7 +2014,8 @@ gpg_decrypt_sync (CamelCipherContext *context,
 		g_object_unref (istream);
 		return NULL;
 	}
-	camel_stream_reset (istream, NULL);
+
+	g_seekable_seek (G_SEEKABLE (istream), 0, G_SEEK_SET, NULL, NULL);
 
 	ostream = camel_stream_mem_new ();
 	camel_stream_mem_set_secure ((CamelStreamMem *) ostream);
@@ -2039,7 +2046,8 @@ gpg_decrypt_sync (CamelCipherContext *context,
 		goto fail;
 	}
 
-	camel_stream_reset (ostream, NULL);
+	g_seekable_seek (G_SEEKABLE (ostream), 0, G_SEEK_SET, NULL, NULL);
+
 	if (camel_content_type_is(ct, "multipart", "encrypted")) {
 		CamelDataWrapper *dw;
 		CamelStream *null = camel_stream_null_new ();
diff --git a/camel/camel-mime-part-utils.c b/camel/camel-mime-part-utils.c
index 7d496dc..47ccf25 100644
--- a/camel/camel-mime-part-utils.c
+++ b/camel/camel-mime-part-utils.c
@@ -197,7 +197,10 @@ camel_mime_message_build_preview (CamelMimePart *msg,
 			gchar *line = NULL;
 			GString *str = g_string_new (NULL);
 
-			camel_stream_reset (mstream, NULL);
+			g_seekable_seek (
+				G_SEEKABLE (mstream), 0,
+				G_SEEK_SET, NULL, NULL);
+
 			bstream = camel_stream_buffer_new (mstream, CAMEL_STREAM_BUFFER_READ|CAMEL_STREAM_BUFFER_BUFFER);
 
 			/* We should fetch just 200 unquoted lines. */
diff --git a/camel/camel-multipart-signed.c b/camel/camel-multipart-signed.c
index b82debe..4dea7d5 100644
--- a/camel/camel-multipart-signed.c
+++ b/camel/camel-multipart-signed.c
@@ -151,7 +151,9 @@ multipart_signed_parse_content (CamelMultipartSigned *mps)
 	   This is so we can parse all cases properly, without altering the content.
 	   All we are doing is finding part offsets. */
 
-	camel_stream_reset (stream, NULL);
+	/* XXX Assumes data wrapper streams are always seekable. */
+	g_seekable_seek (G_SEEKABLE (stream), 0, G_SEEK_SET, NULL, NULL);
+
 	cmp = camel_mime_parser_new ();
 	camel_mime_parser_init_with_stream (cmp, stream, NULL);
 	camel_mime_parser_push_state (cmp, CAMEL_MIME_PARSER_STATE_MULTIPART, boundary);
@@ -315,7 +317,10 @@ multipart_signed_write_to_stream_sync (CamelDataWrapper *data_wrapper,
 	/* 1 */
 	/* FIXME: locking? */
 	if (data_wrapper->stream) {
-		camel_stream_reset (data_wrapper->stream, NULL);
+		/* XXX Assumes data wrapper streams are always seekable. */
+		g_seekable_seek (
+			G_SEEKABLE (data_wrapper->stream),
+			0, G_SEEK_SET, NULL, NULL);
 		return camel_stream_write_to_stream (
 			data_wrapper->stream, stream, cancellable, error);
 	}
@@ -353,7 +358,10 @@ multipart_signed_write_to_stream_sync (CamelDataWrapper *data_wrapper,
 	total += count;
 
 	/* output content part */
-	camel_stream_reset (mps->contentraw, NULL);
+	/* XXX Both CamelGpgContext and CamelSMIMEContext set this
+	 *     to a memory stream, so assume it's always seekable. */
+	g_seekable_seek (
+		G_SEEKABLE (mps->contentraw), 0, G_SEEK_SET, NULL, NULL);
 	count = camel_stream_write_to_stream (
 		mps->contentraw, stream, cancellable, error);
 	if (count == -1)
@@ -476,7 +484,10 @@ multipart_signed_get_part (CamelMultipart *multipart,
 			stream = multipart_signed_clip_stream (
 				mps, mps->start1, mps->end1, NULL, NULL);
 		}
-		camel_stream_reset (stream, NULL);
+		/* XXX The "contentraw" stream is safe to assume to
+		 *     be seekable.  Data wrapper streams less so. */
+		g_seekable_seek (
+			G_SEEKABLE (stream), 0, G_SEEK_SET, NULL, NULL);
 		mps->content = camel_mime_part_new ();
 		camel_data_wrapper_construct_from_stream_sync (
 			CAMEL_DATA_WRAPPER (mps->content), stream, NULL, NULL);
@@ -494,7 +505,9 @@ multipart_signed_get_part (CamelMultipart *multipart,
 		}
 		stream = multipart_signed_clip_stream (
 			mps, mps->start2, mps->end2, NULL, NULL);
-		camel_stream_reset (stream, NULL);
+		/* XXX Assumes data wrapper streams are always seekable. */
+		g_seekable_seek (
+			G_SEEKABLE (stream), 0, G_SEEK_SET, NULL, NULL);
 		mps->signature = camel_mime_part_new ();
 		camel_data_wrapper_construct_from_stream_sync (
 			CAMEL_DATA_WRAPPER (mps->signature),
@@ -653,7 +666,8 @@ camel_multipart_signed_get_content_stream (CamelMultipartSigned *mps,
 	if (mps->contentraw) {
 		constream = g_object_ref (mps->contentraw);
 	} else {
-		CamelStream *stream;
+		CamelStream *base_stream;
+		CamelStream *filter_stream;
 		CamelMimeFilter *canon_filter;
 
 		if (mps->start1 == -1 && multipart_signed_parse_content (mps) == -1) {
@@ -667,19 +681,29 @@ camel_multipart_signed_get_content_stream (CamelMultipartSigned *mps,
 		/* first, prepare our parts */
 
 		/* FIXME Missing a GCancellable */
-		stream = multipart_signed_clip_stream (
+		base_stream = multipart_signed_clip_stream (
 			mps, mps->start1, mps->end1, NULL, error);
 
-		if (stream == NULL)
+		if (base_stream == NULL)
 			return NULL;
 
-		constream = camel_stream_filter_new (stream);
-		g_object_unref (stream);
+		filter_stream = camel_stream_filter_new (base_stream);
 
 		/* Note: see rfc2015 or rfc3156, section 5 */
-		canon_filter = camel_mime_filter_canon_new (CAMEL_MIME_FILTER_CANON_CRLF);
-		camel_stream_filter_add ((CamelStreamFilter *) constream, (CamelMimeFilter *) canon_filter);
+		canon_filter = camel_mime_filter_canon_new (
+			CAMEL_MIME_FILTER_CANON_CRLF);
+		camel_stream_filter_add (
+			CAMEL_STREAM_FILTER (filter_stream), canon_filter);
 		g_object_unref (canon_filter);
+
+		/* We want to return a pure memory stream,
+		 * so apply the CRLF filter ahead of time. */
+		constream = camel_stream_mem_new ();
+		camel_stream_write_to_stream (
+			filter_stream, constream, NULL, NULL);
+
+		g_object_unref (filter_stream);
+		g_object_unref (base_stream);
 	}
 
 	return constream;
diff --git a/camel/camel-smime-context.c b/camel/camel-smime-context.c
index b0bda48..efdbc34 100644
--- a/camel/camel-smime-context.c
+++ b/camel/camel-smime-context.c
@@ -850,7 +850,7 @@ smime_context_sign_sync (CamelCipherContext *context,
 	success = TRUE;
 
 	dw = camel_data_wrapper_new ();
-	camel_stream_reset (ostream, NULL);
+	g_seekable_seek (G_SEEKABLE (ostream), 0, G_SEEK_SET, NULL, NULL);
 	camel_data_wrapper_construct_from_stream_sync (
 		dw, ostream, cancellable, NULL);
 	dw->encoding = CAMEL_TRANSFER_ENCODING_BINARY;
@@ -880,9 +880,11 @@ smime_context_sign_sync (CamelCipherContext *context,
 		camel_multipart_set_boundary ((CamelMultipart *) mps, NULL);
 
 		mps->signature = sigpart;
-		mps->contentraw = istream;
-		camel_stream_reset (istream, NULL);
-		g_object_ref (istream);
+		mps->contentraw = g_object_ref (istream);
+
+		g_seekable_seek (
+			G_SEEKABLE (istream), 0,
+			G_SEEK_SET, NULL, NULL);
 
 		camel_medium_set_content ((CamelMedium *) opart, (CamelDataWrapper *) mps);
 	} else {
@@ -1214,7 +1216,8 @@ smime_context_decrypt_sync (CamelCipherContext *context,
 		g_object_unref (istream);
 		goto fail;
 	}
-	camel_stream_reset (istream, NULL);
+
+	g_seekable_seek (G_SEEKABLE (istream), 0, G_SEEK_SET, NULL, NULL);
 
 	dec = NSS_CMSDecoder_Start (NULL,
 				   sm_write_stream, ostream, /* content callback     */
@@ -1243,13 +1246,16 @@ smime_context_decrypt_sync (CamelCipherContext *context,
 	}
 #endif
 
-	camel_stream_reset (ostream, NULL);
+	g_seekable_seek (G_SEEKABLE (ostream), 0, G_SEEK_SET, NULL, NULL);
+
 	camel_data_wrapper_construct_from_stream_sync (
 		CAMEL_DATA_WRAPPER (opart), ostream, NULL, NULL);
 
 	if (NSS_CMSMessage_IsSigned (cmsg)) {
-		camel_stream_reset (ostream, NULL);
-		valid = sm_verify_cmsg (context, cmsg, ostream, cancellable, error);
+		g_seekable_seek (
+			G_SEEKABLE (ostream), 0, G_SEEK_SET, NULL, NULL);
+		valid = sm_verify_cmsg (
+			context, cmsg, ostream, cancellable, error);
 	} else {
 		valid = camel_cipher_validity_new ();
 		valid->encrypt.description = g_strdup (_("Encrypted content"));
@@ -1357,11 +1363,14 @@ camel_smime_context_describe_part (CamelSMIMEContext *context, CamelMimePart *pa
 		/* FIXME: stream this to the decoder incrementally */
 		buffer = g_byte_array_new ();
 		istream = camel_stream_mem_new_with_byte_array (buffer);
+
 		/* FIXME Pass a GCancellable and GError here. */
 		camel_data_wrapper_decode_to_stream_sync (
 			camel_medium_get_content ((CamelMedium *) part),
 			istream, NULL, NULL);
-		camel_stream_reset (istream, NULL);
+
+		g_seekable_seek (
+			G_SEEKABLE (istream), 0, G_SEEK_SET, NULL, NULL);
 
 		dec = NSS_CMSDecoder_Start (NULL,
 					   NULL, NULL,
diff --git a/camel/providers/imap/camel-imap-message-cache.c b/camel/providers/imap/camel-imap-message-cache.c
index 3a2aed3..20a55e5 100644
--- a/camel/providers/imap/camel-imap-message-cache.c
+++ b/camel/providers/imap/camel-imap-message-cache.c
@@ -349,7 +349,7 @@ insert_finish (CamelImapMessageCache *cache,
                CamelStream *stream)
 {
 	camel_stream_flush (stream, NULL, NULL);
-	camel_stream_reset (stream, NULL);
+	g_seekable_seek (G_SEEKABLE (stream), 0, G_SEEK_SET, NULL, NULL);
 	cache_put (cache, uid, key, stream);
 	g_free (path);
 
@@ -516,7 +516,9 @@ camel_imap_message_cache_get (CamelImapMessageCache *cache, const gchar *uid,
 
 	stream = g_hash_table_lookup (cache->parts, key);
 	if (stream) {
-		camel_stream_reset (CAMEL_STREAM (stream), NULL);
+		g_seekable_seek (
+			G_SEEKABLE (stream), 0,
+			G_SEEK_SET, NULL, NULL);
 		g_object_ref (stream);
 		g_free (path);
 		return stream;
diff --git a/camel/providers/imapx/camel-imapx-server.c b/camel/providers/imapx/camel-imapx-server.c
index 3ca39e6..f8bc7e4 100644
--- a/camel/providers/imapx/camel-imapx-server.c
+++ b/camel/providers/imapx/camel-imapx-server.c
@@ -481,9 +481,9 @@ imapx_command_add_part (CamelIMAPXCommand *ic, camel_imapx_command_part_t type,
 		if ( (type & CAMEL_IMAPX_COMMAND_MASK) == CAMEL_IMAPX_COMMAND_DATAWRAPPER) {
 			camel_data_wrapper_write_to_stream_sync ((CamelDataWrapper *) ob, (CamelStream *) null, NULL, NULL);
 		} else {
-			camel_stream_reset ((CamelStream *) ob, NULL);
+			g_seekable_seek (G_SEEKABLE (ob), 0, G_SEEK_SET, NULL, NULL);
 			camel_stream_write_to_stream ((CamelStream *) ob, (CamelStream *) null, NULL, NULL);
-			camel_stream_reset ((CamelStream *) ob, NULL);
+			g_seekable_seek (G_SEEKABLE (ob), 0, G_SEEK_SET, NULL, NULL);
 		}
 		type |= CAMEL_IMAPX_COMMAND_LITERAL_PLUS;
 		g_object_ref (ob);
@@ -544,7 +544,8 @@ imapx_command_add_part (CamelIMAPXCommand *ic, camel_imapx_command_part_t type,
 	memcpy (cp->data, byte_array->data, cp->data_size);
 	cp->data[cp->data_size] = 0;
 
-	camel_stream_reset ((CamelStream *) ic->mem, NULL);
+	g_seekable_seek (G_SEEKABLE (ic->mem), 0, G_SEEK_SET, NULL, NULL);
+
 	/* FIXME: hackish? */
 	g_byte_array_set_size (byte_array, 0);
 
diff --git a/camel/providers/imapx/camel-imapx-stream.c b/camel/providers/imapx/camel-imapx-stream.c
index 99852f2..84281ad 100644
--- a/camel/providers/imapx/camel-imapx-stream.c
+++ b/camel/providers/imapx/camel-imapx-stream.c
@@ -471,7 +471,11 @@ camel_imapx_stream_nstring_stream (CamelIMAPXStream *is,
 				ret = -1;
 				break;
 			}
-			camel_stream_reset (mem, NULL);
+
+			g_seekable_seek (
+				G_SEEKABLE (mem), 0,
+				G_SEEK_SET, NULL, NULL);
+
 			*stream = mem;
 			break;
 		case IMAPX_TOK_TOKEN:
diff --git a/camel/providers/imapx/camel-imapx-utils.c b/camel/providers/imapx/camel-imapx-utils.c
index 226bf1d..0580605 100644
--- a/camel/providers/imapx/camel-imapx-utils.c
+++ b/camel/providers/imapx/camel-imapx-utils.c
@@ -1447,17 +1447,23 @@ imapx_dump_fetch (struct _fetch_info *finfo)
 	if (finfo->body) {
 		camel_stream_printf(sout, "Body content:\n");
 		camel_stream_write_to_stream (finfo->body, sout, NULL, NULL);
-		camel_stream_reset (finfo->body, 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_to_stream (finfo->text, sout, NULL, NULL);
-		camel_stream_reset (finfo->text, 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_to_stream (finfo->header, sout, NULL, NULL);
-		camel_stream_reset (finfo->header, NULL);
+		g_seekable_seek (
+			G_SEEKABLE (finfo->header),
+			0, G_SEEK_SET, NULL, NULL);
 	}
 	if (finfo->minfo) {
 		camel_stream_printf(sout, "Message Info:\n");
diff --git a/camel/providers/nntp/camel-nntp-folder.c b/camel/providers/nntp/camel-nntp-folder.c
index 7f70d1e..de67d4c 100644
--- a/camel/providers/nntp/camel-nntp-folder.c
+++ b/camel/providers/nntp/camel-nntp-folder.c
@@ -221,9 +221,15 @@ nntp_folder_download_message (CamelNNTPFolder *nntp_folder,
 	if (ret == 220) {
 		stream = camel_data_cache_add (nntp_store->cache, "cache", msgid, NULL);
 		if (stream) {
+			gboolean success;
+
 			if (camel_stream_write_to_stream ((CamelStream *) nntp_store->stream, stream, cancellable, error) == -1)
 				goto fail;
-			if (camel_stream_reset (stream, error) == -1)
+
+			success = g_seekable_seek (
+				G_SEEKABLE (stream), 0,
+				G_SEEK_SET, cancellable, error);
+			if (!success)
 				goto fail;
 		} else {
 			stream = g_object_ref (nntp_store->stream);
diff --git a/camel/providers/nntp/camel-nntp-store.c b/camel/providers/nntp/camel-nntp-store.c
index 576399a..c1626e7 100644
--- a/camel/providers/nntp/camel-nntp-store.c
+++ b/camel/providers/nntp/camel-nntp-store.c
@@ -1540,7 +1540,7 @@ camel_nntp_raw_commandv (CamelNNTPStore *store,
 		goto ioerror;
 
 	/* FIXME: hack */
-	camel_stream_reset ((CamelStream *) store->mem, NULL);
+	g_seekable_seek (G_SEEKABLE (store->mem), 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-folder.c b/camel/providers/pop3/camel-pop3-folder.c
index b15cf49..f080748 100644
--- a/camel/providers/pop3/camel-pop3-folder.c
+++ b/camel/providers/pop3/camel-pop3-folder.c
@@ -181,7 +181,9 @@ cmd_tocache (CamelPOP3Engine *pe,
 
 	/* it all worked, output a '#' to say we're a-ok */
 	if (error == NULL) {
-		camel_stream_reset (fi->stream, NULL);
+		g_seekable_seek (
+			G_SEEKABLE (fi->stream),
+			0, G_SEEK_SET, NULL, NULL);
 		camel_stream_write (fi->stream, "#", 1, NULL, &error);
 	}
 
@@ -407,7 +409,8 @@ pop3_folder_get_message_sync (CamelFolder *folder,
 		/* getting error code? */
 		/*g_assert (pcr->state == CAMEL_POP3_COMMAND_DATA);*/
 		camel_pop3_engine_command_free (pop3_store->engine, pcr);
-		camel_stream_reset (stream, NULL);
+		g_seekable_seek (
+			G_SEEKABLE (stream), 0, G_SEEK_SET, NULL, NULL);
 
 		/* Check to see we have safely written flag set */
 		if (i == -1) {
diff --git a/camel/tests/lib/messages.c b/camel/tests/lib/messages.c
index 27c4140..8241636 100644
--- a/camel/tests/lib/messages.c
+++ b/camel/tests/lib/messages.c
@@ -200,20 +200,20 @@ test_message_compare (CamelMimeMessage *msg)
 	check_msg (camel_data_wrapper_write_to_stream_sync (
 		CAMEL_DATA_WRAPPER (msg), stream1, NULL, NULL) != -1,
 		"write_to_stream 1 failed", NULL);
-	camel_stream_reset (stream1, NULL);
+	g_seekable_seek (G_SEEKABLE (stream1), 0, G_SEEK_SET, NULL, NULL);
 
 	msg2 = camel_mime_message_new ();
 	check_msg (camel_data_wrapper_construct_from_stream_sync (
 		CAMEL_DATA_WRAPPER (msg2), stream1, NULL, NULL) != -1,
 		"construct_from_stream 1 failed");
-	camel_stream_reset (stream1, NULL);
+	g_seekable_seek (G_SEEKABLE (stream1), 0, G_SEEK_SET, NULL, NULL);
 
 	byte_array2 = g_byte_array_new ();
 	stream2 = camel_stream_mem_new_with_byte_array (byte_array2);
 	check_msg (camel_data_wrapper_write_to_stream_sync (
 		CAMEL_DATA_WRAPPER (msg2), stream2, NULL, NULL) != -1,
 		"write_to_stream 2 failed");
-	camel_stream_reset (stream2, NULL);
+	g_seekable_seek (G_SEEKABLE (stream2), 0, G_SEEK_SET, NULL, NULL);
 
 	if (byte_array1->len != byte_array2->len) {
 		CamelDataWrapper *content;
diff --git a/camel/tests/message/test4.c b/camel/tests/message/test4.c
index 3df1528..7485e63 100644
--- a/camel/tests/message/test4.c
+++ b/camel/tests/message/test4.c
@@ -104,7 +104,8 @@ gint main (gint argc, gchar **argv)
 		message = camel_mime_message_new ();
 		camel_data_wrapper_construct_from_stream_sync (
 			CAMEL_DATA_WRAPPER (message), stream, NULL, NULL);
-		camel_stream_reset (stream, NULL);
+		g_seekable_seek (
+			G_SEEKABLE (stream), 0, G_SEEK_SET, NULL, NULL);
 
 		/*dump_mime_struct ((CamelMimePart *) message, 0);*/
 		test_message_compare (message);
diff --git a/camel/tests/mime-filter/test-tohtml.c b/camel/tests/mime-filter/test-tohtml.c
index 7e8ad74..42a8d27 100644
--- a/camel/tests/mime-filter/test-tohtml.c
+++ b/camel/tests/mime-filter/test-tohtml.c
@@ -69,7 +69,8 @@ test_filter (CamelMimeFilter *f, const gchar *inname, const gchar *outname)
 	check_count (f, 1);
 	check_unref (in, 1);
 
-	check (camel_stream_reset (indisk, NULL) == 0);
+	check (g_seekable_seek (
+		G_SEEKABLE (indisk), 0, G_SEEK_SET, NULL, NULL));
 
 	camel_test_push("writing through filter stream");
 
diff --git a/camel/tests/smime/pgp.c b/camel/tests/smime/pgp.c
index 27563ba..1bd5fe9 100644
--- a/camel/tests/smime/pgp.c
+++ b/camel/tests/smime/pgp.c
@@ -130,7 +130,7 @@ gint main (gint argc, gchar **argv)
 	stream1 = camel_stream_mem_new ();
 	camel_stream_write (
 		stream1, "Hello, I am a test stream.\n", 27, NULL, NULL);
-	camel_stream_reset (stream1, NULL);
+	g_seekable_seek (G_SEEKABLE (stream1), 0, G_SEEK_SET, NULL, NULL);
 
 	conpart = camel_mime_part_new ();
 	dw = camel_data_wrapper_new ();
@@ -169,11 +169,11 @@ gint main (gint argc, gchar **argv)
 	camel_stream_write (
 		stream1, "Hello, I am a test of encryption/decryption.",
 		44, NULL, NULL);
-	camel_stream_reset (stream1, NULL);
+	g_seekable_seek (G_SEEKABLE (stream1), 0, G_SEEK_SET, NULL, NULL);
 
 	conpart = camel_mime_part_new ();
 	dw = camel_data_wrapper_new ();
-	camel_stream_reset (stream1, NULL);
+	g_seekable_seek (G_SEEKABLE (stream1), 0, G_SEEK_SET, NULL, NULL);
 	camel_data_wrapper_construct_from_stream_sync (
 		dw, stream1, NULL, NULL);
 	camel_medium_set_content ((CamelMedium *) conpart, dw);
diff --git a/camel/tests/smime/pkcs7.c b/camel/tests/smime/pkcs7.c
index 783c3f5..dd31188 100644
--- a/camel/tests/smime/pkcs7.c
+++ b/camel/tests/smime/pkcs7.c
@@ -103,7 +103,7 @@ gint main (gint argc, gchar **argv)
 
 	stream1 = camel_stream_mem_new ();
 	camel_stream_write (stream1, "Hello, I am a test stream.", 25);
-	camel_stream_reset (stream1);
+	g_seekable_seek (G_SEEKABLE (stream1), 0, G_SEEK_SET, NULL, NULL);
 
 	stream2 = camel_stream_mem_new ();
 
@@ -116,8 +116,8 @@ gint main (gint argc, gchar **argv)
 	camel_exception_clear (ex);
 
 	camel_test_push ("PKCS7 verify");
-	camel_stream_reset (stream1);
-	camel_stream_reset (stream2);
+	g_seekable_seek (G_SEEKABLE (stream1), 0, G_SEEK_SET, NULL, NULL);
+	g_seekable_seek (G_SEEKABLE (stream2), 0, G_SEEK_SET, NULL, NULL);
 	valid = camel_smime_verify (ctx, CAMEL_CIPHER_HASH_SHA1, stream1, stream2, ex);
 	check_msg (!camel_exception_is_set (ex), "%s", camel_exception_get_description (ex));
 	check_msg (camel_cipher_validity_get_valid (valid), "%s", camel_cipher_validity_get_description (valid));
@@ -132,7 +132,7 @@ gint main (gint argc, gchar **argv)
 	stream3 = camel_stream_mem_new ();
 
 	camel_stream_write (stream1, "Hello, I am a test of encryption/decryption.", 44);
-	camel_stream_reset (stream1);
+	g_seekable_seek (G_SEEKABLE (stream1), 0, G_SEEK_SET, NULL, NULL);
 
 	camel_exception_clear (ex);
 
@@ -145,7 +145,7 @@ gint main (gint argc, gchar **argv)
 	g_ptr_array_free (recipients, TRUE);
 	camel_test_pull ();
 
-	camel_stream_reset (stream2);
+	g_seekable_seek (G_SEEKABLE (stream2), 0, G_SEEK_SET, NULL, NULL);
 	camel_exception_clear (ex);
 
 	camel_test_push ("PKCS7 decrypt");



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