From 6b89252b9f2d3aff1ecd2779095a8b09685385c5 Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Thu, 28 Feb 2002 20:37:11 +0000 Subject: Rearrange the save filter stuff so that we save raw streams for all mime 2002-02-28 Jeffrey Stedfast * camel-mime-part-utils.c (camel_mime_part_construct_content_from_parser): Rearrange the save filter stuff so that we save raw streams for all mime parts. If the mime part turns out to be a multupart, then don't bother saving the raw stream, we only need to save the raw stream for leaf parts. svn path=/trunk/; revision=15873 --- camel/camel-mime-part-utils.c | 67 ++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 36 deletions(-) (limited to 'camel/camel-mime-part-utils.c') diff --git a/camel/camel-mime-part-utils.c b/camel/camel-mime-part-utils.c index e21152951b..3b93fab686 100644 --- a/camel/camel-mime-part-utils.c +++ b/camel/camel-mime-part-utils.c @@ -2,7 +2,8 @@ /* camel-mime-part-utils : Utility for mime parsing and so on * * Authors: Bertrand Guiheneuf - * Michael Zucchi + * Michael Zucchi + * Jeffrey Stedfast * * Copyright 1999, 2000 Ximian, Inc. (www.ximian.com) * @@ -312,10 +313,24 @@ simple_data_wrapper_construct_from_parser (CamelDataWrapper *dw, CamelMimeParser void camel_mime_part_construct_content_from_parser (CamelMimePart *dw, CamelMimeParser *mp) { + struct _header_content_type *content_type; CamelDataWrapper *content = NULL; + CamelMimeFilter *save_filter; + CamelStream *raw = NULL; + int saveid = -1; char *buf; int len; + content_type = camel_mime_parser_content_type (mp); + +#define SAVE_RAW_MIME_STREAM_FOR_SECURE_MIME_SIGNATURES +#ifdef SAVE_RAW_MIME_STREAM_FOR_SECURE_MIME_SIGNATURES + raw = camel_stream_mem_new (); + save_filter = camel_mime_filter_save_new_with_stream (raw); + saveid = camel_mime_parser_filter_add (mp, save_filter); + camel_object_unref (CAMEL_OBJECT (save_filter)); +#endif /* SAVE_RAW_MIME_STREAM_FOR_SECURE_MIME_SIGNATURES */ + switch (camel_mime_parser_state (mp)) { case HSCAN_HEADER: d(printf("Creating body part\n")); @@ -328,53 +343,24 @@ camel_mime_part_construct_content_from_parser (CamelMimePart *dw, CamelMimeParse camel_mime_part_construct_from_parser ((CamelMimePart *)content, mp); break; case HSCAN_MULTIPART: { - struct _header_content_type *content_type; - CamelMimeFilter *save_filter = NULL; CamelDataWrapper *bodypart; - CamelStream *raw = NULL; - int saveid = -1; /* FIXME: we should use a came-mime-mutlipart, not jsut a camel-multipart, but who cares */ d(printf("Creating multi-part\n")); + + /* we don't need to save raw streams for multiparts */ + camel_object_unref (CAMEL_OBJECT (raw)); + camel_mime_parser_filter_remove (mp, saveid); + content = (CamelDataWrapper *)camel_multipart_new (); - - content_type = camel_mime_parser_content_type (mp); + camel_multipart_set_boundary ((CamelMultipart *)content, header_content_type_param (content_type, "boundary")); -#define SAVE_RAW_MIME_STREAM_FOR_SECURE_MIME_SIGNATURES -#ifdef SAVE_RAW_MIME_STREAM_FOR_SECURE_MIME_SIGNATURES - if (header_content_type_is (content_type, "multipart", "signed")) { - /* save the raw mime stream for the first mime part in the multipart/signed */ - raw = camel_stream_mem_new (); - save_filter = camel_mime_filter_save_new_with_stream (raw); - saveid = camel_mime_parser_filter_add (mp, save_filter); - camel_object_unref (CAMEL_OBJECT (save_filter)); - } -#endif /* SAVE_RAW_MIME_STREAM_FOR_SECURE_MIME_SIGNATURES */ - while (camel_mime_parser_step (mp, &buf, &len) != HSCAN_MULTIPART_END) { camel_mime_parser_unstep (mp); bodypart = (CamelDataWrapper *)camel_mime_part_new (); camel_mime_part_construct_from_parser ((CamelMimePart *)bodypart, mp); -#ifdef SAVE_RAW_MIME_STREAM_FOR_SECURE_MIME_SIGNATURES - if (raw) { - /* set the raw mime stream on the first part within the multipart/signed */ - CamelDataWrapper *content_object; - - content_object = camel_medium_get_content_object (CAMEL_MEDIUM (bodypart)); - if (!CAMEL_IS_MULTIPART (content_object)) { - camel_stream_reset (raw); - CAMEL_MIME_PART (bodypart)->stream = raw; - } else { - camel_object_unref (CAMEL_OBJECT (raw)); - } - camel_mime_parser_filter_remove (mp, saveid); - saveid = -1; - raw = NULL; - } -#endif /* SAVE_RAW_MIME_STREAM_FOR_SECURE_MIME_SIGNATURES */ - camel_multipart_add_part ((CamelMultipart *)content, (CamelMimePart *)bodypart); camel_object_unref ((CamelObject *)bodypart); } @@ -395,4 +381,13 @@ camel_mime_part_construct_content_from_parser (CamelMimePart *dw, CamelMimeParse camel_medium_set_content_object ((CamelMedium *)dw, content); camel_object_unref ((CamelObject *)content); } + +#ifdef SAVE_RAW_MIME_STREAM_FOR_SECURE_MIME_SIGNATURES + if (!CAMEL_IS_MULTIPART (content)) { + /* set the raw mime stream on this leaf part in case our parent is a multipart/signed */ + camel_mime_parser_filter_remove (mp, saveid); + camel_stream_reset (raw); + dw->stream = raw; + } +#endif /* SAVE_RAW_MIME_STREAM_FOR_SECURE_MIME_SIGNATURES */ } -- cgit v1.2.3