From 46d07e9e465e336a5c39d8c27c846cb380fbc6fb Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Mon, 2 Oct 2000 18:33:18 +0000 Subject: If the body of the message has 8-bit chars, set the 2000-10-02 Jeffrey Stedfast * 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 --- composer/ChangeLog | 6 ++++++ composer/e-msg-composer.c | 43 +++++++++++++++++++++++++++---------------- 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 + + * 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 * 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; } -- cgit v1.2.3