Changeset 4161 for trunk/lisp/gnus/rfc2047.el
- Timestamp:
- 09/09/06 16:30:10 (2 years ago)
- Files:
-
- trunk/lisp/gnus/rfc2047.el (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lisp/gnus/rfc2047.el
r4058 r4161 172 172 (buffer-substring-no-properties (point) (point-max))))) 173 173 174 (defun rfc2047-quote-special-characters-in-quoted-strings (&optional 175 encodable-regexp) 176 "Quote special characters with `\\'s in quoted strings. 177 Quoting will not be done in a quoted string if it contains characters 178 matching ENCODABLE-REGEXP." 179 (goto-char (point-min)) 180 (let ((tspecials (concat "[" ietf-drums-tspecials "]")) 181 beg) 182 (with-syntax-table (standard-syntax-table) 183 (while (search-forward "\"" nil t) 184 (unless (eq (char-before) ?\\) 185 (setq beg (match-end 0)) 186 (goto-char (match-beginning 0)) 187 (condition-case nil 188 (progn 189 (forward-sexp) 190 (save-restriction 191 (narrow-to-region beg (1- (point))) 192 (goto-char beg) 193 (unless (and encodable-regexp 194 (re-search-forward encodable-regexp nil t)) 195 (while (re-search-forward tspecials nil 'move) 196 (unless (and (eq (char-before) ?\\) ;; Already quoted. 197 (looking-at tspecials)) 198 (goto-char (match-beginning 0)) 199 (unless (or (eq (char-before) ?\\) 200 (and rfc2047-encode-encoded-words 201 (eq (char-after) ??) 202 (eq (char-before) ?=))) 203 (insert "\\"))) 204 (forward-char))))) 205 (error 206 (goto-char beg)))))))) 207 174 208 (defvar rfc2047-encoding-type 'address-mime 175 209 "The type of encoding done by `rfc2047-encode-region'. … … 188 222 (save-restriction 189 223 (rfc2047-narrow-to-field) 224 (setq method nil 225 alist rfc2047-header-encoding-alist) 226 (while (setq elem (pop alist)) 227 (when (or (and (stringp (car elem)) 228 (looking-at (car elem))) 229 (eq (car elem) t)) 230 (setq alist nil 231 method (cdr elem)))) 190 232 (if (not (rfc2047-encodable-p)) 191 (prog1 233 (prog2 234 (when (eq method 'address-mime) 235 (rfc2047-quote-special-characters-in-quoted-strings)) 192 236 (if (and (eq (mm-body-7-or-8) '8bit) 193 237 (mm-multibyte-p) … … 210 254 (point-max)))) 211 255 ;; We found something that may perhaps be encoded. 212 (setq method nil213 alist rfc2047-header-encoding-alist)214 (while (setq elem (pop alist))215 (when (or (and (stringp (car elem))216 (looking-at (car elem)))217 (eq (car elem) t))218 (setq alist nil219 method (cdr elem))))220 256 (re-search-forward "^[^:]+: *" nil t) 221 257 (cond … … 348 384 (goto-char end)))) 349 385 ;; `address-mime' case -- take care of quoted words, comments. 386 (rfc2047-quote-special-characters-in-quoted-strings encodable-regexp) 350 387 (with-syntax-table rfc2047-syntax-table 351 388 (goto-char (point-min)) … … 822 859 them.") 823 860 861 (defun rfc2047-strip-backslashes-in-quoted-strings () 862 "Strip backslashes in quoted strings. `\\\"' remains." 863 (goto-char (point-min)) 864 (let (beg) 865 (with-syntax-table (standard-syntax-table) 866 (while (search-forward "\"" nil t) 867 (unless (eq (char-before) ?\\) 868 (setq beg (match-end 0)) 869 (goto-char (match-beginning 0)) 870 (condition-case nil 871 (progn 872 (forward-sexp) 873 (save-restriction 874 (narrow-to-region beg (1- (point))) 875 (goto-char beg) 876 (while (search-forward "\\" nil 'move) 877 (unless (memq (char-after) '(?\")) 878 (delete-backward-char 1)) 879 (forward-char))) 880 (forward-char)) 881 (error 882 (goto-char beg)))))))) 883 824 884 (defun rfc2047-charset-to-coding-system (charset) 825 885 "Return coding-system corresponding to MIME CHARSET. … … 899 959 ;; `=?iso-8859-1?q?foo?=@'. 900 960 901 (defun rfc2047-decode-region (start end) 902 "Decode MIME-encoded words in region between START and END." 961 (defun rfc2047-decode-region (start end &optional address-mime) 962 "Decode MIME-encoded words in region between START and END. 963 If ADDRESS-MIME is non-nil, strip backslashes which precede characters 964 other than `\"' and `\\' in quoted strings." 903 965 (interactive "r") 904 966 (let ((case-fold-search t) … … 911 973 (save-restriction 912 974 (narrow-to-region start end) 975 (when address-mime 976 (rfc2047-strip-backslashes-in-quoted-strings)) 913 977 (goto-char (setq b start)) 914 978 ;; Look for the encoded-words. … … 996 1060 (mm-decode-coding-region b (point-max) mail-parse-charset)))))) 997 1061 998 (defun rfc2047-decode-string (string) 999 "Decode the quoted-printable-encoded STRING and return the results." 1062 (defun rfc2047-decode-address-region (start end) 1063 "Decode MIME-encoded words in region between START and END. 1064 Backslashes which precede characters other than `\"' and `\\' in quoted 1065 strings are stripped." 1066 (rfc2047-decode-region start end t)) 1067 1068 (defun rfc2047-decode-string (string &optional address-mime) 1069 "Decode MIME-encoded STRING and return the result. 1070 If ADDRESS-MIME is non-nil, strip backslashes which precede characters 1071 other than `\"' and `\\' in quoted strings." 1000 1072 (let ((m (mm-multibyte-p))) 1001 1073 (if (string-match "=\\?" string) … … 1011 1083 (insert string) 1012 1084 (inline 1013 (rfc2047-decode-region (point-min) (point-max) ))1085 (rfc2047-decode-region (point-min) (point-max) address-mime)) 1014 1086 (buffer-string)) 1087 (when address-mime 1088 (setq string 1089 (with-temp-buffer 1090 (when (mm-multibyte-string-p string) 1091 (mm-enable-multibyte)) 1092 (insert string) 1093 (rfc2047-strip-backslashes-in-quoted-strings) 1094 (buffer-string)))) 1015 1095 ;; Fixme: As above, `m' here is inappropriate. 1016 1096 (if (and m … … 1034 1114 (mm-string-as-multibyte string))))) 1035 1115 1116 (defun rfc2047-decode-address-string (string) 1117 "Decode MIME-encoded STRING and return the result. 1118 Backslashes which precede characters other than `\"' and `\\' in quoted 1119 strings are stripped." 1120 (rfc2047-decode-string string t)) 1121 1036 1122 (defun rfc2047-pad-base64 (string) 1037 1123 "Pad STRING to quartets."
