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