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