unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH 0/3] Allow widen reply 
@ 2013-05-11 20:15 Mark Walters
  2013-05-11 20:15 ` [PATCH 1/3] cli: show: separate out the printing of recipient headers Mark Walters
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Mark Walters @ 2013-05-11 20:15 UTC (permalink / raw)
  To: notmuch

This is an initial draft of a patch to allow the emacs frontend to
"widen" the reply: i.e., change the headers to reply-to-all after a
reply-to-sender has been started.

The reply cli json output is modified to always output the
reply-to-all headers.

Emacs message mode already as a key binding for widening reply (C-c
C-f w) so we use that.

There are some things that need to be worked out: do we want to allow
narrowing the reply (ie going from reply-to-all back to
reply-to-sender)? I did not implement this as it was slightly easier
not to, message-mode doesn't have this by default, and it's easy for a
user to remove recipients.

I have not updated tests (the reply json test fails) or the
schemata. I thought it was worth deciding what format we wanted for
the json first.

Finally, I am not sure I have got the overriding of
message-widen-reply keybinding right. It does seem to work.

Best wishes

Mark



Mark Walters (3):
  cli: show: separate out the printing of recipient headers
  cli: reply: additionally output reply-to-all headers to allow widen
    reply
  emacs: mua: allow the user to widen the reply

 emacs/notmuch-mua.el |   22 +++++++++++++++++++++-
 notmuch-client.h     |    3 +++
 notmuch-reply.c      |   18 +++++++++++++++++-
 notmuch-show.c       |   35 +++++++++++++++++++++--------------
 4 files changed, 62 insertions(+), 16 deletions(-)

-- 
1.7.9.1

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

* [PATCH 1/3] cli: show: separate out the printing of recipient headers
  2013-05-11 20:15 [PATCH 0/3] Allow widen reply Mark Walters
@ 2013-05-11 20:15 ` Mark Walters
  2013-05-11 20:15 ` [PATCH 2/3] cli: reply: additionally output reply-to-all headers to allow widen reply Mark Walters
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Mark Walters @ 2013-05-11 20:15 UTC (permalink / raw)
  To: notmuch

This splits out the sprinter printing of recipient headers so that
notmuch-reply can call it directly. This will be used when reply
outputs header for reply-all and reply-to-sender.
---
 notmuch-client.h |    3 +++
 notmuch-show.c   |   35 +++++++++++++++++++++--------------
 2 files changed, 24 insertions(+), 14 deletions(-)

diff --git a/notmuch-client.h b/notmuch-client.h
index 45749a6..d55d4c0 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -223,6 +223,9 @@ void
 format_headers_sprinter (struct sprinter *sp, GMimeMessage *message,
 			 notmuch_bool_t reply);
 
+void
+format_headers_recipients_sprinter (struct sprinter *sp, GMimeMessage *message);
+
 typedef enum {
     NOTMUCH_SHOW_TEXT_PART_REPLY = 1 << 0,
 } notmuch_show_text_part_flags;
diff --git a/notmuch-show.c b/notmuch-show.c
index 62178f7..8b9ab61 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -213,23 +213,10 @@ _is_from_line (const char *line)
 }
 
 void
-format_headers_sprinter (sprinter_t *sp, GMimeMessage *message,
-			 notmuch_bool_t reply)
+format_headers_recipients_sprinter (sprinter_t *sp, GMimeMessage *message)
 {
-    /* Any changes to the JSON or S-Expression format should be
-     * reflected in the file devel/schemata. */
-
     InternetAddressList *recipients;
     const char *recipients_string;
-    const char *reply_to_string;
-
-    sp->begin_map (sp);
-
-    sp->map_key (sp, "Subject");
-    sp->string (sp, g_mime_message_get_subject (message));
-
-    sp->map_key (sp, "From");
-    sp->string (sp, g_mime_message_get_sender (message));
 
     recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_TO);
     recipients_string = internet_address_list_to_string (recipients, 0);
@@ -251,6 +238,26 @@ format_headers_sprinter (sprinter_t *sp, GMimeMessage *message,
 	sp->map_key (sp, "Bcc");
 	sp->string (sp, recipients_string);
     }
+}
+
+void
+format_headers_sprinter (sprinter_t *sp, GMimeMessage *message,
+			 notmuch_bool_t reply)
+{
+    /* Any changes to the JSON or S-Expression format should be
+     * reflected in the file devel/schemata. */
+
+    const char *reply_to_string;
+
+    sp->begin_map (sp);
+
+    sp->map_key (sp, "Subject");
+    sp->string (sp, g_mime_message_get_subject (message));
+
+    sp->map_key (sp, "From");
+    sp->string (sp, g_mime_message_get_sender (message));
+
+    format_headers_recipients_sprinter (sp, message);
 
     reply_to_string = g_mime_message_get_reply_to (message);
     if (reply_to_string) {
-- 
1.7.9.1

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

* [PATCH 2/3] cli: reply: additionally output reply-to-all headers to allow widen reply
  2013-05-11 20:15 [PATCH 0/3] Allow widen reply Mark Walters
  2013-05-11 20:15 ` [PATCH 1/3] cli: show: separate out the printing of recipient headers Mark Walters
