]> git.notmuchmail.org Git - notmuch/blobdiff - lib/database.cc
emacs: send notmuch-query stderr to /dev/null
[notmuch] / lib / database.cc
index 6affc205e4e81b894443722b30f54457ff7669e3..d88b168b9c872f31f9bf51ae5e6f537feccd1dbb 100644 (file)
@@ -24,7 +24,6 @@
 
 #include <sys/time.h>
 #include <signal.h>
-#include <xapian.h>
 
 #include <glib.h> /* g_free, GPtrArray, GHashTable */
 
@@ -90,8 +89,9 @@ typedef struct {
  *
  * In addition, terms from the content of the message are added with
  * "from", "to", "attachment", and "subject" prefixes for use by the
- * user in searching. But the database doesn't really care itself
- * about any of these.
+ * user in searching. Similarly, terms from the path of the mail
+ * message are added with a "folder" prefix. But the database doesn't
+ * really care itself about any of these.
  *
  * The data portion of a mail document is empty.
  *
@@ -185,7 +185,7 @@ typedef struct {
  * nearly universal to all mail messages).
  */
 
-prefix_t BOOLEAN_PREFIX_INTERNAL[] = {
+static prefix_t BOOLEAN_PREFIX_INTERNAL[] = {
     { "type",                  "T" },
     { "reference",             "XREFERENCE" },
     { "replyto",               "XREPLYTO" },
@@ -194,18 +194,19 @@ prefix_t BOOLEAN_PREFIX_INTERNAL[] = {
     { "directory-direntry",    "XDDIRENTRY" },
 };
 
-prefix_t BOOLEAN_PREFIX_EXTERNAL[] = {
+static prefix_t BOOLEAN_PREFIX_EXTERNAL[] = {
     { "thread",                        "G" },
     { "tag",                   "K" },
     { "is",                    "K" },
     { "id",                    "Q" }
 };
 
-prefix_t PROBABILISTIC_PREFIX[]= {
+static prefix_t PROBABILISTIC_PREFIX[]= {
     { "from",                  "XFROM" },
     { "to",                    "XTO" },
     { "attachment",            "XATTACHMENT" },
-    { "subject",               "XSUBJECT"}
+    { "subject",               "XSUBJECT"},
+    { "folder",                        "XFOLDER"}
 };
 
 int
@@ -1300,7 +1301,7 @@ _resolve_message_id_to_thread_id (notmuch_database_t *notmuch,
 
     talloc_free (metadata_key);
 
-    return thread_id;
+    return talloc_strdup (ctx, thread_id);
 }
 
 static notmuch_status_t
@@ -1671,7 +1672,8 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
 
   DONE:
     if (message) {
-       if (ret == NOTMUCH_STATUS_SUCCESS && message_ret)
+       if ((ret == NOTMUCH_STATUS_SUCCESS ||
+            ret == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) && message_ret)
            *message_ret = message;
        else
            notmuch_message_destroy (message);
@@ -1710,17 +1712,26 @@ notmuch_database_remove_message (notmuch_database_t *notmuch,
        if (status)
            return status;
 
-       term = talloc_asprintf (notmuch, "%s%s", prefix, direntry);
+       term = talloc_asprintf (local, "%s%s", prefix, direntry);
 
        find_doc_ids_for_term (notmuch, term, &i, &end);
 
        for ( ; i != end; i++) {
            Xapian::TermIterator j;
+           notmuch_message_t *message;
+           notmuch_private_status_t private_status;
 
-           document = find_document_for_doc_id (notmuch, *i);
+           message = _notmuch_message_create (local, notmuch,
+                                              *i, &private_status);
+           if (message == NULL)
+               return COERCE_STATUS (private_status,
+                                     "Inconsistent document ID in datbase.");
 
-           document.remove_term (term);
+           _notmuch_message_remove_filename (message, filename);
+           _notmuch_message_sync (message);
 
+           /* Take care to find document after sync'ing filename removal. */
+           document = find_document_for_doc_id (notmuch, *i);
            j = document.termlist_begin ();
            j.skip_to (prefix);
 
@@ -1731,7 +1742,6 @@ notmuch_database_remove_message (notmuch_database_t *notmuch,
                db->delete_document (document.get_docid ());
                status = NOTMUCH_STATUS_SUCCESS;
            } else {
-               db->replace_document (document.get_docid (), document);
                status = NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID;
            }
        }