Synch with Oort Gnus.
[elisp/gnus.git-] / lisp / gnus-agent.el
index fd5f269..c8b7792 100644 (file)
@@ -1,5 +1,6 @@
 ;;; gnus-agent.el --- unplugged support for Semi-gnus
-;; Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
+;; Copyright (C) 1997, 1998, 1999, 2000, 2001
+;;        Free Software Foundation, Inc.
 
 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
 ;;     Tatsuya Ichikawa <t-ichi@po.shiojiri.ne.jp>
@@ -38,6 +39,9 @@
     (require 'timer))
   (require 'gnus-group))
 
+(eval-and-compile
+  (autoload 'gnus-server-update-server "gnus-srvr"))
+
 (defcustom gnus-agent-directory (nnheader-concat gnus-directory "agent/")
   "Where the Gnus agent will store its files."
   :group 'gnus-agent
@@ -74,16 +78,28 @@ If nil, only read articles will be expired."
   :group 'gnus-agent
   :type 'hook)
 
+;; Extracted from gnus-xmas-redefine in order to preserve user settings
+(when (featurep 'xemacs)
+  (add-hook 'gnus-agent-group-mode-hook 'gnus-xmas-agent-group-menu-add))
+
 (defcustom gnus-agent-summary-mode-hook nil
   "Hook run in Agent summary minor modes."
   :group 'gnus-agent
   :type 'hook)
 
+;; Extracted from gnus-xmas-redefine in order to preserve user settings
+(when (featurep 'xemacs)
+  (add-hook 'gnus-agent-summary-mode-hook 'gnus-xmas-agent-summary-menu-add))
+
 (defcustom gnus-agent-server-mode-hook nil
   "Hook run in Agent summary minor modes."
   :group 'gnus-agent
   :type 'hook)
 
+;; Extracted from gnus-xmas-redefine in order to preserve user settings
+(when (featurep 'xemacs)
+  (add-hook 'gnus-agent-server-mode-hook 'gnus-xmas-agent-server-menu-add))
+
 (defcustom gnus-agent-confirmation-function 'y-or-n-p
   "Function to confirm when error happens."
   :version "21.1"
@@ -349,15 +365,17 @@ last form in your `.gnus.el' file:
 
 \(gnus-agentize)
 
-This will modify the `gnus-before-startup-hook', `gnus-post-method',
-and `message-send-mail-function' variables, and install the Gnus
-agent minor mode in all Gnus buffers."
+This will modify the `gnus-setup-news-hook', and
+`message-send-mail-real-function' variables, and install the Gnus agent
+minor mode in all Gnus buffers."
   (interactive)
   (gnus-open-agent)
   (add-hook 'gnus-setup-news-hook 'gnus-agent-queue-setup)
   (unless gnus-agent-send-mail-function
-    (setq gnus-agent-send-mail-function message-send-mail-function
-         message-send-mail-function 'gnus-agent-send-mail))
+    (setq gnus-agent-send-mail-function (or 
+                                         message-send-mail-real-function
+                                         message-send-mail-function)
+         message-send-mail-real-function 'gnus-agent-send-mail))
   (unless gnus-agent-covered-methods
     (setq gnus-agent-covered-methods (list gnus-select-method))))
 
@@ -542,6 +560,7 @@ be a select method."
     (when (member method gnus-agent-covered-methods)
       (error "Server already in the agent program"))
     (push method gnus-agent-covered-methods)
+    (gnus-server-update-server server)
     (gnus-agent-write-servers)
     (message "Entered %s into the Agent" server)))
 
@@ -555,6 +574,7 @@ be a select method."
       (error "Server not in the agent program"))
     (setq gnus-agent-covered-methods
          (delete method gnus-agent-covered-methods))
+    (gnus-server-update-server server)
     (gnus-agent-write-servers)
     (message "Removed %s from the agent" server)))
 
@@ -637,23 +657,18 @@ the actual number of articles toggled is returned."
               (gnus-agent-method-p gnus-command-method))
       (gnus-agent-load-alist gnus-newsgroup-name)
       ;; First mark all undownloaded articles as undownloaded.
-      (let ((articles (append gnus-newsgroup-unreads
-                             gnus-newsgroup-marked
-                             gnus-newsgroup-dormant))
-           article)
-       (while (setq article (pop articles))
-         (unless (or (cdr (assq article gnus-agent-article-alist))
-                     (memq article gnus-newsgroup-downloadable)
-                     (memq article gnus-newsgroup-cached))
-           (push article gnus-newsgroup-undownloaded))))
+      (dolist (article (mapcar (lambda (header) (mail-header-number header))
+                              gnus-newsgroup-headers))
+       (unless (or (cdr (assq article gnus-agent-article-alist))
+                   (memq article gnus-newsgroup-downloadable)
+                   (memq article gnus-newsgroup-cached))
+         (push article gnus-newsgroup-undownloaded)))
       ;; Then mark downloaded downloadable as not-downloadable,
       ;; if you get my drift.
-      (let ((articles gnus-newsgroup-downloadable)
-           article)
-       (while (setq article (pop articles))
-         (when (cdr (assq article gnus-agent-article-alist))
-           (setq gnus-newsgroup-downloadable
-                 (delq article gnus-newsgroup-downloadable))))))))
+      (dolist (article gnus-newsgroup-downloadable)
+       (when (cdr (assq article gnus-agent-article-alist))
+         (setq gnus-newsgroup-downloadable
+               (delq article gnus-newsgroup-downloadable)))))))
 
 (defun gnus-agent-catchup ()
   "Mark all undownloaded articles as read."
@@ -1056,7 +1071,8 @@ the actual number of articles toggled is returned."
 (defun gnus-agent-save-alist (group &optional articles state dir)
   "Save the article-state alist for GROUP."
   (let ((file-name-coding-system nnmail-pathname-coding-system)
-       (pathname-coding-system nnmail-pathname-coding-system))
+       (pathname-coding-system nnmail-pathname-coding-system)
+       print-level print-length)
     (with-temp-file (if dir
                        (expand-file-name ".agentview" dir)
                      (gnus-agent-article-name ".agentview" group))
@@ -1107,9 +1123,10 @@ the actual number of articles toggled is returned."
           (unless (funcall gnus-agent-confirmation-function
                            (format "Error (%s).  Continue? " err))
             (error "Cannot fetch articles into the Gnus agent.")))
-         (quit 
+         (quit
           (unless (funcall gnus-agent-confirmation-function
-                           (format "Quit (%s).  Continue? " err))
+                           (format "Quit fetching session (%s).  Continue? "
+                                   err))
             (signal 'quit "Cannot fetch articles into the Gnus agent."))))
        (pop methods))
       (gnus-message 6 "Finished fetching articles into the Gnus agent"))))
@@ -1551,8 +1568,8 @@ The following commands are available:
                      (if (numberp fetch-date)
                          (>  fetch-date day)
                        ;; History file is corrupted.
-                       (gnus-message 
-                        5 
+                       (gnus-message
+                        5
                         (format "File %s is corrupted!"
                                 (gnus-agent-lib-file "history")))
                        (sit-for 1)