+int
+notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[])
+{
+ notmuch_database_t *notmuch;
+ notmuch_query_t *query;
+ char *query_string;
+ int opt_index, ret = 0;
+ int (*reply_format_func) (void *ctx,
+ notmuch_config_t *config,
+ notmuch_query_t *query,
+ notmuch_show_params_t *params,
+ notmuch_bool_t reply_all,
+ struct sprinter *sp);
+ notmuch_show_params_t params = {
+ .part = -1,
+ .crypto = {
+ .verify = FALSE,
+ .decrypt = FALSE
+ }
+ };
+ int format = FORMAT_DEFAULT;
+ int reply_all = TRUE;
+ struct sprinter *sp = NULL;
+
+ notmuch_opt_desc_t options[] = {
+ { NOTMUCH_OPT_KEYWORD, &format, "format", 'f',
+ (notmuch_keyword_t []){ { "default", FORMAT_DEFAULT },
+ { "json", FORMAT_JSON },
+ { "sexp", FORMAT_SEXP },
+ { "headers-only", FORMAT_HEADERS_ONLY },
+ { 0, 0 } } },
+ { NOTMUCH_OPT_INT, ¬much_format_version, "format-version", 0, 0 },
+ { NOTMUCH_OPT_KEYWORD, &reply_all, "reply-to", 'r',
+ (notmuch_keyword_t []){ { "all", TRUE },
+ { "sender", FALSE },
+ { 0, 0 } } },
+ { NOTMUCH_OPT_BOOLEAN, ¶ms.crypto.decrypt, "decrypt", 'd', 0 },
+ { 0, 0, 0, 0, 0 }
+ };
+
+ opt_index = parse_arguments (argc, argv, options, 1);
+ if (opt_index < 0) {
+ /* diagnostics already printed */
+ return 1;
+ }
+
+ if (format == FORMAT_HEADERS_ONLY) {
+ reply_format_func = notmuch_reply_format_headers_only;
+ } else if (format == FORMAT_JSON) {
+ reply_format_func = notmuch_reply_format_sprinter;
+ sp = sprinter_json_create (config, stdout);
+ } else if (format == FORMAT_SEXP) {
+ reply_format_func = notmuch_reply_format_sprinter;
+ sp = sprinter_sexp_create (config, stdout);
+ } else {
+ reply_format_func = notmuch_reply_format_default;
+ }
+
+ notmuch_exit_if_unsupported_format ();
+
+ query_string = query_string_from_args (config, argc-opt_index, argv+opt_index);
+ if (query_string == NULL) {
+ fprintf (stderr, "Out of memory\n");
+ return 1;
+ }
+
+ if (*query_string == '\0') {
+ fprintf (stderr, "Error: notmuch reply requires at least one search term.\n");
+ return 1;
+ }
+
+ if (notmuch_database_open (notmuch_config_get_database_path (config),
+ NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much))
+ return 1;
+
+ query = notmuch_query_create (notmuch, query_string);
+ if (query == NULL) {
+ fprintf (stderr, "Out of memory\n");
+ return 1;