* gnus-registry.el (gnus-registry-save): allow forced saving even
[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 (eval-when-compile (require 'cl))
37
38 (defcustom gnus-startup-file (nnheader-concat gnus-home-directory ".newsrc")
39   "Your `.newsrc' file.
40 `.newsrc-SERVER' will be used instead if that exists."
41   :group 'gnus-start
42   :type 'file)
43
44 (defcustom gnus-backup-startup-file 'never
45   "Whether to create backup files.
46 This variable takes the same values as the `version-control'
47 variable."
48   :group 'gnus-start
49   :type '(choice (const :tag "Never" never)
50                  (const :tag "If existing" nil)
51                  (other :tag "Always" t)))
52
53 (defcustom gnus-save-startup-file-via-temp-buffer t
54   "Whether to write the startup file contents to a buffer then save
55 the buffer or write directly to the file.  The buffer is faster
56 because all of the contents are written at once.  The direct write
57 uses considerably less memory."
58   :group 'gnus-start
59   :type '(choice (const :tag "Write via buffer" t)
60                  (const :tag "Write directly to file" nil)))
61
62 (defcustom gnus-init-file (nnheader-concat gnus-home-directory ".gnus")
63   "Your Gnus Emacs-Lisp startup file name.
64 If a file with the `.el' or `.elc' suffixes exists, it will be read instead."
65   :group 'gnus-start
66   :type 'file)
67
68 (defcustom gnus-site-init-file
69   (condition-case nil
70       (concat (file-name-directory
71                (directory-file-name installation-directory))
72               "site-lisp/gnus-init")
73     (error nil))
74   "The site-wide Gnus Emacs-Lisp startup file name, or nil if none.
75 If a file with the `.el' or `.elc' suffixes exists, it will be read instead."
76   :group 'gnus-start
77   :type '(choice file (const nil)))
78
79 (defcustom gnus-default-subscribed-newsgroups nil
80   "List of newsgroups to subscribe, when a user runs Gnus the first time.
81 The value should be a list of strings.
82 If it is t, Gnus will not do anything special the first time it is
83 started; it'll just use the normal newsgroups subscription methods."
84   :group 'gnus-start
85   :type '(choice (repeat string) (const :tag "Nothing special" t)))
86
87 (defcustom gnus-use-dribble-file t
88   "*Non-nil means that Gnus will use a dribble file to store user updates.
89 If Emacs should crash without saving the .newsrc files, complete
90 information can be restored from the dribble file."
91   :group 'gnus-dribble-file
92   :type 'boolean)
93
94 (defcustom gnus-dribble-directory nil
95   "*The directory where dribble files will be saved.
96 If this variable is nil, the directory where the .newsrc files are
97 saved will be used."
98   :group 'gnus-dribble-file
99   :type '(choice directory (const nil)))
100
101 (defcustom gnus-check-new-newsgroups 'ask-server
102   "*Non-nil means that Gnus will run `gnus-find-new-newsgroups' at startup.
103 This normally finds new newsgroups by comparing the active groups the
104 servers have already reported with those Gnus already knows, either alive
105 or killed.
106
107 When any of the following are true, `gnus-find-new-newsgroups' will instead
108 ask the servers (primary, secondary, and archive servers) to list new
109 groups since the last time it checked:
110   1. This variable is `ask-server'.
111   2. This variable is a list of select methods (see below).
112   3. `gnus-read-active-file' is nil or `some'.
113   4. A prefix argument is given to `gnus-find-new-newsgroups' interactively.
114
115 Thus, if this variable is `ask-server' or a list of select methods or
116 `gnus-read-active-file' is nil or `some', then the killed list is no
117 longer necessary, so you could safely set `gnus-save-killed-list' to nil.
118
119 This variable can be a list of select methods which Gnus will query with
120 the `ask-server' method in addition to the primary, secondary, and archive
121 servers.
122
123 Eg.
124   (setq gnus-check-new-newsgroups
125         '((nntp \"some.server\") (nntp \"other.server\")))
126
127 If this variable is nil, then you have to tell Gnus explicitly to
128 check for new newsgroups with \\<gnus-group-mode-map>\\[gnus-find-new-newsgroups]."
129   :group 'gnus-start
130   :type '(choice (const :tag "no" nil)
131                  (const :tag "by brute force" t)
132                  (const :tag "ask servers" ask-server)
133                  (repeat :menu-tag "ask additional servers"
134                          :tag "ask additional servers"
135                          :value ((nntp ""))
136                          (sexp :format "%v"))))
137
138 (defcustom gnus-check-bogus-newsgroups nil
139   "*Non-nil means that Gnus will check and remove bogus newsgroup at startup.
140 If this variable is nil, then you have to tell Gnus explicitly to
141 check for bogus newsgroups with \\<gnus-group-mode-map>\\[gnus-group-check-bogus-groups]."
142   :group 'gnus-start-server
143   :type 'boolean)
144
145 (defcustom gnus-read-active-file 'some
146   "*Non-nil means that Gnus will read the entire active file at startup.
147 If this variable is nil, Gnus will only know about the groups in your
148 `.newsrc' file.
149
150 If this variable is `some', Gnus will try to only read the relevant
151 parts of the active file from the server.  Not all servers support
152 this, and it might be quite slow with other servers, but this should
153 generally be faster than both the t and nil value.
154
155 If you set this variable to nil or `some', you probably still want to
156 be told about new newsgroups that arrive.  To do that, set
157 `gnus-check-new-newsgroups' to `ask-server'.  This may not work
158 properly with all servers."
159   :group 'gnus-start-server
160   :type '(choice (const nil)
161                  (const some)
162                  (const t)))
163
164 (defconst gnus-level-subscribed 5
165   "Groups with levels less than or equal to this variable are subscribed.")
166
167 (defconst gnus-level-unsubscribed 7
168   "Groups with levels less than or equal to this variable are unsubscribed.
169 Groups with levels less than `gnus-level-subscribed', which should be
170 less than this variable, are subscribed.")
171
172 (defconst gnus-level-zombie 8
173   "Groups with this level are zombie groups.")
174
175 (defconst gnus-level-killed 9
176   "Groups with this level are killed.")
177
178 (defcustom gnus-level-default-subscribed 3
179   "*New subscribed groups will be subscribed at this level."
180   :group 'gnus-group-levels
181   :type 'integer)
182
183 (defcustom gnus-level-default-unsubscribed 6
184   "*New unsubscribed groups will be unsubscribed at this level."
185   :group 'gnus-group-levels
186   :type 'integer)
187
188 (defcustom gnus-activate-level (1+ gnus-level-subscribed)
189   "*Groups higher than this level won't be activated on startup.
190 Setting this variable to something low might save lots of time when
191 you have many groups that you aren't interested in."
192   :group 'gnus-group-levels
193   :type 'integer)
194
195 (defcustom gnus-activate-foreign-newsgroups 4
196   "*If nil, Gnus will not check foreign newsgroups at startup.
197 If it is non-nil, it should be a number between one and nine.  Foreign
198 newsgroups that have a level lower or equal to this number will be
199 activated on startup.  For instance, if you want to active all
200 subscribed newsgroups, but not the rest, you'd set this variable to
201 `gnus-level-subscribed'.
202
203 If you subscribe to lots of newsgroups from different servers, startup
204 might take a while.  By setting this variable to nil, you'll save time,
205 but you won't be told how many unread articles there are in the
206 groups."
207   :group 'gnus-group-levels
208   :type '(choice integer
209                  (const :tag "none" nil)))
210
211 (defcustom gnus-read-newsrc-file t
212   "*Non-nil means that Gnus will read the `.newsrc' file.
213 Gnus always reads its own startup file, which is called
214 \".newsrc.eld\".  The file called \".newsrc\" is in a format that can
215 be readily understood by other newsreaders.  If you don't plan on
216 using other newsreaders, set this variable to nil to save some time on
217 entry."
218   :version "21.1"
219   :group 'gnus-newsrc
220   :type 'boolean)
221
222 (defcustom gnus-save-newsrc-file t
223   "*Non-nil means that Gnus will save the `.newsrc' file.
224 Gnus always saves its own startup file, which is called
225 \".newsrc.eld\".  The file called \".newsrc\" is in a format that can
226 be readily understood by other newsreaders.  If you don't plan on
227 using other newsreaders, set this variable to nil to save some time on
228 exit."
229   :group 'gnus-newsrc
230   :type 'boolean)
231
232 (defcustom gnus-save-killed-list t
233   "*If non-nil, save the list of killed groups to the startup file.
234 If you set this variable to nil, you'll save both time (when starting
235 and quitting) and space (both memory and disk), but it will also mean
236 that Gnus has no record of which groups are new and which are old, so
237 the automatic new newsgroups subscription methods become meaningless.
238
239 You should always set `gnus-check-new-newsgroups' to `ask-server' or
240 nil if you set this variable to nil.
241
242 This variable can also be a regexp.  In that case, all groups that do
243 not match this regexp will be removed before saving the list."
244   :group 'gnus-newsrc
245   :type 'boolean)
246
247 (defcustom gnus-ignored-newsgroups
248   (mapconcat 'identity
249              '("^to\\."                 ; not "real" groups
250                "^[0-9. \t]+\\( \\|$\\)" ; all digits in name
251                "^[\"][]\"[#'()]"        ; bogus characters
252                )
253              "\\|")
254   "*A regexp to match uninteresting newsgroups in the active file.
255 Any lines in the active file matching this regular expression are
256 removed from the newsgroup list before anything else is done to it,
257 thus making them effectively non-existent."
258   :group 'gnus-group-new
259   :type 'regexp)
260
261 (defcustom gnus-subscribe-newsgroup-method 'gnus-subscribe-zombies
262   "*Function(s) called with a group name when new group is detected.
263 A few pre-made functions are supplied: `gnus-subscribe-randomly'
264 inserts new groups at the beginning of the list of groups;
265 `gnus-subscribe-alphabetically' inserts new groups in strict
266 alphabetic order; `gnus-subscribe-hierarchically' inserts new groups
267 in hierarchical newsgroup order; `gnus-subscribe-interactively' asks
268 for your decision; `gnus-subscribe-killed' kills all new groups;
269 `gnus-subscribe-zombies' will make all new groups into zombies;
270 `gnus-subscribe-topics' will enter groups into the topics that
271 claim them."
272   :group 'gnus-group-new
273   :type '(radio (function-item gnus-subscribe-randomly)
274                 (function-item gnus-subscribe-alphabetically)
275                 (function-item gnus-subscribe-hierarchically)
276                 (function-item gnus-subscribe-interactively)
277                 (function-item gnus-subscribe-killed)
278                 (function-item gnus-subscribe-zombies)
279                 (function-item gnus-subscribe-topics)
280                 function
281                 (repeat function)))
282
283 (defcustom gnus-subscribe-newsgroup-hooks nil
284   "*Hooks run after you subscribe to a new group. The hooks will be called
285 with new group's name as argument."
286   :group 'gnus-group-new
287   :type 'hook)
288
289 (defcustom gnus-subscribe-options-newsgroup-method
290   'gnus-subscribe-alphabetically
291   "*Function(s) called to subscribe newsgroups mentioned on \"options -n\" lines.
292 If, for instance, you want to subscribe to all newsgroups in the
293 \"no\" and \"alt\" hierarchies, you'd put the following in your
294 .newsrc file:
295
296 options -n no.all alt.all
297
298 Gnus will the subscribe all new newsgroups in these hierarchies with
299 the subscription method in this variable."
300   :group 'gnus-group-new
301   :type '(radio (function-item gnus-subscribe-randomly)
302                 (function-item gnus-subscribe-alphabetically)
303                 (function-item gnus-subscribe-hierarchically)
304                 (function-item gnus-subscribe-interactively)
305                 (function-item gnus-subscribe-killed)
306                 (function-item gnus-subscribe-zombies)
307                 (function-item gnus-subscribe-topics)
308                 function
309                 (repeat function)))
310
311 (defcustom gnus-subscribe-hierarchical-interactive nil
312   "*If non-nil, Gnus will offer to subscribe hierarchically.
313 When a new hierarchy appears, Gnus will ask the user:
314
315 'alt.binaries': Do you want to subscribe to this hierarchy? ([d]ys):
316
317 If the user pressed `d', Gnus will descend the hierarchy, `y' will
318 subscribe to all newsgroups in the hierarchy and `s' will skip this
319 hierarchy in its entirety."
320   :group 'gnus-group-new
321   :type 'boolean)
322
323 (defcustom gnus-auto-subscribed-groups
324   "^nnml\\|^nnfolder\\|^nnmbox\\|^nnmh\\|^nnbabyl\\|^nnmaildir"
325   "*All new groups that match this regexp will be subscribed automatically.
326 Note that this variable only deals with new groups.  It has no effect
327 whatsoever on old groups.
328
329 New groups that match this regexp will not be handled by
330 `gnus-subscribe-newsgroup-method'.  Instead, they will
331 be subscribed using `gnus-subscribe-options-newsgroup-method'."
332   :group 'gnus-group-new
333   :type 'regexp)
334
335 (defcustom gnus-options-subscribe nil
336   "*All new groups matching this regexp will be subscribed unconditionally.
337 Note that this variable deals only with new newsgroups.  This variable
338 does not affect old newsgroups.
339
340 New groups that match this regexp will not be handled by
341 `gnus-subscribe-newsgroup-method'.  Instead, they will
342 be subscribed using `gnus-subscribe-options-newsgroup-method'."
343   :group 'gnus-group-new
344   :type '(choice regexp
345                  (const :tag "none" nil)))
346
347 (defcustom gnus-options-not-subscribe nil
348   "*All new groups matching this regexp will be ignored.
349 Note that this variable deals only with new newsgroups.  This variable
350 does not affect old (already subscribed) newsgroups."
351   :group 'gnus-group-new
352   :type '(choice regexp
353                  (const :tag "none" nil)))
354
355 (defcustom gnus-modtime-botch nil
356   "*Non-nil means .newsrc should be deleted prior to save.
357 Its use is due to the bogus appearance that .newsrc was modified on
358 disc."
359   :group 'gnus-newsrc
360   :type 'boolean)
361
362 (defcustom gnus-check-bogus-groups-hook nil
363   "A hook run after removing bogus groups."
364   :group 'gnus-start-server
365   :type 'hook)
366
367 (defcustom gnus-startup-hook nil
368   "A hook called at startup.
369 This hook is called after Gnus is connected to the NNTP server."
370   :group 'gnus-start
371   :type 'hook)
372
373 (defcustom gnus-before-startup-hook nil
374   "A hook called at before startup.
375 This hook is called as the first thing when Gnus is started."
376   :group 'gnus-start
377   :type 'hook)
378
379 (defcustom gnus-started-hook nil
380   "A hook called as the last thing after startup."
381   :group 'gnus-start
382   :type 'hook)
383
384 (defcustom gnus-setup-news-hook 
385   '(gnus-fixup-nnimap-unread-after-getting-new-news)
386   "A hook after reading the .newsrc file, but before generating the buffer."
387   :group 'gnus-start
388   :type 'hook)
389
390 (defcustom gnus-get-top-new-news-hook nil
391   "A hook run just before Gnus checks for new news globally."
392   :group 'gnus-group-new
393   :type 'hook)
394
395 (defcustom gnus-get-new-news-hook nil
396   "A hook run just before Gnus checks for new news."
397   :group 'gnus-group-new
398   :type 'hook)
399
400 (defcustom gnus-after-getting-new-news-hook
401   '(gnus-display-time-event-handler 
402     gnus-fixup-nnimap-unread-after-getting-new-news)
403   "*A hook run after Gnus checks for new news when Gnus is already running."
404   :group 'gnus-group-new
405   :type 'hook)
406
407 (defcustom gnus-read-newsrc-el-hook nil
408   "A hook called after reading the newsrc.eld? file."
409   :group 'gnus-newsrc
410   :type 'hook)
411
412 (defcustom gnus-save-newsrc-hook nil
413   "A hook called before saving any of the newsrc files."
414   :group 'gnus-newsrc
415   :type 'hook)
416
417 (defcustom gnus-save-quick-newsrc-hook nil
418   "A hook called just before saving the quick newsrc file.
419 Can be used to turn version control on or off."
420   :group 'gnus-newsrc
421   :type 'hook)
422
423 (defcustom gnus-save-standard-newsrc-hook nil
424   "A hook called just before saving the standard newsrc file.
425 Can be used to turn version control on or off."
426   :group 'gnus-newsrc
427   :type 'hook)
428
429 (defcustom gnus-group-mode-hook nil
430   "Hook for Gnus group mode."
431   :group 'gnus-group-various
432   :options '(gnus-topic-mode)
433   :type 'hook)
434
435 (defcustom gnus-always-read-dribble-file nil
436   "Unconditionally read the dribble file."
437   :group 'gnus-newsrc
438   :type 'boolean)
439
440 ;;; Internal variables
441
442 (defvar gnus-ding-file-coding-system mm-universal-coding-system
443   "Coding system for ding file.")
444
445 (defvar gnus-newsrc-file-version nil)
446 (defvar gnus-override-subscribe-method nil)
447 (defvar gnus-dribble-buffer nil)
448 (defvar gnus-newsrc-options nil
449   "Options line in the .newsrc file.")
450
451 (defvar gnus-newsrc-options-n nil
452   "List of regexps representing groups to be subscribed/ignored unconditionally.")
453
454 (defvar gnus-newsrc-last-checked-date nil
455   "Date Gnus last asked server for new newsgroups.")
456
457 (defvar gnus-current-startup-file nil
458   "Startup file for the current host.")
459
460 ;; Byte-compiler warning.
461 (defvar gnus-group-line-format)
462
463 ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
464 (defvar gnus-init-inhibit nil)
465 (defun gnus-read-init-file (&optional inhibit-next)
466   ;; Don't load .gnus if the -q option was used.
467   (when init-file-user
468     (if gnus-init-inhibit
469         (setq gnus-init-inhibit nil)
470       (setq gnus-init-inhibit inhibit-next)
471       (dolist (file (list gnus-site-init-file gnus-init-file))
472         (when (and file
473                    (locate-library file))
474           (if (or debug-on-error debug-on-quit)
475               (load file nil t)
476             (condition-case var
477                 (load file nil t)
478               (error
479                (error "Error in %s: %s" file (cadr var))))))))))
480
481 ;; For subscribing new newsgroup
482
483 (defun gnus-subscribe-hierarchical-interactive (groups)
484   (let ((groups (sort groups 'string<))
485         prefixes prefix start ans group starts)
486     (while groups
487       (setq prefixes (list "^"))
488       (while (and groups prefixes)
489         (while (not (string-match (car prefixes) (car groups)))
490           (setq prefixes (cdr prefixes)))
491         (setq prefix (car prefixes))
492         (setq start (1- (length prefix)))
493         (if (and (string-match "[^\\.]\\." (car groups) start)
494                  (cdr groups)
495                  (setq prefix
496                        (concat "^" (substring (car groups) 0 (match-end 0))))
497                  (string-match prefix (cadr groups)))
498             (progn
499               (push prefix prefixes)
500               (message "Descend hierarchy %s? ([y]nsq): "
501                        (substring prefix 1 (1- (length prefix))))
502               (while (not (memq (setq ans (read-char-exclusive))
503                                 '(?y ?\n ?\r ?n ?s ?q)))
504                 (ding)
505                 (message "Descend hierarchy %s? ([y]nsq): "
506                          (substring prefix 1 (1- (length prefix)))))
507               (cond ((= ans ?n)
508                      (while (and groups
509                                  (string-match prefix
510                                                (setq group (car groups))))
511                        (push group gnus-killed-list)
512                        (gnus-sethash group group gnus-killed-hashtb)
513                        (setq groups (cdr groups)))
514                      (setq starts (cdr starts)))
515                     ((= ans ?s)
516                      (while (and groups
517                                  (string-match prefix
518                                                (setq group (car groups))))
519                        (gnus-sethash group group gnus-killed-hashtb)
520                        (gnus-subscribe-alphabetically (car groups))
521                        (setq groups (cdr groups)))
522                      (setq starts (cdr starts)))
523                     ((= ans ?q)
524                      (while groups
525                        (setq group (car groups))
526                        (push group gnus-killed-list)
527                        (gnus-sethash group group gnus-killed-hashtb)
528                        (setq groups (cdr groups))))
529                     (t nil)))
530           (message "Subscribe %s? ([n]yq)" (car groups))
531           (while (not (memq (setq ans (read-char-exclusive))
532                             '(?y ?\n ?\r ?q ?n)))
533             (ding)
534             (message "Subscribe %s? ([n]yq)" (car groups)))
535           (setq group (car groups))
536           (cond ((= ans ?y)
537                  (gnus-subscribe-alphabetically (car groups))
538                  (gnus-sethash group group gnus-killed-hashtb))
539                 ((= ans ?q)
540                  (while groups
541                    (setq group (car groups))
542                    (push group gnus-killed-list)
543                    (gnus-sethash group group gnus-killed-hashtb)
544                    (setq groups (cdr groups))))
545                 (t
546                  (push group gnus-killed-list)
547                  (gnus-sethash group group gnus-killed-hashtb)))
548           (setq groups (cdr groups)))))))
549
550 (defun gnus-subscribe-randomly (newsgroup)
551   "Subscribe new NEWSGROUP by making it the first newsgroup."
552   (gnus-subscribe-newsgroup newsgroup))
553
554 (defun gnus-subscribe-alphabetically (newgroup)
555   "Subscribe new NEWSGROUP and insert it in alphabetical order."
556   (let ((groups (cdr gnus-newsrc-alist))
557         before)
558     (while (and (not before) groups)
559       (if (string< newgroup (caar groups))
560           (setq before (caar groups))
561         (setq groups (cdr groups))))
562     (gnus-subscribe-newsgroup newgroup before)))
563
564 (defun gnus-subscribe-hierarchically (newgroup)
565   "Subscribe new NEWSGROUP and insert it in hierarchical newsgroup order."
566   ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
567   (save-excursion
568     (set-buffer (nnheader-find-file-noselect gnus-current-startup-file))
569     (prog1
570         (let ((groupkey newgroup) before)
571           (while (and (not before) groupkey)
572             (goto-char (point-min))
573             (let ((groupkey-re
574                    (concat "^\\(" (regexp-quote groupkey) ".*\\)[!:]")))
575               (while (and (re-search-forward groupkey-re nil t)
576                           (progn
577                             (setq before (match-string 1))
578                             (string< before newgroup)))))
579             ;; Remove tail of newsgroup name (eg. a.b.c -> a.b)
580             (setq groupkey
581                   (when (string-match "^\\(.*\\)\\.[^.]+$" groupkey)
582                     (substring groupkey (match-beginning 1) (match-end 1)))))
583           (gnus-subscribe-newsgroup newgroup before))
584       (kill-buffer (current-buffer)))))
585
586 (defun gnus-subscribe-interactively (group)
587   "Subscribe the new GROUP interactively.
588 It is inserted in hierarchical newsgroup order if subscribed.  If not,
589 it is killed."
590   (if (gnus-y-or-n-p (format "Subscribe new newsgroup: %s " group))
591       (gnus-subscribe-hierarchically group)
592     (push group gnus-killed-list)))
593
594 (defun gnus-subscribe-zombies (group)
595   "Make the new GROUP into a zombie group."
596   (push group gnus-zombie-list))
597
598 (defun gnus-subscribe-killed (group)
599   "Make the new GROUP a killed group."
600   (push group gnus-killed-list))
601
602 (defun gnus-subscribe-newsgroup (newsgroup &optional next)
603   "Subscribe new NEWSGROUP.
604 If NEXT is non-nil, it is inserted before NEXT.  Otherwise it is made
605 the first newsgroup."
606   (save-excursion
607     (goto-char (point-min))
608     ;; We subscribe the group by changing its level to `subscribed'.
609     (gnus-group-change-level
610      newsgroup gnus-level-default-subscribed
611      gnus-level-killed (gnus-gethash (or next "dummy.group")
612                                      gnus-newsrc-hashtb))
613     (gnus-message 5 "Subscribe newsgroup: %s" newsgroup)
614     (run-hook-with-args 'gnus-subscribe-newsgroup-hooks newsgroup)
615     t))
616
617 (defun gnus-read-active-file-p ()
618   "Say whether the active file has been read from `gnus-select-method'."
619   (memq gnus-select-method gnus-have-read-active-file))
620
621 ;;; General various misc type functions.
622
623 ;; Silence byte-compiler.
624 (eval-when-compile
625   (defvar gnus-current-headers)
626   (defvar gnus-thread-indent-array)
627   (defvar gnus-newsgroup-name)
628   (defvar gnus-newsgroup-headers)
629   (defvar gnus-group-list-mode)
630   (defvar gnus-group-mark-positions)
631   (defvar gnus-newsgroup-data)
632   (defvar gnus-newsgroup-unreads)
633   (defvar nnoo-state-alist)
634   (defvar gnus-current-select-method)
635   (defvar mail-sources)
636   (defvar nnmail-scan-directory-mail-source-once)
637   (defvar nnmail-split-history)
638   (defvar nnmail-spool-file))
639
640 (defun gnus-close-all-servers ()
641   "Close all servers."
642   (interactive)
643   (dolist (server gnus-opened-servers)
644     (gnus-close-server (car server))))
645
646 (defun gnus-clear-system ()
647   "Clear all variables and buffers."
648   ;; Clear Gnus variables.
649   (let ((variables (remove 'gnus-format-specs gnus-variable-list)))
650     (while variables
651       (set (car variables) nil)
652       (setq variables (cdr variables))))
653   ;; Clear other internal variables.
654   (setq gnus-list-of-killed-groups nil
655         gnus-have-read-active-file nil
656         gnus-newsrc-alist nil
657         gnus-newsrc-hashtb nil
658         gnus-killed-list nil
659         gnus-zombie-list nil
660         gnus-killed-hashtb nil
661         gnus-active-hashtb nil
662         gnus-moderated-hashtb nil
663         gnus-description-hashtb nil
664         gnus-current-headers nil
665         gnus-thread-indent-array nil
666         gnus-newsgroup-headers nil
667         gnus-newsgroup-name nil
668         gnus-server-alist nil
669         gnus-group-list-mode nil
670         gnus-opened-servers nil
671         gnus-group-mark-positions nil
672         gnus-newsgroup-data nil
673         gnus-newsgroup-unreads nil
674         nnoo-state-alist nil
675         gnus-current-select-method nil
676         nnmail-split-history nil
677         gnus-ephemeral-servers nil)
678   (gnus-shutdown 'gnus)
679   ;; Kill the startup file.
680   (and gnus-current-startup-file
681        (get-file-buffer gnus-current-startup-file)
682        (kill-buffer (get-file-buffer gnus-current-startup-file)))
683   ;; Clear the dribble buffer.
684   (gnus-dribble-clear)
685   ;; Kill global KILL file buffer.
686   (when (get-file-buffer (gnus-newsgroup-kill-file nil))
687     (kill-buffer (get-file-buffer (gnus-newsgroup-kill-file nil))))
688   (gnus-kill-buffer nntp-server-buffer)
689   ;; Kill Gnus buffers.
690   (dolist (buffer (gnus-buffers))
691     (gnus-kill-buffer buffer))
692   ;; Remove Gnus frames.
693   (gnus-kill-gnus-frames))
694
695 (defun gnus-no-server-1 (&optional arg slave)
696   "Read network news.
697 If ARG is a positive number, Gnus will use that as the
698 startup level.  If ARG is nil, Gnus will be started at level 2.
699 If ARG is non-nil and not a positive number, Gnus will
700 prompt the user for the name of an NNTP server to use.
701 As opposed to `gnus', this command will not connect to the local server."
702   (interactive "P")
703   (let ((val (or arg (1- gnus-level-default-subscribed))))
704     (gnus val t slave)
705     (make-local-variable 'gnus-group-use-permanent-levels)
706     (setq gnus-group-use-permanent-levels val)))
707
708 (defun gnus-1 (&optional arg dont-connect slave)
709   "Read network news.
710 If ARG is non-nil and a positive number, Gnus will use that as the
711 startup level.  If ARG is non-nil and not a positive number, Gnus will
712 prompt the user for the name of an NNTP server to use."
713   (interactive "P")
714
715   (if (gnus-alive-p)
716       (progn
717         (switch-to-buffer gnus-group-buffer)
718         (gnus-group-get-new-news
719          (and (numberp arg)
720               (> arg 0)
721               (max (car gnus-group-list-mode) arg))))
722
723     (gnus-clear-system)
724     (gnus-splash)
725     (gnus-run-hooks 'gnus-before-startup-hook)
726     (nnheader-init-server-buffer)
727     (setq gnus-slave slave)
728     (gnus-read-init-file)
729     (if gnus-agent
730         (gnus-agentize))
731
732     (when gnus-simple-splash
733       (setq gnus-simple-splash nil)
734       (cond
735        ((featurep 'xemacs)
736         (gnus-xmas-splash))
737        ((and window-system
738              (= (frame-height) (1+ (window-height))))
739         (gnus-x-splash))))
740
741     (let ((level (and (numberp arg) (> arg 0) arg))
742           did-connect)
743       (unwind-protect
744           (progn
745             (unless dont-connect
746               (setq did-connect
747                     (gnus-start-news-server (and arg (not level))))))
748         (if (and (not dont-connect)
749                  (not did-connect))
750             (gnus-group-quit)
751           (gnus-run-hooks 'gnus-startup-hook)
752           ;; NNTP server is successfully open.
753
754           ;; Find the current startup file name.
755           (setq gnus-current-startup-file
756                 (gnus-make-newsrc-file gnus-startup-file))
757
758           ;; Read the dribble file.
759           (when (or gnus-slave gnus-use-dribble-file)
760             (gnus-dribble-read-file))
761
762           ;; Allow using GroupLens predictions.
763           (when gnus-use-grouplens
764             (bbb-login)
765             (add-hook 'gnus-summary-mode-hook 'gnus-grouplens-mode))
766
767           ;; Do the actual startup.
768           (if gnus-agent
769               (gnus-request-create-group "queue" '(nndraft "")))
770           (gnus-request-create-group "drafts" '(nndraft ""))
771           (gnus-setup-news nil level dont-connect)
772           (gnus-run-hooks 'gnus-setup-news-hook)
773           (gnus-start-draft-setup)
774           ;; Generate the group buffer.
775           (gnus-group-list-groups level)
776           (gnus-group-first-unread-group)
777           (gnus-configure-windows 'group)
778           (gnus-group-set-mode-line)
779           (gnus-run-hooks 'gnus-started-hook))))))
780
781 (defun gnus-start-draft-setup ()
782   "Make sure the draft group exists."
783   (gnus-request-create-group "drafts" '(nndraft ""))
784   (unless (gnus-gethash "nndraft:drafts" gnus-newsrc-hashtb)
785     (let ((gnus-level-default-subscribed 1))
786       (gnus-subscribe-group "nndraft:drafts" nil '(nndraft "")))
787     (gnus-group-set-parameter
788      "nndraft:drafts" 'gnus-dummy '((gnus-draft-mode)))))
789
790 \f
791 ;;;
792 ;;; Dribble file
793 ;;;
794
795 (defvar gnus-dribble-ignore nil)
796 (defvar gnus-dribble-eval-file nil)
797
798 (defun gnus-dribble-file-name ()
799   "Return the dribble file for the current .newsrc."
800   (concat
801    (if gnus-dribble-directory
802        (concat (file-name-as-directory gnus-dribble-directory)
803                (file-name-nondirectory gnus-current-startup-file))
804      gnus-current-startup-file)
805    "-dribble"))
806
807 (defun gnus-dribble-enter (string)
808   "Enter STRING into the dribble buffer."
809   (when (and (not gnus-dribble-ignore)
810              gnus-dribble-buffer
811              (buffer-name gnus-dribble-buffer))
812     (let ((obuf (current-buffer)))
813       (set-buffer gnus-dribble-buffer)
814       (goto-char (point-max))
815       (insert string "\n")
816       ;; This has been commented by Josh Huber <huber@alum.wpi.edu>
817       ;; It causes problems with both XEmacs and Emacs 21, and doesn't
818       ;; seem to be of much value. (FIXME: remove this after we make sure
819       ;; it's not needed).
820       ;; (set-window-point (get-buffer-window (current-buffer)) (point-max))
821       (bury-buffer gnus-dribble-buffer)
822       (save-excursion
823         (set-buffer gnus-group-buffer)
824         (gnus-group-set-mode-line))
825       (set-buffer obuf))))
826
827 (defun gnus-dribble-touch ()
828   "Touch the dribble buffer."
829   (gnus-dribble-enter ""))
830
831 (defun gnus-dribble-read-file ()
832   "Read the dribble file from disk."
833   (let ((dribble-file (gnus-dribble-file-name)))
834     (save-excursion
835       (set-buffer (setq gnus-dribble-buffer
836                         (gnus-get-buffer-create
837                          (file-name-nondirectory dribble-file))))
838       (erase-buffer)
839       (setq buffer-file-name dribble-file)
840       (auto-save-mode t)
841       (buffer-disable-undo)
842       (bury-buffer (current-buffer))
843       (set-buffer-modified-p nil)
844       (let ((auto (make-auto-save-file-name))
845             (gnus-dribble-ignore t)
846             (purpose nil)
847             modes)
848         (when (or (file-exists-p auto) (file-exists-p dribble-file))
849           ;; Load whichever file is newest -- the auto save file
850           ;; or the "real" file.
851           (if (file-newer-than-file-p auto dribble-file)
852               (nnheader-insert-file-contents auto)
853             (nnheader-insert-file-contents dribble-file))
854           (unless (zerop (buffer-size))
855             (set-buffer-modified-p t))
856           ;; Set the file modes to reflect the .newsrc file modes.
857           (save-buffer)
858           (when (and (file-exists-p gnus-current-startup-file)
859                      (file-exists-p dribble-file)
860                      (setq modes (file-modes gnus-current-startup-file)))
861             (set-file-modes dribble-file modes))
862           (goto-char (point-min))
863           (when (search-forward "Gnus was exited on purpose" nil t)
864             (setq purpose t))
865           ;; Possibly eval the file later.
866           (when (or gnus-always-read-dribble-file
867                     (gnus-y-or-n-p
868                      (if purpose
869                          "Gnus exited on purpose without saving; read auto-save file anyway? "
870                      "Gnus auto-save file exists.  Do you want to read it? ")))
871             (setq gnus-dribble-eval-file t)))))))
872
873 (defun gnus-dribble-eval-file ()
874   (when gnus-dribble-eval-file
875     (setq gnus-dribble-eval-file nil)
876     (save-excursion
877       (let ((gnus-dribble-ignore t))
878         (set-buffer gnus-dribble-buffer)
879         (eval-buffer (current-buffer))))))
880
881 (defun gnus-dribble-delete-file ()
882   (when (file-exists-p (gnus-dribble-file-name))
883     (delete-file (gnus-dribble-file-name)))
884   (when gnus-dribble-buffer
885     (save-excursion
886       (set-buffer gnus-dribble-buffer)
887       (let ((auto (make-auto-save-file-name)))
888         (when (file-exists-p auto)
889           (delete-file auto))
890         (erase-buffer)
891         (set-buffer-modified-p nil)))))
892
893 (defun gnus-dribble-save ()
894   (when (and gnus-dribble-buffer
895              (buffer-name gnus-dribble-buffer))
896     (save-excursion
897       (set-buffer gnus-dribble-buffer)
898       (save-buffer))))
899
900 (defun gnus-dribble-clear ()
901   (when (gnus-buffer-exists-p gnus-dribble-buffer)
902     (save-excursion
903       (set-buffer gnus-dribble-buffer)
904       (erase-buffer)
905       (set-buffer-modified-p nil)
906       (setq buffer-saved-size (buffer-size)))))
907
908 \f
909 ;;;
910 ;;; Active & Newsrc File Handling
911 ;;;
912
913 (defun gnus-setup-news (&optional rawfile level dont-connect)
914   "Setup news information.
915 If RAWFILE is non-nil, the .newsrc file will also be read.
916 If LEVEL is non-nil, the news will be set up at level LEVEL."
917   (require 'nnmail)
918   (let ((init (not (and gnus-newsrc-alist gnus-active-hashtb (not rawfile))))
919         ;; Binding this variable will inhibit multiple fetchings
920         ;; of the same mail source.
921         (nnmail-fetched-sources (list t)))
922
923     (when init
924       ;; Clear some variables to re-initialize news information.
925       (setq gnus-newsrc-alist nil
926             gnus-active-hashtb nil)
927       ;; Read the newsrc file and create `gnus-newsrc-hashtb'.
928       (gnus-read-newsrc-file rawfile))
929
930     ;; Make sure the archive server is available to all and sundry.
931     (when gnus-message-archive-method
932       (unless (assoc "archive" gnus-server-alist)
933         (push `("archive"
934                 nnfolder
935                 "archive"
936                 (nnfolder-directory
937                  ,(nnheader-concat message-directory "archive"))
938                 (nnfolder-active-file
939                  ,(nnheader-concat message-directory "archive/active"))
940                 (nnfolder-get-new-mail nil)
941                 (nnfolder-inhibit-expiry t))
942               gnus-server-alist)))
943
944     ;; If we don't read the complete active file, we fill in the
945     ;; hashtb here.
946     (when (or (null gnus-read-active-file)
947               (eq gnus-read-active-file 'some))
948       (gnus-update-active-hashtb-from-killed))
949
950     ;; Read the active file and create `gnus-active-hashtb'.
951     ;; If `gnus-read-active-file' is nil, then we just create an empty
952     ;; hash table.  The partial filling out of the hash table will be
953     ;; done in `gnus-get-unread-articles'.
954     (and gnus-read-active-file
955          (not level)
956          (gnus-read-active-file nil dont-connect))
957
958     (unless gnus-active-hashtb
959       (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
960
961     ;; Initialize the cache.
962     (when gnus-use-cache
963       (gnus-cache-open))
964
965     ;; Possibly eval the dribble file.
966     (and init
967          (or gnus-use-dribble-file gnus-slave)
968          (gnus-dribble-eval-file))
969
970     ;; Slave Gnusii should then clear the dribble buffer.
971     (when (and init gnus-slave)
972       (gnus-dribble-clear))
973
974     (gnus-update-format-specifications)
975
976     ;; See whether we need to read the description file.
977     (when (and (boundp 'gnus-group-line-format)
978                (stringp gnus-group-line-format)
979                (let ((case-fold-search nil))
980                  (string-match "%[-,0-9]*D" gnus-group-line-format))
981                (not gnus-description-hashtb)
982                (not dont-connect)
983                gnus-read-active-file)
984       (gnus-read-all-descriptions-files))
985
986     ;; Find new newsgroups and treat them.
987     (when (and init gnus-check-new-newsgroups (not level)
988                (gnus-check-server gnus-select-method)
989                (not gnus-slave)
990                gnus-plugged)
991       (gnus-find-new-newsgroups))
992
993     ;; Check and remove bogus newsgroups.
994     (when (and init gnus-check-bogus-newsgroups
995                gnus-read-active-file (not level)
996                (gnus-server-opened gnus-select-method))
997       (gnus-check-bogus-newsgroups))
998
999     ;; We might read in new NoCeM messages here.
1000     (when (and gnus-use-nocem
1001                (not level)
1002                (not dont-connect))
1003       (gnus-nocem-scan-groups))
1004
1005     ;; Read any slave files.
1006     (gnus-master-read-slave-newsrc)
1007
1008     ;; Find the number of unread articles in each non-dead group.
1009     (let ((gnus-read-active-file (and (not level) gnus-read-active-file)))
1010       (gnus-get-unread-articles level))))
1011
1012 (defun gnus-call-subscribe-functions (method group)
1013   "Call METHOD to subscribe GROUP.
1014 If no function returns `non-nil', call `gnus-subscribe-zombies'."
1015   (unless (cond
1016            ((functionp method)
1017             (funcall method group))
1018            ((listp method)
1019             (catch 'found
1020               (dolist (func method)
1021                 (if (funcall func group)
1022                     (throw 'found t)))
1023               nil))
1024            (t nil))
1025     (gnus-subscribe-zombies group)))
1026
1027 (defun gnus-find-new-newsgroups (&optional arg)
1028   "Search for new newsgroups and add them.
1029 Each new newsgroup will be treated with `gnus-subscribe-newsgroup-method'.
1030 The `-n' option line from .newsrc is respected.
1031
1032 With 1 C-u, use the `ask-server' method to query the server for new
1033 groups.
1034 With 2 C-u's, use most complete method possible to query the server
1035 for new groups, and subscribe the new groups as zombies."
1036   (interactive "p")
1037   (let* ((gnus-subscribe-newsgroup-method
1038           gnus-subscribe-newsgroup-method)
1039          (check (cond
1040                  ((or (and (= (or arg 1) 4)
1041                            (not (listp gnus-check-new-newsgroups)))
1042                       (null gnus-read-active-file)
1043                       (eq gnus-read-active-file 'some))
1044                   'ask-server)
1045                  ((= (or arg 1) 16)
1046                   (setq gnus-subscribe-newsgroup-method
1047                         'gnus-subscribe-zombies)
1048                   t)
1049                  (t gnus-check-new-newsgroups))))
1050     (unless (gnus-check-first-time-used)
1051       (if (or (consp check)
1052               (eq check 'ask-server))
1053           ;; Ask the server for new groups.
1054           (gnus-ask-server-for-new-groups)
1055         ;; Go through the active hashtb and look for new groups.
1056         (let ((groups 0)
1057               group new-newsgroups)
1058           (gnus-message 5 "Looking for new newsgroups...")
1059           (unless gnus-have-read-active-file
1060             (gnus-read-active-file))
1061           (setq gnus-newsrc-last-checked-date (message-make-date))
1062           (unless gnus-killed-hashtb
1063             (gnus-make-hashtable-from-killed))
1064           ;; Go though every newsgroup in `gnus-active-hashtb' and compare
1065           ;; with `gnus-newsrc-hashtb' and `gnus-killed-hashtb'.
1066           (mapatoms
1067            (lambda (sym)
1068              (if (or (null (setq group (symbol-name sym)))
1069                      (not (boundp sym))
1070                      (null (symbol-value sym))
1071                      (gnus-gethash group gnus-killed-hashtb)
1072                      (gnus-gethash group gnus-newsrc-hashtb))
1073                  ()
1074                (let ((do-sub (gnus-matches-options-n group)))
1075                  (cond
1076                   ((eq do-sub 'subscribe)
1077                    (setq groups (1+ groups))
1078                    (gnus-sethash group group gnus-killed-hashtb)
1079                    (gnus-call-subscribe-functions
1080                     gnus-subscribe-options-newsgroup-method group))
1081                   ((eq do-sub 'ignore)
1082                    nil)
1083                   (t
1084                    (setq groups (1+ groups))
1085                    (gnus-sethash group group gnus-killed-hashtb)
1086                    (if gnus-subscribe-hierarchical-interactive
1087                        (push group new-newsgroups)
1088                      (gnus-call-subscribe-functions
1089                       gnus-subscribe-newsgroup-method group)))))))
1090            gnus-active-hashtb)
1091           (when new-newsgroups
1092             (gnus-subscribe-hierarchical-interactive new-newsgroups))
1093           (if (> groups 0)
1094               (gnus-message 5 "%d new newsgroup%s arrived."
1095                             groups (if (> groups 1) "s have" " has"))
1096             (gnus-message 5 "No new newsgroups.")))))))
1097
1098 (defun gnus-matches-options-n (group)
1099   ;; Returns `subscribe' if the group is to be unconditionally
1100   ;; subscribed, `ignore' if it is to be ignored, and nil if there is
1101   ;; no match for the group.
1102
1103   ;; First we check the two user variables.
1104   (cond
1105    ((and gnus-options-subscribe
1106          (string-match gnus-options-subscribe group))
1107     'subscribe)
1108    ((and gnus-auto-subscribed-groups
1109          (string-match gnus-auto-subscribed-groups group))
1110     'subscribe)
1111    ((and gnus-options-not-subscribe
1112          (string-match gnus-options-not-subscribe group))
1113     'ignore)
1114    ;; Then we go through the list that was retrieved from the .newsrc
1115    ;; file.  This list has elements on the form
1116    ;; `(REGEXP . {ignore,subscribe})'.  The first match found (the list
1117    ;; is in the reverse order of the options line) is returned.
1118    (t
1119     (let ((regs gnus-newsrc-options-n))
1120       (while (and regs
1121                   (not (string-match (caar regs) group)))
1122         (setq regs (cdr regs)))
1123       (and regs (cdar regs))))))
1124
1125 (defun gnus-ask-server-for-new-groups ()
1126   (let* ((new-date (message-make-date))
1127          (date (or gnus-newsrc-last-checked-date new-date))
1128          (methods (cons gnus-select-method
1129                         (nconc
1130                          (when (gnus-archive-server-wanted-p)
1131                            (list "archive"))
1132                          (append
1133                           (and (consp gnus-check-new-newsgroups)
1134                                gnus-check-new-newsgroups)
1135                           gnus-secondary-select-methods))))
1136          (groups 0)
1137          group new-newsgroups got-new method hashtb
1138          gnus-override-subscribe-method)
1139     (unless gnus-killed-hashtb
1140       (gnus-make-hashtable-from-killed))
1141     ;; Go through both primary and secondary select methods and
1142     ;; request new newsgroups.
1143     (while (setq method (gnus-server-get-method nil (pop methods)))
1144       (setq new-newsgroups nil
1145             gnus-override-subscribe-method method)
1146       (when (and (gnus-check-server method)
1147                  (gnus-request-newgroups date method))
1148         (save-excursion
1149           (setq got-new t
1150                 hashtb (gnus-make-hashtable 100))
1151           (set-buffer nntp-server-buffer)
1152           ;; Enter all the new groups into a hashtable.
1153           (gnus-active-to-gnus-format method hashtb 'ignore))
1154         ;; Now all new groups from `method' are in `hashtb'.
1155         (mapatoms
1156          (lambda (group-sym)
1157            (if (or (null (setq group (symbol-name group-sym)))
1158                    (not (boundp group-sym))
1159                    (null (symbol-value group-sym))
1160                    (gnus-gethash group gnus-newsrc-hashtb)
1161                    (member group gnus-zombie-list)
1162                    (member group gnus-killed-list))
1163                ;; The group is already known.
1164                ()
1165              ;; Make this group active.
1166              (when (symbol-value group-sym)
1167                (gnus-set-active group (symbol-value group-sym)))
1168              ;; Check whether we want it or not.
1169              (let ((do-sub (gnus-matches-options-n group)))
1170                (cond
1171                 ((eq do-sub 'subscribe)
1172                  (incf groups)
1173                  (gnus-sethash group group gnus-killed-hashtb)
1174                  (gnus-call-subscribe-functions
1175                   gnus-subscribe-options-newsgroup-method group))
1176                 ((eq do-sub 'ignore)
1177                  nil)
1178                 (t
1179                  (incf groups)
1180                  (gnus-sethash group group gnus-killed-hashtb)
1181                  (if gnus-subscribe-hierarchical-interactive
1182                      (push group new-newsgroups)
1183                    (gnus-call-subscribe-functions
1184                     gnus-subscribe-newsgroup-method group)))))))
1185          hashtb))
1186       (when new-newsgroups
1187         (gnus-subscribe-hierarchical-interactive new-newsgroups)))
1188     (if (> groups 0)
1189         (gnus-message 5 "%d new newsgroup%s arrived"
1190                       groups (if (> groups 1) "s have" " has"))
1191       (gnus-message 5 "No new newsgroups"))
1192     (when got-new
1193       (setq gnus-newsrc-last-checked-date new-date))
1194     got-new))
1195
1196 (defun gnus-check-first-time-used ()
1197   (catch 'ended
1198     ;; First check if any of the following files exist.  If they do,
1199     ;; it's not the first time the user has used Gnus.
1200     (dolist (file (list (concat gnus-current-startup-file ".el")
1201                         (concat gnus-current-startup-file ".eld")
1202                         (concat gnus-startup-file ".el")
1203                         (concat gnus-startup-file ".eld")))
1204       (when (file-exists-p file)
1205         (throw 'ended nil)))
1206     (gnus-message 6 "First time user; subscribing you to default groups")
1207     (unless (gnus-read-active-file-p)
1208       (let ((gnus-read-active-file t))
1209         (gnus-read-active-file)))
1210     (setq gnus-newsrc-last-checked-date (message-make-date))
1211     ;; Subscribe to the default newsgroups.
1212     (let ((groups (or gnus-default-subscribed-newsgroups
1213                       gnus-backup-default-subscribed-newsgroups))
1214           group)
1215       (if (eq groups t)
1216           ;; If t, we subscribe (or not) all groups as if they were new.
1217           (mapatoms
1218            (lambda (sym)
1219              (when (setq group (symbol-name sym))
1220                (let ((do-sub (gnus-matches-options-n group)))
1221                  (cond
1222                   ((eq do-sub 'subscribe)
1223                    (gnus-sethash group group gnus-killed-hashtb)
1224                    (gnus-call-subscribe-functions
1225                     gnus-subscribe-options-newsgroup-method group))
1226                   ((eq do-sub 'ignore)
1227                    nil)
1228                   (t
1229                    (push group gnus-killed-list))))))
1230            gnus-active-hashtb)
1231         (dolist (group groups)
1232           ;; Only subscribe the default groups that are activated.
1233           (when (gnus-active group)
1234             (gnus-group-change-level
1235              group gnus-level-default-subscribed gnus-level-killed)))
1236         (save-excursion
1237           (set-buffer gnus-group-buffer)
1238           ;; Don't error if the group already exists. This happens when a
1239           ;; first-time user types 'F'. -- didier
1240           (gnus-group-make-help-group t))
1241         (when gnus-novice-user
1242           (gnus-message 7 "`A k' to list killed groups"))))))
1243
1244 (defun gnus-subscribe-group (group &optional previous method)
1245   "Subcribe GROUP and put it after PREVIOUS."
1246   (gnus-group-change-level
1247    (if method
1248        (list t group gnus-level-default-subscribed nil nil method)
1249      group)
1250    gnus-level-default-subscribed gnus-level-killed previous t)
1251   t)
1252
1253 ;; `gnus-group-change-level' is the fundamental function for changing
1254 ;; subscription levels of newsgroups.  This might mean just changing
1255 ;; from level 1 to 2, which is pretty trivial, from 2 to 6 or back
1256 ;; again, which subscribes/unsubscribes a group, which is equally
1257 ;; trivial.  Changing from 1-7 to 8-9 means that you kill a group, and
1258 ;; from 8-9 to 1-7 means that you remove the group from the list of
1259 ;; killed (or zombie) groups and add them to the (kinda) subscribed
1260 ;; groups.  And last but not least, moving from 8 to 9 and 9 to 8,
1261 ;; which is trivial.
1262 ;; ENTRY can either be a string (newsgroup name) or a list (if
1263 ;; FROMKILLED is t, it's a list on the format (NUM INFO-LIST),
1264 ;; otherwise it's a list in the format of the `gnus-newsrc-hashtb'
1265 ;; entries.
1266 ;; LEVEL is the new level of the group, OLDLEVEL is the old level and
1267 ;; PREVIOUS is the group (in hashtb entry format) to insert this group
1268 ;; after.
1269 (defun gnus-group-change-level (entry level &optional oldlevel
1270                                       previous fromkilled)
1271   (let (group info active num)
1272     ;; Glean what info we can from the arguments
1273     (if (consp entry)
1274         (if fromkilled (setq group (nth 1 entry))
1275           (setq group (car (nth 2 entry))))
1276       (setq group entry))
1277     (when (and (stringp entry)
1278                oldlevel
1279                (< oldlevel gnus-level-zombie))
1280       (setq entry (gnus-gethash entry gnus-newsrc-hashtb)))
1281     (if (and (not oldlevel)
1282              (consp entry))
1283         (setq oldlevel (gnus-info-level (nth 2 entry)))
1284       (setq oldlevel (or oldlevel gnus-level-killed)))
1285     (when (stringp previous)
1286       (setq previous (gnus-gethash previous gnus-newsrc-hashtb)))
1287
1288     (if (and (>= oldlevel gnus-level-zombie)
1289              (gnus-gethash group gnus-newsrc-hashtb))
1290         ;; We are trying to subscribe a group that is already
1291         ;; subscribed.
1292         ()                              ; Do nothing.
1293
1294       (unless (gnus-ephemeral-group-p group)
1295         (gnus-dribble-enter
1296          (format "(gnus-group-change-level %S %S %S %S %S)"
1297                  group level oldlevel (car (nth 2 previous)) fromkilled)))
1298
1299       ;; Then we remove the newgroup from any old structures, if needed.
1300       ;; If the group was killed, we remove it from the killed or zombie
1301       ;; list.  If not, and it is in fact going to be killed, we remove
1302       ;; it from the newsrc hash table and assoc.
1303       (cond
1304        ((>= oldlevel gnus-level-zombie)
1305         ;; oldlevel could be wrong.
1306         (setq gnus-zombie-list (delete group gnus-zombie-list))
1307         (setq gnus-killed-list (delete group gnus-killed-list)))
1308        (t
1309         (when (and (>= level gnus-level-zombie)
1310                    entry)
1311           (gnus-sethash (car (nth 2 entry)) nil gnus-newsrc-hashtb)
1312           (when (nth 3 entry)
1313             (setcdr (gnus-gethash (car (nth 3 entry))
1314                                   gnus-newsrc-hashtb)
1315                     (cdr entry)))
1316           (setcdr (cdr entry) (cdddr entry)))))
1317
1318       ;; Finally we enter (if needed) the list where it is supposed to
1319       ;; go, and change the subscription level.  If it is to be killed,
1320       ;; we enter it into the killed or zombie list.
1321       (cond
1322        ((>= level gnus-level-zombie)
1323         ;; Remove from the hash table.
1324         (gnus-sethash group nil gnus-newsrc-hashtb)
1325         ;; We do not enter foreign groups into the list of dead
1326         ;; groups.
1327         (unless (gnus-group-foreign-p group)
1328           (if (= level gnus-level-zombie)
1329               (push group gnus-zombie-list)
1330             (if (= oldlevel gnus-level-killed)
1331                 ;; Remove from active hashtb.
1332                 (unintern group gnus-active-hashtb)
1333               ;; Don't add it into killed-list if it was killed.
1334               (push group gnus-killed-list)))))
1335        (t
1336         ;; If the list is to be entered into the newsrc assoc, and
1337         ;; it was killed, we have to create an entry in the newsrc
1338         ;; hashtb format and fix the pointers in the newsrc assoc.
1339         (if (< oldlevel gnus-level-zombie)
1340             ;; It was alive, and it is going to stay alive, so we
1341             ;; just change the level and don't change any pointers or
1342             ;; hash table entries.
1343             (setcar (cdaddr entry) level)
1344           (if (listp entry)
1345               (setq info (cdr entry)
1346                     num (car entry))
1347             (setq active (gnus-active group))
1348             (setq num
1349                   (if active (- (1+ (cdr active)) (car active)) t))
1350             ;; Shorten the select method if possible, if we need to
1351             ;; store it at all (native groups).
1352             (let ((method (gnus-method-simplify
1353                            (or gnus-override-subscribe-method
1354                                (gnus-group-method group)))))
1355               (if method
1356                   (setq info (list group level nil nil method))
1357                 (setq info (list group level nil)))))
1358           (unless previous
1359             (setq previous
1360                   (let ((p gnus-newsrc-alist))
1361                     (while (cddr p)
1362                       (setq p (cdr p)))
1363                     p)))
1364           (setq entry (cons info (cddr previous)))
1365           (if (cdr previous)
1366               (progn
1367                 (setcdr (cdr previous) entry)
1368                 (gnus-sethash group (cons num (cdr previous))
1369                               gnus-newsrc-hashtb))
1370             (setcdr previous entry)
1371             (gnus-sethash group (cons num previous)
1372                           gnus-newsrc-hashtb))
1373           (when (cdr entry)
1374             (setcdr (gnus-gethash (caadr entry) gnus-newsrc-hashtb) entry))
1375           (gnus-dribble-enter
1376            (format
1377             "(gnus-group-set-info '%S)" info)))))
1378       (when gnus-group-change-level-function
1379         (funcall gnus-group-change-level-function
1380                  group level oldlevel previous)))))
1381
1382 (defun gnus-kill-newsgroup (newsgroup)
1383   "Obsolete function.  Kills a newsgroup."
1384   (gnus-group-change-level
1385    (gnus-gethash newsgroup gnus-newsrc-hashtb) gnus-level-killed))
1386
1387 (defun gnus-check-bogus-newsgroups (&optional confirm)
1388   "Remove bogus newsgroups.
1389 If CONFIRM is non-nil, the user has to confirm the deletion of every
1390 newsgroup."
1391   (let ((newsrc (cdr gnus-newsrc-alist))
1392         bogus group entry info)
1393     (gnus-message 5 "Checking bogus newsgroups...")
1394     (unless (gnus-read-active-file-p)
1395       (gnus-read-active-file t))
1396     (when (gnus-read-active-file-p)
1397       ;; Find all bogus newsgroup that are subscribed.
1398       (while newsrc
1399         (setq info (pop newsrc)
1400               group (gnus-info-group info))
1401         (unless (or (gnus-active group) ; Active
1402                     (and (gnus-info-method info)
1403                          (not (gnus-secondary-method-p
1404                                (gnus-info-method info))))) ; Foreign
1405           ;; Found a bogus newsgroup.
1406           (push group bogus)))
1407       (if confirm
1408           (map-y-or-n-p
1409            "Remove bogus group %s? "
1410            (lambda (group)
1411              ;; Remove all bogus subscribed groups by first killing them, and
1412              ;; then removing them from the list of killed groups.
1413              (when (setq entry (gnus-gethash group gnus-newsrc-hashtb))
1414                (gnus-group-change-level entry gnus-level-killed)
1415                (setq gnus-killed-list (delete group gnus-killed-list))))
1416            bogus '("group" "groups" "remove"))
1417         (while (setq group (pop bogus))
1418           ;; Remove all bogus subscribed groups by first killing them, and
1419           ;; then removing them from the list of killed groups.
1420           (when (setq entry (gnus-gethash group gnus-newsrc-hashtb))
1421             (gnus-group-change-level entry gnus-level-killed)
1422             (setq gnus-killed-list (delete group gnus-killed-list)))))
1423       ;; Then we remove all bogus groups from the list of killed and
1424       ;; zombie groups.  They are removed without confirmation.
1425       (let ((dead-lists '(gnus-killed-list gnus-zombie-list))
1426             killed)
1427         (while dead-lists
1428           (setq killed (symbol-value (car dead-lists)))
1429           (while killed
1430             (unless (gnus-active (setq group (pop killed)))
1431               ;; The group is bogus.
1432               ;; !!!Slow as hell.
1433               (set (car dead-lists)
1434                    (delete group (symbol-value (car dead-lists))))))
1435           (setq dead-lists (cdr dead-lists))))
1436       (gnus-run-hooks 'gnus-check-bogus-groups-hook)
1437       (gnus-message 5 "Checking bogus newsgroups...done"))))
1438
1439 (defun gnus-check-duplicate-killed-groups ()
1440   "Remove duplicates from the list of killed groups."
1441   (interactive)
1442   (let ((killed gnus-killed-list))
1443     (while killed
1444       (gnus-message 9 "%d" (length killed))
1445       (setcdr killed (delete (car killed) (cdr killed)))
1446       (setq killed (cdr killed)))))
1447
1448 ;; We want to inline a function from gnus-cache, so we cheat here:
1449 (eval-when-compile
1450   (defvar gnus-cache-active-hashtb)
1451   (defun gnus-cache-possibly-alter-active (group active)
1452     "Alter the ACTIVE info for GROUP to reflect the articles in the cache."
1453     (when gnus-cache-active-hashtb
1454       (let ((cache-active (gnus-gethash group gnus-cache-active-hashtb)))
1455         (when cache-active
1456           (when (< (car cache-active) (car active))
1457             (setcar active (car cache-active)))
1458           (when (> (cdr cache-active) (cdr active))
1459             (setcdr active (cdr cache-active))))))))
1460
1461 (defun gnus-activate-group (group &optional scan dont-check method)
1462   ;; Check whether a group has been activated or not.
1463   ;; If SCAN, request a scan of that group as well.
1464   (let ((method (or method (inline (gnus-find-method-for-group group))))
1465         active)
1466     (and (inline (gnus-check-server method))
1467          ;; We escape all bugs and quit here to make it possible to
1468          ;; continue if a group is so out-there that it reports bugs
1469          ;; and stuff.
1470          (progn
1471            (and scan
1472                 (gnus-check-backend-function 'request-scan (car method))
1473                 (gnus-request-scan group method))
1474            t)
1475          (if (or debug-on-error debug-on-quit)
1476              (inline (gnus-request-group group dont-check method))
1477            (condition-case nil
1478                (inline (gnus-request-group group dont-check method))
1479              ;;(error nil)
1480              (quit
1481               (message "Quit activating %s" group)
1482               nil)))
1483          (unless dont-check
1484            (setq active (gnus-parse-active))
1485            ;; If there are no articles in the group, the GROUP
1486            ;; command may have responded with the `(0 . 0)'.  We
1487            ;; ignore this if we already have an active entry
1488            ;; for the group.
1489            (if (and (zerop (car active))
1490                     (zerop (cdr active))
1491                     (gnus-active group))
1492                (gnus-active group)
1493              (gnus-set-active group active)
1494              ;; Return the new active info.
1495              active)))))
1496
1497 (defun gnus-get-unread-articles-in-group (info active &optional update)
1498   (when active
1499     ;; Allow the backend to update the info in the group.
1500     (when (and update
1501                (gnus-request-update-info
1502                 info (inline (gnus-find-method-for-group
1503                               (gnus-info-group info)))))
1504       (gnus-activate-group (gnus-info-group info) nil t))
1505
1506     (let* ((range (gnus-info-read info))
1507            (num 0))
1508       ;; If a cache is present, we may have to alter the active info.
1509       (when (and gnus-use-cache info)
1510         (inline (gnus-cache-possibly-alter-active
1511                  (gnus-info-group info) active)))
1512       ;; Modify the list of read articles according to what articles
1513       ;; are available; then tally the unread articles and add the
1514       ;; number to the group hash table entry.
1515       (cond
1516        ((zerop (cdr active))
1517         (setq num 0))
1518        ((not range)
1519         (setq num (- (1+ (cdr active)) (car active))))
1520        ((not (listp (cdr range)))
1521         ;; Fix a single (num . num) range according to the
1522         ;; active hash table.
1523         ;; Fix by Carsten Bormann <cabo@Informatik.Uni-Bremen.DE>.
1524         (and (< (cdr range) (car active)) (setcdr range (1- (car active))))
1525         (and (> (cdr range) (cdr active)) (setcdr range (cdr active)))
1526         ;; Compute number of unread articles.
1527         (setq num (max 0 (- (cdr active) (- (1+ (cdr range)) (car range))))))
1528        (t
1529         ;; The read list is a list of ranges.  Fix them according to
1530         ;; the active hash table.
1531         ;; First peel off any elements that are below the lower
1532         ;; active limit.
1533         (while (and (cdr range)
1534                     (>= (car active)
1535                         (or (and (atom (cadr range)) (cadr range))
1536                             (caadr range))))
1537           (if (numberp (car range))
1538               (setcar range
1539                       (cons (car range)
1540                             (or (and (numberp (cadr range))
1541                                      (cadr range))
1542                                 (cdadr range))))
1543             (setcdr (car range)
1544                     (or (and (numberp (nth 1 range)) (nth 1 range))
1545                         (cdadr range))))
1546           (setcdr range (cddr range)))
1547         ;; Adjust the first element to be the same as the lower limit.
1548         (when (and (not (atom (car range)))
1549                    (< (cdar range) (car active)))
1550           (setcdr (car range) (1- (car active))))
1551         ;; Then we want to peel off any elements that are higher
1552         ;; than the upper active limit.
1553         (let ((srange range))
1554           ;; Go past all valid elements.
1555           (while (and (cdr srange)
1556                       (<= (or (and (atom (cadr srange))
1557                                    (cadr srange))
1558                               (caadr srange))
1559                           (cdr active)))
1560             (setq srange (cdr srange)))
1561           (when (cdr srange)
1562             ;; Nuke all remaining invalid elements.
1563             (setcdr srange nil))
1564
1565           ;; Adjust the final element.
1566           (when (and (not (atom (car srange)))
1567                      (> (cdar srange) (cdr active)))
1568             (setcdr (car srange) (cdr active))))
1569         ;; Compute the number of unread articles.
1570         (while range
1571           (setq num (+ num (- (1+ (or (and (atom (car range)) (car range))
1572                                       (cdar range)))
1573                               (or (and (atom (car range)) (car range))
1574                                   (caar range)))))
1575           (setq range (cdr range)))
1576         (setq num (max 0 (- (cdr active) num)))))
1577       ;; Set the number of unread articles.
1578       (when (and info
1579                  (gnus-gethash (gnus-info-group info) gnus-newsrc-hashtb))
1580         (setcar (gnus-gethash (gnus-info-group info) gnus-newsrc-hashtb) num))
1581       num)))
1582
1583 ;; Go though `gnus-newsrc-alist' and compare with `gnus-active-hashtb'
1584 ;; and compute how many unread articles there are in each group.
1585 (defun gnus-get-unread-articles (&optional level)
1586   (setq gnus-server-method-cache nil)
1587   (let* ((newsrc (cdr gnus-newsrc-alist))
1588          (level (or level gnus-activate-level (1+ gnus-level-subscribed)))
1589          (foreign-level
1590           (min
1591            (cond ((and gnus-activate-foreign-newsgroups
1592                        (not (numberp gnus-activate-foreign-newsgroups)))
1593                   (1+ gnus-level-subscribed))
1594                  ((numberp gnus-activate-foreign-newsgroups)
1595                   gnus-activate-foreign-newsgroups)
1596                  (t 0))
1597            level))
1598          scanned-methods info group active method retrieve-groups)
1599     (gnus-message 6 "Checking new news...")
1600
1601     (while newsrc
1602       (setq active (gnus-active (setq group (gnus-info-group
1603                                              (setq info (pop newsrc))))))
1604
1605       ;; Check newsgroups.  If the user doesn't want to check them, or
1606       ;; they can't be checked (for instance, if the news server can't
1607       ;; be reached) we just set the number of unread articles in this
1608       ;; newsgroup to t.  This means that Gnus thinks that there are
1609       ;; unread articles, but it has no idea how many.
1610
1611       ;; To be more explicit:
1612       ;; >0 for an active group with messages
1613       ;; 0 for an active group with no unread messages
1614       ;; nil for non-foreign groups that the user has requested not be checked
1615       ;; t for unchecked foreign groups or bogus groups, or groups that can't
1616       ;;   be checked, for one reason or other.
1617       (if (and (setq method (gnus-info-method info))
1618                (not (inline
1619                       (gnus-server-equal
1620                        gnus-select-method
1621                        (setq method (gnus-server-get-method nil method)))))
1622                (not (gnus-secondary-method-p method)))
1623           ;; These groups are foreign.  Check the level.
1624           (when (and (<= (gnus-info-level info) foreign-level)
1625                      (setq active (gnus-activate-group group 'scan)))
1626             ;; Let the Gnus agent save the active file.
1627             (when (and gnus-agent active (gnus-online method))
1628               (gnus-agent-save-group-info
1629                method (gnus-group-real-name group) active))
1630             (unless (inline (gnus-virtual-group-p group))
1631               (inline (gnus-close-group group)))
1632             (when (fboundp (intern (concat (symbol-name (car method))
1633                                            "-request-update-info")))
1634               (inline (gnus-request-update-info info method))))
1635         ;; These groups are native or secondary.
1636         (cond
1637          ;; We don't want these groups.
1638          ((> (gnus-info-level info) level)
1639           (setq active 'ignore))
1640          ;; Activate groups.
1641          ((not gnus-read-active-file)
1642           (if (gnus-check-backend-function 'retrieve-groups group)
1643               ;; if server support gnus-retrieve-groups we push
1644               ;; the group onto retrievegroups for later checking
1645               (if (assoc method retrieve-groups)
1646                   (setcdr (assoc method retrieve-groups)
1647                           (cons group (cdr (assoc method retrieve-groups))))
1648                 (push (list method group) retrieve-groups))
1649             ;; hack: `nnmail-get-new-mail' changes the mail-source depending
1650             ;; on the group, so we must perform a scan for every group
1651             ;; if the users has any directory mail sources.
1652             ;; hack: if `nnmail-scan-directory-mail-source-once' is non-nil,
1653             ;; for it scan all spool files even when the groups are
1654             ;; not required.
1655             (if (and
1656                  (or nnmail-scan-directory-mail-source-once
1657                      (null (assq 'directory
1658                                  (or mail-sources
1659                                      (if (listp nnmail-spool-file)
1660                                          nnmail-spool-file
1661                                        (list nnmail-spool-file))))))
1662                  (member method scanned-methods))
1663                 (setq active (gnus-activate-group group))
1664               (setq active (gnus-activate-group group 'scan))
1665               (push method scanned-methods))
1666             (when active
1667               (gnus-close-group group))))))
1668
1669       ;; Get the number of unread articles in the group.
1670       (cond
1671        ((eq active 'ignore)
1672         ;; Don't do anything.
1673         )
1674        (active
1675         (inline (gnus-get-unread-articles-in-group info active t)))
1676        (t
1677         ;; The group couldn't be reached, so we nix out the number of
1678         ;; unread articles and stuff.
1679         (gnus-set-active group nil)
1680         (let ((tmp (gnus-gethash group gnus-newsrc-hashtb)))
1681           (when tmp
1682             (setcar tmp t))))))
1683
1684     ;; iterate through groups on methods which support gnus-retrieve-groups
1685     ;; and fetch a partial active file and use it to find new news.
1686     (dolist (rg retrieve-groups)
1687       (let ((method (or (car rg) gnus-select-method))
1688             (groups (cdr rg)))
1689         (when (gnus-check-server method)
1690           ;; Request that the backend scan its incoming messages.
1691           (when (gnus-check-backend-function 'request-scan (car method))
1692             (gnus-request-scan nil method))
1693           (gnus-read-active-file-2
1694            (mapcar (lambda (group) (gnus-group-real-name group)) groups)
1695            method)
1696           (dolist (group groups)
1697             (cond
1698              ((setq active (gnus-active (gnus-info-group
1699                                          (setq info (gnus-get-info group)))))
1700               (inline (gnus-get-unread-articles-in-group info active t)))
1701              (t
1702               ;; The group couldn't be reached, so we nix out the number of
1703               ;; unread articles and stuff.
1704               (gnus-set-active group nil)
1705               (setcar (gnus-gethash group gnus-newsrc-hashtb) t)))))))
1706
1707     (gnus-message 6 "Checking new news...done")))
1708
1709 ;; Create a hash table out of the newsrc alist.  The `car's of the
1710 ;; alist elements are used as keys.
1711 (defun gnus-make-hashtable-from-newsrc-alist ()
1712   (let ((alist gnus-newsrc-alist)
1713         (ohashtb gnus-newsrc-hashtb)
1714         prev)
1715     (setq gnus-newsrc-hashtb (gnus-make-hashtable (length alist)))
1716     (setq alist
1717           (setq prev (setq gnus-newsrc-alist
1718                            (if (equal (caar gnus-newsrc-alist)
1719                                       "dummy.group")
1720                                gnus-newsrc-alist
1721                              (cons (list "dummy.group" 0 nil) alist)))))
1722     (while alist
1723       (gnus-sethash
1724        (caar alist)
1725        ;; Preserve number of unread articles in groups.
1726        (cons (and ohashtb (car (gnus-gethash (caar alist) ohashtb)))
1727              prev)
1728        gnus-newsrc-hashtb)
1729       (setq prev alist
1730             alist (cdr alist)))))
1731
1732 (defun gnus-make-hashtable-from-killed ()
1733   "Create a hash table from the killed and zombie lists."
1734   (let ((lists '(gnus-killed-list gnus-zombie-list))
1735         list)
1736     (setq gnus-killed-hashtb
1737           (gnus-make-hashtable
1738            (+ (length gnus-killed-list) (length gnus-zombie-list))))
1739     (while lists
1740       (setq list (symbol-value (pop lists)))
1741       (while list
1742         (gnus-sethash (car list) (pop list) gnus-killed-hashtb)))))
1743
1744 (defun gnus-parse-active ()
1745   "Parse active info in the nntp server buffer."
1746   (save-excursion
1747     (set-buffer nntp-server-buffer)
1748     (goto-char (point-min))
1749     ;; Parse the result we got from `gnus-request-group'.
1750     (when (looking-at "[0-9]+ [0-9]+ \\([0-9]+\\) [0-9]+")
1751       (goto-char (match-beginning 1))
1752       (cons (read (current-buffer))
1753             (read (current-buffer))))))
1754
1755 (defun gnus-make-articles-unread (group articles)
1756   "Mark ARTICLES in GROUP as unread."
1757   (let* ((info (nth 2 (or (gnus-gethash group gnus-newsrc-hashtb)
1758                           (gnus-gethash (gnus-group-real-name group)
1759                                         gnus-newsrc-hashtb))))
1760          (ranges (gnus-info-read info))
1761          news article)
1762     (while articles
1763       (when (gnus-member-of-range
1764              (setq article (pop articles)) ranges)
1765         (push article news)))
1766     (when news
1767       ;; Enter this list into the group info.
1768       (gnus-info-set-read
1769        info (gnus-remove-from-range (gnus-info-read info) (nreverse news)))
1770
1771       ;; Set the number of unread articles in gnus-newsrc-hashtb.
1772       (gnus-get-unread-articles-in-group info (gnus-active group))
1773
1774       ;; Insert the change into the group buffer and the dribble file.
1775       (gnus-group-update-group group t))))
1776
1777 (defun gnus-make-ascending-articles-unread (group articles)
1778   "Mark ascending ARTICLES in GROUP as unread."
1779   (let* ((entry (or (gnus-gethash group gnus-newsrc-hashtb)
1780                     (gnus-gethash (gnus-group-real-name group)
1781                                   gnus-newsrc-hashtb)))
1782          (info (nth 2 entry))
1783          (ranges (gnus-info-read info))
1784          (r ranges)
1785          modified)
1786
1787     (while articles
1788       (let ((article (pop articles))) ; get the next article to remove from ranges
1789         (while (let ((range (car ranges))) ; note the current range
1790                  (if (atom range)       ; single value range
1791                      (cond ((not range)
1792                             ;; the articles extend past the end of the ranges
1793                             ;; OK - I'm done
1794                             (setq articles nil))
1795                            ((< range article)
1796                             ;; this range preceeds the article. Leave the range unmodified.
1797                             (pop ranges)
1798                             ranges)
1799                            ((= range article)
1800                             ;; this range exactly matches the article; REMOVE THE RANGE.
1801                             ;; NOTE: When the range being removed is the last range, the list is corrupted by inserting null at its end.
1802                             (setcar ranges (cadr ranges))
1803                             (setcdr ranges (cddr ranges))
1804                             (setq modified (if (car ranges) t 'remove-null))
1805                             nil))
1806                    (let ((min (car range))
1807                          (max (cdr range)))
1808                      ;; I have a min/max range to consider
1809                      (cond ((> min max) ; invalid range introduced by splitter
1810                             (setcar ranges (cadr ranges))
1811                             (setcdr ranges (cddr ranges))
1812                             (setq modified (if (car ranges) t 'remove-null))
1813                             ranges)
1814                            ((= min max)
1815                             ;; replace min/max range with a single-value range
1816                             (setcar ranges min)
1817                             ranges)
1818                            ((< max article)
1819                             ;; this range preceeds the article. Leave the range unmodified.
1820                             (pop ranges)
1821                             ranges)
1822                            ((< article min)
1823                             ;; this article preceeds the range.  Return null to move to the
1824                             ;; next article
1825                             nil)
1826                            (t
1827                             ;; this article splits the range into two parts
1828                             (setcdr ranges (cons (cons (1+ article) max) (cdr ranges)))
1829                             (setcdr range (1- article))
1830                             (setq modified t)
1831                             ranges))))))))
1832                   
1833     (when modified
1834       (when (eq modified 'remove-null)
1835         (setq r (delq nil r)))
1836       ;; Enter this list into the group info.
1837       (gnus-info-set-read info r)
1838
1839       ;; Set the number of unread articles in gnus-newsrc-hashtb.
1840       (gnus-get-unread-articles-in-group info (gnus-active group))
1841
1842       ;; Insert the change into the group buffer and the dribble file.
1843       (gnus-group-update-group group t))))
1844
1845 ;; Enter all dead groups into the hashtb.
1846 (defun gnus-update-active-hashtb-from-killed ()
1847   (let ((hashtb (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
1848         (lists (list gnus-killed-list gnus-zombie-list))
1849         killed)
1850     (while lists
1851       (setq killed (car lists))
1852       (while killed
1853         (gnus-sethash (car killed) nil hashtb)
1854         (setq killed (cdr killed)))
1855       (setq lists (cdr lists)))))
1856
1857 (defun gnus-get-killed-groups ()
1858   "Go through the active hashtb and mark all unknown groups as killed."
1859   ;; First make sure active file has been read.
1860   (unless (gnus-read-active-file-p)
1861     (let ((gnus-read-active-file t))
1862       (gnus-read-active-file)))
1863   (unless gnus-killed-hashtb
1864     (gnus-make-hashtable-from-killed))
1865   ;; Go through all newsgroups that are known to Gnus - enlarge kill list.
1866   (mapatoms
1867    (lambda (sym)
1868      (let ((groups 0)
1869            (group (symbol-name sym)))
1870        (if (or (null group)
1871                (gnus-gethash group gnus-killed-hashtb)
1872                (gnus-gethash group gnus-newsrc-hashtb))
1873            ()
1874          (let ((do-sub (gnus-matches-options-n group)))
1875            (if (or (eq do-sub 'subscribe) (eq do-sub 'ignore))
1876                ()
1877              (setq groups (1+ groups))
1878              (push group gnus-killed-list)
1879              (gnus-sethash group group gnus-killed-hashtb))))))
1880    gnus-active-hashtb)
1881   (gnus-dribble-touch))
1882
1883 ;; Get the active file(s) from the backend(s).
1884 (defun gnus-read-active-file (&optional force not-native)
1885   (gnus-group-set-mode-line)
1886   (let ((methods
1887          (mapcar
1888           (lambda (m) (if (stringp m) (gnus-server-get-method nil m) m))
1889           (append
1890            (if (and (not not-native)
1891                     (gnus-check-server gnus-select-method))
1892                ;; The native server is available.
1893                (cons gnus-select-method gnus-secondary-select-methods)
1894              ;; The native server is down, so we just do the
1895              ;; secondary ones.
1896              gnus-secondary-select-methods)
1897            ;; Also read from the archive server.
1898            (when (gnus-archive-server-wanted-p)
1899              (list "archive")))))
1900         method)
1901     (setq gnus-have-read-active-file nil)
1902     (save-excursion
1903       (set-buffer nntp-server-buffer)
1904       (while (setq method (pop methods))
1905         ;; Only do each method once, in case the methods appear more
1906         ;; than once in this list.
1907         (unless (member method methods)
1908           (if (or debug-on-error debug-on-quit)
1909               (gnus-read-active-file-1 method force)
1910             (condition-case ()
1911                 (gnus-read-active-file-1 method force)
1912               ;; We catch C-g so that we can continue past servers
1913               ;; that do not respond.
1914               (quit
1915                (message "Quit reading the active file")
1916                nil))))))))
1917
1918 (defun gnus-read-active-file-1 (method force)
1919   (let (where mesg)
1920     (setq where (nth 1 method)
1921           mesg (format "Reading active file%s via %s..."
1922                        (if (and where (not (zerop (length where))))
1923                            (concat " from " where) "")
1924                        (car method)))
1925     (gnus-message 5 mesg)
1926     (when (gnus-check-server method)
1927       ;; Request that the backend scan its incoming messages.
1928       (when (gnus-check-backend-function 'request-scan (car method))
1929         (gnus-request-scan nil method))
1930       (cond
1931        ((and (eq gnus-read-active-file 'some)
1932              (gnus-check-backend-function 'retrieve-groups (car method))
1933              (not force))
1934         (let ((newsrc (cdr gnus-newsrc-alist))
1935               (gmethod (gnus-server-get-method nil method))
1936               groups info)
1937           (while (setq info (pop newsrc))
1938             (when (inline
1939                     (gnus-server-equal
1940                      (inline
1941                        (gnus-find-method-for-group
1942                         (gnus-info-group info) info))
1943                      gmethod))
1944               (push (gnus-group-real-name (gnus-info-group info))
1945                     groups)))
1946           (gnus-read-active-file-2 groups method)))
1947        ((null method)
1948         t)
1949        (t
1950         (if (not (gnus-request-list method))
1951             (unless (equal method gnus-message-archive-method)
1952               (gnus-error 1 "Cannot read active file from %s server"
1953                           (car method)))
1954           (gnus-message 5 mesg)
1955           (gnus-active-to-gnus-format method gnus-active-hashtb nil t)
1956           ;; We mark this active file as read.
1957           (push method gnus-have-read-active-file)
1958           (gnus-message 5 "%sdone" mesg)))))))
1959
1960 (defun gnus-read-active-file-2 (groups method)
1961   "Read an active file for GROUPS in METHOD using gnus-retrieve-groups."
1962   (when groups
1963     (save-excursion
1964       (set-buffer nntp-server-buffer)
1965       (gnus-check-server method)
1966       (let ((list-type (gnus-retrieve-groups groups method)))
1967         (cond ((not list-type)
1968                (gnus-error
1969                 1.2 "Cannot read partial active file from %s server."
1970                 (car method)))
1971               ((eq list-type 'active)
1972                (gnus-active-to-gnus-format method gnus-active-hashtb nil t))
1973               (t
1974                (gnus-groups-to-gnus-format method gnus-active-hashtb t)))))))
1975
1976 ;; Read an active file and place the results in `gnus-active-hashtb'.
1977 (defun gnus-active-to-gnus-format (&optional method hashtb ignore-errors
1978                                              real-active)
1979   (unless method
1980     (setq method gnus-select-method))
1981   (let ((cur (current-buffer))
1982         (hashtb (or hashtb
1983                     (if (and gnus-active-hashtb
1984                              (not (equal method gnus-select-method)))
1985                         gnus-active-hashtb
1986                       (setq gnus-active-hashtb
1987                             (if (equal method gnus-select-method)
1988                                 (gnus-make-hashtable
1989                                  (count-lines (point-min) (point-max)))
1990                               (gnus-make-hashtable 4096)))))))
1991     ;; Delete unnecessary lines.
1992     (goto-char (point-min))
1993     (cond
1994      ((string= gnus-ignored-newsgroups "")
1995       (delete-matching-lines "^to\\."))
1996      (t
1997       (delete-matching-lines (concat "^to\\.\\|" gnus-ignored-newsgroups))))
1998
1999     (goto-char (point-min))
2000     (unless (re-search-forward "[\\\"]" nil t)
2001       ;; Make the group names readable as a lisp expression even if they
2002       ;; contain special characters.
2003       (goto-char (point-max))
2004       (while (re-search-backward "[][';?()#]" nil t)
2005         (insert ?\\)))
2006
2007     ;; Let the Gnus agent save the active file.
2008     (when (and gnus-agent real-active (gnus-online method))
2009       (gnus-agent-save-active method))
2010
2011     ;; If these are groups from a foreign select method, we insert the
2012     ;; group prefix in front of the group names.
2013     (when (not (gnus-server-equal
2014                 (gnus-server-get-method nil method)
2015                 (gnus-server-get-method nil gnus-select-method)))
2016       (let ((prefix (gnus-group-prefixed-name "" method)))
2017         (goto-char (point-min))
2018         (while (and (not (eobp))
2019                     (progn
2020                       (when (= (following-char) ?\")
2021                         (forward-char 1))
2022                       (insert prefix)
2023                       (zerop (forward-line 1)))))))
2024     ;; Store the active file in a hash table.
2025     (goto-char (point-min))
2026     (let (group max min)
2027       (while (not (eobp))
2028         (condition-case ()
2029             (progn
2030               (narrow-to-region (point) (gnus-point-at-eol))
2031               ;; group gets set to a symbol interned in the hash table
2032               ;; (what a hack!!) - jwz
2033               (setq group (let ((obarray hashtb)) (read cur)))
2034               ;; ### The extended group name scheme makes
2035               ;; the previous optimization strategy sort of pointless...
2036               (when (stringp group)
2037                 (setq group (intern group hashtb)))
2038               (if (and (numberp (setq max (read cur)))
2039                        (numberp (setq min (read cur)))
2040                        (progn
2041                          (skip-chars-forward " \t")
2042                          (not
2043                           (or (eq (char-after) ?=)
2044                               (eq (char-after) ?x)
2045                               (eq (char-after) ?j)))))
2046                   (progn
2047                     (set group (cons min max))
2048                     ;; if group is moderated, stick in moderation table
2049                     (when (eq (char-after) ?m)
2050                       (unless gnus-moderated-hashtb
2051                         (setq gnus-moderated-hashtb (gnus-make-hashtable)))
2052                       (gnus-sethash (symbol-name group) t
2053                                     gnus-moderated-hashtb)))
2054                 (set group nil)))
2055           (error
2056            (and group
2057                 (symbolp group)
2058                 (set group nil))
2059            (unless ignore-errors
2060              (gnus-message 3 "Warning - invalid active: %s"
2061                            (buffer-substring
2062                             (gnus-point-at-bol) (gnus-point-at-eol))))))
2063         (widen)
2064         (forward-line 1)))))
2065
2066 (defun gnus-groups-to-gnus-format (method &optional hashtb real-active)
2067   ;; Parse a "groups" active file.
2068   (let ((cur (current-buffer))
2069         (hashtb (or hashtb
2070                     (if (and method gnus-active-hashtb)
2071                         gnus-active-hashtb
2072                       (setq gnus-active-hashtb
2073                             (gnus-make-hashtable
2074                              (count-lines (point-min) (point-max)))))))
2075         (prefix (and method
2076                      (not (gnus-server-equal
2077                            (gnus-server-get-method nil method)
2078                            (gnus-server-get-method nil gnus-select-method)))
2079                      (gnus-group-prefixed-name "" method))))
2080
2081     ;; Let the Gnus agent save the active file.
2082     (if (and gnus-agent
2083              real-active
2084              (gnus-online method)
2085              (gnus-agent-method-p method))
2086         (progn
2087           (gnus-agent-save-groups method)
2088           (gnus-active-to-gnus-format method hashtb nil real-active))
2089
2090       (goto-char (point-min))
2091       ;; We split this into to separate loops, one with the prefix
2092       ;; and one without to speed the reading up somewhat.
2093       (if prefix
2094           (let (min max opoint group)
2095             (while (not (eobp))
2096               (condition-case ()
2097                   (progn
2098                     (read cur) (read cur)
2099                     (setq min (read cur)
2100                           max (read cur)
2101                           opoint (point))
2102                     (skip-chars-forward " \t")
2103                     (insert prefix)
2104                     (goto-char opoint)
2105                     (set (let ((obarray hashtb)) (read cur))
2106                          (cons min max)))
2107                 (error (and group (symbolp group) (set group nil))))
2108               (forward-line 1)))
2109         (let (min max group)
2110           (while (not (eobp))
2111             (condition-case ()
2112                 (when (eq (char-after) ?2)
2113                   (read cur) (read cur)
2114                   (setq min (read cur)
2115                         max (read cur))
2116                   (set (setq group (let ((obarray hashtb)) (read cur)))
2117                        (cons min max)))
2118               (error (and group (symbolp group) (set group nil))))
2119             (forward-line 1)))))))
2120
2121 (defun gnus-read-newsrc-file (&optional force)
2122   "Read startup file.
2123 If FORCE is non-nil, the .newsrc file is read."
2124   ;; Reset variables that might be defined in the .newsrc.eld file.
2125   (let ((variables (remove 'gnus-format-specs gnus-variable-list)))
2126     (while variables
2127       (set (car variables) nil)
2128       (setq variables (cdr variables))))
2129   (let* ((newsrc-file gnus-current-startup-file)
2130          (quick-file (concat newsrc-file ".el")))
2131     (save-excursion
2132       ;; We always load the .newsrc.eld file.  If always contains
2133       ;; much information that can not be gotten from the .newsrc
2134       ;; file (ticked articles, killed groups, foreign methods, etc.)
2135       (gnus-read-newsrc-el-file quick-file)
2136
2137       (when (and gnus-read-newsrc-file
2138                  (file-exists-p gnus-current-startup-file)
2139                  (or force
2140                      (and (file-newer-than-file-p newsrc-file quick-file)
2141                           (file-newer-than-file-p newsrc-file
2142                                                   (concat quick-file "d")))
2143                      (not gnus-newsrc-alist)))
2144         ;; We read the .newsrc file.  Note that if there if a
2145         ;; .newsrc.eld file exists, it has already been read, and
2146         ;; the `gnus-newsrc-hashtb' has been created.  While reading
2147         ;; the .newsrc file, Gnus will only use the information it
2148         ;; can find there for changing the data already read -
2149         ;; i. e., reading the .newsrc file will not trash the data
2150         ;; already read (except for read articles).
2151         (save-excursion
2152           (gnus-message 5 "Reading %s..." newsrc-file)
2153           (set-buffer (nnheader-find-file-noselect newsrc-file))
2154           (buffer-disable-undo)
2155           (gnus-newsrc-to-gnus-format)
2156           (kill-buffer (current-buffer))
2157           (gnus-message 5 "Reading %s...done" newsrc-file)))
2158
2159       ;; Convert old to new.
2160       (gnus-convert-old-newsrc))))
2161
2162 (defun gnus-convert-old-newsrc ()
2163   "Convert old newsrc into the new format, if needed."
2164   (let ((fcv (and gnus-newsrc-file-version
2165                   (gnus-continuum-version gnus-newsrc-file-version))))
2166     (cond
2167      ;; No .newsrc.eld file was loaded.
2168      ((null fcv) nil)
2169      ;; Gnus 5 .newsrc.eld was loaded.
2170      ((< fcv (gnus-continuum-version "September Gnus v0.1"))
2171       (gnus-convert-old-ticks)))))
2172
2173 (defun gnus-convert-old-ticks ()
2174   (let ((newsrc (cdr gnus-newsrc-alist))
2175         marks info dormant ticked)
2176     (while (setq info (pop newsrc))
2177       (when (setq marks (gnus-info-marks info))
2178         (setq dormant (cdr (assq 'dormant marks))
2179               ticked (cdr (assq 'tick marks)))
2180         (when (or dormant ticked)
2181           (gnus-info-set-read
2182            info
2183            (gnus-add-to-range
2184             (gnus-info-read info)
2185             (nconc (gnus-uncompress-range dormant)
2186                    (gnus-uncompress-range ticked)))))))))
2187
2188 (defun gnus-load (file)
2189   "Load FILE, but in such a way that read errors can be reported."
2190   (with-temp-buffer
2191     (insert-file-contents file)
2192     (while (not (eobp))
2193       (condition-case type
2194           (let ((form (read (current-buffer))))
2195             (eval form))
2196         (error
2197          (unless (eq (car type) 'end-of-file)
2198            (let ((error (format "Error in %s line %d" file
2199                                 (count-lines (point-min) (point)))))
2200              (ding)
2201              (unless (gnus-yes-or-no-p (concat error "; continue? "))
2202                (error "%s" error)))))))))
2203
2204 (defun gnus-read-newsrc-el-file (file)
2205   (let ((ding-file (concat file "d")))
2206     (when (file-exists-p ding-file)
2207       ;; We always, always read the .eld file.
2208       (gnus-message 5 "Reading %s..." ding-file)
2209       (let (gnus-newsrc-assoc)
2210         (let ((coding-system-for-read gnus-ding-file-coding-system))
2211           (gnus-load ding-file))
2212         ;; Older versions of `gnus-format-specs' are no longer valid
2213         ;; in Oort Gnus 0.01.
2214         (let ((version
2215                (and gnus-newsrc-file-version
2216                     (gnus-continuum-version gnus-newsrc-file-version))))
2217           (when (or (not version)
2218                     (< version 5.090009))
2219             (setq gnus-format-specs gnus-default-format-specs)))
2220         (when gnus-newsrc-assoc
2221           (setq gnus-newsrc-alist gnus-newsrc-assoc))))
2222     (gnus-make-hashtable-from-newsrc-alist)
2223     (when (file-newer-than-file-p file ding-file)
2224       ;; Old format quick file
2225       (gnus-message 5 "Reading %s..." file)
2226       ;; The .el file is newer than the .eld file, so we read that one
2227       ;; as well.
2228       (gnus-read-old-newsrc-el-file file)))
2229   (gnus-run-hooks 'gnus-read-newsrc-el-hook))
2230
2231 ;; Parse the old-style quick startup file
2232 (defun gnus-read-old-newsrc-el-file (file)
2233   (let (newsrc killed marked group m info)
2234     (prog1
2235         (let ((gnus-killed-assoc nil)
2236               gnus-marked-assoc gnus-newsrc-alist gnus-newsrc-assoc)
2237           (prog1
2238               (ignore-errors
2239                 (load file t t t))
2240             (setq newsrc gnus-newsrc-assoc
2241                   killed gnus-killed-assoc
2242                   marked gnus-marked-assoc)))
2243       (setq gnus-newsrc-alist nil)
2244       (while (setq group (pop newsrc))
2245         (if (setq info (gnus-get-info (car group)))
2246             (progn
2247               (gnus-info-set-read info (cddr group))
2248               (gnus-info-set-level
2249                info (if (nth 1 group) gnus-level-default-subscribed
2250                       gnus-level-default-unsubscribed))
2251               (push info gnus-newsrc-alist))
2252           (push (setq info
2253                       (list (car group)
2254                             (if (nth 1 group) gnus-level-default-subscribed
2255                               gnus-level-default-unsubscribed)
2256                             (cddr group)))
2257                 gnus-newsrc-alist))
2258         ;; Copy marks into info.
2259         (when (setq m (assoc (car group) marked))
2260           (unless (nthcdr 3 info)
2261             (nconc info (list nil)))
2262           (gnus-info-set-marks
2263            info (list (cons 'tick (gnus-compress-sequence
2264                                    (sort (cdr m) '<) t))))))
2265       (setq newsrc killed)
2266       (while newsrc
2267         (setcar newsrc (caar newsrc))
2268         (setq newsrc (cdr newsrc)))
2269       (setq gnus-killed-list killed))
2270     ;; The .el file version of this variable does not begin with
2271     ;; "options", while the .eld version does, so we just add it if it
2272     ;; isn't there.
2273     (when
2274         gnus-newsrc-options
2275       (when (not (string-match "^ *options" gnus-newsrc-options))
2276         (setq gnus-newsrc-options (concat "options " gnus-newsrc-options)))
2277       (when (not (string-match "\n$" gnus-newsrc-options))
2278         (setq gnus-newsrc-options (concat gnus-newsrc-options "\n")))
2279       ;; Finally, if we read some options lines, we parse them.
2280       (unless (string= gnus-newsrc-options "")
2281         (gnus-newsrc-parse-options gnus-newsrc-options)))
2282
2283     (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist))
2284     (gnus-make-hashtable-from-newsrc-alist)))
2285
2286 (defun gnus-make-newsrc-file (file)
2287   "Make server dependent file name by catenating FILE and server host name."
2288   (let* ((file (expand-file-name file nil))
2289          (real-file (concat file "-" (nth 1 gnus-select-method))))
2290     (if (or (file-exists-p real-file)
2291             (file-exists-p (concat real-file ".el"))
2292             (file-exists-p (concat real-file ".eld")))
2293         real-file
2294       file)))
2295
2296 (defun gnus-newsrc-to-gnus-format ()
2297   (setq gnus-newsrc-options "")
2298   (setq gnus-newsrc-options-n nil)
2299
2300   (unless gnus-active-hashtb
2301     (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
2302   (let ((buf (current-buffer))
2303         (already-read (> (length gnus-newsrc-alist) 1))
2304         group subscribed options-symbol newsrc Options-symbol
2305         symbol reads num1)
2306     (goto-char (point-min))
2307     ;; We intern the symbol `options' in the active hashtb so that we
2308     ;; can `eq' against it later.
2309     (set (setq options-symbol (intern "options" gnus-active-hashtb)) nil)
2310     (set (setq Options-symbol (intern "Options" gnus-active-hashtb)) nil)
2311
2312     (while (not (eobp))
2313       ;; We first read the first word on the line by narrowing and
2314       ;; then reading into `gnus-active-hashtb'.  Most groups will
2315       ;; already exist in that hashtb, so this will save some string
2316       ;; space.
2317       (narrow-to-region
2318        (point)
2319        (progn (skip-chars-forward "^ \t!:\n") (point)))
2320       (goto-char (point-min))
2321       (setq symbol
2322             (and (/= (point-min) (point-max))
2323                  (let ((obarray gnus-active-hashtb)) (read buf))))
2324       (widen)
2325       ;; Now, the symbol we have read is either `options' or a group
2326       ;; name.  If it is an options line, we just add it to a string.
2327       (cond
2328        ((or (eq symbol options-symbol)
2329             (eq symbol Options-symbol))
2330         (setq gnus-newsrc-options
2331               ;; This concating is quite inefficient, but since our
2332               ;; thorough studies show that approx 99.37% of all
2333               ;; .newsrc files only contain a single options line, we
2334               ;; don't give a damn, frankly, my dear.
2335               (concat gnus-newsrc-options
2336                       (buffer-substring
2337                        (gnus-point-at-bol)
2338                        ;; Options may continue on the next line.
2339                        (or (and (re-search-forward "^[^ \t]" nil 'move)
2340                                 (progn (beginning-of-line) (point)))
2341                            (point)))))
2342         (forward-line -1))
2343        (symbol
2344         ;; Group names can be just numbers.
2345         (when (numberp symbol)
2346           (setq symbol (intern (int-to-string symbol) gnus-active-hashtb)))
2347         (unless (boundp symbol)
2348           (set symbol nil))
2349         ;; It was a group name.
2350         (setq subscribed (eq (char-after) ?:)
2351               group (symbol-name symbol)
2352               reads nil)
2353         (if (eolp)
2354             ;; If the line ends here, this is clearly a buggy line, so
2355             ;; we put point a the beginning of line and let the cond
2356             ;; below do the error handling.
2357             (beginning-of-line)
2358           ;; We skip to the beginning of the ranges.
2359           (skip-chars-forward "!: \t"))
2360         ;; We are now at the beginning of the list of read articles.
2361         ;; We read them range by range.
2362         (while
2363             (cond
2364              ((looking-at "[0-9]+")
2365               ;; We narrow and read a number instead of buffer-substring/
2366               ;; string-to-int because it's faster.  narrow/widen is
2367               ;; faster than save-restriction/narrow, and save-restriction
2368               ;; produces a garbage object.
2369               (setq num1 (progn
2370                            (narrow-to-region (match-beginning 0) (match-end 0))
2371                            (read buf)))
2372               (widen)
2373               ;; If the next character is a dash, then this is a range.
2374               (if (eq (char-after) ?-)
2375                   (progn
2376                     ;; We read the upper bound of the range.
2377                     (forward-char 1)
2378                     (if (not (looking-at "[0-9]+"))
2379                         ;; This is a buggy line, by we pretend that
2380                         ;; it's kinda OK.  Perhaps the user should be
2381                         ;; dinged?
2382                         (push num1 reads)
2383                       (push
2384                        (cons num1
2385                              (progn
2386                                (narrow-to-region (match-beginning 0)
2387                                                  (match-end 0))
2388                                (read buf)))
2389                        reads)
2390                       (widen)))
2391                 ;; It was just a simple number, so we add it to the
2392                 ;; list of ranges.
2393                 (push num1 reads))
2394               ;; If the next char in ?\n, then we have reached the end
2395               ;; of the line and return nil.
2396               (not (eq (char-after) ?\n)))
2397              ((eq (char-after) ?\n)
2398               ;; End of line, so we end.
2399               nil)
2400              (t
2401               ;; Not numbers and not eol, so this might be a buggy
2402               ;; line...
2403               (unless (eobp)
2404                 ;; If it was eob instead of ?\n, we allow it.
2405                 ;; The line was buggy.
2406                 (setq group nil)
2407                 (gnus-error 3.1 "Mangled line: %s"
2408                             (buffer-substring (gnus-point-at-bol)
2409                                               (gnus-point-at-eol))))
2410               nil))
2411           ;; Skip past ", ".  Spaces are invalid in these ranges, but
2412           ;; we allow them, because it's a common mistake to put a
2413           ;; space after the comma.
2414           (skip-chars-forward ", "))
2415
2416         ;; We have already read .newsrc.eld, so we gently update the
2417         ;; data in the hash table with the information we have just
2418         ;; read.
2419         (when group
2420           (let ((info (gnus-get-info group))
2421                 level)
2422             (if info
2423                 ;; There is an entry for this file in the alist.
2424                 (progn
2425                   (gnus-info-set-read info (nreverse reads))
2426                   ;; We update the level very gently.  In fact, we
2427                   ;; only change it if there's been a status change
2428                   ;; from subscribed to unsubscribed, or vice versa.
2429                   (setq level (gnus-info-level info))
2430                   (cond ((and (<= level gnus-level-subscribed)
2431                               (not subscribed))
2432                          (setq level (if reads
2433                                          gnus-level-default-unsubscribed
2434                                        (1+ gnus-level-default-unsubscribed))))
2435                         ((and (> level gnus-level-subscribed) subscribed)
2436                          (setq level gnus-level-default-subscribed)))
2437                   (gnus-info-set-level info level))
2438               ;; This is a new group.
2439               (setq info (list group
2440                                (if subscribed
2441                                    gnus-level-default-subscribed
2442                                  (if reads
2443                                      (1+ gnus-level-subscribed)
2444                                    gnus-level-default-unsubscribed))
2445                                (nreverse reads))))
2446             (push info newsrc)))))
2447       (forward-line 1))
2448
2449     (setq newsrc (nreverse newsrc))
2450
2451     (if (not already-read)
2452         ()
2453       ;; We now have two newsrc lists - `newsrc', which is what we
2454       ;; have read from .newsrc, and `gnus-newsrc-alist', which is
2455       ;; what we've read from .newsrc.eld.  We have to merge these
2456       ;; lists.  We do this by "attaching" any (foreign) groups in the
2457       ;; gnus-newsrc-alist to the (native) group that precedes them.
2458       (let ((rc (cdr gnus-newsrc-alist))
2459             (prev gnus-newsrc-alist)
2460             entry mentry)
2461         (while rc
2462           (or (null (nth 4 (car rc)))   ; It's a native group.
2463               (assoc (caar rc) newsrc)  ; It's already in the alist.
2464               (if (setq entry (assoc (caar prev) newsrc))
2465                   (setcdr (setq mentry (memq entry newsrc))
2466                           (cons (car rc) (cdr mentry)))
2467                 (push (car rc) newsrc)))
2468           (setq prev rc
2469                 rc (cdr rc)))))
2470
2471     (setq gnus-newsrc-alist newsrc)
2472     ;; We make the newsrc hashtb.
2473     (gnus-make-hashtable-from-newsrc-alist)
2474
2475     ;; Finally, if we read some options lines, we parse them.
2476     (unless (string= gnus-newsrc-options "")
2477       (gnus-newsrc-parse-options gnus-newsrc-options))))
2478
2479 ;; Parse options lines to find "options -n !all rec.all" and stuff.
2480 ;; The return value will be a list on the form
2481 ;; ((regexp1 . ignore)
2482 ;;  (regexp2 . subscribe)...)
2483 ;; When handling new newsgroups, groups that match a `ignore' regexp
2484 ;; will be ignored, and groups that match a `subscribe' regexp will be
2485 ;; subscribed.  A line like
2486 ;; options -n !all rec.all
2487 ;; will lead to a list that looks like
2488 ;; (("^rec\\..+" . subscribe)
2489 ;;  ("^.+" . ignore))
2490 ;; So all "rec.*" groups will be subscribed, while all the other
2491 ;; groups will be ignored.  Note that "options -n !all rec.all" is very
2492 ;; different from "options -n rec.all !all".
2493 (defun gnus-newsrc-parse-options (options)
2494   (let (out eol)
2495     (save-excursion
2496       (gnus-set-work-buffer)
2497       (insert (regexp-quote options))
2498       ;; First we treat all continuation lines.
2499       (goto-char (point-min))
2500       (while (re-search-forward "\n[ \t]+" nil t)
2501         (replace-match " " t t))
2502       ;; Then we transform all "all"s into ".+"s.
2503       (goto-char (point-min))
2504       (while (re-search-forward "\\ball\\b" nil t)
2505         (replace-match ".+" t t))
2506       (goto-char (point-min))
2507       ;; We remove all other options than the "-n" ones.
2508       (while (re-search-forward "[ \t]-[^n][^-]*" nil t)
2509         (replace-match " ")
2510         (forward-char -1))
2511       (goto-char (point-min))
2512
2513       ;; We are only interested in "options -n" lines - we
2514       ;; ignore the other option lines.
2515       (while (re-search-forward "[ \t]-n" nil t)
2516         (setq eol
2517               (or (save-excursion
2518                     (and (re-search-forward "[ \t]-n" (gnus-point-at-eol) t)
2519                          (- (point) 2)))
2520                   (gnus-point-at-eol)))
2521         ;; Search for all "words"...
2522         (while (re-search-forward "[^ \t,\n]+" eol t)
2523           (if (eq (char-after (match-beginning 0)) ?!)
2524               ;; If the word begins with a bang (!), this is a "not"
2525               ;; spec.  We put this spec (minus the bang) and the
2526               ;; symbol `ignore' into the list.
2527               (push (cons (concat
2528                            "^" (buffer-substring
2529                                 (1+ (match-beginning 0))
2530                                 (match-end 0))
2531                            "\\($\\|\\.\\)")
2532                           'ignore)
2533                     out)
2534             ;; There was no bang, so this is a "yes" spec.
2535             (push (cons (concat "^" (match-string 0) "\\($\\|\\.\\)")
2536                         'subscribe)
2537                   out))))
2538
2539       (setq gnus-newsrc-options-n out))))
2540
2541 (eval-and-compile
2542   (defalias 'gnus-long-file-names
2543     (if (fboundp 'msdos-long-file-names)
2544       'msdos-long-file-names
2545       (lambda () t))))
2546
2547 (defun gnus-save-newsrc-file (&optional force)
2548   "Save .newsrc file."
2549   ;; Note: We cannot save .newsrc file if all newsgroups are removed
2550   ;; from the variable gnus-newsrc-alist.
2551   (when (and (or gnus-newsrc-alist gnus-killed-list)
2552              gnus-current-startup-file)
2553     (save-excursion
2554       (if (and (or gnus-use-dribble-file gnus-slave)
2555                (not force)
2556                (or (not gnus-dribble-buffer)
2557                    (not (buffer-name gnus-dribble-buffer))
2558                    (zerop (save-excursion
2559                             (set-buffer gnus-dribble-buffer)
2560                             (buffer-size)))))
2561           (gnus-message 4 "(No changes need to be saved)")
2562         (gnus-run-hooks 'gnus-save-newsrc-hook)
2563         (if gnus-slave
2564             (gnus-slave-save-newsrc)
2565           ;; Save .newsrc.
2566           (when gnus-save-newsrc-file
2567             (gnus-message 8 "Saving %s..." gnus-current-startup-file)
2568             (gnus-gnus-to-newsrc-format)
2569             (gnus-message 8 "Saving %s...done" gnus-current-startup-file))
2570           ;; Save .newsrc.eld.
2571           (set-buffer (gnus-get-buffer-create " *Gnus-newsrc*"))
2572           (make-local-variable 'version-control)
2573           (setq version-control gnus-backup-startup-file)
2574           (setq buffer-file-name
2575                 (concat gnus-current-startup-file ".eld"))
2576           (setq default-directory (file-name-directory buffer-file-name))
2577           (buffer-disable-undo)
2578           (erase-buffer)
2579           (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file)
2580
2581           (if gnus-save-startup-file-via-temp-buffer
2582               (let ((coding-system-for-write gnus-ding-file-coding-system)
2583                     (standard-output (current-buffer)))
2584                 (gnus-gnus-to-quick-newsrc-format)
2585                 (gnus-run-hooks 'gnus-save-quick-newsrc-hook)
2586                 (save-buffer))
2587             (let ((coding-system-for-write gnus-ding-file-coding-system)
2588                   (version-control gnus-backup-startup-file)
2589                   (startup-file (concat gnus-current-startup-file ".eld"))
2590                   (working-dir (file-name-directory gnus-current-startup-file))
2591                   working-file
2592                   (i -1))
2593               ;; Generate the name of a non-existent file.
2594               (while (progn (setq working-file
2595                                   (format
2596                                    (if (and (eq system-type 'ms-dos)
2597                                             (not (gnus-long-file-names)))
2598                                        "%s#%d.tm#" ; MSDOS limits files to 8+3
2599                                      (if (memq system-type '(vax-vms axp-vms))
2600                                          "%s$tmp$%d"
2601                                        "%s#tmp#%d"))
2602                                    working-dir (setq i (1+ i))))
2603                             (file-exists-p working-file)))
2604
2605               (unwind-protect
2606                   (progn
2607                     (gnus-with-output-to-file working-file
2608                       (gnus-gnus-to-quick-newsrc-format)
2609                       (gnus-run-hooks 'gnus-save-quick-newsrc-hook))
2610
2611                     ;; These bindings will mislead the current buffer
2612                     ;; into thinking that it is visiting the startup
2613                     ;; file.
2614                     (let ((buffer-backed-up nil)
2615                           (buffer-file-name startup-file)
2616                           (file-precious-flag t)
2617                           (setmodes (file-modes startup-file)))
2618                       ;; Backup the current version of the startup file.
2619                       (backup-buffer)
2620
2621                       ;; Replace the existing startup file with the temp file.
2622                       (rename-file working-file startup-file t)
2623                       (set-file-modes startup-file setmodes)))
2624                 (condition-case nil
2625                     (delete-file working-file)
2626                   (file-error nil)))))
2627
2628           (gnus-kill-buffer (current-buffer))
2629           (gnus-message
2630            5 "Saving %s.eld...done" gnus-current-startup-file))
2631         (gnus-dribble-delete-file)
2632         (gnus-group-set-mode-line)))))
2633
2634 (defun gnus-gnus-to-quick-newsrc-format (&optional minimal name &rest specific-variables)
2635   "Print Gnus variables such as gnus-newsrc-alist in lisp format."
2636     (princ ";; -*- emacs-lisp -*-\n")
2637     (if name
2638         (princ (format ";; %s\n" name))
2639       (princ ";; Gnus startup file.\n"))
2640
2641     (unless minimal
2642       (princ "\
2643 ;; Never delete this file -- if you want to force Gnus to read the
2644 ;; .newsrc file (if you have one), touch .newsrc instead.\n")
2645       (princ "(setq gnus-newsrc-file-version ")
2646       (princ (gnus-prin1-to-string gnus-version))
2647       (princ ")\n"))
2648
2649     (let* ((print-quoted t)
2650            (print-readably t)
2651            (print-escape-multibyte nil)
2652            (print-escape-nonascii t)
2653            (print-length nil)
2654            (print-level nil)
2655            (print-escape-newlines t)
2656            (gnus-killed-list
2657             (if (and gnus-save-killed-list
2658                      (stringp gnus-save-killed-list))
2659                 (gnus-strip-killed-list)
2660               gnus-killed-list))
2661            (variables 
2662             (or specific-variables
2663                 (if gnus-save-killed-list gnus-variable-list
2664                   ;; Remove the `gnus-killed-list' from the list of variables
2665                   ;; to be saved, if required.
2666                   (delq 'gnus-killed-list (copy-sequence gnus-variable-list)))))
2667            ;; Peel off the "dummy" group.
2668            (gnus-newsrc-alist (cdr gnus-newsrc-alist))
2669            variable)
2670       ;; Insert the variables into the file.
2671       (while variables
2672         (when (and (boundp (setq variable (pop variables)))
2673                    (symbol-value variable))
2674           (princ "(setq ")
2675           (princ (symbol-name variable))
2676           (princ " '")
2677           (prin1 (symbol-value variable))
2678           (princ ")\n")))))
2679
2680 (defun gnus-strip-killed-list ()
2681   "Return the killed list minus the groups that match `gnus-save-killed-list'."
2682   (let ((list gnus-killed-list)
2683         olist)
2684     (while list
2685       (when (string-match gnus-save-killed-list (car list))
2686         (push (car list) olist))
2687       (pop list))
2688     (nreverse olist)))
2689
2690 (defun gnus-gnus-to-newsrc-format ()
2691   ;; Generate and save the .newsrc file.
2692   (save-excursion
2693     (set-buffer (create-file-buffer gnus-current-startup-file))
2694     (let ((newsrc (cdr gnus-newsrc-alist))
2695           (standard-output (current-buffer))
2696           info ranges range method)
2697       (setq buffer-file-name gnus-current-startup-file)
2698       (setq default-directory (file-name-directory buffer-file-name))
2699       (buffer-disable-undo)
2700       (erase-buffer)
2701       ;; Write options.
2702       (when gnus-newsrc-options
2703         (insert gnus-newsrc-options))
2704       ;; Write subscribed and unsubscribed.
2705       (while (setq info (pop newsrc))
2706         ;; Don't write foreign groups to .newsrc.
2707         (when (or (null (setq method (gnus-info-method info)))
2708                   (equal method "native")
2709                   (inline (gnus-server-equal method gnus-select-method)))
2710           (insert (gnus-info-group info)
2711                   (if (> (gnus-info-level info) gnus-level-subscribed)
2712                       "!" ":"))
2713           (when (setq ranges (gnus-info-read info))
2714             (insert " ")
2715             (if (not (listp (cdr ranges)))
2716                 (if (= (car ranges) (cdr ranges))
2717                     (princ (car ranges))
2718                   (princ (car ranges))
2719                   (insert "-")
2720                   (princ (cdr ranges)))
2721               (while (setq range (pop ranges))
2722                 (if (or (atom range) (= (car range) (cdr range)))
2723                     (princ (or (and (atom range) range) (car range)))
2724                   (princ (car range))
2725                   (insert "-")
2726                   (princ (cdr range)))
2727                 (when ranges
2728                   (insert ",")))))
2729           (insert "\n")))
2730       (make-local-variable 'version-control)
2731       (setq version-control 'never)
2732       ;; It has been reported that sometime the modtime on the .newsrc
2733       ;; file seems to be off.  We really do want to overwrite it, so
2734       ;; we clear the modtime here before saving.  It's a bit odd,
2735       ;; though...
2736       ;; sometimes the modtime clear isn't sufficient.  most brute force:
2737       ;; delete the silly thing entirely first.  but this fails to provide
2738       ;; such niceties as .newsrc~ creation.
2739       (if gnus-modtime-botch
2740           (delete-file gnus-startup-file)
2741         (clear-visited-file-modtime))
2742       (gnus-run-hooks 'gnus-save-standard-newsrc-hook)
2743       (save-buffer)
2744       (kill-buffer (current-buffer)))))
2745
2746 \f
2747 ;;;
2748 ;;; Slave functions.
2749 ;;;
2750
2751 (defvar gnus-slave-mode nil)
2752
2753 (defun gnus-slave-mode ()
2754   "Minor mode for slave Gnusae."
2755   (gnus-add-minor-mode 'gnus-slave-mode " Slave" (make-sparse-keymap))
2756   (gnus-run-hooks 'gnus-slave-mode-hook))
2757
2758 (defun gnus-slave-save-newsrc ()
2759   (save-excursion
2760     (set-buffer gnus-dribble-buffer)
2761     (let ((slave-name
2762            (mm-make-temp-file (concat gnus-current-startup-file "-slave-")))
2763           (modes (ignore-errors
2764                    (file-modes (concat gnus-current-startup-file ".eld")))))
2765       (let ((coding-system-for-write gnus-ding-file-coding-system))
2766         (gnus-write-buffer slave-name))
2767       (when modes
2768         (set-file-modes slave-name modes)))))
2769
2770 (defun gnus-master-read-slave-newsrc ()
2771   (let ((slave-files
2772          (directory-files
2773           (file-name-directory gnus-current-startup-file)
2774           t (concat
2775              "^" (regexp-quote
2776                   (concat
2777                    (file-name-nondirectory gnus-current-startup-file)
2778                    "-slave-")))
2779           t))
2780         file)
2781     (if (not slave-files)
2782         ()                              ; There are no slave files to read.
2783       (gnus-message 7 "Reading slave newsrcs...")
2784       (save-excursion
2785         (set-buffer (gnus-get-buffer-create " *gnus slave*"))
2786         (setq slave-files
2787               (sort (mapcar (lambda (file)
2788                               (list (nth 5 (file-attributes file)) file))
2789                             slave-files)
2790                     (lambda (f1 f2)
2791                       (or (< (caar f1) (caar f2))
2792                           (< (nth 1 (car f1)) (nth 1 (car f2)))))))
2793         (while slave-files
2794           (erase-buffer)
2795           (setq file (nth 1 (car slave-files)))
2796           (nnheader-insert-file-contents file)
2797           (when (condition-case ()
2798                     (progn
2799                       (eval-buffer (current-buffer))
2800                       t)
2801                   (error
2802                    (gnus-error 3.2 "Possible error in %s" file)
2803                    nil))
2804             (unless gnus-slave          ; Slaves shouldn't delete these files.
2805               (ignore-errors
2806                 (delete-file file))))
2807           (setq slave-files (cdr slave-files))))
2808       (gnus-dribble-touch)
2809       (gnus-message 7 "Reading slave newsrcs...done"))))
2810
2811 \f
2812 ;;;
2813 ;;; Group description.
2814 ;;;
2815
2816 (defun gnus-read-all-descriptions-files ()
2817   (let ((methods (cons gnus-select-method
2818                        (nconc
2819                         (when (gnus-archive-server-wanted-p)
2820                           (list "archive"))
2821                         gnus-secondary-select-methods))))
2822     (while methods
2823       (gnus-read-descriptions-file (car methods))
2824       (setq methods (cdr methods)))
2825     t))
2826
2827 (defun gnus-read-descriptions-file (&optional method)
2828   (let ((method (or method gnus-select-method))
2829         group)
2830     (when (stringp method)
2831       (setq method (gnus-server-to-method method)))
2832     ;; We create the hashtable whether we manage to read the desc file
2833     ;; to avoid trying to re-read after a failed read.
2834     (unless gnus-description-hashtb
2835       (setq gnus-description-hashtb
2836             (gnus-make-hashtable (length gnus-active-hashtb))))
2837     ;; Mark this method's desc file as read.
2838     (gnus-sethash (gnus-group-prefixed-name "" method) "Has read"
2839                   gnus-description-hashtb)
2840
2841     (gnus-message 5 "Reading descriptions file via %s..." (car method))
2842     (cond
2843      ((null (gnus-get-function method 'request-list-newsgroups t))
2844       t)
2845      ((not (gnus-check-server method))
2846       (gnus-message 1 "Couldn't open server")
2847       nil)
2848      ((not (gnus-request-list-newsgroups method))
2849       (gnus-message 1 "Couldn't read newsgroups descriptions")
2850       nil)
2851      (t
2852       (save-excursion
2853         (save-restriction
2854           (set-buffer nntp-server-buffer)
2855           (goto-char (point-min))
2856           (when (or (search-forward "\n.\n" nil t)
2857                     (goto-char (point-max)))
2858             (beginning-of-line)
2859             (narrow-to-region (point-min) (point)))
2860           ;; If these are groups from a foreign select method, we insert the
2861           ;; group prefix in front of the group names.
2862           (and method (not (inline
2863                              (gnus-server-equal
2864                               (gnus-server-get-method nil method)
2865                               (gnus-server-get-method
2866                                nil gnus-select-method))))
2867                (let ((prefix (gnus-group-prefixed-name "" method)))
2868                  (goto-char (point-min))
2869                  (while (and (not (eobp))
2870                              (progn (insert prefix)
2871                                     (zerop (forward-line 1)))))))
2872           (goto-char (point-min))
2873           (while (not (eobp))
2874             ;; If we get an error, we set group to 0, which is not a
2875             ;; symbol...
2876             (setq group
2877                   (condition-case ()
2878                       (let ((obarray gnus-description-hashtb))
2879                         ;; Group is set to a symbol interned in this
2880                         ;; hash table.
2881                         (read nntp-server-buffer))
2882                     (error 0)))
2883             (skip-chars-forward " \t")
2884             ;; ...  which leads to this line being effectively ignored.
2885             (when (symbolp group)
2886               (let* ((str (buffer-substring
2887                            (point) (progn (end-of-line) (point))))
2888                      (name (symbol-name group))
2889                      (charset
2890                       (or (gnus-group-name-charset method name)
2891                           (gnus-parameter-charset name)
2892                           gnus-default-charset)))
2893                 ;; Fixme: Don't decode in unibyte mode.
2894                 (when (and str charset (featurep 'mule))
2895                   (setq str (mm-decode-coding-string str charset)))
2896                 (set group str)))
2897             (forward-line 1))))
2898       (gnus-message 5 "Reading descriptions file...done")
2899       t))))
2900
2901 (defun gnus-group-get-description (group)
2902   "Get the description of a group by sending XGTITLE to the server."
2903   (when (gnus-request-group-description group)
2904     (save-excursion
2905       (set-buffer nntp-server-buffer)
2906       (goto-char (point-min))
2907       (when (looking-at "[^ \t]+[ \t]+\\(.*\\)")
2908         (match-string 1)))))
2909
2910 ;;;###autoload
2911 (defun gnus-declare-backend (name &rest abilities)
2912   "Declare backend NAME with ABILITIES as a Gnus backend."
2913   (setq gnus-valid-select-methods
2914         (nconc gnus-valid-select-methods
2915                (list (apply 'list name abilities))))
2916   (gnus-redefine-select-method-widget))
2917
2918 (defun gnus-set-default-directory ()
2919   "Set the default directory in the current buffer to `gnus-default-directory'.
2920 If this variable is nil, don't do anything."
2921   (setq default-directory
2922         (if (and gnus-default-directory
2923                  (file-exists-p gnus-default-directory))
2924             (file-name-as-directory (expand-file-name gnus-default-directory))
2925           default-directory)))
2926
2927 (eval-and-compile
2928 (defalias 'gnus-display-time-event-handler 
2929   (if (gnus-boundp 'display-time-timer)
2930       'display-time-event-handler
2931     (lambda () "Does nothing as `display-time-timer' is not bound.
2932 Would otherwise be an alias for `display-time-event-handler'." nil))))
2933
2934 ;;;###autoload
2935 (defun gnus-fixup-nnimap-unread-after-getting-new-news ()
2936   (let (server group info)
2937     (mapatoms
2938      (lambda (sym)
2939        (when (and (setq group (symbol-name sym))
2940                   (gnus-group-entry group)
2941                   (setq info (symbol-value sym)))
2942          (gnus-sethash group (cons (nth 2 info) (cdr (gnus-group-entry group)))
2943                        gnus-newsrc-hashtb)))
2944      (if (boundp 'nnimap-mailbox-info)
2945          (symbol-value 'nnimap-mailbox-info)
2946        (make-vector 1 0)))))
2947
2948
2949 (provide 'gnus-start)
2950
2951 ;;; gnus-start.el ends here
2952
2953