2003-12-31 Jeremy Maitin-Shepard <jbms@attbi.com>
[gnus] / lisp / gnus-start.el
1 ;;; gnus-start.el --- startup functions for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news
7
8 ;; This file is part of GNU Emacs.
9
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 2, or (at your option)
13 ;; any later version.
14
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.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;;; Code:
28
29 (require 'gnus)
30 (require 'gnus-win)
31 (require 'gnus-int)
32 (require 'gnus-spec)
33 (require 'gnus-range)
34 (require 'gnus-util)
35 (autoload 'message-make-date "message")
36 (autoload 'gnus-agent-read-servers-validate "gnus-agent")
37 (autoload 'gnus-agent-possibly-alter-active "gnus-agent")
38 (eval-when-compile (require 'cl))
39
40 (defcustom gnus-startup-file (nnheader-concat gnus-home-directory ".newsrc")
41   "Your `.newsrc' file.
42 `.newsrc-SERVER' will be used instead if that exists."
43   :group 'gnus-start
44   :type 'file)
45
46 (defcustom gnus-backup-startup-file 'never
47   "Whether to create backup files.
48 This variable takes the same values as the `version-control'
49 variable."
50   :group 'gnus-start
51   :type '(choice (const :tag "Never" never)
52                  (const :tag "If existing" nil)
53                  (other :tag "Always" t)))
54
55 (defcustom gnus-save-startup-file-via-temp-buffer t
56   "Whether to write the startup file contents to a buffer then save
57 the buffer or write directly to the file.  The buffer is faster
58 because all of the contents are written at once.  The direct write
59 uses considerably less memory."
60   :group 'gnus-start
61   :type '(choice (const :tag "Write via buffer" t)
62                  (const :tag "Write directly to file" nil)))
63
64 (defcustom gnus-init-file (nnheader-concat gnus-home-directory ".gnus")
65   "Your Gnus Emacs-Lisp startup file name.
66 If a file with the `.el' or `.elc' suffixes exists, it will be read instead."
67   :group 'gnus-start
68   :type 'file)
69
70 (defcustom gnus-site-init-file
71   (condition-case nil
72       (concat (file-name-directory
73                (directory-file-name installation-directory))
74               "site-lisp/gnus-init")
75     (error nil))
76   "The site-wide Gnus Emacs-Lisp startup file name, or nil if none.
77 If a file with the `.el' or `.elc' suffixes exists, it will be read instead."
78   :group 'gnus-start
79   :type '(choice file (const nil)))
80
81 (defcustom gnus-default-subscribed-newsgroups nil
82   "List of newsgroups to subscribe, when a user runs Gnus the first time.
83 The value should be a list of strings.
84 If it is t, Gnus will not do anything special the first time it is
85 started; it'll just use the normal newsgroups subscription methods."
86   :group 'gnus-start
87   :type '(choice (repeat string) (const :tag "Nothing special" t)))
88
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)
95
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)))
102
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.
108
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. `gnus-read-active-file' is nil or `some'.
115   4. A prefix argument is given to `gnus-find-new-newsgroups' interactively.
116
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.
120
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.
124
125 Eg.
126   (setq gnus-check-new-newsgroups
127         '((nntp \"some.server\") (nntp \"other.server\")))
128
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"))))
139
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)
146
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.
151
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.
156
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)))
165
166 (defconst gnus-level-subscribed 5
167   "Groups with levels less than or equal to this variable are subscribed.")
168
169 (defconst gnus-level-unsubscribed 7
170   "Groups with levels less than or equal to this variable are unsubscribed.
171 Groups with levels less than `gnus-level-subscribed', which should be
172 less than this variable, are subscribed.")
173
174 (defconst gnus-level-zombie 8
175   "Groups with this level are zombie groups.")
176
177 (defconst gnus-level-killed 9
178   "Groups with this level are killed.")
179
180 (defcustom gnus-level-default-subscribed 3
181   "*New subscribed groups will be subscribed at this level."
182   :group 'gnus-group-levels
183   :type 'integer)
184
185 (defcustom gnus-level-default-unsubscribed 6
186   "*New unsubscribed groups will be unsubscribed at this level."
187   :group 'gnus-group-levels
188   :type 'integer)
189
190 (defcustom gnus-activate-level (1+ gnus-level-subscribed)
191   "*Groups higher than this level won't be activated on startup.
192 Setting this variable to something low might save lots of time when
193 you have many groups that you aren't interested in."
194   :group 'gnus-group-levels
195   :type 'integer)
196
197 (defcustom gnus-activate-foreign-newsgroups 4
198   "*If nil, Gnus will not check foreign newsgroups at startup.
199 If it is non-nil, it should be a number between one and nine.  Foreign
200 newsgroups that have a level lower or equal to this number will be
201 activated on startup.  For instance, if you want to active all
202 subscribed newsgroups, but not the rest, you'd set this variable to
203 `gnus-level-subscribed'.
204
205 If you subscribe to lots of newsgroups from different servers, startup
206 might take a while.  By setting this variable to nil, you'll save time,
207 but you won't be told how many unread articles there are in the
208 groups."
209   :group 'gnus-group-levels
210   :type '(choice integer
211                  (const :tag "none" nil)))
212
213 (defcustom gnus-read-newsrc-file t
214   "*Non-nil means that Gnus will read the `.newsrc' file.
215 Gnus always reads its own startup file, which is called
216 \".newsrc.eld\".  The file called \".newsrc\" is in a format that can
217 be readily understood by other newsreaders.  If you don't plan on
218 using other newsreaders, set this variable to nil to save some time on
219 entry."
220   :version "21.1"
221   :group 'gnus-newsrc
222   :type 'boolean)
223
224 (defcustom gnus-save-newsrc-file t
225   "*Non-nil means that Gnus will save the `.newsrc' file.
226 Gnus always saves its own startup file, which is called
227 \".newsrc.eld\".  The file called \".newsrc\" is in a format that can
228 be readily understood by other newsreaders.  If you don't plan on
229 using other newsreaders, set this variable to nil to save some time on
230 exit."
231   :group 'gnus-newsrc
232   :type 'boolean)
233
234 (defcustom gnus-save-killed-list t
235   "*If non-nil, save the list of killed groups to the startup file.
236 If you set this variable to nil, you'll save both time (when starting
237 and quitting) and space (both memory and disk), but it will also mean
238 that Gnus has no record of which groups are new and which are old, so
239 the automatic new newsgroups subscription methods become meaningless.
240
241 You should always set `gnus-check-new-newsgroups' to `ask-server' or
242 nil if you set this variable to nil.
243
244 This variable can also be a regexp.  In that case, all groups that do
245 not match this regexp will be removed before saving the list."
246   :group 'gnus-newsrc
247   :type '(radio (sexp :format "Non-nil\n"
248                       :match (lambda (widget value)
249                                (and value (not (stringp value))))
250                       :value t)
251                 (const nil)
252                 (regexp :format "%t: %v\n" :size 0)))
253
254 (defcustom gnus-ignored-newsgroups
255   (mapconcat 'identity
256              '("^to\\."                 ; not "real" groups
257                "^[0-9. \t]+\\( \\|$\\)" ; all digits in name
258                "^[\"][]\"[#'()]"        ; bogus characters
259                )
260              "\\|")
261   "*A regexp to match uninteresting newsgroups in the active file.
262 Any lines in the active file matching this regular expression are
263 removed from the newsgroup list before anything else is done to it,
264 thus making them effectively non-existent."
265   :group 'gnus-group-new
266   :type 'regexp)
267
268 (defcustom gnus-subscribe-newsgroup-method 'gnus-subscribe-zombies
269   "*Function(s) called with a group name when new group is detected.
270 A few pre-made functions are supplied: `gnus-subscribe-randomly'
271 inserts new groups at the beginning of the list of groups;
272 `gnus-subscribe-alphabetically' inserts new groups in strict
273 alphabetic order; `gnus-subscribe-hierarchically' inserts new groups
274 in hierarchical newsgroup order; `gnus-subscribe-interactively' asks
275 for your decision; `gnus-subscribe-killed' kills all new groups;
276 `gnus-subscribe-zombies' will make all new groups into zombies;
277 `gnus-subscribe-topics' will enter groups into the topics that
278 claim them."
279   :group 'gnus-group-new
280   :type '(radio (function-item gnus-subscribe-randomly)
281                 (function-item gnus-subscribe-alphabetically)
282                 (function-item gnus-subscribe-hierarchically)
283                 (function-item gnus-subscribe-interactively)
284                 (function-item gnus-subscribe-killed)
285                 (function-item gnus-subscribe-zombies)
286                 (function-item gnus-subscribe-topics)
287                 function
288                 (repeat function)))
289
290 (defcustom gnus-subscribe-newsgroup-hooks nil
291   "*Hooks run after you subscribe to a new group.
292 The hooks will be called with new group's name as argument."
293   :group 'gnus-group-new
294   :type 'hook)
295
296 (defcustom gnus-subscribe-options-newsgroup-method
297   'gnus-subscribe-alphabetically
298   "*Function(s) called to subscribe newsgroups mentioned on \"options -n\" lines.
299 If, for instance, you want to subscribe to all newsgroups in the
300 \"no\" and \"alt\" hierarchies, you'd put the following in your
301 .newsrc file:
302
303 options -n no.all alt.all
304
305 Gnus will the subscribe all new newsgroups in these hierarchies with
306 the subscription method in this variable."
307   :group 'gnus-group-new
308   :type '(radio (function-item gnus-subscribe-randomly)
309                 (function-item gnus-subscribe-alphabetically)
310                 (function-item gnus-subscribe-hierarchically)
311                 (function-item gnus-subscribe-interactively)
312                 (function-item gnus-subscribe-killed)
313                 (function-item gnus-subscribe-zombies)
314                 (function-item gnus-subscribe-topics)
315                 function
316                 (repeat function)))
317
318 (defcustom gnus-subscribe-hierarchical-interactive nil
319   "*If non-nil, Gnus will offer to subscribe hierarchically.
320 When a new hierarchy appears, Gnus will ask the user:
321
322 'alt.binaries': Do you want to subscribe to this hierarchy? ([d]ys):
323
324 If the user pressed `d', Gnus will descend the hierarchy, `y' will
325 subscribe to all newsgroups in the hierarchy and `s' will skip this
326 hierarchy in its entirety."
327   :group 'gnus-group-new
328   :type 'boolean)
329
330 (defcustom gnus-auto-subscribed-groups
331   "^nnml\\|^nnfolder\\|^nnmbox\\|^nnmh\\|^nnbabyl\\|^nnmaildir"
332   "*All new groups that match this regexp will be subscribed automatically.
333 Note that this variable only deals with new groups.  It has no effect
334 whatsoever on old groups.
335
336 New groups that match this regexp will not be handled by
337 `gnus-subscribe-newsgroup-method'.  Instead, they will
338 be subscribed using `gnus-subscribe-options-newsgroup-method'."
339   :group 'gnus-group-new
340   :type 'regexp)
341
342 (defcustom gnus-options-subscribe nil
343   "*All new groups matching this regexp will be subscribed unconditionally.
344 Note that this variable deals only with new newsgroups.  This variable
345 does not affect old newsgroups.
346
347 New groups that match this regexp will not be handled by
348 `gnus-subscribe-newsgroup-method'.  Instead, they will
349 be subscribed using `gnus-subscribe-options-newsgroup-method'."
350   :group 'gnus-group-new
351   :type '(choice regexp
352                  (const :tag "none" nil)))
353
354 (defcustom gnus-options-not-subscribe nil
355   "*All new groups matching this regexp will be ignored.
356 Note that this variable deals only with new newsgroups.  This variable
357 does not affect old (already subscribed) newsgroups."
358   :group 'gnus-group-new
359   :type '(choice regexp
360                  (const :tag "none" nil)))
361
362 (defcustom gnus-modtime-botch nil
363   "*Non-nil means .newsrc should be deleted prior to save.
364 Its use is due to the bogus appearance that .newsrc was modified on
365 disc."
366   :group 'gnus-newsrc
367   :type 'boolean)
368
369 (defcustom gnus-check-bogus-groups-hook nil
370   "A hook run after removing bogus groups."
371   :group 'gnus-start-server
372   :type 'hook)
373
374 (defcustom gnus-startup-hook nil
375   "A hook called at startup.
376 This hook is called after Gnus is connected to the NNTP server."
377   :group 'gnus-start
378   :type 'hook)
379
380 (defcustom gnus-before-startup-hook nil
381   "A hook called at before startup.
382 This hook is called as the first thing when Gnus is started."
383   :group 'gnus-start
384   :type 'hook)
385
386 (defcustom gnus-started-hook nil
387   "A hook called as the last thing after startup."
388   :group 'gnus-start
389   :type 'hook)
390
391 (defcustom gnus-setup-news-hook
392   '(gnus-fixup-nnimap-unread-after-getting-new-news)
393   "A hook after reading the .newsrc file, but before generating the buffer."
394   :group 'gnus-start
395   :type 'hook)
396
397 (defcustom gnus-get-top-new-news-hook nil
398   "A hook run just before Gnus checks for new news globally."
399   :group 'gnus-group-new
400   :type 'hook)
401
402 (defcustom gnus-get-new-news-hook nil
403   "A hook run just before Gnus checks for new news."
404   :group 'gnus-group-new
405   :type 'hook)
406
407 (defcustom gnus-after-getting-new-news-hook
408   '(gnus-display-time-event-handler
409     gnus-fixup-nnimap-unread-after-getting-new-news)
410   "*A hook run after Gnus checks for new news when Gnus is already running."
411   :group 'gnus-group-new
412   :type 'hook)
413
414 (defcustom gnus-read-newsrc-el-hook nil
415   "A hook called after reading the newsrc.eld? file."
416   :group 'gnus-newsrc
417   :type 'hook)
418
419 (defcustom gnus-save-newsrc-hook nil
420   "A hook called before saving any of the newsrc files."
421   :group 'gnus-newsrc
422   :type 'hook)
423
424 (defcustom gnus-save-quick-newsrc-hook nil
425   "A hook called just before saving the quick newsrc file.
426 Can be used to turn version control on or off."
427   :group 'gnus-newsrc
428   :type 'hook)
429
430 (defcustom gnus-save-standard-newsrc-hook nil
431   "A hook called just before saving the standard newsrc file.
432 Can be used to turn version control on or off."
433   :group 'gnus-newsrc
434   :type 'hook)
435
436 (defcustom gnus-group-mode-hook nil
437   "Hook for Gnus group mode."
438   :group 'gnus-group-various
439   :options '(gnus-topic-mode)
440   :type 'hook)
441
442 (defcustom gnus-always-read-dribble-file nil
443   "Unconditionally read the dribble file."
444   :group 'gnus-newsrc
445   :type 'boolean)
446
447 ;;; Internal variables
448
449 (defvar gnus-ding-file-coding-system mm-universal-coding-system
450   "Coding system for ding file.")
451
452 (defvar gnus-newsrc-file-version nil)
453 (defvar gnus-override-subscribe-method nil)
454 (defvar gnus-dribble-buffer nil)
455 (defvar gnus-newsrc-options nil
456   "Options line in the .newsrc file.")
457
458 (defvar gnus-newsrc-options-n nil
459   "List of regexps representing groups to be subscribed/ignored unconditionally.")
460
461 (defvar gnus-newsrc-last-checked-date nil
462   "Date Gnus last asked server for new newsgroups.")
463
464 (defvar gnus-current-startup-file nil
465   "Startup file for the current host.")
466
467 ;; Byte-compiler warning.
468 (defvar gnus-group-line-format)
469
470 ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
471 (defvar gnus-init-inhibit nil)
472 (defun gnus-read-init-file (&optional inhibit-next)
473   ;; Don't load .gnus if the -q option was used.
474   (when init-file-user
475     (if gnus-init-inhibit
476         (setq gnus-init-inhibit nil)
477       (setq gnus-init-inhibit inhibit-next)
478       (dolist (file (list gnus-site-init-file gnus-init-file))
479         (when (and file
480                    (locate-library file))
481           (if (or debug-on-error debug-on-quit)
482               (load file nil t)
483             (condition-case var
484                 (load file nil t)
485               (error
486                (error "Error in %s: %s" file (cadr var))))))))))
487
488 ;; For subscribing new newsgroup
489
490 (defun gnus-subscribe-hierarchical-interactive (groups)
491   (let ((groups (sort groups 'string<))
492         prefixes prefix start ans group starts)
493     (while groups
494       (setq prefixes (list "^"))
495       (while (and groups prefixes)
496         (while (not (string-match (car prefixes) (car groups)))
497           (setq prefixes (cdr prefixes)))
498         (setq prefix (car prefixes))
499         (setq start (1- (length prefix)))
500         (if (and (string-match "[^\\.]\\." (car groups) start)
501                  (cdr groups)
502                  (setq prefix
503                        (concat "^" (substring (car groups) 0 (match-end 0))))
504                  (string-match prefix (cadr groups)))
505             (progn
506               (push prefix prefixes)
507               (message "Descend hierarchy %s? ([y]nsq): "
508                        (substring prefix 1 (1- (length prefix))))
509               (while (not (memq (setq ans (read-char-exclusive))
510                                 '(?y ?\n ?\r ?n ?s ?q)))
511                 (ding)
512                 (message "Descend hierarchy %s? ([y]nsq): "
513                          (substring prefix 1 (1- (length prefix)))))
514               (cond ((= ans ?n)
515                      (while (and groups
516                                  (string-match prefix
517                                                (setq group (car groups))))
518                        (push group gnus-killed-list)
519                        (gnus-sethash group group gnus-killed-hashtb)
520                        (setq groups (cdr groups)))
521                      (setq starts (cdr starts)))
522                     ((= ans ?s)
523                      (while (and groups
524                                  (string-match prefix
525                                                (setq group (car groups))))
526                        (gnus-sethash group group gnus-killed-hashtb)
527                        (gnus-subscribe-alphabetically (car groups))
528                        (setq groups (cdr groups)))
529                      (setq starts (cdr starts)))
530                     ((= ans ?q)
531                      (while groups
532                        (setq group (car groups))
533                        (push group gnus-killed-list)
534                        (gnus-sethash group group gnus-killed-hashtb)
535                        (setq groups (cdr groups))))
536                     (t nil)))
537           (message "Subscribe %s? ([n]yq)" (car groups))
538           (while (not (memq (setq ans (read-char-exclusive))
539                             '(?y ?\n ?\r ?q ?n)))
540             (ding)
541             (message "Subscribe %s? ([n]yq)" (car groups)))
542           (setq group (car groups))
543           (cond ((= ans ?y)
544                  (gnus-subscribe-alphabetically (car groups))
545                  (gnus-sethash group group gnus-killed-hashtb))
546                 ((= ans ?q)
547                  (while groups
548                    (setq group (car groups))
549                    (push group gnus-killed-list)
550                    (gnus-sethash group group gnus-killed-hashtb)
551                    (setq groups (cdr groups))))
552                 (t
553                  (push group gnus-killed-list)
554                  (gnus-sethash group group gnus-killed-hashtb)))
555           (setq groups (cdr groups)))))))
556
557 (defun gnus-subscribe-randomly (newsgroup)
558   "Subscribe new NEWSGROUP by making it the first newsgroup."
559   (gnus-subscribe-newsgroup newsgroup))
560
561 (defun gnus-subscribe-alphabetically (newgroup)
562   "Subscribe new NEWGROUP and insert it in alphabetical order."
563   (let ((groups (cdr gnus-newsrc-alist))
564         before)
565     (while (and (not before) groups)
566       (if (string< newgroup (caar groups))
567           (setq before (caar groups))
568         (setq groups (cdr groups))))
569     (gnus-subscribe-newsgroup newgroup before)))
570
571 (defun gnus-subscribe-hierarchically (newgroup)
572   "Subscribe new NEWGROUP and insert it in hierarchical newsgroup order."
573   ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
574   (save-excursion
575     (set-buffer (nnheader-find-file-noselect gnus-current-startup-file))
576     (prog1
577         (let ((groupkey newgroup) before)
578           (while (and (not before) groupkey)
579             (goto-char (point-min))
580             (let ((groupkey-re
581                    (concat "^\\(" (regexp-quote groupkey) ".*\\)[!:]")))
582               (while (and (re-search-forward groupkey-re nil t)
583                           (progn
584                             (setq before (match-string 1))
585                             (string< before newgroup)))))
586             ;; Remove tail of newsgroup name (eg. a.b.c -> a.b)
587             (setq groupkey
588                   (when (string-match "^\\(.*\\)\\.[^.]+$" groupkey)
589                     (substring groupkey (match-beginning 1) (match-end 1)))))
590           (gnus-subscribe-newsgroup newgroup before))
591       (kill-buffer (current-buffer)))))
592
593 (defun gnus-subscribe-interactively (group)
594   "Subscribe the new GROUP interactively.
595 It is inserted in hierarchical newsgroup order if subscribed.  If not,
596 it is killed."
597   (if (gnus-y-or-n-p (format "Subscribe new newsgroup: %s " group))
598       (gnus-subscribe-hierarchically group)
599     (push group gnus-killed-list)))
600
601 (defun gnus-subscribe-zombies (group)
602   "Make the new GROUP into a zombie group."
603   (push group gnus-zombie-list))
604
605 (defun gnus-subscribe-killed (group)
606   "Make the new GROUP a killed group."
607   (push group gnus-killed-list))
608
609 (defun gnus-subscribe-newsgroup (newsgroup &optional next)
610   "Subscribe new NEWSGROUP.
611 If NEXT is non-nil, it is inserted before NEXT.  Otherwise it is made
612 the first newsgroup."
613   (save-excursion
614     (goto-char (point-min))
615     ;; We subscribe the group by changing its level to `subscribed'.
616     (gnus-group-change-level
617      newsgroup gnus-level-default-subscribed
618      gnus-level-killed (gnus-gethash (or next "dummy.group")
619                                      gnus-newsrc-hashtb))
620     (gnus-message 5 "Subscribe newsgroup: %s" newsgroup)
621     (run-hook-with-args 'gnus-subscribe-newsgroup-hooks newsgroup)
622     t))
623
624 (defun gnus-read-active-file-p ()
625   "Say whether the active file has been read from `gnus-select-method'."
626   (memq gnus-select-method gnus-have-read-active-file))
627
628 ;;; General various misc type functions.
629
630 ;; Silence byte-compiler.
631 (eval-when-compile
632   (defvar gnus-current-headers)
633   (defvar gnus-thread-indent-array)
634   (defvar gnus-newsgroup-name)
635   (defvar gnus-newsgroup-headers)
636   (defvar gnus-group-list-mode)
637   (defvar gnus-group-mark-positions)
638   (defvar gnus-newsgroup-data)
639   (defvar gnus-newsgroup-unreads)
640   (defvar nnoo-state-alist)
641   (defvar gnus-current-select-method)
642   (defvar mail-sources)
643   (defvar nnmail-scan-directory-mail-source-once)
644   (defvar nnmail-split-history)
645   (defvar nnmail-spool-file))
646
647 (defun gnus-close-all-servers ()
648   "Close all servers."
649   (interactive)
650   (dolist (server gnus-opened-servers)
651     (gnus-close-server (car server))))
652
653 (defun gnus-clear-system ()
654   "Clear all variables and buffers."
655   ;; Clear Gnus variables.
656   (let ((variables (remove 'gnus-format-specs gnus-variable-list)))
657     (while variables
658       (set (car variables) nil)
659       (setq variables (cdr variables))))
660   ;; Clear other internal variables.
661   (setq gnus-list-of-killed-groups nil
662         gnus-have-read-active-file nil
663         gnus-agent-covered-methods nil
664         gnus-server-method-cache nil
665         gnus-newsrc-alist nil
666         gnus-newsrc-hashtb nil
667         gnus-killed-list nil
668         gnus-zombie-list nil
669         gnus-killed-hashtb nil
670         gnus-active-hashtb nil
671         gnus-moderated-hashtb nil
672         gnus-description-hashtb nil
673         gnus-current-headers nil
674         gnus-thread-indent-array nil
675         gnus-newsgroup-headers nil
676         gnus-newsgroup-name nil
677         gnus-server-alist nil
678         gnus-group-list-mode nil
679         gnus-opened-servers nil
680         gnus-group-mark-positions nil
681         gnus-newsgroup-data nil
682         gnus-newsgroup-unreads nil
683         nnoo-state-alist nil
684         gnus-current-select-method nil
685         nnmail-split-history nil
686         gnus-ephemeral-servers nil)
687   (gnus-shutdown 'gnus)
688   ;; Kill the startup file.
689   (and gnus-current-startup-file
690        (get-file-buffer gnus-current-startup-file)
691        (kill-buffer (get-file-buffer gnus-current-startup-file)))
692   ;; Clear the dribble buffer.
693   (gnus-dribble-clear)
694   ;; Kill global KILL file buffer.
695   (when (get-file-buffer (gnus-newsgroup-kill-file nil))
696     (kill-buffer (get-file-buffer (gnus-newsgroup-kill-file nil))))
697   (gnus-kill-buffer nntp-server-buffer)
698   ;; Kill Gnus buffers.
699   (dolist (buffer (gnus-buffers))
700     (gnus-kill-buffer buffer))
701   ;; Remove Gnus frames.
702   (gnus-kill-gnus-frames))
703
704 (defun gnus-no-server-1 (&optional arg slave)
705   "Read network news.
706 If ARG is a positive number, Gnus will use that as the
707 startup level.  If ARG is nil, Gnus will be started at level 2.
708 If ARG is non-nil and not a positive number, Gnus will
709 prompt the user for the name of an NNTP server to use.
710 As opposed to `gnus', this command will not connect to the local server."
711   (interactive "P")
712   (let ((val (or arg (1- gnus-level-default-subscribed))))
713     (gnus val t slave)
714     (make-local-variable 'gnus-group-use-permanent-levels)
715     (setq gnus-group-use-permanent-levels val)))
716
717 (defun gnus-1 (&optional arg dont-connect slave)
718   "Read network news.
719 If ARG is non-nil and a positive number, Gnus will use that as the
720 startup level.  If ARG is non-nil and not a positive number, Gnus will
721 prompt the user for the name of an NNTP server to use."
722   (interactive "P")
723
724   (if (gnus-alive-p)
725       (progn
726         (switch-to-buffer gnus-group-buffer)
727         (gnus-group-get-new-news
728          (and (numberp arg)
729               (> arg 0)
730               (max (car gnus-group-list-mode) arg))))
731
732     (gnus-clear-system)
733     (gnus-splash)
734     (gnus-run-hooks 'gnus-before-startup-hook)
735     (nnheader-init-server-buffer)
736     (setq gnus-slave slave)
737     (gnus-read-init-file)
738     (if gnus-agent
739         (gnus-agentize))
740
741     (when gnus-simple-splash
742       (setq gnus-simple-splash nil)
743       (cond
744        ((featurep 'xemacs)
745         (gnus-xmas-splash))
746        ((and window-system
747              (= (frame-height) (1+ (window-height))))
748         (gnus-x-splash))))
749
750     (let ((level (and (numberp arg) (> arg 0) arg))
751           did-connect)
752       (unwind-protect
753           (progn
754             (unless dont-connect
755               (setq did-connect
756                     (gnus-start-news-server (and arg (not level))))))
757         (if (and (not dont-connect)
758                  (not did-connect))
759             (gnus-group-quit)
760           (gnus-run-hooks 'gnus-startup-hook)
761           ;; NNTP server is successfully open.
762
763           ;; Find the current startup file name.
764           (setq gnus-current-startup-file
765                 (gnus-make-newsrc-file gnus-startup-file))
766
767           ;; Read the dribble file.
768           (when (or gnus-slave gnus-use-dribble-file)
769             (gnus-dribble-read-file))
770
771           ;; Allow using GroupLens predictions.
772           (when gnus-use-grouplens
773             (bbb-login)
774             (add-hook 'gnus-summary-mode-hook 'gnus-grouplens-mode))
775
776           ;; Do the actual startup.
777           (if gnus-agent
778               (gnus-request-create-group "queue" '(nndraft "")))
779           (gnus-request-create-group "drafts" '(nndraft ""))
780           (gnus-setup-news nil level dont-connect)
781           (gnus-run-hooks 'gnus-setup-news-hook)
782           (gnus-start-draft-setup)
783           ;; Generate the group buffer.
784           (gnus-group-list-groups level)
785           (gnus-group-first-unread-group)
786           (gnus-configure-windows 'group)
787           (gnus-group-set-mode-line)
788           (gnus-run-hooks 'gnus-started-hook))))))
789
790 (defun gnus-start-draft-setup ()
791   "Make sure the draft group exists."
792   (gnus-request-create-group "drafts" '(nndraft ""))
793   (unless (gnus-gethash "nndraft:drafts" gnus-newsrc-hashtb)
794     (let ((gnus-level-default-subscribed 1))
795       (gnus-subscribe-group "nndraft:drafts" nil '(nndraft "")))
796     (gnus-group-set-parameter
797      "nndraft:drafts" 'gnus-dummy '((gnus-draft-mode)))))
798
799 \f
800 ;;;
801 ;;; Dribble file
802 ;;;
803
804 (defvar gnus-dribble-ignore nil)
805 (defvar gnus-dribble-eval-file nil)
806
807 (defun gnus-dribble-file-name ()
808   "Return the dribble file for the current .newsrc."
809   (concat
810    (if gnus-dribble-directory
811        (concat (file-name-as-directory gnus-dribble-directory)
812                (file-name-nondirectory gnus-current-startup-file))
813      gnus-current-startup-file)
814    "-dribble"))
815
816 (defun gnus-dribble-enter (string)
817   "Enter STRING into the dribble buffer."
818   (when (and (not gnus-dribble-ignore)
819              gnus-dribble-buffer
820              (buffer-name gnus-dribble-buffer))
821     (let ((obuf (current-buffer)))
822       (set-buffer gnus-dribble-buffer)
823       (goto-char (point-max))
824       (insert string "\n")
825       ;; This has been commented by Josh Huber <huber@alum.wpi.edu>
826       ;; It causes problems with both XEmacs and Emacs 21, and doesn't
827       ;; seem to be of much value. (FIXME: remove this after we make sure
828       ;; it's not needed).
829       ;; (set-window-point (get-buffer-window (current-buffer)) (point-max))
830       (bury-buffer gnus-dribble-buffer)
831       (save-excursion
832         (set-buffer gnus-group-buffer)
833         (gnus-group-set-mode-line))
834       (set-buffer obuf))))
835
836 (defun gnus-dribble-touch ()
837   "Touch the dribble buffer."
838   (gnus-dribble-enter ""))
839
840 (defun gnus-dribble-read-file ()
841   "Read the dribble file from disk."
842   (let ((dribble-file (gnus-dribble-file-name)))
843     (save-excursion
844       (set-buffer (setq gnus-dribble-buffer
845                         (gnus-get-buffer-create
846                          (file-name-nondirectory dribble-file))))
847       (erase-buffer)
848       (setq buffer-file-name dribble-file)
849       (auto-save-mode t)
850       (buffer-disable-undo)
851       (bury-buffer (current-buffer))
852       (set-buffer-modified-p nil)
853       (let ((auto (make-auto-save-file-name))
854             (gnus-dribble-ignore t)
855             (purpose nil)
856             modes)
857         (when (or (file-exists-p auto) (file-exists-p dribble-file))
858           ;; Load whichever file is newest -- the auto save file
859           ;; or the "real" file.
860           (if (file-newer-than-file-p auto dribble-file)
861               (nnheader-insert-file-contents auto)
862             (nnheader-insert-file-contents dribble-file))
863           (unless (zerop (buffer-size))
864             (set-buffer-modified-p t))
865           ;; Set the file modes to reflect the .newsrc file modes.
866           (save-buffer)
867           (when (and (file-exists-p gnus-current-startup-file)
868                      (file-exists-p dribble-file)
869                      (setq modes (file-modes gnus-current-startup-file)))
870             (set-file-modes dribble-file modes))
871           (goto-char (point-min))
872           (when (search-forward "Gnus was exited on purpose" nil t)
873             (setq purpose t))
874           ;; Possibly eval the file later.
875           (when (or gnus-always-read-dribble-file
876                     (gnus-y-or-n-p
877                      (if purpose
878                          "Gnus exited on purpose without saving; read auto-save file anyway? "
879                      "Gnus auto-save file exists.  Do you want to read it? ")))
880             (setq gnus-dribble-eval-file t)))))))
881
882 (defun gnus-dribble-eval-file ()
883   (when gnus-dribble-eval-file
884     (setq gnus-dribble-eval-file nil)
885     (save-excursion
886       (let ((gnus-dribble-ignore t))
887         (set-buffer gnus-dribble-buffer)
888         (eval-buffer (current-buffer))))))
889
890 (defun gnus-dribble-delete-file ()
891   (when (file-exists-p (gnus-dribble-file-name))
892     (delete-file (gnus-dribble-file-name)))
893   (when gnus-dribble-buffer
894     (save-excursion
895       (set-buffer gnus-dribble-buffer)
896       (let ((auto (make-auto-save-file-name)))
897         (when (file-exists-p auto)
898           (delete-file auto))
899         (erase-buffer)
900         (set-buffer-modified-p nil)))))
901
902 (defun gnus-dribble-save ()
903   (when (and gnus-dribble-buffer
904              (buffer-name gnus-dribble-buffer))
905     (save-excursion
906       (set-buffer gnus-dribble-buffer)
907       (save-buffer))))
908
909 (defun gnus-dribble-clear ()
910   (when (gnus-buffer-exists-p gnus-dribble-buffer)
911     (save-excursion
912       (set-buffer gnus-dribble-buffer)
913       (erase-buffer)
914       (set-buffer-modified-p nil)
915       (setq buffer-saved-size (buffer-size)))))
916
917 \f
918 ;;;
919 ;;; Active & Newsrc File Handling
920 ;;;
921
922 (defun gnus-setup-news (&optional rawfile level dont-connect)
923   "Setup news information.
924 If RAWFILE is non-nil, the .newsrc file will also be read.
925 If LEVEL is non-nil, the news will be set up at level LEVEL."
926   (require 'nnmail)
927   (let ((init (not (and gnus-newsrc-alist gnus-active-hashtb (not rawfile))))
928         ;; Binding this variable will inhibit multiple fetchings
929         ;; of the same mail source.
930         (nnmail-fetched-sources (list t)))
931
932     (when init
933       ;; Clear some variables to re-initialize news information.
934       (setq gnus-newsrc-alist nil
935             gnus-active-hashtb nil)
936       ;; Read the newsrc file and create `gnus-newsrc-hashtb'.
937       (gnus-read-newsrc-file rawfile))
938
939     ;; Make sure the archive server is available to all and sundry.
940     (when gnus-message-archive-method
941       (unless (assoc "archive" gnus-server-alist)
942         (push `("archive"
943                 nnfolder
944                 "archive"
945                 (nnfolder-directory
946                  ,(nnheader-concat message-directory "archive"))
947                 (nnfolder-active-file
948                  ,(nnheader-concat message-directory "archive/active"))
949                 (nnfolder-get-new-mail nil)
950                 (nnfolder-inhibit-expiry t))
951               gnus-server-alist)))
952
953     ;; If we don't read the complete active file, we fill in the
954     ;; hashtb here.
955     (when (or (null gnus-read-active-file)
956               (eq gnus-read-active-file 'some))
957       (gnus-update-active-hashtb-from-killed))
958
959     ;; Validate agent covered methods now that gnus-server-alist has
960     ;; been initialized.
961     ;; NOTE: This is here for one purpose only.  By validating the
962     ;; agentized server's, it converts the old 5.10.3, and earlier,
963     ;; format to the current format.  That enables the agent code
964     ;; within gnus-read-active-file to function correctly.
965     (if gnus-agent
966         (gnus-agent-read-servers-validate))
967
968     ;; Read the active file and create `gnus-active-hashtb'.
969     ;; If `gnus-read-active-file' is nil, then we just create an empty
970     ;; hash table.  The partial filling out of the hash table will be
971     ;; done in `gnus-get-unread-articles'.
972     (and gnus-read-active-file
973          (not level)
974          (gnus-read-active-file nil dont-connect))
975
976     (unless gnus-active-hashtb
977       (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
978
979     ;; Initialize the cache.
980     (when gnus-use-cache
981       (gnus-cache-open))
982
983     ;; Possibly eval the dribble file.
984     (and init
985          (or gnus-use-dribble-file gnus-slave)
986          (gnus-dribble-eval-file))
987
988     ;; Slave Gnusii should then clear the dribble buffer.
989     (when (and init gnus-slave)
990       (gnus-dribble-clear))
991
992     (gnus-update-format-specifications)
993
994     ;; See whether we need to read the description file.
995     (when (and (boundp 'gnus-group-line-format)
996                (stringp gnus-group-line-format)
997                (let ((case-fold-search nil))
998                  (string-match "%[-,0-9]*D" gnus-group-line-format))
999                (not gnus-description-hashtb)
1000                (not dont-connect)
1001                gnus-read-active-file)
1002       (gnus-read-all-descriptions-files))
1003
1004     ;; Find new newsgroups and treat them.
1005     (when (and init gnus-check-new-newsgroups (not level)
1006                (gnus-check-server gnus-select-method)
1007                (not gnus-slave)
1008                gnus-plugged)
1009       (gnus-find-new-newsgroups))
1010
1011     ;; Check and remove bogus newsgroups.
1012     (when (and init gnus-check-bogus-newsgroups
1013                gnus-read-active-file (not level)
1014                (gnus-server-opened gnus-select-method))
1015       (gnus-check-bogus-newsgroups))
1016
1017     ;; We might read in new NoCeM messages here.
1018     (when (and gnus-use-nocem
1019                (not level)
1020                (not dont-connect))
1021       (gnus-nocem-scan-groups))
1022
1023     ;; Read any slave files.
1024     (gnus-master-read-slave-newsrc)
1025
1026     ;; Find the number of unread articles in each non-dead group.
1027     (let ((gnus-read-active-file (and (not level) gnus-read-active-file)))
1028       (gnus-get-unread-articles level))))
1029
1030 (defun gnus-call-subscribe-functions (method group)
1031   "Call METHOD to subscribe GROUP.
1032 If no function returns `non-nil', call `gnus-subscribe-zombies'."
1033   (unless (cond
1034            ((functionp method)
1035             (funcall method group))
1036            ((listp method)
1037             (catch 'found
1038               (dolist (func method)
1039                 (if (funcall func group)
1040                     (throw 'found t)))
1041               nil))
1042            (t nil))
1043     (gnus-subscribe-zombies group)))
1044
1045 (defun gnus-find-new-newsgroups (&optional arg)
1046   "Search for new newsgroups and add them.
1047 Each new newsgroup will be treated with `gnus-subscribe-newsgroup-method'.
1048 The `-n' option line from .newsrc is respected.
1049
1050 With 1 C-u, use the `ask-server' method to query the server for new
1051 groups.
1052 With 2 C-u's, use most complete method possible to query the server
1053 for new groups, and subscribe the new groups as zombies."
1054   (interactive "p")
1055   (let* ((gnus-subscribe-newsgroup-method
1056           gnus-subscribe-newsgroup-method)
1057          (check (cond
1058                  ((or (and (= (or arg 1) 4)
1059                            (not (listp gnus-check-new-newsgroups)))
1060                       (null gnus-read-active-file)
1061                       (eq gnus-read-active-file 'some))
1062                   'ask-server)
1063                  ((= (or arg 1) 16)
1064                   (setq gnus-subscribe-newsgroup-method
1065                         'gnus-subscribe-zombies)
1066                   t)
1067                  (t gnus-check-new-newsgroups))))
1068     (unless (gnus-check-first-time-used)
1069       (if (or (consp check)
1070               (eq check 'ask-server))
1071           ;; Ask the server for new groups.
1072           (gnus-ask-server-for-new-groups)
1073         ;; Go through the active hashtb and look for new groups.
1074         (let ((groups 0)
1075               group new-newsgroups)
1076           (gnus-message 5 "Looking for new newsgroups...")
1077           (unless gnus-have-read-active-file
1078             (gnus-read-active-file))
1079           (setq gnus-newsrc-last-checked-date (message-make-date))
1080           (unless gnus-killed-hashtb
1081             (gnus-make-hashtable-from-killed))
1082           ;; Go though every newsgroup in `gnus-active-hashtb' and compare
1083           ;; with `gnus-newsrc-hashtb' and `gnus-killed-hashtb'.
1084           (mapatoms
1085            (lambda (sym)
1086              (if (or (null (setq group (symbol-name sym)))
1087                      (not (boundp sym))
1088                      (null (symbol-value sym))
1089                      (gnus-gethash group gnus-killed-hashtb)
1090                      (gnus-gethash group gnus-newsrc-hashtb))
1091                  ()
1092                (let ((do-sub (gnus-matches-options-n group)))
1093                  (cond
1094                   ((eq do-sub 'subscribe)
1095                    (setq groups (1+ groups))
1096                    (gnus-sethash group group gnus-killed-hashtb)
1097                    (gnus-call-subscribe-functions
1098                     gnus-subscribe-options-newsgroup-method group))
1099                   ((eq do-sub 'ignore)
1100                    nil)
1101                   (t
1102                    (setq groups (1+ groups))
1103                    (gnus-sethash group group gnus-killed-hashtb)
1104                    (if gnus-subscribe-hierarchical-interactive
1105                        (push group new-newsgroups)
1106                      (gnus-call-subscribe-functions
1107                       gnus-subscribe-newsgroup-method group)))))))
1108            gnus-active-hashtb)
1109           (when new-newsgroups
1110             (gnus-subscribe-hierarchical-interactive new-newsgroups))
1111           (if (> groups 0)
1112               (gnus-message 5 "%d new newsgroup%s arrived."
1113                             groups (if (> groups 1) "s have" " has"))
1114             (gnus-message 5 "No new newsgroups.")))))))
1115
1116 (defun gnus-matches-options-n (group)
1117   ;; Returns `subscribe' if the group is to be unconditionally
1118   ;; subscribed, `ignore' if it is to be ignored, and nil if there is
1119   ;; no match for the group.
1120
1121   ;; First we check the two user variables.
1122   (cond
1123    ((and gnus-options-subscribe
1124          (string-match gnus-options-subscribe group))
1125     'subscribe)
1126    ((and gnus-auto-subscribed-groups
1127          (string-match gnus-auto-subscribed-groups group))
1128     'subscribe)
1129    ((and gnus-options-not-subscribe
1130          (string-match gnus-options-not-subscribe group))
1131     'ignore)
1132    ;; Then we go through the list that was retrieved from the .newsrc
1133    ;; file.  This list has elements on the form
1134    ;; `(REGEXP . {ignore,subscribe})'.  The first match found (the list
1135    ;; is in the reverse order of the options line) is returned.
1136    (t
1137     (let ((regs gnus-newsrc-options-n))
1138       (while (and regs
1139                   (not (string-match (caar regs) group)))
1140         (setq regs (cdr regs)))
1141       (and regs (cdar regs))))))
1142
1143 (defun gnus-ask-server-for-new-groups ()
1144   (let* ((new-date (message-make-date))
1145          (date (or gnus-newsrc-last-checked-date new-date))
1146          (methods (cons gnus-select-method
1147                         (nconc
1148                          (when (gnus-archive-server-wanted-p)
1149                            (list "archive"))
1150                          (append
1151                           (and (consp gnus-check-new-newsgroups)
1152                                gnus-check-new-newsgroups)
1153                           gnus-secondary-select-methods))))
1154          (groups 0)
1155          group new-newsgroups got-new method hashtb
1156          gnus-override-subscribe-method)
1157     (unless gnus-killed-hashtb
1158       (gnus-make-hashtable-from-killed))
1159     ;; Go through both primary and secondary select methods and
1160     ;; request new newsgroups.
1161     (while (setq method (gnus-server-get-method nil (pop methods)))
1162       (setq new-newsgroups nil
1163             gnus-override-subscribe-method method)
1164       (when (and (gnus-check-server method)
1165                  (gnus-request-newgroups date method))
1166         (save-excursion
1167           (setq got-new t
1168                 hashtb (gnus-make-hashtable 100))
1169           (set-buffer nntp-server-buffer)
1170           ;; Enter all the new groups into a hashtable.
1171           (gnus-active-to-gnus-format method hashtb 'ignore))
1172         ;; Now all new groups from `method' are in `hashtb'.
1173         (mapatoms
1174          (lambda (group-sym)
1175            (if (or (null (setq group (symbol-name group-sym)))
1176                    (not (boundp group-sym))
1177                    (null (symbol-value group-sym))
1178                    (gnus-gethash group gnus-newsrc-hashtb)
1179                    (member group gnus-zombie-list)
1180                    (member group gnus-killed-list))
1181                ;; The group is already known.
1182                ()
1183              ;; Make this group active.
1184              (when (symbol-value group-sym)
1185                (gnus-set-active group (symbol-value group-sym)))
1186              ;; Check whether we want it or not.
1187              (let ((do-sub (gnus-matches-options-n group)))
1188                (cond
1189                 ((eq do-sub 'subscribe)
1190                  (incf groups)
1191                  (gnus-sethash group group gnus-killed-hashtb)
1192                  (gnus-call-subscribe-functions
1193                   gnus-subscribe-options-newsgroup-method group))
1194                 ((eq do-sub 'ignore)
1195                  nil)
1196                 (t
1197                  (incf groups)
1198                  (gnus-sethash group group gnus-killed-hashtb)
1199                  (if gnus-subscribe-hierarchical-interactive
1200                      (push group new-newsgroups)
1201                    (gnus-call-subscribe-functions
1202                     gnus-subscribe-newsgroup-method group)))))))
1203          hashtb))
1204       (when new-newsgroups
1205         (gnus-subscribe-hierarchical-interactive new-newsgroups)))
1206     (if (> groups 0)
1207         (gnus-message 5 "%d new newsgroup%s arrived"
1208                       groups (if (> groups 1) "s have" " has"))
1209       (gnus-message 5 "No new newsgroups"))
1210     (when got-new
1211       (setq gnus-newsrc-last-checked-date new-date))
1212     got-new))
1213
1214 (defun gnus-check-first-time-used ()
1215   (catch 'ended
1216     ;; First check if any of the following files exist.  If they do,
1217     ;; it's not the first time the user has used Gnus.
1218     (dolist (file (list (concat gnus-current-startup-file ".el")
1219                         (concat gnus-current-startup-file ".eld")
1220                         (concat gnus-startup-file ".el")
1221                         (concat gnus-startup-file ".eld")))
1222       (when (file-exists-p file)
1223         (throw 'ended nil)))
1224     (gnus-message 6 "First time user; subscribing you to default groups")
1225     (unless (gnus-read-active-file-p)
1226       (let ((gnus-read-active-file t))
1227         (gnus-read-active-file)))
1228     (setq gnus-newsrc-last-checked-date (message-make-date))
1229     ;; Subscribe to the default newsgroups.
1230     (let ((groups (or gnus-default-subscribed-newsgroups
1231                       gnus-backup-default-subscribed-newsgroups))
1232           group)
1233       (if (eq groups t)
1234           ;; If t, we subscribe (or not) all groups as if they were new.
1235           (mapatoms
1236            (lambda (sym)
1237              (when (setq group (symbol-name sym))
1238                (let ((do-sub (gnus-matches-options-n group)))
1239                  (cond
1240                   ((eq do-sub 'subscribe)
1241                    (gnus-sethash group group gnus-killed-hashtb)
1242                    (gnus-call-subscribe-functions
1243                     gnus-subscribe-options-newsgroup-method group))
1244                   ((eq do-sub 'ignore)
1245                    nil)
1246                   (t
1247                    (push group gnus-killed-list))))))
1248            gnus-active-hashtb)
1249         (dolist (group groups)
1250           ;; Only subscribe the default groups that are activated.
1251           (when (gnus-active group)
1252             (gnus-group-change-level
1253              group gnus-level-default-subscribed gnus-level-killed)))
1254         (save-excursion
1255           (set-buffer gnus-group-buffer)
1256           ;; Don't error if the group already exists. This happens when a
1257           ;; first-time user types 'F'. -- didier
1258           (gnus-group-make-help-group t))
1259         (when gnus-novice-user
1260           (gnus-message 7 "`A k' to list killed groups"))))))
1261
1262 (defun gnus-subscribe-group (group &optional previous method)
1263   "Subscribe GROUP and put it after PREVIOUS."
1264   (gnus-group-change-level
1265    (if method
1266        (list t group gnus-level-default-subscribed nil nil method)
1267      group)
1268    gnus-level-default-subscribed gnus-level-killed previous t)
1269   t)