1 ;;; mime-view.el --- interactive MIME viewer for GNU Emacs
3 ;; Copyright (C) 1995,1996,1997 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 ;; Version: $Revision: 0.105 $
10 ;; Keywords: MIME, multimedia, mail, news
12 ;; This file is part of SEMI (SEMI is Emacs MIME Interfaces).
14 ;; This program is free software; you can redistribute it and/or
15 ;; modify it under the terms of the GNU General Public License as
16 ;; published by the Free Software Foundation; either version 2, or (at
17 ;; your option) any later version.
19 ;; This program is distributed in the hope that it will be useful, but
20 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 ;; General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27 ;; Boston, MA 02111-1307, USA.
34 (require 'eword-decode)
42 (defconst mime-view-RCS-ID
43 "$Id: mime-view.el,v 0.105 1997-09-05 11:44:28 morioka Exp $")
45 (defconst mime-view-version
46 `,(get-version-string mime-view-RCS-ID))
48 (defconst mime-view-version-name
49 `,(concat "SEMI MIME-View " mime-view-version
50 " (" semi-version-name ")"))
56 (defvar mime-acting-condition
57 '(((type . "text/plain")
58 (method "tm-plain" nil 'file 'type 'encoding 'mode 'name)
62 (method "tm-html" nil 'file 'type 'encoding 'mode 'name)
65 ((type . "text/x-rot13-47")
66 (method . mime-display-caesar)
69 ((type . "text/x-rot13-47-48")
70 (method . mime-display-caesar)
73 ((type . "audio/basic")
74 (method "tm-au" nil 'file 'type 'encoding 'mode 'name)
78 ((type . "image/jpeg")
79 (method "tm-image" nil 'file 'type 'encoding 'mode 'name)
83 (method "tm-image" nil 'file 'type 'encoding 'mode 'name)
87 (method "tm-image" nil 'file 'type 'encoding 'mode 'name)
90 ((type . "image/tiff")
91 (method "tm-image" nil 'file 'type 'encoding 'mode 'name)
94 ((type . "image/x-tiff")
95 (method "tm-image" nil 'file 'type 'encoding 'mode 'name)
98 ((type . "image/x-xbm")
99 (method "tm-image" nil 'file 'type 'encoding 'mode 'name)
100 (mode "play" "print")
102 ((type . "image/x-pic")
103 (method "tm-image" nil 'file 'type 'encoding 'mode 'name)
104 (mode "play" "print")
106 ((type . "image/x-mag")
107 (method "tm-image" nil 'file 'type 'encoding 'mode 'name)
108 (mode "play" "print")
111 ((type . "video/mpeg")
112 (method "tm-mpeg" nil 'file 'type 'encoding 'mode 'name)
116 ((type . "application/postscript")
117 (method "tm-ps" nil 'file 'type 'encoding 'mode 'name)
118 (mode "play" "print")
120 ((type . "application/octet-stream")
121 (method "tm-file" nil 'file 'type 'encoding 'mode 'name)
122 (mode "play" "print")
125 ;;((type . "message/external-body")
126 ;; (method "xterm" nil
127 ;; "-e" "showexternal"
128 ;; 'file '"access-type" '"name" '"site" '"directory"))
129 ((type . "message/external-body")
130 ("access-type" . "anon-ftp")
131 (method . mime-display-message/external-ftp)
133 ((type . "message/rfc822")
134 (method . mime-display-message/rfc822)
137 ((type . "message/partial")
138 (method . mime-display-message/partial)
142 ((method "metamail" t "-m" "tm" "-x" "-d" "-z" "-e" 'file)
145 ((method "tm-file" nil 'file 'type 'encoding 'mode 'name)
150 (defvar mime-view-childrens-header-showing-Content-Type-list
151 '("message/rfc822" "message/news"))
153 (defvar mime-view-visible-media-type-list
154 '("text/plain" nil "text/richtext" "text/enriched"
155 "text/rfc822-headers"
156 "text/x-latex" "application/x-latex"
157 "message/delivery-status"
158 "application/pgp" "text/x-pgp"
159 "application/octet-stream"
160 "application/x-selection" "application/x-comment")
161 "*List of media-types to be able to display in MIME-View buffer.
162 Each elements are string of TYPE/SUBTYPE, e.g. \"text/plain\".")
164 (defvar mime-view-content-button-visible-ctype-list
165 '("application/pgp"))
167 (defvar mime-view-uuencode-encoding-name-list '("x-uue" "x-uuencode"))
169 (defvar mime-view-ignored-field-list
170 '(".*Received" ".*Path" ".*Id" "References"
171 "Replied" "Errors-To"
172 "Lines" "Sender" ".*Host" "Xref"
173 "Content-Type" "Precedence"
175 "All fields that match this list will be hidden in MIME preview buffer.
176 Each elements are regexp of field-name. [mime-view.el]")
178 (defvar mime-view-ignored-field-regexp
180 (apply (function regexp-or) mime-view-ignored-field-list)
183 (defvar mime-view-visible-field-list '("Dnas.*" "Message-Id")
184 "All fields that match this list will be displayed in MIME preview buffer.
185 Each elements are regexp of field-name.")
187 (defvar mime-view-redisplay nil)
189 (defvar mime-view-announcement-for-message/partial
190 (if (and (>= emacs-major-version 19) window-system)
192 \[[ This is message/partial style split message. ]]
193 \[[ Please press `v' key in this buffer ]]
194 \[[ or click here by mouse button-2. ]]"
196 \[[ This is message/partial style split message. ]]
197 \[[ Please press `v' key in this buffer. ]]"
201 ;;; @@ predicate functions
204 (defun mime-view-header-visible-p (rcnum cinfo)
205 "Return non-nil if header of current entity is visible."
207 (member (mime-entity-info-type/subtype
208 (mime-article/rcnum-to-cinfo (cdr rcnum) cinfo))
209 mime-view-childrens-header-showing-Content-Type-list)
212 (defun mime-view-body-visible-p (rcnum cinfo &optional ctype)
216 (mime-entity-info-type/subtype
217 (setq ccinfo (mime-article/rcnum-to-cinfo rcnum cinfo))
220 (and (member ctype mime-view-visible-media-type-list)
221 (if (string-equal ctype "application/octet-stream")
224 (setq ccinfo (mime-article/rcnum-to-cinfo rcnum cinfo))
226 (member (mime-entity-info-encoding ccinfo)
227 '(nil "7bit" "8bit"))
236 (defun mime-view-insert-entity-button (rcnum cinfo ctype params subj encoding)
237 "Insert entity-button."
239 (let ((access-type (assoc "access-type" params))
240 (num (or (cdr (assoc "x-part-number" params))
244 (format "%s" (1+ num))
250 (let ((server (assoc "server" params)))
251 (setq access-type (cdr access-type))
253 (format "%s %s ([%s] %s)"
254 num subj access-type (cdr server))
255 (let ((site (cdr (assoc "site" params)))
256 (dir (cdr (assoc "directory" params)))
258 (format "%s %s ([%s] %s:%s)"
259 num subj access-type site dir)
263 (let ((charset (cdr (assoc "charset" params))))
269 (concat "; " charset)
270 (if encoding (concat " (" encoding ")"))
273 (if (>= (+ (current-column)(length rest))(window-width))
277 (function mime-view-play-current-entity))
280 (defun mime-view-entity-button-function
281 (rcnum cinfo ctype params subj encoding)
282 "Insert entity button conditionally.
283 Please redefine this function if you want to change default setting."
285 (string= ctype "application/x-selection")
286 (and (string= ctype "application/octet-stream")
287 (string= (mime-entity-info-type/subtype
288 (mime-article/rcnum-to-cinfo (cdr rcnum) cinfo))
289 "multipart/encrypted"))
290 (mime-view-insert-entity-button rcnum cinfo ctype params subj encoding)
294 ;;; @@ content header filter
297 (defun mime-view-cut-header ()
298 (goto-char (point-min))
299 (while (re-search-forward mime-view-ignored-field-regexp nil t)
300 (let* ((beg (match-beginning 0))
302 (name (buffer-substring beg end))
304 (or (member-if (function
306 (string-match regexp name)
307 )) mime-view-visible-field-list)
310 (if (re-search-forward "^\\([^ \t]\\|$\\)" nil t)
315 (defun mime-view-default-content-header-filter ()
316 (mime-view-cut-header)
317 (eword-decode-header)
320 (defvar mime-view-content-header-filter-alist nil)
323 ;;; @@ content filter
326 (defvar mime-view-content-filter-alist
327 '(("text/enriched" . mime-view-filter-for-text/enriched)
328 ("text/richtext" . mime-view-filter-for-text/richtext)
329 (t . mime-view-filter-for-text/plain)
331 "Alist of media-types vs. corresponding MIME-View filter functions.
332 Each element looks like (TYPE/SUBTYPE . FUNCTION) or (t . FUNCTION).
333 TYPE/SUBTYPE is a string of media-type and FUNCTION is a filter
334 function. t means default media-type.")
337 ;;; @@ entity separator
340 (defun mime-view-entity-separator-function (rcnum cinfo ctype params subj)
341 "Insert entity separator conditionally.
342 Please redefine this function if you want to change default setting."
343 (or (mime-view-header-visible-p rcnum cinfo)
344 (mime-view-body-visible-p rcnum cinfo ctype)
346 (goto-char (point-max))
351 ;;; @@ buffer local variables
354 ;;; @@@ in raw buffer
357 (defvar mime::article/content-info
358 "Information about structure of message.
359 Please use reference function `mime::content-info/SLOT-NAME' to
360 reference slot of content-info. Their argument is only content-info.
362 Following is a list of slots of the structure:
364 rcnum reversed content-number (list)
365 point-min beginning point of region in raw-buffer
366 point-max end point of region in raw-buffer
367 type media-type/subtype (string or nil)
368 parameters parameter of Content-Type field (association list)
369 encoding Content-Transfer-Encoding (string or nil)
370 children entities included in this entity (list of content-infos)
372 If a entity includes other entities in its body, such as multipart or
373 message/rfc822, content-infos of other entities are included in
374 `children', so content-info become a tree.")
375 (make-variable-buffer-local 'mime::article/content-info)
377 (defvar mime-view-buffer nil
378 "MIME View buffer corresponding with the (raw) buffer.")
379 (make-variable-buffer-local 'mime-view-buffer)
382 ;;; @@@ in view buffer
385 (defvar mime-mother-buffer nil
386 "Mother buffer corresponding with the (MIME-View) buffer.
387 If current MIME-View buffer is generated by other buffer, such as
388 message/partial, it is called `mother-buffer'.")
389 (make-variable-buffer-local 'mime-mother-buffer)
391 (defvar mime-raw-buffer nil
392 "Raw buffer corresponding with the (MIME-View) buffer.")
393 (make-variable-buffer-local 'mime-raw-buffer)
395 (defvar mime-view-original-major-mode nil
396 "Major-mode in mime-raw-buffer.")
397 (make-variable-buffer-local 'mime-view-original-major-mode)
399 (make-variable-buffer-local 'mime::preview/original-window-configuration)
402 ;;; @@ quitting method
405 (defvar mime-view-quitting-method-alist
406 '((mime-show-message-mode
407 . mime-view-quitting-method-for-mime-show-message-mode))
408 "Alist of major-mode vs. quitting-method of mime-view.")
410 (defvar mime-view-over-to-previous-method-alist nil)
411 (defvar mime-view-over-to-next-method-alist nil)
413 (defvar mime-view-show-summary-method nil
414 "Alist of major-mode vs. show-summary-method.")
417 ;;; @@ following method
420 (defvar mime-view-following-method-alist nil
421 "Alist of major-mode vs. following-method of mime-view.")
423 (defvar mime-view-following-required-fields-list
430 ;; hack from Gnus 5.0.4.
432 (defvar mime-view-x-face-to-pbm-command
433 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm")
435 (defvar mime-view-x-face-command
436 (concat mime-view-x-face-to-pbm-command
438 "String to be executed to display an X-Face field.
439 The command will be executed in a sub-shell asynchronously.
440 The compressed face will be piped to this command.")
442 (defun mime-view-x-face-function ()
443 "Function to display X-Face field. You can redefine to customize."
444 ;; 1995/10/12 (c.f. tm-eng:130)
445 ;; fixed by Eric Ding <ericding@San-Jose.ate.slb.com>
447 (narrow-to-region (point-min) (re-search-forward "^$" nil t))
449 (goto-char (point-min))
450 (if (re-search-forward "^X-Face:[ \t]*" nil t)
451 (let ((beg (match-end 0))
452 (end (std11-field-end))
454 (call-process-region beg end "sh" nil 0 nil
455 "-c" mime-view-x-face-command)
462 (defun mime-view-setup-buffers (&optional ctl encoding ibuf obuf)
468 (or mime-view-redisplay
469 (setq mime::article/content-info (mime-parse-message ctl encoding))
471 (let* ((cinfo mime::article/content-info)
472 (pcl (mime/flatten-content-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-view-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-view-buffer obuf)
499 (defun mime-view-display-entity (content cinfo ibuf obuf)
500 "Display entity from content-info CONTENT."
501 (let* ((beg (mime-entity-info-point-min content))
502 (end (mime-entity-info-point-max content))
503 (ctype (mime-entity-info-type/subtype content))
504 (params (mime-entity-info-parameters content))
505 (encoding (mime-entity-info-encoding content))
506 (rcnum (mime-entity-info-rnum content))
510 (setq he (if (re-search-forward "^$" nil t)
517 (narrow-to-region beg end)
520 (mime-article/get-subject params encoding)))
524 (narrow-to-region nb nb)
525 (mime-view-entity-button-function rcnum cinfo ctype params subj encoding)
526 (if (mime-view-header-visible-p rcnum cinfo)
527 (mime-view-display-header beg he)
529 (if (and (null rcnum)
531 ctype mime-view-content-button-visible-ctype-list))
533 (goto-char (point-max))
534 (mime-view-insert-entity-button
535 rcnum cinfo ctype params subj encoding)
537 (cond ((mime-view-body-visible-p rcnum cinfo ctype)
538 (mime-view-display-body he end
539 rcnum cinfo ctype params subj encoding)
541 ((equal ctype "message/partial")
542 (mime-view-insert-message/partial-button)
545 (null (mime::content-info/children cinfo))
547 (goto-char (point-max))
548 (mime-view-insert-entity-button
549 rcnum cinfo ctype params subj encoding)
551 (mime-view-entity-separator-function rcnum cinfo ctype params subj)
552 (setq ne (point-max))
554 (put-text-property nb ne 'mime-view-raw-buffer ibuf)
555 (put-text-property nb ne 'mime-view-cinfo content)
559 (defun mime-view-display-header (beg end)
561 (narrow-to-region (point)(point))
562 (insert-buffer-substring mime-raw-buffer beg end)
563 (let ((f (cdr (assq mime-view-original-major-mode
564 mime-view-content-header-filter-alist))))
567 (mime-view-default-content-header-filter)
569 (run-hooks 'mime-view-content-header-filter-hook)
572 (defun mime-view-display-body (beg end rcnum cinfo ctype params subj encoding)
574 (narrow-to-region (point-max)(point-max))
575 (insert-buffer-substring mime-raw-buffer beg end)
576 (let ((f (cdr (or (assoc ctype mime-view-content-filter-alist)
577 (assq t mime-view-content-filter-alist)))))
579 (funcall f ctype params encoding)
583 (defun mime-view-insert-message/partial-button ()
585 (goto-char (point-max))
586 (if (not (search-backward "\n\n" nil t))
589 (goto-char (point-max))
590 (narrow-to-region (point-max)(point-max))
591 (insert mime-view-announcement-for-message/partial)
592 (mime-add-button (point-min)(point-max)
593 (function mime-view-play-current-entity))
596 (defun mime-article/get-uu-filename (param &optional encoding)
597 (if (member (or encoding
598 (cdr (assq 'encoding param))
600 mime-view-uuencode-encoding-name-list)
602 (or (if (re-search-forward "^begin [0-9]+ " nil t)
603 (if (looking-at ".+$")
604 (buffer-substring (match-beginning 0)(match-end 0))
609 (defun mime-article/get-subject (param &optional encoding)
610 (or (std11-find-field-body '("Content-Description" "Subject"))
612 (if (or (and (setq ret (mime/Content-Disposition))
613 (setq ret (assoc "filename" (cdr ret)))
615 (setq ret (assoc "name" param))
616 (setq ret (assoc "x-name" param))
618 (std11-strip-quoted-string (cdr ret))
620 (mime-article/get-uu-filename param encoding)
624 ;;; @ content information
627 (defun mime-article/point-content-number (p &optional cinfo)
629 (setq cinfo mime::article/content-info)
631 (let ((b (mime-entity-info-point-min cinfo))
632 (e (mime-entity-info-point-max cinfo))
633 (c (mime::content-info/children cinfo))
635 (if (and (<= b p)(<= p e))
636 (or (let (co ret (sn 0))
640 (setq ret (mime-article/point-content-number p co))
641 (cond ((eq ret t) (throw 'tag (list sn)))
642 (ret (throw 'tag (cons sn ret)))
649 (defun mime-article/rcnum-to-cinfo (rcnum &optional cinfo)
651 (setq cinfo mime::article/content-info)
655 (equal (mime-entity-info-rnum ci) rcnum)
657 (mime/flatten-content-info cinfo)
660 (defun mime-article/cnum-to-cinfo (cn &optional cinfo)
662 (setq cinfo mime::article/content-info)
669 (let ((rc (nth sn (mime::content-info/children cinfo))))
671 (mime-article/cnum-to-cinfo (cdr cn) rc)
675 (defun mime/flatten-content-info (&optional cinfo)
677 (setq cinfo mime::article/content-info)
679 (let ((dest (list cinfo))
680 (rcl (mime::content-info/children cinfo))
683 (setq dest (nconc dest (mime/flatten-content-info (car rcl))))
689 ;;; @ MIME viewer mode
692 (defconst mime-view-menu-title "MIME-View")
693 (defconst mime-view-menu-list
694 '((up "Move to upper content" mime-view-move-to-upper)
695 (previous "Move to previous content" mime-view-move-to-previous)
696 (next "Move to next content" mime-view-move-to-next)
697 (scroll-down "Scroll to previous content" mime-view-scroll-down-entity)
698 (scroll-up "Scroll to next content" mime-view-scroll-up-entity)
699 (play "Play Content" mime-view-play-current-entity)
700 (extract "Extract Content" mime-view-extract-current-entity)
701 (print "Print" mime-view-print-current-entity)
702 (x-face "Show X Face" mime-view-display-x-face)
704 "Menu for MIME Viewer")
706 (cond (running-xemacs
707 (defvar mime-view-xemacs-popup-menu
708 (cons mime-view-menu-title
711 (vector (nth 1 item)(nth 2 item) t)
713 mime-view-menu-list)))
714 (defun mime-view-xemacs-popup-menu (event)
715 "Popup the menu in the MIME Viewer buffer"
717 (select-window (event-window event))
718 (set-buffer (event-buffer event))
719 (popup-menu 'mime-view-xemacs-popup-menu))
720 (defvar mouse-button-2 'button2)
723 (defvar mouse-button-2 [mouse-2])
726 (defun mime-view-define-keymap (&optional default)
727 (let ((mime-view-mode-map (if (keymapp default)
728 (copy-keymap default)
731 (define-key mime-view-mode-map
732 "u" (function mime-view-move-to-upper))
733 (define-key mime-view-mode-map
734 "p" (function mime-view-move-to-previous))
735 (define-key mime-view-mode-map
736 "n" (function mime-view-move-to-next))
737 (define-key mime-view-mode-map
738 "\e\t" (function mime-view-move-to-previous))
739 (define-key mime-view-mode-map
740 "\t" (function mime-view-move-to-next))
741 (define-key mime-view-mode-map
742 " " (function mime-view-scroll-up-entity))
743 (define-key mime-view-mode-map
744 "\M- " (function mime-view-scroll-down-entity))
745 (define-key mime-view-mode-map
746 "\177" (function mime-view-scroll-down-entity))
747 (define-key mime-view-mode-map
748 "\C-m" (function mime-view-next-line-content))
749 (define-key mime-view-mode-map
750 "\C-\M-m" (function mime-view-previous-line-content))
751 (define-key mime-view-mode-map
752 "v" (function mime-view-play-current-entity))
753 (define-key mime-view-mode-map
754 "e" (function mime-view-extract-current-entity))
755 (define-key mime-view-mode-map
756 "\C-c\C-p" (function mime-view-print-current-entity))
757 (define-key mime-view-mode-map
758 "a" (function mime-view-follow-current-entity))
759 (define-key mime-view-mode-map
760 "q" (function mime-view-quit))
761 (define-key mime-view-mode-map
762 "h" (function mime-view-show-summary))
763 (define-key mime-view-mode-map
764 "\C-c\C-x" (function mime-view-kill-buffer))
765 ;; (define-key mime-view-mode-map
766 ;; "<" (function beginning-of-buffer))
767 ;; (define-key mime-view-mode-map
768 ;; ">" (function end-of-buffer))
769 (define-key mime-view-mode-map
770 "?" (function describe-mode))
771 (define-key mime-view-mode-map
772 [tab] (function mime-view-move-to-next))
773 (define-key mime-view-mode-map
774 [delete] (function mime-view-scroll-down-entity))
775 (define-key mime-view-mode-map
776 [backspace] (function mime-view-scroll-down-entity))
777 (if (functionp default)
778 (cond (running-xemacs
779 (set-keymap-default-binding mime-view-mode-map default)
782 (setq mime-view-mode-map
783 (append mime-view-mode-map (list (cons t default))))
786 (define-key mime-view-mode-map
787 mouse-button-2 (function mime-button-dispatcher))
789 (cond (running-xemacs
790 (define-key mime-view-mode-map
791 mouse-button-3 (function mime-view-xemacs-popup-menu))
793 ((>= emacs-major-version 19)
794 (define-key mime-view-mode-map [menu-bar mime-view]
795 (cons mime-view-menu-title
796 (make-sparse-keymap mime-view-menu-title)))
799 (define-key mime-view-mode-map
800 (vector 'menu-bar 'mime-view (car item))
801 (cons (nth 1 item)(nth 2 item))
804 (reverse mime-view-menu-list)
807 (use-local-map mime-view-mode-map)
808 (run-hooks 'mime-view-define-keymap-hook)
811 (defsubst mime-hide-echo-buffer ()
812 "Hide mime-echo buffer."
813 (let ((win (get-buffer-window mime-echo-buffer-name)))
818 (defun mime-view-mode (&optional mother ctl encoding ibuf obuf
819 default-keymap-or-function)
820 "Major mode for viewing MIME message.
822 Here is a list of the standard keys for mime-view-mode.
827 u Move to upper content
828 p or M-TAB Move to previous content
829 n or TAB Move to next content
830 SPC Scroll up or move to next content
831 M-SPC or DEL Scroll down or move to previous content
832 RET Move to next line
833 M-RET Move to previous line
834 v Decode current content as `play mode'
835 e Decode current content as `extract mode'
836 C-c C-p Decode current content as `print mode'
837 a Followup to current content.
840 button-2 Move to point under the mouse cursor
841 and decode current content as `play mode'
844 (let ((buf (get-buffer mime-echo-buffer-name)))
849 (mime-hide-echo-buffer)
851 (let ((ret (mime-view-setup-buffers ctl encoding ibuf obuf))
852 (win-conf (current-window-configuration))
855 (switch-to-buffer ret)
856 (setq mime::preview/original-window-configuration win-conf)
859 (setq mime-mother-buffer mother)
861 (mime-view-define-keymap default-keymap-or-function)
862 (let ((point (next-single-property-change (point-min) 'mime-view-cinfo)))
865 (goto-char (point-min))
866 (search-forward "\n\n" nil t)
868 (run-hooks 'mime-view-mode-hook)
875 (autoload 'mime-view-play-current-entity "mime-play" "Play current entity." t)
877 (defun mime-view-extract-current-entity ()
878 "Extract current entity into file (maybe).
879 It decodes current entity to call internal or external method as
880 \"extract\" mode. The method is selected from variable
881 `mime-acting-condition'."
883 (mime-view-play-current-entity "extract")
886 (defun mime-view-print-current-entity ()
887 "Print current entity (maybe).
888 It decodes current entity to call internal or external method as
889 \"print\" mode. The method is selected from variable
890 `mime-acting-condition'."
892 (mime-view-play-current-entity "print")
899 (defun mime-view-get-original-major-mode ()
900 "Return major-mode of original buffer.
901 If a current buffer has mime-mother-buffer, return original major-mode
902 of the mother-buffer."
903 (if mime-mother-buffer
905 (set-buffer mime-mother-buffer)
906 (mime-view-get-original-major-mode)
908 mime-view-original-major-mode))
910 (defun mime-view-follow-current-entity ()
911 "Write follow message to current entity.
912 It calls following-method selected from variable
913 `mime-view-following-method-alist'."
915 (let ((root-cinfo (get-text-property (point-min) 'mime-view-cinfo))
917 (while (null (setq cinfo (get-text-property (point) 'mime-view-cinfo)))
920 (let* ((p-beg (previous-single-property-change (point) 'mime-view-cinfo))
922 (rcnum (mime-entity-info-rnum cinfo))
927 (if (eq (next-single-property-change (point-min)
933 ((eq (next-single-property-change p-beg 'mime-view-cinfo)
937 (setq p-end (next-single-property-change p-beg 'mime-view-cinfo))
939 (setq p-end (point-max))
942 (setq p-end (point-max))
950 (next-single-property-change
951 (point) 'mime-view-cinfo))
953 (let ((rc (mime-entity-info-rnum
954 (get-text-property (point)
956 (or (equal rcnum (nthcdr (- (length rc) len) rc))
961 (setq p-end (point-max))
964 (let* ((mode (mime-view-get-original-major-mode))
965 (new-name (format "%s-%s" (buffer-name) (reverse rcnum)))
967 (the-buf (current-buffer))
968 (a-buf mime-raw-buffer)
971 (set-buffer (setq new-buf (get-buffer-create new-name)))
973 (insert-buffer-substring the-buf p-beg p-end)
974 (goto-char (point-min))
975 (if (mime-view-header-visible-p rcnum root-cinfo)
976 (delete-region (goto-char (point-min))
977 (if (re-search-forward "^$" nil t)
981 (goto-char (point-min))
983 (goto-char (point-min))
984 (let ((rcnum (mime-entity-info-rnum cinfo)) ci str)
989 (setq ci (mime-article/rcnum-to-cinfo rcnum))
992 (mime-entity-info-point-min ci)
993 (mime-entity-info-point-max ci)
995 (std11-header-string-except
997 (apply (function regexp-or) fields)
999 (if (string= (mime-entity-info-type/subtype ci)
1006 (setq fields (std11-collect-field-names)
1010 (let ((rest mime-view-following-required-fields-list))
1012 (let ((field-name (car rest)))
1013 (or (std11-field-body field-name)
1019 (set-buffer the-buf)
1020 (set-buffer mime-mother-buffer)
1021 (set-buffer mime-raw-buffer)
1022 (std11-field-body field-name)
1026 (setq rest (cdr rest))
1028 (eword-decode-header)
1030 (let ((f (cdr (assq mode mime-view-following-method-alist))))
1035 "Sorry, following method for %s is not implemented yet."
1044 (defun mime-view-display-x-face ()
1046 (save-window-excursion
1047 (set-buffer mime-raw-buffer)
1048 (mime-view-x-face-function)
1055 (defun mime-view-move-to-upper ()
1056 "Move to upper entity.
1057 If there is no upper entity, call function `mime-view-quit'."
1060 (while (null (setq cinfo (get-text-property (point) 'mime-view-cinfo)))
1063 (let ((r (mime-article/rcnum-to-cinfo
1064 (cdr (mime-entity-info-rnum cinfo))
1065 (get-text-property 1 'mime-view-cinfo)))
1068 (while (setq point (previous-single-property-change
1069 (point) 'mime-view-cinfo))
1071 (if (eq r (get-text-property (point) 'mime-view-cinfo))
1078 (defun mime-view-move-to-previous ()
1079 "Move to previous entity.
1080 If there is no previous entity, it calls function registered in
1081 variable `mime-view-over-to-previous-method-alist'."
1083 (while (null (get-text-property (point) 'mime-view-cinfo))
1086 (let ((point (previous-single-property-change (point) 'mime-view-cinfo)))
1089 (let ((f (assq mime-view-original-major-mode
1090 mime-view-over-to-previous-method-alist)))
1096 (defun mime-view-move-to-next ()
1097 "Move to next entity.
1098 If there is no previous entity, it calls function registered in
1099 variable `mime-view-over-to-next-method-alist'."
1101 (let ((point (next-single-property-change (point) 'mime-view-cinfo)))
1104 (let ((f (assq mime-view-original-major-mode
1105 mime-view-over-to-next-method-alist)))
1111 (defun mime-view-scroll-up-entity (&optional h)
1112 "Scroll up current entity.
1113 If reached to (point-max), it calls function registered in variable
1114 `mime-view-over-to-next-method-alist'."
1117 (setq h (1- (window-height)))
1119 (if (= (point) (point-max))
1120 (let ((f (assq mime-view-original-major-mode
1121 mime-view-over-to-next-method-alist)))
1126 (or (next-single-property-change (point) 'mime-view-cinfo)
1129 (if (> (point) point)
1134 (defun mime-view-scroll-down-entity (&optional h)
1135 "Scroll down current entity.
1136 If reached to (point-min), it calls function registered in variable
1137 `mime-view-over-to-previous-method-alist'."
1140 (setq h (1- (window-height)))
1142 (if (= (point) (point-min))
1143 (let ((f (assq mime-view-original-major-mode
1144 mime-view-over-to-previous-method-alist)))
1151 (while (> (point) 1)
1153 (previous-single-property-change (point)
1159 (setq point (point-min))
1161 (forward-line (- h))
1162 (if (< (point) point)
1166 (defun mime-view-next-line-content ()
1168 (mime-view-scroll-up-entity 1)
1171 (defun mime-view-previous-line-content ()
1173 (mime-view-scroll-down-entity 1)
1180 (defun mime-view-quit ()
1181 "Quit from MIME-View buffer.
1182 It calls function registered in variable
1183 `mime-view-quitting-method-alist'."
1185 (let ((r (assq mime-view-original-major-mode
1186 mime-view-quitting-method-alist)))
1191 (defun mime-view-show-summary ()
1193 It calls function registered in variable
1194 `mime-view-show-summary-method'."
1196 (let ((r (assq mime-view-original-major-mode
1197 mime-view-show-summary-method)))
1202 (defun mime-view-kill-buffer ()
1204 (kill-buffer (current-buffer))
1211 (provide 'mime-view)
1213 (run-hooks 'mime-view-load-hook)
1215 ;;; mime-view.el ends here