(message-exchange-point-and-mark): Use message-mark-active-p.
[gnus] / lisp / gnus-agent.el
index a565146..c5e8817 100644 (file)
@@ -229,7 +229,6 @@ NOTES:
 (defvar gnus-agent-send-mail-function nil)
 (defvar gnus-agent-file-coding-system 'raw-text)
 (defvar gnus-agent-file-loading-cache nil)
-(defvar gnus-agent-file-header-cache nil)
 
 ;; Dynamic variables
 (defvar gnus-headers)
@@ -1135,8 +1134,8 @@ downloaded into the agent."
                                   (gnus-find-method-for-group group))))
     (when (gnus-agent-method-p gnus-command-method)
       (let* ((local (gnus-agent-get-local group))
-             (active-min (car active))
-             (active-max (cdr active))
+             (active-min (or (car active) 0))
+             (active-max (or (cdr active) 0))
              (agent-min (or (car local) active-min))
              (agent-max (or (cdr local) active-max)))
 
@@ -1732,49 +1731,53 @@ FILE and places the combined headers into `nntp-server-buffer'."
 (defun gnus-agent-read-agentview (file)
   "Load FILE and do a `read' there."
   (with-temp-buffer
-    (ignore-errors
-      (nnheader-insert-file-contents file)
-      (goto-char (point-min))
-      (let ((alist (read (current-buffer)))
-            (version (condition-case nil (read (current-buffer))
-                       (end-of-file 0)))
-            changed-version)
-
-        (cond
-        ((= version 0)
-         (let ((inhibit-quit t)
-               entry)
-           (gnus-agent-open-history)
-           (set-buffer (gnus-agent-history-buffer))
-           (goto-char (point-min))
-           (while (not (eobp))
-             (if (and (looking-at
-                       "[^\t\n]+\t\\([0-9]+\\)\t\\([^ \n]+\\) \\([0-9]+\\)")
-                      (string= (match-string 2)
-                               gnus-agent-read-agentview)
-                      (setq entry (assoc (string-to-number (match-string 3)) alist)))
-                 (setcdr entry (string-to-number (match-string 1))))
-             (forward-line 1))
-           (gnus-agent-close-history)
-           (setq changed-version t)))
-        ((= version 1)
-         (setq changed-version (not (= 1 gnus-agent-article-alist-save-format))))
-        ((= version 2)
-         (let (uncomp)
-           (mapcar
-            (lambda (comp-list)
-              (let ((state (car comp-list))
-                    (sequence (gnus-uncompress-sequence
-                               (cdr comp-list))))
-                (mapcar (lambda (article-id)
-                          (setq uncomp (cons (cons article-id state) uncomp)))
-                        sequence)))
-            alist)
-           (setq alist (sort uncomp 'car-less-than-car)))))
-        (when changed-version
-          (let ((gnus-agent-article-alist alist))
-            (gnus-agent-save-alist gnus-agent-read-agentview)))
-        alist))))
+    (condition-case nil
+      (progn
+        (nnheader-insert-file-contents file)
+        (goto-char (point-min))
+        (let ((alist (read (current-buffer)))
+              (version (condition-case nil (read (current-buffer))
+                         (end-of-file 0)))
+              changed-version)
+
+          (cond
+           ((< version 2)
+            (error "gnus-agent-read-agentview no longer supports version %d.  Stop gnus, manually evaluate gnus-agent-convert-to-compressed-agentview, then restart gnus." version))
+           ((= version 0)
+            (let ((inhibit-quit t)
+                  entry)
+              (gnus-agent-open-history)
+              (set-buffer (gnus-agent-history-buffer))
+              (goto-char (point-min))
+              (while (not (eobp))
+                (if (and (looking-at
+                          "[^\t\n]+\t\\([0-9]+\\)\t\\([^ \n]+\\) \\([0-9]+\\)")
+                         (string= (match-string 2)
+                                  gnus-agent-read-agentview)
+                         (setq entry (assoc (string-to-number (match-string 3)) alist)))
+                    (setcdr entry (string-to-number (match-string 1))))
+                (forward-line 1))
+              (gnus-agent-close-history)
+              (setq changed-version t)))
+           ((= version 1)
+            (setq changed-version (not (= 1 gnus-agent-article-alist-save-format))))
+           ((= version 2)
+            (let (uncomp)
+              (mapcar
+               (lambda (comp-list)
+                 (let ((state (car comp-list))
+                       (sequence (gnus-uncompress-sequence
+                                  (cdr comp-list))))
+                   (mapcar (lambda (article-id)
+                             (setq uncomp (cons (cons article-id state) uncomp)))
+                           sequence)))
+               alist)
+              (setq alist (sort uncomp 'car-less-than-car)))))
+          (when changed-version
+            (let ((gnus-agent-article-alist alist))
+              (gnus-agent-save-alist gnus-agent-read-agentview)))
+          alist))
+      (file-error nil))))
 
 (defun gnus-agent-save-alist (group &optional articles state)
   "Save the article-state alist for GROUP."
@@ -1857,7 +1860,8 @@ modified) original contents, they are first saved to their own file."
         (line 1))
     (with-temp-buffer
       (condition-case nil
-          (nnheader-insert-file-contents file)
+         (let ((nnheader-file-coding-system gnus-agent-file-coding-system))
+           (nnheader-insert-file-contents file))
         (file-error))
 
       (goto-char (point-min))
@@ -1900,27 +1904,27 @@ modified) original contents, they are first saved to their own file."
              ;; NOTE: gnus-command-method is used within gnus-agent-lib-file.
              (dest (gnus-agent-lib-file "local")))
         (gnus-make-directory (gnus-agent-lib-file ""))
-        (with-temp-file dest
-          (let ((gnus-command-method (symbol-value (intern "+method" my-obarray)))
-                (file-name-coding-system nnmail-pathname-coding-system)
-                (coding-system-for-write
-                 gnus-agent-file-coding-system)
-                print-level print-length item article
-                (standard-output (current-buffer)))
-            (mapatoms (lambda (symbol)
-                        (cond ((not (boundp symbol))
-                               nil)
-                              ((member (symbol-name symbol) '("+dirty" "+method"))
-                               nil)
-                              (t
-                               (prin1 symbol)
-                               (let ((range (symbol-value symbol)))
-                                 (princ " ")
-                                 (princ (car range))
-                                 (princ " ")
-                                 (princ (cdr range))
-                                 (princ "\n"))))) 
-                      my-obarray)))))))
+
+       (let ((buffer-file-coding-system gnus-agent-file-coding-system))
+         (with-temp-file dest
+           (let ((gnus-command-method (symbol-value (intern "+method" my-obarray)))
+                 (file-name-coding-system nnmail-pathname-coding-system)
+                 print-level print-length item article
+                 (standard-output (current-buffer)))
+             (mapatoms (lambda (symbol)
+                         (cond ((not (boundp symbol))
+                                nil)
+                               ((member (symbol-name symbol) '("+dirty" "+method"))
+                                nil)
+                               (t
+                                (prin1 symbol)
+                                (let ((range (symbol-value symbol)))
+                                  (princ " ")
+                                  (princ (car range))
+                                  (princ " ")
+                                  (princ (cdr range))
+                                  (princ "\n"))))) 
+                       my-obarray))))))))
 
 (defun gnus-agent-get-local (group)
   (let* ((gmane (gnus-group-real-name group))
@@ -1957,7 +1961,7 @@ modified) original contents, they are first saved to their own file."
                t)
               (minmax
                nil)
-              (t
+              ((and min max)
                (set symb (cons min max))
                t))
         (set (intern "+dirty" local) t))))
