1 ;;; gnus-agent.el --- unplugged support for Gnus
2 ;; Copyright (C) 1997,98 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; This file is part of GNU Emacs.
7 ;; GNU Emacs is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; GNU Emacs is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs; see the file COPYING. If not, write to the
19 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 ;; Boston, MA 02111-1307, USA.
32 (require 'gnus-score))
34 (defcustom gnus-agent-directory (nnheader-concat gnus-directory "agent/")
35 "Where the Gnus agent will store its files."
39 (defcustom gnus-agent-plugged-hook nil
40 "Hook run when plugging into the network."
44 (defcustom gnus-agent-unplugged-hook nil
45 "Hook run when unplugging from the network."
49 (defcustom gnus-agent-handle-level gnus-level-subscribed
50 "Groups on levels higher than this variable will be ignored by the Agent."
54 (defcustom gnus-agent-expire-days 7
55 "Read articles older than this will be expired."
59 (defcustom gnus-agent-expire-all nil
60 "If non-nil, also expire unread, ticked and dormant articles.
61 If nil, only read articles will be expired."
65 (defcustom gnus-agent-group-mode-hook nil
66 "Hook run in Agent group minor modes."
70 (defcustom gnus-agent-summary-mode-hook nil
71 "Hook run in Agent summary minor modes."
75 (defcustom gnus-agent-server-mode-hook nil
76 "Hook run in Agent summary minor modes."
80 ;;; Internal variables
82 (defvar gnus-agent-history-buffers nil)
83 (defvar gnus-agent-buffer-alist nil)
84 (defvar gnus-agent-article-alist nil)
85 (defvar gnus-agent-group-alist nil)
86 (defvar gnus-agent-covered-methods nil)
87 (defvar gnus-category-alist nil)
88 (defvar gnus-agent-current-history nil)
89 (defvar gnus-agent-overview-buffer nil)
90 (defvar gnus-category-predicate-cache nil)
91 (defvar gnus-category-group-cache nil)
92 (defvar gnus-agent-spam-hashtb nil)
93 (defvar gnus-agent-file-name nil)
94 (defvar gnus-agent-send-mail-function nil)
95 (defvar gnus-agent-file-coding-system 'no-conversion)
97 (defconst gnus-agent-scoreable-headers
99 "subject" "from" "date" "message-id"
100 "references" "chars" "lines" "xref")
101 "Headers that are considered when scoring articles
102 for download via the Agent.")
105 (defvar gnus-headers)
112 (defun gnus-open-agent ()
114 (gnus-agent-read-servers)
116 (setq gnus-agent-overview-buffer
117 (gnus-get-buffer-create " *Gnus agent overview*"))
118 (add-hook 'gnus-group-mode-hook 'gnus-agent-mode)
119 (add-hook 'gnus-summary-mode-hook 'gnus-agent-mode)
120 (add-hook 'gnus-server-mode-hook 'gnus-agent-mode))
122 (gnus-add-shutdown 'gnus-close-agent 'gnus)
124 (defun gnus-close-agent ()
125 (setq gnus-agent-covered-methods nil
126 gnus-category-predicate-cache nil
127 gnus-category-group-cache nil
128 gnus-agent-spam-hashtb nil)
129 (gnus-kill-buffer gnus-agent-overview-buffer))
132 ;;; Utility functions
135 (defun gnus-agent-read-file (file)
136 "Load FILE and do a `read' there."
139 (nnheader-insert-file-contents file)
140 (goto-char (point-min))
141 (read (current-buffer)))))
143 (defsubst gnus-agent-method ()
144 (concat (symbol-name (car gnus-command-method)) "/"
145 (if (equal (cadr gnus-command-method) "")
147 (cadr gnus-command-method))))
149 (defsubst gnus-agent-directory ()
150 "Path of the Gnus agent directory."
151 (nnheader-concat gnus-agent-directory
152 (nnheader-translate-file-chars (gnus-agent-method)) "/"))
154 (defun gnus-agent-lib-file (file)
155 "The full path of the Gnus agent library FILE."
156 (concat (gnus-agent-directory) "agent.lib/" file))
158 ;;; Fetching setup functions.
160 (defun gnus-agent-start-fetch ()
161 "Initialize data structures for efficient fetching."
162 (gnus-agent-open-history)
163 (setq gnus-agent-current-history (gnus-agent-history-buffer)))
165 (defun gnus-agent-stop-fetch ()
166 "Save all data structures and clean up."
167 (gnus-agent-save-history)
168 (gnus-agent-close-history)
169 (setq gnus-agent-spam-hashtb nil)
171 (set-buffer nntp-server-buffer)
174 (defmacro gnus-agent-with-fetch (&rest forms)
178 (gnus-agent-start-fetch)
180 (gnus-agent-stop-fetch)))
182 (put 'gnus-agent-with-fetch 'lisp-indent-function 0)
183 (put 'gnus-agent-with-fetch 'edebug-form-spec '(body))
189 (defvar gnus-agent-mode-hook nil
190 "Hook run when installing agent mode.")
192 (defvar gnus-agent-mode nil)
193 (defvar gnus-agent-mode-status '(gnus-agent-mode " Plugged"))
195 (defun gnus-agent-mode ()
196 "Minor mode for providing a agent support in Gnus buffers."
197 (let* ((buffer (progn (string-match "^gnus-\\(.*\\)-mode$"
198 (symbol-name major-mode))
199 (match-string 1 (symbol-name major-mode))))
200 (mode (intern (format "gnus-agent-%s-mode" buffer))))
201 (set (make-local-variable 'gnus-agent-mode) t)
203 (set (make-local-variable mode) t)
205 (when (gnus-visual-p 'agent-menu 'menu)
206 (funcall (intern (format "gnus-agent-%s-make-menu-bar" buffer))))
207 (unless (assq 'gnus-agent-mode minor-mode-alist)
208 (push gnus-agent-mode-status minor-mode-alist))
209 (unless (assq mode minor-mode-map-alist)
210 (push (cons mode (symbol-value (intern (format "gnus-agent-%s-mode-map"
212 minor-mode-map-alist))
213 (when (eq major-mode 'gnus-group-mode)
214 (gnus-agent-toggle-plugged gnus-plugged))
215 (gnus-run-hooks 'gnus-agent-mode-hook
216 (intern (format "gnus-agent-%s-mode-hook" buffer)))))
218 (defvar gnus-agent-group-mode-map (make-sparse-keymap))
219 (gnus-define-keys gnus-agent-group-mode-map
220 "Ju" gnus-agent-fetch-groups
221 "Jc" gnus-enter-category-buffer
222 "Jj" gnus-agent-toggle-plugged
223 "Js" gnus-agent-fetch-session
224 "JS" gnus-group-send-drafts
225 "Ja" gnus-agent-add-group)
227 (defun gnus-agent-group-make-menu-bar ()
228 (unless (boundp 'gnus-agent-group-menu)
230 gnus-agent-group-menu gnus-agent-group-mode-map ""
232 ["Toggle plugged" gnus-agent-toggle-plugged t]
233 ["List categories" gnus-enter-category-buffer t]
234 ["Send drafts" gnus-group-send-drafts gnus-plugged]
236 ["All" gnus-agent-fetch-session gnus-plugged]
237 ["Group" gnus-agent-fetch-group gnus-plugged])))))
239 (defvar gnus-agent-summary-mode-map (make-sparse-keymap))
240 (gnus-define-keys gnus-agent-summary-mode-map
241 "Jj" gnus-agent-toggle-plugged
242 "J#" gnus-agent-mark-article
243 "J\M-#" gnus-agent-unmark-article
244 "@" gnus-agent-toggle-mark
245 "Jc" gnus-agent-catchup)
247 (defun gnus-agent-summary-make-menu-bar ()
248 (unless (boundp 'gnus-agent-summary-menu)
250 gnus-agent-summary-menu gnus-agent-summary-mode-map ""
252 ["Toggle plugged" gnus-agent-toggle-plugged t]
253 ["Mark as downloadable" gnus-agent-mark-article t]
254 ["Unmark as downloadable" gnus-agent-unmark-article t]
255 ["Toggle mark" gnus-agent-toggle-mark t]
256 ["Catchup undownloaded" gnus-agent-catchup t]))))
258 (defvar gnus-agent-server-mode-map (make-sparse-keymap))
259 (gnus-define-keys gnus-agent-server-mode-map
260 "Jj" gnus-agent-toggle-plugged
261 "Ja" gnus-agent-add-server
262 "Jr" gnus-agent-remove-server)
264 (defun gnus-agent-server-make-menu-bar ()
265 (unless (boundp 'gnus-agent-server-menu)
267 gnus-agent-server-menu gnus-agent-server-mode-map ""
269 ["Toggle plugged" gnus-agent-toggle-plugged t]
270 ["Add" gnus-agent-add-server t]
271 ["Remove" gnus-agent-remove-server t]))))
273 (defun gnus-agent-toggle-plugged (plugged)
274 "Toggle whether Gnus is unplugged or not."
275 (interactive (list (not gnus-plugged)))
278 (setq gnus-plugged plugged)
279 (gnus-run-hooks 'gnus-agent-plugged-hook)
280 (setcar (cdr gnus-agent-mode-status) " Plugged"))
281 (gnus-agent-close-connections)
282 (setq gnus-plugged plugged)
283 (gnus-run-hooks 'gnus-agent-unplugged-hook)
284 (setcar (cdr gnus-agent-mode-status) " Unplugged"))
285 (set-buffer-modified-p t))
287 (defun gnus-agent-close-connections ()
288 "Close all methods covered by the Gnus agent."
289 (let ((methods gnus-agent-covered-methods))
291 (gnus-close-server (pop methods)))))
294 (defun gnus-unplugged ()
295 "Start Gnus unplugged."
297 (setq gnus-plugged nil)
301 (defun gnus-plugged ()
302 "Start Gnus plugged."
304 (setq gnus-plugged t)
308 (defun gnus-agentize ()
309 "Allow Gnus to be an offline newsreader.
310 The normal usage of this command is to put the following as the
311 last form in your `.gnus.el' file:
315 This will modify the `gnus-before-startup-hook', `gnus-post-method',
316 and `message-send-mail-function' variables, and install the Gnus
317 agent minor mode in all Gnus buffers."
320 (add-hook 'gnus-setup-news-hook 'gnus-agent-queue-setup)
321 (unless gnus-agent-send-mail-function
322 (setq gnus-agent-send-mail-function message-send-mail-function
323 message-send-mail-function 'gnus-agent-send-mail))
324 (unless gnus-agent-covered-methods
325 (setq gnus-agent-covered-methods (list gnus-select-method))))
327 (defun gnus-agent-queue-setup ()
328 "Make sure the queue group exists."
329 (unless (gnus-gethash "nndraft:queue" gnus-newsrc-hashtb)
330 (gnus-request-create-group "queue" '(nndraft ""))
331 (let ((gnus-level-default-subscribed 1))
332 (gnus-subscribe-group "nndraft:queue" nil '(nndraft "")))
333 (gnus-group-set-parameter
334 "nndraft:queue" 'gnus-dummy '((gnus-draft-mode)))))
336 (defun gnus-agent-send-mail ()
338 (funcall gnus-agent-send-mail-function)
339 (goto-char (point-min))
341 (concat "^" (regexp-quote mail-header-separator) "\n"))
343 (gnus-agent-insert-meta-information 'mail)
344 (gnus-request-accept-article "nndraft:queue")))
346 (defun gnus-agent-insert-meta-information (type &optional method)
347 "Insert meta-information into the message that says how it's to be posted.
348 TYPE can be either `mail' or `news'. If the latter METHOD can
351 (message-remove-header gnus-agent-meta-information-header)
352 (goto-char (point-min))
353 (insert gnus-agent-meta-information-header ": "
354 (symbol-name type) " " (format "%S" method)
357 (while (search-backward "\n" nil t)
358 (replace-match "\\n" t t))))
361 ;;; Group mode commands
364 (defun gnus-agent-fetch-groups (n)
365 "Put all new articles in the current groups into the Agent."
367 (gnus-group-iterate n 'gnus-agent-fetch-group))
369 (defun gnus-agent-fetch-group (group)
370 "Put all new articles in GROUP into the Agent."
371 (interactive (list (gnus-group-group-name)))
373 (error "No group on the current line"))
374 (let ((gnus-command-method (gnus-find-method-for-group group)))
375 (gnus-agent-with-fetch
376 (gnus-agent-fetch-group-1 group gnus-command-method)
377 (gnus-message 5 "Fetching %s...done" group))))
379 (defun gnus-agent-add-group (category arg)
380 "Add the current group to an agent category."
386 (mapcar (lambda (cat) (list (symbol-name (car cat))))
390 (let ((cat (assq category gnus-category-alist))
392 (gnus-group-iterate arg
394 (when (cadddr (setq c (gnus-group-category group)))
395 (setf (cadddr c) (delete group (cadddr c))))
396 (push group groups)))
397 (setf (cadddr cat) (nconc (cadddr cat) groups))
398 (gnus-category-write)))
401 ;;; Server mode commands
404 (defun gnus-agent-add-server (server)
405 "Enroll SERVER in the agent program."
406 (interactive (list (gnus-server-server-name)))
408 (error "No server on the current line"))
409 (let ((method (gnus-server-get-method nil (gnus-server-server-name))))
410 (when (member method gnus-agent-covered-methods)
411 (error "Server already in the agent program"))
412 (push method gnus-agent-covered-methods)
413 (gnus-agent-write-servers)
414 (message "Entered %s into the Agent" server)))
416 (defun gnus-agent-remove-server (server)
417 "Remove SERVER from the agent program."
418 (interactive (list (gnus-server-server-name)))
420 (error "No server on the current line"))
421 (let ((method (gnus-server-get-method nil (gnus-server-server-name))))
422 (unless (member method gnus-agent-covered-methods)
423 (error "Server not in the agent program"))
424 (setq gnus-agent-covered-methods
425 (delete method gnus-agent-covered-methods))
426 (gnus-agent-write-servers)
427 (message "Removed %s from the agent" server)))
429 (defun gnus-agent-read-servers ()
430 "Read the alist of covered servers."
431 (setq gnus-agent-covered-methods
432 (gnus-agent-read-file
433 (nnheader-concat gnus-agent-directory "lib/servers"))))
435 (defun gnus-agent-write-servers ()
436 "Write the alist of covered servers."
437 (with-temp-file (nnheader-concat gnus-agent-directory "lib/servers")
438 (prin1 gnus-agent-covered-methods (current-buffer))))
444 (defun gnus-agent-mark-article (n &optional unmark)
445 "Mark the next N articles as downloadable.
446 If N is negative, mark backward instead. If UNMARK is non-nil, remove
447 the mark instead. The difference between N and the actual number of
448 articles marked is returned."
450 (let ((backward (< n 0))
455 (gnus-summary-set-agent-mark
456 (gnus-summary-article-number) unmark)
457 (zerop (gnus-summary-next-subject (if backward -1 1) nil t))))
460 (gnus-message 7 "No more articles"))
461 (gnus-summary-recenter)
462 (gnus-summary-position-point)
465 (defun gnus-agent-unmark-article (n)
466 "Remove the downloadable mark from the next N articles.
467 If N is negative, unmark backward instead. The difference between N and
468 the actual number of articles unmarked is returned."
470 (gnus-agent-mark-article n t))
472 (defun gnus-agent-toggle-mark (n)
473 "Toggle the downloadable mark from the next N articles.
474 If N is negative, toggle backward instead. The difference between N and
475 the actual number of articles toggled is returned."
477 (gnus-agent-mark-article n 'toggle))
479 (defun gnus-summary-set-agent-mark (article &optional unmark)
480 "Mark ARTICLE as downloadable."
481 (let ((unmark (if (and (not (null unmark)) (not (eq t unmark)))
482 (memq article gnus-newsgroup-downloadable)
486 (setq gnus-newsgroup-downloadable
487 (delq article gnus-newsgroup-downloadable))
488 (push article gnus-newsgroup-undownloaded))
489 (setq gnus-newsgroup-undownloaded
490 (delq article gnus-newsgroup-undownloaded))
491 (push article gnus-newsgroup-downloadable))
492 (gnus-summary-update-mark
493 (if unmark gnus-undownloaded-mark gnus-downloadable-mark)
496 (defun gnus-agent-get-undownloaded-list ()
497 "Mark all unfetched articles as read."
498 (let ((gnus-command-method (gnus-find-method-for-group gnus-newsgroup-name)))
499 (when (and (not gnus-plugged)
500 (gnus-agent-method-p gnus-command-method))
501 (gnus-agent-load-alist gnus-newsgroup-name)
502 (let ((articles gnus-newsgroup-unreads)
504 (while (setq article (pop articles))
505 (unless (or (cdr (assq article gnus-agent-article-alist))
506 (memq article gnus-newsgroup-downloadable))
507 (push article gnus-newsgroup-undownloaded)))))))
509 (defun gnus-agent-catchup ()
510 "Mark all undownloaded articles as read."
513 (while gnus-newsgroup-undownloaded
514 (gnus-summary-mark-article
515 (pop gnus-newsgroup-undownloaded) gnus-catchup-mark)))
516 (gnus-summary-position-point))
519 ;;; Internal functions
522 (defun gnus-agent-save-active (method)
523 (when (gnus-agent-method-p method)
524 (let* ((gnus-command-method method)
525 (file (gnus-agent-lib-file "active")))
526 (gnus-make-directory (file-name-directory file))
527 (let ((coding-system-for-write gnus-agent-file-coding-system))
528 (write-region (point-min) (point-max) file nil 'silent))
529 (when (file-exists-p (gnus-agent-lib-file "groups"))
530 (delete-file (gnus-agent-lib-file "groups"))))))
532 (defun gnus-agent-save-groups (method)
533 (let* ((gnus-command-method method)
534 (file (gnus-agent-lib-file "groups")))
535 (gnus-make-directory (file-name-directory file))
536 (let ((coding-system-for-write
537 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)) "\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
610 gnus-agent-file-coding-system))
611 (write-region (1+ (point-min)) (point-max)
612 gnus-agent-file-name nil 'silent))))
614 (defun gnus-agent-close-history ()
615 (when (gnus-buffer-live-p gnus-agent-current-history)
616 (kill-buffer gnus-agent-current-history)
617 (setq gnus-agent-history-buffers
618 (delq (assoc (gnus-agent-method) gnus-agent-history-buffers)
619 gnus-agent-history-buffers))))
621 (defun gnus-agent-enter-history (id group-arts date)
623 (set-buffer gnus-agent-current-history)
624 (goto-char (point-max))
625 (insert id "\t" (number-to-string date) "\t")
627 (insert (caar group-arts) " " (number-to-string (cdr (pop group-arts)))
631 (defun gnus-agent-article-in-history-p (id)
633 (set-buffer (gnus-agent-history-buffer))
634 (goto-char (point-min))
635 (search-forward (concat "\n" id "\t") nil t)))
637 (defun gnus-agent-history-path (id)
639 (set-buffer (gnus-agent-history-buffer))
640 (goto-char (point-min))
641 (when (search-forward (concat "\n" id "\t") nil t)
642 (let ((method (gnus-agent-method)))
644 (while (not (numberp (setq group (read (current-buffer)))))
645 (push (concat method "/" group) paths))
646 (nreverse paths))))))
652 (defun gnus-agent-fetch-articles (group articles)
653 "Fetch ARTICLES from GROUP and put them into the Agent."
655 ;; Prune off articles that we have already fetched.
657 (cdr (assq (car articles) gnus-agent-article-alist)))
659 (let ((arts articles))
661 (if (cdr (assq (cadr arts) gnus-agent-article-alist))
662 (setcdr arts (cddr arts))
663 (setq arts (cdr arts)))))
666 (gnus-agent-directory)
667 (gnus-agent-group-path group) "/"))
668 (date (time-to-days (current-time)))
671 (gnus-make-directory dir)
672 (gnus-message 7 "Fetching articles for %s..." group)
673 ;; Fetch the articles from the backend.
674 (if (gnus-check-backend-function 'retrieve-articles group)
675 (setq pos (gnus-retrieve-articles articles group))
678 (while (setq article (pop articles))
679 (when (gnus-request-article article group)
680 (goto-char (point-max))
681 (push (cons article (point)) pos)
682 (insert-buffer-substring nntp-server-buffer)))
683 (copy-to-buffer nntp-server-buffer (point-min) (point-max))
684 (setq pos (nreverse pos)))))
685 ;; Then save these articles into the Agent.
687 (set-buffer nntp-server-buffer)
689 (narrow-to-region (cdar pos) (or (cdadr pos) (point-max)))
690 (goto-char (point-min))
691 (when (search-forward "\n\n" nil t)
692 (when (search-backward "\nXrefs: " nil t)
693 ;; Handle crossposting.
694 (skip-chars-forward "^ ")
695 (skip-chars-forward " ")
697 (while (looking-at "\\([^: \n]+\\):\\([0-9]+\\) +")
698 (push (cons (buffer-substring (match-beginning 1)
700 (buffer-substring (match-beginning 2)
703 (goto-char (match-end 0)))
704 (gnus-agent-crosspost crosses (caar pos))))
705 (goto-char (point-min))
706 (if (not (re-search-forward "^Message-ID: *<\\([^>\n]+\\)>" nil t))
707 (setq id "No-Message-ID-in-article")
708 (setq id (buffer-substring (match-beginning 1) (match-end 1))))
709 (let ((coding-system-for-write
710 gnus-agent-file-coding-system))
711 (write-region (point-min) (point-max)
712 (concat dir (number-to-string (caar pos)))
714 (when (setq elem (assq (caar pos) gnus-agent-article-alist))
716 (gnus-agent-enter-history
717 id (or crosses (list (cons group (caar pos)))) date)
720 (gnus-agent-save-alist group)))))
722 (defun gnus-agent-crosspost (crosses article)
723 (let (gnus-agent-article-alist group alist beg end)
725 (set-buffer gnus-agent-overview-buffer)
726 (when (nnheader-find-nov-line article)
729 (setq end (progn (forward-line 1) (point)))))
731 (setq group (caar crosses))
732 (unless (setq alist (assoc group gnus-agent-group-alist))
733 (push (setq alist (list group (gnus-agent-load-alist (caar crosses))))
734 gnus-agent-group-alist))
735 (setcdr alist (cons (cons (cdar crosses) t) (cdr alist)))
737 (set-buffer (gnus-get-buffer-create (format " *Gnus agent overview %s*"
739 (when (= (point-max) (point-min))
740 (push (cons group (current-buffer)) gnus-agent-buffer-alist)
742 (nnheader-insert-file-contents
743 (gnus-agent-article-name ".overview" group))))
744 (nnheader-find-nov-line (string-to-number (cdar crosses)))
745 (insert (string-to-number (cdar crosses)))
746 (insert-buffer-substring gnus-agent-overview-buffer beg end))
749 (defun gnus-agent-flush-cache ()
751 (while gnus-agent-buffer-alist
752 (set-buffer (cdar gnus-agent-buffer-alist))
753 (let ((coding-system-for-write
754 gnus-agent-file-coding-system))
755 (write-region (point-min) (point-max)
756 (gnus-agent-article-name ".overview"
757 (caar gnus-agent-buffer-alist))
759 (pop gnus-agent-buffer-alist))
760 (while gnus-agent-group-alist
761 (with-temp-file (caar gnus-agent-group-alist)
762 (princ (cdar gnus-agent-group-alist))
764 (pop gnus-agent-group-alist))))
766 (defun gnus-agent-fetch-headers (group &optional force)
767 (let ((articles (if (gnus-agent-load-alist group)
768 (gnus-sorted-intersection
769 (gnus-list-of-unread-articles group)
770 (gnus-uncompress-range
771 (cons (1+ (caar (last gnus-agent-article-alist)))
772 (cdr (gnus-active group)))))
773 (gnus-list-of-unread-articles group))))
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-dependencies gnus-newsgroup-headers
906 gnus-newsgroup-scored gnus-headers gnus-score
907 gnus-use-cache articles arts
908 category predicate info marks score-param)
910 (when (and (or (gnus-active group) (gnus-activate-group group))
911 (setq articles (gnus-agent-fetch-headers group)))
912 ;; Parse them and see which articles we want to fetch.
913 (setq gnus-newsgroup-dependencies
914 (make-vector (length articles) 0))
915 ;; No need to call `gnus-get-newsgroup-headers-xover' with
916 ;; the entire .overview for group as we still have the just
917 ;; downloaded headers in `gnus-agent-overview-buffer'.
918 (let ((nntp-server-buffer gnus-agent-overview-buffer))
919 (setq gnus-newsgroup-headers
920 (gnus-get-newsgroup-headers-xover articles nil nil group)))
921 (setq category (gnus-group-category group))
924 (or (gnus-group-get-parameter group 'agent-predicate t)
926 ;; Do we want to download everything, or nothing?
927 (if (or (eq (caaddr predicate) 'gnus-agent-true)
928 (eq (caaddr predicate) 'gnus-agent-false))
930 (setq arts (symbol-value
931 (cadr (assoc (caaddr predicate)
932 '((gnus-agent-true articles)
933 (gnus-agent-false nil))))))
934 ;; No, we need to decide what we want.
936 (let ((score-method (or
937 (gnus-group-get-parameter group 'agent-score t)
940 (require 'gnus-score)
941 (if (eq score-method 'file)
943 (gnus-score-load-files
944 (gnus-all-score-files group)))
946 (while (setq list (car entries))
947 (push (car list) score-file)
948 (setq list (cdr list))
950 (when (member (caar list)
951 gnus-agent-scoreable-headers)
952 (push (car list) score-file))
953 (setq list (cdr list)))
955 (append score-param (list (nreverse score-file)))
956 score-file nil entries (cdr entries)))
958 (if (stringp (car score-method))
960 (list (list score-method)))))))
962 (gnus-score-headers score-param))
964 (while (setq gnus-headers (pop gnus-newsgroup-headers))
966 (or (cdr (assq (mail-header-number gnus-headers)
967 gnus-newsgroup-scored))
968 gnus-summary-default-score))
969 (when (funcall predicate)
970 (push (mail-header-number gnus-headers)
972 ;; Fetch the articles.
974 (gnus-agent-fetch-articles group arts)))
975 ;; Perhaps we have some additional articles to fetch.
976 (setq arts (assq 'download (gnus-info-marks
977 (setq info (gnus-get-info group)))))
979 (gnus-agent-fetch-articles
980 group (gnus-uncompress-range (cdr arts)))
981 (setq marks (delq arts (gnus-info-marks info)))
982 (gnus-info-set-marks info marks))))
985 ;;; Agent Category Mode
988 (defvar gnus-category-mode-hook nil
989 "Hook run in `gnus-category-mode' buffers.")
991 (defvar gnus-category-line-format " %(%20c%): %g\n"
992 "Format of category lines.")
994 (defvar gnus-category-mode-line-format "Gnus: %%b"
995 "The format specification for the category mode line.")
997 (defvar gnus-agent-short-article 100
998 "Articles that have fewer lines than this are short.")
1000 (defvar gnus-agent-long-article 200
1001 "Articles that have more lines than this are long.")
1003 (defvar gnus-agent-low-score 0
1004 "Articles that have a score lower than this have a low score.")
1006 (defvar gnus-agent-high-score 0
1007 "Articles that have a score higher than this have a high score.")
1010 ;;; Internal variables.
1012 (defvar gnus-category-buffer "*Agent Category*")
1014 (defvar gnus-category-line-format-alist
1015 `((?c gnus-tmp-name ?s)
1016 (?g gnus-tmp-groups ?d)))
1018 (defvar gnus-category-mode-line-format-alist
1019 `((?u user-defined ?s)))
1021 (defvar gnus-category-line-format-spec nil)
1022 (defvar gnus-category-mode-line-format-spec nil)
1024 (defvar gnus-category-mode-map nil)
1025 (put 'gnus-category-mode 'mode-class 'special)
1027 (unless gnus-category-mode-map
1028 (setq gnus-category-mode-map (make-sparse-keymap))
1029 (suppress-keymap gnus-category-mode-map)
1031 (gnus-define-keys gnus-category-mode-map
1032 "q" gnus-category-exit
1033 "k" gnus-category-kill
1034 "c" gnus-category-copy
1035 "a" gnus-category-add
1036 "p" gnus-category-edit-predicate
1037 "g" gnus-category-edit-groups
1038 "s" gnus-category-edit-score
1039 "l" gnus-category-list
1041 "\C-c\C-i" gnus-info-find-node
1042 "\C-c\C-b" gnus-bug))
1044 (defvar gnus-category-menu-hook nil
1045 "*Hook run after the creation of the menu.")
1047 (defun gnus-category-make-menu-bar ()
1048 (gnus-turn-off-edit-menu 'category)
1049 (unless (boundp 'gnus-category-menu)
1051 gnus-category-menu gnus-category-mode-map ""
1053 ["Add" gnus-category-add t]
1054 ["Kill" gnus-category-kill t]
1055 ["Copy" gnus-category-copy t]
1056 ["Edit predicate" gnus-category-edit-predicate t]
1057 ["Edit score" gnus-category-edit-score t]
1058 ["Edit groups" gnus-category-edit-groups t]
1059 ["Exit" gnus-category-exit t]))
1061 (gnus-run-hooks 'gnus-category-menu-hook)))
1063 (defun gnus-category-mode ()
1064 "Major mode for listing and editing agent categories.
1066 All normal editing commands are switched off.
1067 \\<gnus-category-mode-map>
1068 For more in-depth information on this mode, read the manual
1069 (`\\[gnus-info-find-node]').
1071 The following commands are available:
1073 \\{gnus-category-mode-map}"
1075 (when (gnus-visual-p 'category-menu 'menu)
1076 (gnus-category-make-menu-bar))
1077 (kill-all-local-variables)
1078 (gnus-simplify-mode-line)
1079 (setq major-mode 'gnus-category-mode)
1080 (setq mode-name "Category")
1081 (gnus-set-default-directory)
1082 (setq mode-line-process nil)
1083 (use-local-map gnus-category-mode-map)
1084 (buffer-disable-undo (current-buffer))
1085 (setq truncate-lines t)
1086 (setq buffer-read-only t)
1087 (gnus-run-hooks 'gnus-category-mode-hook))
1089 (defalias 'gnus-category-position-point 'gnus-goto-colon)
1091 (defun gnus-category-insert-line (category)
1092 (let* ((gnus-tmp-name (car category))
1093 (gnus-tmp-groups (length (cadddr category))))
1095 (gnus-add-text-properties
1099 (eval gnus-category-line-format-spec))
1100 (list 'gnus-category gnus-tmp-name))))
1102 (defun gnus-enter-category-buffer ()
1103 "Go to the Category buffer."
1105 (gnus-category-setup-buffer)
1106 (gnus-configure-windows 'category)
1107 (gnus-category-prepare))
1109 (defun gnus-category-setup-buffer ()
1110 (unless (get-buffer gnus-category-buffer)
1112 (set-buffer (gnus-get-buffer-create gnus-category-buffer))
1113 (gnus-category-mode))))
1115 (defun gnus-category-prepare ()
1116 (gnus-set-format 'category-mode)
1117 (gnus-set-format 'category t)
1118 (let ((alist gnus-category-alist)
1119 (buffer-read-only nil))
1122 (gnus-category-insert-line (pop alist)))
1123 (goto-char (point-min))
1124 (gnus-category-position-point)))
1126 (defun gnus-category-name ()
1127 (or (get-text-property (gnus-point-at-bol) 'gnus-category)
1128 (error "No category on the current line")))
1130 (defun gnus-category-read ()
1131 "Read the category alist."
1132 (setq gnus-category-alist
1133 (or (gnus-agent-read-file
1134 (nnheader-concat gnus-agent-directory "lib/categories"))
1135 (list (list 'default 'short nil nil)))))
1137 (defun gnus-category-write ()
1138 "Write the category alist."
1139 (setq gnus-category-predicate-cache nil
1140 gnus-category-group-cache nil)
1141 (with-temp-file (nnheader-concat gnus-agent-directory "lib/categories")
1142 (prin1 gnus-category-alist (current-buffer))))
1144 (defun gnus-category-edit-predicate (category)
1145 "Edit the predicate for CATEGORY."
1146 (interactive (list (gnus-category-name)))
1147 (let ((info (assq category gnus-category-alist)))
1149 (cadr info) (format "Editing the predicate for category %s" category)
1150 `(lambda (predicate)
1151 (setf (cadr (assq ',category gnus-category-alist)) predicate)
1152 (gnus-category-write)
1153 (gnus-category-list)))))
1155 (defun gnus-category-edit-score (category)
1156 "Edit the score expression for CATEGORY."
1157 (interactive (list (gnus-category-name)))
1158 (let ((info (assq category gnus-category-alist)))
1161 (format "Editing the score expression for category %s" category)
1163 (setf (caddr (assq ',category gnus-category-alist)) groups)
1164 (gnus-category-write)
1165 (gnus-category-list)))))
1167 (defun gnus-category-edit-groups (category)
1168 "Edit the group list for CATEGORY."
1169 (interactive (list (gnus-category-name)))
1170 (let ((info (assq category gnus-category-alist)))
1172 (cadddr info) (format "Editing the group list for category %s" category)
1174 (setf (cadddr (assq ',category gnus-category-alist)) groups)
1175 (gnus-category-write)
1176 (gnus-category-list)))))
1178 (defun gnus-category-kill (category)
1179 "Kill the current category."
1180 (interactive (list (gnus-category-name)))
1181 (let ((info (assq category gnus-category-alist))
1182 (buffer-read-only nil))
1184 (gnus-category-write)
1185 (setq gnus-category-alist (delq info gnus-category-alist))))
1187 (defun gnus-category-copy (category to)
1188 "Copy the current category."
1189 (interactive (list (gnus-category-name) (intern (read-string "New name: "))))
1190 (let ((info (assq category gnus-category-alist)))
1191 (push (list to (gnus-copy-sequence (cadr info))
1192 (gnus-copy-sequence (caddr info)) nil)
1193 gnus-category-alist)
1194 (gnus-category-write)
1195 (gnus-category-list)))
1197 (defun gnus-category-add (category)
1198 "Create a new category."
1199 (interactive "SCategory name: ")
1200 (when (assq category gnus-category-alist)
1201 (error "Category %s already exists" category))
1202 (push (list category 'true nil nil)
1203 gnus-category-alist)
1204 (gnus-category-write)
1205 (gnus-category-list))
1207 (defun gnus-category-list ()
1208 "List all categories."
1210 (gnus-category-prepare))
1212 (defun gnus-category-exit ()
1213 "Return to the group buffer."
1215 (kill-buffer (current-buffer))
1216 (gnus-configure-windows 'group t))
1218 ;; To avoid having 8-bit characters in the source file.
1219 (defvar gnus-category-not (list '! 'not (intern (format "%c" 172))))
1221 (defvar gnus-category-predicate-alist
1222 '((spam . gnus-agent-spam-p)
1223 (short . gnus-agent-short-p)
1224 (long . gnus-agent-long-p)
1225 (low . gnus-agent-low-scored-p)
1226 (high . gnus-agent-high-scored-p)
1227 (true . gnus-agent-true)
1228 (false . gnus-agent-false))
1229 "Mapping from short score predicate symbols to predicate functions.")
1231 (defun gnus-agent-spam-p ()
1232 "Say whether an article is spam or not."
1233 (unless gnus-agent-spam-hashtb
1234 (setq gnus-agent-spam-hashtb (gnus-make-hashtable 1000)))
1235 (if (not (equal (mail-header-references gnus-headers) ""))
1237 (let ((string (gnus-simplify-subject (mail-header-subject gnus-headers))))
1239 (gnus-gethash string gnus-agent-spam-hashtb)
1240 (gnus-sethash string t gnus-agent-spam-hashtb)))))
1242 (defun gnus-agent-short-p ()
1243 "Say whether an article is short or not."
1244 (< (mail-header-lines gnus-headers) gnus-agent-short-article))
1246 (defun gnus-agent-long-p ()
1247 "Say whether an article is long or not."
1248 (> (mail-header-lines gnus-headers) gnus-agent-long-article))
1250 (defun gnus-agent-low-scored-p ()
1251 "Say whether an article has a low score or not."
1252 (< gnus-score gnus-agent-low-score))
1254 (defun gnus-agent-high-scored-p ()
1255 "Say whether an article has a high score or not."
1256 (> gnus-score gnus-agent-high-score))
1258 (defun gnus-category-make-function (cat)
1259 "Make a function from category CAT."
1260 `(lambda () ,(gnus-category-make-function-1 cat)))
1262 (defun gnus-agent-true ()
1266 (defun gnus-agent-false ()
1270 (defun gnus-category-make-function-1 (cat)
1271 "Make a function from category CAT."
1273 ;; Functions are just returned as is.
1275 (gnus-functionp cat))
1276 `(,(or (cdr (assq cat gnus-category-predicate-alist))
1278 ;; More complex category.
1281 ((memq (car cat) '(& and))
1283 ((memq (car cat) '(| or))
1285 ((memq (car cat) gnus-category-not)
1287 ,@(mapcar 'gnus-category-make-function-1 (cdr cat))))
1289 (error "Unknown category type: %s" cat))))
1291 (defun gnus-get-predicate (predicate)
1292 "Return the predicate for CATEGORY."
1293 (or (cdr (assoc predicate gnus-category-predicate-cache))
1294 (cdar (push (cons predicate
1295 (gnus-category-make-function predicate))
1296 gnus-category-predicate-cache))))
1298 (defun gnus-group-category (group)
1299 "Return the category GROUP belongs to."
1300 (unless gnus-category-group-cache
1301 (setq gnus-category-group-cache (gnus-make-hashtable 1000))
1302 (let ((cs gnus-category-alist)
1304 (while (setq cat (pop cs))
1305 (setq groups (cadddr cat))
1307 (gnus-sethash (pop groups) cat gnus-category-group-cache)))))
1308 (or (gnus-gethash group gnus-category-group-cache)
1309 (assq 'default gnus-category-alist)))
1311 (defun gnus-agent-expire ()
1312 "Expire all old articles."
1314 (let ((methods gnus-agent-covered-methods)
1315 (day (- (time-to-days (current-time)) gnus-agent-expire-days))
1316 gnus-command-method sym group articles
1317 history overview file histories elem art nov-file low info
1318 unreads marked article)
1320 (setq overview (gnus-get-buffer-create " *expire overview*"))
1321 (while (setq gnus-command-method (pop methods))
1322 (let ((expiry-hashtb (gnus-make-hashtable 1023)))
1323 (gnus-agent-open-history)
1325 (setq gnus-agent-current-history
1326 (setq history (gnus-agent-history-buffer))))
1327 (goto-char (point-min))
1328 (when (> (buffer-size) 1)
1329 (goto-char (point-min))
1331 (skip-chars-forward "^\t")
1332 (if (> (read (current-buffer)) day)
1333 ;; New article; we don't expire it.
1335 ;; Old article. Schedule it for possible nuking.
1337 (setq sym (let ((obarray expiry-hashtb))
1338 (read (current-buffer))))
1340 (set sym (cons (cons (read (current-buffer)) (point))
1341 (symbol-value sym)))
1342 (set sym (list (cons (read (current-buffer)) (point)))))
1343 (skip-chars-forward " "))
1345 ;; We now have all articles that can possibly be expired.
1348 (setq group (symbol-name sym)
1349 articles (sort (symbol-value sym) 'car-less-than-car)
1350 low (car (gnus-active group))
1351 info (gnus-get-info group)
1352 unreads (ignore-errors (gnus-list-of-unread-articles group))
1353 marked (nconc (gnus-uncompress-range
1354 (cdr (assq 'tick (gnus-info-marks info))))
1355 (gnus-uncompress-range
1357 (gnus-info-marks info)))))
1358 nov-file (gnus-agent-article-name ".overview" group))
1359 (gnus-agent-load-alist group)
1360 (gnus-message 5 "Expiring articles in %s" group)
1361 (set-buffer overview)
1363 (when (file-exists-p nov-file)
1364 (nnheader-insert-file-contents nov-file))
1365 (goto-char (point-min))
1367 (while (setq elem (pop articles))
1368 (setq article (car elem))
1369 (when (or (null low)
1371 gnus-agent-expire-all
1372 (and (not (memq article unreads))
1373 (not (memq article marked))))
1374 ;; Find and nuke the NOV line.
1375 (while (and (not (eobp))
1377 (setq art (read (current-buffer)))))
1380 (gnus-agent-article-name
1381 (number-to-string art) group))
1383 ;; Remove old NOV lines that have no articles.
1384 (gnus-delete-line)))
1389 ;; Nuke the article.
1390 (when (file-exists-p (setq file (gnus-agent-article-name
1391 (number-to-string article)
1394 ;; Schedule the history line for nuking.
1395 (push (cdr elem) histories)))
1396 (gnus-make-directory (file-name-directory nov-file))
1397 (let ((coding-system-for-write
1398 gnus-agent-file-coding-system))
1399 (write-region (point-min) (point-max) nov-file nil 'silent))
1400 ;; Delete the unwanted entries in the alist.
1401 (setq gnus-agent-article-alist
1402 (sort gnus-agent-article-alist 'car-less-than-car))
1403 (let* ((alist gnus-agent-article-alist)
1404 (prev (cons nil alist))
1408 (<= (caar alist) article))
1409 (if (or (not (cdar alist))
1411 (gnus-agent-article-name
1416 (push (caar alist) expired)
1417 (setcdr prev (setq alist (cdr alist))))
1419 alist (cdr alist))))
1420 (setq gnus-agent-article-alist (cdr first))
1421 (gnus-agent-save-alist group)
1422 ;; Mark all articles up to the first article
1423 ;; in `gnus-article-alist' as read.
1424 (when (caar gnus-agent-article-alist)
1425 (setcar (nthcdr 2 info)
1428 (cons 1 (- (caar gnus-agent-article-alist) 1)))))
1429 ;; Maybe everything has been expired from `gnus-article-alist'
1430 ;; and so the above marking as read could not be conducted,
1431 ;; or there are expired article within the range of the alist.
1432 (when (or (not (caar gnus-agent-article-alist))
1433 (> (car expired) (caar gnus-agent-article-alist)))
1434 (setcar (nthcdr 2 info)
1437 (nreverse expired))))
1439 (concat "(gnus-group-set-info '"
1440 (gnus-prin1-to-string info)
1443 (set-buffer history)
1444 (setq histories (nreverse (sort histories '<)))
1446 (goto-char (pop histories))
1448 (gnus-agent-save-history)
1449 (gnus-agent-close-history))
1450 (gnus-message 4 "Expiry...done"))))))
1453 (defun gnus-agent-batch ()
1455 (let ((init-file-user "")
1456 (gnus-always-read-dribble-file t))
1458 (gnus-group-send-drafts)
1459 (gnus-agent-fetch-session))
1461 (provide 'gnus-agent)
1463 ;;; gnus-agent.el ends here