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))
376 (file-readable-p file))
378 (insert-file-contents file)
379 (setq mime-situation-examples-file-coding-system
380 (and (boundp 'buffer-file-coding-system)
381 buffer-file-coding-system)
383 ;; ((boundp 'buffer-file-coding-system)
384 ;; (symbol-value 'buffer-file-coding-system))
385 ;; ((boundp 'file-coding-system)
386 ;; (symbol-value 'file-coding-system))
389 (condition-case error
391 (error (message "%s is broken: %s" file (cdr error))))
395 (while (and (> (length mime-preview-situation-example-list)
396 mime-preview-situation-example-list-max-size)
398 (setq mime-preview-situation-example-list
399 (mime-reduce-situation-examples
400 mime-preview-situation-example-list))
402 (error (setq mime-preview-situation-example-list nil)))
403 ;; (let ((rest mime-preview-situation-example-list))
405 ;; (ctree-set-calist-strictly 'mime-preview-condition
407 ;; (setq rest (cdr rest))))
410 (while (and (> (length mime-acting-situation-example-list)
411 mime-acting-situation-example-list-max-size)
413 (setq mime-acting-situation-example-list
414 (mime-reduce-situation-examples
415 mime-acting-situation-example-list))
417 (error (setq mime-acting-situation-example-list nil))))))
419 (defun mime-save-situation-examples ()
420 (if (or mime-preview-situation-example-list
421 mime-acting-situation-example-list)
422 (let ((file mime-situation-examples-file))
424 (insert ";;; " (file-name-nondirectory file) "\n")
425 (insert "\n;; This file is generated automatically by "
426 mime-view-version "\n\n")
427 (insert ";;; Code:\n\n")
428 (if mime-preview-situation-example-list
429 (pp `(setq mime-preview-situation-example-list
430 ',mime-preview-situation-example-list)
432 (if mime-acting-situation-example-list
433 (pp `(setq mime-acting-situation-example-list
434 ',mime-acting-situation-example-list)
437 (file-name-nondirectory file)
439 (setq buffer-file-coding-system
440 mime-situation-examples-file-coding-system)
442 ;; ((boundp 'buffer-file-coding-system)
443 ;; (setq buffer-file-coding-system
444 ;; mime-situation-examples-file-coding-system))
445 ;; ((boundp 'file-coding-system)
446 ;; (setq file-coding-system
447 ;; mime-situation-examples-file-coding-system)))
448 (setq buffer-file-name file)
451 (add-hook 'kill-emacs-hook 'mime-save-situation-examples)
453 (defun mime-reduce-situation-examples (situation-examples)
454 (let ((len (length situation-examples))
462 ir situation-examples)
466 jr situation-examples)
470 (setq ret (mime-compare-situation-with-example (car ic)(car jc))
472 det-ret (+ (length (car ic))(length (car jc)))
473 det-org (length (cdr ret))
474 freq (+ (cdr ic)(cdr jc)))
475 (cond ((< max-sim sim)
482 dest (cons (cdr ret) freq))
485 (cond ((> min-det-ret det-ret)
486 (setq min-det-ret det-ret
491 dest (cons (cdr ret) freq))
493 ((= min-det-ret det-ret)
494 (cond ((> min-det-org det-org)
495 (setq min-det-org det-org
499 dest (cons (cdr ret) freq))
501 ((= min-det-org det-org)
502 (cond ((> min-freq freq)
506 dest (cons (cdr ret) freq))
520 (setq jr (nthcdr (1- d-j) situation-examples))
521 (setcdr jr (cddr jr))
523 (setq situation-examples
524 (cdr situation-examples))
525 (setq ir (nthcdr (1- d-i) situation-examples))
526 (setcdr ir (cddr ir))
528 (if (setq ir (assoc (car dest) situation-examples))
530 (setcdr ir (+ (cdr ir)(cdr dest)))
532 (cons dest situation-examples)
533 ;; situation-examples may be modified.
537 ;;; @ presentation of preview
543 ;;; @@@ predicate function
546 ;; (defun mime-view-entity-button-visible-p (entity)
547 ;; "Return non-nil if header of ENTITY is visible.
548 ;; Please redefine this function if you want to change default setting."
549 ;; (let ((media-type (mime-entity-media-type entity))
550 ;; (media-subtype (mime-entity-media-subtype entity)))
551 ;; (or (not (eq media-type 'application))
552 ;; (and (not (eq media-subtype 'x-selection))
553 ;; (or (not (eq media-subtype 'octet-stream))
554 ;; (let ((mother-entity (mime-entity-parent entity)))
555 ;; (or (not (eq (mime-entity-media-type mother-entity)
557 ;; (not (eq (mime-entity-media-subtype mother-entity)
562 ;;; @@@ entity button generator
565 (defun mime-view-insert-entity-button (entity)
566 "Insert entity-button of ENTITY."
567 (let ((entity-node-id (mime-entity-node-id entity))
568 (params (mime-entity-parameters entity))
569 (subject (mime-view-entity-title entity)))
571 (let ((access-type (assoc "access-type" params))
572 (num (or (cdr (assoc "x-part-number" params))
573 (if (consp entity-node-id)
576 (format "%s" (1+ num))
578 (reverse entity-node-id) ".")
582 (let ((server (assoc "server" params)))
583 (setq access-type (cdr access-type))
585 (format "%s %s ([%s] %s)"
586 num subject access-type (cdr server))
587 (let ((site (cdr (assoc "site" params)))
588 (dir (cdr (assoc "directory" params)))
589 (url (cdr (assoc "url" params)))
592 (format "%s %s ([%s] %s)"
593 num subject access-type url)
594 (format "%s %s ([%s] %s:%s)"
595 num subject access-type site dir))
599 (let ((media-type (mime-entity-media-type entity))
600 (media-subtype (mime-entity-media-subtype entity))
601 (charset (cdr (assoc "charset" params)))
602 (encoding (mime-entity-encoding entity)))
606 (format " <%s/%s%s%s>"
607 media-type media-subtype
609 (concat "; " charset)
612 (concat " (" encoding ")")
614 (if (>= (+ (current-column)(length rest))(window-width))
618 (function mime-preview-play-current-entity))
625 (defvar mime-header-presentation-method-alist nil
626 "Alist of major mode vs. corresponding header-presentation-method functions.
627 Each element looks like (SYMBOL . FUNCTION).
628 SYMBOL must be major mode in raw-buffer or t. t means default.
629 Interface of FUNCTION must be (ENTITY SITUATION).")
631 (defvar mime-view-ignored-field-list
632 '(".*Received:" ".*Path:" ".*Id:" "^References:"
633 "^Replied:" "^Errors-To:"
634 "^Lines:" "^Sender:" ".*Host:" "^Xref:"
635 "^Content-Type:" "^Precedence:"
636 "^Status:" "^X-VM-.*:")
637 "All fields that match this list will be hidden in MIME preview buffer.
638 Each elements are regexp of field-name.")
640 (defvar mime-view-visible-field-list '("^Dnas.*:" "^Message-Id:")
641 "All fields that match this list will be displayed in MIME preview buffer.
642 Each elements are regexp of field-name.")
648 ;;; @@@ predicate function
651 (in-calist-package 'mime-view)
653 (defun mime-calist::field-match-method-as-default-rule (calist
654 field-type field-value)
655 (let ((s-field (assq field-type calist)))
656 (cond ((null s-field)
657 (cons (cons field-type field-value) calist)
661 (define-calist-field-match-method
662 'header #'mime-calist::field-match-method-as-default-rule)
664 (define-calist-field-match-method
665 'body #'mime-calist::field-match-method-as-default-rule)
668 (defvar mime-preview-condition nil
669 "Condition-tree about how to display entity.")
671 (ctree-set-calist-strictly
672 'mime-preview-condition '((type . application)(subtype . octet-stream)
675 (ctree-set-calist-strictly
676 'mime-preview-condition '((type . application)(subtype . octet-stream)
679 (ctree-set-calist-strictly
680 'mime-preview-condition '((type . application)(subtype . octet-stream)
684 (ctree-set-calist-strictly
685 'mime-preview-condition '((type . application)(subtype . pgp)
688 (ctree-set-calist-strictly
689 'mime-preview-condition '((type . application)(subtype . x-latex)
692 (ctree-set-calist-strictly
693 'mime-preview-condition '((type . application)(subtype . x-selection)
696 (ctree-set-calist-strictly
697 'mime-preview-condition '((type . application)(subtype . x-comment)
700 (ctree-set-calist-strictly
701 'mime-preview-condition '((type . message)(subtype . delivery-status)
704 (ctree-set-calist-strictly
705 'mime-preview-condition
707 (body-presentation-method . mime-display-text/plain)))
709 (ctree-set-calist-strictly
710 'mime-preview-condition
713 (body-presentation-method . mime-display-text/plain)))
715 (ctree-set-calist-strictly
716 'mime-preview-condition
717 '((type . text)(subtype . enriched)
719 (body-presentation-method . mime-display-text/enriched)))
721 (ctree-set-calist-strictly
722 'mime-preview-condition
723 '((type . text)(subtype . richtext)
725 (body-presentation-method . mime-display-text/richtext)))
727 (autoload 'mime-display-application/x-postpet "postpet")
729 (ctree-set-calist-strictly
730 'mime-preview-condition
731 '((type . application)(subtype . x-postpet)
733 (body-presentation-method . mime-display-application/x-postpet)))
735 (ctree-set-calist-strictly
736 'mime-preview-condition
737 '((type . text)(subtype . t)
739 (body-presentation-method . mime-display-text/plain)))
741 (ctree-set-calist-strictly
742 'mime-preview-condition
743 '((type . multipart)(subtype . alternative)
745 (body-presentation-method . mime-display-multipart/alternative)))
747 (ctree-set-calist-strictly
748 'mime-preview-condition
749 '((type . multipart)(subtype . t)
751 (body-presentation-method . mime-display-multipart/mixed)))
753 (ctree-set-calist-strictly
754 'mime-preview-condition
755 '((type . message)(subtype . partial)
757 (body-presentation-method . mime-display-message/partial-button)))
759 (ctree-set-calist-strictly
760 'mime-preview-condition
761 '((type . message)(subtype . rfc822)
763 (body-presentation-method . mime-display-multipart/mixed)
764 (childrens-situation (header . visible)
765 (entity-button . invisible))))
767 (ctree-set-calist-strictly
768 'mime-preview-condition
769 '((type . message)(subtype . news)
771 (body-presentation-method . mime-display-multipart/mixed)
772 (childrens-situation (header . visible)
773 (entity-button . invisible))))
776 ;;; @@@ entity presentation
779 (defun mime-display-text/plain (entity situation)
781 (narrow-to-region (point-max)(point-max))
783 (mime-insert-text-content entity)
785 (message "Can't decode current entity.")
787 (run-hooks 'mime-text-decode-hook)
788 (goto-char (point-max))
789 (if (not (eq (char-after (1- (point))) ?\n))
792 (mime-add-url-buttons)
793 (run-hooks 'mime-display-text/plain-hook)
796 (defun mime-display-text/richtext (entity situation)
798 (narrow-to-region (point-max)(point-max))
799 (mime-insert-text-content entity)
800 (run-hooks 'mime-text-decode-hook)
801 (let ((beg (point-min)))
802 (remove-text-properties beg (point-max) '(face nil))
803 (richtext-decode beg (point-max))
806 (defun mime-display-text/enriched (entity situation)
808 (narrow-to-region (point-max)(point-max))
809 (mime-insert-text-content entity)
810 (run-hooks 'mime-text-decode-hook)
811 (let ((beg (point-min)))
812 (remove-text-properties beg (point-max) '(face nil))
813 (enriched-decode beg (point-max))
817 (defvar mime-view-announcement-for-message/partial
818 (if (and (>= emacs-major-version 19) window-system)
820 \[[ This is message/partial style split message. ]]
821 \[[ Please press `v' key in this buffer ]]
822 \[[ or click here by mouse button-2. ]]"
824 \[[ This is message/partial style split message. ]]
825 \[[ Please press `v' key in this buffer. ]]"
828 (defun mime-display-message/partial-button (&optional entity situation)
830 (goto-char (point-max))
831 (if (not (search-backward "\n\n" nil t))
834 (goto-char (point-max))
835 (narrow-to-region (point-max)(point-max))
836 (insert mime-view-announcement-for-message/partial)
837 (mime-add-button (point-min)(point-max)
838 #'mime-preview-play-current-entity)
841 (defun mime-display-multipart/mixed (entity situation)
842 (let ((children (mime-entity-children entity))
843 (original-major-mode-cell (assq 'major-mode situation))
845 (cdr (assq 'childrens-situation situation))))
846 (if original-major-mode-cell
847 (setq default-situation
848 (cons original-major-mode-cell default-situation)))
850 (mime-display-entity (car children) nil default-situation)
851 (setq children (cdr children))
854 (defcustom mime-view-type-subtype-score-alist
855 '(((text . enriched) . 3)
856 ((text . richtext) . 2)
859 "Alist MEDIA-TYPE vs corresponding score.
860 MEDIA-TYPE must be (TYPE . SUBTYPE), TYPE or t. t means default."
862 :type '(repeat (cons (choice :tag "Media-Type"
863 (cons :tag "Type/Subtype"
864 (symbol :tag "Primary-type")
865 (symbol :tag "Subtype"))
867 (const :tag "Default" t))
870 (defun mime-display-multipart/alternative (entity situation)
871 (let* ((children (mime-entity-children entity))
872 (original-major-mode-cell (assq 'major-mode situation))
874 (cdr (assq 'childrens-situation situation)))
879 (if original-major-mode-cell
880 (setq default-situation
881 (cons original-major-mode-cell default-situation)))
886 (mime-find-entity-preview-situation
887 child default-situation)))
888 (if (cdr (assq 'body-presentation-method situation))
893 (cdr (assq 'type situation))
894 (cdr (assq 'subtype situation)))
895 mime-view-type-subtype-score-alist)
897 (cdr (assq 'type situation))
898 mime-view-type-subtype-score-alist)
901 mime-view-type-subtype-score-alist)
903 (if (> score max-score)
913 (let ((child (car children))
914 (situation (car situations)))
915 (mime-display-entity child (if (= i p)
917 (put-alist 'body 'invisible
918 (copy-alist situation)))))
919 (setq children (cdr children)
920 situations (cdr situations)
924 ;;; @ acting-condition
927 (defvar mime-acting-condition nil
928 "Condition-tree about how to process entity.")
930 (defun mime-view-read-mailcap-files (&optional files)
932 (setq files mime-view-mailcap-files))
935 (setq file (car files))
936 (if (file-readable-p file)
937 (setq entries (append entries (mime-parse-mailcap-file file))))
938 (setq files (cdr files)))
940 (let ((entry (car entries))
943 (let* ((field (car entry))
944 (field-type (car field)))
945 (cond ((eq field-type 'view) (setq view field))
946 ((eq field-type 'print) (setq print field))
947 ((memq field-type '(compose composetyped edit)))
948 (t (setq shared (cons field shared))))
950 (setq entry (cdr entry)))
951 (setq shared (nreverse shared))
952 (ctree-set-calist-with-default
953 'mime-acting-condition
954 (append shared (list '(mode . "play")(cons 'method (cdr view)))))
956 (ctree-set-calist-with-default
957 'mime-acting-condition
959 (list '(mode . "print")(cons 'method (cdr view)))))))
960 (setq entries (cdr entries)))))
962 (mime-view-read-mailcap-files)
964 (ctree-set-calist-strictly
965 'mime-acting-condition
966 '((type . application)(subtype . octet-stream)
968 (method . mime-detect-content)
971 (ctree-set-calist-with-default
972 'mime-acting-condition
974 (method . mime-save-content)))
976 (ctree-set-calist-strictly
977 'mime-acting-condition
978 '((type . text)(subtype . x-rot13-47)(mode . "play")
979 (method . mime-view-caesar)
981 (ctree-set-calist-strictly
982 'mime-acting-condition
983 '((type . text)(subtype . x-rot13-47-48)(mode . "play")
984 (method . mime-view-caesar)
987 (ctree-set-calist-strictly
988 'mime-acting-condition
989 '((type . message)(subtype . rfc822)(mode . "play")
990 (method . mime-view-message/rfc822)
992 (ctree-set-calist-strictly
993 'mime-acting-condition
994 '((type . message)(subtype . partial)(mode . "play")
995 (method . mime-store-message/partial-piece)
998 (ctree-set-calist-strictly
999 'mime-acting-condition
1000 '((type . message)(subtype . external-body)
1001 ("access-type" . "anon-ftp")
1002 (method . mime-view-message/external-anon-ftp)
1005 (ctree-set-calist-strictly
1006 'mime-acting-condition
1007 '((type . message)(subtype . external-body)
1008 ("access-type" . "url")
1009 (method . mime-view-message/external-url)
1012 (ctree-set-calist-strictly
1013 'mime-acting-condition
1014 '((type . application)(subtype . octet-stream)
1015 (method . mime-save-content)
1019 ;;; @ quitting method
1022 (defvar mime-preview-quitting-method-alist
1023 '((mime-show-message-mode
1024 . mime-preview-quitting-method-for-mime-show-message-mode))
1025 "Alist of major-mode vs. quitting-method of mime-view.")
1027 (defvar mime-preview-over-to-previous-method-alist nil
1028 "Alist of major-mode vs. over-to-previous-method of mime-view.")
1030 (defvar mime-preview-over-to-next-method-alist nil
1031 "Alist of major-mode vs. over-to-next-method of mime-view.")
1034 ;;; @ following method
1037 (defvar mime-preview-following-method-alist nil
1038 "Alist of major-mode vs. following-method of mime-view.")
1040 (defvar mime-view-following-required-fields-list
1047 (defun mime-display-entity (entity &optional situation
1048 default-situation preview-buffer)
1050 (setq preview-buffer (current-buffer)))
1051 (let* (e nb ne nhb nbb)
1052 (in-calist-package 'mime-view)
1055 (mime-find-entity-preview-situation entity default-situation)))
1056 (let ((button-is-invisible
1057 (eq (cdr (or (assq '*entity-button situation)
1058 (assq 'entity-button situation)))
1061 (eq (cdr (or (assq '*header situation)
1062 (assq 'header situation)))
1065 (eq (cdr (or (assq '*body situation)
1066 (assq 'body situation)))
1068 (children (mime-entity-children entity)))
1069 (set-buffer preview-buffer)
1071 (narrow-to-region nb nb)
1072 (or button-is-invisible
1073 ;; (if (mime-view-entity-button-visible-p entity)
1074 (mime-view-insert-entity-button entity)
1077 (if header-is-visible
1078 (let ((header-presentation-method
1079 (or (cdr (assq 'header-presentation-method situation))
1080 (cdr (assq (cdr (assq 'major-mode situation))
1081 mime-header-presentation-method-alist)))))
1083 (if header-presentation-method
1084 (funcall header-presentation-method entity situation)
1085 (mime-insert-header entity
1086 mime-view-ignored-field-list
1087 mime-view-visible-field-list))
1088 (run-hooks 'mime-display-header-hook)
1089 (put-text-property nhb (point-max) 'mime-view-entity-header entity)
1090 (goto-char (point-max))
1095 (let ((body-presentation-method
1096 (cdr (assq 'body-presentation-method situation))))
1097 (if (functionp body-presentation-method)
1098 (funcall body-presentation-method entity situation)
1099 (mime-display-text/plain entity situation)))
1100 (when button-is-invisible
1101 (goto-char (point-max))
1102 (mime-view-insert-entity-button entity)
1104 (unless header-is-visible
1105 (goto-char (point-max))
1108 (setq ne (point-max))
1110 (put-text-property nb ne 'mime-view-entity entity)
1111 (put-text-property nb ne 'mime-view-situation situation)
1112 (put-text-property nbb ne 'mime-view-entity-body entity)
1114 (if (and children body-is-visible)
1115 (let ((body-presentation-method
1116 (cdr (assq 'body-presentation-method situation))))
1117 (if (functionp body-presentation-method)
1118 (funcall body-presentation-method entity situation)
1119 (mime-display-multipart/mixed entity situation))))
1123 ;;; @ MIME viewer mode
1126 (defconst mime-view-menu-title "MIME-View")
1127 (defconst mime-view-menu-list
1128 '((up "Move to upper entity" mime-preview-move-to-upper)
1129 (previous "Move to previous entity" mime-preview-move-to-previous)
1130 (next "Move to next entity" mime-preview-move-to-next)
1131 (scroll-down "Scroll-down" mime-preview-scroll-down-entity)
1132 (scroll-up "Scroll-up" mime-preview-scroll-up-entity)
1133 (play "Play current entity" mime-preview-play-current-entity)
1134 (extract "Extract current entity" mime-preview-extract-current-entity)
1135 (print "Print current entity" mime-preview-print-current-entity)
1137 "Menu for MIME Viewer")
1139 (cond ((featurep 'xemacs)
1140 (defvar mime-view-xemacs-popup-menu
1141 (cons mime-view-menu-title
1144 (vector (nth 1 item)(nth 2 item) t)
1146 mime-view-menu-list)))
1147 (defun mime-view-xemacs-popup-menu (event)
1148 "Popup the menu in the MIME Viewer buffer"
1150 (select-window (event-window event))
1151 (set-buffer (event-buffer event))
1152 (popup-menu 'mime-view-xemacs-popup-menu))
1153 (defvar mouse-button-2 'button2)
1154 (defvar mouse-button-3 'button3)
1157 (defvar mime-view-popup-menu
1158 (let ((menu (make-sparse-keymap mime-view-menu-title)))
1162 (list (intern (nth 1 item)) 'menu-item
1163 (nth 1 item)(nth 2 item))
1165 mime-view-menu-list))))
1166 (defun mime-view-popup-menu (event)
1167 "Popup the menu in the MIME Viewer buffer"
1169 (let ((menu mime-view-popup-menu) events func)
1170 (setq events (x-popup-menu t menu))
1172 (setq func (lookup-key menu (apply #'vector events)))
1175 (defvar mouse-button-2 [mouse-2])
1176 (defvar mouse-button-3 [mouse-3])
1179 (defun mime-view-define-keymap (&optional default)
1180 (let ((mime-view-mode-map (if (keymapp default)
1181 (copy-keymap default)
1182 (make-sparse-keymap))))
1183 (define-key mime-view-mode-map
1184 "u" (function mime-preview-move-to-upper))
1185 (define-key mime-view-mode-map
1186 "p" (function mime-preview-move-to-previous))
1187 (define-key mime-view-mode-map
1188 "n" (function mime-preview-move-to-next))
1189 (define-key mime-view-mode-map
1190 "\e\t" (function mime-preview-move-to-previous))
1191 (define-key mime-view-mode-map
1192 "\t" (function mime-preview-move-to-next))
1193 (define-key mime-view-mode-map
1194 " " (function mime-preview-scroll-up-entity))
1195 (define-key mime-view-mode-map
1196 "\M- " (function mime-preview-scroll-down-entity))
1197 (define-key mime-view-mode-map
1198 "\177" (function mime-preview-scroll-down-entity))
1199 (define-key mime-view-mode-map
1200 "\C-m" (function mime-preview-next-line-entity))
1201 (define-key mime-view-mode-map
1202 "\C-\M-m" (function mime-preview-previous-line-entity))
1203 (define-key mime-view-mode-map
1204 "v" (function mime-preview-play-current-entity))
1205 (define-key mime-view-mode-map
1206 "e" (function mime-preview-extract-current-entity))
1207 (define-key mime-view-mode-map
1208 "\C-c\C-p" (function mime-preview-print-current-entity))
1210 (define-key mime-view-mode-map
1211 "\C-c\C-t\C-f" (function mime-preview-toggle-header))
1212 (define-key mime-view-mode-map
1213 "\C-c\C-th" (function mime-preview-toggle-header))
1214 (define-key mime-view-mode-map
1215 "\C-c\C-t\C-c" (function mime-preview-toggle-content))
1217 (define-key mime-view-mode-map
1218 "\C-c\C-v\C-f" (function mime-preview-show-header))
1219 (define-key mime-view-mode-map
1220 "\C-c\C-vh" (function mime-preview-show-header))
1221 (define-key mime-view-mode-map
1222 "\C-c\C-v\C-c" (function mime-preview-show-content))
1224 (define-key mime-view-mode-map
1225 "\C-c\C-d\C-f" (function mime-preview-hide-header))
1226 (define-key mime-view-mode-map
1227 "\C-c\C-dh" (function mime-preview-hide-header))
1228 (define-key mime-view-mode-map
1229 "\C-c\C-d\C-c" (function mime-preview-hide-content))
1231 (define-key mime-view-mode-map
1232 "a" (function mime-preview-follow-current-entity))
1233 (define-key mime-view-mode-map
1234 "q" (function mime-preview-quit))
1235 (define-key mime-view-mode-map
1236 "\C-c\C-x" (function mime-preview-kill-buffer))
1237 ;; (define-key mime-view-mode-map
1238 ;; "<" (function beginning-of-buffer))
1239 ;; (define-key mime-view-mode-map
1240 ;; ">" (function end-of-buffer))
1241 (define-key mime-view-mode-map
1242 "?" (function describe-mode))
1243 (define-key mime-view-mode-map
1244 [tab] (function mime-preview-move-to-next))
1245 (define-key mime-view-mode-map
1246 [delete] (function mime-preview-scroll-down-entity))
1247 (define-key mime-view-mode-map
1248 [backspace] (function mime-preview-scroll-down-entity))
1249 (if (functionp default)
1250 (cond ((featurep 'xemacs)
1251 (set-keymap-default-binding mime-view-mode-map default)
1254 (setq mime-view-mode-map
1255 (append mime-view-mode-map (list (cons t default))))
1258 (define-key mime-view-mode-map
1259 mouse-button-2 (function mime-button-dispatcher))
1261 (cond ((featurep 'xemacs)
1262 (define-key mime-view-mode-map
1263 mouse-button-3 (function mime-view-xemacs-popup-menu))
1265 ((>= emacs-major-version 19)
1266 (define-key mime-view-mode-map
1267 mouse-button-3 (function mime-view-popup-menu))
1268 (define-key mime-view-mode-map [menu-bar mime-view]
1269 (cons mime-view-menu-title
1270 (make-sparse-keymap mime-view-menu-title)))
1273 (define-key mime-view-mode-map
1274 (vector 'menu-bar 'mime-view (car item))
1275 (cons (nth 1 item)(nth 2 item)))
1277 (reverse mime-view-menu-list))
1279 ;; (run-hooks 'mime-view-define-keymap-hook)
1280 mime-view-mode-map))
1282 (defvar mime-view-mode-default-map (mime-view-define-keymap))
1285 (defsubst mime-maybe-hide-echo-buffer ()
1286 "Clear mime-echo buffer and delete window for it."
1287 (let ((buf (get-buffer mime-echo-buffer-name)))
1292 (let ((win (get-buffer-window buf)))
1299 (defvar mime-view-redisplay nil)
1302 (defun mime-display-message (message &optional preview-buffer
1303 mother default-keymap-or-function
1304 original-major-mode keymap)
1305 "View MESSAGE in MIME-View mode.
1307 Optional argument PREVIEW-BUFFER specifies the buffer of the
1308 presentation. It must be either nil or a name of preview buffer.
1310 Optional argument MOTHER specifies mother-buffer of the preview-buffer.
1312 Optional argument DEFAULT-KEYMAP-OR-FUNCTION is nil, keymap or
1313 function. If it is a keymap, keymap of MIME-View mode will be added
1314 to it. If it is a function, it will be bound as default binding of
1315 keymap of MIME-View mode.
1317 Optional argument ORIGINAL-MAJOR-MODE is major-mode of representation
1318 buffer of MESSAGE. If it is nil, current `major-mode' is used.
1320 Optional argument KEYMAP is keymap of MIME-View mode. If it is
1321 non-nil, DEFAULT-KEYMAP-OR-FUNCTION is ignored. If it is nil,
1322 `mime-view-mode-default-map' is used."
1323 (mime-maybe-hide-echo-buffer)
1324 (let ((win-conf (current-window-configuration)))
1326 (setq preview-buffer
1327 (concat "*Preview-" (mime-entity-name message) "*")))
1328 (or original-major-mode
1329 (setq original-major-mode major-mode))
1330 (let ((inhibit-read-only t))
1331 (set-buffer (get-buffer-create preview-buffer))
1335 (setq mime-mother-buffer mother))
1336 (setq mime-preview-original-window-configuration win-conf)
1337 (setq major-mode 'mime-view-mode)
1338 (setq mode-name "MIME-View")
1339 (mime-display-entity message nil
1340 `((entity-button . invisible)
1342 (major-mode . ,original-major-mode))
1346 (if default-keymap-or-function
1347 (mime-view-define-keymap default-keymap-or-function)
1348 mime-view-mode-default-map)))
1350 (next-single-property-change (point-min) 'mime-view-entity)))
1353 (goto-char (point-min))
1354 (search-forward "\n\n" nil t)))
1355 (run-hooks 'mime-view-mode-hook)
1356 (set-buffer-modified-p nil)
1357 (setq buffer-read-only t)
1361 (defun mime-view-buffer (&optional raw-buffer preview-buffer mother
1362 default-keymap-or-function
1363 representation-type)
1364 "View RAW-BUFFER in MIME-View mode.
1365 Optional argument PREVIEW-BUFFER is either nil or a name of preview
1367 Optional argument DEFAULT-KEYMAP-OR-FUNCTION is nil, keymap or
1368 function. If it is a keymap, keymap of MIME-View mode will be added
1369 to it. If it is a function, it will be bound as default binding of
1370 keymap of MIME-View mode.
1371 Optional argument REPRESENTATION-TYPE is representation-type of
1372 message. It must be nil, `binary' or `cooked'. If it is nil,
1373 `cooked' is used as default."
1376 (setq raw-buffer (current-buffer)))
1377 (or representation-type
1378 (setq representation-type
1380 (set-buffer raw-buffer)
1381 (cdr (or (assq major-mode mime-raw-representation-type-alist)
1382 (assq t mime-raw-representation-type-alist)))
1384 (if (eq representation-type 'binary)
1385 (setq representation-type 'buffer)
1387 (setq preview-buffer (mime-display-message
1388 (mime-open-entity representation-type raw-buffer)
1389 preview-buffer mother default-keymap-or-function))
1390 (or (get-buffer-window preview-buffer)
1391 (let ((r-win (get-buffer-window raw-buffer)))
1393 (set-window-buffer r-win preview-buffer)
1394 (let ((m-win (and mother (get-buffer-window mother))))
1396 (set-window-buffer m-win preview-buffer)
1397 (switch-to-buffer preview-buffer)
1400 (defun mime-view-mode (&optional mother ctl encoding
1401 raw-buffer preview-buffer
1402 default-keymap-or-function)
1403 "Major mode for viewing MIME message.
1405 Here is a list of the standard keys for mime-view-mode.
1410 u Move to upper content
1411 p or M-TAB Move to previous content
1412 n or TAB Move to next content
1413 SPC Scroll up or move to next content
1414 M-SPC or DEL Scroll down or move to previous content
1415 RET Move to next line
1416 M-RET Move to previous line
1417 v Decode current content as `play mode'
1418 e Decode current content as `extract mode'
1419 C-c C-p Decode current content as `print mode'
1420 a Followup to current content.
1422 button-2 Move to point under the mouse cursor
1423 and decode current content as `play mode'
1426 (unless mime-view-redisplay
1428 (if raw-buffer (set-buffer raw-buffer))
1431 (or (assq major-mode mime-raw-representation-type-alist)
1432 (assq t mime-raw-representation-type-alist)))))
1433 (if (eq type 'binary)
1436 (setq mime-message-structure (mime-open-entity type raw-buffer))
1437 (or (mime-entity-content-type mime-message-structure)
1438 (mime-entity-set-content-type mime-message-structure ctl))
1440 (or (mime-entity-encoding mime-message-structure)
1441 (mime-entity-set-encoding mime-message-structure encoding))
1443 (mime-display-message mime-message-structure preview-buffer
1444 mother default-keymap-or-function)
1451 (defun mime-preview-find-boundary-info (&optional get-mother)
1455 (while (null (setq entity
1456 (get-text-property (point) 'mime-view-entity)))
1458 (setq p-beg (previous-single-property-change (point) 'mime-view-entity))
1459 (setq entity-node-id (mime-entity-node-id entity))
1460 (setq len (length entity-node-id))
1463 (if (eq (next-single-property-change (point-min)
1469 ((eq (next-single-property-change p-beg 'mime-view-entity)
1471 (setq p-beg (point))
1473 (setq p-end (next-single-property-change p-beg 'mime-view-entity))
1475 (setq p-end (point-max))
1477 ((null entity-node-id)
1478 (setq p-end (point-max))
1486 (next-single-property-change
1487 (point) 'mime-view-entity))
1489 (let ((rc (mime-entity-node-id
1490 (get-text-property (1- (point))
1491 'mime-view-entity))))
1492 (or (and (>= (setq i (- (length rc) len)) 0)
1493 (equal entity-node-id (nthcdr i rc)))
1496 (setq p-end (point-max))))
1498 (vector p-beg p-end entity)))
1504 (autoload 'mime-preview-play-current-entity "mime-play"
1505 "Play current entity." t)
1507 (defun mime-preview-extract-current-entity (&optional ignore-examples)
1508 "Extract current entity into file (maybe).
1509 It decodes current entity to call internal or external method as
1510 \"extract\" mode. The method is selected from variable
1511 `mime-acting-condition'."
1513 (mime-preview-play-current-entity ignore-examples "extract")
1516 (defun mime-preview-print-current-entity (&optional ignore-examples)
1517 "Print current entity (maybe).
1518 It decodes current entity to call internal or external method as
1519 \"print\" mode. The method is selected from variable
1520 `mime-acting-condition'."
1522 (mime-preview-play-current-entity ignore-examples "print")
1529 (defun mime-preview-follow-current-entity ()
1530 "Write follow message to current entity.
1531 It calls following-method selected from variable
1532 `mime-preview-following-method-alist'."
1534 (let ((entity (mime-preview-find-boundary-info t))
1537 (setq p-beg (aref entity 0)
1538 p-end (aref entity 1)
1539 entity (aref entity 2))
1540 (if (get-text-property p-beg 'mime-view-entity-body)
1543 (next-single-property-change
1544 p-beg 'mime-view-entity-body nil
1545 (or (next-single-property-change p-beg 'mime-view-entity)
1547 (let* ((mode (mime-preview-original-major-mode 'recursive))
1548 (entity-node-id (mime-entity-node-id entity))
1550 (format "%s-%s" (buffer-name) (reverse entity-node-id)))
1552 (the-buf (current-buffer))
1555 (set-buffer (setq new-buf (get-buffer-create new-name)))
1558 (insert-buffer-substring the-buf pb-beg p-end)
1559 (goto-char (point-min))
1560 (let ((current-entity
1561 (if (and (eq (mime-entity-media-type entity) 'message)
1562 (eq (mime-entity-media-subtype entity) 'rfc822))
1563 (car (mime-entity-children entity))
1565 (while (and current-entity
1566 (if (and (eq (mime-entity-media-type
1567 current-entity) 'message)
1568 (eq (mime-entity-media-subtype
1569 current-entity) 'rfc822))
1571 (mime-insert-header current-entity fields)
1573 (setq fields (std11-collect-field-names)
1574 current-entity (mime-entity-parent current-entity))
1576 (let ((rest mime-view-following-required-fields-list)
1579 (setq field-name (car rest))
1580 (or (std11-field-body field-name)
1583 (set-buffer the-buf)
1584 (let ((entity (when mime-mother-buffer
1585 (set-buffer mime-mother-buffer)
1586 (get-text-property (point)
1587 'mime-view-entity))))
1589 (null (setq ret (mime-entity-fetch-field
1590 entity field-name))))
1591 (setq entity (mime-entity-parent entity)))))
1593 (insert (concat field-name ": " ret "\n"))
1595 (setq rest (cdr rest))
1598 (let ((f (cdr (assq mode mime-preview-following-method-alist))))
1603 "Sorry, following method for %s is not implemented yet."
1612 (defun mime-preview-move-to-upper ()
1613 "Move to upper entity.
1614 If there is no upper entity, call function `mime-preview-quit'."
1617 (while (null (setq cinfo
1618 (get-text-property (point) 'mime-view-entity)))
1621 (let ((r (mime-entity-parent cinfo))
1624 (while (setq point (previous-single-property-change
1625 (point) 'mime-view-entity))
1627 (when (eq r (get-text-property (point) 'mime-view-entity))
1628 (if (or (eq mime-preview-move-scroll t)
1629 (and mime-preview-move-scroll
1632 (move-to-window-line -1)
1633 (forward-line (* -1 next-screen-context-lines))
1636 (recenter next-screen-context-lines))
1643 (defun mime-preview-move-to-previous ()
1644 "Move to previous entity.
1645 If there is no previous entity, it calls function registered in
1646 variable `mime-preview-over-to-previous-method-alist'."
1648 (while (and (not (bobp))
1649 (null (get-text-property (point) 'mime-view-entity)))
1652 (let ((point (previous-single-property-change (point) 'mime-view-entity)))
1654 (>= point (point-min)))
1655 (if (get-text-property (1- point) 'mime-view-entity)
1656 (progn (goto-char point)
1658 (or (eq mime-preview-move-scroll t)
1659 (and mime-preview-move-scroll
1662 (move-to-window-line 0)
1663 (forward-line next-screen-context-lines)
1666 (recenter (* -1 next-screen-context-lines))))
1667 (goto-char (1- point))
1668 (mime-preview-move-to-previous)
1670 (let ((f (assq (mime-preview-original-major-mode)
1671 mime-preview-over-to-previous-method-alist)))
1677 (defun mime-preview-move-to-next ()
1678 "Move to next entity.
1679 If there is no previous entity, it calls function registered in
1680 variable `mime-preview-over-to-next-method-alist'."
1682 (while (and (not (eobp))
1683 (null (get-text-property (point) 'mime-view-entity)))
1686 (let ((point (next-single-property-change (point) 'mime-view-entity)))
1688 (<= point (point-max)))
1691 (if (null (get-text-property point 'mime-view-entity))
1692 (mime-preview-move-to-next)
1694 (or (eq mime-preview-move-scroll t)
1695 (and mime-preview-move-scroll
1698 (move-to-window-line -1)
1700 (* -1 next-screen-context-lines))
1703 (recenter next-screen-context-lines))
1705 (let ((f (assq (mime-preview-original-major-mode)
1706 mime-preview-over-to-next-method-alist)))
1712 (defun mime-preview-scroll-up-entity (&optional h)
1713 "Scroll up current entity.
1714 If reached to (point-max), it calls function registered in variable
1715 `mime-preview-over-to-next-method-alist'."
1718 (let ((f (assq (mime-preview-original-major-mode)
1719 mime-preview-over-to-next-method-alist)))
1724 (or (next-single-property-change (point) 'mime-view-entity)
1726 (bottom (window-end (selected-window))))
1729 (progn (goto-char point)
1730 (recenter next-screen-context-lines))
1734 (goto-char (point-max)))))
1737 (defun mime-preview-scroll-down-entity (&optional h)
1738 "Scroll down current entity.
1739 If reached to (point-min), it calls function registered in variable
1740 `mime-preview-over-to-previous-method-alist'."
1743 (let ((f (assq (mime-preview-original-major-mode)
1744 mime-preview-over-to-previous-method-alist)))
1749 (or (previous-single-property-change (point) 'mime-view-entity)
1751 (top (window-start (selected-window))))
1754 (progn (goto-char point)
1755 (recenter (* -1 next-screen-context-lines)))
1758 (beginning-of-buffer
1759 (goto-char (point-min)))))
1762 (defun mime-preview-next-line-entity (&optional lines)
1763 "Scroll up one line (or prefix LINES lines).
1764 If LINES is negative, scroll down LINES lines."
1766 (mime-preview-scroll-up-entity (or lines 1))
1769 (defun mime-preview-previous-line-entity (&optional lines)
1770 "Scrroll down one line (or prefix LINES lines).
1771 If LINES is negative, scroll up LINES lines."
1773 (mime-preview-scroll-down-entity (or lines 1))
1780 (defun mime-preview-toggle-display (type &optional display)
1781 (let ((situation (mime-preview-find-boundary-info))
1782 (sym (intern (concat "*" (symbol-name type))))
1784 (setq p-beg (aref situation 0)
1785 p-end (aref situation 1)
1786 entity (aref situation 2)
1787 situation (get-text-property p-beg 'mime-view-situation))
1788 (cond ((eq display 'invisible)
1793 (eq (cdr (or (assq sym situation)
1794 (assq type situation)))
1796 (setq situation (put-alist sym (if display
1801 (let ((inhibit-read-only t))
1802 (delete-region p-beg p-end)
1803 (mime-display-entity entity situation)))
1804 (let ((ret (assoc situation mime-preview-situation-example-list)))
1806 (setcdr ret (1+ (cdr ret)))
1807 (add-to-list 'mime-preview-situation-example-list
1808 (cons situation 0))))))
1810 (defun mime-preview-toggle-header (&optional force-visible)
1812 (mime-preview-toggle-display 'header force-visible))
1814 (defun mime-preview-toggle-content (&optional force-visible)
1816 (mime-preview-toggle-display 'body force-visible))
1818 (defun mime-preview-show-header ()
1820 (mime-preview-toggle-display 'header 'visible))
1822 (defun mime-preview-show-content ()
1824 (mime-preview-toggle-display 'body 'visible))
1826 (defun mime-preview-hide-header ()
1828 (mime-preview-toggle-display 'header 'invisible))
1830 (defun mime-preview-hide-content ()
1832 (mime-preview-toggle-display 'body 'invisible))
1838 (defun mime-preview-quit ()
1839 "Quit from MIME-preview buffer.
1840 It calls function registered in variable
1841 `mime-preview-quitting-method-alist'."
1843 (let ((r (assq (mime-preview-original-major-mode)
1844 mime-preview-quitting-method-alist)))
1849 (defun mime-preview-kill-buffer ()
1851 (kill-buffer (current-buffer))
1858 (provide 'mime-view)
1861 (setq mime-situation-examples-file nil)
1862 ;; to avoid to read situation-examples-file at compile time.
1865 (mime-view-read-situation-examples-file)
1867 ;;; mime-view.el ends here