1 ;;; tm-mh-e.el --- MIME extension 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>
8 ;; Created: 1993/11/21 (obsolete mh-e-mime.el)
9 ;; Version: $Revision: 7.68 $
10 ;; Keywords: mail, MH, MIME, multimedia, encoded-word, multilingual
12 ;; This file is part of tm (Tools for MIME).
14 ;; This program is free software; you can redistribute it and/or
15 ;; modify it under the terms of the GNU General Public License as
16 ;; published by the Free Software Foundation; either version 2, or (at
17 ;; your option) any later version.
19 ;; This program is distributed in the hope that it will be useful, but
20 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 ;; General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with This program; see the file COPYING. If not, write to
26 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27 ;; Boston, MA 02111-1307, USA.
34 (or (featurep 'mh-utils)
39 (or (fboundp 'mh-get-header-field)
40 (defalias 'mh-get-header-field 'mh-get-field)
42 (or (boundp 'mh-temp-buffer)
43 (defconst mh-temp-buffer " *mh-temp*")
50 (defconst tm-mh-e/RCS-ID
51 "$Id: tm-mh-e.el,v 7.68 1996/08/31 15:15:12 morioka Exp $")
53 (defconst tm-mh-e/version (get-version-string tm-mh-e/RCS-ID))
59 (defvar tm-mh-e/automatic-mime-preview t
60 "*If non-nil, show MIME processed message.")
62 (defvar tm-mh-e/decode-encoded-word t
63 "*If non-nil, decode encoded-word when it is not MIME preview mode.")
69 ;; (if (not (fboundp 'tm-mh-e/original-mh-display-msg))
70 ;; (fset 'tm-mh-e/original-mh-display-msg
71 ;; (symbol-function 'mh-display-msg))
74 (defun mh-display-msg (msg-num folder &optional show-buffer mode)
76 (setq mode tm-mh-e/automatic-mime-preview)
78 ;; Display message NUMBER of FOLDER.
79 ;; Sets the current buffer to the show buffer.
82 (setq show-buffer mh-show-buffer))
83 ;; Bind variables in folder buffer in case they are local
84 (let ((msg-filename (mh-msg-filename msg-num)))
85 (if (not (file-exists-p msg-filename))
86 (error "Message %d does not exist" msg-num))
87 (set-buffer show-buffer)
88 (cond ((not (equal msg-filename buffer-file-name))
89 ;; Buffer does not yet contain message.
90 (clear-visited-file-modtime)
92 (setq buffer-file-name nil) ; no locking during setup
93 (setq buffer-read-only nil)
96 (let* ((aname (concat "article-" folder))
97 (abuf (get-buffer aname))
102 (setq buffer-read-only nil)
105 (setq abuf (get-buffer-create aname))
108 (let ((file-coding-system-for-read
109 (if (boundp 'MULE) *noconv*))
111 (insert-file-contents msg-filename)
112 ;; (goto-char (point-min))
113 (while (re-search-forward "\r$" nil t)
117 (set-buffer-modified-p nil)
118 (setq buffer-read-only t)
119 (setq buffer-file-name msg-filename)
121 (mime/viewer-mode nil nil nil
122 aname (concat "show-" folder))
123 (goto-char (point-min))
125 (let ((clean-message-header mh-clean-message-header)
126 (invisible-headers mh-invisible-headers)
127 (visible-headers mh-visible-headers)
130 ;; modified by ARIURA <ariura@cc.tuat.ac.jp>
133 (mh-exec-lib-cmd-output "mhl" "-nobell" "-noclear"
134 (if (stringp mhl-formfile)
135 (list "-form" mhl-formfile))
137 (insert-file-contents msg-filename))
139 (goto-char (point-min))
140 (cond (clean-message-header
141 (mh-clean-msg-header (point-min)
144 (goto-char (point-min)))
146 (mh-start-of-uncleaned-message)))
147 (if tm-mh-e/decode-encoded-word
148 (mime/decode-message-header)
150 (set-buffer-modified-p nil)
151 (setq buffer-read-only t)
152 (setq buffer-file-name msg-filename)
155 (or (eq buffer-undo-list t) ;don't save undo info for prev msgs
156 (setq buffer-undo-list nil))
157 ;;; Added by itokon (02/19/96)
158 (setq buffer-file-name msg-filename)
161 (setq mode-line-buffer-identification
162 (list (format mh-show-buffer-mode-line-buffer-id
165 (setq mh-showing-with-headers nil)))))
167 (defun tm-mh-e/view-message (&optional msg)
168 "MIME decode and play this message."
170 (if (or (null tm-mh-e/automatic-mime-preview)
171 (null (get-buffer mh-show-buffer))
173 (set-buffer mh-show-buffer)
174 (not (eq major-mode 'mime/viewer-mode))
176 (let ((tm-mh-e/automatic-mime-preview t))
177 (mh-invalidate-show-buffer)
180 (pop-to-buffer mh-show-buffer)
183 (defun tm-mh-e/toggle-decoding-mode (arg)
184 "Toggle MIME processing mode.
185 With arg, turn MIME processing on if arg is positive."
187 (setq tm-mh-e/automatic-mime-preview
189 (not tm-mh-e/automatic-mime-preview)
192 (set-buffer mh-show-buffer)
193 (if (null tm-mh-e/automatic-mime-preview)
194 (if (and mime::preview/article-buffer
195 (get-buffer mime::preview/article-buffer))
196 (kill-buffer mime::preview/article-buffer)
198 (mh-invalidate-show-buffer)
199 (mh-show (mh-get-msg-num t))
202 (defun tm-mh-e/show (&optional message)
204 (mh-invalidate-show-buffer)
208 (defun tm-mh-e/header-display ()
210 (mh-invalidate-show-buffer)
211 (let ((mime-viewer/ignored-field-regexp "^:$")
212 tm-mh-e/decode-encoded-word)
216 (defun tm-mh-e/raw-display ()
218 (mh-invalidate-show-buffer)
219 (let (tm-mh-e/automatic-mime-preview
220 tm-mh-e/decode-encoded-word)
224 (defun tm-mh-e/scroll-up-msg (&optional arg)
226 (mh-page-msg (or arg 1))
229 (defun tm-mh-e/scroll-down-msg (&optional arg)
231 (mh-page-msg (- (or arg 1)))
234 (defun tm-mh-e/burst-multipart/digest ()
235 "Burst apart the current message, which should be a multipart/digest.
236 The message is replaced by its table of contents and the letters from the
237 digest are inserted into the folder after that message."
239 (let ((digest (mh-get-msg-num t)))
240 (mh-process-or-undo-commands mh-current-folder)
241 (mh-set-folder-modified-p t) ; lock folder while bursting
242 (message "Bursting digest...")
243 (mh-exec-cmd "mhn" "-store" mh-current-folder digest)
244 (mh-scan-folder mh-current-folder (format "%d-last" mh-first-msg-num))
245 (message "Bursting digest...done")
252 (fset 'tm-mh-e/decode-charset-buffer
253 (symbol-function 'mime-charset/decode-buffer))
255 (set-alist 'mime-viewer/code-converter-alist
257 (function tm-mh-e/decode-charset-buffer))
259 (defun tm-mh-e/content-header-filter ()
260 (goto-char (point-min))
261 (mime-preview/cut-header)
262 (tm-mh-e/decode-charset-buffer default-mime-charset)
263 (mime/decode-message-header)
266 (set-alist 'mime-viewer/content-header-filter-alist
268 (function tm-mh-e/content-header-filter))
270 (defun tm-mh-e/quitting-method ()
271 (let ((win (get-buffer-window
272 mime/output-buffer-name))
273 (buf (current-buffer))
279 (let ((name (buffer-name buf)))
282 (if (not tm-mh-e/automatic-mime-preview)
283 (mh-invalidate-show-buffer)
285 (mh-show (mh-get-msg-num t))
288 (set-alist 'mime-viewer/quitting-method-alist
290 (function tm-mh-e/quitting-method))
291 (set-alist 'mime-viewer/show-summary-method
293 (function tm-mh-e/quitting-method))
295 (defun tm-mh-e/following-method (buf)
298 (goto-char (point-max))
299 (setq mh-show-buffer buf)
300 (apply (function mh-send)
301 (std11-field-bodies '("To" "cc" "Subject") ""))
302 (setq mh-sent-from-folder buf)
303 (setq mh-sent-from-msg 1)
304 (let ((last (point)))
309 (set-alist 'mime-viewer/following-method-alist
311 (function tm-mh-e/following-method))
314 ;;; @@ for tm-partial
321 (set-atype 'mime/content-decoding-condition
322 '((type . "message/partial")
323 (method . mime-article/grab-message/partials)
324 (major-mode . mh-show-mode)
326 . (and (or (string-match "^article-\\(.+\\)$" article-buffer)
327 (string-match "^show-\\(.+\\)$" article-buffer))
328 (substring article-buffer
329 (match-beginning 1) (match-end 1))
332 (set-alist 'tm-partial/preview-article-method-alist
336 (let ((tm-mh-e/automatic-mime-preview t))
345 (define-key mh-folder-mode-map "v" (function tm-mh-e/view-message))
346 (define-key mh-folder-mode-map "\et" (function tm-mh-e/toggle-decoding-mode))
347 (define-key mh-folder-mode-map "." (function tm-mh-e/show))
348 (define-key mh-folder-mode-map "," (function tm-mh-e/header-display))
349 (define-key mh-folder-mode-map "\e," (function tm-mh-e/raw-display))
350 (define-key mh-folder-mode-map "\r" (function tm-mh-e/scroll-up-msg))
351 (define-key mh-folder-mode-map "\e\r" (function tm-mh-e/scroll-down-msg))
352 (define-key mh-folder-mode-map "\C-c\C-b"
353 (function tm-mh-e/burst-multipart/digest))
355 (defun tm-mh-e/summary-before-quit ()
356 (let ((buf (get-buffer mh-show-buffer)))
358 (let ((the-buf (current-buffer)))
359 (switch-to-buffer buf)
360 (if (and mime::article/preview-buffer
361 (setq buf (get-buffer mime::article/preview-buffer))
364 (switch-to-buffer the-buf)
367 (switch-to-buffer the-buf)
371 (add-hook 'mh-before-quit-hook (function tm-mh-e/summary-before-quit))
374 ;;; @@ for tmh-comp.el
377 (autoload 'tm-mh-e/edit-again "tmh-comp"
378 "Clean-up a draft or a message previously sent and make it resendable." t)
379 (autoload 'tm-mh-e/extract-rejected-mail "tmh-comp"
380 "Extract a letter returned by the mail system and make it re-editable." t)
381 (autoload 'tm-mh-e/forward "tmh-comp"
382 "Forward a message or message sequence by MIME style." t)
388 (substitute-key-definition
389 'mh-edit-again 'tm-mh-e/edit-again mh-folder-mode-map)
390 (substitute-key-definition
391 'mh-extract-rejected-mail 'tm-mh-e/extract-rejected-mail
393 (substitute-key-definition
394 'mh-forward 'tm-mh-e/forward mh-folder-mode-map)
402 'mh-letter-mode-hook)
422 (run-hooks 'tm-mh-e-load-hook)
424 ;;; tm-mh-e.el ends here