Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id F4063429E26 for ; Wed, 11 Jan 2012 19:31:44 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id K2lovlkmzSay for ; Wed, 11 Jan 2012 19:31:43 -0800 (PST) Received: from dmz-mailsec-scanner-7.mit.edu (DMZ-MAILSEC-SCANNER-7.MIT.EDU [18.7.68.36]) by olra.theworths.org (Postfix) with ESMTP id 70A14429E25 for ; Wed, 11 Jan 2012 19:31:43 -0800 (PST) X-AuditID: 12074424-b7fae6d000000906-71-4f0e541ed366 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39]) by dmz-mailsec-scanner-7.mit.edu (Symantec Messaging Gateway) with SMTP id CA.96.02310.E145E0F4; Wed, 11 Jan 2012 22:31:42 -0500 (EST) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q0C3VgC3005143; Wed, 11 Jan 2012 22:31:42 -0500 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q0C3VfCd012853 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Wed, 11 Jan 2012 22:31:42 -0500 (EST) Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77) (envelope-from ) id 1RlBOE-0004g9-O7; Wed, 11 Jan 2012 22:31:46 -0500 Date: Wed, 11 Jan 2012 22:31:46 -0500 From: Austin Clements To: Jani Nikula Subject: Re: [PATCH v3 1/4] cli: add support for replying just to the sender in "notmuch reply" Message-ID: <20120112033146.GU20796@mit.edu> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmphleLIzCtJLcpLzFFi42IRYrdT15UL4fM3uLfVyqJpurPF9ZszmR2Y PG7df83u8WzVLeYApigum5TUnMyy1CJ9uwSujMdzPjMVPE2r+L+7nbWBca1/FyMnh4SAicT0 C6dYIWwxiQv31rN1MXJxCAnsY5T4Nn0zM4SzgVFi9bZ5UM5JJokJl78wQjhLGCV6Z3Wyg/Sz CKhKNLV2MoLYbAIaEtv2LwezRQQUJTaf3A9mMwtIS3z73cwEYgsLJErMv/IULM4roCNx5Ndd JoihyxklFu+9wgaREJQ4OfMJC0SzlsSNfy+BijjABi3/xwES5hQIk1j2cBFYuaiAisSUk9vY JjAKzULSPQtJ9yyE7gWMzKsYZVNyq3RzEzNzilOTdYuTE/PyUot0zfVyM0v0UlNKNzGCA9tF ZQdj8yGlQ4wCHIxKPLw79vL6C7EmlhVX5h5ilORgUhLlXRbE5y/El5SfUpmRWJwRX1Sak1p8 iFGCg1lJhNepBqicNyWxsiq1KB8mJc3BoiTOq6H1zk9IID2xJDU7NbUgtQgmK8PBoSTBOzMY aKhgUWp6akVaZk4JQpqJgxNkOA/Q8BCQGt7igsTc4sx0iPwpRkUpcd5ckIQASCKjNA+uF5Z4 XjGKA70izDsdpIoHmLTgul8BDWYCGrxlHQ/I4JJEhJRUA+O+N3selmdmiP41l7I9GLiitkLr w6OEmwcCFT6E/gjabaDw62zKMfbbp1dExi/a9bCngH1Bk5CS8ePDXwX0G19Nu3XqqIRGRYc8 6/wTPHevPdcxsmtSNr3cvuvjrP+l0/5MLm7rzW8wlZbMWt24fXNHocHGon8Xj7PErzw/ebHz komsmaK7t3QosRRnJBpqMRcVJwIAPCqbnhcDAAA= Cc: notmuch@notmuchmail.org X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Jan 2012 03:31:45 -0000 Quoth Jani Nikula on Jan 10 at 9:54 pm: > Add new option --reply-to=(all|sender) to "notmuch reply" to select whether > to reply to all (sender and all recipients), or just sender. Reply to all > remains the default. > > Credits to Mark Walters for his similar earlier > work where I picked up the basic idea of handling reply-to-sender in > add_recipients_from_message(). All bugs are mine, though. > > Signed-off-by: Jani Nikula > > --- > > Settled on --reply-to=(all|sender) per Carl's earlier suggestion > (id:87pqn5cg4g.fsf@yoom.home.cworth.org) and David's approval on IRC. > --- > man/man1/notmuch-reply.1 | 28 +++++++++++++++--- > notmuch-reply.c | 70 ++++++++++++++++++++++++++++++++++----------- > 2 files changed, 76 insertions(+), 22 deletions(-) > > diff --git a/man/man1/notmuch-reply.1 b/man/man1/notmuch-reply.1 > index db464d8..5160ece 100644 > --- a/man/man1/notmuch-reply.1 > +++ b/man/man1/notmuch-reply.1 > @@ -14,11 +14,13 @@ Constructs a reply template for a set of messages. > To make replying to email easier, > .B notmuch reply > takes an existing set of messages and constructs a suitable mail > -template. The Reply-to header (if any, otherwise From:) is used for > -the To: address. Vales from the To: and Cc: headers are copied, but > -not including any of the current user's email addresses (as configured > -in primary_mail or other_email in the .notmuch\-config file) in the > -recipient list > +template. The Reply-to: header (if any, otherwise From:) is used for > +the To: address. Unless > +.BR \-\-reply-to=sender > +is specified, values from the To: and Cc: headers are copied, but not > +including any of the current user's email addresses (as configured in > +primary_mail or other_email in the .notmuch\-config file) in the > +recipient list. > > It also builds a suitable new subject, including Re: at the front (if > not already present), and adding the message IDs of the messages being > @@ -45,6 +47,22 @@ Includes subject and quoted message body. > Only produces In\-Reply\-To, References, To, Cc, and Bcc headers. > .RE > .RE > +.RS > +.TP 4 > +.BR \-\-reply\-to= ( all | sender ) > +.RS > +.TP 4 > +.BR all " (default)" > +Replies to all addresses. > +.TP 4 > +.BR sender > +Replies only to the sender. If replying to user's own message > +(Reply-to: or From: header is one of the user's configured email > +addresses), try To:, Cc:, and Bcc: headers in this order, and copy > +values from the first that contains something other than only the > +user's addresses. > +.RE > +.RE > > See \fBnotmuch-search-terms\fR(7) > for details of the supported syntax for . > diff --git a/notmuch-reply.c b/notmuch-reply.c > index 000f6da..7b785a7 100644 > --- a/notmuch-reply.c > +++ b/notmuch-reply.c > @@ -170,7 +170,7 @@ address_is_users (const char *address, notmuch_config_t *config) > > /* For each address in 'list' that is not configured as one of the > * user's addresses in 'config', add that address to 'message' as an > - * address of 'type'. > + * address of 'type', if 'add' is true. I puzzled over this for a while before I figured out what was actually going on here. I was confused because this comment makes it sound like this function doesn't do what its name says if 'add' is false. And, in fact, it doesn't! I understand from an evolutionary standpoint why the code works this way, but at the very least, I think the comment should call out this peculiarity. Better might be to rename the function, since it's now more general purpose than adding recipients for an address list, and possibly change its API slightly to reflect its generality. Off the top of my head, I'm thinking something like /* Scan address list 'list'. * * If 'add' is non-NULL, then for each address in 'list' that is not * configured as one of the user's addresses in 'config', add that * address to 'message' as an address of 'type'. If any addresses are * added, set *added_ret to TRUE. * * If one of the user's addresses is encountered in 'list' and * *user_addr_ret is not NULL, set *user_addr_ret to this address. */ static void scan_address_list (InternetAddressList *list, notmuch_config_t *config, GMimeMessage *add, GMimeRecipientType add_type, notmuch_bool_t *added_ret, const char **user_addr_ret) (The reason for added_ret is below.) This would barely change the code (in fact, it would simplify the handling of from_addr), but I think it would make the function less misleading. > * > * The first address encountered that *is* the user's address will be > * returned, (otherwise NULL is returned). > @@ -179,7 +179,8 @@ static const char * > add_recipients_for_address_list (GMimeMessage *message, > notmuch_config_t *config, > GMimeRecipientType type, > - InternetAddressList *list) > + InternetAddressList *list, > + notmuch_bool_t add) > { > InternetAddress *address; > int i; > @@ -197,7 +198,7 @@ add_recipients_for_address_list (GMimeMessage *message, > continue; > > add_recipients_for_address_list (message, config, > - type, group_list); > + type, group_list, add); > } else { > InternetAddressMailbox *mailbox; > const char *name; > @@ -211,7 +212,7 @@ add_recipients_for_address_list (GMimeMessage *message, > if (address_is_users (addr, config)) { > if (ret == NULL) > ret = addr; > - } else { > + } else if (add) { > g_mime_message_add_recipient (message, type, name, addr); > } > } > @@ -222,7 +223,7 @@ add_recipients_for_address_list (GMimeMessage *message, > > /* For each address in 'recipients' that is not configured as one of > * the user's addresses in 'config', add that address to 'message' as > - * an address of 'type'. > + * an address of 'type', if 'add' is true. > * > * The first address encountered that *is* the user's address will be > * returned, (otherwise NULL is returned). > @@ -231,7 +232,8 @@ static const char * > add_recipients_for_string (GMimeMessage *message, > notmuch_config_t *config, > GMimeRecipientType type, > - const char *recipients) > + const char *recipients, > + notmuch_bool_t add) > { > InternetAddressList *list; > > @@ -242,7 +244,7 @@ add_recipients_for_string (GMimeMessage *message, > if (list == NULL) > return NULL; > > - return add_recipients_for_address_list (message, config, type, list); > + return add_recipients_for_address_list (message, config, type, list, add); > } > > /* Does the address in the Reply-To header of 'message' already appear > @@ -286,13 +288,19 @@ reply_to_header_is_redundant (notmuch_message_t *message) > > /* Augments the recipients of reply from the headers of message. > * > + * If 'reply_all' is true, use sender and all recipients, otherwise use the > + * first header that contains something other than the user's addresses Since there's no context here, perhaps you could elaborate on "first header"? Maybe ".. otherwise scan the reply-to, from, to, cc, and bcc headers for the first that contains something other than the user's addresses and add the recipients from this header (typically ..". > + * (typically this would be reply-to-sender, but also handles reply to user's > + * own message in a sensible way). > + * > * If any of the user's addresses were found in these headers, the first > * of these returned, otherwise NULL is returned. > */ > static const char * > add_recipients_from_message (GMimeMessage *reply, > notmuch_config_t *config, > - notmuch_message_t *message) > + notmuch_message_t *message, > + notmuch_bool_t reply_all) > { > struct { > const char *header; > @@ -305,6 +313,7 @@ add_recipients_from_message (GMimeMessage *reply, > { "bcc", NULL, GMIME_RECIPIENT_TYPE_BCC } > }; > const char *from_addr = NULL; > + notmuch_bool_t add_recipients = TRUE; > unsigned int i; > > /* Some mailing lists munge the Reply-To header despite it being A Bad > @@ -325,6 +334,7 @@ add_recipients_from_message (GMimeMessage *reply, > > for (i = 0; i < ARRAY_SIZE (reply_to_map); i++) { > const char *addr, *recipients; > + GMimeRecipientType recipient_type = reply_to_map[i].recipient_type; > > recipients = notmuch_message_get_header (message, > reply_to_map[i].header); > @@ -332,11 +342,29 @@ add_recipients_from_message (GMimeMessage *reply, > recipients = notmuch_message_get_header (message, > reply_to_map[i].fallback); > > - addr = add_recipients_for_string (reply, config, > - reply_to_map[i].recipient_type, > - recipients); > + addr = add_recipients_for_string (reply, config, recipient_type, > + recipients, add_recipients); > + > if (from_addr == NULL) > from_addr = addr; > + > + if (!reply_all) { > + /* Stop adding new recipients in reply-to-sender mode if we have > + * added some recipient(s) above. > + * > + * This also handles the case of user replying to his own message, > + * where reply-to/from is not a recipient. In this case there may be > + * more than one recipient even if not replying to all. > + */ > + InternetAddressList *list; > + list = g_mime_message_get_recipients (reply, recipient_type); > + if (list && internet_address_list_length (list)) > + add_recipients = FALSE; Is this different from just determining if add_recipients_for_string added anything? If not, maybe add_recipients_for_string (or scan_address_list) could simply return whether or not it added any recipients. > + > + /* Check if we've got a from address and all recipients we need. */ > + if (!add_recipients && from_addr) > + break; > + } > } > > return from_addr; > @@ -480,7 +508,8 @@ static int > notmuch_reply_format_default(void *ctx, > notmuch_config_t *config, > notmuch_query_t *query, > - notmuch_show_params_t *params) > + notmuch_show_params_t *params, > + notmuch_bool_t reply_all) > { > GMimeMessage *reply; > notmuch_messages_t *messages; > @@ -509,7 +538,8 @@ notmuch_reply_format_default(void *ctx, > g_mime_message_set_subject (reply, subject); > } > > - from_addr = add_recipients_from_message (reply, config, message); > + from_addr = add_recipients_from_message (reply, config, message, > + reply_all); > > if (from_addr == NULL) > from_addr = guess_from_received_header (config, message); > @@ -558,7 +588,8 @@ static int > notmuch_reply_format_headers_only(void *ctx, > notmuch_config_t *config, > notmuch_query_t *query, > - unused (notmuch_show_params_t *params)) > + unused (notmuch_show_params_t *params), > + notmuch_bool_t reply_all) > { > GMimeMessage *reply; > notmuch_messages_t *messages; > @@ -598,7 +629,7 @@ notmuch_reply_format_headers_only(void *ctx, > g_mime_object_set_header (GMIME_OBJECT (reply), > "References", references); > > - (void)add_recipients_from_message (reply, config, message); > + (void)add_recipients_from_message (reply, config, message, reply_all); > > reply_headers = g_mime_object_to_string (GMIME_OBJECT (reply)); > printf ("%s", reply_headers); > @@ -625,9 +656,10 @@ notmuch_reply_command (void *ctx, int argc, char *argv[]) > notmuch_query_t *query; > char *query_string; > int opt_index, ret = 0; > - int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_show_params_t *params); > + int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_show_params_t *params, notmuch_bool_t reply_all); > notmuch_show_params_t params = { .part = -1 }; > int format = FORMAT_DEFAULT; > + int reply_all = TRUE; > notmuch_bool_t decrypt = FALSE; > > notmuch_opt_desc_t options[] = { > @@ -635,6 +667,10 @@ notmuch_reply_command (void *ctx, int argc, char *argv[]) > (notmuch_keyword_t []){ { "default", FORMAT_DEFAULT }, > { "headers-only", FORMAT_HEADERS_ONLY }, > { 0, 0 } } }, > + { NOTMUCH_OPT_KEYWORD, &reply_all, "reply-to", 'r', > + (notmuch_keyword_t []){ { "all", TRUE }, > + { "sender", FALSE }, > + { 0, 0 } } }, > { NOTMUCH_OPT_BOOLEAN, &decrypt, "decrypt", 'd', 0 }, > { 0, 0, 0, 0, 0 } > }; > @@ -688,7 +724,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[]) > return 1; > } > > - if (reply_format_func (ctx, config, query, ¶ms) != 0) > + if (reply_format_func (ctx, config, query, ¶ms, reply_all) != 0) > return 1; > > notmuch_query_destroy (query);