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 (defvar mime-preview-inline-fontify t
679 "If non-nil, fontify the inline part.")
681 (ctree-set-calist-strictly
682 'mime-preview-condition
685 (body-presentation-method . mime-display-text/plain)))
687 (ctree-set-calist-strictly
688 'mime-preview-condition
689 '((type . text)(subtype . enriched)
691 (body-presentation-method . mime-display-text/enriched)))
693 (ctree-set-calist-strictly
694 'mime-preview-condition
695 '((type . text)(subtype . richtext)
697 (body-presentation-method . mime-display-text/richtext)))
699 (autoload 'mime-display-application/x-postpet "postpet")
701 (ctree-set-calist-strictly
702 'mime-preview-condition
703 '((type . application)(subtype . x-postpet)
705 (body-presentation-method . mime-display-application/x-postpet)))
707 (ctree-set-calist-strictly
708 'mime-preview-condition
709 '((type . application)(subtype . emacs-lisp)
711 (body-presentation-method . mime-display-application/emacs-lisp)))
713 (ctree-set-calist-strictly
714 'mime-preview-condition
715 '((type . text)(subtype . t)
717 (body-presentation-method . mime-display-text/plain)))
719 (ctree-set-calist-strictly
720 'mime-preview-condition
721 '((type . multipart)(subtype . alternative)
723 (body-presentation-method . mime-display-multipart/alternative)))
725 (ctree-set-calist-strictly
726 'mime-preview-condition
727 '((type . multipart)(subtype . related)
729 (body-presentation-method . mime-display-multipart/related)))
731 (ctree-set-calist-strictly
732 'mime-preview-condition
733 '((type . multipart)(subtype . t)
735 (body-presentation-method . mime-display-multipart/mixed)))
737 (ctree-set-calist-strictly
738 'mime-preview-condition
739 '((type . message)(subtype . partial)
741 (body-presentation-method . mime-display-message/partial-button)))
743 (ctree-set-calist-strictly
744 'mime-preview-condition
745 '((type . message)(subtype . rfc822)
747 (body-presentation-method . mime-display-multipart/mixed)
748 (childrens-situation (header . visible)
749 (entity-button . invisible))))
751 (ctree-set-calist-strictly
752 'mime-preview-condition
753 '((type . message)(subtype . news)
755 (body-presentation-method . mime-display-multipart/mixed)
756 (childrens-situation (header . visible)
757 (entity-button . invisible))))
760 ;;; @@@ entity presentation
763 (defun mime-display-text/plain (entity situation)
765 (narrow-to-region (point-max)(point-max))
767 (if (and mime-preview-inline-fontify
768 (mime-entity-filename entity)) ;should be an attachment.
769 (mime-display-inline-fontify entity)
770 (mime-insert-text-content entity))
772 (message "Can't decode current entity.")
774 (run-hooks 'mime-text-decode-hook)
775 (goto-char (point-max))
776 (if (not (eq (char-after (1- (point))) ?\n))
778 (if (and mime-preview-fill-flowed-text
779 (equal (cdr (assoc "format" situation)) "flowed"))
781 (mime-add-url-buttons)
782 (run-hooks 'mime-display-text/plain-hook)))
784 (defun mime-display-text/richtext (entity situation)
786 (narrow-to-region (point-max)(point-max))
787 (mime-insert-text-content entity)
788 (run-hooks 'mime-text-decode-hook)
789 (let ((beg (point-min)))
790 (remove-text-properties beg (point-max) '(face nil))
791 (richtext-decode beg (point-max)))))
793 (defun mime-display-text/enriched (entity situation)
795 (narrow-to-region (point-max)(point-max))
796 (mime-insert-text-content entity)
797 (run-hooks 'mime-text-decode-hook)
798 (let ((beg (point-min)))
799 (remove-text-properties beg (point-max) '(face nil))
800 (enriched-decode beg (point-max)))))
802 (defvar mime-view-announcement-for-message/partial
803 "This is message/partial style split message.")
805 (defun mime-display-message/partial-button (&optional entity situation)
807 (goto-char (point-max))
808 (if (not (search-backward "\n\n" nil t))
810 (goto-char (point-max))
811 (mime-insert-button mime-view-announcement-for-message/partial
812 #'mime-preview-play-current-entity)))
814 (defun mime-display-multipart/mixed (entity situation)
815 (let ((children (mime-entity-children entity))
816 (original-major-mode-cell (assq 'major-mode situation))
818 (cdr (assq 'childrens-situation situation))))
819 (if original-major-mode-cell
820 (setq default-situation
821 (cons original-major-mode-cell default-situation)))
823 (mime-display-entity (car children) nil default-situation)
824 (setq children (cdr children)))))
826 (defcustom mime-view-type-subtype-score-alist
827 '(((text . enriched) . 3)
828 ((text . richtext) . 2)
831 "Alist MEDIA-TYPE vs corresponding score.
832 MEDIA-TYPE must be (TYPE . SUBTYPE), TYPE or t. t means default."
834 :type '(repeat (cons (choice :tag "Media-Type"
835 (cons :tag "Type/Subtype"
836 (symbol :tag "Primary-type")
837 (symbol :tag "Subtype"))
839 (const :tag "Default" t))
842 (defun mime-display-multipart/alternative (entity situation)
843 (let* ((children (mime-entity-children entity))
844 (original-major-mode-cell (assq 'major-mode situation))
846 (cdr (assq 'childrens-situation situation)))
851 (if original-major-mode-cell
852 (setq default-situation
853 (cons original-major-mode-cell default-situation)))
858 (mime-find-entity-preview-situation
859 child default-situation)))
860 (if (cdr (assq 'body-presentation-method situation))
865 (cdr (assq 'type situation))
866 (cdr (assq 'subtype situation)))
867 mime-view-type-subtype-score-alist)
869 (cdr (assq 'type situation))
870 mime-view-type-subtype-score-alist)
873 mime-view-type-subtype-score-alist)))))
874 (if (> score max-score)
882 (let ((child (car children))
883 (situation (car situations)))
884 (mime-display-entity child (if (= i p)
886 (put-alist 'body 'invisible
887 (copy-alist situation)))))
888 (setq children (cdr children)
889 situations (cdr situations)
892 (defun mime-display-multipart/related (entity situation)
893 (let* ((param-start (mime-parse-msg-id
894 (std11-lexical-analyze
896 (mime-content-type-parameters
897 (mime-entity-content-type entity)))))))
898 (start (or (and param-start (mime-find-entity-from-content-id
901 (car (mime-entity-children entity))))
902 (original-major-mode-cell (assq 'major-mode situation))
903 (default-situation (cdr (assq 'childrens-situation situation))))
904 (if original-major-mode-cell
905 (setq default-situation
906 (cons original-major-mode-cell default-situation)))
907 (mime-display-entity start nil default-situation)))
909 ;;; stolen (and renamed) from mm-view.el.
910 (defun mime-display-inline-fontify (entity &optional mode)
911 ;; XEmacs @#$@ version of font-lock refuses to fully turn itself
912 ;; on for buffers whose name begins with " ". That's why we use
913 ;; save-current-buffer/get-buffer-create rather than
915 (let ((buffer (get-buffer-create "*fontification*"))
919 (buffer-disable-undo)
920 (kill-all-local-variables)
922 (mime-insert-text-content entity)
927 (if (setq filename (mime-entity-filename entity))
928 (set-visited-file-name filename))
930 (let ((font-lock-verbose nil))
931 ;; I find font-lock a bit too verbose.
932 (font-lock-fontify-buffer))
933 ;; By default, XEmacs font-lock uses non-duplicable text
934 ;; properties. This code forces all the text properties
935 ;; to be copied along with the text.
936 (static-when (fboundp 'extent-list)
937 (map-extents (lambda (ext ignored)
938 (set-extent-property ext 'duplicable t)
940 nil nil nil nil nil 'text-prop)))
941 (set-visited-file-name nil)))
942 (insert-buffer-substring buffer)))
944 (defun mime-display-application/emacs-lisp (entity situation)
946 (narrow-to-region (point-max)(point-max))
947 (mime-display-inline-fontify entity 'emacs-lisp-mode)
948 (run-hooks 'mime-text-decode-hook 'mime-display-text/plain-hook)))
951 ;;; @ acting-condition
954 (defvar mime-acting-condition nil
955 "Condition-tree about how to process entity.")
957 (defun mime-view-read-mailcap-files (&optional files)
959 (setq files mime-view-mailcap-files))
962 (setq file (car files))
963 (if (file-readable-p file)
964 (setq entries (append entries (mime-parse-mailcap-file file))))
965 (setq files (cdr files)))
967 (let ((entry (car entries))
970 (let* ((field (car entry))
971 (field-type (car field)))
972 (cond ((eq field-type 'view) (setq view field))
973 ((eq field-type 'print) (setq print field))
974 ((memq field-type '(compose composetyped edit)))
975 (t (setq shared (cons field shared))))
977 (setq entry (cdr entry)))
978 (setq shared (nreverse shared))
979 (ctree-set-calist-with-default
980 'mime-acting-condition
981 (append shared (list '(mode . "play")(cons 'method (cdr view)))))
983 (ctree-set-calist-with-default
984 'mime-acting-condition
986 (list '(mode . "print")(cons 'method (cdr view)))))))
987 (setq entries (cdr entries)))))
989 (mime-view-read-mailcap-files)
991 (ctree-set-calist-strictly
992 'mime-acting-condition
993 '((type . application)(subtype . octet-stream)
995 (method . mime-detect-content)))
997 (ctree-set-calist-with-default
998 'mime-acting-condition
1000 (method . mime-save-content)))
1002 (ctree-set-calist-strictly
1003 'mime-acting-condition
1004 '((type . text)(subtype . x-rot13-47)(mode . "play")
1005 (method . mime-view-caesar)))
1006 (ctree-set-calist-strictly
1007 'mime-acting-condition
1008 '((type . text)(subtype . x-rot13-47-48)(mode . "play")
1009 (method . mime-view-caesar)))
1011 (ctree-set-calist-strictly
1012 'mime-acting-condition
1013 '((type . message)(subtype . rfc822)(mode . "play")
1014 (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)))
1020 (ctree-set-calist-strictly
1021 'mime-acting-condition
1022 '((type . message)(subtype . external-body)
1023 ("access-type" . "anon-ftp")
1024 (method . mime-view-message/external-anon-ftp)))
1026 (ctree-set-calist-strictly
1027 'mime-acting-condition
1028 '((type . message)(subtype . external-body)
1029 ("access-type" . "url")
1030 (method . mime-view-message/external-url)))
1032 (ctree-set-calist-strictly
1033 'mime-acting-condition
1034 '((type . application)(subtype . octet-stream)
1035 (method . mime-save-content)))
1038 ;;; @ quitting method
1041 (defvar mime-preview-quitting-method-alist
1042 '((mime-show-message-mode
1043 . mime-preview-quitting-method-for-mime-show-message-mode))
1044 "Alist of major-mode vs. quitting-method of mime-view.")
1046 (defvar mime-preview-over-to-previous-method-alist nil
1047 "Alist of major-mode vs. over-to-previous-method of mime-view.")
1049 (defvar mime-preview-over-to-next-method-alist nil
1050 "Alist of major-mode vs. over-to-next-method of mime-view.")
1053 ;;; @ following method
1056 (defvar mime-preview-following-method-alist nil
1057 "Alist of major-mode vs. following-method of mime-view.")
1059 (defvar mime-view-following-required-fields-list
1066 (defun mime-display-entity (entity &optional situation
1067 default-situation preview-buffer)
1069 (setq preview-buffer (current-buffer)))
1070 (let* (e nb ne nhb nbb)
1071 (in-calist-package 'mime-view)
1074 (mime-find-entity-preview-situation entity default-situation)))
1075 (let ((button-is-invisible
1076 (eq (cdr (or (assq '*entity-button situation)
1077 (assq 'entity-button situation)))
1080 (eq (cdr (or (assq '*header situation)
1081 (assq 'header situation)))
1084 (eq (cdr (or (assq '*body situation)
1085 (assq 'body situation)))
1087 (children (mime-entity-children entity)))
1088 (set-buffer preview-buffer)
1090 (narrow-to-region nb nb)
1091 (or button-is-invisible
1092 ;; (if (mime-view-entity-button-visible-p entity)
1093 (mime-view-insert-entity-button entity)
1096 (if header-is-visible
1097 (let ((header-presentation-method
1098 (or (cdr (assq 'header-presentation-method situation))
1099 (cdr (assq (cdr (assq 'major-mode situation))
1100 mime-header-presentation-method-alist)))))
1102 (if header-presentation-method
1103 (funcall header-presentation-method entity situation)
1104 (mime-insert-header entity
1105 mime-view-ignored-field-list
1106 mime-view-visible-field-list))
1107 (mime-add-url-buttons)
1108 (run-hooks 'mime-display-header-hook)
1109 (put-text-property nhb (point-max) 'mime-view-entity-header entity)
1110 (goto-char (point-max))
1115 (let ((body-presentation-method
1116 (cdr (assq 'body-presentation-method situation))))
1117 (if (functionp body-presentation-method)
1118 (funcall body-presentation-method entity situation)
1119 (mime-display-text/plain entity situation)))
1120 (when button-is-invisible
1121 (goto-char (point-max))
1122 (mime-view-insert-entity-button entity))
1123 (unless header-is-visible
1124 (goto-char (point-max))
1126 (setq ne (point-max))
1128 (put-text-property nb ne 'mime-view-entity entity)
1129 (put-text-property nb ne 'mime-view-situation situation)
1130 (put-text-property nbb ne 'mime-view-entity-body entity)
1132 (if (and children body-is-visible)
1133 (let ((body-presentation-method
1134 (cdr (assq 'body-presentation-method situation))))
1135 (if (functionp body-presentation-method)
1136 (funcall body-presentation-method entity situation)
1137 (mime-display-multipart/mixed entity situation)))))))
1140 ;;; @ MIME viewer mode
1143 (defconst mime-view-popup-menu-list
1145 ["Move to upper entity" mime-preview-move-to-upper]
1146 ["Move to previous entity" mime-preview-move-to-previous]
1147 ["Move to next entity" mime-preview-move-to-next]
1148 ["Scroll-down" mime-preview-scroll-down-entity]
1149 ["Scroll-up" mime-preview-scroll-up-entity]
1150 ["Play current entity" mime-preview-play-current-entity]
1151 ["Extract current entity" mime-preview-extract-current-entity]
1152 ["Print current entity" mime-preview-print-current-entity])
1153 "Menu for MIME Viewer")
1155 (defun mime-view-popup-menu (event)
1156 "Popup the menu in the MIME Viewer buffer"
1158 (mime-popup-menu-popup mime-view-popup-menu-list event))
1160 ;;; The current local map is taken precendence over `widget-keymap',
1161 ;;; because GNU Emacs' widget implementation doesn't set `local-map' property.
1162 ;;; So we need to specify derivation.
1163 (defvar widget-keymap)
1164 (defun mime-view-maybe-inherit-widget-keymap ()
1165 (when (boundp 'widget-keymap)
1166 (set-keymap-parent (current-local-map) widget-keymap)))
1168 (add-hook 'mime-view-define-keymap-hook 'mime-view-maybe-inherit-widget-keymap)
1170 (defun mime-view-define-keymap (&optional default)
1171 (let ((mime-view-mode-map (if (keymapp default)
1172 (copy-keymap default)
1173 (make-sparse-keymap))))
1174 (define-key mime-view-mode-map
1175 "u" (function mime-preview-move-to-upper))
1176 (define-key mime-view-mode-map
1177 "p" (function mime-preview-move-to-previous))
1178 (define-key mime-view-mode-map
1179 "n" (function mime-preview-move-to-next))
1180 (define-key mime-view-mode-map
1181 "\e\t" (function mime-preview-move-to-previous))
1182 (define-key mime-view-mode-map
1183 "\t" (function mime-preview-move-to-next))
1184 (define-key mime-view-mode-map
1185 " " (function mime-preview-scroll-up-entity))
1186 (define-key mime-view-mode-map
1187 "\M- " (function mime-preview-scroll-down-entity))
1188 (define-key mime-view-mode-map
1189 "\177" (function mime-preview-scroll-down-entity))
1190 (define-key mime-view-mode-map
1191 "\C-m" (function mime-preview-next-line-entity))
1192 (define-key mime-view-mode-map
1193 "\C-\M-m" (function mime-preview-previous-line-entity))
1194 (define-key mime-view-mode-map
1195 "v" (function mime-preview-play-current-entity))
1196 (define-key mime-view-mode-map
1197 "e" (function mime-preview-extract-current-entity))
1198 (define-key mime-view-mode-map
1199 "\C-c\C-p" (function mime-preview-print-current-entity))
1201 (define-key mime-view-mode-map
1202 "\C-c\C-t\C-f" (function mime-preview-toggle-header))
1203 (define-key mime-view-mode-map
1204 "\C-c\C-th" (function mime-preview-toggle-header))
1205 (define-key mime-view-mode-map
1206 "\C-c\C-t\C-c" (function mime-preview-toggle-content))
1208 (define-key mime-view-mode-map
1209 "\C-c\C-v\C-f" (function mime-preview-show-header))
1210 (define-key mime-view-mode-map
1211 "\C-c\C-vh" (function mime-preview-show-header))
1212 (define-key mime-view-mode-map
1213 "\C-c\C-v\C-c" (function mime-preview-show-content))
1215 (define-key mime-view-mode-map
1216 "\C-c\C-d\C-f" (function mime-preview-hide-header))
1217 (define-key mime-view-mode-map
1218 "\C-c\C-dh" (function mime-preview-hide-header))
1219 (define-key mime-view-mode-map
1220 "\C-c\C-d\C-c" (function mime-preview-hide-content))
1222 (define-key mime-view-mode-map
1223 "a" (function mime-preview-follow-current-entity))
1224 (define-key mime-view-mode-map
1225 "q" (function mime-preview-quit))
1226 (define-key mime-view-mode-map
1227 "\C-c\C-x" (function mime-preview-kill-buffer))
1228 ;; (define-key mime-view-mode-map
1229 ;; "<" (function beginning-of-buffer))
1230 ;; (define-key mime-view-mode-map
1231 ;; ">" (function end-of-buffer))
1232 (define-key mime-view-mode-map
1233 "?" (function describe-mode))
1234 (define-key mime-view-mode-map
1235 [tab] (function mime-preview-move-to-next))
1236 (define-key mime-view-mode-map
1237 [delete] (function mime-preview-scroll-down-entity))
1238 (define-key mime-view-mode-map
1239 [backspace] (function mime-preview-scroll-down-entity))
1240 (if (functionp default)
1241 (if (featurep 'xemacs)
1242 (set-keymap-default-binding mime-view-mode-map default)
1243 (setq mime-view-mode-map
1244 (append mime-view-mode-map (list (cons t default))))))
1245 (define-key mime-view-mode-map
1246 [down-mouse-3] (function mime-view-popup-menu))
1247 ;; (run-hooks 'mime-view-define-keymap-hook)
1248 mime-view-mode-map))
1250 (defvar mime-view-mode-default-map (mime-view-define-keymap))
1253 (defsubst mime-maybe-hide-echo-buffer ()
1254 "Clear mime-echo buffer and delete window for it."
1255 (let ((buf (get-buffer mime-echo-buffer-name)))
1260 (let ((win (get-buffer-window buf)))
1262 (delete-window win)))
1263 (bury-buffer buf)))))
1265 (defvar mime-view-redisplay nil)
1268 (defun mime-display-message (message &optional preview-buffer
1269 mother default-keymap-or-function
1270 original-major-mode keymap)
1271 "View MESSAGE in MIME-View mode.
1273 Optional argument PREVIEW-BUFFER specifies the buffer of the
1274 presentation. It must be either nil or a name of preview buffer.
1276 Optional argument MOTHER specifies mother-buffer of the preview-buffer.
1278 Optional argument DEFAULT-KEYMAP-OR-FUNCTION is nil, keymap or
1279 function. If it is a keymap, keymap of MIME-View mode will be added
1280 to it. If it is a function, it will be bound as default binding of
1281 keymap of MIME-View mode.
1283 Optional argument ORIGINAL-MAJOR-MODE is major-mode of representation
1284 buffer of MESSAGE. If it is nil, current `major-mode' is used.
1286 Optional argument KEYMAP is keymap of MIME-View mode. If it is
1287 non-nil, DEFAULT-KEYMAP-OR-FUNCTION is ignored. If it is nil,
1288 `mime-view-mode-default-map' is used."
1289 (mime-maybe-hide-echo-buffer)
1290 (let ((win-conf (current-window-configuration)))
1292 (setq preview-buffer
1293 (concat "*Preview-" (mime-entity-name message) "*")))
1294 (or original-major-mode
1295 (setq original-major-mode major-mode))
1296 (let ((inhibit-read-only t))
1297 (set-buffer (get-buffer-create preview-buffer))
1301 (setq mime-mother-buffer mother))
1302 (setq mime-preview-original-window-configuration win-conf)
1303 (setq major-mode 'mime-view-mode)
1304 (setq mode-name "MIME-View")
1305 (mime-display-entity message nil
1306 `((entity-button . invisible)
1308 (major-mode . ,original-major-mode))
1312 (if default-keymap-or-function
1313 (mime-view-define-keymap default-keymap-or-function)
1314 mime-view-mode-default-map)))
1316 (next-single-property-change (point-min) 'mime-view-entity)))
1319 (goto-char (point-min))
1320 (search-forward "\n\n" nil t)))
1321 (run-hooks 'mime-view-mode-hook)
1322 (set-buffer-modified-p nil)
1323 (setq buffer-read-only t)
1327 (defun mime-view-buffer (&optional raw-buffer preview-buffer mother
1328 default-keymap-or-function
1329 representation-type)
1330 "View RAW-BUFFER in MIME-View mode.
1331 Optional argument PREVIEW-BUFFER is either nil or a name of preview
1333 Optional argument DEFAULT-KEYMAP-OR-FUNCTION is nil, keymap or
1334 function. If it is a keymap, keymap of MIME-View mode will be added
1335 to it. If it is a function, it will be bound as default binding of
1336 keymap of MIME-View mode.
1337 Optional argument REPRESENTATION-TYPE is representation-type of
1338 message. It must be nil, `binary' or `cooked'. If it is nil,
1339 `cooked' is used as default."
1342 (setq raw-buffer (current-buffer)))
1343 (or representation-type
1344 (setq representation-type
1346 (set-buffer raw-buffer)
1347 (cdr (or (assq major-mode mime-raw-representation-type-alist)
1348 (assq t mime-raw-representation-type-alist))))))
1349 (if (eq representation-type 'binary)
1350 (setq representation-type 'buffer))
1351 (setq preview-buffer (mime-display-message
1352 (mime-open-entity representation-type raw-buffer)
1353 preview-buffer mother default-keymap-or-function))
1354 (or (get-buffer-window preview-buffer)
1355 (let ((r-win (get-buffer-window raw-buffer)))
1357 (set-window-buffer r-win preview-buffer)
1358 (let ((m-win (and mother (get-buffer-window mother))))
1360 (set-window-buffer m-win preview-buffer)
1361 (switch-to-buffer preview-buffer)))))))
1363 (defun mime-view-mode (&optional mother ctl encoding
1364 raw-buffer preview-buffer
1365 default-keymap-or-function)
1366 "Major mode for viewing MIME message.
1368 Here is a list of the standard keys for mime-view-mode.
1373 u Move to upper content
1374 p or M-TAB Move to previous content
1375 n or TAB Move to next content
1376 SPC Scroll up or move to next content
1377 M-SPC or DEL Scroll down or move to previous content
1378 RET Move to next line
1379 M-RET Move to previous line
1380 v Decode current content as `play mode'
1381 e Decode current content as `extract mode'
1382 C-c C-p Decode current content as `print mode'
1383 a Followup to current content.
1385 button-2 Move to point under the mouse cursor
1386 and decode current content as `play mode'
1389 (unless mime-view-redisplay
1391 (if raw-buffer (set-buffer raw-buffer))
1394 (or (assq major-mode mime-raw-representation-type-alist)
1395 (assq t mime-raw-representation-type-alist)))))
1396 (if (eq type 'binary)
1397 (setq type 'buffer))
1398 (setq mime-message-structure (mime-open-entity type raw-buffer))
1399 (or (mime-entity-content-type mime-message-structure)
1400 (mime-entity-set-content-type mime-message-structure ctl)))
1401 (or (mime-entity-encoding mime-message-structure)
1402 (mime-entity-set-encoding mime-message-structure encoding))))
1403 (mime-display-message mime-message-structure preview-buffer
1404 mother default-keymap-or-function))
1410 (defun mime-preview-find-boundary-info (&optional get-mother)
1414 (while (null (setq entity
1415 (get-text-property (point) 'mime-view-entity)))
1417 (setq p-beg (previous-single-property-change (point) 'mime-view-entity))
1418 (setq entity-node-id (mime-entity-node-id entity))
1419 (setq len (length entity-node-id))
1422 (if (eq (next-single-property-change (point-min)
1427 ((eq (next-single-property-change p-beg 'mime-view-entity)
1429 (setq p-beg (point))))
1430 (setq p-end (next-single-property-change p-beg 'mime-view-entity))
1432 (setq p-end (point-max)))
1433 ((null entity-node-id)
1434 (setq p-end (point-max)))
1441 (next-single-property-change
1442 (point) 'mime-view-entity))
1444 (let ((rc (mime-entity-node-id
1445 (get-text-property (1- (point))
1446 'mime-view-entity))))
1447 (or (and (>= (setq i (- (length rc) len)) 0)
1448 (equal entity-node-id (nthcdr i rc)))
1451 (setq p-end (point-max))))))
1452 (vector p-beg p-end entity)))
1458 (autoload 'mime-preview-play-current-entity "mime-play"
1459 "Play current entity." t)
1461 (defun mime-preview-extract-current-entity (&optional ignore-examples)
1462 "Extract current entity into file (maybe).
1463 It decodes current entity to call internal or external method as
1464 \"extract\" mode. The method is selected from variable
1465 `mime-acting-condition'."
1467 (mime-preview-play-current-entity ignore-examples "extract"))
1469 (defun mime-preview-print-current-entity (&optional ignore-examples)
1470 "Print current entity (maybe).
1471 It decodes current entity to call internal or external method as
1472 \"print\" mode. The method is selected from variable
1473 `mime-acting-condition'."
1475 (mime-preview-play-current-entity ignore-examples "print"))
1481 (defun mime-preview-follow-current-entity ()
1482 "Write follow message to current entity.
1483 It calls following-method selected from variable
1484 `mime-preview-following-method-alist'."
1486 (let ((entity (mime-preview-find-boundary-info t))
1489 (setq p-beg (aref entity 0)
1490 p-end (aref entity 1)
1491 entity (aref entity 2))
1492 (if (get-text-property p-beg 'mime-view-entity-body)
1495 (next-single-property-change
1496 p-beg 'mime-view-entity-body nil
1497 (or (next-single-property-change p-beg 'mime-view-entity)
1499 (let* ((mode (mime-preview-original-major-mode 'recursive))
1500 (entity-node-id (mime-entity-node-id entity))
1502 (format "%s-%s" (buffer-name) (reverse entity-node-id)))
1504 (the-buf (current-buffer))
1507 (set-buffer (setq new-buf (get-buffer-create new-name)))
1510 (insert-buffer-substring the-buf pb-beg p-end)
1511 (goto-char (point-min))
1512 (let ((current-entity
1513 (if (and (eq (mime-entity-media-type entity) 'message)
1514 (eq (mime-entity-media-subtype entity) 'rfc822))
1515 (car (mime-entity-children entity))
1517 (while (and current-entity
1518 (if (and (eq (mime-entity-media-type
1519 current-entity) 'message)
1520 (eq (mime-entity-media-subtype
1521 current-entity) 'rfc822))
1523 (mime-insert-header current-entity fields)
1525 (setq fields (std11-collect-field-names)
1526 current-entity (mime-entity-parent current-entity))))
1527 (let ((rest mime-view-following-required-fields-list)
1530 (setq field-name (car rest))
1531 (or (std11-field-body field-name)
1534 (set-buffer the-buf)
1535 (let ((entity (when mime-mother-buffer
1536 (set-buffer mime-mother-buffer)
1537 (get-text-property (point)
1538 'mime-view-entity))))
1540 (null (setq ret (mime-entity-fetch-field
1541 entity field-name))))
1542 (setq entity (mime-entity-parent entity)))))
1544 (insert (concat field-name ": " ret "\n")))))
1545 (setq rest (cdr rest)))))
1546 (let ((f (cdr (assq mode mime-preview-following-method-alist))))
1551 "Sorry, following method for %s is not implemented yet."
1558 (defun mime-preview-move-to-upper ()
1559 "Move to upper entity.
1560 If there is no upper entity, call function `mime-preview-quit'."
1563 (while (null (setq cinfo
1564 (get-text-property (point) 'mime-view-entity)))
1566 (let ((r (mime-entity-parent cinfo))
1569 (while (setq point (previous-single-property-change
1570 (point) 'mime-view-entity))
1572 (when (eq r (get-text-property (point) 'mime-view-entity))
1573 (if (or (eq mime-preview-move-scroll t)
1574 (and mime-preview-move-scroll
1577 (move-to-window-line -1)
1578 (forward-line (* -1 next-screen-context-lines))
1581 (recenter next-screen-context-lines))
1583 (mime-preview-quit)))))
1585 (defun mime-preview-move-to-previous ()
1586 "Move to previous entity.
1587 If there is no previous entity, it calls function registered in
1588 variable `mime-preview-over-to-previous-method-alist'."
1590 (while (and (not (bobp))
1591 (null (get-text-property (point) 'mime-view-entity)))
1593 (let ((point (previous-single-property-change (point) 'mime-view-entity)))
1595 (>= point (point-min)))
1596 (if (get-text-property (1- point) 'mime-view-entity)
1597 (progn (goto-char point)
1599 (or (eq mime-preview-move-scroll t)
1600 (and mime-preview-move-scroll
1603 (move-to-window-line 0)
1604 (forward-line next-screen-context-lines)
1607 (recenter (* -1 next-screen-context-lines))))
1608 (goto-char (1- point))
1609 (mime-preview-move-to-previous))
1610 (let ((f (assq (mime-preview-original-major-mode)
1611 mime-preview-over-to-previous-method-alist)))
1613 (funcall (cdr f)))))))
1615 (defun mime-preview-move-to-next ()
1616 "Move to next entity.
1617 If there is no previous entity, it calls function registered in
1618 variable `mime-preview-over-to-next-method-alist'."
1620 (while (and (not (eobp))
1621 (null (get-text-property (point) 'mime-view-entity)))
1623 (let ((point (next-single-property-change (point) 'mime-view-entity)))
1625 (<= point (point-max)))
1628 (if (null (get-text-property point 'mime-view-entity))
1629 (mime-preview-move-to-next)
1631 (or (eq mime-preview-move-scroll t)
1632 (and mime-preview-move-scroll
1635 (move-to-window-line -1)
1637 (* -1 next-screen-context-lines))
1640 (recenter next-screen-context-lines))))
1641 (let ((f (assq (mime-preview-original-major-mode)
1642 mime-preview-over-to-next-method-alist)))
1644 (funcall (cdr f)))))))
1646 (defun mime-preview-scroll-up-entity (&optional h)
1647 "Scroll up current entity.
1648 If reached to (point-max), it calls function registered in variable
1649 `mime-preview-over-to-next-method-alist'."
1652 (let ((f (assq (mime-preview-original-major-mode)
1653 mime-preview-over-to-next-method-alist)))
1657 (or (next-single-property-change (point) 'mime-view-entity)
1659 (bottom (window-end (selected-window))))
1662 (progn (goto-char point)
1663 (recenter next-screen-context-lines))
1667 (goto-char (point-max))))))))
1669 (defun mime-preview-scroll-down-entity (&optional h)
1670 "Scroll down current entity.
1671 If reached to (point-min), it calls function registered in variable
1672 `mime-preview-over-to-previous-method-alist'."
1675 (let ((f (assq (mime-preview-original-major-mode)
1676 mime-preview-over-to-previous-method-alist)))
1680 (or (previous-single-property-change (point) 'mime-view-entity)
1682 (top (window-start (selected-window))))
1685 (progn (goto-char point)
1686 (recenter (* -1 next-screen-context-lines)))
1689 (beginning-of-buffer
1690 (goto-char (point-min))))))))
1692 (defun mime-preview-next-line-entity (&optional lines)
1693 "Scroll up one line (or prefix LINES lines).
1694 If LINES is negative, scroll down LINES lines."
1696 (mime-preview-scroll-up-entity (or lines 1)))
1698 (defun mime-preview-previous-line-entity (&optional lines)
1699 "Scrroll down one line (or prefix LINES lines).
1700 If LINES is negative, scroll up LINES lines."
1702 (mime-preview-scroll-down-entity (or lines 1)))
1708 (defun mime-preview-toggle-display (type &optional display)
1709 (let ((situation (mime-preview-find-boundary-info))
1710 (sym (intern (concat "*" (symbol-name type))))
1712 (setq p-beg (aref situation 0)
1713 p-end (aref situation 1)
1714 entity (aref situation 2)
1715 situation (get-text-property p-beg 'mime-view-situation))
1716 (cond ((eq display 'invisible)
1721 (memq (cdr (or (assq sym situation)
1722 (assq type situation)))
1723 '(nil invisible)))))
1724 (setq situation (put-alist sym (if display
1729 (let ((inhibit-read-only t))
1730 (delete-region p-beg p-end)
1731 (mime-display-entity entity situation)))
1732 (let ((ret (assoc situation mime-preview-situation-example-list)))
1734 (setcdr ret (1+ (cdr ret)))
1735 (add-to-list 'mime-preview-situation-example-list
1736 (cons situation 0))))))
1738 (defun mime-preview-toggle-header (&optional force-visible)
1740 (mime-preview-toggle-display 'header force-visible))
1742 (defun mime-preview-toggle-content (&optional force-visible)
1744 (mime-preview-toggle-display 'body force-visible))
1746 (defun mime-preview-show-header ()
1748 (mime-preview-toggle-display 'header 'visible))
1750 (defun mime-preview-show-content ()
1752 (mime-preview-toggle-display 'body 'visible))
1754 (defun mime-preview-hide-header ()
1756 (mime-preview-toggle-display 'header 'invisible))
1758 (defun mime-preview-hide-content ()
1760 (mime-preview-toggle-display 'body 'invisible))
1766 (defun mime-preview-quit ()
1767 "Quit from MIME-preview buffer.
1768 It calls function registered in variable
1769 `mime-preview-quitting-method-alist'."
1771 (let ((r (assq (mime-preview-original-major-mode)
1772 mime-preview-quitting-method-alist)))
1774 (funcall (cdr r)))))
1776 (defun mime-preview-kill-buffer ()
1778 (kill-buffer (current-buffer)))
1784 (provide 'mime-view)
1787 (setq mime-situation-examples-file nil)
1788 ;; to avoid to read situation-examples-file at compile time.
1791 (mime-view-read-situation-examples-file)
1793 ;;; mime-view.el ends here