* gnus-start.el (gnus-gnus-to-quick-newsrc-format): Bind
[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 (require '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 ;;;###autoload
791 (defun gnus-unload ()
792   "Unload all Gnus features.
793 \(For some value of `all' or `Gnus'.)  Currently, features whose names
794 have prefixes `gnus-', `nn', `mm-' or `rfc' are unloaded.  Use
795 cautiously -- unloading may cause trouble."
796   (interactive)
797   (dolist (feature features)
798     (if (string-match "^\\(gnus-\\|nn\\|mm-\\|rfc\\)" (symbol-name feature))
799         (unload-feature feature 'force))))
800
801 \f
802 ;;;
803 ;;; Dribble file
804 ;;;
805
806 (defvar gnus-dribble-ignore nil)
807 (defvar gnus-dribble-eval-file nil)
808
809 (defun gnus-dribble-file-name ()
810   "Return the dribble file for the current .newsrc."
811   (concat
812    (if gnus-dribble-directory
813        (concat (file-name-as-directory gnus-dribble-directory)
814                (file-name-nondirectory gnus-current-startup-file))
815      gnus-current-startup-file)
816    "-dribble"))
817
818 (defun gnus-dribble-enter (string)
819   "Enter STRING into the dribble buffer."
820   (when (and (not gnus-dribble-ignore)
821              gnus-dribble-buffer
822              (buffer-name gnus-dribble-buffer))
823     (let ((obuf (current-buffer)))
824       (set-buffer gnus-dribble-buffer)
825       (goto-char (point-max))
826       (insert string "\n")
827       ;; This has been commented by Josh Huber <huber@alum.wpi.edu>
828       ;; It causes problems with both XEmacs and Emacs 21, and doesn't
829       ;; seem to be of much value. (FIXME: remove this after we make sure
830       ;; it's not needed).
831       ;; (set-window-point (get-buffer-window (current-buffer)) (point-max))
832       (bury-buffer gnus-dribble-buffer)
833       (save-excursion
834         (set-buffer gnus-group-buffer)
835         (gnus-group-set-mode-line))
836       (set-buffer obuf))))
837
838 (defun gnus-dribble-touch ()
839   "Touch the dribble buffer."
840   (gnus-dribble-enter ""))
841
842 (defun gnus-dribble-read-file ()
843   "Read the dribble file from disk."
844   (let ((dribble-file (gnus-dribble-file-name)))
845     (save-excursion
846       (set-buffer (setq gnus-dribble-buffer
847                         (gnus-get-buffer-create
848                          (file-name-nondirectory dribble-file))))
849       (erase-buffer)
850       (setq buffer-file-name dribble-file)
851       (auto-save-mode t)
852       (buffer-disable-undo)
853       (bury-buffer (current-buffer))
854       (set-buffer-modified-p nil)
855       (let ((auto (make-auto-save-file-name))
856             (gnus-dribble-ignore t)
857             (purpose nil)
858             modes)
859         (when (or (file-exists-p auto) (file-exists-p dribble-file))
860           ;; Load whichever file is newest -- the auto save file
861           ;; or the "real" file.
862           (if (file-newer-than-file-p auto dribble-file)
863               (nnheader-insert-file-contents auto)
864             (nnheader-insert-file-contents dribble-file))
865           (unless (zerop (buffer-size))
866             (set-buffer-modified-p t))
867           ;; Set the file modes to reflect the .newsrc file modes.
868           (save-buffer)
869           (when (and (file-exists-p gnus-current-startup-file)
870                      (file-exists-p dribble-file)
871                      (setq modes (file-modes gnus-current-startup-file)))
872             (set-file-modes dribble-file modes))
873           (goto-char (point-min))
874           (when (search-forward "Gnus was exited on purpose" nil t)
875             (setq purpose t))
876           ;; Possibly eval the file later.
877           (when (or gnus-always-read-dribble-file
878                     (gnus-y-or-n-p
879                      (if purpose
880                          "Gnus exited on purpose without saving; read auto-save file anyway? "
881                      "Gnus auto-save file exists.  Do you want to read it? ")))
882             (setq gnus-dribble-eval-file t)))))))
883
884 (defun gnus-dribble-eval-file ()
885   (when gnus-dribble-eval-file
886     (setq gnus-dribble-eval-file nil)
887     (save-excursion
888       (let ((gnus-dribble-ignore t))
889         (set-buffer gnus-dribble-buffer)
890         (eval-buffer (current-buffer))))))
891
892 (defun gnus-dribble-delete-file ()
893   (when (file-exists-p (gnus-dribble-file-name))
894     (delete-file (gnus-dribble-file-name)))
895   (when gnus-dribble-buffer
896     (save-excursion
897       (set-buffer gnus-dribble-buffer)
898       (let ((auto (make-auto-save-file-name)))
899         (when (file-exists-p auto)
900           (delete-file auto))
901         (erase-buffer)
902         (set-buffer-modified-p nil)))))
903
904 (defun gnus-dribble-save ()
905   (when (and gnus-dribble-buffer
906              (buffer-name gnus-dribble-buffer))
907     (save-excursion
908       (set-buffer gnus-dribble-buffer)
909       (save-buffer))))
910
911 (defun gnus-dribble-clear ()
912   (when (gnus-buffer-exists-p gnus-dribble-buffer)
913     (save-excursion
914       (set-buffer gnus-dribble-buffer)
915       (erase-buffer)
916       (set-buffer-modified-p nil)
917       (setq buffer-saved-size (buffer-size)))))
918
919 \f
920 ;;;
921 ;;; Active & Newsrc File Handling
922 ;;;
923
924 (defun gnus-setup-news (&optional rawfile level dont-connect)
925   "Setup news information.
926 If RAWFILE is non-nil, the .newsrc file will also be read.
927 If LEVEL is non-nil, the news will be set up at level LEVEL."
928   (require 'nnmail)
929   (let ((init (not (and gnus-newsrc-alist gnus-active-hashtb (not rawfile))))
930         ;; Binding this variable will inhibit multiple fetchings
931         ;; of the same mail source.
932         (nnmail-fetched-sources (list t)))
933
934     (when init
935       ;; Clear some variables to re-initialize news information.
936       (setq gnus-newsrc-alist nil
937             gnus-active-hashtb nil)
938       ;; Read the newsrc file and create `gnus-newsrc-hashtb'.
939       (gnus-read-newsrc-file rawfile))
940
941     ;; Make sure the archive server is available to all and sundry.
942     (when gnus-message-archive-method
943       (unless (assoc "archive" gnus-server-alist)
944         (push `("archive"
945                 nnfolder
946                 "archive"
947                 (nnfolder-directory
948                  ,(nnheader-concat message-directory "archive"))
949                 (nnfolder-active-file
950                  ,(nnheader-concat message-directory "archive/active"))
951                 (nnfolder-get-new-mail nil)
952                 (nnfolder-inhibit-expiry t))
953               gnus-server-alist)))
954
955     ;; If we don't read the complete active file, we fill in the
956     ;; hashtb here.
957     (when (or (null gnus-read-active-file)
958               (eq gnus-read-active-file 'some))
959       (gnus-update-active-hashtb-from-killed))
960
961     ;; Read the active file and create `gnus-active-hashtb'.
962     ;; If `gnus-read-active-file' is nil, then we just create an empty
963     ;; hash table.  The partial filling out of the hash table will be
964     ;; done in `gnus-get-unread-articles'.
965     (and gnus-read-active-file
966          (not level)
967          (gnus-read-active-file nil dont-connect))
968
969     (unless gnus-active-hashtb
970       (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
971
972     ;; Initialize the cache.
973     (when gnus-use-cache
974       (gnus-cache-open))
975
976     ;; Possibly eval the dribble file.
977     (and init
978          (or gnus-use-dribble-file gnus-slave)
979          (gnus-dribble-eval-file))
980
981     ;; Slave Gnusii should then clear the dribble buffer.
982     (when (and init gnus-slave)
983       (gnus-dribble-clear))
984
985     (gnus-update-format-specifications)
986
987     ;; See whether we need to read the description file.
988     (when (and (boundp 'gnus-group-line-format)
989                (stringp gnus-group-line-format)
990                (let ((case-fold-search nil))
991                  (string-match "%[-,0-9]*D" gnus-group-line-format))
992                (not gnus-description-hashtb)
993                (not dont-connect)
994                gnus-read-active-file)
995       (gnus-read-all-descriptions-files))
996
997     ;; Find new newsgroups and treat them.
998     (when (and init gnus-check-new-newsgroups (not level)
999                (gnus-check-server gnus-select-method)
1000                (not gnus-slave)
1001                gnus-plugged)
1002       (gnus-find-new-newsgroups))
1003
1004     ;; Check and remove bogus newsgroups.
1005     (when (and init gnus-check-bogus-newsgroups
1006                gnus-read-active-file (not level)
1007                (gnus-server-opened gnus-select-method))
1008       (gnus-check-bogus-newsgroups))
1009
1010     ;; We might read in new NoCeM messages here.
1011     (when (and gnus-use-nocem
1012                (not level)
1013                (not dont-connect))
1014       (gnus-nocem-scan-groups))
1015
1016     ;; Read any slave files.
1017     (gnus-master-read-slave-newsrc)
1018
1019     ;; Find the number of unread articles in each non-dead group.
1020     (let ((gnus-read-active-file (and (not level) gnus-read-active-file)))
1021       (gnus-get-unread-articles level))))
1022
1023 (defun gnus-call-subscribe-functions (method group)
1024   "Call METHOD to subscribe GROUP.
1025 If no function returns `non-nil', call `gnus-subscribe-zombies'."
1026   (unless (cond
1027            ((gnus-functionp method)
1028             (funcall method group))
1029            ((listp method)
1030             (catch 'found
1031               (dolist (func method)
1032                 (if (funcall func group)
1033                     (throw 'found t)))
1034               nil))
1035            (t nil))
1036     (gnus-subscribe-zombies group)))
1037
1038 (defun gnus-find-new-newsgroups (&optional arg)
1039   "Search for new newsgroups and add them.
1040 Each new newsgroup will be treated with `gnus-subscribe-newsgroup-method'.
1041 The `-n' option line from .newsrc is respected.
1042
1043 With 1 C-u, use the `ask-server' method to query the server for new
1044 groups.
1045 With 2 C-u's, use most complete method possible to query the server
1046 for new groups, and subscribe the new groups as zombies."
1047   (interactive "p")
1048   (let* ((gnus-subscribe-newsgroup-method
1049           gnus-subscribe-newsgroup-method)
1050          (check (cond
1051                  ((or (and (= (or arg 1) 4)
1052                            (not (listp gnus-check-new-newsgroups)))
1053                       (null gnus-read-active-file)
1054                       (eq gnus-read-active-file 'some))
1055                   'ask-server)
1056                  ((= (or arg 1) 16)
1057                   (setq gnus-subscribe-newsgroup-method
1058                         'gnus-subscribe-zombies)
1059                   t)
1060                  (t gnus-check-new-newsgroups))))
1061     (unless (gnus-check-first-time-used)
1062       (if (or (consp check)
1063               (eq check 'ask-server))
1064           ;; Ask the server for new groups.
1065           (gnus-ask-server-for-new-groups)
1066         ;; Go through the active hashtb and look for new groups.
1067         (let ((groups 0)
1068               group new-newsgroups)
1069           (gnus-message 5 "Looking for new newsgroups...")
1070           (unless gnus-have-read-active-file
1071             (gnus-read-active-file))
1072           (setq gnus-newsrc-last-checked-date (message-make-date))
1073           (unless gnus-killed-hashtb
1074             (gnus-make-hashtable-from-killed))
1075           ;; Go though every newsgroup in `gnus-active-hashtb' and compare
1076           ;; with `gnus-newsrc-hashtb' and `gnus-killed-hashtb'.
1077           (mapatoms
1078            (lambda (sym)
1079              (if (or (null (setq group (symbol-name sym)))
1080                      (not (boundp sym))
1081                      (null (symbol-value sym))
1082                      (gnus-gethash group gnus-killed-hashtb)
1083                      (gnus-gethash group gnus-newsrc-hashtb))
1084                  ()
1085                (let ((do-sub (gnus-matches-options-n group)))
1086                  (cond
1087                   ((eq do-sub 'subscribe)
1088                    (setq groups (1+ groups))
1089                    (gnus-sethash group group gnus-killed-hashtb)
1090                    (gnus-call-subscribe-functions
1091                     gnus-subscribe-options-newsgroup-method group))
1092                   ((eq do-sub 'ignore)
1093                    nil)
1094                   (t
1095                    (setq groups (1+ groups))
1096                    (gnus-sethash group group gnus-killed-hashtb)
1097                    (if gnus-subscribe-hierarchical-interactive
1098                        (push group new-newsgroups)
1099                      (gnus-call-subscribe-functions
1100                       gnus-subscribe-newsgroup-method group)))))))
1101            gnus-active-hashtb)
1102           (when new-newsgroups
1103             (gnus-subscribe-hierarchical-interactive new-newsgroups))
1104           (if (> groups 0)
1105               (gnus-message 5 "%d new newsgroup%s arrived."
1106                             groups (if (> groups 1) "s have" " has"))
1107             (gnus-message 5 "No new newsgroups.")))))))
1108
1109 (defun gnus-matches-options-n (group)
1110   ;; Returns `subscribe' if the group is to be unconditionally
1111   ;; subscribed, `ignore' if it is to be ignored, and nil if there is
1112   ;; no match for the group.
1113
1114   ;; First we check the two user variables.
1115   (cond
1116    ((and gnus-options-subscribe
1117          (string-match gnus-options-subscribe group))
1118     'subscribe)
1119    ((and gnus-auto-subscribed-groups
1120          (string-match gnus-auto-subscribed-groups group))
1121     'subscribe)
1122    ((and gnus-options-not-subscribe
1123          (string-match gnus-options-not-subscribe group))
1124     'ignore)
1125    ;; Then we go through the list that was retrieved from the .newsrc
1126    ;; file.  This list has elements on the form
1127    ;; `(REGEXP . {ignore,subscribe})'.  The first match found (the list
1128    ;; is in the reverse order of the options line) is returned.
1129    (t
1130     (let ((regs gnus-newsrc-options-n))
1131       (while (and regs
1132                   (not (string-match (caar regs) group)))
1133         (setq regs (cdr regs)))
1134       (and regs (cdar regs))))))
1135
1136 (defun gnus-ask-server-for-new-groups ()
1137   (let* ((new-date (message-make-date))
1138          (date (or gnus-newsrc-last-checked-date new-date))
1139          (methods (cons gnus-select-method
1140                         (nconc
1141                          (when (gnus-archive-server-wanted-p)
1142                            (list "archive"))
1143                          (append
1144                           (and (consp gnus-check-new-newsgroups)
1145                                gnus-check-new-newsgroups)
1146                           gnus-secondary-select-methods))))
1147          (groups 0)
1148          group new-newsgroups got-new method hashtb
1149          gnus-override-subscribe-method)
1150     (unless gnus-killed-hashtb
1151       (gnus-make-hashtable-from-killed))
1152     ;; Go through both primary and secondary select methods and
1153     ;; request new newsgroups.
1154     (while (setq method (gnus-server-get-method nil (pop methods)))
1155       (setq new-newsgroups nil
1156             gnus-override-subscribe-method method)
1157       (when (and (gnus-check-server method)
1158                  (gnus-request-newgroups date method))
1159         (save-excursion
1160           (setq got-new t
1161                 hashtb (gnus-make-hashtable 100))
1162           (set-buffer nntp-server-buffer)
1163           ;; Enter all the new groups into a hashtable.
1164           (gnus-active-to-gnus-format method hashtb 'ignore))
1165         ;; Now all new groups from `method' are in `hashtb'.
1166         (mapatoms
1167          (lambda (group-sym)
1168            (if (or (null (setq group (symbol-name group-sym)))
1169                    (not (boundp group-sym))
1170                    (null (symbol-value group-sym))
1171                    (gnus-gethash group gnus-newsrc-hashtb)
1172                    (member group gnus-zombie-list)
1173                    (member group gnus-killed-list))
1174                ;; The group is already known.
1175                ()
1176              ;; Make this group active.
1177              (when (symbol-value group-sym)
1178                (gnus-set-active group (symbol-value group-sym)))
1179              ;; Check whether we want it or not.
1180              (let ((do-sub (gnus-matches-options-n group)))
1181                (cond
1182                 ((eq do-sub 'subscribe)
1183                  (incf groups)
1184                  (gnus-sethash group group gnus-killed-hashtb)
1185                  (gnus-call-subscribe-functions
1186                   gnus-subscribe-options-newsgroup-method group))
1187                 ((eq do-sub 'ignore)
1188                  nil)
1189                 (t
1190                  (incf groups)
1191                  (gnus-sethash group group gnus-killed-hashtb)
1192                  (if gnus-subscribe-hierarchical-interactive
1193                      (push group new-newsgroups)
1194                    (gnus-call-subscribe-functions
1195                     gnus-subscribe-newsgroup-method group)))))))
1196          hashtb))
1197       (when new-newsgroups
1198         (gnus-subscribe-hierarchical-interactive new-newsgroups)))
1199     (if (> groups 0)
1200         (gnus-message 5 "%d new newsgroup%s arrived"
1201                       groups (if (> groups 1) "s have" " has"))
1202       (gnus-message 5 "No new newsgroups"))
1203     (when got-new
1204       (setq gnus-newsrc-last-checked-date new-date))
1205     got-new))
1206
1207 (defun gnus-check-first-time-used ()
1208   (catch 'ended
1209     ;; First check if any of the following files exist.  If they do,
1210     ;; it's not the first time the user has used Gnus.
1211     (dolist (file (list (concat gnus-current-startup-file ".el")
1212                         (concat gnus-current-startup-file ".eld")
1213                         (concat gnus-startup-file ".el")
1214                         (concat gnus-startup-file ".eld")))
1215       (when (file-exists-p file)
1216         (throw 'ended nil)))
1217     (gnus-message 6 "First time user; subscribing you to default groups")
1218     (unless (gnus-read-active-file-p)
1219       (let ((gnus-read-active-file t))
1220         (gnus-read-active-file)))
1221     (setq gnus-newsrc-last-checked-date (message-make-date))
1222     ;; Subscribe to the default newsgroups.
1223     (let ((groups (or gnus-default-subscribed-newsgroups
1224                       gnus-backup-default-subscribed-newsgroups))
1225           group)
1226       (if (eq groups t)
1227           ;; If t, we subscribe (or not) all groups as if they were new.
1228           (mapatoms
1229            (lambda (sym)
1230              (when (setq group (symbol-name sym))
1231                (let ((do-sub (gnus-matches-options-n group)))
1232                  (cond
1233                   ((eq do-sub 'subscribe)
1234                    (gnus-sethash group group gnus-killed-hashtb)
1235                    (gnus-call-subscribe-functions
1236                     gnus-subscribe-options-newsgroup-method group))
1237                   ((eq do-sub 'ignore)
1238                    nil)
1239                   (t
1240                    (push group gnus-killed-list))))))
1241            gnus-active-hashtb)
1242         (dolist (group groups)
1243           ;; Only subscribe the default groups that are activated.
1244           (when (gnus-active group)
1245             (gnus-group-change-level
1246              group gnus-level-default-subscribed gnus-level-killed)))
1247         (save-excursion
1248           (set-buffer gnus-group-buffer)
1249           ;; Don't error if the group already exists. This happens when a
1250           ;; first-time user types 'F'. -- didier
1251           (gnus-group-make-help-group t))
1252         (when gnus-novice-user
1253           (gnus-message 7 "`A k' to list killed groups"))))))
1254
1255 (defun gnus-subscribe-group (group &optional previous method)
1256   "Subcribe GROUP and put it after PREVIOUS."
1257   (gnus-group-change-level
1258    (if method
1259        (list t group gnus-level-default-subscribed nil nil method)
1260      group)
1261    gnus-level-default-subscribed gnus-level-killed previous t)
1262   t)
1263
1264 ;; `gnus-group-change-level' is the fundamental function for changing
1265 ;; subscription levels of newsgroups.  This might mean just changing
1266 ;; from level 1 to 2, which is pretty trivial, from 2 to 6 or back
1267 ;; again, which subscribes/unsubscribes a group, which is equally
1268 ;; trivial.  Changing from 1-7 to 8-9 means that you kill a group, and
1269 ;; from 8-9 to 1-7 means that you remove the group from the list of
1270 ;; killed (or zombie) groups and add them to the (kinda) subscribed
1271 ;; groups.  And last but not least, moving from 8 to 9 and 9 to 8,
1272 ;; which is trivial.
1273 ;; ENTRY can either be a string (newsgroup name) or a list (if
1274 ;; FROMKILLED is t, it's a list on the format (NUM INFO-LIST),
1275 ;; otherwise it's a list in the format of the `gnus-newsrc-hashtb'
1276 ;; entries.
1277 ;; LEVEL is the new level of the group, OLDLEVEL is the old level and
1278 ;; PREVIOUS is the group (in hashtb entry format) to insert this group
1279 ;; after.
1280 (defun gnus-group-change-level (entry level &optional oldlevel
1281                                       previous fromkilled)
1282   (let (group info active num)
1283     ;; Glean what info we can from the arguments
1284     (if (consp entry)
1285         (if fromkilled (setq group (nth 1 entry))
1286           (setq group (car (nth 2 entry))))
1287       (setq group entry))
1288     (when (and (stringp entry)
1289                oldlevel
1290                (< oldlevel gnus-level-zombie))
1291       (setq entry (gnus-gethash entry gnus-newsrc-hashtb)))
1292     (if (and (not oldlevel)
1293              (consp entry))
1294         (setq oldlevel (gnus-info-level (nth 2 entry)))
1295       (setq oldlevel (or oldlevel gnus-level-killed)))
1296     (when (stringp previous)
1297       (setq previous (gnus-gethash previous gnus-newsrc-hashtb)))
1298
1299     (if (and (>= oldlevel gnus-level-zombie)
1300              (gnus-gethash group gnus-newsrc-hashtb))
1301         ;; We are trying to subscribe a group that is already
1302         ;; subscribed.
1303         ()                              ; Do nothing.
1304
1305       (unless (gnus-ephemeral-group-p group)
1306         (gnus-dribble-enter
1307          (format "(gnus-group-change-level %S %S %S %S %S)"
1308                  group level oldlevel (car (nth 2 previous)) fromkilled)))
1309
1310       ;; Then we remove the newgroup from any old structures, if needed.
1311       ;; If the group was killed, we remove it from the killed or zombie
1312       ;; list.  If not, and it is in fact going to be killed, we remove
1313       ;; it from the newsrc hash table and assoc.
1314       (cond
1315        ((>= oldlevel gnus-level-zombie)
1316         ;; oldlevel could be wrong.
1317         (setq gnus-zombie-list (delete group gnus-zombie-list))
1318         (setq gnus-killed-list (delete group gnus-killed-list)))
1319        (t
1320         (when (and (>= level gnus-level-zombie)
1321                    entry)
1322           (gnus-sethash (car (nth 2 entry)) nil gnus-newsrc-hashtb)
1323           (when (nth 3 entry)
1324             (setcdr (gnus-gethash (car (nth 3 entry))
1325                                   gnus-newsrc-hashtb)
1326                     (cdr entry)))
1327           (setcdr (cdr entry) (cdddr entry)))))
1328
1329       ;; Finally we enter (if needed) the list where it is supposed to
1330       ;; go, and change the subscription level.  If it is to be killed,
1331       ;; we enter it into the killed or zombie list.
1332       (cond
1333        ((>= level gnus-level-zombie)
1334         ;; Remove from the hash table.
1335         (gnus-sethash group nil gnus-newsrc-hashtb)
1336         ;; We do not enter foreign groups into the list of dead
1337         ;; groups.
1338         (unless (gnus-group-foreign-p group)
1339           (if (= level gnus-level-zombie)
1340               (push group gnus-zombie-list)
1341             (if (= oldlevel gnus-level-killed)
1342                 ;; Remove from active hashtb.
1343                 (unintern group gnus-active-hashtb)
1344               ;; Don't add it into killed-list if it was killed.
1345               (push group gnus-killed-list)))))
1346        (t
1347         ;; If the list is to be entered into the newsrc assoc, and
1348         ;; it was killed, we have to create an entry in the newsrc
1349         ;; hashtb format and fix the pointers in the newsrc assoc.
1350         (if (< oldlevel gnus-level-zombie)
1351             ;; It was alive, and it is going to stay alive, so we
1352             ;; just change the level and don't change any pointers or
1353             ;; hash table entries.
1354             (setcar (cdaddr entry) level)
1355           (if (listp entry)
1356               (setq info (cdr entry)
1357                     num (car entry))
1358             (setq active (gnus-active group))
1359             (setq num
1360                   (if active (- (1+ (cdr active)) (car active)) t))
1361             ;; Shorten the select method if possible, if we need to
1362             ;; store it at all (native groups).
1363             (let ((method (gnus-method-simplify
1364                            (or gnus-override-subscribe-method
1365                                (gnus-group-method group)))))
1366               (if method
1367                   (setq info (list group level nil nil method))
1368                 (setq info (list group level nil)))))
1369           (unless previous
1370             (setq previous
1371                   (let ((p gnus-newsrc-alist))
1372                     (while (cddr p)
1373                       (setq p (cdr p)))
1374                     p)))
1375           (setq entry (cons info (cddr previous)))
1376           (if (cdr previous)
1377               (progn
1378                 (setcdr (cdr previous) entry)
1379                 (gnus-sethash group (cons num (cdr previous))
1380                               gnus-newsrc-hashtb))
1381             (setcdr previous entry)
1382             (gnus-sethash group (cons num previous)
1383                           gnus-newsrc-hashtb))
1384           (when (cdr entry)
1385             (setcdr (gnus-gethash (caadr entry) gnus-newsrc-hashtb) entry))
1386           (gnus-dribble-enter
1387            (format
1388             "(gnus-group-set-info '%S)" info)))))
1389       (when gnus-group-change-level-function
1390         (funcall gnus-group-change-level-function
1391                  group level oldlevel previous)))))
1392
1393 (defun gnus-kill-newsgroup (newsgroup)
1394   "Obsolete function.  Kills a newsgroup."
1395   (gnus-group-change-level
1396    (gnus-gethash newsgroup gnus-newsrc-hashtb) gnus-level-killed))
1397
1398 (defun gnus-check-bogus-newsgroups (&optional confirm)
1399   "Remove bogus newsgroups.
1400 If CONFIRM is non-nil, the user has to confirm the deletion of every
1401 newsgroup."
1402   (let ((newsrc (cdr gnus-newsrc-alist))
1403         bogus group entry info)
1404     (gnus-message 5 "Checking bogus newsgroups...")
1405     (unless (gnus-read-active-file-p)
1406       (gnus-read-active-file t))
1407     (when (gnus-read-active-file-p)
1408       ;; Find all bogus newsgroup that are subscribed.
1409       (while newsrc
1410         (setq info (pop newsrc)
1411               group (gnus-info-group info))
1412         (unless (or (gnus-active group) ; Active
1413                     (and (gnus-info-method info)
1414                          (not (gnus-secondary-method-p
1415                                (gnus-info-method info))))) ; Foreign
1416           ;; Found a bogus newsgroup.
1417           (push group bogus)))
1418       (if confirm
1419           (map-y-or-n-p
1420            "Remove bogus group %s? "
1421            (lambda (group)
1422              ;; Remove all bogus subscribed groups by first killing them, and
1423              ;; then removing them from the list of killed groups.
1424              (when (setq entry (gnus-gethash group gnus-newsrc-hashtb))
1425                (gnus-group-change-level entry gnus-level-killed)
1426                (setq gnus-killed-list (delete group gnus-killed-list))))
1427            bogus '("group" "groups" "remove"))
1428         (while (setq group (pop bogus))
1429           ;; Remove all bogus subscribed groups by first killing them, and
1430           ;; then removing them from the list of killed groups.
1431           (when (setq entry (gnus-gethash group gnus-newsrc-hashtb))
1432             (gnus-group-change-level entry gnus-level-killed)
1433             (setq gnus-killed-list (delete group gnus-killed-list)))))
1434       ;; Then we remove all bogus groups from the list of killed and
1435       ;; zombie groups.  They are removed without confirmation.
1436       (let ((dead-lists '(gnus-killed-list gnus-zombie-list))
1437             killed)
1438         (while dead-lists
1439           (setq killed (symbol-value (car dead-lists)))
1440           (while killed
1441             (unless (gnus-active (setq group (pop killed)))
1442               ;; The group is bogus.
1443               ;; !!!Slow as hell.
1444               (set (car dead-lists)
1445                    (delete group (symbol-value (car dead-lists))))))
1446           (setq dead-lists (cdr dead-lists))))
1447       (gnus-run-hooks 'gnus-check-bogus-groups-hook)
1448       (gnus-message 5 "Checking bogus newsgroups...done"))))
1449
1450 (defun gnus-check-duplicate-killed-groups ()
1451   "Remove duplicates from the list of killed groups."
1452   (interactive)
1453   (let ((killed gnus-killed-list))
1454     (while killed
1455       (gnus-message 9 "%d" (length killed))
1456       (setcdr killed (delete (car killed) (cdr killed)))
1457       (setq killed (cdr killed)))))
1458
1459 ;; We want to inline a function from gnus-cache, so we cheat here:
1460 (eval-when-compile
1461   (defvar gnus-cache-active-hashtb)
1462   (defun gnus-cache-possibly-alter-active (group active)
1463     "Alter the ACTIVE info for GROUP to reflect the articles in the cache."
1464     (when gnus-cache-active-hashtb
1465       (let ((cache-active (gnus-gethash group gnus-cache-active-hashtb)))
1466         (when cache-active
1467           (when (< (car cache-active) (car active))
1468             (setcar active (car cache-active)))
1469           (when (> (cdr cache-active) (cdr active))
1470             (setcdr active (cdr cache-active))))))))
1471
1472 (defun gnus-activate-group (group &optional scan dont-check method)
1473   ;; Check whether a group has been activated or not.
1474   ;; If SCAN, request a scan of that group as well.
1475   (let ((method (or method (inline (gnus-find-method-for-group group))))
1476         active)
1477     (and (inline (gnus-check-server method))
1478          ;; We escape all bugs and quit here to make it possible to
1479          ;; continue if a group is so out-there that it reports bugs
1480          ;; and stuff.
1481          (progn
1482            (and scan
1483                 (gnus-check-backend-function 'request-scan (car method))
1484                 (gnus-request-scan group method))
1485            t)
1486          (if (or debug-on-error debug-on-quit)
1487              (inline (gnus-request-group group dont-check method))
1488            (condition-case nil
1489                (inline (gnus-request-group group dont-check method))
1490              ;;(error nil)
1491              (quit
1492               (message "Quit activating %s" group)
1493               nil)))
1494          (unless dont-check
1495            (setq active (gnus-parse-active))
1496            ;; If there are no articles in the group, the GROUP
1497            ;; command may have responded with the `(0 . 0)'.  We
1498            ;; ignore this if we already have an active entry
1499            ;; for the group.
1500            (if (and (zerop (car active))
1501                     (zerop (cdr active))
1502                     (gnus-active group))
1503                (gnus-active group)
1504              (gnus-set-active group active)
1505              ;; Return the new active info.
1506              active)))))
1507
1508 (defun gnus-get-unread-articles-in-group (info active &optional update)
1509   (when active
1510     ;; Allow the backend to update the info in the group.
1511     (when (and update
1512                (gnus-request-update-info
1513                 info (inline (gnus-find-method-for-group
1514                               (gnus-info-group info)))))
1515       (gnus-activate-group (gnus-info-group info) nil t))
1516
1517     (let* ((range (gnus-info-read info))
1518            (num 0))
1519       ;; If a cache is present, we may have to alter the active info.
1520       (when (and gnus-use-cache info)
1521         (inline (gnus-cache-possibly-alter-active
1522                  (gnus-info-group info) active)))
1523       ;; Modify the list of read articles according to what articles
1524       ;; are available; then tally the unread articles and add the
1525       ;; number to the group hash table entry.
1526       (cond
1527        ((zerop (cdr active))
1528         (setq num 0))
1529        ((not range)
1530         (setq num (- (1+ (cdr active)) (car active))))
1531        ((not (listp (cdr range)))
1532         ;; Fix a single (num . num) range according to the
1533         ;; active hash table.
1534         ;; Fix by Carsten Bormann <cabo@Informatik.Uni-Bremen.DE>.
1535         (and (< (cdr range) (car active)) (setcdr range (1- (car active))))
1536         (and (> (cdr range) (cdr active)) (setcdr range (cdr active)))
1537         ;; Compute number of unread articles.
1538         (setq num (max 0 (- (cdr active) (- (1+ (cdr range)) (car range))))))
1539        (t
1540         ;; The read list is a list of ranges.  Fix them according to
1541         ;; the active hash table.
1542         ;; First peel off any elements that are below the lower
1543         ;; active limit.
1544         (while (and (cdr range)
1545                     (>= (car active)
1546                         (or (and (atom (cadr range)) (cadr range))
1547                             (caadr range))))
1548           (if (numberp (car range))
1549               (setcar range
1550                       (cons (car range)
1551                             (or (and (numberp (cadr range))
1552                                      (cadr range))
1553                                 (cdadr range))))
1554             (setcdr (car range)
1555                     (or (and (numberp (nth 1 range)) (nth 1 range))
1556                         (cdadr range))))
1557           (setcdr range (cddr range)))
1558         ;; Adjust the first element to be the same as the lower limit.
1559         (when (and (not (atom (car range)))
1560                    (< (cdar range) (car active)))
1561           (setcdr (car range) (1- (car active))))
1562         ;; Then we want to peel off any elements that are higher
1563         ;; than the upper active limit.
1564         (let ((srange range))
1565           ;; Go past all valid elements.
1566           (while (and (cdr srange)
1567                       (<= (or (and (atom (cadr srange))
1568                                    (cadr srange))
1569                               (caadr srange))
1570                           (cdr active)))
1571             (setq srange (cdr srange)))
1572           (when (cdr srange)
1573             ;; Nuke all remaining invalid elements.
1574             (setcdr srange nil))
1575
1576           ;; Adjust the final element.
1577           (when (and (not (atom (car srange)))
1578                      (> (cdar srange) (cdr active)))
1579             (setcdr (car srange) (cdr active))))
1580         ;; Compute the number of unread articles.
1581         (while range
1582           (setq num (+ num (- (1+ (or (and (atom (car range)) (car range))
1583                                       (cdar range)))
1584                               (or (and (atom (car range)) (car range))
1585                                   (caar range)))))
1586           (setq range (cdr range)))
1587         (setq num (max 0 (- (cdr active) num)))))
1588       ;; Set the number of unread articles.
1589       (when (and info
1590                  (gnus-gethash (gnus-info-group info) gnus-newsrc-hashtb))
1591         (setcar (gnus-gethash (gnus-info-group info) gnus-newsrc-hashtb) num))
1592       num)))
1593
1594 ;; Go though `gnus-newsrc-alist' and compare with `gnus-active-hashtb'
1595 ;; and compute how many unread articles there are in each group.
1596 (defun gnus-get-unread-articles (&optional level)
1597   (setq gnus-server-method-cache nil)
1598   (let* ((newsrc (cdr gnus-newsrc-alist))
1599          (level (or level gnus-activate-level (1+ gnus-level-subscribed)))
1600          (foreign-level
1601           (min
1602            (cond ((and gnus-activate-foreign-newsgroups
1603                        (not (numberp gnus-activate-foreign-newsgroups)))
1604                   (1+ gnus-level-subscribed))
1605                  ((numberp gnus-activate-foreign-newsgroups)
1606                   gnus-activate-foreign-newsgroups)
1607                  (t 0))
1608            level))
1609          scanned-methods info group active method retrieve-groups)
1610     (gnus-message 6 "Checking new news...")
1611
1612     (while newsrc
1613       (setq active (gnus-active (setq group (gnus-info-group
1614                                              (setq info (pop newsrc))))))
1615
1616       ;; Check newsgroups.  If the user doesn't want to check them, or
1617       ;; they can't be checked (for instance, if the news server can't
1618       ;; be reached) we just set the number of unread articles in this
1619       ;; newsgroup to t.  This means that Gnus thinks that there are
1620       ;; unread articles, but it has no idea how many.
1621
1622       ;; To be more explicit:
1623       ;; >0 for an active group with messages
1624       ;; 0 for an active group with no unread messages
1625       ;; nil for non-foreign groups that the user has requested not be checked
1626       ;; t for unchecked foreign groups or bogus groups, or groups that can't
1627       ;;   be checked, for one reason or other.
1628       (if (and (setq method (gnus-info-method info))
1629                (not (inline
1630                       (gnus-server-equal
1631                        gnus-select-method
1632                        (setq method (gnus-server-get-method nil method)))))
1633                (not (gnus-secondary-method-p method)))
1634           ;; These groups are foreign.  Check the level.
1635           (when (and (<= (gnus-info-level info) foreign-level)
1636                      (setq active (gnus-activate-group group 'scan)))
1637             ;; Let the Gnus agent save the active file.
1638             (when (and gnus-agent active (gnus-online method))
1639               (gnus-agent-save-group-info
1640                method (gnus-group-real-name group) active))
1641             (unless (inline (gnus-virtual-group-p group))
1642               (inline (gnus-close-group group)))
1643             (when (fboundp (intern (concat (symbol-name (car method))
1644                                            "-request-update-info")))
1645               (inline (gnus-request-update-info info method))))
1646         ;; These groups are native or secondary.
1647         (cond
1648          ;; We don't want these groups.
1649          ((> (gnus-info-level info) level)
1650           (setq active 'ignore))
1651          ;; Activate groups.
1652          ((not gnus-read-active-file)
1653           (if (gnus-check-backend-function 'retrieve-groups group)
1654               ;; if server support gnus-retrieve-groups we push
1655               ;; the group onto retrievegroups for later checking
1656               (if (assoc method retrieve-groups)
1657                   (setcdr (assoc method retrieve-groups)
1658                           (cons group (cdr (assoc method retrieve-groups))))
1659                 (push (list method group) retrieve-groups))
1660             ;; hack: `nnmail-get-new-mail' changes the mail-source depending
1661             ;; on the group, so we must perform a scan for every group
1662             ;; if the users has any directory mail sources.
1663             ;; hack: if `nnmail-scan-directory-mail-source-once' is non-nil,
1664             ;; for it scan all spool files even when the groups are
1665             ;; not required.
1666             (if (and
1667                  (or nnmail-scan-directory-mail-source-once
1668                      (null (assq 'directory
1669                                  (or mail-sources
1670                                      (if (listp nnmail-spool-file)
1671                                          nnmail-spool-file
1672                                        (list nnmail-spool-file))))))
1673                  (member method scanned-methods))
1674                 (setq active (gnus-activate-group group))
1675               (setq active (gnus-activate-group group 'scan))
1676               (push method scanned-methods))
1677             (when active
1678               (gnus-close-group group))))))
1679
1680       ;; Get the number of unread articles in the group.
1681       (cond
1682        ((eq active 'ignore)
1683         ;; Don't do anything.
1684         )
1685        (active
1686         (inline (gnus-get-unread-articles-in-group info active t)))
1687        (t
1688         ;; The group couldn't be reached, so we nix out the number of
1689         ;; unread articles and stuff.
1690         (gnus-set-active group nil)
1691         (let ((tmp (gnus-gethash group gnus-newsrc-hashtb)))
1692           (when tmp
1693             (setcar tmp t))))))
1694
1695     ;; iterate through groups on methods which support gnus-retrieve-groups
1696     ;; and fetch a partial active file and use it to find new news.
1697     (dolist (rg retrieve-groups)
1698       (let ((method (or (car rg) gnus-select-method))
1699             (groups (cdr rg)))
1700         (when (gnus-check-server method)
1701           ;; Request that the backend scan its incoming messages.
1702           (when (gnus-check-backend-function 'request-scan (car method))
1703             (gnus-request-scan nil method))
1704           (gnus-read-active-file-2
1705            (mapcar (lambda (group) (gnus-group-real-name group)) groups)
1706            method)
1707           (dolist (group groups)
1708             (cond
1709              ((setq active (gnus-active (gnus-info-group
1710                                          (setq info (gnus-get-info group)))))
1711               (inline (gnus-get-unread-articles-in-group info active t)))
1712              (t
1713               ;; The group couldn't be reached, so we nix out the number of
1714               ;; unread articles and stuff.
1715               (gnus-set-active group nil)
1716               (setcar (gnus-gethash group gnus-newsrc-hashtb) t)))))))
1717
1718     (gnus-message 6 "Checking new news...done")))
1719
1720 ;; Create a hash table out of the newsrc alist.  The `car's of the
1721 ;; alist elements are used as keys.
1722 (defun gnus-make-hashtable-from-newsrc-alist ()
1723   (let ((alist gnus-newsrc-alist)
1724         (ohashtb gnus-newsrc-hashtb)
1725         prev)
1726     (setq gnus-newsrc-hashtb (gnus-make-hashtable (length alist)))
1727     (setq alist
1728           (setq prev (setq gnus-newsrc-alist
1729                            (if (equal (caar gnus-newsrc-alist)
1730                                       "dummy.group")
1731                                gnus-newsrc-alist
1732                              (cons (list "dummy.group" 0 nil) alist)))))
1733     (while alist
1734       (gnus-sethash
1735        (caar alist)
1736        ;; Preserve number of unread articles in groups.
1737        (cons (and ohashtb (car (gnus-gethash (caar alist) ohashtb)))
1738              prev)
1739        gnus-newsrc-hashtb)
1740       (setq prev alist
1741             alist (cdr alist)))))
1742
1743 (defun gnus-make-hashtable-from-killed ()
1744   "Create a hash table from the killed and zombie lists."
1745   (let ((lists '(gnus-killed-list gnus-zombie-list))
1746         list)
1747     (setq gnus-killed-hashtb
1748           (gnus-make-hashtable
1749            (+ (length gnus-killed-list) (length gnus-zombie-list))))
1750     (while lists
1751       (setq list (symbol-value (pop lists)))
1752       (while list
1753         (gnus-sethash (car list) (pop list) gnus-killed-hashtb)))))
1754
1755 (defun gnus-parse-active ()
1756   "Parse active info in the nntp server buffer."
1757   (save-excursion
1758     (set-buffer nntp-server-buffer)
1759     (goto-char (point-min))
1760     ;; Parse the result we got from `gnus-request-group'.
1761     (when (looking-at "[0-9]+ [0-9]+ \\([0-9]+\\) [0-9]+")
1762       (goto-char (match-beginning 1))
1763       (cons (read (current-buffer))
1764             (read (current-buffer))))))
1765
1766 (defun gnus-make-articles-unread (group articles)
1767   "Mark ARTICLES in GROUP as unread."
1768   (let* ((info (nth 2 (or (gnus-gethash group gnus-newsrc-hashtb)
1769                           (gnus-gethash (gnus-group-real-name group)
1770                                         gnus-newsrc-hashtb))))
1771          (ranges (gnus-info-read info))
1772          news article)
1773     (while articles
1774       (when (gnus-member-of-range
1775              (setq article (pop articles)) ranges)
1776         (push article news)))
1777     (when news
1778       ;; Enter this list into the group info.
1779       (gnus-info-set-read
1780        info (gnus-remove-from-range (gnus-info-read info) (nreverse news)))
1781
1782       ;; Set the number of unread articles in gnus-newsrc-hashtb.
1783       (gnus-get-unread-articles-in-group info (gnus-active group))
1784
1785       ;; Insert the change into the group buffer and the dribble file.
1786       (gnus-group-update-group group t))))
1787
1788 (defun gnus-make-ascending-articles-unread (group articles)
1789   "Mark ascending ARTICLES in GROUP as unread."
1790   (let* ((entry (or (gnus-gethash group gnus-newsrc-hashtb)
1791                     (gnus-gethash (gnus-group-real-name group)
1792                                   gnus-newsrc-hashtb)))
1793          (info (nth 2 entry))
1794          (ranges (gnus-info-read info))
1795          (r ranges)
1796          modified)
1797
1798     (while articles
1799       (let ((article (pop articles))) ; get the next article to remove from ranges
1800         (while (let ((range (car ranges))) ; note the current range
1801                  (if (atom range)       ; single value range
1802                      (cond ((not range)
1803                             ;; the articles extend past the end of the ranges
1804                             ;; OK - I'm done
1805                             (setq articles nil))
1806                            ((< range article)
1807                             ;; this range preceeds the article. Leave the range unmodified.
1808                             (pop ranges)
1809                             ranges)
1810                            ((= range article)
1811                             ;; this range exactly matches the article; REMOVE THE RANGE.
1812                             ;; NOTE: When the range being removed is the last range, the list is corrupted by inserting null at its end.
1813                             (setcar ranges (cadr ranges))
1814                             (setcdr ranges (cddr ranges))
1815                             (setq modified (if (car ranges) t 'remove-null))
1816                             nil))
1817                    (let ((min (car range))
1818                          (max (cdr range)))
1819                      ;; I have a min/max range to consider
1820                      (cond ((> min max) ; invalid range introduced by splitter
1821                             (setcar ranges (cadr ranges))
1822                             (setcdr ranges (cddr ranges))
1823                             (setq modified (if (car ranges) t 'remove-null))
1824                             ranges)
1825                            ((= min max)
1826                             ;; replace min/max range with a single-value range
1827                             (setcar ranges min)
1828                             ranges)
1829                            ((< max article)
1830                             ;; this range preceeds the article. Leave the range unmodified.
1831                             (pop ranges)
1832                             ranges)
1833                            ((< article min)
1834                             ;; this article preceeds the range.  Return null to move to the
1835                             ;; next article
1836                             nil)
1837                            (t
1838                             ;; this article splits the range into two parts
1839                             (setcdr ranges (cons (cons (1+ article) max) (cdr ranges)))
1840                             (setcdr range (1- article))
1841                             (setq modified t)
1842                             ranges))))))))
1843                   
1844     (when modified
1845       (when (eq modified 'remove-null)
1846         (setq r (delq nil r)))
1847       ;; Enter this list into the group info.
1848       (gnus-info-set-read info r)
1849
1850       ;; Set the number of unread articles in gnus-newsrc-hashtb.
1851       (gnus-get-unread-articles-in-group info (gnus-active group))
1852
1853       ;; Insert the change into the group buffer and the dribble file.
1854       (gnus-group-update-group group t))))
1855
1856 ;; Enter all dead groups into the hashtb.
1857 (defun gnus-update-active-hashtb-from-killed ()
1858   (let ((hashtb (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
1859         (lists (list gnus-killed-list gnus-zombie-list))
1860         killed)
1861     (while lists
1862       (setq killed (car lists))
1863       (while killed
1864         (gnus-sethash (car killed) nil hashtb)
1865         (setq killed (cdr killed)))
1866       (setq lists (cdr lists)))))
1867
1868 (defun gnus-get-killed-groups ()
1869   "Go through the active hashtb and mark all unknown groups as killed."
1870   ;; First make sure active file has been read.
1871   (unless (gnus-read-active-file-p)
1872     (let ((gnus-read-active-file t))
1873       (gnus-read-active-file)))
1874   (unless gnus-killed-hashtb
1875     (gnus-make-hashtable-from-killed))
1876   ;; Go through all newsgroups that are known to Gnus - enlarge kill list.
1877   (mapatoms
1878    (lambda (sym)
1879      (let ((groups 0)
1880            (group (symbol-name sym)))
1881        (if (or (null group)
1882                (gnus-gethash group gnus-killed-hashtb)
1883                (gnus-gethash group gnus-newsrc-hashtb))
1884            ()
1885          (let ((do-sub (gnus-matches-options-n group)))
1886            (if (or (eq do-sub 'subscribe) (eq do-sub 'ignore))
1887                ()
1888              (setq groups (1+ groups))
1889              (push group gnus-killed-list)
1890              (gnus-sethash group group gnus-killed-hashtb))))))
1891    gnus-active-hashtb)
1892   (gnus-dribble-touch))
1893
1894 ;; Get the active file(s) from the backend(s).
1895 (defun gnus-read-active-file (&optional force not-native)
1896   (gnus-group-set-mode-line)
1897   (let ((methods
1898          (mapcar
1899           (lambda (m) (if (stringp m) (gnus-server-get-method nil m) m))
1900           (append
1901            (if (and (not not-native)
1902                     (gnus-check-server gnus-select-method))
1903                ;; The native server is available.
1904                (cons gnus-select-method gnus-secondary-select-methods)
1905              ;; The native server is down, so we just do the
1906              ;; secondary ones.
1907              gnus-secondary-select-methods)
1908            ;; Also read from the archive server.
1909            (when (gnus-archive-server-wanted-p)
1910              (list "archive")))))
1911         method)
1912     (setq gnus-have-read-active-file nil)
1913     (save-excursion
1914       (set-buffer nntp-server-buffer)
1915       (while (setq method (pop methods))
1916         ;; Only do each method once, in case the methods appear more
1917         ;; than once in this list.
1918         (unless (member method methods)
1919           (if (or debug-on-error debug-on-quit)
1920               (gnus-read-active-file-1 method force)
1921             (condition-case ()
1922                 (gnus-read-active-file-1 method force)
1923               ;; We catch C-g so that we can continue past servers
1924               ;; that do not respond.
1925               (quit
1926                (message "Quit reading the active file")
1927                nil))))))))
1928
1929 (defun gnus-read-active-file-1 (method force)
1930   (let (where mesg)
1931     (setq where (nth 1 method)
1932           mesg (format "Reading active file%s via %s..."
1933                        (if (and where (not (zerop (length where))))
1934                            (concat " from " where) "")
1935                        (car method)))
1936     (gnus-message 5 mesg)
1937     (when (gnus-check-server method)
1938       ;; Request that the backend scan its incoming messages.
1939       (when (gnus-check-backend-function 'request-scan (car method))
1940         (gnus-request-scan nil method))
1941       (cond
1942        ((and (eq gnus-read-active-file 'some)
1943              (gnus-check-backend-function 'retrieve-groups (car method))
1944              (not force))
1945         (let ((newsrc (cdr gnus-newsrc-alist))
1946               (gmethod (gnus-server-get-method nil method))
1947               groups info)
1948           (while (setq info (pop newsrc))
1949             (when (inline
1950                     (gnus-server-equal
1951                      (inline
1952                        (gnus-find-method-for-group
1953                         (gnus-info-group info) info))
1954                      gmethod))
1955               (push (gnus-group-real-name (gnus-info-group info))
1956                     groups)))
1957           (gnus-read-active-file-2 groups method)))
1958        ((null method)
1959         t)
1960        (t
1961         (if (not (gnus-request-list method))
1962             (unless (equal method gnus-message-archive-method)
1963               (gnus-error 1 "Cannot read active file from %s server"
1964                           (car method)))
1965           (gnus-message 5 mesg)
1966           (gnus-active-to-gnus-format method gnus-active-hashtb nil t)
1967           ;; We mark this active file as read.
1968           (push method gnus-have-read-active-file)
1969           (gnus-message 5 "%sdone" mesg)))))))
1970
1971 (defun gnus-read-active-file-2 (groups method)
1972   "Read an active file for GROUPS in METHOD using gnus-retrieve-groups."
1973   (when groups
1974     (save-excursion
1975       (set-buffer nntp-server-buffer)
1976       (gnus-check-server method)
1977       (let ((list-type (gnus-retrieve-groups groups method)))
1978         (cond ((not list-type)
1979                (gnus-error
1980                 1.2 "Cannot read partial active file from %s server."
1981                 (car method)))
1982               ((eq list-type 'active)
1983                (gnus-active-to-gnus-format method gnus-active-hashtb nil t))
1984               (t
1985                (gnus-groups-to-gnus-format method gnus-active-hashtb t)))))))
1986
1987 ;; Read an active file and place the results in `gnus-active-hashtb'.
1988 (defun gnus-active-to-gnus-format (&optional method hashtb ignore-errors
1989                                              real-active)
1990   (unless method
1991     (setq method gnus-select-method))
1992   (let ((cur (current-buffer))
1993         (hashtb (or hashtb
1994                     (if (and gnus-active-hashtb
1995                              (not (equal method gnus-select-method)))
1996                         gnus-active-hashtb
1997                       (setq gnus-active-hashtb
1998                             (if (equal method gnus-select-method)
1999                                 (gnus-make-hashtable
2000                                  (count-lines (point-min) (point-max)))
2001                               (gnus-make-hashtable 4096)))))))
2002     ;; Delete unnecessary lines.
2003     (goto-char (point-min))
2004     (cond
2005      ((string= gnus-ignored-newsgroups "")
2006       (delete-matching-lines "^to\\."))
2007      (t
2008       (delete-matching-lines (concat "^to\\.\\|" gnus-ignored-newsgroups))))
2009
2010     (goto-char (point-min))
2011     (unless (re-search-forward "[\\\"]" nil t)
2012       ;; Make the group names readable as a lisp expression even if they
2013       ;; contain special characters.
2014       (goto-char (point-max))
2015       (while (re-search-backward "[][';?()#]" nil t)
2016         (insert ?\\)))
2017
2018     ;; Let the Gnus agent save the active file.
2019     (when (and gnus-agent real-active (gnus-online method))
2020       (gnus-agent-save-active method))
2021
2022     ;; If these are groups from a foreign select method, we insert the
2023     ;; group prefix in front of the group names.
2024     (when (not (gnus-server-equal
2025                 (gnus-server-get-method nil method)
2026                 (gnus-server-get-method nil gnus-select-method)))
2027       (let ((prefix (gnus-group-prefixed-name "" method)))
2028         (goto-char (point-min))
2029         (while (and (not (eobp))
2030                     (progn
2031                       (when (= (following-char) ?\")
2032                         (forward-char 1))
2033                       (insert prefix)
2034                       (zerop (forward-line 1)))))))
2035     ;; Store the active file in a hash table.
2036     (goto-char (point-min))
2037     (let (group max min)
2038       (while (not (eobp))
2039         (condition-case ()
2040             (progn
2041               (narrow-to-region (point) (gnus-point-at-eol))
2042               ;; group gets set to a symbol interned in the hash table
2043               ;; (what a hack!!) - jwz
2044               (setq group (let ((obarray hashtb)) (read cur)))
2045               ;; ### The extended group name scheme makes
2046               ;; the previous optimization strategy sort of pointless...
2047               (when (stringp group)
2048                 (setq group (intern group hashtb)))
2049               (if (and (numberp (setq max (read cur)))
2050                        (numberp (setq min (read cur)))
2051                        (progn
2052                          (skip-chars-forward " \t")
2053                          (not
2054                           (or (eq (char-after) ?=)
2055                               (eq (char-after) ?x)
2056                               (eq (char-after) ?j)))))
2057                   (progn
2058                     (set group (cons min max))
2059                     ;; if group is moderated, stick in moderation table
2060                     (when (eq (char-after) ?m)
2061                       (unless gnus-moderated-hashtb
2062                         (setq gnus-moderated-hashtb (gnus-make-hashtable)))
2063                       (gnus-sethash (symbol-name group) t
2064                                     gnus-moderated-hashtb)))
2065                 (set group nil)))
2066           (error
2067            (and group
2068                 (symbolp group)
2069                 (set group nil))
2070            (unless ignore-errors
2071              (gnus-message 3 "Warning - invalid active: %s"
2072                            (buffer-substring
2073                             (gnus-point-at-bol) (gnus-point-at-eol))))))
2074         (widen)
2075         (forward-line 1)))))
2076
2077 (defun gnus-groups-to-gnus-format (method &optional hashtb real-active)
2078   ;; Parse a "groups" active file.
2079   (let ((cur (current-buffer))
2080         (hashtb (or hashtb
2081                     (if (and method gnus-active-hashtb)
2082                         gnus-active-hashtb
2083                       (setq gnus-active-hashtb
2084                             (gnus-make-hashtable
2085                              (count-lines (point-min) (point-max)))))))
2086         (prefix (and method
2087                      (not (gnus-server-equal
2088                            (gnus-server-get-method nil method)
2089                            (gnus-server-get-method nil gnus-select-method)))
2090                      (gnus-group-prefixed-name "" method))))
2091
2092     ;; Let the Gnus agent save the active file.
2093     (if (and gnus-agent
2094              real-active
2095              (gnus-online method)
2096              (gnus-agent-method-p method))
2097         (progn
2098           (gnus-agent-save-groups method)
2099           (gnus-active-to-gnus-format method hashtb nil real-active))
2100
2101       (goto-char (point-min))
2102       ;; We split this into to separate loops, one with the prefix
2103       ;; and one without to speed the reading up somewhat.
2104       (if prefix
2105           (let (min max opoint group)
2106             (while (not (eobp))
2107               (condition-case ()
2108                   (progn
2109                     (read cur) (read cur)
2110                     (setq min (read cur)
2111                           max (read cur)
2112                           opoint (point))
2113                     (skip-chars-forward " \t")
2114                     (insert prefix)
2115                     (goto-char opoint)
2116                     (set (let ((obarray hashtb)) (read cur))
2117                          (cons min max)))
2118                 (error (and group (symbolp group) (set group nil))))
2119               (forward-line 1)))
2120         (let (min max group)
2121           (while (not (eobp))
2122             (condition-case ()
2123                 (when (eq (char-after) ?2)
2124                   (read cur) (read cur)
2125                   (setq min (read cur)
2126                         max (read cur))
2127                   (set (setq group (let ((obarray hashtb)) (read cur)))
2128                        (cons min max)))
2129               (error (and group (symbolp group) (set group nil))))
2130             (forward-line 1)))))))
2131
2132 (defun gnus-read-newsrc-file (&optional force)
2133   "Read startup file.
2134 If FORCE is non-nil, the .newsrc file is read."
2135   ;; Reset variables that might be defined in the .newsrc.eld file.
2136   (let ((variables (remove 'gnus-format-specs gnus-variable-list)))
2137     (while variables
2138       (set (car variables) nil)
2139       (setq variables (cdr variables))))
2140   (let* ((newsrc-file gnus-current-startup-file)
2141          (quick-file (concat newsrc-file ".el")))
2142     (save-excursion
2143       ;; We always load the .newsrc.eld file.  If always contains
2144       ;; much information that can not be gotten from the .newsrc
2145       ;; file (ticked articles, killed groups, foreign methods, etc.)
2146       (gnus-read-newsrc-el-file quick-file)
2147
2148       (when (and gnus-read-newsrc-file
2149                  (file-exists-p gnus-current-startup-file)
2150                  (or force
2151                      (and (file-newer-than-file-p newsrc-file quick-file)
2152                           (file-newer-than-file-p newsrc-file
2153                                                   (concat quick-file "d")))
2154                      (not gnus-newsrc-alist)))
2155         ;; We read the .newsrc file.  Note that if there if a
2156         ;; .newsrc.eld file exists, it has already been read, and
2157         ;; the `gnus-newsrc-hashtb' has been created.  While reading
2158         ;; the .newsrc file, Gnus will only use the information it
2159         ;; can find there for changing the data already read -
2160         ;; i. e., reading the .newsrc file will not trash the data
2161         ;; already read (except for read articles).
2162         (save-excursion
2163           (gnus-message 5 "Reading %s..." newsrc-file)
2164           (set-buffer (nnheader-find-file-noselect newsrc-file))
2165           (buffer-disable-undo)
2166           (gnus-newsrc-to-gnus-format)
2167           (kill-buffer (current-buffer))
2168           (gnus-message 5 "Reading %s...done" newsrc-file)))
2169
2170       ;; Convert old to new.
2171       (gnus-convert-old-newsrc))))
2172
2173 (defun gnus-convert-old-newsrc ()
2174   "Convert old newsrc into the new format, if needed."
2175   (let ((fcv (and gnus-newsrc-file-version
2176                   (gnus-continuum-version gnus-newsrc-file-version))))
2177     (cond
2178      ;; No .newsrc.eld file was loaded.
2179      ((null fcv) nil)
2180      ;; Gnus 5 .newsrc.eld was loaded.
2181      ((< fcv (gnus-continuum-version "September Gnus v0.1"))
2182       (gnus-convert-old-ticks)))))
2183
2184 (defun gnus-convert-old-ticks ()
2185   (let ((newsrc (cdr gnus-newsrc-alist))
2186         marks info dormant ticked)
2187     (while (setq info (pop newsrc))
2188       (when (setq marks (gnus-info-marks info))
2189         (setq dormant (cdr (assq 'dormant marks))
2190               ticked (cdr (assq 'tick marks)))
2191         (when (or dormant ticked)
2192           (gnus-info-set-read
2193            info
2194            (gnus-add-to-range
2195             (gnus-info-read info)
2196             (nconc (gnus-uncompress-range dormant)
2197                    (gnus-uncompress-range ticked)))))))))
2198
2199 (defun gnus-load (file)
2200   "Load FILE, but in such a way that read errors can be reported."
2201   (with-temp-buffer
2202     (insert-file-contents file)
2203     (while (not (eobp))
2204       (condition-case type
2205           (let ((form (read (current-buffer))))
2206             (eval form))
2207         (error
2208          (unless (eq (car type) 'end-of-file)
2209            (let ((error (format "Error in %s line %d" file
2210                                 (count-lines (point-min) (point)))))
2211              (ding)
2212              (unless (gnus-yes-or-no-p (concat error "; continue? "))
2213                (error "%s" error)))))))))
2214
2215 (defun gnus-read-newsrc-el-file (file)
2216   (let ((ding-file (concat file "d")))
2217     (when (file-exists-p ding-file)
2218       ;; We always, always read the .eld file.
2219       (gnus-message 5 "Reading %s..." ding-file)
2220       (let (gnus-newsrc-assoc)
2221         (let ((coding-system-for-read gnus-ding-file-coding-system))
2222           (gnus-load ding-file))
2223         ;; Older versions of `gnus-format-specs' are no longer valid
2224         ;; in Oort Gnus 0.01.
2225         (let ((version
2226                (and gnus-newsrc-file-version
2227                     (gnus-continuum-version gnus-newsrc-file-version))))
2228           (when (or (not version)
2229                     (< version 5.090009))
2230             (setq gnus-format-specs gnus-default-format-specs)))
2231         (when gnus-newsrc-assoc
2232           (setq gnus-newsrc-alist gnus-newsrc-assoc))))
2233     (gnus-make-hashtable-from-newsrc-alist)
2234     (when (file-newer-than-file-p file ding-file)
2235       ;; Old format quick file
2236       (gnus-message 5 "Reading %s..." file)
2237       ;; The .el file is newer than the .eld file, so we read that one
2238       ;; as well.
2239       (gnus-read-old-newsrc-el-file file)))
2240   (gnus-run-hooks 'gnus-read-newsrc-el-hook))
2241
2242 ;; Parse the old-style quick startup file
2243 (defun gnus-read-old-newsrc-el-file (file)
2244   (let (newsrc killed marked group m info)
2245     (prog1
2246         (let ((gnus-killed-assoc nil)
2247               gnus-marked-assoc gnus-newsrc-alist gnus-newsrc-assoc)
2248           (prog1
2249               (ignore-errors
2250                 (load file t t t))
2251             (setq newsrc gnus-newsrc-assoc
2252                   killed gnus-killed-assoc
2253                   marked gnus-marked-assoc)))
2254       (setq gnus-newsrc-alist nil)
2255       (while (setq group (pop newsrc))
2256         (if (setq info (gnus-get-info (car group)))
2257             (progn
2258               (gnus-info-set-read info (cddr group))
2259               (gnus-info-set-level
2260                info (if (nth 1 group) gnus-level-default-subscribed
2261                       gnus-level-default-unsubscribed))
2262               (push info gnus-newsrc-alist))
2263           (push (setq info
2264                       (list (car group)
2265                             (if (nth 1 group) gnus-level-default-subscribed
2266                               gnus-level-default-unsubscribed)
2267                             (cddr group)))
2268                 gnus-newsrc-alist))
2269         ;; Copy marks into info.
2270         (when (setq m (assoc (car group) marked))
2271           (unless (nthcdr 3 info)
2272             (nconc info (list nil)))
2273           (gnus-info-set-marks
2274            info (list (cons 'tick (gnus-compress-sequence
2275                                    (sort (cdr m) '<) t))))))
2276       (setq newsrc killed)
2277       (while newsrc
2278         (setcar newsrc (caar newsrc))
2279         (setq newsrc (cdr newsrc)))
2280       (setq gnus-killed-list killed))
2281     ;; The .el file version of this variable does not begin with
2282     ;; "options", while the .eld version does, so we just add it if it
2283     ;; isn't there.
2284     (when
2285         gnus-newsrc-options
2286       (when (not (string-match "^ *options" gnus-newsrc-options))
2287         (setq gnus-newsrc-options (concat "options " gnus-newsrc-options)))
2288       (when (not (string-match "\n$" gnus-newsrc-options))
2289         (setq gnus-newsrc-options (concat gnus-newsrc-options "\n")))
2290       ;; Finally, if we read some options lines, we parse them.
2291       (unless (string= gnus-newsrc-options "")
2292         (gnus-newsrc-parse-options gnus-newsrc-options)))
2293
2294     (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist))
2295     (gnus-make-hashtable-from-newsrc-alist)))
2296
2297 (defun gnus-make-newsrc-file (file)
2298   "Make server dependent file name by catenating FILE and server host name."
2299   (let* ((file (expand-file-name file nil))
2300          (real-file (concat file "-" (nth 1 gnus-select-method))))
2301     (if (or (file-exists-p real-file)
2302             (file-exists-p (concat real-file ".el"))
2303             (file-exists-p (concat real-file ".eld")))
2304         real-file
2305       file)))
2306
2307 (defun gnus-newsrc-to-gnus-format ()
2308   (setq gnus-newsrc-options "")
2309   (setq gnus-newsrc-options-n nil)
2310
2311   (unless gnus-active-hashtb
2312     (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
2313   (let ((buf (current-buffer))
2314         (already-read (> (length gnus-newsrc-alist) 1))
2315         group subscribed options-symbol newsrc Options-symbol
2316         symbol reads num1)
2317     (goto-char (point-min))
2318     ;; We intern the symbol `options' in the active hashtb so that we
2319     ;; can `eq' against it later.
2320     (set (setq options-symbol (intern "options" gnus-active-hashtb)) nil)
2321     (set (setq Options-symbol (intern "Options" gnus-active-hashtb)) nil)
2322
2323     (while (not (eobp))
2324       ;; We first read the first word on the line by narrowing and
2325       ;; then reading into `gnus-active-hashtb'.  Most groups will
2326       ;; already exist in that hashtb, so this will save some string
2327       ;; space.
2328       (narrow-to-region
2329        (point)
2330        (progn (skip-chars-forward "^ \t!:\n") (point)))
2331       (goto-char (point-min))
2332       (setq symbol
2333             (and (/= (point-min) (point-max))
2334                  (let ((obarray gnus-active-hashtb)) (read buf))))
2335       (widen)
2336       ;; Now, the symbol we have read is either `options' or a group
2337       ;; name.  If it is an options line, we just add it to a string.
2338       (cond
2339        ((or (eq symbol options-symbol)
2340             (eq symbol Options-symbol))
2341         (setq gnus-newsrc-options
2342               ;; This concating is quite inefficient, but since our
2343               ;; thorough studies show that approx 99.37% of all
2344               ;; .newsrc files only contain a single options line, we
2345               ;; don't give a damn, frankly, my dear.
2346               (concat gnus-newsrc-options
2347                       (buffer-substring
2348                        (gnus-point-at-bol)
2349                        ;; Options may continue on the next line.
2350                        (or (and (re-search-forward "^[^ \t]" nil 'move)
2351                                 (progn (beginning-of-line) (point)))
2352                            (point)))))
2353         (forward-line -1))
2354        (symbol
2355         ;; Group names can be just numbers.
2356         (when (numberp symbol)
2357           (setq symbol (intern (int-to-string symbol) gnus-active-hashtb)))
2358         (unless (boundp symbol)
2359           (set symbol nil))
2360         ;; It was a group name.
2361         (setq subscribed (eq (char-after) ?:)
2362               group (symbol-name symbol)
2363               reads nil)
2364         (if (eolp)
2365             ;; If the line ends here, this is clearly a buggy line, so
2366             ;; we put point a the beginning of line and let the cond
2367             ;; below do the error handling.
2368             (beginning-of-line)
2369           ;; We skip to the beginning of the ranges.
2370           (skip-chars-forward "!: \t"))
2371         ;; We are now at the beginning of the list of read articles.
2372         ;; We read them range by range.
2373         (while
2374             (cond
2375              ((looking-at "[0-9]+")
2376               ;; We narrow and read a number instead of buffer-substring/
2377               ;; string-to-int because it's faster.  narrow/widen is
2378               ;; faster than save-restriction/narrow, and save-restriction
2379               ;; produces a garbage object.
2380               (setq num1 (progn
2381                            (narrow-to-region (match-beginning 0) (match-end 0))
2382                            (read buf)))
2383               (widen)
2384               ;; If the next character is a dash, then this is a range.
2385               (if (eq (char-after) ?-)
2386                   (progn
2387                     ;; We read the upper bound of the range.
2388                     (forward-char 1)
2389                     (if (not (looking-at "[0-9]+"))
2390                         ;; This is a buggy line, by we pretend that
2391                         ;; it's kinda OK.  Perhaps the user should be
2392                         ;; dinged?
2393                         (push num1 reads)
2394                       (push
2395                        (cons num1
2396                              (progn
2397                                (narrow-to-region (match-beginning 0)
2398                                                  (match-end 0))
2399                                (read buf)))
2400                        reads)
2401                       (widen)))
2402                 ;; It was just a simple number, so we add it to the
2403                 ;; list of ranges.
2404                 (push num1 reads))
2405               ;; If the next char in ?\n, then we have reached the end
2406               ;; of the line and return nil.
2407               (not (eq (char-after) ?\n)))
2408              ((eq (char-after) ?\n)
2409               ;; End of line, so we end.
2410               nil)
2411              (t
2412               ;; Not numbers and not eol, so this might be a buggy
2413               ;; line...
2414               (unless (eobp)
2415                 ;; If it was eob instead of ?\n, we allow it.
2416                 ;; The line was buggy.
2417                 (setq group nil)
2418                 (gnus-error 3.1 "Mangled line: %s"
2419                             (buffer-substring (gnus-point-at-bol)
2420                                               (gnus-point-at-eol))))
2421               nil))
2422           ;; Skip past ", ".  Spaces are invalid in these ranges, but
2423           ;; we allow them, because it's a common mistake to put a
2424           ;; space after the comma.
2425           (skip-chars-forward ", "))
2426
2427         ;; We have already read .newsrc.eld, so we gently update the
2428         ;; data in the hash table with the information we have just
2429         ;; read.
2430         (when group
2431           (let ((info (gnus-get-info group))
2432                 level)
2433             (if info
2434                 ;; There is an entry for this file in the alist.
2435                 (progn
2436                   (gnus-info-set-read info (nreverse reads))
2437                   ;; We update the level very gently.  In fact, we
2438                   ;; only change it if there's been a status change
2439                   ;; from subscribed to unsubscribed, or vice versa.
2440                   (setq level (gnus-info-level info))
2441                   (cond ((and (<= level gnus-level-subscribed)
2442                               (not subscribed))
2443                          (setq level (if reads
2444                                          gnus-level-default-unsubscribed
2445                                        (1+ gnus-level-default-unsubscribed))))
2446                         ((and (> level gnus-level-subscribed) subscribed)
2447                          (setq level gnus-level-default-subscribed)))
2448                   (gnus-info-set-level info level))
2449               ;; This is a new group.
2450               (setq info (list group
2451                                (if subscribed
2452                                    gnus-level-default-subscribed
2453                                  (if reads
2454                                      (1+ gnus-level-subscribed)
2455                                    gnus-level-default-unsubscribed))
2456                                (nreverse reads))))
2457             (push info newsrc)))))
2458       (forward-line 1))
2459
2460     (setq newsrc (nreverse newsrc))
2461
2462     (if (not already-read)
2463         ()
2464       ;; We now have two newsrc lists - `newsrc', which is what we
2465       ;; have read from .newsrc, and `gnus-newsrc-alist', which is
2466       ;; what we've read from .newsrc.eld.  We have to merge these
2467       ;; lists.  We do this by "attaching" any (foreign) groups in the
2468       ;; gnus-newsrc-alist to the (native) group that precedes them.
2469       (let ((rc (cdr gnus-newsrc-alist))
2470             (prev gnus-newsrc-alist)
2471             entry mentry)
2472         (while rc
2473           (or (null (nth 4 (car rc)))   ; It's a native group.
2474               (assoc (caar rc) newsrc)  ; It's already in the alist.
2475               (if (setq entry (assoc (caar prev) newsrc))
2476                   (setcdr (setq mentry (memq entry newsrc))
2477                           (cons (car rc) (cdr mentry)))
2478                 (push (car rc) newsrc)))
2479           (setq prev rc
2480                 rc (cdr rc)))))
2481
2482     (setq gnus-newsrc-alist newsrc)
2483     ;; We make the newsrc hashtb.
2484     (gnus-make-hashtable-from-newsrc-alist)
2485
2486     ;; Finally, if we read some options lines, we parse them.
2487     (unless (string= gnus-newsrc-options "")
2488       (gnus-newsrc-parse-options gnus-newsrc-options))))
2489
2490 ;; Parse options lines to find "options -n !all rec.all" and stuff.
2491 ;; The return value will be a list on the form
2492 ;; ((regexp1 . ignore)
2493 ;;  (regexp2 . subscribe)...)
2494 ;; When handling new newsgroups, groups that match a `ignore' regexp
2495 ;; will be ignored, and groups that match a `subscribe' regexp will be
2496 ;; subscribed.  A line like
2497 ;; options -n !all rec.all
2498 ;; will lead to a list that looks like
2499 ;; (("^rec\\..+" . subscribe)
2500 ;;  ("^.+" . ignore))
2501 ;; So all "rec.*" groups will be subscribed, while all the other
2502 ;; groups will be ignored.  Note that "options -n !all rec.all" is very
2503 ;; different from "options -n rec.all !all".
2504 (defun gnus-newsrc-parse-options (options)
2505   (let (out eol)
2506     (save-excursion
2507       (gnus-set-work-buffer)
2508       (insert (regexp-quote options))
2509       ;; First we treat all continuation lines.
2510       (goto-char (point-min))
2511       (while (re-search-forward "\n[ \t]+" nil t)
2512         (replace-match " " t t))
2513       ;; Then we transform all "all"s into ".+"s.
2514       (goto-char (point-min))
2515       (while (re-search-forward "\\ball\\b" nil t)
2516         (replace-match ".+" t t))
2517       (goto-char (point-min))
2518       ;; We remove all other options than the "-n" ones.
2519       (while (re-search-forward "[ \t]-[^n][^-]*" nil t)
2520         (replace-match " ")
2521         (forward-char -1))
2522       (goto-char (point-min))
2523
2524       ;; We are only interested in "options -n" lines - we
2525       ;; ignore the other option lines.
2526       (while (re-search-forward "[ \t]-n" nil t)
2527         (setq eol
2528               (or (save-excursion
2529                     (and (re-search-forward "[ \t]-n" (gnus-point-at-eol) t)
2530                          (- (point) 2)))
2531                   (gnus-point-at-eol)))
2532         ;; Search for all "words"...
2533         (while (re-search-forward "[^ \t,\n]+" eol t)
2534           (if (eq (char-after (match-beginning 0)) ?!)
2535               ;; If the word begins with a bang (!), this is a "not"
2536               ;; spec.  We put this spec (minus the bang) and the
2537               ;; symbol `ignore' into the list.
2538               (push (cons (concat
2539                            "^" (buffer-substring
2540                                 (1+ (match-beginning 0))
2541                                 (match-end 0))
2542                            "\\($\\|\\.\\)")
2543                           'ignore)
2544                     out)
2545             ;; There was no bang, so this is a "yes" spec.
2546             (push (cons (concat "^" (match-string 0) "\\($\\|\\.\\)")
2547                         'subscribe)
2548                   out))))
2549
2550       (setq gnus-newsrc-options-n out))))
2551
2552 (eval-and-compile
2553   (defalias 'gnus-long-file-names
2554     (if (fboundp 'msdos-long-file-names)
2555       'msdos-long-file-names
2556       (lambda () t))))
2557
2558 (defun gnus-save-newsrc-file (&optional force)
2559   "Save .newsrc file."
2560   ;; Note: We cannot save .newsrc file if all newsgroups are removed
2561   ;; from the variable gnus-newsrc-alist.
2562   (when (and (or gnus-newsrc-alist gnus-killed-list)
2563              gnus-current-startup-file)
2564     (save-excursion
2565       (if (and (or gnus-use-dribble-file gnus-slave)
2566                (not force)
2567                (or (not gnus-dribble-buffer)
2568                    (not (buffer-name gnus-dribble-buffer))
2569                    (zerop (save-excursion
2570                             (set-buffer gnus-dribble-buffer)
2571                             (buffer-size)))))
2572           (gnus-message 4 "(No changes need to be saved)")
2573         (gnus-run-hooks 'gnus-save-newsrc-hook)
2574         (if gnus-slave
2575             (gnus-slave-save-newsrc)
2576           ;; Save .newsrc.
2577           (when gnus-save-newsrc-file
2578             (gnus-message 8 "Saving %s..." gnus-current-startup-file)
2579             (gnus-gnus-to-newsrc-format)
2580             (gnus-message 8 "Saving %s...done" gnus-current-startup-file))
2581           ;; Save .newsrc.eld.
2582           (set-buffer (gnus-get-buffer-create " *Gnus-newsrc*"))
2583           (make-local-variable 'version-control)
2584           (setq version-control gnus-backup-startup-file)
2585           (setq buffer-file-name
2586                 (concat gnus-current-startup-file ".eld"))
2587           (setq default-directory (file-name-directory buffer-file-name))
2588           (buffer-disable-undo)
2589           (erase-buffer)
2590           (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file)
2591
2592           (if gnus-save-startup-file-via-temp-buffer
2593               (let ((coding-system-for-write gnus-ding-file-coding-system)
2594                     (standard-output (current-buffer)))
2595                 (gnus-gnus-to-quick-newsrc-format)
2596                 (gnus-run-hooks 'gnus-save-quick-newsrc-hook)
2597                 (save-buffer))
2598             (let ((coding-system-for-write gnus-ding-file-coding-system)
2599                   (version-control gnus-backup-startup-file)
2600                   (startup-file (concat gnus-current-startup-file ".eld"))
2601                   (working-dir (file-name-directory gnus-current-startup-file))
2602                   working-file
2603                   (i -1))
2604               ;; Generate the name of a non-existent file.
2605               (while (progn (setq working-file
2606                                   (format
2607                                    (if (and (eq system-type 'ms-dos)
2608                                             (not (gnus-long-file-names)))
2609                                        "%s#%d.tm#" ; MSDOS limits files to 8+3
2610                                      (if (memq system-type '(vax-vms axp-vms))
2611                                          "%s$tmp$%d"
2612                                        "%s#tmp#%d"))
2613                                    working-dir (setq i (1+ i))))
2614                             (file-exists-p working-file)))
2615
2616               (unwind-protect
2617                   (progn
2618                     (gnus-with-output-to-file
2619                      working-file
2620                      (gnus-gnus-to-quick-newsrc-format)
2621                      (gnus-run-hooks 'gnus-save-quick-newsrc-hook))
2622
2623                     ;; These bindings will mislead the current buffer
2624                     ;; into thinking that it is visiting the startup
2625                     ;; file.
2626                     (let ((buffer-backed-up nil)
2627                           (buffer-file-name startup-file)
2628                           (file-precious-flag t)
2629                           (setmodes (file-modes startup-file)))
2630                       ;; Backup the current version of the startup file.
2631                       (backup-buffer)
2632
2633                       ;; Replace the existing startup file with the temp file.
2634                       (rename-file working-file startup-file t)
2635                       (set-file-modes startup-file setmodes)))
2636                 (condition-case nil
2637                     (delete-file working-file)
2638                   (file-error nil)))))
2639
2640           (gnus-kill-buffer (current-buffer))
2641           (gnus-message
2642            5 "Saving %s.eld...done" gnus-current-startup-file))
2643         (gnus-dribble-delete-file)
2644         (gnus-group-set-mode-line)))))
2645
2646 (defun gnus-gnus-to-quick-newsrc-format ()
2647   "Print Gnus variables such as gnus-newsrc-alist in lisp format."
2648     (princ ";; -*- emacs-lisp -*-\n")
2649     (princ ";; Gnus startup file.\n")
2650     (princ "\
2651 ;; Never delete this file -- if you want to force Gnus to read the
2652 ;; .newsrc file (if you have one), touch .newsrc instead.\n")
2653     (princ "(setq gnus-newsrc-file-version ")
2654     (princ (gnus-prin1-to-string gnus-version))
2655     (princ ")\n")
2656     (let* ((print-length nil)
2657            (gnus-killed-list
2658             (if (and gnus-save-killed-list
2659                      (stringp gnus-save-killed-list))
2660                 (gnus-strip-killed-list)
2661               gnus-killed-list))
2662            (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                 (when (and str charset (featurep 'mule))
2894                   (setq str (mm-decode-coding-string str charset)))
2895                 (set group str)))
2896             (forward-line 1))))
2897       (gnus-message 5 "Reading descriptions file...done")
2898       t))))
2899
2900 (defun gnus-group-get-description (group)
2901   "Get the description of a group by sending XGTITLE to the server."
2902   (when (gnus-request-group-description group)
2903     (save-excursion
2904       (set-buffer nntp-server-buffer)
2905       (goto-char (point-min))
2906       (when (looking-at "[^ \t]+[ \t]+\\(.*\\)")
2907         (match-string 1)))))
2908
2909 ;;;###autoload
2910 (defun gnus-declare-backend (name &rest abilities)
2911   "Declare backend NAME with ABILITIES as a Gnus backend."
2912   (setq gnus-valid-select-methods
2913         (nconc gnus-valid-select-methods
2914                (list (apply 'list name abilities))))
2915   (gnus-redefine-select-method-widget))
2916
2917 (defun gnus-set-default-directory ()
2918   "Set the default directory in the current buffer to `gnus-default-directory'.
2919 If this variable is nil, don't do anything."
2920   (setq default-directory
2921         (if (and gnus-default-directory
2922                  (file-exists-p gnus-default-directory))
2923             (file-name-as-directory (expand-file-name gnus-default-directory))
2924           default-directory)))
2925
2926 (eval-and-compile
2927 (defalias 'gnus-display-time-event-handler 
2928   (if (gnus-boundp 'display-time-timer)
2929       'display-time-event-handler
2930     (lambda () "Does nothing as `display-time-timer' is not bound.
2931 Would otherwise be an alias for `display-time-event-handler'." nil))))
2932
2933 ;;;###autoload
2934 (defun gnus-fixup-nnimap-unread-after-getting-new-news ()
2935   (let (server group info)
2936     (mapatoms
2937      (lambda (sym)
2938        (when (and (setq group (symbol-name sym))
2939                   (gnus-group-entry group)
2940                   (setq info (symbol-value sym)))
2941          (gnus-sethash group (cons (nth 2 info) (cdr (gnus-group-entry group)))
2942                        gnus-newsrc-hashtb)))
2943      (if (boundp 'nnimap-mailbox-info)
2944          (symbol-value 'nnimap-mailbox-info)
2945        (make-vector 1 0)))))
2946
2947
2948 (provide 'gnus-start)
2949
2950 ;;; gnus-start.el ends here
2951
2952