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