Importing qgnus-0.19
[elisp/gnus.git-] / lisp / gnus-agent.el
index cb893b5..a76b502 100644 (file)
@@ -61,6 +61,7 @@
 (defvar gnus-agent-spam-hashtb nil)
 (defvar gnus-agent-file-name nil)
 (defvar gnus-agent-send-mail-function nil)
+(defvar gnus-agent-article-file-coding-system 'no-conversion)
 
 ;; Dynamic variables
 (defvar gnus-headers)
 
 (defvar gnus-agent-group-mode-map (make-sparse-keymap))
 (gnus-define-keys gnus-agent-group-mode-map
-  "Ju" gnus-agent-fetch-group
+  "Ju" gnus-agent-fetch-groups
   "Jc" gnus-enter-category-buffer
   "Jj" gnus-agent-toggle-plugged
   "Js" gnus-agent-fetch-session
@@ -296,6 +297,11 @@ agent minor mode in all Gnus buffers."
 ;;; Group mode commands
 ;;;
 
+(defun gnus-agent-fetch-groups (n)
+  "Put all new articles in the current groups into the agent."
+  (interactive "P")
+  (gnus-group-iterate n 'gnus-agent-fetch-group))
+
 (defun gnus-agent-fetch-group (group)
   "Put all new articles in GROUP into the agent."
   (interactive (list (gnus-group-group-name)))
@@ -303,7 +309,8 @@ agent minor mode in all Gnus buffers."
     (error "No group on the current line"))
   (let ((gnus-command-method (gnus-find-method-for-group group)))
     (gnus-agent-with-fetch
-      (gnus-agent-fetch-group-1 group gnus-command-method))))
+      (gnus-agent-fetch-group-1 group gnus-command-method)
+      (gnus-message 5 "Fetching %s...done" group))))
 
 (defun gnus-agent-add-group (category arg)
   "Add the current group to an agent category."
@@ -376,7 +383,6 @@ If N is negative, mark backward instead.  If UNMARK is non-nil, remove
 the mark instead.  The difference between N and the actual number of
 articles marked is returned."
   (interactive "p")
-  (gnus-set-global-variables)
   (let ((backward (< n 0))
        (n (abs n)))
     (while (and
@@ -397,7 +403,6 @@ articles marked is returned."
 If N is negative, unmark backward instead.  The difference between N and
 the actual number of articles unmarked is returned."
   (interactive "p")
-  (gnus-set-global-variables)
   (gnus-agent-mark-article n t))
 
 (defun gnus-agent-toggle-mark (n)
@@ -405,7 +410,6 @@ the actual number of articles unmarked is returned."
 If N is negative, toggle backward instead.  The difference between N and
 the actual number of articles toggled is returned."
   (interactive "p")
-  (gnus-set-global-variables)
   (gnus-agent-mark-article n 'toggle))
 
 (defun gnus-summary-set-agent-mark (article &optional unmark)
@@ -413,9 +417,13 @@ the actual number of articles toggled is returned."
   (let ((unmark (if (and (not (null unmark)) (not (eq t unmark)))
                    (memq article gnus-newsgroup-downloadable)
                  unmark)))
-    (setq gnus-newsgroup-downloadable
-         (delq article gnus-newsgroup-downloadable))
-    (unless unmark
+    (if unmark
+       (progn
+         (setq gnus-newsgroup-downloadable
+               (delq article gnus-newsgroup-downloadable))
+         (push article gnus-newsgroup-undownloaded))
+      (setq gnus-newsgroup-undownloaded
+           (delq article gnus-newsgroup-undownloaded))
       (push article gnus-newsgroup-downloadable))
     (gnus-summary-update-mark
      (if unmark gnus-undownloaded-mark gnus-downloadable-mark)
@@ -452,7 +460,8 @@ the actual number of articles toggled is returned."
     (let* ((gnus-command-method method)
           (file (gnus-agent-lib-file "active")))
       (gnus-make-directory (file-name-directory file))
-      (write-region (point-min) (point-max) file nil 'silent)
+      (let ((coding-system-for-write gnus-agent-article-file-coding-system))
+       (write-region (point-min) (point-max) file nil 'silent))
       (when (file-exists-p (gnus-agent-lib-file "groups"))
        (delete-file (gnus-agent-lib-file "groups"))))))
 
@@ -466,7 +475,8 @@ the actual number of articles toggled is returned."
 
 (defun gnus-agent-group-path (group)
   "Translate GROUP into a path."
-  (nnheader-replace-chars-in-string group ?. ?/))
+  (nnheader-translate-file-chars
+   (nnheader-replace-chars-in-string group ?. ?/)))
 
 \f
 
@@ -604,9 +614,10 @@ the actual number of articles toggled is returned."
            (if (not (re-search-forward "^Message-ID: *<\\([^>\n]+\\)>" nil t))
                (setq id "No-Message-ID-in-article")
              (setq id (buffer-substring (match-beginning 1) (match-end 1))))
-           (write-region (point-min) (point-max)
-                         (concat dir (number-to-string (caar pos)))
-                         nil 'silent)
+           (let ((coding-system-for-write gnus-agent-article-file-coding-system))
+             (write-region (point-min) (point-max)
+                           (concat dir (number-to-string (caar pos)))
+                           nil 'silent))
            (when (setq elem (assq (caar pos) gnus-agent-article-alist))
              (setcdr elem t))
            (gnus-agent-enter-history
@@ -682,7 +693,8 @@ the actual number of articles toggled is returned."
          (when (file-exists-p
                 (setq file (gnus-agent-article-name ".overview" group)))
            (gnus-agent-braid-nov group articles file))
-         (gnus-make-directory (file-name-directory file))
+         (gnus-make-directory (nnheader-translate-file-chars
+                               (file-name-directory file)))
          (write-region (point-min) (point-max) file nil 'silent)
          (gnus-agent-save-alist group articles nil))
        t))))
@@ -759,6 +771,14 @@ the actual number of articles toggled is returned."
   (concat (gnus-agent-directory) (gnus-agent-group-path group) "/"
          (if (stringp article) article (string-to-number article))))
 
+;;;###autoload
+(defun gnus-agent-batch-fetch ()
+  "Start Gnus and fetch session."
+  (interactive)
+  (gnus)
+  (gnus-agent-fetch-session)
+  (gnus-group-exit))
+
 (defun gnus-agent-fetch-session ()
   "Fetch all articles and headers that are eligible for fetching."
   (interactive)