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