+ 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;