aboutsummaryrefslogtreecommitdiffstats
path: root/composer/e-msg-composer-attachment-bar.c
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@ximian.com>2001-10-19 09:56:21 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2001-10-19 09:56:21 +0800
commitdfd09f4f17bc75a3d8d745e850f00bbee919d820 (patch)
tree85c1e4cd025abca81d10ec0acd943c9b76fe76a4 /composer/e-msg-composer-attachment-bar.c
parentdf5691bccf164913fe9b92aa03facbdfff1b9fa4 (diff)
downloadgsoc2013-evolution-dfd09f4f17bc75a3d8d745e850f00bbee919d820.tar
gsoc2013-evolution-dfd09f4f17bc75a3d8d745e850f00bbee919d820.tar.gz
gsoc2013-evolution-dfd09f4f17bc75a3d8d745e850f00bbee919d820.tar.bz2
gsoc2013-evolution-dfd09f4f17bc75a3d8d745e850f00bbee919d820.tar.lz
gsoc2013-evolution-dfd09f4f17bc75a3d8d745e850f00bbee919d820.tar.xz
gsoc2013-evolution-dfd09f4f17bc75a3d8d745e850f00bbee919d820.tar.zst
gsoc2013-evolution-dfd09f4f17bc75a3d8d745e850f00bbee919d820.zip
Don't use a g_return_val_if_fail after iconv_open, this is a valid error
2001-10-18 Jeffrey Stedfast <fejj@ximian.com> * e-msg-composer.c (best_encoding): Don't use a g_return_val_if_fail after iconv_open, this is a valid error condition and so should use check it for real. * e-msg-composer-attachment-bar.c (attach_to_multipart): Correctly set the charset parameter and use camel's bestenc filter to determine which content transfer encoding to use. svn path=/trunk/; revision=13784
Diffstat (limited to 'composer/e-msg-composer-attachment-bar.c')
-rw-r--r--composer/e-msg-composer-attachment-bar.c78
1 files changed, 28 insertions, 50 deletions
diff --git a/composer/e-msg-composer-attachment-bar.c b/composer/e-msg-composer-attachment-bar.c
index 14b0b39588..6619a59597 100644
--- a/composer/e-msg-composer-attachment-bar.c
+++ b/composer/e-msg-composer-attachment-bar.c
@@ -50,7 +50,9 @@
#include "camel/camel-data-wrapper.h"
#include "camel/camel-stream-fs.h"
-#include "camel/camel-stream-mem.h"
+#include "camel/camel-stream-null.h"
+#include "camel/camel-stream-filter.h"
+#include "camel/camel-mime-filter-bestenc.h"
#include "camel/camel-mime-part.h"
@@ -714,39 +716,6 @@ e_msg_composer_attachment_bar_new (GtkAdjustment *adj)
return GTK_WIDGET (new);
}
-/* FIXME: is_8bit() and best_encoding() should really be shared
- between e-msg-composer.c and this file. */
-static gboolean
-is_8bit (const guchar *text)
-{
- guchar *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;
-}
-
static void
attach_to_multipart (CamelMultipart *multipart,
EMsgComposerAttachment *attachment,
@@ -758,23 +727,32 @@ attach_to_multipart (CamelMultipart *multipart,
if (!header_content_type_is (content_type, "multipart", "*")) {
if (header_content_type_is (content_type, "text", "*")) {
+ CamelMimePartEncodingType encoding;
+ CamelStreamFilter *filtered_stream;
+ CamelMimeFilterBestenc *bestenc;
CamelStream *stream;
- GByteArray *array;
- guchar *text;
+ char *type;
- array = g_byte_array_new ();
- stream = camel_stream_mem_new_with_byte_array (array);
- camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (attachment->body), stream);
- g_byte_array_append (array, "", 1);
- text = array->data;
+ stream = camel_stream_null_new ();
+ filtered_stream = camel_stream_filter_new_with_stream (stream);
+ bestenc = camel_mime_filter_bestenc_new (CAMEL_BESTENC_GET_ENCODING);
+ camel_stream_filter_add (filtered_stream, CAMEL_MIME_FILTER (bestenc));
+ camel_object_unref (CAMEL_OBJECT (stream));
- if (is_8bit (text)) {
- camel_mime_part_set_encoding (attachment->body, best_encoding (text));
- header_content_type_set_param (content_type, "charset", default_charset);
- } else
- camel_mime_part_set_encoding (attachment->body, CAMEL_MIME_PART_ENCODING_7BIT);
+ camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (attachment->body),
+ CAMEL_STREAM (filtered_stream));
- camel_object_unref (CAMEL_OBJECT (stream));
+ encoding = camel_mime_filter_bestenc_get_best_encoding (bestenc, CAMEL_BESTENC_8BIT);
+ camel_mime_part_set_encoding (attachment->body, encoding);
+
+ /* looks kinda nasty, but this is how ya have to do it */
+ header_content_type_set_param (content_type, "charset", default_charset);
+ type = header_content_type_format (content_type);
+ camel_mime_part_set_content_type (attachment->body, type);
+ g_free (type);
+
+ camel_object_unref (CAMEL_OBJECT (bestenc));
+ camel_object_unref (CAMEL_OBJECT (filtered_stream));
} else if (!header_content_type_is (content_type, "message", "*")) {
camel_mime_part_set_encoding (attachment->body,
CAMEL_MIME_PART_ENCODING_BASE64);
@@ -796,12 +774,12 @@ e_msg_composer_attachment_bar_to_multipart (EMsgComposerAttachmentBar *bar,
g_return_if_fail (E_IS_MSG_COMPOSER_ATTACHMENT_BAR (bar));
g_return_if_fail (multipart != NULL);
g_return_if_fail (CAMEL_IS_MULTIPART (multipart));
-
+
priv = bar->priv;
-
+
for (p = priv->attachments; p != NULL; p = p->next) {
EMsgComposerAttachment *attachment;
-
+
attachment = E_MSG_COMPOSER_ATTACHMENT (p->data);
attach_to_multipart (multipart, attachment, default_charset);
}