*** empty log message ***
[gnus] / lisp / gnus-start.el
1 ;;; gnus-start.el --- startup functions for Gnus
2 ;; Copyright (C) 1996 Free Software Foundation, Inc.
3
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
5 ;; Keywords: news
6
7 ;; This file is part of GNU Emacs.
8
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; any later version.
13
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ;; GNU General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
23
24 ;;; Commentary:
25
26 ;;; Code:
27
28 (require 'gnus-load)
29 (require 'gnus)
30 (require 'gnus-win)
31 (require 'gnus-int)
32 (require 'gnus-spec)
33 (require 'gnus-range)
34 (require 'message)
35
36 (defvar gnus-startup-file "~/.newsrc"
37   "*Your `.newsrc' file.
38 `.newsrc-SERVER' will be used instead if that exists.")
39
40 (defvar gnus-init-file "~/.gnus"
41   "*Your Gnus elisp startup file.
42 If a file with the .el or .elc suffixes exist, it will be read
43 instead.")
44
45 (defvar gnus-default-subscribed-newsgroups nil
46   "*This variable lists what newsgroups should be subscribed the first time Gnus is used.
47 It should be a list of strings.
48 If it is `t', Gnus will not do anything special the first time it is
49 started; it'll just use the normal newsgroups subscription methods.")
50
51 (defvar gnus-use-dribble-file t
52   "*Non-nil means that Gnus will use a dribble file to store user updates.
53 If Emacs should crash without saving the .newsrc files, complete
54 information can be restored from the dribble file.")
55
56 (defvar gnus-dribble-directory nil
57   "*The directory where dribble files will be saved.
58 If this variable is nil, the directory where the .newsrc files are
59 saved will be used.")
60
61 (defvar gnus-check-new-newsgroups t
62   "*Non-nil means that Gnus will run gnus-find-new-newsgroups at startup.
63 This normally finds new newsgroups by comparing the active groups the
64 servers have already reported with those Gnus already knows, either alive
65 or killed.
66
67 When any of the following are true, gnus-find-new-newsgroups will instead
68 ask the servers (primary, secondary, and archive servers) to list new
69 groups since the last time it checked:
70   1. This variable is `ask-server'.
71   2. This variable is a list of select methods (see below).
72   3. `gnus-read-active-file' is nil or `some'.
73   4. A prefix argument is given to gnus-find-new-newsgroups interactively.
74
75 Thus, if this variable is `ask-server' or a list of select methods or
76 `gnus-read-active-file' is nil or `some', then the killed list is no
77 longer necessary, so you could safely set `gnus-save-killed-list' to nil.
78
79 This variable can be a list of select methods which Gnus will query with
80 the `ask-server' method in addition to the primary, secondary, and archive
81 servers.
82
83 Eg.
84   (setq gnus-check-new-newsgroups
85         '((nntp \"some.server\") (nntp \"other.server\")))
86
87 If this variable is nil, then you have to tell Gnus explicitly to
88 check for new newsgroups with \\<gnus-group-mode-map>\\[gnus-find-new-newsgroups].")
89
90 (defvar gnus-check-bogus-newsgroups nil
91   "*Non-nil means that Gnus will check and remove bogus newsgroup at startup.
92 If this variable is nil, then you have to tell Gnus explicitly to
93 check for bogus newsgroups with \\<gnus-group-mode-map>\\[gnus-group-check-bogus-groups].")
94
95 (defvar gnus-read-active-file t
96   "*Non-nil means that Gnus will read the entire active file at startup.
97 If this variable is nil, Gnus will only know about the groups in your
98 `.newsrc' file.
99
100 If this variable is `some', Gnus will try to only read the relevant
101 parts of the active file from the server.  Not all servers support
102 this, and it might be quite slow with other servers, but this should
103 generally be faster than both the t and nil value.
104
105 If you set this variable to nil or `some', you probably still want to
106 be told about new newsgroups that arrive.  To do that, set
107 `gnus-check-new-newsgroups' to `ask-server'.  This may not work
108 properly with all servers.")
109
110 (defvar gnus-level-subscribed 5
111   "*Groups with levels less than or equal to this variable are subscribed.")
112
113 (defvar gnus-level-unsubscribed 7
114   "*Groups with levels less than or equal to this variable are unsubscribed.
115 Groups with levels less than `gnus-level-subscribed', which should be
116 less than this variable, are subscribed.")
117
118 (defvar gnus-level-zombie 8
119   "*Groups with this level are zombie groups.")
120
121 (defvar gnus-level-killed 9
122   "*Groups with this level are killed.")
123
124 (defvar gnus-level-default-subscribed 3
125   "*New subscribed groups will be subscribed at this level.")
126
127 (defvar gnus-level-default-unsubscribed 6
128   "*New unsubscribed groups will be unsubscribed at this level.")
129
130 (defvar gnus-activate-level (1+ gnus-level-subscribed)
131   "*Groups higher than this level won't be activated on startup.
132 Setting this variable to something low might save lots of time when
133 you have many groups that you aren't interested in.")
134
135 (defvar gnus-activate-foreign-newsgroups 4
136   "*If nil, Gnus will not check foreign newsgroups at startup.
137 If it is non-nil, it should be a number between one and nine.  Foreign
138 newsgroups that have a level lower or equal to this number will be
139 activated on startup.  For instance, if you want to active all
140 subscribed newsgroups, but not the rest, you'd set this variable to
141 `gnus-level-subscribed'.
142
143 If you subscribe to lots of newsgroups from different servers, startup
144 might take a while.  By setting this variable to nil, you'll save time,
145 but you won't be told how many unread articles there are in the
146 groups.")
147
148 (defvar gnus-save-newsrc-file t
149   "*Non-nil means that Gnus will save the `.newsrc' file.
150 Gnus always saves its own startup file, which is called
151 \".newsrc.eld\".  The file called \".newsrc\" is in a format that can
152 be readily understood by other newsreaders.  If you don't plan on
153 using other newsreaders, set this variable to nil to save some time on
154 exit.")
155
156 (defvar gnus-save-killed-list t
157   "*If non-nil, save the list of killed groups to the startup file.
158 If you set this variable to nil, you'll save both time (when starting
159 and quitting) and space (both memory and disk), but it will also mean
160 that Gnus has no record of which groups are new and which are old, so
161 the automatic new newsgroups subscription methods become meaningless.
162
163 You should always set `gnus-check-new-newsgroups' to `ask-server' or
164 nil if you set this variable to nil.")
165
166 (defvar gnus-ignored-newsgroups
167   (purecopy (mapconcat 'identity
168                        '("^to\\."       ; not "real" groups
169                          "^[0-9. \t]+ " ; all digits in name
170                          "[][\"#'()]"   ; bogus characters
171                          )
172                        "\\|"))
173   "*A regexp to match uninteresting newsgroups in the active file.
174 Any lines in the active file matching this regular expression are
175 removed from the newsgroup list before anything else is done to it,
176 thus making them effectively non-existent.")
177
178 (defvar gnus-subscribe-newsgroup-method 'gnus-subscribe-zombies
179   "*Function called with a group name when new group is detected.
180 A few pre-made functions are supplied: `gnus-subscribe-randomly'
181 inserts new groups at the beginning of the list of groups;
182 `gnus-subscribe-alphabetically' inserts new groups in strict
183 alphabetic order; `gnus-subscribe-hierarchically' inserts new groups
184 in hierarchical newsgroup order; `gnus-subscribe-interactively' asks
185 for your decision; `gnus-subscribe-killed' kills all new groups;
186 `gnus-subscribe-zombies' will make all new groups into zombies.")
187
188 ;; Suggested by a bug report by Hallvard B Furuseth.
189 ;; <h.b.furuseth@usit.uio.no>.
190 (defvar gnus-subscribe-options-newsgroup-method
191   (function gnus-subscribe-alphabetically)
192   "*This function is called to subscribe newsgroups mentioned on \"options -n\" lines.
193 If, for instance, you want to subscribe to all newsgroups in the
194 \"no\" and \"alt\" hierarchies, you'd put the following in your
195 .newsrc file:
196
197 options -n no.all alt.all
198
199 Gnus will the subscribe all new newsgroups in these hierarchies with
200 the subscription method in this variable.")
201
202 (defvar gnus-subscribe-hierarchical-interactive nil
203   "*If non-nil, Gnus will offer to subscribe hierarchically.
204 When a new hierarchy appears, Gnus will ask the user:
205
206 'alt.binaries': Do you want to subscribe to this hierarchy? ([d]ys):
207
208 If the user pressed `d', Gnus will descend the hierarchy, `y' will
209 subscribe to all newsgroups in the hierarchy and `s' will skip this
210 hierarchy in its entirety.")
211
212 (defvar gnus-auto-subscribed-groups
213   "^nnml\\|^nnfolder\\|^nnmbox\\|^nnmh\\|^nnbabyl"
214   "*All new groups that match this regexp will be subscribed automatically.
215 Note that this variable only deals with new groups.  It has no effect
216 whatsoever on old groups.
217
218 New groups that match this regexp will not be handled by
219 `gnus-subscribe-newsgroup-method'.  Instead, they will
220 be subscribed using `gnus-subscribe-options-newsgroup-method'.")
221
222 (defvar gnus-options-subscribe nil
223   "*All new groups matching this regexp will be subscribed unconditionally.
224 Note that this variable deals only with new newsgroups.  This variable
225 does not affect old newsgroups.
226
227 New groups that match this regexp will not be handled by
228 `gnus-subscribe-newsgroup-method'.  Instead, they will
229 be subscribed using `gnus-subscribe-options-newsgroup-method'.")
230
231 (defvar gnus-options-not-subscribe nil
232   "*All new groups matching this regexp will be ignored.
233 Note that this variable deals only with new newsgroups.  This variable
234 does not affect old (already subscribed) newsgroups.")
235
236 (defvar gnus-modtime-botch nil
237   "*Non-nil means .newsrc should be deleted prior to save.  
238 Its use is due to the bogus appearance that .newsrc was modified on
239 disc.")
240
241 (defvar gnus-check-bogus-groups-hook nil
242   "A hook run after removing bogus groups.")
243
244 (defvar gnus-startup-hook nil
245   "*A hook called at startup.
246 This hook is called after Gnus is connected to the NNTP server.")
247
248 (defvar gnus-get-new-news-hook nil
249   "*A hook run just before Gnus checks for new news.")
250
251 (defvar gnus-after-getting-new-news-hook nil
252   "*A hook run after Gnus checks for new news.")
253
254 (defvar gnus-save-newsrc-hook nil
255   "*A hook called before saving any of the newsrc files.")
256
257 (defvar gnus-save-quick-newsrc-hook nil
258   "*A hook called just before saving the quick newsrc file.
259 Can be used to turn version control on or off.")
260
261 (defvar gnus-save-standard-newsrc-hook nil
262   "*A hook called just before saving the standard newsrc file.
263 Can be used to turn version control on or off.")
264
265 ;;; Internal variables
266
267 (defvar gnus-newsrc-file-version nil)
268 (defvar gnus-override-subscribe-method nil)
269 (defvar gnus-dribble-buffer nil)
270 (defvar gnus-newsrc-options nil
271   "Options line in the .newsrc file.")
272
273 (defvar gnus-newsrc-options-n nil
274   "List of regexps representing groups to be subscribed/ignored unconditionally.")
275
276 (defvar gnus-newsrc-last-checked-date nil
277   "Date Gnus last asked server for new newsgroups.")
278
279 (defvar gnus-current-startup-file nil
280   "Startup file for the current host.")
281
282 ;; Byte-compiler warning.
283 (defvar gnus-group-line-format)
284
285 ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
286 (defvar gnus-init-inhibit nil)
287 (defun gnus-read-init-file (&optional inhibit-next)
288   (if gnus-init-inhibit
289       (setq gnus-init-inhibit nil)
290     (setq gnus-init-inhibit inhibit-next)
291     (and gnus-init-file
292          (or (and (file-exists-p gnus-init-file)
293                   ;; Don't try to load a directory.
294                   (not (file-directory-p gnus-init-file)))
295              (file-exists-p (concat gnus-init-file ".el"))
296              (file-exists-p (concat gnus-init-file ".elc")))
297          (condition-case var
298              (load gnus-init-file nil t)
299            (error
300             (error "Error in %s: %s" gnus-init-file var))))))
301
302 ;; For subscribing new newsgroup
303
304 (defun gnus-subscribe-hierarchical-interactive (groups)
305   (let ((groups (sort groups 'string<))
306         prefixes prefix start ans group starts)
307     (while groups
308       (setq prefixes (list "^"))
309       (while (and groups prefixes)
310         (while (not (string-match (car prefixes) (car groups)))
311           (setq prefixes (cdr prefixes)))
312         (setq prefix (car prefixes))
313         (setq start (1- (length prefix)))
314         (if (and (string-match "[^\\.]\\." (car groups) start)
315                  (cdr groups)
316                  (setq prefix
317                        (concat "^" (substring (car groups) 0 (match-end 0))))
318                  (string-match prefix (cadr groups)))
319             (progn
320               (setq prefixes (cons prefix prefixes))
321               (message "Descend hierarchy %s? ([y]nsq): "
322                        (substring prefix 1 (1- (length prefix))))
323               (while (not (memq (setq ans (read-char)) '(?y ?\n ?n ?s ?q)))
324                 (ding)
325                 (message "Descend hierarchy %s? ([y]nsq): "
326                          (substring prefix 1 (1- (length prefix)))))
327               (cond ((= ans ?n)
328                      (while (and groups
329                                  (string-match prefix
330                                                (setq group (car groups))))
331                        (setq gnus-killed-list
332                              (cons group gnus-killed-list))
333                        (gnus-sethash group group gnus-killed-hashtb)
334                        (setq groups (cdr groups)))
335                      (setq starts (cdr starts)))
336                     ((= ans ?s)
337                      (while (and groups
338                                  (string-match prefix
339                                                (setq group (car groups))))
340                        (gnus-sethash group group gnus-killed-hashtb)
341                        (gnus-subscribe-alphabetically (car groups))
342                        (setq groups (cdr groups)))
343                      (setq starts (cdr starts)))
344                     ((= ans ?q)
345                      (while groups
346                        (setq group (car groups))
347                        (setq gnus-killed-list (cons group gnus-killed-list))
348                        (gnus-sethash group group gnus-killed-hashtb)
349                        (setq groups (cdr groups))))
350                     (t nil)))
351           (message "Subscribe %s? ([n]yq)" (car groups))
352           (while (not (memq (setq ans (read-char)) '(?y ?\n ?q ?n)))
353             (ding)
354             (message "Subscribe %s? ([n]yq)" (car groups)))
355           (setq group (car groups))
356           (cond ((= ans ?y)
357                  (gnus-subscribe-alphabetically (car groups))
358                  (gnus-sethash group group gnus-killed-hashtb))
359                 ((= ans ?q)
360                  (while groups
361                    (setq group (car groups))
362                    (setq gnus-killed-list (cons group gnus-killed-list))
363                    (gnus-sethash group group gnus-killed-hashtb)
364                    (setq groups (cdr groups))))
365                 (t
366                  (setq gnus-killed-list (cons group gnus-killed-list))
367                  (gnus-sethash group group gnus-killed-hashtb)))
368           (setq groups (cdr groups)))))))
369
370 (defun gnus-subscribe-randomly (newsgroup)
371   "Subscribe new NEWSGROUP by making it the first newsgroup."
372   (gnus-subscribe-newsgroup newsgroup))
373
374 (defun gnus-subscribe-alphabetically (newgroup)
375   "Subscribe new NEWSGROUP and insert it in alphabetical order."
376   (let ((groups (cdr gnus-newsrc-alist))
377         before)
378     (while (and (not before) groups)
379       (if (string< newgroup (caar groups))
380           (setq before (caar groups))
381         (setq groups (cdr groups))))
382     (gnus-subscribe-newsgroup newgroup before)))
383
384 (defun gnus-subscribe-hierarchically (newgroup)
385   "Subscribe new NEWSGROUP and insert it in hierarchical newsgroup order."
386   ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
387   (save-excursion
388     (set-buffer (find-file-noselect gnus-current-startup-file))
389     (let ((groupkey newgroup)
390           before)
391       (while (and (not before) groupkey)
392         (goto-char (point-min))
393         (let ((groupkey-re
394                (concat "^\\(" (regexp-quote groupkey) ".*\\)[!:]")))
395           (while (and (re-search-forward groupkey-re nil t)
396                       (progn
397                         (setq before (match-string 1))
398                         (string< before newgroup)))))
399         ;; Remove tail of newsgroup name (eg. a.b.c -> a.b)
400         (setq groupkey
401               (if (string-match "^\\(.*\\)\\.[^.]+$" groupkey)
402                   (substring groupkey (match-beginning 1) (match-end 1)))))
403       (gnus-subscribe-newsgroup newgroup before))
404     (kill-buffer (current-buffer))))
405
406 (defun gnus-subscribe-interactively (group)
407   "Subscribe the new GROUP interactively.
408 It is inserted in hierarchical newsgroup order if subscribed.  If not,
409 it is killed."
410   (if (gnus-y-or-n-p (format "Subscribe new newsgroup: %s " group))
411       (gnus-subscribe-hierarchically group)
412     (push group gnus-killed-list)))
413
414 (defun gnus-subscribe-zombies (group)
415   "Make the new GROUP into a zombie group."
416   (push group gnus-zombie-list))
417
418 (defun gnus-subscribe-killed (group)
419   "Make the new GROUP a killed group."
420   (push group gnus-killed-list))
421
422 (defun gnus-subscribe-newsgroup (newsgroup &optional next)
423   "Subscribe new NEWSGROUP.
424 If NEXT is non-nil, it is inserted before NEXT.  Otherwise it is made
425 the first newsgroup."
426   (save-excursion
427     (goto-char (point-min))
428     ;; We subscribe the group by changing its level to `subscribed'.
429     (gnus-group-change-level
430      newsgroup gnus-level-default-subscribed
431      gnus-level-killed (gnus-gethash (or next "dummy.group")
432                                      gnus-newsrc-hashtb))
433     (gnus-message 5 "Subscribe newsgroup: %s" newsgroup)))
434
435 (defun gnus-read-active-file-p ()
436   "Say whether the active file has been read from `gnus-select-method'."
437   (memq gnus-select-method gnus-have-read-active-file))
438
439 ;;; General various misc type functions.
440
441 ;; Silence byte-compiler.
442 (defvar gnus-current-headers)
443 (defvar gnus-thread-indent-array)
444 (defvar gnus-newsgroup-name)
445 (defvar gnus-newsgroup-headers)
446 (defvar gnus-group-list-mode)
447 (defvar gnus-group-mark-positions)
448 (defvar gnus-newsgroup-data)
449 (defvar gnus-newsgroup-unreads)
450 (defvar nnoo-state-alist)
451 (defvar gnus-current-select-method)
452 (defun gnus-clear-system ()
453   "Clear all variables and buffers."
454   ;; Clear Gnus variables.
455   (let ((variables gnus-variable-list))
456     (while variables
457       (set (car variables) nil)
458       (setq variables (cdr variables))))
459   ;; Clear other internal variables.
460   (setq gnus-list-of-killed-groups nil
461         gnus-have-read-active-file nil
462         gnus-newsrc-alist nil
463         gnus-newsrc-hashtb nil
464         gnus-killed-list nil
465         gnus-zombie-list nil
466         gnus-killed-hashtb nil
467         gnus-active-hashtb nil
468         gnus-moderated-list nil
469         gnus-description-hashtb nil
470         gnus-current-headers nil
471         gnus-thread-indent-array nil
472         gnus-newsgroup-headers nil
473         gnus-newsgroup-name nil
474         gnus-server-alist nil
475         gnus-group-list-mode nil
476         gnus-opened-servers nil
477         gnus-group-mark-positions nil
478         gnus-newsgroup-data nil
479         gnus-newsgroup-unreads nil
480         nnoo-state-alist nil
481         gnus-current-select-method nil)
482   (gnus-shutdown 'gnus)
483   ;; Kill the startup file.
484   (and gnus-current-startup-file
485        (get-file-buffer gnus-current-startup-file)
486        (kill-buffer (get-file-buffer gnus-current-startup-file)))
487   ;; Clear the dribble buffer.
488   (gnus-dribble-clear)
489   ;; Kill global KILL file buffer.
490   (when (get-file-buffer (gnus-newsgroup-kill-file nil))
491     (kill-buffer (get-file-buffer (gnus-newsgroup-kill-file nil))))
492   (gnus-kill-buffer nntp-server-buffer)
493   ;; Kill Gnus buffers.
494   (while gnus-buffer-list
495     (gnus-kill-buffer (pop gnus-buffer-list)))
496   ;; Remove Gnus frames.
497   (gnus-kill-gnus-frames))
498
499 (defun gnus-no-server-1 (&optional arg slave)
500   "Read network news.
501 If ARG is a positive number, Gnus will use that as the
502 startup level.  If ARG is nil, Gnus will be started at level 2.
503 If ARG is non-nil and not a positive number, Gnus will
504 prompt the user for the name of an NNTP server to use.
505 As opposed to `gnus', this command will not connect to the local server."
506   (interactive "P")
507   (let ((val (or arg (1- gnus-level-default-subscribed))))
508     (gnus val t slave)
509     (make-local-variable 'gnus-group-use-permanent-levels)
510     (setq gnus-group-use-permanent-levels val)))
511
512 (defun gnus-1 (&optional arg dont-connect slave)
513   "Read network news.
514 If ARG is non-nil and a positive number, Gnus will use that as the
515 startup level.  If ARG is non-nil and not a positive number, Gnus will
516 prompt the user for the name of an NNTP server to use."
517   (interactive "P")
518
519   (if (and (get-buffer gnus-group-buffer)
520            (save-excursion
521              (set-buffer gnus-group-buffer)
522              (eq major-mode 'gnus-group-mode)))
523       (progn
524         (switch-to-buffer gnus-group-buffer)
525         (gnus-group-get-new-news))
526
527     (gnus-splash)
528     (gnus-clear-system)
529     (nnheader-init-server-buffer)
530     (gnus-read-init-file)
531     (setq gnus-slave slave)
532
533     (when (string-match "xemacs" (emacs-version))
534       (gnus-splash))
535
536     (let ((level (and (numberp arg) (> arg 0) arg))
537           did-connect)
538       (unwind-protect
539           (progn
540             (or dont-connect
541                 (setq did-connect
542                       (gnus-start-news-server (and arg (not level))))))
543         (if (and (not dont-connect)
544                  (not did-connect))
545             (gnus-group-quit)
546           (run-hooks 'gnus-startup-hook)
547           ;; NNTP server is successfully open.
548
549           ;; Find the current startup file name.
550           (setq gnus-current-startup-file
551                 (gnus-make-newsrc-file gnus-startup-file))
552
553           ;; Read the dribble file.
554           (when (or gnus-slave gnus-use-dribble-file)
555             (gnus-dribble-read-file))
556
557           ;; Allow using GroupLens predictions.
558           (when gnus-use-grouplens
559             (bbb-login)
560             (add-hook 'gnus-summary-mode-hook 'gnus-grouplens-mode))
561
562           ;; Do the actual startup.
563           (gnus-setup-news nil level dont-connect)
564           ;; Generate the group buffer.
565           (gnus-group-list-groups level)
566           (gnus-group-first-unread-group)
567           (gnus-configure-windows 'group)
568           (gnus-group-set-mode-line))))))
569
570 ;;;###autoload
571 (defun gnus-unload ()
572   "Unload all Gnus features."
573   (interactive)
574   (or (boundp 'load-history)
575       (error "Sorry, `gnus-unload' is not implemented in this Emacs version."))
576   (let ((history load-history)
577         feature)
578     (while history
579       (and (string-match "^\\(gnus\\|nn\\)" (caar history))
580            (setq feature (cdr (assq 'provide (car history))))
581            (unload-feature feature 'force))
582       (setq history (cdr history)))))
583
584 \f
585 ;;;
586 ;;; Dribble file
587 ;;;
588
589 (defvar gnus-dribble-ignore nil)
590 (defvar gnus-dribble-eval-file nil)
591
592 (defun gnus-dribble-file-name ()
593   "Return the dribble file for the current .newsrc."
594   (concat
595    (if gnus-dribble-directory
596        (concat (file-name-as-directory gnus-dribble-directory)
597                (file-name-nondirectory gnus-current-startup-file))
598      gnus-current-startup-file)
599    "-dribble"))
600
601 (defun gnus-dribble-enter (string)
602   "Enter STRING into the dribble buffer."
603   (if (and (not gnus-dribble-ignore)
604            gnus-dribble-buffer
605            (buffer-name gnus-dribble-buffer))
606       (let ((obuf (current-buffer)))
607         (set-buffer gnus-dribble-buffer)
608         (insert string "\n")
609         (set-window-point (get-buffer-window (current-buffer)) (point-max))
610         (bury-buffer gnus-dribble-buffer)
611         (set-buffer obuf))))
612
613 (defun gnus-dribble-read-file ()
614   "Read the dribble file from disk."
615   (let ((dribble-file (gnus-dribble-file-name)))
616     (save-excursion
617       (set-buffer (setq gnus-dribble-buffer
618                         (get-buffer-create
619                          (file-name-nondirectory dribble-file))))
620       (gnus-add-current-to-buffer-list)
621       (erase-buffer)
622       (setq buffer-file-name dribble-file)
623       (auto-save-mode t)
624       (buffer-disable-undo (current-buffer))
625       (bury-buffer (current-buffer))
626       (set-buffer-modified-p nil)
627       (let ((auto (make-auto-save-file-name))
628             (gnus-dribble-ignore t)
629             modes)
630         (when (or (file-exists-p auto) (file-exists-p dribble-file))
631           ;; Load whichever file is newest -- the auto save file
632           ;; or the "real" file.
633           (if (file-newer-than-file-p auto dribble-file)
634               (insert-file-contents auto)
635             (insert-file-contents dribble-file))
636           (unless (zerop (buffer-size))
637             (set-buffer-modified-p t))
638           ;; Set the file modes to reflect the .newsrc file modes.
639           (save-buffer)
640           (when (and (file-exists-p gnus-current-startup-file)
641                      (setq modes (file-modes gnus-current-startup-file)))
642             (set-file-modes dribble-file modes))
643           ;; Possibly eval the file later.
644           (when (gnus-y-or-n-p
645                  "Auto-save file exists.  Do you want to read it? ")
646             (setq gnus-dribble-eval-file t)))))))
647
648 (defun gnus-dribble-eval-file ()
649   (when gnus-dribble-eval-file
650     (setq gnus-dribble-eval-file nil)
651     (save-excursion
652       (let ((gnus-dribble-ignore t))
653         (set-buffer gnus-dribble-buffer)
654         (eval-buffer (current-buffer))))))
655
656 (defun gnus-dribble-delete-file ()
657   (when (file-exists-p (gnus-dribble-file-name))
658     (delete-file (gnus-dribble-file-name)))
659   (when gnus-dribble-buffer
660     (save-excursion
661       (set-buffer gnus-dribble-buffer)
662       (let ((auto (make-auto-save-file-name)))
663         (if (file-exists-p auto)
664             (delete-file auto))
665         (erase-buffer)
666         (set-buffer-modified-p nil)))))
667
668 (defun gnus-dribble-save ()
669   (when (and gnus-dribble-buffer
670              (buffer-name gnus-dribble-buffer))
671     (save-excursion
672       (set-buffer gnus-dribble-buffer)
673       (save-buffer))))
674
675 (defun gnus-dribble-clear ()
676   (when (gnus-buffer-exists-p gnus-dribble-buffer)
677     (save-excursion
678       (set-buffer gnus-dribble-buffer)
679       (erase-buffer)
680       (set-buffer-modified-p nil)
681       (setq buffer-saved-size (buffer-size)))))
682
683 \f
684 ;;;
685 ;;; Active & Newsrc File Handling
686 ;;;
687
688 (defun gnus-setup-news (&optional rawfile level dont-connect)
689   "Setup news information.
690 If RAWFILE is non-nil, the .newsrc file will also be read.
691 If LEVEL is non-nil, the news will be set up at level LEVEL."
692   (let ((init (not (and gnus-newsrc-alist gnus-active-hashtb (not rawfile)))))
693
694     (when init 
695       ;; Clear some variables to re-initialize news information.
696       (setq gnus-newsrc-alist nil
697             gnus-active-hashtb nil)
698       ;; Read the newsrc file and create `gnus-newsrc-hashtb'.
699       (gnus-read-newsrc-file rawfile))
700
701     (when (and (not (assoc "archive" gnus-server-alist))
702                (gnus-archive-server-wanted-p))
703       (push (cons "archive" gnus-message-archive-method)
704             gnus-server-alist))
705
706     ;; If we don't read the complete active file, we fill in the
707     ;; hashtb here.
708     (if (or (null gnus-read-active-file)
709             (eq gnus-read-active-file 'some))
710         (gnus-update-active-hashtb-from-killed))
711
712     ;; Read the active file and create `gnus-active-hashtb'.
713     ;; If `gnus-read-active-file' is nil, then we just create an empty
714     ;; hash table.  The partial filling out of the hash table will be
715     ;; done in `gnus-get-unread-articles'.
716     (and gnus-read-active-file
717          (not level)
718          (gnus-read-active-file))
719
720     (or gnus-active-hashtb
721         (setq gnus-active-hashtb (make-vector 4095 0)))
722
723     ;; Initialize the cache.
724     (when gnus-use-cache
725       (gnus-cache-open))
726
727     ;; Possibly eval the dribble file.
728     (and init (or gnus-use-dribble-file gnus-slave) (gnus-dribble-eval-file))
729
730     ;; Slave Gnusii should then clear the dribble buffer.
731     (when (and init gnus-slave)
732       (gnus-dribble-clear))
733
734     (gnus-update-format-specifications)
735
736     ;; See whether we need to read the description file.
737     (if (and (string-match "%[-,0-9]*D" gnus-group-line-format)
738              (not gnus-description-hashtb)
739              (not dont-connect)
740              gnus-read-active-file)
741         (gnus-read-all-descriptions-files))
742
743     ;; Find new newsgroups and treat them.
744     (if (and init gnus-check-new-newsgroups (not level)
745              (gnus-check-server gnus-select-method))
746         (gnus-find-new-newsgroups))
747
748     ;; We might read in new NoCeM messages here.
749     (when (and gnus-use-nocem 
750                (not level)
751                (not dont-connect))
752       (gnus-nocem-scan-groups))
753
754     ;; Find the number of unread articles in each non-dead group.
755     (let ((gnus-read-active-file (and (not level) gnus-read-active-file)))
756       (gnus-get-unread-articles level))
757
758     (if (and init gnus-check-bogus-newsgroups
759              gnus-read-active-file (not level)
760              (gnus-server-opened gnus-select-method))
761         (gnus-check-bogus-newsgroups))))
762
763 (defun gnus-find-new-newsgroups (&optional arg)
764   "Search for new newsgroups and add them.
765 Each new newsgroup will be treated with `gnus-subscribe-newsgroup-method.'
766 The `-n' option line from .newsrc is respected.
767 If ARG (the prefix), use the `ask-server' method to query
768 the server for new groups."
769   (interactive "P")
770   (let ((check (if (or (and arg (not (listp gnus-check-new-newsgroups)))
771                        (null gnus-read-active-file)
772                        (eq gnus-read-active-file 'some))
773                    'ask-server gnus-check-new-newsgroups)))
774     (unless (gnus-check-first-time-used)
775       (if (or (consp check)
776               (eq check 'ask-server))
777           ;; Ask the server for new groups.
778           (gnus-ask-server-for-new-groups)
779         ;; Go through the active hashtb and look for new groups.
780         (let ((groups 0)
781               group new-newsgroups)
782           (gnus-message 5 "Looking for new newsgroups...")
783           (unless gnus-have-read-active-file
784             (gnus-read-active-file))
785           (setq gnus-newsrc-last-checked-date (current-time-string))
786           (unless gnus-killed-hashtb
787             (gnus-make-hashtable-from-killed))
788           ;; Go though every newsgroup in `gnus-active-hashtb' and compare
789           ;; with `gnus-newsrc-hashtb' and `gnus-killed-hashtb'.
790           (mapatoms
791            (lambda (sym)
792              (if (or (null (setq group (symbol-name sym)))
793                      (not (boundp sym))
794                      (null (symbol-value sym))
795                      (gnus-gethash group gnus-killed-hashtb)
796                      (gnus-gethash group gnus-newsrc-hashtb))
797                  ()
798                (let ((do-sub (gnus-matches-options-n group)))
799                  (cond
800                   ((eq do-sub 'subscribe)
801                    (setq groups (1+ groups))
802                    (gnus-sethash group group gnus-killed-hashtb)
803                    (funcall gnus-subscribe-options-newsgroup-method group))
804                   ((eq do-sub 'ignore)
805                    nil)
806                   (t
807                    (setq groups (1+ groups))
808                    (gnus-sethash group group gnus-killed-hashtb)
809                    (if gnus-subscribe-hierarchical-interactive
810                        (setq new-newsgroups (cons group new-newsgroups))
811                      (funcall gnus-subscribe-newsgroup-method group)))))))
812            gnus-active-hashtb)
813           (when new-newsgroups
814             (gnus-subscribe-hierarchical-interactive new-newsgroups))
815           ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
816           (if (> groups 0)
817               (gnus-message 6 "%d new newsgroup%s arrived."
818                             groups (if (> groups 1) "s have" " has"))
819             (gnus-message 6 "No new newsgroups.")))))))
820
821 (defun gnus-matches-options-n (group)
822   ;; Returns `subscribe' if the group is to be unconditionally
823   ;; subscribed, `ignore' if it is to be ignored, and nil if there is
824   ;; no match for the group.
825
826   ;; First we check the two user variables.
827   (cond
828    ((and gnus-options-subscribe
829          (string-match gnus-options-subscribe group))
830     'subscribe)
831    ((and gnus-auto-subscribed-groups
832          (string-match gnus-auto-subscribed-groups group))
833     'subscribe)
834    ((and gnus-options-not-subscribe
835          (string-match gnus-options-not-subscribe group))
836     'ignore)
837    ;; Then we go through the list that was retrieved from the .newsrc
838    ;; file.  This list has elements on the form
839    ;; `(REGEXP . {ignore,subscribe})'.  The first match found (the list
840    ;; is in the reverse order of the options line) is returned.
841    (t
842     (let ((regs gnus-newsrc-options-n))
843       (while (and regs
844                   (not (string-match (caar regs) group)))
845         (setq regs (cdr regs)))
846       (and regs (cdar regs))))))
847
848 (defun gnus-ask-server-for-new-groups ()
849   (let* ((date (or gnus-newsrc-last-checked-date (current-time-string)))
850          (methods (cons gnus-select-method
851                         (nconc
852                          (when (gnus-archive-server-wanted-p)
853                            (list "archive"))
854                          (append
855                           (and (consp gnus-check-new-newsgroups)
856                                gnus-check-new-newsgroups)
857                           gnus-secondary-select-methods))))
858          (groups 0)
859          (new-date (current-time-string))
860          group new-newsgroups got-new method hashtb
861          gnus-override-subscribe-method)
862     ;; Go through both primary and secondary select methods and
863     ;; request new newsgroups.
864     (while (setq method (gnus-server-get-method nil (pop methods)))
865       (setq new-newsgroups nil)
866       (setq gnus-override-subscribe-method method)
867       (when (and (gnus-check-server method)
868                  (gnus-request-newgroups date method))
869         (save-excursion
870           (setq got-new t)
871           (setq hashtb (gnus-make-hashtable 100))
872           (set-buffer nntp-server-buffer)
873           ;; Enter all the new groups into a hashtable.
874           (gnus-active-to-gnus-format method hashtb 'ignore))
875         ;; Now all new groups from `method' are in `hashtb'.
876         (mapatoms
877          (lambda (group-sym)
878            (if (or (null (setq group (symbol-name group-sym)))
879                    (not (boundp group-sym))
880                    (null (symbol-value group-sym))
881                    (gnus-gethash group gnus-newsrc-hashtb)
882                    (member group gnus-zombie-list)
883                    (member group gnus-killed-list))
884                ;; The group is already known.
885                ()
886              ;; Make this group active.
887              (when (symbol-value group-sym)
888                (gnus-set-active group (symbol-value group-sym)))
889              ;; Check whether we want it or not.
890              (let ((do-sub (gnus-matches-options-n group)))
891                (cond
892                 ((eq do-sub 'subscribe)
893                  (incf groups)
894                  (gnus-sethash group group gnus-killed-hashtb)
895                  (funcall gnus-subscribe-options-newsgroup-method group))
896                 ((eq do-sub 'ignore)
897                  nil)
898                 (t
899                  (incf groups)
900                  (gnus-sethash group group gnus-killed-hashtb)
901                  (if gnus-subscribe-hierarchical-interactive
902                      (push group new-newsgroups)
903                    (funcall gnus-subscribe-newsgroup-method group)))))))
904          hashtb))
905       (when new-newsgroups
906         (gnus-subscribe-hierarchical-interactive new-newsgroups)))
907     ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
908     (when (> groups 0)
909       (gnus-message 6 "%d new newsgroup%s arrived."
910                     groups (if (> groups 1) "s have" " has")))
911     (and got-new (setq gnus-newsrc-last-checked-date new-date))
912     got-new))
913
914 (defun gnus-check-first-time-used ()
915   (if (or (> (length gnus-newsrc-alist) 1)
916           (file-exists-p gnus-startup-file)
917           (file-exists-p (concat gnus-startup-file ".el"))
918           (file-exists-p (concat gnus-startup-file ".eld")))
919       nil
920     (gnus-message 6 "First time user; subscribing you to default groups")
921     (unless (gnus-read-active-file-p)
922       (gnus-read-active-file))
923     (setq gnus-newsrc-last-checked-date (current-time-string))
924     (let ((groups gnus-default-subscribed-newsgroups)
925           group)
926       (if (eq groups t)
927           nil
928         (setq groups (or groups gnus-backup-default-subscribed-newsgroups))
929         (mapatoms
930          (lambda (sym)
931            (if (null (setq group (symbol-name sym)))
932                ()
933              (let ((do-sub (gnus-matches-options-n group)))
934                (cond
935                 ((eq do-sub 'subscribe)
936                  (gnus-sethash group group gnus-killed-hashtb)
937                  (funcall gnus-subscribe-options-newsgroup-method group))
938                 ((eq do-sub 'ignore)
939                  nil)
940                 (t
941                  (setq gnus-killed-list (cons group gnus-killed-list)))))))
942          gnus-active-hashtb)
943         (while groups
944           (if (gnus-active (car groups))
945               (gnus-group-change-level
946                (car groups) gnus-level-default-subscribed gnus-level-killed))
947           (setq groups (cdr groups)))
948         (gnus-group-make-help-group)
949         (and gnus-novice-user
950              (gnus-message 7 "`A k' to list killed groups"))))))
951
952 (defun gnus-subscribe-group (group previous &optional method)
953   (gnus-group-change-level
954    (if method
955        (list t group gnus-level-default-subscribed nil nil method)
956      group)
957    gnus-level-default-subscribed gnus-level-killed previous t))
958
959 ;; `gnus-group-change-level' is the fundamental function for changing
960 ;; subscription levels of newsgroups.  This might mean just changing
961 ;; from level 1 to 2, which is pretty trivial, from 2 to 6 or back
962 ;; again, which subscribes/unsubscribes a group, which is equally
963 ;; trivial.  Changing from 1-7 to 8-9 means that you kill a group, and
964 ;; from 8-9 to 1-7 means that you remove the group from the list of
965 ;; killed (or zombie) groups and add them to the (kinda) subscribed
966 ;; groups.  And last but not least, moving from 8 to 9 and 9 to 8,
967 ;; which is trivial.
968 ;; ENTRY can either be a string (newsgroup name) or a list (if
969 ;; FROMKILLED is t, it's a list on the format (NUM INFO-LIST),
970 ;; otherwise it's a list in the format of the `gnus-newsrc-hashtb'
971 ;; entries.
972 ;; LEVEL is the new level of the group, OLDLEVEL is the old level and
973 ;; PREVIOUS is the group (in hashtb entry format) to insert this group
974 ;; after.
975 (defun gnus-group-change-level (entry level &optional oldlevel
976                                       previous fromkilled)
977   (let (group info active num)
978     ;; Glean what info we can from the arguments
979     (if (consp entry)
980         (if fromkilled (setq group (nth 1 entry))
981           (setq group (car (nth 2 entry))))
982       (setq group entry))
983     (if (and (stringp entry)
984              oldlevel
985              (< oldlevel gnus-level-zombie))
986         (setq entry (gnus-gethash entry gnus-newsrc-hashtb)))
987     (if (and (not oldlevel)
988              (consp entry))
989         (setq oldlevel (gnus-info-level (nth 2 entry)))
990       (setq oldlevel (or oldlevel 9)))
991     (if (stringp previous)
992         (setq previous (gnus-gethash previous gnus-newsrc-hashtb)))
993
994     (if (and (>= oldlevel gnus-level-zombie)
995              (gnus-gethash group gnus-newsrc-hashtb))
996         ;; We are trying to subscribe a group that is already
997         ;; subscribed.
998         ()                              ; Do nothing.
999
1000       (or (gnus-ephemeral-group-p group)
1001           (gnus-dribble-enter
1002            (format "(gnus-group-change-level %S %S %S %S %S)"
1003                    group level oldlevel (car (nth 2 previous)) fromkilled)))
1004
1005       ;; Then we remove the newgroup from any old structures, if needed.
1006       ;; If the group was killed, we remove it from the killed or zombie
1007       ;; list.  If not, and it is in fact going to be killed, we remove
1008       ;; it from the newsrc hash table and assoc.
1009       (cond
1010        ((>= oldlevel gnus-level-zombie)
1011         (if (= oldlevel gnus-level-zombie)
1012             (setq gnus-zombie-list (delete group gnus-zombie-list))
1013           (setq gnus-killed-list (delete group gnus-killed-list))))
1014        (t
1015         (if (and (>= level gnus-level-zombie)
1016                  entry)
1017             (progn
1018               (gnus-sethash (car (nth 2 entry)) nil gnus-newsrc-hashtb)
1019               (if (nth 3 entry)
1020                   (setcdr (gnus-gethash (car (nth 3 entry))
1021                                         gnus-newsrc-hashtb)
1022                           (cdr entry)))
1023               (setcdr (cdr entry) (cdddr entry))))))
1024
1025       ;; Finally we enter (if needed) the list where it is supposed to
1026       ;; go, and change the subscription level.  If it is to be killed,
1027       ;; we enter it into the killed or zombie list.
1028       (cond 
1029        ((>= level gnus-level-zombie)
1030         ;; Remove from the hash table.
1031         (gnus-sethash group nil gnus-newsrc-hashtb)
1032         ;; We do not enter foreign groups into the list of dead
1033         ;; groups.
1034         (unless (gnus-group-foreign-p group)
1035           (if (= level gnus-level-zombie)
1036               (setq gnus-zombie-list (cons group gnus-zombie-list))
1037             (setq gnus-killed-list (cons group gnus-killed-list)))))
1038        (t
1039         ;; If the list is to be entered into the newsrc assoc, and
1040         ;; it was killed, we have to create an entry in the newsrc
1041         ;; hashtb format and fix the pointers in the newsrc assoc.
1042         (if (< oldlevel gnus-level-zombie)
1043             ;; It was alive, and it is going to stay alive, so we
1044             ;; just change the level and don't change any pointers or
1045             ;; hash table entries.
1046             (setcar (cdaddr entry) level)
1047           (if (listp entry)
1048               (setq info (cdr entry)
1049                     num (car entry))
1050             (setq active (gnus-active group))
1051             (setq num
1052                   (if active (- (1+ (cdr active)) (car active)) t))
1053             ;; Check whether the group is foreign.  If so, the
1054             ;; foreign select method has to be entered into the
1055             ;; info.
1056             (let ((method (or gnus-override-subscribe-method
1057                               (gnus-group-method group))))
1058               (if (eq method gnus-select-method)
1059                   (setq info (list group level nil))
1060                 (setq info (list group level nil nil method)))))
1061           (unless previous
1062             (setq previous
1063                   (let ((p gnus-newsrc-alist))
1064                     (while (cddr p)
1065                       (setq p (cdr p)))
1066                     p)))
1067           (setq entry (cons info (cddr previous)))
1068           (if (cdr previous)
1069               (progn
1070                 (setcdr (cdr previous) entry)
1071                 (gnus-sethash group (cons num (cdr previous))
1072                               gnus-newsrc-hashtb))
1073             (setcdr previous entry)
1074             (gnus-sethash group (cons num previous)
1075                           gnus-newsrc-hashtb))
1076           (when (cdr entry)
1077             (setcdr (gnus-gethash (caadr entry) gnus-newsrc-hashtb) entry)))))
1078       (when gnus-group-change-level-function
1079         (funcall gnus-group-change-level-function group level oldlevel)))))
1080
1081 (defun gnus-kill-newsgroup (newsgroup)
1082   "Obsolete function.  Kills a newsgroup."
1083   (gnus-group-change-level
1084    (gnus-gethash newsgroup gnus-newsrc-hashtb) gnus-level-killed))
1085
1086 (defun gnus-check-bogus-newsgroups (&optional confirm)
1087   "Remove bogus newsgroups.
1088 If CONFIRM is non-nil, the user has to confirm the deletion of every
1089 newsgroup."
1090   (let ((newsrc (cdr gnus-newsrc-alist))
1091         bogus group entry info)
1092     (gnus-message 5 "Checking bogus newsgroups...")
1093     (unless (gnus-read-active-file-p)
1094       (gnus-read-active-file))
1095     (when (gnus-read-active-file-p)
1096       ;; Find all bogus newsgroup that are subscribed.
1097       (while newsrc
1098         (setq info (pop newsrc)
1099               group (gnus-info-group info))
1100         (unless (or (gnus-active group) ; Active
1101                     (gnus-info-method info) ; Foreign
1102                     (and confirm
1103                          (not (gnus-y-or-n-p
1104                                (format "Remove bogus newsgroup: %s " group)))))
1105           ;; Found a bogus newsgroup.
1106           (push group bogus)))
1107       ;; Remove all bogus subscribed groups by first killing them, and
1108       ;; then removing them from the list of killed groups.
1109       (while bogus
1110         (when (setq entry (gnus-gethash (setq group (pop bogus))
1111                                         gnus-newsrc-hashtb))
1112           (gnus-group-change-level entry gnus-level-killed)
1113           (setq gnus-killed-list (delete group gnus-killed-list))))
1114       ;; Then we remove all bogus groups from the list of killed and
1115       ;; zombie groups.  They are removed without confirmation.
1116       (let ((dead-lists '(gnus-killed-list gnus-zombie-list))
1117             killed)
1118         (while dead-lists
1119           (setq killed (symbol-value (car dead-lists)))
1120           (while killed
1121             (unless (gnus-active (setq group (pop killed)))
1122               ;; The group is bogus.
1123               ;; !!!Slow as hell.
1124               (set (car dead-lists)
1125                    (delete group (symbol-value (car dead-lists))))))
1126           (setq dead-lists (cdr dead-lists))))
1127       (run-hooks 'gnus-check-bogus-groups-hook)
1128       (gnus-message 5 "Checking bogus newsgroups...done"))))
1129
1130 (defun gnus-check-duplicate-killed-groups ()
1131   "Remove duplicates from the list of killed groups."
1132   (interactive)
1133   (let ((killed gnus-killed-list))
1134     (while killed
1135       (gnus-message 9 "%d" (length killed))
1136       (setcdr killed (delete (car killed) (cdr killed)))
1137       (setq killed (cdr killed)))))
1138
1139 ;; We want to inline a function from gnus-cache, so we cheat here:
1140 (eval-when-compile
1141   (defvar gnus-cache-active-hashtb)
1142   (defun gnus-cache-possibly-alter-active (group active)
1143     "Alter the ACTIVE info for GROUP to reflect the articles in the cache."
1144     (when gnus-cache-active-hashtb
1145       (let ((cache-active (gnus-gethash group gnus-cache-active-hashtb)))
1146         (and cache-active 
1147              (< (car cache-active) (car active))
1148              (setcar active (car cache-active)))
1149         (and cache-active
1150              (> (cdr cache-active) (cdr active))
1151              (setcdr active (cdr cache-active)))))))
1152
1153 (defun gnus-get-unread-articles-in-group (info active &optional update)
1154   (when active
1155     ;; Allow the backend to update the info in the group.
1156     (when (and update 
1157                (gnus-request-update-info
1158                 info (gnus-find-method-for-group (gnus-info-group info))))
1159       (gnus-activate-group (gnus-info-group info) nil t))
1160     (let* ((range (gnus-info-read info))
1161            (num 0))
1162       ;; If a cache is present, we may have to alter the active info.
1163       (when (and gnus-use-cache info)
1164         (inline (gnus-cache-possibly-alter-active 
1165                  (gnus-info-group info) active)))
1166       ;; Modify the list of read articles according to what articles
1167       ;; are available; then tally the unread articles and add the
1168       ;; number to the group hash table entry.
1169       (cond
1170        ((zerop (cdr active))
1171         (setq num 0))
1172        ((not range)
1173         (setq num (- (1+ (cdr active)) (car active))))
1174        ((not (listp (cdr range)))
1175         ;; Fix a single (num . num) range according to the
1176         ;; active hash table.
1177         ;; Fix by Carsten Bormann <cabo@Informatik.Uni-Bremen.DE>.
1178         (and (< (cdr range) (car active)) (setcdr range (1- (car active))))
1179         (and (> (cdr range) (cdr active)) (setcdr range (cdr active)))
1180         ;; Compute number of unread articles.
1181         (setq num (max 0 (- (cdr active) (- (1+ (cdr range)) (car range))))))
1182        (t
1183         ;; The read list is a list of ranges.  Fix them according to
1184         ;; the active hash table.
1185         ;; First peel off any elements that are below the lower
1186         ;; active limit.
1187         (while (and (cdr range)
1188                     (>= (car active)
1189                         (or (and (atom (cadr range)) (cadr range))
1190                             (caadr range))))
1191           (if (numberp (car range))
1192               (setcar range
1193                       (cons (car range)
1194                             (or (and (numberp (cadr range))
1195                                      (cadr range))
1196                                 (cdadr range))))
1197             (setcdr (car range)
1198                     (or (and (numberp (nth 1 range)) (nth 1 range))
1199                         (cdadr range))))
1200           (setcdr range (cddr range)))
1201         ;; Adjust the first element to be the same as the lower limit.
1202         (if (and (not (atom (car range)))
1203                  (< (cdar range) (car active)))
1204             (setcdr (car range) (1- (car active))))
1205         ;; Then we want to peel off any elements that are higher
1206         ;; than the upper active limit.
1207         (let ((srange range))
1208           ;; Go past all legal elements.
1209           (while (and (cdr srange)
1210                       (<= (or (and (atom (cadr srange))
1211                                    (cadr srange))
1212                               (caadr srange)) (cdr active)))
1213             (setq srange (cdr srange)))
1214           (if (cdr srange)
1215               ;; Nuke all remaining illegal elements.
1216               (setcdr srange nil))
1217
1218           ;; Adjust the final element.
1219           (if (and (not (atom (car srange)))
1220                    (> (cdar srange) (cdr active)))
1221               (setcdr (car srange) (cdr active))))
1222         ;; Compute the number of unread articles.
1223         (while range
1224           (setq num (+ num (- (1+ (or (and (atom (car range)) (car range))
1225                                       (cdar range)))
1226                               (or (and (atom (car range)) (car range))
1227                                   (caar range)))))
1228           (setq range (cdr range)))
1229         (setq num (max 0 (- (cdr active) num)))))
1230       ;; Set the number of unread articles.
1231       (when info
1232         (setcar (gnus-gethash (gnus-info-group info) gnus-newsrc-hashtb) num))
1233       num)))
1234
1235 ;; Go though `gnus-newsrc-alist' and compare with `gnus-active-hashtb'
1236 ;; and compute how many unread articles there are in each group.
1237 (defun gnus-get-unread-articles (&optional level)
1238   (let* ((newsrc (cdr gnus-newsrc-alist))
1239          (level (or level gnus-activate-level (1+ gnus-level-subscribed)))
1240          (foreign-level
1241           (min
1242            (cond ((and gnus-activate-foreign-newsgroups
1243                        (not (numberp gnus-activate-foreign-newsgroups)))
1244                   (1+ gnus-level-subscribed))
1245                  ((numberp gnus-activate-foreign-newsgroups)
1246                   gnus-activate-foreign-newsgroups)
1247                  (t 0))
1248            level))
1249          info group active method)
1250     (gnus-message 5 "Checking new news...")
1251
1252     (while newsrc
1253       (setq active (gnus-active (setq group (gnus-info-group
1254                                              (setq info (pop newsrc))))))
1255
1256       ;; Check newsgroups.  If the user doesn't want to check them, or
1257       ;; they can't be checked (for instance, if the news server can't
1258       ;; be reached) we just set the number of unread articles in this
1259       ;; newsgroup to t.  This means that Gnus thinks that there are
1260       ;; unread articles, but it has no idea how many.
1261       (if (and (setq method (gnus-info-method info))
1262                (not (gnus-server-equal
1263                      gnus-select-method
1264                      (setq method (gnus-server-get-method nil method))))
1265                (not (gnus-secondary-method-p method)))
1266           ;; These groups are foreign.  Check the level.
1267           (when (<= (gnus-info-level info) foreign-level)
1268             (setq active (gnus-activate-group group 'scan))
1269             (unless (inline (gnus-virtual-group-p group))
1270               (inline (gnus-close-group group)))
1271             (when (fboundp (intern (concat (symbol-name (car method))
1272                                            "-request-update-info")))
1273               (inline (gnus-request-update-info info method))))
1274         ;; These groups are native or secondary.
1275         (when (and (<= (gnus-info-level info) level)
1276                    (not gnus-read-active-file))
1277           (setq active (gnus-activate-group group 'scan))
1278           (inline (gnus-close-group group))))
1279
1280       ;; Get the number of unread articles in the group.
1281       (if active
1282           (inline (gnus-get-unread-articles-in-group info active))
1283         ;; The group couldn't be reached, so we nix out the number of
1284         ;; unread articles and stuff.
1285         (gnus-set-active group nil)
1286         (setcar (gnus-gethash group gnus-newsrc-hashtb) t)))
1287
1288     (gnus-message 5 "Checking new news...done")))
1289
1290 ;; Create a hash table out of the newsrc alist.  The `car's of the
1291 ;; alist elements are used as keys.
1292 (defun gnus-make-hashtable-from-newsrc-alist ()
1293   (let ((alist gnus-newsrc-alist)
1294         (ohashtb gnus-newsrc-hashtb)
1295         prev)
1296     (setq gnus-newsrc-hashtb (gnus-make-hashtable (length alist)))
1297     (setq alist
1298           (setq prev (setq gnus-newsrc-alist
1299                            (if (equal (caar gnus-newsrc-alist)
1300                                       "dummy.group")
1301                                gnus-newsrc-alist
1302                              (cons (list "dummy.group" 0 nil) alist)))))
1303     (while alist
1304       (gnus-sethash
1305        (caar alist)
1306        (cons (and ohashtb (car (gnus-gethash (caar alist) ohashtb)))
1307              prev)
1308        gnus-newsrc-hashtb)
1309       (setq prev alist
1310             alist (cdr alist)))))
1311
1312 (defun gnus-make-hashtable-from-killed ()
1313   "Create a hash table from the killed and zombie lists."
1314   (let ((lists '(gnus-killed-list gnus-zombie-list))
1315         list)
1316     (setq gnus-killed-hashtb
1317           (gnus-make-hashtable
1318            (+ (length gnus-killed-list) (length gnus-zombie-list))))
1319     (while (setq list (pop lists))
1320       (setq list (symbol-value list))
1321       (while list
1322         (gnus-sethash (car list) (pop list) gnus-killed-hashtb)))))
1323
1324 (defun gnus-activate-group (group &optional scan dont-check method)
1325   ;; Check whether a group has been activated or not.
1326   ;; If SCAN, request a scan of that group as well.
1327   (let ((method (or method (gnus-find-method-for-group group)))
1328         active)
1329     (and (gnus-check-server method)
1330          ;; We escape all bugs and quit here to make it possible to
1331          ;; continue if a group is so out-there that it reports bugs
1332          ;; and stuff.
1333          (progn
1334            (and scan
1335                 (gnus-check-backend-function 'request-scan (car method))
1336                 (gnus-request-scan group method))
1337            t)
1338          (condition-case ()
1339              (gnus-request-group group dont-check method)
1340                                         ;   (error nil)
1341            (quit nil))
1342          (gnus-set-active group (setq active (gnus-parse-active)))
1343          ;; Return the new active info.
1344          active)))
1345
1346 (defun gnus-parse-active ()
1347   "Parse active info in the nntp server buffer."
1348   (save-excursion
1349     (set-buffer nntp-server-buffer)
1350     (goto-char (point-min))
1351     ;; Parse the result we got from `gnus-request-group'.
1352     (when (looking-at "[0-9]+ [0-9]+ \\([0-9]+\\) [0-9]+")
1353       (goto-char (match-beginning 1))
1354       (cons (read (current-buffer))
1355             (read (current-buffer))))))
1356
1357 (defun gnus-make-articles-unread (group articles)
1358   "Mark ARTICLES in GROUP as unread."
1359   (let* ((info (nth 2 (or (gnus-gethash group gnus-newsrc-hashtb)
1360                           (gnus-gethash (gnus-group-real-name group)
1361                                         gnus-newsrc-hashtb))))
1362          (ranges (gnus-info-read info))
1363          news article)
1364     (while articles
1365       (when (gnus-member-of-range
1366              (setq article (pop articles)) ranges)
1367         (setq news (cons article news))))
1368     (when news
1369       (gnus-info-set-read
1370        info (gnus-remove-from-range (gnus-info-read info) (nreverse news)))
1371       (gnus-group-update-group group t))))
1372
1373 ;; Enter all dead groups into the hashtb.
1374 (defun gnus-update-active-hashtb-from-killed ()
1375   (let ((hashtb (setq gnus-active-hashtb (make-vector 4095 0)))
1376         (lists (list gnus-killed-list gnus-zombie-list))
1377         killed)
1378     (while lists
1379       (setq killed (car lists))
1380       (while killed
1381         (gnus-sethash (car killed) nil hashtb)
1382         (setq killed (cdr killed)))
1383       (setq lists (cdr lists)))))
1384
1385 (defun gnus-get-killed-groups ()
1386   "Go through the active hashtb and mark all unknown groups as killed."
1387   ;; First make sure active file has been read.
1388   (unless (gnus-read-active-file-p)
1389     (let ((gnus-read-active-file t))
1390       (gnus-read-active-file)))
1391   (or gnus-killed-hashtb (gnus-make-hashtable-from-killed))
1392   ;; Go through all newsgroups that are known to Gnus - enlarge kill list.
1393   (mapatoms
1394    (lambda (sym)
1395      (let ((groups 0)
1396            (group (symbol-name sym)))
1397        (if (or (null group)
1398                (gnus-gethash group gnus-killed-hashtb)
1399                (gnus-gethash group gnus-newsrc-hashtb))
1400            ()
1401          (let ((do-sub (gnus-matches-options-n group)))
1402            (if (or (eq do-sub 'subscribe) (eq do-sub 'ignore))
1403                ()
1404              (setq groups (1+ groups))
1405              (setq gnus-killed-list
1406                    (cons group gnus-killed-list))
1407              (gnus-sethash group group gnus-killed-hashtb))))))
1408    gnus-active-hashtb))
1409
1410 ;; Get the active file(s) from the backend(s).
1411 (defun gnus-read-active-file ()
1412   (gnus-group-set-mode-line)
1413   (let ((methods 
1414          (append
1415           (if (gnus-check-server gnus-select-method)
1416               ;; The native server is available.
1417               (cons gnus-select-method gnus-secondary-select-methods)
1418             ;; The native server is down, so we just do the
1419             ;; secondary ones.
1420             gnus-secondary-select-methods)
1421           ;; Also read from the archive server.
1422           (when (gnus-archive-server-wanted-p)
1423             (list "archive"))))
1424         list-type)
1425     (setq gnus-have-read-active-file nil)
1426     (save-excursion
1427       (set-buffer nntp-server-buffer)
1428       (while methods
1429         (let* ((method (if (stringp (car methods))
1430                            (gnus-server-get-method nil (car methods))
1431                          (car methods)))
1432                (where (nth 1 method))
1433                (mesg (format "Reading active file%s via %s..."
1434                              (if (and where (not (zerop (length where))))
1435                                  (concat " from " where) "")
1436                              (car method))))
1437           (gnus-message 5 mesg)
1438           (when (gnus-check-server method)
1439             ;; Request that the backend scan its incoming messages.
1440             (and (gnus-check-backend-function 'request-scan (car method))
1441                  (gnus-request-scan nil method))
1442             (cond
1443              ((and (eq gnus-read-active-file 'some)
1444                    (gnus-check-backend-function 'retrieve-groups (car method)))
1445               (let ((newsrc (cdr gnus-newsrc-alist))
1446                     (gmethod (gnus-server-get-method nil method))
1447                     groups info)
1448                 (while (setq info (pop newsrc))
1449                   (when (gnus-server-equal
1450                          (gnus-find-method-for-group 
1451                           (gnus-info-group info) info)
1452                          gmethod)
1453                     (push (gnus-group-real-name (gnus-info-group info)) 
1454                           groups)))
1455                 (when groups
1456                   (gnus-check-server method)
1457                   (setq list-type (gnus-retrieve-groups groups method))
1458                   (cond
1459                    ((not list-type)
1460                     (gnus-error
1461                      1.2 "Cannot read partial active file from %s server."
1462                      (car method)))
1463                    ((eq list-type 'active)
1464                     (gnus-active-to-gnus-format method gnus-active-hashtb))
1465                    (t
1466                     (gnus-groups-to-gnus-format method gnus-active-hashtb))))))
1467              (t
1468               (if (not (gnus-request-list method))
1469                   (unless (equal method gnus-message-archive-method)
1470                     (gnus-error 1 "Cannot read active file from %s server."
1471                                 (car method)))
1472                 (gnus-message 5 mesg)
1473                 (gnus-active-to-gnus-format method gnus-active-hashtb)
1474                 ;; We mark this active file as read.
1475                 (push method gnus-have-read-active-file)
1476                 (gnus-message 5 "%sdone" mesg))))))
1477         (setq methods (cdr methods))))))
1478
1479 ;; Read an active file and place the results in `gnus-active-hashtb'.
1480 (defun gnus-active-to-gnus-format (&optional method hashtb ignore-errors)
1481   (unless method
1482     (setq method gnus-select-method))
1483   (let ((cur (current-buffer))
1484         (hashtb (or hashtb
1485                     (if (and gnus-active-hashtb
1486                              (not (equal method gnus-select-method)))
1487                         gnus-active-hashtb
1488                       (setq gnus-active-hashtb
1489                             (if (equal method gnus-select-method)
1490                                 (gnus-make-hashtable
1491                                  (count-lines (point-min) (point-max)))
1492                               (gnus-make-hashtable 4096)))))))
1493     ;; Delete unnecessary lines.
1494     (goto-char (point-min))
1495     (while (search-forward "\nto." nil t)
1496       (delete-region (1+ (match-beginning 0))
1497                      (progn (forward-line 1) (point))))
1498     (or (string= gnus-ignored-newsgroups "")
1499         (progn
1500           (goto-char (point-min))
1501           (delete-matching-lines gnus-ignored-newsgroups)))
1502     ;; Make the group names readable as a lisp expression even if they
1503     ;; contain special characters.
1504     ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
1505     (goto-char (point-max))
1506     (while (re-search-backward "[][';?()#]" nil t)
1507       (insert ?\\))
1508     ;; If these are groups from a foreign select method, we insert the
1509     ;; group prefix in front of the group names.
1510     (and method (not (gnus-server-equal
1511                       (gnus-server-get-method nil method)
1512                       (gnus-server-get-method nil gnus-select-method)))
1513          (let ((prefix (gnus-group-prefixed-name "" method)))
1514            (goto-char (point-min))
1515            (while (and (not (eobp))
1516                        (progn (insert prefix)
1517                               (zerop (forward-line 1)))))))
1518     ;; Store the active file in a hash table.
1519     (goto-char (point-min))
1520     (if (string-match "%[oO]" gnus-group-line-format)
1521         ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
1522         ;; If we want information on moderated groups, we use this
1523         ;; loop...
1524         (let* ((mod-hashtb (make-vector 7 0))
1525                (m (intern "m" mod-hashtb))
1526                group max min)
1527           (while (not (eobp))
1528             (condition-case nil
1529                 (progn
1530                   (narrow-to-region (point) (gnus-point-at-eol))
1531                   (setq group (let ((obarray hashtb)) (read cur)))
1532                   (if (and (numberp (setq max (read cur)))
1533                            (numberp (setq min (read cur)))
1534                            (progn
1535                              (skip-chars-forward " \t")
1536                              (not
1537                               (or (= (following-char) ?=)
1538                                   (= (following-char) ?x)
1539                                   (= (following-char) ?j)))))
1540                       (set group (cons min max))
1541                     (set group nil))
1542                   ;; Enter moderated groups into a list.
1543                   (if (eq (let ((obarray mod-hashtb)) (read cur)) m)
1544                       (setq gnus-moderated-list
1545                             (cons (symbol-name group) gnus-moderated-list))))
1546               (error
1547                (and group
1548                     (symbolp group)
1549                     (set group nil))))
1550             (widen)
1551             (forward-line 1)))
1552       ;; And if we do not care about moderation, we use this loop,
1553       ;; which is faster.
1554       (let (group max min)
1555         (while (not (eobp))
1556           (condition-case ()
1557               (progn
1558                 (narrow-to-region (point) (gnus-point-at-eol))
1559                 ;; group gets set to a symbol interned in the hash table
1560                 ;; (what a hack!!) - jwz
1561                 (setq group (let ((obarray hashtb)) (read cur)))
1562                 (if (and (numberp (setq max (read cur)))
1563                          (numberp (setq min (read cur)))
1564                          (progn
1565                            (skip-chars-forward " \t")
1566                            (not
1567                             (or (= (following-char) ?=)
1568                                 (= (following-char) ?x)
1569                                 (= (following-char) ?j)))))
1570                     (set group (cons min max))
1571                   (set group nil)))
1572             (error
1573              (progn
1574                (and group
1575                     (symbolp group)
1576                     (set group nil))
1577                (or ignore-errors
1578                    (gnus-message 3 "Warning - illegal active: %s"
1579                                  (buffer-substring
1580                                   (gnus-point-at-bol) (gnus-point-at-eol)))))))
1581           (widen)
1582           (forward-line 1))))))
1583
1584 (defun gnus-groups-to-gnus-format (method &optional hashtb)
1585   ;; Parse a "groups" active file.
1586   (let ((cur (current-buffer))
1587         (hashtb (or hashtb
1588                     (if (and method gnus-active-hashtb)
1589                         gnus-active-hashtb
1590                       (setq gnus-active-hashtb
1591                             (gnus-make-hashtable
1592                              (count-lines (point-min) (point-max)))))))
1593         (prefix (and method
1594                      (not (gnus-server-equal
1595                            (gnus-server-get-method nil method)
1596                            (gnus-server-get-method nil gnus-select-method)))
1597                      (gnus-group-prefixed-name "" method))))
1598
1599     (goto-char (point-min))
1600     ;; We split this into to separate loops, one with the prefix
1601     ;; and one without to speed the reading up somewhat.
1602     (if prefix
1603         (let (min max opoint group)
1604           (while (not (eobp))
1605             (condition-case ()
1606                 (progn
1607                   (read cur) (read cur)
1608                   (setq min (read cur)
1609                         max (read cur)
1610                         opoint (point))
1611                   (skip-chars-forward " \t")
1612                   (insert prefix)
1613                   (goto-char opoint)
1614                   (set (let ((obarray hashtb)) (read cur))
1615                        (cons min max)))
1616               (error (and group (symbolp group) (set group nil))))
1617             (forward-line 1)))
1618       (let (min max group)
1619         (while (not (eobp))
1620           (condition-case ()
1621               (if (= (following-char) ?2)
1622                   (progn
1623                     (read cur) (read cur)
1624                     (setq min (read cur)
1625                           max (read cur))
1626                     (set (setq group (let ((obarray hashtb)) (read cur)))
1627                          (cons min max))))
1628             (error (and group (symbolp group) (set group nil))))
1629           (forward-line 1))))))
1630
1631 (defun gnus-read-newsrc-file (&optional force)
1632   "Read startup file.
1633 If FORCE is non-nil, the .newsrc file is read."
1634   ;; Reset variables that might be defined in the .newsrc.eld file.
1635   (let ((variables gnus-variable-list))
1636     (while variables
1637       (set (car variables) nil)
1638       (setq variables (cdr variables))))
1639   (let* ((newsrc-file gnus-current-startup-file)
1640          (quick-file (concat newsrc-file ".el")))
1641     (save-excursion
1642       ;; We always load the .newsrc.eld file.  If always contains
1643       ;; much information that can not be gotten from the .newsrc
1644       ;; file (ticked articles, killed groups, foreign methods, etc.)
1645       (gnus-read-newsrc-el-file quick-file)
1646
1647       (if (and (file-exists-p gnus-current-startup-file)
1648                (or force
1649                    (and (file-newer-than-file-p newsrc-file quick-file)
1650                         (file-newer-than-file-p newsrc-file
1651                                                 (concat quick-file "d")))
1652                    (not gnus-newsrc-alist)))
1653           ;; We read the .newsrc file.  Note that if there if a
1654           ;; .newsrc.eld file exists, it has already been read, and
1655           ;; the `gnus-newsrc-hashtb' has been created.  While reading
1656           ;; the .newsrc file, Gnus will only use the information it
1657           ;; can find there for changing the data already read -
1658           ;; ie. reading the .newsrc file will not trash the data
1659           ;; already read (except for read articles).
1660           (save-excursion
1661             (gnus-message 5 "Reading %s..." newsrc-file)
1662             (set-buffer (find-file-noselect newsrc-file))
1663             (buffer-disable-undo (current-buffer))
1664             (gnus-newsrc-to-gnus-format)
1665             (kill-buffer (current-buffer))
1666             (gnus-message 5 "Reading %s...done" newsrc-file)))
1667
1668       ;; Read any slave files.
1669       (unless gnus-slave
1670         (gnus-master-read-slave-newsrc))
1671       
1672       ;; Convert old to new.
1673       (gnus-convert-old-newsrc))))
1674
1675 (defun gnus-convert-old-newsrc ()
1676   "Convert old newsrc into the new format, if needed."
1677   (let ((fcv (and gnus-newsrc-file-version
1678                   (gnus-continuum-version gnus-newsrc-file-version))))
1679     (cond
1680      ;; No .newsrc.eld file was loaded.
1681      ((null fcv) nil)
1682      ;; Gnus 5 .newsrc.eld was loaded.
1683      ((< fcv (gnus-continuum-version "September Gnus v0.1"))
1684       (gnus-convert-old-ticks)))))
1685
1686 (defun gnus-convert-old-ticks ()
1687   (let ((newsrc (cdr gnus-newsrc-alist))
1688         marks info dormant ticked)
1689     (while (setq info (pop newsrc))
1690       (when (setq marks (gnus-info-marks info))
1691         (setq dormant (cdr (assq 'dormant marks))
1692               ticked (cdr (assq 'tick marks)))
1693         (when (or dormant ticked)
1694           (gnus-info-set-read
1695            info
1696            (gnus-add-to-range
1697             (gnus-info-read info)
1698             (nconc (gnus-uncompress-range dormant)
1699                    (gnus-uncompress-range ticked)))))))))
1700
1701 (defun gnus-read-newsrc-el-file (file)
1702   (let ((ding-file (concat file "d")))
1703     ;; We always, always read the .eld file.
1704     (gnus-message 5 "Reading %s..." ding-file)
1705     (let (gnus-newsrc-assoc)
1706       (condition-case nil
1707           (load ding-file t t t)
1708         (error
1709          (gnus-error 1 "Error in %s" ding-file)))
1710       (when gnus-newsrc-assoc
1711         (setq gnus-newsrc-alist gnus-newsrc-assoc)))
1712     (gnus-make-hashtable-from-newsrc-alist)
1713     (when (file-newer-than-file-p file ding-file)
1714       ;; Old format quick file
1715       (gnus-message 5 "Reading %s..." file)
1716       ;; The .el file is newer than the .eld file, so we read that one
1717       ;; as well.
1718       (gnus-read-old-newsrc-el-file file))))
1719
1720 ;; Parse the old-style quick startup file
1721 (defun gnus-read-old-newsrc-el-file (file)
1722   (let (newsrc killed marked group m info)
1723     (prog1
1724         (let ((gnus-killed-assoc nil)
1725               gnus-marked-assoc gnus-newsrc-alist gnus-newsrc-assoc)
1726           (prog1
1727               (condition-case nil
1728                   (load file t t t)
1729                 (error nil))
1730             (setq newsrc gnus-newsrc-assoc
1731                   killed gnus-killed-assoc
1732                   marked gnus-marked-assoc)))
1733       (setq gnus-newsrc-alist nil)
1734       (while (setq group (pop newsrc))
1735         (if (setq info (gnus-get-info (car group)))
1736             (progn
1737               (gnus-info-set-read info (cddr group))
1738               (gnus-info-set-level
1739                info (if (nth 1 group) gnus-level-default-subscribed
1740                       gnus-level-default-unsubscribed))
1741               (setq gnus-newsrc-alist (cons info gnus-newsrc-alist)))
1742           (push (setq info
1743                       (list (car group)
1744                             (if (nth 1 group) gnus-level-default-subscribed
1745                               gnus-level-default-unsubscribed)
1746                             (cddr group)))
1747                 gnus-newsrc-alist))
1748         ;; Copy marks into info.
1749         (when (setq m (assoc (car group) marked))
1750           (unless (nthcdr 3 info)
1751             (nconc info (list nil)))
1752           (gnus-info-set-marks
1753            info (list (cons 'tick (gnus-compress-sequence 
1754                                    (sort (cdr m) '<) t))))))
1755       (setq newsrc killed)
1756       (while newsrc
1757         (setcar newsrc (caar newsrc))
1758         (setq newsrc (cdr newsrc)))
1759       (setq gnus-killed-list killed))
1760     ;; The .el file version of this variable does not begin with
1761     ;; "options", while the .eld version does, so we just add it if it
1762     ;; isn't there.
1763     (and
1764      gnus-newsrc-options
1765      (progn
1766        (and (not (string-match "^ *options" gnus-newsrc-options))
1767             (setq gnus-newsrc-options (concat "options " gnus-newsrc-options)))
1768        (and (not (string-match "\n$" gnus-newsrc-options))
1769             (setq gnus-newsrc-options (concat gnus-newsrc-options "\n")))
1770        ;; Finally, if we read some options lines, we parse them.
1771        (or (string= gnus-newsrc-options "")
1772            (gnus-newsrc-parse-options gnus-newsrc-options))))
1773
1774     (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist))
1775     (gnus-make-hashtable-from-newsrc-alist)))
1776
1777 (defun gnus-make-newsrc-file (file)
1778   "Make server dependent file name by catenating FILE and server host name."
1779   (let* ((file (expand-file-name file nil))
1780          (real-file (concat file "-" (nth 1 gnus-select-method))))
1781     (if (or (file-exists-p real-file)
1782             (file-exists-p (concat real-file ".el"))
1783             (file-exists-p (concat real-file ".eld")))
1784         real-file file)))
1785
1786 (defun gnus-newsrc-to-gnus-format ()
1787   (setq gnus-newsrc-options "")
1788   (setq gnus-newsrc-options-n nil)
1789
1790   (or gnus-active-hashtb
1791       (setq gnus-active-hashtb (make-vector 4095 0)))
1792   (let ((buf (current-buffer))
1793         (already-read (> (length gnus-newsrc-alist) 1))
1794         group subscribed options-symbol newsrc Options-symbol
1795         symbol reads num1)
1796     (goto-char (point-min))
1797     ;; We intern the symbol `options' in the active hashtb so that we
1798     ;; can `eq' against it later.
1799     (set (setq options-symbol (intern "options" gnus-active-hashtb)) nil)
1800     (set (setq Options-symbol (intern "Options" gnus-active-hashtb)) nil)
1801
1802     (while (not (eobp))
1803       ;; We first read the first word on the line by narrowing and
1804       ;; then reading into `gnus-active-hashtb'.  Most groups will
1805       ;; already exist in that hashtb, so this will save some string
1806       ;; space.
1807       (narrow-to-region
1808        (point)
1809        (progn (skip-chars-forward "^ \t!:\n") (point)))
1810       (goto-char (point-min))
1811       (setq symbol
1812             (and (/= (point-min) (point-max))
1813                  (let ((obarray gnus-active-hashtb)) (read buf))))
1814       (widen)
1815       ;; Now, the symbol we have read is either `options' or a group
1816       ;; name.  If it is an options line, we just add it to a string.
1817       (cond
1818        ((or (eq symbol options-symbol)
1819             (eq symbol Options-symbol))
1820         (setq gnus-newsrc-options
1821               ;; This concating is quite inefficient, but since our
1822               ;; thorough studies show that approx 99.37% of all
1823               ;; .newsrc files only contain a single options line, we
1824               ;; don't give a damn, frankly, my dear.
1825               (concat gnus-newsrc-options
1826                       (buffer-substring
1827                        (gnus-point-at-bol)
1828                        ;; Options may continue on the next line.
1829                        (or (and (re-search-forward "^[^ \t]" nil 'move)
1830                                 (progn (beginning-of-line) (point)))
1831                            (point)))))
1832         (forward-line -1))
1833        (symbol
1834         ;; Group names can be just numbers.  
1835         (when (numberp symbol) 
1836           (setq symbol (intern (int-to-string symbol) gnus-active-hashtb)))
1837         (or (boundp symbol) (set symbol nil))
1838         ;; It was a group name.
1839         (setq subscribed (= (following-char) ?:)
1840               group (symbol-name symbol)
1841               reads nil)
1842         (if (eolp)
1843             ;; If the line ends here, this is clearly a buggy line, so
1844             ;; we put point a the beginning of line and let the cond
1845             ;; below do the error handling.
1846             (beginning-of-line)
1847           ;; We skip to the beginning of the ranges.
1848           (skip-chars-forward "!: \t"))
1849         ;; We are now at the beginning of the list of read articles.
1850         ;; We read them range by range.
1851         (while
1852             (cond
1853              ((looking-at "[0-9]+")
1854               ;; We narrow and read a number instead of buffer-substring/
1855               ;; string-to-int because it's faster.  narrow/widen is
1856               ;; faster than save-restriction/narrow, and save-restriction
1857               ;; produces a garbage object.
1858               (setq num1 (progn
1859                            (narrow-to-region (match-beginning 0) (match-end 0))
1860                            (read buf)))
1861               (widen)
1862               ;; If the next character is a dash, then this is a range.
1863               (if (= (following-char) ?-)
1864                   (progn
1865                     ;; We read the upper bound of the range.
1866                     (forward-char 1)
1867                     (if (not (looking-at "[0-9]+"))
1868                         ;; This is a buggy line, by we pretend that
1869                         ;; it's kinda OK.  Perhaps the user should be
1870                         ;; dinged?
1871                         (setq reads (cons num1 reads))
1872                       (setq reads
1873                             (cons
1874                              (cons num1
1875                                    (progn
1876                                      (narrow-to-region (match-beginning 0)
1877                                                        (match-end 0))
1878                                      (read buf)))
1879                              reads))
1880                       (widen)))
1881                 ;; It was just a simple number, so we add it to the
1882                 ;; list of ranges.
1883                 (setq reads (cons num1 reads)))
1884               ;; If the next char in ?\n, then we have reached the end
1885               ;; of the line and return nil.
1886               (/= (following-char) ?\n))
1887              ((= (following-char) ?\n)
1888               ;; End of line, so we end.
1889               nil)
1890              (t
1891               ;; Not numbers and not eol, so this might be a buggy
1892               ;; line...
1893               (or (eobp)
1894                   ;; If it was eob instead of ?\n, we allow it.
1895                   (progn
1896                     ;; The line was buggy.
1897                     (setq group nil)
1898                     (gnus-error 3.1 "Mangled line: %s"
1899                                 (buffer-substring (gnus-point-at-bol)
1900                                                   (gnus-point-at-eol)))))
1901               nil))
1902           ;; Skip past ", ".  Spaces are illegal in these ranges, but
1903           ;; we allow them, because it's a common mistake to put a
1904           ;; space after the comma.
1905           (skip-chars-forward ", "))
1906
1907         ;; We have already read .newsrc.eld, so we gently update the
1908         ;; data in the hash table with the information we have just
1909         ;; read.
1910         (when group
1911           (let ((info (gnus-get-info group))
1912                 level)
1913             (if info
1914                 ;; There is an entry for this file in the alist.
1915                 (progn
1916                   (gnus-info-set-read info (nreverse reads))
1917                   ;; We update the level very gently.  In fact, we
1918                   ;; only change it if there's been a status change
1919                   ;; from subscribed to unsubscribed, or vice versa.
1920                   (setq level (gnus-info-level info))
1921                   (cond ((and (<= level gnus-level-subscribed)
1922                               (not subscribed))
1923                          (setq level (if reads
1924                                          gnus-level-default-unsubscribed
1925                                        (1+ gnus-level-default-unsubscribed))))
1926                         ((and (> level gnus-level-subscribed) subscribed)
1927                          (setq level gnus-level-default-subscribed)))
1928                   (gnus-info-set-level info level))
1929               ;; This is a new group.
1930               (setq info (list group
1931                                (if subscribed
1932                                    gnus-level-default-subscribed
1933                                  (if reads
1934                                      (1+ gnus-level-subscribed)
1935                                    gnus-level-default-unsubscribed))
1936                                (nreverse reads))))
1937             (setq newsrc (cons info newsrc))))))
1938       (forward-line 1))
1939
1940     (setq newsrc (nreverse newsrc))
1941
1942     (if (not already-read)
1943         ()
1944       ;; We now have two newsrc lists - `newsrc', which is what we
1945       ;; have read from .newsrc, and `gnus-newsrc-alist', which is
1946       ;; what we've read from .newsrc.eld.  We have to merge these
1947       ;; lists.  We do this by "attaching" any (foreign) groups in the
1948       ;; gnus-newsrc-alist to the (native) group that precedes them.
1949       (let ((rc (cdr gnus-newsrc-alist))
1950             (prev gnus-newsrc-alist)
1951             entry mentry)
1952         (while rc
1953           (or (null (nth 4 (car rc)))   ; It's a native group.
1954               (assoc (caar rc) newsrc) ; It's already in the alist.
1955               (if (setq entry (assoc (caar prev) newsrc))
1956                   (setcdr (setq mentry (memq entry newsrc))
1957                           (cons (car rc) (cdr mentry)))
1958                 (setq newsrc (cons (car rc) newsrc))))
1959           (setq prev rc
1960                 rc (cdr rc)))))
1961
1962     (setq gnus-newsrc-alist newsrc)
1963     ;; We make the newsrc hashtb.
1964     (gnus-make-hashtable-from-newsrc-alist)
1965
1966     ;; Finally, if we read some options lines, we parse them.
1967     (or (string= gnus-newsrc-options "")
1968         (gnus-newsrc-parse-options gnus-newsrc-options))))
1969
1970 ;; Parse options lines to find "options -n !all rec.all" and stuff.
1971 ;; The return value will be a list on the form
1972 ;; ((regexp1 . ignore)
1973 ;;  (regexp2 . subscribe)...)
1974 ;; When handling new newsgroups, groups that match a `ignore' regexp
1975 ;; will be ignored, and groups that match a `subscribe' regexp will be
1976 ;; subscribed.  A line like
1977 ;; options -n !all rec.all
1978 ;; will lead to a list that looks like
1979 ;; (("^rec\\..+" . subscribe)
1980 ;;  ("^.+" . ignore))
1981 ;; So all "rec.*" groups will be subscribed, while all the other
1982 ;; groups will be ignored.  Note that "options -n !all rec.all" is very
1983 ;; different from "options -n rec.all !all".
1984 (defun gnus-newsrc-parse-options (options)
1985   (let (out eol)
1986     (save-excursion
1987       (gnus-set-work-buffer)
1988       (insert (regexp-quote options))
1989       ;; First we treat all continuation lines.
1990       (goto-char (point-min))
1991       (while (re-search-forward "\n[ \t]+" nil t)
1992         (replace-match " " t t))
1993       ;; Then we transform all "all"s into ".+"s.
1994       (goto-char (point-min))
1995       (while (re-search-forward "\\ball\\b" nil t)
1996         (replace-match ".+" t t))
1997       (goto-char (point-min))
1998       ;; We remove all other options than the "-n" ones.
1999       (while (re-search-forward "[ \t]-[^n][^-]*" nil t)
2000         (replace-match " ")
2001         (forward-char -1))
2002       (goto-char (point-min))
2003
2004       ;; We are only interested in "options -n" lines - we
2005       ;; ignore the other option lines.
2006       (while (re-search-forward "[ \t]-n" nil t)
2007         (setq eol
2008               (or (save-excursion
2009                     (and (re-search-forward "[ \t]-n" (gnus-point-at-eol) t)
2010                          (- (point) 2)))
2011                   (gnus-point-at-eol)))
2012         ;; Search for all "words"...
2013         (while (re-search-forward "[^ \t,\n]+" eol t)
2014           (if (= (char-after (match-beginning 0)) ?!)
2015               ;; If the word begins with a bang (!), this is a "not"
2016               ;; spec.  We put this spec (minus the bang) and the
2017               ;; symbol `ignore' into the list.
2018               (setq out (cons (cons (concat
2019                                      "^" (buffer-substring
2020                                           (1+ (match-beginning 0))
2021                                           (match-end 0)))
2022                                     'ignore) out))
2023             ;; There was no bang, so this is a "yes" spec.
2024             (setq out (cons (cons (concat "^" (match-string 0))
2025                                   'subscribe) out)))))
2026
2027       (setq gnus-newsrc-options-n out))))
2028
2029 (defun gnus-save-newsrc-file (&optional force)
2030   "Save .newsrc file."
2031   ;; Note: We cannot save .newsrc file if all newsgroups are removed
2032   ;; from the variable gnus-newsrc-alist.
2033   (when (and (or gnus-newsrc-alist gnus-killed-list)
2034              gnus-current-startup-file)
2035     (save-excursion
2036       (if (and (or gnus-use-dribble-file gnus-slave)
2037                (not force)
2038                (or (not gnus-dribble-buffer)
2039                    (not (buffer-name gnus-dribble-buffer))
2040                    (zerop (save-excursion
2041                             (set-buffer gnus-dribble-buffer)
2042                             (buffer-size)))))
2043           (gnus-message 4 "(No changes need to be saved)")
2044         (run-hooks 'gnus-save-newsrc-hook)
2045         (if gnus-slave
2046             (gnus-slave-save-newsrc)
2047           ;; Save .newsrc.
2048           (when gnus-save-newsrc-file
2049             (gnus-message 5 "Saving %s..." gnus-current-startup-file)
2050             (gnus-gnus-to-newsrc-format)
2051             (gnus-message 5 "Saving %s...done" gnus-current-startup-file))
2052           ;; Save .newsrc.eld.
2053           (set-buffer (get-buffer-create " *Gnus-newsrc*"))
2054           (make-local-variable 'version-control)
2055           (setq version-control 'never)
2056           (setq buffer-file-name
2057                 (concat gnus-current-startup-file ".eld"))
2058           (setq default-directory (file-name-directory buffer-file-name))
2059           (gnus-add-current-to-buffer-list)
2060           (buffer-disable-undo (current-buffer))
2061           (erase-buffer)
2062           (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file)
2063           (gnus-gnus-to-quick-newsrc-format)
2064           (run-hooks 'gnus-save-quick-newsrc-hook)
2065           (save-buffer)
2066           (kill-buffer (current-buffer))
2067           (gnus-message
2068            5 "Saving %s.eld...done" gnus-current-startup-file))
2069         (gnus-dribble-delete-file)
2070         (gnus-group-set-mode-line)))))
2071
2072 (defun gnus-gnus-to-quick-newsrc-format ()
2073   "Insert Gnus variables such as gnus-newsrc-alist in lisp format."
2074   (insert ";; Gnus startup file.\n")
2075   (insert ";; Never delete this file - touch .newsrc instead to force Gnus\n")
2076   (insert ";; to read .newsrc.\n")
2077   (insert "(setq gnus-newsrc-file-version "
2078           (prin1-to-string gnus-version) ")\n")
2079   (let ((variables
2080          (if gnus-save-killed-list gnus-variable-list
2081            ;; Remove the `gnus-killed-list' from the list of variables
2082            ;; to be saved, if required.
2083            (delq 'gnus-killed-list (copy-sequence gnus-variable-list))))
2084         ;; Peel off the "dummy" group.
2085         (gnus-newsrc-alist (cdr gnus-newsrc-alist))
2086         variable)
2087     ;; Insert the variables into the file.
2088     (while variables
2089       (when (and (boundp (setq variable (pop variables)))
2090                  (symbol-value variable))
2091         (insert "(setq " (symbol-name variable) " '")
2092         (prin1 (symbol-value variable) (current-buffer))
2093         (insert ")\n")))))
2094
2095 (defun gnus-gnus-to-newsrc-format ()
2096   ;; Generate and save the .newsrc file.
2097   (save-excursion
2098     (set-buffer (create-file-buffer gnus-current-startup-file))
2099     (let ((newsrc (cdr gnus-newsrc-alist))
2100           (standard-output (current-buffer))
2101           info ranges range method)
2102       (setq buffer-file-name gnus-current-startup-file)
2103       (setq default-directory (file-name-directory buffer-file-name))
2104       (buffer-disable-undo (current-buffer))
2105       (erase-buffer)
2106       ;; Write options.
2107       (if gnus-newsrc-options (insert gnus-newsrc-options))
2108       ;; Write subscribed and unsubscribed.
2109       (while (setq info (pop newsrc))
2110         ;; Don't write foreign groups to .newsrc.
2111         (when (or (null (setq method (gnus-info-method info)))
2112                   (equal method "native")
2113                   (gnus-server-equal method gnus-select-method))
2114           (insert (gnus-info-group info)
2115                   (if (> (gnus-info-level info) gnus-level-subscribed)
2116                       "!" ":"))
2117           (when (setq ranges (gnus-info-read info))
2118             (insert " ")
2119             (if (not (listp (cdr ranges)))
2120                 (if (= (car ranges) (cdr ranges))
2121                     (princ (car ranges))
2122                   (princ (car ranges))
2123                   (insert "-")
2124                   (princ (cdr ranges)))
2125               (while (setq range (pop ranges))
2126                 (if (or (atom range) (= (car range) (cdr range)))
2127                     (princ (or (and (atom range) range) (car range)))
2128                   (princ (car range))
2129                   (insert "-")
2130                   (princ (cdr range)))
2131                 (if ranges (insert ",")))))
2132           (insert "\n")))
2133       (make-local-variable 'version-control)
2134       (setq version-control 'never)
2135       ;; It has been reported that sometime the modtime on the .newsrc
2136       ;; file seems to be off.  We really do want to overwrite it, so
2137       ;; we clear the modtime here before saving.  It's a bit odd,
2138       ;; though...
2139       ;; sometimes the modtime clear isn't sufficient.  most brute force:
2140       ;; delete the silly thing entirely first.  but this fails to provide
2141       ;; such niceties as .newsrc~ creation.
2142       (if gnus-modtime-botch
2143           (delete-file gnus-startup-file)
2144         (clear-visited-file-modtime))
2145       (run-hooks 'gnus-save-standard-newsrc-hook)
2146       (save-buffer)
2147       (kill-buffer (current-buffer)))))
2148
2149 \f
2150 ;;;
2151 ;;; Slave functions.
2152 ;;;
2153
2154 (defun gnus-slave-save-newsrc ()
2155   (save-excursion
2156     (set-buffer gnus-dribble-buffer)
2157     (let ((slave-name
2158            (make-temp-name (concat gnus-current-startup-file "-slave-"))))
2159       (write-region (point-min) (point-max) slave-name nil 'nomesg))))
2160
2161 (defun gnus-master-read-slave-newsrc ()
2162   (let ((slave-files
2163          (directory-files
2164           (file-name-directory gnus-current-startup-file)
2165           t (concat
2166              "^" (regexp-quote
2167                   (concat
2168                    (file-name-nondirectory gnus-current-startup-file)
2169                    "-slave-")))
2170           t))
2171         file)
2172     (if (not slave-files)
2173         ()                              ; There are no slave files to read.
2174       (gnus-message 7 "Reading slave newsrcs...")
2175       (save-excursion
2176         (set-buffer (get-buffer-create " *gnus slave*"))
2177         (buffer-disable-undo (current-buffer))
2178         (setq slave-files
2179               (sort (mapcar (lambda (file)
2180                               (list (nth 5 (file-attributes file)) file))
2181                             slave-files)
2182                     (lambda (f1 f2)
2183                       (or (< (caar f1) (caar f2))
2184                           (< (nth 1 (car f1)) (nth 1 (car f2)))))))
2185         (while slave-files
2186           (erase-buffer)
2187           (setq file (nth 1 (car slave-files)))
2188           (insert-file-contents file)
2189           (if (condition-case ()
2190                   (progn
2191                     (eval-buffer (current-buffer))
2192                     t)
2193                 (error
2194                  (gnus-error 3.2 "Possible error in %s" file)
2195                  nil))
2196               (or gnus-slave ; Slaves shouldn't delete these files.
2197                   (condition-case ()
2198                       (delete-file file)
2199                     (error nil))))
2200           (setq slave-files (cdr slave-files))))
2201       (gnus-message 7 "Reading slave newsrcs...done"))))
2202
2203 \f
2204 ;;;
2205 ;;; Group description.
2206 ;;;
2207
2208 (defun gnus-read-all-descriptions-files ()
2209   (let ((methods (cons gnus-select-method 
2210                        (nconc
2211                         (when (gnus-archive-server-wanted-p)
2212                           (list "archive"))
2213                         gnus-secondary-select-methods))))
2214     (while methods
2215       (gnus-read-descriptions-file (car methods))
2216       (setq methods (cdr methods)))
2217     t))
2218
2219 (defun gnus-read-descriptions-file (&optional method)
2220   (let ((method (or method gnus-select-method))
2221         group)
2222     (when (stringp method)
2223       (setq method (gnus-server-to-method method)))
2224     ;; We create the hashtable whether we manage to read the desc file
2225     ;; to avoid trying to re-read after a failed read.
2226     (or gnus-description-hashtb
2227         (setq gnus-description-hashtb
2228               (gnus-make-hashtable (length gnus-active-hashtb))))
2229     ;; Mark this method's desc file as read.
2230     (gnus-sethash (gnus-group-prefixed-name "" method) "Has read"
2231                   gnus-description-hashtb)
2232
2233     (gnus-message 5 "Reading descriptions file via %s..." (car method))
2234     (cond
2235      ((not (gnus-check-server method))
2236       (gnus-message 1 "Couldn't open server")
2237       nil)
2238      ((not (gnus-request-list-newsgroups method))
2239       (gnus-message 1 "Couldn't read newsgroups descriptions")
2240       nil)
2241      (t
2242       (save-excursion
2243         (save-restriction
2244           (set-buffer nntp-server-buffer)
2245           (goto-char (point-min))
2246           (when (or (search-forward "\n.\n" nil t)
2247                     (goto-char (point-max)))
2248             (beginning-of-line)
2249             (narrow-to-region (point-min) (point)))
2250           ;; If these are groups from a foreign select method, we insert the
2251           ;; group prefix in front of the group names.
2252           (and method (not (gnus-server-equal
2253                             (gnus-server-get-method nil method)
2254                             (gnus-server-get-method nil gnus-select-method)))
2255                (let ((prefix (gnus-group-prefixed-name "" method)))
2256                  (goto-char (point-min))
2257                  (while (and (not (eobp))
2258                              (progn (insert prefix)
2259                                     (zerop (forward-line 1)))))))
2260           (goto-char (point-min))
2261           (while (not (eobp))
2262             ;; If we get an error, we set group to 0, which is not a
2263             ;; symbol...
2264             (setq group
2265                   (condition-case ()
2266                       (let ((obarray gnus-description-hashtb))
2267                         ;; Group is set to a symbol interned in this
2268                         ;; hash table.
2269                         (read nntp-server-buffer))
2270                     (error 0)))
2271             (skip-chars-forward " \t")
2272             ;; ...  which leads to this line being effectively ignored.
2273             (and (symbolp group)
2274                  (set group (buffer-substring
2275                              (point) (progn (end-of-line) (point)))))
2276             (forward-line 1))))
2277       (gnus-message 5 "Reading descriptions file...done")
2278       t))))
2279
2280 (defun gnus-group-get-description (group)
2281   "Get the description of a group by sending XGTITLE to the server."
2282   (when (gnus-request-group-description group)
2283     (save-excursion
2284       (set-buffer nntp-server-buffer)
2285       (goto-char (point-min))
2286       (when (looking-at "[^ \t]+[ \t]+\\(.*\\)")
2287         (match-string 1)))))
2288
2289 ;;;###autoload
2290 (defun gnus-declare-backend (name &rest abilities)
2291   "Declare backend NAME with ABILITIES as a Gnus backend."
2292   (setq gnus-valid-select-methods
2293         (nconc gnus-valid-select-methods
2294                (list (apply 'list name abilities)))))
2295
2296 (provide 'gnus-start)
2297
2298 ;;; gnus-start.el ends here