From 1d6a4283e41381e9f6155ce398f20d3408e1c4c7 Mon Sep 17 00:00:00 2001 From: "Richard M. Stallman" Date: Sat, 12 Apr 1997 20:09:17 +0000 Subject: [PATCH] (mail-quote-printable, mail-unquote-printable) (mail-unquote-printable-hexdigit): New functions. --- lisp/mail/mail-utils.el | 43 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/lisp/mail/mail-utils.el b/lisp/mail/mail-utils.el index 71dd1950728..95450544248 100644 --- a/lisp/mail/mail-utils.el +++ b/lisp/mail/mail-utils.el @@ -57,6 +57,49 @@ from START (inclusive) to END (exclusive)." (concat (substring string 0 start) (substring string end nil)))) +(defun mail-quote-printable (string &optional wrapper) + "Convert a string to the \"quoted printable\" Q encoding. +If the optional argument WRAPPER is non-nil, +we add the wrapper characters =3D?ISO-8859-1?Q?....?=3D." + (let ((i 0) (result "")) + (save-match-data + (while (string-match "[?=\"\200-\377]" string i) + (setq result + (concat result (substring string i (match-beginning 0)) + (upcase (format "=%02x" + (aref string (match-beginning 0)))))) + (setq i (match-end 0))) + (if wrapper + (concat "=3D?ISO-8859-1?Q?" + result (substring string i) + "?=3D") + (concat result (substring string i)))))) + +(defun mail-unquote-printable-hexdigit (char) + (if (>= char ?A) + (+ (- char ?A) 10) + (- char ?0))) + +(defun mail-unquote-printable (string &optional wrapper) + "Undo the \"quoted printable\" encoding. +If the optional argument WRAPPER is non-nil, +we expect to find and remove the wrapper characters =3D?ISO-8859-1?Q?....?=3D." + (save-match-data + (and wrapper + (string-match "\\`=3D\\?ISO-8859-1\\?Q\\?\\([^?]*\\)\\?" string) + (setq string (match-string 1 string))) + (let ((i 0) (result "")) + (while (string-match "=\\(..\\)" string i) + (setq result + (concat result (substring string i (match-beginning 0)) + (make-string 1 + (+ (* 16 (mail-unquote-printable-hexdigit + (aref string (match-beginning 1)))) + (mail-unquote-printable-hexdigit + (aref string (1+ (match-beginning 1)))))))) + (setq i (match-end 0))) + (concat result (substring string i))))) + (defun mail-strip-quoted-names (address) "Delete comments and quoted strings in an address list ADDRESS. Also delete leading/trailing whitespace and replace FOO with just BAR. -- 2.39.5