1 ;;; mime-view.el --- interactive MIME viewer for GNU Emacs
3 ;; Copyright (C) 1995,1996,1997,1998,1999 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
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.
41 (defconst mime-view-version
42 (concat (mime-product-name mime-user-interface-product) " MIME-View "
43 (mapconcat #'number-to-string
44 (mime-product-version mime-user-interface-product) ".")
45 " (" (mime-product-code-name mime-user-interface-product) ")"))
51 (defgroup mime-view nil
55 (defcustom mime-view-find-every-acting-situation t
56 "*Find every available acting-situation if non-nil."
60 (defcustom mime-acting-situation-examples-file "~/.mime-example"
61 "*File name of example about acting-situation demonstrated by user."
65 (defcustom mime-preview-move-scroll nil
66 "*Decides whether to scroll when moving to next entity.
67 When t, scroll the buffer. Non-nil but not t means scroll when
68 the next entity is within `next-screen-context-lines' from top or
69 buttom. Nil means don't scroll at all."
71 :type '(choice (const :tag "Off" nil)
73 (sexp :tag "Situation" 1)))
75 (defcustom mime-preview-scroll-full-screen nil
76 "*When non-nil, always scroll full screen.
77 If nil, point will be moved to the next entity if exists."
79 :type '(choice (const :tag "On" t)
80 (const :tag "Off" nil)))
82 (defcustom mime-view-force-inline-types '(text multipart)
83 "*List of MIME types that \"attachment\" should be ignored.
84 The element can be type or type/subtype. When t, inline everything
87 :type '(choice (const :tag "Nothing" nil)
89 (list (repeat symbol))))
91 (defcustom mime-view-button-place-alist
93 (application . before)
94 (multipart/alternative . around))
95 "*Alist of MIME type or type/subtype vs. button place.
96 When around, button will be inserted before and after that part.
97 When after or before, button will be inserted that place.
98 If not specified, that type will not have button."
100 :type '(choice (const :tag "Nothing" nil)
101 (list (repeat symbol))))
104 (defcustom mime-view-type-subtype-score-alist
105 '(((text . enriched) . 3)
106 ((text . richtext) . 2)
109 "Alist MEDIA-TYPE vs corresponding score.
110 MEDIA-TYPE must be (TYPE . SUBTYPE), TYPE or t. t means default."
112 :type '(repeat (cons (choice :tag "Media-Type"
113 (cons :tag "Type/Subtype"
114 (symbol :tag "Primary-type")
115 (symbol :tag "Subtype"))
117 (const :tag "Default" t))
120 ;;; @ in raw-buffer (representation space)
123 (defvar mime-preview-buffer nil
124 "MIME-preview buffer corresponding with the (raw) buffer.")
125 (make-variable-buffer-local 'mime-preview-buffer)
128 (defvar mime-raw-representation-type-alist
129 '((mime-show-message-mode . binary)
130 (mime-temp-message-mode . binary)
132 "Alist of `major-mode' vs. representation-type of mime-raw-buffer.
133 Each element looks like (SYMBOL . REPRESENTATION-TYPE). SYMBOL is
134 `major-mode' or t. t means default. REPRESENTATION-TYPE must be
135 `binary' or `cooked'.")
138 ;; (defun mime-raw-find-entity-from-point (point &optional message-info)
139 ;; "Return entity from POINT in mime-raw-buffer.
140 ;; If optional argument MESSAGE-INFO is not specified,
141 ;; `mime-message-structure' is used."
143 ;; (setq message-info mime-message-structure))
144 ;; (if (and (<= (mime-entity-point-min message-info) point)
145 ;; (<= point (mime-entity-point-max message-info)))
146 ;; (let ((children (mime-entity-children message-info)))
150 ;; (mime-raw-find-entity-from-point point (car children))))
154 ;; (setq children (cdr children)))
156 ;; (make-obsolete 'mime-raw-find-entity-from-point "don't use it.")
159 ;;; @ in preview-buffer (presentation space)
162 (defvar mime-mother-buffer nil
163 "Mother buffer corresponding with the (MIME-preview) buffer.
164 If current MIME-preview buffer is generated by other buffer, such as
165 message/partial, it is called `mother-buffer'.")
166 (make-variable-buffer-local 'mime-mother-buffer)
168 ;; (defvar mime-raw-buffer nil
169 ;; "Raw buffer corresponding with the (MIME-preview) buffer.")
170 ;; (make-variable-buffer-local 'mime-raw-buffer)
172 (defvar mime-preview-original-window-configuration nil
173 "Window-configuration before `mime-view-mode' is called.")
174 (make-variable-buffer-local 'mime-preview-original-window-configuration)
176 (defun mime-preview-original-major-mode (&optional recursive point)
177 "Return major-mode of original buffer.
178 If optional argument RECURSIVE is non-nil and current buffer has
179 mime-mother-buffer, it returns original major-mode of the
181 (if (and recursive mime-mother-buffer)
183 (set-buffer mime-mother-buffer)
184 (mime-preview-original-major-mode recursive))
185 (cdr (assq 'major-mode
186 (get-text-property (or point
187 (if (> (point) (buffer-size))
188 (max (1- (point-max)) (point-min))
190 'mime-view-situation)))))
193 ;;; @ entity information
196 (defun mime-entity-situation (entity &optional situation)
197 "Return situation of ENTITY."
198 (let (rest param name)
200 (unless (assq 'type situation)
201 (setq rest (or (mime-entity-content-type entity)
202 (make-mime-content-type 'text 'plain))
203 situation (cons (car rest) situation)
205 (unless (assq 'subtype situation)
207 (setq rest (or (cdr (mime-entity-content-type entity))
208 '((subtype . plain)))))
209 (setq situation (cons (car rest) situation)
212 (setq param (car rest))
213 (or (assoc (car param) situation)
214 (setq situation (cons param situation)))
215 (setq rest (cdr rest)))
217 ;; Content-Disposition
219 (unless (assq 'disposition-type situation)
220 (setq rest (mime-entity-content-disposition entity))
222 (setq situation (cons (cons 'disposition-type
223 (mime-content-disposition-type rest))
225 rest (mime-content-disposition-parameters rest))))
227 (setq param (car rest)
229 (if (cond ((string= name "filename")
230 (if (assq 'filename situation)
232 (setq name 'filename)))
233 ((string= name "creation-date")
234 (if (assq 'creation-date situation)
236 (setq name 'creation-date)))
237 ((string= name "modification-date")
238 (if (assq 'modification-date situation)
240 (setq name 'modification-date)))
241 ((string= name "read-date")
242 (if (assq 'read-date situation)
244 (setq name 'read-date)))
245 ((string= name "size")
246 (if (assq 'size situation)
249 (t (setq name (cons 'disposition name))
250 (if (assoc name situation)
254 (cons (cons name (cdr param))
256 (setq rest (cdr rest)))
258 ;; Content-Transfer-Encoding
259 (or (assq 'encoding situation)
261 (cons (cons 'encoding (or (mime-entity-encoding entity)
267 (defun mime-view-entity-title (entity)
268 (or (mime-entity-read-field entity 'Content-Description)
269 (mime-entity-read-field entity 'Subject)
270 (mime-entity-filename entity)
274 ;; (defsubst mime-raw-point-to-entity-node-id (point &optional message-info)
275 ;; "Return entity-node-id from POINT in mime-raw-buffer.
276 ;; If optional argument MESSAGE-INFO is not specified,
277 ;; `mime-message-structure' is used."
278 ;; (mime-entity-node-id (mime-raw-find-entity-from-point point message-info)))
280 ;; (make-obsolete 'mime-raw-point-to-entity-node-id "don't use it.")
282 ;; (defsubst mime-raw-point-to-entity-number (point &optional message-info)
283 ;; "Return entity-number from POINT in mime-raw-buffer.
284 ;; If optional argument MESSAGE-INFO is not specified,
285 ;; `mime-message-structure' is used."
286 ;; (mime-entity-number (mime-raw-find-entity-from-point point message-info)))
288 ;; (make-obsolete 'mime-raw-point-to-entity-number "don't use it.")
290 ;; (defun mime-raw-flatten-message-info (&optional message-info)
291 ;; "Return list of entity in mime-raw-buffer.
292 ;; If optional argument MESSAGE-INFO is not specified,
293 ;; `mime-message-structure' is used."
295 ;; (setq message-info mime-message-structure))
296 ;; (let ((dest (list message-info))
297 ;; (rcl (mime-entity-children message-info)))
299 ;; (setq dest (nconc dest (mime-raw-flatten-message-info (car rcl))))
300 ;; (setq rcl (cdr rcl)))
303 (defmacro mime-view-header-is-visible (situation)
304 `(eq (cdr (or (assq '*header ,situation)
305 (assq 'header ,situation)))
308 (defmacro mime-view-body-is-visible (situation)
309 `(eq (cdr (or (assq '*body ,situation)
310 (assq 'body ,situation)))
313 (defmacro mime-view-children-is-invisible (situation)
314 `(eq (cdr (or (assq '*children ,situation)
315 (assq 'children ,situation)))
318 (defmacro mime-view-button-is-visible (situation)
320 `(or (eq (or (cdr (assq '*entity-button ,situation))
321 (cdr (assq 'entity-button ,situation)))
323 (and (not (eq (or (cdr (assq '*entity-button ,situation))
324 (cdr (assq 'entity-button ,situation)))
326 (mime-view-entity-button-visible-p entity))))
328 ;;; @ presentation of preview
334 ;;; @@@ predicate function
338 (defun mime-view-entity-type/subtype (entity)
339 (if (not (mime-entity-media-type entity))
341 (intern (format "%s/%s"
342 (mime-entity-media-type entity)
343 (mime-entity-media-subtype entity)))))
345 (defun mime-view-entity-button-visible-p (entity)
346 "Return non-nil if header of ENTITY is visible.
347 You can customize the visibility by changing `mime-view-button-place-alist'."
349 ;; Check current entity
351 (memq (cdr (assq (mime-view-entity-type/subtype entity)
352 mime-view-button-place-alist))
355 (memq (cdr (assq (mime-entity-media-type entity)
356 mime-view-button-place-alist))
358 (and (mime-entity-parent entity)
361 (reverse (mime-entity-children
362 (mime-entity-parent entity)))))))
363 ;; When previous entity exists
366 ;; Check previous entity
370 (mime-view-entity-type/subtype prev-entity)
371 mime-view-button-place-alist))
376 (mime-entity-media-type prev-entity)
377 mime-view-button-place-alist))
379 ;; default for everything.
381 mime-view-button-place-alist))
384 ;;; @@@ entity button generator
387 (defun mime-view-insert-entity-button (entity &optional body-is-invisible)
388 "Insert entity-button of ENTITY."
389 (let ((entity-node-id (mime-entity-node-id entity))
390 (params (mime-entity-parameters entity))
391 (subject (mime-view-entity-title entity)))
394 (let ((access-type (assoc "access-type" params))
395 (num (or (cdr (assoc "x-part-number" params))
396 (if (consp entity-node-id)
399 (format "%s" (1+ num))))
400 (reverse entity-node-id) ".")
403 (let ((server (assoc "server" params)))
404 (setq access-type (cdr access-type))
406 (format "%s %s ([%s] %s)"
407 num subject access-type (cdr server))
408 (let ((site (cdr (assoc "site" params)))
409 (dir (cdr (assoc "directory" params)))
410 (url (cdr (assoc "url" params))))
412 (format "%s %s ([%s] %s)"
413 num subject access-type url)
414 (format "%s %s ([%s] %s:%s)"
415 num subject access-type site dir))))))
417 (let ((media-type (mime-entity-media-type entity))
418 (media-subtype (mime-entity-media-subtype entity))
419 (charset (cdr (assoc "charset" params)))
420 (encoding (mime-entity-encoding entity)))
424 (format " <%s/%s%s%s>"
425 media-type media-subtype
427 (concat "; " charset)
430 (concat " (" encoding ")")
432 (if (>= (+ (current-column)(length rest))(window-width))
435 (if body-is-invisible
438 (function mime-preview-play-current-entity)
439 (if body-is-invisible
446 (defvar mime-header-presentation-method-alist nil
447 "Alist of major mode vs. corresponding header-presentation-method functions.
448 Each element looks like (SYMBOL . FUNCTION).
449 SYMBOL must be major mode in raw-buffer or t. t means default.
450 Interface of FUNCTION must be (ENTITY SITUATION).")
452 (defvar mime-view-ignored-field-list
453 '(".*Received:" ".*Path:" ".*Id:" "^References:"
454 "^Replied:" "^Errors-To:"
455 "^Lines:" "^Sender:" ".*Host:" "^Xref:"
456 "^Content-Type:" "^Precedence:"
457 "^Status:" "^X-VM-.*:")
458 "All fields that match this list will be hidden in MIME preview buffer.
459 Each elements are regexp of field-name.")
461 (defvar mime-view-visible-field-list '("^Dnas.*:" "^Message-Id:")
462 "All fields that match this list will be displayed in MIME preview buffer.
463 Each elements are regexp of field-name.")
469 ;;; @@@ predicate function
472 (in-calist-package 'mime-view)
474 (defun mime-calist::field-match-method-as-default-rule (calist
475 field-type field-value)
476 (let ((s-field (assq field-type calist)))
477 (cond ((null s-field)
478 (cons (cons field-type field-value) calist))
481 (define-calist-field-match-method
482 'header #'mime-calist::field-match-method-as-default-rule)
484 (define-calist-field-match-method
485 'body #'mime-calist::field-match-method-as-default-rule)
488 (defvar mime-preview-condition nil
489 "Condition-tree about how to display entity.")
491 ;;(ctree-set-calist-strictly
492 ;; 'mime-preview-condition '((type . application)(subtype . octet-stream)
494 ;; (body . visible)))
496 (ctree-set-calist-strictly
497 'mime-preview-condition '((type . application)(subtype . t)
500 (ctree-set-calist-strictly
501 'mime-preview-condition '((type . application)(subtype . t)
505 (ctree-set-calist-strictly
506 'mime-preview-condition '((type . application)(subtype . pgp)
509 (ctree-set-calist-strictly
510 'mime-preview-condition '((type . application)(subtype . x-latex)
513 (ctree-set-calist-strictly
514 'mime-preview-condition '((type . application)(subtype . x-selection)
517 (ctree-set-calist-strictly
518 'mime-preview-condition '((type . application)(subtype . x-comment)
521 (ctree-set-calist-strictly
522 'mime-preview-condition '((type . message)(subtype . delivery-status)
525 (ctree-set-calist-strictly
526 'mime-preview-condition
528 (body-presentation-method . mime-display-text/plain)))
530 (ctree-set-calist-strictly
531 'mime-preview-condition
534 (body-presentation-method . mime-display-text/plain)))
536 (ctree-set-calist-strictly
537 'mime-preview-condition
538 '((type . text)(subtype . enriched)
540 (body-presentation-method . mime-display-text/enriched)))
542 (ctree-set-calist-strictly
543 'mime-preview-condition
544 '((type . text)(subtype . richtext)
546 (body-presentation-method . mime-display-text/richtext)))
548 (ctree-set-calist-strictly
549 'mime-preview-condition
550 '((type . application)(subtype . x-postpet)
552 (body-presentation-method . mime-display-application/x-postpet)))
554 (ctree-set-calist-strictly
555 'mime-preview-condition '((type . application)(subtype . t)
558 (body-presentation-method . mime-display-detect-application/octet-stream)))
560 (ctree-set-calist-strictly
561 'mime-preview-condition
562 '((type . text)(subtype . t)
564 (body-presentation-method . mime-display-text/plain)))
566 (ctree-set-calist-strictly
567 'mime-preview-condition
568 '((type . text)(subtype . x-rot13-47-48)
570 (body-presentation-method . mime-display-text/x-rot13-47-48)))
572 (ctree-set-calist-strictly
573 'mime-preview-condition
574 '((type . multipart)(subtype . alternative)
576 (body-presentation-method . mime-display-multipart/alternative)))
578 (ctree-set-calist-strictly
579 'mime-preview-condition
580 '((type . multipart)(subtype . t)
582 (body-presentation-method . mime-display-multipart/mixed)))
584 (ctree-set-calist-strictly
585 'mime-preview-condition
586 '((type . message)(subtype . partial)
588 (body-presentation-method . mime-display-message/partial-button)))
590 (ctree-set-calist-strictly
591 'mime-preview-condition
592 '((type . message)(subtype . rfc822)
594 (body-presentation-method . mime-display-multipart/mixed)
595 (childrens-situation (header . visible)
596 (entity-button . invisible))))
598 (ctree-set-calist-strictly
599 'mime-preview-condition
600 '((type . message)(subtype . news)
602 (body-presentation-method . mime-display-multipart/mixed)
603 (childrens-situation (header . visible)
604 (entity-button . invisible))))
606 ;; message/external-body has only one child.
607 (ctree-set-calist-strictly
608 'mime-preview-condition
609 '((type . message)(subtype . external-body)
611 (body-presentation-method . nil)
612 (childrens-situation (header . invisible)
614 (entity-button . visible))))
617 ;;; @@@ entity presentation
620 (defun mime-display-text/plain (entity situation)
622 (narrow-to-region (point-max)(point-max))
623 (mime-insert-text-content entity)
624 (run-hooks 'mime-text-decode-hook)
625 (goto-char (point-max))
626 (if (not (eq (char-after (1- (point))) ?\n))
628 (mime-add-url-buttons)
629 (run-hooks 'mime-display-text/plain-hook)))
631 (defun mime-display-text/richtext (entity situation)
633 (narrow-to-region (point-max)(point-max))
634 (mime-insert-text-content entity)
635 (run-hooks 'mime-text-decode-hook)
636 (let ((beg (point-min)))
637 (remove-text-properties beg (point-max) '(face nil))
638 (richtext-decode beg (point-max)))))
640 (defun mime-display-text/enriched (entity situation)
642 (narrow-to-region (point-max)(point-max))
643 (mime-insert-text-content entity)
644 (run-hooks 'mime-text-decode-hook)
645 (let ((beg (point-min)))
646 (remove-text-properties beg (point-max) '(face nil))
647 (enriched-decode beg (point-max)))))
649 (defun mime-display-text/x-rot13-47-48 (entity situation)
651 (narrow-to-region (point-max)(point-max))
652 (mime-insert-text-content entity)
653 (goto-char (point-max))
654 (if (not (eq (char-after (1- (point))) ?\n))
656 (mule-caesar-region (point-min) (point-max))
657 (mime-add-url-buttons)))
659 (put 'unpack 'lisp-indent-function 1)
660 (defmacro unpack (string &rest body)
661 `(let* ((*unpack*string* (string-as-unibyte ,string))
665 (defun unpack-skip (len)
666 (setq *unpack*index* (+ len *unpack*index*)))
668 (defun unpack-fixed (len)
670 (substring *unpack*string* *unpack*index* (+ *unpack*index* len))
673 (defun unpack-byte ()
674 (char-int (aref (unpack-fixed 1) 0)))
676 (defun unpack-short ()
677 (let* ((b0 (unpack-byte))
681 (defun unpack-long ()
682 (let* ((s0 (unpack-short))
684 (+ (* 65536 s0) s1)))
686 (defun unpack-string ()
687 (let ((len (unpack-byte)))
690 (defun unpack-string-sjis ()
691 (decode-mime-charset-string (unpack-string) 'shift_jis))
693 (defun postpet-decode (string)
698 (set-alist 'res 'carryingcount (unpack-long))
700 (set-alist 'res 'sentyear (unpack-short))
701 (set-alist 'res 'sentmonth (unpack-short))
702 (set-alist 'res 'sentday (unpack-short))
704 (set-alist 'res 'petname (unpack-string-sjis))
705 (set-alist 'res 'owner (unpack-string-sjis))
706 (set-alist 'res 'pettype (unpack-fixed 4))
707 (set-alist 'res 'health (unpack-short))
709 (set-alist 'res 'sex (unpack-long))
711 (set-alist 'res 'brain (unpack-byte))
713 (set-alist 'res 'happiness (unpack-byte))
715 (set-alist 'res 'petbirthyear (unpack-short))
716 (set-alist 'res 'petbirthmonth (unpack-short))
717 (set-alist 'res 'petbirthday (unpack-short))
719 (set-alist 'res 'from (unpack-string))
726 (set-alist 'res 'treasure (unpack-short))
727 (set-alist 'res 'money (unpack-long))
731 (defun mime-display-application/x-postpet (entity situation)
733 (narrow-to-region (point-max)(point-max))
734 (let ((pet (postpet-decode (mime-entity-content entity))))
736 (insert "Petname: " (cdr (assq 'petname pet)) "\n"
737 "Owner: " (cdr (assq 'owner pet)) "\n"
738 "Pettype: " (cdr (assq 'pettype pet)) "\n"
739 "From: " (cdr (assq 'from pet)) "\n"
740 "CarryingCount: " (int-to-string (cdr (assq 'carryingcount pet))) "\n"
741 "SentYear: " (int-to-string (cdr (assq 'sentyear pet))) "\n"
742 "SentMonth: " (int-to-string (cdr (assq 'sentmonth pet))) "\n"
743 "SentDay: " (int-to-string (cdr (assq 'sentday pet))) "\n"
744 "PetbirthYear: " (int-to-string (cdr (assq 'petbirthyear pet))) "\n"
745 "PetbirthMonth: " (int-to-string (cdr (assq 'petbirthmonth pet))) "\n"
746 "PetbirthDay: " (int-to-string (cdr (assq 'petbirthday pet))) "\n"
747 "Health: " (int-to-string (cdr (assq 'health pet))) "\n"
748 "Sex: " (int-to-string (cdr (assq 'sex pet))) "\n"
749 "Brain: " (int-to-string (cdr (assq 'brain pet))) "\n"
750 "Happiness: " (int-to-string (cdr (assq 'happiness pet))) "\n"
751 "Treasure: " (int-to-string (cdr (assq 'treasure pet))) "\n"
752 "Money: " (int-to-string (cdr (assq 'money pet))) "\n")
753 (insert "Invalid format\n"))
754 (run-hooks 'mime-display-application/x-postpet-hook))))
757 (defvar mime-view-announcement-for-message/partial
758 (if (and (>= emacs-major-version 19) window-system)
760 \[[ This is message/partial style split message. ]]
761 \[[ Please press `v' key in this buffer ]]
762 \[[ or click here by mouse button-2. ]]"
764 \[[ This is message/partial style split message. ]]
765 \[[ Please press `v' key in this buffer. ]]"))
767 (defun mime-display-message/partial-button (&optional entity situation)
769 (goto-char (point-max))
770 (if (not (search-backward "\n\n" nil t))
772 (goto-char (point-max))
773 (narrow-to-region (point-max)(point-max))
774 (insert mime-view-announcement-for-message/partial)
775 (mime-add-button (point-min)(point-max)
776 #'mime-preview-play-current-entity)))
778 (defun mime-display-multipart/mixed (entity situation)
779 (let ((children (mime-entity-children entity))
780 (original-major-mode-cell (assq 'major-mode situation))
782 (cdr (assq 'childrens-situation situation))))
783 (if original-major-mode-cell
784 (setq default-situation
785 (cons original-major-mode-cell default-situation)))
787 (mime-display-entity (car children) nil default-situation)
788 (setq children (cdr children)))))
790 (defun mime-display-multipart/alternative (entity situation)
791 (let* ((children (mime-entity-children entity))
792 (original-major-mode-cell (assq 'major-mode situation))
794 (cdr (assq 'childrens-situation situation)))
799 (if original-major-mode-cell
800 (setq default-situation
801 (cons original-major-mode-cell default-situation)))
806 (or (ctree-match-calist
807 mime-preview-condition
808 (append (mime-entity-situation child)
811 (if (cdr (assq 'body-presentation-method situation))
816 (cdr (assq 'type situation))
817 (cdr (assq 'subtype situation)))
818 mime-view-type-subtype-score-alist)
820 (cdr (assq 'type situation))
821 mime-view-type-subtype-score-alist)
824 mime-view-type-subtype-score-alist)))))
825 (if (> score max-score)
833 (let ((child (car children))
834 (situation (car situations)))
835 (mime-display-entity child (if (= i p)
837 (del-alist 'body-presentation-method
838 (copy-alist situation)))))
839 (setq children (cdr children)
840 situations (cdr situations)
843 (defun mime-display-detect-application/octet-stream (entity situation)
844 "Detect unknown ENTITY and display it inline.
845 This can only handle gzipped contents."
846 (or (and (mime-entity-filename entity)
847 (string-match "\\.gz$" (mime-entity-filename entity))
848 (mime-display-gzipped entity situation))
849 (mime-display-text/plain entity situation)))
851 (defun mime-display-gzipped (entity situation)
852 "Ungzip gzipped part and display."
855 (insert (mime-entity-content entity))
857 (call-process-region (point-min) (point-max) "gzip" t t
859 (buffer-string (point-min) (point-max))))
862 (defun mime-preview-inline ()
863 "View part as text without code conversion."
865 (let ((inhibit-read-only t)
866 (entity (get-text-property (point) 'mime-view-entity))
867 (situation (get-text-property (point) 'mime-view-situation))
870 (not (get-text-property (point) 'mime-view-entity-header))
871 (not (memq (mime-entity-media-type entity)
872 '(multipart message))))
873 (setq start (or (and (not (mime-entity-parent entity))
874 (1+ (previous-single-property-change
876 'mime-view-entity-header)))
877 (and (not (eq (point) (point-min)))
878 (not (eq (get-text-property (1- (point))
882 (previous-single-property-change (point)
887 (or (next-single-property-change (point)
891 (if (mime-view-entity-button-visible-p entity)
892 (mime-view-insert-entity-button entity))
893 (insert (mime-entity-content entity))
894 (if (and (bolp) (eolp))
897 (add-text-properties start (point)
898 (list 'mime-view-entity entity
899 'mime-view-situation situation))
902 (defun mime-preview-text (&optional ask-coding)
903 "View part as text. MIME charset will be guessed automatically.
904 With prefix, it prompts for coding-system."
906 (let ((inhibit-read-only t)
907 (entity (get-text-property (point) 'mime-view-entity))
908 (situation (get-text-property (point) 'mime-view-situation))
909 (coding (if ask-coding
910 (or (read-coding-system "Coding system: ")
915 (not (get-text-property (point) 'mime-view-entity-header))
916 (not (memq (mime-entity-media-type entity)
917 '(multipart message))))
918 (setq start (or (and (not (mime-entity-parent entity))
919 (1+ (previous-single-property-change
921 'mime-view-entity-header)))
922 (and (not (eq (point) (point-min)))
923 (not (eq (get-text-property (1- (point))
927 (previous-single-property-change (point)
932 (or (next-single-property-change (point)
936 (if (mime-view-entity-button-visible-p entity)
937 (mime-view-insert-entity-button entity))
938 (insert (decode-coding-string (mime-entity-content entity) coding))
939 (if (and (bolp) (eolp))
942 (add-text-properties start (point)
943 (list 'mime-view-entity entity
944 'mime-view-situation situation))
948 (defun mime-preview-type ()
949 "View part as text without code conversion."
951 (mime-preview-toggle-content t))
953 (defun mime-preview-buttonize ()
956 (goto-char (point-min))
958 (while (setq point (next-single-property-change
959 (point) 'mime-view-entity))
961 (unless (get-text-property (point) 'mime-button-callback)
962 (mime-preview-toggle-button))))))
964 (defun mime-preview-unbuttonize ()
967 (goto-char (point-min))
969 (while (setq point (next-single-property-change
970 (point) 'mime-view-entity))
972 (when (get-text-property (point) 'mime-button-callback)
973 (mime-preview-toggle-button))))))
976 ;;; @ acting-condition
979 (defvar mime-acting-condition nil
980 "Condition-tree about how to process entity.")
982 (if (file-readable-p mailcap-file)
983 (let ((entries (mailcap-parse-file)))
985 (let ((entry (car entries))
988 (let* ((field (car entry))
989 (field-type (car field)))
990 (cond ((eq field-type 'view) (setq view field))
991 ((eq field-type 'print) (setq print field))
992 ((memq field-type '(compose composetyped edit)))
993 (t (setq shared (cons field shared)))))
994 (setq entry (cdr entry)))
995 (setq shared (nreverse shared))
996 (ctree-set-calist-with-default
997 'mime-acting-condition
998 (append shared (list '(mode . "play")(cons 'method (cdr view)))))
1000 (ctree-set-calist-with-default
1001 'mime-acting-condition
1003 (list '(mode . "print")(cons 'method (cdr view)))))))
1004 (setq entries (cdr entries)))))
1006 (ctree-set-calist-strictly
1007 'mime-acting-condition
1008 '((type . application)(subtype . octet-stream)
1010 (method . mime-detect-content)))
1012 (ctree-set-calist-with-default
1013 'mime-acting-condition
1014 '((mode . "extract")
1015 (method . mime-save-content)))
1017 (ctree-set-calist-strictly
1018 'mime-acting-condition
1019 '((type . text)(subtype . x-rot13-47)(mode . "play")
1020 (method . mime-view-caesar)))
1021 (ctree-set-calist-strictly
1022 'mime-acting-condition
1023 '((type . text)(subtype . x-rot13-47-48)(mode . "play")
1024 (method . mime-view-caesar)))
1026 (ctree-set-calist-strictly
1027 'mime-acting-condition
1028 '((type . message)(subtype . rfc822)(mode . "play")
1029 (method . mime-view-message/rfc822)))
1030 (ctree-set-calist-strictly
1031 'mime-acting-condition
1032 '((type . message)(subtype . partial)(mode . "play")
1033 (method . mime-store-message/partial-piece)))
1035 (ctree-set-calist-strictly
1036 'mime-acting-condition
1037 '((type . message)(subtype . external-body)
1038 ("access-type" . "anon-ftp")
1039 (method . mime-view-message/external-anon-ftp)))
1041 (ctree-set-calist-strictly
1042 'mime-acting-condition
1043 '((type . message)(subtype . external-body)
1044 ("access-type" . "url")
1045 (method . mime-view-message/external-url)))
1047 (ctree-set-calist-strictly
1048 'mime-acting-condition
1049 '((type . application)(subtype . octet-stream)
1050 (method . mime-save-content)))
1053 ;;; @ quitting method
1056 (defvar mime-preview-quitting-method-alist
1057 '((mime-show-message-mode
1058 . mime-preview-quitting-method-for-mime-show-message-mode))
1059 "Alist of `major-mode' vs. quitting-method of mime-view.")
1061 (defvar mime-preview-over-to-previous-method-alist nil
1062 "Alist of `major-mode' vs. over-to-previous-method of mime-view.")
1064 (defvar mime-preview-over-to-next-method-alist nil
1065 "Alist of `major-mode' vs. over-to-next-method of mime-view.")
1068 ;;; @ following method
1071 (defvar mime-preview-following-method-alist nil
1072 "Alist of `major-mode' vs. following-method of mime-view.")
1074 (defvar mime-view-following-required-fields-list
1081 (defun mime-display-entity (entity &optional situation
1082 default-situation preview-buffer)
1083 "Display mime-entity ENTITY."
1085 (setq preview-buffer (current-buffer)))
1086 (in-calist-package 'mime-view)
1089 (or (ctree-match-calist mime-preview-condition
1090 (append (mime-entity-situation entity)
1092 default-situation)))
1093 (let ((button-is-visible (mime-view-button-is-visible situation))
1095 (mime-view-header-is-visible situation))
1096 (header-presentation-method
1097 (or (cdr (assq '*header-presentation-method situation))
1098 (cdr (assq 'header-presentation-method situation))
1099 (cdr (assq (cdr (assq 'major-mode situation))
1100 mime-header-presentation-method-alist))))
1102 (mime-view-body-is-visible situation))
1103 (body-presentation-method
1104 (cdr (assq 'body-presentation-method situation)))
1105 (children (mime-entity-children entity))
1107 ;; Check if attachment is specified.
1108 ;; if inline is forced or not.
1109 (unless (or (eq t mime-view-force-inline-types)
1110 (memq (mime-entity-media-type entity)
1111 mime-view-force-inline-types)
1112 (memq (mime-view-entity-type/subtype entity)
1113 mime-view-force-inline-types)
1114 ;; whether Content-Disposition header exists.
1115 (not (mime-entity-content-disposition entity))
1117 (mime-content-disposition-type
1118 (mime-entity-content-disposition entity))))
1119 ;; This is attachment
1120 (setq header-is-visible nil
1121 body-is-visible nil)
1122 (put-alist 'header 'invisible situation)
1123 (put-alist 'body 'invisible situation))
1124 (set-buffer preview-buffer)
1127 (narrow-to-region nb nb)
1128 (if button-is-visible
1129 (mime-view-insert-entity-button entity
1130 ;; work around composite type
1133 (when header-is-visible
1135 (if header-presentation-method
1136 (funcall header-presentation-method entity situation)
1137 (mime-insert-header entity
1138 mime-view-ignored-field-list
1139 mime-view-visible-field-list))
1140 (run-hooks 'mime-display-header-hook)
1141 (put-text-property nhb (point-max) 'mime-view-entity-header entity)
1142 (goto-char (point-max))
1146 ((and body-is-visible
1147 (functionp body-presentation-method))
1148 (funcall body-presentation-method entity situation))
1150 ;; When both body and button is not displayed,
1151 ;; there should be a button to indicate there's a part.
1152 (unless button-is-visible
1153 (goto-char (point-max))
1154 (mime-view-insert-entity-button entity
1155 ;; work around composite type
1158 (unless header-is-visible
1159 (goto-char (point-max))
1161 (setq ne (point-max)))
1162 (put-text-property nb ne 'mime-view-entity entity)
1163 (put-text-property nb ne 'mime-view-situation situation)
1164 (put-text-property nbb ne 'mime-view-entity-body entity)
1166 (if (and children body-is-visible)
1167 (if (functionp body-presentation-method)
1168 (funcall body-presentation-method entity situation)
1169 (mime-display-multipart/mixed entity situation)))))
1171 ;;; @ MIME viewer mode
1174 (defconst mime-view-menu-title "MIME-View")
1175 (defconst mime-view-menu-list
1176 '((up "Move to upper entity" mime-preview-move-to-upper)
1177 (previous "Move to previous entity" mime-preview-move-to-previous)
1178 (next "Move to next entity" mime-preview-move-to-next)
1179 (scroll-down "Scroll-down" mime-preview-scroll-down-entity)
1180 (scroll-up "Scroll-up" mime-preview-scroll-up-entity)
1181 (play "Play current entity" mime-preview-play-current-entity)
1182 (extract "Extract current entity" mime-preview-extract-current-entity)
1183 (print "Print current entity" mime-preview-print-current-entity)
1184 (raw "View text without code conversion" mime-preview-inline)
1185 (text "View text with code conversion" mime-preview-text)
1186 (type "View internally as type" mime-preview-type))
1187 "Menu for MIME Viewer.")
1189 (cond ((featurep 'xemacs)
1190 (defvar mime-view-xemacs-popup-menu
1191 (cons mime-view-menu-title
1194 (vector (nth 1 item)(nth 2 item) t)))
1195 mime-view-menu-list)))
1196 (defun mime-view-xemacs-popup-menu (event)
1197 "Popup the menu in the MIME Viewer buffer"
1199 (select-window (event-window event))
1200 (set-buffer (event-buffer event))
1201 (popup-menu 'mime-view-xemacs-popup-menu))
1202 (defvar mouse-button-2 'button2))
1204 (defvar mouse-button-2 [mouse-2])))
1206 (defun mime-view-define-keymap (&optional default)
1207 (let ((mime-view-mode-map (if (keymapp default)
1208 (copy-keymap default)
1209 (make-sparse-keymap))))
1210 (define-key mime-view-mode-map
1211 "u" (function mime-preview-move-to-upper))
1212 (define-key mime-view-mode-map
1213 "p" (function mime-preview-move-to-previous))
1214 (define-key mime-view-mode-map
1215 "n" (function mime-preview-move-to-next))
1216 (define-key mime-view-mode-map
1217 "\e\t" (function mime-preview-move-to-previous))
1218 (define-key mime-view-mode-map
1219 "\t" (function mime-preview-move-to-next))
1220 (define-key mime-view-mode-map
1221 " " (function mime-preview-scroll-up-entity))
1222 (define-key mime-view-mode-map
1223 "\M- " (function mime-preview-scroll-down-entity))
1224 (define-key mime-view-mode-map
1225 "\177" (function mime-preview-scroll-down-entity))
1226 (define-key mime-view-mode-map
1227 "\C-m" (function mime-preview-next-line-entity))
1228 (define-key mime-view-mode-map
1229 "\C-\M-m" (function mime-preview-previous-line-entity))
1230 (define-key mime-view-mode-map
1231 "v" (function mime-preview-play-current-entity))
1232 (define-key mime-view-mode-map
1233 "e" (function mime-preview-extract-current-entity))
1234 (define-key mime-view-mode-map
1235 "\C-c\C-e" (function mime-preview-extract-current-entity))
1236 (define-key mime-view-mode-map
1237 "i" (function mime-preview-inline))
1238 (define-key mime-view-mode-map
1239 "c" (function mime-preview-text))
1240 (define-key mime-view-mode-map
1241 "t" (function mime-preview-type))
1242 (define-key mime-view-mode-map
1243 "b" (function mime-preview-buttonize))
1244 (define-key mime-view-mode-map
1245 "B" (function mime-preview-unbuttonize))
1246 (define-key mime-view-mode-map
1247 "\C-c\C-t\C-h" (function mime-preview-toggle-header))
1248 (define-key mime-view-mode-map
1249 "\C-c\C-th" (function mime-preview-toggle-header))
1250 (define-key mime-view-mode-map
1251 "\C-c\C-t\C-c" (function mime-preview-toggle-content))
1252 (define-key mime-view-mode-map
1253 "\C-c\C-tc" (function mime-preview-toggle-content))
1254 (define-key mime-view-mode-map
1255 "\C-c\C-tH" (function mime-preview-toggle-all-header))
1256 (define-key mime-view-mode-map
1257 "\C-c\C-tb" (function mime-preview-toggle-button))
1258 (define-key mime-view-mode-map
1259 "\C-c\C-p" (function mime-preview-print-current-entity))
1260 (define-key mime-view-mode-map
1261 "a" (function mime-preview-follow-current-entity))
1262 (define-key mime-view-mode-map
1263 "q" (function mime-preview-quit))
1264 (define-key mime-view-mode-map
1265 "\C-c\C-x" (function mime-preview-kill-buffer))
1266 ;; (define-key mime-view-mode-map
1267 ;; "<" (function beginning-of-buffer))
1268 ;; (define-key mime-view-mode-map
1269 ;; ">" (function end-of-buffer))
1270 (define-key mime-view-mode-map
1271 "?" (function describe-mode))
1272 (define-key mime-view-mode-map
1273 [tab] (function mime-preview-move-to-next))
1274 (define-key mime-view-mode-map
1275 [delete] (function mime-preview-scroll-down-entity))
1276 (define-key mime-view-mode-map
1277 [backspace] (function mime-preview-scroll-down-entity))
1278 (if (functionp default)
1279 (cond ((featurep 'xemacs)
1280 (set-keymap-default-binding mime-view-mode-map default))
1282 (setq mime-view-mode-map
1283 (append mime-view-mode-map (list (cons t default)))))))
1285 (define-key mime-view-mode-map
1286 mouse-button-2 (function mime-button-dispatcher)))
1287 (cond ((featurep 'xemacs)
1288 (define-key mime-view-mode-map
1289 mouse-button-3 (function mime-view-xemacs-popup-menu)))
1290 ((>= emacs-major-version 19)
1291 (define-key mime-view-mode-map [menu-bar mime-view]
1292 (cons mime-view-menu-title
1293 (make-sparse-keymap mime-view-menu-title)))
1296 (define-key mime-view-mode-map
1297 (vector 'menu-bar 'mime-view (car item))
1298 (cons (nth 1 item)(nth 2 item)))))
1299 (reverse mime-view-menu-list))))
1300 (use-local-map mime-view-mode-map)
1301 (run-hooks 'mime-view-define-keymap-hook)))
1303 (defsubst mime-maybe-hide-echo-buffer ()
1304 "Clear mime-echo buffer and delete window for it."
1305 (let ((buf (get-buffer mime-echo-buffer-name)))
1310 (let ((win (get-buffer-window buf)))
1312 (delete-window win)))
1313 (bury-buffer buf)))))
1315 (defvar mime-view-redisplay nil)
1318 (defun mime-display-message (message &optional preview-buffer
1319 mother default-keymap-or-function
1320 original-major-mode)
1321 "View MESSAGE in MIME-View mode.
1323 Optional argument PREVIEW-BUFFER specifies the buffer of the
1324 presentation. It must be either nil or a name of preview buffer.
1326 Optional argument MOTHER specifies mother-buffer of the preview-buffer.
1328 Optional argument DEFAULT-KEYMAP-OR-FUNCTION is nil, keymap or
1329 function. If it is a keymap, keymap of MIME-View mode will be added
1330 to it. If it is a function, it will be bound as default binding of
1331 keymap of MIME-View mode."
1332 (mime-maybe-hide-echo-buffer)
1333 (let ((win-conf (current-window-configuration)))
1335 (setq preview-buffer
1336 (concat "*Preview-" (mime-entity-name message) "*")))
1337 (or original-major-mode
1338 (setq original-major-mode major-mode))
1339 (let ((inhibit-read-only t))
1340 (set-buffer (get-buffer-create preview-buffer))
1344 (setq mime-mother-buffer mother))
1345 (setq mime-preview-original-window-configuration win-conf)
1346 (setq major-mode 'mime-view-mode)
1347 (setq mode-name "MIME-View")
1348 (mime-display-entity message nil
1349 `((entity-button . invisible)
1351 (major-mode . ,original-major-mode))
1353 (mime-view-define-keymap default-keymap-or-function)
1354 (set (make-local-variable 'line-move-ignore-invisible) t)
1356 (next-single-property-change (point-min) 'mime-view-entity)))
1359 (goto-char (point-min))
1360 (search-forward "\n\n" nil t)))
1361 (run-hooks 'mime-view-mode-hook)
1362 (set-buffer-modified-p nil)
1363 (setq buffer-read-only t)
1367 (defun mime-view-buffer (&optional raw-buffer preview-buffer mother
1368 default-keymap-or-function
1369 representation-type)
1370 "View RAW-BUFFER in MIME-View mode.
1371 Optional argument PREVIEW-BUFFER is either nil or a name of preview
1373 Optional argument DEFAULT-KEYMAP-OR-FUNCTION is nil, keymap or
1374 function. If it is a keymap, keymap of MIME-View mode will be added
1375 to it. If it is a function, it will be bound as default binding of
1376 keymap of MIME-View mode.
1377 Optional argument REPRESENTATION-TYPE is representation-type of
1378 message. It must be nil, `binary' or `cooked'. If it is nil,
1379 `cooked' is used as default."
1382 (setq raw-buffer (current-buffer)))
1383 (or representation-type
1384 (setq representation-type
1386 (set-buffer raw-buffer)
1387 (cdr (or (assq major-mode mime-raw-representation-type-alist)
1388 (assq t mime-raw-representation-type-alist))))))
1389 (if (eq representation-type 'binary)
1390 (setq representation-type 'buffer))
1391 (setq preview-buffer (mime-display-message
1392 (mime-open-entity representation-type raw-buffer)
1393 preview-buffer mother default-keymap-or-function))
1394 (or (get-buffer-window preview-buffer)
1395 (let ((r-win (get-buffer-window raw-buffer)))
1397 (set-window-buffer r-win preview-buffer)
1398 (let ((m-win (and mother (get-buffer-window mother))))
1400 (set-window-buffer m-win preview-buffer)
1401 (switch-to-buffer preview-buffer)))))))
1403 (defun mime-view-mode (&optional mother ctl encoding
1404 raw-buffer preview-buffer
1405 default-keymap-or-function)
1406 "Major mode for viewing MIME message.
1408 Here is a list of the standard keys for mime-view-mode.
1413 u Move to upper content
1414 p or M-TAB Move to previous content
1415 n or TAB Move to next content
1416 SPC Scroll up or move to next content
1417 M-SPC or DEL Scroll down or move to previous content
1418 RET Move to next line
1419 M-RET Move to previous line
1420 v Decode current content as `play mode'
1421 e Decode current content as `extract mode'
1422 C-c C-p Decode current content as `print mode'
1423 a Followup to current content.
1425 button-2 Move to point under the mouse cursor
1426 and decode current content as `play mode'"
1428 (unless mime-view-redisplay
1430 (if raw-buffer (set-buffer raw-buffer))
1433 (or (assq major-mode mime-raw-representation-type-alist)
1434 (assq t mime-raw-representation-type-alist)))))
1435 (if (eq type 'binary)
1436 (setq type 'buffer))
1437 (setq mime-message-structure (mime-open-entity type raw-buffer))
1438 (or (mime-entity-content-type mime-message-structure)
1439 (mime-entity-set-content-type-internal
1440 mime-message-structure ctl)))
1441 (or (mime-entity-encoding mime-message-structure)
1442 (mime-entity-set-encoding-internal mime-message-structure encoding))))
1443 (mime-display-message mime-message-structure preview-buffer
1444 mother default-keymap-or-function))
1450 (autoload 'mime-preview-play-current-entity "mime-play"
1451 "Play current entity." t)
1453 (defun mime-preview-extract-current-entity (&optional ignore-examples)
1454 "Extract current entity into file (maybe).
1455 It decodes current entity to call internal or external method as
1456 \"extract\" mode. The method is selected from variable
1457 `mime-acting-condition'."
1459 (mime-preview-play-current-entity ignore-examples "extract"))
1461 (defun mime-preview-print-current-entity (&optional ignore-examples)
1462 "Print current entity (maybe).
1463 It decodes current entity to call internal or external method as
1464 \"print\" mode. The method is selected from variable
1465 `mime-acting-condition'."
1467 (mime-preview-play-current-entity ignore-examples "print"))
1473 (defun mime-preview-follow-current-entity ()
1474 "Write follow message to current entity.
1475 It calls following-method selected from variable
1476 `mime-preview-following-method-alist'."
1478 (let (entity position entity-node-id header-exists)
1479 (while (null (setq entity
1480 (get-text-property (point) 'mime-view-entity)))
1482 (setq position (mime-preview-entity-boundary))
1483 (setq entity-node-id (mime-entity-node-id entity)
1485 ;; When on an invisible entity, there's no header.
1486 (or (mime-view-header-is-visible
1487 (get-text-property (car position) 'mime-view-situation))
1488 ;; We are on a rfc822 button.
1489 (and (eq 'message (mime-entity-media-type
1491 (eq 'rfc822 (mime-entity-media-subtype
1494 (next-single-property-change
1495 (car position) 'mime-button-callback
1497 'mime-view-entity-header))))
1498 (let* ((mode (mime-preview-original-major-mode 'recursive))
1500 (format "%s-%s" (buffer-name) (reverse entity-node-id)))
1502 (the-buf (current-buffer))
1505 (set-buffer (setq new-buf (get-buffer-create new-name)))
1507 ;; Compatibility kludge.
1508 ;; FSF Emacs can only take substring of current-buffer.
1511 (set-buffer the-buf)
1512 (buffer-substring-no-properties (car position)
1515 (delete-region (goto-char (point-min))
1516 (re-search-forward "^$"))
1518 (goto-char (point-min))
1519 (let ((current-entity
1520 (if (and (eq (mime-entity-media-type entity) 'message)
1521 (eq (mime-entity-media-subtype entity) 'rfc822))
1522 (car (mime-entity-children entity))
1524 (while (and current-entity
1525 (if (and (eq (mime-entity-media-type
1526 current-entity) 'message)
1527 (eq (mime-entity-media-subtype
1528 current-entity) 'rfc822))
1530 (mime-insert-header current-entity fields)
1532 (setq fields (std11-collect-field-names)
1533 current-entity (mime-entity-parent current-entity))))
1534 (let ((rest mime-view-following-required-fields-list)
1537 (setq field-name (car rest))
1538 (or (std11-field-body field-name)
1541 (set-buffer the-buf)
1542 (let ((entity (when mime-mother-buffer
1543 (set-buffer mime-mother-buffer)
1544 (get-text-property (point)
1545 'mime-view-entity))))
1547 (null (setq ret (mime-entity-fetch-field
1548 entity field-name))))
1549 (setq entity (mime-entity-parent entity)))))
1551 (insert (concat field-name ": " ret "\n")))))
1552 (setq rest (cdr rest))))
1553 (mime-decode-header-in-buffer))
1554 (let ((f (cdr (assq mode mime-preview-following-method-alist))))
1559 "Sorry, following method for %s is not implemented yet."
1566 (defun mime-preview-move-to-upper ()
1567 "Move to upper entity.
1568 If there is no upper entity, call function `mime-preview-quit'."
1571 (while (null (setq cinfo
1572 (get-text-property (point) 'mime-view-entity)))
1574 (let ((r (mime-entity-parent cinfo))
1577 (while (setq point (previous-single-property-change
1578 (point) 'mime-view-entity))
1580 (when (eq r (get-text-property (point) 'mime-view-entity))
1581 (if (or (eq mime-preview-move-scroll t)
1582 (and mime-preview-move-scroll
1585 (move-to-window-line -1)
1586 (forward-line (* -1 next-screen-context-lines))
1589 (recenter next-screen-context-lines))
1591 (mime-preview-quit)))))
1593 (defun mime-preview-move-to-previous ()
1594 "Move to previous entity.
1595 If there is no previous entity, it calls function registered in
1596 variable `mime-preview-over-to-previous-method-alist'."
1598 (while (and (not (bobp))
1599 (null (get-text-property (point) 'mime-view-entity)))
1601 (let ((point (previous-single-property-change (point) 'mime-view-entity)))
1603 (>= point (point-min)))
1604 (if (get-text-property (1- point) 'mime-view-entity)
1605 (progn (goto-char point)
1607 (or (eq mime-preview-move-scroll t)
1608 (and mime-preview-move-scroll
1611 (move-to-window-line 0)
1612 (forward-line next-screen-context-lines)
1615 (recenter next-screen-context-lines)))
1616 (goto-char (1- point))
1617 (mime-preview-move-to-previous))
1618 (let ((f (assq (mime-preview-original-major-mode)
1619 mime-preview-over-to-previous-method-alist)))
1621 (funcall (cdr f)))))))
1623 (defun mime-preview-move-to-next ()
1624 "Move to next entity.
1625 If there is no previous entity, it calls function registered in
1626 variable `mime-preview-over-to-next-method-alist'."
1628 (while (and (not (eobp))
1629 (null (get-text-property (point) 'mime-view-entity)))
1631 (let ((point (next-single-property-change (point) 'mime-view-entity)))
1633 (<= point (point-max)))
1636 (if (null (get-text-property point 'mime-view-entity))
1637 (mime-preview-move-to-next)
1639 (or (eq mime-preview-move-scroll t)
1640 (and mime-preview-move-scroll
1643 (move-to-window-line -1)
1645 (* -1 next-screen-context-lines))
1648 (recenter next-screen-context-lines))))
1649 (let ((f (assq (mime-preview-original-major-mode)
1650 mime-preview-over-to-next-method-alist)))
1652 (funcall (cdr f)))))))
1654 (defun mime-preview-scroll-up-entity (&optional h)
1655 "Scroll up current entity.
1656 If reached to (point-max), it calls function registered in variable
1657 `mime-preview-over-to-next-method-alist'."
1660 (let ((f (assq (mime-preview-original-major-mode)
1661 mime-preview-over-to-next-method-alist)))
1665 (or (next-single-property-change (point) 'mime-view-entity)
1667 (bottom (window-end (selected-window))))
1670 (not mime-preview-scroll-full-screen))
1671 (progn (goto-char point)
1672 (recenter next-screen-context-lines))
1676 (goto-char (point-max))))))))
1678 (defun mime-preview-scroll-down-entity (&optional h)
1679 "Scroll down current entity.
1680 If reached to (point-min), it calls function registered in variable
1681 `mime-preview-over-to-previous-method-alist'."
1684 (let ((f (assq (mime-preview-original-major-mode)
1685 mime-preview-over-to-previous-method-alist)))
1689 (or (previous-single-property-change (point) 'mime-view-entity)
1691 (top (window-start (selected-window))))
1694 (not mime-preview-scroll-full-screen))
1695 (progn (goto-char point)
1696 (recenter (* -1 next-screen-context-lines)))
1699 (beginning-of-buffer
1700 (goto-char (point-min))))))))
1702 (defun mime-preview-next-line-entity (&optional lines)
1703 "Scroll up one line (or prefix LINES lines).
1704 If LINES is negative, scroll down LINES lines."
1706 (mime-preview-scroll-up-entity (or lines 1)))
1708 (defun mime-preview-previous-line-entity (&optional lines)
1709 "Scrroll down one line (or prefix LINES lines).
1710 If LINES is negative, scroll up LINES lines."
1712 (mime-preview-scroll-down-entity (or lines 1)))
1714 (defun mime-preview-entity-boundary (&optional point)
1716 (setq point (point)))
1717 (and (eq point (point-max))
1718 (setq point (1- (point-max))))
1719 (let ((entity (get-text-property point 'mime-view-entity))
1720 (start (previous-single-property-change (1+ point) 'mime-view-entity
1724 (while (and (mime-entity-children entity)
1726 (if (not (mime-view-body-is-visible
1727 (get-text-property point 'mime-view-situation)))
1729 ;; If the part is shown, search the last part.
1730 (let ((child (car (last (mime-entity-children entity)))))
1731 (while (not (eq (get-text-property point 'mime-view-entity) child))
1732 (setq point (next-single-property-change point 'mime-view-entity)))
1733 (setq entity child))))
1734 (setq end (next-single-property-change point 'mime-view-entity
1738 (defun mime-preview-toggle-header (&optional show)
1739 "Toggle display of entity header.
1740 When prefix is given, it always displays the header."
1742 (let ((inhibit-read-only t)
1743 (mime-view-force-inline-types t)
1744 (position (mime-preview-entity-boundary))
1745 entity header-is-visible situation)
1746 (setq entity (get-text-property (car position) 'mime-view-entity)
1747 situation (get-text-property (car position) 'mime-view-situation))
1748 (setq header-is-visible (mime-view-header-is-visible situation))
1750 (delete-region (car position) (cdr position))
1751 (if (or show (not header-is-visible))
1752 (mime-display-entity
1754 (del-alist '*entity-button
1755 (put-alist '*header 'visible
1757 (mime-display-entity
1759 (put-alist '*entity-button
1761 (put-alist '*header 'invisible
1764 (defun mime-preview-toggle-all-header (&optional show)
1765 "Toggle display of entity header.
1766 When prefix is given, it always displays the header."
1768 (let ((inhibit-read-only t)
1769 (mime-view-force-inline-types t)
1770 (position (mime-preview-entity-boundary))
1771 entity header-is-visible situation)
1772 (setq entity (get-text-property (car position) 'mime-view-entity)
1773 situation (get-text-property (car position) 'mime-view-situation))
1774 (setq header-is-visible (mime-view-header-is-visible situation))
1776 (delete-region (car position) (cdr position))
1777 (if (or show (not header-is-visible))
1778 (mime-display-entity
1780 (del-alist '*entity-button
1782 (del-alist '*header-presentation-method
1784 (mime-display-entity
1791 (put-alist '*header-presentation-method
1792 #'(lambda (entity situation)
1794 entity nil '(".*")))
1797 (defun mime-preview-toggle-content (&optional show)
1798 "Toggle display of entity body.
1799 When prefix is given, it always displays the content."
1801 (let ((inhibit-read-only t)
1802 (mime-view-force-inline-types t)
1803 (position (mime-preview-entity-boundary))
1805 (setq entity (get-text-property (car position) 'mime-view-entity)
1806 situation (get-text-property (car position) 'mime-view-situation))
1808 (if (or show (not (mime-view-body-is-visible situation)))
1811 (put-alist '*body 'visible situation))
1813 '*entity-button 'visible
1814 (put-alist '*body 'invisible situation))))
1816 (delete-region (car position) (cdr position))
1817 (mime-display-entity entity situation))))
1819 (defun mime-preview-toggle-button (&optional show)
1820 "Toggle display of entity button.
1821 When prefix is given, it always displays the content."
1823 (let ((inhibit-read-only t)
1824 (mime-view-force-inline-types t)
1825 (position (mime-preview-entity-boundary))
1826 entity situation button-is-visible)
1827 (setq entity (get-text-property (car position) 'mime-view-entity)
1828 situation (get-text-property (car position) 'mime-view-situation)
1829 button-is-visible (mime-view-button-is-visible situation))
1831 (delete-region (car position) (cdr position))
1832 (if (or show (not button-is-visible))
1833 (mime-display-entity entity
1834 (put-alist '*entity-button
1835 'visible situation))
1836 (mime-display-entity entity
1837 (put-alist '*entity-button
1838 'invisible situation))))))
1843 (defun mime-preview-quit ()
1844 "Quit from MIME-preview buffer.
1845 It calls function registered in variable
1846 `mime-preview-quitting-method-alist'."
1848 (let ((r (assq (mime-preview-original-major-mode)
1849 mime-preview-quitting-method-alist)))
1852 (kill-buffer (current-buffer)))))
1854 (defun mime-preview-kill-buffer ()
1856 (kill-buffer (current-buffer)))
1862 (provide 'mime-view)
1864 (run-hooks 'mime-view-load-hook)
1866 ;;; mime-view.el ends here