annotate lisp/gnus/rfc2047.el @ 82951:0fde48feb604

Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
author Andreas Schwab <schwab@suse.de>
date Thu, 22 Jul 2004 16:45:51 +0000
parents d0e0914b0f6d
children c5e16264557d cce1c0ee76ee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
2 ;; Copyright (C) 1998, 1999, 2000, 2002, 2003 Free Software Foundation, Inc.
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
3
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
5 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
6 ;; This file is part of GNU Emacs.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
7
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
8 ;; GNU Emacs is free software; you can redistribute it and/or modify
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
9 ;; it under the terms of the GNU General Public License as published by
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
10 ;; the Free Software Foundation; either version 2, or (at your option)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
11 ;; any later version.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
12
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
13 ;; GNU Emacs is distributed in the hope that it will be useful,
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
16 ;; GNU General Public License for more details.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
17
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
18 ;; You should have received a copy of the GNU General Public License
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
19 ;; along with GNU Emacs; see the file COPYING. If not, write to the
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
20 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
21 ;; Boston, MA 02111-1307, USA.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
22
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
23 ;;; Commentary:
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
24
34674
79dde983f45b Add some commentary.
Dave Love <fx@gnu.org>
parents: 33815
diff changeset
25 ;; RFC 2047 is "MIME (Multipurpose Internet Mail Extensions) Part
79dde983f45b Add some commentary.
Dave Love <fx@gnu.org>
parents: 33815
diff changeset
26 ;; Three: Message Header Extensions for Non-ASCII Text".
79dde983f45b Add some commentary.
Dave Love <fx@gnu.org>
parents: 33815
diff changeset
27
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
28 ;;; Code:
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
29
47945
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
30 (eval-when-compile
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
31 (require 'cl)
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
32 (defvar message-posting-charset)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
33 (unless (fboundp 'with-syntax-table) ; not in Emacs 20
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
34 (defmacro with-syntax-table (table &rest body)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
35 "Evaluate BODY with syntax table of current buffer set to TABLE.
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
36 The syntax table of the current buffer is saved, BODY is evaluated, and the
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
37 saved table is restored, even in case of an abnormal exit.
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
38 Value is what BODY returns."
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
39 (let ((old-table (make-symbol "table"))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
40 (old-buffer (make-symbol "buffer")))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
41 `(let ((,old-table (syntax-table))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
42 (,old-buffer (current-buffer)))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
43 (unwind-protect
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
44 (progn
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
45 (set-syntax-table ,table)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
46 ,@body)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
47 (save-current-buffer
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
48 (set-buffer ,old-buffer)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
49 (set-syntax-table ,old-table))))))))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
50
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
51 (require 'qp)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
52 (require 'mm-util)
47945
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
53 ;; Fixme: Avoid this (used for mail-parse-charset) mm dependence on gnus.
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
54 (require 'mail-prsvr)
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
55 (require 'base64)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
56 (autoload 'mm-body-7-or-8 "mm-bodies")
33127
eca95f9d7f05 (base64): Require unconditionally.
Dave Love <fx@gnu.org>
parents: 31764
diff changeset
57
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
58 (eval-and-compile
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
59 ;; Avoid gnus-util for mm- code.
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
60 (defalias 'rfc2047-point-at-bol
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
61 (if (fboundp 'point-at-bol)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
62 'point-at-bol
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
63 'line-beginning-position))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
64
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
65 (defalias 'rfc2047-point-at-eol
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
66 (if (fboundp 'point-at-eol)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
67 'point-at-eol
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
68 'line-end-position)))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
69
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
70 (defvar rfc2047-header-encoding-alist
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
71 '(("Newsgroups" . nil)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
72 ("Followup-To" . nil)
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
73 ("Message-ID" . nil)
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
74 ("\\(Resent-\\)?\\(From\\|Cc\\|To\\|Bcc\\|Reply-To\\|Sender\
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
75 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\)" . address-mime)
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
76 (t . mime))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
77 "*Header/encoding method alist.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
78 The list is traversed sequentially. The keys can either be
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
79 header regexps or t.
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
80
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
81 The values can be:
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
82
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
83 1) nil, in which case no encoding is done;
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
84 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
85 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
86 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
87 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
88 5) `default', in which case the field will be encoded as the rest
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
89 of the article.")
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
90
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
91 (defvar rfc2047-charset-encoding-alist
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
92 '((us-ascii . nil)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
93 (iso-8859-1 . Q)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
94 (iso-8859-2 . Q)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
95 (iso-8859-3 . Q)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
96 (iso-8859-4 . Q)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
97 (iso-8859-5 . B)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
98 (koi8-r . B)
47945
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
99 (iso-8859-7 . B)
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
100 (iso-8859-8 . B)
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
101 (iso-8859-9 . Q)
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
102 (iso-8859-14 . Q)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
103 (iso-8859-15 . Q)
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
104 (iso-2022-jp . B)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
105 (iso-2022-kr . B)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
106 (gb2312 . B)
35838
53eebdb81828 2001-02-01 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents: 35453
diff changeset
107 (big5 . B)
53eebdb81828 2001-02-01 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents: 35453
diff changeset
108 (cn-big5 . B)
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
109 (cn-gb . B)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
110 (cn-gb-2312 . B)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
111 (euc-kr . B)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
112 (iso-2022-jp-2 . B)
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
113 (iso-2022-int-1 . B)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
114 (viscii . Q))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
115 "Alist of MIME charsets to RFC2047 encodings.
47945
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
116 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
117 quoted-printable and base64 respectively.")
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
118
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
119 (defvar rfc2047-encoding-function-alist
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
120 '((Q . rfc2047-q-encode-region)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
121 (B . rfc2047-b-encode-region)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
122 (nil . ignore))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
123 "Alist of RFC2047 encodings to encoding functions.")
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
124
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
125 ;;;
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
126 ;;; Functions for encoding RFC2047 messages
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
127 ;;;
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
128
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
129 (defun rfc2047-narrow-to-field ()
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
130 "Narrow the buffer to the header on the current line."
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
131 (beginning-of-line)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
132 (narrow-to-region
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
133 (point)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
134 (progn
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
135 (forward-line 1)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
136 (if (re-search-forward "^[^ \n\t]" nil t)
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
137 (rfc2047-point-at-bol)
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
138 (point-max))))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
139 (goto-char (point-min)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
140
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
141 (defun rfc2047-field-value ()
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
142 "Return the value of the field at point."
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
143 (save-excursion
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
144 (save-restriction
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
145 (rfc2047-narrow-to-field)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
146 (re-search-forward ":[ \t\n]*" nil t)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
147 (buffer-substring (point) (point-max)))))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
148
47945
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
149 (defvar rfc2047-encoding-type 'address-mime
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
150 "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
151 This should be dynamically bound around calls to
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
152 `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
153 `rfc2047-header-encoding-alist', for definitions.")
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
154
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
155 (defun rfc2047-encode-message-header ()
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
156 "Encode the message header according to `rfc2047-header-encoding-alist'.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
157 Should be called narrowed to the head of the message."
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
158 (interactive "*")
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
159 (save-excursion
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
160 (goto-char (point-min))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
161 (let (alist elem method)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
162 (while (not (eobp))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
163 (save-restriction
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
164 (rfc2047-narrow-to-field)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
165 (if (not (rfc2047-encodable-p))
50881
b042c57894f8 (rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents: 47951
diff changeset
166 (prog1
b042c57894f8 (rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents: 47951
diff changeset
167 (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
168 (mm-multibyte-p)
b042c57894f8 (rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents: 47951
diff changeset
169 (mm-coding-system-p
b042c57894f8 (rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents: 47951
diff changeset
170 (car message-posting-charset)))
b042c57894f8 (rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents: 47951
diff changeset
171 ;; 8 bit must be decoded.
b042c57894f8 (rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents: 47951
diff changeset
172 (mm-encode-coding-region
b042c57894f8 (rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents: 47951
diff changeset
173 (point-min) (point-max)
b042c57894f8 (rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents: 47951
diff changeset
174 (mm-charset-to-coding-system
b042c57894f8 (rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents: 47951
diff changeset
175 (car message-posting-charset))))
b042c57894f8 (rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents: 47951
diff changeset
176 ;; No encoding necessary, but folding is nice
b042c57894f8 (rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents: 47951
diff changeset
177 (rfc2047-fold-region
b042c57894f8 (rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents: 47951
diff changeset
178 (save-excursion
b042c57894f8 (rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents: 47951
diff changeset
179 (goto-char (point-min))
b042c57894f8 (rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents: 47951
diff changeset
180 (skip-chars-forward "^:")
b042c57894f8 (rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents: 47951
diff changeset
181 (when (looking-at ": ")
b042c57894f8 (rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents: 47951
diff changeset
182 (forward-char 2))
b042c57894f8 (rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents: 47951
diff changeset
183 (point))
b042c57894f8 (rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents: 47951
diff changeset
184 (point-max)))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
185 ;; We found something that may perhaps be encoded.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
186 (setq method nil
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
187 alist rfc2047-header-encoding-alist)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
188 (while (setq elem (pop alist))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
189 (when (or (and (stringp (car elem))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
190 (looking-at (car elem)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
191 (eq (car elem) t))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
192 (setq alist nil
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
193 method (cdr elem))))
47945
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
194 (goto-char (point-min))
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
195 (re-search-forward "^[^:]+: *" nil t)
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
196 (cond
47945
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
197 ((eq method 'address-mime)
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
198 (rfc2047-encode-region (point) (point-max)))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
199 ((eq method 'mime)
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
200 (let ((rfc2047-encoding-type 'mime))
47945
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
201 (rfc2047-encode-region (point) (point-max))))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
202 ((eq method 'default)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
203 (if (and (featurep 'mule)
33815
61c7f3065929 (rfc2047-encode-message-header): Don't encode if
Dave Love <fx@gnu.org>
parents: 33304
diff changeset
204 (if (boundp 'default-enable-multibyte-characters)
61c7f3065929 (rfc2047-encode-message-header): Don't encode if
Dave Love <fx@gnu.org>
parents: 33304
diff changeset
205 default-enable-multibyte-characters)
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
206 mail-parse-charset)
47945
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
207 (mm-encode-coding-region (point) (point-max)
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
208 mail-parse-charset)))
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
209 ;; We get this when CC'ing messsages to newsgroups with
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
210 ;; 8-bit names. The group name mail copy just got
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
211 ;; unconditionally encoded. Previously, it would ask
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
212 ;; whether to encode, which was quite confusing for the
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
213 ;; user. If the new behaviour is wrong, tell me. I have
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
214 ;; left the old code commented out below.
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
215 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-07.
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
216 ;; Modified by Dave Love, with the commented-out code changed
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
217 ;; in accordance with changes elsewhere.
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
218 ((null method)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
219 (rfc2047-encode-region (point) (point-max)))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
220 ;;; ((null method)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
221 ;;; (if (or (message-options-get
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
222 ;;; 'rfc2047-encode-message-header-encode-any)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
223 ;;; (message-options-set
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
224 ;;; 'rfc2047-encode-message-header-encode-any
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
225 ;;; (y-or-n-p
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
226 ;;; "Some texts are not encoded. Encode anyway?")))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
227 ;;; (rfc2047-encode-region (point-min) (point-max))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
228 ;;; (error "Cannot send unencoded text")))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
229 ((mm-coding-system-p method)
33815
61c7f3065929 (rfc2047-encode-message-header): Don't encode if
Dave Love <fx@gnu.org>
parents: 33304
diff changeset
230 (if (and (featurep 'mule)
61c7f3065929 (rfc2047-encode-message-header): Don't encode if
Dave Love <fx@gnu.org>
parents: 33304
diff changeset
231 (if (boundp 'default-enable-multibyte-characters)
61c7f3065929 (rfc2047-encode-message-header): Don't encode if
Dave Love <fx@gnu.org>
parents: 33304
diff changeset
232 default-enable-multibyte-characters))
47945
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
233 (mm-encode-coding-region (point) (point-max) method)))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
234 ;; Hm.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
235 (t)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
236 (goto-char (point-max)))))))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
237
35985
b9c371244b90 (rfc2047-fold-region): Don't forward-char at EOB.
Dave Love <fx@gnu.org>
parents: 35838
diff changeset
238 ;; 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
239 ;; 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
240 (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
241
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
242 (defun rfc2047-encodable-p ()
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
243 "Return non-nil if any characters in current buffer need encoding in headers.
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
244 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
245 (require 'message) ; for message-posting-charset
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
246 (let ((charsets
47945
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
247 (mm-find-mime-charset-region (point-min) (point-max))))
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
248 (and charsets
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
249 (not (equal charsets (list (car message-posting-charset)))))))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
250
47945
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
251 ;; 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
252 ;; encoding. Double quotes are string delimiters, backslash is
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
253 ;; 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
254 ;; 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
255 ;; 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
256 ;; things differently.
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
257 (defconst rfc2047-syntax-table
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
258 ;; (make-char-table 'syntax-table '(2)) only works in Emacs.
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
259 (let ((table (make-syntax-table)))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
260 ;; The following is done to work for setting all elements of the table
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
261 ;; in Emacs 21 and 22 and XEmacs; it appears to be the cleanest way.
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
262 ;; Play safe and don't assume the form of the word syntax entry --
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
263 ;; copy it from ?a.
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
264 (if (fboundp 'set-char-table-range) ; Emacs
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
265 (funcall (intern "set-char-table-range")
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
266 table t (aref (standard-syntax-table) ?a))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
267 (if (fboundp 'put-char-table)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
268 (if (fboundp 'get-char-table) ; warning avoidance
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
269 (put-char-table t (get-char-table ?a (standard-syntax-table))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
270 table))))
47945
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
271 (modify-syntax-entry ?\\ "\\" table)
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
272 (modify-syntax-entry ?\" "\"" table)
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
273 (modify-syntax-entry ?\( "." table)
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
274 (modify-syntax-entry ?\) "." table)
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
275 (modify-syntax-entry ?\< "." table)
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
276 (modify-syntax-entry ?\> "." table)
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
277 (modify-syntax-entry ?\[ "." table)
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
278 (modify-syntax-entry ?\] "." table)
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
279 (modify-syntax-entry ?: "." table)
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
280 (modify-syntax-entry ?\; "." table)
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
281 (modify-syntax-entry ?, "." table)
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
282 (modify-syntax-entry ?@ "." table)
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
283 table))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
284
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
285 (defun rfc2047-encode-region (b e)
47945
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
286 "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
287 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
288 Dynamically bind `rfc2047-encoding-type' to change that."
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
289 (save-restriction
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
290 (narrow-to-region b e)
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
291 (if (eq 'mime rfc2047-encoding-type)
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
292 ;; Simple case. Treat as single word after any initial ASCII
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
293 ;; part and before any tailing ASCII part. The leading ASCII
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
294 ;; is relevant for instance in Subject headers with `Re:' for
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
295 ;; interoperability with non-MIME clients, and we might as
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
296 ;; well avoid the tail too.
47945
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
297 (progn
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
298 (goto-char (point-min))
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
299 ;; Does it need encoding?
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
300 (skip-chars-forward "\000-\177")
47945
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
301 (unless (eobp)
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
302 (skip-chars-backward "^ \n") ; beginning of space-delimited word
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
303 (rfc2047-encode (point) (progn
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
304 (goto-char e)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
305 (skip-chars-backward "\000-\177")
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
306 (skip-chars-forward "^ \n")
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
307 ;; end of space-delimited word
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
308 (point)))))
47945
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
309 ;; `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
310 (with-syntax-table rfc2047-syntax-table
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
311 (let ((start) ; start of current token
47945
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
312 end ; end of current token
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
313 ;; 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
314 ;; token, either immediately or separated by space.
47945
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
315 last-encoded)
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
316 (goto-char (point-min))
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
317 (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
318 ;; Look for rfc2822-style: sequences of atoms, quoted
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
319 ;; strings, specials, whitespace. (Specials mustn't be
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
320 ;; encoded.)
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
321 (while (not (eobp))
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
322 (setq start (point))
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
323 ;; Skip whitespace.
50881
b042c57894f8 (rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents: 47951
diff changeset
324 (unless (= 0 (skip-chars-forward " \t\n"))
47945
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
325 (setq start (point)))
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
326 (cond
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
327 ((not (char-after))) ; eob
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
328 ;; else token start
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
329 ((eq ?\" (char-syntax (char-after)))
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
330 ;; Quoted word.
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
331 (forward-sexp)
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
332 (setq end (point))
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
333 ;; Does it need encoding?
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
334 (goto-char start)
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
335 (skip-chars-forward "\000-\177" end)
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
336 (if (= end (point))
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
337 (setq last-encoded nil)
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
338 ;; It needs encoding. Strip the quotes first,
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
339 ;; since encoded words can't occur in quotes.
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
340 (goto-char end)
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
341 (delete-backward-char 1)
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
342 (goto-char start)
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
343 (delete-char 1)
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
344 (when last-encoded
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
345 ;; There was a preceding quoted word. We need
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
346 ;; to include any separating whitespace in this
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
347 ;; word to avoid it getting lost.
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
348 (skip-chars-backward " \t")
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
349 ;; A space is needed between the encoded words.
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
350 (insert ? )
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
351 (setq start (point)
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
352 end (1+ end)))
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
353 ;; Adjust the end position for the deleted quotes.
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
354 (rfc2047-encode start (- end 2))
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
355 (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
356 ((eq ?. (char-syntax (char-after)))
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
357 ;; Skip other delimiters, but record that they've
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
358 ;; potentially separated quoted words.
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
359 (forward-char)
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
360 (setq last-encoded nil))
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
361 (t ; normal token/whitespace sequence
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
362 ;; Find the end.
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
363 (forward-word 1)
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
364 (skip-chars-backward " \t")
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
365 (setq end (point))
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
366 ;; Deal with encoding and leading space as for
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
367 ;; quoted words.
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
368 (goto-char start)
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
369 (skip-chars-forward "\000-\177" end)
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
370 (if (= end (point))
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
371 (setq last-encoded nil)
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
372 (when last-encoded
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
373 (goto-char start)
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
374 (skip-chars-backward " \t")
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
375 (insert ? )
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
376 (setq start (point)
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
377 end (1+ end)))
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
378 (rfc2047-encode start end)
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
379 (setq last-encoded t)))))
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
380 (error
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
381 (error "Invalid data for rfc2047 encoding: %s"
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
382 (buffer-substring b e)))))))
47945
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
383 (rfc2047-fold-region b (point))))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
384
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
385 (defun rfc2047-encode-string (string)
47945
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
386 "Encode words in STRING.
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
387 By default, the string is treated as containing addresses (see
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
388 `rfc2047-encoding-type')."
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
389 (with-temp-buffer
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
390 (insert string)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
391 (rfc2047-encode-region (point-min) (point-max))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
392 (buffer-string)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
393
47945
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
394 (defun rfc2047-encode (b e)
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
395 "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
396 By default, the region is treated as containing addresses (see
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
397 `rfc2047-encoding-type')."
47945
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
398 (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
399 (cs (if (> (length mime-charset) 1)
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
400 ;; 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
401 ;; parts that can be encoded separately.
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
402 (error "Can't rfc2047-encode `%s'"
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
403 (buffer-substring b e))
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
404 (setq mime-charset (car mime-charset))
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
405 (mm-charset-to-coding-system mime-charset)))
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
406 ;; Fixme: Better, calculate the number of non-ASCII
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
407 ;; characters, at least for 8-bit charsets.
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
408 (encoding (or (cdr (assq mime-charset
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
409 rfc2047-charset-encoding-alist))
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
410 ;; For the charsets that don't have a preferred
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
411 ;; encoding, choose the one that's shorter.
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
412 (save-restriction
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
413 (narrow-to-region b e)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
414 (if (eq (mm-qp-or-base64) 'base64)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
415 'B
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
416 'Q))))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
417 (start (concat
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
418 "=?" (downcase (symbol-name mime-charset)) "?"
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
419 (downcase (symbol-name encoding)) "?"))
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
420 (factor (case mime-charset
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
421 ((iso-8859-5 iso-8859-7 iso-8859-8 koi8-r) 1)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
422 ((big5 gb2312 euc-kr) 2)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
423 (utf-8 4)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
424 (t 8)))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
425 (pre (- b (save-restriction
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
426 (widen)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
427 (rfc2047-point-at-bol))))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
428 ;; encoded-words must not be longer than 75 characters,
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
429 ;; including charset, encoding etc. This leaves us with
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
430 ;; 75 - (length start) - 2 - 2 characters. The last 2 is for
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
431 ;; possible base64 padding. In the worst case (iso-2022-*)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
432 ;; each character expands to 8 bytes which is expanded by a
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
433 ;; factor of 4/3 by base64 encoding.
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
434 (length (floor (- 75 (length start) 4) (* factor (/ 4.0 3.0))))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
435 ;; Limit line length to 76 characters.
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
436 (length1 (max 1 (floor (- 76 (length start) 4 pre)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
437 (* factor (/ 4.0 3.0)))))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
438 (first t))
47945
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
439 (if mime-charset
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
440 (save-restriction
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
441 (narrow-to-region b e)
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
442 (when (eq encoding 'B)
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
443 ;; break into lines before encoding
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
444 (goto-char (point-min))
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
445 (while (not (eobp))
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
446 (if first
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
447 (progn
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
448 (goto-char (min (point-max) (+ length1 (point))))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
449 (setq first nil))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
450 (goto-char (min (point-max) (+ length (point)))))
47945
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
451 (unless (eobp)
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
452 (insert ?\n)))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
453 (setq first t))
47945
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
454 (if (and (mm-multibyte-p)
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
455 (mm-coding-system-p cs))
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
456 (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
457 (funcall (cdr (assq encoding rfc2047-encoding-function-alist))
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
458 (point-min) (point-max))
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
459 (goto-char (point-min))
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
460 (while (not (eobp))
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
461 (unless first
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
462 (insert ? ))
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
463 (setq first nil)
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
464 (insert start)
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
465 (end-of-line)
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
466 (insert "?=")
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
467 (forward-line 1))))))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
468
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
469 (defun rfc2047-fold-field ()
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
470 "Fold the current header field."
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
471 (save-excursion
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
472 (save-restriction
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
473 (rfc2047-narrow-to-field)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
474 (rfc2047-fold-region (point-min) (point-max)))))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
475
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
476 (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
477 "Fold long lines in region B to E."
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
478 (save-restriction
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
479 (narrow-to-region b e)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
480 (goto-char (point-min))
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
481 (let ((break nil)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
482 (qword-break nil)
50881
b042c57894f8 (rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents: 47951
diff changeset
483 (first t)
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
484 (bol (save-restriction
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
485 (widen)
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
486 (rfc2047-point-at-bol))))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
487 (while (not (eobp))
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
488 (when (and (or break qword-break)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
489 (> (- (point) bol) 76))
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
490 (goto-char (or break qword-break))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
491 (setq break nil
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
492 qword-break nil)
50881
b042c57894f8 (rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents: 47951
diff changeset
493 (if (looking-at "[ \t]")
47945
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
494 (insert ?\n)
35453
26726eff41ca 2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents: 34674
diff changeset
495 (insert "\n "))
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
496 (setq bol (1- (point)))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
497 ;; Don't break before the first non-LWSP characters.
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
498 (skip-chars-forward " \t")
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
499 (unless (eobp)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
500 (forward-char 1)))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
501 (cond
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
502 ((eq (char-after) ?\n)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
503 (forward-char 1)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
504 (setq bol (point)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
505 break nil
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
506 qword-break nil)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
507 (skip-chars-forward " \t")
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
508 (unless (or (eobp) (eq (char-after) ?\n))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
509 (forward-char 1)))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
510 ((eq (char-after) ?\r)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
511 (forward-char 1))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
512 ((memq (char-after) '(? ?\t))
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
513 (skip-chars-forward " \t")
50881
b042c57894f8 (rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents: 47951
diff changeset
514 (if first
b042c57894f8 (rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents: 47951
diff changeset
515 ;; 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
516 (setq first nil)
b042c57894f8 (rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents: 47951
diff changeset
517 (setq break (1- (point)))))
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
518 ((not break)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
519 (if (not (looking-at "=\\?[^=]"))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
520 (if (eq (char-after) ?=)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
521 (forward-char 1)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
522 (skip-chars-forward "^ \t\n\r="))
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
523 ;; Don't break at the start of the field.
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
524 (unless (= (point) b)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
525 (setq qword-break (point)))
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
526 (skip-chars-forward "^ \t\n\r")))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
527 (t
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
528 (skip-chars-forward "^ \t\n\r"))))
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
529 (when (and (or break qword-break)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
530 (> (- (point) bol) 76))
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
531 (goto-char (or break qword-break))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
532 (setq break nil
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
533 qword-break nil)
50881
b042c57894f8 (rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents: 47951
diff changeset
534 (if (looking-at "[ \t]")
47945
3915f2c7691e (message-posting-charset): defvar when compiling.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
535 (insert ?\n)
35453
26726eff41ca 2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents: 34674
diff changeset
536 (insert "\n "))
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
537 (setq bol (1- (point)))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
538 ;; Don't break before the first non-LWSP characters.
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
539 (skip-chars-forward " \t")
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
540 (unless (eobp)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
541 (forward-char 1))))))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
542
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
543 (defun rfc2047-unfold-field ()
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
544 "Fold the current line."
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
545 (save-excursion
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
546 (save-restriction
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
547 (rfc2047-narrow-to-field)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
548 (rfc2047-unfold-region (point-min) (point-max)))))
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
549
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
550 (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
551 "Unfold lines in region B to E."
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
552 (save-restriction
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
553 (narrow-to-region b e)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
554 (goto-char (point-min))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
555 (let ((bol (save-restriction
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
556 (widen)
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
557 (rfc2047-point-at-bol)))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
558 (eol (rfc2047-point-at-eol)))
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
559 (forward-line 1)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
560 (while (not (eobp))
50881
b042c57894f8 (rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents: 47951
diff changeset
561 (if (and (looking-at "[ \t]")
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
562 (< (- (rfc2047-point-at-eol) bol) 76))
50881
b042c57894f8 (rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents: 47951
diff changeset
563 (delete-region eol (progn
b042c57894f8 (rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents: 47951
diff changeset
564 (goto-char eol)
b042c57894f8 (rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents: 47951
diff changeset
565 (skip-chars-forward "\r\n")
b042c57894f8 (rfc2047-header-encoding-alist): Add Followup-To.
Dave Love <fx@gnu.org>
parents: 47951
diff changeset
566 (point)))
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
567 (setq bol (rfc2047-point-at-bol)))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
568 (setq eol (rfc2047-point-at-eol))
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
569 (forward-line 1)))))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
570
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
571 (defun rfc2047-b-encode-region (b e)
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
572 "Base64-encode the header contained in region B to E."
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
573 (save-restriction
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
574 (narrow-to-region (goto-char b) e)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
575 (while (not (eobp))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
576 (base64-encode-region (point) (progn (end-of-line) (point)) t)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
577 (if (and (bolp) (eolp))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
578 (delete-backward-char 1))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
579 (forward-line))))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
580
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
581 (defun rfc2047-q-encode-region (b e)
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
582 "Quoted-printable-encode the header in region B to E."
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
583 (save-excursion
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
584 (save-restriction
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
585 (narrow-to-region (goto-char b) e)
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
586 (let ((bol (save-restriction
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
587 (widen)
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
588 (rfc2047-point-at-bol))))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
589 (quoted-printable-encode-region
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
590 b e nil
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
591 ;; = (\075), _ (\137), ? (\077) are used in the encoded word.
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
592 ;; Avoid using 8bit characters.
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
593 ;; This list excludes `especials' (see the RFC2047 syntax),
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
594 ;; meaning that some characters in non-structured fields will
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
595 ;; get encoded when they con't need to be. The following is
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
596 ;; what it used to be.
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
597 ;;; ;; Equivalent to "^\000-\007\011\013\015-\037\200-\377=_?"
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
598 ;;; "\010\012\014\040-\074\076\100-\136\140-\177")
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
599 "-\b\n\f !#-'*+0-9A-Z\\^`-~\d")
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
600 (subst-char-in-region (point-min) (point-max) ? ?_)
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
601 ;; The size of QP encapsulation is about 20, so set limit to
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
602 ;; 56=76-20.
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
603 (unless (< (- (point-max) (point-min)) 56)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
604 ;; Don't break if it could fit in one line.
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
605 ;; Let rfc2047-encode-region break it later.
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
606 (goto-char (1+ (point-min)))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
607 (while (and (not (bobp)) (not (eobp)))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
608 (goto-char (min (point-max) (+ 56 bol)))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
609 (search-backward "=" (- (point) 2) t)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
610 (unless (or (bobp) (eobp))
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
611 (insert ?\n)
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
612 (setq bol (point)))))))))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
613
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
614 ;;;
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
615 ;;; Functions for decoding RFC2047 messages
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
616 ;;;
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
617
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
618 (eval-and-compile
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
619 (defconst rfc2047-encoded-word-regexp
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
620 "=\\?\\([^][\000-\040()<>@,\;:\\\"/?.=]+\\)\\?\\(B\\|Q\\)\
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
621 \\?\\([!->@-~ +]*\\)\\?="))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
622
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
623 ;; Fixme: This should decode in place, not cons intermediate strings.
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
624 ;; Also check whether it needs to worry about delimiting fields like
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
625 ;; encoding.
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
626
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
627 ;; In fact it's reported that (invalid) encoding of mailboxes in
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
628 ;; addr-specs is in use, so delimiting fields might help. Probably
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
629 ;; not decoding a word which isn't properly delimited is good enough
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
630 ;; and worthwhile (is it more correct or not?), e.g. something like
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
631 ;; `=?iso-8859-1?q?foo?=@'.
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
632
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
633 (defun rfc2047-decode-region (start end)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
634 "Decode MIME-encoded words in region between START and END."
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
635 (interactive "r")
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
636 (let ((case-fold-search t)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
637 b e)
47951
9cd6016af581 Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents: 47945
diff changeset
638 (save-excursion
9cd6016af581 Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents: 47945
diff changeset
639 (save-restriction
9cd6016af581 Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents: 47945
diff changeset
640 (narrow-to-region start end)
9cd6016af581 Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents: 47945
diff changeset
641 (goto-char (point-min))
9cd6016af581 Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents: 47945
diff changeset
642 ;; Remove whitespace between encoded words.
9cd6016af581 Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents: 47945
diff changeset
643 (while (re-search-forward
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
644 (eval-when-compile
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
645 (concat "\\(" rfc2047-encoded-word-regexp "\\)"
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
646 "\\(\n?[ \t]\\)+"
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
647 "\\(" rfc2047-encoded-word-regexp "\\)"))
47951
9cd6016af581 Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents: 47945
diff changeset
648 nil t)
9cd6016af581 Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents: 47945
diff changeset
649 (delete-region (goto-char (match-end 1)) (match-beginning 6)))
9cd6016af581 Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents: 47945
diff changeset
650 ;; Decode the encoded words.
9cd6016af581 Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents: 47945
diff changeset
651 (setq b (goto-char (point-min)))
9cd6016af581 Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents: 47945
diff changeset
652 (while (re-search-forward rfc2047-encoded-word-regexp nil t)
9cd6016af581 Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents: 47945
diff changeset
653 (setq e (match-beginning 0))
9cd6016af581 Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents: 47945
diff changeset
654 (insert (rfc2047-parse-and-decode
9cd6016af581 Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents: 47945
diff changeset
655 (prog1
9cd6016af581 Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents: 47945
diff changeset
656 (match-string 0)
9cd6016af581 Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents: 47945
diff changeset
657 (delete-region (match-beginning 0) (match-end 0)))))
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
658 ;; Remove newlines between decoded words, though such things
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
659 ;; essentially must not be there.
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
660 (save-restriction
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
661 (narrow-to-region e (point))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
662 (goto-char e)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
663 (while (re-search-forward "[\n\r]+" nil t)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
664 (replace-match " "))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
665 (goto-char (point-max)))
47951
9cd6016af581 Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents: 47945
diff changeset
666 (when (and (mm-multibyte-p)
9cd6016af581 Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents: 47945
diff changeset
667 mail-parse-charset
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
668 (not (eq mail-parse-charset 'us-ascii))
47951
9cd6016af581 Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents: 47945
diff changeset
669 (not (eq mail-parse-charset 'gnus-decoded)))
9cd6016af581 Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents: 47945
diff changeset
670 (mm-decode-coding-region b e mail-parse-charset))
9cd6016af581 Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents: 47945
diff changeset
671 (setq b (point)))
9cd6016af581 Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents: 47945
diff changeset
672 (when (and (mm-multibyte-p)
9cd6016af581 Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents: 47945
diff changeset
673 mail-parse-charset
9cd6016af581 Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents: 47945
diff changeset
674 (not (eq mail-parse-charset 'us-ascii))
9cd6016af581 Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents: 47945
diff changeset
675 (not (eq mail-parse-charset 'gnus-decoded)))
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
676 (mm-decode-coding-region b (point-max) mail-parse-charset))))))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
677
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
678 (defun rfc2047-decode-string (string)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
679 "Decode the quoted-printable-encoded STRING and return the results."
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
680 (let ((m (mm-multibyte-p)))
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
681 (if (string-match "=\\?" string)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
682 (with-temp-buffer
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
683 ;; Fixme: This logic is wrong, but seems to be required by
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
684 ;; Gnus summary buffer generation. The value of `m' depends
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
685 ;; on the current buffer, not global multibyteness or that
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
686 ;; of the string. Also the string returned should always be
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
687 ;; multibyte in a multibyte session, i.e. the buffer should
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
688 ;; be multibyte before `buffer-string' is called.
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
689 (when m
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
690 (mm-enable-multibyte))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
691 (insert string)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
692 (inline
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
693 (rfc2047-decode-region (point-min) (point-max)))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
694 (buffer-string))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
695 ;; Fixme: As above, `m' here is inappropriate.
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
696 (if (and m
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
697 mail-parse-charset
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
698 (not (eq mail-parse-charset 'us-ascii))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
699 (not (eq mail-parse-charset 'gnus-decoded)))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
700 (mm-decode-coding-string string mail-parse-charset)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
701 (mm-string-as-multibyte string)))))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
702
47951
9cd6016af581 Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents: 47945
diff changeset
703 (defun rfc2047-parse-and-decode (word)
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
704 "Decode WORD and return it if it is an encoded word.
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
705 Return WORD if it is not not an encoded word or if the charset isn't
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
706 decodable."
47951
9cd6016af581 Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents: 47945
diff changeset
707 (if (not (string-match rfc2047-encoded-word-regexp word))
9cd6016af581 Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents: 47945
diff changeset
708 word
9cd6016af581 Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents: 47945
diff changeset
709 (or
9cd6016af581 Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents: 47945
diff changeset
710 (condition-case nil
9cd6016af581 Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents: 47945
diff changeset
711 (rfc2047-decode
9cd6016af581 Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents: 47945
diff changeset
712 (match-string 1 word)
9cd6016af581 Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents: 47945
diff changeset
713 (upcase (match-string 2 word))
9cd6016af581 Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents: 47945
diff changeset
714 (match-string 3 word))
9cd6016af581 Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents: 47945
diff changeset
715 (error word))
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
716 word))) ; un-decodable
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
717
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
718 (defun rfc2047-pad-base64 (string)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
719 "Pad STRING to quartets."
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
720 ;; Be more liberal to accept buggy base64 strings. If
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
721 ;; base64-decode-string accepts buggy strings, this function could
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
722 ;; be aliased to identity.
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
723 (case (mod (length string) 4)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
724 (0 string)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
725 (1 string) ;; Error, don't pad it.
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
726 (2 (concat string "=="))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
727 (3 (concat string "="))))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
728
47951
9cd6016af581 Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents: 47945
diff changeset
729 (defun rfc2047-decode (charset encoding string)
9cd6016af581 Revert decoding changes temporarily.
Dave Love <fx@gnu.org>
parents: 47945
diff changeset
730 "Decode STRING from the given MIME CHARSET in the given ENCODING.
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
731 Valid ENCODINGs are \"B\" and \"Q\".
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
732 If your Emacs implementation can't decode CHARSET, return nil."
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
733 (if (stringp charset)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
734 (setq charset (intern (downcase charset))))
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
735 (if (or (not charset)
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
736 (eq 'gnus-all mail-parse-ignored-charsets)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
737 (memq 'gnus-all mail-parse-ignored-charsets)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
738 (memq charset mail-parse-ignored-charsets))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
739 (setq charset mail-parse-charset))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
740 (let ((cs (mm-charset-to-coding-system charset)))
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
741 (if (and (not cs) charset
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
742 (listp mail-parse-ignored-charsets)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
743 (memq 'gnus-unknown mail-parse-ignored-charsets))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
744 (setq cs (mm-charset-to-coding-system mail-parse-charset)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
745 (when cs
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
746 (when (and (eq cs 'ascii)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
747 mail-parse-charset)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
748 (setq cs mail-parse-charset))
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
749 (mm-decode-coding-string
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
750 (cond
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
751 ((equal "B" encoding)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
752 (base64-decode-string
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
753 (rfc2047-pad-base64 string)))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
754 ((equal "Q" encoding)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
755 (quoted-printable-decode-string
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
756 (mm-replace-chars-in-string string ?_ ? )))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
757 (t (error "Invalid encoding: %s" encoding)))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents: 55411
diff changeset
758 cs))))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
759
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
760 (provide 'rfc2047)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
761
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 50881
diff changeset
762 ;;; arch-tag: a07fe3d4-22b5-4c4a-bd89-b1f82d5d36f6
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
763 ;;; rfc2047.el ends here