Merge branch 'master' into comment-cache
[emacs.git] / lisp / gnus / gnus-start.el
blobbe46339cd38158ed69c308922224ae51d45bd693
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>
6 ;; Keywords: news
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/>.
23 ;;; Commentary:
25 ;;; Code:
27 (require 'gnus)
28 (require 'gnus-win)
29 (require 'gnus-int)
30 (require 'gnus-spec)
31 (require 'gnus-range)
32 (require 'gnus-util)
33 (require 'gnus-cloud)
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")
39 (eval-when-compile
40 (require 'cl))
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")
47 "Your `.newsrc' file.
48 `.newsrc-SERVER' will be used instead if that exists."
49 :group 'gnus-start
50 :type 'file)
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'
55 variable."
56 :version "22.1"
57 :group 'gnus-start
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."
67 :version "22.1"
68 :group 'gnus-start
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."
75 :group 'gnus-start
76 :type 'file)
78 (defcustom gnus-site-init-file
79 (condition-case nil
80 (concat (file-name-directory
81 (directory-file-name installation-directory))
82 "site-lisp/gnus-init")
83 (error nil))
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."
86 :group 'gnus-start
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
94 :type 'boolean)
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
99 saved will be used."
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
107 or killed.
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
123 servers.
125 E.g.:
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]."
131 :group 'gnus-start
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"
137 :value ((nntp ""))
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
145 :type 'boolean)
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
150 `.newsrc' file.
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)
163 (const some)
164 (const t)))
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
188 :type 'integer)
190 (defcustom gnus-level-default-unsubscribed 6
191 "New unsubscribed groups will be unsubscribed at this level."
192 :group 'gnus-group-levels
193 :type 'integer)
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
200 :type 'integer)
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
213 groups."
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
224 entry."
225 :version "21.1"
226 :group 'gnus-newsrc
227 :type 'boolean)
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
235 exit."
236 :group 'gnus-newsrc
237 :type 'boolean)
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."
251 :group 'gnus-newsrc
252 :type '(radio (sexp :format "Non-nil\n"
253 :match (lambda (widget value)
254 (and value (not (stringp value))))
255 :value t)
256 (const nil)
257 regexp))
259 (defcustom gnus-ignored-newsgroups
260 (mapconcat 'identity
261 '("^to\\." ; not "real" groups
262 "^[0-9. \t]+\\( \\|$\\)" ; all digits in name
263 "^[\"][\"#'()]" ; bogus characters
265 "\\|")
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
271 :type 'regexp)
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
283 claim them."
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)
292 function
293 (repeat function)))
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."
300 :version "22.1"
301 :group 'gnus-group-new
302 :type 'hook)
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
309 .newsrc file:
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)
323 function
324 (repeat function)))
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
336 :type 'boolean)
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."
343 :version "24.1"
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
357 :type 'regexp)
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
382 disc."
383 :group 'gnus-newsrc
384 :type 'boolean)
386 (defcustom gnus-check-bogus-groups-hook nil
387 "A hook run after removing bogus groups."
388 :group 'gnus-start-server
389 :type 'hook)
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."
394 :group 'gnus-start
395 :type 'hook)
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'."
401 :group 'gnus-start
402 :type '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'."
408 :version "24.4"
409 :group 'gnus-start
410 :type 'hook)
412 (defcustom gnus-started-hook nil
413 "A hook called as the last thing after startup."
414 :group 'gnus-start
415 :type 'hook)
417 (defcustom gnus-setup-news-hook nil
418 "A hook after reading the .newsrc file, but before generating the buffer."
419 :group 'gnus-start
420 :type 'hook)
422 (defcustom gnus-get-top-new-news-hook nil
423 "A hook run just before Gnus checks for new news globally."
424 :version "22.1"
425 :group 'gnus-group-new
426 :type 'hook)
428 (defcustom gnus-get-new-news-hook nil
429 "A hook run just before Gnus checks for new news."
430 :group 'gnus-group-new
431 :type 'hook)
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."
436 :version "24.1"
437 :group 'gnus-group-new
438 :type 'hook)
440 (defcustom gnus-read-newsrc-el-hook nil
441 "A hook called after reading the newsrc.eld? file."
442 :group 'gnus-newsrc
443 :type 'hook)
445 (defcustom gnus-save-newsrc-hook nil
446 "A hook called before saving any of the newsrc files."
447 :group 'gnus-newsrc
448 :type 'hook)
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."
453 :group 'gnus-newsrc
454 :type 'hook)
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."
459 :group 'gnus-newsrc
460 :type 'hook)
462 (defcustom gnus-group-mode-hook nil
463 "Hook for Gnus group mode."
464 :group 'gnus-group-various
465 :options '(gnus-topic-mode)
466 :type 'hook)
468 (defcustom gnus-always-read-dribble-file nil
469 "Unconditionally read the dribble file."
470 :group 'gnus-newsrc
471 :type 'boolean)
473 ;;; Internal variables
475 ;; Fixme: deal with old emacs-mule when mm-universal-coding-system is
476 ;; utf-8-emacs.
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.
502 (when init-file-user
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))
507 (when (and file
508 (locate-library file))
509 (if (or debug-on-error debug-on-quit)
510 (load file nil t)
511 (condition-case var
512 (load file nil t)
513 (error
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)
521 (while groups
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))
530 start)
531 (cdr groups)
532 (setq prefix
533 (concat "^" (substring
534 (gnus-group-real-name (car groups))
535 0 (match-end 0))))
536 (string-match prefix (gnus-group-real-name (cadr groups))))
537 (progn
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)))
543 (ding)
544 (message "Descend hierarchy %s? ([y]nsq): "
545 (substring prefix 1 (1- (length prefix)))))
546 (cond ((= ans ?n)
547 (while (and groups
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)))
555 ((= ans ?s)
556 (while (and groups
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)))
564 ((= ans ?q)
565 (while groups
566 (setq group (car groups))
567 (push group gnus-killed-list)
568 (gnus-sethash group group gnus-killed-hashtb)
569 (setq groups (cdr groups))))
570 (t nil)))
571 (message "Subscribe %s? ([n]yq)" (car groups))
572 (while (not (memq (setq ans (read-char-exclusive))
573 '(?y ?\n ?\r ?q ?n)))
574 (ding)
575 (message "Subscribe %s? ([n]yq)" (car groups)))
576 (setq group (car groups))
577 (cond ((= ans ?y)
578 (gnus-subscribe-alphabetically (car groups))
579 (gnus-sethash group group gnus-killed-hashtb))
580 ((= ans ?q)
581 (while groups
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))
598 before)
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)
609 (prog1
610 (let ((groupkey newgroup) before)
611 (while (and (not before) groupkey)
612 (goto-char (point-min))
613 (let ((groupkey-re
614 (concat "^\\(" (regexp-quote groupkey) ".*\\)[!:]")))
615 (while (and (re-search-forward groupkey-re nil t)
616 (progn
617 (setq before (match-string 1))
618 (string< before newgroup)))))
619 ;; Remove tail of newsgroup name (eg. a.b.c -> a.b)
620 (setq groupkey
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,
629 it is killed."
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."
646 (save-excursion
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 ()
680 "Close all servers."
681 (interactive)
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)))
689 (while variables
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
701 gnus-killed-list nil
702 gnus-zombie-list 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
717 nnoo-state-alist 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.
728 (gnus-dribble-clear)
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.
734 (dolist (buffer (gnus-buffers))
735 (gnus-kill-buffer buffer))
736 ;; Remove Gnus frames.
737 (gnus-kill-gnus-frames))
739 (defun gnus-no-server-1 (&optional arg slave)
740 "Read network news.
741 If ARG is a positive number, Gnus will use that as the startup
742 level. If ARG is nil, Gnus will be started at level 2
743 \(`gnus-level-default-subscribed' minus one). If ARG is non-nil
744 and not a positive number, Gnus will prompt the user for the name
745 of an NNTP server to use. As opposed to \\[gnus], this command
746 will not connect to the local server."
747 (interactive "P")
748 (let ((val (or arg (1- gnus-level-default-subscribed))))
749 (gnus val t slave)
750 (make-local-variable 'gnus-group-use-permanent-levels)
751 (setq gnus-group-use-permanent-levels val)))
753 (defun gnus-1 (&optional arg dont-connect slave)
754 "Read network news.
755 If ARG is non-nil and a positive number, Gnus will use that as the
756 startup level. If ARG is non-nil and not a positive number, Gnus will
757 prompt the user for the name of an NNTP server to use."
758 (interactive "P")
760 (if (gnus-alive-p)
761 (progn
762 (gnus-run-hooks 'gnus-before-resume-hook)
763 (switch-to-buffer gnus-group-buffer)
764 (gnus-group-get-new-news
765 (and (numberp arg)
766 (> arg 0)
767 (max (car gnus-group-list-mode) arg))))
769 (gnus-clear-system)
770 (gnus-splash)
771 (gnus-run-hooks 'gnus-before-startup-hook)
772 (nnheader-init-server-buffer)
773 (setq gnus-slave slave)
774 (gnus-read-init-file)
776 ;; Add "native" to gnus-predefined-server-alist just to have a
777 ;; name for the native select method.
778 (when gnus-select-method
779 (add-to-list 'gnus-predefined-server-alist
780 (cons "native" gnus-select-method)))
782 (if gnus-agent
783 (gnus-agentize))
785 (let ((level (and (numberp arg) (> arg 0) arg))
786 did-connect)
787 (unwind-protect
788 (progn
789 (unless dont-connect
790 (setq did-connect
791 (gnus-start-news-server (and arg (not level))))))
792 (if (and (not dont-connect)
793 (not did-connect))
794 ;; Couldn't connect to the server, so bail out.
795 (gnus-group-quit)
796 (gnus-run-hooks 'gnus-startup-hook)
797 ;; Find the current startup file name.
798 (setq gnus-current-startup-file
799 (gnus-make-newsrc-file gnus-startup-file))
801 ;; Read the dribble file.
802 (when (or gnus-slave gnus-use-dribble-file)
803 (gnus-dribble-read-file))
805 ;; Do the actual startup.
806 (gnus-setup-news nil level dont-connect)
807 (gnus-run-hooks 'gnus-setup-news-hook)
808 (when gnus-agent
809 (gnus-request-create-group "queue" '(nndraft "")))
810 (gnus-start-draft-setup)
811 ;; Generate the group buffer.
812 (gnus-group-list-groups level)
813 (gnus-group-first-unread-group)
814 (gnus-configure-windows 'group)
815 (gnus-group-set-mode-line)
816 (gnus-run-hooks 'gnus-started-hook))))))
818 (defun gnus-start-draft-setup ()
819 "Make sure the draft group exists."
820 (interactive)
821 (gnus-request-create-group "drafts" '(nndraft ""))
822 (unless (gnus-group-entry "nndraft:drafts")
823 (let ((gnus-level-default-subscribed 1))
824 (gnus-subscribe-group "nndraft:drafts" nil '(nndraft "")))
825 (setcar (gnus-group-entry "nndraft:drafts") 0))
826 (unless (equal (gnus-group-get-parameter "nndraft:drafts" 'gnus-dummy t)
827 '((gnus-draft-mode)))
828 (gnus-group-set-parameter
829 "nndraft:drafts" 'gnus-dummy '((gnus-draft-mode)))))
833 ;;; Dribble file
836 (defvar gnus-dribble-ignore nil)
837 (defvar gnus-dribble-eval-file nil)
839 (defun gnus-dribble-file-name ()
840 "Return the dribble file for the current .newsrc."
841 (concat
842 (if gnus-dribble-directory
843 (concat (file-name-as-directory gnus-dribble-directory)
844 (file-name-nondirectory gnus-current-startup-file))
845 gnus-current-startup-file)
846 "-dribble"))
848 (defun gnus-dribble-enter (string &optional regexp)
849 "Enter STRING into the dribble buffer.
850 If REGEXP is given, lines that match it will be deleted."
851 (when (and (not gnus-dribble-ignore)
852 gnus-dribble-buffer
853 (buffer-name gnus-dribble-buffer))
854 (let ((obuf (current-buffer)))
855 (set-buffer gnus-dribble-buffer)
856 (when regexp
857 (goto-char (point-min))
858 (let (end)
859 (while (re-search-forward regexp nil t)
860 (unless (bolp) (forward-line 1))
861 (setq end (point))
862 (goto-char (match-beginning 0))
863 (delete-region (point-at-bol) end))))
864 (goto-char (point-max))
865 ;; Make sure that each dribble entry is a single line, so that
866 ;; the "remove" code above works.
867 (insert (replace-regexp-in-string "\n" "\\\\n" string) "\n")
868 (bury-buffer gnus-dribble-buffer)
869 (with-current-buffer gnus-group-buffer
870 (gnus-group-set-mode-line))
871 (set-buffer obuf))))
873 (defun gnus-dribble-touch ()
874 "Touch the dribble buffer."
875 (gnus-dribble-enter ""))
877 (defun gnus-dribble-read-file ()
878 "Read the dribble file from disk."
879 (let ((dribble-file (gnus-dribble-file-name)))
880 (unless (file-exists-p (file-name-directory dribble-file))
881 (make-directory (file-name-directory dribble-file) t))
882 (with-current-buffer (setq gnus-dribble-buffer
883 (gnus-get-buffer-create
884 (file-name-nondirectory dribble-file)))
885 (set (make-local-variable 'file-precious-flag) t)
886 (setq buffer-save-without-query t)
887 (erase-buffer)
888 (setq buffer-file-name dribble-file)
889 ;; The buffer may be shrunk a lot when deleting old entries.
890 ;; It caused the auto-saving to stop.
891 (set (make-local-variable 'auto-save-include-big-deletions) t)
892 (auto-save-mode t)
893 (buffer-disable-undo)
894 (bury-buffer (current-buffer))
895 (set-buffer-modified-p nil)
896 (let ((auto (make-auto-save-file-name))
897 (gnus-dribble-ignore t)
898 (purpose nil)
899 modes)
900 (when (or (file-exists-p auto) (file-exists-p dribble-file))
901 ;; Load whichever file is newest -- the auto save file
902 ;; or the "real" file.
903 (if (file-newer-than-file-p auto dribble-file)
904 (nnheader-insert-file-contents auto)
905 (nnheader-insert-file-contents dribble-file))
906 (unless (zerop (buffer-size))
907 (set-buffer-modified-p t))
908 ;; Set the file modes to reflect the .newsrc file modes.
909 (save-buffer)
910 (when (and (file-exists-p gnus-current-startup-file)
911 (file-exists-p dribble-file)
912 (setq modes (file-modes gnus-current-startup-file)))
913 (gnus-set-file-modes dribble-file modes))
914 (goto-char (point-min))
915 (when (search-forward "Gnus was exited on purpose" nil t)
916 (setq purpose t))
917 ;; Possibly eval the file later.
918 (when (or gnus-always-read-dribble-file
919 (gnus-y-or-n-p
920 (if purpose
921 "Gnus exited on purpose without saving; read auto-save file anyway? "
922 "Gnus auto-save file exists. Do you want to read it? ")))
923 (setq gnus-dribble-eval-file t)))))))
925 (defun gnus-dribble-eval-file ()
926 (when gnus-dribble-eval-file
927 (setq gnus-dribble-eval-file nil)
928 (save-excursion
929 (let ((gnus-dribble-ignore t))
930 (set-buffer gnus-dribble-buffer)
931 (eval-buffer (current-buffer))))))
933 (defun gnus-dribble-delete-file ()
934 (when (file-exists-p (gnus-dribble-file-name))
935 (delete-file (gnus-dribble-file-name)))
936 (when gnus-dribble-buffer
937 (with-current-buffer gnus-dribble-buffer
938 (let ((auto (make-auto-save-file-name)))
939 (when (file-exists-p auto)
940 (delete-file auto))
941 (erase-buffer)
942 (set-buffer-modified-p nil)))))
944 (defun gnus-dribble-save ()
945 (when (and gnus-dribble-buffer
946 (buffer-name gnus-dribble-buffer))
947 (with-current-buffer gnus-dribble-buffer
948 (when (> (buffer-size) 0)
949 (save-buffer)))))
951 (defun gnus-dribble-clear ()
952 (when (gnus-buffer-exists-p gnus-dribble-buffer)
953 (with-current-buffer gnus-dribble-buffer
954 (erase-buffer)
955 (set-buffer-modified-p nil)
956 (setq buffer-saved-size (buffer-size)))))
960 ;;; Active & Newsrc File Handling
963 (defun gnus-setup-news (&optional rawfile level dont-connect)
964 "Setup news information.
965 If RAWFILE is non-nil, the .newsrc file will also be read.
966 If LEVEL is non-nil, the news will be set up at level LEVEL."
967 (require 'nnmail)
968 (let ((init (not (and gnus-newsrc-alist gnus-active-hashtb (not rawfile))))
969 ;; Binding this variable will inhibit multiple fetchings
970 ;; of the same mail source.
971 (nnmail-fetched-sources (list t)))
973 (when init
974 ;; Clear some variables to re-initialize news information.
975 (setq gnus-newsrc-alist nil
976 gnus-active-hashtb nil)
977 ;; Read the newsrc file and create `gnus-newsrc-hashtb'.
978 (gnus-read-newsrc-file rawfile))
980 ;; Make sure the archive server is available to all and sundry.
981 (let ((method (or (and (stringp gnus-message-archive-method)
982 (gnus-server-to-method
983 gnus-message-archive-method))
984 gnus-message-archive-method)))
985 ;; Check whether the archive method is writable.
986 (unless (or (not method)
987 (stringp method)
988 (memq 'respool (assoc (format "%s" (car method))
989 gnus-valid-select-methods)))
990 (setq method "archive")) ;; The default.
991 (when (stringp method)
992 (setq method `(nnfolder
993 ,method
994 (nnfolder-directory
995 ,(nnheader-concat message-directory method))
996 (nnfolder-active-file
997 ,(nnheader-concat message-directory
998 (concat method "/active")))
999 (nnfolder-get-new-mail nil)
1000 (nnfolder-inhibit-expiry t))))
1001 (if (assoc "archive" gnus-server-alist)
1002 (when gnus-update-message-archive-method
1003 (if method
1004 (setcdr (assoc "archive" gnus-server-alist) method)
1005 (setq gnus-server-alist (delq (assoc "archive" gnus-server-alist)
1006 gnus-server-alist))))
1007 (when method
1008 (push (cons "archive" method) gnus-server-alist))))
1010 ;; If we don't read the complete active file, we fill in the
1011 ;; hashtb here.
1012 (when (or (null gnus-read-active-file)
1013 (eq gnus-read-active-file 'some))
1014 (gnus-update-active-hashtb-from-killed))
1015 (unless gnus-active-hashtb
1016 (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
1017 ;; Initialize the cache.
1018 (when gnus-use-cache
1019 (gnus-cache-open))
1021 ;; Possibly eval the dribble file.
1022 (and init
1023 (or gnus-use-dribble-file gnus-slave)
1024 (gnus-dribble-eval-file))
1026 ;; Slave Gnusii should then clear the dribble buffer.
1027 (when (and init gnus-slave)
1028 (gnus-dribble-clear))
1030 (gnus-update-format-specifications)
1032 ;; See whether we need to read the description file.
1033 (when (and (boundp 'gnus-group-line-format)
1034 (stringp gnus-group-line-format)
1035 (let ((case-fold-search nil))
1036 (string-match "%[-,0-9]*D" gnus-group-line-format))
1037 (not gnus-description-hashtb)
1038 (not dont-connect)
1039 gnus-read-active-file)
1040 (gnus-read-all-descriptions-files))
1042 ;; Find new newsgroups and treat them.
1043 (when (and init gnus-check-new-newsgroups (not level)
1044 (gnus-check-server gnus-select-method)
1045 (not gnus-slave)
1046 gnus-plugged)
1047 (gnus-find-new-newsgroups))
1049 ;; Check and remove bogus newsgroups.
1050 (when (and init gnus-check-bogus-newsgroups
1051 gnus-read-active-file (not level)
1052 (gnus-server-opened gnus-select-method))
1053 (gnus-check-bogus-newsgroups))
1055 ;; Read any slave files.
1056 (gnus-master-read-slave-newsrc)
1058 ;; Find the number of unread articles in each non-dead group.
1059 (let ((gnus-read-active-file (and (not level) gnus-read-active-file)))
1060 (gnus-get-unread-articles level dont-connect))))
1062 (defun gnus-call-subscribe-functions (method group)
1063 "Call METHOD to subscribe GROUP.
1064 If no function returns `non-nil', call `gnus-subscribe-zombies'."
1065 (unless (cond
1066 ((functionp method)
1067 (funcall method group))
1068 ((listp method)
1069 (catch 'found
1070 (dolist (func method)
1071 (if (funcall func group)
1072 (throw 'found t)))
1073 nil))
1074 (t nil))
1075 (gnus-subscribe-zombies group)))
1077 (defun gnus-find-new-newsgroups (&optional arg)
1078 "Search for new newsgroups and add them.
1079 Each new newsgroup will be treated with `gnus-subscribe-newsgroup-method'.
1080 The `-n' option line from .newsrc is respected.
1082 With 1 C-u, use the `ask-server' method to query the server for new
1083 groups.
1084 With 2 C-u's, use most complete method possible to query the server
1085 for new groups, and subscribe the new groups as zombies."
1086 (interactive "p")
1087 (let* ((gnus-subscribe-newsgroup-method
1088 gnus-subscribe-newsgroup-method)
1089 (check (cond
1090 ((or (and (= (or arg 1) 4)
1091 (not (listp gnus-check-new-newsgroups)))
1092 (null gnus-read-active-file)
1093 (eq gnus-read-active-file 'some))
1094 'ask-server)
1095 ((= (or arg 1) 16)
1096 (setq gnus-subscribe-newsgroup-method
1097 'gnus-subscribe-zombies)
1099 (t gnus-check-new-newsgroups))))
1100 (if (or (consp check)
1101 (eq check 'ask-server))
1102 ;; Ask the server for new groups.
1103 (gnus-ask-server-for-new-groups)
1104 ;; Go through the active hashtb and look for new groups.
1105 (let ((groups 0)
1106 group new-newsgroups)
1107 (gnus-message 5 "Looking for new newsgroups...")
1108 (unless gnus-have-read-active-file
1109 (gnus-read-active-file))
1110 (setq gnus-newsrc-last-checked-date (message-make-date))
1111 (unless gnus-killed-hashtb
1112 (gnus-make-hashtable-from-killed))
1113 ;; Go though every newsgroup in `gnus-active-hashtb' and compare
1114 ;; with `gnus-newsrc-hashtb' and `gnus-killed-hashtb'.
1115 (mapatoms
1116 (lambda (sym)
1117 (if (or (null (setq group (symbol-name sym)))
1118 (not (boundp sym))
1119 (null (symbol-value sym))
1120 (gnus-gethash group gnus-killed-hashtb)
1121 (gnus-gethash group gnus-newsrc-hashtb))
1123 (let ((do-sub (gnus-matches-options-n group)))
1124 (cond
1125 ((eq do-sub 'subscribe)
1126 (setq groups (1+ groups))
1127 (gnus-sethash group group gnus-killed-hashtb)
1128 (gnus-call-subscribe-functions
1129 gnus-subscribe-options-newsgroup-method group))
1130 ((eq do-sub 'ignore)
1131 nil)
1133 (setq groups (1+ groups))
1134 (gnus-sethash group group gnus-killed-hashtb)
1135 (if gnus-subscribe-hierarchical-interactive
1136 (push group new-newsgroups)
1137 (gnus-call-subscribe-functions
1138 gnus-subscribe-newsgroup-method group)))))))
1139 gnus-active-hashtb)
1140 (when new-newsgroups
1141 (gnus-subscribe-hierarchical-interactive new-newsgroups))
1142 (if (> groups 0)
1143 (gnus-message 5 "%d new newsgroup%s arrived."
1144 groups (if (> groups 1) "s have" " has"))
1145 (gnus-message 5 "No new newsgroups."))
1146 groups))))
1148 (defun gnus-matches-options-n (group)
1149 ;; Returns `subscribe' if the group is to be unconditionally
1150 ;; subscribed, `ignore' if it is to be ignored, and nil if there is
1151 ;; no match for the group.
1153 ;; First we check the two user variables.
1154 (cond
1155 ((and gnus-options-subscribe
1156 (string-match gnus-options-subscribe group))
1157 'subscribe)
1158 ((let ((do-subscribe nil))
1159 (dolist (category gnus-auto-subscribed-categories)
1160 (when (gnus-member-of-valid category group)
1161 (setq do-subscribe t)))
1162 do-subscribe)
1163 'subscribe)
1164 ((and gnus-auto-subscribed-groups
1165 (string-match gnus-auto-subscribed-groups group))
1166 'subscribe)
1167 ((and gnus-options-not-subscribe
1168 (string-match gnus-options-not-subscribe group))
1169 'ignore)
1170 ;; Then we go through the list that was retrieved from the .newsrc
1171 ;; file. This list has elements on the form
1172 ;; `(REGEXP . {ignore,subscribe})'. The first match found (the list
1173 ;; is in the reverse order of the options line) is returned.
1175 (let ((regs gnus-newsrc-options-n))
1176 (while (and regs
1177 (not (string-match (caar regs) group)))
1178 (setq regs (cdr regs)))
1179 (and regs (cdar regs))))))
1181 (defun gnus-ask-server-for-new-groups ()
1182 (let* ((new-date (message-make-date))
1183 (date (or gnus-newsrc-last-checked-date new-date))
1184 (methods (cons gnus-select-method
1185 (nconc
1186 (when (gnus-archive-server-wanted-p)
1187 (list "archive"))
1188 (append
1189 (and (consp gnus-check-new-newsgroups)
1190 gnus-check-new-newsgroups)
1191 gnus-secondary-select-methods))))
1192 (groups 0)
1193 group new-newsgroups got-new method hashtb
1194 gnus-override-subscribe-method)
1195 (unless gnus-killed-hashtb
1196 (gnus-make-hashtable-from-killed))
1197 ;; Go through both primary and secondary select methods and
1198 ;; request new newsgroups.
1199 (while (setq method (gnus-server-get-method nil (pop methods)))
1200 (setq new-newsgroups nil
1201 gnus-override-subscribe-method method)
1202 (when (and (gnus-check-server method)
1203 (gnus-request-newgroups date method))
1204 (save-excursion
1205 (setq got-new t
1206 hashtb (gnus-make-hashtable 100))
1207 (set-buffer nntp-server-buffer)
1208 ;; Enter all the new groups into a hashtable.
1209 (gnus-active-to-gnus-format method hashtb 'ignore))
1210 ;; Now all new groups from `method' are in `hashtb'.
1211 (mapatoms
1212 (lambda (group-sym)
1213 (if (or (null (setq group (symbol-name group-sym)))
1214 (not (boundp group-sym))
1215 (null (symbol-value group-sym))
1216 (gnus-gethash group gnus-newsrc-hashtb)
1217 (member group gnus-zombie-list)
1218 (member group gnus-killed-list))
1219 ;; The group is already known.
1221 ;; Make this group active.
1222 (when (symbol-value group-sym)
1223 (gnus-set-active group (symbol-value group-sym)))
1224 ;; Check whether we want it or not.
1225 (let ((do-sub (gnus-matches-options-n group)))
1226 (cond
1227 ((eq do-sub 'subscribe)
1228 (incf groups)
1229 (gnus-sethash group group gnus-killed-hashtb)
1230 (gnus-call-subscribe-functions
1231 gnus-subscribe-options-newsgroup-method group))
1232 ((eq do-sub 'ignore)
1233 nil)
1235 (incf groups)
1236 (gnus-sethash group group gnus-killed-hashtb)
1237 (if gnus-subscribe-hierarchical-interactive
1238 (push group new-newsgroups)
1239 (gnus-call-subscribe-functions
1240 gnus-subscribe-newsgroup-method group)))))))
1241 hashtb))
1242 (when new-newsgroups
1243 (gnus-subscribe-hierarchical-interactive new-newsgroups)))
1244 (if (> groups 0)
1245 (gnus-message 5 "%d new newsgroup%s arrived"
1246 groups (if (> groups 1) "s have" " has"))
1247 (gnus-message 5 "No new newsgroups"))
1248 (when got-new
1249 (setq gnus-newsrc-last-checked-date new-date))
1250 new-newsgroups))
1252 (defun gnus-subscribe-group (group &optional previous method)
1253 "Subscribe GROUP and put it after PREVIOUS."
1254 (gnus-group-change-level
1255 (if method
1256 (list t group gnus-level-default-subscribed nil nil method)
1257 group)
1258 gnus-level-default-subscribed gnus-level-killed previous t)
1261 ;; `gnus-group-change-level' is the fundamental function for changing
1262 ;; subscription levels of newsgroups. This might mean just changing
1263 ;; from level 1 to 2, which is pretty trivial, from 2 to 6 or back
1264 ;; again, which subscribes/unsubscribes a group, which is equally
1265 ;; trivial. Changing from 1-7 to 8-9 means that you kill a group, and
1266 ;; from 8-9 to 1-7 means that you remove the group from the list of
1267 ;; killed (or zombie) groups and add them to the (kinda) subscribed
1268 ;; groups. And last but not least, moving from 8 to 9 and 9 to 8,
1269 ;; which is trivial.
1270 ;; ENTRY can either be a string (newsgroup name) or a list (if
1271 ;; FROMKILLED is t, it's a list on the format (NUM INFO-LIST),
1272 ;; otherwise it's a list in the format of the `gnus-newsrc-hashtb'
1273 ;; entries.
1274 ;; LEVEL is the new level of the group, OLDLEVEL is the old level and
1275 ;; PREVIOUS is the group (in hashtb entry format) to insert this group
1276 ;; after.
1277 (defun gnus-group-change-level (entry level &optional oldlevel
1278 previous fromkilled)
1279 (let (group info active num)
1280 ;; Glean what info we can from the arguments
1281 (if (consp entry)
1282 (if fromkilled (setq group (nth 1 entry))
1283 (setq group (car (nth 2 entry))))
1284 (setq group entry))
1285 (when (and (stringp entry)
1286 oldlevel
1287 (< oldlevel gnus-level-zombie))
1288 (setq entry (gnus-group-entry entry)))
1289 (if (and (not oldlevel)
1290 (consp entry))
1291 (setq oldlevel (gnus-info-level (nth 2 entry)))
1292 (setq oldlevel (or oldlevel gnus-level-killed)))
1293 (when (stringp previous)
1294 (setq previous (gnus-group-entry previous)))
1296 (if (and (>= oldlevel gnus-level-zombie)
1297 (gnus-group-entry group))
1298 ;; We are trying to subscribe a group that is already
1299 ;; subscribed.
1300 () ; Do nothing.
1302 (unless (gnus-ephemeral-group-p group)
1303 (gnus-dribble-enter
1304 (format "(gnus-group-change-level %S %S %S %S %S)"
1305 group level oldlevel (car (nth 2 previous)) fromkilled)))
1307 ;; Then we remove the newgroup from any old structures, if needed.
1308 ;; If the group was killed, we remove it from the killed or zombie
1309 ;; list. If not, and it is in fact going to be killed, we remove
1310 ;; it from the newsrc hash table and assoc.
1311 (cond
1312 ((>= oldlevel gnus-level-zombie)
1313 ;; oldlevel could be wrong.
1314 (setq gnus-zombie-list (delete group gnus-zombie-list))
1315 (setq gnus-killed-list (delete group gnus-killed-list)))
1317 (when (and (>= level gnus-level-zombie)
1318 entry)
1319 (gnus-sethash (car (nth 2 entry)) nil gnus-newsrc-hashtb)
1320 (when (nth 3 entry)
1321 (setcdr (gnus-group-entry (car (nth 3 entry)))
1322 (cdr entry)))
1323 (setcdr (cdr entry) (cdddr entry)))))
1325 ;; Finally we enter (if needed) the list where it is supposed to
1326 ;; go, and change the subscription level. If it is to be killed,
1327 ;; we enter it into the killed or zombie list.
1328 (cond
1329 ((>= level gnus-level-zombie)
1330 ;; Remove from the hash table.
1331 (gnus-sethash group nil gnus-newsrc-hashtb)
1332 (if (= level gnus-level-zombie)
1333 (push group gnus-zombie-list)
1334 (if (= oldlevel gnus-level-killed)
1335 ;; Remove from active hashtb.
1336 (unintern group gnus-active-hashtb)
1337 ;; Don't add it into killed-list if it was killed.
1338 (push group gnus-killed-list))))
1340 ;; If the list is to be entered into the newsrc assoc, and
1341 ;; it was killed, we have to create an entry in the newsrc
1342 ;; hashtb format and fix the pointers in the newsrc assoc.
1343 (if (< oldlevel gnus-level-zombie)
1344 ;; It was alive, and it is going to stay alive, so we
1345 ;; just change the level and don't change any pointers or
1346 ;; hash table entries.
1347 (setcar (cdaddr entry) level)
1348 (if (listp entry)
1349 (setq info (cdr entry)
1350 num (car entry))
1351 (setq active (gnus-active group))
1352 (setq num
1353 (if active (- (1+ (cdr active)) (car active)) t))
1354 ;; Shorten the select method if possible, if we need to
1355 ;; store it at all (native groups).
1356 (let ((method (gnus-method-simplify
1357 (or gnus-override-subscribe-method
1358 (gnus-group-method group)))))
1359 (if method
1360 (setq info (list group level nil nil method))
1361 (setq info (list group level nil)))))
1362 (unless previous
1363 (setq previous
1364 (let ((p gnus-newsrc-alist))
1365 (while (cddr p)
1366 (setq p (cdr p)))
1367 p)))
1368 (setq entry (cons info (cddr previous)))
1369 (if (cdr previous)
1370 (progn
1371 (setcdr (cdr previous) entry)
1372 (gnus-sethash group (cons num (cdr previous))
1373 gnus-newsrc-hashtb))
1374 (setcdr previous entry)
1375 (gnus-sethash group (cons num previous)
1376 gnus-newsrc-hashtb))
1377 (when (cdr entry)
1378 (setcdr (gnus-group-entry (caadr entry)) entry))
1379 (gnus-dribble-enter
1380 (format "(gnus-group-set-info '%S)" info)
1381 (concat "^(gnus-group-set-info '(\"" (regexp-quote group) "\"")))))
1382 (when gnus-group-change-level-function
1383 (funcall gnus-group-change-level-function
1384 group level oldlevel previous)))))
1386 (defun gnus-check-bogus-newsgroups (&optional confirm)
1387 "Remove bogus newsgroups.
1388 If CONFIRM is non-nil, the user has to confirm the deletion of every
1389 newsgroup."
1390 (let ((newsrc (cdr gnus-newsrc-alist))
1391 bogus group entry info)
1392 (gnus-message 5 "Checking bogus newsgroups...")
1393 (unless (gnus-read-active-file-p)
1394 (gnus-read-active-file t))
1395 (when (gnus-read-active-file-p)
1396 ;; Find all bogus newsgroup that are subscribed.
1397 (while newsrc
1398 (setq info (pop newsrc)
1399 group (gnus-info-group info))
1400 (unless (or (gnus-active group) ; Active
1401 (and (gnus-info-method info)
1402 (not (gnus-secondary-method-p
1403 (gnus-info-method info))))) ; Foreign
1404 ;; Found a bogus newsgroup.
1405 (push group bogus)))
1406 (if confirm
1407 (map-y-or-n-p
1408 (format "Remove bogus group %%s (of %d groups)? " (length bogus))
1409 (lambda (group)
1410 ;; Remove all bogus subscribed groups by first killing them, and
1411 ;; then removing them from the list of killed groups.
1412 (when (setq entry (gnus-group-entry group))
1413 (gnus-group-change-level entry gnus-level-killed)
1414 (setq gnus-killed-list (delete group gnus-killed-list))))
1415 bogus '("group" "groups" "remove"))
1416 (while (setq group (pop bogus))
1417 ;; Remove all bogus subscribed groups by first killing them, and
1418 ;; then removing them from the list of killed groups.
1419 (when (setq entry (gnus-group-entry group))
1420 (gnus-group-change-level entry gnus-level-killed)
1421 (setq gnus-killed-list (delete group gnus-killed-list)))))
1422 ;; Then we remove all bogus groups from the list of killed and
1423 ;; zombie groups. They are removed without confirmation.
1424 (let ((dead-lists '(gnus-killed-list gnus-zombie-list))
1425 killed)
1426 (while dead-lists
1427 (setq killed (symbol-value (car dead-lists)))
1428 (while killed
1429 (unless (gnus-active (setq group (pop killed)))
1430 ;; The group is bogus.
1431 ;; !!!Slow as hell.
1432 (set (car dead-lists)
1433 (delete group (symbol-value (car dead-lists))))))
1434 (setq dead-lists (cdr dead-lists))))
1435 (gnus-run-hooks 'gnus-check-bogus-groups-hook)
1436 (gnus-message 5 "Checking bogus newsgroups...done"))))
1438 (defun gnus-check-duplicate-killed-groups ()
1439 "Remove duplicates from the list of killed groups."
1440 (interactive)
1441 (let ((killed gnus-killed-list))
1442 (while killed
1443 (gnus-message 9 "%d" (length killed))
1444 (setcdr killed (delete (car killed) (cdr killed)))
1445 (setq killed (cdr killed)))))
1447 ;; We want to inline a function from gnus-cache, so we cheat here:
1448 (defvar gnus-cache-active-hashtb)
1449 (eval-when-compile
1450 (defun gnus-cache-possibly-alter-active (group active)
1451 "Alter the ACTIVE info for GROUP to reflect the articles in the cache."
1452 (when gnus-cache-active-hashtb
1453 (let ((cache-active (gnus-gethash group gnus-cache-active-hashtb)))
1454 (when cache-active
1455 (when (< (car cache-active) (car active))
1456 (setcar active (car cache-active)))
1457 (when (> (cdr cache-active) (cdr active))
1458 (setcdr active (cdr cache-active))))))))
1460 (defun gnus-activate-group (group &optional scan dont-check method
1461 dont-sub-check)
1462 "Check whether a group has been activated or not.
1463 If SCAN, request a scan of that group as well. If METHOD, use
1464 that select method instead of determining the method based on the
1465 group name. If DONT-CHECK, don't check whether the group
1466 actually exists. If DONT-SUB-CHECK or DONT-CHECK, don't let the
1467 backend check whether the group actually exists."
1468 (let ((method (or method (inline (gnus-find-method-for-group group))))
1469 active)
1470 (and (inline (gnus-check-server method))
1471 ;; We escape all bugs and quit here to make it possible to
1472 ;; continue if a group is so out-there that it reports bugs
1473 ;; and stuff.
1474 (progn
1475 (and scan
1476 (gnus-check-backend-function 'request-scan (car method))
1477 (gnus-request-scan group method))
1479 (if (or debug-on-error debug-on-quit)
1480 (inline (gnus-request-group group (or dont-sub-check dont-check)
1481 method
1482 (gnus-get-info group)))
1483 (condition-case nil
1484 (inline (gnus-request-group group (or dont-sub-check dont-check)
1485 method
1486 (gnus-get-info group)))
1487 (quit
1488 (if debug-on-quit
1489 (debug "Quit")
1490 (message "Quit activating %s" group))
1491 nil)))
1492 (unless dont-check
1493 (setq active (gnus-parse-active))
1494 ;; If there are no articles in the group, the GROUP
1495 ;; command may have responded with the `(0 . 0)'. We
1496 ;; ignore this if we already have an active entry
1497 ;; for the group.
1498 (if (and (zerop (or (car active) 0))
1499 (zerop (or (cdr active) 0))
1500 (gnus-active group))
1501 (gnus-active group)
1503 ;; If a cache is present, we may have to alter the active info.
1504 (when gnus-use-cache
1505 (inline (gnus-cache-possibly-alter-active
1506 group active)))
1508 ;; If the agent is enabled, we may have to alter the active info.
1509 (when gnus-agent
1510 (gnus-agent-possibly-alter-active group active))
1512 (gnus-set-active group active)
1513 ;; Return the new active info.
1514 active)))))
1516 (defun gnus-get-unread-articles-in-group (info active &optional update)
1517 (when (and info active)
1518 ;; Allow the backend to update the info in the group.
1519 (when (and update
1520 (gnus-request-update-info
1521 info (inline (gnus-find-method-for-group
1522 (gnus-info-group info)))))
1523 (gnus-activate-group (gnus-info-group info) nil t))
1525 (let* ((range (gnus-info-read info))
1526 (num 0))
1528 ;; These checks are present in gnus-activate-group but skipped
1529 ;; due to setting dont-check in the preceding call.
1531 ;; If a cache is present, we may have to alter the active info.
1532 (when (and gnus-use-cache info)
1533 (inline (gnus-cache-possibly-alter-active
1534 (gnus-info-group info) active)))
1536 ;; If the agent is enabled, we may have to alter the active info.
1537 (when (and gnus-agent info)
1538 (gnus-agent-possibly-alter-active (gnus-info-group info) active info))
1540 ;; Modify the list of read articles according to what articles
1541 ;; are available; then tally the unread articles and add the
1542 ;; number to the group hash table entry.
1543 (cond
1544 ((zerop (cdr active))
1545 (setq num 0))
1546 ((not range)
1547 (setq num (- (1+ (cdr active)) (car active))))
1548 ((not (listp (cdr range)))
1549 ;; Fix a single (num . num) range according to the
1550 ;; active hash table.
1551 ;; Fix by Carsten Bormann <cabo@Informatik.Uni-Bremen.DE>.
1552 (and (< (cdr range) (car active)) (setcdr range (1- (car active))))
1553 (and (> (cdr range) (cdr active)) (setcdr range (cdr active)))
1554 ;; Compute number of unread articles.
1555 (setq num (max 0 (- (cdr active) (- (1+ (cdr range)) (car range))))))
1557 ;; The read list is a list of ranges. Fix them according to
1558 ;; the active hash table.
1559 ;; First peel off any elements that are below the lower
1560 ;; active limit.
1561 (while (and (cdr range)
1562 (>= (car active)
1563 (or (and (atom (cadr range)) (cadr range))
1564 (caadr range))))
1565 (if (numberp (car range))
1566 (setcar range
1567 (cons (car range)
1568 (or (and (numberp (cadr range))
1569 (cadr range))
1570 (cdadr range))))
1571 (setcdr (car range)
1572 (or (and (numberp (nth 1 range)) (nth 1 range))
1573 (cdadr range))))
1574 (setcdr range (cddr range)))
1575 ;; Adjust the first element to be the same as the lower limit.
1576 (when (and (not (atom (car range)))
1577 (< (cdar range) (car active)))
1578 (setcdr (car range) (1- (car active))))
1579 ;; Then we want to peel off any elements that are higher
1580 ;; than the upper active limit.
1581 (let ((srange range))
1582 ;; Go past all valid elements.
1583 (while (and (cdr srange)
1584 (<= (or (and (atom (cadr srange))
1585 (cadr srange))
1586 (caadr srange))
1587 (cdr active)))
1588 (setq srange (cdr srange)))
1589 (when (cdr srange)
1590 ;; Nuke all remaining invalid elements.
1591 (setcdr srange nil))
1593 ;; Adjust the final element.
1594 (when (and (not (atom (car srange)))
1595 (> (cdar srange) (cdr active)))
1596 (setcdr (car srange) (cdr active))))
1597 ;; Compute the number of unread articles.
1598 (while range
1599 (setq num (+ num (- (1+ (or (and (atom (car range)) (car range))
1600 (cdar range)))
1601 (or (and (atom (car range)) (car range))
1602 (caar range)))))
1603 (setq range (cdr range)))
1604 (setq num (max 0 (- (cdr active) num)))))
1605 ;; Set the number of unread articles.
1606 (when (and info
1607 (gnus-group-entry (gnus-info-group info)))
1608 (setcar (gnus-group-entry (gnus-info-group info)) num))
1609 num)))
1611 ;; Go though `gnus-newsrc-alist' and compare with `gnus-active-hashtb'
1612 ;; and compute how many unread articles there are in each group.
1613 (defun gnus-get-unread-articles (&optional level dont-connect one-level)
1614 (setq gnus-server-method-cache nil)
1615 (require 'gnus-agent)
1616 (let* ((newsrc (cdr gnus-newsrc-alist))
1617 (alevel (or level gnus-activate-level (1+ gnus-level-subscribed)))
1618 (foreign-level
1620 level
1621 (min
1622 (cond ((and gnus-activate-foreign-newsgroups
1623 (not (numberp gnus-activate-foreign-newsgroups)))
1624 (1+ gnus-level-subscribed))
1625 ((numberp gnus-activate-foreign-newsgroups)
1626 gnus-activate-foreign-newsgroups)
1627 (t 0))
1628 alevel)))
1629 (methods-cache nil)
1630 (type-cache nil)
1631 (gnus-agent-article-local-times 0)
1632 (archive-method (gnus-server-to-method "archive"))
1633 infos info group active method cmethod
1634 method-type method-group-list entry)
1635 (gnus-message 6 "Checking new news...")
1637 (while newsrc
1638 (setq active (gnus-active (setq group (gnus-info-group
1639 (setq info (pop newsrc))))))
1640 ;; First go through all the groups, see what select methods they
1641 ;; belong to, and then collect them into lists per unique select
1642 ;; method.
1643 (if (not (setq method (gnus-info-method info)))
1644 (setq method gnus-select-method)
1645 ;; There may be several similar methods. Possibly extend the
1646 ;; method.
1647 (if (setq cmethod (assoc method methods-cache))
1648 (setq method (cdr cmethod))
1649 (setq cmethod (if (stringp method)
1650 (gnus-server-to-method method)
1651 (inline (gnus-find-method-for-group
1652 (gnus-info-group info) info))))
1653 (push (cons method cmethod) methods-cache)
1654 (setq method cmethod)))
1655 (setq method-group-list (assoc method type-cache))
1656 (unless method-group-list
1657 (setq method-type
1658 (cond
1659 ((or (gnus-secondary-method-p method)
1660 (and (gnus-archive-server-wanted-p)
1661 (gnus-methods-equal-p archive-method method)))
1662 'secondary)
1663 ((inline (gnus-server-equal gnus-select-method method))
1664 'primary)
1666 'foreign)))
1667 (push (setq method-group-list (list method method-type nil nil))
1668 type-cache))
1669 ;; Only add groups that need updating.
1670 (if (or (and foreign-level (null (numberp foreign-level)))
1671 (funcall (if one-level #'= #'<=) (gnus-info-level info)
1672 (if (eq (cadr method-group-list) 'foreign)
1673 foreign-level
1674 alevel)))
1675 (setcar (nthcdr 2 method-group-list)
1676 (cons info (nth 2 method-group-list)))
1677 ;; The group is inactive, so we nix out the number of unread articles.
1678 ;; It leads `(gnus-group-unread group)' to return t. See also
1679 ;; `gnus-group-prepare-flat'.
1680 (unless active
1681 (when (setq entry (gnus-group-entry group))
1682 (setcar entry t)))))
1684 ;; Sort the methods based so that the primary and secondary
1685 ;; methods come first. This is done for legacy reasons to try to
1686 ;; ensure that side-effect behavior doesn't change from previous
1687 ;; Gnus versions.
1688 (setq type-cache
1689 (sort (nreverse type-cache)
1690 (lambda (c1 c2)
1691 (< (gnus-method-rank (cadr c1) (car c1))
1692 (gnus-method-rank (cadr c2) (car c2))))))
1693 ;; Go through the list of servers and possibly extend methods that
1694 ;; aren't equal (and that need extension; i.e., they are async).
1695 (let ((methods nil))
1696 (dolist (elem type-cache)
1697 (destructuring-bind (method method-type infos dummy) elem
1698 (let ((gnus-opened-servers methods))
1699 (when (and (gnus-similar-server-opened method)
1700 (gnus-check-backend-function
1701 'retrieve-group-data-early (car method)))
1702 (setq method (gnus-server-extend-method
1703 (gnus-info-group (car infos))
1704 method))
1705 (setcar elem method))
1706 (push (list method 'ok) methods)))))
1708 ;; If we have primary/secondary select methods, but no groups from
1709 ;; them, we still want to issue a retrieval request from them.
1710 (unless dont-connect
1711 (dolist (method (cons gnus-select-method
1712 gnus-secondary-select-methods))
1713 (when (and (not (assoc method type-cache))
1714 (gnus-check-backend-function 'request-list (car method)))
1715 (with-current-buffer nntp-server-buffer
1716 (gnus-read-active-file-1 method nil)))))
1718 ;; Clear out all the early methods.
1719 (dolist (elem type-cache)
1720 (destructuring-bind (method method-type infos dummy) elem
1721 (when (and method
1722 infos
1723 (gnus-check-backend-function
1724 'retrieve-group-data-early (car method))
1725 (not (gnus-method-denied-p method)))
1726 (when (ignore-errors (gnus-get-function method 'open-server))
1727 (unless (gnus-server-opened method)
1728 (gnus-open-server method))
1729 (when (gnus-server-opened method)
1730 ;; Just mark this server as "cleared".
1731 (gnus-retrieve-group-data-early method nil))))))
1733 ;; Start early async retrieval of data.
1734 (let ((done-methods nil)
1735 sanity-spec)
1736 (dolist (elem type-cache)
1737 (destructuring-bind (method method-type infos dummy) elem
1738 (setq sanity-spec (list (car method) (cadr method)))
1739 (when (and method infos
1740 (not (gnus-method-denied-p method)))
1741 ;; If the open-server method doesn't exist, then the method
1742 ;; itself doesn't exist, so we ignore it.
1743 (if (not (ignore-errors (gnus-get-function method 'open-server)))
1744 (setq type-cache (delq elem type-cache))
1745 (unless (gnus-server-opened method)
1746 (gnus-open-server method))
1747 (when (and
1748 ;; This is a sanity check, so that we never
1749 ;; attempt to start two async requests to the
1750 ;; same server, because that will fail. This
1751 ;; should never happen, since the methods should
1752 ;; be unique at this point, but apparently it
1753 ;; does happen in the wild with some setups.
1754 (not (member sanity-spec done-methods))
1755 (gnus-server-opened method)
1756 (gnus-check-backend-function
1757 'retrieve-group-data-early (car method)))
1758 (push sanity-spec done-methods)
1759 (when (gnus-check-backend-function 'request-scan (car method))
1760 (gnus-request-scan nil method))
1761 ;; Store the token we get back from -early so that we
1762 ;; can pass it to -finish later.
1763 (setcar (nthcdr 3 elem)
1764 (gnus-retrieve-group-data-early method infos))))))))
1766 ;; Do the rest of the retrieval.
1767 (dolist (elem type-cache)
1768 (destructuring-bind (method method-type infos early-data) elem
1769 (when (and method infos
1770 (not (gnus-method-denied-p method)))
1771 (let ((updatep (gnus-check-backend-function
1772 'request-update-info (car method))))
1773 ;; See if any of the groups from this method require updating.
1774 (gnus-read-active-for-groups method infos early-data)
1775 (dolist (info infos)
1776 (inline (gnus-get-unread-articles-in-group
1777 info (gnus-active (gnus-info-group info))
1778 updatep)))))))
1779 (gnus-message 6 "Checking new news...done")))
1781 (defun gnus-method-rank (type method)
1782 (cond
1783 ;; Get info for virtual groups last.
1784 ((eq (car method) 'nnvirtual)
1785 200)
1786 ((eq type 'primary)
1788 ;; Compute the rank of the secondary methods based on where they
1789 ;; are in the secondary select list.
1790 ((eq type 'secondary)
1791 (let ((i 2))
1792 (block nil
1793 (dolist (smethod gnus-secondary-select-methods)
1794 (when (equal method smethod)
1795 (return i))
1796 (incf i))
1797 i)))
1798 ;; Just say that all foreign groups have the same rank.
1800 100)))
1802 (defun gnus-read-active-for-groups (method infos early-data)
1803 (with-current-buffer nntp-server-buffer
1804 (cond
1805 ;; Finish up getting the data from the methods that have -early
1806 ;; methods.
1807 ((and
1808 early-data
1809 (gnus-check-backend-function 'finish-retrieve-group-infos (car method))
1810 (or (not (gnus-agent-method-p method))
1811 (gnus-online method)))
1812 (gnus-finish-retrieve-group-infos method infos early-data)
1813 ;; We may have altered the data now, so mark the dribble buffer
1814 ;; as dirty so that it gets saved.
1815 (gnus-dribble-touch)
1816 (gnus-agent-save-active method))
1817 ;; Most backends have -retrieve-groups.
1818 ((gnus-check-backend-function 'retrieve-groups (car method))
1819 (when (gnus-check-backend-function 'request-scan (car method))
1820 (gnus-request-scan nil method))
1821 (let (groups)
1822 (gnus-read-active-file-2
1823 (dolist (info infos (nreverse groups))
1824 (push (gnus-group-real-name (gnus-info-group info)) groups))
1825 method)))
1826 ;; Virtually all backends have -request-list.
1827 ((gnus-check-backend-function 'request-list (car method))
1828 (gnus-read-active-file-1 method nil))
1829 ;; Except nnvirtual and friends, where we request each group, one
1830 ;; by one.
1832 (dolist (info infos)
1833 (gnus-activate-group (gnus-info-group info) nil nil method t))))))
1835 ;; Create a hash table out of the newsrc alist. The `car's of the
1836 ;; alist elements are used as keys.
1837 (defun gnus-make-hashtable-from-newsrc-alist ()
1838 (let ((alist gnus-newsrc-alist)
1839 (ohashtb gnus-newsrc-hashtb)
1840 prev info method rest methods)
1841 (setq gnus-newsrc-hashtb (gnus-make-hashtable (length alist)))
1842 (setq alist
1843 (setq prev (setq gnus-newsrc-alist
1844 (if (equal (caar gnus-newsrc-alist)
1845 "dummy.group")
1846 gnus-newsrc-alist
1847 (cons (list "dummy.group" 0 nil) alist)))))
1848 (while alist
1849 (setq info (car alist))
1850 ;; Make the same select-methods identical Lisp objects.
1851 (when (setq method (gnus-info-method info))
1852 (if (setq rest (member method methods))
1853 (gnus-info-set-method info (car rest))
1854 (push method methods)))
1855 ;; Check for duplicates.
1856 (if (gnus-gethash (car info) gnus-newsrc-hashtb)
1857 ;; Remove this entry from the alist.
1858 (setcdr prev (cddr prev))
1859 (gnus-sethash
1860 (car info)
1861 ;; Preserve number of unread articles in groups.
1862 (cons (and ohashtb (car (gnus-gethash (car info) ohashtb)))
1863 prev)
1864 gnus-newsrc-hashtb)
1865 (setq prev alist))
1866 (setq alist (cdr alist)))
1867 ;; Make the same select-methods in `gnus-server-alist' identical
1868 ;; as well.
1869 (while methods
1870 (setq method (pop methods))
1871 (when (setq rest (rassoc method gnus-server-alist))
1872 (setcdr rest method)))))
1874 (defun gnus-make-hashtable-from-killed ()
1875 "Create a hash table from the killed and zombie lists."
1876 (let ((lists '(gnus-killed-list gnus-zombie-list))
1877 list)
1878 (setq gnus-killed-hashtb
1879 (gnus-make-hashtable
1880 (+ (length gnus-killed-list) (length gnus-zombie-list))))
1881 (while lists
1882 (setq list (symbol-value (pop lists)))
1883 (while list
1884 (gnus-sethash (car list) (pop list) gnus-killed-hashtb)))))
1886 (defun gnus-parse-active ()
1887 "Parse active info in the nntp server buffer."
1888 (with-current-buffer nntp-server-buffer
1889 (goto-char (point-min))
1890 ;; Parse the result we got from `gnus-request-group'.
1891 (when (looking-at "[0-9]+ [0-9]+ \\([0-9]+\\) [0-9]+")
1892 (goto-char (match-beginning 1))
1893 (cons (read (current-buffer))
1894 (read (current-buffer))))))
1896 (defun gnus-make-articles-unread (group articles)
1897 "Mark ARTICLES in GROUP as unread."
1898 (let* ((info (nth 2 (or (gnus-group-entry group)
1899 (gnus-group-entry
1900 (gnus-group-real-name group)))))
1901 (ranges (gnus-info-read info))
1902 news article)
1903 (while articles
1904 (when (gnus-member-of-range
1905 (setq article (pop articles)) ranges)
1906 (push article news)))
1907 (when news
1908 ;; Enter this list into the group info.
1909 (gnus-info-set-read
1910 info (gnus-remove-from-range (gnus-info-read info) (nreverse news)))
1912 ;; Set the number of unread articles in gnus-newsrc-hashtb.
1913 (gnus-get-unread-articles-in-group info (gnus-active group))
1915 ;; Insert the change into the group buffer and the dribble file.
1916 (gnus-group-update-group group t))))
1918 (defun gnus-make-ascending-articles-unread (group articles)
1919 "Mark ascending ARTICLES in GROUP as unread."
1920 (let* ((entry (or (gnus-group-entry group)
1921 (gnus-group-entry (gnus-group-real-name group))))
1922 (info (nth 2 entry))
1923 (ranges (gnus-info-read info))
1924 (r ranges)
1925 modified)
1927 (while articles
1928 (let ((article (pop articles))) ; get the next article to remove from ranges
1929 (while (let ((range (car ranges))) ; note the current range
1930 (if (atom range) ; single value range
1931 (cond ((not range)
1932 ;; the articles extend past the end of the ranges
1933 ;; OK - I'm done
1934 (setq articles nil))
1935 ((< range article)
1936 ;; this range precedes the article. Leave the range unmodified.
1937 (pop ranges)
1938 ranges)
1939 ((= range article)
1940 ;; this range exactly matches the article; REMOVE THE RANGE.
1941 ;; NOTE: When the range being removed is the last range, the list is corrupted by inserting null at its end.
1942 (setcar ranges (cadr ranges))
1943 (setcdr ranges (cddr ranges))
1944 (setq modified (if (car ranges) t 'remove-null))
1945 nil))
1946 (let ((min (car range))
1947 (max (cdr range)))
1948 ;; I have a min/max range to consider
1949 (cond ((> min max) ; invalid range introduced by splitter
1950 (setcar ranges (cadr ranges))
1951 (setcdr ranges (cddr ranges))
1952 (setq modified (if (car ranges) t 'remove-null))
1953 ranges)
1954 ((= min max)
1955 ;; replace min/max range with a single-value range
1956 (setcar ranges min)
1957 ranges)
1958 ((< max article)
1959 ;; this range precedes the article. Leave the range unmodified.
1960 (pop ranges)
1961 ranges)
1962 ((< article min)
1963 ;; this article precedes the range. Return null to move to the
1964 ;; next article
1965 nil)
1967 ;; this article splits the range into two parts
1968 (setcdr ranges (cons (cons (1+ article) max) (cdr ranges)))
1969 (setcdr range (1- article))
1970 (setq modified t)
1971 ranges))))))))
1973 (when modified
1974 (when (eq modified 'remove-null)
1975 (setq r (delq nil r)))
1976 ;; Enter this list into the group info.
1977 (gnus-info-set-read info r)
1979 ;; Set the number of unread articles in gnus-newsrc-hashtb.
1980 (gnus-get-unread-articles-in-group info (gnus-active group))
1982 ;; Insert the change into the group buffer and the dribble file.
1983 (gnus-group-update-group group t))))
1985 ;; Enter all dead groups into the hashtb.
1986 (defun gnus-update-active-hashtb-from-killed ()
1987 (let ((hashtb (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
1988 (lists (list gnus-killed-list gnus-zombie-list))
1989 killed)
1990 (while lists
1991 (setq killed (car lists))
1992 (while killed
1993 (gnus-sethash (string-as-unibyte (car killed)) nil hashtb)
1994 (setq killed (cdr killed)))
1995 (setq lists (cdr lists)))))
1997 (defun gnus-get-killed-groups ()
1998 "Go through the active hashtb and mark all unknown groups as killed."
1999 ;; First make sure active file has been read.
2000 (unless (gnus-read-active-file-p)
2001 (let ((gnus-read-active-file t))
2002 (gnus-read-active-file)))
2003 (unless gnus-killed-hashtb
2004 (gnus-make-hashtable-from-killed))
2005 ;; Go through all newsgroups that are known to Gnus - enlarge kill list.
2006 (mapatoms
2007 (lambda (sym)
2008 (let ((groups 0)
2009 (group (symbol-name sym)))
2010 (if (or (null group)
2011 (gnus-gethash group gnus-killed-hashtb)
2012 (gnus-gethash group gnus-newsrc-hashtb))
2014 (let ((do-sub (gnus-matches-options-n group)))
2015 (if (or (eq do-sub 'subscribe) (eq do-sub 'ignore))
2017 (setq groups (1+ groups))
2018 (push group gnus-killed-list)
2019 (gnus-sethash group group gnus-killed-hashtb))))))
2020 gnus-active-hashtb)
2021 (gnus-dribble-touch))
2023 ;; Get the active file(s) from the backend(s).
2024 (defun gnus-read-active-file (&optional force not-native)
2025 (gnus-group-set-mode-line)
2026 (let ((methods
2027 (mapcar
2028 (lambda (m) (if (stringp m) (gnus-server-get-method nil m) m))
2029 (append
2030 (if (and (not not-native)
2031 (gnus-check-server gnus-select-method))
2032 ;; The native server is available.
2033 (cons gnus-select-method gnus-secondary-select-methods)
2034 ;; The native server is down, so we just do the
2035 ;; secondary ones.
2036 gnus-secondary-select-methods)
2037 ;; Also read from the archive server.
2038 (when (gnus-archive-server-wanted-p)
2039 (list "archive")))))
2040 method)
2041 (setq gnus-have-read-active-file nil)
2042 (with-current-buffer nntp-server-buffer
2043 (while (setq method (pop methods))
2044 ;; Only do each method once, in case the methods appear more
2045 ;; than once in this list.
2046 (when (and (not (member method methods))
2047 ;; Check whether the backend exists.
2048 (ignore-errors (gnus-get-function method 'open-server)))
2049 (if (or debug-on-error debug-on-quit)
2050 (gnus-read-active-file-1 method force)
2051 (condition-case ()
2052 (gnus-read-active-file-1 method force)
2053 ;; We catch C-g so that we can continue past servers
2054 ;; that do not respond.
2055 (quit
2056 (if debug-on-quit
2057 (debug "Quit")
2058 (message "Quit reading the active file"))
2059 nil))))))))
2061 (defun gnus-read-active-file-1 (method force)
2062 (let (where mesg)
2063 (setq where (nth 1 method)
2064 mesg (format "Reading active file%s via %s..."
2065 (if (and where (not (zerop (length where))))
2066 (concat " from " where) "")
2067 (car method)))
2068 (gnus-message 5 "%s" mesg)
2069 (when (gnus-check-server method)
2070 ;; Request that the backend scan its incoming messages.
2071 (when (and (or (and gnus-agent
2072 (gnus-online method))
2073 (not gnus-agent))
2074 (gnus-check-backend-function 'request-scan (car method)))
2075 (gnus-request-scan nil method))
2076 (cond
2077 ((and (eq gnus-read-active-file 'some)
2078 (gnus-check-backend-function 'retrieve-groups (car method))
2079 (not force))
2080 (let ((newsrc (cdr gnus-newsrc-alist))
2081 (gmethod (gnus-server-get-method nil method))
2082 groups info)
2083 (while (setq info (pop newsrc))
2084 (when (inline
2085 (gnus-server-equal
2086 (inline
2087 (gnus-find-method-for-group
2088 (gnus-info-group info) info))
2089 gmethod))
2090 (push (gnus-group-real-name (gnus-info-group info))
2091 groups)))
2092 (gnus-read-active-file-2 groups method)))
2093 ((null method)
2096 (if (not (gnus-request-list method))
2097 (unless (equal method gnus-message-archive-method)
2098 (gnus-error 1 "Cannot read active file from %s server"
2099 (car method)))
2100 (gnus-message 5 "%s" mesg)
2101 (gnus-active-to-gnus-format method gnus-active-hashtb nil t)
2102 ;; We mark this active file as read.
2103 (add-to-list 'gnus-have-read-active-file method)
2104 (gnus-message 5 "%sdone" mesg)))))))
2106 (defun gnus-read-active-file-2 (groups method)
2107 "Read an active file for GROUPS in METHOD using `gnus-retrieve-groups'."
2108 (when groups
2109 (with-current-buffer nntp-server-buffer
2110 (gnus-check-server method)
2111 (let ((list-type (gnus-retrieve-groups groups method)))
2112 (cond ((not list-type)
2113 (gnus-error
2114 1.2 "Cannot read partial active file from %s server."
2115 (car method)))
2116 ((eq list-type 'active)
2117 (gnus-active-to-gnus-format method gnus-active-hashtb nil t))
2119 (gnus-groups-to-gnus-format method gnus-active-hashtb t)))))))
2121 ;; Read an active file and place the results in `gnus-active-hashtb'.
2122 (defun gnus-active-to-gnus-format (&optional method hashtb ignore-errors
2123 real-active)
2124 (unless method
2125 (setq method gnus-select-method))
2126 (let ((cur (current-buffer))
2127 (hashtb (or hashtb
2128 (if (and gnus-active-hashtb
2129 (not (equal method gnus-select-method)))
2130 gnus-active-hashtb
2131 (setq gnus-active-hashtb
2132 (if (equal method gnus-select-method)
2133 (gnus-make-hashtable
2134 (count-lines (point-min) (point-max)))
2135 (gnus-make-hashtable 4096))))))
2136 group max min)
2137 ;; Delete unnecessary lines.
2138 (goto-char (point-min))
2139 (cond
2140 ((string= gnus-ignored-newsgroups "")
2141 (delete-matching-lines "^to\\."))
2143 (delete-matching-lines (concat "^to\\.\\|" gnus-ignored-newsgroups))))
2145 (goto-char (point-min))
2146 (unless (re-search-forward "[\\\"]" nil t)
2147 ;; Make the group names readable as a lisp expression even if they
2148 ;; contain special characters.
2149 (goto-char (point-max))
2150 (while (re-search-backward "[][';?()#]" nil t)
2151 (insert ?\\)))
2153 ;; Let the Gnus agent save the active file.
2154 (when (and gnus-agent real-active (gnus-online method))
2155 (gnus-agent-save-active method))
2157 ;; If these are groups from a foreign select method, we insert the
2158 ;; group prefix in front of the group names.
2159 (when (not (gnus-server-equal
2160 (gnus-server-get-method nil method)
2161 (gnus-server-get-method nil gnus-select-method)))
2162 (let ((prefix (gnus-group-prefixed-name "" method)))
2163 (goto-char (point-min))
2164 (while (and (not (eobp))
2165 (progn
2166 (when (= (following-char) ?\")
2167 (forward-char 1))
2168 (insert prefix)
2169 (zerop (forward-line 1)))))))
2170 ;; Store the active file in a hash table.
2171 ;; Use a unibyte buffer in order to make `read' read non-ASCII
2172 ;; group names (which have been encoded) as unibyte strings.
2173 (mm-with-unibyte-buffer
2174 (insert-buffer-substring cur)
2175 (setq cur (current-buffer))
2176 (goto-char (point-min))
2177 (while (not (eobp))
2178 (condition-case ()
2179 (progn
2180 (narrow-to-region (point) (point-at-eol))
2181 ;; group gets set to a symbol interned in the hash table
2182 ;; (what a hack!!) - jwz
2183 (setq group (let ((obarray hashtb)) (read cur)))
2184 ;; ### The extended group name scheme makes
2185 ;; the previous optimization strategy sort of pointless...
2186 (when (stringp group)
2187 (setq group (intern group hashtb)))
2188 (if (and (numberp (setq max (read cur)))
2189 (numberp (setq min (read cur)))
2190 (progn
2191 (skip-chars-forward " \t")
2192 (not
2193 (or (eq (char-after) ?=)
2194 (eq (char-after) ?x)
2195 (eq (char-after) ?j)))))
2196 (progn
2197 (set group (cons min max))
2198 ;; if group is moderated, stick in moderation table
2199 (when (eq (char-after) ?m)
2200 (unless gnus-moderated-hashtb
2201 (setq gnus-moderated-hashtb (gnus-make-hashtable)))
2202 (gnus-sethash (symbol-name group) t
2203 gnus-moderated-hashtb)))
2204 (set group nil)))
2205 (error
2206 (and group
2207 (symbolp group)
2208 (set group nil))
2209 (unless ignore-errors
2210 (gnus-message 3 "Warning - invalid active: %s"
2211 (buffer-substring
2212 (point-at-bol) (point-at-eol))))))
2213 (widen)
2214 (forward-line 1)))))
2216 (defun gnus-groups-to-gnus-format (method &optional hashtb real-active)
2217 ;; Parse a "groups" active file.
2218 (let ((cur (current-buffer))
2219 (hashtb (or hashtb
2220 (if (and method gnus-active-hashtb)
2221 gnus-active-hashtb
2222 (setq gnus-active-hashtb
2223 (gnus-make-hashtable
2224 (count-lines (point-min) (point-max)))))))
2225 (prefix (and method
2226 (not (gnus-server-equal
2227 (gnus-server-get-method nil method)
2228 (gnus-server-get-method nil gnus-select-method)))
2229 (gnus-group-prefixed-name "" method))))
2231 ;; Let the Gnus agent save the active file.
2232 (if (and gnus-agent
2233 real-active
2234 (gnus-online method)
2235 (gnus-agent-method-p method))
2236 (progn
2237 (gnus-agent-save-active method t)
2238 (gnus-active-to-gnus-format method hashtb nil real-active))
2240 (goto-char (point-min))
2241 ;; We split this into to separate loops, one with the prefix
2242 ;; and one without to speed the reading up somewhat.
2243 (if prefix
2244 (let (min max opoint group)
2245 (while (not (eobp))
2246 (condition-case ()
2247 (progn
2248 (read cur) (read cur)
2249 (setq min (read cur)
2250 max (read cur)
2251 opoint (point))
2252 (skip-chars-forward " \t")
2253 (insert prefix)
2254 (goto-char opoint)
2255 (set (let ((obarray hashtb)) (read cur))
2256 (cons min max)))
2257 (error (and group (symbolp group) (set group nil))))
2258 (forward-line 1)))
2259 (let (min max group)
2260 (while (not (eobp))
2261 (condition-case ()
2262 (when (eq (char-after) ?2)
2263 (read cur) (read cur)
2264 (setq min (read cur)
2265 max (read cur))
2266 (set (setq group (let ((obarray hashtb)) (read cur)))
2267 (cons min max)))
2268 (error (and group (symbolp group) (set group nil))))
2269 (forward-line 1)))))))
2271 (defun gnus-read-newsrc-file (&optional force)
2272 "Read startup file.
2273 If FORCE is non-nil, the .newsrc file is read."
2274 ;; Reset variables that might be defined in the .newsrc.eld file.
2275 (let ((variables (remove 'gnus-format-specs gnus-variable-list)))
2276 (while variables
2277 (set (car variables) nil)
2278 (setq variables (cdr variables))))
2279 (let* ((newsrc-file gnus-current-startup-file)
2280 (quick-file (concat newsrc-file ".el")))
2281 (save-excursion
2282 ;; We always load the .newsrc.eld file. If always contains
2283 ;; much information that can not be gotten from the .newsrc
2284 ;; file (ticked articles, killed groups, foreign methods, etc.)
2285 (gnus-read-newsrc-el-file quick-file)
2287 (when (and gnus-read-newsrc-file
2288 (file-exists-p gnus-current-startup-file)
2289 (or force
2290 (and (file-newer-than-file-p newsrc-file quick-file)
2291 (file-newer-than-file-p newsrc-file
2292 (concat quick-file "d")))
2293 (not gnus-newsrc-alist)))
2294 ;; We read the .newsrc file. Note that if there if a
2295 ;; .newsrc.eld file exists, it has already been read, and
2296 ;; the `gnus-newsrc-hashtb' has been created. While reading
2297 ;; the .newsrc file, Gnus will only use the information it
2298 ;; can find there for changing the data already read -
2299 ;; i. e., reading the .newsrc file will not trash the data
2300 ;; already read (except for read articles).
2301 (save-excursion
2302 (gnus-message 5 "Reading %s..." newsrc-file)
2303 (set-buffer (nnheader-find-file-noselect newsrc-file))
2304 (buffer-disable-undo)
2305 (gnus-newsrc-to-gnus-format)
2306 (kill-buffer (current-buffer))
2307 (gnus-message 5 "Reading %s...done" newsrc-file)))
2309 ;; Convert old to new.
2310 (gnus-convert-old-newsrc)
2311 (gnus-clean-old-newsrc))))
2313 (defun gnus-clean-old-newsrc (&optional force)
2314 ;; Currently no cleanups.
2317 (defun gnus-convert-old-newsrc ()
2318 "Convert old newsrc formats into the current format, if needed."
2319 (let ((fcv (and gnus-newsrc-file-version
2320 (gnus-continuum-version gnus-newsrc-file-version)))
2321 (gcv (gnus-continuum-version)))
2322 (when fcv
2323 ;; A newsrc file was loaded.
2324 (let (prompt-displayed
2325 (converters
2326 (sort
2327 (mapcar (lambda (date-func)
2328 (cons (gnus-continuum-version (car date-func))
2329 date-func))
2330 ;; This is a list of converters that must be run
2331 ;; to bring the newsrc file up to the current
2332 ;; version. If you create an incompatibility
2333 ;; with older versions, you should create an
2334 ;; entry here. The entry should consist of the
2335 ;; current gnus version (hardcoded so that it
2336 ;; doesn't change with each release) and the
2337 ;; function that must be applied to convert the
2338 ;; previous version into the current version.
2339 '(("September Gnus v0.1" nil
2340 gnus-convert-old-ticks)
2341 ("Oort Gnus v0.08" "legacy-gnus-agent"
2342 gnus-agent-convert-to-compressed-agentview)
2343 ("Gnus v5.10.7" "legacy-gnus-agent"
2344 gnus-agent-unlist-expire-days)
2345 ("Gnus v5.10.7" "legacy-gnus-agent"
2346 gnus-agent-unhook-expire-days)))
2347 #'car-less-than-car)))
2348 ;; Skip converters older than the file version
2349 (while (and converters (>= fcv (caar converters)))
2350 (pop converters))
2352 ;; Perform converters to bring older version up to date.
2353 (when (and converters (< fcv (caar converters)))
2354 (while (and converters (< fcv (caar converters))
2355 (<= (caar converters) gcv))
2356 (let* ((converter-spec (pop converters))
2357 (convert-to (nth 1 converter-spec))
2358 (load-from (nth 2 converter-spec))
2359 (func (nth 3 converter-spec)))
2360 (when (and load-from
2361 (not (fboundp func)))
2362 (load load-from t))
2363 (or prompt-displayed
2364 (not (gnus-convert-converter-needs-prompt func))
2365 (while (let (c
2366 (cursor-in-echo-area t)
2367 (echo-keystrokes 0))
2368 (message "Convert gnus from version `%s' to `%s'? (n/y/?)"
2369 gnus-newsrc-file-version gnus-version)
2370 (setq c (read-char-exclusive))
2372 (cond ((or (eq c ?n) (eq c ?N))
2373 (error "Can not start gnus without converting"))
2374 ((or (eq c ?y) (eq c ?Y))
2375 (setq prompt-displayed t)
2376 nil)
2377 ((eq c ?\?)
2378 (message "This conversion is irreversible. \
2379 To be safe, you should backup your files before proceeding.")
2380 (sit-for 5)
2383 (gnus-message 3 "Ignoring unexpected input")
2384 (sit-for 3)
2385 t)))))
2387 (funcall func convert-to)))
2388 (gnus-dribble-enter
2389 (format-message ";Converted gnus from version `%s' to `%s'."
2390 gnus-newsrc-file-version gnus-version)))))))
2392 (defun gnus-convert-mark-converter-prompt (converter no-prompt)
2393 "Indicate whether CONVERTER requires gnus-convert-old-newsrc to
2394 display the conversion prompt. NO-PROMPT may be nil (prompt),
2395 t (no prompt), or any form that can be called as a function.
2396 The form should return either t or nil."
2397 (put converter 'gnus-convert-no-prompt no-prompt))
2399 (defun gnus-convert-converter-needs-prompt (converter)
2400 (let ((no-prompt (get converter 'gnus-convert-no-prompt)))
2401 (not (if (memq no-prompt '(t nil))
2402 no-prompt
2403 (funcall no-prompt)))))
2405 (defun gnus-convert-old-ticks (converting-to)
2406 (let ((newsrc (cdr gnus-newsrc-alist))
2407 marks info dormant ticked)
2408 (while (setq info (pop newsrc))
2409 (when (setq marks (gnus-info-marks info))
2410 (setq dormant (cdr (assq 'dormant marks))
2411 ticked (cdr (assq 'tick marks)))
2412 (when (or dormant ticked)
2413 (gnus-info-set-read
2414 info
2415 (gnus-add-to-range
2416 (gnus-info-read info)
2417 (nconc (gnus-uncompress-range dormant)
2418 (gnus-uncompress-range ticked)))))))))
2420 (defun gnus-load (file)
2421 "Load FILE, but in such a way that read errors can be reported."
2422 (with-temp-buffer
2423 (insert-file-contents file)
2424 (while (not (eobp))
2425 (condition-case type
2426 (let ((form (read (current-buffer))))
2427 (eval form))
2428 (error
2429 (unless (eq (car type) 'end-of-file)
2430 (let ((errmsg (format "Error in %s line %d" file
2431 (count-lines (point-min) (point)))))
2432 (ding)
2433 (unless (gnus-yes-or-no-p (concat errmsg "; continue? "))
2434 (error "%s" errmsg)))))))))
2436 (defun gnus-read-newsrc-el-file (file)
2437 (let ((ding-file (concat file "d")))
2438 (when (file-exists-p ding-file)
2439 ;; We always, always read the .eld file.
2440 (gnus-message 5 "Reading %s..." ding-file)
2441 (let (gnus-newsrc-assoc)
2442 (gnus-load ding-file)
2443 ;; Older versions of `gnus-format-specs' are no longer valid
2444 ;; in Oort Gnus 0.01.
2445 (let ((version
2446 (and gnus-newsrc-file-version
2447 (gnus-continuum-version gnus-newsrc-file-version))))
2448 (when (or (not version)
2449 (< version 5.090009))
2450 (setq gnus-format-specs gnus-default-format-specs)))
2451 (when gnus-newsrc-assoc
2452 (setq gnus-newsrc-alist gnus-newsrc-assoc))))
2453 (dolist (elem gnus-newsrc-alist)
2454 ;; Protect against broken .newsrc.el files.
2455 (when (car elem)
2456 (setcar elem (string-as-unibyte (car elem)))))
2457 (gnus-make-hashtable-from-newsrc-alist)
2458 (when (file-newer-than-file-p file ding-file)
2459 ;; Old format quick file
2460 (gnus-message 5 "Reading %s..." file)
2461 ;; The .el file is newer than the .eld file, so we read that one
2462 ;; as well.
2463 (gnus-read-old-newsrc-el-file file)))
2464 (gnus-run-hooks 'gnus-read-newsrc-el-hook))
2466 ;; Parse the old-style quick startup file
2467 (defun gnus-read-old-newsrc-el-file (file)
2468 (let (newsrc killed marked group m info)
2469 (prog1
2470 (let ((gnus-killed-assoc nil)
2471 gnus-marked-assoc gnus-newsrc-alist gnus-newsrc-assoc)
2472 (prog1
2473 (ignore-errors
2474 (load file t t t))
2475 (setq newsrc gnus-newsrc-assoc
2476 killed gnus-killed-assoc
2477 marked gnus-marked-assoc)))
2478 (setq gnus-newsrc-alist nil)
2479 (while (setq group (pop newsrc))
2480 (if (setq info (gnus-get-info (car group)))
2481 (progn
2482 (gnus-info-set-read info (cddr group))
2483 (gnus-info-set-level
2484 info (if (nth 1 group) gnus-level-default-subscribed
2485 gnus-level-default-unsubscribed))
2486 (push info gnus-newsrc-alist))
2487 (push (setq info
2488 (list (car group)
2489 (if (nth 1 group) gnus-level-default-subscribed
2490 gnus-level-default-unsubscribed)
2491 (cddr group)))
2492 gnus-newsrc-alist))
2493 ;; Copy marks into info.
2494 (when (setq m (assoc (car group) marked))
2495 (unless (nthcdr 3 info)
2496 (nconc info (list nil)))
2497 (gnus-info-set-marks
2498 info (list (cons 'tick (gnus-compress-sequence
2499 (sort (cdr m) '<) t))))))
2500 (setq newsrc killed)
2501 (while newsrc
2502 (setcar newsrc (caar newsrc))
2503 (setq newsrc (cdr newsrc)))
2504 (setq gnus-killed-list killed))
2505 ;; The .el file version of this variable does not begin with
2506 ;; "options", while the .eld version does, so we just add it if it
2507 ;; isn't there.
2508 (when
2509 gnus-newsrc-options
2510 (when (not (string-match "^ *options" gnus-newsrc-options))
2511 (setq gnus-newsrc-options (concat "options " gnus-newsrc-options)))
2512 (when (not (string-match "\n$" gnus-newsrc-options))
2513 (setq gnus-newsrc-options (concat gnus-newsrc-options "\n")))
2514 ;; Finally, if we read some options lines, we parse them.
2515 (unless (string= gnus-newsrc-options "")
2516 (gnus-newsrc-parse-options gnus-newsrc-options)))
2518 (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist))
2519 (gnus-make-hashtable-from-newsrc-alist)))
2521 (defun gnus-make-newsrc-file (file)
2522 "Make server dependent file name by catenating FILE and server host name."
2523 (let* ((file (expand-file-name file nil))
2524 (real-file (concat file "-" (nth 1 gnus-select-method))))
2525 (if (or (file-exists-p real-file)
2526 (file-exists-p (concat real-file ".el"))
2527 (file-exists-p (concat real-file ".eld")))
2528 real-file
2529 file)))
2531 (defun gnus-newsrc-to-gnus-format ()
2532 (setq gnus-newsrc-options "")
2533 (setq gnus-newsrc-options-n nil)
2535 (unless gnus-active-hashtb
2536 (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
2537 (let ((buf (current-buffer))
2538 (already-read (> (length gnus-newsrc-alist) 1))
2539 group subscribed options-symbol newsrc Options-symbol
2540 symbol reads num1)
2541 (goto-char (point-min))
2542 ;; We intern the symbol `options' in the active hashtb so that we
2543 ;; can `eq' against it later.
2544 (set (setq options-symbol (intern "options" gnus-active-hashtb)) nil)
2545 (set (setq Options-symbol (intern "Options" gnus-active-hashtb)) nil)
2547 (while (not (eobp))
2548 ;; We first read the first word on the line by narrowing and
2549 ;; then reading into `gnus-active-hashtb'. Most groups will
2550 ;; already exist in that hashtb, so this will save some string
2551 ;; space.
2552 (narrow-to-region
2553 (point)
2554 (progn (skip-chars-forward "^ \t!:\n") (point)))
2555 (goto-char (point-min))
2556 (setq symbol
2557 (and (/= (point-min) (point-max))
2558 (let ((obarray gnus-active-hashtb)) (read buf))))
2559 (widen)
2560 ;; Now, the symbol we have read is either `options' or a group
2561 ;; name. If it is an options line, we just add it to a string.
2562 (cond
2563 ((or (eq symbol options-symbol)
2564 (eq symbol Options-symbol))
2565 (setq gnus-newsrc-options
2566 ;; This concatting is quite inefficient, but since our
2567 ;; thorough studies show that approx 99.37% of all
2568 ;; .newsrc files only contain a single options line, we
2569 ;; don't give a damn, frankly, my dear.
2570 (concat gnus-newsrc-options
2571 (buffer-substring
2572 (point-at-bol)
2573 ;; Options may continue on the next line.
2574 (or (and (re-search-forward "^[^ \t]" nil 'move)
2575 (point-at-bol))
2576 (point)))))
2577 (forward-line -1))
2578 (symbol
2579 ;; Group names can be just numbers.
2580 (when (numberp symbol)
2581 (setq symbol (intern (int-to-string symbol) gnus-active-hashtb)))
2582 (unless (boundp symbol)
2583 (set symbol nil))
2584 ;; It was a group name.
2585 (setq subscribed (eq (char-after) ?:)
2586 group (symbol-name symbol)
2587 reads nil)
2588 (if (eolp)
2589 ;; If the line ends here, this is clearly a buggy line, so
2590 ;; we put point a the beginning of line and let the cond
2591 ;; below do the error handling.
2592 (beginning-of-line)
2593 ;; We skip to the beginning of the ranges.
2594 (skip-chars-forward "!: \t"))
2595 ;; We are now at the beginning of the list of read articles.
2596 ;; We read them range by range.
2597 (while
2598 (cond
2599 ((looking-at "[0-9]+")
2600 ;; We narrow and read a number instead of buffer-substring/
2601 ;; string-to-number because it's faster. narrow/widen is
2602 ;; faster than save-restriction/narrow, and save-restriction
2603 ;; produces a garbage object.
2604 (setq num1 (progn
2605 (narrow-to-region (match-beginning 0) (match-end 0))
2606 (read buf)))
2607 (widen)
2608 ;; If the next character is a dash, then this is a range.
2609 (if (eq (char-after) ?-)
2610 (progn
2611 ;; We read the upper bound of the range.
2612 (forward-char 1)
2613 (if (not (looking-at "[0-9]+"))
2614 ;; This is a buggy line, by we pretend that
2615 ;; it's kinda OK. Perhaps the user should be
2616 ;; dinged?
2617 (push num1 reads)
2618 (push
2619 (cons num1
2620 (progn
2621 (narrow-to-region (match-beginning 0)
2622 (match-end 0))
2623 (read buf)))
2624 reads)
2625 (widen)))
2626 ;; It was just a simple number, so we add it to the
2627 ;; list of ranges.
2628 (push num1 reads))
2629 ;; If the next char in ?\n, then we have reached the end
2630 ;; of the line and return nil.
2631 (not (eq (char-after) ?\n)))
2632 ((eq (char-after) ?\n)
2633 ;; End of line, so we end.
2634 nil)
2636 ;; Not numbers and not eol, so this might be a buggy
2637 ;; line...
2638 (unless (eobp)
2639 ;; If it was eob instead of ?\n, we allow it.
2640 ;; The line was buggy.
2641 (setq group nil)
2642 (gnus-error 3.1 "Mangled line: %s"
2643 (buffer-substring (point-at-bol)
2644 (point-at-eol))))
2645 nil))
2646 ;; Skip past ", ". Spaces are invalid in these ranges, but
2647 ;; we allow them, because it's a common mistake to put a
2648 ;; space after the comma.
2649 (skip-chars-forward ", "))
2651 ;; We have already read .newsrc.eld, so we gently update the
2652 ;; data in the hash table with the information we have just
2653 ;; read.
2654 (when group
2655 (let ((info (gnus-get-info group))
2656 level)
2657 (if info
2658 ;; There is an entry for this file in the alist.
2659 (progn
2660 (gnus-info-set-read info (nreverse reads))
2661 ;; We update the level very gently. In fact, we
2662 ;; only change it if there's been a status change
2663 ;; from subscribed to unsubscribed, or vice versa.
2664 (setq level (gnus-info-level info))
2665 (cond ((and (<= level gnus-level-subscribed)
2666 (not subscribed))
2667 (setq level (if reads
2668 gnus-level-default-unsubscribed
2669 (1+ gnus-level-default-unsubscribed))))
2670 ((and (> level gnus-level-subscribed) subscribed)
2671 (setq level gnus-level-default-subscribed)))
2672 (gnus-info-set-level info level))
2673 ;; This is a new group.
2674 (setq info (list group
2675 (if subscribed
2676 gnus-level-default-subscribed
2677 (if reads
2678 (1+ gnus-level-subscribed)
2679 gnus-level-default-unsubscribed))
2680 (nreverse reads))))
2681 (push info newsrc)))))
2682 (forward-line 1))
2684 (setq newsrc (nreverse newsrc))
2686 (if (not already-read)
2688 ;; We now have two newsrc lists - `newsrc', which is what we
2689 ;; have read from .newsrc, and `gnus-newsrc-alist', which is
2690 ;; what we've read from .newsrc.eld. We have to merge these
2691 ;; lists. We do this by "attaching" any (foreign) groups in the
2692 ;; gnus-newsrc-alist to the (native) group that precedes them.
2693 (let ((rc (cdr gnus-newsrc-alist))
2694 (prev gnus-newsrc-alist)
2695 entry mentry)
2696 (while rc
2697 (or (null (nth 4 (car rc))) ; It's a native group.
2698 (assoc (caar rc) newsrc) ; It's already in the alist.
2699 (if (setq entry (assoc (caar prev) newsrc))
2700 (setcdr (setq mentry (memq entry newsrc))
2701 (cons (car rc) (cdr mentry)))
2702 (push (car rc) newsrc)))
2703 (setq prev rc
2704 rc (cdr rc)))))
2706 (setq gnus-newsrc-alist newsrc)
2707 ;; We make the newsrc hashtb.
2708 (gnus-make-hashtable-from-newsrc-alist)
2710 ;; Finally, if we read some options lines, we parse them.
2711 (unless (string= gnus-newsrc-options "")
2712 (gnus-newsrc-parse-options gnus-newsrc-options))))
2714 ;; Parse options lines to find "options -n !all rec.all" and stuff.
2715 ;; The return value will be a list on the form
2716 ;; ((regexp1 . ignore)
2717 ;; (regexp2 . subscribe)...)
2718 ;; When handling new newsgroups, groups that match a `ignore' regexp
2719 ;; will be ignored, and groups that match a `subscribe' regexp will be
2720 ;; subscribed. A line like
2721 ;; options -n !all rec.all
2722 ;; will lead to a list that looks like
2723 ;; (("^rec\\..+" . subscribe)
2724 ;; ("^.+" . ignore))
2725 ;; So all "rec.*" groups will be subscribed, while all the other
2726 ;; groups will be ignored. Note that "options -n !all rec.all" is very
2727 ;; different from "options -n rec.all !all".
2728 (defun gnus-newsrc-parse-options (options)
2729 (let (out eol)
2730 (save-excursion
2731 (gnus-set-work-buffer)
2732 (insert (regexp-quote options))
2733 ;; First we treat all continuation lines.
2734 (goto-char (point-min))
2735 (while (re-search-forward "\n[ \t]+" nil t)
2736 (replace-match " " t t))
2737 ;; Then we transform all "all"s into ".+"s.
2738 (goto-char (point-min))
2739 (while (re-search-forward "\\ball\\b" nil t)
2740 (replace-match ".+" t t))
2741 (goto-char (point-min))
2742 ;; We remove all other options than the "-n" ones.
2743 (while (re-search-forward "[ \t]-[^n][^-]*" nil t)
2744 (replace-match " ")
2745 (forward-char -1))
2746 (goto-char (point-min))
2748 ;; We are only interested in "options -n" lines - we
2749 ;; ignore the other option lines.
2750 (while (re-search-forward "[ \t]-n" nil t)
2751 (setq eol
2752 (or (save-excursion
2753 (and (re-search-forward "[ \t]-n" (point-at-eol) t)
2754 (- (point) 2)))
2755 (point-at-eol)))
2756 ;; Search for all "words"...
2757 (while (re-search-forward "[^ \t,\n]+" eol t)
2758 (if (eq (char-after (match-beginning 0)) ?!)
2759 ;; If the word begins with a bang (!), this is a "not"
2760 ;; spec. We put this spec (minus the bang) and the
2761 ;; symbol `ignore' into the list.
2762 (push (cons (concat
2763 "^" (buffer-substring
2764 (1+ (match-beginning 0))
2765 (match-end 0))
2766 "\\($\\|\\.\\)")
2767 'ignore)
2768 out)
2769 ;; There was no bang, so this is a "yes" spec.
2770 (push (cons (concat "^" (match-string 0) "\\($\\|\\.\\)")
2771 'subscribe)
2772 out))))
2774 (setq gnus-newsrc-options-n out))))
2776 (eval-and-compile
2777 (defalias 'gnus-long-file-names
2778 (if (fboundp 'msdos-long-file-names)
2779 'msdos-long-file-names
2780 (lambda () t))))
2782 (defvar gnus-save-newsrc-file-last-timestamp nil)
2783 (defun gnus-save-newsrc-file (&optional force)
2784 "Save .newsrc file."
2785 ;; Note: We cannot save .newsrc file if all newsgroups are removed
2786 ;; from the variable gnus-newsrc-alist.
2787 (when (and (or gnus-newsrc-alist gnus-killed-list)
2788 gnus-current-startup-file)
2789 ;; Save agent range limits for the currently active method.
2790 (when gnus-agent
2791 (gnus-agent-save-local force))
2793 (save-excursion
2794 (if (and (or gnus-use-dribble-file gnus-slave)
2795 (not force)
2796 (or (not gnus-dribble-buffer)
2797 (not (buffer-name gnus-dribble-buffer))
2798 (zerop (with-current-buffer gnus-dribble-buffer
2799 (buffer-size)))))
2800 (gnus-message 4 "(No changes need to be saved)")
2801 (gnus-run-hooks 'gnus-save-newsrc-hook)
2802 (if gnus-slave
2803 (gnus-slave-save-newsrc)
2804 ;; Save .newsrc only if the select method is an NNTP method.
2805 ;; The .newsrc file is for interoperability with other
2806 ;; newsreaders, so saving non-NNTP groups there doesn't make
2807 ;; much sense.
2808 (when (and gnus-save-newsrc-file
2809 (eq (car (gnus-server-to-method gnus-select-method))
2810 'nntp))
2811 (gnus-message 8 "Saving %s..." gnus-current-startup-file)
2812 (gnus-gnus-to-newsrc-format)
2813 (gnus-message 8 "Saving %s...done" gnus-current-startup-file))
2815 ;; Save .newsrc.eld.
2816 (set-buffer (gnus-get-buffer-create " *Gnus-newsrc*"))
2817 (make-local-variable 'version-control)
2818 (setq version-control gnus-backup-startup-file)
2819 (setq buffer-file-name
2820 (concat gnus-current-startup-file ".eld"))
2821 (setq default-directory (file-name-directory buffer-file-name))
2822 (buffer-disable-undo)
2823 (erase-buffer)
2824 (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file)
2826 ;; check timestamp of `gnus-current-startup-file'.eld against
2827 ;; `gnus-save-newsrc-file-last-timestamp'
2828 (let* ((checkfile (concat gnus-current-startup-file ".eld"))
2829 (mtime (nth 5 (file-attributes checkfile))))
2830 (when (and gnus-save-newsrc-file-last-timestamp
2831 (time-less-p gnus-save-newsrc-file-last-timestamp
2832 mtime))
2833 (unless (y-or-n-p
2834 (format "%s was updated externally after %s, save?"
2835 checkfile
2836 (format-time-string
2837 "%c"
2838 gnus-save-newsrc-file-last-timestamp)))
2839 (error "Couldn't save %s: updated externally" checkfile))))
2841 (if gnus-save-startup-file-via-temp-buffer
2842 (let ((coding-system-for-write gnus-ding-file-coding-system)
2843 (standard-output (current-buffer)))
2844 (gnus-gnus-to-quick-newsrc-format)
2845 (gnus-run-hooks 'gnus-save-quick-newsrc-hook)
2846 (save-buffer)
2847 (setq gnus-save-newsrc-file-last-timestamp
2848 (nth 5 (file-attributes buffer-file-name))))
2849 (let ((coding-system-for-write gnus-ding-file-coding-system)
2850 (version-control gnus-backup-startup-file)
2851 (startup-file (concat gnus-current-startup-file ".eld"))
2852 (working-dir (file-name-directory gnus-current-startup-file))
2853 working-file
2854 (i -1))
2855 ;; Generate the name of a non-existent file.
2856 (while (progn (setq working-file
2857 (format
2858 (if (and (eq system-type 'ms-dos)
2859 (not (gnus-long-file-names)))
2860 "%s#%d.tm#" ; MSDOS limits files to 8+3
2861 "%s#tmp#%d")
2862 working-dir (setq i (1+ i))))
2863 (file-exists-p working-file)))
2865 (unwind-protect
2866 (progn
2867 (gnus-with-output-to-file working-file
2868 (gnus-gnus-to-quick-newsrc-format)
2869 (gnus-run-hooks 'gnus-save-quick-newsrc-hook))
2871 ;; These bindings will mislead the current buffer
2872 ;; into thinking that it is visiting the startup
2873 ;; file.
2874 (let ((buffer-backed-up nil)
2875 (buffer-file-name startup-file)
2876 (file-precious-flag t)
2877 (setmodes (file-modes startup-file)))
2878 ;; Backup the current version of the startup file.
2879 (backup-buffer)
2881 ;; Replace the existing startup file with the temp file.
2882 (rename-file working-file startup-file t)
2883 (gnus-set-file-modes startup-file setmodes)
2884 (setq gnus-save-newsrc-file-last-timestamp
2885 (nth 5 (file-attributes startup-file)))))
2886 (condition-case nil
2887 (delete-file working-file)
2888 (file-error nil)))))
2890 (gnus-kill-buffer (current-buffer))
2891 (gnus-message
2892 5 "Saving %s.eld...done" gnus-current-startup-file))
2893 (gnus-dribble-delete-file)
2894 (gnus-group-set-mode-line)))))
2896 (defun gnus-gnus-to-quick-newsrc-format (&optional minimal name &rest specific-variables)
2897 "Print Gnus variables such as `gnus-newsrc-alist' in Lisp format."
2898 (princ (format ";; -*- mode:emacs-lisp; coding: %s; -*-\n"
2899 gnus-ding-file-coding-system))
2900 (if name
2901 (princ (format ";; %s\n" name))
2902 (princ ";; Gnus startup file.\n"))
2904 (unless minimal
2905 (princ "\
2906 ;; Never delete this file -- if you want to force Gnus to read the
2907 ;; .newsrc file (if you have one), touch .newsrc instead.\n")
2908 (princ "(setq gnus-newsrc-file-version ")
2909 (princ (gnus-prin1-to-string gnus-version))
2910 (princ ")\n"))
2912 (let* ((print-quoted t)
2913 (print-readably t)
2914 (print-escape-multibyte nil)
2915 (print-escape-nonascii t)
2916 (print-length nil)
2917 (print-level nil)
2918 (print-circle nil)
2919 (print-escape-newlines t)
2920 (gnus-killed-list
2921 (if (and gnus-save-killed-list
2922 (stringp gnus-save-killed-list))
2923 (gnus-strip-killed-list)
2924 gnus-killed-list))
2925 (variables
2926 (or specific-variables
2927 (if gnus-save-killed-list gnus-variable-list
2928 ;; Remove the `gnus-killed-list' from the list of variables
2929 ;; to be saved, if required.
2930 (delq 'gnus-killed-list (copy-sequence gnus-variable-list)))))
2931 ;; Peel off the "dummy" group.
2932 (gnus-newsrc-alist (cdr gnus-newsrc-alist))
2933 variable)
2934 ;; Insert the variables into the file.
2935 (while variables
2936 (when (and (boundp (setq variable (pop variables)))
2937 (symbol-value variable))
2938 (princ "\n(setq ")
2939 (princ (symbol-name variable))
2940 (princ " '")
2941 (prin1 (symbol-value variable))
2942 (princ ")\n")))))
2944 (defun gnus-strip-killed-list ()
2945 "Return the killed list minus the groups that match `gnus-save-killed-list'."
2946 (let ((list gnus-killed-list)
2947 olist)
2948 (while list
2949 (when (string-match gnus-save-killed-list (car list))
2950 (push (car list) olist))
2951 (pop list))
2952 (nreverse olist)))
2954 (defun gnus-gnus-to-newsrc-format (&optional foreign-ok)
2955 (interactive (list (gnus-y-or-n-p "write foreign groups too? ")))
2956 ;; Generate and save the .newsrc file.
2957 (with-current-buffer (create-file-buffer gnus-current-startup-file)
2958 (let ((newsrc (cdr gnus-newsrc-alist))
2959 (standard-output (current-buffer))
2960 info ranges range method)
2961 (setq buffer-file-name gnus-current-startup-file)
2962 (setq default-directory (file-name-directory buffer-file-name))
2963 (buffer-disable-undo)
2964 (erase-buffer)
2965 ;; Use a unibyte buffer since group names are unibyte strings;
2966 ;; in particular, non-ASCII group names are the ones encoded by
2967 ;; a certain coding system.
2968 (mm-disable-multibyte)
2969 ;; Write options.
2970 (when gnus-newsrc-options
2971 (insert gnus-newsrc-options))
2972 ;; Write subscribed and unsubscribed.
2973 (while (setq info (pop newsrc))
2974 ;; Don't write foreign groups to .newsrc.
2975 (when (or (null (setq method (gnus-info-method info)))
2976 (equal method "native")
2977 (inline (gnus-server-equal method gnus-select-method))
2978 foreign-ok)
2979 (insert (gnus-info-group info)
2980 (if (> (gnus-info-level info) gnus-level-subscribed)
2981 "!" ":"))
2982 (when (setq ranges (gnus-info-read info))
2983 (insert " ")
2984 (if (not (listp (cdr ranges)))
2985 (if (= (car ranges) (cdr ranges))
2986 (princ (car ranges))
2987 (princ (car ranges))
2988 (insert "-")
2989 (princ (cdr ranges)))
2990 (while (setq range (pop ranges))
2991 (if (or (atom range) (= (car range) (cdr range)))
2992 (princ (or (and (atom range) range) (car range)))
2993 (princ (car range))
2994 (insert "-")
2995 (princ (cdr range)))
2996 (when ranges
2997 (insert ",")))))
2998 (insert "\n")))
2999 (make-local-variable 'version-control)
3000 (setq version-control 'never)
3001 ;; It has been reported that sometime the modtime on the .newsrc
3002 ;; file seems to be off. We really do want to overwrite it, so
3003 ;; we clear the modtime here before saving. It's a bit odd,
3004 ;; though...
3005 ;; sometimes the modtime clear isn't sufficient. most brute force:
3006 ;; delete the silly thing entirely first. but this fails to provide
3007 ;; such niceties as .newsrc~ creation.
3008 (if gnus-modtime-botch
3009 (delete-file gnus-startup-file)
3010 (clear-visited-file-modtime))
3011 (gnus-run-hooks 'gnus-save-standard-newsrc-hook)
3012 (let ((coding-system-for-write 'raw-text))
3013 (save-buffer))
3014 (kill-buffer (current-buffer)))))
3018 ;;; Slave functions.
3021 (defvar gnus-slave-mode nil)
3023 (defun gnus-slave-mode ()
3024 "Minor mode for slave Gnusae."
3025 ;; FIXME: gnus-slave-mode appears to never be set (i.e. it'll always be nil):
3026 ;; Remove, or fix and use define-minor-mode.
3027 (add-minor-mode 'gnus-slave-mode " Slave" (make-sparse-keymap))
3028 (gnus-run-hooks 'gnus-slave-mode-hook))
3030 (defun gnus-slave-save-newsrc ()
3031 (with-current-buffer gnus-dribble-buffer
3032 (let ((slave-name
3033 (make-temp-file (concat gnus-current-startup-file "-slave-")))
3034 (modes (ignore-errors
3035 (file-modes (concat gnus-current-startup-file ".eld")))))
3036 (let ((coding-system-for-write gnus-ding-file-coding-system))
3037 (gnus-write-buffer slave-name))
3038 (when modes
3039 (gnus-set-file-modes slave-name modes)))))
3041 (defun gnus-master-read-slave-newsrc ()
3042 (let ((slave-files
3043 (directory-files
3044 (file-name-directory gnus-current-startup-file)
3045 t (concat
3046 "^" (regexp-quote
3047 (concat
3048 (file-name-nondirectory gnus-current-startup-file)
3049 "-slave-")))
3051 file)
3052 (if (not slave-files)
3053 () ; There are no slave files to read.
3054 (gnus-message 7 "Reading slave newsrcs...")
3055 (with-current-buffer (gnus-get-buffer-create " *gnus slave*")
3056 (setq slave-files
3057 (sort (mapcar (lambda (file)
3058 (list (nth 5 (file-attributes file)) file))
3059 slave-files)
3060 (lambda (f1 f2)
3061 (or (< (caar f1) (caar f2))
3062 (< (nth 1 (car f1)) (nth 1 (car f2)))))))
3063 (while slave-files
3064 (erase-buffer)
3065 (setq file (nth 1 (car slave-files)))
3066 (nnheader-insert-file-contents file)
3067 (when (condition-case ()
3068 (progn
3069 (eval-buffer (current-buffer))
3071 (error
3072 (gnus-error 3.2 "Possible error in %s" file)
3073 nil))
3074 (unless gnus-slave ; Slaves shouldn't delete these files.
3075 (ignore-errors
3076 (delete-file file))))
3077 (setq slave-files (cdr slave-files))))
3078 (gnus-dribble-touch)
3079 (gnus-message 7 "Reading slave newsrcs...done"))))
3083 ;;; Group description.
3086 (defun gnus-read-all-descriptions-files ()
3087 (let ((methods (cons gnus-select-method
3088 (nconc
3089 (when (gnus-archive-server-wanted-p)
3090 (list "archive"))
3091 gnus-secondary-select-methods))))
3092 (while methods
3093 (gnus-read-descriptions-file (car methods))
3094 (setq methods (cdr methods)))
3097 (defun gnus-read-descriptions-file (&optional method)
3098 (let ((method (or method gnus-select-method))
3099 group)
3100 (when (stringp method)
3101 (setq method (gnus-server-to-method method)))
3102 ;; We create the hashtable whether we manage to read the desc file
3103 ;; to avoid trying to re-read after a failed read.
3104 (unless gnus-description-hashtb
3105 (setq gnus-description-hashtb
3106 (gnus-make-hashtable (length gnus-active-hashtb))))
3107 ;; Mark this method's desc file as read.
3108 (gnus-sethash (gnus-group-prefixed-name "" method) "Has read"
3109 gnus-description-hashtb)
3111 (gnus-message 5 "Reading descriptions file via %s..." (car method))
3112 (cond
3113 ((null (gnus-get-function method 'request-list-newsgroups t))
3115 ((not (gnus-check-server method))
3116 (gnus-message 1 "Couldn't open server")
3117 nil)
3118 ((not (gnus-request-list-newsgroups method))
3119 (gnus-message 1 "Couldn't read newsgroups descriptions")
3120 nil)
3122 (save-excursion
3123 ;; FIXME: Shouldn't save-restriction be done after set-buffer?
3124 (save-restriction
3125 (set-buffer nntp-server-buffer)
3126 (goto-char (point-min))
3127 (when (or (search-forward "\n.\n" nil t)
3128 (goto-char (point-max)))
3129 (beginning-of-line)
3130 (narrow-to-region (point-min) (point)))
3131 ;; If these are groups from a foreign select method, we insert the
3132 ;; group prefix in front of the group names.
3133 (and method (not (inline
3134 (gnus-server-equal
3135 (gnus-server-get-method nil method)
3136 (gnus-server-get-method
3137 nil gnus-select-method))))
3138 (let ((prefix (gnus-group-prefixed-name "" method)))
3139 (goto-char (point-min))
3140 (while (and (not (eobp))
3141 (progn (insert prefix)
3142 (zerop (forward-line 1)))))))
3143 (goto-char (point-min))
3144 (while (not (eobp))
3145 ;; If we get an error, we set group to 0, which is not a
3146 ;; symbol...
3147 (setq group
3148 (condition-case ()
3149 (let ((obarray gnus-description-hashtb))
3150 ;; Group is set to a symbol interned in this
3151 ;; hash table.
3152 (read nntp-server-buffer))
3153 (error 0)))
3154 (skip-chars-forward " \t")
3155 ;; ... which leads to this line being effectively ignored.
3156 (when (symbolp group)
3157 (let* ((str (buffer-substring
3158 (point) (progn (end-of-line) (point))))
3159 (name (symbol-name group))
3160 (charset
3161 (or (gnus-group-name-charset method name)
3162 (gnus-parameter-charset name)
3163 gnus-default-charset)))
3164 ;; Fixme: Don't decode in unibyte mode.
3165 (when (and str charset)
3166 (setq str (decode-coding-string str charset)))
3167 (set group str)))
3168 (forward-line 1))))
3169 (gnus-message 5 "Reading descriptions file...done")
3170 t))))
3172 (defun gnus-group-get-description (group)
3173 "Get the description of a group by sending XGTITLE to the server."
3174 (when (gnus-request-group-description group)
3175 (with-current-buffer nntp-server-buffer
3176 (goto-char (point-min))
3177 (when (looking-at "[^ \t]+[ \t]+\\(.*\\)")
3178 (match-string 1)))))
3180 ;;;###autoload
3181 (defun gnus-declare-backend (name &rest abilities)
3182 "Declare back end NAME with ABILITIES as a Gnus back end."
3183 (setq gnus-valid-select-methods
3184 (nconc gnus-valid-select-methods
3185 (list (apply 'list name abilities))))
3186 (gnus-redefine-select-method-widget))
3188 (defun gnus-set-default-directory ()
3189 "Set the default directory in the current buffer to `gnus-default-directory'.
3190 If this variable is nil, don't do anything."
3191 (setq default-directory
3192 (if (and gnus-default-directory
3193 (file-exists-p gnus-default-directory))
3194 (file-name-as-directory (expand-file-name gnus-default-directory))
3195 default-directory)))
3197 (defun gnus-display-time-event-handler ()
3198 (if (and (fboundp 'display-time-event-handler)
3199 (gnus-boundp 'display-time-timer))
3200 (display-time-event-handler)))
3202 (defun gnus-check-reasonable-setup ()
3203 ;; Check whether nnml and nnfolder share a directory.
3204 (let (method active actives match)
3205 (dolist (server gnus-server-alist)
3206 (setq method (gnus-server-to-method server)
3207 active (intern (format "%s-active-file" (car method))))
3208 (when (and (member (car method) '(nnml nnfolder))
3209 (gnus-server-opened method)
3210 (boundp active))
3211 (when (setq match (assoc (symbol-value active) actives))
3212 (display-warning 'gnus-server
3213 (format "%s and %s share the same active file %s"
3214 (car method)
3215 (cadr match)
3216 (car match))))
3217 (push (list (symbol-value active) method) actives)))))
3219 (provide 'gnus-start)
3221 ;;; gnus-start.el ends here