- /* Dump output is one line per message. We match a sequence of
- * non-space characters for the message-id, then one or more
- * spaces, then a list of space-separated tags as a sequence of
- * characters within literal '(' and ')'. */
- xregcomp (®ex,
- "^([^ ]+) \\(([^)]*)\\)$",
- REG_EXTENDED);
-
- while ((line_len = getline (&line, &line_size, input)) != -1) {
- regmatch_t match[3];
- char *message_id, *tags, *tag, *next;
- notmuch_message_t *message;
- notmuch_status_t status;
-
- chomp_newline (line);
-
- rerr = xregexec (®ex, line, 3, match, 0);
- if (rerr == REG_NOMATCH)
- {
- fprintf (stderr, "Warning: Ignoring invalid input line: %s\n",
- line);
- continue;
+ return 0;
+
+}
+
+int
+notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])
+{
+ notmuch_database_t *notmuch;
+ notmuch_bool_t accumulate = FALSE;
+ tag_op_flag_t flags = 0;
+ tag_op_list_t *tag_ops;
+
+ char *input_file_name = NULL;
+ const char *name_for_error = NULL;
+ gzFile input = NULL;
+ char *line = NULL;
+ void *line_ctx = NULL;
+ ssize_t line_len;
+
+ int ret = 0;
+ int opt_index;
+ int input_format = DUMP_FORMAT_AUTO;
+
+ if (notmuch_database_open (notmuch_config_get_database_path (config),
+ NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much))
+ return EXIT_FAILURE;
+
+ if (notmuch_config_get_maildir_synchronize_flags (config))
+ flags |= TAG_FLAG_MAILDIR_SYNC;
+
+ notmuch_opt_desc_t options[] = {
+ { NOTMUCH_OPT_KEYWORD, &input_format, "format", 'f',
+ (notmuch_keyword_t []){ { "auto", DUMP_FORMAT_AUTO },
+ { "batch-tag", DUMP_FORMAT_BATCH_TAG },
+ { "sup", DUMP_FORMAT_SUP },
+ { 0, 0 } } },
+ { NOTMUCH_OPT_STRING, &input_file_name, "input", 'i', 0 },
+ { NOTMUCH_OPT_BOOLEAN, &accumulate, "accumulate", 'a', 0 },
+ { 0, 0, 0, 0, 0 }
+ };
+
+ opt_index = parse_arguments (argc, argv, options, 1);
+ if (opt_index < 0) {
+ ret = EXIT_FAILURE;
+ goto DONE;
+ }
+
+ name_for_error = input_file_name ? input_file_name : "stdin";
+
+ if (! accumulate)
+ flags |= TAG_FLAG_REMOVE_ALL;
+
+ errno = 0;
+ if (input_file_name)
+ input = gzopen (input_file_name, "r");
+ else {
+ int infd = dup (STDIN_FILENO);
+ if (infd < 0) {
+ fprintf (stderr, "Error duping stdin: %s\n",
+ strerror (errno));
+ ret = EXIT_FAILURE;
+ goto DONE;