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)
97 (defvar mime-raw-representation-type-alist
98 '((mime-show-message-mode . binary)
99 (mime-temp-message-mode . binary)
102 "Alist of major-mode vs. representation-type of mime-raw-buffer.
103 Each element looks like (SYMBOL . REPRESENTATION-TYPE). SYMBOL is
104 major-mode or t. t means default. REPRESENTATION-TYPE must be
105 `binary' or `cooked'.
106 This value is overridden by buffer local variable
107 `mime-raw-representation-type' if it is not nil.")
110 ;;; @@ in preview-buffer
113 (defvar mime-mother-buffer nil
114 "Mother buffer corresponding with the (MIME-preview) buffer.
115 If current MIME-preview buffer is generated by other buffer, such as
116 message/partial, it is called `mother-buffer'.")
117 (make-variable-buffer-local 'mime-mother-buffer)
119 (defvar mime-raw-buffer nil
120 "Raw buffer corresponding with the (MIME-preview) buffer.")
121 (make-variable-buffer-local 'mime-raw-buffer)
123 (defvar mime-preview-original-major-mode nil
124 "Major-mode of mime-raw-buffer.")
125 (make-variable-buffer-local 'mime-preview-original-major-mode)
127 (defvar mime-preview-original-window-configuration nil
128 "Window-configuration before mime-view-mode is called.")
129 (make-variable-buffer-local 'mime-preview-original-window-configuration)
132 ;;; @ entity information
135 (defsubst mime-raw-find-entity-from-node-id (entity-node-id
136 &optional message-info)
137 "Return entity from ENTITY-NODE-ID in mime-raw-buffer.
138 If optional argument MESSAGE-INFO is not specified,
139 `mime-raw-message-info' is used."
140 (mime-raw-find-entity-from-number (reverse entity-node-id) message-info))
142 (defun mime-raw-find-entity-from-number (entity-number &optional message-info)
143 "Return entity from ENTITY-NUMBER in mime-raw-buffer.
144 If optional argument MESSAGE-INFO is not specified,
145 `mime-raw-message-info' is used."
147 (setq message-info mime-raw-message-info))
148 (if (eq entity-number t)
150 (let ((sn (car entity-number)))
153 (let ((rc (nth sn (mime-entity-children message-info))))
155 (mime-raw-find-entity-from-number (cdr entity-number) rc)
159 (defun mime-raw-find-entity-from-point (point &optional message-info)
160 "Return entity from POINT in mime-raw-buffer.
161 If optional argument MESSAGE-INFO is not specified,
162 `mime-raw-message-info' is used."
164 (setq message-info mime-raw-message-info))
165 (if (and (<= (mime-entity-point-min message-info) point)
166 (<= point (mime-entity-point-max message-info)))
167 (let ((children (mime-entity-children message-info)))
171 (mime-raw-find-entity-from-point point (car children))))
175 (setq children (cdr children)))
178 (defsubst mime-raw-point-to-entity-node-id (point &optional message-info)
179 "Return entity-node-id from POINT in mime-raw-buffer.
180 If optional argument MESSAGE-INFO is not specified,
181 `mime-raw-message-info' is used."
182 (mime-entity-node-id (mime-raw-find-entity-from-point point message-info)))
184 (defsubst mime-raw-point-to-entity-number (point &optional message-info)
185 "Return entity-number from POINT in mime-raw-buffer.
186 If optional argument MESSAGE-INFO is not specified,
187 `mime-raw-message-info' is used."
188 (reverse (mime-raw-point-to-entity-node-id point message-info)))
190 (defsubst mime-raw-entity-parent (entity &optional message-info)
191 "Return mother entity of ENTITY.
192 If optional argument MESSAGE-INFO is not specified,
193 `mime-raw-message-info' is used."
194 (mime-raw-find-entity-from-node-id (cdr (mime-entity-node-id entity))
197 (defun mime-raw-flatten-message-info (&optional message-info)
198 "Return list of entity in mime-raw-buffer.
199 If optional argument MESSAGE-INFO is not specified,
200 `mime-raw-message-info' is used."
202 (setq message-info mime-raw-message-info))
203 (let ((dest (list message-info))
204 (rcl (mime-entity-children message-info)))
206 (setq dest (nconc dest (mime-raw-flatten-message-info (car rcl))))
207 (setq rcl (cdr rcl)))
211 ;;; @ presentation of preview
217 ;;; @@@ predicate function
220 (defun mime-view-entity-button-visible-p (entity message-info)
221 "Return non-nil if header of ENTITY is visible.
222 Please redefine this function if you want to change default setting."
223 (let ((media-type (mime-entity-media-type entity))
224 (media-subtype (mime-entity-media-subtype entity)))
225 (or (not (eq media-type 'application))
226 (and (not (eq media-subtype 'x-selection))
227 (or (not (eq media-subtype 'octet-stream))
229 (mime-raw-entity-parent entity message-info)))
230 (or (not (eq (mime-entity-media-type mother-entity)
232 (not (eq (mime-entity-media-subtype mother-entity)
237 ;;; @@@ entity button generator
240 (defun mime-view-insert-entity-button (entity message-info subj)
241 "Insert entity-button of ENTITY."
242 (let ((entity-node-id (mime-entity-node-id entity))
243 (params (mime-entity-parameters entity)))
245 (let ((access-type (assoc "access-type" params))
246 (num (or (cdr (assoc "x-part-number" params))
247 (if (consp entity-node-id)
250 (format "%s" (1+ num))
252 (reverse entity-node-id) ".")
256 (let ((server (assoc "server" params)))
257 (setq access-type (cdr access-type))
259 (format "%s %s ([%s] %s)"
260 num subj access-type (cdr server))
261 (let ((site (cdr (assoc "site" params)))
262 (dir (cdr (assoc "directory" params)))
264 (format "%s %s ([%s] %s:%s)"
265 num subj access-type site dir)
269 (let ((media-type (mime-entity-media-type entity))
270 (media-subtype (mime-entity-media-subtype entity))
271 (charset (cdr (assoc "charset" params)))
272 (encoding (mime-entity-encoding entity)))
276 (format " <%s/%s%s%s>"
277 media-type media-subtype
279 (concat "; " charset)
282 (concat " (" encoding ")")
284 (if (>= (+ (current-column)(length rest))(window-width))
288 (function mime-preview-play-current-entity))
295 ;;; @@@ entity header filter
298 (defvar mime-view-content-header-filter-alist nil)
300 (defun mime-view-default-content-header-filter ()
301 (mime-view-cut-header)
302 (eword-decode-header)
305 ;;; @@@ entity field cutter
308 (defvar mime-view-ignored-field-list
309 '(".*Received" ".*Path" ".*Id" "References"
310 "Replied" "Errors-To"
311 "Lines" "Sender" ".*Host" "Xref"
312 "Content-Type" "Precedence"
314 "All fields that match this list will be hidden in MIME preview buffer.
315 Each elements are regexp of field-name.")
317 (defvar mime-view-ignored-field-regexp
319 (apply (function regexp-or) mime-view-ignored-field-list)
322 (defvar mime-view-visible-field-list '("Dnas.*" "Message-Id")
323 "All fields that match this list will be displayed in MIME preview buffer.
324 Each elements are regexp of field-name.")
326 (defun mime-view-cut-header ()
327 (goto-char (point-min))
328 (while (re-search-forward mime-view-ignored-field-regexp nil t)
329 (let* ((beg (match-beginning 0))
331 (name (buffer-substring beg end))
334 (let ((rest mime-view-visible-field-list))
336 (if (string-match (car rest) name)
339 (setq rest (cdr rest))))
342 (if (re-search-forward "^\\([^ \t]\\|$\\)" nil t)
351 ;;; @@@ predicate function
354 (defun mime-calist::field-match-method-as-default-rule (calist
355 field-type field-value)
356 (let ((s-field (assq field-type calist)))
357 (cond ((null s-field)
358 (cons (cons field-type field-value) calist)
362 (define-calist-field-match-method
363 'header #'mime-calist::field-match-method-as-default-rule)
365 (define-calist-field-match-method
366 'body #'mime-calist::field-match-method-as-default-rule)
369 (defvar mime-preview-condition nil
370 "Condition-tree about how to display entity.")
372 (ctree-set-calist-strictly
373 'mime-preview-condition '((type . application)(subtype . octet-stream)
376 (ctree-set-calist-strictly
377 'mime-preview-condition '((type . application)(subtype . octet-stream)
380 (ctree-set-calist-strictly
381 'mime-preview-condition '((type . application)(subtype . octet-stream)
385 (ctree-set-calist-strictly
386 'mime-preview-condition '((type . application)(subtype . pgp)
389 (ctree-set-calist-strictly
390 'mime-preview-condition '((type . application)(subtype . x-latex)
393 (ctree-set-calist-strictly
394 'mime-preview-condition '((type . application)(subtype . x-selection)
397 (ctree-set-calist-strictly
398 'mime-preview-condition '((type . application)(subtype . x-comment)
401 (ctree-set-calist-strictly
402 'mime-preview-condition '((type . message)(subtype . delivery-status)
405 (ctree-set-calist-strictly
406 'mime-preview-condition
408 (body-presentation-method . mime-preview-text/plain)))
410 (ctree-set-calist-strictly
411 'mime-preview-condition
414 (body-presentation-method . mime-preview-text/plain)))
416 (ctree-set-calist-strictly
417 'mime-preview-condition
418 '((type . text)(subtype . enriched)
420 (body-presentation-method . mime-preview-text/enriched)))
422 (ctree-set-calist-strictly
423 'mime-preview-condition
424 '((type . text)(subtype . richtext)
426 (body-presentation-method . mime-preview-text/richtext)))
428 (ctree-set-calist-strictly
429 'mime-preview-condition
430 '((type . text)(subtype . t)
432 (body-presentation-method . mime-preview-text/plain)))
434 (ctree-set-calist-strictly
435 'mime-preview-condition '((type . message)(subtype . partial)
436 (body-presentation-method
437 . mime-preview-message/partial-button)))
439 (ctree-set-calist-strictly
440 'mime-preview-condition '((type . message)(subtype . rfc822)
441 (body-presentation-method . nil)
442 (childrens-situation (header . visible)
443 (entity-button . invisible))))
445 (ctree-set-calist-strictly
446 'mime-preview-condition '((type . message)(subtype . news)
447 (body-presentation-method . nil)
448 (childrens-situation (header . visible)
449 (entity-button . invisible))))
452 ;;; @@@ entity presentation
455 (autoload 'mime-preview-text/plain "mime-text")
456 (autoload 'mime-preview-text/enriched "mime-text")
457 (autoload 'mime-preview-text/richtext "mime-text")
459 (defvar mime-view-announcement-for-message/partial
460 (if (and (>= emacs-major-version 19) window-system)
462 \[[ This is message/partial style split message. ]]
463 \[[ Please press `v' key in this buffer ]]
464 \[[ or click here by mouse button-2. ]]"
466 \[[ This is message/partial style split message. ]]
467 \[[ Please press `v' key in this buffer. ]]"
470 (defun mime-preview-message/partial-button (&optional entity situation)
472 (goto-char (point-max))
473 (if (not (search-backward "\n\n" nil t))
476 (goto-char (point-max))
477 (narrow-to-region (point-max)(point-max))
478 (insert mime-view-announcement-for-message/partial)
479 (mime-add-button (point-min)(point-max)
480 #'mime-preview-play-current-entity)
483 (defun mime-preview-multipart/mixed (entity situation)
484 (let ((children (mime-entity-children entity))
486 (cdr (assq 'childrens-situation situation))))
488 (mime-view-display-entity (car children) mime-raw-message-info
489 mime-raw-buffer (current-buffer)
491 (setq children (cdr children))
495 ;;; @ acting-condition
498 (defvar mime-acting-condition nil
499 "Condition-tree about how to process entity.")
501 (if (file-readable-p mailcap-file)
502 (let ((entries (mailcap-parse-file)))
504 (let ((entry (car entries))
507 (let* ((field (car entry))
508 (field-type (car field)))
509 (cond ((eq field-type 'view) (setq view field))
510 ((eq field-type 'print) (setq print field))
511 ((memq field-type '(compose composetyped edit)))
512 (t (setq shared (cons field shared))))
514 (setq entry (cdr entry))
516 (setq shared (nreverse shared))
517 (ctree-set-calist-with-default
518 'mime-acting-condition
519 (append shared (list '(mode . "play")(cons 'method (cdr view)))))
521 (ctree-set-calist-with-default
522 'mime-acting-condition
524 (list '(mode . "print")(cons 'method (cdr view))))
527 (setq entries (cdr entries))
530 ;; (ctree-set-calist-strictly
531 ;; 'mime-acting-condition
532 ;; '((type . t)(subtype . t)(mode . "extract")
533 ;; (method . mime-method-to-save)))
534 (ctree-set-calist-with-default
535 'mime-acting-condition
537 (method . mime-method-to-save)))
539 ;; (ctree-set-calist-strictly
540 ;; 'mime-acting-condition
541 ;; '((type . text)(subtype . plain)(mode . "play")
542 ;; (method "tm-plain" nil 'file "" 'encoding 'mode 'name)
544 ;; (ctree-set-calist-strictly
545 ;; 'mime-acting-condition
546 ;; '((type . text)(subtype . plain)(mode . "print")
547 ;; (method "tm-plain" nil 'file "" 'encoding 'mode 'name)
549 ;; (ctree-set-calist-strictly
550 ;; 'mime-acting-condition
551 ;; '((type . text)(subtype . html)(mode . "play")
552 ;; (method "tm-html" nil 'file "" 'encoding 'mode 'name)
554 (ctree-set-calist-strictly
555 'mime-acting-condition
556 '((type . text)(subtype . x-rot13-47)(mode . "play")
557 (method . mime-method-to-display-caesar)
559 (ctree-set-calist-strictly
560 'mime-acting-condition
561 '((type . text)(subtype . x-rot13-47-48)(mode . "play")
562 (method . mime-method-to-display-caesar)
565 ;; (ctree-set-calist-strictly
566 ;; 'mime-acting-condition
567 ;; '((type . audio)(subtype . basic)(mode . "play")
568 ;; (method "tm-au" nil 'file "" 'encoding 'mode 'name)
571 ;; (ctree-set-calist-strictly
572 ;; 'mime-acting-condition
573 ;; '((type . image)(mode . "play")
574 ;; (method "tm-image" nil 'file "" 'encoding 'mode 'name)
576 ;; (ctree-set-calist-strictly
577 ;; 'mime-acting-condition
578 ;; '((type . image)(mode . "print")
579 ;; (method "tm-image" nil 'file "" 'encoding 'mode 'name)
582 ;; (ctree-set-calist-strictly
583 ;; 'mime-acting-condition
584 ;; '((type . video)(subtype . mpeg)(mode . "play")
585 ;; (method "tm-mpeg" nil 'file "" 'encoding 'mode 'name)
588 ;; (ctree-set-calist-strictly
589 ;; 'mime-acting-condition
590 ;; '((type . application)(subtype . postscript)(mode . "play")
591 ;; (method "tm-ps" nil 'file "" 'encoding 'mode 'name)
593 ;; (ctree-set-calist-strictly
594 ;; 'mime-acting-condition
595 ;; '((type . application)(subtype . postscript)(mode . "print")
596 ;; (method "tm-ps" nil 'file "" 'encoding 'mode 'name)
599 (ctree-set-calist-strictly
600 'mime-acting-condition
601 '((type . message)(subtype . rfc822)(mode . "play")
602 (method . mime-method-to-display-message/rfc822)
604 (ctree-set-calist-strictly
605 'mime-acting-condition
606 '((type . message)(subtype . partial)(mode . "play")
607 (method . mime-method-to-store-message/partial)
610 (ctree-set-calist-strictly
611 'mime-acting-condition
612 '((type . message)(subtype . external-body)
613 ("access-type" . "anon-ftp")
614 (method . mime-method-to-display-message/external-ftp)
617 (ctree-set-calist-strictly
618 'mime-acting-condition
619 '((type . application)(subtype . octet-stream)
620 (method . mime-method-to-save)
624 ;;; @ quitting method
627 (defvar mime-preview-quitting-method-alist
628 '((mime-show-message-mode
629 . mime-preview-quitting-method-for-mime-show-message-mode))
630 "Alist of major-mode vs. quitting-method of mime-view.")
632 (defvar mime-view-over-to-previous-method-alist nil)
633 (defvar mime-view-over-to-next-method-alist nil)
635 (defvar mime-view-show-summary-method nil
636 "Alist of major-mode vs. show-summary-method.")
639 ;;; @ following method
642 (defvar mime-view-following-method-alist nil
643 "Alist of major-mode vs. following-method of mime-view.")
645 (defvar mime-view-following-required-fields-list
652 ;; hack from Gnus 5.0.4.
654 (defvar mime-view-x-face-to-pbm-command
655 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm")
657 (defvar mime-view-x-face-command
658 (concat mime-view-x-face-to-pbm-command
660 "String to be executed to display an X-Face field.
661 The command will be executed in a sub-shell asynchronously.
662 The compressed face will be piped to this command.")
664 (defun mime-view-x-face-function ()
665 "Function to display X-Face field. You can redefine to customize."
666 ;; 1995/10/12 (c.f. tm-eng:130)
667 ;; fixed by Eric Ding <ericding@San-Jose.ate.slb.com>
669 (narrow-to-region (point-min) (re-search-forward "^$" nil t))
671 (goto-char (point-min))
672 (if (re-search-forward "^X-Face:[ \t]*" nil t)
673 (let ((beg (match-end 0))
674 (end (std11-field-end))
676 (call-process-region beg end "sh" nil 0 nil
677 "-c" mime-view-x-face-command)
684 (defvar mime-view-uuencode-encoding-name-list '("x-uue" "x-uuencode"))
690 (defvar mime-view-redisplay nil)
692 (defun mime-view-setup-buffers (&optional ctl encoding ibuf obuf)
698 (or mime-view-redisplay
699 (setq mime-raw-message-info (mime-parse-message ctl encoding))
701 (let ((message-info mime-raw-message-info)
702 (the-buf (current-buffer))
705 (setq obuf (concat "*Preview-" (buffer-name the-buf) "*")))
706 (set-buffer (get-buffer-create obuf))
707 (let ((inhibit-read-only t))
708 ;;(setq buffer-read-only nil)
711 (setq mime-raw-buffer the-buf)
712 (setq mime-preview-original-major-mode mode)
713 (setq major-mode 'mime-view-mode)
714 (setq mode-name "MIME-View")
715 (mime-view-display-entity message-info message-info
717 '((entity-button . invisible)
720 (set-buffer-modified-p nil)
722 (setq buffer-read-only t)
725 (setq mime-preview-buffer obuf)
728 (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 (content-type (mime-entity-content-type entity))
733 (encoding (mime-entity-encoding entity))
734 end-of-header e nb ne subj)
737 (setq end-of-header (if (re-search-forward "^$" nil t)
740 (if (> end-of-header end)
741 (setq end-of-header end)
744 (narrow-to-region start end)
745 (setq subj (eword-decode-string (mime-raw-get-subject entity)))
749 (ctree-match-calist mime-preview-condition
752 (make-mime-content-type 'text 'plain))
753 (list* (cons 'encoding encoding)
754 (cons 'major-mode major-mode)
758 (eq (cdr (assq 'entity-button situation)) 'invisible))
760 (eq (cdr (assq 'header situation)) 'visible))
761 (body-presentation-method
762 (cdr (assq 'body-presentation-method situation)))
763 (children (mime-entity-children entity)))
766 (narrow-to-region nb nb)
767 (or button-is-invisible
768 (if (mime-view-entity-button-visible-p entity message-info)
769 (mime-view-insert-entity-button entity message-info subj)
771 (if header-is-visible
773 (narrow-to-region (point)(point))
774 (insert-buffer-substring mime-raw-buffer start end-of-header)
775 (let ((f (cdr (assq mime-preview-original-major-mode
776 mime-view-content-header-filter-alist))))
779 (mime-view-default-content-header-filter)
781 (run-hooks 'mime-view-content-header-filter-hook)
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)
791 ((functionp body-presentation-method)
792 (funcall body-presentation-method entity situation)
795 (when button-is-invisible
796 (goto-char (point-max))
797 (mime-view-insert-entity-button entity message-info subj)
799 (or header-is-visible
801 (goto-char (point-max))
805 (setq ne (point-max))
807 (put-text-property nb ne 'mime-view-raw-buffer ibuf)
808 (put-text-property nb ne 'mime-view-entity entity)
811 (mime-preview-multipart/mixed entity situation)
815 (defun mime-raw-get-uu-filename ()
817 (if (re-search-forward "^begin [0-9]+ " nil t)
818 (if (looking-at ".+$")
819 (buffer-substring (match-beginning 0)(match-end 0))
822 (defun mime-raw-get-subject (entity)
823 (or (std11-find-field-body '("Content-Description" "Subject"))
824 (let ((ret (mime-entity-content-disposition entity)))
826 (setq ret (mime-content-disposition-filename ret))
827 (std11-strip-quoted-string ret)
829 (let ((ret (mime-entity-content-type entity)))
833 (let ((param (mime-content-type-parameters ret)))
834 (or (assoc "name" param)
835 (assoc "x-name" param))
837 (std11-strip-quoted-string ret)
839 (if (member (mime-entity-encoding entity)
840 mime-view-uuencode-encoding-name-list)
841 (mime-raw-get-uu-filename))
845 ;;; @ MIME viewer mode
848 (defconst mime-view-menu-title "MIME-View")
849 (defconst mime-view-menu-list
850 '((up "Move to upper entity" mime-preview-move-to-upper)
851 (previous "Move to previous entity" mime-preview-move-to-previous)
852 (next "Move to next entity" mime-preview-move-to-next)
853 (scroll-down "Scroll-down" mime-preview-scroll-down-entity)
854 (scroll-up "Scroll-up" mime-preview-scroll-up-entity)
855 (play "Play current entity" mime-preview-play-current-entity)
856 (extract "Extract current entity" mime-preview-extract-current-entity)
857 (print "Print current entity" mime-preview-print-current-entity)
858 (x-face "Show X Face" mime-preview-display-x-face)
860 "Menu for MIME Viewer")
862 (cond (running-xemacs
863 (defvar mime-view-xemacs-popup-menu
864 (cons mime-view-menu-title
867 (vector (nth 1 item)(nth 2 item) t)
869 mime-view-menu-list)))
870 (defun mime-view-xemacs-popup-menu (event)
871 "Popup the menu in the MIME Viewer buffer"
873 (select-window (event-window event))
874 (set-buffer (event-buffer event))
875 (popup-menu 'mime-view-xemacs-popup-menu))
876 (defvar mouse-button-2 'button2)
879 (defvar mouse-button-2 [mouse-2])
882 (defun mime-view-define-keymap (&optional default)
883 (let ((mime-view-mode-map (if (keymapp default)
884 (copy-keymap default)
887 (define-key mime-view-mode-map
888 "u" (function mime-preview-move-to-upper))
889 (define-key mime-view-mode-map
890 "p" (function mime-preview-move-to-previous))
891 (define-key mime-view-mode-map
892 "n" (function mime-preview-move-to-next))
893 (define-key mime-view-mode-map
894 "\e\t" (function mime-preview-move-to-previous))
895 (define-key mime-view-mode-map
896 "\t" (function mime-preview-move-to-next))
897 (define-key mime-view-mode-map
898 " " (function mime-preview-scroll-up-entity))
899 (define-key mime-view-mode-map
900 "\M- " (function mime-preview-scroll-down-entity))
901 (define-key mime-view-mode-map
902 "\177" (function mime-preview-scroll-down-entity))
903 (define-key mime-view-mode-map
904 "\C-m" (function mime-preview-next-line-entity))
905 (define-key mime-view-mode-map
906 "\C-\M-m" (function mime-preview-previous-line-entity))
907 (define-key mime-view-mode-map
908 "v" (function mime-preview-play-current-entity))
909 (define-key mime-view-mode-map
910 "e" (function mime-preview-extract-current-entity))
911 (define-key mime-view-mode-map
912 "\C-c\C-p" (function mime-preview-print-current-entity))
913 (define-key mime-view-mode-map
914 "a" (function mime-preview-follow-current-entity))
915 (define-key mime-view-mode-map
916 "q" (function mime-preview-quit))
917 (define-key mime-view-mode-map
918 "h" (function mime-preview-show-summary))
919 (define-key mime-view-mode-map
920 "\C-c\C-x" (function mime-preview-kill-buffer))
921 ;; (define-key mime-view-mode-map
922 ;; "<" (function beginning-of-buffer))
923 ;; (define-key mime-view-mode-map
924 ;; ">" (function end-of-buffer))
925 (define-key mime-view-mode-map
926 "?" (function describe-mode))
927 (define-key mime-view-mode-map
928 [tab] (function mime-preview-move-to-next))
929 (define-key mime-view-mode-map
930 [delete] (function mime-preview-scroll-down-entity))
931 (define-key mime-view-mode-map
932 [backspace] (function mime-preview-scroll-down-entity))
933 (if (functionp default)
934 (cond (running-xemacs
935 (set-keymap-default-binding mime-view-mode-map default)
938 (setq mime-view-mode-map
939 (append mime-view-mode-map (list (cons t default))))
942 (define-key mime-view-mode-map
943 mouse-button-2 (function mime-button-dispatcher))
945 (cond (running-xemacs
946 (define-key mime-view-mode-map
947 mouse-button-3 (function mime-view-xemacs-popup-menu))
949 ((>= emacs-major-version 19)
950 (define-key mime-view-mode-map [menu-bar mime-view]
951 (cons mime-view-menu-title
952 (make-sparse-keymap mime-view-menu-title)))
955 (define-key mime-view-mode-map
956 (vector 'menu-bar 'mime-view (car item))
957 (cons (nth 1 item)(nth 2 item))
960 (reverse mime-view-menu-list)
963 (use-local-map mime-view-mode-map)
964 (run-hooks 'mime-view-define-keymap-hook)
967 (defsubst mime-maybe-hide-echo-buffer ()
968 "Clear mime-echo buffer and delete window for it."
969 (let ((buf (get-buffer mime-echo-buffer-name)))
974 (let ((win (get-buffer-window buf)))
981 (defun mime-view-mode (&optional mother ctl encoding ibuf obuf
982 default-keymap-or-function)
983 "Major mode for viewing MIME message.
985 Here is a list of the standard keys for mime-view-mode.
990 u Move to upper content
991 p or M-TAB Move to previous content
992 n or TAB Move to next content
993 SPC Scroll up or move to next content
994 M-SPC or DEL Scroll down or move to previous content
995 RET Move to next line
996 M-RET Move to previous line
997 v Decode current content as `play mode'
998 e Decode current content as `extract mode'
999 C-c C-p Decode current content as `print mode'
1000 a Followup to current content.
1003 button-2 Move to point under the mouse cursor
1004 and decode current content as `play mode'
1007 (mime-maybe-hide-echo-buffer)
1008 (let ((ret (mime-view-setup-buffers ctl encoding ibuf obuf))
1009 (win-conf (current-window-configuration))
1012 (switch-to-buffer ret)
1013 (setq mime-preview-original-window-configuration win-conf)
1016 (setq mime-mother-buffer mother)
1018 (mime-view-define-keymap default-keymap-or-function)
1020 (next-single-property-change (point-min) 'mime-view-entity)))
1023 (goto-char (point-min))
1024 (search-forward "\n\n" nil t)
1026 (run-hooks 'mime-view-mode-hook)
1033 (autoload 'mime-preview-play-current-entity "mime-play"
1034 "Play current entity." t)
1036 (defun mime-preview-extract-current-entity ()
1037 "Extract current entity into file (maybe).
1038 It decodes current entity to call internal or external method as
1039 \"extract\" mode. The method is selected from variable
1040 `mime-acting-condition'."
1042 (mime-preview-play-current-entity "extract")
1045 (defun mime-preview-print-current-entity ()
1046 "Print current entity (maybe).
1047 It decodes current entity to call internal or external method as
1048 \"print\" mode. The method is selected from variable
1049 `mime-acting-condition'."
1051 (mime-preview-play-current-entity "print")
1058 (defun mime-preview-original-major-mode ()
1059 "Return major-mode of original buffer.
1060 If a current buffer has mime-mother-buffer, return original major-mode
1061 of the mother-buffer."
1062 (if mime-mother-buffer
1064 (set-buffer mime-mother-buffer)
1065 (mime-preview-original-major-mode)
1067 mime-preview-original-major-mode))
1069 (defun mime-preview-follow-current-entity ()
1070 "Write follow message to current entity.
1071 It calls following-method selected from variable
1072 `mime-view-following-method-alist'."
1075 (while (null (setq entity
1076 (get-text-property (point) 'mime-view-entity)))
1080 (previous-single-property-change (point) 'mime-view-entity))
1082 (entity-node-id (mime-entity-node-id entity))
1083 (len (length entity-node-id))
1087 (if (eq (next-single-property-change (point-min)
1093 ((eq (next-single-property-change p-beg 'mime-view-entity)
1095 (setq p-beg (point))
1097 (setq p-end (next-single-property-change p-beg 'mime-view-entity))
1099 (setq p-end (point-max))
1101 ((null entity-node-id)
1102 (setq p-end (point-max))
1110 (next-single-property-change
1111 (point) 'mime-view-entity))
1113 (let ((rc (mime-entity-node-id
1114 (get-text-property (point)
1115 'mime-view-entity))))
1116 (or (equal entity-node-id
1117 (nthcdr (- (length rc) len) rc))
1122 (setq p-end (point-max))
1125 (let* ((mode (mime-preview-original-major-mode))
1127 (format "%s-%s" (buffer-name) (reverse entity-node-id)))
1129 (the-buf (current-buffer))
1130 (a-buf mime-raw-buffer)
1133 (set-buffer (setq new-buf (get-buffer-create new-name)))
1135 (insert-buffer-substring the-buf p-beg p-end)
1136 (goto-char (point-min))
1137 (let ((entity-node-id (mime-entity-node-id entity)) ci str)
1145 (mime-raw-find-entity-from-node-id entity-node-id))
1148 (mime-entity-point-min ci)
1149 (mime-entity-point-max ci)
1151 (std11-header-string-except
1153 (apply (function regexp-or) fields)
1156 (eq (mime-entity-media-type ci) 'message)
1157 (eq (mime-entity-media-subtype ci) 'rfc822))
1163 (setq fields (std11-collect-field-names)
1164 entity-node-id (cdr entity-node-id))
1167 (let ((rest mime-view-following-required-fields-list))
1169 (let ((field-name (car rest)))
1170 (or (std11-field-body field-name)
1176 (set-buffer the-buf)
1177 (set-buffer mime-mother-buffer)
1178 (set-buffer mime-raw-buffer)
1179 (std11-field-body field-name)
1183 (setq rest (cdr rest))
1185 (eword-decode-header)
1187 (let ((f (cdr (assq mode mime-view-following-method-alist))))
1192 "Sorry, following method for %s is not implemented yet."
1201 (defun mime-preview-display-x-face ()
1203 (save-window-excursion
1204 (set-buffer mime-raw-buffer)
1205 (mime-view-x-face-function)
1212 (defun mime-preview-move-to-upper ()
1213 "Move to upper entity.
1214 If there is no upper entity, call function `mime-preview-quit'."
1217 (while (null (setq cinfo
1218 (get-text-property (point) 'mime-view-entity)))
1221 (let ((r (mime-raw-find-entity-from-node-id
1222 (cdr (mime-entity-node-id cinfo))
1223 (get-text-property 1 'mime-view-entity)))
1226 (while (setq point (previous-single-property-change
1227 (point) 'mime-view-entity))
1229 (if (eq r (get-text-property (point) 'mime-view-entity))
1236 (defun mime-preview-move-to-previous ()
1237 "Move to previous entity.
1238 If there is no previous entity, it calls function registered in
1239 variable `mime-view-over-to-previous-method-alist'."
1241 (while (null (get-text-property (point) 'mime-view-entity))
1244 (let ((point (previous-single-property-change (point) 'mime-view-entity)))
1246 (if (get-text-property (1- point) 'mime-view-entity)
1248 (goto-char (1- point))
1249 (mime-preview-move-to-previous)
1251 (let ((f (assq mime-preview-original-major-mode
1252 mime-view-over-to-previous-method-alist)))
1258 (defun mime-preview-move-to-next ()
1259 "Move to next entity.
1260 If there is no previous entity, it calls function registered in
1261 variable `mime-view-over-to-next-method-alist'."
1263 (while (null (get-text-property (point) 'mime-view-entity))
1266 (let ((point (next-single-property-change (point) 'mime-view-entity)))
1270 (if (null (get-text-property point 'mime-view-entity))
1271 (mime-preview-move-to-next)
1273 (let ((f (assq mime-preview-original-major-mode
1274 mime-view-over-to-next-method-alist)))
1280 (defun mime-preview-scroll-up-entity (&optional h)
1281 "Scroll up current entity.
1282 If reached to (point-max), it calls function registered in variable
1283 `mime-view-over-to-next-method-alist'."
1286 (setq h (1- (window-height)))
1288 (if (= (point) (point-max))
1289 (let ((f (assq mime-preview-original-major-mode
1290 mime-view-over-to-next-method-alist)))
1295 (or (next-single-property-change (point) 'mime-view-entity)
1298 (if (> (point) point)
1303 (defun mime-preview-scroll-down-entity (&optional h)
1304 "Scroll down current entity.
1305 If reached to (point-min), it calls function registered in variable
1306 `mime-view-over-to-previous-method-alist'."
1309 (setq h (1- (window-height)))
1311 (if (= (point) (point-min))
1312 (let ((f (assq mime-preview-original-major-mode
1313 mime-view-over-to-previous-method-alist)))
1322 (previous-single-property-change (point)
1328 (setq point (point-min))
1330 (forward-line (- h))
1331 (if (< (point) point)
1335 (defun mime-preview-next-line-entity ()
1337 (mime-preview-scroll-up-entity 1)
1340 (defun mime-preview-previous-line-entity ()
1342 (mime-preview-scroll-down-entity 1)
1349 (defun mime-preview-quit ()
1350 "Quit from MIME-preview buffer.
1351 It calls function registered in variable
1352 `mime-preview-quitting-method-alist'."
1354 (let ((r (assq mime-preview-original-major-mode
1355 mime-preview-quitting-method-alist)))
1360 (defun mime-preview-show-summary ()
1362 It calls function registered in variable
1363 `mime-view-show-summary-method'."
1365 (let ((r (assq mime-preview-original-major-mode
1366 mime-view-show-summary-method)))
1371 (defun mime-preview-kill-buffer ()
1373 (kill-buffer (current-buffer))
1380 (provide 'mime-view)
1382 (run-hooks 'mime-view-load-hook)
1384 ;;; mime-view.el ends here