From: Jani Nikula <jani@nikula.org>
To: notmuch@notmuchmail.org
Subject: [PATCH v4 2/5] cli: add support for replying just to the sender in "notmuch reply"
Date: Thu, 12 Jan 2012 23:40:16 +0200 [thread overview]
Message-ID: <9be66534c17fbffe00b0c1201f378e60fadd11d1.1326403905.git.jani@nikula.org> (raw)
In-Reply-To: <cover.1326403905.git.jani@nikula.org>
In-Reply-To: <cover.1326403905.git.jani@nikula.org>
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 <markwalters1009@gmail.com> 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 <jani@nikula.org>
---
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 | 52 +++++++++++++++++++++++++++++++++++++--------
2 files changed, 65 insertions(+), 15 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 <search-terms>.
diff --git a/notmuch-reply.c b/notmuch-reply.c
index 4fae66f..b4c81de 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -289,7 +289,14 @@ reply_to_header_is_redundant (notmuch_message_t *message)
return 0;
}
-/* Augments the recipients of reply from the headers of message.
+/* Augment the recipients of 'reply' from the "Reply-to:", "From:", "To:",
+ * "Cc:", and "Bcc:" headers of 'message'.
+ *
+ * If 'reply_all' is true, use sender and all recipients, otherwise scan the
+ * headers for the first that contains something other than the user's addresses
+ * and add the recipients from this header (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.
@@ -297,7 +304,8 @@ reply_to_header_is_redundant (notmuch_message_t *message)
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;
@@ -311,6 +319,7 @@ add_recipients_from_message (GMimeMessage *reply,
};
const char *from_addr = NULL;
unsigned int i;
+ unsigned int n = 0;
/* Some mailing lists munge the Reply-To header despite it being A Bad
* Thing, see http://www.unicom.com/pw/reply-to-harmful.html
@@ -337,8 +346,23 @@ add_recipients_from_message (GMimeMessage *reply,
recipients = notmuch_message_get_header (message,
reply_to_map[i].fallback);
- scan_address_string (recipients, config, reply,
- reply_to_map[i].recipient_type, &from_addr);
+ n += scan_address_string (recipients, config, reply,
+ reply_to_map[i].recipient_type, &from_addr);
+
+ if (!reply_all && n) {
+ /* 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.
+ */
+ reply = NULL;
+
+ /* From address and some recipients are enough, bail out. */
+ if (from_addr)
+ break;
+ }
}
return from_addr;
@@ -482,7 +506,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;
@@ -511,7 +536,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);
@@ -560,7 +586,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;
@@ -600,7 +627,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);
@@ -627,9 +654,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[] = {
@@ -637,6 +665,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 }
};
@@ -690,7 +722,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);
--
1.7.5.4
next prev parent reply other threads:[~2012-01-12 21:40 UTC|newest]
Thread overview: 81+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-05 20:25 [PATCH 0/4] notmuch reply bugfix & reply to sender only Jani Nikula
2012-01-05 20:25 ` [PATCH 1/4] cli: fix use of uninitialized variable in "notmuch reply" Jani Nikula
2012-01-06 3:22 ` David Bremner
2012-01-06 8:11 ` Jani Nikula
2012-01-06 11:57 ` David Bremner
2012-01-07 3:52 ` David Bremner
2012-01-07 7:31 ` Jani Nikula
2012-01-07 11:57 ` Mark Walters
2012-01-07 12:14 ` David Bremner
2012-01-05 20:25 ` [PATCH 2/4] cli: convert "notmuch reply" to use the new argument parser Jani Nikula
2012-01-05 20:25 ` [PATCH 3/4] cli: add support for replying just to the sender in "notmuch reply" Jani Nikula
2012-01-05 20:25 ` [PATCH 4/4] emacs: add support for replying just to the sender of messages and threads Jani Nikula
2012-01-05 20:33 ` [PATCH 0/4] notmuch reply bugfix & reply to sender only Jameson Graef Rollins
2012-01-07 19:25 ` Mueen Nawaz
2012-01-05 22:01 ` Mark Walters
2012-01-06 12:34 ` Jani Nikula
2012-01-06 13:32 ` Mark Walters
2012-01-06 13:34 ` [PATCH 1/4] Add the option "--reply-to" to notmuch reply Mark Walters
2012-01-08 12:47 ` Jani Nikula
2012-01-08 15:08 ` Mark Walters
2012-01-08 16:11 ` Jani Nikula
2012-01-06 13:34 ` [PATCH 2/4] Update the man page for notmuch-reply to give the syntax for the --reply-to option Mark Walters
2012-01-06 13:34 ` [PATCH 3/4] Emacs changes for reply-to-sender Mark Walters
2012-01-06 13:34 ` [PATCH 4/4] add tests " Mark Walters
2012-01-06 14:20 ` [PATCH 0/4] notmuch reply bugfix & reply to sender only Mark Walters
2012-01-06 0:01 ` Adam Wolfe Gordon
2012-01-06 22:11 ` Tomi Ollila
2012-01-06 8:54 ` David Edmondson
2012-01-08 21:48 ` [PATCH v2 0/6] reply to sender Jani Nikula
2012-01-09 8:22 ` David Edmondson
2012-01-09 18:55 ` Dmitry Kurochkin
2012-01-08 21:48 ` [PATCH v2 1/6] cli: fix use of uninitialized variable in "notmuch reply" Jani Nikula
2012-01-08 21:48 ` [PATCH v2 2/6] cli: convert "notmuch reply" to use the new argument parser Jani Nikula
2012-01-08 21:48 ` [PATCH v2 3/6] cli: add support for replying just to the sender in "notmuch reply" Jani Nikula
2012-01-08 23:23 ` Mark Walters
2012-01-09 9:41 ` Jani Nikula
2012-01-09 11:13 ` Mark Walters
2012-01-08 21:48 ` [PATCH v2 4/6] emacs: add support for replying just to the sender Jani Nikula
2012-01-08 21:48 ` [PATCH v2 5/6] emacs: bind 'r' to reply-to-sender and 'R' to reply-to-all Jani Nikula
2012-01-08 22:01 ` Jeremy Nickurak
2012-01-08 23:32 ` Jameson Graef Rollins
2012-01-08 23:56 ` Jeremy Nickurak
2012-01-09 14:10 ` is there a default reply function? (was: Re: [PATCH v2 5/6] emacs: bind 'r' to reply-to-sender and 'R' to reply-to-all) Gregor Zattler
2012-01-08 21:48 ` [PATCH v2 6/6] test: add tests for "notmuch reply" --reply-to=sender Jani Nikula
2012-01-10 19:54 ` [PATCH v3 0/4] reply to sender Jani Nikula
2012-01-10 19:54 ` [PATCH v3 1/4] cli: add support for replying just to the sender in "notmuch reply" Jani Nikula
2012-01-12 3:31 ` Austin Clements
2012-01-10 19:54 ` [PATCH v3 2/4] emacs: add support for replying just to the sender Jani Nikula
2012-01-11 8:20 ` David Edmondson
2012-01-11 8:45 ` Jani Nikula
2012-01-11 9:08 ` David Edmondson
2012-01-11 21:15 ` Aaron Ecay
2012-01-11 22:08 ` Jani Nikula
2012-01-10 19:54 ` [PATCH v3 3/4] emacs: bind 'r' to reply-to-sender and 'R' to reply-to-all Jani Nikula
2012-01-11 8:21 ` David Edmondson
2012-01-10 19:54 ` [PATCH v3 4/4] test: add tests for "notmuch reply" --reply-to=sender Jani Nikula
2012-01-12 3:50 ` Austin Clements
2012-01-12 12:59 ` Tomi Ollila
2012-01-12 21:40 ` [PATCH v4 0/5] reply to sender Jani Nikula
2012-01-12 21:40 ` [PATCH v4 1/5] cli: slightly refactor "notmuch reply" address scanning functions Jani Nikula
2012-01-12 21:59 ` Austin Clements
2012-01-14 14:22 ` Jani Nikula
2012-01-12 23:28 ` Mark Walters
2012-01-12 21:40 ` Jani Nikula [this message]
2012-01-12 22:02 ` [PATCH v4 2/5] cli: add support for replying just to the sender in "notmuch reply" Austin Clements
2012-01-12 23:46 ` Mark Walters
2012-01-12 21:40 ` [PATCH v4 3/5] emacs: add support for replying just to the sender Jani Nikula
2012-01-12 21:40 ` [PATCH v4 4/5] emacs: bind 'r' to reply-to-sender and 'R' to reply-to-all Jani Nikula
2012-01-12 21:40 ` [PATCH v4 5/5] test: add tests for "notmuch reply" --reply-to=sender Jani Nikula
2012-01-14 14:46 ` [PATCH v5 0/5] reply to sender Jani Nikula
2012-01-14 14:46 ` [PATCH v5 1/5] cli: slightly refactor "notmuch reply" address scanning functions Jani Nikula
2012-01-14 15:31 ` David Bremner
2012-01-14 16:48 ` Jani Nikula
2012-01-16 18:06 ` Dmitry Kurochkin
2012-01-16 18:40 ` David Edmondson
2012-01-16 19:26 ` David Bremner
2012-01-16 19:32 ` Jameson Graef Rollins
2012-01-14 14:46 ` [PATCH v5 2/5] cli: add support for replying just to the sender in "notmuch reply" Jani Nikula
2012-01-14 14:46 ` [PATCH v5 3/5] emacs: add support for replying just to the sender Jani Nikula
2012-01-14 14:46 ` [PATCH v5 4/5] emacs: bind 'r' to reply-to-sender and 'R' to reply-to-all Jani Nikula
2012-01-14 14:46 ` [PATCH v5 5/5] test: add tests for "notmuch reply" --reply-to=sender Jani Nikula
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9be66534c17fbffe00b0c1201f378e60fadd11d1.1326403905.git.jani@nikula.org \
--to=jani@nikula.org \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).