1 ;;; mime-view.el --- interactive MIME viewer for GNU Emacs
3 ;; Copyright (C) 1995,1996,1997,1998 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;; Renamed: 1994/8/31 from tm-body.el
8 ;; Renamed: 1997/02/19 from tm-view.el
9 ;; Keywords: MIME, multimedia, mail, news
11 ;; This file is part of SEMI (Sophisticated Emacs MIME Interfaces).
13 ;; This program is free software; you can redistribute it and/or
14 ;; modify it under the terms of the GNU General Public License as
15 ;; published by the Free Software Foundation; either version 2, or (at
16 ;; your option) any later version.
18 ;; This program is distributed in the hope that it will be useful, but
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 ;; General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 ;; Boston, MA 02111-1307, USA.
32 (require 'eword-decode)
41 (defconst mime-view-version-string
42 `,(concat "SEMI MIME-View "
43 (mapconcat #'number-to-string (cdr semi-version) ".")
44 " (" (car semi-version) ")"))
47 ;;; @ buffer local variables
53 (defvar mime-raw-message-info
54 "Information about structure of message.
55 Please use reference function `mime-entity-SLOT' to get value of SLOT.
57 Following is a list of slots of the structure:
59 node-id reversed entity-number (list of integers)
60 point-min beginning point of region in raw-buffer
61 point-max end point of region in raw-buffer
62 type media-type (symbol)
63 subtype media-subtype (symbol)
64 type/subtype media-type/subtype (string or nil)
65 parameters parameter of Content-Type field (association list)
66 encoding Content-Transfer-Encoding (string or nil)
67 children entities included in this entity (list of content-infos)
69 If an entity includes other entities in its body, such as multipart or
70 message/rfc822, `mime-entity' structures of them are included in
71 `children', so the `mime-entity' structure become a tree.")
72 (make-variable-buffer-local 'mime-raw-message-info)
74 (defvar mime-preview-buffer nil
75 "MIME-preview buffer corresponding with the (raw) buffer.")
76 (make-variable-buffer-local 'mime-preview-buffer)
79 ;;; @@ in preview-buffer
82 (defvar mime-mother-buffer nil
83 "Mother buffer corresponding with the (MIME-preview) buffer.
84 If current MIME-preview buffer is generated by other buffer, such as
85 message/partial, it is called `mother-buffer'.")
86 (make-variable-buffer-local 'mime-mother-buffer)
88 (defvar mime-raw-buffer nil
89 "Raw buffer corresponding with the (MIME-preview) buffer.")
90 (make-variable-buffer-local 'mime-raw-buffer)
92 (defvar mime-preview-original-major-mode nil
93 "Major-mode of mime-raw-buffer.")
94 (make-variable-buffer-local 'mime-preview-original-major-mode)
96 (defvar mime-preview-original-window-configuration nil
97 "Window-configuration before mime-view-mode is called.")
98 (make-variable-buffer-local 'mime-preview-original-window-configuration)
101 ;;; @ entity information
104 (defsubst mime-raw-find-entity-from-node-id (entity-node-id
105 &optional message-info)
106 "Return entity from ENTITY-NODE-ID in mime-raw-buffer.
107 If optional argument MESSAGE-INFO is not specified,
108 `mime-raw-message-info' is used."
109 (mime-raw-find-entity-from-number (reverse entity-node-id) message-info))
111 (defun mime-raw-find-entity-from-number (entity-number &optional message-info)
112 "Return entity from ENTITY-NUMBER in mime-raw-buffer.
113 If optional argument MESSAGE-INFO is not specified,
114 `mime-raw-message-info' is used."
116 (setq message-info mime-raw-message-info))
117 (if (eq entity-number t)
119 (let ((sn (car entity-number)))
122 (let ((rc (nth sn (mime-entity-children message-info))))
124 (mime-raw-find-entity-from-number (cdr entity-number) rc)
128 (defun mime-raw-find-entity-from-point (point &optional message-info)
129 "Return entity from POINT in mime-raw-buffer.
130 If optional argument MESSAGE-INFO is not specified,
131 `mime-raw-message-info' is used."
133 (setq message-info mime-raw-message-info))
134 (if (and (<= (mime-entity-point-min message-info) point)
135 (<= point (mime-entity-point-max message-info)))
136 (let ((children (mime-entity-children message-info)))
140 (mime-raw-find-entity-from-point point (car children))))
144 (setq children (cdr children)))
147 (defsubst mime-raw-point-to-entity-node-id (point &optional message-info)
148 "Return entity-node-id from POINT in mime-raw-buffer.
149 If optional argument MESSAGE-INFO is not specified,
150 `mime-raw-message-info' is used."
151 (mime-entity-node-id (mime-raw-find-entity-from-point point message-info)))
153 (defsubst mime-raw-point-to-entity-number (point &optional message-info)
154 "Return entity-number from POINT in mime-raw-buffer.
155 If optional argument MESSAGE-INFO is not specified,
156 `mime-raw-message-info' is used."
157 (reverse (mime-raw-point-to-entity-node-id point message-info)))
159 (defsubst mime-raw-entity-parent (entity &optional message-info)
160 "Return mother entity of ENTITY.
161 If optional argument MESSAGE-INFO is not specified,
162 `mime-raw-message-info' is used."
163 (mime-raw-find-entity-from-node-id (cdr (mime-entity-node-id entity))
166 (defun mime-raw-flatten-message-info (&optional message-info)
167 "Return list of entity in mime-raw-buffer.
168 If optional argument MESSAGE-INFO is not specified,
169 `mime-raw-message-info' is used."
171 (setq message-info mime-raw-message-info))
172 (let ((dest (list message-info))
173 (rcl (mime-entity-children message-info)))
175 (setq dest (nconc dest (mime-raw-flatten-message-info (car rcl))))
176 (setq rcl (cdr rcl)))
180 ;;; @ presentation of preview
186 ;;; @@@ predicate function
189 (defvar mime-view-content-button-visible-ctype-list
190 '("application/pgp"))
192 (defun mime-view-entity-button-visible-p (entity message-info)
193 "Return non-nil if header of ENTITY is visible.
194 Please redefine this function if you want to change default setting."
195 (and (not (mime-root-entity-p entity))
196 (let ((media-type (mime-entity-media-type entity))
197 (media-subtype (mime-entity-media-subtype entity)))
198 (or (not (eq media-type 'application))
199 (and (not (eq media-subtype 'x-selection))
200 (or (not (eq media-subtype 'octet-stream))
202 (mime-raw-entity-parent entity message-info)))
203 (or (not (eq (mime-entity-media-type mother-entity)
205 (not (eq (mime-entity-media-subtype mother-entity)
210 ;;; @@@ entity button generator
213 (defun mime-view-insert-entity-button (entity message-info subj)
214 "Insert entity-button of ENTITY."
215 (let ((entity-node-id (mime-entity-node-id entity))
216 (params (mime-entity-parameters entity)))
218 (let ((access-type (assoc "access-type" params))
219 (num (or (cdr (assoc "x-part-number" params))
220 (if (consp entity-node-id)
223 (format "%s" (1+ num))
225 (reverse entity-node-id) ".")
229 (let ((server (assoc "server" params)))
230 (setq access-type (cdr access-type))
232 (format "%s %s ([%s] %s)"
233 num subj access-type (cdr server))
234 (let ((site (cdr (assoc "site" params)))
235 (dir (cdr (assoc "directory" params)))
237 (format "%s %s ([%s] %s:%s)"
238 num subj access-type site dir)
242 (let ((media-type (mime-entity-media-type entity))
243 (media-subtype (mime-entity-media-subtype entity))
244 (charset (cdr (assoc "charset" params)))
245 (encoding (mime-entity-encoding entity)))
249 (format " <%s/%s%s%s>"
250 media-type media-subtype
252 (concat "; " charset)
255 (concat " (" encoding ")")
257 (if (>= (+ (current-column)(length rest))(window-width))
261 (function mime-preview-play-current-entity))
268 ;;; @@@ predicate function
271 (defvar mime-view-childrens-header-showing-Content-Type-list
272 '("message/rfc822" "message/news"))
274 (defun mime-view-header-visible-p (entity message-info)
275 "Return non-nil if header of ENTITY is visible."
276 (let ((entity-node-id (mime-entity-node-id entity)))
277 (or (null entity-node-id)
278 (member (mime-entity-type/subtype
279 (mime-raw-find-entity-from-node-id
280 (cdr entity-node-id) message-info))
281 mime-view-childrens-header-showing-Content-Type-list)
284 ;;; @@@ entity header filter
287 (defvar mime-view-content-header-filter-alist nil)
289 (defun mime-view-default-content-header-filter ()
290 (mime-view-cut-header)
291 (eword-decode-header)
294 (defun mime-view-display-header (beg end)
296 (narrow-to-region (point)(point))
297 (insert-buffer-substring mime-raw-buffer beg end)
298 (let ((f (cdr (assq mime-preview-original-major-mode
299 mime-view-content-header-filter-alist))))
302 (mime-view-default-content-header-filter)
304 (run-hooks 'mime-view-content-header-filter-hook)
307 ;;; @@@ entity field cutter
310 (defvar mime-view-ignored-field-list
311 '(".*Received" ".*Path" ".*Id" "References"
312 "Replied" "Errors-To"
313 "Lines" "Sender" ".*Host" "Xref"
314 "Content-Type" "Precedence"
316 "All fields that match this list will be hidden in MIME preview buffer.
317 Each elements are regexp of field-name.")
319 (defvar mime-view-ignored-field-regexp
321 (apply (function regexp-or) mime-view-ignored-field-list)
324 (defvar mime-view-visible-field-list '("Dnas.*" "Message-Id")
325 "All fields that match this list will be displayed in MIME preview buffer.
326 Each elements are regexp of field-name.")
328 (defun mime-view-cut-header ()
329 (goto-char (point-min))
330 (while (re-search-forward mime-view-ignored-field-regexp nil t)
331 (let* ((beg (match-beginning 0))
333 (name (buffer-substring beg end))
336 (let ((rest mime-view-visible-field-list))
338 (if (string-match (car rest) name)
341 (setq rest (cdr rest))))
344 (if (re-search-forward "^\\([^ \t]\\|$\\)" nil t)
353 ;;; @@@ predicate function
356 (defvar mime-view-body-visible-condition
367 (octet-stream encoding
377 "Condition-tree to be able to display body of entity.")
379 (defun mime-view-body-visible-p (entity message-info)
380 "Return non-nil if body of ENTITY is visible."
382 mime-view-body-visible-condition
383 (list* (cons 'type (mime-entity-media-type entity))
384 (cons 'subtype (mime-entity-media-subtype entity))
385 (cons 'encoding (mime-entity-encoding entity))
386 (cons 'major-mode major-mode)
387 (mime-entity-parameters entity))))
390 ;;; @@@ entity filter
393 (defvar mime-view-content-filter-alist
394 '(("text/enriched" . mime-view-filter-for-text/enriched)
395 ("text/richtext" . mime-view-filter-for-text/richtext)
396 (t . mime-view-filter-for-text/plain)
398 "Alist of media-types vs. corresponding MIME-preview filter functions.
399 Each element looks like (TYPE/SUBTYPE . FUNCTION) or (t . FUNCTION).
400 TYPE/SUBTYPE is a string of media-type and FUNCTION is a filter
401 function. t means default media-type.")
403 (defun mime-view-display-body (start end entity message-info subj)
405 (narrow-to-region (point-max)(point-max))
406 (insert-buffer-substring mime-raw-buffer start end)
407 (let* ((ctype (mime-entity-type/subtype entity))
408 (params (mime-entity-parameters entity))
409 (encoding (mime-entity-encoding entity))
410 (f (cdr (or (assoc ctype mime-view-content-filter-alist)
411 (assq t mime-view-content-filter-alist)))))
413 (funcall f ctype params encoding))
416 (defvar mime-view-announcement-for-message/partial
417 (if (and (>= emacs-major-version 19) window-system)
419 \[[ This is message/partial style split message. ]]
420 \[[ Please press `v' key in this buffer ]]
421 \[[ or click here by mouse button-2. ]]"
423 \[[ This is message/partial style split message. ]]
424 \[[ Please press `v' key in this buffer. ]]"
427 (defun mime-view-insert-message/partial-button ()
429 (goto-char (point-max))
430 (if (not (search-backward "\n\n" nil t))
433 (goto-char (point-max))
434 (narrow-to-region (point-max)(point-max))
435 (insert mime-view-announcement-for-message/partial)
436 (mime-add-button (point-min)(point-max)
437 #'mime-preview-play-current-entity)
441 ;;; @@ entity separator
444 (defun mime-view-entity-separator-function (entity message-info)
445 "Insert entity-separator of ENTITY conditionally.
446 Please redefine this function if you want to change default setting."
447 (or (mime-view-header-visible-p entity message-info)
448 (mime-view-body-visible-p entity message-info)
450 (goto-char (point-max))
455 ;;; @ acting-condition
458 (defvar mime-acting-condition
459 '(((type . text)(subtype . plain)
460 (method "tm-plain" nil 'file "" 'encoding 'mode 'name)
461 (mode "play" "print")
463 ((type . text)(subtype . html)
464 (method "tm-html" nil 'file "" 'encoding 'mode 'name)
467 ((type . text)(subtype . x-rot13-47)
468 (method . mime-method-to-display-caesar)
471 ((type . text)(subtype . x-rot13-47-48)
472 (method . mime-method-to-display-caesar)
476 ((type . audio)(subtype . basic)
477 (method "tm-au" nil 'file "" 'encoding 'mode 'name)
482 (method "tm-image" nil 'file "" 'encoding 'mode 'name)
483 (mode "play" "print")
486 ((type . video)(subtype . mpeg)
487 (method "tm-mpeg" nil 'file "" 'encoding 'mode 'name)
491 ((type . application)(subtype . postscript)
492 (method "tm-ps" nil 'file "" 'encoding 'mode 'name)
493 (mode "play" "print")
495 ((type . application)(subtype . octet-stream)
496 (method . mime-method-to-save)(mode "play" "print")
499 ((type . message)(subtype . external-body)
500 ("access-type" . "anon-ftp")
501 (method . mime-method-to-display-message/external-ftp)
503 ((type . message)(subtype . rfc822)
504 (method . mime-method-to-display-message/rfc822)
507 ((type . message)(subtype . partial)
508 (method . mime-method-to-store-message/partial)
512 ((method "metamail" t "-m" "tm" "-x" "-d" "-z" "-e" 'file)
515 ((method . mime-method-to-save)(mode . "extract"))
519 ;;; @ quitting method
522 (defvar mime-preview-quitting-method-alist
523 '((mime-show-message-mode
524 . mime-preview-quitting-method-for-mime-show-message-mode))
525 "Alist of major-mode vs. quitting-method of mime-view.")
527 (defvar mime-view-over-to-previous-method-alist nil)
528 (defvar mime-view-over-to-next-method-alist nil)
530 (defvar mime-view-show-summary-method nil
531 "Alist of major-mode vs. show-summary-method.")
534 ;;; @ following method
537 (defvar mime-view-following-method-alist nil
538 "Alist of major-mode vs. following-method of mime-view.")
540 (defvar mime-view-following-required-fields-list
547 ;; hack from Gnus 5.0.4.
549 (defvar mime-view-x-face-to-pbm-command
550 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm")
552 (defvar mime-view-x-face-command
553 (concat mime-view-x-face-to-pbm-command
555 "String to be executed to display an X-Face field.
556 The command will be executed in a sub-shell asynchronously.
557 The compressed face will be piped to this command.")
559 (defun mime-view-x-face-function ()
560 "Function to display X-Face field. You can redefine to customize."
561 ;; 1995/10/12 (c.f. tm-eng:130)
562 ;; fixed by Eric Ding <ericding@San-Jose.ate.slb.com>
564 (narrow-to-region (point-min) (re-search-forward "^$" nil t))
566 (goto-char (point-min))
567 (if (re-search-forward "^X-Face:[ \t]*" nil t)
568 (let ((beg (match-end 0))
569 (end (std11-field-end))
571 (call-process-region beg end "sh" nil 0 nil
572 "-c" mime-view-x-face-command)
579 (defvar mime-view-uuencode-encoding-name-list '("x-uue" "x-uuencode"))
581 (defvar mime-raw-buffer-coding-system-alist
582 `((t . ,(mime-charset-to-coding-system default-mime-charset)))
583 "Alist of major-mode vs. corresponding coding-system of `mime-raw-buffer'.")
589 (defvar mime-view-redisplay nil)
591 (defun mime-view-setup-buffers (&optional ctl encoding ibuf obuf)
597 (or mime-view-redisplay
598 (setq mime-raw-message-info (mime-parse-message ctl encoding))
600 (let* ((message-info mime-raw-message-info)
601 (pcl (mime-raw-flatten-message-info message-info))
602 (the-buf (current-buffer))
606 (setq obuf (concat "*Preview-" (buffer-name the-buf) "*")))
607 (set-buffer (get-buffer-create obuf))
608 (let ((inhibit-read-only t))
609 ;;(setq buffer-read-only nil)
612 (setq mime-raw-buffer the-buf)
613 (setq mime-preview-original-major-mode mode)
614 (setq major-mode 'mime-view-mode)
615 (setq mode-name "MIME-View")
617 (mime-view-display-entity (car pcl) message-info the-buf obuf)
620 (set-buffer-modified-p nil)
622 (setq buffer-read-only t)
625 (setq mime-preview-buffer obuf)
628 (defun mime-view-display-entity (entity message-info ibuf obuf)
630 (let* ((beg (mime-entity-point-min entity))
631 (end (mime-entity-point-max entity))
632 (media-type (mime-entity-media-type entity))
633 (media-subtype (mime-entity-media-subtype entity))
634 (ctype (if media-type
636 (format "%s/%s" media-type media-subtype)
637 (symbol-name media-type)
639 (params (mime-entity-parameters entity))
640 (encoding (mime-entity-encoding entity))
641 (entity-node-id (mime-entity-node-id entity))
645 (setq he (if (re-search-forward "^$" nil t)
652 (narrow-to-region beg end)
655 (mime-raw-get-subject params encoding)))
659 (narrow-to-region nb nb)
660 (if (mime-view-entity-button-visible-p entity message-info)
661 (mime-view-insert-entity-button entity message-info subj)
663 (if (mime-view-header-visible-p entity message-info)
664 (mime-view-display-header beg he)
666 (if (and (mime-root-entity-p entity)
668 ctype mime-view-content-button-visible-ctype-list))
670 (goto-char (point-max))
671 (mime-view-insert-entity-button entity message-info subj)
673 (cond ((mime-view-body-visible-p entity message-info)
674 (mime-view-display-body he end entity message-info subj)
676 ((and (eq media-type 'message)(eq media-subtype 'partial))
677 (mime-view-insert-message/partial-button)
679 ((and (null entity-node-id)
680 (null (mime-entity-children message-info))
682 (goto-char (point-max))
683 (mime-view-insert-entity-button entity message-info subj)
685 (mime-view-entity-separator-function entity message-info)
686 (setq ne (point-max))
688 (put-text-property nb ne 'mime-view-raw-buffer ibuf)
689 (put-text-property nb ne 'mime-view-entity entity)
693 (defun mime-raw-get-uu-filename (param &optional encoding)
694 (if (member (or encoding
695 (cdr (assq 'encoding param))
697 mime-view-uuencode-encoding-name-list)
699 (or (if (re-search-forward "^begin [0-9]+ " nil t)
700 (if (looking-at ".+$")
701 (buffer-substring (match-beginning 0)(match-end 0))
706 (defun mime-raw-get-subject (param &optional encoding)
707 (or (std11-find-field-body '("Content-Description" "Subject"))
709 (if (or (and (setq ret (mime/Content-Disposition))
710 (setq ret (assoc "filename" (cdr ret)))
712 (setq ret (assoc "name" param))
713 (setq ret (assoc "x-name" param))
715 (std11-strip-quoted-string (cdr ret))
717 (mime-raw-get-uu-filename param encoding)
721 ;;; @ MIME viewer mode
724 (defconst mime-view-menu-title "MIME-View")
725 (defconst mime-view-menu-list
726 '((up "Move to upper entity" mime-preview-move-to-upper)
727 (previous "Move to previous entity" mime-preview-move-to-previous)
728 (next "Move to next entity" mime-preview-move-to-next)
729 (scroll-down "Scroll-down" mime-preview-scroll-down-entity)
730 (scroll-up "Scroll-up" mime-preview-scroll-up-entity)
731 (play "Play current entity" mime-preview-play-current-entity)
732 (extract "Extract current entity" mime-preview-extract-current-entity)
733 (print "Print current entity" mime-preview-print-current-entity)
734 (x-face "Show X Face" mime-preview-display-x-face)
736 "Menu for MIME Viewer")
738 (cond (running-xemacs
739 (defvar mime-view-xemacs-popup-menu
740 (cons mime-view-menu-title
743 (vector (nth 1 item)(nth 2 item) t)
745 mime-view-menu-list)))
746 (defun mime-view-xemacs-popup-menu (event)
747 "Popup the menu in the MIME Viewer buffer"
749 (select-window (event-window event))
750 (set-buffer (event-buffer event))
751 (popup-menu 'mime-view-xemacs-popup-menu))
752 (defvar mouse-button-2 'button2)
755 (defvar mouse-button-2 [mouse-2])
758 (defun mime-view-define-keymap (&optional default)
759 (let ((mime-view-mode-map (if (keymapp default)
760 (copy-keymap default)
763 (define-key mime-view-mode-map
764 "u" (function mime-preview-move-to-upper))
765 (define-key mime-view-mode-map
766 "p" (function mime-preview-move-to-previous))
767 (define-key mime-view-mode-map
768 "n" (function mime-preview-move-to-next))
769 (define-key mime-view-mode-map
770 "\e\t" (function mime-preview-move-to-previous))
771 (define-key mime-view-mode-map
772 "\t" (function mime-preview-move-to-next))
773 (define-key mime-view-mode-map
774 " " (function mime-preview-scroll-up-entity))
775 (define-key mime-view-mode-map
776 "\M- " (function mime-preview-scroll-down-entity))
777 (define-key mime-view-mode-map
778 "\177" (function mime-preview-scroll-down-entity))
779 (define-key mime-view-mode-map
780 "\C-m" (function mime-preview-next-line-entity))
781 (define-key mime-view-mode-map
782 "\C-\M-m" (function mime-preview-previous-line-entity))
783 (define-key mime-view-mode-map
784 "v" (function mime-preview-play-current-entity))
785 (define-key mime-view-mode-map
786 "e" (function mime-preview-extract-current-entity))
787 (define-key mime-view-mode-map
788 "\C-c\C-p" (function mime-preview-print-current-entity))
789 (define-key mime-view-mode-map
790 "a" (function mime-preview-follow-current-entity))
791 (define-key mime-view-mode-map
792 "q" (function mime-preview-quit))
793 (define-key mime-view-mode-map
794 "h" (function mime-preview-show-summary))
795 (define-key mime-view-mode-map
796 "\C-c\C-x" (function mime-preview-kill-buffer))
797 ;; (define-key mime-view-mode-map
798 ;; "<" (function beginning-of-buffer))
799 ;; (define-key mime-view-mode-map
800 ;; ">" (function end-of-buffer))
801 (define-key mime-view-mode-map
802 "?" (function describe-mode))
803 (define-key mime-view-mode-map
804 [tab] (function mime-preview-move-to-next))
805 (define-key mime-view-mode-map
806 [delete] (function mime-preview-scroll-down-entity))
807 (define-key mime-view-mode-map
808 [backspace] (function mime-preview-scroll-down-entity))
809 (if (functionp default)
810 (cond (running-xemacs
811 (set-keymap-default-binding mime-view-mode-map default)
814 (setq mime-view-mode-map
815 (append mime-view-mode-map (list (cons t default))))
818 (define-key mime-view-mode-map
819 mouse-button-2 (function mime-button-dispatcher))
821 (cond (running-xemacs
822 (define-key mime-view-mode-map
823 mouse-button-3 (function mime-view-xemacs-popup-menu))
825 ((>= emacs-major-version 19)
826 (define-key mime-view-mode-map [menu-bar mime-view]
827 (cons mime-view-menu-title
828 (make-sparse-keymap mime-view-menu-title)))
831 (define-key mime-view-mode-map
832 (vector 'menu-bar 'mime-view (car item))
833 (cons (nth 1 item)(nth 2 item))
836 (reverse mime-view-menu-list)
839 (use-local-map mime-view-mode-map)
840 (run-hooks 'mime-view-define-keymap-hook)
843 (defsubst mime-maybe-hide-echo-buffer ()
844 "Clear mime-echo buffer and delete window for it."
845 (let ((buf (get-buffer mime-echo-buffer-name)))
850 (let ((win (get-buffer-window buf)))
857 (defun mime-view-mode (&optional mother ctl encoding ibuf obuf
858 default-keymap-or-function)
859 "Major mode for viewing MIME message.
861 Here is a list of the standard keys for mime-view-mode.
866 u Move to upper content
867 p or M-TAB Move to previous content
868 n or TAB Move to next content
869 SPC Scroll up or move to next content
870 M-SPC or DEL Scroll down or move to previous content
871 RET Move to next line
872 M-RET Move to previous line
873 v Decode current content as `play mode'
874 e Decode current content as `extract mode'
875 C-c C-p Decode current content as `print mode'
876 a Followup to current content.
879 button-2 Move to point under the mouse cursor
880 and decode current content as `play mode'
883 (mime-maybe-hide-echo-buffer)
884 (let ((ret (mime-view-setup-buffers ctl encoding ibuf obuf))
885 (win-conf (current-window-configuration))
888 (switch-to-buffer ret)
889 (setq mime-preview-original-window-configuration win-conf)
892 (setq mime-mother-buffer mother)
894 (mime-view-define-keymap default-keymap-or-function)
896 (next-single-property-change (point-min) 'mime-view-entity)))
899 (goto-char (point-min))
900 (search-forward "\n\n" nil t)
902 (run-hooks 'mime-view-mode-hook)
909 (autoload 'mime-preview-play-current-entity "mime-play"
910 "Play current entity." t)
912 (defun mime-preview-extract-current-entity ()
913 "Extract current entity into file (maybe).
914 It decodes current entity to call internal or external method as
915 \"extract\" mode. The method is selected from variable
916 `mime-acting-condition'."
918 (mime-preview-play-current-entity "extract")
921 (defun mime-preview-print-current-entity ()
922 "Print current entity (maybe).
923 It decodes current entity to call internal or external method as
924 \"print\" mode. The method is selected from variable
925 `mime-acting-condition'."
927 (mime-preview-play-current-entity "print")
934 (defun mime-preview-original-major-mode ()
935 "Return major-mode of original buffer.
936 If a current buffer has mime-mother-buffer, return original major-mode
937 of the mother-buffer."
938 (if mime-mother-buffer
940 (set-buffer mime-mother-buffer)
941 (mime-preview-original-major-mode)
943 mime-preview-original-major-mode))
945 (defun mime-preview-follow-current-entity ()
946 "Write follow message to current entity.
947 It calls following-method selected from variable
948 `mime-view-following-method-alist'."
950 (let ((message-info (get-text-property (point-min) 'mime-view-entity))
952 (while (null (setq entity
953 (get-text-property (point) 'mime-view-entity)))
957 (previous-single-property-change (point) 'mime-view-entity))
959 (entity-node-id (mime-entity-node-id entity))
960 (len (length entity-node-id))
964 (if (eq (next-single-property-change (point-min)
970 ((eq (next-single-property-change p-beg 'mime-view-entity)
974 (setq p-end (next-single-property-change p-beg 'mime-view-entity))
976 (setq p-end (point-max))
978 ((null entity-node-id)
979 (setq p-end (point-max))
987 (next-single-property-change
988 (point) 'mime-view-entity))
990 (let ((rc (mime-entity-node-id
991 (get-text-property (point)
992 'mime-view-entity))))
993 (or (equal entity-node-id
994 (nthcdr (- (length rc) len) rc))
999 (setq p-end (point-max))
1002 (let* ((mode (mime-preview-original-major-mode))
1004 (format "%s-%s" (buffer-name) (reverse entity-node-id)))
1006 (the-buf (current-buffer))
1007 (a-buf mime-raw-buffer)
1010 (set-buffer (setq new-buf (get-buffer-create new-name)))
1012 (insert-buffer-substring the-buf p-beg p-end)
1013 (goto-char (point-min))
1014 (if (mime-view-header-visible-p entity message-info)
1015 (delete-region (goto-char (point-min))
1016 (if (re-search-forward "^$" nil t)
1020 (goto-char (point-min))
1022 (goto-char (point-min))
1023 (let ((entity-node-id (mime-entity-node-id entity)) ci str)
1031 (mime-raw-find-entity-from-node-id entity-node-id))
1034 (mime-entity-point-min ci)
1035 (mime-entity-point-max ci)
1037 (std11-header-string-except
1039 (apply (function regexp-or) fields)
1042 (eq (mime-entity-media-type ci) 'message)
1043 (eq (mime-entity-media-subtype ci) 'rfc822))
1049 (setq fields (std11-collect-field-names)
1050 entity-node-id (cdr entity-node-id))
1053 (let ((rest mime-view-following-required-fields-list))
1055 (let ((field-name (car rest)))
1056 (or (std11-field-body field-name)
1062 (set-buffer the-buf)
1063 (set-buffer mime-mother-buffer)
1064 (set-buffer mime-raw-buffer)
1065 (std11-field-body field-name)
1069 (setq rest (cdr rest))
1071 (eword-decode-header)
1073 (let ((f (cdr (assq mode mime-view-following-method-alist))))
1078 "Sorry, following method for %s is not implemented yet."
1087 (defun mime-preview-display-x-face ()
1089 (save-window-excursion
1090 (set-buffer mime-raw-buffer)
1091 (mime-view-x-face-function)
1098 (defun mime-preview-move-to-upper ()
1099 "Move to upper entity.
1100 If there is no upper entity, call function `mime-preview-quit'."
1103 (while (null (setq cinfo
1104 (get-text-property (point) 'mime-view-entity)))
1107 (let ((r (mime-raw-find-entity-from-node-id
1108 (cdr (mime-entity-node-id cinfo))
1109 (get-text-property 1 'mime-view-entity)))
1112 (while (setq point (previous-single-property-change
1113 (point) 'mime-view-entity))
1115 (if (eq r (get-text-property (point) 'mime-view-entity))
1122 (defun mime-preview-move-to-previous ()
1123 "Move to previous entity.
1124 If there is no previous entity, it calls function registered in
1125 variable `mime-view-over-to-previous-method-alist'."
1127 (while (null (get-text-property (point) 'mime-view-entity))
1131 (previous-single-property-change (point) 'mime-view-entity)))
1134 (let ((f (assq mime-preview-original-major-mode
1135 mime-view-over-to-previous-method-alist)))
1141 (defun mime-preview-move-to-next ()
1142 "Move to next entity.
1143 If there is no previous entity, it calls function registered in
1144 variable `mime-view-over-to-next-method-alist'."
1146 (let ((point (next-single-property-change (point) 'mime-view-entity)))
1149 (let ((f (assq mime-preview-original-major-mode
1150 mime-view-over-to-next-method-alist)))
1156 (defun mime-preview-scroll-up-entity (&optional h)
1157 "Scroll up current entity.
1158 If reached to (point-max), it calls function registered in variable
1159 `mime-view-over-to-next-method-alist'."
1162 (setq h (1- (window-height)))
1164 (if (= (point) (point-max))
1165 (let ((f (assq mime-preview-original-major-mode
1166 mime-view-over-to-next-method-alist)))
1171 (or (next-single-property-change (point) 'mime-view-entity)
1174 (if (> (point) point)
1179 (defun mime-preview-scroll-down-entity (&optional h)
1180 "Scroll down current entity.
1181 If reached to (point-min), it calls function registered in variable
1182 `mime-view-over-to-previous-method-alist'."
1185 (setq h (1- (window-height)))
1187 (if (= (point) (point-min))
1188 (let ((f (assq mime-preview-original-major-mode
1189 mime-view-over-to-previous-method-alist)))
1196 (while (> (point) 1)
1198 (previous-single-property-change (point)
1204 (setq point (point-min))
1206 (forward-line (- h))
1207 (if (< (point) point)
1211 (defun mime-preview-next-line-entity ()
1213 (mime-preview-scroll-up-entity 1)
1216 (defun mime-preview-previous-line-entity ()
1218 (mime-preview-scroll-down-entity 1)
1225 (defun mime-preview-quit ()
1226 "Quit from MIME-preview buffer.
1227 It calls function registered in variable
1228 `mime-preview-quitting-method-alist'."
1230 (let ((r (assq mime-preview-original-major-mode
1231 mime-preview-quitting-method-alist)))
1236 (defun mime-preview-show-summary ()
1238 It calls function registered in variable
1239 `mime-view-show-summary-method'."
1241 (let ((r (assq mime-preview-original-major-mode
1242 mime-view-show-summary-method)))
1247 (defun mime-preview-kill-buffer ()
1249 (kill-buffer (current-buffer))
1256 (provide 'mime-view)
1258 (run-hooks 'mime-view-load-hook)
1260 ;;; mime-view.el ends here