1 ;;; gnus-start.el --- startup functions for Gnus
3 ;; Copyright (C) 1996-2017 Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
34 (autoload 'message-make-date
"message")
35 (autoload 'gnus-agent-read-servers-validate
"gnus-agent")
36 (autoload 'gnus-agent-save-local
"gnus-agent")
37 (autoload 'gnus-agent-possibly-alter-active
"gnus-agent")
42 (defvar gnus-agent-covered-methods
)
43 (defvar gnus-agent-file-loading-local
)
44 (defvar gnus-agent-file-loading-cache
)
46 (defcustom gnus-startup-file
(nnheader-concat gnus-home-directory
".newsrc")
48 `.newsrc-SERVER' will be used instead if that exists."
52 (defcustom gnus-backup-startup-file
'never
53 "Control use of version numbers for backups of `gnus-startup-file'.
54 This variable takes the same values as the `version-control'
58 :type
'(choice (const :tag
"Never" never
)
59 (const :tag
"If existing" nil
)
60 (other :tag
"Always" t
)))
62 (defcustom gnus-save-startup-file-via-temp-buffer t
63 "Whether to write the startup file contents to a buffer then save
64 the buffer or write directly to the file. The buffer is faster
65 because all of the contents are written at once. The direct write
66 uses considerably less memory."
69 :type
'(choice (const :tag
"Write via buffer" t
)
70 (const :tag
"Write directly to file" nil
)))
72 (defcustom gnus-init-file
(nnheader-concat gnus-home-directory
".gnus")
73 "Your Gnus Emacs-Lisp startup file name.
74 If a file with the `.el' or `.elc' suffixes exists, it will be read instead."
78 (defcustom gnus-site-init-file
80 (concat (file-name-directory
81 (directory-file-name installation-directory
))
82 "site-lisp/gnus-init")
84 "The site-wide Gnus Emacs-Lisp startup file name, or nil if none.
85 If a file with the `.el' or `.elc' suffixes exists, it will be read instead."
87 :type
'(choice file
(const nil
)))
89 (defcustom gnus-use-dribble-file t
90 "Non-nil means that Gnus will use a dribble file to store user updates.
91 If Emacs should crash without saving the .newsrc files, complete
92 information can be restored from the dribble file."
93 :group
'gnus-dribble-file
96 (defcustom gnus-dribble-directory nil
97 "The directory where dribble files will be saved.
98 If this variable is nil, the directory where the .newsrc files are
100 :group
'gnus-dribble-file
101 :type
'(choice directory
(const nil
)))
103 (defcustom gnus-check-new-newsgroups
'ask-server
104 "Non-nil means that Gnus will run `gnus-find-new-newsgroups' at startup.
105 This normally finds new newsgroups by comparing the active groups the
106 servers have already reported with those Gnus already knows, either alive
109 When any of the following are true, `gnus-find-new-newsgroups' will instead
110 ask the servers (primary, secondary, and archive servers) to list new
111 groups since the last time it checked:
112 1. This variable is `ask-server'.
113 2. This variable is a list of select methods (see below).
114 3. Option `gnus-read-active-file' is nil or `some'.
115 4. A prefix argument is given to `gnus-find-new-newsgroups' interactively.
117 Thus, if this variable is `ask-server' or a list of select methods or
118 `gnus-read-active-file' is nil or `some', then the killed list is no
119 longer necessary, so you could safely set `gnus-save-killed-list' to nil.
121 This variable can be a list of select methods which Gnus will query with
122 the `ask-server' method in addition to the primary, secondary, and archive
126 (setq gnus-check-new-newsgroups
127 \\='((nntp \"some.server\") (nntp \"other.server\")))
129 If this variable is nil, then you have to tell Gnus explicitly to
130 check for new newsgroups with \\<gnus-group-mode-map>\\[gnus-find-new-newsgroups]."
132 :type
'(choice (const :tag
"no" nil
)
133 (const :tag
"by brute force" t
)
134 (const :tag
"ask servers" ask-server
)
135 (repeat :menu-tag
"ask additional servers"
136 :tag
"ask additional servers"
138 (sexp :format
"%v"))))
140 (defcustom gnus-check-bogus-newsgroups nil
141 "Non-nil means that Gnus will check and remove bogus newsgroup at startup.
142 If this variable is nil, then you have to tell Gnus explicitly to
143 check for bogus newsgroups with \\<gnus-group-mode-map>\\[gnus-group-check-bogus-groups]."
144 :group
'gnus-start-server
147 (defcustom gnus-read-active-file
'some
148 "Non-nil means that Gnus will read the entire active file at startup.
149 If this variable is nil, Gnus will only know about the groups in your
152 If this variable is `some', Gnus will try to only read the relevant
153 parts of the active file from the server. Not all servers support
154 this, and it might be quite slow with other servers, but this should
155 generally be faster than both the t and nil value.
157 If you set this variable to nil or `some', you probably still want to
158 be told about new newsgroups that arrive. To do that, set
159 `gnus-check-new-newsgroups' to `ask-server'. This may not work
160 properly with all servers."
161 :group
'gnus-start-server
162 :type
'(choice (const nil
)
166 (defconst gnus-level-subscribed
5
167 "Groups with levels less than or equal to this variable are subscribed.")
169 (defconst gnus-level-unsubscribed
7
170 "Groups with levels less than or equal to this variable are unsubscribed.
172 Groups with levels less than `gnus-level-subscribed', which
173 should be less than this variable, are subscribed. Groups with
174 levels from `gnus-level-subscribed' (exclusive) upto this
175 variable (inclusive) are unsubscribed. See also
176 `gnus-level-zombie', `gnus-level-killed' and the Info node `(gnus)Group
177 Levels' for details.")
179 (defconst gnus-level-zombie
8
180 "Groups with this level are zombie groups.")
182 (defconst gnus-level-killed
9
183 "Groups with this level are killed.")
185 (defcustom gnus-level-default-subscribed
3
186 "New subscribed groups will be subscribed at this level."
187 :group
'gnus-group-levels
190 (defcustom gnus-level-default-unsubscribed
6
191 "New unsubscribed groups will be unsubscribed at this level."
192 :group
'gnus-group-levels
195 (defcustom gnus-activate-level
(1+ gnus-level-subscribed
)
196 "Groups higher than this level won't be activated on startup.
197 Setting this variable to something low might save lots of time when
198 you have many groups that you aren't interested in."
199 :group
'gnus-group-levels
202 (defcustom gnus-activate-foreign-newsgroups
4
203 "If nil, Gnus will not check foreign newsgroups at startup.
204 If it is non-nil, it should be a number between one and nine. Foreign
205 newsgroups that have a level lower or equal to this number will be
206 activated on startup. For instance, if you want to active all
207 subscribed newsgroups, but not the rest, you'd set this variable to
208 `gnus-level-subscribed'.
210 If you subscribe to lots of newsgroups from different servers, startup
211 might take a while. By setting this variable to nil, you'll save time,
212 but you won't be told how many unread articles there are in the
214 :group
'gnus-group-levels
215 :type
'(choice integer
216 (const :tag
"none" nil
)))
218 (defcustom gnus-read-newsrc-file t
219 "Non-nil means that Gnus will read the `.newsrc' file.
220 Gnus always reads its own startup file, which is called
221 \".newsrc.eld\". The file called \".newsrc\" is in a format that can
222 be readily understood by other newsreaders. If you don't plan on
223 using other newsreaders, set this variable to nil to save some time on
229 (defcustom gnus-save-newsrc-file t
230 "Non-nil means that Gnus will save the `.newsrc' file.
231 Gnus always saves its own startup file, which is called
232 \".newsrc.eld\". The file called \".newsrc\" is in a format that can
233 be readily understood by other newsreaders. If you don't plan on
234 using other newsreaders, set this variable to nil to save some time on
239 (defcustom gnus-save-killed-list t
240 "If non-nil, save the list of killed groups to the startup file.
241 If you set this variable to nil, you'll save both time (when starting
242 and quitting) and space (both memory and disk), but it will also mean
243 that Gnus has no record of which groups are new and which are old, so
244 the automatic new newsgroups subscription methods become meaningless.
246 You should always set `gnus-check-new-newsgroups' to `ask-server' or
247 nil if you set this variable to nil.
249 This variable can also be a regexp. In that case, all groups that do
250 not match this regexp will be removed before saving the list."
252 :type
'(radio (sexp :format
"Non-nil\n"
253 :match
(lambda (widget value
)
254 (and value
(not (stringp value
))))
259 (defcustom gnus-ignored-newsgroups
261 '("^to\\." ; not "real" groups
262 "^[0-9. \t]+\\( \\|$\\)" ; all digits in name
263 "^[\"][\"#'()]" ; bogus characters
266 "A regexp to match uninteresting newsgroups in the active file.
267 Any lines in the active file matching this regular expression are
268 removed from the newsgroup list before anything else is done to it,
269 thus making them effectively non-existent."
270 :group
'gnus-group-new
273 (defcustom gnus-subscribe-newsgroup-method
'gnus-subscribe-zombies
274 "Function(s) called with a group name when new group is detected.
275 A few pre-made functions are supplied: `gnus-subscribe-randomly'
276 inserts new groups at the beginning of the list of groups;
277 `gnus-subscribe-alphabetically' inserts new groups in strict
278 alphabetic order; `gnus-subscribe-hierarchically' inserts new groups
279 in hierarchical newsgroup order; `gnus-subscribe-interactively' asks
280 for your decision; `gnus-subscribe-killed' kills all new groups;
281 `gnus-subscribe-zombies' will make all new groups into zombies;
282 `gnus-subscribe-topics' will enter groups into the topics that
284 :group
'gnus-group-new
285 :type
'(radio (function-item gnus-subscribe-randomly
)
286 (function-item gnus-subscribe-alphabetically
)
287 (function-item gnus-subscribe-hierarchically
)
288 (function-item gnus-subscribe-interactively
)
289 (function-item gnus-subscribe-killed
)
290 (function-item gnus-subscribe-zombies
)
291 (function-item gnus-subscribe-topics
)
295 (define-obsolete-variable-alias 'gnus-subscribe-newsgroup-hooks
296 'gnus-subscribe-newsgroup-functions
"24.3")
297 (defcustom gnus-subscribe-newsgroup-functions nil
298 "Hooks run after you subscribe to a new group.
299 The hooks will be called with new group's name as argument."
301 :group
'gnus-group-new
304 (defcustom gnus-subscribe-options-newsgroup-method
305 'gnus-subscribe-alphabetically
306 "Function(s) called to subscribe newsgroups mentioned on \"options -n\" lines.
307 If, for instance, you want to subscribe to all newsgroups in the
308 \"no\" and \"alt\" hierarchies, you'd put the following in your
311 options -n no.all alt.all
313 Gnus will then subscribe all new newsgroups in these hierarchies
314 with the subscription method in this variable."
315 :group
'gnus-group-new
316 :type
'(radio (function-item gnus-subscribe-randomly
)
317 (function-item gnus-subscribe-alphabetically
)
318 (function-item gnus-subscribe-hierarchically
)
319 (function-item gnus-subscribe-interactively
)
320 (function-item gnus-subscribe-killed
)
321 (function-item gnus-subscribe-zombies
)
322 (function-item gnus-subscribe-topics
)
326 (defcustom gnus-subscribe-hierarchical-interactive nil
327 "If non-nil, Gnus will offer to subscribe hierarchically.
328 When a new hierarchy appears, Gnus will ask the user:
330 'alt.binaries': Do you want to subscribe to this hierarchy? ([d]ys):
332 If the user pressed `d', Gnus will descend the hierarchy, `y' will
333 subscribe to all newsgroups in the hierarchy and `s' will skip this
334 hierarchy in its entirety."
335 :group
'gnus-group-new
338 (defcustom gnus-auto-subscribed-categories
'(mail post-mail
)
339 "New groups from methods of these categories will be subscribed automatically.
340 Note that this variable only deals with new groups. It has no
341 effect whatsoever on old groups. The default is to automatically
342 subscribe all groups from mail-like backends."
344 :group
'gnus-group-new
345 :type
'(repeat symbol
))
347 (defcustom gnus-auto-subscribed-groups
348 "^nnml\\|^nnfolder\\|^nnmbox\\|^nnmh\\|^nnbabyl\\|^nnmaildir\\|^nnimap"
349 "All new groups that match this regexp will be subscribed automatically.
350 Note that this variable only deals with new groups. It has no effect
351 whatsoever on old groups.
353 New groups that match this regexp will not be handled by
354 `gnus-subscribe-newsgroup-method'. Instead, they will
355 be subscribed using `gnus-subscribe-options-newsgroup-method'."
356 :group
'gnus-group-new
359 (defcustom gnus-options-subscribe nil
360 "All new groups matching this regexp will be subscribed unconditionally.
361 Note that this variable deals only with new newsgroups. This variable
362 does not affect old newsgroups.
364 New groups that match this regexp will not be handled by
365 `gnus-subscribe-newsgroup-method'. Instead, they will
366 be subscribed using `gnus-subscribe-options-newsgroup-method'."
367 :group
'gnus-group-new
368 :type
'(choice regexp
369 (const :tag
"none" nil
)))
371 (defcustom gnus-options-not-subscribe nil
372 "All new groups matching this regexp will be ignored.
373 Note that this variable deals only with new newsgroups. This variable
374 does not affect old (already subscribed) newsgroups."
375 :group
'gnus-group-new
376 :type
'(choice regexp
377 (const :tag
"none" nil
)))
379 (defcustom gnus-modtime-botch nil
380 "Non-nil means .newsrc should be deleted prior to save.
381 Its use is due to the bogus appearance that .newsrc was modified on
386 (defcustom gnus-check-bogus-groups-hook nil
387 "A hook run after removing bogus groups."
388 :group
'gnus-start-server
391 (defcustom gnus-startup-hook nil
392 "A hook called at startup.
393 This hook is called after Gnus is connected to the NNTP server."
397 (defcustom gnus-before-startup-hook nil
398 "A hook called before startup.
399 This hook is called as the first thing when Gnus is started.
400 See also `gnus-before-resume-hook'."
404 (defcustom gnus-before-resume-hook nil
405 "A hook called before resuming Gnus after suspend.
406 This hook is called as the first thing when Gnus is resumed after a suspend.
407 See also `gnus-before-startup-hook'."
412 (defcustom gnus-started-hook nil
413 "A hook called as the last thing after startup."
417 (defcustom gnus-setup-news-hook nil
418 "A hook after reading the .newsrc file, but before generating the buffer."
422 (defcustom gnus-get-top-new-news-hook nil
423 "A hook run just before Gnus checks for new news globally."
425 :group
'gnus-group-new
428 (defcustom gnus-get-new-news-hook nil
429 "A hook run just before Gnus checks for new news."
430 :group
'gnus-group-new
433 (defcustom gnus-after-getting-new-news-hook
434 '(gnus-display-time-event-handler)
435 "A hook run after Gnus checks for new news when Gnus is already running."
437 :group
'gnus-group-new
440 (defcustom gnus-read-newsrc-el-hook nil
441 "A hook called after reading the newsrc.eld? file."
445 (defcustom gnus-save-newsrc-hook nil
446 "A hook called before saving any of the newsrc files."
450 (defcustom gnus-save-quick-newsrc-hook nil
451 "A hook called just before saving the quick newsrc file.
452 Can be used to turn version control on or off."
456 (defcustom gnus-save-standard-newsrc-hook nil
457 "A hook called just before saving the standard newsrc file.
458 Can be used to turn version control on or off."
462 (defcustom gnus-group-mode-hook nil
463 "Hook for Gnus group mode."
464 :group
'gnus-group-various
465 :options
'(gnus-topic-mode)
468 (defcustom gnus-always-read-dribble-file nil
469 "Unconditionally read the dribble file."
473 ;;; Internal variables
475 ;; Fixme: deal with old emacs-mule when mm-universal-coding-system is
477 (defvar gnus-ding-file-coding-system mm-universal-coding-system
478 "Coding system for ding file.")
480 (defvar gnus-newsrc-file-version nil
)
481 (defvar gnus-override-subscribe-method nil
)
482 (defvar gnus-dribble-buffer nil
)
483 (defvar gnus-newsrc-options nil
484 "Options line in the .newsrc file.")
486 (defvar gnus-newsrc-options-n nil
487 "List of regexps representing groups to be subscribed/ignored unconditionally.")
489 (defvar gnus-newsrc-last-checked-date nil
490 "Date Gnus last asked server for new newsgroups.")
492 (defvar gnus-current-startup-file nil
493 "Startup file for the current host.")
495 ;; Byte-compiler warning.
496 (defvar gnus-group-line-format
)
498 ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
499 (defvar gnus-init-inhibit nil
)
500 (defun gnus-read-init-file (&optional inhibit-next
)
501 ;; Don't load .gnus if the -q option was used.
503 (if gnus-init-inhibit
504 (setq gnus-init-inhibit nil
)
505 (setq gnus-init-inhibit inhibit-next
)
506 (dolist (file (list gnus-site-init-file gnus-init-file
))
508 (locate-library file
))
509 (if (or debug-on-error debug-on-quit
)
514 (error "Error in %s: %s" file
(cadr var
))))))))))
516 ;; For subscribing new newsgroup
518 (defun gnus-subscribe-hierarchical-interactive (groups)
519 (let ((groups (sort groups
'string
<))
520 prefixes prefix start ans group starts real-group
)
522 (setq prefixes
(list "^"))
523 (while (and groups prefixes
)
524 (while (not (string-match (car prefixes
)
525 (gnus-group-real-name (car groups
))))
526 (setq prefixes
(cdr prefixes
)))
527 (setq prefix
(car prefixes
))
528 (setq start
(1- (length prefix
)))
529 (if (and (string-match "[^\\.]\\." (gnus-group-real-name (car groups
))
533 (concat "^" (substring
534 (gnus-group-real-name (car groups
))
536 (string-match prefix
(gnus-group-real-name (cadr groups
))))
538 (push prefix prefixes
)
539 (message "Descend hierarchy %s? ([y]nsq): "
540 (substring prefix
1 (1- (length prefix
))))
541 (while (not (memq (setq ans
(read-char-exclusive))
542 '(?y ?
\n ?
\r ?n ?s ?q
)))
544 (message "Descend hierarchy %s? ([y]nsq): "
545 (substring prefix
1 (1- (length prefix
)))))
548 (setq group
(car groups
)
549 real-group
(gnus-group-real-name group
))
550 (string-match prefix real-group
))
551 (push group gnus-killed-list
)
552 (gnus-sethash group group gnus-killed-hashtb
)
553 (setq groups
(cdr groups
)))
554 (setq starts
(cdr starts
)))
557 (setq group
(car groups
)
558 real-group
(gnus-group-real-name group
))
559 (string-match prefix real-group
))
560 (gnus-sethash group group gnus-killed-hashtb
)
561 (gnus-subscribe-alphabetically (car groups
))
562 (setq groups
(cdr groups
)))
563 (setq starts
(cdr starts
)))
566 (setq group
(car groups
))
567 (push group gnus-killed-list
)
568 (gnus-sethash group group gnus-killed-hashtb
)
569 (setq groups
(cdr groups
))))
571 (message "Subscribe %s? ([n]yq)" (car groups
))
572 (while (not (memq (setq ans
(read-char-exclusive))
573 '(?y ?
\n ?
\r ?q ?n
)))
575 (message "Subscribe %s? ([n]yq)" (car groups
)))
576 (setq group
(car groups
))
578 (gnus-subscribe-alphabetically (car groups
))
579 (gnus-sethash group group gnus-killed-hashtb
))
582 (setq group
(car groups
))
583 (push group gnus-killed-list
)
584 (gnus-sethash group group gnus-killed-hashtb
)
585 (setq groups
(cdr groups
))))
587 (push group gnus-killed-list
)
588 (gnus-sethash group group gnus-killed-hashtb
)))
589 (setq groups
(cdr groups
)))))))
591 (defun gnus-subscribe-randomly (newsgroup)
592 "Subscribe new NEWSGROUP by making it the first newsgroup."
593 (gnus-subscribe-newsgroup newsgroup
))
595 (defun gnus-subscribe-alphabetically (newgroup)
596 "Subscribe new NEWGROUP and insert it in alphabetical order."
597 (let ((groups (cdr gnus-newsrc-alist
))
599 (while (and (not before
) groups
)
600 (if (string< newgroup
(caar groups
))
601 (setq before
(caar groups
))
602 (setq groups
(cdr groups
))))
603 (gnus-subscribe-newsgroup newgroup before
)))
605 (defun gnus-subscribe-hierarchically (newgroup)
606 "Subscribe new NEWGROUP and insert it in hierarchical newsgroup order."
607 ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
608 (with-current-buffer (nnheader-find-file-noselect gnus-current-startup-file
)
610 (let ((groupkey newgroup
) before
)
611 (while (and (not before
) groupkey
)
612 (goto-char (point-min))
614 (concat "^\\(" (regexp-quote groupkey
) ".*\\)[!:]")))
615 (while (and (re-search-forward groupkey-re nil t
)
617 (setq before
(match-string 1))
618 (string< before newgroup
)))))
619 ;; Remove tail of newsgroup name (eg. a.b.c -> a.b)
621 (when (string-match "^\\(.*\\)\\.[^.]+$" groupkey
)
622 (substring groupkey
(match-beginning 1) (match-end 1)))))
623 (gnus-subscribe-newsgroup newgroup before
))
624 (kill-buffer (current-buffer)))))
626 (defun gnus-subscribe-interactively (group)
627 "Subscribe the new GROUP interactively.
628 It is inserted in hierarchical newsgroup order if subscribed. If not,
630 (if (gnus-y-or-n-p (format "Subscribe new newsgroup %s? " group
))
631 (gnus-subscribe-hierarchically group
)
632 (push group gnus-killed-list
)))
634 (defun gnus-subscribe-zombies (group)
635 "Make the new GROUP into a zombie group."
636 (push group gnus-zombie-list
))
638 (defun gnus-subscribe-killed (group)
639 "Make the new GROUP a killed group."
640 (push group gnus-killed-list
))
642 (defun gnus-subscribe-newsgroup (newsgroup &optional next
)
643 "Subscribe new NEWSGROUP.
644 If NEXT is non-nil, it is inserted before NEXT. Otherwise it is made
645 the first newsgroup."
647 (goto-char (point-min))
648 ;; We subscribe the group by changing its level to `subscribed'.
649 (gnus-group-change-level
650 newsgroup gnus-level-default-subscribed
651 gnus-level-killed
(gnus-group-entry (or next
"dummy.group")))
652 (gnus-request-update-group-status newsgroup
'subscribe
)
653 (gnus-message 5 "Subscribe newsgroup: %s" newsgroup
)
654 (run-hook-with-args 'gnus-subscribe-newsgroup-functions newsgroup
)
657 (defun gnus-read-active-file-p ()
658 "Say whether the active file has been read from `gnus-select-method'."
659 (memq gnus-select-method gnus-have-read-active-file
))
661 ;;; General various misc type functions.
663 ;; Silence byte-compiler.
664 (defvar gnus-current-headers
)
665 (defvar gnus-thread-indent-array
)
666 (defvar gnus-newsgroup-name
)
667 (defvar gnus-newsgroup-headers
)
668 (defvar gnus-group-list-mode
)
669 (defvar gnus-group-mark-positions
)
670 (defvar gnus-newsgroup-data
)
671 (defvar gnus-newsgroup-unreads
)
672 (defvar nnoo-state-alist
)
673 (defvar gnus-current-select-method
)
674 (defvar mail-sources
)
675 (defvar nnmail-scan-directory-mail-source-once
)
676 (defvar nnmail-split-history
)
677 (defvar nnmail-spool-file
)
679 (defun gnus-close-all-servers ()
682 (dolist (server gnus-opened-servers
)
683 (gnus-close-server (car server
))))
685 (defun gnus-clear-system ()
686 "Clear all variables and buffers."
687 ;; Clear Gnus variables.
688 (let ((variables (remove 'gnus-format-specs gnus-variable-list
)))
690 (set (car variables
) nil
)
691 (setq variables
(cdr variables
))))
692 ;; Clear other internal variables.
693 (setq gnus-list-of-killed-groups nil
694 gnus-have-read-active-file nil
695 gnus-agent-covered-methods nil
696 gnus-agent-file-loading-local nil
697 gnus-agent-file-loading-cache nil
698 gnus-server-method-cache nil
699 gnus-newsrc-alist nil
700 gnus-newsrc-hashtb nil
703 gnus-killed-hashtb nil
704 gnus-active-hashtb nil
705 gnus-moderated-hashtb nil
706 gnus-description-hashtb nil
707 gnus-current-headers nil
708 gnus-thread-indent-array nil
709 gnus-newsgroup-headers nil
710 gnus-newsgroup-name nil
711 gnus-server-alist nil
712 gnus-group-list-mode nil
713 gnus-opened-servers nil
714 gnus-group-mark-positions nil
715 gnus-newsgroup-data nil
716 gnus-newsgroup-unreads nil
718 gnus-current-select-method nil
719 nnmail-split-history nil
720 gnus-extended-servers nil
721 gnus-ephemeral-servers nil
)
722 (gnus-shutdown 'gnus
)
723 ;; Kill the startup file.
724 (and gnus-current-startup-file
725 (get-file-buffer gnus-current-startup-file
)
726 (kill-buffer (get-file-buffer gnus-current-startup-file
)))
727 ;; Clear the dribble buffer.
729 ;; Kill global KILL file buffer.
730 (when (get-file-buffer (gnus-newsgroup-kill-file nil
))
731 (kill-buffer (get-file-buffer (gnus-newsgroup-kill-file nil
))))
732 (gnus-kill-buffer nntp-server-buffer
)
733 ;; Kill Gnus buffers.
735 (dolist (buffer (gnus-buffers))
736 (when (gnus-buffer-exists-p buffer
)
737 (with-current-buffer buffer
738 (set-buffer-modified-p nil
)
739 (when (local-variable-p 'kill-buffer-hook
)
740 (setq kill-buffer-hook nil
))))
741 (gnus-kill-buffer buffer
))
742 ;; Remove Gnus frames.
743 (gnus-kill-gnus-frames))
745 (defun gnus-no-server-1 (&optional arg slave
)
747 If ARG is a positive number, Gnus will use that as the startup
748 level. If ARG is nil, Gnus will be started at level 2
749 \(`gnus-level-default-subscribed' minus one). If ARG is non-nil
750 and not a positive number, Gnus will prompt the user for the name
751 of an NNTP server to use. As opposed to \\[gnus], this command
752 will not connect to the local server."
754 (let ((val (or arg
(1- gnus-level-default-subscribed
))))
756 (make-local-variable 'gnus-group-use-permanent-levels
)
757 (setq gnus-group-use-permanent-levels val
)))
759 (defun gnus-1 (&optional arg dont-connect slave
)
761 If ARG is non-nil and a positive number, Gnus will use that as the
762 startup level. If ARG is non-nil and not a positive number, Gnus will
763 prompt the user for the name of an NNTP server to use."
768 (gnus-run-hooks 'gnus-before-resume-hook
)
769 (switch-to-buffer gnus-group-buffer
)
770 (gnus-group-get-new-news
773 (max (car gnus-group-list-mode
) arg
))))
777 (gnus-run-hooks 'gnus-before-startup-hook
)
778 (nnheader-init-server-buffer)
779 (setq gnus-slave slave
)
780 (gnus-read-init-file)
782 ;; Add "native" to gnus-predefined-server-alist just to have a
783 ;; name for the native select method.
784 (when gnus-select-method
785 (add-to-list 'gnus-predefined-server-alist
786 (cons "native" gnus-select-method
)))
791 (let ((level (and (numberp arg
) (> arg
0) arg
))
797 (gnus-start-news-server (and arg
(not level
))))))
798 (if (and (not dont-connect
)
800 ;; Couldn't connect to the server, so bail out.
802 (gnus-run-hooks 'gnus-startup-hook
)
803 ;; Find the current startup file name.
804 (setq gnus-current-startup-file
805 (gnus-make-newsrc-file gnus-startup-file
))
807 ;; Read the dribble file.
808 (when (or gnus-slave gnus-use-dribble-file
)
809 (gnus-dribble-read-file))
811 ;; Do the actual startup.
812 (gnus-setup-news nil level dont-connect
)
813 (gnus-run-hooks 'gnus-setup-news-hook
)
815 (gnus-request-create-group "queue" '(nndraft "")))
816 (gnus-start-draft-setup)
817 ;; Generate the group buffer.
818 (gnus-group-list-groups level
)
819 (gnus-group-first-unread-group)
820 (gnus-configure-windows 'group
)
821 (gnus-group-set-mode-line)
822 (gnus-run-hooks 'gnus-started-hook
))))))
824 (defun gnus-start-draft-setup ()
825 "Make sure the draft group exists."
827 (gnus-request-create-group "drafts" '(nndraft ""))
828 (unless (gnus-group-entry "nndraft:drafts")
829 (let ((gnus-level-default-subscribed 1))
830 (gnus-subscribe-group "nndraft:drafts" nil
'(nndraft "")))
831 (setcar (gnus-group-entry "nndraft:drafts") 0))
832 (unless (equal (gnus-group-get-parameter "nndraft:drafts" 'gnus-dummy t
)
833 '((gnus-draft-mode)))
834 (gnus-group-set-parameter
835 "nndraft:drafts" 'gnus-dummy
'((gnus-draft-mode)))))
842 (defvar gnus-dribble-ignore nil
)
843 (defvar gnus-dribble-eval-file nil
)
845 (defun gnus-dribble-file-name ()
846 "Return the dribble file for the current .newsrc."
848 (if gnus-dribble-directory
849 (concat (file-name-as-directory gnus-dribble-directory
)
850 (file-name-nondirectory gnus-current-startup-file
))
851 gnus-current-startup-file
)
854 (defun gnus-dribble-enter (string &optional regexp
)
855 "Enter STRING into the dribble buffer.
856 If REGEXP is given, lines that match it will be deleted."
857 (when (and (not gnus-dribble-ignore
)
859 (buffer-name gnus-dribble-buffer
))
860 (let ((obuf (current-buffer)))
861 (set-buffer gnus-dribble-buffer
)
863 (goto-char (point-min))
865 (while (re-search-forward regexp nil t
)
866 (unless (bolp) (forward-line 1))
868 (goto-char (match-beginning 0))
869 (delete-region (point-at-bol) end
))))
870 (goto-char (point-max))
871 ;; Make sure that each dribble entry is a single line, so that
872 ;; the "remove" code above works.
873 (insert (replace-regexp-in-string "\n" "\\\\n" string
) "\n")
874 (bury-buffer gnus-dribble-buffer
)
875 (with-current-buffer gnus-group-buffer
876 (gnus-group-set-mode-line))
879 (defun gnus-dribble-touch ()
880 "Touch the dribble buffer."
881 (gnus-dribble-enter ""))
883 (defun gnus-dribble-read-file ()
884 "Read the dribble file from disk."
885 (let ((dribble-file (gnus-dribble-file-name)))
886 (unless (file-exists-p (file-name-directory dribble-file
))
887 (make-directory (file-name-directory dribble-file
) t
))
888 (with-current-buffer (setq gnus-dribble-buffer
889 (gnus-get-buffer-create
890 (file-name-nondirectory dribble-file
)))
891 (set (make-local-variable 'file-precious-flag
) t
)
892 (setq buffer-save-without-query t
)
894 (setq buffer-file-name dribble-file
)
895 ;; The buffer may be shrunk a lot when deleting old entries.
896 ;; It caused the auto-saving to stop.
897 (set (make-local-variable 'auto-save-include-big-deletions
) t
)
899 (buffer-disable-undo)
900 (bury-buffer (current-buffer))
901 (set-buffer-modified-p nil
)
902 (let ((auto (make-auto-save-file-name))
903 (gnus-dribble-ignore t
)
906 (when (or (file-exists-p auto
) (file-exists-p dribble-file
))
907 ;; Load whichever file is newest -- the auto save file
908 ;; or the "real" file.
909 (if (file-newer-than-file-p auto dribble-file
)
910 (nnheader-insert-file-contents auto
)
911 (nnheader-insert-file-contents dribble-file
))
912 (unless (zerop (buffer-size))
913 (set-buffer-modified-p t
))
914 ;; Set the file modes to reflect the .newsrc file modes.
916 (when (and (file-exists-p gnus-current-startup-file
)
917 (file-exists-p dribble-file
)
918 (setq modes
(file-modes gnus-current-startup-file
)))
919 (gnus-set-file-modes dribble-file modes
))
920 (goto-char (point-min))
921 (when (search-forward "Gnus was exited on purpose" nil t
)
923 ;; Possibly eval the file later.
924 (when (or gnus-always-read-dribble-file
927 "Gnus exited on purpose without saving; read auto-save file anyway? "
928 "Gnus auto-save file exists. Do you want to read it? ")))
929 (setq gnus-dribble-eval-file t
)))))))
931 (defun gnus-dribble-eval-file ()
932 (when gnus-dribble-eval-file
933 (setq gnus-dribble-eval-file nil
)
935 (let ((gnus-dribble-ignore t
))
936 (set-buffer gnus-dribble-buffer
)
937 (eval-buffer (current-buffer))))))
939 (defun gnus-dribble-delete-file ()
940 (when (file-exists-p (gnus-dribble-file-name))
941 (delete-file (gnus-dribble-file-name)))
942 (when gnus-dribble-buffer
943 (with-current-buffer gnus-dribble-buffer
944 (let ((auto (make-auto-save-file-name)))
945 (when (file-exists-p auto
)
948 (set-buffer-modified-p nil
)))))
950 (defun gnus-dribble-save ()
951 (when (and gnus-dribble-buffer
952 (buffer-name gnus-dribble-buffer
))
953 (with-current-buffer gnus-dribble-buffer
954 (when (> (buffer-size) 0)
957 (defun gnus-dribble-clear ()
958 (when (gnus-buffer-exists-p gnus-dribble-buffer
)
959 (with-current-buffer gnus-dribble-buffer
961 (set-buffer-modified-p nil
)
962 (setq buffer-saved-size
(buffer-size)))))
966 ;;; Active & Newsrc File Handling
969 (defun gnus-setup-news (&optional rawfile level dont-connect
)
970 "Setup news information.
971 If RAWFILE is non-nil, the .newsrc file will also be read.
972 If LEVEL is non-nil, the news will be set up at level LEVEL."
974 (let ((init (not (and gnus-newsrc-alist gnus-active-hashtb
(not rawfile
))))
975 ;; Binding this variable will inhibit multiple fetchings
976 ;; of the same mail source.
977 (nnmail-fetched-sources (list t
)))
980 ;; Clear some variables to re-initialize news information.
981 (setq gnus-newsrc-alist nil
982 gnus-active-hashtb nil
)
983 ;; Read the newsrc file and create `gnus-newsrc-hashtb'.
984 (gnus-read-newsrc-file rawfile
))
986 ;; Make sure the archive server is available to all and sundry.
987 (let ((method (or (and (stringp gnus-message-archive-method
)
988 (gnus-server-to-method
989 gnus-message-archive-method
))
990 gnus-message-archive-method
)))
991 ;; Check whether the archive method is writable.
992 (unless (or (not method
)
994 (memq 'respool
(assoc (format "%s" (car method
))
995 gnus-valid-select-methods
)))
996 (setq method
"archive")) ;; The default.
997 (when (stringp method
)
998 (setq method
`(nnfolder
1001 ,(nnheader-concat message-directory method
))
1002 (nnfolder-active-file
1003 ,(nnheader-concat message-directory
1004 (concat method
"/active")))
1005 (nnfolder-get-new-mail nil
)
1006 (nnfolder-inhibit-expiry t
))))
1007 (if (assoc "archive" gnus-server-alist
)
1008 (when gnus-update-message-archive-method
1010 (setcdr (assoc "archive" gnus-server-alist
) method
)
1011 (setq gnus-server-alist
(delq (assoc "archive" gnus-server-alist
)
1012 gnus-server-alist
))))
1014 (push (cons "archive" method
) gnus-server-alist
))))
1016 ;; If we don't read the complete active file, we fill in the
1018 (when (or (null gnus-read-active-file
)
1019 (eq gnus-read-active-file
'some
))
1020 (gnus-update-active-hashtb-from-killed))
1021 (unless gnus-active-hashtb
1022 (setq gnus-active-hashtb
(gnus-make-hashtable 4096)))
1023 ;; Initialize the cache.
1024 (when gnus-use-cache
1027 ;; Possibly eval the dribble file.
1029 (or gnus-use-dribble-file gnus-slave
)
1030 (gnus-dribble-eval-file))
1032 ;; Slave Gnusii should then clear the dribble buffer.
1033 (when (and init gnus-slave
)
1034 (gnus-dribble-clear))
1036 (gnus-update-format-specifications)
1038 ;; See whether we need to read the description file.
1039 (when (and (boundp 'gnus-group-line-format
)
1040 (stringp gnus-group-line-format
)
1041 (let ((case-fold-search nil
))
1042 (string-match "%[-,0-9]*D" gnus-group-line-format
))
1043 (not gnus-description-hashtb
)
1045 gnus-read-active-file
)
1046 (gnus-read-all-descriptions-files))
1048 ;; Find new newsgroups and treat them.
1049 (when (and init gnus-check-new-newsgroups
(not level
)
1050 (gnus-check-server gnus-select-method
)
1053 (gnus-find-new-newsgroups))
1055 ;; Check and remove bogus newsgroups.
1056 (when (and init gnus-check-bogus-newsgroups
1057 gnus-read-active-file
(not level
)
1058 (gnus-server-opened gnus-select-method
))
1059 (gnus-check-bogus-newsgroups))
1061 ;; Read any slave files.
1062 (gnus-master-read-slave-newsrc)
1064 ;; Find the number of unread articles in each non-dead group.
1065 (let ((gnus-read-active-file (and (not level
) gnus-read-active-file
)))
1066 (gnus-get-unread-articles level dont-connect
))))
1068 (defun gnus-call-subscribe-functions (method group
)
1069 "Call METHOD to subscribe GROUP.
1070 If no function returns `non-nil', call `gnus-subscribe-zombies'."
1073 (funcall method group
))
1076 (dolist (func method
)
1077 (if (funcall func group
)
1081 (gnus-subscribe-zombies group
)))
1083 (defun gnus-find-new-newsgroups (&optional arg
)
1084 "Search for new newsgroups and add them.
1085 Each new newsgroup will be treated with `gnus-subscribe-newsgroup-method'.
1086 The `-n' option line from .newsrc is respected.
1088 With 1 C-u, use the `ask-server' method to query the server for new
1090 With 2 C-u's, use most complete method possible to query the server
1091 for new groups, and subscribe the new groups as zombies."
1093 (let* ((gnus-subscribe-newsgroup-method
1094 gnus-subscribe-newsgroup-method
)
1096 ((or (and (= (or arg
1) 4)
1097 (not (listp gnus-check-new-newsgroups
)))
1098 (null gnus-read-active-file
)
1099 (eq gnus-read-active-file
'some
))
1102 (setq gnus-subscribe-newsgroup-method
1103 'gnus-subscribe-zombies
)
1105 (t gnus-check-new-newsgroups
))))
1106 (if (or (consp check
)
1107 (eq check
'ask-server
))
1108 ;; Ask the server for new groups.
1109 (gnus-ask-server-for-new-groups)
1110 ;; Go through the active hashtb and look for new groups.
1112 group new-newsgroups
)
1113 (gnus-message 5 "Looking for new newsgroups...")
1114 (unless gnus-have-read-active-file
1115 (gnus-read-active-file))
1116 (setq gnus-newsrc-last-checked-date
(message-make-date))
1117 (unless gnus-killed-hashtb
1118 (gnus-make-hashtable-from-killed))
1119 ;; Go though every newsgroup in `gnus-active-hashtb' and compare
1120 ;; with `gnus-newsrc-hashtb' and `gnus-killed-hashtb'.
1123 (if (or (null (setq group
(symbol-name sym
)))
1125 (null (symbol-value sym
))
1126 (gnus-gethash group gnus-killed-hashtb
)
1127 (gnus-gethash group gnus-newsrc-hashtb
))
1129 (let ((do-sub (gnus-matches-options-n group
)))
1131 ((eq do-sub
'subscribe
)
1132 (setq groups
(1+ groups
))
1133 (gnus-sethash group group gnus-killed-hashtb
)
1134 (gnus-call-subscribe-functions
1135 gnus-subscribe-options-newsgroup-method group
))
1136 ((eq do-sub
'ignore
)
1139 (setq groups
(1+ groups
))
1140 (gnus-sethash group group gnus-killed-hashtb
)
1141 (if gnus-subscribe-hierarchical-interactive
1142 (push group new-newsgroups
)
1143 (gnus-call-subscribe-functions
1144 gnus-subscribe-newsgroup-method group
)))))))
1146 (when new-newsgroups
1147 (gnus-subscribe-hierarchical-interactive new-newsgroups
))
1149 (gnus-message 5 "%d new newsgroup%s arrived."
1150 groups
(if (> groups
1) "s have" " has"))
1151 (gnus-message 5 "No new newsgroups."))
1154 (defun gnus-matches-options-n (group)
1155 ;; Returns `subscribe' if the group is to be unconditionally
1156 ;; subscribed, `ignore' if it is to be ignored, and nil if there is
1157 ;; no match for the group.
1159 ;; First we check the two user variables.
1161 ((and gnus-options-subscribe
1162 (string-match gnus-options-subscribe group
))
1164 ((let ((do-subscribe nil
))
1165 (dolist (category gnus-auto-subscribed-categories
)
1166 (when (gnus-member-of-valid category group
)
1167 (setq do-subscribe t
)))
1170 ((and gnus-auto-subscribed-groups
1171 (string-match gnus-auto-subscribed-groups group
))
1173 ((and gnus-options-not-subscribe
1174 (string-match gnus-options-not-subscribe group
))
1176 ;; Then we go through the list that was retrieved from the .newsrc
1177 ;; file. This list has elements on the form
1178 ;; `(REGEXP . {ignore,subscribe})'. The first match found (the list
1179 ;; is in the reverse order of the options line) is returned.
1181 (let ((regs gnus-newsrc-options-n
))
1183 (not (string-match (caar regs
) group
)))
1184 (setq regs
(cdr regs
)))
1185 (and regs
(cdar regs
))))))
1187 (defun gnus-ask-server-for-new-groups ()
1188 (let* ((new-date (message-make-date))
1189 (date (or gnus-newsrc-last-checked-date new-date
))
1190 (methods (cons gnus-select-method
1192 (when (gnus-archive-server-wanted-p)
1195 (and (consp gnus-check-new-newsgroups
)
1196 gnus-check-new-newsgroups
)
1197 gnus-secondary-select-methods
))))
1199 group new-newsgroups got-new method hashtb
1200 gnus-override-subscribe-method
)
1201 (unless gnus-killed-hashtb
1202 (gnus-make-hashtable-from-killed))
1203 ;; Go through both primary and secondary select methods and
1204 ;; request new newsgroups.
1205 (while (setq method
(gnus-server-get-method nil
(pop methods
)))
1206 (setq new-newsgroups nil
1207 gnus-override-subscribe-method method
)
1208 (when (and (gnus-check-server method
)
1209 (gnus-request-newgroups date method
))
1212 hashtb
(gnus-make-hashtable 100))
1213 (set-buffer nntp-server-buffer
)
1214 ;; Enter all the new groups into a hashtable.
1215 (gnus-active-to-gnus-format method hashtb
'ignore
))
1216 ;; Now all new groups from `method' are in `hashtb'.
1219 (if (or (null (setq group
(symbol-name group-sym
)))
1220 (not (boundp group-sym
))
1221 (null (symbol-value group-sym
))
1222 (gnus-gethash group gnus-newsrc-hashtb
)
1223 (member group gnus-zombie-list
)
1224 (member group gnus-killed-list
))
1225 ;; The group is already known.
1227 ;; Make this group active.
1228 (when (symbol-value group-sym
)
1229 (gnus-set-active group
(symbol-value group-sym
)))
1230 ;; Check whether we want it or not.
1231 (let ((do-sub (gnus-matches-options-n group
)))
1233 ((eq do-sub
'subscribe
)
1235 (gnus-sethash group group gnus-killed-hashtb
)
1236 (gnus-call-subscribe-functions
1237 gnus-subscribe-options-newsgroup-method group
))
1238 ((eq do-sub
'ignore
)
1242 (gnus-sethash group group gnus-killed-hashtb
)
1243 (if gnus-subscribe-hierarchical-interactive
1244 (push group new-newsgroups
)
1245 (gnus-call-subscribe-functions
1246 gnus-subscribe-newsgroup-method group
)))))))
1248 (when new-newsgroups
1249 (gnus-subscribe-hierarchical-interactive new-newsgroups
)))
1251 (gnus-message 5 "%d new newsgroup%s arrived"
1252 groups
(if (> groups
1) "s have" " has"))
1253 (gnus-message 5 "No new newsgroups"))
1255 (setq gnus-newsrc-last-checked-date new-date
))
1258 (defun gnus-subscribe-group (group &optional previous method
)
1259 "Subscribe GROUP and put it after PREVIOUS."
1260 (gnus-group-change-level
1262 (list t group gnus-level-default-subscribed nil nil method
)
1264 gnus-level-default-subscribed gnus-level-killed previous t
)
1267 ;; `gnus-group-change-level' is the fundamental function for changing
1268 ;; subscription levels of newsgroups. This might mean just changing
1269 ;; from level 1 to 2, which is pretty trivial, from 2 to 6 or back
1270 ;; again, which subscribes/unsubscribes a group, which is equally
1271 ;; trivial. Changing from 1-7 to 8-9 means that you kill a group, and
1272 ;; from 8-9 to 1-7 means that you remove the group from the list of
1273 ;; killed (or zombie) groups and add them to the (kinda) subscribed
1274 ;; groups. And last but not least, moving from 8 to 9 and 9 to 8,
1275 ;; which is trivial.
1276 ;; ENTRY can either be a string (newsgroup name) or a list (if
1277 ;; FROMKILLED is t, it's a list on the format (NUM INFO-LIST),
1278 ;; otherwise it's a list in the format of the `gnus-newsrc-hashtb'
1280 ;; LEVEL is the new level of the group, OLDLEVEL is the old level and
1281 ;; PREVIOUS is the group (in hashtb entry format) to insert this group
1283 (defun gnus-group-change-level (entry level
&optional oldlevel
1284 previous fromkilled
)
1285 (let (group info active num
)
1286 ;; Glean what info we can from the arguments
1288 (if fromkilled
(setq group
(nth 1 entry
))
1289 (setq group
(car (nth 2 entry
))))
1291 (when (and (stringp entry
)
1293 (< oldlevel gnus-level-zombie
))
1294 (setq entry
(gnus-group-entry entry
)))
1295 (if (and (not oldlevel
)
1297 (setq oldlevel
(gnus-info-level (nth 2 entry
)))
1298 (setq oldlevel
(or oldlevel gnus-level-killed
)))
1299 (when (stringp previous
)
1300 (setq previous
(gnus-group-entry previous
)))
1302 (if (and (>= oldlevel gnus-level-zombie
)
1303 (gnus-group-entry group
))
1304 ;; We are trying to subscribe a group that is already
1308 (unless (gnus-ephemeral-group-p group
)
1310 (format "(gnus-group-change-level %S %S %S %S %S)"
1311 group level oldlevel
(car (nth 2 previous
)) fromkilled
)))
1313 ;; Then we remove the newgroup from any old structures, if needed.
1314 ;; If the group was killed, we remove it from the killed or zombie
1315 ;; list. If not, and it is in fact going to be killed, we remove
1316 ;; it from the newsrc hash table and assoc.
1318 ((>= oldlevel gnus-level-zombie
)
1319 ;; oldlevel could be wrong.
1320 (setq gnus-zombie-list
(delete group gnus-zombie-list
))
1321 (setq gnus-killed-list
(delete group gnus-killed-list
)))
1323 (when (and (>= level gnus-level-zombie
)
1325 (gnus-sethash (car (nth 2 entry
)) nil gnus-newsrc-hashtb
)
1327 (setcdr (gnus-group-entry (car (nth 3 entry
)))
1329 (setcdr (cdr entry
) (cdddr entry
)))))
1331 ;; Finally we enter (if needed) the list where it is supposed to
1332 ;; go, and change the subscription level. If it is to be killed,
1333 ;; we enter it into the killed or zombie list.
1335 ((>= level gnus-level-zombie
)
1336 ;; Remove from the hash table.
1337 (gnus-sethash group nil gnus-newsrc-hashtb
)
1338 (if (= level gnus-level-zombie
)
1339 (push group gnus-zombie-list
)
1340 (if (= oldlevel gnus-level-killed
)
1341 ;; Remove from active hashtb.
1342 (unintern group gnus-active-hashtb
)
1343 ;; Don't add it into killed-list if it was killed.
1344 (push group gnus-killed-list
))))
1346 ;; If the list is to be entered into the newsrc assoc, and
1347 ;; it was killed, we have to create an entry in the newsrc
1348 ;; hashtb format and fix the pointers in the newsrc assoc.
1349 (if (< oldlevel gnus-level-zombie
)
1350 ;; It was alive, and it is going to stay alive, so we
1351 ;; just change the level and don't change any pointers or
1352 ;; hash table entries.
1353 (setcar (cdaddr entry
) level
)
1355 (setq info
(cdr entry
)
1357 (setq active
(gnus-active group
))
1359 (if active
(- (1+ (cdr active
)) (car active
)) t
))
1360 ;; Shorten the select method if possible, if we need to
1361 ;; store it at all (native groups).
1362 (let ((method (gnus-method-simplify
1363 (or gnus-override-subscribe-method
1364 (gnus-group-method group
)))))
1366 (setq info
(list group level nil nil method
))
1367 (setq info
(list group level nil
)))))
1370 (let ((p gnus-newsrc-alist
))
1374 (setq entry
(cons info
(cddr previous
)))
1377 (setcdr (cdr previous
) entry
)
1378 (gnus-sethash group
(cons num
(cdr previous
))
1379 gnus-newsrc-hashtb
))
1380 (setcdr previous entry
)
1381 (gnus-sethash group
(cons num previous
)
1382 gnus-newsrc-hashtb
))
1384 (setcdr (gnus-group-entry (caadr entry
)) entry
))
1386 (format "(gnus-group-set-info '%S)" info
)
1387 (concat "^(gnus-group-set-info '(\"" (regexp-quote group
) "\"")))))
1388 (when gnus-group-change-level-function
1389 (funcall gnus-group-change-level-function
1390 group level oldlevel previous
)))))
1392 (defun gnus-check-bogus-newsgroups (&optional confirm
)
1393 "Remove bogus newsgroups.
1394 If CONFIRM is non-nil, the user has to confirm the deletion of every
1396 (let ((newsrc (cdr gnus-newsrc-alist
))
1397 bogus group entry info
)
1398 (gnus-message 5 "Checking bogus newsgroups...")
1399 (unless (gnus-read-active-file-p)
1400 (gnus-read-active-file t
))
1401 (when (gnus-read-active-file-p)
1402 ;; Find all bogus newsgroup that are subscribed.
1404 (setq info
(pop newsrc
)
1405 group
(gnus-info-group info
))
1406 (unless (or (gnus-active group
) ; Active
1407 (and (gnus-info-method info
)
1408 (not (gnus-secondary-method-p
1409 (gnus-info-method info
))))) ; Foreign
1410 ;; Found a bogus newsgroup.
1411 (push group bogus
)))
1414 (format "Remove bogus group %%s (of %d groups)? " (length bogus
))
1416 ;; Remove all bogus subscribed groups by first killing them, and
1417 ;; then removing them from the list of killed groups.
1418 (when (setq entry
(gnus-group-entry group
))
1419 (gnus-group-change-level entry gnus-level-killed
)
1420 (setq gnus-killed-list
(delete group gnus-killed-list
))))
1421 bogus
'("group" "groups" "remove"))
1422 (while (setq group
(pop bogus
))
1423 ;; Remove all bogus subscribed groups by first killing them, and
1424 ;; then removing them from the list of killed groups.
1425 (when (setq entry
(gnus-group-entry group
))
1426 (gnus-group-change-level entry gnus-level-killed
)
1427 (setq gnus-killed-list
(delete group gnus-killed-list
)))))
1428 ;; Then we remove all bogus groups from the list of killed and
1429 ;; zombie groups. They are removed without confirmation.
1430 (let ((dead-lists '(gnus-killed-list gnus-zombie-list
))
1433 (setq killed
(symbol-value (car dead-lists
)))
1435 (unless (gnus-active (setq group
(pop killed
)))
1436 ;; The group is bogus.
1438 (set (car dead-lists
)
1439 (delete group
(symbol-value (car dead-lists
))))))
1440 (setq dead-lists
(cdr dead-lists
))))
1441 (gnus-run-hooks 'gnus-check-bogus-groups-hook
)
1442 (gnus-message 5 "Checking bogus newsgroups...done"))))
1444 (defun gnus-check-duplicate-killed-groups ()
1445 "Remove duplicates from the list of killed groups."
1447 (let ((killed gnus-killed-list
))
1449 (gnus-message 9 "%d" (length killed
))
1450 (setcdr killed
(delete (car killed
) (cdr killed
)))
1451 (setq killed
(cdr killed
)))))
1453 ;; We want to inline a function from gnus-cache, so we cheat here:
1454 (defvar gnus-cache-active-hashtb
)
1456 (defun gnus-cache-possibly-alter-active (group active
)
1457 "Alter the ACTIVE info for GROUP to reflect the articles in the cache."
1458 (when gnus-cache-active-hashtb
1459 (let ((cache-active (gnus-gethash group gnus-cache-active-hashtb
)))
1461 (when (< (car cache-active
) (car active
))
1462 (setcar active
(car cache-active
)))
1463 (when (> (cdr cache-active
) (cdr active
))
1464 (setcdr active
(cdr cache-active
))))))))
1466 (defun gnus-activate-group (group &optional scan dont-check method
1468 "Check whether a group has been activated or not.
1469 If SCAN, request a scan of that group as well. If METHOD, use
1470 that select method instead of determining the method based on the
1471 group name. If DONT-CHECK, don't check whether the group
1472 actually exists. If DONT-SUB-CHECK or DONT-CHECK, don't let the
1473 backend check whether the group actually exists."
1474 (let ((method (or method
(inline (gnus-find-method-for-group group
))))
1476 (and (inline (gnus-check-server method
))
1477 ;; We escape all bugs and quit here to make it possible to
1478 ;; continue if a group is so out-there that it reports bugs
1482 (gnus-check-backend-function 'request-scan
(car method
))
1483 (gnus-request-scan group method
))
1485 (if (or debug-on-error debug-on-quit
)
1486 (inline (gnus-request-group group
(or dont-sub-check dont-check
)
1488 (gnus-get-info group
)))
1490 (inline (gnus-request-group group
(or dont-sub-check dont-check
)
1492 (gnus-get-info group
)))
1496 (message "Quit activating %s" group
))
1499 (setq active
(gnus-parse-active))
1500 ;; If there are no articles in the group, the GROUP
1501 ;; command may have responded with the `(0 . 0)'. We
1502 ;; ignore this if we already have an active entry
1504 (if (and (zerop (or (car active
) 0))
1505 (zerop (or (cdr active
) 0))
1506 (gnus-active group
))
1509 ;; If a cache is present, we may have to alter the active info.
1510 (when gnus-use-cache
1511 (inline (gnus-cache-possibly-alter-active
1514 ;; If the agent is enabled, we may have to alter the active info.
1516 (gnus-agent-possibly-alter-active group active
))
1518 (gnus-set-active group active
)
1519 ;; Return the new active info.
1522 (defun gnus-get-unread-articles-in-group (info active
&optional update
)
1523 (when (and info active
)
1524 ;; Allow the backend to update the info in the group.
1526 (gnus-request-update-info
1527 info
(inline (gnus-find-method-for-group
1528 (gnus-info-group info
)))))
1529 (gnus-activate-group (gnus-info-group info
) nil t
))
1531 (let* ((range (gnus-info-read info
))
1534 ;; These checks are present in gnus-activate-group but skipped
1535 ;; due to setting dont-check in the preceding call.
1537 ;; If a cache is present, we may have to alter the active info.
1538 (when (and gnus-use-cache info
)
1539 (inline (gnus-cache-possibly-alter-active
1540 (gnus-info-group info
) active
)))
1542 ;; If the agent is enabled, we may have to alter the active info.
1543 (when (and gnus-agent info
)
1544 (gnus-agent-possibly-alter-active (gnus-info-group info
) active info
))
1546 ;; Modify the list of read articles according to what articles
1547 ;; are available; then tally the unread articles and add the
1548 ;; number to the group hash table entry.
1550 ((zerop (cdr active
))
1553 (setq num
(- (1+ (cdr active
)) (car active
))))
1554 ((not (listp (cdr range
)))
1555 ;; Fix a single (num . num) range according to the
1556 ;; active hash table.
1557 ;; Fix by Carsten Bormann <cabo@Informatik.Uni-Bremen.DE>.
1558 (and (< (cdr range
) (car active
)) (setcdr range
(1- (car active
))))
1559 (and (> (cdr range
) (cdr active
)) (setcdr range
(cdr active
)))
1560 ;; Compute number of unread articles.
1561 (setq num
(max 0 (- (cdr active
) (- (1+ (cdr range
)) (car range
))))))
1563 ;; The read list is a list of ranges. Fix them according to
1564 ;; the active hash table.
1565 ;; First peel off any elements that are below the lower
1567 (while (and (cdr range
)
1569 (or (and (atom (cadr range
)) (cadr range
))
1571 (if (numberp (car range
))
1574 (or (and (numberp (cadr range
))
1578 (or (and (numberp (nth 1 range
)) (nth 1 range
))
1580 (setcdr range
(cddr range
)))
1581 ;; Adjust the first element to be the same as the lower limit.
1582 (when (and (not (atom (car range
)))
1583 (< (cdar range
) (car active
)))
1584 (setcdr (car range
) (1- (car active
))))
1585 ;; Then we want to peel off any elements that are higher
1586 ;; than the upper active limit.
1587 (let ((srange range
))
1588 ;; Go past all valid elements.
1589 (while (and (cdr srange
)
1590 (<= (or (and (atom (cadr srange
))
1594 (setq srange
(cdr srange
)))
1596 ;; Nuke all remaining invalid elements.
1597 (setcdr srange nil
))
1599 ;; Adjust the final element.
1600 (when (and (not (atom (car srange
)))
1601 (> (cdar srange
) (cdr active
)))
1602 (setcdr (car srange
) (cdr active
))))
1603 ;; Compute the number of unread articles.
1605 (setq num
(+ num
(- (1+ (or (and (atom (car range
)) (car range
))
1607 (or (and (atom (car range
)) (car range
))
1609 (setq range
(cdr range
)))
1610 (setq num
(max 0 (- (cdr active
) num
)))))
1611 ;; Set the number of unread articles.
1613 (gnus-group-entry (gnus-info-group info
)))
1614 (setcar (gnus-group-entry (gnus-info-group info
)) num
))
1617 ;; Go though `gnus-newsrc-alist' and compare with `gnus-active-hashtb'
1618 ;; and compute how many unread articles there are in each group.
1619 (defun gnus-get-unread-articles (&optional level dont-connect one-level
)
1620 (setq gnus-server-method-cache nil
)
1621 (require 'gnus-agent
)
1622 (let* ((newsrc (cdr gnus-newsrc-alist
))
1623 (alevel (or level gnus-activate-level
(1+ gnus-level-subscribed
)))
1628 (cond ((and gnus-activate-foreign-newsgroups
1629 (not (numberp gnus-activate-foreign-newsgroups
)))
1630 (1+ gnus-level-subscribed
))
1631 ((numberp gnus-activate-foreign-newsgroups
)
1632 gnus-activate-foreign-newsgroups
)
1637 (gnus-agent-article-local-times 0)
1638 (archive-method (gnus-server-to-method "archive"))
1639 infos info group active method cmethod
1640 method-type method-group-list entry
)
1641 (gnus-message 6 "Checking new news...")
1644 (setq active
(gnus-active (setq group
(gnus-info-group
1645 (setq info
(pop newsrc
))))))
1646 ;; First go through all the groups, see what select methods they
1647 ;; belong to, and then collect them into lists per unique select
1649 (if (not (setq method
(gnus-info-method info
)))
1650 (setq method gnus-select-method
)
1651 ;; There may be several similar methods. Possibly extend the
1653 (if (setq cmethod
(assoc method methods-cache
))
1654 (setq method
(cdr cmethod
))
1655 (setq cmethod
(if (stringp method
)
1656 (gnus-server-to-method method
)
1657 (inline (gnus-find-method-for-group
1658 (gnus-info-group info
) info
))))
1659 (push (cons method cmethod
) methods-cache
)
1660 (setq method cmethod
)))
1661 (setq method-group-list
(assoc method type-cache
))
1662 (unless method-group-list
1665 ((or (gnus-secondary-method-p method
)
1666 (and (gnus-archive-server-wanted-p)
1667 (gnus-methods-equal-p archive-method method
)))
1669 ((inline (gnus-server-equal gnus-select-method method
))
1673 (push (setq method-group-list
(list method method-type nil nil
))
1675 ;; Only add groups that need updating.
1676 (if (or (and foreign-level
(null (numberp foreign-level
)))
1677 (funcall (if one-level
#'= #'<=) (gnus-info-level info
)
1678 (if (eq (cadr method-group-list
) 'foreign
)
1681 (setcar (nthcdr 2 method-group-list
)
1682 (cons info
(nth 2 method-group-list
)))
1683 ;; The group is inactive, so we nix out the number of unread articles.
1684 ;; It leads `(gnus-group-unread group)' to return t. See also
1685 ;; `gnus-group-prepare-flat'.
1687 (when (setq entry
(gnus-group-entry group
))
1688 (setcar entry t
)))))
1690 ;; Sort the methods based so that the primary and secondary
1691 ;; methods come first. This is done for legacy reasons to try to
1692 ;; ensure that side-effect behavior doesn't change from previous
1695 (sort (nreverse type-cache
)
1697 (< (gnus-method-rank (cadr c1
) (car c1
))
1698 (gnus-method-rank (cadr c2
) (car c2
))))))
1699 ;; Go through the list of servers and possibly extend methods that
1700 ;; aren't equal (and that need extension; i.e., they are async).
1701 (let ((methods nil
))
1702 (dolist (elem type-cache
)
1703 (destructuring-bind (method method-type infos dummy
) elem
1704 (let ((gnus-opened-servers methods
))
1705 (when (and (gnus-similar-server-opened method
)
1706 (gnus-check-backend-function
1707 'retrieve-group-data-early
(car method
)))
1708 (setq method
(gnus-server-extend-method
1709 (gnus-info-group (car infos
))
1711 (setcar elem method
))
1712 (push (list method
'ok
) methods
)))))
1714 ;; If we have primary/secondary select methods, but no groups from
1715 ;; them, we still want to issue a retrieval request from them.
1716 (unless dont-connect
1717 (dolist (method (cons gnus-select-method
1718 gnus-secondary-select-methods
))
1719 (when (and (not (assoc method type-cache
))
1720 (gnus-check-backend-function 'request-list
(car method
)))
1721 (with-current-buffer nntp-server-buffer
1722 (gnus-read-active-file-1 method nil
)))))
1724 ;; Clear out all the early methods.
1725 (dolist (elem type-cache
)
1726 (destructuring-bind (method method-type infos dummy
) elem
1729 (gnus-check-backend-function
1730 'retrieve-group-data-early
(car method
))
1731 (not (gnus-method-denied-p method
)))
1732 (when (ignore-errors (gnus-get-function method
'open-server
))
1733 (unless (gnus-server-opened method
)
1734 (gnus-open-server method
))
1735 (when (gnus-server-opened method
)
1736 ;; Just mark this server as "cleared".
1737 (gnus-retrieve-group-data-early method nil
))))))
1739 ;; Start early async retrieval of data.
1740 (let ((done-methods nil
)
1742 (dolist (elem type-cache
)
1743 (destructuring-bind (method method-type infos dummy
) elem
1744 (setq sanity-spec
(list (car method
) (cadr method
)))
1745 (when (and method infos
1746 (not (gnus-method-denied-p method
)))
1747 ;; If the open-server method doesn't exist, then the method
1748 ;; itself doesn't exist, so we ignore it.
1749 (if (not (ignore-errors (gnus-get-function method
'open-server
)))
1750 (setq type-cache
(delq elem type-cache
))
1751 (unless (gnus-server-opened method
)
1752 (gnus-open-server method
))
1754 ;; This is a sanity check, so that we never
1755 ;; attempt to start two async requests to the
1756 ;; same server, because that will fail. This
1757 ;; should never happen, since the methods should
1758 ;; be unique at this point, but apparently it
1759 ;; does happen in the wild with some setups.
1760 (not (member sanity-spec done-methods
))
1761 (gnus-server-opened method
)
1762 (gnus-check-backend-function
1763 'retrieve-group-data-early
(car method
)))
1764 (push sanity-spec done-methods
)
1765 (when (gnus-check-backend-function 'request-scan
(car method
))
1766 (gnus-request-scan nil method
))
1767 ;; Store the token we get back from -early so that we
1768 ;; can pass it to -finish later.
1769 (setcar (nthcdr 3 elem
)
1770 (gnus-retrieve-group-data-early method infos
))))))))
1772 ;; Do the rest of the retrieval.
1773 (dolist (elem type-cache
)
1774 (destructuring-bind (method method-type infos early-data
) elem
1775 (when (and method infos
1776 (not (gnus-method-denied-p method
)))
1777 (let ((updatep (gnus-check-backend-function
1778 'request-update-info
(car method
))))
1779 ;; See if any of the groups from this method require updating.
1780 (gnus-read-active-for-groups method infos early-data
)
1781 (dolist (info infos
)
1782 (inline (gnus-get-unread-articles-in-group
1783 info
(gnus-active (gnus-info-group info
))
1785 (gnus-message 6 "Checking new news...done")))
1787 (defun gnus-method-rank (type method
)
1789 ;; Get info for virtual groups last.
1790 ((eq (car method
) 'nnvirtual
)
1794 ;; Compute the rank of the secondary methods based on where they
1795 ;; are in the secondary select list.
1796 ((eq type
'secondary
)
1799 (dolist (smethod gnus-secondary-select-methods
)
1800 (when (equal method smethod
)
1804 ;; Just say that all foreign groups have the same rank.
1808 (defun gnus-read-active-for-groups (method infos early-data
)
1809 (with-current-buffer nntp-server-buffer
1811 ;; Finish up getting the data from the methods that have -early
1815 (gnus-check-backend-function 'finish-retrieve-group-infos
(car method
))
1816 (or (not (gnus-agent-method-p method
))
1817 (gnus-online method
)))
1818 (gnus-finish-retrieve-group-infos method infos early-data
)
1819 ;; We may have altered the data now, so mark the dribble buffer
1820 ;; as dirty so that it gets saved.
1821 (gnus-dribble-touch)
1822 (gnus-agent-save-active method
))
1823 ;; Most backends have -retrieve-groups.
1824 ((gnus-check-backend-function 'retrieve-groups
(car method
))
1825 (when (gnus-check-backend-function 'request-scan
(car method
))
1826 (gnus-request-scan nil method
))
1828 (gnus-read-active-file-2
1829 (dolist (info infos
(nreverse groups
))
1830 (push (gnus-group-real-name (gnus-info-group info
)) groups
))
1832 ;; Virtually all backends have -request-list.
1833 ((gnus-check-backend-function 'request-list
(car method
))
1834 (gnus-read-active-file-1 method nil
))
1835 ;; Except nnvirtual and friends, where we request each group, one
1838 (dolist (info infos
)
1839 (gnus-activate-group (gnus-info-group info
) nil nil method t
))))))
1841 ;; Create a hash table out of the newsrc alist. The `car's of the
1842 ;; alist elements are used as keys.
1843 (defun gnus-make-hashtable-from-newsrc-alist ()
1844 (let ((alist gnus-newsrc-alist
)
1845 (ohashtb gnus-newsrc-hashtb
)
1846 prev info method rest methods
)
1847 (setq gnus-newsrc-hashtb
(gnus-make-hashtable (length alist
)))
1849 (setq prev
(setq gnus-newsrc-alist
1850 (if (equal (caar gnus-newsrc-alist
)
1853 (cons (list "dummy.group" 0 nil
) alist
)))))
1855 (setq info
(car alist
))
1856 ;; Make the same select-methods identical Lisp objects.
1857 (when (setq method
(gnus-info-method info
))
1858 (if (setq rest
(member method methods
))
1859 (gnus-info-set-method info
(car rest
))
1860 (push method methods
)))
1861 ;; Check for duplicates.
1862 (if (gnus-gethash (car info
) gnus-newsrc-hashtb
)
1863 ;; Remove this entry from the alist.
1864 (setcdr prev
(cddr prev
))
1867 ;; Preserve number of unread articles in groups.
1868 (cons (and ohashtb
(car (gnus-gethash (car info
) ohashtb
)))
1872 (setq alist
(cdr alist
)))
1873 ;; Make the same select-methods in `gnus-server-alist' identical
1876 (setq method
(pop methods
))
1877 (when (setq rest
(rassoc method gnus-server-alist
))
1878 (setcdr rest method
)))))
1880 (defun gnus-make-hashtable-from-killed ()
1881 "Create a hash table from the killed and zombie lists."
1882 (let ((lists '(gnus-killed-list gnus-zombie-list
))
1884 (setq gnus-killed-hashtb
1885 (gnus-make-hashtable
1886 (+ (length gnus-killed-list
) (length gnus-zombie-list
))))
1888 (setq list
(symbol-value (pop lists
)))
1890 (gnus-sethash (car list
) (pop list
) gnus-killed-hashtb
)))))
1892 (defun gnus-parse-active ()
1893 "Parse active info in the nntp server buffer."
1894 (with-current-buffer nntp-server-buffer
1895 (goto-char (point-min))
1896 ;; Parse the result we got from `gnus-request-group'.
1897 (when (looking-at "[0-9]+ [0-9]+ \\([0-9]+\\) [0-9]+")
1898 (goto-char (match-beginning 1))
1899 (cons (read (current-buffer))
1900 (read (current-buffer))))))
1902 (defun gnus-make-articles-unread (group articles
)
1903 "Mark ARTICLES in GROUP as unread."
1904 (let* ((info (nth 2 (or (gnus-group-entry group
)
1906 (gnus-group-real-name group
)))))
1907 (ranges (gnus-info-read info
))
1910 (when (gnus-member-of-range
1911 (setq article
(pop articles
)) ranges
)
1912 (push article news
)))
1914 ;; Enter this list into the group info.
1916 info
(gnus-remove-from-range (gnus-info-read info
) (nreverse news
)))
1918 ;; Set the number of unread articles in gnus-newsrc-hashtb.
1919 (gnus-get-unread-articles-in-group info
(gnus-active group
))
1921 ;; Insert the change into the group buffer and the dribble file.
1922 (gnus-group-update-group group t
))))
1924 (defun gnus-make-ascending-articles-unread (group articles
)
1925 "Mark ascending ARTICLES in GROUP as unread."
1926 (let* ((entry (or (gnus-group-entry group
)
1927 (gnus-group-entry (gnus-group-real-name group
))))
1928 (info (nth 2 entry
))
1929 (ranges (gnus-info-read info
))
1934 (let ((article (pop articles
))) ; get the next article to remove from ranges
1935 (while (let ((range (car ranges
))) ; note the current range
1936 (if (atom range
) ; single value range
1938 ;; the articles extend past the end of the ranges
1940 (setq articles nil
))
1942 ;; this range precedes the article. Leave the range unmodified.
1946 ;; this range exactly matches the article; REMOVE THE RANGE.
1947 ;; NOTE: When the range being removed is the last range, the list is corrupted by inserting null at its end.
1948 (setcar ranges
(cadr ranges
))
1949 (setcdr ranges
(cddr ranges
))
1950 (setq modified
(if (car ranges
) t
'remove-null
))
1952 (let ((min (car range
))
1954 ;; I have a min/max range to consider
1955 (cond ((> min max
) ; invalid range introduced by splitter
1956 (setcar ranges
(cadr ranges
))
1957 (setcdr ranges
(cddr ranges
))
1958 (setq modified
(if (car ranges
) t
'remove-null
))
1961 ;; replace min/max range with a single-value range
1965 ;; this range precedes the article. Leave the range unmodified.
1969 ;; this article precedes the range. Return null to move to the
1973 ;; this article splits the range into two parts
1974 (setcdr ranges
(cons (cons (1+ article
) max
) (cdr ranges
)))
1975 (setcdr range
(1- article
))
1980 (when (eq modified
'remove-null
)
1981 (setq r
(delq nil r
)))
1982 ;; Enter this list into the group info.
1983 (gnus-info-set-read info r
)
1985 ;; Set the number of unread articles in gnus-newsrc-hashtb.
1986 (gnus-get-unread-articles-in-group info
(gnus-active group
))
1988 ;; Insert the change into the group buffer and the dribble file.
1989 (gnus-group-update-group group t
))))
1991 ;; Enter all dead groups into the hashtb.
1992 (defun gnus-update-active-hashtb-from-killed ()
1993 (let ((hashtb (setq gnus-active-hashtb
(gnus-make-hashtable 4096)))
1994 (lists (list gnus-killed-list gnus-zombie-list
))
1997 (setq killed
(car lists
))
1999 (gnus-sethash (string-as-unibyte (car killed
)) nil hashtb
)
2000 (setq killed
(cdr killed
)))
2001 (setq lists
(cdr lists
)))))
2003 (defun gnus-get-killed-groups ()
2004 "Go through the active hashtb and mark all unknown groups as killed."
2005 ;; First make sure active file has been read.
2006 (unless (gnus-read-active-file-p)
2007 (let ((gnus-read-active-file t
))
2008 (gnus-read-active-file)))
2009 (unless gnus-killed-hashtb
2010 (gnus-make-hashtable-from-killed))
2011 ;; Go through all newsgroups that are known to Gnus - enlarge kill list.
2015 (group (symbol-name sym
)))
2016 (if (or (null group
)
2017 (gnus-gethash group gnus-killed-hashtb
)
2018 (gnus-gethash group gnus-newsrc-hashtb
))
2020 (let ((do-sub (gnus-matches-options-n group
)))
2021 (if (or (eq do-sub
'subscribe
) (eq do-sub
'ignore
))
2023 (setq groups
(1+ groups
))
2024 (push group gnus-killed-list
)
2025 (gnus-sethash group group gnus-killed-hashtb
))))))
2027 (gnus-dribble-touch))
2029 ;; Get the active file(s) from the backend(s).
2030 (defun gnus-read-active-file (&optional force not-native
)
2031 (gnus-group-set-mode-line)
2034 (lambda (m) (if (stringp m
) (gnus-server-get-method nil m
) m
))
2036 (if (and (not not-native
)
2037 (gnus-check-server gnus-select-method
))
2038 ;; The native server is available.
2039 (cons gnus-select-method gnus-secondary-select-methods
)
2040 ;; The native server is down, so we just do the
2042 gnus-secondary-select-methods
)
2043 ;; Also read from the archive server.
2044 (when (gnus-archive-server-wanted-p)
2045 (list "archive")))))
2047 (setq gnus-have-read-active-file nil
)
2048 (with-current-buffer nntp-server-buffer
2049 (while (setq method
(pop methods
))
2050 ;; Only do each method once, in case the methods appear more
2051 ;; than once in this list.
2052 (when (and (not (member method methods
))
2053 ;; Check whether the backend exists.
2054 (ignore-errors (gnus-get-function method
'open-server
)))
2055 (if (or debug-on-error debug-on-quit
)
2056 (gnus-read-active-file-1 method force
)
2058 (gnus-read-active-file-1 method force
)
2059 ;; We catch C-g so that we can continue past servers
2060 ;; that do not respond.
2064 (message "Quit reading the active file"))
2067 (defun gnus-read-active-file-1 (method force
)
2069 (setq where
(nth 1 method
)
2070 mesg
(format "Reading active file%s via %s..."
2071 (if (and where
(not (zerop (length where
))))
2072 (concat " from " where
) "")
2074 (gnus-message 5 "%s" mesg
)
2075 (when (gnus-check-server method
)
2076 ;; Request that the backend scan its incoming messages.
2077 (when (and (or (and gnus-agent
2078 (gnus-online method
))
2080 (gnus-check-backend-function 'request-scan
(car method
)))
2081 (gnus-request-scan nil method
))
2083 ((and (eq gnus-read-active-file
'some
)
2084 (gnus-check-backend-function 'retrieve-groups
(car method
))
2086 (let ((newsrc (cdr gnus-newsrc-alist
))
2087 (gmethod (gnus-server-get-method nil method
))
2089 (while (setq info
(pop newsrc
))
2093 (gnus-find-method-for-group
2094 (gnus-info-group info
) info
))
2096 (push (gnus-group-real-name (gnus-info-group info
))
2098 (gnus-read-active-file-2 groups method
)))
2102 (if (not (gnus-request-list method
))
2103 (unless (equal method gnus-message-archive-method
)
2104 (gnus-error 1 "Cannot read active file from %s server"
2106 (gnus-message 5 "%s" mesg
)
2107 (gnus-active-to-gnus-format method gnus-active-hashtb nil t
)
2108 ;; We mark this active file as read.
2109 (add-to-list 'gnus-have-read-active-file method
)
2110 (gnus-message 5 "%sdone" mesg
)))))))
2112 (defun gnus-read-active-file-2 (groups method
)
2113 "Read an active file for GROUPS in METHOD using `gnus-retrieve-groups'."
2115 (with-current-buffer nntp-server-buffer
2116 (gnus-check-server method
)
2117 (let ((list-type (gnus-retrieve-groups groups method
)))
2118 (cond ((not list-type
)
2120 1.2 "Cannot read partial active file from %s server."
2122 ((eq list-type
'active
)
2123 (gnus-active-to-gnus-format method gnus-active-hashtb nil t
))
2125 (gnus-groups-to-gnus-format method gnus-active-hashtb t
)))))))
2127 ;; Read an active file and place the results in `gnus-active-hashtb'.
2128 (defun gnus-active-to-gnus-format (&optional method hashtb ignore-errors
2131 (setq method gnus-select-method
))
2132 (let ((cur (current-buffer))
2134 (if (and gnus-active-hashtb
2135 (not (equal method gnus-select-method
)))
2137 (setq gnus-active-hashtb
2138 (if (equal method gnus-select-method
)
2139 (gnus-make-hashtable
2140 (count-lines (point-min) (point-max)))
2141 (gnus-make-hashtable 4096))))))
2143 ;; Delete unnecessary lines.
2144 (goto-char (point-min))
2146 ((string= gnus-ignored-newsgroups
"")
2147 (delete-matching-lines "^to\\."))
2149 (delete-matching-lines (concat "^to\\.\\|" gnus-ignored-newsgroups
))))
2151 (goto-char (point-min))
2152 (unless (re-search-forward "[\\\"]" nil t
)
2153 ;; Make the group names readable as a lisp expression even if they
2154 ;; contain special characters.
2155 (goto-char (point-max))
2156 (while (re-search-backward "[][';?()#]" nil t
)
2159 ;; Let the Gnus agent save the active file.
2160 (when (and gnus-agent real-active
(gnus-online method
))
2161 (gnus-agent-save-active method
))
2163 ;; If these are groups from a foreign select method, we insert the
2164 ;; group prefix in front of the group names.
2165 (when (not (gnus-server-equal
2166 (gnus-server-get-method nil method
)
2167 (gnus-server-get-method nil gnus-select-method
)))
2168 (let ((prefix (gnus-group-prefixed-name "" method
)))
2169 (goto-char (point-min))
2170 (while (and (not (eobp))
2172 (when (= (following-char) ?
\")
2175 (zerop (forward-line 1)))))))
2176 ;; Store the active file in a hash table.
2177 ;; Use a unibyte buffer in order to make `read' read non-ASCII
2178 ;; group names (which have been encoded) as unibyte strings.
2179 (mm-with-unibyte-buffer
2180 (insert-buffer-substring cur
)
2181 (setq cur
(current-buffer))
2182 (goto-char (point-min))
2186 (narrow-to-region (point) (point-at-eol))
2187 ;; group gets set to a symbol interned in the hash table
2188 ;; (what a hack!!) - jwz
2189 (setq group
(let ((obarray hashtb
)) (read cur
)))
2190 ;; ### The extended group name scheme makes
2191 ;; the previous optimization strategy sort of pointless...
2192 (when (stringp group
)
2193 (setq group
(intern group hashtb
)))
2194 (if (and (numberp (setq max
(read cur
)))
2195 (numberp (setq min
(read cur
)))
2197 (skip-chars-forward " \t")
2199 (or (eq (char-after) ?
=)
2200 (eq (char-after) ?x
)
2201 (eq (char-after) ?j
)))))
2203 (set group
(cons min max
))
2204 ;; if group is moderated, stick in moderation table
2205 (when (eq (char-after) ?m
)
2206 (unless gnus-moderated-hashtb
2207 (setq gnus-moderated-hashtb
(gnus-make-hashtable)))
2208 (gnus-sethash (symbol-name group
) t
2209 gnus-moderated-hashtb
)))
2215 (unless ignore-errors
2216 (gnus-message 3 "Warning - invalid active: %s"
2218 (point-at-bol) (point-at-eol))))))
2220 (forward-line 1)))))
2222 (defun gnus-groups-to-gnus-format (method &optional hashtb real-active
)
2223 ;; Parse a "groups" active file.
2224 (let ((cur (current-buffer))
2226 (if (and method gnus-active-hashtb
)
2228 (setq gnus-active-hashtb
2229 (gnus-make-hashtable
2230 (count-lines (point-min) (point-max)))))))
2232 (not (gnus-server-equal
2233 (gnus-server-get-method nil method
)
2234 (gnus-server-get-method nil gnus-select-method
)))
2235 (gnus-group-prefixed-name "" method
))))
2237 ;; Let the Gnus agent save the active file.
2240 (gnus-online method
)
2241 (gnus-agent-method-p method
))
2243 (gnus-agent-save-active method t
)
2244 (gnus-active-to-gnus-format method hashtb nil real-active
))
2246 (goto-char (point-min))
2247 ;; We split this into to separate loops, one with the prefix
2248 ;; and one without to speed the reading up somewhat.
2250 (let (min max opoint group
)
2254 (read cur
) (read cur
)
2255 (setq min
(read cur
)
2258 (skip-chars-forward " \t")
2261 (set (let ((obarray hashtb
)) (read cur
))
2263 (error (and group
(symbolp group
) (set group nil
))))
2265 (let (min max group
)
2268 (when (eq (char-after) ?
2)
2269 (read cur
) (read cur
)
2270 (setq min
(read cur
)
2272 (set (setq group
(let ((obarray hashtb
)) (read cur
)))
2274 (error (and group
(symbolp group
) (set group nil
))))
2275 (forward-line 1)))))))
2277 (defun gnus-read-newsrc-file (&optional force
)
2279 If FORCE is non-nil, the .newsrc file is read."
2280 ;; Reset variables that might be defined in the .newsrc.eld file.
2281 (let ((variables (remove 'gnus-format-specs gnus-variable-list
)))
2283 (set (car variables
) nil
)
2284 (setq variables
(cdr variables
))))
2285 (let* ((newsrc-file gnus-current-startup-file
)
2286 (quick-file (concat newsrc-file
".el")))
2288 ;; We always load the .newsrc.eld file. If always contains
2289 ;; much information that can not be gotten from the .newsrc
2290 ;; file (ticked articles, killed groups, foreign methods, etc.)
2291 (gnus-read-newsrc-el-file quick-file
)
2293 (when (and gnus-read-newsrc-file
2294 (file-exists-p gnus-current-startup-file
)
2296 (and (file-newer-than-file-p newsrc-file quick-file
)
2297 (file-newer-than-file-p newsrc-file
2298 (concat quick-file
"d")))
2299 (not gnus-newsrc-alist
)))
2300 ;; We read the .newsrc file. Note that if there if a
2301 ;; .newsrc.eld file exists, it has already been read, and
2302 ;; the `gnus-newsrc-hashtb' has been created. While reading
2303 ;; the .newsrc file, Gnus will only use the information it
2304 ;; can find there for changing the data already read -
2305 ;; i. e., reading the .newsrc file will not trash the data
2306 ;; already read (except for read articles).
2308 (gnus-message 5 "Reading %s..." newsrc-file
)
2309 (set-buffer (nnheader-find-file-noselect newsrc-file
))
2310 (buffer-disable-undo)
2311 (gnus-newsrc-to-gnus-format)
2312 (kill-buffer (current-buffer))
2313 (gnus-message 5 "Reading %s...done" newsrc-file
)))
2315 ;; Convert old to new.
2316 (gnus-convert-old-newsrc)
2317 (gnus-clean-old-newsrc))))
2319 (defun gnus-clean-old-newsrc (&optional force
)
2320 ;; Currently no cleanups.
2323 (defun gnus-convert-old-newsrc ()
2324 "Convert old newsrc formats into the current format, if needed."
2325 (let ((fcv (and gnus-newsrc-file-version
2326 (gnus-continuum-version gnus-newsrc-file-version
)))
2327 (gcv (gnus-continuum-version)))
2329 ;; A newsrc file was loaded.
2330 (let (prompt-displayed
2333 (mapcar (lambda (date-func)
2334 (cons (gnus-continuum-version (car date-func
))
2336 ;; This is a list of converters that must be run
2337 ;; to bring the newsrc file up to the current
2338 ;; version. If you create an incompatibility
2339 ;; with older versions, you should create an
2340 ;; entry here. The entry should consist of the
2341 ;; current gnus version (hardcoded so that it
2342 ;; doesn't change with each release) and the
2343 ;; function that must be applied to convert the
2344 ;; previous version into the current version.
2345 '(("September Gnus v0.1" nil
2346 gnus-convert-old-ticks
)
2347 ("Oort Gnus v0.08" "legacy-gnus-agent"
2348 gnus-agent-convert-to-compressed-agentview
)
2349 ("Gnus v5.10.7" "legacy-gnus-agent"
2350 gnus-agent-unlist-expire-days
)
2351 ("Gnus v5.10.7" "legacy-gnus-agent"
2352 gnus-agent-unhook-expire-days
)))
2353 #'car-less-than-car
)))
2354 ;; Skip converters older than the file version
2355 (while (and converters
(>= fcv
(caar converters
)))
2358 ;; Perform converters to bring older version up to date.
2359 (when (and converters
(< fcv
(caar converters
)))
2360 (while (and converters
(< fcv
(caar converters
))
2361 (<= (caar converters
) gcv
))
2362 (let* ((converter-spec (pop converters
))
2363 (convert-to (nth 1 converter-spec
))
2364 (load-from (nth 2 converter-spec
))
2365 (func (nth 3 converter-spec
)))
2366 (when (and load-from
2367 (not (fboundp func
)))
2369 (or prompt-displayed
2370 (not (gnus-convert-converter-needs-prompt func
))
2372 (cursor-in-echo-area t
)
2373 (echo-keystrokes 0))
2374 (message "Convert gnus from version `%s' to `%s'? (n/y/?)"
2375 gnus-newsrc-file-version gnus-version
)
2376 (setq c
(read-char-exclusive))
2378 (cond ((or (eq c ?n
) (eq c ?N
))
2379 (error "Can not start gnus without converting"))
2380 ((or (eq c ?y
) (eq c ?Y
))
2381 (setq prompt-displayed t
)
2384 (message "This conversion is irreversible. \
2385 To be safe, you should backup your files before proceeding.")
2389 (gnus-message 3 "Ignoring unexpected input")
2393 (funcall func convert-to
)))
2395 (format-message ";Converted gnus from version `%s' to `%s'."
2396 gnus-newsrc-file-version gnus-version
)))))))
2398 (defun gnus-convert-mark-converter-prompt (converter no-prompt
)
2399 "Indicate whether CONVERTER requires gnus-convert-old-newsrc to
2400 display the conversion prompt. NO-PROMPT may be nil (prompt),
2401 t (no prompt), or any form that can be called as a function.
2402 The form should return either t or nil."
2403 (put converter
'gnus-convert-no-prompt no-prompt
))
2405 (defun gnus-convert-converter-needs-prompt (converter)
2406 (let ((no-prompt (get converter
'gnus-convert-no-prompt
)))
2407 (not (if (memq no-prompt
'(t nil
))
2409 (funcall no-prompt
)))))
2411 (defun gnus-convert-old-ticks (converting-to)
2412 (let ((newsrc (cdr gnus-newsrc-alist
))
2413 marks info dormant ticked
)
2414 (while (setq info
(pop newsrc
))
2415 (when (setq marks
(gnus-info-marks info
))
2416 (setq dormant
(cdr (assq 'dormant marks
))
2417 ticked
(cdr (assq 'tick marks
)))
2418 (when (or dormant ticked
)
2422 (gnus-info-read info
)
2423 (nconc (gnus-uncompress-range dormant
)
2424 (gnus-uncompress-range ticked
)))))))))
2426 (defun gnus-load (file)
2427 "Load FILE, but in such a way that read errors can be reported."
2429 (insert-file-contents file
)
2431 (condition-case type
2432 (let ((form (read (current-buffer))))
2435 (unless (eq (car type
) 'end-of-file
)
2436 (let ((errmsg (format "Error in %s line %d" file
2437 (count-lines (point-min) (point)))))
2439 (unless (gnus-yes-or-no-p (concat errmsg
"; continue? "))
2440 (error "%s" errmsg
)))))))))
2442 (defun gnus-read-newsrc-el-file (file)
2443 (let ((ding-file (concat file
"d")))
2444 (when (file-exists-p ding-file
)
2445 ;; We always, always read the .eld file.
2446 (gnus-message 5 "Reading %s..." ding-file
)
2447 (let (gnus-newsrc-assoc)
2448 (gnus-load ding-file
)
2449 ;; Older versions of `gnus-format-specs' are no longer valid
2450 ;; in Oort Gnus 0.01.
2452 (and gnus-newsrc-file-version
2453 (gnus-continuum-version gnus-newsrc-file-version
))))
2454 (when (or (not version
)
2455 (< version
5.090009))
2456 (setq gnus-format-specs gnus-default-format-specs
)))
2457 (when gnus-newsrc-assoc
2458 (setq gnus-newsrc-alist gnus-newsrc-assoc
))))
2459 (dolist (elem gnus-newsrc-alist
)
2460 ;; Protect against broken .newsrc.el files.
2462 (setcar elem
(string-as-unibyte (car elem
)))))
2463 (gnus-make-hashtable-from-newsrc-alist)
2464 (when (file-newer-than-file-p file ding-file
)
2465 ;; Old format quick file
2466 (gnus-message 5 "Reading %s..." file
)
2467 ;; The .el file is newer than the .eld file, so we read that one
2469 (gnus-read-old-newsrc-el-file file
)))
2470 (gnus-run-hooks 'gnus-read-newsrc-el-hook
))
2472 ;; Parse the old-style quick startup file
2473 (defun gnus-read-old-newsrc-el-file (file)
2474 (let (newsrc killed marked group m info
)
2476 (let ((gnus-killed-assoc nil
)
2477 gnus-marked-assoc gnus-newsrc-alist gnus-newsrc-assoc
)
2481 (setq newsrc gnus-newsrc-assoc
2482 killed gnus-killed-assoc
2483 marked gnus-marked-assoc
)))
2484 (setq gnus-newsrc-alist nil
)
2485 (while (setq group
(pop newsrc
))
2486 (if (setq info
(gnus-get-info (car group
)))
2488 (gnus-info-set-read info
(cddr group
))
2489 (gnus-info-set-level
2490 info
(if (nth 1 group
) gnus-level-default-subscribed
2491 gnus-level-default-unsubscribed
))
2492 (push info gnus-newsrc-alist
))
2495 (if (nth 1 group
) gnus-level-default-subscribed
2496 gnus-level-default-unsubscribed
)
2499 ;; Copy marks into info.
2500 (when (setq m
(assoc (car group
) marked
))
2501 (unless (nthcdr 3 info
)
2502 (nconc info
(list nil
)))
2503 (gnus-info-set-marks
2504 info
(list (cons 'tick
(gnus-compress-sequence
2505 (sort (cdr m
) '<) t
))))))
2506 (setq newsrc killed
)
2508 (setcar newsrc
(caar newsrc
))
2509 (setq newsrc
(cdr newsrc
)))
2510 (setq gnus-killed-list killed
))
2511 ;; The .el file version of this variable does not begin with
2512 ;; "options", while the .eld version does, so we just add it if it
2516 (when (not (string-match "^ *options" gnus-newsrc-options
))
2517 (setq gnus-newsrc-options
(concat "options " gnus-newsrc-options
)))
2518 (when (not (string-match "\n$" gnus-newsrc-options
))
2519 (setq gnus-newsrc-options
(concat gnus-newsrc-options
"\n")))
2520 ;; Finally, if we read some options lines, we parse them.
2521 (unless (string= gnus-newsrc-options
"")
2522 (gnus-newsrc-parse-options gnus-newsrc-options
)))
2524 (setq gnus-newsrc-alist
(nreverse gnus-newsrc-alist
))
2525 (gnus-make-hashtable-from-newsrc-alist)))
2527 (defun gnus-make-newsrc-file (file)
2528 "Make server dependent file name by catenating FILE and server host name."
2529 (let* ((file (expand-file-name file nil
))
2530 (real-file (concat file
"-" (nth 1 gnus-select-method
))))
2531 (if (or (file-exists-p real-file
)
2532 (file-exists-p (concat real-file
".el"))
2533 (file-exists-p (concat real-file
".eld")))
2537 (defun gnus-newsrc-to-gnus-format ()
2538 (setq gnus-newsrc-options
"")
2539 (setq gnus-newsrc-options-n nil
)
2541 (unless gnus-active-hashtb
2542 (setq gnus-active-hashtb
(gnus-make-hashtable 4096)))
2543 (let ((buf (current-buffer))
2544 (already-read (> (length gnus-newsrc-alist
) 1))
2545 group subscribed options-symbol newsrc Options-symbol
2547 (goto-char (point-min))
2548 ;; We intern the symbol `options' in the active hashtb so that we
2549 ;; can `eq' against it later.
2550 (set (setq options-symbol
(intern "options" gnus-active-hashtb
)) nil
)
2551 (set (setq Options-symbol
(intern "Options" gnus-active-hashtb
)) nil
)
2554 ;; We first read the first word on the line by narrowing and
2555 ;; then reading into `gnus-active-hashtb'. Most groups will
2556 ;; already exist in that hashtb, so this will save some string
2560 (progn (skip-chars-forward "^ \t!:\n") (point)))
2561 (goto-char (point-min))
2563 (and (/= (point-min) (point-max))
2564 (let ((obarray gnus-active-hashtb
)) (read buf
))))
2566 ;; Now, the symbol we have read is either `options' or a group
2567 ;; name. If it is an options line, we just add it to a string.
2569 ((or (eq symbol options-symbol
)
2570 (eq symbol Options-symbol
))
2571 (setq gnus-newsrc-options
2572 ;; This concatting is quite inefficient, but since our
2573 ;; thorough studies show that approx 99.37% of all
2574 ;; .newsrc files only contain a single options line, we
2575 ;; don't give a damn, frankly, my dear.
2576 (concat gnus-newsrc-options
2579 ;; Options may continue on the next line.
2580 (or (and (re-search-forward "^[^ \t]" nil
'move
)
2585 ;; Group names can be just numbers.
2586 (when (numberp symbol
)
2587 (setq symbol
(intern (int-to-string symbol
) gnus-active-hashtb
)))
2588 (unless (boundp symbol
)
2590 ;; It was a group name.
2591 (setq subscribed
(eq (char-after) ?
:)
2592 group
(symbol-name symbol
)
2595 ;; If the line ends here, this is clearly a buggy line, so
2596 ;; we put point a the beginning of line and let the cond
2597 ;; below do the error handling.
2599 ;; We skip to the beginning of the ranges.
2600 (skip-chars-forward "!: \t"))
2601 ;; We are now at the beginning of the list of read articles.
2602 ;; We read them range by range.
2605 ((looking-at "[0-9]+")
2606 ;; We narrow and read a number instead of buffer-substring/
2607 ;; string-to-number because it's faster. narrow/widen is
2608 ;; faster than save-restriction/narrow, and save-restriction
2609 ;; produces a garbage object.
2611 (narrow-to-region (match-beginning 0) (match-end 0))
2614 ;; If the next character is a dash, then this is a range.
2615 (if (eq (char-after) ?-
)
2617 ;; We read the upper bound of the range.
2619 (if (not (looking-at "[0-9]+"))
2620 ;; This is a buggy line, by we pretend that
2621 ;; it's kinda OK. Perhaps the user should be
2627 (narrow-to-region (match-beginning 0)
2632 ;; It was just a simple number, so we add it to the
2635 ;; If the next char in ?\n, then we have reached the end
2636 ;; of the line and return nil.
2637 (not (eq (char-after) ?
\n)))
2638 ((eq (char-after) ?
\n)
2639 ;; End of line, so we end.
2642 ;; Not numbers and not eol, so this might be a buggy
2645 ;; If it was eob instead of ?\n, we allow it.
2646 ;; The line was buggy.
2648 (gnus-error 3.1 "Mangled line: %s"
2649 (buffer-substring (point-at-bol)
2652 ;; Skip past ", ". Spaces are invalid in these ranges, but
2653 ;; we allow them, because it's a common mistake to put a
2654 ;; space after the comma.
2655 (skip-chars-forward ", "))
2657 ;; We have already read .newsrc.eld, so we gently update the
2658 ;; data in the hash table with the information we have just
2661 (let ((info (gnus-get-info group
))
2664 ;; There is an entry for this file in the alist.
2666 (gnus-info-set-read info
(nreverse reads
))
2667 ;; We update the level very gently. In fact, we
2668 ;; only change it if there's been a status change
2669 ;; from subscribed to unsubscribed, or vice versa.
2670 (setq level
(gnus-info-level info
))
2671 (cond ((and (<= level gnus-level-subscribed
)
2673 (setq level
(if reads
2674 gnus-level-default-unsubscribed
2675 (1+ gnus-level-default-unsubscribed
))))
2676 ((and (> level gnus-level-subscribed
) subscribed
)
2677 (setq level gnus-level-default-subscribed
)))
2678 (gnus-info-set-level info level
))
2679 ;; This is a new group.
2680 (setq info
(list group
2682 gnus-level-default-subscribed
2684 (1+ gnus-level-subscribed
)
2685 gnus-level-default-unsubscribed
))
2687 (push info newsrc
)))))
2690 (setq newsrc
(nreverse newsrc
))
2692 (if (not already-read
)
2694 ;; We now have two newsrc lists - `newsrc', which is what we
2695 ;; have read from .newsrc, and `gnus-newsrc-alist', which is
2696 ;; what we've read from .newsrc.eld. We have to merge these
2697 ;; lists. We do this by "attaching" any (foreign) groups in the
2698 ;; gnus-newsrc-alist to the (native) group that precedes them.
2699 (let ((rc (cdr gnus-newsrc-alist
))
2700 (prev gnus-newsrc-alist
)
2703 (or (null (nth 4 (car rc
))) ; It's a native group.
2704 (assoc (caar rc
) newsrc
) ; It's already in the alist.
2705 (if (setq entry
(assoc (caar prev
) newsrc
))
2706 (setcdr (setq mentry
(memq entry newsrc
))
2707 (cons (car rc
) (cdr mentry
)))
2708 (push (car rc
) newsrc
)))
2712 (setq gnus-newsrc-alist newsrc
)
2713 ;; We make the newsrc hashtb.
2714 (gnus-make-hashtable-from-newsrc-alist)
2716 ;; Finally, if we read some options lines, we parse them.
2717 (unless (string= gnus-newsrc-options
"")
2718 (gnus-newsrc-parse-options gnus-newsrc-options
))))
2720 ;; Parse options lines to find "options -n !all rec.all" and stuff.
2721 ;; The return value will be a list on the form
2722 ;; ((regexp1 . ignore)
2723 ;; (regexp2 . subscribe)...)
2724 ;; When handling new newsgroups, groups that match a `ignore' regexp
2725 ;; will be ignored, and groups that match a `subscribe' regexp will be
2726 ;; subscribed. A line like
2727 ;; options -n !all rec.all
2728 ;; will lead to a list that looks like
2729 ;; (("^rec\\..+" . subscribe)
2730 ;; ("^.+" . ignore))
2731 ;; So all "rec.*" groups will be subscribed, while all the other
2732 ;; groups will be ignored. Note that "options -n !all rec.all" is very
2733 ;; different from "options -n rec.all !all".
2734 (defun gnus-newsrc-parse-options (options)
2737 (gnus-set-work-buffer)
2738 (insert (regexp-quote options
))
2739 ;; First we treat all continuation lines.
2740 (goto-char (point-min))
2741 (while (re-search-forward "\n[ \t]+" nil t
)
2742 (replace-match " " t t
))
2743 ;; Then we transform all "all"s into ".+"s.
2744 (goto-char (point-min))
2745 (while (re-search-forward "\\ball\\b" nil t
)
2746 (replace-match ".+" t t
))
2747 (goto-char (point-min))
2748 ;; We remove all other options than the "-n" ones.
2749 (while (re-search-forward "[ \t]-[^n][^-]*" nil t
)
2752 (goto-char (point-min))
2754 ;; We are only interested in "options -n" lines - we
2755 ;; ignore the other option lines.
2756 (while (re-search-forward "[ \t]-n" nil t
)
2759 (and (re-search-forward "[ \t]-n" (point-at-eol) t
)
2762 ;; Search for all "words"...
2763 (while (re-search-forward "[^ \t,\n]+" eol t
)
2764 (if (eq (char-after (match-beginning 0)) ?
!)
2765 ;; If the word begins with a bang (!), this is a "not"
2766 ;; spec. We put this spec (minus the bang) and the
2767 ;; symbol `ignore' into the list.
2769 "^" (buffer-substring
2770 (1+ (match-beginning 0))
2775 ;; There was no bang, so this is a "yes" spec.
2776 (push (cons (concat "^" (match-string 0) "\\($\\|\\.\\)")
2780 (setq gnus-newsrc-options-n out
))))
2783 (defalias 'gnus-long-file-names
2784 (if (fboundp 'msdos-long-file-names
)
2785 'msdos-long-file-names
2788 (defvar gnus-save-newsrc-file-last-timestamp nil
)
2789 (defun gnus-save-newsrc-file (&optional force
)
2790 "Save .newsrc file."
2791 ;; Note: We cannot save .newsrc file if all newsgroups are removed
2792 ;; from the variable gnus-newsrc-alist.
2793 (when (and (or gnus-newsrc-alist gnus-killed-list
)
2794 gnus-current-startup-file
)
2795 ;; Save agent range limits for the currently active method.
2797 (gnus-agent-save-local force
))
2800 (if (and (or gnus-use-dribble-file gnus-slave
)
2802 (or (not gnus-dribble-buffer
)
2803 (not (buffer-name gnus-dribble-buffer
))
2804 (zerop (with-current-buffer gnus-dribble-buffer
2806 (gnus-message 4 "(No changes need to be saved)")
2807 (gnus-run-hooks 'gnus-save-newsrc-hook
)
2809 (gnus-slave-save-newsrc)
2810 ;; Save .newsrc only if the select method is an NNTP method.
2811 ;; The .newsrc file is for interoperability with other
2812 ;; newsreaders, so saving non-NNTP groups there doesn't make
2814 (when (and gnus-save-newsrc-file
2815 (eq (car (gnus-server-to-method gnus-select-method
))
2817 (gnus-message 8 "Saving %s..." gnus-current-startup-file
)
2818 (gnus-gnus-to-newsrc-format)
2819 (gnus-message 8 "Saving %s...done" gnus-current-startup-file
))
2821 ;; Save .newsrc.eld.
2822 (set-buffer (gnus-get-buffer-create " *Gnus-newsrc*"))
2823 (make-local-variable 'version-control
)
2824 (setq version-control gnus-backup-startup-file
)
2825 (setq buffer-file-name
2826 (concat gnus-current-startup-file
".eld"))
2827 (setq default-directory
(file-name-directory buffer-file-name
))
2828 (buffer-disable-undo)
2830 (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file
)
2832 ;; check timestamp of `gnus-current-startup-file'.eld against
2833 ;; `gnus-save-newsrc-file-last-timestamp'
2834 (let* ((checkfile (concat gnus-current-startup-file
".eld"))
2835 (mtime (nth 5 (file-attributes checkfile
))))
2836 (when (and gnus-save-newsrc-file-last-timestamp
2837 (time-less-p gnus-save-newsrc-file-last-timestamp
2840 (format "%s was updated externally after %s, save?"
2844 gnus-save-newsrc-file-last-timestamp
)))
2845 (error "Couldn't save %s: updated externally" checkfile
))))
2847 (if gnus-save-startup-file-via-temp-buffer
2848 (let ((coding-system-for-write gnus-ding-file-coding-system
)
2849 (standard-output (current-buffer)))
2850 (gnus-gnus-to-quick-newsrc-format)
2851 (gnus-run-hooks 'gnus-save-quick-newsrc-hook
)
2853 (setq gnus-save-newsrc-file-last-timestamp
2854 (nth 5 (file-attributes buffer-file-name
))))
2855 (let ((coding-system-for-write gnus-ding-file-coding-system
)
2856 (version-control gnus-backup-startup-file
)
2857 (startup-file (concat gnus-current-startup-file
".eld"))
2858 (working-dir (file-name-directory gnus-current-startup-file
))
2861 ;; Generate the name of a non-existent file.
2862 (while (progn (setq working-file
2864 (if (and (eq system-type
'ms-dos
)
2865 (not (gnus-long-file-names)))
2866 "%s#%d.tm#" ; MSDOS limits files to 8+3
2868 working-dir
(setq i
(1+ i
))))
2869 (file-exists-p working-file
)))
2873 (gnus-with-output-to-file working-file
2874 (gnus-gnus-to-quick-newsrc-format)
2875 (gnus-run-hooks 'gnus-save-quick-newsrc-hook
))
2877 ;; These bindings will mislead the current buffer
2878 ;; into thinking that it is visiting the startup
2880 (let ((buffer-backed-up nil
)
2881 (buffer-file-name startup-file
)
2882 (file-precious-flag t
)
2883 (setmodes (file-modes startup-file
)))
2884 ;; Backup the current version of the startup file.
2887 ;; Replace the existing startup file with the temp file.
2888 (rename-file working-file startup-file t
)
2889 (gnus-set-file-modes startup-file setmodes
)
2890 (setq gnus-save-newsrc-file-last-timestamp
2891 (nth 5 (file-attributes startup-file
)))))
2893 (delete-file working-file
)
2894 (file-error nil
)))))
2896 (gnus-kill-buffer (current-buffer))
2898 5 "Saving %s.eld...done" gnus-current-startup-file
))
2899 (gnus-dribble-delete-file)
2900 (gnus-group-set-mode-line)))))
2902 (defun gnus-gnus-to-quick-newsrc-format (&optional minimal name
&rest specific-variables
)
2903 "Print Gnus variables such as `gnus-newsrc-alist' in Lisp format."
2904 (princ (format ";; -*- mode:emacs-lisp; coding: %s; -*-\n"
2905 gnus-ding-file-coding-system
))
2907 (princ (format ";; %s\n" name
))
2908 (princ ";; Gnus startup file.\n"))
2912 ;; Never delete this file -- if you want to force Gnus to read the
2913 ;; .newsrc file (if you have one), touch .newsrc instead.\n")
2914 (princ "(setq gnus-newsrc-file-version ")
2915 (princ (gnus-prin1-to-string gnus-version
))
2918 (let* ((print-quoted t
)
2920 (print-escape-multibyte nil
)
2921 (print-escape-nonascii t
)
2925 (print-escape-newlines t
)
2927 (if (and gnus-save-killed-list
2928 (stringp gnus-save-killed-list
))
2929 (gnus-strip-killed-list)
2932 (or specific-variables
2933 (if gnus-save-killed-list gnus-variable-list
2934 ;; Remove the `gnus-killed-list' from the list of variables
2935 ;; to be saved, if required.
2936 (delq 'gnus-killed-list
(copy-sequence gnus-variable-list
)))))
2937 ;; Peel off the "dummy" group.
2938 (gnus-newsrc-alist (cdr gnus-newsrc-alist
))
2940 ;; Insert the variables into the file.
2942 (when (and (boundp (setq variable
(pop variables
)))
2943 (symbol-value variable
))
2945 (princ (symbol-name variable
))
2947 (prin1 (symbol-value variable
))
2950 (defun gnus-strip-killed-list ()
2951 "Return the killed list minus the groups that match `gnus-save-killed-list'."
2952 (let ((list gnus-killed-list
)
2955 (when (string-match gnus-save-killed-list
(car list
))
2956 (push (car list
) olist
))
2960 (defun gnus-gnus-to-newsrc-format (&optional foreign-ok
)
2961 (interactive (list (gnus-y-or-n-p "write foreign groups too? ")))
2962 ;; Generate and save the .newsrc file.
2963 (with-current-buffer (create-file-buffer gnus-current-startup-file
)
2964 (let ((newsrc (cdr gnus-newsrc-alist
))
2965 (standard-output (current-buffer))
2966 info ranges range method
)
2967 (setq buffer-file-name gnus-current-startup-file
)
2968 (setq default-directory
(file-name-directory buffer-file-name
))
2969 (buffer-disable-undo)
2971 ;; Use a unibyte buffer since group names are unibyte strings;
2972 ;; in particular, non-ASCII group names are the ones encoded by
2973 ;; a certain coding system.
2974 (mm-disable-multibyte)
2976 (when gnus-newsrc-options
2977 (insert gnus-newsrc-options
))
2978 ;; Write subscribed and unsubscribed.
2979 (while (setq info
(pop newsrc
))
2980 ;; Don't write foreign groups to .newsrc.
2981 (when (or (null (setq method
(gnus-info-method info
)))
2982 (equal method
"native")
2983 (inline (gnus-server-equal method gnus-select-method
))
2985 (insert (gnus-info-group info
)
2986 (if (> (gnus-info-level info
) gnus-level-subscribed
)
2988 (when (setq ranges
(gnus-info-read info
))
2990 (if (not (listp (cdr ranges
)))
2991 (if (= (car ranges
) (cdr ranges
))
2992 (princ (car ranges
))
2993 (princ (car ranges
))
2995 (princ (cdr ranges
)))
2996 (while (setq range
(pop ranges
))
2997 (if (or (atom range
) (= (car range
) (cdr range
)))
2998 (princ (or (and (atom range
) range
) (car range
)))
3001 (princ (cdr range
)))
3005 (make-local-variable 'version-control
)
3006 (setq version-control
'never
)
3007 ;; It has been reported that sometime the modtime on the .newsrc
3008 ;; file seems to be off. We really do want to overwrite it, so
3009 ;; we clear the modtime here before saving. It's a bit odd,
3011 ;; sometimes the modtime clear isn't sufficient. most brute force:
3012 ;; delete the silly thing entirely first. but this fails to provide
3013 ;; such niceties as .newsrc~ creation.
3014 (if gnus-modtime-botch
3015 (delete-file gnus-startup-file
)
3016 (clear-visited-file-modtime))
3017 (gnus-run-hooks 'gnus-save-standard-newsrc-hook
)
3018 (let ((coding-system-for-write 'raw-text
))
3020 (kill-buffer (current-buffer)))))
3024 ;;; Slave functions.
3027 (defvar gnus-slave-mode nil
)
3029 (defun gnus-slave-mode ()
3030 "Minor mode for slave Gnusae."
3031 ;; FIXME: gnus-slave-mode appears to never be set (i.e. it'll always be nil):
3032 ;; Remove, or fix and use define-minor-mode.
3033 (add-minor-mode 'gnus-slave-mode
" Slave" (make-sparse-keymap))
3034 (gnus-run-hooks 'gnus-slave-mode-hook
))
3036 (defun gnus-slave-save-newsrc ()
3037 (with-current-buffer gnus-dribble-buffer
3039 (make-temp-file (concat gnus-current-startup-file
"-slave-")))
3040 (modes (ignore-errors
3041 (file-modes (concat gnus-current-startup-file
".eld")))))
3042 (let ((coding-system-for-write gnus-ding-file-coding-system
))
3043 (gnus-write-buffer slave-name
))
3045 (gnus-set-file-modes slave-name modes
)))))
3047 (defun gnus-master-read-slave-newsrc ()
3050 (file-name-directory gnus-current-startup-file
)
3054 (file-name-nondirectory gnus-current-startup-file
)
3058 (if (not slave-files
)
3059 () ; There are no slave files to read.
3060 (gnus-message 7 "Reading slave newsrcs...")
3061 (with-current-buffer (gnus-get-buffer-create " *gnus slave*")
3063 (sort (mapcar (lambda (file)
3064 (list (nth 5 (file-attributes file
)) file
))
3067 (or (< (caar f1
) (caar f2
))
3068 (< (nth 1 (car f1
)) (nth 1 (car f2
)))))))
3071 (setq file
(nth 1 (car slave-files
)))
3072 (nnheader-insert-file-contents file
)
3073 (when (condition-case ()
3075 (eval-buffer (current-buffer))
3078 (gnus-error 3.2 "Possible error in %s" file
)
3080 (unless gnus-slave
; Slaves shouldn't delete these files.
3082 (delete-file file
))))
3083 (setq slave-files
(cdr slave-files
))))
3084 (gnus-dribble-touch)
3085 (gnus-message 7 "Reading slave newsrcs...done"))))
3089 ;;; Group description.
3092 (defun gnus-read-all-descriptions-files ()
3093 (let ((methods (cons gnus-select-method
3095 (when (gnus-archive-server-wanted-p)
3097 gnus-secondary-select-methods
))))
3099 (gnus-read-descriptions-file (car methods
))
3100 (setq methods
(cdr methods
)))
3103 (defun gnus-read-descriptions-file (&optional method
)
3104 (let ((method (or method gnus-select-method
))
3106 (when (stringp method
)
3107 (setq method
(gnus-server-to-method method
)))
3108 ;; We create the hashtable whether we manage to read the desc file
3109 ;; to avoid trying to re-read after a failed read.
3110 (unless gnus-description-hashtb
3111 (setq gnus-description-hashtb
3112 (gnus-make-hashtable (length gnus-active-hashtb
))))
3113 ;; Mark this method's desc file as read.
3114 (gnus-sethash (gnus-group-prefixed-name "" method
) "Has read"
3115 gnus-description-hashtb
)
3117 (gnus-message 5 "Reading descriptions file via %s..." (car method
))
3119 ((null (gnus-get-function method
'request-list-newsgroups t
))
3121 ((not (gnus-check-server method
))
3122 (gnus-message 1 "Couldn't open server")
3124 ((not (gnus-request-list-newsgroups method
))
3125 (gnus-message 1 "Couldn't read newsgroups descriptions")
3129 ;; FIXME: Shouldn't save-restriction be done after set-buffer?
3131 (set-buffer nntp-server-buffer
)
3132 (goto-char (point-min))
3133 (when (or (search-forward "\n.\n" nil t
)
3134 (goto-char (point-max)))
3136 (narrow-to-region (point-min) (point)))
3137 ;; If these are groups from a foreign select method, we insert the
3138 ;; group prefix in front of the group names.
3139 (and method
(not (inline
3141 (gnus-server-get-method nil method
)
3142 (gnus-server-get-method
3143 nil gnus-select-method
))))
3144 (let ((prefix (gnus-group-prefixed-name "" method
)))
3145 (goto-char (point-min))
3146 (while (and (not (eobp))
3147 (progn (insert prefix
)
3148 (zerop (forward-line 1)))))))
3149 (goto-char (point-min))
3151 ;; If we get an error, we set group to 0, which is not a
3155 (let ((obarray gnus-description-hashtb
))
3156 ;; Group is set to a symbol interned in this
3158 (read nntp-server-buffer
))
3160 (skip-chars-forward " \t")
3161 ;; ... which leads to this line being effectively ignored.
3162 (when (symbolp group
)
3163 (let* ((str (buffer-substring
3164 (point) (progn (end-of-line) (point))))
3165 (name (symbol-name group
))
3167 (or (gnus-group-name-charset method name
)
3168 (gnus-parameter-charset name
)
3169 gnus-default-charset
)))
3170 ;; Fixme: Don't decode in unibyte mode.
3171 (when (and str charset
)
3172 (setq str
(decode-coding-string str charset
)))
3175 (gnus-message 5 "Reading descriptions file...done")
3178 (defun gnus-group-get-description (group)
3179 "Get the description of a group by sending XGTITLE to the server."
3180 (when (gnus-request-group-description group
)
3181 (with-current-buffer nntp-server-buffer
3182 (goto-char (point-min))
3183 (when (looking-at "[^ \t]+[ \t]+\\(.*\\)")
3184 (match-string 1)))))
3187 (defun gnus-declare-backend (name &rest abilities
)
3188 "Declare back end NAME with ABILITIES as a Gnus back end."
3189 (setq gnus-valid-select-methods
3190 (nconc gnus-valid-select-methods
3191 (list (apply 'list name abilities
))))
3192 (gnus-redefine-select-method-widget))
3194 (defun gnus-set-default-directory ()
3195 "Set the default directory in the current buffer to `gnus-default-directory'.
3196 If this variable is nil, don't do anything."
3197 (setq default-directory
3198 (if (and gnus-default-directory
3199 (file-exists-p gnus-default-directory
))
3200 (file-name-as-directory (expand-file-name gnus-default-directory
))
3201 default-directory
)))
3203 (defun gnus-display-time-event-handler ()
3204 (if (and (fboundp 'display-time-event-handler
)
3205 (bound-and-true-p display-time-timer
))
3206 (display-time-event-handler)))
3208 (defun gnus-check-reasonable-setup ()
3209 ;; Check whether nnml and nnfolder share a directory.
3210 (let (method active actives match
)
3211 (dolist (server gnus-server-alist
)
3212 (setq method
(gnus-server-to-method server
)
3213 active
(intern (format "%s-active-file" (car method
))))
3214 (when (and (member (car method
) '(nnml nnfolder
))
3215 (gnus-server-opened method
)
3217 (when (setq match
(assoc (symbol-value active
) actives
))
3218 (display-warning 'gnus-server
3219 (format "%s and %s share the same active file %s"
3223 (push (list (symbol-value active
) method
) actives
)))))
3225 (provide 'gnus-start
)
3227 ;;; gnus-start.el ends here