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)
42 (defconst mime-view-version-string
43 `,(concat (car mime-module-version) " MIME-View "
44 (mapconcat #'number-to-string (cddr mime-module-version) ".")
45 " (" (cadr mime-module-version) ")"))
51 (defgroup mime-view nil
55 (defcustom mime-view-find-every-acting-situation t
56 "*Find every available acting-situation if non-nil."
60 (defcustom mime-acting-situation-examples-file "~/.mime-example"
61 "*File name of example about acting-situation demonstrated by user."
66 ;;; @ buffer local variables
72 (defvar mime-raw-message-info
73 "Information about structure of message.
74 Please use reference function `mime-entity-SLOT' to get value of SLOT.
76 Following is a list of slots of the structure:
78 node-id reversed entity-number (list of integers)
79 point-min beginning point of region in raw-buffer
80 point-max end point of region in raw-buffer
81 type media-type (symbol)
82 subtype media-subtype (symbol)
83 type/subtype media-type/subtype (string or nil)
84 parameters parameter of Content-Type field (association list)
85 encoding Content-Transfer-Encoding (string or nil)
86 children entities included in this entity (list of content-infos)
88 If an entity includes other entities in its body, such as multipart or
89 message/rfc822, `mime-entity' structures of them are included in
90 `children', so the `mime-entity' structure become a tree.")
91 (make-variable-buffer-local 'mime-raw-message-info)
93 (defvar mime-preview-buffer nil
94 "MIME-preview buffer corresponding with the (raw) buffer.")
95 (make-variable-buffer-local 'mime-preview-buffer)
98 ;;; @@ in preview-buffer
101 (defvar mime-mother-buffer nil
102 "Mother buffer corresponding with the (MIME-preview) buffer.
103 If current MIME-preview buffer is generated by other buffer, such as
104 message/partial, it is called `mother-buffer'.")
105 (make-variable-buffer-local 'mime-mother-buffer)
107 (defvar mime-raw-buffer nil
108 "Raw buffer corresponding with the (MIME-preview) buffer.")
109 (make-variable-buffer-local 'mime-raw-buffer)
111 (defvar mime-preview-original-major-mode nil
112 "Major-mode of mime-raw-buffer.")
113 (make-variable-buffer-local 'mime-preview-original-major-mode)
115 (defvar mime-preview-original-window-configuration nil
116 "Window-configuration before mime-view-mode is called.")
117 (make-variable-buffer-local 'mime-preview-original-window-configuration)
120 ;;; @ entity information
123 (defsubst mime-raw-find-entity-from-node-id (entity-node-id
124 &optional message-info)
125 "Return entity from ENTITY-NODE-ID in mime-raw-buffer.
126 If optional argument MESSAGE-INFO is not specified,
127 `mime-raw-message-info' is used."
128 (mime-raw-find-entity-from-number (reverse entity-node-id) message-info))
130 (defun mime-raw-find-entity-from-number (entity-number &optional message-info)
131 "Return entity from ENTITY-NUMBER in mime-raw-buffer.
132 If optional argument MESSAGE-INFO is not specified,
133 `mime-raw-message-info' is used."
135 (setq message-info mime-raw-message-info))
136 (if (eq entity-number t)
138 (let ((sn (car entity-number)))
141 (let ((rc (nth sn (mime-entity-children message-info))))
143 (mime-raw-find-entity-from-number (cdr entity-number) rc)
147 (defun mime-raw-find-entity-from-point (point &optional message-info)
148 "Return entity from POINT in mime-raw-buffer.
149 If optional argument MESSAGE-INFO is not specified,
150 `mime-raw-message-info' is used."
152 (setq message-info mime-raw-message-info))
153 (if (and (<= (mime-entity-point-min message-info) point)
154 (<= point (mime-entity-point-max message-info)))
155 (let ((children (mime-entity-children message-info)))
159 (mime-raw-find-entity-from-point point (car children))))
163 (setq children (cdr children)))
166 (defsubst mime-raw-point-to-entity-node-id (point &optional message-info)
167 "Return entity-node-id from POINT in mime-raw-buffer.
168 If optional argument MESSAGE-INFO is not specified,
169 `mime-raw-message-info' is used."
170 (mime-entity-node-id (mime-raw-find-entity-from-point point message-info)))
172 (defsubst mime-raw-point-to-entity-number (point &optional message-info)
173 "Return entity-number from POINT in mime-raw-buffer.
174 If optional argument MESSAGE-INFO is not specified,
175 `mime-raw-message-info' is used."
176 (reverse (mime-raw-point-to-entity-node-id point message-info)))
178 (defsubst mime-raw-entity-parent (entity &optional message-info)
179 "Return mother entity of ENTITY.
180 If optional argument MESSAGE-INFO is not specified,
181 `mime-raw-message-info' is used."
182 (mime-raw-find-entity-from-node-id (cdr (mime-entity-node-id entity))
185 (defun mime-raw-flatten-message-info (&optional message-info)
186 "Return list of entity in mime-raw-buffer.
187 If optional argument MESSAGE-INFO is not specified,
188 `mime-raw-message-info' is used."
190 (setq message-info mime-raw-message-info))
191 (let ((dest (list message-info))
192 (rcl (mime-entity-children message-info)))
194 (setq dest (nconc dest (mime-raw-flatten-message-info (car rcl))))
195 (setq rcl (cdr rcl)))
199 ;;; @ presentation of preview
205 ;;; @@@ predicate function
208 (defun mime-view-entity-button-visible-p (entity message-info)
209 "Return non-nil if header of ENTITY is visible.
210 Please redefine this function if you want to change default setting."
211 (let ((media-type (mime-entity-media-type entity))
212 (media-subtype (mime-entity-media-subtype entity)))
213 (or (not (eq media-type 'application))
214 (and (not (eq media-subtype 'x-selection))
215 (or (not (eq media-subtype 'octet-stream))
217 (mime-raw-entity-parent entity message-info)))
218 (or (not (eq (mime-entity-media-type mother-entity)
220 (not (eq (mime-entity-media-subtype mother-entity)
225 ;;; @@@ entity button generator
228 (defun mime-view-insert-entity-button (entity message-info subj)
229 "Insert entity-button of ENTITY."
230 (let ((entity-node-id (mime-entity-node-id entity))
231 (params (mime-entity-parameters entity)))
233 (let ((access-type (assoc "access-type" params))
234 (num (or (cdr (assoc "x-part-number" params))
235 (if (consp entity-node-id)
238 (format "%s" (1+ num))
240 (reverse entity-node-id) ".")
244 (let ((server (assoc "server" params)))
245 (setq access-type (cdr access-type))
247 (format "%s %s ([%s] %s)"
248 num subj access-type (cdr server))
249 (let ((site (cdr (assoc "site" params)))
250 (dir (cdr (assoc "directory" params)))
252 (format "%s %s ([%s] %s:%s)"
253 num subj access-type site dir)
257 (let ((media-type (mime-entity-media-type entity))
258 (media-subtype (mime-entity-media-subtype entity))
259 (charset (cdr (assoc "charset" params)))
260 (encoding (mime-entity-encoding entity)))
264 (format " <%s/%s%s%s>"
265 media-type media-subtype
267 (concat "; " charset)
270 (concat " (" encoding ")")
272 (if (>= (+ (current-column)(length rest))(window-width))
276 (function mime-preview-play-current-entity))
283 ;;; @@@ predicate function
286 ;; (defvar mime-view-childrens-header-showing-Content-Type-list
287 ;; '("message/rfc822" "message/news"))
289 ;; (defun mime-view-header-visible-p (entity message-info)
290 ;; "Return non-nil if header of ENTITY is visible."
291 ;; (let ((entity-node-id (mime-entity-node-id entity)))
292 ;; (member (mime-entity-type/subtype
293 ;; (mime-raw-find-entity-from-node-id
294 ;; (cdr entity-node-id) message-info))
295 ;; mime-view-childrens-header-showing-Content-Type-list)
298 ;;; @@@ entity header filter
301 (defvar mime-view-content-header-filter-alist nil)
303 (defun mime-view-default-content-header-filter ()
304 (mime-view-cut-header)
305 (eword-decode-header)
308 ;;; @@@ entity field cutter
311 (defvar mime-view-ignored-field-list
312 '(".*Received" ".*Path" ".*Id" "References"
313 "Replied" "Errors-To"
314 "Lines" "Sender" ".*Host" "Xref"
315 "Content-Type" "Precedence"
317 "All fields that match this list will be hidden in MIME preview buffer.
318 Each elements are regexp of field-name.")
320 (defvar mime-view-ignored-field-regexp
322 (apply (function regexp-or) mime-view-ignored-field-list)
325 (defvar mime-view-visible-field-list '("Dnas.*" "Message-Id")
326 "All fields that match this list will be displayed in MIME preview buffer.
327 Each elements are regexp of field-name.")
329 (defun mime-view-cut-header ()
330 (goto-char (point-min))
331 (while (re-search-forward mime-view-ignored-field-regexp nil t)
332 (let* ((beg (match-beginning 0))
334 (name (buffer-substring beg end))
337 (let ((rest mime-view-visible-field-list))
339 (if (string-match (car rest) name)
342 (setq rest (cdr rest))))
345 (if (re-search-forward "^\\([^ \t]\\|$\\)" nil t)
354 ;;; @@@ predicate function
357 (defun mime-calist::field-match-method-as-default-rule (calist
358 field-type field-value)
359 (let ((s-field (assq field-type calist)))
360 (cond ((null s-field)
361 (cons (cons field-type field-value) calist)
365 (define-calist-field-match-method
366 'header #'mime-calist::field-match-method-as-default-rule)
368 (define-calist-field-match-method
369 'body #'mime-calist::field-match-method-as-default-rule)
372 (defvar mime-preview-condition nil
373 "Condition-tree about how to display entity.")
375 (ctree-set-calist-strictly
376 'mime-preview-condition '((type . application)(subtype . octet-stream)
379 (ctree-set-calist-strictly
380 'mime-preview-condition '((type . application)(subtype . octet-stream)
383 (ctree-set-calist-strictly
384 'mime-preview-condition '((type . application)(subtype . octet-stream)
388 (ctree-set-calist-strictly
389 'mime-preview-condition '((type . application)(subtype . pgp)
392 (ctree-set-calist-strictly
393 'mime-preview-condition '((type . application)(subtype . x-latex)
396 (ctree-set-calist-strictly
397 'mime-preview-condition '((type . application)(subtype . x-selection)
400 (ctree-set-calist-strictly
401 'mime-preview-condition '((type . application)(subtype . x-comment)
404 (ctree-set-calist-strictly
405 'mime-preview-condition '((type . message)(subtype . delivery-status)
408 (ctree-set-calist-strictly
409 'mime-preview-condition
411 (body-presentation-method . mime-preview-text/plain)))
413 (ctree-set-calist-strictly
414 'mime-preview-condition
417 (body-presentation-method . mime-preview-text/plain)))
419 (ctree-set-calist-strictly
420 'mime-preview-condition
421 '((type . text)(subtype . enriched)
423 (body-presentation-method . mime-preview-text/enriched)))
425 (ctree-set-calist-strictly
426 'mime-preview-condition
427 '((type . text)(subtype . richtext)
429 (body-presentation-method . mime-preview-text/richtext)))
431 (ctree-set-calist-strictly
432 'mime-preview-condition
433 '((type . text)(subtype . t)
435 (body-presentation-method . mime-preview-text/plain)))
437 (ctree-set-calist-strictly
438 'mime-preview-condition '((type . message)(subtype . partial)
439 (body-presentation-method
440 . mime-preview-message/partial-button)))
442 (ctree-set-calist-strictly
443 'mime-preview-condition '((type . message)(subtype . rfc822)
444 (body-presentation-method . nil)
445 (childrens-situation (header . visible)
446 (entity-button . invisible))))
448 (ctree-set-calist-strictly
449 'mime-preview-condition '((type . message)(subtype . news)
450 (body-presentation-method . nil)
451 (childrens-situation (header . visible)
452 (entity-button . invisible))))
455 ;;; @@@ entity filter
458 (autoload 'mime-preview-text/plain "mime-text")
459 (autoload 'mime-preview-text/enriched "mime-text")
460 (autoload 'mime-preview-text/richtext "mime-text")
462 (defvar mime-text-decoder-alist
463 '((mime-show-message-mode . mime-text-decode-buffer)
464 (mime-temp-message-mode . mime-text-decode-buffer)
465 (t . mime-text-decode-buffer-maybe)
467 "Alist of major-mode vs. mime-text-decoder.
468 Each element looks like (SYMBOL . FUNCTION). SYMBOL is major-mode or
471 Specification of FUNCTION is described in DOC-string of variable
474 This value is overridden by buffer local variable `mime-text-decoder'
478 (defvar mime-view-announcement-for-message/partial
479 (if (and (>= emacs-major-version 19) window-system)
481 \[[ This is message/partial style split message. ]]
482 \[[ Please press `v' key in this buffer ]]
483 \[[ or click here by mouse button-2. ]]"
485 \[[ This is message/partial style split message. ]]
486 \[[ Please press `v' key in this buffer. ]]"
489 (defun mime-preview-message/partial-button (&optional entity situation)
491 (goto-char (point-max))
492 (if (not (search-backward "\n\n" nil t))
495 (goto-char (point-max))
496 (narrow-to-region (point-max)(point-max))
497 (insert mime-view-announcement-for-message/partial)
498 (mime-add-button (point-min)(point-max)
499 #'mime-preview-play-current-entity)
503 ;;; @ acting-condition
506 (defvar mime-acting-condition nil
507 "Condition-tree about how to process entity.")
509 (if (file-readable-p mailcap-file)
510 (let ((entries (mailcap-parse-file)))
512 (let ((entry (car entries))
515 (let* ((field (car entry))
516 (field-type (car field)))
517 (cond ((eq field-type 'view) (setq view field))
518 ((eq field-type 'print) (setq print field))
519 ((memq field-type '(compose composetyped edit)))
520 (t (setq shared (cons field shared))))
522 (setq entry (cdr entry))
524 (setq shared (nreverse shared))
525 (ctree-set-calist-with-default
526 'mime-acting-condition
527 (append shared (list '(mode . "play")(cons 'method (cdr view)))))
529 (ctree-set-calist-with-default
530 'mime-acting-condition
532 (list '(mode . "print")(cons 'method (cdr view))))
535 (setq entries (cdr entries))
538 ;; (ctree-set-calist-strictly
539 ;; 'mime-acting-condition
540 ;; '((type . t)(subtype . t)(mode . "extract")
541 ;; (method . mime-method-to-save)))
542 (ctree-set-calist-with-default
543 'mime-acting-condition
545 (method . mime-method-to-save)))
547 ;; (ctree-set-calist-strictly
548 ;; 'mime-acting-condition
549 ;; '((type . text)(subtype . plain)(mode . "play")
550 ;; (method "tm-plain" nil 'file "" 'encoding 'mode 'name)
552 ;; (ctree-set-calist-strictly
553 ;; 'mime-acting-condition
554 ;; '((type . text)(subtype . plain)(mode . "print")
555 ;; (method "tm-plain" nil 'file "" 'encoding 'mode 'name)
557 ;; (ctree-set-calist-strictly
558 ;; 'mime-acting-condition
559 ;; '((type . text)(subtype . html)(mode . "play")
560 ;; (method "tm-html" nil 'file "" 'encoding 'mode 'name)
562 (ctree-set-calist-strictly
563 'mime-acting-condition
564 '((type . text)(subtype . x-rot13-47)(mode . "play")
565 (method . mime-method-to-display-caesar)
567 (ctree-set-calist-strictly
568 'mime-acting-condition
569 '((type . text)(subtype . x-rot13-47-48)(mode . "play")
570 (method . mime-method-to-display-caesar)
573 ;; (ctree-set-calist-strictly
574 ;; 'mime-acting-condition
575 ;; '((type . audio)(subtype . basic)(mode . "play")
576 ;; (method "tm-au" nil 'file "" 'encoding 'mode 'name)
579 ;; (ctree-set-calist-strictly
580 ;; 'mime-acting-condition
581 ;; '((type . image)(mode . "play")
582 ;; (method "tm-image" nil 'file "" 'encoding 'mode 'name)
584 ;; (ctree-set-calist-strictly
585 ;; 'mime-acting-condition
586 ;; '((type . image)(mode . "print")
587 ;; (method "tm-image" nil 'file "" 'encoding 'mode 'name)
590 ;; (ctree-set-calist-strictly
591 ;; 'mime-acting-condition
592 ;; '((type . video)(subtype . mpeg)(mode . "play")
593 ;; (method "tm-mpeg" nil 'file "" 'encoding 'mode 'name)
596 ;; (ctree-set-calist-strictly
597 ;; 'mime-acting-condition
598 ;; '((type . application)(subtype . postscript)(mode . "play")
599 ;; (method "tm-ps" nil 'file "" 'encoding 'mode 'name)
601 ;; (ctree-set-calist-strictly
602 ;; 'mime-acting-condition
603 ;; '((type . application)(subtype . postscript)(mode . "print")
604 ;; (method "tm-ps" nil 'file "" 'encoding 'mode 'name)
607 (ctree-set-calist-strictly
608 'mime-acting-condition
609 '((type . message)(subtype . rfc822)(mode . "play")
610 (method . mime-method-to-display-message/rfc822)
612 (ctree-set-calist-strictly
613 'mime-acting-condition
614 '((type . message)(subtype . partial)(mode . "play")
615 (method . mime-method-to-store-message/partial)
618 (ctree-set-calist-strictly
619 'mime-acting-condition
620 '((type . message)(subtype . external-body)
621 ("access-type" . "anon-ftp")
622 (method . mime-method-to-display-message/external-ftp)
625 (ctree-set-calist-strictly
626 'mime-acting-condition
627 '((type . application)(subtype . octet-stream)
628 (method . mime-method-to-save)
632 ;;; @ quitting method
635 (defvar mime-preview-quitting-method-alist
636 '((mime-show-message-mode
637 . mime-preview-quitting-method-for-mime-show-message-mode))
638 "Alist of major-mode vs. quitting-method of mime-view.")
640 (defvar mime-view-over-to-previous-method-alist nil)
641 (defvar mime-view-over-to-next-method-alist nil)
643 (defvar mime-view-show-summary-method nil
644 "Alist of major-mode vs. show-summary-method.")
647 ;;; @ following method
650 (defvar mime-view-following-method-alist nil
651 "Alist of major-mode vs. following-method of mime-view.")
653 (defvar mime-view-following-required-fields-list
660 ;; hack from Gnus 5.0.4.
662 (defvar mime-view-x-face-to-pbm-command
663 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm")
665 (defvar mime-view-x-face-command
666 (concat mime-view-x-face-to-pbm-command
668 "String to be executed to display an X-Face field.
669 The command will be executed in a sub-shell asynchronously.
670 The compressed face will be piped to this command.")
672 (defun mime-view-x-face-function ()
673 "Function to display X-Face field. You can redefine to customize."
674 ;; 1995/10/12 (c.f. tm-eng:130)
675 ;; fixed by Eric Ding <ericding@San-Jose.ate.slb.com>
677 (narrow-to-region (point-min) (re-search-forward "^$" nil t))
679 (goto-char (point-min))
680 (if (re-search-forward "^X-Face:[ \t]*" nil t)
681 (let ((beg (match-end 0))
682 (end (std11-field-end))
684 (call-process-region beg end "sh" nil 0 nil
685 "-c" mime-view-x-face-command)
692 (defvar mime-view-uuencode-encoding-name-list '("x-uue" "x-uuencode"))
694 (defvar mime-raw-buffer-coding-system-alist
695 `((t . ,(mime-charset-to-coding-system default-mime-charset)))
696 "Alist of major-mode vs. corresponding coding-system of `mime-raw-buffer'.")
702 (defvar mime-view-redisplay nil)
704 (defun mime-view-setup-buffers (&optional ctl encoding ibuf obuf)
710 (or mime-view-redisplay
711 (setq mime-raw-message-info (mime-parse-message ctl encoding))
713 (let ((message-info mime-raw-message-info)
714 (the-buf (current-buffer))
717 (setq obuf (concat "*Preview-" (buffer-name the-buf) "*")))
718 (set-buffer (get-buffer-create obuf))
719 (let ((inhibit-read-only t))
720 ;;(setq buffer-read-only nil)
723 (setq mime-raw-buffer the-buf)
724 (setq mime-preview-original-major-mode mode)
725 (setq major-mode 'mime-view-mode)
726 (setq mode-name "MIME-View")
727 (mime-view-display-entity message-info message-info
729 '((entity-button . invisible)
732 (set-buffer-modified-p nil)
734 (setq buffer-read-only t)
737 (setq mime-preview-buffer obuf)
740 (defun mime-view-display-entity (entity message-info ibuf obuf
742 (let* ((start (mime-entity-point-min entity))
743 (end (mime-entity-point-max entity))
744 (content-type (mime-entity-content-type entity))
745 (encoding (mime-entity-encoding entity))
746 end-of-header e nb ne subj)
749 (setq end-of-header (if (re-search-forward "^$" nil t)
752 (if (> end-of-header end)
753 (setq end-of-header end)
756 (narrow-to-region start end)
757 (setq subj (eword-decode-string (mime-raw-get-subject entity)))
761 (ctree-match-calist mime-preview-condition
764 (make-mime-content-type 'text 'plain))
765 (list* (cons 'encoding encoding)
766 (cons 'major-mode major-mode)
770 (eq (cdr (assq 'entity-button situation)) 'invisible))
772 (eq (cdr (assq 'header situation)) 'visible))
773 (body-presentation-method
774 (cdr (assq 'body-presentation-method situation))))
777 (narrow-to-region nb nb)
778 (or button-is-invisible
779 (if (mime-view-entity-button-visible-p entity message-info)
780 (mime-view-insert-entity-button entity message-info subj)
782 (if header-is-visible
784 (narrow-to-region (point)(point))
785 (insert-buffer-substring mime-raw-buffer start end-of-header)
786 (let ((f (cdr (assq mime-preview-original-major-mode
787 mime-view-content-header-filter-alist))))
790 (mime-view-default-content-header-filter)
792 (run-hooks 'mime-view-content-header-filter-hook)
794 (cond ((eq body-presentation-method 'with-filter)
795 (let ((body-filter (cdr (assq 'body-filter situation))))
797 (narrow-to-region (point-max)(point-max))
798 (insert-buffer-substring mime-raw-buffer end-of-header end)
799 (funcall body-filter situation)
801 ((functionp body-presentation-method)
802 (funcall body-presentation-method entity situation)
804 (or header-is-visible
805 body-presentation-method
807 (goto-char (point-max))
810 (setq ne (point-max))
812 (put-text-property nb ne 'mime-view-raw-buffer ibuf)
813 (put-text-property nb ne 'mime-view-entity entity)
815 (let ((children (mime-entity-children entity))
817 (cdr (assq 'childrens-situation situation))))
819 (mime-view-display-entity (car children) message-info ibuf obuf
821 (setq children (cdr children))
824 (defun mime-raw-get-uu-filename ()
826 (if (re-search-forward "^begin [0-9]+ " nil t)
827 (if (looking-at ".+$")
828 (buffer-substring (match-beginning 0)(match-end 0))
831 (defun mime-raw-get-subject (entity)
832 (or (std11-find-field-body '("Content-Description" "Subject"))
833 (let ((ret (mime-entity-content-disposition entity)))
835 (setq ret (mime-content-disposition-filename ret))
836 (std11-strip-quoted-string ret)
838 (let ((ret (mime-entity-content-type entity)))
842 (let ((param (mime-content-type-parameters ret)))
843 (or (assoc "name" param)
844 (assoc "x-name" param))
846 (std11-strip-quoted-string ret)
848 (if (member (mime-entity-encoding entity)
849 mime-view-uuencode-encoding-name-list)
850 (mime-raw-get-uu-filename))
854 ;;; @ MIME viewer mode
857 (defconst mime-view-menu-title "MIME-View")
858 (defconst mime-view-menu-list
859 '((up "Move to upper entity" mime-preview-move-to-upper)
860 (previous "Move to previous entity" mime-preview-move-to-previous)
861 (next "Move to next entity" mime-preview-move-to-next)
862 (scroll-down "Scroll-down" mime-preview-scroll-down-entity)
863 (scroll-up "Scroll-up" mime-preview-scroll-up-entity)
864 (play "Play current entity" mime-preview-play-current-entity)
865 (extract "Extract current entity" mime-preview-extract-current-entity)
866 (print "Print current entity" mime-preview-print-current-entity)
867 (x-face "Show X Face" mime-preview-display-x-face)
869 "Menu for MIME Viewer")
871 (cond (running-xemacs
872 (defvar mime-view-xemacs-popup-menu
873 (cons mime-view-menu-title
876 (vector (nth 1 item)(nth 2 item) t)
878 mime-view-menu-list)))
879 (defun mime-view-xemacs-popup-menu (event)
880 "Popup the menu in the MIME Viewer buffer"
882 (select-window (event-window event))
883 (set-buffer (event-buffer event))
884 (popup-menu 'mime-view-xemacs-popup-menu))
885 (defvar mouse-button-2 'button2)
888 (defvar mouse-button-2 [mouse-2])
891 (defun mime-view-define-keymap (&optional default)
892 (let ((mime-view-mode-map (if (keymapp default)
893 (copy-keymap default)
896 (define-key mime-view-mode-map
897 "u" (function mime-preview-move-to-upper))
898 (define-key mime-view-mode-map
899 "p" (function mime-preview-move-to-previous))
900 (define-key mime-view-mode-map
901 "n" (function mime-preview-move-to-next))
902 (define-key mime-view-mode-map
903 "\e\t" (function mime-preview-move-to-previous))
904 (define-key mime-view-mode-map
905 "\t" (function mime-preview-move-to-next))
906 (define-key mime-view-mode-map
907 " " (function mime-preview-scroll-up-entity))
908 (define-key mime-view-mode-map
909 "\M- " (function mime-preview-scroll-down-entity))
910 (define-key mime-view-mode-map
911 "\177" (function mime-preview-scroll-down-entity))
912 (define-key mime-view-mode-map
913 "\C-m" (function mime-preview-next-line-entity))
914 (define-key mime-view-mode-map
915 "\C-\M-m" (function mime-preview-previous-line-entity))
916 (define-key mime-view-mode-map
917 "v" (function mime-preview-play-current-entity))
918 (define-key mime-view-mode-map
919 "e" (function mime-preview-extract-current-entity))
920 (define-key mime-view-mode-map
921 "\C-c\C-p" (function mime-preview-print-current-entity))
922 (define-key mime-view-mode-map
923 "a" (function mime-preview-follow-current-entity))
924 (define-key mime-view-mode-map
925 "q" (function mime-preview-quit))
926 (define-key mime-view-mode-map
927 "h" (function mime-preview-show-summary))
928 (define-key mime-view-mode-map
929 "\C-c\C-x" (function mime-preview-kill-buffer))
930 ;; (define-key mime-view-mode-map
931 ;; "<" (function beginning-of-buffer))
932 ;; (define-key mime-view-mode-map
933 ;; ">" (function end-of-buffer))
934 (define-key mime-view-mode-map
935 "?" (function describe-mode))
936 (define-key mime-view-mode-map
937 [tab] (function mime-preview-move-to-next))
938 (define-key mime-view-mode-map
939 [delete] (function mime-preview-scroll-down-entity))
940 (define-key mime-view-mode-map
941 [backspace] (function mime-preview-scroll-down-entity))
942 (if (functionp default)
943 (cond (running-xemacs
944 (set-keymap-default-binding mime-view-mode-map default)
947 (setq mime-view-mode-map
948 (append mime-view-mode-map (list (cons t default))))
951 (define-key mime-view-mode-map
952 mouse-button-2 (function mime-button-dispatcher))
954 (cond (running-xemacs
955 (define-key mime-view-mode-map
956 mouse-button-3 (function mime-view-xemacs-popup-menu))
958 ((>= emacs-major-version 19)
959 (define-key mime-view-mode-map [menu-bar mime-view]
960 (cons mime-view-menu-title
961 (make-sparse-keymap mime-view-menu-title)))
964 (define-key mime-view-mode-map
965 (vector 'menu-bar 'mime-view (car item))
966 (cons (nth 1 item)(nth 2 item))
969 (reverse mime-view-menu-list)
972 (use-local-map mime-view-mode-map)
973 (run-hooks 'mime-view-define-keymap-hook)
976 (defsubst mime-maybe-hide-echo-buffer ()
977 "Clear mime-echo buffer and delete window for it."
978 (let ((buf (get-buffer mime-echo-buffer-name)))
983 (let ((win (get-buffer-window buf)))
990 (defun mime-view-mode (&optional mother ctl encoding ibuf obuf
991 default-keymap-or-function)
992 "Major mode for viewing MIME message.
994 Here is a list of the standard keys for mime-view-mode.
999 u Move to upper content
1000 p or M-TAB Move to previous content
1001 n or TAB Move to next content
1002 SPC Scroll up or move to next content
1003 M-SPC or DEL Scroll down or move to previous content
1004 RET Move to next line
1005 M-RET Move to previous line
1006 v Decode current content as `play mode'
1007 e Decode current content as `extract mode'
1008 C-c C-p Decode current content as `print mode'
1009 a Followup to current content.
1012 button-2 Move to point under the mouse cursor
1013 and decode current content as `play mode'
1016 (mime-maybe-hide-echo-buffer)
1017 (let ((ret (mime-view-setup-buffers ctl encoding ibuf obuf))
1018 (win-conf (current-window-configuration))
1021 (switch-to-buffer ret)
1022 (setq mime-preview-original-window-configuration win-conf)
1025 (setq mime-mother-buffer mother)
1027 (mime-view-define-keymap default-keymap-or-function)
1029 (next-single-property-change (point-min) 'mime-view-entity)))
1032 (goto-char (point-min))
1033 (search-forward "\n\n" nil t)
1035 (run-hooks 'mime-view-mode-hook)
1042 (autoload 'mime-preview-play-current-entity "mime-play"
1043 "Play current entity." t)
1045 (defun mime-preview-extract-current-entity ()
1046 "Extract current entity into file (maybe).
1047 It decodes current entity to call internal or external method as
1048 \"extract\" mode. The method is selected from variable
1049 `mime-acting-condition'."
1051 (mime-preview-play-current-entity "extract")
1054 (defun mime-preview-print-current-entity ()
1055 "Print current entity (maybe).
1056 It decodes current entity to call internal or external method as
1057 \"print\" mode. The method is selected from variable
1058 `mime-acting-condition'."
1060 (mime-preview-play-current-entity "print")
1067 (defun mime-preview-original-major-mode ()
1068 "Return major-mode of original buffer.
1069 If a current buffer has mime-mother-buffer, return original major-mode
1070 of the mother-buffer."
1071 (if mime-mother-buffer
1073 (set-buffer mime-mother-buffer)
1074 (mime-preview-original-major-mode)
1076 mime-preview-original-major-mode))
1078 (defun mime-preview-follow-current-entity ()
1079 "Write follow message to current entity.
1080 It calls following-method selected from variable
1081 `mime-view-following-method-alist'."
1084 (while (null (setq entity
1085 (get-text-property (point) 'mime-view-entity)))
1089 (previous-single-property-change (point) 'mime-view-entity))
1091 (entity-node-id (mime-entity-node-id entity))
1092 (len (length entity-node-id))
1096 (if (eq (next-single-property-change (point-min)
1102 ((eq (next-single-property-change p-beg 'mime-view-entity)
1104 (setq p-beg (point))
1106 (setq p-end (next-single-property-change p-beg 'mime-view-entity))
1108 (setq p-end (point-max))
1110 ((null entity-node-id)
1111 (setq p-end (point-max))
1119 (next-single-property-change
1120 (point) 'mime-view-entity))
1122 (let ((rc (mime-entity-node-id
1123 (get-text-property (point)
1124 'mime-view-entity))))
1125 (or (equal entity-node-id
1126 (nthcdr (- (length rc) len) rc))
1131 (setq p-end (point-max))
1134 (let* ((mode (mime-preview-original-major-mode))
1136 (format "%s-%s" (buffer-name) (reverse entity-node-id)))
1138 (the-buf (current-buffer))
1139 (a-buf mime-raw-buffer)
1142 (set-buffer (setq new-buf (get-buffer-create new-name)))
1144 (insert-buffer-substring the-buf p-beg p-end)
1145 (goto-char (point-min))
1146 (let ((entity-node-id (mime-entity-node-id entity)) ci str)
1154 (mime-raw-find-entity-from-node-id entity-node-id))
1157 (mime-entity-point-min ci)
1158 (mime-entity-point-max ci)
1160 (std11-header-string-except
1162 (apply (function regexp-or) fields)
1165 (eq (mime-entity-media-type ci) 'message)
1166 (eq (mime-entity-media-subtype ci) 'rfc822))
1172 (setq fields (std11-collect-field-names)
1173 entity-node-id (cdr entity-node-id))
1176 (let ((rest mime-view-following-required-fields-list))
1178 (let ((field-name (car rest)))
1179 (or (std11-field-body field-name)
1185 (set-buffer the-buf)
1186 (set-buffer mime-mother-buffer)
1187 (set-buffer mime-raw-buffer)
1188 (std11-field-body field-name)
1192 (setq rest (cdr rest))
1194 (eword-decode-header)
1196 (let ((f (cdr (assq mode mime-view-following-method-alist))))
1201 "Sorry, following method for %s is not implemented yet."
1210 (defun mime-preview-display-x-face ()
1212 (save-window-excursion
1213 (set-buffer mime-raw-buffer)
1214 (mime-view-x-face-function)
1221 (defun mime-preview-move-to-upper ()
1222 "Move to upper entity.
1223 If there is no upper entity, call function `mime-preview-quit'."
1226 (while (null (setq cinfo
1227 (get-text-property (point) 'mime-view-entity)))
1230 (let ((r (mime-raw-find-entity-from-node-id
1231 (cdr (mime-entity-node-id cinfo))
1232 (get-text-property 1 'mime-view-entity)))
1235 (while (setq point (previous-single-property-change
1236 (point) 'mime-view-entity))
1238 (if (eq r (get-text-property (point) 'mime-view-entity))
1245 (defun mime-preview-move-to-previous ()
1246 "Move to previous entity.
1247 If there is no previous entity, it calls function registered in
1248 variable `mime-view-over-to-previous-method-alist'."
1250 (while (null (get-text-property (point) 'mime-view-entity))
1253 (let ((point (previous-single-property-change (point) 'mime-view-entity)))
1255 (if (get-text-property (1- point) 'mime-view-entity)
1257 (goto-char (1- point))
1258 (mime-preview-move-to-previous)
1260 (let ((f (assq mime-preview-original-major-mode
1261 mime-view-over-to-previous-method-alist)))
1267 (defun mime-preview-move-to-next ()
1268 "Move to next entity.
1269 If there is no previous entity, it calls function registered in
1270 variable `mime-view-over-to-next-method-alist'."
1272 (while (null (get-text-property (point) 'mime-view-entity))
1275 (let ((point (next-single-property-change (point) 'mime-view-entity)))
1279 (if (null (get-text-property point 'mime-view-entity))
1280 (mime-preview-move-to-next)
1282 (let ((f (assq mime-preview-original-major-mode
1283 mime-view-over-to-next-method-alist)))
1289 (defun mime-preview-scroll-up-entity (&optional h)
1290 "Scroll up current entity.
1291 If reached to (point-max), it calls function registered in variable
1292 `mime-view-over-to-next-method-alist'."
1295 (setq h (1- (window-height)))
1297 (if (= (point) (point-max))
1298 (let ((f (assq mime-preview-original-major-mode
1299 mime-view-over-to-next-method-alist)))
1304 (or (next-single-property-change (point) 'mime-view-entity)
1307 (if (> (point) point)
1312 (defun mime-preview-scroll-down-entity (&optional h)
1313 "Scroll down current entity.
1314 If reached to (point-min), it calls function registered in variable
1315 `mime-view-over-to-previous-method-alist'."
1318 (setq h (1- (window-height)))
1320 (if (= (point) (point-min))
1321 (let ((f (assq mime-preview-original-major-mode
1322 mime-view-over-to-previous-method-alist)))
1331 (previous-single-property-change (point)
1337 (setq point (point-min))
1339 (forward-line (- h))
1340 (if (< (point) point)
1344 (defun mime-preview-next-line-entity ()
1346 (mime-preview-scroll-up-entity 1)
1349 (defun mime-preview-previous-line-entity ()
1351 (mime-preview-scroll-down-entity 1)
1358 (defun mime-preview-quit ()
1359 "Quit from MIME-preview buffer.
1360 It calls function registered in variable
1361 `mime-preview-quitting-method-alist'."
1363 (let ((r (assq mime-preview-original-major-mode
1364 mime-preview-quitting-method-alist)))
1369 (defun mime-preview-show-summary ()
1371 It calls function registered in variable
1372 `mime-view-show-summary-method'."
1374 (let ((r (assq mime-preview-original-major-mode
1375 mime-view-show-summary-method)))
1380 (defun mime-preview-kill-buffer ()
1382 (kill-buffer (current-buffer))
1389 (provide 'mime-view)
1391 (run-hooks 'mime-view-load-hook)
1393 ;;; mime-view.el ends here