--- /dev/null
+Return-Path: <jani@nikula.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 1626D431FB6\r
+ for <notmuch@notmuchmail.org>; Thu, 8 Mar 2012 14:05:18 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id mJaMF39Vrbsn for <notmuch@notmuchmail.org>;\r
+ Thu, 8 Mar 2012 14:05:16 -0800 (PST)\r
+Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com\r
+ [209.85.217.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 31A47431FAE\r
+ for <notmuch@notmuchmail.org>; Thu, 8 Mar 2012 14:05:16 -0800 (PST)\r
+Received: by lbok6 with SMTP id k6so250584lbo.26\r
+ for <notmuch@notmuchmail.org>; Thu, 08 Mar 2012 14:05:13 -0800 (PST)\r
+Received: by 10.112.24.196 with SMTP id w4mr2867102lbf.62.1331244313062;\r
+ Thu, 08 Mar 2012 14:05:13 -0800 (PST)\r
+Received: from localhost (dsl-hkibrasgw4-fe50f800-253.dhcp.inet.fi.\r
+ [84.248.80.253])\r
+ by mx.google.com with ESMTPS id s18sm3829853lbv.17.2012.03.08.14.05.10\r
+ (version=SSLv3 cipher=OTHER); Thu, 08 Mar 2012 14:05:11 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: Adam Wolfe Gordon <awg+notmuch@xvx.ca>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH v6 02/10] reply: Factor out reply creation\r
+In-Reply-To: <1329893199-21630-3-git-send-email-awg+notmuch@xvx.ca>\r
+References: <1329893199-21630-1-git-send-email-awg+notmuch@xvx.ca>\r
+ <1329893199-21630-3-git-send-email-awg+notmuch@xvx.ca>\r
+User-Agent: Notmuch/0.11.1+295~g780f284 (http://notmuchmail.org) Emacs/23.3.1\r
+ (i686-pc-linux-gnu)\r
+Date: Fri, 09 Mar 2012 00:05:08 +0200\r
+Message-ID: <87obs692az.fsf@nikula.org>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Gm-Message-State:\r
+ ALoCoQltTWWK+yu7GdphpS7gZN1dgW3cvKj4JuRybFZGTAvgDTZrtOMCxnjvtryM91+3Al4Chz2Z\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Thu, 08 Mar 2012 22:05:18 -0000\r
+\r
+On Tue, 21 Feb 2012 23:46:31 -0700, Adam Wolfe Gordon <awg+notmuch@xvx.ca> wrote:\r
+> Factor out the creation of a reply message based on an original\r
+> message so it can be shared by different reply formats.\r
+> ---\r
+> notmuch-reply.c | 101 +++++++++++++++++++++++++++++++-----------------------\r
+> 1 files changed, 58 insertions(+), 43 deletions(-)\r
+> \r
+> diff --git a/notmuch-reply.c b/notmuch-reply.c\r
+> index 6b244e6..8e56245 100644\r
+> --- a/notmuch-reply.c\r
+> +++ b/notmuch-reply.c\r
+> @@ -505,6 +505,61 @@ guess_from_received_header (notmuch_config_t *config, notmuch_message_t *message\r
+> return NULL;\r
+> }\r
+> \r
+> +static GMimeMessage *\r
+> +create_reply_message(void *ctx,\r
+> + notmuch_config_t *config,\r
+> + notmuch_message_t *message,\r
+> + notmuch_bool_t reply_all)\r
+> +{\r
+> + const char *subject, *from_addr = NULL;\r
+> + const char *in_reply_to, *orig_references, *references;\r
+> +\r
+> + /* The 1 means we want headers in a "pretty" order. */\r
+> + GMimeMessage *reply = g_mime_message_new (1);\r
+> + if (reply == NULL) {\r
+> + fprintf (stderr, "Out of memory\n");\r
+> + return NULL;\r
+> + }\r
+> +\r
+> + subject = notmuch_message_get_header (message, "subject");\r
+> + if (subject) {\r
+> + if (strncasecmp (subject, "Re:", 3))\r
+> + subject = talloc_asprintf (ctx, "Re: %s", subject);\r
+> + g_mime_message_set_subject (reply, subject);\r
+> + }\r
+> +\r
+> + from_addr = add_recipients_from_message (reply, config,\r
+> + message, reply_all);\r
+> +\r
+> + if (from_addr == NULL)\r
+> + from_addr = guess_from_received_header (config, message);\r
+> +\r
+> + if (from_addr == NULL)\r
+> + from_addr = notmuch_config_get_user_primary_email (config);\r
+> +\r
+> + from_addr = talloc_asprintf (ctx, "%s <%s>",\r
+> + notmuch_config_get_user_name (config),\r
+> + from_addr);\r
+> + g_mime_object_set_header (GMIME_OBJECT (reply),\r
+> + "From", from_addr);\r
+> +\r
+> + in_reply_to = talloc_asprintf (ctx, "<%s>",\r
+> + notmuch_message_get_message_id (message));\r
+> +\r
+> + g_mime_object_set_header (GMIME_OBJECT (reply),\r
+> + "In-Reply-To", in_reply_to);\r
+> +\r
+> + orig_references = notmuch_message_get_header (message, "references");\r
+> + references = talloc_asprintf (ctx, "%s%s%s",\r
+> + orig_references ? orig_references : "",\r
+> + orig_references ? " " : "",\r
+> + in_reply_to);\r
+> + g_mime_object_set_header (GMIME_OBJECT (reply),\r
+> + "References", references);\r
+> +\r
+> + return reply;\r
+> +}\r
+> +\r
+> static int\r
+> notmuch_reply_format_default(void *ctx,\r
+> notmuch_config_t *config,\r
+> @@ -515,8 +570,6 @@ notmuch_reply_format_default(void *ctx,\r
+> GMimeMessage *reply;\r
+> notmuch_messages_t *messages;\r
+> notmuch_message_t *message;\r
+> - const char *subject, *from_addr = NULL;\r
+> - const char *in_reply_to, *orig_references, *references;\r
+> const notmuch_show_format_t *format = &format_reply;\r
+> \r
+> for (messages = notmuch_query_search_messages (query);\r
+> @@ -525,48 +578,10 @@ notmuch_reply_format_default(void *ctx,\r
+> {\r
+> message = notmuch_messages_get (messages);\r
+> \r
+> - /* The 1 means we want headers in a "pretty" order. */\r
+> - reply = g_mime_message_new (1);\r
+> - if (reply == NULL) {\r
+> - fprintf (stderr, "Out of memory\n");\r
+> - return 1;\r
+> - }\r
+> -\r
+> - subject = notmuch_message_get_header (message, "subject");\r
+> - if (subject) {\r
+> - if (strncasecmp (subject, "Re:", 3))\r
+> - subject = talloc_asprintf (ctx, "Re: %s", subject);\r
+> - g_mime_message_set_subject (reply, subject);\r
+> - }\r
+> -\r
+> - from_addr = add_recipients_from_message (reply, config, message,\r
+> - reply_all);\r
+> + reply = create_reply_message (ctx, config, message, reply_all);\r
+> \r
+> - if (from_addr == NULL)\r
+> - from_addr = guess_from_received_header (config, message);\r
+> -\r
+> - if (from_addr == NULL)\r
+> - from_addr = notmuch_config_get_user_primary_email (config);\r
+> -\r
+> - from_addr = talloc_asprintf (ctx, "%s <%s>",\r
+> - notmuch_config_get_user_name (config),\r
+> - from_addr);\r
+> - g_mime_object_set_header (GMIME_OBJECT (reply),\r
+> - "From", from_addr);\r
+> -\r
+> - in_reply_to = talloc_asprintf (ctx, "<%s>",\r
+> - notmuch_message_get_message_id (message));\r
+> -\r
+> - g_mime_object_set_header (GMIME_OBJECT (reply),\r
+> - "In-Reply-To", in_reply_to);\r
+> -\r
+> - orig_references = notmuch_message_get_header (message, "references");\r
+> - references = talloc_asprintf (ctx, "%s%s%s",\r
+> - orig_references ? orig_references : "",\r
+> - orig_references ? " " : "",\r
+> - in_reply_to);\r
+> - g_mime_object_set_header (GMIME_OBJECT (reply),\r
+> - "References", references);\r
+> + if (!reply)\r
+> + continue;\r
+\r
+This changes the existing behaviour, which was to abort on errors. Also,\r
+"continue" here skips notmuch_message_destroy (message). With out of\r
+memory being the only possible error here, perhaps it's just easiest to\r
+abort instead of trying to go on?\r
+\r
+\r
+BR,\r
+Jani.\r
+\r
+\r
+\r
+> \r
+> show_reply_headers (reply);\r
+> \r
+> -- \r
+> 1.7.5.4\r
+> \r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r