+int
+notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])
+{
+ notmuch_database_t *notmuch;
+ const char *query_str = NULL;
+ int ret;
+
+ if (notmuch_database_open (notmuch_config_get_database_path (config),
+ NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much))
+ return EXIT_FAILURE;
+
+ notmuch_exit_if_unmatched_db_uuid (notmuch);
+
+ const char *output_file_name = NULL;
+ int opt_index;
+
+ int output_format = DUMP_FORMAT_BATCH_TAG;
+ int include = 0;
+ bool gzip_output = 0;
+
+ notmuch_opt_desc_t options[] = {
+ { .opt_keyword = &output_format, .name = "format", .keywords =
+ (notmuch_keyword_t []){ { "sup", DUMP_FORMAT_SUP },
+ { "batch-tag", DUMP_FORMAT_BATCH_TAG },
+ { 0, 0 } } },
+ { .opt_flags = &include, .name = "include", .keywords =
+ (notmuch_keyword_t []){ { "config", DUMP_INCLUDE_CONFIG },
+ { "properties", DUMP_INCLUDE_PROPERTIES },
+ { "tags", DUMP_INCLUDE_TAGS} } },
+ { .opt_string = &output_file_name, .name = "output" },
+ { .opt_bool = &gzip_output, .name = "gzip" },
+ { .opt_inherit = notmuch_shared_options },
+ { }
+ };
+
+ opt_index = parse_arguments (argc, argv, options, 1);
+ if (opt_index < 0)
+ return EXIT_FAILURE;
+
+ notmuch_process_shared_options (argv[0]);
+
+ if (include == 0)
+ include = DUMP_INCLUDE_CONFIG | DUMP_INCLUDE_TAGS | DUMP_INCLUDE_PROPERTIES;
+
+ if (opt_index < argc) {
+ query_str = query_string_from_args (notmuch, argc - opt_index, argv + opt_index);
+ if (query_str == NULL) {
+ fprintf (stderr, "Out of memory.\n");
+ return EXIT_FAILURE;
+ }
+ }
+
+ ret = notmuch_database_dump (notmuch, output_file_name, query_str,
+ output_format, include, gzip_output);
+
+ notmuch_database_destroy (notmuch);
+
+ return ret;