+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;
+ FILE *input = stdin;
+ char *line = NULL;
+ void *line_ctx = NULL;
+ size_t line_size;
+ 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)
+ return EXIT_FAILURE;
+
+ if (! accumulate)
+ flags |= TAG_FLAG_REMOVE_ALL;
+
+ if (input_file_name) {
+ input = fopen (input_file_name, "r");