[PATCH v5 2/5] cli: add support for replying just to the sender in "notmuch reply"
authorJani Nikula <jani@nikula.org>
Sat, 14 Jan 2012 14:46:16 +0000 (16:46 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:42:08 +0000 (09:42 -0800)
61/3f4ae1d7ba882876c51b90a3f26692e9654d2c [new file with mode: 0644]

diff --git a/61/3f4ae1d7ba882876c51b90a3f26692e9654d2c b/61/3f4ae1d7ba882876c51b90a3f26692e9654d2c
new file mode 100644 (file)
index 0000000..b5d6ceb
--- /dev/null
@@ -0,0 +1,263 @@
+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 F1D24421167\r
+       for <notmuch@notmuchmail.org>; Sat, 14 Jan 2012 06:46:41 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\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 I78OYBw5lfWZ for <notmuch@notmuchmail.org>;\r
+       Sat, 14 Jan 2012 06:46:38 -0800 (PST)\r
+Received: from mail-ee0-f53.google.com (mail-ee0-f53.google.com\r
+ [74.125.83.53])       (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
+ certificate requested)        by olra.theworths.org (Postfix) with ESMTPS id\r
+ 603EF421164   for <notmuch@notmuchmail.org>; Sat, 14 Jan 2012 06:46:33 -0800\r
+ (PST)\r
+Received: by mail-ee0-f53.google.com with SMTP id d41so20490eek.26\r
+       for <notmuch@notmuchmail.org>; Sat, 14 Jan 2012 06:46:33 -0800 (PST)\r
+Received: by 10.213.113.14 with SMTP id y14mr764170ebp.0.1326552391290;\r
+       Sat, 14 Jan 2012 06:46:31 -0800 (PST)\r
+Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi.\r
+       [80.220.92.23])\r
+       by mx.google.com with ESMTPS id a60sm44669190eeb.4.2012.01.14.06.46.29\r
+       (version=SSLv3 cipher=OTHER); Sat, 14 Jan 2012 06:46:30 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v5 2/5] cli: add support for replying just to the sender in\r
+       "notmuch reply"\r
+Date: Sat, 14 Jan 2012 16:46:16 +0200\r
+Message-Id:\r
+ <2a6d0eb5a441719155bf001feb3b68553d7c3c55.1326551350.git.jani@nikula.org>\r
+X-Mailer: git-send-email 1.7.5.4\r
+In-Reply-To: <cover.1326551350.git.jani@nikula.org>\r
+References: <cover.1326551350.git.jani@nikula.org>\r
+In-Reply-To: <cover.1326551350.git.jani@nikula.org>\r
+References: <cover.1325794371.git.jani@nikula.org>\r
+       <cover.1326551350.git.jani@nikula.org>\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: Sat, 14 Jan 2012 14:46:42 -0000\r
+\r
+Add new option --reply-to=(all|sender) to "notmuch reply" to select whether\r
+to reply to all (sender and all recipients), or just sender. Reply to all\r
+remains the default.\r
+\r
+Credits to Mark Walters <markwalters1009@gmail.com> for his similar earlier\r
+work where I picked up the basic idea of handling reply-to-sender in\r
+add_recipients_from_message(). All bugs are mine, though.\r
+\r
+Signed-off-by: Jani Nikula <jani@nikula.org>\r
+\r
+---\r
+\r
+Settled on --reply-to=(all|sender) per Carl's earlier suggestion\r
+(id:87pqn5cg4g.fsf@yoom.home.cworth.org) and David's approval on IRC.\r
+---\r
+ man/man1/notmuch-reply.1 |   28 ++++++++++++++++++----\r
+ notmuch-reply.c          |   57 ++++++++++++++++++++++++++++++++++++---------\r
+ 2 files changed, 68 insertions(+), 17 deletions(-)\r
+\r
+diff --git a/man/man1/notmuch-reply.1 b/man/man1/notmuch-reply.1\r
+index db464d8..5160ece 100644\r
+--- a/man/man1/notmuch-reply.1\r
++++ b/man/man1/notmuch-reply.1\r
+@@ -14,11 +14,13 @@ Constructs a reply template for a set of messages.\r
+ To make replying to email easier,\r
+ .B notmuch reply\r
+ takes an existing set of messages and constructs a suitable mail\r
+-template. The Reply-to header (if any, otherwise From:) is used for\r
+-the To: address. Vales from the To: and Cc: headers are copied, but\r
+-not including any of the current user's email addresses (as configured\r
+-in primary_mail or other_email in the .notmuch\-config file) in the\r
+-recipient list\r
++template. The Reply-to: header (if any, otherwise From:) is used for\r
++the To: address. Unless\r
++.BR \-\-reply-to=sender\r
++is specified, values from the To: and Cc: headers are copied, but not\r
++including any of the current user's email addresses (as configured in\r
++primary_mail or other_email in the .notmuch\-config file) in the\r
++recipient list.\r
\r
+ It also builds a suitable new subject, including Re: at the front (if\r
+ not already present), and adding the message IDs of the messages being\r
+@@ -45,6 +47,22 @@ Includes subject and quoted message body.\r
+ Only produces In\-Reply\-To, References, To, Cc, and Bcc headers.\r
+ .RE\r
+ .RE\r
++.RS\r
++.TP 4\r
++.BR \-\-reply\-to= ( all | sender )\r
++.RS\r
++.TP 4\r
++.BR all " (default)"\r
++Replies to all addresses.\r
++.TP 4\r
++.BR sender\r
++Replies only to the sender. If replying to user's own message\r
++(Reply-to: or From: header is one of the user's configured email\r
++addresses), try To:, Cc:, and Bcc: headers in this order, and copy\r
++values from the first that contains something other than only the\r
++user's addresses.\r
++.RE\r
++.RE\r
\r
+ See \fBnotmuch-search-terms\fR(7)\r
+ for details of the supported syntax for <search-terms>.\r
+diff --git a/notmuch-reply.c b/notmuch-reply.c\r
+index a8d6a94..da3acce 100644\r
+--- a/notmuch-reply.c\r
++++ b/notmuch-reply.c\r
+@@ -291,15 +291,23 @@ reply_to_header_is_redundant (notmuch_message_t *message)\r
+     return 0;\r
+ }\r
\r
+-/* Augments the recipients of reply from the headers of message.\r
++/* Augment the recipients of 'reply' from the "Reply-to:", "From:",\r
++ * "To:", "Cc:", and "Bcc:" headers of 'message'.\r
+  *\r
+- * If any of the user's addresses were found in these headers, the first\r
+- * of these returned, otherwise NULL is returned.\r
++ * If 'reply_all' is true, use sender and all recipients, otherwise\r
++ * scan the headers for the first that contains something other than\r
++ * the user's addresses and add the recipients from this header\r
++ * (typically this would be reply-to-sender, but also handles reply to\r
++ * user's own message in a sensible way).\r
++ *\r
++ * If any of the user's addresses were found in these headers, the\r
++ * first of these returned, otherwise NULL is returned.\r
+  */\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
++                           notmuch_bool_t reply_all)\r
+ {\r
+     struct {\r
+       const char *header;\r
+@@ -313,6 +321,7 @@ add_recipients_from_message (GMimeMessage *reply,\r
+     };\r
+     const char *from_addr = NULL;\r
+     unsigned int i;\r
++    unsigned int n = 0;\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
+@@ -339,8 +348,24 @@ add_recipients_from_message (GMimeMessage *reply,\r
+           recipients = notmuch_message_get_header (message,\r
+                                                    reply_to_map[i].fallback);\r
\r
+-      scan_address_string (recipients, config, reply,\r
+-                           reply_to_map[i].recipient_type, &from_addr);\r
++      n += scan_address_string (recipients, config, reply,\r
++                                reply_to_map[i].recipient_type, &from_addr);\r
++\r
++      if (!reply_all && n) {\r
++          /* Stop adding new recipients in reply-to-sender mode if\r
++           * we have added some recipient(s) above.\r
++           *\r
++           * This also handles the case of user replying to his own\r
++           * message, where reply-to/from is not a recipient. In\r
++           * this case there may be more than one recipient even if\r
++           * not replying to all.\r
++           */\r
++          reply = NULL;\r
++\r
++          /* From address and some recipients are enough, bail out. */\r
++          if (from_addr)\r
++              break;\r
++      }\r
+     }\r
\r
+     return from_addr;\r
+@@ -484,7 +509,8 @@ static int\r
+ notmuch_reply_format_default(void *ctx,\r
+                            notmuch_config_t *config,\r
+                            notmuch_query_t *query,\r
+-                           notmuch_show_params_t *params)\r
++                           notmuch_show_params_t *params,\r
++                           notmuch_bool_t reply_all)\r
+ {\r
+     GMimeMessage *reply;\r
+     notmuch_messages_t *messages;\r
+@@ -513,7 +539,8 @@ notmuch_reply_format_default(void *ctx,\r
+           g_mime_message_set_subject (reply, subject);\r
+       }\r
\r
+-      from_addr = add_recipients_from_message (reply, config, message);\r
++      from_addr = add_recipients_from_message (reply, config, message,\r
++                                               reply_all);\r
\r
+       if (from_addr == NULL)\r
+           from_addr = guess_from_received_header (config, message);\r
+@@ -562,7 +589,8 @@ static int\r
+ notmuch_reply_format_headers_only(void *ctx,\r
+                                 notmuch_config_t *config,\r
+                                 notmuch_query_t *query,\r
+-                                unused (notmuch_show_params_t *params))\r
++                                unused (notmuch_show_params_t *params),\r
++                                notmuch_bool_t reply_all)\r
+ {\r
+     GMimeMessage *reply;\r
+     notmuch_messages_t *messages;\r
+@@ -602,7 +630,7 @@ notmuch_reply_format_headers_only(void *ctx,\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_all);\r
\r
+       reply_headers = g_mime_object_to_string (GMIME_OBJECT (reply));\r
+       printf ("%s", reply_headers);\r
+@@ -629,9 +657,10 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
+     notmuch_query_t *query;\r
+     char *query_string;\r
+     int opt_index, ret = 0;\r
+-    int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_show_params_t *params);\r
++    int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_show_params_t *params, notmuch_bool_t reply_all);\r
+     notmuch_show_params_t params = { .part = -1 };\r
+     int format = FORMAT_DEFAULT;\r
++    int reply_all = TRUE;\r
+     notmuch_bool_t decrypt = FALSE;\r
\r
+     notmuch_opt_desc_t options[] = {\r
+@@ -639,6 +668,10 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
+         (notmuch_keyword_t []){ { "default", FORMAT_DEFAULT },\r
+                                 { "headers-only", FORMAT_HEADERS_ONLY },\r
+                                 { 0, 0 } } },\r
++      { NOTMUCH_OPT_KEYWORD, &reply_all, "reply-to", 'r',\r
++        (notmuch_keyword_t []){ { "all", TRUE },\r
++                                { "sender", FALSE },\r
++                                { 0, 0 } } },\r
+       { NOTMUCH_OPT_BOOLEAN, &decrypt, "decrypt", 'd', 0 },\r
+       { 0, 0, 0, 0, 0 }\r
+     };\r
+@@ -692,7 +725,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
+       return 1;\r
+     }\r
\r
+-    if (reply_format_func (ctx, config, query, &params) != 0)\r
++    if (reply_format_func (ctx, config, query, &params, reply_all) != 0)\r
+       return 1;\r
\r
+     notmuch_query_destroy (query);\r
+-- \r
+1.7.5.4\r
+\r