Importing pgnus-0.55
[elisp/gnus.git-] / lisp / mailcap.el
index 44ae372..9a8307e 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))
       (viewer . "maplay %s")
       (type   . "audio/x-mpeg"))
      (".*"
-      (viewer . mm-view-sound-file)
+      (viewer . mailcap-save-binary-file)
       (test   . (or (featurep 'nas-sound)
                      (featurep 'native-sound)))
       (type   . "audio/*"))
       (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,11 +271,13 @@ not.")
       (expand-file-name fname mailcap-temporary-directory))))
 
 (defun mailcap-save-binary-file ()
-  (let ((file (read-file-name
-              "Filename to save as: "
-              (or mailcap-download-directory "~/")))
-       (require-final-newline nil))
-    (write-region (point-min) (point-max) file)
+  (goto-char (point-min))
+  (unwind-protect
+      (let ((file (read-file-name
+                  "Filename to save as: "
+                  (or mailcap-download-directory "~/")))
+           (require-final-newline nil))
+       (write-region (point-min) (point-max) file))
     (kill-buffer (current-buffer))))
 
 (defun mailcap-maybe-eval ()
@@ -294,7 +301,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
@@ -316,7 +323,8 @@ If FORCE, re-parse even if already parsed."
          fname)
       (while fnames
        (setq fname (car fnames))
-       (if (and (file-exists-p fname) (file-readable-p fname))
+       (if (and (file-exists-p fname) (file-readable-p fname)
+                (file-regular-p fname))
            (mailcap-parse-mailcap (car fnames)))
        (setq fnames (cdr fnames))))
     (setq mailcap-parsed-p t)))
@@ -353,7 +361,7 @@ If FORCE, re-parse even if already parsed."
        (downcase-region save-pos (point))
        (setq minor
              (cond
-              ((= ?* (or (char-after save-pos) 0)) ".*")
+              ((eq ?* (or (char-after save-pos) 0)) ".*")
               ((= (point) save-pos) ".*")
               (t (buffer-substring save-pos (point)))))
        (skip-chars-forward "; \t\n")
@@ -363,7 +371,7 @@ If FORCE, re-parse even if already parsed."
        (skip-chars-forward "; \t\n")
        (setq save-pos (point))
        (skip-chars-forward "^;\n")
-       (if (= (or (char-after save-pos) 0) ?')
+       (if (eq (or (char-after save-pos) 0) ?')
            (setq viewer (progn
                           (narrow-to-region (1+ save-pos) (point))
                           (goto-char (point-min))
@@ -404,7 +412,7 @@ If FORCE, re-parse even if already parsed."
        (downcase-region name-pos (point))
        (setq name (buffer-substring name-pos (point)))
        (skip-chars-forward " \t\n")
-       (if (/= (or (char-after (point)) 0)  ?=) ; There is no value
+       (if (not (eq (char-after (point)) ?=)) ; There is no value
            (setq value nil)
          (skip-chars-forward " \t\n=")
          (setq val-pos (point))
@@ -418,14 +426,14 @@ If FORCE, re-parse even if already parsed."
                  (error (goto-char (point-max)))))
            (while (not done)
              (skip-chars-forward "^;")
-             (if (= (or (char-after (1- (point))) 0) ?\\ )
+             (if (eq (char-after (1- (point))) ?\\ )
                  (progn
                    (subst-char-in-region (1- (point)) (point) ?\\ ? )
                    (skip-chars-forward ";"))
                (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
@@ -434,7 +442,9 @@ If FORCE, re-parse even if already parsed."
        (test (assq 'test info))        ; The test clause
        )
     (setq status (and test (split-string (cdr test) " ")))
-    (if (and (assoc "needsx11" info) (not (getenv "DISPLAY")))
+    (if (and (or (assoc "needsterm" info)
+                (assoc "needsx11" info))
+            (not (getenv "DISPLAY")))
        (setq status nil)
       (cond
        ((and (equal (nth 0 status) "test")
@@ -463,7 +473,7 @@ If FORCE, re-parse even if already parsed."
       (cond
        ((equal (car (car major)) minor)
        (setq exact (cons (cdr (car major)) exact)))
-       ((string-match (car (car major)) minor)
+       ((and minor (string-match (car (car major)) minor))
        (setq wildcard (cons (cdr (car major)) wildcard))))
       (setq major (cdr major)))
     (nconc (nreverse exact) (nreverse wildcard))))
@@ -591,7 +601,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
@@ -815,6 +825,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