Mercurial > emacs
comparison lisp/gnus/rfc2231.el @ 85712:a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-911
author | Miles Bader <miles@gnu.org> |
---|---|
date | Sun, 28 Oct 2007 09:18:39 +0000 |
parents | 24202b793a08 |
children | 107ccd98fa12 880960b70474 |
comparison
equal
deleted
inserted
replaced
85711:b6f5dc84b2e1 | 85712:a3c27999decb |
---|---|
51 must never cause a Lisp error." | 51 must never cause a Lisp error." |
52 (with-temp-buffer | 52 (with-temp-buffer |
53 (let ((ttoken (ietf-drums-token-to-list ietf-drums-text-token)) | 53 (let ((ttoken (ietf-drums-token-to-list ietf-drums-text-token)) |
54 (stoken (ietf-drums-token-to-list ietf-drums-tspecials)) | 54 (stoken (ietf-drums-token-to-list ietf-drums-tspecials)) |
55 (ntoken (ietf-drums-token-to-list "0-9")) | 55 (ntoken (ietf-drums-token-to-list "0-9")) |
56 c type attribute encoded number prev-attribute vals | 56 c type attribute encoded number parameters value) |
57 prev-encoded parameters value) | |
58 (ietf-drums-init | 57 (ietf-drums-init |
59 (condition-case nil | 58 (condition-case nil |
60 (mail-header-remove-whitespace | 59 (mail-header-remove-whitespace |
61 (mail-header-remove-comments string)) | 60 (mail-header-remove-comments string)) |
62 ;; The most likely cause of an error is unbalanced parentheses | 61 ;; The most likely cause of an error is unbalanced parentheses |
79 (mail-header-remove-whitespace | 78 (mail-header-remove-whitespace |
80 (mail-header-remove-comments string)))) | 79 (mail-header-remove-comments string)))) |
81 ;; Finally, attempt to extract only type. | 80 ;; Finally, attempt to extract only type. |
82 (if (string-match | 81 (if (string-match |
83 (concat "\\`[\t\n ]*\\([^" ietf-drums-tspecials "\t\n ]+" | 82 (concat "\\`[\t\n ]*\\([^" ietf-drums-tspecials "\t\n ]+" |
84 "\\(/[^" ietf-drums-tspecials | 83 "\\(?:/[^" ietf-drums-tspecials |
85 "\t\n ]+\\)?\\)\\([\t\n ;]\\|\\'\\)") | 84 "\t\n ]+\\)?\\)\\(?:[\t\n ;]\\|\\'\\)") |
86 string) | 85 string) |
87 (match-string 1 string) | 86 (match-string 1 string) |
88 "")))))) | 87 "")))))) |
89 (let ((table (copy-syntax-table ietf-drums-syntax-table))) | 88 (let ((table (copy-syntax-table ietf-drums-syntax-table))) |
90 (modify-syntax-entry ?\' "w" table) | 89 (modify-syntax-entry ?\' "w" table) |
140 (setq encoded t) | 139 (setq encoded t) |
141 (forward-char 1) | 140 (forward-char 1) |
142 (setq c (char-after))))) | 141 (setq c (char-after))))) |
143 (setq number nil | 142 (setq number nil |
144 encoded nil)) | 143 encoded nil)) |
145 ;; See if we have any previous continuations. | |
146 (when (and prev-attribute | |
147 (not (eq prev-attribute attribute))) | |
148 (setq vals | |
149 (mapconcat 'cdr (sort vals 'car-less-than-car) "")) | |
150 (push (cons prev-attribute | |
151 (if prev-encoded | |
152 (rfc2231-decode-encoded-string vals) | |
153 vals)) | |
154 parameters) | |
155 (setq prev-attribute nil | |
156 vals nil | |
157 prev-encoded nil)) | |
158 (unless (eq c ?=) | 144 (unless (eq c ?=) |
159 (error "Invalid header: %s" string)) | 145 (error "Invalid header: %s" string)) |
160 (forward-char 1) | 146 (forward-char 1) |
161 (setq c (char-after)) | 147 (setq c (char-after)) |
162 (cond | 148 (cond |
185 (forward-char 1) | 171 (forward-char 1) |
186 (setq c (char-after))) | 172 (setq c (char-after))) |
187 (point))))) | 173 (point))))) |
188 (t | 174 (t |
189 (error "Invalid header: %s" string))) | 175 (error "Invalid header: %s" string))) |
190 (if number | 176 (push (list attribute value number encoded) |
191 (progn | 177 parameters)))) |
192 (push (cons number value) vals) | |
193 (setq prev-attribute attribute | |
194 prev-encoded encoded)) | |
195 (push (cons attribute | |
196 (if encoded | |
197 (rfc2231-decode-encoded-string value) | |
198 value)) | |
199 parameters)))) | |
200 | |
201 ;; Take care of any final continuations. | |
202 (when prev-attribute | |
203 (setq vals (mapconcat 'cdr (sort vals 'car-less-than-car) "")) | |
204 (push (cons prev-attribute | |
205 (if prev-encoded | |
206 (rfc2231-decode-encoded-string vals) | |
207 vals)) | |
208 parameters))) | |
209 (error | 178 (error |
210 (setq parameters nil) | 179 (setq parameters nil) |
211 (if signal-error | 180 (when signal-error |
212 (signal (car err) (cdr err)) | 181 (signal (car err) (cdr err))))) |
213 ;;(message "%s" (error-message-string err)) | 182 |
214 ))) | 183 ;; Now collect and concatenate continuation parameters. |
215 | 184 (let ((cparams nil) |
216 (cons type (nreverse parameters)))))) | 185 elem) |
186 (loop for (attribute value part encoded) | |
187 in (sort parameters (lambda (e1 e2) | |
188 (< (or (caddr e1) 0) | |
189 (or (caddr e2) 0)))) | |
190 do (if (or (not (setq elem (assq attribute cparams))) | |
191 (and (numberp part) | |
192 (zerop part))) | |
193 (push (list attribute value encoded) cparams) | |
194 (setcar (cdr elem) (concat (cadr elem) value)))) | |
195 ;; Finally decode encoded values. | |
196 (cons type (mapcar | |
197 (lambda (elem) | |
198 (cons (car elem) | |
199 (if (nth 2 elem) | |
200 (rfc2231-decode-encoded-string (nth 1 elem)) | |
201 (nth 1 elem)))) | |
202 (nreverse cparams)))))))) | |
217 | 203 |
218 (defun rfc2231-decode-encoded-string (string) | 204 (defun rfc2231-decode-encoded-string (string) |
219 "Decode an RFC2231-encoded string. | 205 "Decode an RFC2231-encoded string. |
220 These look like: | 206 These look like: |
221 \"us-ascii'en-us'This%20is%20%2A%2A%2Afun%2A%2A%2A\", | 207 \"us-ascii'en-us'This%20is%20%2A%2A%2Afun%2A%2A%2A\", |
222 \"us-ascii''This%20is%20%2A%2A%2Afun%2A%2A%2A\", | 208 \"us-ascii''This%20is%20%2A%2A%2Afun%2A%2A%2A\", |
223 \"'en-us'This%20is%20%2A%2A%2Afun%2A%2A%2A\", | 209 \"'en-us'This%20is%20%2A%2A%2Afun%2A%2A%2A\", |
224 \"''This%20is%20%2A%2A%2Afun%2A%2A%2A\", or | 210 \"''This%20is%20%2A%2A%2Afun%2A%2A%2A\", or |
225 \"This is ***fun***\"." | 211 \"This is ***fun***\"." |
226 (string-match "\\`\\(\\([^']+\\)?'\\([^']+\\)?'\\)?\\(.+\\)" string) | 212 (string-match "\\`\\(?:\\([^']+\\)?'\\([^']+\\)?'\\)?\\(.+\\)" string) |
227 (let ((coding-system (mm-charset-to-coding-system (match-string 2 string))) | 213 (let ((coding-system (mm-charset-to-coding-system (match-string 1 string))) |
228 ;;(language (match-string 3 string)) | 214 ;;(language (match-string 2 string)) |
229 (value (match-string 4 string))) | 215 (value (match-string 3 string))) |
230 (mm-with-unibyte-buffer | 216 (mm-with-unibyte-buffer |
231 (insert value) | 217 (insert value) |
232 (goto-char (point-min)) | 218 (goto-char (point-min)) |
233 (while (search-forward "%" nil t) | 219 (while (search-forward "%" nil t) |
234 (insert | 220 (insert |