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 'no-conversion)
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
335 "nndraft:queue" 'gnus-dummy '((gnus-draft-mode)))))
337 (defun gnus-agent-send-mail ()
339 (funcall gnus-agent-send-mail-function)
340 (goto-char (point-min))
342 (concat "^" (regexp-quote mail-header-separator) "\n"))
344 (gnus-agent-insert-meta-information 'mail)
345 (gnus-request-accept-article "nndraft:queue" nil t t)))
347 (defun gnus-agent-insert-meta-information (type &optional method)
348 "Insert meta-information into the message that says how it's to be posted.
349 TYPE can be either `mail' or `news'. If the latter METHOD can
352 (message-remove-header gnus-agent-meta-information-header)
353 (goto-char (point-min))
354 (insert gnus-agent-meta-information-header ": "
355 (symbol-name type) " " (format "%S" method)
358 (while (search-backward "\n" nil t)
359 (replace-match "\\n" t t))))
362 ;;; Group mode commands
365 (defun gnus-agent-fetch-groups (n)
366 "Put all new articles in the current groups into the Agent."
368 (gnus-group-iterate n 'gnus-agent-fetch-group))
370 (defun gnus-agent-fetch-group (group)
371 "Put all new articles in GROUP into the Agent."
372 (interactive (list (gnus-group-group-name)))
374 (error "No group on the current line"))
375 (let ((gnus-command-method (gnus-find-method-for-group group)))
376 (gnus-agent-with-fetch
377 (gnus-agent-fetch-group-1 group gnus-command-method)
378 (gnus-message 5 "Fetching %s...done" group))))
380 (defun gnus-agent-add-group (category arg)
381 "Add the current group to an agent category."
387 (mapcar (lambda (cat) (list (symbol-name (car cat))))
391 (let ((cat (assq category gnus-category-alist))
393 (gnus-group-iterate arg
395 (when (cadddr (setq c (gnus-group-category group)))
396 (setf (cadddr c) (delete group (cadddr c))))
397 (push group groups)))
398 (setf (cadddr cat) (nconc (cadddr cat) groups))
399 (gnus-category-write)))
402 ;;; Server mode commands
405 (defun gnus-agent-add-server (server)
406 "Enroll SERVER in the agent program."
407 (interactive (list (gnus-server-server-name)))
409 (error "No server on the current line"))
410 (let ((method (gnus-server-get-method nil (gnus-server-server-name))))
411 (when (member method gnus-agent-covered-methods)
412 (error "Server already in the agent program"))
413 (push method gnus-agent-covered-methods)
414 (gnus-agent-write-servers)
415 (message "Entered %s into the Agent" server)))
417 (defun gnus-agent-remove-server (server)
418 "Remove SERVER from the agent program."
419 (interactive (list (gnus-server-server-name)))
421 (error "No server on the current line"))
422 (let ((method (gnus-server-get-method nil (gnus-server-server-name))))
423 (unless (member method gnus-agent-covered-methods)
424 (error "Server not in the agent program"))
425 (setq gnus-agent-covered-methods
426 (delete method gnus-agent-covered-methods))
427 (gnus-agent-write-servers)
428 (message "Removed %s from the agent" server)))
430 (defun gnus-agent-read-servers ()
431 "Read the alist of covered servers."
432 (setq gnus-agent-covered-methods
433 (gnus-agent-read-file
434 (nnheader-concat gnus-agent-directory "lib/servers"))))
436 (defun gnus-agent-write-servers ()
437 "Write the alist of covered servers."
438 (with-temp-file (nnheader-concat gnus-agent-directory "lib/servers")
439 (prin1 gnus-agent-covered-methods (current-buffer))))
445 (defun gnus-agent-mark-article (n &optional unmark)
446 "Mark the next N articles as downloadable.
447 If N is negative, mark backward instead. If UNMARK is non-nil, remove
448 the mark instead. The difference between N and the actual number of
449 articles marked is returned."
451 (let ((backward (< n 0))
456 (gnus-summary-set-agent-mark
457 (gnus-summary-article-number) unmark)
458 (zerop (gnus-summary-next-subject (if backward -1 1) nil t))))
461 (gnus-message 7 "No more articles"))
462 (gnus-summary-recenter)
463 (gnus-summary-position-point)
466 (defun gnus-agent-unmark-article (n)
467 "Remove the downloadable mark from the next N articles.
468 If N is negative, unmark backward instead. The difference between N and
469 the actual number of articles unmarked is returned."
471 (gnus-agent-mark-article n t))
473 (defun gnus-agent-toggle-mark (n)
474 "Toggle the downloadable mark from the next N articles.
475 If N is negative, toggle backward instead. The difference between N and
476 the actual number of articles toggled is returned."
478 (gnus-agent-mark-article n 'toggle))
480 (defun gnus-summary-set-agent-mark (article &optional unmark)
481 "Mark ARTICLE as downloadable."
482 (let ((unmark (if (and (not (null unmark)) (not (eq t unmark)))
483 (memq article gnus-newsgroup-downloadable)
487 (setq gnus-newsgroup-downloadable
488 (delq article gnus-newsgroup-downloadable))
489 (push article gnus-newsgroup-undownloaded))
490 (setq gnus-newsgroup-undownloaded
491 (delq article gnus-newsgroup-undownloaded))
492 (push article gnus-newsgroup-downloadable))
493 (gnus-summary-update-mark
494 (if unmark gnus-undownloaded-mark gnus-downloadable-mark)
497 (defun gnus-agent-get-undownloaded-list ()
498 "Mark all unfetched articles as read."
499 (let ((gnus-command-method (gnus-find-method-for-group gnus-newsgroup-name)))
500 (when (and (not gnus-plugged)
501 (gnus-agent-method-p gnus-command-method))
502 (gnus-agent-load-alist gnus-newsgroup-name)
503 (let ((articles gnus-newsgroup-unreads)
505 (while (setq article (pop articles))
506 (unless (or (cdr (assq article gnus-agent-article-alist))
507 (memq article gnus-newsgroup-downloadable))
508 (push article gnus-newsgroup-undownloaded)))))))
510 (defun gnus-agent-catchup ()
511 "Mark all undownloaded articles as read."
514 (while gnus-newsgroup-undownloaded
515 (gnus-summary-mark-article
516 (pop gnus-newsgroup-undownloaded) gnus-catchup-mark)))
517 (gnus-summary-position-point))
520 ;;; Internal functions
523 (defun gnus-agent-save-active (method)
524 (when (gnus-agent-method-p method)
525 (let* ((gnus-command-method method)
526 (file (gnus-agent-lib-file "active")))
527 (gnus-make-directory (file-name-directory file))
528 (let ((coding-system-for-write gnus-agent-file-coding-system))
529 (write-region (point-min) (point-max) file nil 'silent))
530 (when (file-exists-p (gnus-agent-lib-file "groups"))
531 (delete-file (gnus-agent-lib-file "groups"))))))
533 (defun gnus-agent-save-groups (method)
534 (let* ((gnus-command-method method)
535 (file (gnus-agent-lib-file "groups")))
536 (gnus-make-directory (file-name-directory file))
537 (let ((coding-system-for-write gnus-agent-file-coding-system))
538 (write-region (point-min) (point-max) file nil 'silent))
539 (when (file-exists-p (gnus-agent-lib-file "active"))
540 (delete-file (gnus-agent-lib-file "active")))))
542 (defun gnus-agent-save-group-info (method group active)
543 (when (gnus-agent-method-p method)
544 (let* ((gnus-command-method method)
545 (file (if nntp-server-list-active-group
546 (gnus-agent-lib-file "active")
547 (gnus-agent-lib-file "groups"))))
548 (gnus-make-directory (file-name-directory file))
550 (when (file-exists-p file)
551 (nnheader-insert-file-contents file))
552 (goto-char (point-min))
553 (if nntp-server-list-active-group
555 (when (re-search-forward
556 (concat "^" (regexp-quote group) " ") nil t)
558 (insert group " " (number-to-string (cdr active)) " "
559 (number-to-string (car active)) " y\n"))
560 (when (re-search-forward (concat (regexp-quote group) "\\($\\| \\)") nil t)
562 (insert-buffer-substring nntp-server-buffer))))))
564 (defun gnus-agent-group-path (group)
565 "Translate GROUP into a path."
566 (if nnmail-use-long-file-names
567 (gnus-group-real-name group)
568 (nnheader-replace-chars-in-string
569 (nnheader-translate-file-chars (gnus-group-real-name group))
574 (defun gnus-agent-method-p (method)
575 "Say whether METHOD is covered by the agent."
576 (member method gnus-agent-covered-methods))
578 (defun gnus-agent-get-function (method)
579 (if (and (not gnus-plugged)
580 (gnus-agent-method-p method))
586 ;;; History functions
588 (defun gnus-agent-history-buffer ()
589 (cdr (assoc (gnus-agent-method) gnus-agent-history-buffers)))
591 (defun gnus-agent-open-history ()
593 (push (cons (gnus-agent-method)
594 (set-buffer (gnus-get-buffer-create
595 (format " *Gnus agent %s history*"
596 (gnus-agent-method)))))
597 gnus-agent-history-buffers)
600 (let ((file (gnus-agent-lib-file "history")))
601 (when (file-exists-p file)
603 (set (make-local-variable 'gnus-agent-file-name) file))))
605 (defun gnus-agent-save-history ()
607 (set-buffer gnus-agent-current-history)
608 (gnus-make-directory (file-name-directory gnus-agent-file-name))
609 (let ((coding-system-for-write gnus-agent-file-coding-system))
610 (write-region (1+ (point-min)) (point-max)
611 gnus-agent-file-name nil 'silent))))
613 (defun gnus-agent-close-history ()
614 (when (gnus-buffer-live-p gnus-agent-current-history)
615 (kill-buffer gnus-agent-current-history)
616 (setq gnus-agent-history-buffers
617 (delq (assoc (gnus-agent-method) gnus-agent-history-buffers)
618 gnus-agent-history-buffers))))
620 (defun gnus-agent-enter-history (id group-arts date)
622 (set-buffer gnus-agent-current-history)
623 (goto-char (point-max))
624 (insert id "\t" (number-to-string date) "\t")
626 (insert (caar group-arts) " " (number-to-string (cdr (pop group-arts)))
630 (defun gnus-agent-article-in-history-p (id)
632 (set-buffer (gnus-agent-history-buffer))
633 (goto-char (point-min))
634 (search-forward (concat "\n" id "\t") nil t)))
636 (defun gnus-agent-history-path (id)
638 (set-buffer (gnus-agent-history-buffer))
639 (goto-char (point-min))
640 (when (search-forward (concat "\n" id "\t") nil t)
641 (let ((method (gnus-agent-method)))
643 (while (not (numberp (setq group (read (current-buffer)))))
644 (push (concat method "/" group) paths))
645 (nreverse paths))))))
651 (defun gnus-agent-fetch-articles (group articles)
652 "Fetch ARTICLES from GROUP and put them into the Agent."
654 ;; Prune off articles that we have already fetched.
656 (cdr (assq (car articles) gnus-agent-article-alist)))
658 (let ((arts articles))
660 (if (cdr (assq (cadr arts) gnus-agent-article-alist))
661 (setcdr arts (cddr arts))
662 (setq arts (cdr arts)))))
665 (gnus-agent-directory)
666 (gnus-agent-group-path group) "/"))
667 (date (time-to-days (current-time)))
670 (gnus-make-directory dir)
671 (gnus-message 7 "Fetching articles for %s..." group)
672 ;; Fetch the articles from the backend.
673 (if (gnus-check-backend-function 'retrieve-articles group)
674 (setq pos (gnus-retrieve-articles articles group))
677 (while (setq article (pop articles))
678 (when (gnus-request-article article group)
679 (goto-char (point-max))
680 (push (cons article (point)) pos)
681 (insert-buffer-substring nntp-server-buffer)))
682 (copy-to-buffer nntp-server-buffer (point-min) (point-max))
683 (setq pos (nreverse pos)))))
684 ;; Then save these articles into the Agent.
686 (set-buffer nntp-server-buffer)
688 (narrow-to-region (cdar pos) (or (cdadr pos) (point-max)))
689 (goto-char (point-min))
690 (when (search-forward "\n\n" nil t)
691 (when (search-backward "\nXrefs: " nil t)
692 ;; Handle crossposting.
693 (skip-chars-forward "^ ")
694 (skip-chars-forward " ")
696 (while (looking-at "\\([^: \n]+\\):\\([0-9]+\\) +")
697 (push (cons (buffer-substring (match-beginning 1)
699 (buffer-substring (match-beginning 2)
702 (goto-char (match-end 0)))
703 (gnus-agent-crosspost crosses (caar pos))))
704 (goto-char (point-min))
705 (if (not (re-search-forward "^Message-ID: *<\\([^>\n]+\\)>" nil t))
706 (setq id "No-Message-ID-in-article")
707 (setq id (buffer-substring (match-beginning 1) (match-end 1))))
708 (let ((coding-system-for-write
709 gnus-agent-file-coding-system))
710 (write-region (point-min) (point-max)
711 (concat dir (number-to-string (caar pos)))
713 (when (setq elem (assq (caar pos) gnus-agent-article-alist))
715 (gnus-agent-enter-history
716 id (or crosses (list (cons group (caar pos)))) date)
719 (gnus-agent-save-alist group)))))
721 (defun gnus-agent-crosspost (crosses article)
722 (let (gnus-agent-article-alist group alist beg end)
724 (set-buffer gnus-agent-overview-buffer)
725 (when (nnheader-find-nov-line article)
728 (setq end (progn (forward-line 1) (point)))))
730 (setq group (caar crosses))
731 (unless (setq alist (assoc group gnus-agent-group-alist))
732 (push (setq alist (list group (gnus-agent-load-alist (caar crosses))))
733 gnus-agent-group-alist))
734 (setcdr alist (cons (cons (cdar crosses) t) (cdr alist)))
736 (set-buffer (gnus-get-buffer-create (format " *Gnus agent overview %s*"
738 (when (= (point-max) (point-min))
739 (push (cons group (current-buffer)) gnus-agent-buffer-alist)
741 (nnheader-insert-file-contents
742 (gnus-agent-article-name ".overview" group))))
743 (nnheader-find-nov-line (string-to-number (cdar crosses)))
744 (insert (string-to-number (cdar crosses)))
745 (insert-buffer-substring gnus-agent-overview-buffer beg end))
748 (defun gnus-agent-flush-cache ()
750 (while gnus-agent-buffer-alist
751 (set-buffer (cdar gnus-agent-buffer-alist))
752 (let ((coding-system-for-write
753 gnus-agent-file-coding-system))
754 (write-region (point-min) (point-max)
755 (gnus-agent-article-name ".overview"
756 (caar gnus-agent-buffer-alist))
758 (pop gnus-agent-buffer-alist))
759 (while gnus-agent-group-alist
760 (with-temp-file (caar gnus-agent-group-alist)
761 (princ (cdar gnus-agent-group-alist))
763 (pop gnus-agent-group-alist))))
765 (defun gnus-agent-fetch-headers (group &optional force)
766 (let ((articles (if (gnus-agent-load-alist group)
767 (gnus-sorted-intersection
768 (gnus-list-of-unread-articles group)
769 (gnus-uncompress-range
770 (cons (1+ (caar (last gnus-agent-article-alist)))
771 (cdr (gnus-active group)))))
772 (gnus-list-of-unread-articles group)))
773 (gnus-decode-encoded-word-function 'identity))
776 (gnus-message 7 "Fetching headers for %s..." group)
778 (set-buffer nntp-server-buffer)
779 (unless (eq 'nov (gnus-retrieve-headers articles group))
780 (nnvirtual-convert-headers))
781 ;; Save these headers for later processing.
782 (copy-to-buffer gnus-agent-overview-buffer (point-min) (point-max))
785 (setq file (gnus-agent-article-name ".overview" group)))
786 (gnus-agent-braid-nov group articles file))
787 (gnus-make-directory (nnheader-translate-file-chars
788 (file-name-directory file)))
789 (let ((coding-system-for-write
790 gnus-agent-file-coding-system))
791 (write-region (point-min) (point-max) file nil 'silent))
792 (gnus-agent-save-alist group articles nil)
793 (gnus-agent-enter-history
794 "last-header-fetched-for-session"
795 (list (cons group (nth (- (length articles) 1) articles)))
796 (time-to-days (current-time)))
799 (defsubst gnus-agent-copy-nov-line (article)
801 (set-buffer gnus-agent-overview-buffer)
803 (if (eq article (read (current-buffer)))
804 (setq e (progn (forward-line 1) (point)))
808 (set-buffer nntp-server-buffer)
809 (insert-buffer-substring gnus-agent-overview-buffer b e)))
811 (defun gnus-agent-braid-nov (group articles file)
812 (set-buffer gnus-agent-overview-buffer)
813 (goto-char (point-min))
814 (set-buffer nntp-server-buffer)
816 (nnheader-insert-file-contents file)
817 (goto-char (point-max))
818 (if (or (= (point-min) (point-max))
821 (< (read (current-buffer)) (car articles))))
822 ;; We have only headers that are after the older headers,
823 ;; so we just append them.
825 (goto-char (point-max))
826 (insert-buffer-substring gnus-agent-overview-buffer))
827 ;; We do it the hard way.
828 (nnheader-find-nov-line (car articles))
829 (gnus-agent-copy-nov-line (car articles))
833 (while (and (not (eobp))
834 (< (read (current-buffer)) (car articles)))
838 (gnus-agent-copy-nov-line (car articles))
839 (setq articles (cdr articles))))
842 (set-buffer gnus-agent-overview-buffer)
845 (set-buffer nntp-server-buffer)
846 (insert-buffer-substring gnus-agent-overview-buffer b e)))))
848 (defun gnus-agent-load-alist (group &optional dir)
849 "Load the article-state alist for GROUP."
850 (setq gnus-agent-article-alist
851 (gnus-agent-read-file
853 (concat dir ".agentview")
854 (gnus-agent-article-name ".agentview" group)))))
856 (defun gnus-agent-save-alist (group &optional articles state dir)
857 "Save the article-state alist for GROUP."
858 (with-temp-file (if dir
859 (concat dir ".agentview")
860 (gnus-agent-article-name ".agentview" group))
861 (princ (setq gnus-agent-article-alist
862 (nconc gnus-agent-article-alist
863 (mapcar (lambda (article) (cons article state))
868 (defun gnus-agent-article-name (article group)
869 (concat (gnus-agent-directory) (gnus-agent-group-path group) "/"
870 (if (stringp article) article (string-to-number article))))
873 (defun gnus-agent-batch-fetch ()
874 "Start Gnus and fetch session."
877 (gnus-agent-fetch-session)
880 (defun gnus-agent-fetch-session ()
881 "Fetch all articles and headers that are eligible for fetching."
883 (unless gnus-agent-covered-methods
884 (error "No servers are covered by the Gnus agent"))
886 (error "Can't fetch articles while Gnus is unplugged"))
887 (let ((methods gnus-agent-covered-methods)
888 groups group gnus-command-method)
891 (setq gnus-command-method (car methods))
892 (when (or (gnus-server-opened gnus-command-method)
893 (gnus-open-server gnus-command-method))
894 (setq groups (gnus-groups-from-server (car methods)))
895 (gnus-agent-with-fetch
896 (while (setq group (pop groups))
897 (when (<= (gnus-group-level group) gnus-agent-handle-level)
898 (gnus-agent-fetch-group-1 group gnus-command-method)))))
900 (gnus-message 6 "Finished fetching articles into the Gnus agent"))))
902 (defun gnus-agent-fetch-group-1 (group method)
904 (let ((gnus-command-method method)
905 (gnus-newsgroup-name group)
906 gnus-newsgroup-dependencies gnus-newsgroup-headers
907 gnus-newsgroup-scored gnus-headers gnus-score
908 gnus-use-cache articles arts
909 category predicate info marks score-param)
911 (when (and (or (gnus-active group) (gnus-activate-group group))
912 (setq articles (gnus-agent-fetch-headers group)))
913 ;; Parse them and see which articles we want to fetch.
914 (setq gnus-newsgroup-dependencies
915 (make-vector (length articles) 0))
916 ;; No need to call `gnus-get-newsgroup-headers-xover' with
917 ;; the entire .overview for group as we still have the just
918 ;; downloaded headers in `gnus-agent-overview-buffer'.
919 (let ((nntp-server-buffer gnus-agent-overview-buffer))
920 (setq gnus-newsgroup-headers
921 (gnus-get-newsgroup-headers-xover articles nil nil group)))
922 (setq category (gnus-group-category group))
925 (or (gnus-group-get-parameter group 'agent-predicate t)
927 ;; Do we want to download everything, or nothing?
928 (if (or (eq (caaddr predicate) 'gnus-agent-true)
929 (eq (caaddr predicate) 'gnus-agent-false))
931 (setq arts (symbol-value
932 (cadr (assoc (caaddr predicate)
933 '((gnus-agent-true articles)
934 (gnus-agent-false nil))))))
935 ;; No, we need to decide what we want.
939 (gnus-group-get-parameter group 'agent-score t)
942 (require 'gnus-score)
943 (if (eq score-method 'file)
945 (gnus-score-load-files
946 (gnus-all-score-files group)))
948 (while (setq list (car entries))
949 (push (car list) score-file)
950 (setq list (cdr list))
952 (when (member (caar list)
953 gnus-agent-scoreable-headers)
954 (push (car list) score-file))
955 (setq list (cdr list)))
957 (append score-param (list (nreverse score-file)))
958 score-file nil entries (cdr entries)))
960 (if (stringp (car score-method))
962 (list (list score-method)))))))
964 (gnus-score-headers score-param))
966 (while (setq gnus-headers (pop gnus-newsgroup-headers))
968 (or (cdr (assq (mail-header-number gnus-headers)
969 gnus-newsgroup-scored))
970 gnus-summary-default-score))
971 (when (funcall predicate)
972 (push (mail-header-number gnus-headers)
974 ;; Fetch the articles.
976 (gnus-agent-fetch-articles group arts)))
977 ;; Perhaps we have some additional articles to fetch.
978 (setq arts (assq 'download (gnus-info-marks
979 (setq info (gnus-get-info group)))))
981 (gnus-agent-fetch-articles
982 group (gnus-uncompress-range (cdr arts)))
983 (setq marks (delq arts (gnus-info-marks info)))
984 (gnus-info-set-marks info marks)
986 (concat "(gnus-group-set-info '"
987 (gnus-prin1-to-string info)
991 ;;; Agent Category Mode
994 (defvar gnus-category-mode-hook nil
995 "Hook run in `gnus-category-mode' buffers.")
997 (defvar gnus-category-line-format " %(%20c%): %g\n"
998 "Format of category lines.")
1000 (defvar gnus-category-mode-line-format "Gnus: %%b"
1001 "The format specification for the category mode line.")
1003 (defvar gnus-agent-short-article 100
1004 "Articles that have fewer lines than this are short.")
1006 (defvar gnus-agent-long-article 200
1007 "Articles that have more lines than this are long.")
1009 (defvar gnus-agent-low-score 0
1010 "Articles that have a score lower than this have a low score.")
1012 (defvar gnus-agent-high-score 0
1013 "Articles that have a score higher than this have a high score.")
1016 ;;; Internal variables.
1018 (defvar gnus-category-buffer "*Agent Category*")
1020 (defvar gnus-category-line-format-alist
1021 `((?c gnus-tmp-name ?s)
1022 (?g gnus-tmp-groups ?d)))
1024 (defvar gnus-category-mode-line-format-alist
1025 `((?u user-defined ?s)))
1027 (defvar gnus-category-line-format-spec nil)
1028 (defvar gnus-category-mode-line-format-spec nil)
1030 (defvar gnus-category-mode-map nil)
1031 (put 'gnus-category-mode 'mode-class 'special)
1033 (unless gnus-category-mode-map
1034 (setq gnus-category-mode-map (make-sparse-keymap))
1035 (suppress-keymap gnus-category-mode-map)
1037 (gnus-define-keys gnus-category-mode-map
1038 "q" gnus-category-exit
1039 "k" gnus-category-kill
1040 "c" gnus-category-copy
1041 "a" gnus-category-add
1042 "p" gnus-category-edit-predicate
1043 "g" gnus-category-edit-groups
1044 "s" gnus-category-edit-score
1045 "l" gnus-category-list
1047 "\C-c\C-i" gnus-info-find-node
1048 "\C-c\C-b" gnus-bug))
1050 (defvar gnus-category-menu-hook nil
1051 "*Hook run after the creation of the menu.")
1053 (defun gnus-category-make-menu-bar ()
1054 (gnus-turn-off-edit-menu 'category)
1055 (unless (boundp 'gnus-category-menu)
1057 gnus-category-menu gnus-category-mode-map ""
1059 ["Add" gnus-category-add t]
1060 ["Kill" gnus-category-kill t]
1061 ["Copy" gnus-category-copy t]
1062 ["Edit predicate" gnus-category-edit-predicate t]
1063 ["Edit score" gnus-category-edit-score t]
1064 ["Edit groups" gnus-category-edit-groups t]
1065 ["Exit" gnus-category-exit t]))
1067 (gnus-run-hooks 'gnus-category-menu-hook)))
1069 (defun gnus-category-mode ()
1070 "Major mode for listing and editing agent categories.
1072 All normal editing commands are switched off.
1073 \\<gnus-category-mode-map>
1074 For more in-depth information on this mode, read the manual
1075 (`\\[gnus-info-find-node]').
1077 The following commands are available:
1079 \\{gnus-category-mode-map}"
1081 (when (gnus-visual-p 'category-menu 'menu)
1082 (gnus-category-make-menu-bar))
1083 (kill-all-local-variables)
1084 (gnus-simplify-mode-line)
1085 (setq major-mode 'gnus-category-mode)
1086 (setq mode-name "Category")
1087 (gnus-set-default-directory)
1088 (setq mode-line-process nil)
1089 (use-local-map gnus-category-mode-map)
1090 (buffer-disable-undo)
1091 (setq truncate-lines t)
1092 (setq buffer-read-only t)
1093 (gnus-run-hooks 'gnus-category-mode-hook))
1095 (defalias 'gnus-category-position-point 'gnus-goto-colon)
1097 (defun gnus-category-insert-line (category)
1098 (let* ((gnus-tmp-name (car category))
1099 (gnus-tmp-groups (length (cadddr category))))
1101 (gnus-add-text-properties
1105 (eval gnus-category-line-format-spec))
1106 (list 'gnus-category gnus-tmp-name))))
1108 (defun gnus-enter-category-buffer ()
1109 "Go to the Category buffer."
1111 (gnus-category-setup-buffer)
1112 (gnus-configure-windows 'category)
1113 (gnus-category-prepare))
1115 (defun gnus-category-setup-buffer ()
1116 (unless (get-buffer gnus-category-buffer)
1118 (set-buffer (gnus-get-buffer-create gnus-category-buffer))
1119 (gnus-category-mode))))
1121 (defun gnus-category-prepare ()
1122 (gnus-set-format 'category-mode)
1123 (gnus-set-format 'category t)
1124 (let ((alist gnus-category-alist)
1125 (buffer-read-only nil))
1128 (gnus-category-insert-line (pop alist)))
1129 (goto-char (point-min))
1130 (gnus-category-position-point)))
1132 (defun gnus-category-name ()
1133 (or (get-text-property (gnus-point-at-bol) 'gnus-category)
1134 (error "No category on the current line")))
1136 (defun gnus-category-read ()
1137 "Read the category alist."
1138 (setq gnus-category-alist
1139 (or (gnus-agent-read-file
1140 (nnheader-concat gnus-agent-directory "lib/categories"))
1141 (list (list 'default 'short nil nil)))))
1143 (defun gnus-category-write ()
1144 "Write the category alist."
1145 (setq gnus-category-predicate-cache nil
1146 gnus-category-group-cache nil)
1147 (with-temp-file (nnheader-concat gnus-agent-directory "lib/categories")
1148 (prin1 gnus-category-alist (current-buffer))))
1150 (defun gnus-category-edit-predicate (category)
1151 "Edit the predicate for CATEGORY."
1152 (interactive (list (gnus-category-name)))
1153 (let ((info (assq category gnus-category-alist)))
1155 (cadr info) (format "Editing the predicate for category %s" category)
1156 `(lambda (predicate)
1157 (setf (cadr (assq ',category gnus-category-alist)) predicate)
1158 (gnus-category-write)
1159 (gnus-category-list)))))
1161 (defun gnus-category-edit-score (category)
1162 "Edit the score expression for CATEGORY."
1163 (interactive (list (gnus-category-name)))
1164 (let ((info (assq category gnus-category-alist)))
1167 (format "Editing the score expression for category %s" category)
1169 (setf (caddr (assq ',category gnus-category-alist)) groups)
1170 (gnus-category-write)
1171 (gnus-category-list)))))
1173 (defun gnus-category-edit-groups (category)
1174 "Edit the group list for CATEGORY."
1175 (interactive (list (gnus-category-name)))
1176 (let ((info (assq category gnus-category-alist)))
1178 (cadddr info) (format "Editing the group list for category %s" category)
1180 (setf (cadddr (assq ',category gnus-category-alist)) groups)
1181 (gnus-category-write)
1182 (gnus-category-list)))))
1184 (defun gnus-category-kill (category)
1185 "Kill the current category."
1186 (interactive (list (gnus-category-name)))
1187 (let ((info (assq category gnus-category-alist))
1188 (buffer-read-only nil))
1190 (gnus-category-write)
1191 (setq gnus-category-alist (delq info gnus-category-alist))))
1193 (defun gnus-category-copy (category to)
1194 "Copy the current category."
1195 (interactive (list (gnus-category-name) (intern (read-string "New name: "))))
1196 (let ((info (assq category gnus-category-alist)))
1197 (push (list to (gnus-copy-sequence (cadr info))
1198 (gnus-copy-sequence (caddr info)) nil)
1199 gnus-category-alist)
1200 (gnus-category-write)
1201 (gnus-category-list)))
1203 (defun gnus-category-add (category)
1204 "Create a new category."
1205 (interactive "SCategory name: ")
1206 (when (assq category gnus-category-alist)
1207 (error "Category %s already exists" category))
1208 (push (list category 'false nil nil)
1209 gnus-category-alist)
1210 (gnus-category-write)
1211 (gnus-category-list))
1213 (defun gnus-category-list ()
1214 "List all categories."
1216 (gnus-category-prepare))
1218 (defun gnus-category-exit ()
1219 "Return to the group buffer."
1221 (kill-buffer (current-buffer))
1222 (gnus-configure-windows 'group t))
1224 ;; To avoid having 8-bit characters in the source file.
1225 (defvar gnus-category-not (list '! 'not (intern (format "%c" 172))))
1227 (defvar gnus-category-predicate-alist
1228 '((spam . gnus-agent-spam-p)
1229 (short . gnus-agent-short-p)
1230 (long . gnus-agent-long-p)
1231 (low . gnus-agent-low-scored-p)
1232 (high . gnus-agent-high-scored-p)
1233 (true . gnus-agent-true)
1234 (false . gnus-agent-false))
1235 "Mapping from short score predicate symbols to predicate functions.")
1237 (defun gnus-agent-spam-p ()
1238 "Say whether an article is spam or not."
1239 (unless gnus-agent-spam-hashtb
1240 (setq gnus-agent-spam-hashtb (gnus-make-hashtable 1000)))
1241 (if (not (equal (mail-header-references gnus-headers) ""))
1243 (let ((string (gnus-simplify-subject (mail-header-subject gnus-headers))))
1245 (gnus-gethash string gnus-agent-spam-hashtb)
1246 (gnus-sethash string t gnus-agent-spam-hashtb)))))
1248 (defun gnus-agent-short-p ()
1249 "Say whether an article is short or not."
1250 (< (mail-header-lines gnus-headers) gnus-agent-short-article))
1252 (defun gnus-agent-long-p ()
1253 "Say whether an article is long or not."
1254 (> (mail-header-lines gnus-headers) gnus-agent-long-article))
1256 (defun gnus-agent-low-scored-p ()
1257 "Say whether an article has a low score or not."
1258 (< gnus-score gnus-agent-low-score))
1260 (defun gnus-agent-high-scored-p ()
1261 "Say whether an article has a high score or not."
1262 (> gnus-score gnus-agent-high-score))
1264 (defun gnus-category-make-function (cat)
1265 "Make a function from category CAT."
1266 `(lambda () ,(gnus-category-make-function-1 cat)))
1268 (defun gnus-agent-true ()
1272 (defun gnus-agent-false ()
1276 (defun gnus-category-make-function-1 (cat)
1277 "Make a function from category CAT."
1279 ;; Functions are just returned as is.
1281 (gnus-functionp cat))
1282 `(,(or (cdr (assq cat gnus-category-predicate-alist))
1284 ;; More complex category.
1287 ((memq (car cat) '(& and))
1289 ((memq (car cat) '(| or))
1291 ((memq (car cat) gnus-category-not)
1293 ,@(mapcar 'gnus-category-make-function-1 (cdr cat))))
1295 (error "Unknown category type: %s" cat))))
1297 (defun gnus-get-predicate (predicate)
1298 "Return the predicate for CATEGORY."
1299 (or (cdr (assoc predicate gnus-category-predicate-cache))
1300 (cdar (push (cons predicate
1301 (gnus-category-make-function predicate))
1302 gnus-category-predicate-cache))))
1304 (defun gnus-group-category (group)
1305 "Return the category GROUP belongs to."
1306 (unless gnus-category-group-cache
1307 (setq gnus-category-group-cache (gnus-make-hashtable 1000))
1308 (let ((cs gnus-category-alist)
1310 (while (setq cat (pop cs))
1311 (setq groups (cadddr cat))
1313 (gnus-sethash (pop groups) cat gnus-category-group-cache)))))
1314 (or (gnus-gethash group gnus-category-group-cache)
1315 (assq 'default gnus-category-alist)))
1317 (defun gnus-agent-expire ()
1318 "Expire all old articles."
1320 (let ((methods gnus-agent-covered-methods)
1321 (day (- (time-to-days (current-time)) gnus-agent-expire-days))
1322 gnus-command-method sym group articles
1323 history overview file histories elem art nov-file low info
1324 unreads marked article)
1326 (setq overview (gnus-get-buffer-create " *expire overview*"))
1327 (while (setq gnus-command-method (pop methods))
1328 (let ((expiry-hashtb (gnus-make-hashtable 1023)))
1329 (gnus-agent-open-history)
1331 (setq gnus-agent-current-history
1332 (setq history (gnus-agent-history-buffer))))
1333 (goto-char (point-min))
1334 (when (> (buffer-size) 1)
1335 (goto-char (point-min))
1337 (skip-chars-forward "^\t")
1338 (if (> (read (current-buffer)) day)
1339 ;; New article; we don't expire it.
1341 ;; Old article. Schedule it for possible nuking.
1343 (setq sym (let ((obarray expiry-hashtb))
1344 (read (current-buffer))))
1346 (set sym (cons (cons (read (current-buffer)) (point))
1347 (symbol-value sym)))
1348 (set sym (list (cons (read (current-buffer)) (point)))))
1349 (skip-chars-forward " "))
1351 ;; We now have all articles that can possibly be expired.
1354 (setq group (symbol-name sym)
1355 articles (sort (symbol-value sym) 'car-less-than-car)
1356 low (car (gnus-active group))
1357 info (gnus-get-info group)
1358 unreads (ignore-errors (gnus-list-of-unread-articles group))
1359 marked (nconc (gnus-uncompress-range
1360 (cdr (assq 'tick (gnus-info-marks info))))
1361 (gnus-uncompress-range
1363 (gnus-info-marks info)))))
1364 nov-file (gnus-agent-article-name ".overview" group))
1365 (gnus-agent-load-alist group)
1366 (gnus-message 5 "Expiring articles in %s" group)
1367 (set-buffer overview)
1369 (when (file-exists-p nov-file)
1370 (nnheader-insert-file-contents nov-file))
1371 (goto-char (point-min))
1373 (while (setq elem (pop articles))
1374 (setq article (car elem))
1375 (when (or (null low)
1377 gnus-agent-expire-all
1378 (and (not (memq article unreads))
1379 (not (memq article marked))))
1380 ;; Find and nuke the NOV line.
1381 (while (and (not (eobp))
1383 (setq art (read (current-buffer)))))
1386 (gnus-agent-article-name
1387 (number-to-string art) group))
1389 ;; Remove old NOV lines that have no articles.
1390 (gnus-delete-line)))
1395 ;; Nuke the article.
1396 (when (file-exists-p (setq file (gnus-agent-article-name
1397 (number-to-string article)
1400 ;; Schedule the history line for nuking.
1401 (push (cdr elem) histories)))
1402 (gnus-make-directory (file-name-directory nov-file))
1403 (let ((coding-system-for-write
1404 gnus-agent-file-coding-system))
1405 (write-region (point-min) (point-max) nov-file nil 'silent))
1406 ;; Delete the unwanted entries in the alist.
1407 (setq gnus-agent-article-alist
1408 (sort gnus-agent-article-alist 'car-less-than-car))
1409 (let* ((alist gnus-agent-article-alist)
1410 (prev (cons nil alist))
1414 (<= (caar alist) article))
1415 (if (or (not (cdar alist))
1417 (gnus-agent-article-name
1422 (push (caar alist) expired)
1423 (setcdr prev (setq alist (cdr alist))))
1425 alist (cdr alist))))
1426 (setq gnus-agent-article-alist (cdr first))
1427 (gnus-agent-save-alist group)
1428 ;; Mark all articles up to the first article
1429 ;; in `gnus-article-alist' as read.
1430 (when (and info (caar gnus-agent-article-alist))
1431 (setcar (nthcdr 2 info)
1434 (cons 1 (- (caar gnus-agent-article-alist) 1)))))
1435 ;; Maybe everything has been expired from `gnus-article-alist'
1436 ;; and so the above marking as read could not be conducted,
1437 ;; or there are expired article within the range of the alist.
1440 (or (not (caar gnus-agent-article-alist))
1442 (caar gnus-agent-article-alist))))
1443 (setcar (nthcdr 2 info)
1446 (nreverse expired))))
1448 (concat "(gnus-group-set-info '"
1449 (gnus-prin1-to-string info)
1452 (set-buffer history)
1453 (setq histories (nreverse (sort histories '<)))
1455 (goto-char (pop histories))
1457 (gnus-agent-save-history)
1458 (gnus-agent-close-history))
1459 (gnus-message 4 "Expiry...done"))))))
1462 (defun gnus-agent-batch ()
1464 (let ((init-file-user "")
1465 (gnus-always-read-dribble-file t))
1467 (gnus-group-send-drafts)
1468 (gnus-agent-fetch-session))
1470 (provide 'gnus-agent)
1472 ;;; gnus-agent.el ends here