1 ;;; emh.el --- MIME extender for mh-e
3 ;; Copyright (C) 1995,1996,1997,1998 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 ;; Keywords: MH, MIME, multimedia, encoded-word, multilingual, mail
13 ;; This file is part of emh.
15 ;; This program is free software; you can redistribute it and/or
16 ;; modify it under the terms of the GNU General Public License as
17 ;; published by the Free Software Foundation; either version 2, or (at
18 ;; your option) any later version.
20 ;; This program is distributed in the hope that it will be useful, but
21 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 ;; General Public License for more details.
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with GNU Emacs; see the file COPYING. If not, write to the
27 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
28 ;; Boston, MA 02111-1307, USA.
35 (eval-when-compile (require 'mime-text))
41 (defconst emh-version "1.4.0")
48 "MIME Extension for mh-e"
52 (defcustom emh-automatic-mime-preview t
53 "*If non-nil, show MIME processed message."
57 (defcustom emh-decode-encoded-word t
58 "*If non-nil, decode encoded-word when it is not MIME preview mode."
66 (defun mh-display-msg (msg-num folder &optional show-buffer mode)
67 "Display message number MSG-NUM of FOLDER.
68 This function uses `mime-view-mode' if MODE is not nil. If MODE is
69 nil, `emh-automatic-mime-preview' is used as default value."
71 (setq mode emh-automatic-mime-preview)
73 ;; Display message NUMBER of FOLDER.
74 ;; Sets the current buffer to the show buffer.
77 (setq show-buffer mh-show-buffer))
78 ;; Bind variables in folder buffer in case they are local
79 (let ((msg-filename (mh-msg-filename msg-num)))
80 (if (not (file-exists-p msg-filename))
81 (error "Message %d does not exist" msg-num))
82 (set-buffer show-buffer)
83 (cond ((not (equal msg-filename buffer-file-name))
84 ;; Buffer does not yet contain message.
85 (clear-visited-file-modtime)
87 (setq buffer-file-name nil) ; no locking during setup
88 (setq buffer-read-only nil)
91 (let* ((aname (concat "article-" folder))
92 (abuf (get-buffer aname))
97 (setq buffer-read-only nil)
100 (setq abuf (get-buffer-create aname))
103 (insert-file-contents-as-raw-text msg-filename)
104 (set-buffer-modified-p nil)
105 (setq buffer-read-only t)
106 (setq buffer-file-name msg-filename)
108 (mime-view-mode nil nil nil
109 aname (concat "show-" folder))
110 (goto-char (point-min))
112 (let ((clean-message-header mh-clean-message-header)
113 (invisible-headers mh-invisible-headers)
114 (visible-headers mh-visible-headers)
117 ;; modified by ARIURA <ariura@cc.tuat.ac.jp>
120 (mh-exec-lib-cmd-output "mhl" "-nobell" "-noclear"
121 (if (stringp mhl-formfile)
122 (list "-form" mhl-formfile))
124 (insert-file-contents msg-filename))
126 (goto-char (point-min))
127 (cond (clean-message-header
128 (mh-clean-msg-header (point-min)
131 (goto-char (point-min)))
133 (mh-start-of-uncleaned-message)))
134 (if emh-decode-encoded-word
135 (eword-decode-header)
137 (set-buffer-modified-p nil)
138 (setq buffer-read-only t)
139 (setq buffer-file-name msg-filename)
142 (or (eq buffer-undo-list t) ;don't save undo info for prev msgs
143 (setq buffer-undo-list nil))
144 ;;; Added by itokon (02/19/96)
145 (setq buffer-file-name msg-filename)
148 (setq mode-line-buffer-identification
149 (list (format mh-show-buffer-mode-line-buffer-id
152 (setq mh-showing-with-headers nil)))))
154 (defun emh-view-message (&optional msg)
155 "MIME decode and play this message."
157 (if (or (null emh-automatic-mime-preview)
158 (null (get-buffer mh-show-buffer))
160 (set-buffer mh-show-buffer)
161 (not (eq major-mode 'mime-view-mode))
163 (let ((emh-automatic-mime-preview t))
164 (mh-invalidate-show-buffer)
167 (pop-to-buffer mh-show-buffer)
170 (defun emh-toggle-decoding-mode (arg)
171 "Toggle MIME processing mode.
172 With arg, turn MIME processing on if arg is positive."
174 (setq emh-automatic-mime-preview
176 (not emh-automatic-mime-preview)
179 (set-buffer mh-show-buffer)
180 (if (null emh-automatic-mime-preview)
181 (if (and mime-raw-buffer
182 (get-buffer mime-raw-buffer))
183 (kill-buffer mime-raw-buffer)
185 (mh-invalidate-show-buffer)
186 (mh-show (mh-get-msg-num t))
189 (defun emh-show (&optional message)
191 (mh-invalidate-show-buffer)
195 (defun emh-header-display ()
197 (mh-invalidate-show-buffer)
198 (let ((mime-view-ignored-field-regexp "^:$")
199 emh-decode-encoded-word)
203 (defun emh-raw-display ()
205 (mh-invalidate-show-buffer)
206 (let (emh-automatic-mime-preview
207 emh-decode-encoded-word)
211 (defun emh-burst-multipart/digest ()
212 "Burst apart the current message, which should be a multipart/digest.
213 The message is replaced by its table of contents and the letters from the
214 digest are inserted into the folder after that message."
216 (let ((digest (mh-get-msg-num t)))
217 (mh-process-or-undo-commands mh-current-folder)
218 (mh-set-folder-modified-p t) ; lock folder while bursting
219 (message "Bursting digest...")
220 (mh-exec-cmd "mhn" "-store" mh-current-folder digest)
221 (mh-scan-folder mh-current-folder (format "%d-last" mh-first-msg-num))
222 (message "Bursting digest...done")
229 (set-alist 'mime-raw-representation-type-alist 'mh-show-mode 'binary)
231 (defvar emh-content-header-filter-hook
233 '(emh-highlight-header)
235 "Hook for header filtering.")
237 (autoload 'emh-highlight-header "emh-face")
239 (defun emh-content-header-filter ()
240 "Header filter for mime-view.
241 It is registered to variable `mime-view-content-header-filter-alist'."
242 (goto-char (point-min))
243 (mime-view-cut-header)
244 (eword-decode-header default-mime-charset)
245 (run-hooks 'emh-content-header-filter-hook)
248 (set-alist 'mime-view-content-header-filter-alist
250 (function emh-content-header-filter))
252 (defun emh-quitting-method ()
253 (let ((buf (current-buffer)))
254 (mime-maybe-hide-echo-buffer)
256 (let ((name (buffer-name buf)))
259 (if (not emh-automatic-mime-preview)
260 (mh-invalidate-show-buffer)
262 (mh-show (mh-get-msg-num t))
265 (set-alist 'mime-preview-quitting-method-alist
266 'mh-show-mode #'emh-quitting-method)
267 (set-alist 'mime-view-show-summary-method
269 (function emh-quitting-method))
271 (defun emh-following-method (buf)
274 (goto-char (point-max))
275 (setq mh-show-buffer buf)
276 (apply (function mh-send)
277 (std11-field-bodies '("From" "cc" "Subject") ""))
278 (setq mh-sent-from-folder buf)
279 (setq mh-sent-from-msg 1)
280 (let ((last (point)))
285 (set-alist 'mime-view-following-method-alist
287 (function emh-following-method))
290 ;;; @@ for mime-partial
293 (autoload 'mime-method-to-combine-message/partial-pieces
295 "Internal method to combine message/partial messages automatically.")
299 '((type . message)(subtype . partial)
300 (method . mime-method-to-combine-message/partial-pieces)
301 (major-mode . mh-show-mode)
303 . (and (or (string-match "^article-\\(.+\\)$"
305 (string-match "^show-\\(.+\\)$" article-buffer))
306 (substring article-buffer
307 (match-beginning 1) (match-end 1))
311 (set-alist 'mime-view-partial-message-method-alist
315 (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-preview-buffer
337 (setq buf (get-buffer mime-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))
353 (eval-after-load "bbdb" '(require 'mime-bbdb))
361 (run-hooks 'emh-load-hook)