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)
40 (defconst mime-view-version-string
41 `,(concat "SEMI MIME-View "
42 (mapconcat #'number-to-string (cdr semi-version) ".")
43 " (" (car semi-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-view-body-visible-condition
353 (octet-stream encoding
363 "Condition-tree to be able to display body of entity.")
365 (defun mime-view-body-visible-p (entity message-info)
366 "Return non-nil if body of ENTITY is visible."
368 mime-view-body-visible-condition
369 (list* (cons 'type (mime-entity-media-type entity))
370 (cons 'subtype (mime-entity-media-subtype entity))
371 (cons 'encoding (mime-entity-encoding entity))
372 (cons 'major-mode major-mode)
373 (mime-entity-parameters entity))))
376 ;;; @@@ entity filter
379 (defvar mime-view-content-filter-alist
380 '(("text/enriched" . mime-view-filter-for-text/enriched)
381 ("text/richtext" . mime-view-filter-for-text/richtext)
382 (t . mime-view-filter-for-text/plain)
384 "Alist of media-types vs. corresponding MIME-preview filter functions.
385 Each element looks like (TYPE/SUBTYPE . FUNCTION) or (t . FUNCTION).
386 TYPE/SUBTYPE is a string of media-type and FUNCTION is a filter
387 function. t means default media-type.")
390 (autoload 'mime-view-filter-for-text/plain "mime-text")
391 (autoload 'mime-view-filter-for-text/enriched "mime-text")
392 (autoload 'mime-view-filter-for-text/richtext "mime-text")
394 (defvar mime-text-decoder-alist
395 '((mime-show-message-mode . mime-text-decode-buffer)
396 (mime-temp-message-mode . mime-text-decode-buffer)
397 (t . mime-text-decode-buffer-maybe)
399 "Alist of major-mode vs. mime-text-decoder.
400 Each element looks like (SYMBOL . FUNCTION). SYMBOL is major-mode or
403 Specification of FUNCTION is described in DOC-string of variable
406 This value is overridden by buffer local variable `mime-text-decoder'
410 (defvar mime-view-announcement-for-message/partial
411 (if (and (>= emacs-major-version 19) window-system)
413 \[[ This is message/partial style split message. ]]
414 \[[ Please press `v' key in this buffer ]]
415 \[[ or click here by mouse button-2. ]]"
417 \[[ This is message/partial style split message. ]]
418 \[[ Please press `v' key in this buffer. ]]"
421 (defun mime-view-insert-message/partial-button ()
423 (goto-char (point-max))
424 (if (not (search-backward "\n\n" nil t))
427 (goto-char (point-max))
428 (narrow-to-region (point-max)(point-max))
429 (insert mime-view-announcement-for-message/partial)
430 (mime-add-button (point-min)(point-max)
431 #'mime-preview-play-current-entity)
435 ;;; @@ entity separator
438 (defun mime-view-entity-separator-visible-p (entity message-info)
439 "Return non-nil if separator is needed for ENTITY."
440 (and (not (mime-view-header-visible-p entity message-info))
441 (not (mime-view-body-visible-p entity message-info))))
444 ;;; @ acting-condition
447 (defvar mime-acting-condition
448 '(((type . text)(subtype . plain)
449 (method "tm-plain" nil 'file "" 'encoding 'mode 'name)
450 (mode "play" "print")
452 ((type . text)(subtype . html)
453 (method "tm-html" nil 'file "" 'encoding 'mode 'name)
456 ((type . text)(subtype . x-rot13-47)
457 (method . mime-method-to-display-caesar)
460 ((type . text)(subtype . x-rot13-47-48)
461 (method . mime-method-to-display-caesar)
465 ((type . audio)(subtype . basic)
466 (method "tm-au" nil 'file "" 'encoding 'mode 'name)
471 (method "tm-image" nil 'file "" 'encoding 'mode 'name)
472 (mode "play" "print")
475 ((type . video)(subtype . mpeg)
476 (method "tm-mpeg" nil 'file "" 'encoding 'mode 'name)
480 ((type . application)(subtype . postscript)
481 (method "tm-ps" nil 'file "" 'encoding 'mode 'name)
482 (mode "play" "print")
484 ((type . application)(subtype . octet-stream)
485 (method . mime-method-to-save)(mode "play" "print")
488 ((type . message)(subtype . external-body)
489 ("access-type" . "anon-ftp")
490 (method . mime-method-to-display-message/external-ftp)
492 ((type . message)(subtype . rfc822)
493 (method . mime-method-to-display-message/rfc822)
496 ((type . message)(subtype . partial)
497 (method . mime-method-to-store-message/partial)
501 ((method "metamail" t "-m" "tm" "-x" "-d" "-z" "-e" 'file)
504 ((method . mime-method-to-save)(mode . "extract"))
508 ;;; @ quitting method
511 (defvar mime-preview-quitting-method-alist
512 '((mime-show-message-mode
513 . mime-preview-quitting-method-for-mime-show-message-mode))
514 "Alist of major-mode vs. quitting-method of mime-view.")
516 (defvar mime-view-over-to-previous-method-alist nil)
517 (defvar mime-view-over-to-next-method-alist nil)
519 (defvar mime-view-show-summary-method nil
520 "Alist of major-mode vs. show-summary-method.")
523 ;;; @ following method
526 (defvar mime-view-following-method-alist nil
527 "Alist of major-mode vs. following-method of mime-view.")
529 (defvar mime-view-following-required-fields-list
536 ;; hack from Gnus 5.0.4.
538 (defvar mime-view-x-face-to-pbm-command
539 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm")
541 (defvar mime-view-x-face-command
542 (concat mime-view-x-face-to-pbm-command
544 "String to be executed to display an X-Face field.
545 The command will be executed in a sub-shell asynchronously.
546 The compressed face will be piped to this command.")
548 (defun mime-view-x-face-function ()
549 "Function to display X-Face field. You can redefine to customize."
550 ;; 1995/10/12 (c.f. tm-eng:130)
551 ;; fixed by Eric Ding <ericding@San-Jose.ate.slb.com>
553 (narrow-to-region (point-min) (re-search-forward "^$" nil t))
555 (goto-char (point-min))
556 (if (re-search-forward "^X-Face:[ \t]*" nil t)
557 (let ((beg (match-end 0))
558 (end (std11-field-end))
560 (call-process-region beg end "sh" nil 0 nil
561 "-c" mime-view-x-face-command)
568 (defvar mime-view-uuencode-encoding-name-list '("x-uue" "x-uuencode"))
570 (defvar mime-raw-buffer-coding-system-alist
571 `((t . ,(mime-charset-to-coding-system default-mime-charset)))
572 "Alist of major-mode vs. corresponding coding-system of `mime-raw-buffer'.")
578 (defvar mime-view-redisplay nil)
580 (defun mime-view-setup-buffers (&optional ctl encoding ibuf obuf)
586 (or mime-view-redisplay
587 (setq mime-raw-message-info (mime-parse-message ctl encoding))
589 (let* ((message-info mime-raw-message-info)
590 (pcl (mime-raw-flatten-message-info message-info))
591 (the-buf (current-buffer))
595 (setq obuf (concat "*Preview-" (buffer-name the-buf) "*")))
596 (set-buffer (get-buffer-create obuf))
597 (let ((inhibit-read-only t))
598 ;;(setq buffer-read-only nil)
601 (setq mime-raw-buffer the-buf)
602 (setq mime-preview-original-major-mode mode)
603 (setq major-mode 'mime-view-mode)
604 (setq mode-name "MIME-View")
606 (mime-view-display-entity (car pcl) message-info the-buf obuf)
609 (set-buffer-modified-p nil)
611 (setq buffer-read-only t)
614 (setq mime-preview-buffer obuf)
617 (defun mime-view-display-entity (entity message-info ibuf obuf)
619 (let* ((start (mime-entity-point-min entity))
620 (end (mime-entity-point-max entity))
621 (media-type (mime-entity-media-type entity))
622 (media-subtype (mime-entity-media-subtype entity))
623 (ctype (if media-type
625 (format "%s/%s" media-type media-subtype)
626 (symbol-name media-type)
628 (params (mime-entity-parameters entity))
629 (encoding (mime-entity-encoding entity))
630 (entity-node-id (mime-entity-node-id entity))
631 end-of-header e nb ne subj)
634 (setq end-of-header (if (re-search-forward "^$" nil t)
637 (if (> end-of-header end)
638 (setq end-of-header end)
641 (narrow-to-region start end)
644 (mime-raw-get-subject params encoding)))
648 (narrow-to-region nb nb)
649 (if (mime-view-entity-button-visible-p entity message-info)
650 (mime-view-insert-entity-button entity message-info subj)
652 (if (mime-view-header-visible-p entity message-info)
654 (narrow-to-region (point)(point))
655 (insert-buffer-substring mime-raw-buffer start end-of-header)
656 (let ((f (cdr (assq mime-preview-original-major-mode
657 mime-view-content-header-filter-alist))))
660 (mime-view-default-content-header-filter)
662 (run-hooks 'mime-view-content-header-filter-hook)
664 (if (and (mime-root-entity-p entity)
666 ctype mime-view-content-button-visible-ctype-list))
668 (goto-char (point-max))
669 (mime-view-insert-entity-button entity message-info subj)
671 (cond ((mime-view-body-visible-p entity message-info)
673 (narrow-to-region (point-max)(point-max))
674 (insert-buffer-substring mime-raw-buffer end-of-header end)
675 (let ((f (cdr (or (assoc ctype mime-view-content-filter-alist)
676 (assq t mime-view-content-filter-alist)))))
678 (funcall f ctype params encoding))
680 ((and (eq media-type 'message)(eq media-subtype 'partial))
681 (mime-view-insert-message/partial-button)
683 ((and (null entity-node-id)
684 (null (mime-entity-children message-info))
686 (goto-char (point-max))
687 (mime-view-insert-entity-button entity message-info subj)
689 (when (mime-view-entity-separator-visible-p entity message-info)
690 (goto-char (point-max))
692 (setq ne (point-max))
694 (put-text-property nb ne 'mime-view-raw-buffer ibuf)
695 (put-text-property nb ne 'mime-view-entity entity)
699 (defun mime-raw-get-uu-filename (param &optional encoding)
700 (if (member (or encoding
701 (cdr (assq 'encoding param))
703 mime-view-uuencode-encoding-name-list)
705 (or (if (re-search-forward "^begin [0-9]+ " nil t)
706 (if (looking-at ".+$")
707 (buffer-substring (match-beginning 0)(match-end 0))
712 (defun mime-raw-get-subject (param &optional encoding)
713 (or (std11-find-field-body '("Content-Description" "Subject"))
715 (if (or (and (setq ret (mime/Content-Disposition))
716 (setq ret (assoc "filename" (cdr ret)))
718 (setq ret (assoc "name" param))
719 (setq ret (assoc "x-name" param))
721 (std11-strip-quoted-string (cdr ret))
723 (mime-raw-get-uu-filename param encoding)
727 ;;; @ MIME viewer mode
730 (defconst mime-view-menu-title "MIME-View")
731 (defconst mime-view-menu-list
732 '((up "Move to upper entity" mime-preview-move-to-upper)
733 (previous "Move to previous entity" mime-preview-move-to-previous)
734 (next "Move to next entity" mime-preview-move-to-next)
735 (scroll-down "Scroll-down" mime-preview-scroll-down-entity)
736 (scroll-up "Scroll-up" mime-preview-scroll-up-entity)
737 (play "Play current entity" mime-preview-play-current-entity)
738 (extract "Extract current entity" mime-preview-extract-current-entity)
739 (print "Print current entity" mime-preview-print-current-entity)
740 (x-face "Show X Face" mime-preview-display-x-face)
742 "Menu for MIME Viewer")
744 (cond (running-xemacs
745 (defvar mime-view-xemacs-popup-menu
746 (cons mime-view-menu-title
749 (vector (nth 1 item)(nth 2 item) t)
751 mime-view-menu-list)))
752 (defun mime-view-xemacs-popup-menu (event)
753 "Popup the menu in the MIME Viewer buffer"
755 (select-window (event-window event))
756 (set-buffer (event-buffer event))
757 (popup-menu 'mime-view-xemacs-popup-menu))
758 (defvar mouse-button-2 'button2)
761 (defvar mouse-button-2 [mouse-2])
764 (defun mime-view-define-keymap (&optional default)
765 (let ((mime-view-mode-map (if (keymapp default)
766 (copy-keymap default)
769 (define-key mime-view-mode-map
770 "u" (function mime-preview-move-to-upper))
771 (define-key mime-view-mode-map
772 "p" (function mime-preview-move-to-previous))
773 (define-key mime-view-mode-map
774 "n" (function mime-preview-move-to-next))
775 (define-key mime-view-mode-map
776 "\e\t" (function mime-preview-move-to-previous))
777 (define-key mime-view-mode-map
778 "\t" (function mime-preview-move-to-next))
779 (define-key mime-view-mode-map
780 " " (function mime-preview-scroll-up-entity))
781 (define-key mime-view-mode-map
782 "\M- " (function mime-preview-scroll-down-entity))
783 (define-key mime-view-mode-map
784 "\177" (function mime-preview-scroll-down-entity))
785 (define-key mime-view-mode-map
786 "\C-m" (function mime-preview-next-line-entity))
787 (define-key mime-view-mode-map
788 "\C-\M-m" (function mime-preview-previous-line-entity))
789 (define-key mime-view-mode-map
790 "v" (function mime-preview-play-current-entity))
791 (define-key mime-view-mode-map
792 "e" (function mime-preview-extract-current-entity))
793 (define-key mime-view-mode-map
794 "\C-c\C-p" (function mime-preview-print-current-entity))
795 (define-key mime-view-mode-map
796 "a" (function mime-preview-follow-current-entity))
797 (define-key mime-view-mode-map
798 "q" (function mime-preview-quit))
799 (define-key mime-view-mode-map
800 "h" (function mime-preview-show-summary))
801 (define-key mime-view-mode-map
802 "\C-c\C-x" (function mime-preview-kill-buffer))
803 ;; (define-key mime-view-mode-map
804 ;; "<" (function beginning-of-buffer))
805 ;; (define-key mime-view-mode-map
806 ;; ">" (function end-of-buffer))
807 (define-key mime-view-mode-map
808 "?" (function describe-mode))
809 (define-key mime-view-mode-map
810 [tab] (function mime-preview-move-to-next))
811 (define-key mime-view-mode-map
812 [delete] (function mime-preview-scroll-down-entity))
813 (define-key mime-view-mode-map
814 [backspace] (function mime-preview-scroll-down-entity))
815 (if (functionp default)
816 (cond (running-xemacs
817 (set-keymap-default-binding mime-view-mode-map default)
820 (setq mime-view-mode-map
821 (append mime-view-mode-map (list (cons t default))))
824 (define-key mime-view-mode-map
825 mouse-button-2 (function mime-button-dispatcher))
827 (cond (running-xemacs
828 (define-key mime-view-mode-map
829 mouse-button-3 (function mime-view-xemacs-popup-menu))
831 ((>= emacs-major-version 19)
832 (define-key mime-view-mode-map [menu-bar mime-view]
833 (cons mime-view-menu-title
834 (make-sparse-keymap mime-view-menu-title)))
837 (define-key mime-view-mode-map
838 (vector 'menu-bar 'mime-view (car item))
839 (cons (nth 1 item)(nth 2 item))
842 (reverse mime-view-menu-list)
845 (use-local-map mime-view-mode-map)
846 (run-hooks 'mime-view-define-keymap-hook)
849 (defsubst mime-maybe-hide-echo-buffer ()
850 "Clear mime-echo buffer and delete window for it."
851 (let ((buf (get-buffer mime-echo-buffer-name)))
856 (let ((win (get-buffer-window buf)))
863 (defun mime-view-mode (&optional mother ctl encoding ibuf obuf
864 default-keymap-or-function)
865 "Major mode for viewing MIME message.
867 Here is a list of the standard keys for mime-view-mode.
872 u Move to upper content
873 p or M-TAB Move to previous content
874 n or TAB Move to next content
875 SPC Scroll up or move to next content
876 M-SPC or DEL Scroll down or move to previous content
877 RET Move to next line
878 M-RET Move to previous line
879 v Decode current content as `play mode'
880 e Decode current content as `extract mode'
881 C-c C-p Decode current content as `print mode'
882 a Followup to current content.
885 button-2 Move to point under the mouse cursor
886 and decode current content as `play mode'
889 (mime-maybe-hide-echo-buffer)
890 (let ((ret (mime-view-setup-buffers ctl encoding ibuf obuf))
891 (win-conf (current-window-configuration))
894 (switch-to-buffer ret)
895 (setq mime-preview-original-window-configuration win-conf)
898 (setq mime-mother-buffer mother)
900 (mime-view-define-keymap default-keymap-or-function)
902 (next-single-property-change (point-min) 'mime-view-entity)))
905 (goto-char (point-min))
906 (search-forward "\n\n" nil t)
908 (run-hooks 'mime-view-mode-hook)
915 (autoload 'mime-preview-play-current-entity "mime-play"
916 "Play current entity." t)
918 (defun mime-preview-extract-current-entity ()
919 "Extract current entity into file (maybe).
920 It decodes current entity to call internal or external method as
921 \"extract\" mode. The method is selected from variable
922 `mime-acting-condition'."
924 (mime-preview-play-current-entity "extract")
927 (defun mime-preview-print-current-entity ()
928 "Print current entity (maybe).
929 It decodes current entity to call internal or external method as
930 \"print\" mode. The method is selected from variable
931 `mime-acting-condition'."
933 (mime-preview-play-current-entity "print")
940 (defun mime-preview-original-major-mode ()
941 "Return major-mode of original buffer.
942 If a current buffer has mime-mother-buffer, return original major-mode
943 of the mother-buffer."
944 (if mime-mother-buffer
946 (set-buffer mime-mother-buffer)
947 (mime-preview-original-major-mode)
949 mime-preview-original-major-mode))
951 (defun mime-preview-follow-current-entity ()
952 "Write follow message to current entity.
953 It calls following-method selected from variable
954 `mime-view-following-method-alist'."
956 (let ((message-info (get-text-property (point-min) 'mime-view-entity))
958 (while (null (setq entity
959 (get-text-property (point) 'mime-view-entity)))
963 (previous-single-property-change (point) 'mime-view-entity))
965 (entity-node-id (mime-entity-node-id entity))
966 (len (length entity-node-id))
970 (if (eq (next-single-property-change (point-min)
976 ((eq (next-single-property-change p-beg 'mime-view-entity)
980 (setq p-end (next-single-property-change p-beg 'mime-view-entity))
982 (setq p-end (point-max))
984 ((null entity-node-id)
985 (setq p-end (point-max))
993 (next-single-property-change
994 (point) 'mime-view-entity))
996 (let ((rc (mime-entity-node-id
997 (get-text-property (point)
998 'mime-view-entity))))
999 (or (equal entity-node-id
1000 (nthcdr (- (length rc) len) rc))
1005 (setq p-end (point-max))
1008 (let* ((mode (mime-preview-original-major-mode))
1010 (format "%s-%s" (buffer-name) (reverse entity-node-id)))
1012 (the-buf (current-buffer))
1013 (a-buf mime-raw-buffer)
1016 (set-buffer (setq new-buf (get-buffer-create new-name)))
1018 (insert-buffer-substring the-buf p-beg p-end)
1019 (goto-char (point-min))
1020 (if (mime-view-header-visible-p entity message-info)
1021 (delete-region (goto-char (point-min))
1022 (if (re-search-forward "^$" nil t)
1026 (goto-char (point-min))
1028 (goto-char (point-min))
1029 (let ((entity-node-id (mime-entity-node-id entity)) ci str)
1037 (mime-raw-find-entity-from-node-id entity-node-id))
1040 (mime-entity-point-min ci)
1041 (mime-entity-point-max ci)
1043 (std11-header-string-except
1045 (apply (function regexp-or) fields)
1048 (eq (mime-entity-media-type ci) 'message)
1049 (eq (mime-entity-media-subtype ci) 'rfc822))
1055 (setq fields (std11-collect-field-names)
1056 entity-node-id (cdr entity-node-id))
1059 (let ((rest mime-view-following-required-fields-list))
1061 (let ((field-name (car rest)))
1062 (or (std11-field-body field-name)
1068 (set-buffer the-buf)
1069 (set-buffer mime-mother-buffer)
1070 (set-buffer mime-raw-buffer)
1071 (std11-field-body field-name)
1075 (setq rest (cdr rest))
1077 (eword-decode-header)
1079 (let ((f (cdr (assq mode mime-view-following-method-alist))))
1084 "Sorry, following method for %s is not implemented yet."
1093 (defun mime-preview-display-x-face ()
1095 (save-window-excursion
1096 (set-buffer mime-raw-buffer)
1097 (mime-view-x-face-function)
1104 (defun mime-preview-move-to-upper ()
1105 "Move to upper entity.
1106 If there is no upper entity, call function `mime-preview-quit'."
1109 (while (null (setq cinfo
1110 (get-text-property (point) 'mime-view-entity)))
1113 (let ((r (mime-raw-find-entity-from-node-id
1114 (cdr (mime-entity-node-id cinfo))
1115 (get-text-property 1 'mime-view-entity)))
1118 (while (setq point (previous-single-property-change
1119 (point) 'mime-view-entity))
1121 (if (eq r (get-text-property (point) 'mime-view-entity))
1128 (defun mime-preview-move-to-previous ()
1129 "Move to previous entity.
1130 If there is no previous entity, it calls function registered in
1131 variable `mime-view-over-to-previous-method-alist'."
1133 (while (null (get-text-property (point) 'mime-view-entity))
1137 (previous-single-property-change (point) 'mime-view-entity)))
1140 (let ((f (assq mime-preview-original-major-mode
1141 mime-view-over-to-previous-method-alist)))
1147 (defun mime-preview-move-to-next ()
1148 "Move to next entity.
1149 If there is no previous entity, it calls function registered in
1150 variable `mime-view-over-to-next-method-alist'."
1152 (let ((point (next-single-property-change (point) 'mime-view-entity)))
1155 (let ((f (assq mime-preview-original-major-mode
1156 mime-view-over-to-next-method-alist)))
1162 (defun mime-preview-scroll-up-entity (&optional h)
1163 "Scroll up current entity.
1164 If reached to (point-max), it calls function registered in variable
1165 `mime-view-over-to-next-method-alist'."
1168 (setq h (1- (window-height)))
1170 (if (= (point) (point-max))
1171 (let ((f (assq mime-preview-original-major-mode
1172 mime-view-over-to-next-method-alist)))
1177 (or (next-single-property-change (point) 'mime-view-entity)
1180 (if (> (point) point)
1185 (defun mime-preview-scroll-down-entity (&optional h)
1186 "Scroll down current entity.
1187 If reached to (point-min), it calls function registered in variable
1188 `mime-view-over-to-previous-method-alist'."
1191 (setq h (1- (window-height)))
1193 (if (= (point) (point-min))
1194 (let ((f (assq mime-preview-original-major-mode
1195 mime-view-over-to-previous-method-alist)))
1202 (while (> (point) 1)
1204 (previous-single-property-change (point)
1210 (setq point (point-min))
1212 (forward-line (- h))
1213 (if (< (point) point)
1217 (defun mime-preview-next-line-entity ()
1219 (mime-preview-scroll-up-entity 1)
1222 (defun mime-preview-previous-line-entity ()
1224 (mime-preview-scroll-down-entity 1)
1231 (defun mime-preview-quit ()
1232 "Quit from MIME-preview buffer.
1233 It calls function registered in variable
1234 `mime-preview-quitting-method-alist'."
1236 (let ((r (assq mime-preview-original-major-mode
1237 mime-preview-quitting-method-alist)))
1242 (defun mime-preview-show-summary ()
1244 It calls function registered in variable
1245 `mime-view-show-summary-method'."
1247 (let ((r (assq mime-preview-original-major-mode
1248 mime-view-show-summary-method)))
1253 (defun mime-preview-kill-buffer ()
1255 (kill-buffer (current-buffer))
1262 (provide 'mime-view)
1264 (run-hooks 'mime-view-load-hook)
1266 ;;; mime-view.el ends here