Mercurial > emacs
annotate lisp/gnus/rfc2047.el @ 109805:8d09f7d877e7
nsselect.m: include keyboard.h for QPRIMARY, remove its declaration (Bug#6863).
author | Jan D <jan.h.d@swipnet.se> |
---|---|
date | Mon, 16 Aug 2010 10:03:27 +0200 |
parents | 1f8f03cfcd2b |
children | 8d09094063d0 |
rev | line source |
---|---|
38413
a26d9b55abb6
Some fixes to follow coding conventions in files from Gnus.
Pavel Janík <Pavel@Janik.cz>
parents:
35985
diff
changeset
|
1 ;;; rfc2047.el --- functions for encoding and decoding rfc2047 messages |
60161
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
2 |
104830
79c2323377ac
Use default-value rather than default-enable-multibyte-characters.
Glenn Morris <rgm@gnu.org>
parents:
103027
diff
changeset
|
3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, |
106815 | 4 ;; 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
31717 | 5 |
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org> | |
7 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp> | |
8 ;; This file is part of GNU Emacs. | |
9 | |
94662
f42ef85caf91
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
92777
diff
changeset
|
10 ;; GNU Emacs is free software: you can redistribute it and/or modify |
31717 | 11 ;; 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:
92777
diff
changeset
|
12 ;; 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:
92777
diff
changeset
|
13 ;; (at your option) any later version. |
31717 | 14 |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; 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:
92777
diff
changeset
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
31717 | 18 ;; GNU General Public License for more details. |
19 | |
20 ;; 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:
92777
diff
changeset
|
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
31717 | 22 |
23 ;;; Commentary: | |
24 | |
34674 | 25 ;; RFC 2047 is "MIME (Multipurpose Internet Mail Extensions) Part |
26 ;; Three: Message Header Extensions for Non-ASCII Text". | |
27 | |
31717 | 28 ;;; Code: |
29 | |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
30 (eval-when-compile |
86154 | 31 (require 'cl)) |
32 (defvar message-posting-charset) | |
31717 | 33 |
34 (require 'mm-util) | |
60161
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
35 (require 'ietf-drums) |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
36 ;; Fixme: Avoid this (used for mail-parse-charset) mm dependence on gnus. |
31717 | 37 (require 'mail-prsvr) |
78125 | 38 (require 'rfc2045) ;; rfc2045-encode-string |
33304 | 39 (autoload 'mm-body-7-or-8 "mm-bodies") |
33127
eca95f9d7f05
(base64): Require unconditionally.
Dave Love <fx@gnu.org>
parents:
31764
diff
changeset
|
40 |
31717 | 41 (defvar rfc2047-header-encoding-alist |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
42 '(("Newsgroups" . nil) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
43 ("Followup-To" . nil) |
31717 | 44 ("Message-ID" . nil) |
58835
9bdd97960431
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-716
Miles Bader <miles@gnu.org>
parents:
57243
diff
changeset
|
45 ("\\(Resent-\\)?\\(From\\|Cc\\|To\\|Bcc\\|\\(In-\\)?Reply-To\\|Sender\ |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
46 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\)" . address-mime) |
31717 | 47 (t . mime)) |
48 "*Header/encoding method alist. | |
49 The list is traversed sequentially. The keys can either be | |
33304 | 50 header regexps or t. |
31717 | 51 |
52 The values can be: | |
53 | |
54 1) nil, in which case no encoding is done; | |
55 2) `mime', in which case the header will be encoded according to RFC2047; | |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
56 3) `address-mime', like `mime', but takes account of the rules for address |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
57 fields (where quoted strings and comments must be treated separately); |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
58 4) a charset, in which case it will be encoded as that charset; |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
59 5) `default', in which case the field will be encoded as the rest |
31717 | 60 of the article.") |
61 | |
62 (defvar rfc2047-charset-encoding-alist | |
63 '((us-ascii . nil) | |
64 (iso-8859-1 . Q) | |
65 (iso-8859-2 . Q) | |
66 (iso-8859-3 . Q) | |
67 (iso-8859-4 . Q) | |
68 (iso-8859-5 . B) | |
69 (koi8-r . B) | |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
70 (iso-8859-7 . B) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
71 (iso-8859-8 . B) |
31717 | 72 (iso-8859-9 . Q) |
33304 | 73 (iso-8859-14 . Q) |
74 (iso-8859-15 . Q) | |
31717 | 75 (iso-2022-jp . B) |
76 (iso-2022-kr . B) | |
77 (gb2312 . B) | |
90684
53a222d8d8e8
(rfc2047-charset-encoding-alist): Add gbk and GB18030.
Kenichi Handa <handa@m17n.org>
parents:
90601
diff
changeset
|
78 (gbk . B) |
53a222d8d8e8
(rfc2047-charset-encoding-alist): Add gbk and GB18030.
Kenichi Handa <handa@m17n.org>
parents:
90601
diff
changeset
|
79 (gb18030 . B) |
35838
53eebdb81828
2001-02-01 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
35453
diff
changeset
|
80 (big5 . B) |
53eebdb81828
2001-02-01 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
35453
diff
changeset
|
81 (cn-big5 . B) |
31717 | 82 (cn-gb . B) |
83 (cn-gb-2312 . B) | |
84 (euc-kr . B) | |
85 (iso-2022-jp-2 . B) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
86 (iso-2022-int-1 . B) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
87 (viscii . Q)) |
31717 | 88 "Alist of MIME charsets to RFC2047 encodings. |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
89 Valid encodings are nil, `Q' and `B'. These indicate binary (no) encoding, |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
90 quoted-printable and base64 respectively.") |
31717 | 91 |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
92 (defvar rfc2047-encode-function-alist |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
93 '((Q . rfc2047-q-encode-string) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
94 (B . rfc2047-b-encode-string) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
95 (nil . identity)) |
31717 | 96 "Alist of RFC2047 encodings to encoding functions.") |
97 | |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
98 (defvar rfc2047-encode-encoded-words t |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
99 "Whether encoded words should be encoded again.") |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
100 |
87097 | 101 (defvar rfc2047-allow-irregular-q-encoded-words t |
102 "*Whether to decode irregular Q-encoded words.") | |
103 | |
104 (eval-and-compile ;; Necessary to hard code them in `rfc2047-decode-region'. | |
105 (defconst rfc2047-encoded-word-regexp | |
106 "=\\?\\([^][\000-\040()<>@,\;:*\\\"/?.=]+\\)\\(?:\\*[^?]+\\)?\\?\ | |
107 \\(B\\?[+/0-9A-Za-z]*=*\ | |
108 \\|Q\\?[ ->@-~]*\ | |
109 \\)\\?=" | |
110 "Regexp that matches encoded word." | |
111 ;; The patterns for the B encoding and the Q encoding, i.e. the ones | |
112 ;; beginning with "B" and "Q" respectively, are restricted into only | |
113 ;; the characters that those encodings may generally use. | |
114 ) | |
115 (defconst rfc2047-encoded-word-regexp-loose | |
116 "=\\?\\([^][\000-\040()<>@,\;:*\\\"/?.=]+\\)\\(?:\\*[^?]+\\)?\\?\ | |
117 \\(B\\?[+/0-9A-Za-z]*=*\ | |
118 \\|Q\\?\\(?:\\?+[ -<>@-~]\\)?\\(?:[ ->@-~]+\\?+[ -<>@-~]\\)*[ ->@-~]*\\?*\ | |
119 \\)\\?=" | |
120 "Regexp that matches encoded word allowing loose Q encoding." | |
121 ;; The pattern for the Q encoding, i.e. the one beginning with "Q", | |
122 ;; is similar to: | |
123 ;; "Q\\?\\(\\?+[^\n=?]\\)?\\([^\n?]+\\?+[^\n=?]\\)*[^\n?]*\\?*" | |
124 ;; <--------1-------><----------2,3----------><--4--><-5-> | |
125 ;; They mean: | |
126 ;; 1. After "Q?", allow "?"s that follow a character other than "=". | |
127 ;; 2. Allow "=" after "Q?"; it isn't regarded as the terminator. | |
128 ;; 3. In the middle of an encoded word, allow "?"s that follow a | |
129 ;; character other than "=". | |
130 ;; 4. Allow any characters other than "?" in the middle of an | |
131 ;; encoded word. | |
132 ;; 5. At the end, allow "?"s. | |
133 )) | |
134 | |
31717 | 135 ;;; |
136 ;;; Functions for encoding RFC2047 messages | |
137 ;;; | |
138 | |
57243
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
139 (defun rfc2047-qp-or-base64 () |
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
140 "Return the type with which to encode the buffer. |
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
141 This is either `base64' or `quoted-printable'." |
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
142 (save-excursion |
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
143 (let ((limit (min (point-max) (+ 2000 (point-min)))) |
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
144 (n8bit 0)) |
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
145 (goto-char (point-min)) |
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
146 (skip-chars-forward "\x20-\x7f\r\n\t" limit) |
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
147 (while (< (point) limit) |
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
148 (incf n8bit) |
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
149 (forward-char 1) |
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
150 (skip-chars-forward "\x20-\x7f\r\n\t" limit)) |
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
151 (if (or (< (* 6 n8bit) (- limit (point-min))) |
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
152 ;; Don't base64, say, a short line with a single |
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
153 ;; non-ASCII char when splitting parts by charset. |
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
154 (= n8bit 1)) |
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
155 'quoted-printable |
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
156 'base64)))) |
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
157 |
31717 | 158 (defun rfc2047-narrow-to-field () |
159 "Narrow the buffer to the header on the current line." | |
160 (beginning-of-line) | |
161 (narrow-to-region | |
162 (point) | |
163 (progn | |
164 (forward-line 1) | |
165 (if (re-search-forward "^[^ \n\t]" nil t) | |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
166 (point-at-bol) |
31717 | 167 (point-max)))) |
168 (goto-char (point-min))) | |
169 | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
170 (defun rfc2047-field-value () |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
171 "Return the value of the field at point." |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
172 (save-excursion |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
173 (save-restriction |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
174 (rfc2047-narrow-to-field) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
175 (re-search-forward ":[ \t\n]*" nil t) |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
176 (buffer-substring-no-properties (point) (point-max))))) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
177 |
72605 | 178 (defun rfc2047-quote-special-characters-in-quoted-strings (&optional |
179 encodable-regexp) | |
180 "Quote special characters with `\\'s in quoted strings. | |
181 Quoting will not be done in a quoted string if it contains characters | |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
182 matching ENCODABLE-REGEXP or it is within parentheses." |
72605 | 183 (goto-char (point-min)) |
184 (let ((tspecials (concat "[" ietf-drums-tspecials "]")) | |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
185 (start (point)) |
72810 | 186 beg end) |
72605 | 187 (with-syntax-table (standard-syntax-table) |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
188 (while (not (eobp)) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
189 (if (ignore-errors |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
190 (forward-list 1) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
191 (eq (char-before) ?\))) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
192 (forward-list -1) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
193 (goto-char (point-max))) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
194 (save-restriction |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
195 (narrow-to-region start (point)) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
196 (goto-char start) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
197 (while (search-forward "\"" nil t) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
198 (setq beg (match-beginning 0)) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
199 (unless (eq (char-before beg) ?\\) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
200 (goto-char beg) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
201 (setq beg (1+ beg)) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
202 (condition-case nil |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
203 (progn |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
204 (forward-sexp) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
205 (setq end (1- (point))) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
206 (goto-char beg) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
207 (if (and encodable-regexp |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
208 (re-search-forward encodable-regexp end t)) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
209 (goto-char (1+ end)) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
210 (save-restriction |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
211 (narrow-to-region beg end) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
212 (while (re-search-forward tspecials nil 'move) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
213 (if (eq (char-before) ?\\) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
214 (if (looking-at tspecials) ;; Already quoted. |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
215 (forward-char) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
216 (insert "\\")) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
217 (goto-char (match-beginning 0)) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
218 (insert "\\") |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
219 (forward-char)))) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
220 (forward-char))) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
221 (error |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
222 (goto-char beg))))) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
223 (goto-char (point-max))) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
224 (forward-list 1) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
225 (setq start (point)))))) |
72605 | 226 |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
227 (defvar rfc2047-encoding-type 'address-mime |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
228 "The type of encoding done by `rfc2047-encode-region'. |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
229 This should be dynamically bound around calls to |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
230 `rfc2047-encode-region' to either `mime' or `address-mime'. See |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
231 `rfc2047-header-encoding-alist', for definitions.") |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
232 |
31717 | 233 (defun rfc2047-encode-message-header () |
234 "Encode the message header according to `rfc2047-header-encoding-alist'. | |
235 Should be called narrowed to the head of the message." | |
236 (interactive "*") | |
237 (save-excursion | |
238 (goto-char (point-min)) | |
239 (let (alist elem method) | |
240 (while (not (eobp)) | |
241 (save-restriction | |
242 (rfc2047-narrow-to-field) | |
72605 | 243 (setq method nil |
244 alist rfc2047-header-encoding-alist) | |
245 (while (setq elem (pop alist)) | |
246 (when (or (and (stringp (car elem)) | |
247 (looking-at (car elem))) | |
248 (eq (car elem) t)) | |
249 (setq alist nil | |
250 method (cdr elem)))) | |
31717 | 251 (if (not (rfc2047-encodable-p)) |
72605 | 252 (prog2 |
253 (when (eq method 'address-mime) | |
254 (rfc2047-quote-special-characters-in-quoted-strings)) | |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
255 (if (and (eq (mm-body-7-or-8) '8bit) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
256 (mm-multibyte-p) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
257 (mm-coding-system-p |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
258 (car message-posting-charset))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
259 ;; 8 bit must be decoded. |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
260 (mm-encode-coding-region |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
261 (point-min) (point-max) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
262 (mm-charset-to-coding-system |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
263 (car message-posting-charset)))) |
50881
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
264 ;; No encoding necessary, but folding is nice |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
265 (when nil |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
266 (rfc2047-fold-region |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
267 (save-excursion |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
268 (goto-char (point-min)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
269 (skip-chars-forward "^:") |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
270 (when (looking-at ": ") |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
271 (forward-char 2)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
272 (point)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
273 (point-max)))) |
31717 | 274 ;; We found something that may perhaps be encoded. |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
275 (re-search-forward "^[^:]+: *" nil t) |
31717 | 276 (cond |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
277 ((eq method 'address-mime) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
278 (rfc2047-encode-region (point) (point-max))) |
31717 | 279 ((eq method 'mime) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
280 (let ((rfc2047-encoding-type 'mime)) |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
281 (rfc2047-encode-region (point) (point-max)))) |
31717 | 282 ((eq method 'default) |
283 (if (and (featurep 'mule) | |
104830
79c2323377ac
Use default-value rather than default-enable-multibyte-characters.
Glenn Morris <rgm@gnu.org>
parents:
103027
diff
changeset
|
284 (if (boundp 'enable-multibyte-characters) |
79c2323377ac
Use default-value rather than default-enable-multibyte-characters.
Glenn Morris <rgm@gnu.org>
parents:
103027
diff
changeset
|
285 (default-value 'enable-multibyte-characters)) |
31717 | 286 mail-parse-charset) |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
287 (mm-encode-coding-region (point) (point-max) |
31717 | 288 mail-parse-charset))) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
289 ;; We get this when CC'ing messsages to newsgroups with |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
290 ;; 8-bit names. The group name mail copy just got |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
291 ;; unconditionally encoded. Previously, it would ask |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
292 ;; whether to encode, which was quite confusing for the |
96376
c3309dba6542
American English spelling fix.
Glenn Morris <rgm@gnu.org>
parents:
94662
diff
changeset
|
293 ;; user. If the new behavior is wrong, tell me. I have |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
294 ;; left the old code commented out below. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
295 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-07. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
296 ;; Modified by Dave Love, with the commented-out code changed |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
297 ;; in accordance with changes elsewhere. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
298 ((null method) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
299 (rfc2047-encode-region (point) (point-max))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
300 ;;; ((null method) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
301 ;;; (if (or (message-options-get |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
302 ;;; 'rfc2047-encode-message-header-encode-any) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
303 ;;; (message-options-set |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
304 ;;; 'rfc2047-encode-message-header-encode-any |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
305 ;;; (y-or-n-p |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
306 ;;; "Some texts are not encoded. Encode anyway?"))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
307 ;;; (rfc2047-encode-region (point-min) (point-max)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
308 ;;; (error "Cannot send unencoded text"))) |
31717 | 309 ((mm-coding-system-p method) |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
310 (if (or (and (featurep 'mule) |
104830
79c2323377ac
Use default-value rather than default-enable-multibyte-characters.
Glenn Morris <rgm@gnu.org>
parents:
103027
diff
changeset
|
311 (if (boundp 'enable-multibyte-characters) |
79c2323377ac
Use default-value rather than default-enable-multibyte-characters.
Glenn Morris <rgm@gnu.org>
parents:
103027
diff
changeset
|
312 (default-value 'enable-multibyte-characters))) |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
313 (featurep 'file-coding)) |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
314 (mm-encode-coding-region (point) (point-max) method))) |
31717 | 315 ;; Hm. |
316 (t))) | |
317 (goto-char (point-max))))))) | |
318 | |
35985
b9c371244b90
(rfc2047-fold-region): Don't forward-char at EOB.
Dave Love <fx@gnu.org>
parents:
35838
diff
changeset
|
319 ;; Fixme: This, and the require below may not be the Right Thing, but |
b9c371244b90
(rfc2047-fold-region): Don't forward-char at EOB.
Dave Love <fx@gnu.org>
parents:
35838
diff
changeset
|
320 ;; should be safe just before release. -- fx 2001-02-08 |
b9c371244b90
(rfc2047-fold-region): Don't forward-char at EOB.
Dave Love <fx@gnu.org>
parents:
35838
diff
changeset
|
321 |
33304 | 322 (defun rfc2047-encodable-p () |
323 "Return non-nil if any characters in current buffer need encoding in headers. | |
324 The buffer may be narrowed." | |
35985
b9c371244b90
(rfc2047-fold-region): Don't forward-char at EOB.
Dave Love <fx@gnu.org>
parents:
35838
diff
changeset
|
325 (require 'message) ; for message-posting-charset |
31717 | 326 (let ((charsets |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
327 (mm-find-mime-charset-region (point-min) (point-max)))) |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
328 (goto-char (point-min)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
329 (or (and rfc2047-encode-encoded-words |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
330 (prog1 |
87097 | 331 (re-search-forward rfc2047-encoded-word-regexp nil t) |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
332 (goto-char (point-min)))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
333 (and charsets |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
334 (not (equal charsets (list (car message-posting-charset)))))))) |
31717 | 335 |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
336 ;; Use this syntax table when parsing into regions that may need |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
337 ;; encoding. Double quotes are string delimiters, backslash is |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
338 ;; character quoting, and all other RFC 2822 special characters are |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
339 ;; treated as punctuation so we can use forward-sexp/forward-word to |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
340 ;; skip to the end of regions appropriately. Nb. ietf-drums does |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
341 ;; things differently. |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
342 (defconst rfc2047-syntax-table |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
343 ;; (make-char-table 'syntax-table '(2)) only works in Emacs. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
344 (let ((table (make-syntax-table))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
345 ;; The following is done to work for setting all elements of the table |
90104
a01e7a9f1659
Revision: miles@gnu.org--gnu-2005/emacs--unicode--0--patch-14
Miles Bader <miles@gnu.org>
parents:
90054
diff
changeset
|
346 ;; in Emacs 21-23 and XEmacs; it appears to be the cleanest way. |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
347 ;; Play safe and don't assume the form of the word syntax entry -- |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
348 ;; copy it from ?a. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
349 (if (fboundp 'set-char-table-range) ; Emacs |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
350 (funcall (intern "set-char-table-range") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
351 table t (aref (standard-syntax-table) ?a)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
352 (if (fboundp 'put-char-table) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
353 (if (fboundp 'get-char-table) ; warning avoidance |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
354 (put-char-table t (get-char-table ?a (standard-syntax-table)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
355 table)))) |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
356 (modify-syntax-entry ?\\ "\\" table) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
357 (modify-syntax-entry ?\" "\"" table) |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
358 (modify-syntax-entry ?\( "(" table) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
359 (modify-syntax-entry ?\) ")" table) |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
360 (modify-syntax-entry ?\< "." table) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
361 (modify-syntax-entry ?\> "." table) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
362 (modify-syntax-entry ?\[ "." table) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
363 (modify-syntax-entry ?\] "." table) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
364 (modify-syntax-entry ?: "." table) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
365 (modify-syntax-entry ?\; "." table) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
366 (modify-syntax-entry ?, "." table) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
367 (modify-syntax-entry ?@ "." table) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
368 table)) |
31717 | 369 |
370 (defun rfc2047-encode-region (b e) | |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
371 "Encode words in region B to E that need encoding. |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
372 By default, the region is treated as containing RFC2822 addresses. |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
373 Dynamically bind `rfc2047-encoding-type' to change that." |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
374 (save-restriction |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
375 (narrow-to-region b e) |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
376 (let ((encodable-regexp (if rfc2047-encode-encoded-words |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
377 "[^\000-\177]+\\|=\\?" |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
378 "[^\000-\177]+")) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
379 start ; start of current token |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
380 end begin csyntax |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
381 ;; Whether there's an encoded word before the current token, |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
382 ;; either immediately or separated by space. |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
383 last-encoded |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
384 (orig-text (buffer-substring-no-properties b e))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
385 (if (eq 'mime rfc2047-encoding-type) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
386 ;; Simple case. Continuous words in which all those contain |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
387 ;; non-ASCII characters are encoded collectively. Encoding |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
388 ;; ASCII words, including `Re:' used in Subject headers, is |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
389 ;; avoided for interoperability with non-MIME clients and |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
390 ;; for making it easy to find keywords. |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
391 (progn |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
392 (goto-char (point-min)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
393 (while (progn (skip-chars-forward " \t\n") |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
394 (not (eobp))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
395 (setq start (point)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
396 (while (and (looking-at "[ \t\n]*\\([^ \t\n]+\\)") |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
397 (progn |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
398 (setq end (match-end 0)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
399 (re-search-forward encodable-regexp end t))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
400 (goto-char end)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
401 (if (> (point) start) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
402 (rfc2047-encode start (point)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
403 (goto-char end)))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
404 ;; `address-mime' case -- take care of quoted words, comments. |
72605 | 405 (rfc2047-quote-special-characters-in-quoted-strings encodable-regexp) |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
406 (with-syntax-table rfc2047-syntax-table |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
407 (goto-char (point-min)) |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
408 (condition-case err ; in case of unbalanced quotes |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
409 ;; Look for rfc2822-style: sequences of atoms, quoted |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
410 ;; strings, specials, whitespace. (Specials mustn't be |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
411 ;; encoded.) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
412 (while (not (eobp)) |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
413 ;; Skip whitespace. |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
414 (skip-chars-forward " \t\n") |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
415 (setq start (point)) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
416 (cond |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
417 ((not (char-after))) ; eob |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
418 ;; else token start |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
419 ((eq ?\" (setq csyntax (char-syntax (char-after)))) |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
420 ;; Quoted word. |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
421 (forward-sexp) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
422 (setq end (point)) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
423 ;; Does it need encoding? |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
424 (goto-char start) |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
425 (if (re-search-forward encodable-regexp end 'move) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
426 ;; It needs encoding. Strip the quotes first, |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
427 ;; since encoded words can't occur in quotes. |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
428 (progn |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
429 (goto-char end) |
108765
d835100c3e8b
Replace Lisp calls to delete-backward-char by delete-char.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107427
diff
changeset
|
430 (delete-char -1) |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
431 (goto-char start) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
432 (delete-char 1) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
433 (when last-encoded |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
434 ;; There was a preceding quoted word. We need |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
435 ;; to include any separating whitespace in this |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
436 ;; word to avoid it getting lost. |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
437 (skip-chars-backward " \t") |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
438 ;; A space is needed between the encoded words. |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
439 (insert ? ) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
440 (setq start (point) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
441 end (1+ end))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
442 ;; Adjust the end position for the deleted quotes. |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
443 (rfc2047-encode start (- end 2)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
444 (setq last-encoded t)) ; record that it was encoded |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
445 (setq last-encoded nil))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
446 ((eq ?. csyntax) |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
447 ;; Skip other delimiters, but record that they've |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
448 ;; potentially separated quoted words. |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
449 (forward-char) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
450 (setq last-encoded nil)) |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
451 ((eq ?\) csyntax) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
452 (error "Unbalanced parentheses")) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
453 ((eq ?\( csyntax) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
454 ;; Look for the end of parentheses. |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
455 (forward-list) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
456 ;; Encode text as an unstructured field. |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
457 (let ((rfc2047-encoding-type 'mime)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
458 (rfc2047-encode-region (1+ start) (1- (point)))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
459 (skip-chars-forward ")")) |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
460 (t ; normal token/whitespace sequence |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
461 ;; Find the end. |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
462 ;; Skip one ASCII word, or encode continuous words |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
463 ;; in which all those contain non-ASCII characters. |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
464 (setq end nil) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
465 (while (not (or end (eobp))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
466 (when (looking-at "[\000-\177]+") |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
467 (setq begin (point) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
468 end (match-end 0)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
469 (when (progn |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
470 (while (and (or (re-search-forward |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
471 "[ \t\n]\\|\\Sw" end 'move) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
472 (setq end nil)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
473 (eq ?\\ (char-syntax (char-before)))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
474 ;; Skip backslash-quoted characters. |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
475 (forward-char)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
476 end) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
477 (setq end (match-beginning 0)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
478 (if rfc2047-encode-encoded-words |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
479 (progn |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
480 (goto-char begin) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
481 (when (search-forward "=?" end 'move) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
482 (goto-char (match-beginning 0)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
483 (setq end nil))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
484 (goto-char end)))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
485 ;; Where the value nil of `end' means there may be |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
486 ;; text to have to be encoded following the point. |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
487 ;; Otherwise, the point reached to the end of ASCII |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
488 ;; words separated by whitespace or a special char. |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
489 (unless end |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
490 (when (looking-at encodable-regexp) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
491 (goto-char (setq begin (match-end 0))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
492 (while (and (looking-at "[ \t\n]+\\([^ \t\n]+\\)") |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
493 (setq end (match-end 0)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
494 (progn |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
495 (while (re-search-forward |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
496 encodable-regexp end t)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
497 (< begin (point))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
498 (goto-char begin) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
499 (or (not (re-search-forward "\\Sw" end t)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
500 (progn |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
501 (goto-char (match-beginning 0)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
502 nil))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
503 (goto-char end)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
504 (when (looking-at "[^ \t\n]+") |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
505 (setq end (match-end 0)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
506 (if (re-search-forward "\\Sw+" end t) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
507 ;; There are special characters better |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
508 ;; to be encoded so that MTAs may parse |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
509 ;; them safely. |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
510 (cond ((= end (point))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
511 ((looking-at (concat "\\sw*\\(" |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
512 encodable-regexp |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
513 "\\)")) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
514 (setq end nil)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
515 (t |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
516 (goto-char (1- (match-end 0))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
517 (unless (= (point) (match-beginning 0)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
518 ;; Separate encodable text and |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
519 ;; delimiter. |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
520 (insert " ")))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
521 (goto-char end) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
522 (skip-chars-forward " \t\n") |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
523 (if (and (looking-at "[^ \t\n]+") |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
524 (string-match encodable-regexp |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
525 (match-string 0))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
526 (setq end nil) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
527 (goto-char end))))))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
528 (skip-chars-backward " \t\n") |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
529 (setq end (point)) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
530 (goto-char start) |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
531 (if (re-search-forward encodable-regexp end 'move) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
532 (progn |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
533 (unless (memq (char-before start) '(nil ?\t ? )) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
534 (if (progn |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
535 (goto-char start) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
536 (skip-chars-backward "^ \t\n") |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
537 (and (looking-at "\\Sw+") |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
538 (= (match-end 0) start))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
539 ;; Also encode bogus delimiters. |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
540 (setq start (point)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
541 ;; Separate encodable text and delimiter. |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
542 (goto-char start) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
543 (insert " ") |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
544 (setq start (1+ start) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
545 end (1+ end)))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
546 (rfc2047-encode start end) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
547 (setq last-encoded t)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
548 (setq last-encoded nil))))) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
549 (error |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
550 (if (or debug-on-quit debug-on-error) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
551 (signal (car err) (cdr err)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
552 (error "Invalid data for rfc2047 encoding: %s" |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
553 (mm-replace-in-string orig-text "[ \t\n]+" " ")))))))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
554 (rfc2047-fold-region b (point)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
555 (goto-char (point-max)))) |
31717 | 556 |
557 (defun rfc2047-encode-string (string) | |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
558 "Encode words in STRING. |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
559 By default, the string is treated as containing addresses (see |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
560 `rfc2047-encoding-type')." |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
561 (mm-with-multibyte-buffer |
31717 | 562 (insert string) |
563 (rfc2047-encode-region (point-min) (point-max)) | |
564 (buffer-string))) | |
565 | |
87097 | 566 ;; From RFC 2047: |
567 ;; 2. Syntax of encoded-words | |
568 ;; [...] | |
569 ;; While there is no limit to the length of a multiple-line header | |
570 ;; field, each line of a header field that contains one or more | |
571 ;; 'encoded-word's is limited to 76 characters. | |
572 ;; | |
573 ;; In `rfc2047-encode-parameter' it is bound to nil, so don't defconst it. | |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
574 (defvar rfc2047-encode-max-chars 76 |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
575 "Maximum characters of each header line that contain encoded-words. |
87097 | 576 According to RFC 2047, it is 76. If it is nil, encoded-words |
577 will not be folded. Too small value may cause an error. You | |
578 should not change this value.") | |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
579 |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
580 (defun rfc2047-encode-1 (column string cs encoder start crest tail |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
581 &optional eword) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
582 "Subroutine used by `rfc2047-encode'." |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
583 (cond ((string-equal string "") |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
584 (or eword "")) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
585 ((not rfc2047-encode-max-chars) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
586 (concat start |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
587 (funcall encoder (if cs |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
588 (mm-encode-coding-string string cs) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
589 string)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
590 "?=")) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
591 ((>= column rfc2047-encode-max-chars) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
592 (when eword |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
593 (cond ((string-match "\n[ \t]+\\'" eword) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
594 ;; Reomove a superfluous empty line. |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
595 (setq eword (substring eword 0 (match-beginning 0)))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
596 ((string-match "(+\\'" eword) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
597 ;; Break the line before the open parenthesis. |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
598 (setq crest (concat crest (match-string 0 eword)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
599 eword (substring eword 0 (match-beginning 0)))))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
600 (rfc2047-encode-1 (length crest) string cs encoder start " " tail |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
601 (concat eword "\n" crest))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
602 (t |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
603 (let ((index 0) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
604 (limit (1- (length string))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
605 (prev "") |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
606 next len) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
607 (while (and prev |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
608 (<= index limit)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
609 (setq next (concat start |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
610 (funcall encoder |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
611 (if cs |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
612 (mm-encode-coding-string |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
613 (substring string 0 (1+ index)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
614 cs) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
615 (substring string 0 (1+ index)))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
616 "?=") |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
617 len (+ column (length next))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
618 (if (> len rfc2047-encode-max-chars) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
619 (setq next prev |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
620 prev nil) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
621 (if (or (< index limit) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
622 (<= (+ len (or (string-match "\n" tail) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
623 (length tail))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
624 rfc2047-encode-max-chars)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
625 (setq prev next |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
626 index (1+ index)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
627 (if (string-match "\\`)+" tail) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
628 ;; Break the line after the close parenthesis. |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
629 (setq tail (concat (substring tail 0 (match-end 0)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
630 "\n " |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
631 (substring tail (match-end 0))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
632 prev next |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
633 index (1+ index)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
634 (setq next prev |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
635 prev nil))))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
636 (if (> index limit) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
637 (concat eword next tail) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
638 (if (= 0 index) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
639 (if (and eword |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
640 (string-match "(+\\'" eword)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
641 (setq crest (concat crest (match-string 0 eword)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
642 eword (substring eword 0 (match-beginning 0))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
643 (setq eword (concat eword next))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
644 (setq crest " " |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
645 eword (concat eword next))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
646 (when (string-match "\n[ \t]+\\'" eword) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
647 ;; Reomove a superfluous empty line. |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
648 (setq eword (substring eword 0 (match-beginning 0)))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
649 (rfc2047-encode-1 (length crest) (substring string index) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
650 cs encoder start " " tail |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
651 (concat eword "\n" crest))))))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
652 |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
653 (defun rfc2047-encode (b e) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
654 "Encode the word(s) in the region B to E. |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
655 Point moves to the end of the region." |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
656 (let ((mime-charset (or (mm-find-mime-charset-region b e) (list 'us-ascii))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
657 cs encoding tail crest eword) |
109649
1f8f03cfcd2b
(rfc2047-encode): Use utf-8 charset as a last resort.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
108765
diff
changeset
|
658 ;; Use utf-8 as a last resort if determining charset of text fails. |
1f8f03cfcd2b
(rfc2047-encode): Use utf-8 charset as a last resort.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
108765
diff
changeset
|
659 (if (memq nil mime-charset) |
1f8f03cfcd2b
(rfc2047-encode): Use utf-8 charset as a last resort.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
108765
diff
changeset
|
660 (setq mime-charset (list 'utf-8))) |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
661 (cond ((> (length mime-charset) 1) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
662 (error "Can't rfc2047-encode `%s'" |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
663 (buffer-substring-no-properties b e))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
664 ((= (length mime-charset) 1) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
665 (setq mime-charset (car mime-charset) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
666 cs (mm-charset-to-coding-system mime-charset)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
667 (unless (and (mm-multibyte-p) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
668 (mm-coding-system-p cs)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
669 (setq cs nil)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
670 (save-restriction |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
671 (narrow-to-region b e) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
672 (setq encoding |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
673 (or (cdr (assq mime-charset |
31717 | 674 rfc2047-charset-encoding-alist)) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
675 ;; For the charsets that don't have a preferred |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
676 ;; encoding, choose the one that's shorter. |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
677 (if (eq (rfc2047-qp-or-base64) 'base64) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
678 'B |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
679 'Q))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
680 (widen) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
681 (goto-char e) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
682 (skip-chars-forward "^ \t\n") |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
683 ;; `tail' may contain a close parenthesis. |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
684 (setq tail (buffer-substring-no-properties e (point))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
685 (goto-char b) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
686 (setq b (point-marker) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
687 e (set-marker (make-marker) e)) |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
688 (rfc2047-fold-region (point-at-bol) b) |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
689 (goto-char b) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
690 (skip-chars-backward "^ \t\n") |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
691 (unless (= 0 (skip-chars-backward " \t")) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
692 ;; `crest' may contain whitespace and an open parenthesis. |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
693 (setq crest (buffer-substring-no-properties (point) b))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
694 (setq eword (rfc2047-encode-1 |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
695 (- b (point-at-bol)) |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
696 (mm-replace-in-string |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
697 (buffer-substring-no-properties b e) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
698 "\n\\([ \t]?\\)" "\\1") |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
699 cs |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
700 (or (cdr (assq encoding |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
701 rfc2047-encode-function-alist)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
702 'identity) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
703 (concat "=?" (downcase (symbol-name mime-charset)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
704 "?" (upcase (symbol-name encoding)) "?") |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
705 (or crest " ") |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
706 tail)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
707 (delete-region (if (eq (aref eword 0) ?\n) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
708 (if (bolp) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
709 ;; The line was folded before encoding. |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
710 (1- (point)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
711 (point)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
712 (goto-char b)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
713 (+ e (length tail))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
714 ;; `eword' contains `crest' and `tail'. |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
715 (insert eword) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
716 (set-marker b nil) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
717 (set-marker e nil) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
718 (unless (or (/= 0 (length tail)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
719 (eobp) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
720 (looking-at "[ \t\n)]")) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
721 (insert " ")))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
722 (t |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
723 (goto-char e))))) |
31717 | 724 |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
725 (defun rfc2047-fold-field () |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
726 "Fold the current header field." |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
727 (save-excursion |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
728 (save-restriction |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
729 (rfc2047-narrow-to-field) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
730 (rfc2047-fold-region (point-min) (point-max))))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
731 |
31717 | 732 (defun rfc2047-fold-region (b e) |
35985
b9c371244b90
(rfc2047-fold-region): Don't forward-char at EOB.
Dave Love <fx@gnu.org>
parents:
35838
diff
changeset
|
733 "Fold long lines in region B to E." |
31717 | 734 (save-restriction |
735 (narrow-to-region b e) | |
736 (goto-char (point-min)) | |
33304 | 737 (let ((break nil) |
738 (qword-break nil) | |
50881
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
739 (first t) |
33304 | 740 (bol (save-restriction |
741 (widen) | |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
742 (point-at-bol)))) |
31717 | 743 (while (not (eobp)) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
744 (when (and (or break qword-break) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
745 (> (- (point) bol) 76)) |
33304 | 746 (goto-char (or break qword-break)) |
747 (setq break nil | |
748 qword-break nil) | |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
749 (skip-chars-backward " \t") |
50881
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
750 (if (looking-at "[ \t]") |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
751 (insert ?\n) |
35453
26726eff41ca
2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
34674
diff
changeset
|
752 (insert "\n ")) |
33304 | 753 (setq bol (1- (point))) |
754 ;; Don't break before the first non-LWSP characters. | |
755 (skip-chars-forward " \t") | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
756 (unless (eobp) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
757 (forward-char 1))) |
31717 | 758 (cond |
33304 | 759 ((eq (char-after) ?\n) |
760 (forward-char 1) | |
761 (setq bol (point) | |
762 break nil | |
763 qword-break nil) | |
764 (skip-chars-forward " \t") | |
765 (unless (or (eobp) (eq (char-after) ?\n)) | |
766 (forward-char 1))) | |
767 ((eq (char-after) ?\r) | |
768 (forward-char 1)) | |
31717 | 769 ((memq (char-after) '(? ?\t)) |
33304 | 770 (skip-chars-forward " \t") |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
771 (unless first ;; Don't break just after the header name. |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
772 (setq break (point)))) |
33304 | 773 ((not break) |
774 (if (not (looking-at "=\\?[^=]")) | |
775 (if (eq (char-after) ?=) | |
776 (forward-char 1) | |
777 (skip-chars-forward "^ \t\n\r=")) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
778 ;; Don't break at the start of the field. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
779 (unless (= (point) b) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
780 (setq qword-break (point))) |
33304 | 781 (skip-chars-forward "^ \t\n\r"))) |
782 (t | |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
783 (skip-chars-forward "^ \t\n\r"))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
784 (setq first nil)) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
785 (when (and (or break qword-break) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
786 (> (- (point) bol) 76)) |
33304 | 787 (goto-char (or break qword-break)) |
788 (setq break nil | |
789 qword-break nil) | |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
790 (if (or (> 0 (skip-chars-backward " \t")) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
791 (looking-at "[ \t]")) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
792 (insert ?\n) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
793 (insert "\n ")) |
33304 | 794 (setq bol (1- (point))) |
795 ;; Don't break before the first non-LWSP characters. | |
796 (skip-chars-forward " \t") | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
797 (unless (eobp) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
798 (forward-char 1)))))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
799 |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
800 (defun rfc2047-unfold-field () |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
801 "Fold the current line." |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
802 (save-excursion |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
803 (save-restriction |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
804 (rfc2047-narrow-to-field) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
805 (rfc2047-unfold-region (point-min) (point-max))))) |
33304 | 806 |
807 (defun rfc2047-unfold-region (b e) | |
35985
b9c371244b90
(rfc2047-fold-region): Don't forward-char at EOB.
Dave Love <fx@gnu.org>
parents:
35838
diff
changeset
|
808 "Unfold lines in region B to E." |
33304 | 809 (save-restriction |
810 (narrow-to-region b e) | |
811 (goto-char (point-min)) | |
812 (let ((bol (save-restriction | |
813 (widen) | |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
814 (point-at-bol))) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
815 (eol (point-at-eol))) |
33304 | 816 (forward-line 1) |
817 (while (not (eobp)) | |
50881
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
818 (if (and (looking-at "[ \t]") |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
819 (< (- (point-at-eol) bol) 76)) |
50881
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
820 (delete-region eol (progn |
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
821 (goto-char eol) |
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
822 (skip-chars-forward "\r\n") |
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
823 (point))) |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
824 (setq bol (point-at-bol))) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
825 (setq eol (point-at-eol)) |
33304 | 826 (forward-line 1))))) |
31717 | 827 |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
828 (defun rfc2047-b-encode-string (string) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
829 "Base64-encode the header contained in STRING." |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
830 (base64-encode-string string t)) |
31717 | 831 |
107427
ecbe0edc4f69
Stop message.el from loading about 40 libraries it doesn't always need.
Glenn Morris <rgm@gnu.org>
parents:
106815
diff
changeset
|
832 (autoload 'quoted-printable-encode-region "qp") |
ecbe0edc4f69
Stop message.el from loading about 40 libraries it doesn't always need.
Glenn Morris <rgm@gnu.org>
parents:
106815
diff
changeset
|
833 |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
834 (defun rfc2047-q-encode-string (string) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
835 "Quoted-printable-encode the header in STRING." |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
836 (mm-with-unibyte-buffer |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
837 (insert string) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
838 (quoted-printable-encode-region |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
839 (point-min) (point-max) nil |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
840 ;; = (\075), _ (\137), ? (\077) are used in the encoded word. |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
841 ;; Avoid using 8bit characters. |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
842 ;; This list excludes `especials' (see the RFC2047 syntax), |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
843 ;; meaning that some characters in non-structured fields will |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
844 ;; get encoded when they con't need to be. The following is |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
845 ;; what it used to be. |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
846 ;;; ;; Equivalent to "^\000-\007\011\013\015-\037\200-\377=_?" |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
847 ;;; "\010\012\014\040-\074\076\100-\136\140-\177") |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
848 "-\b\n\f !#-'*+0-9A-Z\\^`-~\d") |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
849 (subst-char-in-region (point-min) (point-max) ? ?_) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
850 (buffer-string))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
851 |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
852 (defun rfc2047-encode-parameter (param value) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
853 "Return and PARAM=VALUE string encoded in the RFC2047-like style. |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
854 This is a replacement for the `rfc2231-encode-string' function. |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
855 |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
856 When attaching files as MIME parts, we should use the RFC2231 encoding |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
857 to specify the file names containing non-ASCII characters. However, |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
858 many mail softwares don't support it in practice and recipients won't |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
859 be able to extract files with correct names. Instead, the RFC2047-like |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
860 encoding is acceptable generally. This function provides the very |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
861 RFC2047-like encoding, resigning to such a regrettable trend. To use |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
862 it, put the following line in your ~/.gnus.el file: |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
863 |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
864 \(defalias 'mail-header-encode-parameter 'rfc2047-encode-parameter) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
865 " |
78125 | 866 (let ((rfc2047-encoding-type 'mime) |
867 (rfc2047-encode-max-chars nil)) | |
868 (rfc2045-encode-string param (rfc2047-encode-string value)))) | |
31717 | 869 |
870 ;;; | |
871 ;;; Functions for decoding RFC2047 messages | |
872 ;;; | |
873 | |
60161
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
874 (defvar rfc2047-quote-decoded-words-containing-tspecials nil |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
875 "If non-nil, quote decoded words containing special characters.") |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
876 |
66299
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
877 (defvar rfc2047-allow-incomplete-encoded-text t |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
878 "*Non-nil means allow incomplete encoded-text in successive encoded-words. |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
879 Dividing of encoded-text in the place other than character boundaries |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
880 violates RFC2047 section 5, while we have a capability to decode it. |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
881 If it is non-nil, the decoder will decode B- or Q-encoding in each |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
882 encoded-word, concatenate them, and decode it by charset. Otherwise, |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
883 the decoder will fully decode each encoded-word before concatenating |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
884 them.") |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
885 |
72605 | 886 (defun rfc2047-strip-backslashes-in-quoted-strings () |
72632 | 887 "Strip backslashes in quoted strings. `\\\"' remains." |
72605 | 888 (goto-char (point-min)) |
889 (let (beg) | |
890 (with-syntax-table (standard-syntax-table) | |
891 (while (search-forward "\"" nil t) | |
892 (unless (eq (char-before) ?\\) | |
893 (setq beg (match-end 0)) | |
894 (goto-char (match-beginning 0)) | |
895 (condition-case nil | |
896 (progn | |
897 (forward-sexp) | |
898 (save-restriction | |
899 (narrow-to-region beg (1- (point))) | |
900 (goto-char beg) | |
901 (while (search-forward "\\" nil 'move) | |
72632 | 902 (unless (memq (char-after) '(?\")) |
108765
d835100c3e8b
Replace Lisp calls to delete-backward-char by delete-char.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107427
diff
changeset
|
903 (delete-char -1)) |
72605 | 904 (forward-char))) |
905 (forward-char)) | |
906 (error | |
907 (goto-char beg)))))))) | |
908 | |
100315
da90832da238
* rfc2047.el (rfc2047-charset-to-coding-system): Add new argument
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
96376
diff
changeset
|
909 (defun rfc2047-charset-to-coding-system (charset &optional allow-override) |
66299
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
910 "Return coding-system corresponding to MIME CHARSET. |
100315
da90832da238
* rfc2047.el (rfc2047-charset-to-coding-system): Add new argument
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
96376
diff
changeset
|
911 If your Emacs implementation can't decode CHARSET, return nil. |
da90832da238
* rfc2047.el (rfc2047-charset-to-coding-system): Add new argument
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
96376
diff
changeset
|
912 |
da90832da238
* rfc2047.el (rfc2047-charset-to-coding-system): Add new argument
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
96376
diff
changeset
|
913 If allow-override is given, use `mm-charset-override-alist' to |
da90832da238
* rfc2047.el (rfc2047-charset-to-coding-system): Add new argument
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
96376
diff
changeset
|
914 map undesired charset names to their replacement. This should |
da90832da238
* rfc2047.el (rfc2047-charset-to-coding-system): Add new argument
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
96376
diff
changeset
|
915 only be used for decoding, not for encoding." |
66299
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
916 (when (stringp charset) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
917 (setq charset (intern (downcase charset)))) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
918 (when (or (not charset) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
919 (eq 'gnus-all mail-parse-ignored-charsets) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
920 (memq 'gnus-all mail-parse-ignored-charsets) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
921 (memq charset mail-parse-ignored-charsets)) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
922 (setq charset mail-parse-charset)) |
100315
da90832da238
* rfc2047.el (rfc2047-charset-to-coding-system): Add new argument
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
96376
diff
changeset
|
923 (let ((cs (mm-charset-to-coding-system charset nil allow-override))) |
66299
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
924 (cond ((eq cs 'ascii) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
925 (setq cs (or (mm-charset-to-coding-system mail-parse-charset) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
926 'raw-text))) |
69046
d037a8cb1b92
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-106
Miles Bader <miles@gnu.org>
parents:
68633
diff
changeset
|
927 ((mm-coding-system-p cs)) |
66299
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
928 ((and charset |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
929 (listp mail-parse-ignored-charsets) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
930 (memq 'gnus-unknown mail-parse-ignored-charsets)) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
931 (setq cs (mm-charset-to-coding-system mail-parse-charset)))) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
932 (if (eq cs 'ascii) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
933 'raw-text |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
934 cs))) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
935 |
107427
ecbe0edc4f69
Stop message.el from loading about 40 libraries it doesn't always need.
Glenn Morris <rgm@gnu.org>
parents:
106815
diff
changeset
|
936 (autoload 'quoted-printable-decode-string "qp") |
ecbe0edc4f69
Stop message.el from loading about 40 libraries it doesn't always need.
Glenn Morris <rgm@gnu.org>
parents:
106815
diff
changeset
|
937 |
66299
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
938 (defun rfc2047-decode-encoded-words (words) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
939 "Decode successive encoded-words in WORDS and return a decoded string. |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
940 Each element of WORDS looks like (CHARSET ENCODING ENCODED-TEXT |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
941 ENCODED-WORD)." |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
942 (let (word charset cs encoding text rest) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
943 (while words |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
944 (setq word (pop words)) |
69944
a87e26272828
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-210
Miles Bader <miles@gnu.org>
parents:
69046
diff
changeset
|
945 (if (and (setq cs (rfc2047-charset-to-coding-system |
100315
da90832da238
* rfc2047.el (rfc2047-charset-to-coding-system): Add new argument
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
96376
diff
changeset
|
946 (setq charset (car word)) t)) |
66299
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
947 (condition-case code |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
948 (cond ((char-equal ?B (nth 1 word)) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
949 (setq text (base64-decode-string |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
950 (rfc2047-pad-base64 (nth 2 word))))) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
951 ((char-equal ?Q (nth 1 word)) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
952 (setq text (quoted-printable-decode-string |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
953 (mm-subst-char-in-string |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
954 ?_ ? (nth 2 word) t))))) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
955 (error |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
956 (message "%s" (error-message-string code)) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
957 nil))) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
958 (if (and rfc2047-allow-incomplete-encoded-text |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
959 (eq cs (caar rest))) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
960 ;; Concatenate text of which the charset is the same. |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
961 (setcdr (car rest) (concat (cdar rest) text)) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
962 (push (cons cs text) rest)) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
963 ;; Don't decode encoded-word. |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
964 (push (cons nil (nth 3 word)) rest))) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
965 (while rest |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
966 (setq words (concat |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
967 (or (and (setq cs (caar rest)) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
968 (condition-case code |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
969 (mm-decode-coding-string (cdar rest) cs) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
970 (error |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
971 (message "%s" (error-message-string code)) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
972 nil))) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
973 (concat (when (cdr rest) " ") |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
974 (cdar rest) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
975 (when (and words |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
976 (not (eq (string-to-char words) ? ))) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
977 " "))) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
978 words) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
979 rest (cdr rest))) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
980 words)) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
981 |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
982 ;; Fixme: This should decode in place, not cons intermediate strings. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
983 ;; Also check whether it needs to worry about delimiting fields like |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
984 ;; encoding. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
985 |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
986 ;; In fact it's reported that (invalid) encoding of mailboxes in |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
987 ;; addr-specs is in use, so delimiting fields might help. Probably |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
988 ;; not decoding a word which isn't properly delimited is good enough |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
989 ;; and worthwhile (is it more correct or not?), e.g. something like |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
990 ;; `=?iso-8859-1?q?foo?=@'. |
31717 | 991 |
72605 | 992 (defun rfc2047-decode-region (start end &optional address-mime) |
993 "Decode MIME-encoded words in region between START and END. | |
994 If ADDRESS-MIME is non-nil, strip backslashes which precede characters | |
995 other than `\"' and `\\' in quoted strings." | |
31717 | 996 (interactive "r") |
997 (let ((case-fold-search t) | |
87097 | 998 (eword-regexp |
999 (if rfc2047-allow-irregular-q-encoded-words | |
1000 (eval-when-compile | |
1001 (concat "[\n\t ]*\\(" rfc2047-encoded-word-regexp-loose "\\)")) | |
1002 (eval-when-compile | |
1003 (concat "[\n\t ]*\\(" rfc2047-encoded-word-regexp "\\)")))) | |
66299
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
1004 b e match words) |
47951
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
1005 (save-excursion |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
1006 (save-restriction |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
1007 (narrow-to-region start end) |
72605 | 1008 (when address-mime |
1009 (rfc2047-strip-backslashes-in-quoted-strings)) | |
66299
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
1010 (goto-char (setq b start)) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
1011 ;; Look for the encoded-words. |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
1012 (while (setq match (re-search-forward eword-regexp nil t)) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
1013 (setq e (match-beginning 1) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
1014 end (match-end 0) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
1015 words nil) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
1016 (while match |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
1017 (push (list (match-string 2) ;; charset |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
1018 (char-after (match-beginning 3)) ;; encoding |
87097 | 1019 (substring (match-string 3) 2) ;; encoded-text |
66299
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
1020 (match-string 1)) ;; encoded-word |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
1021 words) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
1022 ;; Look for the subsequent encoded-words. |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
1023 (when (setq match (looking-at eword-regexp)) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
1024 (goto-char (setq end (match-end 0))))) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
1025 ;; Replace the encoded-words with the decoded one. |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
1026 (delete-region e end) |
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
1027 (insert (rfc2047-decode-encoded-words (nreverse words))) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
1028 (save-restriction |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
1029 (narrow-to-region e (point)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
1030 (goto-char e) |
60161
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1031 ;; Remove newlines between decoded words, though such |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1032 ;; things essentially must not be there. |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
1033 (while (re-search-forward "[\n\r]+" nil t) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
1034 (replace-match " ")) |
106099
fc3c7104330d
(rfc2047-decode-region): Don't quote decoded words containing tspecial
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
104830
diff
changeset
|
1035 (setq end (point-max)) |
60161
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1036 ;; Quote decoded words if there are special characters |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1037 ;; which might violate RFC2822. |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1038 (when (and rfc2047-quote-decoded-words-containing-tspecials |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1039 (let ((regexp (car (rassq |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1040 'address-mime |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1041 rfc2047-header-encoding-alist)))) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1042 (when regexp |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1043 (save-restriction |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1044 (widen) |
106099
fc3c7104330d
(rfc2047-decode-region): Don't quote decoded words containing tspecial
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
104830
diff
changeset
|
1045 (and |
fc3c7104330d
(rfc2047-decode-region): Don't quote decoded words containing tspecial
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
104830
diff
changeset
|
1046 ;; Don't quote words if already quoted. |
fc3c7104330d
(rfc2047-decode-region): Don't quote decoded words containing tspecial
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
104830
diff
changeset
|
1047 (not (and (eq (char-before e) ?\") |
fc3c7104330d
(rfc2047-decode-region): Don't quote decoded words containing tspecial
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
104830
diff
changeset
|
1048 (eq (char-after end) ?\"))) |
fc3c7104330d
(rfc2047-decode-region): Don't quote decoded words containing tspecial
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
104830
diff
changeset
|
1049 (progn |
fc3c7104330d
(rfc2047-decode-region): Don't quote decoded words containing tspecial
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
104830
diff
changeset
|
1050 (beginning-of-line) |
fc3c7104330d
(rfc2047-decode-region): Don't quote decoded words containing tspecial
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
104830
diff
changeset
|
1051 (while (and (memq (char-after) '(? ?\t)) |
fc3c7104330d
(rfc2047-decode-region): Don't quote decoded words containing tspecial
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
104830
diff
changeset
|
1052 (zerop (forward-line -1)))) |
fc3c7104330d
(rfc2047-decode-region): Don't quote decoded words containing tspecial
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
104830
diff
changeset
|
1053 (looking-at regexp))))))) |
60161
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1054 (let (quoted) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1055 (goto-char e) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1056 (skip-chars-forward " \t") |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1057 (setq start (point)) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1058 (setq quoted (eq (char-after) ?\")) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1059 (goto-char (point-max)) |
103027
25a15bc4c9bb
(rfc2047-decode-region): Don't skip past `start', which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
1060 (skip-chars-backward " \t" start) |
60161
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1061 (if (setq quoted (and quoted |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1062 (> (point) (1+ start)) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1063 (eq (char-before) ?\"))) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1064 (progn |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1065 (backward-char) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1066 (setq start (1+ start) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1067 end (point-marker))) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1068 (setq end (point-marker))) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1069 (goto-char start) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1070 (while (search-forward "\"" end t) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1071 (when (prog2 |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1072 (backward-char) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1073 (zerop (% (skip-chars-backward "\\\\") 2)) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1074 (goto-char (match-beginning 0))) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1075 (insert "\\")) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1076 (forward-char)) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1077 (when (and (not quoted) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1078 (progn |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1079 (goto-char start) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1080 (re-search-forward |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1081 (concat "[" ietf-drums-tspecials "]") |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1082 end t))) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1083 (goto-char start) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1084 (insert "\"") |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1085 (goto-char end) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1086 (insert "\"")) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
1087 (set-marker end nil))) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
1088 (goto-char (point-max))) |
47951
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
1089 (when (and (mm-multibyte-p) |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
1090 mail-parse-charset |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
1091 (not (eq mail-parse-charset 'us-ascii)) |
47951
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
1092 (not (eq mail-parse-charset 'gnus-decoded))) |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
1093 (mm-decode-coding-region b e mail-parse-charset)) |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
1094 (setq b (point))) |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
1095 (when (and (mm-multibyte-p) |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
1096 mail-parse-charset |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
1097 (not (eq mail-parse-charset 'us-ascii)) |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
1098 (not (eq mail-parse-charset 'gnus-decoded))) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
1099 (mm-decode-coding-region b (point-max) mail-parse-charset)))))) |
31717 | 1100 |
72605 | 1101 (defun rfc2047-decode-address-region (start end) |
1102 "Decode MIME-encoded words in region between START and END. | |
1103 Backslashes which precede characters other than `\"' and `\\' in quoted | |
1104 strings are stripped." | |
1105 (rfc2047-decode-region start end t)) | |
1106 | |
1107 (defun rfc2047-decode-string (string &optional address-mime) | |
1108 "Decode MIME-encoded STRING and return the result. | |
1109 If ADDRESS-MIME is non-nil, strip backslashes which precede characters | |
1110 other than `\"' and `\\' in quoted strings." | |
92777
1186239f19c8
(rfc2047-decode-string): Don't use `m'. Avoid mm-string-as-multibyte as well.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91327
diff
changeset
|
1111 ;; (let ((m (mm-multibyte-p))) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
1112 (if (string-match "=\\?" string) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
1113 (with-temp-buffer |
92777
1186239f19c8
(rfc2047-decode-string): Don't use `m'. Avoid mm-string-as-multibyte as well.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91327
diff
changeset
|
1114 ;; We used to only call mm-enable-multibyte if `m' is non-nil, |
1186239f19c8
(rfc2047-decode-string): Don't use `m'. Avoid mm-string-as-multibyte as well.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91327
diff
changeset
|
1115 ;; but this can't be the right criterion. Don't just revert this |
1186239f19c8
(rfc2047-decode-string): Don't use `m'. Avoid mm-string-as-multibyte as well.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91327
diff
changeset
|
1116 ;; change if it encounters a bug. Please help me fix it |
1186239f19c8
(rfc2047-decode-string): Don't use `m'. Avoid mm-string-as-multibyte as well.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91327
diff
changeset
|
1117 ;; right instead. --Stef |
1186239f19c8
(rfc2047-decode-string): Don't use `m'. Avoid mm-string-as-multibyte as well.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91327
diff
changeset
|
1118 ;; The string returned should always be multibyte in a multibyte |
1186239f19c8
(rfc2047-decode-string): Don't use `m'. Avoid mm-string-as-multibyte as well.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91327
diff
changeset
|
1119 ;; session, i.e. the buffer should be multibyte before |
1186239f19c8
(rfc2047-decode-string): Don't use `m'. Avoid mm-string-as-multibyte as well.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91327
diff
changeset
|
1120 ;; `buffer-string' is called. |
1186239f19c8
(rfc2047-decode-string): Don't use `m'. Avoid mm-string-as-multibyte as well.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91327
diff
changeset
|
1121 (mm-enable-multibyte) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
1122 (insert string) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
1123 (inline |
72605 | 1124 (rfc2047-decode-region (point-min) (point-max) address-mime)) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
1125 (buffer-string)) |
72605 | 1126 (when address-mime |
1127 (setq string | |
1128 (with-temp-buffer | |
1129 (when (mm-multibyte-string-p string) | |
1130 (mm-enable-multibyte)) | |
1131 (insert string) | |
1132 (rfc2047-strip-backslashes-in-quoted-strings) | |
1133 (buffer-string)))) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
1134 ;; Fixme: As above, `m' here is inappropriate. |
92777
1186239f19c8
(rfc2047-decode-string): Don't use `m'. Avoid mm-string-as-multibyte as well.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91327
diff
changeset
|
1135 (if (and ;; m |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
1136 mail-parse-charset |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
1137 (not (eq mail-parse-charset 'us-ascii)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
1138 (not (eq mail-parse-charset 'gnus-decoded))) |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
1139 ;; `decode-coding-string' in Emacs offers a third optional |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
1140 ;; arg NOCOPY to avoid consing a new string if the decoding |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
1141 ;; is "trivial". Unfortunately it currently doesn't |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
1142 ;; consider anything else than a `nil' coding system |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
1143 ;; trivial. |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
1144 ;; `rfc2047-decode-string' is called multiple times for each |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
1145 ;; article during summary buffer generation, and we really |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
1146 ;; want to avoid unnecessary consing. So we bypass |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
1147 ;; `decode-coding-string' if the string is purely ASCII. |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
1148 (if (and (fboundp 'detect-coding-string) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
1149 ;; string is purely ASCII |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
1150 (eq (detect-coding-string string t) 'undecided)) |
92777
1186239f19c8
(rfc2047-decode-string): Don't use `m'. Avoid mm-string-as-multibyte as well.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91327
diff
changeset
|
1151 string |
1186239f19c8
(rfc2047-decode-string): Don't use `m'. Avoid mm-string-as-multibyte as well.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91327
diff
changeset
|
1152 (mm-decode-coding-string string mail-parse-charset)) |
1186239f19c8
(rfc2047-decode-string): Don't use `m'. Avoid mm-string-as-multibyte as well.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91327
diff
changeset
|
1153 (mm-string-to-multibyte string)))) ;; ) |
31717 | 1154 |
72605 | 1155 (defun rfc2047-decode-address-string (string) |
1156 "Decode MIME-encoded STRING and return the result. | |
1157 Backslashes which precede characters other than `\"' and `\\' in quoted | |
1158 strings are stripped." | |
1159 (rfc2047-decode-string string t)) | |
1160 | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
1161 (defun rfc2047-pad-base64 (string) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
1162 "Pad STRING to quartets." |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
1163 ;; Be more liberal to accept buggy base64 strings. If |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
1164 ;; base64-decode-string accepts buggy strings, this function could |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
1165 ;; be aliased to identity. |
57243
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
1166 (if (= 0 (mod (length string) 4)) |
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
1167 string |
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
1168 (when (string-match "=+$" string) |
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
1169 (setq string (substring string 0 (match-beginning 0)))) |
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
1170 (case (mod (length string) 4) |
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
1171 (0 string) |
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
1172 (1 string) ;; Error, don't pad it. |
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
1173 (2 (concat string "==")) |
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
1174 (3 (concat string "="))))) |
31717 | 1175 |
1176 (provide 'rfc2047) | |
1177 | |
92777
1186239f19c8
(rfc2047-decode-string): Don't use `m'. Avoid mm-string-as-multibyte as well.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91327
diff
changeset
|
1178 ;; arch-tag: a07fe3d4-22b5-4c4a-bd89-b1f82d5d36f6 |
31717 | 1179 ;;; rfc2047.el ends here |