Mercurial > emacs
annotate lisp/gnus/rfc2231.el @ 89943:4c90ffeb71c5
Revision: miles@gnu.org--gnu-2004/emacs--unicode--0--patch-15
Merge from emacs--cvs-trunk--0
Patches applied:
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-218
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-220
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-221
Restore deleted tagline in etc/TUTORIAL.ru
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-222
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-228
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-229
Remove TeX output files from the archive
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-230
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-247
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-248
src/lisp.h (CYCLE_CHECK): Macro moved from xfaces.c
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-249
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-256
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-258
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-263
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-264
Update from CVS: lispref/display.texi: emacs -> Emacs.
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-265
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-274
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-275
Update from CVS: man/makefile.w32-in: Revert last change
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-276
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-295
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-296
Allow restarting an existing debugger session that's exited
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-297
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-299
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-300
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-327
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-328
Update from CVS: src/.gdbinit (xsymbol): Fix last change.
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-329
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-344
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-345
Tweak source regexps so that building in place won't cause problems
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-346
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-351
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-352
Update from CVS: lisp/flymake.el: New file.
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-353
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-361
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-362
Support " [...]" style defaults in minibuffer-electric-default-mode
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-363
(read-number): Use canonical format for default in prompt.
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-364
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-367
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-368
Improve display-supports-face-attributes-p on non-ttys
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-369
Rewrite face-differs-from-default-p
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-370
Move `display-supports-face-attributes-p' entirely into C code
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-371
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-372
Simplify face-differs-from-default-p; don't consider :stipple.
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-373
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-374
(tty_supports_face_attributes_p): Ensure attributes differ from default
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-375
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-376
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-377
(Fdisplay_supports_face_attributes_p): Work around bootstrapping problem
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-378
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-380
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-381
Face merging cleanups
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-382
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-384
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-385
src/xfaces.c (push_named_merge_point): Return 0 if a cycle is detected
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-386
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-395
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-396
Tweak arch tagging to make build/install-in-place less annoying
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-397
Work around vc-arch problems when building eshell
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-398
Tweak permissions
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-399
Tweak directory permissions
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-400
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-401
More build-in-place tweaking of arch tagging
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-402
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-403
Yet more build-in-place tweaking of arch tagging
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-404
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-409
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-410
Make sure image types are initialized for lookup too
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-411
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-416
Update from CVS
author | Miles Bader <miles@gnu.org> |
---|---|
date | Mon, 28 Jun 2004 07:56:49 +0000 |
parents | 561b856c5b1f |
children | cce1c0ee76ee |
rev | line source |
---|---|
38413
a26d9b55abb6
Some fixes to follow coding conventions in files from Gnus.
Pavel Janík <Pavel@Janik.cz>
parents:
33342
diff
changeset
|
1 ;;; rfc2231.el --- functions for decoding rfc2231 headers |
31717 | 2 |
3 ;; Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc. | |
4 | |
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org> | |
6 ;; This file is part of GNU Emacs. | |
7 | |
8 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
9 ;; it under the terms of the GNU General Public License as published by | |
10 ;; the Free Software Foundation; either version 2, or (at your option) | |
11 ;; any later version. | |
12 | |
13 ;; GNU Emacs is distributed in the hope that it will be useful, | |
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 ;; GNU General Public License for more details. | |
17 | |
18 ;; You should have received a copy of the GNU General Public License | |
19 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
20 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
21 ;; Boston, MA 02111-1307, USA. | |
22 | |
23 ;;; Commentary: | |
24 | |
25 ;;; Code: | |
26 | |
33121
228696a7231c
2000-11-01 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
27 (eval-when-compile (require 'cl)) |
31717 | 28 (require 'ietf-drums) |
29 | |
30 (defun rfc2231-get-value (ct attribute) | |
31 "Return the value of ATTRIBUTE from CT." | |
32 (cdr (assq attribute (cdr ct)))) | |
33 | |
34 (defun rfc2231-parse-string (string) | |
35 "Parse STRING and return a list. | |
36 The list will be on the form | |
37 `(name (attribute . value) (attribute . value)...)" | |
38 (with-temp-buffer | |
39 (let ((ttoken (ietf-drums-token-to-list ietf-drums-text-token)) | |
40 (stoken (ietf-drums-token-to-list ietf-drums-tspecials)) | |
41 (ntoken (ietf-drums-token-to-list "0-9")) | |
42 (prev-value "") | |
43 display-name mailbox c display-string parameters | |
44 attribute value type subtype number encoded | |
45 prev-attribute) | |
46 (ietf-drums-init (mail-header-remove-whitespace | |
47 (mail-header-remove-comments string))) | |
48 (let ((table (copy-syntax-table ietf-drums-syntax-table))) | |
49 (modify-syntax-entry ?\' "w" table) | |
50 ;; The following isn't valid, but one should be liberal | |
51 ;; in what one receives. | |
52 (modify-syntax-entry ?\: "w" table) | |
53 (set-syntax-table table)) | |
54 (setq c (char-after)) | |
55 (when (and (memq c ttoken) | |
56 (not (memq c stoken))) | |
57 (setq type (downcase (buffer-substring | |
58 (point) (progn (forward-sexp 1) (point))))) | |
59 ;; Do the params | |
60 (while (not (eobp)) | |
61 (setq c (char-after)) | |
62 (unless (eq c ?\;) | |
63 (error "Invalid header: %s" string)) | |
64 (forward-char 1) | |
65 ;; If c in nil, then this is an invalid header, but | |
66 ;; since elm generates invalid headers on this form, | |
67 ;; we allow it. | |
68 (when (setq c (char-after)) | |
69 (if (and (memq c ttoken) | |
70 (not (memq c stoken))) | |
71 (setq attribute | |
72 (intern | |
73 (downcase | |
74 (buffer-substring | |
75 (point) (progn (forward-sexp 1) (point)))))) | |
76 (error "Invalid header: %s" string)) | |
77 (setq c (char-after)) | |
78 (setq encoded nil) | |
79 (when (eq c ?*) | |
80 (forward-char 1) | |
81 (setq c (char-after)) | |
82 (when (memq c ntoken) | |
83 (setq number | |
84 (string-to-number | |
85 (buffer-substring | |
86 (point) (progn (forward-sexp 1) (point))))) | |
87 (setq c (char-after)) | |
88 (when (eq c ?*) | |
89 (setq encoded t) | |
90 (forward-char 1) | |
91 (setq c (char-after))))) | |
92 ;; See if we have any previous continuations. | |
93 (when (and prev-attribute | |
94 (not (eq prev-attribute attribute))) | |
95 (push (cons prev-attribute prev-value) parameters) | |
96 (setq prev-attribute nil | |
97 prev-value "")) | |
98 (unless (eq c ?=) | |
99 (error "Invalid header: %s" string)) | |
100 (forward-char 1) | |
101 (setq c (char-after)) | |
102 (cond | |
103 ((eq c ?\") | |
104 (setq value | |
105 (buffer-substring (1+ (point)) | |
106 (progn (forward-sexp 1) (1- (point)))))) | |
107 ((and (memq c ttoken) | |
108 (not (memq c stoken))) | |
109 (setq value (buffer-substring | |
110 (point) (progn (forward-sexp 1) (point))))) | |
111 (t | |
112 (error "Invalid header: %s" string))) | |
113 (when encoded | |
114 (setq value (rfc2231-decode-encoded-string value))) | |
115 (if number | |
116 (setq prev-attribute attribute | |
117 prev-value (concat prev-value value)) | |
118 (push (cons attribute value) parameters)))) | |
119 | |
120 ;; Take care of any final continuations. | |
121 (when prev-attribute | |
122 (push (cons prev-attribute prev-value) parameters)) | |
123 | |
124 (when type | |
125 `(,type ,@(nreverse parameters))))))) | |
126 | |
127 (defun rfc2231-decode-encoded-string (string) | |
128 "Decode an RFC2231-encoded string. | |
129 These look like \"us-ascii'en-us'This%20is%20%2A%2A%2Afun%2A%2A%2A\"." | |
130 (with-temp-buffer | |
131 (let ((elems (split-string string "'"))) | |
132 ;; The encoded string may contain zero to two single-quote | |
133 ;; marks. This should give us the encoded word stripped | |
134 ;; of any preceding values. | |
135 (insert (car (last elems))) | |
136 (goto-char (point-min)) | |
137 (while (search-forward "%" nil t) | |
138 (insert | |
139 (prog1 | |
140 (string-to-number (buffer-substring (point) (+ (point) 2)) 16) | |
141 (delete-region (1- (point)) (+ (point) 2))))) | |
142 ;; Encode using the charset, if any. | |
143 (when (and (< (length elems) 1) | |
144 (not (equal (intern (car elems)) 'us-ascii))) | |
145 (mm-decode-coding-region (point-min) (point-max) | |
146 (intern (car elems)))) | |
147 (buffer-string)))) | |
148 | |
149 (defun rfc2231-encode-string (param value) | |
150 "Return and PARAM=VALUE string encoded according to RFC2231." | |
151 (let ((control (ietf-drums-token-to-list ietf-drums-no-ws-ctl-token)) | |
152 (tspecial (ietf-drums-token-to-list ietf-drums-tspecials)) | |
153 (special (ietf-drums-token-to-list "*'%\n\t")) | |
154 (ascii (ietf-drums-token-to-list ietf-drums-text-token)) | |
155 (num -1) | |
156 spacep encodep charsetp charset broken) | |
157 (with-temp-buffer | |
158 (insert value) | |
159 (goto-char (point-min)) | |
160 (while (not (eobp)) | |
161 (cond | |
162 ((or (memq (following-char) control) | |
163 (memq (following-char) tspecial) | |
164 (memq (following-char) special)) | |
165 (setq encodep t)) | |
166 ((eq (following-char) ? ) | |
167 (setq spacep t)) | |
168 ((not (memq (following-char) ascii)) | |
169 (setq charsetp t))) | |
170 (forward-char 1)) | |
171 (when charsetp | |
172 (setq charset (mm-encode-body))) | |
173 (cond | |
174 ((or encodep charsetp) | |
175 (goto-char (point-min)) | |
176 (while (not (eobp)) | |
177 (when (> (current-column) 60) | |
178 (insert "\n") | |
179 (setq broken t)) | |
180 (if (or (not (memq (following-char) ascii)) | |
181 (memq (following-char) control) | |
182 (memq (following-char) tspecial) | |
183 (memq (following-char) special) | |
184 (eq (following-char) ? )) | |
185 (progn | |
186 (insert "%" (format "%02x" (following-char))) | |
187 (delete-char 1)) | |
188 (forward-char 1))) | |
189 (goto-char (point-min)) | |
190 (insert (or charset "ascii") "''") | |
191 (goto-char (point-min)) | |
192 (if (not broken) | |
193 (insert param "*=") | |
194 (while (not (eobp)) | |
195 (insert param "*" (format "%d" (incf num)) "*=") | |
196 (forward-line 1)))) | |
197 (spacep | |
198 (goto-char (point-min)) | |
199 (insert param "=\"") | |
200 (goto-char (point-max)) | |
201 (insert "\"")) | |
202 (t | |
203 (goto-char (point-min)) | |
204 (insert param "="))) | |
205 (buffer-string)))) | |
206 | |
207 (provide 'rfc2231) | |
208 | |
89870 | 209 ;;; arch-tag: c3ab751d-d108-406a-b301-68882ad8cd63 |
31717 | 210 ;;; rfc2231.el ends here |