1 ;;; gnus-start.el --- startup functions for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
35 (autoload 'message-make-date "message")
36 (eval-when-compile (require 'cl))
38 (defcustom gnus-startup-file (nnheader-concat gnus-home-directory ".newsrc")
40 `.newsrc-SERVER' will be used instead if that exists."
44 (defcustom gnus-backup-startup-file 'never
45 "Whether to create backup files.
46 This variable takes the same values as the `version-control'
49 :type '(choice (const :tag "Never" never)
50 (const :tag "If existing" nil)
51 (other :tag "Always" t)))
53 (defcustom gnus-save-startup-file-via-temp-buffer t
54 "Whether to write the startup file contents to a buffer then save
55 the buffer or write directly to the file. The buffer is faster
56 because all of the contents are written at once. The direct write
57 uses considerably less memory."
59 :type '(choice (const :tag "Write via buffer" t)
60 (const :tag "Write directly to file" nil)))
62 (defcustom gnus-init-file (nnheader-concat gnus-home-directory ".gnus")
63 "Your Gnus Emacs-Lisp startup file name.
64 If a file with the `.el' or `.elc' suffixes exists, it will be read instead."
68 (defcustom gnus-site-init-file
70 (concat (file-name-directory
71 (directory-file-name installation-directory))
72 "site-lisp/gnus-init")
74 "The site-wide Gnus Emacs-Lisp startup file name, or nil if none.
75 If a file with the `.el' or `.elc' suffixes exists, it will be read instead."
77 :type '(choice file (const nil)))
79 (defcustom gnus-default-subscribed-newsgroups nil
80 "List of newsgroups to subscribe, when a user runs Gnus the first time.
81 The value should be a list of strings.
82 If it is t, Gnus will not do anything special the first time it is
83 started; it'll just use the normal newsgroups subscription methods."
85 :type '(choice (repeat string) (const :tag "Nothing special" t)))
87 (defcustom gnus-use-dribble-file t
88 "*Non-nil means that Gnus will use a dribble file to store user updates.
89 If Emacs should crash without saving the .newsrc files, complete
90 information can be restored from the dribble file."
91 :group 'gnus-dribble-file
94 (defcustom gnus-dribble-directory nil
95 "*The directory where dribble files will be saved.
96 If this variable is nil, the directory where the .newsrc files are
98 :group 'gnus-dribble-file
99 :type '(choice directory (const nil)))
101 (defcustom gnus-check-new-newsgroups 'ask-server
102 "*Non-nil means that Gnus will run `gnus-find-new-newsgroups' at startup.
103 This normally finds new newsgroups by comparing the active groups the
104 servers have already reported with those Gnus already knows, either alive
107 When any of the following are true, `gnus-find-new-newsgroups' will instead
108 ask the servers (primary, secondary, and archive servers) to list new
109 groups since the last time it checked:
110 1. This variable is `ask-server'.
111 2. This variable is a list of select methods (see below).
112 3. `gnus-read-active-file' is nil or `some'.
113 4. A prefix argument is given to `gnus-find-new-newsgroups' interactively.
115 Thus, if this variable is `ask-server' or a list of select methods or
116 `gnus-read-active-file' is nil or `some', then the killed list is no
117 longer necessary, so you could safely set `gnus-save-killed-list' to nil.
119 This variable can be a list of select methods which Gnus will query with
120 the `ask-server' method in addition to the primary, secondary, and archive
124 (setq gnus-check-new-newsgroups
125 '((nntp \"some.server\") (nntp \"other.server\")))
127 If this variable is nil, then you have to tell Gnus explicitly to
128 check for new newsgroups with \\<gnus-group-mode-map>\\[gnus-find-new-newsgroups]."
130 :type '(choice (const :tag "no" nil)
131 (const :tag "by brute force" t)
132 (const :tag "ask servers" ask-server)
133 (repeat :menu-tag "ask additional servers"
134 :tag "ask additional servers"
136 (sexp :format "%v"))))
138 (defcustom gnus-check-bogus-newsgroups nil
139 "*Non-nil means that Gnus will check and remove bogus newsgroup at startup.
140 If this variable is nil, then you have to tell Gnus explicitly to
141 check for bogus newsgroups with \\<gnus-group-mode-map>\\[gnus-group-check-bogus-groups]."
142 :group 'gnus-start-server
145 (defcustom gnus-read-active-file 'some
146 "*Non-nil means that Gnus will read the entire active file at startup.
147 If this variable is nil, Gnus will only know about the groups in your
150 If this variable is `some', Gnus will try to only read the relevant
151 parts of the active file from the server. Not all servers support
152 this, and it might be quite slow with other servers, but this should
153 generally be faster than both the t and nil value.
155 If you set this variable to nil or `some', you probably still want to
156 be told about new newsgroups that arrive. To do that, set
157 `gnus-check-new-newsgroups' to `ask-server'. This may not work
158 properly with all servers."
159 :group 'gnus-start-server
160 :type '(choice (const nil)
164 (defconst gnus-level-subscribed 5
165 "Groups with levels less than or equal to this variable are subscribed.")
167 (defconst gnus-level-unsubscribed 7
168 "Groups with levels less than or equal to this variable are unsubscribed.
169 Groups with levels less than `gnus-level-subscribed', which should be
170 less than this variable, are subscribed.")
172 (defconst gnus-level-zombie 8
173 "Groups with this level are zombie groups.")
175 (defconst gnus-level-killed 9
176 "Groups with this level are killed.")
178 (defcustom gnus-level-default-subscribed 3
179 "*New subscribed groups will be subscribed at this level."
180 :group 'gnus-group-levels
183 (defcustom gnus-level-default-unsubscribed 6
184 "*New unsubscribed groups will be unsubscribed at this level."
185 :group 'gnus-group-levels
188 (defcustom gnus-activate-level (1+ gnus-level-subscribed)
189 "*Groups higher than this level won't be activated on startup.
190 Setting this variable to something low might save lots of time when
191 you have many groups that you aren't interested in."
192 :group 'gnus-group-levels
195 (defcustom gnus-activate-foreign-newsgroups 4
196 "*If nil, Gnus will not check foreign newsgroups at startup.
197 If it is non-nil, it should be a number between one and nine. Foreign
198 newsgroups that have a level lower or equal to this number will be
199 activated on startup. For instance, if you want to active all
200 subscribed newsgroups, but not the rest, you'd set this variable to
201 `gnus-level-subscribed'.
203 If you subscribe to lots of newsgroups from different servers, startup
204 might take a while. By setting this variable to nil, you'll save time,
205 but you won't be told how many unread articles there are in the
207 :group 'gnus-group-levels
208 :type '(choice integer
209 (const :tag "none" nil)))
211 (defcustom gnus-read-newsrc-file t
212 "*Non-nil means that Gnus will read the `.newsrc' file.
213 Gnus always reads its own startup file, which is called
214 \".newsrc.eld\". The file called \".newsrc\" is in a format that can
215 be readily understood by other newsreaders. If you don't plan on
216 using other newsreaders, set this variable to nil to save some time on
222 (defcustom gnus-save-newsrc-file t
223 "*Non-nil means that Gnus will save the `.newsrc' file.
224 Gnus always saves its own startup file, which is called
225 \".newsrc.eld\". The file called \".newsrc\" is in a format that can
226 be readily understood by other newsreaders. If you don't plan on
227 using other newsreaders, set this variable to nil to save some time on
232 (defcustom gnus-save-killed-list t
233 "*If non-nil, save the list of killed groups to the startup file.
234 If you set this variable to nil, you'll save both time (when starting
235 and quitting) and space (both memory and disk), but it will also mean
236 that Gnus has no record of which groups are new and which are old, so
237 the automatic new newsgroups subscription methods become meaningless.
239 You should always set `gnus-check-new-newsgroups' to `ask-server' or
240 nil if you set this variable to nil.
242 This variable can also be a regexp. In that case, all groups that do
243 not match this regexp will be removed before saving the list."
247 (defcustom gnus-ignored-newsgroups
249 '("^to\\." ; not "real" groups
250 "^[0-9. \t]+\\( \\|$\\)" ; all digits in name
251 "^[\"][]\"[#'()]" ; bogus characters
254 "*A regexp to match uninteresting newsgroups in the active file.
255 Any lines in the active file matching this regular expression are
256 removed from the newsgroup list before anything else is done to it,
257 thus making them effectively non-existent."
258 :group 'gnus-group-new
261 (defcustom gnus-subscribe-newsgroup-method 'gnus-subscribe-zombies
262 "*Function(s) called with a group name when new group is detected.
263 A few pre-made functions are supplied: `gnus-subscribe-randomly'
264 inserts new groups at the beginning of the list of groups;
265 `gnus-subscribe-alphabetically' inserts new groups in strict
266 alphabetic order; `gnus-subscribe-hierarchically' inserts new groups
267 in hierarchical newsgroup order; `gnus-subscribe-interactively' asks
268 for your decision; `gnus-subscribe-killed' kills all new groups;
269 `gnus-subscribe-zombies' will make all new groups into zombies;
270 `gnus-subscribe-topics' will enter groups into the topics that
272 :group 'gnus-group-new
273 :type '(radio (function-item gnus-subscribe-randomly)
274 (function-item gnus-subscribe-alphabetically)
275 (function-item gnus-subscribe-hierarchically)
276 (function-item gnus-subscribe-interactively)
277 (function-item gnus-subscribe-killed)
278 (function-item gnus-subscribe-zombies)
279 (function-item gnus-subscribe-topics)
283 (defcustom gnus-subscribe-newsgroup-hooks nil
284 "*Hooks run after you subscribe to a new group. The hooks will be called
285 with new group's name as argument."
286 :group 'gnus-group-new
289 (defcustom gnus-subscribe-options-newsgroup-method
290 'gnus-subscribe-alphabetically
291 "*Function(s) called to subscribe newsgroups mentioned on \"options -n\" lines.
292 If, for instance, you want to subscribe to all newsgroups in the
293 \"no\" and \"alt\" hierarchies, you'd put the following in your
296 options -n no.all alt.all
298 Gnus will the subscribe all new newsgroups in these hierarchies with
299 the subscription method in this variable."
300 :group 'gnus-group-new
301 :type '(radio (function-item gnus-subscribe-randomly)
302 (function-item gnus-subscribe-alphabetically)
303 (function-item gnus-subscribe-hierarchically)
304 (function-item gnus-subscribe-interactively)
305 (function-item gnus-subscribe-killed)
306 (function-item gnus-subscribe-zombies)
307 (function-item gnus-subscribe-topics)
311 (defcustom gnus-subscribe-hierarchical-interactive nil
312 "*If non-nil, Gnus will offer to subscribe hierarchically.
313 When a new hierarchy appears, Gnus will ask the user:
315 'alt.binaries': Do you want to subscribe to this hierarchy? ([d]ys):
317 If the user pressed `d', Gnus will descend the hierarchy, `y' will
318 subscribe to all newsgroups in the hierarchy and `s' will skip this
319 hierarchy in its entirety."
320 :group 'gnus-group-new
323 (defcustom gnus-auto-subscribed-groups
324 "^nnml\\|^nnfolder\\|^nnmbox\\|^nnmh\\|^nnbabyl\\|^nnmaildir"
325 "*All new groups that match this regexp will be subscribed automatically.
326 Note that this variable only deals with new groups. It has no effect
327 whatsoever on old groups.
329 New groups that match this regexp will not be handled by
330 `gnus-subscribe-newsgroup-method'. Instead, they will
331 be subscribed using `gnus-subscribe-options-newsgroup-method'."
332 :group 'gnus-group-new
335 (defcustom gnus-options-subscribe nil
336 "*All new groups matching this regexp will be subscribed unconditionally.
337 Note that this variable deals only with new newsgroups. This variable
338 does not affect old newsgroups.
340 New groups that match this regexp will not be handled by
341 `gnus-subscribe-newsgroup-method'. Instead, they will
342 be subscribed using `gnus-subscribe-options-newsgroup-method'."
343 :group 'gnus-group-new
344 :type '(choice regexp
345 (const :tag "none" nil)))
347 (defcustom gnus-options-not-subscribe nil
348 "*All new groups matching this regexp will be ignored.
349 Note that this variable deals only with new newsgroups. This variable
350 does not affect old (already subscribed) newsgroups."
351 :group 'gnus-group-new
352 :type '(choice regexp
353 (const :tag "none" nil)))
355 (defcustom gnus-modtime-botch nil
356 "*Non-nil means .newsrc should be deleted prior to save.
357 Its use is due to the bogus appearance that .newsrc was modified on
362 (defcustom gnus-check-bogus-groups-hook nil
363 "A hook run after removing bogus groups."
364 :group 'gnus-start-server
367 (defcustom gnus-startup-hook nil
368 "A hook called at startup.
369 This hook is called after Gnus is connected to the NNTP server."
373 (defcustom gnus-before-startup-hook nil
374 "A hook called at before startup.
375 This hook is called as the first thing when Gnus is started."
379 (defcustom gnus-started-hook nil
380 "A hook called as the last thing after startup."
384 (defcustom gnus-setup-news-hook
385 '(gnus-fixup-nnimap-unread-after-getting-new-news)
386 "A hook after reading the .newsrc file, but before generating the buffer."
390 (defcustom gnus-get-top-new-news-hook nil
391 "A hook run just before Gnus checks for new news globally."
392 :group 'gnus-group-new
395 (defcustom gnus-get-new-news-hook nil
396 "A hook run just before Gnus checks for new news."
397 :group 'gnus-group-new
400 (defcustom gnus-after-getting-new-news-hook
401 '(gnus-display-time-event-handler
402 gnus-fixup-nnimap-unread-after-getting-new-news)
403 "*A hook run after Gnus checks for new news when Gnus is already running."
404 :group 'gnus-group-new
407 (defcustom gnus-read-newsrc-el-hook nil
408 "A hook called after reading the newsrc.eld? file."
412 (defcustom gnus-save-newsrc-hook nil
413 "A hook called before saving any of the newsrc files."
417 (defcustom gnus-save-quick-newsrc-hook nil
418 "A hook called just before saving the quick newsrc file.
419 Can be used to turn version control on or off."
423 (defcustom gnus-save-standard-newsrc-hook nil
424 "A hook called just before saving the standard newsrc file.
425 Can be used to turn version control on or off."
429 (defcustom gnus-group-mode-hook nil
430 "Hook for Gnus group mode."
431 :group 'gnus-group-various
432 :options '(gnus-topic-mode)
435 (defcustom gnus-always-read-dribble-file nil
436 "Unconditionally read the dribble file."
440 ;;; Internal variables
442 (defvar gnus-ding-file-coding-system mm-universal-coding-system
443 "Coding system for ding file.")
445 (defvar gnus-newsrc-file-version nil)
446 (defvar gnus-override-subscribe-method nil)
447 (defvar gnus-dribble-buffer nil)
448 (defvar gnus-newsrc-options nil
449 "Options line in the .newsrc file.")
451 (defvar gnus-newsrc-options-n nil
452 "List of regexps representing groups to be subscribed/ignored unconditionally.")
454 (defvar gnus-newsrc-last-checked-date nil
455 "Date Gnus last asked server for new newsgroups.")
457 (defvar gnus-current-startup-file nil
458 "Startup file for the current host.")
460 ;; Byte-compiler warning.
461 (defvar gnus-group-line-format)
463 ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
464 (defvar gnus-init-inhibit nil)
465 (defun gnus-read-init-file (&optional inhibit-next)
466 ;; Don't load .gnus if the -q option was used.
468 (if gnus-init-inhibit
469 (setq gnus-init-inhibit nil)
470 (setq gnus-init-inhibit inhibit-next)
471 (dolist (file (list gnus-site-init-file gnus-init-file))
473 (locate-library file))
474 (if (or debug-on-error debug-on-quit)
479 (error "Error in %s: %s" file (cadr var))))))))))
481 ;; For subscribing new newsgroup
483 (defun gnus-subscribe-hierarchical-interactive (groups)
484 (let ((groups (sort groups 'string<))
485 prefixes prefix start ans group starts)
487 (setq prefixes (list "^"))
488 (while (and groups prefixes)
489 (while (not (string-match (car prefixes) (car groups)))
490 (setq prefixes (cdr prefixes)))
491 (setq prefix (car prefixes))
492 (setq start (1- (length prefix)))
493 (if (and (string-match "[^\\.]\\." (car groups) start)
496 (concat "^" (substring (car groups) 0 (match-end 0))))
497 (string-match prefix (cadr groups)))
499 (push prefix prefixes)
500 (message "Descend hierarchy %s? ([y]nsq): "
501 (substring prefix 1 (1- (length prefix))))
502 (while (not (memq (setq ans (read-char-exclusive))
503 '(?y ?\n ?\r ?n ?s ?q)))
505 (message "Descend hierarchy %s? ([y]nsq): "
506 (substring prefix 1 (1- (length prefix)))))
510 (setq group (car groups))))
511 (push group gnus-killed-list)
512 (gnus-sethash group group gnus-killed-hashtb)
513 (setq groups (cdr groups)))
514 (setq starts (cdr starts)))
518 (setq group (car groups))))
519 (gnus-sethash group group gnus-killed-hashtb)
520 (gnus-subscribe-alphabetically (car groups))
521 (setq groups (cdr groups)))
522 (setq starts (cdr starts)))
525 (setq group (car groups))
526 (push group gnus-killed-list)
527 (gnus-sethash group group gnus-killed-hashtb)
528 (setq groups (cdr groups))))
530 (message "Subscribe %s? ([n]yq)" (car groups))
531 (while (not (memq (setq ans (read-char-exclusive))
532 '(?y ?\n ?\r ?q ?n)))
534 (message "Subscribe %s? ([n]yq)" (car groups)))
535 (setq group (car groups))
537 (gnus-subscribe-alphabetically (car groups))
538 (gnus-sethash group group gnus-killed-hashtb))
541 (setq group (car groups))
542 (push group gnus-killed-list)
543 (gnus-sethash group group gnus-killed-hashtb)
544 (setq groups (cdr groups))))
546 (push group gnus-killed-list)
547 (gnus-sethash group group gnus-killed-hashtb)))
548 (setq groups (cdr groups)))))))
550 (defun gnus-subscribe-randomly (newsgroup)
551 "Subscribe new NEWSGROUP by making it the first newsgroup."
552 (gnus-subscribe-newsgroup newsgroup))
554 (defun gnus-subscribe-alphabetically (newgroup)
555 "Subscribe new NEWSGROUP and insert it in alphabetical order."
556 (let ((groups (cdr gnus-newsrc-alist))
558 (while (and (not before) groups)
559 (if (string< newgroup (caar groups))
560 (setq before (caar groups))
561 (setq groups (cdr groups))))
562 (gnus-subscribe-newsgroup newgroup before)))
564 (defun gnus-subscribe-hierarchically (newgroup)
565 "Subscribe new NEWSGROUP and insert it in hierarchical newsgroup order."
566 ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
568 (set-buffer (nnheader-find-file-noselect gnus-current-startup-file))
570 (let ((groupkey newgroup) before)
571 (while (and (not before) groupkey)
572 (goto-char (point-min))
574 (concat "^\\(" (regexp-quote groupkey) ".*\\)[!:]")))
575 (while (and (re-search-forward groupkey-re nil t)
577 (setq before (match-string 1))
578 (string< before newgroup)))))
579 ;; Remove tail of newsgroup name (eg. a.b.c -> a.b)
581 (when (string-match "^\\(.*\\)\\.[^.]+$" groupkey)
582 (substring groupkey (match-beginning 1) (match-end 1)))))
583 (gnus-subscribe-newsgroup newgroup before))
584 (kill-buffer (current-buffer)))))
586 (defun gnus-subscribe-interactively (group)
587 "Subscribe the new GROUP interactively.
588 It is inserted in hierarchical newsgroup order if subscribed. If not,
590 (if (gnus-y-or-n-p (format "Subscribe new newsgroup: %s " group))
591 (gnus-subscribe-hierarchically group)
592 (push group gnus-killed-list)))
594 (defun gnus-subscribe-zombies (group)
595 "Make the new GROUP into a zombie group."
596 (push group gnus-zombie-list))
598 (defun gnus-subscribe-killed (group)
599 "Make the new GROUP a killed group."
600 (push group gnus-killed-list))
602 (defun gnus-subscribe-newsgroup (newsgroup &optional next)
603 "Subscribe new NEWSGROUP.
604 If NEXT is non-nil, it is inserted before NEXT. Otherwise it is made
605 the first newsgroup."
607 (goto-char (point-min))
608 ;; We subscribe the group by changing its level to `subscribed'.
609 (gnus-group-change-level
610 newsgroup gnus-level-default-subscribed
611 gnus-level-killed (gnus-gethash (or next "dummy.group")
613 (gnus-message 5 "Subscribe newsgroup: %s" newsgroup)
614 (run-hook-with-args 'gnus-subscribe-newsgroup-hooks newsgroup)
617 (defun gnus-read-active-file-p ()
618 "Say whether the active file has been read from `gnus-select-method'."
619 (memq gnus-select-method gnus-have-read-active-file))
621 ;;; General various misc type functions.
623 ;; Silence byte-compiler.
625 (defvar gnus-current-headers)
626 (defvar gnus-thread-indent-array)
627 (defvar gnus-newsgroup-name)
628 (defvar gnus-newsgroup-headers)
629 (defvar gnus-group-list-mode)
630 (defvar gnus-group-mark-positions)
631 (defvar gnus-newsgroup-data)
632 (defvar gnus-newsgroup-unreads)
633 (defvar nnoo-state-alist)
634 (defvar gnus-current-select-method)
635 (defvar mail-sources)
636 (defvar nnmail-scan-directory-mail-source-once)
637 (defvar nnmail-split-history)
638 (defvar nnmail-spool-file))
640 (defun gnus-close-all-servers ()
643 (dolist (server gnus-opened-servers)
644 (gnus-close-server (car server))))
646 (defun gnus-clear-system ()
647 "Clear all variables and buffers."
648 ;; Clear Gnus variables.
649 (let ((variables (remove 'gnus-format-specs gnus-variable-list)))
651 (set (car variables) nil)
652 (setq variables (cdr variables))))
653 ;; Clear other internal variables.
654 (setq gnus-list-of-killed-groups nil
655 gnus-have-read-active-file nil
656 gnus-newsrc-alist nil
657 gnus-newsrc-hashtb nil
660 gnus-killed-hashtb nil
661 gnus-active-hashtb nil
662 gnus-moderated-hashtb nil
663 gnus-description-hashtb nil
664 gnus-current-headers nil
665 gnus-thread-indent-array nil
666 gnus-newsgroup-headers nil
667 gnus-newsgroup-name nil
668 gnus-server-alist nil
669 gnus-group-list-mode nil
670 gnus-opened-servers nil
671 gnus-group-mark-positions nil
672 gnus-newsgroup-data nil
673 gnus-newsgroup-unreads nil
675 gnus-current-select-method nil
676 nnmail-split-history nil
677 gnus-ephemeral-servers nil)
678 (gnus-shutdown 'gnus)
679 ;; Kill the startup file.
680 (and gnus-current-startup-file
681 (get-file-buffer gnus-current-startup-file)
682 (kill-buffer (get-file-buffer gnus-current-startup-file)))
683 ;; Clear the dribble buffer.
685 ;; Kill global KILL file buffer.
686 (when (get-file-buffer (gnus-newsgroup-kill-file nil))
687 (kill-buffer (get-file-buffer (gnus-newsgroup-kill-file nil))))
688 (gnus-kill-buffer nntp-server-buffer)
689 ;; Kill Gnus buffers.
690 (dolist (buffer (gnus-buffers))
691 (gnus-kill-buffer buffer))
692 ;; Remove Gnus frames.
693 (gnus-kill-gnus-frames))
695 (defun gnus-no-server-1 (&optional arg slave)
697 If ARG is a positive number, Gnus will use that as the
698 startup level. If ARG is nil, Gnus will be started at level 2.
699 If ARG is non-nil and not a positive number, Gnus will
700 prompt the user for the name of an NNTP server to use.
701 As opposed to `gnus', this command will not connect to the local server."
703 (let ((val (or arg (1- gnus-level-default-subscribed))))
705 (make-local-variable 'gnus-group-use-permanent-levels)
706 (setq gnus-group-use-permanent-levels val)))
708 (defun gnus-1 (&optional arg dont-connect slave)
710 If ARG is non-nil and a positive number, Gnus will use that as the
711 startup level. If ARG is non-nil and not a positive number, Gnus will
712 prompt the user for the name of an NNTP server to use."
717 (switch-to-buffer gnus-group-buffer)
718 (gnus-group-get-new-news
721 (max (car gnus-group-list-mode) arg))))
725 (gnus-run-hooks 'gnus-before-startup-hook)
726 (nnheader-init-server-buffer)
727 (setq gnus-slave slave)
728 (gnus-read-init-file)
732 (when gnus-simple-splash
733 (setq gnus-simple-splash nil)
738 (= (frame-height) (1+ (window-height))))
741 (let ((level (and (numberp arg) (> arg 0) arg))
747 (gnus-start-news-server (and arg (not level))))))
748 (if (and (not dont-connect)
751 (gnus-run-hooks 'gnus-startup-hook)
752 ;; NNTP server is successfully open.
754 ;; Find the current startup file name.
755 (setq gnus-current-startup-file
756 (gnus-make-newsrc-file gnus-startup-file))
758 ;; Read the dribble file.
759 (when (or gnus-slave gnus-use-dribble-file)
760 (gnus-dribble-read-file))
762 ;; Allow using GroupLens predictions.
763 (when gnus-use-grouplens
765 (add-hook 'gnus-summary-mode-hook 'gnus-grouplens-mode))
767 ;; Do the actual startup.
769 (gnus-request-create-group "queue" '(nndraft "")))
770 (gnus-request-create-group "drafts" '(nndraft ""))
771 (gnus-setup-news nil level dont-connect)
772 (gnus-run-hooks 'gnus-setup-news-hook)
773 (gnus-start-draft-setup)
774 ;; Generate the group buffer.
775 (gnus-group-list-groups level)
776 (gnus-group-first-unread-group)
777 (gnus-configure-windows 'group)
778 (gnus-group-set-mode-line)
779 (gnus-run-hooks 'gnus-started-hook))))))
781 (defun gnus-start-draft-setup ()
782 "Make sure the draft group exists."
783 (gnus-request-create-group "drafts" '(nndraft ""))
784 (unless (gnus-gethash "nndraft:drafts" gnus-newsrc-hashtb)
785 (let ((gnus-level-default-subscribed 1))
786 (gnus-subscribe-group "nndraft:drafts" nil '(nndraft "")))
787 (gnus-group-set-parameter
788 "nndraft:drafts" 'gnus-dummy '((gnus-draft-mode)))))
795 (defvar gnus-dribble-ignore nil)
796 (defvar gnus-dribble-eval-file nil)
798 (defun gnus-dribble-file-name ()
799 "Return the dribble file for the current .newsrc."
801 (if gnus-dribble-directory
802 (concat (file-name-as-directory gnus-dribble-directory)
803 (file-name-nondirectory gnus-current-startup-file))
804 gnus-current-startup-file)
807 (defun gnus-dribble-enter (string)
808 "Enter STRING into the dribble buffer."
809 (when (and (not gnus-dribble-ignore)
811 (buffer-name gnus-dribble-buffer))
812 (let ((obuf (current-buffer)))
813 (set-buffer gnus-dribble-buffer)
814 (goto-char (point-max))
816 ;; This has been commented by Josh Huber <huber@alum.wpi.edu>
817 ;; It causes problems with both XEmacs and Emacs 21, and doesn't
818 ;; seem to be of much value. (FIXME: remove this after we make sure
820 ;; (set-window-point (get-buffer-window (current-buffer)) (point-max))
821 (bury-buffer gnus-dribble-buffer)
823 (set-buffer gnus-group-buffer)
824 (gnus-group-set-mode-line))
827 (defun gnus-dribble-touch ()
828 "Touch the dribble buffer."
829 (gnus-dribble-enter ""))
831 (defun gnus-dribble-read-file ()
832 "Read the dribble file from disk."
833 (let ((dribble-file (gnus-dribble-file-name)))
835 (set-buffer (setq gnus-dribble-buffer
836 (gnus-get-buffer-create
837 (file-name-nondirectory dribble-file))))
839 (setq buffer-file-name dribble-file)
841 (buffer-disable-undo)
842 (bury-buffer (current-buffer))
843 (set-buffer-modified-p nil)
844 (let ((auto (make-auto-save-file-name))
845 (gnus-dribble-ignore t)
848 (when (or (file-exists-p auto) (file-exists-p dribble-file))
849 ;; Load whichever file is newest -- the auto save file
850 ;; or the "real" file.
851 (if (file-newer-than-file-p auto dribble-file)
852 (nnheader-insert-file-contents auto)
853 (nnheader-insert-file-contents dribble-file))
854 (unless (zerop (buffer-size))
855 (set-buffer-modified-p t))
856 ;; Set the file modes to reflect the .newsrc file modes.
858 (when (and (file-exists-p gnus-current-startup-file)
859 (file-exists-p dribble-file)
860 (setq modes (file-modes gnus-current-startup-file)))
861 (set-file-modes dribble-file modes))
862 (goto-char (point-min))
863 (when (search-forward "Gnus was exited on purpose" nil t)
865 ;; Possibly eval the file later.
866 (when (or gnus-always-read-dribble-file
869 "Gnus exited on purpose without saving; read auto-save file anyway? "
870 "Gnus auto-save file exists. Do you want to read it? ")))
871 (setq gnus-dribble-eval-file t)))))))
873 (defun gnus-dribble-eval-file ()
874 (when gnus-dribble-eval-file
875 (setq gnus-dribble-eval-file nil)
877 (let ((gnus-dribble-ignore t))
878 (set-buffer gnus-dribble-buffer)
879 (eval-buffer (current-buffer))))))
881 (defun gnus-dribble-delete-file ()
882 (when (file-exists-p (gnus-dribble-file-name))
883 (delete-file (gnus-dribble-file-name)))
884 (when gnus-dribble-buffer
886 (set-buffer gnus-dribble-buffer)
887 (let ((auto (make-auto-save-file-name)))
888 (when (file-exists-p auto)
891 (set-buffer-modified-p nil)))))
893 (defun gnus-dribble-save ()
894 (when (and gnus-dribble-buffer
895 (buffer-name gnus-dribble-buffer))
897 (set-buffer gnus-dribble-buffer)
900 (defun gnus-dribble-clear ()
901 (when (gnus-buffer-exists-p gnus-dribble-buffer)
903 (set-buffer gnus-dribble-buffer)
905 (set-buffer-modified-p nil)
906 (setq buffer-saved-size (buffer-size)))))
910 ;;; Active & Newsrc File Handling
913 (defun gnus-setup-news (&optional rawfile level dont-connect)
914 "Setup news information.
915 If RAWFILE is non-nil, the .newsrc file will also be read.
916 If LEVEL is non-nil, the news will be set up at level LEVEL."
918 (let ((init (not (and gnus-newsrc-alist gnus-active-hashtb (not rawfile))))
919 ;; Binding this variable will inhibit multiple fetchings
920 ;; of the same mail source.
921 (nnmail-fetched-sources (list t)))
924 ;; Clear some variables to re-initialize news information.
925 (setq gnus-newsrc-alist nil
926 gnus-active-hashtb nil)
927 ;; Read the newsrc file and create `gnus-newsrc-hashtb'.
928 (gnus-read-newsrc-file rawfile))
930 ;; Make sure the archive server is available to all and sundry.
931 (when gnus-message-archive-method
932 (unless (assoc "archive" gnus-server-alist)
937 ,(nnheader-concat message-directory "archive"))
938 (nnfolder-active-file
939 ,(nnheader-concat message-directory "archive/active"))
940 (nnfolder-get-new-mail nil)
941 (nnfolder-inhibit-expiry t))
944 ;; If we don't read the complete active file, we fill in the
946 (when (or (null gnus-read-active-file)
947 (eq gnus-read-active-file 'some))
948 (gnus-update-active-hashtb-from-killed))
950 ;; Read the active file and create `gnus-active-hashtb'.
951 ;; If `gnus-read-active-file' is nil, then we just create an empty
952 ;; hash table. The partial filling out of the hash table will be
953 ;; done in `gnus-get-unread-articles'.
954 (and gnus-read-active-file
956 (gnus-read-active-file nil dont-connect))
958 (unless gnus-active-hashtb
959 (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
961 ;; Initialize the cache.
965 ;; Possibly eval the dribble file.
967 (or gnus-use-dribble-file gnus-slave)
968 (gnus-dribble-eval-file))
970 ;; Slave Gnusii should then clear the dribble buffer.
971 (when (and init gnus-slave)
972 (gnus-dribble-clear))
974 (gnus-update-format-specifications)
976 ;; See whether we need to read the description file.
977 (when (and (boundp 'gnus-group-line-format)
978 (stringp gnus-group-line-format)
979 (let ((case-fold-search nil))
980 (string-match "%[-,0-9]*D" gnus-group-line-format))
981 (not gnus-description-hashtb)
983 gnus-read-active-file)
984 (gnus-read-all-descriptions-files))
986 ;; Find new newsgroups and treat them.
987 (when (and init gnus-check-new-newsgroups (not level)
988 (gnus-check-server gnus-select-method)
991 (gnus-find-new-newsgroups))
993 ;; Check and remove bogus newsgroups.
994 (when (and init gnus-check-bogus-newsgroups
995 gnus-read-active-file (not level)
996 (gnus-server-opened gnus-select-method))
997 (gnus-check-bogus-newsgroups))
999 ;; We might read in new NoCeM messages here.
1000 (when (and gnus-use-nocem
1003 (gnus-nocem-scan-groups))
1005 ;; Read any slave files.
1006 (gnus-master-read-slave-newsrc)
1008 ;; Find the number of unread articles in each non-dead group.
1009 (let ((gnus-read-active-file (and (not level) gnus-read-active-file)))
1010 (gnus-get-unread-articles level))))
1012 (defun gnus-call-subscribe-functions (method group)
1013 "Call METHOD to subscribe GROUP.
1014 If no function returns `non-nil', call `gnus-subscribe-zombies'."
1017 (funcall method group))
1020 (dolist (func method)
1021 (if (funcall func group)
1025 (gnus-subscribe-zombies group)))
1027 (defun gnus-find-new-newsgroups (&optional arg)
1028 "Search for new newsgroups and add them.
1029 Each new newsgroup will be treated with `gnus-subscribe-newsgroup-method'.
1030 The `-n' option line from .newsrc is respected.
1032 With 1 C-u, use the `ask-server' method to query the server for new
1034 With 2 C-u's, use most complete method possible to query the server
1035 for new groups, and subscribe the new groups as zombies."
1037 (let* ((gnus-subscribe-newsgroup-method
1038 gnus-subscribe-newsgroup-method)
1040 ((or (and (= (or arg 1) 4)
1041 (not (listp gnus-check-new-newsgroups)))
1042 (null gnus-read-active-file)
1043 (eq gnus-read-active-file 'some))
1046 (setq gnus-subscribe-newsgroup-method
1047 'gnus-subscribe-zombies)
1049 (t gnus-check-new-newsgroups))))
1050 (unless (gnus-check-first-time-used)
1051 (if (or (consp check)
1052 (eq check 'ask-server))
1053 ;; Ask the server for new groups.
1054 (gnus-ask-server-for-new-groups)
1055 ;; Go through the active hashtb and look for new groups.
1057 group new-newsgroups)
1058 (gnus-message 5 "Looking for new newsgroups...")
1059 (unless gnus-have-read-active-file
1060 (gnus-read-active-file))
1061 (setq gnus-newsrc-last-checked-date (message-make-date))
1062 (unless gnus-killed-hashtb
1063 (gnus-make-hashtable-from-killed))
1064 ;; Go though every newsgroup in `gnus-active-hashtb' and compare
1065 ;; with `gnus-newsrc-hashtb' and `gnus-killed-hashtb'.
1068 (if (or (null (setq group (symbol-name sym)))
1070 (null (symbol-value sym))
1071 (gnus-gethash group gnus-killed-hashtb)
1072 (gnus-gethash group gnus-newsrc-hashtb))
1074 (let ((do-sub (gnus-matches-options-n group)))
1076 ((eq do-sub 'subscribe)
1077 (setq groups (1+ groups))
1078 (gnus-sethash group group gnus-killed-hashtb)
1079 (gnus-call-subscribe-functions
1080 gnus-subscribe-options-newsgroup-method group))
1081 ((eq do-sub 'ignore)
1084 (setq groups (1+ groups))
1085 (gnus-sethash group group gnus-killed-hashtb)
1086 (if gnus-subscribe-hierarchical-interactive
1087 (push group new-newsgroups)
1088 (gnus-call-subscribe-functions
1089 gnus-subscribe-newsgroup-method group)))))))
1091 (when new-newsgroups
1092 (gnus-subscribe-hierarchical-interactive new-newsgroups))
1094 (gnus-message 5 "%d new newsgroup%s arrived."
1095 groups (if (> groups 1) "s have" " has"))
1096 (gnus-message 5 "No new newsgroups.")))))))
1098 (defun gnus-matches-options-n (group)
1099 ;; Returns `subscribe' if the group is to be unconditionally
1100 ;; subscribed, `ignore' if it is to be ignored, and nil if there is
1101 ;; no match for the group.
1103 ;; First we check the two user variables.
1105 ((and gnus-options-subscribe
1106 (string-match gnus-options-subscribe group))
1108 ((and gnus-auto-subscribed-groups
1109 (string-match gnus-auto-subscribed-groups group))
1111 ((and gnus-options-not-subscribe
1112 (string-match gnus-options-not-subscribe group))
1114 ;; Then we go through the list that was retrieved from the .newsrc
1115 ;; file. This list has elements on the form
1116 ;; `(REGEXP . {ignore,subscribe})'. The first match found (the list
1117 ;; is in the reverse order of the options line) is returned.
1119 (let ((regs gnus-newsrc-options-n))
1121 (not (string-match (caar regs) group)))
1122 (setq regs (cdr regs)))
1123 (and regs (cdar regs))))))
1125 (defun gnus-ask-server-for-new-groups ()
1126 (let* ((new-date (message-make-date))
1127 (date (or gnus-newsrc-last-checked-date new-date))
1128 (methods (cons gnus-select-method
1130 (when (gnus-archive-server-wanted-p)
1133 (and (consp gnus-check-new-newsgroups)
1134 gnus-check-new-newsgroups)
1135 gnus-secondary-select-methods))))
1137 group new-newsgroups got-new method hashtb
1138 gnus-override-subscribe-method)
1139 (unless gnus-killed-hashtb
1140 (gnus-make-hashtable-from-killed))
1141 ;; Go through both primary and secondary select methods and
1142 ;; request new newsgroups.
1143 (while (setq method (gnus-server-get-method nil (pop methods)))
1144 (setq new-newsgroups nil
1145 gnus-override-subscribe-method method)
1146 (when (and (gnus-check-server method)
1147 (gnus-request-newgroups date method))
1150 hashtb (gnus-make-hashtable 100))
1151 (set-buffer nntp-server-buffer)
1152 ;; Enter all the new groups into a hashtable.
1153 (gnus-active-to-gnus-format method hashtb 'ignore))
1154 ;; Now all new groups from `method' are in `hashtb'.
1157 (if (or (null (setq group (symbol-name group-sym)))
1158 (not (boundp group-sym))
1159 (null (symbol-value group-sym))
1160 (gnus-gethash group gnus-newsrc-hashtb)
1161 (member group gnus-zombie-list)
1162 (member group gnus-killed-list))
1163 ;; The group is already known.
1165 ;; Make this group active.
1166 (when (symbol-value group-sym)
1167 (gnus-set-active group (symbol-value group-sym)))
1168 ;; Check whether we want it or not.
1169 (let ((do-sub (gnus-matches-options-n group)))
1171 ((eq do-sub 'subscribe)
1173 (gnus-sethash group group gnus-killed-hashtb)
1174 (gnus-call-subscribe-functions
1175 gnus-subscribe-options-newsgroup-method group))
1176 ((eq do-sub 'ignore)
1180 (gnus-sethash group group gnus-killed-hashtb)
1181 (if gnus-subscribe-hierarchical-interactive
1182 (push group new-newsgroups)
1183 (gnus-call-subscribe-functions
1184 gnus-subscribe-newsgroup-method group)))))))
1186 (when new-newsgroups
1187 (gnus-subscribe-hierarchical-interactive new-newsgroups)))
1189 (gnus-message 5 "%d new newsgroup%s arrived"
1190 groups (if (> groups 1) "s have" " has"))
1191 (gnus-message 5 "No new newsgroups"))
1193 (setq gnus-newsrc-last-checked-date new-date))
1196 (defun gnus-check-first-time-used ()
1198 ;; First check if any of the following files exist. If they do,
1199 ;; it's not the first time the user has used Gnus.
1200 (dolist (file (list (concat gnus-current-startup-file ".el")
1201 (concat gnus-current-startup-file ".eld")
1202 (concat gnus-startup-file ".el")
1203 (concat gnus-startup-file ".eld")))
1204 (when (file-exists-p file)
1205 (throw 'ended nil)))
1206 (gnus-message 6 "First time user; subscribing you to default groups")
1207 (unless (gnus-read-active-file-p)
1208 (let ((gnus-read-active-file t))
1209 (gnus-read-active-file)))
1210 (setq gnus-newsrc-last-checked-date (message-make-date))
1211 ;; Subscribe to the default newsgroups.
1212 (let ((groups (or gnus-default-subscribed-newsgroups
1213 gnus-backup-default-subscribed-newsgroups))
1216 ;; If t, we subscribe (or not) all groups as if they were new.
1219 (when (setq group (symbol-name sym))
1220 (let ((do-sub (gnus-matches-options-n group)))
1222 ((eq do-sub 'subscribe)
1223 (gnus-sethash group group gnus-killed-hashtb)
1224 (gnus-call-subscribe-functions
1225 gnus-subscribe-options-newsgroup-method group))
1226 ((eq do-sub 'ignore)
1229 (push group gnus-killed-list))))))
1231 (dolist (group groups)
1232 ;; Only subscribe the default groups that are activated.
1233 (when (gnus-active group)
1234 (gnus-group-change-level
1235 group gnus-level-default-subscribed gnus-level-killed)))
1237 (set-buffer gnus-group-buffer)
1238 ;; Don't error if the group already exists. This happens when a
1239 ;; first-time user types 'F'. -- didier
1240 (gnus-group-make-help-group t))
1241 (when gnus-novice-user
1242 (gnus-message 7 "`A k' to list killed groups"))))))
1244 (defun gnus-subscribe-group (group &optional previous method)
1245 "Subcribe GROUP and put it after PREVIOUS."
1246 (gnus-group-change-level
1248 (list t group gnus-level-default-subscribed nil nil method)
1250 gnus-level-default-subscribed gnus-level-killed previous t)
1253 ;; `gnus-group-change-level' is the fundamental function for changing
1254 ;; subscription levels of newsgroups. This might mean just changing
1255 ;; from level 1 to 2, which is pretty trivial, from 2 to 6 or back
1256 ;; again, which subscribes/unsubscribes a group, which is equally
1257 ;; trivial. Changing from 1-7 to 8-9 means that you kill a group, and
1258 ;; from 8-9 to 1-7 means that you remove the group from the list of
1259 ;; killed (or zombie) groups and add them to the (kinda) subscribed
1260 ;; groups. And last but not least, moving from 8 to 9 and 9 to 8,
1261 ;; which is trivial.
1262 ;; ENTRY can either be a string (newsgroup name) or a list (if
1263 ;; FROMKILLED is t, it's a list on the format (NUM INFO-LIST),
1264 ;; otherwise it's a list in the format of the `gnus-newsrc-hashtb'
1266 ;; LEVEL is the new level of the group, OLDLEVEL is the old level and
1267 ;; PREVIOUS is the group (in hashtb entry format) to insert this group
1269 (defun gnus-group-change-level (entry level &optional oldlevel
1270 previous fromkilled)
1271 (let (group info active num)
1272 ;; Glean what info we can from the arguments
1274 (if fromkilled (setq group (nth 1 entry))
1275 (setq group (car (nth 2 entry))))
1277 (when (and (stringp entry)
1279 (< oldlevel gnus-level-zombie))
1280 (setq entry (gnus-gethash entry gnus-newsrc-hashtb)))
1281 (if (and (not oldlevel)
1283 (setq oldlevel (gnus-info-level (nth 2 entry)))
1284 (setq oldlevel (or oldlevel gnus-level-killed)))
1285 (when (stringp previous)
1286 (setq previous (gnus-gethash previous gnus-newsrc-hashtb)))
1288 (if (and (>= oldlevel gnus-level-zombie)
1289 (gnus-gethash group gnus-newsrc-hashtb))
1290 ;; We are trying to subscribe a group that is already
1294 (unless (gnus-ephemeral-group-p group)
1296 (format "(gnus-group-change-level %S %S %S %S %S)"
1297 group level oldlevel (car (nth 2 previous)) fromkilled)))
1299 ;; Then we remove the newgroup from any old structures, if needed.
1300 ;; If the group was killed, we remove it from the killed or zombie
1301 ;; list. If not, and it is in fact going to be killed, we remove
1302 ;; it from the newsrc hash table and assoc.
1304 ((>= oldlevel gnus-level-zombie)
1305 ;; oldlevel could be wrong.
1306 (setq gnus-zombie-list (delete group gnus-zombie-list))
1307 (setq gnus-killed-list (delete group gnus-killed-list)))
1309 (when (and (>= level gnus-level-zombie)
1311 (gnus-sethash (car (nth 2 entry)) nil gnus-newsrc-hashtb)
1313 (setcdr (gnus-gethash (car (nth 3 entry))
1316 (setcdr (cdr entry) (cdddr entry)))))
1318 ;; Finally we enter (if needed) the list where it is supposed to
1319 ;; go, and change the subscription level. If it is to be killed,
1320 ;; we enter it into the killed or zombie list.
1322 ((>= level gnus-level-zombie)
1323 ;; Remove from the hash table.
1324 (gnus-sethash group nil gnus-newsrc-hashtb)
1325 ;; We do not enter foreign groups into the list of dead
1327 (unless (gnus-group-foreign-p group)
1328 (if (= level gnus-level-zombie)
1329 (push group gnus-zombie-list)
1330 (if (= oldlevel gnus-level-killed)
1331 ;; Remove from active hashtb.
1332 (unintern group gnus-active-hashtb)
1333 ;; Don't add it into killed-list if it was killed.
1334 (push group gnus-killed-list)))))
1336 ;; If the list is to be entered into the newsrc assoc, and
1337 ;; it was killed, we have to create an entry in the newsrc
1338 ;; hashtb format and fix the pointers in the newsrc assoc.
1339 (if (< oldlevel gnus-level-zombie)
1340 ;; It was alive, and it is going to stay alive, so we
1341 ;; just change the level and don't change any pointers or
1342 ;; hash table entries.
1343 (setcar (cdaddr entry) level)
1345 (setq info (cdr entry)
1347 (setq active (gnus-active group))
1349 (if active (- (1+ (cdr active)) (car active)) t))
1350 ;; Shorten the select method if possible, if we need to
1351 ;; store it at all (native groups).
1352 (let ((method (gnus-method-simplify
1353 (or gnus-override-subscribe-method
1354 (gnus-group-method group)))))
1356 (setq info (list group level nil nil method))
1357 (setq info (list group level nil)))))
1360 (let ((p gnus-newsrc-alist))
1364 (setq entry (cons info (cddr previous)))
1367 (setcdr (cdr previous) entry)
1368 (gnus-sethash group (cons num (cdr previous))
1369 gnus-newsrc-hashtb))
1370 (setcdr previous entry)
1371 (gnus-sethash group (cons num previous)
1372 gnus-newsrc-hashtb))
1374 (setcdr (gnus-gethash (caadr entry) gnus-newsrc-hashtb) entry))
1377 "(gnus-group-set-info '%S)" info)))))
1378 (when gnus-group-change-level-function
1379 (funcall gnus-group-change-level-function
1380 group level oldlevel previous)))))
1382 (defun gnus-kill-newsgroup (newsgroup)
1383 "Obsolete function. Kills a newsgroup."
1384 (gnus-group-change-level
1385 (gnus-gethash newsgroup gnus-newsrc-hashtb) gnus-level-killed))
1387 (defun gnus-check-bogus-newsgroups (&optional confirm)
1388 "Remove bogus newsgroups.
1389 If CONFIRM is non-nil, the user has to confirm the deletion of every
1391 (let ((newsrc (cdr gnus-newsrc-alist))
1392 bogus group entry info)
1393 (gnus-message 5 "Checking bogus newsgroups...")
1394 (unless (gnus-read-active-file-p)
1395 (gnus-read-active-file t))
1396 (when (gnus-read-active-file-p)
1397 ;; Find all bogus newsgroup that are subscribed.
1399 (setq info (pop newsrc)
1400 group (gnus-info-group info))
1401 (unless (or (gnus-active group) ; Active
1402 (and (gnus-info-method info)
1403 (not (gnus-secondary-method-p
1404 (gnus-info-method info))))) ; Foreign
1405 ;; Found a bogus newsgroup.
1406 (push group bogus)))
1409 "Remove bogus group %s? "
1411 ;; Remove all bogus subscribed groups by first killing them, and
1412 ;; then removing them from the list of killed groups.
1413 (when (setq entry (gnus-gethash group gnus-newsrc-hashtb))
1414 (gnus-group-change-level entry gnus-level-killed)
1415 (setq gnus-killed-list (delete group gnus-killed-list))))
1416 bogus '("group" "groups" "remove"))
1417 (while (setq group (pop bogus))
1418 ;; Remove all bogus subscribed groups by first killing them, and
1419 ;; then removing them from the list of killed groups.
1420 (when (setq entry (gnus-gethash group gnus-newsrc-hashtb))
1421 (gnus-group-change-level entry gnus-level-killed)
1422 (setq gnus-killed-list (delete group gnus-killed-list)))))
1423 ;; Then we remove all bogus groups from the list of killed and
1424 ;; zombie groups. They are removed without confirmation.
1425 (let ((dead-lists '(gnus-killed-list gnus-zombie-list))
1428 (setq killed (symbol-value (car dead-lists)))
1430 (unless (gnus-active (setq group (pop killed)))
1431 ;; The group is bogus.
1433 (set (car dead-lists)
1434 (delete group (symbol-value (car dead-lists))))))
1435 (setq dead-lists (cdr dead-lists))))
1436 (gnus-run-hooks 'gnus-check-bogus-groups-hook)
1437 (gnus-message 5 "Checking bogus newsgroups...done"))))
1439 (defun gnus-check-duplicate-killed-groups ()
1440 "Remove duplicates from the list of killed groups."
1442 (let ((killed gnus-killed-list))
1444 (gnus-message 9 "%d" (length killed))
1445 (setcdr killed (delete (car killed) (cdr killed)))
1446 (setq killed (cdr killed)))))
1448 ;; We want to inline a function from gnus-cache, so we cheat here:
1450 (defvar gnus-cache-active-hashtb)
1451 (defun gnus-cache-possibly-alter-active (group active)
1452 "Alter the ACTIVE info for GROUP to reflect the articles in the cache."
1453 (when gnus-cache-active-hashtb
1454 (let ((cache-active (gnus-gethash group gnus-cache-active-hashtb)))
1456 (when (< (car cache-active) (car active))
1457 (setcar active (car cache-active)))
1458 (when (> (cdr cache-active) (cdr active))
1459 (setcdr active (cdr cache-active))))))))
1461 (defun gnus-activate-group (group &optional scan dont-check method)
1462 ;; Check whether a group has been activated or not.
1463 ;; If SCAN, request a scan of that group as well.
1464 (let ((method (or method (inline (gnus-find-method-for-group group))))
1466 (and (inline (gnus-check-server method))
1467 ;; We escape all bugs and quit here to make it possible to
1468 ;; continue if a group is so out-there that it reports bugs
1472 (gnus-check-backend-function 'request-scan (car method))
1473 (gnus-request-scan group method))
1475 (if (or debug-on-error debug-on-quit)
1476 (inline (gnus-request-group group dont-check method))
1478 (inline (gnus-request-group group dont-check method))
1481 (message "Quit activating %s" group)
1484 (setq active (gnus-parse-active))
1485 ;; If there are no articles in the group, the GROUP
1486 ;; command may have responded with the `(0 . 0)'. We
1487 ;; ignore this if we already have an active entry
1489 (if (and (zerop (car active))
1490 (zerop (cdr active))
1491 (gnus-active group))
1493 (gnus-set-active group active)
1494 ;; Return the new active info.
1497 (defun gnus-get-unread-articles-in-group (info active &optional update)
1499 ;; Allow the backend to update the info in the group.
1501 (gnus-request-update-info
1502 info (inline (gnus-find-method-for-group
1503 (gnus-info-group info)))))
1504 (gnus-activate-group (gnus-info-group info) nil t))
1506 (let* ((range (gnus-info-read info))
1508 ;; If a cache is present, we may have to alter the active info.
1509 (when (and gnus-use-cache info)
1510 (inline (gnus-cache-possibly-alter-active
1511 (gnus-info-group info) active)))
1512 ;; Modify the list of read articles according to what articles
1513 ;; are available; then tally the unread articles and add the
1514 ;; number to the group hash table entry.
1516 ((zerop (cdr active))
1519 (setq num (- (1+ (cdr active)) (car active))))
1520 ((not (listp (cdr range)))
1521 ;; Fix a single (num . num) range according to the
1522 ;; active hash table.
1523 ;; Fix by Carsten Bormann <cabo@Informatik.Uni-Bremen.DE>.
1524 (and (< (cdr range) (car active)) (setcdr range (1- (car active))))
1525 (and (> (cdr range) (cdr active)) (setcdr range (cdr active)))
1526 ;; Compute number of unread articles.
1527 (setq num (max 0 (- (cdr active) (- (1+ (cdr range)) (car range))))))
1529 ;; The read list is a list of ranges. Fix them according to
1530 ;; the active hash table.
1531 ;; First peel off any elements that are below the lower
1533 (while (and (cdr range)
1535 (or (and (atom (cadr range)) (cadr range))
1537 (if (numberp (car range))
1540 (or (and (numberp (cadr range))
1544 (or (and (numberp (nth 1 range)) (nth 1 range))
1546 (setcdr range (cddr range)))
1547 ;; Adjust the first element to be the same as the lower limit.
1548 (when (and (not (atom (car range)))
1549 (< (cdar range) (car active)))
1550 (setcdr (car range) (1- (car active))))
1551 ;; Then we want to peel off any elements that are higher
1552 ;; than the upper active limit.
1553 (let ((srange range))
1554 ;; Go past all valid elements.
1555 (while (and (cdr srange)
1556 (<= (or (and (atom (cadr srange))
1560 (setq srange (cdr srange)))
1562 ;; Nuke all remaining invalid elements.
1563 (setcdr srange nil))
1565 ;; Adjust the final element.
1566 (when (and (not (atom (car srange)))
1567 (> (cdar srange) (cdr active)))
1568 (setcdr (car srange) (cdr active))))
1569 ;; Compute the number of unread articles.
1571 (setq num (+ num (- (1+ (or (and (atom (car range)) (car range))
1573 (or (and (atom (car range)) (car range))
1575 (setq range (cdr range)))
1576 (setq num (max 0 (- (cdr active) num)))))
1577 ;; Set the number of unread articles.
1579 (gnus-gethash (gnus-info-group info) gnus-newsrc-hashtb))
1580 (setcar (gnus-gethash (gnus-info-group info) gnus-newsrc-hashtb) num))
1583 ;; Go though `gnus-newsrc-alist' and compare with `gnus-active-hashtb'
1584 ;; and compute how many unread articles there are in each group.
1585 (defun gnus-get-unread-articles (&optional level)
1586 (setq gnus-server-method-cache nil)
1587 (let* ((newsrc (cdr gnus-newsrc-alist))
1588 (level (or level gnus-activate-level (1+ gnus-level-subscribed)))
1591 (cond ((and gnus-activate-foreign-newsgroups
1592 (not (numberp gnus-activate-foreign-newsgroups)))
1593 (1+ gnus-level-subscribed))
1594 ((numberp gnus-activate-foreign-newsgroups)
1595 gnus-activate-foreign-newsgroups)
1598 scanned-methods info group active method retrieve-groups)
1599 (gnus-message 6 "Checking new news...")
1602 (setq active (gnus-active (setq group (gnus-info-group
1603 (setq info (pop newsrc))))))
1605 ;; Check newsgroups. If the user doesn't want to check them, or
1606 ;; they can't be checked (for instance, if the news server can't
1607 ;; be reached) we just set the number of unread articles in this
1608 ;; newsgroup to t. This means that Gnus thinks that there are
1609 ;; unread articles, but it has no idea how many.
1611 ;; To be more explicit:
1612 ;; >0 for an active group with messages
1613 ;; 0 for an active group with no unread messages
1614 ;; nil for non-foreign groups that the user has requested not be checked
1615 ;; t for unchecked foreign groups or bogus groups, or groups that can't
1616 ;; be checked, for one reason or other.
1617 (if (and (setq method (gnus-info-method info))
1621 (setq method (gnus-server-get-method nil method)))))
1622 (not (gnus-secondary-method-p method)))
1623 ;; These groups are foreign. Check the level.
1624 (when (and (<= (gnus-info-level info) foreign-level)
1625 (setq active (gnus-activate-group group 'scan)))
1626 ;; Let the Gnus agent save the active file.
1627 (when (and gnus-agent active (gnus-online method))
1628 (gnus-agent-save-group-info
1629 method (gnus-group-real-name group) active))
1630 (unless (inline (gnus-virtual-group-p group))
1631 (inline (gnus-close-group group)))
1632 (when (fboundp (intern (concat (symbol-name (car method))
1633 "-request-update-info")))
1634 (inline (gnus-request-update-info info method))))
1635 ;; These groups are native or secondary.
1637 ;; We don't want these groups.
1638 ((> (gnus-info-level info) level)
1639 (setq active 'ignore))
1641 ((not gnus-read-active-file)
1642 (if (gnus-check-backend-function 'retrieve-groups group)
1643 ;; if server support gnus-retrieve-groups we push
1644 ;; the group onto retrievegroups for later checking
1645 (if (assoc method retrieve-groups)
1646 (setcdr (assoc method retrieve-groups)
1647 (cons group (cdr (assoc method retrieve-groups))))
1648 (push (list method group) retrieve-groups))
1649 ;; hack: `nnmail-get-new-mail' changes the mail-source depending
1650 ;; on the group, so we must perform a scan for every group
1651 ;; if the users has any directory mail sources.
1652 ;; hack: if `nnmail-scan-directory-mail-source-once' is non-nil,
1653 ;; for it scan all spool files even when the groups are
1656 (or nnmail-scan-directory-mail-source-once
1657 (null (assq 'directory
1659 (if (listp nnmail-spool-file)
1661 (list nnmail-spool-file))))))
1662 (member method scanned-methods))
1663 (setq active (gnus-activate-group group))
1664 (setq active (gnus-activate-group group 'scan))
1665 (push method scanned-methods))
1667 (gnus-close-group group))))))
1669 ;; Get the number of unread articles in the group.
1671 ((eq active 'ignore)
1672 ;; Don't do anything.
1675 (inline (gnus-get-unread-articles-in-group info active t)))
1677 ;; The group couldn't be reached, so we nix out the number of
1678 ;; unread articles and stuff.
1679 (gnus-set-active group nil)
1680 (let ((tmp (gnus-gethash group gnus-newsrc-hashtb)))
1684 ;; iterate through groups on methods which support gnus-retrieve-groups
1685 ;; and fetch a partial active file and use it to find new news.
1686 (dolist (rg retrieve-groups)
1687 (let ((method (or (car rg) gnus-select-method))
1689 (when (gnus-check-server method)
1690 ;; Request that the backend scan its incoming messages.
1691 (when (gnus-check-backend-function 'request-scan (car method))
1692 (gnus-request-scan nil method))
1693 (gnus-read-active-file-2
1694 (mapcar (lambda (group) (gnus-group-real-name group)) groups)
1696 (dolist (group groups)
1698 ((setq active (gnus-active (gnus-info-group
1699 (setq info (gnus-get-info group)))))
1700 (inline (gnus-get-unread-articles-in-group info active t)))
1702 ;; The group couldn't be reached, so we nix out the number of
1703 ;; unread articles and stuff.
1704 (gnus-set-active group nil)
1705 (setcar (gnus-gethash group gnus-newsrc-hashtb) t)))))))
1707 (gnus-message 6 "Checking new news...done")))
1709 ;; Create a hash table out of the newsrc alist. The `car's of the
1710 ;; alist elements are used as keys.
1711 (defun gnus-make-hashtable-from-newsrc-alist ()
1712 (let ((alist gnus-newsrc-alist)
1713 (ohashtb gnus-newsrc-hashtb)
1715 (setq gnus-newsrc-hashtb (gnus-make-hashtable (length alist)))
1717 (setq prev (setq gnus-newsrc-alist
1718 (if (equal (caar gnus-newsrc-alist)
1721 (cons (list "dummy.group" 0 nil) alist)))))
1725 ;; Preserve number of unread articles in groups.
1726 (cons (and ohashtb (car (gnus-gethash (caar alist) ohashtb)))
1730 alist (cdr alist)))))
1732 (defun gnus-make-hashtable-from-killed ()
1733 "Create a hash table from the killed and zombie lists."
1734 (let ((lists '(gnus-killed-list gnus-zombie-list))
1736 (setq gnus-killed-hashtb
1737 (gnus-make-hashtable
1738 (+ (length gnus-killed-list) (length gnus-zombie-list))))
1740 (setq list (symbol-value (pop lists)))
1742 (gnus-sethash (car list) (pop list) gnus-killed-hashtb)))))
1744 (defun gnus-parse-active ()
1745 "Parse active info in the nntp server buffer."
1747 (set-buffer nntp-server-buffer)
1748 (goto-char (point-min))
1749 ;; Parse the result we got from `gnus-request-group'.
1750 (when (looking-at "[0-9]+ [0-9]+ \\([0-9]+\\) [0-9]+")
1751 (goto-char (match-beginning 1))
1752 (cons (read (current-buffer))
1753 (read (current-buffer))))))
1755 (defun gnus-make-articles-unread (group articles)
1756 "Mark ARTICLES in GROUP as unread."
1757 (let* ((info (nth 2 (or (gnus-gethash group gnus-newsrc-hashtb)
1758 (gnus-gethash (gnus-group-real-name group)
1759 gnus-newsrc-hashtb))))
1760 (ranges (gnus-info-read info))
1763 (when (gnus-member-of-range
1764 (setq article (pop articles)) ranges)
1765 (push article news)))
1767 ;; Enter this list into the group info.
1769 info (gnus-remove-from-range (gnus-info-read info) (nreverse news)))
1771 ;; Set the number of unread articles in gnus-newsrc-hashtb.
1772 (gnus-get-unread-articles-in-group info (gnus-active group))
1774 ;; Insert the change into the group buffer and the dribble file.
1775 (gnus-group-update-group group t))))
1777 (defun gnus-make-ascending-articles-unread (group articles)
1778 "Mark ascending ARTICLES in GROUP as unread."
1779 (let* ((entry (or (gnus-gethash group gnus-newsrc-hashtb)
1780 (gnus-gethash (gnus-group-real-name group)
1781 gnus-newsrc-hashtb)))
1782 (info (nth 2 entry))
1783 (ranges (gnus-info-read info))
1788 (let ((article (pop articles))) ; get the next article to remove from ranges
1789 (while (let ((range (car ranges))) ; note the current range
1790 (if (atom range) ; single value range
1792 ;; the articles extend past the end of the ranges
1794 (setq articles nil))
1796 ;; this range preceeds the article. Leave the range unmodified.
1800 ;; this range exactly matches the article; REMOVE THE RANGE.
1801 ;; NOTE: When the range being removed is the last range, the list is corrupted by inserting null at its end.
1802 (setcar ranges (cadr ranges))
1803 (setcdr ranges (cddr ranges))
1804 (setq modified (if (car ranges) t 'remove-null))
1806 (let ((min (car range))
1808 ;; I have a min/max range to consider
1809 (cond ((> min max) ; invalid range introduced by splitter
1810 (setcar ranges (cadr ranges))
1811 (setcdr ranges (cddr ranges))
1812 (setq modified (if (car ranges) t 'remove-null))
1815 ;; replace min/max range with a single-value range
1819 ;; this range preceeds the article. Leave the range unmodified.
1823 ;; this article preceeds the range. Return null to move to the
1827 ;; this article splits the range into two parts
1828 (setcdr ranges (cons (cons (1+ article) max) (cdr ranges)))
1829 (setcdr range (1- article))
1834 (when (eq modified 'remove-null)
1835 (setq r (delq nil r)))
1836 ;; Enter this list into the group info.
1837 (gnus-info-set-read info r)
1839 ;; Set the number of unread articles in gnus-newsrc-hashtb.
1840 (gnus-get-unread-articles-in-group info (gnus-active group))
1842 ;; Insert the change into the group buffer and the dribble file.
1843 (gnus-group-update-group group t))))
1845 ;; Enter all dead groups into the hashtb.
1846 (defun gnus-update-active-hashtb-from-killed ()
1847 (let ((hashtb (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
1848 (lists (list gnus-killed-list gnus-zombie-list))
1851 (setq killed (car lists))
1853 (gnus-sethash (car killed) nil hashtb)
1854 (setq killed (cdr killed)))
1855 (setq lists (cdr lists)))))
1857 (defun gnus-get-killed-groups ()
1858 "Go through the active hashtb and mark all unknown groups as killed."
1859 ;; First make sure active file has been read.
1860 (unless (gnus-read-active-file-p)
1861 (let ((gnus-read-active-file t))
1862 (gnus-read-active-file)))
1863 (unless gnus-killed-hashtb
1864 (gnus-make-hashtable-from-killed))
1865 ;; Go through all newsgroups that are known to Gnus - enlarge kill list.
1869 (group (symbol-name sym)))
1870 (if (or (null group)
1871 (gnus-gethash group gnus-killed-hashtb)
1872 (gnus-gethash group gnus-newsrc-hashtb))
1874 (let ((do-sub (gnus-matches-options-n group)))
1875 (if (or (eq do-sub 'subscribe) (eq do-sub 'ignore))
1877 (setq groups (1+ groups))
1878 (push group gnus-killed-list)
1879 (gnus-sethash group group gnus-killed-hashtb))))))
1881 (gnus-dribble-touch))
1883 ;; Get the active file(s) from the backend(s).
1884 (defun gnus-read-active-file (&optional force not-native)
1885 (gnus-group-set-mode-line)
1888 (lambda (m) (if (stringp m) (gnus-server-get-method nil m) m))
1890 (if (and (not not-native)
1891 (gnus-check-server gnus-select-method))
1892 ;; The native server is available.
1893 (cons gnus-select-method gnus-secondary-select-methods)
1894 ;; The native server is down, so we just do the
1896 gnus-secondary-select-methods)
1897 ;; Also read from the archive server.
1898 (when (gnus-archive-server-wanted-p)
1899 (list "archive")))))
1901 (setq gnus-have-read-active-file nil)
1903 (set-buffer nntp-server-buffer)
1904 (while (setq method (pop methods))
1905 ;; Only do each method once, in case the methods appear more
1906 ;; than once in this list.
1907 (unless (member method methods)
1908 (if (or debug-on-error debug-on-quit)
1909 (gnus-read-active-file-1 method force)
1911 (gnus-read-active-file-1 method force)
1912 ;; We catch C-g so that we can continue past servers
1913 ;; that do not respond.
1915 (message "Quit reading the active file")
1918 (defun gnus-read-active-file-1 (method force)
1920 (setq where (nth 1 method)
1921 mesg (format "Reading active file%s via %s..."
1922 (if (and where (not (zerop (length where))))
1923 (concat " from " where) "")
1925 (gnus-message 5 mesg)
1926 (when (gnus-check-server method)
1927 ;; Request that the backend scan its incoming messages.
1928 (when (gnus-check-backend-function 'request-scan (car method))
1929 (gnus-request-scan nil method))
1931 ((and (eq gnus-read-active-file 'some)
1932 (gnus-check-backend-function 'retrieve-groups (car method))
1934 (let ((newsrc (cdr gnus-newsrc-alist))
1935 (gmethod (gnus-server-get-method nil method))
1937 (while (setq info (pop newsrc))
1941 (gnus-find-method-for-group
1942 (gnus-info-group info) info))
1944 (push (gnus-group-real-name (gnus-info-group info))
1946 (gnus-read-active-file-2 groups method)))
1950 (if (not (gnus-request-list method))
1951 (unless (equal method gnus-message-archive-method)
1952 (gnus-error 1 "Cannot read active file from %s server"
1954 (gnus-message 5 mesg)
1955 (gnus-active-to-gnus-format method gnus-active-hashtb nil t)
1956 ;; We mark this active file as read.
1957 (push method gnus-have-read-active-file)
1958 (gnus-message 5 "%sdone" mesg)))))))
1960 (defun gnus-read-active-file-2 (groups method)
1961 "Read an active file for GROUPS in METHOD using gnus-retrieve-groups."
1964 (set-buffer nntp-server-buffer)
1965 (gnus-check-server method)
1966 (let ((list-type (gnus-retrieve-groups groups method)))
1967 (cond ((not list-type)
1969 1.2 "Cannot read partial active file from %s server."
1971 ((eq list-type 'active)
1972 (gnus-active-to-gnus-format method gnus-active-hashtb nil t))
1974 (gnus-groups-to-gnus-format method gnus-active-hashtb t)))))))
1976 ;; Read an active file and place the results in `gnus-active-hashtb'.
1977 (defun gnus-active-to-gnus-format (&optional method hashtb ignore-errors
1980 (setq method gnus-select-method))
1981 (let ((cur (current-buffer))
1983 (if (and gnus-active-hashtb
1984 (not (equal method gnus-select-method)))
1986 (setq gnus-active-hashtb
1987 (if (equal method gnus-select-method)
1988 (gnus-make-hashtable
1989 (count-lines (point-min) (point-max)))
1990 (gnus-make-hashtable 4096)))))))
1991 ;; Delete unnecessary lines.
1992 (goto-char (point-min))
1994 ((string= gnus-ignored-newsgroups "")
1995 (delete-matching-lines "^to\\."))
1997 (delete-matching-lines (concat "^to\\.\\|" gnus-ignored-newsgroups))))
1999 (goto-char (point-min))
2000 (unless (re-search-forward "[\\\"]" nil t)
2001 ;; Make the group names readable as a lisp expression even if they
2002 ;; contain special characters.
2003 (goto-char (point-max))
2004 (while (re-search-backward "[][';?()#]" nil t)
2007 ;; Let the Gnus agent save the active file.
2008 (when (and gnus-agent real-active (gnus-online method))
2009 (gnus-agent-save-active method))
2011 ;; If these are groups from a foreign select method, we insert the
2012 ;; group prefix in front of the group names.
2013 (when (not (gnus-server-equal
2014 (gnus-server-get-method nil method)
2015 (gnus-server-get-method nil gnus-select-method)))
2016 (let ((prefix (gnus-group-prefixed-name "" method)))
2017 (goto-char (point-min))
2018 (while (and (not (eobp))
2020 (when (= (following-char) ?\")
2023 (zerop (forward-line 1)))))))
2024 ;; Store the active file in a hash table.
2025 (goto-char (point-min))
2026 (let (group max min)
2030 (narrow-to-region (point) (gnus-point-at-eol))
2031 ;; group gets set to a symbol interned in the hash table
2032 ;; (what a hack!!) - jwz
2033 (setq group (let ((obarray hashtb)) (read cur)))
2034 ;; ### The extended group name scheme makes
2035 ;; the previous optimization strategy sort of pointless...
2036 (when (stringp group)
2037 (setq group (intern group hashtb)))
2038 (if (and (numberp (setq max (read cur)))
2039 (numberp (setq min (read cur)))
2041 (skip-chars-forward " \t")
2043 (or (eq (char-after) ?=)
2044 (eq (char-after) ?x)
2045 (eq (char-after) ?j)))))
2047 (set group (cons min max))
2048 ;; if group is moderated, stick in moderation table
2049 (when (eq (char-after) ?m)
2050 (unless gnus-moderated-hashtb
2051 (setq gnus-moderated-hashtb (gnus-make-hashtable)))
2052 (gnus-sethash (symbol-name group) t
2053 gnus-moderated-hashtb)))
2059 (unless ignore-errors
2060 (gnus-message 3 "Warning - invalid active: %s"
2062 (gnus-point-at-bol) (gnus-point-at-eol))))))
2064 (forward-line 1)))))
2066 (defun gnus-groups-to-gnus-format (method &optional hashtb real-active)
2067 ;; Parse a "groups" active file.
2068 (let ((cur (current-buffer))
2070 (if (and method gnus-active-hashtb)
2072 (setq gnus-active-hashtb
2073 (gnus-make-hashtable
2074 (count-lines (point-min) (point-max)))))))
2076 (not (gnus-server-equal
2077 (gnus-server-get-method nil method)
2078 (gnus-server-get-method nil gnus-select-method)))
2079 (gnus-group-prefixed-name "" method))))
2081 ;; Let the Gnus agent save the active file.
2084 (gnus-online method)
2085 (gnus-agent-method-p method))
2087 (gnus-agent-save-groups method)
2088 (gnus-active-to-gnus-format method hashtb nil real-active))
2090 (goto-char (point-min))
2091 ;; We split this into to separate loops, one with the prefix
2092 ;; and one without to speed the reading up somewhat.
2094 (let (min max opoint group)
2098 (read cur) (read cur)
2099 (setq min (read cur)
2102 (skip-chars-forward " \t")
2105 (set (let ((obarray hashtb)) (read cur))
2107 (error (and group (symbolp group) (set group nil))))
2109 (let (min max group)
2112 (when (eq (char-after) ?2)
2113 (read cur) (read cur)
2114 (setq min (read cur)
2116 (set (setq group (let ((obarray hashtb)) (read cur)))
2118 (error (and group (symbolp group) (set group nil))))
2119 (forward-line 1)))))))
2121 (defun gnus-read-newsrc-file (&optional force)
2123 If FORCE is non-nil, the .newsrc file is read."
2124 ;; Reset variables that might be defined in the .newsrc.eld file.
2125 (let ((variables (remove 'gnus-format-specs gnus-variable-list)))
2127 (set (car variables) nil)
2128 (setq variables (cdr variables))))
2129 (let* ((newsrc-file gnus-current-startup-file)
2130 (quick-file (concat newsrc-file ".el")))
2132 ;; We always load the .newsrc.eld file. If always contains
2133 ;; much information that can not be gotten from the .newsrc
2134 ;; file (ticked articles, killed groups, foreign methods, etc.)
2135 (gnus-read-newsrc-el-file quick-file)
2137 (when (and gnus-read-newsrc-file
2138 (file-exists-p gnus-current-startup-file)
2140 (and (file-newer-than-file-p newsrc-file quick-file)
2141 (file-newer-than-file-p newsrc-file
2142 (concat quick-file "d")))
2143 (not gnus-newsrc-alist)))
2144 ;; We read the .newsrc file. Note that if there if a
2145 ;; .newsrc.eld file exists, it has already been read, and
2146 ;; the `gnus-newsrc-hashtb' has been created. While reading
2147 ;; the .newsrc file, Gnus will only use the information it
2148 ;; can find there for changing the data already read -
2149 ;; i. e., reading the .newsrc file will not trash the data
2150 ;; already read (except for read articles).
2152 (gnus-message 5 "Reading %s..." newsrc-file)
2153 (set-buffer (nnheader-find-file-noselect newsrc-file))
2154 (buffer-disable-undo)
2155 (gnus-newsrc-to-gnus-format)
2156 (kill-buffer (current-buffer))
2157 (gnus-message 5 "Reading %s...done" newsrc-file)))
2159 ;; Convert old to new.
2160 (gnus-convert-old-newsrc))))
2162 (defun gnus-convert-old-newsrc ()
2163 "Convert old newsrc into the new format, if needed."
2164 (let ((fcv (and gnus-newsrc-file-version
2165 (gnus-continuum-version gnus-newsrc-file-version))))
2167 ;; No .newsrc.eld file was loaded.
2169 ;; Gnus 5 .newsrc.eld was loaded.
2170 ((< fcv (gnus-continuum-version "September Gnus v0.1"))
2171 (gnus-convert-old-ticks)))))
2173 (defun gnus-convert-old-ticks ()
2174 (let ((newsrc (cdr gnus-newsrc-alist))
2175 marks info dormant ticked)
2176 (while (setq info (pop newsrc))
2177 (when (setq marks (gnus-info-marks info))
2178 (setq dormant (cdr (assq 'dormant marks))
2179 ticked (cdr (assq 'tick marks)))
2180 (when (or dormant ticked)
2184 (gnus-info-read info)
2185 (nconc (gnus-uncompress-range dormant)
2186 (gnus-uncompress-range ticked)))))))))
2188 (defun gnus-load (file)
2189 "Load FILE, but in such a way that read errors can be reported."
2191 (insert-file-contents file)
2193 (condition-case type
2194 (let ((form (read (current-buffer))))
2197 (unless (eq (car type) 'end-of-file)
2198 (let ((error (format "Error in %s line %d" file
2199 (count-lines (point-min) (point)))))
2201 (unless (gnus-yes-or-no-p (concat error "; continue? "))
2202 (error "%s" error)))))))))
2204 (defun gnus-read-newsrc-el-file (file)
2205 (let ((ding-file (concat file "d")))
2206 (when (file-exists-p ding-file)
2207 ;; We always, always read the .eld file.
2208 (gnus-message 5 "Reading %s..." ding-file)
2209 (let (gnus-newsrc-assoc)
2210 (let ((coding-system-for-read gnus-ding-file-coding-system))
2211 (gnus-load ding-file))
2212 ;; Older versions of `gnus-format-specs' are no longer valid
2213 ;; in Oort Gnus 0.01.
2215 (and gnus-newsrc-file-version
2216 (gnus-continuum-version gnus-newsrc-file-version))))
2217 (when (or (not version)
2218 (< version 5.090009))
2219 (setq gnus-format-specs gnus-default-format-specs)))
2220 (when gnus-newsrc-assoc
2221 (setq gnus-newsrc-alist gnus-newsrc-assoc))))
2222 (gnus-make-hashtable-from-newsrc-alist)
2223 (when (file-newer-than-file-p file ding-file)
2224 ;; Old format quick file
2225 (gnus-message 5 "Reading %s..." file)
2226 ;; The .el file is newer than the .eld file, so we read that one
2228 (gnus-read-old-newsrc-el-file file)))
2229 (gnus-run-hooks 'gnus-read-newsrc-el-hook))
2231 ;; Parse the old-style quick startup file
2232 (defun gnus-read-old-newsrc-el-file (file)
2233 (let (newsrc killed marked group m info)
2235 (let ((gnus-killed-assoc nil)
2236 gnus-marked-assoc gnus-newsrc-alist gnus-newsrc-assoc)
2240 (setq newsrc gnus-newsrc-assoc
2241 killed gnus-killed-assoc
2242 marked gnus-marked-assoc)))
2243 (setq gnus-newsrc-alist nil)
2244 (while (setq group (pop newsrc))
2245 (if (setq info (gnus-get-info (car group)))
2247 (gnus-info-set-read info (cddr group))
2248 (gnus-info-set-level
2249 info (if (nth 1 group) gnus-level-default-subscribed
2250 gnus-level-default-unsubscribed))
2251 (push info gnus-newsrc-alist))
2254 (if (nth 1 group) gnus-level-default-subscribed
2255 gnus-level-default-unsubscribed)
2258 ;; Copy marks into info.
2259 (when (setq m (assoc (car group) marked))
2260 (unless (nthcdr 3 info)
2261 (nconc info (list nil)))
2262 (gnus-info-set-marks
2263 info (list (cons 'tick (gnus-compress-sequence
2264 (sort (cdr m) '<) t))))))
2265 (setq newsrc killed)
2267 (setcar newsrc (caar newsrc))
2268 (setq newsrc (cdr newsrc)))
2269 (setq gnus-killed-list killed))
2270 ;; The .el file version of this variable does not begin with
2271 ;; "options", while the .eld version does, so we just add it if it
2275 (when (not (string-match "^ *options" gnus-newsrc-options))
2276 (setq gnus-newsrc-options (concat "options " gnus-newsrc-options)))
2277 (when (not (string-match "\n$" gnus-newsrc-options))
2278 (setq gnus-newsrc-options (concat gnus-newsrc-options "\n")))
2279 ;; Finally, if we read some options lines, we parse them.
2280 (unless (string= gnus-newsrc-options "")
2281 (gnus-newsrc-parse-options gnus-newsrc-options)))
2283 (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist))
2284 (gnus-make-hashtable-from-newsrc-alist)))
2286 (defun gnus-make-newsrc-file (file)
2287 "Make server dependent file name by catenating FILE and server host name."
2288 (let* ((file (expand-file-name file nil))
2289 (real-file (concat file "-" (nth 1 gnus-select-method))))
2290 (if (or (file-exists-p real-file)
2291 (file-exists-p (concat real-file ".el"))
2292 (file-exists-p (concat real-file ".eld")))
2296 (defun gnus-newsrc-to-gnus-format ()
2297 (setq gnus-newsrc-options "")
2298 (setq gnus-newsrc-options-n nil)
2300 (unless gnus-active-hashtb
2301 (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
2302 (let ((buf (current-buffer))
2303 (already-read (> (length gnus-newsrc-alist) 1))
2304 group subscribed options-symbol newsrc Options-symbol
2306 (goto-char (point-min))
2307 ;; We intern the symbol `options' in the active hashtb so that we
2308 ;; can `eq' against it later.
2309 (set (setq options-symbol (intern "options" gnus-active-hashtb)) nil)
2310 (set (setq Options-symbol (intern "Options" gnus-active-hashtb)) nil)
2313 ;; We first read the first word on the line by narrowing and
2314 ;; then reading into `gnus-active-hashtb'. Most groups will
2315 ;; already exist in that hashtb, so this will save some string
2319 (progn (skip-chars-forward "^ \t!:\n") (point)))
2320 (goto-char (point-min))
2322 (and (/= (point-min) (point-max))
2323 (let ((obarray gnus-active-hashtb)) (read buf))))
2325 ;; Now, the symbol we have read is either `options' or a group
2326 ;; name. If it is an options line, we just add it to a string.
2328 ((or (eq symbol options-symbol)
2329 (eq symbol Options-symbol))
2330 (setq gnus-newsrc-options
2331 ;; This concating is quite inefficient, but since our
2332 ;; thorough studies show that approx 99.37% of all
2333 ;; .newsrc files only contain a single options line, we
2334 ;; don't give a damn, frankly, my dear.
2335 (concat gnus-newsrc-options
2338 ;; Options may continue on the next line.
2339 (or (and (re-search-forward "^[^ \t]" nil 'move)
2340 (progn (beginning-of-line) (point)))
2344 ;; Group names can be just numbers.
2345 (when (numberp symbol)
2346 (setq symbol (intern (int-to-string symbol) gnus-active-hashtb)))
2347 (unless (boundp symbol)
2349 ;; It was a group name.
2350 (setq subscribed (eq (char-after) ?:)
2351 group (symbol-name symbol)
2354 ;; If the line ends here, this is clearly a buggy line, so
2355 ;; we put point a the beginning of line and let the cond
2356 ;; below do the error handling.
2358 ;; We skip to the beginning of the ranges.
2359 (skip-chars-forward "!: \t"))
2360 ;; We are now at the beginning of the list of read articles.
2361 ;; We read them range by range.
2364 ((looking-at "[0-9]+")
2365 ;; We narrow and read a number instead of buffer-substring/
2366 ;; string-to-int because it's faster. narrow/widen is
2367 ;; faster than save-restriction/narrow, and save-restriction
2368 ;; produces a garbage object.
2370 (narrow-to-region (match-beginning 0) (match-end 0))
2373 ;; If the next character is a dash, then this is a range.
2374 (if (eq (char-after) ?-)
2376 ;; We read the upper bound of the range.
2378 (if (not (looking-at "[0-9]+"))
2379 ;; This is a buggy line, by we pretend that
2380 ;; it's kinda OK. Perhaps the user should be
2386 (narrow-to-region (match-beginning 0)
2391 ;; It was just a simple number, so we add it to the
2394 ;; If the next char in ?\n, then we have reached the end
2395 ;; of the line and return nil.
2396 (not (eq (char-after) ?\n)))
2397 ((eq (char-after) ?\n)
2398 ;; End of line, so we end.
2401 ;; Not numbers and not eol, so this might be a buggy
2404 ;; If it was eob instead of ?\n, we allow it.
2405 ;; The line was buggy.
2407 (gnus-error 3.1 "Mangled line: %s"
2408 (buffer-substring (gnus-point-at-bol)
2409 (gnus-point-at-eol))))
2411 ;; Skip past ", ". Spaces are invalid in these ranges, but
2412 ;; we allow them, because it's a common mistake to put a
2413 ;; space after the comma.
2414 (skip-chars-forward ", "))
2416 ;; We have already read .newsrc.eld, so we gently update the
2417 ;; data in the hash table with the information we have just
2420 (let ((info (gnus-get-info group))
2423 ;; There is an entry for this file in the alist.
2425 (gnus-info-set-read info (nreverse reads))
2426 ;; We update the level very gently. In fact, we
2427 ;; only change it if there's been a status change
2428 ;; from subscribed to unsubscribed, or vice versa.
2429 (setq level (gnus-info-level info))
2430 (cond ((and (<= level gnus-level-subscribed)
2432 (setq level (if reads
2433 gnus-level-default-unsubscribed
2434 (1+ gnus-level-default-unsubscribed))))
2435 ((and (> level gnus-level-subscribed) subscribed)
2436 (setq level gnus-level-default-subscribed)))
2437 (gnus-info-set-level info level))
2438 ;; This is a new group.
2439 (setq info (list group
2441 gnus-level-default-subscribed
2443 (1+ gnus-level-subscribed)
2444 gnus-level-default-unsubscribed))
2446 (push info newsrc)))))
2449 (setq newsrc (nreverse newsrc))
2451 (if (not already-read)
2453 ;; We now have two newsrc lists - `newsrc', which is what we
2454 ;; have read from .newsrc, and `gnus-newsrc-alist', which is
2455 ;; what we've read from .newsrc.eld. We have to merge these
2456 ;; lists. We do this by "attaching" any (foreign) groups in the
2457 ;; gnus-newsrc-alist to the (native) group that precedes them.
2458 (let ((rc (cdr gnus-newsrc-alist))
2459 (prev gnus-newsrc-alist)
2462 (or (null (nth 4 (car rc))) ; It's a native group.
2463 (assoc (caar rc) newsrc) ; It's already in the alist.
2464 (if (setq entry (assoc (caar prev) newsrc))
2465 (setcdr (setq mentry (memq entry newsrc))
2466 (cons (car rc) (cdr mentry)))
2467 (push (car rc) newsrc)))
2471 (setq gnus-newsrc-alist newsrc)
2472 ;; We make the newsrc hashtb.
2473 (gnus-make-hashtable-from-newsrc-alist)
2475 ;; Finally, if we read some options lines, we parse them.
2476 (unless (string= gnus-newsrc-options "")
2477 (gnus-newsrc-parse-options gnus-newsrc-options))))
2479 ;; Parse options lines to find "options -n !all rec.all" and stuff.
2480 ;; The return value will be a list on the form
2481 ;; ((regexp1 . ignore)
2482 ;; (regexp2 . subscribe)...)
2483 ;; When handling new newsgroups, groups that match a `ignore' regexp
2484 ;; will be ignored, and groups that match a `subscribe' regexp will be
2485 ;; subscribed. A line like
2486 ;; options -n !all rec.all
2487 ;; will lead to a list that looks like
2488 ;; (("^rec\\..+" . subscribe)
2489 ;; ("^.+" . ignore))
2490 ;; So all "rec.*" groups will be subscribed, while all the other
2491 ;; groups will be ignored. Note that "options -n !all rec.all" is very
2492 ;; different from "options -n rec.all !all".
2493 (defun gnus-newsrc-parse-options (options)
2496 (gnus-set-work-buffer)
2497 (insert (regexp-quote options))
2498 ;; First we treat all continuation lines.
2499 (goto-char (point-min))
2500 (while (re-search-forward "\n[ \t]+" nil t)
2501 (replace-match " " t t))
2502 ;; Then we transform all "all"s into ".+"s.
2503 (goto-char (point-min))
2504 (while (re-search-forward "\\ball\\b" nil t)
2505 (replace-match ".+" t t))
2506 (goto-char (point-min))
2507 ;; We remove all other options than the "-n" ones.
2508 (while (re-search-forward "[ \t]-[^n][^-]*" nil t)
2511 (goto-char (point-min))
2513 ;; We are only interested in "options -n" lines - we
2514 ;; ignore the other option lines.
2515 (while (re-search-forward "[ \t]-n" nil t)
2518 (and (re-search-forward "[ \t]-n" (gnus-point-at-eol) t)
2520 (gnus-point-at-eol)))
2521 ;; Search for all "words"...
2522 (while (re-search-forward "[^ \t,\n]+" eol t)
2523 (if (eq (char-after (match-beginning 0)) ?!)
2524 ;; If the word begins with a bang (!), this is a "not"
2525 ;; spec. We put this spec (minus the bang) and the
2526 ;; symbol `ignore' into the list.
2528 "^" (buffer-substring
2529 (1+ (match-beginning 0))
2534 ;; There was no bang, so this is a "yes" spec.
2535 (push (cons (concat "^" (match-string 0) "\\($\\|\\.\\)")
2539 (setq gnus-newsrc-options-n out))))
2542 (defalias 'gnus-long-file-names
2543 (if (fboundp 'msdos-long-file-names)
2544 'msdos-long-file-names
2547 (defun gnus-save-newsrc-file (&optional force)
2548 "Save .newsrc file."
2549 ;; Note: We cannot save .newsrc file if all newsgroups are removed
2550 ;; from the variable gnus-newsrc-alist.
2551 (when (and (or gnus-newsrc-alist gnus-killed-list)
2552 gnus-current-startup-file)
2554 (if (and (or gnus-use-dribble-file gnus-slave)
2556 (or (not gnus-dribble-buffer)
2557 (not (buffer-name gnus-dribble-buffer))
2558 (zerop (save-excursion
2559 (set-buffer gnus-dribble-buffer)
2561 (gnus-message 4 "(No changes need to be saved)")
2562 (gnus-run-hooks 'gnus-save-newsrc-hook)
2564 (gnus-slave-save-newsrc)
2566 (when gnus-save-newsrc-file
2567 (gnus-message 8 "Saving %s..." gnus-current-startup-file)
2568 (gnus-gnus-to-newsrc-format)
2569 (gnus-message 8 "Saving %s...done" gnus-current-startup-file))
2570 ;; Save .newsrc.eld.
2571 (set-buffer (gnus-get-buffer-create " *Gnus-newsrc*"))
2572 (make-local-variable 'version-control)
2573 (setq version-control gnus-backup-startup-file)
2574 (setq buffer-file-name
2575 (concat gnus-current-startup-file ".eld"))
2576 (setq default-directory (file-name-directory buffer-file-name))
2577 (buffer-disable-undo)
2579 (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file)
2581 (if gnus-save-startup-file-via-temp-buffer
2582 (let ((coding-system-for-write gnus-ding-file-coding-system)
2583 (standard-output (current-buffer)))
2584 (gnus-gnus-to-quick-newsrc-format)
2585 (gnus-run-hooks 'gnus-save-quick-newsrc-hook)
2587 (let ((coding-system-for-write gnus-ding-file-coding-system)
2588 (version-control gnus-backup-startup-file)
2589 (startup-file (concat gnus-current-startup-file ".eld"))
2590 (working-dir (file-name-directory gnus-current-startup-file))
2593 ;; Generate the name of a non-existent file.
2594 (while (progn (setq working-file
2596 (if (and (eq system-type 'ms-dos)
2597 (not (gnus-long-file-names)))
2598 "%s#%d.tm#" ; MSDOS limits files to 8+3
2599 (if (memq system-type '(vax-vms axp-vms))
2602 working-dir (setq i (1+ i))))
2603 (file-exists-p working-file)))
2607 (gnus-with-output-to-file working-file
2608 (gnus-gnus-to-quick-newsrc-format)
2609 (gnus-run-hooks 'gnus-save-quick-newsrc-hook))
2611 ;; These bindings will mislead the current buffer
2612 ;; into thinking that it is visiting the startup
2614 (let ((buffer-backed-up nil)
2615 (buffer-file-name startup-file)
2616 (file-precious-flag t)
2617 (setmodes (file-modes startup-file)))
2618 ;; Backup the current version of the startup file.
2621 ;; Replace the existing startup file with the temp file.
2622 (rename-file working-file startup-file t)
2623 (set-file-modes startup-file setmodes)))
2625 (delete-file working-file)
2626 (file-error nil)))))
2628 (gnus-kill-buffer (current-buffer))
2630 5 "Saving %s.eld...done" gnus-current-startup-file))
2631 (gnus-dribble-delete-file)
2632 (gnus-group-set-mode-line)))))
2634 (defun gnus-gnus-to-quick-newsrc-format ()
2635 "Print Gnus variables such as gnus-newsrc-alist in lisp format."
2636 (princ ";; -*- emacs-lisp -*-\n")
2637 (princ ";; Gnus startup file.\n")
2639 ;; Never delete this file -- if you want to force Gnus to read the
2640 ;; .newsrc file (if you have one), touch .newsrc instead.\n")
2641 (princ "(setq gnus-newsrc-file-version ")
2642 (princ (gnus-prin1-to-string gnus-version))
2644 (let* ((print-quoted t)
2646 (print-escape-multibyte nil)
2647 (print-escape-nonascii t)
2650 (print-escape-newlines t)
2652 (if (and gnus-save-killed-list
2653 (stringp gnus-save-killed-list))
2654 (gnus-strip-killed-list)
2657 (if gnus-save-killed-list gnus-variable-list
2658 ;; Remove the `gnus-killed-list' from the list of variables
2659 ;; to be saved, if required.
2660 (delq 'gnus-killed-list (copy-sequence gnus-variable-list))))
2661 ;; Peel off the "dummy" group.
2662 (gnus-newsrc-alist (cdr gnus-newsrc-alist))
2664 ;; Insert the variables into the file.
2666 (when (and (boundp (setq variable (pop variables)))
2667 (symbol-value variable))
2669 (princ (symbol-name variable))
2671 (prin1 (symbol-value variable))
2674 (defun gnus-strip-killed-list ()
2675 "Return the killed list minus the groups that match `gnus-save-killed-list'."
2676 (let ((list gnus-killed-list)
2679 (when (string-match gnus-save-killed-list (car list))
2680 (push (car list) olist))
2684 (defun gnus-gnus-to-newsrc-format ()
2685 ;; Generate and save the .newsrc file.
2687 (set-buffer (create-file-buffer gnus-current-startup-file))
2688 (let ((newsrc (cdr gnus-newsrc-alist))
2689 (standard-output (current-buffer))
2690 info ranges range method)
2691 (setq buffer-file-name gnus-current-startup-file)
2692 (setq default-directory (file-name-directory buffer-file-name))
2693 (buffer-disable-undo)
2696 (when gnus-newsrc-options
2697 (insert gnus-newsrc-options))
2698 ;; Write subscribed and unsubscribed.
2699 (while (setq info (pop newsrc))
2700 ;; Don't write foreign groups to .newsrc.
2701 (when (or (null (setq method (gnus-info-method info)))
2702 (equal method "native")
2703 (inline (gnus-server-equal method gnus-select-method)))
2704 (insert (gnus-info-group info)
2705 (if (> (gnus-info-level info) gnus-level-subscribed)
2707 (when (setq ranges (gnus-info-read info))
2709 (if (not (listp (cdr ranges)))
2710 (if (= (car ranges) (cdr ranges))
2711 (princ (car ranges))
2712 (princ (car ranges))
2714 (princ (cdr ranges)))
2715 (while (setq range (pop ranges))
2716 (if (or (atom range) (= (car range) (cdr range)))
2717 (princ (or (and (atom range) range) (car range)))
2720 (princ (cdr range)))
2724 (make-local-variable 'version-control)
2725 (setq version-control 'never)
2726 ;; It has been reported that sometime the modtime on the .newsrc
2727 ;; file seems to be off. We really do want to overwrite it, so
2728 ;; we clear the modtime here before saving. It's a bit odd,
2730 ;; sometimes the modtime clear isn't sufficient. most brute force:
2731 ;; delete the silly thing entirely first. but this fails to provide
2732 ;; such niceties as .newsrc~ creation.
2733 (if gnus-modtime-botch
2734 (delete-file gnus-startup-file)
2735 (clear-visited-file-modtime))
2736 (gnus-run-hooks 'gnus-save-standard-newsrc-hook)
2738 (kill-buffer (current-buffer)))))
2742 ;;; Slave functions.
2745 (defvar gnus-slave-mode nil)
2747 (defun gnus-slave-mode ()
2748 "Minor mode for slave Gnusae."
2749 (gnus-add-minor-mode 'gnus-slave-mode " Slave" (make-sparse-keymap))
2750 (gnus-run-hooks 'gnus-slave-mode-hook))
2752 (defun gnus-slave-save-newsrc ()
2754 (set-buffer gnus-dribble-buffer)
2756 (mm-make-temp-file (concat gnus-current-startup-file "-slave-")))
2757 (modes (ignore-errors
2758 (file-modes (concat gnus-current-startup-file ".eld")))))
2759 (let ((coding-system-for-write gnus-ding-file-coding-system))
2760 (gnus-write-buffer slave-name))
2762 (set-file-modes slave-name modes)))))
2764 (defun gnus-master-read-slave-newsrc ()
2767 (file-name-directory gnus-current-startup-file)
2771 (file-name-nondirectory gnus-current-startup-file)
2775 (if (not slave-files)
2776 () ; There are no slave files to read.
2777 (gnus-message 7 "Reading slave newsrcs...")
2779 (set-buffer (gnus-get-buffer-create " *gnus slave*"))
2781 (sort (mapcar (lambda (file)
2782 (list (nth 5 (file-attributes file)) file))
2785 (or (< (caar f1) (caar f2))
2786 (< (nth 1 (car f1)) (nth 1 (car f2)))))))
2789 (setq file (nth 1 (car slave-files)))
2790 (nnheader-insert-file-contents file)
2791 (when (condition-case ()
2793 (eval-buffer (current-buffer))
2796 (gnus-error 3.2 "Possible error in %s" file)
2798 (unless gnus-slave ; Slaves shouldn't delete these files.
2800 (delete-file file))))
2801 (setq slave-files (cdr slave-files))))
2802 (gnus-dribble-touch)
2803 (gnus-message 7 "Reading slave newsrcs...done"))))
2807 ;;; Group description.
2810 (defun gnus-read-all-descriptions-files ()
2811 (let ((methods (cons gnus-select-method
2813 (when (gnus-archive-server-wanted-p)
2815 gnus-secondary-select-methods))))
2817 (gnus-read-descriptions-file (car methods))
2818 (setq methods (cdr methods)))
2821 (defun gnus-read-descriptions-file (&optional method)
2822 (let ((method (or method gnus-select-method))
2824 (when (stringp method)
2825 (setq method (gnus-server-to-method method)))
2826 ;; We create the hashtable whether we manage to read the desc file
2827 ;; to avoid trying to re-read after a failed read.
2828 (unless gnus-description-hashtb
2829 (setq gnus-description-hashtb
2830 (gnus-make-hashtable (length gnus-active-hashtb))))
2831 ;; Mark this method's desc file as read.
2832 (gnus-sethash (gnus-group-prefixed-name "" method) "Has read"
2833 gnus-description-hashtb)
2835 (gnus-message 5 "Reading descriptions file via %s..." (car method))
2837 ((null (gnus-get-function method 'request-list-newsgroups t))
2839 ((not (gnus-check-server method))
2840 (gnus-message 1 "Couldn't open server")
2842 ((not (gnus-request-list-newsgroups method))
2843 (gnus-message 1 "Couldn't read newsgroups descriptions")
2848 (set-buffer nntp-server-buffer)
2849 (goto-char (point-min))
2850 (when (or (search-forward "\n.\n" nil t)
2851 (goto-char (point-max)))
2853 (narrow-to-region (point-min) (point)))
2854 ;; If these are groups from a foreign select method, we insert the
2855 ;; group prefix in front of the group names.
2856 (and method (not (inline
2858 (gnus-server-get-method nil method)
2859 (gnus-server-get-method
2860 nil gnus-select-method))))
2861 (let ((prefix (gnus-group-prefixed-name "" method)))
2862 (goto-char (point-min))
2863 (while (and (not (eobp))
2864 (progn (insert prefix)
2865 (zerop (forward-line 1)))))))
2866 (goto-char (point-min))
2868 ;; If we get an error, we set group to 0, which is not a
2872 (let ((obarray gnus-description-hashtb))
2873 ;; Group is set to a symbol interned in this
2875 (read nntp-server-buffer))
2877 (skip-chars-forward " \t")
2878 ;; ... which leads to this line being effectively ignored.
2879 (when (symbolp group)
2880 (let* ((str (buffer-substring
2881 (point) (progn (end-of-line) (point))))
2882 (name (symbol-name group))
2884 (or (gnus-group-name-charset method name)
2885 (gnus-parameter-charset name)
2886 gnus-default-charset)))
2887 ;; Fixme: Don't decode in unibyte mode.
2888 (when (and str charset (featurep 'mule))
2889 (setq str (mm-decode-coding-string str charset)))
2892 (gnus-message 5 "Reading descriptions file...done")
2895 (defun gnus-group-get-description (group)
2896 "Get the description of a group by sending XGTITLE to the server."
2897 (when (gnus-request-group-description group)
2899 (set-buffer nntp-server-buffer)
2900 (goto-char (point-min))
2901 (when (looking-at "[^ \t]+[ \t]+\\(.*\\)")
2902 (match-string 1)))))
2905 (defun gnus-declare-backend (name &rest abilities)
2906 "Declare backend NAME with ABILITIES as a Gnus backend."
2907 (setq gnus-valid-select-methods
2908 (nconc gnus-valid-select-methods
2909 (list (apply 'list name abilities))))
2910 (gnus-redefine-select-method-widget))
2912 (defun gnus-set-default-directory ()
2913 "Set the default directory in the current buffer to `gnus-default-directory'.
2914 If this variable is nil, don't do anything."
2915 (setq default-directory
2916 (if (and gnus-default-directory
2917 (file-exists-p gnus-default-directory))
2918 (file-name-as-directory (expand-file-name gnus-default-directory))
2919 default-directory)))
2922 (defalias 'gnus-display-time-event-handler
2923 (if (gnus-boundp 'display-time-timer)
2924 'display-time-event-handler
2925 (lambda () "Does nothing as `display-time-timer' is not bound.
2926 Would otherwise be an alias for `display-time-event-handler'." nil))))
2929 (defun gnus-fixup-nnimap-unread-after-getting-new-news ()
2930 (let (server group info)
2933 (when (and (setq group (symbol-name sym))
2934 (gnus-group-entry group)
2935 (setq info (symbol-value sym)))
2936 (gnus-sethash group (cons (nth 2 info) (cdr (gnus-group-entry group)))
2937 gnus-newsrc-hashtb)))
2938 (if (boundp 'nnimap-mailbox-info)
2939 (symbol-value 'nnimap-mailbox-info)
2940 (make-vector 1 0)))))
2943 (provide 'gnus-start)
2945 ;;; gnus-start.el ends here