-(defvar mime-view-redisplay nil)
-
-(defun mime-view-setup-buffers (&optional ctl encoding ibuf obuf)
- (if ibuf
- (progn
- (get-buffer ibuf)
- (set-buffer ibuf)
- ))
- (or mime-view-redisplay
- (setq mime-raw-message-info (mime-parse-message ctl encoding))
- )
- (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))
- (let ((inhibit-read-only t))
- ;;(setq buffer-read-only nil)
- (widen)
- (erase-buffer)
- (setq mime-raw-buffer the-buf)
- (setq mime-preview-original-major-mode mode)
- (setq major-mode 'mime-view-mode)
- (setq mode-name "MIME-View")
- (mime-view-display-message message-info the-buf obuf)
- (set-buffer-modified-p nil)
- )
- (setq buffer-read-only t)
- (set-buffer the-buf)
- )
- (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))
- (ctype (if media-type
- (if media-subtype
- (format "%s/%s" media-type media-subtype)
- (symbol-name media-type)
- )))
- (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)
- (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))
- 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)
- (if (mime-view-entity-button-visible-p entity message-info)
- (mime-view-insert-entity-button entity message-info subj)
- )
- (if (mime-view-header-visible-p entity message-info)
- (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)))
- (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
- (cdr (assq 'encoding param))
- )
- mime-view-uuencode-encoding-name-list)
- (save-excursion
- (or (if (re-search-forward "^begin [0-9]+ " nil t)
- (if (looking-at ".+$")
- (buffer-substring (match-beginning 0)(match-end 0))
- ))
- ""))
- ))
-
-(defun mime-raw-get-subject (param &optional encoding)
- (or (std11-find-field-body '("Content-Description" "Subject"))
- (let (ret)
- (if (or (and (setq ret (mime/Content-Disposition))
- (setq ret (assoc "filename" (cdr ret)))
- )
- (setq ret (assoc "name" param))
- (setq ret (assoc "x-name" param))
- )
- (std11-strip-quoted-string (cdr ret))
+(defun mime-display-entity (entity &optional situation
+ default-situation preview-buffer)
+ (or preview-buffer
+ (setq preview-buffer (current-buffer)))
+ (let* (e nb ne nhb nbb)
+ (in-calist-package 'mime-view)
+ (or situation
+ (setq situation
+ (mime-find-entity-preview-situation entity default-situation)))
+ (let ((button-is-invisible
+ (eq (cdr (or (assq '*entity-button situation)
+ (assq 'entity-button situation)))
+ 'invisible))
+ (header-is-visible
+ (eq (cdr (or (assq '*header situation)
+ (assq 'header situation)))
+ 'visible))
+ (body-is-visible
+ (eq (cdr (or (assq '*body situation)
+ (assq 'body situation)))
+ 'visible))
+ (children (mime-entity-children entity)))
+ (set-buffer preview-buffer)
+ (setq nb (point))
+ (narrow-to-region nb nb)
+ (or button-is-invisible
+ ;; (if (mime-view-entity-button-visible-p entity)
+ (mime-view-insert-entity-button entity)
+ ;; )
+ )
+ (if header-is-visible
+ (let ((header-presentation-method
+ (or (cdr (assq 'header-presentation-method situation))
+ (cdr (assq (cdr (assq 'major-mode situation))
+ mime-header-presentation-method-alist)))))
+ (setq nhb (point))
+ (if header-presentation-method
+ (funcall header-presentation-method entity situation)
+ (mime-insert-header entity
+ mime-view-ignored-field-list
+ mime-view-visible-field-list))
+ (run-hooks 'mime-display-header-hook)
+ (put-text-property nhb (point-max) 'mime-view-entity-header entity)
+ (goto-char (point-max))
+ (insert "\n")))
+ (setq nbb (point))
+ (unless children
+ (if body-is-visible
+ (let ((body-presentation-method
+ (cdr (assq 'body-presentation-method situation))))
+ (if (functionp body-presentation-method)
+ (funcall body-presentation-method entity situation)
+ (mime-display-text/plain entity situation)))
+ (when button-is-invisible
+ (goto-char (point-max))
+ (mime-view-insert-entity-button entity)
+ )
+ (unless header-is-visible
+ (goto-char (point-max))
+ (insert "\n"))