+ for (i = 0; i < parents->len; i++)
+ _notmuch_message_add_term (message, "ref",
+ (char *) g_ptr_array_index (parents, i));
+
+ thread_ids = find_thread_ids (notmuch, parents, message_id);
+
+ for (i = 0; i < parents->len; i++)
+ g_free (g_ptr_array_index (parents, i));
+ g_ptr_array_free (parents, TRUE);
+
+ if (thread_ids->len) {
+ GString *thread_id;
+ char *id;
+
+ for (i = 0; i < thread_ids->len; i++) {
+ id = (char *) thread_ids->pdata[i];
+ _notmuch_message_add_thread_id (message, id);
+ if (i == 0)
+ thread_id = g_string_new (id);
+ else
+ g_string_append_printf (thread_id, ",%s", id);
+
+ free (id);
+ }
+ g_string_free (thread_id, TRUE);
+ } else {
+ _notmuch_message_ensure_thread_id (message);
+ }
+
+ g_ptr_array_free (thread_ids, TRUE);
+
+ return NOTMUCH_STATUS_SUCCESS;
+}
+
+notmuch_status_t
+notmuch_database_add_message (notmuch_database_t *notmuch,
+ const char *filename)
+{
+ notmuch_message_file_t *message_file;
+ notmuch_message_t *message;
+ notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;
+
+ const char *date, *header;
+ const char *from, *to, *subject, *old_filename;
+ char *message_id;
+
+ message_file = notmuch_message_file_open (filename);
+ if (message_file == NULL) {
+ ret = NOTMUCH_STATUS_FILE_ERROR;
+ goto DONE;
+ }
+
+ notmuch_message_file_restrict_headers (message_file,
+ "date",
+ "from",
+ "in-reply-to",
+ "message-id",
+ "references",
+ "subject",
+ "to",
+ (char *) NULL);
+
+ try {
+ /* The first order of business is to find/create a message ID. */
+
+ header = notmuch_message_file_get_header (message_file, "message-id");