Mercurial > emacs
annotate lisp/gnus/rfc2231.el @ 96215:ad9760e68890
(Todo): Update.
author | Dan Nicolaescu <dann@ics.uci.edu> |
---|---|
date | Tue, 24 Jun 2008 03:24:38 +0000 |
parents | 15ffd5c2dc17 |
children | a9dc0e7c3f2b |
rev | line source |
---|---|
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
1 ;;; rfc2231.el --- Functions for decoding rfc2231 headers |
31717 | 2 |
74548 | 3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, |
79708 | 4 ;; 2006, 2007, 2008 Free Software Foundation, Inc. |
31717 | 5 |
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org> | |
7 ;; This file is part of GNU Emacs. | |
8 | |
94662
f42ef85caf91
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
9 ;; GNU Emacs is free software: you can redistribute it and/or modify |
31717 | 10 ;; it under the terms of the GNU General Public License as published by |
94662
f42ef85caf91
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
11 ;; the Free Software Foundation, either version 3 of the License, or |
f42ef85caf91
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
12 ;; (at your option) any later version. |
31717 | 13 |
14 ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
94662
f42ef85caf91
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
31717 | 17 ;; GNU General Public License for more details. |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
94662
f42ef85caf91
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
31717 | 21 |
22 ;;; Commentary: | |
23 | |
24 ;;; Code: | |
25 | |
33121
228696a7231c
2000-11-01 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
26 (eval-when-compile (require 'cl)) |
31717 | 27 (require 'ietf-drums) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
28 (require 'rfc2047) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
29 (autoload 'mm-encode-body "mm-bodies") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
30 (autoload 'mail-header-remove-whitespace "mail-parse") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
31 (autoload 'mail-header-remove-comments "mail-parse") |
31717 | 32 |
33 (defun rfc2231-get-value (ct attribute) | |
34 "Return the value of ATTRIBUTE from CT." | |
35 (cdr (assq attribute (cdr ct)))) | |
36 | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
37 (defun rfc2231-parse-qp-string (string) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
38 "Parse QP-encoded string using `rfc2231-parse-string'. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
39 N.B. This is in violation with RFC2047, but it seem to be in common use." |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
40 (rfc2231-parse-string (rfc2047-decode-string string))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
41 |
68720
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
42 (defun rfc2231-parse-string (string &optional signal-error) |
31717 | 43 "Parse STRING and return a list. |
44 The list will be on the form | |
68720
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
45 `(name (attribute . value) (attribute . value)...)'. |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
46 |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
47 If the optional SIGNAL-ERROR is non-nil, signal an error when this |
68940
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
48 function fails in parsing of parameters. Otherwise, this function |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
49 must never cause a Lisp error." |
31717 | 50 (with-temp-buffer |
51 (let ((ttoken (ietf-drums-token-to-list ietf-drums-text-token)) | |
52 (stoken (ietf-drums-token-to-list ietf-drums-tspecials)) | |
53 (ntoken (ietf-drums-token-to-list "0-9")) | |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
54 c type attribute encoded number parameters value) |
68940
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
55 (ietf-drums-init |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
56 (condition-case nil |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
57 (mail-header-remove-whitespace |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
58 (mail-header-remove-comments string)) |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
59 ;; The most likely cause of an error is unbalanced parentheses |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
60 ;; or double-quotes. If all parentheses and double-quotes are |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
61 ;; quoted meaninglessly with backslashes, removing them might |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
62 ;; make it parseable. Let's try... |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
63 (error |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
64 (let (mod) |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
65 (when (and (string-match "\\\\\"" string) |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
66 (not (string-match "\\`\"\\|[^\\]\"" string))) |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
67 (setq string (mm-replace-in-string string "\\\\\"" "\"") |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
68 mod t)) |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
69 (when (and (string-match "\\\\(" string) |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
70 (string-match "\\\\)" string) |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
71 (not (string-match "\\`(\\|[^\\][()]" string))) |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
72 (setq string (mm-replace-in-string string "\\\\\\([()]\\)" "\\1") |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
73 mod t)) |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
74 (or (and mod |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
75 (ignore-errors |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
76 (mail-header-remove-whitespace |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
77 (mail-header-remove-comments string)))) |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
78 ;; Finally, attempt to extract only type. |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
79 (if (string-match |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
80 (concat "\\`[\t\n ]*\\([^" ietf-drums-tspecials "\t\n ]+" |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
81 "\\(?:/[^" ietf-drums-tspecials |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
82 "\t\n ]+\\)?\\)\\(?:[\t\n ;]\\|\\'\\)") |
68940
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
83 string) |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
84 (match-string 1 string) |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
85 "")))))) |
31717 | 86 (let ((table (copy-syntax-table ietf-drums-syntax-table))) |
87 (modify-syntax-entry ?\' "w" table) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
88 (modify-syntax-entry ?* " " table) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
89 (modify-syntax-entry ?\; " " table) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
90 (modify-syntax-entry ?= " " table) |
31717 | 91 ;; The following isn't valid, but one should be liberal |
92 ;; in what one receives. | |
93 (modify-syntax-entry ?\: "w" table) | |
94 (set-syntax-table table)) | |
95 (setq c (char-after)) | |
96 (when (and (memq c ttoken) | |
68940
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
97 (not (memq c stoken)) |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
98 (setq type (ignore-errors |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
99 (downcase |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
100 (buffer-substring (point) (progn |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
101 (forward-sexp 1) |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
102 (point))))))) |
31717 | 103 ;; Do the params |
68720
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
104 (condition-case err |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
105 (progn |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
106 (while (not (eobp)) |
31717 | 107 (setq c (char-after)) |
68720
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
108 (unless (eq c ?\;) |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
109 (error "Invalid header: %s" string)) |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
110 (forward-char 1) |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
111 ;; If c in nil, then this is an invalid header, but |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
112 ;; since elm generates invalid headers on this form, |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
113 ;; we allow it. |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
114 (when (setq c (char-after)) |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
115 (if (and (memq c ttoken) |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
116 (not (memq c stoken))) |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
117 (setq attribute |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
118 (intern |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
119 (downcase |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
120 (buffer-substring |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
121 (point) (progn (forward-sexp 1) (point)))))) |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
122 (error "Invalid header: %s" string)) |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
123 (setq c (char-after)) |
68762
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
124 (if (eq c ?*) |
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
125 (progn |
68720
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
126 (forward-char 1) |
68762
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
127 (setq c (char-after)) |
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
128 (if (not (memq c ntoken)) |
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
129 (setq encoded t |
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
130 number nil) |
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
131 (setq number |
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
132 (string-to-number |
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
133 (buffer-substring |
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
134 (point) (progn (forward-sexp 1) (point))))) |
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
135 (setq c (char-after)) |
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
136 (when (eq c ?*) |
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
137 (setq encoded t) |
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
138 (forward-char 1) |
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
139 (setq c (char-after))))) |
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
140 (setq number nil |
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
141 encoded nil)) |
68720
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
142 (unless (eq c ?=) |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
143 (error "Invalid header: %s" string)) |
31717 | 144 (forward-char 1) |
68720
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
145 (setq c (char-after)) |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
146 (cond |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
147 ((eq c ?\") |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
148 (setq value (buffer-substring (1+ (point)) |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
149 (progn |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
150 (forward-sexp 1) |
68762
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
151 (1- (point))))) |
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
152 (when encoded |
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
153 (setq value (mapconcat (lambda (c) (format "%%%02x" c)) |
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
154 value "")))) |
68720
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
155 ((and (or (memq c ttoken) |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
156 ;; EXTENSION: Support non-ascii chars. |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
157 (> c ?\177)) |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
158 (not (memq c stoken))) |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
159 (setq value |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
160 (buffer-substring |
67418
28264c86d408
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-668
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
161 (point) |
28264c86d408
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-668
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
162 (progn |
71411 | 163 ;; Jump over asterisk, non-ASCII |
164 ;; and non-boundary characters. | |
165 (while (and c | |
166 (or (eq c ?*) | |
167 (> c ?\177) | |
168 (not (eq (char-syntax c) ? )))) | |
67418
28264c86d408
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-668
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
169 (forward-char 1) |
71411 | 170 (setq c (char-after))) |
67418
28264c86d408
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-668
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
171 (point))))) |
68720
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
172 (t |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
173 (error "Invalid header: %s" string))) |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
174 (push (list attribute value number encoded) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
175 parameters)))) |
68720
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
176 (error |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
177 (setq parameters nil) |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
178 (when signal-error |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
179 (signal (car err) (cdr err))))) |
31717 | 180 |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
181 ;; Now collect and concatenate continuation parameters. |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
182 (let ((cparams nil) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
183 elem) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
184 (loop for (attribute value part encoded) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
185 in (sort parameters (lambda (e1 e2) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
186 (< (or (caddr e1) 0) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
187 (or (caddr e2) 0)))) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
188 do (if (or (not (setq elem (assq attribute cparams))) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
189 (and (numberp part) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
190 (zerop part))) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
191 (push (list attribute value encoded) cparams) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
192 (setcar (cdr elem) (concat (cadr elem) value)))) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
193 ;; Finally decode encoded values. |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
194 (cons type (mapcar |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
195 (lambda (elem) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
196 (cons (car elem) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
197 (if (nth 2 elem) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
198 (rfc2231-decode-encoded-string (nth 1 elem)) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
199 (nth 1 elem)))) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
200 (nreverse cparams)))))))) |
31717 | 201 |
202 (defun rfc2231-decode-encoded-string (string) | |
203 "Decode an RFC2231-encoded string. | |
68762
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
204 These look like: |
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
205 \"us-ascii'en-us'This%20is%20%2A%2A%2Afun%2A%2A%2A\", |
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
206 \"us-ascii''This%20is%20%2A%2A%2Afun%2A%2A%2A\", |
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
207 \"'en-us'This%20is%20%2A%2A%2Afun%2A%2A%2A\", |
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
208 \"''This%20is%20%2A%2A%2Afun%2A%2A%2A\", or |
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
209 \"This is ***fun***\"." |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
210 (string-match "\\`\\(?:\\([^']+\\)?'\\([^']+\\)?'\\)?\\(.+\\)" string) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
211 (let ((coding-system (mm-charset-to-coding-system (match-string 1 string))) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
212 ;;(language (match-string 2 string)) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
213 (value (match-string 3 string))) |
69640
69cdb1e84c38
(rfc2231-decode-encoded-string): Work on unibyte
Kenichi Handa <handa@m17n.org>
parents:
68940
diff
changeset
|
214 (mm-with-unibyte-buffer |
68762
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
215 (insert value) |
31717 | 216 (goto-char (point-min)) |
95451 | 217 (while (re-search-forward "%\\([0-9A-Fa-f][0-9A-Fa-f]\\)" nil t) |
31717 | 218 (insert |
219 (prog1 | |
95451 | 220 (string-to-number (match-string 1) 16) |
221 (delete-region (match-beginning 0) (match-end 0))))) | |
68762
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
222 ;; Decode using the charset, if any. |
69640
69cdb1e84c38
(rfc2231-decode-encoded-string): Work on unibyte
Kenichi Handa <handa@m17n.org>
parents:
68940
diff
changeset
|
223 (if (memq coding-system '(nil ascii)) |
69cdb1e84c38
(rfc2231-decode-encoded-string): Work on unibyte
Kenichi Handa <handa@m17n.org>
parents:
68940
diff
changeset
|
224 (buffer-string) |
69cdb1e84c38
(rfc2231-decode-encoded-string): Work on unibyte
Kenichi Handa <handa@m17n.org>
parents:
68940
diff
changeset
|
225 (mm-decode-coding-string (buffer-string) coding-system))))) |
31717 | 226 |
227 (defun rfc2231-encode-string (param value) | |
68720
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
228 "Return and PARAM=VALUE string encoded according to RFC2231. |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
229 Use `mml-insert-parameter' or `mml-insert-parameter-string' to insert |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
230 the result of this function." |
31717 | 231 (let ((control (ietf-drums-token-to-list ietf-drums-no-ws-ctl-token)) |
232 (tspecial (ietf-drums-token-to-list ietf-drums-tspecials)) | |
233 (special (ietf-drums-token-to-list "*'%\n\t")) | |
234 (ascii (ietf-drums-token-to-list ietf-drums-text-token)) | |
235 (num -1) | |
68720
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
236 ;; Don't make lines exceeding 76 column. |
68606
5ea0e0a7dd38
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-42
Miles Bader <miles@gnu.org>
parents:
67418
diff
changeset
|
237 (limit (- 74 (length param))) |
31717 | 238 spacep encodep charsetp charset broken) |
69640
69cdb1e84c38
(rfc2231-decode-encoded-string): Work on unibyte
Kenichi Handa <handa@m17n.org>
parents:
68940
diff
changeset
|
239 (mm-with-multibyte-buffer |
31717 | 240 (insert value) |
241 (goto-char (point-min)) | |
242 (while (not (eobp)) | |
243 (cond | |
244 ((or (memq (following-char) control) | |
245 (memq (following-char) tspecial) | |
246 (memq (following-char) special)) | |
247 (setq encodep t)) | |
248 ((eq (following-char) ? ) | |
249 (setq spacep t)) | |
250 ((not (memq (following-char) ascii)) | |
251 (setq charsetp t))) | |
252 (forward-char 1)) | |
253 (when charsetp | |
254 (setq charset (mm-encode-body))) | |
69644
26ee9321c6d7
(rfc2231-encode-string): Use mm-disable-multibyte
Kenichi Handa <handa@m17n.org>
parents:
69640
diff
changeset
|
255 (mm-disable-multibyte) |
31717 | 256 (cond |
68606
5ea0e0a7dd38
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-42
Miles Bader <miles@gnu.org>
parents:
67418
diff
changeset
|
257 ((or encodep charsetp |
5ea0e0a7dd38
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-42
Miles Bader <miles@gnu.org>
parents:
67418
diff
changeset
|
258 (progn |
5ea0e0a7dd38
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-42
Miles Bader <miles@gnu.org>
parents:
67418
diff
changeset
|
259 (end-of-line) |
5ea0e0a7dd38
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-42
Miles Bader <miles@gnu.org>
parents:
67418
diff
changeset
|
260 (> (current-column) (if spacep (- limit 2) limit)))) |
5ea0e0a7dd38
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-42
Miles Bader <miles@gnu.org>
parents:
67418
diff
changeset
|
261 (setq limit (- limit 6)) |
31717 | 262 (goto-char (point-min)) |
68606
5ea0e0a7dd38
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-42
Miles Bader <miles@gnu.org>
parents:
67418
diff
changeset
|
263 (insert (symbol-name (or charset 'us-ascii)) "''") |
31717 | 264 (while (not (eobp)) |
265 (if (or (not (memq (following-char) ascii)) | |
266 (memq (following-char) control) | |
267 (memq (following-char) tspecial) | |
268 (memq (following-char) special) | |
269 (eq (following-char) ? )) | |
270 (progn | |
68606
5ea0e0a7dd38
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-42
Miles Bader <miles@gnu.org>
parents:
67418
diff
changeset
|
271 (when (>= (current-column) (1- limit)) |
5ea0e0a7dd38
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-42
Miles Bader <miles@gnu.org>
parents:
67418
diff
changeset
|
272 (insert ";\n") |
5ea0e0a7dd38
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-42
Miles Bader <miles@gnu.org>
parents:
67418
diff
changeset
|
273 (setq broken t)) |
31717 | 274 (insert "%" (format "%02x" (following-char))) |
275 (delete-char 1)) | |
68606
5ea0e0a7dd38
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-42
Miles Bader <miles@gnu.org>
parents:
67418
diff
changeset
|
276 (when (> (current-column) limit) |
5ea0e0a7dd38
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-42
Miles Bader <miles@gnu.org>
parents:
67418
diff
changeset
|
277 (insert ";\n") |
5ea0e0a7dd38
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-42
Miles Bader <miles@gnu.org>
parents:
67418
diff
changeset
|
278 (setq broken t)) |
31717 | 279 (forward-char 1))) |
280 (goto-char (point-min)) | |
281 (if (not broken) | |
282 (insert param "*=") | |
283 (while (not (eobp)) | |
68720
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
284 (insert (if (>= num 0) " " "") |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
285 param "*" (format "%d" (incf num)) "*=") |
31717 | 286 (forward-line 1)))) |
287 (spacep | |
288 (goto-char (point-min)) | |
68762
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
289 (insert param "=\"") |
31717 | 290 (goto-char (point-max)) |
291 (insert "\"")) | |
292 (t | |
293 (goto-char (point-min)) | |
68762
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
294 (insert param "="))) |
31717 | 295 (buffer-string)))) |
296 | |
297 (provide 'rfc2231) | |
298 | |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
299 ;; arch-tag: c3ab751d-d108-406a-b301-68882ad8cd63 |
31717 | 300 ;;; rfc2231.el ends here |