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) ")"))
49 (defvar mime-acting-condition
50 '(((type . text)(subtype . plain)
51 (method "tm-plain" nil 'file "" 'encoding 'mode 'name)
54 ((type . text)(subtype . html)
55 (method "tm-html" nil 'file "" 'encoding 'mode 'name)
58 ((type . text)(subtype . x-rot13-47)
59 (method . mime-method-to-display-caesar)
62 ((type . text)(subtype . x-rot13-47-48)
63 (method . mime-method-to-display-caesar)
67 ((type . audio)(subtype . basic)
68 (method "tm-au" nil 'file "" 'encoding 'mode 'name)
73 (method "tm-image" nil 'file "" 'encoding 'mode 'name)
77 ((type . video)(subtype . mpeg)
78 (method "tm-mpeg" nil 'file "" 'encoding 'mode 'name)
82 ((type . application)(subtype . postscript)
83 (method "tm-ps" nil 'file "" 'encoding 'mode 'name)
86 ((type . application)(subtype . octet-stream)
87 (method . mime-method-to-save)(mode "play" "print")
90 ((type . message)(subtype . external-body)
91 ("access-type" . "anon-ftp")
92 (method . mime-method-to-display-message/external-ftp)
94 ((type . message)(subtype . rfc822)
95 (method . mime-method-to-display-message/rfc822)
98 ((type . message)(subtype . partial)
99 (method . mime-method-to-store-message/partial)
103 ((method "metamail" t "-m" "tm" "-x" "-d" "-z" "-e" 'file)
106 ((method . mime-method-to-save)(mode . "extract"))
109 (defvar mime-view-childrens-header-showing-Content-Type-list
110 '("message/rfc822" "message/news"))
112 (defvar mime-view-visible-media-type-list
113 '("text/plain" nil "text/richtext" "text/enriched"
114 "text/rfc822-headers"
115 "text/x-latex" "application/x-latex"
116 "message/delivery-status"
117 "application/pgp" "text/x-pgp"
118 "application/octet-stream"
119 "application/x-selection" "application/x-comment")
120 "*List of media-types to be able to display in MIME-preview buffer.
121 Each elements are string of TYPE/SUBTYPE, e.g. \"text/plain\".")
123 (defvar mime-view-content-button-visible-ctype-list
124 '("application/pgp"))
126 (defvar mime-view-uuencode-encoding-name-list '("x-uue" "x-uuencode"))
128 (defvar mime-view-ignored-field-list
129 '(".*Received" ".*Path" ".*Id" "References"
130 "Replied" "Errors-To"
131 "Lines" "Sender" ".*Host" "Xref"
132 "Content-Type" "Precedence"
134 "All fields that match this list will be hidden in MIME preview buffer.
135 Each elements are regexp of field-name. [mime-view.el]")
137 (defvar mime-view-ignored-field-regexp
139 (apply (function regexp-or) mime-view-ignored-field-list)
142 (defvar mime-view-visible-field-list '("Dnas.*" "Message-Id")
143 "All fields that match this list will be displayed in MIME preview buffer.
144 Each elements are regexp of field-name.")
146 (defvar mime-view-redisplay nil)
148 (defvar mime-view-announcement-for-message/partial
149 (if (and (>= emacs-major-version 19) window-system)
151 \[[ This is message/partial style split message. ]]
152 \[[ Please press `v' key in this buffer ]]
153 \[[ or click here by mouse button-2. ]]"
155 \[[ This is message/partial style split message. ]]
156 \[[ Please press `v' key in this buffer. ]]"
163 (defun mime-view-insert-entity-button (rcnum cinfo
164 media-type media-subtype params
166 "Insert entity-button."
168 (let ((access-type (assoc "access-type" params))
169 (num (or (cdr (assoc "x-part-number" params))
173 (format "%s" (1+ num))
179 (let ((server (assoc "server" params)))
180 (setq access-type (cdr access-type))
182 (format "%s %s ([%s] %s)"
183 num subj access-type (cdr server))
184 (let ((site (cdr (assoc "site" params)))
185 (dir (cdr (assoc "directory" params)))
187 (format "%s %s ([%s] %s:%s)"
188 num subj access-type site dir)
192 (let ((charset (cdr (assoc "charset" params))))
196 (format " <%s/%s%s%s>"
197 media-type media-subtype
199 (concat "; " charset)
202 (concat " (" encoding ")")
204 (if (>= (+ (current-column)(length rest))(window-width))
208 (function mime-preview-play-current-entity))
211 (defun mime-view-entity-button-function (rcnum cinfo
212 media-type media-subtype
213 params subj encoding)
214 "Insert entity button conditionally.
215 Please redefine this function if you want to change default setting."
217 (and (eq media-type 'application)
218 (or (eq media-subtype 'x-selection)
219 (and (eq media-subtype 'octet-stream)
221 (mime-raw-reversed-entity-number-to-entity-info
223 (and (eq (mime-entity-info-media-type entity-info)
225 (eq (mime-entity-info-media-subtype entity-info)
228 (mime-view-insert-entity-button
229 rcnum cinfo media-type media-subtype params subj encoding)
233 ;;; @@ content header filter
236 (defun mime-view-cut-header ()
237 (goto-char (point-min))
238 (while (re-search-forward mime-view-ignored-field-regexp nil t)
239 (let* ((beg (match-beginning 0))
241 (name (buffer-substring beg end))
244 (let ((rest mime-view-visible-field-list))
246 (if (string-match (car rest) name)
249 (setq rest (cdr rest))))
252 (if (re-search-forward "^\\([^ \t]\\|$\\)" nil t)
257 (defun mime-view-default-content-header-filter ()
258 (mime-view-cut-header)
259 (eword-decode-header)
262 (defvar mime-view-content-header-filter-alist nil)
265 ;;; @@ content filter
268 (defvar mime-view-content-filter-alist
269 '(("text/enriched" . mime-view-filter-for-text/enriched)
270 ("text/richtext" . mime-view-filter-for-text/richtext)
271 (t . mime-view-filter-for-text/plain)
273 "Alist of media-types vs. corresponding MIME-preview filter functions.
274 Each element looks like (TYPE/SUBTYPE . FUNCTION) or (t . FUNCTION).
275 TYPE/SUBTYPE is a string of media-type and FUNCTION is a filter
276 function. t means default media-type.")
279 ;;; @@ entity separator
282 (defun mime-view-entity-separator-function (rcnum cinfo
283 media-type media-subtype
285 "Insert entity separator conditionally.
286 Please redefine this function if you want to change default setting."
287 (or (mime-view-header-visible-p rcnum cinfo)
288 (mime-view-body-visible-p rcnum cinfo media-type media-subtype)
290 (goto-char (point-max))
295 ;;; @@ buffer local variables
298 ;;; @@@ in raw-buffer
301 (defvar mime-raw-message-info
302 "Information about structure of message.
303 Please use reference function `mime-entity-info-SLOT' to get value of
306 Following is a list of slots of the structure:
308 rcnum reversed content-number (list)
309 point-min beginning point of region in raw-buffer
310 point-max end point of region in raw-buffer
311 type media-type (symbol)
312 subtype media-subtype (symbol)
313 type/subtype media-type/subtype (string or nil)
314 parameters parameter of Content-Type field (association list)
315 encoding Content-Transfer-Encoding (string or nil)
316 children entities included in this entity (list of content-infos)
318 If an entity includes other entities in its body, such as multipart or
319 message/rfc822, entity-infos of other entities are included in
320 `children', so entity-info become a tree.")
321 (make-variable-buffer-local 'mime-raw-message-info)
323 (defvar mime-preview-buffer nil
324 "MIME-preview buffer corresponding with the (raw) buffer.")
325 (make-variable-buffer-local 'mime-preview-buffer)
328 ;;; @@@ in preview-buffer
331 (defvar mime-mother-buffer nil
332 "Mother buffer corresponding with the (MIME-preview) buffer.
333 If current MIME-preview buffer is generated by other buffer, such as
334 message/partial, it is called `mother-buffer'.")
335 (make-variable-buffer-local 'mime-mother-buffer)
337 (defvar mime-raw-buffer nil
338 "Raw buffer corresponding with the (MIME-preview) buffer.")
339 (make-variable-buffer-local 'mime-raw-buffer)
341 (defvar mime-preview-original-major-mode nil
342 "Major-mode of mime-raw-buffer.")
343 (make-variable-buffer-local 'mime-preview-original-major-mode)
345 (make-variable-buffer-local 'mime-preview-original-window-configuration)
348 ;;; @@ quitting method
351 (defvar mime-view-quitting-method-alist
352 '((mime-show-message-mode
353 . mime-view-quitting-method-for-mime-show-message-mode))
354 "Alist of major-mode vs. quitting-method of mime-view.")
356 (defvar mime-view-over-to-previous-method-alist nil)
357 (defvar mime-view-over-to-next-method-alist nil)
359 (defvar mime-view-show-summary-method nil
360 "Alist of major-mode vs. show-summary-method.")
363 ;;; @@ following method
366 (defvar mime-view-following-method-alist nil
367 "Alist of major-mode vs. following-method of mime-view.")
369 (defvar mime-view-following-required-fields-list
376 ;; hack from Gnus 5.0.4.
378 (defvar mime-view-x-face-to-pbm-command
379 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm")
381 (defvar mime-view-x-face-command
382 (concat mime-view-x-face-to-pbm-command
384 "String to be executed to display an X-Face field.
385 The command will be executed in a sub-shell asynchronously.
386 The compressed face will be piped to this command.")
388 (defun mime-view-x-face-function ()
389 "Function to display X-Face field. You can redefine to customize."
390 ;; 1995/10/12 (c.f. tm-eng:130)
391 ;; fixed by Eric Ding <ericding@San-Jose.ate.slb.com>
393 (narrow-to-region (point-min) (re-search-forward "^$" nil t))
395 (goto-char (point-min))
396 (if (re-search-forward "^X-Face:[ \t]*" nil t)
397 (let ((beg (match-end 0))
398 (end (std11-field-end))
400 (call-process-region beg end "sh" nil 0 nil
401 "-c" mime-view-x-face-command)
408 (defun mime-view-setup-buffers (&optional ctl encoding ibuf obuf)
414 (or mime-view-redisplay
415 (setq mime-raw-message-info (mime-parse-message ctl encoding))
417 (let* ((cinfo mime-raw-message-info)
418 (pcl (mime-raw-flatten-message-info cinfo))
419 (the-buf (current-buffer))
423 (setq obuf (concat "*Preview-" (buffer-name the-buf) "*")))
424 (set-buffer (get-buffer-create obuf))
425 (let ((inhibit-read-only t))
426 ;;(setq buffer-read-only nil)
429 (setq mime-raw-buffer the-buf)
430 (setq mime-preview-original-major-mode mode)
431 (setq major-mode 'mime-view-mode)
432 (setq mode-name "MIME-View")
434 (mime-view-display-entity (car pcl) cinfo the-buf obuf)
437 (set-buffer-modified-p nil)
439 (setq buffer-read-only t)
442 (setq mime-preview-buffer obuf)
445 (defun mime-view-display-entity (content cinfo ibuf obuf)
446 "Display entity from content-info CONTENT."
447 (let* ((beg (mime-entity-info-point-min content))
448 (end (mime-entity-info-point-max content))
449 (media-type (mime-entity-info-media-type content))
450 (media-subtype (mime-entity-info-media-subtype content))
451 (ctype (if media-type
453 (format "%s/%s" media-type media-subtype)
454 (symbol-name media-type)
456 (params (mime-entity-info-parameters content))
457 (encoding (mime-entity-info-encoding content))
458 (rcnum (mime-entity-info-rnum content))
462 (setq he (if (re-search-forward "^$" nil t)
469 (narrow-to-region beg end)
472 (mime-raw-get-subject params encoding)))
476 (narrow-to-region nb nb)
477 (mime-view-entity-button-function
478 rcnum cinfo media-type media-subtype params subj encoding)
479 (if (mime-view-header-visible-p rcnum cinfo)
480 (mime-view-display-header beg he)
482 (if (and (null rcnum)
484 ctype mime-view-content-button-visible-ctype-list))
486 (goto-char (point-max))
487 (mime-view-insert-entity-button
488 rcnum cinfo media-type media-subtype params subj encoding)
490 (cond ((mime-view-body-visible-p rcnum cinfo media-type media-subtype)
491 (mime-view-display-body he end
492 rcnum cinfo ctype params subj encoding)
494 ((and (eq media-type 'message)(eq media-subtype 'partial))
495 (mime-view-insert-message/partial-button)
498 (null (mime-entity-info-children cinfo))
500 (goto-char (point-max))
501 (mime-view-insert-entity-button
502 rcnum cinfo media-type media-subtype params subj encoding)
504 (mime-view-entity-separator-function
505 rcnum cinfo media-type media-subtype params subj)
506 (setq ne (point-max))
508 (put-text-property nb ne 'mime-view-raw-buffer ibuf)
509 (put-text-property nb ne 'mime-view-cinfo content)
513 (defun mime-view-display-header (beg end)
515 (narrow-to-region (point)(point))
516 (insert-buffer-substring mime-raw-buffer beg end)
517 (let ((f (cdr (assq mime-preview-original-major-mode
518 mime-view-content-header-filter-alist))))
521 (mime-view-default-content-header-filter)
523 (run-hooks 'mime-view-content-header-filter-hook)
526 (defun mime-view-display-body (beg end rcnum cinfo ctype params subj encoding)
528 (narrow-to-region (point-max)(point-max))
529 (insert-buffer-substring mime-raw-buffer beg end)
530 (let ((f (cdr (or (assoc ctype mime-view-content-filter-alist)
531 (assq t mime-view-content-filter-alist)))))
533 (funcall f ctype params encoding)
537 (defun mime-view-insert-message/partial-button ()
539 (goto-char (point-max))
540 (if (not (search-backward "\n\n" nil t))
543 (goto-char (point-max))
544 (narrow-to-region (point-max)(point-max))
545 (insert mime-view-announcement-for-message/partial)
546 (mime-add-button (point-min)(point-max)
547 (function mime-preview-play-current-entity))
550 (defun mime-raw-get-uu-filename (param &optional encoding)
551 (if (member (or encoding
552 (cdr (assq 'encoding param))
554 mime-view-uuencode-encoding-name-list)
556 (or (if (re-search-forward "^begin [0-9]+ " nil t)
557 (if (looking-at ".+$")
558 (buffer-substring (match-beginning 0)(match-end 0))
563 (defun mime-raw-get-subject (param &optional encoding)
564 (or (std11-find-field-body '("Content-Description" "Subject"))
566 (if (or (and (setq ret (mime/Content-Disposition))
567 (setq ret (assoc "filename" (cdr ret)))
569 (setq ret (assoc "name" param))
570 (setq ret (assoc "x-name" param))
572 (std11-strip-quoted-string (cdr ret))
574 (mime-raw-get-uu-filename param encoding)
578 ;;; @ entity information
581 (defun mime-raw-point-to-entity-number (position &optional message-info)
582 "Return entity-number from POTION in mime-raw-buffer.
583 If optional argument MESSAGE-INFO is not specified,
584 `mime-raw-message-info' is used."
586 (setq message-info mime-raw-message-info))
587 (let ((b (mime-entity-info-point-min message-info))
588 (e (mime-entity-info-point-max message-info))
589 (c (mime-entity-info-children message-info))
591 (if (and (<= b position)(<= position e))
592 (or (let (co ret (sn 0))
596 (setq ret (mime-raw-point-to-entity-number position co))
597 (cond ((eq ret t) (throw 'tag (list sn)))
598 (ret (throw 'tag (cons sn ret)))
605 (defsubst mime-raw-reversed-entity-number-to-entity-info
606 (entity-number &optional message-info)
607 "Return entity-info from REVERSED-ENTITY-NUMBER in mime-raw-buffer.
608 If optional argument MESSAGE-INFO is not specified,
609 `mime-raw-message-info' is used."
610 (mime-raw-entity-number-to-entity-info (reverse entity-number) message-info))
612 (defun mime-raw-entity-number-to-entity-info (entity-number
613 &optional message-info)
614 "Return entity-info from ENTITY-NUMBER in mime-raw-buffer.
615 If optional argument MESSAGE-INFO is not specified,
616 `mime-raw-message-info' is used."
618 (setq message-info mime-raw-message-info))
619 (if (eq entity-number t)
621 (let ((sn (car entity-number)))
624 (let ((rc (nth sn (mime-entity-info-children message-info))))
626 (mime-raw-entity-number-to-entity-info (cdr entity-number) rc)
630 (defun mime-raw-flatten-message-info (&optional message-info)
631 "Return list of entity-infos in mime-raw-buffer.
632 If optional argument MESSAGE-INFO is not specified,
633 `mime-raw-message-info' is used."
635 (setq message-info mime-raw-message-info))
636 (let ((dest (list message-info))
637 (rcl (mime-entity-info-children message-info)))
639 (setq dest (nconc dest (mime-raw-flatten-message-info (car rcl))))
640 (setq rcl (cdr rcl)))
644 ;;; @@ predicate functions
647 (defun mime-view-header-visible-p (rcnum cinfo)
648 "Return non-nil if header of current entity is visible."
650 (member (mime-entity-info-type/subtype
651 (mime-raw-reversed-entity-number-to-entity-info
653 mime-view-childrens-header-showing-Content-Type-list)
656 (defun mime-view-body-visible-p (rcnum cinfo media-type media-subtype)
657 (let ((ctype (if media-type
659 (format "%s/%s" media-type media-subtype)
660 (symbol-name media-type)
662 (and (member ctype mime-view-visible-media-type-list)
663 (if (and (eq media-type 'application)
664 (eq media-subtype 'octet-stream))
666 (mime-raw-reversed-entity-number-to-entity-info
668 (member (mime-entity-info-encoding ccinfo)
669 '(nil "7bit" "8bit"))
675 ;;; @ MIME viewer mode
678 (defconst mime-view-menu-title "MIME-View")
679 (defconst mime-view-menu-list
680 '((up "Move to upper entity" mime-preview-move-to-upper)
681 (previous "Move to previous entity" mime-preview-move-to-previous)
682 (next "Move to next entity" mime-preview-move-to-next)
683 (scroll-down "Scroll-down" mime-preview-scroll-down-entity)
684 (scroll-up "Scroll-up" mime-preview-scroll-up-entity)
685 (play "Play current entity" mime-preview-play-current-entity)
686 (extract "Extract current entity" mime-preview-extract-current-entity)
687 (print "Print current entity" mime-preview-print-current-entity)
688 (x-face "Show X Face" mime-preview-display-x-face)
690 "Menu for MIME Viewer")
692 (cond (running-xemacs
693 (defvar mime-view-xemacs-popup-menu
694 (cons mime-view-menu-title
697 (vector (nth 1 item)(nth 2 item) t)
699 mime-view-menu-list)))
700 (defun mime-view-xemacs-popup-menu (event)
701 "Popup the menu in the MIME Viewer buffer"
703 (select-window (event-window event))
704 (set-buffer (event-buffer event))
705 (popup-menu 'mime-view-xemacs-popup-menu))
706 (defvar mouse-button-2 'button2)
709 (defvar mouse-button-2 [mouse-2])
712 (defun mime-view-define-keymap (&optional default)
713 (let ((mime-view-mode-map (if (keymapp default)
714 (copy-keymap default)
717 (define-key mime-view-mode-map
718 "u" (function mime-preview-move-to-upper))
719 (define-key mime-view-mode-map
720 "p" (function mime-preview-move-to-previous))
721 (define-key mime-view-mode-map
722 "n" (function mime-preview-move-to-next))
723 (define-key mime-view-mode-map
724 "\e\t" (function mime-preview-move-to-previous))
725 (define-key mime-view-mode-map
726 "\t" (function mime-preview-move-to-next))
727 (define-key mime-view-mode-map
728 " " (function mime-preview-scroll-up-entity))
729 (define-key mime-view-mode-map
730 "\M- " (function mime-preview-scroll-down-entity))
731 (define-key mime-view-mode-map
732 "\177" (function mime-preview-scroll-down-entity))
733 (define-key mime-view-mode-map
734 "\C-m" (function mime-preview-next-line-entity))
735 (define-key mime-view-mode-map
736 "\C-\M-m" (function mime-preview-previous-line-entity))
737 (define-key mime-view-mode-map
738 "v" (function mime-preview-play-current-entity))
739 (define-key mime-view-mode-map
740 "e" (function mime-preview-extract-current-entity))
741 (define-key mime-view-mode-map
742 "\C-c\C-p" (function mime-preview-print-current-entity))
743 (define-key mime-view-mode-map
744 "a" (function mime-preview-follow-current-entity))
745 (define-key mime-view-mode-map
746 "q" (function mime-preview-quit))
747 (define-key mime-view-mode-map
748 "h" (function mime-preview-show-summary))
749 (define-key mime-view-mode-map
750 "\C-c\C-x" (function mime-preview-kill-buffer))
751 ;; (define-key mime-view-mode-map
752 ;; "<" (function beginning-of-buffer))
753 ;; (define-key mime-view-mode-map
754 ;; ">" (function end-of-buffer))
755 (define-key mime-view-mode-map
756 "?" (function describe-mode))
757 (define-key mime-view-mode-map
758 [tab] (function mime-preview-move-to-next))
759 (define-key mime-view-mode-map
760 [delete] (function mime-preview-scroll-down-entity))
761 (define-key mime-view-mode-map
762 [backspace] (function mime-preview-scroll-down-entity))
763 (if (functionp default)
764 (cond (running-xemacs
765 (set-keymap-default-binding mime-view-mode-map default)
768 (setq mime-view-mode-map
769 (append mime-view-mode-map (list (cons t default))))
772 (define-key mime-view-mode-map
773 mouse-button-2 (function mime-button-dispatcher))
775 (cond (running-xemacs
776 (define-key mime-view-mode-map
777 mouse-button-3 (function mime-view-xemacs-popup-menu))
779 ((>= emacs-major-version 19)
780 (define-key mime-view-mode-map [menu-bar mime-view]
781 (cons mime-view-menu-title
782 (make-sparse-keymap mime-view-menu-title)))
785 (define-key mime-view-mode-map
786 (vector 'menu-bar 'mime-view (car item))
787 (cons (nth 1 item)(nth 2 item))
790 (reverse mime-view-menu-list)
793 (use-local-map mime-view-mode-map)
794 (run-hooks 'mime-view-define-keymap-hook)
797 (defsubst mime-maybe-hide-echo-buffer ()
798 "Clear mime-echo buffer and delete window for it."
799 (let ((buf (get-buffer mime-echo-buffer-name)))
804 (let ((win (get-buffer-window buf)))
811 (defun mime-view-mode (&optional mother ctl encoding ibuf obuf
812 default-keymap-or-function)
813 "Major mode for viewing MIME message.
815 Here is a list of the standard keys for mime-view-mode.
820 u Move to upper content
821 p or M-TAB Move to previous content
822 n or TAB Move to next content
823 SPC Scroll up or move to next content
824 M-SPC or DEL Scroll down or move to previous content
825 RET Move to next line
826 M-RET Move to previous line
827 v Decode current content as `play mode'
828 e Decode current content as `extract mode'
829 C-c C-p Decode current content as `print mode'
830 a Followup to current content.
833 button-2 Move to point under the mouse cursor
834 and decode current content as `play mode'
837 (mime-maybe-hide-echo-buffer)
838 (let ((ret (mime-view-setup-buffers ctl encoding ibuf obuf))
839 (win-conf (current-window-configuration))
842 (switch-to-buffer ret)
843 (setq mime-preview-original-window-configuration win-conf)
846 (setq mime-mother-buffer mother)
848 (mime-view-define-keymap default-keymap-or-function)
849 (let ((point (next-single-property-change (point-min) 'mime-view-cinfo)))
852 (goto-char (point-min))
853 (search-forward "\n\n" nil t)
855 (run-hooks 'mime-view-mode-hook)
862 (autoload 'mime-preview-play-current-entity "mime-play"
863 "Play current entity." t)
865 (defun mime-preview-extract-current-entity ()
866 "Extract current entity into file (maybe).
867 It decodes current entity to call internal or external method as
868 \"extract\" mode. The method is selected from variable
869 `mime-acting-condition'."
871 (mime-preview-play-current-entity "extract")
874 (defun mime-preview-print-current-entity ()
875 "Print current entity (maybe).
876 It decodes current entity to call internal or external method as
877 \"print\" mode. The method is selected from variable
878 `mime-acting-condition'."
880 (mime-preview-play-current-entity "print")
887 (defun mime-preview-original-major-mode ()
888 "Return major-mode of original buffer.
889 If a current buffer has mime-mother-buffer, return original major-mode
890 of the mother-buffer."
891 (if mime-mother-buffer
893 (set-buffer mime-mother-buffer)
894 (mime-preview-original-major-mode)
896 mime-preview-original-major-mode))
898 (defun mime-preview-follow-current-entity ()
899 "Write follow message to current entity.
900 It calls following-method selected from variable
901 `mime-view-following-method-alist'."
903 (let ((root-cinfo (get-text-property (point-min) 'mime-view-cinfo))
905 (while (null (setq cinfo (get-text-property (point) 'mime-view-cinfo)))
908 (let* ((p-beg (previous-single-property-change (point) 'mime-view-cinfo))
910 (rcnum (mime-entity-info-rnum cinfo))
915 (if (eq (next-single-property-change (point-min)
921 ((eq (next-single-property-change p-beg 'mime-view-cinfo)
925 (setq p-end (next-single-property-change p-beg 'mime-view-cinfo))
927 (setq p-end (point-max))
930 (setq p-end (point-max))
938 (next-single-property-change
939 (point) 'mime-view-cinfo))
941 (let ((rc (mime-entity-info-rnum
942 (get-text-property (point)
944 (or (equal rcnum (nthcdr (- (length rc) len) rc))
949 (setq p-end (point-max))
952 (let* ((mode (mime-preview-original-major-mode))
953 (new-name (format "%s-%s" (buffer-name) (reverse rcnum)))
955 (the-buf (current-buffer))
956 (a-buf mime-raw-buffer)
959 (set-buffer (setq new-buf (get-buffer-create new-name)))
961 (insert-buffer-substring the-buf p-beg p-end)
962 (goto-char (point-min))
963 (if (mime-view-header-visible-p rcnum root-cinfo)
964 (delete-region (goto-char (point-min))
965 (if (re-search-forward "^$" nil t)
969 (goto-char (point-min))
971 (goto-char (point-min))
972 (let ((rcnum (mime-entity-info-rnum cinfo)) ci str)
980 (mime-raw-reversed-entity-number-to-entity-info
984 (mime-entity-info-point-min ci)
985 (mime-entity-info-point-max ci)
987 (std11-header-string-except
989 (apply (function regexp-or) fields)
992 (eq (mime-entity-info-media-type ci) 'message)
993 (eq (mime-entity-info-media-subtype ci) 'rfc822))
999 (setq fields (std11-collect-field-names)
1003 (let ((rest mime-view-following-required-fields-list))
1005 (let ((field-name (car rest)))
1006 (or (std11-field-body field-name)
1012 (set-buffer the-buf)
1013 (set-buffer mime-mother-buffer)
1014 (set-buffer mime-raw-buffer)
1015 (std11-field-body field-name)
1019 (setq rest (cdr rest))
1021 (eword-decode-header)
1023 (let ((f (cdr (assq mode mime-view-following-method-alist))))
1028 "Sorry, following method for %s is not implemented yet."
1037 (defun mime-preview-display-x-face ()
1039 (save-window-excursion
1040 (set-buffer mime-raw-buffer)
1041 (mime-view-x-face-function)
1048 (defun mime-preview-move-to-upper ()
1049 "Move to upper entity.
1050 If there is no upper entity, call function `mime-preview-quit'."
1053 (while (null (setq cinfo (get-text-property (point) 'mime-view-cinfo)))
1056 (let ((r (mime-raw-reversed-entity-number-to-entity-info
1057 (cdr (mime-entity-info-rnum cinfo))
1058 (get-text-property 1 'mime-view-cinfo)))
1061 (while (setq point (previous-single-property-change
1062 (point) 'mime-view-cinfo))
1064 (if (eq r (get-text-property (point) 'mime-view-cinfo))
1071 (defun mime-preview-move-to-previous ()
1072 "Move to previous entity.
1073 If there is no previous entity, it calls function registered in
1074 variable `mime-view-over-to-previous-method-alist'."
1076 (while (null (get-text-property (point) 'mime-view-cinfo))
1079 (let ((point (previous-single-property-change (point) 'mime-view-cinfo)))
1082 (let ((f (assq mime-preview-original-major-mode
1083 mime-view-over-to-previous-method-alist)))
1089 (defun mime-preview-move-to-next ()
1090 "Move to next entity.
1091 If there is no previous entity, it calls function registered in
1092 variable `mime-view-over-to-next-method-alist'."
1094 (let ((point (next-single-property-change (point) 'mime-view-cinfo)))
1097 (let ((f (assq mime-preview-original-major-mode
1098 mime-view-over-to-next-method-alist)))
1104 (defun mime-preview-scroll-up-entity (&optional h)
1105 "Scroll up current entity.
1106 If reached to (point-max), it calls function registered in variable
1107 `mime-view-over-to-next-method-alist'."
1110 (setq h (1- (window-height)))
1112 (if (= (point) (point-max))
1113 (let ((f (assq mime-preview-original-major-mode
1114 mime-view-over-to-next-method-alist)))
1119 (or (next-single-property-change (point) 'mime-view-cinfo)
1122 (if (> (point) point)
1127 (defun mime-preview-scroll-down-entity (&optional h)
1128 "Scroll down current entity.
1129 If reached to (point-min), it calls function registered in variable
1130 `mime-view-over-to-previous-method-alist'."
1133 (setq h (1- (window-height)))
1135 (if (= (point) (point-min))
1136 (let ((f (assq mime-preview-original-major-mode
1137 mime-view-over-to-previous-method-alist)))
1144 (while (> (point) 1)
1146 (previous-single-property-change (point)
1152 (setq point (point-min))
1154 (forward-line (- h))
1155 (if (< (point) point)
1159 (defun mime-preview-next-line-entity ()
1161 (mime-preview-scroll-up-entity 1)
1164 (defun mime-preview-previous-line-entity ()
1166 (mime-preview-scroll-down-entity 1)
1173 (defun mime-preview-quit ()
1174 "Quit from MIME-preview buffer.
1175 It calls function registered in variable
1176 `mime-view-quitting-method-alist'."
1178 (let ((r (assq mime-preview-original-major-mode
1179 mime-view-quitting-method-alist)))
1184 (defun mime-preview-show-summary ()
1186 It calls function registered in variable
1187 `mime-view-show-summary-method'."
1189 (let ((r (assq mime-preview-original-major-mode
1190 mime-view-show-summary-method)))
1195 (defun mime-preview-kill-buffer ()
1197 (kill-buffer (current-buffer))
1204 (provide 'mime-view)
1206 (run-hooks 'mime-view-load-hook)
1208 ;;; mime-view.el ends here