1 ;;; emh.el --- MIME extender for mh-e
3 ;; Copyright (C) 1995,1996 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
7 ;; Maintainer: MORIOKA Tomohiko <morioka@jaist.ac.jp>
9 ;; Renamed: 1993/11/27 from mh-e-mime.el
10 ;; Renamed: 1997/02/21 from tm-mh-e.el
11 ;; Version: $Revision: 0.3 $
12 ;; Keywords: MH, MIME, multimedia, encoded-word, multilingual, mail
14 ;; This file is part of emh.
16 ;; This program is free software; you can redistribute it and/or
17 ;; modify it under the terms of the GNU General Public License as
18 ;; published by the Free Software Foundation; either version 2, or (at
19 ;; your option) any later version.
21 ;; This program is distributed in the hope that it will be useful, but
22 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 ;; General Public License for more details.
26 ;; You should have received a copy of the GNU General Public License
27 ;; along with GNU Emacs; see the file COPYING. If not, write to the
28 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
29 ;; Boston, MA 02111-1307, USA.
46 "$Id: emh.el,v 0.3 1997-02-28 02:39:57 tmorioka Exp $")
48 (defconst emh-version (get-version-string emh-RCS-ID))
54 (defvar emh-automatic-mime-preview t
55 "*If non-nil, show MIME processed message.")
57 (defvar emh-decode-encoded-word t
58 "*If non-nil, decode encoded-word when it is not MIME preview mode.")
64 (defun mh-display-msg (msg-num folder &optional show-buffer mode)
66 (setq mode emh-automatic-mime-preview)
68 ;; Display message NUMBER of FOLDER.
69 ;; Sets the current buffer to the show buffer.
72 (setq show-buffer mh-show-buffer))
73 ;; Bind variables in folder buffer in case they are local
74 (let ((msg-filename (mh-msg-filename msg-num)))
75 (if (not (file-exists-p msg-filename))
76 (error "Message %d does not exist" msg-num))
77 (set-buffer show-buffer)
78 (cond ((not (equal msg-filename buffer-file-name))
79 ;; Buffer does not yet contain message.
80 (clear-visited-file-modtime)
82 (setq buffer-file-name nil) ; no locking during setup
83 (setq buffer-read-only nil)
86 (let* ((aname (concat "article-" folder))
87 (abuf (get-buffer aname))
92 (setq buffer-read-only nil)
95 (setq abuf (get-buffer-create aname))
99 (insert-file-contents msg-filename)
100 ;; (goto-char (point-min))
101 (while (re-search-forward "\r$" nil t)
105 (set-buffer-modified-p nil)
106 (setq buffer-read-only t)
107 (setq buffer-file-name msg-filename)
109 (mime-view-mode nil nil nil
110 aname (concat "show-" folder))
111 (goto-char (point-min))
113 (let ((clean-message-header mh-clean-message-header)
114 (invisible-headers mh-invisible-headers)
115 (visible-headers mh-visible-headers)
118 ;; modified by ARIURA <ariura@cc.tuat.ac.jp>
121 (mh-exec-lib-cmd-output "mhl" "-nobell" "-noclear"
122 (if (stringp mhl-formfile)
123 (list "-form" mhl-formfile))
125 (insert-file-contents msg-filename))
127 (goto-char (point-min))
128 (cond (clean-message-header
129 (mh-clean-msg-header (point-min)
132 (goto-char (point-min)))
134 (mh-start-of-uncleaned-message)))
135 (if emh-decode-encoded-word
136 (eword-decode-header)
138 (set-buffer-modified-p nil)
139 (setq buffer-read-only t)
140 (setq buffer-file-name msg-filename)
143 (or (eq buffer-undo-list t) ;don't save undo info for prev msgs
144 (setq buffer-undo-list nil))
145 ;;; Added by itokon (02/19/96)
146 (setq buffer-file-name msg-filename)
149 (setq mode-line-buffer-identification
150 (list (format mh-show-buffer-mode-line-buffer-id
153 (setq mh-showing-with-headers nil)))))
155 (defun emh-view-message (&optional msg)
156 "MIME decode and play this message."
158 (if (or (null emh-automatic-mime-preview)
159 (null (get-buffer mh-show-buffer))
161 (set-buffer mh-show-buffer)
162 (not (eq major-mode 'mime-view-mode))
164 (let ((emh-automatic-mime-preview t))
165 (mh-invalidate-show-buffer)
168 (pop-to-buffer mh-show-buffer)
171 (defun emh-toggle-decoding-mode (arg)
172 "Toggle MIME processing mode.
173 With arg, turn MIME processing on if arg is positive."
175 (setq emh-automatic-mime-preview
177 (not emh-automatic-mime-preview)
180 (set-buffer mh-show-buffer)
181 (if (null emh-automatic-mime-preview)
182 (if (and mime::preview/article-buffer
183 (get-buffer mime::preview/article-buffer))
184 (kill-buffer mime::preview/article-buffer)
186 (mh-invalidate-show-buffer)
187 (mh-show (mh-get-msg-num t))
190 (defun emh-show (&optional message)
192 (mh-invalidate-show-buffer)
196 (defun emh-header-display ()
198 (mh-invalidate-show-buffer)
199 (let ((mime-view-ignored-field-regexp "^:$")
200 emh-decode-encoded-word)
204 (defun emh-raw-display ()
206 (mh-invalidate-show-buffer)
207 (let (emh-automatic-mime-preview
208 emh-decode-encoded-word)
212 (defun emh-burst-multipart/digest ()
213 "Burst apart the current message, which should be a multipart/digest.
214 The message is replaced by its table of contents and the letters from the
215 digest are inserted into the folder after that message."
217 (let ((digest (mh-get-msg-num t)))
218 (mh-process-or-undo-commands mh-current-folder)
219 (mh-set-folder-modified-p t) ; lock folder while bursting
220 (message "Bursting digest...")
221 (mh-exec-cmd "mhn" "-store" mh-current-folder digest)
222 (mh-scan-folder mh-current-folder (format "%d-last" mh-first-msg-num))
223 (message "Bursting digest...done")
230 (fset 'emh-decode-charset-buffer
231 (symbol-function 'mime-charset/decode-buffer))
233 (set-alist 'mime-text-decoder-alist
235 (function emh-decode-charset-buffer))
237 (defun emh-content-header-filter ()
238 (goto-char (point-min))
239 (mime-preview/cut-header)
240 (emh-decode-charset-buffer default-mime-charset)
241 (eword-decode-header)
244 (set-alist 'mime-view-content-header-filter-alist
246 (function emh-content-header-filter))
248 (defun emh-quitting-method ()
249 (let ((win (get-buffer-window
250 mime/output-buffer-name))
251 (buf (current-buffer))
257 (let ((name (buffer-name buf)))
260 (if (not emh-automatic-mime-preview)
261 (mh-invalidate-show-buffer)
263 (mh-show (mh-get-msg-num t))
266 (set-alist 'mime-view-quitting-method-alist
268 (function emh-quitting-method))
269 (set-alist 'mime-view-show-summary-method
271 (function emh-quitting-method))
273 (defun emh-following-method (buf)
276 (goto-char (point-max))
277 (setq mh-show-buffer buf)
278 (apply (function mh-send)
279 (std11-field-bodies '("From" "cc" "Subject") ""))
280 (setq mh-sent-from-folder buf)
281 (setq mh-sent-from-msg 1)
282 (let ((last (point)))
287 (set-alist 'mime-view-following-method-alist
289 (function emh-following-method))
292 ;;; @@ for mime-partial
299 (set-atype 'mime/content-decoding-condition
300 '((type . "message/partial")
301 (method . mime-article/grab-message/partials)
302 (major-mode . mh-show-mode)
304 . (and (or (string-match "^article-\\(.+\\)$" article-buffer)
305 (string-match "^show-\\(.+\\)$" article-buffer))
306 (substring article-buffer
307 (match-beginning 1) (match-end 1))
310 (set-alist 'mime-partial/preview-article-method-alist
314 (let ((emh-automatic-mime-preview t))
323 (define-key mh-folder-mode-map "v" (function emh-view-message))
324 (define-key mh-folder-mode-map "\et" (function emh-toggle-decoding-mode))
325 (define-key mh-folder-mode-map "." (function emh-show))
326 (define-key mh-folder-mode-map "," (function emh-header-display))
327 (define-key mh-folder-mode-map "\e," (function emh-raw-display))
328 (define-key mh-folder-mode-map "\C-c\C-b"
329 (function emh-burst-multipart/digest))
331 (defun emh-summary-before-quit ()
332 (let ((buf (get-buffer mh-show-buffer)))
334 (let ((the-buf (current-buffer)))
335 (switch-to-buffer buf)
336 (if (and mime::article/preview-buffer
337 (setq buf (get-buffer mime::article/preview-buffer))
340 (switch-to-buffer the-buf)
343 (switch-to-buffer the-buf)
347 (add-hook 'mh-before-quit-hook (function emh-summary-before-quit))
350 ;;; @@ for emh-comp.el
353 (autoload 'emh-edit-again "emh-comp"
354 "Clean-up a draft or a message previously sent and make it resendable." t)
355 (autoload 'emh-extract-rejected-mail "emh-comp"
356 "Extract a letter returned by the mail system and make it re-editable." t)
357 (autoload 'emh-forward "emh-comp"
358 "Forward a message or message sequence by MIME style." t)
364 (substitute-key-definition
365 'mh-edit-again 'emh-edit-again mh-folder-mode-map)
366 (substitute-key-definition
367 'mh-extract-rejected-mail 'emh-extract-rejected-mail
369 (substitute-key-definition
370 'mh-forward 'emh-forward mh-folder-mode-map)
378 'mh-letter-mode-hook)
398 (run-hooks 'emh-load-hook)