aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@ximian.com>2003-06-11 23:59:30 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2003-06-11 23:59:30 +0800
commit2c194837766ea2c43963080f67968fcd21d87137 (patch)
tree0bca9d86abc052c890ae3d34f4065b06dcbe1666
parent59581dc2d31b2c7833115b35a4ec2fdc84a5cffb (diff)
downloadgsoc2013-evolution-2c194837766ea2c43963080f67968fcd21d87137.tar.gz
gsoc2013-evolution-2c194837766ea2c43963080f67968fcd21d87137.tar.zst
gsoc2013-evolution-2c194837766ea2c43963080f67968fcd21d87137.zip
Add the CAMEL_BESTENC_TEXT bit to enctype if the part is a text part.
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. svn path=/trunk/; revision=21409
-rw-r--r--camel/ChangeLog9
-rw-r--r--camel/camel-mime-filter-bestenc.c18
-rw-r--r--camel/camel-mime-filter-bestenc.h5
-rw-r--r--camel/camel-mime-message.c1
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;
}