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