reply: Factor out reply creation

Factor out the creation of a reply message based on an original
message so it can be shared by different reply formats.
This commit is contained in:
Adam Wolfe Gordon 2012-03-18 10:32:34 -06:00 committed by David Bremner
parent 30172649e8
commit 766aebc02c

View file

@ -505,31 +505,20 @@ guess_from_received_header (notmuch_config_t *config, notmuch_message_t *message
return NULL; return NULL;
} }
static int static GMimeMessage *
notmuch_reply_format_default(void *ctx, create_reply_message(void *ctx,
notmuch_config_t *config, notmuch_config_t *config,
notmuch_query_t *query, notmuch_message_t *message,
notmuch_show_params_t *params,
notmuch_bool_t reply_all) notmuch_bool_t reply_all)
{ {
GMimeMessage *reply;
notmuch_messages_t *messages;
notmuch_message_t *message;
const char *subject, *from_addr = NULL; const char *subject, *from_addr = NULL;
const char *in_reply_to, *orig_references, *references; const char *in_reply_to, *orig_references, *references;
const notmuch_show_format_t *format = &format_reply;
for (messages = notmuch_query_search_messages (query);
notmuch_messages_valid (messages);
notmuch_messages_move_to_next (messages))
{
message = notmuch_messages_get (messages);
/* The 1 means we want headers in a "pretty" order. */ /* The 1 means we want headers in a "pretty" order. */
reply = g_mime_message_new (1); GMimeMessage *reply = g_mime_message_new (1);
if (reply == NULL) { if (reply == NULL) {
fprintf (stderr, "Out of memory\n"); fprintf (stderr, "Out of memory\n");
return 1; return NULL;
} }
subject = notmuch_message_get_header (message, "subject"); subject = notmuch_message_get_header (message, "subject");
@ -539,8 +528,8 @@ notmuch_reply_format_default(void *ctx,
g_mime_message_set_subject (reply, subject); g_mime_message_set_subject (reply, subject);
} }
from_addr = add_recipients_from_message (reply, config, message, from_addr = add_recipients_from_message (reply, config,
reply_all); message, reply_all);
if (from_addr == NULL) if (from_addr == NULL)
from_addr = guess_from_received_header (config, message); from_addr = guess_from_received_header (config, message);
@ -568,6 +557,37 @@ notmuch_reply_format_default(void *ctx,
g_mime_object_set_header (GMIME_OBJECT (reply), g_mime_object_set_header (GMIME_OBJECT (reply),
"References", references); "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;
const notmuch_show_format_t *format = &format_reply;
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); show_reply_headers (reply);
g_object_unref (G_OBJECT (reply)); g_object_unref (G_OBJECT (reply));