1 ;;; emh.el --- MIME extender for mh-e
3 ;; Copyright (C) 1995,1996,1997 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.10 $
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.
42 "$Id: emh.el,v 0.10 1997-03-17 14:30:46 morioka Exp $")
44 (defconst emh-version (get-version-string emh-RCS-ID))
50 (defvar emh-automatic-mime-preview t
51 "*If non-nil, show MIME processed message.")
53 (defvar emh-decode-encoded-word t
54 "*If non-nil, decode encoded-word when it is not MIME preview mode.")
60 (defun mh-display-msg (msg-num folder &optional show-buffer mode)
62 (setq mode emh-automatic-mime-preview)
64 ;; Display message NUMBER of FOLDER.
65 ;; Sets the current buffer to the show buffer.
68 (setq show-buffer mh-show-buffer))
69 ;; Bind variables in folder buffer in case they are local
70 (let ((msg-filename (mh-msg-filename msg-num)))
71 (if (not (file-exists-p msg-filename))
72 (error "Message %d does not exist" msg-num))
73 (set-buffer show-buffer)
74 (cond ((not (equal msg-filename buffer-file-name))
75 ;; Buffer does not yet contain message.
76 (clear-visited-file-modtime)
78 (setq buffer-file-name nil) ; no locking during setup
79 (setq buffer-read-only nil)
82 (let* ((aname (concat "article-" folder))
83 (abuf (get-buffer aname))
88 (setq buffer-read-only nil)
91 (setq abuf (get-buffer-create aname))
95 (insert-file-contents msg-filename)
96 ;; (goto-char (point-min))
97 (while (re-search-forward "\r$" nil t)
101 (set-buffer-modified-p nil)
102 (setq buffer-read-only t)
103 (setq buffer-file-name msg-filename)
105 (mime-view-mode nil nil nil
106 aname (concat "show-" folder))
107 (goto-char (point-min))
109 (let ((clean-message-header mh-clean-message-header)
110 (invisible-headers mh-invisible-headers)
111 (visible-headers mh-visible-headers)
114 ;; modified by ARIURA <ariura@cc.tuat.ac.jp>
117 (mh-exec-lib-cmd-output "mhl" "-nobell" "-noclear"
118 (if (stringp mhl-formfile)
119 (list "-form" mhl-formfile))
121 (insert-file-contents msg-filename))
123 (goto-char (point-min))
124 (cond (clean-message-header
125 (mh-clean-msg-header (point-min)
128 (goto-char (point-min)))
130 (mh-start-of-uncleaned-message)))
131 (if emh-decode-encoded-word
132 (eword-decode-header)
134 (set-buffer-modified-p nil)
135 (setq buffer-read-only t)
136 (setq buffer-file-name msg-filename)
139 (or (eq buffer-undo-list t) ;don't save undo info for prev msgs
140 (setq buffer-undo-list nil))
141 ;;; Added by itokon (02/19/96)
142 (setq buffer-file-name msg-filename)
145 (setq mode-line-buffer-identification
146 (list (format mh-show-buffer-mode-line-buffer-id
149 (setq mh-showing-with-headers nil)))))
151 (defun emh-view-message (&optional msg)
152 "MIME decode and play this message."
154 (if (or (null emh-automatic-mime-preview)
155 (null (get-buffer mh-show-buffer))
157 (set-buffer mh-show-buffer)
158 (not (eq major-mode 'mime-view-mode))
160 (let ((emh-automatic-mime-preview t))
161 (mh-invalidate-show-buffer)
164 (pop-to-buffer mh-show-buffer)
167 (defun emh-toggle-decoding-mode (arg)
168 "Toggle MIME processing mode.
169 With arg, turn MIME processing on if arg is positive."
171 (setq emh-automatic-mime-preview
173 (not emh-automatic-mime-preview)
176 (set-buffer mh-show-buffer)
177 (if (null emh-automatic-mime-preview)
178 (if (and mime::preview/article-buffer
179 (get-buffer mime::preview/article-buffer))
180 (kill-buffer mime::preview/article-buffer)
182 (mh-invalidate-show-buffer)
183 (mh-show (mh-get-msg-num t))
186 (defun emh-show (&optional message)
188 (mh-invalidate-show-buffer)
192 (defun emh-header-display ()
194 (mh-invalidate-show-buffer)
195 (let ((mime-view-ignored-field-regexp "^:$")
196 emh-decode-encoded-word)
200 (defun emh-raw-display ()
202 (mh-invalidate-show-buffer)
203 (let (emh-automatic-mime-preview
204 emh-decode-encoded-word)
208 (defun emh-burst-multipart/digest ()
209 "Burst apart the current message, which should be a multipart/digest.
210 The message is replaced by its table of contents and the letters from the
211 digest are inserted into the folder after that message."
213 (let ((digest (mh-get-msg-num t)))
214 (mh-process-or-undo-commands mh-current-folder)
215 (mh-set-folder-modified-p t) ; lock folder while bursting
216 (message "Bursting digest...")
217 (mh-exec-cmd "mhn" "-store" mh-current-folder digest)
218 (mh-scan-folder mh-current-folder (format "%d-last" mh-first-msg-num))
219 (message "Bursting digest...done")
226 (fset 'emh-text-decode-buffer
227 (symbol-function 'mime-text-decode-buffer))
229 (set-alist 'mime-text-decoder-alist
231 (function emh-text-decode-buffer))
233 (defvar emh-content-header-filter-hook
235 '(emh-highlight-header)
237 "Hook for header filtering.")
239 (autoload 'emh-highlight-header "emh-face")
241 (defun emh-content-header-filter ()
242 "Header filter for mime-view.
243 It is registered to variable `mime-view-content-header-filter-alist'."
244 (goto-char (point-min))
245 (mime-view-cut-header)
246 (emh-text-decode-buffer default-mime-charset)
247 (eword-decode-header)
248 (run-hooks 'emh-content-header-filter-hook)
251 (set-alist 'mime-view-content-header-filter-alist
253 (function emh-content-header-filter))
255 (defun emh-quitting-method ()
256 (let ((win (get-buffer-window
257 mime/output-buffer-name))
258 (buf (current-buffer))
264 (let ((name (buffer-name buf)))
267 (if (not emh-automatic-mime-preview)
268 (mh-invalidate-show-buffer)
270 (mh-show (mh-get-msg-num t))
273 (set-alist 'mime-view-quitting-method-alist
275 (function emh-quitting-method))
276 (set-alist 'mime-view-show-summary-method
278 (function emh-quitting-method))
280 (defun emh-following-method (buf)
283 (goto-char (point-max))
284 (setq mh-show-buffer buf)
285 (apply (function mh-send)
286 (std11-field-bodies '("From" "cc" "Subject") ""))
287 (setq mh-sent-from-folder buf)
288 (setq mh-sent-from-msg 1)
289 (let ((last (point)))
294 (set-alist 'mime-view-following-method-alist
296 (function emh-following-method))
299 ;;; @@ for mime-partial
306 (set-atype 'mime/content-decoding-condition
307 '((type . "message/partial")
308 (method . mime-article/grab-message/partials)
309 (major-mode . mh-show-mode)
311 . (and (or (string-match "^article-\\(.+\\)$" article-buffer)
312 (string-match "^show-\\(.+\\)$" article-buffer))
313 (substring article-buffer
314 (match-beginning 1) (match-end 1))
317 (set-alist 'mime-partial/preview-article-method-alist
321 (let ((emh-automatic-mime-preview t))
330 (define-key mh-folder-mode-map "v" (function emh-view-message))
331 (define-key mh-folder-mode-map "\et" (function emh-toggle-decoding-mode))
332 (define-key mh-folder-mode-map "." (function emh-show))
333 (define-key mh-folder-mode-map "," (function emh-header-display))
334 (define-key mh-folder-mode-map "\e," (function emh-raw-display))
335 (define-key mh-folder-mode-map "\C-c\C-b"
336 (function emh-burst-multipart/digest))
338 (defun emh-summary-before-quit ()
339 (let ((buf (get-buffer mh-show-buffer)))
341 (let ((the-buf (current-buffer)))
342 (switch-to-buffer buf)
343 (if (and mime::article/preview-buffer
344 (setq buf (get-buffer mime::article/preview-buffer))
347 (switch-to-buffer the-buf)
350 (switch-to-buffer the-buf)
354 (add-hook 'mh-before-quit-hook (function emh-summary-before-quit))
357 ;;; @@ for emh-comp.el
360 (autoload 'emh-edit-again "emh-comp"
361 "Clean-up a draft or a message previously sent and make it resendable." t)
362 (autoload 'emh-extract-rejected-mail "emh-comp"
363 "Extract a letter returned by the mail system and make it re-editable." t)
364 (autoload 'emh-forward "emh-comp"
365 "Forward a message or message sequence by MIME style." t)
371 (substitute-key-definition
372 'mh-edit-again 'emh-edit-again mh-folder-mode-map)
373 (substitute-key-definition
374 'mh-extract-rejected-mail 'emh-extract-rejected-mail
376 (substitute-key-definition
377 'mh-forward 'emh-forward mh-folder-mode-map)
385 'mh-letter-mode-hook)
405 (run-hooks 'emh-load-hook)