1 ;;; mime-view.el --- interactive MIME viewer for GNU Emacs
3 ;; Copyright (C) 1995,1996,1997,1998 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 (Sophisticated Emacs 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.
32 (require 'eword-decode)
41 (defconst mime-view-version-string
42 `,(concat (car mime-module-version) " MIME-View "
43 (mapconcat #'number-to-string (cddr mime-module-version) ".")
44 " (" (cadr mime-module-version) ")"))
47 ;;; @ buffer local variables
53 (defvar mime-raw-message-info
54 "Information about structure of message.
55 Please use reference function `mime-entity-SLOT' to get value of SLOT.
57 Following is a list of slots of the structure:
59 node-id reversed entity-number (list of integers)
60 point-min beginning point of region in raw-buffer
61 point-max end point of region in raw-buffer
62 type media-type (symbol)
63 subtype media-subtype (symbol)
64 type/subtype media-type/subtype (string or nil)
65 parameters parameter of Content-Type field (association list)
66 encoding Content-Transfer-Encoding (string or nil)
67 children entities included in this entity (list of content-infos)
69 If an entity includes other entities in its body, such as multipart or
70 message/rfc822, `mime-entity' structures of them are included in
71 `children', so the `mime-entity' structure become a tree.")
72 (make-variable-buffer-local 'mime-raw-message-info)
74 (defvar mime-preview-buffer nil
75 "MIME-preview buffer corresponding with the (raw) buffer.")
76 (make-variable-buffer-local 'mime-preview-buffer)
79 ;;; @@ in preview-buffer
82 (defvar mime-mother-buffer nil
83 "Mother buffer corresponding with the (MIME-preview) buffer.
84 If current MIME-preview buffer is generated by other buffer, such as
85 message/partial, it is called `mother-buffer'.")
86 (make-variable-buffer-local 'mime-mother-buffer)
88 (defvar mime-raw-buffer nil
89 "Raw buffer corresponding with the (MIME-preview) buffer.")
90 (make-variable-buffer-local 'mime-raw-buffer)
92 (defvar mime-preview-original-major-mode nil
93 "Major-mode of mime-raw-buffer.")
94 (make-variable-buffer-local 'mime-preview-original-major-mode)
96 (defvar mime-preview-original-window-configuration nil
97 "Window-configuration before mime-view-mode is called.")
98 (make-variable-buffer-local 'mime-preview-original-window-configuration)
101 ;;; @ entity information
104 (defsubst mime-raw-find-entity-from-node-id (entity-node-id
105 &optional message-info)
106 "Return entity from ENTITY-NODE-ID in mime-raw-buffer.
107 If optional argument MESSAGE-INFO is not specified,
108 `mime-raw-message-info' is used."
109 (mime-raw-find-entity-from-number (reverse entity-node-id) message-info))
111 (defun mime-raw-find-entity-from-number (entity-number &optional message-info)
112 "Return entity from ENTITY-NUMBER in mime-raw-buffer.
113 If optional argument MESSAGE-INFO is not specified,
114 `mime-raw-message-info' is used."
116 (setq message-info mime-raw-message-info))
117 (if (eq entity-number t)
119 (let ((sn (car entity-number)))
122 (let ((rc (nth sn (mime-entity-children message-info))))
124 (mime-raw-find-entity-from-number (cdr entity-number) rc)
128 (defun mime-raw-find-entity-from-point (point &optional message-info)
129 "Return entity from POINT in mime-raw-buffer.
130 If optional argument MESSAGE-INFO is not specified,
131 `mime-raw-message-info' is used."
133 (setq message-info mime-raw-message-info))
134 (if (and (<= (mime-entity-point-min message-info) point)
135 (<= point (mime-entity-point-max message-info)))
136 (let ((children (mime-entity-children message-info)))
140 (mime-raw-find-entity-from-point point (car children))))
144 (setq children (cdr children)))
147 (defsubst mime-raw-point-to-entity-node-id (point &optional message-info)
148 "Return entity-node-id from POINT in mime-raw-buffer.
149 If optional argument MESSAGE-INFO is not specified,
150 `mime-raw-message-info' is used."
151 (mime-entity-node-id (mime-raw-find-entity-from-point point message-info)))
153 (defsubst mime-raw-point-to-entity-number (point &optional message-info)
154 "Return entity-number from POINT in mime-raw-buffer.
155 If optional argument MESSAGE-INFO is not specified,
156 `mime-raw-message-info' is used."
157 (reverse (mime-raw-point-to-entity-node-id point message-info)))
159 (defsubst mime-raw-entity-parent (entity &optional message-info)
160 "Return mother entity of ENTITY.
161 If optional argument MESSAGE-INFO is not specified,
162 `mime-raw-message-info' is used."
163 (mime-raw-find-entity-from-node-id (cdr (mime-entity-node-id entity))
166 (defun mime-raw-flatten-message-info (&optional message-info)
167 "Return list of entity in mime-raw-buffer.
168 If optional argument MESSAGE-INFO is not specified,
169 `mime-raw-message-info' is used."
171 (setq message-info mime-raw-message-info))
172 (let ((dest (list message-info))
173 (rcl (mime-entity-children message-info)))
175 (setq dest (nconc dest (mime-raw-flatten-message-info (car rcl))))
176 (setq rcl (cdr rcl)))
180 ;;; @ presentation of preview
186 ;;; @@@ predicate function
189 (defvar mime-view-content-button-visible-ctype-list
190 '("application/pgp"))
192 (defun mime-view-entity-button-visible-p (entity message-info)
193 "Return non-nil if header of ENTITY is visible.
194 Please redefine this function if you want to change default setting."
195 (and (not (mime-root-entity-p entity))
196 (let ((media-type (mime-entity-media-type entity))
197 (media-subtype (mime-entity-media-subtype entity)))
198 (or (not (eq media-type 'application))
199 (and (not (eq media-subtype 'x-selection))
200 (or (not (eq media-subtype 'octet-stream))
202 (mime-raw-entity-parent entity message-info)))
203 (or (not (eq (mime-entity-media-type mother-entity)
205 (not (eq (mime-entity-media-subtype mother-entity)
210 ;;; @@@ entity button generator
213 (defun mime-view-insert-entity-button (entity message-info subj)
214 "Insert entity-button of ENTITY."
215 (let ((entity-node-id (mime-entity-node-id entity))
216 (params (mime-entity-parameters entity)))
218 (let ((access-type (assoc "access-type" params))
219 (num (or (cdr (assoc "x-part-number" params))
220 (if (consp entity-node-id)
223 (format "%s" (1+ num))
225 (reverse entity-node-id) ".")
229 (let ((server (assoc "server" params)))
230 (setq access-type (cdr access-type))
232 (format "%s %s ([%s] %s)"
233 num subj access-type (cdr server))
234 (let ((site (cdr (assoc "site" params)))
235 (dir (cdr (assoc "directory" params)))
237 (format "%s %s ([%s] %s:%s)"
238 num subj access-type site dir)
242 (let ((media-type (mime-entity-media-type entity))
243 (media-subtype (mime-entity-media-subtype entity))
244 (charset (cdr (assoc "charset" params)))
245 (encoding (mime-entity-encoding entity)))
249 (format " <%s/%s%s%s>"
250 media-type media-subtype
252 (concat "; " charset)
255 (concat " (" encoding ")")
257 (if (>= (+ (current-column)(length rest))(window-width))
261 (function mime-preview-play-current-entity))
268 ;;; @@@ predicate function
271 (defvar mime-view-childrens-header-showing-Content-Type-list
272 '("message/rfc822" "message/news"))
274 (defun mime-view-header-visible-p (entity message-info)
275 "Return non-nil if header of ENTITY is visible."
276 (let ((entity-node-id (mime-entity-node-id entity)))
277 (or (null entity-node-id)
278 (member (mime-entity-type/subtype
279 (mime-raw-find-entity-from-node-id
280 (cdr entity-node-id) message-info))
281 mime-view-childrens-header-showing-Content-Type-list)
284 ;;; @@@ entity header filter
287 (defvar mime-view-content-header-filter-alist nil)
289 (defun mime-view-default-content-header-filter ()
290 (mime-view-cut-header)
291 (eword-decode-header)
294 ;;; @@@ entity field cutter
297 (defvar mime-view-ignored-field-list
298 '(".*Received" ".*Path" ".*Id" "References"
299 "Replied" "Errors-To"
300 "Lines" "Sender" ".*Host" "Xref"
301 "Content-Type" "Precedence"
303 "All fields that match this list will be hidden in MIME preview buffer.
304 Each elements are regexp of field-name.")
306 (defvar mime-view-ignored-field-regexp
308 (apply (function regexp-or) mime-view-ignored-field-list)
311 (defvar mime-view-visible-field-list '("Dnas.*" "Message-Id")
312 "All fields that match this list will be displayed in MIME preview buffer.
313 Each elements are regexp of field-name.")
315 (defun mime-view-cut-header ()
316 (goto-char (point-min))
317 (while (re-search-forward mime-view-ignored-field-regexp nil t)
318 (let* ((beg (match-beginning 0))
320 (name (buffer-substring beg end))
323 (let ((rest mime-view-visible-field-list))
325 (if (string-match (car rest) name)
328 (setq rest (cdr rest))))
331 (if (re-search-forward "^\\([^ \t]\\|$\\)" nil t)
340 ;;; @@@ predicate function
343 (defvar mime-preview-condition nil
344 "Condition-tree about how to display entity.")
346 (ctree-set-calist-strictly
347 'mime-preview-condition '((type . application)(subtype . octet-stream)
350 (ctree-set-calist-strictly
351 'mime-preview-condition '((type . application)(subtype . octet-stream)
354 (ctree-set-calist-strictly
355 'mime-preview-condition '((type . application)(subtype . octet-stream)
359 (ctree-set-calist-strictly
360 'mime-preview-condition '((type . application)(subtype . pgp)
363 (ctree-set-calist-strictly
364 'mime-preview-condition '((type . application)(subtype . x-latex)
367 (ctree-set-calist-strictly
368 'mime-preview-condition '((type . application)(subtype . x-selection)
371 (ctree-set-calist-strictly
372 'mime-preview-condition '((type . application)(subtype . x-comment)
375 (ctree-set-calist-strictly
376 'mime-preview-condition '((type . message)(subtype . delivery-status)
379 (ctree-set-calist-strictly
380 'mime-preview-condition '((body . visible)
381 (body-presentation-method . with-filter)
382 (body-filter . mime-preview-filter-for-text/plain)))
384 (ctree-set-calist-strictly
385 'mime-preview-condition '((type . nil)
387 (body-presentation-method . with-filter)
388 (body-filter . mime-preview-filter-for-text/plain)))
390 (ctree-set-calist-strictly
391 'mime-preview-condition '((type . text)(subtype . enriched)
393 (body-presentation-method . with-filter)
395 . mime-preview-filter-for-text/enriched)))
397 (ctree-set-calist-strictly
398 'mime-preview-condition '((type . text)(subtype . richtext)
400 (body-presentation-method . with-filter)
402 . mime-preview-filter-for-text/richtext)))
404 (ctree-set-calist-strictly
405 'mime-preview-condition '((type . text)(subtype . t)
407 (body-presentation-method . with-filter)
408 (body-filter . mime-preview-filter-for-text/plain)))
410 (ctree-set-calist-strictly
411 'mime-preview-condition '((type . message)(subtype . partial)
412 (body-presentation-method
413 . mime-view-insert-message/partial-button)))
415 (defun mime-view-body-visible-p (entity message-info)
416 "Return non-nil if body of ENTITY is visible."
417 (ctree-match-calist mime-preview-condition
418 (list* (cons 'type (mime-entity-media-type entity))
419 (cons 'subtype (mime-entity-media-subtype entity))
420 (cons 'encoding (mime-entity-encoding entity))
421 (cons 'major-mode major-mode)
422 (mime-entity-parameters entity))))
425 ;;; @@@ entity filter
428 (autoload 'mime-preview-filter-for-text/plain "mime-text")
429 (autoload 'mime-preview-filter-for-text/enriched "mime-text")
430 (autoload 'mime-preview-filter-for-text/richtext "mime-text")
432 (defvar mime-text-decoder-alist
433 '((mime-show-message-mode . mime-text-decode-buffer)
434 (mime-temp-message-mode . mime-text-decode-buffer)
435 (t . mime-text-decode-buffer-maybe)
437 "Alist of major-mode vs. mime-text-decoder.
438 Each element looks like (SYMBOL . FUNCTION). SYMBOL is major-mode or
441 Specification of FUNCTION is described in DOC-string of variable
444 This value is overridden by buffer local variable `mime-text-decoder'
448 (defvar mime-view-announcement-for-message/partial
449 (if (and (>= emacs-major-version 19) window-system)
451 \[[ This is message/partial style split message. ]]
452 \[[ Please press `v' key in this buffer ]]
453 \[[ or click here by mouse button-2. ]]"
455 \[[ This is message/partial style split message. ]]
456 \[[ Please press `v' key in this buffer. ]]"
459 (defun mime-view-insert-message/partial-button (&optional situation)
461 (goto-char (point-max))
462 (if (not (search-backward "\n\n" nil t))
465 (goto-char (point-max))
466 (narrow-to-region (point-max)(point-max))
467 (insert mime-view-announcement-for-message/partial)
468 (mime-add-button (point-min)(point-max)
469 #'mime-preview-play-current-entity)
473 ;;; @@ entity separator
476 (defun mime-view-entity-separator-visible-p (entity message-info)
477 "Return non-nil if separator is needed for ENTITY."
478 (and (not (mime-view-header-visible-p entity message-info))
479 (not (mime-view-body-visible-p entity message-info))))
482 ;;; @ acting-condition
485 (defvar mime-acting-condition
486 '(((type . text)(subtype . plain)
487 (method "tm-plain" nil 'file "" 'encoding 'mode 'name)
488 (mode "play" "print")
490 ((type . text)(subtype . html)
491 (method "tm-html" nil 'file "" 'encoding 'mode 'name)
494 ((type . text)(subtype . x-rot13-47)
495 (method . mime-method-to-display-caesar)
498 ((type . text)(subtype . x-rot13-47-48)
499 (method . mime-method-to-display-caesar)
503 ((type . audio)(subtype . basic)
504 (method "tm-au" nil 'file "" 'encoding 'mode 'name)
509 (method "tm-image" nil 'file "" 'encoding 'mode 'name)
510 (mode "play" "print")
513 ((type . video)(subtype . mpeg)
514 (method "tm-mpeg" nil 'file "" 'encoding 'mode 'name)
518 ((type . application)(subtype . postscript)
519 (method "tm-ps" nil 'file "" 'encoding 'mode 'name)
520 (mode "play" "print")
522 ((type . application)(subtype . octet-stream)
523 (method . mime-method-to-save)(mode "play" "print")
526 ((type . message)(subtype . external-body)
527 ("access-type" . "anon-ftp")
528 (method . mime-method-to-display-message/external-ftp)
530 ((type . message)(subtype . rfc822)
531 (method . mime-method-to-display-message/rfc822)
534 ((type . message)(subtype . partial)
535 (method . mime-method-to-store-message/partial)
539 ((method "metamail" t "-m" "tm" "-x" "-d" "-z" "-e" 'file)
542 ((method . mime-method-to-save)(mode . "extract"))
546 ;;; @ quitting method
549 (defvar mime-preview-quitting-method-alist
550 '((mime-show-message-mode
551 . mime-preview-quitting-method-for-mime-show-message-mode))
552 "Alist of major-mode vs. quitting-method of mime-view.")
554 (defvar mime-view-over-to-previous-method-alist nil)
555 (defvar mime-view-over-to-next-method-alist nil)
557 (defvar mime-view-show-summary-method nil
558 "Alist of major-mode vs. show-summary-method.")
561 ;;; @ following method
564 (defvar mime-view-following-method-alist nil
565 "Alist of major-mode vs. following-method of mime-view.")
567 (defvar mime-view-following-required-fields-list
574 ;; hack from Gnus 5.0.4.
576 (defvar mime-view-x-face-to-pbm-command
577 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm")
579 (defvar mime-view-x-face-command
580 (concat mime-view-x-face-to-pbm-command
582 "String to be executed to display an X-Face field.
583 The command will be executed in a sub-shell asynchronously.
584 The compressed face will be piped to this command.")
586 (defun mime-view-x-face-function ()
587 "Function to display X-Face field. You can redefine to customize."
588 ;; 1995/10/12 (c.f. tm-eng:130)
589 ;; fixed by Eric Ding <ericding@San-Jose.ate.slb.com>
591 (narrow-to-region (point-min) (re-search-forward "^$" nil t))
593 (goto-char (point-min))
594 (if (re-search-forward "^X-Face:[ \t]*" nil t)
595 (let ((beg (match-end 0))
596 (end (std11-field-end))
598 (call-process-region beg end "sh" nil 0 nil
599 "-c" mime-view-x-face-command)
606 (defvar mime-view-uuencode-encoding-name-list '("x-uue" "x-uuencode"))
608 (defvar mime-raw-buffer-coding-system-alist
609 `((t . ,(mime-charset-to-coding-system default-mime-charset)))
610 "Alist of major-mode vs. corresponding coding-system of `mime-raw-buffer'.")
616 (defvar mime-view-redisplay nil)
618 (defun mime-view-setup-buffers (&optional ctl encoding ibuf obuf)
624 (or mime-view-redisplay
625 (setq mime-raw-message-info (mime-parse-message ctl encoding))
627 (let ((message-info mime-raw-message-info)
628 (the-buf (current-buffer))
631 (setq obuf (concat "*Preview-" (buffer-name the-buf) "*")))
632 (set-buffer (get-buffer-create obuf))
633 (let ((inhibit-read-only t))
634 ;;(setq buffer-read-only nil)
637 (setq mime-raw-buffer the-buf)
638 (setq mime-preview-original-major-mode mode)
639 (setq major-mode 'mime-view-mode)
640 (setq mode-name "MIME-View")
641 (mime-view-display-entity message-info message-info the-buf obuf)
642 (set-buffer-modified-p nil)
644 (setq buffer-read-only t)
647 (setq mime-preview-buffer obuf)
650 (defun mime-view-display-entity (entity message-info ibuf obuf)
652 (let* ((start (mime-entity-point-min entity))
653 (end (mime-entity-point-max entity))
654 (media-type (mime-entity-media-type entity))
655 (media-subtype (mime-entity-media-subtype entity))
656 (ctype (if media-type
658 (format "%s/%s" media-type media-subtype)
659 (symbol-name media-type)
661 (params (mime-entity-parameters entity))
662 (encoding (mime-entity-encoding entity))
663 (entity-node-id (mime-entity-node-id entity))
664 end-of-header e nb ne subj)
667 (setq end-of-header (if (re-search-forward "^$" nil t)
670 (if (> end-of-header end)
671 (setq end-of-header end)
674 (narrow-to-region start end)
677 (mime-raw-get-subject params encoding)))
681 (narrow-to-region nb nb)
682 (if (mime-view-entity-button-visible-p entity message-info)
683 (mime-view-insert-entity-button entity message-info subj)
685 (if (mime-view-header-visible-p entity message-info)
687 (narrow-to-region (point)(point))
688 (insert-buffer-substring mime-raw-buffer start end-of-header)
689 (let ((f (cdr (assq mime-preview-original-major-mode
690 mime-view-content-header-filter-alist))))
693 (mime-view-default-content-header-filter)
695 (run-hooks 'mime-view-content-header-filter-hook)
697 (if (and (mime-root-entity-p entity)
699 ctype mime-view-content-button-visible-ctype-list))
701 (goto-char (point-max))
702 (mime-view-insert-entity-button entity message-info subj)
705 (ctree-match-calist mime-preview-condition
706 (list* (cons 'type media-type)
707 (cons 'subtype media-subtype)
708 (cons 'encoding encoding)
709 (cons 'major-mode major-mode)
711 (body-presentation-method
712 (cdr (assq 'body-presentation-method situation))))
713 (cond ((eq body-presentation-method 'with-filter)
714 (let ((body-filter (cdr (assq 'body-filter situation))))
716 (narrow-to-region (point-max)(point-max))
717 (insert-buffer-substring mime-raw-buffer end-of-header end)
718 (funcall body-filter situation)
720 ((functionp body-presentation-method)
721 (funcall body-presentation-method situation)
723 ((and (null entity-node-id)
724 (null (mime-entity-children message-info)))
725 (goto-char (point-max))
726 (mime-view-insert-entity-button entity message-info subj)
728 (when (mime-view-entity-separator-visible-p entity message-info)
729 (goto-char (point-max))
732 (setq ne (point-max))
734 (put-text-property nb ne 'mime-view-raw-buffer ibuf)
735 (put-text-property nb ne 'mime-view-entity entity)
737 (let ((children (mime-entity-children entity)))
739 (mime-view-display-entity (car children) message-info ibuf obuf)
740 (setq children (cdr children))
743 (defun mime-raw-get-uu-filename (param &optional encoding)
744 (if (member (or encoding
745 (cdr (assq 'encoding param))
747 mime-view-uuencode-encoding-name-list)
749 (or (if (re-search-forward "^begin [0-9]+ " nil t)
750 (if (looking-at ".+$")
751 (buffer-substring (match-beginning 0)(match-end 0))
756 (defun mime-raw-get-subject (param &optional encoding)
757 (or (std11-find-field-body '("Content-Description" "Subject"))
759 (if (or (and (setq ret (mime/Content-Disposition))
760 (setq ret (assoc "filename" (cdr ret)))
762 (setq ret (assoc "name" param))
763 (setq ret (assoc "x-name" param))
765 (std11-strip-quoted-string (cdr ret))
767 (mime-raw-get-uu-filename param encoding)
771 ;;; @ MIME viewer mode
774 (defconst mime-view-menu-title "MIME-View")
775 (defconst mime-view-menu-list
776 '((up "Move to upper entity" mime-preview-move-to-upper)
777 (previous "Move to previous entity" mime-preview-move-to-previous)
778 (next "Move to next entity" mime-preview-move-to-next)
779 (scroll-down "Scroll-down" mime-preview-scroll-down-entity)
780 (scroll-up "Scroll-up" mime-preview-scroll-up-entity)
781 (play "Play current entity" mime-preview-play-current-entity)
782 (extract "Extract current entity" mime-preview-extract-current-entity)
783 (print "Print current entity" mime-preview-print-current-entity)
784 (x-face "Show X Face" mime-preview-display-x-face)
786 "Menu for MIME Viewer")
788 (cond (running-xemacs
789 (defvar mime-view-xemacs-popup-menu
790 (cons mime-view-menu-title
793 (vector (nth 1 item)(nth 2 item) t)
795 mime-view-menu-list)))
796 (defun mime-view-xemacs-popup-menu (event)
797 "Popup the menu in the MIME Viewer buffer"
799 (select-window (event-window event))
800 (set-buffer (event-buffer event))
801 (popup-menu 'mime-view-xemacs-popup-menu))
802 (defvar mouse-button-2 'button2)
805 (defvar mouse-button-2 [mouse-2])
808 (defun mime-view-define-keymap (&optional default)
809 (let ((mime-view-mode-map (if (keymapp default)
810 (copy-keymap default)
813 (define-key mime-view-mode-map
814 "u" (function mime-preview-move-to-upper))
815 (define-key mime-view-mode-map
816 "p" (function mime-preview-move-to-previous))
817 (define-key mime-view-mode-map
818 "n" (function mime-preview-move-to-next))
819 (define-key mime-view-mode-map
820 "\e\t" (function mime-preview-move-to-previous))
821 (define-key mime-view-mode-map
822 "\t" (function mime-preview-move-to-next))
823 (define-key mime-view-mode-map
824 " " (function mime-preview-scroll-up-entity))
825 (define-key mime-view-mode-map
826 "\M- " (function mime-preview-scroll-down-entity))
827 (define-key mime-view-mode-map
828 "\177" (function mime-preview-scroll-down-entity))
829 (define-key mime-view-mode-map
830 "\C-m" (function mime-preview-next-line-entity))
831 (define-key mime-view-mode-map
832 "\C-\M-m" (function mime-preview-previous-line-entity))
833 (define-key mime-view-mode-map
834 "v" (function mime-preview-play-current-entity))
835 (define-key mime-view-mode-map
836 "e" (function mime-preview-extract-current-entity))
837 (define-key mime-view-mode-map
838 "\C-c\C-p" (function mime-preview-print-current-entity))
839 (define-key mime-view-mode-map
840 "a" (function mime-preview-follow-current-entity))
841 (define-key mime-view-mode-map
842 "q" (function mime-preview-quit))
843 (define-key mime-view-mode-map
844 "h" (function mime-preview-show-summary))
845 (define-key mime-view-mode-map
846 "\C-c\C-x" (function mime-preview-kill-buffer))
847 ;; (define-key mime-view-mode-map
848 ;; "<" (function beginning-of-buffer))
849 ;; (define-key mime-view-mode-map
850 ;; ">" (function end-of-buffer))
851 (define-key mime-view-mode-map
852 "?" (function describe-mode))
853 (define-key mime-view-mode-map
854 [tab] (function mime-preview-move-to-next))
855 (define-key mime-view-mode-map
856 [delete] (function mime-preview-scroll-down-entity))
857 (define-key mime-view-mode-map
858 [backspace] (function mime-preview-scroll-down-entity))
859 (if (functionp default)
860 (cond (running-xemacs
861 (set-keymap-default-binding mime-view-mode-map default)
864 (setq mime-view-mode-map
865 (append mime-view-mode-map (list (cons t default))))
868 (define-key mime-view-mode-map
869 mouse-button-2 (function mime-button-dispatcher))
871 (cond (running-xemacs
872 (define-key mime-view-mode-map
873 mouse-button-3 (function mime-view-xemacs-popup-menu))
875 ((>= emacs-major-version 19)
876 (define-key mime-view-mode-map [menu-bar mime-view]
877 (cons mime-view-menu-title
878 (make-sparse-keymap mime-view-menu-title)))
881 (define-key mime-view-mode-map
882 (vector 'menu-bar 'mime-view (car item))
883 (cons (nth 1 item)(nth 2 item))
886 (reverse mime-view-menu-list)
889 (use-local-map mime-view-mode-map)
890 (run-hooks 'mime-view-define-keymap-hook)
893 (defsubst mime-maybe-hide-echo-buffer ()
894 "Clear mime-echo buffer and delete window for it."
895 (let ((buf (get-buffer mime-echo-buffer-name)))
900 (let ((win (get-buffer-window buf)))
907 (defun mime-view-mode (&optional mother ctl encoding ibuf obuf
908 default-keymap-or-function)
909 "Major mode for viewing MIME message.
911 Here is a list of the standard keys for mime-view-mode.
916 u Move to upper content
917 p or M-TAB Move to previous content
918 n or TAB Move to next content
919 SPC Scroll up or move to next content
920 M-SPC or DEL Scroll down or move to previous content
921 RET Move to next line
922 M-RET Move to previous line
923 v Decode current content as `play mode'
924 e Decode current content as `extract mode'
925 C-c C-p Decode current content as `print mode'
926 a Followup to current content.
929 button-2 Move to point under the mouse cursor
930 and decode current content as `play mode'
933 (mime-maybe-hide-echo-buffer)
934 (let ((ret (mime-view-setup-buffers ctl encoding ibuf obuf))
935 (win-conf (current-window-configuration))
938 (switch-to-buffer ret)
939 (setq mime-preview-original-window-configuration win-conf)
942 (setq mime-mother-buffer mother)
944 (mime-view-define-keymap default-keymap-or-function)
946 (next-single-property-change (point-min) 'mime-view-entity)))
949 (goto-char (point-min))
950 (search-forward "\n\n" nil t)
952 (run-hooks 'mime-view-mode-hook)
959 (autoload 'mime-preview-play-current-entity "mime-play"
960 "Play current entity." t)
962 (defun mime-preview-extract-current-entity ()
963 "Extract current entity into file (maybe).
964 It decodes current entity to call internal or external method as
965 \"extract\" mode. The method is selected from variable
966 `mime-acting-condition'."
968 (mime-preview-play-current-entity "extract")
971 (defun mime-preview-print-current-entity ()
972 "Print current entity (maybe).
973 It decodes current entity to call internal or external method as
974 \"print\" mode. The method is selected from variable
975 `mime-acting-condition'."
977 (mime-preview-play-current-entity "print")
984 (defun mime-preview-original-major-mode ()
985 "Return major-mode of original buffer.
986 If a current buffer has mime-mother-buffer, return original major-mode
987 of the mother-buffer."
988 (if mime-mother-buffer
990 (set-buffer mime-mother-buffer)
991 (mime-preview-original-major-mode)
993 mime-preview-original-major-mode))
995 (defun mime-preview-follow-current-entity ()
996 "Write follow message to current entity.
997 It calls following-method selected from variable
998 `mime-view-following-method-alist'."
1000 (let ((message-info (get-text-property (point-min) 'mime-view-entity))
1002 (while (null (setq entity
1003 (get-text-property (point) 'mime-view-entity)))
1007 (previous-single-property-change (point) 'mime-view-entity))
1009 (entity-node-id (mime-entity-node-id entity))
1010 (len (length entity-node-id))
1014 (if (eq (next-single-property-change (point-min)
1020 ((eq (next-single-property-change p-beg 'mime-view-entity)
1022 (setq p-beg (point))
1024 (setq p-end (next-single-property-change p-beg 'mime-view-entity))
1026 (setq p-end (point-max))
1028 ((null entity-node-id)
1029 (setq p-end (point-max))
1037 (next-single-property-change
1038 (point) 'mime-view-entity))
1040 (let ((rc (mime-entity-node-id
1041 (get-text-property (point)
1042 'mime-view-entity))))
1043 (or (equal entity-node-id
1044 (nthcdr (- (length rc) len) rc))
1049 (setq p-end (point-max))
1052 (let* ((mode (mime-preview-original-major-mode))
1054 (format "%s-%s" (buffer-name) (reverse entity-node-id)))
1056 (the-buf (current-buffer))
1057 (a-buf mime-raw-buffer)
1060 (set-buffer (setq new-buf (get-buffer-create new-name)))
1062 (insert-buffer-substring the-buf p-beg p-end)
1063 (goto-char (point-min))
1064 (if (mime-view-header-visible-p entity message-info)
1065 (delete-region (goto-char (point-min))
1066 (if (re-search-forward "^$" nil t)
1070 (goto-char (point-min))
1072 (goto-char (point-min))
1073 (let ((entity-node-id (mime-entity-node-id entity)) ci str)
1081 (mime-raw-find-entity-from-node-id entity-node-id))
1084 (mime-entity-point-min ci)
1085 (mime-entity-point-max ci)
1087 (std11-header-string-except
1089 (apply (function regexp-or) fields)
1092 (eq (mime-entity-media-type ci) 'message)
1093 (eq (mime-entity-media-subtype ci) 'rfc822))
1099 (setq fields (std11-collect-field-names)
1100 entity-node-id (cdr entity-node-id))
1103 (let ((rest mime-view-following-required-fields-list))
1105 (let ((field-name (car rest)))
1106 (or (std11-field-body field-name)
1112 (set-buffer the-buf)
1113 (set-buffer mime-mother-buffer)
1114 (set-buffer mime-raw-buffer)
1115 (std11-field-body field-name)
1119 (setq rest (cdr rest))
1121 (eword-decode-header)
1123 (let ((f (cdr (assq mode mime-view-following-method-alist))))
1128 "Sorry, following method for %s is not implemented yet."
1137 (defun mime-preview-display-x-face ()
1139 (save-window-excursion
1140 (set-buffer mime-raw-buffer)
1141 (mime-view-x-face-function)
1148 (defun mime-preview-move-to-upper ()
1149 "Move to upper entity.
1150 If there is no upper entity, call function `mime-preview-quit'."
1153 (while (null (setq cinfo
1154 (get-text-property (point) 'mime-view-entity)))
1157 (let ((r (mime-raw-find-entity-from-node-id
1158 (cdr (mime-entity-node-id cinfo))
1159 (get-text-property 1 'mime-view-entity)))
1162 (while (setq point (previous-single-property-change
1163 (point) 'mime-view-entity))
1165 (if (eq r (get-text-property (point) 'mime-view-entity))
1172 (defun mime-preview-move-to-previous ()
1173 "Move to previous entity.
1174 If there is no previous entity, it calls function registered in
1175 variable `mime-view-over-to-previous-method-alist'."
1177 (while (null (get-text-property (point) 'mime-view-entity))
1181 (previous-single-property-change (point) 'mime-view-entity)))
1184 (let ((f (assq mime-preview-original-major-mode
1185 mime-view-over-to-previous-method-alist)))
1191 (defun mime-preview-move-to-next ()
1192 "Move to next entity.
1193 If there is no previous entity, it calls function registered in
1194 variable `mime-view-over-to-next-method-alist'."
1196 (let ((point (next-single-property-change (point) 'mime-view-entity)))
1199 (let ((f (assq mime-preview-original-major-mode
1200 mime-view-over-to-next-method-alist)))
1206 (defun mime-preview-scroll-up-entity (&optional h)
1207 "Scroll up current entity.
1208 If reached to (point-max), it calls function registered in variable
1209 `mime-view-over-to-next-method-alist'."
1212 (setq h (1- (window-height)))
1214 (if (= (point) (point-max))
1215 (let ((f (assq mime-preview-original-major-mode
1216 mime-view-over-to-next-method-alist)))
1221 (or (next-single-property-change (point) 'mime-view-entity)
1224 (if (> (point) point)
1229 (defun mime-preview-scroll-down-entity (&optional h)
1230 "Scroll down current entity.
1231 If reached to (point-min), it calls function registered in variable
1232 `mime-view-over-to-previous-method-alist'."
1235 (setq h (1- (window-height)))
1237 (if (= (point) (point-min))
1238 (let ((f (assq mime-preview-original-major-mode
1239 mime-view-over-to-previous-method-alist)))
1246 (while (> (point) 1)
1248 (previous-single-property-change (point)
1254 (setq point (point-min))
1256 (forward-line (- h))
1257 (if (< (point) point)
1261 (defun mime-preview-next-line-entity ()
1263 (mime-preview-scroll-up-entity 1)
1266 (defun mime-preview-previous-line-entity ()
1268 (mime-preview-scroll-down-entity 1)
1275 (defun mime-preview-quit ()
1276 "Quit from MIME-preview buffer.
1277 It calls function registered in variable
1278 `mime-preview-quitting-method-alist'."
1280 (let ((r (assq mime-preview-original-major-mode
1281 mime-preview-quitting-method-alist)))
1286 (defun mime-preview-show-summary ()
1288 It calls function registered in variable
1289 `mime-view-show-summary-method'."
1291 (let ((r (assq mime-preview-original-major-mode
1292 mime-view-show-summary-method)))
1297 (defun mime-preview-kill-buffer ()
1299 (kill-buffer (current-buffer))
1306 (provide 'mime-view)
1308 (run-hooks 'mime-view-load-hook)
1310 ;;; mime-view.el ends here