unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Mark Walters <markwalters1009@gmail.com>
To: notmuch@notmuchmail.org
Subject: [PATCH 1/2] Command line changes for reply-to-sender
Date: Thu, 26 May 2011 17:06:51 +0100	[thread overview]
Message-ID: <1306426012-8176-2-git-send-email-markwalters1009@gmail.com> (raw)
In-Reply-To: <1306426012-8176-1-git-send-email-markwalters1009@gmail.com>

Adds the format "--format=one" to possible reply formats which only
replies to the sender.

More precisely the function follows these rules:
reply only to sender unless it was the user
reply only to all people on the to line unless they were all the user
reply to all people on the cc line

The most common expected case is we just reply to sender, but if we reply to
our own email then we reply to the whole to line.

Implementation details

Note we continue parsing addresses beyond the ones we reply to because
we want to make sure the from address is correct. (At the very least it
is the same as it would be if we replied to all.)

We overload the message variable in add_recipients_for_address_list so
if it is NULL we parse the address (looking for the users address)
but do not add to the message recipients list

We add the variable reply_to_all to the function chain to keep track
of whether we should reply to everyone.
---
 notmuch-reply.c |   38 +++++++++++++++++++++++++++-----------
 1 files changed, 27 insertions(+), 11 deletions(-)

diff --git a/notmuch-reply.c b/notmuch-reply.c
index ab15650..3df3b52 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -191,7 +191,8 @@ add_recipients_for_address_list (GMimeMessage *message,
 		if (ret == NULL)
 		    ret = addr;
 	    } else {
-		g_mime_message_add_recipient (message, type, name, addr);
+		 if (message) 
+		      g_mime_message_add_recipient (message, type, name, addr);
 	    }
 	}
     }
@@ -271,7 +272,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,
+			     int reply_to_all)
 {
     struct {
 	const char *header;
@@ -311,9 +313,20 @@ 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);
+
+	/* We add the addresses if we are replying to all or we have not yet found
+	 * a non-user address. We have to keep parsing to make sure we do find the 
+	 * correct from address for the user, but we pass a NULL message
+	 */
+	if ((reply_to_all) || (g_mime_message_get_all_recipients (reply) == NULL))
+	    addr = add_recipients_for_string (reply, config,
+					      reply_to_map[i].recipient_type,
+					      recipients);
+	else
+	     addr = add_recipients_for_string (NULL, config,
+					       reply_to_map[i].recipient_type,
+					       recipients);
+
 	if (from_addr == NULL)
 	    from_addr = addr;
     }
@@ -453,7 +466,7 @@ guess_from_received_header (notmuch_config_t *config, notmuch_message_t *message
 }
 
 static int
-notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_t *query)
+notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_t *query, int reply_to_all)
 {
     GMimeMessage *reply;
     notmuch_messages_t *messages;
@@ -484,7 +497,7 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_
 	    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_to_all);
 
 	if (from_addr == NULL)
 	    from_addr = guess_from_received_header (config, message);
@@ -531,7 +544,7 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_
 
 /* This format is currently tuned for a git send-email --notmuch hook */
 static int
-notmuch_reply_format_headers_only(void *ctx, notmuch_config_t *config, notmuch_query_t *query)
+notmuch_reply_format_headers_only(void *ctx, notmuch_config_t *config, notmuch_query_t *query, int reply_to_all)
 {
     GMimeMessage *reply;
     notmuch_messages_t *messages;
@@ -571,7 +584,7 @@ notmuch_reply_format_headers_only(void *ctx, notmuch_config_t *config, notmuch_q
 	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_to_all);
 
 	reply_headers = g_mime_object_to_string (GMIME_OBJECT (reply));
 	printf ("%s", reply_headers);
@@ -593,7 +606,8 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
     notmuch_query_t *query;
     char *opt, *query_string;
     int i, ret = 0;
-    int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query);
+    int reply_to_all = 1;
+    int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, int reply_to_all);
 
     reply_format_func = notmuch_reply_format_default;
 
@@ -608,6 +622,8 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
 		reply_format_func = notmuch_reply_format_default;
 	    } else if (strcmp (opt, "headers-only") == 0) {
 		reply_format_func = notmuch_reply_format_headers_only;
+	    } else if (strcmp (opt, "one") == 0) {
+		reply_to_all = 0;
 	    } else {
 		fprintf (stderr, "Invalid value for --format: %s\n", opt);
 		return 1;
@@ -647,7 +663,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
 	return 1;
     }
 
-    if (reply_format_func (ctx, config, query) != 0)
+    if (reply_format_func (ctx, config, query, reply_to_all) != 0)
 	return 1;
 
     notmuch_query_destroy (query);
-- 
1.7.2.5

  reply	other threads:[~2011-05-26 16:07 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-26 16:06 [PATCH 0/2] Implement reply to sender Mark Walters
2011-05-26 16:06 ` Mark Walters [this message]
2011-05-26 16:06 ` [PATCH 2/2] Emacs changes for " Mark Walters
2011-05-26 21:21 ` [PATCH 0/2] Implement " Carl Worth
2011-05-26 23:31   ` [PATCH v2 0/3] " Mark Walters
2011-05-26 23:31   ` [PATCH v2 1/3] Adds the option "--reply-to=" to notmuch reply Mark Walters
2011-05-26 23:31   ` [PATCH v2 2/3] Documentation changes for --reply-to= option " Mark Walters
2011-05-26 23:31   ` [PATCH v2 3/3] Emacs changes for reply to sender Mark Walters

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=1306426012-8176-2-git-send-email-markwalters1009@gmail.com \
    --to=markwalters1009@gmail.com \
    --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).