From: Adam Wolfe Gordon Date: Mon, 12 Mar 2012 04:05:34 +0000 (+1800) Subject: [PATCH v7 02/10] reply: Factor out reply creation X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=2c0d51790ee20199980cf6c73956d4c1765dad15;p=notmuch-archives.git [PATCH v7 02/10] reply: Factor out reply creation --- diff --git a/73/b89370126d9ee8e915b23f0d34659e6151a147 b/73/b89370126d9ee8e915b23f0d34659e6151a147 new file mode 100644 index 000000000..b8acca0cc --- /dev/null +++ b/73/b89370126d9ee8e915b23f0d34659e6151a147 @@ -0,0 +1,195 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 08658431FBC + for ; Sun, 11 Mar 2012 21:06:03 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 0 +X-Spam-Level: +X-Spam-Status: No, score=0 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_NONE=-0.0001] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id gYe4taW5f4-e for ; + Sun, 11 Mar 2012 21:06:00 -0700 (PDT) +Received: from idcmail-mo2no.shaw.ca (idcmail-mo2no.shaw.ca [64.59.134.9]) + by olra.theworths.org (Postfix) with ESMTP id 8063F431FCF + for ; Sun, 11 Mar 2012 21:05:55 -0700 (PDT) +Received: from lb7f8hsrpno-svcs.dcs.int.inet (HELO pd7ml3no-ssvc.prod.shaw.ca) + ([10.0.144.222]) + by pd7mo1no-svcs.prod.shaw.ca with ESMTP; 11 Mar 2012 22:05:55 -0600 +X-Cloudmark-SP-Filtered: true +X-Cloudmark-SP-Result: v=1.1 cv=aDUJ/pRHNXkohnfhaDKKve0FfU8uPxX8npdo6G126bI= + c=1 sm=1 + a=C18FcIqa7k4A:10 a=BLceEmwcHowA:10 a=yQp6g8lIsgqumF79BAsFDg==:17 + a=Ip1p9aMYQwLSyBp_cu4A:9 a=VU9I-PVEt86hzLs7d4sA:7 + a=HpAAvcLHHh0Zw7uRqdWCyQ==:117 +Received: from unknown (HELO lagos.xvx.ca) ([96.52.216.56]) + by pd7ml3no-dmz.prod.shaw.ca with ESMTP; 11 Mar 2012 22:05:55 -0600 +Received: by lagos.xvx.ca (Postfix, from userid 1000) + id E98B88004958; Sun, 11 Mar 2012 22:05:54 -0600 (MDT) +From: Adam Wolfe Gordon +To: notmuch@notmuchmail.org +Subject: [PATCH v7 02/10] reply: Factor out reply creation +Date: Sun, 11 Mar 2012 22:05:34 -0600 +Message-Id: <1331525142-30539-3-git-send-email-awg+notmuch@xvx.ca> +X-Mailer: git-send-email 1.7.5.4 +In-Reply-To: <1331525142-30539-1-git-send-email-awg+notmuch@xvx.ca> +References: <1331525142-30539-1-git-send-email-awg+notmuch@xvx.ca> +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Mon, 12 Mar 2012 04:06:03 -0000 + +Factor out the creation of a reply message based on an original +message so it can be shared by different reply formats. +--- + notmuch-reply.c | 104 ++++++++++++++++++++++++++++++++---------------------- + 1 files changed, 62 insertions(+), 42 deletions(-) + +diff --git a/notmuch-reply.c b/notmuch-reply.c +index 6b244e6..f1478cc 100644 +--- a/notmuch-reply.c ++++ b/notmuch-reply.c +@@ -505,6 +505,61 @@ guess_from_received_header (notmuch_config_t *config, notmuch_message_t *message + return NULL; + } + ++static GMimeMessage * ++create_reply_message(void *ctx, ++ notmuch_config_t *config, ++ notmuch_message_t *message, ++ notmuch_bool_t reply_all) ++{ ++ const char *subject, *from_addr = NULL; ++ const char *in_reply_to, *orig_references, *references; ++ ++ /* The 1 means we want headers in a "pretty" order. */ ++ GMimeMessage *reply = g_mime_message_new (1); ++ if (reply == NULL) { ++ fprintf (stderr, "Out of memory\n"); ++ return NULL; ++ } ++ ++ 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, +@@ -515,8 +570,6 @@ notmuch_reply_format_default(void *ctx, + GMimeMessage *reply; + notmuch_messages_t *messages; + notmuch_message_t *message; +- const char *subject, *from_addr = NULL; +- const char *in_reply_to, *orig_references, *references; + const notmuch_show_format_t *format = &format_reply; + + for (messages = notmuch_query_search_messages (query); +@@ -525,49 +578,16 @@ notmuch_reply_format_default(void *ctx, + { + message = notmuch_messages_get (messages); + +- /* The 1 means we want headers in a "pretty" order. */ +- reply = g_mime_message_new (1); +- if (reply == NULL) { +- fprintf (stderr, "Out of memory\n"); +- return 1; +- } ++ reply = create_reply_message (ctx, config, message, reply_all); + +- 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); ++ /* 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; + } + +- 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); +- + show_reply_headers (reply); + + g_object_unref (G_OBJECT (reply)); +-- +1.7.5.4 +