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)
425 print-length print-level)
427 (insert ";;; " (file-name-nondirectory file) "\n")
428 (insert "\n;; This file is generated automatically by "
429 mime-view-version "\n\n")
430 (insert ";;; Code:\n\n")
431 (if mime-preview-situation-example-list
432 (pp `(setq mime-preview-situation-example-list
433 ',mime-preview-situation-example-list)
435 (if mime-acting-situation-example-list
436 (pp `(setq mime-acting-situation-example-list
437 ',mime-acting-situation-example-list)
440 (file-name-nondirectory file)
443 ((boundp 'buffer-file-coding-system)
444 (setq buffer-file-coding-system
445 mime-situation-examples-file-coding-system))
446 ((boundp 'file-coding-system)
447 (setq file-coding-system
448 mime-situation-examples-file-coding-system)))
449 ;; (setq buffer-file-coding-system
450 ;; mime-situation-examples-file-coding-system)
451 (setq buffer-file-name file)
454 (add-hook 'kill-emacs-hook 'mime-save-situation-examples)
456 (defun mime-reduce-situation-examples (situation-examples)
457 (let ((len (length situation-examples))
465 ir situation-examples)
469 jr situation-examples)
473 (setq ret (mime-compare-situation-with-example (car ic)(car jc))
475 det-ret (+ (length (car ic))(length (car jc)))
476 det-org (length (cdr ret))
477 freq (+ (cdr ic)(cdr jc)))
478 (cond ((< max-sim sim)
485 dest (cons (cdr ret) freq))
488 (cond ((> min-det-ret det-ret)
489 (setq min-det-ret det-ret
494 dest (cons (cdr ret) freq))
496 ((= min-det-ret det-ret)
497 (cond ((> min-det-org det-org)
498 (setq min-det-org det-org
502 dest (cons (cdr ret) freq))
504 ((= min-det-org det-org)
505 (cond ((> min-freq freq)
509 dest (cons (cdr ret) freq))
523 (setq jr (nthcdr (1- d-j) situation-examples))
524 (setcdr jr (cddr jr))
526 (setq situation-examples
527 (cdr situation-examples))
528 (setq ir (nthcdr (1- d-i) situation-examples))
529 (setcdr ir (cddr ir))
531 (if (setq ir (assoc (car dest) situation-examples))
533 (setcdr ir (+ (cdr ir)(cdr dest)))
535 (cons dest situation-examples)
536 ;; situation-examples may be modified.
540 ;;; @ presentation of preview
546 ;;; @@@ predicate function
549 ;; (defun mime-view-entity-button-visible-p (entity)
550 ;; "Return non-nil if header of ENTITY is visible.
551 ;; Please redefine this function if you want to change default setting."
552 ;; (let ((media-type (mime-entity-media-type entity))
553 ;; (media-subtype (mime-entity-media-subtype entity)))
554 ;; (or (not (eq media-type 'application))
555 ;; (and (not (eq media-subtype 'x-selection))
556 ;; (or (not (eq media-subtype 'octet-stream))
557 ;; (let ((mother-entity (mime-entity-parent entity)))
558 ;; (or (not (eq (mime-entity-media-type mother-entity)
560 ;; (not (eq (mime-entity-media-subtype mother-entity)
565 ;;; @@@ entity button generator
568 (defun mime-view-insert-entity-button (entity)
569 "Insert entity-button of ENTITY."
570 (let ((entity-node-id (mime-entity-node-id entity))
571 (params (mime-entity-parameters entity))
572 (subject (mime-view-entity-title entity)))
574 (let ((access-type (assoc "access-type" params))
575 (num (or (cdr (assoc "x-part-number" params))
576 (if (consp entity-node-id)
579 (format "%s" (1+ num))
581 (reverse entity-node-id) ".")
585 (let ((server (assoc "server" params)))
586 (setq access-type (cdr access-type))
588 (format "%s %s ([%s] %s)"
589 num subject access-type (cdr server))
590 (let ((site (cdr (assoc "site" params)))
591 (dir (cdr (assoc "directory" params)))
592 (url (cdr (assoc "url" params)))
595 (format "%s %s ([%s] %s)"
596 num subject access-type url)
597 (format "%s %s ([%s] %s:%s)"
598 num subject access-type site dir))
602 (let* ((charset (cdr (assoc "charset" params)))
603 (encoding (mime-entity-encoding entity))
604 (rest (format " <%s/%s%s%s>"
605 (mime-entity-media-type entity)
606 (mime-entity-media-subtype entity)
608 (concat "; " charset)
611 (concat " (" encoding ")")
615 (if (>= (+ (current-column)(length rest))(window-width))
619 (function mime-preview-play-current-entity))
626 (defvar mime-header-presentation-method-alist nil
627 "Alist of major mode vs. corresponding header-presentation-method functions.
628 Each element looks like (SYMBOL . FUNCTION).
629 SYMBOL must be major mode in raw-buffer or t. t means default.
630 Interface of FUNCTION must be (ENTITY SITUATION).")
632 (defvar mime-view-ignored-field-list
633 '(".*Received:" ".*Path:" ".*Id:" "^References:"
634 "^Replied:" "^Errors-To:"
635 "^Lines:" "^Sender:" ".*Host:" "^Xref:"
636 "^Content-Type:" "^Precedence:"
637 "^Status:" "^X-VM-.*:")
638 "All fields that match this list will be hidden in MIME preview buffer.
639 Each elements are regexp of field-name.")
641 (defvar mime-view-visible-field-list '("^Dnas.*:" "^Message-Id:")
642 "All fields that match this list will be displayed in MIME preview buffer.
643 Each elements are regexp of field-name.")
649 ;;; @@@ predicate function
652 (in-calist-package 'mime-view)
654 (defun mime-calist::field-match-method-as-default-rule (calist
655 field-type field-value)
656 (let ((s-field (assq field-type calist)))
657 (cond ((null s-field)
658 (cons (cons field-type field-value) calist)
662 (define-calist-field-match-method
663 'header #'mime-calist::field-match-method-as-default-rule)
665 (define-calist-field-match-method
666 'body #'mime-calist::field-match-method-as-default-rule)
669 (defvar mime-preview-condition nil
670 "Condition-tree about how to display entity.")
672 (ctree-set-calist-strictly
673 'mime-preview-condition '((type . application)(subtype . octet-stream)
676 (ctree-set-calist-strictly
677 'mime-preview-condition '((type . application)(subtype . octet-stream)
680 (ctree-set-calist-strictly
681 'mime-preview-condition '((type . application)(subtype . octet-stream)
685 (ctree-set-calist-strictly
686 'mime-preview-condition '((type . application)(subtype . pgp)
689 (ctree-set-calist-strictly
690 'mime-preview-condition '((type . application)(subtype . x-latex)
693 (ctree-set-calist-strictly
694 'mime-preview-condition '((type . application)(subtype . x-selection)
697 (ctree-set-calist-strictly
698 'mime-preview-condition '((type . application)(subtype . x-comment)
701 (ctree-set-calist-strictly
702 'mime-preview-condition '((type . message)(subtype . delivery-status)
705 (ctree-set-calist-strictly
706 'mime-preview-condition
708 (body-presentation-method . mime-display-text/plain)))
710 (ctree-set-calist-strictly
711 'mime-preview-condition
714 (body-presentation-method . mime-display-text/plain)))
716 (ctree-set-calist-strictly
717 'mime-preview-condition
718 '((type . text)(subtype . enriched)
720 (body-presentation-method . mime-display-text/enriched)))
722 (ctree-set-calist-strictly
723 'mime-preview-condition
724 '((type . text)(subtype . richtext)
726 (body-presentation-method . mime-display-text/richtext)))
728 (autoload 'mime-display-application/x-postpet "postpet")
730 (ctree-set-calist-strictly
731 'mime-preview-condition
732 '((type . application)(subtype . x-postpet)
734 (body-presentation-method . mime-display-application/x-postpet)))
736 (ctree-set-calist-strictly
737 'mime-preview-condition
738 '((type . text)(subtype . t)
740 (body-presentation-method . mime-display-text/plain)))
742 (ctree-set-calist-strictly
743 'mime-preview-condition
744 '((type . multipart)(subtype . alternative)
746 (body-presentation-method . mime-display-multipart/alternative)))
748 (ctree-set-calist-strictly
749 'mime-preview-condition
750 '((type . multipart)(subtype . related)
752 (body-presentation-method . mime-display-multipart/related)))
754 (ctree-set-calist-strictly
755 'mime-preview-condition
756 '((type . multipart)(subtype . t)
758 (body-presentation-method . mime-display-multipart/mixed)))
760 (ctree-set-calist-strictly
761 'mime-preview-condition
762 '((type . message)(subtype . partial)
764 (body-presentation-method . mime-display-message/partial-button)))
766 (ctree-set-calist-strictly
767 'mime-preview-condition
768 '((type . message)(subtype . rfc822)
770 (body-presentation-method . mime-display-multipart/mixed)
771 (childrens-situation (header . visible)
772 (entity-button . invisible))))
774 (ctree-set-calist-strictly
775 'mime-preview-condition
776 '((type . message)(subtype . news)
778 (body-presentation-method . mime-display-multipart/mixed)
779 (childrens-situation (header . visible)
780 (entity-button . invisible))))
783 ;;; @@@ entity presentation
786 (defun mime-display-text/plain (entity situation)
788 (narrow-to-region (point-max)(point-max))
790 (mime-insert-text-content entity)
792 (message "Can't decode current entity.")
794 (run-hooks 'mime-text-decode-hook)
795 (goto-char (point-max))
796 (if (not (eq (char-after (1- (point))) ?\n))
799 (mime-add-url-buttons)
800 (run-hooks 'mime-display-text/plain-hook)
803 (defun mime-display-text/richtext (entity situation)
805 (narrow-to-region (point-max)(point-max))
806 (mime-insert-text-content entity)
807 (run-hooks 'mime-text-decode-hook)
808 (let ((beg (point-min))
809 (adaptive-fill-mode nil))
810 (remove-text-properties beg (point-max) '(face nil))
811 (richtext-decode beg (point-max))
814 (defun mime-display-text/enriched (entity situation)
816 (narrow-to-region (point-max)(point-max))
817 (mime-insert-text-content entity)
818 (run-hooks 'mime-text-decode-hook)
819 (let ((beg (point-min))
820 (adaptive-fill-mode nil))
821 (remove-text-properties beg (point-max) '(face nil))
822 (enriched-decode beg (point-max))
826 (defvar mime-view-announcement-for-message/partial
827 (if (and (>= emacs-major-version 19) window-system)
829 \[[ This is message/partial style split message. ]]
830 \[[ Please press `v' key in this buffer ]]
831 \[[ or click here by mouse button-2. ]]"
833 \[[ This is message/partial style split message. ]]
834 \[[ Please press `v' key in this buffer. ]]"
837 (defun mime-display-message/partial-button (&optional entity situation)
839 (goto-char (point-max))
840 (if (not (search-backward "\n\n" nil t))
843 (goto-char (point-max))
844 (narrow-to-region (point-max)(point-max))
845 (insert mime-view-announcement-for-message/partial)
846 (mime-add-button (point-min)(point-max)
847 #'mime-preview-play-current-entity)
850 (defun mime-display-multipart/mixed (entity situation)
851 (let ((children (mime-entity-children entity))
852 (original-major-mode-cell (assq 'major-mode situation))
854 (cdr (assq 'childrens-situation situation))))
855 (if original-major-mode-cell
856 (setq default-situation
857 (cons original-major-mode-cell default-situation)))
859 (mime-display-entity (car children) nil default-situation)
860 (setq children (cdr children))
863 (defcustom mime-view-type-subtype-score-alist
864 '(((text . enriched) . 3)
865 ((text . richtext) . 2)
868 "Alist MEDIA-TYPE vs corresponding score.
869 MEDIA-TYPE must be (TYPE . SUBTYPE), TYPE or t. t means default."
871 :type '(repeat (cons (choice :tag "Media-Type"
872 (cons :tag "Type/Subtype"
873 (symbol :tag "Primary-type")
874 (symbol :tag "Subtype"))
876 (const :tag "Default" t))
879 (defun mime-display-multipart/alternative (entity situation)
880 (let* ((children (mime-entity-children entity))
881 (original-major-mode-cell (assq 'major-mode situation))
883 (cdr (assq 'childrens-situation situation)))
888 (if original-major-mode-cell
889 (setq default-situation
890 (cons original-major-mode-cell default-situation)))
895 (mime-find-entity-preview-situation
896 child default-situation)))
897 (if (cdr (assq 'body-presentation-method situation))
902 (cdr (assq 'type situation))
903 (cdr (assq 'subtype situation)))
904 mime-view-type-subtype-score-alist)
906 (cdr (assq 'type situation))
907 mime-view-type-subtype-score-alist)
910 mime-view-type-subtype-score-alist)
912 (if (> score max-score)
922 (let ((child (car children))
923 (situation (car situations)))
924 (mime-display-entity child (if (= i p)
926 (put-alist 'body 'invisible
927 (copy-alist situation)))))
928 (setq children (cdr children)
929 situations (cdr situations)
932 (defun mime-display-multipart/related (entity situation)
933 (let* ((param-start (mime-parse-msg-id
934 (std11-lexical-analyze
936 (mime-content-type-parameters
937 (mime-entity-content-type entity)))))))
938 (start (or (and param-start (mime-find-entity-from-content-id
941 (car (mime-entity-children entity))))
942 (original-major-mode-cell (assq 'major-mode situation))
943 (default-situation (cdr (assq 'childrens-situation situation))))
945 (if original-major-mode-cell
946 (setq default-situation
947 (cons original-major-mode-cell default-situation)))
948 (mime-display-entity start nil default-situation))))
950 ;;; @ acting-condition
953 (defvar mime-acting-condition nil
954 "Condition-tree about how to process entity.")
956 (defun mime-view-read-mailcap-files (&optional files)
958 (setq files mime-view-mailcap-files))
961 (setq file (car files))
962 (if (file-readable-p file)
963 (setq entries (append entries (mime-parse-mailcap-file file))))
964 (setq files (cdr files)))
966 (let ((entry (car entries))
969 (let* ((field (car entry))
970 (field-type (car field)))
971 (cond ((eq field-type 'view) (setq view field))
972 ((eq field-type 'print) (setq print field))
973 ((memq field-type '(compose composetyped edit)))
974 (t (setq shared (cons field shared))))
976 (setq entry (cdr entry)))
977 (setq shared (nreverse shared))
978 (ctree-set-calist-with-default
979 'mime-acting-condition
980 (append shared (list '(mode . "play")(cons 'method (cdr view)))))
982 (ctree-set-calist-with-default
983 'mime-acting-condition
985 (list '(mode . "print")(cons 'method (cdr view)))))))
986 (setq entries (cdr entries)))))
988 (mime-view-read-mailcap-files)
990 (ctree-set-calist-strictly
991 'mime-acting-condition
992 '((type . application)(subtype . octet-stream)
994 (method . mime-detect-content)
997 (ctree-set-calist-with-default
998 'mime-acting-condition
1000 (method . mime-save-content)))
1002 (ctree-set-calist-strictly
1003 'mime-acting-condition
1004 '((type . text)(subtype . x-rot13-47)(mode . "play")
1005 (method . mime-view-caesar)
1007 (ctree-set-calist-strictly
1008 'mime-acting-condition
1009 '((type . text)(subtype . x-rot13-47-48)(mode . "play")
1010 (method . mime-view-caesar)
1013 (ctree-set-calist-strictly
1014 'mime-acting-condition
1015 '((type . message)(subtype . rfc822)(mode . "play")
1016 (method . mime-view-message/rfc822)
1018 (ctree-set-calist-strictly
1019 'mime-acting-condition
1020 '((type . message)(subtype . partial)(mode . "play")
1021 (method . mime-store-message/partial-piece)
1024 (ctree-set-calist-strictly
1025 'mime-acting-condition
1026 '((type . message)(subtype . external-body)
1027 ("access-type" . "anon-ftp")
1028 (method . mime-view-message/external-anon-ftp)
1031 (ctree-set-calist-strictly
1032 'mime-acting-condition
1033 '((type . message)(subtype . external-body)
1034 ("access-type" . "url")
1035 (method . mime-view-message/external-url)
1038 (ctree-set-calist-strictly
1039 'mime-acting-condition
1040 '((type . application)(subtype . octet-stream)
1041 (method . mime-save-content)
1045 ;;; @ quitting method
1048 (defvar mime-preview-quitting-method-alist
1049 '((mime-show-message-mode
1050 . mime-preview-quitting-method-for-mime-show-message-mode))
1051 "Alist of major-mode vs. quitting-method of mime-view.")
1053 (defvar mime-preview-over-to-previous-method-alist nil
1054 "Alist of major-mode vs. over-to-previous-method of mime-view.")
1056 (defvar mime-preview-over-to-next-method-alist nil
1057 "Alist of major-mode vs. over-to-next-method of mime-view.")
1060 ;;; @ following method
1063 (defvar mime-preview-following-method-alist nil
1064 "Alist of major-mode vs. following-method of mime-view.")
1066 (defvar mime-view-following-required-fields-list
1073 (defun mime-display-entity (entity &optional situation
1074 default-situation preview-buffer)
1076 (setq preview-buffer (current-buffer)))
1077 (let* (e nb ne nhb nbb)
1078 (in-calist-package 'mime-view)
1081 (mime-find-entity-preview-situation entity default-situation)))
1082 (let ((button-is-invisible
1083 (eq (cdr (or (assq '*entity-button situation)
1084 (assq 'entity-button situation)))
1087 (eq (cdr (or (assq '*header situation)
1088 (assq 'header situation)))
1091 (eq (cdr (or (assq '*body situation)
1092 (assq 'body situation)))
1094 (children (mime-entity-children entity)))
1095 (set-buffer preview-buffer)
1097 (narrow-to-region nb nb)
1098 (or button-is-invisible
1099 ;; (if (mime-view-entity-button-visible-p entity)
1100 (mime-view-insert-entity-button entity)
1103 (if header-is-visible
1104 (let ((header-presentation-method
1105 (or (cdr (assq 'header-presentation-method situation))
1106 (cdr (assq (cdr (assq 'major-mode situation))
1107 mime-header-presentation-method-alist)))))
1109 (if header-presentation-method
1110 (funcall header-presentation-method entity situation)
1111 (mime-insert-header entity
1112 mime-view-ignored-field-list
1113 mime-view-visible-field-list))
1114 (run-hooks 'mime-display-header-hook)
1115 (put-text-property nhb (point-max) 'mime-view-entity-header entity)
1116 (goto-char (point-max))
1121 (let ((body-presentation-method
1122 (cdr (assq 'body-presentation-method situation))))
1123 (if (functionp body-presentation-method)
1124 (funcall body-presentation-method entity situation)
1125 (mime-display-text/plain entity situation)))
1126 (when button-is-invisible
1127 (goto-char (point-max))
1128 (mime-view-insert-entity-button entity)
1130 (unless header-is-visible
1131 (goto-char (point-max))
1134 (setq ne (point-max))
1136 (put-text-property nb ne 'mime-view-entity entity)
1137 (put-text-property nb ne 'mime-view-situation situation)
1138 (put-text-property nbb ne 'mime-view-entity-body entity)
1140 (if (and children body-is-visible)
1141 (let ((body-presentation-method
1142 (cdr (assq 'body-presentation-method situation))))
1143 (if (functionp body-presentation-method)
1144 (funcall body-presentation-method entity situation)
1145 (mime-display-multipart/mixed entity situation))))
1149 ;;; @ MIME viewer mode
1152 (defconst mime-view-menu-title "MIME-View")
1153 (defconst mime-view-menu-list
1154 '((up "Move to upper entity" mime-preview-move-to-upper)
1155 (previous "Move to previous entity" mime-preview-move-to-previous)
1156 (next "Move to next entity" mime-preview-move-to-next)
1157 (scroll-down "Scroll-down" mime-preview-scroll-down-entity)
1158 (scroll-up "Scroll-up" mime-preview-scroll-up-entity)
1159 (play "Play current entity" mime-preview-play-current-entity)
1160 (extract "Extract current entity" mime-preview-extract-current-entity)
1161 (print "Print current entity" mime-preview-print-current-entity)
1163 "Menu for MIME Viewer")
1165 (cond ((featurep 'xemacs)
1166 (defvar mime-view-xemacs-popup-menu
1167 (cons mime-view-menu-title
1170 (vector (nth 1 item)(nth 2 item) t)
1172 mime-view-menu-list)))
1173 (defun mime-view-xemacs-popup-menu (event)
1174 "Popup the menu in the MIME Viewer buffer"
1176 (select-window (event-window event))
1177 (set-buffer (event-buffer event))
1178 (popup-menu 'mime-view-xemacs-popup-menu))
1179 (defvar mouse-button-2 'button2)
1180 (defvar mouse-button-3 'button3)
1183 (defvar mime-view-popup-menu
1184 (let ((menu (make-sparse-keymap mime-view-menu-title)))
1188 (list (intern (nth 1 item)) 'menu-item
1189 (nth 1 item)(nth 2 item))
1191 mime-view-menu-list))))
1192 (defun mime-view-popup-menu (event)
1193 "Popup the menu in the MIME Viewer buffer"
1195 (let ((menu mime-view-popup-menu) events func)
1196 (setq events (x-popup-menu t menu))
1198 (setq func (lookup-key menu (apply #'vector events)))
1201 (defvar mouse-button-2 [mouse-2])
1202 (defvar mouse-button-3 [mouse-3])
1205 (defun mime-view-define-keymap (&optional default)
1206 (let ((mime-view-mode-map (if (keymapp default)
1207 (copy-keymap default)
1208 (make-sparse-keymap))))
1209 (define-key mime-view-mode-map
1210 "u" (function mime-preview-move-to-upper))
1211 (define-key mime-view-mode-map
1212 "p" (function mime-preview-move-to-previous))
1213 (define-key mime-view-mode-map
1214 "n" (function mime-preview-move-to-next))
1215 (define-key mime-view-mode-map
1216 "\e\t" (function mime-preview-move-to-previous))
1217 (define-key mime-view-mode-map
1218 "\t" (function mime-preview-move-to-next))
1219 (define-key mime-view-mode-map
1220 " " (function mime-preview-scroll-up-entity))
1221 (define-key mime-view-mode-map
1222 "\M- " (function mime-preview-scroll-down-entity))
1223 (define-key mime-view-mode-map
1224 "\177" (function mime-preview-scroll-down-entity))
1225 (define-key mime-view-mode-map
1226 "\C-m" (function mime-preview-next-line-entity))
1227 (define-key mime-view-mode-map
1228 "\C-\M-m" (function mime-preview-previous-line-entity))
1229 (define-key mime-view-mode-map
1230 "v" (function mime-preview-play-current-entity))
1231 (define-key mime-view-mode-map
1232 "e" (function mime-preview-extract-current-entity))
1233 (define-key mime-view-mode-map
1234 "\C-c\C-p" (function mime-preview-print-current-entity))
1236 (define-key mime-view-mode-map
1237 "\C-c\C-t\C-f" (function mime-preview-toggle-header))
1238 (define-key mime-view-mode-map
1239 "\C-c\C-th" (function mime-preview-toggle-header))
1240 (define-key mime-view-mode-map
1241 "\C-c\C-t\C-c" (function mime-preview-toggle-content))
1243 (define-key mime-view-mode-map
1244 "\C-c\C-v\C-f" (function mime-preview-show-header))
1245 (define-key mime-view-mode-map
1246 "\C-c\C-vh" (function mime-preview-show-header))
1247 (define-key mime-view-mode-map
1248 "\C-c\C-v\C-c" (function mime-preview-show-content))
1250 (define-key mime-view-mode-map
1251 "\C-c\C-d\C-f" (function mime-preview-hide-header))
1252 (define-key mime-view-mode-map
1253 "\C-c\C-dh" (function mime-preview-hide-header))
1254 (define-key mime-view-mode-map
1255 "\C-c\C-d\C-c" (function mime-preview-hide-content))
1257 (define-key mime-view-mode-map
1258 "a" (function mime-preview-follow-current-entity))
1259 (define-key mime-view-mode-map
1260 "q" (function mime-preview-quit))
1261 (define-key mime-view-mode-map
1262 "\C-c\C-x" (function mime-preview-kill-buffer))
1263 ;; (define-key mime-view-mode-map
1264 ;; "<" (function beginning-of-buffer))
1265 ;; (define-key mime-view-mode-map
1266 ;; ">" (function end-of-buffer))
1267 (define-key mime-view-mode-map
1268 "?" (function describe-mode))
1269 (define-key mime-view-mode-map
1270 [tab] (function mime-preview-move-to-next))
1271 (define-key mime-view-mode-map
1272 [delete] (function mime-preview-scroll-down-entity))
1273 (define-key mime-view-mode-map
1274 [backspace] (function mime-preview-scroll-down-entity))
1275 (if (functionp default)
1276 (cond ((featurep 'xemacs)
1277 (set-keymap-default-binding mime-view-mode-map default)
1280 (setq mime-view-mode-map
1281 (append mime-view-mode-map (list (cons t default))))
1284 (define-key mime-view-mode-map
1285 mouse-button-2 (function mime-button-dispatcher))
1287 (cond ((featurep 'xemacs)
1288 (define-key mime-view-mode-map
1289 mouse-button-3 (function mime-view-xemacs-popup-menu))
1291 ((>= emacs-major-version 19)
1292 (define-key mime-view-mode-map
1293 mouse-button-3 (function mime-view-popup-menu))
1294 (define-key mime-view-mode-map [menu-bar mime-view]
1295 (cons mime-view-menu-title
1296 (make-sparse-keymap mime-view-menu-title)))
1299 (define-key mime-view-mode-map
1300 (vector 'menu-bar 'mime-view (car item))
1301 (cons (nth 1 item)(nth 2 item)))
1303 (reverse mime-view-menu-list))
1305 ;; (run-hooks 'mime-view-define-keymap-hook)
1306 mime-view-mode-map))
1308 (defvar mime-view-mode-default-map (mime-view-define-keymap))
1311 (defsubst mime-maybe-hide-echo-buffer ()
1312 "Clear mime-echo buffer and delete window for it."
1313 (let ((buf (get-buffer mime-echo-buffer-name)))
1318 (let ((win (get-buffer-window buf)))
1325 (defvar mime-view-redisplay nil)
1328 (defun mime-display-message (message &optional preview-buffer
1329 mother default-keymap-or-function
1330 original-major-mode keymap)
1331 "View MESSAGE in MIME-View mode.
1333 Optional argument PREVIEW-BUFFER specifies the buffer of the
1334 presentation. It must be either nil or a name of preview buffer.
1336 Optional argument MOTHER specifies mother-buffer of the preview-buffer.
1338 Optional argument DEFAULT-KEYMAP-OR-FUNCTION is nil, keymap or
1339 function. If it is a keymap, keymap of MIME-View mode will be added
1340 to it. If it is a function, it will be bound as default binding of
1341 keymap of MIME-View mode.
1343 Optional argument ORIGINAL-MAJOR-MODE is major-mode of representation
1344 buffer of MESSAGE. If it is nil, current `major-mode' is used.
1346 Optional argument KEYMAP is keymap of MIME-View mode. If it is
1347 non-nil, DEFAULT-KEYMAP-OR-FUNCTION is ignored. If it is nil,
1348 `mime-view-mode-default-map' is used."
1349 (mime-maybe-hide-echo-buffer)
1350 (let ((win-conf (current-window-configuration)))
1352 (setq preview-buffer
1353 (concat "*Preview-" (mime-entity-name message) "*")))
1354 (or original-major-mode
1355 (setq original-major-mode major-mode))
1356 (let ((inhibit-read-only t))
1357 (set-buffer (get-buffer-create preview-buffer))
1361 (setq mime-mother-buffer mother))
1362 (setq mime-preview-original-window-configuration win-conf)
1363 (setq major-mode 'mime-view-mode)
1364 (setq mode-name "MIME-View")
1365 (mime-display-entity message nil
1366 `((entity-button . invisible)
1368 (major-mode . ,original-major-mode))
1372 (if default-keymap-or-function
1373 (mime-view-define-keymap default-keymap-or-function)
1374 mime-view-mode-default-map)))
1376 (next-single-property-change (point-min) 'mime-view-entity)))
1379 (goto-char (point-min))
1380 (search-forward "\n\n" nil t)))
1381 (run-hooks 'mime-view-mode-hook)
1382 (set-buffer-modified-p nil)
1383 (setq buffer-read-only t)
1387 (defun mime-view-buffer (&optional raw-buffer preview-buffer mother
1388 default-keymap-or-function
1389 representation-type)
1390 "View RAW-BUFFER in MIME-View mode.
1391 Optional argument PREVIEW-BUFFER is either nil or a name of preview
1393 Optional argument DEFAULT-KEYMAP-OR-FUNCTION is nil, keymap or
1394 function. If it is a keymap, keymap of MIME-View mode will be added
1395 to it. If it is a function, it will be bound as default binding of
1396 keymap of MIME-View mode.
1397 Optional argument REPRESENTATION-TYPE is representation-type of
1398 message. It must be nil, `binary' or `cooked'. If it is nil,
1399 `cooked' is used as default."
1402 (setq raw-buffer (current-buffer)))
1403 (or representation-type
1404 (setq representation-type
1406 (set-buffer raw-buffer)
1407 (cdr (or (assq major-mode mime-raw-representation-type-alist)
1408 (assq t mime-raw-representation-type-alist)))
1410 (if (eq representation-type 'binary)
1411 (setq representation-type 'buffer)
1413 (setq preview-buffer (mime-display-message
1414 (mime-open-entity representation-type raw-buffer)
1415 preview-buffer mother default-keymap-or-function))
1416 (or (get-buffer-window preview-buffer)
1417 (let ((r-win (get-buffer-window raw-buffer)))
1419 (set-window-buffer r-win preview-buffer)
1420 (let ((m-win (and mother (get-buffer-window mother))))
1422 (set-window-buffer m-win preview-buffer)
1423 (switch-to-buffer preview-buffer)
1426 (defun mime-view-mode (&optional mother ctl encoding
1427 raw-buffer preview-buffer
1428 default-keymap-or-function)
1429 "Major mode for viewing MIME message.
1431 Here is a list of the standard keys for mime-view-mode.
1436 u Move to upper content
1437 p or M-TAB Move to previous content
1438 n or TAB Move to next content
1439 SPC Scroll up or move to next content
1440 M-SPC or DEL Scroll down or move to previous content
1441 RET Move to next line
1442 M-RET Move to previous line
1443 v Decode current content as `play mode'
1444 e Decode current content as `extract mode'
1445 C-c C-p Decode current content as `print mode'
1446 a Followup to current content.
1448 button-2 Move to point under the mouse cursor
1449 and decode current content as `play mode'
1452 (unless mime-view-redisplay
1454 (if raw-buffer (set-buffer raw-buffer))
1457 (or (assq major-mode mime-raw-representation-type-alist)
1458 (assq t mime-raw-representation-type-alist)))))
1459 (if (eq type 'binary)
1462 (setq mime-message-structure (mime-open-entity type raw-buffer))
1463 (or (mime-entity-content-type mime-message-structure)
1464 (mime-entity-set-content-type mime-message-structure ctl))
1466 (or (mime-entity-encoding mime-message-structure)
1467 (mime-entity-set-encoding mime-message-structure encoding))
1469 (mime-display-message mime-message-structure preview-buffer
1470 mother default-keymap-or-function)
1477 (defun mime-preview-find-boundary-info (&optional with-children)
1478 "Return boundary information of current part.
1479 If WITH-CHILDREN, refer boundary surrounding current part and its branches."
1485 (get-text-property (point) 'mime-view-entity)))
1486 (> (point) (point-min)))
1488 (setq p-beg (previous-single-property-change (point) 'mime-view-entity))
1489 (setq entity-node-id (and entity (mime-entity-node-id entity)))
1490 (setq len (length entity-node-id))
1493 (if (eq (next-single-property-change (point-min)
1499 ((eq (next-single-property-change p-beg 'mime-view-entity)
1501 (setq p-beg (point))
1503 (setq p-end (next-single-property-change p-beg 'mime-view-entity))
1505 (setq p-end (point-max))
1507 ((null entity-node-id)
1508 (setq p-end (point-max))
1515 (next-single-property-change
1516 (point) 'mime-view-entity))
1518 (let ((rc (mime-entity-node-id
1519 (get-text-property (point)
1520 'mime-view-entity))))
1521 (or (and (>= (setq i (- (length rc) len)) 0)
1522 (equal entity-node-id (nthcdr i rc)))
1524 (setq p-end (or (next-single-property-change
1525 (point) 'mime-view-entity)
1527 (setq p-end (point-max))))
1529 (vector p-beg p-end entity)))
1535 (autoload 'mime-preview-play-current-entity "mime-play"
1536 "Play current entity." t)
1538 (defun mime-preview-extract-current-entity (&optional ignore-examples)
1539 "Extract current entity into file (maybe).
1540 It decodes current entity to call internal or external method as
1541 \"extract\" mode. The method is selected from variable
1542 `mime-acting-condition'."
1544 (mime-preview-play-current-entity ignore-examples "extract")
1547 (defun mime-preview-print-current-entity (&optional ignore-examples)
1548 "Print current entity (maybe).
1549 It decodes current entity to call internal or external method as
1550 \"print\" mode. The method is selected from variable
1551 `mime-acting-condition'."
1553 (mime-preview-play-current-entity ignore-examples "print")
1560 (defun mime-preview-follow-current-entity ()
1561 "Write follow message to current entity.
1562 It calls following-method selected from variable
1563 `mime-preview-following-method-alist'."
1565 (let* ((boundary-info (mime-preview-find-boundary-info t))
1566 (p-beg (aref boundary-info 0))
1567 (p-end (aref boundary-info 1))
1568 (entity (aref boundary-info 2))
1570 (if (or (get-text-property p-beg 'mime-view-entity-body)
1574 (next-single-property-change
1575 p-beg 'mime-view-entity-body nil
1576 (or (next-single-property-change p-beg 'mime-view-entity)
1578 (let* ((mode (mime-preview-original-major-mode 'recursive))
1579 (entity-node-id (and entity (mime-entity-node-id entity)))
1581 (format "%s-%s" (buffer-name) (reverse entity-node-id)))
1583 (the-buf (current-buffer))
1586 (set-buffer (setq new-buf (get-buffer-create new-name)))
1589 (insert-buffer-substring the-buf pb-beg p-end)
1590 (goto-char (point-min))
1591 (let ((current-entity
1593 (eq (mime-entity-media-type entity) 'message)
1594 (eq (mime-entity-media-subtype entity) 'rfc822))
1595 (car (mime-entity-children entity))
1597 (while (and current-entity
1598 (if (and (eq (mime-entity-media-type
1599 current-entity) 'message)
1600 (eq (mime-entity-media-subtype
1601 current-entity) 'rfc822))
1603 (mime-insert-header current-entity fields)
1605 (setq fields (std11-collect-field-names)
1606 current-entity (mime-entity-parent current-entity))
1608 (let ((rest mime-view-following-required-fields-list)
1611 (setq field-name (car rest))
1612 (or (std11-field-body field-name)
1615 (set-buffer the-buf)
1616 (let ((entity (when mime-mother-buffer
1617 (set-buffer mime-mother-buffer)
1618 (get-text-property (point)
1619 'mime-view-entity))))
1621 (null (setq ret (mime-entity-fetch-field
1622 entity field-name))))
1623 (setq entity (mime-entity-parent entity)))))
1625 (insert (concat field-name ": " ret "\n"))
1627 (setq rest (cdr rest))
1630 (let ((f (cdr (assq mode mime-preview-following-method-alist))))
1634 "Sorry, following method for %s is not implemented yet."
1643 (defun mime-preview-move-to-upper ()
1644 "Move to upper entity.
1645 If there is no upper entity, call function `mime-preview-quit'."
1648 (while (null (setq cinfo
1649 (get-text-property (point) 'mime-view-entity)))
1652 (let ((r (mime-entity-parent cinfo))
1655 (while (setq point (previous-single-property-change
1656 (point) 'mime-view-entity))
1658 (when (eq r (get-text-property (point) 'mime-view-entity))
1659 (if (or (eq mime-preview-move-scroll t)
1660 (and mime-preview-move-scroll
1663 (move-to-window-line -1)
1664 (forward-line (* -1 next-screen-context-lines))
1667 (recenter next-screen-context-lines))
1674 (defun mime-preview-move-to-previous ()
1675 "Move to previous entity.
1676 If there is no previous entity, it calls function registered in
1677 variable `mime-preview-over-to-previous-method-alist'."
1679 (while (and (not (bobp))
1680 (null (get-text-property (point) 'mime-view-entity)))
1683 (let ((point (previous-single-property-change (point) 'mime-view-entity)))
1685 (>= point (point-min)))
1686 (if (get-text-property (1- point) 'mime-view-entity)
1687 (progn (goto-char point)
1689 (or (eq mime-preview-move-scroll t)
1690 (and mime-preview-move-scroll
1693 (move-to-window-line 0)
1694 (forward-line next-screen-context-lines)
1697 (recenter (* -1 next-screen-context-lines))))
1698 (goto-char (1- point))
1699 (mime-preview-move-to-previous)
1701 (let ((f (assq (mime-preview-original-major-mode)
1702 mime-preview-over-to-previous-method-alist)))
1708 (defun mime-preview-move-to-next ()
1709 "Move to next entity.
1710 If there is no previous entity, it calls function registered in
1711 variable `mime-preview-over-to-next-method-alist'."
1713 (while (and (not (eobp))
1714 (null (get-text-property (point) 'mime-view-entity)))
1717 (let ((point (next-single-property-change (point) 'mime-view-entity)))
1719 (<= point (point-max)))
1722 (if (null (get-text-property point 'mime-view-entity))
1723 (mime-preview-move-to-next)
1725 (or (eq mime-preview-move-scroll t)
1726 (and mime-preview-move-scroll
1729 (move-to-window-line -1)
1731 (* -1 next-screen-context-lines))
1734 (recenter next-screen-context-lines))
1736 (let ((f (assq (mime-preview-original-major-mode)
1737 mime-preview-over-to-next-method-alist)))
1743 (defun mime-preview-scroll-up-entity (&optional h)
1744 "Scroll up current entity.
1745 If reached to (point-max), it calls function registered in variable
1746 `mime-preview-over-to-next-method-alist'."
1749 (let ((f (assq (mime-preview-original-major-mode)
1750 mime-preview-over-to-next-method-alist)))
1755 (or (next-single-property-change (point) 'mime-view-entity)
1757 (bottom (window-end (selected-window))))
1760 (progn (goto-char point)
1761 (recenter next-screen-context-lines))
1765 (goto-char (point-max)))))
1768 (defun mime-preview-scroll-down-entity (&optional h)
1769 "Scroll down current entity.
1770 If reached to (point-min), it calls function registered in variable
1771 `mime-preview-over-to-previous-method-alist'."
1774 (let ((f (assq (mime-preview-original-major-mode)
1775 mime-preview-over-to-previous-method-alist)))
1780 (or (previous-single-property-change (point) 'mime-view-entity)
1782 (top (window-start (selected-window))))
1785 (progn (goto-char point)
1786 (recenter (* -1 next-screen-context-lines)))
1789 (beginning-of-buffer
1790 (goto-char (point-min)))))
1793 (defun mime-preview-next-line-entity (&optional lines)
1794 "Scroll up one line (or prefix LINES lines).
1795 If LINES is negative, scroll down LINES lines."
1797 (mime-preview-scroll-up-entity (or lines 1))
1800 (defun mime-preview-previous-line-entity (&optional lines)
1801 "Scrroll down one line (or prefix LINES lines).
1802 If LINES is negative, scroll up LINES lines."
1804 (mime-preview-scroll-down-entity (or lines 1))
1811 (defun mime-preview-toggle-display (type &optional display)
1812 (let ((situation (mime-preview-find-boundary-info t))
1813 (sym (intern (concat "*" (symbol-name type))))
1815 (setq p-beg (aref situation 0)
1816 p-end (aref situation 1)
1817 entity (aref situation 2)
1818 situation (get-text-property p-beg 'mime-view-situation))
1819 (cond ((eq display 'invisible)
1824 (memq (cdr (or (assq sym situation)
1825 (assq type situation)))
1826 '(nil invisible)))))
1827 (setq situation (put-alist sym (if display
1832 (let ((inhibit-read-only t))
1833 (delete-region p-beg p-end)
1834 (mime-display-entity entity situation)))
1835 (let ((ret (assoc situation mime-preview-situation-example-list)))
1837 (setcdr ret (1+ (cdr ret)))
1838 (add-to-list 'mime-preview-situation-example-list
1839 (cons situation 0))))))
1841 (defun mime-preview-toggle-header (&optional force-visible)
1843 (mime-preview-toggle-display 'header force-visible))
1845 (defun mime-preview-toggle-content (&optional force-visible)
1847 (mime-preview-toggle-display 'body force-visible))
1849 (defun mime-preview-show-header ()
1851 (mime-preview-toggle-display 'header 'visible))
1853 (defun mime-preview-show-content ()
1855 (mime-preview-toggle-display 'body 'visible))
1857 (defun mime-preview-hide-header ()
1859 (mime-preview-toggle-display 'header 'invisible))
1861 (defun mime-preview-hide-content ()
1863 (mime-preview-toggle-display 'body 'invisible))
1869 (defun mime-preview-quit ()
1870 "Quit from MIME-preview buffer.
1871 It calls function registered in variable
1872 `mime-preview-quitting-method-alist'."
1874 (let ((r (assq (mime-preview-original-major-mode)
1875 mime-preview-quitting-method-alist)))
1880 (defun mime-preview-kill-buffer ()
1882 (kill-buffer (current-buffer))
1889 (provide 'mime-view)
1892 (setq mime-situation-examples-file nil)
1893 ;; to avoid to read situation-examples-file at compile time.
1896 (mime-view-read-situation-examples-file)
1898 ;;; mime-view.el ends here