1 ;;; emh.el --- MIME extender for mh-e
3 ;; Copyright (C) 1995,1996,1997,1998,2000 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <tomo@m17n.org>
6 ;; OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
7 ;; Maintainer: MORIOKA Tomohiko <tomo@m17n.org>
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.
40 (defconst emh-version "1.14.0")
47 "MIME Extension for mh-e"
51 (defcustom emh-automatic-mime-preview t
52 "*If non-nil, show MIME processed message."
56 (defcustom emh-decode-encoded-word t
57 "*If non-nil, decode encoded-word when it is not MIME preview mode."
65 (defsubst emh-raw-buffer (folder-buffer)
66 (concat "article-" (if (bufferp folder-buffer)
67 (buffer-name folder-buffer)
70 (defun mh-display-msg (msg-num folder &optional show-buffer mode)
71 "Display message number MSG-NUM of FOLDER.
72 This function uses `mime-view-mode' if MODE is not nil. If MODE is
73 nil, `emh-automatic-mime-preview' is used as default value."
75 (setq mode emh-automatic-mime-preview)
77 ;; Display message NUMBER of FOLDER.
78 ;; Sets the current buffer to the show buffer.
81 (setq show-buffer mh-show-buffer))
82 ;; Bind variables in folder buffer in case they are local
83 (let ((msg-filename (mh-msg-filename msg-num)))
84 (if (not (file-exists-p msg-filename))
85 (error "Message %d does not exist" msg-num))
86 (set-buffer show-buffer)
87 (cond ((not (equal msg-filename buffer-file-name))
88 ;; Buffer does not yet contain message.
89 (clear-visited-file-modtime)
91 (setq buffer-file-name nil) ; no locking during setup
92 (setq buffer-read-only nil)
95 (let* ((aname (emh-raw-buffer folder))
96 (abuf (get-buffer aname)))
100 (setq buffer-read-only nil)
103 (setq abuf (get-buffer-create aname))
105 (set-buffer-multibyte nil)
107 (raw-text-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-display-message (mime-open-entity 'buffer aname)
113 (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))
120 ;; modified by ARIURA <ariura@cc.tuat.ac.jp>
123 (mh-exec-lib-cmd-output "mhl" "-nobell" "-noclear"
124 (if (stringp mhl-formfile)
125 (list "-form" mhl-formfile))
127 (insert-file-contents msg-filename))
129 (goto-char (point-min))
130 (cond (clean-message-header
131 (mh-clean-msg-header (point-min)
134 (goto-char (point-min)))
136 (mh-start-of-uncleaned-message)))
137 (if emh-decode-encoded-word
138 (mime-decode-header-in-buffer))
139 (set-buffer-modified-p nil)
140 (setq buffer-read-only t)
141 (setq buffer-file-name msg-filename)
144 (or (eq buffer-undo-list t) ;don't save undo info for prev msgs
145 (setq buffer-undo-list nil))
146 ;;; Added by itokon (02/19/96)
147 (setq buffer-file-name msg-filename)
150 (setq mode-line-buffer-identification
151 (list (format mh-show-buffer-mode-line-buffer-id
154 (setq mh-showing-with-headers nil)))))
156 (defun emh-view-message (&optional msg)
157 "MIME decode and play this message."
159 (if (or (null emh-automatic-mime-preview)
160 (null (get-buffer mh-show-buffer))
162 (set-buffer mh-show-buffer)
163 (not (eq major-mode 'mime-view-mode))
165 (let ((emh-automatic-mime-preview t))
166 (mh-invalidate-show-buffer)
169 (pop-to-buffer mh-show-buffer)
172 (defun emh-toggle-decoding-mode (arg)
173 "Toggle MIME processing mode.
174 With arg, turn MIME processing on if arg is positive."
176 (setq emh-automatic-mime-preview
178 (not emh-automatic-mime-preview)
180 (let ((raw-buffer (emh-raw-buffer (current-buffer))))
181 (if (get-buffer raw-buffer)
182 (kill-buffer raw-buffer)
184 (mh-invalidate-show-buffer)
185 (mh-show (mh-get-msg-num t))
188 (defun emh-show (&optional message)
190 (mh-invalidate-show-buffer)
194 (defun emh-header-display ()
196 (mh-invalidate-show-buffer)
197 (let (mime-view-ignored-field-list
198 mime-view-visible-field-list
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 (defvar emh-display-header-hook (if window-system '(emh-highlight-header))
230 "Hook for header filtering.")
232 (autoload 'emh-highlight-header "emh-face")
234 (defun emh-header-presentation-method (entity situation)
235 (mime-insert-header entity
236 mime-view-ignored-field-list
237 mime-view-visible-field-list)
238 (run-hooks 'emh-display-header-hook)
241 (set-alist 'mime-header-presentation-method-alist
242 'mh-show-mode #'emh-header-presentation-method)
245 (defun emh-quitting-method ()
246 (let ((buf (current-buffer)))
247 (mime-maybe-hide-echo-buffer)
249 (let ((name (buffer-name buf)))
252 (if (not emh-automatic-mime-preview)
253 (mh-invalidate-show-buffer)
255 (mh-show (mh-get-msg-num t))
258 (set-alist 'mime-preview-quitting-method-alist
259 'mh-show-mode #'emh-quitting-method)
262 (defun emh-following-method (buf)
265 (goto-char (point-max))
266 (setq mh-show-buffer buf)
267 (apply (function mh-send)
268 (std11-field-bodies '("From" "cc" "Subject") ""))
269 (setq mh-sent-from-folder buf)
270 (setq mh-sent-from-msg 1)
271 (let ((last (point)))
276 (set-alist 'mime-preview-following-method-alist
277 'mh-show-mode #'emh-following-method)
280 ;;; @@ for mime-partial
283 (defun emh-request-partial-message ()
284 (let ((msg-filename (mh-msg-filename (mh-get-msg-num t)))
285 (show-buffer mh-show-buffer))
286 (set-buffer (get-buffer-create " *Partial Article*"))
288 (setq mime-preview-buffer show-buffer)
289 (raw-text-insert-file-contents msg-filename)
293 (defun emh-get-folder-buffer ()
294 (let ((buffer-name (buffer-name (current-buffer))))
295 (and (or (string-match "^article-\\(.+\\)$" buffer-name)
296 (string-match "^show-\\(.+\\)$" buffer-name))
297 (substring buffer-name
298 (match-beginning 1) (match-end 1))
301 (autoload 'mime-combine-message/partial-pieces-automatically
303 "Internal method to combine message/partial messages automatically.")
307 '((type . message)(subtype . partial)
308 (major-mode . mh-show-mode)
309 (method . mime-combine-message/partial-pieces-automatically)
310 (summary-buffer-exp . (emh-get-folder-buffer))
311 (request-partial-message-method . emh-request-partial-message)
318 (define-key mh-folder-mode-map "v" (function emh-view-message))
319 (define-key mh-folder-mode-map "\et" (function emh-toggle-decoding-mode))
320 (define-key mh-folder-mode-map "." (function emh-show))
321 (define-key mh-folder-mode-map "," (function emh-header-display))
322 (define-key mh-folder-mode-map "\e," (function emh-raw-display))
323 (define-key mh-folder-mode-map "\C-c\C-b"
324 (function emh-burst-multipart/digest))
326 (defun emh-summary-before-quit ()
327 (let ((buf (get-buffer mh-show-buffer)))
329 (let ((the-buf (current-buffer)))
330 (switch-to-buffer buf)
331 (if (and mime-preview-buffer
332 (setq buf (get-buffer mime-preview-buffer))
335 (switch-to-buffer the-buf)
338 (switch-to-buffer the-buf)
342 (add-hook 'mh-before-quit-hook (function emh-summary-before-quit))
348 (eval-after-load "bbdb" '(require 'mime-bbdb))
356 (run-hooks 'emh-load-hook)