+ for (;
+ notmuch_messages_valid (messages);
+ notmuch_messages_move_to_next (messages)) {
+ message = notmuch_messages_get (messages);
+
+ if (mime_node_open (config, message, ¶ms->crypto, &node))
+ return 1;
+
+ reply = create_reply_message (config, config, message,
+ GMIME_MESSAGE (node->part), reply_all,
+ format == FORMAT_HEADERS_ONLY);
+ if (! reply)
+ return 1;
+
+ if (format == FORMAT_JSON || format == FORMAT_SEXP) {
+ sp->begin_map (sp);
+
+ /* The headers of the reply message we've created */
+ sp->map_key (sp, "reply-headers");
+ /* FIXME: send msg_crypto here to avoid killing the
+ * subject line on reply to encrypted messages! */
+ format_headers_sprinter (sp, reply, true, NULL);
+
+ /* Start the original */
+ sp->map_key (sp, "original");
+ format_part_sprinter (config, sp, node, true, false);
+
+ /* End */
+ sp->end (sp);
+ } else {
+ GMimeStream *stream_stdout = stream_stdout = g_mime_stream_stdout_new ();
+ if (stream_stdout) {
+ show_reply_headers (stream_stdout, reply);
+ if (format == FORMAT_DEFAULT)
+ format_part_reply (stream_stdout, node);
+ }
+ g_mime_stream_flush (stream_stdout);
+ g_object_unref (stream_stdout);
+ }
+
+ g_object_unref (G_OBJECT (reply));
+ talloc_free (node);
+
+ notmuch_message_destroy (message);
+ }
+
+ return 0;
+}
+
+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;
+ notmuch_show_params_t params = {
+ .part = -1,
+ .crypto = { .decrypt = NOTMUCH_DECRYPT_AUTO },
+ };
+ int format = FORMAT_DEFAULT;
+ int reply_all = true;
+
+ notmuch_opt_desc_t options[] = {
+ { .opt_keyword = &format, .name = "format", .keywords =
+ (notmuch_keyword_t []){ { "default", FORMAT_DEFAULT },
+ { "json", FORMAT_JSON },
+ { "sexp", FORMAT_SEXP },
+ { "headers-only", FORMAT_HEADERS_ONLY },
+ { 0, 0 } } },
+ { .opt_int = ¬much_format_version, .name = "format-version" },
+ { .opt_keyword = &reply_all, .name = "reply-to", .keywords =
+ (notmuch_keyword_t []){ { "all", true },
+ { "sender", false },
+ { 0, 0 } } },
+ { .opt_keyword = (int *) (¶ms.crypto.decrypt), .name = "decrypt",
+ .keyword_no_arg_value = "true", .keywords =
+ (notmuch_keyword_t []){ { "false", NOTMUCH_DECRYPT_FALSE },
+ { "auto", NOTMUCH_DECRYPT_AUTO },
+ { "true", NOTMUCH_DECRYPT_NOSTASH },
+ { 0, 0 } } },
+ { .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]);
+
+ notmuch_exit_if_unsupported_format ();
+
+ query_string = query_string_from_args (config, argc - opt_index, argv + opt_index);