Re: [PATCH v4 2/5] cli: add support for replying just to the sender in "notmuch reply"
authorAustin Clements <amdragon@MIT.EDU>
Thu, 12 Jan 2012 22:02:51 +0000 (17:02 +1900)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:42:01 +0000 (09:42 -0800)
32/33b2956c4bbbf6a2e65566b0f82acfd3eadaf7 [new file with mode: 0644]

diff --git a/32/33b2956c4bbbf6a2e65566b0f82acfd3eadaf7 b/32/33b2956c4bbbf6a2e65566b0f82acfd3eadaf7
new file mode 100644 (file)
index 0000000..6e1fb02
--- /dev/null
@@ -0,0 +1,290 @@
+Return-Path: <amdragon@mit.edu>\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 EC9A3429E27\r
+       for <notmuch@notmuchmail.org>; Thu, 12 Jan 2012 14:02:51 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\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 0+r6ya1plusQ for <notmuch@notmuchmail.org>;\r
+       Thu, 12 Jan 2012 14:02:51 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-8.mit.edu (DMZ-MAILSEC-SCANNER-8.MIT.EDU\r
+       [18.7.68.37])\r
+       by olra.theworths.org (Postfix) with ESMTP id E22AC429E26\r
+       for <notmuch@notmuchmail.org>; Thu, 12 Jan 2012 14:02:50 -0800 (PST)\r
+X-AuditID: 12074425-b7f4a6d0000008e0-83-4f0f588abca6\r
+Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
+       by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id DB.DB.02272.A885F0F4; Thu, 12 Jan 2012 17:02:50 -0500 (EST)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+       by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q0CM2nuK016803; \r
+       Thu, 12 Jan 2012 17:02:49 -0500\r
+Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])\r
+       (authenticated bits=0)\r
+       (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+       by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q0CM2mT3023426\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Thu, 12 Jan 2012 17:02:49 -0500 (EST)\r
+Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1RlSjT-0006Xb-BY; Thu, 12 Jan 2012 17:02:51 -0500\r
+Date: Thu, 12 Jan 2012 17:02:51 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: Jani Nikula <jani@nikula.org>\r
+Subject: Re: [PATCH v4 2/5] cli: add support for replying just to the sender\r
+       in "notmuch reply"\r
+Message-ID: <20120112220251.GG18625@mit.edu>\r
+References: <cover.1325794371.git.jani@nikula.org>\r
+       <cover.1326403905.git.jani@nikula.org>\r
+       <9be66534c17fbffe00b0c1201f378e60fadd11d1.1326403905.git.jani@nikula.org>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+Content-Disposition: inline\r
+In-Reply-To:\r
+ <9be66534c17fbffe00b0c1201f378e60fadd11d1.1326403905.git.jani@nikula.org>\r
+User-Agent: Mutt/1.5.21 (2010-09-15)\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFuphleLIzCtJLcpLzFFi42IRYrdT1+2K4Pc32DhP1qJpurPF6rk8Ftdv\r
+       zmR2YPbYOesuu8et+6/ZPZ6tusUcwBzFZZOSmpNZllqkb5fAlbFu7gz2gj6nipuT/jI1MG4x\r
+       7mLk5JAQMJHYM3cDO4QtJnHh3nq2LkYuDiGBfYwSPU3fmSGcDYwSl4+cZAKpEhI4ySTx8W8G\r
+       RGIJo8Tbm1fZQBIsAqoSr56+ZAax2QQ0JLbtX84IYosIKEpsPrkfzGYWMJNYOfU72CBhgUSJ\r
+       3devgcV5BXQkNi1pY4QYupxRYvbNZywQCUGJkzOfsEA0a0nc+PcSqJkDyJaWWP6PAyTMKRAm\r
+       8eLnUbASUQEViSknt7FNYBSahaR7FpLuWQjdCxiZVzHKpuRW6eYmZuYUpybrFicn5uWlFula\r
+       6OVmluilppRuYgQHuovqDsYJh5QOMQpwMCrx8L4S5vcXYk0sK67MPcQoycGkJMrLCowTIb6k\r
+       /JTKjMTijPii0pzU4kOMEhzMSiK8MbpAOd6UxMqq1KJ8mJQ0B4uSOK+m1js/IYH0xJLU7NTU\r
+       gtQimKwMB4eSBO+ZcKBGwaLU9NSKtMycEoQ0EwcnyHAeoOHHQGp4iwsSc4sz0yHypxgVpcR5\r
+       r4MkBEASGaV5cL2wRPSKURzoFWHe4yBVPMAkBtf9CmgwE9DgshQ+kMEliQgpqQbGwy2V2Y9Z\r
+       k++y+jzpMGpzrOdeqHPZI/JfZoNJ8nLR+ENSFS49Scc3rLKPb585zfHjs46bffx7YpZErNnx\r
+       ePPcHPmYEMX23Qte2/GYnai8MOW9t+YRi1nzJ1tf5mRq+mFpk97gueyOjXKG9O/zV84vf6me\r
+       x/XzyLObpW/3Cxm22fokZkXGTjmhxFKckWioxVxUnAgAo7O54B8DAAA=\r
+Cc: notmuch@notmuchmail.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: Thu, 12 Jan 2012 22:02:52 -0000\r
+\r
+LGTM.  Again, one minor nit below, but not enough to hold up this\r
+patch.\r
+\r
+Quoth Jani Nikula on Jan 12 at 11:40 pm:\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          |   52 +++++++++++++++++++++++++++++++++++++--------\r
+>  2 files changed, 65 insertions(+), 15 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 4fae66f..b4c81de 100644\r
+> --- a/notmuch-reply.c\r
+> +++ b/notmuch-reply.c\r
+> @@ -289,7 +289,14 @@ 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:", "To:",\r
+> + * "Cc:", and "Bcc:" headers of 'message'.\r
+> + *\r
+> + * If 'reply_all' is true, use sender and all recipients, otherwise scan the\r
+> + * headers for the first that contains something other than the user's addresses\r
+> + * and add the recipients from this header (typically this would be\r
+> + * reply-to-sender, but also handles reply to user's own message in a sensible\r
+> + * way).\r
+\r
+Same comment about 80 column wrapping.\r
+\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
+> @@ -297,7 +304,8 @@ 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
+> +                         notmuch_bool_t reply_all)\r
+>  {\r
+>      struct {\r
+>      const char *header;\r
+> @@ -311,6 +319,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
+> @@ -337,8 +346,23 @@ 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 we have\r
+> +         * added some recipient(s) above.\r
+> +         *\r
+> +         * This also handles the case of user replying to his own message,\r
+> +         * where reply-to/from is not a recipient. In this case there may be\r
+> +         * more than one recipient even if 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
+Nifty.\r
+\r
+> +    }\r
+>      }\r
+>  \r
+>      return from_addr;\r
+> @@ -482,7 +506,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
+> @@ -511,7 +536,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
+> @@ -560,7 +586,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
+> @@ -600,7 +627,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
+> @@ -627,9 +654,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
+> @@ -637,6 +665,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
+> @@ -690,7 +722,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