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.97 $
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.97 1997-07-14 15:15:17 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::content-info/type
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::content-info/type
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::content-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::content-info/type
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 (defsubst 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::content-info/point-min content))
502 (end (mime::content-info/point-max content))
503 (ctype (mime::content-info/type content))
504 (params (mime::content-info/parameters content))
505 (encoding (mime::content-info/encoding content))
506 (rcnum (mime::content-info/rcnum 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-preview/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-preview/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-preview/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-preview/display-body (beg end
573 rcnum cinfo ctype params subj encoding)
575 (narrow-to-region (point-max)(point-max))
576 (insert-buffer-substring mime-raw-buffer beg end)
577 (let ((f (cdr (or (assoc ctype mime-view-content-filter-alist)
578 (assq t mime-view-content-filter-alist)))))
580 (funcall f ctype params encoding)
584 (defun mime-view-insert-message/partial-button ()
586 (goto-char (point-max))
587 (if (not (search-backward "\n\n" nil t))
590 (goto-char (point-max))
591 (narrow-to-region (point-max)(point-max))
592 (insert mime-view-announcement-for-message/partial)
593 (mime-add-button (point-min)(point-max)
594 (function mime-view-play-current-entity))
597 (defun mime-article/get-uu-filename (param &optional encoding)
598 (if (member (or encoding
599 (cdr (assq 'encoding param))
601 mime-view-uuencode-encoding-name-list)
603 (or (if (re-search-forward "^begin [0-9]+ " nil t)
604 (if (looking-at ".+$")
605 (buffer-substring (match-beginning 0)(match-end 0))
610 (defun mime-article/get-subject (param &optional encoding)
611 (or (std11-find-field-body '("Content-Description" "Subject"))
613 (if (or (and (setq ret (mime/Content-Disposition))
614 (setq ret (assoc "filename" (cdr ret)))
616 (setq ret (assoc "name" param))
617 (setq ret (assoc "x-name" param))
619 (std11-strip-quoted-string (cdr ret))
621 (mime-article/get-uu-filename param encoding)
625 ;;; @ content information
628 (defun mime-article/point-content-number (p &optional cinfo)
630 (setq cinfo mime::article/content-info)
632 (let ((b (mime::content-info/point-min cinfo))
633 (e (mime::content-info/point-max cinfo))
634 (c (mime::content-info/children cinfo))
636 (if (and (<= b p)(<= p e))
637 (or (let (co ret (sn 0))
641 (setq ret (mime-article/point-content-number p co))
642 (cond ((eq ret t) (throw 'tag (list sn)))
643 (ret (throw 'tag (cons sn ret)))
650 (defun mime-article/rcnum-to-cinfo (rcnum &optional cinfo)
652 (setq cinfo mime::article/content-info)
656 (equal (mime::content-info/rcnum ci) rcnum)
658 (mime/flatten-content-info cinfo)
661 (defun mime-article/cnum-to-cinfo (cn &optional cinfo)
663 (setq cinfo mime::article/content-info)
670 (let ((rc (nth sn (mime::content-info/children cinfo))))
672 (mime-article/cnum-to-cinfo (cdr cn) rc)
676 (defun mime/flatten-content-info (&optional cinfo)
678 (setq cinfo mime::article/content-info)
680 (let ((dest (list cinfo))
681 (rcl (mime::content-info/children cinfo))
684 (setq dest (nconc dest (mime/flatten-content-info (car rcl))))
690 ;;; @ MIME viewer mode
693 (defconst mime-view-menu-title "MIME-View")
694 (defconst mime-view-menu-list
695 '((up "Move to upper content" mime-view-move-to-upper)
696 (previous "Move to previous content" mime-view-move-to-previous)
697 (next "Move to next content" mime-view-move-to-next)
698 (scroll-down "Scroll to previous content" mime-view-scroll-down-entity)
699 (scroll-up "Scroll to next content" mime-view-scroll-up-entity)
700 (play "Play Content" mime-view-play-current-entity)
701 (extract "Extract Content" mime-view-extract-current-entity)
702 (print "Print" mime-view-print-current-entity)
703 (x-face "Show X Face" mime-view-display-x-face)
705 "Menu for MIME Viewer")
707 (cond (running-xemacs
708 (defvar mime-view-xemacs-popup-menu
709 (cons mime-view-menu-title
712 (vector (nth 1 item)(nth 2 item) t)
714 mime-view-menu-list)))
715 (defun mime-view-xemacs-popup-menu (event)
716 "Popup the menu in the MIME Viewer buffer"
718 (select-window (event-window event))
719 (set-buffer (event-buffer event))
720 (popup-menu 'mime-view-xemacs-popup-menu))
721 (defvar mouse-button-2 'button2)
724 (defvar mouse-button-2 [mouse-2])
727 (defun mime-view-define-keymap (&optional default)
728 (let ((mime-view-mode-map (if (keymapp default)
729 (copy-keymap default)
732 (define-key mime-view-mode-map
733 "u" (function mime-view-move-to-upper))
734 (define-key mime-view-mode-map
735 "p" (function mime-view-move-to-previous))
736 (define-key mime-view-mode-map
737 "n" (function mime-view-move-to-next))
738 (define-key mime-view-mode-map
739 "\e\t" (function mime-view-move-to-previous))
740 (define-key mime-view-mode-map
741 "\t" (function mime-view-move-to-next))
742 (define-key mime-view-mode-map
743 " " (function mime-view-scroll-up-entity))
744 (define-key mime-view-mode-map
745 "\M- " (function mime-view-scroll-down-entity))
746 (define-key mime-view-mode-map
747 "\177" (function mime-view-scroll-down-entity))
748 (define-key mime-view-mode-map
749 "\C-m" (function mime-view-next-line-content))
750 (define-key mime-view-mode-map
751 "\C-\M-m" (function mime-view-previous-line-content))
752 (define-key mime-view-mode-map
753 "v" (function mime-view-play-current-entity))
754 (define-key mime-view-mode-map
755 "e" (function mime-view-extract-current-entity))
756 (define-key mime-view-mode-map
757 "\C-c\C-p" (function mime-view-print-current-entity))
758 (define-key mime-view-mode-map
759 "a" (function mime-view-follow-current-entity))
760 (define-key mime-view-mode-map
761 "q" (function mime-view-quit))
762 (define-key mime-view-mode-map
763 "h" (function mime-view-show-summary))
764 (define-key mime-view-mode-map
765 "\C-c\C-x" (function mime-view-kill-buffer))
766 ;; (define-key mime-view-mode-map
767 ;; "<" (function beginning-of-buffer))
768 ;; (define-key mime-view-mode-map
769 ;; ">" (function end-of-buffer))
770 (define-key mime-view-mode-map
771 "?" (function describe-mode))
772 (define-key mime-view-mode-map
773 [tab] (function mime-view-move-to-next))
774 (define-key mime-view-mode-map
775 [delete] (function mime-view-scroll-down-entity))
776 (define-key mime-view-mode-map
777 [backspace] (function mime-view-scroll-down-entity))
778 (if (functionp default)
779 (cond (running-xemacs
780 (set-keymap-default-binding mime-view-mode-map default)
783 (setq mime-view-mode-map
784 (append mime-view-mode-map (list (cons t default))))
787 (define-key mime-view-mode-map
788 mouse-button-2 (function mime-button-dispatcher))
790 (cond (running-xemacs
791 (define-key mime-view-mode-map
792 mouse-button-3 (function mime-view-xemacs-popup-menu))
794 ((>= emacs-major-version 19)
795 (define-key mime-view-mode-map [menu-bar mime-view]
796 (cons mime-view-menu-title
797 (make-sparse-keymap mime-view-menu-title)))
800 (define-key mime-view-mode-map
801 (vector 'menu-bar 'mime-view (car item))
802 (cons (nth 1 item)(nth 2 item))
805 (reverse mime-view-menu-list)
808 (use-local-map mime-view-mode-map)
809 (run-hooks 'mime-view-define-keymap-hook)
812 (defsubst mime-hide-echo-buffer ()
813 "Hide mime-echo buffer."
814 (let ((win (get-buffer-window mime-echo-buffer-name)))
819 (defun mime-view-mode (&optional mother ctl encoding ibuf obuf
820 default-keymap-or-function)
821 "Major mode for viewing MIME message.
823 Here is a list of the standard keys for mime-view-mode.
828 u Move to upper content
829 p or M-TAB Move to previous content
830 n or TAB Move to next content
831 SPC Scroll up or move to next content
832 M-SPC or DEL Scroll down or move to previous content
833 RET Move to next line
834 M-RET Move to previous line
835 v Decode current content as `play mode'
836 e Decode current content as `extract mode'
837 C-c C-p Decode current content as `print mode'
838 a Followup to current content.
841 button-2 Move to point under the mouse cursor
842 and decode current content as `play mode'
845 (let ((buf (get-buffer mime-echo-buffer-name)))
850 (mime-hide-echo-buffer)
852 (let ((ret (mime-view-setup-buffers ctl encoding ibuf obuf))
853 (win-conf (current-window-configuration))
856 (switch-to-buffer ret)
857 (setq mime::preview/original-window-configuration win-conf)
860 (setq mime-mother-buffer mother)
862 (mime-view-define-keymap default-keymap-or-function)
863 (let ((point (next-single-property-change (point-min) 'mime-view-cinfo)))
866 (goto-char (point-min))
867 (search-forward "\n\n" nil t)
869 (run-hooks 'mime-view-mode-hook)
876 (autoload 'mime-view-play-current-entity "mime-play" "Play current entity." t)
878 (defun mime-view-extract-current-entity ()
879 "Extract current entity into file (maybe).
880 It decodes current entity to call internal or external method as
881 \"extract\" mode. The method is selected from variable
882 `mime-acting-condition'."
884 (mime-view-play-current-entity "extract")
887 (defun mime-view-print-current-entity ()
888 "Print current entity (maybe).
889 It decodes current entity to call internal or external method as
890 \"print\" mode. The method is selected from variable
891 `mime-acting-condition'."
893 (mime-view-play-current-entity "print")
900 (defun mime-view-get-original-major-mode ()
901 "Return major-mode of original buffer.
902 If a current buffer has mime-mother-buffer, return original major-mode
903 of the mother-buffer."
904 (if mime-mother-buffer
906 (set-buffer mime-mother-buffer)
907 (mime-view-get-original-major-mode)
909 mime-view-original-major-mode))
911 (defun mime-view-follow-current-entity ()
912 "Write follow message to current entity.
913 It calls following-method selected from variable
914 `mime-view-following-method-alist'."
916 (let ((root-cinfo (get-text-property (point-min) 'mime-view-cinfo))
918 (while (null (setq cinfo (get-text-property (point) 'mime-view-cinfo)))
921 (let* ((p-beg (previous-single-property-change (point) 'mime-view-cinfo))
923 (rcnum (mime::content-info/rcnum cinfo))
928 (if (eq (next-single-property-change (point-min)
934 ((eq (next-single-property-change p-beg 'mime-view-cinfo)
938 (setq p-end (next-single-property-change p-beg 'mime-view-cinfo))
940 (setq p-end (point-max))
943 (setq p-end (point-max))
951 (next-single-property-change
952 (point) 'mime-view-cinfo))
954 (let ((rc (mime::content-info/rcnum
955 (get-text-property (point)
957 (or (equal rcnum (nthcdr (- (length rc) len) rc))
962 (setq p-end (point-max))
965 (let* ((mode (mime-view-get-original-major-mode))
966 (new-name (format "%s-%s" (buffer-name) (reverse rcnum)))
968 (the-buf (current-buffer))
969 (a-buf mime-raw-buffer)
972 (set-buffer (setq new-buf (get-buffer-create new-name)))
974 (insert-buffer-substring the-buf p-beg p-end)
975 (goto-char (point-min))
976 (if (mime-view-header-visible-p rcnum root-cinfo)
977 (delete-region (goto-char (point-min))
978 (if (re-search-forward "^$" nil t)
982 (goto-char (point-min))
984 (goto-char (point-min))
985 (let ((rcnum (mime::content-info/rcnum cinfo)) ci str)
990 (setq ci (mime-article/rcnum-to-cinfo rcnum))
993 (mime::content-info/point-min ci)
994 (mime::content-info/point-max ci)
996 (std11-header-string-except
998 (apply (function regexp-or) fields)
1000 (if (string= (mime::content-info/type ci)
1007 (setq fields (std11-collect-field-names)
1011 (let ((rest mime-view-following-required-fields-list))
1013 (let ((field-name (car rest)))
1014 (or (std11-field-body field-name)
1020 (set-buffer the-buf)
1021 (set-buffer mime-mother-buffer)
1022 (set-buffer mime-raw-buffer)
1023 (std11-field-body field-name)
1027 (setq rest (cdr rest))
1029 (eword-decode-header)
1031 (let ((f (cdr (assq mode mime-view-following-method-alist))))
1036 "Sorry, following method for %s is not implemented yet."
1045 (defun mime-view-display-x-face ()
1047 (save-window-excursion
1048 (set-buffer mime-raw-buffer)
1049 (mime-view-x-face-function)
1056 (defun mime-view-move-to-upper ()
1057 "Move to upper entity.
1058 If there is no upper entity, call function `mime-view-quit'."
1061 (while (null (setq cinfo (get-text-property (point) 'mime-view-cinfo)))
1064 (let ((r (mime-article/rcnum-to-cinfo
1065 (cdr (mime::content-info/rcnum cinfo))
1066 (get-text-property 1 'mime-view-cinfo)))
1069 (while (setq point (previous-single-property-change
1070 (point) 'mime-view-cinfo))
1072 (if (eq r (get-text-property (point) 'mime-view-cinfo))
1079 (defun mime-view-move-to-previous ()
1080 "Move to previous entity.
1081 If there is no previous entity, it calls function registered in
1082 variable `mime-view-over-to-previous-method-alist'."
1084 (while (null (get-text-property (point) 'mime-view-cinfo))
1087 (let ((point (previous-single-property-change (point) 'mime-view-cinfo)))
1090 (let ((f (assq mime-view-original-major-mode
1091 mime-view-over-to-previous-method-alist)))
1097 (defun mime-view-move-to-next ()
1098 "Move to next entity.
1099 If there is no previous entity, it calls function registered in
1100 variable `mime-view-over-to-next-method-alist'."
1102 (let ((point (next-single-property-change (point) 'mime-view-cinfo)))
1105 (let ((f (assq mime-view-original-major-mode
1106 mime-view-over-to-next-method-alist)))
1112 (defun mime-view-scroll-up-entity (&optional h)
1113 "Scroll up current entity.
1114 If reached to (point-max), it calls function registered in variable
1115 `mime-view-over-to-next-method-alist'."
1118 (setq h (1- (window-height)))
1120 (if (= (point) (point-max))
1121 (let ((f (assq mime-view-original-major-mode
1122 mime-view-over-to-next-method-alist)))
1127 (or (next-single-property-change (point) 'mime-view-cinfo)
1130 (if (> (point) point)
1135 (defun mime-view-scroll-down-entity (&optional h)
1136 "Scroll down current entity.
1137 If reached to (point-min), it calls function registered in variable
1138 `mime-view-over-to-previous-method-alist'."
1141 (setq h (1- (window-height)))
1143 (if (= (point) (point-min))
1144 (let ((f (assq mime-view-original-major-mode
1145 mime-view-over-to-previous-method-alist)))
1152 (while (> (point) 1)
1154 (previous-single-property-change (point)
1160 (setq point (point-min))
1162 (forward-line (- h))
1163 (if (< (point) point)
1167 (defun mime-view-next-line-content ()
1169 (mime-view-scroll-up-entity 1)
1172 (defun mime-view-previous-line-content ()
1174 (mime-view-scroll-down-entity 1)
1181 (defun mime-view-quit ()
1182 "Quit from MIME-View buffer.
1183 It calls function registered in variable
1184 `mime-view-quitting-method-alist'."
1186 (let ((r (assq mime-view-original-major-mode
1187 mime-view-quitting-method-alist)))
1192 (defun mime-view-show-summary ()
1194 It calls function registered in variable
1195 `mime-view-show-summary-method'."
1197 (let ((r (assq mime-view-original-major-mode
1198 mime-view-show-summary-method)))
1203 (defun mime-view-kill-buffer ()
1205 (kill-buffer (current-buffer))
1212 (provide 'mime-view)
1214 (run-hooks 'mime-view-load-hook)
1216 ;;; mime-view.el ends here