@@ -3431,6 +3435,9 @@ has been fetched."
 (defun gnus-agent-regenerate-group (group &optional reread)
   "Regenerate GROUP.
 If REREAD is t, all articles in the .overview are marked as unread.
+If REREAD is a list, the specified articles will be marked as unread.
+In addition, their NOV entries in .overview will be refreshed using
+the articles' current headers.
 If REREAD is not nil, downloaded articles are marked as unread."
   (interactive
    (list (let ((def (or (gnus-group-group-name)
@@ -3459,7 +3466,6 @@ If REREAD is not nil, downloaded articles are marked as unread."
                     (gnus-message 3 "Ignoring unexpected input")
                     (sit-for 1)
                     t)))))
-
   (when group
       (gnus-message 5 "Regenerating in %s" group)
       (let* ((gnus-command-method (or gnus-command-method
@@ -3496,7 +3502,12 @@ If REREAD is not nil, downloaded articles are marked as unread."
                        (forward-line 1)
                        (let ((l1 (car nov-arts))
                              (l2 (cadr nov-arts)))
-                         (cond ((not l2)
+                         (cond ((and (listp reread) (memq l1 reread))
+                                (gnus-delete-line)
+                                (setq nov-arts (cdr nov-arts))
+                                (gnus-message 4 "gnus-agent-regenerate-group: NOV\
+entry of article %s deleted." l1))
+                               ((not l2)
                                 nil)
                                ((< l1 l2)
                                 (gnus-message 3 "gnus-agent-regenerate-group: NOV\
@@ -3623,18 +3634,21 @@ If REREAD is not nil, downloaded articles are marked as unread."
               ;; recalculate the number of unread articles in the group
 
               (let ((group (gnus-group-real-name group))
-                    (group-active (gnus-active group)))
+                    (group-active (or (gnus-active group)
+                                     (gnus-activate-group group))))
                 (gnus-agent-possibly-alter-active group group-active)))))
 
         (when (and reread gnus-agent-article-alist)
           (gnus-make-ascending-articles-unread
            group
-           (delq nil (mapcar (function (lambda (c)
-                                         (cond ((eq reread t)
-                                                (car c))
-                                               ((cdr c)
-                                                (car c)))))
-                             gnus-agent-article-alist)))
+           (if (listp reread)
+               reread
+             (delq nil (mapcar (function (lambda (c)
+                                           (cond ((eq reread t)
+                                                  (car c))
+                                                 ((cdr c)
+                                                  (car c)))))
+                               gnus-agent-article-alist))))
 
           (when (gnus-buffer-live-p gnus-group-buffer)
             (gnus-group-update-group group t)
@@ -3686,49 +3700,6 @@ If CLEAN, obsolete (ignore)."
 (defun gnus-agent-group-covered-p (group)
   (gnus-agent-method-p (gnus-group-method group)))
 
-(add-hook 'gnus-group-prepare-hook
-          (lambda ()
-            'gnus-agent-do-once
-
-            (when (listp gnus-agent-expire-days)
-              (beep)
-              (beep)
-              (gnus-message 1 "WARNING: gnus-agent-expire-days no longer\
- supports being set to a list.")(sleep-for 3)
-              (gnus-message 1 "Change your configuration to set it to an\
- integer.")(sleep-for 3)
-              (gnus-message 1 "I am now setting group parameters on each\
- group to match the configuration that the list offered.")
-
-              (save-excursion
-                (let ((groups (gnus-group-listed-groups)))
-                  (while groups
-                    (let* ((group (pop groups))
-                           (days gnus-agent-expire-days)
-                           (day (catch 'found
-                                  (while days
-                                    (when (eq 0 (string-match
-                                                 (caar days)
-                                                 group))
-                                      (throw 'found (cadar days)))
-                                    (setq days (cdr days)))
-                                  nil)))
-                      (when day
-                        (gnus-group-set-parameter group 'agent-days-until-old
-                                                  day))))))
-
-              (let ((h gnus-group-prepare-hook))
-                (while h
-                  (let ((func (pop h)))
-                    (when (and (listp func)
-                               (eq (cadr (caddr func)) 'gnus-agent-do-once))
-                      (remove-hook 'gnus-group-prepare-hook func)
-                      (setq h nil)))))
-
-              (gnus-message 1 "I have finished setting group parameters on\
- each group. You may now customize your groups and/or topics to control the\
- agent."))))
-
 (provide 'gnus-agent)
 
 ;;; gnus-agent.el ends here