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