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