unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH 1/2] notmuch-reply: Add support for replying only to sender
@ 2009-12-03  8:46 Aneesh Kumar K.V
  2009-12-03  8:46 ` [PATCH 2/2] notmuch.el: Add support for reply-to sender Aneesh Kumar K.V
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Aneesh Kumar K.V @ 2009-12-03  8:46 UTC (permalink / raw)
  To: cworth, aneesh.kumar; +Cc: Aneesh Kumar K.V, notmuch

From: Aneesh Kumar K.V <aneesh.kumar@gmail.com>

This patch add --format=sender-only option.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@gmail.com>
---
 notmuch-reply.c |   76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 76 insertions(+), 0 deletions(-)

diff --git a/notmuch-reply.c b/notmuch-reply.c
index 9ca1236..9d96ef1 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -354,6 +354,80 @@ notmuch_reply_format_headers_only(void *ctx, notmuch_config_t *config, notmuch_q
     }
     return 0;
 }
+static int
+notmuch_reply_format_sender_only(void *ctx, notmuch_config_t *config, notmuch_query_t *query)
+{
+    GMimeMessage *reply;
+    notmuch_messages_t *messages;
+    notmuch_message_t *message;
+    const char *subject, *recipient, *from_addr = NULL;
+    const char *in_reply_to, *orig_references, *references;
+    char *reply_headers;
+
+    for (messages = notmuch_query_search_messages (query);
+	 notmuch_messages_has_more (messages);
+	 notmuch_messages_advance (messages))
+    {
+	message = notmuch_messages_get (messages);
+
+	/* The 1 means we want headers in a "pretty" order. */
+	reply = g_mime_message_new (1);
+	if (reply == NULL) {
+	    fprintf (stderr, "Out of memory\n");
+	    return 1;
+	}
+
+	subject = notmuch_message_get_header (message, "subject");
+
+	if (strncasecmp (subject, "Re:", 3))
+	    subject = talloc_asprintf (ctx, "Re: %s", subject);
+	g_mime_message_set_subject (reply, subject);
+
+	recipient = notmuch_message_get_header (message, "From");
+	g_mime_object_set_header (GMIME_OBJECT (reply),
+					"To", recipient);
+
+	from_addr = notmuch_config_get_user_primary_email (config);
+	from_addr = talloc_asprintf (ctx, "%s <%s>",
+				     notmuch_config_get_user_name (config),
+				     from_addr);
+	g_mime_object_set_header (GMIME_OBJECT (reply),
+				  "From", from_addr);
+
+	g_mime_object_set_header (GMIME_OBJECT (reply), "Bcc",
+			   notmuch_config_get_user_primary_email (config));
+
+	in_reply_to = talloc_asprintf (ctx, "<%s>",
+			     notmuch_message_get_message_id (message));
+
+	g_mime_object_set_header (GMIME_OBJECT (reply),
+				  "In-Reply-To", in_reply_to);
+
+	orig_references = notmuch_message_get_header (message, "references");
+	references = talloc_asprintf (ctx, "%s%s%s",
+				      orig_references ? orig_references : "",
+				      orig_references ? " " : "",
+				      in_reply_to);
+	g_mime_object_set_header (GMIME_OBJECT (reply),
+				  "References", references);
+
+	reply_headers = g_mime_object_to_string (GMIME_OBJECT (reply));
+	printf ("%s", reply_headers);
+	free (reply_headers);
+
+	g_object_unref (G_OBJECT (reply));
+	reply = NULL;
+
+	printf ("On %s, %s wrote:\n",
+		notmuch_message_get_header (message, "date"),
+		notmuch_message_get_header (message, "from"));
+
+	show_message_body (notmuch_message_get_filename (message), reply_part);
+
+	notmuch_message_destroy (message);
+    }
+    return 0;
+}
 
 int
 notmuch_reply_command (void *ctx, int argc, char *argv[])
@@ -378,6 +452,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, "sender-only") == 0) {
+		reply_format_func = notmuch_reply_format_sender_only;
 	    } else {
 		fprintf (stderr, "Invalid value for --format: %s\n", opt);
 		return 1;
-- 
1.6.5.2.74.g610f9

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/2] notmuch.el: Add support for reply-to sender
  2009-12-03  8:46 [PATCH 1/2] notmuch-reply: Add support for replying only to sender Aneesh Kumar K.V
@ 2009-12-03  8:46 ` Aneesh Kumar K.V
  2009-12-04 19:07 ` [PATCH 1/2] notmuch-reply: Add support for replying only to sender Carl Worth
  2009-12-05  9:37 ` [PATCH -V2] notmuch-reply: Add support for replying only to sender Aneesh Kumar K.V
  2 siblings, 0 replies; 10+ messages in thread
