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 52D61431FBF for ; Sat, 5 Dec 2009 01:38:08 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org 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 vJrfds3Kd2tW for ; Sat, 5 Dec 2009 01:38:07 -0800 (PST) Received: from e23smtp08.au.ibm.com (e23smtp08.au.ibm.com [202.81.31.141]) by olra.theworths.org (Postfix) with ESMTP id 56302431FBC for ; Sat, 5 Dec 2009 01:38:07 -0800 (PST) Received: from d23relay05.au.ibm.com (d23relay05.au.ibm.com [202.81.31.247]) by e23smtp08.au.ibm.com (8.14.3/8.13.1) with ESMTP id nB5Kc5Ro028850 for ; Sun, 6 Dec 2009 07:38:05 +1100 Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139]) by d23relay05.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id nB59YJlZ1589450 for ; Sat, 5 Dec 2009 20:34:21 +1100 Received: from d23av04.au.ibm.com (loopback [127.0.0.1]) by d23av04.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id nB59c2Kt007326 for ; Sat, 5 Dec 2009 20:38:02 +1100 Received: from localhost.localdomain ([9.77.207.152]) by d23av04.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id nB59c0n6007312; Sat, 5 Dec 2009 20:38:00 +1100 From: "Aneesh Kumar K.V" To: cworth@cworth.org, aneesh.kumar@linux.vnet.ibm.com Date: Sat, 5 Dec 2009 15:07:58 +0530 Message-Id: <1260005878-18500-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> X-Mailer: git-send-email 1.6.5.2.74.g610f9 In-Reply-To: <1259830005-3439-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> References: <1259830005-3439-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> Cc: "Aneesh Kumar K.V" , notmuch@notmuchmail.org Subject: [notmuch] [PATCH -V2] notmuch-reply: Add support for replying only to sender X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.12 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: Sat, 05 Dec 2009 09:38:08 -0000 From: Aneesh Kumar K.V This patch add --format=sender-only option. Signed-off-by: Aneesh Kumar K.V --- notmuch-reply.c | 54 ++++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 40 insertions(+), 14 deletions(-) diff --git a/notmuch-reply.c b/notmuch-reply.c index 0cda72d..859b725 100644 --- a/notmuch-reply.c +++ b/notmuch-reply.c @@ -23,15 +23,23 @@ #include "notmuch-client.h" #include "gmime-filter-reply.h" -static const struct { +struct reply_map { const char *header; const char *fallback; GMimeRecipientType recipient_type; -} reply_to_map[] = { +}; + +static const struct reply_map reply_to_all_map[] = { { "reply-to", "from", GMIME_RECIPIENT_TYPE_TO }, { "to", NULL, GMIME_RECIPIENT_TYPE_TO }, { "cc", NULL, GMIME_RECIPIENT_TYPE_CC }, - { "bcc", NULL, GMIME_RECIPIENT_TYPE_BCC } + { "bcc", NULL, GMIME_RECIPIENT_TYPE_BCC }, + { NULL, NULL, 0} +}; + +static const struct reply_map reply_to_sender_map[] = { + { "reply-to", "from", GMIME_RECIPIENT_TYPE_TO }, + { NULL, NULL, 0} }; static void @@ -200,7 +208,8 @@ add_recipients_for_string (GMimeMessage *message, } static int -notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_t *query) +__notmuch_reply(void *ctx, notmuch_config_t *config, + notmuch_query_t *query, const struct reply_map *map) { GMimeMessage *reply; notmuch_messages_t *messages; @@ -229,17 +238,19 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_ subject = talloc_asprintf (ctx, "Re: %s", subject); g_mime_message_set_subject (reply, subject); - for (i = 0; i < ARRAY_SIZE (reply_to_map); i++) { + for (i = 0;; i++) { const char *addr; + if (!map[i].header) + break; recipients = notmuch_message_get_header (message, - reply_to_map[i].header); - if ((recipients == NULL || recipients[0] == '\0') && reply_to_map[i].fallback) + map[i].header); + if ((recipients == NULL || recipients[0] == '\0') && map[i].fallback) recipients = notmuch_message_get_header (message, - reply_to_map[i].fallback); + map[i].fallback); addr = add_recipients_for_string (reply, config, - reply_to_map[i].recipient_type, + map[i].recipient_type, recipients); if (from_addr == NULL) from_addr = addr; @@ -289,6 +300,12 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_ return 0; } +static int +notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_t *query) +{ + return __notmuch_reply(ctx, config, query, reply_to_all_map); +} + /* 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) @@ -332,17 +349,18 @@ notmuch_reply_format_headers_only(void *ctx, notmuch_config_t *config, notmuch_q g_mime_object_set_header (GMIME_OBJECT (reply), "References", references); - for (i = 0; i < ARRAY_SIZE (reply_to_map); i++) { + for (i = 0; i < ARRAY_SIZE (reply_to_all_map); i++) { const char *addr; recipients = notmuch_message_get_header (message, - reply_to_map[i].header); - if ((recipients == NULL || recipients[0] == '\0') && reply_to_map[i].fallback) + reply_to_all_map[i].header); + if ((recipients == NULL || recipients[0] == '\0') && + reply_to_all_map[i].fallback) recipients = notmuch_message_get_header (message, - reply_to_map[i].fallback); + reply_to_all_map[i].fallback); addr = add_recipients_for_string (reply, config, - reply_to_map[i].recipient_type, + reply_to_all_map[i].recipient_type, recipients); } @@ -361,6 +379,12 @@ notmuch_reply_format_headers_only(void *ctx, notmuch_config_t *config, notmuch_q return 0; } +static int +notmuch_reply_format_sender_only(void *ctx, notmuch_config_t *config, notmuch_query_t *query) +{ + return __notmuch_reply(ctx, config, query, reply_to_sender_map); +} + int notmuch_reply_command (void *ctx, int argc, char *argv[]) { @@ -384,6 +408,8 @@ notmuch_reply_command (void *ctx, int argc, char *argv[]) reply_format_func = notmuch_reply_format_default; } else if (strcmp (opt, "headers-only") == 0) { reply_format_func = notmuch_reply_format_headers_only; + } else if (strcmp (opt, "sender-only") == 0) { + reply_format_func = notmuch_reply_format_sender_only; } else { fprintf (stderr, "Invalid value for --format: %s\n", opt); return 1; -- 1.6.5.2.74.g610f9