;;; ;;; tm-mh-e.el --- MIME extender for mh-e ;;; ;;; Copyright (C) 1995 Free Software Foundation, Inc. ;;; Copyright (C) 1993,1994,1995 MORIOKA Tomohiko ;;; ;;; Author: MORIOKA Tomohiko ;;; Keywords: mail, MH, MIME, multimedia, encoded-word, multilingual ;;; ;;; This file is part of tm (Tools for MIME). ;;; ;;; @ require modules ;;; (require 'tl-str) (require 'tl-misc) (require 'mh-e) (if (not (boundp 'mh-e-version)) (require 'tm-mh-e3) ) (require 'tm-view) ;;; @ version ;;; (defconst tm-mh-e/RCS-ID "$Id: tm-mh-e.el,v 7.3 1995/10/13 08:15:17 morioka Exp $") (defconst tm-mh-e/version (get-version-string tm-mh-e/RCS-ID)) ;;; @ variable ;;; (defvar tm-mh-e/decode-all t "*If t, decode all of the message. Otherwise decode header only.") ;;; @ functions ;;; (if (not (fboundp 'tm-mh-e/original-mh-display-msg)) (fset 'tm-mh-e/original-mh-display-msg (symbol-function 'mh-display-msg)) ) (defun mh-display-msg (msg-num folder &optional show-buffer mode) (or mode (setq mode tm-mh-e/decode-all) ) ;; Display message NUMBER of FOLDER. ;; Sets the current buffer to the show buffer. (set-buffer folder) (or show-buffer (setq show-buffer mh-show-buffer)) ;; Bind variables in folder buffer in case they are local (let ((msg-filename (mh-msg-filename msg-num))) (if (not (file-exists-p msg-filename)) (error "Message %d does not exist" msg-num)) (set-buffer show-buffer) (cond ((not (equal msg-filename buffer-file-name)) ;; Buffer does not yet contain message. (clear-visited-file-modtime) (unlock-buffer) (setq buffer-file-name nil) ; no locking during setup (setq buffer-read-only nil) (erase-buffer) (if mode (let* ((aname (concat "article-" folder)) (abuf (get-buffer aname)) ) (if abuf (progn (set-buffer abuf) (setq buffer-read-only nil) (erase-buffer) ) (setq abuf (get-buffer-create aname)) (set-buffer abuf) ) (let ((file-coding-system-for-read (if (boundp 'MULE) *noconv*)) kanji-fileio-code) (insert-file-contents msg-filename) ;; (goto-char (point-min)) (while (re-search-forward "\r$" nil t) (replace-match "") ) ) (set-buffer-modified-p nil) (setq buffer-read-only t) (mh-show-mode) (mime/viewer-mode nil nil nil aname (concat "show-" folder)) (goto-char (point-min)) ) (let ((clean-message-header mh-clean-message-header) (invisible-headers mh-invisible-headers) (visible-headers mh-visible-headers) ) ;; 1995/9/21 ;; modified by ARIURA ;; to support mhl. (if mhl-formfile (mh-exec-lib-cmd-output "mhl" "-nobell" "-noclear" (if (stringp mhl-formfile) (list "-form" mhl-formfile)) msg-filename) (insert-file-contents msg-filename)) ;; end (goto-char (point-min)) (cond (clean-message-header (mh-clean-msg-header (point-min) invisible-headers visible-headers) (goto-char (point-min))) (t (mh-start-of-uncleaned-message))) (mime/decode-message-header) (set-buffer-modified-p nil) (setq buffer-read-only t) (mh-show-mode) )) (or (eq buffer-undo-list t) ;don't save undo info for prev msgs (setq buffer-undo-list nil)) (setq buffer-file-name msg-filename) (set-mark nil) (setq mode-line-buffer-identification (list (format mh-show-buffer-mode-line-buffer-id folder msg-num))) (set-buffer folder) (setq mh-showing-with-headers nil))))) (defun tm-mh-e/view-message (&optional msg) "MIME decode and play this message." (interactive) (if (null tm-mh-e/decode-all) (let ((tm-mh-e/decode-all t)) (mh-invalidate-show-buffer) (mh-show-msg msg) )) (pop-to-buffer mh-show-buffer) ) (defun tm-mh-e/toggle-decoding-mode (arg) "Toggle MIME processing mode. With arg, turn MIME processing on if arg is positive." (interactive "P") (setq tm-mh-e/decode-all (if (null arg) (not tm-mh-e/decode-all) arg)) (save-excursion (set-buffer mh-show-buffer) (if (null tm-mh-e/decode-all) (if (and mime::preview/article-buffer (get-buffer mime::preview/article-buffer)) (kill-buffer mime::preview/article-buffer) ))) (mh-invalidate-show-buffer) (mh-show (mh-get-msg-num t)) ) (defun tm-mh-e/header-display () (interactive) (if tm-mh-e/decode-all (let ((win (selected-window))) (pop-to-buffer mh-show-buffer) (switch-to-buffer mime::preview/article-buffer) (goto-char (point-min)) (select-window win) ) (mh-header-display) )) ;;; @ for tm-view ;;; (fset 'tm-mh-e/code-convert-region-to-emacs (symbol-function 'mime/code-convert-region-to-emacs)) (defun tm-mh-e/content-header-filter () (goto-char (point-min)) (while (and (re-search-forward mime-viewer/ignored-field-regexp nil t) (progn (delete-region (match-beginning 0) (save-excursion (and (re-search-forward "^\\([^ \t]\\|$\\)" nil t) (match-beginning 0) ))) t))) (tm-mh-e/code-convert-region-to-emacs (point-min)(point-max) mime/default-coding-system) (mime/decode-message-header) (if (featurep 'hilit19) (hilit-rehighlight-buffer-quietly) ) ) (defun tm-mh-e/quitting-method () (let ((win (get-buffer-window mime/output-buffer-name)) (buf (current-buffer)) ) (if win (delete-window win) ) (pop-to-buffer (let ((name (buffer-name buf))) (substring name 5) )) (if (not tm-mh-e/decode-all) (mh-invalidate-show-buffer) ) (mh-show (mh-get-msg-num t)) )) ;;; @ for tm-comp ;;; (defun tm-mh-e::make-message (folder number) (vector folder number) ) (defun tm-mh-e::message/folder (message) (elt message 0) ) (defun tm-mh-e::message/number (message) (elt message 1) ) (defun tm-mh-e::message/file-name (message) (expand-file-name (tm-mh-e::message/number message) (mh-expand-file-name (tm-mh-e::message/folder message)) )) (defun tm-mh-e::prompt-for-message (prompt folder &optional default) (let ((files (directory-files (mh-expand-file-name folder) nil "^[0-9]+$") )) (completing-read prompt (let ((i 0)) (mapcar (function (lambda (file) (setq i (+ i 1)) (list file i) )) files) )) )) (defun tm-mh-e::query-message () (let* ((folder (mh-prompt-for-folder "Visit" "+inbox" nil)) (number (tm-mh-e::prompt-for-message "Number?" folder)) ) (tm-mh-e::make-message folder number) )) (defun tm-mh-e::insert-message (&optional message) (if (null message) (setq message (tm-mh-e::query-message)) ) (insert-file (tm-mh-e::message/file-name message)) ) (call-after-loaded 'tm-comp (function (lambda () (set-alist 'tm-comp/message-inserter-alist 'mh-letter-mode (function tm-mh-e::insert-message)) ))) ;;; @ set up ;;; (define-key mh-folder-mode-map "v" (function tm-mh-e/view-message)) (define-key mh-folder-mode-map "\et" (function tm-mh-e/toggle-decoding-mode)) (define-key mh-folder-mode-map "," (function tm-mh-e/header-display)) (define-key mh-folder-mode-map "\r" (function (lambda () (interactive) (scroll-other-window 1) ))) (define-key mh-folder-mode-map "\e\r" (function (lambda () (interactive) (scroll-other-window -1) ))) (defun tm-mh-e/summary-before-quit () (let ((buf (get-buffer mh-show-buffer))) (if buf (let ((the-buf (current-buffer))) (switch-to-buffer buf) (if (and mime::article/preview-buffer (setq buf (get-buffer mime::article/preview-buffer)) ) (progn (switch-to-buffer the-buf) (kill-buffer buf) ) (switch-to-buffer the-buf) ) )))) (add-hook 'mh-before-quit-hook (function tm-mh-e/summary-before-quit)) (set-alist 'mime-viewer/quitting-method-alist 'mh-show-mode (function tm-mh-e/quitting-method)) (set-alist 'mime-viewer/content-header-filter-alist 'mh-show-mode (function tm-mh-e/content-header-filter)) (set-alist 'mime-viewer/code-converter-alist 'mh-show-mode (function tm-mh-e/code-convert-region-to-emacs)) ;;; @ end ;;; (provide 'tm-mh-e) (run-hooks 'tm-mh-e-load-hook)