aboutsummaryrefslogtreecommitdiffstats
path: root/composer
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@helixcode.com>2000-10-03 02:33:18 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2000-10-03 02:33:18 +0800
commit46d07e9e465e336a5c39d8c27c846cb380fbc6fb (patch)
tree1366dc664343c8a50bc52a77d1ac87d78636bf5a /composer
parent0212cbae5fbe76635365cfff575fd5f2f38b3e35 (diff)
downloadgsoc2013-evolution-46d07e9e465e336a5c39d8c27c846cb380fbc6fb.tar
gsoc2013-evolution-46d07e9e465e336a5c39d8c27c846cb380fbc6fb.tar.gz
gsoc2013-evolution-46d07e9e465e336a5c39d8c27c846cb380fbc6fb.tar.bz2
gsoc2013-evolution-46d07e9e465e336a5c39d8c27c846cb380fbc6fb.tar.lz
gsoc2013-evolution-46d07e9e465e336a5c39d8c27c846cb380fbc6fb.tar.xz
gsoc2013-evolution-46d07e9e465e336a5c39d8c27c846cb380fbc6fb.tar.zst
gsoc2013-evolution-46d07e9e465e336a5c39d8c27c846cb380fbc6fb.zip
If the body of the message has 8-bit chars, set the
2000-10-02 Jeffrey Stedfast <fejj@helixcode.com> * e-msg-composer.c (build_message): If the body of the message has 8-bit chars, set the Content-Transfer-Encoding type to the best encoding. svn path=/trunk/; revision=5662
Diffstat (limited to 'composer')
-rw-r--r--composer/ChangeLog6
-rw-r--r--composer/e-msg-composer.c43
2 files changed, 33 insertions, 16 deletions
diff --git a/composer/ChangeLog b/composer/ChangeLog
index 670a102f2b..6791f3d7b0 100644
--- a/composer/ChangeLog
+++ b/composer/ChangeLog
@@ -1,3 +1,9 @@
+2000-10-02 Jeffrey Stedfast <fejj@helixcode.com>
+
+ * e-msg-composer.c (build_message): If the body of the message has
+ 8-bit chars, set the Content-Transfer-Encoding type to the best
+ encoding.
+
2000-10-02 Dan Winship <danw@helixcode.com>
* e-icon-list.c: fix #include of gnome-canvas-pixbuf.h
diff --git a/composer/e-msg-composer.c b/composer/e-msg-composer.c
index 5f932141b2..c9edee6907 100644
--- a/composer/e-msg-composer.c
+++ b/composer/e-msg-composer.c
@@ -187,17 +187,36 @@ typedef enum {
} MsgFormat;
static gboolean
-is_8bit (guchar *text)
+is_8bit (const guchar *text)
{
guchar *c;
- for (c = text; *c; c++)
+ for (c = (guchar *) text; *c; c++)
if (*c > (guchar) 127)
return TRUE;
return FALSE;
}
+static int
+best_encoding (const guchar *text)
+{
+ guchar *ch;
+ int count = 0;
+ int total;
+
+ for (ch = (guchar *) text; *ch; ch++)
+ if (*ch > (guchar) 127)
+ count++;
+
+ total = (int) (ch - text);
+
+ if ((float) count <= total * 0.17)
+ return CAMEL_MIME_PART_ENCODING_QUOTEDPRINTABLE;
+ else
+ return CAMEL_MIME_PART_ENCODING_BASE64;
+}
+
/* This functions builds a CamelMimeMessage for the message that the user has
composed in `composer'. */
static CamelMimeMessage *
@@ -247,8 +266,8 @@ build_message (EMsgComposer *composer)
}
plain = get_text (composer->persist_stream_interface, "text/plain");
- e8bit = is_8bit (plain);
fmt = format_text (plain);
+ e8bit = is_8bit (fmt);
g_free (plain);
if (type != MSG_FORMAT_PLAIN)
@@ -263,7 +282,7 @@ build_message (EMsgComposer *composer)
part = camel_mime_part_new ();
camel_mime_part_set_content (part, fmt, strlen (fmt), "text/plain");
if (e8bit)
- camel_mime_part_set_encoding (part, CAMEL_MIME_PART_ENCODING_8BIT);
+ camel_mime_part_set_encoding (part, best_encoding (fmt));
g_free (fmt);
camel_multipart_add_part (body, part);
@@ -292,7 +311,7 @@ build_message (EMsgComposer *composer)
case MSG_FORMAT_PLAIN:
camel_mime_part_set_content (part, fmt, strlen (fmt), "text/plain");
if (e8bit)
- camel_mime_part_set_encoding (part, CAMEL_MIME_PART_ENCODING_8BIT);
+ camel_mime_part_set_encoding (part, best_encoding (fmt));
g_free (fmt);
break;
}
@@ -304,23 +323,15 @@ build_message (EMsgComposer *composer)
camel_medium_set_content_object (CAMEL_MEDIUM (new), CAMEL_DATA_WRAPPER (multipart));
camel_object_unref (CAMEL_OBJECT (multipart));
} else {
- CamelDataWrapper *cdw;
- CamelStream *stream;
switch (type) {
case MSG_FORMAT_ALTERNATIVE:
camel_medium_set_content_object (CAMEL_MEDIUM (new), CAMEL_DATA_WRAPPER (body));
camel_object_unref (CAMEL_OBJECT (body));
break;
case MSG_FORMAT_PLAIN:
- stream = camel_stream_mem_new_with_buffer (fmt, strlen (fmt));
- cdw = camel_data_wrapper_new ();
- camel_data_wrapper_construct_from_stream (cdw, stream);
- camel_object_unref (CAMEL_OBJECT (stream));
-
- camel_data_wrapper_set_mime_type (cdw, "text/plain");
-
- camel_medium_set_content_object (CAMEL_MEDIUM (new), CAMEL_DATA_WRAPPER (cdw));
- camel_object_unref (CAMEL_OBJECT (cdw));
+ camel_mime_part_set_content (CAMEL_MIME_PART (new), fmt, strlen (fmt), "text/plain");
+ if (e8bit)
+ camel_mime_part_set_encoding (CAMEL_MIME_PART (new), best_encoding (fmt));
g_free (fmt);
break;
}