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 WEMI (Widget based 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)
40 (defconst mime-view-version-string
41 `,(concat (car mime-module-version) " MIME-View "
42 (mapconcat #'number-to-string (cddr mime-module-version) ".")
43 " (" (cadr mime-module-version) ")"))
46 ;;; @ buffer local variables
52 (defvar mime-raw-message-info
53 "Information about structure of message.
54 Please use reference function `mime-entity-SLOT' to get value of SLOT.
56 Following is a list of slots of the structure:
58 node-id reversed entity-number (list of integers)
59 point-min beginning point of region in raw-buffer
60 point-max end point of region in raw-buffer
61 type media-type (symbol)
62 subtype media-subtype (symbol)
63 type/subtype media-type/subtype (string or nil)
64 parameters parameter of Content-Type field (association list)
65 encoding Content-Transfer-Encoding (string or nil)
66 children entities included in this entity (list of content-infos)
68 If an entity includes other entities in its body, such as multipart or
69 message/rfc822, `mime-entity' structures of them are included in
70 `children', so the `mime-entity' structure become a tree.")
71 (make-variable-buffer-local 'mime-raw-message-info)
73 (defvar mime-preview-buffer nil
74 "MIME-preview buffer corresponding with the (raw) buffer.")
75 (make-variable-buffer-local 'mime-preview-buffer)
78 ;;; @@ in preview-buffer
81 (defvar mime-mother-buffer nil
82 "Mother buffer corresponding with the (MIME-preview) buffer.
83 If current MIME-preview buffer is generated by other buffer, such as
84 message/partial, it is called `mother-buffer'.")
85 (make-variable-buffer-local 'mime-mother-buffer)
87 (defvar mime-raw-buffer nil
88 "Raw buffer corresponding with the (MIME-preview) buffer.")
89 (make-variable-buffer-local 'mime-raw-buffer)
91 (defvar mime-preview-original-major-mode nil
92 "Major-mode of mime-raw-buffer.")
93 (make-variable-buffer-local 'mime-preview-original-major-mode)
95 (defvar mime-preview-original-window-configuration nil
96 "Window-configuration before mime-view-mode is called.")
97 (make-variable-buffer-local 'mime-preview-original-window-configuration)
100 ;;; @ entity information
103 (defsubst mime-raw-find-entity-from-node-id (entity-node-id
104 &optional message-info)
105 "Return entity from ENTITY-NODE-ID in mime-raw-buffer.
106 If optional argument MESSAGE-INFO is not specified,
107 `mime-raw-message-info' is used."
108 (mime-raw-find-entity-from-number (reverse entity-node-id) message-info))
110 (defun mime-raw-find-entity-from-number (entity-number &optional message-info)
111 "Return entity from ENTITY-NUMBER in mime-raw-buffer.
112 If optional argument MESSAGE-INFO is not specified,
113 `mime-raw-message-info' is used."
115 (setq message-info mime-raw-message-info))
116 (if (eq entity-number t)
118 (let ((sn (car entity-number)))
121 (let ((rc (nth sn (mime-entity-children message-info))))
123 (mime-raw-find-entity-from-number (cdr entity-number) rc)
127 (defun mime-raw-find-entity-from-point (point &optional message-info)
128 "Return entity from POINT in mime-raw-buffer.
129 If optional argument MESSAGE-INFO is not specified,
130 `mime-raw-message-info' is used."
132 (setq message-info mime-raw-message-info))
133 (if (and (<= (mime-entity-point-min message-info) point)
134 (<= point (mime-entity-point-max message-info)))
135 (let ((children (mime-entity-children message-info)))
139 (mime-raw-find-entity-from-point point (car children))))
143 (setq children (cdr children)))
146 (defsubst mime-raw-point-to-entity-node-id (point &optional message-info)
147 "Return entity-node-id from POINT in mime-raw-buffer.
148 If optional argument MESSAGE-INFO is not specified,
149 `mime-raw-message-info' is used."
150 (mime-entity-node-id (mime-raw-find-entity-from-point point message-info)))
152 (defsubst mime-raw-point-to-entity-number (point &optional message-info)
153 "Return entity-number from POINT in mime-raw-buffer.
154 If optional argument MESSAGE-INFO is not specified,
155 `mime-raw-message-info' is used."
156 (reverse (mime-raw-point-to-entity-node-id point message-info)))
158 (defsubst mime-raw-entity-parent (entity &optional message-info)
159 "Return mother entity of ENTITY.
160 If optional argument MESSAGE-INFO is not specified,
161 `mime-raw-message-info' is used."
162 (mime-raw-find-entity-from-node-id (cdr (mime-entity-node-id entity))
165 (defun mime-raw-flatten-message-info (&optional message-info)
166 "Return list of entity in mime-raw-buffer.
167 If optional argument MESSAGE-INFO is not specified,
168 `mime-raw-message-info' is used."
170 (setq message-info mime-raw-message-info))
171 (let ((dest (list message-info))
172 (rcl (mime-entity-children message-info)))
174 (setq dest (nconc dest (mime-raw-flatten-message-info (car rcl))))
175 (setq rcl (cdr rcl)))
179 ;;; @ presentation of preview
185 ;;; @@@ predicate function
188 (defvar mime-view-content-button-visible-ctype-list
189 '("application/pgp"))
191 (defun mime-view-entity-button-visible-p (entity message-info)
192 "Return non-nil if header of ENTITY is visible.
193 Please redefine this function if you want to change default setting."
194 (and (not (mime-root-entity-p entity))
195 (let ((media-type (mime-entity-media-type entity))
196 (media-subtype (mime-entity-media-subtype entity)))
197 (or (not (eq media-type 'application))
198 (and (not (eq media-subtype 'x-selection))
199 (or (not (eq media-subtype 'octet-stream))
201 (mime-raw-entity-parent entity message-info)))
202 (or (not (eq (mime-entity-media-type mother-entity)
204 (not (eq (mime-entity-media-subtype mother-entity)
209 ;;; @@@ entity button generator
212 (defun mime-view-insert-entity-button (entity message-info subj)
213 "Insert entity-button of ENTITY."
214 (let ((entity-node-id (mime-entity-node-id entity))
215 (params (mime-entity-parameters entity)))
217 (let ((access-type (assoc "access-type" params))
218 (num (or (cdr (assoc "x-part-number" params))
219 (if (consp entity-node-id)
222 (format "%s" (1+ num))
224 (reverse entity-node-id) ".")
228 (let ((server (assoc "server" params)))
229 (setq access-type (cdr access-type))
231 (format "%s %s ([%s] %s)"
232 num subj access-type (cdr server))
233 (let ((site (cdr (assoc "site" params)))
234 (dir (cdr (assoc "directory" params)))
236 (format "%s %s ([%s] %s:%s)"
237 num subj access-type site dir)
241 (let ((media-type (mime-entity-media-type entity))
242 (media-subtype (mime-entity-media-subtype entity))
243 (charset (cdr (assoc "charset" params)))
244 (encoding (mime-entity-encoding entity)))
248 (format " <%s/%s%s%s>"
249 media-type media-subtype
251 (concat "; " charset)
254 (concat " (" encoding ")")
256 (if (>= (+ (current-column)(length rest))(window-width))
260 (function mime-preview-play-current-entity))
267 ;;; @@@ predicate function
270 (defvar mime-view-childrens-header-showing-Content-Type-list
271 '("message/rfc822" "message/news"))
273 (defun mime-view-header-visible-p (entity message-info)
274 "Return non-nil if header of ENTITY is visible."
275 (let ((entity-node-id (mime-entity-node-id entity)))
276 (or (null entity-node-id)
277 (member (mime-entity-type/subtype
278 (mime-raw-find-entity-from-node-id
279 (cdr entity-node-id) message-info))
280 mime-view-childrens-header-showing-Content-Type-list)
283 ;;; @@@ entity header filter
286 (defvar mime-view-content-header-filter-alist nil)
288 (defun mime-view-default-content-header-filter ()
289 (mime-view-cut-header)
290 (eword-decode-header)
293 ;;; @@@ entity field cutter
296 (defvar mime-view-ignored-field-list
297 '(".*Received" ".*Path" ".*Id" "References"
298 "Replied" "Errors-To"
299 "Lines" "Sender" ".*Host" "Xref"
300 "Content-Type" "Precedence"
302 "All fields that match this list will be hidden in MIME preview buffer.
303 Each elements are regexp of field-name.")
305 (defvar mime-view-ignored-field-regexp
307 (apply (function regexp-or) mime-view-ignored-field-list)
310 (defvar mime-view-visible-field-list '("Dnas.*" "Message-Id")
311 "All fields that match this list will be displayed in MIME preview buffer.
312 Each elements are regexp of field-name.")
314 (defun mime-view-cut-header ()
315 (goto-char (point-min))
316 (while (re-search-forward mime-view-ignored-field-regexp nil t)
317 (let* ((beg (match-beginning 0))
319 (name (buffer-substring beg end))
322 (let ((rest mime-view-visible-field-list))
324 (if (string-match (car rest) name)
327 (setq rest (cdr rest))))
330 (if (re-search-forward "^\\([^ \t]\\|$\\)" nil t)
339 ;;; @@@ predicate function
342 (defvar mime-preview-condition nil
343 "Condition-tree about how to display entity.")
345 (ctree-set-calist-strictly
346 'mime-preview-condition '((type . application)(subtype . octet-stream)
349 (ctree-set-calist-strictly
350 'mime-preview-condition '((type . application)(subtype . octet-stream)
353 (ctree-set-calist-strictly
354 'mime-preview-condition '((type . application)(subtype . octet-stream)
358 (ctree-set-calist-strictly
359 'mime-preview-condition '((type . application)(subtype . pgp)
362 (ctree-set-calist-strictly
363 'mime-preview-condition '((type . application)(subtype . x-latex)
366 (ctree-set-calist-strictly
367 'mime-preview-condition '((type . application)(subtype . x-selection)
370 (ctree-set-calist-strictly
371 'mime-preview-condition '((type . application)(subtype . x-comment)
374 (ctree-set-calist-strictly
375 'mime-preview-condition '((type . message)(subtype . delivery-status)
378 (ctree-set-calist-strictly
379 'mime-preview-condition '((body . visible)
380 (body-presentation-method . with-filter)
381 (body-filter . mime-preview-filter-for-text/plain)))
383 (ctree-set-calist-strictly
384 'mime-preview-condition '((type . nil)
386 (body-presentation-method . with-filter)
387 (body-filter . mime-preview-filter-for-text/plain)))
389 (ctree-set-calist-strictly
390 'mime-preview-condition '((type . text)(subtype . enriched)
392 (body-presentation-method . with-filter)
394 . mime-preview-filter-for-text/enriched)))
396 (ctree-set-calist-strictly
397 'mime-preview-condition '((type . text)(subtype . richtext)
399 (body-presentation-method . with-filter)
401 . mime-preview-filter-for-text/richtext)))
403 (ctree-set-calist-strictly
404 'mime-preview-condition '((type . text)(subtype . t)
406 (body-presentation-method . with-filter)
407 (body-filter . mime-preview-filter-for-text/plain)))
409 (ctree-set-calist-strictly
410 'mime-preview-condition '((type . message)(subtype . partial)
411 (body-presentation-method
412 . mime-view-insert-message/partial-button)))
414 (defun mime-view-body-visible-p (entity message-info)
415 "Return non-nil if body of ENTITY is visible."
416 (ctree-match-calist mime-preview-condition
417 (list* (cons 'type (mime-entity-media-type entity))
418 (cons 'subtype (mime-entity-media-subtype entity))
419 (cons 'encoding (mime-entity-encoding entity))
420 (cons 'major-mode major-mode)
421 (mime-entity-parameters entity))))
424 ;;; @@@ entity filter
427 (autoload 'mime-preview-filter-for-text/plain "mime-text")
428 (autoload 'mime-preview-filter-for-text/enriched "mime-text")
429 (autoload 'mime-preview-filter-for-text/richtext "mime-text")
431 (defvar mime-text-decoder-alist
432 '((mime-show-message-mode . mime-text-decode-buffer)
433 (mime-temp-message-mode . mime-text-decode-buffer)
434 (t . mime-text-decode-buffer-maybe)
436 "Alist of major-mode vs. mime-text-decoder.
437 Each element looks like (SYMBOL . FUNCTION). SYMBOL is major-mode or
440 Specification of FUNCTION is described in DOC-string of variable
443 This value is overridden by buffer local variable `mime-text-decoder'
447 (defvar mime-view-announcement-for-message/partial
448 (if (and (>= emacs-major-version 19) window-system)
450 This is message/partial style split message.
451 Please press `v' key in this buffer
452 or click here by mouse button-2. "
454 This is message/partial style split message.
455 Please press `v' key in this buffer. "
458 (defun mime-view-insert-message/partial-button (&optional situation)
460 (goto-char (point-max))
461 (if (not (search-backward "\n\n" nil t))
464 (goto-char (point-max))
465 ;;(narrow-to-region (point-max)(point-max))
466 ;;(insert mime-view-announcement-for-message/partial)
467 ;; (mime-add-button (point-min)(point-max)
468 ;; #'mime-preview-play-current-entity)
469 (mime-insert-button mime-view-announcement-for-message/partial
470 #'mime-preview-play-current-entity)
474 ;;; @@ entity separator
477 (defun mime-view-entity-separator-visible-p (entity message-info)
478 "Return non-nil if separator is needed for ENTITY."
479 (and (not (mime-view-header-visible-p entity message-info))
480 (not (mime-view-body-visible-p entity message-info))))
483 ;;; @ acting-condition
486 (defvar mime-acting-condition
487 '(((type . text)(subtype . plain)
488 (method "tm-plain" nil 'file "" 'encoding 'mode 'name)
489 (mode "play" "print")
491 ((type . text)(subtype . html)
492 (method "tm-html" nil 'file "" 'encoding 'mode 'name)
495 ((type . text)(subtype . x-rot13-47)
496 (method . mime-method-to-display-caesar)
499 ((type . text)(subtype . x-rot13-47-48)
500 (method . mime-method-to-display-caesar)
504 ((type . audio)(subtype . basic)
505 (method "tm-au" nil 'file "" 'encoding 'mode 'name)
510 (method "tm-image" nil 'file "" 'encoding 'mode 'name)
511 (mode "play" "print")
514 ((type . video)(subtype . mpeg)
515 (method "tm-mpeg" nil 'file "" 'encoding 'mode 'name)
519 ((type . application)(subtype . postscript)
520 (method "tm-ps" nil 'file "" 'encoding 'mode 'name)
521 (mode "play" "print")
523 ((type . application)(subtype . octet-stream)
524 (method . mime-method-to-save)(mode "play" "print")
527 ((type . message)(subtype . external-body)
528 ("access-type" . "anon-ftp")
529 (method . mime-method-to-display-message/external-ftp)
531 ((type . message)(subtype . rfc822)
532 (method . mime-method-to-display-message/rfc822)
535 ((type . message)(subtype . partial)
536 (method . mime-method-to-store-message/partial)
540 ((method "metamail" t "-m" "tm" "-x" "-d" "-z" "-e" 'file)
543 ((method . mime-method-to-save)(mode . "extract"))
547 ;;; @ quitting method
550 (defvar mime-preview-quitting-method-alist
551 '((mime-show-message-mode
552 . mime-preview-quitting-method-for-mime-show-message-mode))
553 "Alist of major-mode vs. quitting-method of mime-view.")
555 (defvar mime-view-over-to-previous-method-alist nil)
556 (defvar mime-view-over-to-next-method-alist nil)
558 (defvar mime-view-show-summary-method nil
559 "Alist of major-mode vs. show-summary-method.")
562 ;;; @ following method
565 (defvar mime-view-following-method-alist nil
566 "Alist of major-mode vs. following-method of mime-view.")
568 (defvar mime-view-following-required-fields-list
575 ;; hack from Gnus 5.0.4.
577 (defvar mime-view-x-face-to-pbm-command
578 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm")
580 (defvar mime-view-x-face-command
581 (concat mime-view-x-face-to-pbm-command
583 "String to be executed to display an X-Face field.
584 The command will be executed in a sub-shell asynchronously.
585 The compressed face will be piped to this command.")
587 (defun mime-view-x-face-function ()
588 "Function to display X-Face field. You can redefine to customize."
589 ;; 1995/10/12 (c.f. tm-eng:130)
590 ;; fixed by Eric Ding <ericding@San-Jose.ate.slb.com>
592 (narrow-to-region (point-min) (re-search-forward "^$" nil t))
594 (goto-char (point-min))
595 (if (re-search-forward "^X-Face:[ \t]*" nil t)
596 (let ((beg (match-end 0))
597 (end (std11-field-end))
599 (call-process-region beg end "sh" nil 0 nil
600 "-c" mime-view-x-face-command)
607 (defvar mime-view-uuencode-encoding-name-list '("x-uue" "x-uuencode"))
609 (defvar mime-raw-buffer-coding-system-alist
610 `((t . ,(mime-charset-to-coding-system default-mime-charset)))
611 "Alist of major-mode vs. corresponding coding-system of `mime-raw-buffer'.")
617 (defvar mime-view-redisplay nil)
619 (defun mime-view-setup-buffers (&optional ctl encoding ibuf obuf)
625 (or mime-view-redisplay
626 (setq mime-raw-message-info (mime-parse-message ctl encoding))
628 (let ((message-info mime-raw-message-info)
629 (the-buf (current-buffer))
632 (setq obuf (concat "*Preview-" (buffer-name the-buf) "*")))
633 (set-buffer (get-buffer-create obuf))
634 (let ((inhibit-read-only t))
635 ;;(setq buffer-read-only nil)
638 (setq mime-raw-buffer the-buf)
639 (setq mime-preview-original-major-mode mode)
640 (setq major-mode 'mime-view-mode)
641 (setq mode-name "MIME-View")
642 (mime-view-display-entity message-info message-info the-buf obuf)
643 (set-buffer-modified-p nil)
645 (setq buffer-read-only t)
648 (setq mime-preview-buffer obuf)
651 (defun mime-view-display-entity (entity message-info ibuf obuf)
653 (let* ((start (mime-entity-point-min entity))
654 (end (mime-entity-point-max entity))
655 (media-type (mime-entity-media-type entity))
656 (media-subtype (mime-entity-media-subtype entity))
657 (ctype (if media-type
659 (format "%s/%s" media-type media-subtype)
660 (symbol-name media-type)
662 (params (mime-entity-parameters entity))
663 (encoding (mime-entity-encoding entity))
664 (entity-node-id (mime-entity-node-id entity))
665 end-of-header e nb ne subj)
668 (setq end-of-header (if (re-search-forward "^$" nil t)
671 (if (> end-of-header end)
672 (setq end-of-header end)
675 (narrow-to-region start end)
678 (mime-raw-get-subject params encoding)))
682 (narrow-to-region nb nb)
683 (if (mime-view-entity-button-visible-p entity message-info)
684 (mime-view-insert-entity-button entity message-info subj)
686 (if (mime-view-header-visible-p entity message-info)
688 (narrow-to-region (point)(point))
689 (insert-buffer-substring mime-raw-buffer start end-of-header)
690 (let ((f (cdr (assq mime-preview-original-major-mode
691 mime-view-content-header-filter-alist))))
694 (mime-view-default-content-header-filter)
696 (run-hooks 'mime-view-content-header-filter-hook)
698 (if (and (mime-root-entity-p entity)
700 ctype mime-view-content-button-visible-ctype-list))
702 (goto-char (point-max))
703 (mime-view-insert-entity-button entity message-info subj)
706 (ctree-match-calist mime-preview-condition
707 (list* (cons 'type media-type)
708 (cons 'subtype media-subtype)
709 (cons 'encoding encoding)
710 (cons 'major-mode major-mode)
712 (body-presentation-method
713 (cdr (assq 'body-presentation-method situation))))
714 (cond ((eq body-presentation-method 'with-filter)
715 (let ((body-filter (cdr (assq 'body-filter situation))))
717 (narrow-to-region (point-max)(point-max))
718 (insert-buffer-substring mime-raw-buffer end-of-header end)
719 (funcall body-filter situation)
721 ((functionp body-presentation-method)
722 (funcall body-presentation-method situation)
724 ((and (null entity-node-id)
725 (null (mime-entity-children message-info)))
726 (goto-char (point-max))
727 (mime-view-insert-entity-button entity message-info subj)
729 (when (mime-view-entity-separator-visible-p entity message-info)
730 (goto-char (point-max))
733 (setq ne (point-max))
735 (put-text-property nb ne 'mime-view-raw-buffer ibuf)
736 (put-text-property nb ne 'mime-view-entity entity)
738 (let ((children (mime-entity-children entity)))
740 (mime-view-display-entity (car children) message-info ibuf obuf)
741 (setq children (cdr children))
744 (defun mime-raw-get-uu-filename (param &optional encoding)
745 (if (member (or encoding
746 (cdr (assq 'encoding param))
748 mime-view-uuencode-encoding-name-list)
750 (or (if (re-search-forward "^begin [0-9]+ " nil t)
751 (if (looking-at ".+$")
752 (buffer-substring (match-beginning 0)(match-end 0))
757 (defun mime-raw-get-subject (param &optional encoding)
758 (or (std11-find-field-body '("Content-Description" "Subject"))
760 (if (or (and (setq ret (mime/Content-Disposition))
761 (setq ret (assoc "filename" (cdr ret)))
763 (setq ret (assoc "name" param))
764 (setq ret (assoc "x-name" param))
766 (std11-strip-quoted-string (cdr ret))
768 (mime-raw-get-uu-filename param encoding)
772 ;;; @ MIME viewer mode
775 (defconst mime-view-menu-title "MIME-View")
776 (defconst mime-view-menu-list
777 '((up "Move to upper entity" mime-preview-move-to-upper)
778 (previous "Move to previous entity" mime-preview-move-to-previous)
779 (next "Move to next entity" mime-preview-move-to-next)
780 (scroll-down "Scroll-down" mime-preview-scroll-down-entity)
781 (scroll-up "Scroll-up" mime-preview-scroll-up-entity)
782 (play "Play current entity" mime-preview-play-current-entity)
783 (extract "Extract current entity" mime-preview-extract-current-entity)
784 (print "Print current entity" mime-preview-print-current-entity)
785 (x-face "Show X Face" mime-preview-display-x-face)
787 "Menu for MIME Viewer")
789 (cond (running-xemacs
790 (defvar mime-view-xemacs-popup-menu
791 (cons mime-view-menu-title
794 (vector (nth 1 item)(nth 2 item) t)
796 mime-view-menu-list)))
797 (defun mime-view-xemacs-popup-menu (event)
798 "Popup the menu in the MIME Viewer buffer"
800 (select-window (event-window event))
801 (set-buffer (event-buffer event))
802 (popup-menu 'mime-view-xemacs-popup-menu))
803 (defvar mouse-button-2 'button2)
806 (defvar mouse-button-2 [mouse-2])
809 (defun mime-view-define-keymap (&optional default)
810 (let ((mime-view-mode-map (if (keymapp default)
811 (copy-keymap default)
814 (define-key mime-view-mode-map
815 "u" (function mime-preview-move-to-upper))
816 (define-key mime-view-mode-map
817 "p" (function mime-preview-move-to-previous))
818 (define-key mime-view-mode-map
819 "n" (function mime-preview-move-to-next))
820 (define-key mime-view-mode-map
821 "\e\t" (function mime-preview-move-to-previous))
822 (define-key mime-view-mode-map
823 "\t" (function mime-preview-move-to-next))
824 (define-key mime-view-mode-map
825 " " (function mime-preview-scroll-up-entity))
826 (define-key mime-view-mode-map
827 "\M- " (function mime-preview-scroll-down-entity))
828 (define-key mime-view-mode-map
829 "\177" (function mime-preview-scroll-down-entity))
830 (define-key mime-view-mode-map
831 "\C-m" (function mime-preview-next-line-entity))
832 (define-key mime-view-mode-map
833 "\C-\M-m" (function mime-preview-previous-line-entity))
834 (define-key mime-view-mode-map
835 "v" (function mime-preview-play-current-entity))
836 (define-key mime-view-mode-map
837 "e" (function mime-preview-extract-current-entity))
838 (define-key mime-view-mode-map
839 "\C-c\C-p" (function mime-preview-print-current-entity))
840 (define-key mime-view-mode-map
841 "a" (function mime-preview-follow-current-entity))
842 (define-key mime-view-mode-map
843 "q" (function mime-preview-quit))
844 (define-key mime-view-mode-map
845 "h" (function mime-preview-show-summary))
846 (define-key mime-view-mode-map
847 "\C-c\C-x" (function mime-preview-kill-buffer))
848 ;; (define-key mime-view-mode-map
849 ;; "<" (function beginning-of-buffer))
850 ;; (define-key mime-view-mode-map
851 ;; ">" (function end-of-buffer))
852 (define-key mime-view-mode-map
853 "?" (function describe-mode))
854 (define-key mime-view-mode-map
855 [tab] (function mime-preview-move-to-next))
856 (define-key mime-view-mode-map
857 [delete] (function mime-preview-scroll-down-entity))
858 (define-key mime-view-mode-map
859 [backspace] (function mime-preview-scroll-down-entity))
860 (if (functionp default)
861 (cond (running-xemacs
862 (set-keymap-default-binding mime-view-mode-map default)
865 (setq mime-view-mode-map
866 (append mime-view-mode-map (list (cons t default))))
869 (define-key mime-view-mode-map
870 mouse-button-2 (function mime-button-dispatcher))
872 (cond (running-xemacs
873 (define-key mime-view-mode-map
874 mouse-button-3 (function mime-view-xemacs-popup-menu))
876 ((>= emacs-major-version 19)
877 (define-key mime-view-mode-map [menu-bar mime-view]
878 (cons mime-view-menu-title
879 (make-sparse-keymap mime-view-menu-title)))
882 (define-key mime-view-mode-map
883 (vector 'menu-bar 'mime-view (car item))
884 (cons (nth 1 item)(nth 2 item))
887 (reverse mime-view-menu-list)
890 (use-local-map mime-view-mode-map)
891 (run-hooks 'mime-view-define-keymap-hook)
894 (defsubst mime-maybe-hide-echo-buffer ()
895 "Clear mime-echo buffer and delete window for it."
896 (let ((buf (get-buffer mime-echo-buffer-name)))
901 (let ((win (get-buffer-window buf)))
908 (defun mime-view-mode (&optional mother ctl encoding ibuf obuf
909 default-keymap-or-function)
910 "Major mode for viewing MIME message.
912 Here is a list of the standard keys for mime-view-mode.
917 u Move to upper content
918 p or M-TAB Move to previous content
919 n or TAB Move to next content
920 SPC Scroll up or move to next content
921 M-SPC or DEL Scroll down or move to previous content
922 RET Move to next line
923 M-RET Move to previous line
924 v Decode current content as `play mode'
925 e Decode current content as `extract mode'
926 C-c C-p Decode current content as `print mode'
927 a Followup to current content.
930 button-2 Move to point under the mouse cursor
931 and decode current content as `play mode'
934 (mime-maybe-hide-echo-buffer)
935 (let ((ret (mime-view-setup-buffers ctl encoding ibuf obuf))
936 (win-conf (current-window-configuration))
939 (switch-to-buffer ret)
940 (setq mime-preview-original-window-configuration win-conf)
943 (setq mime-mother-buffer mother)
945 (mime-view-define-keymap default-keymap-or-function)
947 (next-single-property-change (point-min) 'mime-view-entity)))
950 (goto-char (point-min))
951 (search-forward "\n\n" nil t)
953 (run-hooks 'mime-view-mode-hook)
960 (autoload 'mime-preview-play-current-entity "mime-play"
961 "Play current entity." t)
963 (defun mime-preview-extract-current-entity ()
964 "Extract current entity into file (maybe).
965 It decodes current entity to call internal or external method as
966 \"extract\" mode. The method is selected from variable
967 `mime-acting-condition'."
969 (mime-preview-play-current-entity "extract")
972 (defun mime-preview-print-current-entity ()
973 "Print current entity (maybe).
974 It decodes current entity to call internal or external method as
975 \"print\" mode. The method is selected from variable
976 `mime-acting-condition'."
978 (mime-preview-play-current-entity "print")
985 (defun mime-preview-original-major-mode ()
986 "Return major-mode of original buffer.
987 If a current buffer has mime-mother-buffer, return original major-mode
988 of the mother-buffer."
989 (if mime-mother-buffer
991 (set-buffer mime-mother-buffer)
992 (mime-preview-original-major-mode)
994 mime-preview-original-major-mode))
996 (defun mime-preview-follow-current-entity ()
997 "Write follow message to current entity.
998 It calls following-method selected from variable
999 `mime-view-following-method-alist'."
1001 (let ((message-info (get-text-property (point-min) 'mime-view-entity))
1003 (while (null (setq entity
1004 (get-text-property (point) 'mime-view-entity)))
1008 (previous-single-property-change (point) 'mime-view-entity))
1010 (entity-node-id (mime-entity-node-id entity))
1011 (len (length entity-node-id))
1015 (if (eq (next-single-property-change (point-min)
1021 ((eq (next-single-property-change p-beg 'mime-view-entity)
1023 (setq p-beg (point))
1025 (setq p-end (next-single-property-change p-beg 'mime-view-entity))
1027 (setq p-end (point-max))
1029 ((null entity-node-id)
1030 (setq p-end (point-max))
1038 (next-single-property-change
1039 (point) 'mime-view-entity))
1041 (let ((rc (mime-entity-node-id
1042 (get-text-property (point)
1043 'mime-view-entity))))
1044 (or (equal entity-node-id
1045 (nthcdr (- (length rc) len) rc))
1050 (setq p-end (point-max))
1053 (let* ((mode (mime-preview-original-major-mode))
1055 (format "%s-%s" (buffer-name) (reverse entity-node-id)))
1057 (the-buf (current-buffer))
1058 (a-buf mime-raw-buffer)
1061 (set-buffer (setq new-buf (get-buffer-create new-name)))
1063 (insert-buffer-substring the-buf p-beg p-end)
1064 (goto-char (point-min))
1065 (if (mime-view-header-visible-p entity message-info)
1066 (delete-region (goto-char (point-min))
1067 (if (re-search-forward "^$" nil t)
1071 (goto-char (point-min))
1073 (goto-char (point-min))
1074 (let ((entity-node-id (mime-entity-node-id entity)) ci str)
1082 (mime-raw-find-entity-from-node-id entity-node-id))
1085 (mime-entity-point-min ci)
1086 (mime-entity-point-max ci)
1088 (std11-header-string-except
1090 (apply (function regexp-or) fields)
1093 (eq (mime-entity-media-type ci) 'message)
1094 (eq (mime-entity-media-subtype ci) 'rfc822))
1100 (setq fields (std11-collect-field-names)
1101 entity-node-id (cdr entity-node-id))
1104 (let ((rest mime-view-following-required-fields-list))
1106 (let ((field-name (car rest)))
1107 (or (std11-field-body field-name)
1113 (set-buffer the-buf)
1114 (set-buffer mime-mother-buffer)
1115 (set-buffer mime-raw-buffer)
1116 (std11-field-body field-name)
1120 (setq rest (cdr rest))
1122 (eword-decode-header)
1124 (let ((f (cdr (assq mode mime-view-following-method-alist))))
1129 "Sorry, following method for %s is not implemented yet."
1138 (defun mime-preview-display-x-face ()
1140 (save-window-excursion
1141 (set-buffer mime-raw-buffer)
1142 (mime-view-x-face-function)
1149 (defun mime-preview-move-to-upper ()
1150 "Move to upper entity.
1151 If there is no upper entity, call function `mime-preview-quit'."
1154 (while (null (setq cinfo
1155 (get-text-property (point) 'mime-view-entity)))
1158 (let ((r (mime-raw-find-entity-from-node-id
1159 (cdr (mime-entity-node-id cinfo))
1160 (get-text-property 1 'mime-view-entity)))
1163 (while (setq point (previous-single-property-change
1164 (point) 'mime-view-entity))
1166 (if (eq r (get-text-property (point) 'mime-view-entity))
1173 (defun mime-preview-move-to-previous ()
1174 "Move to previous entity.
1175 If there is no previous entity, it calls function registered in
1176 variable `mime-view-over-to-previous-method-alist'."
1178 (while (null (get-text-property (point) 'mime-view-entity))
1182 (previous-single-property-change (point) 'mime-view-entity)))
1185 (let ((f (assq mime-preview-original-major-mode
1186 mime-view-over-to-previous-method-alist)))
1192 (defun mime-preview-move-to-next ()
1193 "Move to next entity.
1194 If there is no previous entity, it calls function registered in
1195 variable `mime-view-over-to-next-method-alist'."
1197 (let ((point (next-single-property-change (point) 'mime-view-entity)))
1200 (let ((f (assq mime-preview-original-major-mode
1201 mime-view-over-to-next-method-alist)))
1207 (defun mime-preview-scroll-up-entity (&optional h)
1208 "Scroll up current entity.
1209 If reached to (point-max), it calls function registered in variable
1210 `mime-view-over-to-next-method-alist'."
1213 (setq h (1- (window-height)))
1215 (if (= (point) (point-max))
1216 (let ((f (assq mime-preview-original-major-mode
1217 mime-view-over-to-next-method-alist)))
1222 (or (next-single-property-change (point) 'mime-view-entity)
1225 (if (> (point) point)
1230 (defun mime-preview-scroll-down-entity (&optional h)
1231 "Scroll down current entity.
1232 If reached to (point-min), it calls function registered in variable
1233 `mime-view-over-to-previous-method-alist'."
1236 (setq h (1- (window-height)))
1238 (if (= (point) (point-min))
1239 (let ((f (assq mime-preview-original-major-mode
1240 mime-view-over-to-previous-method-alist)))
1247 (while (> (point) 1)
1249 (previous-single-property-change (point)
1255 (setq point (point-min))
1257 (forward-line (- h))
1258 (if (< (point) point)
1262 (defun mime-preview-next-line-entity ()
1264 (mime-preview-scroll-up-entity 1)
1267 (defun mime-preview-previous-line-entity ()
1269 (mime-preview-scroll-down-entity 1)
1276 (defun mime-preview-quit ()
1277 "Quit from MIME-preview buffer.
1278 It calls function registered in variable
1279 `mime-preview-quitting-method-alist'."
1281 (let ((r (assq mime-preview-original-major-mode
1282 mime-preview-quitting-method-alist)))
1287 (defun mime-preview-show-summary ()
1289 It calls function registered in variable
1290 `mime-view-show-summary-method'."
1292 (let ((r (assq mime-preview-original-major-mode
1293 mime-view-show-summary-method)))
1298 (defun mime-preview-kill-buffer ()
1300 (kill-buffer (current-buffer))
1307 (provide 'mime-view)
1309 (run-hooks 'mime-view-load-hook)
1311 ;;; mime-view.el ends here