]> git.notmuchmail.org Git - notmuch/blobdiff - notmuch.c
notmuch_database_add_message: Do not return a message on failure.
[notmuch] / notmuch.c
index 3b0182a9e91a2a550ed9ad986f880d61764ebb6f..a7559fc7a6266a034f6b8580819ff0ca9a2be1e9 100644 (file)
--- a/notmuch.c
+++ b/notmuch.c
@@ -180,7 +180,7 @@ add_files_recursive (notmuch_database_t *notmuch,
     char *next = NULL;
     time_t path_mtime, path_dbtime;
     notmuch_status_t status, ret = NOTMUCH_STATUS_SUCCESS;
-    notmuch_message_t *message, **closure;
+    notmuch_message_t *message = NULL, **closure;
 
     /* If we're told to, we bail out on encountering a read-only
      * directory, (with this being a clear clue from the user to
@@ -266,7 +266,6 @@ add_files_recursive (notmuch_database_t *notmuch,
                        state->added_messages++;
                        if (state->callback)
                            (state->callback) (message);
-                       notmuch_message_destroy (message);
                        break;
                    /* Non-fatal issues (go on to next file) */
                    case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:
@@ -287,10 +286,17 @@ add_files_recursive (notmuch_database_t *notmuch,
                    case NOTMUCH_STATUS_FILE_ERROR:
                    case NOTMUCH_STATUS_NULL_POINTER:
                    case NOTMUCH_STATUS_TAG_TOO_LONG:
+                   case NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW:
                    case NOTMUCH_STATUS_LAST_STATUS:
                        INTERNAL_ERROR ("add_message returned unexpected value: %d",  status);
                        goto DONE;
                }
+
+               if (message) {
+                   notmuch_message_destroy (message);
+                   message = NULL;
+               }
+
                if (state->processed_files % 1000 == 0)
                    add_files_print_progress (state);
            }
@@ -854,6 +860,10 @@ restore_command (int argc, char *argv[])
                goto NEXT_LINE;
            }
 
+           notmuch_message_freeze (message);
+
+           notmuch_message_remove_all_tags (message);
+
            next = tags;
            while (next) {
                tag = strsep (&next, " ");
@@ -869,6 +879,7 @@ restore_command (int argc, char *argv[])
                }
            }
 
+           notmuch_message_thaw (message);
            notmuch_message_destroy (message);
        }
       NEXT_LINE: