
* tests/message/test4.c: New test suite for the mime parser (which is where the below 2 fixes were noticed). * camel-mime-parser.c (folder_boundary_check): Calculate 'len' by subtracting the boundary start from inend rather than 'atleast'. (folder_scan_content): Calculate 'inend' differently depending on the EOF state. 2003-08-08 Jeffrey Stedfast <fejj@ximian.com> * camel-mime-filter-tohtml.c (html_convert): Rather than checking *inptr == '\n', check inptr >= inend - this gets rid of an Invalid Read report from valgrind. * camel-mime-part.c (write_to_stream): Don't necessarily re-encode just because the encodings differ. Need to look into making it so that message/rfc822 and multipart parts ignore the Content-Transfer-Encoding header and just keep their 'encoding' bits set to DEFAULT. 2003-08-05 Jeffrey Stedfast <fejj@ximian.com> * providers/imap/camel-imap-folder.c (get_content): Updated. * camel-mime-message.c (camel_mime_message_init): Don't override the mime_type here. (process_header): Updated to use CamelDataWrapper's mime_type field. (find_best_encoding): Same. (best_encoding): Here too. * camel-digest-folder.c (camel_digest_folder_new): Updated for CamelMimePart::content_type change. * camel-mime-part.c (camel_mime_part_init): Override our parent class's default mime_type. (camel_mime_part_finalize): Don't need to unref the content_type anymore. (process_header): Updated to use CamelDataWrapper's mime_type field. (camel_mime_part_set_filename): Same. (camel_mime_part_get_filename): Same. (camel_mime_part_get_content_type): Same. (set_content_object): Here too. (write_to_stream): Updated. (construct_from_parser): Updated. * camel-mime-part.h: Remove the content_type field. 2003-07-31 Jeffrey Stedfast <fejj@ximian.com> * tests/lib/messages.c (test_message_compare_content): If the chunks differ, perform a hexdump on the data being compared so that we may analyse it easier. * camel-multipart-signed.c (write_to_stream): Return ssize_t. * camel-mime-utils.h: Added the CamelMimePartEncodingType enum here. * camel-mime-part.h: Removed the CamelMimePartEncodingType enum from here. * camel-mime-part.c (write_to_stream): Updated to return ssize_t. Also minor changes to only re-encode the content stream if the charset or encoding changed (this way we write it out in the original raw form if nothing changed). * camel-mime-part-utils.c (simple_data_wrapper_construct_from_parser): Drastically simplify. We no longer scan html content to try and find the charset, nor do we care about converting the content to UTF-8 and handling broken windows charsets. * camel-mime-message.c (find_best_encoding): Use decode_to_stream() here. Also updated to not assume the content charset is UTF-8 since it is very likely not the case anymore since data-wrappers no longer are converted to UTF-8 at parse time. * camel-folder-summary.c (summary_build_content_info_message): Use decode_to_stream instead here too. * camel-folder-search.c (match_words_1message): Use decode_to_stream instead of write_to_stream so we can search the contents. * camel-data-wrapper.c (camel_data_wrapper_init): Set the default encoding to DEFAULT. (write_to_stream): Updated to return ssize_t (camel_data_wrapper_decode_to_stream): New virtual function to decode a data wrapper to a stream (results in nearly identical behaviour to the old write_to_stream method). (decode_to_stream): Default implementation of above virtual method. Decodes base64/qp/etc streams. * camel-data-wrapper.h: Removed the rawtext bit and added an encoding member. svn path=/trunk/; revision=22171
138 lines
4.6 KiB
C
138 lines
4.6 KiB
C
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; fill-column: 160 -*- */
|
|
/* camel-mime-part-utils : Utility for mime parsing and so on
|
|
*
|
|
* Authors: Bertrand Guiheneuf <bertrand@helixcode.com>
|
|
* Michael Zucchi <notzed@ximian.com>
|
|
* Jeffrey Stedfast <fejj@ximian.com>
|
|
*
|
|
* Copyright 1999-2003 Ximian, Inc. (www.ximian.com)
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of version 2 of the GNU General Public
|
|
* License as published by the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
* USA
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
#include <config.h>
|
|
#endif
|
|
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#include <ctype.h>
|
|
#include <errno.h>
|
|
|
|
#include <gal/util/e-iconv.h>
|
|
|
|
#include "camel-charset-map.h"
|
|
#include "camel-mime-part-utils.h"
|
|
#include "camel-mime-message.h"
|
|
#include "camel-multipart.h"
|
|
#include "camel-multipart-signed.h"
|
|
#include "camel-multipart-encrypted.h"
|
|
#include "camel-seekable-substream.h"
|
|
#include "camel-stream-fs.h"
|
|
#include "camel-stream-filter.h"
|
|
#include "camel-stream-mem.h"
|
|
#include "camel-mime-filter-basic.h"
|
|
#include "camel-mime-filter-charset.h"
|
|
#include "camel-mime-filter-crlf.h"
|
|
#include "camel-mime-filter-save.h"
|
|
#include "camel-html-parser.h"
|
|
|
|
#define d(x) /*(printf("%s(%d): ", __FILE__, __LINE__),(x))
|
|
#include <stdio.h>*/
|
|
|
|
/* simple data wrapper */
|
|
static void
|
|
simple_data_wrapper_construct_from_parser (CamelDataWrapper *dw, CamelMimeParser *mp)
|
|
{
|
|
char *encoding, *buf;
|
|
GByteArray *buffer;
|
|
CamelStream *mem;
|
|
size_t len;
|
|
|
|
d(printf ("simple_data_wrapper_construct_from_parser()\n"));
|
|
|
|
/* first, work out conversion, if any, required, we dont care about what we dont know about */
|
|
encoding = header_content_encoding_decode (camel_mime_parser_header (mp, "Content-Transfer-Encoding", NULL));
|
|
|
|
/* read in the entire content */
|
|
buffer = g_byte_array_new ();
|
|
while (camel_mime_parser_step (mp, &buf, &len) != HSCAN_BODY_END) {
|
|
d(printf("appending o/p data: %d: %.*s\n", len, len, buf));
|
|
g_byte_array_append (buffer, buf, len);
|
|
}
|
|
|
|
d(printf("message part kept in memory!\n"));
|
|
|
|
mem = camel_stream_mem_new_with_byte_array (buffer);
|
|
camel_data_wrapper_construct_from_stream (dw, mem);
|
|
camel_object_unref (mem);
|
|
|
|
if (encoding) {
|
|
dw->encoding = camel_mime_part_encoding_from_string (encoding);
|
|
g_free (encoding);
|
|
}
|
|
}
|
|
|
|
/* This replaces the data wrapper repository ... and/or could be replaced by it? */
|
|
void
|
|
camel_mime_part_construct_content_from_parser (CamelMimePart *dw, CamelMimeParser *mp)
|
|
{
|
|
CamelDataWrapper *content = NULL;
|
|
CamelContentType *ct;
|
|
|
|
ct = camel_mime_parser_content_type (mp);
|
|
|
|
switch (camel_mime_parser_state (mp)) {
|
|
case HSCAN_HEADER:
|
|
d(printf("Creating body part\n"));
|
|
/* multipart/signed is some fucked up type that we must treat as binary data, fun huh, idiots. */
|
|
if (header_content_type_is (ct, "multipart", "signed")) {
|
|
content = (CamelDataWrapper *) camel_multipart_signed_new ();
|
|
camel_multipart_construct_from_parser ((CamelMultipart *) content, mp);
|
|
} else {
|
|
content = camel_data_wrapper_new ();
|
|
simple_data_wrapper_construct_from_parser (content, mp);
|
|
}
|
|
break;
|
|
case HSCAN_MESSAGE:
|
|
d(printf("Creating message part\n"));
|
|
content = (CamelDataWrapper *) camel_mime_message_new ();
|
|
camel_mime_part_construct_from_parser ((CamelMimePart *)content, mp);
|
|
break;
|
|
case HSCAN_MULTIPART:
|
|
d(printf("Creating multi-part\n"));
|
|
if (header_content_type_is (ct, "multipart", "encrypted"))
|
|
content = (CamelDataWrapper *) camel_multipart_encrypted_new ();
|
|
else if (header_content_type_is (ct, "multipart", "signed"))
|
|
content = (CamelDataWrapper *) camel_multipart_signed_new ();
|
|
else
|
|
content = (CamelDataWrapper *) camel_multipart_new ();
|
|
|
|
camel_multipart_construct_from_parser((CamelMultipart *)content, mp);
|
|
d(printf("Created multi-part\n"));
|
|
break;
|
|
default:
|
|
g_warning("Invalid state encountered???: %d", camel_mime_parser_state (mp));
|
|
}
|
|
|
|
if (content) {
|
|
/* would you believe you have to set this BEFORE you set the content object??? oh my god !!!! */
|
|
camel_data_wrapper_set_mime_type_field (content, camel_mime_part_get_content_type (dw));
|
|
camel_medium_set_content_object ((CamelMedium *)dw, content);
|
|
camel_object_unref (content);
|
|
}
|
|
}
|