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.87 $
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.87 1997-05-09 03:05:51 morioka Exp $")
45 (defconst mime-view-version (get-version-string mime-view-RCS-ID))
51 (defvar mime/content-decoding-condition
52 '(((type . "text/plain")
53 (method "tm-plain" nil 'file 'type 'encoding 'mode 'name)
57 (method "tm-html" nil 'file 'type 'encoding 'mode 'name)
60 ((type . "text/x-rot13-47")
61 (method . mime-display-caesar)
64 ((type . "text/x-rot13-47-48")
65 (method . mime-display-caesar)
68 ((type . "audio/basic")
69 (method "tm-au" nil 'file 'type 'encoding 'mode 'name)
73 ((type . "image/jpeg")
74 (method "tm-image" nil 'file 'type 'encoding 'mode 'name)
78 (method "tm-image" nil 'file 'type 'encoding 'mode 'name)
81 ((type . "image/tiff")
82 (method "tm-image" nil 'file 'type 'encoding 'mode 'name)
85 ((type . "image/x-tiff")
86 (method "tm-image" nil 'file 'type 'encoding 'mode 'name)
89 ((type . "image/x-xbm")
90 (method "tm-image" nil 'file 'type 'encoding 'mode 'name)
93 ((type . "image/x-pic")
94 (method "tm-image" nil 'file 'type 'encoding 'mode 'name)
97 ((type . "image/x-mag")
98 (method "tm-image" nil 'file 'type 'encoding 'mode 'name)
102 ((type . "video/mpeg")
103 (method "tm-mpeg" nil 'file 'type 'encoding 'mode 'name)
107 ((type . "application/postscript")
108 (method "tm-ps" nil 'file 'type 'encoding 'mode 'name)
109 (mode "play" "print")
111 ((type . "application/octet-stream")
112 (method "tm-file" nil 'file 'type 'encoding 'mode 'name)
113 (mode "play" "print")
116 ;;((type . "message/external-body")
117 ;; (method "xterm" nil
118 ;; "-e" "showexternal"
119 ;; 'file '"access-type" '"name" '"site" '"directory"))
120 ((type . "message/external-body")
121 ("access-type" . "anon-ftp")
122 (method . mime-article/decode-message/external-ftp)
124 ((type . "message/rfc822")
125 (method . mime-article/view-message/rfc822)
128 ((type . "message/partial")
129 (method . mime-article/decode-message/partial)
133 ((method "metamail" t "-m" "tm" "-x" "-d" "-z" "-e" 'file)
136 ((method "tm-file" nil 'file 'type 'encoding 'mode 'name)
141 (defvar mime-view-childrens-header-showing-Content-Type-list
142 '("message/rfc822" "message/news"))
144 (defvar mime-view-visible-media-type-list
145 '("text/plain" nil "text/richtext" "text/enriched"
146 "text/rfc822-headers"
147 "text/x-latex" "application/x-latex"
148 "message/delivery-status"
149 "application/pgp" "text/x-pgp"
150 "application/octet-stream"
151 "application/x-selection" "application/x-comment")
152 "*List of media-types to be able to display in MIME-View buffer.
153 Each elements are string of TYPE/SUBTYPE, e.g. \"text/plain\".")
155 (defvar mime-view-content-button-visible-ctype-list
156 '("application/pgp"))
158 (defvar mime-view-uuencode-encoding-name-list '("x-uue" "x-uuencode"))
160 (defvar mime-view-ignored-field-list
161 '(".*Received" ".*Path" ".*Id" "References"
162 "Replied" "Errors-To"
163 "Lines" "Sender" ".*Host" "Xref"
164 "Content-Type" "Precedence"
166 "All fields that match this list will be hidden in MIME preview buffer.
167 Each elements are regexp of field-name. [mime-view.el]")
169 (defvar mime-view-ignored-field-regexp
171 (apply (function regexp-or) mime-view-ignored-field-list)
174 (defvar mime-view-visible-field-list '("Dnas.*" "Message-Id")
175 "All fields that match this list will be displayed in MIME preview buffer.
176 Each elements are regexp of field-name.")
178 (defvar mime-view-redisplay nil)
180 (defvar mime-view-announcement-for-message/partial
181 (if (and (>= emacs-major-version 19) window-system)
183 \[[ This is message/partial style split message. ]]
184 \[[ Please press `v' key in this buffer ]]
185 \[[ or click here by mouse button-2. ]]"
187 \[[ This is message/partial style split message. ]]
188 \[[ Please press `v' key in this buffer. ]]"
192 ;;; @@ predicate functions
195 (defun mime-view-header-visible-p (rcnum cinfo)
196 "Return non-nil if header of current entity is visible."
198 (member (mime::content-info/type
199 (mime-article/rcnum-to-cinfo (cdr rcnum) cinfo))
200 mime-view-childrens-header-showing-Content-Type-list)
203 (defun mime-view-body-visible-p (rcnum cinfo &optional ctype)
207 (mime::content-info/type
208 (setq ccinfo (mime-article/rcnum-to-cinfo rcnum cinfo))
211 (and (member ctype mime-view-visible-media-type-list)
212 (if (string-equal ctype "application/octet-stream")
215 (setq ccinfo (mime-article/rcnum-to-cinfo rcnum cinfo))
217 (member (mime::content-info/encoding ccinfo)
218 '(nil "7bit" "8bit"))
227 (defun mime-view-insert-entity-button (rcnum cinfo ctype params subj encoding)
228 "Insert entity-button."
230 (narrow-to-region (point)(point))
231 (let ((access-type (assoc "access-type" params))
232 (num (or (cdr (assoc "x-part-number" params))
236 (format "%s" (1+ num))
242 (let ((server (assoc "server" params)))
243 (setq access-type (cdr access-type))
245 (insert (format "[%s %s ([%s] %s)]\n" num subj
246 access-type (cdr server)))
247 (let ((site (cdr (assoc "site" params)))
248 (dir (cdr (assoc "directory" params)))
250 (insert (format "[%s %s ([%s] %s:%s)]\n" num subj
251 access-type site dir))
255 (let ((charset (cdr (assoc "charset" params))))
256 (insert (concat "[" num " " subj))
260 (concat "; " charset)
261 (if encoding (concat " (" encoding ")"))
264 (if (>= (+ (current-column)(length rest))(window-width))
270 (mime-add-button (point-min)(1- (point-max))
271 (function mime-view-play-current-entity))
274 (defun mime-view-entity-button-function
275 (rcnum cinfo ctype params subj encoding)
276 "Insert entity button conditionally.
277 Please redefine this function if you want to change default setting."
279 (string= ctype "application/x-selection")
280 (and (string= ctype "application/octet-stream")
281 (string= (mime::content-info/type
282 (mime-article/rcnum-to-cinfo (cdr rcnum) cinfo))
283 "multipart/encrypted"))
284 (mime-view-insert-entity-button rcnum cinfo ctype params subj encoding)
288 ;;; @@ content header filter
291 (defsubst mime-view-cut-header ()
292 (goto-char (point-min))
293 (while (re-search-forward mime-view-ignored-field-regexp nil t)
294 (let* ((beg (match-beginning 0))
296 (name (buffer-substring beg end))
298 (or (member-if (function
300 (string-match regexp name)
301 )) mime-view-visible-field-list)
304 (if (re-search-forward "^\\([^ \t]\\|$\\)" nil t)
309 (defun mime-view-default-content-header-filter ()
310 (mime-view-cut-header)
311 (eword-decode-header)
314 (defvar mime-view-content-header-filter-alist nil)
317 ;;; @@ content filter
320 (defvar mime-view-content-filter-alist
321 '(("text/enriched" . mime-view-filter-for-text/enriched)
322 ("text/richtext" . mime-view-filter-for-text/richtext)
323 (t . mime-view-filter-for-text/plain)
325 "Alist of media-types vs. corresponding MIME-View filter functions.
326 Each element looks like (TYPE/SUBTYPE . FUNCTION) or (t . FUNCTION).
327 TYPE/SUBTYPE is a string of media-type and FUNCTION is a filter
328 function. t means default media-type.")
331 ;;; @@ entity separator
334 (defun mime-view-entity-separator-function (rcnum cinfo ctype params subj)
335 "Insert entity separator conditionally.
336 Please redefine this function if you want to change default setting."
337 (or (mime-view-header-visible-p rcnum cinfo)
338 (mime-view-body-visible-p rcnum cinfo ctype)
340 (goto-char (point-max))
345 ;;; @@ buffer local variables
348 ;;; @@@ in raw buffer
351 (defvar mime::article/content-info
352 "Information about structure of message.
353 Please use reference function `mime::content-info/SLOT-NAME' to
354 reference slot of content-info. Their argument is only content-info.
356 Following is a list of slots of the structure:
358 rcnum reversed content-number (list)
359 point-min beginning point of region in raw-buffer
360 point-max end point of region in raw-buffer
361 type media-type/subtype (string or nil)
362 parameters parameter of Content-Type field (association list)
363 encoding Content-Transfer-Encoding (string or nil)
364 children entities included in this entity (list of content-infos)
366 If a entity includes other entities in its body, such as multipart or
367 message/rfc822, content-infos of other entities are included in
368 `children', so content-info become a tree.")
369 (make-variable-buffer-local 'mime::article/content-info)
371 (defvar mime-view-buffer nil
372 "MIME View buffer corresponding with the (raw) buffer.")
373 (make-variable-buffer-local 'mime-view-buffer)
376 ;;; @@@ in view buffer
379 (defvar mime-mother-buffer nil
380 "Mother buffer corresponding with the (MIME-View) buffer.
381 If current MIME-View buffer is generated by other buffer, such as
382 message/partial, it is called `mother-buffer'.")
383 (make-variable-buffer-local 'mime-mother-buffer)
385 (defvar mime-raw-buffer nil
386 "Raw buffer corresponding with the (MIME-View) buffer.")
387 (make-variable-buffer-local 'mime-raw-buffer)
389 (defvar mime-view-original-major-mode nil
390 "Major-mode in mime-raw-buffer.")
391 (make-variable-buffer-local 'mime-view-original-major-mode)
393 (make-variable-buffer-local 'mime::preview/original-window-configuration)
396 ;;; @@ quitting method
399 (defvar mime-view-quitting-method-alist
400 '((mime-show-message-mode
401 . mime-view-quitting-method-for-mime-show-message-mode))
402 "Alist of major-mode vs. quitting-method of mime-view.")
404 (defvar mime-view-over-to-previous-method-alist nil)
405 (defvar mime-view-over-to-next-method-alist nil)
407 (defvar mime-view-show-summary-method nil
408 "Alist of major-mode vs. show-summary-method.")
411 ;;; @@ following method
414 (defvar mime-view-following-method-alist nil
415 "Alist of major-mode vs. following-method of mime-view.")
417 (defvar mime-view-following-required-fields-list
424 ;; hack from Gnus 5.0.4.
426 (defvar mime-view-x-face-to-pbm-command
427 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm")
429 (defvar mime-view-x-face-command
430 (concat mime-view-x-face-to-pbm-command
432 "String to be executed to display an X-Face field.
433 The command will be executed in a sub-shell asynchronously.
434 The compressed face will be piped to this command.")
436 (defun mime-view-x-face-function ()
437 "Function to display X-Face field. You can redefine to customize."
438 ;; 1995/10/12 (c.f. tm-eng:130)
439 ;; fixed by Eric Ding <ericding@San-Jose.ate.slb.com>
441 (narrow-to-region (point-min) (re-search-forward "^$" nil t))
443 (goto-char (point-min))
444 (if (re-search-forward "^X-Face:[ \t]*" nil t)
445 (let ((beg (match-end 0))
446 (end (std11-field-end))
448 (call-process-region beg end "sh" nil 0 nil
449 "-c" mime-view-x-face-command)
456 (defun mime-view-setup-buffers (&optional ctl encoding ibuf obuf)
462 (or mime-view-redisplay
463 (setq mime::article/content-info (mime-parse-message ctl encoding))
465 (let* ((cinfo mime::article/content-info)
466 (pcl (mime/flatten-content-info cinfo))
467 (the-buf (current-buffer))
471 (setq obuf (concat "*Preview-" (buffer-name the-buf) "*")))
472 (set-buffer (get-buffer-create obuf))
473 (setq buffer-read-only nil)
476 (setq mime-raw-buffer the-buf)
477 (setq mime-view-original-major-mode mode)
478 (setq major-mode 'mime-view-mode)
479 (setq mode-name "MIME-View")
481 (mime-view-display-entity (car pcl) cinfo the-buf obuf)
484 (set-buffer-modified-p nil)
485 (setq buffer-read-only t)
488 (setq mime-view-buffer obuf)
491 (defun mime-view-display-entity (content cinfo ibuf obuf)
492 "Display entity from content-info CONTENT."
493 (let* ((beg (mime::content-info/point-min content))
494 (end (mime::content-info/point-max content))
495 (ctype (mime::content-info/type content))
496 (params (mime::content-info/parameters content))
497 (encoding (mime::content-info/encoding content))
498 (rcnum (mime::content-info/rcnum content))
502 (setq he (if (re-search-forward "^$" nil t)
509 (narrow-to-region beg end)
512 (mime-article/get-subject params encoding)))
516 (narrow-to-region nb nb)
517 (mime-view-entity-button-function rcnum cinfo ctype params subj encoding)
518 (if (mime-view-header-visible-p rcnum cinfo)
519 (mime-preview/display-header beg he)
521 (if (and (null rcnum)
523 ctype mime-view-content-button-visible-ctype-list))
525 (goto-char (point-max))
526 (mime-view-insert-entity-button
527 rcnum cinfo ctype params subj encoding)
529 (cond ((mime-view-body-visible-p rcnum cinfo ctype)
530 (mime-preview/display-body he end
531 rcnum cinfo ctype params subj encoding)
533 ((equal ctype "message/partial")
534 (mime-preview/display-message/partial)
537 (null (mime::content-info/children cinfo))
539 (goto-char (point-max))
540 (mime-view-insert-entity-button
541 rcnum cinfo ctype params subj encoding)
543 (mime-view-entity-separator-function rcnum cinfo ctype params subj)
544 (setq ne (point-max))
546 (put-text-property nb ne 'mime-view-raw-buffer ibuf)
547 (put-text-property nb ne 'mime-view-cinfo content)
551 (defun mime-preview/display-header (beg end)
553 (narrow-to-region (point)(point))
554 (insert-buffer-substring mime-raw-buffer beg end)
555 (let ((f (cdr (assq mime-view-original-major-mode
556 mime-view-content-header-filter-alist))))
559 (mime-view-default-content-header-filter)
561 (run-hooks 'mime-view-content-header-filter-hook)
564 (defun mime-preview/display-body (beg end
565 rcnum cinfo ctype params subj encoding)
567 (narrow-to-region (point-max)(point-max))
568 (insert-buffer-substring mime-raw-buffer beg end)
569 (let ((f (cdr (or (assoc ctype mime-view-content-filter-alist)
570 (assq t mime-view-content-filter-alist)))))
572 (funcall f ctype params encoding)
576 (defun mime-preview/display-message/partial ()
578 (goto-char (point-max))
579 (if (not (search-backward "\n\n" nil t))
582 (let ((be (point-max)))
583 (narrow-to-region be be)
584 (insert mime-view-announcement-for-message/partial)
585 (mime-add-button (point-min)(point-max)
586 (function mime-view-play-current-entity))
589 (defun mime-article/get-uu-filename (param &optional encoding)
590 (if (member (or encoding
591 (cdr (assq 'encoding param))
593 mime-view-uuencode-encoding-name-list)
595 (or (if (re-search-forward "^begin [0-9]+ " nil t)
596 (if (looking-at ".+$")
597 (buffer-substring (match-beginning 0)(match-end 0))
602 (defun mime-article/get-subject (param &optional encoding)
603 (or (std11-find-field-body '("Content-Description" "Subject"))
605 (if (or (and (setq ret (mime/Content-Disposition))
606 (setq ret (assoc "filename" (cdr ret)))
608 (setq ret (assoc "name" param))
609 (setq ret (assoc "x-name" param))
611 (std11-strip-quoted-string (cdr ret))
613 (mime-article/get-uu-filename param encoding)
617 ;;; @ content information
620 (defun mime-article/point-content-number (p &optional cinfo)
622 (setq cinfo mime::article/content-info)
624 (let ((b (mime::content-info/point-min cinfo))
625 (e (mime::content-info/point-max cinfo))
626 (c (mime::content-info/children cinfo))
628 (if (and (<= b p)(<= p e))
629 (or (let (co ret (sn 0))
633 (setq ret (mime-article/point-content-number p co))
634 (cond ((eq ret t) (throw 'tag (list sn)))
635 (ret (throw 'tag (cons sn ret)))
642 (defun mime-article/rcnum-to-cinfo (rcnum &optional cinfo)
644 (setq cinfo mime::article/content-info)
648 (equal (mime::content-info/rcnum ci) rcnum)
650 (mime/flatten-content-info cinfo)
653 (defun mime-article/cnum-to-cinfo (cn &optional cinfo)
655 (setq cinfo mime::article/content-info)
662 (let ((rc (nth sn (mime::content-info/children cinfo))))
664 (mime-article/cnum-to-cinfo (cdr cn) rc)
668 (defun mime/flatten-content-info (&optional cinfo)
670 (setq cinfo mime::article/content-info)
672 (let ((dest (list cinfo))
673 (rcl (mime::content-info/children cinfo))
676 (setq dest (nconc dest (mime/flatten-content-info (car rcl))))
682 ;;; @ MIME viewer mode
685 (defconst mime-view-menu-title "MIME-View")
686 (defconst mime-view-menu-list
687 '((up "Move to upper content" mime-view-move-to-upper)
688 (previous "Move to previous content" mime-view-move-to-previous)
689 (next "Move to next content" mime-view-move-to-next)
690 (scroll-down "Scroll to previous content" mime-view-scroll-down-entity)
691 (scroll-up "Scroll to next content" mime-view-scroll-up-entity)
692 (play "Play Content" mime-view-play-current-entity)
693 (extract "Extract Content" mime-view-extract-current-entity)
694 (print "Print" mime-view-print-current-entity)
695 (x-face "Show X Face" mime-view-display-x-face)
697 "Menu for MIME Viewer")
699 (cond (running-xemacs
700 (defvar mime-view-xemacs-popup-menu
701 (cons mime-view-menu-title
704 (vector (nth 1 item)(nth 2 item) t)
706 mime-view-menu-list)))
707 (defun mime-view-xemacs-popup-menu (event)
708 "Popup the menu in the MIME Viewer buffer"
710 (select-window (event-window event))
711 (set-buffer (event-buffer event))
712 (popup-menu 'mime-view-xemacs-popup-menu))
713 (defvar mouse-button-2 'button2)
716 (defvar mouse-button-2 [mouse-2])
719 (defun mime-view-define-keymap (&optional default)
720 (let ((mime-view-mode-map (if (keymapp default)
721 (copy-keymap default)
724 (define-key mime-view-mode-map
725 "u" (function mime-view-move-to-upper))
726 (define-key mime-view-mode-map
727 "p" (function mime-view-move-to-previous))
728 (define-key mime-view-mode-map
729 "n" (function mime-view-move-to-next))
730 (define-key mime-view-mode-map
731 "\e\t" (function mime-view-move-to-previous))
732 (define-key mime-view-mode-map
733 "\t" (function mime-view-move-to-next))
734 (define-key mime-view-mode-map
735 " " (function mime-view-scroll-up-entity))
736 (define-key mime-view-mode-map
737 "\M- " (function mime-view-scroll-down-entity))
738 (define-key mime-view-mode-map
739 "\177" (function mime-view-scroll-down-entity))
740 (define-key mime-view-mode-map
741 "\C-m" (function mime-view-next-line-content))
742 (define-key mime-view-mode-map
743 "\C-\M-m" (function mime-view-previous-line-content))
744 (define-key mime-view-mode-map
745 "v" (function mime-view-play-current-entity))
746 (define-key mime-view-mode-map
747 "e" (function mime-view-extract-current-entity))
748 (define-key mime-view-mode-map
749 "\C-c\C-p" (function mime-view-print-current-entity))
750 (define-key mime-view-mode-map
751 "a" (function mime-view-follow-current-entity))
752 (define-key mime-view-mode-map
753 "q" (function mime-view-quit))
754 (define-key mime-view-mode-map
755 "h" (function mime-view-show-summary))
756 (define-key mime-view-mode-map
757 "\C-c\C-x" (function mime-view-kill-buffer))
758 (define-key mime-view-mode-map
759 "<" (function beginning-of-buffer))
760 (define-key mime-view-mode-map
761 ">" (function end-of-buffer))
762 (define-key mime-view-mode-map
763 "?" (function describe-mode))
764 (if (functionp default)
765 (cond (running-xemacs
766 (set-keymap-default-binding mime-view-mode-map default)
769 (setq mime-view-mode-map
770 (append mime-view-mode-map (list (cons t default))))
773 (define-key mime-view-mode-map
774 mouse-button-2 (function mime-button-dispatcher))
776 (cond (running-xemacs
777 (define-key mime-view-mode-map
778 mouse-button-3 (function mime-view-xemacs-popup-menu))
780 ((>= emacs-major-version 19)
781 (define-key mime-view-mode-map [menu-bar mime-view]
782 (cons mime-view-menu-title
783 (make-sparse-keymap mime-view-menu-title)))
786 (define-key mime-view-mode-map
787 (vector 'menu-bar 'mime-view (car item))
788 (cons (nth 1 item)(nth 2 item))
791 (reverse mime-view-menu-list)
794 (use-local-map mime-view-mode-map)
795 (run-hooks 'mime-view-define-keymap-hook)
798 (defsubst mime-hide-echo-buffer ()
799 "Hide mime-echo buffer."
800 (let ((win (get-buffer-window mime-echo-buffer-name)))
805 (defun mime-view-mode (&optional mother ctl encoding ibuf obuf
806 default-keymap-or-function)
807 "Major mode for viewing MIME message.
809 Here is a list of the standard keys for mime-view-mode.
814 u Move to upper content
815 p or M-TAB Move to previous content
816 n or TAB Move to next content
817 SPC Scroll up or move to next content
818 M-SPC or DEL Scroll down or move to previous content
819 RET Move to next line
820 M-RET Move to previous line
821 v Decode current content as `play mode'
822 e Decode current content as `extract mode'
823 C-c C-p Decode current content as `print mode'
824 a Followup to current content.
827 button-2 Move to point under the mouse cursor
828 and decode current content as `play mode'
831 (let ((buf (get-buffer mime-echo-buffer-name)))
836 (mime-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-view-play-current-entity "mime-play" "Play current entity." t)
864 (defun mime-view-extract-current-entity ()
865 "Extract current entity into file (maybe).
866 It decodes current entity to call internal or external method as
867 \"extract\" mode. The method is selected from variable
868 `mime/content-decoding-condition'."
870 (mime-view-play-current-entity "extract")
873 (defun mime-view-print-current-entity ()
874 "Print current entity (maybe).
875 It decodes current entity to call internal or external method as
876 \"print\" mode. The method is selected from variable
877 `mime/content-decoding-condition'."
879 (mime-view-play-current-entity "print")
886 (defun mime-view-get-original-major-mode ()
887 "Return major-mode of original buffer.
888 If a current buffer has mime-mother-buffer, return original major-mode
889 of the mother-buffer."
890 (if mime-mother-buffer
892 (set-buffer mime-mother-buffer)
893 (mime-view-get-original-major-mode)
895 mime-view-original-major-mode))
897 (defun mime-view-follow-current-entity ()
898 "Write follow message to current entity.
899 It calls following-method selected from variable
900 `mime-view-following-method-alist'."
902 (let ((root-cinfo (get-text-property (point-min) 'mime-view-cinfo))
904 (while (null (setq cinfo (get-text-property (point) 'mime-view-cinfo)))
907 (let* ((p-beg (previous-single-property-change (point) 'mime-view-cinfo))
909 (rcnum (mime::content-info/rcnum cinfo))
914 (if (eq (next-single-property-change (point-min)
920 ((eq (next-single-property-change p-beg 'mime-view-cinfo)
924 (setq p-end (next-single-property-change p-beg 'mime-view-cinfo))
926 (setq p-end (point-max))
929 (setq p-end (point-max))
937 (next-single-property-change
938 (point) 'mime-view-cinfo))
940 (let ((rc (mime::content-info/rcnum
941 (get-text-property (point)
943 (or (equal rcnum (nthcdr (- (length rc) len) rc))
948 (setq p-end (point-max))
951 (let* ((mode (mime-view-get-original-major-mode))
952 (new-name (format "%s-%s" (buffer-name) (reverse rcnum)))
954 (the-buf (current-buffer))
955 (a-buf mime-raw-buffer)
958 (set-buffer (setq new-buf (get-buffer-create new-name)))
960 (insert-buffer-substring the-buf p-beg p-end)
961 (goto-char (point-min))
962 (if (mime-view-header-visible-p rcnum root-cinfo)
963 (delete-region (goto-char (point-min))
964 (if (re-search-forward "^$" nil t)
968 (goto-char (point-min))
970 (goto-char (point-min))
971 (let ((rcnum (mime::content-info/rcnum cinfo)) ci str)
976 (setq ci (mime-article/rcnum-to-cinfo rcnum))
979 (mime::content-info/point-min ci)
980 (mime::content-info/point-max ci)
982 (std11-header-string-except
984 (apply (function regexp-or) fields)
986 (if (string= (mime::content-info/type ci)
993 (setq fields (std11-collect-field-names)
997 (let ((rest mime-view-following-required-fields-list))
999 (let ((field-name (car rest)))
1000 (or (std11-field-body field-name)
1006 (set-buffer the-buf)
1007 (set-buffer mime-mother-buffer)
1008 (set-buffer mime-raw-buffer)
1009 (std11-field-body field-name)
1013 (setq rest (cdr rest))
1015 (eword-decode-header)
1017 (let ((f (cdr (assq mode mime-view-following-method-alist))))
1022 "Sorry, following method for %s is not implemented yet."
1031 (defun mime-view-display-x-face ()
1033 (save-window-excursion
1034 (set-buffer mime-raw-buffer)
1035 (mime-view-x-face-function)
1042 (defun mime-view-move-to-upper ()
1043 "Move to upper entity.
1044 If there is no upper entity, call function `mime-view-quit'."
1047 (while (null (setq cinfo (get-text-property (point) 'mime-view-cinfo)))
1050 (let ((r (mime-article/rcnum-to-cinfo
1051 (cdr (mime::content-info/rcnum cinfo))
1052 (get-text-property 1 'mime-view-cinfo)))
1055 (while (setq point (previous-single-property-change
1056 (point) 'mime-view-cinfo))
1058 (if (eq r (get-text-property (point) 'mime-view-cinfo))
1065 (defun mime-view-move-to-previous ()
1066 "Move to previous entity.
1067 If there is no previous entity, it calls function registered in
1068 variable `mime-view-over-to-previous-method-alist'."
1070 (while (null (get-text-property (point) 'mime-view-cinfo))
1073 (let ((point (previous-single-property-change (point) 'mime-view-cinfo)))
1076 (let ((f (assq mime-view-original-major-mode
1077 mime-view-over-to-previous-method-alist)))
1083 (defun mime-view-move-to-next ()
1084 "Move to next entity.
1085 If there is no previous entity, it calls function registered in
1086 variable `mime-view-over-to-next-method-alist'."
1088 (let ((point (next-single-property-change (point) 'mime-view-cinfo)))
1091 (let ((f (assq mime-view-original-major-mode
1092 mime-view-over-to-next-method-alist)))
1098 (defun mime-view-scroll-up-entity (&optional h)
1099 "Scroll up current entity.
1100 If reached to (point-max), it calls function registered in variable
1101 `mime-view-over-to-next-method-alist'."
1104 (setq h (1- (window-height)))
1106 (if (= (point) (point-max))
1107 (let ((f (assq mime-view-original-major-mode
1108 mime-view-over-to-next-method-alist)))
1113 (or (next-single-property-change (point) 'mime-view-cinfo)
1116 (if (> (point) point)
1121 (defun mime-view-scroll-down-entity (&optional h)
1122 "Scroll down current entity.
1123 If reached to (point-min), it calls function registered in variable
1124 `mime-view-over-to-previous-method-alist'."
1127 (setq h (1- (window-height)))
1129 (if (= (point) (point-min))
1130 (let ((f (assq mime-view-original-major-mode
1131 mime-view-over-to-previous-method-alist)))
1138 (while (> (point) 1)
1140 (previous-single-property-change (point)
1146 (setq point (point-min))
1148 (forward-line (- h))
1149 (if (< (point) point)
1153 (defun mime-view-next-line-content ()
1155 (mime-view-scroll-up-entity 1)
1158 (defun mime-view-previous-line-content ()
1160 (mime-view-scroll-down-entity 1)
1167 (defun mime-view-quit ()
1168 "Quit from MIME-View buffer.
1169 It calls function registered in variable
1170 `mime-view-quitting-method-alist'."
1172 (let ((r (assq mime-view-original-major-mode
1173 mime-view-quitting-method-alist)))
1178 (defun mime-view-show-summary ()
1180 It calls function registered in variable
1181 `mime-view-show-summary-method'."
1183 (let ((r (assq mime-view-original-major-mode
1184 mime-view-show-summary-method)))
1189 (defun mime-view-kill-buffer ()
1191 (kill-buffer (current-buffer))
1198 (provide 'mime-view)
1200 (run-hooks 'mime-view-load-hook)
1202 ;;; mime-view.el ends here