+ if (body == NULL)
+ return;
+
+ next_line = body;
+
+ while (1) {
+ line = next_line;
+ if (*line == '\0')
+ break;
+
+ next_line = strchr (line, '\n');
+ if (next_line == NULL) {
+ next_line = line + strlen (line);
+ }
+ line_end = next_line - 1;
+
+ /* Trim whitespace. */
+ while (*next_line && isspace (*next_line))
+ next_line++;
+
+ /* Skip lines that are quotes. */
+ if (*line == '>')
+ continue;
+
+ /* Also skip lines introducing a quote on the next line. */
+ while (line_end > line && isspace (*line_end))
+ line_end--;
+
+ if (*line_end == ':' && *next_line == '>')
+ continue;
+
+ /* Finally, bail as soon as we see a signature. */
+ /* XXX: Should only do this if "near" the end of the message. */
+ if (strncmp (line, "-- ", 3) == 0 ||
+ strncmp (line, "----------", 10) == 0 ||
+ strncmp (line, "__________", 10) == 0)
+ break;
+
+ *(line_end + 1) = '\0';
+ gen_terms (term_gen, "body", line);
+ }
+}
+
+
+/* Callback to generate terms for each mime part of a message. */
+static void
+gen_terms_part (GMimeObject *parent,
+ GMimeObject *part,
+ gpointer user_data)
+{
+ Xapian::TermGenerator *term_gen = (Xapian::TermGenerator *) user_data;
+ GMimeStream *stream;
+ GMimeDataWrapper *wrapper;
+ GByteArray *byte_array;
+ char *body;
+
+ if (! GMIME_IS_PART (part)) {
+ fprintf (stderr, "Warning: Not indexing unknown mime part: %s.\n",
+ g_type_name (G_OBJECT_TYPE (part)));
+ return;
+ }
+
+ byte_array = g_byte_array_new ();
+
+ stream = g_mime_stream_mem_new_with_byte_array (byte_array);
+ g_mime_stream_mem_set_owner (GMIME_STREAM_MEM (stream), FALSE);
+ wrapper = g_mime_part_get_content_object (GMIME_PART (part));
+ g_mime_data_wrapper_write_to_stream (wrapper, stream);
+
+ g_object_unref (stream);
+
+ body = (char *) g_byte_array_free (byte_array, FALSE);
+
+ gen_terms_body_str (*term_gen, body);
+
+ free (body);
+}
+
+static void
+index_file (Xapian::WritableDatabase db,
+ Xapian::TermGenerator term_gen,
+ const char *filename)