+ *(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 (Xapian::TermGenerator term_gen,
+ GMimeObject *part)
+{
+ GMimeStream *stream;
+ GMimeDataWrapper *wrapper;
+ GByteArray *byte_array;
+ GMimeContentDisposition *disposition;
+ 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_MESSAGE_PART (part)) {
+ GMimeMessage *message;
+
+ message = g_mime_message_part_get_message (GMIME_MESSAGE_PART (part));
+
+ gen_terms_part (term_gen, g_mime_message_get_mime_part (message));
+
+ return;
+ }
+
+ if (! (GMIME_IS_PART (part))) {
+ fprintf (stderr, "Warning: Not indexing unknown mime part: %s.\n",
+ g_type_name (G_OBJECT_TYPE (part)));
+ return;
+ }
+
+ disposition = g_mime_object_get_content_disposition (part);
+ if (disposition &&
+ strcmp (disposition->disposition, GMIME_DISPOSITION_ATTACHMENT) == 0)
+ {
+ const char *filename = g_mime_part_get_filename (GMIME_PART (part));
+ const char *extension;
+
+ add_term (term_gen.get_document (), "label", "attachment");
+ gen_terms (term_gen, "attachment", filename);
+
+ if (filename) {
+ extension = strchr (filename, '.');
+ if (extension) {
+ add_term (term_gen.get_document (), "attachment_extension",
+ extension + 1);
+ }
+ }
+
+ return;