Importing pgnus-0.32
[elisp/gnus.git-] / lisp / mailcap.el
index 44ae372..c5249f3 100644 (file)
       (viewer . "open %s")
       (type   . "application/postscript")
       (test   . (eq (mm-device-type) 'ns)))
-     ("postscript" 
+     ("postscript"
       (viewer . "ghostview %s")
       (type . "application/postscript")
       (test   . (eq (mm-device-type) 'x))
       (type   . "audio/*")))
     ("message"
      ("rfc-*822"
+      (viewer . gnus-article-prepare-display)
+      (test   . (and (featurep 'gnus)
+                    (gnus-alive-p)))
+      (type   . "message/rfc-822"))
+     ("rfc-*822"
       (viewer . vm-mode)
       (test   . (fboundp 'vm-mode))
       (type   . "message/rfc-822"))
       (viewer . view-mode)
       (test   . (fboundp 'view-mode))
       (type   . "message/rfc-822"))
-     ("rfc-*822" 
+     ("rfc-*822"
       (viewer . fundamental-mode)
       (type   . "message/rfc-822")))
     ("image"
       (type    . "text/plain"))
      ("enriched"
       (viewer . enriched-decode-region)
-      (test   . (fboundp 'enriched-decode-region))
+      (test   . (fboundp 'enriched-decode))
       (type   . "text/enriched"))
      ("html"
       (viewer . mm-w3-prepare-buffer)
@@ -266,6 +271,7 @@ not.")
       (expand-file-name fname mailcap-temporary-directory))))
 
 (defun mailcap-save-binary-file ()
+  (goto-char (point-min))
   (let ((file (read-file-name
               "Filename to save as: "
               (or mailcap-download-directory "~/")))
@@ -294,7 +300,7 @@ not.")
 (defun mailcap-parse-mailcaps (&optional path force)
   "Parse out all the mailcaps specified in a unix-style path string PATH.
 If FORCE, re-parse even if already parsed."
-  (interactive)
+  (interactive (list nil t))
   (when (or (not mailcap-parsed-p)
            force)
     (cond
@@ -425,7 +431,7 @@ If FORCE, re-parse even if already parsed."
                (setq done t))))
          (setq value (buffer-substring val-pos (point))))
        (setq results (cons (cons name value) results)))
-      results)))  
+      results)))
 
 (defun mailcap-mailcap-entry-passes-test (info)
   ;; Return t iff a mailcap entry passes its test clause or no test
@@ -591,7 +597,7 @@ If FORCE, re-parse even if already parsed."
 
 (defun mailcap-mime-info (string &optional request)
   "Get the MIME viewer command for STRING, return nil if none found.
-Expects a complete content-type header line as its argument. 
+Expects a complete content-type header line as its argument.
 
 Second argument REQUEST specifies what information to return.  If it is
 nil or the empty string, the viewer (second field of the mailcap
@@ -626,7 +632,7 @@ this type is returned."
            (if (mailcap-viewer-passes-test (car viewers) info)
                (setq passed (cons (car viewers) passed)))
            (setq viewers (cdr viewers)))
-         (setq passed (sort (nreverse passed) 'mailcap-viewer-lessp))
+         (setq passed (sort passed 'mailcap-viewer-lessp))
          (setq viewer (car passed))))
       (when (and (stringp (cdr (assq 'viewer viewer)))
                 passed)
@@ -815,6 +821,27 @@ correspond to.")
       (setq extn (concat "." extn)))
   (cdr (assoc (downcase extn) mailcap-mime-extensions)))
 
+(defvar mailcap-binary-suffixes
+  (if (memq system-type '(ms-dos windows-nt))
+      '(".exe" ".com" ".bat" ".cmd" ".btm" "")
+    '("")))
+
+(defun mailcap-command-p (command)
+  "Say whether COMMAND is in the exec path.
+The path of COMMAND will be returned iff COMMAND is a command."
+  (let ((path (if (file-name-absolute-p command) '(nil) exec-path))
+       file dir)
+    (catch 'found
+      (while (setq dir (pop path))
+       (let ((suffixes mailcap-binary-suffixes))
+         (while suffixes
+           (when (and (file-executable-p
+                       (setq file (expand-file-name
+                                   (concat command (pop suffixes))
+                                   dir)))
+                      (not (file-directory-p file)))
+             (throw 'found file))))))))
+
 (provide 'mailcap)
 
 ;;; mailcap.el ends here