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