summaryrefslogtreecommitdiff
path: root/lisp/mail/rfc6068.el
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2021-08-30 02:03:15 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2021-08-30 02:03:15 +0200
commit1dc79aa8fc4f9cfd675c5c2ad744c9d85a185515 (patch)
tree108177c852baf0581062533334677437a939830a /lisp/mail/rfc6068.el
parent7dabcb15118674be4a6254f1d69d44a3db20c7c4 (diff)
downloademacs-1dc79aa8fc4f9cfd675c5c2ad744c9d85a185515.tar.gz
emacs-1dc79aa8fc4f9cfd675c5c2ad744c9d85a185515.tar.bz2
emacs-1dc79aa8fc4f9cfd675c5c2ad744c9d85a185515.zip
Make epg use rfc6068 for decoding %-encoded strings
* lisp/epg.el (epg--decode-percent-escape-as-utf-8): Make obsolete and adjust callers. (epg--decode-hexstring): Ditto. * lisp/mail/rfc6068.el (rfc6068-unhexify-string): Allow returning non-decoded octets (bug#39689).
Diffstat (limited to 'lisp/mail/rfc6068.el')
-rw-r--r--lisp/mail/rfc6068.el29
1 files changed, 18 insertions, 11 deletions
diff --git a/lisp/mail/rfc6068.el b/lisp/mail/rfc6068.el
index 6198342116e..34fd7b5df4e 100644
--- a/lisp/mail/rfc6068.el
+++ b/lisp/mail/rfc6068.el
@@ -22,17 +22,24 @@
;;; Commentary:
;;; Code:
-(defun rfc6068-unhexify-string (string)
- "Unhexify STRING -- e.g. `hello%20there' -> `hello there'."
- (decode-coding-string
- (with-temp-buffer
- (set-buffer-multibyte nil)
- (insert string)
- (goto-char (point-min))
- (while (re-search-forward "%\\([[:xdigit:]]\\{2\\}\\)" nil t)
- (replace-match (string (string-to-number (match-string 1) 16)) t t))
- (buffer-string))
- 'utf-8))
+(defun rfc6068-unhexify-string (string &optional inhibit-decode)
+ "Unhexify STRING -- e.g. `hello%20there' -> `hello there'.
+STRING is assumed to be a percentage-encoded utf-8 string.
+
+If INHIBIT-DECODE is non-nil, return the resulting raw byte
+string instead of decoding as utf-8."
+ (let ((string
+ (with-temp-buffer
+ (set-buffer-multibyte nil)
+ (insert string)
+ (goto-char (point-min))
+ (while (re-search-forward "%\\([[:xdigit:]]\\{2\\}\\)" nil t)
+ (replace-match (string (string-to-number (match-string 1) 16))
+ t t))
+ (buffer-string))))
+ (if inhibit-decode
+ string
+ (decode-coding-string string 'utf-8))))
(defun rfc6068-parse-mailto-url (mailto-url)
"Parse MAILTO-URL, and return an alist of header-name, header-value pairs.