unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [RFC PATCH 0/3] Quoting HTML-only emails in replies
@ 2011-11-30 16:40 Adam Wolfe Gordon
  2011-11-30 16:40 ` [RFC PATCH 1/3] test: replies that quote HTML parts (expected to fail) Adam Wolfe Gordon
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Adam Wolfe Gordon @ 2011-11-30 16:40 UTC (permalink / raw)
  To: notmuch, awg

Hi everyone,

I use notmuch at work, where the email server is Exchange and the majority
of my colleagues use Outlook. This means that I get a fair bit of
HTML-only email. When using notmuch reply to create replies to such
emails, the quoted body ends up containing only the line "Non-text part:
text/html", and if I want to quote them I have to do it manually.

This series of patches fixes this issue. It adds a --format=html option to
notmuch reply, which acts like --format=default except that it includes
HTML parts as well as text parts. The emacs interface render the quoted
HTML into text using w3m. I've added a customize option,
notmuch-mua-quote-html-parts to control this behavior. I've included a
test for the notmuch reply part, though it's not a great one.

This code is working well for me, but I'm marking this as RFC because
there are a few things that could be better:

1. If an email has a text part and an HTML part they'll both end up
   quoted, and emacs might make the text part look ugly by trying to
   render it as HTML.  Ideally it should omit HTML parts from the reply
   when a text part exists, but it looks like this would take some
   non-trivial refactoring of the notmuch reply code.

2. The easiest way to implement --format=html in notmuch reply was to use
   a global variable controlling HTML output, which feels clumsy to me.
   Perhaps someone who is more familiar with the notmuch code can suggest
   a cleaner way of doing it.

3. As I mentioned, the test I've included isn't great.  A test that uses
   an HTML-only email would be nice, and if (1) can be resolved, then the
   existing test will have different results.

I hope someone else will find these changes useful - please do let me know
if you have suggestions.

Cheers.

Adam Wolfe Gordon (3):
  test: replies that quote HTML parts (expected to fail)
  reply: New format 'html' that quotes text/html parts
  emacs: Optionally quote HTML parts when replying.

 emacs/notmuch-mua.el |   23 +++++++++++++++++++++++
 notmuch-reply.c      |    8 +++++++-
 notmuch.c            |    6 +++++-
 test/multipart       |   24 ++++++++++++++++++++++++
 4 files changed, 59 insertions(+), 2 deletions(-)

-- 
1.7.5.4

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

* [RFC PATCH 1/3] test: replies that quote HTML parts (expected to fail)
  2011-11-30 16:40 [RFC PATCH 0/3] Quoting HTML-only emails in replies Adam Wolfe Gordon
@ 2011-11-30 16:40 ` Adam Wolfe Gordon
  2011-11-30 16:40 ` [RFC PATCH 2/3] reply: New format 'html' that quotes text/html parts Adam Wolfe Gordon
  2011-11-30 16:40 ` [RFC PATCH 3/3] emacs: Optionally quote HTML parts when replying Adam Wolfe Gordon
  2 siblings, 0 replies; 4+ messages in thread
From: Adam Wolfe Gordon @ 2011-11-30 16:40 UTC (permalink / raw)
  To: notmuch, awg

Test `notmuch reply` with the new --format=html flag, indicating that HTML parts
should be quoted in the reply.
---
 test/multipart |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/test/multipart b/test/multipart
index f83526b..d5ca7fd 100755
--- a/test/multipart
+++ b/test/multipart
@@ -589,6 +589,30 @@ Non-text part: text/html
 EOF
 test_expect_equal_file OUTPUT EXPECTED
 
