annotate lisp/tm/tm-ew-d.el @ 32:e04119814345 r19-15b99

Import from CVS: tag r19-15b99
author cvs
date Mon, 13 Aug 2007 08:52:56 +0200
parents 0293115a14e9
children 131b0175ea99
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1 ;;; tm-ew-d.el --- RFC 2047 based encoded-word decoder for GNU Emacs
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
2
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
3 ;; Copyright (C) 1995,1996,1997 Free Software Foundation, Inc.
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
5 ;; Author: ENAMI Tsugutomo <enami@sys.ptg.sony.co.jp>
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
6 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
7 ;; Maintainer: MORIOKA Tomohiko <morioka@jaist.ac.jp>
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
8 ;; Created: 1995/10/03
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
9 ;; Original: 1992/07/20 ENAMI Tsugutomo's `mime.el'.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
10 ;; Renamed: 1993/06/03 to tiny-mime.el.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
11 ;; Renamed: 1995/10/03 from tiny-mime.el. (split off encoder)
32
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 16
diff changeset
12 ;; Version: $Revision: 1.5 $
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
13 ;; Keywords: encoded-word, MIME, multilingual, header, mail, news
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
14
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
15 ;; This file is part of tm (Tools for MIME).
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
16
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
17 ;; This program is free software; you can redistribute it and/or
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
18 ;; modify it under the terms of the GNU General Public License as
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
19 ;; published by the Free Software Foundation; either version 2, or (at
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
20 ;; your option) any later version.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
21
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
22 ;; This program is distributed in the hope that it will be useful, but
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
23 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
24 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
25 ;; General Public License for more details.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
26
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
27 ;; You should have received a copy of the GNU General Public License
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
28 ;; along with GNU Emacs; see the file COPYING. If not, write to the
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
29 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
30 ;; Boston, MA 02111-1307, USA.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
31
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
32 ;;; Code:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
33
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
34 (require 'emu)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
35 (require 'std11)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
36 (require 'mel)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
37 (require 'tm-def)
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 8
diff changeset
38 (require 'tl-str)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
39
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
40
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
41 ;;; @ version
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
42 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
43
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
44 (defconst tm-ew-d/RCS-ID
32
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 16
diff changeset
45 "$Id: tm-ew-d.el,v 1.5 1997/03/16 05:55:41 steve Exp $")
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
46 (defconst mime/eword-decoder-version (get-version-string tm-ew-d/RCS-ID))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
47
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
48
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
49 ;;; @ MIME encoded-word definition
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
50 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
51
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
52 (defconst mime/encoded-text-regexp "[!->@-~]+")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
53 (defconst mime/encoded-word-regexp (concat (regexp-quote "=?")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
54 "\\("
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
55 mime/charset-regexp
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
56 "\\)"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
57 (regexp-quote "?")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
58 "\\(B\\|Q\\)"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
59 (regexp-quote "?")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
60 "\\("
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
61 mime/encoded-text-regexp
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
62 "\\)"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
63 (regexp-quote "?=")))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
64
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
65
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
66 ;;; @ for string
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
67 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
68
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
69 (defun mime-eword/decode-string (string &optional must-unfold)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
70 "Decode MIME encoded-words in STRING.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
71
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
72 STRING is unfolded before decoding.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
73
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
74 If an encoded-word is broken or your emacs implementation can not
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
75 decode the charset included in it, it is not decoded.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
76
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
77 If MUST-UNFOLD is non-nil, it unfolds and eliminates line-breaks even
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
78 if there are in decoded encoded-words (generated by bad manner MUA
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
79 such as a version of Net$cape). [tm-ew-d.el]"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
80 (setq string (std11-unfold-string string))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
81 (let ((dest "")(ew nil)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
82 beg end)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
83 (while (and (string-match mime/encoded-word-regexp string)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
84 (setq beg (match-beginning 0)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
85 end (match-end 0))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
86 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
87 (if (> beg 0)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
88 (if (not
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
89 (and (eq ew t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
90 (string-match "^[ \t]+$" (substring string 0 beg))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
91 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
92 (setq dest (concat dest (substring string 0 beg)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
93 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
94 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
95 (setq dest
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
96 (concat dest
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
97 (mime/decode-encoded-word
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
98 (substring string beg end) must-unfold)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
99 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
100 (setq string (substring string end))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
101 (setq ew t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
102 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
103 (concat dest string)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
104 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
105
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
106
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
107 ;;; @ for region
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
108 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
109
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
110 (defun mime-eword/decode-region (start end &optional unfolding must-unfold)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
111 "Decode MIME encoded-words in region between START and END.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
112
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
113 If UNFOLDING is not nil, it unfolds before decoding.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
114
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
115 If MUST-UNFOLD is non-nil, it unfolds and eliminates line-breaks even
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
116 if there are in decoded encoded-words (generated by bad manner MUA
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
117 such as a version of Net$cape). [tm-ew-d.el]"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
118 (interactive "*r")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
119 (save-excursion
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
120 (save-restriction
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
121 (narrow-to-region start end)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
122 (if unfolding
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
123 (mime/unfolding)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
124 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
125 (goto-char (point-min))
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
126 (while (re-search-forward (concat "\\(" mime/encoded-word-regexp "\\)"
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
127 "\\(\n?[ \t]\\)+"
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
128 "\\(" mime/encoded-word-regexp "\\)")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
129 nil t)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
130 (replace-match "\\1\\6")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
131 (goto-char (point-min))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
132 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
133 (let (charset encoding text)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
134 (while (re-search-forward mime/encoded-word-regexp nil t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
135 (insert (mime/decode-encoded-word
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
136 (prog1
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
137 (buffer-substring (match-beginning 0) (match-end 0))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
138 (delete-region (match-beginning 0) (match-end 0))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
139 ) must-unfold))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
140 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
141 )))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
142
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
143
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
144 ;;; @ for message header
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
145 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
146
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
147 (defun mime/decode-message-header ()
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
148 "Decode MIME encoded-words in message header. [tm-ew-d.el]"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
149 (interactive "*")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
150 (save-excursion
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
151 (save-restriction
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
152 (narrow-to-region (goto-char (point-min))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
153 (progn (re-search-forward "^$" nil t) (point)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
154 (mime-eword/decode-region (point-min) (point-max) t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
155 )))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
156
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
157 (defun mime/unfolding ()
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
158 (goto-char (point-min))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
159 (let (field beg end)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
160 (while (re-search-forward std11-field-head-regexp nil t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
161 (setq beg (match-beginning 0)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
162 end (std11-field-end))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
163 (setq field (buffer-substring beg end))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
164 (if (string-match mime/encoded-word-regexp field)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
165 (save-restriction
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
166 (narrow-to-region (goto-char beg) end)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
167 (while (re-search-forward "\n\\([ \t]\\)" nil t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
168 (replace-match
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
169 (match-string 1))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
170 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
171 (goto-char (point-max))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
172 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
173 )))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
174
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
175
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
176 ;;; @ encoded-word decoder
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
177 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
178
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
179 (defun mime/decode-encoded-word (word &optional must-unfold)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
180 "Decode WORD if it is an encoded-word.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
181
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
182 If your emacs implementation can not decode the charset of WORD, it
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
183 returns WORD. Similarly the encoded-word is broken, it returns WORD.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
184
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
185 If MUST-UNFOLD is non-nil, it unfolds and eliminates line-breaks even
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
186 if there are in decoded encoded-word (generated by bad manner MUA such
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
187 as a version of Net$cape). [tm-ew-d.el]"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
188 (or (if (string-match mime/encoded-word-regexp word)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
189 (let ((charset
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
190 (substring word (match-beginning 1) (match-end 1))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
191 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
192 (encoding
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
193 (upcase
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
194 (substring word (match-beginning 2) (match-end 2))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
195 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
196 (text
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
197 (substring word (match-beginning 3) (match-end 3))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
198 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
199 (condition-case err
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
200 (mime/decode-encoded-text charset encoding text must-unfold)
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
201 (error
32
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 16
diff changeset
202 (and (add-text-properties 0 (length word)
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 16
diff changeset
203 (and tm:warning-face
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 16
diff changeset
204 (list 'face tm:warning-face))
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 16
diff changeset
205 word)
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
206 word)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
207 ))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
208 word))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
209
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
210
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
211 ;;; @ encoded-text decoder
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
212 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
213
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
214 (defun mime/decode-encoded-text (charset encoding string &optional must-unfold)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
215 "Decode STRING as an encoded-text.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
216
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
217 If your emacs implementation can not decode CHARSET, it returns nil.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
218
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
219 If ENCODING is not \"B\" or \"Q\", it occurs error.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
220 So you should write error-handling code if you don't want break by errors.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
221
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
222 If MUST-UNFOLD is non-nil, it unfolds and eliminates line-breaks even
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
223 if there are in decoded encoded-text (generated by bad manner MUA such
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
224 as a version of Net$cape). [tm-ew-d.el]"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
225 (let ((cs (mime-charset-to-coding-system charset)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
226 (if cs
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
227 (let ((dest
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
228 (cond
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
229 ((string-equal "B" encoding)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
230 (if (and (string-match mime/B-encoded-text-regexp string)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
231 (string-equal string (match-string 0 string)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
232 (base64-decode-string string)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
233 (error "Invalid encoded-text %s" string)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
234 ((string-equal "Q" encoding)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
235 (if (and (string-match mime/Q-encoded-text-regexp string)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
236 (string-equal string (match-string 0 string)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
237 (q-encoding-decode-string string)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
238 (error "Invalid encoded-text %s" string)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
239 (t
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
240 (error "Invalid encoding %s" encoding)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
241 )))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
242 )
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
243 (if dest
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
244 (progn
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
245 (setq dest (decode-coding-string dest cs))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
246 (if must-unfold
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
247 (mapconcat (function
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
248 (lambda (chr)
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
249 (cond
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
250 ((eq chr ?\n) "")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
251 ((eq chr ?\t) " ")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
252 (t (char-to-string chr)))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
253 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
254 (std11-unfold-string dest)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
255 "")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
256 dest)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
257 ))))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
258
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
259
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
260 ;;; @ end
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
261 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
262
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
263 (provide 'tm-ew-d)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
264
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
265 ;;; tm-ew-d.el ends here