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 (remove-text-properties beg (point-max) '(face nil))
810 (richtext-decode beg (point-max))
813 (defun mime-display-text/enriched (entity situation)
815 (narrow-to-region (point-max)(point-max))
816 (mime-insert-text-content entity)
817 (run-hooks 'mime-text-decode-hook)
818 (let ((beg (point-min)))
819 (remove-text-properties beg (point-max) '(face nil))
820 (enriched-decode beg (point-max))
824 (defvar mime-view-announcement-for-message/partial
825 (if (and (>= emacs-major-version 19) window-system)
827 \[[ This is message/partial style split message. ]]
828 \[[ Please press `v' key in this buffer ]]
829 \[[ or click here by mouse button-2. ]]"
831 \[[ This is message/partial style split message. ]]
832 \[[ Please press `v' key in this buffer. ]]"
835 (defun mime-display-message/partial-button (&optional entity situation)
837 (goto-char (point-max))
838 (if (not (search-backward "\n\n" nil t))
841 (goto-char (point-max))
842 (narrow-to-region (point-max)(point-max))
843 (insert mime-view-announcement-for-message/partial)
844 (mime-add-button (point-min)(point-max)
845 #'mime-preview-play-current-entity)
848 (defun mime-display-multipart/mixed (entity situation)
849 (let ((children (mime-entity-children entity))
850 (original-major-mode-cell (assq 'major-mode situation))
852 (cdr (assq 'childrens-situation situation))))
853 (if original-major-mode-cell
854 (setq default-situation
855 (cons original-major-mode-cell default-situation)))
857 (mime-display-entity (car children) nil default-situation)
858 (setq children (cdr children))
861 (defcustom mime-view-type-subtype-score-alist
862 '(((text . enriched) . 3)
863 ((text . richtext) . 2)
866 "Alist MEDIA-TYPE vs corresponding score.
867 MEDIA-TYPE must be (TYPE . SUBTYPE), TYPE or t. t means default."
869 :type '(repeat (cons (choice :tag "Media-Type"
870 (cons :tag "Type/Subtype"
871 (symbol :tag "Primary-type")
872 (symbol :tag "Subtype"))
874 (const :tag "Default" t))
877 (defun mime-display-multipart/alternative (entity situation)
878 (let* ((children (mime-entity-children entity))
879 (original-major-mode-cell (assq 'major-mode situation))
881 (cdr (assq 'childrens-situation situation)))
886 (if original-major-mode-cell
887 (setq default-situation
888 (cons original-major-mode-cell default-situation)))
893 (mime-find-entity-preview-situation
894 child default-situation)))
895 (if (cdr (assq 'body-presentation-method situation))
900 (cdr (assq 'type situation))
901 (cdr (assq 'subtype situation)))
902 mime-view-type-subtype-score-alist)
904 (cdr (assq 'type situation))
905 mime-view-type-subtype-score-alist)
908 mime-view-type-subtype-score-alist)
910 (if (> score max-score)
920 (let ((child (car children))
921 (situation (car situations)))
922 (mime-display-entity child (if (= i p)
924 (put-alist 'body 'invisible
925 (copy-alist situation)))))
926 (setq children (cdr children)
927 situations (cdr situations)
930 (defun mime-display-multipart/related (entity situation)
931 (let* ((param-start (mime-parse-msg-id
932 (std11-lexical-analyze
934 (mime-content-type-parameters
935 (mime-entity-content-type entity)))))))
936 (start (or (and param-start (mime-find-entity-from-content-id
939 (car (mime-entity-children entity))))
940 (original-major-mode-cell (assq 'major-mode situation))
941 (default-situation (cdr (assq 'childrens-situation situation))))
942 (if original-major-mode-cell
943 (setq default-situation
944 (cons original-major-mode-cell default-situation)))
945 (mime-display-entity start nil default-situation)))
947 ;;; @ acting-condition
950 (defvar mime-acting-condition nil
951 "Condition-tree about how to process entity.")
953 (defun mime-view-read-mailcap-files (&optional files)
955 (setq files mime-view-mailcap-files))
958 (setq file (car files))
959 (if (file-readable-p file)
960 (setq entries (append entries (mime-parse-mailcap-file file))))
961 (setq files (cdr files)))
963 (let ((entry (car entries))
966 (let* ((field (car entry))
967 (field-type (car field)))
968 (cond ((eq field-type 'view) (setq view field))
969 ((eq field-type 'print) (setq print field))
970 ((memq field-type '(compose composetyped edit)))
971 (t (setq shared (cons field shared))))
973 (setq entry (cdr entry)))
974 (setq shared (nreverse shared))
975 (ctree-set-calist-with-default
976 'mime-acting-condition
977 (append shared (list '(mode . "play")(cons 'method (cdr view)))))
979 (ctree-set-calist-with-default
980 'mime-acting-condition
982 (list '(mode . "print")(cons 'method (cdr view)))))))
983 (setq entries (cdr entries)))))
985 (mime-view-read-mailcap-files)
987 (ctree-set-calist-strictly
988 'mime-acting-condition
989 '((type . application)(subtype . octet-stream)
991 (method . mime-detect-content)
994 (ctree-set-calist-with-default
995 'mime-acting-condition
997 (method . mime-save-content)))
999 (ctree-set-calist-strictly
1000 'mime-acting-condition
1001 '((type . text)(subtype . x-rot13-47)(mode . "play")
1002 (method . mime-view-caesar)
1004 (ctree-set-calist-strictly
1005 'mime-acting-condition
1006 '((type . text)(subtype . x-rot13-47-48)(mode . "play")
1007 (method . mime-view-caesar)
1010 (ctree-set-calist-strictly
1011 'mime-acting-condition
1012 '((type . message)(subtype . rfc822)(mode . "play")
1013 (method . mime-view-message/rfc822)
1015 (ctree-set-calist-strictly
1016 'mime-acting-condition
1017 '((type . message)(subtype . partial)(mode . "play")
1018 (method . mime-store-message/partial-piece)
1021 (ctree-set-calist-strictly
1022 'mime-acting-condition
1023 '((type . message)(subtype . external-body)
1024 ("access-type" . "anon-ftp")
1025 (method . mime-view-message/external-anon-ftp)
1028 (ctree-set-calist-strictly
1029 'mime-acting-condition
1030 '((type . message)(subtype . external-body)
1031 ("access-type" . "url")
1032 (method . mime-view-message/external-url)
1035 (ctree-set-calist-strictly
1036 'mime-acting-condition
1037 '((type . application)(subtype . octet-stream)
1038 (method . mime-save-content)
1042 ;;; @ quitting method
1045 (defvar mime-preview-quitting-method-alist
1046 '((mime-show-message-mode
1047 . mime-preview-quitting-method-for-mime-show-message-mode))
1048 "Alist of major-mode vs. quitting-method of mime-view.")
1050 (defvar mime-preview-over-to-previous-method-alist nil
1051 "Alist of major-mode vs. over-to-previous-method of mime-view.")
1053 (defvar mime-preview-over-to-next-method-alist nil
1054 "Alist of major-mode vs. over-to-next-method of mime-view.")
1057 ;;; @ following method
1060 (defvar mime-preview-following-method-alist nil
1061 "Alist of major-mode vs. following-method of mime-view.")
1063 (defvar mime-view-following-required-fields-list
1070 (defun mime-display-entity (entity &optional situation
1071 default-situation preview-buffer)
1073 (setq preview-buffer (current-buffer)))
1074 (let* (e nb ne nhb nbb)
1075 (in-calist-package 'mime-view)
1078 (mime-find-entity-preview-situation entity default-situation)))
1079 (let ((button-is-invisible
1080 (eq (cdr (or (assq '*entity-button situation)
1081 (assq 'entity-button situation)))
1084 (eq (cdr (or (assq '*header situation)
1085 (assq 'header situation)))
1088 (eq (cdr (or (assq '*body situation)
1089 (assq 'body situation)))
1091 (children (mime-entity-children entity)))
1092 (set-buffer preview-buffer)
1094 (narrow-to-region nb nb)
1095 (or button-is-invisible
1096 ;; (if (mime-view-entity-button-visible-p entity)
1097 (mime-view-insert-entity-button entity)
1100 (if header-is-visible
1101 (let ((header-presentation-method
1102 (or (cdr (assq 'header-presentation-method situation))
1103 (cdr (assq (cdr (assq 'major-mode situation))
1104 mime-header-presentation-method-alist)))))
1106 (if header-presentation-method
1107 (funcall header-presentation-method entity situation)
1108 (mime-insert-header entity
1109 mime-view-ignored-field-list
1110 mime-view-visible-field-list))
1111 (run-hooks 'mime-display-header-hook)
1112 (put-text-property nhb (point-max) 'mime-view-entity-header entity)
1113 (goto-char (point-max))
1118 (let ((body-presentation-method
1119 (cdr (assq 'body-presentation-method situation))))
1120 (if (functionp body-presentation-method)
1121 (funcall body-presentation-method entity situation)
1122 (mime-display-text/plain entity situation)))
1123 (when button-is-invisible
1124 (goto-char (point-max))
1125 (mime-view-insert-entity-button entity)
1127 (unless header-is-visible
1128 (goto-char (point-max))
1131 (setq ne (point-max))
1133 (put-text-property nb ne 'mime-view-entity entity)
1134 (put-text-property nb ne 'mime-view-situation situation)
1135 (put-text-property nbb ne 'mime-view-entity-body entity)
1137 (if (and children body-is-visible)
1138 (let ((body-presentation-method
1139 (cdr (assq 'body-presentation-method situation))))
1140 (if (functionp body-presentation-method)
1141 (funcall body-presentation-method entity situation)
1142 (mime-display-multipart/mixed entity situation))))
1146 ;;; @ MIME viewer mode
1149 (defconst mime-view-menu-title "MIME-View")
1150 (defconst mime-view-menu-list
1151 '((up "Move to upper entity" mime-preview-move-to-upper)
1152 (previous "Move to previous entity" mime-preview-move-to-previous)
1153 (next "Move to next entity" mime-preview-move-to-next)
1154 (scroll-down "Scroll-down" mime-preview-scroll-down-entity)
1155 (scroll-up "Scroll-up" mime-preview-scroll-up-entity)
1156 (play "Play current entity" mime-preview-play-current-entity)
1157 (extract "Extract current entity" mime-preview-extract-current-entity)
1158 (print "Print current entity" mime-preview-print-current-entity)
1160 "Menu for MIME Viewer")
1162 (cond ((featurep 'xemacs)
1163 (defvar mime-view-xemacs-popup-menu
1164 (cons mime-view-menu-title
1167 (vector (nth 1 item)(nth 2 item) t)
1169 mime-view-menu-list)))
1170 (defun mime-view-xemacs-popup-menu (event)
1171 "Popup the menu in the MIME Viewer buffer"
1173 (select-window (event-window event))
1174 (set-buffer (event-buffer event))
1175 (popup-menu 'mime-view-xemacs-popup-menu))
1176 (defvar mouse-button-2 'button2)
1177 (defvar mouse-button-3 'button3)
1180 (defvar mime-view-popup-menu
1181 (let ((menu (make-sparse-keymap mime-view-menu-title)))
1185 (list (intern (nth 1 item)) 'menu-item
1186 (nth 1 item)(nth 2 item))
1188 mime-view-menu-list))))
1189 (defun mime-view-popup-menu (event)
1190 "Popup the menu in the MIME Viewer buffer"
1192 (let ((menu mime-view-popup-menu) events func)
1193 (setq events (x-popup-menu t menu))
1195 (setq func (lookup-key menu (apply #'vector events)))
1198 (defvar mouse-button-2 [mouse-2])
1199 (defvar mouse-button-3 [mouse-3])
1202 (defun mime-view-define-keymap (&optional default)
1203 (let ((mime-view-mode-map (if (keymapp default)
1204 (copy-keymap default)
1205 (make-sparse-keymap))))
1206 (define-key mime-view-mode-map
1207 "u" (function mime-preview-move-to-upper))
1208 (define-key mime-view-mode-map
1209 "p" (function mime-preview-move-to-previous))
1210 (define-key mime-view-mode-map
1211 "n" (function mime-preview-move-to-next))
1212 (define-key mime-view-mode-map
1213 "\e\t" (function mime-preview-move-to-previous))
1214 (define-key mime-view-mode-map
1215 "\t" (function mime-preview-move-to-next))
1216 (define-key mime-view-mode-map
1217 " " (function mime-preview-scroll-up-entity))
1218 (define-key mime-view-mode-map
1219 "\M- " (function mime-preview-scroll-down-entity))
1220 (define-key mime-view-mode-map
1221 "\177" (function mime-preview-scroll-down-entity))
1222 (define-key mime-view-mode-map
1223 "\C-m" (function mime-preview-next-line-entity))
1224 (define-key mime-view-mode-map
1225 "\C-\M-m" (function mime-preview-previous-line-entity))
1226 (define-key mime-view-mode-map
1227 "v" (function mime-preview-play-current-entity))
1228 (define-key mime-view-mode-map
1229 "e" (function mime-preview-extract-current-entity))
1230 (define-key mime-view-mode-map
1231 "\C-c\C-p" (function mime-preview-print-current-entity))
1233 (define-key mime-view-mode-map
1234 "\C-c\C-t\C-f" (function mime-preview-toggle-header))
1235 (define-key mime-view-mode-map
1236 "\C-c\C-th" (function mime-preview-toggle-header))
1237 (define-key mime-view-mode-map
1238 "\C-c\C-t\C-c" (function mime-preview-toggle-content))
1240 (define-key mime-view-mode-map
1241 "\C-c\C-v\C-f" (function mime-preview-show-header))
1242 (define-key mime-view-mode-map
1243 "\C-c\C-vh" (function mime-preview-show-header))
1244 (define-key mime-view-mode-map
1245 "\C-c\C-v\C-c" (function mime-preview-show-content))
1247 (define-key mime-view-mode-map
1248 "\C-c\C-d\C-f" (function mime-preview-hide-header))
1249 (define-key mime-view-mode-map
1250 "\C-c\C-dh" (function mime-preview-hide-header))
1251 (define-key mime-view-mode-map
1252 "\C-c\C-d\C-c" (function mime-preview-hide-content))
1254 (define-key mime-view-mode-map
1255 "a" (function mime-preview-follow-current-entity))
1256 (define-key mime-view-mode-map
1257 "q" (function mime-preview-quit))
1258 (define-key mime-view-mode-map
1259 "\C-c\C-x" (function mime-preview-kill-buffer))
1260 ;; (define-key mime-view-mode-map
1261 ;; "<" (function beginning-of-buffer))
1262 ;; (define-key mime-view-mode-map
1263 ;; ">" (function end-of-buffer))
1264 (define-key mime-view-mode-map
1265 "?" (function describe-mode))
1266 (define-key mime-view-mode-map
1267 [tab] (function mime-preview-move-to-next))
1268 (define-key mime-view-mode-map
1269 [delete] (function mime-preview-scroll-down-entity))
1270 (define-key mime-view-mode-map
1271 [backspace] (function mime-preview-scroll-down-entity))
1272 (if (functionp default)
1273 (cond ((featurep 'xemacs)
1274 (set-keymap-default-binding mime-view-mode-map default)
1277 (setq mime-view-mode-map
1278 (append mime-view-mode-map (list (cons t default))))
1281 (define-key mime-view-mode-map
1282 mouse-button-2 (function mime-button-dispatcher))
1284 (cond ((featurep 'xemacs)
1285 (define-key mime-view-mode-map
1286 mouse-button-3 (function mime-view-xemacs-popup-menu))
1288 ((>= emacs-major-version 19)
1289 (define-key mime-view-mode-map
1290 mouse-button-3 (function mime-view-popup-menu))
1291 (define-key mime-view-mode-map [menu-bar mime-view]
1292 (cons mime-view-menu-title
1293 (make-sparse-keymap mime-view-menu-title)))
1296 (define-key mime-view-mode-map
1297 (vector 'menu-bar 'mime-view (car item))
1298 (cons (nth 1 item)(nth 2 item)))
1300 (reverse mime-view-menu-list))
1302 ;; (run-hooks 'mime-view-define-keymap-hook)
1303 mime-view-mode-map))
1305 (defvar mime-view-mode-default-map (mime-view-define-keymap))
1308 (defsubst mime-maybe-hide-echo-buffer ()
1309 "Clear mime-echo buffer and delete window for it."
1310 (let ((buf (get-buffer mime-echo-buffer-name)))
1315 (let ((win (get-buffer-window buf)))
1322 (defvar mime-view-redisplay nil)
1325 (defun mime-display-message (message &optional preview-buffer
1326 mother default-keymap-or-function
1327 original-major-mode keymap)
1328 "View MESSAGE in MIME-View mode.
1330 Optional argument PREVIEW-BUFFER specifies the buffer of the
1331 presentation. It must be either nil or a name of preview buffer.
1333 Optional argument MOTHER specifies mother-buffer of the preview-buffer.
1335 Optional argument DEFAULT-KEYMAP-OR-FUNCTION is nil, keymap or
1336 function. If it is a keymap, keymap of MIME-View mode will be added
1337 to it. If it is a function, it will be bound as default binding of
1338 keymap of MIME-View mode.
1340 Optional argument ORIGINAL-MAJOR-MODE is major-mode of representation
1341 buffer of MESSAGE. If it is nil, current `major-mode' is used.
1343 Optional argument KEYMAP is keymap of MIME-View mode. If it is
1344 non-nil, DEFAULT-KEYMAP-OR-FUNCTION is ignored. If it is nil,
1345 `mime-view-mode-default-map' is used."
1346 (mime-maybe-hide-echo-buffer)
1347 (let ((win-conf (current-window-configuration)))
1349 (setq preview-buffer
1350 (concat "*Preview-" (mime-entity-name message) "*")))
1351 (or original-major-mode
1352 (setq original-major-mode major-mode))
1353 (let ((inhibit-read-only t))
1354 (set-buffer (get-buffer-create preview-buffer))
1358 (setq mime-mother-buffer mother))
1359 (setq mime-preview-original-window-configuration win-conf)
1360 (setq major-mode 'mime-view-mode)
1361 (setq mode-name "MIME-View")
1362 (mime-display-entity message nil
1363 `((entity-button . invisible)
1365 (major-mode . ,original-major-mode))
1369 (if default-keymap-or-function
1370 (mime-view-define-keymap default-keymap-or-function)
1371 mime-view-mode-default-map)))
1373 (next-single-property-change (point-min) 'mime-view-entity)))
1376 (goto-char (point-min))
1377 (search-forward "\n\n" nil t)))
1378 (run-hooks 'mime-view-mode-hook)
1379 (set-buffer-modified-p nil)
1380 (setq buffer-read-only t)
1384 (defun mime-view-buffer (&optional raw-buffer preview-buffer mother
1385 default-keymap-or-function
1386 representation-type)
1387 "View RAW-BUFFER in MIME-View mode.
1388 Optional argument PREVIEW-BUFFER is either nil or a name of preview
1390 Optional argument DEFAULT-KEYMAP-OR-FUNCTION is nil, keymap or
1391 function. If it is a keymap, keymap of MIME-View mode will be added
1392 to it. If it is a function, it will be bound as default binding of
1393 keymap of MIME-View mode.
1394 Optional argument REPRESENTATION-TYPE is representation-type of
1395 message. It must be nil, `binary' or `cooked'. If it is nil,
1396 `cooked' is used as default."
1399 (setq raw-buffer (current-buffer)))
1400 (or representation-type
1401 (setq representation-type
1403 (set-buffer raw-buffer)
1404 (cdr (or (assq major-mode mime-raw-representation-type-alist)
1405 (assq t mime-raw-representation-type-alist)))
1407 (if (eq representation-type 'binary)
1408 (setq representation-type 'buffer)
1410 (setq preview-buffer (mime-display-message
1411 (mime-open-entity representation-type raw-buffer)
1412 preview-buffer mother default-keymap-or-function))
1413 (or (get-buffer-window preview-buffer)
1414 (let ((r-win (get-buffer-window raw-buffer)))
1416 (set-window-buffer r-win preview-buffer)
1417 (let ((m-win (and mother (get-buffer-window mother))))
1419 (set-window-buffer m-win preview-buffer)
1420 (switch-to-buffer preview-buffer)
1423 (defun mime-view-mode (&optional mother ctl encoding
1424 raw-buffer preview-buffer
1425 default-keymap-or-function)
1426 "Major mode for viewing MIME message.
1428 Here is a list of the standard keys for mime-view-mode.
1433 u Move to upper content
1434 p or M-TAB Move to previous content
1435 n or TAB Move to next content
1436 SPC Scroll up or move to next content
1437 M-SPC or DEL Scroll down or move to previous content
1438 RET Move to next line
1439 M-RET Move to previous line
1440 v Decode current content as `play mode'
1441 e Decode current content as `extract mode'
1442 C-c C-p Decode current content as `print mode'
1443 a Followup to current content.
1445 button-2 Move to point under the mouse cursor
1446 and decode current content as `play mode'
1449 (unless mime-view-redisplay
1451 (if raw-buffer (set-buffer raw-buffer))
1454 (or (assq major-mode mime-raw-representation-type-alist)
1455 (assq t mime-raw-representation-type-alist)))))
1456 (if (eq type 'binary)
1459 (setq mime-message-structure (mime-open-entity type raw-buffer))
1460 (or (mime-entity-content-type mime-message-structure)
1461 (mime-entity-set-content-type mime-message-structure ctl))
1463 (or (mime-entity-encoding mime-message-structure)
1464 (mime-entity-set-encoding mime-message-structure encoding))
1466 (mime-display-message mime-message-structure preview-buffer
1467 mother default-keymap-or-function)
1474 (defun mime-preview-find-boundary-info (&optional with-children)
1475 "Return boundary information of current part.
1476 If WITH-CHILDREN, refer boundary surrounding current part and its branches."
1480 (while (null (setq entity
1481 (get-text-property (point) 'mime-view-entity)))
1483 (setq p-beg (previous-single-property-change (point) 'mime-view-entity))
1484 (setq entity-node-id (mime-entity-node-id entity))
1485 (setq len (length entity-node-id))
1488 (if (eq (next-single-property-change (point-min)
1494 ((eq (next-single-property-change p-beg 'mime-view-entity)
1496 (setq p-beg (point))
1498 (setq p-end (next-single-property-change p-beg 'mime-view-entity))
1500 (setq p-end (point-max))
1502 ((null entity-node-id)
1503 (setq p-end (point-max))
1510 (next-single-property-change
1511 (point) 'mime-view-entity))
1513 (let ((rc (mime-entity-node-id
1514 (get-text-property (point)
1515 'mime-view-entity))))
1516 (or (and (>= (setq i (- (length rc) len)) 0)
1517 (equal entity-node-id (nthcdr i rc)))
1519 (setq p-end (or (next-single-property-change
1520 (point) 'mime-view-entity)
1522 (setq p-end (point-max))))
1524 (vector p-beg p-end entity)))
1530 (autoload 'mime-preview-play-current-entity "mime-play"
1531 "Play current entity." t)
1533 (defun mime-preview-extract-current-entity (&optional ignore-examples)
1534 "Extract current entity into file (maybe).
1535 It decodes current entity to call internal or external method as
1536 \"extract\" mode. The method is selected from variable
1537 `mime-acting-condition'."
1539 (mime-preview-play-current-entity ignore-examples "extract")
1542 (defun mime-preview-print-current-entity (&optional ignore-examples)
1543 "Print current entity (maybe).
1544 It decodes current entity to call internal or external method as
1545 \"print\" mode. The method is selected from variable
1546 `mime-acting-condition'."
1548 (mime-preview-play-current-entity ignore-examples "print")
1555 (defun mime-preview-follow-current-entity ()
1556 "Write follow message to current entity.
1557 It calls following-method selected from variable
1558 `mime-preview-following-method-alist'."
1560 (let ((entity (mime-preview-find-boundary-info t))
1563 (setq p-beg (aref entity 0)
1564 p-end (aref entity 1)
1565 entity (aref entity 2))
1566 (if (get-text-property p-beg 'mime-view-entity-body)
1569 (next-single-property-change
1570 p-beg 'mime-view-entity-body nil
1571 (or (next-single-property-change p-beg 'mime-view-entity)
1573 (let* ((mode (mime-preview-original-major-mode 'recursive))
1574 (entity-node-id (mime-entity-node-id entity))
1576 (format "%s-%s" (buffer-name) (reverse entity-node-id)))
1578 (the-buf (current-buffer))
1581 (set-buffer (setq new-buf (get-buffer-create new-name)))
1584 (insert-buffer-substring the-buf pb-beg p-end)
1585 (goto-char (point-min))
1586 (let ((current-entity
1587 (if (and (eq (mime-entity-media-type entity) 'message)
1588 (eq (mime-entity-media-subtype entity) 'rfc822))
1589 (car (mime-entity-children entity))
1591 (while (and current-entity
1592 (if (and (eq (mime-entity-media-type
1593 current-entity) 'message)
1594 (eq (mime-entity-media-subtype
1595 current-entity) 'rfc822))
1597 (mime-insert-header current-entity fields)
1599 (setq fields (std11-collect-field-names)
1600 current-entity (mime-entity-parent current-entity))
1602 (let ((rest mime-view-following-required-fields-list)
1605 (setq field-name (car rest))
1606 (or (std11-field-body field-name)
1609 (set-buffer the-buf)
1610 (let ((entity (when mime-mother-buffer
1611 (set-buffer mime-mother-buffer)
1612 (get-text-property (point)
1613 'mime-view-entity))))
1615 (null (setq ret (mime-entity-fetch-field
1616 entity field-name))))
1617 (setq entity (mime-entity-parent entity)))))
1619 (insert (concat field-name ": " ret "\n"))
1621 (setq rest (cdr rest))
1624 (let ((f (cdr (assq mode mime-preview-following-method-alist))))
1628 "Sorry, following method for %s is not implemented yet."
1637 (defun mime-preview-move-to-upper ()
1638 "Move to upper entity.
1639 If there is no upper entity, call function `mime-preview-quit'."
1642 (while (null (setq cinfo
1643 (get-text-property (point) 'mime-view-entity)))
1646 (let ((r (mime-entity-parent cinfo))
1649 (while (setq point (previous-single-property-change
1650 (point) 'mime-view-entity))
1652 (when (eq r (get-text-property (point) 'mime-view-entity))
1653 (if (or (eq mime-preview-move-scroll t)
1654 (and mime-preview-move-scroll
1657 (move-to-window-line -1)
1658 (forward-line (* -1 next-screen-context-lines))
1661 (recenter next-screen-context-lines))
1668 (defun mime-preview-move-to-previous ()
1669 "Move to previous entity.
1670 If there is no previous entity, it calls function registered in
1671 variable `mime-preview-over-to-previous-method-alist'."
1673 (while (and (not (bobp))
1674 (null (get-text-property (point) 'mime-view-entity)))
1677 (let ((point (previous-single-property-change (point) 'mime-view-entity)))
1679 (>= point (point-min)))
1680 (if (get-text-property (1- point) 'mime-view-entity)
1681 (progn (goto-char point)
1683 (or (eq mime-preview-move-scroll t)
1684 (and mime-preview-move-scroll
1687 (move-to-window-line 0)
1688 (forward-line next-screen-context-lines)
1691 (recenter (* -1 next-screen-context-lines))))
1692 (goto-char (1- point))
1693 (mime-preview-move-to-previous)
1695 (let ((f (assq (mime-preview-original-major-mode)
1696 mime-preview-over-to-previous-method-alist)))
1702 (defun mime-preview-move-to-next ()
1703 "Move to next entity.
1704 If there is no previous entity, it calls function registered in
1705 variable `mime-preview-over-to-next-method-alist'."
1707 (while (and (not (eobp))
1708 (null (get-text-property (point) 'mime-view-entity)))
1711 (let ((point (next-single-property-change (point) 'mime-view-entity)))
1713 (<= point (point-max)))
1716 (if (null (get-text-property point 'mime-view-entity))
1717 (mime-preview-move-to-next)
1719 (or (eq mime-preview-move-scroll t)
1720 (and mime-preview-move-scroll
1723 (move-to-window-line -1)
1725 (* -1 next-screen-context-lines))
1728 (recenter next-screen-context-lines))
1730 (let ((f (assq (mime-preview-original-major-mode)
1731 mime-preview-over-to-next-method-alist)))
1737 (defun mime-preview-scroll-up-entity (&optional h)
1738 "Scroll up current entity.
1739 If reached to (point-max), it calls function registered in variable
1740 `mime-preview-over-to-next-method-alist'."
1743 (let ((f (assq (mime-preview-original-major-mode)
1744 mime-preview-over-to-next-method-alist)))
1749 (or (next-single-property-change (point) 'mime-view-entity)
1751 (bottom (window-end (selected-window))))
1754 (progn (goto-char point)
1755 (recenter next-screen-context-lines))
1759 (goto-char (point-max)))))
1762 (defun mime-preview-scroll-down-entity (&optional h)
1763 "Scroll down current entity.
1764 If reached to (point-min), it calls function registered in variable
1765 `mime-preview-over-to-previous-method-alist'."
1768 (let ((f (assq (mime-preview-original-major-mode)
1769 mime-preview-over-to-previous-method-alist)))
1774 (or (previous-single-property-change (point) 'mime-view-entity)
1776 (top (window-start (selected-window))))
1779 (progn (goto-char point)
1780 (recenter (* -1 next-screen-context-lines)))
1783 (beginning-of-buffer
1784 (goto-char (point-min)))))
1787 (defun mime-preview-next-line-entity (&optional lines)
1788 "Scroll up one line (or prefix LINES lines).
1789 If LINES is negative, scroll down LINES lines."
1791 (mime-preview-scroll-up-entity (or lines 1))
1794 (defun mime-preview-previous-line-entity (&optional lines)
1795 "Scrroll down one line (or prefix LINES lines).
1796 If LINES is negative, scroll up LINES lines."
1798 (mime-preview-scroll-down-entity (or lines 1))
1805 (defun mime-preview-toggle-display (type &optional display)
1806 (let ((situation (mime-preview-find-boundary-info t))
1807 (sym (intern (concat "*" (symbol-name type))))
1809 (setq p-beg (aref situation 0)
1810 p-end (aref situation 1)
1811 entity (aref situation 2)
1812 situation (get-text-property p-beg 'mime-view-situation))
1813 (cond ((eq display 'invisible)
1818 (eq (cdr (or (assq sym situation)
1819 (assq type situation)))
1821 (setq situation (put-alist sym (if display
1826 (let ((inhibit-read-only t))
1827 (delete-region p-beg p-end)
1828 (mime-display-entity entity situation)))
1829 (let ((ret (assoc situation mime-preview-situation-example-list)))
1831 (setcdr ret (1+ (cdr ret)))
1832 (add-to-list 'mime-preview-situation-example-list
1833 (cons situation 0))))))
1835 (defun mime-preview-toggle-header (&optional force-visible)
1837 (mime-preview-toggle-display 'header force-visible))
1839 (defun mime-preview-toggle-content (&optional force-visible)
1841 (mime-preview-toggle-display 'body force-visible))
1843 (defun mime-preview-show-header ()
1845 (mime-preview-toggle-display 'header 'visible))
1847 (defun mime-preview-show-content ()
1849 (mime-preview-toggle-display 'body 'visible))
1851 (defun mime-preview-hide-header ()
1853 (mime-preview-toggle-display 'header 'invisible))
1855 (defun mime-preview-hide-content ()
1857 (mime-preview-toggle-display 'body 'invisible))
1863 (defun mime-preview-quit ()
1864 "Quit from MIME-preview buffer.
1865 It calls function registered in variable
1866 `mime-preview-quitting-method-alist'."
1868 (let ((r (assq (mime-preview-original-major-mode)
1869 mime-preview-quitting-method-alist)))
1874 (defun mime-preview-kill-buffer ()
1876 (kill-buffer (current-buffer))
1883 (provide 'mime-view)
1886 (setq mime-situation-examples-file nil)
1887 ;; to avoid to read situation-examples-file at compile time.
1890 (mime-view-read-situation-examples-file)
1892 ;;; mime-view.el ends here