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)))
304 ;;; @ presentation of preview
310 ;;; @@@ predicate function
314 (defun mime-view-entity-type/subtype (entity)
315 (if (not (mime-entity-media-type entity))
317 (intern (format "%s/%s"
318 (mime-entity-media-type entity)
319 (mime-entity-media-subtype entity)))))
321 (defun mime-view-entity-button-visible-p (entity)
322 "Return non-nil if header of ENTITY is visible.
323 You can customize the visibility by changing `mime-view-button-place-alist'."
325 ;; Check current entity
327 (memq (cdr (assq (mime-view-entity-type/subtype entity)
328 mime-view-button-place-alist))
331 (memq (cdr (assq (mime-entity-media-type entity)
332 mime-view-button-place-alist))
334 (and (mime-entity-parent entity)
337 (reverse (mime-entity-children
338 (mime-entity-parent entity)))))))
339 ;; When previous entity exists
342 ;; Check previous entity
346 (mime-view-entity-type/subtype prev-entity)
347 mime-view-button-place-alist))
352 (mime-entity-media-type prev-entity)
353 mime-view-button-place-alist))
354 '(around after))))))))
356 ;;; @@@ entity button generator
359 (defun mime-view-insert-entity-button (entity &optional body-is-invisible)
360 "Insert entity-button of ENTITY."
361 (let ((entity-node-id (mime-entity-node-id entity))
362 (params (mime-entity-parameters entity))
363 (subject (mime-view-entity-title entity)))
366 (let ((access-type (assoc "access-type" params))
367 (num (or (cdr (assoc "x-part-number" params))
368 (if (consp entity-node-id)
371 (format "%s" (1+ num))))
372 (reverse entity-node-id) ".")
375 (let ((server (assoc "server" params)))
376 (setq access-type (cdr access-type))
378 (format "%s %s ([%s] %s)"
379 num subject access-type (cdr server))
380 (let ((site (cdr (assoc "site" params)))
381 (dir (cdr (assoc "directory" params)))
382 (url (cdr (assoc "url" params))))
384 (format "%s %s ([%s] %s)"
385 num subject access-type url)
386 (format "%s %s ([%s] %s:%s)"
387 num subject access-type site dir))))))
389 (let ((media-type (mime-entity-media-type entity))
390 (media-subtype (mime-entity-media-subtype entity))
391 (charset (cdr (assoc "charset" params)))
392 (encoding (mime-entity-encoding entity)))
396 (format " <%s/%s%s%s>"
397 media-type media-subtype
399 (concat "; " charset)
402 (concat " (" encoding ")")
404 (if (>= (+ (current-column)(length rest))(window-width))
407 (if body-is-invisible
410 (function mime-preview-play-current-entity))))
416 (defvar mime-header-presentation-method-alist nil
417 "Alist of major mode vs. corresponding header-presentation-method functions.
418 Each element looks like (SYMBOL . FUNCTION).
419 SYMBOL must be major mode in raw-buffer or t. t means default.
420 Interface of FUNCTION must be (ENTITY SITUATION).")
422 (defvar mime-view-ignored-field-list
423 '(".*Received:" ".*Path:" ".*Id:" "^References:"
424 "^Replied:" "^Errors-To:"
425 "^Lines:" "^Sender:" ".*Host:" "^Xref:"
426 "^Content-Type:" "^Precedence:"
427 "^Status:" "^X-VM-.*:")
428 "All fields that match this list will be hidden in MIME preview buffer.
429 Each elements are regexp of field-name.")
431 (defvar mime-view-visible-field-list '("^Dnas.*:" "^Message-Id:")
432 "All fields that match this list will be displayed in MIME preview buffer.
433 Each elements are regexp of field-name.")
439 ;;; @@@ predicate function
442 (in-calist-package 'mime-view)
444 (defun mime-calist::field-match-method-as-default-rule (calist
445 field-type field-value)
446 (let ((s-field (assq field-type calist)))
447 (cond ((null s-field)
448 (cons (cons field-type field-value) calist))
451 (define-calist-field-match-method
452 'header #'mime-calist::field-match-method-as-default-rule)
454 (define-calist-field-match-method
455 'body #'mime-calist::field-match-method-as-default-rule)
458 (defvar mime-preview-condition nil
459 "Condition-tree about how to display entity.")
461 ;;(ctree-set-calist-strictly
462 ;; 'mime-preview-condition '((type . application)(subtype . octet-stream)
464 ;; (body . visible)))
466 (ctree-set-calist-strictly
467 'mime-preview-condition '((type . application)(subtype . t)
470 (ctree-set-calist-strictly
471 'mime-preview-condition '((type . application)(subtype . t)
475 (ctree-set-calist-strictly
476 'mime-preview-condition '((type . application)(subtype . pgp)
479 (ctree-set-calist-strictly
480 'mime-preview-condition '((type . application)(subtype . x-latex)
483 (ctree-set-calist-strictly
484 'mime-preview-condition '((type . application)(subtype . x-selection)
487 (ctree-set-calist-strictly
488 'mime-preview-condition '((type . application)(subtype . x-comment)
491 (ctree-set-calist-strictly
492 'mime-preview-condition '((type . message)(subtype . delivery-status)
495 (ctree-set-calist-strictly
496 'mime-preview-condition
498 (body-presentation-method . mime-display-text/plain)))
500 (ctree-set-calist-strictly
501 'mime-preview-condition
504 (body-presentation-method . mime-display-text/plain)))
506 (ctree-set-calist-strictly
507 'mime-preview-condition
508 '((type . text)(subtype . enriched)
510 (body-presentation-method . mime-display-text/enriched)))
512 (ctree-set-calist-strictly
513 'mime-preview-condition
514 '((type . text)(subtype . richtext)
516 (body-presentation-method . mime-display-text/richtext)))
518 (ctree-set-calist-strictly
519 'mime-preview-condition
520 '((type . application)(subtype . x-postpet)
522 (body-presentation-method . mime-display-application/x-postpet)))
524 (ctree-set-calist-strictly
525 'mime-preview-condition '((type . application)(subtype . t)
528 (body-presentation-method . mime-display-detect-application/octet-stream)))
530 (ctree-set-calist-strictly
531 'mime-preview-condition
532 '((type . text)(subtype . t)
534 (body-presentation-method . mime-display-text/plain)))
536 (ctree-set-calist-strictly
537 'mime-preview-condition
538 '((type . text)(subtype . x-rot13-47-48)
540 (body-presentation-method . mime-display-text/x-rot13-47-48)))
542 (ctree-set-calist-strictly
543 'mime-preview-condition
544 '((type . multipart)(subtype . alternative)
546 (body-presentation-method . mime-display-multipart/alternative)))
548 (ctree-set-calist-strictly
549 'mime-preview-condition '((type . message)(subtype . partial)
550 (body-presentation-method
551 . mime-display-message/partial-button)))
553 (ctree-set-calist-strictly
554 'mime-preview-condition '((type . message)(subtype . rfc822)
555 (body-presentation-method . nil)
556 (childrens-situation (header . visible)
557 (entity-button . invisible))))
559 (ctree-set-calist-strictly
560 'mime-preview-condition '((type . message)(subtype . news)
561 (body-presentation-method . nil)
562 (childrens-situation (header . visible)
563 (entity-button . invisible))))
566 ;;; @@@ entity presentation
569 (defun mime-display-text/plain (entity situation)
571 (narrow-to-region (point-max)(point-max))
572 (mime-insert-text-content entity)
573 (run-hooks 'mime-text-decode-hook)
574 (goto-char (point-max))
575 (if (not (eq (char-after (1- (point))) ?\n))
577 (mime-add-url-buttons)
578 (run-hooks 'mime-display-text/plain-hook)))
580 (defun mime-display-text/richtext (entity situation)
582 (narrow-to-region (point-max)(point-max))
583 (mime-insert-text-content entity)
584 (run-hooks 'mime-text-decode-hook)
585 (let ((beg (point-min)))
586 (remove-text-properties beg (point-max) '(face nil))
587 (richtext-decode beg (point-max)))))
589 (defun mime-display-text/enriched (entity situation)
591 (narrow-to-region (point-max)(point-max))
592 (mime-insert-text-content entity)
593 (run-hooks 'mime-text-decode-hook)
594 (let ((beg (point-min)))
595 (remove-text-properties beg (point-max) '(face nil))
596 (enriched-decode beg (point-max)))))
598 (defun mime-display-text/x-rot13-47-48 (entity situation)
600 (narrow-to-region (point-max)(point-max))
601 (mime-insert-text-content entity)
602 (goto-char (point-max))
603 (if (not (eq (char-after (1- (point))) ?\n))
605 (mule-caesar-region (point-min) (point-max))
606 (mime-add-url-buttons)))
608 (put 'unpack 'lisp-indent-function 1)
609 (defmacro unpack (string &rest body)
610 `(let* ((*unpack*string* (string-as-unibyte ,string))
614 (defun unpack-skip (len)
615 (setq *unpack*index* (+ len *unpack*index*)))
617 (defun unpack-fixed (len)
619 (substring *unpack*string* *unpack*index* (+ *unpack*index* len))
622 (defun unpack-byte ()
623 (char-int (aref (unpack-fixed 1) 0)))
625 (defun unpack-short ()
626 (let* ((b0 (unpack-byte))
630 (defun unpack-long ()
631 (let* ((s0 (unpack-short))
633 (+ (* 65536 s0) s1)))
635 (defun unpack-string ()
636 (let ((len (unpack-byte)))
639 (defun unpack-string-sjis ()
640 (decode-mime-charset-string (unpack-string) 'shift_jis))
642 (defun postpet-decode (string)
647 (set-alist 'res 'carryingcount (unpack-long))
649 (set-alist 'res 'sentyear (unpack-short))
650 (set-alist 'res 'sentmonth (unpack-short))
651 (set-alist 'res 'sentday (unpack-short))
653 (set-alist 'res 'petname (unpack-string-sjis))
654 (set-alist 'res 'owner (unpack-string-sjis))
655 (set-alist 'res 'pettype (unpack-fixed 4))
656 (set-alist 'res 'health (unpack-short))
658 (set-alist 'res 'sex (unpack-long))
660 (set-alist 'res 'brain (unpack-byte))
662 (set-alist 'res 'happiness (unpack-byte))
664 (set-alist 'res 'petbirthyear (unpack-short))
665 (set-alist 'res 'petbirthmonth (unpack-short))
666 (set-alist 'res 'petbirthday (unpack-short))
668 (set-alist 'res 'from (unpack-string))
675 (set-alist 'res 'treasure (unpack-short))
676 (set-alist 'res 'money (unpack-long))
680 (defun mime-display-application/x-postpet (entity situation)
682 (narrow-to-region (point-max)(point-max))
683 (let ((pet (postpet-decode (mime-entity-content entity))))
685 (insert "Petname: " (cdr (assq 'petname pet)) "\n"
686 "Owner: " (cdr (assq 'owner pet)) "\n"
687 "Pettype: " (cdr (assq 'pettype pet)) "\n"
688 "From: " (cdr (assq 'from pet)) "\n"
689 "CarryingCount: " (int-to-string (cdr (assq 'carryingcount pet))) "\n"
690 "SentYear: " (int-to-string (cdr (assq 'sentyear pet))) "\n"
691 "SentMonth: " (int-to-string (cdr (assq 'sentmonth pet))) "\n"
692 "SentDay: " (int-to-string (cdr (assq 'sentday pet))) "\n"
693 "PetbirthYear: " (int-to-string (cdr (assq 'petbirthyear pet))) "\n"
694 "PetbirthMonth: " (int-to-string (cdr (assq 'petbirthmonth pet))) "\n"
695 "PetbirthDay: " (int-to-string (cdr (assq 'petbirthday pet))) "\n"
696 "Health: " (int-to-string (cdr (assq 'health pet))) "\n"
697 "Sex: " (int-to-string (cdr (assq 'sex pet))) "\n"
698 "Brain: " (int-to-string (cdr (assq 'brain pet))) "\n"
699 "Happiness: " (int-to-string (cdr (assq 'happiness pet))) "\n"
700 "Treasure: " (int-to-string (cdr (assq 'treasure pet))) "\n"
701 "Money: " (int-to-string (cdr (assq 'money pet))) "\n")
702 (insert "Invalid format\n"))
703 (run-hooks 'mime-display-application/x-postpet-hook))))
706 (defvar mime-view-announcement-for-message/partial
707 (if (and (>= emacs-major-version 19) window-system)
709 \[[ This is message/partial style split message. ]]
710 \[[ Please press `v' key in this buffer ]]
711 \[[ or click here by mouse button-2. ]]"
713 \[[ This is message/partial style split message. ]]
714 \[[ Please press `v' key in this buffer. ]]"))
716 (defun mime-display-message/partial-button (&optional entity situation)
718 (goto-char (point-max))
719 (if (not (search-backward "\n\n" nil t))
721 (goto-char (point-max))
722 (narrow-to-region (point-max)(point-max))
723 (insert mime-view-announcement-for-message/partial)
724 (mime-add-button (point-min)(point-max)
725 #'mime-preview-play-current-entity)))
727 (defun mime-display-multipart/mixed (entity situation)
728 (let ((children (mime-entity-children entity))
729 (original-major-mode-cell (assq 'major-mode situation))
731 (cdr (assq 'childrens-situation situation))))
732 (if original-major-mode-cell
733 (setq default-situation
734 (cons original-major-mode-cell default-situation)))
736 (mime-display-entity (car children) nil default-situation)
737 (setq children (cdr children)))))
739 (defun mime-display-multipart/alternative (entity situation)
740 (let* ((children (mime-entity-children entity))
741 (original-major-mode-cell (assq 'major-mode situation))
743 (cdr (assq 'childrens-situation situation)))
748 (if original-major-mode-cell
749 (setq default-situation
750 (cons original-major-mode-cell default-situation)))
755 (or (ctree-match-calist
756 mime-preview-condition
757 (append (mime-entity-situation child)
760 (if (cdr (assq 'body-presentation-method situation))
765 (cdr (assq 'type situation))
766 (cdr (assq 'subtype situation)))
767 mime-view-type-subtype-score-alist)
769 (cdr (assq 'type situation))
770 mime-view-type-subtype-score-alist)
773 mime-view-type-subtype-score-alist)))))
774 (if (> score max-score)
782 (let ((child (car children))
783 (situation (car situations)))
784 (mime-display-entity child (if (= i p)
786 (del-alist 'body-presentation-method
787 (copy-alist situation)))))
788 (setq children (cdr children)
789 situations (cdr situations)
792 (defun mime-display-detect-application/octet-stream (entity situation)
793 "Detect unknown ENTITY and display it inline.
794 This can only handle gzipped contents."
795 (or (and (mime-entity-filename entity)
796 (string-match "\\.gz$" (mime-entity-filename entity))
797 (mime-display-gzipped entity situation))
798 (mime-display-text/plain entity situation)))
800 (defun mime-display-gzipped (entity situation)
801 "Ungzip gzipped part and display."
804 (insert (mime-entity-content entity))
806 (call-process-region (point-min) (point-max) "gzip" t t
808 (buffer-string (point-min) (point-max))))
811 (defun mime-preview-inline ()
812 "View part as text without code conversion."
814 (let ((inhibit-read-only t)
815 (entity (get-text-property (point) 'mime-view-entity))
816 (situation (get-text-property (point) 'mime-view-situation))
819 (not (get-text-property (point) 'mime-view-entity-header))
820 (not (memq (mime-entity-media-type entity)
821 '(multipart message))))
822 (setq start (or (and (not (mime-entity-parent entity))
823 (1+ (previous-single-property-change
825 'mime-view-entity-header)))
826 (and (not (eq (point) (point-min)))
827 (not (eq (get-text-property (1- (point))
831 (previous-single-property-change (point)
836 (or (next-single-property-change (point)
840 (if (mime-view-entity-button-visible-p entity)
841 (mime-view-insert-entity-button entity))
842 (insert (mime-entity-content entity))
843 (if (and (bolp) (eolp))
846 (add-text-properties start (point)
847 (list 'mime-view-entity entity
848 'mime-view-situation situation))
851 (defun mime-preview-text (&optional ask-coding)
852 "View part as text. MIME charset will be guessed automatically.
853 With prefix, it prompts for coding-system."
855 (let ((inhibit-read-only t)
856 (entity (get-text-property (point) 'mime-view-entity))
857 (situation (get-text-property (point) 'mime-view-situation))
858 (coding (if ask-coding
859 (or (read-coding-system "Coding system: ")
864 (not (get-text-property (point) 'mime-view-entity-header))
865 (not (memq (mime-entity-media-type entity)
866 '(multipart message))))
867 (setq start (or (and (not (mime-entity-parent entity))
868 (1+ (previous-single-property-change
870 'mime-view-entity-header)))
871 (and (not (eq (point) (point-min)))
872 (not (eq (get-text-property (1- (point))
876 (previous-single-property-change (point)
881 (or (next-single-property-change (point)
885 (if (mime-view-entity-button-visible-p entity)
886 (mime-view-insert-entity-button entity))
887 (insert (decode-coding-string (mime-entity-content entity) coding))
888 (if (and (bolp) (eolp))
891 (add-text-properties start (point)
892 (list 'mime-view-entity entity
893 'mime-view-situation situation))
897 (defun mime-preview-type ()
898 "View part as text without code conversion."
900 (let ((inhibit-read-only t)
901 (entity (get-text-property (point) 'mime-view-entity))
902 (situation (get-text-property (point) 'mime-view-situation))
903 (mime-view-force-inline-types t)
906 (not (get-text-property (point) 'mime-view-entity-header))
907 (not (memq (mime-entity-media-type entity)
908 '(multipart message))))
909 (setq start (or (and (not (mime-entity-parent entity))
910 (1+ (previous-single-property-change
912 'mime-view-entity-header)))
913 (and (not (eq (point) (point-min)))
914 (not (eq (get-text-property (1- (point))
918 (previous-single-property-change (point)
923 (or (next-single-property-change (point)
928 (narrow-to-region (point) (point))
929 (mime-display-entity entity (if (eq (assq 'body situation)
932 (put-alist 'body 'visible
934 (if (and (bolp) (eolp))
937 (defun mime-preview-buttonize ()
940 (goto-char (point-min))
941 (let ((inhibit-read-only t)
943 (while (setq point (next-single-property-change
944 (point) 'mime-view-entity))
946 (unless (get-text-property (point) 'mime-button-callback)
947 (mime-view-insert-entity-button
948 (get-text-property (point) 'mime-view-entity)))))))
950 (defun mime-preview-unbuttonize ()
953 (goto-char (point-min))
954 (let ((inhibit-read-only t)
956 (while (setq point (next-single-property-change
957 (point) 'mime-view-entity))
959 (if (get-text-property (point) 'mime-button-callback)
960 (delete-region (point) (save-excursion
962 (next-single-property-change
963 (point) 'mime-button-callback)))))))))
966 ;;; @ acting-condition
969 (defvar mime-acting-condition nil
970 "Condition-tree about how to process entity.")
972 (if (file-readable-p mailcap-file)
973 (let ((entries (mailcap-parse-file)))
975 (let ((entry (car entries))
978 (let* ((field (car entry))
979 (field-type (car field)))
980 (cond ((eq field-type 'view) (setq view field))
981 ((eq field-type 'print) (setq print field))
982 ((memq field-type '(compose composetyped edit)))
983 (t (setq shared (cons field shared)))))
984 (setq entry (cdr entry)))
985 (setq shared (nreverse shared))
986 (ctree-set-calist-with-default
987 'mime-acting-condition
988 (append shared (list '(mode . "play")(cons 'method (cdr view)))))
990 (ctree-set-calist-with-default
991 'mime-acting-condition
993 (list '(mode . "print")(cons 'method (cdr view)))))))
994 (setq entries (cdr entries)))))
996 (ctree-set-calist-strictly
997 'mime-acting-condition
998 '((type . application)(subtype . octet-stream)
1000 (method . mime-detect-content)))
1002 (ctree-set-calist-with-default
1003 'mime-acting-condition
1004 '((mode . "extract")
1005 (method . mime-save-content)))
1007 (ctree-set-calist-strictly
1008 'mime-acting-condition
1009 '((type . text)(subtype . x-rot13-47)(mode . "play")
1010 (method . mime-view-caesar)))
1011 (ctree-set-calist-strictly
1012 'mime-acting-condition
1013 '((type . text)(subtype . x-rot13-47-48)(mode . "play")
1014 (method . mime-view-caesar)))
1016 (ctree-set-calist-strictly
1017 'mime-acting-condition
1018 '((type . message)(subtype . rfc822)(mode . "play")
1019 (method . mime-view-message/rfc822)))
1020 (ctree-set-calist-strictly
1021 'mime-acting-condition
1022 '((type . message)(subtype . partial)(mode . "play")
1023 (method . mime-store-message/partial-piece)))
1025 (ctree-set-calist-strictly
1026 'mime-acting-condition
1027 '((type . message)(subtype . external-body)
1028 ("access-type" . "anon-ftp")
1029 (method . mime-view-message/external-anon-ftp)))
1031 (ctree-set-calist-strictly
1032 'mime-acting-condition
1033 '((type . message)(subtype . external-body)
1034 ("access-type" . "url")
1035 (method . mime-view-message/external-url)))
1037 (ctree-set-calist-strictly
1038 'mime-acting-condition
1039 '((type . application)(subtype . octet-stream)
1040 (method . mime-save-content)))
1043 ;;; @ quitting method
1046 (defvar mime-preview-quitting-method-alist
1047 '((mime-show-message-mode
1048 . mime-preview-quitting-method-for-mime-show-message-mode))
1049 "Alist of `major-mode' vs. quitting-method of mime-view.")
1051 (defvar mime-preview-over-to-previous-method-alist nil
1052 "Alist of `major-mode' vs. over-to-previous-method of mime-view.")
1054 (defvar mime-preview-over-to-next-method-alist nil
1055 "Alist of `major-mode' vs. over-to-next-method of mime-view.")
1058 ;;; @ following method
1061 (defvar mime-preview-following-method-alist nil
1062 "Alist of `major-mode' vs. following-method of mime-view.")
1064 (defvar mime-view-following-required-fields-list
1071 (defun mime-display-entity (entity &optional situation
1072 default-situation preview-buffer)
1073 "Display mime-entity ENTITY."
1075 (setq preview-buffer (current-buffer)))
1076 (in-calist-package 'mime-view)
1079 (or (ctree-match-calist mime-preview-condition
1080 (append (mime-entity-situation entity)
1082 default-situation)))
1083 (let ((button-is-invisible
1084 (or (eq (cdr (assq 'entity-button situation)) 'invisible)
1085 (not (mime-view-entity-button-visible-p entity))))
1087 (eq (cdr (assq 'header situation)) 'visible))
1088 (header-presentation-method
1089 (or (cdr (assq 'header-presentation-method situation))
1090 (cdr (assq (cdr (assq 'major-mode situation))
1091 mime-header-presentation-method-alist))))
1093 (eq (cdr (assq 'body situation)) 'visible))
1094 (body-presentation-method
1095 (cdr (assq 'body-presentation-method situation)))
1096 (children (mime-entity-children entity))
1098 ;; Check if attachment is specified.
1099 ;; if inline is forced or not.
1100 (unless (or (eq t mime-view-force-inline-types)
1101 (memq (mime-entity-media-type entity)
1102 mime-view-force-inline-types)
1103 (memq (mime-view-entity-type/subtype entity)
1104 mime-view-force-inline-types)
1105 ;; whether Content-Disposition header exists.
1106 (not (mime-entity-content-disposition entity))
1108 (mime-content-disposition-type
1109 (mime-entity-content-disposition entity))))
1110 ;; This is attachment
1111 (setq header-is-visible nil
1112 body-is-visible nil))
1113 (set-buffer preview-buffer)
1116 (narrow-to-region nb nb)
1117 (if (and (not button-is-invisible)
1118 (mime-view-entity-button-visible-p entity))
1119 (mime-view-insert-entity-button entity
1120 ;; work around composite type
1123 (when header-is-visible
1125 (if header-presentation-method
1126 (funcall header-presentation-method entity situation)
1127 (mime-insert-header entity
1128 mime-view-ignored-field-list
1129 mime-view-visible-field-list))
1130 (run-hooks 'mime-display-header-hook)
1131 (put-text-property nhb (point-max) 'mime-view-entity-header entity)
1132 (goto-char (point-max))
1136 ((and body-is-visible
1137 (functionp body-presentation-method))
1138 (funcall body-presentation-method entity situation))
1140 (when button-is-invisible
1141 (goto-char (point-max))
1142 (mime-view-insert-entity-button entity
1143 ;; work around composite type
1146 (unless header-is-visible
1147 (goto-char (point-max))
1149 (setq ne (point-max)))
1150 (put-text-property nb ne 'mime-view-entity entity)
1151 (put-text-property nb ne 'mime-view-situation situation)
1152 (put-text-property nbb ne 'mime-view-entity-body entity)
1155 (if (functionp body-presentation-method)
1156 (funcall body-presentation-method entity situation)
1157 (mime-display-multipart/mixed entity situation)))))
1160 ;;; @ MIME viewer mode
1163 (defconst mime-view-menu-title "MIME-View")
1164 (defconst mime-view-menu-list
1165 '((up "Move to upper entity" mime-preview-move-to-upper)
1166 (previous "Move to previous entity" mime-preview-move-to-previous)
1167 (next "Move to next entity" mime-preview-move-to-next)
1168 (scroll-down "Scroll-down" mime-preview-scroll-down-entity)
1169 (scroll-up "Scroll-up" mime-preview-scroll-up-entity)
1170 (play "Play current entity" mime-preview-play-current-entity)
1171 (extract "Extract current entity" mime-preview-extract-current-entity)
1172 (print "Print current entity" mime-preview-print-current-entity)
1173 (raw "View text without code conversion" mime-preview-inline)
1174 (text "View text with code conversion" mime-preview-text)
1175 (type "View internally as type" mime-preview-type))
1176 "Menu for MIME Viewer.")
1178 (cond ((featurep 'xemacs)
1179 (defvar mime-view-xemacs-popup-menu
1180 (cons mime-view-menu-title
1183 (vector (nth 1 item)(nth 2 item) t)))
1184 mime-view-menu-list)))
1185 (defun mime-view-xemacs-popup-menu (event)
1186 "Popup the menu in the MIME Viewer buffer"
1188 (select-window (event-window event))
1189 (set-buffer (event-buffer event))
1190 (popup-menu 'mime-view-xemacs-popup-menu))
1191 (defvar mouse-button-2 'button2))
1193 (defvar mouse-button-2 [mouse-2])))
1195 (defun mime-view-define-keymap (&optional default)
1196 (let ((mime-view-mode-map (if (keymapp default)
1197 (copy-keymap default)
1198 (make-sparse-keymap))))
1199 (define-key mime-view-mode-map
1200 "u" (function mime-preview-move-to-upper))
1201 (define-key mime-view-mode-map
1202 "p" (function mime-preview-move-to-previous))
1203 (define-key mime-view-mode-map
1204 "n" (function mime-preview-move-to-next))
1205 (define-key mime-view-mode-map
1206 "\e\t" (function mime-preview-move-to-previous))
1207 (define-key mime-view-mode-map
1208 "\t" (function mime-preview-move-to-next))
1209 (define-key mime-view-mode-map
1210 " " (function mime-preview-scroll-up-entity))
1211 (define-key mime-view-mode-map
1212 "\M- " (function mime-preview-scroll-down-entity))
1213 (define-key mime-view-mode-map
1214 "\177" (function mime-preview-scroll-down-entity))
1215 (define-key mime-view-mode-map
1216 "\C-m" (function mime-preview-next-line-entity))
1217 (define-key mime-view-mode-map
1218 "\C-\M-m" (function mime-preview-previous-line-entity))
1219 (define-key mime-view-mode-map
1220 "v" (function mime-preview-play-current-entity))
1221 (define-key mime-view-mode-map
1222 "e" (function mime-preview-extract-current-entity))
1223 (define-key mime-view-mode-map
1224 "i" (function mime-preview-inline))
1225 (define-key mime-view-mode-map
1226 "c" (function mime-preview-text))
1227 (define-key mime-view-mode-map
1228 "t" (function mime-preview-type))
1229 (define-key mime-view-mode-map
1230 "b" (function mime-preview-buttonize))
1231 (define-key mime-view-mode-map
1232 "B" (function mime-preview-unbuttonize))
1233 (define-key mime-view-mode-map
1234 "\C-c\C-p" (function mime-preview-print-current-entity))
1235 (define-key mime-view-mode-map
1236 "a" (function mime-preview-follow-current-entity))
1237 (define-key mime-view-mode-map
1238 "q" (function mime-preview-quit))
1239 (define-key mime-view-mode-map
1240 "\C-c\C-x" (function mime-preview-kill-buffer))
1241 ;; (define-key mime-view-mode-map
1242 ;; "<" (function beginning-of-buffer))
1243 ;; (define-key mime-view-mode-map
1244 ;; ">" (function end-of-buffer))
1245 (define-key mime-view-mode-map
1246 "?" (function describe-mode))
1247 (define-key mime-view-mode-map
1248 [tab] (function mime-preview-move-to-next))
1249 (define-key mime-view-mode-map
1250 [delete] (function mime-preview-scroll-down-entity))
1251 (define-key mime-view-mode-map
1252 [backspace] (function mime-preview-scroll-down-entity))
1253 (if (functionp default)
1254 (cond ((featurep 'xemacs)
1255 (set-keymap-default-binding mime-view-mode-map default))
1257 (setq mime-view-mode-map
1258 (append mime-view-mode-map (list (cons t default)))))))
1260 (define-key mime-view-mode-map
1261 mouse-button-2 (function mime-button-dispatcher)))
1262 (cond ((featurep 'xemacs)
1263 (define-key mime-view-mode-map
1264 mouse-button-3 (function mime-view-xemacs-popup-menu)))
1265 ((>= emacs-major-version 19)
1266 (define-key mime-view-mode-map [menu-bar mime-view]
1267 (cons mime-view-menu-title
1268 (make-sparse-keymap mime-view-menu-title)))
1271 (define-key mime-view-mode-map
1272 (vector 'menu-bar 'mime-view (car item))
1273 (cons (nth 1 item)(nth 2 item)))))
1274 (reverse mime-view-menu-list))))
1275 (use-local-map mime-view-mode-map)
1276 (run-hooks 'mime-view-define-keymap-hook)))
1278 (defsubst mime-maybe-hide-echo-buffer ()
1279 "Clear mime-echo buffer and delete window for it."
1280 (let ((buf (get-buffer mime-echo-buffer-name)))
1285 (let ((win (get-buffer-window buf)))
1287 (delete-window win)))
1288 (bury-buffer buf)))))
1290 (defvar mime-view-redisplay nil)
1293 (defun mime-display-message (message &optional preview-buffer
1294 mother default-keymap-or-function
1295 original-major-mode)
1296 "View MESSAGE in MIME-View mode.
1298 Optional argument PREVIEW-BUFFER specifies the buffer of the
1299 presentation. It must be either nil or a name of preview buffer.
1301 Optional argument MOTHER specifies mother-buffer of the preview-buffer.
1303 Optional argument DEFAULT-KEYMAP-OR-FUNCTION is nil, keymap or
1304 function. If it is a keymap, keymap of MIME-View mode will be added
1305 to it. If it is a function, it will be bound as default binding of
1306 keymap of MIME-View mode."
1307 (mime-maybe-hide-echo-buffer)
1308 (let ((win-conf (current-window-configuration)))
1310 (setq preview-buffer
1311 (concat "*Preview-" (mime-entity-name message) "*")))
1312 (or original-major-mode
1313 (setq original-major-mode
1314 (with-current-buffer (mime-entity-header-buffer message)
1316 (let ((inhibit-read-only t))
1317 (set-buffer (get-buffer-create preview-buffer))
1321 (setq mime-mother-buffer mother))
1322 (setq mime-preview-original-window-configuration win-conf)
1323 (setq major-mode 'mime-view-mode)
1324 (setq mode-name "MIME-View")
1325 (mime-display-entity message nil
1326 `((entity-button . invisible)
1328 (major-mode . ,original-major-mode))
1330 (mime-view-define-keymap default-keymap-or-function)
1331 (set (make-local-variable 'line-move-ignore-invisible) t)
1333 (next-single-property-change (point-min) 'mime-view-entity)))
1336 (goto-char (point-min))
1337 (search-forward "\n\n" nil t)))
1338 (run-hooks 'mime-view-mode-hook)
1339 (set-buffer-modified-p nil)
1340 (setq buffer-read-only t)
1344 (defun mime-view-buffer (&optional raw-buffer preview-buffer mother
1345 default-keymap-or-function
1346 representation-type)
1347 "View RAW-BUFFER in MIME-View mode.
1348 Optional argument PREVIEW-BUFFER is either nil or a name of preview
1350 Optional argument DEFAULT-KEYMAP-OR-FUNCTION is nil, keymap or
1351 function. If it is a keymap, keymap of MIME-View mode will be added
1352 to it. If it is a function, it will be bound as default binding of
1353 keymap of MIME-View mode.
1354 Optional argument REPRESENTATION-TYPE is representation-type of
1355 message. It must be nil, `binary' or `cooked'. If it is nil,
1356 `cooked' is used as default."
1359 (setq raw-buffer (current-buffer)))
1360 (or representation-type
1361 (setq representation-type
1363 (set-buffer raw-buffer)
1364 (cdr (or (assq major-mode mime-raw-representation-type-alist)
1365 (assq t mime-raw-representation-type-alist))))))
1366 (if (eq representation-type 'binary)
1367 (setq representation-type 'buffer))
1368 (setq preview-buffer (mime-display-message
1369 (mime-open-entity representation-type raw-buffer)
1370 preview-buffer mother default-keymap-or-function))
1371 (or (get-buffer-window preview-buffer)
1372 (let ((r-win (get-buffer-window raw-buffer)))
1374 (set-window-buffer r-win preview-buffer)
1375 (let ((m-win (and mother (get-buffer-window mother))))
1377 (set-window-buffer m-win preview-buffer)
1378 (switch-to-buffer preview-buffer)))))))
1380 (defun mime-view-mode (&optional mother ctl encoding
1381 raw-buffer preview-buffer
1382 default-keymap-or-function)
1383 "Major mode for viewing MIME message.
1385 Here is a list of the standard keys for mime-view-mode.
1390 u Move to upper content
1391 p or M-TAB Move to previous content
1392 n or TAB Move to next content
1393 SPC Scroll up or move to next content
1394 M-SPC or DEL Scroll down or move to previous content
1395 RET Move to next line
1396 M-RET Move to previous line
1397 v Decode current content as `play mode'
1398 e Decode current content as `extract mode'
1399 C-c C-p Decode current content as `print mode'
1400 a Followup to current content.
1402 button-2 Move to point under the mouse cursor
1403 and decode current content as `play mode'"
1405 (unless mime-view-redisplay
1407 (if raw-buffer (set-buffer raw-buffer))
1410 (or (assq major-mode mime-raw-representation-type-alist)
1411 (assq t mime-raw-representation-type-alist)))))
1412 (if (eq type 'binary)
1413 (setq type 'buffer))
1414 (setq mime-message-structure (mime-open-entity type raw-buffer))
1415 (or (mime-entity-content-type mime-message-structure)
1416 (mime-entity-set-content-type-internal
1417 mime-message-structure ctl)))
1418 (or (mime-entity-encoding mime-message-structure)
1419 (mime-entity-set-encoding-internal mime-message-structure encoding))))
1420 (mime-display-message mime-message-structure preview-buffer
1421 mother default-keymap-or-function))
1427 (autoload 'mime-preview-play-current-entity "mime-play"
1428 "Play current entity." t)
1430 (defun mime-preview-extract-current-entity (&optional ignore-examples)
1431 "Extract current entity into file (maybe).
1432 It decodes current entity to call internal or external method as
1433 \"extract\" mode. The method is selected from variable
1434 `mime-acting-condition'."
1436 (mime-preview-play-current-entity ignore-examples "extract"))
1438 (defun mime-preview-print-current-entity (&optional ignore-examples)
1439 "Print current entity (maybe).
1440 It decodes current entity to call internal or external method as
1441 \"print\" mode. The method is selected from variable
1442 `mime-acting-condition'."
1444 (mime-preview-play-current-entity ignore-examples "print"))
1450 (defun mime-preview-follow-current-entity ()
1451 "Write follow message to current entity.
1452 It calls following-method selected from variable
1453 `mime-preview-following-method-alist'."
1456 (while (null (setq entity
1457 (get-text-property (point) 'mime-view-entity)))
1460 (previous-single-property-change (point) 'mime-view-entity))
1463 (entity-node-id (mime-entity-node-id entity))
1464 (len (length entity-node-id)))
1467 (if (eq (next-single-property-change (point-min)
1472 ((eq (next-single-property-change p-beg 'mime-view-entity)
1474 (setq p-beg (point))))
1475 (setq p-end (next-single-property-change p-beg 'mime-view-entity))
1477 (setq p-end (point-max)))
1478 ((null entity-node-id)
1479 (setq p-end (point-max)))
1486 (next-single-property-change
1487 (point) 'mime-view-entity))
1489 (let ((rc (mime-entity-node-id
1490 (get-text-property (point)
1491 'mime-view-entity))))
1492 (or (equal entity-node-id
1493 (nthcdr (- (length rc) len) rc))
1496 (setq p-end (point-max))))))
1498 (previous-single-property-change p-end 'mime-view-entity-header))
1499 (if (or (null ph-end)
1501 (setq ph-end p-beg))
1502 (let* ((mode (mime-preview-original-major-mode 'recursive))
1504 (format "%s-%s" (buffer-name) (reverse entity-node-id)))
1506 (the-buf (current-buffer))
1509 (set-buffer (setq new-buf (get-buffer-create new-name)))
1512 (insert (buffer-substring-no-properties ph-end p-end the-buf))
1513 (when (= ph-end p-beg)
1514 (goto-char (point-min))
1516 (goto-char (point-min))
1517 (let ((current-entity
1518 (if (and (eq (mime-entity-media-type entity) 'message)
1519 (eq (mime-entity-media-subtype entity) 'rfc822))
1520 (car (mime-entity-children entity))
1523 (while (and current-entity
1526 (with-current-buffer
1527 (mime-entity-header-buffer current-entity)
1530 (mime-entity-header-start-point
1532 (mime-entity-header-end-point
1534 (std11-header-string-except
1537 (apply (function regexp-or) fields)
1539 (if (and (eq (mime-entity-media-type
1540 current-entity) 'message)
1541 (eq (mime-entity-media-subtype
1542 current-entity) 'rfc822))
1547 (setq fields (std11-collect-field-names)
1548 current-entity (mime-entity-parent current-entity))))
1549 (let ((rest mime-view-following-required-fields-list)
1552 (setq field-name (car rest))
1553 (or (std11-field-body field-name)
1556 (set-buffer the-buf)
1558 (when mime-mother-buffer
1559 (set-buffer mime-mother-buffer)
1560 (mime-entity-fetch-field
1561 (get-text-property (point)
1565 (insert (concat field-name ": " ret "\n")))))
1566 (setq rest (cdr rest))))
1567 (mime-decode-header-in-buffer))
1568 (let ((f (cdr (assq mode mime-preview-following-method-alist))))
1573 "Sorry, following method for %s is not implemented yet."
1580 (defun mime-preview-move-to-upper ()
1581 "Move to upper entity.
1582 If there is no upper entity, call function `mime-preview-quit'."
1585 (while (null (setq cinfo
1586 (get-text-property (point) 'mime-view-entity)))
1588 (let ((r (mime-entity-parent cinfo))
1591 (while (setq point (previous-single-property-change
1592 (point) 'mime-view-entity))
1594 (when (eq r (get-text-property (point) 'mime-view-entity))
1595 (if (or (eq mime-preview-move-scroll t)
1596 (and mime-preview-move-scroll
1599 (move-to-window-line -1)
1600 (forward-line (* -1 next-screen-context-lines))
1603 (recenter next-screen-context-lines))
1605 (mime-preview-quit)))))
1607 (defun mime-preview-move-to-previous ()
1608 "Move to previous entity.
1609 If there is no previous entity, it calls function registered in
1610 variable `mime-preview-over-to-previous-method-alist'."
1612 (while (and (not (bobp))
1613 (null (get-text-property (point) 'mime-view-entity)))
1615 (let ((point (previous-single-property-change (point) 'mime-view-entity)))
1617 (>= point (point-min)))
1618 (if (get-text-property (1- point) 'mime-view-entity)
1619 (progn (goto-char point)
1621 (or (eq mime-preview-move-scroll t)
1622 (and mime-preview-move-scroll
1625 (move-to-window-line 0)
1626 (forward-line next-screen-context-lines)
1629 (recenter next-screen-context-lines)))
1630 (goto-char (1- point))
1631 (mime-preview-move-to-previous))
1632 (let ((f (assq (mime-preview-original-major-mode)
1633 mime-preview-over-to-previous-method-alist)))
1635 (funcall (cdr f)))))))
1637 (defun mime-preview-move-to-next ()
1638 "Move to next entity.
1639 If there is no previous entity, it calls function registered in
1640 variable `mime-preview-over-to-next-method-alist'."
1642 (while (and (not (eobp))
1643 (null (get-text-property (point) 'mime-view-entity)))
1645 (let ((point (next-single-property-change (point) 'mime-view-entity)))
1647 (<= point (point-max)))
1650 (if (null (get-text-property point 'mime-view-entity))
1651 (mime-preview-move-to-next)
1653 (or (eq mime-preview-move-scroll t)
1654 (and mime-preview-move-scroll
1657 (move-to-window-line -1)
1659 (* -1 next-screen-context-lines))
1662 (recenter next-screen-context-lines))))
1663 (let ((f (assq (mime-preview-original-major-mode)
1664 mime-preview-over-to-next-method-alist)))
1666 (funcall (cdr f)))))))
1668 (defun mime-preview-scroll-up-entity (&optional h)
1669 "Scroll up current entity.
1670 If reached to (point-max), it calls function registered in variable
1671 `mime-preview-over-to-next-method-alist'."
1674 (let ((f (assq (mime-preview-original-major-mode)
1675 mime-preview-over-to-next-method-alist)))
1679 (or (next-single-property-change (point) 'mime-view-entity)
1681 (bottom (window-end (selected-window))))
1684 (not mime-preview-scroll-full-screen))
1685 (progn (goto-char point)
1686 (recenter next-screen-context-lines))
1690 (goto-char (point-max))))))))
1692 (defun mime-preview-scroll-down-entity (&optional h)
1693 "Scroll down current entity.
1694 If reached to (point-min), it calls function registered in variable
1695 `mime-preview-over-to-previous-method-alist'."
1698 (let ((f (assq (mime-preview-original-major-mode)
1699 mime-preview-over-to-previous-method-alist)))
1703 (or (previous-single-property-change (point) 'mime-view-entity)
1705 (top (window-start (selected-window))))
1708 (not mime-preview-scroll-full-screen))
1709 (progn (goto-char point)
1710 (recenter (* -1 next-screen-context-lines)))
1713 (beginning-of-buffer
1714 (goto-char (point-min))))))))
1716 (defun mime-preview-next-line-entity (&optional lines)
1717 "Scroll up one line (or prefix LINES lines).
1718 If LINES is negative, scroll down LINES lines."
1720 (mime-preview-scroll-up-entity (or lines 1)))
1722 (defun mime-preview-previous-line-entity (&optional lines)
1723 "Scrroll down one line (or prefix LINES lines).
1724 If LINES is negative, scroll up LINES lines."
1726 (mime-preview-scroll-down-entity (or lines 1)))
1731 (defun mime-preview-quit ()
1732 "Quit from MIME-preview buffer.
1733 It calls function registered in variable
1734 `mime-preview-quitting-method-alist'."
1736 (let ((r (assq (mime-preview-original-major-mode)
1737 mime-preview-quitting-method-alist)))
1739 (funcall (cdr r)))))
1741 (defun mime-preview-kill-buffer ()
1743 (kill-buffer (current-buffer)))
1749 (provide 'mime-view)
1751 (run-hooks 'mime-view-load-hook)
1753 ;;; mime-view.el ends here