From: Paul Eggert <eggert@cs.ucla.edu>
To: Drew Adams <drew.adams@oracle.com>, Eli Zaretskii <eliz@gnu.org>
Cc: 21471-done@debbugs.gnu.org
Subject: bug#21471: 25.0.50; bug report with text from Info has spurious escape chars
Date: Mon, 14 Sep 2015 09:38:29 -0700 [thread overview]
Message-ID: <55F6F805.8010506@cs.ucla.edu> (raw)
In-Reply-To: <1b2518bd-4049-423f-a32e-85d5b3adc3f4@default>
[-- Attachment #1: Type: text/plain, Size: 322 bytes --]
It is a longstanding double-encoding bug in mailclient-encode-string-as-url, and
I installed the attached attempt to fix it. Please give this a try. I am
boldly marking the bug as fixed.
I expect our more-extensive use of curved quotes to shake out other bugs like
this in Emacs, and it is a good thing to fix them.
[-- Attachment #2: 0001-Don-t-double-encode-non-ASCII-for-mail-client.patch --]
[-- Type: text/plain, Size: 4369 bytes --]
From d76d8aa460927924ab35b119c49be09f8aa84dd3 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Mon, 14 Sep 2015 09:31:23 -0700
Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20double-encode=20non-ASCII=20for?=
=?UTF-8?q?=20mail=20client?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* lisp/mail/mailclient.el (mailclient-encode-string-as-url):
Use RFC 6068’s list of unreserved characters.
(mailclient-send-it): When encoding the body as a URL,
first decode it as per Content-Type: and Content-Transfer-Encoding:,
as URLs must use percent-encoded UTF-8 (Bug#21471).
* doc/misc/url.texi (mailto): Update RFC number.
---
doc/misc/url.texi | 2 +-
lisp/mail/mailclient.el | 42 ++++++++++++++++++++++++++++++++++++++----
2 files changed, 39 insertions(+), 5 deletions(-)
diff --git a/doc/misc/url.texi b/doc/misc/url.texi
index d94b19f..95fe5ea 100644
--- a/doc/misc/url.texi
+++ b/doc/misc/url.texi
@@ -593,7 +593,7 @@ sending a message to @samp{foo@@bar.com}. The ``retrieval method''
for such URLs is to open a mail composition buffer in which the
appropriate content (e.g., the recipient address) has been filled in.
- As defined in RFC 2368, a @code{mailto} URL has the form
+ As defined in RFC 6068, a @code{mailto} URL can have the form
@example
@samp{mailto:@var{mailbox}[?@var{header}=@var{contents}[&@var{header}=@var{contents}]]}
diff --git a/lisp/mail/mailclient.el b/lisp/mail/mailclient.el
index 31da6ee..bef2038 100644
--- a/lisp/mail/mailclient.el
+++ b/lisp/mail/mailclient.el
@@ -62,10 +62,9 @@ supported. Defaults to non-nil on Windows, nil otherwise."
(mapcar
(lambda (char)
(cond
- ((eq char ?\x20) "%20") ;; space
((eq char ?\n) "%0D%0A") ;; newline
- ((string-match "[-a-zA-Z0-9_:/.@]" (char-to-string char))
- (char-to-string char)) ;; printable
+ ((string-match "[-a-zA-Z0-9._~]" (char-to-string char))
+ (char-to-string char)) ;; unreserved as per RFC 6068
(t ;; everything else
(format "%%%02x" char)))) ;; escape
;; Convert string to list of chars
@@ -125,6 +124,13 @@ The mail client is taken to be the handler of mailto URLs."
(< (point) delimline))
(replace-match "\n"))
(let ((case-fold-search t)
+ (mime-charset-pattern
+ (concat
+ "^content-type:[ \t]*text/plain;"
+ "\\(?:[ \t\n]*\\(?:format\\|delsp\\)=\"?[-a-z0-9]+\"?;\\)*"
+ "[ \t\n]*charset=\"?\\([^ \t\n\";]+\\)\"?"))
+ coding-system
+ character-coding
;; Use the external browser function to send the
;; message.
(browse-url-mailto-function nil))
@@ -135,6 +141,15 @@ The mail client is taken to be the handler of mailto URLs."
(concat
(save-excursion
(narrow-to-region (point-min) delimline)
+ (goto-char (point-min))
+ (setq coding-system
+ (if (re-search-forward mime-charset-pattern nil t)
+ (coding-system-from-name (match-string 1))
+ 'undecided))
+ (setq character-coding
+ (mail-fetch-field "content-transfer-encoding"))
+ (when character-coding
+ (setq character-coding (downcase character-coding)))
(concat
"mailto:"
;; some of the headers according to RFC822
@@ -171,7 +186,26 @@ The mail client is taken to be the handler of mailto URLs."
"*** E-Mail body has been placed on clipboard, "
"please paste it here! ***"))
;; else
- (buffer-substring (+ 1 delimline) (point-max))))))))))))
+ (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)))))))))))))
(provide 'mailclient)
--
2.1.4
next prev parent reply other threads:[~2015-09-14 16:38 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <<55F5CBA0.90406@cs.ucla.edu>
[not found] ` <<065d972a-464a-4d55-9b67-29b3827caeb9@default>
[not found] ` <<83si6ha5dd.fsf@gnu.org>
2015-09-14 13:41 ` bug#21471: 25.0.50; bug report with text from Info has spurious escape chars Drew Adams
2015-09-14 16:38 ` Paul Eggert [this message]
2015-09-14 18:20 ` Eli Zaretskii
2015-09-14 21:10 ` Paul Eggert
2015-09-15 6:56 ` Eli Zaretskii
[not found] <<cde9bbc9-378e-4656-8d10-caf2b8e208b7@default>
[not found] ` <<83wpvu9jf1.fsf@gnu.org>
2015-09-13 20:58 ` bug#21471: 25.0.50; REGRESSION: " Drew Adams
2015-09-14 6:22 ` Eli Zaretskii
[not found] ` <<ad82df82-fa76-4fcf-bd11-0b15de8dcb3a@default>
[not found] ` <<83r3m1a5bf.fsf@gnu.org>
2015-09-14 13:47 ` Drew Adams
2015-09-13 15:07 Drew Adams
2015-09-13 19:16 ` bug#21471: 25.0.50; " Paul Eggert
2015-09-13 20:55 ` Drew Adams
2015-09-14 6:21 ` Eli Zaretskii
2015-09-13 20:02 ` bug#21471: 25.0.50; REGRESSION: " Eli Zaretskii
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=55F6F805.8010506@cs.ucla.edu \
--to=eggert@cs.ucla.edu \
--cc=21471-done@debbugs.gnu.org \
--cc=drew.adams@oracle.com \
--cc=eliz@gnu.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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.