2 ;;; tm-mh-e.el --- MIME extender for mh-e
4 ;;; Copyright (C) 1995 Free Software Foundation, Inc.
5 ;;; Copyright (C) 1993,1994,1995 MORIOKA Tomohiko
7 ;;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
8 ;;; Keywords: mail, MH, MIME, multimedia, encoded-word, multilingual
10 ;;; This file is part of tm (Tools for MIME).
19 (if (not (boundp 'mh-e-version))
28 (defconst tm-mh-e/RCS-ID
29 "$Id: tm-mh-e.el,v 7.9 1995/10/26 09:26:23 morioka Exp $")
31 (defconst tm-mh-e/version (get-version-string tm-mh-e/RCS-ID))
37 (defvar tm-mh-e/decode-all t
38 "*If t, decode all of the message. Otherwise decode header only.")
40 (defvar tm-mh-e/decode-encoded-word t)
46 (if (not (fboundp 'tm-mh-e/original-mh-display-msg))
47 (fset 'tm-mh-e/original-mh-display-msg
48 (symbol-function 'mh-display-msg))
51 (defun mh-display-msg (msg-num folder &optional show-buffer mode)
53 (setq mode tm-mh-e/decode-all)
55 ;; Display message NUMBER of FOLDER.
56 ;; Sets the current buffer to the show buffer.
59 (setq show-buffer mh-show-buffer))
60 ;; Bind variables in folder buffer in case they are local
61 (let ((msg-filename (mh-msg-filename msg-num)))
62 (if (not (file-exists-p msg-filename))
63 (error "Message %d does not exist" msg-num))
64 (set-buffer show-buffer)
65 (cond ((not (equal msg-filename buffer-file-name))
66 ;; Buffer does not yet contain message.
67 (clear-visited-file-modtime)
69 (setq buffer-file-name nil) ; no locking during setup
70 (setq buffer-read-only nil)
73 (let* ((aname (concat "article-" folder))
74 (abuf (get-buffer aname))
79 (setq buffer-read-only nil)
82 (setq abuf (get-buffer-create aname))
85 (let ((file-coding-system-for-read
86 (if (boundp 'MULE) *noconv*))
88 (insert-file-contents msg-filename)
89 ;; (goto-char (point-min))
90 (while (re-search-forward "\r$" nil t)
94 (set-buffer-modified-p nil)
95 (setq buffer-read-only t)
97 (mime/viewer-mode nil nil nil
98 aname (concat "show-" folder))
99 (goto-char (point-min))
101 (let ((clean-message-header mh-clean-message-header)
102 (invisible-headers mh-invisible-headers)
103 (visible-headers mh-visible-headers)
106 ;; modified by ARIURA <ariura@cc.tuat.ac.jp>
109 (mh-exec-lib-cmd-output "mhl" "-nobell" "-noclear"
110 (if (stringp mhl-formfile)
111 (list "-form" mhl-formfile))
113 (insert-file-contents msg-filename))
115 (goto-char (point-min))
116 (cond (clean-message-header
117 (mh-clean-msg-header (point-min)
120 (goto-char (point-min)))
122 (mh-start-of-uncleaned-message)))
123 (if tm-mh-e/decode-encoded-word
124 (mime/decode-message-header)
126 (set-buffer-modified-p nil)
127 (setq buffer-read-only t)
130 (or (eq buffer-undo-list t) ;don't save undo info for prev msgs
131 (setq buffer-undo-list nil))
132 (setq buffer-file-name msg-filename)
134 (setq mode-line-buffer-identification
135 (list (format mh-show-buffer-mode-line-buffer-id
138 (setq mh-showing-with-headers nil)))))
140 (defun tm-mh-e/view-message (&optional msg)
141 "MIME decode and play this message."
143 (if (null tm-mh-e/decode-all)
144 (let ((tm-mh-e/decode-all t))
145 (mh-invalidate-show-buffer)
148 (pop-to-buffer mh-show-buffer)
151 (defun tm-mh-e/toggle-decoding-mode (arg)
152 "Toggle MIME processing mode.
153 With arg, turn MIME processing on if arg is positive."
155 (setq tm-mh-e/decode-all
157 (not tm-mh-e/decode-all)
160 (set-buffer mh-show-buffer)
161 (if (null tm-mh-e/decode-all)
162 (if (and mime::preview/article-buffer
163 (get-buffer mime::preview/article-buffer))
164 (kill-buffer mime::preview/article-buffer)
166 (mh-invalidate-show-buffer)
167 (mh-show (mh-get-msg-num t))
170 (defun tm-mh-e/show (&optional message)
172 (mh-invalidate-show-buffer)
176 (defun tm-mh-e/header-display ()
178 (mh-invalidate-show-buffer)
179 (let (mime-viewer/ignored-field-list
180 tm-mh-e/decode-encoded-word)
184 (defun tm-mh-e/raw-display ()
186 (mh-invalidate-show-buffer)
187 (let (tm-mh-e/decode-all
188 tm-mh-e/decode-encoded-word)
196 (fset 'tm-mh-e/code-convert-region-to-emacs
197 (symbol-function 'mime/code-convert-region-to-emacs))
199 (defun tm-mh-e/content-header-filter ()
200 (goto-char (point-min))
201 (while (and (re-search-forward mime-viewer/ignored-field-regexp nil t)
207 (re-search-forward "^\\([^ \t]\\|$\\)" nil t)
211 (tm-mh-e/code-convert-region-to-emacs (point-min)(point-max)
212 mime/default-coding-system)
213 (mime/decode-message-header)
214 (if (featurep 'hilit19)
215 (hilit-rehighlight-buffer-quietly)
219 (defun tm-mh-e/quitting-method ()
220 (let ((win (get-buffer-window
221 mime/output-buffer-name))
222 (buf (current-buffer))
228 (let ((name (buffer-name buf)))
231 (if (not tm-mh-e/decode-all)
232 (mh-invalidate-show-buffer)
234 (mh-show (mh-get-msg-num t))
245 (set-atype 'mime/content-decoding-condition
246 '((type . "message/partial")
247 (method . mime-article/grab-message/partials)
248 (major-mode . mh-show-mode)
250 . (and (or (string-match "^article-\\(.+\\)$" article-buffer)
251 (string-match "^show-\\(.+\\)$" article-buffer))
252 (substring article-buffer
253 (match-beginning 1) (match-end 1))
256 (set-alist 'tm-partial/preview-article-method-alist
260 (let ((tm-mh-e/decode-all t))
269 (defun tm-mh-e::make-message (folder number)
270 (vector folder number)
273 (defun tm-mh-e::message/folder (message)
277 (defun tm-mh-e::message/number (message)
281 (defun tm-mh-e::message/file-name (message)
283 (tm-mh-e::message/number message)
284 (mh-expand-file-name (tm-mh-e::message/folder message))
287 (defun tm-mh-e/prompt-for-message (prompt folder &optional default)
289 (directory-files (mh-expand-file-name folder) nil "^[0-9]+$")
291 (default mh-sent-from-msg)
295 (int-to-string default)
298 (completing-read prompt
309 (defun tm-mh-e/query-message ()
310 (let* ((folder (mh-prompt-for-folder "Visit" "+inbox" nil))
311 (number (tm-mh-e/prompt-for-message "Number: " folder))
313 (tm-mh-e::make-message folder number)
316 (defun tm-mh-e/insert-message (&optional message)
318 (setq message (tm-mh-e/query-message))
320 (insert-file (tm-mh-e::message/file-name message))
328 'tm-edit/message-inserter-alist
329 'mh-letter-mode (function tm-mh-e/insert-message))
336 (define-key mh-folder-mode-map "v" (function tm-mh-e/view-message))
337 (define-key mh-folder-mode-map "\et" (function tm-mh-e/toggle-decoding-mode))
338 (define-key mh-folder-mode-map "." (function tm-mh-e/show))
339 (define-key mh-folder-mode-map "," (function tm-mh-e/header-display))
340 (define-key mh-folder-mode-map "\e," (function tm-mh-e/raw-display))
341 (define-key mh-folder-mode-map "\r"
344 (scroll-other-window 1)
346 (define-key mh-folder-mode-map "\e\r"
349 (scroll-other-window -1)
352 (defun tm-mh-e/summary-before-quit ()
353 (let ((buf (get-buffer mh-show-buffer)))
355 (let ((the-buf (current-buffer)))
356 (switch-to-buffer buf)
357 (if (and mime::article/preview-buffer
358 (setq buf (get-buffer mime::article/preview-buffer))
361 (switch-to-buffer the-buf)
364 (switch-to-buffer the-buf)
368 (add-hook 'mh-before-quit-hook (function tm-mh-e/summary-before-quit))
370 (set-alist 'mime-viewer/quitting-method-alist
372 (function tm-mh-e/quitting-method))
374 (set-alist 'mime-viewer/content-header-filter-alist
376 (function tm-mh-e/content-header-filter))
378 (set-alist 'mime-viewer/code-converter-alist
380 (function tm-mh-e/code-convert-region-to-emacs))
388 (run-hooks 'tm-mh-e-load-hook)