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