+test_begin_subtest "'notmuch reply' to a multipart message with --format=html"
+notmuch reply --format=html 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
+cat <<EOF >EXPECTED
+From: Notmuch Test Suite <test_suite@notmuchmail.org>
+Subject: Re: Multipart message
+To: Carl Worth <cworth@cworth.org>, cworth@cworth.org
+In-Reply-To: <87liy5ap00.fsf@yoom.home.cworth.org>
+References: <87liy5ap00.fsf@yoom.home.cworth.org>
+
+On Fri, 05 Jan 2001 15:43:57 +0000, Carl Worth <cworth@cworth.org> wrote:
+> From: Carl Worth <cworth@cworth.org>
+> To: cworth@cworth.org
+> Subject: html message
+> Date: Fri, 05 Jan 2001 15:42:57 +0000
+>
+> <p>This is an embedded message, with a multipart/alternative part.</p>
+> This is an embedded message, with a multipart/alternative part.
+> This is a text attachment.
+> And this message is signed.
+> 
+> -Carl
+EOF
+test_expect_equal_file OUTPUT EXPECTED
+
 test_begin_subtest "'notmuch show --part' does not corrupt a part with CRLF pair"
 notmuch show --format=raw --part=3 id:base64-part-with-crlf > crlf.out
 echo -n -e "\xEF\x0D\x0A" > crlf.expected
-- 
1.7.5.4

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

* [RFC PATCH 2/3] reply: New format 'html' that quotes text/html parts
  2011-11-30 16:40 [RFC PATCH 0/3] Quoting HTML-only emails in replies Adam Wolfe Gordon
  2011-11-30 16:40 ` [RFC PATCH 1/3] test: replies that quote HTML parts (expected to fail) Adam Wolfe Gordon
@ 2011-11-30 16:40 ` Adam Wolfe Gordon
  2011-11-30 16:40 ` [RFC PATCH 3/3] emacs: Optionally quote HTML parts when replying Adam Wolfe Gordon
  2 siblings, 0 replies; 4+ messages in thread
From: Adam Wolfe Gordon @ 2011-11-30 16:40 UTC (permalink / raw)
  To: notmuch, awg

A new format for notmuch reply that quotes text/html parts as well as text/plain
parts. The defaults have not changed, so notmuch reply with no arguments still
quotes only plain-text parts.  This is useful for people who regularly get
HTML-only email.
---
 notmuch-reply.c |    8 +++++++-
 notmuch.c       |    6 +++++-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/notmuch-reply.c b/notmuch-reply.c
index 7ac879f..d44e179 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -46,6 +46,8 @@ static const notmuch_show_format_t format_reply = {
     ""
 };
 
+static notmuch_bool_t allow_html = FALSE;
+
 static void
 show_reply_headers (GMimeMessage *message)
 {
@@ -104,7 +106,7 @@ reply_part_content (GMimeObject *part)
 	/* Ignore PGP/MIME cruft parts */
     }
     else if (g_mime_content_type_is_type (content_type, "text", "*") &&
-	!g_mime_content_type_is_type (content_type, "text", "html"))
+	(!g_mime_content_type_is_type (content_type, "text", "html") || allow_html))
     {
 	GMimeStream *stream_stdout = NULL, *stream_filter = NULL;
 	GMimeDataWrapper *wrapper;
@@ -639,8 +641,12 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
 	    opt = argv[i] + sizeof ("--format=") - 1;
 	    if (strcmp (opt, "default") == 0) {
 		reply_format_func = notmuch_reply_format_default;
+		allow_html = FALSE;
 	    } else if (strcmp (opt, "headers-only") == 0) {
 		reply_format_func = notmuch_reply_format_headers_only;
+	    } else if (strcmp (opt, "html") == 0) {
+		reply_format_func = notmuch_reply_format_default;
+		allow_html = TRUE;
 	    } else {
 		fprintf (stderr, "Invalid value for --format: %s\n", opt);
 		return 1;
diff --git a/notmuch.c b/notmuch.c
index d44ce9a..f72e79c 100644
--- a/notmuch.c
+++ b/notmuch.c
@@ -366,7 +366,7 @@ static command_t commands[] = {
       "\n"
       "\tSupported options for reply include:\n"
       "\n"
-      "\t--format=(default|headers-only)\n"
+      "\t--format=(default|headers-only|html)\n"
       "\n"
       "\t\tdefault:\n"
       "\t\t\tIncludes subject and quoted message body.\n"
@@ -375,6 +375,10 @@ static command_t commands[] = {
       "\t\t\tOnly produces In-Reply-To, References, To\n"
       "\t\t\tCc, and Bcc headers.\n"
       "\n"
+      "\t\thtml:\n"
+      "\t\t\tIncludes subject and quoted message body,\n"
+      "\t\t\tincluding HTML parts.\n"
+      "\n"
       "\tSee \"notmuch help search-terms\" for details of the search\n"
       "\tterms syntax." },
     { "tag", notmuch_tag_command,
-- 
1.7.5.4

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

* [RFC PATCH 3/3] emacs: Optionally quote HTML parts when replying.
  2011-11-30 16:40 [RFC PATCH 0/3] Quoting HTML-only emails in replies Adam Wolfe Gordon
  2011-11-30 16:40 ` [RFC PATCH 1/3] test: replies that quote HTML parts (expected to fail) Adam Wolfe Gordon
  2011-11-30 16:40 ` [RFC PATCH 2/3] reply: New format 'html' that quotes text/html parts Adam Wolfe Gordon
@ 2011-11-30 16:40 ` Adam Wolfe Gordon
  2 siblings, 0 replies; 4+ messages in thread
