1 ;;; gnus-agent.el --- unplugged support for Semi-gnus
2 ;; Copyright (C) 1997,98 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; Tatsuya Ichikawa <t-ichi@po.shiojiri.ne.jp>
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.
33 (require 'gnus-score))
35 (defcustom gnus-agent-directory (nnheader-concat gnus-directory "agent/")
36 "Where the Gnus agent will store its files."
40 (defcustom gnus-agent-plugged-hook nil
41 "Hook run when plugging into the network."
45 (defcustom gnus-agent-unplugged-hook nil
46 "Hook run when unplugging from the network."
50 (defcustom gnus-agent-handle-level gnus-level-subscribed
51 "Groups on levels higher than this variable will be ignored by the Agent."
55 (defcustom gnus-agent-expire-days 7
56 "Read articles older than this will be expired."
60 (defcustom gnus-agent-expire-all nil
61 "If non-nil, also expire unread, ticked and dormant articles.
62 If nil, only read articles will be expired."
66 (defcustom gnus-agent-group-mode-hook nil
67 "Hook run in Agent group minor modes."
71 (defcustom gnus-agent-summary-mode-hook nil
72 "Hook run in Agent summary minor modes."
76 (defcustom gnus-agent-server-mode-hook nil
77 "Hook run in Agent summary minor modes."
81 ;;; Internal variables
83 (defvar gnus-agent-history-buffers nil)
84 (defvar gnus-agent-buffer-alist nil)
85 (defvar gnus-agent-article-alist nil)
86 (defvar gnus-agent-group-alist nil)
87 (defvar gnus-agent-covered-methods nil)
88 (defvar gnus-category-alist nil)
89 (defvar gnus-agent-current-history nil)
90 (defvar gnus-agent-overview-buffer nil)
91 (defvar gnus-category-predicate-cache nil)
92 (defvar gnus-category-group-cache nil)
93 (defvar gnus-agent-spam-hashtb nil)
94 (defvar gnus-agent-file-name nil)
95 (defvar gnus-agent-send-mail-function nil)
96 (defvar gnus-agent-file-coding-system 'binary)
98 (defconst gnus-agent-scoreable-headers
100 "subject" "from" "date" "message-id"
101 "references" "chars" "lines" "xref")
102 "Headers that are considered when scoring articles
103 for download via the Agent.")
106 (defvar gnus-headers)
113 (defun gnus-open-agent ()
115 (gnus-agent-read-servers)
117 (setq gnus-agent-overview-buffer
118 (gnus-get-buffer-create " *Gnus agent overview*"))
119 (add-hook 'gnus-group-mode-hook 'gnus-agent-mode)
120 (add-hook 'gnus-summary-mode-hook 'gnus-agent-mode)
121 (add-hook 'gnus-server-mode-hook 'gnus-agent-mode))
123 (gnus-add-shutdown 'gnus-close-agent 'gnus)
125 (defun gnus-close-agent ()
126 (setq gnus-agent-covered-methods nil
127 gnus-category-predicate-cache nil
128 gnus-category-group-cache nil
129 gnus-agent-spam-hashtb nil)
130 (gnus-kill-buffer gnus-agent-overview-buffer))
133 ;;; Utility functions
136 (defun gnus-agent-read-file (file)
137 "Load FILE and do a `read' there."
140 (nnheader-insert-file-contents file)
141 (goto-char (point-min))
142 (read (current-buffer)))))
144 (defsubst gnus-agent-method ()
145 (concat (symbol-name (car gnus-command-method)) "/"
146 (if (equal (cadr gnus-command-method) "")
148 (cadr gnus-command-method))))
150 (defsubst gnus-agent-directory ()
151 "Path of the Gnus agent directory."
152 (nnheader-concat gnus-agent-directory
153 (nnheader-translate-file-chars (gnus-agent-method)) "/"))
155 (defun gnus-agent-lib-file (file)
156 "The full path of the Gnus agent library FILE."
157 (concat (gnus-agent-directory) "agent.lib/" file))
159 ;;; Fetching setup functions.
161 (defun gnus-agent-start-fetch ()
162 "Initialize data structures for efficient fetching."
163 (gnus-agent-open-history)
164 (setq gnus-agent-current-history (gnus-agent-history-buffer)))
166 (defun gnus-agent-stop-fetch ()
167 "Save all data structures and clean up."
168 (gnus-agent-save-history)
169 (gnus-agent-close-history)
170 (setq gnus-agent-spam-hashtb nil)
172 (set-buffer nntp-server-buffer)
175 (defmacro gnus-agent-with-fetch (&rest forms)
179 (gnus-agent-start-fetch)
181 (gnus-agent-stop-fetch)))
183 (put 'gnus-agent-with-fetch 'lisp-indent-function 0)
184 (put 'gnus-agent-with-fetch 'edebug-form-spec '(body))
190 (defvar gnus-agent-mode-hook nil
191 "Hook run when installing agent mode.")
193 (defvar gnus-agent-mode nil)
194 (defvar gnus-agent-mode-status '(gnus-agent-mode " Plugged"))
196 (defun gnus-agent-mode ()
197 "Minor mode for providing a agent support in Gnus buffers."
198 (let* ((buffer (progn (string-match "^gnus-\\(.*\\)-mode$"
199 (symbol-name major-mode))
200 (match-string 1 (symbol-name major-mode))))
201 (mode (intern (format "gnus-agent-%s-mode" buffer))))
202 (set (make-local-variable 'gnus-agent-mode) t)
204 (set (make-local-variable mode) t)
206 (when (gnus-visual-p 'agent-menu 'menu)
207 (funcall (intern (format "gnus-agent-%s-make-menu-bar" buffer))))
208 (unless (assq 'gnus-agent-mode minor-mode-alist)
209 (push gnus-agent-mode-status minor-mode-alist))
210 (unless (assq mode minor-mode-map-alist)
211 (push (cons mode (symbol-value (intern (format "gnus-agent-%s-mode-map"
213 minor-mode-map-alist))
214 (when (eq major-mode 'gnus-group-mode)
215 (gnus-agent-toggle-plugged gnus-plugged))
216 (gnus-run-hooks 'gnus-agent-mode-hook
217 (intern (format "gnus-agent-%s-mode-hook" buffer)))))
219 (defvar gnus-agent-group-mode-map (make-sparse-keymap))
220 (gnus-define-keys gnus-agent-group-mode-map
221 "Ju" gnus-agent-fetch-groups
222 "Jc" gnus-enter-category-buffer
223 "Jj" gnus-agent-toggle-plugged
224 "Js" gnus-agent-fetch-session
225 "JS" gnus-group-send-drafts
226 "Ja" gnus-agent-add-group)
228 (defun gnus-agent-group-make-menu-bar ()
229 (unless (boundp 'gnus-agent-group-menu)
231 gnus-agent-group-menu gnus-agent-group-mode-map ""
233 ["Toggle plugged" gnus-agent-toggle-plugged t]
234 ["List categories" gnus-enter-category-buffer t]
235 ["Send drafts" gnus-group-send-drafts gnus-plugged]
237 ["All" gnus-agent-fetch-session gnus-plugged]
238 ["Group" gnus-agent-fetch-group gnus-plugged])))))
240 (defvar gnus-agent-summary-mode-map (make-sparse-keymap))
241 (gnus-define-keys gnus-agent-summary-mode-map
242 "Jj" gnus-agent-toggle-plugged
243 "J#" gnus-agent-mark-article
244 "J\M-#" gnus-agent-unmark-article
245 "@" gnus-agent-toggle-mark
246 "Jc" gnus-agent-catchup)
248 (defun gnus-agent-summary-make-menu-bar ()
249 (unless (boundp 'gnus-agent-summary-menu)
251 gnus-agent-summary-menu gnus-agent-summary-mode-map ""
253 ["Toggle plugged" gnus-agent-toggle-plugged t]
254 ["Mark as downloadable" gnus-agent-mark-article t]
255 ["Unmark as downloadable" gnus-agent-unmark-article t]
256 ["Toggle mark" gnus-agent-toggle-mark t]
257 ["Catchup undownloaded" gnus-agent-catchup t]))))
259 (defvar gnus-agent-server-mode-map (make-sparse-keymap))
260 (gnus-define-keys gnus-agent-server-mode-map
261 "Jj" gnus-agent-toggle-plugged
262 "Ja" gnus-agent-add-server
263 "Jr" gnus-agent-remove-server)
265 (defun gnus-agent-server-make-menu-bar ()
266 (unless (boundp 'gnus-agent-server-menu)
268 gnus-agent-server-menu gnus-agent-server-mode-map ""
270 ["Toggle plugged" gnus-agent-toggle-plugged t]
271 ["Add" gnus-agent-add-server t]
272 ["Remove" gnus-agent-remove-server t]))))
274 (defun gnus-agent-toggle-plugged (plugged)
275 "Toggle whether Gnus is unplugged or not."
276 (interactive (list (not gnus-plugged)))
279 (setq gnus-plugged plugged)
280 (gnus-run-hooks 'gnus-agent-plugged-hook)
281 (setcar (cdr gnus-agent-mode-status) " Plugged"))
282 (gnus-agent-close-connections)
283 (setq gnus-plugged plugged)
284 (gnus-run-hooks 'gnus-agent-unplugged-hook)
285 (setcar (cdr gnus-agent-mode-status) " Unplugged"))
286 (set-buffer-modified-p t))
288 (defun gnus-agent-close-connections ()
289 "Close all methods covered by the Gnus agent."
290 (let ((methods gnus-agent-covered-methods))
292 (gnus-close-server (pop methods)))))
295 (defun gnus-unplugged ()
296 "Start Gnus unplugged."
298 (setq gnus-plugged nil)
302 (defun gnus-plugged ()
303 "Start Gnus plugged."
305 (setq gnus-plugged t)
309 (defun gnus-agentize ()
310 "Allow Gnus to be an offline newsreader.
311 The normal usage of this command is to put the following as the
312 last form in your `.gnus.el' file:
316 This will modify the `gnus-before-startup-hook', `gnus-post-method',
317 and `message-send-mail-function' variables, and install the Gnus
318 agent minor mode in all Gnus buffers."
321 (add-hook 'gnus-setup-news-hook 'gnus-agent-queue-setup)
322 (unless gnus-agent-send-mail-function
323 (setq gnus-agent-send-mail-function message-send-mail-function
324 message-send-mail-function 'gnus-agent-send-mail))
325 (unless gnus-agent-covered-methods
326 (setq gnus-agent-covered-methods (list gnus-select-method))))
328 (defun gnus-agent-queue-setup ()
329 "Make sure the queue group exists."
330 (unless (gnus-gethash "nndraft:queue" gnus-newsrc-hashtb)
331 (gnus-request-create-group "queue" '(nndraft ""))
332 (let ((gnus-level-default-subscribed 1))
333 (gnus-subscribe-group "nndraft:queue" nil '(nndraft "")))
334 (gnus-group-set-parameter "nndraft:queue" 'charset "nil")
335 (gnus-group-set-parameter
336 "nndraft:queue" 'gnus-dummy '((gnus-draft-mode)))))
338 (defun gnus-agent-send-mail ()
340 (funcall gnus-agent-send-mail-function)
341 (goto-char (point-min))
343 (concat "^" (regexp-quote mail-header-separator) "\n"))
345 (gnus-agent-insert-meta-information 'mail)
346 (gnus-request-accept-article "nndraft:queue" nil t t)))
348 (defun gnus-agent-insert-meta-information (type &optional method)
349 "Insert meta-information into the message that says how it's to be posted.
350 TYPE can be either `mail' or `news'. If the latter METHOD can
353 (message-remove-header gnus-agent-meta-information-header)
354 (goto-char (point-min))
355 (insert gnus-agent-meta-information-header ": "
356 (symbol-name type) " " (format "%S" method)
359 (while (search-backward "\n" nil t)
360 (replace-match "\\n" t t))))
363 ;;; Group mode commands
366 (defun gnus-agent-fetch-groups (n)
367 "Put all new articles in the current groups into the Agent."
369 (gnus-group-iterate n 'gnus-agent-fetch-group))
371 (defun gnus-agent-fetch-group (group)
372 "Put all new articles in GROUP into the Agent."
373 (interactive (list (gnus-group-group-name)))
375 (error "No group on the current line"))
376 (let ((gnus-command-method (gnus-find-method-for-group group)))
377 (gnus-agent-with-fetch
378 (gnus-agent-fetch-group-1 group gnus-command-method)
379 (gnus-message 5 "Fetching %s...done" group))))
381 (defun gnus-agent-add-group (category arg)
382 "Add the current group to an agent category."
388 (mapcar (lambda (cat) (list (symbol-name (car cat))))
392 (let ((cat (assq category gnus-category-alist))
394 (gnus-group-iterate arg
396 (when (cadddr (setq c (gnus-group-category group)))
397 (setf (cadddr c) (delete group (cadddr c))))
398 (push group groups)))
399 (setf (cadddr cat) (nconc (cadddr cat) groups))
400 (gnus-category-write)))
403 ;;; Server mode commands
406 (defun gnus-agent-add-server (server)
407 "Enroll SERVER in the agent program."
408 (interactive (list (gnus-server-server-name)))
410 (error "No server on the current line"))
411 (let ((method (gnus-server-get-method nil (gnus-server-server-name))))
412 (when (member method gnus-agent-covered-methods)
413 (error "Server already in the agent program"))
414 (push method gnus-agent-covered-methods)
415 (gnus-agent-write-servers)
416 (message "Entered %s into the Agent" server)))
418 (defun gnus-agent-remove-server (server)
419 "Remove SERVER from the agent program."
420 (interactive (list (gnus-server-server-name)))
422 (error "No server on the current line"))
423 (let ((method (gnus-server-get-method nil (gnus-server-server-name))))
424 (unless (member method gnus-agent-covered-methods)
425 (error "Server not in the agent program"))
426 (setq gnus-agent-covered-methods
427 (delete method gnus-agent-covered-methods))
428 (gnus-agent-write-servers)
429 (message "Removed %s from the agent" server)))
431 (defun gnus-agent-read-servers ()
432 "Read the alist of covered servers."
433 (setq gnus-agent-covered-methods
434 (gnus-agent-read-file
435 (nnheader-concat gnus-agent-directory "lib/servers"))))
437 (defun gnus-agent-write-servers ()
438 "Write the alist of covered servers."
439 (with-temp-file (nnheader-concat gnus-agent-directory "lib/servers")
440 (prin1 gnus-agent-covered-methods (current-buffer))))
446 (defun gnus-agent-mark-article (n &optional unmark)
447 "Mark the next N articles as downloadable.
448 If N is negative, mark backward instead. If UNMARK is non-nil, remove
449 the mark instead. The difference between N and the actual number of
450 articles marked is returned."
452 (let ((backward (< n 0))
457 (gnus-summary-set-agent-mark
458 (gnus-summary-article-number) unmark)
459 (zerop (gnus-summary-next-subject (if backward -1 1) nil t))))
462 (gnus-message 7 "No more articles"))
463 (gnus-summary-recenter)
464 (gnus-summary-position-point)
467 (defun gnus-agent-unmark-article (n)
468 "Remove the downloadable mark from the next N articles.
469 If N is negative, unmark backward instead. The difference between N and
470 the actual number of articles unmarked is returned."
472 (gnus-agent-mark-article n t))
474 (defun gnus-agent-toggle-mark (n)
475 "Toggle the downloadable mark from the next N articles.
476 If N is negative, toggle backward instead. The difference between N and
477 the actual number of articles toggled is returned."
479 (gnus-agent-mark-article n 'toggle))
481 (defun gnus-summary-set-agent-mark (article &optional unmark)
482 "Mark ARTICLE as downloadable."
483 (let ((unmark (if (and (not (null unmark)) (not (eq t unmark)))
484 (memq article gnus-newsgroup-downloadable)
488 (setq gnus-newsgroup-downloadable
489 (delq article gnus-newsgroup-downloadable))
490 (push article gnus-newsgroup-undownloaded))
491 (setq gnus-newsgroup-undownloaded
492 (delq article gnus-newsgroup-undownloaded))
493 (push article gnus-newsgroup-downloadable))
494 (gnus-summary-update-mark
495 (if unmark gnus-undownloaded-mark gnus-downloadable-mark)
498 (defun gnus-agent-get-undownloaded-list ()
499 "Mark all unfetched articles as read."
500 (let ((gnus-command-method (gnus-find-method-for-group gnus-newsgroup-name)))
501 (when (and (not gnus-plugged)
502 (gnus-agent-method-p gnus-command-method))
503 (gnus-agent-load-alist gnus-newsgroup-name)
504 (let ((articles gnus-newsgroup-unreads)
506 (while (setq article (pop articles))
507 (unless (or (cdr (assq article gnus-agent-article-alist))
508 (memq article gnus-newsgroup-downloadable))
509 (push article gnus-newsgroup-undownloaded)))))))
511 (defun gnus-agent-catchup ()
512 "Mark all undownloaded articles as read."
515 (while gnus-newsgroup-undownloaded
516 (gnus-summary-mark-article
517 (pop gnus-newsgroup-undownloaded) gnus-catchup-mark)))
518 (gnus-summary-position-point))
521 ;;; Internal functions
524 (defun gnus-agent-save-active (method)
525 (when (gnus-agent-method-p method)
526 (let* ((gnus-command-method method)
527 (file (gnus-agent-lib-file "active")))
528 (gnus-make-directory (file-name-directory file))
529 (write-region-as-specified-coding-system
530 (point-min) (point-max) file nil 'silent
531 gnus-agent-file-coding-system)
532 (when (file-exists-p (gnus-agent-lib-file "groups"))
533 (delete-file (gnus-agent-lib-file "groups"))))))
535 (defun gnus-agent-save-groups (method)
536 (let* ((gnus-command-method method)
537 (file (gnus-agent-lib-file "groups")))
538 (gnus-make-directory (file-name-directory file))
539 (write-region-as-specified-coding-system
540 (point-min) (point-max) file nil 'silent
541 gnus-agent-file-coding-system)
542 (when (file-exists-p (gnus-agent-lib-file "active"))
543 (delete-file (gnus-agent-lib-file "active")))))
545 (defun gnus-agent-save-group-info (method group active)
546 (when (gnus-agent-method-p method)
547 (let* ((gnus-command-method method)
548 (file (if nntp-server-list-active-group
549 (gnus-agent-lib-file "active")
550 (gnus-agent-lib-file "groups"))))
551 (gnus-make-directory (file-name-directory file))
553 (when (file-exists-p file)
554 (nnheader-insert-file-contents file))
555 (goto-char (point-min))
556 (if nntp-server-list-active-group
558 (when (re-search-forward
559 (concat "^" (regexp-quote group) " ") nil t)
561 (insert group " " (number-to-string (cdr active)) " "
562 (number-to-string (car active)) " y\n"))
563 (when (re-search-forward
564 (concat (regexp-quote group) "\\($\\| \\)") nil t)
566 (insert-buffer-substring nntp-server-buffer))))))
568 (defun gnus-agent-group-path (group)
569 "Translate GROUP into a path."
570 (if nnmail-use-long-file-names
571 (gnus-group-real-name group)
572 (nnheader-replace-chars-in-string
573 (nnheader-translate-file-chars (gnus-group-real-name group))
578 (defun gnus-agent-method-p (method)
579 "Say whether METHOD is covered by the agent."
580 (member method gnus-agent-covered-methods))
582 (defun gnus-agent-get-function (method)
583 (if (and (not gnus-plugged)
584 (gnus-agent-method-p method))
590 ;;; History functions
592 (defun gnus-agent-history-buffer ()
593 (cdr (assoc (gnus-agent-method) gnus-agent-history-buffers)))
595 (defun gnus-agent-open-history ()
597 (push (cons (gnus-agent-method)
598 (set-buffer (gnus-get-buffer-create
599 (format " *Gnus agent %s history*"
600 (gnus-agent-method)))))
601 gnus-agent-history-buffers)
604 (let ((file (gnus-agent-lib-file "history")))
605 (when (file-exists-p file)
607 (set (make-local-variable 'gnus-agent-file-name) file))))
609 (defun gnus-agent-save-history ()
611 (set-buffer gnus-agent-current-history)
612 (gnus-make-directory (file-name-directory gnus-agent-file-name))
613 (write-region-as-specified-coding-system
614 (1+ (point-min)) (point-max) gnus-agent-file-name nil 'silent
615 gnus-agent-file-coding-system)))
617 (defun gnus-agent-close-history ()
618 (when (gnus-buffer-live-p gnus-agent-current-history)
619 (kill-buffer gnus-agent-current-history)
620 (setq gnus-agent-history-buffers
621 (delq (assoc (gnus-agent-method) gnus-agent-history-buffers)
622 gnus-agent-history-buffers))))
624 (defun gnus-agent-enter-history (id group-arts date)
626 (set-buffer gnus-agent-current-history)
627 (goto-char (point-max))
628 (insert id "\t" (number-to-string date) "\t")
630 (insert (caar group-arts) " " (number-to-string (cdr (pop group-arts)))
634 (defun gnus-agent-article-in-history-p (id)
636 (set-buffer (gnus-agent-history-buffer))
637 (goto-char (point-min))
638 (search-forward (concat "\n" id "\t") nil t)))
640 (defun gnus-agent-history-path (id)
642 (set-buffer (gnus-agent-history-buffer))
643 (goto-char (point-min))
644 (when (search-forward (concat "\n" id "\t") nil t)
645 (let ((method (gnus-agent-method)))
647 (while (not (numberp (setq group (read (current-buffer)))))
648 (push (concat method "/" group) paths))
649 (nreverse paths))))))
655 (defun gnus-agent-fetch-articles (group articles)
656 "Fetch ARTICLES from GROUP and put them into the Agent."
658 ;; Prune off articles that we have already fetched.
660 (cdr (assq (car articles) gnus-agent-article-alist)))
662 (let ((arts articles))
664 (if (cdr (assq (cadr arts) gnus-agent-article-alist))
665 (setcdr arts (cddr arts))
666 (setq arts (cdr arts)))))
669 (gnus-agent-directory)
670 (gnus-agent-group-path group) "/"))
671 (date (time-to-days (current-time)))
674 (gnus-make-directory dir)
675 (gnus-message 7 "Fetching articles for %s..." group)
676 ;; Fetch the articles from the backend.
677 (if (gnus-check-backend-function 'retrieve-articles group)
678 (setq pos (gnus-retrieve-articles articles group))
681 (while (setq article (pop articles))
682 (when (gnus-request-article article group)
683 (goto-char (point-max))
684 (push (cons article (point)) pos)
685 (insert-buffer-substring nntp-server-buffer)))
686 (copy-to-buffer nntp-server-buffer (point-min) (point-max))
687 (setq pos (nreverse pos)))))
688 ;; Then save these articles into the Agent.
690 (set-buffer nntp-server-buffer)
692 (narrow-to-region (cdar pos) (or (cdadr pos) (point-max)))
693 (goto-char (point-min))
694 (when (search-forward "\n\n" nil t)
695 (when (search-backward "\nXrefs: " nil t)
696 ;; Handle crossposting.
697 (skip-chars-forward "^ ")
698 (skip-chars-forward " ")
700 (while (looking-at "\\([^: \n]+\\):\\([0-9]+\\) +")
701 (push (cons (buffer-substring (match-beginning 1)
703 (buffer-substring (match-beginning 2)
706 (goto-char (match-end 0)))
707 (gnus-agent-crosspost crosses (caar pos))))
708 (goto-char (point-min))
709 (if (not (re-search-forward "^Message-ID: *<\\([^>\n]+\\)>" nil t))
710 (setq id "No-Message-ID-in-article")
711 (setq id (buffer-substring (match-beginning 1) (match-end 1))))
712 (write-region-as-specified-coding-system
713 (point-min) (point-max)
714 (concat dir (number-to-string (caar pos))) nil 'silent
715 gnus-agent-file-coding-system)
716 (when (setq elem (assq (caar pos) gnus-agent-article-alist))
718 (gnus-agent-enter-history
719 id (or crosses (list (cons group (caar pos)))) date)
722 (gnus-agent-save-alist group)))))
724 (defun gnus-agent-crosspost (crosses article)
725 (let (gnus-agent-article-alist group alist beg end)
727 (set-buffer gnus-agent-overview-buffer)
728 (when (nnheader-find-nov-line article)
731 (setq end (progn (forward-line 1) (point)))))
733 (setq group (caar crosses))
734 (unless (setq alist (assoc group gnus-agent-group-alist))
735 (push (setq alist (list group (gnus-agent-load-alist (caar crosses))))
736 gnus-agent-group-alist))
737 (setcdr alist (cons (cons (cdar crosses) t) (cdr alist)))
739 (set-buffer (gnus-get-buffer-create (format " *Gnus agent overview %s*"
741 (when (= (point-max) (point-min))
742 (push (cons group (current-buffer)) gnus-agent-buffer-alist)
744 (nnheader-insert-file-contents
745 (gnus-agent-article-name ".overview" group))))
746 (nnheader-find-nov-line (string-to-number (cdar crosses)))
747 (insert (string-to-number (cdar crosses)))
748 (insert-buffer-substring gnus-agent-overview-buffer beg end))
751 (defun gnus-agent-flush-cache ()
753 (while gnus-agent-buffer-alist
754 (set-buffer (cdar gnus-agent-buffer-alist))
755 (write-region-as-specified-coding-system
756 (point-min) (point-max)
757 (gnus-agent-article-name ".overview"
758 (caar gnus-agent-buffer-alist))
759 nil 'silent gnus-agent-file-coding-system)
760 (pop gnus-agent-buffer-alist))
761 (while gnus-agent-group-alist
762 (with-temp-file (caar gnus-agent-group-alist)
763 (princ (cdar gnus-agent-group-alist))
765 (pop gnus-agent-group-alist))))
767 (defun gnus-agent-fetch-headers (group &optional force)
768 (let ((articles (if (gnus-agent-load-alist group)
769 (gnus-sorted-intersection
770 (gnus-list-of-unread-articles group)
771 (gnus-uncompress-range
772 (cons (1+ (caar (last gnus-agent-article-alist)))
773 (cdr (gnus-active group)))))
774 (gnus-list-of-unread-articles group)))
775 (gnus-decode-encoded-word-function 'identity)
776 (file (gnus-agent-article-name ".overview" group)))
778 (gnus-make-directory (nnheader-translate-file-chars
779 (file-name-directory file)))
781 (gnus-message 7 "Fetching headers for %s..." group)
783 (set-buffer nntp-server-buffer)
784 (unless (eq 'nov (gnus-retrieve-headers articles group))
785 (nnvirtual-convert-headers))
786 ;; Save these headers for later processing.
787 (copy-to-buffer gnus-agent-overview-buffer (point-min) (point-max))
788 (when (file-exists-p file)
789 (gnus-agent-braid-nov group articles file))
790 (write-region-as-specified-coding-system
791 (point-min) (point-max) file nil 'silent
792 gnus-agent-file-coding-system)
793 (gnus-agent-save-alist group articles nil)
794 (gnus-agent-enter-history
795 "last-header-fetched-for-session"
796 (list (cons group (nth (- (length articles) 1) articles)))
797 (time-to-days (current-time)))
800 (defsubst gnus-agent-copy-nov-line (article)
802 (set-buffer gnus-agent-overview-buffer)
804 (if (eq article (read (current-buffer)))
805 (setq e (progn (forward-line 1) (point)))
809 (set-buffer nntp-server-buffer)
810 (insert-buffer-substring gnus-agent-overview-buffer b e)))
812 (defun gnus-agent-braid-nov (group articles file)
813 (set-buffer gnus-agent-overview-buffer)
814 (goto-char (point-min))
815 (set-buffer nntp-server-buffer)
817 (nnheader-insert-file-contents file)
818 (goto-char (point-max))
819 (if (or (= (point-min) (point-max))
822 (< (read (current-buffer)) (car articles))))
823 ;; We have only headers that are after the older headers,
824 ;; so we just append them.
826 (goto-char (point-max))
827 (insert-buffer-substring gnus-agent-overview-buffer))
828 ;; We do it the hard way.
829 (nnheader-find-nov-line (car articles))
830 (gnus-agent-copy-nov-line (car articles))
834 (while (and (not (eobp))
835 (< (read (current-buffer)) (car articles)))
839 (gnus-agent-copy-nov-line (car articles))
840 (setq articles (cdr articles))))
843 (set-buffer gnus-agent-overview-buffer)
846 (set-buffer nntp-server-buffer)
847 (insert-buffer-substring gnus-agent-overview-buffer b e)))))
849 (defun gnus-agent-load-alist (group &optional dir)
850 "Load the article-state alist for GROUP."
851 (setq gnus-agent-article-alist
852 (gnus-agent-read-file
854 (concat dir ".agentview")
855 (gnus-agent-article-name ".agentview" group)))))
857 (defun gnus-agent-save-alist (group &optional articles state dir)
858 "Save the article-state alist for GROUP."
859 (with-temp-file (if dir
860 (concat dir ".agentview")
861 (gnus-agent-article-name ".agentview" group))
862 (princ (setq gnus-agent-article-alist
863 (nconc gnus-agent-article-alist
864 (mapcar (lambda (article) (cons article state))
869 (defun gnus-agent-article-name (article group)
870 (concat (gnus-agent-directory) (gnus-agent-group-path group) "/"
871 (if (stringp article) article (string-to-number article))))
874 (defun gnus-agent-batch-fetch ()
875 "Start Gnus and fetch session."
878 (gnus-agent-fetch-session)
881 (defun gnus-agent-fetch-session ()
882 "Fetch all articles and headers that are eligible for fetching."
884 (unless gnus-agent-covered-methods
885 (error "No servers are covered by the Gnus agent"))
887 (error "Can't fetch articles while Gnus is unplugged"))
888 (let ((methods gnus-agent-covered-methods)
889 groups group gnus-command-method)
892 (setq gnus-command-method (car methods))
893 (when (or (gnus-server-opened gnus-command-method)
894 (gnus-open-server gnus-command-method))
895 (setq groups (gnus-groups-from-server (car methods)))
896 (gnus-agent-with-fetch
897 (while (setq group (pop groups))
898 (when (<= (gnus-group-level group) gnus-agent-handle-level)
899 (gnus-agent-fetch-group-1 group gnus-command-method)))))
901 (gnus-message 6 "Finished fetching articles into the Gnus agent"))))
903 (defun gnus-agent-fetch-group-1 (group method)
905 (let ((gnus-command-method method)
906 (gnus-newsgroup-name group)
907 gnus-newsgroup-dependencies gnus-newsgroup-headers
908 gnus-newsgroup-scored gnus-headers gnus-score
909 gnus-use-cache articles arts
910 category predicate info marks score-param)
912 (when (and (or (gnus-active group) (gnus-activate-group group))
913 (setq articles (gnus-agent-fetch-headers group)))
914 ;; Parse them and see which articles we want to fetch.
915 (setq gnus-newsgroup-dependencies
916 (make-vector (length articles) 0))
917 ;; No need to call `gnus-get-newsgroup-headers-xover' with
918 ;; the entire .overview for group as we still have the just
919 ;; downloaded headers in `gnus-agent-overview-buffer'.
920 (let ((nntp-server-buffer gnus-agent-overview-buffer))
921 (setq gnus-newsgroup-headers
922 (gnus-get-newsgroup-headers-xover articles nil nil group)))
923 (setq category (gnus-group-category group))
926 (or (gnus-group-get-parameter group 'agent-predicate t)
928 ;; Do we want to download everything, or nothing?
929 (if (or (eq (caaddr predicate) 'gnus-agent-true)
930 (eq (caaddr predicate) 'gnus-agent-false))
932 (setq arts (symbol-value
933 (cadr (assoc (caaddr predicate)
934 '((gnus-agent-true articles)
935 (gnus-agent-false nil))))))
936 ;; No, we need to decide what we want.
940 (gnus-group-get-parameter group 'agent-score t)
943 (require 'gnus-score)
944 (if (eq score-method 'file)
946 (gnus-score-load-files
947 (gnus-all-score-files group)))
949 (while (setq list (car entries))
950 (push (car list) score-file)
951 (setq list (cdr list))
953 (when (member (caar list)
954 gnus-agent-scoreable-headers)
955 (push (car list) score-file))
956 (setq list (cdr list)))
958 (append score-param (list (nreverse score-file)))
959 score-file nil entries (cdr entries)))
961 (if (stringp (car score-method))
963 (list (list score-method)))))))
965 (gnus-score-headers score-param))
967 (while (setq gnus-headers (pop gnus-newsgroup-headers))
969 (or (cdr (assq (mail-header-number gnus-headers)
970 gnus-newsgroup-scored))
971 gnus-summary-default-score))
972 (when (funcall predicate)
973 (push (mail-header-number gnus-headers)
975 ;; Fetch the articles.
977 (gnus-agent-fetch-articles group arts)))
978 ;; Perhaps we have some additional articles to fetch.
979 (setq arts (assq 'download (gnus-info-marks
980 (setq info (gnus-get-info group)))))
982 (gnus-agent-fetch-articles
983 group (gnus-uncompress-range (cdr arts)))
984 (setq marks (delq arts (gnus-info-marks info)))
985 (gnus-info-set-marks info marks)
987 (concat "(gnus-group-set-info '"
988 (gnus-prin1-to-string info)
992 ;;; Agent Category Mode
995 (defvar gnus-category-mode-hook nil
996 "Hook run in `gnus-category-mode' buffers.")
998 (defvar gnus-category-line-format " %(%20c%): %g\n"
999 "Format of category lines.")
1001 (defvar gnus-category-mode-line-format "Gnus: %%b"
1002 "The format specification for the category mode line.")
1004 (defvar gnus-agent-short-article 100
1005 "Articles that have fewer lines than this are short.")
1007 (defvar gnus-agent-long-article 200
1008 "Articles that have more lines than this are long.")
1010 (defvar gnus-agent-low-score 0
1011 "Articles that have a score lower than this have a low score.")
1013 (defvar gnus-agent-high-score 0
1014 "Articles that have a score higher than this have a high score.")
1017 ;;; Internal variables.
1019 (defvar gnus-category-buffer "*Agent Category*")
1021 (defvar gnus-category-line-format-alist
1022 `((?c gnus-tmp-name ?s)
1023 (?g gnus-tmp-groups ?d)))
1025 (defvar gnus-category-mode-line-format-alist
1026 `((?u user-defined ?s)))
1028 (defvar gnus-category-line-format-spec nil)
1029 (defvar gnus-category-mode-line-format-spec nil)
1031 (defvar gnus-category-mode-map nil)
1032 (put 'gnus-category-mode 'mode-class 'special)
1034 (unless gnus-category-mode-map
1035 (setq gnus-category-mode-map (make-sparse-keymap))
1036 (suppress-keymap gnus-category-mode-map)
1038 (gnus-define-keys gnus-category-mode-map
1039 "q" gnus-category-exit
1040 "k" gnus-category-kill
1041 "c" gnus-category-copy
1042 "a" gnus-category-add
1043 "p" gnus-category-edit-predicate
1044 "g" gnus-category-edit-groups
1045 "s" gnus-category-edit-score
1046 "l" gnus-category-list
1048 "\C-c\C-i" gnus-info-find-node
1049 "\C-c\C-b" gnus-bug))
1051 (defvar gnus-category-menu-hook nil
1052 "*Hook run after the creation of the menu.")
1054 (defun gnus-category-make-menu-bar ()
1055 (gnus-turn-off-edit-menu 'category)
1056 (unless (boundp 'gnus-category-menu)
1058 gnus-category-menu gnus-category-mode-map ""
1060 ["Add" gnus-category-add t]
1061 ["Kill" gnus-category-kill t]
1062 ["Copy" gnus-category-copy t]
1063 ["Edit predicate" gnus-category-edit-predicate t]
1064 ["Edit score" gnus-category-edit-score t]
1065 ["Edit groups" gnus-category-edit-groups t]
1066 ["Exit" gnus-category-exit t]))
1068 (gnus-run-hooks 'gnus-category-menu-hook)))
1070 (defun gnus-category-mode ()
1071 "Major mode for listing and editing agent categories.
1073 All normal editing commands are switched off.
1074 \\<gnus-category-mode-map>
1075 For more in-depth information on this mode, read the manual
1076 (`\\[gnus-info-find-node]').
1078 The following commands are available:
1080 \\{gnus-category-mode-map}"
1082 (when (gnus-visual-p 'category-menu 'menu)
1083 (gnus-category-make-menu-bar))
1084 (kill-all-local-variables)
1085 (gnus-simplify-mode-line)
1086 (setq major-mode 'gnus-category-mode)
1087 (setq mode-name "Category")
1088 (gnus-set-default-directory)
1089 (setq mode-line-process nil)
1090 (use-local-map gnus-category-mode-map)
1091 (buffer-disable-undo)
1092 (setq truncate-lines t)
1093 (setq buffer-read-only t)
1094 (gnus-run-hooks 'gnus-category-mode-hook))
1096 (defalias 'gnus-category-position-point 'gnus-goto-colon)
1098 (defun gnus-category-insert-line (category)
1099 (let* ((gnus-tmp-name (car category))
1100 (gnus-tmp-groups (length (cadddr category))))
1102 (gnus-add-text-properties
1106 (eval gnus-category-line-format-spec))
1107 (list 'gnus-category gnus-tmp-name))))
1109 (defun gnus-enter-category-buffer ()
1110 "Go to the Category buffer."
1112 (gnus-category-setup-buffer)
1113 (gnus-configure-windows 'category)
1114 (gnus-category-prepare))
1116 (defun gnus-category-setup-buffer ()
1117 (unless (get-buffer gnus-category-buffer)
1119 (set-buffer (gnus-get-buffer-create gnus-category-buffer))
1120 (gnus-category-mode))))
1122 (defun gnus-category-prepare ()
1123 (gnus-set-format 'category-mode)
1124 (gnus-set-format 'category t)
1125 (let ((alist gnus-category-alist)
1126 (buffer-read-only nil))
1129 (gnus-category-insert-line (pop alist)))
1130 (goto-char (point-min))
1131 (gnus-category-position-point)))
1133 (defun gnus-category-name ()
1134 (or (get-text-property (gnus-point-at-bol) 'gnus-category)
1135 (error "No category on the current line")))
1137 (defun gnus-category-read ()
1138 "Read the category alist."
1139 (setq gnus-category-alist
1140 (or (gnus-agent-read-file
1141 (nnheader-concat gnus-agent-directory "lib/categories"))
1142 (list (list 'default 'short nil nil)))))
1144 (defun gnus-category-write ()
1145 "Write the category alist."
1146 (setq gnus-category-predicate-cache nil
1147 gnus-category-group-cache nil)
1148 (with-temp-file (nnheader-concat gnus-agent-directory "lib/categories")
1149 (prin1 gnus-category-alist (current-buffer))))
1151 (defun gnus-category-edit-predicate (category)
1152 "Edit the predicate for CATEGORY."
1153 (interactive (list (gnus-category-name)))
1154 (let ((info (assq category gnus-category-alist)))
1156 (cadr info) (format "Editing the predicate for category %s" category)
1157 `(lambda (predicate)
1158 (setf (cadr (assq ',category gnus-category-alist)) predicate)
1159 (gnus-category-write)
1160 (gnus-category-list)))))
1162 (defun gnus-category-edit-score (category)
1163 "Edit the score expression for CATEGORY."
1164 (interactive (list (gnus-category-name)))
1165 (let ((info (assq category gnus-category-alist)))
1168 (format "Editing the score expression for category %s" category)
1170 (setf (caddr (assq ',category gnus-category-alist)) groups)
1171 (gnus-category-write)
1172 (gnus-category-list)))))
1174 (defun gnus-category-edit-groups (category)
1175 "Edit the group list for CATEGORY."
1176 (interactive (list (gnus-category-name)))
1177 (let ((info (assq category gnus-category-alist)))
1179 (cadddr info) (format "Editing the group list for category %s" category)
1181 (setf (cadddr (assq ',category gnus-category-alist)) groups)
1182 (gnus-category-write)
1183 (gnus-category-list)))))
1185 (defun gnus-category-kill (category)
1186 "Kill the current category."
1187 (interactive (list (gnus-category-name)))
1188 (let ((info (assq category gnus-category-alist))
1189 (buffer-read-only nil))
1191 (gnus-category-write)
1192 (setq gnus-category-alist (delq info gnus-category-alist))))
1194 (defun gnus-category-copy (category to)
1195 "Copy the current category."
1196 (interactive (list (gnus-category-name) (intern (read-string "New name: "))))
1197 (let ((info (assq category gnus-category-alist)))
1198 (push (list to (gnus-copy-sequence (cadr info))
1199 (gnus-copy-sequence (caddr info)) nil)
1200 gnus-category-alist)
1201 (gnus-category-write)
1202 (gnus-category-list)))
1204 (defun gnus-category-add (category)
1205 "Create a new category."
1206 (interactive "SCategory name: ")
1207 (when (assq category gnus-category-alist)
1208 (error "Category %s already exists" category))
1209 (push (list category 'false nil nil)
1210 gnus-category-alist)
1211 (gnus-category-write)
1212 (gnus-category-list))
1214 (defun gnus-category-list ()
1215 "List all categories."
1217 (gnus-category-prepare))
1219 (defun gnus-category-exit ()
1220 "Return to the group buffer."
1222 (kill-buffer (current-buffer))
1223 (gnus-configure-windows 'group t))
1225 ;; To avoid having 8-bit characters in the source file.
1226 (defvar gnus-category-not (list '! 'not (intern (format "%c" 172))))
1228 (defvar gnus-category-predicate-alist
1229 '((spam . gnus-agent-spam-p)
1230 (short . gnus-agent-short-p)
1231 (long . gnus-agent-long-p)
1232 (low . gnus-agent-low-scored-p)
1233 (high . gnus-agent-high-scored-p)
1234 (true . gnus-agent-true)
1235 (false . gnus-agent-false))
1236 "Mapping from short score predicate symbols to predicate functions.")
1238 (defun gnus-agent-spam-p ()
1239 "Say whether an article is spam or not."
1240 (unless gnus-agent-spam-hashtb
1241 (setq gnus-agent-spam-hashtb (gnus-make-hashtable 1000)))
1242 (if (not (equal (mail-header-references gnus-headers) ""))
1244 (let ((string (gnus-simplify-subject (mail-header-subject gnus-headers))))
1246 (gnus-gethash string gnus-agent-spam-hashtb)
1247 (gnus-sethash string t gnus-agent-spam-hashtb)))))
1249 (defun gnus-agent-short-p ()
1250 "Say whether an article is short or not."
1251 (< (mail-header-lines gnus-headers) gnus-agent-short-article))
1253 (defun gnus-agent-long-p ()
1254 "Say whether an article is long or not."
1255 (> (mail-header-lines gnus-headers) gnus-agent-long-article))
1257 (defun gnus-agent-low-scored-p ()
1258 "Say whether an article has a low score or not."
1259 (< gnus-score gnus-agent-low-score))
1261 (defun gnus-agent-high-scored-p ()
1262 "Say whether an article has a high score or not."
1263 (> gnus-score gnus-agent-high-score))
1265 (defun gnus-category-make-function (cat)
1266 "Make a function from category CAT."
1267 `(lambda () ,(gnus-category-make-function-1 cat)))
1269 (defun gnus-agent-true ()
1273 (defun gnus-agent-false ()
1277 (defun gnus-category-make-function-1 (cat)
1278 "Make a function from category CAT."
1280 ;; Functions are just returned as is.
1282 (gnus-functionp cat))
1283 `(,(or (cdr (assq cat gnus-category-predicate-alist))
1285 ;; More complex category.
1288 ((memq (car cat) '(& and))
1290 ((memq (car cat) '(| or))
1292 ((memq (car cat) gnus-category-not)
1294 ,@(mapcar 'gnus-category-make-function-1 (cdr cat))))
1296 (error "Unknown category type: %s" cat))))
1298 (defun gnus-get-predicate (predicate)
1299 "Return the predicate for CATEGORY."
1300 (or (cdr (assoc predicate gnus-category-predicate-cache))
1301 (cdar (push (cons predicate
1302 (gnus-category-make-function predicate))
1303 gnus-category-predicate-cache))))
1305 (defun gnus-group-category (group)
1306 "Return the category GROUP belongs to."
1307 (unless gnus-category-group-cache
1308 (setq gnus-category-group-cache (gnus-make-hashtable 1000))
1309 (let ((cs gnus-category-alist)
1311 (while (setq cat (pop cs))
1312 (setq groups (cadddr cat))
1314 (gnus-sethash (pop groups) cat gnus-category-group-cache)))))
1315 (or (gnus-gethash group gnus-category-group-cache)
1316 (assq 'default gnus-category-alist)))
1318 (defun gnus-agent-expire ()
1319 "Expire all old articles."
1321 (let ((methods gnus-agent-covered-methods)
1322 (day (- (time-to-days (current-time)) gnus-agent-expire-days))
1323 gnus-command-method sym group articles
1324 history overview file histories elem art nov-file low info
1325 unreads marked article)
1327 (setq overview (gnus-get-buffer-create " *expire overview*"))
1328 (while (setq gnus-command-method (pop methods))
1329 (let ((expiry-hashtb (gnus-make-hashtable 1023)))
1330 (gnus-agent-open-history)
1332 (setq gnus-agent-current-history
1333 (setq history (gnus-agent-history-buffer))))
1334 (goto-char (point-min))
1335 (when (> (buffer-size) 1)
1336 (goto-char (point-min))
1338 (skip-chars-forward "^\t")
1339 (if (> (read (current-buffer)) day)
1340 ;; New article; we don't expire it.
1342 ;; Old article. Schedule it for possible nuking.
1344 (setq sym (let ((obarray expiry-hashtb))
1345 (read (current-buffer))))
1347 (set sym (cons (cons (read (current-buffer)) (point))
1348 (symbol-value sym)))
1349 (set sym (list (cons (read (current-buffer)) (point)))))
1350 (skip-chars-forward " "))
1352 ;; We now have all articles that can possibly be expired.
1355 (setq group (symbol-name sym)
1356 articles (sort (symbol-value sym) 'car-less-than-car)
1357 low (car (gnus-active group))
1358 info (gnus-get-info group)
1359 unreads (ignore-errors (gnus-list-of-unread-articles group))
1360 marked (nconc (gnus-uncompress-range
1361 (cdr (assq 'tick (gnus-info-marks info))))
1362 (gnus-uncompress-range
1364 (gnus-info-marks info)))))
1365 nov-file (gnus-agent-article-name ".overview" group))
1366 (gnus-agent-load-alist group)
1367 (gnus-message 5 "Expiring articles in %s" group)
1368 (set-buffer overview)
1370 (when (file-exists-p nov-file)
1371 (nnheader-insert-file-contents nov-file))
1372 (goto-char (point-min))
1374 (while (setq elem (pop articles))
1375 (setq article (car elem))
1376 (when (or (null low)
1378 gnus-agent-expire-all
1379 (and (not (memq article unreads))
1380 (not (memq article marked))))
1381 ;; Find and nuke the NOV line.
1382 (while (and (not (eobp))
1384 (setq art (read (current-buffer)))))
1387 (gnus-agent-article-name
1388 (number-to-string art) group))
1390 ;; Remove old NOV lines that have no articles.
1391 (gnus-delete-line)))
1396 ;; Nuke the article.
1397 (when (file-exists-p (setq file (gnus-agent-article-name
1398 (number-to-string article)
1401 ;; Schedule the history line for nuking.
1402 (push (cdr elem) histories)))
1403 (gnus-make-directory (file-name-directory nov-file))
1404 (write-region-as-specified-coding-system
1405 (point-min) (point-max) nov-file nil 'silent
1406 gnus-agent-file-coding-system)
1407 ;; Delete the unwanted entries in the alist.
1408 (setq gnus-agent-article-alist
1409 (sort gnus-agent-article-alist 'car-less-than-car))
1410 (let* ((alist gnus-agent-article-alist)
1411 (prev (cons nil alist))
1415 (<= (caar alist) article))
1416 (if (or (not (cdar alist))
1418 (gnus-agent-article-name
1423 (push (caar alist) expired)
1424 (setcdr prev (setq alist (cdr alist))))
1426 alist (cdr alist))))
1427 (setq gnus-agent-article-alist (cdr first))
1428 (gnus-agent-save-alist group)
1429 ;; Mark all articles up to the first article
1430 ;; in `gnus-article-alist' as read.
1431 (when (and info (caar gnus-agent-article-alist))
1432 (setcar (nthcdr 2 info)
1435 (cons 1 (- (caar gnus-agent-article-alist) 1)))))
1436 ;; Maybe everything has been expired from `gnus-article-alist'
1437 ;; and so the above marking as read could not be conducted,
1438 ;; or there are expired article within the range of the alist.
1441 (or (not (caar gnus-agent-article-alist))
1443 (caar gnus-agent-article-alist))))
1444 (setcar (nthcdr 2 info)
1447 (nreverse expired))))
1449 (concat "(gnus-group-set-info '"
1450 (gnus-prin1-to-string info)
1453 (set-buffer history)
1454 (setq histories (nreverse (sort histories '<)))
1456 (goto-char (pop histories))
1458 (gnus-agent-save-history)
1459 (gnus-agent-close-history))
1460 (gnus-message 4 "Expiry...done"))))))
1463 (defun gnus-agent-batch ()
1465 (let ((init-file-user "")
1466 (gnus-always-read-dribble-file t))
1468 (gnus-group-send-drafts)
1469 (gnus-agent-fetch-session))
1471 (provide 'gnus-agent)
1473 ;;; gnus-agent.el ends here