Mercurial > emacs
annotate lisp/gnus/rfc2047.el @ 90240:c30690dd6a7d
*** empty log message ***
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Fri, 14 Oct 2005 00:48:52 +0000 |
parents | 2d92f5c9d6ae |
children | 0ca0d9181b5e |
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 |
64754
fafd692d1e40
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64085
diff
changeset
|
3 ;; Copyright (C) 1998, 1999, 2000, 2002, 2003, 2004, |
fafd692d1e40
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64085
diff
changeset
|
4 ;; 2005 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 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
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 | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
64085 | 22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
23 ;; Boston, MA 02110-1301, USA. | |
31717 | 24 |
25 ;;; Commentary: | |
26 | |
34674 | 27 ;; RFC 2047 is "MIME (Multipurpose Internet Mail Extensions) Part |
28 ;; Three: Message Header Extensions for Non-ASCII Text". | |
29 | |
31717 | 30 ;;; Code: |
31 | |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
32 (eval-when-compile |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
33 (require 'cl) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
34 (defvar message-posting-charset) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
35 (unless (fboundp 'with-syntax-table) ; not in Emacs 20 |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
36 (defmacro with-syntax-table (table &rest body) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
37 "Evaluate BODY with syntax table of current buffer set to TABLE. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
38 The syntax table of the current buffer is saved, BODY is evaluated, and the |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
39 saved table is restored, even in case of an abnormal exit. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
40 Value is what BODY returns." |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
41 (let ((old-table (make-symbol "table")) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
42 (old-buffer (make-symbol "buffer"))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
43 `(let ((,old-table (syntax-table)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
44 (,old-buffer (current-buffer))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
45 (unwind-protect |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
46 (progn |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
47 (set-syntax-table ,table) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
48 ,@body) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
49 (save-current-buffer |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
50 (set-buffer ,old-buffer) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
51 (set-syntax-table ,old-table)))))))) |
31717 | 52 |
53 (require 'qp) | |
54 (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
|
55 (require 'ietf-drums) |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
56 ;; Fixme: Avoid this (used for mail-parse-charset) mm dependence on gnus. |
31717 | 57 (require 'mail-prsvr) |
33304 | 58 (require 'base64) |
59 (autoload 'mm-body-7-or-8 "mm-bodies") | |
33127
eca95f9d7f05
(base64): Require unconditionally.
Dave Love <fx@gnu.org>
parents:
31764
diff
changeset
|
60 |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
61 (eval-and-compile |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
62 ;; Avoid gnus-util for mm- code. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
63 (defalias 'rfc2047-point-at-bol |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
64 (if (fboundp 'point-at-bol) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
65 'point-at-bol |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
66 'line-beginning-position)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
67 |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
68 (defalias 'rfc2047-point-at-eol |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
69 (if (fboundp 'point-at-eol) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
70 'point-at-eol |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
71 'line-end-position))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
72 |
31717 | 73 (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
|
74 '(("Newsgroups" . nil) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
75 ("Followup-To" . nil) |
31717 | 76 ("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
|
77 ("\\(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
|
78 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\)" . address-mime) |
31717 | 79 (t . mime)) |
80 "*Header/encoding method alist. | |
81 The list is traversed sequentially. The keys can either be | |
33304 | 82 header regexps or t. |
31717 | 83 |
84 The values can be: | |
85 | |
86 1) nil, in which case no encoding is done; | |
87 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
|
88 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
|
89 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
|
90 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
|
91 5) `default', in which case the field will be encoded as the rest |
31717 | 92 of the article.") |
93 | |
94 (defvar rfc2047-charset-encoding-alist | |
95 '((us-ascii . nil) | |
96 (iso-8859-1 . Q) | |
97 (iso-8859-2 . Q) | |
98 (iso-8859-3 . Q) | |
99 (iso-8859-4 . Q) | |
100 (iso-8859-5 . B) | |
101 (koi8-r . B) | |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
102 (iso-8859-7 . B) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
103 (iso-8859-8 . B) |
31717 | 104 (iso-8859-9 . Q) |
33304 | 105 (iso-8859-14 . Q) |
106 (iso-8859-15 . Q) | |
31717 | 107 (iso-2022-jp . B) |
108 (iso-2022-kr . B) | |
109 (gb2312 . B) | |
35838
53eebdb81828
2001-02-01 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
35453
diff
changeset
|
110 (big5 . B) |
53eebdb81828
2001-02-01 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
35453
diff
changeset
|
111 (cn-big5 . B) |
31717 | 112 (cn-gb . B) |
113 (cn-gb-2312 . B) | |
114 (euc-kr . B) | |
115 (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
|
116 (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
|
117 (viscii . Q)) |
31717 | 118 "Alist of MIME charsets to RFC2047 encodings. |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
119 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
|
120 quoted-printable and base64 respectively.") |
31717 | 121 |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
122 (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
|
123 '((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
|
124 (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
|
125 (nil . identity)) |
31717 | 126 "Alist of RFC2047 encodings to encoding functions.") |
127 | |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
128 (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
|
129 "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
|
130 |
31717 | 131 ;;; |
132 ;;; Functions for encoding RFC2047 messages | |
133 ;;; | |
134 | |
57243
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
135 (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
|
136 "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
|
137 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
|
138 (save-excursion |
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
139 (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
|
140 (n8bit 0)) |
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
141 (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
|
142 (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
|
143 (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
|
144 (incf n8bit) |
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
145 (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
|
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 (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
|
148 ;; 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
|
149 ;; 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
|
150 (= n8bit 1)) |
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
151 'quoted-printable |
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
152 'base64)))) |
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
153 |
31717 | 154 (defun rfc2047-narrow-to-field () |
155 "Narrow the buffer to the header on the current line." | |
156 (beginning-of-line) | |
157 (narrow-to-region | |
158 (point) | |
159 (progn | |
160 (forward-line 1) | |
161 (if (re-search-forward "^[^ \n\t]" nil t) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
162 (rfc2047-point-at-bol) |
31717 | 163 (point-max)))) |
164 (goto-char (point-min))) | |
165 | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
166 (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
|
167 "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
|
168 (save-excursion |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
169 (save-restriction |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
170 (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
|
171 (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
|
172 (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
|
173 |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
174 (defvar rfc2047-encoding-type 'address-mime |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
175 "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
|
176 This should be dynamically bound around calls to |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
177 `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
|
178 `rfc2047-header-encoding-alist', for definitions.") |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
179 |
31717 | 180 (defun rfc2047-encode-message-header () |
181 "Encode the message header according to `rfc2047-header-encoding-alist'. | |
182 Should be called narrowed to the head of the message." | |
183 (interactive "*") | |
184 (save-excursion | |
185 (goto-char (point-min)) | |
186 (let (alist elem method) | |
187 (while (not (eobp)) | |
188 (save-restriction | |
189 (rfc2047-narrow-to-field) | |
190 (if (not (rfc2047-encodable-p)) | |
50881
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
191 (prog1 |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
192 (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
|
193 (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
|
194 (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
|
195 (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
|
196 ;; 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
|
197 (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
|
198 (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
|
199 (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
|
200 (car message-posting-charset)))) |
50881
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
201 ;; 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
|
202 (when nil |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
203 (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
|
204 (save-excursion |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
205 (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
|
206 (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
|
207 (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
|
208 (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
|
209 (point)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
210 (point-max)))) |
31717 | 211 ;; We found something that may perhaps be encoded. |
212 (setq method nil | |
213 alist rfc2047-header-encoding-alist) | |
214 (while (setq elem (pop alist)) | |
215 (when (or (and (stringp (car elem)) | |
216 (looking-at (car elem))) | |
217 (eq (car elem) t)) | |
218 (setq alist nil | |
219 method (cdr elem)))) | |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
220 (re-search-forward "^[^:]+: *" nil t) |
31717 | 221 (cond |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
222 ((eq method 'address-mime) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
223 (rfc2047-encode-region (point) (point-max))) |
31717 | 224 ((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
|
225 (let ((rfc2047-encoding-type 'mime)) |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
226 (rfc2047-encode-region (point) (point-max)))) |
31717 | 227 ((eq method 'default) |
228 (if (and (featurep 'mule) | |
33815
61c7f3065929
(rfc2047-encode-message-header): Don't encode if
Dave Love <fx@gnu.org>
parents:
33304
diff
changeset
|
229 (if (boundp 'default-enable-multibyte-characters) |
61c7f3065929
(rfc2047-encode-message-header): Don't encode if
Dave Love <fx@gnu.org>
parents:
33304
diff
changeset
|
230 default-enable-multibyte-characters) |
31717 | 231 mail-parse-charset) |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
232 (mm-encode-coding-region (point) (point-max) |
31717 | 233 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
|
234 ;; 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
|
235 ;; 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
|
236 ;; 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
|
237 ;; whether to encode, which was quite confusing for the |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
238 ;; user. If the new behaviour is wrong, tell me. I have |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
239 ;; 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
|
240 ;; -- 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
|
241 ;; 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
|
242 ;; 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
|
243 ((null method) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
244 (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
|
245 ;;; ((null method) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
246 ;;; (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
|
247 ;;; '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
|
248 ;;; (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
|
249 ;;; '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
|
250 ;;; (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
|
251 ;;; "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
|
252 ;;; (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
|
253 ;;; (error "Cannot send unencoded text"))) |
31717 | 254 ((mm-coding-system-p method) |
33815
61c7f3065929
(rfc2047-encode-message-header): Don't encode if
Dave Love <fx@gnu.org>
parents:
33304
diff
changeset
|
255 (if (and (featurep 'mule) |
61c7f3065929
(rfc2047-encode-message-header): Don't encode if
Dave Love <fx@gnu.org>
parents:
33304
diff
changeset
|
256 (if (boundp 'default-enable-multibyte-characters) |
61c7f3065929
(rfc2047-encode-message-header): Don't encode if
Dave Love <fx@gnu.org>
parents:
33304
diff
changeset
|
257 default-enable-multibyte-characters)) |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
258 (mm-encode-coding-region (point) (point-max) method))) |
31717 | 259 ;; Hm. |
260 (t))) | |
261 (goto-char (point-max))))))) | |
262 | |
35985
b9c371244b90
(rfc2047-fold-region): Don't forward-char at EOB.
Dave Love <fx@gnu.org>
parents:
35838
diff
changeset
|
263 ;; 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
|
264 ;; 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
|
265 (eval-when-compile (defvar message-posting-charset)) |
b9c371244b90
(rfc2047-fold-region): Don't forward-char at EOB.
Dave Love <fx@gnu.org>
parents:
35838
diff
changeset
|
266 |
33304 | 267 (defun rfc2047-encodable-p () |
268 "Return non-nil if any characters in current buffer need encoding in headers. | |
269 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
|
270 (require 'message) ; for message-posting-charset |
31717 | 271 (let ((charsets |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
272 (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
|
273 (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
|
274 (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
|
275 (prog1 |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
276 (search-forward "=?" nil t) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
277 (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
|
278 (and charsets |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
279 (not (equal charsets (list (car message-posting-charset)))))))) |
31717 | 280 |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
281 ;; 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
|
282 ;; encoding. Double quotes are string delimiters, backslash is |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
283 ;; 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
|
284 ;; 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
|
285 ;; 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
|
286 ;; things differently. |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
287 (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
|
288 ;; (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
|
289 (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
|
290 ;; 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
|
291 ;; 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
|
292 ;; 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
|
293 ;; 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
|
294 (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
|
295 (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
|
296 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
|
297 (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
|
298 (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
|
299 (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
|
300 table)))) |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
301 (modify-syntax-entry ?\\ "\\" table) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
302 (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
|
303 (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
|
304 (modify-syntax-entry ?\) ")" table) |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
305 (modify-syntax-entry ?\< "." table) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
306 (modify-syntax-entry ?\> "." table) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
307 (modify-syntax-entry ?\[ "." table) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
308 (modify-syntax-entry ?\] "." table) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
309 (modify-syntax-entry ?: "." table) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
310 (modify-syntax-entry ?\; "." table) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
311 (modify-syntax-entry ?, "." table) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
312 (modify-syntax-entry ?@ "." table) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
313 table)) |
31717 | 314 |
315 (defun rfc2047-encode-region (b e) | |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
316 "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
|
317 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
|
318 Dynamically bind `rfc2047-encoding-type' to change that." |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
319 (save-restriction |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
320 (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
|
321 (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
|
322 "[^\000-\177]+\\|=\\?" |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
323 "[^\000-\177]+")) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
324 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
|
325 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
|
326 ;; 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
|
327 ;; 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
|
328 last-encoded |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
329 (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
|
330 (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
|
331 ;; 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
|
332 ;; 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
|
333 ;; 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
|
334 ;; 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
|
335 ;; 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
|
336 (progn |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
337 (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
|
338 (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
|
339 (not (eobp))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
340 (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
|
341 (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
|
342 (progn |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
343 (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
|
344 (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
|
345 (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
|
346 (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
|
347 (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
|
348 (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
|
349 ;; `address-mime' case -- take care of quoted words, comments. |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
350 (with-syntax-table rfc2047-syntax-table |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
351 (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
|
352 (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
|
353 ;; Look for rfc2822-style: sequences of atoms, quoted |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
354 ;; strings, specials, whitespace. (Specials mustn't be |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
355 ;; encoded.) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
356 (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
|
357 ;; Skip whitespace. |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
358 (skip-chars-forward " \t\n") |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
359 (setq start (point)) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
360 (cond |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
361 ((not (char-after))) ; eob |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
362 ;; 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
|
363 ((eq ?\" (setq csyntax (char-syntax (char-after)))) |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
364 ;; Quoted word. |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
365 (forward-sexp) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
366 (setq end (point)) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
367 ;; Does it need encoding? |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
368 (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
|
369 (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
|
370 ;; 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
|
371 ;; 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
|
372 (progn |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
373 (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
|
374 (delete-backward-char 1) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
375 (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
|
376 (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
|
377 (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
|
378 ;; 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
|
379 ;; 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
|
380 ;; 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
|
381 (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
|
382 ;; 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
|
383 (insert ? ) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
384 (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
|
385 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
|
386 ;; 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
|
387 (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
|
388 (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
|
389 (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
|
390 ((eq ?. csyntax) |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
391 ;; Skip other delimiters, but record that they've |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
392 ;; potentially separated quoted words. |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
393 (forward-char) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
394 (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
|
395 ((eq ?\) csyntax) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
396 (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
|
397 ((eq ?\( csyntax) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
398 ;; 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
|
399 (forward-list) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
400 ;; 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
|
401 (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
|
402 (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
|
403 (skip-chars-forward ")")) |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
404 (t ; normal token/whitespace sequence |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
405 ;; 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
|
406 ;; 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
|
407 ;; 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
|
408 (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
|
409 (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
|
410 (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
|
411 (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
|
412 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
|
413 (when (progn |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
414 (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
|
415 "[ \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
|
416 (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
|
417 (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
|
418 ;; 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
|
419 (forward-char)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
420 end) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
421 (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
|
422 (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
|
423 (progn |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
424 (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
|
425 (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
|
426 (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
|
427 (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
|
428 (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
|
429 ;; 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
|
430 ;; 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
|
431 ;; 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
|
432 ;; 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
|
433 (unless end |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
434 (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
|
435 (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
|
436 (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
|
437 (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
|
438 (progn |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
439 (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
|
440 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
|
441 (< begin (point))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
442 (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
|
443 (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
|
444 (progn |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
445 (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
|
446 nil))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
447 (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
|
448 (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
|
449 (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
|
450 (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
|
451 ;; 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
|
452 ;; 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
|
453 ;; them safely. |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
454 (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
|
455 ((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
|
456 encodable-regexp |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
457 "\\)")) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
458 (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
|
459 (t |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
460 (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
|
461 (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
|
462 ;; 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
|
463 ;; delimiter. |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
464 (insert " ")))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
465 (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
|
466 (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
|
467 (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
|
468 (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
|
469 (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
|
470 (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
|
471 (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
|
472 (skip-chars-backward " \t\n") |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
473 (setq end (point)) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
474 (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
|
475 (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
|
476 (progn |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
477 (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
|
478 (if (progn |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
479 (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
|
480 (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
|
481 (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
|
482 (= (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
|
483 ;; 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
|
484 (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
|
485 ;; 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
|
486 (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
|
487 (insert " ") |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
488 (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
|
489 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
|
490 (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
|
491 (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
|
492 (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
|
493 (error |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
494 (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
|
495 (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
|
496 (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
|
497 (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
|
498 (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
|
499 (goto-char (point-max)))) |
31717 | 500 |
501 (defun rfc2047-encode-string (string) | |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
502 "Encode words in STRING. |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
503 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
|
504 `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
|
505 (mm-with-multibyte-buffer |
31717 | 506 (insert string) |
507 (rfc2047-encode-region (point-min) (point-max)) | |
508 (buffer-string))) | |
509 | |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
510 (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
|
511 "Maximum characters of each header line that contain encoded-words. |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
512 If it is nil, encoded-words will not be folded. Too small value may |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
513 cause an error. Don't change this for no particular reason.") |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
514 |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
515 (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
|
516 &optional eword) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
517 "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
|
518 (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
|
519 (or eword "")) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
520 ((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
|
521 (concat start |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
522 (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
|
523 (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
|
524 string)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
525 "?=")) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
526 ((>= 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
|
527 (when eword |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
528 (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
|
529 ;; 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
|
530 (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
|
531 ((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
|
532 ;; 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
|
533 (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
|
534 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
|
535 (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
|
536 (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
|
537 (t |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
538 (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
|
539 (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
|
540 (prev "") |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
541 next len) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
542 (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
|
543 (<= index limit)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
544 (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
|
545 (funcall encoder |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
546 (if cs |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
547 (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
|
548 (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
|
549 cs) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
550 (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
|
551 "?=") |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
552 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
|
553 (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
|
554 (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
|
555 prev nil) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
556 (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
|
557 (<= (+ 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
|
558 (length tail))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
559 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
|
560 (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
|
561 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
|
562 (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
|
563 ;; 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
|
564 (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
|
565 "\n " |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
566 (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
|
567 prev next |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
568 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
|
569 (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
|
570 prev nil))))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
571 (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
|
572 (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
|
573 (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
|
574 (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
|
575 (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
|
576 (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
|
577 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
|
578 (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
|
579 (setq crest " " |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
580 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
|
581 (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
|
582 ;; 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
|
583 (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
|
584 (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
|
585 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
|
586 (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
|
587 |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
588 (defun rfc2047-encode (b e) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
589 "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
|
590 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
|
591 (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
|
592 cs encoding tail crest 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 ((> (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
|
594 (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
|
595 (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
|
596 ((= (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
|
597 (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
|
598 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
|
599 (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
|
600 (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
|
601 (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
|
602 (save-restriction |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
603 (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
|
604 (setq encoding |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
605 (or (cdr (assq mime-charset |
31717 | 606 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
|
607 ;; 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
|
608 ;; 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
|
609 (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
|
610 'B |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
611 'Q))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
612 (widen) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
613 (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
|
614 (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
|
615 ;; `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
|
616 (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
|
617 (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
|
618 (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
|
619 e (set-marker (make-marker) e)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
620 (rfc2047-fold-region (rfc2047-point-at-bol) b) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
621 (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
|
622 (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
|
623 (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
|
624 ;; `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
|
625 (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
|
626 (setq eword (rfc2047-encode-1 |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
627 (- b (rfc2047-point-at-bol)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
628 (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
|
629 (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
|
630 "\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
|
631 cs |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
632 (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
|
633 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
|
634 'identity) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
635 (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
|
636 "?" (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
|
637 (or crest " ") |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
638 tail)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
639 (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
|
640 (if (bolp) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
641 ;; 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
|
642 (1- (point)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
643 (point)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
644 (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
|
645 (+ 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
|
646 ;; `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
|
647 (insert eword) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
648 (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
|
649 (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
|
650 (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
|
651 (eobp) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
652 (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
|
653 (insert " ")))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
654 (t |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
655 (goto-char e))))) |
31717 | 656 |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
657 (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
|
658 "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
|
659 (save-excursion |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
660 (save-restriction |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
661 (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
|
662 (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
|
663 |
31717 | 664 (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
|
665 "Fold long lines in region B to E." |
31717 | 666 (save-restriction |
667 (narrow-to-region b e) | |
668 (goto-char (point-min)) | |
33304 | 669 (let ((break nil) |
670 (qword-break nil) | |
50881
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
671 (first t) |
33304 | 672 (bol (save-restriction |
673 (widen) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
674 (rfc2047-point-at-bol)))) |
31717 | 675 (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
|
676 (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
|
677 (> (- (point) bol) 76)) |
33304 | 678 (goto-char (or break qword-break)) |
679 (setq break nil | |
680 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
|
681 (skip-chars-backward " \t") |
50881
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
682 (if (looking-at "[ \t]") |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
683 (insert ?\n) |
35453
26726eff41ca
2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
34674
diff
changeset
|
684 (insert "\n ")) |
33304 | 685 (setq bol (1- (point))) |
686 ;; Don't break before the first non-LWSP characters. | |
687 (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
|
688 (unless (eobp) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
689 (forward-char 1))) |
31717 | 690 (cond |
33304 | 691 ((eq (char-after) ?\n) |
692 (forward-char 1) | |
693 (setq bol (point) | |
694 break nil | |
695 qword-break nil) | |
696 (skip-chars-forward " \t") | |
697 (unless (or (eobp) (eq (char-after) ?\n)) | |
698 (forward-char 1))) | |
699 ((eq (char-after) ?\r) | |
700 (forward-char 1)) | |
31717 | 701 ((memq (char-after) '(? ?\t)) |
33304 | 702 (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
|
703 (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
|
704 (setq break (point)))) |
33304 | 705 ((not break) |
706 (if (not (looking-at "=\\?[^=]")) | |
707 (if (eq (char-after) ?=) | |
708 (forward-char 1) | |
709 (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
|
710 ;; 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
|
711 (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
|
712 (setq qword-break (point))) |
33304 | 713 (skip-chars-forward "^ \t\n\r"))) |
714 (t | |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
715 (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
|
716 (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
|
717 (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
|
718 (> (- (point) bol) 76)) |
33304 | 719 (goto-char (or break qword-break)) |
720 (setq break nil | |
721 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
|
722 (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
|
723 (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
|
724 (insert ?\n) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
725 (insert "\n ")) |
33304 | 726 (setq bol (1- (point))) |
727 ;; Don't break before the first non-LWSP characters. | |
728 (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
|
729 (unless (eobp) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
730 (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
|
731 |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
732 (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
|
733 "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
|
734 (save-excursion |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
735 (save-restriction |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
736 (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
|
737 (rfc2047-unfold-region (point-min) (point-max))))) |
33304 | 738 |
739 (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
|
740 "Unfold lines in region B to E." |
33304 | 741 (save-restriction |
742 (narrow-to-region b e) | |
743 (goto-char (point-min)) | |
744 (let ((bol (save-restriction | |
745 (widen) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
746 (rfc2047-point-at-bol))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
747 (eol (rfc2047-point-at-eol))) |
33304 | 748 (forward-line 1) |
749 (while (not (eobp)) | |
50881
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
750 (if (and (looking-at "[ \t]") |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
751 (< (- (rfc2047-point-at-eol) bol) 76)) |
50881
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
752 (delete-region eol (progn |
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
753 (goto-char eol) |
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
754 (skip-chars-forward "\r\n") |
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
755 (point))) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
756 (setq bol (rfc2047-point-at-bol))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
757 (setq eol (rfc2047-point-at-eol)) |
33304 | 758 (forward-line 1))))) |
31717 | 759 |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
760 (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
|
761 "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
|
762 (base64-encode-string string t)) |
31717 | 763 |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
764 (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
|
765 "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
|
766 (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
|
767 (insert string) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
768 (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
|
769 (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
|
770 ;; = (\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
|
771 ;; 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
|
772 ;; 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
|
773 ;; 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
|
774 ;; 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
|
775 ;; 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
|
776 ;;; ;; 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
|
777 ;;; "\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
|
778 "-\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
|
779 (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
|
780 (buffer-string))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
781 |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
782 (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
|
783 "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
|
784 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
|
785 |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
786 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
|
787 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
|
788 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
|
789 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
|
790 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
|
791 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
|
792 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
|
793 |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
794 \(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
|
795 " |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
796 (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
|
797 (rfc2047-encode-max-chars nil) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
798 (string (rfc2047-encode-string value))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
799 (if (string-match (concat "[" ietf-drums-tspecials "]") string) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
800 (format "%s=%S" param string) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
801 (concat param "=" string)))) |
31717 | 802 |
803 ;;; | |
804 ;;; Functions for decoding RFC2047 messages | |
805 ;;; | |
806 | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
807 (eval-and-compile |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
808 (defconst rfc2047-encoded-word-regexp |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
809 "=\\?\\([^][\000-\040()<>@,\;:*\\\"/?.=]+\\)\\(\\*[^?]+\\)?\ |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
810 \\?\\(B\\|Q\\)\\?\\([!->@-~ ]*\\)\\?=")) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
811 |
60161
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
812 (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
|
813 "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
|
814 |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
815 ;; 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
|
816 ;; 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
|
817 ;; encoding. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
818 |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
819 ;; 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
|
820 ;; 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
|
821 ;; 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
|
822 ;; 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
|
823 ;; `=?iso-8859-1?q?foo?=@'. |
31717 | 824 |
825 (defun rfc2047-decode-region (start end) | |
826 "Decode MIME-encoded words in region between START and END." | |
827 (interactive "r") | |
828 (let ((case-fold-search t) | |
829 b e) | |
47951
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
830 (save-excursion |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
831 (save-restriction |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
832 (narrow-to-region start end) |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
833 (goto-char (point-min)) |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
834 ;; Remove whitespace between encoded words. |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
835 (while (re-search-forward |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
836 (eval-when-compile |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
837 (concat "\\(" rfc2047-encoded-word-regexp "\\)" |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
838 "\\(\n?[ \t]\\)+" |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
839 "\\(" rfc2047-encoded-word-regexp "\\)")) |
47951
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
840 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
|
841 (delete-region (goto-char (match-end 1)) (match-beginning 7))) |
47951
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
842 ;; Decode the encoded words. |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
843 (setq b (goto-char (point-min))) |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
844 (while (re-search-forward rfc2047-encoded-word-regexp nil t) |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
845 (setq e (match-beginning 0)) |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
846 (insert (rfc2047-parse-and-decode |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
847 (prog1 |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
848 (match-string 0) |
60161
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
849 (delete-region e (match-end 0))))) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
850 (while (looking-at rfc2047-encoded-word-regexp) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
851 (insert (rfc2047-parse-and-decode |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
852 (prog1 |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
853 (match-string 0) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
854 (delete-region (point) (match-end 0)))))) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
855 (save-restriction |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
856 (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
|
857 (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
|
858 ;; 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
|
859 ;; 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
|
860 (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
|
861 (replace-match " ")) |
60161
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
862 ;; 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
|
863 ;; 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
|
864 (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
|
865 (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
|
866 'address-mime |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
867 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
|
868 (when regexp |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
869 (save-restriction |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
870 (widen) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
871 (beginning-of-line) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
872 (while (and (memq (char-after) '(? ?\t)) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
873 (zerop (forward-line -1)))) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
874 (looking-at regexp))))) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
875 (let (quoted) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
876 (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
|
877 (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
|
878 (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
|
879 (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
|
880 (goto-char (point-max)) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
881 (skip-chars-backward " \t") |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
882 (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
|
883 (> (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
|
884 (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
|
885 (progn |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
886 (backward-char) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
887 (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
|
888 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
|
889 (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
|
890 (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
|
891 (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
|
892 (when (prog2 |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
893 (backward-char) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
894 (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
|
895 (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
|
896 (insert "\\")) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
897 (forward-char)) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
898 (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
|
899 (progn |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
900 (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
|
901 (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
|
902 (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
|
903 end t))) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
904 (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
|
905 (insert "\"") |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
906 (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
|
907 (insert "\"")) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
908 (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
|
909 (goto-char (point-max))) |
47951
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
910 (when (and (mm-multibyte-p) |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
911 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
|
912 (not (eq mail-parse-charset 'us-ascii)) |
47951
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
913 (not (eq mail-parse-charset 'gnus-decoded))) |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
914 (mm-decode-coding-region b e mail-parse-charset)) |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
915 (setq b (point))) |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
916 (when (and (mm-multibyte-p) |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
917 mail-parse-charset |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
918 (not (eq mail-parse-charset 'us-ascii)) |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
919 (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
|
920 (mm-decode-coding-region b (point-max) mail-parse-charset)))))) |
31717 | 921 |
922 (defun rfc2047-decode-string (string) | |
923 "Decode the quoted-printable-encoded STRING and return the results." | |
924 (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
|
925 (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
|
926 (with-temp-buffer |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
927 ;; Fixme: This logic is wrong, but seems to be required by |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
928 ;; Gnus summary buffer generation. The value of `m' depends |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
929 ;; on the current buffer, not global multibyteness or that |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
930 ;; of the string. Also the string returned should always be |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
931 ;; multibyte in a multibyte session, i.e. the buffer should |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
932 ;; be multibyte before `buffer-string' is called. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
933 (when m |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
934 (mm-enable-multibyte)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
935 (insert string) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
936 (inline |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
937 (rfc2047-decode-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
|
938 (buffer-string)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
939 ;; Fixme: As above, `m' here is inappropriate. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
940 (if (and m |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
941 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
|
942 (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
|
943 (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
|
944 ;; `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
|
945 ;; 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
|
946 ;; 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
|
947 ;; 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
|
948 ;; trivial. |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
949 ;; `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
|
950 ;; 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
|
951 ;; 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
|
952 ;; `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
|
953 (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
|
954 ;; 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
|
955 (eq (detect-coding-string string t) 'undecided)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
956 string |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
957 (mm-decode-coding-string string 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
|
958 (mm-string-as-multibyte string))))) |
31717 | 959 |
47951
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
960 (defun rfc2047-parse-and-decode (word) |
31717 | 961 "Decode WORD and return it if it is an encoded word. |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
962 Return WORD if it is not not an encoded word or if the charset isn't |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
963 decodable." |
47951
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
964 (if (not (string-match rfc2047-encoded-word-regexp word)) |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
965 word |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
966 (or |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
967 (condition-case nil |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
968 (rfc2047-decode |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
969 (match-string 1 word) |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
970 (string-to-char (match-string 3 word)) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
971 (match-string 4 word)) |
47951
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
972 (error word)) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
973 word))) ; un-decodable |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
974 |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
975 (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
|
976 "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
|
977 ;; 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
|
978 ;; 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
|
979 ;; 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
|
980 (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
|
981 string |
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
982 (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
|
983 (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
|
984 (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
|
985 (0 string) |
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
986 (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
|
987 (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
|
988 (3 (concat string "="))))) |
31717 | 989 |
47951
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
990 (defun rfc2047-decode (charset encoding string) |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
991 "Decode STRING from the given MIME CHARSET in the given ENCODING. |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
992 Valid ENCODINGs are the characters \"B\" and \"Q\". |
33304 | 993 If your Emacs implementation can't decode CHARSET, return nil." |
31717 | 994 (if (stringp charset) |
995 (setq charset (intern (downcase charset)))) | |
33304 | 996 (if (or (not charset) |
31717 | 997 (eq 'gnus-all mail-parse-ignored-charsets) |
998 (memq 'gnus-all mail-parse-ignored-charsets) | |
999 (memq charset mail-parse-ignored-charsets)) | |
1000 (setq charset mail-parse-charset)) | |
1001 (let ((cs (mm-charset-to-coding-system charset))) | |
33304 | 1002 (if (and (not cs) charset |
31717 | 1003 (listp mail-parse-ignored-charsets) |
1004 (memq 'gnus-unknown mail-parse-ignored-charsets)) | |
1005 (setq cs (mm-charset-to-coding-system mail-parse-charset))) | |
1006 (when cs | |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
1007 (when (eq cs 'ascii) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
1008 (setq cs (or mail-parse-charset 'raw-text))) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
1009 (mm-decode-coding-string |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
1010 (cond |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
1011 ((char-equal ?B encoding) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
1012 (base64-decode-string |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
1013 (rfc2047-pad-base64 string))) |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
1014 ((char-equal ?Q encoding) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
1015 (quoted-printable-decode-string |
61126
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
1016 (mm-subst-char-in-string ?_ ? string t))) |
c0aa521e0ca7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
1017 (t (error "Invalid encoding: %c" encoding))) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
1018 cs)))) |
31717 | 1019 |
1020 (provide 'rfc2047) | |
1021 | |
52401 | 1022 ;;; arch-tag: a07fe3d4-22b5-4c4a-bd89-b1f82d5d36f6 |
31717 | 1023 ;;; rfc2047.el ends here |