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 ;;; OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
9 ;;; modified by YAMAOKA Katsumi <yamaoka@ga.sony.co.jp>
10 ;;; Keywords: mail, MH, MIME, multimedia, encoded-word, multilingual
12 ;;; This file is part of tm (Tools for MIME).
21 (if (not (boundp 'mh-e-version))
30 (defconst tm-mh-e/RCS-ID
31 "$Id: tm-mh-e.el,v 7.25 1995/11/19 06:44:32 morioka Exp $")
33 (defconst tm-mh-e/version (get-version-string tm-mh-e/RCS-ID))
39 (defvar tm-mh-e/automatic-mime-preview t
40 "If non-nil, show MIME processed message.")
42 (defvar tm-mh-e/decode-encoded-word t
43 "If non-nil, decode encoded-word when it is not MIME preview mode.")
45 (defvar tm-mh-e/use-forwcomps nil)
46 (defvar tm-mh-e/forwcomps "forwcomps")
52 (if (not (fboundp 'tm-mh-e/original-mh-display-msg))
53 (fset 'tm-mh-e/original-mh-display-msg
54 (symbol-function 'mh-display-msg))
57 (defun mh-display-msg (msg-num folder &optional show-buffer mode)
59 (setq mode tm-mh-e/automatic-mime-preview)
61 ;; Display message NUMBER of FOLDER.
62 ;; Sets the current buffer to the show buffer.
65 (setq show-buffer mh-show-buffer))
66 ;; Bind variables in folder buffer in case they are local
67 (let ((msg-filename (mh-msg-filename msg-num)))
68 (if (not (file-exists-p msg-filename))
69 (error "Message %d does not exist" msg-num))
70 (set-buffer show-buffer)
71 (cond ((not (equal msg-filename buffer-file-name))
72 ;; Buffer does not yet contain message.
73 (clear-visited-file-modtime)
75 (setq buffer-file-name nil) ; no locking during setup
76 (setq buffer-read-only nil)
79 (let* ((aname (concat "article-" folder))
80 (abuf (get-buffer aname))
85 (setq buffer-read-only nil)
88 (setq abuf (get-buffer-create aname))
91 (let ((file-coding-system-for-read
92 (if (boundp 'MULE) *noconv*))
94 (insert-file-contents msg-filename)
95 ;; (goto-char (point-min))
96 (while (re-search-forward "\r$" nil t)
100 (set-buffer-modified-p nil)
101 (setq buffer-read-only t)
103 (mime/viewer-mode nil nil nil
104 aname (concat "show-" folder))
105 (goto-char (point-min))
107 (let ((clean-message-header mh-clean-message-header)
108 (invisible-headers mh-invisible-headers)
109 (visible-headers mh-visible-headers)
112 ;; modified by ARIURA <ariura@cc.tuat.ac.jp>
115 (mh-exec-lib-cmd-output "mhl" "-nobell" "-noclear"
116 (if (stringp mhl-formfile)
117 (list "-form" mhl-formfile))
119 (insert-file-contents msg-filename))
121 (goto-char (point-min))
122 (cond (clean-message-header
123 (mh-clean-msg-header (point-min)
126 (goto-char (point-min)))
128 (mh-start-of-uncleaned-message)))
129 (if tm-mh-e/decode-encoded-word
130 (mime/decode-message-header)
132 (set-buffer-modified-p nil)
133 (setq buffer-read-only t)
136 (or (eq buffer-undo-list t) ;don't save undo info for prev msgs
137 (setq buffer-undo-list nil))
138 (setq buffer-file-name msg-filename)
140 (setq mode-line-buffer-identification
141 (list (format mh-show-buffer-mode-line-buffer-id
144 (setq mh-showing-with-headers nil)))))
146 (defun tm-mh-e/view-message (&optional msg)
147 "MIME decode and play this message."
149 (if (or (null tm-mh-e/automatic-mime-preview)
150 (null (get-buffer mh-show-buffer))
152 (set-buffer mh-show-buffer)
153 (not (eq major-mode 'mime/viewer-mode))
155 (let ((tm-mh-e/automatic-mime-preview t))
156 (mh-invalidate-show-buffer)
159 (pop-to-buffer mh-show-buffer)
162 (defun tm-mh-e/toggle-decoding-mode (arg)
163 "Toggle MIME processing mode.
164 With arg, turn MIME processing on if arg is positive."
166 (setq tm-mh-e/automatic-mime-preview
168 (not tm-mh-e/automatic-mime-preview)
171 (set-buffer mh-show-buffer)
172 (if (null tm-mh-e/automatic-mime-preview)
173 (if (and mime::preview/article-buffer
174 (get-buffer mime::preview/article-buffer))
175 (kill-buffer mime::preview/article-buffer)
177 (mh-invalidate-show-buffer)
178 (mh-show (mh-get-msg-num t))
181 (defun tm-mh-e/show (&optional message)
183 (mh-invalidate-show-buffer)
187 (defun tm-mh-e/header-display ()
189 (mh-invalidate-show-buffer)
190 (let (mime-viewer/ignored-field-list
191 tm-mh-e/decode-encoded-word)
195 (defun tm-mh-e/raw-display ()
197 (mh-invalidate-show-buffer)
198 (let (tm-mh-e/automatic-mime-preview
199 tm-mh-e/decode-encoded-word)
207 (fset 'tm-mh-e/code-convert-region-to-emacs
208 (symbol-function 'mime/code-convert-region-to-emacs))
210 (defun tm-mh-e/content-header-filter ()
211 (goto-char (point-min))
212 (while (and (re-search-forward mime-viewer/ignored-field-regexp nil t)
218 (re-search-forward "^\\([^ \t]\\|$\\)" nil t)
222 (tm-mh-e/code-convert-region-to-emacs (point-min)(point-max)
223 mime/default-coding-system)
224 (mime/decode-message-header)
225 (if (featurep 'hilit19)
226 (hilit-rehighlight-buffer-quietly)
230 (defun tm-mh-e/quitting-method ()
231 (let ((win (get-buffer-window
232 mime/output-buffer-name))
233 (buf (current-buffer))
239 (let ((name (buffer-name buf)))
242 (if (not tm-mh-e/automatic-mime-preview)
243 (mh-invalidate-show-buffer)
245 (mh-show (mh-get-msg-num t))
256 (set-atype 'mime/content-decoding-condition
257 '((type . "message/partial")
258 (method . mime-article/grab-message/partials)
259 (major-mode . mh-show-mode)
261 . (and (or (string-match "^article-\\(.+\\)$" article-buffer)
262 (string-match "^show-\\(.+\\)$" article-buffer))
263 (substring article-buffer
264 (match-beginning 1) (match-end 1))
267 (set-alist 'tm-partial/preview-article-method-alist
271 (let ((tm-mh-e/automatic-mime-preview t))
280 (defun tm-mh-e::make-message (folder number)
281 (vector folder number)
284 (defun tm-mh-e::message/folder (message)
288 (defun tm-mh-e::message/number (message)
292 (defun tm-mh-e::message/file-name (message)
294 (tm-mh-e::message/number message)
295 (mh-expand-file-name (tm-mh-e::message/folder message))
298 ;;; modified by OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
299 ;;; 1995/11/14 (cf. [tm-ja:1096])
300 (defun tm-mh-e/prompt-for-message (prompt folder &optional default)
302 (directory-files (mh-expand-file-name folder) nil "^[0-9]+$")
304 (folder-buf (get-buffer folder))
308 (set-buffer folder-buf)
309 (let ((show-buffer (get-buffer mh-show-buffer)))
311 (file-name-nondirectory
312 (buffer-file-name show-buffer))
314 (if (or (null default)
315 (not (string-match "^[0-9]+$" default)))
317 (if (string= folder mh-sent-from-folder)
318 (int-to-string mh-sent-from-msg)
321 (completing-read prompt
332 (defun tm-mh-e/query-message ()
333 (let* ((folder (mh-prompt-for-folder
334 "Message from" (or mh-sent-from-folder "+inbox") nil))
335 (number (tm-mh-e/prompt-for-message "Message number: " folder))
337 (tm-mh-e::make-message folder number)
341 ;;; by OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
342 ;;; 1995/11/14 (cf. [tm-ja:1099])
343 (defun tm-mh-e/forward (to cc &optional msg-or-seq)
344 "Forward a message or message sequence as MIME multipart/digest.
345 Defaults to displayed message. If optional prefix argument provided,
346 then prompt for the message sequence. See also documentation for
347 `\\[mh-send]' function."
350 (list (mh-read-address "To: ")
351 (mh-read-address "Cc: ")
352 (if current-prefix-arg
353 (mh-read-seq-default "Forward" t)
357 (setq msg-or-seq (mh-get-msg-num t)))
358 (if (numberp msg-or-seq)
359 (setq msg-or-seq (int-to-string msg-or-seq)))
360 (let* ((folder mh-current-folder)
361 (config (current-window-configuration))
362 ;; use "draft" for compatibility with forw.
363 ;; forw always leaves file in "draft" since it doesn't have -draft
364 (draft-name (expand-file-name "draft" mh-user-path))
365 (draft (cond ((or (not (file-exists-p draft-name))
366 (y-or-n-p "The file `draft' exists. Discard it? "))
367 (if tm-mh-e/use-forwcomps
369 "-noedit" "-nowhatnowproc"
370 "-form" tm-mh-e/forwcomps
373 "-noedit" "-nowhatnowproc"
377 (mh-read-draft "" draft-name t)
378 (mh-insert-fields "To:" to "Cc:" cc)
379 (set-buffer-modified-p nil)))
381 (mh-read-draft "" draft-name nil)))))
382 (let (orig-from orig-subject)
384 (goto-char (point-min))
387 (re-search-forward "^-*\n")
388 ;; modified by Katsumi Yamaoka <yamaoka@ga.sony.co.jp>
389 ;; 1995/11/17 (cf.[tm-ja:1116])
390 (and (< (point) (point-max))
391 (not (re-search-forward "^[\t ]*\n" nil t))
392 (goto-char (point-max))
394 (insert "--<<digest>>-{\n")
395 (mh-exec-cmd-output "pick" nil folder msg-or-seq)
396 (narrow-to-region (point) (mark t))
397 (while (re-search-forward "^\\([0-9]+\\)\n" nil t)
399 (buffer-substring (match-beginning 1) (match-end 1))))
400 (replace-match "--[[message/rfc822]]\n" nil nil)
401 (insert-file (mh-expand-file-name
402 forw-msg (mh-expand-file-name folder)))
403 (if (not (bolp)) (insert "\n"))
404 (mime-editor/inserted-message-filter))
405 (goto-char (mark t)))
406 (insert-string "--}-<<digest>>")))
407 (re-search-forward "^--\\[\\[message/rfc822\\]")
410 (narrow-to-region (point) (point-max))
411 (setq orig-from (mh-get-header-field "From:"))
412 (setq orig-subject (mh-get-header-field "Subject:")))
414 (mh-forwarded-letter-subject orig-from orig-subject)))
415 (mh-insert-fields "Subject:" forw-subject)
416 (goto-char (point-min))
417 (re-search-forward "^--\\[\\[message/rfc822\\]")
419 (delete-other-windows)
420 (if (numberp msg-or-seq)
421 (mh-add-msgs-to-seq msg-or-seq 'forwarded t)
422 (mh-add-msgs-to-seq (mh-seq-to-msgs msg-or-seq) 'forwarded t))
423 (mh-compose-and-send-mail draft "" folder msg-or-seq
425 mh-note-forw "Forwarded:"
429 (defun tm-mh-e/insert-message (&optional message)
431 (setq message (tm-mh-e/query-message))
433 (insert-file (tm-mh-e::message/file-name message))
434 (mime-editor/inserted-message-filter)
442 'mime-editor/message-inserter-alist
443 'mh-letter-mode (function tm-mh-e/insert-message))
445 'mime-editor/mail-inserter-alist
446 'mh-letter-mode (function tm-mh-e/insert-message))
448 'mime-editor/mail-inserter-alist
449 'news-reply-mode (function tm-mh-e/insert-message))
456 (substitute-key-definition
457 'mh-forward 'tm-mh-e/forward mh-folder-mode-map)
464 (define-key mh-folder-mode-map "v" (function tm-mh-e/view-message))
465 (define-key mh-folder-mode-map "\et" (function tm-mh-e/toggle-decoding-mode))
466 (define-key mh-folder-mode-map "." (function tm-mh-e/show))
467 (define-key mh-folder-mode-map "," (function tm-mh-e/header-display))
468 (define-key mh-folder-mode-map "\e," (function tm-mh-e/raw-display))
469 (define-key mh-folder-mode-map "\r"
472 (scroll-other-window 1)
474 (define-key mh-folder-mode-map "\e\r"
477 (scroll-other-window -1)
480 (defun tm-mh-e/summary-before-quit ()
481 (let ((buf (get-buffer mh-show-buffer)))
483 (let ((the-buf (current-buffer)))
484 (switch-to-buffer buf)
485 (if (and mime::article/preview-buffer
486 (setq buf (get-buffer mime::article/preview-buffer))
489 (switch-to-buffer the-buf)
492 (switch-to-buffer the-buf)
496 (add-hook 'mh-before-quit-hook (function tm-mh-e/summary-before-quit))
498 (set-alist 'mime-viewer/quitting-method-alist
500 (function tm-mh-e/quitting-method))
502 (set-alist 'mime-viewer/content-header-filter-alist
504 (function tm-mh-e/content-header-filter))
506 (set-alist 'mime-viewer/code-converter-alist
508 (function tm-mh-e/code-convert-region-to-emacs))
516 (run-hooks 'tm-mh-e-load-hook)