From: Adam Wolfe Gordon @ 2011-11-30 16:40 UTC (permalink / raw)
  To: notmuch, awg

Add support for rendering and quoting HTML parts. Adds a customize option
notmuch-mua-quote-html-parts, which when non-nil causes HTML parts to be
included in replies using notmuch reply --format=html.
---
 emacs/notmuch-mua.el |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index 8824b08..e7c1315 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -46,6 +46,14 @@ list."
   :group 'notmuch
   :type '(repeat string))
 
+(defcustom notmuch-mua-quote-html-parts nil
+  "Quote HTML parts when replying to a message.
+
+If non-nil, notmuch will attempt to render HTML parts using w3m and insert them
+into reply buffers."
+  :group 'notmuch
+  :type 'boolean)
+
 ;;
 
 (defun notmuch-mua-user-agent-full ()
@@ -69,10 +77,13 @@ list."
 	    (push header message-hidden-headers)))
 	notmuch-mua-hidden-headers))
 
+(defun w3m-region (start end)) ;; From `w3m.el'.
 (defun notmuch-mua-reply (query-string &optional sender)
   (let (headers
 	body
 	(args '("reply")))
+    (if notmuch-mua-quote-html-parts
+	(setq args (append args '("--format=html"))))
     (if notmuch-show-process-crypto
 	(setq args (append args '("--decrypt"))))
     (setq args (append args (list query-string)))
@@ -89,6 +100,18 @@ list."
 	      (goto-char (point-min))
 	      (setq headers (mail-header-extract)))))
       (forward-line 1)
+      (if notmuch-mua-quote-html-parts
+	  (save-excursion
+	    (if (re-search-forward "<html" nil t)
+		(save-restriction
+		  (goto-char (point-at-bol))
+		  (narrow-to-region (point) (point-max))
+		  (w3m-region (point) (point-max))
+		  (goto-char (point-min))
+		  (fill-region (point) (point-max))
+		  (goto-char (point-min))
+		  (while (re-search-forward "^" nil t)
+		    (replace-match "> " nil nil))))))
       (setq body (buffer-substring (point) (point-max))))
     ;; If sender is non-nil, set the From: header to its value.
     (when sender
-- 
1.7.5.4

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

end of thread, other threads:[~2011-11-30 16:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-30 16:40 [RFC PATCH 0/3] Quoting HTML-only emails in replies Adam Wolfe Gordon
2011-11-30 16:40 ` [RFC PATCH 1/3] test: replies that quote HTML parts (expected to fail) Adam Wolfe Gordon
2011-11-30 16:40 ` [RFC PATCH 2/3] reply: New format 'html' that quotes text/html parts Adam Wolfe Gordon
2011-11-30 16:40 ` [RFC PATCH 3/3] emacs: Optionally quote HTML parts when replying Adam Wolfe Gordon

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