aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorRichard M. Stallman2004-01-12 21:53:39 +0000
committerRichard M. Stallman2004-01-12 21:53:39 +0000
commit1c81a393d55076cea5ffb7d4cb440b687b52904a (patch)
treed20e2091ce9825f278f9bf6e5b2c87dec7854fa3 /lisp
parentbcb6b6b8b1a7bc1f724bb0b5ba3306c760d97c35 (diff)
downloademacs-1c81a393d55076cea5ffb7d4cb440b687b52904a.tar.gz
emacs-1c81a393d55076cea5ffb7d4cb440b687b52904a.zip
(mail-unquote-printable-hexdigit): Upcase CHAR.
(mail-unquote-printable-region): New arg NOERROR. For invalid encoding, either signal an error to just return nil.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/mail/mail-utils.el55
1 files changed, 33 insertions, 22 deletions
diff --git a/lisp/mail/mail-utils.el b/lisp/mail/mail-utils.el
index 628b937529c..e60e8358de9 100644
--- a/lisp/mail/mail-utils.el
+++ b/lisp/mail/mail-utils.el
@@ -79,6 +79,7 @@ we add the wrapper characters =?ISO-8859-1?Q?....?=."
79 (concat result (substring string i)))))) 79 (concat result (substring string i))))))
80 80
81(defun mail-unquote-printable-hexdigit (char) 81(defun mail-unquote-printable-hexdigit (char)
82 (setq char (upcase char))
82 (if (>= char ?A) 83 (if (>= char ?A)
83 (+ (- char ?A) 10) 84 (+ (- char ?A) 10)
84 (- char ?0))) 85 (- char ?0)))
@@ -107,31 +108,41 @@ we expect to find and remove the wrapper characters =?ISO-8859-1?Q?....?=."
107 (apply 'concat (nreverse (cons (substring string i) strings)))))) 108 (apply 'concat (nreverse (cons (substring string i) strings))))))
108 109
109;;;###autoload 110;;;###autoload
110(defun mail-unquote-printable-region (beg end &optional wrapper) 111(defun mail-unquote-printable-region (beg end &optional wrapper noerror)
111 "Undo the \"quoted printable\" encoding in buffer from BEG to END. 112 "Undo the \"quoted printable\" encoding in buffer from BEG to END.
112If the optional argument WRAPPER is non-nil, 113If the optional argument WRAPPER is non-nil,
113we expect to find and remove the wrapper characters =?ISO-8859-1?Q?....?=." 114we expect to find and remove the wrapper characters =?ISO-8859-1?Q?....?=.
115If NOERROR is non-nil, return t if successful."
114 (interactive "r\nP") 116 (interactive "r\nP")
115 (save-match-data 117 (let (failed)
116 (save-excursion 118 (save-match-data
117 (save-restriction 119 (save-excursion
118 (narrow-to-region beg end) 120 (save-restriction
119 (goto-char (point-min)) 121 (narrow-to-region beg end)
120 (when (and wrapper 122 (goto-char (point-min))
121 (looking-at "\\`=\\?ISO-8859-1\\?Q\\?\\([^?]*\\)\\?")) 123 (when (and wrapper
122 (delete-region (match-end 1) end) 124 (looking-at "\\`=\\?ISO-8859-1\\?Q\\?\\([^?]*\\)\\?"))
123 (delete-region (point) (match-beginning 1))) 125 (delete-region (match-end 1) end)
124 (while (re-search-forward "=\\(..\\|\n\\)" nil t) 126 (delete-region (point) (match-beginning 1)))
125 (goto-char (match-end 0)) 127 (while (re-search-forward "=\\(\\([0-9A-F][0-9A-F]\\)\\|[=\n]\\|..\\)" nil t)
126 (replace-match 128 (goto-char (match-end 0))
127 (if (= (char-after (match-beginning 1)) ?\n) 129 (cond ((= (char-after (match-beginning 1)) ?\n)
128 "" 130 (replace-match ""))
129 (make-string 1 131 ((= (char-after (match-beginning 1)) ?=)
130 (+ (* 16 (mail-unquote-printable-hexdigit 132 (replace-match "="))
131 (char-after (match-beginning 1)))) 133 ((match-beginning 2)
132 (mail-unquote-printable-hexdigit 134 (replace-match
133 (char-after (1+ (match-beginning 1))))))) 135 (make-string 1
134 t t)))))) 136 (+ (* 16 (mail-unquote-printable-hexdigit
137 (char-after (match-beginning 2))))
138 (mail-unquote-printable-hexdigit
139 (char-after (1+ (match-beginning 2))))))
140 t t))
141 (noerror
142 (setq failed t))
143 (t
144 (error "Malformed MIME quoted-printable message"))))
145 (not failed))))))
135 146
136(eval-when-compile (require 'rfc822)) 147(eval-when-compile (require 'rfc822))
137 148