1 ;;; gnus-agent.el --- unplugged support for Gnus
2 ;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; This file is part of GNU Emacs.
8 ;; GNU Emacs is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; GNU Emacs is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs; see the file COPYING. If not, write to the
20 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 ;; Boston, MA 02111-1307, USA.
36 (if (featurep 'xemacs)
42 (autoload 'gnus-server-update-server "gnus-srvr")
43 (autoload 'gnus-agent-customize-category "gnus-cus")
46 (defcustom gnus-agent-directory (nnheader-concat gnus-directory "agent/")
47 "Where the Gnus agent will store its files."
51 (defcustom gnus-agent-plugged-hook nil
52 "Hook run when plugging into the network."
56 (defcustom gnus-agent-unplugged-hook nil
57 "Hook run when unplugging from the network."
61 (defcustom gnus-agent-fetched-hook nil
62 "Hook run when finished fetching articles."
66 (defcustom gnus-agent-handle-level gnus-level-subscribed
67 "Groups on levels higher than this variable will be ignored by the Agent."
71 (defcustom gnus-agent-expire-days 7
72 "Read articles older than this will be expired.
73 If you wish to disable Agent expiring, see `gnus-agent-enable-expiration'."
75 :type '(number :tag "days"))
77 (defcustom gnus-agent-expire-all nil
78 "If non-nil, also expire unread, ticked and dormant articles.
79 If nil, only read articles will be expired."
83 (defcustom gnus-agent-group-mode-hook nil
84 "Hook run in Agent group minor modes."
88 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
89 (when (featurep 'xemacs)
90 (add-hook 'gnus-agent-group-mode-hook 'gnus-xmas-agent-group-menu-add))
92 (defcustom gnus-agent-summary-mode-hook nil
93 "Hook run in Agent summary minor modes."
97 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
98 (when (featurep 'xemacs)
99 (add-hook 'gnus-agent-summary-mode-hook 'gnus-xmas-agent-summary-menu-add))
101 (defcustom gnus-agent-server-mode-hook nil
102 "Hook run in Agent summary minor modes."
106 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
107 (when (featurep 'xemacs)
108 (add-hook 'gnus-agent-server-mode-hook 'gnus-xmas-agent-server-menu-add))
110 (defcustom gnus-agent-confirmation-function 'y-or-n-p
111 "Function to confirm when error happens."
116 (defcustom gnus-agent-synchronize-flags 'ask
117 "Indicate if flags are synchronized when you plug in.
118 If this is `ask' the hook will query the user."
120 :type '(choice (const :tag "Always" t)
121 (const :tag "Never" nil)
122 (const :tag "Ask" ask))
125 (defcustom gnus-agent-go-online 'ask
126 "Indicate if offline servers go online when you plug in.
127 If this is `ask' the hook will query the user."
129 :type '(choice (const :tag "Always" t)
130 (const :tag "Never" nil)
131 (const :tag "Ask" ask))
134 (defcustom gnus-agent-mark-unread-after-downloaded t
135 "Indicate whether to mark articles unread after downloaded."
140 (defcustom gnus-agent-download-marks '(download)
141 "Marks for downloading."
143 :type '(repeat (symbol :tag "Mark"))
146 (defcustom gnus-agent-consider-all-articles nil
147 "When non-`nil', the agent will let the agent predicate decide
148 whether articles need to be downloaded or not, for all articles. When
149 `nil', the default, the agent will only let the predicate decide
150 whether unread articles are downloaded or not. If you enable this,
151 groups with large active ranges may open slower and you may also want
152 to look into the agent expiry settings to block the expiration of
153 read articles as they would just be downloaded again."
158 (defcustom gnus-agent-max-fetch-size 10000000 ;; 10 Mb
159 "Chunk size for `gnus-agent-fetch-session'.
160 The function will split its article fetches into chunks smaller than
165 (defcustom gnus-agent-enable-expiration 'ENABLE
166 "The default expiration state for each group.
167 When set to ENABLE, the default, `gnus-agent-expire' will expire old
168 contents from a group's local storage. This value may be overridden
169 to disable expiration in specific categories, topics, and groups. Of
170 course, you could change gnus-agent-enable-expiration to DISABLE then
171 enable expiration per categories, topics, and groups."
173 :type '(radio (const :format "Enable " ENABLE)
174 (const :format "Disable " DISABLE)))
176 (defcustom gnus-agent-expire-unagentized-dirs t
177 "*Whether expiration should expire in unagentized directories.
178 Have gnus-agent-expire scan the directories under
179 \(gnus-agent-directory) for groups that are no longer agentized.
180 When found, offer to remove them."
184 ;;; Internal variables
186 (defvar gnus-agent-history-buffers nil)
187 (defvar gnus-agent-buffer-alist nil)
188 (defvar gnus-agent-article-alist nil
189 "An assoc list identifying the articles whose headers have been fetched.
190 If successfully fetched, these headers will be stored in the group's overview
191 file. The key of each assoc pair is the article ID, the value of each assoc
192 pair is a flag indicating whether the identified article has been downloaded
193 \(gnus-agent-fetch-articles sets the value to the day of the download).
195 1) The last element of this list can not be expired as some
196 routines (for example, get-agent-fetch-headers) use the last
197 value to track which articles have had their headers retrieved.
198 2) The function `gnus-agent-regenerate' may destructively modify the value.")
199 (defvar gnus-agent-group-alist nil)
200 (defvar gnus-category-alist nil)
201 (defvar gnus-agent-current-history nil)
202 (defvar gnus-agent-overview-buffer nil)
203 (defvar gnus-category-predicate-cache nil)
204 (defvar gnus-category-group-cache nil)
205 (defvar gnus-agent-spam-hashtb nil)
206 (defvar gnus-agent-file-name nil)
207 (defvar gnus-agent-send-mail-function nil)
208 (defvar gnus-agent-file-coding-system 'raw-text)
209 (defvar gnus-agent-file-loading-cache nil)
210 (defvar gnus-agent-file-header-cache nil)
212 (defvar gnus-agent-auto-agentize-methods '(nntp nnimap)
213 "Initially, all servers from these methods are agentized.
214 The user may remove or add servers using the Server buffer. See Info
215 node `(gnus)Server Buffer'.")
218 (defvar gnus-headers)
225 (defun gnus-open-agent ()
227 (gnus-agent-read-servers)
229 (gnus-agent-create-buffer)
230 (add-hook 'gnus-group-mode-hook 'gnus-agent-mode)
231 (add-hook 'gnus-summary-mode-hook 'gnus-agent-mode)
232 (add-hook 'gnus-server-mode-hook 'gnus-agent-mode))
234 (defun gnus-agent-create-buffer ()
235 (if (gnus-buffer-live-p gnus-agent-overview-buffer)
237 (setq gnus-agent-overview-buffer
238 (gnus-get-buffer-create " *Gnus agent overview*"))
239 (with-current-buffer gnus-agent-overview-buffer
240 (mm-enable-multibyte))
243 (gnus-add-shutdown 'gnus-close-agent 'gnus)
245 (defun gnus-close-agent ()
246 (setq gnus-category-predicate-cache nil
247 gnus-category-group-cache nil
248 gnus-agent-spam-hashtb nil)
249 (gnus-kill-buffer gnus-agent-overview-buffer))
252 ;;; Utility functions
255 (defun gnus-agent-read-file (file)
256 "Load FILE and do a `read' there."
259 (nnheader-insert-file-contents file)
260 (goto-char (point-min))
261 (read (current-buffer)))))
263 (defsubst gnus-agent-method ()
264 (concat (symbol-name (car gnus-command-method)) "/"
265 (if (equal (cadr gnus-command-method) "")
267 (cadr gnus-command-method))))
269 (defsubst gnus-agent-directory ()
270 "The name of the Gnus agent directory."
271 (nnheader-concat gnus-agent-directory
272 (nnheader-translate-file-chars (gnus-agent-method)) "/"))
274 (defun gnus-agent-lib-file (file)
275 "The full name of the Gnus agent library FILE."
276 (expand-file-name file
277 (file-name-as-directory
278 (expand-file-name "agent.lib" (gnus-agent-directory)))))
280 (defun gnus-agent-cat-set-property (category property value)
282 (setcdr (or (assq property category)
283 (let ((cell (cons property nil)))
284 (setcdr category (cons cell (cdr category)))
286 (let ((category category))
287 (while (cond ((eq property (caadr category))
288 (setcdr category (cddr category))
291 (setq category (cdr category)))))))
295 (defmacro gnus-agent-cat-defaccessor (name prop-name)
296 "Define accessor and setter methods for manipulating a list of the form
297 \(NAME (PROPERTY1 VALUE1) ... (PROPERTY_N VALUE_N)).
298 Given the call (gnus-agent-cat-defaccessor func PROPERTY1), the list may be
299 manipulated as follows:
300 (func LIST): Returns VALUE1
301 (setf (func LIST) NEW_VALUE1): Replaces VALUE1 with NEW_VALUE1."
302 `(progn (defmacro ,name (category)
303 (list (quote cdr) (list (quote assq)
304 (quote (quote ,prop-name)) category)))
306 (define-setf-method ,name (category)
307 (let* ((--category--temp-- (make-symbol "--category--"))
308 (--value--temp-- (make-symbol "--value--")))
309 (list (list --category--temp--) ; temporary-variables
310 (list category) ; value-forms
311 (list --value--temp--) ; store-variables
312 (let* ((category --category--temp--) ; store-form
313 (value --value--temp--))
314 (list (quote gnus-agent-cat-set-property)
316 (quote (quote ,prop-name))
318 (list (quote ,name) --category--temp--) ; access-form
322 (defmacro gnus-agent-cat-name (category)
325 (gnus-agent-cat-defaccessor
326 gnus-agent-cat-days-until-old agent-days-until-old)
327 (gnus-agent-cat-defaccessor
328 gnus-agent-cat-enable-expiration agent-enable-expiration)
329 (gnus-agent-cat-defaccessor
330 gnus-agent-cat-groups agent-groups)
331 (gnus-agent-cat-defaccessor
332 gnus-agent-cat-high-score agent-high-score)
333 (gnus-agent-cat-defaccessor
334 gnus-agent-cat-length-when-long agent-length-when-long)
335 (gnus-agent-cat-defaccessor
336 gnus-agent-cat-length-when-short agent-length-when-short)
337 (gnus-agent-cat-defaccessor
338 gnus-agent-cat-low-score agent-low-score)
339 (gnus-agent-cat-defaccessor
340 gnus-agent-cat-predicate agent-predicate)
341 (gnus-agent-cat-defaccessor
342 gnus-agent-cat-score-file agent-score-file)
343 (gnus-agent-cat-defaccessor
344 gnus-agent-cat-disable-undownloaded-faces agent-disable-undownloaded-faces)
347 (defsetf gnus-agent-cat-groups (category) (groups)
348 (list 'gnus-agent-set-cat-groups category groups)))
350 (defun gnus-agent-set-cat-groups (category groups)
351 (unless (eq groups 'ignore)
353 (old-g (gnus-agent-cat-groups category)))
354 (cond ((eq new-g old-g)
355 ;; gnus-agent-add-group is fiddling with the group
356 ;; list. Still, Im done.
359 ((eq new-g (cdr old-g))
360 ;; gnus-agent-add-group is fiddling with the group list
361 (setcdr (or (assq 'agent-groups category)
362 (let ((cell (cons 'agent-groups nil)))
363 (setcdr category (cons cell (cdr category)))
366 (let ((groups groups))
368 (let* ((group (pop groups))
369 (old-category (gnus-group-category group)))
370 (if (eq category old-category)
372 (setf (gnus-agent-cat-groups old-category)
373 (delete group (gnus-agent-cat-groups
375 ;; Purge cache as preceeding loop invalidated it.
376 (setq gnus-category-group-cache nil))
378 (setcdr (or (assq 'agent-groups category)
379 (let ((cell (cons 'agent-groups nil)))
380 (setcdr category (cons cell (cdr category)))
383 (defsubst gnus-agent-cat-make (name &optional default-agent-predicate)
384 (list name `(agent-predicate . ,(or default-agent-predicate 'false))))
386 ;;; Fetching setup functions.
388 (defun gnus-agent-start-fetch ()
389 "Initialize data structures for efficient fetching."
390 (gnus-agent-create-buffer))
392 (defun gnus-agent-stop-fetch ()
393 "Save all data structures and clean up."
394 (setq gnus-agent-spam-hashtb nil)
396 (set-buffer nntp-server-buffer)
399 (defmacro gnus-agent-with-fetch (&rest forms)
402 (let ((gnus-agent-fetching t))
403 (gnus-agent-start-fetch)
405 (gnus-agent-stop-fetch)))
407 (put 'gnus-agent-with-fetch 'lisp-indent-function 0)
408 (put 'gnus-agent-with-fetch 'edebug-form-spec '(body))
410 (defmacro gnus-agent-append-to-list (tail value)
411 `(setq ,tail (setcdr ,tail (cons ,value nil))))
413 (defmacro gnus-agent-message (level &rest args)
414 `(if (<= ,level gnus-verbose)
421 (defvar gnus-agent-mode-hook nil
422 "Hook run when installing agent mode.")
424 (defvar gnus-agent-mode nil)
425 (defvar gnus-agent-mode-status '(gnus-agent-mode " Plugged"))
427 (defun gnus-agent-mode ()
428 "Minor mode for providing a agent support in Gnus buffers."
429 (let* ((buffer (progn (string-match "^gnus-\\(.*\\)-mode$"
430 (symbol-name major-mode))
431 (match-string 1 (symbol-name major-mode))))
432 (mode (intern (format "gnus-agent-%s-mode" buffer))))
433 (set (make-local-variable 'gnus-agent-mode) t)
435 (set (make-local-variable mode) t)
437 (when (gnus-visual-p 'agent-menu 'menu)
438 (funcall (intern (format "gnus-agent-%s-make-menu-bar" buffer))))
439 (unless (assq 'gnus-agent-mode minor-mode-alist)
440 (push gnus-agent-mode-status minor-mode-alist))
441 (unless (assq mode minor-mode-map-alist)
442 (push (cons mode (symbol-value (intern (format "gnus-agent-%s-mode-map"
444 minor-mode-map-alist))
445 (when (eq major-mode 'gnus-group-mode)
446 (let ((init-plugged gnus-plugged)
447 (gnus-agent-go-online nil))
448 ;; g-a-t-p does nothing when gnus-plugged isn't changed.
449 ;; Therefore, make certain that the current value does not
450 ;; match the desired initial value.
451 (setq gnus-plugged :unknown)
452 (gnus-agent-toggle-plugged init-plugged)))
453 (gnus-run-hooks 'gnus-agent-mode-hook
454 (intern (format "gnus-agent-%s-mode-hook" buffer)))))
456 (defvar gnus-agent-group-mode-map (make-sparse-keymap))
457 (gnus-define-keys gnus-agent-group-mode-map
458 "Ju" gnus-agent-fetch-groups
459 "Jc" gnus-enter-category-buffer
460 "Jj" gnus-agent-toggle-plugged
461 "Js" gnus-agent-fetch-session
462 "JY" gnus-agent-synchronize-flags
463 "JS" gnus-group-send-queue
464 "Ja" gnus-agent-add-group
465 "Jr" gnus-agent-remove-group
466 "Jo" gnus-agent-toggle-group-plugged)
468 (defun gnus-agent-group-make-menu-bar ()
469 (unless (boundp 'gnus-agent-group-menu)
471 gnus-agent-group-menu gnus-agent-group-mode-map ""
473 ["Toggle plugged" gnus-agent-toggle-plugged t]
474 ["Toggle group plugged" gnus-agent-toggle-group-plugged t]
475 ["List categories" gnus-enter-category-buffer t]
476 ["Add (current) group to category" gnus-agent-add-group t]
477 ["Remove (current) group from category" gnus-agent-remove-group t]
478 ["Send queue" gnus-group-send-queue gnus-plugged]
480 ["All" gnus-agent-fetch-session gnus-plugged]
481 ["Group" gnus-agent-fetch-group gnus-plugged])
482 ["Synchronize flags" gnus-agent-synchronize-flags t]
485 (defvar gnus-agent-summary-mode-map (make-sparse-keymap))
486 (gnus-define-keys gnus-agent-summary-mode-map
487 "Jj" gnus-agent-toggle-plugged
488 "Ju" gnus-agent-summary-fetch-group
489 "JS" gnus-agent-fetch-group
490 "Js" gnus-agent-summary-fetch-series
491 "J#" gnus-agent-mark-article
492 "J\M-#" gnus-agent-unmark-article
493 "@" gnus-agent-toggle-mark
494 "Jc" gnus-agent-catchup)
496 (defun gnus-agent-summary-make-menu-bar ()
497 (unless (boundp 'gnus-agent-summary-menu)
499 gnus-agent-summary-menu gnus-agent-summary-mode-map ""
501 ["Toggle plugged" gnus-agent-toggle-plugged t]
502 ["Mark as downloadable" gnus-agent-mark-article t]
503 ["Unmark as downloadable" gnus-agent-unmark-article t]
504 ["Toggle mark" gnus-agent-toggle-mark t]
505 ["Fetch downloadable" gnus-agent-summary-fetch-group t]
506 ["Catchup undownloaded" gnus-agent-catchup t]))))
508 (defvar gnus-agent-server-mode-map (make-sparse-keymap))
509 (gnus-define-keys gnus-agent-server-mode-map
510 "Jj" gnus-agent-toggle-plugged
511 "Ja" gnus-agent-add-server
512 "Jr" gnus-agent-remove-server)
514 (defun gnus-agent-server-make-menu-bar ()
515 (unless (boundp 'gnus-agent-server-menu)
517 gnus-agent-server-menu gnus-agent-server-mode-map ""
519 ["Toggle plugged" gnus-agent-toggle-plugged t]
520 ["Add" gnus-agent-add-server t]
521 ["Remove" gnus-agent-remove-server t]))))
523 (defun gnus-agent-make-mode-line-string (string mouse-button mouse-func)
524 (if (and (fboundp 'propertize)
525 (fboundp 'make-mode-line-mouse-map))
526 (propertize string 'local-map
527 (make-mode-line-mouse-map mouse-button mouse-func))
530 (defun gnus-agent-toggle-plugged (set-to)
531 "Toggle whether Gnus is unplugged or not."
532 (interactive (list (not gnus-plugged)))
533 (cond ((eq set-to gnus-plugged)
536 (setq gnus-plugged set-to)
537 (gnus-run-hooks 'gnus-agent-plugged-hook)
538 (setcar (cdr gnus-agent-mode-status)
539 (gnus-agent-make-mode-line-string " Plugged"
541 'gnus-agent-toggle-plugged))
542 (gnus-agent-go-online gnus-agent-go-online)
543 (gnus-agent-possibly-synchronize-flags))
545 (gnus-agent-close-connections)
546 (setq gnus-plugged set-to)
547 (gnus-run-hooks 'gnus-agent-unplugged-hook)
548 (setcar (cdr gnus-agent-mode-status)
549 (gnus-agent-make-mode-line-string " Unplugged"
551 'gnus-agent-toggle-plugged))))
552 (set-buffer-modified-p t))
554 (defmacro gnus-agent-while-plugged (&rest body)
555 `(let ((original-gnus-plugged gnus-plugged))
557 (progn (gnus-agent-toggle-plugged t)
559 (gnus-agent-toggle-plugged original-gnus-plugged))))
561 (put 'gnus-agent-while-plugged 'lisp-indent-function 0)
562 (put 'gnus-agent-while-plugged 'edebug-form-spec '(body))
564 (defun gnus-agent-close-connections ()
565 "Close all methods covered by the Gnus agent."
566 (let ((methods (gnus-agent-covered-methods)))
568 (gnus-close-server (pop methods)))))
571 (defun gnus-unplugged ()
572 "Start Gnus unplugged."
574 (setq gnus-plugged nil)
578 (defun gnus-plugged ()
579 "Start Gnus plugged."
581 (setq gnus-plugged t)
585 (defun gnus-slave-unplugged (&optional arg)
586 "Read news as a slave unplugged."
588 (setq gnus-plugged nil)
589 (gnus arg nil 'slave))
592 (defun gnus-agentize ()
593 "Allow Gnus to be an offline newsreader.
595 The gnus-agentize function is now called internally by gnus when
596 gnus-agent is set. If you wish to avoid calling gnus-agentize,
597 customize gnus-agent to nil.
599 This will modify the `gnus-setup-news-hook', and
600 `message-send-mail-real-function' variables, and install the Gnus agent
601 minor mode in all Gnus buffers."
604 (add-hook 'gnus-setup-news-hook 'gnus-agent-queue-setup)
605 (unless gnus-agent-send-mail-function
606 (setq gnus-agent-send-mail-function
607 (or message-send-mail-real-function
608 message-send-mail-function)
609 message-send-mail-real-function 'gnus-agent-send-mail))
611 (unless gnus-agent-covered-methods
613 (lambda (server-or-method)
614 (let ((method (gnus-server-to-method server-or-method)))
615 (when (memq (car method)
616 gnus-agent-auto-agentize-methods)
617 (push (gnus-method-to-server method)
618 gnus-agent-covered-methods)
619 (setq gnus-agent-method-p-cache nil))))
620 (cons gnus-select-method gnus-secondary-select-methods))))
622 (defun gnus-agent-queue-setup (&optional group-name)
623 "Make sure the queue group exists.
624 Optional arg GROUP-NAME allows to specify another group."
625 (unless (gnus-gethash (format "nndraft:%s" (or group-name "queue"))
627 (gnus-request-create-group (or group-name "queue") '(nndraft ""))
628 (let ((gnus-level-default-subscribed 1))
629 (gnus-subscribe-group (format "nndraft:%s" (or group-name "queue"))
631 (gnus-group-set-parameter
632 (format "nndraft:%s" (or group-name "queue"))
633 'gnus-dummy '((gnus-draft-mode)))))
635 (defun gnus-agent-send-mail ()
637 (funcall gnus-agent-send-mail-function)
638 (goto-char (point-min))
640 (concat "^" (regexp-quote mail-header-separator) "\n"))
642 (gnus-agent-insert-meta-information 'mail)
643 (gnus-request-accept-article "nndraft:queue" nil t t)))
645 (defun gnus-agent-insert-meta-information (type &optional method)
646 "Insert meta-information into the message that says how it's to be posted.
647 TYPE can be either `mail' or `news'. If the latter, then METHOD can
650 (message-remove-header gnus-agent-meta-information-header)
651 (goto-char (point-min))
652 (insert gnus-agent-meta-information-header ": "
653 (symbol-name type) " " (format "%S" method)
656 (while (search-backward "\n" nil t)
657 (replace-match "\\n" t t))))
659 (defun gnus-agent-restore-gcc ()
660 "Restore GCC field from saved header."
662 (goto-char (point-min))
663 (while (re-search-forward (concat gnus-agent-gcc-header ":") nil t)
664 (replace-match "Gcc:" 'fixedcase))))
666 (defun gnus-agent-any-covered-gcc ()
668 (message-narrow-to-headers)
669 (let* ((gcc (mail-fetch-field "gcc" nil t))
671 (mapcar 'gnus-inews-group-method
672 (message-unquote-tokens
673 (message-tokenize-header
676 (while (and (not covered) methods)
677 (setq covered (gnus-agent-method-p (car methods))
678 methods (cdr methods)))
682 (defun gnus-agent-possibly-save-gcc ()
683 "Save GCC if Gnus is unplugged."
684 (when (and (not gnus-plugged) (gnus-agent-any-covered-gcc))
686 (goto-char (point-min))
687 (let ((case-fold-search t))
688 (while (re-search-forward "^gcc:" nil t)
689 (replace-match (concat gnus-agent-gcc-header ":") 'fixedcase))))))
691 (defun gnus-agent-possibly-do-gcc ()
692 "Do GCC if Gnus is plugged."
693 (when (or gnus-plugged (not (gnus-agent-any-covered-gcc)))
694 (gnus-inews-do-gcc)))
697 ;;; Group mode commands
700 (defun gnus-agent-fetch-groups (n)
701 "Put all new articles in the current groups into the Agent."
704 (error "Groups can't be fetched when Gnus is unplugged"))
705 (gnus-group-iterate n 'gnus-agent-fetch-group))
707 (defun gnus-agent-fetch-group (&optional group)
708 "Put all new articles in GROUP into the Agent."
709 (interactive (list (gnus-group-group-name)))
710 (setq group (or group gnus-newsgroup-name))
712 (error "No group on the current line"))
714 (gnus-agent-while-plugged
715 (let ((gnus-command-method (gnus-find-method-for-group group)))
716 (gnus-agent-with-fetch
717 (gnus-agent-fetch-group-1 group gnus-command-method)
718 (gnus-message 5 "Fetching %s...done" group)))))
720 (defun gnus-agent-add-group (category arg)
721 "Add the current group to an agent category."
727 (mapcar (lambda (cat) (list (symbol-name (car cat))))
731 (let ((cat (assq category gnus-category-alist))
733 (gnus-group-iterate arg
735 (when (gnus-agent-cat-groups (setq c (gnus-group-category group)))
736 (setf (gnus-agent-cat-groups c)
737 (delete group (gnus-agent-cat-groups c))))
738 (push group groups)))
739 (setf (gnus-agent-cat-groups cat)
740 (nconc (gnus-agent-cat-groups cat) groups))
741 (gnus-category-write)))
743 (defun gnus-agent-remove-group (arg)
744 "Remove the current group from its agent category, if any."
747 (gnus-group-iterate arg
749 (when (gnus-agent-cat-groups (setq c (gnus-group-category group)))
750 (setf (gnus-agent-cat-groups c)
751 (delete group (gnus-agent-cat-groups c))))))
752 (gnus-category-write)))
754 (defun gnus-agent-synchronize-flags ()
755 "Synchronize unplugged flags with servers."
758 (dolist (gnus-command-method (gnus-agent-covered-methods))
759 (when (file-exists-p (gnus-agent-lib-file "flags"))
760 (gnus-agent-synchronize-flags-server gnus-command-method)))))
762 (defun gnus-agent-possibly-synchronize-flags ()
763 "Synchronize flags according to `gnus-agent-synchronize-flags'."
766 (dolist (gnus-command-method (gnus-agent-covered-methods))
767 (when (file-exists-p (gnus-agent-lib-file "flags"))
768 (gnus-agent-possibly-synchronize-flags-server gnus-command-method)))))
770 (defun gnus-agent-synchronize-flags-server (method)
771 "Synchronize flags set when unplugged for server."
772 (let ((gnus-command-method method))
773 (when (file-exists-p (gnus-agent-lib-file "flags"))
774 (set-buffer (get-buffer-create " *Gnus Agent flag synchronize*"))
776 (nnheader-insert-file-contents (gnus-agent-lib-file "flags"))
777 (if (null (gnus-check-server gnus-command-method))
778 (gnus-message 1 "Couldn't open server %s" (nth 1 gnus-command-method))
780 (if (null (eval (read (current-buffer))))
782 (write-file (gnus-agent-lib-file "flags"))
783 (error "Couldn't set flags from file %s"
784 (gnus-agent-lib-file "flags"))))
785 (delete-file (gnus-agent-lib-file "flags")))
788 (defun gnus-agent-possibly-synchronize-flags-server (method)
789 "Synchronize flags for server according to `gnus-agent-synchronize-flags'."
790 (when (or (and gnus-agent-synchronize-flags
791 (not (eq gnus-agent-synchronize-flags 'ask)))
792 (and (eq gnus-agent-synchronize-flags 'ask)
793 (gnus-y-or-n-p (format "Synchronize flags on server `%s'? "
795 (gnus-agent-synchronize-flags-server method)))
798 ;;; Server mode commands
801 (defun gnus-agent-add-server ()
802 "Enroll SERVER in the agent program."
804 (let* ((server (gnus-server-server-name))
805 (named-server (gnus-server-named-server))
807 (gnus-server-get-method nil server))))
809 (error "No server on the current line"))
811 (when (gnus-agent-method-p method)
812 (error "Server already in the agent program"))
814 (push named-server gnus-agent-covered-methods)
816 (setq gnus-agent-method-p-cache nil)
817 (gnus-server-update-server server)
818 (gnus-agent-write-servers)
819 (gnus-message 1 "Entered %s into the Agent" server)))
821 (defun gnus-agent-remove-server ()
822 "Remove SERVER from the agent program."
824 (let* ((server (gnus-server-server-name))
825 (named-server (gnus-server-named-server)))
827 (error "No server on the current line"))
829 (unless (member named-server gnus-agent-covered-methods)
830 (error "Server not in the agent program"))
832 (setq gnus-agent-covered-methods
833 (delete named-server gnus-agent-covered-methods)
834 gnus-agent-method-p-cache nil)
836 (gnus-server-update-server server)
837 (gnus-agent-write-servers)
838 (gnus-message 1 "Removed %s from the agent" server)))
840 (defun gnus-agent-read-servers ()
841 "Read the alist of covered servers."
842 (setq gnus-agent-covered-methods
843 (gnus-agent-read-file
844 (nnheader-concat gnus-agent-directory "lib/servers"))
845 gnus-agent-method-p-cache nil)
847 ;; I am called so early in start-up that I can not validate server
848 ;; names. When that is the case, I skip the validation. That is
849 ;; alright as the gnus startup code calls the validate methods
851 (if gnus-server-alist
852 (gnus-agent-read-servers-validate)))
854 (defun gnus-agent-read-servers-validate ()
855 (mapcar (lambda (server-or-method)
856 (let* ((server (if (stringp server-or-method)
858 (gnus-method-to-server server-or-method)))
859 (method (gnus-server-to-method server)))
861 (unless (member server gnus-agent-covered-methods)
862 (push server gnus-agent-covered-methods)
863 (setq gnus-agent-method-p-cache nil))
864 (gnus-message 1 "Ignoring disappeared server `%s'" server))))
865 (prog1 gnus-agent-covered-methods
866 (setq gnus-agent-covered-methods nil))))
868 (defun gnus-agent-read-servers-validate-native (native-method)
869 (setq gnus-agent-covered-methods
870 (mapcar (lambda (method)
872 (equal method native-method))
874 method)) gnus-agent-covered-methods)))
876 (defun gnus-agent-write-servers ()
877 "Write the alist of covered servers."
878 (gnus-make-directory (nnheader-concat gnus-agent-directory "lib"))
879 (let ((coding-system-for-write nnheader-file-coding-system)
880 (file-name-coding-system nnmail-pathname-coding-system))
881 (with-temp-file (nnheader-concat gnus-agent-directory "lib/servers")
882 (prin1 gnus-agent-covered-methods
889 (defun gnus-agent-mark-article (n &optional unmark)
890 "Mark the next N articles as downloadable.
891 If N is negative, mark backward instead. If UNMARK is non-nil, remove
892 the mark instead. The difference between N and the actual number of
893 articles marked is returned."
895 (let ((backward (< n 0))
900 (gnus-summary-set-agent-mark
901 (gnus-summary-article-number) unmark)
902 (zerop (gnus-summary-next-subject (if backward -1 1) nil t))))
905 (gnus-message 7 "No more articles"))
906 (gnus-summary-recenter)
907 (gnus-summary-position-point)
910 (defun gnus-agent-unmark-article (n)
911 "Remove the downloadable mark from the next N articles.
912 If N is negative, unmark backward instead. The difference between N and
913 the actual number of articles unmarked is returned."
915 (gnus-agent-mark-article n t))
917 (defun gnus-agent-toggle-mark (n)
918 "Toggle the downloadable mark from the next N articles.
919 If N is negative, toggle backward instead. The difference between N and
920 the actual number of articles toggled is returned."
922 (gnus-agent-mark-article n 'toggle))
924 (defun gnus-summary-set-agent-mark (article &optional unmark)
925 "Mark ARTICLE as downloadable. If UNMARK is nil, article is marked.
926 When UNMARK is t, the article is unmarked. For any other value, the
927 article's mark is toggled."
928 (let ((unmark (cond ((eq nil unmark)
933 (memq article gnus-newsgroup-downloadable)))))
934 (when (gnus-summary-goto-subject article nil t)
935 (gnus-summary-update-mark
938 (setq gnus-newsgroup-downloadable
939 (delq article gnus-newsgroup-downloadable))
940 (gnus-article-mark article))
942 (setq gnus-newsgroup-downloadable
943 (gnus-add-to-sorted-list gnus-newsgroup-downloadable article))
944 gnus-downloadable-mark)
948 (defun gnus-agent-get-undownloaded-list ()
949 "Construct list of articles that have not been downloaded."
950 (let ((gnus-command-method (gnus-find-method-for-group gnus-newsgroup-name)))
951 (when (set (make-local-variable 'gnus-newsgroup-agentized)
952 (gnus-agent-method-p gnus-command-method))
953 (let* ((alist (gnus-agent-load-alist gnus-newsgroup-name))
954 (headers (sort (mapcar (lambda (h)
955 (mail-header-number h))
956 gnus-newsgroup-headers) '<))
957 (cached (and gnus-use-cache gnus-newsgroup-cached))
958 (undownloaded (list nil))
959 (tail-undownloaded undownloaded)
960 (unfetched (list nil))
961 (tail-unfetched unfetched))
962 (while (and alist headers)
963 (let ((a (caar alist))
966 ;; Ignore IDs in the alist that are not being
967 ;; displayed in the summary.
968 (setq alist (cdr alist)))
970 ;; Headers that are not in the alist should be
971 ;; fictious (see nnagent-retrieve-headers); they
972 ;; imply that this article isn't in the agent.
973 (gnus-agent-append-to-list tail-undownloaded h)
974 (gnus-agent-append-to-list tail-unfetched h)
975 (setq headers (cdr headers)))
977 (setq alist (cdr alist))
978 (setq headers (cdr headers))
979 nil ; ignore already downloaded
982 (setq alist (cdr alist))
983 (setq headers (cdr headers))
985 ;; This article isn't in the agent. Check to see
986 ;; if it is in the cache. If it is, it's been
988 (while (and cached (< (car cached) a))
989 (setq cached (cdr cached)))
990 (unless (equal a (car cached))
991 (gnus-agent-append-to-list tail-undownloaded a))))))
994 (let ((num (pop headers)))
995 (gnus-agent-append-to-list tail-undownloaded num)
996 (gnus-agent-append-to-list tail-unfetched num)))
998 (setq gnus-newsgroup-undownloaded (cdr undownloaded)
999 gnus-newsgroup-unfetched (cdr unfetched))))))
1001 (defun gnus-agent-catchup ()
1002 "Mark as read all unhandled articles.
1003 An article is unhandled if it is neither cached, nor downloaded, nor
1007 (let ((articles gnus-newsgroup-undownloaded))
1008 (when (or gnus-newsgroup-downloadable
1009 gnus-newsgroup-cached)
1010 (setq articles (gnus-sorted-ndifference
1011 (gnus-sorted-ndifference
1012 (gnus-copy-sequence articles)
1013 gnus-newsgroup-downloadable)
1014 gnus-newsgroup-cached)))
1017 (gnus-summary-mark-article
1018 (pop articles) gnus-catchup-mark)))
1019 (gnus-summary-position-point)))
1021 (defun gnus-agent-summary-fetch-series ()
1023 (when gnus-newsgroup-processable
1024 (setq gnus-newsgroup-downloadable
1025 (let* ((dl gnus-newsgroup-downloadable)
1026 (gnus-newsgroup-downloadable
1027 (sort (gnus-copy-sequence gnus-newsgroup-processable) '<))
1028 (fetched-articles (gnus-agent-summary-fetch-group)))
1029 ;; The preceeding call to (gnus-agent-summary-fetch-group)
1030 ;; updated gnus-newsgroup-downloadable to remove each
1031 ;; article successfully fetched.
1033 ;; For each article that I processed, remove its
1034 ;; processable mark IF the article is no longer
1035 ;; downloadable (i.e. it's already downloaded)
1036 (dolist (article gnus-newsgroup-processable)
1037 (unless (memq article gnus-newsgroup-downloadable)
1038 (gnus-summary-remove-process-mark article)))
1039 (gnus-sorted-ndifference dl fetched-articles)))))
1041 (defun gnus-agent-summary-fetch-group (&optional all)
1042 "Fetch the downloadable articles in the group.
1043 Optional arg ALL, if non-nil, means to fetch all articles."
1046 (if all gnus-newsgroup-articles
1047 gnus-newsgroup-downloadable))
1048 (gnus-command-method (gnus-find-method-for-group gnus-newsgroup-name))
1050 (gnus-agent-while-plugged
1052 (error "No articles to download"))
1053 (gnus-agent-with-fetch
1054 (setq gnus-newsgroup-undownloaded
1055 (gnus-sorted-ndifference
1056 gnus-newsgroup-undownloaded
1057 (setq fetched-articles
1058 (gnus-agent-fetch-articles
1059 gnus-newsgroup-name articles)))))
1061 (dolist (article articles)
1062 (let ((was-marked-downloadable
1063 (memq article gnus-newsgroup-downloadable)))
1064 (cond (gnus-agent-mark-unread-after-downloaded
1065 (setq gnus-newsgroup-downloadable
1066 (delq article gnus-newsgroup-downloadable))
1068 ;; The downloadable mark is implemented as a
1069 ;; type of read mark. Therefore, marking the
1070 ;; article as unread is sufficient to clear
1071 ;; its downloadable flag.
1072 (gnus-summary-mark-article article gnus-unread-mark))
1073 (was-marked-downloadable
1074 (gnus-summary-set-agent-mark article t)))
1075 (when (gnus-summary-goto-subject article nil t)
1076 (gnus-summary-update-download-mark article))))))
1079 (defun gnus-agent-fetch-selected-article ()
1080 "Fetch the current article as it is selected.
1081 This can be added to `gnus-select-article-hook' or
1082 `gnus-mark-article-hook'."
1083 (let ((gnus-command-method gnus-current-select-method))
1084 (when (and gnus-plugged (gnus-agent-method-p gnus-command-method))
1085 (when (gnus-agent-fetch-articles
1087 (list gnus-current-article))
1088 (setq gnus-newsgroup-undownloaded
1089 (delq gnus-current-article gnus-newsgroup-undownloaded))
1090 (gnus-summary-update-download-mark gnus-current-article)))))
1093 ;;; Internal functions
1097 ;;; The agent's active range is defined as follows:
1098 ;;; If the agent has no record of the group, use the actual active
1100 ;;; If the agent has a record, set the agent's active range to
1101 ;;; include the max limit of the actual active range.
1102 ;;; When expiring, update the min limit to match the smallest of the
1103 ;;; min article not expired or the min actual active range.
1105 (defun gnus-agent-save-active (method)
1106 (gnus-agent-save-active-1 method 'gnus-active-to-gnus-format))
1108 (defun gnus-agent-save-active-1 (method function)
1109 (when (gnus-agent-method-p method)
1110 (let* ((gnus-command-method method)
1111 (new (gnus-make-hashtable (count-lines (point-min) (point-max))))
1112 (file (gnus-agent-lib-file "active")))
1113 (funcall function nil new)
1114 (gnus-agent-write-active file new)
1116 (nnheader-insert-file-contents file))))
1118 (defun gnus-agent-write-active (file new &optional literal-replacement)
1120 (when (and (not literal-replacement)
1121 (file-exists-p file))
1122 (setq old (gnus-make-hashtable (count-lines (point-min) (point-max))))
1124 (nnheader-insert-file-contents file)
1125 (gnus-active-to-gnus-format nil old))
1126 ;; Iterate over the current active groups, the current active
1127 ;; range may expand, but NOT CONTRACT, the agent's active range.
1130 (let ((new-active (and nsym (boundp nsym) (symbol-value nsym))))
1132 (let* ((osym (intern (symbol-name nsym) old))
1133 (old-active (and (boundp osym) (symbol-value osym))))
1135 (let ((new-min (car new-active))
1136 (old-min (car old-active))
1137 (new-max (cdr new-active))
1138 (old-max (cdr old-active)))
1139 (if (and (integerp new-min)
1140 (< new-min old-min))
1141 (setcar old-active new-min))
1142 (if (and (integerp new-max)
1143 (> new-max old-max))
1144 (setcdr old-active new-max)))
1145 (set osym new-active))))))
1147 (gnus-make-directory (file-name-directory file))
1148 (let ((nnmail-active-file-coding-system gnus-agent-file-coding-system))
1149 ;; The hashtable contains real names of groups. However, do NOT
1150 ;; add the foreign server prefix as gnus-active-to-gnus-format
1151 ;; will add it while reading the file.
1152 (gnus-write-active-file file old nil))))
1154 (defun gnus-agent-save-groups (method)
1155 (gnus-agent-save-active-1 method 'gnus-groups-to-gnus-format))
1157 (defun gnus-agent-save-group-info (method group active)
1158 (when (gnus-agent-method-p method)
1159 (let* ((gnus-command-method method)
1160 (coding-system-for-write nnheader-file-coding-system)
1161 (file-name-coding-system nnmail-pathname-coding-system)
1162 (file (gnus-agent-lib-file "active"))
1163 oactive-min oactive-max)
1164 (gnus-make-directory (file-name-directory file))
1165 (with-temp-file file
1166 ;; Emacs got problem to match non-ASCII group in multibyte buffer.
1167 (mm-disable-multibyte)
1168 (when (file-exists-p file)
1169 (nnheader-insert-file-contents file)
1171 (goto-char (point-min))
1172 (when (re-search-forward
1173 (concat "^" (regexp-quote group) " ") nil t)
1175 (setq oactive-max (read (current-buffer)) ;; max
1176 oactive-min (read (current-buffer)))) ;; min
1177 (gnus-delete-line)))
1178 (insert (format "%S %d %d y\n" (intern group)
1179 (max (or oactive-max (cdr active)) (cdr active))
1180 (min (or oactive-min (car active)) (car active))))
1181 (goto-char (point-max))
1182 (while (search-backward "\\." nil t)
1183 (delete-char 1))))))
1185 (defun gnus-agent-group-path (group)
1186 "Translate GROUP into a file name."
1188 ;; NOTE: This is what nnmail-group-pathname does as of Apr 2003.
1189 ;; The two methods must be kept synchronized, which is why
1190 ;; gnus-agent-group-pathname was added.
1193 (nnheader-translate-file-chars
1194 (nnheader-replace-duplicate-chars-in-string
1195 (nnheader-replace-chars-in-string
1196 (gnus-group-real-name group)
1199 (if (or nnmail-use-long-file-names
1200 (file-directory-p (expand-file-name group (gnus-agent-directory))))
1202 (mm-encode-coding-string
1203 (nnheader-replace-chars-in-string group ?. ?/)
1204 nnmail-pathname-coding-system)))
1206 (defun gnus-agent-group-pathname (group)
1207 "Translate GROUP into a file name."
1208 ;; nnagent uses nnmail-group-pathname to read articles while
1209 ;; unplugged. The agent must, therefore, use the same directory
1211 (let ((gnus-command-method (or gnus-command-method
1212 (gnus-find-method-for-group group))))
1213 (nnmail-group-pathname (gnus-group-real-name group) (gnus-agent-directory))))
1215 (defun gnus-agent-get-function (method)
1216 (if (gnus-online method)
1221 (defun gnus-agent-covered-methods ()
1222 "Return the subset of methods that are covered by the agent."
1223 (delq nil (mapcar #'gnus-server-to-method gnus-agent-covered-methods)))
1225 ;;; History functions
1227 (defun gnus-agent-history-buffer ()
1228 (cdr (assoc (gnus-agent-method) gnus-agent-history-buffers)))
1230 (defun gnus-agent-open-history ()
1232 (push (cons (gnus-agent-method)
1233 (set-buffer (gnus-get-buffer-create
1234 (format " *Gnus agent %s history*"
1235 (gnus-agent-method)))))
1236 gnus-agent-history-buffers)
1237 (mm-disable-multibyte) ;; everything is binary
1240 (let ((file (gnus-agent-lib-file "history")))
1241 (when (file-exists-p file)
1242 (nnheader-insert-file-contents file))
1243 (set (make-local-variable 'gnus-agent-file-name) file))))
1245 (defun gnus-agent-close-history ()
1246 (when (gnus-buffer-live-p gnus-agent-current-history)
1247 (kill-buffer gnus-agent-current-history)
1248 (setq gnus-agent-history-buffers
1249 (delq (assoc (gnus-agent-method) gnus-agent-history-buffers)
1250 gnus-agent-history-buffers))))
1256 (defun gnus-agent-fetch-articles (group articles)
1257 "Fetch ARTICLES from GROUP and put them into the Agent."
1259 (gnus-agent-load-alist group)
1260 (let* ((alist gnus-agent-article-alist)
1261 (headers (if (< (length articles) 2) nil gnus-newsgroup-headers))
1262 (selected-sets (list nil))
1263 (current-set-size 0)
1266 ;; Check each article
1267 (while (setq article (pop articles))
1268 ;; Skip alist entries preceeding this article
1269 (while (> article (or (caar alist) (1+ article)))
1270 (setq alist (cdr alist)))
1272 ;; Prune off articles that we have already fetched.
1273 (unless (and (eq article (caar alist))
1275 ;; Skip headers preceeding this article
1278 (let* ((header (car headers)))
1280 (mail-header-number header)
1282 (setq headers (cdr headers)))
1284 ;; Add this article to the current set
1285 (setcar selected-sets (cons article (car selected-sets)))
1287 ;; Update the set size, when the set is too large start a
1288 ;; new one. I do this after adding the article as I want at
1289 ;; least one article in each set.
1290 (when (< gnus-agent-max-fetch-size
1291 (setq current-set-size
1293 (if (= header-number article)
1294 (let ((char-size (mail-header-chars
1296 (if (<= char-size 0)
1297 ;; The char size was missing/invalid,
1298 ;; assume a worst-case situation of
1299 ;; 65 char/line. If the line count
1300 ;; is missing, arbitrarily assume a
1301 ;; size of 1000 characters.
1302 (max (* 65 (mail-header-lines
1307 (setcar selected-sets (nreverse (car selected-sets)))
1308 (setq selected-sets (cons nil selected-sets)
1309 current-set-size 0))))
1311 (when (or (cdr selected-sets) (car selected-sets))
1312 (let* ((fetched-articles (list nil))
1313 (tail-fetched-articles fetched-articles)
1314 (dir (gnus-agent-group-pathname group))
1315 (date (time-to-days (current-time)))
1316 (case-fold-search t)
1319 (setcar selected-sets (nreverse (car selected-sets)))
1320 (setq selected-sets (nreverse selected-sets))
1322 (gnus-make-directory dir)
1323 (gnus-message 7 "Fetching articles for %s..." group)
1326 (while (setq articles (pop selected-sets))
1327 ;; Fetch the articles from the backend.
1328 (if (gnus-check-backend-function 'retrieve-articles group)
1329 (setq pos (gnus-retrieve-articles articles group))
1332 (while (setq article (pop articles))
1333 (gnus-message 10 "Fetching article %s for %s..."
1336 (gnus-backlog-request-article group article
1338 (gnus-request-article article group))
1339 (goto-char (point-max))
1340 (push (cons article (point)) pos)
1341 (insert-buffer-substring nntp-server-buffer)))
1343 nntp-server-buffer (point-min) (point-max))
1344 (setq pos (nreverse pos)))))
1345 ;; Then save these articles into the Agent.
1347 (set-buffer nntp-server-buffer)
1349 (narrow-to-region (cdar pos) (or (cdadr pos) (point-max)))
1350 (goto-char (point-min))
1351 (unless (eobp) ;; Don't save empty articles.
1352 (when (search-forward "\n\n" nil t)
1353 (when (search-backward "\nXrefs: " nil t)
1354 ;; Handle cross posting.
1355 (goto-char (match-end 0)) ; move to end of header name
1356 (skip-chars-forward "^ ") ; skip server name
1357 (skip-chars-forward " ")
1359 (while (looking-at "\\([^: \n]+\\):\\([0-9]+\\) *")
1360 (push (cons (buffer-substring (match-beginning 1)
1363 (buffer-substring (match-beginning 2)
1366 (goto-char (match-end 0)))
1367 (gnus-agent-crosspost crosses (caar pos) date)))
1368 (goto-char (point-min))
1369 (if (not (re-search-forward
1370 "^Message-ID: *<\\([^>\n]+\\)>" nil t))
1371 (setq id "No-Message-ID-in-article")
1372 (setq id (buffer-substring
1373 (match-beginning 1) (match-end 1))))
1374 (let ((coding-system-for-write
1375 gnus-agent-file-coding-system))
1376 (write-region (point-min) (point-max)
1377 (concat dir (number-to-string (caar pos)))
1380 (gnus-agent-append-to-list
1381 tail-fetched-articles (caar pos)))
1383 (setq pos (cdr pos)))))
1385 (gnus-agent-save-alist group (cdr fetched-articles) date)
1386 (gnus-message 7 ""))
1387 (cdr fetched-articles))))))
1389 (defun gnus-agent-crosspost (crosses article &optional date)
1390 (setq date (or date t))
1392 (let (gnus-agent-article-alist group alist beg end)
1394 (set-buffer gnus-agent-overview-buffer)
1395 (when (nnheader-find-nov-line article)
1398 (setq end (progn (forward-line 1) (point)))))
1400 (setq group (caar crosses))
1401 (unless (setq alist (assoc group gnus-agent-group-alist))
1402 (push (setq alist (list group (gnus-agent-load-alist (caar crosses))))
1403 gnus-agent-group-alist))
1404 (setcdr alist (cons (cons (cdar crosses) date) (cdr alist)))
1406 (set-buffer (gnus-get-buffer-create (format " *Gnus agent overview %s*"
1408 (when (= (point-max) (point-min))
1409 (push (cons group (current-buffer)) gnus-agent-buffer-alist)
1411 (nnheader-insert-file-contents
1412 (gnus-agent-article-name ".overview" group))))
1413 (nnheader-find-nov-line (string-to-number (cdar crosses)))
1414 (insert (string-to-number (cdar crosses)))
1415 (insert-buffer-substring gnus-agent-overview-buffer beg end)
1416 (gnus-agent-check-overview-buffer))
1417 (setq crosses (cdr crosses)))))
1419 (defun gnus-agent-backup-overview-buffer ()
1420 (when gnus-newsgroup-name
1421 (let ((root (gnus-agent-article-name ".overview" gnus-newsgroup-name))
1424 (while (file-exists-p
1425 (setq name (concat root "~"
1426 (int-to-string (setq cnt (1+ cnt))) "~"))))
1427 (write-region (point-min) (point-max) name nil 'no-msg)
1428 (gnus-message 1 "Created backup copy of overview in %s." name)))
1431 (defun gnus-agent-check-overview-buffer (&optional buffer)
1432 "Check the overview file given for sanity.
1433 In particular, checks that the file is sorted by article number
1434 and that there are no duplicates."
1439 (set-buffer buffer))
1442 (goto-char (point-min))
1444 (while (< (point) (point-max))
1446 (cur (condition-case nil
1447 (read (current-buffer))
1450 ((or (not (integerp cur))
1451 (not (eq (char-after) ?\t)))
1453 (setq backed-up (gnus-agent-backup-overview-buffer)))
1455 "Overview buffer contains garbage '%s'."
1457 p (gnus-point-at-eol))))
1460 (setq backed-up (gnus-agent-backup-overview-buffer)))
1462 "Duplicate overview line for %d" cur)
1463 (delete-region (point) (progn (forward-line 1) (point))))
1466 (setq backed-up (gnus-agent-backup-overview-buffer)))
1467 (gnus-message 1 "Overview buffer not sorted!")
1468 (sort-numeric-fields 1 (point-min) (point-max))
1469 (goto-char (point-min))
1472 (setq prev-num cur)))
1473 (forward-line 1)))))))
1475 (defun gnus-agent-flush-cache ()
1477 (while gnus-agent-buffer-alist
1478 (set-buffer (cdar gnus-agent-buffer-alist))
1479 (let ((coding-system-for-write
1480 gnus-agent-file-coding-system))
1481 (write-region (point-min) (point-max)
1482 (gnus-agent-article-name ".overview"
1483 (caar gnus-agent-buffer-alist))
1485 (setq gnus-agent-buffer-alist (cdr gnus-agent-buffer-alist)))
1486 (while gnus-agent-group-alist
1487 (with-temp-file (gnus-agent-article-name
1488 ".agentview" (caar gnus-agent-group-alist))
1489 (princ (cdar gnus-agent-group-alist))
1491 (princ 1 (current-buffer))
1493 (setq gnus-agent-group-alist (cdr gnus-agent-group-alist)))))
1495 (defun gnus-agent-find-parameter (group symbol)
1496 "Search for GROUPs SYMBOL in the group's parameters, the group's
1497 topic parameters, the group's category, or the customizable
1498 variables. Returns the first non-nil value found."
1499 (or (gnus-group-find-parameter group symbol t)
1500 (gnus-group-parameter-value (cdr (gnus-group-category group)) symbol t)
1504 '((agent-short-article . gnus-agent-short-article)
1505 (agent-long-article . gnus-agent-long-article)
1506 (agent-low-score . gnus-agent-low-score)
1507 (agent-high-score . gnus-agent-high-score)
1508 (agent-days-until-old . gnus-agent-expire-days)
1509 (agent-enable-expiration
1510 . gnus-agent-enable-expiration)
1511 (agent-predicate . gnus-agent-predicate)))))))
1513 (defun gnus-agent-fetch-headers (group &optional force)
1514 "Fetch interesting headers into the agent. The group's overview
1515 file will be updated to include the headers while a list of available
1516 article numbers will be returned."
1517 (let* ((fetch-all (and gnus-agent-consider-all-articles
1518 ;; Do not fetch all headers if the predicate
1519 ;; implies that we only consider unread articles.
1520 (not (gnus-predicate-implies-unread
1521 (gnus-agent-find-parameter group
1522 'agent-predicate)))))
1523 (articles (if fetch-all
1524 (gnus-uncompress-range (gnus-active group))
1525 (gnus-list-of-unread-articles group)))
1526 (gnus-decode-encoded-word-function 'identity)
1527 (file (gnus-agent-article-name ".overview" group)))
1530 ;; Add articles with marks to the list of article headers we want to
1531 ;; fetch. Don't fetch articles solely on the basis of a recent or seen
1532 ;; mark, but do fetch recent or seen articles if they have other, more
1533 ;; interesting marks. (We have to fetch articles with boring marks
1534 ;; because otherwise the agent will remove their marks.)
1535 (dolist (arts (gnus-info-marks (gnus-get-info group)))
1536 (unless (memq (car arts) '(seen recent killed cache))
1537 (setq articles (gnus-range-add articles (cdr arts)))))
1538 (setq articles (sort (gnus-uncompress-sequence articles) '<)))
1540 ;; At this point, I have the list of articles to consider for
1541 ;; fetching. This is the list that I'll return to my caller. Some
1542 ;; of these articles may have already been fetched. That's OK as
1543 ;; the fetch article code will filter those out. Internally, I'll
1544 ;; filter this list to just those articles whose headers need to
1546 (let ((articles articles))
1547 ;; Remove known articles.
1548 (when (and (or gnus-agent-cache
1550 (gnus-agent-load-alist group))
1551 ;; Remove articles marked as downloaded.
1553 ;; I want to fetch all headers in the active range.
1554 ;; Therefore, exclude only those headers that are in the
1556 ;; NOTE: This is probably NOT what I want to do after
1557 ;; agent expiration in this group.
1558 (setq articles (gnus-agent-uncached-articles articles group))
1560 ;; I want to only fetch those headers that have never been
1561 ;; fetched. Therefore, exclude all headers that are, or
1562 ;; WERE, in the article alist.
1563 (let ((low (1+ (caar (last gnus-agent-article-alist))))
1564 (high (cdr (gnus-active group))))
1565 ;; Low can be greater than High when the same group is
1566 ;; fetched twice in the same session {The first fetch will
1567 ;; fill the article alist such that (last
1568 ;; gnus-agent-article-alist) equals (cdr (gnus-active
1569 ;; group))}. The addition of one(the 1+ above) then
1570 ;; forces Low to be greater than High. When this happens,
1571 ;; gnus-list-range-intersection returns nil which
1572 ;; indicates that no headers need to be fetched. -- Kevin
1573 (setq articles (gnus-list-range-intersection
1574 articles (list (cons low high)))))))
1577 10 "gnus-agent-fetch-headers: undownloaded articles are '%s'"
1578 (gnus-compress-sequence articles t))
1581 (set-buffer nntp-server-buffer)
1585 (gnus-message 7 "Fetching headers for %s..." group)
1588 (gnus-make-directory (nnheader-translate-file-chars
1589 (file-name-directory file) t))
1591 (unless (eq 'nov (gnus-retrieve-headers articles group))
1592 (nnvirtual-convert-headers))
1593 (gnus-agent-check-overview-buffer)
1594 ;; Move these headers to the overview buffer so that
1595 ;; gnus-agent-braid-nov can merge them with the contents
1598 gnus-agent-overview-buffer (point-min) (point-max))
1599 (when (file-exists-p file)
1600 (gnus-agent-braid-nov group articles file))
1601 (let ((coding-system-for-write
1602 gnus-agent-file-coding-system))
1603 (gnus-agent-check-overview-buffer)
1604 (write-region (point-min) (point-max) file nil 'silent))
1605 (gnus-agent-save-alist group articles nil)
1609 (nnheader-insert-file-contents file)))))
1612 (defsubst gnus-agent-copy-nov-line (article)
1614 (set-buffer gnus-agent-overview-buffer)
1615 (while (and (not (eobp))
1616 (< (setq art (read (current-buffer))) article))
1620 (not (eq article art)))
1621 (set-buffer nntp-server-buffer)
1623 (setq e (progn (forward-line 1) (point)))
1624 (set-buffer nntp-server-buffer)
1625 (insert-buffer-substring gnus-agent-overview-buffer b e))))
1627 (defun gnus-agent-braid-nov (group articles file)
1628 "Merge agent overview data with given file.
1629 Takes headers for ARTICLES from `gnus-agent-overview-buffer' and the given
1630 FILE and places the combined headers into `nntp-server-buffer'."
1632 (set-buffer gnus-agent-overview-buffer)
1633 (goto-char (point-min))
1634 (set-buffer nntp-server-buffer)
1636 (nnheader-insert-file-contents file)
1637 (goto-char (point-max))
1639 (unless (looking-at "[0-9]+\t")
1640 ;; Remove corrupted lines
1642 1 "Overview %s is corrupted. Removing corrupted lines..." file)
1643 (goto-char (point-min))
1645 (if (looking-at "[0-9]+\t")
1647 (delete-region (point) (progn (forward-line 1) (point)))))
1649 (unless (or (= (point-min) (point-max))
1650 (< (setq last (read (current-buffer))) (car articles)))
1651 ;; We do it the hard way.
1652 (when (nnheader-find-nov-line (car articles))
1653 ;; Replacing existing NOV entry
1654 (delete-region (point) (progn (forward-line 1) (point))))
1655 (gnus-agent-copy-nov-line (pop articles))
1659 (while (let ((art (read (current-buffer))))
1660 (cond ((< art (car articles))
1663 ((= art (car articles))
1666 (point) (progn (forward-line 1) (point)))
1672 (gnus-agent-copy-nov-line (pop articles)))))
1674 ;; Copy the rest lines
1675 (set-buffer nntp-server-buffer)
1676 (goto-char (point-max))
1679 (set-buffer gnus-agent-overview-buffer)
1681 (while (<= (read (current-buffer)) last)
1684 (setq start (point))
1685 (set-buffer nntp-server-buffer))
1686 (insert-buffer-substring gnus-agent-overview-buffer start))))
1688 ;; Keeps the compiler from warning about the free variable in
1689 ;; gnus-agent-read-agentview.
1691 (defvar gnus-agent-read-agentview))
1693 (defun gnus-agent-load-alist (group)
1694 "Load the article-state alist for GROUP."
1695 ;; Bind free variable that's used in `gnus-agent-read-agentview'.
1696 (let ((gnus-agent-read-agentview group))
1697 (setq gnus-agent-article-alist
1698 (gnus-cache-file-contents
1699 (gnus-agent-article-name ".agentview" group)
1700 'gnus-agent-file-loading-cache
1701 'gnus-agent-read-agentview))))
1703 ;; Save format may be either 1 or 2. Two is the new, compressed
1704 ;; format that is still being tested. Format 1 is uncompressed but
1705 ;; known to be reliable.
1706 (defconst gnus-agent-article-alist-save-format 2)
1708 (defun gnus-agent-read-agentview (file)
1709 "Load FILE and do a `read' there."
1712 (nnheader-insert-file-contents file)
1713 (goto-char (point-min))
1714 (let ((alist (read (current-buffer)))
1715 (version (condition-case nil (read (current-buffer))
1721 (let ((inhibit-quit t)
1723 (gnus-agent-open-history)
1724 (set-buffer (gnus-agent-history-buffer))
1725 (goto-char (point-min))
1727 (if (and (looking-at
1728 "[^\t\n]+\t\\([0-9]+\\)\t\\([^ \n]+\\) \\([0-9]+\\)")
1729 (string= (match-string 2)
1730 gnus-agent-read-agentview)
1731 (setq entry (assoc (string-to-number (match-string 3)) alist)))
1732 (setcdr entry (string-to-number (match-string 1))))
1734 (gnus-agent-close-history)
1735 (setq changed-version t)))
1737 (setq changed-version (not (= 1 gnus-agent-article-alist-save-format))))
1742 (let ((state (car comp-list))
1743 (sequence (gnus-uncompress-sequence
1745 (mapcar (lambda (article-id)
1746 (setq uncomp (cons (cons article-id state) uncomp)))
1749 (setq alist (sort uncomp
1750 (lambda (first second)
1751 (< (car first) (car second))))))))
1752 (when changed-version
1753 (let ((gnus-agent-article-alist alist))
1754 (gnus-agent-save-alist gnus-agent-read-agentview)))
1757 (defun gnus-agent-save-alist (group &optional articles state dir)
1758 "Save the article-state alist for GROUP."
1759 (let* ((file-name-coding-system nnmail-pathname-coding-system)
1760 (prev (cons nil gnus-agent-article-alist))
1762 print-level print-length item article)
1763 (while (setq article (pop articles))
1764 (while (and (cdr prev)
1765 (< (caadr prev) article))
1766 (setq prev (cdr prev)))
1769 (setcdr prev (list (cons article state))))
1770 ((> (caadr prev) article)
1771 (setcdr prev (cons (cons article state) (cdr prev))))
1772 ((= (caadr prev) article)
1773 (setcdr (cadr prev) state)))
1774 (setq prev (cdr prev)))
1775 (setq gnus-agent-article-alist (cdr all))
1777 (gnus-make-directory dir)
1778 (gnus-make-directory (gnus-agent-article-name "" group)))
1779 (with-temp-file (if dir
1780 (expand-file-name ".agentview" dir)
1781 (gnus-agent-article-name ".agentview" group))
1782 (cond ((eq gnus-agent-article-alist-save-format 1)
1783 (princ gnus-agent-article-alist (current-buffer)))
1784 ((eq gnus-agent-article-alist-save-format 2)
1785 (let ((compressed nil))
1786 (mapcar (lambda (pair)
1787 (let* ((article-id (car pair))
1788 (day-of-download (cdr pair))
1789 (comp-list (assq day-of-download compressed)))
1792 (cons article-id (cdr comp-list)))
1794 (cons (list day-of-download article-id)
1796 nil)) gnus-agent-article-alist)
1797 (mapcar (lambda (comp-list)
1799 (gnus-compress-sequence
1800 (nreverse (cdr comp-list)))))
1802 (princ compressed (current-buffer)))))
1804 (princ gnus-agent-article-alist-save-format (current-buffer))
1807 (defun gnus-agent-article-name (article group)
1808 (expand-file-name article
1809 (file-name-as-directory
1810 (gnus-agent-group-pathname group))))
1812 (defun gnus-agent-batch-confirmation (msg)
1813 "Show error message and return t."
1814 (gnus-message 1 msg)
1818 (defun gnus-agent-batch-fetch ()
1819 "Start Gnus and fetch session."
1822 (let ((gnus-agent-confirmation-function 'gnus-agent-batch-confirmation))
1823 (gnus-agent-fetch-session))
1826 (defun gnus-agent-fetch-session ()
1827 "Fetch all articles and headers that are eligible for fetching."
1829 (unless gnus-agent-covered-methods
1830 (error "No servers are covered by the Gnus agent"))
1831 (unless gnus-plugged
1832 (error "Can't fetch articles while Gnus is unplugged"))
1833 (let ((methods (gnus-agent-covered-methods))
1834 groups group gnus-command-method)
1837 (setq gnus-command-method (car methods))
1838 (when (and (or (gnus-server-opened gnus-command-method)
1839 (gnus-open-server gnus-command-method))
1840 (gnus-online gnus-command-method))
1841 (setq groups (gnus-groups-from-server (car methods)))
1842 (gnus-agent-with-fetch
1843 (while (setq group (pop groups))
1844 (when (<= (gnus-group-level group)
1845 gnus-agent-handle-level)
1846 (if (or debug-on-error debug-on-quit)
1847 (gnus-agent-fetch-group-1
1848 group gnus-command-method)
1850 (gnus-agent-fetch-group-1
1851 group gnus-command-method)
1853 (unless (funcall gnus-agent-confirmation-function
1854 (format "Error %s. Continue? "
1855 (error-message-string err)))
1856 (error "Cannot fetch articles into the Gnus agent")))
1858 (unless (funcall gnus-agent-confirmation-function
1860 "Quit fetching session %s. Continue? "
1861 (error-message-string err)))
1863 "Cannot fetch articles into the Gnus agent")))))))))
1864 (setq methods (cdr methods)))
1865 (gnus-run-hooks 'gnus-agent-fetched-hook)
1866 (gnus-message 6 "Finished fetching articles into the Gnus agent"))))
1868 (defun gnus-agent-fetch-group-1 (group method)
1870 (let ((gnus-command-method method)
1871 (gnus-newsgroup-name group)
1872 (gnus-newsgroup-dependencies gnus-newsgroup-dependencies)
1873 (gnus-newsgroup-headers gnus-newsgroup-headers)
1874 (gnus-newsgroup-scored gnus-newsgroup-scored)
1875 (gnus-use-cache gnus-use-cache)
1876 (gnus-summary-expunge-below gnus-summary-expunge-below)
1877 (gnus-summary-mark-below gnus-summary-mark-below)
1878 (gnus-orphan-score gnus-orphan-score)
1879 ;; Maybe some other gnus-summary local variables should also
1885 category predicate info marks score-param
1887 (unless (gnus-check-group group)
1888 (error "Can't open server for %s" group))
1891 (when (or gnus-newsgroup-active
1893 (gnus-activate-group group))
1894 (let ((marked-articles gnus-newsgroup-downloadable))
1895 ;; Identify the articles marked for download
1896 (unless gnus-newsgroup-active
1897 ;; The variable gnus-newsgroup-active was selected as I need
1898 ;; a gnus-summary local variable that is NOT bound to any
1899 ;; value (its global value should default to nil).
1900 (dolist (mark gnus-agent-download-marks)
1901 (let ((arts (cdr (assq mark (gnus-info-marks
1902 (setq info (gnus-get-info group)))))))
1904 (setq marked-articles (nconc (gnus-uncompress-range arts)
1907 (setq marked-articles (sort marked-articles '<))
1909 ;; Fetch any new articles from the server
1910 (setq articles (gnus-agent-fetch-headers group))
1912 ;; Merge new articles with marked
1913 (setq articles (sort (append marked-articles articles) '<))
1916 ;; Parse them and see which articles we want to fetch.
1917 (setq gnus-newsgroup-dependencies
1918 (or gnus-newsgroup-dependencies
1919 (make-vector (length articles) 0)))
1920 (setq gnus-newsgroup-headers
1921 (or gnus-newsgroup-headers
1922 (gnus-get-newsgroup-headers-xover articles nil nil
1924 ;; `gnus-agent-overview-buffer' may be killed for
1925 ;; timeout reason. If so, recreate it.
1926 (gnus-agent-create-buffer)
1928 ;; Figure out how to select articles in this group
1929 (setq category (gnus-group-category group))
1933 (gnus-agent-find-parameter group 'agent-predicate)))
1935 ;; If the selection predicate requires scoring, score each header
1936 (unless (memq predicate '(gnus-agent-true gnus-agent-false))
1938 (gnus-agent-find-parameter group 'agent-score-file)))
1939 ;; Translate score-param into real one
1942 ((eq score-param 'file)
1943 (setq score-param (gnus-all-score-files group)))
1944 ((stringp (car score-param)))
1946 (setq score-param (list (list score-param)))))
1948 (gnus-score-headers score-param))))
1950 (unless (and (eq predicate 'gnus-agent-false)
1951 (not marked-articles))
1952 (let ((arts (list nil)))
1953 (let ((arts-tail arts)
1954 (alist (gnus-agent-load-alist group))
1955 (marked-articles marked-articles)
1956 (gnus-newsgroup-headers gnus-newsgroup-headers))
1957 (while (setq gnus-headers (pop gnus-newsgroup-headers))
1958 (let ((num (mail-header-number gnus-headers)))
1959 ;; Determine if this article is already in the cache
1961 (> num (caar alist)))
1962 (setq alist (cdr alist)))
1964 (unless (and (eq num (caar alist))
1967 ;; Determine if this article was marked for download.
1968 (while (and marked-articles
1969 (> num (car marked-articles)))
1970 (setq marked-articles
1971 (cdr marked-articles)))
1973 ;; When this article is marked, or selected by the
1974 ;; predicate, add it to the download list
1975 (when (or (eq num (car marked-articles))
1978 (assq num gnus-newsgroup-scored))
1979 gnus-summary-default-score))
1980 (gnus-agent-long-article
1981 (gnus-agent-find-parameter
1982 group 'agent-long-article))
1983 (gnus-agent-short-article
1984 (gnus-agent-find-parameter
1985 group 'agent-short-article))
1986 (gnus-agent-low-score
1987 (gnus-agent-find-parameter
1988 group 'agent-low-score))
1989 (gnus-agent-high-score
1990 (gnus-agent-find-parameter
1991 group 'agent-high-score))
1992 (gnus-agent-expire-days
1993 (gnus-agent-find-parameter
1994 group 'agent-days-until-old)))
1995 (funcall predicate)))
1996 (gnus-agent-append-to-list arts-tail num))))))
1998 (let (fetched-articles)
1999 ;; Fetch all selected articles
2000 (setq gnus-newsgroup-undownloaded
2001 (gnus-sorted-ndifference
2002 gnus-newsgroup-undownloaded
2003 (setq fetched-articles
2005 (gnus-agent-fetch-articles group (cdr arts))
2008 (let ((unfetched-articles
2009 (gnus-sorted-ndifference (cdr arts) fetched-articles)))
2010 (if gnus-newsgroup-active
2011 ;; Update the summary buffer
2013 (dolist (article marked-articles)
2014 (gnus-summary-set-agent-mark article t))
2015 (dolist (article fetched-articles)
2016 (if gnus-agent-mark-unread-after-downloaded
2017 (gnus-summary-mark-article
2018 article gnus-unread-mark))
2019 (when (gnus-summary-goto-subject article nil t)
2020 (gnus-summary-update-download-mark article)))
2021 (dolist (article unfetched-articles)
2022 (gnus-summary-mark-article
2023 article gnus-canceled-mark)))
2025 ;; Update the group buffer.
2027 ;; When some, or all, of the marked articles came
2028 ;; from the download mark. Remove that mark. I
2029 ;; didn't do this earlier as I only want to remove
2030 ;; the marks after the fetch is completed.
2032 (dolist (mark gnus-agent-download-marks)
2033 (when (eq mark 'download)
2035 (assq mark (gnus-info-marks
2036 (setq info (gnus-get-info group))))))
2037 (when (cdr marked-arts)
2039 (delq marked-arts (gnus-info-marks info)))
2040 (gnus-info-set-marks info marks)))))
2041 (let ((read (gnus-info-read
2042 (or info (setq info (gnus-get-info group))))))
2044 info (gnus-add-to-range read unfetched-articles)))
2046 (gnus-group-update-group group t)
2050 (concat "(gnus-group-set-info '"
2051 (gnus-prin1-to-string info)
2055 ;;; Agent Category Mode
2058 (defvar gnus-category-mode-hook nil
2059 "Hook run in `gnus-category-mode' buffers.")
2061 (defvar gnus-category-line-format " %(%20c%): %g\n"
2062 "Format of category lines.
2064 Valid specifiers include:
2065 %c Topic name (string)
2066 %g The number of groups in the topic (integer)
2068 General format specifiers can also be used. See Info node
2069 `(gnus)Formatting Variables'.")
2071 (defvar gnus-category-mode-line-format "Gnus: %%b"
2072 "The format specification for the category mode line.")
2074 (defvar gnus-agent-predicate 'false
2075 "The selection predicate used when no other source is available.")
2077 (defvar gnus-agent-short-article 100
2078 "Articles that have fewer lines than this are short.")
2080 (defvar gnus-agent-long-article 200
2081 "Articles that have more lines than this are long.")
2083 (defvar gnus-agent-low-score 0
2084 "Articles that have a score lower than this have a low score.")
2086 (defvar gnus-agent-high-score 0
2087 "Articles that have a score higher than this have a high score.")
2090 ;;; Internal variables.
2092 (defvar gnus-category-buffer "*Agent Category*")
2094 (defvar gnus-category-line-format-alist
2095 `((?c gnus-tmp-name ?s)
2096 (?g gnus-tmp-groups ?d)))
2098 (defvar gnus-category-mode-line-format-alist
2099 `((?u user-defined ?s)))
2101 (defvar gnus-category-line-format-spec nil)
2102 (defvar gnus-category-mode-line-format-spec nil)
2104 (defvar gnus-category-mode-map nil)
2105 (put 'gnus-category-mode 'mode-class 'special)
2107 (unless gnus-category-mode-map
2108 (setq gnus-category-mode-map (make-sparse-keymap))
2109 (suppress-keymap gnus-category-mode-map)
2111 (gnus-define-keys gnus-category-mode-map
2112 "q" gnus-category-exit
2113 "k" gnus-category-kill
2114 "c" gnus-category-copy
2115 "a" gnus-category-add
2116 "e" gnus-agent-customize-category
2117 "p" gnus-category-edit-predicate
2118 "g" gnus-category-edit-groups
2119 "s" gnus-category-edit-score
2120 "l" gnus-category-list
2122 "\C-c\C-i" gnus-info-find-node
2123 "\C-c\C-b" gnus-bug))
2125 (defvar gnus-category-menu-hook nil
2126 "*Hook run after the creation of the menu.")
2128 (defun gnus-category-make-menu-bar ()
2129 (gnus-turn-off-edit-menu 'category)
2130 (unless (boundp 'gnus-category-menu)
2132 gnus-category-menu gnus-category-mode-map ""
2134 ["Add" gnus-category-add t]
2135 ["Kill" gnus-category-kill t]
2136 ["Copy" gnus-category-copy t]
2137 ["Edit category" gnus-agent-customize-category t]
2138 ["Edit predicate" gnus-category-edit-predicate t]
2139 ["Edit score" gnus-category-edit-score t]
2140 ["Edit groups" gnus-category-edit-groups t]
2141 ["Exit" gnus-category-exit t]))
2143 (gnus-run-hooks 'gnus-category-menu-hook)))
2145 (defun gnus-category-mode ()
2146 "Major mode for listing and editing agent categories.
2148 All normal editing commands are switched off.
2149 \\<gnus-category-mode-map>
2150 For more in-depth information on this mode, read the manual
2151 \(`\\[gnus-info-find-node]').
2153 The following commands are available:
2155 \\{gnus-category-mode-map}"
2157 (when (gnus-visual-p 'category-menu 'menu)
2158 (gnus-category-make-menu-bar))
2159 (kill-all-local-variables)
2160 (gnus-simplify-mode-line)
2161 (setq major-mode 'gnus-category-mode)
2162 (setq mode-name "Category")
2163 (gnus-set-default-directory)
2164 (setq mode-line-process nil)
2165 (use-local-map gnus-category-mode-map)
2166 (buffer-disable-undo)
2167 (setq truncate-lines t)
2168 (setq buffer-read-only t)
2169 (gnus-run-hooks 'gnus-category-mode-hook))
2171 (defalias 'gnus-category-position-point 'gnus-goto-colon)
2173 (defun gnus-category-insert-line (category)
2174 (let* ((gnus-tmp-name (format "%s" (car category)))
2175 (gnus-tmp-groups (length (gnus-agent-cat-groups category))))
2177 (gnus-add-text-properties
2181 (eval gnus-category-line-format-spec))
2182 (list 'gnus-category gnus-tmp-name))))
2184 (defun gnus-enter-category-buffer ()
2185 "Go to the Category buffer."
2187 (gnus-category-setup-buffer)
2188 (gnus-configure-windows 'category)
2189 (gnus-category-prepare))
2191 (defun gnus-category-setup-buffer ()
2192 (unless (get-buffer gnus-category-buffer)
2194 (set-buffer (gnus-get-buffer-create gnus-category-buffer))
2195 (gnus-category-mode))))
2197 (defun gnus-category-prepare ()
2198 (gnus-set-format 'category-mode)
2199 (gnus-set-format 'category t)
2200 (let ((alist gnus-category-alist)
2201 (buffer-read-only nil))
2204 (gnus-category-insert-line (pop alist)))
2205 (goto-char (point-min))
2206 (gnus-category-position-point)))
2208 (defun gnus-category-name ()
2209 (or (intern (get-text-property (gnus-point-at-bol) 'gnus-category))
2210 (error "No category on the current line")))
2212 (defun gnus-category-read ()
2213 "Read the category alist."
2214 (setq gnus-category-alist
2218 (nnheader-insert-file-contents (nnheader-concat gnus-agent-directory "lib/categories"))
2219 (goto-char (point-min))
2220 ;; This code isn't temp, it will be needed so long as
2221 ;; anyone may be migrating from an older version.
2223 ;; Once we're certain that people will not revert to an
2224 ;; earlier version, we can take out the old-list code in
2225 ;; gnus-category-write.
2226 (let* ((old-list (read (current-buffer)))
2227 (new-list (ignore-errors (read (current-buffer)))))
2230 ;; Convert from a positional list to an alist.
2240 '(agent-predicate agent-score-file agent-groups))))
2243 (list (gnus-agent-cat-make 'default 'short)))))
2245 (defun gnus-category-write ()
2246 "Write the category alist."
2247 (setq gnus-category-predicate-cache nil
2248 gnus-category-group-cache nil)
2249 (gnus-make-directory (nnheader-concat gnus-agent-directory "lib"))
2250 (with-temp-file (nnheader-concat gnus-agent-directory "lib/categories")
2251 ;; This prin1 is temporary. It exists so that people can revert
2252 ;; to an earlier version of gnus-agent.
2253 (prin1 (mapcar (lambda (c)
2255 (cdr (assoc 'agent-predicate c))
2256 (cdr (assoc 'agent-score-file c))
2257 (cdr (assoc 'agent-groups c))))
2258 gnus-category-alist)
2261 (prin1 gnus-category-alist (current-buffer))))
2263 (defun gnus-category-edit-predicate (category)
2264 "Edit the predicate for CATEGORY."
2265 (interactive (list (gnus-category-name)))
2266 (let ((info (assq category gnus-category-alist)))
2268 (gnus-agent-cat-predicate info)
2269 (format "Editing the select predicate for category %s" category)
2270 `(lambda (predicate)
2271 ;; Avoid run-time execution of setf form
2272 ;; (setf (gnus-agent-cat-predicate (assq ',category gnus-category-alist))
2274 ;; use its expansion instead:
2275 (gnus-agent-cat-set-property (assq ',category gnus-category-alist)
2276 'agent-predicate predicate)
2278 (gnus-category-write)
2279 (gnus-category-list)))))
2281 (defun gnus-category-edit-score (category)
2282 "Edit the score expression for CATEGORY."
2283 (interactive (list (gnus-category-name)))
2284 (let ((info (assq category gnus-category-alist)))
2286 (gnus-agent-cat-score-file info)
2287 (format "Editing the score expression for category %s" category)
2288 `(lambda (score-file)
2289 ;; Avoid run-time execution of setf form
2290 ;; (setf (gnus-agent-cat-score-file (assq ',category gnus-category-alist))
2292 ;; use its expansion instead:
2293 (gnus-agent-cat-set-property (assq ',category gnus-category-alist)
2294 'agent-score-file score-file)
2296 (gnus-category-write)
2297 (gnus-category-list)))))
2299 (defun gnus-category-edit-groups (category)
2300 "Edit the group list for CATEGORY."
2301 (interactive (list (gnus-category-name)))
2302 (let ((info (assq category gnus-category-alist)))
2304 (gnus-agent-cat-groups info)
2305 (format "Editing the group list for category %s" category)
2307 ;; Avoid run-time execution of setf form
2308 ;; (setf (gnus-agent-cat-groups (assq ',category gnus-category-alist))
2310 ;; use its expansion instead:
2311 (gnus-agent-set-cat-groups (assq ',category gnus-category-alist)
2314 (gnus-category-write)
2315 (gnus-category-list)))))
2317 (defun gnus-category-kill (category)
2318 "Kill the current category."
2319 (interactive (list (gnus-category-name)))
2320 (let ((info (assq category gnus-category-alist))
2321 (buffer-read-only nil))
2323 (setq gnus-category-alist (delq info gnus-category-alist))
2324 (gnus-category-write)))
2326 (defun gnus-category-copy (category to)
2327 "Copy the current category."
2328 (interactive (list (gnus-category-name) (intern (read-string "New name: "))))
2329 (let ((info (assq category gnus-category-alist)))
2330 (push (let ((newcat (gnus-copy-sequence info)))
2331 (setf (gnus-agent-cat-name newcat) to)
2332 (setf (gnus-agent-cat-groups newcat) nil)
2334 gnus-category-alist)
2335 (gnus-category-write)
2336 (gnus-category-list)))
2338 (defun gnus-category-add (category)
2339 "Create a new category."
2340 (interactive "SCategory name: ")
2341 (when (assq category gnus-category-alist)
2342 (error "Category %s already exists" category))
2343 (push (gnus-agent-cat-make category)
2344 gnus-category-alist)
2345 (gnus-category-write)
2346 (gnus-category-list))
2348 (defun gnus-category-list ()
2349 "List all categories."
2351 (gnus-category-prepare))
2353 (defun gnus-category-exit ()
2354 "Return to the group buffer."
2356 (kill-buffer (current-buffer))
2357 (gnus-configure-windows 'group t))
2359 ;; To avoid having 8-bit characters in the source file.
2360 (defvar gnus-category-not (list '! 'not (intern (format "%c" 172))))
2362 (defvar gnus-category-predicate-alist
2363 '((spam . gnus-agent-spam-p)
2364 (short . gnus-agent-short-p)
2365 (long . gnus-agent-long-p)
2366 (low . gnus-agent-low-scored-p)
2367 (high . gnus-agent-high-scored-p)
2368 (read . gnus-agent-read-p)
2369 (true . gnus-agent-true)
2370 (false . gnus-agent-false))
2371 "Mapping from short score predicate symbols to predicate functions.")
2373 (defun gnus-agent-spam-p ()
2374 "Say whether an article is spam or not."
2375 (unless gnus-agent-spam-hashtb
2376 (setq gnus-agent-spam-hashtb (gnus-make-hashtable 1000)))
2377 (if (not (equal (mail-header-references gnus-headers) ""))
2379 (let ((string (gnus-simplify-subject (mail-header-subject gnus-headers))))
2381 (gnus-gethash string gnus-agent-spam-hashtb)
2382 (gnus-sethash string t gnus-agent-spam-hashtb)))))
2384 (defun gnus-agent-short-p ()
2385 "Say whether an article is short or not."
2386 (< (mail-header-lines gnus-headers) gnus-agent-short-article))
2388 (defun gnus-agent-long-p ()
2389 "Say whether an article is long or not."
2390 (> (mail-header-lines gnus-headers) gnus-agent-long-article))
2392 (defun gnus-agent-low-scored-p ()
2393 "Say whether an article has a low score or not."
2394 (< gnus-score gnus-agent-low-score))
2396 (defun gnus-agent-high-scored-p ()
2397 "Say whether an article has a high score or not."
2398 (> gnus-score gnus-agent-high-score))
2400 (defun gnus-agent-read-p ()
2401 "Say whether an article is read or not."
2402 (gnus-member-of-range (mail-header-number gnus-headers)
2403 (gnus-info-read (gnus-get-info gnus-newsgroup-name))))
2405 (defun gnus-category-make-function (predicate)
2406 "Make a function from PREDICATE."
2407 (let ((func (gnus-category-make-function-1 predicate)))
2408 (if (and (= (length func) 1)
2409 (symbolp (car func)))
2411 (gnus-byte-compile `(lambda () ,func)))))
2413 (defun gnus-agent-true ()
2417 (defun gnus-agent-false ()
2421 (defun gnus-category-make-function-1 (predicate)
2422 "Make a function from PREDICATE."
2424 ;; Functions are just returned as is.
2425 ((or (symbolp predicate)
2426 (functionp predicate))
2427 `(,(or (cdr (assq predicate gnus-category-predicate-alist))
2429 ;; More complex predicate.
2432 ((memq (car predicate) '(& and))
2434 ((memq (car predicate) '(| or))
2436 ((memq (car predicate) gnus-category-not)
2438 ,@(mapcar 'gnus-category-make-function-1 (cdr predicate))))
2440 (error "Unknown predicate type: %s" predicate))))
2442 (defun gnus-get-predicate (predicate)
2443 "Return the function implementing PREDICATE."
2444 (or (cdr (assoc predicate gnus-category-predicate-cache))
2445 (let ((func (gnus-category-make-function predicate)))
2446 (setq gnus-category-predicate-cache
2447 (nconc gnus-category-predicate-cache
2448 (list (cons predicate func))))
2451 (defun gnus-predicate-implies-unread (predicate)
2452 "Say whether PREDICATE implies unread articles only.
2453 It is okay to miss some cases, but there must be no false positives.
2454 That is, if this predicate returns true, then indeed the predicate must
2455 return only unread articles."
2456 (eq t (gnus-function-implies-unread-1
2457 (gnus-category-make-function-1 predicate))))
2459 (defun gnus-function-implies-unread-1 (function)
2460 "Recursively evaluate a predicate function to determine whether it can select
2461 any read articles. Returns t if the function is known to never
2462 return read articles, nil when it is known to always return read
2463 articles, and t_nil when the function may return both read and unread
2465 (let ((func (car function))
2466 (args (mapcar 'gnus-function-implies-unread-1 (cdr function))))
2467 (cond ((eq func 'and)
2468 (cond ((memq t args) ; if any argument returns only unread articles
2469 ;; then that argument constrains the result to only unread articles.
2471 ((memq 't_nil args) ; if any argument is indeterminate
2472 ;; then the result is indeterminate
2475 (cond ((memq nil args) ; if any argument returns read articles
2476 ;; then that argument ensures that the results includes read articles.
2478 ((memq 't_nil args) ; if any argument is indeterminate
2479 ;; then that argument ensures that the results are indeterminate
2481 (t ; if all arguments return only unread articles
2482 ;; then the result returns only unread articles
2485 (cond ((eq (car args) 't_nil) ; if the argument is indeterminate
2486 ; then the result is indeterminate
2489 ; toggle the result to be the opposite of the argument
2491 ((eq func 'gnus-agent-read-p)
2492 nil) ; The read predicate NEVER returns unread articles
2493 ((eq func 'gnus-agent-false)
2494 t) ; The false predicate returns t as the empty set excludes all read articles
2495 ((eq func 'gnus-agent-true)
2496 nil) ; The true predicate ALWAYS returns read articles
2497 ((catch 'found-match
2498 (let ((alist gnus-category-predicate-alist))
2500 (if (eq func (cdar alist))
2501 (throw 'found-match t)
2502 (setq alist (cdr alist))))))
2503 't_nil) ; All other predicates return read and unread articles
2505 (error "Unknown predicate function: %s" function)))))
2507 (defun gnus-group-category (group)
2508 "Return the category GROUP belongs to."
2509 (unless gnus-category-group-cache
2510 (setq gnus-category-group-cache (gnus-make-hashtable 1000))
2511 (let ((cs gnus-category-alist)
2513 (while (setq cat (pop cs))
2514 (setq groups (gnus-agent-cat-groups cat))
2516 (gnus-sethash (pop groups) cat gnus-category-group-cache)))))
2517 (or (gnus-gethash group gnus-category-group-cache)
2518 (assq 'default gnus-category-alist)))
2520 (defun gnus-agent-expire-group (group &optional articles force)
2521 "Expire all old articles in GROUP.
2522 If you want to force expiring of certain articles, this function can
2523 take ARTICLES, and FORCE parameters as well.
2525 The articles on which the expiration process runs are selected as follows:
2526 if ARTICLES is null, all read and unmarked articles.
2527 if ARTICLES is t, all articles.
2528 if ARTICLES is a list, just those articles.
2529 FORCE is equivalent to setting the expiration predicates to true."
2531 (list (let ((def (or (gnus-group-group-name)
2532 gnus-newsgroup-name)))
2533 (let ((select (read-string (if def
2534 (concat "Group Name ("
2537 (if (and (equal "" select)
2543 (gnus-agent-expire articles group force)
2544 (let ( ;; Bind gnus-agent-expire-stats to enable tracking of
2545 ;; expiration statistics of this single group
2546 (gnus-agent-expire-stats (list 0 0 0.0)))
2547 (if (or (not (eq articles t))
2549 (concat "Are you sure that you want to "
2550 "expire all articles in " group ".")))
2551 (let ((gnus-command-method (gnus-find-method-for-group group))
2552 (overview (gnus-get-buffer-create " *expire overview*"))
2555 (let ((active-file (gnus-agent-lib-file "active")))
2556 (when (file-exists-p active-file)
2558 (nnheader-insert-file-contents active-file)
2559 (gnus-active-to-gnus-format
2561 (setq orig (gnus-make-hashtable
2562 (count-lines (point-min) (point-max))))))
2564 (gnus-agent-expire-group-1
2565 group overview (gnus-gethash-safe group orig)
2567 (gnus-agent-write-active active-file orig t)))
2568 (kill-buffer overview))))
2569 (gnus-message 4 (gnus-agent-expire-done-message)))))
2571 (defun gnus-agent-expire-group-1 (group overview active articles force)
2572 ;; Internal function - requires caller to have set
2573 ;; gnus-command-method, initialized overview buffer, and to have
2574 ;; provided a non-nil active
2576 (let ((dir (gnus-agent-group-pathname group)))
2577 (when (boundp 'gnus-agent-expire-current-dirs)
2578 (set 'gnus-agent-expire-current-dirs
2580 (symbol-value 'gnus-agent-expire-current-dirs))))
2582 (if (and (not force)
2583 (eq 'DISABLE (gnus-agent-find-parameter group
2584 'agent-enable-expiration)))
2585 (gnus-message 5 "Expiry skipping over %s" group)
2586 (gnus-message 5 "Expiring articles in %s" group)
2587 (gnus-agent-load-alist group)
2588 (let* ((stats (if (boundp 'gnus-agent-expire-stats)
2589 ;; Use the list provided by my caller
2590 (symbol-value 'gnus-agent-expire-stats)
2591 ;; otherwise use my own temporary list
2593 (info (gnus-get-info group))
2594 (alist gnus-agent-article-alist)
2595 (day (- (time-to-days (current-time))
2596 (gnus-agent-find-parameter group 'agent-days-until-old)))
2597 (specials (if (and alist
2599 ;; This could be a bit of a problem. I need to
2600 ;; keep the last article to avoid refetching
2601 ;; headers when using nntp in the backend. At
2602 ;; the same time, if someone uses a backend
2603 ;; that supports article moving then I may have
2604 ;; to remove the last article to complete the
2605 ;; move. Right now, I'm going to assume that
2606 ;; FORCE overrides specials.
2607 (list (caar (last alist)))))
2608 (unreads ;; Articles that are excluded from the
2609 ;; expiration process
2610 (cond (gnus-agent-expire-all
2611 ;; All articles are marked read by global decree
2614 ;; All articles are marked read by function
2618 ;; Unread articles are marked protected from
2619 ;; expiration Don't call
2620 ;; gnus-list-of-unread-articles as it returns
2621 ;; articles that have not been fetched into the
2624 (gnus-agent-unread-articles group)))
2626 ;; All articles EXCEPT those named by the caller
2627 ;; are protected from expiration
2628 (gnus-sorted-difference
2629 (gnus-uncompress-range
2631 (caar (last alist))))
2632 (sort articles '<)))))
2633 (marked ;; More articles that are excluded from the
2634 ;; expiration process
2635 (cond (gnus-agent-expire-all
2636 ;; All articles are unmarked by global decree
2639 ;; All articles are unmarked by function
2643 ;; All articles may as well be unmarked as the
2644 ;; unreads list already names the articles we are
2648 ;; Ticked and/or dormant articles are excluded
2651 (gnus-uncompress-range
2652 (cdr (assq 'tick (gnus-info-marks info))))
2653 (gnus-uncompress-range
2655 (gnus-info-marks info))))))))
2656 (nov-file (concat dir ".overview"))
2662 ;; The normal article alist contains elements that look like
2663 ;; (article# . fetch_date) I need to combine other
2664 ;; information with this list. For example, a flag indicating
2665 ;; that a particular article MUST BE KEPT. To do this, I'm
2666 ;; going to transform the elements to look like (article#
2667 ;; fetch_date keep_flag NOV_entry_marker) Later, I'll reverse
2668 ;; the process to generate the expired article alist.
2670 ;; Convert the alist elements to (article# fetch_date nil
2672 (setq dlist (mapcar (lambda (e)
2673 (list (car e) (cdr e) nil nil)) alist))
2675 ;; Convert the keep lists to elements that look like (article#
2676 ;; nil keep_flag nil) then append it to the expanded dlist
2677 ;; These statements are sorted by ascending precidence of the
2679 (setq dlist (nconc dlist
2681 (list e nil 'unread nil))
2683 (setq dlist (nconc dlist
2685 (list e nil 'marked nil))
2687 (setq dlist (nconc dlist
2689 (list e nil 'special nil))
2692 (set-buffer overview)
2694 (buffer-disable-undo)
2695 (when (file-exists-p nov-file)
2696 (gnus-message 7 "gnus-agent-expire: Loading overview...")
2697 (nnheader-insert-file-contents nov-file)
2698 (goto-char (point-min))
2701 (while (< (setq p (point)) (point-max))
2703 ;; If I successfully read an integer (the plus zero
2704 ;; ensures a numeric type), prepend a marker entry
2706 (push (list (+ 0 (read (current-buffer))) nil nil
2707 (set-marker (make-marker) p))
2710 (gnus-message 1 "gnus-agent-expire: read error \
2711 occurred when reading expression at %s in %s. Skipping to next \
2712 line." (point) nov-file)))
2713 ;; Whether I succeeded, or failed, it doesn't matter.
2714 ;; Move to the next line then try again.
2718 7 "gnus-agent-expire: Loading overview... Done"))
2719 (set-buffer-modified-p nil)
2721 ;; At this point, all of the information is in dlist. The
2722 ;; only problem is that much of it is spread across multiple
2723 ;; entries. Sort then MERGE!!
2724 (gnus-message 7 "gnus-agent-expire: Sorting entries... ")
2725 ;; If two entries have the same article-number then sort by
2726 ;; ascending keep_flag.
2733 (cond ((< (nth 0 a) (nth 0 b))
2735 ((> (nth 0 a) (nth 0 b))
2738 (let ((a (or (symbol-value (nth 2 a))
2740 (b (or (symbol-value (nth 2 b))
2743 (gnus-message 7 "gnus-agent-expire: Sorting entries... Done")
2744 (gnus-message 7 "gnus-agent-expire: Merging entries... ")
2745 (let ((dlist dlist))
2746 (while (cdr dlist) ; I'm not at the end-of-list
2747 (if (eq (caar dlist) (caadr dlist))
2748 (let ((first (cdr (car dlist)))
2749 (secnd (cdr (cadr dlist))))
2750 (setcar first (or (car first)
2751 (car secnd))) ; fetch_date
2752 (setq first (cdr first)
2754 (setcar first (or (car first)
2755 (car secnd))) ; Keep_flag
2756 (setq first (cdr first)
2758 (setcar first (or (car first)
2759 (car secnd))) ; NOV_entry_marker
2761 (setcdr dlist (cddr dlist)))
2762 (setq dlist (cdr dlist)))))
2763 (gnus-message 7 "gnus-agent-expire: Merging entries... Done")
2765 (let* ((len (float (length dlist)))
2769 (let ((new-completed (truncate (* 100.0
2770 (/ (setq cnt (1+ cnt))
2773 (when (> new-completed completed)
2774 (setq completed new-completed)
2775 (gnus-message 7 "%3d%% completed..." completed)))
2776 (let* ((entry (car dlist))
2777 (article-number (nth 0 entry))
2778 (fetch-date (nth 1 entry))
2779 (keep (nth 2 entry))
2780 (marker (nth 3 entry)))
2783 ;; Kept articles are unread, marked, or special.
2785 (gnus-agent-message 10
2786 "gnus-agent-expire: %s:%d: Kept %s article%s."
2787 group article-number keep (if fetch-date " and file" ""))
2789 (unless (file-exists-p
2790 (concat dir (number-to-string
2792 (setf (nth 1 entry) nil)
2793 (gnus-agent-message 3 "gnus-agent-expire cleared \
2794 download flag on %s:%d as the cached article file is missing."
2795 group (caar dlist)))
2797 (gnus-message 1 "gnus-agent-expire detected a \
2798 missing NOV entry. Run gnus-agent-regenerate-group to restore it.")))
2799 (gnus-agent-append-to-list
2801 (cons article-number fetch-date)))
2803 ;; The following articles are READ, UNMARKED, and
2804 ;; ORDINARY. See if they can be EXPIRED!!!
2807 ((not (integerp fetch-date))
2808 'read) ;; never fetched article (may expire
2810 ((not (file-exists-p
2811 (concat dir (number-to-string
2813 (setf (nth 1 entry) nil)
2814 'externally-expired) ;; Can't find the cached
2815 ;; article. Handle case
2816 ;; as though this article
2817 ;; was never fetched.
2819 ;; We now have the arrival day, so we see
2820 ;; whether it's old enough to be expired.
2826 ;; I found some reason to expire this entry.
2828 (let ((actions nil))
2829 (when (memq type '(forced expired))
2830 (ignore-errors ; Just being paranoid.
2831 (let ((file-name (concat dir (number-to-string
2833 (incf (nth 2 stats) (nth 7 (file-attributes file-name)))
2834 (incf (nth 1 stats))
2835 (delete-file file-name))
2836 (push "expired cached article" actions))
2837 (setf (nth 1 entry) nil)
2841 (push "NOV entry removed" actions)
2844 (incf (nth 0 stats))
2846 (let ((from (gnus-point-at-bol))
2847 (to (progn (forward-line 1) (point))))
2848 (incf (nth 2 stats) (- to from))
2849 (delete-region from to)))
2851 ;; If considering all articles is set, I can only
2852 ;; expire article IDs that are no longer in the
2853 ;; active range (That is, articles that preceed the
2854 ;; first article in the new alist).
2855 (if (and gnus-agent-consider-all-articles
2856 (>= article-number (car active)))
2857 ;; I have to keep this ID in the alist
2858 (gnus-agent-append-to-list
2859 tail-alist (cons article-number fetch-date))
2860 (push (format "Removed %s article number from \
2861 article alist" type) actions))
2864 (gnus-agent-message 8 "gnus-agent-expire: %s:%d: %s"
2865 group article-number
2866 (mapconcat 'identity actions ", ")))))
2869 10 "gnus-agent-expire: %s:%d: Article kept as \
2870 expiration tests failed." group article-number)
2871 (gnus-agent-append-to-list
2872 tail-alist (cons article-number fetch-date)))
2875 ;; Clean up markers as I want to recycle this buffer
2876 ;; over several groups.
2878 (set-marker marker nil))
2880 (setq dlist (cdr dlist))))
2882 (setq alist (cdr alist))
2884 (let ((inhibit-quit t))
2885 (unless (equal alist gnus-agent-article-alist)
2886 (setq gnus-agent-article-alist alist)
2887 (gnus-agent-save-alist group)
2889 ;; The active list changed, set the agent's active range
2890 ;; to match the beginning of the list.
2892 (setcar active (caar alist))))
2894 (when (buffer-modified-p)
2895 (let ((coding-system-for-write
2896 gnus-agent-file-coding-system))
2897 (gnus-make-directory dir)
2898 (write-region (point-min) (point-max) nov-file nil
2900 ;; clear the modified flag as that I'm not confused by
2901 ;; its status on the next pass through this routine.
2902 (set-buffer-modified-p nil)))
2904 (when (eq articles t)
2905 (gnus-summary-update-info))))))))
2907 (defun gnus-agent-expire (&optional articles group force)
2908 "Expire all old articles.
2909 If you want to force expiring of certain articles, this function can
2910 take ARTICLES, GROUP and FORCE parameters as well.
2912 The articles on which the expiration process runs are selected as follows:
2913 if ARTICLES is null, all read and unmarked articles.
2914 if ARTICLES is t, all articles.
2915 if ARTICLES is a list, just those articles.
2916 Setting GROUP will limit expiration to that group.
2917 FORCE is equivalent to setting the expiration predicates to true."
2921 (gnus-agent-expire-group group articles force)
2922 (if (or (not (eq articles t))
2923 (yes-or-no-p "Are you sure that you want to expire all \
2924 articles in every agentized group."))
2925 (let ((methods (gnus-agent-covered-methods))
2926 ;; Bind gnus-agent-expire-current-dirs to enable tracking
2927 ;; of agent directories.
2928 (gnus-agent-expire-current-dirs nil)
2929 ;; Bind gnus-agent-expire-stats to enable tracking of
2930 ;; expiration statistics across all groups
2931 (gnus-agent-expire-stats (list 0 0 0.0))
2932 gnus-command-method overview orig)
2933 (setq overview (gnus-get-buffer-create " *expire overview*"))
2935 (while (setq gnus-command-method (pop methods))
2936 (let ((active-file (gnus-agent-lib-file "active")))
2937 (when (file-exists-p active-file)
2939 (nnheader-insert-file-contents active-file)
2940 (gnus-active-to-gnus-format
2942 (setq orig (gnus-make-hashtable
2943 (count-lines (point-min) (point-max))))))
2944 (dolist (expiring-group (gnus-groups-from-server
2945 gnus-command-method))
2947 (gnus-gethash-safe expiring-group orig)))
2951 (gnus-agent-expire-group-1
2952 expiring-group overview active articles force)))))
2953 (gnus-agent-write-active active-file orig t))))
2954 (kill-buffer overview))
2955 (gnus-agent-expire-unagentized-dirs)
2956 (gnus-message 4 (gnus-agent-expire-done-message))))))
2958 (defun gnus-agent-expire-done-message ()
2959 (if (and (> gnus-verbose 4)
2960 (boundp 'gnus-agent-expire-stats))
2961 (let* ((stats (symbol-value 'gnus-agent-expire-stats))
2962 (size (nth 2 stats))
2963 (units '(B KB MB GB)))
2964 (while (and (> size 1024.0)
2966 (setq size (/ size 1024.0)
2969 (format "Expiry recovered %d NOV entries, deleted %d files,\
2976 (defun gnus-agent-expire-unagentized-dirs ()
2977 (when (and gnus-agent-expire-unagentized-dirs
2978 (boundp 'gnus-agent-expire-current-dirs))
2979 (let* ((keep (gnus-make-hashtable))
2980 ;; Formally bind gnus-agent-expire-current-dirs so that the
2981 ;; compiler will not complain about free references.
2982 (gnus-agent-expire-current-dirs
2983 (symbol-value 'gnus-agent-expire-current-dirs))
2986 (gnus-sethash gnus-agent-directory t keep)
2987 (while gnus-agent-expire-current-dirs
2988 (setq dir (pop gnus-agent-expire-current-dirs))
2989 (when (and (stringp dir)
2990 (file-directory-p dir))
2991 (while (not (gnus-gethash dir keep))
2992 (gnus-sethash dir t keep)
2993 (setq dir (file-name-directory (directory-file-name dir))))))
3000 "Given a directory, check it and its subdirectories for
3001 membership in the keep hash. If it isn't found, add
3003 (let ((files (directory-files d))
3005 (while (setq file (pop files))
3006 (cond ((equal file ".") ; Ignore self
3008 ((equal file "..") ; Ignore parent
3010 ((equal file ".overview")
3011 ;; Directory must contain .overview to be
3012 ;; agent's cache of a group.
3013 (let ((d (file-name-as-directory d))
3015 ;; Search ancestor's for last directory NOT
3016 ;; found in keep hash.
3017 (while (not (gnus-gethash
3018 (setq d (file-name-directory d)) keep))
3020 d (directory-file-name d)))
3021 ;; if ANY ancestor was NOT in keep hash and
3022 ;; it it's already in to-remove, add it to
3025 (not (member r to-remove)))
3026 (push r to-remove))))
3027 ((file-directory-p (setq file (nnheader-concat d file)))
3028 (funcall checker file)))))))))
3029 (funcall checker (expand-file-name gnus-agent-directory))
3031 (when (and to-remove
3032 (or gnus-expert-user
3034 "gnus-agent-expire has identified local directories that are\
3035 not currently required by any agentized group. Do you wish to consider\
3038 (let ((dir (pop to-remove)))
3039 (if (gnus-y-or-n-p (format "Delete %s? " dir))
3040 (let* (delete-recursive
3045 (if (file-directory-p f-or-d)
3047 (delete-directory f-or-d)
3050 (or (member f '("." ".."))
3051 (funcall delete-recursive
3054 (directory-files f-or-d))
3055 (delete-directory f-or-d)))
3056 (delete-file f-or-d)))))))
3057 (funcall delete-recursive dir))))))))))
3060 (defun gnus-agent-batch ()
3061 "Start Gnus, send queue and fetch session."
3063 (let ((init-file-user "")
3064 (gnus-always-read-dribble-file t))
3066 (let ((gnus-agent-confirmation-function 'gnus-agent-batch-confirmation))
3067 (gnus-group-send-queue)
3068 (gnus-agent-fetch-session)))
3070 (defun gnus-agent-unread-articles (group)
3071 (let* ((read (gnus-info-read (gnus-get-info group)))
3072 (known (gnus-agent-load-alist group))
3074 (tail-unread unread))
3075 (while (and known read)
3076 (let ((candidate (car (pop known))))
3077 (while (let* ((range (car read))
3078 (min (if (numberp range) range (car range)))
3079 (max (if (numberp range) range (cdr range))))
3080 (cond ((or (not min)
3082 (gnus-agent-append-to-list tail-unread candidate)
3085 (setq read (cdr read))
3086 ;; return t so that I always loop one more
3087 ;; time. If I just iterated off the end of
3088 ;; read, min will become nil and the current
3089 ;; candidate will be added to the unread list.
3092 (gnus-agent-append-to-list tail-unread (car (pop known))))
3095 (defun gnus-agent-uncached-articles (articles group &optional cached-header)
3096 "Restrict ARTICLES to numbers already fetched.
3097 Returns a sublist of ARTICLES that excludes thos article ids in GROUP
3098 that have already been fetched.
3099 If CACHED-HEADER is nil, articles are only excluded if the article itself
3102 ;; Logically equivalent to: (gnus-sorted-difference articles (mapcar
3103 ;; 'car gnus-agent-article-alist))
3105 ;; Functionally, I don't need to construct a temp list using mapcar.
3107 (if (and (or gnus-agent-cache (not gnus-plugged))
3108 (gnus-agent-load-alist group))
3109 (let* ((ref gnus-agent-article-alist)
3111 (uncached (list nil))
3112 (tail-uncached uncached))
3113 (while (and ref arts)
3114 (let ((v1 (car arts))
3116 (cond ((< v1 v2) ; v1 does not appear in the reference list
3117 (gnus-agent-append-to-list tail-uncached v1)
3118 (setq arts (cdr arts)))
3120 (unless (or cached-header (cdar ref)) ; v1 is already cached
3121 (gnus-agent-append-to-list tail-uncached v1))
3122 (setq arts (cdr arts))
3123 (setq ref (cdr ref)))
3124 (t ; reference article (v2) preceeds the list being filtered
3125 (setq ref (cdr ref))))))
3127 (gnus-agent-append-to-list tail-uncached (pop arts)))
3129 ;; if gnus-agent-load-alist fails, no articles are cached.
3132 (defun gnus-agent-retrieve-headers (articles group &optional fetch-old)
3134 (gnus-agent-create-buffer)
3135 (let ((gnus-decode-encoded-word-function 'identity)
3136 (file (gnus-agent-article-name ".overview" group))
3137 cached-articles uncached-articles)
3138 (gnus-make-directory (nnheader-translate-file-chars
3139 (file-name-directory file) t))
3141 ;; Populate temp buffer with known headers
3142 (when (file-exists-p file)
3143 (with-current-buffer gnus-agent-overview-buffer
3145 (let ((nnheader-file-coding-system
3146 gnus-agent-file-coding-system))
3147 (nnheader-insert-nov-file file (car articles)))))
3149 (if (setq uncached-articles (gnus-agent-uncached-articles articles group
3152 ;; Populate nntp-server-buffer with uncached headers
3153 (set-buffer nntp-server-buffer)
3155 (cond ((not (eq 'nov (let (gnus-agent) ; Turn off agent
3156 (gnus-retrieve-headers
3157 uncached-articles group fetch-old))))
3158 (nnvirtual-convert-headers))
3159 ((eq 'nntp (car gnus-current-select-method))
3160 ;; The author of gnus-get-newsgroup-headers-xover
3161 ;; reports that the XOVER command is commonly
3162 ;; unreliable. The problem is that recently
3163 ;; posted articles may not be entered into the
3164 ;; NOV database in time to respond to my XOVER
3167 ;; I'm going to use his assumption that the NOV
3168 ;; database is updated in order of ascending
3169 ;; article ID. Therefore, a response containing
3170 ;; article ID N implies that all articles from 1
3171 ;; to N-1 are up-to-date. Therefore, missing
3172 ;; articles in that range have expired.
3174 (set-buffer nntp-server-buffer)
3175 (let* ((fetched-articles (list nil))
3176 (tail-fetched-articles fetched-articles)
3177 (min (cond ((numberp fetch-old)
3178 (max 1 (- (car articles) fetch-old)))
3183 (max (car (last articles))))
3185 ;; Get the list of articles that were fetched
3186 (goto-char (point-min))
3187 (let ((pm (point-max)))
3188 (while (< (point) pm)
3189 (when (looking-at "[0-9]+\t")
3190 (gnus-agent-append-to-list
3191 tail-fetched-articles
3192 (read (current-buffer))))
3195 ;; Clip this list to the headers that will
3196 ;; actually be returned
3197 (setq fetched-articles (gnus-list-range-intersection
3198 (cdr fetched-articles)
3201 ;; Clip the uncached articles list to exclude
3202 ;; IDs after the last FETCHED header. The
3203 ;; excluded IDs may be fetchable using HEAD.
3204 (if (car tail-fetched-articles)
3205 (setq uncached-articles
3206 (gnus-list-range-intersection
3208 (cons (car uncached-articles)
3209 (car tail-fetched-articles)))))
3211 ;; Create the list of articles that were
3212 ;; "successfully" fetched. Success, in this
3213 ;; case, means that the ID should not be
3214 ;; fetched again. In the case of an expired
3215 ;; article, the header will not be fetched.
3216 (setq uncached-articles
3217 (gnus-sorted-nunion fetched-articles
3221 ;; Erase the temp buffer
3222 (set-buffer gnus-agent-overview-buffer)
3225 ;; Copy the nntp-server-buffer to the temp buffer
3226 (set-buffer nntp-server-buffer)
3227 (copy-to-buffer gnus-agent-overview-buffer (point-min) (point-max))
3229 ;; Merge the temp buffer with the known headers (found on
3230 ;; disk in FILE) into the nntp-server-buffer
3231 (when (and uncached-articles (file-exists-p file))
3232 (gnus-agent-braid-nov group uncached-articles file))
3234 ;; Save the new set of known headers to FILE
3235 (set-buffer nntp-server-buffer)
3236 (let ((coding-system-for-write
3237 gnus-agent-file-coding-system))
3238 (gnus-agent-check-overview-buffer)
3239 (write-region (point-min) (point-max) file nil 'silent))
3241 ;; Update the group's article alist to include the newly
3242 ;; fetched articles.
3243 (gnus-agent-load-alist group)
3244 (gnus-agent-save-alist group uncached-articles nil)
3247 ;; Copy the temp buffer to the nntp-server-buffer
3248 (set-buffer nntp-server-buffer)
3250 (insert-buffer-substring gnus-agent-overview-buffer)))
3253 (not (numberp fetch-old)))
3254 t ; Don't remove anything.
3255 (nnheader-nov-delete-outside-range
3256 (if fetch-old (max 1 (- (car articles) fetch-old))
3258 (car (last articles)))
3263 (defun gnus-agent-request-article (article group)
3264 "Retrieve ARTICLE in GROUP from the agent cache."
3265 (when (and gnus-agent
3266 (or gnus-agent-cache
3269 (let* ((gnus-command-method (gnus-find-method-for-group group))
3270 (file (gnus-agent-article-name (number-to-string article) group))
3271 (buffer-read-only nil))
3272 (when (and (file-exists-p file)
3273 (> (nth 7 (file-attributes file)) 0))
3275 (gnus-kill-all-overlays)
3276 (let ((coding-system-for-read gnus-cache-coding-system))
3277 (insert-file-contents file))
3280 (defun gnus-agent-regenerate-group (group &optional reread)
3282 If REREAD is t, all articles in the .overview are marked as unread.
3283 If REREAD is not nil, downloaded articles are marked as unread."
3285 (list (let ((def (or (gnus-group-group-name)
3286 gnus-newsgroup-name)))
3287 (let ((select (read-string (if def
3288 (concat "Group Name ("
3291 (if (and (equal "" select)
3296 (while (let ((c (read-char-exclusive
3297 "Mark as unread: (n)one / (a)ll / all (d)ownloaded articles? (n)"
3299 (cond ((or (eq c ?\r) (eq c ?n) (eq c ?N))
3301 ((or (eq c ?a) (eq c ?A))
3303 ((or (eq c ?d) (eq c ?D))
3304 (throw 'mark 'some)))
3305 (message "Ignoring unexpected input")
3308 (gnus-message 5 "Regenerating in %s" group)
3309 (let* ((gnus-command-method (or gnus-command-method
3310 (gnus-find-method-for-group group)))
3311 (file (gnus-agent-article-name ".overview" group))
3312 (dir (file-name-directory file))
3314 (downloaded (if (file-exists-p dir)
3315 (sort (mapcar (lambda (name) (string-to-int name))
3316 (directory-files dir nil "^[0-9]+$" t))
3318 (progn (gnus-make-directory dir) nil)))
3323 (mm-with-unibyte-buffer
3324 (if (file-exists-p file)
3325 (let ((nnheader-file-coding-system
3326 gnus-agent-file-coding-system))
3327 (nnheader-insert-file-contents file)))
3328 (set-buffer-modified-p nil)
3330 ;; Load the article IDs found in the overview file. As a
3331 ;; side-effect, validate the file contents.
3335 (goto-char (point-min))
3336 (while (< (point) (point-max))
3337 (cond ((and (looking-at "[0-9]+\t")
3338 (<= (- (match-end 0) (match-beginning 0)) 9))
3339 (push (read (current-buffer)) nov-arts)
3341 (let ((l1 (car nov-arts))
3342 (l2 (cadr nov-arts)))
3346 (gnus-message 3 "gnus-agent-regenerate-group: NOV\
3347 entries are NOT in ascending order.")
3348 ;; Don't sort now as I haven't verified
3349 ;; that every line begins with a number
3353 (gnus-message 4 "gnus-agent-regenerate-group: NOV\
3354 entries contained duplicate of article %s. Duplicate deleted." l1)
3356 (setq nov-arts (cdr nov-arts))))))
3358 (gnus-message 1 "gnus-agent-regenerate-group: NOV\
3359 entries contained line that did not begin with an article number. Deleted\
3361 (gnus-delete-line))))
3364 (gnus-message 5 "gnus-agent-regenerate-group: Sorting NOV\
3365 entries into ascending order.")
3366 (sort-numeric-fields 1 (point-min) (point-max))
3367 (setq nov-arts nil)))))
3368 (gnus-agent-check-overview-buffer)
3370 ;; Construct a new article alist whose nodes match every header
3371 ;; in the .overview file. As a side-effect, missing headers are
3372 ;; reconstructed from the downloaded article file.
3373 (while (or downloaded nov-arts)
3374 (cond ((and downloaded
3376 (> (car downloaded) (car nov-arts))))
3377 ;; This entry is missing from the overview file
3378 (gnus-message 3 "Regenerating NOV %s %d..." group
3380 (let ((file (concat dir (number-to-string (car downloaded)))))
3381 (mm-with-unibyte-buffer
3382 (nnheader-insert-file-contents file)
3383 (nnheader-remove-body)
3384 (setq header (nnheader-parse-naked-head)))
3385 (mail-header-set-number header (car downloaded))
3387 (let ((key (concat "^" (int-to-string (car nov-arts))
3389 (or (re-search-backward key nil t)
3390 (re-search-forward key))
3392 (goto-char (point-min)))
3393 (nnheader-insert-nov header))
3394 (setq nov-arts (cons (car downloaded) nov-arts)))
3395 ((eq (car downloaded) (car nov-arts))
3396 ;; This entry in the overview has been downloaded
3397 (push (cons (car downloaded)
3399 (nth 5 (file-attributes
3400 (concat dir (number-to-string
3401 (car downloaded))))))) alist)
3402 (setq downloaded (cdr downloaded))
3403 (setq nov-arts (cdr nov-arts)))
3405 ;; This entry in the overview has not been downloaded
3406 (push (cons (car nov-arts) nil) alist)
3407 (setq nov-arts (cdr nov-arts)))))
3409 ;; When gnus-agent-consider-all-articles is set,
3410 ;; gnus-agent-regenerate-group should NOT remove article IDs from
3411 ;; the alist. Those IDs serve as markers to indicate that an
3412 ;; attempt has been made to fetch that article's header.
3414 ;; When gnus-agent-consider-all-articles is NOT set,
3415 ;; gnus-agent-regenerate-group can remove the article ID of every
3416 ;; article (with the exception of the last ID in the list - it's
3417 ;; special) that no longer appears in the overview. In this
3418 ;; situtation, the last article ID in the list implies that it,
3419 ;; and every article ID preceeding it, have been fetched from the
3421 (if gnus-agent-consider-all-articles
3422 ;; Restore all article IDs that were not found in the overview file.
3423 (let* ((n (cons nil alist))
3425 (o (gnus-agent-load-alist group)))
3427 (let ((nID (caadr n))
3430 (setq n (setcdr n (list (list oID))))
3433 (setcdr n (cons (list oID) (cdr n)))
3439 (setq n (cdr n))))))
3440 (setq alist (cdr merged)))
3441 ;; Restore the last article ID if it is not already in the new alist
3442 (let ((n (last alist))
3443 (o (last (gnus-agent-load-alist group))))
3447 (push (cons (caar o) nil) alist))
3448 ((< (caar n) (caar o))
3449 (setcdr n (list (car o)))))))
3451 (let ((inhibit-quit t))
3452 (if (setq regenerated (buffer-modified-p))
3453 (let ((coding-system-for-write gnus-agent-file-coding-system))
3454 (write-region (point-min) (point-max) file nil 'silent)))
3456 (setq regenerated (or regenerated
3457 (and reread gnus-agent-article-alist)
3458 (not (equal alist gnus-agent-article-alist)))
3461 (setq gnus-agent-article-alist alist)
3464 (gnus-agent-save-alist group)))
3467 (when (and reread gnus-agent-article-alist)
3468 (gnus-make-ascending-articles-unread
3470 (delq nil (mapcar (function (lambda (c)
3471 (cond ((eq reread t)
3475 gnus-agent-article-alist)))
3477 (when (gnus-buffer-live-p gnus-group-buffer)
3478 (gnus-group-update-group group t)
3482 (gnus-message 5 nil)
3486 (defun gnus-agent-regenerate (&optional clean reread)
3487 "Regenerate all agent covered files.
3488 If CLEAN, don't read existing active files."
3491 (gnus-message 4 "Regenerating Gnus agent files...")
3492 (dolist (gnus-command-method (gnus-agent-covered-methods))
3493 (let ((active-file (gnus-agent-lib-file "active"))
3494 active-hashtb active-changed
3496 (gnus-make-directory (file-name-directory active-file))
3498 (setq active-hashtb (gnus-make-hashtable 1000))
3499 (mm-with-unibyte-buffer
3500 (if (file-exists-p active-file)
3501 (let ((nnheader-file-coding-system
3502 gnus-agent-file-coding-system))
3503 (nnheader-insert-file-contents active-file))
3504 (setq active-changed t))
3505 (gnus-active-to-gnus-format
3506 nil (setq active-hashtb
3507 (gnus-make-hashtable
3508 (count-lines (point-min) (point-max)))))))
3509 (dolist (group (gnus-groups-from-server gnus-command-method))
3510 (setq regenerated (or (gnus-agent-regenerate-group group reread)
3512 (let ((min (or (caar gnus-agent-article-alist) 1))
3513 (max (or (caar (last gnus-agent-article-alist)) 0))
3514 (active (gnus-gethash-safe (gnus-group-real-name group)
3516 (read (gnus-info-read (gnus-get-info group))))
3519 (setq active (cons min max)
3521 (gnus-sethash group active active-hashtb))
3522 (when (> (car active) min)
3524 (setq active-changed t))
3525 (when (< (cdr active) max)
3527 (setq active-changed t)))))
3528 (when active-changed
3529 (setq regenerated t)
3530 (gnus-message 4 "Regenerate %s" active-file)
3531 (let ((nnmail-active-file-coding-system
3532 gnus-agent-file-coding-system))
3533 (gnus-write-active-file active-file active-hashtb)))))
3534 (gnus-message 4 "Regenerating Gnus agent files...done")
3537 (defun gnus-agent-go-online (&optional force)
3538 "Switch servers into online status."
3539 (interactive (list t))
3540 (dolist (server gnus-opened-servers)
3541 (when (eq (nth 1 server) 'offline)
3542 (if (if (eq force 'ask)
3544 (format "Switch %s:%s into online status? "
3545 (caar server) (cadar server)))
3547 (setcar (nthcdr 1 server) 'close)))))
3549 (defun gnus-agent-toggle-group-plugged (group)
3550 "Toggle the status of the server of the current group."
3551 (interactive (list (gnus-group-group-name)))
3552 (let* ((method (gnus-find-method-for-group group))
3553 (status (cadr (assoc method gnus-opened-servers))))
3554 (if (eq status 'offline)
3555 (gnus-server-set-status method 'closed)
3556 (gnus-close-server method)
3557 (gnus-server-set-status method 'offline))
3558 (message "Turn %s:%s from %s to %s." (car method) (cadr method)
3559 (if (eq status 'offline) 'offline 'online)
3560 (if (eq status 'offline) 'online 'offline))))
3562 (defun gnus-agent-group-covered-p (group)
3563 (gnus-agent-method-p (gnus-group-method group)))
3565 (add-hook 'gnus-group-prepare-hook
3569 (when (listp gnus-agent-expire-days)
3572 (gnus-message 1 "WARNING: gnus-agent-expire-days no longer\
3573 supports being set to a list.")(sleep-for 3)
3574 (gnus-message 1 "Change your configuration to set it to an\
3575 integer.")(sleep-for 3)
3576 (gnus-message 1 "I am now setting group parameters on each\
3577 group to match the configuration that the list offered.")
3580 (let ((groups (gnus-group-listed-groups)))
3582 (let* ((group (pop groups))
3583 (days gnus-agent-expire-days)
3586 (when (eq 0 (string-match
3589 (throw 'found (cadar days)))
3590 (setq days (cdr days)))
3593 (gnus-group-set-parameter group 'agent-days-until-old
3596 (let ((h gnus-group-prepare-hook))
3598 (let ((func (pop h)))
3599 (when (and (listp func)
3600 (eq (cadr (caddr func)) 'gnus-agent-do-once))
3601 (remove-hook 'gnus-group-prepare-hook func)
3604 (gnus-message 1 "I have finished setting group parameters on\
3605 each group. You may now customize your groups and/or topics to control the\
3608 (provide 'gnus-agent)
3610 ;;; gnus-agent.el ends here