Re: [PATCH v3 1/4] cli: add support for replying just to the sender in "notmuch reply"
authorAustin Clements <amdragon@MIT.EDU>
Thu, 12 Jan 2012 03:31:46 +0000 (22:31 +1900)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:41:56 +0000 (09:41 -0800)
71/a52984f9353c127c43c002d53ab8ac1f362a1f [new file with mode: 0644]

diff --git a/71/a52984f9353c127c43c002d53ab8ac1f362a1f b/71/a52984f9353c127c43c002d53ab8ac1f362a1f
new file mode 100644 (file)
index 0000000..6aa700c
--- /dev/null
@@ -0,0 +1,402 @@
+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 F4063429E26\r
+       for <notmuch@notmuchmail.org>; Wed, 11 Jan 2012 19:31:44 -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 K2lovlkmzSay for <notmuch@notmuchmail.org>;\r
+       Wed, 11 Jan 2012 19:31:43 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-7.mit.edu (DMZ-MAILSEC-SCANNER-7.MIT.EDU\r
+       [18.7.68.36])\r
+       by olra.theworths.org (Postfix) with ESMTP id 70A14429E25\r
+       for <notmuch@notmuchmail.org>; Wed, 11 Jan 2012 19:31:43 -0800 (PST)\r
+X-AuditID: 12074424-b7fae6d000000906-71-4f0e541ed366\r
+Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
+       by dmz-mailsec-scanner-7.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id CA.96.02310.E145E0F4; Wed, 11 Jan 2012 22:31:42 -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 q0C3VgC3005143; \r
+       Wed, 11 Jan 2012 22:31:42 -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 q0C3VfCd012853\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Wed, 11 Jan 2012 22:31:42 -0500 (EST)\r
+Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1RlBOE-0004g9-O7; Wed, 11 Jan 2012 22:31:46 -0500\r
+Date: Wed, 11 Jan 2012 22:31:46 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: Jani Nikula <jani@nikula.org>\r
+Subject: Re: [PATCH v3 1/4] cli: add support for replying just to the sender\r
+       in "notmuch reply"\r
+Message-ID: <20120112033146.GU20796@mit.edu>\r
+References: <cover.1325794371.git.jani@nikula.org>\r
+       <cover.1326224339.git.jani@nikula.org>\r
+       <d32e63c8115b1f2868acf96c83b30697be88ff10.1326224339.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
+ <d32e63c8115b1f2868acf96c83b30697be88ff10.1326224339.git.jani@nikula.org>\r
+User-Agent: Mutt/1.5.21 (2010-09-15)\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFmphleLIzCtJLcpLzFFi42IRYrdT15UL4fM3uLfVyqJpurPF9ZszmR2Y\r
+       PG7df83u8WzVLeYApigum5TUnMyy1CJ9uwSujMdzPjMVPE2r+L+7nbWBca1/FyMnh4SAicT0\r
+       C6dYIWwxiQv31rN1MXJxCAnsY5T4Nn0zM4SzgVFi9bZ5UM5JJokJl78wQjhLGCV6Z3Wyg/Sz\r
+       CKhKNLV2MoLYbAIaEtv2LwezRQQUJTaf3A9mMwtIS3z73cwEYgsLJErMv/IULM4roCNx5Ndd\r
+       JoihyxklFu+9wgaREJQ4OfMJC0SzlsSNfy+BijjABi3/xwES5hQIk1j2cBFYuaiAisSUk9vY\r
+       JjAKzULSPQtJ9yyE7gWMzKsYZVNyq3RzEzNzilOTdYuTE/PyUot0zfVyM0v0UlNKNzGCA9tF\r
+       ZQdj8yGlQ4wCHIxKPLw79vL6C7EmlhVX5h5ilORgUhLlXRbE5y/El5SfUpmRWJwRX1Sak1p8\r
+       iFGCg1lJhNepBqicNyWxsiq1KB8mJc3BoiTOq6H1zk9IID2xJDU7NbUgtQgmK8PBoSTBOzMY\r
+       aKhgUWp6akVaZk4JQpqJgxNkOA/Q8BCQGt7igsTc4sx0iPwpRkUpcd5ckIQASCKjNA+uF5Z4\r
+       XjGKA70izDsdpIoHmLTgul8BDWYCGrxlHQ/I4JJEhJRUA+O+N3selmdmiP41l7I9GLiitkLr\r
+       w6OEmwcCFT6E/gjabaDw62zKMfbbp1dExi/a9bCngH1Bk5CS8ePDXwX0G19Nu3XqqIRGRYc8\r
+       6/wTPHevPdcxsmtSNr3cvuvjrP+l0/5MLm7rzW8wlZbMWt24fXNHocHGon8Xj7PErzw/ebHz\r
+       komsmaK7t3QosRRnJBpqMRcVJwIAPCqbnhcDAAA=\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 03:31:45 -0000\r
+\r
+Quoth Jani Nikula on Jan 10 at  9:54 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          |   70 ++++++++++++++++++++++++++++++++++-----------\r
+>  2 files changed, 76 insertions(+), 22 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 000f6da..7b785a7 100644\r
+> --- a/notmuch-reply.c\r
+> +++ b/notmuch-reply.c\r
+> @@ -170,7 +170,7 @@ address_is_users (const char *address, notmuch_config_t *config)\r
+>  \r
+>  /* For each address in 'list' that is not configured as one of the\r
+>   * user's addresses in 'config', add that address to 'message' as an\r
+> - * address of 'type'.\r
+> + * address of 'type', if 'add' is true.\r
+\r
+I puzzled over this for a while before I figured out what was actually\r
+going on here.  I was confused because this comment makes it sound\r
+like this function doesn't do what its name says if 'add' is false.\r
+And, in fact, it doesn't!\r
+\r
+I understand from an evolutionary standpoint why the code works this\r
+way, but at the very least, I think the comment should call out this\r
+peculiarity.  Better might be to rename the function, since it's now\r
+more general purpose than adding recipients for an address list, and\r
+possibly change its API slightly to reflect its generality.  Off the\r
+top of my head, I'm thinking something like\r
+\r
+/* Scan address list 'list'.\r
+ *\r
+ * If 'add' is non-NULL, then for each address in 'list' that is not\r
+ * configured as one of the user's addresses in 'config', add that\r
+ * address to 'message' as an address of 'type'.  If any addresses are\r
+ * added, set *added_ret to TRUE.\r
+ *\r
+ * If one of the user's addresses is encountered in 'list' and\r
+ * *user_addr_ret is not NULL, set *user_addr_ret to this address.\r
+ */\r
+static void\r
+scan_address_list (InternetAddressList *list,\r
+                   notmuch_config_t *config,\r
+                   GMimeMessage *add, GMimeRecipientType add_type,\r
+                   notmuch_bool_t *added_ret,\r
+                   const char **user_addr_ret)\r
+\r
+(The reason for added_ret is below.)  This would barely change the\r
+code (in fact, it would simplify the handling of from_addr), but I\r
+think it would make the function less misleading.\r
+\r
+>   *\r
+>   * The first address encountered that *is* the user's address will be\r
+>   * returned, (otherwise NULL is returned).\r
+> @@ -179,7 +179,8 @@ static const char *\r
+>  add_recipients_for_address_list (GMimeMessage *message,\r
+>                               notmuch_config_t *config,\r
+>                               GMimeRecipientType type,\r
+> -                             InternetAddressList *list)\r
+> +                             InternetAddressList *list,\r
+> +                             notmuch_bool_t add)\r
+>  {\r
+>      InternetAddress *address;\r
+>      int i;\r
+> @@ -197,7 +198,7 @@ add_recipients_for_address_list (GMimeMessage *message,\r
+>              continue;\r
+>  \r
+>          add_recipients_for_address_list (message, config,\r
+> -                                         type, group_list);\r
+> +                                         type, group_list, add);\r
+>      } else {\r
+>          InternetAddressMailbox *mailbox;\r
+>          const char *name;\r
+> @@ -211,7 +212,7 @@ add_recipients_for_address_list (GMimeMessage *message,\r
+>          if (address_is_users (addr, config)) {\r
+>              if (ret == NULL)\r
+>                  ret = addr;\r
+> -        } else {\r
+> +        } else if (add) {\r
+>              g_mime_message_add_recipient (message, type, name, addr);\r
+>          }\r
+>      }\r
+> @@ -222,7 +223,7 @@ add_recipients_for_address_list (GMimeMessage *message,\r
+>  \r
+>  /* For each address in 'recipients' that is not configured as one of\r
+>   * the user's addresses in 'config', add that address to 'message' as\r
+> - * an address of 'type'.\r
+> + * an address of 'type', if 'add' is true.\r
+>   *\r
+>   * The first address encountered that *is* the user's address will be\r
+>   * returned, (otherwise NULL is returned).\r
+> @@ -231,7 +232,8 @@ static const char *\r
+>  add_recipients_for_string (GMimeMessage *message,\r
+>                         notmuch_config_t *config,\r
+>                         GMimeRecipientType type,\r
+> -                       const char *recipients)\r
+> +                       const char *recipients,\r
+> +                       notmuch_bool_t add)\r
+>  {\r
+>      InternetAddressList *list;\r
+>  \r
+> @@ -242,7 +244,7 @@ add_recipients_for_string (GMimeMessage *message,\r
+>      if (list == NULL)\r
+>      return NULL;\r
+>  \r
+> -    return add_recipients_for_address_list (message, config, type, list);\r
+> +    return add_recipients_for_address_list (message, config, type, list, add);\r
+>  }\r
+>  \r
+>  /* Does the address in the Reply-To header of 'message' already appear\r
+> @@ -286,13 +288,19 @@ reply_to_header_is_redundant (notmuch_message_t *message)\r
+>  \r
+>  /* Augments the recipients of reply from the headers of message.\r
+>   *\r
+> + * If 'reply_all' is true, use sender and all recipients, otherwise use the\r
+> + * first header that contains something other than the user's addresses\r
+\r
+Since there's no context here, perhaps you could elaborate on "first\r
+header"?  Maybe ".. otherwise scan the reply-to, from, to, cc, and bcc\r
+headers for the first that contains something other than the user's\r
+addresses and add the recipients from this header (typically ..".\r
+\r
+> + * (typically this would be reply-to-sender, but also handles reply to user's\r
+> + * own message in a sensible way).\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
+>   */\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
+> @@ -305,6 +313,7 @@ add_recipients_from_message (GMimeMessage *reply,\r
+>      { "bcc",        NULL, GMIME_RECIPIENT_TYPE_BCC }\r
+>      };\r
+>      const char *from_addr = NULL;\r
+> +    notmuch_bool_t add_recipients = TRUE;\r
+>      unsigned int i;\r
+>  \r
+>      /* Some mailing lists munge the Reply-To header despite it being A Bad\r
+> @@ -325,6 +334,7 @@ add_recipients_from_message (GMimeMessage *reply,\r
+>  \r
+>      for (i = 0; i < ARRAY_SIZE (reply_to_map); i++) {\r
+>      const char *addr, *recipients;\r
+> +    GMimeRecipientType recipient_type = reply_to_map[i].recipient_type;\r
+>  \r
+>      recipients = notmuch_message_get_header (message,\r
+>                                               reply_to_map[i].header);\r
+> @@ -332,11 +342,29 @@ add_recipients_from_message (GMimeMessage *reply,\r
+>          recipients = notmuch_message_get_header (message,\r
+>                                                   reply_to_map[i].fallback);\r
+>  \r
+> -    addr = add_recipients_for_string (reply, config,\r
+> -                                      reply_to_map[i].recipient_type,\r
+> -                                      recipients);\r
+> +    addr = add_recipients_for_string (reply, config, recipient_type,\r
+> +                                      recipients, add_recipients);\r
+> +\r
+>      if (from_addr == NULL)\r
+>          from_addr = addr;\r
+> +\r
+> +    if (!reply_all) {\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
+> +        InternetAddressList *list;\r
+> +        list = g_mime_message_get_recipients (reply, recipient_type);\r
+> +        if (list && internet_address_list_length (list))\r
+> +            add_recipients = FALSE;\r
+\r
+Is this different from just determining if add_recipients_for_string\r
+added anything?  If not, maybe add_recipients_for_string (or\r
+scan_address_list) could simply return whether or not it added any\r
+recipients.\r
+\r
+> +\r
+> +        /* Check if we've got a from address and all recipients we need. */\r
+> +        if (!add_recipients && from_addr)\r
+> +            break;\r
+> +    }\r
+>      }\r
+>  \r
+>      return from_addr;\r
+> @@ -480,7 +508,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
+> @@ -509,7 +538,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
+> @@ -558,7 +588,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
+> @@ -598,7 +629,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
+> @@ -625,9 +656,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
+> @@ -635,6 +667,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
+> @@ -688,7 +724,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