Subject: Re: bug#21471: 25.0.50; bug report with text from Info has spurious escape chars

From: Paul Eggert <[email-masked]>
Date: Mon, 14 Sep 2015 14:10:51 -0700

Eli Zaretskii wrote:
> What was this fix supposed to change?

It was supposed to fix the two scenarios mentioned (one mine, the other Drew's). 
  I didn't know the clipboard didn't work.  Fixed, I hope, with the attached patch.
From 59f0b53c1092b1528d34d9c4edebcf034be628a4 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email-masked]>
Date: Mon, 14 Sep 2015 14:09:24 -0700
Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20double-encode=20non-ASCII=20mai?=
 =?UTF-8?q?l=20clipboard?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* lisp/mail/mailclient.el (mailclient-send-it):
Also fix the case when mailclient-place-body-on-clipboard-flag
is non-nil.  Problem reported by Eli Zaretskii (Bug#21471#37).
---
 lisp/mail/mailclient.el | 56 ++++++++++++++++++++++---------------------------
 1 file changed, 25 insertions(+), 31 deletions(-)

diff --git a/lisp/mail/mailclient.el b/lisp/mail/mailclient.el
index bef2038..2fb944b 100644
--- a/lisp/mail/mailclient.el
+++ b/lisp/mail/mailclient.el
@@ -175,37 +175,31 @@ The mail client is taken to be the handler of mailto URLs."
 			       (mailclient-encode-string-as-url subj))
 		     ""))))
 	      ;; body
-	      (concat
-	       (mailclient-url-delim) "body="
-	       (mailclient-encode-string-as-url
-		(if mailclient-place-body-on-clipboard-flag
-		    (progn
-		      (clipboard-kill-ring-save
-		       (+ 1 delimline) (point-max))
-		      (concat
-		       "*** E-Mail body has been placed on clipboard, "
-		       "please paste it here! ***"))
-		  ;; else
-		  (let ((body (buffer-substring (+ 1 delimline) (point-max))))
-		    (if (null character-coding)
-			body
-		      ;; mailto: requires UTF-8 and cannot deal with
-		      ;; Content-Transfer-Encoding or Content-Type.
-		      ;; FIXME: There is a lot of code duplication here
-		      ;; with rmail.el.
-		      (erase-buffer)
-		      (set-buffer-multibyte nil)
-		      (insert body)
-		      (cond
-		       ((string= character-coding "quoted-printable")
-			(mail-unquote-printable-region (point-min) (point-max)
-						       nil nil 'unibyte))
-		       ((string= character-coding "base64")
-			(base64-decode-region (point-min) (point-max)))
-		       (t (error "unsupported Content-Transfer-Encoding: %s"
-				 character-coding)))
-		      (decode-coding-region (point-min) (point-max)
-					    coding-system t)))))))))))))
+	      (mailclient-url-delim) "body="
+	      (progn
+		(delete-region (point-min) delimline)
+		(unless (null character-coding)
+		  ;; mailto: and clipboard need UTF-8 and cannot deal with
+		  ;; Content-Transfer-Encoding or Content-Type.
+		  ;; FIXME: There is code duplication here with rmail.el.
+		  (set-buffer-multibyte nil)
+		  (cond
+		   ((string= character-coding "base64")
+		    (base64-decode-region (point-min) (point-max)))
+		   ((string= character-coding "quoted-printable")
+		    (mail-unquote-printable-region (point-min) (point-max)
+						   nil nil t))
+		   (t (error "unsupported Content-Transfer-Encoding: %s"
+			     character-coding)))
+		  (decode-coding-region (point-min) (point-max) coding-system))
+		(mailclient-encode-string-as-url
+		 (if mailclient-place-body-on-clipboard-flag
+		     (progn
+		       (clipboard-kill-ring-save (point-min) (point-max))
+		       (concat
+			"*** E-Mail body has been placed on clipboard, "
+			"please paste it here! ***"))
+		   (buffer-string)))))))))))
 
 (provide 'mailclient)
 
-- 
2.1.4