;; Copyright (C) 1995,1996,1997,1998 Free Software Foundation, Inc.
;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
-;; Created: 1994/7/13
-;; Renamed: 1994/8/31 from tm-body.el
+;; Created: 1994/07/13
+;; Renamed: 1994/08/31 from tm-body.el
;; Renamed: 1997/02/19 from tm-view.el
;; Keywords: MIME, multimedia, mail, news
(require 'mel)
(require 'eword-decode)
(require 'mime-parse)
+(require 'semi-def)
(require 'calist)
;;;
(defconst mime-view-version-string
- `,(concat "SEMI MIME-View "
- (mapconcat #'number-to-string (cdr semi-version) ".")
- " (" (car semi-version) ")"))
+ `,(concat (car mime-module-version) " MIME-View "
+ (mapconcat #'number-to-string (cddr mime-module-version) ".")
+ " (" (cadr mime-module-version) ")"))
;;; @ buffer local variables
;;; @@@ predicate function
;;;
-(defvar mime-view-content-button-visible-ctype-list
- '("application/pgp"))
-
(defun mime-view-entity-button-visible-p (entity message-info)
"Return non-nil if header of ENTITY is visible.
Please redefine this function if you want to change default setting."
- (and (not (mime-root-entity-p entity))
- (let ((media-type (mime-entity-media-type entity))
- (media-subtype (mime-entity-media-subtype entity)))
- (or (not (eq media-type 'application))
- (and (not (eq media-subtype 'x-selection))
- (or (not (eq media-subtype 'octet-stream))
- (let ((mother-entity
- (mime-raw-entity-parent entity message-info)))
- (or (not (eq (mime-entity-media-type mother-entity)
- 'multipart))
- (not (eq (mime-entity-media-subtype mother-entity)
- 'encrypted)))
- )
- ))))))
+ (let ((media-type (mime-entity-media-type entity))
+ (media-subtype (mime-entity-media-subtype entity)))
+ (or (not (eq media-type 'application))
+ (and (not (eq media-subtype 'x-selection))
+ (or (not (eq media-subtype 'octet-stream))
+ (let ((mother-entity
+ (mime-raw-entity-parent entity message-info)))
+ (or (not (eq (mime-entity-media-type mother-entity)
+ 'multipart))
+ (not (eq (mime-entity-media-subtype mother-entity)
+ 'encrypted)))
+ )
+ )))))
;;; @@@ entity button generator
;;;
(defun mime-view-header-visible-p (entity message-info)
"Return non-nil if header of ENTITY is visible."
(let ((entity-node-id (mime-entity-node-id entity)))
- (or (null entity-node-id)
- (member (mime-entity-type/subtype
- (mime-raw-find-entity-from-node-id
- (cdr entity-node-id) message-info))
- mime-view-childrens-header-showing-Content-Type-list)
- )))
+ (member (mime-entity-type/subtype
+ (mime-raw-find-entity-from-node-id
+ (cdr entity-node-id) message-info))
+ mime-view-childrens-header-showing-Content-Type-list)
+ ))
;;; @@@ entity header filter
;;;
;;; @@@ predicate function
;;;
-(defvar mime-view-body-visible-condition
- '(type
- (nil)
- (text subtype
- (plain)
- (enriched)
- (rfc822-headers)
- (richtext)
- (x-latex)
- (x-pgp))
- (application subtype
- (octet-stream encoding
- (nil)
- ("7bit")
- ("8bit"))
- (pgp)
- (x-latex)
- (x-selection)
- (x-comment))
- (message subtype
- (delivery-status)))
- "Condition-tree to be able to display body of entity.")
+(defvar mime-preview-condition nil
+ "Condition-tree about how to display entity.")
+
+(ctree-set-calist-strictly
+ 'mime-preview-condition '((type . application)(subtype . octet-stream)
+ (encoding . nil)
+ (body . visible)))
+(ctree-set-calist-strictly
+ 'mime-preview-condition '((type . application)(subtype . octet-stream)
+ (encoding . "7bit")
+ (body . visible)))
+(ctree-set-calist-strictly
+ 'mime-preview-condition '((type . application)(subtype . octet-stream)
+ (encoding . "8bit")
+ (body . visible)))
+
+(ctree-set-calist-strictly
+ 'mime-preview-condition '((type . application)(subtype . pgp)
+ (body . visible)))
+
+(ctree-set-calist-strictly
+ 'mime-preview-condition '((type . application)(subtype . x-latex)
+ (body . visible)))
+
+(ctree-set-calist-strictly
+ 'mime-preview-condition '((type . application)(subtype . x-selection)
+ (body . visible)))
+
+(ctree-set-calist-strictly
+ 'mime-preview-condition '((type . application)(subtype . x-comment)
+ (body . visible)))
+
+(ctree-set-calist-strictly
+ 'mime-preview-condition '((type . message)(subtype . delivery-status)
+ (body . visible)))
+
+(ctree-set-calist-strictly
+ 'mime-preview-condition '((body . visible)
+ (body-presentation-method . with-filter)
+ (body-filter . mime-preview-filter-for-text/plain)))
+
+(ctree-set-calist-strictly
+ 'mime-preview-condition '((type . nil)
+ (body . visible)
+ (body-presentation-method . with-filter)
+ (body-filter . mime-preview-filter-for-text/plain)))
+
+(ctree-set-calist-strictly
+ 'mime-preview-condition '((type . text)(subtype . enriched)
+ (body . visible)
+ (body-presentation-method . with-filter)
+ (body-filter
+ . mime-preview-filter-for-text/enriched)))
+
+(ctree-set-calist-strictly
+ 'mime-preview-condition '((type . text)(subtype . richtext)
+ (body . visible)
+ (body-presentation-method . with-filter)
+ (body-filter
+ . mime-preview-filter-for-text/richtext)))
+
+(ctree-set-calist-strictly
+ 'mime-preview-condition '((type . text)(subtype . t)
+ (body . visible)
+ (body-presentation-method . with-filter)
+ (body-filter . mime-preview-filter-for-text/plain)))
+
+(ctree-set-calist-strictly
+ 'mime-preview-condition '((type . message)(subtype . partial)
+ (body-presentation-method
+ . mime-view-insert-message/partial-button)))
(defun mime-view-body-visible-p (entity message-info)
"Return non-nil if body of ENTITY is visible."
- (ctree-match-calist
- mime-view-body-visible-condition
- (list* (cons 'type (mime-entity-media-type entity))
- (cons 'subtype (mime-entity-media-subtype entity))
- (cons 'encoding (mime-entity-encoding entity))
- (cons 'major-mode major-mode)
- (mime-entity-parameters entity))))
+ (ctree-match-calist mime-preview-condition
+ (list* (cons 'type (mime-entity-media-type entity))
+ (cons 'subtype (mime-entity-media-subtype entity))
+ (cons 'encoding (mime-entity-encoding entity))
+ (cons 'major-mode major-mode)
+ (mime-entity-parameters entity))))
;;; @@@ entity filter
;;;
-(defvar mime-view-content-filter-alist
- '(("text/enriched" . mime-view-filter-for-text/enriched)
- ("text/richtext" . mime-view-filter-for-text/richtext)
- (t . mime-view-filter-for-text/plain)
- )
- "Alist of media-types vs. corresponding MIME-preview filter functions.
-Each element looks like (TYPE/SUBTYPE . FUNCTION) or (t . FUNCTION).
-TYPE/SUBTYPE is a string of media-type and FUNCTION is a filter
-function. t means default media-type.")
-
-
-(autoload 'mime-view-filter-for-text/plain "mime-text")
-(autoload 'mime-view-filter-for-text/enriched "mime-text")
-(autoload 'mime-view-filter-for-text/richtext "mime-text")
+(autoload 'mime-preview-filter-for-text/plain "mime-text")
+(autoload 'mime-preview-filter-for-text/enriched "mime-text")
+(autoload 'mime-preview-filter-for-text/richtext "mime-text")
(defvar mime-text-decoder-alist
'((mime-show-message-mode . mime-text-decode-buffer)
\[[ Please press `v' key in this buffer. ]]"
))
-(defun mime-view-insert-message/partial-button ()
+(defun mime-view-insert-message/partial-button (&optional situation)
(save-restriction
(goto-char (point-max))
(if (not (search-backward "\n\n" nil t))
(or mime-view-redisplay
(setq mime-raw-message-info (mime-parse-message ctl encoding))
)
- (let* ((message-info mime-raw-message-info)
- (pcl (mime-raw-flatten-message-info message-info))
- (the-buf (current-buffer))
- (mode major-mode)
- )
+ (let ((message-info mime-raw-message-info)
+ (the-buf (current-buffer))
+ (mode major-mode))
(or obuf
(setq obuf (concat "*Preview-" (buffer-name the-buf) "*")))
(set-buffer (get-buffer-create obuf))
(setq mime-preview-original-major-mode mode)
(setq major-mode 'mime-view-mode)
(setq mode-name "MIME-View")
- (while pcl
- (mime-view-display-entity (car pcl) message-info the-buf obuf)
- (setq pcl (cdr pcl))
- )
+ (mime-view-display-message message-info the-buf obuf)
(set-buffer-modified-p nil)
)
(setq buffer-read-only t)
(setq mime-preview-buffer obuf)
)
+(defun mime-view-display-message (message-info ibuf obuf)
+ (let* ((start (mime-entity-point-min message-info))
+ (end (mime-entity-point-max message-info))
+ (media-type (mime-entity-media-type message-info))
+ (media-subtype (mime-entity-media-subtype message-info))
+ (params (mime-entity-parameters message-info))
+ (encoding (mime-entity-encoding message-info))
+ end-of-header e nb ne subj)
+ (set-buffer ibuf)
+ (goto-char start)
+ (setq end-of-header (if (re-search-forward "^$" nil t)
+ (1+ (match-end 0))
+ end))
+ (if (> end-of-header end)
+ (setq end-of-header end)
+ )
+ (save-restriction
+ (narrow-to-region start end)
+ (setq subj
+ (eword-decode-string
+ (mime-raw-get-subject params encoding)))
+ )
+ (set-buffer obuf)
+ (setq nb (point))
+ (narrow-to-region nb nb)
+ ;; Insert message-header
+ (save-restriction
+ (narrow-to-region (point)(point))
+ (insert-buffer-substring mime-raw-buffer start end-of-header)
+ (let ((f (cdr (assq mime-preview-original-major-mode
+ mime-view-content-header-filter-alist))))
+ (if (functionp f)
+ (funcall f)
+ (mime-view-default-content-header-filter)
+ ))
+ (run-hooks 'mime-view-content-header-filter-hook)
+ )
+ (let* ((situation
+ (ctree-match-calist mime-preview-condition
+ (list* (cons 'type media-type)
+ (cons 'subtype media-subtype)
+ (cons 'encoding encoding)
+ (cons 'major-mode major-mode)
+ params)))
+ (message-button
+ (cdr (assq 'message-button situation)))
+ (body-presentation-method
+ (cdr (assq 'body-presentation-method situation))))
+ (when message-button
+ (goto-char (point-max))
+ (mime-view-insert-entity-button message-info message-info subj)
+ )
+ (cond ((eq body-presentation-method 'with-filter)
+ (let ((body-filter (cdr (assq 'body-filter situation))))
+ (save-restriction
+ (narrow-to-region (point-max)(point-max))
+ (insert-buffer-substring mime-raw-buffer end-of-header end)
+ (funcall body-filter situation)
+ )))
+ ((functionp body-presentation-method)
+ (funcall body-presentation-method situation)
+ )
+ ((null (mime-entity-children message-info))
+ (goto-char (point-max))
+ (mime-view-insert-entity-button message-info message-info subj)
+ ))
+ )
+ (setq ne (point-max))
+ (widen)
+ (put-text-property nb ne 'mime-view-raw-buffer ibuf)
+ (put-text-property nb ne 'mime-view-entity message-info)
+ (goto-char ne)
+ (let ((children (mime-entity-children message-info)))
+ (while children
+ (mime-view-display-entity (car children) message-info ibuf obuf)
+ (setq children (cdr children))
+ ))))
+
(defun mime-view-display-entity (entity message-info ibuf obuf)
- "Display ENTITY."
(let* ((start (mime-entity-point-min entity))
(end (mime-entity-point-max entity))
(media-type (mime-entity-media-type entity))
(media-subtype (mime-entity-media-subtype entity))
- (ctype (if media-type
- (if media-subtype
- (format "%s/%s" media-type media-subtype)
- (symbol-name media-type)
- )))
(params (mime-entity-parameters entity))
(encoding (mime-entity-encoding entity))
- (entity-node-id (mime-entity-node-id entity))
end-of-header e nb ne subj)
(set-buffer ibuf)
(goto-char start)
))
(run-hooks 'mime-view-content-header-filter-hook)
))
- (if (and (mime-root-entity-p entity)
- (member
- ctype mime-view-content-button-visible-ctype-list))
- (save-excursion
- (goto-char (point-max))
- (mime-view-insert-entity-button entity message-info subj)
- ))
- (cond ((mime-view-body-visible-p entity message-info)
- (save-restriction
- (narrow-to-region (point-max)(point-max))
- (insert-buffer-substring mime-raw-buffer end-of-header end)
- (let ((f (cdr (or (assoc ctype mime-view-content-filter-alist)
- (assq t mime-view-content-filter-alist)))))
- (and (functionp f)
- (funcall f ctype params encoding))
- )))
- ((and (eq media-type 'message)(eq media-subtype 'partial))
- (mime-view-insert-message/partial-button)
- )
- ((and (null entity-node-id)
- (null (mime-entity-children message-info))
- )
- (goto-char (point-max))
- (mime-view-insert-entity-button entity message-info subj)
- ))
- (when (mime-view-entity-separator-visible-p entity message-info)
- (goto-char (point-max))
- (insert "\n"))
+ (let* ((situation
+ (ctree-match-calist mime-preview-condition
+ (list* (cons 'type media-type)
+ (cons 'subtype media-subtype)
+ (cons 'encoding encoding)
+ (cons 'major-mode major-mode)
+ params)))
+ (body-presentation-method
+ (cdr (assq 'body-presentation-method situation))))
+ (cond ((eq body-presentation-method 'with-filter)
+ (let ((body-filter (cdr (assq 'body-filter situation))))
+ (save-restriction
+ (narrow-to-region (point-max)(point-max))
+ (insert-buffer-substring mime-raw-buffer end-of-header end)
+ (funcall body-filter situation)
+ )))
+ ((functionp body-presentation-method)
+ (funcall body-presentation-method situation)
+ ))
+ (when (mime-view-entity-separator-visible-p entity message-info)
+ (goto-char (point-max))
+ (insert "\n"))
+ )
(setq ne (point-max))
(widen)
(put-text-property nb ne 'mime-view-raw-buffer ibuf)
(put-text-property nb ne 'mime-view-entity entity)
(goto-char ne)
- ))
+ (let ((children (mime-entity-children entity)))
+ (while children
+ (mime-view-display-entity (car children) message-info ibuf obuf)
+ (setq children (cdr children))
+ ))))
(defun mime-raw-get-uu-filename (param &optional encoding)
(if (member (or encoding