static gint multipart_signed_construct_from_parser (CamelMultipart *multipart, CamelMimeParser *mp) { gint err; CamelContentType *content_type; CamelMultipartSigned *mps = (CamelMultipartSigned *) multipart; CamelDataWrapper *data_wrapper; GByteArray *byte_array; gchar *buf; gsize len; /* we *must not* be in multipart state, otherwise the mime parser will * parse the headers which is a no no @#$@# stupid multipart/signed spec */ g_assert (camel_mime_parser_state (mp) == CAMEL_MIME_PARSER_STATE_HEADER); /* All we do is copy it to a memstream */ content_type = camel_mime_parser_content_type (mp); camel_multipart_set_boundary (multipart, camel_content_type_param (content_type, "boundary")); data_wrapper = CAMEL_DATA_WRAPPER (multipart); byte_array = camel_data_wrapper_get_byte_array (data_wrapper); /* Wipe any previous contents from the byte array. */ g_byte_array_set_size (byte_array, 0); while (camel_mime_parser_step (mp, &buf, &len) != CAMEL_MIME_PARSER_STATE_BODY_END) g_byte_array_append (byte_array, (guint8 *) buf, len); mps->start1 = -1; if (mps->content) { g_object_unref (mps->content); mps->content = NULL; } if (mps->contentraw) { g_object_unref (mps->contentraw); mps->contentraw = NULL; } if (mps->signature) { g_object_unref (mps->signature); mps->signature = NULL; } err = camel_mime_parser_errno (mp); if (err != 0) { errno = err; return -1; } else return 0; }
static gint multipart_construct_from_parser (CamelMultipart *multipart, CamelMimeParser *mp) { gint err; CamelContentType *content_type; CamelMimePart *bodypart; gchar *buf; gsize len; g_assert (camel_mime_parser_state (mp) == CAMEL_MIME_PARSER_STATE_MULTIPART); /* FIXME: we should use a came-mime-mutlipart, not jsut a camel-multipart, but who cares */ d(printf("Creating multi-part\n")); content_type = camel_mime_parser_content_type (mp); camel_multipart_set_boundary (multipart, camel_content_type_param(content_type, "boundary")); while (camel_mime_parser_step (mp, &buf, &len) != CAMEL_MIME_PARSER_STATE_MULTIPART_END) { camel_mime_parser_unstep (mp); bodypart = camel_mime_part_new (); camel_mime_part_construct_from_parser_sync ( bodypart, mp, NULL, NULL); camel_multipart_add_part (multipart, bodypart); g_object_unref (bodypart); } /* these are only return valid data in the MULTIPART_END state */ camel_multipart_set_preface (multipart, camel_mime_parser_preface (mp)); camel_multipart_set_postface (multipart, camel_mime_parser_postface (mp)); err = camel_mime_parser_errno (mp); if (err != 0) { errno = err; return -1; } else return 0; }