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.
36 (eval-when-compile (require 'static))
42 (defconst mime-view-version
43 (concat (mime-product-name mime-user-interface-product) " MIME-View "
44 (mapconcat #'number-to-string
45 (mime-product-version mime-user-interface-product) ".")
46 " (" (mime-product-code-name mime-user-interface-product) ")"))
52 (defgroup mime-view nil
56 (defcustom mime-situation-examples-file "~/.mime-example"
57 "*File name of situation-examples demonstrated by user."
61 (defcustom mime-preview-move-scroll nil
62 "*Decides whether to scroll when moving to next entity.
63 When t, scroll the buffer. Non-nil but not t means scroll when
64 the next entity is within next-screen-context-lines from top or
65 buttom. Nil means don't scroll at all."
67 :type '(choice (const :tag "Off" nil)
69 (sexp :tag "Situation" 1)))
71 (defcustom mime-view-mailcap-files
72 (let ((files '("/etc/mailcap" "/usr/etc/mailcap" "~/.mailcap")))
73 (or (member mime-mailcap-file files)
74 (setq files (cons mime-mailcap-file files)))
76 "List of mailcap files."
81 ;;; @ in raw-buffer (representation space)
84 (defvar mime-preview-buffer nil
85 "MIME-preview buffer corresponding with the (raw) buffer.")
86 (make-variable-buffer-local 'mime-preview-buffer)
89 (defvar mime-raw-representation-type-alist
90 '((mime-show-message-mode . binary)
91 (mime-temp-message-mode . binary)
94 "Alist of major-mode vs. representation-type of mime-raw-buffer.
95 Each element looks like (SYMBOL . REPRESENTATION-TYPE). SYMBOL is
96 major-mode or t. t means default. REPRESENTATION-TYPE must be
97 `binary' or `cooked'.")
100 ;;; @ in preview-buffer (presentation space)
103 (defvar mime-mother-buffer nil
104 "Mother buffer corresponding with the (MIME-preview) buffer.
105 If current MIME-preview buffer is generated by other buffer, such as
106 message/partial, it is called `mother-buffer'.")
107 (make-variable-buffer-local 'mime-mother-buffer)
109 ;; (defvar mime-raw-buffer nil
110 ;; "Raw buffer corresponding with the (MIME-preview) buffer.")
111 ;; (make-variable-buffer-local 'mime-raw-buffer)
113 (defvar mime-preview-original-window-configuration nil
114 "Window-configuration before mime-view-mode is called.")
115 (make-variable-buffer-local 'mime-preview-original-window-configuration)
117 (defun mime-preview-original-major-mode (&optional recursive point)
118 "Return major-mode of original buffer.
119 If optional argument RECURSIVE is non-nil and current buffer has
120 mime-mother-buffer, it returns original major-mode of the
122 (if (and recursive mime-mother-buffer)
124 (set-buffer mime-mother-buffer)
125 (mime-preview-original-major-mode recursive)
127 (cdr (assq 'major-mode
128 (get-text-property (or point
129 (if (> (point) (buffer-size))
130 (max (1- (point-max)) (point-min))
132 'mime-view-situation)))))
135 ;;; @ entity information
138 (defun mime-entity-situation (entity &optional situation)
139 "Return situation of ENTITY."
140 (let (rest param name)
142 (unless (assq 'type situation)
143 (setq rest (or (mime-entity-content-type entity)
144 (make-mime-content-type 'text 'plain))
145 situation (cons (car rest) situation)
148 (unless (assq 'subtype situation)
150 (setq rest (or (cdr (mime-entity-content-type entity))
151 '((subtype . plain)))))
152 (setq situation (cons (car rest) situation)
156 (setq param (car rest))
157 (or (assoc (car param) situation)
158 (setq situation (cons param situation)))
159 (setq rest (cdr rest)))
161 ;; Content-Disposition
163 (unless (assq 'disposition-type situation)
164 (setq rest (mime-entity-content-disposition entity))
166 (setq situation (cons (cons 'disposition-type
167 (mime-content-disposition-type rest))
169 rest (mime-content-disposition-parameters rest))
172 (setq param (car rest)
174 (if (cond ((string= name "filename")
175 (if (assq 'filename situation)
177 (setq name 'filename)))
178 ((string= name "creation-date")
179 (if (assq 'creation-date situation)
181 (setq name 'creation-date)))
182 ((string= name "modification-date")
183 (if (assq 'modification-date situation)
185 (setq name 'modification-date)))
186 ((string= name "read-date")
187 (if (assq 'read-date situation)
189 (setq name 'read-date)))
190 ((string= name "size")
191 (if (assq 'size situation)
194 (t (setq name (cons 'disposition name))
195 (if (assoc name situation)
199 (cons (cons name (cdr param))
201 (setq rest (cdr rest)))
203 ;; Content-Transfer-Encoding
204 (or (assq 'encoding situation)
206 (cons (cons 'encoding (or (mime-entity-encoding entity)
212 (defsubst mime-delq-null-situation (situations field
213 &rest ignored-values)
216 (let* ((situation (car situations))
217 (cell (assq field situation)))
219 (or (memq (cdr cell) ignored-values)
220 (setq dest (cons situation dest))
222 (setq situations (cdr situations)))
225 (defun mime-compare-situation-with-example (situation example)
226 (let ((example (copy-alist example))
229 (let* ((cell (car situation))
231 (ecell (assoc key example)))
233 (if (equal cell ecell)
234 (setq match (1+ match))
235 (setq example (delq ecell example))
238 (setq situation (cdr situation))
243 (defun mime-sort-situation (situation)
253 (disposition-type . 6)
257 (let ((ret (assq a-t order)))
259 (setq a-order (cdr ret))
265 (let ((ret (assq b-t order)))
267 (setq b-order (cdr ret))
272 (if (= a-order b-order)
273 (string< (format "%s" a-t)(format "%s" b-t))
278 (defun mime-unify-situations (entity-situation
279 condition situation-examples
280 &optional required-name ignored-value
283 (in-calist-package 'mime-view)
285 (ctree-find-calist condition entity-situation
288 (setq ret (mime-delq-null-situation ret required-name
290 (or (assq 'ignore-examples entity-situation)
298 (let ((situation (car rest))
299 (examples situation-examples))
302 (mime-compare-situation-with-example
303 situation (caar examples)))
304 (ret-score (car ret)))
305 (cond ((> ret-score max-score)
306 (setq max-score ret-score
307 max-escore (cdar examples)
308 max-examples (list (cdr ret))
309 max-situations (list situation))
311 ((= ret-score max-score)
312 (cond ((> (cdar examples) max-escore)
313 (setq max-escore (cdar examples)
314 max-examples (list (cdr ret))
315 max-situations (list situation))
317 ((= (cdar examples) max-escore)
319 (cons (cdr ret) max-examples))
320 (or (member situation max-situations)
322 (cons situation max-situations)))
324 (setq examples (cdr examples))))
325 (setq rest (cdr rest)))
327 (setq ret max-situations)
329 (let* ((example (car max-examples))
331 (assoc example situation-examples)))
333 (setcdr cell (1+ (cdr cell)))
334 (setq situation-examples
335 (cons (cons example 0)
338 (setq max-examples (cdr max-examples))
340 (cons ret situation-examples)
341 ;; ret: list of situations
342 ;; situation-examples: new examples (notoce that contents of
343 ;; argument `situation-examples' has bees modified)
346 (defun mime-view-entity-title (entity)
347 (or (mime-entity-read-field entity 'Content-Description)
348 (mime-entity-read-field entity 'Subject)
349 (mime-entity-filename entity)
352 (defvar mime-preview-situation-example-list nil)
353 (defvar mime-preview-situation-example-list-max-size 16)
354 ;; (defvar mime-preview-situation-example-condition nil)
356 (defun mime-find-entity-preview-situation (entity
357 &optional default-situation)
359 (mime-unify-situations
360 (append (mime-entity-situation entity)
362 mime-preview-condition
363 mime-preview-situation-example-list)))
364 (setq mime-preview-situation-example-list
370 (defvar mime-acting-situation-example-list nil)
371 (defvar mime-acting-situation-example-list-max-size 16)
372 (defvar mime-situation-examples-file-coding-system nil)
374 (defun mime-view-read-situation-examples-file (&optional file)
376 (setq file mime-situation-examples-file))
378 (file-readable-p file))
380 (insert-file-contents file)
381 (setq mime-situation-examples-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))
388 ;; (and (boundp 'buffer-file-coding-system)
389 ;; buffer-file-coding-system)
391 (condition-case error
393 (error (message "%s is broken: %s" file (cdr error))))
397 (while (and (> (length mime-preview-situation-example-list)
398 mime-preview-situation-example-list-max-size)
400 (setq mime-preview-situation-example-list
401 (mime-reduce-situation-examples
402 mime-preview-situation-example-list))
404 (error (setq mime-preview-situation-example-list nil)))
405 ;; (let ((rest mime-preview-situation-example-list))
407 ;; (ctree-set-calist-strictly 'mime-preview-condition
409 ;; (setq rest (cdr rest))))
412 (while (and (> (length mime-acting-situation-example-list)
413 mime-acting-situation-example-list-max-size)
415 (setq mime-acting-situation-example-list
416 (mime-reduce-situation-examples
417 mime-acting-situation-example-list))
419 (error (setq mime-acting-situation-example-list nil))))))
421 (defun mime-save-situation-examples ()
422 (if (or mime-preview-situation-example-list
423 mime-acting-situation-example-list)
424 (let ((file mime-situation-examples-file))
426 (insert ";;; " (file-name-nondirectory file) "\n")
427 (insert "\n;; This file is generated automatically by "
428 mime-view-version "\n\n")
429 (insert ";;; Code:\n\n")
430 (if mime-preview-situation-example-list
431 (pp `(setq mime-preview-situation-example-list
432 ',mime-preview-situation-example-list)
434 (if mime-acting-situation-example-list
435 (pp `(setq mime-acting-situation-example-list
436 ',mime-acting-situation-example-list)
439 (file-name-nondirectory file)
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-coding-system
449 ;; mime-situation-examples-file-coding-system)
450 (setq buffer-file-name file)
453 (add-hook 'kill-emacs-hook 'mime-save-situation-examples)
455 (defun mime-reduce-situation-examples (situation-examples)
456 (let ((len (length situation-examples))
464 ir situation-examples)
468 jr situation-examples)
472 (setq ret (mime-compare-situation-with-example (car ic)(car jc))
474 det-ret (+ (length (car ic))(length (car jc)))
475 det-org (length (cdr ret))
476 freq (+ (cdr ic)(cdr jc)))
477 (cond ((< max-sim sim)
484 dest (cons (cdr ret) freq))
487 (cond ((> min-det-ret det-ret)
488 (setq min-det-ret det-ret
493 dest (cons (cdr ret) freq))
495 ((= min-det-ret det-ret)
496 (cond ((> min-det-org det-org)
497 (setq min-det-org det-org
501 dest (cons (cdr ret) freq))
503 ((= min-det-org det-org)
504 (cond ((> min-freq freq)
508 dest (cons (cdr ret) freq))
522 (setq jr (nthcdr (1- d-j) situation-examples))
523 (setcdr jr (cddr jr))
525 (setq situation-examples
526 (cdr situation-examples))
527 (setq ir (nthcdr (1- d-i) situation-examples))
528 (setcdr ir (cddr ir))
530 (if (setq ir (assoc (car dest) situation-examples))
532 (setcdr ir (+ (cdr ir)(cdr dest)))
534 (cons dest situation-examples)
535 ;; situation-examples may be modified.
539 ;;; @ presentation of preview
545 ;;; @@@ predicate function
548 ;; (defun mime-view-entity-button-visible-p (entity)
549 ;; "Return non-nil if header of ENTITY is visible.
550 ;; Please redefine this function if you want to change default setting."
551 ;; (let ((media-type (mime-entity-media-type entity))
552 ;; (media-subtype (mime-entity-media-subtype entity)))
553 ;; (or (not (eq media-type 'application))
554 ;; (and (not (eq media-subtype 'x-selection))
555 ;; (or (not (eq media-subtype 'octet-stream))
556 ;; (let ((mother-entity (mime-entity-parent entity)))
557 ;; (or (not (eq (mime-entity-media-type mother-entity)
559 ;; (not (eq (mime-entity-media-subtype mother-entity)
564 ;;; @@@ entity button generator
567 (defun mime-view-insert-entity-button (entity)
568 "Insert entity-button of ENTITY."
569 (let ((entity-node-id (mime-entity-node-id entity))
570 (params (mime-entity-parameters entity))
571 (subject (mime-view-entity-title entity)))
573 (let ((access-type (assoc "access-type" params))
574 (num (or (cdr (assoc "x-part-number" params))
575 (if (consp entity-node-id)
578 (format "%s" (1+ num))
580 (reverse entity-node-id) ".")
584 (let ((server (assoc "server" params)))
585 (setq access-type (cdr access-type))
587 (format "%s %s ([%s] %s)"
588 num subject access-type (cdr server))
589 (let ((site (cdr (assoc "site" params)))
590 (dir (cdr (assoc "directory" params)))
591 (url (cdr (assoc "url" params)))
594 (format "%s %s ([%s] %s)"
595 num subject access-type url)
596 (format "%s %s ([%s] %s:%s)"
597 num subject access-type site dir))
601 (let ((media-type (mime-entity-media-type entity))
602 (media-subtype (mime-entity-media-subtype entity))
603 (charset (cdr (assoc "charset" params)))
604 (encoding (mime-entity-encoding entity)))
608 (format " <%s/%s%s%s>"
609 media-type media-subtype
611 (concat "; " charset)
614 (concat " (" encoding ")")
616 (if (>= (+ (current-column)(length rest))(window-width))
620 (function mime-preview-play-current-entity))
627 (defvar mime-header-presentation-method-alist nil
628 "Alist of major mode vs. corresponding header-presentation-method functions.
629 Each element looks like (SYMBOL . FUNCTION).
630 SYMBOL must be major mode in raw-buffer or t. t means default.
631 Interface of FUNCTION must be (ENTITY SITUATION).")
633 (defvar mime-view-ignored-field-list
634 '(".*Received:" ".*Path:" ".*Id:" "^References:"
635 "^Replied:" "^Errors-To:"
636 "^Lines:" "^Sender:" ".*Host:" "^Xref:"
637 "^Content-Type:" "^Precedence:"
638 "^Status:" "^X-VM-.*:")
639 "All fields that match this list will be hidden in MIME preview buffer.
640 Each elements are regexp of field-name.")
642 (defvar mime-view-visible-field-list '("^Dnas.*:" "^Message-Id:")
643 "All fields that match this list will be displayed in MIME preview buffer.
644 Each elements are regexp of field-name.")
650 ;;; @@@ predicate function
653 (in-calist-package 'mime-view)
655 (defun mime-calist::field-match-method-as-default-rule (calist
656 field-type field-value)
657 (let ((s-field (assq field-type calist)))
658 (cond ((null s-field)
659 (cons (cons field-type field-value) calist)
663 (define-calist-field-match-method
664 'header #'mime-calist::field-match-method-as-default-rule)
666 (define-calist-field-match-method
667 'body #'mime-calist::field-match-method-as-default-rule)
670 (defvar mime-preview-condition nil
671 "Condition-tree about how to display entity.")
673 (ctree-set-calist-strictly
674 'mime-preview-condition '((type . application)(subtype . octet-stream)
677 (ctree-set-calist-strictly
678 'mime-preview-condition '((type . application)(subtype . octet-stream)
681 (ctree-set-calist-strictly
682 'mime-preview-condition '((type . application)(subtype . octet-stream)
686 (ctree-set-calist-strictly
687 'mime-preview-condition '((type . application)(subtype . pgp)
690 (ctree-set-calist-strictly
691 'mime-preview-condition '((type . application)(subtype . x-latex)
694 (ctree-set-calist-strictly
695 'mime-preview-condition '((type . application)(subtype . x-selection)
698 (ctree-set-calist-strictly
699 'mime-preview-condition '((type . application)(subtype . x-comment)
702 (ctree-set-calist-strictly
703 'mime-preview-condition '((type . message)(subtype . delivery-status)
706 (ctree-set-calist-strictly
707 'mime-preview-condition
709 (body-presentation-method . mime-display-text/plain)))
711 (ctree-set-calist-strictly
712 'mime-preview-condition
715 (body-presentation-method . mime-display-text/plain)))
717 (ctree-set-calist-strictly
718 'mime-preview-condition
719 '((type . text)(subtype . enriched)
721 (body-presentation-method . mime-display-text/enriched)))
723 (ctree-set-calist-strictly
724 'mime-preview-condition
725 '((type . text)(subtype . richtext)
727 (body-presentation-method . mime-display-text/richtext)))
729 (autoload 'mime-display-application/x-postpet "postpet")
731 (ctree-set-calist-strictly
732 'mime-preview-condition
733 '((type . application)(subtype . x-postpet)
735 (body-presentation-method . mime-display-application/x-postpet)))
737 (ctree-set-calist-strictly
738 'mime-preview-condition
739 '((type . text)(subtype . t)
741 (body-presentation-method . mime-display-text/plain)))
743 (ctree-set-calist-strictly
744 'mime-preview-condition
745 '((type . multipart)(subtype . alternative)
747 (body-presentation-method . mime-display-multipart/alternative)))
749 (ctree-set-calist-strictly
750 'mime-preview-condition
751 '((type . multipart)(subtype . t)
753 (body-presentation-method . mime-display-multipart/mixed)))
755 (ctree-set-calist-strictly
756 'mime-preview-condition
757 '((type . message)(subtype . partial)
759 (body-presentation-method . mime-display-message/partial-button)))
761 (ctree-set-calist-strictly
762 'mime-preview-condition
763 '((type . message)(subtype . rfc822)
765 (body-presentation-method . mime-display-multipart/mixed)
766 (childrens-situation (header . visible)
767 (entity-button . invisible))))
769 (ctree-set-calist-strictly
770 'mime-preview-condition
771 '((type . message)(subtype . news)
773 (body-presentation-method . mime-display-multipart/mixed)
774 (childrens-situation (header . visible)
775 (entity-button . invisible))))
778 ;;; @@@ entity presentation
781 (defun mime-display-text/plain (entity situation)
783 (narrow-to-region (point-max)(point-max))
785 (mime-insert-text-content entity)
787 (message "Can't decode current entity.")
789 (run-hooks 'mime-text-decode-hook)
790 (goto-char (point-max))
791 (if (not (eq (char-after (1- (point))) ?\n))
794 (mime-add-url-buttons)
795 (run-hooks 'mime-display-text/plain-hook)
798 (defun mime-display-text/richtext (entity situation)
800 (narrow-to-region (point-max)(point-max))
801 (mime-insert-text-content entity)
802 (run-hooks 'mime-text-decode-hook)
803 (let ((beg (point-min)))
804 (remove-text-properties beg (point-max) '(face nil))
805 (richtext-decode beg (point-max))
808 (defun mime-display-text/enriched (entity situation)
810 (narrow-to-region (point-max)(point-max))
811 (mime-insert-text-content entity)
812 (run-hooks 'mime-text-decode-hook)
813 (let ((beg (point-min)))
814 (remove-text-properties beg (point-max) '(face nil))
815 (enriched-decode beg (point-max))
819 (defvar mime-view-announcement-for-message/partial
820 (if (and (>= emacs-major-version 19) window-system)
822 \[[ This is message/partial style split message. ]]
823 \[[ Please press `v' key in this buffer ]]
824 \[[ or click here by mouse button-2. ]]"
826 \[[ This is message/partial style split message. ]]
827 \[[ Please press `v' key in this buffer. ]]"
830 (defun mime-display-message/partial-button (&optional entity situation)
832 (goto-char (point-max))
833 (if (not (search-backward "\n\n" nil t))
836 (goto-char (point-max))
837 (narrow-to-region (point-max)(point-max))
838 (insert mime-view-announcement-for-message/partial)
839 (mime-add-button (point-min)(point-max)
840 #'mime-preview-play-current-entity)
843 (defun mime-display-multipart/mixed (entity situation)
844 (let ((children (mime-entity-children entity))
845 (original-major-mode-cell (assq 'major-mode situation))
847 (cdr (assq 'childrens-situation situation))))
848 (if original-major-mode-cell
849 (setq default-situation
850 (cons original-major-mode-cell default-situation)))
852 (mime-display-entity (car children) nil default-situation)
853 (setq children (cdr children))
856 (defcustom mime-view-type-subtype-score-alist
857 '(((text . enriched) . 3)
858 ((text . richtext) . 2)
861 "Alist MEDIA-TYPE vs corresponding score.
862 MEDIA-TYPE must be (TYPE . SUBTYPE), TYPE or t. t means default."
864 :type '(repeat (cons (choice :tag "Media-Type"
865 (cons :tag "Type/Subtype"
866 (symbol :tag "Primary-type")
867 (symbol :tag "Subtype"))
869 (const :tag "Default" t))
872 (defun mime-display-multipart/alternative (entity situation)
873 (let* ((children (mime-entity-children entity))
874 (original-major-mode-cell (assq 'major-mode situation))
876 (cdr (assq 'childrens-situation situation)))
881 (if original-major-mode-cell
882 (setq default-situation
883 (cons original-major-mode-cell default-situation)))
888 (mime-find-entity-preview-situation
889 child default-situation)))
890 (if (cdr (assq 'body-presentation-method situation))
895 (cdr (assq 'type situation))
896 (cdr (assq 'subtype situation)))
897 mime-view-type-subtype-score-alist)
899 (cdr (assq 'type situation))
900 mime-view-type-subtype-score-alist)
903 mime-view-type-subtype-score-alist)
905 (if (> score max-score)
915 (let ((child (car children))
916 (situation (car situations)))
917 (mime-display-entity child (if (= i p)
919 (put-alist 'body 'invisible
920 (copy-alist situation)))))
921 (setq children (cdr children)
922 situations (cdr situations)
926 ;;; @ acting-condition
929 (defvar mime-acting-condition nil
930 "Condition-tree about how to process entity.")
932 (defun mime-view-read-mailcap-files (&optional files)
934 (setq files mime-view-mailcap-files))
937 (setq file (car files))
938 (if (file-readable-p file)
939 (setq entries (append entries (mime-parse-mailcap-file file))))
940 (setq files (cdr files)))
942 (let ((entry (car entries))
945 (let* ((field (car entry))
946 (field-type (car field)))
947 (cond ((eq field-type 'view) (setq view field))
948 ((eq field-type 'print) (setq print field))
949 ((memq field-type '(compose composetyped edit)))
950 (t (setq shared (cons field shared))))
952 (setq entry (cdr entry)))
953 (setq shared (nreverse shared))
954 (ctree-set-calist-with-default
955 'mime-acting-condition
956 (append shared (list '(mode . "play")(cons 'method (cdr view)))))
958 (ctree-set-calist-with-default
959 'mime-acting-condition
961 (list '(mode . "print")(cons 'method (cdr view)))))))
962 (setq entries (cdr entries)))))
964 (mime-view-read-mailcap-files)
966 (ctree-set-calist-strictly
967 'mime-acting-condition
968 '((type . application)(subtype . octet-stream)
970 (method . mime-detect-content)
973 (ctree-set-calist-with-default
974 'mime-acting-condition
976 (method . mime-save-content)))
978 (ctree-set-calist-strictly
979 'mime-acting-condition
980 '((type . text)(subtype . x-rot13-47)(mode . "play")
981 (method . mime-view-caesar)
983 (ctree-set-calist-strictly
984 'mime-acting-condition
985 '((type . text)(subtype . x-rot13-47-48)(mode . "play")
986 (method . mime-view-caesar)
989 (ctree-set-calist-strictly
990 'mime-acting-condition
991 '((type . message)(subtype . rfc822)(mode . "play")
992 (method . mime-view-message/rfc822)
994 (ctree-set-calist-strictly
995 'mime-acting-condition
996 '((type . message)(subtype . partial)(mode . "play")
997 (method . mime-store-message/partial-piece)
1000 (ctree-set-calist-strictly
1001 'mime-acting-condition
1002 '((type . message)(subtype . external-body)
1003 ("access-type" . "anon-ftp")
1004 (method . mime-view-message/external-anon-ftp)
1007 (ctree-set-calist-strictly
1008 'mime-acting-condition
1009 '((type . message)(subtype . external-body)
1010 ("access-type" . "url")
1011 (method . mime-view-message/external-url)
1014 (ctree-set-calist-strictly
1015 'mime-acting-condition
1016 '((type . application)(subtype . octet-stream)
1017 (method . mime-save-content)
1021 ;;; @ quitting method
1024 (defvar mime-preview-quitting-method-alist
1025 '((mime-show-message-mode
1026 . mime-preview-quitting-method-for-mime-show-message-mode))
1027 "Alist of major-mode vs. quitting-method of mime-view.")
1029 (defvar mime-preview-over-to-previous-method-alist nil
1030 "Alist of major-mode vs. over-to-previous-method of mime-view.")
1032 (defvar mime-preview-over-to-next-method-alist nil
1033 "Alist of major-mode vs. over-to-next-method of mime-view.")
1036 ;;; @ following method
1039 (defvar mime-preview-following-method-alist nil
1040 "Alist of major-mode vs. following-method of mime-view.")
1042 (defvar mime-view-following-required-fields-list
1049 (defun mime-display-entity (entity &optional situation
1050 default-situation preview-buffer)
1052 (setq preview-buffer (current-buffer)))
1053 (let* (e nb ne nhb nbb)
1054 (in-calist-package 'mime-view)
1057 (mime-find-entity-preview-situation entity default-situation)))
1058 (let ((button-is-invisible
1059 (eq (cdr (or (assq '*entity-button situation)
1060 (assq 'entity-button situation)))
1063 (eq (cdr (or (assq '*header situation)
1064 (assq 'header situation)))
1067 (eq (cdr (or (assq '*body situation)
1068 (assq 'body situation)))
1070 (children (mime-entity-children entity)))
1071 (set-buffer preview-buffer)
1073 (narrow-to-region nb nb)
1074 (or button-is-invisible
1075 ;; (if (mime-view-entity-button-visible-p entity)
1076 (mime-view-insert-entity-button entity)
1079 (if header-is-visible
1080 (let ((header-presentation-method
1081 (or (cdr (assq 'header-presentation-method situation))
1082 (cdr (assq (cdr (assq 'major-mode situation))
1083 mime-header-presentation-method-alist)))))
1085 (if header-presentation-method
1086 (funcall header-presentation-method entity situation)
1087 (mime-insert-header entity
1088 mime-view-ignored-field-list
1089 mime-view-visible-field-list))
1090 (run-hooks 'mime-display-header-hook)
1091 (put-text-property nhb (point-max) 'mime-view-entity-header entity)
1092 (goto-char (point-max))
1097 (let ((body-presentation-method
1098 (cdr (assq 'body-presentation-method situation))))
1099 (if (functionp body-presentation-method)
1100 (funcall body-presentation-method entity situation)
1101 (mime-display-text/plain entity situation)))
1102 (when button-is-invisible
1103 (goto-char (point-max))
1104 (mime-view-insert-entity-button entity)
1106 (unless header-is-visible
1107 (goto-char (point-max))
1110 (setq ne (point-max))
1112 (put-text-property nb ne 'mime-view-entity entity)
1113 (put-text-property nb ne 'mime-view-situation situation)
1114 (put-text-property nbb ne 'mime-view-entity-body entity)
1116 (if (and children body-is-visible)
1117 (let ((body-presentation-method
1118 (cdr (assq 'body-presentation-method situation))))
1119 (if (functionp body-presentation-method)
1120 (funcall body-presentation-method entity situation)
1121 (mime-display-multipart/mixed entity situation))))
1125 ;;; @ MIME viewer mode
1128 (defconst mime-view-menu-title "MIME-View")
1129 (defconst mime-view-menu-list
1130 '((up "Move to upper entity" mime-preview-move-to-upper)
1131 (previous "Move to previous entity" mime-preview-move-to-previous)
1132 (next "Move to next entity" mime-preview-move-to-next)
1133 (scroll-down "Scroll-down" mime-preview-scroll-down-entity)
1134 (scroll-up "Scroll-up" mime-preview-scroll-up-entity)
1135 (play "Play current entity" mime-preview-play-current-entity)
1136 (extract "Extract current entity" mime-preview-extract-current-entity)
1137 (print "Print current entity" mime-preview-print-current-entity)
1139 "Menu for MIME Viewer")
1141 (cond ((featurep 'xemacs)
1142 (defvar mime-view-xemacs-popup-menu
1143 (cons mime-view-menu-title
1146 (vector (nth 1 item)(nth 2 item) t)
1148 mime-view-menu-list)))
1149 (defun mime-view-xemacs-popup-menu (event)
1150 "Popup the menu in the MIME Viewer buffer"
1152 (select-window (event-window event))
1153 (set-buffer (event-buffer event))
1154 (popup-menu 'mime-view-xemacs-popup-menu))
1155 (defvar mouse-button-2 'button2)
1156 (defvar mouse-button-3 'button3)
1159 (defvar mime-view-popup-menu
1160 (let ((menu (make-sparse-keymap mime-view-menu-title)))
1164 (list (intern (nth 1 item)) 'menu-item
1165 (nth 1 item)(nth 2 item))
1167 mime-view-menu-list))))
1168 (defun mime-view-popup-menu (event)
1169 "Popup the menu in the MIME Viewer buffer"
1171 (let ((menu mime-view-popup-menu) events func)
1172 (setq events (x-popup-menu t menu))
1174 (setq func (lookup-key menu (apply #'vector events)))
1177 (defvar mouse-button-2 [mouse-2])
1178 (defvar mouse-button-3 [mouse-3])
1181 (defun mime-view-define-keymap (&optional default)
1182 (let ((mime-view-mode-map (if (keymapp default)
1183 (copy-keymap default)
1184 (make-sparse-keymap))))
1185 (define-key mime-view-mode-map
1186 "u" (function mime-preview-move-to-upper))
1187 (define-key mime-view-mode-map
1188 "p" (function mime-preview-move-to-previous))
1189 (define-key mime-view-mode-map
1190 "n" (function mime-preview-move-to-next))
1191 (define-key mime-view-mode-map
1192 "\e\t" (function mime-preview-move-to-previous))
1193 (define-key mime-view-mode-map
1194 "\t" (function mime-preview-move-to-next))
1195 (define-key mime-view-mode-map
1196 " " (function mime-preview-scroll-up-entity))
1197 (define-key mime-view-mode-map
1198 "\M- " (function mime-preview-scroll-down-entity))
1199 (define-key mime-view-mode-map
1200 "\177" (function mime-preview-scroll-down-entity))
1201 (define-key mime-view-mode-map
1202 "\C-m" (function mime-preview-next-line-entity))
1203 (define-key mime-view-mode-map
1204 "\C-\M-m" (function mime-preview-previous-line-entity))
1205 (define-key mime-view-mode-map
1206 "v" (function mime-preview-play-current-entity))
1207 (define-key mime-view-mode-map
1208 "e" (function mime-preview-extract-current-entity))
1209 (define-key mime-view-mode-map
1210 "\C-c\C-p" (function mime-preview-print-current-entity))
1212 (define-key mime-view-mode-map
1213 "\C-c\C-t\C-f" (function mime-preview-toggle-header))
1214 (define-key mime-view-mode-map
1215 "\C-c\C-th" (function mime-preview-toggle-header))
1216 (define-key mime-view-mode-map
1217 "\C-c\C-t\C-c" (function mime-preview-toggle-content))
1219 (define-key mime-view-mode-map
1220 "\C-c\C-v\C-f" (function mime-preview-show-header))
1221 (define-key mime-view-mode-map
1222 "\C-c\C-vh" (function mime-preview-show-header))
1223 (define-key mime-view-mode-map
1224 "\C-c\C-v\C-c" (function mime-preview-show-content))
1226 (define-key mime-view-mode-map
1227 "\C-c\C-d\C-f" (function mime-preview-hide-header))
1228 (define-key mime-view-mode-map
1229 "\C-c\C-dh" (function mime-preview-hide-header))
1230 (define-key mime-view-mode-map
1231 "\C-c\C-d\C-c" (function mime-preview-hide-content))
1233 (define-key mime-view-mode-map
1234 "a" (function mime-preview-follow-current-entity))
1235 (define-key mime-view-mode-map
1236 "q" (function mime-preview-quit))
1237 (define-key mime-view-mode-map
1238 "\C-c\C-x" (function mime-preview-kill-buffer))
1239 ;; (define-key mime-view-mode-map
1240 ;; "<" (function beginning-of-buffer))
1241 ;; (define-key mime-view-mode-map
1242 ;; ">" (function end-of-buffer))
1243 (define-key mime-view-mode-map
1244 "?" (function describe-mode))
1245 (define-key mime-view-mode-map
1246 [tab] (function mime-preview-move-to-next))
1247 (define-key mime-view-mode-map
1248 [delete] (function mime-preview-scroll-down-entity))
1249 (define-key mime-view-mode-map
1250 [backspace] (function mime-preview-scroll-down-entity))
1251 (if (functionp default)
1252 (cond ((featurep 'xemacs)
1253 (set-keymap-default-binding mime-view-mode-map default)
1256 (setq mime-view-mode-map
1257 (append mime-view-mode-map (list (cons t default))))
1260 (define-key mime-view-mode-map
1261 mouse-button-2 (function mime-button-dispatcher))
1263 (cond ((featurep 'xemacs)
1264 (define-key mime-view-mode-map
1265 mouse-button-3 (function mime-view-xemacs-popup-menu))
1267 ((>= emacs-major-version 19)
1268 (define-key mime-view-mode-map
1269 mouse-button-3 (function mime-view-popup-menu))
1270 (define-key mime-view-mode-map [menu-bar mime-view]
1271 (cons mime-view-menu-title
1272 (make-sparse-keymap mime-view-menu-title)))
1275 (define-key mime-view-mode-map
1276 (vector 'menu-bar 'mime-view (car item))
1277 (cons (nth 1 item)(nth 2 item)))
1279 (reverse mime-view-menu-list))
1281 ;; (run-hooks 'mime-view-define-keymap-hook)
1282 mime-view-mode-map))
1284 (defvar mime-view-mode-default-map (mime-view-define-keymap))
1287 (defsubst mime-maybe-hide-echo-buffer ()
1288 "Clear mime-echo buffer and delete window for it."
1289 (let ((buf (get-buffer mime-echo-buffer-name)))
1294 (let ((win (get-buffer-window buf)))
1301 (defvar mime-view-redisplay nil)
1304 (defun mime-display-message (message &optional preview-buffer
1305 mother default-keymap-or-function
1306 original-major-mode keymap)
1307 "View MESSAGE in MIME-View mode.
1309 Optional argument PREVIEW-BUFFER specifies the buffer of the
1310 presentation. It must be either nil or a name of preview buffer.
1312 Optional argument MOTHER specifies mother-buffer of the preview-buffer.
1314 Optional argument DEFAULT-KEYMAP-OR-FUNCTION is nil, keymap or
1315 function. If it is a keymap, keymap of MIME-View mode will be added
1316 to it. If it is a function, it will be bound as default binding of
1317 keymap of MIME-View mode.
1319 Optional argument ORIGINAL-MAJOR-MODE is major-mode of representation
1320 buffer of MESSAGE. If it is nil, current `major-mode' is used.
1322 Optional argument KEYMAP is keymap of MIME-View mode. If it is
1323 non-nil, DEFAULT-KEYMAP-OR-FUNCTION is ignored. If it is nil,
1324 `mime-view-mode-default-map' is used."
1325 (mime-maybe-hide-echo-buffer)
1326 (let ((win-conf (current-window-configuration)))
1328 (setq preview-buffer
1329 (concat "*Preview-" (mime-entity-name message) "*")))
1330 (or original-major-mode
1331 (setq original-major-mode major-mode))
1332 (let ((inhibit-read-only t))
1333 (set-buffer (get-buffer-create preview-buffer))
1337 (setq mime-mother-buffer mother))
1338 (setq mime-preview-original-window-configuration win-conf)
1339 (setq major-mode 'mime-view-mode)
1340 (setq mode-name "MIME-View")
1341 (mime-display-entity message nil
1342 `((entity-button . invisible)
1344 (major-mode . ,original-major-mode))
1348 (if default-keymap-or-function
1349 (mime-view-define-keymap default-keymap-or-function)
1350 mime-view-mode-default-map)))
1352 (next-single-property-change (point-min) 'mime-view-entity)))
1355 (goto-char (point-min))
1356 (search-forward "\n\n" nil t)))
1357 (run-hooks 'mime-view-mode-hook)
1358 (set-buffer-modified-p nil)
1359 (setq buffer-read-only t)
1363 (defun mime-view-buffer (&optional raw-buffer preview-buffer mother
1364 default-keymap-or-function
1365 representation-type)
1366 "View RAW-BUFFER in MIME-View mode.
1367 Optional argument PREVIEW-BUFFER is either nil or a name of preview
1369 Optional argument DEFAULT-KEYMAP-OR-FUNCTION is nil, keymap or
1370 function. If it is a keymap, keymap of MIME-View mode will be added
1371 to it. If it is a function, it will be bound as default binding of
1372 keymap of MIME-View mode.
1373 Optional argument REPRESENTATION-TYPE is representation-type of
1374 message. It must be nil, `binary' or `cooked'. If it is nil,
1375 `cooked' is used as default."
1378 (setq raw-buffer (current-buffer)))
1379 (or representation-type
1380 (setq representation-type
1382 (set-buffer raw-buffer)
1383 (cdr (or (assq major-mode mime-raw-representation-type-alist)
1384 (assq t mime-raw-representation-type-alist)))
1386 (if (eq representation-type 'binary)
1387 (setq representation-type 'buffer)
1389 (setq preview-buffer (mime-display-message
1390 (mime-open-entity representation-type raw-buffer)
1391 preview-buffer mother default-keymap-or-function))
1392 (or (get-buffer-window preview-buffer)
1393 (let ((r-win (get-buffer-window raw-buffer)))
1395 (set-window-buffer r-win preview-buffer)
1396 (let ((m-win (and mother (get-buffer-window mother))))
1398 (set-window-buffer m-win preview-buffer)
1399 (switch-to-buffer preview-buffer)
1402 (defun mime-view-mode (&optional mother ctl encoding
1403 raw-buffer preview-buffer
1404 default-keymap-or-function)
1405 "Major mode for viewing MIME message.
1407 Here is a list of the standard keys for mime-view-mode.
1412 u Move to upper content
1413 p or M-TAB Move to previous content
1414 n or TAB Move to next content
1415 SPC Scroll up or move to next content
1416 M-SPC or DEL Scroll down or move to previous content
1417 RET Move to next line
1418 M-RET Move to previous line
1419 v Decode current content as `play mode'
1420 e Decode current content as `extract mode'
1421 C-c C-p Decode current content as `print mode'
1422 a Followup to current content.
1424 button-2 Move to point under the mouse cursor
1425 and decode current content as `play mode'
1428 (unless mime-view-redisplay
1430 (if raw-buffer (set-buffer raw-buffer))
1433 (or (assq major-mode mime-raw-representation-type-alist)
1434 (assq t mime-raw-representation-type-alist)))))
1435 (if (eq type 'binary)
1438 (setq mime-message-structure (mime-open-entity type raw-buffer))
1439 (or (mime-entity-content-type mime-message-structure)
1440 (mime-entity-set-content-type mime-message-structure ctl))
1442 (or (mime-entity-encoding mime-message-structure)
1443 (mime-entity-set-encoding mime-message-structure encoding))
1445 (mime-display-message mime-message-structure preview-buffer
1446 mother default-keymap-or-function)
1453 (defun mime-preview-find-boundary-info (&optional get-mother)
1457 (while (null (setq entity
1458 (get-text-property (point) 'mime-view-entity)))
1460 (setq p-beg (previous-single-property-change (point) 'mime-view-entity))
1461 (setq entity-node-id (mime-entity-node-id entity))
1462 (setq len (length entity-node-id))
1465 (if (eq (next-single-property-change (point-min)
1471 ((eq (next-single-property-change p-beg 'mime-view-entity)
1473 (setq p-beg (point))
1475 (setq p-end (next-single-property-change p-beg 'mime-view-entity))
1477 (setq p-end (point-max))
1479 ((null entity-node-id)
1480 (setq p-end (point-max))
1488 (next-single-property-change
1489 (point) 'mime-view-entity))
1491 (let ((rc (mime-entity-node-id
1492 (get-text-property (1- (point))
1493 'mime-view-entity))))
1494 (or (and (>= (setq i (- (length rc) len)) 0)
1495 (equal entity-node-id (nthcdr i rc)))
1498 (setq p-end (point-max))))
1500 (vector p-beg p-end entity)))
1506 (autoload 'mime-preview-play-current-entity "mime-play"
1507 "Play current entity." t)
1509 (defun mime-preview-extract-current-entity (&optional ignore-examples)
1510 "Extract current entity into file (maybe).
1511 It decodes current entity to call internal or external method as
1512 \"extract\" mode. The method is selected from variable
1513 `mime-acting-condition'."
1515 (mime-preview-play-current-entity ignore-examples "extract")
1518 (defun mime-preview-print-current-entity (&optional ignore-examples)
1519 "Print current entity (maybe).
1520 It decodes current entity to call internal or external method as
1521 \"print\" mode. The method is selected from variable
1522 `mime-acting-condition'."
1524 (mime-preview-play-current-entity ignore-examples "print")
1531 (defun mime-preview-follow-current-entity ()
1532 "Write follow message to current entity.
1533 It calls following-method selected from variable
1534 `mime-preview-following-method-alist'."
1536 (let ((entity (mime-preview-find-boundary-info t))
1539 (setq p-beg (aref entity 0)
1540 p-end (aref entity 1)
1541 entity (aref entity 2))
1542 (if (get-text-property p-beg 'mime-view-entity-body)
1545 (next-single-property-change
1546 p-beg 'mime-view-entity-body nil
1547 (or (next-single-property-change p-beg 'mime-view-entity)
1549 (let* ((mode (mime-preview-original-major-mode 'recursive))
1550 (entity-node-id (mime-entity-node-id entity))
1552 (format "%s-%s" (buffer-name) (reverse entity-node-id)))
1554 (the-buf (current-buffer))
1557 (set-buffer (setq new-buf (get-buffer-create new-name)))
1560 (insert-buffer-substring the-buf pb-beg p-end)
1561 (goto-char (point-min))
1562 (let ((current-entity
1563 (if (and (eq (mime-entity-media-type entity) 'message)
1564 (eq (mime-entity-media-subtype entity) 'rfc822))
1565 (car (mime-entity-children entity))
1567 (while (and current-entity
1568 (if (and (eq (mime-entity-media-type
1569 current-entity) 'message)
1570 (eq (mime-entity-media-subtype
1571 current-entity) 'rfc822))
1573 (mime-insert-header current-entity fields)
1575 (setq fields (std11-collect-field-names)
1576 current-entity (mime-entity-parent current-entity))
1578 (let ((rest mime-view-following-required-fields-list)
1581 (setq field-name (car rest))
1582 (or (std11-field-body field-name)
1585 (set-buffer the-buf)
1586 (let ((entity (when mime-mother-buffer
1587 (set-buffer mime-mother-buffer)
1588 (get-text-property (point)
1589 'mime-view-entity))))
1591 (null (setq ret (mime-entity-fetch-field
1592 entity field-name))))
1593 (setq entity (mime-entity-parent entity)))))
1595 (insert (concat field-name ": " ret "\n"))
1597 (setq rest (cdr rest))
1600 (let ((f (cdr (assq mode mime-preview-following-method-alist))))
1605 "Sorry, following method for %s is not implemented yet."
1614 (defun mime-preview-move-to-upper ()
1615 "Move to upper entity.
1616 If there is no upper entity, call function `mime-preview-quit'."
1619 (while (null (setq cinfo
1620 (get-text-property (point) 'mime-view-entity)))
1623 (let ((r (mime-entity-parent cinfo))
1626 (while (setq point (previous-single-property-change
1627 (point) 'mime-view-entity))
1629 (when (eq r (get-text-property (point) 'mime-view-entity))
1630 (if (or (eq mime-preview-move-scroll t)
1631 (and mime-preview-move-scroll
1634 (move-to-window-line -1)
1635 (forward-line (* -1 next-screen-context-lines))
1638 (recenter next-screen-context-lines))
1645 (defun mime-preview-move-to-previous ()
1646 "Move to previous entity.
1647 If there is no previous entity, it calls function registered in
1648 variable `mime-preview-over-to-previous-method-alist'."
1650 (while (and (not (bobp))
1651 (null (get-text-property (point) 'mime-view-entity)))
1654 (let ((point (previous-single-property-change (point) 'mime-view-entity)))
1656 (>= point (point-min)))
1657 (if (get-text-property (1- point) 'mime-view-entity)
1658 (progn (goto-char point)
1660 (or (eq mime-preview-move-scroll t)
1661 (and mime-preview-move-scroll
1664 (move-to-window-line 0)
1665 (forward-line next-screen-context-lines)
1668 (recenter (* -1 next-screen-context-lines))))
1669 (goto-char (1- point))
1670 (mime-preview-move-to-previous)
1672 (let ((f (assq (mime-preview-original-major-mode)
1673 mime-preview-over-to-previous-method-alist)))
1679 (defun mime-preview-move-to-next ()
1680 "Move to next entity.
1681 If there is no previous entity, it calls function registered in
1682 variable `mime-preview-over-to-next-method-alist'."
1684 (while (and (not (eobp))
1685 (null (get-text-property (point) 'mime-view-entity)))
1688 (let ((point (next-single-property-change (point) 'mime-view-entity)))
1690 (<= point (point-max)))
1693 (if (null (get-text-property point 'mime-view-entity))
1694 (mime-preview-move-to-next)
1696 (or (eq mime-preview-move-scroll t)
1697 (and mime-preview-move-scroll
1700 (move-to-window-line -1)
1702 (* -1 next-screen-context-lines))
1705 (recenter next-screen-context-lines))
1707 (let ((f (assq (mime-preview-original-major-mode)
1708 mime-preview-over-to-next-method-alist)))
1714 (defun mime-preview-scroll-up-entity (&optional h)
1715 "Scroll up current entity.
1716 If reached to (point-max), it calls function registered in variable
1717 `mime-preview-over-to-next-method-alist'."
1720 (let ((f (assq (mime-preview-original-major-mode)
1721 mime-preview-over-to-next-method-alist)))
1726 (or (next-single-property-change (point) 'mime-view-entity)
1728 (bottom (window-end (selected-window))))
1731 (progn (goto-char point)
1732 (recenter next-screen-context-lines))
1736 (goto-char (point-max)))))
1739 (defun mime-preview-scroll-down-entity (&optional h)
1740 "Scroll down current entity.
1741 If reached to (point-min), it calls function registered in variable
1742 `mime-preview-over-to-previous-method-alist'."
1745 (let ((f (assq (mime-preview-original-major-mode)
1746 mime-preview-over-to-previous-method-alist)))
1751 (or (previous-single-property-change (point) 'mime-view-entity)
1753 (top (window-start (selected-window))))
1756 (progn (goto-char point)
1757 (recenter (* -1 next-screen-context-lines)))
1760 (beginning-of-buffer
1761 (goto-char (point-min)))))
1764 (defun mime-preview-next-line-entity (&optional lines)
1765 "Scroll up one line (or prefix LINES lines).
1766 If LINES is negative, scroll down LINES lines."
1768 (mime-preview-scroll-up-entity (or lines 1))
1771 (defun mime-preview-previous-line-entity (&optional lines)
1772 "Scrroll down one line (or prefix LINES lines).
1773 If LINES is negative, scroll up LINES lines."
1775 (mime-preview-scroll-down-entity (or lines 1))
1782 (defun mime-preview-toggle-display (type &optional display)
1783 (let ((situation (mime-preview-find-boundary-info))
1784 (sym (intern (concat "*" (symbol-name type))))
1786 (setq p-beg (aref situation 0)
1787 p-end (aref situation 1)
1788 entity (aref situation 2)
1789 situation (get-text-property p-beg 'mime-view-situation))
1790 (cond ((eq display 'invisible)
1795 (eq (cdr (or (assq sym situation)
1796 (assq type situation)))
1798 (setq situation (put-alist sym (if display
1803 (let ((inhibit-read-only t))
1804 (delete-region p-beg p-end)
1805 (mime-display-entity entity situation)))
1806 (let ((ret (assoc situation mime-preview-situation-example-list)))
1808 (setcdr ret (1+ (cdr ret)))
1809 (add-to-list 'mime-preview-situation-example-list
1810 (cons situation 0))))))
1812 (defun mime-preview-toggle-header (&optional force-visible)
1814 (mime-preview-toggle-display 'header force-visible))
1816 (defun mime-preview-toggle-content (&optional force-visible)
1818 (mime-preview-toggle-display 'body force-visible))
1820 (defun mime-preview-show-header ()
1822 (mime-preview-toggle-display 'header 'visible))
1824 (defun mime-preview-show-content ()
1826 (mime-preview-toggle-display 'body 'visible))
1828 (defun mime-preview-hide-header ()
1830 (mime-preview-toggle-display 'header 'invisible))
1832 (defun mime-preview-hide-content ()
1834 (mime-preview-toggle-display 'body 'invisible))
1840 (defun mime-preview-quit ()
1841 "Quit from MIME-preview buffer.
1842 It calls function registered in variable
1843 `mime-preview-quitting-method-alist'."
1845 (let ((r (assq (mime-preview-original-major-mode)
1846 mime-preview-quitting-method-alist)))
1851 (defun mime-preview-kill-buffer ()
1853 (kill-buffer (current-buffer))
1860 (provide 'mime-view)
1863 (setq mime-situation-examples-file nil)
1864 ;; to avoid to read situation-examples-file at compile time.
1867 (mime-view-read-situation-examples-file)
1869 ;;; mime-view.el ends here