*** empty log message ***
[gnus] / lisp / gnus-agent.el
1 ;;; gnus-agent.el --- unplugged support for Gnus
2 ;; Copyright (C) 1997 Free Software Foundation, Inc.
3
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
5 ;; Keywords: news
6
7 ;; This file is part of GNU Emacs.
8
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; any later version.
13
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ;; GNU General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
23
24 ;;; Commentary:
25
26 ;;; Code:
27
28 (require 'gnus)
29 (require 'gnus-cache)
30 (require 'nnvirtual)
31 (require 'gnus-sum)
32 (eval-when-compile (require 'cl))
33
34 (defcustom gnus-agent-directory (nnheader-concat gnus-directory "agent/")
35   "Where the Gnus agent will store its files."
36   :group 'gnus-agent
37   :type 'directory)
38
39 (defcustom gnus-agent-plugged-hook nil
40   "Hook run when plugging into the network."
41   :group 'gnus-agent
42   :type 'hook)
43
44 (defcustom gnus-agent-unplugged-hook nil
45   "Hook run when unplugging from the network."
46   :group 'gnus-agent
47   :type 'hook)
48
49 ;;; Internal variables
50
51 (defvar gnus-agent-history-buffers nil)
52 (defvar gnus-agent-buffer-alist nil)
53 (defvar gnus-agent-article-alist nil)
54 (defvar gnus-agent-group-alist nil)
55 (defvar gnus-agent-covered-methods nil)
56 (defvar gnus-category-alist nil)
57 (defvar gnus-agent-current-history nil)
58 (defvar gnus-agent-overview-buffer nil)
59 (defvar gnus-category-predicate-cache nil)
60 (defvar gnus-category-group-cache nil)
61 (defvar gnus-agent-spam-hashtb nil)
62 (defvar gnus-agent-file-name nil)
63 (defvar gnus-agent-send-mail-function nil)
64 (defvar gnus-agent-article-file-coding-system 'no-conversion)
65
66 ;; Dynamic variables
67 (defvar gnus-headers)
68 (defvar gnus-score)
69
70 ;;;
71 ;;; Setup
72 ;;;
73
74 (defun gnus-open-agent ()
75   (setq gnus-agent t)
76   (gnus-agent-read-servers)
77   (gnus-category-read)
78   (setq gnus-agent-overview-buffer
79         (get-buffer-create " *Gnus agent overview*"))
80   (add-hook 'gnus-group-mode-hook 'gnus-agent-mode)
81   (add-hook 'gnus-summary-mode-hook 'gnus-agent-mode)
82   (add-hook 'gnus-server-mode-hook 'gnus-agent-mode))
83
84 (gnus-add-shutdown 'gnus-close-agent 'gnus)
85
86 (defun gnus-close-agent ()
87   (setq gnus-agent-covered-methods nil
88         gnus-category-predicate-cache nil
89         gnus-category-group-cache nil
90         gnus-agent-spam-hashtb nil)
91   (gnus-kill-buffer gnus-agent-overview-buffer))
92
93 ;;;
94 ;;; Utility functions
95 ;;;
96
97 (defun gnus-agent-read-file (file)
98   "Load FILE and do a `read' there."
99   (nnheader-temp-write nil
100     (ignore-errors
101       (insert-file-contents file)
102       (goto-char (point-min))
103       (read (current-buffer)))))
104
105 (defsubst gnus-agent-method ()
106   (concat (symbol-name (car gnus-command-method)) "/"
107           (if (equal (cadr gnus-command-method) "")
108               "unnamed"
109             (cadr gnus-command-method))))
110
111 (defsubst gnus-agent-directory ()
112   "Path of the Gnus agent directory."
113   (nnheader-concat gnus-agent-directory (gnus-agent-method) "/"))
114
115 (defun gnus-agent-lib-file (file)
116   "The full path of the Gnus agent library FILE."
117   (concat (gnus-agent-directory) "agent.lib/" file))
118
119 ;;; Fetching setup functions.
120
121 (defun gnus-agent-start-fetch ()
122   "Initialize data structures for efficient fetching."
123   (gnus-agent-open-history)
124   (setq gnus-agent-current-history (gnus-agent-history-buffer)))
125
126 (defun gnus-agent-stop-fetch ()
127   "Save all data structures and clean up."
128   (gnus-agent-save-history)
129   (gnus-agent-close-history)
130   (setq gnus-agent-spam-hashtb nil)
131   (save-excursion
132     (set-buffer nntp-server-buffer)
133     (widen)))
134
135 (defmacro gnus-agent-with-fetch (&rest forms)
136   "Do FORMS safely."
137   `(unwind-protect
138        (progn
139          (gnus-agent-start-fetch)
140          ,@forms)
141      (gnus-agent-stop-fetch)))
142
143 (put 'gnus-agent-with-fetch 'lisp-indent-function 0)
144 (put 'gnus-agent-with-fetch 'edebug-form-spec '(body))
145
146 ;;;
147 ;;; Mode infestation
148 ;;;
149
150 (defvar gnus-agent-mode-hook nil
151   "Hook run when installing agent mode.")
152
153 (defvar gnus-agent-mode nil)
154 (defvar gnus-agent-mode-status '(gnus-agent-mode " Plugged"))
155
156 (defun gnus-agent-mode ()
157   "Minor mode for providing a agent support in Gnus buffers."
158   (let* ((buffer (progn (string-match "^gnus-\\(.*\\)-mode$"
159                                       (symbol-name major-mode))
160                         (match-string 1 (symbol-name major-mode))))
161          (mode (intern (format "gnus-agent-%s-mode" buffer))))
162     (set (make-local-variable 'gnus-agent-mode) t)
163     (set mode nil)
164     (set (make-local-variable mode) t)
165     ;; Set up the menu.
166     (when (gnus-visual-p 'agent-menu 'menu)
167       (funcall (intern (format "gnus-agent-%s-make-menu-bar" buffer))))
168     (unless (assq 'gnus-agent-mode minor-mode-alist)
169       (push gnus-agent-mode-status minor-mode-alist))
170     (unless (assq mode minor-mode-map-alist)
171       (push (cons mode (symbol-value (intern (format "gnus-agent-%s-mode-map"
172                                                      buffer))))
173             minor-mode-map-alist))
174     (gnus-agent-toggle-plugged gnus-plugged)
175     (run-hooks 'gnus-agent-mode-hook)))
176
177 (defvar gnus-agent-group-mode-map (make-sparse-keymap))
178 (gnus-define-keys gnus-agent-group-mode-map
179   "Ju" gnus-agent-fetch-group
180   "Jc" gnus-enter-category-buffer
181   "Jj" gnus-agent-toggle-plugged
182   "Js" gnus-agent-fetch-session
183   "JS" gnus-group-send-drafts
184   "Ja" gnus-agent-add-group)
185
186 (defun gnus-agent-group-make-menu-bar ()
187   (unless (boundp 'gnus-agent-group-menu)
188     (easy-menu-define
189      gnus-agent-group-menu gnus-agent-group-mode-map ""
190      '("Agent"
191        ["Toggle plugged" gnus-agent-toggle-plugged t]
192        ["List categories" gnus-enter-category-buffer t]
193        ["Send drafts" gnus-group-send-drafts gnus-plugged]
194        ("Fetch"
195         ["All" gnus-agent-fetch-session gnus-plugged]
196         ["Group" gnus-agent-fetch-group gnus-plugged])))))
197
198 (defvar gnus-agent-summary-mode-map (make-sparse-keymap))
199 (gnus-define-keys gnus-agent-summary-mode-map
200   "Jj" gnus-agent-toggle-plugged
201   "J#" gnus-agent-mark-article
202   "J\M-#" gnus-agent-unmark-article
203   "@" gnus-agent-toggle-mark
204   "Jc" gnus-agent-catchup)
205
206 (defun gnus-agent-summary-make-menu-bar ()
207   (unless (boundp 'gnus-agent-summary-menu)
208     (easy-menu-define
209      gnus-agent-summary-menu gnus-agent-summary-mode-map ""
210      '("Agent"
211        ["Toggle plugged" gnus-agent-toggle-plugged t]
212        ["Mark as downloadable" gnus-agent-mark-article t]
213        ["Unmark as downloadable" gnus-agent-unmark-article t]
214        ["Toggle mark" gnus-agent-toggle-mark t]
215        ["Catchup undownloaded" gnus-agent-catchup t]))))
216
217 (defvar gnus-agent-server-mode-map (make-sparse-keymap))
218 (gnus-define-keys gnus-agent-server-mode-map
219   "Jj" gnus-agent-toggle-plugged
220   "Ja" gnus-agent-add-server
221   "Jr" gnus-agent-remove-server)
222
223 (defun gnus-agent-server-make-menu-bar ()
224   (unless (boundp 'gnus-agent-server-menu)
225     (easy-menu-define
226      gnus-agent-server-menu gnus-agent-server-mode-map ""
227      '("Agent"
228        ["Toggle plugged" gnus-agent-toggle-plugged t]
229        ["Add" gnus-agent-add-server t]
230        ["Remove" gnus-agent-remove-server t]))))
231
232 (defun gnus-agent-toggle-plugged (plugged)
233   "Toggle whether Gnus is unplugged or not."
234   (interactive (list (not gnus-plugged)))
235   (if plugged
236       (progn
237         (run-hooks 'gnus-agent-plugged-hook)
238         (setcar (cdr gnus-agent-mode-status) " Plugged"))
239     (gnus-agent-close-connections)
240     (run-hooks 'gnus-agent-unplugged-hook)
241     (setcar (cdr gnus-agent-mode-status) " Unplugged"))
242   (setq gnus-plugged plugged)
243   (set-buffer-modified-p t))
244
245 (defun gnus-agent-close-connections ()
246   "Close all methods covered by the Gnus agent."
247   (let ((methods gnus-agent-covered-methods))
248     (while methods
249       (gnus-close-server (pop methods)))))
250
251 ;;;###autoload
252 (defun gnus-unplugged ()
253   "Start Gnus unplugged."
254   (interactive)
255   (setq gnus-plugged nil)
256   (gnus))
257
258 ;;;###autoload
259 (defun gnus-agentize ()
260   "Allow Gnus to be an offline newsreader.
261 The normal usage of this command is to put the following as the
262 last form in your `.gnus.el' file:
263
264 \(gnus-agentize)
265
266 This will modify the `gnus-before-startup-hook', `gnus-post-method',
267 and `message-send-mail-function' variables, and install the Gnus
268 agent minor mode in all Gnus buffers."
269   (interactive)
270   (gnus-open-agent)
271   (add-hook 'gnus-setup-news-hook 'gnus-agent-queue-setup)
272   (unless gnus-agent-send-mail-function 
273     (setq gnus-agent-send-mail-function message-send-mail-function
274           message-send-mail-function 'gnus-agent-send-mail))
275   (unless gnus-agent-covered-methods
276     (setq gnus-agent-covered-methods (list gnus-select-method))))
277
278 (defun gnus-agent-queue-setup ()
279   "Make sure the queue group exists."
280   (unless (gnus-gethash "nndraft:queue" gnus-newsrc-hashtb)
281     (gnus-request-create-group "queue" '(nndraft ""))
282     (let ((gnus-level-default-subscribed 1))
283       (gnus-subscribe-group "nndraft:queue" nil '(nndraft "")))
284     (gnus-group-set-parameter
285      "nndraft:queue" 'gnus-dummy '((gnus-draft-mode)))))
286
287 (defun gnus-agent-send-mail ()
288   (if gnus-plugged
289       (funcall gnus-agent-send-mail-function)
290     (goto-char (point-min))
291     (re-search-forward
292      (concat "^" (regexp-quote mail-header-separator) "\n"))
293     (replace-match "\n")
294     (gnus-request-accept-article "nndraft:queue")))
295
296 ;;;
297 ;;; Group mode commands
298 ;;;
299
300 (defun gnus-agent-fetch-group (group)
301   "Put all new articles in GROUP into the agent."
302   (interactive (list (gnus-group-group-name)))
303   (unless group
304     (error "No group on the current line"))
305   (let ((gnus-command-method (gnus-find-method-for-group group)))
306     (gnus-agent-with-fetch
307       (gnus-agent-fetch-group-1 group gnus-command-method)
308       (gnus-message 5 "Fetching %s...done" group))))
309
310 (defun gnus-agent-add-group (category arg)
311   "Add the current group to an agent category."
312   (interactive
313    (list
314     (intern
315      (completing-read
316       "Add to category: "
317       (mapcar (lambda (cat) (list (symbol-name (car cat))))
318               gnus-category-alist)
319       nil t))
320     current-prefix-arg))
321   (let ((cat (assq category gnus-category-alist))
322         c groups)
323     (gnus-group-iterate arg
324       (lambda (group)
325         (when (cadddr (setq c (gnus-group-category group)))
326           (setf (cadddr c) (delete group (cadddr c))))
327         (push group groups)))
328     (setf (cadddr cat) (nconc (cadddr cat) groups))
329     (gnus-category-write)))
330
331 ;;;
332 ;;; Server mode commands
333 ;;;
334
335 (defun gnus-agent-add-server (server)
336   "Enroll SERVER in the agent program."
337   (interactive (list (gnus-server-server-name)))
338   (unless server
339     (error "No server on the current line"))
340   (let ((method (gnus-server-get-method nil (gnus-server-server-name))))
341     (when (member method gnus-agent-covered-methods)
342       (error "Server already in the agent program"))
343     (push method gnus-agent-covered-methods)
344     (gnus-agent-write-servers)
345     (message "Entered %s into the agent" server)))
346
347 (defun gnus-agent-remove-server (server)
348   "Remove SERVER from the agent program."
349   (interactive (list (gnus-server-server-name)))
350   (unless server
351     (error "No server on the current line"))
352   (let ((method (gnus-server-get-method nil (gnus-server-server-name))))
353     (unless (member method gnus-agent-covered-methods)
354       (error "Server not in the agent program"))
355     (setq gnus-agent-covered-methods
356           (delete method gnus-agent-covered-methods))
357     (gnus-agent-write-servers)
358     (message "Removed %s from the agent" server)))
359
360 (defun gnus-agent-read-servers ()
361   "Read the alist of covered servers."
362   (setq gnus-agent-covered-methods
363         (gnus-agent-read-file
364          (nnheader-concat gnus-agent-directory "lib/servers"))))
365
366 (defun gnus-agent-write-servers ()
367   "Write the alist of covered servers."
368   (nnheader-temp-write (nnheader-concat gnus-agent-directory "lib/servers")
369     (prin1 gnus-agent-covered-methods (current-buffer))))
370
371 ;;;
372 ;;; Summary commands
373 ;;;
374
375 (defun gnus-agent-mark-article (n &optional unmark)
376   "Mark the next N articles as downloadable.
377 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
378 the mark instead.  The difference between N and the actual number of
379 articles marked is returned."
380   (interactive "p")
381   (let ((backward (< n 0))
382         (n (abs n)))
383     (while (and
384             (> n 0)
385             (progn
386               (gnus-summary-set-agent-mark
387                (gnus-summary-article-number) unmark)
388               (zerop (gnus-summary-next-subject (if backward -1 1) nil t))))
389       (setq n (1- n)))
390     (when (/= 0 n)
391       (gnus-message 7 "No more articles"))
392     (gnus-summary-recenter)
393     (gnus-summary-position-point)
394     n))
395
396 (defun gnus-agent-unmark-article (n)
397   "Remove the downloadable mark from the next N articles.
398 If N is negative, unmark backward instead.  The difference between N and
399 the actual number of articles unmarked is returned."
400   (interactive "p")
401   (gnus-agent-mark-article n t))
402
403 (defun gnus-agent-toggle-mark (n)
404   "Toggle the downloadable mark from the next N articles.
405 If N is negative, toggle backward instead.  The difference between N and
406 the actual number of articles toggled is returned."
407   (interactive "p")
408   (gnus-agent-mark-article n 'toggle))
409
410 (defun gnus-summary-set-agent-mark (article &optional unmark)
411   "Mark ARTICLE as downloadable."
412   (let ((unmark (if (and (not (null unmark)) (not (eq t unmark)))
413                     (memq article gnus-newsgroup-downloadable)
414                   unmark)))
415     (setq gnus-newsgroup-downloadable
416           (delq article gnus-newsgroup-downloadable))
417     (unless unmark
418       (push article gnus-newsgroup-downloadable))
419     (gnus-summary-update-mark
420      (if unmark gnus-undownloaded-mark gnus-downloadable-mark)
421      'unread)))
422
423 (defun gnus-agent-get-undownloaded-list ()
424   "Mark all unfetched articles as read."
425   (let ((gnus-command-method (gnus-find-method-for-group gnus-newsgroup-name)))
426     (when (and (not gnus-plugged)
427                (gnus-agent-method-p gnus-command-method))
428       (gnus-agent-load-alist gnus-newsgroup-name)
429       (let ((articles gnus-newsgroup-unreads)
430             article)
431         (while (setq article (pop articles))
432           (unless (or (cdr (assq article gnus-agent-article-alist))
433                   (memq article gnus-newsgroup-downloadable))
434             (push article gnus-newsgroup-undownloaded)))))))
435
436 (defun gnus-agent-catchup ()
437   "Mark all undownloaded articles as read."
438   (interactive)
439   (save-excursion
440     (while gnus-newsgroup-undownloaded
441       (gnus-summary-mark-article
442        (pop gnus-newsgroup-undownloaded) gnus-catchup-mark)))
443   (gnus-summary-position-point))
444
445 ;;;
446 ;;; Internal functions
447 ;;;
448
449 (defun gnus-agent-save-active (method)
450   (when (gnus-agent-method-p method)
451     (let* ((gnus-command-method method)
452            (file (gnus-agent-lib-file "active")))
453       (gnus-make-directory (file-name-directory file))
454       (let ((coding-system-for-write gnus-agent-article-file-coding-system))
455         (write-region (point-min) (point-max) file nil 'silent))
456       (when (file-exists-p (gnus-agent-lib-file "groups"))
457         (delete-file (gnus-agent-lib-file "groups"))))))
458
459 (defun gnus-agent-save-groups (method)
460   (let* ((gnus-command-method method)
461          (file (gnus-agent-lib-file "groups")))
462     (gnus-make-directory (file-name-directory file))
463     (write-region (point-min) (point-max) file nil 'silent))
464     (when (file-exists-p (gnus-agent-lib-file "active"))
465       (delete-file (gnus-agent-lib-file "active"))))
466
467 (defun gnus-agent-group-path (group)
468   "Translate GROUP into a path."
469   (nnheader-translate-file-chars
470    (nnheader-replace-chars-in-string group ?. ?/)))
471
472 \f
473
474 (defun gnus-agent-method-p (method)
475   "Say whether METHOD is covered by the agent."
476   (member method gnus-agent-covered-methods))
477
478 (defun gnus-agent-get-function (method)
479   (if (and (not gnus-plugged)
480            (gnus-agent-method-p method))
481       (progn
482         (require 'nnagent)
483         'nnagent)
484     (car method)))
485
486 ;;; History functions
487
488 (defun gnus-agent-history-buffer ()
489   (cdr (assoc (gnus-agent-method) gnus-agent-history-buffers)))
490
491 (defun gnus-agent-open-history ()
492   (save-excursion
493     (push (cons (gnus-agent-method)
494                 (set-buffer (get-buffer-create
495                              (format " *Gnus agent %s history*"
496                                      (gnus-agent-method)))))
497           gnus-agent-history-buffers)
498     (erase-buffer)
499     (insert "\n")
500     (let ((file (gnus-agent-lib-file "history")))
501       (when (file-exists-p file)
502         (insert-file file))
503       (set (make-local-variable 'gnus-agent-file-name) file))))
504
505 (defun gnus-agent-save-history ()
506   (save-excursion
507     (set-buffer gnus-agent-current-history)
508     (gnus-make-directory (file-name-directory gnus-agent-file-name))
509     (write-region (1+ (point-min)) (point-max)
510                   gnus-agent-file-name nil 'silent)))
511
512 (defun gnus-agent-close-history ()
513   (when (gnus-buffer-live-p gnus-agent-current-history)
514     (kill-buffer gnus-agent-current-history)
515     (setq gnus-agent-history-buffers
516           (delq (assoc (gnus-agent-method) gnus-agent-history-buffers)
517                 gnus-agent-history-buffers))))
518
519 (defun gnus-agent-enter-history (id group-arts date)
520   (save-excursion
521     (set-buffer gnus-agent-current-history)
522     (goto-char (point-max))
523     (insert id "\t" (number-to-string date) "\t")
524     (while group-arts
525       (insert (caar group-arts) "/" (number-to-string (cdr (pop group-arts)))
526               " "))
527     (insert "\n")))
528
529 (defun gnus-agent-article-in-history-p (id)
530   (save-excursion
531     (set-buffer (gnus-agent-history-buffer))
532     (goto-char (point-min))
533     (search-forward (concat "\n" id "\t") nil t)))
534
535 (defun gnus-agent-history-path (id)
536   (save-excursion
537     (set-buffer (gnus-agent-history-buffer))
538     (goto-char (point-min))
539     (when (search-forward (concat "\n" id "\t") nil t)
540       (let ((method (gnus-agent-method)))
541         (let (paths group)
542           (while (not (numberp (setq group (read (current-buffer)))))
543             (push (concat method "/" group) paths))
544           (nreverse paths))))))
545
546 ;;;
547 ;;; Fetching
548 ;;;
549
550 (defun gnus-agent-fetch-articles (group articles)
551   "Fetch ARTICLES from GROUP and put them into the agent."
552   (when articles
553     ;; Prune off articles that we have already fetched.
554     (while (and articles
555                 (cdr (assq (car articles) gnus-agent-article-alist)))
556       (pop articles))
557     (let ((arts articles))
558       (while (cdr arts)
559         (if (cdr (assq (cadr arts) gnus-agent-article-alist))
560             (setcdr arts (cddr arts))
561           (setq arts (cdr arts)))))
562     (when articles
563       (let ((dir (concat
564                   (gnus-agent-directory)
565                   (gnus-agent-group-path group) "/"))
566             (date (gnus-time-to-day (current-time)))
567             (case-fold-search t)
568             pos alists crosses id elem)
569         (gnus-make-directory dir)
570         (gnus-message 7 "Fetching articles for %s..." group)
571         ;; Fetch the articles from the backend.
572         (if (gnus-check-backend-function 'retrieve-articles group)
573             (setq pos (gnus-retrieve-articles articles group))
574           (nnheader-temp-write nil
575             (let ((buf (current-buffer))
576                   article)
577               (while (setq article (pop articles))
578                 (when (gnus-request-article article group)
579                   (goto-char (point-max))
580                   (push (cons article (point)) pos)
581                   (insert-buffer-substring nntp-server-buffer)))
582               (copy-to-buffer nntp-server-buffer (point-min) (point-max))
583               (setq pos (nreverse pos)))))
584         ;; Then save these articles into the agent.
585         (save-excursion
586           (set-buffer nntp-server-buffer)
587           (while pos
588             (narrow-to-region (cdar pos) (or (cdadr pos) (point-max)))
589             (goto-char (point-min))
590             (when (search-forward "\n\n" nil t)
591               (when (search-backward "\nXrefs: " nil t)
592                 ;; Handle crossposting.
593                 (skip-chars-forward "^ ")
594                 (skip-chars-forward " ")
595                 (setq crosses nil)
596                 (while (looking-at "\\([^: \n]+\\):\\([0-9]+\\) +")
597                   (push (cons (buffer-substring (match-beginning 1)
598                                                 (match-end 1))
599                               (buffer-substring (match-beginning 2)
600                                                 (match-end 2)))
601                         crosses)
602                   (goto-char (match-end 0)))
603                 (gnus-agent-crosspost crosses (caar pos))))
604             (goto-char (point-min))
605             (if (not (re-search-forward "^Message-ID: *<\\([^>\n]+\\)>" nil t))
606                 (setq id "No-Message-ID-in-article")
607               (setq id (buffer-substring (match-beginning 1) (match-end 1))))
608             (let ((coding-system-for-write gnus-agent-article-file-coding-system))
609               (write-region (point-min) (point-max)
610                             (concat dir (number-to-string (caar pos)))
611                             nil 'silent))
612             (when (setq elem (assq (caar pos) gnus-agent-article-alist))
613               (setcdr elem t))
614             (gnus-agent-enter-history
615              id (or crosses (list (cons group (caar pos)))) date)
616             (widen)
617             (pop pos)))
618         (gnus-agent-save-alist group)))))
619
620 (defun gnus-agent-crosspost (crosses article)
621   (let (gnus-agent-article-alist group alist beg end)
622     (save-excursion
623       (set-buffer gnus-agent-overview-buffer)
624       (when (nnheader-find-nov-line article)
625         (forward-word 1)
626         (setq beg (point))
627         (setq end (progn (forward-line 1) (point)))))
628     (while crosses
629       (setq group (caar crosses))
630       (unless (setq alist (assoc group gnus-agent-group-alist))
631         (push (setq alist (list group (gnus-agent-load-alist (caar crosses))))
632               gnus-agent-group-alist))
633       (setcdr alist (cons (cons (cdar crosses) t) (cdr alist)))
634       (save-excursion
635         (set-buffer (get-buffer-create (format " *Gnus agent overview %s*"
636                                                group)))
637         (when (= (point-max) (point-min))
638           (push (cons group (current-buffer)) gnus-agent-buffer-alist)
639           (ignore-errors
640             (insert-file-contents
641              (gnus-agent-article-name ".overview" group))))
642         (nnheader-find-nov-line (string-to-number (cdar crosses)))
643         (insert (string-to-number (cdar crosses)))
644         (insert-buffer-substring gnus-agent-overview-buffer beg end))
645       (pop crosses))))
646
647 (defun gnus-agent-flush-cache ()
648   (save-excursion
649     (while gnus-agent-buffer-alist
650       (set-buffer (cdar gnus-agent-buffer-alist))
651       (write-region (point-min) (point-max)
652                     (gnus-agent-article-name ".overview"
653                                              (caar gnus-agent-buffer-alist))
654                      nil 'silent)
655       (pop gnus-agent-buffer-alist))
656     (while gnus-agent-group-alist
657       (nnheader-temp-write (caar gnus-agent-group-alist)
658         (princ (cdar gnus-agent-group-alist))
659         (insert "\n"))
660       (pop gnus-agent-group-alist))))
661
662 (defun gnus-agent-fetch-headers (group articles &optional force)
663   (gnus-agent-load-alist group)
664   ;; Find out what headers we need to retrieve.
665   (when articles
666     (while (and articles
667                 (assq (car articles) gnus-agent-article-alist))
668       (pop articles))
669     (let ((arts articles))
670       (while (cdr arts)
671         (if (assq (cadr arts) gnus-agent-article-alist)
672             (setcdr arts (cddr arts))
673           (setq arts (cdr arts)))))
674     ;; Fetch them.
675     (when articles
676       (gnus-message 7 "Fetching headers for %s..." group)
677       (save-excursion
678         (set-buffer nntp-server-buffer)
679         (unless (eq 'nov (gnus-retrieve-headers articles group))
680           (nnvirtual-convert-headers))
681         ;; Save these headers for later processing.
682         (copy-to-buffer gnus-agent-overview-buffer (point-min) (point-max))
683         (let (file)
684           (when (file-exists-p
685                  (setq file (gnus-agent-article-name ".overview" group)))
686             (gnus-agent-braid-nov group articles file))
687           (gnus-make-directory (nnheader-translate-file-chars
688                                 (file-name-directory file)))
689           (write-region (point-min) (point-max) file nil 'silent)
690           (gnus-agent-save-alist group articles nil))
691         t))))
692
693 (defsubst gnus-agent-copy-nov-line (article)
694   (let (b e)
695     (set-buffer gnus-agent-overview-buffer)
696     (setq b (point))
697     (if (eq article (read (current-buffer)))
698         (setq e (progn (forward-line 1) (point)))
699       (setq e b))
700     (set-buffer nntp-server-buffer)
701     (insert-buffer-substring gnus-agent-overview-buffer b e)))
702
703 (defun gnus-agent-braid-nov (group articles file)
704   (let (beg end)
705     (set-buffer gnus-agent-overview-buffer)
706     (goto-char (point-min))
707     (set-buffer nntp-server-buffer)
708     (erase-buffer)
709     (insert-file-contents file)
710     (goto-char (point-min))
711     (if (or (= (point-min) (point-max))
712             (progn
713               (forward-line -1)
714               (< (read (current-buffer)) (car articles))))
715         ;; We have only headers that are after the older headers,
716         ;; so we just append them.
717         (progn
718           (goto-char (point-max))
719           (insert-buffer-substring gnus-agent-overview-buffer))
720       ;; We do it the hard way.
721       (nnheader-find-nov-line (car articles))
722       (gnus-agent-copy-nov-line (car articles))
723       (pop articles)
724       (while (and articles
725                   (not (eobp)))
726         (while (and (not (eobp))
727                     (< (read (current-buffer)) (car articles)))
728           (forward-line 1))
729         (beginning-of-line)
730         (unless (eobp)
731           (gnus-agent-copy-nov-line (car articles))
732           (setq articles (cdr articles))))
733       (when articles
734         (let (b e)
735           (set-buffer gnus-agent-overview-buffer)
736           (setq b (point)
737                 e (point-max))
738           (set-buffer nntp-server-buffer)
739           (insert-buffer-substring gnus-agent-overview-buffer b e))))))
740
741 (defun gnus-agent-load-alist (group &optional dir)
742   "Load the article-state alist for GROUP."
743   (setq gnus-agent-article-alist
744         (gnus-agent-read-file
745          (if dir
746              (concat dir ".agentview")
747            (gnus-agent-article-name ".agentview" group)))))
748
749 (defun gnus-agent-save-alist (group &optional articles state dir)
750   "Load the article-state alist for GROUP."
751   (nnheader-temp-write (if dir
752                            (concat dir ".agentview")
753                          (gnus-agent-article-name ".agentview" group))
754     (princ (setq gnus-agent-article-alist
755                  (nconc gnus-agent-article-alist
756                         (mapcar (lambda (article) (cons article state))
757                                 articles)))
758            (current-buffer))
759     (insert "\n")))
760
761 (defun gnus-agent-article-name (article group)
762   (concat (gnus-agent-directory) (gnus-agent-group-path group) "/"
763           (if (stringp article) article (string-to-number article))))
764
765 ;;;###autoload
766 (defun gnus-agent-batch-fetch ()
767   "Start Gnus and fetch session."
768   (interactive)
769   (gnus)
770   (gnus-agent-fetch-session)
771   (gnus-group-exit))
772
773 (defun gnus-agent-fetch-session ()
774   "Fetch all articles and headers that are eligible for fetching."
775   (interactive)
776   (unless gnus-agent-covered-methods
777     (error "No servers are covered by the Gnus agent"))
778   (unless gnus-plugged
779     (error "Can't fetch articles while Gnus is unplugged"))
780   (let ((methods gnus-agent-covered-methods)
781         groups group gnus-command-method)
782     (save-excursion
783       (while methods
784         (setq gnus-command-method (car methods)
785               groups (gnus-groups-from-server (pop methods)))
786         (gnus-agent-with-fetch
787           (while (setq group (pop groups))
788             (gnus-agent-fetch-group-1 group gnus-command-method))))
789       (gnus-message 6 "Finished fetching articles into the Gnus agent"))))
790
791 (defun gnus-agent-fetch-group-1 (group method)
792   "Fetch GROUP."
793   (let ((gnus-command-method method)
794         gnus-newsgroup-dependencies gnus-newsgroup-headers
795         gnus-newsgroup-scored gnus-headers gnus-score
796         gnus-use-cache articles score arts
797         category predicate info marks score-param)
798     ;; Fetch headers.
799     (when (and (setq articles (gnus-list-of-unread-articles group))
800                (gnus-agent-fetch-headers group articles))
801       ;; Parse them and see which articles we want to fetch.
802       (setq gnus-newsgroup-dependencies
803             (make-vector (length articles) 0))
804       (setq gnus-newsgroup-headers
805             (gnus-get-newsgroup-headers-xover articles nil nil group))
806       (setq category (gnus-group-category group))
807       (setq predicate
808             (gnus-get-predicate 
809              (or (gnus-group-get-parameter group 'agent-predicate)
810                  (cadr category))))
811       (setq score-param
812             (or (gnus-group-get-parameter group 'agent-score)
813                 (caddr category)))
814       (when score-param
815         (gnus-score-headers (list (list score-param))))
816       (setq arts nil)
817       (while (setq gnus-headers (pop gnus-newsgroup-headers))
818         (setq gnus-score
819               (or (cdr (assq (mail-header-number gnus-headers)
820                              gnus-newsgroup-scored))
821                   gnus-summary-default-score))
822         (when (funcall predicate)
823           (push (mail-header-number gnus-headers)
824                 arts)))
825       ;; Fetch the articles.
826       (when arts
827         (gnus-agent-fetch-articles group arts)))
828     ;; Perhaps we have some additional articles to fetch.
829     (setq arts (assq 'download (gnus-info-marks
830                                 (setq info (gnus-get-info group)))))
831     (when (cdr arts)
832       (gnus-agent-fetch-articles
833        group (gnus-uncompress-range (cdr arts)))
834       (setq marks (delq arts (gnus-info-marks info)))
835       (gnus-info-set-marks info marks))))
836
837 ;;;
838 ;;; Agent Category Mode
839 ;;;
840
841 (defvar gnus-category-mode-hook nil
842   "Hook run in `gnus-category-mode' buffers.")
843
844 (defvar gnus-category-line-format "     %(%20c%): %g\n"
845   "Format of category lines.")
846
847 (defvar gnus-category-mode-line-format "Gnus: %%b"
848   "The format specification for the category mode line.")
849
850 (defvar gnus-agent-short-article 100
851   "Articles that have fewer lines than this are short.")
852
853 (defvar gnus-agent-long-article 200
854   "Articles that have more lines than this are long.")
855
856 (defvar gnus-agent-low-score 0
857   "Articles that have a score lower than this have a low score.")
858
859 (defvar gnus-agent-high-score 0
860   "Articles that have a score higher than this have a high score.")
861
862
863 ;;; Internal variables.
864
865 (defvar gnus-category-buffer "*Agent Category*")
866
867 (defvar gnus-category-line-format-alist
868   `((?c name ?s)
869     (?g groups ?d)))
870
871 (defvar gnus-category-mode-line-format-alist
872   `((?u user-defined ?s)))
873
874 (defvar gnus-category-line-format-spec nil)
875 (defvar gnus-category-mode-line-format-spec nil)
876
877 (defvar gnus-category-mode-map nil)
878 (put 'gnus-category-mode 'mode-class 'special)
879
880 (unless gnus-category-mode-map
881   (setq gnus-category-mode-map (make-sparse-keymap))
882   (suppress-keymap gnus-category-mode-map)
883
884   (gnus-define-keys gnus-category-mode-map
885     "q" gnus-category-exit
886     "k" gnus-category-kill
887     "c" gnus-category-copy
888     "a" gnus-category-add
889     "p" gnus-category-edit-predicate
890     "g" gnus-category-edit-groups
891     "s" gnus-category-edit-score
892     "l" gnus-category-list
893
894     "\C-c\C-i" gnus-info-find-node
895     "\C-c\C-b" gnus-bug))
896
897 (defvar gnus-category-menu-hook nil
898   "*Hook run after the creation of the menu.")
899
900 (defun gnus-category-make-menu-bar ()
901   (gnus-turn-off-edit-menu 'category)
902   (unless (boundp 'gnus-category-menu)
903     (easy-menu-define
904      gnus-category-menu gnus-category-mode-map ""
905      '("Categories"
906        ["Add" gnus-category-add t]
907        ["Kill" gnus-category-kill t]
908        ["Copy" gnus-category-copy t]
909        ["Edit predicate" gnus-category-edit-predicate t]
910        ["Edit score" gnus-category-edit-score t]
911        ["Edit groups" gnus-category-edit-groups t]
912        ["Exit" gnus-category-exit t]))
913
914     (run-hooks 'gnus-category-menu-hook)))
915
916 (defun gnus-category-mode ()
917   "Major mode for listing and editing agent categories.
918
919 All normal editing commands are switched off.
920 \\<gnus-category-mode-map>
921 For more in-depth information on this mode, read the manual
922 (`\\[gnus-info-find-node]').
923
924 The following commands are available:
925
926 \\{gnus-category-mode-map}"
927   (interactive)
928   (when (gnus-visual-p 'category-menu 'menu)
929     (gnus-category-make-menu-bar))
930   (kill-all-local-variables)
931   (gnus-simplify-mode-line)
932   (setq major-mode 'gnus-category-mode)
933   (setq mode-name "Category")
934   (gnus-set-default-directory)
935   (setq mode-line-process nil)
936   (use-local-map gnus-category-mode-map)
937   (buffer-disable-undo (current-buffer))
938   (setq truncate-lines t)
939   (setq buffer-read-only t)
940   (run-hooks 'gnus-category-mode-hook))
941
942 (defalias 'gnus-category-position-point 'gnus-goto-colon)
943
944 (defun gnus-category-insert-line (category)
945   (let* ((name (car category))
946          (groups (length (cadddr category))))
947     (beginning-of-line)
948     (gnus-add-text-properties
949      (point)
950      (prog1 (1+ (point))
951        ;; Insert the text.
952        (eval gnus-category-line-format-spec))
953      (list 'gnus-category name))))
954
955 (defun gnus-enter-category-buffer ()
956   "Go to the Category buffer."
957   (interactive)
958   (gnus-category-setup-buffer)
959   (gnus-configure-windows 'category)
960   (gnus-category-prepare))
961
962 (defun gnus-category-setup-buffer ()
963   (unless (get-buffer gnus-category-buffer)
964     (save-excursion
965       (set-buffer (get-buffer-create gnus-category-buffer))
966       (gnus-add-current-to-buffer-list)
967       (gnus-category-mode))))
968
969 (defun gnus-category-prepare ()
970   (gnus-set-format 'category-mode)
971   (gnus-set-format 'category t)
972   (let ((alist gnus-category-alist)
973         (buffer-read-only nil))
974     (erase-buffer)
975     (while alist
976       (gnus-category-insert-line (pop alist)))
977     (goto-char (point-min))
978     (gnus-category-position-point)))
979
980 (defun gnus-category-name ()
981   (or (get-text-property (gnus-point-at-bol) 'gnus-category)
982       (error "No category on the current line")))
983
984 (defun gnus-category-read ()
985   "Read the category alist."
986   (setq gnus-category-alist
987         (or (gnus-agent-read-file
988              (nnheader-concat gnus-agent-directory "lib/categories"))
989             (list (list 'default 'true nil nil)))))
990     
991 (defun gnus-category-write ()
992   "Write the category alist."
993   (setq gnus-category-predicate-cache nil
994         gnus-category-group-cache nil)
995   (nnheader-temp-write (nnheader-concat gnus-agent-directory "lib/categories")
996     (prin1 gnus-category-alist (current-buffer))))
997
998 (defun gnus-category-edit-predicate (category)
999   "Edit the predicate for CATEGORY."
1000   (interactive (list (gnus-category-name)))
1001   (let ((info (assq category gnus-category-alist)))
1002     (gnus-edit-form
1003      (cadr info) (format "Editing the predicate for category %s" category)
1004      `(lambda (predicate)
1005         (setf (cadr (assq ',category gnus-category-alist)) predicate)
1006         (gnus-category-write)
1007         (gnus-category-list)))))
1008   
1009 (defun gnus-category-edit-score (category)
1010   "Edit the score expression for CATEGORY."
1011   (interactive (list (gnus-category-name)))
1012   (let ((info (assq category gnus-category-alist)))
1013     (gnus-edit-form
1014      (caddr info)
1015      (format "Editing the score expression for category %s" category)
1016      `(lambda (groups)
1017         (setf (caddr (assq ',category gnus-category-alist)) groups)
1018         (gnus-category-write)
1019         (gnus-category-list)))))
1020
1021 (defun gnus-category-edit-groups (category)
1022   "Edit the group list for CATEGORY."
1023   (interactive (list (gnus-category-name)))
1024   (let ((info (assq category gnus-category-alist)))
1025     (gnus-edit-form
1026      (cadddr info) (format "Editing the group list for category %s" category)
1027      `(lambda (groups)
1028         (setf (cadddr (assq ',category gnus-category-alist)) groups)
1029         (gnus-category-write)
1030         (gnus-category-list)))))
1031
1032 (defun gnus-category-kill (category)
1033   "Kill the current category."
1034   (interactive (list (gnus-category-name)))
1035   (let ((info (assq category gnus-category-alist))
1036         (buffer-read-only nil))
1037     (gnus-delete-line)
1038     (gnus-category-write)
1039     (setq gnus-category-alist (delq info gnus-category-alist))))
1040
1041 (defun gnus-category-copy (category to)
1042   "Copy the current category."
1043   (interactive (list (gnus-category-name) (intern (read-string "New name: "))))
1044   (let ((info (assq category gnus-category-alist)))
1045     (push (list to (gnus-copy-sequence (cadr info))
1046                 (gnus-copy-sequence (caddr info)) nil)
1047           gnus-category-alist)
1048     (gnus-category-write)
1049     (gnus-category-list)))
1050
1051 (defun gnus-category-add (category)
1052   "Create a new category."
1053   (interactive "SCategory name: ")
1054   (when (assq category gnus-category-alist)
1055     (error "Category %s already exists" category))
1056   (push (list category 'true nil nil)
1057         gnus-category-alist)
1058   (gnus-category-write)
1059   (gnus-category-list))
1060
1061 (defun gnus-category-list ()
1062   "List all categories."
1063   (interactive)
1064   (gnus-category-prepare))
1065
1066 (defun gnus-category-exit ()
1067   "Return to the group buffer."
1068   (interactive)
1069   (kill-buffer (current-buffer))
1070   (gnus-configure-windows 'group t))
1071
1072 ;; To avoid having 8-bit characters in the source file.
1073 (defvar gnus-category-not (list '! 'not (intern (format "%c" 172))))
1074
1075 (defvar gnus-category-predicate-alist
1076   '((spam . gnus-agent-spam-p)
1077     (short . gnus-agent-short-p)
1078     (long . gnus-agent-long-p)
1079     (low . gnus-agent-low-scored-p)
1080     (high . gnus-agent-high-scored-p)
1081     (true . gnus-agent-true)
1082     (false . gnus-agent-false))
1083   "Mapping from short score predicate symbols to predicate functions.")
1084
1085 (defun gnus-agent-spam-p ()
1086   "Say whether an article is spam or not."
1087   (unless gnus-agent-spam-hashtb
1088     (setq gnus-agent-spam-hashtb (gnus-make-hashtable 1000)))
1089   (if (not (equal (mail-header-references gnus-headers) ""))
1090       nil
1091     (let ((string (gnus-simplify-subject (mail-header-subject gnus-headers))))
1092       (prog1
1093           (gnus-gethash string gnus-agent-spam-hashtb)
1094         (gnus-sethash string t gnus-agent-spam-hashtb)))))
1095
1096 (defun gnus-agent-short-p ()
1097   "Say whether an article is short or not."
1098   (< (mail-header-lines gnus-headers) gnus-agent-short-article))
1099
1100 (defun gnus-agent-long-p ()
1101   "Say whether an article is long or not."
1102   (> (mail-header-lines gnus-headers) gnus-agent-long-article))
1103
1104 (defun gnus-agent-low-scored-p ()
1105   "Say whether an article has a low score or not."
1106   (< gnus-score gnus-agent-low-score))
1107
1108 (defun gnus-agent-high-scored-p ()
1109   "Say whether an article has a high score or not."
1110   (> gnus-score gnus-agent-low-score))
1111
1112 (defun gnus-category-make-function (cat)
1113   "Make a function from category CAT."
1114   `(lambda () ,(gnus-category-make-function-1 cat)))
1115
1116 (defun gnus-agent-true ()
1117   "Return t."
1118   t)
1119
1120 (defun gnus-agent-false ()
1121   "Return nil."
1122   nil)
1123   
1124 (defun gnus-category-make-function-1 (cat)
1125   "Make a function from category CAT."
1126   (cond
1127    ;; Functions are just returned as is.
1128    ((or (symbolp cat)
1129         (gnus-functionp cat))
1130     `(,(or (cdr (assq cat gnus-category-predicate-alist))
1131            cat)))
1132    ;; More complex category.
1133    ((consp cat)
1134     `(,(cond
1135         ((memq (car cat) '(& and))
1136          'and)
1137         ((memq (car cat) '(| or))
1138          'or)
1139         ((memq (car cat) gnus-category-not)
1140          'not))
1141       ,@(mapcar 'gnus-category-make-function-1 (cdr cat))))
1142    (t
1143     (error "Unknown category type: %s" cat))))
1144
1145 (defun gnus-get-predicate (predicate)
1146   "Return the predicate for CATEGORY."
1147   (or (cdr (assoc predicate gnus-category-predicate-cache))
1148       (cdar (push (cons predicate
1149                         (gnus-category-make-function predicate))
1150                   gnus-category-predicate-cache))))
1151
1152 (defun gnus-group-category (group)
1153   "Return the category GROUP belongs to."
1154   (unless gnus-category-group-cache
1155     (setq gnus-category-group-cache (gnus-make-hashtable 1000))
1156     (let ((cs gnus-category-alist)
1157           groups cat)
1158       (while (setq cat (pop cs))
1159         (setq groups (cadddr cat))
1160         (while groups
1161           (gnus-sethash (pop groups) cat gnus-category-group-cache)))))
1162   (or (gnus-gethash group gnus-category-group-cache)
1163       (assq 'default gnus-category-alist)))
1164
1165 (defun gnus-agent-expire ()
1166   "Expire all old articles."
1167   (interactive)
1168   (let ((methods gnus-agent-covered-methods)
1169         (alist (cdr gnus-newsrc-alist))
1170         gnus-command-method ofiles info method file group)
1171     (while (setq gnus-command-method (pop methods))
1172       (setq ofiles (nconc ofiles (gnus-agent-expire-directory
1173                                   (gnus-agent-directory)))))
1174     (while (setq info (pop alist))
1175       (when (and (gnus-agent-method-p
1176                   (setq gnus-command-method
1177                         (gnus-find-method-for-group
1178                          (setq group (gnus-info-group info)))))
1179                  (member
1180                   (setq file
1181                         (concat
1182                          (gnus-agent-directory)
1183                          (gnus-agent-group-path group) "/.overview"))
1184                   ofiles))
1185         (setq ofiles (delete file ofiles))
1186         (gnus-agent-expire-group file group)))
1187     (while ofiles
1188       (gnus-agent-expire-group (pop ofiles)))))
1189
1190 (defun gnus-agent-expire-directory (dir)
1191   "Expire all groups in DIR recursively."
1192   (when (file-directory-p dir)
1193     (let ((files (directory-files dir t))
1194           file ofiles)
1195       (while (setq file (pop files))
1196         (cond
1197          ((member (file-name-nondirectory file) '("." ".."))
1198           ;; Do nothing.
1199           )
1200          ((file-directory-p file)
1201           ;; Recurse.
1202           (setq ofiles (nconc ofiles (gnus-agent-expire-directory file))))
1203          ((string-match "\\.overview$" file)
1204           ;; Expire group.
1205           (push file ofiles))))
1206       ofiles)))
1207
1208 (defun gnus-agent-expire-group (overview &optional group)
1209   "Expire articles in OVERVIEW."
1210   (gnus-message 5 "Expiring %s..." overview)
1211   (let ((odate (- (gnus-time-to-day (current-time)) 4))
1212         (dir (file-name-directory overview))
1213         (info (when group (gnus-get-info group)))
1214         headers article file point unreads)
1215     (gnus-agent-load-alist nil dir)
1216     (when info
1217       (setq unreads
1218             (nconc
1219              (gnus-list-of-unread-articles group)
1220              (gnus-uncompress-range
1221               (cdr (assq 'tick (gnus-info-marks info))))
1222              (gnus-uncompress-range
1223               (cdr (assq 'dormant (gnus-info-marks info)))))))
1224     (nnheader-temp-write overview
1225       (insert-file-contents overview)
1226       (goto-char (point-min))
1227       (while (not (eobp))
1228         (setq point (point))
1229         (condition-case ()
1230             (setq headers (inline (nnheader-parse-nov)))
1231           (error
1232            (goto-char point)
1233            (gnus-delete-line)
1234            (setq headers nil)))
1235         (when headers
1236           (unless (memq (setq article (mail-header-number headers)) unreads)
1237             (if (not (< (inline
1238                           (gnus-time-to-day
1239                            (inline (nnmail-date-to-time
1240                                     (mail-header-date headers)))))
1241                         odate))
1242                 (forward-line 1)              
1243               (gnus-delete-line)
1244               (setq gnus-agent-article-alist
1245                     (delq (assq article gnus-agent-article-alist)
1246                           gnus-agent-article-alist))
1247               (when (file-exists-p
1248                      (setq file (concat dir (number-to-string article))))
1249                 (delete-file file))))))
1250       (gnus-agent-save-alist nil nil nil dir))))
1251
1252 (provide 'gnus-agent)
1253
1254 ;;; gnus-agent.el ends here