annotate lisp/tm/tm-ew-d.el @ 80:1ce6082ce73f r20-0b90

Import from CVS: tag r20-0b90
author cvs
date Mon, 13 Aug 2007 09:06:37 +0200
parents 54cc21c15cbb
children 364816949b59
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
1 ;;; tm-ew-d.el --- RFC 2047 based encoded-word decoder for GNU Emacs
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
2
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 32
diff changeset
3 ;; Copyright (C) 1995,1996 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)
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 74
diff changeset
12 ;; Version: $Revision: 1.2 $
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
13 ;; Keywords: encoded-word, MIME, multilingual, header, mail, news
4
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)
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 74
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
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 74
diff changeset
45 "$Id: tm-ew-d.el,v 1.2 1997/01/11 20:14:11 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))
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
126 (while (re-search-forward "\\?=\\(\n*\\s +\\)+=\\?" nil t)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 32
diff changeset
127 (replace-match "?==?")
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
128 )
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 32
diff changeset
129 (goto-char (point-min))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
130 (let (charset encoding text)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
131 (while (re-search-forward mime/encoded-word-regexp nil t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
132 (insert (mime/decode-encoded-word
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
133 (prog1
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
134 (buffer-substring (match-beginning 0) (match-end 0))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
135 (delete-region (match-beginning 0) (match-end 0))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
136 ) must-unfold))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
137 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
138 )))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
139
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
140
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
141 ;;; @ for message header
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 (defun mime/decode-message-header ()
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
145 "Decode MIME encoded-words in message header. [tm-ew-d.el]"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
146 (interactive "*")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
147 (save-excursion
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
148 (save-restriction
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
149 (narrow-to-region (goto-char (point-min))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
150 (progn (re-search-forward "^$" nil t) (point)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
151 (mime-eword/decode-region (point-min) (point-max) t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
152 )))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
153
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
154 (defun mime/unfolding ()
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
155 (goto-char (point-min))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
156 (let (field beg end)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
157 (while (re-search-forward std11-field-head-regexp nil t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
158 (setq beg (match-beginning 0)
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
159 end (std11-field-end))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
160 (setq field (buffer-substring beg end))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
161 (if (string-match mime/encoded-word-regexp field)
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
162 (save-restriction
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
163 (narrow-to-region (goto-char beg) end)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
164 (while (re-search-forward "\n\\([ \t]\\)" nil t)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
165 (replace-match
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
166 (match-string 1))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
167 )
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
168 (goto-char (point-max))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
169 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
170 )))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
171
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
172
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
173 ;;; @ encoded-word decoder
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 (defun mime/decode-encoded-word (word &optional must-unfold)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
177 "Decode WORD if it is an encoded-word.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
178
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
179 If your emacs implementation can not decode the charset of WORD, it
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
180 returns WORD. Similarly the encoded-word is broken, it returns 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 MUST-UNFOLD is non-nil, it unfolds and eliminates line-breaks even
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
183 if there are in decoded encoded-word (generated by bad manner MUA such
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
184 as a version of Net$cape). [tm-ew-d.el]"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
185 (or (if (string-match mime/encoded-word-regexp word)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
186 (let ((charset
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
187 (substring word (match-beginning 1) (match-end 1))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
188 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
189 (encoding
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
190 (upcase
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
191 (substring word (match-beginning 2) (match-end 2))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
192 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
193 (text
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
194 (substring word (match-beginning 3) (match-end 3))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
195 ))
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
196 (condition-case err
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
197 (mime/decode-encoded-text charset encoding text must-unfold)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
198 (error nil))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 32
diff changeset
199 ))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
200 word))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
201
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
202
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
203 ;;; @ encoded-text decoder
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
204 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
205
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
206 (defun mime/decode-encoded-text (charset encoding string &optional must-unfold)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
207 "Decode STRING as an encoded-text.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
208
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
209 If your emacs implementation can not decode CHARSET, it returns nil.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
210
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
211 If ENCODING is not \"B\" or \"Q\", it occurs error.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
212 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
213
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
214 If MUST-UNFOLD is non-nil, it unfolds and eliminates line-breaks even
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
215 if there are in decoded encoded-text (generated by bad manner MUA such
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
216 as a version of Net$cape). [tm-ew-d.el]"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
217 (let ((cs (mime-charset-to-coding-system charset)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
218 (if cs
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
219 (let ((dest
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
220 (cond ((and (string-equal "B" encoding)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
221 (string-match mime/B-encoded-text-regexp string))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
222 (base64-decode-string string))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
223 ((and (string-equal "Q" encoding)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
224 (string-match mime/Q-encoded-text-regexp string))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
225 (q-encoding-decode-string string))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
226 (t (message "Invalid encoded-word %s" encoding)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 32
diff changeset
227 nil))))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
228 (if dest
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
229 (progn
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
230 (setq dest (decode-coding-string dest cs))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
231 (if must-unfold
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
232 (mapconcat (function
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
233 (lambda (chr)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 32
diff changeset
234 (if (eq chr ?\n)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 32
diff changeset
235 ""
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 32
diff changeset
236 (char-to-string chr)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 32
diff changeset
237 )
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
238 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
239 (std11-unfold-string dest)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
240 "")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
241 dest)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
242 ))))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
243
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
244
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
245 ;;; @ end
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
246 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
247
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
248 (provide 'tm-ew-d)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
249
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
250 ;;; tm-ew-d.el ends here