annotate lisp/gnus/rfc2047.el @ 43221:fadb49348c98

Use `sort -k 2', not `sort +1', as POSIX 1003.1-2001 disallows the old syntax.
author Paul Eggert <eggert@twinsun.com>
date Sun, 10 Feb 2002 08:08:59 +0000
parents a26d9b55abb6
children 3915f2c7691e 690e82320649
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
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
2 ;; Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
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
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
30 (eval-when-compile (require 'cl))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
31
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
32 (require 'qp)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
33 (require 'mm-util)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
34 (require 'ietf-drums)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
35 (require 'mail-prsvr)
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
36 (require 'base64)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
37 ;; Fixme: Avoid this (for gnus-point-at-...) mm dependence on gnus.
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
38 (require 'gnus-util)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
39 (autoload 'mm-body-7-or-8 "mm-bodies")
33127
eca95f9d7f05 (base64): Require unconditionally.
Dave Love <fx@gnu.org>
parents: 31764
diff changeset
40
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
41 (defvar rfc2047-header-encoding-alist
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
42 '(("Newsgroups" . nil)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
43 ("Message-ID" . nil)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
44 (t . mime))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
45 "*Header/encoding method alist.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
46 The list is traversed sequentially. The keys can either be
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
47 header regexps or t.
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
48
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
49 The values can be:
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 1) nil, in which case no encoding is done;
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
52 2) `mime', in which case the header will be encoded according to RFC2047;
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
53 3) a charset, in which case it will be encoded as that charset;
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
54 4) `default', in which case the field will be encoded as the rest
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
55 of the article.")
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
56
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
57 (defvar rfc2047-charset-encoding-alist
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
58 '((us-ascii . nil)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
59 (iso-8859-1 . Q)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
60 (iso-8859-2 . Q)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
61 (iso-8859-3 . Q)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
62 (iso-8859-4 . Q)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
63 (iso-8859-5 . B)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
64 (koi8-r . B)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
65 (iso-8859-7 . Q)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
66 (iso-8859-8 . Q)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
67 (iso-8859-9 . Q)
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
68 (iso-8859-14 . Q)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
69 (iso-8859-15 . Q)
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
70 (iso-2022-jp . B)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
71 (iso-2022-kr . B)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
72 (gb2312 . B)
35838
53eebdb81828 2001-02-01 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents: 35453
diff changeset
73 (big5 . B)
53eebdb81828 2001-02-01 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents: 35453
diff changeset
74 (cn-big5 . B)
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
75 (cn-gb . B)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
76 (cn-gb-2312 . B)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
77 (euc-kr . B)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
78 (iso-2022-jp-2 . B)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
79 (iso-2022-int-1 . B))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
80 "Alist of MIME charsets to RFC2047 encodings.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
81 Valid encodings are nil, `Q' and `B'.")
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 (defvar rfc2047-encoding-function-alist
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
84 '((Q . rfc2047-q-encode-region)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
85 (B . rfc2047-b-encode-region)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
86 (nil . ignore))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
87 "Alist of RFC2047 encodings to encoding functions.")
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
88
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
89 (defvar rfc2047-q-encoding-alist
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
90 '(("\\(From\\|Cc\\|To\\|Bcc\||Reply-To\\):" . "-A-Za-z0-9!*+/")
31764
54ae1def18cf Merge from Gnus trunk.
Dave Love <fx@gnu.org>
parents: 31717
diff changeset
91 ;; = (\075), _ (\137), ? (\077) are used in the encoded word.
35985
b9c371244b90 (rfc2047-fold-region): Don't forward-char at EOB.
Dave Love <fx@gnu.org>
parents: 35838
diff changeset
92 ;; Avoid using 8bit characters.
31764
54ae1def18cf Merge from Gnus trunk.
Dave Love <fx@gnu.org>
parents: 31717
diff changeset
93 ;; Equivalent to "^\000-\007\011\013\015-\037\200-\377=_?"
54ae1def18cf Merge from Gnus trunk.
Dave Love <fx@gnu.org>
parents: 31717
diff changeset
94 ("." . "\010\012\014\040-\074\076\100-\136\140-\177"))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
95 "Alist of header regexps and valid Q characters.")
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
96
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
97 ;;;
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
98 ;;; Functions for encoding RFC2047 messages
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
99 ;;;
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
100
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
101 (defun rfc2047-narrow-to-field ()
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
102 "Narrow the buffer to the header on the current line."
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
103 (beginning-of-line)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
104 (narrow-to-region
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
105 (point)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
106 (progn
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
107 (forward-line 1)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
108 (if (re-search-forward "^[^ \n\t]" nil t)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
109 (progn
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
110 (beginning-of-line)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
111 (point))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
112 (point-max))))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
113 (goto-char (point-min)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
114
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
115 (defun rfc2047-encode-message-header ()
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
116 "Encode the message header according to `rfc2047-header-encoding-alist'.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
117 Should be called narrowed to the head of the message."
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
118 (interactive "*")
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
119 (save-excursion
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
120 (goto-char (point-min))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
121 (let (alist elem method)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
122 (while (not (eobp))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
123 (save-restriction
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
124 (rfc2047-narrow-to-field)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
125 (if (not (rfc2047-encodable-p))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
126 (if (and (eq (mm-body-7-or-8) '8bit)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
127 (mm-multibyte-p)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
128 (mm-coding-system-p
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
129 (car message-posting-charset)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
130 ;; 8 bit must be decoded.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
131 ;; Is message-posting-charset a coding system?
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
132 (mm-encode-coding-region
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
133 (point-min) (point-max)
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
134 (car message-posting-charset)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
135 ;; We found something that may perhaps be encoded.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
136 (setq method nil
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
137 alist rfc2047-header-encoding-alist)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
138 (while (setq elem (pop alist))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
139 (when (or (and (stringp (car elem))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
140 (looking-at (car elem)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
141 (eq (car elem) t))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
142 (setq alist nil
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
143 method (cdr elem))))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
144 (cond
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
145 ((eq method 'mime)
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
146 (rfc2047-encode-region (point-min) (point-max)))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
147 ((eq method 'default)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
148 (if (and (featurep 'mule)
33815
61c7f3065929 (rfc2047-encode-message-header): Don't encode if
Dave Love <fx@gnu.org>
parents: 33304
diff changeset
149 (if (boundp 'default-enable-multibyte-characters)
61c7f3065929 (rfc2047-encode-message-header): Don't encode if
Dave Love <fx@gnu.org>
parents: 33304
diff changeset
150 default-enable-multibyte-characters)
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
151 mail-parse-charset)
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
152 (mm-encode-coding-region (point-min) (point-max)
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
153 mail-parse-charset)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
154 ((mm-coding-system-p method)
33815
61c7f3065929 (rfc2047-encode-message-header): Don't encode if
Dave Love <fx@gnu.org>
parents: 33304
diff changeset
155 (if (and (featurep 'mule)
61c7f3065929 (rfc2047-encode-message-header): Don't encode if
Dave Love <fx@gnu.org>
parents: 33304
diff changeset
156 (if (boundp 'default-enable-multibyte-characters)
61c7f3065929 (rfc2047-encode-message-header): Don't encode if
Dave Love <fx@gnu.org>
parents: 33304
diff changeset
157 default-enable-multibyte-characters))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
158 (mm-encode-coding-region (point-min) (point-max) method)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
159 ;; Hm.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
160 (t)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
161 (goto-char (point-max)))))))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
162
35985
b9c371244b90 (rfc2047-fold-region): Don't forward-char at EOB.
Dave Love <fx@gnu.org>
parents: 35838
diff changeset
163 ;; 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
164 ;; 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
165 (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
166
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
167 (defun rfc2047-encodable-p ()
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
168 "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
169 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
170 (require 'message) ; for message-posting-charset
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
171 (let ((charsets
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
172 (mapcar
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
173 'mm-mime-charset
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
174 (mm-find-charset-region (point-min) (point-max))))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
175 (cs (list 'us-ascii (car message-posting-charset)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
176 found)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
177 (while charsets
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
178 (unless (memq (pop charsets) cs)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
179 (setq found t)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
180 found))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
181
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
182 (defun rfc2047-dissect-region (b e)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
183 "Dissect the region between B and E into words."
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
184 (let ((word-chars "-A-Za-z0-9!*+/")
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
185 ;; Not using ietf-drums-specials-token makes life simple.
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
186 mail-parse-mule-charset
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
187 words point current
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
188 result word)
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
189 (save-restriction
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
190 (narrow-to-region b e)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
191 (goto-char (point-min))
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
192 (skip-chars-forward "\000-\177")
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
193 (while (not (eobp))
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
194 (setq point (point))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
195 (skip-chars-backward word-chars b)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
196 (unless (eq b (point))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
197 (push (cons (buffer-substring b (point)) nil) words))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
198 (setq b (point))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
199 (goto-char point)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
200 (setq current (mm-charset-after))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
201 (forward-char 1)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
202 (skip-chars-forward word-chars)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
203 (while (and (not (eobp))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
204 (eq (mm-charset-after) current))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
205 (forward-char 1)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
206 (skip-chars-forward word-chars))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
207 (unless (eq b (point))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
208 (push (cons (buffer-substring b (point)) current) words))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
209 (setq b (point))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
210 (skip-chars-forward "\000-\177"))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
211 (unless (eq b (point))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
212 (push (cons (buffer-substring b (point)) nil) words)))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
213 ;; merge adjacent words
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
214 (setq word (pop words))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
215 (while word
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
216 (if (and (cdr word)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
217 (caar words)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
218 (not (cdar words))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
219 (not (string-match "[^ \t]" (caar words))))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
220 (if (eq (cdr (nth 1 words)) (cdr word))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
221 (progn
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
222 (setq word (cons (concat
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
223 (car (nth 1 words)) (caar words)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
224 (car word))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
225 (cdr word)))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
226 (pop words)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
227 (pop words))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
228 (push (cons (concat (caar words) (car word)) (cdr word))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
229 result)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
230 (pop words)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
231 (setq word (pop words)))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
232 (push word result)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
233 (setq word (pop words))))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
234 result))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
235
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
236 (defun rfc2047-encode-region (b e)
35985
b9c371244b90 (rfc2047-fold-region): Don't forward-char at EOB.
Dave Love <fx@gnu.org>
parents: 35838
diff changeset
237 "Encode all encodable words in region B to E."
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
238 (let ((words (rfc2047-dissect-region b e)) word)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
239 (save-restriction
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
240 (narrow-to-region b e)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
241 (delete-region (point-min) (point-max))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
242 (while (setq word (pop words))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
243 (if (not (cdr word))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
244 (insert (car word))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
245 (rfc2047-fold-region (gnus-point-at-bol) (point))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
246 (goto-char (point-max))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
247 (if (> (- (point) (save-restriction
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
248 (widen)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
249 (gnus-point-at-bol))) 76)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
250 (insert "\n "))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
251 ;; Insert blank between encoded words
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
252 (if (eq (char-before) ?=) (insert " "))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
253 (rfc2047-encode (point)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
254 (progn (insert (car word)) (point))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
255 (cdr word))))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
256 (rfc2047-fold-region (point-min) (point-max)))))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
257
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
258 (defun rfc2047-encode-string (string)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
259 "Encode words in STRING."
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
260 (with-temp-buffer
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
261 (insert string)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
262 (rfc2047-encode-region (point-min) (point-max))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
263 (buffer-string)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
264
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
265 (defun rfc2047-encode (b e charset)
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
266 "Encode the word in the region B to E with CHARSET."
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
267 (let* ((mime-charset (mm-mime-charset charset))
35838
53eebdb81828 2001-02-01 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents: 35453
diff changeset
268 (cs (mm-charset-to-coding-system mime-charset))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
269 (encoding (or (cdr (assq mime-charset
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
270 rfc2047-charset-encoding-alist))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
271 'B))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
272 (start (concat
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
273 "=?" (downcase (symbol-name mime-charset)) "?"
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
274 (downcase (symbol-name encoding)) "?"))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
275 (first t))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
276 (save-restriction
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
277 (narrow-to-region b e)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
278 (when (eq encoding 'B)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
279 ;; break into lines before encoding
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
280 (goto-char (point-min))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
281 (while (not (eobp))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
282 (goto-char (min (point-max) (+ 15 (point))))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
283 (unless (eobp)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
284 (insert "\n"))))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
285 (if (and (mm-multibyte-p)
35838
53eebdb81828 2001-02-01 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents: 35453
diff changeset
286 (mm-coding-system-p cs))
53eebdb81828 2001-02-01 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents: 35453
diff changeset
287 (mm-encode-coding-region (point-min) (point-max) cs))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
288 (funcall (cdr (assq encoding rfc2047-encoding-function-alist))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
289 (point-min) (point-max))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
290 (goto-char (point-min))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
291 (while (not (eobp))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
292 (unless first
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
293 (insert " "))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
294 (setq first nil)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
295 (insert start)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
296 (end-of-line)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
297 (insert "?=")
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
298 (forward-line 1)))))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
299
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
300 (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
301 "Fold long lines in region B to E."
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
302 (save-restriction
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
303 (narrow-to-region b e)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
304 (goto-char (point-min))
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
305 (let ((break nil)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
306 (qword-break nil)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
307 (bol (save-restriction
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
308 (widen)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
309 (gnus-point-at-bol))))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
310 (while (not (eobp))
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
311 (when (and (or break qword-break) (> (- (point) bol) 76))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
312 (goto-char (or break qword-break))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
313 (setq break nil
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
314 qword-break nil)
35453
26726eff41ca 2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents: 34674
diff changeset
315 (if (looking-at " \t")
26726eff41ca 2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents: 34674
diff changeset
316 (insert "\n")
26726eff41ca 2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents: 34674
diff changeset
317 (insert "\n "))
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
318 (setq bol (1- (point)))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
319 ;; Don't break before the first non-LWSP characters.
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
320 (skip-chars-forward " \t")
35985
b9c371244b90 (rfc2047-fold-region): Don't forward-char at EOB.
Dave Love <fx@gnu.org>
parents: 35838
diff changeset
321 (unless (eobp) (forward-char 1)))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
322 (cond
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
323 ((eq (char-after) ?\n)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
324 (forward-char 1)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
325 (setq bol (point)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
326 break nil
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
327 qword-break nil)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
328 (skip-chars-forward " \t")
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
329 (unless (or (eobp) (eq (char-after) ?\n))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
330 (forward-char 1)))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
331 ((eq (char-after) ?\r)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
332 (forward-char 1))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
333 ((memq (char-after) '(? ?\t))
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
334 (skip-chars-forward " \t")
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
335 (setq break (1- (point))))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
336 ((not break)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
337 (if (not (looking-at "=\\?[^=]"))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
338 (if (eq (char-after) ?=)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
339 (forward-char 1)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
340 (skip-chars-forward "^ \t\n\r="))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
341 (setq qword-break (point))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
342 (skip-chars-forward "^ \t\n\r")))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
343 (t
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
344 (skip-chars-forward "^ \t\n\r"))))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
345 (when (and (or break qword-break) (> (- (point) bol) 76))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
346 (goto-char (or break qword-break))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
347 (setq break nil
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
348 qword-break nil)
35453
26726eff41ca 2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents: 34674
diff changeset
349 (if (looking-at " \t")
26726eff41ca 2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents: 34674
diff changeset
350 (insert "\n")
26726eff41ca 2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents: 34674
diff changeset
351 (insert "\n "))
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
352 (setq bol (1- (point)))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
353 ;; Don't break before the first non-LWSP characters.
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
354 (skip-chars-forward " \t")
35985
b9c371244b90 (rfc2047-fold-region): Don't forward-char at EOB.
Dave Love <fx@gnu.org>
parents: 35838
diff changeset
355 (unless (eobp) (forward-char 1))))))
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
356
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
357 (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
358 "Unfold lines in region B to E."
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
359 (save-restriction
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
360 (narrow-to-region b e)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
361 (goto-char (point-min))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
362 (let ((bol (save-restriction
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
363 (widen)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
364 (gnus-point-at-bol)))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
365 (eol (gnus-point-at-eol))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
366 leading)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
367 (forward-line 1)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
368 (while (not (eobp))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
369 (looking-at "[ \t]*")
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
370 (setq leading (- (match-end 0) (match-beginning 0)))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
371 (if (< (- (gnus-point-at-eol) bol leading) 76)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
372 (progn
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
373 (goto-char eol)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
374 (delete-region eol (progn
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
375 (skip-chars-forward "[ \t\n\r]+")
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
376 (1- (point)))))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
377 (setq bol (gnus-point-at-bol)))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
378 (setq eol (gnus-point-at-eol))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
379 (forward-line 1)))))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
380
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
381 (defun rfc2047-b-encode-region (b e)
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
382 "Base64-encode the header contained in region B to E."
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
383 (save-restriction
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
384 (narrow-to-region (goto-char b) e)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
385 (while (not (eobp))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
386 (base64-encode-region (point) (progn (end-of-line) (point)) t)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
387 (if (and (bolp) (eolp))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
388 (delete-backward-char 1))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
389 (forward-line))))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
390
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
391 (defun rfc2047-q-encode-region (b e)
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
392 "Quoted-printable-encode the header in region B to E."
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
393 (save-excursion
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
394 (save-restriction
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
395 (narrow-to-region (goto-char b) e)
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
396 (let ((alist rfc2047-q-encoding-alist)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
397 (bol (save-restriction
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
398 (widen)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
399 (gnus-point-at-bol))))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
400 (while alist
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
401 (when (looking-at (caar alist))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
402 (quoted-printable-encode-region b e nil (cdar alist))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
403 (subst-char-in-region (point-min) (point-max) ? ?_)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
404 (setq alist nil))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
405 (pop alist))
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
406 ;; 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
407 ;; 56=76-20.
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
408 (unless (< (- (point-max) (point-min)) 56)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
409 ;; Don't break if it could fit in one line.
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
410 ;; Let rfc2047-encode-region break it later.
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
411 (goto-char (1+ (point-min)))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
412 (while (and (not (bobp)) (not (eobp)))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
413 (goto-char (min (point-max) (+ 56 bol)))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
414 (search-backward "=" (- (point) 2) t)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
415 (unless (or (bobp) (eobp))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
416 (insert "\n")
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
417 (setq bol (point)))))))))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
418
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
419 ;;;
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
420 ;;; Functions for decoding RFC2047 messages
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
421 ;;;
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
422
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
423 (defvar rfc2047-encoded-word-regexp
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
424 "=\\?\\([^][\000-\040()<>@,\;:\\\"/?.=]+\\)\\?\\(B\\|Q\\)\\?\\([!->@-~ +]+\\)\\?=")
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
425
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
426 (defun rfc2047-decode-region (start end)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
427 "Decode MIME-encoded words in region between START and END."
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
428 (interactive "r")
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
429 (let ((case-fold-search t)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
430 b e)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
431 (save-excursion
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
432 (save-restriction
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
433 (narrow-to-region start end)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
434 (goto-char (point-min))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
435 ;; Remove whitespace between encoded words.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
436 (while (re-search-forward
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
437 (concat "\\(" rfc2047-encoded-word-regexp "\\)"
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
438 "\\(\n?[ \t]\\)+"
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
439 "\\(" rfc2047-encoded-word-regexp "\\)")
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
440 nil t)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
441 (delete-region (goto-char (match-end 1)) (match-beginning 6)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
442 ;; Decode the encoded words.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
443 (setq b (goto-char (point-min)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
444 (while (re-search-forward rfc2047-encoded-word-regexp nil t)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
445 (setq e (match-beginning 0))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
446 (insert (rfc2047-parse-and-decode
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
447 (prog1
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
448 (match-string 0)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
449 (delete-region (match-beginning 0) (match-end 0)))))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
450 (when (and (mm-multibyte-p)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
451 mail-parse-charset
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
452 (not (eq mail-parse-charset 'gnus-decoded)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
453 (mm-decode-coding-region b e mail-parse-charset))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
454 (setq b (point)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
455 (when (and (mm-multibyte-p)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
456 mail-parse-charset
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
457 (not (eq mail-parse-charset 'us-ascii))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
458 (not (eq mail-parse-charset 'gnus-decoded)))
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
459 (mm-decode-coding-region b (point-max) mail-parse-charset))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
460 (rfc2047-unfold-region (point-min) (point-max))))))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
461
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
462 (defun rfc2047-decode-string (string)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
463 "Decode the quoted-printable-encoded STRING and return the results."
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
464 (let ((m (mm-multibyte-p)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
465 (with-temp-buffer
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
466 (when m
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
467 (mm-enable-multibyte))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
468 (insert string)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
469 (inline
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
470 (rfc2047-decode-region (point-min) (point-max)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
471 (buffer-string))))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
472
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
473 (defun rfc2047-parse-and-decode (word)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
474 "Decode WORD and return it if it is an encoded word.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
475 Return WORD if not."
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
476 (if (not (string-match rfc2047-encoded-word-regexp word))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
477 word
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
478 (or
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
479 (condition-case nil
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
480 (rfc2047-decode
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
481 (match-string 1 word)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
482 (upcase (match-string 2 word))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
483 (match-string 3 word))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
484 (error word))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
485 word)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
486
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
487 (defun rfc2047-decode (charset encoding string)
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
488 "Decode STRING from the given MIME CHARSET in the given ENCODING.
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
489 Valid ENCODINGs are \"B\" and \"Q\".
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
490 If your Emacs implementation can't decode CHARSET, return nil."
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
491 (if (stringp charset)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
492 (setq charset (intern (downcase charset))))
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
493 (if (or (not charset)
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
494 (eq 'gnus-all mail-parse-ignored-charsets)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
495 (memq 'gnus-all mail-parse-ignored-charsets)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
496 (memq charset mail-parse-ignored-charsets))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
497 (setq charset mail-parse-charset))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
498 (let ((cs (mm-charset-to-coding-system charset)))
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
499 (if (and (not cs) charset
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
500 (listp mail-parse-ignored-charsets)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
501 (memq 'gnus-unknown mail-parse-ignored-charsets))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
502 (setq cs (mm-charset-to-coding-system mail-parse-charset)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
503 (when cs
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
504 (when (and (eq cs 'ascii)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
505 mail-parse-charset)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
506 (setq cs mail-parse-charset))
33304
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
507 ;; Ensure unibyte result in Emacs 20.
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
508 (let (default-enable-multibyte-characters)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
509 (with-temp-buffer
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
510 (mm-decode-coding-string
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
511 (cond
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
512 ((equal "B" encoding)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
513 (base64-decode-string string))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
514 ((equal "Q" encoding)
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
515 (quoted-printable-decode-string
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
516 (mm-replace-chars-in-string string ?_ ? )))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
517 (t (error "Invalid encoding: %s" encoding)))
d401dfab680a Require gnus-util.
Dave Love <fx@gnu.org>
parents: 33127
diff changeset
518 cs))))))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
519
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
520 (provide 'rfc2047)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
521
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
522 ;;; rfc2047.el ends here