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.111 $
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.111 1997-09-05 16:07:25 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 media-type media-subtype)
213 (let ((ctype (if media-type
215 (format "%s/%s" media-type media-subtype)
216 (symbol-name media-type)
218 (and (member ctype mime-view-visible-media-type-list)
219 (if (and (eq media-type 'application)
220 (eq media-subtype 'octet-stream))
221 (let ((ccinfo (mime-article/rcnum-to-cinfo rcnum cinfo)))
222 (member (mime-entity-info-encoding ccinfo)
223 '(nil "7bit" "8bit"))
232 (defun mime-view-insert-entity-button (rcnum cinfo ctype params subj encoding)
233 "Insert entity-button."
235 (let ((access-type (assoc "access-type" params))
236 (num (or (cdr (assoc "x-part-number" params))
240 (format "%s" (1+ num))
246 (let ((server (assoc "server" params)))
247 (setq access-type (cdr access-type))
249 (format "%s %s ([%s] %s)"
250 num subj access-type (cdr server))
251 (let ((site (cdr (assoc "site" params)))
252 (dir (cdr (assoc "directory" params)))
254 (format "%s %s ([%s] %s:%s)"
255 num subj access-type site dir)
259 (let ((charset (cdr (assoc "charset" params))))
265 (concat "; " charset)
266 (if encoding (concat " (" encoding ")"))
269 (if (>= (+ (current-column)(length rest))(window-width))
273 (function mime-view-play-current-entity))
276 (defun mime-view-entity-button-function
277 (rcnum cinfo ctype params subj encoding)
278 "Insert entity button conditionally.
279 Please redefine this function if you want to change default setting."
281 (string= ctype "application/x-selection")
282 (and (string= ctype "application/octet-stream")
284 (mime-article/rcnum-to-cinfo (cdr rcnum) cinfo)))
285 (and (eq (mime-entity-info-media-type entity-info)
287 (eq (mime-entity-info-media-subtype entity-info)
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
341 media-type media-subtype
343 "Insert entity separator conditionally.
344 Please redefine this function if you want to change default setting."
345 (or (mime-view-header-visible-p rcnum cinfo)
346 (mime-view-body-visible-p rcnum cinfo media-type media-subtype)
348 (goto-char (point-max))
353 ;;; @@ buffer local variables
356 ;;; @@@ in raw buffer
359 (defvar mime::article/content-info
360 "Information about structure of message.
361 Please use reference function `mime::content-info/SLOT-NAME' to
362 reference slot of content-info. Their argument is only content-info.
364 Following is a list of slots of the structure:
366 rcnum reversed content-number (list)
367 point-min beginning point of region in raw-buffer
368 point-max end point of region in raw-buffer
369 type media-type/subtype (string or nil)
370 parameters parameter of Content-Type field (association list)
371 encoding Content-Transfer-Encoding (string or nil)
372 children entities included in this entity (list of content-infos)
374 If a entity includes other entities in its body, such as multipart or
375 message/rfc822, content-infos of other entities are included in
376 `children', so content-info become a tree.")
377 (make-variable-buffer-local 'mime::article/content-info)
379 (defvar mime-view-buffer nil
380 "MIME View buffer corresponding with the (raw) buffer.")
381 (make-variable-buffer-local 'mime-view-buffer)
384 ;;; @@@ in view buffer
387 (defvar mime-mother-buffer nil
388 "Mother buffer corresponding with the (MIME-View) buffer.
389 If current MIME-View buffer is generated by other buffer, such as
390 message/partial, it is called `mother-buffer'.")
391 (make-variable-buffer-local 'mime-mother-buffer)
393 (defvar mime-raw-buffer nil
394 "Raw buffer corresponding with the (MIME-View) buffer.")
395 (make-variable-buffer-local 'mime-raw-buffer)
397 (defvar mime-view-original-major-mode nil
398 "Major-mode in mime-raw-buffer.")
399 (make-variable-buffer-local 'mime-view-original-major-mode)
401 (make-variable-buffer-local 'mime::preview/original-window-configuration)
404 ;;; @@ quitting method
407 (defvar mime-view-quitting-method-alist
408 '((mime-show-message-mode
409 . mime-view-quitting-method-for-mime-show-message-mode))
410 "Alist of major-mode vs. quitting-method of mime-view.")
412 (defvar mime-view-over-to-previous-method-alist nil)
413 (defvar mime-view-over-to-next-method-alist nil)
415 (defvar mime-view-show-summary-method nil
416 "Alist of major-mode vs. show-summary-method.")
419 ;;; @@ following method
422 (defvar mime-view-following-method-alist nil
423 "Alist of major-mode vs. following-method of mime-view.")
425 (defvar mime-view-following-required-fields-list
432 ;; hack from Gnus 5.0.4.
434 (defvar mime-view-x-face-to-pbm-command
435 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm")
437 (defvar mime-view-x-face-command
438 (concat mime-view-x-face-to-pbm-command
440 "String to be executed to display an X-Face field.
441 The command will be executed in a sub-shell asynchronously.
442 The compressed face will be piped to this command.")
444 (defun mime-view-x-face-function ()
445 "Function to display X-Face field. You can redefine to customize."
446 ;; 1995/10/12 (c.f. tm-eng:130)
447 ;; fixed by Eric Ding <ericding@San-Jose.ate.slb.com>
449 (narrow-to-region (point-min) (re-search-forward "^$" nil t))
451 (goto-char (point-min))
452 (if (re-search-forward "^X-Face:[ \t]*" nil t)
453 (let ((beg (match-end 0))
454 (end (std11-field-end))
456 (call-process-region beg end "sh" nil 0 nil
457 "-c" mime-view-x-face-command)
464 (defun mime-view-setup-buffers (&optional ctl encoding ibuf obuf)
470 (or mime-view-redisplay
471 (setq mime::article/content-info (mime-parse-message ctl encoding))
473 (let* ((cinfo mime::article/content-info)
474 (pcl (mime/flatten-content-info cinfo))
475 (the-buf (current-buffer))
479 (setq obuf (concat "*Preview-" (buffer-name the-buf) "*")))
480 (set-buffer (get-buffer-create obuf))
481 (let ((inhibit-read-only t))
482 ;;(setq buffer-read-only nil)
485 (setq mime-raw-buffer the-buf)
486 (setq mime-view-original-major-mode mode)
487 (setq major-mode 'mime-view-mode)
488 (setq mode-name "MIME-View")
490 (mime-view-display-entity (car pcl) cinfo the-buf obuf)
493 (set-buffer-modified-p nil)
495 (setq buffer-read-only t)
498 (setq mime-view-buffer obuf)
501 (defun mime-view-display-entity (content cinfo ibuf obuf)
502 "Display entity from content-info CONTENT."
503 (let* ((beg (mime-entity-info-point-min content))
504 (end (mime-entity-info-point-max content))
505 (media-type (mime-entity-info-media-type content))
506 (media-subtype (mime-entity-info-media-subtype content))
507 (ctype (if media-type
509 (format "%s/%s" media-type media-subtype)
510 (symbol-name media-type)
512 (params (mime-entity-info-parameters content))
513 (encoding (mime-entity-info-encoding content))
514 (rcnum (mime-entity-info-rnum content))
518 (setq he (if (re-search-forward "^$" nil t)
525 (narrow-to-region beg end)
528 (mime-article/get-subject params encoding)))
532 (narrow-to-region nb nb)
533 (mime-view-entity-button-function rcnum cinfo ctype params subj encoding)
534 (if (mime-view-header-visible-p rcnum cinfo)
535 (mime-view-display-header beg he)
537 (if (and (null rcnum)
539 ctype mime-view-content-button-visible-ctype-list))
541 (goto-char (point-max))
542 (mime-view-insert-entity-button
543 rcnum cinfo ctype params subj encoding)
545 (cond ((mime-view-body-visible-p rcnum cinfo media-type media-subtype)
546 (mime-view-display-body he end
547 rcnum cinfo ctype params subj encoding)
549 ((and (eq media-type 'message)(eq media-subtype 'partial))
550 (mime-view-insert-message/partial-button)
553 (null (mime-entity-info-children cinfo))
555 (goto-char (point-max))
556 (mime-view-insert-entity-button
557 rcnum cinfo ctype params subj encoding)
559 (mime-view-entity-separator-function
560 rcnum cinfo media-type media-subtype params subj)
561 (setq ne (point-max))
563 (put-text-property nb ne 'mime-view-raw-buffer ibuf)
564 (put-text-property nb ne 'mime-view-cinfo content)
568 (defun mime-view-display-header (beg end)
570 (narrow-to-region (point)(point))
571 (insert-buffer-substring mime-raw-buffer beg end)
572 (let ((f (cdr (assq mime-view-original-major-mode
573 mime-view-content-header-filter-alist))))
576 (mime-view-default-content-header-filter)
578 (run-hooks 'mime-view-content-header-filter-hook)
581 (defun mime-view-display-body (beg end rcnum cinfo ctype params subj encoding)
583 (narrow-to-region (point-max)(point-max))
584 (insert-buffer-substring mime-raw-buffer beg end)
585 (let ((f (cdr (or (assoc ctype mime-view-content-filter-alist)
586 (assq t mime-view-content-filter-alist)))))
588 (funcall f ctype params encoding)
592 (defun mime-view-insert-message/partial-button ()
594 (goto-char (point-max))
595 (if (not (search-backward "\n\n" nil t))
598 (goto-char (point-max))
599 (narrow-to-region (point-max)(point-max))
600 (insert mime-view-announcement-for-message/partial)
601 (mime-add-button (point-min)(point-max)
602 (function mime-view-play-current-entity))
605 (defun mime-article/get-uu-filename (param &optional encoding)
606 (if (member (or encoding
607 (cdr (assq 'encoding param))
609 mime-view-uuencode-encoding-name-list)
611 (or (if (re-search-forward "^begin [0-9]+ " nil t)
612 (if (looking-at ".+$")
613 (buffer-substring (match-beginning 0)(match-end 0))
618 (defun mime-article/get-subject (param &optional encoding)
619 (or (std11-find-field-body '("Content-Description" "Subject"))
621 (if (or (and (setq ret (mime/Content-Disposition))
622 (setq ret (assoc "filename" (cdr ret)))
624 (setq ret (assoc "name" param))
625 (setq ret (assoc "x-name" param))
627 (std11-strip-quoted-string (cdr ret))
629 (mime-article/get-uu-filename param encoding)
633 ;;; @ content information
636 (defun mime-article/point-content-number (p &optional cinfo)
638 (setq cinfo mime::article/content-info)
640 (let ((b (mime-entity-info-point-min cinfo))
641 (e (mime-entity-info-point-max cinfo))
642 (c (mime-entity-info-children cinfo))
644 (if (and (<= b p)(<= p e))
645 (or (let (co ret (sn 0))
649 (setq ret (mime-article/point-content-number p co))
650 (cond ((eq ret t) (throw 'tag (list sn)))
651 (ret (throw 'tag (cons sn ret)))
658 (defun mime-article/rcnum-to-cinfo (rcnum &optional cinfo)
660 (setq cinfo mime::article/content-info)
664 (equal (mime-entity-info-rnum ci) rcnum)
666 (mime/flatten-content-info cinfo)
669 (defun mime-article/cnum-to-cinfo (cn &optional cinfo)
671 (setq cinfo mime::article/content-info)
678 (let ((rc (nth sn (mime-entity-info-children cinfo))))
680 (mime-article/cnum-to-cinfo (cdr cn) rc)
684 (defun mime/flatten-content-info (&optional cinfo)
686 (setq cinfo mime::article/content-info)
688 (let ((dest (list cinfo))
689 (rcl (mime-entity-info-children cinfo))
692 (setq dest (nconc dest (mime/flatten-content-info (car rcl))))
698 ;;; @ MIME viewer mode
701 (defconst mime-view-menu-title "MIME-View")
702 (defconst mime-view-menu-list
703 '((up "Move to upper content" mime-view-move-to-upper)
704 (previous "Move to previous content" mime-view-move-to-previous)
705 (next "Move to next content" mime-view-move-to-next)
706 (scroll-down "Scroll to previous content" mime-view-scroll-down-entity)
707 (scroll-up "Scroll to next content" mime-view-scroll-up-entity)
708 (play "Play Content" mime-view-play-current-entity)
709 (extract "Extract Content" mime-view-extract-current-entity)
710 (print "Print" mime-view-print-current-entity)
711 (x-face "Show X Face" mime-view-display-x-face)
713 "Menu for MIME Viewer")
715 (cond (running-xemacs
716 (defvar mime-view-xemacs-popup-menu
717 (cons mime-view-menu-title
720 (vector (nth 1 item)(nth 2 item) t)
722 mime-view-menu-list)))
723 (defun mime-view-xemacs-popup-menu (event)
724 "Popup the menu in the MIME Viewer buffer"
726 (select-window (event-window event))
727 (set-buffer (event-buffer event))
728 (popup-menu 'mime-view-xemacs-popup-menu))
729 (defvar mouse-button-2 'button2)
732 (defvar mouse-button-2 [mouse-2])
735 (defun mime-view-define-keymap (&optional default)
736 (let ((mime-view-mode-map (if (keymapp default)
737 (copy-keymap default)
740 (define-key mime-view-mode-map
741 "u" (function mime-view-move-to-upper))
742 (define-key mime-view-mode-map
743 "p" (function mime-view-move-to-previous))
744 (define-key mime-view-mode-map
745 "n" (function mime-view-move-to-next))
746 (define-key mime-view-mode-map
747 "\e\t" (function mime-view-move-to-previous))
748 (define-key mime-view-mode-map
749 "\t" (function mime-view-move-to-next))
750 (define-key mime-view-mode-map
751 " " (function mime-view-scroll-up-entity))
752 (define-key mime-view-mode-map
753 "\M- " (function mime-view-scroll-down-entity))
754 (define-key mime-view-mode-map
755 "\177" (function mime-view-scroll-down-entity))
756 (define-key mime-view-mode-map
757 "\C-m" (function mime-view-next-line-content))
758 (define-key mime-view-mode-map
759 "\C-\M-m" (function mime-view-previous-line-content))
760 (define-key mime-view-mode-map
761 "v" (function mime-view-play-current-entity))
762 (define-key mime-view-mode-map
763 "e" (function mime-view-extract-current-entity))
764 (define-key mime-view-mode-map
765 "\C-c\C-p" (function mime-view-print-current-entity))
766 (define-key mime-view-mode-map
767 "a" (function mime-view-follow-current-entity))
768 (define-key mime-view-mode-map
769 "q" (function mime-view-quit))
770 (define-key mime-view-mode-map
771 "h" (function mime-view-show-summary))
772 (define-key mime-view-mode-map
773 "\C-c\C-x" (function mime-view-kill-buffer))
774 ;; (define-key mime-view-mode-map
775 ;; "<" (function beginning-of-buffer))
776 ;; (define-key mime-view-mode-map
777 ;; ">" (function end-of-buffer))
778 (define-key mime-view-mode-map
779 "?" (function describe-mode))
780 (define-key mime-view-mode-map
781 [tab] (function mime-view-move-to-next))
782 (define-key mime-view-mode-map
783 [delete] (function mime-view-scroll-down-entity))
784 (define-key mime-view-mode-map
785 [backspace] (function mime-view-scroll-down-entity))
786 (if (functionp default)
787 (cond (running-xemacs
788 (set-keymap-default-binding mime-view-mode-map default)
791 (setq mime-view-mode-map
792 (append mime-view-mode-map (list (cons t default))))
795 (define-key mime-view-mode-map
796 mouse-button-2 (function mime-button-dispatcher))
798 (cond (running-xemacs
799 (define-key mime-view-mode-map
800 mouse-button-3 (function mime-view-xemacs-popup-menu))
802 ((>= emacs-major-version 19)
803 (define-key mime-view-mode-map [menu-bar mime-view]
804 (cons mime-view-menu-title
805 (make-sparse-keymap mime-view-menu-title)))
808 (define-key mime-view-mode-map
809 (vector 'menu-bar 'mime-view (car item))
810 (cons (nth 1 item)(nth 2 item))
813 (reverse mime-view-menu-list)
816 (use-local-map mime-view-mode-map)
817 (run-hooks 'mime-view-define-keymap-hook)
820 (defsubst mime-hide-echo-buffer ()
821 "Hide mime-echo buffer."
822 (let ((win (get-buffer-window mime-echo-buffer-name)))
827 (defun mime-view-mode (&optional mother ctl encoding ibuf obuf
828 default-keymap-or-function)
829 "Major mode for viewing MIME message.
831 Here is a list of the standard keys for mime-view-mode.
836 u Move to upper content
837 p or M-TAB Move to previous content
838 n or TAB Move to next content
839 SPC Scroll up or move to next content
840 M-SPC or DEL Scroll down or move to previous content
841 RET Move to next line
842 M-RET Move to previous line
843 v Decode current content as `play mode'
844 e Decode current content as `extract mode'
845 C-c C-p Decode current content as `print mode'
846 a Followup to current content.
849 button-2 Move to point under the mouse cursor
850 and decode current content as `play mode'
853 (let ((buf (get-buffer mime-echo-buffer-name)))
858 (mime-hide-echo-buffer)
860 (let ((ret (mime-view-setup-buffers ctl encoding ibuf obuf))
861 (win-conf (current-window-configuration))
864 (switch-to-buffer ret)
865 (setq mime::preview/original-window-configuration win-conf)
868 (setq mime-mother-buffer mother)
870 (mime-view-define-keymap default-keymap-or-function)
871 (let ((point (next-single-property-change (point-min) 'mime-view-cinfo)))
874 (goto-char (point-min))
875 (search-forward "\n\n" nil t)
877 (run-hooks 'mime-view-mode-hook)
884 (autoload 'mime-view-play-current-entity "mime-play" "Play current entity." t)
886 (defun mime-view-extract-current-entity ()
887 "Extract current entity into file (maybe).
888 It decodes current entity to call internal or external method as
889 \"extract\" mode. The method is selected from variable
890 `mime-acting-condition'."
892 (mime-view-play-current-entity "extract")
895 (defun mime-view-print-current-entity ()
896 "Print current entity (maybe).
897 It decodes current entity to call internal or external method as
898 \"print\" mode. The method is selected from variable
899 `mime-acting-condition'."
901 (mime-view-play-current-entity "print")
908 (defun mime-view-get-original-major-mode ()
909 "Return major-mode of original buffer.
910 If a current buffer has mime-mother-buffer, return original major-mode
911 of the mother-buffer."
912 (if mime-mother-buffer
914 (set-buffer mime-mother-buffer)
915 (mime-view-get-original-major-mode)
917 mime-view-original-major-mode))
919 (defun mime-view-follow-current-entity ()
920 "Write follow message to current entity.
921 It calls following-method selected from variable
922 `mime-view-following-method-alist'."
924 (let ((root-cinfo (get-text-property (point-min) 'mime-view-cinfo))
926 (while (null (setq cinfo (get-text-property (point) 'mime-view-cinfo)))
929 (let* ((p-beg (previous-single-property-change (point) 'mime-view-cinfo))
931 (rcnum (mime-entity-info-rnum cinfo))
936 (if (eq (next-single-property-change (point-min)
942 ((eq (next-single-property-change p-beg 'mime-view-cinfo)
946 (setq p-end (next-single-property-change p-beg 'mime-view-cinfo))
948 (setq p-end (point-max))
951 (setq p-end (point-max))
959 (next-single-property-change
960 (point) 'mime-view-cinfo))
962 (let ((rc (mime-entity-info-rnum
963 (get-text-property (point)
965 (or (equal rcnum (nthcdr (- (length rc) len) rc))
970 (setq p-end (point-max))
973 (let* ((mode (mime-view-get-original-major-mode))
974 (new-name (format "%s-%s" (buffer-name) (reverse rcnum)))
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 rcnum root-cinfo)
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 ((rcnum (mime-entity-info-rnum cinfo)) ci str)
998 (setq ci (mime-article/rcnum-to-cinfo rcnum))
1001 (mime-entity-info-point-min ci)
1002 (mime-entity-info-point-max ci)
1004 (std11-header-string-except
1006 (apply (function regexp-or) fields)
1009 (eq (mime-entity-info-media-type ci) 'message)
1010 (eq (mime-entity-info-media-subtype ci) 'rfc822))
1016 (setq fields (std11-collect-field-names)
1020 (let ((rest mime-view-following-required-fields-list))
1022 (let ((field-name (car rest)))
1023 (or (std11-field-body field-name)
1029 (set-buffer the-buf)
1030 (set-buffer mime-mother-buffer)
1031 (set-buffer mime-raw-buffer)
1032 (std11-field-body field-name)
1036 (setq rest (cdr rest))
1038 (eword-decode-header)
1040 (let ((f (cdr (assq mode mime-view-following-method-alist))))
1045 "Sorry, following method for %s is not implemented yet."
1054 (defun mime-view-display-x-face ()
1056 (save-window-excursion
1057 (set-buffer mime-raw-buffer)
1058 (mime-view-x-face-function)
1065 (defun mime-view-move-to-upper ()
1066 "Move to upper entity.
1067 If there is no upper entity, call function `mime-view-quit'."
1070 (while (null (setq cinfo (get-text-property (point) 'mime-view-cinfo)))
1073 (let ((r (mime-article/rcnum-to-cinfo
1074 (cdr (mime-entity-info-rnum cinfo))
1075 (get-text-property 1 'mime-view-cinfo)))
1078 (while (setq point (previous-single-property-change
1079 (point) 'mime-view-cinfo))
1081 (if (eq r (get-text-property (point) 'mime-view-cinfo))
1088 (defun mime-view-move-to-previous ()
1089 "Move to previous entity.
1090 If there is no previous entity, it calls function registered in
1091 variable `mime-view-over-to-previous-method-alist'."
1093 (while (null (get-text-property (point) 'mime-view-cinfo))
1096 (let ((point (previous-single-property-change (point) 'mime-view-cinfo)))
1099 (let ((f (assq mime-view-original-major-mode
1100 mime-view-over-to-previous-method-alist)))
1106 (defun mime-view-move-to-next ()
1107 "Move to next entity.
1108 If there is no previous entity, it calls function registered in
1109 variable `mime-view-over-to-next-method-alist'."
1111 (let ((point (next-single-property-change (point) 'mime-view-cinfo)))
1114 (let ((f (assq mime-view-original-major-mode
1115 mime-view-over-to-next-method-alist)))
1121 (defun mime-view-scroll-up-entity (&optional h)
1122 "Scroll up current entity.
1123 If reached to (point-max), it calls function registered in variable
1124 `mime-view-over-to-next-method-alist'."
1127 (setq h (1- (window-height)))
1129 (if (= (point) (point-max))
1130 (let ((f (assq mime-view-original-major-mode
1131 mime-view-over-to-next-method-alist)))
1136 (or (next-single-property-change (point) 'mime-view-cinfo)
1139 (if (> (point) point)
1144 (defun mime-view-scroll-down-entity (&optional h)
1145 "Scroll down current entity.
1146 If reached to (point-min), it calls function registered in variable
1147 `mime-view-over-to-previous-method-alist'."
1150 (setq h (1- (window-height)))
1152 (if (= (point) (point-min))
1153 (let ((f (assq mime-view-original-major-mode
1154 mime-view-over-to-previous-method-alist)))
1161 (while (> (point) 1)
1163 (previous-single-property-change (point)
1169 (setq point (point-min))
1171 (forward-line (- h))
1172 (if (< (point) point)
1176 (defun mime-view-next-line-content ()
1178 (mime-view-scroll-up-entity 1)
1181 (defun mime-view-previous-line-content ()
1183 (mime-view-scroll-down-entity 1)
1190 (defun mime-view-quit ()
1191 "Quit from MIME-View buffer.
1192 It calls function registered in variable
1193 `mime-view-quitting-method-alist'."
1195 (let ((r (assq mime-view-original-major-mode
1196 mime-view-quitting-method-alist)))
1201 (defun mime-view-show-summary ()
1203 It calls function registered in variable
1204 `mime-view-show-summary-method'."
1206 (let ((r (assq mime-view-original-major-mode
1207 mime-view-show-summary-method)))
1212 (defun mime-view-kill-buffer ()
1214 (kill-buffer (current-buffer))
1221 (provide 'mime-view)
1223 (run-hooks 'mime-view-load-hook)
1225 ;;; mime-view.el ends here