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