+ subject = notmuch_message_get_header (message, "subject");
+ if (subject) {
+ if (strncasecmp (subject, "Re:", 3))
+ subject = talloc_asprintf (ctx, "Re: %s", subject);
+ g_mime_message_set_subject (reply, subject);
+ }
+
+ from_addr = add_recipients_from_message (reply, config,
+ message, reply_all);
+
+ if (from_addr == NULL)
+ from_addr = guess_from_received_header (config, message);
+
+ if (from_addr == NULL)
+ from_addr = notmuch_config_get_user_primary_email (config);
+
+ from_addr = talloc_asprintf (ctx, "%s <%s>",
+ notmuch_config_get_user_name (config),
+ from_addr);
+ g_mime_object_set_header (GMIME_OBJECT (reply),
+ "From", from_addr);
+
+ in_reply_to = talloc_asprintf (ctx, "<%s>",
+ notmuch_message_get_message_id (message));
+
+ g_mime_object_set_header (GMIME_OBJECT (reply),
+ "In-Reply-To", in_reply_to);
+
+ orig_references = notmuch_message_get_header (message, "references");
+ references = talloc_asprintf (ctx, "%s%s%s",
+ orig_references ? orig_references : "",
+ orig_references ? " " : "",
+ in_reply_to);
+ g_mime_object_set_header (GMIME_OBJECT (reply),
+ "References", references);
+
+ return reply;
+}
+
+static int
+notmuch_reply_format_default(void *ctx,
+ notmuch_config_t *config,
+ notmuch_query_t *query,
+ notmuch_show_params_t *params,
+ notmuch_bool_t reply_all)
+{
+ GMimeMessage *reply;
+ notmuch_messages_t *messages;
+ notmuch_message_t *message;
+ mime_node_t *root;
+
+ for (messages = notmuch_query_search_messages (query);
+ notmuch_messages_valid (messages);
+ notmuch_messages_move_to_next (messages))
+ {
+ message = notmuch_messages_get (messages);
+
+ reply = create_reply_message (ctx, config, message, reply_all);
+
+ /* If reply creation failed, we're out of memory, so don't
+ * bother trying any more messages.
+ */
+ if (!reply) {
+ notmuch_message_destroy (message);
+ return 1;
+ }
+
+ show_reply_headers (reply);
+
+ g_object_unref (G_OBJECT (reply));
+ reply = NULL;
+
+ if (mime_node_open (ctx, message, params->cryptoctx, params->decrypt,
+ &root) == NOTMUCH_STATUS_SUCCESS) {
+ format_part_reply (root);
+ talloc_free (root);
+ }
+
+ notmuch_message_destroy (message);
+ }
+ return 0;
+}
+
+static int
+notmuch_reply_format_json(void *ctx,
+ notmuch_config_t *config,
+ notmuch_query_t *query,
+ notmuch_show_params_t *params,
+ notmuch_bool_t reply_all)
+{
+ GMimeMessage *reply;
+ notmuch_messages_t *messages;
+ notmuch_message_t *message;
+ mime_node_t *node;
+
+ if (notmuch_query_count_messages (query) != 1) {
+ fprintf (stderr, "Error: search term did not match precisely one message.\n");
+ return 1;
+ }
+
+ messages = notmuch_query_search_messages (query);
+ message = notmuch_messages_get (messages);
+ if (mime_node_open (ctx, message, params->cryptoctx, params->decrypt,
+ &node) != NOTMUCH_STATUS_SUCCESS)
+ return 1;
+
+ reply = create_reply_message (ctx, config, message, reply_all);
+ if (!reply)
+ return 1;
+
+ /* The headers of the reply message we've created */
+ printf ("{\"reply-headers\": ");
+ format_headers_json (ctx, reply, TRUE);
+ g_object_unref (G_OBJECT (reply));
+ reply = NULL;
+
+ /* Start the original */
+ printf (", \"original\": ");
+
+ format_part_json (ctx, node, TRUE);
+
+ /* End */
+ printf ("}\n");
+ notmuch_message_destroy (message);
+
+ return 0;
+}
+
+/* This format is currently tuned for a git send-email --notmuch hook */
+static int
+notmuch_reply_format_headers_only(void *ctx,
+ notmuch_config_t *config,
+ notmuch_query_t *query,
+ unused (notmuch_show_params_t *params),
+ notmuch_bool_t reply_all)
+{
+ GMimeMessage *reply;
+ notmuch_messages_t *messages;
+ notmuch_message_t *message;
+ const char *in_reply_to, *orig_references, *references;
+ char *reply_headers;
+