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-info-SLOT' to get value of
57 Following is a list of slots of the structure:
59 node-id reversed entity-number (list of integers or t)
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, entity-infos of other entities are included in
71 `children', so entity-info 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 (make-variable-buffer-local 'mime-preview-original-window-configuration)
102 (defvar mime-view-content-button-visible-ctype-list
103 '("application/pgp"))
105 (defun mime-view-insert-entity-button (entity message-info subj)
106 "Insert entity-button of ENTITY."
107 (let ((entity-node-id (mime-entity-info-node-id entity))
108 (params (mime-entity-info-parameters entity)))
110 (let ((access-type (assoc "access-type" params))
111 (num (or (cdr (assoc "x-part-number" params))
112 (if (consp entity-node-id)
115 (format "%s" (1+ num))
117 (reverse entity-node-id) ".")
121 (let ((server (assoc "server" params)))
122 (setq access-type (cdr access-type))
124 (format "%s %s ([%s] %s)"
125 num subj access-type (cdr server))
126 (let ((site (cdr (assoc "site" params)))
127 (dir (cdr (assoc "directory" params)))
129 (format "%s %s ([%s] %s:%s)"
130 num subj access-type site dir)
134 (let ((media-type (mime-entity-info-media-type entity))
135 (media-subtype (mime-entity-info-media-subtype entity))
136 (charset (cdr (assoc "charset" params)))
137 (encoding (mime-entity-info-encoding entity)))
141 (format " <%s/%s%s%s>"
142 media-type media-subtype
144 (concat "; " charset)
147 (concat " (" encoding ")")
149 (if (>= (+ (current-column)(length rest))(window-width))
153 (function mime-preview-play-current-entity))
156 (defun mime-view-entity-button-function (entity message-info subj)
157 "Insert entity-button of ENTITY conditionally.
158 Please redefine this function if you want to change default setting."
159 (let ((entity-node-id (mime-entity-info-node-id entity))
160 (media-type (mime-entity-info-media-type entity))
161 (media-subtype (mime-entity-info-media-subtype entity)))
162 (or (null entity-node-id)
163 (and (eq media-type 'application)
164 (or (eq media-subtype 'x-selection)
165 (and (eq media-subtype 'octet-stream)
167 (mime-raw-entity-node-id-to-entity-info
168 (cdr entity-node-id) message-info)))
169 (and (eq (mime-entity-info-media-type mother-entity)
171 (eq (mime-entity-info-media-subtype mother-entity)
174 (mime-view-insert-entity-button entity message-info subj)
181 ;;; @@ predicate function
184 (defvar mime-view-childrens-header-showing-Content-Type-list
185 '("message/rfc822" "message/news"))
187 (defun mime-view-header-visible-p (entity-node-id message-info)
188 "Return non-nil if header of entity is visible."
189 (or (null entity-node-id)
190 (member (mime-entity-info-type/subtype
191 (mime-raw-entity-node-id-to-entity-info
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 ;;; @@ entity field cutter
209 (defvar mime-view-ignored-field-list
210 '(".*Received" ".*Path" ".*Id" "References"
211 "Replied" "Errors-To"
212 "Lines" "Sender" ".*Host" "Xref"
213 "Content-Type" "Precedence"
215 "All fields that match this list will be hidden in MIME preview buffer.
216 Each elements are regexp of field-name.")
218 (defvar mime-view-ignored-field-regexp
220 (apply (function regexp-or) mime-view-ignored-field-list)
223 (defvar mime-view-visible-field-list '("Dnas.*" "Message-Id")
224 "All fields that match this list will be displayed in MIME preview buffer.
225 Each elements are regexp of field-name.")
227 (defun mime-view-cut-header ()
228 (goto-char (point-min))
229 (while (re-search-forward mime-view-ignored-field-regexp nil t)
230 (let* ((beg (match-beginning 0))
232 (name (buffer-substring beg end))
235 (let ((rest mime-view-visible-field-list))
237 (if (string-match (car rest) name)
240 (setq rest (cdr rest))))
243 (if (re-search-forward "^\\([^ \t]\\|$\\)" nil t)
252 ;;; @@ predicate function
255 (defvar mime-view-visible-media-type-list
256 '("text/plain" nil "text/richtext" "text/enriched"
257 "text/rfc822-headers"
258 "text/x-latex" "application/x-latex"
259 "message/delivery-status"
260 "application/pgp" "text/x-pgp"
261 "application/octet-stream"
262 "application/x-selection" "application/x-comment")
263 "*List of media-types to be able to display in MIME-preview buffer.
264 Each elements are string of TYPE/SUBTYPE, e.g. \"text/plain\".")
266 (defun mime-view-body-visible-p (entity-node-id
268 media-type media-subtype)
269 "Return non-nil if body of entity is visible."
270 (let ((ctype (if media-type
272 (format "%s/%s" media-type media-subtype)
273 (symbol-name media-type)
275 (and (member ctype mime-view-visible-media-type-list)
276 (if (and (eq media-type 'application)
277 (eq media-subtype 'octet-stream))
279 (mime-raw-entity-node-id-to-entity-info
280 entity-node-id message-info)))
281 (member (mime-entity-info-encoding entity-info)
282 '(nil "7bit" "8bit"))
290 (defvar mime-view-content-filter-alist
291 '(("text/enriched" . mime-view-filter-for-text/enriched)
292 ("text/richtext" . mime-view-filter-for-text/richtext)
293 (t . mime-view-filter-for-text/plain)
295 "Alist of media-types vs. corresponding MIME-preview filter functions.
296 Each element looks like (TYPE/SUBTYPE . FUNCTION) or (t . FUNCTION).
297 TYPE/SUBTYPE is a string of media-type and FUNCTION is a filter
298 function. t means default media-type.")
300 (defvar mime-view-announcement-for-message/partial
301 (if (and (>= emacs-major-version 19) window-system)
303 \[[ This is message/partial style split message. ]]
304 \[[ Please press `v' key in this buffer ]]
305 \[[ or click here by mouse button-2. ]]"
307 \[[ This is message/partial style split message. ]]
308 \[[ Please press `v' key in this buffer. ]]"
312 ;;; @ entity separator
315 (defun mime-view-entity-separator-function (entity-node-id
317 media-type media-subtype
319 "Insert entity separator conditionally.
320 Please redefine this function if you want to change default setting."
321 (or (mime-view-header-visible-p entity-node-id cinfo)
322 (mime-view-body-visible-p entity-node-id cinfo media-type media-subtype)
324 (goto-char (point-max))
329 ;;; @ acting-condition
332 (defvar mime-acting-condition
333 '(((type . text)(subtype . plain)
334 (method "tm-plain" nil 'file "" 'encoding 'mode 'name)
335 (mode "play" "print")
337 ((type . text)(subtype . html)
338 (method "tm-html" nil 'file "" 'encoding 'mode 'name)
341 ((type . text)(subtype . x-rot13-47)
342 (method . mime-method-to-display-caesar)
345 ((type . text)(subtype . x-rot13-47-48)
346 (method . mime-method-to-display-caesar)
350 ((type . audio)(subtype . basic)
351 (method "tm-au" nil 'file "" 'encoding 'mode 'name)
356 (method "tm-image" nil 'file "" 'encoding 'mode 'name)
357 (mode "play" "print")
360 ((type . video)(subtype . mpeg)
361 (method "tm-mpeg" nil 'file "" 'encoding 'mode 'name)
365 ((type . application)(subtype . postscript)
366 (method "tm-ps" nil 'file "" 'encoding 'mode 'name)
367 (mode "play" "print")
369 ((type . application)(subtype . octet-stream)
370 (method . mime-method-to-save)(mode "play" "print")
373 ((type . message)(subtype . external-body)
374 ("access-type" . "anon-ftp")
375 (method . mime-method-to-display-message/external-ftp)
377 ((type . message)(subtype . rfc822)
378 (method . mime-method-to-display-message/rfc822)
381 ((type . message)(subtype . partial)
382 (method . mime-method-to-store-message/partial)
386 ((method "metamail" t "-m" "tm" "-x" "-d" "-z" "-e" 'file)
389 ((method . mime-method-to-save)(mode . "extract"))
393 ;;; @ quitting method
396 (defvar mime-preview-quitting-method-alist
397 '((mime-show-message-mode
398 . mime-preview-quitting-method-for-mime-show-message-mode))
399 "Alist of major-mode vs. quitting-method of mime-view.")
401 (defvar mime-view-over-to-previous-method-alist nil)
402 (defvar mime-view-over-to-next-method-alist nil)
404 (defvar mime-view-show-summary-method nil
405 "Alist of major-mode vs. show-summary-method.")
408 ;;; @ following method
411 (defvar mime-view-following-method-alist nil
412 "Alist of major-mode vs. following-method of mime-view.")
414 (defvar mime-view-following-required-fields-list
421 ;; hack from Gnus 5.0.4.
423 (defvar mime-view-x-face-to-pbm-command
424 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm")
426 (defvar mime-view-x-face-command
427 (concat mime-view-x-face-to-pbm-command
429 "String to be executed to display an X-Face field.
430 The command will be executed in a sub-shell asynchronously.
431 The compressed face will be piped to this command.")
433 (defun mime-view-x-face-function ()
434 "Function to display X-Face field. You can redefine to customize."
435 ;; 1995/10/12 (c.f. tm-eng:130)
436 ;; fixed by Eric Ding <ericding@San-Jose.ate.slb.com>
438 (narrow-to-region (point-min) (re-search-forward "^$" nil t))
440 (goto-char (point-min))
441 (if (re-search-forward "^X-Face:[ \t]*" nil t)
442 (let ((beg (match-end 0))
443 (end (std11-field-end))
445 (call-process-region beg end "sh" nil 0 nil
446 "-c" mime-view-x-face-command)
453 (defvar mime-view-uuencode-encoding-name-list '("x-uue" "x-uuencode"))
460 (defvar mime-view-redisplay nil)
462 (defun mime-view-setup-buffers (&optional ctl encoding ibuf obuf)
468 (or mime-view-redisplay
469 (setq mime-raw-message-info (mime-parse-message ctl encoding))
471 (let* ((cinfo mime-raw-message-info)
472 (pcl (mime-raw-flatten-message-info cinfo))
473 (the-buf (current-buffer))
477 (setq obuf (concat "*Preview-" (buffer-name the-buf) "*")))
478 (set-buffer (get-buffer-create obuf))
479 (let ((inhibit-read-only t))
480 ;;(setq buffer-read-only nil)
483 (setq mime-raw-buffer the-buf)
484 (setq mime-preview-original-major-mode mode)
485 (setq major-mode 'mime-view-mode)
486 (setq mode-name "MIME-View")
488 (mime-view-display-entity (car pcl) cinfo the-buf obuf)
491 (set-buffer-modified-p nil)
493 (setq buffer-read-only t)
496 (setq mime-preview-buffer obuf)
499 (defun mime-view-display-entity (entity cinfo ibuf obuf)
501 (let* ((beg (mime-entity-info-point-min entity))
502 (end (mime-entity-info-point-max entity))
503 (media-type (mime-entity-info-media-type entity))
504 (media-subtype (mime-entity-info-media-subtype entity))
505 (ctype (if media-type
507 (format "%s/%s" media-type media-subtype)
508 (symbol-name media-type)
510 (params (mime-entity-info-parameters entity))
511 (encoding (mime-entity-info-encoding entity))
512 (entity-node-id (mime-entity-info-node-id entity))
516 (setq he (if (re-search-forward "^$" nil t)
523 (narrow-to-region beg end)
526 (mime-raw-get-subject params encoding)))
530 (narrow-to-region nb nb)
531 (mime-view-entity-button-function entity cinfo subj)
532 (if (mime-view-header-visible-p entity-node-id cinfo)
533 (mime-view-display-header beg he)
535 (if (and (null entity-node-id)
537 ctype mime-view-content-button-visible-ctype-list))
539 (goto-char (point-max))
540 (mime-view-insert-entity-button entity cinfo subj)
542 (cond ((mime-view-body-visible-p entity-node-id cinfo
543 media-type media-subtype)
544 (mime-view-display-body he end
546 ctype params subj encoding)
548 ((and (eq media-type 'message)(eq media-subtype 'partial))
549 (mime-view-insert-message/partial-button)
551 ((and (null entity-node-id)
552 (null (mime-entity-info-children cinfo))
554 (goto-char (point-max))
555 (mime-view-insert-entity-button entity cinfo subj)
557 (mime-view-entity-separator-function
558 entity-node-id cinfo media-type media-subtype params subj)
559 (setq ne (point-max))
561 (put-text-property nb ne 'mime-view-raw-buffer ibuf)
562 (put-text-property nb ne 'mime-view-entity-info entity)
566 (defun mime-view-display-header (beg end)
568 (narrow-to-region (point)(point))
569 (insert-buffer-substring mime-raw-buffer beg end)
570 (let ((f (cdr (assq mime-preview-original-major-mode
571 mime-view-content-header-filter-alist))))
574 (mime-view-default-content-header-filter)
576 (run-hooks 'mime-view-content-header-filter-hook)
579 (defun mime-view-display-body (beg end entity-node-id cinfo
580 ctype params subj encoding)
582 (narrow-to-region (point-max)(point-max))
583 (insert-buffer-substring mime-raw-buffer beg end)
584 (let ((f (cdr (or (assoc ctype mime-view-content-filter-alist)
585 (assq t mime-view-content-filter-alist)))))
587 (funcall f ctype params encoding)
591 (defun mime-view-insert-message/partial-button ()
593 (goto-char (point-max))
594 (if (not (search-backward "\n\n" nil t))
597 (goto-char (point-max))
598 (narrow-to-region (point-max)(point-max))
599 (insert mime-view-announcement-for-message/partial)
600 (mime-add-button (point-min)(point-max)
601 (function mime-preview-play-current-entity))
604 (defun mime-raw-get-uu-filename (param &optional encoding)
605 (if (member (or encoding
606 (cdr (assq 'encoding param))
608 mime-view-uuencode-encoding-name-list)
610 (or (if (re-search-forward "^begin [0-9]+ " nil t)
611 (if (looking-at ".+$")
612 (buffer-substring (match-beginning 0)(match-end 0))
617 (defun mime-raw-get-subject (param &optional encoding)
618 (or (std11-find-field-body '("Content-Description" "Subject"))
620 (if (or (and (setq ret (mime/Content-Disposition))
621 (setq ret (assoc "filename" (cdr ret)))
623 (setq ret (assoc "name" param))
624 (setq ret (assoc "x-name" param))
626 (std11-strip-quoted-string (cdr ret))
628 (mime-raw-get-uu-filename param encoding)
632 ;;; @ entity information
635 (defun mime-raw-point-to-entity-number (position &optional message-info)
636 "Return entity-number from POTION in mime-raw-buffer.
637 If optional argument MESSAGE-INFO is not specified,
638 `mime-raw-message-info' is used."
640 (setq message-info mime-raw-message-info))
641 (let ((b (mime-entity-info-point-min message-info))
642 (e (mime-entity-info-point-max message-info))
643 (c (mime-entity-info-children message-info))
645 (if (and (<= b position)(<= position e))
646 (or (let (co ret (sn 0))
650 (setq ret (mime-raw-point-to-entity-number position co))
651 (cond ((eq ret t) (throw 'tag (list sn)))
652 (ret (throw 'tag (cons sn ret)))
659 (defun mime-raw-point-to-entity-node-id (position &optional message-info)
660 "Return entity-node-id from POTION in mime-raw-buffer.
661 If optional argument MESSAGE-INFO is not specified,
662 `mime-raw-message-info' is used."
663 (reverse (mime-raw-point-to-entity-number position message-info)))
665 (defsubst mime-raw-entity-node-id-to-entity-info (entity-node-id
666 &optional message-info)
667 "Return entity-info from ENTITY-NODE-ID in mime-raw-buffer.
668 If optional argument MESSAGE-INFO is not specified,
669 `mime-raw-message-info' is used."
670 (mime-raw-entity-number-to-entity-info (reverse entity-node-id)
673 (defun mime-raw-entity-number-to-entity-info (entity-number
674 &optional message-info)
675 "Return entity-info from ENTITY-NUMBER in mime-raw-buffer.
676 If optional argument MESSAGE-INFO is not specified,
677 `mime-raw-message-info' is used."
679 (setq message-info mime-raw-message-info))
680 (if (eq entity-number t)
682 (let ((sn (car entity-number)))
685 (let ((rc (nth sn (mime-entity-info-children message-info))))
687 (mime-raw-entity-number-to-entity-info (cdr entity-number) rc)
691 (defun mime-raw-flatten-message-info (&optional message-info)
692 "Return list of entity-infos in mime-raw-buffer.
693 If optional argument MESSAGE-INFO is not specified,
694 `mime-raw-message-info' is used."
696 (setq message-info mime-raw-message-info))
697 (let ((dest (list message-info))
698 (rcl (mime-entity-info-children message-info)))
700 (setq dest (nconc dest (mime-raw-flatten-message-info (car rcl))))
701 (setq rcl (cdr rcl)))
705 ;;; @ MIME viewer mode
708 (defconst mime-view-menu-title "MIME-View")
709 (defconst mime-view-menu-list
710 '((up "Move to upper entity" mime-preview-move-to-upper)
711 (previous "Move to previous entity" mime-preview-move-to-previous)
712 (next "Move to next entity" mime-preview-move-to-next)
713 (scroll-down "Scroll-down" mime-preview-scroll-down-entity)
714 (scroll-up "Scroll-up" mime-preview-scroll-up-entity)
715 (play "Play current entity" mime-preview-play-current-entity)
716 (extract "Extract current entity" mime-preview-extract-current-entity)
717 (print "Print current entity" mime-preview-print-current-entity)
718 (x-face "Show X Face" mime-preview-display-x-face)
720 "Menu for MIME Viewer")
722 (cond (running-xemacs
723 (defvar mime-view-xemacs-popup-menu
724 (cons mime-view-menu-title
727 (vector (nth 1 item)(nth 2 item) t)
729 mime-view-menu-list)))
730 (defun mime-view-xemacs-popup-menu (event)
731 "Popup the menu in the MIME Viewer buffer"
733 (select-window (event-window event))
734 (set-buffer (event-buffer event))
735 (popup-menu 'mime-view-xemacs-popup-menu))
736 (defvar mouse-button-2 'button2)
739 (defvar mouse-button-2 [mouse-2])
742 (defun mime-view-define-keymap (&optional default)
743 (let ((mime-view-mode-map (if (keymapp default)
744 (copy-keymap default)
747 (define-key mime-view-mode-map
748 "u" (function mime-preview-move-to-upper))
749 (define-key mime-view-mode-map
750 "p" (function mime-preview-move-to-previous))
751 (define-key mime-view-mode-map
752 "n" (function mime-preview-move-to-next))
753 (define-key mime-view-mode-map
754 "\e\t" (function mime-preview-move-to-previous))
755 (define-key mime-view-mode-map
756 "\t" (function mime-preview-move-to-next))
757 (define-key mime-view-mode-map
758 " " (function mime-preview-scroll-up-entity))
759 (define-key mime-view-mode-map
760 "\M- " (function mime-preview-scroll-down-entity))
761 (define-key mime-view-mode-map
762 "\177" (function mime-preview-scroll-down-entity))
763 (define-key mime-view-mode-map
764 "\C-m" (function mime-preview-next-line-entity))
765 (define-key mime-view-mode-map
766 "\C-\M-m" (function mime-preview-previous-line-entity))
767 (define-key mime-view-mode-map
768 "v" (function mime-preview-play-current-entity))
769 (define-key mime-view-mode-map
770 "e" (function mime-preview-extract-current-entity))
771 (define-key mime-view-mode-map
772 "\C-c\C-p" (function mime-preview-print-current-entity))
773 (define-key mime-view-mode-map
774 "a" (function mime-preview-follow-current-entity))
775 (define-key mime-view-mode-map
776 "q" (function mime-preview-quit))
777 (define-key mime-view-mode-map
778 "h" (function mime-preview-show-summary))
779 (define-key mime-view-mode-map
780 "\C-c\C-x" (function mime-preview-kill-buffer))
781 ;; (define-key mime-view-mode-map
782 ;; "<" (function beginning-of-buffer))
783 ;; (define-key mime-view-mode-map
784 ;; ">" (function end-of-buffer))
785 (define-key mime-view-mode-map
786 "?" (function describe-mode))
787 (define-key mime-view-mode-map
788 [tab] (function mime-preview-move-to-next))
789 (define-key mime-view-mode-map
790 [delete] (function mime-preview-scroll-down-entity))
791 (define-key mime-view-mode-map
792 [backspace] (function mime-preview-scroll-down-entity))
793 (if (functionp default)
794 (cond (running-xemacs
795 (set-keymap-default-binding mime-view-mode-map default)
798 (setq mime-view-mode-map
799 (append mime-view-mode-map (list (cons t default))))
802 (define-key mime-view-mode-map
803 mouse-button-2 (function mime-button-dispatcher))
805 (cond (running-xemacs
806 (define-key mime-view-mode-map
807 mouse-button-3 (function mime-view-xemacs-popup-menu))
809 ((>= emacs-major-version 19)
810 (define-key mime-view-mode-map [menu-bar mime-view]
811 (cons mime-view-menu-title
812 (make-sparse-keymap mime-view-menu-title)))
815 (define-key mime-view-mode-map
816 (vector 'menu-bar 'mime-view (car item))
817 (cons (nth 1 item)(nth 2 item))
820 (reverse mime-view-menu-list)
823 (use-local-map mime-view-mode-map)
824 (run-hooks 'mime-view-define-keymap-hook)
827 (defsubst mime-maybe-hide-echo-buffer ()
828 "Clear mime-echo buffer and delete window for it."
829 (let ((buf (get-buffer mime-echo-buffer-name)))
834 (let ((win (get-buffer-window buf)))
841 (defun mime-view-mode (&optional mother ctl encoding ibuf obuf
842 default-keymap-or-function)
843 "Major mode for viewing MIME message.
845 Here is a list of the standard keys for mime-view-mode.
850 u Move to upper content
851 p or M-TAB Move to previous content
852 n or TAB Move to next content
853 SPC Scroll up or move to next content
854 M-SPC or DEL Scroll down or move to previous content
855 RET Move to next line
856 M-RET Move to previous line
857 v Decode current content as `play mode'
858 e Decode current content as `extract mode'
859 C-c C-p Decode current content as `print mode'
860 a Followup to current content.
863 button-2 Move to point under the mouse cursor
864 and decode current content as `play mode'
867 (mime-maybe-hide-echo-buffer)
868 (let ((ret (mime-view-setup-buffers ctl encoding ibuf obuf))
869 (win-conf (current-window-configuration))
872 (switch-to-buffer ret)
873 (setq mime-preview-original-window-configuration win-conf)
876 (setq mime-mother-buffer mother)
878 (mime-view-define-keymap default-keymap-or-function)
879 (let ((point (next-single-property-change (point-min) 'mime-view-entity-info)))
882 (goto-char (point-min))
883 (search-forward "\n\n" nil t)
885 (run-hooks 'mime-view-mode-hook)
892 (autoload 'mime-preview-play-current-entity "mime-play"
893 "Play current entity." t)
895 (defun mime-preview-extract-current-entity ()
896 "Extract current entity into file (maybe).
897 It decodes current entity to call internal or external method as
898 \"extract\" mode. The method is selected from variable
899 `mime-acting-condition'."
901 (mime-preview-play-current-entity "extract")
904 (defun mime-preview-print-current-entity ()
905 "Print current entity (maybe).
906 It decodes current entity to call internal or external method as
907 \"print\" mode. The method is selected from variable
908 `mime-acting-condition'."
910 (mime-preview-play-current-entity "print")
917 (defun mime-preview-original-major-mode ()
918 "Return major-mode of original buffer.
919 If a current buffer has mime-mother-buffer, return original major-mode
920 of the mother-buffer."
921 (if mime-mother-buffer
923 (set-buffer mime-mother-buffer)
924 (mime-preview-original-major-mode)
926 mime-preview-original-major-mode))
928 (defun mime-preview-follow-current-entity ()
929 "Write follow message to current entity.
930 It calls following-method selected from variable
931 `mime-view-following-method-alist'."
933 (let ((root-cinfo (get-text-property (point-min) 'mime-view-entity-info))
935 (while (null (setq cinfo
936 (get-text-property (point) 'mime-view-entity-info)))
940 (previous-single-property-change (point) 'mime-view-entity-info))
942 (entity-node-id (mime-entity-info-node-id cinfo))
943 (len (length entity-node-id))
947 (if (eq (next-single-property-change (point-min)
948 'mime-view-entity-info)
953 ((eq (next-single-property-change p-beg 'mime-view-entity-info)
957 (setq p-end (next-single-property-change p-beg 'mime-view-entity-info))
959 (setq p-end (point-max))
961 ((null entity-node-id)
962 (setq p-end (point-max))
970 (next-single-property-change
971 (point) 'mime-view-entity-info))
973 (let ((rc (mime-entity-info-node-id
974 (get-text-property (point)
975 'mime-view-entity-info))))
976 (or (equal entity-node-id
977 (nthcdr (- (length rc) len) rc))
982 (setq p-end (point-max))
985 (let* ((mode (mime-preview-original-major-mode))
987 (format "%s-%s" (buffer-name) (reverse entity-node-id)))
989 (the-buf (current-buffer))
990 (a-buf mime-raw-buffer)
993 (set-buffer (setq new-buf (get-buffer-create new-name)))
995 (insert-buffer-substring the-buf p-beg p-end)
996 (goto-char (point-min))
997 (if (mime-view-header-visible-p entity-node-id root-cinfo)
998 (delete-region (goto-char (point-min))
999 (if (re-search-forward "^$" nil t)
1003 (goto-char (point-min))
1005 (goto-char (point-min))
1006 (let ((entity-node-id (mime-entity-info-node-id cinfo)) ci str)
1014 (mime-raw-entity-node-id-to-entity-info
1018 (mime-entity-info-point-min ci)
1019 (mime-entity-info-point-max ci)
1021 (std11-header-string-except
1023 (apply (function regexp-or) fields)
1026 (eq (mime-entity-info-media-type ci) 'message)
1027 (eq (mime-entity-info-media-subtype ci) 'rfc822))
1033 (setq fields (std11-collect-field-names)
1034 entity-node-id (cdr entity-node-id))
1037 (let ((rest mime-view-following-required-fields-list))
1039 (let ((field-name (car rest)))
1040 (or (std11-field-body field-name)
1046 (set-buffer the-buf)
1047 (set-buffer mime-mother-buffer)
1048 (set-buffer mime-raw-buffer)
1049 (std11-field-body field-name)
1053 (setq rest (cdr rest))
1055 (eword-decode-header)
1057 (let ((f (cdr (assq mode mime-view-following-method-alist))))
1062 "Sorry, following method for %s is not implemented yet."
1071 (defun mime-preview-display-x-face ()
1073 (save-window-excursion
1074 (set-buffer mime-raw-buffer)
1075 (mime-view-x-face-function)
1082 (defun mime-preview-move-to-upper ()
1083 "Move to upper entity.
1084 If there is no upper entity, call function `mime-preview-quit'."
1087 (while (null (setq cinfo
1088 (get-text-property (point) 'mime-view-entity-info)))
1091 (let ((r (mime-raw-entity-node-id-to-entity-info
1092 (cdr (mime-entity-info-node-id cinfo))
1093 (get-text-property 1 'mime-view-entity-info)))
1096 (while (setq point (previous-single-property-change
1097 (point) 'mime-view-entity-info))
1099 (if (eq r (get-text-property (point) 'mime-view-entity-info))
1106 (defun mime-preview-move-to-previous ()
1107 "Move to previous entity.
1108 If there is no previous entity, it calls function registered in
1109 variable `mime-view-over-to-previous-method-alist'."
1111 (while (null (get-text-property (point) 'mime-view-entity-info))
1115 (previous-single-property-change (point) 'mime-view-entity-info)))
1118 (let ((f (assq mime-preview-original-major-mode
1119 mime-view-over-to-previous-method-alist)))
1125 (defun mime-preview-move-to-next ()
1126 "Move to next entity.
1127 If there is no previous entity, it calls function registered in
1128 variable `mime-view-over-to-next-method-alist'."
1130 (let ((point (next-single-property-change (point) 'mime-view-entity-info)))
1133 (let ((f (assq mime-preview-original-major-mode
1134 mime-view-over-to-next-method-alist)))
1140 (defun mime-preview-scroll-up-entity (&optional h)
1141 "Scroll up current entity.
1142 If reached to (point-max), it calls function registered in variable
1143 `mime-view-over-to-next-method-alist'."
1146 (setq h (1- (window-height)))
1148 (if (= (point) (point-max))
1149 (let ((f (assq mime-preview-original-major-mode
1150 mime-view-over-to-next-method-alist)))
1155 (or (next-single-property-change (point) 'mime-view-entity-info)
1158 (if (> (point) point)
1163 (defun mime-preview-scroll-down-entity (&optional h)
1164 "Scroll down current entity.
1165 If reached to (point-min), it calls function registered in variable
1166 `mime-view-over-to-previous-method-alist'."
1169 (setq h (1- (window-height)))
1171 (if (= (point) (point-min))
1172 (let ((f (assq mime-preview-original-major-mode
1173 mime-view-over-to-previous-method-alist)))
1180 (while (> (point) 1)
1182 (previous-single-property-change (point)
1183 'mime-view-entity-info))
1188 (setq point (point-min))
1190 (forward-line (- h))
1191 (if (< (point) point)
1195 (defun mime-preview-next-line-entity ()
1197 (mime-preview-scroll-up-entity 1)
1200 (defun mime-preview-previous-line-entity ()
1202 (mime-preview-scroll-down-entity 1)
1209 (defun mime-preview-quit ()
1210 "Quit from MIME-preview buffer.
1211 It calls function registered in variable
1212 `mime-preview-quitting-method-alist'."
1214 (let ((r (assq mime-preview-original-major-mode
1215 mime-preview-quitting-method-alist)))
1220 (defun mime-preview-show-summary ()
1222 It calls function registered in variable
1223 `mime-view-show-summary-method'."
1225 (let ((r (assq mime-preview-original-major-mode
1226 mime-view-show-summary-method)))
1231 (defun mime-preview-kill-buffer ()
1233 (kill-buffer (current-buffer))
1240 (provide 'mime-view)
1242 (run-hooks 'mime-view-load-hook)
1244 ;;; mime-view.el ends here