From: Aneesh Kumar K.V @ 2009-12-03  8:46 UTC (permalink / raw)
  To: cworth, aneesh.kumar; +Cc: Aneesh Kumar K.V, notmuch

From: Aneesh Kumar K.V <aneesh.kumar@gmail.com>

Add key binding to do a reply-to sender. This
is mapped to 'R'

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@gmail.com>
---
 notmuch.el |   24 ++++++++++++++++++++++--
 1 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/notmuch.el b/notmuch.el
index bd8a6ce..c067e63 100644
--- a/notmuch.el
+++ b/notmuch.el
@@ -62,7 +62,8 @@
     (define-key map "s" 'notmuch-search)
     (define-key map "m" 'message-mail)
     (define-key map "f" 'notmuch-show-forward-current)
-    (define-key map "r" 'notmuch-show-reply)
+    (define-key map "r" 'notmuch-show-reply-all)
+    (define-key map "R" 'notmuch-show-reply)
     (define-key map "|" 'notmuch-show-pipe-message)
     (define-key map "w" 'notmuch-show-save-attachments)
     (define-key map "V" 'notmuch-show-view-raw-message)
@@ -367,12 +368,31 @@ buffer."
 	(forward-line)))
   (message-mode))
 
-(defun notmuch-show-reply ()
+(defun notmuch-show-reply-all ()
   "Begin composing a reply to the current message in a new buffer."
   (interactive)
   (let ((message-id (notmuch-show-get-message-id)))
     (notmuch-reply message-id)))
 
+
+(defun notmuch-format-reply (format-string query-string)
+  (switch-to-buffer (generate-new-buffer "notmuch-draft"))
+  (call-process notmuch-command nil t nil "reply" 
+		(concat "--format=" format-string) query-string)
+  (message-insert-signature)
+  (goto-char (point-min))
+  (if (re-search-forward "^$" nil t)
+      (progn
+	(insert "--text follows this line--")
+	(forward-line)))
+  (message-mode))
+
+(defun notmuch-show-reply ()
+  "Begin composing a reply to the current message in a new buffer."
+  (interactive)
+  (let ((message-id (notmuch-show-get-message-id)))
+    (notmuch-format-reply "sender-only" message-id)))
+
 (defun notmuch-show-forward-current ()
   "Forward the current message."
   (interactive)
-- 
1.6.5.2.74.g610f9

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] notmuch-reply: Add support for replying only to sender
  2009-12-03  8:46 [PATCH 1/2] notmuch-reply: Add support for replying only to sender Aneesh Kumar K.V
  2009-12-03  8:46 ` [PATCH 2/2] notmuch.el: Add support for reply-to sender Aneesh Kumar K.V
@ 2009-12-04 19:07 ` Carl Worth
  2009-12-04 19:21   ` Jed Brown
  2009-12-11  5:31   ` Aneesh Kumar K. V
  2009-12-05  9:37 ` [PATCH -V2] notmuch-reply: Add support for replying only to sender Aneesh Kumar K.V
  2 siblings, 2 replies; 10+ messages in thread
From: Carl Worth @ 2009-12-04 19:07 UTC (permalink / raw)
  To: Aneesh Kumar K.V, aneesh.kumar; +Cc: Aneesh Kumar K.V, notmuch

[-- Attachment #1: Type: text/plain, Size: 372 bytes --]

On Thu,  3 Dec 2009 14:16:44 +0530, "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com> wrote:
> From: Aneesh Kumar K.V <aneesh.kumar@gmail.com>
> 
> This patch add --format=sender-only option.

I like the idea here, (and agree that an 'R' keybinding would be great).

But surely there's a way to implement this with dramatically less code
duplication?

-Carl

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] notmuch-reply: Add support for replying only to sender
  2009-12-04 19:07 ` [PATCH 1/2] notmuch-reply: Add support for replying only to sender Carl Worth
@ 2009-12-04 19:21   ` Jed Brown
  2009-12-11  5:31   ` Aneesh Kumar K. V
  1 sibling, 0 replies; 10+ messages in thread
From: Jed Brown @ 2009-12-04 19:21 UTC (permalink / raw)
  To: Carl Worth, Aneesh Kumar K.V, aneesh.kumar; +Cc: Aneesh Kumar K.V, notmuch

On Fri, 04 Dec 2009 11:07:54 -0800, Carl Worth <cworth@cworth.org> wrote:

> But surely there's a way to implement this with dramatically less code
> duplication?

It should just be very short after this series

  id:1259450376-24523-1-git-send-email-jed@59A2.org

I think --format= should not be used for this, formatting is orthogonal
to selecting recipients.

Speaking of code duplication, perhaps it is worth abstracting options
parsing (or using an existing library).

Jed

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH -V2] notmuch-reply: Add support for replying only to sender
  2009-12-03  8:46 [PATCH 1/2] notmuch-reply: Add support for replying only to sender Aneesh Kumar K.V
  2009-12-03  8:46 ` [PATCH 2/2] notmuch.el: Add support for reply-to sender Aneesh Kumar K.V
  2009-12-04 19:07 ` [PATCH 1/2] notmuch-reply: Add support for replying only to sender Carl Worth
@ 2009-12-05  9:37 ` Aneesh Kumar K.V
  2 siblings, 0 replies; 10+ messages in thread
From: Aneesh Kumar K.V @ 2009-12-05  9:37 UTC (permalink / raw)
  To: cworth, aneesh.kumar; +Cc: Aneesh Kumar K.V, notmuch

From: Aneesh Kumar K.V <aneesh.kumar@gmail.com>

This patch add --format=sender-only option.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@gmail.com>
---
 notmuch-reply.c |   54 ++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 40 insertions(+), 14 deletions(-)

diff --git a/notmuch-reply.c b/notmuch-reply.c
index 0cda72d..859b725 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -23,15 +23,23 @@
 #include "notmuch-client.h"
 #include "gmime-filter-reply.h"
 
-static const struct {
+struct reply_map {
     const char *header;
     const char *fallback;
     GMimeRecipientType recipient_type;
-} reply_to_map[] = {
+};
+
+static const struct reply_map reply_to_all_map[] = {
     { "reply-to", "from", GMIME_RECIPIENT_TYPE_TO  },
     { "to",         NULL, GMIME_RECIPIENT_TYPE_TO  },
     { "cc",         NULL, GMIME_RECIPIENT_TYPE_CC  },
-    { "bcc",        NULL, GMIME_RECIPIENT_TYPE_BCC }
+    { "bcc",        NULL, GMIME_RECIPIENT_TYPE_BCC },
+    { NULL,         NULL, 0}
+};
+
+static const struct reply_map reply_to_sender_map[] = {
+    { "reply-to", "from", GMIME_RECIPIENT_TYPE_TO  },
+    { NULL,         NULL, 0}
 };
 
 static void
@@ -200,7 +208,8 @@ add_recipients_for_string (GMimeMessage *message,
 }
 
 static int
-notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_t *query)
+__notmuch_reply(void *ctx, notmuch_config_t *config,
+		notmuch_query_t *query, const struct reply_map *map)
 {
     GMimeMessage *reply;
     notmuch_messages_t *messages;
@@ -229,17 +238,19 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_
 	    subject = talloc_asprintf (ctx, "Re: %s", subject);
 	g_mime_message_set_subject (reply, subject);
 
-	for (i = 0; i < ARRAY_SIZE (reply_to_map); i++) {
+	for (i = 0;; i++) {
 	    const char *addr;
 
+	    if (!map[i].header)
+		    break;
 	    recipients = notmuch_message_get_header (message,
-						     reply_to_map[i].header);
-	    if ((recipients == NULL || recipients[0] == '\0') && reply_to_map[i].fallback)
+						    map[i].header);
+	    if ((recipients == NULL || recipients[0] == '\0') && map[i].fallback)
 		recipients = notmuch_message_get_header (message,
-							 reply_to_map[i].fallback);
+							 map[i].fallback);
 
 	    addr = add_recipients_for_string (reply, config,
-					      reply_to_map[i].recipient_type,
+					      map[i].recipient_type,
 					      recipients);
 	    if (from_addr == NULL)
 		from_addr = addr;
@@ -289,6 +300,12 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_
     return 0;
 }
 
+static int
+notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_t *query)
+{
+	return __notmuch_reply(ctx, config, query, reply_to_all_map);
+}
+
 /* 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)
@@ -332,17 +349,18 @@ notmuch_reply_format_headers_only(void *ctx, notmuch_config_t *config, notmuch_q
 	g_mime_object_set_header (GMIME_OBJECT (reply),
 				  "References", references);
 
-	for (i = 0; i < ARRAY_SIZE (reply_to_map); i++) {
+	for (i = 0; i < ARRAY_SIZE (reply_to_all_map); i++) {
 	    const char *addr;
 
 	    recipients = notmuch_message_get_header (message,
-						     reply_to_map[i].header);
-	    if ((recipients == NULL || recipients[0] == '\0') && reply_to_map[i].fallback)
+						     reply_to_all_map[i].header);
+	    if ((recipients == NULL || recipients[0] == '\0') &&
+					reply_to_all_map[i].fallback)
 		recipients = notmuch_message_get_header (message,
-							 reply_to_map[i].fallback);
+						 reply_to_all_map[i].fallback);
 
 	    addr = add_recipients_for_string (reply, config,
-					      reply_to_map[i].recipient_type,
+					      reply_to_all_map[i].recipient_type,
 					      recipients);
 	}
 
@@ -361,6 +379,12 @@ notmuch_reply_format_headers_only(void *ctx, notmuch_config_t *config, notmuch_q
     return 0;
 }
 
+static int
+notmuch_reply_format_sender_only(void *ctx, notmuch_config_t *config, notmuch_query_t *query)
+{
+	return __notmuch_reply(ctx, config, query, reply_to_sender_map);
+}
+
 int
 notmuch_reply_command (void *ctx, int argc, char *argv[])
 {
@@ -384,6 +408,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, "sender-only") == 0) {
+		reply_format_func = notmuch_reply_format_sender_only;
 	    } else {
 		fprintf (stderr, "Invalid value for --format: %s\n", opt);
 		return 1;
-- 
1.6.5.2.74.g610f9

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] notmuch-reply: Add support for replying only to sender
  2009-12-04 19:07 ` [PATCH 1/2] notmuch-reply: Add support for replying only to sender Carl Worth
  2009-12-04 19:21   ` Jed Brown
@ 2009-12-11  5:31   ` Aneesh Kumar K. V
  2010-03-09 18:25     ` Carl Worth
  1 sibling, 1 reply; 10+ messages in thread
From: Aneesh Kumar K. V @ 2009-12-11  5:31 UTC (permalink / raw)
  To: Carl Worth; +Cc: Aneesh Kumar K.V, notmuch

On Fri, 04 Dec 2009 11:07:54 -0800, Carl Worth <cworth@cworth.org> wrote:
> On Thu,  3 Dec 2009 14:16:44 +0530, "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com> wrote:
> > From: Aneesh Kumar K.V <aneesh.kumar@gmail.com>
> > 
> > This patch add --format=sender-only option.
> 
> I like the idea here, (and agree that an 'R' keybinding would be great).
> 
> But surely there's a way to implement this with dramatically less code
> duplication?

I sent an updated patch which did the above with less code duplication. Any
chance of getting this merged ?

-aneesh

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] notmuch-reply: Add support for replying only to sender
  2009-12-11  5:31   ` Aneesh Kumar K. V
@ 2010-03-09 18:25     ` Carl Worth
  2010-03-10 16:31       ` [PATCH -V3 " Aneesh Kumar K.V
  2010-03-10 16:31       ` [PATCH -V3 2/2] notmuch.el: Add support for reply-to sender Aneesh Kumar K.V
  0 siblings, 2 replies; 10+ messages in thread
From: Carl Worth @ 2010-03-09 18:25 UTC (permalink / raw)
  To: Aneesh Kumar K. V; +Cc: Aneesh Kumar K.V, notmuch

[-- Attachment #1: Type: text/plain, Size: 1259 bytes --]

On Fri, 11 Dec 2009 11:01:15 +0530, "Aneesh Kumar K. V" <aneesh.kumar@linux.vnet.ibm.com> wrote:
> On Fri, 04 Dec 2009 11:07:54 -0800, Carl Worth <cworth@cworth.org> wrote:
> > On Thu,  3 Dec 2009 14:16:44 +0530, "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com> wrote:
> > > 
> > > This patch add --format=sender-only option.
> > 
> > I like the idea here, (and agree that an 'R' keybinding would be great).
> > 
> > But surely there's a way to implement this with dramatically less code
> > duplication?
> 
> I sent an updated patch which did the above with less code duplication. Any
> chance of getting this merged ?

Thanks for the updated patch, (and I sincerely apologize for my late
response).

I still like the functionality and keybinding, and it's great to see
less code duplication in this patch, but I also agree with the point Jed
made:

  I think --format= should not be used for this, formatting is orthogonal
  to selecting recipients.

We're already using --format for selection JSON output, for example. And
it's not totally unreasonable to expect that someone might want JSON
output from "notmuch reply" as well. So let's use a separate option
here.

Perhaps:

	--recipient=all|sender

or so?

-Carl

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH -V3 1/2] notmuch-reply: Add support for replying only to sender
  2010-03-09 18:25     ` Carl Worth
@ 2010-03-10 16:31       ` Aneesh Kumar K.V
  2010-03-11 12:45         ` Michal Sojka
  2010-03-10 16:31       ` [PATCH -V3 2/2] notmuch.el: Add support for reply-to sender Aneesh Kumar K.V
  1 sibling, 1 reply; 10+ messages in thread
From: Aneesh Kumar K.V @ 2010-03-10 16:31 UTC (permalink / raw)
  To: cworth; +Cc: Aneesh Kumar K.V, notmuch

From: Aneesh Kumar K.V <aneesh.kumar@gmail.com>

This patch add --recipient=all|sender option

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@gmail.com>
---
 notmuch-client.h |    2 +
 notmuch-reply.c  |   55 ++++++++++++++++++++++++++++++++++++++++-------------
 2 files changed, 43 insertions(+), 14 deletions(-)

diff --git a/notmuch-client.h b/notmuch-client.h
index c80b39c..26fdb4a 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -70,6 +70,8 @@
 #define STRNCMP_LITERAL(var, literal) \
     strncmp ((var), (literal), sizeof (literal) - 1)
 
+#define NOTMUCH_REPLY_ALL   0x1
+#define NOTMUCH_REPLY_SENDER_ONLY 0x2
 static inline void
 chomp_newline (char *str)
 {
diff --git a/notmuch-reply.c b/notmuch-reply.c
index 6c15536..e8a0820 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -232,20 +232,37 @@ 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_options)
 {
-    struct {
+    struct reply_to_map {
 	const char *header;
 	const char *fallback;
 	GMimeRecipientType recipient_type;
-    } reply_to_map[] = {
+    } ;
+    const char *from_addr = NULL;
+    unsigned int i;
+    struct reply_to_map *reply_to_map;
+
+    struct reply_to_map reply_to_map_all[] = {
 	{ "reply-to", "from", GMIME_RECIPIENT_TYPE_TO  },
 	{ "to",         NULL, GMIME_RECIPIENT_TYPE_TO  },
 	{ "cc",         NULL, GMIME_RECIPIENT_TYPE_CC  },
-	{ "bcc",        NULL, GMIME_RECIPIENT_TYPE_BCC }
+	{ "bcc",        NULL, GMIME_RECIPIENT_TYPE_BCC },
+	{  NULL,        NULL, 0 }
     };
-    const char *from_addr = NULL;
-    unsigned int i;
+
+    /* we try from first and then reply-to */
+    struct reply_to_map reply_to_map_sender[] = {
+	{ "from", "reply-to", GMIME_RECIPIENT_TYPE_TO  },
+	{  NULL,        NULL, 0 }
+    };
+
+    if (reply_options == NOTMUCH_REPLY_SENDER_ONLY) {
+	reply_to_map = reply_to_map_sender;
+    } else {
+	reply_to_map = reply_to_map_all;
+    }
 
     /* Some mailing lists munge the Reply-To header despite it being A Bad
      * Thing, see http://www.unicom.com/pw/reply-to-harmful.html
@@ -263,7 +280,7 @@ add_recipients_from_message (GMimeMessage *reply,
 	reply_to_map[0].fallback = NULL;
     }
 
-    for (i = 0; i < ARRAY_SIZE (reply_to_map); i++) {
+    for (i = 0; reply_to_map[i].header; i++) {
 	const char *addr, *recipients;
 
 	recipients = notmuch_message_get_header (message,
@@ -283,7 +300,7 @@ add_recipients_from_message (GMimeMessage *reply,
 }
 
 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_options)
 {
     GMimeMessage *reply;
     notmuch_messages_t *messages;
@@ -311,7 +328,7 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_
 	    subject = talloc_asprintf (ctx, "Re: %s", subject);
 	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_options);
 
 	if (from_addr == NULL)
 	    from_addr = notmuch_config_get_user_primary_email (config);
@@ -359,7 +376,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_options)
 {
     GMimeMessage *reply;
     notmuch_messages_t *messages;
@@ -399,7 +416,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_options);
 
 	g_mime_object_set_header (GMIME_OBJECT (reply), "Bcc",
 			   notmuch_config_get_user_primary_email (config));
@@ -423,8 +440,8 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
     notmuch_database_t *notmuch;
     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 i, ret = 0, reply_to = NOTMUCH_REPLY_ALL;
+    int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, int reply_options);
 
     reply_format_func = notmuch_reply_format_default;
 
@@ -443,6 +460,16 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
 		fprintf (stderr, "Invalid value for --format: %s\n", opt);
 		return 1;
 	    }
+	} else if (STRNCMP_LITERAL (argv[i], "--recipient=") == 0) {
+	    opt = argv[i] + sizeof ("--recipient=") - 1;
+	    if (strcmp (opt, "all") == 0) {
+		reply_to = NOTMUCH_REPLY_ALL;
+	    } else if (strcmp (opt, "sender") == 0) {
+		reply_to = NOTMUCH_REPLY_SENDER_ONLY;
+	    } else {
+		fprintf (stderr, "Invalid value for --recipient: %s\n", opt);
+		return 1;
+	    }
 	} else {
 	    fprintf (stderr, "Unrecognized option: %s\n", argv[i]);
 	    return 1;
@@ -478,7 +505,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) != 0)
 	return 1;
 
     notmuch_query_destroy (query);
-- 
1.7.0.2.157.gb7e7f

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH -V3 2/2] notmuch.el: Add support for reply-to sender
  2010-03-09 18:25     ` Carl Worth
  2010-03-10 16:31       ` [PATCH -V3 " Aneesh Kumar K.V
@ 2010-03-10 16:31       ` Aneesh Kumar K.V
  1 sibling, 0 replies; 10+ messages in thread
From: Aneesh Kumar K.V @ 2010-03-10 16:31 UTC (permalink / raw)
  To: cworth; +Cc: Aneesh Kumar K.V, notmuch

From: Aneesh Kumar K.V <aneesh.kumar@gmail.com>

Add key binding to do a reply-to sender. This is mapped to 'R'

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@gmail.com>
---
 emacs/notmuch.el |   24 ++++++++++++++++++++++--
 1 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 5b553bb..9ba1ec1 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -78,7 +78,8 @@
     (define-key map "s" 'notmuch-search)
     (define-key map "m" 'message-mail)
     (define-key map "f" 'notmuch-show-forward-current)
-    (define-key map "r" 'notmuch-show-reply)
+    (define-key map "r" 'notmuch-show-reply-all)
+    (define-key map "R" 'notmuch-show-reply)
     (define-key map "|" 'notmuch-show-pipe-message)
     (define-key map "w" 'notmuch-show-save-attachments)
     (define-key map "V" 'notmuch-show-view-raw-message)
@@ -446,12 +447,31 @@ buffer."
 	(forward-line)))
   (message-mode))
 
-(defun notmuch-show-reply ()
+(defun notmuch-show-reply-all ()
   "Begin composing a reply to the current message in a new buffer."
   (interactive)
   (let ((message-id (notmuch-show-get-message-id)))
     (notmuch-reply message-id)))
 
+
+(defun notmuch-recipient-reply (recipient query-string)
+  (switch-to-buffer (generate-new-buffer "notmuch-draft"))
+  (call-process notmuch-command nil t nil "reply"
+		(concat "--recipient=" recipient) query-string)
+  (message-insert-signature)
+  (goto-char (point-min))
+  (if (re-search-forward "^$" nil t)
+      (progn
+	(insert "--text follows this line--")
+	(forward-line)))
+  (message-mode))
+
+(defun notmuch-show-reply ()
+  "Begin composing a reply to the current message in a new buffer."
+  (interactive)
+  (let ((message-id (notmuch-show-get-message-id)))
+    (notmuch-recipient-reply "sender" message-id)))
+
 (defun notmuch-show-forward-current ()
   "Forward the current message."
   (interactive)
-- 
1.7.0.2.157.gb7e7f

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH -V3 1/2] notmuch-reply: Add support for replying only to sender
  2010-03-10 16:31       ` [PATCH -V3 " Aneesh Kumar K.V
@ 2010-03-11 12:45         ` Michal Sojka
  0 siblings, 0 replies; 10+ messages in thread
From: Michal Sojka @ 2010-03-11 12:45 UTC (permalink / raw)
  To: Aneesh Kumar K.V, cworth; +Cc: Aneesh Kumar K.V, notmuch

Hi,

On Wed, 10 Mar 2010, Aneesh Kumar K.V wrote:
> From: Aneesh Kumar K.V <aneesh.kumar@gmail.com>
> 
> This patch add --recipient=all|sender option
> 
> Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@gmail.com>
> ---
>  notmuch-client.h |    2 +
>  notmuch-reply.c  |   55 ++++++++++++++++++++++++++++++++++++++++-------------
>  2 files changed, 43 insertions(+), 14 deletions(-)
> 
> diff --git a/notmuch-client.h b/notmuch-client.h
> index c80b39c..26fdb4a 100644
> --- a/notmuch-client.h
> +++ b/notmuch-client.h
> @@ -70,6 +70,8 @@
>  #define STRNCMP_LITERAL(var, literal) \
>      strncmp ((var), (literal), sizeof (literal) - 1)
>  
> +#define NOTMUCH_REPLY_ALL   0x1
> +#define NOTMUCH_REPLY_SENDER_ONLY 0x2

Why not to define this as enum? When I see a definition like this
it reminds me bit flags which can be used together e.g.
  (NOTMUCH_REPLY_ALL | NOTMUCH_REPLY_SENDER_ONLY).

This has obviously no sense here.

>  static inline void
>  chomp_newline (char *str)
>  {
> diff --git a/notmuch-reply.c b/notmuch-reply.c
> index 6c15536..e8a0820 100644
> --- a/notmuch-reply.c
> +++ b/notmuch-reply.c
> @@ -232,20 +232,37 @@ 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_options)
>  {
> -    struct {
> +    struct reply_to_map {
>  	const char *header;
>  	const char *fallback;
>  	GMimeRecipientType recipient_type;
> -    } reply_to_map[] = {
> +    } ;
> +    const char *from_addr = NULL;
> +    unsigned int i;
> +    struct reply_to_map *reply_to_map;
> +
> +    struct reply_to_map reply_to_map_all[] = {
>  	{ "reply-to", "from", GMIME_RECIPIENT_TYPE_TO  },
>  	{ "to",         NULL, GMIME_RECIPIENT_TYPE_TO  },
>  	{ "cc",         NULL, GMIME_RECIPIENT_TYPE_CC  },
> -	{ "bcc",        NULL, GMIME_RECIPIENT_TYPE_BCC }
> +	{ "bcc",        NULL, GMIME_RECIPIENT_TYPE_BCC },
> +	{  NULL,        NULL, 0 }
>      };
> -    const char *from_addr = NULL;
> -    unsigned int i;
> +
> +    /* we try from first and then reply-to */
> +    struct reply_to_map reply_to_map_sender[] = {
> +	{ "from", "reply-to", GMIME_RECIPIENT_TYPE_TO  },
> +	{  NULL,        NULL, 0 }
> +    };

I'm not sure whether an e-mail without From: is a valid e-mail. If not,
you would never use "reply-to" header. Also, given the link below
(http://www.unicom.com/pw/reply-to-harmful.html), this will not behave
as Carl likes :). Finally, don't forget that reply_to_map can be
modified in add_recipients_from_message().

I missed your original patch so I implement this for myself in a less
intrusive way (see
id:1267464588-21050-1-git-send-email-sojkam1@fel.cvut.cz). What I like
at your approach is that --recipient option can have several values. I
think it would be useful to have three possible values of this option:
"all", "sender" and something like "reply-to-or-sender". The latter
option would cause using of Reply-to: header event if it is found as
redundant by reply_to_header_is_redundant(). I find this useful for
several private mailing lists I use.

-Michal
> +
> +    if (reply_options == NOTMUCH_REPLY_SENDER_ONLY) {
> +	reply_to_map = reply_to_map_sender;
> +    } else {
> +	reply_to_map = reply_to_map_all;
> +    }
>  
>      /* Some mailing lists munge the Reply-To header despite it being A Bad
>       * Thing, see http://www.unicom.com/pw/reply-to-harmful.html

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2010-03-11 12:46 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-03  8:46 [PATCH 1/2] notmuch-reply: Add support for replying only to sender Aneesh Kumar K.V
2009-12-03  8:46 ` [PATCH 2/2] notmuch.el: Add support for reply-to sender Aneesh Kumar K.V
2009-12-04 19:07 ` [PATCH 1/2] notmuch-reply: Add support for replying only to sender Carl Worth
2009-12-04 19:21   ` Jed Brown
2009-12-11  5:31   ` Aneesh Kumar K. V
2010-03-09 18:25     ` Carl Worth
2010-03-10 16:31       ` [PATCH -V3 " Aneesh Kumar K.V
2010-03-11 12:45         ` Michal Sojka
2010-03-10 16:31       ` [PATCH -V3 2/2] notmuch.el: Add support for reply-to sender Aneesh Kumar K.V
2009-12-05  9:37 ` [PATCH -V2] notmuch-reply: Add support for replying only to sender Aneesh Kumar K.V

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).