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.25 $
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.
41 "$Id: emh.el,v 0.25 1998-02-17 13:50:17 morioka Exp $")
43 (defconst emh-version (get-version-string emh-RCS-ID))
50 "MIME Extension for mh-e"
54 (defcustom emh-automatic-mime-preview t
55 "*If non-nil, show MIME processed message."
59 (defcustom emh-decode-encoded-word t
60 "*If non-nil, decode encoded-word when it is not MIME preview mode."
68 (defun mh-display-msg (msg-num folder &optional show-buffer mode)
69 "Display message number MSG-NUM of FOLDER.
70 This function uses `mime-view-mode' if MODE is not nil. If MODE is
71 nil, `emh-automatic-mime-preview' is used as default value."
73 (setq mode emh-automatic-mime-preview)
75 ;; Display message NUMBER of FOLDER.
76 ;; Sets the current buffer to the show buffer.
79 (setq show-buffer mh-show-buffer))
80 ;; Bind variables in folder buffer in case they are local
81 (let ((msg-filename (mh-msg-filename msg-num)))
82 (if (not (file-exists-p msg-filename))
83 (error "Message %d does not exist" msg-num))
84 (set-buffer show-buffer)
85 (cond ((not (equal msg-filename buffer-file-name))
86 ;; Buffer does not yet contain message.
87 (clear-visited-file-modtime)
89 (setq buffer-file-name nil) ; no locking during setup
90 (setq buffer-read-only nil)
93 (let* ((aname (concat "article-" folder))
94 (abuf (get-buffer aname))
99 (setq buffer-read-only nil)
102 (setq abuf (get-buffer-create aname))
105 (let ((coding-system-for-read 'raw-text))
106 (insert-file-contents msg-filename)
108 (set-buffer-modified-p nil)
109 (setq buffer-read-only t)
110 (setq buffer-file-name msg-filename)
112 (mime-view-mode nil nil nil
113 aname (concat "show-" folder))
114 (goto-char (point-min))
116 (let ((clean-message-header mh-clean-message-header)
117 (invisible-headers mh-invisible-headers)
118 (visible-headers mh-visible-headers)
121 ;; modified by ARIURA <ariura@cc.tuat.ac.jp>
124 (mh-exec-lib-cmd-output "mhl" "-nobell" "-noclear"
125 (if (stringp mhl-formfile)
126 (list "-form" mhl-formfile))
128 (insert-file-contents msg-filename))
130 (goto-char (point-min))
131 (cond (clean-message-header
132 (mh-clean-msg-header (point-min)
135 (goto-char (point-min)))
137 (mh-start-of-uncleaned-message)))
138 (if emh-decode-encoded-word
139 (eword-decode-header)
141 (set-buffer-modified-p nil)
142 (setq buffer-read-only t)
143 (setq buffer-file-name msg-filename)
146 (or (eq buffer-undo-list t) ;don't save undo info for prev msgs
147 (setq buffer-undo-list nil))
148 ;;; Added by itokon (02/19/96)
149 (setq buffer-file-name msg-filename)
152 (setq mode-line-buffer-identification
153 (list (format mh-show-buffer-mode-line-buffer-id
156 (setq mh-showing-with-headers nil)))))
158 (defun emh-view-message (&optional msg)
159 "MIME decode and play this message."
161 (if (or (null emh-automatic-mime-preview)
162 (null (get-buffer mh-show-buffer))
164 (set-buffer mh-show-buffer)
165 (not (eq major-mode 'mime-view-mode))
167 (let ((emh-automatic-mime-preview t))
168 (mh-invalidate-show-buffer)
171 (pop-to-buffer mh-show-buffer)
174 (defun emh-toggle-decoding-mode (arg)
175 "Toggle MIME processing mode.
176 With arg, turn MIME processing on if arg is positive."
178 (setq emh-automatic-mime-preview
180 (not emh-automatic-mime-preview)
183 (set-buffer mh-show-buffer)
184 (if (null emh-automatic-mime-preview)
185 (if (and mime-raw-buffer
186 (get-buffer mime-raw-buffer))
187 (kill-buffer mime-raw-buffer)
189 (mh-invalidate-show-buffer)
190 (mh-show (mh-get-msg-num t))
193 (defun emh-show (&optional message)
195 (mh-invalidate-show-buffer)
199 (defun emh-header-display ()
201 (mh-invalidate-show-buffer)
202 (let ((mime-view-ignored-field-regexp "^:$")
203 emh-decode-encoded-word)
207 (defun emh-raw-display ()
209 (mh-invalidate-show-buffer)
210 (let (emh-automatic-mime-preview
211 emh-decode-encoded-word)
215 (defun emh-burst-multipart/digest ()
216 "Burst apart the current message, which should be a multipart/digest.
217 The message is replaced by its table of contents and the letters from the
218 digest are inserted into the folder after that message."
220 (let ((digest (mh-get-msg-num t)))
221 (mh-process-or-undo-commands mh-current-folder)
222 (mh-set-folder-modified-p t) ; lock folder while bursting
223 (message "Bursting digest...")
224 (mh-exec-cmd "mhn" "-store" mh-current-folder digest)
225 (mh-scan-folder mh-current-folder (format "%d-last" mh-first-msg-num))
226 (message "Bursting digest...done")
233 (fset 'emh-text-decode-buffer
234 (symbol-function 'mime-text-decode-buffer))
236 (set-alist 'mime-text-decoder-alist
238 (function emh-text-decode-buffer))
240 (defvar emh-content-header-filter-hook
242 '(emh-highlight-header)
244 "Hook for header filtering.")
246 (autoload 'emh-highlight-header "emh-face")
248 (defun emh-content-header-filter ()
249 "Header filter for mime-view.
250 It is registered to variable `mime-view-content-header-filter-alist'."
251 (goto-char (point-min))
252 (mime-view-cut-header)
253 (eword-decode-header default-mime-charset)
254 (run-hooks 'emh-content-header-filter-hook)
257 (set-alist 'mime-view-content-header-filter-alist
259 (function emh-content-header-filter))
261 (defun emh-quitting-method ()
262 (let ((buf (current-buffer)))
263 (mime-maybe-hide-echo-buffer)
265 (let ((name (buffer-name buf)))
268 (if (not emh-automatic-mime-preview)
269 (mh-invalidate-show-buffer)
271 (mh-show (mh-get-msg-num t))
274 (set-alist 'mime-view-quitting-method-alist
276 (function emh-quitting-method))
277 (set-alist 'mime-view-show-summary-method
279 (function emh-quitting-method))
281 (defun emh-following-method (buf)
284 (goto-char (point-max))
285 (setq mh-show-buffer buf)
286 (apply (function mh-send)
287 (std11-field-bodies '("From" "cc" "Subject") ""))
288 (setq mh-sent-from-folder buf)
289 (setq mh-sent-from-msg 1)
290 (let ((last (point)))
295 (set-alist 'mime-view-following-method-alist
297 (function emh-following-method))
300 ;;; @@ for mime-partial
306 (autoload 'mime-combine-message/partials-automatically
308 "Internal method to combine message/partial messages automatically.")
309 (set-atype 'mime-acting-condition
310 '((type . "message/partial")
311 (method . mime-combine-message/partials-automatically)
312 (major-mode . mh-show-mode)
314 . (and (or (string-match "^article-\\(.+\\)$"
316 (string-match "^show-\\(.+\\)$" article-buffer))
317 (substring article-buffer
318 (match-beginning 1) (match-end 1))
321 (set-alist 'mime-view-partial-message-method-alist
325 (let ((emh-automatic-mime-preview t))
334 (define-key mh-folder-mode-map "v" (function emh-view-message))
335 (define-key mh-folder-mode-map "\et" (function emh-toggle-decoding-mode))
336 (define-key mh-folder-mode-map "." (function emh-show))
337 (define-key mh-folder-mode-map "," (function emh-header-display))
338 (define-key mh-folder-mode-map "\e," (function emh-raw-display))
339 (define-key mh-folder-mode-map "\C-c\C-b"
340 (function emh-burst-multipart/digest))
342 (defun emh-summary-before-quit ()
343 (let ((buf (get-buffer mh-show-buffer)))
345 (let ((the-buf (current-buffer)))
346 (switch-to-buffer buf)
347 (if (and mime-view-buffer
348 (setq buf (get-buffer mime-view-buffer))
351 (switch-to-buffer the-buf)
354 (switch-to-buffer the-buf)
358 (add-hook 'mh-before-quit-hook (function emh-summary-before-quit))
364 (eval-after-load "bbdb" '(require 'mime-bbdb))
372 (run-hooks 'emh-load-hook)