From d6b8654b225b160faf6cf6002186d1c9d2839c3f Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Mon, 6 Nov 2000 20:52:22 +0000 Subject: set the content type on the plain part of outgoing messages. 2000-11-06 Larry Ewing * e-msg-composer.c (build_message): set the content type on the plain part of outgoing messages. (best_content): a helper function to get the best content type for the attachment. This should probably use the helper functions in the future. svn path=/trunk/; revision=6423 --- composer/e-msg-composer.c | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) (limited to 'composer/e-msg-composer.c') diff --git a/composer/e-msg-composer.c b/composer/e-msg-composer.c index 6fd10d578c..456b8a54f9 100644 --- a/composer/e-msg-composer.c +++ b/composer/e-msg-composer.c @@ -43,6 +43,7 @@ #include #include "camel/camel.h" +#include "camel-charset-map.h" #include "mail/mail.h" #include "mail/mail-tools.h" @@ -150,6 +151,21 @@ best_encoding (const guchar *text) return CAMEL_MIME_PART_ENCODING_BASE64; } +static char * +best_content (gchar *plain) +{ + char *result; + const char *best; + + if ((best = camel_charset_best (plain, strlen (plain)))) { + result = g_strdup_printf ("text/plain ; charset=%s", best); + } else { + result = g_strdup ("text/plain"); + } + + return result; +} + /* This functions builds a CamelMimeMessage for the message that the user has composed in `composer'. */ static CamelMimeMessage * @@ -164,8 +180,10 @@ build_message (EMsgComposer *composer) gchar *from = NULL; gboolean e8bit; char *html = NULL, *plain = NULL; + char *content_type = NULL; int i; + if (composer->persist_stream_interface == CORBA_OBJECT_NIL) return NULL; @@ -205,13 +223,15 @@ build_message (EMsgComposer *composer) return NULL; e8bit = is_8bit (plain); - + content_type = best_content (plain); + if (type != MSG_FORMAT_PLAIN) { html = get_text (composer->persist_stream_interface, "text/html"); /* the component has probably died */ if (html == NULL) { g_free (plain); + g_free (content_type); return NULL; } } @@ -223,11 +243,14 @@ build_message (EMsgComposer *composer) camel_multipart_set_boundary (body, NULL); part = camel_mime_part_new (); - camel_mime_part_set_content (part, plain, strlen (plain), "text/plain"); + + camel_mime_part_set_content (part, plain, strlen (plain), content_type); + if (e8bit) - camel_mime_part_set_encoding (part, best_encoding (plain)); - + camel_mime_part_set_encoding (part, best_encoding (plain)); + g_free (plain); + g_free (content_type); camel_multipart_add_part (body, part); camel_object_unref (CAMEL_OBJECT (part)); @@ -252,10 +275,13 @@ build_message (EMsgComposer *composer) camel_object_unref (CAMEL_OBJECT (body)); break; case MSG_FORMAT_PLAIN: - camel_mime_part_set_content (part, plain, strlen (plain), "text/plain"); + camel_mime_part_set_content (part, plain, strlen (plain), best_content (plain)); + if (e8bit) camel_mime_part_set_encoding (part, best_encoding (plain)); + g_free (plain); + g_free (content_type); break; } camel_multipart_add_part (multipart, part); @@ -271,11 +297,15 @@ build_message (EMsgComposer *composer) camel_medium_set_content_object (CAMEL_MEDIUM (new), CAMEL_DATA_WRAPPER (body)); camel_object_unref (CAMEL_OBJECT (body)); break; + case MSG_FORMAT_PLAIN: - camel_mime_part_set_content (CAMEL_MIME_PART (new), plain, strlen (plain), "text/plain"); + camel_mime_part_set_content (CAMEL_MIME_PART (new), plain, strlen (plain), best_content (plain)); + if (e8bit) camel_mime_part_set_encoding (CAMEL_MIME_PART (new), best_encoding (plain)); + g_free (plain); + g_free (content_type); break; } } -- cgit v1.2.3