diff options
| author | Karl Heuer | 1999-08-16 03:14:25 +0000 |
|---|---|---|
| committer | Karl Heuer | 1999-08-16 03:14:25 +0000 |
| commit | 60ba61bb3b1a9c47e751c983afa9ede8a74678fa (patch) | |
| tree | 630c5218f7d6c04217fe7aa725207e5347d00eb3 /lisp | |
| parent | 057df17c4bc0be2a3b2749b437eed10b000bdfea (diff) | |
| download | emacs-60ba61bb3b1a9c47e751c983afa9ede8a74678fa.tar.gz emacs-60ba61bb3b1a9c47e751c983afa9ede8a74678fa.zip | |
(mail-unquote-printable): Make it autoload.
Optimize by calling concat just once. Handle =\n sequence.
(mail-unquote-printable-region): New command.
(mail-quote-printable): Make it autoload.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/mail/mail-utils.el | 45 |
1 files changed, 38 insertions, 7 deletions
diff --git a/lisp/mail/mail-utils.el b/lisp/mail/mail-utils.el index a30d06abacb..f5409512068 100644 --- a/lisp/mail/mail-utils.el +++ b/lisp/mail/mail-utils.el | |||
| @@ -59,6 +59,7 @@ from START (inclusive) to END (exclusive)." | |||
| 59 | (concat (substring string 0 start) | 59 | (concat (substring string 0 start) |
| 60 | (substring string end nil)))) | 60 | (substring string end nil)))) |
| 61 | 61 | ||
| 62 | ;;;###autoload | ||
| 62 | (defun mail-quote-printable (string &optional wrapper) | 63 | (defun mail-quote-printable (string &optional wrapper) |
| 63 | "Convert a string to the \"quoted printable\" Q encoding. | 64 | "Convert a string to the \"quoted printable\" Q encoding. |
| 64 | If the optional argument WRAPPER is non-nil, | 65 | If the optional argument WRAPPER is non-nil, |
| @@ -82,6 +83,7 @@ we add the wrapper characters =?ISO-8859-1?Q?....?=." | |||
| 82 | (+ (- char ?A) 10) | 83 | (+ (- char ?A) 10) |
| 83 | (- char ?0))) | 84 | (- char ?0))) |
| 84 | 85 | ||
| 86 | ;;;###autoload | ||
| 85 | (defun mail-unquote-printable (string &optional wrapper) | 87 | (defun mail-unquote-printable (string &optional wrapper) |
| 86 | "Undo the \"quoted printable\" encoding. | 88 | "Undo the \"quoted printable\" encoding. |
| 87 | If the optional argument WRAPPER is non-nil, | 89 | If the optional argument WRAPPER is non-nil, |
| @@ -90,17 +92,46 @@ we expect to find and remove the wrapper characters =?ISO-8859-1?Q?....?=." | |||
| 90 | (and wrapper | 92 | (and wrapper |
| 91 | (string-match "\\`=\\?ISO-8859-1\\?Q\\?\\([^?]*\\)\\?" string) | 93 | (string-match "\\`=\\?ISO-8859-1\\?Q\\?\\([^?]*\\)\\?" string) |
| 92 | (setq string (match-string 1 string))) | 94 | (setq string (match-string 1 string))) |
| 93 | (let ((i 0) (result "")) | 95 | (let ((i 0) strings) |
| 94 | (while (string-match "=\\(..\\)" string i) | 96 | (while (string-match "=\\(..\\|\n\\)" string i) |
| 95 | (setq result | 97 | (setq strings (cons (substring string i (match-beginning 0)) strings)) |
| 96 | (concat result (substring string i (match-beginning 0)) | 98 | (unless (= (aref string (match-beginning 1)) ?\n) |
| 97 | (make-string 1 | 99 | (setq strings |
| 100 | (cons (make-string 1 | ||
| 98 | (+ (* 16 (mail-unquote-printable-hexdigit | 101 | (+ (* 16 (mail-unquote-printable-hexdigit |
| 99 | (aref string (match-beginning 1)))) | 102 | (aref string (match-beginning 1)))) |
| 100 | (mail-unquote-printable-hexdigit | 103 | (mail-unquote-printable-hexdigit |
| 101 | (aref string (1+ (match-beginning 1)))))))) | 104 | (aref string (1+ (match-beginning 1)))))) |
| 105 | strings))) | ||
| 102 | (setq i (match-end 0))) | 106 | (setq i (match-end 0))) |
| 103 | (concat result (substring string i))))) | 107 | (apply 'concat (nreverse (cons (substring string i) strings)))))) |
| 108 | |||
| 109 | ;;;###autoload | ||
| 110 | (defun mail-unquote-printable-region (beg end &optional wrapper) | ||
| 111 | "Undo the \"quoted printable\" encoding in buffer from BEG to END. | ||
| 112 | If the optional argument WRAPPER is non-nil, | ||
| 113 | we expect to find and remove the wrapper characters =?ISO-8859-1?Q?....?=." | ||
| 114 | (interactive "r\nP") | ||
| 115 | (save-match-data | ||
| 116 | (save-excursion | ||
| 117 | (save-restriction | ||
| 118 | (narrow-to-region beg end) | ||
| 119 | (goto-char (point-min)) | ||
| 120 | (when (and wrapper | ||
| 121 | (looking-at "\\`=\\?ISO-8859-1\\?Q\\?\\([^?]*\\)\\?")) | ||
| 122 | (delete-region (match-end 1) end) | ||
| 123 | (delete-region (point) (match-beginning 1))) | ||
| 124 | (while (re-search-forward "=\\(..\\|\n\\)" nil t) | ||
| 125 | (goto-char (match-end 0)) | ||
| 126 | (replace-match | ||
| 127 | (if (= (char-after (match-beginning 1)) ?\n) | ||
| 128 | "" | ||
| 129 | (make-string 1 | ||
| 130 | (+ (* 16 (mail-unquote-printable-hexdigit | ||
| 131 | (char-after (match-beginning 1)))) | ||
| 132 | (mail-unquote-printable-hexdigit | ||
| 133 | (char-after (1+ (match-beginning 1))))))) | ||
| 134 | t t)))))) | ||
| 104 | 135 | ||
| 105 | (defun mail-strip-quoted-names (address) | 136 | (defun mail-strip-quoted-names (address) |
| 106 | "Delete comments and quoted strings in an address list ADDRESS. | 137 | "Delete comments and quoted strings in an address list ADDRESS. |