diff options
author | Ettore Perazzoli <ettore@src.gnome.org> | 1999-11-17 22:39:25 +0800 |
---|---|---|
committer | Ettore Perazzoli <ettore@src.gnome.org> | 1999-11-17 22:39:25 +0800 |
commit | ca7044930f42a698fd88f914c2512a20e2eeaae9 (patch) | |
tree | 522962a77005d741097713e87de1d50353b17768 /tests/test1.c | |
parent | 16de3313b700cb56ab9e829d1e9b7e7d2c81241b (diff) | |
download | gsoc2013-evolution-ca7044930f42a698fd88f914c2512a20e2eeaae9.tar.gz gsoc2013-evolution-ca7044930f42a698fd88f914c2512a20e2eeaae9.tar.zst gsoc2013-evolution-ca7044930f42a698fd88f914c2512a20e2eeaae9.zip |
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
Diffstat (limited to 'tests/test1.c')
-rw-r--r-- | tests/test1.c | 52 |
1 files changed, 49 insertions, 3 deletions
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 <stdio.h> + #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 [<attachment>]\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; |