*** 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   (gnus-set-global-variables)
382   (let ((backward (< n 0))
383         (n (abs n)))
384     (while (and
385             (> n 0)
386             (progn
387               (gnus-summary-set-agent-mark
388                (gnus-summary-article-number) unmark)
389               (zerop (gnus-summary-next-subject (if backward -1 1) nil t))))
390       (setq n (1- n)))
391     (when (/= 0 n)
392       (gnus-message 7 "No more articles"))
393     (gnus-summary-recenter)
394     (gnus-summary-position-point)
395     n))
396
397 (defun gnus-agent-unmark-article (n)
398   "Remove the downloadable mark from the next N articles.
399 If N is negative, unmark backward instead.  The difference between N and
400 the actual number of articles unmarked is returned."
401   (interactive "p")
402   (gnus-set-global-variables)
403   (gnus-agent-mark-article n t))
404
405 (defun gnus-agent-toggle-mark (n)
406   "Toggle the downloadable mark from the next N articles.
407 If N is negative, toggle backward instead.  The difference between N and
408 the actual number of articles toggled is returned."
409   (interactive "p")
410   (gnus-set-global-variables)
411   (gnus-agent-mark-article n 'toggle))
412
413 (defun gnus-summary-set-agent-mark (article &optional unmark)
414   "Mark ARTICLE as downloadable."
415   (let ((unmark (if (and (not (null unmark)) (not (eq t unmark)))
416                     (memq article gnus-newsgroup-downloadable)
417                   unmark)))
418     (setq gnus-newsgroup-downloadable
419           (delq article gnus-newsgroup-downloadable))
420     (unless unmark
421       (push article gnus-newsgroup-downloadable))
422     (gnus-summary-update-mark
423      (if unmark gnus-undownloaded-mark gnus-downloadable-mark)
424      'unread)))
425
426 (defun gnus-agent-get-undownloaded-list ()
427   "Mark all unfetched articles as read."
428   (let ((gnus-command-method (gnus-find-method-for-group gnus-newsgroup-name)))
429     (when (and (not gnus-plugged)
430                (gnus-agent-method-p gnus-command-method))
431       (gnus-agent-load-alist gnus-newsgroup-name)
432       (let ((articles gnus-newsgroup-unreads)
433             article)
434         (while (setq article (pop articles))
435           (unless (or (cdr (assq article gnus-agent-article-alist))
436                   (memq article gnus-newsgroup-downloadable))
437             (push article gnus-newsgroup-undownloaded)))))))
438
439 (defun gnus-agent-catchup ()
440   "Mark all undownloaded articles as read."
441   (interactive)
442   (save-excursion
443     (while gnus-newsgroup-undownloaded
444       (gnus-summary-mark-article
445        (pop gnus-newsgroup-undownloaded) gnus-catchup-mark)))
446   (gnus-summary-position-point))
447
448 ;;;
449 ;;; Internal functions
450 ;;;
451
452 (defun gnus-agent-save-active (method)
453   (when (gnus-agent-method-p method)
454     (let* ((gnus-command-method method)
455            (file (gnus-agent-lib-file "active")))
456       (gnus-make-directory (file-name-directory file))
457       (let ((coding-system-for-write gnus-agent-article-file-coding-system))
458         (write-region (point-min) (point-max) file nil 'silent))
459       (when (file-exists-p (gnus-agent-lib-file "groups"))
460         (delete-file (gnus-agent-lib-file "groups"))))))
461
462 (defun gnus-agent-save-groups (method)
463   (let* ((gnus-command-method method)
464          (file (gnus-agent-lib-file "groups")))
465     (gnus-make-directory (file-name-directory file))
466     (write-region (point-min) (point-max) file nil 'silent))
467     (when (file-exists-p (gnus-agent-lib-file "active"))
468       (delete-file (gnus-agent-lib-file "active"))))
469
470 (defun gnus-agent-group-path (group)
471   "Translate GROUP into a path."
472   (nnheader-translate-file-chars
473    (nnheader-replace-chars-in-string group ?. ?/)))
474
475 \f
476
477 (defun gnus-agent-method-p (method)
478   "Say whether METHOD is covered by the agent."
479   (member method gnus-agent-covered-methods))
480
481 (defun gnus-agent-get-function (method)
482   (if (and (not gnus-plugged)
483            (gnus-agent-method-p method))
484       (progn
485         (require 'nnagent)
486         'nnagent)
487     (car method)))
488
489 ;;; History functions
490
491 (defun gnus-agent-history-buffer ()
492   (cdr (assoc (gnus-agent-method) gnus-agent-history-buffers)))
493
494 (defun gnus-agent-open-history ()
495   (save-excursion
496     (push (cons (gnus-agent-method)
497                 (set-buffer (get-buffer-create
498                              (format " *Gnus agent %s history*"
499                                      (gnus-agent-method)))))
500           gnus-agent-history-buffers)
501     (erase-buffer)
502     (insert "\n")
503     (let ((file (gnus-agent-lib-file "history")))
504       (when (file-exists-p file)
505         (insert-file file))
506       (set (make-local-variable 'gnus-agent-file-name) file))))
507
508 (defun gnus-agent-save-history ()
509   (save-excursion
510     (set-buffer gnus-agent-current-history)
511     (gnus-make-directory (file-name-directory gnus-agent-file-name))
512     (write-region (1+ (point-min)) (point-max)
513                   gnus-agent-file-name nil 'silent)))
514
515 (defun gnus-agent-close-history ()
516   (when (gnus-buffer-live-p gnus-agent-current-history)
517     (kill-buffer gnus-agent-current-history)
518     (setq gnus-agent-history-buffers
519           (delq (assoc (gnus-agent-method) gnus-agent-history-buffers)
520                 gnus-agent-history-buffers))))
521
522 (defun gnus-agent-enter-history (id group-arts date)
523   (save-excursion
524     (set-buffer gnus-agent-current-history)
525     (goto-char (point-max))
526     (insert id "\t" (number-to-string date) "\t")
527     (while group-arts
528       (insert (caar group-arts) "/" (number-to-string (cdr (pop group-arts)))
529               " "))
530     (insert "\n")))
531
532 (defun gnus-agent-article-in-history-p (id)
533   (save-excursion
534     (set-buffer (gnus-agent-history-buffer))
535     (goto-char (point-min))
536     (search-forward (concat "\n" id "\t") nil t)))
537
538 (defun gnus-agent-history-path (id)
539   (save-excursion
540     (set-buffer (gnus-agent-history-buffer))
541     (goto-char (point-min))
542     (when (search-forward (concat "\n" id "\t") nil t)
543       (let ((method (gnus-agent-method)))
544         (let (paths group)
545           (while (not (numberp (setq group (read (current-buffer)))))
546             (push (concat method "/" group) paths))
547           (nreverse paths))))))
548
549 ;;;
550 ;;; Fetching
551 ;;;
552
553 (defun gnus-agent-fetch-articles (group articles)
554   "Fetch ARTICLES from GROUP and put them into the agent."
555   (when articles
556     ;; Prune off articles that we have already fetched.
557     (while (and articles
558                 (cdr (assq (car articles) gnus-agent-article-alist)))
559       (pop articles))
560     (let ((arts articles))
561       (while (cdr arts)
562         (if (cdr (assq (cadr arts) gnus-agent-article-alist))
563             (setcdr arts (cddr arts))
564           (setq arts (cdr arts)))))
565     (when articles
566       (let ((dir (concat
567                   (gnus-agent-directory)
568                   (gnus-agent-group-path group) "/"))
569             (date (gnus-time-to-day (current-time)))
570             (case-fold-search t)
571             pos alists crosses id elem)
572         (gnus-make-directory dir)
573         (gnus-message 7 "Fetching articles for %s..." group)
574         ;; Fetch the articles from the backend.
575         (if (gnus-check-backend-function 'retrieve-articles group)
576             (setq pos (gnus-retrieve-articles articles group))
577           (nnheader-temp-write nil
578             (let ((buf (current-buffer))
579                   article)
580               (while (setq article (pop articles))
581                 (when (gnus-request-article article group)
582                   (goto-char (point-max))
583                   (push (cons article (point)) pos)
584                   (insert-buffer-substring nntp-server-buffer)))
585               (copy-to-buffer nntp-server-buffer (point-min) (point-max))
586               (setq pos (nreverse pos)))))
587         ;; Then save these articles into the agent.
588         (save-excursion
589           (set-buffer nntp-server-buffer)
590           (while pos
591             (narrow-to-region (cdar pos) (or (cdadr pos) (point-max)))
592             (goto-char (point-min))
593             (when (search-forward "\n\n" nil t)
594               (when (search-backward "\nXrefs: " nil t)
595                 ;; Handle crossposting.
596                 (skip-chars-forward "^ ")
597                 (skip-chars-forward " ")
598                 (setq crosses nil)
599                 (while (looking-at "\\([^: \n]+\\):\\([0-9]+\\) +")
600                   (push (cons (buffer-substring (match-beginning 1)
601                                                 (match-end 1))
602                               (buffer-substring (match-beginning 2)
603                                                 (match-end 2)))
604                         crosses)
605                   (goto-char (match-end 0)))
606                 (gnus-agent-crosspost crosses (caar pos))))
607             (goto-char (point-min))
608             (if (not (re-search-forward "^Message-ID: *<\\([^>\n]+\\)>" nil t))
609                 (setq id "No-Message-ID-in-article")
610               (setq id (buffer-substring (match-beginning 1) (match-end 1))))
611             (let ((coding-system-for-write gnus-agent-article-file-coding-system))
612               (write-region (point-min) (point-max)
613                             (concat dir (number-to-string (caar pos)))
614                             nil 'silent))
615             (when (setq elem (assq (caar pos) gnus-agent-article-alist))
616               (setcdr elem t))
617             (gnus-agent-enter-history
618              id (or crosses (list (cons group (caar pos)))) date)
619             (widen)
620             (pop pos)))
621         (gnus-agent-save-alist group)))))
622
623 (defun gnus-agent-crosspost (crosses article)
624   (let (gnus-agent-article-alist group alist beg end)
625     (save-excursion
626       (set-buffer gnus-agent-overview-buffer)
627       (when (nnheader-find-nov-line article)
628         (forward-word 1)
629         (setq beg (point))
630         (setq end (progn (forward-line 1) (point)))))
631     (while crosses
632       (setq group (caar crosses))
633       (unless (setq alist (assoc group gnus-agent-group-alist))
634         (push (setq alist (list group (gnus-agent-load-alist (caar crosses))))
635               gnus-agent-group-alist))
636       (setcdr alist (cons (cons (cdar crosses) t) (cdr alist)))
637       (save-excursion
638         (set-buffer (get-buffer-create (format " *Gnus agent overview %s*"
639                                                group)))
640         (when (= (point-max) (point-min))
641           (push (cons group (current-buffer)) gnus-agent-buffer-alist)
642           (ignore-errors
643             (insert-file-contents
644              (gnus-agent-article-name ".overview" group))))
645         (nnheader-find-nov-line (string-to-number (cdar crosses)))
646         (insert (string-to-number (cdar crosses)))
647         (insert-buffer-substring gnus-agent-overview-buffer beg end))
648       (pop crosses))))
649
650 (defun gnus-agent-flush-cache ()
651   (save-excursion
652     (while gnus-agent-buffer-alist
653       (set-buffer (cdar gnus-agent-buffer-alist))
654       (write-region (point-min) (point-max)
655                     (gnus-agent-article-name ".overview"
656                                              (caar gnus-agent-buffer-alist))
657                      nil 'silent)
658       (pop gnus-agent-buffer-alist))
659     (while gnus-agent-group-alist
660       (nnheader-temp-write (caar gnus-agent-group-alist)
661         (princ (cdar gnus-agent-group-alist))
662         (insert "\n"))
663       (pop gnus-agent-group-alist))))
664
665 (defun gnus-agent-fetch-headers (group articles &optional force)
666   (gnus-agent-load-alist group)
667   ;; Find out what headers we need to retrieve.
668   (when articles
669     (while (and articles
670                 (assq (car articles) gnus-agent-article-alist))
671       (pop articles))
672     (let ((arts articles))
673       (while (cdr arts)
674         (if (assq (cadr arts) gnus-agent-article-alist)
675             (setcdr arts (cddr arts))
676           (setq arts (cdr arts)))))
677     ;; Fetch them.
678     (when articles
679       (gnus-message 7 "Fetching headers for %s..." group)
680       (save-excursion
681         (set-buffer nntp-server-buffer)
682         (unless (eq 'nov (gnus-retrieve-headers articles group))
683           (nnvirtual-convert-headers))
684         ;; Save these headers for later processing.
685         (copy-to-buffer gnus-agent-overview-buffer (point-min) (point-max))
686         (let (file)
687           (when (file-exists-p
688                  (setq file (gnus-agent-article-name ".overview" group)))
689             (gnus-agent-braid-nov group articles file))
690           (gnus-make-directory (nnheader-translate-file-chars
691                                 (file-name-directory file)))
692           (write-region (point-min) (point-max) file nil 'silent)
693           (gnus-agent-save-alist group articles nil))
694         t))))
695
696 (defsubst gnus-agent-copy-nov-line (article)
697   (let (b e)
698     (set-buffer gnus-agent-overview-buffer)
699     (setq b (point))
700     (if (eq article (read (current-buffer)))
701         (setq e (progn (forward-line 1) (point)))
702       (setq e b))
703     (set-buffer nntp-server-buffer)
704     (insert-buffer-substring gnus-agent-overview-buffer b e)))
705
706 (defun gnus-agent-braid-nov (group articles file)
707   (let (beg end)
708     (set-buffer gnus-agent-overview-buffer)
709     (goto-char (point-min))
710     (set-buffer nntp-server-buffer)
711     (erase-buffer)
712     (insert-file-contents file)
713     (goto-char (point-min))
714     (if (or (= (point-min) (point-max))
715             (progn
716               (forward-line -1)
717               (< (read (current-buffer)) (car articles))))
718         ;; We have only headers that are after the older headers,
719         ;; so we just append them.
720         (progn
721           (goto-char (point-max))
722           (insert-buffer-substring gnus-agent-overview-buffer))
723       ;; We do it the hard way.
724       (nnheader-find-nov-line (car articles))
725       (gnus-agent-copy-nov-line (car articles))
726       (pop articles)
727       (while (and articles
728                   (not (eobp)))
729         (while (and (not (eobp))
730                     (< (read (current-buffer)) (car articles)))
731           (forward-line 1))
732         (beginning-of-line)
733         (unless (eobp)
734           (gnus-agent-copy-nov-line (car articles))
735           (setq articles (cdr articles))))
736       (when articles
737         (let (b e)
738           (set-buffer gnus-agent-overview-buffer)
739           (setq b (point)
740                 e (point-max))
741           (set-buffer nntp-server-buffer)
742           (insert-buffer-substring gnus-agent-overview-buffer b e))))))
743
744 (defun gnus-agent-load-alist (group &optional dir)
745   "Load the article-state alist for GROUP."
746   (setq gnus-agent-article-alist
747         (gnus-agent-read-file
748          (if dir
749              (concat dir ".agentview")
750            (gnus-agent-article-name ".agentview" group)))))
751
752 (defun gnus-agent-save-alist (group &optional articles state dir)
753   "Load the article-state alist for GROUP."
754   (nnheader-temp-write (if dir
755                            (concat dir ".agentview")
756                          (gnus-agent-article-name ".agentview" group))
757     (princ (setq gnus-agent-article-alist
758                  (nconc gnus-agent-article-alist
759                         (mapcar (lambda (article) (cons article state))
760                                 articles)))
761            (current-buffer))
762     (insert "\n")))
763
764 (defun gnus-agent-article-name (article group)
765   (concat (gnus-agent-directory) (gnus-agent-group-path group) "/"
766           (if (stringp article) article (string-to-number article))))
767
768 ;;;###autoload
769 (defun gnus-agent-batch-fetch ()
770   "Start Gnus and fetch session."
771   (interactive)
772   (gnus)
773   (gnus-agent-fetch-session)
774   (gnus-group-exit))
775
776 (defun gnus-agent-fetch-session ()
777   "Fetch all articles and headers that are eligible for fetching."
778   (interactive)
779   (unless gnus-agent-covered-methods
780     (error "No servers are covered by the Gnus agent"))
781   (unless gnus-plugged
782     (error "Can't fetch articles while Gnus is unplugged"))
783   (let ((methods gnus-agent-covered-methods)
784         groups group gnus-command-method)
785     (save-excursion
786       (while methods
787         (setq gnus-command-method (car methods)
788               groups (gnus-groups-from-server (pop methods)))
789         (gnus-agent-with-fetch
790           (while (setq group (pop groups))
791             (gnus-agent-fetch-group-1 group gnus-command-method))))
792       (gnus-message 6 "Finished fetching articles into the Gnus agent"))))
793
794 (defun gnus-agent-fetch-group-1 (group method)
795   "Fetch GROUP."
796   (let ((gnus-command-method method)
797         gnus-newsgroup-dependencies gnus-newsgroup-headers
798         gnus-newsgroup-scored gnus-headers gnus-score
799         gnus-use-cache articles score arts
800         category predicate info marks score-param)
801     ;; Fetch headers.
802     (when (and (setq articles (gnus-list-of-unread-articles group))
803                (gnus-agent-fetch-headers group articles))
804       ;; Parse them and see which articles we want to fetch.
805       (setq gnus-newsgroup-dependencies
806             (make-vector (length articles) 0))
807       (setq gnus-newsgroup-headers
808             (gnus-get-newsgroup-headers-xover articles nil nil group))
809       (setq category (gnus-group-category group))
810       (setq predicate
811             (gnus-get-predicate 
812              (or (gnus-group-get-parameter group 'agent-predicate)
813                  (cadr category))))
814       (setq score-param
815             (or (gnus-group-get-parameter group 'agent-score)
816                 (caddr category)))
817       (when score-param
818         (gnus-score-headers (list (list score-param))))
819       (setq arts nil)
820       (while (setq gnus-headers (pop gnus-newsgroup-headers))
821         (setq gnus-score
822               (or (cdr (assq (mail-header-number gnus-headers)
823                              gnus-newsgroup-scored))
824                   gnus-summary-default-score))
825         (when (funcall predicate)
826           (push (mail-header-number gnus-headers)
827                 arts)))
828       ;; Fetch the articles.
829       (when arts
830         (gnus-agent-fetch-articles group arts)))
831     ;; Perhaps we have some additional articles to fetch.
832     (setq arts (assq 'download (gnus-info-marks
833                                 (setq info (gnus-get-info group)))))
834     (when (cdr arts)
835       (gnus-agent-fetch-articles
836        group (gnus-uncompress-range (cdr arts)))
837       (setq marks (delq arts (gnus-info-marks info)))
838       (gnus-info-set-marks info marks))))
839
840 ;;;
841 ;;; Agent Category Mode
842 ;;;
843
844 (defvar gnus-category-mode-hook nil
845   "Hook run in `gnus-category-mode' buffers.")
846
847 (defvar gnus-category-line-format "     %(%20c%): %g\n"
848   "Format of category lines.")
849
850 (defvar gnus-category-mode-line-format "Gnus: %%b"
851   "The format specification for the category mode line.")
852
853 (defvar gnus-agent-short-article 100
854   "Articles that have fewer lines than this are short.")
855
856 (defvar gnus-agent-long-article 200
857   "Articles that have more lines than this are long.")
858
859 (defvar gnus-agent-low-score 0
860   "Articles that have a score lower than this have a low score.")
861
862 (defvar gnus-agent-high-score 0
863   "Articles that have a score higher than this have a high score.")
864
865
866 ;;; Internal variables.
867
868 (defvar gnus-category-buffer "*Agent Category*")
869
870 (defvar gnus-category-line-format-alist
871   `((?c name ?s)
872     (?g groups ?d)))
873
874 (defvar gnus-category-mode-line-format-alist
875   `((?u user-defined ?s)))
876
877 (defvar gnus-category-line-format-spec nil)
878 (defvar gnus-category-mode-line-format-spec nil)
879
880 (defvar gnus-category-mode-map nil)
881 (put 'gnus-category-mode 'mode-class 'special)
882
883 (unless gnus-category-mode-map
884   (setq gnus-category-mode-map (make-sparse-keymap))
885   (suppress-keymap gnus-category-mode-map)
886
887   (gnus-define-keys gnus-category-mode-map
888     "q" gnus-category-exit
889     "k" gnus-category-kill
890     "c" gnus-category-copy
891     "a" gnus-category-add
892     "p" gnus-category-edit-predicate
893     "g" gnus-category-edit-groups
894     "s" gnus-category-edit-score
895     "l" gnus-category-list
896
897     "\C-c\C-i" gnus-info-find-node
898     "\C-c\C-b" gnus-bug))
899
900 (defvar gnus-category-menu-hook nil
901   "*Hook run after the creation of the menu.")
902
903 (defun gnus-category-make-menu-bar ()
904   (gnus-turn-off-edit-menu 'category)
905   (unless (boundp 'gnus-category-menu)
906     (easy-menu-define
907      gnus-category-menu gnus-category-mode-map ""
908      '("Categories"
909        ["Add" gnus-category-add t]
910        ["Kill" gnus-category-kill t]
911        ["Copy" gnus-category-copy t]
912        ["Edit predicate" gnus-category-edit-predicate t]
913        ["Edit score" gnus-category-edit-score t]
914        ["Edit groups" gnus-category-edit-groups t]
915        ["Exit" gnus-category-exit t]))
916
917     (run-hooks 'gnus-category-menu-hook)))
918
919 (defun gnus-category-mode ()
920   "Major mode for listing and editing agent categories.
921
922 All normal editing commands are switched off.
923 \\<gnus-category-mode-map>
924 For more in-depth information on this mode, read the manual
925 (`\\[gnus-info-find-node]').
926
927 The following commands are available:
928
929 \\{gnus-category-mode-map}"
930   (interactive)
931   (when (gnus-visual-p 'category-menu 'menu)
932     (gnus-category-make-menu-bar))
933   (kill-all-local-variables)
934   (gnus-simplify-mode-line)
935   (setq major-mode 'gnus-category-mode)
936   (setq mode-name "Category")
937   (gnus-set-default-directory)
938   (setq mode-line-process nil)
939   (use-local-map gnus-category-mode-map)
940   (buffer-disable-undo (current-buffer))
941   (setq truncate-lines t)
942   (setq buffer-read-only t)
943   (run-hooks 'gnus-category-mode-hook))
944
945 (defalias 'gnus-category-position-point 'gnus-goto-colon)
946
947 (defun gnus-category-insert-line (category)
948   (let* ((name (car category))
949          (groups (length (cadddr category))))
950     (beginning-of-line)
951     (gnus-add-text-properties
952      (point)
953      (prog1 (1+ (point))
954        ;; Insert the text.
955        (eval gnus-category-line-format-spec))
956      (list 'gnus-category name))))
957
958 (defun gnus-enter-category-buffer ()
959   "Go to the Category buffer."
960   (interactive)
961   (gnus-category-setup-buffer)
962   (gnus-configure-windows 'category)
963   (gnus-category-prepare))
964
965 (defun gnus-category-setup-buffer ()
966   (unless (get-buffer gnus-category-buffer)
967     (save-excursion
968       (set-buffer (get-buffer-create gnus-category-buffer))
969       (gnus-add-current-to-buffer-list)
970       (gnus-category-mode))))
971
972 (defun gnus-category-prepare ()
973   (gnus-set-format 'category-mode)
974   (gnus-set-format 'category t)
975   (let ((alist gnus-category-alist)
976         (buffer-read-only nil))
977     (erase-buffer)
978     (while alist
979       (gnus-category-insert-line (pop alist)))
980     (goto-char (point-min))
981     (gnus-category-position-point)))
982
983 (defun gnus-category-name ()
984   (or (get-text-property (gnus-point-at-bol) 'gnus-category)
985       (error "No category on the current line")))
986
987 (defun gnus-category-read ()
988   "Read the category alist."
989   (setq gnus-category-alist
990         (or (gnus-agent-read-file
991              (nnheader-concat gnus-agent-directory "lib/categories"))
992             (list (list 'default 'true nil nil)))))
993     
994 (defun gnus-category-write ()
995   "Write the category alist."
996   (setq gnus-category-predicate-cache nil
997         gnus-category-group-cache nil)
998   (nnheader-temp-write (nnheader-concat gnus-agent-directory "lib/categories")
999     (prin1 gnus-category-alist (current-buffer))))
1000
1001 (defun gnus-category-edit-predicate (category)
1002   "Edit the predicate for CATEGORY."
1003   (interactive (list (gnus-category-name)))
1004   (let ((info (assq category gnus-category-alist)))
1005     (gnus-edit-form
1006      (cadr info) (format "Editing the predicate for category %s" category)
1007      `(lambda (predicate)
1008         (setf (cadr (assq ',category gnus-category-alist)) predicate)
1009         (gnus-category-write)
1010         (gnus-category-list)))))
1011   
1012 (defun gnus-category-edit-score (category)
1013   "Edit the score expression for CATEGORY."
1014   (interactive (list (gnus-category-name)))
1015   (let ((info (assq category gnus-category-alist)))
1016     (gnus-edit-form
1017      (caddr info)
1018      (format "Editing the score expression for category %s" category)
1019      `(lambda (groups)
1020         (setf (caddr (assq ',category gnus-category-alist)) groups)
1021         (gnus-category-write)
1022         (gnus-category-list)))))
1023
1024 (defun gnus-category-edit-groups (category)
1025   "Edit the group list for CATEGORY."
1026   (interactive (list (gnus-category-name)))
1027   (let ((info (assq category gnus-category-alist)))
1028     (gnus-edit-form
1029      (cadddr info) (format "Editing the group list for category %s" category)
1030      `(lambda (groups)
1031         (setf (cadddr (assq ',category gnus-category-alist)) groups)
1032         (gnus-category-write)
1033         (gnus-category-list)))))
1034
1035 (defun gnus-category-kill (category)
1036   "Kill the current category."
1037   (interactive (list (gnus-category-name)))
1038   (let ((info (assq category gnus-category-alist))
1039         (buffer-read-only nil))
1040     (gnus-delete-line)
1041     (gnus-category-write)
1042     (setq gnus-category-alist (delq info gnus-category-alist))))
1043
1044 (defun gnus-category-copy (category to)
1045   "Copy the current category."
1046   (interactive (list (gnus-category-name) (intern (read-string "New name: "))))
1047   (let ((info (assq category gnus-category-alist)))
1048     (push (list to (gnus-copy-sequence (cadr info))
1049                 (gnus-copy-sequence (caddr info)) nil)
1050           gnus-category-alist)
1051     (gnus-category-write)
1052     (gnus-category-list)))
1053
1054 (defun gnus-category-add (category)
1055   "Create a new category."
1056   (interactive "SCategory name: ")
1057   (when (assq category gnus-category-alist)
1058     (error "Category %s already exists" category))
1059   (push (list category 'true nil nil)
1060         gnus-category-alist)
1061   (gnus-category-write)
1062   (gnus-category-list))
1063
1064 (defun gnus-category-list ()
1065   "List all categories."
1066   (interactive)
1067   (gnus-category-prepare))
1068
1069 (defun gnus-category-exit ()
1070   "Return to the group buffer."
1071   (interactive)
1072   (kill-buffer (current-buffer))
1073   (gnus-configure-windows 'group t))
1074
1075 ;; To avoid having 8-bit characters in the source file.
1076 (defvar gnus-category-not (list '! 'not (intern (format "%c" 172))))
1077
1078 (defvar gnus-category-predicate-alist
1079   '((spam . gnus-agent-spam-p)
1080     (short . gnus-agent-short-p)
1081     (long . gnus-agent-long-p)
1082     (low . gnus-agent-low-scored-p)
1083     (high . gnus-agent-high-scored-p)
1084     (true . gnus-agent-true)
1085     (false . gnus-agent-false))
1086   "Mapping from short score predicate symbols to predicate functions.")
1087
1088 (defun gnus-agent-spam-p ()
1089   "Say whether an article is spam or not."
1090   (unless gnus-agent-spam-hashtb
1091     (setq gnus-agent-spam-hashtb (gnus-make-hashtable 1000)))
1092   (if (not (equal (mail-header-references gnus-headers) ""))
1093       nil
1094     (let ((string (gnus-simplify-subject (mail-header-subject gnus-headers))))
1095       (prog1
1096           (gnus-gethash string gnus-agent-spam-hashtb)
1097         (gnus-sethash string t gnus-agent-spam-hashtb)))))
1098
1099 (defun gnus-agent-short-p ()
1100   "Say whether an article is short or not."
1101   (< (mail-header-lines gnus-headers) gnus-agent-short-article))
1102
1103 (defun gnus-agent-long-p ()
1104   "Say whether an article is long or not."
1105   (> (mail-header-lines gnus-headers) gnus-agent-long-article))
1106
1107 (defun gnus-agent-low-scored-p ()
1108   "Say whether an article has a low score or not."
1109   (< gnus-score gnus-agent-low-score))
1110
1111 (defun gnus-agent-high-scored-p ()
1112   "Say whether an article has a high score or not."
1113   (> gnus-score gnus-agent-low-score))
1114
1115 (defun gnus-category-make-function (cat)
1116   "Make a function from category CAT."
1117   `(lambda () ,(gnus-category-make-function-1 cat)))
1118
1119 (defun gnus-agent-true ()
1120   "Return t."
1121   t)
1122
1123 (defun gnus-agent-false ()
1124   "Return nil."
1125   nil)
1126   
1127 (defun gnus-category-make-function-1 (cat)
1128   "Make a function from category CAT."
1129   (cond
1130    ;; Functions are just returned as is.
1131    ((or (symbolp cat)
1132         (gnus-functionp cat))
1133     `(,(or (cdr (assq cat gnus-category-predicate-alist))
1134            cat)))
1135    ;; More complex category.
1136    ((consp cat)
1137     `(,(cond
1138         ((memq (car cat) '(& and))
1139          'and)
1140         ((memq (car cat) '(| or))
1141          'or)
1142         ((memq (car cat) gnus-category-not)
1143          'not))
1144       ,@(mapcar 'gnus-category-make-function-1 (cdr cat))))
1145    (t
1146     (error "Unknown category type: %s" cat))))
1147
1148 (defun gnus-get-predicate (predicate)
1149   "Return the predicate for CATEGORY."
1150   (or (cdr (assoc predicate gnus-category-predicate-cache))
1151       (cdar (push (cons predicate
1152                         (gnus-category-make-function predicate))
1153                   gnus-category-predicate-cache))))
1154
1155 (defun gnus-group-category (group)
1156   "Return the category GROUP belongs to."
1157   (unless gnus-category-group-cache
1158     (setq gnus-category-group-cache (gnus-make-hashtable 1000))
1159     (let ((cs gnus-category-alist)
1160           groups cat)
1161       (while (setq cat (pop cs))
1162         (setq groups (cadddr cat))
1163         (while groups
1164           (gnus-sethash (pop groups) cat gnus-category-group-cache)))))
1165   (or (gnus-gethash group gnus-category-group-cache)
1166       (assq 'default gnus-category-alist)))
1167
1168 (defun gnus-agent-expire ()
1169   "Expire all old articles."
1170   (interactive)
1171   (let ((methods gnus-agent-covered-methods)
1172         (alist (cdr gnus-newsrc-alist))
1173         gnus-command-method ofiles info method file group)
1174     (while (setq gnus-command-method (pop methods))
1175       (setq ofiles (nconc ofiles (gnus-agent-expire-directory
1176                                   (gnus-agent-directory)))))
1177     (while (setq info (pop alist))
1178       (when (and (gnus-agent-method-p
1179                   (setq gnus-command-method
1180                         (gnus-find-method-for-group
1181                          (setq group (gnus-info-group info)))))
1182                  (member
1183                   (setq file
1184                         (concat
1185                          (gnus-agent-directory)
1186                          (gnus-agent-group-path group) "/.overview"))
1187                   ofiles))
1188         (setq ofiles (delete file ofiles))
1189         (gnus-agent-expire-group file group)))
1190     (while ofiles
1191       (gnus-agent-expire-group (pop ofiles)))))
1192
1193 (defun gnus-agent-expire-directory (dir)
1194   "Expire all groups in DIR recursively."
1195   (when (file-directory-p dir)
1196     (let ((files (directory-files dir t))
1197           file ofiles)
1198       (while (setq file (pop files))
1199         (cond
1200          ((member (file-name-nondirectory file) '("." ".."))
1201           ;; Do nothing.
1202           )
1203          ((file-directory-p file)
1204           ;; Recurse.
1205           (setq ofiles (nconc ofiles (gnus-agent-expire-directory file))))
1206          ((string-match "\\.overview$" file)
1207           ;; Expire group.
1208           (push file ofiles))))
1209       ofiles)))
1210
1211 (defun gnus-agent-expire-group (overview &optional group)
1212   "Expire articles in OVERVIEW."
1213   (gnus-message 5 "Expiring %s..." overview)
1214   (let ((odate (- (gnus-time-to-day (current-time)) 4))
1215         (dir (file-name-directory overview))
1216         (info (when group (gnus-get-info group)))
1217         headers article file point unreads)
1218     (gnus-agent-load-alist nil dir)
1219     (when info
1220       (setq unreads
1221             (nconc
1222              (gnus-list-of-unread-articles group)
1223              (gnus-uncompress-range
1224               (cdr (assq 'tick (gnus-info-marks info))))
1225              (gnus-uncompress-range
1226               (cdr (assq 'dormant (gnus-info-marks info)))))))
1227     (nnheader-temp-write overview
1228       (insert-file-contents overview)
1229       (goto-char (point-min))
1230       (while (not (eobp))
1231         (setq point (point))
1232         (condition-case ()
1233             (setq headers (inline (nnheader-parse-nov)))
1234           (error
1235            (goto-char point)
1236            (gnus-delete-line)
1237            (setq headers nil)))
1238         (when headers
1239           (unless (memq (setq article (mail-header-number headers)) unreads)
1240             (if (not (< (inline
1241                           (gnus-time-to-day
1242                            (inline (nnmail-date-to-time
1243                                     (mail-header-date headers)))))
1244                         odate))
1245                 (forward-line 1)              
1246               (gnus-delete-line)
1247               (setq gnus-agent-article-alist
1248                     (delq (assq article gnus-agent-article-alist)
1249                           gnus-agent-article-alist))
1250               (when (file-exists-p
1251                      (setq file (concat dir (number-to-string article))))
1252                 (delete-file file))))))
1253       (gnus-agent-save-alist nil nil nil dir))))
1254
1255 (provide 'gnus-agent)
1256
1257 ;;; gnus-agent.el ends here