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 ;;; Keywords: mail, MH, MIME, multimedia, encoded-word, multilingual
11 ;;; This file is part of tm (Tools for MIME).
20 (if (not (boundp 'mh-e-version))
29 (defconst tm-mh-e/RCS-ID
30 "$Id: tm-mh-e.el,v 7.22 1995/11/16 10:20:53 morioka Exp $")
32 (defconst tm-mh-e/version (get-version-string tm-mh-e/RCS-ID))
38 (defvar tm-mh-e/automatic-mime-preview t
39 "If non-nil, show MIME processed message.")
41 (defvar tm-mh-e/decode-encoded-word t
42 "If non-nil, decode encoded-word when it is not MIME preview mode.")
48 (if (not (fboundp 'tm-mh-e/original-mh-display-msg))
49 (fset 'tm-mh-e/original-mh-display-msg
50 (symbol-function 'mh-display-msg))
53 (defun mh-display-msg (msg-num folder &optional show-buffer mode)
55 (setq mode tm-mh-e/automatic-mime-preview)
57 ;; Display message NUMBER of FOLDER.
58 ;; Sets the current buffer to the show buffer.
61 (setq show-buffer mh-show-buffer))
62 ;; Bind variables in folder buffer in case they are local
63 (let ((msg-filename (mh-msg-filename msg-num)))
64 (if (not (file-exists-p msg-filename))
65 (error "Message %d does not exist" msg-num))
66 (set-buffer show-buffer)
67 (cond ((not (equal msg-filename buffer-file-name))
68 ;; Buffer does not yet contain message.
69 (clear-visited-file-modtime)
71 (setq buffer-file-name nil) ; no locking during setup
72 (setq buffer-read-only nil)
75 (let* ((aname (concat "article-" folder))
76 (abuf (get-buffer aname))
81 (setq buffer-read-only nil)
84 (setq abuf (get-buffer-create aname))
87 (let ((file-coding-system-for-read
88 (if (boundp 'MULE) *noconv*))
90 (insert-file-contents msg-filename)
91 ;; (goto-char (point-min))
92 (while (re-search-forward "\r$" nil t)
96 (set-buffer-modified-p nil)
97 (setq buffer-read-only t)
99 (mime/viewer-mode nil nil nil
100 aname (concat "show-" folder))
101 (goto-char (point-min))
103 (let ((clean-message-header mh-clean-message-header)
104 (invisible-headers mh-invisible-headers)
105 (visible-headers mh-visible-headers)
108 ;; modified by ARIURA <ariura@cc.tuat.ac.jp>
111 (mh-exec-lib-cmd-output "mhl" "-nobell" "-noclear"
112 (if (stringp mhl-formfile)
113 (list "-form" mhl-formfile))
115 (insert-file-contents msg-filename))
117 (goto-char (point-min))
118 (cond (clean-message-header
119 (mh-clean-msg-header (point-min)
122 (goto-char (point-min)))
124 (mh-start-of-uncleaned-message)))
125 (if tm-mh-e/decode-encoded-word
126 (mime/decode-message-header)
128 (set-buffer-modified-p nil)
129 (setq buffer-read-only t)
132 (or (eq buffer-undo-list t) ;don't save undo info for prev msgs
133 (setq buffer-undo-list nil))
134 (setq buffer-file-name msg-filename)
136 (setq mode-line-buffer-identification
137 (list (format mh-show-buffer-mode-line-buffer-id
140 (setq mh-showing-with-headers nil)))))
142 (defun tm-mh-e/view-message (&optional msg)
143 "MIME decode and play this message."
145 (if (or (null tm-mh-e/automatic-mime-preview)
146 (null (get-buffer mh-show-buffer))
148 (set-buffer mh-show-buffer)
149 (not (eq major-mode 'mime/viewer-mode))
151 (let ((tm-mh-e/automatic-mime-preview t))
152 (mh-invalidate-show-buffer)
155 (pop-to-buffer mh-show-buffer)
158 (defun tm-mh-e/toggle-decoding-mode (arg)
159 "Toggle MIME processing mode.
160 With arg, turn MIME processing on if arg is positive."
162 (setq tm-mh-e/automatic-mime-preview
164 (not tm-mh-e/automatic-mime-preview)
167 (set-buffer mh-show-buffer)
168 (if (null tm-mh-e/automatic-mime-preview)
169 (if (and mime::preview/article-buffer
170 (get-buffer mime::preview/article-buffer))
171 (kill-buffer mime::preview/article-buffer)
173 (mh-invalidate-show-buffer)
174 (mh-show (mh-get-msg-num t))
177 (defun tm-mh-e/show (&optional message)
179 (mh-invalidate-show-buffer)
183 (defun tm-mh-e/header-display ()
185 (mh-invalidate-show-buffer)
186 (let (mime-viewer/ignored-field-list
187 tm-mh-e/decode-encoded-word)
191 (defun tm-mh-e/raw-display ()
193 (mh-invalidate-show-buffer)
194 (let (tm-mh-e/automatic-mime-preview
195 tm-mh-e/decode-encoded-word)
203 (fset 'tm-mh-e/code-convert-region-to-emacs
204 (symbol-function 'mime/code-convert-region-to-emacs))
206 (defun tm-mh-e/content-header-filter ()
207 (goto-char (point-min))
208 (while (and (re-search-forward mime-viewer/ignored-field-regexp nil t)
214 (re-search-forward "^\\([^ \t]\\|$\\)" nil t)
218 (tm-mh-e/code-convert-region-to-emacs (point-min)(point-max)
219 mime/default-coding-system)
220 (mime/decode-message-header)
221 (if (featurep 'hilit19)
222 (hilit-rehighlight-buffer-quietly)
226 (defun tm-mh-e/quitting-method ()
227 (let ((win (get-buffer-window
228 mime/output-buffer-name))
229 (buf (current-buffer))
235 (let ((name (buffer-name buf)))
238 (if (not tm-mh-e/automatic-mime-preview)
239 (mh-invalidate-show-buffer)
241 (mh-show (mh-get-msg-num t))
252 (set-atype 'mime/content-decoding-condition
253 '((type . "message/partial")
254 (method . mime-article/grab-message/partials)
255 (major-mode . mh-show-mode)
257 . (and (or (string-match "^article-\\(.+\\)$" article-buffer)
258 (string-match "^show-\\(.+\\)$" article-buffer))
259 (substring article-buffer
260 (match-beginning 1) (match-end 1))
263 (set-alist 'tm-partial/preview-article-method-alist
267 (let ((tm-mh-e/automatic-mime-preview t))
276 (defun tm-mh-e::make-message (folder number)
277 (vector folder number)
280 (defun tm-mh-e::message/folder (message)
284 (defun tm-mh-e::message/number (message)
288 (defun tm-mh-e::message/file-name (message)
290 (tm-mh-e::message/number message)
291 (mh-expand-file-name (tm-mh-e::message/folder message))
294 ;;; modified by OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
295 ;;; 1995/11/14 (c.f. [tm ML:1096])
296 (defun tm-mh-e/prompt-for-message (prompt folder &optional default)
298 (directory-files (mh-expand-file-name folder) nil "^[0-9]+$")
300 (folder-buf (get-buffer folder))
304 (set-buffer folder-buf)
305 (let ((show-buffer (get-buffer mh-show-buffer)))
307 (file-name-nondirectory
308 (buffer-file-name show-buffer))
310 (if (or (null default)
311 (not (string-match "^[0-9]+$" default)))
313 (if (string= folder mh-sent-from-folder)
314 (int-to-string mh-sent-from-msg)
317 (completing-read prompt
328 (defun tm-mh-e/query-message ()
329 (let* ((folder (mh-prompt-for-folder
330 "Message from" (or mh-sent-from-folder "+inbox") nil))
331 (number (tm-mh-e/prompt-for-message "Message number: " folder))
333 (tm-mh-e::make-message folder number)
337 ;;; by OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
338 ;;; 1995/11/14 (c.f. [tm ML:1099])
339 (defun tm-mh-e/forward (to cc &optional msg-or-seq)
340 "Forward a message or message sequence as MIME multipart/digest.
341 Defaults to displayed message. If optional prefix argument provided,
342 then prompt for the message sequence. See also documentation for
343 `\\[mh-send]' function."
346 (list (mh-read-address "To: ")
347 (mh-read-address "Cc: ")
348 (if current-prefix-arg
349 (mh-read-seq-default "Forward" t)
353 (setq msg-or-seq (mh-get-msg-num t)))
354 (if (numberp msg-or-seq)
355 (setq msg-or-seq (int-to-string msg-or-seq)))
356 (let* ((folder mh-current-folder)
357 (config (current-window-configuration))
358 ;; use "draft" for compatibility with forw.
359 ;; forw always leaves file in "draft" since it doesn't have -draft
360 (draft-name (expand-file-name "draft" mh-user-path))
361 (draft (cond ((or (not (file-exists-p draft-name))
362 (y-or-n-p "The file 'draft' exists. Discard it? "))
364 "-noedit" "-nowhatnowproc"
367 (mh-read-draft "" draft-name t)
368 (mh-insert-fields "To:" to "Cc:" cc)
369 (set-buffer-modified-p nil)))
371 (mh-read-draft "" draft-name nil)))))
372 (let (orig-from orig-subject)
374 (goto-char (point-min))
377 (re-search-forward "^-*\n")
378 (insert "--<<digest>>-{\n")
379 (mh-exec-cmd-output "pick" nil folder msg-or-seq)
380 (narrow-to-region (point) (mark t))
381 (while (re-search-forward "^\\([0-9]+\\)\n" nil t)
383 (buffer-substring (match-beginning 1) (match-end 1))))
384 (replace-match "--[[message/rfc822]]\n" nil nil)
385 (insert-file (mh-expand-file-name
386 forw-msg (mh-expand-file-name folder)))
387 (if (not (bolp)) (insert "\n"))
388 (mime-editor/inserted-message-filter))
389 (goto-char (mark t)))
390 (insert-string "--}-<<digest>>")))
391 (re-search-forward "^--\\[\\[message/rfc822\\]")
394 (narrow-to-region (point) (point-max))
395 (setq orig-from (mh-get-header-field "From:"))
396 (setq orig-subject (mh-get-header-field "Subject:")))
398 (mh-forwarded-letter-subject orig-from orig-subject)))
399 (mh-insert-fields "Subject:" forw-subject)
400 (goto-char (point-min))
401 (re-search-forward "^--\\[\\[message/rfc822\\]")
403 (delete-other-windows)
404 (if (numberp msg-or-seq)
405 (mh-add-msgs-to-seq msg-or-seq 'forwarded t)
406 (mh-add-msgs-to-seq (mh-seq-to-msgs msg-or-seq) 'forwarded t))
407 (mh-compose-and-send-mail draft "" folder msg-or-seq
409 mh-note-forw "Forwarded:"
413 (defun tm-mh-e/insert-message (&optional message)
415 (setq message (tm-mh-e/query-message))
417 (insert-file (tm-mh-e::message/file-name message))
418 (mime-editor/inserted-message-filter)
426 'mime-editor/message-inserter-alist
427 'mh-letter-mode (function tm-mh-e/insert-message))
429 'mime-editor/mail-inserter-alist
430 'mh-letter-mode (function tm-mh-e/insert-message))
432 'mime-editor/mail-inserter-alist
433 'news-reply-mode (function tm-mh-e/insert-message))
439 (substitute-key-definition
440 'mh-forward 'tm-mh-e/forward mh-folder-mode-map)
447 (define-key mh-folder-mode-map "v" (function tm-mh-e/view-message))
448 (define-key mh-folder-mode-map "\et" (function tm-mh-e/toggle-decoding-mode))
449 (define-key mh-folder-mode-map "." (function tm-mh-e/show))
450 (define-key mh-folder-mode-map "," (function tm-mh-e/header-display))
451 (define-key mh-folder-mode-map "\e," (function tm-mh-e/raw-display))
452 (define-key mh-folder-mode-map "\r"
455 (scroll-other-window 1)
457 (define-key mh-folder-mode-map "\e\r"
460 (scroll-other-window -1)
463 (defun tm-mh-e/summary-before-quit ()
464 (let ((buf (get-buffer mh-show-buffer)))
466 (let ((the-buf (current-buffer)))
467 (switch-to-buffer buf)
468 (if (and mime::article/preview-buffer
469 (setq buf (get-buffer mime::article/preview-buffer))
472 (switch-to-buffer the-buf)
475 (switch-to-buffer the-buf)
479 (add-hook 'mh-before-quit-hook (function tm-mh-e/summary-before-quit))
481 (set-alist 'mime-viewer/quitting-method-alist
483 (function tm-mh-e/quitting-method))
485 (set-alist 'mime-viewer/content-header-filter-alist
487 (function tm-mh-e/content-header-filter))
489 (set-alist 'mime-viewer/code-converter-alist
491 (function tm-mh-e/code-convert-region-to-emacs))
499 (run-hooks 'tm-mh-e-load-hook)