(mime-entity-safe-filename): Use `mime-read-field' instead of
[elisp/semi.git] / mime-view.el
index 19b2c5f..32ff988 100644 (file)
@@ -27,8 +27,7 @@
 
 ;;; Code:
 
-(require 'std11)
-(require 'mime-lib)
+(require 'mime)
 (require 'semi-def)
 (require 'calist)
 (require 'alist)
@@ -175,6 +174,15 @@ mother-buffer."
 ;;; @ entity information
 ;;;
 
+(defsubst mime-entity-representation-type (entity)
+  (with-current-buffer (mime-entity-buffer entity)
+    (or mime-raw-representation-type
+       (cdr (or (assq major-mode mime-raw-representation-type-alist)
+                (assq t mime-raw-representation-type-alist))))))
+
+(defsubst mime-entity-cooked-p (entity)
+  (eq (mime-entity-representation-type entity) 'cooked))
+
 (defsubst mime-entity-parent (entity &optional message-info)
   "Return mother entity of ENTITY.
 If optional argument MESSAGE-INFO is not specified,
@@ -234,26 +242,17 @@ If optional argument MESSAGE-INFO is not specified,
 
 (defun mime-entity-filename (entity)
   (or (mime-entity-uu-filename entity)
-      (let ((ret (mime-entity-content-disposition entity)))
-       (and ret
-            (setq ret (mime-content-disposition-filename ret))
-            (std11-strip-quoted-string ret)
-            ))
-      (let ((ret (mime-entity-content-type entity)))
-       (and ret
-            (setq ret
-                  (cdr
-                   (let ((param (mime-content-type-parameters ret)))
-                     (or (assoc "name" param)
-                         (assoc "x-name" param))
-                     )))
-            (std11-strip-quoted-string ret)
-            ))
-      ))
+      (mime-content-disposition-filename
+       (mime-entity-content-disposition entity))
+      (cdr (let ((param (mime-content-type-parameters
+                        (mime-entity-content-type entity))))
+            (or (assoc "name" param)
+                (assoc "x-name" param))
+            ))))
 
 (defun mime-view-entity-title (entity)
-  (or (mime-entity-read-field entity 'Content-Description)
-      (mime-entity-read-field entity 'Subject)
+  (or (mime-read-field 'Content-Description entity)
+      (mime-read-field 'Subject entity)
       (mime-entity-filename entity)
       ""))
 
@@ -715,38 +714,6 @@ MEDIA-TYPE must be (TYPE . SUBTYPE), TYPE or t.  t means default."
   '("From"))
 
 
-;;; @ X-Face
-;;;
-
-;; hack from Gnus 5.0.4.
-
-(defvar mime-view-x-face-to-pbm-command
-  "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm")
-
-(defvar mime-view-x-face-command
-  (concat mime-view-x-face-to-pbm-command
-         " | xv -quit -")
-  "String to be executed to display an X-Face field.
-The command will be executed in a sub-shell asynchronously.
-The compressed face will be piped to this command.")
-
-(defun mime-view-x-face-function ()
-  "Function to display X-Face field. You can redefine to customize."
-  ;; 1995/10/12 (c.f. tm-eng:130)
-  ;;   fixed by Eric Ding <ericding@San-Jose.ate.slb.com>
-  (save-restriction
-    (narrow-to-region (point-min) (re-search-forward "^$" nil t))
-    ;; end
-    (goto-char (point-min))
-    (if (re-search-forward "^X-Face:[ \t]*" nil t)
-       (let ((beg (match-end 0))
-             (end (std11-field-end))
-             )
-         (call-process-region beg end "sh" nil 0 nil
-                              "-c" mime-view-x-face-command)
-         ))))
-
-
 ;;; @ buffer setup
 ;;;
 
@@ -785,15 +752,13 @@ The compressed face will be piped to this command.")
       (when header-is-visible
        (if header-presentation-method
            (funcall header-presentation-method entity situation)
-         (mime-insert-decoded-header
-          entity
-          mime-view-ignored-field-list mime-view-visible-field-list
-          (save-excursion
-            (set-buffer raw-buffer)
-            (if (eq (cdr (assq major-mode mime-raw-representation-type-alist))
-                    'binary)
-                default-mime-charset)
-            )))
+         (mime-insert-decoded-header entity
+                                     mime-view-ignored-field-list
+                                     mime-view-visible-field-list
+                                     (if (mime-entity-cooked-p entity)
+                                         nil
+                                       default-mime-charset))
+         )
        (goto-char (point-max))
        (insert "\n")
        (run-hooks 'mime-display-header-hook)
@@ -838,7 +803,6 @@ The compressed face will be piped to this command.")
     (play       "Play current entity"     mime-preview-play-current-entity)
     (extract    "Extract current entity"  mime-preview-extract-current-entity)
     (print      "Print current entity"    mime-preview-print-current-entity)
-    (x-face     "Show X Face"             mime-preview-display-x-face)
     )
   "Menu for MIME Viewer")
 
@@ -970,10 +934,9 @@ The compressed face will be piped to this command.")
        (setq preview-buffer
              (concat "*Preview-" (buffer-name raw-buffer) "*")))
     (set-buffer raw-buffer)
-    (mime-parse-buffer)
     (setq mime-preview-buffer preview-buffer)
     (let ((inhibit-read-only t))
-      (switch-to-buffer preview-buffer)
+      (set-buffer (get-buffer-create preview-buffer))
       (widen)
       (erase-buffer)
       (setq mime-raw-buffer raw-buffer)
@@ -996,19 +959,21 @@ The compressed face will be piped to this command.")
          (search-forward "\n\n" nil t)
          ))
       (run-hooks 'mime-view-mode-hook)
-      ))
-  (set-buffer-modified-p nil)
-  (setq buffer-read-only t)
-  )
+      (set-buffer-modified-p nil)
+      (setq buffer-read-only t)
+      (or (get-buffer-window preview-buffer)
+         (let ((r-win (get-buffer-window raw-buffer)))
+           (if r-win
+               (set-window-buffer r-win preview-buffer)
+             (switch-to-buffer preview-buffer)
+             )))
+      )))
 
 (defun mime-view-buffer (&optional raw-buffer preview-buffer mother
                                   default-keymap-or-function)
   (interactive)
   (mime-display-message
-   (save-excursion
-     (if raw-buffer (set-buffer raw-buffer))
-     (mime-parse-message)
-     )
+   (mime-parse-buffer raw-buffer)
    preview-buffer mother default-keymap-or-function))
 
 (defun mime-view-mode (&optional mother ctl encoding
@@ -1041,7 +1006,7 @@ button-2  Move to point under the mouse cursor
    (save-excursion
      (if raw-buffer (set-buffer raw-buffer))
      (or mime-view-redisplay
-        (mime-parse-message ctl encoding))
+        (setq mime-message-structure (mime-parse-message ctl encoding)))
      )
    preview-buffer mother default-keymap-or-function))
 
@@ -1203,17 +1168,6 @@ It calls following-method selected from variable
        ))))
 
 
-;;; @@ X-Face
-;;;
-
-(defun mime-preview-display-x-face ()
-  (interactive)
-  (save-window-excursion
-    (set-buffer mime-raw-buffer)
-    (mime-view-x-face-function)
-    ))
-
-
 ;;; @@ moving
 ;;;