@ 2013-05-11 20:15 ` Mark Walters
  2013-05-11 20:15 ` [PATCH 3/3] emacs: mua: allow the user to widen the reply Mark Walters
  2013-05-12 20:53 ` [PATCH 0/3] Allow widen reply Jani Nikula
  3 siblings, 0 replies; 5+ messages in thread
From: Mark Walters @ 2013-05-11 20:15 UTC (permalink / raw)
  To: notmuch

This additionally outputs the reply-to-all versions To: Cc: and Bcc:
fields under the heading reply-all-recipients so that a frontend can
`widen' the reply.
---
 notmuch-reply.c |   18 +++++++++++++++++-
 1 files changed, 17 insertions(+), 1 deletions(-)

diff --git a/notmuch-reply.c b/notmuch-reply.c
index e151f78..6935f69 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -595,7 +595,7 @@ notmuch_reply_format_sprinter(void *ctx,
 			      notmuch_bool_t reply_all,
 			      sprinter_t *sp)
 {
-    GMimeMessage *reply;
+    GMimeMessage *reply_all_recipients, *reply;
     notmuch_messages_t *messages;
     notmuch_message_t *message;
     mime_node_t *node;
@@ -614,6 +614,14 @@ notmuch_reply_format_sprinter(void *ctx,
     if (!reply)
 	return 1;
 
+    /* The 1 means we want headers in a "pretty" order. */
+    reply_all_recipients = g_mime_message_new (1);
+    if (reply_all_recipients == NULL) {
+	fprintf (stderr, "Out of memory\n");
+	return 1;
+    }
+    add_recipients_from_message (reply_all_recipients, config, message, TRUE);
+
     sp->begin_map (sp);
 
     /* The headers of the reply message we've created */
@@ -622,6 +630,14 @@ notmuch_reply_format_sprinter(void *ctx,
     g_object_unref (G_OBJECT (reply));
     reply = NULL;
 
+    /* The recipient headers if we were applying to all */
+    sp->map_key (sp, "reply-all-recipients");
+    sp->begin_map (sp);
+    format_headers_recipients_sprinter (sp, reply_all_recipients);
+    sp->end (sp);
+    g_object_unref (G_OBJECT (reply_all_recipients));
+    reply_all_recipients = NULL;
+
     /* Start the original */
     sp->map_key (sp, "original");
     format_part_sprinter (ctx, sp, node, TRUE, TRUE);
-- 
1.7.9.1

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

* [PATCH 3/3] emacs: mua: allow the user to widen the reply
  2013-05-11 20:15 [PATCH 0/3] Allow widen reply Mark Walters
  2013-05-11 20:15 ` [PATCH 1/3] cli: show: separate out the printing of recipient headers Mark Walters
  2013-05-11 20:15 ` [PATCH 2/3] cli: reply: additionally output reply-to-all headers to allow widen reply Mark Walters
@ 2013-05-11 20:15 ` Mark Walters
  2013-05-12 20:53 ` [PATCH 0/3] Allow widen reply Jani Nikula
  3 siblings, 0 replies; 5+ messages in thread
From: Mark Walters @ 2013-05-11 20:15 UTC (permalink / raw)
  To: notmuch

Emacs message mode already has a widen reply option C-c C-f w (which
obviously doesn't work when used via notmuch). This uses the new
reply-all-recipients output to add a function to make it work in this case.
---
 emacs/notmuch-mua.el |   22 +++++++++++++++++++++-
 1 files changed, 21 insertions(+), 1 deletions(-)

diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index 24eebff..1f28287 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -74,6 +74,12 @@ list."
   :type '(repeat string)
   :group 'notmuch-send)
 
+;; This is used to store the reply all headers to allow the reply to
+;; be `widened' in the mail compose window.
+(defvar notmuch-mua-reply-all-recipients nil)
+(make-variable-buffer-local 'notmuch-mua-reply-all-recipients)
+(put 'notmuch-mua-reply-all-recipients 'permanent-local t)
+
 ;;
 
 (defun notmuch-mua-get-switch-function ()
@@ -145,6 +151,14 @@ list."
   (funcall original-func header references)
   (unless (bolp) (insert "\n")))
 
+(defun notmuch-mua-widen-reply ()
+  (interactive)
+  (let ((reply-all-headers notmuch-mua-reply-all-recipients))
+    (message-replace-header "To" (plist-get reply-all-headers :To))
+    (message-replace-header "Cc" (plist-get reply-all-headers :Cc))
+    (message-replace-header "Bcc" (plist-get reply-all-headers :Bcc))
+    (message-sort-headers)))
+
 (defun notmuch-mua-reply (query-string &optional sender reply-all)
   (let ((args '("reply" "--format=json" "--format-version=1"))
 	reply
@@ -165,7 +179,8 @@ list."
 
     ;; Extract the headers of both the reply and the original message.
     (let* ((original-headers (plist-get original :headers))
-	   (reply-headers (plist-get reply :reply-headers)))
+	   (reply-headers (plist-get reply :reply-headers))
+	   (reply-all-recipients (plist-get reply :reply-all-recipients)))
 
       ;; If sender is non-nil, set the From: header to its value.
       (when sender
@@ -191,6 +206,11 @@ list."
 			    (notmuch-headers-plist-to-alist reply-headers)
 			    nil (notmuch-mua-get-switch-function))))
 
+      ;; Store the JSON for use by the mail compose window for header
+      ;; toggling etc.
+      (setq notmuch-mua-reply-all-recipients reply-all-recipients)
+      (local-set-key "\C-c\C-fw" 'notmuch-mua-widen-reply)
+
       ;; Insert the message body - but put it in front of the signature
       ;; if one is present
       (goto-char (point-max))
-- 
1.7.9.1

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

* Re: [PATCH 0/3] Allow widen reply
  2013-05-11 20:15 [PATCH 0/3] Allow widen reply Mark Walters
                   ` (2 preceding siblings ...)
  2013-05-11 20:15 ` [PATCH 3/3] emacs: mua: allow the user to widen the reply Mark Walters
@ 2013-05-12 20:53 ` Jani Nikula
  3 siblings, 0 replies; 5+ messages in thread
From: Jani Nikula @ 2013-05-12 20:53 UTC (permalink / raw)
  To: Mark Walters, notmuch


Hi Mark -

On Sat, 11 May 2013, Mark Walters <markwalters1009@gmail.com> wrote:
> This is an initial draft of a patch to allow the emacs frontend to
> "widen" the reply: i.e., change the headers to reply-to-all after a
> reply-to-sender has been started.

I didn't look at the patches very much, but I like the idea, a lot. This
is the way it should be.

> There are some things that need to be worked out: do we want to allow
> narrowing the reply (ie going from reply-to-all back to
> reply-to-sender)? I did not implement this as it was slightly easier
> not to, message-mode doesn't have this by default, and it's easy for a
> user to remove recipients.

Might be useful, but can be added later on.

The same for better handling of mail-followup-to: and reply-to:. For
those, I'm not sure if a keybinding for "widening" the recipients is the
right choice, as they both mean *changing*, not necessarily widening the
recipient list. Maybe you can come up with an approach here that extends
well to those too later on. ;)

BR,
Jani.

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

end of thread, other threads:[~2013-05-12 20:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-11 20:15 [PATCH 0/3] Allow widen reply Mark Walters
2013-05-11 20:15 ` [PATCH 1/3] cli: show: separate out the printing of recipient headers Mark Walters
2013-05-11 20:15 ` [PATCH 2/3] cli: reply: additionally output reply-to-all headers to allow widen reply Mark Walters
2013-05-11 20:15 ` [PATCH 3/3] emacs: mua: allow the user to widen the reply Mark Walters
2013-05-12 20:53 ` [PATCH 0/3] Allow widen reply Jani Nikula

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