This commit was generated by cvs2svn to compensate for changes in r5830,
[elisp/gnus.git-] / lisp / gnus-uu.el
index 1f4ed39..19929f3 100644 (file)
@@ -1,5 +1,5 @@
 ;;; gnus-uu.el --- extract (uu)encoded files in Gnus
-;; Copyright (C) 198,995,86,87,93,94,95,96,97,98 Free Software Foundation, Inc.
+;; Copyright (C) 1985,86,87,93,94,95,96,97,98 Free Software Foundation, Inc.
 
 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
 ;; Created: 2 Oct 1993
@@ -32,7 +32,6 @@
 (require 'gnus-art)
 (require 'message)
 (require 'gnus-msg)
-(require 'mm-decode)
 
 (defgroup gnus-extract nil
   "Extracting encoded files."
@@ -58,8 +57,8 @@
   '(("\\.te?xt$\\|\\.doc$\\|read.*me\\|\\.c?$\\|\\.h$\\|\\.bat$\\|\\.asm$\\|makefile" "cat %s | sed 's/\r$//'")
     ("\\.pas$" "cat %s | sed 's/\r$//'")
     ("\\.[1-9]$" "groff -mandoc -Tascii %s | sed s/\b.//g")
-    ("\\.\\(jpe?g\\|gif\\|tiff?\\|p[pgb]m\\|xwd\\|xbm\\|pcx\\)$" "display")
-    ("\\.tga$" "tgatoppm %s | ee -")
+    ("\\.\\(jpe?g\\|gif\\|tiff?\\|p[pgb]m\\|xwd\\|xbm\\|pcx\\)$" "xv")
+    ("\\.tga$" "tgatoppm %s | xv -")
     ("\\.\\(wav\\|aiff\\|hcom\\|u[blw]\\|s[bfw]\\|voc\\|smp\\)$"
      "sox -v .5 %s -t .au -u - > /dev/audio")
     ("\\.au$" "cat %s > /dev/audio")
@@ -216,10 +215,7 @@ Note that this variable can be used in conjunction with the
 
 ;; Various variables users may set
 
-(defcustom gnus-uu-tmp-dir
-  (cond ((fboundp 'temp-directory) (temp-directory))
-       ((boundp 'temporary-file-directory) temporary-file-directory)
-       ("/tmp/"))
+(defcustom gnus-uu-tmp-dir "/tmp/"
   "*Variable saying where gnus-uu is to do its work.
 Default is \"/tmp/\"."
   :group 'gnus-extract
@@ -332,8 +328,7 @@ didn't work, and overwrite existing files.  Otherwise, ask each time."
 (defvar gnus-uu-shar-begin-string "^#! */bin/sh")
 
 (defvar gnus-uu-shar-file-name nil)
-(defvar gnus-uu-shar-name-marker
-  "begin [0-7][0-7][0-7][ \t]+\\(\\(\\w\\|\\.\\)*\\b\\)")
+(defvar gnus-uu-shar-name-marker "begin [0-7][0-7][0-7][ \t]+\\(\\(\\w\\|\\.\\)*\\b\\)")
 
 (defvar gnus-uu-postscript-begin-string "^%!PS-")
 (defvar gnus-uu-postscript-end-string "^%%EOF$")
@@ -373,7 +368,7 @@ didn't work, and overwrite existing files.  Otherwise, ask each time."
 
 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
   ;;"x" gnus-uu-extract-any
-  "m" gnus-summary-save-parts
+  ;;"m" gnus-uu-extract-mime
   "u" gnus-uu-decode-uu
   "U" gnus-uu-decode-uu-and-save
   "s" gnus-uu-decode-unshar
@@ -386,17 +381,17 @@ didn't work, and overwrite existing files.  Otherwise, ask each time."
   "P" gnus-uu-decode-postscript-and-save)
 
 (gnus-define-keys
-    (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
-  "u" gnus-uu-decode-uu-view
-  "U" gnus-uu-decode-uu-and-save-view
-  "s" gnus-uu-decode-unshar-view
-  "S" gnus-uu-decode-unshar-and-save-view
-  "o" gnus-uu-decode-save-view
-  "O" gnus-uu-decode-save-view
-  "b" gnus-uu-decode-binhex-view
-  "B" gnus-uu-decode-binhex-view
-  "p" gnus-uu-decode-postscript-view
-  "P" gnus-uu-decode-postscript-and-save-view)
+ (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
+ "u" gnus-uu-decode-uu-view
+ "U" gnus-uu-decode-uu-and-save-view
+ "s" gnus-uu-decode-unshar-view
+ "S" gnus-uu-decode-unshar-and-save-view
+ "o" gnus-uu-decode-save-view
+ "O" gnus-uu-decode-save-view
+ "b" gnus-uu-decode-binhex-view
+ "B" gnus-uu-decode-binhex-view
+ "p" gnus-uu-decode-postscript-view
+ "P" gnus-uu-decode-postscript-and-save-view)
 
 
 ;; Commands.
@@ -526,7 +521,6 @@ didn't work, and overwrite existing files.  Otherwise, ask each time."
                 (gnus-get-buffer-create " *gnus-uu-forward*")))
       (erase-buffer)
       (insert-file file)
-      (delete-file file)
       (let ((fs gnus-uu-digest-from-subject))
        (when fs
          (setq from (caar fs)
@@ -557,6 +551,8 @@ didn't work, and overwrite existing files.  Otherwise, ask each time."
        (delete-region (point) (gnus-point-at-eol))
        (insert from))
       (message-forward post))
+    (delete-file file)
+    (kill-buffer buf)
     (setq gnus-uu-digest-from-subject nil)))
 
 (defun gnus-uu-digest-post-forward (&optional n)
@@ -567,10 +563,8 @@ didn't work, and overwrite existing files.  Otherwise, ask each time."
 ;; Process marking.
 
 (defun gnus-uu-mark-by-regexp (regexp &optional unmark)
-  "Set the process mark on articles whose subjects match REGEXP.
-When called interactively, prompt for REGEXP.
-Optional UNMARK non-nil means unmark instead of mark."
-  (interactive "sMark (regexp): \nP")
+  "Ask for a regular expression and set the process mark on all articles that match."
+  (interactive (list (read-from-minibuffer "Mark (regexp): ")))
   (let ((articles (gnus-uu-find-articles-matching regexp)))
     (while articles
       (if unmark
@@ -579,10 +573,9 @@ Optional UNMARK non-nil means unmark instead of mark."
     (message ""))
   (gnus-summary-position-point))
 
-(defun gnus-uu-unmark-by-regexp (regexp)
-  "Remove the process mark from articles whose subjects match REGEXP.
-When called interactively, prompt for REGEXP."
-  (interactive "sUnmark (regexp): ")
+(defun gnus-uu-unmark-by-regexp (regexp &optional unmark)
+  "Ask for a regular expression and remove the process mark on all articles that match."
+  (interactive (list (read-from-minibuffer "Mark (regexp): ")))
   (gnus-uu-mark-by-regexp regexp t))
 
 (defun gnus-uu-mark-series ()
@@ -625,12 +618,10 @@ When called interactively, prompt for REGEXP."
 (defun gnus-uu-mark-thread ()
   "Marks all articles downwards in this thread."
   (interactive)
-  (gnus-save-hidden-threads
-    (let ((level (gnus-summary-thread-level)))
-      (while (and (gnus-summary-set-process-mark
-                  (gnus-summary-article-number))
-                 (zerop (gnus-summary-next-subject 1 nil t))
-                 (> (gnus-summary-thread-level) level)))))
+  (let ((level (gnus-summary-thread-level)))
+    (while (and (gnus-summary-set-process-mark (gnus-summary-article-number))
+               (zerop (gnus-summary-next-subject 1))
+               (> (gnus-summary-thread-level) level))))
   (gnus-summary-position-point))
 
 (defun gnus-uu-unmark-thread ()
@@ -659,7 +650,7 @@ When called interactively, prompt for REGEXP."
 (defun gnus-uu-mark-over (&optional score)
   "Mark all articles with a score over SCORE (the prefix)."
   (interactive "P")
-  (let ((score (or score gnus-summary-default-score 0))
+  (let ((score (gnus-score-default score))
        (data gnus-newsgroup-data))
     (save-excursion
       (while data
@@ -842,9 +833,8 @@ When called interactively, prompt for REGEXP."
              (eq in-state 'first-and-last))
          (progn
            (setq state (list 'begin))
-           (save-excursion
-             (set-buffer (gnus-get-buffer-create "*gnus-uu-body*"))
-             (erase-buffer))
+           (save-excursion (set-buffer (gnus-get-buffer-create "*gnus-uu-body*"))
+                           (erase-buffer))
            (save-excursion
              (set-buffer (gnus-get-buffer-create "*gnus-uu-pre*"))
              (erase-buffer)
@@ -959,7 +949,7 @@ When called interactively, prompt for REGEXP."
        (beginning-of-line)
        (forward-line 1)
        (when (file-exists-p gnus-uu-binhex-article-name)
-         (mm-append-to-file start-char (point) gnus-uu-binhex-article-name))))
+         (append-to-file start-char (point) gnus-uu-binhex-article-name))))
     (if (memq 'begin state)
        (cons gnus-uu-binhex-article-name state)
       state)))
@@ -1034,7 +1024,7 @@ When called interactively, prompt for REGEXP."
   ;; finally just replaces the next to last number with "[0-9]+".
   (save-excursion
     (set-buffer (gnus-get-buffer-create gnus-uu-output-buffer-name))
-    (buffer-disable-undo)
+    (buffer-disable-undo (current-buffer))
     (erase-buffer)
     (insert (regexp-quote string))
 
@@ -1134,7 +1124,7 @@ When called interactively, prompt for REGEXP."
        string)
     (save-excursion
       (set-buffer (gnus-get-buffer-create gnus-uu-output-buffer-name))
-      (buffer-disable-undo)
+      (buffer-disable-undo (current-buffer))
       (while string-list
        (erase-buffer)
        (insert (caar string-list))
@@ -1209,10 +1199,9 @@ When called interactively, prompt for REGEXP."
                                       &optional sloppy limit no-errors)
   (let ((state 'first)
        (gnus-asynchronous nil)
-       (gnus-inhibit-treatment t)
        has-been-begin article result-file result-files process-state
        gnus-summary-display-article-function
-       gnus-article-prepare-hook gnus-display-mime-function
+       gnus-article-display-hook gnus-article-prepare-hook
        article-series files)
 
     (while (and articles
@@ -1403,7 +1392,7 @@ When called interactively, prompt for REGEXP."
          ;; We replace certain characters that could make things messy.
          (setq gnus-uu-file-name
                (let ((nnheader-file-name-translation-alist
-                      '((?/ . ?,) (?  . ?_) (?* . ?_) (?$ . ?_))))
+                      '((?/ . ?,) (? . ?_) (?* . ?_) (?$ . ?_))))
                  (nnheader-translate-file-chars (match-string 1))))
           (replace-match (concat "begin 644 " gnus-uu-file-name) t t)
 
@@ -1705,11 +1694,23 @@ When called interactively, prompt for REGEXP."
     (when (setq buf (get-buffer gnus-uu-output-buffer-name))
       (kill-buffer buf))))
 
+(defun gnus-quote-arg-for-sh-or-csh (arg)
+  (let ((pos 0) new-pos accum)
+    ;; *** bug: we don't handle newline characters properly
+    (while (setq new-pos (string-match "[!`\"$\\& \t{}]" arg pos))
+      (push (substring arg pos new-pos) accum)
+      (push "\\" accum)
+      (push (list (aref arg new-pos)) accum)
+      (setq pos (1+ new-pos)))
+    (if (= pos 0)
+        arg
+      (apply 'concat (nconc (nreverse accum) (list (substring arg pos)))))))
+
 ;; Inputs an action and a filename and returns a full command, making sure
 ;; that the filename will be treated as a single argument when the shell
 ;; executes the command.
 (defun gnus-uu-command (action file)
-  (let ((quoted-file (mm-quote-arg file)))
+  (let ((quoted-file (gnus-quote-arg-for-sh-or-csh file)))
     (if (string-match "%s" action)
        (format action quoted-file)
       (concat action " " quoted-file))))
@@ -1805,9 +1806,7 @@ is t."
 
   (gnus-summary-post-news)
 
-  (let ((map (make-sparse-keymap)))
-    (set-keymap-parent map (current-local-map))
-    (use-local-map map))
+  (use-local-map (copy-keymap (current-local-map)))
   (local-set-key "\C-c\C-c" 'gnus-summary-edit-article-done)
   (local-set-key "\C-c\C-c" 'gnus-uu-post-news-inews)
   (local-set-key "\C-c\C-s" 'gnus-uu-post-news-inews)