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/8/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 "SEMI MIME-View "
43 (mapconcat #'number-to-string (cdr semi-version) ".")
44 " (" (car semi-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 (make-variable-buffer-local 'mime-preview-original-window-configuration)
102 (defvar mime-view-content-button-visible-ctype-list
103 '("application/pgp"))
105 (defun mime-view-insert-entity-button (entity message-info subj)
106 "Insert entity-button of ENTITY."
107 (let ((entity-node-id (mime-entity-node-id entity))
108 (params (mime-entity-parameters entity)))
110 (let ((access-type (assoc "access-type" params))
111 (num (or (cdr (assoc "x-part-number" params))
112 (if (consp entity-node-id)
115 (format "%s" (1+ num))
117 (reverse entity-node-id) ".")
121 (let ((server (assoc "server" params)))
122 (setq access-type (cdr access-type))
124 (format "%s %s ([%s] %s)"
125 num subj access-type (cdr server))
126 (let ((site (cdr (assoc "site" params)))
127 (dir (cdr (assoc "directory" params)))
129 (format "%s %s ([%s] %s:%s)"
130 num subj access-type site dir)
134 (let ((media-type (mime-entity-media-type entity))
135 (media-subtype (mime-entity-media-subtype entity))
136 (charset (cdr (assoc "charset" params)))
137 (encoding (mime-entity-encoding entity)))
141 (format " <%s/%s%s%s>"
142 media-type media-subtype
144 (concat "; " charset)
147 (concat " (" encoding ")")
149 (if (>= (+ (current-column)(length rest))(window-width))
153 (function mime-preview-play-current-entity))
156 (defun mime-view-entity-button-function (entity message-info subj)
157 "Insert entity-button of ENTITY conditionally.
158 Please redefine this function if you want to change default setting."
159 (let ((media-type (mime-entity-media-type entity))
160 (media-subtype (mime-entity-media-subtype entity)))
161 (or (mime-root-entity-p entity)
162 (and (eq media-type 'application)
163 (or (eq media-subtype 'x-selection)
164 (and (eq media-subtype 'octet-stream)
166 (mime-raw-entity-parent entity message-info)))
167 (and (eq (mime-entity-media-type mother-entity)
169 (eq (mime-entity-media-subtype mother-entity)
172 (mime-view-insert-entity-button entity message-info subj)
179 ;;; @@ predicate function
182 (defvar mime-view-childrens-header-showing-Content-Type-list
183 '("message/rfc822" "message/news"))
185 (defun mime-view-header-visible-p (entity message-info)
186 "Return non-nil if header of ENTITY is visible."
187 (let ((entity-node-id (mime-entity-node-id entity)))
188 (or (null entity-node-id)
189 (member (mime-entity-type/subtype
190 (mime-raw-find-entity-from-node-id
191 (cdr entity-node-id) message-info))
192 mime-view-childrens-header-showing-Content-Type-list)
195 ;;; @@ entity header filter
198 (defvar mime-view-content-header-filter-alist nil)
200 (defun mime-view-default-content-header-filter ()
201 (mime-view-cut-header)
202 (eword-decode-header)
205 (defun mime-view-display-header (beg end)
207 (narrow-to-region (point)(point))
208 (insert-buffer-substring mime-raw-buffer beg end)
209 (let ((f (cdr (assq mime-preview-original-major-mode
210 mime-view-content-header-filter-alist))))
213 (mime-view-default-content-header-filter)
215 (run-hooks 'mime-view-content-header-filter-hook)
218 ;;; @@ entity field cutter
221 (defvar mime-view-ignored-field-list
222 '(".*Received" ".*Path" ".*Id" "References"
223 "Replied" "Errors-To"
224 "Lines" "Sender" ".*Host" "Xref"
225 "Content-Type" "Precedence"
227 "All fields that match this list will be hidden in MIME preview buffer.
228 Each elements are regexp of field-name.")
230 (defvar mime-view-ignored-field-regexp
232 (apply (function regexp-or) mime-view-ignored-field-list)
235 (defvar mime-view-visible-field-list '("Dnas.*" "Message-Id")
236 "All fields that match this list will be displayed in MIME preview buffer.
237 Each elements are regexp of field-name.")
239 (defun mime-view-cut-header ()
240 (goto-char (point-min))
241 (while (re-search-forward mime-view-ignored-field-regexp nil t)
242 (let* ((beg (match-beginning 0))
244 (name (buffer-substring beg end))
247 (let ((rest mime-view-visible-field-list))
249 (if (string-match (car rest) name)
252 (setq rest (cdr rest))))
255 (if (re-search-forward "^\\([^ \t]\\|$\\)" nil t)
264 ;;; @@ predicate function
267 (defvar mime-view-body-visible-condition
278 (octet-stream encoding
288 "Condition-tree to be able to display body of entity.")
290 (defun mime-view-body-visible-p (entity message-info)
291 "Return non-nil if body of ENTITY is visible."
293 mime-view-body-visible-condition
294 (list* (cons 'type (mime-entity-media-type entity))
295 (cons 'subtype (mime-entity-media-subtype entity))
296 (cons 'encoding (mime-entity-encoding entity))
297 (cons 'major-mode major-mode)
298 (mime-entity-parameters entity))))
300 ;; (defvar mime-view-visible-media-type-list
301 ;; '("text/plain" nil "text/richtext" "text/enriched"
302 ;; "text/rfc822-headers"
303 ;; "text/x-latex" "application/x-latex"
304 ;; "message/delivery-status"
305 ;; "application/pgp" "text/x-pgp"
306 ;; "application/octet-stream"
307 ;; "application/x-selection" "application/x-comment")
308 ;; "*List of media-types to be able to display in MIME-preview buffer.
309 ;; Each elements are string of TYPE/SUBTYPE, e.g. \"text/plain\".")
311 ;; (defun mime-view-body-visible-p (entity message-info)
312 ;; "Return non-nil if body of ENTITY is visible."
313 ;; (let ((media-type (mime-entity-media-type entity))
314 ;; (media-subtype (mime-entity-media-subtype entity))
315 ;; (ctype (mime-entity-type/subtype entity)))
316 ;; (and (member ctype mime-view-visible-media-type-list)
317 ;; (if (and (eq media-type 'application)
318 ;; (eq media-subtype 'octet-stream))
319 ;; (member (mime-entity-encoding entity) '(nil "7bit" "8bit"))
326 (defvar mime-view-content-filter-alist
327 '(("text/enriched" . mime-view-filter-for-text/enriched)
328 ("text/richtext" . mime-view-filter-for-text/richtext)
329 (t . mime-view-filter-for-text/plain)
331 "Alist of media-types vs. corresponding MIME-preview filter functions.
332 Each element looks like (TYPE/SUBTYPE . FUNCTION) or (t . FUNCTION).
333 TYPE/SUBTYPE is a string of media-type and FUNCTION is a filter
334 function. t means default media-type.")
336 (defun mime-view-display-body (start end entity message-info subj)
338 (narrow-to-region (point-max)(point-max))
339 (insert-buffer-substring mime-raw-buffer start end)
340 (let* ((ctype (mime-entity-type/subtype entity))
341 (params (mime-entity-parameters entity))
342 (encoding (mime-entity-encoding entity))
343 (f (cdr (or (assoc ctype mime-view-content-filter-alist)
344 (assq t mime-view-content-filter-alist)))))
346 (funcall f ctype params encoding))
349 (defvar mime-view-announcement-for-message/partial
350 (if (and (>= emacs-major-version 19) window-system)
352 \[[ This is message/partial style split message. ]]
353 \[[ Please press `v' key in this buffer ]]
354 \[[ or click here by mouse button-2. ]]"
356 \[[ This is message/partial style split message. ]]
357 \[[ Please press `v' key in this buffer. ]]"
360 (defun mime-view-insert-message/partial-button ()
362 (goto-char (point-max))
363 (if (not (search-backward "\n\n" nil t))
366 (goto-char (point-max))
367 (narrow-to-region (point-max)(point-max))
368 (insert mime-view-announcement-for-message/partial)
369 (mime-add-button (point-min)(point-max)
370 #'mime-preview-play-current-entity)
374 ;;; @ entity separator
377 (defun mime-view-entity-separator-function (entity message-info)
378 "Insert entity-separator of ENTITY conditionally.
379 Please redefine this function if you want to change default setting."
380 (or (mime-view-header-visible-p entity message-info)
381 (mime-view-body-visible-p entity message-info)
383 (goto-char (point-max))
388 ;;; @ acting-condition
391 (defvar mime-acting-condition
392 '(((type . text)(subtype . plain)
393 (method "tm-plain" nil 'file "" 'encoding 'mode 'name)
394 (mode "play" "print")
396 ((type . text)(subtype . html)
397 (method "tm-html" nil 'file "" 'encoding 'mode 'name)
400 ((type . text)(subtype . x-rot13-47)
401 (method . mime-method-to-display-caesar)
404 ((type . text)(subtype . x-rot13-47-48)
405 (method . mime-method-to-display-caesar)
409 ((type . audio)(subtype . basic)
410 (method "tm-au" nil 'file "" 'encoding 'mode 'name)
415 (method "tm-image" nil 'file "" 'encoding 'mode 'name)
416 (mode "play" "print")
419 ((type . video)(subtype . mpeg)
420 (method "tm-mpeg" nil 'file "" 'encoding 'mode 'name)
424 ((type . application)(subtype . postscript)
425 (method "tm-ps" nil 'file "" 'encoding 'mode 'name)
426 (mode "play" "print")
428 ((type . application)(subtype . octet-stream)
429 (method . mime-method-to-save)(mode "play" "print")
432 ((type . message)(subtype . external-body)
433 ("access-type" . "anon-ftp")
434 (method . mime-method-to-display-message/external-ftp)
436 ((type . message)(subtype . rfc822)
437 (method . mime-method-to-display-message/rfc822)
440 ((type . message)(subtype . partial)
441 (method . mime-method-to-store-message/partial)
445 ((method "metamail" t "-m" "tm" "-x" "-d" "-z" "-e" 'file)
448 ((method . mime-method-to-save)(mode . "extract"))
452 ;;; @ quitting method
455 (defvar mime-preview-quitting-method-alist
456 '((mime-show-message-mode
457 . mime-preview-quitting-method-for-mime-show-message-mode))
458 "Alist of major-mode vs. quitting-method of mime-view.")
460 (defvar mime-view-over-to-previous-method-alist nil)
461 (defvar mime-view-over-to-next-method-alist nil)
463 (defvar mime-view-show-summary-method nil
464 "Alist of major-mode vs. show-summary-method.")
467 ;;; @ following method
470 (defvar mime-view-following-method-alist nil
471 "Alist of major-mode vs. following-method of mime-view.")
473 (defvar mime-view-following-required-fields-list
480 ;; hack from Gnus 5.0.4.
482 (defvar mime-view-x-face-to-pbm-command
483 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm")
485 (defvar mime-view-x-face-command
486 (concat mime-view-x-face-to-pbm-command
488 "String to be executed to display an X-Face field.
489 The command will be executed in a sub-shell asynchronously.
490 The compressed face will be piped to this command.")
492 (defun mime-view-x-face-function ()
493 "Function to display X-Face field. You can redefine to customize."
494 ;; 1995/10/12 (c.f. tm-eng:130)
495 ;; fixed by Eric Ding <ericding@San-Jose.ate.slb.com>
497 (narrow-to-region (point-min) (re-search-forward "^$" nil t))
499 (goto-char (point-min))
500 (if (re-search-forward "^X-Face:[ \t]*" nil t)
501 (let ((beg (match-end 0))
502 (end (std11-field-end))
504 (call-process-region beg end "sh" nil 0 nil
505 "-c" mime-view-x-face-command)
512 (defvar mime-view-uuencode-encoding-name-list '("x-uue" "x-uuencode"))
514 (defvar mime-raw-buffer-coding-system-alist
515 `((t . ,(mime-charset-to-coding-system default-mime-charset)))
516 "Alist of major-mode vs. corresponding coding-system of `mime-raw-buffer'.")
522 (defvar mime-view-redisplay nil)
524 (defun mime-view-setup-buffers (&optional ctl encoding ibuf obuf)
530 (or mime-view-redisplay
531 (setq mime-raw-message-info (mime-parse-message ctl encoding))
533 (let* ((message-info mime-raw-message-info)
534 (pcl (mime-raw-flatten-message-info message-info))
535 (the-buf (current-buffer))
539 (setq obuf (concat "*Preview-" (buffer-name the-buf) "*")))
540 (set-buffer (get-buffer-create obuf))
541 (let ((inhibit-read-only t))
542 ;;(setq buffer-read-only nil)
545 (setq mime-raw-buffer the-buf)
546 (setq mime-preview-original-major-mode mode)
547 (setq major-mode 'mime-view-mode)
548 (setq mode-name "MIME-View")
550 (mime-view-display-entity (car pcl) message-info the-buf obuf)
553 (set-buffer-modified-p nil)
555 (setq buffer-read-only t)
558 (setq mime-preview-buffer obuf)
561 (defun mime-view-display-entity (entity message-info ibuf obuf)
563 (let* ((beg (mime-entity-point-min entity))
564 (end (mime-entity-point-max entity))
565 (media-type (mime-entity-media-type entity))
566 (media-subtype (mime-entity-media-subtype entity))
567 (ctype (if media-type
569 (format "%s/%s" media-type media-subtype)
570 (symbol-name media-type)
572 (params (mime-entity-parameters entity))
573 (encoding (mime-entity-encoding entity))
574 (entity-node-id (mime-entity-node-id entity))
578 (setq he (if (re-search-forward "^$" nil t)
585 (narrow-to-region beg end)
588 (mime-raw-get-subject params encoding)))
592 (narrow-to-region nb nb)
593 (mime-view-entity-button-function entity message-info subj)
594 (if (mime-view-header-visible-p entity message-info)
595 (mime-view-display-header beg he)
597 (if (and (null entity-node-id)
599 ctype mime-view-content-button-visible-ctype-list))
601 (goto-char (point-max))
602 (mime-view-insert-entity-button entity message-info subj)
604 (cond ((mime-view-body-visible-p entity message-info)
605 (mime-view-display-body he end entity message-info subj)
607 ((and (eq media-type 'message)(eq media-subtype 'partial))
608 (mime-view-insert-message/partial-button)
610 ((and (null entity-node-id)
611 (null (mime-entity-children message-info))
613 (goto-char (point-max))
614 (mime-view-insert-entity-button entity message-info subj)
616 (mime-view-entity-separator-function entity message-info)
617 (setq ne (point-max))
619 (put-text-property nb ne 'mime-view-raw-buffer ibuf)
620 (put-text-property nb ne 'mime-view-entity entity)
624 (defun mime-raw-get-uu-filename (param &optional encoding)
625 (if (member (or encoding
626 (cdr (assq 'encoding param))
628 mime-view-uuencode-encoding-name-list)
630 (or (if (re-search-forward "^begin [0-9]+ " nil t)
631 (if (looking-at ".+$")
632 (buffer-substring (match-beginning 0)(match-end 0))
637 (defun mime-raw-get-subject (param &optional encoding)
638 (or (std11-find-field-body '("Content-Description" "Subject"))
640 (if (or (and (setq ret (mime/Content-Disposition))
641 (setq ret (assoc "filename" (cdr ret)))
643 (setq ret (assoc "name" param))
644 (setq ret (assoc "x-name" param))
646 (std11-strip-quoted-string (cdr ret))
648 (mime-raw-get-uu-filename param encoding)
652 ;;; @ entity information
655 (defsubst mime-raw-find-entity-from-node-id (entity-node-id
656 &optional message-info)
657 "Return entity from ENTITY-NODE-ID in mime-raw-buffer.
658 If optional argument MESSAGE-INFO is not specified,
659 `mime-raw-message-info' is used."
660 (mime-raw-find-entity-from-number (reverse entity-node-id) message-info))
662 (defun mime-raw-find-entity-from-number (entity-number &optional message-info)
663 "Return entity from ENTITY-NUMBER in mime-raw-buffer.
664 If optional argument MESSAGE-INFO is not specified,
665 `mime-raw-message-info' is used."
667 (setq message-info mime-raw-message-info))
668 (if (eq entity-number t)
670 (let ((sn (car entity-number)))
673 (let ((rc (nth sn (mime-entity-children message-info))))
675 (mime-raw-find-entity-from-number (cdr entity-number) rc)
679 (defun mime-raw-find-entity-from-point (point &optional message-info)
680 "Return entity from POINT in mime-raw-buffer.
681 If optional argument MESSAGE-INFO is not specified,
682 `mime-raw-message-info' is used."
684 (setq message-info mime-raw-message-info))
685 (if (and (<= (mime-entity-point-min message-info) point)
686 (<= point (mime-entity-point-max message-info)))
687 (let ((children (mime-entity-children message-info)))
691 (mime-raw-find-entity-from-point point (car children))))
695 (setq children (cdr children)))
698 (defsubst mime-raw-point-to-entity-node-id (point &optional message-info)
699 "Return entity-node-id from POINT in mime-raw-buffer.
700 If optional argument MESSAGE-INFO is not specified,
701 `mime-raw-message-info' is used."
702 (mime-entity-node-id (mime-raw-find-entity-from-point point message-info)))
704 (defsubst mime-raw-point-to-entity-number (point &optional message-info)
705 "Return entity-number from POINT in mime-raw-buffer.
706 If optional argument MESSAGE-INFO is not specified,
707 `mime-raw-message-info' is used."
708 (reverse (mime-raw-point-to-entity-node-id point message-id)))
710 (defsubst mime-raw-entity-parent (entity &optional message-info)
711 "Return mother entity of ENTITY.
712 If optional argument MESSAGE-INFO is not specified,
713 `mime-raw-message-info' is used."
714 (mime-raw-find-entity-from-node-id
715 (cdr (mime-entity-node-id entity) message-info)))
717 (defun mime-raw-flatten-message-info (&optional message-info)
718 "Return list of entity in mime-raw-buffer.
719 If optional argument MESSAGE-INFO is not specified,
720 `mime-raw-message-info' is used."
722 (setq message-info mime-raw-message-info))
723 (let ((dest (list message-info))
724 (rcl (mime-entity-children message-info)))
726 (setq dest (nconc dest (mime-raw-flatten-message-info (car rcl))))
727 (setq rcl (cdr rcl)))
731 ;;; @ MIME viewer mode
734 (defconst mime-view-menu-title "MIME-View")
735 (defconst mime-view-menu-list
736 '((up "Move to upper entity" mime-preview-move-to-upper)
737 (previous "Move to previous entity" mime-preview-move-to-previous)
738 (next "Move to next entity" mime-preview-move-to-next)
739 (scroll-down "Scroll-down" mime-preview-scroll-down-entity)
740 (scroll-up "Scroll-up" mime-preview-scroll-up-entity)
741 (play "Play current entity" mime-preview-play-current-entity)
742 (extract "Extract current entity" mime-preview-extract-current-entity)
743 (print "Print current entity" mime-preview-print-current-entity)
744 (x-face "Show X Face" mime-preview-display-x-face)
746 "Menu for MIME Viewer")
748 (cond (running-xemacs
749 (defvar mime-view-xemacs-popup-menu
750 (cons mime-view-menu-title
753 (vector (nth 1 item)(nth 2 item) t)
755 mime-view-menu-list)))
756 (defun mime-view-xemacs-popup-menu (event)
757 "Popup the menu in the MIME Viewer buffer"
759 (select-window (event-window event))
760 (set-buffer (event-buffer event))
761 (popup-menu 'mime-view-xemacs-popup-menu))
762 (defvar mouse-button-2 'button2)
765 (defvar mouse-button-2 [mouse-2])
768 (defun mime-view-define-keymap (&optional default)
769 (let ((mime-view-mode-map (if (keymapp default)
770 (copy-keymap default)
773 (define-key mime-view-mode-map
774 "u" (function mime-preview-move-to-upper))
775 (define-key mime-view-mode-map
776 "p" (function mime-preview-move-to-previous))
777 (define-key mime-view-mode-map
778 "n" (function mime-preview-move-to-next))
779 (define-key mime-view-mode-map
780 "\e\t" (function mime-preview-move-to-previous))
781 (define-key mime-view-mode-map
782 "\t" (function mime-preview-move-to-next))
783 (define-key mime-view-mode-map
784 " " (function mime-preview-scroll-up-entity))
785 (define-key mime-view-mode-map
786 "\M- " (function mime-preview-scroll-down-entity))
787 (define-key mime-view-mode-map
788 "\177" (function mime-preview-scroll-down-entity))
789 (define-key mime-view-mode-map
790 "\C-m" (function mime-preview-next-line-entity))
791 (define-key mime-view-mode-map
792 "\C-\M-m" (function mime-preview-previous-line-entity))
793 (define-key mime-view-mode-map
794 "v" (function mime-preview-play-current-entity))
795 (define-key mime-view-mode-map
796 "e" (function mime-preview-extract-current-entity))
797 (define-key mime-view-mode-map
798 "\C-c\C-p" (function mime-preview-print-current-entity))
799 (define-key mime-view-mode-map
800 "a" (function mime-preview-follow-current-entity))
801 (define-key mime-view-mode-map
802 "q" (function mime-preview-quit))
803 (define-key mime-view-mode-map
804 "h" (function mime-preview-show-summary))
805 (define-key mime-view-mode-map
806 "\C-c\C-x" (function mime-preview-kill-buffer))
807 ;; (define-key mime-view-mode-map
808 ;; "<" (function beginning-of-buffer))
809 ;; (define-key mime-view-mode-map
810 ;; ">" (function end-of-buffer))
811 (define-key mime-view-mode-map
812 "?" (function describe-mode))
813 (define-key mime-view-mode-map
814 [tab] (function mime-preview-move-to-next))
815 (define-key mime-view-mode-map
816 [delete] (function mime-preview-scroll-down-entity))
817 (define-key mime-view-mode-map
818 [backspace] (function mime-preview-scroll-down-entity))
819 (if (functionp default)
820 (cond (running-xemacs
821 (set-keymap-default-binding mime-view-mode-map default)
824 (setq mime-view-mode-map
825 (append mime-view-mode-map (list (cons t default))))
828 (define-key mime-view-mode-map
829 mouse-button-2 (function mime-button-dispatcher))
831 (cond (running-xemacs
832 (define-key mime-view-mode-map
833 mouse-button-3 (function mime-view-xemacs-popup-menu))
835 ((>= emacs-major-version 19)
836 (define-key mime-view-mode-map [menu-bar mime-view]
837 (cons mime-view-menu-title
838 (make-sparse-keymap mime-view-menu-title)))
841 (define-key mime-view-mode-map
842 (vector 'menu-bar 'mime-view (car item))
843 (cons (nth 1 item)(nth 2 item))
846 (reverse mime-view-menu-list)
849 (use-local-map mime-view-mode-map)
850 (run-hooks 'mime-view-define-keymap-hook)
853 (defsubst mime-maybe-hide-echo-buffer ()
854 "Clear mime-echo buffer and delete window for it."
855 (let ((buf (get-buffer mime-echo-buffer-name)))
860 (let ((win (get-buffer-window buf)))
867 (defun mime-view-mode (&optional mother ctl encoding ibuf obuf
868 default-keymap-or-function)
869 "Major mode for viewing MIME message.
871 Here is a list of the standard keys for mime-view-mode.
876 u Move to upper content
877 p or M-TAB Move to previous content
878 n or TAB Move to next content
879 SPC Scroll up or move to next content
880 M-SPC or DEL Scroll down or move to previous content
881 RET Move to next line
882 M-RET Move to previous line
883 v Decode current content as `play mode'
884 e Decode current content as `extract mode'
885 C-c C-p Decode current content as `print mode'
886 a Followup to current content.
889 button-2 Move to point under the mouse cursor
890 and decode current content as `play mode'
893 (mime-maybe-hide-echo-buffer)
894 (let ((ret (mime-view-setup-buffers ctl encoding ibuf obuf))
895 (win-conf (current-window-configuration))
898 (switch-to-buffer ret)
899 (setq mime-preview-original-window-configuration win-conf)
902 (setq mime-mother-buffer mother)
904 (mime-view-define-keymap default-keymap-or-function)
906 (next-single-property-change (point-min) 'mime-view-entity)))
909 (goto-char (point-min))
910 (search-forward "\n\n" nil t)
912 (run-hooks 'mime-view-mode-hook)
919 (autoload 'mime-preview-play-current-entity "mime-play"
920 "Play current entity." t)
922 (defun mime-preview-extract-current-entity ()
923 "Extract current entity into file (maybe).
924 It decodes current entity to call internal or external method as
925 \"extract\" mode. The method is selected from variable
926 `mime-acting-condition'."
928 (mime-preview-play-current-entity "extract")
931 (defun mime-preview-print-current-entity ()
932 "Print current entity (maybe).
933 It decodes current entity to call internal or external method as
934 \"print\" mode. The method is selected from variable
935 `mime-acting-condition'."
937 (mime-preview-play-current-entity "print")
944 (defun mime-preview-original-major-mode ()
945 "Return major-mode of original buffer.
946 If a current buffer has mime-mother-buffer, return original major-mode
947 of the mother-buffer."
948 (if mime-mother-buffer
950 (set-buffer mime-mother-buffer)
951 (mime-preview-original-major-mode)
953 mime-preview-original-major-mode))
955 (defun mime-preview-follow-current-entity ()
956 "Write follow message to current entity.
957 It calls following-method selected from variable
958 `mime-view-following-method-alist'."
960 (let ((message-info (get-text-property (point-min) 'mime-view-entity))
962 (while (null (setq entity
963 (get-text-property (point) 'mime-view-entity)))
967 (previous-single-property-change (point) 'mime-view-entity))
969 (entity-node-id (mime-entity-node-id entity))
970 (len (length entity-node-id))
974 (if (eq (next-single-property-change (point-min)
980 ((eq (next-single-property-change p-beg 'mime-view-entity)
984 (setq p-end (next-single-property-change p-beg 'mime-view-entity))
986 (setq p-end (point-max))
988 ((null entity-node-id)
989 (setq p-end (point-max))
997 (next-single-property-change
998 (point) 'mime-view-entity))
1000 (let ((rc (mime-entity-node-id
1001 (get-text-property (point)
1002 'mime-view-entity))))
1003 (or (equal entity-node-id
1004 (nthcdr (- (length rc) len) rc))
1009 (setq p-end (point-max))
1012 (let* ((mode (mime-preview-original-major-mode))
1014 (format "%s-%s" (buffer-name) (reverse entity-node-id)))
1016 (the-buf (current-buffer))
1017 (a-buf mime-raw-buffer)
1020 (set-buffer (setq new-buf (get-buffer-create new-name)))
1022 (insert-buffer-substring the-buf p-beg p-end)
1023 (goto-char (point-min))
1024 (if (mime-view-header-visible-p entity message-info)
1025 (delete-region (goto-char (point-min))
1026 (if (re-search-forward "^$" nil t)
1030 (goto-char (point-min))
1032 (goto-char (point-min))
1033 (let ((entity-node-id (mime-entity-node-id entity)) ci str)
1041 (mime-raw-find-entity-from-node-id entity-node-id))
1044 (mime-entity-point-min ci)
1045 (mime-entity-point-max ci)
1047 (std11-header-string-except
1049 (apply (function regexp-or) fields)
1052 (eq (mime-entity-media-type ci) 'message)
1053 (eq (mime-entity-media-subtype ci) 'rfc822))
1059 (setq fields (std11-collect-field-names)
1060 entity-node-id (cdr entity-node-id))
1063 (let ((rest mime-view-following-required-fields-list))
1065 (let ((field-name (car rest)))
1066 (or (std11-field-body field-name)
1072 (set-buffer the-buf)
1073 (set-buffer mime-mother-buffer)
1074 (set-buffer mime-raw-buffer)
1075 (std11-field-body field-name)
1079 (setq rest (cdr rest))
1081 (eword-decode-header)
1083 (let ((f (cdr (assq mode mime-view-following-method-alist))))
1088 "Sorry, following method for %s is not implemented yet."
1097 (defun mime-preview-display-x-face ()
1099 (save-window-excursion
1100 (set-buffer mime-raw-buffer)
1101 (mime-view-x-face-function)
1108 (defun mime-preview-move-to-upper ()
1109 "Move to upper entity.
1110 If there is no upper entity, call function `mime-preview-quit'."
1113 (while (null (setq cinfo
1114 (get-text-property (point) 'mime-view-entity)))
1117 (let ((r (mime-raw-find-entity-from-node-id
1118 (cdr (mime-entity-node-id cinfo))
1119 (get-text-property 1 'mime-view-entity)))
1122 (while (setq point (previous-single-property-change
1123 (point) 'mime-view-entity))
1125 (if (eq r (get-text-property (point) 'mime-view-entity))
1132 (defun mime-preview-move-to-previous ()
1133 "Move to previous entity.
1134 If there is no previous entity, it calls function registered in
1135 variable `mime-view-over-to-previous-method-alist'."
1137 (while (null (get-text-property (point) 'mime-view-entity))
1141 (previous-single-property-change (point) 'mime-view-entity)))
1144 (let ((f (assq mime-preview-original-major-mode
1145 mime-view-over-to-previous-method-alist)))
1151 (defun mime-preview-move-to-next ()
1152 "Move to next entity.
1153 If there is no previous entity, it calls function registered in
1154 variable `mime-view-over-to-next-method-alist'."
1156 (let ((point (next-single-property-change (point) 'mime-view-entity)))
1159 (let ((f (assq mime-preview-original-major-mode
1160 mime-view-over-to-next-method-alist)))
1166 (defun mime-preview-scroll-up-entity (&optional h)
1167 "Scroll up current entity.
1168 If reached to (point-max), it calls function registered in variable
1169 `mime-view-over-to-next-method-alist'."
1172 (setq h (1- (window-height)))
1174 (if (= (point) (point-max))
1175 (let ((f (assq mime-preview-original-major-mode
1176 mime-view-over-to-next-method-alist)))
1181 (or (next-single-property-change (point) 'mime-view-entity)
1184 (if (> (point) point)
1189 (defun mime-preview-scroll-down-entity (&optional h)
1190 "Scroll down current entity.
1191 If reached to (point-min), it calls function registered in variable
1192 `mime-view-over-to-previous-method-alist'."
1195 (setq h (1- (window-height)))
1197 (if (= (point) (point-min))
1198 (let ((f (assq mime-preview-original-major-mode
1199 mime-view-over-to-previous-method-alist)))
1206 (while (> (point) 1)
1208 (previous-single-property-change (point)
1214 (setq point (point-min))
1216 (forward-line (- h))
1217 (if (< (point) point)
1221 (defun mime-preview-next-line-entity ()
1223 (mime-preview-scroll-up-entity 1)
1226 (defun mime-preview-previous-line-entity ()
1228 (mime-preview-scroll-down-entity 1)
1235 (defun mime-preview-quit ()
1236 "Quit from MIME-preview buffer.
1237 It calls function registered in variable
1238 `mime-preview-quitting-method-alist'."
1240 (let ((r (assq mime-preview-original-major-mode
1241 mime-preview-quitting-method-alist)))
1246 (defun mime-preview-show-summary ()
1248 It calls function registered in variable
1249 `mime-view-show-summary-method'."
1251 (let ((r (assq mime-preview-original-major-mode
1252 mime-view-show-summary-method)))
1257 (defun mime-preview-kill-buffer ()
1259 (kill-buffer (current-buffer))
1266 (provide 'mime-view)
1268 (run-hooks 'mime-view-load-hook)
1270 ;;; mime-view.el ends here