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)
358 (ctree-set-calist-strictly
359 'mime-preview-condition '((type . application)(subtype . x-latex)
362 (ctree-set-calist-strictly
363 'mime-preview-condition '((type . application)(subtype . x-selection)
366 (ctree-set-calist-strictly
367 'mime-preview-condition '((type . application)(subtype . x-comment)
370 (ctree-set-calist-strictly
371 'mime-preview-condition '((type . message)(subtype . delivery-status)
374 (ctree-set-calist-strictly
375 'mime-preview-condition '((body . visible)
376 (body-presentation-method . with-filter)
377 (body-filter . mime-preview-filter-for-text/plain)))
379 (ctree-set-calist-strictly
380 'mime-preview-condition '((type . nil)
382 (body-presentation-method . with-filter)
383 (body-filter . mime-preview-filter-for-text/plain)))
385 (ctree-set-calist-strictly
386 'mime-preview-condition '((type . text)(subtype . enriched)
388 (body-presentation-method . with-filter)
390 . mime-preview-filter-for-text/enriched)))
392 (ctree-set-calist-strictly
393 'mime-preview-condition '((type . text)(subtype . richtext)
395 (body-presentation-method . with-filter)
397 . mime-preview-filter-for-text/richtext)))
399 (ctree-set-calist-strictly
400 'mime-preview-condition '((type . text)(subtype . t)
402 (body-presentation-method . with-filter)
403 (body-filter . mime-preview-filter-for-text/plain)))
405 (ctree-set-calist-strictly
406 'mime-preview-condition '((type . message)(subtype . partial)
407 (body-presentation-method
408 . mime-view-insert-message/partial-button)))
410 (defun mime-view-body-visible-p (entity message-info)
411 "Return non-nil if body of ENTITY is visible."
412 (ctree-match-calist mime-preview-condition
413 (list* (cons 'type (mime-entity-media-type entity))
414 (cons 'subtype (mime-entity-media-subtype entity))
415 (cons 'encoding (mime-entity-encoding entity))
416 (cons 'major-mode major-mode)
417 (mime-entity-parameters entity))))
420 ;;; @@@ entity filter
423 (autoload 'mime-preview-filter-for-text/plain "mime-text")
424 (autoload 'mime-preview-filter-for-text/enriched "mime-text")
425 (autoload 'mime-preview-filter-for-text/richtext "mime-text")
427 (defvar mime-text-decoder-alist
428 '((mime-show-message-mode . mime-text-decode-buffer)
429 (mime-temp-message-mode . mime-text-decode-buffer)
430 (t . mime-text-decode-buffer-maybe)
432 "Alist of major-mode vs. mime-text-decoder.
433 Each element looks like (SYMBOL . FUNCTION). SYMBOL is major-mode or
436 Specification of FUNCTION is described in DOC-string of variable
439 This value is overridden by buffer local variable `mime-text-decoder'
443 (defvar mime-view-announcement-for-message/partial
444 (if (and (>= emacs-major-version 19) window-system)
446 \[[ This is message/partial style split message. ]]
447 \[[ Please press `v' key in this buffer ]]
448 \[[ or click here by mouse button-2. ]]"
450 \[[ This is message/partial style split message. ]]
451 \[[ Please press `v' key in this buffer. ]]"
454 (defun mime-view-insert-message/partial-button (&optional situation)
456 (goto-char (point-max))
457 (if (not (search-backward "\n\n" nil t))
460 (goto-char (point-max))
461 (narrow-to-region (point-max)(point-max))
462 (insert mime-view-announcement-for-message/partial)
463 (mime-add-button (point-min)(point-max)
464 #'mime-preview-play-current-entity)
468 ;;; @@ entity separator
471 (defun mime-view-entity-separator-visible-p (entity message-info)
472 "Return non-nil if separator is needed for ENTITY."
473 (and (not (mime-view-header-visible-p entity message-info))
474 (not (mime-view-body-visible-p entity message-info))))
477 ;;; @ acting-condition
480 (defvar mime-acting-condition
481 '(((type . text)(subtype . plain)
482 (method "tm-plain" nil 'file "" 'encoding 'mode 'name)
483 (mode "play" "print")
485 ((type . text)(subtype . html)
486 (method "tm-html" nil 'file "" 'encoding 'mode 'name)
489 ((type . text)(subtype . x-rot13-47)
490 (method . mime-method-to-display-caesar)
493 ((type . text)(subtype . x-rot13-47-48)
494 (method . mime-method-to-display-caesar)
498 ((type . audio)(subtype . basic)
499 (method "tm-au" nil 'file "" 'encoding 'mode 'name)
504 (method "tm-image" nil 'file "" 'encoding 'mode 'name)
505 (mode "play" "print")
508 ((type . video)(subtype . mpeg)
509 (method "tm-mpeg" nil 'file "" 'encoding 'mode 'name)
513 ((type . application)(subtype . postscript)
514 (method "tm-ps" nil 'file "" 'encoding 'mode 'name)
515 (mode "play" "print")
517 ((type . application)(subtype . octet-stream)
518 (method . mime-method-to-save)(mode "play" "print")
521 ((type . message)(subtype . external-body)
522 ("access-type" . "anon-ftp")
523 (method . mime-method-to-display-message/external-ftp)
525 ((type . message)(subtype . rfc822)
526 (method . mime-method-to-display-message/rfc822)
529 ((type . message)(subtype . partial)
530 (method . mime-method-to-store-message/partial)
534 ((method "metamail" t "-m" "tm" "-x" "-d" "-z" "-e" 'file)
537 ((method . mime-method-to-save)(mode . "extract"))
541 ;;; @ quitting method
544 (defvar mime-preview-quitting-method-alist
545 '((mime-show-message-mode
546 . mime-preview-quitting-method-for-mime-show-message-mode))
547 "Alist of major-mode vs. quitting-method of mime-view.")
549 (defvar mime-view-over-to-previous-method-alist nil)
550 (defvar mime-view-over-to-next-method-alist nil)
552 (defvar mime-view-show-summary-method nil
553 "Alist of major-mode vs. show-summary-method.")
556 ;;; @ following method
559 (defvar mime-view-following-method-alist nil
560 "Alist of major-mode vs. following-method of mime-view.")
562 (defvar mime-view-following-required-fields-list
569 ;; hack from Gnus 5.0.4.
571 (defvar mime-view-x-face-to-pbm-command
572 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm")
574 (defvar mime-view-x-face-command
575 (concat mime-view-x-face-to-pbm-command
577 "String to be executed to display an X-Face field.
578 The command will be executed in a sub-shell asynchronously.
579 The compressed face will be piped to this command.")
581 (defun mime-view-x-face-function ()
582 "Function to display X-Face field. You can redefine to customize."
583 ;; 1995/10/12 (c.f. tm-eng:130)
584 ;; fixed by Eric Ding <ericding@San-Jose.ate.slb.com>
586 (narrow-to-region (point-min) (re-search-forward "^$" nil t))
588 (goto-char (point-min))
589 (if (re-search-forward "^X-Face:[ \t]*" nil t)
590 (let ((beg (match-end 0))
591 (end (std11-field-end))
593 (call-process-region beg end "sh" nil 0 nil
594 "-c" mime-view-x-face-command)
601 (defvar mime-view-uuencode-encoding-name-list '("x-uue" "x-uuencode"))
603 (defvar mime-raw-buffer-coding-system-alist
604 `((t . ,(mime-charset-to-coding-system default-mime-charset)))
605 "Alist of major-mode vs. corresponding coding-system of `mime-raw-buffer'.")
611 (defvar mime-view-redisplay nil)
613 (defun mime-view-setup-buffers (&optional ctl encoding ibuf obuf)
619 (or mime-view-redisplay
620 (setq mime-raw-message-info (mime-parse-message ctl encoding))
622 (let ((message-info mime-raw-message-info)
623 (the-buf (current-buffer))
626 (setq obuf (concat "*Preview-" (buffer-name the-buf) "*")))
627 (set-buffer (get-buffer-create obuf))
628 (let ((inhibit-read-only t))
629 ;;(setq buffer-read-only nil)
632 (setq mime-raw-buffer the-buf)
633 (setq mime-preview-original-major-mode mode)
634 (setq major-mode 'mime-view-mode)
635 (setq mode-name "MIME-View")
636 (mime-view-display-message message-info the-buf obuf)
637 (set-buffer-modified-p nil)
639 (setq buffer-read-only t)
642 (setq mime-preview-buffer obuf)
645 (defun mime-view-display-message (message-info ibuf obuf)
646 (let* ((start (mime-entity-point-min message-info))
647 (end (mime-entity-point-max message-info))
648 (media-type (mime-entity-media-type message-info))
649 (media-subtype (mime-entity-media-subtype message-info))
650 (params (mime-entity-parameters message-info))
651 (encoding (mime-entity-encoding message-info))
652 end-of-header e nb ne subj)
655 (setq end-of-header (if (re-search-forward "^$" nil t)
658 (if (> end-of-header end)
659 (setq end-of-header end)
662 (narrow-to-region start end)
665 (mime-raw-get-subject params encoding)))
669 (narrow-to-region nb nb)
670 ;; Insert message-header
672 (narrow-to-region (point)(point))
673 (insert-buffer-substring mime-raw-buffer start end-of-header)
674 (let ((f (cdr (assq mime-preview-original-major-mode
675 mime-view-content-header-filter-alist))))
678 (mime-view-default-content-header-filter)
680 (run-hooks 'mime-view-content-header-filter-hook)
683 (ctree-match-calist mime-preview-condition
684 (list* (cons 'type media-type)
685 (cons 'subtype media-subtype)
686 (cons 'encoding encoding)
687 (cons 'major-mode major-mode)
690 (cdr (assq 'message-button situation)))
691 (body-presentation-method
692 (cdr (assq 'body-presentation-method situation))))
694 (goto-char (point-max))
695 (mime-view-insert-entity-button message-info message-info subj)
697 (cond ((eq body-presentation-method 'with-filter)
698 (let ((body-filter (cdr (assq 'body-filter situation))))
700 (narrow-to-region (point-max)(point-max))
701 (insert-buffer-substring mime-raw-buffer end-of-header end)
702 (funcall body-filter situation)
704 ((functionp body-presentation-method)
705 (funcall body-presentation-method situation)
707 ((null (mime-entity-children message-info))
708 (goto-char (point-max))
709 (mime-view-insert-entity-button message-info message-info subj)
712 (setq ne (point-max))
714 (put-text-property nb ne 'mime-view-raw-buffer ibuf)
715 (put-text-property nb ne 'mime-view-entity message-info)
717 (let ((children (mime-entity-children message-info)))
719 (mime-view-display-entity (car children) message-info ibuf obuf)
720 (setq children (cdr children))
723 (defun mime-view-display-entity (entity message-info ibuf obuf)
724 (let* ((start (mime-entity-point-min entity))
725 (end (mime-entity-point-max entity))
726 (media-type (mime-entity-media-type entity))
727 (media-subtype (mime-entity-media-subtype entity))
728 (params (mime-entity-parameters entity))
729 (encoding (mime-entity-encoding entity))
730 end-of-header e nb ne subj)
733 (setq end-of-header (if (re-search-forward "^$" nil t)
736 (if (> end-of-header end)
737 (setq end-of-header end)
740 (narrow-to-region start end)
743 (mime-raw-get-subject params encoding)))
747 (narrow-to-region nb nb)
748 (if (mime-view-entity-button-visible-p entity message-info)
749 (mime-view-insert-entity-button entity message-info subj)
751 (if (mime-view-header-visible-p entity message-info)
753 (narrow-to-region (point)(point))
754 (insert-buffer-substring mime-raw-buffer start end-of-header)
755 (let ((f (cdr (assq mime-preview-original-major-mode
756 mime-view-content-header-filter-alist))))
759 (mime-view-default-content-header-filter)
761 (run-hooks 'mime-view-content-header-filter-hook)
764 (ctree-match-calist mime-preview-condition
765 (list* (cons 'type media-type)
766 (cons 'subtype media-subtype)
767 (cons 'encoding encoding)
768 (cons 'major-mode major-mode)
770 (body-presentation-method
771 (cdr (assq 'body-presentation-method situation))))
772 (cond ((eq body-presentation-method 'with-filter)
773 (let ((body-filter (cdr (assq 'body-filter situation))))
775 (narrow-to-region (point-max)(point-max))
776 (insert-buffer-substring mime-raw-buffer end-of-header end)
777 (funcall body-filter situation)
779 ((functionp body-presentation-method)
780 (funcall body-presentation-method situation)
782 (when (mime-view-entity-separator-visible-p entity message-info)
783 (goto-char (point-max))
786 (setq ne (point-max))
788 (put-text-property nb ne 'mime-view-raw-buffer ibuf)
789 (put-text-property nb ne 'mime-view-entity entity)
791 (let ((children (mime-entity-children entity)))
793 (mime-view-display-entity (car children) message-info ibuf obuf)
794 (setq children (cdr children))
797 (defun mime-raw-get-uu-filename (param &optional encoding)
798 (if (member (or encoding
799 (cdr (assq 'encoding param))
801 mime-view-uuencode-encoding-name-list)
803 (or (if (re-search-forward "^begin [0-9]+ " nil t)
804 (if (looking-at ".+$")
805 (buffer-substring (match-beginning 0)(match-end 0))
810 (defun mime-raw-get-subject (param &optional encoding)
811 (or (std11-find-field-body '("Content-Description" "Subject"))
813 (if (or (and (setq ret (mime/Content-Disposition))
814 (setq ret (assoc "filename" (cdr ret)))
816 (setq ret (assoc "name" param))
817 (setq ret (assoc "x-name" param))
819 (std11-strip-quoted-string (cdr ret))
821 (mime-raw-get-uu-filename param encoding)
825 ;;; @ MIME viewer mode
828 (defconst mime-view-menu-title "MIME-View")
829 (defconst mime-view-menu-list
830 '((up "Move to upper entity" mime-preview-move-to-upper)
831 (previous "Move to previous entity" mime-preview-move-to-previous)
832 (next "Move to next entity" mime-preview-move-to-next)
833 (scroll-down "Scroll-down" mime-preview-scroll-down-entity)
834 (scroll-up "Scroll-up" mime-preview-scroll-up-entity)
835 (play "Play current entity" mime-preview-play-current-entity)
836 (extract "Extract current entity" mime-preview-extract-current-entity)
837 (print "Print current entity" mime-preview-print-current-entity)
838 (x-face "Show X Face" mime-preview-display-x-face)
840 "Menu for MIME Viewer")
842 (cond (running-xemacs
843 (defvar mime-view-xemacs-popup-menu
844 (cons mime-view-menu-title
847 (vector (nth 1 item)(nth 2 item) t)
849 mime-view-menu-list)))
850 (defun mime-view-xemacs-popup-menu (event)
851 "Popup the menu in the MIME Viewer buffer"
853 (select-window (event-window event))
854 (set-buffer (event-buffer event))
855 (popup-menu 'mime-view-xemacs-popup-menu))
856 (defvar mouse-button-2 'button2)
859 (defvar mouse-button-2 [mouse-2])
862 (defun mime-view-define-keymap (&optional default)
863 (let ((mime-view-mode-map (if (keymapp default)
864 (copy-keymap default)
867 (define-key mime-view-mode-map
868 "u" (function mime-preview-move-to-upper))
869 (define-key mime-view-mode-map
870 "p" (function mime-preview-move-to-previous))
871 (define-key mime-view-mode-map
872 "n" (function mime-preview-move-to-next))
873 (define-key mime-view-mode-map
874 "\e\t" (function mime-preview-move-to-previous))
875 (define-key mime-view-mode-map
876 "\t" (function mime-preview-move-to-next))
877 (define-key mime-view-mode-map
878 " " (function mime-preview-scroll-up-entity))
879 (define-key mime-view-mode-map
880 "\M- " (function mime-preview-scroll-down-entity))
881 (define-key mime-view-mode-map
882 "\177" (function mime-preview-scroll-down-entity))
883 (define-key mime-view-mode-map
884 "\C-m" (function mime-preview-next-line-entity))
885 (define-key mime-view-mode-map
886 "\C-\M-m" (function mime-preview-previous-line-entity))
887 (define-key mime-view-mode-map
888 "v" (function mime-preview-play-current-entity))
889 (define-key mime-view-mode-map
890 "e" (function mime-preview-extract-current-entity))
891 (define-key mime-view-mode-map
892 "\C-c\C-p" (function mime-preview-print-current-entity))
893 (define-key mime-view-mode-map
894 "a" (function mime-preview-follow-current-entity))
895 (define-key mime-view-mode-map
896 "q" (function mime-preview-quit))
897 (define-key mime-view-mode-map
898 "h" (function mime-preview-show-summary))
899 (define-key mime-view-mode-map
900 "\C-c\C-x" (function mime-preview-kill-buffer))
901 ;; (define-key mime-view-mode-map
902 ;; "<" (function beginning-of-buffer))
903 ;; (define-key mime-view-mode-map
904 ;; ">" (function end-of-buffer))
905 (define-key mime-view-mode-map
906 "?" (function describe-mode))
907 (define-key mime-view-mode-map
908 [tab] (function mime-preview-move-to-next))
909 (define-key mime-view-mode-map
910 [delete] (function mime-preview-scroll-down-entity))
911 (define-key mime-view-mode-map
912 [backspace] (function mime-preview-scroll-down-entity))
913 (if (functionp default)
914 (cond (running-xemacs
915 (set-keymap-default-binding mime-view-mode-map default)
918 (setq mime-view-mode-map
919 (append mime-view-mode-map (list (cons t default))))
922 (define-key mime-view-mode-map
923 mouse-button-2 (function mime-button-dispatcher))
925 (cond (running-xemacs
926 (define-key mime-view-mode-map
927 mouse-button-3 (function mime-view-xemacs-popup-menu))
929 ((>= emacs-major-version 19)
930 (define-key mime-view-mode-map [menu-bar mime-view]
931 (cons mime-view-menu-title
932 (make-sparse-keymap mime-view-menu-title)))
935 (define-key mime-view-mode-map
936 (vector 'menu-bar 'mime-view (car item))
937 (cons (nth 1 item)(nth 2 item))
940 (reverse mime-view-menu-list)
943 (use-local-map mime-view-mode-map)
944 (run-hooks 'mime-view-define-keymap-hook)
947 (defsubst mime-maybe-hide-echo-buffer ()
948 "Clear mime-echo buffer and delete window for it."
949 (let ((buf (get-buffer mime-echo-buffer-name)))
954 (let ((win (get-buffer-window buf)))
961 (defun mime-view-mode (&optional mother ctl encoding ibuf obuf
962 default-keymap-or-function)
963 "Major mode for viewing MIME message.
965 Here is a list of the standard keys for mime-view-mode.
970 u Move to upper content
971 p or M-TAB Move to previous content
972 n or TAB Move to next content
973 SPC Scroll up or move to next content
974 M-SPC or DEL Scroll down or move to previous content
975 RET Move to next line
976 M-RET Move to previous line
977 v Decode current content as `play mode'
978 e Decode current content as `extract mode'
979 C-c C-p Decode current content as `print mode'
980 a Followup to current content.
983 button-2 Move to point under the mouse cursor
984 and decode current content as `play mode'
987 (mime-maybe-hide-echo-buffer)
988 (let ((ret (mime-view-setup-buffers ctl encoding ibuf obuf))
989 (win-conf (current-window-configuration))
992 (switch-to-buffer ret)
993 (setq mime-preview-original-window-configuration win-conf)
996 (setq mime-mother-buffer mother)
998 (mime-view-define-keymap default-keymap-or-function)
1000 (next-single-property-change (point-min) 'mime-view-entity)))
1003 (goto-char (point-min))
1004 (search-forward "\n\n" nil t)
1006 (run-hooks 'mime-view-mode-hook)
1013 (autoload 'mime-preview-play-current-entity "mime-play"
1014 "Play current entity." t)
1016 (defun mime-preview-extract-current-entity ()
1017 "Extract current entity into file (maybe).
1018 It decodes current entity to call internal or external method as
1019 \"extract\" mode. The method is selected from variable
1020 `mime-acting-condition'."
1022 (mime-preview-play-current-entity "extract")
1025 (defun mime-preview-print-current-entity ()
1026 "Print current entity (maybe).
1027 It decodes current entity to call internal or external method as
1028 \"print\" mode. The method is selected from variable
1029 `mime-acting-condition'."
1031 (mime-preview-play-current-entity "print")
1038 (defun mime-preview-original-major-mode ()
1039 "Return major-mode of original buffer.
1040 If a current buffer has mime-mother-buffer, return original major-mode
1041 of the mother-buffer."
1042 (if mime-mother-buffer
1044 (set-buffer mime-mother-buffer)
1045 (mime-preview-original-major-mode)
1047 mime-preview-original-major-mode))
1049 (defun mime-preview-follow-current-entity ()
1050 "Write follow message to current entity.
1051 It calls following-method selected from variable
1052 `mime-view-following-method-alist'."
1054 (let ((message-info (get-text-property (point-min) 'mime-view-entity))
1056 (while (null (setq entity
1057 (get-text-property (point) 'mime-view-entity)))
1061 (previous-single-property-change (point) 'mime-view-entity))
1063 (entity-node-id (mime-entity-node-id entity))
1064 (len (length entity-node-id))
1068 (if (eq (next-single-property-change (point-min)
1074 ((eq (next-single-property-change p-beg 'mime-view-entity)
1076 (setq p-beg (point))
1078 (setq p-end (next-single-property-change p-beg 'mime-view-entity))
1080 (setq p-end (point-max))
1082 ((null entity-node-id)
1083 (setq p-end (point-max))
1091 (next-single-property-change
1092 (point) 'mime-view-entity))
1094 (let ((rc (mime-entity-node-id
1095 (get-text-property (point)
1096 'mime-view-entity))))
1097 (or (equal entity-node-id
1098 (nthcdr (- (length rc) len) rc))
1103 (setq p-end (point-max))
1106 (let* ((mode (mime-preview-original-major-mode))
1108 (format "%s-%s" (buffer-name) (reverse entity-node-id)))
1110 (the-buf (current-buffer))
1111 (a-buf mime-raw-buffer)
1114 (set-buffer (setq new-buf (get-buffer-create new-name)))
1116 (insert-buffer-substring the-buf p-beg p-end)
1117 (goto-char (point-min))
1118 (if (mime-view-header-visible-p entity message-info)
1119 (delete-region (goto-char (point-min))
1120 (if (re-search-forward "^$" nil t)
1124 (goto-char (point-min))
1126 (goto-char (point-min))
1127 (let ((entity-node-id (mime-entity-node-id entity)) ci str)
1135 (mime-raw-find-entity-from-node-id entity-node-id))
1138 (mime-entity-point-min ci)
1139 (mime-entity-point-max ci)
1141 (std11-header-string-except
1143 (apply (function regexp-or) fields)
1146 (eq (mime-entity-media-type ci) 'message)
1147 (eq (mime-entity-media-subtype ci) 'rfc822))
1153 (setq fields (std11-collect-field-names)
1154 entity-node-id (cdr entity-node-id))
1157 (let ((rest mime-view-following-required-fields-list))
1159 (let ((field-name (car rest)))
1160 (or (std11-field-body field-name)
1166 (set-buffer the-buf)
1167 (set-buffer mime-mother-buffer)
1168 (set-buffer mime-raw-buffer)
1169 (std11-field-body field-name)
1173 (setq rest (cdr rest))
1175 (eword-decode-header)
1177 (let ((f (cdr (assq mode mime-view-following-method-alist))))
1182 "Sorry, following method for %s is not implemented yet."
1191 (defun mime-preview-display-x-face ()
1193 (save-window-excursion
1194 (set-buffer mime-raw-buffer)
1195 (mime-view-x-face-function)
1202 (defun mime-preview-move-to-upper ()
1203 "Move to upper entity.
1204 If there is no upper entity, call function `mime-preview-quit'."
1207 (while (null (setq cinfo
1208 (get-text-property (point) 'mime-view-entity)))
1211 (let ((r (mime-raw-find-entity-from-node-id
1212 (cdr (mime-entity-node-id cinfo))
1213 (get-text-property 1 'mime-view-entity)))
1216 (while (setq point (previous-single-property-change
1217 (point) 'mime-view-entity))
1219 (if (eq r (get-text-property (point) 'mime-view-entity))
1226 (defun mime-preview-move-to-previous ()
1227 "Move to previous entity.
1228 If there is no previous entity, it calls function registered in
1229 variable `mime-view-over-to-previous-method-alist'."
1231 (while (null (get-text-property (point) 'mime-view-entity))
1235 (previous-single-property-change (point) 'mime-view-entity)))
1238 (let ((f (assq mime-preview-original-major-mode
1239 mime-view-over-to-previous-method-alist)))
1245 (defun mime-preview-move-to-next ()
1246 "Move to next entity.
1247 If there is no previous entity, it calls function registered in
1248 variable `mime-view-over-to-next-method-alist'."
1250 (let ((point (next-single-property-change (point) 'mime-view-entity)))
1253 (let ((f (assq mime-preview-original-major-mode
1254 mime-view-over-to-next-method-alist)))
1260 (defun mime-preview-scroll-up-entity (&optional h)
1261 "Scroll up current entity.
1262 If reached to (point-max), it calls function registered in variable
1263 `mime-view-over-to-next-method-alist'."
1266 (setq h (1- (window-height)))
1268 (if (= (point) (point-max))
1269 (let ((f (assq mime-preview-original-major-mode
1270 mime-view-over-to-next-method-alist)))
1275 (or (next-single-property-change (point) 'mime-view-entity)
1278 (if (> (point) point)
1283 (defun mime-preview-scroll-down-entity (&optional h)
1284 "Scroll down current entity.
1285 If reached to (point-min), it calls function registered in variable
1286 `mime-view-over-to-previous-method-alist'."
1289 (setq h (1- (window-height)))
1291 (if (= (point) (point-min))
1292 (let ((f (assq mime-preview-original-major-mode
1293 mime-view-over-to-previous-method-alist)))
1300 (while (> (point) 1)
1302 (previous-single-property-change (point)
1308 (setq point (point-min))
1310 (forward-line (- h))
1311 (if (< (point) point)
1315 (defun mime-preview-next-line-entity ()
1317 (mime-preview-scroll-up-entity 1)
1320 (defun mime-preview-previous-line-entity ()
1322 (mime-preview-scroll-down-entity 1)
1329 (defun mime-preview-quit ()
1330 "Quit from MIME-preview buffer.
1331 It calls function registered in variable
1332 `mime-preview-quitting-method-alist'."
1334 (let ((r (assq mime-preview-original-major-mode
1335 mime-preview-quitting-method-alist)))
1340 (defun mime-preview-show-summary ()
1342 It calls function registered in variable
1343 `mime-view-show-summary-method'."
1345 (let ((r (assq mime-preview-original-major-mode
1346 mime-view-show-summary-method)))
1351 (defun mime-preview-kill-buffer ()
1353 (kill-buffer (current-buffer))
1360 (provide 'mime-view)
1362 (run-hooks 'mime-view-load-hook)
1364 ;;; mime-view.el ends here