2 ;;; tm-ew-d.el --- RFC 1522 based multilingual MIME message header
3 ;;; decoder for GNU Emacs
5 ;;; Copyright (C) 1995 Free Software Foundation, Inc.
6 ;;; Copyright (C) 1992 ENAMI Tsugutomo
7 ;;; Copyright (C) 1993 .. 1996 MORIOKA Tomohiko
9 ;;; Author: ENAMI Tsugutomo <enami@sys.ptg.sony.co.jp>
10 ;;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
11 ;;; Maintainer: MORIOKA Tomohiko <morioka@jaist.ac.jp>
12 ;;; Created: 1993/6/3 (1995/10/3 obsolete tiny-mime.el)
13 ;;; Version: $Revision: 7.12 $
14 ;;; Keywords: mail, news, MIME, RFC 1522, multilingual, encoded-word
16 ;;; This file is part of tm (Tools for MIME).
18 ;;; This program is free software; you can redistribute it and/or
19 ;;; modify it under the terms of the GNU General Public License as
20 ;;; published by the Free Software Foundation; either version 2, or
21 ;;; (at your option) any later version.
23 ;;; This program is distributed in the hope that it will be useful,
24 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
25 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 ;;; General Public License for more details.
28 ;;; You should have received a copy of the GNU General Public License
29 ;;; along with This program. If not, write to the Free Software
30 ;;; Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
43 (defconst tm-ew-d/RCS-ID
44 "$Id: tm-ew-d.el,v 7.12 1996/05/09 18:18:51 morioka Exp $")
45 (defconst mime/eword-decoder-version (get-version-string tm-ew-d/RCS-ID))
48 ;;; @ MIME encoded-word definition
51 (defconst mime/encoded-text-regexp "[!->@-~]+")
52 (defconst mime/encoded-word-regexp (concat (regexp-quote "=?")
60 mime/encoded-text-regexp
68 (defun mime-eword/decode-string (str)
69 (setq str (rfc822/unfolding-string str))
70 (let ((dest "")(ew nil)
72 (while (and (string-match mime/encoded-word-regexp str)
73 (setq beg (match-beginning 0)
79 (string-match "^[ \t]+$" (substring str 0 beg))
81 (setq dest (concat dest (substring str 0 beg)))
84 (setq dest (concat dest
85 (mime/decode-encoded-word (substring str beg end))
87 (setq str (substring str end))
97 (defun mime-eword/decode-region (beg end &optional unfolding)
101 (narrow-to-region beg end)
105 (goto-char (point-min))
106 (while (re-search-forward
107 (concat (regexp-quote "?=") "\\s +" (regexp-quote "=?"))
109 (replace-match "?==?")
111 (goto-char (point-min))
112 (let (charset encoding text)
113 (while (re-search-forward mime/encoded-word-regexp nil t)
114 (insert (mime/decode-encoded-word
116 (buffer-substring (match-beginning 0) (match-end 0))
117 (delete-region (match-beginning 0) (match-end 0))
124 ;;; @ for message header
127 (defun mime/decode-message-header ()
131 (narrow-to-region (goto-char (point-min))
132 (progn (re-search-forward "^$" nil t) (point)))
133 (mime-eword/decode-region (point-min) (point-max) t)
136 (defun mime/unfolding ()
137 (goto-char (point-min))
139 (while (re-search-forward rfc822/field-top-regexp nil t)
140 (setq beg (match-beginning 0))
141 (setq end (rfc822/field-end))
142 (setq field (buffer-substring beg end))
143 (if (string-match mime/encoded-word-regexp field)
145 (narrow-to-region (goto-char beg) end)
146 (while (re-search-forward "\n[ \t]+" nil t)
149 (goto-char (point-max))
154 ;;; @ encoded-word decoder
157 (defun mime/decode-encoded-word (word)
158 (or (if (string-match mime/encoded-word-regexp word)
161 (substring word (match-beginning 1) (match-end 1))
165 (substring word (match-beginning 2) (match-end 2))
168 (substring word (match-beginning 3) (match-end 3))
170 (mime/decode-encoded-text charset encoding text)
175 ;;; @ encoded-text decoder
178 (defun mime/decode-encoded-text (charset encoding str)
180 (cond ((string-equal "B" encoding)
181 (base64-decode-string str))
182 ((string-equal "Q" encoding)
183 (q-encoding-decode-string str))
184 (t (message "unknown encoding %s" encoding)
187 (mime-charset-decode-string dest charset)
196 ;;; tm-ew-d.el ends here