aboutsummaryrefslogtreecommitdiffstats
path: root/camel/camel-mime-message.c
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@ximian.com>2003-08-12 01:57:45 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2003-08-12 01:57:45 +0800
commitb328a21e7c026aaa9cdd5e332ed7e39e0003d8eb (patch)
tree2c0f3caac1a793197a951958fa7f07cdbf61ac07 /camel/camel-mime-message.c
parent7b1013be730b11384d0e0af340758bdef3f00330 (diff)
downloadgsoc2013-evolution-b328a21e7c026aaa9cdd5e332ed7e39e0003d8eb.tar
gsoc2013-evolution-b328a21e7c026aaa9cdd5e332ed7e39e0003d8eb.tar.gz
gsoc2013-evolution-b328a21e7c026aaa9cdd5e332ed7e39e0003d8eb.tar.bz2
gsoc2013-evolution-b328a21e7c026aaa9cdd5e332ed7e39e0003d8eb.tar.lz
gsoc2013-evolution-b328a21e7c026aaa9cdd5e332ed7e39e0003d8eb.tar.xz
gsoc2013-evolution-b328a21e7c026aaa9cdd5e332ed7e39e0003d8eb.tar.zst
gsoc2013-evolution-b328a21e7c026aaa9cdd5e332ed7e39e0003d8eb.zip
New test suite for the mime parser (which is where the below 2 fixes were
* 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
Diffstat (limited to 'camel/camel-mime-message.c')
-rw-r--r--camel/camel-mime-message.c74
1 files changed, 34 insertions, 40 deletions
diff --git a/camel/camel-mime-message.c b/camel/camel-mime-message.c
index f9e9373a8f..ee5b7cac0e 100644
--- a/camel/camel-mime-message.c
+++ b/camel/camel-mime-message.c
@@ -122,8 +122,6 @@ camel_mime_message_init (gpointer object, gpointer klass)
CamelMimeMessage *mime_message = (CamelMimeMessage *)object;
int i;
- camel_data_wrapper_set_mime_type (CAMEL_DATA_WRAPPER (object), "message/rfc822");
-
mime_message->recipients = g_hash_table_new (camel_strcase_hash, camel_strcase_equal);
for (i=0;recipient_names[i];i++) {
g_hash_table_insert(mime_message->recipients, recipient_names[i], camel_internet_address_new());
@@ -540,8 +538,8 @@ process_header (CamelMedium *medium, const char *header_name, const char *header
break;
case HEADER_SUBJECT:
g_free (message->subject);
- if (((CamelMimePart *) message)->content_type) {
- charset = header_content_type_param (((CamelMimePart *) message)->content_type, "charset");
+ if (((CamelDataWrapper *) message)->mime_type) {
+ charset = header_content_type_param (((CamelDataWrapper *) message)->mime_type, "charset");
charset = e_iconv_charset_name (charset);
} else
charset = NULL;
@@ -673,17 +671,17 @@ camel_mime_message_has_8bit_parts (CamelMimeMessage *msg)
static CamelMimePartEncodingType
find_best_encoding (CamelMimePart *part, CamelBestencRequired required, CamelBestencEncoding enctype, char **charsetp)
{
- const char *charsetin = NULL;
- char *charset = NULL;
- CamelStream *null;
- CamelStreamFilter *filter;
CamelMimeFilterCharset *charenc = NULL;
+ CamelMimePartEncodingType encoding;
CamelMimeFilterBestenc *bestenc;
- int idb, idc = -1;
- gboolean istext;
unsigned int flags, callerflags;
- CamelMimePartEncodingType encoding;
CamelDataWrapper *content;
+ CamelStreamFilter *filter;
+ const char *charsetin = NULL;
+ char *charset = NULL;
+ CamelStream *null;
+ int idb, idc = -1;
+ gboolean istext;
/* we use all these weird stream things so we can do it with streams, and
not have to read the whole lot into memory - although i have a feeling
@@ -699,7 +697,7 @@ find_best_encoding (CamelMimePart *part, CamelBestencRequired required, CamelBes
return CAMEL_MIME_PART_ENCODING_DEFAULT;
}
- istext = header_content_type_is (part->content_type, "text", "*");
+ istext = header_content_type_is (((CamelDataWrapper *) part)->mime_type, "text", "*");
if (istext) {
flags = CAMEL_BESTENC_GET_CHARSET | CAMEL_BESTENC_GET_ENCODING;
enctype |= CAMEL_BESTENC_TEXT;
@@ -717,12 +715,10 @@ find_best_encoding (CamelMimePart *part, CamelBestencRequired required, CamelBes
null = (CamelStream *)camel_stream_null_new ();
filter = camel_stream_filter_new_with_stream (null);
- /* if we're not looking for the best charset, then use the one we have */
- if (istext && (required & CAMEL_BESTENC_GET_CHARSET) == 0
- && (charsetin = header_content_type_param (part->content_type, "charset"))) {
- /* if libunicode doesn't support it, we dont really have utf8 anyway, so
- we dont need a converter */
- charenc = camel_mime_filter_charset_new_convert ("UTF-8", charsetin);
+ /* if we're looking for the best charset, then we need to convert to UTF-8 */
+ if (istext && (required & CAMEL_BESTENC_GET_CHARSET) != 0
+ && (charsetin = header_content_type_param (content->mime_type, "charset"))) {
+ charenc = camel_mime_filter_charset_new_convert (charsetin, "UTF-8");
if (charenc != NULL)
idc = camel_stream_filter_add (filter, (CamelMimeFilter *)charenc);
charsetin = NULL;
@@ -731,35 +727,33 @@ find_best_encoding (CamelMimePart *part, CamelBestencRequired required, CamelBes
bestenc = camel_mime_filter_bestenc_new (flags);
idb = camel_stream_filter_add (filter, (CamelMimeFilter *)bestenc);
d(printf("writing to checking stream\n"));
- camel_data_wrapper_write_to_stream (content, (CamelStream *)filter);
+ camel_data_wrapper_decode_to_stream (content, (CamelStream *)filter);
camel_stream_filter_remove (filter, idb);
if (idc != -1) {
camel_stream_filter_remove (filter, idc);
- camel_object_unref ((CamelObject *)charenc);
+ camel_object_unref (charenc);
charenc = NULL;
}
- if (istext)
+ if (istext && (required & CAMEL_BESTENC_GET_CHARSET) != 0) {
charsetin = camel_mime_filter_bestenc_get_best_charset (bestenc);
-
- d(printf("charsetin = %s\n", charsetin ? charsetin : "(null)"));
-
- /* if we have US-ASCII, or we're not doing text, we dont need to bother with the rest */
- if (charsetin != NULL && (required & CAMEL_BESTENC_GET_CHARSET) != 0) {
+ d(printf("best charset = %s\n", charsetin ? charsetin : "(null)"));
charset = g_strdup (charsetin);
+ charsetin = header_content_type_param (content->mime_type, "charset");
+ } else {
+ charset = NULL;
+ }
+
+ /* if we have US-ASCII, or we're not doing text, we dont need to bother with the rest */
+ if (istext && charsetin && charset && (required & CAMEL_BESTENC_GET_CHARSET) != 0) {
d(printf("have charset, trying conversion/etc\n"));
- /* now the 'bestenc' can has told us what the best encoding is, we can use that to create
+ /* now that 'bestenc' has told us what the best encoding is, we can use that to create
a charset conversion filter as well, and then re-add the bestenc to filter the
result to find the best encoding to use as well */
- charenc = camel_mime_filter_charset_new_convert ("UTF-8", charset);
-
- /* eek, libunicode doesn't undertand this charset anyway, then the 'utf8' we
- thought we had is really the native format, in which case, we just treat
- it as binary data (and take the result we have so far) */
-
+ charenc = camel_mime_filter_charset_new_convert (charsetin, charset);
if (charenc != NULL) {
/* otherwise, try another pass, converting to the real charset */
@@ -773,15 +767,15 @@ find_best_encoding (CamelMimePart *part, CamelBestencRequired required, CamelBes
/* and write it to the new stream */
camel_data_wrapper_write_to_stream (content, (CamelStream *)filter);
- camel_object_unref ((CamelObject *)charenc);
+ camel_object_unref (charenc);
}
}
encoding = camel_mime_filter_bestenc_get_best_encoding (bestenc, enctype);
- camel_object_unref ((CamelObject *)filter);
- camel_object_unref ((CamelObject *)bestenc);
- camel_object_unref ((CamelObject *)null);
+ camel_object_unref (filter);
+ camel_object_unref (bestenc);
+ camel_object_unref (null);
d(printf("done, best encoding = %d\n", encoding));
@@ -818,13 +812,13 @@ best_encoding (CamelMimeMessage *msg, CamelMimePart *part, void *datap)
camel_mime_part_set_encoding (part, encoding);
if ((data->required & CAMEL_BESTENC_GET_CHARSET) != 0) {
- if (header_content_type_is (part->content_type, "text", "*")) {
+ if (header_content_type_is (((CamelDataWrapper *) part)->mime_type, "text", "*")) {
char *newct;
/* FIXME: ick, the part content_type interface needs fixing bigtime */
- header_content_type_set_param (part->content_type, "charset",
+ header_content_type_set_param (((CamelDataWrapper *) part)->mime_type, "charset",
charset ? charset : "us-ascii");
- newct = header_content_type_format (part->content_type);
+ newct = header_content_type_format (((CamelDataWrapper *) part)->mime_type);
if (newct) {
d(printf("Setting content-type to %s\n", newct));