[notmuch] [PATCH -V2] notmuch-reply: Add support for replying only to sender
authorAneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Sat, 5 Dec 2009 09:37:58 +0000 (15:07 +0530)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:35:50 +0000 (09:35 -0800)
a9/203ddf144c2a0f72e6ff35e0fb018854570ed5 [new file with mode: 0644]

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