diff options
Diffstat (limited to 'camel/camel-multipart.c')
-rw-r--r-- | camel/camel-multipart.c | 579 |
1 files changed, 334 insertions, 245 deletions
diff --git a/camel/camel-multipart.c b/camel/camel-multipart.c index 5271f16a52..3292e04b78 100644 --- a/camel/camel-multipart.c +++ b/camel/camel-multipart.c @@ -2,15 +2,15 @@ /* camel-multipart.c : Abstract class for a multipart */ -/* +/* * - * Author : + * Author : * Bertrand Guiheneuf <bertrand@helixcode.com> * * Copyright 1999, 2000 Helix Code, Inc. (http://www.helixcode.com) * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * @@ -29,37 +29,37 @@ #include "gmime-content-field.h" #include "gmime-utils.h" #include "camel-stream-mem.h" -#include "camel-seekable-substream.h" +#include "camel-seekable-substream.h" #include "camel-mime-body-part.h" #include "camel-multipart.h" -static void my_add_part (CamelMultipart *multipart, +static void add_part (CamelMultipart *multipart, CamelMimeBodyPart *part); -static void my_add_part_at (CamelMultipart *multipart, - CamelMimeBodyPart *part, - guint index); -static void my_remove_part (CamelMultipart *multipart, - CamelMimeBodyPart *part); -static CamelMimeBodyPart * my_remove_part_at (CamelMultipart *multipart, - guint index); -static CamelMimeBodyPart * my_get_part (CamelMultipart *multipart, - guint index); -static guint my_get_number (CamelMultipart *multipart); -static void my_set_parent (CamelMultipart *multipart, - CamelMimePart *parent); -static CamelMimePart * my_get_parent (CamelMultipart *multipart); -static void my_set_boundary (CamelMultipart *multipart, - gchar *boundary); -static const gchar * my_get_boundary (CamelMultipart *multipart); -static void my_write_to_stream (CamelDataWrapper *data_wrapper, - CamelStream *stream); -static void my_set_input_stream (CamelDataWrapper *data_wrapper, - CamelStream *stream); - -static void my_finalize (GtkObject *object); - -static CamelDataWrapperClass *parent_class=NULL; +static void add_part_at (CamelMultipart *multipart, + CamelMimeBodyPart *part, + guint index); +static void remove_part (CamelMultipart *multipart, + CamelMimeBodyPart *part); +static CamelMimeBodyPart * remove_part_at (CamelMultipart *multipart, + guint index); +static CamelMimeBodyPart * get_part (CamelMultipart *multipart, + guint index); +static guint get_number (CamelMultipart *multipart); +static void set_parent (CamelMultipart *multipart, + CamelMimePart *parent); +static CamelMimePart * get_parent (CamelMultipart *multipart); +static void set_boundary (CamelMultipart *multipart, + gchar *boundary); +static const gchar * get_boundary (CamelMultipart *multipart); +static void write_to_stream (CamelDataWrapper *data_wrapper, + CamelStream *stream); +static void set_input_stream (CamelDataWrapper *data_wrapper, + CamelStream *stream); + +static void finalize (GtkObject *object); + +static CamelDataWrapperClass *parent_class = NULL; @@ -73,51 +73,52 @@ static CamelDataWrapperClass *parent_class=NULL; static void camel_multipart_class_init (CamelMultipartClass *camel_multipart_class) { - CamelDataWrapperClass *camel_data_wrapper_class = CAMEL_DATA_WRAPPER_CLASS (camel_multipart_class); - GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (camel_multipart_class); - + CamelDataWrapperClass *camel_data_wrapper_class = + CAMEL_DATA_WRAPPER_CLASS (camel_multipart_class); + GtkObjectClass *gtk_object_class = + GTK_OBJECT_CLASS (camel_multipart_class); + parent_class = gtk_type_class (camel_data_wrapper_get_type ()); - + /* virtual method definition */ - camel_multipart_class->add_part = my_add_part; - camel_multipart_class->add_part_at = my_add_part_at; - camel_multipart_class->remove_part = my_remove_part; - camel_multipart_class->remove_part_at = my_remove_part_at; - camel_multipart_class->get_part = my_get_part; - camel_multipart_class->get_number = my_get_number; - camel_multipart_class->set_parent = my_set_parent; - camel_multipart_class->get_parent = my_get_parent; - camel_multipart_class->set_boundary = my_set_boundary; - camel_multipart_class->get_boundary = my_get_boundary; - + camel_multipart_class->add_part = add_part; + camel_multipart_class->add_part_at = add_part_at; + camel_multipart_class->remove_part = remove_part; + camel_multipart_class->remove_part_at = remove_part_at; + camel_multipart_class->get_part = get_part; + camel_multipart_class->get_number = get_number; + camel_multipart_class->set_parent = set_parent; + camel_multipart_class->get_parent = get_parent; + camel_multipart_class->set_boundary = set_boundary; + camel_multipart_class->get_boundary = get_boundary; + /* virtual method overload */ - camel_data_wrapper_class->write_to_stream = my_write_to_stream; - camel_data_wrapper_class->set_input_stream = my_set_input_stream; - - gtk_object_class->finalize = my_finalize; + camel_data_wrapper_class->write_to_stream = write_to_stream; + camel_data_wrapper_class->set_input_stream = set_input_stream; + + gtk_object_class->finalize = finalize; } static void -camel_multipart_init (gpointer object, gpointer klass) +camel_multipart_init (gpointer object, gpointer klass) { CamelMultipart *multipart = CAMEL_MULTIPART (object); - camel_data_wrapper_set_mime_type ( CAMEL_DATA_WRAPPER (multipart), "multipart"); - camel_multipart_set_boundary (multipart, "__camel_boundary__"); + + camel_data_wrapper_set_mime_type (CAMEL_DATA_WRAPPER (multipart), + "multipart"); + camel_multipart_set_boundary (multipart, "=-=-=-="); multipart->preface = NULL; multipart->postface = NULL; - } - - GtkType camel_multipart_get_type (void) { static GtkType camel_multipart_type = 0; - - if (!camel_multipart_type) { - GtkTypeInfo camel_multipart_info = + + if (!camel_multipart_type) { + GtkTypeInfo camel_multipart_info = { "CamelMultipart", sizeof (CamelMultipart), @@ -128,105 +129,151 @@ camel_multipart_get_type (void) /* reserved_2 */ NULL, (GtkClassInitFunc) NULL, }; - + camel_multipart_type = gtk_type_unique (camel_data_wrapper_get_type (), &camel_multipart_info); } - + return camel_multipart_type; } static void -my_unref_part (gpointer data, gpointer user_data) +unref_part (gpointer data, gpointer user_data) { GtkObject *body_part = GTK_OBJECT (data); - + gtk_object_unref (body_part); } -static void -my_finalize (GtkObject *object) +static void +finalize (GtkObject *object) { CamelMultipart *multipart = CAMEL_MULTIPART (object); - - if (multipart->parent) gtk_object_unref (GTK_OBJECT (multipart->parent)); - - g_list_foreach (multipart->parts, my_unref_part, NULL); - - if (multipart->boundary) g_free (multipart->boundary); - if (multipart->preface) g_free (multipart->preface); - if (multipart->postface) g_free (multipart->postface); - + + if (multipart->parent) + gtk_object_unref (GTK_OBJECT (multipart->parent)); + + g_list_foreach (multipart->parts, unref_part, NULL); + + if (multipart->boundary) + g_free (multipart->boundary); + if (multipart->preface) + g_free (multipart->preface); + if (multipart->postface) + g_free (multipart->postface); + GTK_OBJECT_CLASS (parent_class)->finalize (object); } - -CamelMultipart * +/** + * camel_multipart_new: + * + * Create a new CamelMultipart object. + * + * Return value: a new CamelMultipart + **/ +CamelMultipart * camel_multipart_new (void) { CamelMultipart *multipart; - + multipart = (CamelMultipart *)gtk_type_new (CAMEL_MULTIPART_TYPE); multipart->preface = NULL; multipart->postface = NULL; - + return multipart; } static void -my_add_part (CamelMultipart *multipart, CamelMimeBodyPart *part) +add_part (CamelMultipart *multipart, CamelMimeBodyPart *part) { multipart->parts = g_list_append (multipart->parts, part); - if (part) gtk_object_ref (GTK_OBJECT (part)); + gtk_object_ref (GTK_OBJECT (part)); } -void +/** + * camel_multipart_add_part: + * @multipart: a CamelMultipart + * @part: the body part to add + * + * Appends the body part to the multipart object. + **/ +void camel_multipart_add_part (CamelMultipart *multipart, CamelMimeBodyPart *part) { - CMP_CLASS (multipart)->add_part (multipart, part); -} + g_return_if_fail (CAMEL_IS_MULTIPART (multipart)); + g_return_if_fail (CAMEL_IS_MIME_BODY_PART (part)); + + CMP_CLASS (multipart)->add_part (multipart, part); +} static void -my_add_part_at (CamelMultipart *multipart, CamelMimeBodyPart *part, guint index) +add_part_at (CamelMultipart *multipart, CamelMimeBodyPart *part, guint index) { multipart->parts = g_list_insert (multipart->parts, part, index); - if (part) gtk_object_ref (GTK_OBJECT (part)); + gtk_object_ref (GTK_OBJECT (part)); } -void -camel_multipart_add_part_at (CamelMultipart *multipart, CamelMimeBodyPart *part, guint index) +/** + * camel_multipart_add_part_at: + * @multipart: a CamelMultipart + * @part: the body part to add + * @index: index to add the multipart at + * + * Adds the body part to the multipart object after the @index'th + * element. If @index is greater than the number of parts, it is + * equivalent to camel_multipart_add_part(). + **/ +void +camel_multipart_add_part_at (CamelMultipart *multipart, + CamelMimeBodyPart *part, guint index) { + g_return_if_fail (CAMEL_IS_MULTIPART (multipart)); + g_return_if_fail (CAMEL_IS_MIME_BODY_PART (part)); + CMP_CLASS (multipart)->add_part_at (multipart, part, index); } + static void -my_remove_part (CamelMultipart *multipart, CamelMimeBodyPart *part) +remove_part (CamelMultipart *multipart, CamelMimeBodyPart *part) { if (!multipart->parts) return; multipart->parts = g_list_remove (multipart->parts, part); - if (part) gtk_object_unref (GTK_OBJECT (part)); + gtk_object_unref (GTK_OBJECT (part)); } -void -camel_multipart_remove_part (CamelMultipart *multipart, CamelMimeBodyPart *part) +/** + * camel_multipart_remove_part: + * @multipart: a CamelMultipart + * @part: the part to remove + * + * Removes @part from @multipart. + **/ +void +camel_multipart_remove_part (CamelMultipart *multipart, + CamelMimeBodyPart *part) { + g_return_if_fail (CAMEL_IS_MULTIPART (multipart)); + g_return_if_fail (CAMEL_IS_MIME_BODY_PART (part)); + CMP_CLASS (multipart)->remove_part (multipart, part); } static CamelMimeBodyPart * -my_remove_part_at (CamelMultipart *multipart, guint index) +remove_part_at (CamelMultipart *multipart, guint index) { GList *parts_list; GList *part_to_remove; CamelMimeBodyPart *removed_body_part; - + if (!(multipart->parts)) return NULL; - + parts_list = multipart->parts; part_to_remove = g_list_nth (parts_list, index); if (!part_to_remove) { @@ -235,113 +282,177 @@ my_remove_part_at (CamelMultipart *multipart, guint index) return NULL; } removed_body_part = CAMEL_MIME_BODY_PART (part_to_remove->data); - + multipart->parts = g_list_remove_link (parts_list, part_to_remove); - if (part_to_remove->data) gtk_object_unref (GTK_OBJECT (part_to_remove->data)); + if (part_to_remove->data) + gtk_object_unref (GTK_OBJECT (part_to_remove->data)); g_list_free_1 (part_to_remove); - + return removed_body_part; - } +/** + * camel_multipart_remove_part_at: + * @multipart: a CamelMultipart + * @index: a zero-based index indicating the part to remove + * + * Remove the indicated part from the multipart object. + * + * Return value: the removed part. Note that it is gtk_object_unref()ed + * before being returned, which may cause it to be destroyed. + **/ CamelMimeBodyPart * camel_multipart_remove_part_at (CamelMultipart *multipart, guint index) { + g_return_val_if_fail (CAMEL_IS_MULTIPART (multipart), NULL); + return CMP_CLASS (multipart)->remove_part_at (multipart, index); } static CamelMimeBodyPart * -my_get_part (CamelMultipart *multipart, guint index) +get_part (CamelMultipart *multipart, guint index) { GList *part; + if (!(multipart->parts)) return NULL; - + part = g_list_nth (multipart->parts, index); - if (part) return CAMEL_MIME_BODY_PART (part->data); + if (part) + return CAMEL_MIME_BODY_PART (part->data); else return NULL; } -CamelMimeBodyPart * +/** + * camel_multipart_get_part: + * @multipart: a CamelMultipart + * @index: a zero-based index indicating the part to get + * + * Return value: the indicated subpart, or %NULL + **/ +CamelMimeBodyPart * camel_multipart_get_part (CamelMultipart *multipart, guint index) { + g_return_val_if_fail (CAMEL_IS_MULTIPART (multipart), NULL); + return CMP_CLASS (multipart)->get_part (multipart, index); } -static guint -my_get_number (CamelMultipart *multipart) +static guint +get_number (CamelMultipart *multipart) { return g_list_length (multipart->parts); } -guint +/** + * camel_multipart_get_number: + * @multipart: a CamelMultipart + * + * Return value: the number of subparts in @multipart + **/ +guint camel_multipart_get_number (CamelMultipart *multipart) { + g_return_val_if_fail (CAMEL_IS_MULTIPART (multipart), 0); + return CMP_CLASS (multipart)->get_number (multipart); } static void -my_set_parent (CamelMultipart *multipart, CamelMimePart *parent) +set_parent (CamelMultipart *multipart, CamelMimePart *parent) { multipart->parent = parent; - if (parent) gtk_object_ref (GTK_OBJECT (parent)); + if (parent) + gtk_object_ref (GTK_OBJECT (parent)); } +/** + * camel_multipart_set_parent: + * @multipart: a CamelMultipart + * @parent: the CamelMimePart that is @multipart's parent + * + * Sets the parent of @multipart. + **/ void camel_multipart_set_parent (CamelMultipart *multipart, CamelMimePart *parent) { + g_return_if_fail (CAMEL_IS_MULTIPART (multipart)); + g_return_if_fail (CAMEL_IS_MIME_PART (parent)); + CMP_CLASS (multipart)->set_parent (multipart, parent); } static CamelMimePart * -my_get_parent (CamelMultipart *multipart) +get_parent (CamelMultipart *multipart) { return multipart->parent; } - +/** + * camel_multipart_get_parent: + * @multipart: a CamelMultipart + * + * Return value: @multipart's parent part + **/ CamelMimePart * camel_multipart_get_parent (CamelMultipart *multipart) { + g_return_val_if_fail (CAMEL_IS_MULTIPART (multipart), NULL); + return CMP_CLASS (multipart)->get_parent (multipart); } +static void +set_boundary (CamelMultipart *multipart, gchar *boundary) +{ + CamelDataWrapper *cdw = CAMEL_DATA_WRAPPER (multipart); + g_return_if_fail (cdw->mime_type != NULL); - -static void -my_set_boundary (CamelMultipart *multipart, gchar *boundary) -{ - gmime_content_field_set_parameter (CAMEL_DATA_WRAPPER (multipart)->mime_type, "boundary", boundary); + gmime_content_field_set_parameter (cdw->mime_type, "boundary", + boundary); } -void +/** + * camel_multipart_set_boundary: + * @multipart: a CamelMultipart + * @boundary: the message boundary + * + * Sets the message boundary for @multipart to @boundary. This should + * be a string which does not occur anywhere in any of @multipart's + * subparts. + **/ +void camel_multipart_set_boundary (CamelMultipart *multipart, gchar *boundary) { + g_return_if_fail (CAMEL_IS_MULTIPART (multipart)); + g_return_if_fail (boundary != NULL); + CMP_CLASS (multipart)->set_boundary (multipart, boundary); } static const gchar * -my_get_boundary (CamelMultipart *multipart) +get_boundary (CamelMultipart *multipart) { - const gchar *boundary; - if (!CAMEL_DATA_WRAPPER (multipart)->mime_type) { - g_warning ("CamelMultipart::_get_boundary CAMEL_DATA_WRAPPER " - "(multipart)->mime_type is NULL\n"); - return NULL; - } - boundary = gmime_content_field_get_parameter (CAMEL_DATA_WRAPPER (multipart)->mime_type, "boundary"); - return boundary; -} + CamelDataWrapper *cdw = CAMEL_DATA_WRAPPER (multipart); + g_return_val_if_fail (cdw->mime_type != NULL, NULL); + return gmime_content_field_get_parameter (cdw->mime_type, "boundary"); +} +/** + * camel_multipart_get_boundary: + * @multipart: a CamelMultipart + * + * Return value: @multipart's message boundary + **/ const gchar * camel_multipart_get_boundary (CamelMultipart *multipart) { @@ -349,140 +460,128 @@ camel_multipart_get_boundary (CamelMultipart *multipart) } -struct my_print_part_user_data { +struct print_part_user_data { CamelStream *stream; const gchar *boundary; }; - - static void -my_print_part (gpointer data, gpointer user_data) +print_part (gpointer data, gpointer user_data) { CamelMimeBodyPart *body_part = CAMEL_MIME_BODY_PART (data); - struct my_print_part_user_data *ud = (struct my_print_part_user_data *)user_data; - - if (ud->boundary) camel_stream_write_strings (ud->stream, "\n--", ud->boundary, "\n", NULL); + struct print_part_user_data *ud = user_data; + + if (ud->boundary) + camel_stream_write_strings (ud->stream, "\n--", + ud->boundary, "\n", NULL); else camel_stream_write_strings (ud->stream, "\n--\n", NULL); - camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (body_part), ud->stream); - - + camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (body_part), + ud->stream); } - - static void -my_write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream) +write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream) { CamelMultipart *multipart = CAMEL_MULTIPART (data_wrapper); - struct my_print_part_user_data ud; + struct print_part_user_data ud; const gchar *boundary; - + /* get the bundary text */ boundary = camel_multipart_get_boundary (multipart); /* we cannot write a multipart without a boundary string */ g_return_if_fail (boundary); - /* - * write the preface text (usually something like - * "This is a mime message, if you see this, then + /* + * write the preface text (usually something like + * "This is a mime message, if you see this, then * your mail client probably doesn't support ...." */ - if (multipart->preface) camel_stream_write_strings (stream, multipart->preface, NULL); - - /* - * Now, write all the parts, separated by the boundary + if (multipart->preface) + camel_stream_write_strings (stream, multipart->preface, NULL); + + /* + * Now, write all the parts, separated by the boundary * delimiter */ ud.boundary = boundary; ud.stream = stream; if (boundary && (boundary[0] == '\0')) g_warning ("Multipart boundary is zero length\n"); - g_list_foreach (multipart->parts, my_print_part, (gpointer)&ud); + g_list_foreach (multipart->parts, print_part, (gpointer)&ud); /* write the terminating boudary delimiter */ camel_stream_write_strings (stream, "\n--", boundary, "--\n", NULL); /* and finally the postface */ - if (multipart->postface) camel_stream_write_strings (stream, multipart->postface, NULL); - + if (multipart->postface) + camel_stream_write_strings (stream, multipart->postface, NULL); } - - - - - -/**********************/ -/* new implementation */ - - /** - * my_localize_part: localize one part in a multipart environement. - * @stream: the stream to read the lines from. + * separate_part: separate one part in a multipart environement. + * @stream: the stream to read the lines from. * @normal_boundary: end of part bundary. * @end_boundary: end of multipart boundary. - * @end_position : end position of the mime part - * - * This routine is a bit special: RFC 2046 says that, in a multipart - * environment, the last crlf before a boundary belongs to the boundary. - * Thus, if there is no blank line before the boundary, the last crlf - * of the last line of the part is removed. - * - * Return value: true if the last boundary element has been found or if no more data was available from the stream, flase otherwise + * @end_position: end position of the mime part + * + * This routine is a bit special: RFC 2046 says that, in a multipart + * environment, the last CRLF before a boundary belongs to the boundary. + * Thus, if there is no blank line before the boundary, the last CRLF + * of the last line of the part is removed. + * + * Return value: %TRUE if the last boundary element has been found or + * if no more data was available from the stream, %FALSE otherwise **/ - static gboolean -my_localize_part (CamelStream *stream, - gchar *normal_boundary, - gchar *end_boundary, - guint32 *end_position) +separate_part (CamelStream *stream, gchar *normal_boundary, + gchar *end_boundary, guint32 *end_position) { gchar *new_line = NULL; gboolean end_of_part = FALSE; gboolean last_part = FALSE; guint32 last_position; - + /* Note for future enhancements */ - /* RFC 2046 precises that when parsing the content of a multipart - * element, the program should not think it will find the last boundary, - * and in particular, the message could have been damaged during - * transport, the parsing should still be OK */ - - g_assert (CAMEL_IS_SEEKABLE_STREAM (stream)); - - last_position = camel_seekable_stream_get_current_position (CAMEL_SEEKABLE_STREAM (stream)); + /* RFC 2046 specifies that when parsing the content of a + * multipart element, the program should not assume it will + * find the last boundary, and in particular, if the message + * is damaged during transport, the parsing should still be + * OK. + */ + + last_position = camel_seekable_stream_get_current_position ( + CAMEL_SEEKABLE_STREAM (stream)); new_line = gmime_read_line_from_stream (stream); - + while (new_line && !end_of_part && !last_part) { end_of_part = (strcmp (new_line, normal_boundary) == 0); last_part = (strcmp (new_line, end_boundary) == 0); if (!end_of_part && !last_part) { - g_free (new_line); - - last_position = - camel_seekable_stream_get_current_position (CAMEL_SEEKABLE_STREAM (stream)); - + + last_position = + camel_seekable_stream_get_current_position ( + CAMEL_SEEKABLE_STREAM (stream)); + new_line = gmime_read_line_from_stream (stream); } } - - if (new_line) g_free (new_line); - else last_part = TRUE; - - *end_position = last_position; - - return (last_part); -} + if (new_line) + g_free (new_line); + else + last_part = TRUE; + *end_position = last_position; + + return last_part; +} static void -my_set_input_stream (CamelDataWrapper *data_wrapper, CamelStream *stream) +set_input_stream (CamelDataWrapper *data_wrapper, CamelStream *stream) { CamelMultipart *multipart = CAMEL_MULTIPART (data_wrapper); CamelSeekableStream *seekable_stream = CAMEL_SEEKABLE_STREAM (stream); @@ -494,68 +593,58 @@ my_set_input_stream (CamelDataWrapper *data_wrapper, CamelStream *stream) guint32 part_begining, part_end; CamelSeekableSubstream *body_part_input_stream; guint32 saved_stream_pos; - - - /* call parent class implementation */ + + /* Call parent class implementation. */ parent_class->set_input_stream (data_wrapper, stream); - + boundary = camel_multipart_get_boundary (multipart); g_return_if_fail (boundary); - + real_boundary_line = g_strdup_printf ("--%s", boundary); end_boundary_line = g_strdup_printf ("--%s--", boundary); - - - /* read the prefix if any */ - end_of_multipart = my_localize_part (stream, - real_boundary_line, - end_boundary_line, - &part_end); - if (multipart->preface) g_free (multipart->preface); - - /* if ( (new_part->str)[0] != '\0') multipart->preface = g_strdup (new_part->str); */ - - /* read all the real parts */ + + /* Read the prefix, if any. */ + end_of_multipart = separate_part (stream, real_boundary_line, + end_boundary_line, &part_end); + if (multipart->preface) + g_free (multipart->preface); + + /* Read all the real parts. */ while (!end_of_multipart) { - /* determine the position of the begining of the part */ + /* Determine the position of the begining of the part. */ part_begining = camel_seekable_stream_get_current_position (seekable_stream); - + body_part = camel_mime_body_part_new (); - - end_of_multipart = my_localize_part (stream, - real_boundary_line, - end_boundary_line, - &part_end); + + end_of_multipart = separate_part (stream, real_boundary_line, + end_boundary_line, + &part_end); body_part_input_stream = CAMEL_SEEKABLE_SUBSTREAM ( camel_seekable_substream_new_with_seekable_stream_and_bounds (seekable_stream, - part_begining, + part_begining, part_end)); - - /* the seekable substream may change the position of the stream - so we must save it before calling set_input_stream */ + + /* The seekable substream may change the position of + * the stream so we must save it before calling + * set_input_stream. + */ saved_stream_pos = camel_seekable_stream_get_current_position (seekable_stream); - - camel_data_wrapper_set_input_stream (CAMEL_DATA_WRAPPER (body_part), - CAMEL_STREAM (body_part_input_stream)); - - /* restore the stream position */ - camel_seekable_stream_seek (seekable_stream, saved_stream_pos, CAMEL_STREAM_SET); - - /* add the body part to the multipart object */ + + camel_data_wrapper_set_input_stream ( + CAMEL_DATA_WRAPPER (body_part), + CAMEL_STREAM (body_part_input_stream)); + + /* Restore the stream position. */ + camel_seekable_stream_seek (seekable_stream, saved_stream_pos, + CAMEL_STREAM_SET); + + /* Add the body part to the multipart object. */ camel_multipart_add_part (multipart, body_part); - printf ("New Part\n"); - } - - /* g_string_assign (new_part, ""); */ - /* my_localize_part (new_part, stream, real_boundary_line, end_boundary_line); */ - - if (multipart->postface) g_free (multipart->postface); - /* if ( (new_part->str)[0] != '\0') multipart->postface = g_strdup (new_part->str); */ - - /* g_string_free (new_part, TRUE); */ - + + if (multipart->postface) + g_free (multipart->postface); + g_free (real_boundary_line); g_free (end_boundary_line); } - |