From ca7044930f42a698fd88f914c2512a20e2eeaae9 Mon Sep 17 00:00:00 2001 From: Ettore Perazzoli Date: Wed, 17 Nov 1999 14:39:25 +0000 Subject: Added streaming capability to CamelDataWrapper. This makes it possible, for example, to build multipart messages out of files that are on disk without loading them in memory. svn path=/trunk/; revision=1394 --- tests/test1.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) (limited to 'tests/test1.c') diff --git a/tests/test1.c b/tests/test1.c index 2ee5241ad1..1adaf0b163 100644 --- a/tests/test1.c +++ b/tests/test1.c @@ -1,10 +1,13 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ + +#include + #include "camel-mime-message.h" #include "camel-mime-body-part.h" #include "camel-multipart.h" -#include "stdio.h" #include "camel-stream.h" #include "camel-stream-fs.h" +#include "camel-stream-data-wrapper.h" #include "camel-log.h" #include "camel.h" @@ -14,12 +17,33 @@ main (int argc, char**argv) CamelMimeMessage *message; CamelMultipart *multipart; CamelMimeBodyPart *body_part; + CamelMimeBodyPart *attachment_part; + CamelStream *attachment_stream; /* FILE *output_file; */ CamelStream *stream; gtk_init (&argc, &argv); camel_init (); + + if (argc < 2) { + attachment_stream = NULL; + } else { + if (argc == 2) { + attachment_stream = camel_stream_fs_new_with_name + (argv[1], CAMEL_STREAM_FS_READ); + if (attachment_stream == NULL) { + fprintf (stderr, "Cannot open `%s'\n", + argv[1]); + return 1; + } + } else { + fprintf (stderr, "Usage: %s []\n", + argv[0]); + return 1; + } + } + message = camel_mime_message_new_with_session ((CamelSession *)NULL); camel_mime_part_set_description (CAMEL_MIME_PART (message), "a test"); @@ -40,11 +64,29 @@ main (int argc, char**argv) camel_mime_message_add_recipient (message, RECIPIENT_TYPE_CC, g_strdup ("maury@justmagic.com")); camel_mime_message_add_recipient (message, RECIPIENT_TYPE_BCC, g_strdup ("Bertrand.Guiheneuf@aful.org")); - multipart = camel_multipart_new (); body_part = camel_mime_body_part_new (); camel_mime_part_set_text (CAMEL_MIME_PART (body_part), "This is a test.\nThis is only a test.\n"); camel_multipart_add_part (multipart, body_part); + + if (attachment_stream == NULL) { + attachment_part = NULL; + } else { + CamelDataWrapper *stream_wrapper; + + stream_wrapper = camel_stream_data_wrapper_new + (attachment_stream); + + attachment_part = camel_mime_body_part_new (); + camel_mime_part_set_encoding (CAMEL_MIME_PART (attachment_part), + CAMEL_MIME_PART_ENCODING_BASE64); + camel_medium_set_content_object (CAMEL_MEDIUM (attachment_part), + stream_wrapper); + camel_multipart_add_part (multipart, attachment_part); + + gtk_object_unref (GTK_OBJECT (stream_wrapper)); + } + camel_medium_set_content_object (CAMEL_MEDIUM (message), CAMEL_DATA_WRAPPER (multipart)); stream = camel_stream_fs_new_with_name ("mail1.test", CAMEL_STREAM_FS_WRITE ); @@ -53,13 +95,17 @@ main (int argc, char**argv) exit(2); } - camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (message), stream); + camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (message), + stream); camel_stream_close (stream); gtk_object_unref (GTK_OBJECT (stream)); gtk_object_unref (GTK_OBJECT (message)); gtk_object_unref (GTK_OBJECT (multipart)); gtk_object_unref (GTK_OBJECT (body_part)); + + if (attachment_part != NULL) + gtk_object_unref (GTK_OBJECT (attachment_part)); printf ("Test1 finished\n"); return 1; -- cgit v1.2.3