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/8/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)
40 (defconst mime-view-version-string
41 `,(concat "SEMI MIME-View "
42 (mapconcat #'number-to-string (cdr semi-version) ".")
43 " (" (car semi-version) ")"))
46 ;;; @ buffer local variables
52 (defvar mime-raw-message-info
53 "Information about structure of message.
54 Please use reference function `mime-entity-SLOT' to get value of SLOT.
56 Following is a list of slots of the structure:
58 node-id reversed entity-number (list of integers or t)
59 point-min beginning point of region in raw-buffer
60 point-max end point of region in raw-buffer
61 type media-type (symbol)
62 subtype media-subtype (symbol)
63 type/subtype media-type/subtype (string or nil)
64 parameters parameter of Content-Type field (association list)
65 encoding Content-Transfer-Encoding (string or nil)
66 children entities included in this entity (list of content-infos)
68 If an entity includes other entities in its body, such as multipart or
69 message/rfc822, entity-infos of other entities are included in
70 `children', so entity-info become a tree.")
71 (make-variable-buffer-local 'mime-raw-message-info)
73 (defvar mime-preview-buffer nil
74 "MIME-preview buffer corresponding with the (raw) buffer.")
75 (make-variable-buffer-local 'mime-preview-buffer)
78 ;;; @@ in preview-buffer
81 (defvar mime-mother-buffer nil
82 "Mother buffer corresponding with the (MIME-preview) buffer.
83 If current MIME-preview buffer is generated by other buffer, such as
84 message/partial, it is called `mother-buffer'.")
85 (make-variable-buffer-local 'mime-mother-buffer)
87 (defvar mime-raw-buffer nil
88 "Raw buffer corresponding with the (MIME-preview) buffer.")
89 (make-variable-buffer-local 'mime-raw-buffer)
91 (defvar mime-preview-original-major-mode nil
92 "Major-mode of mime-raw-buffer.")
93 (make-variable-buffer-local 'mime-preview-original-major-mode)
95 (make-variable-buffer-local 'mime-preview-original-window-configuration)
101 (defvar mime-view-content-button-visible-ctype-list
102 '("application/pgp"))
104 (defun mime-view-insert-entity-button (entity message-info subj)
105 "Insert entity-button of ENTITY."
106 (let ((entity-node-id (mime-entity-node-id entity))
107 (params (mime-entity-parameters entity)))
109 (let ((access-type (assoc "access-type" params))
110 (num (or (cdr (assoc "x-part-number" params))
111 (if (consp entity-node-id)
114 (format "%s" (1+ num))
116 (reverse entity-node-id) ".")
120 (let ((server (assoc "server" params)))
121 (setq access-type (cdr access-type))
123 (format "%s %s ([%s] %s)"
124 num subj access-type (cdr server))
125 (let ((site (cdr (assoc "site" params)))
126 (dir (cdr (assoc "directory" params)))
128 (format "%s %s ([%s] %s:%s)"
129 num subj access-type site dir)
133 (let ((media-type (mime-entity-media-type entity))
134 (media-subtype (mime-entity-media-subtype entity))
135 (charset (cdr (assoc "charset" params)))
136 (encoding (mime-entity-encoding entity)))
140 (format " <%s/%s%s%s>"
141 media-type media-subtype
143 (concat "; " charset)
146 (concat " (" encoding ")")
148 (if (>= (+ (current-column)(length rest))(window-width))
152 (function mime-preview-play-current-entity))
155 (defun mime-view-entity-button-function (entity message-info subj)
156 "Insert entity-button of ENTITY conditionally.
157 Please redefine this function if you want to change default setting."
158 (let ((entity-node-id (mime-entity-node-id entity))
159 (media-type (mime-entity-media-type entity))
160 (media-subtype (mime-entity-media-subtype entity)))
161 (or (null entity-node-id)
162 (and (eq media-type 'application)
163 (or (eq media-subtype 'x-selection)
164 (and (eq media-subtype 'octet-stream)
166 (mime-raw-find-entity-from-node-id
167 (cdr entity-node-id) message-info)))
168 (and (eq (mime-entity-media-type mother-entity)
170 (eq (mime-entity-media-subtype mother-entity)
173 (mime-view-insert-entity-button entity message-info subj)
180 ;;; @@ predicate function
183 (defvar mime-view-childrens-header-showing-Content-Type-list
184 '("message/rfc822" "message/news"))
186 (defun mime-view-header-visible-p (entity message-info)
187 "Return non-nil if header of ENTITY is visible."
188 (let ((entity-node-id (mime-entity-node-id entity)))
189 (or (null entity-node-id)
190 (member (mime-entity-type/subtype
191 (mime-raw-find-entity-from-node-id
192 (cdr entity-node-id) message-info))
193 mime-view-childrens-header-showing-Content-Type-list)
196 ;;; @@ entity header filter
199 (defvar mime-view-content-header-filter-alist nil)
201 (defun mime-view-default-content-header-filter ()
202 (mime-view-cut-header)
203 (eword-decode-header)
206 (defun mime-view-display-header (beg end)
208 (narrow-to-region (point)(point))
209 (insert-buffer-substring mime-raw-buffer beg end)
210 (let ((f (cdr (assq mime-preview-original-major-mode
211 mime-view-content-header-filter-alist))))
214 (mime-view-default-content-header-filter)
216 (run-hooks 'mime-view-content-header-filter-hook)
219 ;;; @@ entity field cutter
222 (defvar mime-view-ignored-field-list
223 '(".*Received" ".*Path" ".*Id" "References"
224 "Replied" "Errors-To"
225 "Lines" "Sender" ".*Host" "Xref"
226 "Content-Type" "Precedence"
228 "All fields that match this list will be hidden in MIME preview buffer.
229 Each elements are regexp of field-name.")
231 (defvar mime-view-ignored-field-regexp
233 (apply (function regexp-or) mime-view-ignored-field-list)
236 (defvar mime-view-visible-field-list '("Dnas.*" "Message-Id")
237 "All fields that match this list will be displayed in MIME preview buffer.
238 Each elements are regexp of field-name.")
240 (defun mime-view-cut-header ()
241 (goto-char (point-min))
242 (while (re-search-forward mime-view-ignored-field-regexp nil t)
243 (let* ((beg (match-beginning 0))
245 (name (buffer-substring beg end))
248 (let ((rest mime-view-visible-field-list))
250 (if (string-match (car rest) name)
253 (setq rest (cdr rest))))
256 (if (re-search-forward "^\\([^ \t]\\|$\\)" nil t)
265 ;;; @@ predicate function
268 (defvar mime-view-visible-media-type-list
269 '("text/plain" nil "text/richtext" "text/enriched"
270 "text/rfc822-headers"
271 "text/x-latex" "application/x-latex"
272 "message/delivery-status"
273 "application/pgp" "text/x-pgp"
274 "application/octet-stream"
275 "application/x-selection" "application/x-comment")
276 "*List of media-types to be able to display in MIME-preview buffer.
277 Each elements are string of TYPE/SUBTYPE, e.g. \"text/plain\".")
279 (defun mime-view-body-visible-p (entity message-info)
280 "Return non-nil if body of ENTITY is visible."
281 (let ((media-type (mime-entity-media-type entity))
282 (media-subtype (mime-entity-media-subtype entity))
283 (ctype (mime-entity-type/subtype entity)))
284 (and (member ctype mime-view-visible-media-type-list)
285 (if (and (eq media-type 'application)
286 (eq media-subtype 'octet-stream))
287 (member (mime-entity-encoding entity-info)
288 '(nil "7bit" "8bit"))
295 (defvar mime-view-content-filter-alist
296 '(("text/enriched" . mime-view-filter-for-text/enriched)
297 ("text/richtext" . mime-view-filter-for-text/richtext)
298 (t . mime-view-filter-for-text/plain)
300 "Alist of media-types vs. corresponding MIME-preview filter functions.
301 Each element looks like (TYPE/SUBTYPE . FUNCTION) or (t . FUNCTION).
302 TYPE/SUBTYPE is a string of media-type and FUNCTION is a filter
303 function. t means default media-type.")
305 (defun mime-view-display-body (beg end entity-node-id cinfo
306 ctype params subj encoding)
308 (narrow-to-region (point-max)(point-max))
309 (insert-buffer-substring mime-raw-buffer beg end)
310 (let ((f (cdr (or (assoc ctype mime-view-content-filter-alist)
311 (assq t mime-view-content-filter-alist)))))
313 (funcall f ctype params encoding)
317 (defvar mime-view-announcement-for-message/partial
318 (if (and (>= emacs-major-version 19) window-system)
320 \[[ This is message/partial style split message. ]]
321 \[[ Please press `v' key in this buffer ]]
322 \[[ or click here by mouse button-2. ]]"
324 \[[ This is message/partial style split message. ]]
325 \[[ Please press `v' key in this buffer. ]]"
328 (defun mime-view-insert-message/partial-button ()
330 (goto-char (point-max))
331 (if (not (search-backward "\n\n" nil t))
334 (goto-char (point-max))
335 (narrow-to-region (point-max)(point-max))
336 (insert mime-view-announcement-for-message/partial)
337 (mime-add-button (point-min)(point-max)
338 #'mime-preview-play-current-entity)
342 ;;; @ entity separator
345 (defun mime-view-entity-separator-function (entity message-info)
346 "Insert entity-separator of ENTITY conditionally.
347 Please redefine this function if you want to change default setting."
348 (or (mime-view-header-visible-p entity message-info)
349 (mime-view-body-visible-p entity message-info)
351 (goto-char (point-max))
356 ;;; @ acting-condition
359 (defvar mime-acting-condition
360 '(((type . text)(subtype . plain)
361 (method "tm-plain" nil 'file "" 'encoding 'mode 'name)
362 (mode "play" "print")
364 ((type . text)(subtype . html)
365 (method "tm-html" nil 'file "" 'encoding 'mode 'name)
368 ((type . text)(subtype . x-rot13-47)
369 (method . mime-method-to-display-caesar)
372 ((type . text)(subtype . x-rot13-47-48)
373 (method . mime-method-to-display-caesar)
377 ((type . audio)(subtype . basic)
378 (method "tm-au" nil 'file "" 'encoding 'mode 'name)
383 (method "tm-image" nil 'file "" 'encoding 'mode 'name)
384 (mode "play" "print")
387 ((type . video)(subtype . mpeg)
388 (method "tm-mpeg" nil 'file "" 'encoding 'mode 'name)
392 ((type . application)(subtype . postscript)
393 (method "tm-ps" nil 'file "" 'encoding 'mode 'name)
394 (mode "play" "print")
396 ((type . application)(subtype . octet-stream)
397 (method . mime-method-to-save)(mode "play" "print")
400 ((type . message)(subtype . external-body)
401 ("access-type" . "anon-ftp")
402 (method . mime-method-to-display-message/external-ftp)
404 ((type . message)(subtype . rfc822)
405 (method . mime-method-to-display-message/rfc822)
408 ((type . message)(subtype . partial)
409 (method . mime-method-to-store-message/partial)
413 ((method "metamail" t "-m" "tm" "-x" "-d" "-z" "-e" 'file)
416 ((method . mime-method-to-save)(mode . "extract"))
420 ;;; @ quitting method
423 (defvar mime-preview-quitting-method-alist
424 '((mime-show-message-mode
425 . mime-preview-quitting-method-for-mime-show-message-mode))
426 "Alist of major-mode vs. quitting-method of mime-view.")
428 (defvar mime-view-over-to-previous-method-alist nil)
429 (defvar mime-view-over-to-next-method-alist nil)
431 (defvar mime-view-show-summary-method nil
432 "Alist of major-mode vs. show-summary-method.")
435 ;;; @ following method
438 (defvar mime-view-following-method-alist nil
439 "Alist of major-mode vs. following-method of mime-view.")
441 (defvar mime-view-following-required-fields-list
448 ;; hack from Gnus 5.0.4.
450 (defvar mime-view-x-face-to-pbm-command
451 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm")
453 (defvar mime-view-x-face-command
454 (concat mime-view-x-face-to-pbm-command
456 "String to be executed to display an X-Face field.
457 The command will be executed in a sub-shell asynchronously.
458 The compressed face will be piped to this command.")
460 (defun mime-view-x-face-function ()
461 "Function to display X-Face field. You can redefine to customize."
462 ;; 1995/10/12 (c.f. tm-eng:130)
463 ;; fixed by Eric Ding <ericding@San-Jose.ate.slb.com>
465 (narrow-to-region (point-min) (re-search-forward "^$" nil t))
467 (goto-char (point-min))
468 (if (re-search-forward "^X-Face:[ \t]*" nil t)
469 (let ((beg (match-end 0))
470 (end (std11-field-end))
472 (call-process-region beg end "sh" nil 0 nil
473 "-c" mime-view-x-face-command)
480 (defvar mime-view-uuencode-encoding-name-list '("x-uue" "x-uuencode"))
487 (defvar mime-view-redisplay nil)
489 (defun mime-view-setup-buffers (&optional ctl encoding ibuf obuf)
495 (or mime-view-redisplay
496 (setq mime-raw-message-info (mime-parse-message ctl encoding))
498 (let* ((cinfo mime-raw-message-info)
499 (pcl (mime-raw-flatten-message-info cinfo))
500 (the-buf (current-buffer))
504 (setq obuf (concat "*Preview-" (buffer-name the-buf) "*")))
505 (set-buffer (get-buffer-create obuf))
506 (let ((inhibit-read-only t))
507 ;;(setq buffer-read-only nil)
510 (setq mime-raw-buffer the-buf)
511 (setq mime-preview-original-major-mode mode)
512 (setq major-mode 'mime-view-mode)
513 (setq mode-name "MIME-View")
515 (mime-view-display-entity (car pcl) cinfo the-buf obuf)
518 (set-buffer-modified-p nil)
520 (setq buffer-read-only t)
523 (setq mime-preview-buffer obuf)
526 (defun mime-view-display-entity (entity message-info ibuf obuf)
528 (let* ((beg (mime-entity-point-min entity))
529 (end (mime-entity-point-max entity))
530 (media-type (mime-entity-media-type entity))
531 (media-subtype (mime-entity-media-subtype entity))
532 (ctype (if media-type
534 (format "%s/%s" media-type media-subtype)
535 (symbol-name media-type)
537 (params (mime-entity-parameters entity))
538 (encoding (mime-entity-encoding entity))
539 (entity-node-id (mime-entity-node-id entity))
543 (setq he (if (re-search-forward "^$" nil t)
550 (narrow-to-region beg end)
553 (mime-raw-get-subject params encoding)))
557 (narrow-to-region nb nb)
558 (mime-view-entity-button-function entity message-info subj)
559 (if (mime-view-header-visible-p entity message-info)
560 (mime-view-display-header beg he)
562 (if (and (null entity-node-id)
564 ctype mime-view-content-button-visible-ctype-list))
566 (goto-char (point-max))
567 (mime-view-insert-entity-button entity message-info subj)
569 (cond ((mime-view-body-visible-p entity message-info)
570 (mime-view-display-body he end
571 entity-node-id message-info
572 ctype params subj encoding)
574 ((and (eq media-type 'message)(eq media-subtype 'partial))
575 (mime-view-insert-message/partial-button)
577 ((and (null entity-node-id)
578 (null (mime-entity-children message-info))
580 (goto-char (point-max))
581 (mime-view-insert-entity-button entity message-info subj)
583 (mime-view-entity-separator-function entity message-info)
584 (setq ne (point-max))
586 (put-text-property nb ne 'mime-view-raw-buffer ibuf)
587 (put-text-property nb ne 'mime-view-entity-info entity)
591 (defun mime-raw-get-uu-filename (param &optional encoding)
592 (if (member (or encoding
593 (cdr (assq 'encoding param))
595 mime-view-uuencode-encoding-name-list)
597 (or (if (re-search-forward "^begin [0-9]+ " nil t)
598 (if (looking-at ".+$")
599 (buffer-substring (match-beginning 0)(match-end 0))
604 (defun mime-raw-get-subject (param &optional encoding)
605 (or (std11-find-field-body '("Content-Description" "Subject"))
607 (if (or (and (setq ret (mime/Content-Disposition))
608 (setq ret (assoc "filename" (cdr ret)))
610 (setq ret (assoc "name" param))
611 (setq ret (assoc "x-name" param))
613 (std11-strip-quoted-string (cdr ret))
615 (mime-raw-get-uu-filename param encoding)
619 ;;; @ entity information
622 (defun mime-raw-point-to-entity-number (position &optional message-info)
623 "Return entity-number from POTION in mime-raw-buffer.
624 If optional argument MESSAGE-INFO is not specified,
625 `mime-raw-message-info' is used."
627 (setq message-info mime-raw-message-info))
628 (let ((b (mime-entity-point-min message-info))
629 (e (mime-entity-point-max message-info))
630 (c (mime-entity-children message-info))
632 (if (and (<= b position)(<= position e))
633 (or (let (co ret (sn 0))
637 (setq ret (mime-raw-point-to-entity-number position co))
638 (cond ((eq ret t) (throw 'tag (list sn)))
639 (ret (throw 'tag (cons sn ret)))
646 (defun mime-raw-point-to-entity-node-id (position &optional message-info)
647 "Return entity-node-id from POTION in mime-raw-buffer.
648 If optional argument MESSAGE-INFO is not specified,
649 `mime-raw-message-info' is used."
650 (reverse (mime-raw-point-to-entity-number position message-info)))
652 (defsubst mime-raw-find-entity-from-node-id (entity-node-id
653 &optional message-info)
654 "Return entity-info from ENTITY-NODE-ID in mime-raw-buffer.
655 If optional argument MESSAGE-INFO is not specified,
656 `mime-raw-message-info' is used."
657 (mime-raw-entity-number-to-entity-info (reverse entity-node-id)
660 (defun mime-raw-entity-number-to-entity-info (entity-number
661 &optional message-info)
662 "Return entity-info from ENTITY-NUMBER in mime-raw-buffer.
663 If optional argument MESSAGE-INFO is not specified,
664 `mime-raw-message-info' is used."
666 (setq message-info mime-raw-message-info))
667 (if (eq entity-number t)
669 (let ((sn (car entity-number)))
672 (let ((rc (nth sn (mime-entity-children message-info))))
674 (mime-raw-entity-number-to-entity-info (cdr entity-number) rc)
678 (defun mime-raw-flatten-message-info (&optional message-info)
679 "Return list of entity-infos in mime-raw-buffer.
680 If optional argument MESSAGE-INFO is not specified,
681 `mime-raw-message-info' is used."
683 (setq message-info mime-raw-message-info))
684 (let ((dest (list message-info))
685 (rcl (mime-entity-children message-info)))
687 (setq dest (nconc dest (mime-raw-flatten-message-info (car rcl))))
688 (setq rcl (cdr rcl)))
692 ;;; @ MIME viewer mode
695 (defconst mime-view-menu-title "MIME-View")
696 (defconst mime-view-menu-list
697 '((up "Move to upper entity" mime-preview-move-to-upper)
698 (previous "Move to previous entity" mime-preview-move-to-previous)
699 (next "Move to next entity" mime-preview-move-to-next)
700 (scroll-down "Scroll-down" mime-preview-scroll-down-entity)
701 (scroll-up "Scroll-up" mime-preview-scroll-up-entity)
702 (play "Play current entity" mime-preview-play-current-entity)
703 (extract "Extract current entity" mime-preview-extract-current-entity)
704 (print "Print current entity" mime-preview-print-current-entity)
705 (x-face "Show X Face" mime-preview-display-x-face)
707 "Menu for MIME Viewer")
709 (cond (running-xemacs
710 (defvar mime-view-xemacs-popup-menu
711 (cons mime-view-menu-title
714 (vector (nth 1 item)(nth 2 item) t)
716 mime-view-menu-list)))
717 (defun mime-view-xemacs-popup-menu (event)
718 "Popup the menu in the MIME Viewer buffer"
720 (select-window (event-window event))
721 (set-buffer (event-buffer event))
722 (popup-menu 'mime-view-xemacs-popup-menu))
723 (defvar mouse-button-2 'button2)
726 (defvar mouse-button-2 [mouse-2])
729 (defun mime-view-define-keymap (&optional default)
730 (let ((mime-view-mode-map (if (keymapp default)
731 (copy-keymap default)
734 (define-key mime-view-mode-map
735 "u" (function mime-preview-move-to-upper))
736 (define-key mime-view-mode-map
737 "p" (function mime-preview-move-to-previous))
738 (define-key mime-view-mode-map
739 "n" (function mime-preview-move-to-next))
740 (define-key mime-view-mode-map
741 "\e\t" (function mime-preview-move-to-previous))
742 (define-key mime-view-mode-map
743 "\t" (function mime-preview-move-to-next))
744 (define-key mime-view-mode-map
745 " " (function mime-preview-scroll-up-entity))
746 (define-key mime-view-mode-map
747 "\M- " (function mime-preview-scroll-down-entity))
748 (define-key mime-view-mode-map
749 "\177" (function mime-preview-scroll-down-entity))
750 (define-key mime-view-mode-map
751 "\C-m" (function mime-preview-next-line-entity))
752 (define-key mime-view-mode-map
753 "\C-\M-m" (function mime-preview-previous-line-entity))
754 (define-key mime-view-mode-map
755 "v" (function mime-preview-play-current-entity))
756 (define-key mime-view-mode-map
757 "e" (function mime-preview-extract-current-entity))
758 (define-key mime-view-mode-map
759 "\C-c\C-p" (function mime-preview-print-current-entity))
760 (define-key mime-view-mode-map
761 "a" (function mime-preview-follow-current-entity))
762 (define-key mime-view-mode-map
763 "q" (function mime-preview-quit))
764 (define-key mime-view-mode-map
765 "h" (function mime-preview-show-summary))
766 (define-key mime-view-mode-map
767 "\C-c\C-x" (function mime-preview-kill-buffer))
768 ;; (define-key mime-view-mode-map
769 ;; "<" (function beginning-of-buffer))
770 ;; (define-key mime-view-mode-map
771 ;; ">" (function end-of-buffer))
772 (define-key mime-view-mode-map
773 "?" (function describe-mode))
774 (define-key mime-view-mode-map
775 [tab] (function mime-preview-move-to-next))
776 (define-key mime-view-mode-map
777 [delete] (function mime-preview-scroll-down-entity))
778 (define-key mime-view-mode-map
779 [backspace] (function mime-preview-scroll-down-entity))
780 (if (functionp default)
781 (cond (running-xemacs
782 (set-keymap-default-binding mime-view-mode-map default)
785 (setq mime-view-mode-map
786 (append mime-view-mode-map (list (cons t default))))
789 (define-key mime-view-mode-map
790 mouse-button-2 (function mime-button-dispatcher))
792 (cond (running-xemacs
793 (define-key mime-view-mode-map
794 mouse-button-3 (function mime-view-xemacs-popup-menu))
796 ((>= emacs-major-version 19)
797 (define-key mime-view-mode-map [menu-bar mime-view]
798 (cons mime-view-menu-title
799 (make-sparse-keymap mime-view-menu-title)))
802 (define-key mime-view-mode-map
803 (vector 'menu-bar 'mime-view (car item))
804 (cons (nth 1 item)(nth 2 item))
807 (reverse mime-view-menu-list)
810 (use-local-map mime-view-mode-map)
811 (run-hooks 'mime-view-define-keymap-hook)
814 (defsubst mime-maybe-hide-echo-buffer ()
815 "Clear mime-echo buffer and delete window for it."
816 (let ((buf (get-buffer mime-echo-buffer-name)))
821 (let ((win (get-buffer-window buf)))
828 (defun mime-view-mode (&optional mother ctl encoding ibuf obuf
829 default-keymap-or-function)
830 "Major mode for viewing MIME message.
832 Here is a list of the standard keys for mime-view-mode.
837 u Move to upper content
838 p or M-TAB Move to previous content
839 n or TAB Move to next content
840 SPC Scroll up or move to next content
841 M-SPC or DEL Scroll down or move to previous content
842 RET Move to next line
843 M-RET Move to previous line
844 v Decode current content as `play mode'
845 e Decode current content as `extract mode'
846 C-c C-p Decode current content as `print mode'
847 a Followup to current content.
850 button-2 Move to point under the mouse cursor
851 and decode current content as `play mode'
854 (mime-maybe-hide-echo-buffer)
855 (let ((ret (mime-view-setup-buffers ctl encoding ibuf obuf))
856 (win-conf (current-window-configuration))
859 (switch-to-buffer ret)
860 (setq mime-preview-original-window-configuration win-conf)
863 (setq mime-mother-buffer mother)
865 (mime-view-define-keymap default-keymap-or-function)
866 (let ((point (next-single-property-change (point-min) 'mime-view-entity-info)))
869 (goto-char (point-min))
870 (search-forward "\n\n" nil t)
872 (run-hooks 'mime-view-mode-hook)
879 (autoload 'mime-preview-play-current-entity "mime-play"
880 "Play current entity." t)
882 (defun mime-preview-extract-current-entity ()
883 "Extract current entity into file (maybe).
884 It decodes current entity to call internal or external method as
885 \"extract\" mode. The method is selected from variable
886 `mime-acting-condition'."
888 (mime-preview-play-current-entity "extract")
891 (defun mime-preview-print-current-entity ()
892 "Print current entity (maybe).
893 It decodes current entity to call internal or external method as
894 \"print\" mode. The method is selected from variable
895 `mime-acting-condition'."
897 (mime-preview-play-current-entity "print")
904 (defun mime-preview-original-major-mode ()
905 "Return major-mode of original buffer.
906 If a current buffer has mime-mother-buffer, return original major-mode
907 of the mother-buffer."
908 (if mime-mother-buffer
910 (set-buffer mime-mother-buffer)
911 (mime-preview-original-major-mode)
913 mime-preview-original-major-mode))
915 (defun mime-preview-follow-current-entity ()
916 "Write follow message to current entity.
917 It calls following-method selected from variable
918 `mime-view-following-method-alist'."
920 (let ((message-info (get-text-property (point-min) 'mime-view-entity-info))
922 (while (null (setq entity
923 (get-text-property (point) 'mime-view-entity-info)))
927 (previous-single-property-change (point) 'mime-view-entity-info))
929 (entity-node-id (mime-entity-node-id entity))
930 (len (length entity-node-id))
934 (if (eq (next-single-property-change (point-min)
935 'mime-view-entity-info)
940 ((eq (next-single-property-change p-beg 'mime-view-entity-info)
944 (setq p-end (next-single-property-change p-beg 'mime-view-entity-info))
946 (setq p-end (point-max))
948 ((null entity-node-id)
949 (setq p-end (point-max))
957 (next-single-property-change
958 (point) 'mime-view-entity-info))
960 (let ((rc (mime-entity-node-id
961 (get-text-property (point)
962 'mime-view-entity-info))))
963 (or (equal entity-node-id
964 (nthcdr (- (length rc) len) rc))
969 (setq p-end (point-max))
972 (let* ((mode (mime-preview-original-major-mode))
974 (format "%s-%s" (buffer-name) (reverse entity-node-id)))
976 (the-buf (current-buffer))
977 (a-buf mime-raw-buffer)
980 (set-buffer (setq new-buf (get-buffer-create new-name)))
982 (insert-buffer-substring the-buf p-beg p-end)
983 (goto-char (point-min))
984 (if (mime-view-header-visible-p entity message-info)
985 (delete-region (goto-char (point-min))
986 (if (re-search-forward "^$" nil t)
990 (goto-char (point-min))
992 (goto-char (point-min))
993 (let ((entity-node-id (mime-entity-node-id entity)) ci str)
1001 (mime-raw-find-entity-from-node-id entity-node-id))
1004 (mime-entity-point-min ci)
1005 (mime-entity-point-max ci)
1007 (std11-header-string-except
1009 (apply (function regexp-or) fields)
1012 (eq (mime-entity-media-type ci) 'message)
1013 (eq (mime-entity-media-subtype ci) 'rfc822))
1019 (setq fields (std11-collect-field-names)
1020 entity-node-id (cdr entity-node-id))
1023 (let ((rest mime-view-following-required-fields-list))
1025 (let ((field-name (car rest)))
1026 (or (std11-field-body field-name)
1032 (set-buffer the-buf)
1033 (set-buffer mime-mother-buffer)
1034 (set-buffer mime-raw-buffer)
1035 (std11-field-body field-name)
1039 (setq rest (cdr rest))
1041 (eword-decode-header)
1043 (let ((f (cdr (assq mode mime-view-following-method-alist))))
1048 "Sorry, following method for %s is not implemented yet."
1057 (defun mime-preview-display-x-face ()
1059 (save-window-excursion
1060 (set-buffer mime-raw-buffer)
1061 (mime-view-x-face-function)
1068 (defun mime-preview-move-to-upper ()
1069 "Move to upper entity.
1070 If there is no upper entity, call function `mime-preview-quit'."
1073 (while (null (setq cinfo
1074 (get-text-property (point) 'mime-view-entity-info)))
1077 (let ((r (mime-raw-find-entity-from-node-id
1078 (cdr (mime-entity-node-id cinfo))
1079 (get-text-property 1 'mime-view-entity-info)))
1082 (while (setq point (previous-single-property-change
1083 (point) 'mime-view-entity-info))
1085 (if (eq r (get-text-property (point) 'mime-view-entity-info))
1092 (defun mime-preview-move-to-previous ()
1093 "Move to previous entity.
1094 If there is no previous entity, it calls function registered in
1095 variable `mime-view-over-to-previous-method-alist'."
1097 (while (null (get-text-property (point) 'mime-view-entity-info))
1101 (previous-single-property-change (point) 'mime-view-entity-info)))
1104 (let ((f (assq mime-preview-original-major-mode
1105 mime-view-over-to-previous-method-alist)))
1111 (defun mime-preview-move-to-next ()
1112 "Move to next entity.
1113 If there is no previous entity, it calls function registered in
1114 variable `mime-view-over-to-next-method-alist'."
1116 (let ((point (next-single-property-change (point) 'mime-view-entity-info)))
1119 (let ((f (assq mime-preview-original-major-mode
1120 mime-view-over-to-next-method-alist)))
1126 (defun mime-preview-scroll-up-entity (&optional h)
1127 "Scroll up current entity.
1128 If reached to (point-max), it calls function registered in variable
1129 `mime-view-over-to-next-method-alist'."
1132 (setq h (1- (window-height)))
1134 (if (= (point) (point-max))
1135 (let ((f (assq mime-preview-original-major-mode
1136 mime-view-over-to-next-method-alist)))
1141 (or (next-single-property-change (point) 'mime-view-entity-info)
1144 (if (> (point) point)
1149 (defun mime-preview-scroll-down-entity (&optional h)
1150 "Scroll down current entity.
1151 If reached to (point-min), it calls function registered in variable
1152 `mime-view-over-to-previous-method-alist'."
1155 (setq h (1- (window-height)))
1157 (if (= (point) (point-min))
1158 (let ((f (assq mime-preview-original-major-mode
1159 mime-view-over-to-previous-method-alist)))
1166 (while (> (point) 1)
1168 (previous-single-property-change (point)
1169 'mime-view-entity-info))
1174 (setq point (point-min))
1176 (forward-line (- h))
1177 (if (< (point) point)
1181 (defun mime-preview-next-line-entity ()
1183 (mime-preview-scroll-up-entity 1)
1186 (defun mime-preview-previous-line-entity ()
1188 (mime-preview-scroll-down-entity 1)
1195 (defun mime-preview-quit ()
1196 "Quit from MIME-preview buffer.
1197 It calls function registered in variable
1198 `mime-preview-quitting-method-alist'."
1200 (let ((r (assq mime-preview-original-major-mode
1201 mime-preview-quitting-method-alist)))
1206 (defun mime-preview-show-summary ()
1208 It calls function registered in variable
1209 `mime-view-show-summary-method'."
1211 (let ((r (assq mime-preview-original-major-mode
1212 mime-view-show-summary-method)))
1217 (defun mime-preview-kill-buffer ()
1219 (kill-buffer (current-buffer))
1226 (provide 'mime-view)
1228 (run-hooks 'mime-view-load-hook)
1230 ;;; mime-view.el ends here