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)))
317 ;;; @ presentation of preview
323 ;;; @@@ predicate function
327 (defun mime-view-entity-type/subtype (entity)
328 (if (not (mime-entity-media-type entity))
330 (intern (format "%s/%s"
331 (mime-entity-media-type entity)
332 (mime-entity-media-subtype entity)))))
334 (defun mime-view-entity-button-visible-p (entity)
335 "Return non-nil if header of ENTITY is visible.
336 You can customize the visibility by changing `mime-view-button-place-alist'."
338 ;; Check current entity
340 (memq (cdr (assq (mime-view-entity-type/subtype entity)
341 mime-view-button-place-alist))
344 (memq (cdr (assq (mime-entity-media-type entity)
345 mime-view-button-place-alist))
347 (and (mime-entity-parent entity)
350 (reverse (mime-entity-children
351 (mime-entity-parent entity)))))))
352 ;; When previous entity exists
355 ;; Check previous entity
359 (mime-view-entity-type/subtype prev-entity)
360 mime-view-button-place-alist))
365 (mime-entity-media-type prev-entity)
366 mime-view-button-place-alist))
368 ;; default for everything.
370 mime-view-button-place-alist))
373 ;;; @@@ entity button generator
376 (defun mime-view-insert-entity-button (entity &optional body-is-invisible)
377 "Insert entity-button of ENTITY."
378 (let ((entity-node-id (mime-entity-node-id entity))
379 (params (mime-entity-parameters entity))
380 (subject (mime-view-entity-title entity)))
383 (let ((access-type (assoc "access-type" params))
384 (num (or (cdr (assoc "x-part-number" params))
385 (if (consp entity-node-id)
388 (format "%s" (1+ num))))
389 (reverse entity-node-id) ".")
392 (let ((server (assoc "server" params)))
393 (setq access-type (cdr access-type))
395 (format "%s %s ([%s] %s)"
396 num subject access-type (cdr server))
397 (let ((site (cdr (assoc "site" params)))
398 (dir (cdr (assoc "directory" params)))
399 (url (cdr (assoc "url" params))))
401 (format "%s %s ([%s] %s)"
402 num subject access-type url)
403 (format "%s %s ([%s] %s:%s)"
404 num subject access-type site dir))))))
406 (let ((media-type (mime-entity-media-type entity))
407 (media-subtype (mime-entity-media-subtype entity))
408 (charset (cdr (assoc "charset" params)))
409 (encoding (mime-entity-encoding entity)))
413 (format " <%s/%s%s%s>"
414 media-type media-subtype
416 (concat "; " charset)
419 (concat " (" encoding ")")
421 (if (>= (+ (current-column)(length rest))(window-width))
424 (if body-is-invisible
427 (function mime-preview-play-current-entity)
428 (if body-is-invisible
435 (defvar mime-header-presentation-method-alist nil
436 "Alist of major mode vs. corresponding header-presentation-method functions.
437 Each element looks like (SYMBOL . FUNCTION).
438 SYMBOL must be major mode in raw-buffer or t. t means default.
439 Interface of FUNCTION must be (ENTITY SITUATION).")
441 (defvar mime-view-ignored-field-list
442 '(".*Received:" ".*Path:" ".*Id:" "^References:"
443 "^Replied:" "^Errors-To:"
444 "^Lines:" "^Sender:" ".*Host:" "^Xref:"
445 "^Content-Type:" "^Precedence:"
446 "^Status:" "^X-VM-.*:")
447 "All fields that match this list will be hidden in MIME preview buffer.
448 Each elements are regexp of field-name.")
450 (defvar mime-view-visible-field-list '("^Dnas.*:" "^Message-Id:")
451 "All fields that match this list will be displayed in MIME preview buffer.
452 Each elements are regexp of field-name.")
458 ;;; @@@ predicate function
461 (in-calist-package 'mime-view)
463 (defun mime-calist::field-match-method-as-default-rule (calist
464 field-type field-value)
465 (let ((s-field (assq field-type calist)))
466 (cond ((null s-field)
467 (cons (cons field-type field-value) calist))
470 (define-calist-field-match-method
471 'header #'mime-calist::field-match-method-as-default-rule)
473 (define-calist-field-match-method
474 'body #'mime-calist::field-match-method-as-default-rule)
477 (defvar mime-preview-condition nil
478 "Condition-tree about how to display entity.")
480 ;;(ctree-set-calist-strictly
481 ;; 'mime-preview-condition '((type . application)(subtype . octet-stream)
483 ;; (body . visible)))
485 (ctree-set-calist-strictly
486 'mime-preview-condition '((type . application)(subtype . t)
489 (ctree-set-calist-strictly
490 'mime-preview-condition '((type . application)(subtype . t)
494 (ctree-set-calist-strictly
495 'mime-preview-condition '((type . application)(subtype . pgp)
498 (ctree-set-calist-strictly
499 'mime-preview-condition '((type . application)(subtype . x-latex)
502 (ctree-set-calist-strictly
503 'mime-preview-condition '((type . application)(subtype . x-selection)
506 (ctree-set-calist-strictly
507 'mime-preview-condition '((type . application)(subtype . x-comment)
510 (ctree-set-calist-strictly
511 'mime-preview-condition '((type . message)(subtype . delivery-status)
514 (ctree-set-calist-strictly
515 'mime-preview-condition
517 (body-presentation-method . mime-display-text/plain)))
519 (ctree-set-calist-strictly
520 'mime-preview-condition
523 (body-presentation-method . mime-display-text/plain)))
525 (ctree-set-calist-strictly
526 'mime-preview-condition
527 '((type . text)(subtype . enriched)
529 (body-presentation-method . mime-display-text/enriched)))
531 (ctree-set-calist-strictly
532 'mime-preview-condition
533 '((type . text)(subtype . richtext)
535 (body-presentation-method . mime-display-text/richtext)))
537 (ctree-set-calist-strictly
538 'mime-preview-condition
539 '((type . application)(subtype . x-postpet)
541 (body-presentation-method . mime-display-application/x-postpet)))
543 (ctree-set-calist-strictly
544 'mime-preview-condition '((type . application)(subtype . t)
547 (body-presentation-method . mime-display-detect-application/octet-stream)))
549 (ctree-set-calist-strictly
550 'mime-preview-condition
551 '((type . text)(subtype . t)
553 (body-presentation-method . mime-display-text/plain)))
555 (ctree-set-calist-strictly
556 'mime-preview-condition
557 '((type . text)(subtype . x-rot13-47-48)
559 (body-presentation-method . mime-display-text/x-rot13-47-48)))
561 (ctree-set-calist-strictly
562 'mime-preview-condition
563 '((type . multipart)(subtype . alternative)
565 (body-presentation-method . mime-display-multipart/alternative)))
567 (ctree-set-calist-strictly
568 'mime-preview-condition '((type . message)(subtype . partial)
569 (body-presentation-method
570 . mime-display-message/partial-button)))
572 (ctree-set-calist-strictly
573 'mime-preview-condition '((type . message)(subtype . rfc822)
574 (body-presentation-method . nil)
575 (childrens-situation (header . visible)
576 (entity-button . invisible))))
578 (ctree-set-calist-strictly
579 'mime-preview-condition '((type . message)(subtype . news)
580 (body-presentation-method . nil)
581 (childrens-situation (header . visible)
582 (entity-button . invisible))))
585 ;;; @@@ entity presentation
588 (defun mime-display-text/plain (entity situation)
590 (narrow-to-region (point-max)(point-max))
591 (mime-insert-text-content entity)
592 (run-hooks 'mime-text-decode-hook)
593 (goto-char (point-max))
594 (if (not (eq (char-after (1- (point))) ?\n))
596 (mime-add-url-buttons)
597 (run-hooks 'mime-display-text/plain-hook)))
599 (defun mime-display-text/richtext (entity situation)
601 (narrow-to-region (point-max)(point-max))
602 (mime-insert-text-content entity)
603 (run-hooks 'mime-text-decode-hook)
604 (let ((beg (point-min)))
605 (remove-text-properties beg (point-max) '(face nil))
606 (richtext-decode beg (point-max)))))
608 (defun mime-display-text/enriched (entity situation)
610 (narrow-to-region (point-max)(point-max))
611 (mime-insert-text-content entity)
612 (run-hooks 'mime-text-decode-hook)
613 (let ((beg (point-min)))
614 (remove-text-properties beg (point-max) '(face nil))
615 (enriched-decode beg (point-max)))))
617 (defun mime-display-text/x-rot13-47-48 (entity situation)
619 (narrow-to-region (point-max)(point-max))
620 (mime-insert-text-content entity)
621 (goto-char (point-max))
622 (if (not (eq (char-after (1- (point))) ?\n))
624 (mule-caesar-region (point-min) (point-max))
625 (mime-add-url-buttons)))
627 (put 'unpack 'lisp-indent-function 1)
628 (defmacro unpack (string &rest body)
629 `(let* ((*unpack*string* (string-as-unibyte ,string))
633 (defun unpack-skip (len)
634 (setq *unpack*index* (+ len *unpack*index*)))
636 (defun unpack-fixed (len)
638 (substring *unpack*string* *unpack*index* (+ *unpack*index* len))
641 (defun unpack-byte ()
642 (char-int (aref (unpack-fixed 1) 0)))
644 (defun unpack-short ()
645 (let* ((b0 (unpack-byte))
649 (defun unpack-long ()
650 (let* ((s0 (unpack-short))
652 (+ (* 65536 s0) s1)))
654 (defun unpack-string ()
655 (let ((len (unpack-byte)))
658 (defun unpack-string-sjis ()
659 (decode-mime-charset-string (unpack-string) 'shift_jis))
661 (defun postpet-decode (string)
666 (set-alist 'res 'carryingcount (unpack-long))
668 (set-alist 'res 'sentyear (unpack-short))
669 (set-alist 'res 'sentmonth (unpack-short))
670 (set-alist 'res 'sentday (unpack-short))
672 (set-alist 'res 'petname (unpack-string-sjis))
673 (set-alist 'res 'owner (unpack-string-sjis))
674 (set-alist 'res 'pettype (unpack-fixed 4))
675 (set-alist 'res 'health (unpack-short))
677 (set-alist 'res 'sex (unpack-long))
679 (set-alist 'res 'brain (unpack-byte))
681 (set-alist 'res 'happiness (unpack-byte))
683 (set-alist 'res 'petbirthyear (unpack-short))
684 (set-alist 'res 'petbirthmonth (unpack-short))
685 (set-alist 'res 'petbirthday (unpack-short))
687 (set-alist 'res 'from (unpack-string))
694 (set-alist 'res 'treasure (unpack-short))
695 (set-alist 'res 'money (unpack-long))
699 (defun mime-display-application/x-postpet (entity situation)
701 (narrow-to-region (point-max)(point-max))
702 (let ((pet (postpet-decode (mime-entity-content entity))))
704 (insert "Petname: " (cdr (assq 'petname pet)) "\n"
705 "Owner: " (cdr (assq 'owner pet)) "\n"
706 "Pettype: " (cdr (assq 'pettype pet)) "\n"
707 "From: " (cdr (assq 'from pet)) "\n"
708 "CarryingCount: " (int-to-string (cdr (assq 'carryingcount pet))) "\n"
709 "SentYear: " (int-to-string (cdr (assq 'sentyear pet))) "\n"
710 "SentMonth: " (int-to-string (cdr (assq 'sentmonth pet))) "\n"
711 "SentDay: " (int-to-string (cdr (assq 'sentday pet))) "\n"
712 "PetbirthYear: " (int-to-string (cdr (assq 'petbirthyear pet))) "\n"
713 "PetbirthMonth: " (int-to-string (cdr (assq 'petbirthmonth pet))) "\n"
714 "PetbirthDay: " (int-to-string (cdr (assq 'petbirthday pet))) "\n"
715 "Health: " (int-to-string (cdr (assq 'health pet))) "\n"
716 "Sex: " (int-to-string (cdr (assq 'sex pet))) "\n"
717 "Brain: " (int-to-string (cdr (assq 'brain pet))) "\n"
718 "Happiness: " (int-to-string (cdr (assq 'happiness pet))) "\n"
719 "Treasure: " (int-to-string (cdr (assq 'treasure pet))) "\n"
720 "Money: " (int-to-string (cdr (assq 'money pet))) "\n")
721 (insert "Invalid format\n"))
722 (run-hooks 'mime-display-application/x-postpet-hook))))
725 (defvar mime-view-announcement-for-message/partial
726 (if (and (>= emacs-major-version 19) window-system)
728 \[[ This is message/partial style split message. ]]
729 \[[ Please press `v' key in this buffer ]]
730 \[[ or click here by mouse button-2. ]]"
732 \[[ This is message/partial style split message. ]]
733 \[[ Please press `v' key in this buffer. ]]"))
735 (defun mime-display-message/partial-button (&optional entity situation)
737 (goto-char (point-max))
738 (if (not (search-backward "\n\n" nil t))
740 (goto-char (point-max))
741 (narrow-to-region (point-max)(point-max))
742 (insert mime-view-announcement-for-message/partial)
743 (mime-add-button (point-min)(point-max)
744 #'mime-preview-play-current-entity)))
746 (defun mime-display-multipart/mixed (entity situation)
747 (let ((children (mime-entity-children entity))
748 (original-major-mode-cell (assq 'major-mode situation))
750 (cdr (assq 'childrens-situation situation))))
751 (if original-major-mode-cell
752 (setq default-situation
753 (cons original-major-mode-cell default-situation)))
755 (mime-display-entity (car children) nil default-situation)
756 (setq children (cdr children)))))
758 (defun mime-display-multipart/alternative (entity situation)
759 (let* ((children (mime-entity-children entity))
760 (original-major-mode-cell (assq 'major-mode situation))
762 (cdr (assq 'childrens-situation situation)))
767 (if original-major-mode-cell
768 (setq default-situation
769 (cons original-major-mode-cell default-situation)))
774 (or (ctree-match-calist
775 mime-preview-condition
776 (append (mime-entity-situation child)
779 (if (cdr (assq 'body-presentation-method situation))
784 (cdr (assq 'type situation))
785 (cdr (assq 'subtype situation)))
786 mime-view-type-subtype-score-alist)
788 (cdr (assq 'type situation))
789 mime-view-type-subtype-score-alist)
792 mime-view-type-subtype-score-alist)))))
793 (if (> score max-score)
801 (let ((child (car children))
802 (situation (car situations)))
803 (mime-display-entity child (if (= i p)
805 (del-alist 'body-presentation-method
806 (copy-alist situation)))))
807 (setq children (cdr children)
808 situations (cdr situations)
811 (defun mime-display-detect-application/octet-stream (entity situation)
812 "Detect unknown ENTITY and display it inline.
813 This can only handle gzipped contents."
814 (or (and (mime-entity-filename entity)
815 (string-match "\\.gz$" (mime-entity-filename entity))
816 (mime-display-gzipped entity situation))
817 (mime-display-text/plain entity situation)))
819 (defun mime-display-gzipped (entity situation)
820 "Ungzip gzipped part and display."
823 (insert (mime-entity-content entity))
825 (call-process-region (point-min) (point-max) "gzip" t t
827 (buffer-string (point-min) (point-max))))
830 (defun mime-preview-inline ()
831 "View part as text without code conversion."
833 (let ((inhibit-read-only t)
834 (entity (get-text-property (point) 'mime-view-entity))
835 (situation (get-text-property (point) 'mime-view-situation))
838 (not (get-text-property (point) 'mime-view-entity-header))
839 (not (memq (mime-entity-media-type entity)
840 '(multipart message))))
841 (setq start (or (and (not (mime-entity-parent entity))
842 (1+ (previous-single-property-change
844 'mime-view-entity-header)))
845 (and (not (eq (point) (point-min)))
846 (not (eq (get-text-property (1- (point))
850 (previous-single-property-change (point)
855 (or (next-single-property-change (point)
859 (if (mime-view-entity-button-visible-p entity)
860 (mime-view-insert-entity-button entity))
861 (insert (mime-entity-content entity))
862 (if (and (bolp) (eolp))
865 (add-text-properties start (point)
866 (list 'mime-view-entity entity
867 'mime-view-situation situation))
870 (defun mime-preview-text (&optional ask-coding)
871 "View part as text. MIME charset will be guessed automatically.
872 With prefix, it prompts for coding-system."
874 (let ((inhibit-read-only t)
875 (entity (get-text-property (point) 'mime-view-entity))
876 (situation (get-text-property (point) 'mime-view-situation))
877 (coding (if ask-coding
878 (or (read-coding-system "Coding system: ")
883 (not (get-text-property (point) 'mime-view-entity-header))
884 (not (memq (mime-entity-media-type entity)
885 '(multipart message))))
886 (setq start (or (and (not (mime-entity-parent entity))
887 (1+ (previous-single-property-change
889 'mime-view-entity-header)))
890 (and (not (eq (point) (point-min)))
891 (not (eq (get-text-property (1- (point))
895 (previous-single-property-change (point)
900 (or (next-single-property-change (point)
904 (if (mime-view-entity-button-visible-p entity)
905 (mime-view-insert-entity-button entity))
906 (insert (decode-coding-string (mime-entity-content entity) coding))
907 (if (and (bolp) (eolp))
910 (add-text-properties start (point)
911 (list 'mime-view-entity entity
912 'mime-view-situation situation))
916 (defun mime-preview-type ()
917 "View part as text without code conversion."
919 (let ((inhibit-read-only t)
920 (entity (get-text-property (point) 'mime-view-entity))
921 (situation (get-text-property (point) 'mime-view-situation))
922 (mime-view-force-inline-types t)
925 (not (get-text-property (point) 'mime-view-entity-header))
926 (not (memq (mime-entity-media-type entity)
927 '(multipart message))))
928 (setq start (or (and (not (mime-entity-parent entity))
929 (1+ (previous-single-property-change
931 'mime-view-entity-header)))
932 (and (not (eq (point) (point-min)))
933 (not (eq (get-text-property (1- (point))
937 (previous-single-property-change (point)
942 (or (next-single-property-change (point)
947 (narrow-to-region (point) (point))
948 (mime-display-entity entity (if (eq (assq 'body situation)
951 (put-alist 'body 'visible
953 (if (and (bolp) (eolp))
956 (defun mime-preview-buttonize ()
959 (goto-char (point-min))
960 (let ((inhibit-read-only t)
962 (while (setq point (next-single-property-change
963 (point) 'mime-view-entity))
965 (unless (get-text-property (point) 'mime-button-callback)
966 (mime-view-insert-entity-button
967 (get-text-property (point) 'mime-view-entity)))))))
969 (defun mime-preview-unbuttonize ()
972 (goto-char (point-min))
973 (let ((inhibit-read-only t)
975 (while (setq point (next-single-property-change
976 (point) 'mime-view-entity))
978 (if (get-text-property (point) 'mime-button-callback)
979 (delete-region (point) (save-excursion
981 (next-single-property-change
982 (point) 'mime-button-callback)))))))))
985 ;;; @ acting-condition
988 (defvar mime-acting-condition nil
989 "Condition-tree about how to process entity.")
991 (if (file-readable-p mailcap-file)
992 (let ((entries (mailcap-parse-file)))
994 (let ((entry (car entries))
997 (let* ((field (car entry))
998 (field-type (car field)))
999 (cond ((eq field-type 'view) (setq view field))
1000 ((eq field-type 'print) (setq print field))
1001 ((memq field-type '(compose composetyped edit)))
1002 (t (setq shared (cons field shared)))))
1003 (setq entry (cdr entry)))
1004 (setq shared (nreverse shared))
1005 (ctree-set-calist-with-default
1006 'mime-acting-condition
1007 (append shared (list '(mode . "play")(cons 'method (cdr view)))))
1009 (ctree-set-calist-with-default
1010 'mime-acting-condition
1012 (list '(mode . "print")(cons 'method (cdr view)))))))
1013 (setq entries (cdr entries)))))
1015 (ctree-set-calist-strictly
1016 'mime-acting-condition
1017 '((type . application)(subtype . octet-stream)
1019 (method . mime-detect-content)))
1021 (ctree-set-calist-with-default
1022 'mime-acting-condition
1023 '((mode . "extract")
1024 (method . mime-save-content)))
1026 (ctree-set-calist-strictly
1027 'mime-acting-condition
1028 '((type . text)(subtype . x-rot13-47)(mode . "play")
1029 (method . mime-view-caesar)))
1030 (ctree-set-calist-strictly
1031 'mime-acting-condition
1032 '((type . text)(subtype . x-rot13-47-48)(mode . "play")
1033 (method . mime-view-caesar)))
1035 (ctree-set-calist-strictly
1036 'mime-acting-condition
1037 '((type . message)(subtype . rfc822)(mode . "play")
1038 (method . mime-view-message/rfc822)))
1039 (ctree-set-calist-strictly
1040 'mime-acting-condition
1041 '((type . message)(subtype . partial)(mode . "play")
1042 (method . mime-store-message/partial-piece)))
1044 (ctree-set-calist-strictly
1045 'mime-acting-condition
1046 '((type . message)(subtype . external-body)
1047 ("access-type" . "anon-ftp")
1048 (method . mime-view-message/external-anon-ftp)))
1050 (ctree-set-calist-strictly
1051 'mime-acting-condition
1052 '((type . message)(subtype . external-body)
1053 ("access-type" . "url")
1054 (method . mime-view-message/external-url)))
1056 (ctree-set-calist-strictly
1057 'mime-acting-condition
1058 '((type . application)(subtype . octet-stream)
1059 (method . mime-save-content)))
1062 ;;; @ quitting method
1065 (defvar mime-preview-quitting-method-alist
1066 '((mime-show-message-mode
1067 . mime-preview-quitting-method-for-mime-show-message-mode))
1068 "Alist of `major-mode' vs. quitting-method of mime-view.")
1070 (defvar mime-preview-over-to-previous-method-alist nil
1071 "Alist of `major-mode' vs. over-to-previous-method of mime-view.")
1073 (defvar mime-preview-over-to-next-method-alist nil
1074 "Alist of `major-mode' vs. over-to-next-method of mime-view.")
1077 ;;; @ following method
1080 (defvar mime-preview-following-method-alist nil
1081 "Alist of `major-mode' vs. following-method of mime-view.")
1083 (defvar mime-view-following-required-fields-list
1090 (defun mime-display-entity (entity &optional situation
1091 default-situation preview-buffer)
1092 "Display mime-entity ENTITY."
1094 (setq preview-buffer (current-buffer)))
1095 (in-calist-package 'mime-view)
1098 (or (ctree-match-calist mime-preview-condition
1099 (append (mime-entity-situation entity)
1101 default-situation)))
1102 (let ((button-is-visible
1104 (or (eq (or (cdr (assq '*entity-button situation))
1105 (cdr (assq 'entity-button situation)))
1107 (and (not (eq (or (cdr (assq '*entity-button situation))
1108 (cdr (assq 'entity-button situation)))
1110 (mime-view-entity-button-visible-p entity))))
1112 (mime-view-header-is-visible situation))
1113 (header-presentation-method
1114 (or (cdr (assq 'header-presentation-method situation))
1115 (cdr (assq (cdr (assq 'major-mode situation))
1116 mime-header-presentation-method-alist))))
1118 (mime-view-body-is-visible situation))
1119 (body-presentation-method
1120 (cdr (assq 'body-presentation-method situation)))
1121 (children (mime-entity-children entity))
1122 (children-is-invisible (eq (cdr (assq '*children situation))
1125 ;; Check if attachment is specified.
1126 ;; if inline is forced or not.
1127 (unless (or (eq t mime-view-force-inline-types)
1128 (memq (mime-entity-media-type entity)
1129 mime-view-force-inline-types)
1130 (memq (mime-view-entity-type/subtype entity)
1131 mime-view-force-inline-types)
1132 ;; whether Content-Disposition header exists.
1133 (not (mime-entity-content-disposition entity))
1135 (mime-content-disposition-type
1136 (mime-entity-content-disposition entity))))
1137 ;; This is attachment
1138 (setq header-is-visible nil
1139 body-is-visible nil)
1140 (put-alist 'header 'invisible situation)
1141 (put-alist 'body 'invisible situation))
1142 (set-buffer preview-buffer)
1145 (narrow-to-region nb nb)
1146 (if button-is-visible
1147 (mime-view-insert-entity-button entity
1148 ;; work around composite type
1151 (when header-is-visible
1153 (if header-presentation-method
1154 (funcall header-presentation-method entity situation)
1155 (mime-insert-header entity
1156 mime-view-ignored-field-list
1157 mime-view-visible-field-list))
1158 (run-hooks 'mime-display-header-hook)
1159 (put-text-property nhb (point-max) 'mime-view-entity-header entity)
1160 (goto-char (point-max))
1164 ((and body-is-visible
1165 (functionp body-presentation-method))
1166 (funcall body-presentation-method entity situation))
1168 ;; When both body and button is not displayed,
1169 ;; there should be a button to indicate there's a part.
1170 (unless button-is-visible
1171 (goto-char (point-max))
1172 (mime-view-insert-entity-button entity
1173 ;; work around composite type
1176 (unless header-is-visible
1177 (goto-char (point-max))
1179 (setq ne (point-max)))
1180 (put-text-property nb ne 'mime-view-entity entity)
1181 (put-text-property nb ne 'mime-view-situation situation)
1182 (put-text-property nbb ne 'mime-view-entity-body entity)
1185 (not children-is-invisible))
1186 (if (functionp body-presentation-method)
1187 (funcall body-presentation-method entity situation)
1188 (mime-display-multipart/mixed entity situation)))))
1190 ;;; @ MIME viewer mode
1193 (defconst mime-view-menu-title "MIME-View")
1194 (defconst mime-view-menu-list
1195 '((up "Move to upper entity" mime-preview-move-to-upper)
1196 (previous "Move to previous entity" mime-preview-move-to-previous)
1197 (next "Move to next entity" mime-preview-move-to-next)
1198 (scroll-down "Scroll-down" mime-preview-scroll-down-entity)
1199 (scroll-up "Scroll-up" mime-preview-scroll-up-entity)
1200 (play "Play current entity" mime-preview-play-current-entity)
1201 (extract "Extract current entity" mime-preview-extract-current-entity)
1202 (print "Print current entity" mime-preview-print-current-entity)
1203 (raw "View text without code conversion" mime-preview-inline)
1204 (text "View text with code conversion" mime-preview-text)
1205 (type "View internally as type" mime-preview-type))
1206 "Menu for MIME Viewer.")
1208 (cond ((featurep 'xemacs)
1209 (defvar mime-view-xemacs-popup-menu
1210 (cons mime-view-menu-title
1213 (vector (nth 1 item)(nth 2 item) t)))
1214 mime-view-menu-list)))
1215 (defun mime-view-xemacs-popup-menu (event)
1216 "Popup the menu in the MIME Viewer buffer"
1218 (select-window (event-window event))
1219 (set-buffer (event-buffer event))
1220 (popup-menu 'mime-view-xemacs-popup-menu))
1221 (defvar mouse-button-2 'button2))
1223 (defvar mouse-button-2 [mouse-2])))
1225 (defun mime-view-define-keymap (&optional default)
1226 (let ((mime-view-mode-map (if (keymapp default)
1227 (copy-keymap default)
1228 (make-sparse-keymap))))
1229 (define-key mime-view-mode-map
1230 "u" (function mime-preview-move-to-upper))
1231 (define-key mime-view-mode-map
1232 "p" (function mime-preview-move-to-previous))
1233 (define-key mime-view-mode-map
1234 "n" (function mime-preview-move-to-next))
1235 (define-key mime-view-mode-map
1236 "\e\t" (function mime-preview-move-to-previous))
1237 (define-key mime-view-mode-map
1238 "\t" (function mime-preview-move-to-next))
1239 (define-key mime-view-mode-map
1240 " " (function mime-preview-scroll-up-entity))
1241 (define-key mime-view-mode-map
1242 "\M- " (function mime-preview-scroll-down-entity))
1243 (define-key mime-view-mode-map
1244 "\177" (function mime-preview-scroll-down-entity))
1245 (define-key mime-view-mode-map
1246 "\C-m" (function mime-preview-next-line-entity))
1247 (define-key mime-view-mode-map
1248 "\C-\M-m" (function mime-preview-previous-line-entity))
1249 (define-key mime-view-mode-map
1250 "v" (function mime-preview-play-current-entity))
1251 (define-key mime-view-mode-map
1252 "e" (function mime-preview-extract-current-entity))
1253 (define-key mime-view-mode-map
1254 "\C-c\C-e" (function mime-preview-extract-current-entity))
1255 (define-key mime-view-mode-map
1256 "i" (function mime-preview-inline))
1257 (define-key mime-view-mode-map
1258 "c" (function mime-preview-text))
1259 (define-key mime-view-mode-map
1260 "t" (function mime-preview-type))
1261 (define-key mime-view-mode-map
1262 "b" (function mime-preview-buttonize))
1263 (define-key mime-view-mode-map
1264 "B" (function mime-preview-unbuttonize))
1265 (define-key mime-view-mode-map
1266 "\C-c\C-t\C-h" (function mime-preview-toggle-header))
1267 (define-key mime-view-mode-map
1268 "\C-c\C-t\C-c" (function mime-preview-toggle-content))
1269 (define-key mime-view-mode-map
1270 "\C-c\C-p" (function mime-preview-print-current-entity))
1271 (define-key mime-view-mode-map
1272 "a" (function mime-preview-follow-current-entity))
1273 (define-key mime-view-mode-map
1274 "q" (function mime-preview-quit))
1275 (define-key mime-view-mode-map
1276 "\C-c\C-x" (function mime-preview-kill-buffer))
1277 ;; (define-key mime-view-mode-map
1278 ;; "<" (function beginning-of-buffer))
1279 ;; (define-key mime-view-mode-map
1280 ;; ">" (function end-of-buffer))
1281 (define-key mime-view-mode-map
1282 "?" (function describe-mode))
1283 (define-key mime-view-mode-map
1284 [tab] (function mime-preview-move-to-next))
1285 (define-key mime-view-mode-map
1286 [delete] (function mime-preview-scroll-down-entity))
1287 (define-key mime-view-mode-map
1288 [backspace] (function mime-preview-scroll-down-entity))
1289 (if (functionp default)
1290 (cond ((featurep 'xemacs)
1291 (set-keymap-default-binding mime-view-mode-map default))
1293 (setq mime-view-mode-map
1294 (append mime-view-mode-map (list (cons t default)))))))
1296 (define-key mime-view-mode-map
1297 mouse-button-2 (function mime-button-dispatcher)))
1298 (cond ((featurep 'xemacs)
1299 (define-key mime-view-mode-map
1300 mouse-button-3 (function mime-view-xemacs-popup-menu)))
1301 ((>= emacs-major-version 19)
1302 (define-key mime-view-mode-map [menu-bar mime-view]
1303 (cons mime-view-menu-title
1304 (make-sparse-keymap mime-view-menu-title)))
1307 (define-key mime-view-mode-map
1308 (vector 'menu-bar 'mime-view (car item))
1309 (cons (nth 1 item)(nth 2 item)))))
1310 (reverse mime-view-menu-list))))
1311 (use-local-map mime-view-mode-map)
1312 (run-hooks 'mime-view-define-keymap-hook)))
1314 (defsubst mime-maybe-hide-echo-buffer ()
1315 "Clear mime-echo buffer and delete window for it."
1316 (let ((buf (get-buffer mime-echo-buffer-name)))
1321 (let ((win (get-buffer-window buf)))
1323 (delete-window win)))
1324 (bury-buffer buf)))))
1326 (defvar mime-view-redisplay nil)
1329 (defun mime-display-message (message &optional preview-buffer
1330 mother default-keymap-or-function
1331 original-major-mode)
1332 "View MESSAGE in MIME-View mode.
1334 Optional argument PREVIEW-BUFFER specifies the buffer of the
1335 presentation. It must be either nil or a name of preview buffer.
1337 Optional argument MOTHER specifies mother-buffer of the preview-buffer.
1339 Optional argument DEFAULT-KEYMAP-OR-FUNCTION is nil, keymap or
1340 function. If it is a keymap, keymap of MIME-View mode will be added
1341 to it. If it is a function, it will be bound as default binding of
1342 keymap of MIME-View mode."
1343 (mime-maybe-hide-echo-buffer)
1344 (let ((win-conf (current-window-configuration)))
1346 (setq preview-buffer
1347 (concat "*Preview-" (mime-entity-name message) "*")))
1348 (or original-major-mode
1349 (setq original-major-mode major-mode))
1350 (let ((inhibit-read-only t))
1351 (set-buffer (get-buffer-create preview-buffer))
1355 (setq mime-mother-buffer mother))
1356 (setq mime-preview-original-window-configuration win-conf)
1357 (setq major-mode 'mime-view-mode)
1358 (setq mode-name "MIME-View")
1359 (mime-display-entity message nil
1360 `((entity-button . invisible)
1362 (major-mode . ,original-major-mode))
1364 (mime-view-define-keymap default-keymap-or-function)
1365 (set (make-local-variable 'line-move-ignore-invisible) t)
1367 (next-single-property-change (point-min) 'mime-view-entity)))
1370 (goto-char (point-min))
1371 (search-forward "\n\n" nil t)))
1372 (run-hooks 'mime-view-mode-hook)
1373 (set-buffer-modified-p nil)
1374 (setq buffer-read-only t)
1378 (defun mime-view-buffer (&optional raw-buffer preview-buffer mother
1379 default-keymap-or-function
1380 representation-type)
1381 "View RAW-BUFFER in MIME-View mode.
1382 Optional argument PREVIEW-BUFFER is either nil or a name of preview
1384 Optional argument DEFAULT-KEYMAP-OR-FUNCTION is nil, keymap or
1385 function. If it is a keymap, keymap of MIME-View mode will be added
1386 to it. If it is a function, it will be bound as default binding of
1387 keymap of MIME-View mode.
1388 Optional argument REPRESENTATION-TYPE is representation-type of
1389 message. It must be nil, `binary' or `cooked'. If it is nil,
1390 `cooked' is used as default."
1393 (setq raw-buffer (current-buffer)))
1394 (or representation-type
1395 (setq representation-type
1397 (set-buffer raw-buffer)
1398 (cdr (or (assq major-mode mime-raw-representation-type-alist)
1399 (assq t mime-raw-representation-type-alist))))))
1400 (if (eq representation-type 'binary)
1401 (setq representation-type 'buffer))
1402 (setq preview-buffer (mime-display-message
1403 (mime-open-entity representation-type raw-buffer)
1404 preview-buffer mother default-keymap-or-function))
1405 (or (get-buffer-window preview-buffer)
1406 (let ((r-win (get-buffer-window raw-buffer)))
1408 (set-window-buffer r-win preview-buffer)
1409 (let ((m-win (and mother (get-buffer-window mother))))
1411 (set-window-buffer m-win preview-buffer)
1412 (switch-to-buffer preview-buffer)))))))
1414 (defun mime-view-mode (&optional mother ctl encoding
1415 raw-buffer preview-buffer
1416 default-keymap-or-function)
1417 "Major mode for viewing MIME message.
1419 Here is a list of the standard keys for mime-view-mode.
1424 u Move to upper content
1425 p or M-TAB Move to previous content
1426 n or TAB Move to next content
1427 SPC Scroll up or move to next content
1428 M-SPC or DEL Scroll down or move to previous content
1429 RET Move to next line
1430 M-RET Move to previous line
1431 v Decode current content as `play mode'
1432 e Decode current content as `extract mode'
1433 C-c C-p Decode current content as `print mode'
1434 a Followup to current content.
1436 button-2 Move to point under the mouse cursor
1437 and decode current content as `play mode'"
1439 (unless mime-view-redisplay
1441 (if raw-buffer (set-buffer raw-buffer))
1444 (or (assq major-mode mime-raw-representation-type-alist)
1445 (assq t mime-raw-representation-type-alist)))))
1446 (if (eq type 'binary)
1447 (setq type 'buffer))
1448 (setq mime-message-structure (mime-open-entity type raw-buffer))
1449 (or (mime-entity-content-type mime-message-structure)
1450 (mime-entity-set-content-type-internal
1451 mime-message-structure ctl)))
1452 (or (mime-entity-encoding mime-message-structure)
1453 (mime-entity-set-encoding-internal mime-message-structure encoding))))
1454 (mime-display-message mime-message-structure preview-buffer
1455 mother default-keymap-or-function))
1461 (autoload 'mime-preview-play-current-entity "mime-play"
1462 "Play current entity." t)
1464 (defun mime-preview-extract-current-entity (&optional ignore-examples)
1465 "Extract current entity into file (maybe).
1466 It decodes current entity to call internal or external method as
1467 \"extract\" mode. The method is selected from variable
1468 `mime-acting-condition'."
1470 (mime-preview-play-current-entity ignore-examples "extract"))
1472 (defun mime-preview-print-current-entity (&optional ignore-examples)
1473 "Print current entity (maybe).
1474 It decodes current entity to call internal or external method as
1475 \"print\" mode. The method is selected from variable
1476 `mime-acting-condition'."
1478 (mime-preview-play-current-entity ignore-examples "print"))
1484 (defun mime-preview-follow-current-entity ()
1485 "Write follow message to current entity.
1486 It calls following-method selected from variable
1487 `mime-preview-following-method-alist'."
1489 (let (entity position entity-node-id header-exists)
1490 (while (null (setq entity
1491 (get-text-property (point) 'mime-view-entity)))
1493 (setq position (mime-preview-entity-boundary))
1494 (setq entity-node-id (mime-entity-node-id entity)
1496 ;; When on an invisible entity, there's no header.
1497 (or (mime-view-header-is-visible
1498 (get-text-property (car position) 'mime-view-situation))
1499 ;; We are on a rfc822 button.
1500 (and (eq 'message (mime-entity-media-type
1502 (eq 'rfc822 (mime-entity-media-subtype
1505 (next-single-property-change
1506 (car position) 'mime-button-callback
1508 'mime-view-entity-header))))
1509 (let* ((mode (mime-preview-original-major-mode 'recursive))
1511 (format "%s-%s" (buffer-name) (reverse entity-node-id)))
1513 (the-buf (current-buffer))
1516 (set-buffer (setq new-buf (get-buffer-create new-name)))
1518 (unless header-exists
1520 (insert (buffer-substring-no-properties (car position)
1521 (cdr position) the-buf))
1522 (goto-char (point-min))
1523 (let ((current-entity
1524 (if (and (eq (mime-entity-media-type entity) 'message)
1525 (eq (mime-entity-media-subtype entity) 'rfc822))
1526 (car (mime-entity-children entity))
1528 (while (and current-entity
1529 (if (and (eq (mime-entity-media-type
1530 current-entity) 'message)
1531 (eq (mime-entity-media-subtype
1532 current-entity) 'rfc822))
1534 (mime-insert-header current-entity fields)
1536 (setq fields (std11-collect-field-names)
1537 current-entity (mime-entity-parent current-entity))))
1538 (let ((rest mime-view-following-required-fields-list)
1541 (setq field-name (car rest))
1542 (or (std11-field-body field-name)
1545 (set-buffer the-buf)
1546 (let ((entity (when mime-mother-buffer
1547 (set-buffer mime-mother-buffer)
1548 (get-text-property (point)
1549 'mime-view-entity))))
1551 (null (setq ret (mime-entity-fetch-field
1552 entity field-name))))
1553 (setq entity (mime-entity-parent entity)))))
1555 (insert (concat field-name ": " ret "\n")))))
1556 (setq rest (cdr rest))))
1557 (mime-decode-header-in-buffer))
1558 (let ((f (cdr (assq mode mime-preview-following-method-alist))))
1563 "Sorry, following method for %s is not implemented yet."
1570 (defun mime-preview-move-to-upper ()
1571 "Move to upper entity.
1572 If there is no upper entity, call function `mime-preview-quit'."
1575 (while (null (setq cinfo
1576 (get-text-property (point) 'mime-view-entity)))
1578 (let ((r (mime-entity-parent cinfo))
1581 (while (setq point (previous-single-property-change
1582 (point) 'mime-view-entity))
1584 (when (eq r (get-text-property (point) 'mime-view-entity))
1585 (if (or (eq mime-preview-move-scroll t)
1586 (and mime-preview-move-scroll
1589 (move-to-window-line -1)
1590 (forward-line (* -1 next-screen-context-lines))
1593 (recenter next-screen-context-lines))
1595 (mime-preview-quit)))))
1597 (defun mime-preview-move-to-previous ()
1598 "Move to previous entity.
1599 If there is no previous entity, it calls function registered in
1600 variable `mime-preview-over-to-previous-method-alist'."
1602 (while (and (not (bobp))
1603 (null (get-text-property (point) 'mime-view-entity)))
1605 (let ((point (previous-single-property-change (point) 'mime-view-entity)))
1607 (>= point (point-min)))
1608 (if (get-text-property (1- point) 'mime-view-entity)
1609 (progn (goto-char point)
1611 (or (eq mime-preview-move-scroll t)
1612 (and mime-preview-move-scroll
1615 (move-to-window-line 0)
1616 (forward-line next-screen-context-lines)
1619 (recenter next-screen-context-lines)))
1620 (goto-char (1- point))
1621 (mime-preview-move-to-previous))
1622 (let ((f (assq (mime-preview-original-major-mode)
1623 mime-preview-over-to-previous-method-alist)))
1625 (funcall (cdr f)))))))
1627 (defun mime-preview-move-to-next ()
1628 "Move to next entity.
1629 If there is no previous entity, it calls function registered in
1630 variable `mime-preview-over-to-next-method-alist'."
1632 (while (and (not (eobp))
1633 (null (get-text-property (point) 'mime-view-entity)))
1635 (let ((point (next-single-property-change (point) 'mime-view-entity)))
1637 (<= point (point-max)))
1640 (if (null (get-text-property point 'mime-view-entity))
1641 (mime-preview-move-to-next)
1643 (or (eq mime-preview-move-scroll t)
1644 (and mime-preview-move-scroll
1647 (move-to-window-line -1)
1649 (* -1 next-screen-context-lines))
1652 (recenter next-screen-context-lines))))
1653 (let ((f (assq (mime-preview-original-major-mode)
1654 mime-preview-over-to-next-method-alist)))
1656 (funcall (cdr f)))))))
1658 (defun mime-preview-scroll-up-entity (&optional h)
1659 "Scroll up current entity.
1660 If reached to (point-max), it calls function registered in variable
1661 `mime-preview-over-to-next-method-alist'."
1664 (let ((f (assq (mime-preview-original-major-mode)
1665 mime-preview-over-to-next-method-alist)))
1669 (or (next-single-property-change (point) 'mime-view-entity)
1671 (bottom (window-end (selected-window))))
1674 (not mime-preview-scroll-full-screen))
1675 (progn (goto-char point)
1676 (recenter next-screen-context-lines))
1680 (goto-char (point-max))))))))
1682 (defun mime-preview-scroll-down-entity (&optional h)
1683 "Scroll down current entity.
1684 If reached to (point-min), it calls function registered in variable
1685 `mime-preview-over-to-previous-method-alist'."
1688 (let ((f (assq (mime-preview-original-major-mode)
1689 mime-preview-over-to-previous-method-alist)))
1693 (or (previous-single-property-change (point) 'mime-view-entity)
1695 (top (window-start (selected-window))))
1698 (not mime-preview-scroll-full-screen))
1699 (progn (goto-char point)
1700 (recenter (* -1 next-screen-context-lines)))
1703 (beginning-of-buffer
1704 (goto-char (point-min))))))))
1706 (defun mime-preview-next-line-entity (&optional lines)
1707 "Scroll up one line (or prefix LINES lines).
1708 If LINES is negative, scroll down LINES lines."
1710 (mime-preview-scroll-up-entity (or lines 1)))
1712 (defun mime-preview-previous-line-entity (&optional lines)
1713 "Scrroll down one line (or prefix LINES lines).
1714 If LINES is negative, scroll up LINES lines."
1716 (mime-preview-scroll-down-entity (or lines 1)))
1718 (defun mime-preview-entity-boundary (&optional point)
1720 (setq point (point)))
1721 (and (eq point (point-max))
1722 (setq point (1- (point-max))))
1723 (let ((entity (get-text-property point 'mime-view-entity))
1724 (start (previous-single-property-change (1+ point) 'mime-view-entity
1728 (while (and (mime-entity-children entity)
1730 (if (mime-view-children-is-invisible
1731 (get-text-property point 'mime-view-situation))
1733 ;; If the part is shown, search the last part.
1734 (let ((child (car (last (mime-entity-children entity)))))
1735 (while (not (eq (get-text-property point 'mime-view-entity) child))
1736 (setq point (next-single-property-change point 'mime-view-entity)))
1737 (setq entity child))))
1738 (setq end (next-single-property-change point 'mime-view-entity
1742 (defun mime-preview-toggle-header ()
1743 "Toggle display of entity header."
1745 (let ((inhibit-read-only t)
1746 (mime-view-force-inline-types t)
1747 (position (mime-preview-entity-boundary))
1748 entity header-is-visible situation)
1749 (setq entity (get-text-property (car position) 'mime-view-entity)
1750 situation (get-text-property (car position) 'mime-view-situation))
1751 (setq header-is-visible (mime-view-header-is-visible situation))
1753 (delete-region (car position) (cdr position))
1754 (if header-is-visible
1755 (mime-display-entity entity
1756 (put-alist '*entity-button 'visible
1757 (put-alist '*header 'invisible
1759 (mime-display-entity entity
1760 (put-alist '*entity-button 'invisible
1761 (put-alist '*header 'visible
1764 (defun mime-preview-toggle-content ()
1765 "Toggle display of entity body."
1767 (let ((inhibit-read-only t)
1768 (mime-view-force-inline-types t)
1769 (position (mime-preview-entity-boundary))
1771 (setq entity (get-text-property (car position) 'mime-view-entity)
1772 situation (get-text-property (car position) 'mime-view-situation))
1774 (if (mime-entity-children entity)
1775 ;; Entity body is always invisible for composite types.
1776 (if (mime-view-children-is-invisible situation)
1777 (put-alist '*children 'visible situation)
1778 (put-alist '*children 'invisible situation))
1779 (if (mime-view-body-is-visible situation)
1780 (put-alist '*body 'invisible situation)
1781 (put-alist '*body 'visible situation))))
1783 (delete-region (car position) (cdr position))
1784 (mime-display-entity entity situation))))
1789 (defun mime-preview-quit ()
1790 "Quit from MIME-preview buffer.
1791 It calls function registered in variable
1792 `mime-preview-quitting-method-alist'."
1794 (let ((r (assq (mime-preview-original-major-mode)
1795 mime-preview-quitting-method-alist)))
1798 (kill-buffer (current-buffer))))
1800 (defun mime-preview-kill-buffer ()
1802 (kill-buffer (current-buffer)))
1808 (provide 'mime-view)
1810 (run-hooks 'mime-view-load-hook)
1812 ;;; mime-view.el ends here