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 (params (mime-entity-parameters message-info))
652 (encoding (mime-entity-encoding message-info))
653 end-of-header e nb ne subj)
656 (setq end-of-header (if (re-search-forward "^$" nil t)
659 (if (> end-of-header end)
660 (setq end-of-header end)
663 (narrow-to-region start end)
666 (mime-raw-get-subject params encoding)))
670 (narrow-to-region nb nb)
671 ;; Insert message-header
673 (narrow-to-region (point)(point))
674 (insert-buffer-substring mime-raw-buffer start end-of-header)
675 (let ((f (cdr (assq mime-preview-original-major-mode
676 mime-view-content-header-filter-alist))))
679 (mime-view-default-content-header-filter)
681 (run-hooks 'mime-view-content-header-filter-hook)
684 (ctree-match-calist mime-preview-condition
685 (list* (cons 'type media-type)
686 (cons 'subtype media-subtype)
687 (cons 'encoding encoding)
688 (cons 'major-mode major-mode)
691 (cdr (assq 'message-button situation)))
692 (body-presentation-method
693 (cdr (assq 'body-presentation-method situation))))
695 (goto-char (point-max))
696 (mime-view-insert-entity-button message-info message-info subj)
698 (cond ((eq body-presentation-method 'with-filter)
699 (let ((body-filter (cdr (assq 'body-filter situation))))
701 (narrow-to-region (point-max)(point-max))
702 (insert-buffer-substring mime-raw-buffer end-of-header end)
703 (funcall body-filter situation)
705 ((functionp body-presentation-method)
706 (funcall body-presentation-method situation)
708 ((null (mime-entity-children message-info))
709 (goto-char (point-max))
710 (mime-view-insert-entity-button message-info message-info subj)
713 (setq ne (point-max))
715 (put-text-property nb ne 'mime-view-raw-buffer ibuf)
716 (put-text-property nb ne 'mime-view-entity message-info)
718 (let ((children (mime-entity-children message-info)))
720 (mime-view-display-entity (car children) message-info ibuf obuf)
721 (setq children (cdr children))
724 (defun mime-view-display-entity (entity message-info ibuf obuf)
725 (let* ((start (mime-entity-point-min entity))
726 (end (mime-entity-point-max entity))
727 (media-type (mime-entity-media-type entity))
728 (media-subtype (mime-entity-media-subtype entity))
729 (params (mime-entity-parameters entity))
730 (encoding (mime-entity-encoding entity))
731 end-of-header e nb ne subj)
734 (setq end-of-header (if (re-search-forward "^$" nil t)
737 (if (> end-of-header end)
738 (setq end-of-header end)
741 (narrow-to-region start end)
744 (mime-raw-get-subject params encoding)))
748 (narrow-to-region nb nb)
749 (if (mime-view-entity-button-visible-p entity message-info)
750 (mime-view-insert-entity-button entity message-info subj)
752 (if (mime-view-header-visible-p entity message-info)
754 (narrow-to-region (point)(point))
755 (insert-buffer-substring mime-raw-buffer start end-of-header)
756 (let ((f (cdr (assq mime-preview-original-major-mode
757 mime-view-content-header-filter-alist))))
760 (mime-view-default-content-header-filter)
762 (run-hooks 'mime-view-content-header-filter-hook)
765 (ctree-match-calist mime-preview-condition
766 (list* (cons 'type media-type)
767 (cons 'subtype media-subtype)
768 (cons 'encoding encoding)
769 (cons 'major-mode major-mode)
771 (body-presentation-method
772 (cdr (assq 'body-presentation-method situation))))
773 (cond ((eq body-presentation-method 'with-filter)
774 (let ((body-filter (cdr (assq 'body-filter situation))))
776 (narrow-to-region (point-max)(point-max))
777 (insert-buffer-substring mime-raw-buffer end-of-header end)
778 (funcall body-filter situation)
780 ((functionp body-presentation-method)
781 (funcall body-presentation-method situation)
783 (when (mime-view-entity-separator-visible-p entity message-info)
784 (goto-char (point-max))
787 (setq ne (point-max))
789 (put-text-property nb ne 'mime-view-raw-buffer ibuf)
790 (put-text-property nb ne 'mime-view-entity entity)
792 (let ((children (mime-entity-children entity)))
794 (mime-view-display-entity (car children) message-info ibuf obuf)
795 (setq children (cdr children))
798 (defun mime-raw-get-uu-filename (param &optional encoding)
799 (if (member (or encoding
800 (cdr (assq 'encoding param))
802 mime-view-uuencode-encoding-name-list)
804 (or (if (re-search-forward "^begin [0-9]+ " nil t)
805 (if (looking-at ".+$")
806 (buffer-substring (match-beginning 0)(match-end 0))
811 (defun mime-raw-get-subject (param &optional encoding)
812 (or (std11-find-field-body '("Content-Description" "Subject"))
814 (if (or (and (setq ret (mime/Content-Disposition))
815 (setq ret (assoc "filename" (cdr ret)))
817 (setq ret (assoc "name" param))
818 (setq ret (assoc "x-name" param))
820 (std11-strip-quoted-string (cdr ret))
822 (mime-raw-get-uu-filename param encoding)
826 ;;; @ MIME viewer mode
829 (defconst mime-view-menu-title "MIME-View")
830 (defconst mime-view-menu-list
831 '((up "Move to upper entity" mime-preview-move-to-upper)
832 (previous "Move to previous entity" mime-preview-move-to-previous)
833 (next "Move to next entity" mime-preview-move-to-next)
834 (scroll-down "Scroll-down" mime-preview-scroll-down-entity)
835 (scroll-up "Scroll-up" mime-preview-scroll-up-entity)
836 (play "Play current entity" mime-preview-play-current-entity)
837 (extract "Extract current entity" mime-preview-extract-current-entity)
838 (print "Print current entity" mime-preview-print-current-entity)
839 (x-face "Show X Face" mime-preview-display-x-face)
841 "Menu for MIME Viewer")
843 (cond (running-xemacs
844 (defvar mime-view-xemacs-popup-menu
845 (cons mime-view-menu-title
848 (vector (nth 1 item)(nth 2 item) t)
850 mime-view-menu-list)))
851 (defun mime-view-xemacs-popup-menu (event)
852 "Popup the menu in the MIME Viewer buffer"
854 (select-window (event-window event))
855 (set-buffer (event-buffer event))
856 (popup-menu 'mime-view-xemacs-popup-menu))
857 (defvar mouse-button-2 'button2)
860 (defvar mouse-button-2 [mouse-2])
863 (defun mime-view-define-keymap (&optional default)
864 (let ((mime-view-mode-map (if (keymapp default)
865 (copy-keymap default)
868 (define-key mime-view-mode-map
869 "u" (function mime-preview-move-to-upper))
870 (define-key mime-view-mode-map
871 "p" (function mime-preview-move-to-previous))
872 (define-key mime-view-mode-map
873 "n" (function mime-preview-move-to-next))
874 (define-key mime-view-mode-map
875 "\e\t" (function mime-preview-move-to-previous))
876 (define-key mime-view-mode-map
877 "\t" (function mime-preview-move-to-next))
878 (define-key mime-view-mode-map
879 " " (function mime-preview-scroll-up-entity))
880 (define-key mime-view-mode-map
881 "\M- " (function mime-preview-scroll-down-entity))
882 (define-key mime-view-mode-map
883 "\177" (function mime-preview-scroll-down-entity))
884 (define-key mime-view-mode-map
885 "\C-m" (function mime-preview-next-line-entity))
886 (define-key mime-view-mode-map
887 "\C-\M-m" (function mime-preview-previous-line-entity))
888 (define-key mime-view-mode-map
889 "v" (function mime-preview-play-current-entity))
890 (define-key mime-view-mode-map
891 "e" (function mime-preview-extract-current-entity))
892 (define-key mime-view-mode-map
893 "\C-c\C-p" (function mime-preview-print-current-entity))
894 (define-key mime-view-mode-map
895 "a" (function mime-preview-follow-current-entity))
896 (define-key mime-view-mode-map
897 "q" (function mime-preview-quit))
898 (define-key mime-view-mode-map
899 "h" (function mime-preview-show-summary))
900 (define-key mime-view-mode-map
901 "\C-c\C-x" (function mime-preview-kill-buffer))
902 ;; (define-key mime-view-mode-map
903 ;; "<" (function beginning-of-buffer))
904 ;; (define-key mime-view-mode-map
905 ;; ">" (function end-of-buffer))
906 (define-key mime-view-mode-map
907 "?" (function describe-mode))
908 (define-key mime-view-mode-map
909 [tab] (function mime-preview-move-to-next))
910 (define-key mime-view-mode-map
911 [delete] (function mime-preview-scroll-down-entity))
912 (define-key mime-view-mode-map
913 [backspace] (function mime-preview-scroll-down-entity))
914 (if (functionp default)
915 (cond (running-xemacs
916 (set-keymap-default-binding mime-view-mode-map default)
919 (setq mime-view-mode-map
920 (append mime-view-mode-map (list (cons t default))))
923 (define-key mime-view-mode-map
924 mouse-button-2 (function mime-button-dispatcher))
926 (cond (running-xemacs
927 (define-key mime-view-mode-map
928 mouse-button-3 (function mime-view-xemacs-popup-menu))
930 ((>= emacs-major-version 19)
931 (define-key mime-view-mode-map [menu-bar mime-view]
932 (cons mime-view-menu-title
933 (make-sparse-keymap mime-view-menu-title)))
936 (define-key mime-view-mode-map
937 (vector 'menu-bar 'mime-view (car item))
938 (cons (nth 1 item)(nth 2 item))
941 (reverse mime-view-menu-list)
944 (use-local-map mime-view-mode-map)
945 (run-hooks 'mime-view-define-keymap-hook)
948 (defsubst mime-maybe-hide-echo-buffer ()
949 "Clear mime-echo buffer and delete window for it."
950 (let ((buf (get-buffer mime-echo-buffer-name)))
955 (let ((win (get-buffer-window buf)))
962 (defun mime-view-mode (&optional mother ctl encoding ibuf obuf
963 default-keymap-or-function)
964 "Major mode for viewing MIME message.
966 Here is a list of the standard keys for mime-view-mode.
971 u Move to upper content
972 p or M-TAB Move to previous content
973 n or TAB Move to next content
974 SPC Scroll up or move to next content
975 M-SPC or DEL Scroll down or move to previous content
976 RET Move to next line
977 M-RET Move to previous line
978 v Decode current content as `play mode'
979 e Decode current content as `extract mode'
980 C-c C-p Decode current content as `print mode'
981 a Followup to current content.
984 button-2 Move to point under the mouse cursor
985 and decode current content as `play mode'
988 (mime-maybe-hide-echo-buffer)
989 (let ((ret (mime-view-setup-buffers ctl encoding ibuf obuf))
990 (win-conf (current-window-configuration))
993 (switch-to-buffer ret)
994 (setq mime-preview-original-window-configuration win-conf)
997 (setq mime-mother-buffer mother)
999 (mime-view-define-keymap default-keymap-or-function)
1001 (next-single-property-change (point-min) 'mime-view-entity)))
1004 (goto-char (point-min))
1005 (search-forward "\n\n" nil t)
1007 (run-hooks 'mime-view-mode-hook)
1014 (autoload 'mime-preview-play-current-entity "mime-play"
1015 "Play current entity." t)
1017 (defun mime-preview-extract-current-entity ()
1018 "Extract current entity into file (maybe).
1019 It decodes current entity to call internal or external method as
1020 \"extract\" mode. The method is selected from variable
1021 `mime-acting-condition'."
1023 (mime-preview-play-current-entity "extract")
1026 (defun mime-preview-print-current-entity ()
1027 "Print current entity (maybe).
1028 It decodes current entity to call internal or external method as
1029 \"print\" mode. The method is selected from variable
1030 `mime-acting-condition'."
1032 (mime-preview-play-current-entity "print")
1039 (defun mime-preview-original-major-mode ()
1040 "Return major-mode of original buffer.
1041 If a current buffer has mime-mother-buffer, return original major-mode
1042 of the mother-buffer."
1043 (if mime-mother-buffer
1045 (set-buffer mime-mother-buffer)
1046 (mime-preview-original-major-mode)
1048 mime-preview-original-major-mode))
1050 (defun mime-preview-follow-current-entity ()
1051 "Write follow message to current entity.
1052 It calls following-method selected from variable
1053 `mime-view-following-method-alist'."
1055 (let ((message-info (get-text-property (point-min) 'mime-view-entity))
1057 (while (null (setq entity
1058 (get-text-property (point) 'mime-view-entity)))
1062 (previous-single-property-change (point) 'mime-view-entity))
1064 (entity-node-id (mime-entity-node-id entity))
1065 (len (length entity-node-id))
1069 (if (eq (next-single-property-change (point-min)
1075 ((eq (next-single-property-change p-beg 'mime-view-entity)
1077 (setq p-beg (point))
1079 (setq p-end (next-single-property-change p-beg 'mime-view-entity))
1081 (setq p-end (point-max))
1083 ((null entity-node-id)
1084 (setq p-end (point-max))
1092 (next-single-property-change
1093 (point) 'mime-view-entity))
1095 (let ((rc (mime-entity-node-id
1096 (get-text-property (point)
1097 'mime-view-entity))))
1098 (or (equal entity-node-id
1099 (nthcdr (- (length rc) len) rc))
1104 (setq p-end (point-max))
1107 (let* ((mode (mime-preview-original-major-mode))
1109 (format "%s-%s" (buffer-name) (reverse entity-node-id)))
1111 (the-buf (current-buffer))
1112 (a-buf mime-raw-buffer)
1115 (set-buffer (setq new-buf (get-buffer-create new-name)))
1117 (insert-buffer-substring the-buf p-beg p-end)
1118 (goto-char (point-min))
1119 (if (mime-view-header-visible-p entity message-info)
1120 (delete-region (goto-char (point-min))
1121 (if (re-search-forward "^$" nil t)
1125 (goto-char (point-min))
1127 (goto-char (point-min))
1128 (let ((entity-node-id (mime-entity-node-id entity)) ci str)
1136 (mime-raw-find-entity-from-node-id entity-node-id))
1139 (mime-entity-point-min ci)
1140 (mime-entity-point-max ci)
1142 (std11-header-string-except
1144 (apply (function regexp-or) fields)
1147 (eq (mime-entity-media-type ci) 'message)
1148 (eq (mime-entity-media-subtype ci) 'rfc822))
1154 (setq fields (std11-collect-field-names)
1155 entity-node-id (cdr entity-node-id))
1158 (let ((rest mime-view-following-required-fields-list))
1160 (let ((field-name (car rest)))
1161 (or (std11-field-body field-name)
1167 (set-buffer the-buf)
1168 (set-buffer mime-mother-buffer)
1169 (set-buffer mime-raw-buffer)
1170 (std11-field-body field-name)
1174 (setq rest (cdr rest))
1176 (eword-decode-header)
1178 (let ((f (cdr (assq mode mime-view-following-method-alist))))
1183 "Sorry, following method for %s is not implemented yet."
1192 (defun mime-preview-display-x-face ()
1194 (save-window-excursion
1195 (set-buffer mime-raw-buffer)
1196 (mime-view-x-face-function)
1203 (defun mime-preview-move-to-upper ()
1204 "Move to upper entity.
1205 If there is no upper entity, call function `mime-preview-quit'."
1208 (while (null (setq cinfo
1209 (get-text-property (point) 'mime-view-entity)))
1212 (let ((r (mime-raw-find-entity-from-node-id
1213 (cdr (mime-entity-node-id cinfo))
1214 (get-text-property 1 'mime-view-entity)))
1217 (while (setq point (previous-single-property-change
1218 (point) 'mime-view-entity))
1220 (if (eq r (get-text-property (point) 'mime-view-entity))
1227 (defun mime-preview-move-to-previous ()
1228 "Move to previous entity.
1229 If there is no previous entity, it calls function registered in
1230 variable `mime-view-over-to-previous-method-alist'."
1232 (while (null (get-text-property (point) 'mime-view-entity))
1236 (previous-single-property-change (point) 'mime-view-entity)))
1239 (let ((f (assq mime-preview-original-major-mode
1240 mime-view-over-to-previous-method-alist)))
1246 (defun mime-preview-move-to-next ()
1247 "Move to next entity.
1248 If there is no previous entity, it calls function registered in
1249 variable `mime-view-over-to-next-method-alist'."
1251 (let ((point (next-single-property-change (point) 'mime-view-entity)))
1254 (let ((f (assq mime-preview-original-major-mode
1255 mime-view-over-to-next-method-alist)))
1261 (defun mime-preview-scroll-up-entity (&optional h)
1262 "Scroll up current entity.
1263 If reached to (point-max), it calls function registered in variable
1264 `mime-view-over-to-next-method-alist'."
1267 (setq h (1- (window-height)))
1269 (if (= (point) (point-max))
1270 (let ((f (assq mime-preview-original-major-mode
1271 mime-view-over-to-next-method-alist)))
1276 (or (next-single-property-change (point) 'mime-view-entity)
1279 (if (> (point) point)
1284 (defun mime-preview-scroll-down-entity (&optional h)
1285 "Scroll down current entity.
1286 If reached to (point-min), it calls function registered in variable
1287 `mime-view-over-to-previous-method-alist'."
1290 (setq h (1- (window-height)))
1292 (if (= (point) (point-min))
1293 (let ((f (assq mime-preview-original-major-mode
1294 mime-view-over-to-previous-method-alist)))
1301 (while (> (point) 1)
1303 (previous-single-property-change (point)
1309 (setq point (point-min))
1311 (forward-line (- h))
1312 (if (< (point) point)
1316 (defun mime-preview-next-line-entity ()
1318 (mime-preview-scroll-up-entity 1)
1321 (defun mime-preview-previous-line-entity ()
1323 (mime-preview-scroll-down-entity 1)
1330 (defun mime-preview-quit ()
1331 "Quit from MIME-preview buffer.
1332 It calls function registered in variable
1333 `mime-preview-quitting-method-alist'."
1335 (let ((r (assq mime-preview-original-major-mode
1336 mime-preview-quitting-method-alist)))
1341 (defun mime-preview-show-summary ()
1343 It calls function registered in variable
1344 `mime-view-show-summary-method'."
1346 (let ((r (assq mime-preview-original-major-mode
1347 mime-view-show-summary-method)))
1352 (defun mime-preview-kill-buffer ()
1354 (kill-buffer (current-buffer))
1361 (provide 'mime-view)
1363 (run-hooks 'mime-view-load-hook)
1365 ;;; mime-view.el ends here