Mercurial > emacs
annotate lisp/gnus/rfc2047.el @ 60391:26a3d09449d7
*** empty log message ***
author | Luc Teirlinck <teirllm@auburn.edu> |
---|---|
date | Sat, 05 Mar 2005 01:15:01 +0000 |
parents | b070535d2416 |
children | c0aa521e0ca7 bf0d492ea2d5 |
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 |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
3 ;; Copyright (C) 1998, 1999, 2000, 2002, 2003, 2004, 2005 |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
4 ;; 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 | |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
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 |
122 (defvar rfc2047-encoding-function-alist | |
123 '((Q . rfc2047-q-encode-region) | |
124 (B . rfc2047-b-encode-region) | |
125 (nil . ignore)) | |
126 "Alist of RFC2047 encodings to encoding functions.") | |
127 | |
128 ;;; | |
129 ;;; Functions for encoding RFC2047 messages | |
130 ;;; | |
131 | |
57243
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
132 (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
|
133 "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
|
134 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
|
135 (save-excursion |
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
136 (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
|
137 (n8bit 0)) |
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
138 (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
|
139 (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
|
140 (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
|
141 (incf n8bit) |
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
142 (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
|
143 (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
|
144 (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
|
145 ;; 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
|
146 ;; 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
|
147 (= n8bit 1)) |
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
148 'quoted-printable |
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
149 'base64)))) |
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
150 |
31717 | 151 (defun rfc2047-narrow-to-field () |
152 "Narrow the buffer to the header on the current line." | |
153 (beginning-of-line) | |
154 (narrow-to-region | |
155 (point) | |
156 (progn | |
157 (forward-line 1) | |
158 (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
|
159 (rfc2047-point-at-bol) |
31717 | 160 (point-max)))) |
161 (goto-char (point-min))) | |
162 | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
163 (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
|
164 "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
|
165 (save-excursion |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
166 (save-restriction |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
167 (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
|
168 (re-search-forward ":[ \t\n]*" nil t) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
169 (buffer-substring (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
|
170 |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
171 (defvar rfc2047-encoding-type 'address-mime |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
172 "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
|
173 This should be dynamically bound around calls to |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
174 `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
|
175 `rfc2047-header-encoding-alist', for definitions.") |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
176 |
31717 | 177 (defun rfc2047-encode-message-header () |
178 "Encode the message header according to `rfc2047-header-encoding-alist'. | |
179 Should be called narrowed to the head of the message." | |
180 (interactive "*") | |
181 (save-excursion | |
182 (goto-char (point-min)) | |
183 (let (alist elem method) | |
184 (while (not (eobp)) | |
185 (save-restriction | |
186 (rfc2047-narrow-to-field) | |
187 (if (not (rfc2047-encodable-p)) | |
50881
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
188 (prog1 |
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
189 (if (and (eq (mm-body-7-or-8) '8bit) |
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
190 (mm-multibyte-p) |
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
191 (mm-coding-system-p |
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
192 (car message-posting-charset))) |
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
193 ;; 8 bit must be decoded. |
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
194 (mm-encode-coding-region |
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
195 (point-min) (point-max) |
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
196 (mm-charset-to-coding-system |
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
197 (car message-posting-charset)))) |
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
198 ;; No encoding necessary, but folding is nice |
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
199 (rfc2047-fold-region |
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
200 (save-excursion |
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
201 (goto-char (point-min)) |
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
202 (skip-chars-forward "^:") |
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
203 (when (looking-at ": ") |
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
204 (forward-char 2)) |
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
205 (point)) |
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
206 (point-max))) |
31717 | 207 ;; We found something that may perhaps be encoded. |
208 (setq method nil | |
209 alist rfc2047-header-encoding-alist) | |
210 (while (setq elem (pop alist)) | |
211 (when (or (and (stringp (car elem)) | |
212 (looking-at (car elem))) | |
213 (eq (car elem) t)) | |
214 (setq alist nil | |
215 method (cdr elem)))) | |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
216 (goto-char (point-min)) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
217 (re-search-forward "^[^:]+: *" nil t) |
31717 | 218 (cond |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
219 ((eq method 'address-mime) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
220 (rfc2047-encode-region (point) (point-max))) |
31717 | 221 ((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
|
222 (let ((rfc2047-encoding-type 'mime)) |
47945
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 'default) |
225 (if (and (featurep 'mule) | |
33815
61c7f3065929
(rfc2047-encode-message-header): Don't encode if
Dave Love <fx@gnu.org>
parents:
33304
diff
changeset
|
226 (if (boundp 'default-enable-multibyte-characters) |
61c7f3065929
(rfc2047-encode-message-header): Don't encode if
Dave Love <fx@gnu.org>
parents:
33304
diff
changeset
|
227 default-enable-multibyte-characters) |
31717 | 228 mail-parse-charset) |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
229 (mm-encode-coding-region (point) (point-max) |
31717 | 230 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
|
231 ;; 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
|
232 ;; 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
|
233 ;; 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
|
234 ;; 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
|
235 ;; 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
|
236 ;; 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
|
237 ;; -- 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
|
238 ;; 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
|
239 ;; 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
|
240 ((null method) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
241 (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
|
242 ;;; ((null method) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
243 ;;; (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
|
244 ;;; '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
|
245 ;;; (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
|
246 ;;; '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
|
247 ;;; (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
|
248 ;;; "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
|
249 ;;; (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
|
250 ;;; (error "Cannot send unencoded text"))) |
31717 | 251 ((mm-coding-system-p method) |
33815
61c7f3065929
(rfc2047-encode-message-header): Don't encode if
Dave Love <fx@gnu.org>
parents:
33304
diff
changeset
|
252 (if (and (featurep 'mule) |
61c7f3065929
(rfc2047-encode-message-header): Don't encode if
Dave Love <fx@gnu.org>
parents:
33304
diff
changeset
|
253 (if (boundp 'default-enable-multibyte-characters) |
61c7f3065929
(rfc2047-encode-message-header): Don't encode if
Dave Love <fx@gnu.org>
parents:
33304
diff
changeset
|
254 default-enable-multibyte-characters)) |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
255 (mm-encode-coding-region (point) (point-max) method))) |
31717 | 256 ;; Hm. |
257 (t))) | |
258 (goto-char (point-max))))))) | |
259 | |
35985
b9c371244b90
(rfc2047-fold-region): Don't forward-char at EOB.
Dave Love <fx@gnu.org>
parents:
35838
diff
changeset
|
260 ;; 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
|
261 ;; 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
|
262 (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
|
263 |
33304 | 264 (defun rfc2047-encodable-p () |
265 "Return non-nil if any characters in current buffer need encoding in headers. | |
266 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
|
267 (require 'message) ; for message-posting-charset |
31717 | 268 (let ((charsets |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
269 (mm-find-mime-charset-region (point-min) (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
|
270 (and charsets |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
271 (not (equal charsets (list (car message-posting-charset))))))) |
31717 | 272 |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
273 ;; 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
|
274 ;; encoding. Double quotes are string delimiters, backslash is |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
275 ;; 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
|
276 ;; 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
|
277 ;; 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
|
278 ;; things differently. |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
279 (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
|
280 ;; (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
|
281 (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
|
282 ;; The following is done to work for setting all elements of the table |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
283 ;; in Emacs 21 and 22 and XEmacs; it appears to be the cleanest way. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
284 ;; 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
|
285 ;; 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
|
286 (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
|
287 (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
|
288 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
|
289 (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
|
290 (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
|
291 (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
|
292 table)))) |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
293 (modify-syntax-entry ?\\ "\\" table) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
294 (modify-syntax-entry ?\" "\"" table) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
295 (modify-syntax-entry ?\( "." table) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
296 (modify-syntax-entry ?\) "." table) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
297 (modify-syntax-entry ?\< "." table) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
298 (modify-syntax-entry ?\> "." table) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
299 (modify-syntax-entry ?\[ "." table) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
300 (modify-syntax-entry ?\] "." table) |
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) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
303 (modify-syntax-entry ?, "." table) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
304 (modify-syntax-entry ?@ "." table) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
305 table)) |
31717 | 306 |
307 (defun rfc2047-encode-region (b e) | |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
308 "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
|
309 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
|
310 Dynamically bind `rfc2047-encoding-type' to change that." |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
311 (save-restriction |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
312 (narrow-to-region b e) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
313 (if (eq 'mime rfc2047-encoding-type) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
314 ;; Simple case. Treat as single word after any initial ASCII |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
315 ;; part and before any tailing ASCII part. The leading ASCII |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
316 ;; is relevant for instance in Subject headers with `Re:' for |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
317 ;; interoperability with non-MIME clients, and we might as |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
318 ;; well avoid the tail too. |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
319 (progn |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
320 (goto-char (point-min)) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
321 ;; Does it need encoding? |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
322 (skip-chars-forward "\000-\177") |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
323 (unless (eobp) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
324 (skip-chars-backward "^ \n") ; beginning of space-delimited word |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
325 (rfc2047-encode (point) (progn |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
326 (goto-char e) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
327 (skip-chars-backward "\000-\177") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
328 (skip-chars-forward "^ \n") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
329 ;; end of space-delimited word |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
330 (point))))) |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
331 ;; `address-mime' case -- take care of quoted words, comments. |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
332 (with-syntax-table 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
|
333 (let ((start) ; start of current token |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
334 end ; end of current token |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
335 ;; Whether there's an encoded word before the current |
50881
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
336 ;; token, either immediately or separated by space. |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
337 last-encoded) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
338 (goto-char (point-min)) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
339 (condition-case nil ; in case of unbalanced quotes |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
340 ;; Look for rfc2822-style: sequences of atoms, quoted |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
341 ;; strings, specials, whitespace. (Specials mustn't be |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
342 ;; encoded.) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
343 (while (not (eobp)) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
344 (setq start (point)) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
345 ;; Skip whitespace. |
50881
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
346 (unless (= 0 (skip-chars-forward " \t\n")) |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
347 (setq start (point))) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
348 (cond |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
349 ((not (char-after))) ; eob |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
350 ;; else token start |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
351 ((eq ?\" (char-syntax (char-after))) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
352 ;; Quoted word. |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
353 (forward-sexp) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
354 (setq end (point)) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
355 ;; Does it need encoding? |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
356 (goto-char start) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
357 (skip-chars-forward "\000-\177" end) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
358 (if (= end (point)) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
359 (setq last-encoded nil) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
360 ;; It needs encoding. Strip the quotes first, |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
361 ;; since encoded words can't occur in quotes. |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
362 (goto-char end) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
363 (delete-backward-char 1) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
364 (goto-char start) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
365 (delete-char 1) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
366 (when last-encoded |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
367 ;; There was a preceding quoted word. We need |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
368 ;; to include any separating whitespace in this |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
369 ;; word to avoid it getting lost. |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
370 (skip-chars-backward " \t") |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
371 ;; A space is needed between the encoded words. |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
372 (insert ? ) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
373 (setq start (point) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
374 end (1+ end))) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
375 ;; Adjust the end position for the deleted quotes. |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
376 (rfc2047-encode start (- end 2)) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
377 (setq last-encoded t))) ; record that it was encoded |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
378 ((eq ?. (char-syntax (char-after))) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
379 ;; Skip other delimiters, but record that they've |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
380 ;; potentially separated quoted words. |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
381 (forward-char) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
382 (setq last-encoded nil)) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
383 (t ; normal token/whitespace sequence |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
384 ;; Find the end. |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
385 (forward-word 1) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
386 (skip-chars-backward " \t") |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
387 (setq end (point)) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
388 ;; Deal with encoding and leading space as for |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
389 ;; quoted words. |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
390 (goto-char start) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
391 (skip-chars-forward "\000-\177" end) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
392 (if (= end (point)) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
393 (setq last-encoded nil) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
394 (when last-encoded |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
395 (goto-char start) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
396 (skip-chars-backward " \t") |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
397 (insert ? ) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
398 (setq start (point) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
399 end (1+ end))) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
400 (rfc2047-encode start end) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
401 (setq last-encoded t))))) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
402 (error |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
403 (error "Invalid data for rfc2047 encoding: %s" |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
404 (buffer-substring b e))))))) |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
405 (rfc2047-fold-region b (point)))) |
31717 | 406 |
407 (defun rfc2047-encode-string (string) | |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
408 "Encode words in STRING. |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
409 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
|
410 `rfc2047-encoding-type')." |
31717 | 411 (with-temp-buffer |
412 (insert string) | |
413 (rfc2047-encode-region (point-min) (point-max)) | |
414 (buffer-string))) | |
415 | |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
416 (defun rfc2047-encode (b e) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
417 "Encode the word(s) in the region B to E. |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
418 By default, the region 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
|
419 `rfc2047-encoding-type')." |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
420 (let* ((mime-charset (mm-find-mime-charset-region b e)) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
421 (cs (if (> (length mime-charset) 1) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
422 ;; Fixme: Instead of this, try to break region into |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
423 ;; parts that can be encoded separately. |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
424 (error "Can't rfc2047-encode `%s'" |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
425 (buffer-substring b e)) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
426 (setq mime-charset (car mime-charset)) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
427 (mm-charset-to-coding-system mime-charset))) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
428 ;; Fixme: Better, calculate the number of non-ASCII |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
429 ;; characters, at least for 8-bit charsets. |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
430 (encoding (or (cdr (assq mime-charset |
31717 | 431 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
|
432 ;; 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
|
433 ;; encoding, choose the one that's shorter. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
434 (save-restriction |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
435 (narrow-to-region b e) |
57243
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
436 (if (eq (rfc2047-qp-or-base64) 'base64) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
437 'B |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
438 'Q)))) |
31717 | 439 (start (concat |
440 "=?" (downcase (symbol-name mime-charset)) "?" | |
441 (downcase (symbol-name encoding)) "?")) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
442 (factor (case mime-charset |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
443 ((iso-8859-5 iso-8859-7 iso-8859-8 koi8-r) 1) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
444 ((big5 gb2312 euc-kr) 2) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
445 (utf-8 4) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
446 (t 8))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
447 (pre (- b (save-restriction |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
448 (widen) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
449 (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
|
450 ;; encoded-words must not be longer than 75 characters, |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
451 ;; including charset, encoding etc. This leaves us with |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
452 ;; 75 - (length start) - 2 - 2 characters. The last 2 is for |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
453 ;; possible base64 padding. In the worst case (iso-2022-*) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
454 ;; each character expands to 8 bytes which is expanded by a |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
455 ;; factor of 4/3 by base64 encoding. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
456 (length (floor (- 75 (length start) 4) (* factor (/ 4.0 3.0)))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
457 ;; Limit line length to 76 characters. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
458 (length1 (max 1 (floor (- 76 (length start) 4 pre) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
459 (* factor (/ 4.0 3.0))))) |
31717 | 460 (first t)) |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
461 (if mime-charset |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
462 (save-restriction |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
463 (narrow-to-region b e) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
464 (when (eq encoding 'B) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
465 ;; break into lines before encoding |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
466 (goto-char (point-min)) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
467 (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
|
468 (if first |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
469 (progn |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
470 (goto-char (min (point-max) (+ length1 (point)))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
471 (setq first nil)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
472 (goto-char (min (point-max) (+ length (point))))) |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
473 (unless (eobp) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
474 (insert ?\n))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
475 (setq first t)) |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
476 (if (and (mm-multibyte-p) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
477 (mm-coding-system-p cs)) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
478 (mm-encode-coding-region (point-min) (point-max) cs)) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
479 (funcall (cdr (assq encoding rfc2047-encoding-function-alist)) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
480 (point-min) (point-max)) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
481 (goto-char (point-min)) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
482 (while (not (eobp)) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
483 (unless first |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
484 (insert ? )) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
485 (setq first nil) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
486 (insert start) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
487 (end-of-line) |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
488 (insert "?=") |
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
489 (forward-line 1)))))) |
31717 | 490 |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
491 (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
|
492 "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
|
493 (save-excursion |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
494 (save-restriction |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
495 (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
|
496 (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
|
497 |
31717 | 498 (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
|
499 "Fold long lines in region B to E." |
31717 | 500 (save-restriction |
501 (narrow-to-region b e) | |
502 (goto-char (point-min)) | |
33304 | 503 (let ((break nil) |
504 (qword-break nil) | |
50881
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
505 (first t) |
33304 | 506 (bol (save-restriction |
507 (widen) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
508 (rfc2047-point-at-bol)))) |
31717 | 509 (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
|
510 (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
|
511 (> (- (point) bol) 76)) |
33304 | 512 (goto-char (or break qword-break)) |
513 (setq break nil | |
514 qword-break nil) | |
50881
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
515 (if (looking-at "[ \t]") |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
516 (insert ?\n) |
35453
26726eff41ca
2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
34674
diff
changeset
|
517 (insert "\n ")) |
33304 | 518 (setq bol (1- (point))) |
519 ;; Don't break before the first non-LWSP characters. | |
520 (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
|
521 (unless (eobp) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
522 (forward-char 1))) |
31717 | 523 (cond |
33304 | 524 ((eq (char-after) ?\n) |
525 (forward-char 1) | |
526 (setq bol (point) | |
527 break nil | |
528 qword-break nil) | |
529 (skip-chars-forward " \t") | |
530 (unless (or (eobp) (eq (char-after) ?\n)) | |
531 (forward-char 1))) | |
532 ((eq (char-after) ?\r) | |
533 (forward-char 1)) | |
31717 | 534 ((memq (char-after) '(? ?\t)) |
33304 | 535 (skip-chars-forward " \t") |
50881
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
536 (if first |
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
537 ;; Don't break just after the header name. |
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
538 (setq first nil) |
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
539 (setq break (1- (point))))) |
33304 | 540 ((not break) |
541 (if (not (looking-at "=\\?[^=]")) | |
542 (if (eq (char-after) ?=) | |
543 (forward-char 1) | |
544 (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
|
545 ;; 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
|
546 (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
|
547 (setq qword-break (point))) |
33304 | 548 (skip-chars-forward "^ \t\n\r"))) |
549 (t | |
550 (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
|
551 (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
|
552 (> (- (point) bol) 76)) |
33304 | 553 (goto-char (or break qword-break)) |
554 (setq break nil | |
555 qword-break nil) | |
50881
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
556 (if (looking-at "[ \t]") |
47945
3915f2c7691e
(message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents:
38413
diff
changeset
|
557 (insert ?\n) |
35453
26726eff41ca
2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
34674
diff
changeset
|
558 (insert "\n ")) |
33304 | 559 (setq bol (1- (point))) |
560 ;; Don't break before the first non-LWSP characters. | |
561 (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
|
562 (unless (eobp) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
563 (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
|
564 |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
565 (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
|
566 "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
|
567 (save-excursion |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
568 (save-restriction |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
569 (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
|
570 (rfc2047-unfold-region (point-min) (point-max))))) |
33304 | 571 |
572 (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
|
573 "Unfold lines in region B to E." |
33304 | 574 (save-restriction |
575 (narrow-to-region b e) | |
576 (goto-char (point-min)) | |
577 (let ((bol (save-restriction | |
578 (widen) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
579 (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
|
580 (eol (rfc2047-point-at-eol))) |
33304 | 581 (forward-line 1) |
582 (while (not (eobp)) | |
50881
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
583 (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
|
584 (< (- (rfc2047-point-at-eol) bol) 76)) |
50881
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
585 (delete-region eol (progn |
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
586 (goto-char eol) |
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
587 (skip-chars-forward "\r\n") |
b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents:
47951
diff
changeset
|
588 (point))) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
589 (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
|
590 (setq eol (rfc2047-point-at-eol)) |
33304 | 591 (forward-line 1))))) |
31717 | 592 |
593 (defun rfc2047-b-encode-region (b e) | |
33304 | 594 "Base64-encode the header contained in region B to E." |
31717 | 595 (save-restriction |
596 (narrow-to-region (goto-char b) e) | |
597 (while (not (eobp)) | |
598 (base64-encode-region (point) (progn (end-of-line) (point)) t) | |
599 (if (and (bolp) (eolp)) | |
600 (delete-backward-char 1)) | |
601 (forward-line)))) | |
602 | |
603 (defun rfc2047-q-encode-region (b e) | |
33304 | 604 "Quoted-printable-encode the header in region B to E." |
31717 | 605 (save-excursion |
606 (save-restriction | |
607 (narrow-to-region (goto-char b) e) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
608 (let ((bol (save-restriction |
33304 | 609 (widen) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
610 (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
|
611 (quoted-printable-encode-region |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
612 b e nil |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
613 ;; = (\075), _ (\137), ? (\077) are used in the encoded word. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
614 ;; Avoid using 8bit characters. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
615 ;; This list excludes `especials' (see the RFC2047 syntax), |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
616 ;; meaning that some characters in non-structured fields will |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
617 ;; get encoded when they con't need to be. The following is |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
618 ;; what it used to be. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
619 ;;; ;; Equivalent to "^\000-\007\011\013\015-\037\200-\377=_?" |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
620 ;;; "\010\012\014\040-\074\076\100-\136\140-\177") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
621 "-\b\n\f !#-'*+0-9A-Z\\^`-~\d") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
622 (subst-char-in-region (point-min) (point-max) ? ?_) |
33304 | 623 ;; The size of QP encapsulation is about 20, so set limit to |
624 ;; 56=76-20. | |
625 (unless (< (- (point-max) (point-min)) 56) | |
626 ;; Don't break if it could fit in one line. | |
627 ;; Let rfc2047-encode-region break it later. | |
628 (goto-char (1+ (point-min))) | |
629 (while (and (not (bobp)) (not (eobp))) | |
630 (goto-char (min (point-max) (+ 56 bol))) | |
631 (search-backward "=" (- (point) 2) t) | |
632 (unless (or (bobp) (eobp)) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
633 (insert ?\n) |
33304 | 634 (setq bol (point))))))))) |
31717 | 635 |
636 ;;; | |
637 ;;; Functions for decoding RFC2047 messages | |
638 ;;; | |
639 | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
640 (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
|
641 (defconst 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
|
642 "=\\?\\([^][\000-\040()<>@,\;:\\\"/?.=]+\\)\\?\\(B\\|Q\\)\ |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
643 \\?\\([!->@-~ +]*\\)\\?=")) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
644 |
60161
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
645 (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
|
646 "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
|
647 |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
648 ;; 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
|
649 ;; 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
|
650 ;; encoding. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
651 |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
652 ;; 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
|
653 ;; 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
|
654 ;; 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
|
655 ;; 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
|
656 ;; `=?iso-8859-1?q?foo?=@'. |
31717 | 657 |
658 (defun rfc2047-decode-region (start end) | |
659 "Decode MIME-encoded words in region between START and END." | |
660 (interactive "r") | |
661 (let ((case-fold-search t) | |
662 b e) | |
47951
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
663 (save-excursion |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
664 (save-restriction |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
665 (narrow-to-region start end) |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
666 (goto-char (point-min)) |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
667 ;; Remove whitespace between encoded words. |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
668 (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
|
669 (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
|
670 (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
|
671 "\\(\n?[ \t]\\)+" |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
672 "\\(" rfc2047-encoded-word-regexp "\\)")) |
47951
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
673 nil t) |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
674 (delete-region (goto-char (match-end 1)) (match-beginning 6))) |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
675 ;; Decode the encoded words. |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
676 (setq b (goto-char (point-min))) |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
677 (while (re-search-forward rfc2047-encoded-word-regexp nil t) |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
678 (setq e (match-beginning 0)) |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
679 (insert (rfc2047-parse-and-decode |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
680 (prog1 |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
681 (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
|
682 (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
|
683 (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
|
684 (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
|
685 (prog1 |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
686 (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
|
687 (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
|
688 (save-restriction |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
689 (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
|
690 (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
|
691 ;; 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
|
692 ;; 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
|
693 (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
|
694 (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
|
695 ;; 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
|
696 ;; 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
|
697 (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
|
698 (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
|
699 'address-mime |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
700 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
|
701 (when regexp |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
702 (save-restriction |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
703 (widen) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
704 (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
|
705 (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
|
706 (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
|
707 (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
|
708 (let (quoted) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
709 (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
|
710 (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
|
711 (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
|
712 (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
|
713 (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
|
714 (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
|
715 (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
|
716 (> (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
|
717 (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
|
718 (progn |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
719 (backward-char) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
720 (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
|
721 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
|
722 (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
|
723 (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
|
724 (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
|
725 (when (prog2 |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
726 (backward-char) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
727 (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
|
728 (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
|
729 (insert "\\")) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
730 (forward-char)) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
731 (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
|
732 (progn |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
733 (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
|
734 (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
|
735 (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
|
736 end t))) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
737 (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
|
738 (insert "\"") |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
739 (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
|
740 (insert "\"")) |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
58835
diff
changeset
|
741 (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
|
742 (goto-char (point-max))) |
47951
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
743 (when (and (mm-multibyte-p) |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
744 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
|
745 (not (eq mail-parse-charset 'us-ascii)) |
47951
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
746 (not (eq mail-parse-charset 'gnus-decoded))) |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
747 (mm-decode-coding-region b e mail-parse-charset)) |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
748 (setq b (point))) |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
749 (when (and (mm-multibyte-p) |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
750 mail-parse-charset |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
751 (not (eq mail-parse-charset 'us-ascii)) |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
752 (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
|
753 (mm-decode-coding-region b (point-max) mail-parse-charset)))))) |
31717 | 754 |
755 (defun rfc2047-decode-string (string) | |
756 "Decode the quoted-printable-encoded STRING and return the results." | |
757 (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
|
758 (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
|
759 (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
|
760 ;; 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
|
761 ;; 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
|
762 ;; 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
|
763 ;; 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
|
764 ;; 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
|
765 ;; 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
|
766 (when m |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
767 (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
|
768 (insert string) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
769 (inline |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
770 (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
|
771 (buffer-string)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
772 ;; 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
|
773 (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
|
774 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
|
775 (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
|
776 (not (eq mail-parse-charset 'gnus-decoded))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
777 (mm-decode-coding-string string 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
|
778 (mm-string-as-multibyte string))))) |
31717 | 779 |
47951
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
780 (defun rfc2047-parse-and-decode (word) |
31717 | 781 "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
|
782 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
|
783 decodable." |
47951
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
784 (if (not (string-match rfc2047-encoded-word-regexp word)) |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
785 word |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
786 (or |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
787 (condition-case nil |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
788 (rfc2047-decode |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
789 (match-string 1 word) |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
790 (upcase (match-string 2 word)) |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
791 (match-string 3 word)) |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
792 (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
|
793 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
|
794 |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
795 (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
|
796 "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
|
797 ;; 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
|
798 ;; 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
|
799 ;; 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
|
800 (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
|
801 string |
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
802 (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
|
803 (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
|
804 (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
|
805 (0 string) |
c5e16264557d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-575
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
806 (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
|
807 (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
|
808 (3 (concat string "="))))) |
31717 | 809 |
47951
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
810 (defun rfc2047-decode (charset encoding string) |
9cd6016af581
Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents:
47945
diff
changeset
|
811 "Decode STRING from the given MIME CHARSET in the given ENCODING. |
31717 | 812 Valid ENCODINGs are \"B\" and \"Q\". |
33304 | 813 If your Emacs implementation can't decode CHARSET, return nil." |
31717 | 814 (if (stringp charset) |
815 (setq charset (intern (downcase charset)))) | |
33304 | 816 (if (or (not charset) |
31717 | 817 (eq 'gnus-all mail-parse-ignored-charsets) |
818 (memq 'gnus-all mail-parse-ignored-charsets) | |
819 (memq charset mail-parse-ignored-charsets)) | |
820 (setq charset mail-parse-charset)) | |
821 (let ((cs (mm-charset-to-coding-system charset))) | |
33304 | 822 (if (and (not cs) charset |
31717 | 823 (listp mail-parse-ignored-charsets) |
824 (memq 'gnus-unknown mail-parse-ignored-charsets)) | |
825 (setq cs (mm-charset-to-coding-system mail-parse-charset))) | |
826 (when cs | |
827 (when (and (eq cs 'ascii) | |
828 mail-parse-charset) | |
829 (setq cs 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
|
830 (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
|
831 (cond |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
832 ((equal "B" encoding) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
833 (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
|
834 (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
|
835 ((equal "Q" encoding) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
836 (quoted-printable-decode-string |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
837 (mm-replace-chars-in-string string ?_ ? ))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
838 (t (error "Invalid encoding: %s" encoding))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55411
diff
changeset
|
839 cs)))) |
31717 | 840 |
841 (provide 'rfc2047) | |
842 | |
52401 | 843 ;;; arch-tag: a07fe3d4-22b5-4c4a-bd89-b1f82d5d36f6 |
31717 | 844 ;;; rfc2047.el ends here |