1 ;;; gnus-agent.el --- unplugged support for Gnus
3 ;; Copyright (C) 1997-2018 Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; This file is part of GNU Emacs.
8 ;; GNU Emacs is free software: you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; GNU Emacs is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
34 (eval-when-compile (require 'cl-lib
))
36 (autoload 'gnus-server-update-server
"gnus-srvr")
37 (autoload 'gnus-agent-customize-category
"gnus-cus")
39 (defcustom gnus-agent-directory
(nnheader-concat gnus-directory
"agent/")
40 "Where the Gnus agent will store its files."
44 (defcustom gnus-agent-plugged-hook nil
45 "Hook run when plugging into the network."
49 (defcustom gnus-agent-unplugged-hook nil
50 "Hook run when unplugging from the network."
54 (defcustom gnus-agent-fetched-hook nil
55 "Hook run when finished fetching articles."
60 (defcustom gnus-agent-handle-level gnus-level-subscribed
61 "Groups on levels higher than this variable will be ignored by the Agent."
65 (defcustom gnus-agent-expire-days
7
66 "Read articles older than this will be expired.
67 If you wish to disable Agent expiring, see `gnus-agent-enable-expiration'."
69 :type
'(number :tag
"days"))
71 (defcustom gnus-agent-expire-all nil
72 "If non-nil, also expire unread, ticked and dormant articles.
73 If nil, only read articles will be expired."
77 (defcustom gnus-agent-group-mode-hook nil
78 "Hook run in Agent group minor modes."
82 (defcustom gnus-agent-summary-mode-hook nil
83 "Hook run in Agent summary minor modes."
87 (defcustom gnus-agent-server-mode-hook nil
88 "Hook run in Agent summary minor modes."
92 (defcustom gnus-agent-confirmation-function
'y-or-n-p
93 "Function to confirm when error happens."
98 (defcustom gnus-agent-synchronize-flags nil
99 "Indicate if flags are synchronized when you plug in.
100 If this is `ask' the hook will query the user."
101 ;; If the default switches to something else than nil, then the function
102 ;; should be fixed not be exceedingly slow. See 2005-09-20 ChangeLog entry.
104 :type
'(choice (const :tag
"Always" t
)
105 (const :tag
"Never" nil
)
106 (const :tag
"Ask" ask
))
109 (defcustom gnus-agent-go-online
'ask
110 "Indicate if offline servers go online when you plug in.
111 If this is `ask' the hook will query the user."
113 :type
'(choice (const :tag
"Always" t
)
114 (const :tag
"Never" nil
)
115 (const :tag
"Ask" ask
))
118 (defcustom gnus-agent-mark-unread-after-downloaded t
119 "Indicate whether to mark articles unread after downloaded."
124 (defcustom gnus-agent-download-marks
'(download)
125 "Marks for downloading."
127 :type
'(repeat (symbol :tag
"Mark"))
130 (defcustom gnus-agent-consider-all-articles nil
131 "When non-nil, the agent will let the agent predicate decide
132 whether articles need to be downloaded or not, for all articles. When
133 nil, the default, the agent will only let the predicate decide
134 whether unread articles are downloaded or not. If you enable this,
135 groups with large active ranges may open slower and you may also want
136 to look into the agent expiry settings to block the expiration of
137 read articles as they would just be downloaded again."
142 (defcustom gnus-agent-max-fetch-size
10000000 ;; 10 Mb
143 "Chunk size for `gnus-agent-fetch-session'.
144 The function will split its article fetches into chunks smaller than
150 (defcustom gnus-agent-enable-expiration
'ENABLE
151 "The default expiration state for each group.
152 When set to ENABLE, the default, `gnus-agent-expire' will expire old
153 contents from a group's local storage. This value may be overridden
154 to disable expiration in specific categories, topics, and groups. Of
155 course, you could change gnus-agent-enable-expiration to DISABLE then
156 enable expiration per categories, topics, and groups."
159 :type
'(radio (const :format
"Enable " ENABLE
)
160 (const :format
"Disable " DISABLE
)))
162 (defcustom gnus-agent-expire-unagentized-dirs t
163 "Whether expiration should expire in unagentized directories.
164 Have gnus-agent-expire scan the directories under
165 \(gnus-agent-directory) for groups that are no longer agentized.
166 When found, offer to remove them."
171 (defcustom gnus-agent-auto-agentize-methods nil
172 "Initially, all servers from these methods are agentized.
173 The user may remove or add servers using the Server buffer.
174 See Info node `(gnus)Server Buffer' and Info node `(gnus)Agent Variables'."
176 :type
'(repeat symbol
)
179 (defcustom gnus-agent-queue-mail t
180 "Whether and when outgoing mail should be queued by the agent.
181 When `always', always queue outgoing mail. When nil, never
182 queue. Otherwise, queue if and only if unplugged."
185 :type
'(radio (const :format
"Always" always
)
186 (const :format
"Never" nil
)
187 (const :format
"When unplugged" t
)))
189 (defcustom gnus-agent-prompt-send-queue nil
190 "If non-nil, `gnus-group-send-queue' will prompt if called when unplugged."
195 (defcustom gnus-agent-article-alist-save-format
1
196 "Indicates whether to use compression(2), versus no
197 compression(1), when writing agentview files. The compressed
198 files do save space but load times are 6-7 times higher. A group
199 must be opened then closed for the agentview to be updated using
201 ;; Wouldn't symbols instead numbers be nicer? --rsteib
204 :type
'(radio (const :format
"Compressed" 2)
205 (const :format
"Uncompressed" 1)))
207 ;;; Internal variables
209 (defvar gnus-agent-history-buffers nil
)
210 (defvar gnus-agent-buffer-alist nil
)
211 (defvar gnus-agent-article-alist nil
212 "An assoc list identifying the articles whose headers have been fetched.
213 If successfully fetched, these headers will be stored in the group's overview
214 file. The key of each assoc pair is the article ID, the value of each assoc
215 pair is a flag indicating whether the identified article has been downloaded
216 \(gnus-agent-fetch-articles sets the value to the day of the download).
218 1) The last element of this list can not be expired as some
219 routines (for example, get-agent-fetch-headers) use the last
220 value to track which articles have had their headers retrieved.
221 2) The function `gnus-agent-regenerate' may destructively modify the value.")
222 (defvar gnus-agent-group-alist nil
)
223 (defvar gnus-category-alist nil
)
224 (defvar gnus-agent-current-history nil
)
225 (defvar gnus-agent-overview-buffer nil
)
226 (defvar gnus-category-predicate-cache nil
)
227 (defvar gnus-category-group-cache nil
)
228 (defvar gnus-agent-spam-hashtb nil
)
229 (defvar gnus-agent-file-name nil
)
230 (defvar gnus-agent-file-coding-system
'raw-text
)
231 (defvar gnus-agent-file-loading-cache nil
)
232 (defvar gnus-agent-total-fetched-hashtb nil
)
233 (defvar gnus-agent-inhibit-update-total-fetched-for nil
)
234 (defvar gnus-agent-need-update-total-fetched-for nil
)
237 (defvar gnus-headers
)
244 (defun gnus-open-agent ()
246 (gnus-agent-read-servers)
248 (gnus-agent-create-buffer)
249 (add-hook 'gnus-group-mode-hook
'gnus-agent-mode
)
250 (add-hook 'gnus-summary-mode-hook
'gnus-agent-mode
)
251 (add-hook 'gnus-server-mode-hook
'gnus-agent-mode
))
253 (defun gnus-agent-create-buffer ()
254 (if (gnus-buffer-live-p gnus-agent-overview-buffer
)
256 (setq gnus-agent-overview-buffer
257 (gnus-get-buffer-create " *Gnus agent overview*"))
258 (with-current-buffer gnus-agent-overview-buffer
259 (mm-enable-multibyte))
262 (gnus-add-shutdown 'gnus-close-agent
'gnus
)
264 (defun gnus-close-agent ()
265 (setq gnus-category-predicate-cache nil
266 gnus-category-group-cache nil
267 gnus-agent-spam-hashtb nil
)
268 (gnus-kill-buffer gnus-agent-overview-buffer
))
271 ;;; Utility functions
274 (defmacro gnus-agent-with-refreshed-group
(group &rest body
)
275 "Performs the body then updates the group's line in the group
276 buffer. Automatically blocks multiple updates due to recursion."
277 `(prog1 (let ((gnus-agent-inhibit-update-total-fetched-for t
)) ,@body
)
278 (when (and gnus-agent-need-update-total-fetched-for
279 (not gnus-agent-inhibit-update-total-fetched-for
))
280 (with-current-buffer gnus-group-buffer
281 (setq gnus-agent-need-update-total-fetched-for nil
)
282 (gnus-group-update-group ,group t
)))))
284 (defun gnus-agent-read-file (file)
285 "Load FILE and do a `read' there."
288 (nnheader-insert-file-contents file
)
289 (goto-char (point-min))
290 (read (current-buffer)))))
292 (defsubst gnus-agent-method
()
293 (concat (symbol-name (car gnus-command-method
)) "/"
294 (if (equal (cadr gnus-command-method
) "")
296 (cadr gnus-command-method
))))
298 (defsubst gnus-agent-directory
()
299 "The name of the Gnus agent directory."
300 (nnheader-concat gnus-agent-directory
301 (nnheader-translate-file-chars (gnus-agent-method)) "/"))
303 (defun gnus-agent-lib-file (file)
304 "The full name of the Gnus agent library FILE."
305 (expand-file-name file
306 (file-name-as-directory
307 (expand-file-name "agent.lib" (gnus-agent-directory)))))
309 (defun gnus-agent-cat-set-property (category property value
)
311 (setcdr (or (assq property category
)
312 (let ((cell (cons property nil
)))
313 (setcdr category
(cons cell
(cdr category
)))
315 (let ((category category
))
316 (while (cond ((eq property
(caadr category
))
317 (setcdr category
(cddr category
))
320 (setq category
(cdr category
)))))))
324 (defmacro gnus-agent-cat-defaccessor
(name prop-name
)
325 "Define accessor and setter methods for manipulating a list of the form
326 \(NAME (PROPERTY1 VALUE1) ... (PROPERTY_N VALUE_N)).
327 Given the call (gnus-agent-cat-defaccessor func PROPERTY1), the list may be
328 manipulated as follows:
329 (func LIST): Returns VALUE1
330 (setf (func LIST) NEW_VALUE1): Replaces VALUE1 with NEW_VALUE1."
331 `(progn (defmacro ,name
(category)
332 (list 'cdr
(list 'assq
'',prop-name category
)))
334 (gv-define-setter ,name
(value category
)
335 (list 'gnus-agent-cat-set-property
336 category
'',prop-name value
))))
339 (defmacro gnus-agent-cat-name
(category)
342 (gnus-agent-cat-defaccessor
343 gnus-agent-cat-days-until-old agent-days-until-old
)
344 (gnus-agent-cat-defaccessor
345 gnus-agent-cat-enable-expiration agent-enable-expiration
)
346 (gnus-agent-cat-defaccessor
347 gnus-agent-cat-groups agent-groups
)
348 (gnus-agent-cat-defaccessor
349 gnus-agent-cat-high-score agent-high-score
)
350 (gnus-agent-cat-defaccessor
351 gnus-agent-cat-length-when-long agent-long-article
)
352 (gnus-agent-cat-defaccessor
353 gnus-agent-cat-length-when-short agent-short-article
)
354 (gnus-agent-cat-defaccessor
355 gnus-agent-cat-low-score agent-low-score
)
356 (gnus-agent-cat-defaccessor
357 gnus-agent-cat-predicate agent-predicate
)
358 (gnus-agent-cat-defaccessor
359 gnus-agent-cat-score-file agent-score
)
360 (gnus-agent-cat-defaccessor
361 gnus-agent-cat-enable-undownloaded-faces agent-enable-undownloaded-faces
)
363 (gv-define-simple-setter gnus-agent-cat-groups gnus-agent-set-cat-groups
)
365 (defun gnus-agent-set-cat-groups (category groups
)
366 (unless (eq groups
'ignore
)
368 (old-g (gnus-agent-cat-groups category
)))
369 (cond ((eq new-g old-g
)
370 ;; gnus-agent-add-group is fiddling with the group
371 ;; list. Still, Im done.
374 ((eq new-g
(cdr old-g
))
375 ;; gnus-agent-add-group is fiddling with the group list
376 (setcdr (or (assq 'agent-groups category
)
377 (let ((cell (cons 'agent-groups nil
)))
378 (setcdr category
(cons cell
(cdr category
)))
381 (let ((groups groups
))
383 (let* ((group (pop groups
))
384 (old-category (gnus-group-category group
)))
385 (if (eq category old-category
)
387 (setf (gnus-agent-cat-groups old-category
)
388 (delete group
(gnus-agent-cat-groups
390 ;; Purge cache as preceding loop invalidated it.
391 (setq gnus-category-group-cache nil
))
393 (setcdr (or (assq 'agent-groups category
)
394 (let ((cell (cons 'agent-groups nil
)))
395 (setcdr category
(cons cell
(cdr category
)))
398 (defsubst gnus-agent-cat-make
(name &optional default-agent-predicate
)
399 (list name
`(agent-predicate .
,(or default-agent-predicate
'false
))))
401 (defun gnus-agent-read-group ()
402 "Read a group name in the minibuffer, with completion."
403 (let ((def (or (gnus-group-group-name) gnus-newsgroup-name
)))
405 (setq def
(gnus-group-decoded-name def
)))
406 (gnus-group-completing-read nil nil t nil nil def
)))
408 ;;; Fetching setup functions.
410 (defun gnus-agent-start-fetch ()
411 "Initialize data structures for efficient fetching."
412 (gnus-agent-create-buffer))
414 (defun gnus-agent-stop-fetch ()
415 "Save all data structures and clean up."
416 (setq gnus-agent-spam-hashtb nil
)
417 (with-current-buffer nntp-server-buffer
420 (defmacro gnus-agent-with-fetch
(&rest forms
)
423 (let ((gnus-agent-fetching t
))
424 (gnus-agent-start-fetch)
426 (gnus-agent-stop-fetch)))
428 (put 'gnus-agent-with-fetch
'lisp-indent-function
0)
429 (put 'gnus-agent-with-fetch
'edebug-form-spec
'(body))
431 (defmacro gnus-agent-append-to-list
(tail value
)
432 `(setq ,tail
(setcdr ,tail
(cons ,value nil
))))
434 (defmacro gnus-agent-message
(level &rest args
)
435 `(if (<= ,level gnus-verbose
)
442 (defvar gnus-agent-mode-hook nil
443 "Hook run when installing agent mode.")
445 (defvar gnus-agent-mode nil
)
446 (defvar gnus-agent-mode-status
'(gnus-agent-mode " Plugged"))
448 (defun gnus-agent-mode ()
449 "Minor mode for providing agent support in Gnus buffers."
450 (let* ((buffer (progn (string-match "^gnus-\\(.*\\)-mode$"
451 (symbol-name major-mode
))
452 (match-string 1 (symbol-name major-mode
))))
453 (mode (intern (format "gnus-agent-%s-mode" buffer
))))
454 (set (make-local-variable 'gnus-agent-mode
) t
)
456 (set (make-local-variable mode
) t
)
458 (when (gnus-visual-p 'agent-menu
'menu
)
459 (funcall (intern (format "gnus-agent-%s-make-menu-bar" buffer
))))
460 (unless (assq mode minor-mode-alist
)
461 (push (cons mode
(cdr gnus-agent-mode-status
)) minor-mode-alist
))
462 (unless (assq mode minor-mode-map-alist
)
463 (push (cons mode
(symbol-value (intern (format "gnus-agent-%s-mode-map"
465 minor-mode-map-alist
))
466 (when (derived-mode-p 'gnus-group-mode
)
467 (let ((init-plugged gnus-plugged
)
468 (gnus-agent-go-online nil
))
469 ;; g-a-t-p does nothing when gnus-plugged isn't changed.
470 ;; Therefore, make certain that the current value does not
471 ;; match the desired initial value.
472 (setq gnus-plugged
:unknown
)
473 (gnus-agent-toggle-plugged init-plugged
)))
474 (gnus-run-hooks 'gnus-agent-mode-hook
475 (intern (format "gnus-agent-%s-mode-hook" buffer
)))))
477 (defvar gnus-agent-group-mode-map
(make-sparse-keymap))
478 (gnus-define-keys gnus-agent-group-mode-map
479 "Ju" gnus-agent-fetch-groups
480 "Jc" gnus-enter-category-buffer
481 "Jj" gnus-agent-toggle-plugged
482 "Js" gnus-agent-fetch-session
483 "JY" gnus-agent-synchronize-flags
484 "JS" gnus-group-send-queue
485 "Ja" gnus-agent-add-group
486 "Jr" gnus-agent-remove-group
487 "Jo" gnus-agent-toggle-group-plugged
)
489 (defun gnus-agent-group-make-menu-bar ()
490 (unless (boundp 'gnus-agent-group-menu
)
492 gnus-agent-group-menu gnus-agent-group-mode-map
""
494 ["Toggle plugged" gnus-agent-toggle-plugged t
]
495 ["Toggle group plugged" gnus-agent-toggle-group-plugged t
]
496 ["List categories" gnus-enter-category-buffer t
]
497 ["Add (current) group to category" gnus-agent-add-group t
]
498 ["Remove (current) group from category" gnus-agent-remove-group t
]
499 ["Send queue" gnus-group-send-queue gnus-plugged
]
501 ["All" gnus-agent-fetch-session gnus-plugged
]
502 ["Group" gnus-agent-fetch-group gnus-plugged
])
503 ["Synchronize flags" gnus-agent-synchronize-flags t
]
506 (defvar gnus-agent-summary-mode-map
(make-sparse-keymap))
507 (gnus-define-keys gnus-agent-summary-mode-map
508 "Jj" gnus-agent-toggle-plugged
509 "Ju" gnus-agent-summary-fetch-group
510 "JS" gnus-agent-fetch-group
511 "Js" gnus-agent-summary-fetch-series
512 "J#" gnus-agent-mark-article
513 "J\M-#" gnus-agent-unmark-article
514 "@" gnus-agent-toggle-mark
515 "Jc" gnus-agent-catchup
)
517 (defun gnus-agent-summary-make-menu-bar ()
518 (unless (boundp 'gnus-agent-summary-menu
)
520 gnus-agent-summary-menu gnus-agent-summary-mode-map
""
522 ["Toggle plugged" gnus-agent-toggle-plugged t
]
523 ["Mark as downloadable" gnus-agent-mark-article t
]
524 ["Unmark as downloadable" gnus-agent-unmark-article t
]
525 ["Toggle mark" gnus-agent-toggle-mark t
]
526 ["Fetch downloadable" gnus-agent-summary-fetch-group t
]
527 ["Catchup undownloaded" gnus-agent-catchup t
]))))
529 (defvar gnus-agent-server-mode-map
(make-sparse-keymap))
530 (gnus-define-keys gnus-agent-server-mode-map
531 "Jj" gnus-agent-toggle-plugged
532 "Ja" gnus-agent-add-server
533 "Jr" gnus-agent-remove-server
)
535 (defun gnus-agent-server-make-menu-bar ()
536 (unless (boundp 'gnus-agent-server-menu
)
538 gnus-agent-server-menu gnus-agent-server-mode-map
""
540 ["Toggle plugged" gnus-agent-toggle-plugged t
]
541 ["Add" gnus-agent-add-server t
]
542 ["Remove" gnus-agent-remove-server t
]))))
544 (defun gnus-agent-make-mode-line-string (string mouse-button mouse-func
)
545 (propertize string
'local-map
546 (make-mode-line-mouse-map mouse-button mouse-func
)
547 'mouse-face
'mode-line-highlight
))
549 (defun gnus-agent-toggle-plugged (set-to)
550 "Toggle whether Gnus is unplugged or not."
551 (interactive (list (not gnus-plugged
)))
552 (cond ((eq set-to gnus-plugged
)
555 (setq gnus-plugged set-to
)
556 (gnus-run-hooks 'gnus-agent-plugged-hook
)
557 (setcar (cdr gnus-agent-mode-status
)
558 (gnus-agent-make-mode-line-string " Plugged"
560 'gnus-agent-toggle-plugged
))
561 (gnus-agent-go-online gnus-agent-go-online
))
563 (gnus-agent-close-connections)
564 (setq gnus-plugged set-to
)
565 (gnus-run-hooks 'gnus-agent-unplugged-hook
)
566 (setcar (cdr gnus-agent-mode-status
)
567 (gnus-agent-make-mode-line-string " Unplugged"
569 'gnus-agent-toggle-plugged
))))
570 (set-buffer-modified-p t
))
572 (defmacro gnus-agent-while-plugged
(&rest body
)
573 `(let ((original-gnus-plugged gnus-plugged
))
575 (progn (gnus-agent-toggle-plugged t
)
577 (gnus-agent-toggle-plugged original-gnus-plugged
))))
579 (put 'gnus-agent-while-plugged
'lisp-indent-function
0)
580 (put 'gnus-agent-while-plugged
'edebug-form-spec
'(body))
582 (defun gnus-agent-close-connections ()
583 "Close all methods covered by the Gnus agent."
584 (let ((methods (gnus-agent-covered-methods)))
586 (gnus-close-server (pop methods
)))))
589 (defun gnus-unplugged ()
590 "Start Gnus unplugged."
592 (setq gnus-plugged nil
)
596 (defun gnus-plugged ()
597 "Start Gnus plugged."
599 (setq gnus-plugged t
)
603 (defun gnus-slave-unplugged (&optional arg
)
604 "Read news as a slave unplugged."
606 (setq gnus-plugged nil
)
607 (gnus arg nil
'slave
))
610 (defun gnus-agentize ()
611 "Allow Gnus to be an offline newsreader.
613 The gnus-agentize function is now called internally by gnus when
614 gnus-agent is set. If you wish to avoid calling gnus-agentize,
615 customize gnus-agent to nil.
617 This will modify the `gnus-setup-news-hook', and
618 `message-send-mail-real-function' variables, and install the Gnus agent
619 minor mode in all Gnus buffers."
622 (setq message-send-mail-real-function
'gnus-agent-send-mail
)
624 ;; If the servers file doesn't exist, auto-agentize some servers and
625 ;; save the servers file so this auto-agentizing isn't invoked
627 (when (and (not (file-exists-p (nnheader-concat
628 gnus-agent-directory
"lib/servers")))
629 gnus-agent-auto-agentize-methods
)
630 (gnus-message 3 "First time agent user, agentizing remote groups...")
632 (lambda (server-or-method)
633 (let ((method (gnus-server-to-method server-or-method
)))
634 (when (memq (car method
)
635 gnus-agent-auto-agentize-methods
)
636 (push (gnus-method-to-server method
)
637 gnus-agent-covered-methods
)
638 (setq gnus-agent-method-p-cache nil
))))
639 (cons gnus-select-method gnus-secondary-select-methods
))
640 (gnus-agent-write-servers)))
642 (defun gnus-agent-queue-setup (&optional group-name
)
643 "Make sure the queue group exists.
644 Optional arg GROUP-NAME allows another group to be specified."
645 (unless (gnus-gethash (format "nndraft:%s" (or group-name
"queue"))
647 (gnus-request-create-group (or group-name
"queue") '(nndraft ""))
648 (let ((gnus-level-default-subscribed 1))
649 (gnus-subscribe-group (format "nndraft:%s" (or group-name
"queue"))
651 (gnus-group-set-parameter
652 (format "nndraft:%s" (or group-name
"queue"))
653 'gnus-dummy
'((gnus-draft-mode)))))
655 (defun gnus-agent-send-mail ()
656 (if (or (not gnus-agent-queue-mail
)
657 (and gnus-plugged
(not (eq gnus-agent-queue-mail
'always
))))
658 (message-multi-smtp-send-mail)
659 (goto-char (point-min))
661 (concat "^" (regexp-quote mail-header-separator
) "\n"))
663 (gnus-agent-insert-meta-information 'mail
)
664 (gnus-request-accept-article "nndraft:queue" nil t t
)
665 (gnus-group-refresh-group "nndraft:queue")))
667 (defun gnus-agent-insert-meta-information (type &optional method
)
668 "Insert meta-information into the message that says how it's to be posted.
669 TYPE can be either `mail' or `news'. If the latter, then METHOD can
672 (message-remove-header gnus-agent-meta-information-header
)
673 (goto-char (point-min))
674 (insert gnus-agent-meta-information-header
": "
675 (symbol-name type
) " " (format "%S" method
)
678 (while (search-backward "\n" nil t
)
679 (replace-match "\\n" t t
))))
681 (defun gnus-agent-restore-gcc ()
682 "Restore GCC field from saved header."
684 (goto-char (point-min))
685 (while (re-search-forward
686 (concat "^" (regexp-quote gnus-agent-gcc-header
) ":") nil t
)
687 (replace-match "Gcc:" 'fixedcase
))))
689 (defun gnus-agent-any-covered-gcc ()
691 (message-narrow-to-headers)
692 (let* ((gcc (mail-fetch-field "gcc" nil t
))
694 (mapcar 'gnus-inews-group-method
695 (message-unquote-tokens
696 (message-tokenize-header
699 (while (and (not covered
) methods
)
700 (setq covered
(gnus-agent-method-p (car methods
))
701 methods
(cdr methods
)))
705 (defun gnus-agent-possibly-save-gcc ()
706 "Save GCC if Gnus is unplugged."
707 (when (and (not gnus-plugged
) (gnus-agent-any-covered-gcc))
709 (goto-char (point-min))
710 (let ((case-fold-search t
))
711 (while (re-search-forward "^gcc:" nil t
)
712 (replace-match (concat gnus-agent-gcc-header
":") 'fixedcase
))))))
714 (defun gnus-agent-possibly-do-gcc ()
715 "Do GCC if Gnus is plugged."
716 (when (or gnus-plugged
(not (gnus-agent-any-covered-gcc)))
717 (gnus-inews-do-gcc)))
720 ;;; Group mode commands
723 (defun gnus-agent-fetch-groups (n)
724 "Put all new articles in the current groups into the Agent."
727 (error "Groups can't be fetched when Gnus is unplugged"))
728 (gnus-group-iterate n
'gnus-agent-fetch-group
))
730 (defun gnus-agent-fetch-group (&optional group
)
731 "Put all new articles in GROUP into the Agent."
732 (interactive (list (gnus-group-group-name)))
733 (setq group
(or group gnus-newsgroup-name
))
735 (error "No group on the current line"))
736 (if (not (gnus-agent-group-covered-p group
))
737 (message "%s isn't covered by the agent" group
)
738 (gnus-agent-while-plugged
739 (let ((gnus-command-method (gnus-find-method-for-group group
)))
740 (gnus-agent-with-fetch
741 (gnus-agent-fetch-group-1 group gnus-command-method
)
742 (gnus-message 5 "Fetching %s...done" group
))))))
744 (defun gnus-agent-add-group (category arg
)
745 "Add the current group to an agent category."
749 (gnus-completing-read
751 (mapcar (lambda (cat) (symbol-name (car cat
)))
755 (let ((cat (assq category gnus-category-alist
))
757 (gnus-group-iterate arg
759 (when (gnus-agent-cat-groups (setq c
(gnus-group-category group
)))
760 (setf (gnus-agent-cat-groups c
)
761 (delete group
(gnus-agent-cat-groups c
))))
762 (push group groups
)))
763 (setf (gnus-agent-cat-groups cat
)
764 (nconc (gnus-agent-cat-groups cat
) groups
))
765 (gnus-category-write)))
767 (defun gnus-agent-remove-group (arg)
768 "Remove the current group from its agent category, if any."
771 (gnus-group-iterate arg
773 (when (gnus-agent-cat-groups (setq c
(gnus-group-category group
)))
774 (setf (gnus-agent-cat-groups c
)
775 (delete group
(gnus-agent-cat-groups c
))))))
776 (gnus-category-write)))
778 (defun gnus-agent-synchronize-flags ()
779 "Synchronize unplugged flags with servers."
782 (dolist (gnus-command-method (gnus-agent-covered-methods))
783 (when (file-exists-p (gnus-agent-lib-file "flags"))
784 (gnus-agent-synchronize-flags-server gnus-command-method
)))))
786 (defun gnus-agent-possibly-synchronize-flags ()
787 "Synchronize flags according to `gnus-agent-synchronize-flags'."
790 (dolist (gnus-command-method (gnus-agent-covered-methods))
791 (when (eq (gnus-server-status gnus-command-method
) 'ok
)
792 (gnus-agent-possibly-synchronize-flags-server gnus-command-method
)))))
794 (defun gnus-agent-synchronize-flags-server (method)
795 "Synchronize flags set when unplugged for server."
796 (let ((gnus-command-method method
)
798 (when (file-exists-p (gnus-agent-lib-file "flags"))
799 (set-buffer (get-buffer-create " *Gnus Agent flag synchronize*"))
801 (nnheader-insert-file-contents (gnus-agent-lib-file "flags"))
802 (cond ((null gnus-plugged
)
804 1 "You must be plugged to synchronize flags with server %s"
805 (nth 1 gnus-command-method
)))
806 ((null (gnus-check-server gnus-command-method
))
808 1 "Couldn't open server %s" (nth 1 gnus-command-method
)))
813 (eval (read (current-buffer)))
814 (delete-region bgn
(point))))
816 (delete-file (gnus-agent-lib-file "flags")))
818 (let ((file (gnus-agent-lib-file "flags")))
819 (write-region (point-min) (point-max)
820 (gnus-agent-lib-file "flags") nil
'silent
)
821 (error "Couldn't set flags from file %s due to %s"
822 file
(error-message-string err
)))))))
825 (defun gnus-agent-possibly-synchronize-flags-server (method)
826 "Synchronize flags for server according to `gnus-agent-synchronize-flags'."
827 (when (and (file-exists-p (gnus-agent-lib-file "flags"))
828 (or (and gnus-agent-synchronize-flags
829 (not (eq gnus-agent-synchronize-flags
'ask
)))
830 (and (eq gnus-agent-synchronize-flags
'ask
)
833 "Synchronize flags on server `%s'? "
835 (gnus-agent-synchronize-flags-server method
)))
838 (defun gnus-agent-rename-group (old-group new-group
)
839 "Rename fully-qualified OLD-GROUP as NEW-GROUP.
840 Always updates the agent, even when disabled, as the old agent
841 files would corrupt gnus when the agent was next enabled.
842 Depends upon the caller to determine whether group renaming is
844 (let* ((old-command-method (gnus-find-method-for-group old-group
))
845 (old-path (directory-file-name
846 (let ((gnus-command-method old-command-method
))
847 (gnus-agent-group-pathname old-group
))))
848 (new-command-method (gnus-find-method-for-group new-group
))
849 (new-path (directory-file-name
850 (let ((gnus-command-method new-command-method
))
851 (gnus-agent-group-pathname new-group
))))
852 (file-name-coding-system nnmail-pathname-coding-system
))
853 (gnus-rename-file old-path new-path t
)
855 (let* ((old-real-group (gnus-group-real-name old-group
))
856 (new-real-group (gnus-group-real-name new-group
))
857 (old-active (gnus-agent-get-group-info old-command-method old-real-group
)))
858 (gnus-agent-save-group-info old-command-method old-real-group nil
)
859 (gnus-agent-save-group-info new-command-method new-real-group old-active
)
861 (let ((old-local (gnus-agent-get-local old-group
862 old-real-group old-command-method
)))
863 (gnus-agent-set-local old-group
865 old-real-group old-command-method
)
866 (gnus-agent-set-local new-group
867 (car old-local
) (cdr old-local
)
868 new-real-group new-command-method
)))))
871 (defun gnus-agent-delete-group (group)
872 "Delete fully-qualified GROUP.
873 Always updates the agent, even when disabled, as the old agent
874 files would corrupt gnus when the agent was next enabled.
875 Depends upon the caller to determine whether group deletion is
877 (let* ((command-method (gnus-find-method-for-group group
))
878 (path (directory-file-name
879 (let ((gnus-command-method command-method
))
880 (gnus-agent-group-pathname group
))))
881 (file-name-coding-system nnmail-pathname-coding-system
))
882 (gnus-delete-directory path
)
884 (let* ((real-group (gnus-group-real-name group
)))
885 (gnus-agent-save-group-info command-method real-group nil
)
886 ;; FIXME: Does gnus-agent-get-local have any useful side-effect?
887 (gnus-agent-get-local group real-group command-method
)
888 (gnus-agent-set-local group
890 real-group command-method
))))
893 ;;; Server mode commands
896 (defun gnus-agent-add-server ()
897 "Enroll SERVER in the agent program."
899 (let* ((server (gnus-server-server-name))
900 (named-server (gnus-server-named-server))
902 (gnus-server-get-method nil server
))))
904 (error "No server on the current line"))
906 (when (gnus-agent-method-p method
)
907 (error "Server already in the agent program"))
909 (push named-server gnus-agent-covered-methods
)
911 (setq gnus-agent-method-p-cache nil
)
912 (gnus-server-update-server server
)
913 (gnus-agent-write-servers)
914 (gnus-message 1 "Entered %s into the Agent" server
)))
916 (defun gnus-agent-remove-server ()
917 "Remove SERVER from the agent program."
919 (let* ((server (gnus-server-server-name))
920 (named-server (gnus-server-named-server)))
922 (error "No server on the current line"))
924 (unless (member named-server gnus-agent-covered-methods
)
925 (error "Server not in the agent program"))
927 (setq gnus-agent-covered-methods
928 (delete named-server gnus-agent-covered-methods
)
929 gnus-agent-method-p-cache nil
)
931 (gnus-server-update-server server
)
932 (gnus-agent-write-servers)
933 (gnus-message 1 "Removed %s from the agent" server
)))
935 (defun gnus-agent-read-servers ()
936 "Read the alist of covered servers."
937 (setq gnus-agent-covered-methods
938 (gnus-agent-read-file
939 (nnheader-concat gnus-agent-directory
"lib/servers"))
940 gnus-agent-method-p-cache nil
)
942 ;; I am called so early in start-up that I can not validate server
943 ;; names. When that is the case, I skip the validation. That is
944 ;; alright as the gnus startup code calls the validate methods
946 (if gnus-server-alist
947 (gnus-agent-read-servers-validate)))
949 (defun gnus-agent-read-servers-validate ()
950 (mapcar (lambda (server-or-method)
951 (let* ((server (if (stringp server-or-method
)
953 (gnus-method-to-server server-or-method
)))
954 (method (gnus-server-to-method server
)))
956 (unless (member server gnus-agent-covered-methods
)
957 (push server gnus-agent-covered-methods
)
958 (setq gnus-agent-method-p-cache nil
))
959 (gnus-message 8 "Ignoring disappeared server `%s'" server
))))
960 (prog1 gnus-agent-covered-methods
961 (setq gnus-agent-covered-methods nil
))))
963 (defun gnus-agent-read-servers-validate-native (native-method)
964 (setq gnus-agent-covered-methods
965 (mapcar (lambda (method)
967 (equal method native-method
))
969 method
)) gnus-agent-covered-methods
)))
971 (defun gnus-agent-write-servers ()
972 "Write the alist of covered servers."
973 (gnus-make-directory (nnheader-concat gnus-agent-directory
"lib"))
974 (let ((coding-system-for-write nnheader-file-coding-system
)
975 (file-name-coding-system nnmail-pathname-coding-system
))
976 (with-temp-file (nnheader-concat gnus-agent-directory
"lib/servers")
977 (prin1 gnus-agent-covered-methods
984 (defun gnus-agent-mark-article (n &optional unmark
)
985 "Mark the next N articles as downloadable.
986 If N is negative, mark backward instead. If UNMARK is non-nil, remove
987 the mark instead. The difference between N and the actual number of
988 articles marked is returned."
990 (let ((backward (< n
0))
995 (gnus-summary-set-agent-mark
996 (gnus-summary-article-number) unmark
)
997 (zerop (gnus-summary-next-subject (if backward -
1 1) nil t
))))
1000 (gnus-message 7 "No more articles"))
1001 (gnus-summary-recenter)
1002 (gnus-summary-position-point)
1005 (defun gnus-agent-unmark-article (n)
1006 "Remove the downloadable mark from the next N articles.
1007 If N is negative, unmark backward instead. The difference between N and
1008 the actual number of articles unmarked is returned."
1010 (gnus-agent-mark-article n t
))
1012 (defun gnus-agent-toggle-mark (n)
1013 "Toggle the downloadable mark from the next N articles.
1014 If N is negative, toggle backward instead. The difference between N and
1015 the actual number of articles toggled is returned."
1017 (gnus-agent-mark-article n
'toggle
))
1019 (defun gnus-summary-set-agent-mark (article &optional unmark
)
1020 "Mark ARTICLE as downloadable. If UNMARK is nil, article is marked.
1021 When UNMARK is t, the article is unmarked. For any other value, the
1022 article's mark is toggled."
1023 (let ((unmark (cond ((eq nil unmark
)
1028 (memq article gnus-newsgroup-downloadable
)))))
1029 (when (gnus-summary-goto-subject article nil t
)
1030 (gnus-summary-update-mark
1033 (setq gnus-newsgroup-downloadable
1034 (delq article gnus-newsgroup-downloadable
))
1035 (gnus-article-mark article
))
1036 (setq gnus-newsgroup-downloadable
1037 (gnus-add-to-sorted-list gnus-newsgroup-downloadable article
))
1038 gnus-downloadable-mark
)
1042 (defun gnus-agent-get-undownloaded-list ()
1043 "Construct list of articles that have not been downloaded."
1044 (let ((gnus-command-method (gnus-find-method-for-group gnus-newsgroup-name
)))
1045 (when (set (make-local-variable 'gnus-newsgroup-agentized
)
1046 (gnus-agent-method-p gnus-command-method
))
1047 (let* ((alist (gnus-agent-load-alist gnus-newsgroup-name
))
1048 (headers (sort (mapcar (lambda (h)
1049 (mail-header-number h
))
1050 gnus-newsgroup-headers
) '<))
1051 (cached (and gnus-use-cache gnus-newsgroup-cached
))
1052 (undownloaded (list nil
))
1053 (tail-undownloaded undownloaded
)
1054 (unfetched (list nil
))
1055 (tail-unfetched unfetched
))
1056 (while (and alist headers
)
1057 (let ((a (caar alist
))
1060 ;; Ignore IDs in the alist that are not being
1061 ;; displayed in the summary.
1062 (setq alist
(cdr alist
)))
1064 ;; Headers that are not in the alist should be
1065 ;; fictitious (see nnagent-retrieve-headers); they
1066 ;; imply that this article isn't in the agent.
1067 (gnus-agent-append-to-list tail-undownloaded h
)
1068 (gnus-agent-append-to-list tail-unfetched h
)
1069 (setq headers
(cdr headers
)))
1071 (setq alist
(cdr alist
))
1072 (setq headers
(cdr headers
))
1073 nil
; ignore already downloaded
1076 (setq alist
(cdr alist
))
1077 (setq headers
(cdr headers
))
1079 ;; This article isn't in the agent. Check to see
1080 ;; if it is in the cache. If it is, it's been
1082 (while (and cached
(< (car cached
) a
))
1083 (setq cached
(cdr cached
)))
1084 (unless (equal a
(car cached
))
1085 (gnus-agent-append-to-list tail-undownloaded a
))))))
1088 (let ((num (pop headers
)))
1089 (gnus-agent-append-to-list tail-undownloaded num
)
1090 (gnus-agent-append-to-list tail-unfetched num
)))
1092 (setq gnus-newsgroup-undownloaded
(cdr undownloaded
)
1093 gnus-newsgroup-unfetched
(cdr unfetched
))))))
1095 (defun gnus-agent-catchup ()
1096 "Mark as read all unhandled articles.
1097 An article is unhandled if it is neither cached, nor downloaded, nor
1101 (let ((articles gnus-newsgroup-undownloaded
))
1102 (when (or gnus-newsgroup-downloadable
1103 gnus-newsgroup-cached
)
1104 (setq articles
(gnus-sorted-ndifference
1105 (gnus-sorted-ndifference
1106 (copy-tree articles
)
1107 gnus-newsgroup-downloadable
)
1108 gnus-newsgroup-cached
)))
1111 (gnus-summary-mark-article
1112 (pop articles
) gnus-catchup-mark
)))
1113 (gnus-summary-position-point)))
1115 (defun gnus-agent-summary-fetch-series ()
1116 "Fetch the process-marked articles into the Agent."
1118 (when gnus-newsgroup-processable
1119 (setq gnus-newsgroup-downloadable
1120 (let* ((dl gnus-newsgroup-downloadable
)
1121 (processable (sort (copy-tree gnus-newsgroup-processable
) '<))
1122 (gnus-newsgroup-downloadable processable
))
1123 (gnus-agent-summary-fetch-group)
1125 ;; For each article that I processed that is no longer
1126 ;; undownloaded, remove its processable mark.
1128 (mapc #'gnus-summary-remove-process-mark
1129 (gnus-sorted-ndifference gnus-newsgroup-processable gnus-newsgroup-undownloaded
))
1131 ;; The preceding call to (gnus-agent-summary-fetch-group)
1132 ;; updated the temporary gnus-newsgroup-downloadable to
1133 ;; remove each article successfully fetched. Now, I
1134 ;; update the real gnus-newsgroup-downloadable to only
1135 ;; include undownloaded articles.
1136 (gnus-sorted-ndifference dl
(gnus-sorted-ndifference processable gnus-newsgroup-undownloaded
))))))
1138 (defun gnus-agent-summary-fetch-group (&optional all
)
1139 "Fetch the downloadable articles in the group.
1140 Optional arg ALL, if non-nil, means to fetch all articles."
1143 (if all gnus-newsgroup-articles
1144 gnus-newsgroup-downloadable
))
1145 (gnus-command-method (gnus-find-method-for-group gnus-newsgroup-name
))
1147 (gnus-agent-while-plugged
1149 (error "No articles to download"))
1150 (gnus-agent-with-fetch
1151 (setq gnus-newsgroup-undownloaded
1152 (gnus-sorted-ndifference
1153 gnus-newsgroup-undownloaded
1154 (setq fetched-articles
1155 (gnus-agent-fetch-articles
1156 gnus-newsgroup-name articles
)))))
1158 (dolist (article articles
)
1159 (let ((was-marked-downloadable
1160 (memq article gnus-newsgroup-downloadable
)))
1161 (cond (gnus-agent-mark-unread-after-downloaded
1162 (setq gnus-newsgroup-downloadable
1163 (delq article gnus-newsgroup-downloadable
))
1164 (when (and (not (member article gnus-newsgroup-dormant
))
1165 (not (member article gnus-newsgroup-marked
)))
1166 (gnus-summary-mark-article article gnus-unread-mark
)))
1167 (was-marked-downloadable
1168 (gnus-summary-set-agent-mark article t
)))
1169 (when (gnus-summary-goto-subject article nil t
)
1170 (gnus-summary-update-download-mark article
))))))
1173 (defun gnus-agent-fetch-selected-article ()
1174 "Fetch the current article as it is selected.
1175 This can be added to `gnus-select-article-hook' or
1176 `gnus-mark-article-hook'."
1177 (let ((gnus-command-method gnus-current-select-method
))
1178 (when (and gnus-plugged
(gnus-agent-method-p gnus-command-method
))
1179 (when (gnus-agent-fetch-articles
1181 (list gnus-current-article
))
1182 (setq gnus-newsgroup-undownloaded
1183 (delq gnus-current-article gnus-newsgroup-undownloaded
))
1184 (gnus-summary-update-download-mark gnus-current-article
)))))
1187 ;;; Internal functions
1190 (defun gnus-agent-synchronize-group-flags (group actions server
)
1191 "Update a plugged group by performing the indicated actions."
1192 (let* ((gnus-command-method (gnus-server-to-method server
))
1194 ;; This initializer is required as gnus-request-set-mark
1195 ;; calls gnus-group-real-name to strip off the host name
1196 ;; before calling the backend. Now that the backend is
1197 ;; trying to call gnus-request-set-mark, I have to
1198 ;; reconstruct the original group name.
1199 (or (gnus-get-info group
)
1201 (setq group
(gnus-group-full-name
1202 group gnus-command-method
))))))
1203 (gnus-request-set-mark group actions
)
1206 (dolist (action actions
)
1207 (let ((range (nth 0 action
))
1208 (what (nth 1 action
))
1209 (marks (nth 2 action
)))
1210 (dolist (mark marks
)
1211 (cond ((eq mark
'read
)
1214 (funcall (if (eq what
'add
)
1216 'gnus-remove-from-range
)
1217 (gnus-info-read info
)
1219 (gnus-get-unread-articles-in-group
1221 (gnus-active (gnus-info-group info
))))
1222 ((memq mark
'(tick))
1223 (let ((info-marks (assoc mark
(gnus-info-marks info
))))
1225 (gnus-info-set-marks info
(cons (setq info-marks
(list mark
)) (gnus-info-marks info
))))
1226 (setcdr info-marks
(funcall (if (eq what
'add
)
1228 'gnus-remove-from-range
)
1232 ;;Marks can be synchronized at any time by simply toggling from
1233 ;;unplugged to plugged. If that is what is happening right now, make
1234 ;;sure that the group buffer is up to date.
1235 (when (gnus-buffer-live-p gnus-group-buffer
)
1236 (gnus-group-update-group group t
)))
1239 (defun gnus-agent-save-active (method &optional groups-p
)
1240 "Sync the agent's active file with the current buffer.
1241 Pass non-nil for GROUPS-P if the buffer starts out in groups format.
1242 Regardless, both the file and the buffer end up in active format
1243 if METHOD is agentized; otherwise the function is a no-op."
1244 (when (gnus-agent-method-p method
)
1245 (let* ((gnus-command-method method
)
1246 (new (gnus-make-hashtable (count-lines (point-min) (point-max))))
1247 (file (gnus-agent-lib-file "active")))
1249 (gnus-groups-to-gnus-format nil new
)
1250 (gnus-active-to-gnus-format nil new
))
1251 (gnus-agent-write-active file new
)
1253 (let ((nnheader-file-coding-system gnus-agent-file-coding-system
))
1254 (nnheader-insert-file-contents file
)))))
1256 (defun gnus-agent-write-active (file new
)
1257 (gnus-make-directory (file-name-directory file
))
1258 (let ((nnmail-active-file-coding-system gnus-agent-file-coding-system
))
1259 ;; The hashtable contains real names of groups. However, do NOT
1260 ;; add the foreign server prefix as gnus-active-to-gnus-format
1261 ;; will add it while reading the file.
1262 (gnus-write-active-file file new nil
)))
1265 (defun gnus-agent-possibly-alter-active (group active
&optional info
)
1266 "Possibly expand a group's active range to include articles
1267 downloaded into the agent."
1268 (let* ((gnus-command-method (or gnus-command-method
1269 (gnus-find-method-for-group group
))))
1270 (when (gnus-agent-method-p gnus-command-method
)
1271 (let* ((local (gnus-agent-get-local group
))
1272 (active-min (or (car active
) 0))
1273 (active-max (or (cdr active
) 0))
1274 (agent-min (or (car local
) active-min
))
1275 (agent-max (or (cdr local
) active-max
)))
1277 (when (< agent-min active-min
)
1278 (setcar active agent-min
))
1280 (when (> agent-max active-max
)
1281 (setcdr active agent-max
))
1283 (when (and info
(< agent-max
(- active-min
100)))
1284 ;; I'm expanding the active range by such a large amount
1285 ;; that there is a gap of more than 100 articles between the
1286 ;; last article known to the agent and the first article
1287 ;; currently available on the server. This gap contains
1288 ;; articles that have been lost, mark them as read so that
1289 ;; gnus doesn't waste resources trying to fetch them.
1291 ;; NOTE: I don't do this for smaller gaps (< 100) as I don't
1292 ;; want to modify the local file everytime someone restarts
1293 ;; gnus. The small gap will cause a tiny performance hit
1294 ;; when gnus tries, and fails, to retrieve the articles.
1295 ;; Still that should be smaller than opening a buffer,
1296 ;; printing this list to the buffer, and then writing it to a
1299 (let ((read (gnus-info-read info
)))
1304 (list (cons (1+ agent-max
)
1305 (1- active-min
))))))
1307 ;; Lie about the agent's local range for this group to
1308 ;; disable the set read each time this server is opened.
1309 ;; NOTE: Opening this group will restore the valid local
1310 ;; range but it will also expand the local range to
1311 ;; encompass the new active range.
1312 (gnus-agent-set-local group agent-min
(1- active-min
)))))))
1314 (defun gnus-agent-save-group-info (method group active
)
1315 "Update a single group's active range in the agent's copy of the server's active file."
1316 (when (gnus-agent-method-p method
)
1317 (let* ((gnus-command-method (or method gnus-command-method
))
1318 (coding-system-for-write nnheader-file-coding-system
)
1319 (file-name-coding-system nnmail-pathname-coding-system
)
1320 (file (gnus-agent-lib-file "active"))
1321 oactive-min oactive-max
)
1322 (gnus-make-directory (file-name-directory file
))
1323 (with-temp-file file
1324 ;; Emacs got problem to match non-ASCII group in multibyte buffer.
1325 (mm-disable-multibyte)
1326 (when (file-exists-p file
)
1327 (nnheader-insert-file-contents file
)
1329 (goto-char (point-min))
1330 (when (re-search-forward
1331 (concat "^" (regexp-quote group
) " ") nil t
)
1333 (setq oactive-max
(read (current-buffer)) ;; max
1334 oactive-min
(read (current-buffer)))) ;; min
1335 (gnus-delete-line)))
1337 (insert (format "%S %d %d y\n" (intern group
)
1338 (max (or oactive-max
(cdr active
)) (cdr active
))
1339 (min (or oactive-min
(car active
)) (car active
))))
1340 (goto-char (point-max))
1341 (while (search-backward "\\." nil t
)
1342 (delete-char 1)))))))
1344 (defun gnus-agent-get-group-info (method group
)
1345 "Get a single group's active range in the agent's copy of the server's active file."
1346 (when (gnus-agent-method-p method
)
1347 (let* ((gnus-command-method (or method gnus-command-method
))
1348 (coding-system-for-write nnheader-file-coding-system
)
1349 (file-name-coding-system nnmail-pathname-coding-system
)
1350 (file (gnus-agent-lib-file "active"))
1351 oactive-min oactive-max
)
1352 (gnus-make-directory (file-name-directory file
))
1354 ;; Emacs got problem to match non-ASCII group in multibyte buffer.
1355 (mm-disable-multibyte)
1356 (when (file-exists-p file
)
1357 (nnheader-insert-file-contents file
)
1359 (goto-char (point-min))
1360 (when (re-search-forward
1361 (concat "^" (regexp-quote group
) " ") nil t
)
1363 (setq oactive-max
(read (current-buffer)) ;; max
1364 oactive-min
(read (current-buffer))) ;; min
1365 (cons oactive-min oactive-max
))))))))
1367 (defvar gnus-agent-decoded-group-names nil
1368 "Alist of non-ASCII group names and decoded ones.")
1370 (defun gnus-agent-decoded-group-name (group)
1371 "Return a decoded group name of GROUP."
1372 (or (cdr (assoc group gnus-agent-decoded-group-names
))
1373 (if (string-match "[^\000-\177]" group
)
1374 (let ((decoded (gnus-group-decoded-name group
)))
1375 (push (cons group decoded
) gnus-agent-decoded-group-names
)
1379 (defun gnus-agent-group-path (group)
1380 "Translate GROUP into a file name."
1382 ;; NOTE: This is what nnmail-group-pathname does as of Apr 2003.
1383 ;; The two methods must be kept synchronized, which is why
1384 ;; gnus-agent-group-pathname was added.
1387 (nnheader-translate-file-chars
1388 (nnheader-replace-duplicate-chars-in-string
1389 (nnheader-replace-chars-in-string
1390 (gnus-group-real-name (gnus-agent-decoded-group-name group
))
1393 (if (or nnmail-use-long-file-names
1394 (file-directory-p (expand-file-name group
(gnus-agent-directory))))
1396 (nnheader-replace-chars-in-string group ?. ?
/)))
1398 (defun gnus-agent-group-pathname (group)
1399 "Translate GROUP into a file name."
1400 ;; nnagent uses nnmail-group-pathname to read articles while
1401 ;; unplugged. The agent must, therefore, use the same directory
1403 (nnmail-group-pathname
1404 (gnus-group-real-name (gnus-agent-decoded-group-name group
))
1405 (if gnus-command-method
1406 (gnus-agent-directory)
1407 (let ((gnus-command-method (gnus-find-method-for-group group
)))
1408 (gnus-agent-directory)))))
1410 (defun gnus-agent-get-function (method)
1411 (if (gnus-online method
)
1416 (defun gnus-agent-covered-methods ()
1417 "Return the subset of methods that are covered by the agent."
1418 (delq nil
(mapcar #'gnus-server-to-method gnus-agent-covered-methods
)))
1420 ;;; History functions
1422 (defun gnus-agent-history-buffer ()
1423 (cdr (assoc (gnus-agent-method) gnus-agent-history-buffers
)))
1425 (defun gnus-agent-open-history ()
1427 (push (cons (gnus-agent-method)
1428 (set-buffer (gnus-get-buffer-create
1429 (format " *Gnus agent %s history*"
1430 (gnus-agent-method)))))
1431 gnus-agent-history-buffers
)
1432 (mm-disable-multibyte) ;; everything is binary
1435 (let ((file (gnus-agent-lib-file "history")))
1436 (when (file-exists-p file
)
1437 (nnheader-insert-file-contents file
))
1438 (set (make-local-variable 'gnus-agent-file-name
) file
))))
1440 (defun gnus-agent-close-history ()
1441 (when (gnus-buffer-live-p gnus-agent-current-history
)
1442 (kill-buffer gnus-agent-current-history
)
1443 (setq gnus-agent-history-buffers
1444 (delq (assoc (gnus-agent-method) gnus-agent-history-buffers
)
1445 gnus-agent-history-buffers
))))
1451 (defun gnus-agent-fetch-articles (group articles
)
1452 "Fetch ARTICLES from GROUP and put them into the Agent."
1454 (gnus-online (gnus-group-method group
)))
1455 (gnus-agent-load-alist group
)
1456 (let* ((alist gnus-agent-article-alist
)
1457 (headers (if (< (length articles
) 2) nil gnus-newsgroup-headers
))
1458 (selected-sets (list nil
))
1459 (current-set-size 0)
1462 ;; Check each article
1463 (while (setq article
(pop articles
))
1464 ;; Skip alist entries preceding this article
1465 (while (> article
(or (caar alist
) (1+ article
)))
1466 (setq alist
(cdr alist
)))
1468 ;; Prune off articles that we have already fetched.
1469 (unless (and (eq article
(caar alist
))
1471 ;; Skip headers preceding this article
1474 (let* ((header (car headers
)))
1476 (mail-header-number header
)
1478 (setq headers
(cdr headers
)))
1480 ;; Add this article to the current set
1481 (setcar selected-sets
(cons article
(car selected-sets
)))
1483 ;; Update the set size, when the set is too large start a
1484 ;; new one. I do this after adding the article as I want at
1485 ;; least one article in each set.
1486 (when (< gnus-agent-max-fetch-size
1487 (setq current-set-size
1489 (if (= header-number article
)
1490 (let ((char-size (mail-header-chars
1492 (if (<= char-size
0)
1493 ;; The char size was missing/invalid,
1494 ;; assume a worst-case situation of
1495 ;; 65 char/line. If the line count
1496 ;; is missing, arbitrarily assume a
1497 ;; size of 1000 characters.
1498 (max (* 65 (mail-header-lines
1503 (setcar selected-sets
(nreverse (car selected-sets
)))
1504 (setq selected-sets
(cons nil selected-sets
)
1505 current-set-size
0))))
1507 (when (or (cdr selected-sets
) (car selected-sets
))
1508 (let* ((fetched-articles (list nil
))
1509 (tail-fetched-articles fetched-articles
)
1510 (dir (gnus-agent-group-pathname group
))
1511 (date (time-to-days nil
))
1512 (case-fold-search t
)
1514 (file-name-coding-system nnmail-pathname-coding-system
))
1516 (setcar selected-sets
(nreverse (car selected-sets
)))
1517 (setq selected-sets
(nreverse selected-sets
))
1519 (gnus-make-directory dir
)
1520 (gnus-message 7 "Fetching articles for %s..."
1521 (gnus-agent-decoded-group-name group
))
1524 (while (setq articles
(pop selected-sets
))
1525 ;; Fetch the articles from the backend.
1526 (if (gnus-check-backend-function 'retrieve-articles group
)
1527 (setq pos
(gnus-retrieve-articles articles group
))
1530 (while (setq article
(pop articles
))
1531 (gnus-message 10 "Fetching article %s for %s..."
1533 (gnus-agent-decoded-group-name group
))
1535 (gnus-backlog-request-article group article
1537 (gnus-request-article article group
))
1538 (goto-char (point-max))
1539 (push (cons article
(point)) pos
)
1540 (insert-buffer-substring nntp-server-buffer
)))
1542 nntp-server-buffer
(point-min) (point-max))
1543 (setq pos
(nreverse pos
)))))
1544 ;; Then save these articles into the Agent.
1545 (with-current-buffer nntp-server-buffer
1547 (narrow-to-region (cdar pos
) (or (cdadr pos
) (point-max)))
1548 (goto-char (point-min))
1549 (unless (eobp) ;; Don't save empty articles.
1550 (when (search-forward "\n\n" nil t
)
1551 (when (search-backward "\nXrefs: " nil t
)
1552 ;; Handle cross posting.
1553 (goto-char (match-end 0)) ; move to end of header name
1554 (skip-chars-forward "^ ") ; skip server name
1555 (skip-chars-forward " ")
1557 (while (looking-at "\\([^: \n]+\\):\\([0-9]+\\) *")
1558 (push (cons (buffer-substring (match-beginning 1)
1561 (buffer-substring (match-beginning 2)
1564 (goto-char (match-end 0)))
1565 (gnus-agent-crosspost crosses
(caar pos
) date
)))
1566 (goto-char (point-min))
1567 (let ((coding-system-for-write
1568 gnus-agent-file-coding-system
))
1569 (write-region (point-min) (point-max)
1570 (concat dir
(number-to-string (caar pos
)))
1573 (gnus-agent-append-to-list
1574 tail-fetched-articles
(caar pos
)))
1576 (setq pos
(cdr pos
)))))
1578 (gnus-agent-save-alist group
(cdr fetched-articles
) date
)
1579 (gnus-agent-update-files-total-fetched-for group
(cdr fetched-articles
))
1581 (gnus-message 7 ""))
1582 (cdr fetched-articles
))))))
1584 (defun gnus-agent-unfetch-articles (group articles
)
1585 "Delete ARTICLES that were fetched from GROUP into the agent."
1587 (gnus-agent-with-refreshed-group
1589 (gnus-agent-load-alist group
)
1590 (let* ((alist (cons nil gnus-agent-article-alist
))
1591 (articles (sort articles
#'<))
1592 (next-possibility alist
)
1593 (delete-this (pop articles
)))
1594 (while (and (cdr next-possibility
) delete-this
)
1595 (let ((have-this (caar (cdr next-possibility
))))
1597 ((< delete-this have-this
)
1598 (setq delete-this
(pop articles
)))
1599 ((= delete-this have-this
)
1600 (let ((timestamp (cdar (cdr next-possibility
))))
1602 (let* ((file-name (concat (gnus-agent-group-pathname group
)
1603 (number-to-string have-this
)))
1605 (float (or (and gnus-agent-total-fetched-hashtb
1606 (file-attribute-size
1607 (file-attributes file-name
)))
1609 (file-name-coding-system
1610 nnmail-pathname-coding-system
))
1611 (delete-file file-name
)
1612 (gnus-agent-update-files-total-fetched-for
1613 group
(- size-file
)))))
1615 (setcdr next-possibility
(cddr next-possibility
)))
1617 (setq next-possibility
(cdr next-possibility
))))))
1618 (setq gnus-agent-article-alist
(cdr alist
))
1619 (gnus-agent-save-alist group
)))))
1621 (defun gnus-agent-crosspost (crosses article
&optional date
)
1622 (setq date
(or date t
))
1624 (let (gnus-agent-article-alist group alist beg end
)
1625 (with-current-buffer gnus-agent-overview-buffer
1626 (when (nnheader-find-nov-line article
)
1629 (setq end
(progn (forward-line 1) (point)))))
1631 (setq group
(caar crosses
))
1632 (unless (setq alist
(assoc group gnus-agent-group-alist
))
1633 (push (setq alist
(list group
(gnus-agent-load-alist (caar crosses
))))
1634 gnus-agent-group-alist
))
1635 (setcdr alist
(cons (cons (cdar crosses
) date
) (cdr alist
)))
1636 (with-current-buffer (gnus-get-buffer-create
1637 (format " *Gnus agent overview %s*"group
))
1638 (when (= (point-max) (point-min))
1639 (push (cons group
(current-buffer)) gnus-agent-buffer-alist
)
1641 (let ((file-name-coding-system nnmail-pathname-coding-system
))
1642 (nnheader-insert-file-contents
1643 (gnus-agent-article-name ".overview" group
)))))
1644 (nnheader-find-nov-line (string-to-number (cdar crosses
)))
1645 (insert (string-to-number (cdar crosses
)))
1646 (insert-buffer-substring gnus-agent-overview-buffer beg end
)
1647 (gnus-agent-check-overview-buffer))
1648 (setq crosses
(cdr crosses
)))))
1650 (defun gnus-agent-backup-overview-buffer ()
1651 (when gnus-newsgroup-name
1652 (let ((root (gnus-agent-article-name ".overview" gnus-newsgroup-name
))
1655 (file-name-coding-system nnmail-pathname-coding-system
))
1656 (while (file-exists-p
1657 (setq name
(concat root
"~"
1658 (int-to-string (setq cnt
(1+ cnt
))) "~"))))
1659 (write-region (point-min) (point-max) name nil
'no-msg
)
1660 (gnus-message 1 "Created backup copy of overview in %s." name
)))
1663 (defun gnus-agent-check-overview-buffer (&optional buffer
)
1664 "Check the overview file given for sanity.
1665 In particular, checks that the file is sorted by article number
1666 and that there are no duplicates."
1671 (set-buffer buffer
))
1674 (goto-char (point-min))
1676 (while (< (point) (point-max))
1678 (cur (condition-case nil
1679 (read (current-buffer))
1682 ((or (not (integerp cur
))
1683 (not (eq (char-after) ?
\t)))
1685 (setq backed-up
(gnus-agent-backup-overview-buffer)))
1687 "Overview buffer contains garbage `%s'."
1692 (setq backed-up
(gnus-agent-backup-overview-buffer)))
1694 "Duplicate overview line for %d" cur
)
1695 (delete-region p
(progn (forward-line 1) (point))))
1698 (setq backed-up
(gnus-agent-backup-overview-buffer)))
1699 (gnus-message 1 "Overview buffer not sorted!")
1700 (sort-numeric-fields 1 (point-min) (point-max))
1701 (goto-char (point-min))
1704 (setq prev-num cur
)))
1705 (forward-line 1)))))))
1707 (defun gnus-agent-flush-server (&optional server-or-method
)
1708 "Flush all agent index files for every subscribed group within
1709 the given SERVER-OR-METHOD. When called with nil, the current
1710 value of gnus-command-method identifies the server."
1711 (let* ((gnus-command-method (if server-or-method
1712 (gnus-server-to-method server-or-method
)
1713 gnus-command-method
))
1714 (alist gnus-newsrc-alist
))
1716 (let ((entry (pop alist
)))
1717 (when (gnus-methods-equal-p gnus-command-method
(gnus-info-method entry
))
1718 (gnus-agent-flush-group (gnus-info-group entry
)))))))
1720 (defun gnus-agent-flush-group (group)
1721 "Flush the agent's index files such that the GROUP no longer
1722 appears to have any local content. The actual content, the
1723 article files, may then be deleted using gnus-agent-expire-group.
1724 If flushing was a mistake, the gnus-agent-regenerate-group method
1725 provides an undo mechanism by reconstructing the index files from
1727 (interactive (list (gnus-agent-read-group)))
1729 (let* ((gnus-command-method (or gnus-command-method
1730 (gnus-find-method-for-group group
)))
1731 (overview (gnus-agent-article-name ".overview" group
))
1732 (agentview (gnus-agent-article-name ".agentview" group
))
1733 (file-name-coding-system nnmail-pathname-coding-system
))
1735 (if (file-exists-p overview
)
1736 (delete-file overview
))
1737 (if (file-exists-p agentview
)
1738 (delete-file agentview
))
1740 (gnus-agent-update-view-total-fetched-for group nil gnus-command-method
)
1741 (gnus-agent-update-view-total-fetched-for group t gnus-command-method
)
1743 ;(gnus-agent-set-local group nil nil)
1744 ;(gnus-agent-save-local t)
1745 (gnus-agent-save-group-info nil group nil
)))
1747 (defun gnus-agent-flush-cache ()
1748 "Flush the agent's index files such that the group no longer
1749 appears to have any local content. The actual content, the
1750 article files, is then deleted using gnus-agent-expire-group. The
1751 gnus-agent-regenerate-group method provides an undo mechanism by
1752 reconstructing the index files from the article files."
1755 (let ((file-name-coding-system nnmail-pathname-coding-system
))
1756 (while gnus-agent-buffer-alist
1757 (set-buffer (cdar gnus-agent-buffer-alist
))
1758 (let ((coding-system-for-write gnus-agent-file-coding-system
))
1759 (write-region (point-min) (point-max)
1760 (gnus-agent-article-name ".overview"
1761 (caar gnus-agent-buffer-alist
))
1763 (setq gnus-agent-buffer-alist
(cdr gnus-agent-buffer-alist
)))
1764 (while gnus-agent-group-alist
1765 (with-temp-file (gnus-agent-article-name
1766 ".agentview" (caar gnus-agent-group-alist
))
1767 (princ (cdar gnus-agent-group-alist
))
1769 (princ 1 (current-buffer))
1771 (setq gnus-agent-group-alist
(cdr gnus-agent-group-alist
))))))
1774 (defun gnus-agent-find-parameter (group symbol
)
1775 "Search for GROUPs SYMBOL in the group's parameters, the group's
1776 topic parameters, the group's category, or the customizable
1777 variables. Returns the first non-nil value found."
1778 (or (gnus-group-find-parameter group symbol t
)
1779 (gnus-group-parameter-value (cdr (gnus-group-category group
)) symbol t
)
1783 '((agent-short-article . gnus-agent-short-article
)
1784 (agent-long-article . gnus-agent-long-article
)
1785 (agent-low-score . gnus-agent-low-score
)
1786 (agent-high-score . gnus-agent-high-score
)
1787 (agent-days-until-old . gnus-agent-expire-days
)
1788 (agent-enable-expiration
1789 . gnus-agent-enable-expiration
)
1790 (agent-predicate . gnus-agent-predicate
)))))))
1792 (defun gnus-agent-fetch-headers (group)
1793 "Fetch interesting headers into the agent. The group's overview
1794 file will be updated to include the headers while a list of available
1795 article numbers will be returned."
1796 (let* ((fetch-all (and gnus-agent-consider-all-articles
1797 ;; Do not fetch all headers if the predicate
1798 ;; implies that we only consider unread articles.
1799 (not (gnus-predicate-implies-unread
1800 (gnus-agent-find-parameter group
1801 'agent-predicate
)))))
1802 (articles (if fetch-all
1803 (if gnus-newsgroup-maximum-articles
1804 (let ((active (gnus-active group
)))
1805 (gnus-uncompress-range
1806 (cons (max (car active
)
1808 gnus-newsgroup-maximum-articles
1811 (gnus-uncompress-range (gnus-active group
)))
1812 (gnus-list-of-unread-articles group
)))
1813 (gnus-decode-encoded-word-function 'identity
)
1814 (gnus-decode-encoded-address-function 'identity
)
1815 (file (gnus-agent-article-name ".overview" group
))
1816 (file-name-coding-system nnmail-pathname-coding-system
))
1819 ;; Add articles with marks to the list of article headers we want to
1820 ;; fetch. Don't fetch articles solely on the basis of a recent or seen
1821 ;; mark, but do fetch recent or seen articles if they have other, more
1822 ;; interesting marks. (We have to fetch articles with boring marks
1823 ;; because otherwise the agent will remove their marks.)
1824 (dolist (arts (gnus-info-marks (gnus-get-info group
)))
1825 (unless (memq (car arts
) '(seen recent killed cache
))
1826 (setq articles
(gnus-range-add articles
(cdr arts
)))))
1827 (setq articles
(sort (gnus-uncompress-sequence articles
) '<)))
1829 ;; At this point, I have the list of articles to consider for
1830 ;; fetching. This is the list that I'll return to my caller. Some
1831 ;; of these articles may have already been fetched. That's OK as
1832 ;; the fetch article code will filter those out. Internally, I'll
1833 ;; filter this list to just those articles whose headers need to
1835 (let ((articles articles
))
1836 ;; Remove known articles.
1837 (when (and (or gnus-agent-cache
1839 (gnus-agent-load-alist group
))
1840 ;; Remove articles marked as downloaded.
1842 ;; I want to fetch all headers in the active range.
1843 ;; Therefore, exclude only those headers that are in the
1845 ;; NOTE: This is probably NOT what I want to do after
1846 ;; agent expiration in this group.
1847 (setq articles
(gnus-agent-uncached-articles articles group
))
1849 ;; I want to only fetch those headers that have never been
1850 ;; fetched. Therefore, exclude all headers that are, or
1851 ;; WERE, in the article alist.
1852 (let ((low (1+ (caar (last gnus-agent-article-alist
))))
1853 (high (cdr (gnus-active group
))))
1854 ;; Low can be greater than High when the same group is
1855 ;; fetched twice in the same session {The first fetch will
1856 ;; fill the article alist such that (last
1857 ;; gnus-agent-article-alist) equals (cdr (gnus-active
1858 ;; group))}. The addition of one(the 1+ above) then
1859 ;; forces Low to be greater than High. When this happens,
1860 ;; gnus-list-range-intersection returns nil which
1861 ;; indicates that no headers need to be fetched. -- Kevin
1862 (setq articles
(gnus-list-range-intersection
1863 articles
(list (cons low high
)))))))
1867 10 "gnus-agent-fetch-headers: undownloaded articles are `%s'"
1868 (gnus-compress-sequence articles t
)))
1870 (with-current-buffer nntp-server-buffer
1873 (gnus-message 8 "Fetching headers for %s..."
1874 (gnus-agent-decoded-group-name group
))
1877 (gnus-make-directory (nnheader-translate-file-chars
1878 (file-name-directory file
) t
))
1880 (unless (eq 'nov
(gnus-retrieve-headers articles group
))
1881 (nnvirtual-convert-headers))
1882 (gnus-agent-check-overview-buffer)
1883 ;; Move these headers to the overview buffer so that
1884 ;; gnus-agent-braid-nov can merge them with the contents
1887 gnus-agent-overview-buffer
(point-min) (point-max))
1888 ;; NOTE: Call g-a-brand-nov even when the file does not
1889 ;; exist. As a minimum, it will validate the article
1890 ;; numbers already in the buffer.
1891 (gnus-agent-braid-nov articles file
)
1892 (let ((coding-system-for-write
1893 gnus-agent-file-coding-system
))
1894 (gnus-agent-check-overview-buffer)
1895 (write-region (point-min) (point-max) file nil
'silent
))
1896 (gnus-agent-update-view-total-fetched-for group t
)
1897 (gnus-agent-save-alist group articles nil
)
1901 (nnheader-insert-file-contents file
)))))
1904 (defsubst gnus-agent-read-article-number
()
1905 "Reads the article number at point. Returns nil when a valid article number can not be read."
1907 ;; It is unfortunate but the read function quietly overflows
1908 ;; integer. As a result, I have to use string operations to test
1909 ;; for overflow BEFORE calling read.
1910 (when (looking-at "[0-9]+\t")
1911 (let ((len (- (match-end 0) (match-beginning 0))))
1913 (read (current-buffer)))
1915 ;; Many 9 digit base-10 numbers can be represented in a 27-bit int
1916 ;; Back convert from int to string to ensure that this is one of them.
1917 (let* ((str1 (buffer-substring (match-beginning 0) (1- (match-end 0))))
1918 (num (read (current-buffer)))
1919 (str2 (int-to-string num
)))
1920 (when (equal str1 str2
)
1923 (defsubst gnus-agent-copy-nov-line
(article)
1924 "Copy the indicated ARTICLE from the overview buffer to the nntp server buffer."
1926 (set-buffer gnus-agent-overview-buffer
)
1927 (while (and (not (eobp))
1928 (or (not (setq art
(gnus-agent-read-article-number)))
1933 (not (eq article art
)))
1934 (set-buffer nntp-server-buffer
)
1936 (setq e
(progn (forward-line 1) (point)))
1937 (set-buffer nntp-server-buffer
)
1938 (insert-buffer-substring gnus-agent-overview-buffer b e
))))
1940 (defun gnus-agent-braid-nov (articles file
)
1941 "Merge agent overview data with given file.
1942 Takes unvalidated headers for ARTICLES from
1943 `gnus-agent-overview-buffer' and validated headers from the given
1944 FILE and places the combined valid headers into
1945 `nntp-server-buffer'. This function can be used, when file
1946 doesn't exist, to valid the overview buffer."
1948 (set-buffer gnus-agent-overview-buffer
)
1949 (goto-char (point-min))
1950 (set-buffer nntp-server-buffer
)
1952 (when (file-exists-p file
)
1953 (nnheader-insert-file-contents file
))
1954 (goto-char (point-max))
1957 (unless (or (= (point-min) (point-max))
1958 (< (setq last
(read (current-buffer))) (car articles
)))
1959 ;; Old and new overlap -- We do it the hard way.
1960 (when (nnheader-find-nov-line (car articles
))
1961 ;; Replacing existing NOV entry
1962 (delete-region (point) (progn (forward-line 1) (point))))
1963 (gnus-agent-copy-nov-line (pop articles
))
1967 (while (let ((art (read (current-buffer))))
1968 (cond ((< art
(car articles
))
1971 ((= art
(car articles
))
1974 (point) (progn (forward-line 1) (point)))
1980 (gnus-agent-copy-nov-line (pop articles
)))))
1982 (goto-char (point-max))
1984 ;; Append the remaining lines
1987 (set-buffer gnus-agent-overview-buffer
)
1988 (setq start
(point))
1989 (set-buffer nntp-server-buffer
))
1992 (insert-buffer-substring gnus-agent-overview-buffer start
)
1995 (setq last
(or last -
134217728))
1996 (while (catch 'problems
1999 (setq art
(gnus-agent-read-article-number))
2001 ;; Bad art num - delete this line
2003 (delete-region (point) (progn (forward-line 1) (point))))
2005 ;; Art num out of order - enable sort
2009 ;; Bad repeat of art number - delete this line
2011 (delete-region (point) (progn (forward-line 1) (point))))
2017 ;; something is seriously wrong as we simply shouldn't see out-of-order data.
2018 ;; First, we'll fix the sort.
2019 (sort-numeric-fields 1 (point-min) (point-max))
2021 ;; but now we have to consider that we may have duplicate rows...
2022 ;; so reset to beginning of file
2023 (goto-char (point-min))
2024 (setq last -
134217728)
2026 ;; and throw a code that restarts this scan
2027 (throw 'problems t
))
2030 ;; Keeps the compiler from warning about the free variable in
2031 ;; gnus-agent-read-agentview.
2032 (defvar gnus-agent-read-agentview
)
2034 (defun gnus-agent-load-alist (group)
2035 "Load the article-state alist for GROUP."
2036 ;; Bind free variable that's used in `gnus-agent-read-agentview'.
2037 (let* ((gnus-agent-read-agentview group
)
2038 (file-name-coding-system nnmail-pathname-coding-system
)
2039 (agentview (gnus-agent-article-name ".agentview" group
)))
2040 (setq gnus-agent-article-alist
2041 (and (file-exists-p agentview
)
2042 (gnus-cache-file-contents
2044 'gnus-agent-file-loading-cache
2045 'gnus-agent-read-agentview
)))))
2047 (defun gnus-agent-read-agentview (file)
2048 "Load FILE and do a `read' there."
2052 (nnheader-insert-file-contents file
)
2053 (goto-char (point-min))
2054 (let ((alist (read (current-buffer)))
2055 (version (condition-case nil
(read (current-buffer))
2061 (let ((inhibit-quit t
)
2063 (gnus-agent-open-history)
2064 (set-buffer (gnus-agent-history-buffer))
2065 (goto-char (point-min))
2067 (if (and (looking-at
2068 "[^\t\n]+\t\\([0-9]+\\)\t\\([^ \n]+\\) \\([0-9]+\\)")
2069 (string= (match-string 2)
2070 gnus-agent-read-agentview
)
2071 (setq entry
(assoc (string-to-number (match-string 3)) alist
)))
2072 (setcdr entry
(string-to-number (match-string 1))))
2074 (gnus-agent-close-history)
2075 (setq changed-version t
)))
2077 (setq changed-version
(not (= 1 gnus-agent-article-alist-save-format
))))
2079 (let (state sequence uncomp
)
2081 (setq state
(caar alist
)
2082 sequence
(inline (gnus-uncompress-range (cdar alist
)))
2085 (push (cons (pop sequence
) state
) uncomp
)))
2086 (setq alist
(sort uncomp
'car-less-than-car
)))
2087 (setq changed-version
(not (= 2 gnus-agent-article-alist-save-format
)))))
2088 (when changed-version
2089 (let ((gnus-agent-article-alist alist
))
2090 (gnus-agent-save-alist gnus-agent-read-agentview
)))
2092 ((end-of-file file-error
)
2093 ;; The agentview file is missing.
2095 ;; If the agent directory exists, attempt to perform a brute-force
2096 ;; reconstruction of its contents.
2098 (file-name-coding-system nnmail-pathname-coding-system
)
2099 (file-attributes (directory-files-and-attributes
2100 (gnus-agent-article-name
2101 "" gnus-agent-read-agentview
)
2103 (while file-attributes
2104 (let ((fa (pop file-attributes
)))
2105 (unless (file-attribute-type (cdr fa
))
2106 (push (cons (string-to-number (car fa
))
2108 (file-attribute-access-time (cdr fa
))))
2111 (file-error nil
))))))
2113 (defun gnus-agent-save-alist (group &optional articles state
)
2114 "Save the article-state alist for GROUP."
2115 (let* ((file-name-coding-system nnmail-pathname-coding-system
)
2116 (prev (cons nil gnus-agent-article-alist
))
2118 print-level print-length article
)
2119 (while (setq article
(pop articles
))
2120 (while (and (cdr prev
)
2121 (< (caadr prev
) article
))
2122 (setq prev
(cdr prev
)))
2125 (setcdr prev
(list (cons article state
))))
2126 ((> (caadr prev
) article
)
2127 (setcdr prev
(cons (cons article state
) (cdr prev
))))
2128 ((= (caadr prev
) article
)
2129 (setcdr (cadr prev
) state
)))
2130 (setq prev
(cdr prev
)))
2131 (setq gnus-agent-article-alist
(cdr all
))
2133 (gnus-agent-set-local group
2134 (caar gnus-agent-article-alist
)
2135 (caar (last gnus-agent-article-alist
)))
2137 (gnus-make-directory (gnus-agent-article-name "" group
))
2138 (with-temp-file (gnus-agent-article-name ".agentview" group
)
2139 (cond ((eq gnus-agent-article-alist-save-format
1)
2140 (princ gnus-agent-article-alist
(current-buffer)))
2141 ((eq gnus-agent-article-alist-save-format
2)
2142 (let ((alist gnus-agent-article-alist
)
2143 article-id day-of-download comp-list compressed
)
2145 (setq article-id
(caar alist
)
2146 day-of-download
(cdar alist
)
2147 comp-list
(assq day-of-download compressed
)
2150 (setcdr comp-list
(cons article-id
(cdr comp-list
)))
2151 (push (list day-of-download article-id
) compressed
)))
2152 (setq alist compressed
)
2154 (setq comp-list
(pop alist
))
2156 (gnus-compress-sequence (nreverse (cdr comp-list
)))))
2157 (princ compressed
(current-buffer)))))
2159 (princ gnus-agent-article-alist-save-format
(current-buffer))
2162 (gnus-agent-update-view-total-fetched-for group nil
)))
2164 (defvar gnus-agent-article-local nil
)
2165 (defvar gnus-agent-article-local-times nil
)
2166 (defvar gnus-agent-file-loading-local nil
)
2168 (defun gnus-agent-load-local (&optional method
)
2169 "Load the METHOD'S local file. The local file contains min/max
2170 article counts for each of the method's subscribed groups."
2171 (let ((gnus-command-method (or method gnus-command-method
)))
2172 (when (or (null gnus-agent-article-local-times
)
2173 (zerop gnus-agent-article-local-times
)
2174 (not (gnus-methods-equal-p
2176 (symbol-value (intern "+method" gnus-agent-article-local
)))))
2177 (setq gnus-agent-article-local
2178 (gnus-cache-file-contents
2179 (gnus-agent-lib-file "local")
2180 'gnus-agent-file-loading-local
2181 'gnus-agent-read-and-cache-local
))
2182 (when gnus-agent-article-local-times
2183 (cl-incf gnus-agent-article-local-times
)))
2184 gnus-agent-article-local
))
2186 (defun gnus-agent-read-and-cache-local (file)
2187 "Load and read FILE then bind its contents to
2188 gnus-agent-article-local. If that variable had `dirty' (also known as
2189 modified) original contents, they are first saved to their own file."
2190 (if (and gnus-agent-article-local
2191 (symbol-value (intern "+dirty" gnus-agent-article-local
)))
2192 (gnus-agent-save-local))
2193 (gnus-agent-read-local file
))
2195 (defun gnus-agent-read-local (file)
2196 "Load FILE and do a `read' there."
2197 (let ((my-obarray (gnus-make-hashtable (count-lines (point-min)
2202 (let ((nnheader-file-coding-system gnus-agent-file-coding-system
))
2203 (nnheader-insert-file-contents file
))
2206 (goto-char (point-min))
2207 ;; Skip any comments at the beginning of the file (the only place where they may appear)
2208 (while (= (following-char) ?\
;)
2210 (setq line
(1+ line
)))
2217 (cur (current-buffer))
2218 (obarray my-obarray
))
2219 (setq group
(read cur
)
2223 (when (stringp group
)
2224 (setq group
(intern group my-obarray
)))
2226 ;; NOTE: The '+ 0' ensure that min and max are both numerics.
2227 (set group
(cons (+ 0 min
) (+ 0 max
))))
2229 (gnus-message 3 "Warning - invalid agent local: %s on line %d: %s"
2230 file line
(error-message-string err
))))
2232 (setq line
(1+ line
))))
2234 (set (intern "+dirty" my-obarray
) nil
)
2235 (set (intern "+method" my-obarray
) gnus-command-method
)
2238 (defun gnus-agent-save-local (&optional force
)
2239 "Save gnus-agent-article-local under it method's agent.lib directory."
2240 (let ((my-obarray gnus-agent-article-local
))
2241 (when (and my-obarray
2242 (or force
(symbol-value (intern "+dirty" my-obarray
))))
2243 (let* ((gnus-command-method (symbol-value (intern "+method" my-obarray
)))
2244 ;; NOTE: gnus-command-method is used within gnus-agent-lib-file.
2245 (dest (gnus-agent-lib-file "local")))
2246 (gnus-make-directory (gnus-agent-lib-file ""))
2248 (let ((coding-system-for-write gnus-agent-file-coding-system
)
2249 (file-name-coding-system nnmail-pathname-coding-system
))
2250 (with-temp-file dest
2251 (let ((gnus-command-method (symbol-value (intern "+method" my-obarray
)))
2252 print-level print-length
2253 (standard-output (current-buffer)))
2254 (mapatoms (lambda (symbol)
2255 (cond ((not (boundp symbol
))
2257 ((member (symbol-name symbol
) '("+dirty" "+method"))
2260 (let ((range (symbol-value symbol
)))
2270 (defun gnus-agent-get-local (group &optional gmane method
)
2271 (let* ((gmane (or gmane
(gnus-group-real-name group
)))
2272 (gnus-command-method (or method
(gnus-find-method-for-group group
)))
2273 (local (gnus-agent-load-local))
2274 (symb (intern gmane local
))
2275 (minmax (and (boundp symb
) (symbol-value symb
))))
2277 ;; Bind these so that gnus-agent-load-alist doesn't change the
2278 ;; current alist (i.e. gnus-agent-article-alist)
2279 (let* ((gnus-agent-article-alist gnus-agent-article-alist
)
2280 (gnus-agent-file-loading-cache gnus-agent-file-loading-cache
)
2281 (alist (gnus-agent-load-alist group
)))
2285 (caar (last alist
))))
2286 (gnus-agent-set-local group
(car minmax
) (cdr minmax
)
2287 gmane gnus-command-method local
))))
2290 (defun gnus-agent-set-local (group min max
&optional gmane method local
)
2291 (let* ((gmane (or gmane
(gnus-group-real-name group
)))
2292 (gnus-command-method (or method
(gnus-find-method-for-group group
)))
2293 (local (or local
(gnus-agent-load-local)))
2294 (symb (intern gmane local
))
2295 (minmax (and (boundp symb
) (symbol-value symb
))))
2296 (if (cond ((and minmax
2297 (or (not (eq min
(car minmax
)))
2298 (not (eq max
(cdr minmax
))))
2307 (set symb
(cons min max
))
2310 (unintern symb local
)))
2311 (set (intern "+dirty" local
) t
))))
2313 (defun gnus-agent-article-name (article group
)
2314 (expand-file-name article
2315 (file-name-as-directory
2316 (gnus-agent-group-pathname group
))))
2318 (defun gnus-agent-batch-confirmation (msg)
2319 "Show error message and return t."
2320 (gnus-message 1 "%s" msg
)
2324 (defun gnus-agent-batch-fetch ()
2325 "Start Gnus and fetch session."
2328 (let ((gnus-agent-confirmation-function 'gnus-agent-batch-confirmation
))
2329 (gnus-agent-fetch-session))
2332 (defun gnus-agent-fetch-session ()
2333 "Fetch all articles and headers that are eligible for fetching."
2335 (unless gnus-agent-covered-methods
2336 (error "No servers are covered by the Gnus agent"))
2337 (unless gnus-plugged
2338 (error "Can't fetch articles while Gnus is unplugged"))
2339 (let ((methods (gnus-agent-covered-methods))
2340 groups group gnus-command-method
)
2343 (setq gnus-command-method
(car methods
))
2344 (when (and (or (gnus-server-opened gnus-command-method
)
2345 (gnus-open-server gnus-command-method
))
2346 (gnus-online gnus-command-method
))
2347 (setq groups
(gnus-groups-from-server (car methods
)))
2348 (gnus-agent-with-fetch
2349 (while (setq group
(pop groups
))
2350 (when (<= (gnus-group-level group
)
2351 gnus-agent-handle-level
)
2352 (if (or debug-on-error debug-on-quit
)
2353 (gnus-agent-fetch-group-1
2354 group gnus-command-method
)
2356 (gnus-agent-fetch-group-1
2357 group gnus-command-method
)
2359 (unless (funcall gnus-agent-confirmation-function
2360 (format "Error %s while fetching session. Should gnus continue? "
2361 (error-message-string err
)))
2362 (error "Cannot fetch articles into the Gnus agent")))
2364 (gnus-agent-regenerate-group group
)
2365 (unless (funcall gnus-agent-confirmation-function
2367 "%s while fetching session. Should gnus continue? "
2368 (error-message-string err
)))
2370 "Cannot fetch articles into the Gnus agent")))))))))
2371 (setq methods
(cdr methods
)))
2372 (gnus-run-hooks 'gnus-agent-fetched-hook
)
2373 (gnus-message 6 "Finished fetching articles into the Gnus agent"))))
2375 (defvar gnus-agent-short-article
500
2376 "Articles that have fewer lines than this are short.")
2378 (defvar gnus-agent-long-article
1000
2379 "Articles that have more lines than this are long.")
2381 (defvar gnus-agent-low-score
0
2382 "Articles that have a score lower than this have a low score.")
2384 (defvar gnus-agent-high-score
0
2385 "Articles that have a score higher than this have a high score.")
2387 (defun gnus-agent-fetch-group-1 (group method
)
2389 (let ((gnus-command-method method
)
2390 (gnus-newsgroup-name group
)
2391 (gnus-newsgroup-dependencies gnus-newsgroup-dependencies
)
2392 (gnus-newsgroup-headers gnus-newsgroup-headers
)
2393 (gnus-newsgroup-scored gnus-newsgroup-scored
)
2394 (gnus-use-cache gnus-use-cache
)
2395 (gnus-summary-expunge-below gnus-summary-expunge-below
)
2396 (gnus-summary-mark-below gnus-summary-mark-below
)
2397 (gnus-orphan-score gnus-orphan-score
)
2398 ;; Maybe some other gnus-summary local variables should also
2404 predicate info marks
2406 (unless (gnus-check-group group
)
2407 (error "Can't open server for %s" group
))
2410 (when (or gnus-newsgroup-active
2412 (gnus-activate-group group
))
2413 (let ((marked-articles gnus-newsgroup-downloadable
))
2414 ;; Identify the articles marked for download
2415 (unless gnus-newsgroup-active
2416 ;; The variable gnus-newsgroup-active was selected as I need
2417 ;; a gnus-summary local variable that is NOT bound to any
2418 ;; value (its global value should default to nil).
2419 (dolist (mark gnus-agent-download-marks
)
2420 (let ((arts (cdr (assq mark
(gnus-info-marks
2421 (setq info
(gnus-get-info group
)))))))
2423 (setq marked-articles
(nconc (gnus-uncompress-range arts
)
2426 (setq marked-articles
(sort marked-articles
'<))
2428 ;; Fetch any new articles from the server
2429 (setq articles
(gnus-agent-fetch-headers group
))
2431 ;; Merge new articles with marked
2432 (setq articles
(sort (append marked-articles articles
) '<))
2435 ;; Parse them and see which articles we want to fetch.
2436 (setq gnus-newsgroup-dependencies
2437 (or gnus-newsgroup-dependencies
2438 (make-vector (length articles
) 0)))
2439 (setq gnus-newsgroup-headers
2440 (or gnus-newsgroup-headers
2441 (gnus-get-newsgroup-headers-xover articles nil nil
2443 ;; `gnus-agent-overview-buffer' may be killed for
2444 ;; timeout reason. If so, recreate it.
2445 (gnus-agent-create-buffer)
2449 (gnus-agent-find-parameter group
'agent-predicate
)))
2451 ;; If the selection predicate requires scoring, score each header
2452 (unless (memq predicate
'(gnus-agent-true gnus-agent-false
))
2454 (gnus-agent-find-parameter group
'agent-score-file
)))
2455 ;; Translate score-param into real one
2458 ((eq score-param
'file
)
2459 (setq score-param
(gnus-all-score-files group
)))
2460 ((stringp (car score-param
)))
2462 (setq score-param
(list (list score-param
)))))
2464 (gnus-score-headers score-param
))))
2466 (unless (and (eq predicate
'gnus-agent-false
)
2467 (not marked-articles
))
2468 (let ((arts (list nil
)))
2469 (let ((arts-tail arts
)
2470 (alist (gnus-agent-load-alist group
))
2471 (marked-articles marked-articles
)
2472 (gnus-newsgroup-headers gnus-newsgroup-headers
))
2473 (while (setq gnus-headers
(pop gnus-newsgroup-headers
))
2474 (let ((num (mail-header-number gnus-headers
)))
2475 ;; Determine if this article is already in the cache
2477 (> num
(caar alist
)))
2478 (setq alist
(cdr alist
)))
2480 (unless (and (eq num
(caar alist
))
2483 ;; Determine if this article was marked for download.
2484 (while (and marked-articles
2485 (> num
(car marked-articles
)))
2486 (setq marked-articles
2487 (cdr marked-articles
)))
2489 ;; When this article is marked, or selected by the
2490 ;; predicate, add it to the download list
2491 (when (or (eq num
(car marked-articles
))
2494 (assq num gnus-newsgroup-scored
))
2495 gnus-summary-default-score
))
2496 (gnus-agent-long-article
2497 (gnus-agent-find-parameter
2498 group
'agent-long-article
))
2499 (gnus-agent-short-article
2500 (gnus-agent-find-parameter
2501 group
'agent-short-article
))
2502 (gnus-agent-low-score
2503 (gnus-agent-find-parameter
2504 group
'agent-low-score
))
2505 (gnus-agent-high-score
2506 (gnus-agent-find-parameter
2507 group
'agent-high-score
))
2508 (gnus-agent-expire-days
2509 (gnus-agent-find-parameter
2510 group
'agent-days-until-old
)))
2511 (funcall predicate
)))
2512 (gnus-agent-append-to-list arts-tail num
))))))
2514 (let (fetched-articles)
2515 ;; Fetch all selected articles
2516 (setq gnus-newsgroup-undownloaded
2517 (gnus-sorted-ndifference
2518 gnus-newsgroup-undownloaded
2519 (setq fetched-articles
2521 (gnus-agent-fetch-articles group
(cdr arts
))
2524 (let ((unfetched-articles
2525 (gnus-sorted-ndifference (cdr arts
) fetched-articles
)))
2526 (if gnus-newsgroup-active
2527 ;; Update the summary buffer
2529 (dolist (article marked-articles
)
2530 (gnus-summary-set-agent-mark article t
))
2531 (dolist (article fetched-articles
)
2532 (when gnus-agent-mark-unread-after-downloaded
2533 (setq gnus-newsgroup-downloadable
2534 (delq article gnus-newsgroup-downloadable
))
2535 (gnus-summary-mark-article
2536 article gnus-unread-mark
))
2537 (when (gnus-summary-goto-subject article nil t
)
2538 (gnus-summary-update-download-mark article
)))
2539 (dolist (article unfetched-articles
)
2540 (gnus-summary-mark-article
2541 article gnus-canceled-mark
)))
2543 ;; Update the group buffer.
2545 ;; When some, or all, of the marked articles came
2546 ;; from the download mark. Remove that mark. I
2547 ;; didn't do this earlier as I only want to remove
2548 ;; the marks after the fetch is completed.
2550 (dolist (mark gnus-agent-download-marks
)
2551 (when (eq mark
'download
)
2553 (assq mark
(gnus-info-marks
2554 (setq info
(gnus-get-info group
))))))
2555 (when (cdr marked-arts
)
2557 (delq marked-arts
(gnus-info-marks info
)))
2558 (gnus-info-set-marks info marks
)))))
2559 (let ((read (gnus-info-read
2560 (or info
(setq info
(gnus-get-info group
))))))
2562 info
(gnus-add-to-range read unfetched-articles
)))
2564 (gnus-group-update-group group t
)
2568 (concat "(gnus-group-set-info '"
2569 (gnus-prin1-to-string info
)
2571 (concat "^(gnus-group-set-info '(\""
2572 (regexp-quote group
) "\""))))))))))))
2575 ;;; Agent Category Mode
2578 (defvar gnus-category-mode-hook nil
2579 "Hook run in `gnus-category-mode' buffers.")
2581 (defvar gnus-category-line-format
" %(%20c%): %g\n"
2582 "Format of category lines.
2584 Valid specifiers include:
2585 %c Topic name (string)
2586 %g The number of groups in the topic (integer)
2588 General format specifiers can also be used. See Info node
2589 `(gnus)Formatting Variables'.")
2591 (defvar gnus-category-mode-line-format
"Gnus: %%b"
2592 "The format specification for the category mode line.")
2594 (defvar gnus-agent-predicate
'false
2595 "The selection predicate used when no other source is available.")
2598 ;;; Internal variables.
2600 (defvar gnus-category-buffer
"*Agent Category*")
2602 (defvar gnus-tmp-name
)
2603 (defvar gnus-tmp-groups
)
2605 (defvar gnus-category-line-format-alist
2606 `((?c gnus-tmp-name ?s
)
2607 (?g gnus-tmp-groups ?d
)))
2609 (defvar gnus-category-mode-line-format-alist
2610 `((?u user-defined ?s
)))
2612 (defvar gnus-category-line-format-spec nil
)
2613 (defvar gnus-category-mode-line-format-spec nil
)
2615 (defvar gnus-category-mode-map nil
)
2616 (put 'gnus-category-mode
'mode-class
'special
)
2618 (unless gnus-category-mode-map
2619 (setq gnus-category-mode-map
(make-sparse-keymap))
2620 (suppress-keymap gnus-category-mode-map
)
2622 (gnus-define-keys gnus-category-mode-map
2623 "q" gnus-category-exit
2624 "k" gnus-category-kill
2625 "c" gnus-category-copy
2626 "a" gnus-category-add
2627 "e" gnus-agent-customize-category
2628 "p" gnus-category-edit-predicate
2629 "g" gnus-category-edit-groups
2630 "s" gnus-category-edit-score
2631 "l" gnus-category-list
2633 "\C-c\C-i" gnus-info-find-node
2634 "\C-c\C-b" gnus-bug
))
2636 (defcustom gnus-category-menu-hook nil
2637 "Hook run after the creation of the menu."
2641 (defun gnus-category-make-menu-bar ()
2642 (gnus-turn-off-edit-menu 'category
)
2643 (unless (boundp 'gnus-category-menu
)
2645 gnus-category-menu gnus-category-mode-map
""
2647 ["Add" gnus-category-add t
]
2648 ["Kill" gnus-category-kill t
]
2649 ["Copy" gnus-category-copy t
]
2650 ["Edit category" gnus-agent-customize-category t
]
2651 ["Edit predicate" gnus-category-edit-predicate t
]
2652 ["Edit score" gnus-category-edit-score t
]
2653 ["Edit groups" gnus-category-edit-groups t
]
2654 ["Exit" gnus-category-exit t
]))
2656 (gnus-run-hooks 'gnus-category-menu-hook
)))
2658 (define-derived-mode gnus-category-mode fundamental-mode
"Category"
2659 "Major mode for listing and editing agent categories.
2661 All normal editing commands are switched off.
2662 \\<gnus-category-mode-map>
2663 For more in-depth information on this mode, read the manual
2664 \(`\\[gnus-info-find-node]').
2666 The following commands are available:
2668 \\{gnus-category-mode-map}"
2669 (when (gnus-visual-p 'category-menu
'menu
)
2670 (gnus-category-make-menu-bar))
2671 (gnus-simplify-mode-line)
2672 (gnus-set-default-directory)
2673 (setq mode-line-process nil
)
2674 (buffer-disable-undo)
2675 (setq truncate-lines t
)
2676 (setq buffer-read-only t
))
2678 (defalias 'gnus-category-position-point
'gnus-goto-colon
)
2680 (defun gnus-category-insert-line (category)
2681 (let* ((gnus-tmp-name (format "%s" (car category
)))
2682 (gnus-tmp-groups (length (gnus-agent-cat-groups category
))))
2684 (add-text-properties
2688 (eval gnus-category-line-format-spec
))
2689 (list 'gnus-category gnus-tmp-name
))))
2691 (defun gnus-enter-category-buffer ()
2692 "Go to the Category buffer."
2694 (gnus-category-setup-buffer)
2695 (gnus-configure-windows 'category
)
2696 (gnus-category-prepare))
2698 (defun gnus-category-setup-buffer ()
2699 (unless (get-buffer gnus-category-buffer
)
2700 (with-current-buffer (gnus-get-buffer-create gnus-category-buffer
)
2701 (gnus-category-mode))))
2703 (defun gnus-category-prepare ()
2704 (gnus-set-format 'category-mode
)
2705 (gnus-set-format 'category t
)
2706 (let ((alist gnus-category-alist
)
2707 (buffer-read-only nil
))
2710 (gnus-category-insert-line (pop alist
)))
2711 (goto-char (point-min))
2712 (gnus-category-position-point)))
2714 (defun gnus-category-name ()
2715 (or (intern (get-text-property (point-at-bol) 'gnus-category
))
2716 (error "No category on the current line")))
2718 (defun gnus-category-read ()
2719 "Read the category alist."
2720 (setq gnus-category-alist
2724 (nnheader-insert-file-contents (nnheader-concat gnus-agent-directory
"lib/categories"))
2725 (goto-char (point-min))
2726 ;; This code isn't temp, it will be needed so long as
2727 ;; anyone may be migrating from an older version.
2729 ;; Once we're certain that people will not revert to an
2730 ;; earlier version, we can take out the old-list code in
2731 ;; gnus-category-write.
2732 (let* ((old-list (read (current-buffer)))
2733 (new-list (ignore-errors (read (current-buffer)))))
2736 ;; Convert from a positional list to an alist.
2746 '(agent-predicate agent-score-file agent-groups
))))
2749 (list (gnus-agent-cat-make 'default
'short
)))))
2751 (defun gnus-category-write ()
2752 "Write the category alist."
2753 (setq gnus-category-predicate-cache nil
2754 gnus-category-group-cache nil
)
2755 (gnus-make-directory (nnheader-concat gnus-agent-directory
"lib"))
2756 (with-temp-file (nnheader-concat gnus-agent-directory
"lib/categories")
2757 ;; This prin1 is temporary. It exists so that people can revert
2758 ;; to an earlier version of gnus-agent.
2759 (prin1 (mapcar (lambda (c)
2761 (cdr (assoc 'agent-predicate c
))
2762 (cdr (assoc 'agent-score-file c
))
2763 (cdr (assoc 'agent-groups c
))))
2764 gnus-category-alist
)
2767 (prin1 gnus-category-alist
(current-buffer))))
2769 (defun gnus-category-edit-predicate (category)
2770 "Edit the predicate for CATEGORY."
2771 (interactive (list (gnus-category-name)))
2772 (let ((info (assq category gnus-category-alist
)))
2774 (gnus-agent-cat-predicate info
)
2775 (format "Editing the select predicate for category %s" category
)
2776 `(lambda (predicate)
2777 ;; Avoid run-time execution of setf form
2778 ;; (setf (gnus-agent-cat-predicate (assq ',category gnus-category-alist))
2780 ;; use its expansion instead:
2781 (gnus-agent-cat-set-property (assq ',category gnus-category-alist
)
2782 'agent-predicate predicate
)
2784 (gnus-category-write)
2785 (gnus-category-list)))))
2787 (defun gnus-category-edit-score (category)
2788 "Edit the score expression for CATEGORY."
2789 (interactive (list (gnus-category-name)))
2790 (let ((info (assq category gnus-category-alist
)))
2792 (gnus-agent-cat-score-file info
)
2793 (format "Editing the score expression for category %s" category
)
2794 `(lambda (score-file)
2795 ;; Avoid run-time execution of setf form
2796 ;; (setf (gnus-agent-cat-score-file (assq ',category gnus-category-alist))
2798 ;; use its expansion instead:
2799 (gnus-agent-cat-set-property (assq ',category gnus-category-alist
)
2800 'agent-score-file score-file
)
2802 (gnus-category-write)
2803 (gnus-category-list)))))
2805 (defun gnus-category-edit-groups (category)
2806 "Edit the group list for CATEGORY."
2807 (interactive (list (gnus-category-name)))
2808 (let ((info (assq category gnus-category-alist
)))
2810 (gnus-agent-cat-groups info
)
2811 (format "Editing the group list for category %s" category
)
2813 ;; Avoid run-time execution of setf form
2814 ;; (setf (gnus-agent-cat-groups (assq ',category gnus-category-alist))
2816 ;; use its expansion instead:
2817 (gnus-agent-set-cat-groups (assq ',category gnus-category-alist
)
2820 (gnus-category-write)
2821 (gnus-category-list)))))
2823 (defun gnus-category-kill (category)
2824 "Kill the current category."
2825 (interactive (list (gnus-category-name)))
2826 (let ((info (assq category gnus-category-alist
))
2827 (buffer-read-only nil
))
2829 (setq gnus-category-alist
(delq info gnus-category-alist
))
2830 (gnus-category-write)))
2832 (defun gnus-category-copy (category to
)
2833 "Copy the current category."
2834 (interactive (list (gnus-category-name) (intern (read-string "New name: "))))
2835 (let ((info (assq category gnus-category-alist
)))
2836 (push (let ((newcat (copy-tree info
)))
2837 (setf (gnus-agent-cat-name newcat
) to
)
2838 (setf (gnus-agent-cat-groups newcat
) nil
)
2840 gnus-category-alist
)
2841 (gnus-category-write)
2842 (gnus-category-list)))
2844 (defun gnus-category-add (category)
2845 "Create a new category."
2846 (interactive "SCategory name: ")
2847 (when (assq category gnus-category-alist
)
2848 (error "Category %s already exists" category
))
2849 (push (gnus-agent-cat-make category
)
2850 gnus-category-alist
)
2851 (gnus-category-write)
2852 (gnus-category-list))
2854 (defun gnus-category-list ()
2855 "List all categories."
2857 (gnus-category-prepare))
2859 (defun gnus-category-exit ()
2860 "Return to the group buffer."
2862 (kill-buffer (current-buffer))
2863 (gnus-configure-windows 'group t
))
2865 ;; To avoid having 8-bit characters in the source file.
2866 (defvar gnus-category-not
(list '! 'not
(intern (format "%c" 172))))
2868 (defvar gnus-category-predicate-alist
2869 '((spam . gnus-agent-spam-p
)
2870 (short . gnus-agent-short-p
)
2871 (long . gnus-agent-long-p
)
2872 (low . gnus-agent-low-scored-p
)
2873 (high . gnus-agent-high-scored-p
)
2874 (read . gnus-agent-read-p
)
2875 (true . gnus-agent-true
)
2876 (false . gnus-agent-false
))
2877 "Mapping from short score predicate symbols to predicate functions.")
2879 (defun gnus-agent-spam-p ()
2880 "Say whether an article is spam or not."
2881 (unless gnus-agent-spam-hashtb
2882 (setq gnus-agent-spam-hashtb
(gnus-make-hashtable 1000)))
2883 (if (not (equal (mail-header-references gnus-headers
) ""))
2885 (let ((string (gnus-simplify-subject (mail-header-subject gnus-headers
))))
2887 (gnus-gethash string gnus-agent-spam-hashtb
)
2888 (gnus-sethash string t gnus-agent-spam-hashtb
)))))
2890 (defun gnus-agent-short-p ()
2891 "Say whether an article is short or not."
2892 (< (mail-header-lines gnus-headers
) gnus-agent-short-article
))
2894 (defun gnus-agent-long-p ()
2895 "Say whether an article is long or not."
2896 (> (mail-header-lines gnus-headers
) gnus-agent-long-article
))
2898 (defun gnus-agent-low-scored-p ()
2899 "Say whether an article has a low score or not."
2900 (< gnus-score gnus-agent-low-score
))
2902 (defun gnus-agent-high-scored-p ()
2903 "Say whether an article has a high score or not."
2904 (> gnus-score gnus-agent-high-score
))
2906 (defun gnus-agent-read-p ()
2907 "Say whether an article is read or not."
2908 (gnus-member-of-range (mail-header-number gnus-headers
)
2909 (gnus-info-read (gnus-get-info gnus-newsgroup-name
))))
2911 (defun gnus-category-make-function (predicate)
2912 "Make a function from PREDICATE."
2913 (let ((func (gnus-category-make-function-1 predicate
)))
2914 (if (and (= (length func
) 1)
2915 (symbolp (car func
)))
2917 (gnus-byte-compile `(lambda () ,func
)))))
2919 (defun gnus-agent-true ()
2923 (defun gnus-agent-false ()
2927 (defun gnus-category-make-function-1 (predicate)
2928 "Make a function from PREDICATE."
2930 ;; Functions are just returned as is.
2931 ((or (symbolp predicate
)
2932 (functionp predicate
))
2933 `(,(or (cdr (assq predicate gnus-category-predicate-alist
))
2935 ;; More complex predicate.
2938 ((memq (car predicate
) '(& and
))
2940 ((memq (car predicate
) '(| or
))
2942 ((memq (car predicate
) gnus-category-not
)
2944 ,@(mapcar 'gnus-category-make-function-1
(cdr predicate
))))
2946 (error "Unknown predicate type: %s" predicate
))))
2948 (defun gnus-get-predicate (predicate)
2949 "Return the function implementing PREDICATE."
2950 (or (cdr (assoc predicate gnus-category-predicate-cache
))
2951 (let ((func (gnus-category-make-function predicate
)))
2952 (push (cons predicate func
) gnus-category-predicate-cache
)
2955 (defun gnus-predicate-implies-unread (predicate)
2956 "Say whether PREDICATE implies unread articles only.
2957 It is okay to miss some cases, but there must be no false positives.
2958 That is, if this predicate returns true, then indeed the predicate must
2959 return only unread articles."
2960 (eq t
(gnus-function-implies-unread-1
2961 (gnus-category-make-function-1 predicate
))))
2963 (defun gnus-function-implies-unread-1 (function)
2964 "Recursively evaluate a predicate function to determine whether it can select
2965 any read articles. Returns t if the function is known to never
2966 return read articles, nil when it is known to always return read
2967 articles, and t_nil when the function may return both read and unread
2969 (let ((func (car function
))
2970 (args (mapcar 'gnus-function-implies-unread-1
(cdr function
))))
2971 (cond ((eq func
'and
)
2972 (cond ((memq t args
) ; if any argument returns only unread articles
2973 ;; then that argument constrains the result to only unread articles.
2975 ((memq 't_nil args
) ; if any argument is indeterminate
2976 ;; then the result is indeterminate
2979 (cond ((memq nil args
) ; if any argument returns read articles
2980 ;; then that argument ensures that the results includes read articles.
2982 ((memq 't_nil args
) ; if any argument is indeterminate
2983 ;; then that argument ensures that the results are indeterminate
2985 (t ; if all arguments return only unread articles
2986 ;; then the result returns only unread articles
2989 (cond ((eq (car args
) 't_nil
) ; if the argument is indeterminate
2990 ; then the result is indeterminate
2993 ; toggle the result to be the opposite of the argument
2995 ((eq func
'gnus-agent-read-p
)
2996 nil
) ; The read predicate NEVER returns unread articles
2997 ((eq func
'gnus-agent-false
)
2998 t
) ; The false predicate returns t as the empty set excludes all read articles
2999 ((eq func
'gnus-agent-true
)
3000 nil
) ; The true predicate ALWAYS returns read articles
3001 ((catch 'found-match
3002 (let ((alist gnus-category-predicate-alist
))
3004 (if (eq func
(cdar alist
))
3005 (throw 'found-match t
)
3006 (setq alist
(cdr alist
))))))
3007 't_nil
) ; All other predicates return read and unread articles
3009 (error "Unknown predicate function: %s" function
)))))
3011 (defun gnus-group-category (group)
3012 "Return the category GROUP belongs to."
3013 (unless gnus-category-group-cache
3014 (setq gnus-category-group-cache
(gnus-make-hashtable 1000))
3015 (let ((cs gnus-category-alist
)
3017 (while (setq cat
(pop cs
))
3018 (setq groups
(gnus-agent-cat-groups cat
))
3020 (gnus-sethash (pop groups
) cat gnus-category-group-cache
)))))
3021 (or (gnus-gethash group gnus-category-group-cache
)
3022 (assq 'default gnus-category-alist
)))
3024 (defvar gnus-agent-expire-current-dirs
)
3025 (defvar gnus-agent-expire-stats
)
3027 (defun gnus-agent-expire-group (group &optional articles force
)
3028 "Expire all old articles in GROUP.
3029 If you want to force expiring of certain articles, this function can
3030 take ARTICLES, and FORCE parameters as well.
3032 The articles on which the expiration process runs are selected as follows:
3033 if ARTICLES is null, all read and unmarked articles.
3034 if ARTICLES is t, all articles.
3035 if ARTICLES is a list, just those articles.
3036 FORCE is equivalent to setting the expiration predicates to true."
3037 (interactive (list (gnus-agent-read-group)))
3040 (gnus-agent-expire articles group force
)
3041 (let (;; Bind gnus-agent-expire-stats to enable tracking of
3042 ;; expiration statistics of this single group
3043 (gnus-agent-expire-stats (list 0 0 0.0)))
3044 (if (or (not (eq articles t
))
3046 (concat "Are you sure that you want to "
3047 "expire all articles in " group
"? ")))
3048 (let ((gnus-command-method (gnus-find-method-for-group group
))
3049 (overview (gnus-get-buffer-create " *expire overview*"))
3052 (let ((active-file (gnus-agent-lib-file "active")))
3053 (when (file-exists-p active-file
)
3055 (nnheader-insert-file-contents active-file
)
3056 (gnus-active-to-gnus-format
3058 (setq orig
(gnus-make-hashtable
3059 (count-lines (point-min) (point-max))))))
3061 (gnus-agent-expire-group-1
3062 group overview
(gnus-gethash-safe group orig
)
3064 (kill-buffer overview
))))
3065 (gnus-message 4 "%s" (gnus-agent-expire-done-message)))))
3067 (defun gnus-agent-expire-group-1 (group overview active articles force
)
3068 ;; Internal function - requires caller to have set
3069 ;; gnus-command-method, initialized overview buffer, and to have
3070 ;; provided a non-nil active
3072 (let ((dir (gnus-agent-group-pathname group
))
3073 (file-name-coding-system nnmail-pathname-coding-system
)
3074 (decoded (gnus-agent-decoded-group-name group
)))
3075 (gnus-agent-with-refreshed-group
3077 (when (boundp 'gnus-agent-expire-current-dirs
)
3078 (push dir gnus-agent-expire-current-dirs
))
3080 (if (and (not force
)
3081 (eq 'DISABLE
(gnus-agent-find-parameter group
3082 'agent-enable-expiration
)))
3083 (gnus-message 5 "Expiry skipping over %s" decoded
)
3084 (gnus-message 5 "Expiring articles in %s" decoded
)
3085 (gnus-agent-load-alist group
)
3086 (let* ((bytes-freed 0)
3087 (size-files-deleted 0.0)
3089 (nov-entries-deleted 0)
3090 (info (gnus-get-info group
))
3091 (alist gnus-agent-article-alist
)
3092 (day (- (time-to-days nil
)
3093 (gnus-agent-find-parameter group
'agent-days-until-old
)))
3094 (specials (if (and alist
3096 ;; This could be a bit of a problem. I need to
3097 ;; keep the last article to avoid refetching
3098 ;; headers when using nntp in the backend. At
3099 ;; the same time, if someone uses a backend
3100 ;; that supports article moving then I may have
3101 ;; to remove the last article to complete the
3102 ;; move. Right now, I'm going to assume that
3103 ;; FORCE overrides specials.
3104 (list (caar (last alist
)))))
3105 (unreads ;; Articles that are excluded from the
3106 ;; expiration process
3107 (cond (gnus-agent-expire-all
3108 ;; All articles are marked read by global decree
3111 ;; All articles are marked read by function
3115 ;; Unread articles are marked protected from
3116 ;; expiration Don't call
3117 ;; gnus-list-of-unread-articles as it returns
3118 ;; articles that have not been fetched into the
3121 (gnus-agent-unread-articles group
)))
3123 ;; All articles EXCEPT those named by the caller
3124 ;; are protected from expiration
3125 (gnus-sorted-difference
3126 (gnus-uncompress-range
3128 (caar (last alist
))))
3129 (sort articles
'<)))))
3130 (marked ;; More articles that are excluded from the
3131 ;; expiration process
3132 (cond (gnus-agent-expire-all
3133 ;; All articles are unmarked by global decree
3136 ;; All articles are unmarked by function
3140 ;; All articles may as well be unmarked as the
3141 ;; unreads list already names the articles we are
3145 ;; Ticked and/or dormant articles are excluded
3148 (gnus-uncompress-range
3149 (cdr (assq 'tick
(gnus-info-marks info
))))
3150 (gnus-uncompress-range
3152 (gnus-info-marks info
))))))))
3153 (nov-file (concat dir
".overview"))
3159 ;; The normal article alist contains elements that look like
3160 ;; (article# . fetch_date) I need to combine other
3161 ;; information with this list. For example, a flag indicating
3162 ;; that a particular article MUST BE KEPT. To do this, I'm
3163 ;; going to transform the elements to look like (article#
3164 ;; fetch_date keep_flag NOV_entry_position) Later, I'll reverse
3165 ;; the process to generate the expired article alist.
3167 ;; Convert the alist elements to (article# fetch_date nil
3169 (setq dlist
(mapcar (lambda (e)
3170 (list (car e
) (cdr e
) nil nil
)) alist
))
3172 ;; Convert the keep lists to elements that look like (article#
3173 ;; nil keep_flag nil) then append it to the expanded dlist
3174 ;; These statements are sorted by ascending precedence of the
3176 (setq dlist
(nconc dlist
3178 (list e nil
'unread nil
))
3180 (setq dlist
(nconc dlist
3182 (list e nil
'marked nil
))
3184 (setq dlist
(nconc dlist
3186 (list e nil
'special nil
))
3189 (set-buffer overview
)
3191 (buffer-disable-undo)
3192 (when (file-exists-p nov-file
)
3193 (gnus-message 7 "gnus-agent-expire: Loading overview...")
3194 (nnheader-insert-file-contents nov-file
)
3195 (goto-char (point-min))
3198 (while (< (setq p
(point)) (point-max))
3200 ;; If I successfully read an integer (the plus zero
3201 ;; ensures a numeric type), append the position
3203 (push (list (+ 0 (read (current-buffer))) nil nil
3207 (gnus-message 1 "gnus-agent-expire: read error \
3208 occurred when reading expression at %s in %s. Skipping to next \
3209 line." (point) nov-file
)))
3210 ;; Whether I succeeded, or failed, it doesn't matter.
3211 ;; Move to the next line then try again.
3215 7 "gnus-agent-expire: Loading overview... Done"))
3216 (set-buffer-modified-p nil
)
3218 ;; At this point, all of the information is in dlist. The
3219 ;; only problem is that much of it is spread across multiple
3220 ;; entries. Sort then MERGE!!
3221 (gnus-message 7 "gnus-agent-expire: Sorting entries... ")
3225 (cond ((< (nth 0 a
) (nth 0 b
))
3227 ((> (nth 0 a
) (nth 0 b
))
3230 ;; If two entries have the same article-number
3231 ;; then sort by ascending keep_flag.
3232 (let* ((kf-score '((special .
0)
3235 (a (or (cdr (assq (nth 2 a
) kf-score
))
3237 (b (or (cdr (assq (nth 2 b
) kf-score
))
3240 (gnus-message 7 "gnus-agent-expire: Sorting entries... Done")
3241 (gnus-message 7 "gnus-agent-expire: Merging entries... ")
3242 (let ((dlist dlist
))
3243 (while (cdr dlist
) ; I'm not at the end-of-list
3244 (if (eq (caar dlist
) (caadr dlist
))
3245 (let ((first (cdr (car dlist
)))
3246 (secnd (cdr (cadr dlist
))))
3247 (setcar first
(or (car first
)
3248 (car secnd
))) ; fetch_date
3249 (setq first
(cdr first
)
3251 (setcar first
(or (car first
)
3252 (car secnd
))) ; Keep_flag
3253 (setq first
(cdr first
)
3255 (setcar first
(or (car first
)
3256 (car secnd
))) ; NOV_entry_position
3258 (setcdr dlist
(cddr dlist
)))
3259 (setq dlist
(cdr dlist
)))))
3261 ;; Check the order of the entry positions. They should be in
3262 ;; ascending order. If they aren't, the positions must be
3263 ;; converted to markers.
3264 (when (catch 'sort-results
3269 (if (setq pos
(nth 3 (pop dlist
)))
3270 (if (< pos prev-pos
)
3271 (throw 'sort-results
'unsorted
)
3272 (setq prev-pos pos
))))))
3273 (gnus-message 7 "gnus-agent-expire: Unsorted overview; inserting markers to compensate.")
3274 (mapc (lambda (entry)
3275 (let ((pos (nth 3 entry
)))
3278 (set-marker (make-marker)
3282 (gnus-message 7 "gnus-agent-expire: Merging entries... Done")
3284 (let* ((len (float (length dlist
)))
3291 (let ((new-completed (truncate (* 100.0
3292 (/ (setq cnt
(1+ cnt
))
3295 (when (> new-completed completed
)
3296 (setq completed new-completed
)
3297 (gnus-message 7 "%3d%% completed..." completed
)))
3298 (let* ((entry (car dlist
))
3299 (article-number (nth 0 entry
))
3300 (fetch-date (nth 1 entry
))
3301 (keep (nth 2 entry
))
3302 (marker (nth 3 entry
)))
3305 ;; Kept articles are unread, marked, or special.
3307 (gnus-agent-message 10
3308 "gnus-agent-expire: %s:%d: Kept %s article%s."
3309 decoded article-number keep
(if fetch-date
" and file" ""))
3311 (unless (file-exists-p
3312 (concat dir
(number-to-string
3314 (setf (nth 1 entry
) nil
)
3315 (gnus-agent-message 3 "gnus-agent-expire cleared \
3316 download flag on %s:%d as the cached article file is missing."
3317 decoded
(caar dlist
)))
3319 (gnus-message 1 "gnus-agent-expire detected a \
3320 missing NOV entry. Run gnus-agent-regenerate-group to restore it.")))
3321 (gnus-agent-append-to-list
3323 (cons article-number fetch-date
)))
3325 ;; The following articles are READ, UNMARKED, and
3326 ;; ORDINARY. See if they can be EXPIRED!!!
3329 ((not (integerp fetch-date
))
3330 'read
) ;; never fetched article (may expire
3332 ((not (file-exists-p
3333 (concat dir
(number-to-string
3335 (setf (nth 1 entry
) nil
)
3336 'externally-expired
) ;; Can't find the cached
3337 ;; article. Handle case
3338 ;; as though this article
3339 ;; was never fetched.
3341 ;; We now have the arrival day, so we see
3342 ;; whether it's old enough to be expired.
3348 ;; I found some reason to expire this entry.
3350 (let ((actions nil
))
3351 (when (memq type
'(forced expired
))
3352 (ignore-errors ; Just being paranoid.
3353 (let* ((file-name (nnheader-concat dir
(number-to-string
3355 (size (float (file-attribute-size
3356 (file-attributes file-name
)))))
3357 (cl-incf bytes-freed size
)
3358 (cl-incf size-files-deleted size
)
3359 (cl-incf files-deleted
)
3360 (delete-file file-name
))
3361 (push "expired cached article" actions
))
3362 (setf (nth 1 entry
) nil
)
3366 (push "NOV entry removed" actions
)
3368 (goto-char (if (markerp marker
)
3370 (- marker position-offset
)))
3372 (cl-incf nov-entries-deleted
)
3374 (let* ((from (point-at-bol))
3375 (to (progn (forward-line 1) (point)))
3376 (freed (- to from
)))
3377 (cl-incf bytes-freed freed
)
3378 (cl-incf position-offset freed
)
3379 (delete-region from to
)))
3381 ;; If considering all articles is set, I can only
3382 ;; expire article IDs that are no longer in the
3383 ;; active range (That is, articles that precede the
3384 ;; first article in the new alist).
3385 (if (and gnus-agent-consider-all-articles
3386 (>= article-number
(car active
)))
3387 ;; I have to keep this ID in the alist
3388 (gnus-agent-append-to-list
3389 tail-alist
(cons article-number fetch-date
))
3390 (push (format "Removed %s article number from \
3391 article alist" type
) actions
))
3394 (gnus-agent-message 8 "gnus-agent-expire: %s:%d: %s"
3395 decoded article-number
3396 (mapconcat 'identity actions
", ")))))
3399 10 "gnus-agent-expire: %s:%d: Article kept as \
3400 expiration tests failed." decoded article-number
)
3401 (gnus-agent-append-to-list
3402 tail-alist
(cons article-number fetch-date
)))
3405 ;; Remove markers as I intend to reuse this buffer again.
3408 (set-marker marker nil
))
3410 (setq dlist
(cdr dlist
))))
3412 (setq alist
(cdr alist
))
3414 (let ((inhibit-quit t
))
3415 (unless (equal alist gnus-agent-article-alist
)
3416 (setq gnus-agent-article-alist alist
)
3417 (gnus-agent-save-alist group
))
3419 (when (buffer-modified-p)
3420 (let ((coding-system-for-write
3421 gnus-agent-file-coding-system
))
3422 (gnus-make-directory dir
)
3423 (write-region (point-min) (point-max) nov-file nil
3425 ;; clear the modified flag as that I'm not confused by
3426 ;; its status on the next pass through this routine.
3427 (set-buffer-modified-p nil
)
3428 (gnus-agent-update-view-total-fetched-for group t
)))
3430 (when (eq articles t
)
3431 (gnus-summary-update-info))))
3433 (when (boundp 'gnus-agent-expire-stats
)
3434 (let ((stats gnus-agent-expire-stats
))
3435 (cl-incf (nth 2 stats
) bytes-freed
)
3436 (cl-incf (nth 1 stats
) files-deleted
)
3437 (cl-incf (nth 0 stats
) nov-entries-deleted
)))
3439 (gnus-agent-update-files-total-fetched-for group
(- size-files-deleted
)))))))
3441 (defun gnus-agent-expire (&optional articles group force
)
3442 "Expire all old articles.
3443 If you want to force expiring of certain articles, this function can
3444 take ARTICLES, GROUP and FORCE parameters as well.
3446 The articles on which the expiration process runs are selected as follows:
3447 if ARTICLES is null, all read and unmarked articles.
3448 if ARTICLES is t, all articles.
3449 if ARTICLES is a list, just those articles.
3450 Setting GROUP will limit expiration to that group.
3451 FORCE is equivalent to setting the expiration predicates to true."
3455 (gnus-agent-expire-group group articles force
)
3456 (if (or (not (eq articles t
))
3457 (yes-or-no-p "Are you sure that you want to expire all \
3458 articles in every agentized group? "))
3459 (let ((methods (gnus-agent-covered-methods))
3460 ;; Bind gnus-agent-expire-current-dirs to enable tracking
3461 ;; of agent directories.
3462 (gnus-agent-expire-current-dirs nil
)
3463 ;; Bind gnus-agent-expire-stats to enable tracking of
3464 ;; expiration statistics across all groups
3465 (gnus-agent-expire-stats (list 0 0 0.0))
3466 gnus-command-method overview orig
)
3467 (setq overview
(gnus-get-buffer-create " *expire overview*"))
3469 (while (setq gnus-command-method
(pop methods
))
3470 (let ((active-file (gnus-agent-lib-file "active")))
3471 (when (file-exists-p active-file
)
3473 (nnheader-insert-file-contents active-file
)
3474 (gnus-active-to-gnus-format
3476 (setq orig
(gnus-make-hashtable
3477 (count-lines (point-min) (point-max))))))
3478 (dolist (expiring-group (gnus-groups-from-server
3479 gnus-command-method
))
3481 (gnus-gethash-safe expiring-group orig
)))
3485 (gnus-agent-expire-group-1
3486 expiring-group overview active articles force
))))))))
3487 (kill-buffer overview
))
3488 (gnus-agent-expire-unagentized-dirs)
3489 (gnus-message 4 "%s" (gnus-agent-expire-done-message))))))
3491 (defun gnus-agent-expire-done-message ()
3492 (if (and (> gnus-verbose
4)
3493 (boundp 'gnus-agent-expire-stats
))
3494 (let* ((stats gnus-agent-expire-stats
)
3495 (size (nth 2 stats
))
3496 (units '(B KB MB GB
)))
3497 (while (and (> size
1024.0)
3499 (setq size
(/ size
1024.0)
3502 (format "Expiry recovered %d NOV entries, deleted %d files,\
3509 (defun gnus-agent-expire-unagentized-dirs ()
3510 (when (and gnus-agent-expire-unagentized-dirs
3511 (boundp 'gnus-agent-expire-current-dirs
))
3512 (let* ((keep (gnus-make-hashtable))
3513 (file-name-coding-system nnmail-pathname-coding-system
))
3515 (gnus-sethash gnus-agent-directory t keep
)
3516 (dolist (dir gnus-agent-expire-current-dirs
)
3517 (when (and (stringp dir
)
3518 (file-directory-p dir
))
3519 (while (not (gnus-gethash dir keep
))
3520 (gnus-sethash dir t keep
)
3521 (setq dir
(file-name-directory (directory-file-name dir
))))))
3528 "Given a directory, check it and its subdirectories for
3529 membership in the keep hash. If it isn't found, add
3531 (let ((files (directory-files d
))
3533 (while (setq file
(pop files
))
3534 (cond ((equal file
".") ; Ignore self
3536 ((equal file
"..") ; Ignore parent
3538 ((equal file
".overview")
3539 ;; Directory must contain .overview to be
3540 ;; agent's cache of a group.
3541 (let ((d (file-name-as-directory d
))
3543 ;; Search ancestor's for last directory NOT
3544 ;; found in keep hash.
3545 (while (not (gnus-gethash
3546 (setq d
(file-name-directory d
)) keep
))
3548 d
(directory-file-name d
)))
3549 ;; if ANY ancestor was NOT in keep hash and
3550 ;; it's not already in to-remove, add it to
3553 (not (member r to-remove
)))
3554 (push r to-remove
))))
3555 ((file-directory-p (setq file
(nnheader-concat d file
)))
3556 (funcall checker file
)))))))))
3557 (funcall checker
(expand-file-name gnus-agent-directory
))
3559 (when (and to-remove
3560 (or gnus-expert-user
3562 "gnus-agent-expire has identified local directories that are\
3563 not currently required by any agentized group. Do you wish to consider\
3566 (let ((dir (pop to-remove
)))
3567 (if (or gnus-expert-user
3568 (gnus-y-or-n-p (format "Delete %s? " dir
)))
3569 (let* (delete-recursive
3575 (if (file-directory-p f-or-d
)
3577 (delete-directory f-or-d
)
3579 (setq files
(directory-files f-or-d
))
3581 (setq f
(pop files
))
3582 (or (member f
'("." ".."))
3583 (funcall delete-recursive
3586 (delete-directory f-or-d
)))
3587 (delete-file f-or-d
)))))))
3588 (funcall delete-recursive dir
))))))))))
3591 (defun gnus-agent-batch ()
3592 "Start Gnus, send queue and fetch session."
3594 (let ((init-file-user "")
3595 (gnus-always-read-dribble-file t
))
3597 (let ((gnus-agent-confirmation-function 'gnus-agent-batch-confirmation
))
3598 (gnus-group-send-queue)
3599 (gnus-agent-fetch-session)))
3601 (defun gnus-agent-unread-articles (group)
3602 (let* ((read (gnus-info-read (gnus-get-info group
)))
3603 (known (gnus-agent-load-alist group
))
3605 (tail-unread unread
))
3606 (while (and known read
)
3607 (let ((candidate (car (pop known
))))
3608 (while (let* ((range (car read
))
3609 (min (if (numberp range
) range
(car range
)))
3610 (max (if (numberp range
) range
(cdr range
))))
3611 (cond ((or (not min
)
3613 (gnus-agent-append-to-list tail-unread candidate
)
3616 (setq read
(cdr read
))
3617 ;; return t so that I always loop one more
3618 ;; time. If I just iterated off the end of
3619 ;; read, min will become nil and the current
3620 ;; candidate will be added to the unread list.
3623 (gnus-agent-append-to-list tail-unread
(car (pop known
))))
3626 (defun gnus-agent-uncached-articles (articles group
&optional cached-header
)
3627 "Restrict ARTICLES to numbers already fetched.
3628 Returns a sublist of ARTICLES that excludes those article ids in GROUP
3629 that have already been fetched.
3630 If CACHED-HEADER is nil, articles are only excluded if the article itself
3633 ;; Logically equivalent to: (gnus-sorted-difference articles (mapcar
3634 ;; 'car gnus-agent-article-alist))
3636 ;; Functionally, I don't need to construct a temp list using mapcar.
3638 (if (and (or gnus-agent-cache
(not gnus-plugged
))
3639 (gnus-agent-load-alist group
))
3640 (let* ((ref gnus-agent-article-alist
)
3642 (uncached (list nil
))
3643 (tail-uncached uncached
))
3644 (while (and ref arts
)
3645 (let ((v1 (car arts
))
3647 (cond ((< v1 v2
) ; v1 does not appear in the reference list
3648 (gnus-agent-append-to-list tail-uncached v1
)
3649 (setq arts
(cdr arts
)))
3651 (unless (or cached-header
(cdar ref
)) ; v1 is already cached
3652 (gnus-agent-append-to-list tail-uncached v1
))
3653 (setq arts
(cdr arts
))
3654 (setq ref
(cdr ref
)))
3655 (t ; reference article (v2) precedes the list being filtered
3656 (setq ref
(cdr ref
))))))
3658 (gnus-agent-append-to-list tail-uncached
(pop arts
)))
3660 ;; if gnus-agent-load-alist fails, no articles are cached.
3663 (defun gnus-agent-retrieve-headers (articles group
&optional fetch-old
)
3665 (gnus-agent-create-buffer)
3666 (let ((gnus-decode-encoded-word-function 'identity
)
3667 (gnus-decode-encoded-address-function 'identity
)
3668 (file (gnus-agent-article-name ".overview" group
))
3670 (file-name-coding-system nnmail-pathname-coding-system
))
3671 (gnus-make-directory (nnheader-translate-file-chars
3672 (file-name-directory file
) t
))
3675 (setq articles
(gnus-uncompress-range
3676 (cons (if (numberp fetch-old
)
3677 (max 1 (- (car articles
) fetch-old
))
3679 (car (last articles
))))))
3681 ;; Populate temp buffer with known headers
3682 (when (file-exists-p file
)
3683 (with-current-buffer gnus-agent-overview-buffer
3685 (let ((nnheader-file-coding-system
3686 gnus-agent-file-coding-system
))
3687 (nnheader-insert-nov-file file
(car articles
)))))
3689 (if (setq uncached-articles
(gnus-agent-uncached-articles articles group
3692 ;; Populate nntp-server-buffer with uncached headers
3693 (set-buffer nntp-server-buffer
)
3695 (cond ((not (eq 'nov
(let (gnus-agent) ; Turn off agent
3696 (gnus-retrieve-headers
3697 uncached-articles group
))))
3698 (nnvirtual-convert-headers))
3699 ((eq 'nntp
(car gnus-current-select-method
))
3700 ;; The author of gnus-get-newsgroup-headers-xover
3701 ;; reports that the XOVER command is commonly
3702 ;; unreliable. The problem is that recently
3703 ;; posted articles may not be entered into the
3704 ;; NOV database in time to respond to my XOVER
3707 ;; I'm going to use his assumption that the NOV
3708 ;; database is updated in order of ascending
3709 ;; article ID. Therefore, a response containing
3710 ;; article ID N implies that all articles from 1
3711 ;; to N-1 are up-to-date. Therefore, missing
3712 ;; articles in that range have expired.
3714 (set-buffer nntp-server-buffer
)
3715 (let* ((fetched-articles (list nil
))
3716 (tail-fetched-articles fetched-articles
)
3717 (min (car articles
))
3718 (max (car (last articles
))))
3720 ;; Get the list of articles that were fetched
3721 (goto-char (point-min))
3722 (let ((pm (point-max))
3724 (while (< (point) pm
)
3725 (when (setq art
(gnus-agent-read-article-number))
3726 (gnus-agent-append-to-list tail-fetched-articles art
))
3729 ;; Clip this list to the headers that will
3730 ;; actually be returned
3731 (setq fetched-articles
(gnus-list-range-intersection
3732 (cdr fetched-articles
)
3735 ;; Clip the uncached articles list to exclude
3736 ;; IDs after the last FETCHED header. The
3737 ;; excluded IDs may be fetchable using HEAD.
3738 (if (car tail-fetched-articles
)
3739 (setq uncached-articles
3740 (gnus-list-range-intersection
3742 (cons (car uncached-articles
)
3743 (car tail-fetched-articles
)))))
3745 ;; Create the list of articles that were
3746 ;; "successfully" fetched. Success, in this
3747 ;; case, means that the ID should not be
3748 ;; fetched again. In the case of an expired
3749 ;; article, the header will not be fetched.
3750 (setq uncached-articles
3751 (gnus-sorted-nunion fetched-articles
3755 ;; Erase the temp buffer
3756 (set-buffer gnus-agent-overview-buffer
)
3759 ;; Copy the nntp-server-buffer to the temp buffer
3760 (set-buffer nntp-server-buffer
)
3761 (copy-to-buffer gnus-agent-overview-buffer
(point-min) (point-max))
3763 ;; Merge the temp buffer with the known headers (found on
3764 ;; disk in FILE) into the nntp-server-buffer
3765 (when uncached-articles
3766 (gnus-agent-braid-nov uncached-articles file
))
3768 ;; Save the new set of known headers to FILE
3769 (set-buffer nntp-server-buffer
)
3770 (let ((coding-system-for-write
3771 gnus-agent-file-coding-system
))
3772 (gnus-agent-check-overview-buffer)
3773 (write-region (point-min) (point-max) file nil
'silent
))
3775 (gnus-agent-update-view-total-fetched-for group t
)
3777 ;; Update the group's article alist to include the newly
3778 ;; fetched articles.
3779 (gnus-agent-load-alist group
)
3780 (gnus-agent-save-alist group uncached-articles nil
)
3783 ;; Copy the temp buffer to the nntp-server-buffer
3784 (set-buffer nntp-server-buffer
)
3786 (insert-buffer-substring gnus-agent-overview-buffer
)))
3789 (not (numberp fetch-old
)))
3790 t
; Don't remove anything.
3791 (nnheader-nov-delete-outside-range
3793 (car (last articles
)))
3798 (defun gnus-agent-request-article (article group
)
3799 "Retrieve ARTICLE in GROUP from the agent cache."
3800 (when (and gnus-agent
3801 (or gnus-agent-cache
3804 (let* ((gnus-command-method (gnus-find-method-for-group group
))
3805 (file (gnus-agent-article-name (number-to-string article
) group
))
3806 (buffer-read-only nil
)
3807 (file-name-coding-system nnmail-pathname-coding-system
))
3808 (when (and (file-exists-p file
)
3809 (> (file-attribute-size (file-attributes file
)) 0))
3811 (gnus-kill-all-overlays)
3812 (let ((coding-system-for-read gnus-cache-coding-system
))
3813 (insert-file-contents file
))
3816 (defun gnus-agent-store-article (article group
)
3817 (let* ((gnus-command-method (gnus-find-method-for-group group
))
3818 (file (gnus-agent-article-name (number-to-string article
) group
))
3819 (file-name-coding-system nnmail-pathname-coding-system
)
3820 (coding-system-for-write gnus-cache-coding-system
))
3821 (when (not (file-exists-p file
))
3822 (gnus-make-directory (file-name-directory file
))
3823 (write-region (point-min) (point-max) file nil
'silent
)
3824 ;; Tell the Agent when the article was fetched, so that it can
3825 ;; be expired later.
3826 (gnus-agent-load-alist group
)
3827 (gnus-agent-save-alist group
(list article
)
3828 (time-to-days nil
)))))
3830 (defun gnus-agent-regenerate-group (group &optional reread
)
3832 If REREAD is t, all articles in the .overview are marked as unread.
3833 If REREAD is a list, the specified articles will be marked as unread.
3834 In addition, their NOV entries in .overview will be refreshed using
3835 the articles' current headers.
3836 If REREAD is not nil, downloaded articles are marked as unread."
3838 (list (gnus-agent-read-group)
3841 (cursor-in-echo-area t
)
3842 (echo-keystrokes 0))
3843 (message "Mark as unread: (n)one / (a)ll / all (d)ownloaded articles? (n) ")
3844 (setq c
(read-char-exclusive))
3846 (cond ((or (eq c ?
\r) (eq c ?n
) (eq c ?N
))
3848 ((or (eq c ?a
) (eq c ?A
))
3850 ((or (eq c ?d
) (eq c ?D
))
3851 (throw 'mark
'some
)))
3852 (gnus-message 3 "Ignoring unexpected input")
3856 (gnus-message 5 "Regenerating in %s" (gnus-agent-decoded-group-name group
))
3857 (let* ((gnus-command-method (or gnus-command-method
3858 (gnus-find-method-for-group group
)))
3859 (file (gnus-agent-article-name ".overview" group
))
3860 (dir (file-name-directory file
))
3861 (file-name-coding-system nnmail-pathname-coding-system
)
3862 (downloaded (if (file-exists-p dir
)
3863 (sort (delq nil
(mapcar (lambda (name)
3864 (and (not (file-directory-p (nnheader-concat dir name
)))
3865 (string-to-number name
)))
3866 (directory-files dir nil
"^[0-9]+$" t
)))
3868 (progn (gnus-make-directory dir
) nil
)))
3873 (mm-with-unibyte-buffer
3874 (if (file-exists-p file
)
3875 (let ((nnheader-file-coding-system
3876 gnus-agent-file-coding-system
))
3877 (nnheader-insert-file-contents file
)))
3878 (set-buffer-modified-p nil
)
3880 ;; Load the article IDs found in the overview file. As a
3881 ;; side-effect, validate the file contents.
3885 (goto-char (point-min))
3886 (while (< (point) (point-max))
3887 (cond ((and (looking-at "[0-9]+\t")
3888 (<= (- (match-end 0) (match-beginning 0)) 9))
3889 (push (read (current-buffer)) nov-arts
)
3891 (let ((l1 (car nov-arts
))
3892 (l2 (cadr nov-arts
)))
3893 (cond ((and (listp reread
) (memq l1 reread
))
3895 (setq nov-arts
(cdr nov-arts
))
3896 (gnus-message 4 "gnus-agent-regenerate-group: NOV\
3897 entry of article %s deleted." l1
))
3901 (gnus-message 3 "gnus-agent-regenerate-group: NOV\
3902 entries are NOT in ascending order.")
3903 ;; Don't sort now as I haven't verified
3904 ;; that every line begins with a number
3908 (gnus-message 4 "gnus-agent-regenerate-group: NOV\
3909 entries contained duplicate of article %s. Duplicate deleted." l1
)
3911 (setq nov-arts
(cdr nov-arts
))))))
3913 (gnus-message 1 "gnus-agent-regenerate-group: NOV\
3914 entries contained line that did not begin with an article number. Deleted\
3916 (gnus-delete-line))))
3918 (gnus-message 5 "gnus-agent-regenerate-group: Sorting NOV\
3919 entries into ascending order.")
3920 (sort-numeric-fields 1 (point-min) (point-max))
3921 (setq nov-arts nil
))))
3922 (gnus-agent-check-overview-buffer)
3924 ;; Construct a new article alist whose nodes match every header
3925 ;; in the .overview file. As a side-effect, missing headers are
3926 ;; reconstructed from the downloaded article file.
3927 (while (or downloaded nov-arts
)
3928 (cond ((and downloaded
3930 (> (car downloaded
) (car nov-arts
))))
3931 ;; This entry is missing from the overview file
3932 (gnus-message 3 "Regenerating NOV %s %d..."
3933 (gnus-agent-decoded-group-name group
)
3935 (let ((file (concat dir
(number-to-string (car downloaded
)))))
3936 (mm-with-unibyte-buffer
3937 (nnheader-insert-file-contents file
)
3938 (nnheader-remove-body)
3939 (setq header
(nnheader-parse-naked-head)))
3940 (mail-header-set-number header
(car downloaded
))
3942 (let ((key (concat "^" (int-to-string (car nov-arts
))
3944 (or (re-search-backward key nil t
)
3945 (re-search-forward key
))
3947 (goto-char (point-min)))
3948 (nnheader-insert-nov header
))
3949 (setq nov-arts
(cons (car downloaded
) nov-arts
)))
3950 ((eq (car downloaded
) (car nov-arts
))
3951 ;; This entry in the overview has been downloaded
3952 (push (cons (car downloaded
)
3954 (file-attribute-modification-time
3956 (concat dir
(number-to-string
3957 (car downloaded
)))))))
3959 (setq downloaded
(cdr downloaded
))
3960 (setq nov-arts
(cdr nov-arts
)))
3962 ;; This entry in the overview has not been downloaded
3963 (push (cons (car nov-arts
) nil
) alist
)
3964 (setq nov-arts
(cdr nov-arts
)))))
3966 ;; When gnus-agent-consider-all-articles is set,
3967 ;; gnus-agent-regenerate-group should NOT remove article IDs from
3968 ;; the alist. Those IDs serve as markers to indicate that an
3969 ;; attempt has been made to fetch that article's header.
3971 ;; When gnus-agent-consider-all-articles is NOT set,
3972 ;; gnus-agent-regenerate-group can remove the article ID of every
3973 ;; article (with the exception of the last ID in the list - it's
3974 ;; special) that no longer appears in the overview. In this
3975 ;; situation, the last article ID in the list implies that it,
3976 ;; and every article ID preceding it, have been fetched from the
3979 (if gnus-agent-consider-all-articles
3980 ;; Restore all article IDs that were not found in the overview file.
3981 (let* ((n (cons nil alist
))
3983 (o (gnus-agent-load-alist group
)))
3985 (let ((nID (caadr n
))
3988 (setq n
(setcdr n
(list (list oID
))))
3991 (setcdr n
(cons (list oID
) (cdr n
)))
3997 (setq n
(cdr n
))))))
3998 (setq alist
(cdr merged
)))
3999 ;; Restore the last article ID if it is not already in the new alist
4000 (let ((n (last alist
))
4001 (o (last (gnus-agent-load-alist group
))))
4005 (push (cons (caar o
) nil
) alist
))
4006 ((< (caar n
) (caar o
))
4007 (setcdr n
(list (car o
)))))))
4009 (let ((inhibit-quit t
))
4010 (if (setq regenerated
(buffer-modified-p))
4011 (let ((coding-system-for-write gnus-agent-file-coding-system
))
4012 (write-region (point-min) (point-max) file nil
'silent
)))
4014 (setq regenerated
(or regenerated
4015 (and reread gnus-agent-article-alist
)
4016 (not (equal alist gnus-agent-article-alist
))))
4018 (setq gnus-agent-article-alist alist
)
4021 (gnus-agent-save-alist group
)
4023 ;; I have to alter the group's active range NOW as
4024 ;; gnus-make-ascending-articles-unread will use it to
4025 ;; recalculate the number of unread articles in the group
4027 (let ((group (gnus-group-real-name group
))
4028 (group-active (or (gnus-active group
)
4029 (gnus-activate-group group
))))
4030 (gnus-agent-possibly-alter-active group group-active
)))))
4032 (when (and reread gnus-agent-article-alist
)
4033 (gnus-agent-synchronize-group-flags
4038 (delq nil
(mapcar (function (lambda (c)
4039 (cond ((eq reread t
)
4043 gnus-agent-article-alist
)))
4045 gnus-command-method
)
4048 (gnus-agent-update-files-total-fetched-for group nil
)))
4054 (defun gnus-agent-regenerate (&optional _clean reread
)
4055 "Regenerate all agent covered files.
4056 CLEAN is obsolete and ignored."
4059 (gnus-message 4 "Regenerating Gnus agent files...")
4060 (dolist (gnus-command-method (gnus-agent-covered-methods))
4061 (dolist (group (gnus-groups-from-server gnus-command-method
))
4062 (setq regenerated
(or (gnus-agent-regenerate-group group reread
)
4064 (gnus-message 4 "Regenerating Gnus agent files...done")
4068 (defun gnus-agent-go-online (&optional force
)
4069 "Switch servers into online status."
4070 (interactive (list t
))
4071 (dolist (server gnus-opened-servers
)
4072 (when (eq (nth 1 server
) 'offline
)
4073 (if (if (eq force
'ask
)
4075 (format "Switch %s:%s into online status? "
4076 (caar server
) (cadar server
)))
4078 (setcar (nthcdr 1 server
) 'close
)))))
4080 (defun gnus-agent-toggle-group-plugged (group)
4081 "Toggle the status of the server of the current group."
4082 (interactive (list (gnus-group-group-name)))
4083 (let* ((method (gnus-find-method-for-group group
))
4084 (status (cadr (assoc method gnus-opened-servers
))))
4085 (if (eq status
'offline
)
4086 (gnus-server-set-status method
'closed
)
4087 (gnus-close-server method
)
4088 (gnus-server-set-status method
'offline
))
4089 (message "Turn %s:%s from %s to %s." (car method
) (cadr method
)
4090 (if (eq status
'offline
) 'offline
'online
)
4091 (if (eq status
'offline
) 'online
'offline
))))
4093 (defun gnus-agent-group-covered-p (group)
4094 (gnus-agent-method-p (gnus-group-method group
)))
4096 (defun gnus-agent-update-files-total-fetched-for (group delta
4097 &optional method path
)
4098 "Update, or set, the total disk space used by the articles that the
4100 (when gnus-agent-total-fetched-hashtb
4101 (gnus-agent-with-refreshed-group
4103 ;; if null, gnus-agent-group-pathname will calc method.
4104 (let* ((gnus-command-method method
)
4105 (path (or path
(gnus-agent-group-pathname group
)))
4106 (entry (or (gnus-gethash path gnus-agent-total-fetched-hashtb
)
4107 (gnus-sethash path
(make-list 3 0)
4108 gnus-agent-total-fetched-hashtb
)))
4109 (file-name-coding-system nnmail-pathname-coding-system
))
4110 (when (file-exists-p path
)
4115 (while (setq file
(pop delta
))
4116 (cl-incf sum
(float (or (file-attribute-size
4121 (number-to-string file
)
4125 (let ((sum (- (nth 2 entry
)))
4126 (info (directory-files-and-attributes
4127 path nil
"^-?[0-9]+$" t
))
4129 (while (setq file
(pop info
))
4130 (cl-incf sum
(float (or (file-attribute-size (cdr file
)) 0))))
4133 (setq gnus-agent-need-update-total-fetched-for t
)
4134 (cl-incf (nth 2 entry
) delta
))))))
4136 (defun gnus-agent-update-view-total-fetched-for
4137 (group agent-over
&optional method path
)
4138 "Update, or set, the total disk space used by the .agentview and
4139 .overview files. These files are calculated separately as they can be
4141 (when gnus-agent-total-fetched-hashtb
4142 (gnus-agent-with-refreshed-group
4144 ;; if null, gnus-agent-group-pathname will calc method.
4145 (let* ((gnus-command-method method
)
4146 (path (or path
(gnus-agent-group-pathname group
)))
4147 (entry (or (gnus-gethash path gnus-agent-total-fetched-hashtb
)
4148 (gnus-sethash path
(make-list 3 0)
4149 gnus-agent-total-fetched-hashtb
)))
4150 (file-name-coding-system nnmail-pathname-coding-system
)
4151 (size (or (file-attribute-size (file-attributes
4157 (setq gnus-agent-need-update-total-fetched-for t
)
4158 (setf (nth (if agent-over
1 0) entry
) size
)))))
4160 (defun gnus-agent-total-fetched-for (group &optional method no-inhibit
)
4161 "Get the total disk space used by the specified GROUP."
4162 (unless (equal group
"dummy.group")
4163 (unless gnus-agent-total-fetched-hashtb
4164 (setq gnus-agent-total-fetched-hashtb
(gnus-make-hashtable 1024)))
4166 ;; if null, gnus-agent-group-pathname will calc method.
4167 (let* ((gnus-command-method method
)
4168 (path (gnus-agent-group-pathname group
))
4169 (entry (gnus-gethash path gnus-agent-total-fetched-hashtb
)))
4172 (let ((gnus-agent-inhibit-update-total-fetched-for (not no-inhibit
)))
4174 (gnus-agent-update-view-total-fetched-for group nil method path
)
4175 (gnus-agent-update-view-total-fetched-for group t method path
)
4176 (gnus-agent-update-files-total-fetched-for group nil method path
)))))))
4178 (provide 'gnus-agent
)
4180 ;;; gnus-agent.el ends here