+static int
+notmuch_reply_format_sprinter(void *ctx,
+ notmuch_config_t *config,
+ notmuch_query_t *query,
+ notmuch_show_params_t *params,
+ notmuch_bool_t reply_all,
+ sprinter_t *sp)
+{
+ GMimeMessage *reply;
+ notmuch_messages_t *messages;
+ notmuch_message_t *message;
+ mime_node_t *node;
+ unsigned count;
+ notmuch_status_t status;
+
+ status = notmuch_query_count_messages_st (query, &count);
+ if (print_status_query ("notmuch reply", query, status))
+ return 1;
+
+ if (count != 1) {
+ fprintf (stderr, "Error: search term did not match precisely one message (matched %d messages).\n", count);
+ return 1;
+ }
+
+ status = notmuch_query_search_messages_st (query, &messages);
+ if (print_status_query ("notmuch reply", query, status))
+ return 1;
+
+ message = notmuch_messages_get (messages);
+ if (mime_node_open (ctx, message, &(params->crypto), &node) != NOTMUCH_STATUS_SUCCESS)
+ return 1;
+
+ reply = create_reply_message (ctx, config, message, reply_all);
+ if (!reply)
+ return 1;
+
+ sp->begin_map (sp);
+
+ /* The headers of the reply message we've created */
+ sp->map_key (sp, "reply-headers");
+ format_headers_sprinter (sp, reply, TRUE);
+ g_object_unref (G_OBJECT (reply));
+ reply = NULL;
+
+ /* Start the original */
+ sp->map_key (sp, "original");
+ format_part_sprinter (ctx, sp, node, TRUE, TRUE, FALSE);
+
+ /* End */
+ sp->end (sp);
+ notmuch_message_destroy (message);
+
+ return 0;
+}
+