From 7878175ed943351c39ce5cebc6f10939b2b88422 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Wed, 14 Oct 2009 15:33:16 -0700 Subject: [PATCH] notmuch-index-message: Add explicit support for multipart mime. Instead of using the recursive "foreach" method, we implement our own recursive function. This allows us to ignore the signature component of a multipart/signed message, (which we certainly don't need to index). --- notmuch-index-message.cc | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/notmuch-index-message.cc b/notmuch-index-message.cc index bb393641..852f4e16 100644 --- a/notmuch-index-message.cc +++ b/notmuch-index-message.cc @@ -395,16 +395,32 @@ gen_terms_body_str (Xapian::TermGenerator term_gen, /* Callback to generate terms for each mime part of a message. */ static void -gen_terms_part (GMimeObject *parent, - GMimeObject *part, - gpointer user_data) +gen_terms_part (Xapian::TermGenerator term_gen, + GMimeObject *part) { - Xapian::TermGenerator *term_gen = (Xapian::TermGenerator *) user_data; GMimeStream *stream; GMimeDataWrapper *wrapper; GByteArray *byte_array; char *body; + if (GMIME_IS_MULTIPART (part)) { + GMimeMultipart *multipart = GMIME_MULTIPART (part); + int i; + + for (i = 0; i < g_mime_multipart_get_count (multipart); i++) { + if (GMIME_IS_MULTIPART_SIGNED (multipart)) { + /* Don't index the signature. */ + if (i == 1) + continue; + if (i > 1) + fprintf (stderr, "Warning: Unexpected extra parts of mutlipart/signed. Indexing anyway.\n"); + } + gen_terms_part (term_gen, + g_mime_multipart_get_part (multipart, i)); + } + return; + } + if (! GMIME_IS_PART (part)) { fprintf (stderr, "Warning: Not indexing unknown mime part: %s.\n", g_type_name (G_OBJECT_TYPE (part))); @@ -422,7 +438,7 @@ gen_terms_part (GMimeObject *parent, body = (char *) g_byte_array_free (byte_array, FALSE); - gen_terms_body_str (*term_gen, body); + gen_terms_body_str (term_gen, body); free (body); } @@ -483,7 +499,7 @@ index_file (Xapian::WritableDatabase db, gen_terms (term_gen, "subject", subject); gen_terms (term_gen, "body", subject); - g_mime_message_foreach (message, gen_terms_part, &term_gen); + gen_terms_part (term_gen, g_mime_message_get_mime_part (message)); parents = g_ptr_array_new (); -- 2.26.2