- 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;
+ }
+
+ /* In order to detect missing messages, this check/optimization is
+ * intentionally done *after* first finding the message. */
+ if (accumulate && (file_tags == NULL || *file_tags == '\0'))
+ {