1 ;;; mime-view.el --- interactive MIME viewer for GNU Emacs
3 ;; Copyright (C) 1995,96,97,98,99,2000 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <tomo@m17n.org>
7 ;; Renamed: 1994/08/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 (Sample of Elastic 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.
40 (defconst mime-view-version
41 (concat (mime-product-name mime-user-interface-product) " MIME-View "
42 (mapconcat #'number-to-string
43 (mime-product-version mime-user-interface-product) ".")
44 " (" (mime-product-code-name mime-user-interface-product) ")"))
50 (defgroup mime-view nil
54 (defcustom mime-situation-examples-file "~/.mime-example"
55 "*File name of situation-examples demonstrated by user."
59 (defcustom mime-preview-move-scroll nil
60 "*Decides whether to scroll when moving to next entity.
61 When t, scroll the buffer. Non-nil but not t means scroll when
62 the next entity is within next-screen-context-lines from top or
63 buttom. Nil means don't scroll at all."
65 :type '(choice (const :tag "Off" nil)
67 (sexp :tag "Situation" 1)))
69 (defcustom mime-view-mailcap-files
70 (let ((files '("/etc/mailcap" "/usr/etc/mailcap" "~/.mailcap")))
71 (or (member mime-mailcap-file files)
72 (setq files (cons mime-mailcap-file files)))
74 "List of mailcap files."
79 ;;; @ in raw-buffer (representation space)
82 (defvar mime-preview-buffer nil
83 "MIME-preview buffer corresponding with the (raw) buffer.")
84 (make-variable-buffer-local 'mime-preview-buffer)
87 (defvar mime-raw-representation-type-alist
88 '((mime-show-message-mode . binary)
89 (mime-temp-message-mode . binary)
92 "Alist of major-mode vs. representation-type of mime-raw-buffer.
93 Each element looks like (SYMBOL . REPRESENTATION-TYPE). SYMBOL is
94 major-mode or t. t means default. REPRESENTATION-TYPE must be
95 `binary' or `cooked'.")
98 ;;; @ in preview-buffer (presentation space)
101 (defvar mime-mother-buffer nil
102 "Mother buffer corresponding with the (MIME-preview) buffer.
103 If current MIME-preview buffer is generated by other buffer, such as
104 message/partial, it is called `mother-buffer'.")
105 (make-variable-buffer-local 'mime-mother-buffer)
107 ;; (defvar mime-raw-buffer nil
108 ;; "Raw buffer corresponding with the (MIME-preview) buffer.")
109 ;; (make-variable-buffer-local 'mime-raw-buffer)
111 (defvar mime-preview-original-window-configuration nil
112 "Window-configuration before mime-view-mode is called.")
113 (make-variable-buffer-local 'mime-preview-original-window-configuration)
115 (defun mime-preview-original-major-mode (&optional recursive point)
116 "Return major-mode of original buffer.
117 If optional argument RECURSIVE is non-nil and current buffer has
118 mime-mother-buffer, it returns original major-mode of the
120 (if (and recursive mime-mother-buffer)
122 (set-buffer mime-mother-buffer)
123 (mime-preview-original-major-mode recursive)
125 (cdr (assq 'major-mode
126 (get-text-property (or point
127 (if (> (point) (buffer-size))
128 (max (1- (point-max)) (point-min))
130 'mime-view-situation)))))
133 ;;; @ entity information
136 (defun mime-entity-situation (entity &optional situation)
137 "Return situation of ENTITY."
138 (let (rest param name)
140 (unless (assq 'type situation)
141 (setq rest (or (mime-entity-content-type entity)
142 (make-mime-content-type 'text 'plain))
143 situation (cons (car rest) situation)
146 (unless (assq 'subtype situation)
148 (setq rest (or (cdr (mime-entity-content-type entity))
149 '((subtype . plain)))))
150 (setq situation (cons (car rest) situation)
154 (setq param (car rest))
155 (or (assoc (car param) situation)
156 (setq situation (cons param situation)))
157 (setq rest (cdr rest)))
159 ;; Content-Disposition
161 (unless (assq 'disposition-type situation)
162 (setq rest (mime-entity-content-disposition entity))
164 (setq situation (cons (cons 'disposition-type
165 (mime-content-disposition-type rest))
167 rest (mime-content-disposition-parameters rest))
170 (setq param (car rest)
172 (if (cond ((string= name "filename")
173 (if (assq 'filename situation)
175 (setq name 'filename)))
176 ((string= name "creation-date")
177 (if (assq 'creation-date situation)
179 (setq name 'creation-date)))
180 ((string= name "modification-date")
181 (if (assq 'modification-date situation)
183 (setq name 'modification-date)))
184 ((string= name "read-date")
185 (if (assq 'read-date situation)
187 (setq name 'read-date)))
188 ((string= name "size")
189 (if (assq 'size situation)
192 (t (setq name (cons 'disposition name))
193 (if (assoc name situation)
197 (cons (cons name (cdr param))
199 (setq rest (cdr rest)))
201 ;; Content-Transfer-Encoding
202 (or (assq 'encoding situation)
204 (cons (cons 'encoding (or (mime-entity-encoding entity)
210 (defsubst mime-delq-null-situation (situations field
211 &rest ignored-values)
214 (let* ((situation (car situations))
215 (cell (assq field situation)))
217 (or (memq (cdr cell) ignored-values)
218 (setq dest (cons situation dest))
220 (setq situations (cdr situations)))
223 (defun mime-compare-situation-with-example (situation example)
224 (let ((example (copy-alist example))
227 (let* ((cell (car situation))
229 (ecell (assoc key example)))
231 (if (equal cell ecell)
232 (setq match (1+ match))
233 (setq example (delq ecell example))
236 (setq situation (cdr situation))
241 (defun mime-sort-situation (situation)
251 (disposition-type . 6)
255 (let ((ret (assq a-t order)))
257 (setq a-order (cdr ret))
263 (let ((ret (assq b-t order)))
265 (setq b-order (cdr ret))
270 (if (= a-order b-order)
271 (string< (format "%s" a-t)(format "%s" b-t))
276 (defun mime-unify-situations (entity-situation
277 condition situation-examples
278 &optional required-name ignored-value
281 (in-calist-package 'mime-view)
283 (ctree-find-calist condition entity-situation
286 (setq ret (mime-delq-null-situation ret required-name
288 (or (assq 'ignore-examples entity-situation)
296 (let ((situation (car rest))
297 (examples situation-examples))
300 (mime-compare-situation-with-example
301 situation (caar examples)))
302 (ret-score (car ret)))
303 (cond ((> ret-score max-score)
304 (setq max-score ret-score
305 max-escore (cdar examples)
306 max-examples (list (cdr ret))
307 max-situations (list situation))
309 ((= ret-score max-score)
310 (cond ((> (cdar examples) max-escore)
311 (setq max-escore (cdar examples)
312 max-examples (list (cdr ret))
313 max-situations (list situation))
315 ((= (cdar examples) max-escore)
317 (cons (cdr ret) max-examples))
318 (or (member situation max-situations)
320 (cons situation max-situations)))
322 (setq examples (cdr examples))))
323 (setq rest (cdr rest)))
325 (setq ret max-situations)
327 (let* ((example (car max-examples))
329 (assoc example situation-examples)))
331 (setcdr cell (1+ (cdr cell)))
332 (setq situation-examples
333 (cons (cons example 0)
336 (setq max-examples (cdr max-examples))
338 (cons ret situation-examples)
339 ;; ret: list of situations
340 ;; situation-examples: new examples (notoce that contents of
341 ;; argument `situation-examples' has bees modified)
344 (defun mime-view-entity-title (entity)
345 (or (mime-entity-read-field entity 'Content-Description)
346 (mime-entity-read-field entity 'Subject)
347 (mime-entity-filename entity)
350 (defvar mime-preview-situation-example-list nil)
351 (defvar mime-preview-situation-example-list-max-size 16)
352 ;; (defvar mime-preview-situation-example-condition nil)
354 (defun mime-find-entity-preview-situation (entity
355 &optional default-situation)
357 (mime-unify-situations
358 (append (mime-entity-situation entity)
360 mime-preview-condition
361 mime-preview-situation-example-list)))
362 (setq mime-preview-situation-example-list
368 (defvar mime-acting-situation-example-list nil)
369 (defvar mime-acting-situation-example-list-max-size 16)
370 (defvar mime-situation-examples-file-coding-system nil)
372 (defun mime-view-read-situation-examples-file (&optional file)
374 (setq file mime-situation-examples-file))
375 (if (file-readable-p file)
377 (insert-file-contents file)
378 (setq mime-situation-examples-file-coding-system
379 (and (boundp 'buffer-file-coding-system)
380 buffer-file-coding-system)
382 ;; ((boundp 'buffer-file-coding-system)
383 ;; (symbol-value 'buffer-file-coding-system))
384 ;; ((boundp 'file-coding-system)
385 ;; (symbol-value 'file-coding-system))
388 (condition-case error
390 (error (message "%s is broken: %s" file (cdr error))))
394 (while (and (> (length mime-preview-situation-example-list)
395 mime-preview-situation-example-list-max-size)
397 (setq mime-preview-situation-example-list
398 (mime-reduce-situation-examples
399 mime-preview-situation-example-list))
401 (error (setq mime-preview-situation-example-list nil)))
402 ;; (let ((rest mime-preview-situation-example-list))
404 ;; (ctree-set-calist-strictly 'mime-preview-condition
406 ;; (setq rest (cdr rest))))
409 (while (and (> (length mime-acting-situation-example-list)
410 mime-acting-situation-example-list-max-size)
412 (setq mime-acting-situation-example-list
413 (mime-reduce-situation-examples
414 mime-acting-situation-example-list))
416 (error (setq mime-acting-situation-example-list nil))))))
418 (defun mime-save-situation-examples ()
419 (if (or mime-preview-situation-example-list
420 mime-acting-situation-example-list)
421 (let ((file mime-situation-examples-file))
423 (insert ";;; " (file-name-nondirectory file) "\n")
424 (insert "\n;; This file is generated automatically by "
425 mime-view-version "\n\n")
426 (insert ";;; Code:\n\n")
427 (if mime-preview-situation-example-list
428 (pp `(setq mime-preview-situation-example-list
429 ',mime-preview-situation-example-list)
431 (if mime-acting-situation-example-list
432 (pp `(setq mime-acting-situation-example-list
433 ',mime-acting-situation-example-list)
436 (file-name-nondirectory file)
438 (setq buffer-file-coding-system
439 mime-situation-examples-file-coding-system)
441 ;; ((boundp 'buffer-file-coding-system)
442 ;; (setq buffer-file-coding-system
443 ;; mime-situation-examples-file-coding-system))
444 ;; ((boundp 'file-coding-system)
445 ;; (setq file-coding-system
446 ;; mime-situation-examples-file-coding-system)))
447 (setq buffer-file-name file)
450 (add-hook 'kill-emacs-hook 'mime-save-situation-examples)
452 (defun mime-reduce-situation-examples (situation-examples)
453 (let ((len (length situation-examples))
461 ir situation-examples)
465 jr situation-examples)
469 (setq ret (mime-compare-situation-with-example (car ic)(car jc))
471 det-ret (+ (length (car ic))(length (car jc)))
472 det-org (length (cdr ret))
473 freq (+ (cdr ic)(cdr jc)))
474 (cond ((< max-sim sim)
481 dest (cons (cdr ret) freq))
484 (cond ((> min-det-ret det-ret)
485 (setq min-det-ret det-ret
490 dest (cons (cdr ret) freq))
492 ((= min-det-ret det-ret)
493 (cond ((> min-det-org det-org)
494 (setq min-det-org det-org
498 dest (cons (cdr ret) freq))
500 ((= min-det-org det-org)
501 (cond ((> min-freq freq)
505 dest (cons (cdr ret) freq))
519 (setq jr (nthcdr (1- d-j) situation-examples))
520 (setcdr jr (cddr jr))
522 (setq situation-examples
523 (cdr situation-examples))
524 (setq ir (nthcdr (1- d-i) situation-examples))
525 (setcdr ir (cddr ir))
527 (if (setq ir (assoc (car dest) situation-examples))
529 (setcdr ir (+ (cdr ir)(cdr dest)))
531 (cons dest situation-examples)
532 ;; situation-examples may be modified.
536 ;;; @ presentation of preview
542 ;;; @@@ predicate function
545 ;; (defun mime-view-entity-button-visible-p (entity)
546 ;; "Return non-nil if header of ENTITY is visible.
547 ;; Please redefine this function if you want to change default setting."
548 ;; (let ((media-type (mime-entity-media-type entity))
549 ;; (media-subtype (mime-entity-media-subtype entity)))
550 ;; (or (not (eq media-type 'application))
551 ;; (and (not (eq media-subtype 'x-selection))
552 ;; (or (not (eq media-subtype 'octet-stream))
553 ;; (let ((mother-entity (mime-entity-parent entity)))
554 ;; (or (not (eq (mime-entity-media-type mother-entity)
556 ;; (not (eq (mime-entity-media-subtype mother-entity)
561 ;;; @@@ entity button generator
564 (defun mime-view-insert-entity-button (entity)
565 "Insert entity-button of ENTITY."
566 (let ((entity-node-id (mime-entity-node-id entity))
567 (params (mime-entity-parameters entity))
568 (subject (mime-view-entity-title entity)))
570 (let ((access-type (assoc "access-type" params))
571 (num (or (cdr (assoc "x-part-number" params))
572 (if (consp entity-node-id)
575 (format "%s" (1+ num))
577 (reverse entity-node-id) ".")
581 (let ((server (assoc "server" params)))
582 (setq access-type (cdr access-type))
584 (format "%s %s ([%s] %s)"
585 num subject access-type (cdr server))
586 (let ((site (cdr (assoc "site" params)))
587 (dir (cdr (assoc "directory" params)))
588 (url (cdr (assoc "url" params)))
591 (format "%s %s ([%s] %s)"
592 num subject access-type url)
593 (format "%s %s ([%s] %s:%s)"
594 num subject access-type site dir))
598 (let ((media-type (mime-entity-media-type entity))
599 (media-subtype (mime-entity-media-subtype entity))
600 (charset (cdr (assoc "charset" params)))
601 (encoding (mime-entity-encoding entity)))
605 (format " <%s/%s%s%s>"
606 media-type media-subtype
608 (concat "; " charset)
611 (concat " (" encoding ")")
613 (if (>= (+ (current-column)(length rest))(window-width))
617 (function mime-preview-play-current-entity))
624 (defvar mime-header-presentation-method-alist nil
625 "Alist of major mode vs. corresponding header-presentation-method functions.
626 Each element looks like (SYMBOL . FUNCTION).
627 SYMBOL must be major mode in raw-buffer or t. t means default.
628 Interface of FUNCTION must be (ENTITY SITUATION).")
630 (defvar mime-view-ignored-field-list
631 '(".*Received:" ".*Path:" ".*Id:" "^References:"
632 "^Replied:" "^Errors-To:"
633 "^Lines:" "^Sender:" ".*Host:" "^Xref:"
634 "^Content-Type:" "^Precedence:"
635 "^Status:" "^X-VM-.*:")
636 "All fields that match this list will be hidden in MIME preview buffer.
637 Each elements are regexp of field-name.")
639 (defvar mime-view-visible-field-list '("^Dnas.*:" "^Message-Id:")
640 "All fields that match this list will be displayed in MIME preview buffer.
641 Each elements are regexp of field-name.")
647 ;;; @@@ predicate function
650 (in-calist-package 'mime-view)
652 (defun mime-calist::field-match-method-as-default-rule (calist
653 field-type field-value)
654 (let ((s-field (assq field-type calist)))
655 (cond ((null s-field)
656 (cons (cons field-type field-value) calist)
660 (define-calist-field-match-method
661 'header #'mime-calist::field-match-method-as-default-rule)
663 (define-calist-field-match-method
664 'body #'mime-calist::field-match-method-as-default-rule)
667 (defvar mime-preview-condition nil
668 "Condition-tree about how to display entity.")
670 (ctree-set-calist-strictly
671 'mime-preview-condition '((type . application)(subtype . octet-stream)
674 (ctree-set-calist-strictly
675 'mime-preview-condition '((type . application)(subtype . octet-stream)
678 (ctree-set-calist-strictly
679 'mime-preview-condition '((type . application)(subtype . octet-stream)
683 (ctree-set-calist-strictly
684 'mime-preview-condition '((type . application)(subtype . pgp)
687 (ctree-set-calist-strictly
688 'mime-preview-condition '((type . application)(subtype . x-latex)
691 (ctree-set-calist-strictly
692 'mime-preview-condition '((type . application)(subtype . x-selection)
695 (ctree-set-calist-strictly
696 'mime-preview-condition '((type . application)(subtype . x-comment)
699 (ctree-set-calist-strictly
700 'mime-preview-condition '((type . message)(subtype . delivery-status)
703 (ctree-set-calist-strictly
704 'mime-preview-condition
706 (body-presentation-method . mime-display-text/plain)))
708 (ctree-set-calist-strictly
709 'mime-preview-condition
712 (body-presentation-method . mime-display-text/plain)))
714 (ctree-set-calist-strictly
715 'mime-preview-condition
716 '((type . text)(subtype . enriched)
718 (body-presentation-method . mime-display-text/enriched)))
720 (ctree-set-calist-strictly
721 'mime-preview-condition
722 '((type . text)(subtype . richtext)
724 (body-presentation-method . mime-display-text/richtext)))
726 (autoload 'mime-display-application/x-postpet "postpet")
728 (ctree-set-calist-strictly
729 'mime-preview-condition
730 '((type . application)(subtype . x-postpet)
732 (body-presentation-method . mime-display-application/x-postpet)))
734 (ctree-set-calist-strictly
735 'mime-preview-condition
736 '((type . text)(subtype . t)
738 (body-presentation-method . mime-display-text/plain)))
740 (ctree-set-calist-strictly
741 'mime-preview-condition
742 '((type . multipart)(subtype . alternative)
744 (body-presentation-method . mime-display-multipart/alternative)))
746 (ctree-set-calist-strictly
747 'mime-preview-condition
748 '((type . multipart)(subtype . t)
750 (body-presentation-method . mime-display-multipart/mixed)))
752 (ctree-set-calist-strictly
753 'mime-preview-condition
754 '((type . message)(subtype . partial)
756 (body-presentation-method . mime-display-message/partial-button)))
758 (ctree-set-calist-strictly
759 'mime-preview-condition
760 '((type . message)(subtype . rfc822)
762 (body-presentation-method . mime-display-multipart/mixed)
763 (childrens-situation (header . visible)
764 (entity-button . invisible))))
766 (ctree-set-calist-strictly
767 'mime-preview-condition
768 '((type . message)(subtype . news)
770 (body-presentation-method . mime-display-multipart/mixed)
771 (childrens-situation (header . visible)
772 (entity-button . invisible))))
775 ;;; @@@ entity presentation
778 (defun mime-display-text/plain (entity situation)
780 (narrow-to-region (point-max)(point-max))
782 (mime-insert-text-content entity)
784 (message "Can't decode current entity.")
786 (run-hooks 'mime-text-decode-hook)
787 (goto-char (point-max))
788 (if (not (eq (char-after (1- (point))) ?\n))
791 (mime-add-url-buttons)
792 (run-hooks 'mime-display-text/plain-hook)
795 (defun mime-display-text/richtext (entity situation)
797 (narrow-to-region (point-max)(point-max))
798 (mime-insert-text-content entity)
799 (run-hooks 'mime-text-decode-hook)
800 (let ((beg (point-min)))
801 (remove-text-properties beg (point-max) '(face nil))
802 (richtext-decode beg (point-max))
805 (defun mime-display-text/enriched (entity situation)
807 (narrow-to-region (point-max)(point-max))
808 (mime-insert-text-content entity)
809 (run-hooks 'mime-text-decode-hook)
810 (let ((beg (point-min)))
811 (remove-text-properties beg (point-max) '(face nil))
812 (enriched-decode beg (point-max))
816 (defvar mime-view-announcement-for-message/partial
817 (if (and (>= emacs-major-version 19) window-system)
819 \[[ This is message/partial style split message. ]]
820 \[[ Please press `v' key in this buffer ]]
821 \[[ or click here by mouse button-2. ]]"
823 \[[ This is message/partial style split message. ]]
824 \[[ Please press `v' key in this buffer. ]]"
827 (defun mime-display-message/partial-button (&optional entity situation)
829 (goto-char (point-max))
830 (if (not (search-backward "\n\n" nil t))
833 (goto-char (point-max))
834 (narrow-to-region (point-max)(point-max))
835 (insert mime-view-announcement-for-message/partial)
836 (mime-add-button (point-min)(point-max)
837 #'mime-preview-play-current-entity)
840 (defun mime-display-multipart/mixed (entity situation)
841 (let ((children (mime-entity-children entity))
842 (original-major-mode-cell (assq 'major-mode situation))
844 (cdr (assq 'childrens-situation situation))))
845 (if original-major-mode-cell
846 (setq default-situation
847 (cons original-major-mode-cell default-situation)))
849 (mime-display-entity (car children) nil default-situation)
850 (setq children (cdr children))
853 (defcustom mime-view-type-subtype-score-alist
854 '(((text . enriched) . 3)
855 ((text . richtext) . 2)
858 "Alist MEDIA-TYPE vs corresponding score.
859 MEDIA-TYPE must be (TYPE . SUBTYPE), TYPE or t. t means default."
861 :type '(repeat (cons (choice :tag "Media-Type"
862 (cons :tag "Type/Subtype"
863 (symbol :tag "Primary-type")
864 (symbol :tag "Subtype"))
866 (const :tag "Default" t))
869 (defun mime-display-multipart/alternative (entity situation)
870 (let* ((children (mime-entity-children entity))
871 (original-major-mode-cell (assq 'major-mode situation))
873 (cdr (assq 'childrens-situation situation)))
878 (if original-major-mode-cell
879 (setq default-situation
880 (cons original-major-mode-cell default-situation)))
885 (mime-find-entity-preview-situation
886 child default-situation)))
887 (if (cdr (assq 'body-presentation-method situation))
892 (cdr (assq 'type situation))
893 (cdr (assq 'subtype situation)))
894 mime-view-type-subtype-score-alist)
896 (cdr (assq 'type situation))
897 mime-view-type-subtype-score-alist)
900 mime-view-type-subtype-score-alist)
902 (if (> score max-score)
912 (let ((child (car children))
913 (situation (car situations)))
914 (mime-display-entity child (if (= i p)
916 (put-alist 'body 'invisible
917 (copy-alist situation)))))
918 (setq children (cdr children)
919 situations (cdr situations)
923 ;;; @ acting-condition
926 (defvar mime-acting-condition nil
927 "Condition-tree about how to process entity.")
929 (defun mime-view-read-mailcap-files (&optional files)
931 (setq files mime-view-mailcap-files))
934 (setq file (car files))
935 (if (file-readable-p file)
936 (setq entries (append entries (mime-parse-mailcap-file file))))
937 (setq files (cdr files)))
939 (let ((entry (car entries))
942 (let* ((field (car entry))
943 (field-type (car field)))
944 (cond ((eq field-type 'view) (setq view field))
945 ((eq field-type 'print) (setq print field))
946 ((memq field-type '(compose composetyped edit)))
947 (t (setq shared (cons field shared))))
949 (setq entry (cdr entry)))
950 (setq shared (nreverse shared))
951 (ctree-set-calist-with-default
952 'mime-acting-condition
953 (append shared (list '(mode . "play")(cons 'method (cdr view)))))
955 (ctree-set-calist-with-default
956 'mime-acting-condition
958 (list '(mode . "print")(cons 'method (cdr view)))))))
959 (setq entries (cdr entries)))))
961 (mime-view-read-mailcap-files)
963 (ctree-set-calist-strictly
964 'mime-acting-condition
965 '((type . application)(subtype . octet-stream)
967 (method . mime-detect-content)
970 (ctree-set-calist-with-default
971 'mime-acting-condition
973 (method . mime-save-content)))
975 (ctree-set-calist-strictly
976 'mime-acting-condition
977 '((type . text)(subtype . x-rot13-47)(mode . "play")
978 (method . mime-view-caesar)
980 (ctree-set-calist-strictly
981 'mime-acting-condition
982 '((type . text)(subtype . x-rot13-47-48)(mode . "play")
983 (method . mime-view-caesar)
986 (ctree-set-calist-strictly
987 'mime-acting-condition
988 '((type . message)(subtype . rfc822)(mode . "play")
989 (method . mime-view-message/rfc822)
991 (ctree-set-calist-strictly
992 'mime-acting-condition
993 '((type . message)(subtype . partial)(mode . "play")
994 (method . mime-store-message/partial-piece)
997 (ctree-set-calist-strictly
998 'mime-acting-condition
999 '((type . message)(subtype . external-body)
1000 ("access-type" . "anon-ftp")
1001 (method . mime-view-message/external-anon-ftp)
1004 (ctree-set-calist-strictly
1005 'mime-acting-condition
1006 '((type . message)(subtype . external-body)
1007 ("access-type" . "url")
1008 (method . mime-view-message/external-url)
1011 (ctree-set-calist-strictly
1012 'mime-acting-condition
1013 '((type . application)(subtype . octet-stream)
1014 (method . mime-save-content)
1018 ;;; @ quitting method
1021 (defvar mime-preview-quitting-method-alist
1022 '((mime-show-message-mode
1023 . mime-preview-quitting-method-for-mime-show-message-mode))
1024 "Alist of major-mode vs. quitting-method of mime-view.")
1026 (defvar mime-preview-over-to-previous-method-alist nil
1027 "Alist of major-mode vs. over-to-previous-method of mime-view.")
1029 (defvar mime-preview-over-to-next-method-alist nil
1030 "Alist of major-mode vs. over-to-next-method of mime-view.")
1033 ;;; @ following method
1036 (defvar mime-preview-following-method-alist nil
1037 "Alist of major-mode vs. following-method of mime-view.")
1039 (defvar mime-view-following-required-fields-list
1046 (defun mime-display-entity (entity &optional situation
1047 default-situation preview-buffer)
1049 (setq preview-buffer (current-buffer)))
1050 (let* (e nb ne nhb nbb)
1051 (in-calist-package 'mime-view)
1054 (mime-find-entity-preview-situation entity default-situation)))
1055 (let ((button-is-invisible
1056 (eq (cdr (or (assq '*entity-button situation)
1057 (assq 'entity-button situation)))
1060 (eq (cdr (or (assq '*header situation)
1061 (assq 'header situation)))
1064 (eq (cdr (or (assq '*body situation)
1065 (assq 'body situation)))
1067 (children (mime-entity-children entity)))
1068 (set-buffer preview-buffer)
1070 (narrow-to-region nb nb)
1071 (or button-is-invisible
1072 ;; (if (mime-view-entity-button-visible-p entity)
1073 (mime-view-insert-entity-button entity)
1076 (if header-is-visible
1077 (let ((header-presentation-method
1078 (or (cdr (assq 'header-presentation-method situation))
1079 (cdr (assq (cdr (assq 'major-mode situation))
1080 mime-header-presentation-method-alist)))))
1082 (if header-presentation-method
1083 (funcall header-presentation-method entity situation)
1084 (mime-insert-header entity
1085 mime-view-ignored-field-list
1086 mime-view-visible-field-list))
1087 (run-hooks 'mime-display-header-hook)
1088 (put-text-property nhb (point-max) 'mime-view-entity-header entity)
1089 (goto-char (point-max))
1094 (let ((body-presentation-method
1095 (cdr (assq 'body-presentation-method situation))))
1096 (if (functionp body-presentation-method)
1097 (funcall body-presentation-method entity situation)
1098 (mime-display-text/plain entity situation)))
1099 (when button-is-invisible
1100 (goto-char (point-max))
1101 (mime-view-insert-entity-button entity)
1103 (unless header-is-visible
1104 (goto-char (point-max))
1107 (setq ne (point-max))
1109 (put-text-property nb ne 'mime-view-entity entity)
1110 (put-text-property nb ne 'mime-view-situation situation)
1111 (put-text-property nbb ne 'mime-view-entity-body entity)
1113 (if (and children body-is-visible)
1114 (let ((body-presentation-method
1115 (cdr (assq 'body-presentation-method situation))))
1116 (if (functionp body-presentation-method)
1117 (funcall body-presentation-method entity situation)
1118 (mime-display-multipart/mixed entity situation))))
1122 ;;; @ MIME viewer mode
1125 (defconst mime-view-menu-title "MIME-View")
1126 (defconst mime-view-menu-list
1127 '((up "Move to upper entity" mime-preview-move-to-upper)
1128 (previous "Move to previous entity" mime-preview-move-to-previous)
1129 (next "Move to next entity" mime-preview-move-to-next)
1130 (scroll-down "Scroll-down" mime-preview-scroll-down-entity)
1131 (scroll-up "Scroll-up" mime-preview-scroll-up-entity)
1132 (play "Play current entity" mime-preview-play-current-entity)
1133 (extract "Extract current entity" mime-preview-extract-current-entity)
1134 (print "Print current entity" mime-preview-print-current-entity)
1136 "Menu for MIME Viewer")
1138 (cond ((featurep 'xemacs)
1139 (defvar mime-view-xemacs-popup-menu
1140 (cons mime-view-menu-title
1143 (vector (nth 1 item)(nth 2 item) t)
1145 mime-view-menu-list)))
1146 (defun mime-view-xemacs-popup-menu (event)
1147 "Popup the menu in the MIME Viewer buffer"
1149 (select-window (event-window event))
1150 (set-buffer (event-buffer event))
1151 (popup-menu 'mime-view-xemacs-popup-menu))
1152 (defvar mouse-button-2 'button2)
1153 (defvar mouse-button-3 'button3)
1156 (defvar mime-view-popup-menu
1157 (let ((menu (make-sparse-keymap mime-view-menu-title)))
1161 (list (intern (nth 1 item)) 'menu-item
1162 (nth 1 item)(nth 2 item))
1164 mime-view-menu-list))))
1165 (defun mime-view-popup-menu (event)
1166 "Popup the menu in the MIME Viewer buffer"
1168 (let ((menu mime-view-popup-menu) events func)
1169 (setq events (x-popup-menu t menu))
1171 (setq func (lookup-key menu (apply #'vector events)))
1174 (defvar mouse-button-2 [mouse-2])
1175 (defvar mouse-button-3 [mouse-3])
1178 (defun mime-view-define-keymap (&optional default)
1179 (let ((mime-view-mode-map (if (keymapp default)
1180 (copy-keymap default)
1181 (make-sparse-keymap))))
1182 (define-key mime-view-mode-map
1183 "u" (function mime-preview-move-to-upper))
1184 (define-key mime-view-mode-map
1185 "p" (function mime-preview-move-to-previous))
1186 (define-key mime-view-mode-map
1187 "n" (function mime-preview-move-to-next))
1188 (define-key mime-view-mode-map
1189 "\e\t" (function mime-preview-move-to-previous))
1190 (define-key mime-view-mode-map
1191 "\t" (function mime-preview-move-to-next))
1192 (define-key mime-view-mode-map
1193 " " (function mime-preview-scroll-up-entity))
1194 (define-key mime-view-mode-map
1195 "\M- " (function mime-preview-scroll-down-entity))
1196 (define-key mime-view-mode-map
1197 "\177" (function mime-preview-scroll-down-entity))
1198 (define-key mime-view-mode-map
1199 "\C-m" (function mime-preview-next-line-entity))
1200 (define-key mime-view-mode-map
1201 "\C-\M-m" (function mime-preview-previous-line-entity))
1202 (define-key mime-view-mode-map
1203 "v" (function mime-preview-play-current-entity))
1204 (define-key mime-view-mode-map
1205 "e" (function mime-preview-extract-current-entity))
1206 (define-key mime-view-mode-map
1207 "\C-c\C-p" (function mime-preview-print-current-entity))
1209 (define-key mime-view-mode-map
1210 "\C-c\C-t\C-f" (function mime-preview-toggle-header))
1211 (define-key mime-view-mode-map
1212 "\C-c\C-th" (function mime-preview-toggle-header))
1213 (define-key mime-view-mode-map
1214 "\C-c\C-t\C-c" (function mime-preview-toggle-content))
1216 (define-key mime-view-mode-map
1217 "\C-c\C-v\C-f" (function mime-preview-show-header))
1218 (define-key mime-view-mode-map
1219 "\C-c\C-vh" (function mime-preview-show-header))
1220 (define-key mime-view-mode-map
1221 "\C-c\C-v\C-c" (function mime-preview-show-content))
1223 (define-key mime-view-mode-map
1224 "\C-c\C-d\C-f" (function mime-preview-hide-header))
1225 (define-key mime-view-mode-map
1226 "\C-c\C-dh" (function mime-preview-hide-header))
1227 (define-key mime-view-mode-map
1228 "\C-c\C-d\C-c" (function mime-preview-hide-content))
1230 (define-key mime-view-mode-map
1231 "a" (function mime-preview-follow-current-entity))
1232 (define-key mime-view-mode-map
1233 "q" (function mime-preview-quit))
1234 (define-key mime-view-mode-map
1235 "\C-c\C-x" (function mime-preview-kill-buffer))
1236 ;; (define-key mime-view-mode-map
1237 ;; "<" (function beginning-of-buffer))
1238 ;; (define-key mime-view-mode-map
1239 ;; ">" (function end-of-buffer))
1240 (define-key mime-view-mode-map
1241 "?" (function describe-mode))
1242 (define-key mime-view-mode-map
1243 [tab] (function mime-preview-move-to-next))
1244 (define-key mime-view-mode-map
1245 [delete] (function mime-preview-scroll-down-entity))
1246 (define-key mime-view-mode-map
1247 [backspace] (function mime-preview-scroll-down-entity))
1248 (if (functionp default)
1249 (cond ((featurep 'xemacs)
1250 (set-keymap-default-binding mime-view-mode-map default)
1253 (setq mime-view-mode-map
1254 (append mime-view-mode-map (list (cons t default))))
1257 (define-key mime-view-mode-map
1258 mouse-button-2 (function mime-button-dispatcher))
1260 (cond ((featurep 'xemacs)
1261 (define-key mime-view-mode-map
1262 mouse-button-3 (function mime-view-xemacs-popup-menu))
1264 ((>= emacs-major-version 19)
1265 (define-key mime-view-mode-map
1266 mouse-button-3 (function mime-view-popup-menu))
1267 (define-key mime-view-mode-map [menu-bar mime-view]
1268 (cons mime-view-menu-title
1269 (make-sparse-keymap mime-view-menu-title)))
1272 (define-key mime-view-mode-map
1273 (vector 'menu-bar 'mime-view (car item))
1274 (cons (nth 1 item)(nth 2 item)))
1276 (reverse mime-view-menu-list))
1278 ;; (run-hooks 'mime-view-define-keymap-hook)
1279 mime-view-mode-map))
1281 (defvar mime-view-mode-default-map (mime-view-define-keymap))
1284 (defsubst mime-maybe-hide-echo-buffer ()
1285 "Clear mime-echo buffer and delete window for it."
1286 (let ((buf (get-buffer mime-echo-buffer-name)))
1291 (let ((win (get-buffer-window buf)))
1298 (defvar mime-view-redisplay nil)
1301 (defun mime-display-message (message &optional preview-buffer
1302 mother default-keymap-or-function
1303 original-major-mode keymap)
1304 "View MESSAGE in MIME-View mode.
1306 Optional argument PREVIEW-BUFFER specifies the buffer of the
1307 presentation. It must be either nil or a name of preview buffer.
1309 Optional argument MOTHER specifies mother-buffer of the preview-buffer.
1311 Optional argument DEFAULT-KEYMAP-OR-FUNCTION is nil, keymap or
1312 function. If it is a keymap, keymap of MIME-View mode will be added
1313 to it. If it is a function, it will be bound as default binding of
1314 keymap of MIME-View mode.
1316 Optional argument ORIGINAL-MAJOR-MODE is major-mode of representation
1317 buffer of MESSAGE. If it is nil, current `major-mode' is used.
1319 Optional argument KEYMAP is keymap of MIME-View mode. If it is
1320 non-nil, DEFAULT-KEYMAP-OR-FUNCTION is ignored. If it is nil,
1321 `mime-view-mode-default-map' is used."
1322 (mime-maybe-hide-echo-buffer)
1323 (let ((win-conf (current-window-configuration)))
1325 (setq preview-buffer
1326 (concat "*Preview-" (mime-entity-name message) "*")))
1327 (or original-major-mode
1328 (setq original-major-mode major-mode))
1329 (let ((inhibit-read-only t))
1330 (set-buffer (get-buffer-create preview-buffer))
1334 (setq mime-mother-buffer mother))
1335 (setq mime-preview-original-window-configuration win-conf)
1336 (setq major-mode 'mime-view-mode)
1337 (setq mode-name "MIME-View")
1338 (mime-display-entity message nil
1339 `((entity-button . invisible)
1341 (major-mode . ,original-major-mode))
1345 (if default-keymap-or-function
1346 (mime-view-define-keymap default-keymap-or-function)
1347 mime-view-mode-default-map)))
1349 (next-single-property-change (point-min) 'mime-view-entity)))
1352 (goto-char (point-min))
1353 (search-forward "\n\n" nil t)))
1354 (run-hooks 'mime-view-mode-hook)
1355 (set-buffer-modified-p nil)
1356 (setq buffer-read-only t)
1360 (defun mime-view-buffer (&optional raw-buffer preview-buffer mother
1361 default-keymap-or-function
1362 representation-type)
1363 "View RAW-BUFFER in MIME-View mode.
1364 Optional argument PREVIEW-BUFFER is either nil or a name of preview
1366 Optional argument DEFAULT-KEYMAP-OR-FUNCTION is nil, keymap or
1367 function. If it is a keymap, keymap of MIME-View mode will be added
1368 to it. If it is a function, it will be bound as default binding of
1369 keymap of MIME-View mode.
1370 Optional argument REPRESENTATION-TYPE is representation-type of
1371 message. It must be nil, `binary' or `cooked'. If it is nil,
1372 `cooked' is used as default."
1375 (setq raw-buffer (current-buffer)))
1376 (or representation-type
1377 (setq representation-type
1379 (set-buffer raw-buffer)
1380 (cdr (or (assq major-mode mime-raw-representation-type-alist)
1381 (assq t mime-raw-representation-type-alist)))
1383 (if (eq representation-type 'binary)
1384 (setq representation-type 'buffer)
1386 (setq preview-buffer (mime-display-message
1387 (mime-open-entity representation-type raw-buffer)
1388 preview-buffer mother default-keymap-or-function))
1389 (or (get-buffer-window preview-buffer)
1390 (let ((r-win (get-buffer-window raw-buffer)))
1392 (set-window-buffer r-win preview-buffer)
1393 (let ((m-win (and mother (get-buffer-window mother))))
1395 (set-window-buffer m-win preview-buffer)
1396 (switch-to-buffer preview-buffer)
1399 (defun mime-view-mode (&optional mother ctl encoding
1400 raw-buffer preview-buffer
1401 default-keymap-or-function)
1402 "Major mode for viewing MIME message.
1404 Here is a list of the standard keys for mime-view-mode.
1409 u Move to upper content
1410 p or M-TAB Move to previous content
1411 n or TAB Move to next content
1412 SPC Scroll up or move to next content
1413 M-SPC or DEL Scroll down or move to previous content
1414 RET Move to next line
1415 M-RET Move to previous line
1416 v Decode current content as `play mode'
1417 e Decode current content as `extract mode'
1418 C-c C-p Decode current content as `print mode'
1419 a Followup to current content.
1421 button-2 Move to point under the mouse cursor
1422 and decode current content as `play mode'
1425 (unless mime-view-redisplay
1427 (if raw-buffer (set-buffer raw-buffer))
1430 (or (assq major-mode mime-raw-representation-type-alist)
1431 (assq t mime-raw-representation-type-alist)))))
1432 (if (eq type 'binary)
1435 (setq mime-message-structure (mime-open-entity type raw-buffer))
1436 (or (mime-entity-content-type mime-message-structure)
1437 (mime-entity-set-content-type mime-message-structure ctl))
1439 (or (mime-entity-encoding mime-message-structure)
1440 (mime-entity-set-encoding mime-message-structure encoding))
1442 (mime-display-message mime-message-structure preview-buffer
1443 mother default-keymap-or-function)
1450 (defun mime-preview-find-boundary-info (&optional get-mother)
1454 (while (null (setq entity
1455 (get-text-property (point) 'mime-view-entity)))
1457 (setq p-beg (previous-single-property-change (point) 'mime-view-entity))
1458 (setq entity-node-id (mime-entity-node-id entity))
1459 (setq len (length entity-node-id))
1462 (if (eq (next-single-property-change (point-min)
1468 ((eq (next-single-property-change p-beg 'mime-view-entity)
1470 (setq p-beg (point))
1472 (setq p-end (next-single-property-change p-beg 'mime-view-entity))
1474 (setq p-end (point-max))
1476 ((null entity-node-id)
1477 (setq p-end (point-max))
1485 (next-single-property-change
1486 (point) 'mime-view-entity))
1488 (let ((rc (mime-entity-node-id
1489 (get-text-property (1- (point))
1490 'mime-view-entity))))
1491 (or (and (>= (setq i (- (length rc) len)) 0)
1492 (equal entity-node-id (nthcdr i rc)))
1495 (setq p-end (point-max))))
1497 (vector p-beg p-end entity)))
1503 (autoload 'mime-preview-play-current-entity "mime-play"
1504 "Play current entity." t)
1506 (defun mime-preview-extract-current-entity (&optional ignore-examples)
1507 "Extract current entity into file (maybe).
1508 It decodes current entity to call internal or external method as
1509 \"extract\" mode. The method is selected from variable
1510 `mime-acting-condition'."
1512 (mime-preview-play-current-entity ignore-examples "extract")
1515 (defun mime-preview-print-current-entity (&optional ignore-examples)
1516 "Print current entity (maybe).
1517 It decodes current entity to call internal or external method as
1518 \"print\" mode. The method is selected from variable
1519 `mime-acting-condition'."
1521 (mime-preview-play-current-entity ignore-examples "print")
1528 (defun mime-preview-follow-current-entity ()
1529 "Write follow message to current entity.
1530 It calls following-method selected from variable
1531 `mime-preview-following-method-alist'."
1533 (let ((entity (mime-preview-find-boundary-info t))
1536 (setq p-beg (aref entity 0)
1537 p-end (aref entity 1)
1538 entity (aref entity 2))
1539 (if (get-text-property p-beg 'mime-view-entity-body)
1542 (next-single-property-change
1543 p-beg 'mime-view-entity-body nil
1544 (or (next-single-property-change p-beg 'mime-view-entity)
1546 (let* ((mode (mime-preview-original-major-mode 'recursive))
1547 (entity-node-id (mime-entity-node-id entity))
1549 (format "%s-%s" (buffer-name) (reverse entity-node-id)))
1551 (the-buf (current-buffer))
1554 (set-buffer (setq new-buf (get-buffer-create new-name)))
1557 (insert-buffer-substring the-buf pb-beg p-end)
1558 (goto-char (point-min))
1559 (let ((current-entity
1560 (if (and (eq (mime-entity-media-type entity) 'message)
1561 (eq (mime-entity-media-subtype entity) 'rfc822))
1562 (car (mime-entity-children entity))
1564 (while (and current-entity
1565 (if (and (eq (mime-entity-media-type
1566 current-entity) 'message)
1567 (eq (mime-entity-media-subtype
1568 current-entity) 'rfc822))
1570 (mime-insert-header current-entity fields)
1572 (setq fields (std11-collect-field-names)
1573 current-entity (mime-entity-parent current-entity))
1575 (let ((rest mime-view-following-required-fields-list)
1578 (setq field-name (car rest))
1579 (or (std11-field-body field-name)
1582 (set-buffer the-buf)
1583 (let ((entity (when mime-mother-buffer
1584 (set-buffer mime-mother-buffer)
1585 (get-text-property (point)
1586 'mime-view-entity))))
1588 (null (setq ret (mime-entity-fetch-field
1589 entity field-name))))
1590 (setq entity (mime-entity-parent entity)))))
1592 (insert (concat field-name ": " ret "\n"))
1594 (setq rest (cdr rest))
1597 (let ((f (cdr (assq mode mime-preview-following-method-alist))))
1602 "Sorry, following method for %s is not implemented yet."
1611 (defun mime-preview-move-to-upper ()
1612 "Move to upper entity.
1613 If there is no upper entity, call function `mime-preview-quit'."
1616 (while (null (setq cinfo
1617 (get-text-property (point) 'mime-view-entity)))
1620 (let ((r (mime-entity-parent cinfo))
1623 (while (setq point (previous-single-property-change
1624 (point) 'mime-view-entity))
1626 (when (eq r (get-text-property (point) 'mime-view-entity))
1627 (if (or (eq mime-preview-move-scroll t)
1628 (and mime-preview-move-scroll
1631 (move-to-window-line -1)
1632 (forward-line (* -1 next-screen-context-lines))
1635 (recenter next-screen-context-lines))
1642 (defun mime-preview-move-to-previous ()
1643 "Move to previous entity.
1644 If there is no previous entity, it calls function registered in
1645 variable `mime-preview-over-to-previous-method-alist'."
1647 (while (and (not (bobp))
1648 (null (get-text-property (point) 'mime-view-entity)))
1651 (let ((point (previous-single-property-change (point) 'mime-view-entity)))
1653 (>= point (point-min)))
1654 (if (get-text-property (1- point) 'mime-view-entity)
1655 (progn (goto-char point)
1657 (or (eq mime-preview-move-scroll t)
1658 (and mime-preview-move-scroll
1661 (move-to-window-line 0)
1662 (forward-line next-screen-context-lines)
1665 (recenter (* -1 next-screen-context-lines))))
1666 (goto-char (1- point))
1667 (mime-preview-move-to-previous)
1669 (let ((f (assq (mime-preview-original-major-mode)
1670 mime-preview-over-to-previous-method-alist)))
1676 (defun mime-preview-move-to-next ()
1677 "Move to next entity.
1678 If there is no previous entity, it calls function registered in
1679 variable `mime-preview-over-to-next-method-alist'."
1681 (while (and (not (eobp))
1682 (null (get-text-property (point) 'mime-view-entity)))
1685 (let ((point (next-single-property-change (point) 'mime-view-entity)))
1687 (<= point (point-max)))
1690 (if (null (get-text-property point 'mime-view-entity))
1691 (mime-preview-move-to-next)
1693 (or (eq mime-preview-move-scroll t)
1694 (and mime-preview-move-scroll
1697 (move-to-window-line -1)
1699 (* -1 next-screen-context-lines))
1702 (recenter next-screen-context-lines))
1704 (let ((f (assq (mime-preview-original-major-mode)
1705 mime-preview-over-to-next-method-alist)))
1711 (defun mime-preview-scroll-up-entity (&optional h)
1712 "Scroll up current entity.
1713 If reached to (point-max), it calls function registered in variable
1714 `mime-preview-over-to-next-method-alist'."
1717 (let ((f (assq (mime-preview-original-major-mode)
1718 mime-preview-over-to-next-method-alist)))
1723 (or (next-single-property-change (point) 'mime-view-entity)
1725 (bottom (window-end (selected-window))))
1728 (progn (goto-char point)
1729 (recenter next-screen-context-lines))
1733 (goto-char (point-max)))))
1736 (defun mime-preview-scroll-down-entity (&optional h)
1737 "Scroll down current entity.
1738 If reached to (point-min), it calls function registered in variable
1739 `mime-preview-over-to-previous-method-alist'."
1742 (let ((f (assq (mime-preview-original-major-mode)
1743 mime-preview-over-to-previous-method-alist)))
1748 (or (previous-single-property-change (point) 'mime-view-entity)
1750 (top (window-start (selected-window))))
1753 (progn (goto-char point)
1754 (recenter (* -1 next-screen-context-lines)))
1757 (beginning-of-buffer
1758 (goto-char (point-min)))))
1761 (defun mime-preview-next-line-entity (&optional lines)
1762 "Scroll up one line (or prefix LINES lines).
1763 If LINES is negative, scroll down LINES lines."
1765 (mime-preview-scroll-up-entity (or lines 1))
1768 (defun mime-preview-previous-line-entity (&optional lines)
1769 "Scrroll down one line (or prefix LINES lines).
1770 If LINES is negative, scroll up LINES lines."
1772 (mime-preview-scroll-down-entity (or lines 1))
1779 (defun mime-preview-toggle-display (type &optional display)
1780 (let ((situation (mime-preview-find-boundary-info))
1781 (sym (intern (concat "*" (symbol-name type))))
1783 (setq p-beg (aref situation 0)
1784 p-end (aref situation 1)
1785 entity (aref situation 2)
1786 situation (get-text-property p-beg 'mime-view-situation))
1787 (cond ((eq display 'invisible)
1792 (eq (cdr (or (assq sym situation)
1793 (assq type situation)))
1795 (setq situation (put-alist sym (if display
1800 (let ((inhibit-read-only t))
1801 (delete-region p-beg p-end)
1802 (mime-display-entity entity situation)))
1803 (let ((ret (assoc situation mime-preview-situation-example-list)))
1805 (setcdr ret (1+ (cdr ret)))
1806 (add-to-list 'mime-preview-situation-example-list
1807 (cons situation 0))))))
1809 (defun mime-preview-toggle-header (&optional force-visible)
1811 (mime-preview-toggle-display 'header force-visible))
1813 (defun mime-preview-toggle-content (&optional force-visible)
1815 (mime-preview-toggle-display 'body force-visible))
1817 (defun mime-preview-show-header ()
1819 (mime-preview-toggle-display 'header 'visible))
1821 (defun mime-preview-show-content ()
1823 (mime-preview-toggle-display 'body 'visible))
1825 (defun mime-preview-hide-header ()
1827 (mime-preview-toggle-display 'header 'invisible))
1829 (defun mime-preview-hide-content ()
1831 (mime-preview-toggle-display 'body 'invisible))
1837 (defun mime-preview-quit ()
1838 "Quit from MIME-preview buffer.
1839 It calls function registered in variable
1840 `mime-preview-quitting-method-alist'."
1842 (let ((r (assq (mime-preview-original-major-mode)
1843 mime-preview-quitting-method-alist)))
1848 (defun mime-preview-kill-buffer ()
1850 (kill-buffer (current-buffer))
1857 (provide 'mime-view)
1859 (mime-view-read-situation-examples-file)
1861 ;;; mime-view.el ends here