1 ;;; mime-view.el --- interactive MIME viewer for GNU Emacs
3 ;; Copyright (C) 1995,96,97,98,99,2000 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <tomo@m17n.org>
7 ;; Renamed: 1994/08/31 from tm-body.el
8 ;; Renamed: 1997/02/19 from tm-view.el
9 ;; Keywords: MIME, multimedia, mail, news
11 ;; This file is part of SEMI (Sample of Elastic MIME Interfaces).
13 ;; This program is free software; you can redistribute it and/or
14 ;; modify it under the terms of the GNU General Public License as
15 ;; published by the Free Software Foundation; either version 2, or (at
16 ;; your option) any later version.
18 ;; This program is distributed in the hope that it will be useful, but
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 ;; General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 ;; Boston, MA 02111-1307, USA.
36 (eval-when-compile (require 'static))
42 (defconst mime-view-version
43 (concat (mime-product-name mime-user-interface-product) " MIME-View "
44 (mapconcat #'number-to-string
45 (mime-product-version mime-user-interface-product) ".")
46 " (" (mime-product-code-name mime-user-interface-product) ")"))
52 (defgroup mime-view nil
56 (defcustom mime-situation-examples-file "~/.mime-example"
57 "*File name of situation-examples demonstrated by user."
61 (defcustom mime-preview-move-scroll nil
62 "*Decides whether to scroll when moving to next entity.
63 When t, scroll the buffer. Non-nil but not t means scroll when
64 the next entity is within next-screen-context-lines from top or
65 buttom. Nil means don't scroll at all."
67 :type '(choice (const :tag "Off" nil)
69 (sexp :tag "Situation" 1)))
71 (defcustom mime-view-mailcap-files
72 (let ((files '("/etc/mailcap" "/usr/etc/mailcap" "~/.mailcap")))
73 (or (member mime-mailcap-file files)
74 (setq files (cons mime-mailcap-file files)))
76 "List of mailcap files."
81 ;;; @ in raw-buffer (representation space)
84 (defvar mime-preview-buffer nil
85 "MIME-preview buffer corresponding with the (raw) buffer.")
86 (make-variable-buffer-local 'mime-preview-buffer)
89 (defvar mime-raw-representation-type-alist
90 '((mime-show-message-mode . binary)
91 (mime-temp-message-mode . binary)
93 "Alist of major-mode vs. representation-type of mime-raw-buffer.
94 Each element looks like (SYMBOL . REPRESENTATION-TYPE). SYMBOL is
95 major-mode or t. t means default. REPRESENTATION-TYPE must be
96 `binary' or `cooked'.")
99 ;;; @ in preview-buffer (presentation space)
102 (defvar mime-mother-buffer nil
103 "Mother buffer corresponding with the (MIME-preview) buffer.
104 If current MIME-preview buffer is generated by other buffer, such as
105 message/partial, it is called `mother-buffer'.")
106 (make-variable-buffer-local 'mime-mother-buffer)
108 ;; (defvar mime-raw-buffer nil
109 ;; "Raw buffer corresponding with the (MIME-preview) buffer.")
110 ;; (make-variable-buffer-local 'mime-raw-buffer)
112 (defvar mime-preview-original-window-configuration nil
113 "Window-configuration before mime-view-mode is called.")
114 (make-variable-buffer-local 'mime-preview-original-window-configuration)
116 (defun mime-preview-original-major-mode (&optional recursive point)
117 "Return major-mode of original buffer.
118 If optional argument RECURSIVE is non-nil and current buffer has
119 mime-mother-buffer, it returns original major-mode of the
121 (if (and recursive mime-mother-buffer)
123 (set-buffer mime-mother-buffer)
124 (mime-preview-original-major-mode recursive))
125 (cdr (assq 'major-mode
126 (get-text-property (or point
127 (if (> (point) (buffer-size))
128 (max (1- (point-max)) (point-min))
130 'mime-view-situation)))))
133 ;;; @ entity information
136 (defun mime-entity-situation (entity &optional situation)
137 "Return situation of ENTITY."
138 (let (rest param name)
140 (unless (assq 'type situation)
141 (setq rest (or (mime-entity-content-type entity)
142 (make-mime-content-type 'text 'plain))
143 situation (cons (car rest) situation)
145 (unless (assq 'subtype situation)
147 (setq rest (or (cdr (mime-entity-content-type entity))
148 '((subtype . plain)))))
149 (setq situation (cons (car rest) situation)
152 (setq param (car rest))
153 (or (assoc (car param) situation)
154 (setq situation (cons param situation)))
155 (setq rest (cdr rest)))
157 ;; Content-Disposition
159 (unless (assq 'disposition-type situation)
160 (setq rest (mime-entity-content-disposition entity))
162 (setq situation (cons (cons 'disposition-type
163 (mime-content-disposition-type rest))
165 rest (mime-content-disposition-parameters rest))))
167 (setq param (car rest)
169 (if (cond ((string= name "filename")
170 (if (assq 'filename situation)
172 (setq name 'filename)))
173 ((string= name "creation-date")
174 (if (assq 'creation-date situation)
176 (setq name 'creation-date)))
177 ((string= name "modification-date")
178 (if (assq 'modification-date situation)
180 (setq name 'modification-date)))
181 ((string= name "read-date")
182 (if (assq 'read-date situation)
184 (setq name 'read-date)))
185 ((string= name "size")
186 (if (assq 'size situation)
189 (t (setq name (cons 'disposition name))
190 (if (assoc name situation)
194 (cons (cons name (cdr param))
196 (setq rest (cdr rest)))
198 ;; Content-Transfer-Encoding
199 (or (assq 'encoding situation)
201 (cons (cons 'encoding (or (mime-entity-encoding entity)
207 (defsubst mime-delq-null-situation (situations field
208 &rest ignored-values)
211 (let* ((situation (car situations))
212 (cell (assq field situation)))
214 (or (memq (cdr cell) ignored-values)
215 (setq dest (cons situation dest)))))
216 (setq situations (cdr situations)))
219 (defun mime-compare-situation-with-example (situation example)
220 (let ((example (copy-alist example))
223 (let* ((cell (car situation))
225 (ecell (assoc key example)))
227 (if (equal cell ecell)
228 (setq match (1+ match))
229 (setq example (delq ecell example)))))
230 (setq situation (cdr situation)))
231 (cons match example)))
233 (defun mime-sort-situation (situation)
243 (disposition-type . 6)))
246 (let ((ret (assq a-t order)))
248 (setq a-order (cdr ret))
252 (let ((ret (assq b-t order)))
254 (setq b-order (cdr ret))
257 (if (= a-order b-order)
258 (string< (format "%s" a-t)(format "%s" b-t))
259 (< a-order b-order))))))
261 (defun mime-unify-situations (entity-situation
262 condition situation-examples
263 &optional required-name ignored-value
266 (in-calist-package 'mime-view)
268 (ctree-find-calist condition entity-situation
271 (setq ret (mime-delq-null-situation ret required-name
273 (or (assq 'ignore-examples entity-situation)
281 (let ((situation (car rest))
282 (examples situation-examples))
285 (mime-compare-situation-with-example
286 situation (caar examples)))
287 (ret-score (car ret)))
288 (cond ((> ret-score max-score)
289 (setq max-score ret-score
290 max-escore (cdar examples)
291 max-examples (list (cdr ret))
292 max-situations (list situation)))
293 ((= ret-score max-score)
294 (cond ((> (cdar examples) max-escore)
295 (setq max-escore (cdar examples)
296 max-examples (list (cdr ret))
297 max-situations (list situation)))
298 ((= (cdar examples) max-escore)
300 (cons (cdr ret) max-examples))
301 (or (member situation max-situations)
303 (cons situation max-situations))))))))
304 (setq examples (cdr examples))))
305 (setq rest (cdr rest)))
307 (setq ret max-situations)
309 (let* ((example (car max-examples))
311 (assoc example situation-examples)))
313 (setcdr cell (1+ (cdr cell)))
314 (setq situation-examples
315 (cons (cons example 0)
316 situation-examples))))
317 (setq max-examples (cdr max-examples)))))))
318 (cons ret situation-examples)
319 ;; ret: list of situations
320 ;; situation-examples: new examples (notoce that contents of
321 ;; argument `situation-examples' has bees modified)
324 (defun mime-view-entity-title (entity)
325 (or (mime-entity-read-field entity 'Content-Description)
326 (mime-entity-read-field entity 'Subject)
327 (mime-entity-filename entity)
330 (defvar mime-preview-situation-example-list nil)
331 (defvar mime-preview-situation-example-list-max-size 16)
332 ;; (defvar mime-preview-situation-example-condition nil)
334 (defun mime-find-entity-preview-situation (entity
335 &optional default-situation)
337 (mime-unify-situations
338 (append (mime-entity-situation entity)
340 mime-preview-condition
341 mime-preview-situation-example-list)))
342 (setq mime-preview-situation-example-list
348 (defvar mime-acting-situation-example-list nil)
349 (defvar mime-acting-situation-example-list-max-size 16)
350 (defvar mime-situation-examples-file-coding-system nil)
352 (defun mime-view-read-situation-examples-file (&optional file)
354 (setq file mime-situation-examples-file))
356 (file-readable-p file))
358 (insert-file-contents file)
359 (setq mime-situation-examples-file-coding-system
361 ((boundp 'buffer-file-coding-system)
362 (symbol-value 'buffer-file-coding-system))
363 ((boundp 'file-coding-system)
364 (symbol-value 'file-coding-system))
366 ;; (and (boundp 'buffer-file-coding-system)
367 ;; buffer-file-coding-system)
369 (condition-case error
371 (error (message "%s is broken: %s" file (cdr error))))
375 (while (and (> (length mime-preview-situation-example-list)
376 mime-preview-situation-example-list-max-size)
378 (setq mime-preview-situation-example-list
379 (mime-reduce-situation-examples
380 mime-preview-situation-example-list))
382 (error (setq mime-preview-situation-example-list nil)))
383 ;; (let ((rest mime-preview-situation-example-list))
385 ;; (ctree-set-calist-strictly 'mime-preview-condition
387 ;; (setq rest (cdr rest))))
390 (while (and (> (length mime-acting-situation-example-list)
391 mime-acting-situation-example-list-max-size)
393 (setq mime-acting-situation-example-list
394 (mime-reduce-situation-examples
395 mime-acting-situation-example-list))
397 (error (setq mime-acting-situation-example-list nil))))))
399 (defun mime-save-situation-examples ()
400 (if (or mime-preview-situation-example-list
401 mime-acting-situation-example-list)
402 (let ((file mime-situation-examples-file))
404 (insert ";;; " (file-name-nondirectory file) "\n")
405 (insert "\n;; This file is generated automatically by "
406 mime-view-version "\n\n")
407 (insert ";;; Code:\n\n")
408 (if mime-preview-situation-example-list
409 (pp `(setq mime-preview-situation-example-list
410 ',mime-preview-situation-example-list)
412 (if mime-acting-situation-example-list
413 (pp `(setq mime-acting-situation-example-list
414 ',mime-acting-situation-example-list)
417 (file-name-nondirectory file)
420 ((boundp 'buffer-file-coding-system)
421 (setq buffer-file-coding-system
422 mime-situation-examples-file-coding-system))
423 ((boundp 'file-coding-system)
424 (setq file-coding-system
425 mime-situation-examples-file-coding-system)))
426 ;; (setq buffer-file-coding-system
427 ;; mime-situation-examples-file-coding-system)
428 (setq buffer-file-name file)
431 (add-hook 'kill-emacs-hook 'mime-save-situation-examples)
433 (defun mime-reduce-situation-examples (situation-examples)
434 (let ((len (length situation-examples))
442 ir situation-examples)
446 jr situation-examples)
450 (setq ret (mime-compare-situation-with-example (car ic)(car jc))
452 det-ret (+ (length (car ic))(length (car jc)))
453 det-org (length (cdr ret))
454 freq (+ (cdr ic)(cdr jc)))
455 (cond ((< max-sim sim)
462 dest (cons (cdr ret) freq)))
464 (cond ((> min-det-ret det-ret)
465 (setq min-det-ret det-ret
470 dest (cons (cdr ret) freq)))
471 ((= min-det-ret det-ret)
472 (cond ((> min-det-org det-org)
473 (setq min-det-org det-org
477 dest (cons (cdr ret) freq)))
478 ((= min-det-org det-org)
479 (cond ((> min-freq freq)
483 dest (cons (cdr ret) freq)))))))))))
492 (setq jr (nthcdr (1- d-j) situation-examples))
493 (setcdr jr (cddr jr))
495 (setq situation-examples
496 (cdr situation-examples))
497 (setq ir (nthcdr (1- d-i) situation-examples))
498 (setcdr ir (cddr ir)))
499 (if (setq ir (assoc (car dest) situation-examples))
501 (setcdr ir (+ (cdr ir)(cdr dest)))
503 (cons dest situation-examples)
504 ;; situation-examples may be modified.
508 ;;; @ presentation of preview
514 ;;; @@@ predicate function
517 ;; (defun mime-view-entity-button-visible-p (entity)
518 ;; "Return non-nil if header of ENTITY is visible.
519 ;; Please redefine this function if you want to change default setting."
520 ;; (let ((media-type (mime-entity-media-type entity))
521 ;; (media-subtype (mime-entity-media-subtype entity)))
522 ;; (or (not (eq media-type 'application))
523 ;; (and (not (eq media-subtype 'x-selection))
524 ;; (or (not (eq media-subtype 'octet-stream))
525 ;; (let ((mother-entity (mime-entity-parent entity)))
526 ;; (or (not (eq (mime-entity-media-type mother-entity)
528 ;; (not (eq (mime-entity-media-subtype mother-entity)
533 ;;; @@@ entity button generator
536 (defun mime-view-insert-entity-button (entity)
537 "Insert entity-button of ENTITY."
538 (let ((entity-node-id (mime-entity-node-id entity))
539 (params (mime-entity-parameters entity))
540 (subject (mime-view-entity-title entity)))
542 (let ((access-type (assoc "access-type" params))
543 (num (or (cdr (assoc "x-part-number" params))
544 (if (consp entity-node-id)
547 (format "%s" (1+ num))))
548 (reverse entity-node-id) ".")
551 (let ((server (assoc "server" params)))
552 (setq access-type (cdr access-type))
554 (format "%s %s ([%s] %s)"
555 num subject access-type (cdr server))
556 (let ((site (cdr (assoc "site" params)))
557 (dir (cdr (assoc "directory" params)))
558 (url (cdr (assoc "url" params))))
560 (format "%s %s ([%s] %s)"
561 num subject access-type url)
562 (format "%s %s ([%s] %s:%s)"
563 num subject access-type site dir))))))
565 (let ((media-type (mime-entity-media-type entity))
566 (media-subtype (mime-entity-media-subtype entity))
567 (charset (cdr (assoc "charset" params)))
568 (encoding (mime-entity-encoding entity)))
572 (format " <%s/%s%s%s>"
573 media-type media-subtype
575 (concat "; " charset)
578 (concat " (" encoding ")")
580 (if (>= (+ (current-column)(length rest))(window-width))
583 (function mime-preview-play-current-entity))))
589 (defvar mime-header-presentation-method-alist nil
590 "Alist of major mode vs. corresponding header-presentation-method functions.
591 Each element looks like (SYMBOL . FUNCTION).
592 SYMBOL must be major mode in raw-buffer or t. t means default.
593 Interface of FUNCTION must be (ENTITY SITUATION).")
595 (defvar mime-view-ignored-field-list
596 '(".*Received:" ".*Path:" ".*Id:" "^References:"
597 "^Replied:" "^Errors-To:"
598 "^Lines:" "^Sender:" ".*Host:" "^Xref:"
599 "^Content-Type:" "^Precedence:"
600 "^Status:" "^X-VM-.*:")
601 "All fields that match this list will be hidden in MIME preview buffer.
602 Each elements are regexp of field-name.")
604 (defvar mime-view-visible-field-list '("^Dnas.*:" "^Message-Id:")
605 "All fields that match this list will be displayed in MIME preview buffer.
606 Each elements are regexp of field-name.")
612 ;;; @@@ predicate function
615 (in-calist-package 'mime-view)
617 (defun mime-calist::field-match-method-as-default-rule (calist
618 field-type field-value)
619 (let ((s-field (assq field-type calist)))
620 (cond ((null s-field)
621 (cons (cons field-type field-value) calist))
624 (define-calist-field-match-method
625 'header #'mime-calist::field-match-method-as-default-rule)
627 (define-calist-field-match-method
628 'body #'mime-calist::field-match-method-as-default-rule)
631 (defvar mime-preview-condition nil
632 "Condition-tree about how to display entity.")
634 (ctree-set-calist-strictly
635 'mime-preview-condition '((type . application)(subtype . octet-stream)
638 (ctree-set-calist-strictly
639 'mime-preview-condition '((type . application)(subtype . octet-stream)
642 (ctree-set-calist-strictly
643 'mime-preview-condition '((type . application)(subtype . octet-stream)
647 (ctree-set-calist-strictly
648 'mime-preview-condition '((type . application)(subtype . pgp)
651 (ctree-set-calist-strictly
652 'mime-preview-condition '((type . application)(subtype . x-latex)
655 (ctree-set-calist-strictly
656 'mime-preview-condition '((type . application)(subtype . x-selection)
659 (ctree-set-calist-strictly
660 'mime-preview-condition '((type . application)(subtype . x-comment)
663 (ctree-set-calist-strictly
664 'mime-preview-condition '((type . message)(subtype . delivery-status)
667 (ctree-set-calist-strictly
668 'mime-preview-condition
670 (body-presentation-method . mime-display-text/plain)))
672 (defvar mime-preview-fill-flowed-text
673 (module-installed-p 'flow-fill)
674 "If non-nil, fill RFC2646 \"flowed\" text.")
676 (autoload 'fill-flowed "flow-fill")
678 (ctree-set-calist-strictly
679 'mime-preview-condition
682 (body-presentation-method . mime-display-text/plain)))
684 (ctree-set-calist-strictly
685 'mime-preview-condition
686 '((type . text)(subtype . enriched)
688 (body-presentation-method . mime-display-text/enriched)))
690 (ctree-set-calist-strictly
691 'mime-preview-condition
692 '((type . text)(subtype . richtext)
694 (body-presentation-method . mime-display-text/richtext)))
696 (autoload 'mime-display-application/x-postpet "postpet")
698 (ctree-set-calist-strictly
699 'mime-preview-condition
700 '((type . application)(subtype . x-postpet)
702 (body-presentation-method . mime-display-application/x-postpet)))
704 (ctree-set-calist-strictly
705 'mime-preview-condition
706 '((type . application)(subtype . emacs-lisp)(disposition-type . inline)
708 (body-presentation-method . mime-display-application/emacs-lisp)))
710 (ctree-set-calist-strictly
711 'mime-preview-condition
712 '((type . text)(subtype . t)
714 (body-presentation-method . mime-display-text/plain)))
716 (ctree-set-calist-strictly
717 'mime-preview-condition
718 '((type . multipart)(subtype . alternative)
720 (body-presentation-method . mime-display-multipart/alternative)))
722 (ctree-set-calist-strictly
723 'mime-preview-condition
724 '((type . multipart)(subtype . related)
726 (body-presentation-method . mime-display-multipart/related)))
728 (ctree-set-calist-strictly
729 'mime-preview-condition
730 '((type . multipart)(subtype . t)
732 (body-presentation-method . mime-display-multipart/mixed)))
734 (ctree-set-calist-strictly
735 'mime-preview-condition
736 '((type . message)(subtype . partial)
738 (body-presentation-method . mime-display-message/partial-button)))
740 (ctree-set-calist-strictly
741 'mime-preview-condition
742 '((type . message)(subtype . rfc822)
744 (body-presentation-method . mime-display-multipart/mixed)
745 (childrens-situation (header . visible)
746 (entity-button . invisible))))
748 (ctree-set-calist-strictly
749 'mime-preview-condition
750 '((type . message)(subtype . news)
752 (body-presentation-method . mime-display-multipart/mixed)
753 (childrens-situation (header . visible)
754 (entity-button . invisible))))
757 ;;; @@@ entity presentation
760 (defun mime-display-text/plain (entity situation)
762 (narrow-to-region (point-max)(point-max))
764 (mime-insert-text-content entity)
766 (message "Can't decode current entity.")
768 (run-hooks 'mime-text-decode-hook)
769 (goto-char (point-max))
770 (if (not (eq (char-after (1- (point))) ?\n))
772 (if (and mime-preview-fill-flowed-text
773 (equal (cdr (assoc "format" situation)) "flowed"))
775 (mime-add-url-buttons)
776 (run-hooks 'mime-display-text/plain-hook)))
778 (defun mime-display-text/richtext (entity situation)
780 (narrow-to-region (point-max)(point-max))
781 (mime-insert-text-content entity)
782 (run-hooks 'mime-text-decode-hook)
783 (let ((beg (point-min)))
784 (remove-text-properties beg (point-max) '(face nil))
785 (richtext-decode beg (point-max)))))
787 (defun mime-display-text/enriched (entity situation)
789 (narrow-to-region (point-max)(point-max))
790 (mime-insert-text-content entity)
791 (run-hooks 'mime-text-decode-hook)
792 (let ((beg (point-min)))
793 (remove-text-properties beg (point-max) '(face nil))
794 (enriched-decode beg (point-max)))))
796 (defvar mime-view-announcement-for-message/partial
797 "This is message/partial style split message.")
799 (defun mime-display-message/partial-button (&optional entity situation)
801 (goto-char (point-max))
802 (if (not (search-backward "\n\n" nil t))
804 (goto-char (point-max))
805 (mime-insert-button mime-view-announcement-for-message/partial
806 #'mime-preview-play-current-entity)))
808 (defun mime-display-multipart/mixed (entity situation)
809 (let ((children (mime-entity-children entity))
810 (original-major-mode-cell (assq 'major-mode situation))
812 (cdr (assq 'childrens-situation situation))))
813 (if original-major-mode-cell
814 (setq default-situation
815 (cons original-major-mode-cell default-situation)))
817 (mime-display-entity (car children) nil default-situation)
818 (setq children (cdr children)))))
820 (defcustom mime-view-type-subtype-score-alist
821 '(((text . enriched) . 3)
822 ((text . richtext) . 2)
825 "Alist MEDIA-TYPE vs corresponding score.
826 MEDIA-TYPE must be (TYPE . SUBTYPE), TYPE or t. t means default."
828 :type '(repeat (cons (choice :tag "Media-Type"
829 (cons :tag "Type/Subtype"
830 (symbol :tag "Primary-type")
831 (symbol :tag "Subtype"))
833 (const :tag "Default" t))
836 (defun mime-display-multipart/alternative (entity situation)
837 (let* ((children (mime-entity-children entity))
838 (original-major-mode-cell (assq 'major-mode situation))
840 (cdr (assq 'childrens-situation situation)))
845 (if original-major-mode-cell
846 (setq default-situation
847 (cons original-major-mode-cell default-situation)))
852 (mime-find-entity-preview-situation
853 child default-situation)))
854 (if (cdr (assq 'body-presentation-method situation))
859 (cdr (assq 'type situation))
860 (cdr (assq 'subtype situation)))
861 mime-view-type-subtype-score-alist)
863 (cdr (assq 'type situation))
864 mime-view-type-subtype-score-alist)
867 mime-view-type-subtype-score-alist)))))
868 (if (> score max-score)
876 (let ((child (car children))
877 (situation (car situations)))
878 (mime-display-entity child (if (= i p)
880 (put-alist 'body 'invisible
881 (copy-alist situation)))))
882 (setq children (cdr children)
883 situations (cdr situations)
886 (defun mime-display-multipart/related (entity situation)
887 (let* ((param-start (mime-parse-msg-id
888 (std11-lexical-analyze
890 (mime-content-type-parameters
891 (mime-entity-content-type entity)))))))
892 (start (or (and param-start (mime-find-entity-from-content-id
895 (car (mime-entity-children entity))))
896 (original-major-mode-cell (assq 'major-mode situation))
897 (default-situation (cdr (assq 'childrens-situation situation))))
898 (if original-major-mode-cell
899 (setq default-situation
900 (cons original-major-mode-cell default-situation)))
901 (mime-display-entity start nil default-situation)))
903 ;;; stolen (and renamed) from mm-view.el.
904 (defun mime-display-inline-fontify (entity mode)
905 ;; XEmacs @#$@ version of font-lock refuses to fully turn itself
906 ;; on for buffers whose name begins with " ". That's why we use
907 ;; save-current-buffer/get-buffer-create rather than
909 (let ((buffer (get-buffer-create "*fontification*")))
912 (buffer-disable-undo)
914 (mime-insert-entity-content entity)
916 (let ((font-lock-verbose nil))
917 ;; I find font-lock a bit too verbose.
918 (font-lock-fontify-buffer))
919 ;; By default, XEmacs font-lock uses non-duplicable text
920 ;; properties. This code forces all the text properties
921 ;; to be copied along with the text.
922 (static-when (fboundp 'extent-list)
923 (map-extents (lambda (ext ignored)
924 (set-extent-property ext 'duplicable t)
926 nil nil nil nil nil 'text-prop)))
927 (insert-buffer-substring buffer)))
929 (defun mime-display-application/emacs-lisp (entity situation)
931 (narrow-to-region (point-max)(point-max))
932 (mime-display-inline-fontify entity 'emacs-lisp-mode)
933 (run-hooks 'mime-text-decode-hook 'mime-display-text/plain-hook)))
936 ;;; @ acting-condition
939 (defvar mime-acting-condition nil
940 "Condition-tree about how to process entity.")
942 (defun mime-view-read-mailcap-files (&optional files)
944 (setq files mime-view-mailcap-files))
947 (setq file (car files))
948 (if (file-readable-p file)
949 (setq entries (append entries (mime-parse-mailcap-file file))))
950 (setq files (cdr files)))
952 (let ((entry (car entries))
955 (let* ((field (car entry))
956 (field-type (car field)))
957 (cond ((eq field-type 'view) (setq view field))
958 ((eq field-type 'print) (setq print field))
959 ((memq field-type '(compose composetyped edit)))
960 (t (setq shared (cons field shared))))
962 (setq entry (cdr entry)))
963 (setq shared (nreverse shared))
964 (ctree-set-calist-with-default
965 'mime-acting-condition
966 (append shared (list '(mode . "play")(cons 'method (cdr view)))))
968 (ctree-set-calist-with-default
969 'mime-acting-condition
971 (list '(mode . "print")(cons 'method (cdr view)))))))
972 (setq entries (cdr entries)))))
974 (mime-view-read-mailcap-files)
976 (ctree-set-calist-strictly
977 'mime-acting-condition
978 '((type . application)(subtype . octet-stream)
980 (method . mime-detect-content)))
982 (ctree-set-calist-with-default
983 'mime-acting-condition
985 (method . mime-save-content)))
987 (ctree-set-calist-strictly
988 'mime-acting-condition
989 '((type . text)(subtype . x-rot13-47)(mode . "play")
990 (method . mime-view-caesar)))
991 (ctree-set-calist-strictly
992 'mime-acting-condition
993 '((type . text)(subtype . x-rot13-47-48)(mode . "play")
994 (method . mime-view-caesar)))
996 (ctree-set-calist-strictly
997 'mime-acting-condition
998 '((type . message)(subtype . rfc822)(mode . "play")
999 (method . mime-view-message/rfc822)))
1000 (ctree-set-calist-strictly
1001 'mime-acting-condition
1002 '((type . message)(subtype . partial)(mode . "play")
1003 (method . mime-store-message/partial-piece)))
1005 (ctree-set-calist-strictly
1006 'mime-acting-condition
1007 '((type . message)(subtype . external-body)
1008 ("access-type" . "anon-ftp")
1009 (method . mime-view-message/external-anon-ftp)))
1011 (ctree-set-calist-strictly
1012 'mime-acting-condition
1013 '((type . message)(subtype . external-body)
1014 ("access-type" . "url")
1015 (method . mime-view-message/external-url)))
1017 (ctree-set-calist-strictly
1018 'mime-acting-condition
1019 '((type . application)(subtype . octet-stream)
1020 (method . mime-save-content)))
1023 ;;; @ quitting method
1026 (defvar mime-preview-quitting-method-alist
1027 '((mime-show-message-mode
1028 . mime-preview-quitting-method-for-mime-show-message-mode))
1029 "Alist of major-mode vs. quitting-method of mime-view.")
1031 (defvar mime-preview-over-to-previous-method-alist nil
1032 "Alist of major-mode vs. over-to-previous-method of mime-view.")
1034 (defvar mime-preview-over-to-next-method-alist nil
1035 "Alist of major-mode vs. over-to-next-method of mime-view.")
1038 ;;; @ following method
1041 (defvar mime-preview-following-method-alist nil
1042 "Alist of major-mode vs. following-method of mime-view.")
1044 (defvar mime-view-following-required-fields-list
1051 (defun mime-display-entity (entity &optional situation
1052 default-situation preview-buffer)
1054 (setq preview-buffer (current-buffer)))
1055 (let* (e nb ne nhb nbb)
1056 (in-calist-package 'mime-view)
1059 (mime-find-entity-preview-situation entity default-situation)))
1060 (let ((button-is-invisible
1061 (eq (cdr (or (assq '*entity-button situation)
1062 (assq 'entity-button situation)))
1065 (eq (cdr (or (assq '*header situation)
1066 (assq 'header situation)))
1069 (eq (cdr (or (assq '*body situation)
1070 (assq 'body situation)))
1072 (children (mime-entity-children entity)))
1073 (set-buffer preview-buffer)
1075 (narrow-to-region nb nb)
1076 (or button-is-invisible
1077 ;; (if (mime-view-entity-button-visible-p entity)
1078 (mime-view-insert-entity-button entity)
1081 (if header-is-visible
1082 (let ((header-presentation-method
1083 (or (cdr (assq 'header-presentation-method situation))
1084 (cdr (assq (cdr (assq 'major-mode situation))
1085 mime-header-presentation-method-alist)))))
1087 (if header-presentation-method
1088 (funcall header-presentation-method entity situation)
1089 (mime-insert-header entity
1090 mime-view-ignored-field-list
1091 mime-view-visible-field-list))
1092 (mime-add-url-buttons)
1093 (run-hooks 'mime-display-header-hook)
1094 (put-text-property nhb (point-max) 'mime-view-entity-header entity)
1095 (goto-char (point-max))
1100 (let ((body-presentation-method
1101 (cdr (assq 'body-presentation-method situation))))
1102 (if (functionp body-presentation-method)
1103 (funcall body-presentation-method entity situation)
1104 (mime-display-text/plain entity situation)))
1105 (when button-is-invisible
1106 (goto-char (point-max))
1107 (mime-view-insert-entity-button entity))
1108 (unless header-is-visible
1109 (goto-char (point-max))
1111 (setq ne (point-max))
1113 (put-text-property nb ne 'mime-view-entity entity)
1114 (put-text-property nb ne 'mime-view-situation situation)
1115 (put-text-property nbb ne 'mime-view-entity-body entity)
1117 (if (and children body-is-visible)
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-multipart/mixed entity situation)))))))
1125 ;;; @ MIME viewer mode
1128 (defconst mime-view-popup-menu-list
1130 ["Move to upper entity" mime-preview-move-to-upper]
1131 ["Move to previous entity" mime-preview-move-to-previous]
1132 ["Move to next entity" mime-preview-move-to-next]
1133 ["Scroll-down" mime-preview-scroll-down-entity]
1134 ["Scroll-up" mime-preview-scroll-up-entity]
1135 ["Play current entity" mime-preview-play-current-entity]
1136 ["Extract current entity" mime-preview-extract-current-entity]
1137 ["Print current entity" mime-preview-print-current-entity])
1138 "Menu for MIME Viewer")
1140 (defun mime-view-popup-menu (event)
1141 "Popup the menu in the MIME Viewer buffer"
1143 (mime-popup-menu-popup mime-view-popup-menu-list event))
1145 ;;; The current local map is taken precendence over `widget-keymap',
1146 ;;; because GNU Emacs' widget implementation doesn't set `local-map' property.
1147 ;;; So we need to specify derivation.
1148 (defvar widget-keymap)
1149 (defun mime-view-maybe-inherit-widget-keymap ()
1150 (when (boundp 'widget-keymap)
1151 (set-keymap-parent (current-local-map) widget-keymap)))
1153 (add-hook 'mime-view-define-keymap-hook 'mime-view-maybe-inherit-widget-keymap)
1155 (defun mime-view-define-keymap (&optional default)
1156 (let ((mime-view-mode-map (if (keymapp default)
1157 (copy-keymap default)
1158 (make-sparse-keymap))))
1159 (define-key mime-view-mode-map
1160 "u" (function mime-preview-move-to-upper))
1161 (define-key mime-view-mode-map
1162 "p" (function mime-preview-move-to-previous))
1163 (define-key mime-view-mode-map
1164 "n" (function mime-preview-move-to-next))
1165 (define-key mime-view-mode-map
1166 "\e\t" (function mime-preview-move-to-previous))
1167 (define-key mime-view-mode-map
1168 "\t" (function mime-preview-move-to-next))
1169 (define-key mime-view-mode-map
1170 " " (function mime-preview-scroll-up-entity))
1171 (define-key mime-view-mode-map
1172 "\M- " (function mime-preview-scroll-down-entity))
1173 (define-key mime-view-mode-map
1174 "\177" (function mime-preview-scroll-down-entity))
1175 (define-key mime-view-mode-map
1176 "\C-m" (function mime-preview-next-line-entity))
1177 (define-key mime-view-mode-map
1178 "\C-\M-m" (function mime-preview-previous-line-entity))
1179 (define-key mime-view-mode-map
1180 "v" (function mime-preview-play-current-entity))
1181 (define-key mime-view-mode-map
1182 "e" (function mime-preview-extract-current-entity))
1183 (define-key mime-view-mode-map
1184 "\C-c\C-p" (function mime-preview-print-current-entity))
1186 (define-key mime-view-mode-map
1187 "\C-c\C-t\C-f" (function mime-preview-toggle-header))
1188 (define-key mime-view-mode-map
1189 "\C-c\C-th" (function mime-preview-toggle-header))
1190 (define-key mime-view-mode-map
1191 "\C-c\C-t\C-c" (function mime-preview-toggle-content))
1193 (define-key mime-view-mode-map
1194 "\C-c\C-v\C-f" (function mime-preview-show-header))
1195 (define-key mime-view-mode-map
1196 "\C-c\C-vh" (function mime-preview-show-header))
1197 (define-key mime-view-mode-map
1198 "\C-c\C-v\C-c" (function mime-preview-show-content))
1200 (define-key mime-view-mode-map
1201 "\C-c\C-d\C-f" (function mime-preview-hide-header))
1202 (define-key mime-view-mode-map
1203 "\C-c\C-dh" (function mime-preview-hide-header))
1204 (define-key mime-view-mode-map
1205 "\C-c\C-d\C-c" (function mime-preview-hide-content))
1207 (define-key mime-view-mode-map
1208 "a" (function mime-preview-follow-current-entity))
1209 (define-key mime-view-mode-map
1210 "q" (function mime-preview-quit))
1211 (define-key mime-view-mode-map
1212 "\C-c\C-x" (function mime-preview-kill-buffer))
1213 ;; (define-key mime-view-mode-map
1214 ;; "<" (function beginning-of-buffer))
1215 ;; (define-key mime-view-mode-map
1216 ;; ">" (function end-of-buffer))
1217 (define-key mime-view-mode-map
1218 "?" (function describe-mode))
1219 (define-key mime-view-mode-map
1220 [tab] (function mime-preview-move-to-next))
1221 (define-key mime-view-mode-map
1222 [delete] (function mime-preview-scroll-down-entity))
1223 (define-key mime-view-mode-map
1224 [backspace] (function mime-preview-scroll-down-entity))
1225 (if (functionp default)
1226 (if (featurep 'xemacs)
1227 (set-keymap-default-binding mime-view-mode-map default)
1228 (setq mime-view-mode-map
1229 (append mime-view-mode-map (list (cons t default))))))
1230 (define-key mime-view-mode-map
1231 [down-mouse-3] (function mime-view-popup-menu))
1232 ;; (run-hooks 'mime-view-define-keymap-hook)
1233 mime-view-mode-map))
1235 (defvar mime-view-mode-default-map (mime-view-define-keymap))
1238 (defsubst mime-maybe-hide-echo-buffer ()
1239 "Clear mime-echo buffer and delete window for it."
1240 (let ((buf (get-buffer mime-echo-buffer-name)))
1245 (let ((win (get-buffer-window buf)))
1247 (delete-window win)))
1248 (bury-buffer buf)))))
1250 (defvar mime-view-redisplay nil)
1253 (defun mime-display-message (message &optional preview-buffer
1254 mother default-keymap-or-function
1255 original-major-mode keymap)
1256 "View MESSAGE in MIME-View mode.
1258 Optional argument PREVIEW-BUFFER specifies the buffer of the
1259 presentation. It must be either nil or a name of preview buffer.
1261 Optional argument MOTHER specifies mother-buffer of the preview-buffer.
1263 Optional argument DEFAULT-KEYMAP-OR-FUNCTION is nil, keymap or
1264 function. If it is a keymap, keymap of MIME-View mode will be added
1265 to it. If it is a function, it will be bound as default binding of
1266 keymap of MIME-View mode.
1268 Optional argument ORIGINAL-MAJOR-MODE is major-mode of representation
1269 buffer of MESSAGE. If it is nil, current `major-mode' is used.
1271 Optional argument KEYMAP is keymap of MIME-View mode. If it is
1272 non-nil, DEFAULT-KEYMAP-OR-FUNCTION is ignored. If it is nil,
1273 `mime-view-mode-default-map' is used."
1274 (mime-maybe-hide-echo-buffer)
1275 (let ((win-conf (current-window-configuration)))
1277 (setq preview-buffer
1278 (concat "*Preview-" (mime-entity-name message) "*")))
1279 (or original-major-mode
1280 (setq original-major-mode major-mode))
1281 (let ((inhibit-read-only t))
1282 (set-buffer (get-buffer-create preview-buffer))
1286 (setq mime-mother-buffer mother))
1287 (setq mime-preview-original-window-configuration win-conf)
1288 (setq major-mode 'mime-view-mode)
1289 (setq mode-name "MIME-View")
1290 (mime-display-entity message nil
1291 `((entity-button . invisible)
1293 (major-mode . ,original-major-mode))
1297 (if default-keymap-or-function
1298 (mime-view-define-keymap default-keymap-or-function)
1299 mime-view-mode-default-map)))
1301 (next-single-property-change (point-min) 'mime-view-entity)))
1304 (goto-char (point-min))
1305 (search-forward "\n\n" nil t)))
1306 (run-hooks 'mime-view-mode-hook)
1307 (set-buffer-modified-p nil)
1308 (setq buffer-read-only t)
1312 (defun mime-view-buffer (&optional raw-buffer preview-buffer mother
1313 default-keymap-or-function
1314 representation-type)
1315 "View RAW-BUFFER in MIME-View mode.
1316 Optional argument PREVIEW-BUFFER is either nil or a name of preview
1318 Optional argument DEFAULT-KEYMAP-OR-FUNCTION is nil, keymap or
1319 function. If it is a keymap, keymap of MIME-View mode will be added
1320 to it. If it is a function, it will be bound as default binding of
1321 keymap of MIME-View mode.
1322 Optional argument REPRESENTATION-TYPE is representation-type of
1323 message. It must be nil, `binary' or `cooked'. If it is nil,
1324 `cooked' is used as default."
1327 (setq raw-buffer (current-buffer)))
1328 (or representation-type
1329 (setq representation-type
1331 (set-buffer raw-buffer)
1332 (cdr (or (assq major-mode mime-raw-representation-type-alist)
1333 (assq t mime-raw-representation-type-alist))))))
1334 (if (eq representation-type 'binary)
1335 (setq representation-type 'buffer))
1336 (setq preview-buffer (mime-display-message
1337 (mime-open-entity representation-type raw-buffer)
1338 preview-buffer mother default-keymap-or-function))
1339 (or (get-buffer-window preview-buffer)
1340 (let ((r-win (get-buffer-window raw-buffer)))
1342 (set-window-buffer r-win preview-buffer)
1343 (let ((m-win (and mother (get-buffer-window mother))))
1345 (set-window-buffer m-win preview-buffer)
1346 (switch-to-buffer preview-buffer)))))))
1348 (defun mime-view-mode (&optional mother ctl encoding
1349 raw-buffer preview-buffer
1350 default-keymap-or-function)
1351 "Major mode for viewing MIME message.
1353 Here is a list of the standard keys for mime-view-mode.
1358 u Move to upper content
1359 p or M-TAB Move to previous content
1360 n or TAB Move to next content
1361 SPC Scroll up or move to next content
1362 M-SPC or DEL Scroll down or move to previous content
1363 RET Move to next line
1364 M-RET Move to previous line
1365 v Decode current content as `play mode'
1366 e Decode current content as `extract mode'
1367 C-c C-p Decode current content as `print mode'
1368 a Followup to current content.
1370 button-2 Move to point under the mouse cursor
1371 and decode current content as `play mode'
1374 (unless mime-view-redisplay
1376 (if raw-buffer (set-buffer raw-buffer))
1379 (or (assq major-mode mime-raw-representation-type-alist)
1380 (assq t mime-raw-representation-type-alist)))))
1381 (if (eq type 'binary)
1382 (setq type 'buffer))
1383 (setq mime-message-structure (mime-open-entity type raw-buffer))
1384 (or (mime-entity-content-type mime-message-structure)
1385 (mime-entity-set-content-type mime-message-structure ctl)))
1386 (or (mime-entity-encoding mime-message-structure)
1387 (mime-entity-set-encoding mime-message-structure encoding))))
1388 (mime-display-message mime-message-structure preview-buffer
1389 mother default-keymap-or-function))
1395 (defun mime-preview-find-boundary-info (&optional get-mother)
1399 (while (null (setq entity
1400 (get-text-property (point) 'mime-view-entity)))
1402 (setq p-beg (previous-single-property-change (point) 'mime-view-entity))
1403 (setq entity-node-id (mime-entity-node-id entity))
1404 (setq len (length entity-node-id))
1407 (if (eq (next-single-property-change (point-min)
1412 ((eq (next-single-property-change p-beg 'mime-view-entity)
1414 (setq p-beg (point))))
1415 (setq p-end (next-single-property-change p-beg 'mime-view-entity))
1417 (setq p-end (point-max)))
1418 ((null entity-node-id)
1419 (setq p-end (point-max)))
1426 (next-single-property-change
1427 (point) 'mime-view-entity))
1429 (let ((rc (mime-entity-node-id
1430 (get-text-property (1- (point))
1431 'mime-view-entity))))
1432 (or (and (>= (setq i (- (length rc) len)) 0)
1433 (equal entity-node-id (nthcdr i rc)))
1436 (setq p-end (point-max))))))
1437 (vector p-beg p-end entity)))
1443 (autoload 'mime-preview-play-current-entity "mime-play"
1444 "Play current entity." t)
1446 (defun mime-preview-extract-current-entity (&optional ignore-examples)
1447 "Extract current entity into file (maybe).
1448 It decodes current entity to call internal or external method as
1449 \"extract\" mode. The method is selected from variable
1450 `mime-acting-condition'."
1452 (mime-preview-play-current-entity ignore-examples "extract"))
1454 (defun mime-preview-print-current-entity (&optional ignore-examples)
1455 "Print current entity (maybe).
1456 It decodes current entity to call internal or external method as
1457 \"print\" mode. The method is selected from variable
1458 `mime-acting-condition'."
1460 (mime-preview-play-current-entity ignore-examples "print"))
1466 (defun mime-preview-follow-current-entity ()
1467 "Write follow message to current entity.
1468 It calls following-method selected from variable
1469 `mime-preview-following-method-alist'."
1471 (let ((entity (mime-preview-find-boundary-info t))
1474 (setq p-beg (aref entity 0)
1475 p-end (aref entity 1)
1476 entity (aref entity 2))
1477 (if (get-text-property p-beg 'mime-view-entity-body)
1480 (next-single-property-change
1481 p-beg 'mime-view-entity-body nil
1482 (or (next-single-property-change p-beg 'mime-view-entity)
1484 (let* ((mode (mime-preview-original-major-mode 'recursive))
1485 (entity-node-id (mime-entity-node-id entity))
1487 (format "%s-%s" (buffer-name) (reverse entity-node-id)))
1489 (the-buf (current-buffer))
1492 (set-buffer (setq new-buf (get-buffer-create new-name)))
1495 (insert-buffer-substring the-buf pb-beg p-end)
1496 (goto-char (point-min))
1497 (let ((current-entity
1498 (if (and (eq (mime-entity-media-type entity) 'message)
1499 (eq (mime-entity-media-subtype entity) 'rfc822))
1500 (car (mime-entity-children entity))
1502 (while (and current-entity
1503 (if (and (eq (mime-entity-media-type
1504 current-entity) 'message)
1505 (eq (mime-entity-media-subtype
1506 current-entity) 'rfc822))
1508 (mime-insert-header current-entity fields)
1510 (setq fields (std11-collect-field-names)
1511 current-entity (mime-entity-parent current-entity))))
1512 (let ((rest mime-view-following-required-fields-list)
1515 (setq field-name (car rest))
1516 (or (std11-field-body field-name)
1519 (set-buffer the-buf)
1520 (let ((entity (when mime-mother-buffer
1521 (set-buffer mime-mother-buffer)
1522 (get-text-property (point)
1523 'mime-view-entity))))
1525 (null (setq ret (mime-entity-fetch-field
1526 entity field-name))))
1527 (setq entity (mime-entity-parent entity)))))
1529 (insert (concat field-name ": " ret "\n")))))
1530 (setq rest (cdr rest)))))
1531 (let ((f (cdr (assq mode mime-preview-following-method-alist))))
1536 "Sorry, following method for %s is not implemented yet."
1543 (defun mime-preview-move-to-upper ()
1544 "Move to upper entity.
1545 If there is no upper entity, call function `mime-preview-quit'."
1548 (while (null (setq cinfo
1549 (get-text-property (point) 'mime-view-entity)))
1551 (let ((r (mime-entity-parent cinfo))
1554 (while (setq point (previous-single-property-change
1555 (point) 'mime-view-entity))
1557 (when (eq r (get-text-property (point) 'mime-view-entity))
1558 (if (or (eq mime-preview-move-scroll t)
1559 (and mime-preview-move-scroll
1562 (move-to-window-line -1)
1563 (forward-line (* -1 next-screen-context-lines))
1566 (recenter next-screen-context-lines))
1568 (mime-preview-quit)))))
1570 (defun mime-preview-move-to-previous ()
1571 "Move to previous entity.
1572 If there is no previous entity, it calls function registered in
1573 variable `mime-preview-over-to-previous-method-alist'."
1575 (while (and (not (bobp))
1576 (null (get-text-property (point) 'mime-view-entity)))
1578 (let ((point (previous-single-property-change (point) 'mime-view-entity)))
1580 (>= point (point-min)))
1581 (if (get-text-property (1- point) 'mime-view-entity)
1582 (progn (goto-char point)
1584 (or (eq mime-preview-move-scroll t)
1585 (and mime-preview-move-scroll
1588 (move-to-window-line 0)
1589 (forward-line next-screen-context-lines)
1592 (recenter (* -1 next-screen-context-lines))))
1593 (goto-char (1- point))
1594 (mime-preview-move-to-previous))
1595 (let ((f (assq (mime-preview-original-major-mode)
1596 mime-preview-over-to-previous-method-alist)))
1598 (funcall (cdr f)))))))
1600 (defun mime-preview-move-to-next ()
1601 "Move to next entity.
1602 If there is no previous entity, it calls function registered in
1603 variable `mime-preview-over-to-next-method-alist'."
1605 (while (and (not (eobp))
1606 (null (get-text-property (point) 'mime-view-entity)))
1608 (let ((point (next-single-property-change (point) 'mime-view-entity)))
1610 (<= point (point-max)))
1613 (if (null (get-text-property point 'mime-view-entity))
1614 (mime-preview-move-to-next)
1616 (or (eq mime-preview-move-scroll t)
1617 (and mime-preview-move-scroll
1620 (move-to-window-line -1)
1622 (* -1 next-screen-context-lines))
1625 (recenter next-screen-context-lines))))
1626 (let ((f (assq (mime-preview-original-major-mode)
1627 mime-preview-over-to-next-method-alist)))
1629 (funcall (cdr f)))))))
1631 (defun mime-preview-scroll-up-entity (&optional h)
1632 "Scroll up current entity.
1633 If reached to (point-max), it calls function registered in variable
1634 `mime-preview-over-to-next-method-alist'."
1637 (let ((f (assq (mime-preview-original-major-mode)
1638 mime-preview-over-to-next-method-alist)))
1642 (or (next-single-property-change (point) 'mime-view-entity)
1644 (bottom (window-end (selected-window))))
1647 (progn (goto-char point)
1648 (recenter next-screen-context-lines))
1652 (goto-char (point-max))))))))
1654 (defun mime-preview-scroll-down-entity (&optional h)
1655 "Scroll down current entity.
1656 If reached to (point-min), it calls function registered in variable
1657 `mime-preview-over-to-previous-method-alist'."
1660 (let ((f (assq (mime-preview-original-major-mode)
1661 mime-preview-over-to-previous-method-alist)))
1665 (or (previous-single-property-change (point) 'mime-view-entity)
1667 (top (window-start (selected-window))))
1670 (progn (goto-char point)
1671 (recenter (* -1 next-screen-context-lines)))
1674 (beginning-of-buffer
1675 (goto-char (point-min))))))))
1677 (defun mime-preview-next-line-entity (&optional lines)
1678 "Scroll up one line (or prefix LINES lines).
1679 If LINES is negative, scroll down LINES lines."
1681 (mime-preview-scroll-up-entity (or lines 1)))
1683 (defun mime-preview-previous-line-entity (&optional lines)
1684 "Scrroll down one line (or prefix LINES lines).
1685 If LINES is negative, scroll up LINES lines."
1687 (mime-preview-scroll-down-entity (or lines 1)))
1693 (defun mime-preview-toggle-display (type &optional display)
1694 (let ((situation (mime-preview-find-boundary-info))
1695 (sym (intern (concat "*" (symbol-name type))))
1697 (setq p-beg (aref situation 0)
1698 p-end (aref situation 1)
1699 entity (aref situation 2)
1700 situation (get-text-property p-beg 'mime-view-situation))
1701 (cond ((eq display 'invisible)
1706 (eq (cdr (or (assq sym situation)
1707 (assq type situation)))
1709 (setq situation (put-alist sym (if display
1714 (let ((inhibit-read-only t))
1715 (delete-region p-beg p-end)
1716 (mime-display-entity entity situation)))
1717 (let ((ret (assoc situation mime-preview-situation-example-list)))
1719 (setcdr ret (1+ (cdr ret)))
1720 (add-to-list 'mime-preview-situation-example-list
1721 (cons situation 0))))))
1723 (defun mime-preview-toggle-header (&optional force-visible)
1725 (mime-preview-toggle-display 'header force-visible))
1727 (defun mime-preview-toggle-content (&optional force-visible)
1729 (mime-preview-toggle-display 'body force-visible))
1731 (defun mime-preview-show-header ()
1733 (mime-preview-toggle-display 'header 'visible))
1735 (defun mime-preview-show-content ()
1737 (mime-preview-toggle-display 'body 'visible))
1739 (defun mime-preview-hide-header ()
1741 (mime-preview-toggle-display 'header 'invisible))
1743 (defun mime-preview-hide-content ()
1745 (mime-preview-toggle-display 'body 'invisible))
1751 (defun mime-preview-quit ()
1752 "Quit from MIME-preview buffer.
1753 It calls function registered in variable
1754 `mime-preview-quitting-method-alist'."
1756 (let ((r (assq (mime-preview-original-major-mode)
1757 mime-preview-quitting-method-alist)))
1759 (funcall (cdr r)))))
1761 (defun mime-preview-kill-buffer ()
1763 (kill-buffer (current-buffer)))
1769 (provide 'mime-view)
1772 (setq mime-situation-examples-file nil)
1773 ;; to avoid to read situation-examples-file at compile time.
1776 (mime-view-read-situation-examples-file)
1778 ;;; mime-view.el ends here