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)
93 "Alist of major-mode vs. representation-type of mime-raw-buffer.
94 Each element looks like (SYMBOL . REPRESENTATION-TYPE). SYMBOL is
95 major-mode or t. t means default. REPRESENTATION-TYPE must be
96 `binary' or `cooked'.")
99 ;;; @ in preview-buffer (presentation space)
102 (defvar mime-mother-buffer nil
103 "Mother buffer corresponding with the (MIME-preview) buffer.
104 If current MIME-preview buffer is generated by other buffer, such as
105 message/partial, it is called `mother-buffer'.")
106 (make-variable-buffer-local 'mime-mother-buffer)
108 ;; (defvar mime-raw-buffer nil
109 ;; "Raw buffer corresponding with the (MIME-preview) buffer.")
110 ;; (make-variable-buffer-local 'mime-raw-buffer)
112 (defvar mime-preview-original-window-configuration nil
113 "Window-configuration before mime-view-mode is called.")
114 (make-variable-buffer-local 'mime-preview-original-window-configuration)
116 (defun mime-preview-original-major-mode (&optional recursive point)
117 "Return major-mode of original buffer.
118 If optional argument RECURSIVE is non-nil and current buffer has
119 mime-mother-buffer, it returns original major-mode of the
121 (if (and recursive mime-mother-buffer)
123 (set-buffer mime-mother-buffer)
124 (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)
145 (unless (assq 'subtype situation)
147 (setq rest (or (cdr (mime-entity-content-type entity))
148 '((subtype . plain)))))
149 (setq situation (cons (car rest) situation)
152 (setq param (car rest))
153 (or (assoc (car param) situation)
154 (setq situation (cons param situation)))
155 (setq rest (cdr rest)))
157 ;; Content-Disposition
159 (unless (assq 'disposition-type situation)
160 (setq rest (mime-entity-content-disposition entity))
162 (setq situation (cons (cons 'disposition-type
163 (mime-content-disposition-type rest))
165 rest (mime-content-disposition-parameters rest))))
167 (setq param (car rest)
169 (if (cond ((string= name "filename")
170 (if (assq 'filename situation)
172 (setq name 'filename)))
173 ((string= name "creation-date")
174 (if (assq 'creation-date situation)
176 (setq name 'creation-date)))
177 ((string= name "modification-date")
178 (if (assq 'modification-date situation)
180 (setq name 'modification-date)))
181 ((string= name "read-date")
182 (if (assq 'read-date situation)
184 (setq name 'read-date)))
185 ((string= name "size")
186 (if (assq 'size situation)
189 (t (setq name (cons 'disposition name))
190 (if (assoc name situation)
194 (cons (cons name (cdr param))
196 (setq rest (cdr rest)))
198 ;; Content-Transfer-Encoding
199 (or (assq 'encoding situation)
201 (cons (cons 'encoding (or (mime-entity-encoding entity)
207 (defsubst mime-delq-null-situation (situations field
208 &rest ignored-values)
211 (let* ((situation (car situations))
212 (cell (assq field situation)))
214 (or (memq (cdr cell) ignored-values)
215 (setq dest (cons situation dest)))))
216 (setq situations (cdr situations)))
219 (defun mime-compare-situation-with-example (situation example)
220 (let ((example (copy-alist example))
223 (let* ((cell (car situation))
225 (ecell (assoc key example)))
227 (if (equal cell ecell)
228 (setq match (1+ match))
229 (setq example (delq ecell example)))))
230 (setq situation (cdr situation)))
231 (cons match example)))
233 (defun mime-sort-situation (situation)
243 (disposition-type . 6)))
246 (let ((ret (assq a-t order)))
248 (setq a-order (cdr ret))
252 (let ((ret (assq b-t order)))
254 (setq b-order (cdr ret))
257 (if (= a-order b-order)
258 (string< (format "%s" a-t)(format "%s" b-t))
259 (< a-order b-order))))))
261 (defun mime-unify-situations (entity-situation
262 condition situation-examples
263 &optional required-name ignored-value
266 (in-calist-package 'mime-view)
268 (ctree-find-calist condition entity-situation
271 (setq ret (mime-delq-null-situation ret required-name
273 (or (assq 'ignore-examples entity-situation)
281 (let ((situation (car rest))
282 (examples situation-examples))
285 (mime-compare-situation-with-example
286 situation (caar examples)))
287 (ret-score (car ret)))
288 (cond ((> ret-score max-score)
289 (setq max-score ret-score
290 max-escore (cdar examples)
291 max-examples (list (cdr ret))
292 max-situations (list situation)))
293 ((= ret-score max-score)
294 (cond ((> (cdar examples) max-escore)
295 (setq max-escore (cdar examples)
296 max-examples (list (cdr ret))
297 max-situations (list situation)))
298 ((= (cdar examples) max-escore)
300 (cons (cdr ret) max-examples))
301 (or (member situation max-situations)
303 (cons situation max-situations))))))))
304 (setq examples (cdr examples))))
305 (setq rest (cdr rest)))
307 (setq ret max-situations)
309 (let* ((example (car max-examples))
311 (assoc example situation-examples)))
313 (setcdr cell (1+ (cdr cell)))
314 (setq situation-examples
315 (cons (cons example 0)
316 situation-examples))))
317 (setq max-examples (cdr max-examples)))))))
318 (cons ret situation-examples)
319 ;; ret: list of situations
320 ;; situation-examples: new examples (notoce that contents of
321 ;; argument `situation-examples' has bees modified)
324 (defun mime-view-entity-title (entity)
325 (or (mime-entity-read-field entity 'Content-Description)
326 (mime-entity-read-field entity 'Subject)
327 (mime-entity-filename entity)
330 (defvar mime-preview-situation-example-list nil)
331 (defvar mime-preview-situation-example-list-max-size 16)
332 ;; (defvar mime-preview-situation-example-condition nil)
334 (defun mime-find-entity-preview-situation (entity
335 &optional default-situation)
337 (mime-unify-situations
338 (append (mime-entity-situation entity)
340 mime-preview-condition
341 mime-preview-situation-example-list)))
342 (setq mime-preview-situation-example-list
348 (defvar mime-acting-situation-example-list nil)
349 (defvar mime-acting-situation-example-list-max-size 16)
350 (defvar mime-situation-examples-file-coding-system nil)
352 (defun mime-view-read-situation-examples-file (&optional file)
354 (setq file mime-situation-examples-file))
356 (file-readable-p file))
358 (insert-file-contents file)
359 (setq mime-situation-examples-file-coding-system
361 ((boundp 'buffer-file-coding-system)
362 (symbol-value 'buffer-file-coding-system))
363 ((boundp 'file-coding-system)
364 (symbol-value 'file-coding-system))
366 ;; (and (boundp 'buffer-file-coding-system)
367 ;; buffer-file-coding-system)
369 (condition-case error
371 (error (message "%s is broken: %s" file (cdr error))))
375 (while (and (> (length mime-preview-situation-example-list)
376 mime-preview-situation-example-list-max-size)
378 (setq mime-preview-situation-example-list
379 (mime-reduce-situation-examples
380 mime-preview-situation-example-list))
382 (error (setq mime-preview-situation-example-list nil)))
383 ;; (let ((rest mime-preview-situation-example-list))
385 ;; (ctree-set-calist-strictly 'mime-preview-condition
387 ;; (setq rest (cdr rest))))
390 (while (and (> (length mime-acting-situation-example-list)
391 mime-acting-situation-example-list-max-size)
393 (setq mime-acting-situation-example-list
394 (mime-reduce-situation-examples
395 mime-acting-situation-example-list))
397 (error (setq mime-acting-situation-example-list nil))))))
399 (defun mime-save-situation-examples ()
400 (if (or mime-preview-situation-example-list
401 mime-acting-situation-example-list)
402 (let ((file mime-situation-examples-file))
404 (insert ";;; " (file-name-nondirectory file) "\n")
405 (insert "\n;; This file is generated automatically by "
406 mime-view-version "\n\n")
407 (insert ";;; Code:\n\n")
408 (if mime-preview-situation-example-list
409 (pp `(setq mime-preview-situation-example-list
410 ',mime-preview-situation-example-list)
412 (if mime-acting-situation-example-list
413 (pp `(setq mime-acting-situation-example-list
414 ',mime-acting-situation-example-list)
417 (file-name-nondirectory file)
420 ((boundp 'buffer-file-coding-system)
421 (setq buffer-file-coding-system
422 mime-situation-examples-file-coding-system))
423 ((boundp 'file-coding-system)
424 (setq file-coding-system
425 mime-situation-examples-file-coding-system)))
426 ;; (setq buffer-file-coding-system
427 ;; mime-situation-examples-file-coding-system)
428 (setq buffer-file-name file)
431 (add-hook 'kill-emacs-hook 'mime-save-situation-examples)
433 (defun mime-reduce-situation-examples (situation-examples)
434 (let ((len (length situation-examples))
442 ir situation-examples)
446 jr situation-examples)
450 (setq ret (mime-compare-situation-with-example (car ic)(car jc))
452 det-ret (+ (length (car ic))(length (car jc)))
453 det-org (length (cdr ret))
454 freq (+ (cdr ic)(cdr jc)))
455 (cond ((< max-sim sim)
462 dest (cons (cdr ret) freq)))
464 (cond ((> min-det-ret det-ret)
465 (setq min-det-ret det-ret
470 dest (cons (cdr ret) freq)))
471 ((= min-det-ret det-ret)
472 (cond ((> min-det-org det-org)
473 (setq min-det-org det-org
477 dest (cons (cdr ret) freq)))
478 ((= min-det-org det-org)
479 (cond ((> min-freq freq)
483 dest (cons (cdr ret) freq)))))))))))
492 (setq jr (nthcdr (1- d-j) situation-examples))
493 (setcdr jr (cddr jr))
495 (setq situation-examples
496 (cdr situation-examples))
497 (setq ir (nthcdr (1- d-i) situation-examples))
498 (setcdr ir (cddr ir)))
499 (if (setq ir (assoc (car dest) situation-examples))
501 (setcdr ir (+ (cdr ir)(cdr dest)))
503 (cons dest situation-examples)
504 ;; situation-examples may be modified.
508 ;;; @ presentation of preview
514 ;;; @@@ predicate function
517 ;; (defun mime-view-entity-button-visible-p (entity)
518 ;; "Return non-nil if header of ENTITY is visible.
519 ;; Please redefine this function if you want to change default setting."
520 ;; (let ((media-type (mime-entity-media-type entity))
521 ;; (media-subtype (mime-entity-media-subtype entity)))
522 ;; (or (not (eq media-type 'application))
523 ;; (and (not (eq media-subtype 'x-selection))
524 ;; (or (not (eq media-subtype 'octet-stream))
525 ;; (let ((mother-entity (mime-entity-parent entity)))
526 ;; (or (not (eq (mime-entity-media-type mother-entity)
528 ;; (not (eq (mime-entity-media-subtype mother-entity)
533 ;;; @@@ entity button generator
536 (defun mime-view-insert-entity-button (entity)
537 "Insert entity-button of ENTITY."
538 (let ((entity-node-id (mime-entity-node-id entity))
539 (params (mime-entity-parameters entity))
540 (subject (mime-view-entity-title entity)))
542 (let ((access-type (assoc "access-type" params))
543 (num (or (cdr (assoc "x-part-number" params))
544 (if (consp entity-node-id)
547 (format "%s" (1+ num))))
548 (reverse entity-node-id) ".")
551 (let ((server (assoc "server" params)))
552 (setq access-type (cdr access-type))
554 (format "%s %s ([%s] %s)"
555 num subject access-type (cdr server))
556 (let ((site (cdr (assoc "site" params)))
557 (dir (cdr (assoc "directory" params)))
558 (url (cdr (assoc "url" params))))
560 (format "%s %s ([%s] %s)"
561 num subject access-type url)
562 (format "%s %s ([%s] %s:%s)"
563 num subject access-type site dir))))))
565 (let ((media-type (mime-entity-media-type entity))
566 (media-subtype (mime-entity-media-subtype entity))
567 (charset (cdr (assoc "charset" params)))
568 (encoding (mime-entity-encoding entity)))
572 (format " <%s/%s%s%s>"
573 media-type media-subtype
575 (concat "; " charset)
578 (concat " (" encoding ")")
580 (if (>= (+ (current-column)(length rest))(window-width))
583 (function mime-preview-play-current-entity))))
589 (defvar mime-header-presentation-method-alist nil
590 "Alist of major mode vs. corresponding header-presentation-method functions.
591 Each element looks like (SYMBOL . FUNCTION).
592 SYMBOL must be major mode in raw-buffer or t. t means default.
593 Interface of FUNCTION must be (ENTITY SITUATION).")
595 (defvar mime-view-ignored-field-list
596 '(".*Received:" ".*Path:" ".*Id:" "^References:"
597 "^Replied:" "^Errors-To:"
598 "^Lines:" "^Sender:" ".*Host:" "^Xref:"
599 "^Content-Type:" "^Precedence:"
600 "^Status:" "^X-VM-.*:")
601 "All fields that match this list will be hidden in MIME preview buffer.
602 Each elements are regexp of field-name.")
604 (defvar mime-view-visible-field-list '("^Dnas.*:" "^Message-Id:")
605 "All fields that match this list will be displayed in MIME preview buffer.
606 Each elements are regexp of field-name.")
612 ;;; @@@ predicate function
615 (in-calist-package 'mime-view)
617 (defun mime-calist::field-match-method-as-default-rule (calist
618 field-type field-value)
619 (let ((s-field (assq field-type calist)))
620 (cond ((null s-field)
621 (cons (cons field-type field-value) calist))
624 (define-calist-field-match-method
625 'header #'mime-calist::field-match-method-as-default-rule)
627 (define-calist-field-match-method
628 'body #'mime-calist::field-match-method-as-default-rule)
631 (defvar mime-preview-condition nil
632 "Condition-tree about how to display entity.")
634 (ctree-set-calist-strictly
635 'mime-preview-condition '((type . application)(subtype . octet-stream)
638 (ctree-set-calist-strictly
639 'mime-preview-condition '((type . application)(subtype . octet-stream)
642 (ctree-set-calist-strictly
643 'mime-preview-condition '((type . application)(subtype . octet-stream)
647 (ctree-set-calist-strictly
648 'mime-preview-condition '((type . application)(subtype . pgp)
651 (ctree-set-calist-strictly
652 'mime-preview-condition '((type . application)(subtype . x-latex)
655 (ctree-set-calist-strictly
656 'mime-preview-condition '((type . application)(subtype . x-selection)
659 (ctree-set-calist-strictly
660 'mime-preview-condition '((type . application)(subtype . x-comment)
663 (ctree-set-calist-strictly
664 'mime-preview-condition '((type . message)(subtype . delivery-status)
667 (ctree-set-calist-strictly
668 'mime-preview-condition
670 (body-presentation-method . mime-display-text/plain)))
672 (defvar mime-preview-fill-flowed-text
673 (module-installed-p 'flow-fill)
674 "If non-nil, fill RFC2646 \"flowed\" text.")
676 (autoload 'fill-flowed "flow-fill")
678 (ctree-set-calist-strictly
679 'mime-preview-condition
682 (body-presentation-method . mime-display-text/plain)))
684 (ctree-set-calist-strictly
685 'mime-preview-condition
686 '((type . text)(subtype . enriched)
688 (body-presentation-method . mime-display-text/enriched)))
690 (ctree-set-calist-strictly
691 'mime-preview-condition
692 '((type . text)(subtype . richtext)
694 (body-presentation-method . mime-display-text/richtext)))
696 (autoload 'mime-display-application/x-postpet "postpet")
698 (ctree-set-calist-strictly
699 'mime-preview-condition
700 '((type . application)(subtype . x-postpet)
702 (body-presentation-method . mime-display-application/x-postpet)))
704 (ctree-set-calist-strictly
705 'mime-preview-condition
706 '((type . text)(subtype . t)
708 (body-presentation-method . mime-display-text/plain)))
710 (ctree-set-calist-strictly
711 'mime-preview-condition
712 '((type . multipart)(subtype . alternative)
714 (body-presentation-method . mime-display-multipart/alternative)))
716 (ctree-set-calist-strictly
717 'mime-preview-condition
718 '((type . multipart)(subtype . related)
720 (body-presentation-method . mime-display-multipart/related)))
722 (ctree-set-calist-strictly
723 'mime-preview-condition
724 '((type . multipart)(subtype . t)
726 (body-presentation-method . mime-display-multipart/mixed)))
728 (ctree-set-calist-strictly
729 'mime-preview-condition
730 '((type . message)(subtype . partial)
732 (body-presentation-method . mime-display-message/partial-button)))
734 (ctree-set-calist-strictly
735 'mime-preview-condition
736 '((type . message)(subtype . rfc822)
738 (body-presentation-method . mime-display-multipart/mixed)
739 (childrens-situation (header . visible)
740 (entity-button . invisible))))
742 (ctree-set-calist-strictly
743 'mime-preview-condition
744 '((type . message)(subtype . news)
746 (body-presentation-method . mime-display-multipart/mixed)
747 (childrens-situation (header . visible)
748 (entity-button . invisible))))
751 ;;; @@@ entity presentation
754 (defun mime-display-text/plain (entity situation)
756 (narrow-to-region (point-max)(point-max))
758 (mime-insert-text-content entity)
760 (message "Can't decode current entity.")
762 (run-hooks 'mime-text-decode-hook)
763 (goto-char (point-max))
764 (if (not (eq (char-after (1- (point))) ?\n))
766 (if (and mime-preview-fill-flowed-text
767 (equal (cdr (assoc "format" situation)) "flowed"))
769 (mime-add-url-buttons)
770 (run-hooks 'mime-display-text/plain-hook)))
772 (defun mime-display-text/richtext (entity situation)
774 (narrow-to-region (point-max)(point-max))
775 (mime-insert-text-content entity)
776 (run-hooks 'mime-text-decode-hook)
777 (let ((beg (point-min)))
778 (remove-text-properties beg (point-max) '(face nil))
779 (richtext-decode beg (point-max)))))
781 (defun mime-display-text/enriched (entity situation)
783 (narrow-to-region (point-max)(point-max))
784 (mime-insert-text-content entity)
785 (run-hooks 'mime-text-decode-hook)
786 (let ((beg (point-min)))
787 (remove-text-properties beg (point-max) '(face nil))
788 (enriched-decode beg (point-max)))))
790 (defvar mime-view-announcement-for-message/partial
791 "This is message/partial style split message.")
793 (defun mime-display-message/partial-button (&optional entity situation)
795 (goto-char (point-max))
796 (if (not (search-backward "\n\n" nil t))
798 (goto-char (point-max))
799 (mime-insert-button mime-view-announcement-for-message/partial
800 #'mime-preview-play-current-entity)))
802 (defun mime-display-multipart/mixed (entity situation)
803 (let ((children (mime-entity-children entity))
804 (original-major-mode-cell (assq 'major-mode situation))
806 (cdr (assq 'childrens-situation situation))))
807 (if original-major-mode-cell
808 (setq default-situation
809 (cons original-major-mode-cell default-situation)))
811 (mime-display-entity (car children) nil default-situation)
812 (setq children (cdr children)))))
814 (defcustom mime-view-type-subtype-score-alist
815 '(((text . enriched) . 3)
816 ((text . richtext) . 2)
819 "Alist MEDIA-TYPE vs corresponding score.
820 MEDIA-TYPE must be (TYPE . SUBTYPE), TYPE or t. t means default."
822 :type '(repeat (cons (choice :tag "Media-Type"
823 (cons :tag "Type/Subtype"
824 (symbol :tag "Primary-type")
825 (symbol :tag "Subtype"))
827 (const :tag "Default" t))
830 (defun mime-display-multipart/alternative (entity situation)
831 (let* ((children (mime-entity-children entity))
832 (original-major-mode-cell (assq 'major-mode situation))
834 (cdr (assq 'childrens-situation situation)))
839 (if original-major-mode-cell
840 (setq default-situation
841 (cons original-major-mode-cell default-situation)))
846 (mime-find-entity-preview-situation
847 child default-situation)))
848 (if (cdr (assq 'body-presentation-method situation))
853 (cdr (assq 'type situation))
854 (cdr (assq 'subtype situation)))
855 mime-view-type-subtype-score-alist)
857 (cdr (assq 'type situation))
858 mime-view-type-subtype-score-alist)
861 mime-view-type-subtype-score-alist)))))
862 (if (> score max-score)
870 (let ((child (car children))
871 (situation (car situations)))
872 (mime-display-entity child (if (= i p)
874 (put-alist 'body 'invisible
875 (copy-alist situation)))))
876 (setq children (cdr children)
877 situations (cdr situations)
880 (defun mime-display-multipart/related (entity situation)
881 (let* ((param-start (mime-parse-msg-id
882 (std11-lexical-analyze
884 (mime-content-type-parameters
885 (mime-entity-content-type entity)))))))
886 (start (or (and param-start (mime-find-entity-from-content-id
889 (car (mime-entity-children entity))))
890 (original-major-mode-cell (assq 'major-mode situation))
891 (default-situation (cdr (assq 'childrens-situation situation))))
892 (if original-major-mode-cell
893 (setq default-situation
894 (cons original-major-mode-cell default-situation)))
895 (mime-display-entity start nil default-situation)))
897 ;;; @ acting-condition
900 (defvar mime-acting-condition nil
901 "Condition-tree about how to process entity.")
903 (defun mime-view-read-mailcap-files (&optional files)
905 (setq files mime-view-mailcap-files))
908 (setq file (car files))
909 (if (file-readable-p file)
910 (setq entries (append entries (mime-parse-mailcap-file file))))
911 (setq files (cdr files)))
913 (let ((entry (car entries))
916 (let* ((field (car entry))
917 (field-type (car field)))
918 (cond ((eq field-type 'view) (setq view field))
919 ((eq field-type 'print) (setq print field))
920 ((memq field-type '(compose composetyped edit)))
921 (t (setq shared (cons field shared))))
923 (setq entry (cdr entry)))
924 (setq shared (nreverse shared))
925 (ctree-set-calist-with-default
926 'mime-acting-condition
927 (append shared (list '(mode . "play")(cons 'method (cdr view)))))
929 (ctree-set-calist-with-default
930 'mime-acting-condition
932 (list '(mode . "print")(cons 'method (cdr view)))))))
933 (setq entries (cdr entries)))))
935 (mime-view-read-mailcap-files)
937 (ctree-set-calist-strictly
938 'mime-acting-condition
939 '((type . application)(subtype . octet-stream)
941 (method . mime-detect-content)))
943 (ctree-set-calist-with-default
944 'mime-acting-condition
946 (method . mime-save-content)))
948 (ctree-set-calist-strictly
949 'mime-acting-condition
950 '((type . text)(subtype . x-rot13-47)(mode . "play")
951 (method . mime-view-caesar)))
952 (ctree-set-calist-strictly
953 'mime-acting-condition
954 '((type . text)(subtype . x-rot13-47-48)(mode . "play")
955 (method . mime-view-caesar)))
957 (ctree-set-calist-strictly
958 'mime-acting-condition
959 '((type . message)(subtype . rfc822)(mode . "play")
960 (method . mime-view-message/rfc822)))
961 (ctree-set-calist-strictly
962 'mime-acting-condition
963 '((type . message)(subtype . partial)(mode . "play")
964 (method . mime-store-message/partial-piece)))
966 (ctree-set-calist-strictly
967 'mime-acting-condition
968 '((type . message)(subtype . external-body)
969 ("access-type" . "anon-ftp")
970 (method . mime-view-message/external-anon-ftp)))
972 (ctree-set-calist-strictly
973 'mime-acting-condition
974 '((type . message)(subtype . external-body)
975 ("access-type" . "url")
976 (method . mime-view-message/external-url)))
978 (ctree-set-calist-strictly
979 'mime-acting-condition
980 '((type . application)(subtype . octet-stream)
981 (method . mime-save-content)))
984 ;;; @ quitting method
987 (defvar mime-preview-quitting-method-alist
988 '((mime-show-message-mode
989 . mime-preview-quitting-method-for-mime-show-message-mode))
990 "Alist of major-mode vs. quitting-method of mime-view.")
992 (defvar mime-preview-over-to-previous-method-alist nil
993 "Alist of major-mode vs. over-to-previous-method of mime-view.")
995 (defvar mime-preview-over-to-next-method-alist nil
996 "Alist of major-mode vs. over-to-next-method of mime-view.")
999 ;;; @ following method
1002 (defvar mime-preview-following-method-alist nil
1003 "Alist of major-mode vs. following-method of mime-view.")
1005 (defvar mime-view-following-required-fields-list
1012 (defun mime-display-entity (entity &optional situation
1013 default-situation preview-buffer)
1015 (setq preview-buffer (current-buffer)))
1016 (let* (e nb ne nhb nbb)
1017 (in-calist-package 'mime-view)
1020 (mime-find-entity-preview-situation entity default-situation)))
1021 (let ((button-is-invisible
1022 (eq (cdr (or (assq '*entity-button situation)
1023 (assq 'entity-button situation)))
1026 (eq (cdr (or (assq '*header situation)
1027 (assq 'header situation)))
1030 (eq (cdr (or (assq '*body situation)
1031 (assq 'body situation)))
1033 (children (mime-entity-children entity)))
1034 (set-buffer preview-buffer)
1036 (narrow-to-region nb nb)
1037 (or button-is-invisible
1038 ;; (if (mime-view-entity-button-visible-p entity)
1039 (mime-view-insert-entity-button entity)
1042 (if header-is-visible
1043 (let ((header-presentation-method
1044 (or (cdr (assq 'header-presentation-method situation))
1045 (cdr (assq (cdr (assq 'major-mode situation))
1046 mime-header-presentation-method-alist)))))
1048 (if header-presentation-method
1049 (funcall header-presentation-method entity situation)
1050 (mime-insert-header entity
1051 mime-view-ignored-field-list
1052 mime-view-visible-field-list))
1053 (mime-add-url-buttons)
1054 (run-hooks 'mime-display-header-hook)
1055 (put-text-property nhb (point-max) 'mime-view-entity-header entity)
1056 (goto-char (point-max))
1061 (let ((body-presentation-method
1062 (cdr (assq 'body-presentation-method situation))))
1063 (if (functionp body-presentation-method)
1064 (funcall body-presentation-method entity situation)
1065 (mime-display-text/plain entity situation)))
1066 (when button-is-invisible
1067 (goto-char (point-max))
1068 (mime-view-insert-entity-button entity))
1069 (unless header-is-visible
1070 (goto-char (point-max))
1072 (setq ne (point-max))
1074 (put-text-property nb ne 'mime-view-entity entity)
1075 (put-text-property nb ne 'mime-view-situation situation)
1076 (put-text-property nbb ne 'mime-view-entity-body entity)
1078 (if (and children body-is-visible)
1079 (let ((body-presentation-method
1080 (cdr (assq 'body-presentation-method situation))))
1081 (if (functionp body-presentation-method)
1082 (funcall body-presentation-method entity situation)
1083 (mime-display-multipart/mixed entity situation)))))))
1086 ;;; @ MIME viewer mode
1089 (defconst mime-view-popup-menu-list
1091 ["Move to upper entity" mime-preview-move-to-upper]
1092 ["Move to previous entity" mime-preview-move-to-previous]
1093 ["Move to next entity" mime-preview-move-to-next]
1094 ["Scroll-down" mime-preview-scroll-down-entity]
1095 ["Scroll-up" mime-preview-scroll-up-entity]
1096 ["Play current entity" mime-preview-play-current-entity]
1097 ["Extract current entity" mime-preview-extract-current-entity]
1098 ["Print current entity" mime-preview-print-current-entity])
1099 "Menu for MIME Viewer")
1101 (defun mime-view-popup-menu (event)
1102 "Popup the menu in the MIME Viewer buffer"
1104 (mime-popup-menu-popup mime-view-popup-menu-list event))
1106 ;;; The current local map is taken precendence over `widget-keymap',
1107 ;;; because GNU Emacs' widget implementation doesn't set `local-map' property.
1108 ;;; So we need to specify derivation.
1109 (defvar widget-keymap)
1110 (defun mime-view-maybe-inherit-widget-keymap ()
1111 (when (boundp 'widget-keymap)
1112 (set-keymap-parent (current-local-map) widget-keymap)))
1114 (add-hook 'mime-view-define-keymap-hook 'mime-view-maybe-inherit-widget-keymap)
1116 (defun mime-view-define-keymap (&optional default)
1117 (let ((mime-view-mode-map (if (keymapp default)
1118 (copy-keymap default)
1119 (make-sparse-keymap))))
1120 (define-key mime-view-mode-map
1121 "u" (function mime-preview-move-to-upper))
1122 (define-key mime-view-mode-map
1123 "p" (function mime-preview-move-to-previous))
1124 (define-key mime-view-mode-map
1125 "n" (function mime-preview-move-to-next))
1126 (define-key mime-view-mode-map
1127 "\e\t" (function mime-preview-move-to-previous))
1128 (define-key mime-view-mode-map
1129 "\t" (function mime-preview-move-to-next))
1130 (define-key mime-view-mode-map
1131 " " (function mime-preview-scroll-up-entity))
1132 (define-key mime-view-mode-map
1133 "\M- " (function mime-preview-scroll-down-entity))
1134 (define-key mime-view-mode-map
1135 "\177" (function mime-preview-scroll-down-entity))
1136 (define-key mime-view-mode-map
1137 "\C-m" (function mime-preview-next-line-entity))
1138 (define-key mime-view-mode-map
1139 "\C-\M-m" (function mime-preview-previous-line-entity))
1140 (define-key mime-view-mode-map
1141 "v" (function mime-preview-play-current-entity))
1142 (define-key mime-view-mode-map
1143 "e" (function mime-preview-extract-current-entity))
1144 (define-key mime-view-mode-map
1145 "\C-c\C-p" (function mime-preview-print-current-entity))
1147 (define-key mime-view-mode-map
1148 "\C-c\C-t\C-f" (function mime-preview-toggle-header))
1149 (define-key mime-view-mode-map
1150 "\C-c\C-th" (function mime-preview-toggle-header))
1151 (define-key mime-view-mode-map
1152 "\C-c\C-t\C-c" (function mime-preview-toggle-content))
1154 (define-key mime-view-mode-map
1155 "\C-c\C-v\C-f" (function mime-preview-show-header))
1156 (define-key mime-view-mode-map
1157 "\C-c\C-vh" (function mime-preview-show-header))
1158 (define-key mime-view-mode-map
1159 "\C-c\C-v\C-c" (function mime-preview-show-content))
1161 (define-key mime-view-mode-map
1162 "\C-c\C-d\C-f" (function mime-preview-hide-header))
1163 (define-key mime-view-mode-map
1164 "\C-c\C-dh" (function mime-preview-hide-header))
1165 (define-key mime-view-mode-map
1166 "\C-c\C-d\C-c" (function mime-preview-hide-content))
1168 (define-key mime-view-mode-map
1169 "a" (function mime-preview-follow-current-entity))
1170 (define-key mime-view-mode-map
1171 "q" (function mime-preview-quit))
1172 (define-key mime-view-mode-map
1173 "\C-c\C-x" (function mime-preview-kill-buffer))
1174 ;; (define-key mime-view-mode-map
1175 ;; "<" (function beginning-of-buffer))
1176 ;; (define-key mime-view-mode-map
1177 ;; ">" (function end-of-buffer))
1178 (define-key mime-view-mode-map
1179 "?" (function describe-mode))
1180 (define-key mime-view-mode-map
1181 [tab] (function mime-preview-move-to-next))
1182 (define-key mime-view-mode-map
1183 [delete] (function mime-preview-scroll-down-entity))
1184 (define-key mime-view-mode-map
1185 [backspace] (function mime-preview-scroll-down-entity))
1186 (if (functionp default)
1187 (if (featurep 'xemacs)
1188 (set-keymap-default-binding mime-view-mode-map default)
1189 (setq mime-view-mode-map
1190 (append mime-view-mode-map (list (cons t default))))))
1191 (define-key mime-view-mode-map
1192 [down-mouse-3] (function mime-view-popup-menu))
1193 ;; (run-hooks 'mime-view-define-keymap-hook)
1194 mime-view-mode-map))
1196 (defvar mime-view-mode-default-map (mime-view-define-keymap))
1199 (defsubst mime-maybe-hide-echo-buffer ()
1200 "Clear mime-echo buffer and delete window for it."
1201 (let ((buf (get-buffer mime-echo-buffer-name)))
1206 (let ((win (get-buffer-window buf)))
1208 (delete-window win)))
1209 (bury-buffer buf)))))
1211 (defvar mime-view-redisplay nil)
1214 (defun mime-display-message (message &optional preview-buffer
1215 mother default-keymap-or-function
1216 original-major-mode keymap)
1217 "View MESSAGE in MIME-View mode.
1219 Optional argument PREVIEW-BUFFER specifies the buffer of the
1220 presentation. It must be either nil or a name of preview buffer.
1222 Optional argument MOTHER specifies mother-buffer of the preview-buffer.
1224 Optional argument DEFAULT-KEYMAP-OR-FUNCTION is nil, keymap or
1225 function. If it is a keymap, keymap of MIME-View mode will be added
1226 to it. If it is a function, it will be bound as default binding of
1227 keymap of MIME-View mode.
1229 Optional argument ORIGINAL-MAJOR-MODE is major-mode of representation
1230 buffer of MESSAGE. If it is nil, current `major-mode' is used.
1232 Optional argument KEYMAP is keymap of MIME-View mode. If it is
1233 non-nil, DEFAULT-KEYMAP-OR-FUNCTION is ignored. If it is nil,
1234 `mime-view-mode-default-map' is used."
1235 (mime-maybe-hide-echo-buffer)
1236 (let ((win-conf (current-window-configuration)))
1238 (setq preview-buffer
1239 (concat "*Preview-" (mime-entity-name message) "*")))
1240 (or original-major-mode
1241 (setq original-major-mode major-mode))
1242 (let ((inhibit-read-only t))
1243 (set-buffer (get-buffer-create preview-buffer))
1247 (setq mime-mother-buffer mother))
1248 (setq mime-preview-original-window-configuration win-conf)
1249 (setq major-mode 'mime-view-mode)
1250 (setq mode-name "MIME-View")
1251 (mime-display-entity message nil
1252 `((entity-button . invisible)
1254 (major-mode . ,original-major-mode))
1258 (if default-keymap-or-function
1259 (mime-view-define-keymap default-keymap-or-function)
1260 mime-view-mode-default-map)))
1262 (next-single-property-change (point-min) 'mime-view-entity)))
1265 (goto-char (point-min))
1266 (search-forward "\n\n" nil t)))
1267 (run-hooks 'mime-view-mode-hook)
1268 (set-buffer-modified-p nil)
1269 (setq buffer-read-only t)
1273 (defun mime-view-buffer (&optional raw-buffer preview-buffer mother
1274 default-keymap-or-function
1275 representation-type)
1276 "View RAW-BUFFER in MIME-View mode.
1277 Optional argument PREVIEW-BUFFER is either nil or a name of preview
1279 Optional argument DEFAULT-KEYMAP-OR-FUNCTION is nil, keymap or
1280 function. If it is a keymap, keymap of MIME-View mode will be added
1281 to it. If it is a function, it will be bound as default binding of
1282 keymap of MIME-View mode.
1283 Optional argument REPRESENTATION-TYPE is representation-type of
1284 message. It must be nil, `binary' or `cooked'. If it is nil,
1285 `cooked' is used as default."
1288 (setq raw-buffer (current-buffer)))
1289 (or representation-type
1290 (setq representation-type
1292 (set-buffer raw-buffer)
1293 (cdr (or (assq major-mode mime-raw-representation-type-alist)
1294 (assq t mime-raw-representation-type-alist))))))
1295 (if (eq representation-type 'binary)
1296 (setq representation-type 'buffer))
1297 (setq preview-buffer (mime-display-message
1298 (mime-open-entity representation-type raw-buffer)
1299 preview-buffer mother default-keymap-or-function))
1300 (or (get-buffer-window preview-buffer)
1301 (let ((r-win (get-buffer-window raw-buffer)))
1303 (set-window-buffer r-win preview-buffer)
1304 (let ((m-win (and mother (get-buffer-window mother))))
1306 (set-window-buffer m-win preview-buffer)
1307 (switch-to-buffer preview-buffer)))))))
1309 (defun mime-view-mode (&optional mother ctl encoding
1310 raw-buffer preview-buffer
1311 default-keymap-or-function)
1312 "Major mode for viewing MIME message.
1314 Here is a list of the standard keys for mime-view-mode.
1319 u Move to upper content
1320 p or M-TAB Move to previous content
1321 n or TAB Move to next content
1322 SPC Scroll up or move to next content
1323 M-SPC or DEL Scroll down or move to previous content
1324 RET Move to next line
1325 M-RET Move to previous line
1326 v Decode current content as `play mode'
1327 e Decode current content as `extract mode'
1328 C-c C-p Decode current content as `print mode'
1329 a Followup to current content.
1331 button-2 Move to point under the mouse cursor
1332 and decode current content as `play mode'
1335 (unless mime-view-redisplay
1337 (if raw-buffer (set-buffer raw-buffer))
1340 (or (assq major-mode mime-raw-representation-type-alist)
1341 (assq t mime-raw-representation-type-alist)))))
1342 (if (eq type 'binary)
1343 (setq type 'buffer))
1344 (setq mime-message-structure (mime-open-entity type raw-buffer))
1345 (or (mime-entity-content-type mime-message-structure)
1346 (mime-entity-set-content-type mime-message-structure ctl)))
1347 (or (mime-entity-encoding mime-message-structure)
1348 (mime-entity-set-encoding mime-message-structure encoding))))
1349 (mime-display-message mime-message-structure preview-buffer
1350 mother default-keymap-or-function))
1356 (defun mime-preview-find-boundary-info (&optional get-mother)
1360 (while (null (setq entity
1361 (get-text-property (point) 'mime-view-entity)))
1363 (setq p-beg (previous-single-property-change (point) 'mime-view-entity))
1364 (setq entity-node-id (mime-entity-node-id entity))
1365 (setq len (length entity-node-id))
1368 (if (eq (next-single-property-change (point-min)
1373 ((eq (next-single-property-change p-beg 'mime-view-entity)
1375 (setq p-beg (point))))
1376 (setq p-end (next-single-property-change p-beg 'mime-view-entity))
1378 (setq p-end (point-max)))
1379 ((null entity-node-id)
1380 (setq p-end (point-max)))
1387 (next-single-property-change
1388 (point) 'mime-view-entity))
1390 (let ((rc (mime-entity-node-id
1391 (get-text-property (1- (point))
1392 'mime-view-entity))))
1393 (or (and (>= (setq i (- (length rc) len)) 0)
1394 (equal entity-node-id (nthcdr i rc)))
1397 (setq p-end (point-max))))))
1398 (vector p-beg p-end entity)))
1404 (autoload 'mime-preview-play-current-entity "mime-play"
1405 "Play current entity." t)
1407 (defun mime-preview-extract-current-entity (&optional ignore-examples)
1408 "Extract current entity into file (maybe).
1409 It decodes current entity to call internal or external method as
1410 \"extract\" mode. The method is selected from variable
1411 `mime-acting-condition'."
1413 (mime-preview-play-current-entity ignore-examples "extract"))
1415 (defun mime-preview-print-current-entity (&optional ignore-examples)
1416 "Print current entity (maybe).
1417 It decodes current entity to call internal or external method as
1418 \"print\" mode. The method is selected from variable
1419 `mime-acting-condition'."
1421 (mime-preview-play-current-entity ignore-examples "print"))
1427 (defun mime-preview-follow-current-entity ()
1428 "Write follow message to current entity.
1429 It calls following-method selected from variable
1430 `mime-preview-following-method-alist'."
1432 (let ((entity (mime-preview-find-boundary-info t))
1435 (setq p-beg (aref entity 0)
1436 p-end (aref entity 1)
1437 entity (aref entity 2))
1438 (if (get-text-property p-beg 'mime-view-entity-body)
1441 (next-single-property-change
1442 p-beg 'mime-view-entity-body nil
1443 (or (next-single-property-change p-beg 'mime-view-entity)
1445 (let* ((mode (mime-preview-original-major-mode 'recursive))
1446 (entity-node-id (mime-entity-node-id entity))
1448 (format "%s-%s" (buffer-name) (reverse entity-node-id)))
1450 (the-buf (current-buffer))
1453 (set-buffer (setq new-buf (get-buffer-create new-name)))
1456 (insert-buffer-substring the-buf pb-beg p-end)
1457 (goto-char (point-min))
1458 (let ((current-entity
1459 (if (and (eq (mime-entity-media-type entity) 'message)
1460 (eq (mime-entity-media-subtype entity) 'rfc822))
1461 (car (mime-entity-children entity))
1463 (while (and current-entity
1464 (if (and (eq (mime-entity-media-type
1465 current-entity) 'message)
1466 (eq (mime-entity-media-subtype
1467 current-entity) 'rfc822))
1469 (mime-insert-header current-entity fields)
1471 (setq fields (std11-collect-field-names)
1472 current-entity (mime-entity-parent current-entity))))
1473 (let ((rest mime-view-following-required-fields-list)
1476 (setq field-name (car rest))
1477 (or (std11-field-body field-name)
1480 (set-buffer the-buf)
1481 (let ((entity (when mime-mother-buffer
1482 (set-buffer mime-mother-buffer)
1483 (get-text-property (point)
1484 'mime-view-entity))))
1486 (null (setq ret (mime-entity-fetch-field
1487 entity field-name))))
1488 (setq entity (mime-entity-parent entity)))))
1490 (insert (concat field-name ": " ret "\n")))))
1491 (setq rest (cdr rest)))))
1492 (let ((f (cdr (assq mode mime-preview-following-method-alist))))
1497 "Sorry, following method for %s is not implemented yet."
1504 (defun mime-preview-move-to-upper ()
1505 "Move to upper entity.
1506 If there is no upper entity, call function `mime-preview-quit'."
1509 (while (null (setq cinfo
1510 (get-text-property (point) 'mime-view-entity)))
1512 (let ((r (mime-entity-parent cinfo))
1515 (while (setq point (previous-single-property-change
1516 (point) 'mime-view-entity))
1518 (when (eq r (get-text-property (point) 'mime-view-entity))
1519 (if (or (eq mime-preview-move-scroll t)
1520 (and mime-preview-move-scroll
1523 (move-to-window-line -1)
1524 (forward-line (* -1 next-screen-context-lines))
1527 (recenter next-screen-context-lines))
1529 (mime-preview-quit)))))
1531 (defun mime-preview-move-to-previous ()
1532 "Move to previous entity.
1533 If there is no previous entity, it calls function registered in
1534 variable `mime-preview-over-to-previous-method-alist'."
1536 (while (and (not (bobp))
1537 (null (get-text-property (point) 'mime-view-entity)))
1539 (let ((point (previous-single-property-change (point) 'mime-view-entity)))
1541 (>= point (point-min)))
1542 (if (get-text-property (1- point) 'mime-view-entity)
1543 (progn (goto-char point)
1545 (or (eq mime-preview-move-scroll t)
1546 (and mime-preview-move-scroll
1549 (move-to-window-line 0)
1550 (forward-line next-screen-context-lines)
1553 (recenter (* -1 next-screen-context-lines))))
1554 (goto-char (1- point))
1555 (mime-preview-move-to-previous))
1556 (let ((f (assq (mime-preview-original-major-mode)
1557 mime-preview-over-to-previous-method-alist)))
1559 (funcall (cdr f)))))))
1561 (defun mime-preview-move-to-next ()
1562 "Move to next entity.
1563 If there is no previous entity, it calls function registered in
1564 variable `mime-preview-over-to-next-method-alist'."
1566 (while (and (not (eobp))
1567 (null (get-text-property (point) 'mime-view-entity)))
1569 (let ((point (next-single-property-change (point) 'mime-view-entity)))
1571 (<= point (point-max)))
1574 (if (null (get-text-property point 'mime-view-entity))
1575 (mime-preview-move-to-next)
1577 (or (eq mime-preview-move-scroll t)
1578 (and mime-preview-move-scroll
1581 (move-to-window-line -1)
1583 (* -1 next-screen-context-lines))
1586 (recenter next-screen-context-lines))))
1587 (let ((f (assq (mime-preview-original-major-mode)
1588 mime-preview-over-to-next-method-alist)))
1590 (funcall (cdr f)))))))
1592 (defun mime-preview-scroll-up-entity (&optional h)
1593 "Scroll up current entity.
1594 If reached to (point-max), it calls function registered in variable
1595 `mime-preview-over-to-next-method-alist'."
1598 (let ((f (assq (mime-preview-original-major-mode)
1599 mime-preview-over-to-next-method-alist)))
1603 (or (next-single-property-change (point) 'mime-view-entity)
1605 (bottom (window-end (selected-window))))
1608 (progn (goto-char point)
1609 (recenter next-screen-context-lines))
1613 (goto-char (point-max))))))))
1615 (defun mime-preview-scroll-down-entity (&optional h)
1616 "Scroll down current entity.
1617 If reached to (point-min), it calls function registered in variable
1618 `mime-preview-over-to-previous-method-alist'."
1621 (let ((f (assq (mime-preview-original-major-mode)
1622 mime-preview-over-to-previous-method-alist)))
1626 (or (previous-single-property-change (point) 'mime-view-entity)
1628 (top (window-start (selected-window))))
1631 (progn (goto-char point)
1632 (recenter (* -1 next-screen-context-lines)))
1635 (beginning-of-buffer
1636 (goto-char (point-min))))))))
1638 (defun mime-preview-next-line-entity (&optional lines)
1639 "Scroll up one line (or prefix LINES lines).
1640 If LINES is negative, scroll down LINES lines."
1642 (mime-preview-scroll-up-entity (or lines 1)))
1644 (defun mime-preview-previous-line-entity (&optional lines)
1645 "Scrroll down one line (or prefix LINES lines).
1646 If LINES is negative, scroll up LINES lines."
1648 (mime-preview-scroll-down-entity (or lines 1)))
1654 (defun mime-preview-toggle-display (type &optional display)
1655 (let ((situation (mime-preview-find-boundary-info))
1656 (sym (intern (concat "*" (symbol-name type))))
1658 (setq p-beg (aref situation 0)
1659 p-end (aref situation 1)
1660 entity (aref situation 2)
1661 situation (get-text-property p-beg 'mime-view-situation))
1662 (cond ((eq display 'invisible)
1667 (eq (cdr (or (assq sym situation)
1668 (assq type situation)))
1670 (setq situation (put-alist sym (if display
1675 (let ((inhibit-read-only t))
1676 (delete-region p-beg p-end)
1677 (mime-display-entity entity situation)))
1678 (let ((ret (assoc situation mime-preview-situation-example-list)))
1680 (setcdr ret (1+ (cdr ret)))
1681 (add-to-list 'mime-preview-situation-example-list
1682 (cons situation 0))))))
1684 (defun mime-preview-toggle-header (&optional force-visible)
1686 (mime-preview-toggle-display 'header force-visible))
1688 (defun mime-preview-toggle-content (&optional force-visible)
1690 (mime-preview-toggle-display 'body force-visible))
1692 (defun mime-preview-show-header ()
1694 (mime-preview-toggle-display 'header 'visible))
1696 (defun mime-preview-show-content ()
1698 (mime-preview-toggle-display 'body 'visible))
1700 (defun mime-preview-hide-header ()
1702 (mime-preview-toggle-display 'header 'invisible))
1704 (defun mime-preview-hide-content ()
1706 (mime-preview-toggle-display 'body 'invisible))
1712 (defun mime-preview-quit ()
1713 "Quit from MIME-preview buffer.
1714 It calls function registered in variable
1715 `mime-preview-quitting-method-alist'."
1717 (let ((r (assq (mime-preview-original-major-mode)
1718 mime-preview-quitting-method-alist)))
1720 (funcall (cdr r)))))
1722 (defun mime-preview-kill-buffer ()
1724 (kill-buffer (current-buffer)))
1730 (provide 'mime-view)
1733 (setq mime-situation-examples-file nil)
1734 ;; to avoid to read situation-examples-file at compile time.
1737 (mime-view-read-situation-examples-file)
1739 ;;; mime-view.el ends here