[notmuch] [PATCH -V3 1/2] notmuch-reply: Add support for replying only to sender
authorAneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Wed, 10 Mar 2010 16:31:25 +0000 (22:01 +0530)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:36:21 +0000 (09:36 -0800)
74/d0549dd8cdc86ab2ff987008c9880d900924fd [new file with mode: 0644]

diff --git a/74/d0549dd8cdc86ab2ff987008c9880d900924fd b/74/d0549dd8cdc86ab2ff987008c9880d900924fd
new file mode 100644 (file)
index 0000000..7ae8ee1
--- /dev/null
@@ -0,0 +1,214 @@
+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 0CB8D4916AE\r
+       for <notmuch@notmuchmail.org>; Wed, 10 Mar 2010 08:31:54 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -5.186\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-5.186 tagged_above=-999 required=5 tests=[AWL=1.413,\r
+       BAYES_00=-2.599, RCVD_IN_DNSWL_MED=-4] autolearn=unavailable\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 J5LAZKI3sq37 for <notmuch@notmuchmail.org>;\r
+       Wed, 10 Mar 2010 08:31:51 -0800 (PST)\r
+Received: from e23smtp07.au.ibm.com (e23smtp07.au.ibm.com [202.81.31.140])\r
+       by olra.theworths.org (Postfix) with ESMTP id 350884916B5\r
+       for <notmuch@notmuchmail.org>; Wed, 10 Mar 2010 08:31:50 -0800 (PST)\r
+Received: from d23relay05.au.ibm.com (d23relay05.au.ibm.com [202.81.31.247])\r
+       by e23smtp07.au.ibm.com (8.14.3/8.13.1) with ESMTP id o2AGVV6r010202\r
+       for <notmuch@notmuchmail.org>; Thu, 11 Mar 2010 03:31:31 +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
+       o2AGPhwl1630298\r
+       for <notmuch@notmuchmail.org>; Thu, 11 Mar 2010 03:25:44 +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
+       o2AGVTOn008214\r
+       for <notmuch@notmuchmail.org>; Thu, 11 Mar 2010 03:31:30 +1100\r
+Received: from localhost.localdomain ([9.124.221.30])\r
+       by d23av04.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id\r
+       o2AGVSYe008190; Thu, 11 Mar 2010 03:31:28 +1100\r
+From: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>\r
+To: cworth@cworth.org\r
+Date: Wed, 10 Mar 2010 22:01:25 +0530\r
+Message-Id:\r
+ <1268238686-13605-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com>\r
+X-Mailer: git-send-email 1.7.0.2.157.gb7e7f\r
+In-Reply-To: <87zl2hic7d.fsf@yoom.home.cworth.org>\r
+References: <87zl2hic7d.fsf@yoom.home.cworth.org>\r
+Cc: "Aneesh Kumar K.V" <aneesh.kumar@gmail.com>, notmuch@notmuchmail.org\r
+Subject: [notmuch] [PATCH -V3 1/2] notmuch-reply: Add support for replying\r
+       only to sender\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: Wed, 10 Mar 2010 16:31:54 -0000\r
+\r
+From: Aneesh Kumar K.V <aneesh.kumar@gmail.com>\r
+\r
+This patch add --recipient=all|sender option\r
+\r
+Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@gmail.com>\r
+---\r
+ notmuch-client.h |    2 +\r
+ notmuch-reply.c  |   55 ++++++++++++++++++++++++++++++++++++++++-------------\r
+ 2 files changed, 43 insertions(+), 14 deletions(-)\r
+\r
+diff --git a/notmuch-client.h b/notmuch-client.h\r
+index c80b39c..26fdb4a 100644\r
+--- a/notmuch-client.h\r
++++ b/notmuch-client.h\r
+@@ -70,6 +70,8 @@\r
+ #define STRNCMP_LITERAL(var, literal) \\r
+     strncmp ((var), (literal), sizeof (literal) - 1)\r
\r
++#define NOTMUCH_REPLY_ALL   0x1\r
++#define NOTMUCH_REPLY_SENDER_ONLY 0x2\r
+ static inline void\r
+ chomp_newline (char *str)\r
+ {\r
+diff --git a/notmuch-reply.c b/notmuch-reply.c\r
+index 6c15536..e8a0820 100644\r
+--- a/notmuch-reply.c\r
++++ b/notmuch-reply.c\r
+@@ -232,20 +232,37 @@ reply_to_header_is_redundant (notmuch_message_t *message)\r
+ static const char *\r
+ add_recipients_from_message (GMimeMessage *reply,\r
+                            notmuch_config_t *config,\r
+-                           notmuch_message_t *message)\r
++                           notmuch_message_t *message,\r
++                           int reply_options)\r
+ {\r
+-    struct {\r
++    struct reply_to_map {\r
+       const char *header;\r
+       const char *fallback;\r
+       GMimeRecipientType recipient_type;\r
+-    } reply_to_map[] = {\r
++    } ;\r
++    const char *from_addr = NULL;\r
++    unsigned int i;\r
++    struct reply_to_map *reply_to_map;\r
++\r
++    struct reply_to_map reply_to_map_all[] = {\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
+-    const char *from_addr = NULL;\r
+-    unsigned int i;\r
++\r
++    /* we try from first and then reply-to */\r
++    struct reply_to_map reply_to_map_sender[] = {\r
++      { "from", "reply-to", GMIME_RECIPIENT_TYPE_TO  },\r
++      {  NULL,        NULL, 0 }\r
++    };\r
++\r
++    if (reply_options == NOTMUCH_REPLY_SENDER_ONLY) {\r
++      reply_to_map = reply_to_map_sender;\r
++    } else {\r
++      reply_to_map = reply_to_map_all;\r
++    }\r
\r
+     /* Some mailing lists munge the Reply-To header despite it being A Bad\r
+      * Thing, see http://www.unicom.com/pw/reply-to-harmful.html\r
+@@ -263,7 +280,7 @@ add_recipients_from_message (GMimeMessage *reply,\r
+       reply_to_map[0].fallback = NULL;\r
+     }\r
\r
+-    for (i = 0; i < ARRAY_SIZE (reply_to_map); i++) {\r
++    for (i = 0; reply_to_map[i].header; i++) {\r
+       const char *addr, *recipients;\r
\r
+       recipients = notmuch_message_get_header (message,\r
+@@ -283,7 +300,7 @@ add_recipients_from_message (GMimeMessage *reply,\r
+ }\r
\r
+ static int\r
+-notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_t *query)\r
++notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_t *query, int reply_options)\r
+ {\r
+     GMimeMessage *reply;\r
+     notmuch_messages_t *messages;\r
+@@ -311,7 +328,7 @@ 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
+-      from_addr = add_recipients_from_message (reply, config, message);\r
++      from_addr = add_recipients_from_message (reply, config, message, reply_options);\r
\r
+       if (from_addr == NULL)\r
+           from_addr = notmuch_config_get_user_primary_email (config);\r
+@@ -359,7 +376,7 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_\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
++notmuch_reply_format_headers_only(void *ctx, notmuch_config_t *config, notmuch_query_t *query, int reply_options)\r
+ {\r
+     GMimeMessage *reply;\r
+     notmuch_messages_t *messages;\r
+@@ -399,7 +416,7 @@ 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
+-      (void)add_recipients_from_message (reply, config, message);\r
++      (void)add_recipients_from_message (reply, config, message, reply_options);\r
\r
+       g_mime_object_set_header (GMIME_OBJECT (reply), "Bcc",\r
+                          notmuch_config_get_user_primary_email (config));\r
+@@ -423,8 +440,8 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
+     notmuch_database_t *notmuch;\r
+     notmuch_query_t *query;\r
+     char *opt, *query_string;\r
+-    int i, ret = 0;\r
+-    int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query);\r
++    int i, ret = 0, reply_to = NOTMUCH_REPLY_ALL;\r
++    int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, int reply_options);\r
\r
+     reply_format_func = notmuch_reply_format_default;\r
\r
+@@ -443,6 +460,16 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
+               fprintf (stderr, "Invalid value for --format: %s\n", opt);\r
+               return 1;\r
+           }\r
++      } else if (STRNCMP_LITERAL (argv[i], "--recipient=") == 0) {\r
++          opt = argv[i] + sizeof ("--recipient=") - 1;\r
++          if (strcmp (opt, "all") == 0) {\r
++              reply_to = NOTMUCH_REPLY_ALL;\r
++          } else if (strcmp (opt, "sender") == 0) {\r
++              reply_to = NOTMUCH_REPLY_SENDER_ONLY;\r
++          } else {\r
++              fprintf (stderr, "Invalid value for --recipient: %s\n", opt);\r
++              return 1;\r
++          }\r
+       } else {\r
+           fprintf (stderr, "Unrecognized option: %s\n", argv[i]);\r
+           return 1;\r
+@@ -478,7 +505,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
+       return 1;\r
+     }\r
\r
+-    if (reply_format_func (ctx, config, query) != 0)\r
++    if (reply_format_func (ctx, config, query, reply_to) != 0)\r
+       return 1;\r
\r
+     notmuch_query_destroy (query);\r
+-- \r
+1.7.0.2.157.gb7e7f\r
+\r