]> git.notmuchmail.org Git - notmuch/blobdiff - notmuch-restore.c
Merge remote-tracking branch 'alip/find_message-v3'
[notmuch] / notmuch-restore.c
index 98660b32cf0257b95da65450e37e4c080ca49b5e..e4a5355beb4f2e5fd9e1eb12ef7dd9816d292951 100644 (file)
@@ -25,6 +25,7 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
 {
     notmuch_config_t *config;
     notmuch_database_t *notmuch;
+    notmuch_bool_t synchronize_flags;
     FILE *input;
     char *line = NULL;
     size_t line_size;
@@ -41,8 +42,8 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
     if (notmuch == NULL)
        return 1;
 
-    notmuch_database_set_maildir_sync (notmuch,
-                                      notmuch_config_get_maildir_synchronize_flags (config));
+    synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);
+
     if (argc) {
        input = fopen (argv[0], "r");
        if (input == NULL) {
@@ -86,10 +87,13 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
        file_tags = xstrndup (line + match[2].rm_so,
                              match[2].rm_eo - match[2].rm_so);
 
-       message = notmuch_database_find_message (notmuch, message_id);
-       if (message == NULL) {
-           fprintf (stderr, "Warning: Cannot apply tags to missing message: %s\n",
-                    message_id);
+       status = notmuch_database_find_message (notmuch, message_id, &message);
+       if (status || message == NULL) {
+           fprintf (stderr, "Warning: Cannot apply tags to %smessage: %s\n",
+                    message ? "" : "missing ", message_id);
+           if (status)
+               fprintf (stderr, "%s\n",
+                        notmuch_status_to_string(status));
            goto NEXT_LINE;
        }
 
@@ -133,6 +137,9 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
 
        notmuch_message_thaw (message);
 
+       if (synchronize_flags)
+           notmuch_message_tags_to_maildir_flags (message);
+
       NEXT_LINE:
        if (message)
            notmuch_message_destroy (message);