]> git.notmuchmail.org Git - notmuch/blobdiff - lib/message.cc
lib: actually return failures from notmuch_message_tags_to_maildir_flags
[notmuch] / lib / message.cc
index e6a5a5af9651d207b01ca755e6adbba700fc0a85..7e825480ecc6e5782a93113e13b0e9730fac96fc 100644 (file)
@@ -193,14 +193,16 @@ _notmuch_message_create (const void *talloc_owner,
  *     There is already a document with message ID 'message_id' in the
  *     database. The returned message can be used to query/modify the
  *     document.
+ *
  *   NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND:
  *
  *     No document with 'message_id' exists in the database. The
  *     returned message contains a newly created document (not yet
  *     added to the database) and a document ID that is known not to
- *     exist in the database. The caller can modify the message, and a
- *     call to _notmuch_message_sync will add * the document to the
- *     database.
+ *     exist in the database.  This message is "blank"; that is, it
+ *     contains only a message ID and no other metadata. The caller
+ *     can modify the message, and a call to _notmuch_message_sync
+ *     will add the document to the database.
  *
  * If an error occurs, this function will return NULL and *status
  * will be set as appropriate. (The status pointer argument must
@@ -412,26 +414,35 @@ _notmuch_message_ensure_message_file (notmuch_message_t *message)
 const char *
 notmuch_message_get_header (notmuch_message_t *message, const char *header)
 {
-    try {
-           std::string value;
-
-           /* Fetch header from the appropriate xapian value field if
-            * available */
-           if (strcasecmp (header, "from") == 0)
-               value = message->doc.get_value (NOTMUCH_VALUE_FROM);
-           else if (strcasecmp (header, "subject") == 0)
-               value = message->doc.get_value (NOTMUCH_VALUE_SUBJECT);
-           else if (strcasecmp (header, "message-id") == 0)
-               value = message->doc.get_value (NOTMUCH_VALUE_MESSAGE_ID);
-
-           if (!value.empty())
+    Xapian::valueno slot = Xapian::BAD_VALUENO;
+
+    /* Fetch header from the appropriate xapian value field if
+     * available */
+    if (strcasecmp (header, "from") == 0)
+       slot = NOTMUCH_VALUE_FROM;
+    else if (strcasecmp (header, "subject") == 0)
+       slot = NOTMUCH_VALUE_SUBJECT;
+    else if (strcasecmp (header, "message-id") == 0)
+       slot = NOTMUCH_VALUE_MESSAGE_ID;
+
+    if (slot != Xapian::BAD_VALUENO) {
+       try {
+           std::string value = message->doc.get_value (slot);
+
+           /* If we have NOTMUCH_FEATURE_FROM_SUBJECT_ID_VALUES, then
+            * empty values indicate empty headers.  If we don't, then
+            * it could just mean we didn't record the header. */
+           if ((message->notmuch->features &
+                NOTMUCH_FEATURE_FROM_SUBJECT_ID_VALUES) ||
+               ! value.empty())
                return talloc_strdup (message, value.c_str ());
 
-    } catch (Xapian::Error &error) {
-       fprintf (stderr, "A Xapian exception occurred when reading header: %s\n",
-                error.get_msg().c_str());
-       message->notmuch->exception_reported = TRUE;
-       return NULL;
+       } catch (Xapian::Error &error) {
+           fprintf (stderr, "A Xapian exception occurred when reading header: %s\n",
+                    error.get_msg().c_str());
+           message->notmuch->exception_reported = TRUE;
+           return NULL;
+       }
     }
 
     /* Otherwise fall back to parsing the file */
@@ -644,6 +655,10 @@ _notmuch_message_add_filename (notmuch_message_t *message,
     if (filename == NULL)
        INTERNAL_ERROR ("Message filename cannot be NULL.");
 
+    if (! (message->notmuch->features & NOTMUCH_FEATURE_FILE_TERMS) ||
+       ! (message->notmuch->features & NOTMUCH_FEATURE_BOOL_FOLDER))
+       return NOTMUCH_STATUS_UPGRADE_REQUIRED;
+
     relative = _notmuch_database_relative_path (message->notmuch, filename);
 
     status = _notmuch_database_split_path (local, relative, &directory, NULL);
@@ -688,6 +703,10 @@ _notmuch_message_remove_filename (notmuch_message_t *message,
     notmuch_private_status_t private_status;
     notmuch_status_t status;
 
+    if (! (message->notmuch->features & NOTMUCH_FEATURE_FILE_TERMS) ||
+       ! (message->notmuch->features & NOTMUCH_FEATURE_BOOL_FOLDER))
+       return NOTMUCH_STATUS_UPGRADE_REQUIRED;
+
     status = _notmuch_database_filename_to_direntry (
        local, message->notmuch, filename, NOTMUCH_FIND_LOOKUP, &direntry);
     if (status || !direntry)
@@ -1032,6 +1051,8 @@ _notmuch_message_gen_terms (notmuch_message_t *message,
        /* Create a gap between this an the next terms so they don't
         * appear to be a phrase. */
        message->termpos = term_gen->get_termpos () + 100;
+
+       _notmuch_message_invalidate_metadata (message, prefix_name);
     }
 
     term_gen->set_termpos (message->termpos);
@@ -1476,7 +1497,7 @@ notmuch_message_tags_to_maildir_flags (notmuch_message_t *message)
     talloc_free (to_set);
     talloc_free (to_clear);
 
-    return NOTMUCH_STATUS_SUCCESS;
+    return status;
 }
 
 notmuch_status_t