mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-22 02:48:08 +01:00
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).
This commit is contained in:
parent
6363ab32ea
commit
7878175ed9
1 changed files with 22 additions and 6 deletions
|
@ -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 ();
|
||||
|
||||
|
|
Loading…
Reference in a new issue