Mercurial > emacs
annotate lisp/gnus/rfc2231.el @ 87404:5d4b7a894119
Doc fix.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 25 Dec 2007 22:48:48 +0000 |
parents | a3c27999decb |
children | 107ccd98fa12 880960b70474 |
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, |
75347 | 4 ;; 2006, 2007 Free Software Foundation, Inc. |
31717 | 5 |
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org> | |
7 ;; This file is part of GNU Emacs. | |
8 | |
9 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
10 ;; it under the terms of the GNU General Public License as published by | |
78224
24202b793a08
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
75347
diff
changeset
|
11 ;; the Free Software Foundation; either version 3, or (at your option) |
31717 | 12 ;; any later version. |
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 | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
64085 | 21 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
22 ;; Boston, MA 02110-1301, USA. | |
31717 | 23 |
24 ;;; Commentary: | |
25 | |
26 ;;; Code: | |
27 | |
33121
228696a7231c
2000-11-01 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
28 (eval-when-compile (require 'cl)) |
31717 | 29 (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
|
30 (require 'rfc2047) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
31 (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
|
32 (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
|
33 (autoload 'mail-header-remove-comments "mail-parse") |
31717 | 34 |
35 (defun rfc2231-get-value (ct attribute) | |
36 "Return the value of ATTRIBUTE from CT." | |
37 (cdr (assq attribute (cdr ct)))) | |
38 | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
39 (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
|
40 "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
|
41 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
|
42 (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
|
43 |
68720
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
44 (defun rfc2231-parse-string (string &optional signal-error) |
31717 | 45 "Parse STRING and return a list. |
46 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
|
47 `(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
|
48 |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
49 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
|
50 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
|
51 must never cause a Lisp error." |
31717 | 52 (with-temp-buffer |
53 (let ((ttoken (ietf-drums-token-to-list ietf-drums-text-token)) | |
54 (stoken (ietf-drums-token-to-list ietf-drums-tspecials)) | |
55 (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
|
56 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
|
57 (ietf-drums-init |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
58 (condition-case nil |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
59 (mail-header-remove-whitespace |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
60 (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
|
61 ;; 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
|
62 ;; 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
|
63 ;; 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
|
64 ;; 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
|
65 (error |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
66 (let (mod) |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
67 (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
|
68 (not (string-match "\\`\"\\|[^\\]\"" string))) |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
69 (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
|
70 mod t)) |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
71 (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
|
72 (string-match "\\\\)" string) |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
73 (not (string-match "\\`(\\|[^\\][()]" string))) |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
74 (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
|
75 mod t)) |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
76 (or (and mod |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
77 (ignore-errors |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
78 (mail-header-remove-whitespace |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
79 (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
|
80 ;; 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
|
81 (if (string-match |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
82 (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
|
83 "\\(?:/[^" 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
|
84 "\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
|
85 string) |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
86 (match-string 1 string) |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
87 "")))))) |
31717 | 88 (let ((table (copy-syntax-table ietf-drums-syntax-table))) |
89 (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
|
90 (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
|
91 (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
|
92 (modify-syntax-entry ?= " " table) |
31717 | 93 ;; The following isn't valid, but one should be liberal |
94 ;; in what one receives. | |
95 (modify-syntax-entry ?\: "w" table) | |
96 (set-syntax-table table)) | |
97 (setq c (char-after)) | |
98 (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
|
99 (not (memq c stoken)) |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
100 (setq type (ignore-errors |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
101 (downcase |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
102 (buffer-substring (point) (progn |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
103 (forward-sexp 1) |
808f636eb13e
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-93
Miles Bader <miles@gnu.org>
parents:
68762
diff
changeset
|
104 (point))))))) |
31717 | 105 ;; Do the params |
68720
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
106 (condition-case err |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
107 (progn |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
108 (while (not (eobp)) |
31717 | 109 (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
|
110 (unless (eq c ?\;) |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
111 (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
|
112 (forward-char 1) |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
113 ;; 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
|
114 ;; 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
|
115 ;; we allow it. |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
116 (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
|
117 (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
|
118 (not (memq c stoken))) |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
119 (setq attribute |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
120 (intern |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
121 (downcase |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
122 (buffer-substring |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
123 (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
|
124 (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
|
125 (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
|
126 (if (eq c ?*) |
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
127 (progn |
68720
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
128 (forward-char 1) |
68762
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
129 (setq c (char-after)) |
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
130 (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
|
131 (setq encoded t |
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
132 number nil) |
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
133 (setq number |
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
134 (string-to-number |
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
135 (buffer-substring |
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
136 (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
|
137 (setq c (char-after)) |
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
138 (when (eq c ?*) |
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
139 (setq encoded t) |
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
140 (forward-char 1) |
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
141 (setq c (char-after))))) |
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
142 (setq number nil |
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
143 encoded nil)) |
68720
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
144 (unless (eq c ?=) |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
145 (error "Invalid header: %s" string)) |
31717 | 146 (forward-char 1) |
68720
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
147 (setq c (char-after)) |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
148 (cond |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
149 ((eq c ?\") |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
150 (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
|
151 (progn |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
152 (forward-sexp 1) |
68762
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
153 (1- (point))))) |
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
154 (when encoded |
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
155 (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
|
156 value "")))) |
68720
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
157 ((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
|
158 ;; 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
|
159 (> c ?\177)) |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
160 (not (memq c stoken))) |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
161 (setq value |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
162 (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
|
163 (point) |
28264c86d408
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-668
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
164 (progn |
71411 | 165 ;; Jump over asterisk, non-ASCII |
166 ;; and non-boundary characters. | |
167 (while (and c | |
168 (or (eq c ?*) | |
169 (> c ?\177) | |
170 (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
|
171 (forward-char 1) |
71411 | 172 (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
|
173 (point))))) |
68720
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
174 (t |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
175 (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
|
176 (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
|
177 parameters)))) |
68720
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
178 (error |
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
179 (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
|
180 (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
|
181 (signal (car err) (cdr err))))) |
31717 | 182 |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
183 ;; 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
|
184 (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
|
185 elem) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
186 (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
|
187 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
|
188 (< (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
|
189 (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
|
190 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
|
191 (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
|
192 (zerop part))) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
193 (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
|
194 (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
|
195 ;; 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
|
196 (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
|
197 (lambda (elem) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
198 (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
|
199 (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
|
200 (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
|
201 (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
|
202 (nreverse cparams)))))))) |
31717 | 203 |
204 (defun rfc2231-decode-encoded-string (string) | |
205 "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
|
206 These look like: |
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
207 \"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
|
208 \"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
|
209 \"'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
|
210 \"''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
|
211 \"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
|
212 (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
|
213 (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
|
214 ;;(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
|
215 (value (match-string 3 string))) |
69640
69cdb1e84c38
(rfc2231-decode-encoded-string): Work on unibyte
Kenichi Handa <handa@m17n.org>
parents:
68940
diff
changeset
|
216 (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
|
217 (insert value) |
31717 | 218 (goto-char (point-min)) |
219 (while (search-forward "%" nil t) | |
220 (insert | |
221 (prog1 | |
222 (string-to-number (buffer-substring (point) (+ (point) 2)) 16) | |
223 (delete-region (1- (point)) (+ (point) 2))))) | |
68762
970bf6e6463b
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents:
68720
diff
changeset
|
224 ;; Decode using the charset, if any. |
69640
69cdb1e84c38
(rfc2231-decode-encoded-string): Work on unibyte
Kenichi Handa <handa@m17n.org>
parents:
68940
diff
changeset
|
225 (if (memq coding-system '(nil ascii)) |
69cdb1e84c38
(rfc2231-decode-encoded-string): Work on unibyte
Kenichi Handa <handa@m17n.org>
parents:
68940
diff
changeset
|
226 (buffer-string) |
69cdb1e84c38
(rfc2231-decode-encoded-string): Work on unibyte
Kenichi Handa <handa@m17n.org>
parents:
68940
diff
changeset
|
227 (mm-decode-coding-string (buffer-string) coding-system))))) |
31717 | 228 |
229 (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
|
230 "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
|
231 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
|
232 the result of this function." |
31717 | 233 (let ((control (ietf-drums-token-to-list ietf-drums-no-ws-ctl-token)) |
234 (tspecial (ietf-drums-token-to-list ietf-drums-tspecials)) | |
235 (special (ietf-drums-token-to-list "*'%\n\t")) | |
236 (ascii (ietf-drums-token-to-list ietf-drums-text-token)) | |
237 (num -1) | |
68720
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
238 ;; 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
|
239 (limit (- 74 (length param))) |
31717 | 240 spacep encodep charsetp charset broken) |
69640
69cdb1e84c38
(rfc2231-decode-encoded-string): Work on unibyte
Kenichi Handa <handa@m17n.org>
parents:
68940
diff
changeset
|
241 (mm-with-multibyte-buffer |
31717 | 242 (insert value) |
243 (goto-char (point-min)) | |
244 (while (not (eobp)) | |
245 (cond | |
246 ((or (memq (following-char) control) | |
247 (memq (following-char) tspecial) | |
248 (memq (following-char) special)) | |
249 (setq encodep t)) | |
250 ((eq (following-char) ? ) | |
251 (setq spacep t)) | |
252 ((not (memq (following-char) ascii)) | |
253 (setq charsetp t))) | |
254 (forward-char 1)) | |
255 (when charsetp | |
256 (setq charset (mm-encode-body))) | |
69644
26ee9321c6d7
(rfc2231-encode-string): Use mm-disable-multibyte
Kenichi Handa <handa@m17n.org>
parents:
69640
diff
changeset
|
257 (mm-disable-multibyte) |
31717 | 258 (cond |
68606
5ea0e0a7dd38
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-42
Miles Bader <miles@gnu.org>
parents:
67418
diff
changeset
|
259 ((or encodep charsetp |
5ea0e0a7dd38
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-42
Miles Bader <miles@gnu.org>
parents:
67418
diff
changeset
|
260 (progn |
5ea0e0a7dd38
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-42
Miles Bader <miles@gnu.org>
parents:
67418
diff
changeset
|
261 (end-of-line) |
5ea0e0a7dd38
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-42
Miles Bader <miles@gnu.org>
parents:
67418
diff
changeset
|
262 (> (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
|
263 (setq limit (- limit 6)) |
31717 | 264 (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
|
265 (insert (symbol-name (or charset 'us-ascii)) "''") |
31717 | 266 (while (not (eobp)) |
267 (if (or (not (memq (following-char) ascii)) | |
268 (memq (following-char) control) | |
269 (memq (following-char) tspecial) | |
270 (memq (following-char) special) | |
271 (eq (following-char) ? )) | |
272 (progn | |
68606
5ea0e0a7dd38
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-42
Miles Bader <miles@gnu.org>
parents:
67418
diff
changeset
|
273 (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
|
274 (insert ";\n") |
5ea0e0a7dd38
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-42
Miles Bader <miles@gnu.org>
parents:
67418
diff
changeset
|
275 (setq broken t)) |
31717 | 276 (insert "%" (format "%02x" (following-char))) |
277 (delete-char 1)) | |
68606
5ea0e0a7dd38
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-42
Miles Bader <miles@gnu.org>
parents:
67418
diff
changeset
|
278 (when (> (current-column) limit) |
5ea0e0a7dd38
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-42
Miles Bader <miles@gnu.org>
parents:
67418
diff
changeset
|
279 (insert ";\n") |
5ea0e0a7dd38
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-42
Miles Bader <miles@gnu.org>
parents:
67418
diff
changeset
|
280 (setq broken t)) |
31717 | 281 (forward-char 1))) |
282 (goto-char (point-min)) | |
283 (if (not broken) | |
284 (insert param "*=") | |
285 (while (not (eobp)) | |
68720
d9dde5b81e71
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-57
Miles Bader <miles@gnu.org>
parents:
68606
diff
changeset
|
286 (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
|
287 param "*" (format "%d" (incf num)) "*=") |
31717 | 288 (forward-line 1)))) |
289 (spacep | |
290 (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
|
291 (insert param "=\"") |
31717 | 292 (goto-char (point-max)) |
293 (insert "\"")) | |
294 (t | |
295 (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
|
296 (insert param "="))) |
31717 | 297 (buffer-string)))) |
298 | |
299 (provide 'rfc2231) | |
300 | |
52401 | 301 ;;; arch-tag: c3ab751d-d108-406a-b301-68882ad8cd63 |
31717 | 302 ;;; rfc2231.el ends here |