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