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/plain")
51 (method "tm-plain" nil 'file 'type 'encoding 'mode 'name)
55 (method "tm-html" nil 'file 'type 'encoding 'mode 'name)
58 ((type . "text/x-rot13-47")
59 (method . mime-method-to-display-caesar)
62 ((type . "text/x-rot13-47-48")
63 (method . mime-method-to-display-caesar)
66 ((type . "audio/basic")
67 (method "tm-au" nil 'file 'type 'encoding 'mode 'name)
71 ((type . "image/jpeg")
72 (method "tm-image" nil 'file 'type 'encoding 'mode 'name)
76 (method "tm-image" nil 'file 'type 'encoding 'mode 'name)
80 (method "tm-image" nil 'file 'type 'encoding 'mode 'name)
83 ((type . "image/tiff")
84 (method "tm-image" nil 'file 'type 'encoding 'mode 'name)
87 ((type . "image/x-tiff")
88 (method "tm-image" nil 'file 'type 'encoding 'mode 'name)
91 ((type . "image/x-xbm")
92 (method "tm-image" nil 'file 'type 'encoding 'mode 'name)
95 ((type . "image/x-pic")
96 (method "tm-image" nil 'file 'type 'encoding 'mode 'name)
99 ((type . "image/x-mag")
100 (method "tm-image" nil 'file 'type 'encoding 'mode 'name)
101 (mode "play" "print")
104 ((type . "video/mpeg")
105 (method "tm-mpeg" nil 'file 'type 'encoding 'mode 'name)
109 ((type . "application/postscript")
110 (method "tm-ps" nil 'file 'type 'encoding 'mode 'name)
111 (mode "play" "print")
113 ((type . "application/octet-stream")
114 (method . mime-method-to-save)(mode "play" "print")
117 ((type . "message/external-body")
118 ("access-type" . "anon-ftp")
119 (method . mime-method-to-display-message/external-ftp)
121 ((type . "message/rfc822")
122 (method . mime-method-to-display-message/rfc822)
125 ((type . "message/partial")
126 (method . mime-method-to-store-message/partial)
130 ((method "metamail" t "-m" "tm" "-x" "-d" "-z" "-e" 'file)
133 ((method . mime-method-to-save)(mode . "extract"))
136 (defvar mime-view-childrens-header-showing-Content-Type-list
137 '("message/rfc822" "message/news"))
139 (defvar mime-view-visible-media-type-list
140 '("text/plain" nil "text/richtext" "text/enriched"
141 "text/rfc822-headers"
142 "text/x-latex" "application/x-latex"
143 "message/delivery-status"
144 "application/pgp" "text/x-pgp"
145 "application/octet-stream"
146 "application/x-selection" "application/x-comment")
147 "*List of media-types to be able to display in MIME-View buffer.
148 Each elements are string of TYPE/SUBTYPE, e.g. \"text/plain\".")
150 (defvar mime-view-content-button-visible-ctype-list
151 '("application/pgp"))
153 (defvar mime-view-uuencode-encoding-name-list '("x-uue" "x-uuencode"))
155 (defvar mime-view-ignored-field-list
156 '(".*Received" ".*Path" ".*Id" "References"
157 "Replied" "Errors-To"
158 "Lines" "Sender" ".*Host" "Xref"
159 "Content-Type" "Precedence"
161 "All fields that match this list will be hidden in MIME preview buffer.
162 Each elements are regexp of field-name. [mime-view.el]")
164 (defvar mime-view-ignored-field-regexp
166 (apply (function regexp-or) mime-view-ignored-field-list)
169 (defvar mime-view-visible-field-list '("Dnas.*" "Message-Id")
170 "All fields that match this list will be displayed in MIME preview buffer.
171 Each elements are regexp of field-name.")
173 (defvar mime-view-redisplay nil)
175 (defvar mime-view-announcement-for-message/partial
176 (if (and (>= emacs-major-version 19) window-system)
178 \[[ This is message/partial style split message. ]]
179 \[[ Please press `v' key in this buffer ]]
180 \[[ or click here by mouse button-2. ]]"
182 \[[ This is message/partial style split message. ]]
183 \[[ Please press `v' key in this buffer. ]]"
190 (defun mime-view-insert-entity-button (rcnum cinfo
191 media-type media-subtype params
193 "Insert entity-button."
195 (let ((access-type (assoc "access-type" params))
196 (num (or (cdr (assoc "x-part-number" params))
200 (format "%s" (1+ num))
206 (let ((server (assoc "server" params)))
207 (setq access-type (cdr access-type))
209 (format "%s %s ([%s] %s)"
210 num subj access-type (cdr server))
211 (let ((site (cdr (assoc "site" params)))
212 (dir (cdr (assoc "directory" params)))
214 (format "%s %s ([%s] %s:%s)"
215 num subj access-type site dir)
219 (let ((charset (cdr (assoc "charset" params))))
223 (format " <%s/%s%s%s>"
224 media-type media-subtype
226 (concat "; " charset)
229 (concat " (" encoding ")")
231 (if (>= (+ (current-column)(length rest))(window-width))
235 (function mime-view-play-current-entity))
238 (defun mime-view-entity-button-function (rcnum cinfo
239 media-type media-subtype
240 params subj encoding)
241 "Insert entity button conditionally.
242 Please redefine this function if you want to change default setting."
244 (and (eq media-type 'application)
245 (or (eq media-subtype 'x-selection)
246 (and (eq media-subtype 'octet-stream)
248 (mime-article/rcnum-to-cinfo (cdr rcnum) cinfo)))
249 (and (eq (mime-entity-info-media-type entity-info)
251 (eq (mime-entity-info-media-subtype entity-info)
254 (mime-view-insert-entity-button
255 rcnum cinfo media-type media-subtype params subj encoding)
259 ;;; @@ content header filter
262 (defun mime-view-cut-header ()
263 (goto-char (point-min))
264 (while (re-search-forward mime-view-ignored-field-regexp nil t)
265 (let* ((beg (match-beginning 0))
267 (name (buffer-substring beg end))
270 (let ((rest mime-view-visible-field-list))
272 (if (string-match (car rest) name)
275 (setq rest (cdr rest))))
278 (if (re-search-forward "^\\([^ \t]\\|$\\)" nil t)
283 (defun mime-view-default-content-header-filter ()
284 (mime-view-cut-header)
285 (eword-decode-header)
288 (defvar mime-view-content-header-filter-alist nil)
291 ;;; @@ content filter
294 (defvar mime-view-content-filter-alist
295 '(("text/enriched" . mime-view-filter-for-text/enriched)
296 ("text/richtext" . mime-view-filter-for-text/richtext)
297 (t . mime-view-filter-for-text/plain)
299 "Alist of media-types vs. corresponding MIME-View filter functions.
300 Each element looks like (TYPE/SUBTYPE . FUNCTION) or (t . FUNCTION).
301 TYPE/SUBTYPE is a string of media-type and FUNCTION is a filter
302 function. t means default media-type.")
305 ;;; @@ entity separator
308 (defun mime-view-entity-separator-function (rcnum cinfo
309 media-type media-subtype
311 "Insert entity separator conditionally.
312 Please redefine this function if you want to change default setting."
313 (or (mime-view-header-visible-p rcnum cinfo)
314 (mime-view-body-visible-p rcnum cinfo media-type media-subtype)
316 (goto-char (point-max))
321 ;;; @@ buffer local variables
324 ;;; @@@ in raw buffer
327 (defvar mime-raw-content-info
328 "Information about structure of message.
329 Please use reference function `mime::content-info/SLOT-NAME' to
330 reference slot of content-info. Their argument is only content-info.
332 Following is a list of slots of the structure:
334 rcnum reversed content-number (list)
335 point-min beginning point of region in raw-buffer
336 point-max end point of region in raw-buffer
337 type media-type/subtype (string or nil)
338 parameters parameter of Content-Type field (association list)
339 encoding Content-Transfer-Encoding (string or nil)
340 children entities included in this entity (list of content-infos)
342 If a entity includes other entities in its body, such as multipart or
343 message/rfc822, content-infos of other entities are included in
344 `children', so content-info become a tree.")
345 (make-variable-buffer-local 'mime-raw-content-info)
347 (defvar mime-view-buffer nil
348 "MIME View buffer corresponding with the (raw) buffer.")
349 (make-variable-buffer-local 'mime-view-buffer)
352 ;;; @@@ in view buffer
355 (defvar mime-mother-buffer nil
356 "Mother buffer corresponding with the (MIME-View) buffer.
357 If current MIME-View buffer is generated by other buffer, such as
358 message/partial, it is called `mother-buffer'.")
359 (make-variable-buffer-local 'mime-mother-buffer)
361 (defvar mime-raw-buffer nil
362 "Raw buffer corresponding with the (MIME-View) buffer.")
363 (make-variable-buffer-local 'mime-raw-buffer)
365 (defvar mime-view-original-major-mode nil
366 "Major-mode in mime-raw-buffer.")
367 (make-variable-buffer-local 'mime-view-original-major-mode)
369 (make-variable-buffer-local 'mime::preview/original-window-configuration)
372 ;;; @@ quitting method
375 (defvar mime-view-quitting-method-alist
376 '((mime-show-message-mode
377 . mime-view-quitting-method-for-mime-show-message-mode))
378 "Alist of major-mode vs. quitting-method of mime-view.")
380 (defvar mime-view-over-to-previous-method-alist nil)
381 (defvar mime-view-over-to-next-method-alist nil)
383 (defvar mime-view-show-summary-method nil
384 "Alist of major-mode vs. show-summary-method.")
387 ;;; @@ following method
390 (defvar mime-view-following-method-alist nil
391 "Alist of major-mode vs. following-method of mime-view.")
393 (defvar mime-view-following-required-fields-list
400 ;; hack from Gnus 5.0.4.
402 (defvar mime-view-x-face-to-pbm-command
403 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm")
405 (defvar mime-view-x-face-command
406 (concat mime-view-x-face-to-pbm-command
408 "String to be executed to display an X-Face field.
409 The command will be executed in a sub-shell asynchronously.
410 The compressed face will be piped to this command.")
412 (defun mime-view-x-face-function ()
413 "Function to display X-Face field. You can redefine to customize."
414 ;; 1995/10/12 (c.f. tm-eng:130)
415 ;; fixed by Eric Ding <ericding@San-Jose.ate.slb.com>
417 (narrow-to-region (point-min) (re-search-forward "^$" nil t))
419 (goto-char (point-min))
420 (if (re-search-forward "^X-Face:[ \t]*" nil t)
421 (let ((beg (match-end 0))
422 (end (std11-field-end))
424 (call-process-region beg end "sh" nil 0 nil
425 "-c" mime-view-x-face-command)
432 (defun mime-view-setup-buffers (&optional ctl encoding ibuf obuf)
438 (or mime-view-redisplay
439 (setq mime-raw-content-info (mime-parse-message ctl encoding))
441 (let* ((cinfo mime-raw-content-info)
442 (pcl (mime/flatten-content-info cinfo))
443 (the-buf (current-buffer))
447 (setq obuf (concat "*Preview-" (buffer-name the-buf) "*")))
448 (set-buffer (get-buffer-create obuf))
449 (let ((inhibit-read-only t))
450 ;;(setq buffer-read-only nil)
453 (setq mime-raw-buffer the-buf)
454 (setq mime-view-original-major-mode mode)
455 (setq major-mode 'mime-view-mode)
456 (setq mode-name "MIME-View")
458 (mime-view-display-entity (car pcl) cinfo the-buf obuf)
461 (set-buffer-modified-p nil)
463 (setq buffer-read-only t)
466 (setq mime-view-buffer obuf)
469 (defun mime-view-display-entity (content cinfo ibuf obuf)
470 "Display entity from content-info CONTENT."
471 (let* ((beg (mime-entity-info-point-min content))
472 (end (mime-entity-info-point-max content))
473 (media-type (mime-entity-info-media-type content))
474 (media-subtype (mime-entity-info-media-subtype content))
475 (ctype (if media-type
477 (format "%s/%s" media-type media-subtype)
478 (symbol-name media-type)
480 (params (mime-entity-info-parameters content))
481 (encoding (mime-entity-info-encoding content))
482 (rcnum (mime-entity-info-rnum content))
486 (setq he (if (re-search-forward "^$" nil t)
493 (narrow-to-region beg end)
496 (mime-article/get-subject params encoding)))
500 (narrow-to-region nb nb)
501 (mime-view-entity-button-function
502 rcnum cinfo media-type media-subtype params subj encoding)
503 (if (mime-view-header-visible-p rcnum cinfo)
504 (mime-view-display-header beg he)
506 (if (and (null rcnum)
508 ctype mime-view-content-button-visible-ctype-list))
510 (goto-char (point-max))
511 (mime-view-insert-entity-button
512 rcnum cinfo media-type media-subtype params subj encoding)
514 (cond ((mime-view-body-visible-p rcnum cinfo media-type media-subtype)
515 (mime-view-display-body he end
516 rcnum cinfo ctype params subj encoding)
518 ((and (eq media-type 'message)(eq media-subtype 'partial))
519 (mime-view-insert-message/partial-button)
522 (null (mime-entity-info-children cinfo))
524 (goto-char (point-max))
525 (mime-view-insert-entity-button
526 rcnum cinfo media-type media-subtype params subj encoding)
528 (mime-view-entity-separator-function
529 rcnum cinfo media-type media-subtype params subj)
530 (setq ne (point-max))
532 (put-text-property nb ne 'mime-view-raw-buffer ibuf)
533 (put-text-property nb ne 'mime-view-cinfo content)
537 (defun mime-view-display-header (beg end)
539 (narrow-to-region (point)(point))
540 (insert-buffer-substring mime-raw-buffer beg end)
541 (let ((f (cdr (assq mime-view-original-major-mode
542 mime-view-content-header-filter-alist))))
545 (mime-view-default-content-header-filter)
547 (run-hooks 'mime-view-content-header-filter-hook)
550 (defun mime-view-display-body (beg end rcnum cinfo ctype params subj encoding)
552 (narrow-to-region (point-max)(point-max))
553 (insert-buffer-substring mime-raw-buffer beg end)
554 (let ((f (cdr (or (assoc ctype mime-view-content-filter-alist)
555 (assq t mime-view-content-filter-alist)))))
557 (funcall f ctype params encoding)
561 (defun mime-view-insert-message/partial-button ()
563 (goto-char (point-max))
564 (if (not (search-backward "\n\n" nil t))
567 (goto-char (point-max))
568 (narrow-to-region (point-max)(point-max))
569 (insert mime-view-announcement-for-message/partial)
570 (mime-add-button (point-min)(point-max)
571 (function mime-view-play-current-entity))
574 (defun mime-article/get-uu-filename (param &optional encoding)
575 (if (member (or encoding
576 (cdr (assq 'encoding param))
578 mime-view-uuencode-encoding-name-list)
580 (or (if (re-search-forward "^begin [0-9]+ " nil t)
581 (if (looking-at ".+$")
582 (buffer-substring (match-beginning 0)(match-end 0))
587 (defun mime-article/get-subject (param &optional encoding)
588 (or (std11-find-field-body '("Content-Description" "Subject"))
590 (if (or (and (setq ret (mime/Content-Disposition))
591 (setq ret (assoc "filename" (cdr ret)))
593 (setq ret (assoc "name" param))
594 (setq ret (assoc "x-name" param))
596 (std11-strip-quoted-string (cdr ret))
598 (mime-article/get-uu-filename param encoding)
602 ;;; @ entity information
605 (defun mime-article/point-content-number (p &optional cinfo)
607 (setq cinfo mime-raw-content-info)
609 (let ((b (mime-entity-info-point-min cinfo))
610 (e (mime-entity-info-point-max cinfo))
611 (c (mime-entity-info-children cinfo))
613 (if (and (<= b p)(<= p e))
614 (or (let (co ret (sn 0))
618 (setq ret (mime-article/point-content-number p co))
619 (cond ((eq ret t) (throw 'tag (list sn)))
620 (ret (throw 'tag (cons sn ret)))
627 (defsubst mime-article/rcnum-to-cinfo (rnum &optional cinfo)
628 (mime-article/cnum-to-cinfo (reverse rnum) cinfo)
631 (defun mime-article/cnum-to-cinfo (cn &optional cinfo)
633 (setq cinfo mime-raw-content-info)
640 (let ((rc (nth sn (mime-entity-info-children cinfo))))
642 (mime-article/cnum-to-cinfo (cdr cn) rc)
646 (defun mime/flatten-content-info (&optional cinfo)
648 (setq cinfo mime-raw-content-info)
650 (let ((dest (list cinfo))
651 (rcl (mime-entity-info-children cinfo))
654 (setq dest (nconc dest (mime/flatten-content-info (car rcl))))
660 ;;; @@ predicate functions
663 (defun mime-view-header-visible-p (rcnum cinfo)
664 "Return non-nil if header of current entity is visible."
666 (member (mime-entity-info-type/subtype
667 (mime-article/rcnum-to-cinfo (cdr rcnum) cinfo))
668 mime-view-childrens-header-showing-Content-Type-list)
671 (defun mime-view-body-visible-p (rcnum cinfo media-type media-subtype)
672 (let ((ctype (if media-type
674 (format "%s/%s" media-type media-subtype)
675 (symbol-name media-type)
677 (and (member ctype mime-view-visible-media-type-list)
678 (if (and (eq media-type 'application)
679 (eq media-subtype 'octet-stream))
680 (let ((ccinfo (mime-article/rcnum-to-cinfo rcnum cinfo)))
681 (member (mime-entity-info-encoding ccinfo)
682 '(nil "7bit" "8bit"))
688 ;;; @ MIME viewer mode
691 (defconst mime-view-menu-title "MIME-View")
692 (defconst mime-view-menu-list
693 '((up "Move to upper content" mime-view-move-to-upper)
694 (previous "Move to previous content" mime-view-move-to-previous)
695 (next "Move to next content" mime-view-move-to-next)
696 (scroll-down "Scroll to previous content" mime-view-scroll-down-entity)
697 (scroll-up "Scroll to next content" mime-view-scroll-up-entity)
698 (play "Play Content" mime-view-play-current-entity)
699 (extract "Extract Content" mime-view-extract-current-entity)
700 (print "Print" mime-view-print-current-entity)
701 (x-face "Show X Face" mime-view-display-x-face)
703 "Menu for MIME Viewer")
705 (cond (running-xemacs
706 (defvar mime-view-xemacs-popup-menu
707 (cons mime-view-menu-title
710 (vector (nth 1 item)(nth 2 item) t)
712 mime-view-menu-list)))
713 (defun mime-view-xemacs-popup-menu (event)
714 "Popup the menu in the MIME Viewer buffer"
716 (select-window (event-window event))
717 (set-buffer (event-buffer event))
718 (popup-menu 'mime-view-xemacs-popup-menu))
719 (defvar mouse-button-2 'button2)
722 (defvar mouse-button-2 [mouse-2])
725 (defun mime-view-define-keymap (&optional default)
726 (let ((mime-view-mode-map (if (keymapp default)
727 (copy-keymap default)
730 (define-key mime-view-mode-map
731 "u" (function mime-view-move-to-upper))
732 (define-key mime-view-mode-map
733 "p" (function mime-view-move-to-previous))
734 (define-key mime-view-mode-map
735 "n" (function mime-view-move-to-next))
736 (define-key mime-view-mode-map
737 "\e\t" (function mime-view-move-to-previous))
738 (define-key mime-view-mode-map
739 "\t" (function mime-view-move-to-next))
740 (define-key mime-view-mode-map
741 " " (function mime-view-scroll-up-entity))
742 (define-key mime-view-mode-map
743 "\M- " (function mime-view-scroll-down-entity))
744 (define-key mime-view-mode-map
745 "\177" (function mime-view-scroll-down-entity))
746 (define-key mime-view-mode-map
747 "\C-m" (function mime-view-next-line-content))
748 (define-key mime-view-mode-map
749 "\C-\M-m" (function mime-view-previous-line-content))
750 (define-key mime-view-mode-map
751 "v" (function mime-view-play-current-entity))
752 (define-key mime-view-mode-map
753 "e" (function mime-view-extract-current-entity))
754 (define-key mime-view-mode-map
755 "\C-c\C-p" (function mime-view-print-current-entity))
756 (define-key mime-view-mode-map
757 "a" (function mime-view-follow-current-entity))
758 (define-key mime-view-mode-map
759 "q" (function mime-view-quit))
760 (define-key mime-view-mode-map
761 "h" (function mime-view-show-summary))
762 (define-key mime-view-mode-map
763 "\C-c\C-x" (function mime-view-kill-buffer))
764 ;; (define-key mime-view-mode-map
765 ;; "<" (function beginning-of-buffer))
766 ;; (define-key mime-view-mode-map
767 ;; ">" (function end-of-buffer))
768 (define-key mime-view-mode-map
769 "?" (function describe-mode))
770 (define-key mime-view-mode-map
771 [tab] (function mime-view-move-to-next))
772 (define-key mime-view-mode-map
773 [delete] (function mime-view-scroll-down-entity))
774 (define-key mime-view-mode-map
775 [backspace] (function mime-view-scroll-down-entity))
776 (if (functionp default)
777 (cond (running-xemacs
778 (set-keymap-default-binding mime-view-mode-map default)
781 (setq mime-view-mode-map
782 (append mime-view-mode-map (list (cons t default))))
785 (define-key mime-view-mode-map
786 mouse-button-2 (function mime-button-dispatcher))
788 (cond (running-xemacs
789 (define-key mime-view-mode-map
790 mouse-button-3 (function mime-view-xemacs-popup-menu))
792 ((>= emacs-major-version 19)
793 (define-key mime-view-mode-map [menu-bar mime-view]
794 (cons mime-view-menu-title
795 (make-sparse-keymap mime-view-menu-title)))
798 (define-key mime-view-mode-map
799 (vector 'menu-bar 'mime-view (car item))
800 (cons (nth 1 item)(nth 2 item))
803 (reverse mime-view-menu-list)
806 (use-local-map mime-view-mode-map)
807 (run-hooks 'mime-view-define-keymap-hook)
810 (defsubst mime-maybe-hide-echo-buffer ()
811 "Clear mime-echo buffer and delete window for it."
812 (let ((buf (get-buffer mime-echo-buffer-name)))
817 (let ((win (get-buffer-window buf)))
824 (defun mime-view-mode (&optional mother ctl encoding ibuf obuf
825 default-keymap-or-function)
826 "Major mode for viewing MIME message.
828 Here is a list of the standard keys for mime-view-mode.
833 u Move to upper content
834 p or M-TAB Move to previous content
835 n or TAB Move to next content
836 SPC Scroll up or move to next content
837 M-SPC or DEL Scroll down or move to previous content
838 RET Move to next line
839 M-RET Move to previous line
840 v Decode current content as `play mode'
841 e Decode current content as `extract mode'
842 C-c C-p Decode current content as `print mode'
843 a Followup to current content.
846 button-2 Move to point under the mouse cursor
847 and decode current content as `play mode'
850 (mime-maybe-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)
1000 (eq (mime-entity-info-media-type ci) 'message)
1001 (eq (mime-entity-info-media-subtype ci) 'rfc822))
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-entity-info-rnum 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