diff options
-rw-r--r-- | camel/ChangeLog | 9 | ||||
-rw-r--r-- | camel/camel-mime-filter-bestenc.c | 18 | ||||
-rw-r--r-- | camel/camel-mime-filter-bestenc.h | 5 | ||||
-rw-r--r-- | camel/camel-mime-message.c | 1 |
4 files changed, 26 insertions, 7 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog index e69de29bb2..2668c971bb 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -0,0 +1,9 @@ +2003-06-09 Jeffrey Stedfast <fejj@ximian.com> + + * camel-mime-message.c (find_best_encoding): Add the + CAMEL_BESTENC_TEXT bit to enctype if the part is a text part. + + * camel-mime-filter-bestenc.c + (camel_mime_filter_bestenc_get_best_encoding): If we have any + nul-bytes or if the content is non-text and contains any 8bit + octets, we need to use base64. Fixes bug #44344. diff --git a/camel/camel-mime-filter-bestenc.c b/camel/camel-mime-filter-bestenc.c index 0de8abd04b..5fc0bb9985 100644 --- a/camel/camel-mime-filter-bestenc.c +++ b/camel/camel-mime-filter-bestenc.c @@ -23,6 +23,7 @@ #include <config.h> #endif +#include <stdio.h> #include <string.h> #include "camel-mime-filter-bestenc.h" @@ -210,7 +211,7 @@ camel_mime_filter_bestenc_new (unsigned int flags) /** * camel_mime_filter_bestenc_get_best_encoding: - * @f: + * @f: bestenc filter object * @required: maximum level of output encoding allowed. * * Return the best encoding, given specific constraints, that can be used to @@ -222,7 +223,11 @@ CamelMimePartEncodingType camel_mime_filter_bestenc_get_best_encoding(CamelMimeFilterBestenc *f, CamelBestencEncoding required) { CamelMimePartEncodingType bestenc; - + int istext; + + istext = (required & CAMEL_BESTENC_TEXT) ? 1 : 0; + required = required & ~CAMEL_BESTENC_TEXT; + #if 0 printf("count0 = %d, count8 = %d, total = %d\n", f->count0, f->count8, f->total); printf("maxline = %d, crlfnoorder = %s\n", f->maxline, f->crlfnoorder?"TRUE":"FALSE"); @@ -238,10 +243,10 @@ camel_mime_filter_bestenc_get_best_encoding(CamelMimeFilterBestenc *f, CamelBest /* if we need to encode, see how we do it */ if (required == CAMEL_BESTENC_BINARY) bestenc = CAMEL_MIME_PART_ENCODING_BINARY; - else if (f->count8 + f->count0 >= (f->total*17/100)) - bestenc = CAMEL_MIME_PART_ENCODING_BASE64; - else + else if (istext && (f->count0 == 0 && f->count8 < (f->total * 17 / 100))) bestenc = CAMEL_MIME_PART_ENCODING_QUOTEDPRINTABLE; + else + bestenc = CAMEL_MIME_PART_ENCODING_BASE64; /* if we have nocrlf order, or long lines, we need to encode always */ if (f->crlfnoorder || f->maxline >= 998) @@ -257,6 +262,7 @@ camel_mime_filter_bestenc_get_best_encoding(CamelMimeFilterBestenc *f, CamelBest return bestenc; case CAMEL_BESTENC_8BIT: case CAMEL_BESTENC_BINARY: + default: if (f->count0 == 0) return CAMEL_MIME_PART_ENCODING_8BIT; else @@ -268,7 +274,7 @@ camel_mime_filter_bestenc_get_best_encoding(CamelMimeFilterBestenc *f, CamelBest /** * camel_mime_filter_bestenc_get_best_charset: - * @f: + * @f: bestenc filter object * * Gets the best charset that can be used to contain this content. * diff --git a/camel/camel-mime-filter-bestenc.h b/camel/camel-mime-filter-bestenc.h index 3d2e79fa55..de4a82d502 100644 --- a/camel/camel-mime-filter-bestenc.h +++ b/camel/camel-mime-filter-bestenc.h @@ -52,6 +52,9 @@ enum _CamelBestencEncoding { CAMEL_BESTENC_7BIT, CAMEL_BESTENC_8BIT, CAMEL_BESTENC_BINARY, + + /* is the content stream to be treated as text? */ + CAMEL_BESTENC_TEXT = 1<<8, }; typedef enum _CamelBestencEncoding CamelBestencEncoding; @@ -70,7 +73,7 @@ struct _CamelMimeFilterBestenc { int startofline; /* are we at the start of a new line? */ int fromcount; - char fromsave[6]; /* save a few characters if we found an \nF near the end of the buffer */ + char fromsave[6]; /* save a few characters if we found an \n near the end of the buffer */ int hadfrom; /* did we encounter a "\nFrom " in the data? */ unsigned int countline; /* current count of characters on a given line */ diff --git a/camel/camel-mime-message.c b/camel/camel-mime-message.c index 7f14218286..dab789cfaf 100644 --- a/camel/camel-mime-message.c +++ b/camel/camel-mime-message.c @@ -702,6 +702,7 @@ find_best_encoding (CamelMimePart *part, CamelBestencRequired required, CamelBes istext = header_content_type_is (part->content_type, "text", "*"); if (istext) { flags = CAMEL_BESTENC_GET_CHARSET | CAMEL_BESTENC_GET_ENCODING; + enctype |= CAMEL_BESTENC_TEXT; } else { flags = CAMEL_BESTENC_GET_ENCODING; } |