+ add_terms_address_addrs (doc, addresses, "from_email");
+
+ add_terms_address_addrs (doc,
+ g_mime_message_get_all_recipients (message),
+ "to_email");
+
+ g_mime_message_get_date (message, &time, NULL);
+
+ gmtime_r (&time, &gm_time_tm);
+
+ if (strftime (date_str, sizeof (date_str),
+ "%Y%m%d%H%M%S", &gm_time_tm) == 0) {
+ fprintf (stderr, "Internal error formatting time\n");
+ exit (1);
+ }
+
+ add_term (doc, "date", date_str);
+
+ add_term (doc, "label", "inbox");
+ add_term (doc, "label", "unread");
+ add_term (doc, "type", "mail");
+ add_term (doc, "source_id", "1");
+
+ message_id = g_mime_message_get_message_id (message);
+ add_term (doc, "msgid", message_id);
+ doc.add_value (NOTMUCH_VALUE_MESSAGE_ID, message_id);
+
+ if (thread_id) {
+ add_term (doc, "thread", thread_id);
+ doc.add_value (NOTMUCH_VALUE_THREAD, thread_id);
+ free ((void *) thread_id);
+ } else {
+ /* If not referenced thread, use the message ID */
+ add_term (doc, "thread", message_id);
+ doc.add_value (NOTMUCH_VALUE_THREAD, message_id);
+ }
+
+ doc.add_value (NOTMUCH_VALUE_DATE, Xapian::sortable_serialise (time));
+
+ db.add_document (doc);
+
+ g_object_unref (message);
+ g_object_unref (parser);
+ g_object_unref (stream);
+}
+
+static void
+usage (const char *argv0)
+{
+ fprintf (stderr, "Usage: %s <path-to-xapian-database>\n", argv0);
+ fprintf (stderr, "\n");
+ fprintf (stderr, "Messages to be indexed are read from stdnin as absolute filenames\n");
+ fprintf (stderr, "one file per line.");
+}
+
+int
+main (int argc, char **argv)
+{
+ const char *database_path;
+ char *filename;
+ GIOChannel *channel;
+ GIOStatus gio_status;
+ GError *error = NULL;
+
+ if (argc < 2) {
+ usage (argv[0]);
+ exit (1);
+ }
+
+ database_path = argv[1];