aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorGravatar Michal Sojka <sojkam1@fel.cvut.cz>2012-02-24 08:36:22 +0100
committerGravatar David Bremner <bremner@debian.org>2012-02-29 07:41:39 -0400
commit40edc971a82e236704216058591d4c7684f8058f (patch)
tree5daca1da235a69fd1feee9b50f4186ef25472f78 /lib
parent74f8f15adc1e6fce2d3fcc34b7e9ef0b65d926db (diff)
Convert non-UTF-8 parts to UTF-8 before indexing them
This fixes a bug that didn't allow to search for non-ASCII words such parts. The code here was copied from show_text_part_content(), because the show command already does the needed conversion when showing the message.
Diffstat (limited to 'lib')
-rw-r--r--lib/index.cc15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/index.cc b/lib/index.cc
index d8f8b2bf..e3777322 100644
--- a/lib/index.cc
+++ b/lib/index.cc
@@ -315,6 +315,7 @@ _index_mime_part (notmuch_message_t *message,
GByteArray *byte_array;
GMimeContentDisposition *disposition;
char *body;
+ const char *charset;
if (! part) {
fprintf (stderr, "Warning: Not indexing empty mime part.\n");
@@ -390,6 +391,20 @@ _index_mime_part (notmuch_message_t *message,
g_mime_stream_filter_add (GMIME_STREAM_FILTER (filter),
discard_uuencode_filter);
+ charset = g_mime_object_get_content_type_parameter (part, "charset");
+ if (charset) {
+ GMimeFilter *charset_filter;
+ charset_filter = g_mime_filter_charset_new (charset, "UTF-8");
+ /* This result can be NULL for things like "unknown-8bit".
+ * Don't set a NULL filter as that makes GMime print
+ * annoying assertion-failure messages on stderr. */
+ if (charset_filter) {
+ g_mime_stream_filter_add (GMIME_STREAM_FILTER (filter),
+ charset_filter);
+ g_object_unref (charset_filter);
+ }
+ }
+
wrapper = g_mime_part_get_content_object (GMIME_PART (part));
if (wrapper)
g_mime_data_wrapper_write_to_stream (wrapper, filter);