1 ;;; mime-view.el --- interactive MIME viewer for GNU Emacs
3 ;; Copyright (C) 1995,1996,1997,1998 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;; Renamed: 1994/08/31 from tm-body.el
8 ;; Renamed: 1997/02/19 from tm-view.el
9 ;; Keywords: MIME, multimedia, mail, news
11 ;; This file is part of SEMI (Sophisticated Emacs MIME Interfaces).
13 ;; This program is free software; you can redistribute it and/or
14 ;; modify it under the terms of the GNU General Public License as
15 ;; published by the Free Software Foundation; either version 2, or (at
16 ;; your option) any later version.
18 ;; This program is distributed in the hope that it will be useful, but
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 ;; General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 ;; Boston, MA 02111-1307, USA.
32 (require 'eword-decode)
41 (defconst mime-view-version-string
42 `,(concat (car mime-module-version) " MIME-View "
43 (mapconcat #'number-to-string (cddr mime-module-version) ".")
44 " (" (cadr mime-module-version) ")"))
47 ;;; @ buffer local variables
53 (defvar mime-raw-message-info
54 "Information about structure of message.
55 Please use reference function `mime-entity-SLOT' to get value of SLOT.
57 Following is a list of slots of the structure:
59 node-id reversed entity-number (list of integers)
60 point-min beginning point of region in raw-buffer
61 point-max end point of region in raw-buffer
62 type media-type (symbol)
63 subtype media-subtype (symbol)
64 type/subtype media-type/subtype (string or nil)
65 parameters parameter of Content-Type field (association list)
66 encoding Content-Transfer-Encoding (string or nil)
67 children entities included in this entity (list of content-infos)
69 If an entity includes other entities in its body, such as multipart or
70 message/rfc822, `mime-entity' structures of them are included in
71 `children', so the `mime-entity' structure become a tree.")
72 (make-variable-buffer-local 'mime-raw-message-info)
74 (defvar mime-preview-buffer nil
75 "MIME-preview buffer corresponding with the (raw) buffer.")
76 (make-variable-buffer-local 'mime-preview-buffer)
79 ;;; @@ in preview-buffer
82 (defvar mime-mother-buffer nil
83 "Mother buffer corresponding with the (MIME-preview) buffer.
84 If current MIME-preview buffer is generated by other buffer, such as
85 message/partial, it is called `mother-buffer'.")
86 (make-variable-buffer-local 'mime-mother-buffer)
88 (defvar mime-raw-buffer nil
89 "Raw buffer corresponding with the (MIME-preview) buffer.")
90 (make-variable-buffer-local 'mime-raw-buffer)
92 (defvar mime-preview-original-major-mode nil
93 "Major-mode of mime-raw-buffer.")
94 (make-variable-buffer-local 'mime-preview-original-major-mode)
96 (defvar mime-preview-original-window-configuration nil
97 "Window-configuration before mime-view-mode is called.")
98 (make-variable-buffer-local 'mime-preview-original-window-configuration)
101 ;;; @ entity information
104 (defsubst mime-raw-find-entity-from-node-id (entity-node-id
105 &optional message-info)
106 "Return entity from ENTITY-NODE-ID in mime-raw-buffer.
107 If optional argument MESSAGE-INFO is not specified,
108 `mime-raw-message-info' is used."
109 (mime-raw-find-entity-from-number (reverse entity-node-id) message-info))
111 (defun mime-raw-find-entity-from-number (entity-number &optional message-info)
112 "Return entity from ENTITY-NUMBER in mime-raw-buffer.
113 If optional argument MESSAGE-INFO is not specified,
114 `mime-raw-message-info' is used."
116 (setq message-info mime-raw-message-info))
117 (if (eq entity-number t)
119 (let ((sn (car entity-number)))
122 (let ((rc (nth sn (mime-entity-children message-info))))
124 (mime-raw-find-entity-from-number (cdr entity-number) rc)
128 (defun mime-raw-find-entity-from-point (point &optional message-info)
129 "Return entity from POINT in mime-raw-buffer.
130 If optional argument MESSAGE-INFO is not specified,
131 `mime-raw-message-info' is used."
133 (setq message-info mime-raw-message-info))
134 (if (and (<= (mime-entity-point-min message-info) point)
135 (<= point (mime-entity-point-max message-info)))
136 (let ((children (mime-entity-children message-info)))
140 (mime-raw-find-entity-from-point point (car children))))
144 (setq children (cdr children)))
147 (defsubst mime-raw-point-to-entity-node-id (point &optional message-info)
148 "Return entity-node-id from POINT in mime-raw-buffer.
149 If optional argument MESSAGE-INFO is not specified,
150 `mime-raw-message-info' is used."
151 (mime-entity-node-id (mime-raw-find-entity-from-point point message-info)))
153 (defsubst mime-raw-point-to-entity-number (point &optional message-info)
154 "Return entity-number from POINT in mime-raw-buffer.
155 If optional argument MESSAGE-INFO is not specified,
156 `mime-raw-message-info' is used."
157 (reverse (mime-raw-point-to-entity-node-id point message-info)))
159 (defsubst mime-raw-entity-parent (entity &optional message-info)
160 "Return mother entity of ENTITY.
161 If optional argument MESSAGE-INFO is not specified,
162 `mime-raw-message-info' is used."
163 (mime-raw-find-entity-from-node-id (cdr (mime-entity-node-id entity))
166 (defun mime-raw-flatten-message-info (&optional message-info)
167 "Return list of entity in mime-raw-buffer.
168 If optional argument MESSAGE-INFO is not specified,
169 `mime-raw-message-info' is used."
171 (setq message-info mime-raw-message-info))
172 (let ((dest (list message-info))
173 (rcl (mime-entity-children message-info)))
175 (setq dest (nconc dest (mime-raw-flatten-message-info (car rcl))))
176 (setq rcl (cdr rcl)))
180 ;;; @ presentation of preview
186 ;;; @@@ predicate function
189 (defun mime-view-entity-button-visible-p (entity message-info)
190 "Return non-nil if header of ENTITY is visible.
191 Please redefine this function if you want to change default setting."
192 (let ((media-type (mime-entity-media-type entity))
193 (media-subtype (mime-entity-media-subtype entity)))
194 (or (not (eq media-type 'application))
195 (and (not (eq media-subtype 'x-selection))
196 (or (not (eq media-subtype 'octet-stream))
198 (mime-raw-entity-parent entity message-info)))
199 (or (not (eq (mime-entity-media-type mother-entity)
201 (not (eq (mime-entity-media-subtype mother-entity)
206 ;;; @@@ entity button generator
209 (defun mime-view-insert-entity-button (entity message-info subj)
210 "Insert entity-button of ENTITY."
211 (let ((entity-node-id (mime-entity-node-id entity))
212 (params (mime-entity-parameters entity)))
214 (let ((access-type (assoc "access-type" params))
215 (num (or (cdr (assoc "x-part-number" params))
216 (if (consp entity-node-id)
219 (format "%s" (1+ num))
221 (reverse entity-node-id) ".")
225 (let ((server (assoc "server" params)))
226 (setq access-type (cdr access-type))
228 (format "%s %s ([%s] %s)"
229 num subj access-type (cdr server))
230 (let ((site (cdr (assoc "site" params)))
231 (dir (cdr (assoc "directory" params)))
233 (format "%s %s ([%s] %s:%s)"
234 num subj access-type site dir)
238 (let ((media-type (mime-entity-media-type entity))
239 (media-subtype (mime-entity-media-subtype entity))
240 (charset (cdr (assoc "charset" params)))
241 (encoding (mime-entity-encoding entity)))
245 (format " <%s/%s%s%s>"
246 media-type media-subtype
248 (concat "; " charset)
251 (concat " (" encoding ")")
253 (if (>= (+ (current-column)(length rest))(window-width))
257 (function mime-preview-play-current-entity))
264 ;;; @@@ predicate function
267 (defvar mime-view-childrens-header-showing-Content-Type-list
268 '("message/rfc822" "message/news"))
270 (defun mime-view-header-visible-p (entity message-info)
271 "Return non-nil if header of ENTITY is visible."
272 (let ((entity-node-id (mime-entity-node-id entity)))
273 (member (mime-entity-type/subtype
274 (mime-raw-find-entity-from-node-id
275 (cdr entity-node-id) message-info))
276 mime-view-childrens-header-showing-Content-Type-list)
279 ;;; @@@ entity header filter
282 (defvar mime-view-content-header-filter-alist nil)
284 (defun mime-view-default-content-header-filter ()
285 (mime-view-cut-header)
286 (eword-decode-header)
289 ;;; @@@ entity field cutter
292 (defvar mime-view-ignored-field-list
293 '(".*Received" ".*Path" ".*Id" "References"
294 "Replied" "Errors-To"
295 "Lines" "Sender" ".*Host" "Xref"
296 "Content-Type" "Precedence"
298 "All fields that match this list will be hidden in MIME preview buffer.
299 Each elements are regexp of field-name.")
301 (defvar mime-view-ignored-field-regexp
303 (apply (function regexp-or) mime-view-ignored-field-list)
306 (defvar mime-view-visible-field-list '("Dnas.*" "Message-Id")
307 "All fields that match this list will be displayed in MIME preview buffer.
308 Each elements are regexp of field-name.")
310 (defun mime-view-cut-header ()
311 (goto-char (point-min))
312 (while (re-search-forward mime-view-ignored-field-regexp nil t)
313 (let* ((beg (match-beginning 0))
315 (name (buffer-substring beg end))
318 (let ((rest mime-view-visible-field-list))
320 (if (string-match (car rest) name)
323 (setq rest (cdr rest))))
326 (if (re-search-forward "^\\([^ \t]\\|$\\)" nil t)
335 ;;; @@@ predicate function
338 (defvar mime-preview-condition nil
339 "Condition-tree about how to display entity.")
341 (ctree-set-calist-strictly
342 'mime-preview-condition '((type . application)(subtype . octet-stream)
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)
354 (ctree-set-calist-strictly
355 'mime-preview-condition '((type . application)(subtype . pgp)
356 (message-button . visible)
359 (ctree-set-calist-strictly
360 'mime-preview-condition '((type . application)(subtype . x-latex)
363 (ctree-set-calist-strictly
364 'mime-preview-condition '((type . application)(subtype . x-selection)
367 (ctree-set-calist-strictly
368 'mime-preview-condition '((type . application)(subtype . x-comment)
371 (ctree-set-calist-strictly
372 'mime-preview-condition '((type . message)(subtype . delivery-status)
375 (ctree-set-calist-strictly
376 'mime-preview-condition '((body . visible)
377 (body-presentation-method . with-filter)
378 (body-filter . mime-preview-filter-for-text/plain)))
380 (ctree-set-calist-strictly
381 'mime-preview-condition '((type . nil)
383 (body-presentation-method . with-filter)
384 (body-filter . mime-preview-filter-for-text/plain)))
386 (ctree-set-calist-strictly
387 'mime-preview-condition '((type . text)(subtype . enriched)
389 (body-presentation-method . with-filter)
391 . mime-preview-filter-for-text/enriched)))
393 (ctree-set-calist-strictly
394 'mime-preview-condition '((type . text)(subtype . richtext)
396 (body-presentation-method . with-filter)
398 . mime-preview-filter-for-text/richtext)))
400 (ctree-set-calist-strictly
401 'mime-preview-condition '((type . text)(subtype . t)
403 (body-presentation-method . with-filter)
404 (body-filter . mime-preview-filter-for-text/plain)))
406 (ctree-set-calist-strictly
407 'mime-preview-condition '((type . message)(subtype . partial)
408 (body-presentation-method
409 . mime-view-insert-message/partial-button)))
411 (defun mime-view-body-visible-p (entity message-info)
412 "Return non-nil if body of ENTITY is visible."
413 (ctree-match-calist mime-preview-condition
414 (list* (cons 'type (mime-entity-media-type entity))
415 (cons 'subtype (mime-entity-media-subtype entity))
416 (cons 'encoding (mime-entity-encoding entity))
417 (cons 'major-mode major-mode)
418 (mime-entity-parameters entity))))
421 ;;; @@@ entity filter
424 (autoload 'mime-preview-filter-for-text/plain "mime-text")
425 (autoload 'mime-preview-filter-for-text/enriched "mime-text")
426 (autoload 'mime-preview-filter-for-text/richtext "mime-text")
428 (defvar mime-text-decoder-alist
429 '((mime-show-message-mode . mime-text-decode-buffer)
430 (mime-temp-message-mode . mime-text-decode-buffer)
431 (t . mime-text-decode-buffer-maybe)
433 "Alist of major-mode vs. mime-text-decoder.
434 Each element looks like (SYMBOL . FUNCTION). SYMBOL is major-mode or
437 Specification of FUNCTION is described in DOC-string of variable
440 This value is overridden by buffer local variable `mime-text-decoder'
444 (defvar mime-view-announcement-for-message/partial
445 (if (and (>= emacs-major-version 19) window-system)
447 \[[ This is message/partial style split message. ]]
448 \[[ Please press `v' key in this buffer ]]
449 \[[ or click here by mouse button-2. ]]"
451 \[[ This is message/partial style split message. ]]
452 \[[ Please press `v' key in this buffer. ]]"
455 (defun mime-view-insert-message/partial-button (&optional situation)
457 (goto-char (point-max))
458 (if (not (search-backward "\n\n" nil t))
461 (goto-char (point-max))
462 (narrow-to-region (point-max)(point-max))
463 (insert mime-view-announcement-for-message/partial)
464 (mime-add-button (point-min)(point-max)
465 #'mime-preview-play-current-entity)
469 ;;; @@ entity separator
472 (defun mime-view-entity-separator-visible-p (entity message-info)
473 "Return non-nil if separator is needed for ENTITY."
474 (and (not (mime-view-header-visible-p entity message-info))
475 (not (mime-view-body-visible-p entity message-info))))
478 ;;; @ acting-condition
481 (defvar mime-acting-condition
482 '(((type . text)(subtype . plain)
483 (method "tm-plain" nil 'file "" 'encoding 'mode 'name)
484 (mode "play" "print")
486 ((type . text)(subtype . html)
487 (method "tm-html" nil 'file "" 'encoding 'mode 'name)
490 ((type . text)(subtype . x-rot13-47)
491 (method . mime-method-to-display-caesar)
494 ((type . text)(subtype . x-rot13-47-48)
495 (method . mime-method-to-display-caesar)
499 ((type . audio)(subtype . basic)
500 (method "tm-au" nil 'file "" 'encoding 'mode 'name)
505 (method "tm-image" nil 'file "" 'encoding 'mode 'name)
506 (mode "play" "print")
509 ((type . video)(subtype . mpeg)
510 (method "tm-mpeg" nil 'file "" 'encoding 'mode 'name)
514 ((type . application)(subtype . postscript)
515 (method "tm-ps" nil 'file "" 'encoding 'mode 'name)
516 (mode "play" "print")
518 ((type . application)(subtype . octet-stream)
519 (method . mime-method-to-save)(mode "play" "print")
522 ((type . message)(subtype . external-body)
523 ("access-type" . "anon-ftp")
524 (method . mime-method-to-display-message/external-ftp)
526 ((type . message)(subtype . rfc822)
527 (method . mime-method-to-display-message/rfc822)
530 ((type . message)(subtype . partial)
531 (method . mime-method-to-store-message/partial)
535 ((method "metamail" t "-m" "tm" "-x" "-d" "-z" "-e" 'file)
538 ((method . mime-method-to-save)(mode . "extract"))
542 ;;; @ quitting method
545 (defvar mime-preview-quitting-method-alist
546 '((mime-show-message-mode
547 . mime-preview-quitting-method-for-mime-show-message-mode))
548 "Alist of major-mode vs. quitting-method of mime-view.")
550 (defvar mime-view-over-to-previous-method-alist nil)
551 (defvar mime-view-over-to-next-method-alist nil)
553 (defvar mime-view-show-summary-method nil
554 "Alist of major-mode vs. show-summary-method.")
557 ;;; @ following method
560 (defvar mime-view-following-method-alist nil
561 "Alist of major-mode vs. following-method of mime-view.")
563 (defvar mime-view-following-required-fields-list
570 ;; hack from Gnus 5.0.4.
572 (defvar mime-view-x-face-to-pbm-command
573 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm")
575 (defvar mime-view-x-face-command
576 (concat mime-view-x-face-to-pbm-command
578 "String to be executed to display an X-Face field.
579 The command will be executed in a sub-shell asynchronously.
580 The compressed face will be piped to this command.")
582 (defun mime-view-x-face-function ()
583 "Function to display X-Face field. You can redefine to customize."
584 ;; 1995/10/12 (c.f. tm-eng:130)
585 ;; fixed by Eric Ding <ericding@San-Jose.ate.slb.com>
587 (narrow-to-region (point-min) (re-search-forward "^$" nil t))
589 (goto-char (point-min))
590 (if (re-search-forward "^X-Face:[ \t]*" nil t)
591 (let ((beg (match-end 0))
592 (end (std11-field-end))
594 (call-process-region beg end "sh" nil 0 nil
595 "-c" mime-view-x-face-command)
602 (defvar mime-view-uuencode-encoding-name-list '("x-uue" "x-uuencode"))
604 (defvar mime-raw-buffer-coding-system-alist
605 `((t . ,(mime-charset-to-coding-system default-mime-charset)))
606 "Alist of major-mode vs. corresponding coding-system of `mime-raw-buffer'.")
612 (defvar mime-view-redisplay nil)
614 (defun mime-view-setup-buffers (&optional ctl encoding ibuf obuf)
620 (or mime-view-redisplay
621 (setq mime-raw-message-info (mime-parse-message ctl encoding))
623 (let ((message-info mime-raw-message-info)
624 (the-buf (current-buffer))
627 (setq obuf (concat "*Preview-" (buffer-name the-buf) "*")))
628 (set-buffer (get-buffer-create obuf))
629 (let ((inhibit-read-only t))
630 ;;(setq buffer-read-only nil)
633 (setq mime-raw-buffer the-buf)
634 (setq mime-preview-original-major-mode mode)
635 (setq major-mode 'mime-view-mode)
636 (setq mode-name "MIME-View")
637 (mime-view-display-message message-info the-buf obuf)
638 (set-buffer-modified-p nil)
640 (setq buffer-read-only t)
643 (setq mime-preview-buffer obuf)
646 (defun mime-view-display-message (message-info ibuf obuf)
647 (let* ((start (mime-entity-point-min message-info))
648 (end (mime-entity-point-max message-info))
649 (media-type (mime-entity-media-type message-info))
650 (media-subtype (mime-entity-media-subtype message-info))
651 (ctype (if media-type
653 (format "%s/%s" media-type media-subtype)
654 (symbol-name media-type)
656 (params (mime-entity-parameters message-info))
657 (encoding (mime-entity-encoding message-info))
658 end-of-header e nb ne subj)
661 (setq end-of-header (if (re-search-forward "^$" nil t)
664 (if (> end-of-header end)
665 (setq end-of-header end)
668 (narrow-to-region start end)
671 (mime-raw-get-subject params encoding)))
675 (narrow-to-region nb nb)
676 ;; Insert message-header
678 (narrow-to-region (point)(point))
679 (insert-buffer-substring mime-raw-buffer start end-of-header)
680 (let ((f (cdr (assq mime-preview-original-major-mode
681 mime-view-content-header-filter-alist))))
684 (mime-view-default-content-header-filter)
686 (run-hooks 'mime-view-content-header-filter-hook)
689 (ctree-match-calist mime-preview-condition
690 (list* (cons 'type media-type)
691 (cons 'subtype media-subtype)
692 (cons 'encoding encoding)
693 (cons 'major-mode major-mode)
696 (cdr (assq 'message-button situation)))
697 (body-presentation-method
698 (cdr (assq 'body-presentation-method situation))))
700 (goto-char (point-max))
701 (mime-view-insert-entity-button message-info message-info subj)
703 (cond ((eq body-presentation-method 'with-filter)
704 (let ((body-filter (cdr (assq 'body-filter situation))))
706 (narrow-to-region (point-max)(point-max))
707 (insert-buffer-substring mime-raw-buffer end-of-header end)
708 (funcall body-filter situation)
710 ((functionp body-presentation-method)
711 (funcall body-presentation-method situation)
713 ((null (mime-entity-children message-info))
714 (goto-char (point-max))
715 (mime-view-insert-entity-button message-info message-info subj)
718 (setq ne (point-max))
720 (put-text-property nb ne 'mime-view-raw-buffer ibuf)
721 (put-text-property nb ne 'mime-view-entity message-info)
723 (let ((children (mime-entity-children message-info)))
725 (mime-view-display-entity (car children) message-info ibuf obuf)
726 (setq children (cdr children))
729 (defun mime-view-display-entity (entity message-info ibuf obuf)
730 (let* ((start (mime-entity-point-min entity))
731 (end (mime-entity-point-max entity))
732 (media-type (mime-entity-media-type entity))
733 (media-subtype (mime-entity-media-subtype entity))
734 (ctype (if media-type
736 (format "%s/%s" media-type media-subtype)
737 (symbol-name media-type)
739 (params (mime-entity-parameters entity))
740 (encoding (mime-entity-encoding entity))
741 end-of-header e nb ne subj)
744 (setq end-of-header (if (re-search-forward "^$" nil t)
747 (if (> end-of-header end)
748 (setq end-of-header end)
751 (narrow-to-region start end)
754 (mime-raw-get-subject params encoding)))
758 (narrow-to-region nb nb)
759 (if (mime-view-entity-button-visible-p entity message-info)
760 (mime-view-insert-entity-button entity message-info subj)
762 (if (mime-view-header-visible-p entity message-info)
764 (narrow-to-region (point)(point))
765 (insert-buffer-substring mime-raw-buffer start end-of-header)
766 (let ((f (cdr (assq mime-preview-original-major-mode
767 mime-view-content-header-filter-alist))))
770 (mime-view-default-content-header-filter)
772 (run-hooks 'mime-view-content-header-filter-hook)
775 (ctree-match-calist mime-preview-condition
776 (list* (cons 'type media-type)
777 (cons 'subtype media-subtype)
778 (cons 'encoding encoding)
779 (cons 'major-mode major-mode)
781 (body-presentation-method
782 (cdr (assq 'body-presentation-method situation))))
783 (cond ((eq body-presentation-method 'with-filter)
784 (let ((body-filter (cdr (assq 'body-filter situation))))
786 (narrow-to-region (point-max)(point-max))
787 (insert-buffer-substring mime-raw-buffer end-of-header end)
788 (funcall body-filter situation)
790 ((functionp body-presentation-method)
791 (funcall body-presentation-method situation)
793 (when (mime-view-entity-separator-visible-p entity message-info)
794 (goto-char (point-max))
797 (setq ne (point-max))
799 (put-text-property nb ne 'mime-view-raw-buffer ibuf)
800 (put-text-property nb ne 'mime-view-entity entity)
802 (let ((children (mime-entity-children entity)))
804 (mime-view-display-entity (car children) message-info ibuf obuf)
805 (setq children (cdr children))
808 (defun mime-raw-get-uu-filename (param &optional encoding)
809 (if (member (or encoding
810 (cdr (assq 'encoding param))
812 mime-view-uuencode-encoding-name-list)
814 (or (if (re-search-forward "^begin [0-9]+ " nil t)
815 (if (looking-at ".+$")
816 (buffer-substring (match-beginning 0)(match-end 0))
821 (defun mime-raw-get-subject (param &optional encoding)
822 (or (std11-find-field-body '("Content-Description" "Subject"))
824 (if (or (and (setq ret (mime/Content-Disposition))
825 (setq ret (assoc "filename" (cdr ret)))
827 (setq ret (assoc "name" param))
828 (setq ret (assoc "x-name" param))
830 (std11-strip-quoted-string (cdr ret))
832 (mime-raw-get-uu-filename param encoding)
836 ;;; @ MIME viewer mode
839 (defconst mime-view-menu-title "MIME-View")
840 (defconst mime-view-menu-list
841 '((up "Move to upper entity" mime-preview-move-to-upper)
842 (previous "Move to previous entity" mime-preview-move-to-previous)
843 (next "Move to next entity" mime-preview-move-to-next)
844 (scroll-down "Scroll-down" mime-preview-scroll-down-entity)
845 (scroll-up "Scroll-up" mime-preview-scroll-up-entity)
846 (play "Play current entity" mime-preview-play-current-entity)
847 (extract "Extract current entity" mime-preview-extract-current-entity)
848 (print "Print current entity" mime-preview-print-current-entity)
849 (x-face "Show X Face" mime-preview-display-x-face)
851 "Menu for MIME Viewer")
853 (cond (running-xemacs
854 (defvar mime-view-xemacs-popup-menu
855 (cons mime-view-menu-title
858 (vector (nth 1 item)(nth 2 item) t)
860 mime-view-menu-list)))
861 (defun mime-view-xemacs-popup-menu (event)
862 "Popup the menu in the MIME Viewer buffer"
864 (select-window (event-window event))
865 (set-buffer (event-buffer event))
866 (popup-menu 'mime-view-xemacs-popup-menu))
867 (defvar mouse-button-2 'button2)
870 (defvar mouse-button-2 [mouse-2])
873 (defun mime-view-define-keymap (&optional default)
874 (let ((mime-view-mode-map (if (keymapp default)
875 (copy-keymap default)
878 (define-key mime-view-mode-map
879 "u" (function mime-preview-move-to-upper))
880 (define-key mime-view-mode-map
881 "p" (function mime-preview-move-to-previous))
882 (define-key mime-view-mode-map
883 "n" (function mime-preview-move-to-next))
884 (define-key mime-view-mode-map
885 "\e\t" (function mime-preview-move-to-previous))
886 (define-key mime-view-mode-map
887 "\t" (function mime-preview-move-to-next))
888 (define-key mime-view-mode-map
889 " " (function mime-preview-scroll-up-entity))
890 (define-key mime-view-mode-map
891 "\M- " (function mime-preview-scroll-down-entity))
892 (define-key mime-view-mode-map
893 "\177" (function mime-preview-scroll-down-entity))
894 (define-key mime-view-mode-map
895 "\C-m" (function mime-preview-next-line-entity))
896 (define-key mime-view-mode-map
897 "\C-\M-m" (function mime-preview-previous-line-entity))
898 (define-key mime-view-mode-map
899 "v" (function mime-preview-play-current-entity))
900 (define-key mime-view-mode-map
901 "e" (function mime-preview-extract-current-entity))
902 (define-key mime-view-mode-map
903 "\C-c\C-p" (function mime-preview-print-current-entity))
904 (define-key mime-view-mode-map
905 "a" (function mime-preview-follow-current-entity))
906 (define-key mime-view-mode-map
907 "q" (function mime-preview-quit))
908 (define-key mime-view-mode-map
909 "h" (function mime-preview-show-summary))
910 (define-key mime-view-mode-map
911 "\C-c\C-x" (function mime-preview-kill-buffer))
912 ;; (define-key mime-view-mode-map
913 ;; "<" (function beginning-of-buffer))
914 ;; (define-key mime-view-mode-map
915 ;; ">" (function end-of-buffer))
916 (define-key mime-view-mode-map
917 "?" (function describe-mode))
918 (define-key mime-view-mode-map
919 [tab] (function mime-preview-move-to-next))
920 (define-key mime-view-mode-map
921 [delete] (function mime-preview-scroll-down-entity))
922 (define-key mime-view-mode-map
923 [backspace] (function mime-preview-scroll-down-entity))
924 (if (functionp default)
925 (cond (running-xemacs
926 (set-keymap-default-binding mime-view-mode-map default)
929 (setq mime-view-mode-map
930 (append mime-view-mode-map (list (cons t default))))
933 (define-key mime-view-mode-map
934 mouse-button-2 (function mime-button-dispatcher))
936 (cond (running-xemacs
937 (define-key mime-view-mode-map
938 mouse-button-3 (function mime-view-xemacs-popup-menu))
940 ((>= emacs-major-version 19)
941 (define-key mime-view-mode-map [menu-bar mime-view]
942 (cons mime-view-menu-title
943 (make-sparse-keymap mime-view-menu-title)))
946 (define-key mime-view-mode-map
947 (vector 'menu-bar 'mime-view (car item))
948 (cons (nth 1 item)(nth 2 item))
951 (reverse mime-view-menu-list)
954 (use-local-map mime-view-mode-map)
955 (run-hooks 'mime-view-define-keymap-hook)
958 (defsubst mime-maybe-hide-echo-buffer ()
959 "Clear mime-echo buffer and delete window for it."
960 (let ((buf (get-buffer mime-echo-buffer-name)))
965 (let ((win (get-buffer-window buf)))
972 (defun mime-view-mode (&optional mother ctl encoding ibuf obuf
973 default-keymap-or-function)
974 "Major mode for viewing MIME message.
976 Here is a list of the standard keys for mime-view-mode.
981 u Move to upper content
982 p or M-TAB Move to previous content
983 n or TAB Move to next content
984 SPC Scroll up or move to next content
985 M-SPC or DEL Scroll down or move to previous content
986 RET Move to next line
987 M-RET Move to previous line
988 v Decode current content as `play mode'
989 e Decode current content as `extract mode'
990 C-c C-p Decode current content as `print mode'
991 a Followup to current content.
994 button-2 Move to point under the mouse cursor
995 and decode current content as `play mode'
998 (mime-maybe-hide-echo-buffer)
999 (let ((ret (mime-view-setup-buffers ctl encoding ibuf obuf))
1000 (win-conf (current-window-configuration))
1003 (switch-to-buffer ret)
1004 (setq mime-preview-original-window-configuration win-conf)
1007 (setq mime-mother-buffer mother)
1009 (mime-view-define-keymap default-keymap-or-function)
1011 (next-single-property-change (point-min) 'mime-view-entity)))
1014 (goto-char (point-min))
1015 (search-forward "\n\n" nil t)
1017 (run-hooks 'mime-view-mode-hook)
1024 (autoload 'mime-preview-play-current-entity "mime-play"
1025 "Play current entity." t)
1027 (defun mime-preview-extract-current-entity ()
1028 "Extract current entity into file (maybe).
1029 It decodes current entity to call internal or external method as
1030 \"extract\" mode. The method is selected from variable
1031 `mime-acting-condition'."
1033 (mime-preview-play-current-entity "extract")
1036 (defun mime-preview-print-current-entity ()
1037 "Print current entity (maybe).
1038 It decodes current entity to call internal or external method as
1039 \"print\" mode. The method is selected from variable
1040 `mime-acting-condition'."
1042 (mime-preview-play-current-entity "print")
1049 (defun mime-preview-original-major-mode ()
1050 "Return major-mode of original buffer.
1051 If a current buffer has mime-mother-buffer, return original major-mode
1052 of the mother-buffer."
1053 (if mime-mother-buffer
1055 (set-buffer mime-mother-buffer)
1056 (mime-preview-original-major-mode)
1058 mime-preview-original-major-mode))
1060 (defun mime-preview-follow-current-entity ()
1061 "Write follow message to current entity.
1062 It calls following-method selected from variable
1063 `mime-view-following-method-alist'."
1065 (let ((message-info (get-text-property (point-min) 'mime-view-entity))
1067 (while (null (setq entity
1068 (get-text-property (point) 'mime-view-entity)))
1072 (previous-single-property-change (point) 'mime-view-entity))
1074 (entity-node-id (mime-entity-node-id entity))
1075 (len (length entity-node-id))
1079 (if (eq (next-single-property-change (point-min)
1085 ((eq (next-single-property-change p-beg 'mime-view-entity)
1087 (setq p-beg (point))
1089 (setq p-end (next-single-property-change p-beg 'mime-view-entity))
1091 (setq p-end (point-max))
1093 ((null entity-node-id)
1094 (setq p-end (point-max))
1102 (next-single-property-change
1103 (point) 'mime-view-entity))
1105 (let ((rc (mime-entity-node-id
1106 (get-text-property (point)
1107 'mime-view-entity))))
1108 (or (equal entity-node-id
1109 (nthcdr (- (length rc) len) rc))
1114 (setq p-end (point-max))
1117 (let* ((mode (mime-preview-original-major-mode))
1119 (format "%s-%s" (buffer-name) (reverse entity-node-id)))
1121 (the-buf (current-buffer))
1122 (a-buf mime-raw-buffer)
1125 (set-buffer (setq new-buf (get-buffer-create new-name)))
1127 (insert-buffer-substring the-buf p-beg p-end)
1128 (goto-char (point-min))
1129 (if (mime-view-header-visible-p entity message-info)
1130 (delete-region (goto-char (point-min))
1131 (if (re-search-forward "^$" nil t)
1135 (goto-char (point-min))
1137 (goto-char (point-min))
1138 (let ((entity-node-id (mime-entity-node-id entity)) ci str)
1146 (mime-raw-find-entity-from-node-id entity-node-id))
1149 (mime-entity-point-min ci)
1150 (mime-entity-point-max ci)
1152 (std11-header-string-except
1154 (apply (function regexp-or) fields)
1157 (eq (mime-entity-media-type ci) 'message)
1158 (eq (mime-entity-media-subtype ci) 'rfc822))
1164 (setq fields (std11-collect-field-names)
1165 entity-node-id (cdr entity-node-id))
1168 (let ((rest mime-view-following-required-fields-list))
1170 (let ((field-name (car rest)))
1171 (or (std11-field-body field-name)
1177 (set-buffer the-buf)
1178 (set-buffer mime-mother-buffer)
1179 (set-buffer mime-raw-buffer)
1180 (std11-field-body field-name)
1184 (setq rest (cdr rest))
1186 (eword-decode-header)
1188 (let ((f (cdr (assq mode mime-view-following-method-alist))))
1193 "Sorry, following method for %s is not implemented yet."
1202 (defun mime-preview-display-x-face ()
1204 (save-window-excursion
1205 (set-buffer mime-raw-buffer)
1206 (mime-view-x-face-function)
1213 (defun mime-preview-move-to-upper ()
1214 "Move to upper entity.
1215 If there is no upper entity, call function `mime-preview-quit'."
1218 (while (null (setq cinfo
1219 (get-text-property (point) 'mime-view-entity)))
1222 (let ((r (mime-raw-find-entity-from-node-id
1223 (cdr (mime-entity-node-id cinfo))
1224 (get-text-property 1 'mime-view-entity)))
1227 (while (setq point (previous-single-property-change
1228 (point) 'mime-view-entity))
1230 (if (eq r (get-text-property (point) 'mime-view-entity))
1237 (defun mime-preview-move-to-previous ()
1238 "Move to previous entity.
1239 If there is no previous entity, it calls function registered in
1240 variable `mime-view-over-to-previous-method-alist'."
1242 (while (null (get-text-property (point) 'mime-view-entity))
1246 (previous-single-property-change (point) 'mime-view-entity)))
1249 (let ((f (assq mime-preview-original-major-mode
1250 mime-view-over-to-previous-method-alist)))
1256 (defun mime-preview-move-to-next ()
1257 "Move to next entity.
1258 If there is no previous entity, it calls function registered in
1259 variable `mime-view-over-to-next-method-alist'."
1261 (let ((point (next-single-property-change (point) 'mime-view-entity)))
1264 (let ((f (assq mime-preview-original-major-mode
1265 mime-view-over-to-next-method-alist)))
1271 (defun mime-preview-scroll-up-entity (&optional h)
1272 "Scroll up current entity.
1273 If reached to (point-max), it calls function registered in variable
1274 `mime-view-over-to-next-method-alist'."
1277 (setq h (1- (window-height)))
1279 (if (= (point) (point-max))
1280 (let ((f (assq mime-preview-original-major-mode
1281 mime-view-over-to-next-method-alist)))
1286 (or (next-single-property-change (point) 'mime-view-entity)
1289 (if (> (point) point)
1294 (defun mime-preview-scroll-down-entity (&optional h)
1295 "Scroll down current entity.
1296 If reached to (point-min), it calls function registered in variable
1297 `mime-view-over-to-previous-method-alist'."
1300 (setq h (1- (window-height)))
1302 (if (= (point) (point-min))
1303 (let ((f (assq mime-preview-original-major-mode
1304 mime-view-over-to-previous-method-alist)))
1311 (while (> (point) 1)
1313 (previous-single-property-change (point)
1319 (setq point (point-min))
1321 (forward-line (- h))
1322 (if (< (point) point)
1326 (defun mime-preview-next-line-entity ()
1328 (mime-preview-scroll-up-entity 1)
1331 (defun mime-preview-previous-line-entity ()
1333 (mime-preview-scroll-down-entity 1)
1340 (defun mime-preview-quit ()
1341 "Quit from MIME-preview buffer.
1342 It calls function registered in variable
1343 `mime-preview-quitting-method-alist'."
1345 (let ((r (assq mime-preview-original-major-mode
1346 mime-preview-quitting-method-alist)))
1351 (defun mime-preview-show-summary ()
1353 It calls function registered in variable
1354 `mime-view-show-summary-method'."
1356 (let ((r (assq mime-preview-original-major-mode
1357 mime-view-show-summary-method)))
1362 (defun mime-preview-kill-buffer ()
1364 (kill-buffer (current-buffer))
1371 (provide 'mime-view)
1373 (run-hooks 'mime-view-load-hook)
1375 ;;; mime-view.el ends here