1 ;;; gnus-start.el --- startup functions for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
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.
29 (eval-when-compile (require 'cl))
30 (eval-when-compile (require 'static))
38 (autoload 'message-make-date "message")
39 (autoload 'gnus-agent-read-servers-validate "gnus-agent")
40 (autoload 'gnus-agent-save-local "gnus-agent")
41 (autoload 'gnus-agent-possibly-alter-active "gnus-agent")
43 (defvar gnus-agent-covered-methods nil)
44 (defvar gnus-agent-file-loading-local nil)
45 (defvar gnus-agent-file-loading-cache nil))
47 (defcustom gnus-startup-file (nnheader-concat gnus-home-directory ".newsrc")
49 `.newsrc-SERVER' will be used instead if that exists."
53 (defcustom gnus-product-directory
54 (nnheader-concat gnus-directory (concat "." gnus-product-name))
55 "Product depend data files directory."
57 :type '(choice directory (const nil)))
59 (defcustom gnus-backup-startup-file 'never
60 "Whether to create backup files.
61 This variable takes the same values as the `version-control'
65 :type '(choice (const :tag "Never" never)
66 (const :tag "If existing" nil)
67 (other :tag "Always" t)))
69 (defcustom gnus-save-startup-file-via-temp-buffer t
70 "Whether to write the startup file contents to a buffer then save
71 the buffer or write directly to the file. The buffer is faster
72 because all of the contents are written at once. The direct write
73 uses considerably less memory."
76 :type '(choice (const :tag "Write via buffer" t)
77 (const :tag "Write directly to file" nil)))
79 (defcustom gnus-init-file (nnheader-concat gnus-home-directory ".gnus")
80 "Your Gnus Emacs-Lisp startup file name.
81 If a file with the `.el' or `.elc' suffixes exists, it will be read instead."
85 (defcustom gnus-site-init-file
87 (concat (file-name-directory
88 (directory-file-name installation-directory))
89 "site-lisp/gnus-init")
91 "The site-wide Gnus Emacs-Lisp startup file name, or nil if none.
92 If a file with the `.el' or `.elc' suffixes exists, it will be read instead."
94 :type '(choice file (const nil)))
96 (defcustom gnus-default-subscribed-newsgroups nil
97 "List of newsgroups to subscribe, when a user runs Gnus the first time.
98 The value should be a list of strings.
99 If it is t, Gnus will not do anything special the first time it is
100 started; it'll just use the normal newsgroups subscription methods."
102 :type '(choice (repeat string) (const :tag "Nothing special" t)))
104 (defcustom gnus-use-dribble-file t
105 "*Non-nil means that Gnus will use a dribble file to store user updates.
106 If Emacs should crash without saving the .newsrc files, complete
107 information can be restored from the dribble file."
108 :group 'gnus-dribble-file
111 (defcustom gnus-dribble-directory nil
112 "*The directory where dribble files will be saved.
113 If this variable is nil, the directory where the .newsrc files are
115 :group 'gnus-dribble-file
116 :type '(choice directory (const nil)))
118 (defcustom gnus-check-new-newsgroups 'ask-server
119 "*Non-nil means that Gnus will run `gnus-find-new-newsgroups' at startup.
120 This normally finds new newsgroups by comparing the active groups the
121 servers have already reported with those Gnus already knows, either alive
124 When any of the following are true, `gnus-find-new-newsgroups' will instead
125 ask the servers (primary, secondary, and archive servers) to list new
126 groups since the last time it checked:
127 1. This variable is `ask-server'.
128 2. This variable is a list of select methods (see below).
129 3. `gnus-read-active-file' is nil or `some'.
130 4. A prefix argument is given to `gnus-find-new-newsgroups' interactively.
132 Thus, if this variable is `ask-server' or a list of select methods or
133 `gnus-read-active-file' is nil or `some', then the killed list is no
134 longer necessary, so you could safely set `gnus-save-killed-list' to nil.
136 This variable can be a list of select methods which Gnus will query with
137 the `ask-server' method in addition to the primary, secondary, and archive
141 (setq gnus-check-new-newsgroups
142 '((nntp \"some.server\") (nntp \"other.server\")))
144 If this variable is nil, then you have to tell Gnus explicitly to
145 check for new newsgroups with \\<gnus-group-mode-map>\\[gnus-find-new-newsgroups]."
147 :type '(choice (const :tag "no" nil)
148 (const :tag "by brute force" t)
149 (const :tag "ask servers" ask-server)
150 (repeat :menu-tag "ask additional servers"
151 :tag "ask additional servers"
153 (sexp :format "%v"))))
155 (defcustom gnus-check-bogus-newsgroups nil
156 "*Non-nil means that Gnus will check and remove bogus newsgroup at startup.
157 If this variable is nil, then you have to tell Gnus explicitly to
158 check for bogus newsgroups with \\<gnus-group-mode-map>\\[gnus-group-check-bogus-groups]."
159 :group 'gnus-start-server
162 (defcustom gnus-read-active-file 'some
163 "*Non-nil means that Gnus will read the entire active file at startup.
164 If this variable is nil, Gnus will only know about the groups in your
167 If this variable is `some', Gnus will try to only read the relevant
168 parts of the active file from the server. Not all servers support
169 this, and it might be quite slow with other servers, but this should
170 generally be faster than both the t and nil value.
172 If you set this variable to nil or `some', you probably still want to
173 be told about new newsgroups that arrive. To do that, set
174 `gnus-check-new-newsgroups' to `ask-server'. This may not work
175 properly with all servers."
176 :group 'gnus-start-server
177 :type '(choice (const nil)
181 (defconst gnus-level-subscribed 5
182 "Groups with levels less than or equal to this variable are subscribed.")
184 (defconst gnus-level-unsubscribed 7
185 "Groups with levels less than or equal to this variable are unsubscribed.
186 Groups with levels less than `gnus-level-subscribed', which should be
187 less than this variable, are subscribed.")
189 (defconst gnus-level-zombie 8
190 "Groups with this level are zombie groups.")
192 (defconst gnus-level-killed 9
193 "Groups with this level are killed.")
195 (defcustom gnus-level-default-subscribed 3
196 "*New subscribed groups will be subscribed at this level."
197 :group 'gnus-group-levels
200 (defcustom gnus-level-default-unsubscribed 6
201 "*New unsubscribed groups will be unsubscribed at this level."
202 :group 'gnus-group-levels
205 (defcustom gnus-activate-level (1+ gnus-level-subscribed)
206 "*Groups higher than this level won't be activated on startup.
207 Setting this variable to something low might save lots of time when
208 you have many groups that you aren't interested in."
209 :group 'gnus-group-levels
212 (defcustom gnus-activate-foreign-newsgroups 4
213 "*If nil, Gnus will not check foreign newsgroups at startup.
214 If it is non-nil, it should be a number between one and nine. Foreign
215 newsgroups that have a level lower or equal to this number will be
216 activated on startup. For instance, if you want to active all
217 subscribed newsgroups, but not the rest, you'd set this variable to
218 `gnus-level-subscribed'.
220 If you subscribe to lots of newsgroups from different servers, startup
221 might take a while. By setting this variable to nil, you'll save time,
222 but you won't be told how many unread articles there are in the
224 :group 'gnus-group-levels
225 :type '(choice integer
226 (const :tag "none" nil)))
228 (defcustom gnus-read-newsrc-file t
229 "*Non-nil means that Gnus will read the `.newsrc' file.
230 Gnus always reads its own startup file, which is called
231 \".newsrc.eld\". The file called \".newsrc\" is in a format that can
232 be readily understood by other newsreaders. If you don't plan on
233 using other newsreaders, set this variable to nil to save some time on
239 (defcustom gnus-save-newsrc-file t
240 "*Non-nil means that Gnus will save the `.newsrc' file.
241 Gnus always saves its own startup file, which is called
242 \".newsrc.eld\". The file called \".newsrc\" is in a format that can
243 be readily understood by other newsreaders. If you don't plan on
244 using other newsreaders, set this variable to nil to save some time on
249 (defcustom gnus-save-killed-list t
250 "*If non-nil, save the list of killed groups to the startup file.
251 If you set this variable to nil, you'll save both time (when starting
252 and quitting) and space (both memory and disk), but it will also mean
253 that Gnus has no record of which groups are new and which are old, so
254 the automatic new newsgroups subscription methods become meaningless.
256 You should always set `gnus-check-new-newsgroups' to `ask-server' or
257 nil if you set this variable to nil.
259 This variable can also be a regexp. In that case, all groups that do
260 not match this regexp will be removed before saving the list."
262 :type '(radio (sexp :format "Non-nil\n"
263 :match (lambda (widget value)
264 (and value (not (stringp value))))
269 (defcustom gnus-ignored-newsgroups
271 '("^to\\." ; not "real" groups
272 "^[0-9. \t]+\\( \\|$\\)" ; all digits in name
273 "^[\"][]\"[#'()]" ; bogus characters
276 "*A regexp to match uninteresting newsgroups in the active file.
277 Any lines in the active file matching this regular expression are
278 removed from the newsgroup list before anything else is done to it,
279 thus making them effectively non-existent."
280 :group 'gnus-group-new
283 (defcustom gnus-subscribe-newsgroup-method 'gnus-subscribe-zombies
284 "*Function(s) called with a group name when new group is detected.
285 A few pre-made functions are supplied: `gnus-subscribe-randomly'
286 inserts new groups at the beginning of the list of groups;
287 `gnus-subscribe-alphabetically' inserts new groups in strict
288 alphabetic order; `gnus-subscribe-hierarchically' inserts new groups
289 in hierarchical newsgroup order; `gnus-subscribe-interactively' asks
290 for your decision; `gnus-subscribe-killed' kills all new groups;
291 `gnus-subscribe-zombies' will make all new groups into zombies;
292 `gnus-subscribe-topics' will enter groups into the topics that
294 :group 'gnus-group-new
295 :type '(radio (function-item gnus-subscribe-randomly)
296 (function-item gnus-subscribe-alphabetically)
297 (function-item gnus-subscribe-hierarchically)
298 (function-item gnus-subscribe-interactively)
299 (function-item gnus-subscribe-killed)
300 (function-item gnus-subscribe-zombies)
301 (function-item gnus-subscribe-topics)
305 (defcustom gnus-subscribe-newsgroup-hooks nil
306 "*Hooks run after you subscribe to a new group.
307 The hooks will be called with new group's name as argument."
309 :group 'gnus-group-new
312 (defcustom gnus-subscribe-options-newsgroup-method
313 'gnus-subscribe-alphabetically
314 "*Function(s) called to subscribe newsgroups mentioned on \"options -n\" lines.
315 If, for instance, you want to subscribe to all newsgroups in the
316 \"no\" and \"alt\" hierarchies, you'd put the following in your
319 options -n no.all alt.all
321 Gnus will the subscribe all new newsgroups in these hierarchies with
322 the subscription method in this variable."
323 :group 'gnus-group-new
324 :type '(radio (function-item gnus-subscribe-randomly)
325 (function-item gnus-subscribe-alphabetically)
326 (function-item gnus-subscribe-hierarchically)
327 (function-item gnus-subscribe-interactively)
328 (function-item gnus-subscribe-killed)
329 (function-item gnus-subscribe-zombies)
330 (function-item gnus-subscribe-topics)
334 (defcustom gnus-subscribe-hierarchical-interactive nil
335 "*If non-nil, Gnus will offer to subscribe hierarchically.
336 When a new hierarchy appears, Gnus will ask the user:
338 'alt.binaries': Do you want to subscribe to this hierarchy? ([d]ys):
340 If the user pressed `d', Gnus will descend the hierarchy, `y' will
341 subscribe to all newsgroups in the hierarchy and `s' will skip this
342 hierarchy in its entirety."
343 :group 'gnus-group-new
346 (defcustom gnus-auto-subscribed-groups
347 "^nnml\\|^nnfolder\\|^nnmbox\\|^nnmh\\|^nnbabyl\\|^nnmaildir"
348 "*All new groups that match this regexp will be subscribed automatically.
349 Note that this variable only deals with new groups. It has no effect
350 whatsoever on old groups.
352 New groups that match this regexp will not be handled by
353 `gnus-subscribe-newsgroup-method'. Instead, they will
354 be subscribed using `gnus-subscribe-options-newsgroup-method'."
355 :group 'gnus-group-new
358 (defcustom gnus-options-subscribe nil
359 "*All new groups matching this regexp will be subscribed unconditionally.
360 Note that this variable deals only with new newsgroups. This variable
361 does not affect old newsgroups.
363 New groups that match this regexp will not be handled by
364 `gnus-subscribe-newsgroup-method'. Instead, they will
365 be subscribed using `gnus-subscribe-options-newsgroup-method'."
366 :group 'gnus-group-new
367 :type '(choice regexp
368 (const :tag "none" nil)))
370 (defcustom gnus-options-not-subscribe nil
371 "*All new groups matching this regexp will be ignored.
372 Note that this variable deals only with new newsgroups. This variable
373 does not affect old (already subscribed) newsgroups."
374 :group 'gnus-group-new
375 :type '(choice regexp
376 (const :tag "none" nil)))
378 (defcustom gnus-modtime-botch nil
379 "*Non-nil means .newsrc should be deleted prior to save.
380 Its use is due to the bogus appearance that .newsrc was modified on
385 (defcustom gnus-check-bogus-groups-hook nil
386 "A hook run after removing bogus groups."
387 :group 'gnus-start-server
390 (defcustom gnus-startup-hook nil
391 "A hook called at startup.
392 This hook is called after Gnus is connected to the NNTP server."
396 (defcustom gnus-before-startup-hook nil
397 "A hook called at before startup.
398 This hook is called as the first thing when Gnus is started."
402 (defcustom gnus-started-hook nil
403 "A hook called as the last thing after startup."
407 (defcustom gnus-setup-news-hook
408 '(gnus-fixup-nnimap-unread-after-getting-new-news)
409 "A hook after reading the .newsrc file, but before generating the buffer."
413 (defcustom gnus-get-top-new-news-hook nil
414 "A hook run just before Gnus checks for new news globally."
416 :group 'gnus-group-new
419 (defcustom gnus-get-new-news-hook nil
420 "A hook run just before Gnus checks for new news."
421 :group 'gnus-group-new
424 (defcustom gnus-after-getting-new-news-hook
425 '(gnus-display-time-event-handler
426 gnus-fixup-nnimap-unread-after-getting-new-news)
427 "A hook run after Gnus checks for new news when Gnus is already running."
428 :group 'gnus-group-new
431 (defcustom gnus-read-newsrc-el-hook nil
432 "A hook called after reading the newsrc.eld? file."
436 (defcustom gnus-save-newsrc-hook nil
437 "A hook called before saving any of the newsrc files."
441 (defcustom gnus-save-quick-newsrc-hook nil
442 "A hook called just before saving the quick newsrc file.
443 Can be used to turn version control on or off."
447 (defcustom gnus-save-standard-newsrc-hook nil
448 "A hook called just before saving the standard newsrc file.
449 Can be used to turn version control on or off."
453 (defcustom gnus-group-mode-hook nil
454 "Hook for Gnus group mode."
455 :group 'gnus-group-various
456 :options '(gnus-topic-mode)
459 (defcustom gnus-always-read-dribble-file nil
460 "Unconditionally read the dribble file."
464 ;;; Internal variables
466 (defvar gnus-ding-file-coding-system 'ctext
467 "Coding system for ding file.")
468 ;; Note that the ding file for T-gnus ought not to have byte-codes.
470 (defvar gnus-newsrc-file-version nil)
471 (defvar gnus-override-subscribe-method nil)
472 (defvar gnus-dribble-buffer nil)
473 (defvar gnus-newsrc-options nil
474 "Options line in the .newsrc file.")
476 (defvar gnus-newsrc-options-n nil
477 "List of regexps representing groups to be subscribed/ignored unconditionally.")
479 (defvar gnus-newsrc-last-checked-date nil
480 "Date Gnus last asked server for new newsgroups.")
482 (defvar gnus-current-startup-file nil
483 "Startup file for the current host.")
485 ;; Byte-compiler warning.
486 (defvar gnus-group-line-format)
488 ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
489 (defvar gnus-init-inhibit nil)
490 (defun gnus-read-init-file (&optional inhibit-next)
491 ;; Don't load .gnus if the -q option was used.
493 (if gnus-init-inhibit
494 (setq gnus-init-inhibit nil)
495 (setq gnus-init-inhibit inhibit-next)
496 (dolist (file (list gnus-site-init-file gnus-init-file))
498 (locate-library file))
499 (if (or debug-on-error debug-on-quit)
504 (error "Error in %s: %s" file (cadr var))))))))))
506 ;; For subscribing new newsgroup
508 (defun gnus-subscribe-hierarchical-interactive (groups)
509 (let ((groups (sort groups 'string<))
510 prefixes prefix start ans group starts real-group)
512 (setq prefixes (list "^"))
513 (while (and groups prefixes)
514 (while (not (string-match (car prefixes)
515 (gnus-group-real-name (car groups))))
516 (setq prefixes (cdr prefixes)))
517 (setq prefix (car prefixes))
518 (setq start (1- (length prefix)))
519 (if (and (string-match "[^\\.]\\." (gnus-group-real-name (car groups))
523 (concat "^" (substring
524 (gnus-group-real-name (car groups))
526 (string-match prefix (gnus-group-real-name (cadr groups))))
528 (push prefix prefixes)
529 (message "Descend hierarchy %s? ([y]nsq): "
530 (substring prefix 1 (1- (length prefix))))
531 (while (not (memq (setq ans (read-char-exclusive))
532 '(?y ?\n ?\r ?n ?s ?q)))
534 (message "Descend hierarchy %s? ([y]nsq): "
535 (substring prefix 1 (1- (length prefix)))))
538 (setq group (car groups)
539 real-group (gnus-group-real-name group))
540 (string-match prefix real-group))
541 (push group gnus-killed-list)
542 (gnus-sethash group group gnus-killed-hashtb)
543 (setq groups (cdr groups)))
544 (setq starts (cdr starts)))
547 (setq group (car groups)
548 real-group (gnus-group-real-name group))
549 (string-match prefix real-group))
550 (gnus-sethash group group gnus-killed-hashtb)
551 (gnus-subscribe-alphabetically (car groups))
552 (setq groups (cdr groups)))
553 (setq starts (cdr starts)))
556 (setq group (car groups))
557 (push group gnus-killed-list)
558 (gnus-sethash group group gnus-killed-hashtb)
559 (setq groups (cdr groups))))
561 (message "Subscribe %s? ([n]yq)" (car groups))
562 (while (not (memq (setq ans (read-char-exclusive))
563 '(?y ?\n ?\r ?q ?n)))
565 (message "Subscribe %s? ([n]yq)" (car groups)))
566 (setq group (car groups))
568 (gnus-subscribe-alphabetically (car groups))
569 (gnus-sethash group group gnus-killed-hashtb))
572 (setq group (car groups))
573 (push group gnus-killed-list)
574 (gnus-sethash group group gnus-killed-hashtb)
575 (setq groups (cdr groups))))
577 (push group gnus-killed-list)
578 (gnus-sethash group group gnus-killed-hashtb)))
579 (setq groups (cdr groups)))))))
581 (defun gnus-subscribe-randomly (newsgroup)
582 "Subscribe new NEWSGROUP by making it the first newsgroup."
583 (gnus-subscribe-newsgroup newsgroup))
585 (defun gnus-subscribe-alphabetically (newgroup)
586 "Subscribe new NEWGROUP and insert it in alphabetical order."
587 (let ((groups (cdr gnus-newsrc-alist))
589 (while (and (not before) groups)
590 (if (string< newgroup (caar groups))
591 (setq before (caar groups))
592 (setq groups (cdr groups))))
593 (gnus-subscribe-newsgroup newgroup before)))
595 (defun gnus-subscribe-hierarchically (newgroup)
596 "Subscribe new NEWGROUP and insert it in hierarchical newsgroup order."
597 ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
599 (set-buffer (nnheader-find-file-noselect gnus-current-startup-file))
601 (let ((groupkey newgroup) before)
602 (while (and (not before) groupkey)
603 (goto-char (point-min))
605 (concat "^\\(" (regexp-quote groupkey) ".*\\)[!:]")))
606 (while (and (re-search-forward groupkey-re nil t)
608 (setq before (match-string 1))
609 (string< before newgroup)))))
610 ;; Remove tail of newsgroup name (eg. a.b.c -> a.b)
612 (when (string-match "^\\(.*\\)\\.[^.]+$" groupkey)
613 (substring groupkey (match-beginning 1) (match-end 1)))))
614 (gnus-subscribe-newsgroup newgroup before))
615 (kill-buffer (current-buffer)))))
617 (defun gnus-subscribe-interactively (group)
618 "Subscribe the new GROUP interactively.
619 It is inserted in hierarchical newsgroup order if subscribed. If not,
621 (if (gnus-y-or-n-p (format "Subscribe new newsgroup: %s " group))
622 (gnus-subscribe-hierarchically group)
623 (push group gnus-killed-list)))
625 (defun gnus-subscribe-zombies (group)
626 "Make the new GROUP into a zombie group."
627 (push group gnus-zombie-list))
629 (defun gnus-subscribe-killed (group)
630 "Make the new GROUP a killed group."
631 (push group gnus-killed-list))
633 (defun gnus-subscribe-newsgroup (newsgroup &optional next)
634 "Subscribe new NEWSGROUP.
635 If NEXT is non-nil, it is inserted before NEXT. Otherwise it is made
636 the first newsgroup."
638 (goto-char (point-min))
639 ;; We subscribe the group by changing its level to `subscribed'.
640 (gnus-group-change-level
641 newsgroup gnus-level-default-subscribed
642 gnus-level-killed (gnus-group-entry (or next "dummy.group")))
643 (gnus-message 5 "Subscribe newsgroup: %s" newsgroup)
644 (run-hook-with-args 'gnus-subscribe-newsgroup-hooks newsgroup)
647 (defun gnus-read-active-file-p ()
648 "Say whether the active file has been read from `gnus-select-method'."
649 (memq gnus-select-method gnus-have-read-active-file))
651 ;;; General various misc type functions.
653 ;; Silence byte-compiler.
655 (defvar gnus-current-headers)
656 (defvar gnus-thread-indent-array)
657 (defvar gnus-newsgroup-name)
658 (defvar gnus-newsgroup-headers)
659 (defvar gnus-group-list-mode)
660 (defvar gnus-group-mark-positions)
661 (defvar gnus-newsgroup-data)
662 (defvar gnus-newsgroup-unreads)
663 (defvar nnoo-state-alist)
664 (defvar gnus-current-select-method)
665 (defvar mail-sources)
666 (defvar nnmail-scan-directory-mail-source-once)
667 (defvar nnmail-split-history)
668 (defvar nnmail-spool-file))
670 (defun gnus-clear-quick-file-variables ()
671 "Clear all variables in quick startup files."
672 (let ((variables gnus-variable-list))
673 ;; Clear Gnus variables.
675 (set (car variables) nil)
676 (setq variables (cdr variables))))
677 (let ((files gnus-product-variable-file-list))
679 (let ((variables (nthcdr 3 (car files))))
681 (set (car variables) nil)
682 (setq variables (cdr variables))))
683 (setq files (cdr files)))))
685 (defun gnus-close-all-servers ()
688 (dolist (server gnus-opened-servers)
689 (gnus-close-server (car server))))
691 (defun gnus-clear-system ()
692 "Clear all variables and buffers."
693 ;; Clear gnus variables.
694 (gnus-clear-quick-file-variables)
695 ;; Clear other internal variables.
696 (setq gnus-list-of-killed-groups nil
697 gnus-have-read-active-file nil
698 gnus-agent-covered-methods nil
699 gnus-agent-file-loading-local nil
700 gnus-agent-file-loading-cache nil
701 gnus-server-method-cache nil
702 gnus-newsrc-alist nil
703 gnus-newsrc-hashtb nil
706 gnus-killed-hashtb nil
707 gnus-active-hashtb nil
708 gnus-moderated-hashtb nil
709 gnus-description-hashtb nil
710 gnus-current-headers nil
711 gnus-thread-indent-array nil
712 gnus-newsgroup-headers nil
713 gnus-newsgroup-name nil
714 gnus-server-alist nil
715 gnus-group-list-mode nil
716 gnus-opened-servers nil
717 gnus-group-mark-positions nil
718 gnus-newsgroup-data nil
719 gnus-newsgroup-unreads nil
721 gnus-current-select-method nil
722 nnmail-split-history nil
723 gnus-ephemeral-servers nil)
724 (gnus-shutdown 'gnus)
725 ;; Kill the startup file.
726 (and gnus-current-startup-file
727 (get-file-buffer gnus-current-startup-file)
728 (kill-buffer (get-file-buffer gnus-current-startup-file)))
729 ;; Clear the dribble buffer.
731 ;; Kill global KILL file buffer.
732 (when (get-file-buffer (gnus-newsgroup-kill-file nil))
733 (kill-buffer (get-file-buffer (gnus-newsgroup-kill-file nil))))
734 (gnus-kill-buffer nntp-server-buffer)
735 ;; Kill Gnus buffers.
736 (dolist (buffer (gnus-buffers))
737 (gnus-kill-buffer buffer))
738 ;; Remove Gnus frames.
739 (gnus-kill-gnus-frames))
741 (defun gnus-no-server-1 (&optional arg slave)
743 If ARG is a positive number, Gnus will use that as the
744 startup level. If ARG is nil, Gnus will be started at level 2.
745 If ARG is non-nil and not a positive number, Gnus will
746 prompt the user for the name of an NNTP server to use.
747 As opposed to `gnus', this command will not connect to the local server."
749 (let ((val (or arg (1- gnus-level-default-subscribed))))
751 (make-local-variable 'gnus-group-use-permanent-levels)
752 (setq gnus-group-use-permanent-levels val)))
754 (defun gnus-1 (&optional arg dont-connect slave)
756 If ARG is non-nil and a positive number, Gnus will use that as the
757 startup level. If ARG is non-nil and not a positive number, Gnus will
758 prompt the user for the name of an NNTP server to use."
763 (switch-to-buffer gnus-group-buffer)
764 (gnus-group-get-new-news
767 (max (car gnus-group-list-mode) arg))))
771 (gnus-run-hooks 'gnus-before-startup-hook)
772 (nnheader-init-server-buffer)
773 (setq gnus-slave slave)
774 (gnus-read-init-file)
778 (when gnus-simple-splash
779 (setq gnus-simple-splash nil)
784 (= (frame-height) (1+ (window-height))))
787 (let ((level (and (numberp arg) (> arg 0) arg))
793 (gnus-start-news-server (and arg (not level))))))
794 (if (and (not dont-connect)
797 (gnus-run-hooks 'gnus-startup-hook)
798 ;; NNTP server is successfully open.
800 ;; Find the current startup file name.
801 (setq gnus-current-startup-file
802 (gnus-make-newsrc-file gnus-startup-file))
804 ;; Read the dribble file.
805 (when (or gnus-slave gnus-use-dribble-file)
806 (gnus-dribble-read-file))
808 ;; Do the actual startup.
810 (gnus-request-create-group "queue" '(nndraft "")))
811 (gnus-request-create-group "drafts" '(nndraft ""))
812 (gnus-setup-news nil level dont-connect)
813 (gnus-run-hooks 'gnus-setup-news-hook)
814 (gnus-start-draft-setup)
815 ;; Generate the group buffer.
816 (gnus-group-list-groups level)
817 (gnus-group-first-unread-group)
818 (gnus-configure-windows 'group)
819 (gnus-group-set-mode-line)
821 (set-language-info "Japanese" 'gnus-info "gnus-ja")
822 (gnus-run-hooks 'gnus-started-hook))))))
824 (defun gnus-start-draft-setup ()
825 "Make sure the draft group exists."
826 (gnus-request-create-group "drafts" '(nndraft ""))
827 (unless (gnus-group-entry "nndraft:drafts")
828 (let ((gnus-level-default-subscribed 1))
829 (gnus-subscribe-group "nndraft:drafts" nil '(nndraft "")))
830 (gnus-group-set-parameter
831 "nndraft:drafts" 'gnus-dummy '((gnus-draft-mode)))))
838 (defvar gnus-dribble-ignore nil)
839 (defvar gnus-dribble-eval-file nil)
841 (defun gnus-dribble-file-name ()
842 "Return the dribble file for the current .newsrc."
844 (if gnus-dribble-directory
845 (concat (file-name-as-directory gnus-dribble-directory)
846 (file-name-nondirectory gnus-current-startup-file))
847 gnus-current-startup-file)
850 (defun gnus-dribble-enter (string)
851 "Enter STRING into the dribble buffer."
852 (when (and (not gnus-dribble-ignore)
854 (buffer-name gnus-dribble-buffer))
855 (let ((obuf (current-buffer)))
856 (set-buffer gnus-dribble-buffer)
857 (goto-char (point-max))
859 ;; This has been commented by Josh Huber <huber@alum.wpi.edu>
860 ;; It causes problems with both XEmacs and Emacs 21, and doesn't
861 ;; seem to be of much value. (FIXME: remove this after we make sure
863 ;; (set-window-point (get-buffer-window (current-buffer)) (point-max))
864 (bury-buffer gnus-dribble-buffer)
866 (set-buffer gnus-group-buffer)
867 (gnus-group-set-mode-line))
870 (defun gnus-dribble-touch ()
871 "Touch the dribble buffer."
872 (gnus-dribble-enter ""))
874 (defun gnus-dribble-read-file ()
875 "Read the dribble file from disk."
876 (let ((dribble-file (gnus-dribble-file-name)))
878 (set-buffer (setq gnus-dribble-buffer
879 (gnus-get-buffer-create
880 (file-name-nondirectory dribble-file))))
882 (setq buffer-file-name dribble-file)
884 (buffer-disable-undo)
885 (bury-buffer (current-buffer))
886 (set-buffer-modified-p nil)
887 (let ((auto (make-auto-save-file-name))
888 (gnus-dribble-ignore t)
891 (when (or (file-exists-p auto) (file-exists-p dribble-file))
892 ;; Load whichever file is newest -- the auto save file
893 ;; or the "real" file.
894 (if (file-newer-than-file-p auto dribble-file)
895 (nnheader-insert-file-contents auto)
896 (nnheader-insert-file-contents dribble-file))
897 (unless (zerop (buffer-size))
898 (set-buffer-modified-p t))
899 ;; Set the file modes to reflect the .newsrc file modes.
901 (when (and (file-exists-p gnus-current-startup-file)
902 (file-exists-p dribble-file)
903 (setq modes (file-modes gnus-current-startup-file)))
904 (gnus-set-file-modes dribble-file modes))
905 (goto-char (point-min))
906 (when (search-forward "Gnus was exited on purpose" nil t)
908 ;; Possibly eval the file later.
909 (when (or gnus-always-read-dribble-file
912 "Gnus exited on purpose without saving; read auto-save file anyway? "
913 "Gnus auto-save file exists. Do you want to read it? ")))
914 (setq gnus-dribble-eval-file t)))))))
916 (defun gnus-dribble-eval-file ()
917 (when gnus-dribble-eval-file
918 (setq gnus-dribble-eval-file nil)
920 (let ((gnus-dribble-ignore t))
921 (set-buffer gnus-dribble-buffer)
922 (eval-buffer (current-buffer))))))
924 (defun gnus-dribble-delete-file ()
925 (when (file-exists-p (gnus-dribble-file-name))
926 (delete-file (gnus-dribble-file-name)))
927 (when gnus-dribble-buffer
929 (set-buffer gnus-dribble-buffer)
930 (let ((auto (make-auto-save-file-name)))
931 (when (file-exists-p auto)
934 (set-buffer-modified-p nil)))))
936 (defun gnus-dribble-save ()
937 (when (and gnus-dribble-buffer
938 (buffer-name gnus-dribble-buffer))
940 (set-buffer gnus-dribble-buffer)
943 (defun gnus-dribble-clear ()
944 (when (gnus-buffer-exists-p gnus-dribble-buffer)
946 (set-buffer gnus-dribble-buffer)
948 (set-buffer-modified-p nil)
949 (setq buffer-saved-size (buffer-size)))))
953 ;;; Active & Newsrc File Handling
956 (defun gnus-setup-news (&optional rawfile level dont-connect)
957 "Setup news information.
958 If RAWFILE is non-nil, the .newsrc file will also be read.
959 If LEVEL is non-nil, the news will be set up at level LEVEL."
961 (let ((init (not (and gnus-newsrc-alist gnus-active-hashtb (not rawfile))))
962 ;; Binding this variable will inhibit multiple fetchings
963 ;; of the same mail source.
964 (nnmail-fetched-sources (list t)))
967 ;; Clear some variables to re-initialize news information.
968 (setq gnus-newsrc-alist nil
969 gnus-active-hashtb nil)
970 ;; Read the newsrc file and create `gnus-newsrc-hashtb'.
971 (gnus-read-newsrc-file rawfile))
973 ;; Make sure the archive server is available to all and sundry.
974 (when gnus-message-archive-method
975 (unless (assoc "archive" gnus-server-alist)
976 (let ((method (or (and (stringp gnus-message-archive-method)
977 (gnus-server-to-method
978 gnus-message-archive-method))
979 gnus-message-archive-method)))
980 ;; Check whether the archive method is writable.
981 (unless (or (stringp method)
982 (memq 'respool (assoc (format "%s" (car method))
983 gnus-valid-select-methods)))
984 (setq method "archive")) ;; The default.
985 (push (if (stringp method)
990 ,(nnheader-concat message-directory method))
991 (nnfolder-active-file
992 ,(nnheader-concat message-directory
993 (concat method "/active")))
994 (nnfolder-get-new-mail nil)
995 (nnfolder-inhibit-expiry t))
996 (cons "archive" method))
997 gnus-server-alist))))
999 ;; If we don't read the complete active file, we fill in the
1001 (when (or (null gnus-read-active-file)
1002 (eq gnus-read-active-file 'some))
1003 (gnus-update-active-hashtb-from-killed))
1005 ;; Validate agent covered methods now that gnus-server-alist has
1006 ;; been initialized.
1007 ;; NOTE: This is here for one purpose only. By validating the
1008 ;; agentized server's, it converts the old 5.10.3, and earlier,
1009 ;; format to the current format. That enables the agent code
1010 ;; within gnus-read-active-file to function correctly.
1012 (gnus-agent-read-servers-validate))
1014 ;; Read the active file and create `gnus-active-hashtb'.
1015 ;; If `gnus-read-active-file' is nil, then we just create an empty
1016 ;; hash table. The partial filling out of the hash table will be
1017 ;; done in `gnus-get-unread-articles'.
1018 (and gnus-read-active-file
1020 (gnus-read-active-file nil dont-connect))
1022 (unless gnus-active-hashtb
1023 (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
1025 ;; Initialize the cache.
1026 (when gnus-use-cache
1029 ;; Possibly eval the dribble file.
1031 (or gnus-use-dribble-file gnus-slave)
1032 (gnus-dribble-eval-file))
1034 ;; Slave Gnusii should then clear the dribble buffer.
1035 (when (and init gnus-slave)
1036 (gnus-dribble-clear))
1038 (gnus-update-format-specifications)
1040 ;; See whether we need to read the description file.
1041 (when (and (boundp 'gnus-group-line-format)
1042 (stringp gnus-group-line-format)
1043 (let ((case-fold-search nil))
1044 (string-match "%[-,0-9]*D" gnus-group-line-format))
1045 (not gnus-description-hashtb)
1047 gnus-read-active-file)
1048 (gnus-read-all-descriptions-files))
1050 ;; Find new newsgroups and treat them.
1051 (when (and init gnus-check-new-newsgroups (not level)
1052 (gnus-check-server gnus-select-method)
1055 (gnus-find-new-newsgroups))
1057 ;; Check and remove bogus newsgroups.
1058 (when (and init gnus-check-bogus-newsgroups
1059 gnus-read-active-file (not level)
1060 (gnus-server-opened gnus-select-method))
1061 (gnus-check-bogus-newsgroups))
1063 ;; We might read in new NoCeM messages here.
1064 (when (and gnus-use-nocem
1067 (gnus-nocem-scan-groups))
1069 ;; Read any slave files.
1070 (gnus-master-read-slave-newsrc)
1072 ;; Find the number of unread articles in each non-dead group.
1073 (let ((gnus-read-active-file (and (not level) gnus-read-active-file)))
1074 (gnus-get-unread-articles level))))
1076 (defun gnus-call-subscribe-functions (method group)
1077 "Call METHOD to subscribe GROUP.
1078 If no function returns `non-nil', call `gnus-subscribe-zombies'."
1081 (funcall method group))
1084 (dolist (func method)
1085 (if (funcall func group)
1089 (gnus-subscribe-zombies group)))
1091 (defun gnus-find-new-newsgroups (&optional arg)
1092 "Search for new newsgroups and add them.
1093 Each new newsgroup will be treated with `gnus-subscribe-newsgroup-method'.
1094 The `-n' option line from .newsrc is respected.
1096 With 1 C-u, use the `ask-server' method to query the server for new
1098 With 2 C-u's, use most complete method possible to query the server
1099 for new groups, and subscribe the new groups as zombies."
1101 (let* ((gnus-subscribe-newsgroup-method
1102 gnus-subscribe-newsgroup-method)
1104 ((or (and (= (or arg 1) 4)
1105 (not (listp gnus-check-new-newsgroups)))
1106 (null gnus-read-active-file)
1107 (eq gnus-read-active-file 'some))
1110 (setq gnus-subscribe-newsgroup-method
1111 'gnus-subscribe-zombies)
1113 (t gnus-check-new-newsgroups))))
1114 (unless (gnus-check-first-time-used)
1115 (if (or (consp check)
1116 (eq check 'ask-server))
1117 ;; Ask the server for new groups.
1118 (gnus-ask-server-for-new-groups)
1119 ;; Go through the active hashtb and look for new groups.
1121 group new-newsgroups)
1122 (gnus-message 5 "Looking for new newsgroups...")
1123 (unless gnus-have-read-active-file
1124 (gnus-read-active-file))
1125 (setq gnus-newsrc-last-checked-date (message-make-date))
1126 (unless gnus-killed-hashtb
1127 (gnus-make-hashtable-from-killed))
1128 ;; Go though every newsgroup in `gnus-active-hashtb' and compare
1129 ;; with `gnus-newsrc-hashtb' and `gnus-killed-hashtb'.
1132 (if (or (null (setq group (symbol-name sym)))
1134 (null (symbol-value sym))
1135 (gnus-gethash group gnus-killed-hashtb)
1136 (gnus-gethash group gnus-newsrc-hashtb))
1138 (let ((do-sub (gnus-matches-options-n group)))
1140 ((eq do-sub 'subscribe)
1141 (setq groups (1+ groups))
1142 (gnus-sethash group group gnus-killed-hashtb)
1143 (gnus-call-subscribe-functions
1144 gnus-subscribe-options-newsgroup-method group))
1145 ((eq do-sub 'ignore)
1148 (setq groups (1+ groups))
1149 (gnus-sethash group group gnus-killed-hashtb)
1150 (if gnus-subscribe-hierarchical-interactive
1151 (push group new-newsgroups)
1152 (gnus-call-subscribe-functions
1153 gnus-subscribe-newsgroup-method group)))))))
1155 (when new-newsgroups
1156 (gnus-subscribe-hierarchical-interactive new-newsgroups))
1158 (gnus-message 5 "%d new newsgroup%s arrived."
1159 groups (if (> groups 1) "s have" " has"))
1160 (gnus-message 5 "No new newsgroups.")))))))
1162 (defun gnus-matches-options-n (group)
1163 ;; Returns `subscribe' if the group is to be unconditionally
1164 ;; subscribed, `ignore' if it is to be ignored, and nil if there is
1165 ;; no match for the group.
1167 ;; First we check the two user variables.
1169 ((and gnus-options-subscribe
1170 (string-match gnus-options-subscribe group))
1172 ((and gnus-auto-subscribed-groups
1173 (string-match gnus-auto-subscribed-groups group))
1175 ((and gnus-options-not-subscribe
1176 (string-match gnus-options-not-subscribe group))
1178 ;; Then we go through the list that was retrieved from the .newsrc
1179 ;; file. This list has elements on the form
1180 ;; `(REGEXP . {ignore,subscribe})'. The first match found (the list
1181 ;; is in the reverse order of the options line) is returned.
1183 (let ((regs gnus-newsrc-options-n))
1185 (not (string-match (caar regs) group)))
1186 (setq regs (cdr regs)))
1187 (and regs (cdar regs))))))
1189 (defun gnus-ask-server-for-new-groups ()
1190 (let* ((new-date (message-make-date))
1191 (date (or gnus-newsrc-last-checked-date new-date))
1192 (methods (cons gnus-select-method
1194 (when (gnus-archive-server-wanted-p)
1197 (and (consp gnus-check-new-newsgroups)
1198 gnus-check-new-newsgroups)
1199 gnus-secondary-select-methods))))
1201 group new-newsgroups got-new method hashtb
1202 gnus-override-subscribe-method)
1203 (unless gnus-killed-hashtb
1204 (gnus-make-hashtable-from-killed))
1205 ;; Go through both primary and secondary select methods and
1206 ;; request new newsgroups.
1207 (while (setq method (gnus-server-get-method nil (pop methods)))
1208 (setq new-newsgroups nil
1209 gnus-override-subscribe-method method)
1210 (when (and (gnus-check-server method)
1211 (gnus-request-newgroups date method))
1214 hashtb (gnus-make-hashtable 100))
1215 (set-buffer nntp-server-buffer)
1216 ;; Enter all the new groups into a hashtable.
1217 (gnus-active-to-gnus-format method hashtb 'ignore))
1218 ;; Now all new groups from `method' are in `hashtb'.
1221 (if (or (null (setq group (symbol-name group-sym)))
1222 (not (boundp group-sym))
1223 (null (symbol-value group-sym))
1224 (gnus-gethash group gnus-newsrc-hashtb)
1225 (member group gnus-zombie-list)
1226 (member group gnus-killed-list))
1227 ;; The group is already known.
1229 ;; Make this group active.
1230 (when (symbol-value group-sym)
1231 (gnus-set-active group (symbol-value group-sym)))
1232 ;; Check whether we want it or not.
1233 (let ((do-sub (gnus-matches-options-n group)))
1235 ((eq do-sub 'subscribe)
1237 (gnus-sethash group group gnus-killed-hashtb)
1238 (gnus-call-subscribe-functions
1239 gnus-subscribe-options-newsgroup-method group))
1240 ((eq do-sub 'ignore)
1244 (gnus-sethash group group gnus-killed-hashtb)
1245 (if gnus-subscribe-hierarchical-interactive
1246 (push group new-newsgroups)
1247 (gnus-call-subscribe-functions
1248 gnus-subscribe-newsgroup-method group)))))))
1250 (when new-newsgroups
1251 (gnus-subscribe-hierarchical-interactive new-newsgroups)))
1253 (gnus-message 5 "%d new newsgroup%s arrived"
1254 groups (if (> groups 1) "s have" " has"))
1255 (gnus-message 5 "No new newsgroups"))
1257 (setq gnus-newsrc-last-checked-date new-date))
1260 (defun gnus-check-first-time-used ()
1262 ;; First check if any of the following files exist. If they do,
1263 ;; it's not the first time the user has used Gnus.
1264 (dolist (file (list (concat gnus-current-startup-file ".el")
1265 (concat gnus-current-startup-file ".eld")
1266 (concat gnus-startup-file ".el")
1267 (concat gnus-startup-file ".eld")))
1268 (when (file-exists-p file)
1269 (throw 'ended nil)))
1270 (gnus-message 6 "First time user; subscribing you to default groups")
1271 (unless (gnus-read-active-file-p)
1272 (let ((gnus-read-active-file t))
1273 (gnus-read-active-file)))
1274 (setq gnus-newsrc-last-checked-date (message-make-date))
1275 ;; Subscribe to the default newsgroups.
1276 (let ((groups (or gnus-default-subscribed-newsgroups
1277 gnus-backup-default-subscribed-newsgroups))
1280 ;; If t, we subscribe (or not) all groups as if they were new.
1283 (when (setq group (symbol-name sym))
1284 (let ((do-sub (gnus-matches-options-n group)))
1286 ((eq do-sub 'subscribe)
1287 (gnus-sethash group group gnus-killed-hashtb)
1288 (gnus-call-subscribe-functions
1289 gnus-subscribe-options-newsgroup-method group))
1290 ((eq do-sub 'ignore)
1293 (push group gnus-killed-list))))))
1295 (dolist (group groups)
1296 ;; Only subscribe the default groups that are activated.
1297 (when (gnus-active group)
1298 (gnus-group-change-level
1299 group gnus-level-default-subscribed gnus-level-killed)))
1301 (set-buffer gnus-group-buffer)
1302 ;; Don't error if the group already exists. This happens when a
1303 ;; first-time user types 'F'. -- didier
1304 (gnus-group-make-help-group t))
1305 (when gnus-novice-user
1306 (gnus-message 7 "`A k' to list killed groups"))))))
1308 (defun gnus-subscribe-group (group &optional previous method)
1309 "Subscribe GROUP and put it after PREVIOUS."
1310 (gnus-group-change-level
1312 (list t group gnus-level-default-subscribed nil nil method)
1314 gnus-level-default-subscribed gnus-level-killed previous t)
1317 ;; `gnus-group-change-level' is the fundamental function for changing
1318 ;; subscription levels of newsgroups. This might mean just changing
1319 ;; from level 1 to 2, which is pretty trivial, from 2 to 6 or back
1320 ;; again, which subscribes/unsubscribes a group, which is equally
1321 ;; trivial. Changing from 1-7 to 8-9 means that you kill a group, and
1322 ;; from 8-9 to 1-7 means that you remove the group from the list of
1323 ;; killed (or zombie) groups and add them to the (kinda) subscribed
1324 ;; groups. And last but not least, moving from 8 to 9 and 9 to 8,
1325 ;; which is trivial.
1326 ;; ENTRY can either be a string (newsgroup name) or a list (if
1327 ;; FROMKILLED is t, it's a list on the format (NUM INFO-LIST),
1328 ;; otherwise it's a list in the format of the `gnus-newsrc-hashtb'
1330 ;; LEVEL is the new level of the group, OLDLEVEL is the old level and
1331 ;; PREVIOUS is the group (in hashtb entry format) to insert this group
1333 (defun gnus-group-change-level (entry level &optional oldlevel
1334 previous fromkilled)
1335 (let (group info active num)
1336 ;; Glean what info we can from the arguments
1338 (if fromkilled (setq group (nth 1 entry))
1339 (setq group (car (nth 2 entry))))
1341 (when (and (stringp entry)
1343 (< oldlevel gnus-level-zombie))
1344 (setq entry (gnus-group-entry entry)))
1345 (if (and (not oldlevel)
1347 (setq oldlevel (gnus-info-level (nth 2 entry)))
1348 (setq oldlevel (or oldlevel gnus-level-killed)))
1349 (when (stringp previous)
1350 (setq previous (gnus-group-entry previous)))
1352 (if (and (>= oldlevel gnus-level-zombie)
1353 (gnus-group-entry group))
1354 ;; We are trying to subscribe a group that is already
1358 (unless (gnus-ephemeral-group-p group)
1360 (format "(gnus-group-change-level %S %S %S %S %S)"
1361 group level oldlevel (car (nth 2 previous)) fromkilled)))
1363 ;; Then we remove the newgroup from any old structures, if needed.
1364 ;; If the group was killed, we remove it from the killed or zombie
1365 ;; list. If not, and it is in fact going to be killed, we remove
1366 ;; it from the newsrc hash table and assoc.
1368 ((>= oldlevel gnus-level-zombie)
1369 ;; oldlevel could be wrong.
1370 (setq gnus-zombie-list (delete group gnus-zombie-list))
1371 (setq gnus-killed-list (delete group gnus-killed-list)))
1373 (when (and (>= level gnus-level-zombie)
1375 (gnus-sethash (car (nth 2 entry)) nil gnus-newsrc-hashtb)
1377 (setcdr (gnus-group-entry (car (nth 3 entry)))
1379 (setcdr (cdr entry) (cdddr entry)))))
1381 ;; Finally we enter (if needed) the list where it is supposed to
1382 ;; go, and change the subscription level. If it is to be killed,
1383 ;; we enter it into the killed or zombie list.
1385 ((>= level gnus-level-zombie)
1386 ;; Remove from the hash table.
1387 (gnus-sethash group nil gnus-newsrc-hashtb)
1388 ;; We do not enter foreign groups into the list of dead
1390 (unless (gnus-group-foreign-p group)
1391 (if (= level gnus-level-zombie)
1392 (push group gnus-zombie-list)
1393 (if (= oldlevel gnus-level-killed)
1394 ;; Remove from active hashtb.
1395 (unintern group gnus-active-hashtb)
1396 ;; Don't add it into killed-list if it was killed.
1397 (push group gnus-killed-list)))))
1399 ;; If the list is to be entered into the newsrc assoc, and
1400 ;; it was killed, we have to create an entry in the newsrc
1401 ;; hashtb format and fix the pointers in the newsrc assoc.
1402 (if (< oldlevel gnus-level-zombie)
1403 ;; It was alive, and it is going to stay alive, so we
1404 ;; just change the level and don't change any pointers or
1405 ;; hash table entries.
1406 (setcar (cdaddr entry) level)
1408 (setq info (cdr entry)
1410 (setq active (gnus-active group))
1412 (if active (- (1+ (cdr active)) (car active)) t))
1413 ;; Shorten the select method if possible, if we need to
1414 ;; store it at all (native groups).
1415 (let ((method (gnus-method-simplify
1416 (or gnus-override-subscribe-method
1417 (gnus-group-method group)))))
1419 (setq info (list group level nil nil method))
1420 (setq info (list group level nil)))))
1423 (let ((p gnus-newsrc-alist))
1427 (setq entry (cons info (cddr previous)))
1430 (setcdr (cdr previous) entry)
1431 (gnus-sethash group (cons num (cdr previous))
1432 gnus-newsrc-hashtb))
1433 (setcdr previous entry)
1434 (gnus-sethash group (cons num previous)
1435 gnus-newsrc-hashtb))
1437 (setcdr (gnus-group-entry (caadr entry)) entry))
1440 "(gnus-group-set-info '%S)" info)))))
1441 (when gnus-group-change-level-function
1442 (funcall gnus-group-change-level-function
1443 group level oldlevel previous)))))
1445 (defun gnus-kill-newsgroup (newsgroup)
1446 "Obsolete function. Kills a newsgroup."
1447 (gnus-group-change-level
1448 (gnus-group-entry newsgroup) gnus-level-killed))
1450 (defun gnus-check-bogus-newsgroups (&optional confirm)
1451 "Remove bogus newsgroups.
1452 If CONFIRM is non-nil, the user has to confirm the deletion of every
1454 (let ((newsrc (cdr gnus-newsrc-alist))
1455 bogus group entry info)
1456 (gnus-message 5 "Checking bogus newsgroups...")
1457 (unless (gnus-read-active-file-p)
1458 (gnus-read-active-file t))
1459 (when (gnus-read-active-file-p)
1460 ;; Find all bogus newsgroup that are subscribed.
1462 (setq info (pop newsrc)
1463 group (gnus-info-group info))
1464 (unless (or (gnus-active group) ; Active
1465 (and (gnus-info-method info)
1466 (not (gnus-secondary-method-p
1467 (gnus-info-method info))))) ; Foreign
1468 ;; Found a bogus newsgroup.
1469 (push group bogus)))
1472 "Remove bogus group %s? "
1474 ;; Remove all bogus subscribed groups by first killing them, and
1475 ;; then removing them from the list of killed groups.
1476 (when (setq entry (gnus-group-entry group))
1477 (gnus-group-change-level entry gnus-level-killed)
1478 (setq gnus-killed-list (delete group gnus-killed-list))))
1479 bogus '("group" "groups" "remove"))
1480 (while (setq group (pop bogus))
1481 ;; Remove all bogus subscribed groups by first killing them, and
1482 ;; then removing them from the list of killed groups.
1483 (when (setq entry (gnus-group-entry group))
1484 (gnus-group-change-level entry gnus-level-killed)
1485 (setq gnus-killed-list (delete group gnus-killed-list)))))
1486 ;; Then we remove all bogus groups from the list of killed and
1487 ;; zombie groups. They are removed without confirmation.
1488 (let ((dead-lists '(gnus-killed-list gnus-zombie-list))
1491 (setq killed (symbol-value (car dead-lists)))
1493 (unless (gnus-active (setq group (pop killed)))
1494 ;; The group is bogus.
1496 (set (car dead-lists)
1497 (delete group (symbol-value (car dead-lists))))))
1498 (setq dead-lists (cdr dead-lists))))
1499 (gnus-run-hooks 'gnus-check-bogus-groups-hook)
1500 (gnus-message 5 "Checking bogus newsgroups...done"))))
1502 (defun gnus-check-duplicate-killed-groups ()
1503 "Remove duplicates from the list of killed groups."
1505 (let ((killed gnus-killed-list))
1507 (gnus-message 9 "%d" (length killed))
1508 (setcdr killed (delete (car killed) (cdr killed)))
1509 (setq killed (cdr killed)))))
1511 ;; We want to inline a function from gnus-cache, so we cheat here:
1513 (defvar gnus-cache-active-hashtb)
1514 (defun gnus-cache-possibly-alter-active (group active)
1515 "Alter the ACTIVE info for GROUP to reflect the articles in the cache."
1516 (when gnus-cache-active-hashtb
1517 (let ((cache-active (gnus-gethash group gnus-cache-active-hashtb)))
1519 (when (< (car cache-active) (car active))
1520 (setcar active (car cache-active)))
1521 (when (> (cdr cache-active) (cdr active))
1522 (setcdr active (cdr cache-active))))))))
1524 (defun gnus-activate-group (group &optional scan dont-check method)
1525 "Check whether a group has been activated or not.
1526 If SCAN, request a scan of that group as well."
1527 (let ((method (or method (inline (gnus-find-method-for-group group))))
1529 (and (inline (gnus-check-server method))
1530 ;; We escape all bugs and quit here to make it possible to
1531 ;; continue if a group is so out-there that it reports bugs
1535 (gnus-check-backend-function 'request-scan (car method))
1536 (gnus-request-scan group method))
1538 (if (or debug-on-error debug-on-quit)
1539 (inline (gnus-request-group group dont-check method))
1541 (inline (gnus-request-group group dont-check method))
1544 (message "Quit activating %s" group)
1547 (setq active (gnus-parse-active))
1548 ;; If there are no articles in the group, the GROUP
1549 ;; command may have responded with the `(0 . 0)'. We
1550 ;; ignore this if we already have an active entry
1552 (if (and (zerop (car active))
1553 (zerop (cdr active))
1554 (gnus-active group))
1557 ;; If a cache is present, we may have to alter the active info.
1558 (when gnus-use-cache
1559 (inline (gnus-cache-possibly-alter-active
1562 ;; If the agent is enabled, we may have to alter the active info.
1564 (gnus-agent-possibly-alter-active group active))
1566 (gnus-set-active group active)
1567 ;; Return the new active info.
1570 (defun gnus-get-unread-articles-in-group (info active &optional update)
1571 (when (and info active)
1572 ;; Allow the backend to update the info in the group.
1574 (gnus-request-update-info
1575 info (inline (gnus-find-method-for-group
1576 (gnus-info-group info)))))
1577 (gnus-activate-group (gnus-info-group info) nil t))
1579 (let* ((range (gnus-info-read info))
1582 ;; These checks are present in gnus-activate-group but skipped
1583 ;; due to setting dont-check in the preceeding call.
1585 ;; If a cache is present, we may have to alter the active info.
1586 (when (and gnus-use-cache info)
1587 (inline (gnus-cache-possibly-alter-active
1588 (gnus-info-group info) active)))
1590 ;; If the agent is enabled, we may have to alter the active info.
1591 (when (and gnus-agent info)
1592 (gnus-agent-possibly-alter-active (gnus-info-group info) active info))
1594 ;; Modify the list of read articles according to what articles
1595 ;; are available; then tally the unread articles and add the
1596 ;; number to the group hash table entry.
1598 ((zerop (cdr active))
1601 (setq num (- (1+ (cdr active)) (car active))))
1602 ((not (listp (cdr range)))
1603 ;; Fix a single (num . num) range according to the
1604 ;; active hash table.
1605 ;; Fix by Carsten Bormann <cabo@Informatik.Uni-Bremen.DE>.
1606 (and (< (cdr range) (car active)) (setcdr range (1- (car active))))
1607 (and (> (cdr range) (cdr active)) (setcdr range (cdr active)))
1608 ;; Compute number of unread articles.
1609 (setq num (max 0 (- (cdr active) (- (1+ (cdr range)) (car range))))))
1611 ;; The read list is a list of ranges. Fix them according to
1612 ;; the active hash table.
1613 ;; First peel off any elements that are below the lower
1615 (while (and (cdr range)
1617 (or (and (atom (cadr range)) (cadr range))
1619 (if (numberp (car range))
1622 (or (and (numberp (cadr range))
1626 (or (and (numberp (nth 1 range)) (nth 1 range))
1628 (setcdr range (cddr range)))
1629 ;; Adjust the first element to be the same as the lower limit.
1630 (when (and (not (atom (car range)))
1631 (< (cdar range) (car active)))
1632 (setcdr (car range) (1- (car active))))
1633 ;; Then we want to peel off any elements that are higher
1634 ;; than the upper active limit.
1635 (let ((srange range))
1636 ;; Go past all valid elements.
1637 (while (and (cdr srange)
1638 (<= (or (and (atom (cadr srange))
1642 (setq srange (cdr srange)))
1644 ;; Nuke all remaining invalid elements.
1645 (setcdr srange nil))
1647 ;; Adjust the final element.
1648 (when (and (not (atom (car srange)))
1649 (> (cdar srange) (cdr active)))
1650 (setcdr (car srange) (cdr active))))
1651 ;; Compute the number of unread articles.
1653 (setq num (+ num (- (1+ (or (and (atom (car range)) (car range))
1655 (or (and (atom (car range)) (car range))
1657 (setq range (cdr range)))
1658 (setq num (max 0 (- (cdr active) num)))))
1659 ;; Set the number of unread articles.
1661 (gnus-group-entry (gnus-info-group info)))
1662 (setcar (gnus-group-entry (gnus-info-group info)) num))
1665 ;; Go though `gnus-newsrc-alist' and compare with `gnus-active-hashtb'
1666 ;; and compute how many unread articles there are in each group.
1667 (defun gnus-get-unread-articles (&optional level)
1668 (setq gnus-server-method-cache nil)
1669 (let* ((newsrc (cdr gnus-newsrc-alist))
1670 (level (or level gnus-activate-level (1+ gnus-level-subscribed)))
1673 (cond ((and gnus-activate-foreign-newsgroups
1674 (not (numberp gnus-activate-foreign-newsgroups)))
1675 (1+ gnus-level-subscribed))
1676 ((numberp gnus-activate-foreign-newsgroups)
1677 gnus-activate-foreign-newsgroups)
1682 scanned-methods info group active method retrieve-groups cmethod
1684 (gnus-message 6 "Checking new news...")
1687 (setq active (gnus-active (setq group (gnus-info-group
1688 (setq info (pop newsrc))))))
1690 ;; Check newsgroups. If the user doesn't want to check them, or
1691 ;; they can't be checked (for instance, if the news server can't
1692 ;; be reached) we just set the number of unread articles in this
1693 ;; newsgroup to t. This means that Gnus thinks that there are
1694 ;; unread articles, but it has no idea how many.
1696 ;; To be more explicit:
1697 ;; >0 for an active group with messages
1698 ;; 0 for an active group with no unread messages
1699 ;; nil for non-foreign groups that the user has requested not be checked
1700 ;; t for unchecked foreign groups or bogus groups, or groups that can't
1701 ;; be checked, for one reason or other.
1702 (when (setq method (gnus-info-method info))
1703 (if (setq cmethod (assoc method methods-cache))
1704 (setq method (cdr cmethod))
1705 (setq cmethod (inline (gnus-server-get-method nil method)))
1706 (push (cons method cmethod) methods-cache)
1707 (setq method cmethod)))
1709 (not (setq method-type (cdr (assoc method type-cache)))))
1712 ((gnus-secondary-method-p method)
1714 ((inline (gnus-server-equal gnus-select-method method))
1718 (push (cons method method-type) type-cache))
1721 (cond ((and method (eq method-type 'foreign))
1722 ;; These groups are foreign. Check the level.
1723 (if (<= (gnus-info-level info) foreign-level)
1724 (when (setq active (gnus-activate-group group 'scan))
1725 ;; Let the Gnus agent save the active file.
1726 (when (and gnus-agent active (gnus-online method))
1727 (gnus-agent-save-group-info
1728 method (gnus-group-real-name group) active))
1729 (unless (inline (gnus-virtual-group-p group))
1730 (inline (gnus-close-group group)))
1731 (when (fboundp (intern (concat (symbol-name (car method))
1732 "-request-update-info")))
1733 (inline (gnus-request-update-info info method))))
1735 ;; These groups are native or secondary.
1736 ((> (gnus-info-level info) level)
1737 ;; We don't want these groups.
1738 (setq active 'ignore))
1740 ((not gnus-read-active-file)
1741 (if (gnus-check-backend-function 'retrieve-groups group)
1742 ;; if server support gnus-retrieve-groups we push
1743 ;; the group onto retrievegroups for later checking
1744 (if (assoc method retrieve-groups)
1745 (setcdr (assoc method retrieve-groups)
1746 (cons group (cdr (assoc method retrieve-groups))))
1747 (push (list method group) retrieve-groups))
1748 ;; hack: `nnmail-get-new-mail' changes the mail-source depending
1749 ;; on the group, so we must perform a scan for every group
1750 ;; if the users has any directory mail sources.
1751 ;; hack: if `nnmail-scan-directory-mail-source-once' is non-nil,
1752 ;; for it scan all spool files even when the groups are
1755 (or nnmail-scan-directory-mail-source-once
1756 (null (assq 'directory
1758 (if (listp nnmail-spool-file)
1760 (list nnmail-spool-file))))))
1761 (member method scanned-methods))
1762 (setq active (gnus-activate-group group))
1763 (setq active (gnus-activate-group group 'scan))
1764 (push method scanned-methods))
1766 (gnus-close-group group)))))
1768 ;; Get the number of unread articles in the group.
1770 ((eq active 'ignore)
1771 ;; Don't do anything.
1773 ((and active ignore)
1774 ;; The level of the foreign group is higher than the specified
1778 (inline (gnus-get-unread-articles-in-group info active t)))
1780 ;; The group couldn't be reached, so we nix out the number of
1781 ;; unread articles and stuff.
1782 (gnus-set-active group nil)
1783 (let ((tmp (gnus-group-entry group)))
1787 ;; iterate through groups on methods which support gnus-retrieve-groups
1788 ;; and fetch a partial active file and use it to find new news.
1789 (dolist (rg retrieve-groups)
1790 (let ((method (or (car rg) gnus-select-method))
1792 (when (gnus-check-server method)
1793 ;; Request that the backend scan its incoming messages.
1794 (when (gnus-check-backend-function 'request-scan (car method))
1795 (gnus-request-scan nil method))
1796 (gnus-read-active-file-2
1797 (mapcar (lambda (group) (gnus-group-real-name group)) groups)
1799 (dolist (group groups)
1801 ((setq active (gnus-active (gnus-info-group
1802 (setq info (gnus-get-info group)))))
1803 (inline (gnus-get-unread-articles-in-group info active t)))
1805 ;; The group couldn't be reached, so we nix out the number of
1806 ;; unread articles and stuff.
1807 (gnus-set-active group nil)
1808 (setcar (gnus-group-entry group) t)))))))
1810 (gnus-message 6 "Checking new news...done")))
1812 ;; Create a hash table out of the newsrc alist. The `car's of the
1813 ;; alist elements are used as keys.
1814 (defun gnus-make-hashtable-from-newsrc-alist ()
1815 (let ((alist gnus-newsrc-alist)
1816 (ohashtb gnus-newsrc-hashtb)
1817 prev info method rest methods)
1818 (setq gnus-newsrc-hashtb (gnus-make-hashtable (length alist)))
1820 (setq prev (setq gnus-newsrc-alist
1821 (if (equal (caar gnus-newsrc-alist)
1824 (cons (list "dummy.group" 0 nil) alist)))))
1826 (setq info (car alist))
1827 ;; Make the same select-methods identical Lisp objects.
1828 (when (setq method (gnus-info-method info))
1829 (if (setq rest (member method methods))
1830 (gnus-info-set-method info (car rest))
1831 (push method methods)))
1834 ;; Preserve number of unread articles in groups.
1835 (cons (and ohashtb (car (gnus-gethash (car info) ohashtb)))
1840 ;; Make the same select-methods in `gnus-server-alist' identical
1843 (setq method (pop methods))
1844 (when (setq rest (rassoc method gnus-server-alist))
1845 (setcdr rest method)))))
1847 (defun gnus-make-hashtable-from-killed ()
1848 "Create a hash table from the killed and zombie lists."
1849 (let ((lists '(gnus-killed-list gnus-zombie-list))
1851 (setq gnus-killed-hashtb
1852 (gnus-make-hashtable
1853 (+ (length gnus-killed-list) (length gnus-zombie-list))))
1855 (setq list (symbol-value (pop lists)))
1857 (gnus-sethash (car list) (pop list) gnus-killed-hashtb)))))
1859 (defun gnus-parse-active ()
1860 "Parse active info in the nntp server buffer."
1862 (set-buffer nntp-server-buffer)
1863 (goto-char (point-min))
1864 ;; Parse the result we got from `gnus-request-group'.
1865 (when (looking-at "[0-9]+ [0-9]+ \\([0-9]+\\) [0-9]+")
1866 (goto-char (match-beginning 1))
1867 (cons (read (current-buffer))
1868 (read (current-buffer))))))
1870 (defun gnus-make-articles-unread (group articles)
1871 "Mark ARTICLES in GROUP as unread."
1872 (let* ((info (nth 2 (or (gnus-group-entry group)
1874 (gnus-group-real-name group)))))
1875 (ranges (gnus-info-read info))
1878 (when (gnus-member-of-range
1879 (setq article (pop articles)) ranges)
1880 (push article news)))
1882 ;; Enter this list into the group info.
1884 info (gnus-remove-from-range (gnus-info-read info) (nreverse news)))
1886 ;; Set the number of unread articles in gnus-newsrc-hashtb.
1887 (gnus-get-unread-articles-in-group info (gnus-active group))
1889 ;; Insert the change into the group buffer and the dribble file.
1890 (gnus-group-update-group group t))))
1892 (defun gnus-make-ascending-articles-unread (group articles)
1893 "Mark ascending ARTICLES in GROUP as unread."
1894 (let* ((entry (or (gnus-group-entry group)
1895 (gnus-group-entry (gnus-group-real-name group))))
1896 (info (nth 2 entry))
1897 (ranges (gnus-info-read info))
1902 (let ((article (pop articles))) ; get the next article to remove from ranges
1903 (while (let ((range (car ranges))) ; note the current range
1904 (if (atom range) ; single value range
1906 ;; the articles extend past the end of the ranges
1908 (setq articles nil))
1910 ;; this range preceeds the article. Leave the range unmodified.
1914 ;; this range exactly matches the article; REMOVE THE RANGE.
1915 ;; NOTE: When the range being removed is the last range, the list is corrupted by inserting null at its end.
1916 (setcar ranges (cadr ranges))
1917 (setcdr ranges (cddr ranges))
1918 (setq modified (if (car ranges) t 'remove-null))
1920 (let ((min (car range))
1922 ;; I have a min/max range to consider
1923 (cond ((> min max) ; invalid range introduced by splitter
1924 (setcar ranges (cadr ranges))
1925 (setcdr ranges (cddr ranges))
1926 (setq modified (if (car ranges) t 'remove-null))
1929 ;; replace min/max range with a single-value range
1933 ;; this range preceeds the article. Leave the range unmodified.
1937 ;; this article preceeds the range. Return null to move to the
1941 ;; this article splits the range into two parts
1942 (setcdr ranges (cons (cons (1+ article) max) (cdr ranges)))
1943 (setcdr range (1- article))
1948 (when (eq modified 'remove-null)
1949 (setq r (delq nil r)))
1950 ;; Enter this list into the group info.
1951 (gnus-info-set-read info r)
1953 ;; Set the number of unread articles in gnus-newsrc-hashtb.
1954 (gnus-get-unread-articles-in-group info (gnus-active group))
1956 ;; Insert the change into the group buffer and the dribble file.
1957 (gnus-group-update-group group t))))
1959 ;; Enter all dead groups into the hashtb.
1960 (defun gnus-update-active-hashtb-from-killed ()
1961 (let ((hashtb (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
1962 (lists (list gnus-killed-list gnus-zombie-list))
1965 (setq killed (car lists))
1967 (gnus-sethash (car killed) nil hashtb)
1968 (setq killed (cdr killed)))
1969 (setq lists (cdr lists)))))
1971 (defun gnus-get-killed-groups ()
1972 "Go through the active hashtb and mark all unknown groups as killed."
1973 ;; First make sure active file has been read.
1974 (unless (gnus-read-active-file-p)
1975 (let ((gnus-read-active-file t))
1976 (gnus-read-active-file)))
1977 (unless gnus-killed-hashtb
1978 (gnus-make-hashtable-from-killed))
1979 ;; Go through all newsgroups that are known to Gnus - enlarge kill list.
1983 (group (symbol-name sym)))
1984 (if (or (null group)
1985 (gnus-gethash group gnus-killed-hashtb)
1986 (gnus-gethash group gnus-newsrc-hashtb))
1988 (let ((do-sub (gnus-matches-options-n group)))
1989 (if (or (eq do-sub 'subscribe) (eq do-sub 'ignore))
1991 (setq groups (1+ groups))
1992 (push group gnus-killed-list)
1993 (gnus-sethash group group gnus-killed-hashtb))))))
1995 (gnus-dribble-touch))
1997 ;; Get the active file(s) from the backend(s).
1998 (defun gnus-read-active-file (&optional force not-native)
1999 (gnus-group-set-mode-line)
2002 (lambda (m) (if (stringp m) (gnus-server-get-method nil m) m))
2004 (if (and (not not-native)
2005 (gnus-check-server gnus-select-method))
2006 ;; The native server is available.
2007 (cons gnus-select-method gnus-secondary-select-methods)
2008 ;; The native server is down, so we just do the
2010 gnus-secondary-select-methods)
2011 ;; Also read from the archive server.
2012 (when (gnus-archive-server-wanted-p)
2013 (list "archive")))))
2015 (setq gnus-have-read-active-file nil)
2017 (set-buffer nntp-server-buffer)
2018 (while (setq method (pop methods))
2019 ;; Only do each method once, in case the methods appear more
2020 ;; than once in this list.
2021 (unless (member method methods)
2022 (if (or debug-on-error debug-on-quit)
2023 (gnus-read-active-file-1 method force)
2025 (gnus-read-active-file-1 method force)
2026 ;; We catch C-g so that we can continue past servers
2027 ;; that do not respond.
2029 (message "Quit reading the active file")
2032 (defun gnus-read-active-file-1 (method force)
2034 (setq where (nth 1 method)
2035 mesg (format "Reading active file%s via %s..."
2036 (if (and where (not (zerop (length where))))
2037 (concat " from " where) "")
2039 (gnus-message 5 mesg)
2040 (when (gnus-check-server method)
2041 ;; Request that the backend scan its incoming messages.
2042 (when (gnus-check-backend-function 'request-scan (car method))
2043 (gnus-request-scan nil method))
2045 ((and (eq gnus-read-active-file 'some)
2046 (gnus-check-backend-function 'retrieve-groups (car method))
2048 (let ((newsrc (cdr gnus-newsrc-alist))
2049 (gmethod (gnus-server-get-method nil method))
2051 (while (setq info (pop newsrc))
2055 (gnus-find-method-for-group
2056 (gnus-info-group info) info))
2058 (push (gnus-group-real-name (gnus-info-group info))
2060 (gnus-read-active-file-2 groups method)))
2064 (if (not (gnus-request-list method))
2065 (unless (equal method gnus-message-archive-method)
2066 (gnus-error 1 "Cannot read active file from %s server"
2068 (gnus-message 5 mesg)
2069 (gnus-active-to-gnus-format method gnus-active-hashtb nil t)
2070 ;; We mark this active file as read.
2071 (push method gnus-have-read-active-file)
2072 (gnus-message 5 "%sdone" mesg)))))))
2074 (defun gnus-read-active-file-2 (groups method)
2075 "Read an active file for GROUPS in METHOD using `gnus-retrieve-groups'."
2078 (set-buffer nntp-server-buffer)
2079 (gnus-check-server method)
2080 (let ((list-type (gnus-retrieve-groups groups method)))
2081 (cond ((not list-type)
2083 1.2 "Cannot read partial active file from %s server."
2085 ((eq list-type 'active)
2086 (gnus-active-to-gnus-format method gnus-active-hashtb nil t))
2088 (gnus-groups-to-gnus-format method gnus-active-hashtb t)))))))
2090 ;; Read an active file and place the results in `gnus-active-hashtb'.
2091 (defun gnus-active-to-gnus-format (&optional method hashtb ignore-errors
2094 (setq method gnus-select-method))
2095 (let ((cur (current-buffer))
2097 (if (and gnus-active-hashtb
2098 (not (equal method gnus-select-method)))
2100 (setq gnus-active-hashtb
2101 (if (equal method gnus-select-method)
2102 (gnus-make-hashtable
2103 (count-lines (point-min) (point-max)))
2104 (gnus-make-hashtable 4096)))))))
2105 ;; Delete unnecessary lines.
2106 (goto-char (point-min))
2108 ((string= gnus-ignored-newsgroups "")
2109 (delete-matching-lines "^to\\."))
2111 (delete-matching-lines (concat "^to\\.\\|" gnus-ignored-newsgroups))))
2113 (goto-char (point-min))
2114 (unless (re-search-forward "[\\\"]" nil t)
2115 ;; Make the group names readable as a lisp expression even if they
2116 ;; contain special characters.
2117 (goto-char (point-max))
2118 (while (re-search-backward "[][';?()#]" nil t)
2121 ;; Let the Gnus agent save the active file.
2122 (when (and gnus-agent real-active (gnus-online method))
2123 (gnus-agent-save-active method))
2125 ;; If these are groups from a foreign select method, we insert the
2126 ;; group prefix in front of the group names.
2127 (when (not (gnus-server-equal
2128 (gnus-server-get-method nil method)
2129 (gnus-server-get-method nil gnus-select-method)))
2130 (let ((prefix (gnus-group-prefixed-name "" method)))
2131 (goto-char (point-min))
2132 (while (and (not (eobp))
2134 (when (= (following-char) ?\")
2137 (zerop (forward-line 1)))))))
2138 ;; Store the active file in a hash table.
2139 (goto-char (point-min))
2140 (let (group max min)
2144 (narrow-to-region (point) (point-at-eol))
2145 ;; group gets set to a symbol interned in the hash table
2146 ;; (what a hack!!) - jwz
2147 (setq group (let ((obarray hashtb)) (read cur)))
2148 ;; ### The extended group name scheme makes
2149 ;; the previous optimization strategy sort of pointless...
2150 (when (stringp group)
2151 (setq group (intern group hashtb)))
2152 (if (and (numberp (setq max (read cur)))
2153 (numberp (setq min (read cur)))
2155 (skip-chars-forward " \t")
2157 (or (eq (char-after) ?=)
2158 (eq (char-after) ?x)
2159 (eq (char-after) ?j)))))
2161 (set group (cons min max))
2162 ;; if group is moderated, stick in moderation table
2163 (when (eq (char-after) ?m)
2164 (unless gnus-moderated-hashtb
2165 (setq gnus-moderated-hashtb (gnus-make-hashtable)))
2166 (gnus-sethash (symbol-name group) t
2167 gnus-moderated-hashtb)))
2173 (unless ignore-errors
2174 (gnus-message 3 "Warning - invalid active: %s"
2176 (point-at-bol) (point-at-eol))))))
2178 (forward-line 1)))))
2180 (defun gnus-groups-to-gnus-format (method &optional hashtb real-active)
2181 ;; Parse a "groups" active file.
2182 (let ((cur (current-buffer))
2184 (if (and method gnus-active-hashtb)
2186 (setq gnus-active-hashtb
2187 (gnus-make-hashtable
2188 (count-lines (point-min) (point-max)))))))
2190 (not (gnus-server-equal
2191 (gnus-server-get-method nil method)
2192 (gnus-server-get-method nil gnus-select-method)))
2193 (gnus-group-prefixed-name "" method))))
2195 ;; Let the Gnus agent save the active file.
2198 (gnus-online method)
2199 (gnus-agent-method-p method))
2201 (gnus-agent-save-active method)
2202 (gnus-active-to-gnus-format method hashtb nil real-active))
2204 (goto-char (point-min))
2205 ;; We split this into to separate loops, one with the prefix
2206 ;; and one without to speed the reading up somewhat.
2208 (let (min max opoint group)
2212 (read cur) (read cur)
2213 (setq min (read cur)
2216 (skip-chars-forward " \t")
2219 (set (let ((obarray hashtb)) (read cur))
2221 (error (and group (symbolp group) (set group nil))))
2223 (let (min max group)
2226 (when (eq (char-after) ?2)
2227 (read cur) (read cur)
2228 (setq min (read cur)
2230 (set (setq group (let ((obarray hashtb)) (read cur)))
2232 (error (and group (symbolp group) (set group nil))))
2233 (forward-line 1)))))))
2235 (defun gnus-read-newsrc-file (&optional force)
2237 If FORCE is non-nil, the .newsrc file is read."
2238 ;; Reset variables that might be defined in the .newsrc.eld file.
2239 (gnus-clear-quick-file-variables)
2240 (let* ((newsrc-file gnus-current-startup-file)
2241 (quick-file (concat newsrc-file ".el")))
2243 ;; We always load the .newsrc.eld file. If always contains
2244 ;; much information that can not be gotten from the .newsrc
2245 ;; file (ticked articles, killed groups, foreign methods, etc.)
2246 (gnus-read-newsrc-el-file quick-file)
2248 (when (and gnus-read-newsrc-file
2249 (file-exists-p gnus-current-startup-file)
2251 (and (file-newer-than-file-p newsrc-file quick-file)
2252 (file-newer-than-file-p newsrc-file
2253 (concat quick-file "d")))
2254 (not gnus-newsrc-alist)))
2255 ;; We read the .newsrc file. Note that if there if a
2256 ;; .newsrc.eld file exists, it has already been read, and
2257 ;; the `gnus-newsrc-hashtb' has been created. While reading
2258 ;; the .newsrc file, Gnus will only use the information it
2259 ;; can find there for changing the data already read -
2260 ;; i. e., reading the .newsrc file will not trash the data
2261 ;; already read (except for read articles).
2263 (gnus-message 5 "Reading %s..." newsrc-file)
2264 (set-buffer (nnheader-find-file-noselect newsrc-file))
2265 (buffer-disable-undo)
2266 (gnus-newsrc-to-gnus-format)
2267 (kill-buffer (current-buffer))
2268 (gnus-message 5 "Reading %s...done" newsrc-file))))))
2270 (quote (;; T-gnus doesn't provide those functions.
2271 (defun gnus-convert-old-newsrc ()
2272 "Convert old newsrc formats into the current format, if needed."
2273 (let ((fcv (and gnus-newsrc-file-version
2274 (gnus-continuum-version gnus-newsrc-file-version))))
2276 ;; A newsrc file was loaded.
2277 (let (prompt-displayed
2280 (mapcar (lambda (date-func)
2281 (cons (gnus-continuum-version (car date-func))
2283 ;; This is a list of converters that must be run
2284 ;; to bring the newsrc file up to the current
2285 ;; version. If you create an incompatibility
2286 ;; with older versions, you should create an
2287 ;; entry here. The entry should consist of the
2288 ;; current gnus version (hardcoded so that it
2289 ;; doesn't change with each release) and the
2290 ;; function that must be applied to convert the
2291 ;; previous version into the current version.
2292 '(("September Gnus v0.1" nil
2293 gnus-convert-old-ticks)
2294 ("Oort Gnus v0.08" "legacy-gnus-agent"
2295 gnus-agent-convert-to-compressed-agentview)
2296 ("Gnus v5.10.7" "legacy-gnus-agent"
2297 gnus-agent-unlist-expire-days)
2298 ("Gnus v5.10.7" "legacy-gnus-agent"
2299 gnus-agent-unhook-expire-days)))
2300 #'car-less-than-car)))
2301 ;; Skip converters older than the file version
2302 (while (and converters (>= fcv (caar converters)))
2305 ;; Perform converters to bring older version up to date.
2306 (when (and converters (< fcv (caar converters)))
2307 (while (and converters (< fcv (caar converters)))
2308 (let* ((converter-spec (pop converters))
2309 (convert-to (nth 1 converter-spec))
2310 (load-from (nth 2 converter-spec))
2311 (func (nth 3 converter-spec)))
2312 (when (and load-from
2313 (not (fboundp func)))
2315 (or prompt-displayed
2316 (not (gnus-convert-converter-needs-prompt func))
2318 (cursor-in-echo-area t)
2319 (echo-keystrokes 0))
2320 (message "Convert gnus from version '%s' to '%s'? (n/y/?)"
2321 gnus-newsrc-file-version gnus-version)
2322 (setq c (read-char-exclusive))
2324 (cond ((or (eq c ?n) (eq c ?N))
2325 (error "Can not start gnus without converting"))
2326 ((or (eq c ?y) (eq c ?Y))
2327 (setq prompt-displayed t)
2330 (message "This conversion is irreversible. \
2331 To be safe, you should backup your files before proceeding.")
2335 (gnus-message 3 "Ignoring unexpected input")
2339 (funcall func convert-to)))
2341 (format ";Converted gnus from version '%s' to '%s'."
2342 gnus-newsrc-file-version gnus-version)))))))
2344 (defun gnus-convert-mark-converter-prompt (converter no-prompt)
2345 "Indicate whether CONVERTER requires gnus-convert-old-newsrc to
2346 display the conversion prompt. NO-PROMPT may be nil (prompt),
2347 t (no prompt), or any form that can be called as a function.
2348 The form should return either t or nil."
2349 (put converter 'gnus-convert-no-prompt no-prompt))
2351 (defun gnus-convert-converter-needs-prompt (converter)
2352 (let ((no-prompt (get converter 'gnus-convert-no-prompt)))
2353 (not (if (memq no-prompt '(t nil))
2355 (funcall no-prompt)))))
2357 (defun gnus-convert-old-ticks (converting-to)
2358 (let ((newsrc (cdr gnus-newsrc-alist))
2359 marks info dormant ticked)
2360 (while (setq info (pop newsrc))
2361 (when (setq marks (gnus-info-marks info))
2362 (setq dormant (cdr (assq 'dormant marks))
2363 ticked (cdr (assq 'tick marks)))
2364 (when (or dormant ticked)
2368 (gnus-info-read info)
2369 (nconc (gnus-uncompress-range dormant)
2370 (gnus-uncompress-range ticked)))))))))
2373 (defun gnus-load (file &optional coding-system)
2374 "Load FILE, but in such a way that read errors can be reported."
2377 (insert-file-contents-as-coding-system coding-system file)
2378 (insert-file-contents file))
2380 (condition-case type
2381 (let ((form (read (current-buffer))))
2384 (unless (eq (car type) 'end-of-file)
2385 (let ((error (format "Error in %s line %d" file
2386 (count-lines (point-min) (point)))))
2388 (unless (gnus-yes-or-no-p (concat error "; continue? "))
2389 (error "%s" error)))))))))
2391 (defun gnus-read-newsrc-el-file (file)
2392 (let ((ding-file (concat file "d")))
2393 (when (file-exists-p ding-file)
2394 ;; We always, always read the .eld file.
2395 (gnus-message 5 "Reading %s..." ding-file)
2396 (let (gnus-newsrc-assoc)
2397 (gnus-load ding-file gnus-ding-file-coding-system)
2398 ;; ;; Older versions of `gnus-format-specs' are no longer valid
2399 ;; ;; in Oort Gnus 0.01.
2401 ;; (and gnus-newsrc-file-version
2402 ;; (gnus-continuum-version gnus-newsrc-file-version))))
2403 ;; (when (or (not version)
2404 ;; (< version 5.090009))
2405 ;; (setq gnus-format-specs gnus-default-format-specs)))
2406 (when gnus-newsrc-assoc
2407 (setq gnus-newsrc-alist gnus-newsrc-assoc))))
2408 (gnus-make-hashtable-from-newsrc-alist)
2409 (when (file-newer-than-file-p file ding-file)
2410 ;; Old format quick file
2411 (gnus-message 5 "Reading %s..." file)
2412 ;; The .el file is newer than the .eld file, so we read that one
2414 (gnus-read-old-newsrc-el-file file)))
2415 (when (and gnus-product-directory
2416 (file-directory-p gnus-product-directory))
2417 (let ((list gnus-product-variable-file-list))
2419 (apply 'gnus-product-read-variable-file-1 (car list))
2420 (setq list (cdr list)))))
2421 (gnus-run-hooks 'gnus-read-newsrc-el-hook))
2423 ;;(defun gnus-re-read-newsrc-el-file (file)
2424 ;; "Attempt to re-read .newsrc.eld file. Returns nil if successful.
2425 ;;The backup file \".newsrc.eld_\" will be created before re-reading."
2426 ;; (message "Error in %s; retrying..." file)
2428 ;; (condition-case nil
2429 ;; (let ((backup (concat file "_")))
2430 ;; (copy-file file backup 'ok-if-already-exists 'keep-time)
2431 ;; (message " (The backup file %s has been created)" backup)
2435 ;; (insert-file-contents-as-binary file nil nil nil 'replace)
2436 ;; (goto-char (point-min))
2437 ;; (when (re-search-forward
2438 ;; "^[\t ]*([\t\n\r ]*setq[\t\n\r ]+gnus-format-specs" nil t)
2439 ;; (delete-region (goto-char (match-beginning 0)) (forward-list 1))
2440 ;; (decode-coding-region (point-min) (point-max)
2441 ;; gnus-ding-file-coding-system)
2442 ;; (condition-case nil
2444 ;; (eval-region (point-min) (point-max))
2449 ;; (message "Error in %s; retrying...done" file))
2450 ;; (message "Error in %s; retrying...failed" file)
2453 (defun gnus-product-read-variable-file-1 (file checking-methods coding
2455 (let (error gnus-product-file-version method file-ver)
2456 (when (or (condition-case err
2457 (let ((coding-system-for-read coding))
2458 (load (expand-file-name file gnus-product-directory)
2462 (message "Error while reading %s: %s"
2463 (expand-file-name file gnus-product-directory)
2464 (error-message-string err))
2466 (and (setq method (assq 'product-version checking-methods))
2467 (not (and (setq file-ver
2468 (cdr (assq 'product-version
2469 gnus-product-file-version)))
2470 (zerop (product-version-compare file-ver
2472 (and (assq 'emacs-version checking-methods)
2473 (not (and (assq 'emacs-version gnus-product-file-version)
2476 (cdr (assq 'emacs-version
2477 gnus-product-file-version))))))
2478 (and (assq 'correct-string-widths checking-methods)
2479 (not (and (assq 'correct-string-widths
2480 gnus-product-file-version)
2481 (eq (and gnus-use-correct-string-widths t)
2482 (and (cdr (assq 'correct-string-widths
2483 gnus-product-file-version))
2486 (message "\"%s\" seems to have mismatched contents, updating..."
2489 (set (car variables) nil)
2490 (gnus-product-variable-touch (car variables))
2491 (setq variables (cdr variables))))))
2493 ;; Parse the old-style quick startup file
2494 (defun gnus-read-old-newsrc-el-file (file)
2495 (let (newsrc killed marked group m info)
2497 (let ((gnus-killed-assoc nil)
2498 gnus-marked-assoc gnus-newsrc-alist gnus-newsrc-assoc)
2502 (setq newsrc gnus-newsrc-assoc
2503 killed gnus-killed-assoc
2504 marked gnus-marked-assoc)))
2505 (setq gnus-newsrc-alist nil)
2506 (while (setq group (pop newsrc))
2507 (if (setq info (gnus-get-info (car group)))
2509 (gnus-info-set-read info (cddr group))
2510 (gnus-info-set-level
2511 info (if (nth 1 group) gnus-level-default-subscribed
2512 gnus-level-default-unsubscribed))
2513 (push info gnus-newsrc-alist))
2516 (if (nth 1 group) gnus-level-default-subscribed
2517 gnus-level-default-unsubscribed)
2520 ;; Copy marks into info.
2521 (when (setq m (assoc (car group) marked))
2522 (unless (nthcdr 3 info)
2523 (nconc info (list nil)))
2524 (gnus-info-set-marks
2525 info (list (cons 'tick (gnus-compress-sequence
2526 (sort (cdr m) '<) t))))))
2527 (setq newsrc killed)
2529 (setcar newsrc (caar newsrc))
2530 (setq newsrc (cdr newsrc)))
2531 (setq gnus-killed-list killed))
2532 ;; The .el file version of this variable does not begin with
2533 ;; "options", while the .eld version does, so we just add it if it
2537 (when (not (string-match "^ *options" gnus-newsrc-options))
2538 (setq gnus-newsrc-options (concat "options " gnus-newsrc-options)))
2539 (when (not (string-match "\n$" gnus-newsrc-options))
2540 (setq gnus-newsrc-options (concat gnus-newsrc-options "\n")))
2541 ;; Finally, if we read some options lines, we parse them.
2542 (unless (string= gnus-newsrc-options "")
2543 (gnus-newsrc-parse-options gnus-newsrc-options)))
2545 (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist))
2546 (gnus-make-hashtable-from-newsrc-alist)))
2548 (defun gnus-make-newsrc-file (file)
2549 "Make server dependent file name by catenating FILE and server host name."
2550 (let* ((file (expand-file-name file nil))
2551 (real-file (concat file "-" (nth 1 gnus-select-method))))
2552 (if (or (file-exists-p real-file)
2553 (file-exists-p (concat real-file ".el"))
2554 (file-exists-p (concat real-file ".eld")))
2558 (defun gnus-newsrc-to-gnus-format ()
2559 (setq gnus-newsrc-options "")
2560 (setq gnus-newsrc-options-n nil)
2562 (unless gnus-active-hashtb
2563 (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
2564 (let ((buf (current-buffer))
2565 (already-read (> (length gnus-newsrc-alist) 1))
2566 group subscribed options-symbol newsrc Options-symbol
2568 (goto-char (point-min))
2569 ;; We intern the symbol `options' in the active hashtb so that we
2570 ;; can `eq' against it later.
2571 (set (setq options-symbol (intern "options" gnus-active-hashtb)) nil)
2572 (set (setq Options-symbol (intern "Options" gnus-active-hashtb)) nil)
2575 ;; We first read the first word on the line by narrowing and
2576 ;; then reading into `gnus-active-hashtb'. Most groups will
2577 ;; already exist in that hashtb, so this will save some string
2581 (progn (skip-chars-forward "^ \t!:\n") (point)))
2582 (goto-char (point-min))
2584 (and (/= (point-min) (point-max))
2585 (let ((obarray gnus-active-hashtb)) (read buf))))
2587 ;; Now, the symbol we have read is either `options' or a group
2588 ;; name. If it is an options line, we just add it to a string.
2590 ((or (eq symbol options-symbol)
2591 (eq symbol Options-symbol))
2592 (setq gnus-newsrc-options
2593 ;; This concating is quite inefficient, but since our
2594 ;; thorough studies show that approx 99.37% of all
2595 ;; .newsrc files only contain a single options line, we
2596 ;; don't give a damn, frankly, my dear.
2597 (concat gnus-newsrc-options
2600 ;; Options may continue on the next line.
2601 (or (and (re-search-forward "^[^ \t]" nil 'move)
2606 ;; Group names can be just numbers.
2607 (when (numberp symbol)
2608 (setq symbol (intern (int-to-string symbol) gnus-active-hashtb)))
2609 (unless (boundp symbol)
2611 ;; It was a group name.
2612 (setq subscribed (eq (char-after) ?:)
2613 group (symbol-name symbol)
2616 ;; If the line ends here, this is clearly a buggy line, so
2617 ;; we put point a the beginning of line and let the cond
2618 ;; below do the error handling.
2620 ;; We skip to the beginning of the ranges.
2621 (skip-chars-forward "!: \t"))
2622 ;; We are now at the beginning of the list of read articles.
2623 ;; We read them range by range.
2626 ((looking-at "[0-9]+")
2627 ;; We narrow and read a number instead of buffer-substring/
2628 ;; string-to-int because it's faster. narrow/widen is
2629 ;; faster than save-restriction/narrow, and save-restriction
2630 ;; produces a garbage object.
2632 (narrow-to-region (match-beginning 0) (match-end 0))
2635 ;; If the next character is a dash, then this is a range.
2636 (if (eq (char-after) ?-)
2638 ;; We read the upper bound of the range.
2640 (if (not (looking-at "[0-9]+"))
2641 ;; This is a buggy line, by we pretend that
2642 ;; it's kinda OK. Perhaps the user should be
2648 (narrow-to-region (match-beginning 0)
2653 ;; It was just a simple number, so we add it to the
2656 ;; If the next char in ?\n, then we have reached the end
2657 ;; of the line and return nil.
2658 (not (eq (char-after) ?\n)))
2659 ((eq (char-after) ?\n)
2660 ;; End of line, so we end.
2663 ;; Not numbers and not eol, so this might be a buggy
2666 ;; If it was eob instead of ?\n, we allow it.
2667 ;; The line was buggy.
2669 (gnus-error 3.1 "Mangled line: %s"
2670 (buffer-substring (point-at-bol)
2673 ;; Skip past ", ". Spaces are invalid in these ranges, but
2674 ;; we allow them, because it's a common mistake to put a
2675 ;; space after the comma.
2676 (skip-chars-forward ", "))
2678 ;; We have already read .newsrc.eld, so we gently update the
2679 ;; data in the hash table with the information we have just
2682 (let ((info (gnus-get-info group))
2685 ;; There is an entry for this file in the alist.
2687 (gnus-info-set-read info (nreverse reads))
2688 ;; We update the level very gently. In fact, we
2689 ;; only change it if there's been a status change
2690 ;; from subscribed to unsubscribed, or vice versa.
2691 (setq level (gnus-info-level info))
2692 (cond ((and (<= level gnus-level-subscribed)
2694 (setq level (if reads
2695 gnus-level-default-unsubscribed
2696 (1+ gnus-level-default-unsubscribed))))
2697 ((and (> level gnus-level-subscribed) subscribed)
2698 (setq level gnus-level-default-subscribed)))
2699 (gnus-info-set-level info level))
2700 ;; This is a new group.
2701 (setq info (list group
2703 gnus-level-default-subscribed
2705 (1+ gnus-level-subscribed)
2706 gnus-level-default-unsubscribed))
2708 (push info newsrc)))))
2711 (setq newsrc (nreverse newsrc))
2713 (if (not already-read)
2715 ;; We now have two newsrc lists - `newsrc', which is what we
2716 ;; have read from .newsrc, and `gnus-newsrc-alist', which is
2717 ;; what we've read from .newsrc.eld. We have to merge these
2718 ;; lists. We do this by "attaching" any (foreign) groups in the
2719 ;; gnus-newsrc-alist to the (native) group that precedes them.
2720 (let ((rc (cdr gnus-newsrc-alist))
2721 (prev gnus-newsrc-alist)
2724 (or (null (nth 4 (car rc))) ; It's a native group.
2725 (assoc (caar rc) newsrc) ; It's already in the alist.
2726 (if (setq entry (assoc (caar prev) newsrc))
2727 (setcdr (setq mentry (memq entry newsrc))
2728 (cons (car rc) (cdr mentry)))
2729 (push (car rc) newsrc)))
2733 (setq gnus-newsrc-alist newsrc)
2734 ;; We make the newsrc hashtb.
2735 (gnus-make-hashtable-from-newsrc-alist)
2737 ;; Finally, if we read some options lines, we parse them.
2738 (unless (string= gnus-newsrc-options "")
2739 (gnus-newsrc-parse-options gnus-newsrc-options))))
2741 ;; Parse options lines to find "options -n !all rec.all" and stuff.
2742 ;; The return value will be a list on the form
2743 ;; ((regexp1 . ignore)
2744 ;; (regexp2 . subscribe)...)
2745 ;; When handling new newsgroups, groups that match a `ignore' regexp
2746 ;; will be ignored, and groups that match a `subscribe' regexp will be
2747 ;; subscribed. A line like
2748 ;; options -n !all rec.all
2749 ;; will lead to a list that looks like
2750 ;; (("^rec\\..+" . subscribe)
2751 ;; ("^.+" . ignore))
2752 ;; So all "rec.*" groups will be subscribed, while all the other
2753 ;; groups will be ignored. Note that "options -n !all rec.all" is very
2754 ;; different from "options -n rec.all !all".
2755 (defun gnus-newsrc-parse-options (options)
2758 (gnus-set-work-buffer)
2759 (insert (regexp-quote options))
2760 ;; First we treat all continuation lines.
2761 (goto-char (point-min))
2762 (while (re-search-forward "\n[ \t]+" nil t)
2763 (replace-match " " t t))
2764 ;; Then we transform all "all"s into ".+"s.
2765 (goto-char (point-min))
2766 (while (re-search-forward "\\ball\\b" nil t)
2767 (replace-match ".+" t t))
2768 (goto-char (point-min))
2769 ;; We remove all other options than the "-n" ones.
2770 (while (re-search-forward "[ \t]-[^n][^-]*" nil t)
2773 (goto-char (point-min))
2775 ;; We are only interested in "options -n" lines - we
2776 ;; ignore the other option lines.
2777 (while (re-search-forward "[ \t]-n" nil t)
2780 (and (re-search-forward "[ \t]-n" (point-at-eol) t)
2783 ;; Search for all "words"...
2784 (while (re-search-forward "[^ \t,\n]+" eol t)
2785 (if (eq (char-after (match-beginning 0)) ?!)
2786 ;; If the word begins with a bang (!), this is a "not"
2787 ;; spec. We put this spec (minus the bang) and the
2788 ;; symbol `ignore' into the list.
2790 "^" (buffer-substring
2791 (1+ (match-beginning 0))
2796 ;; There was no bang, so this is a "yes" spec.
2797 (push (cons (concat "^" (match-string 0) "\\($\\|\\.\\)")
2801 (setq gnus-newsrc-options-n out))))
2804 (defalias 'gnus-long-file-names
2805 (if (fboundp 'msdos-long-file-names)
2806 'msdos-long-file-names
2809 (defun gnus-save-newsrc-file (&optional force)
2810 "Save .newsrc file."
2811 ;; Note: We cannot save .newsrc file if all newsgroups are removed
2812 ;; from the variable gnus-newsrc-alist.
2813 (when (and (or gnus-newsrc-alist gnus-killed-list)
2814 gnus-current-startup-file)
2815 ;; Save agent range limits for the currently active method.
2817 (gnus-agent-save-local force))
2820 (if (and (or gnus-use-dribble-file gnus-slave)
2822 (or (not gnus-dribble-buffer)
2823 (not (buffer-name gnus-dribble-buffer))
2824 (zerop (save-excursion
2825 (set-buffer gnus-dribble-buffer)
2827 (gnus-message 4 "(No changes need to be saved)")
2828 (gnus-run-hooks 'gnus-save-newsrc-hook)
2830 (gnus-slave-save-newsrc)
2832 (when gnus-save-newsrc-file
2833 (gnus-message 8 "Saving %s..." gnus-current-startup-file)
2834 (gnus-gnus-to-newsrc-format)
2835 (gnus-message 8 "Saving %s...done" gnus-current-startup-file))
2837 ;; Save .newsrc.eld.
2838 (set-buffer (gnus-get-buffer-create " *Gnus-newsrc*"))
2839 (make-local-variable 'version-control)
2840 (setq version-control gnus-backup-startup-file)
2841 (setq buffer-file-name
2842 (concat gnus-current-startup-file ".eld"))
2843 (setq default-directory (file-name-directory buffer-file-name))
2844 (buffer-disable-undo)
2846 (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file)
2848 (if gnus-save-startup-file-via-temp-buffer
2849 (let ((coding-system-for-write gnus-ding-file-coding-system)
2850 (standard-output (current-buffer)))
2851 (gnus-gnus-to-quick-newsrc-format)
2852 (gnus-run-hooks 'gnus-save-quick-newsrc-hook)
2854 (let ((coding-system-for-write gnus-ding-file-coding-system)
2855 (version-control gnus-backup-startup-file)
2856 (startup-file (concat gnus-current-startup-file ".eld"))
2857 (working-dir (file-name-directory gnus-current-startup-file))
2860 ;; Generate the name of a non-existent file.
2861 (while (progn (setq working-file
2863 (if (and (eq system-type 'ms-dos)
2864 (not (gnus-long-file-names)))
2865 "%s#%d.tm#" ; MSDOS limits files to 8+3
2866 (if (memq system-type '(vax-vms axp-vms))
2869 working-dir (setq i (1+ i))))
2870 (file-exists-p working-file)))
2874 (gnus-with-output-to-file working-file
2875 (gnus-gnus-to-quick-newsrc-format)
2876 (gnus-run-hooks 'gnus-save-quick-newsrc-hook))
2878 ;; These bindings will mislead the current buffer
2879 ;; into thinking that it is visiting the startup
2881 (let ((buffer-backed-up nil)
2882 (buffer-file-name startup-file)
2883 (file-precious-flag t)
2884 (setmodes (file-modes startup-file)))
2885 ;; Backup the current version of the startup file.
2888 ;; Replace the existing startup file with the temp file.
2889 (rename-file working-file startup-file t)
2890 (gnus-set-file-modes startup-file setmodes)))
2892 (delete-file working-file)
2893 (file-error nil)))))
2895 (gnus-kill-buffer (current-buffer))
2897 5 "Saving %s.eld...done" gnus-current-startup-file))
2898 (gnus-dribble-delete-file)
2899 (gnus-group-set-mode-line))))
2900 (when gnus-product-directory
2901 (gnus-product-save-variable-file)))
2903 ;; Call the function above at C-x C-c.
2904 (defadvice save-buffers-kill-emacs (before save-gnus-newsrc-file-maybe
2905 activate preactivate)
2906 "Save .newsrc and .newsrc.eld when Emacs is killed."
2907 (when (gnus-alive-p)
2908 (gnus-run-hooks 'gnus-exit-gnus-hook)
2909 (gnus-offer-save-summaries)
2910 (gnus-save-newsrc-file)))
2912 (defun gnus-gnus-to-quick-newsrc-format (&optional minimal name &rest specific-variables)
2913 "Print Gnus variables such as `gnus-newsrc-alist' in Lisp format."
2914 (princ ";; -*- emacs-lisp -*-\n")
2916 (princ (format ";; %s\n" name))
2917 (princ ";; Gnus startup file.\n"))
2921 ;; Never delete this file -- if you want to force Gnus to read the
2922 ;; .newsrc file (if you have one), touch .newsrc instead.\n")
2923 (princ "(setq gnus-newsrc-file-version ")
2924 (princ (gnus-prin1-to-string gnus-version))
2927 (let* ((print-quoted t)
2929 (print-escape-multibyte nil)
2930 (print-escape-nonascii t)
2933 (print-escape-newlines t)
2935 (if (and gnus-save-killed-list
2936 (stringp gnus-save-killed-list))
2937 (gnus-strip-killed-list)
2940 (or specific-variables
2941 (if gnus-save-killed-list gnus-variable-list
2942 ;; Remove the `gnus-killed-list' from the list of variables
2943 ;; to be saved, if required.
2944 (delq 'gnus-killed-list (copy-sequence gnus-variable-list)))))
2945 ;; Peel off the "dummy" group.
2946 (gnus-newsrc-alist (cdr gnus-newsrc-alist))
2948 ;; Insert the variables into the file.
2950 (when (and (boundp (setq variable (pop variables)))
2951 (symbol-value variable))
2953 (princ (symbol-name variable))
2955 (prin1 (symbol-value variable))
2958 (defun gnus-product-variable-touch (&rest variables)
2960 (put (pop variables) 'gnus-product-variable 'dirty)))
2962 (defun gnus-product-variables-dirty-p (variables)
2965 (when (eq (get (car variables) 'gnus-product-variable) 'dirty)
2967 (setq variables (cdr variables)))))
2969 (defun gnus-product-save-variable-file (&optional force)
2970 "Save all product variables to files, when need to be saved."
2971 (let ((list gnus-product-variable-file-list))
2972 (gnus-make-directory gnus-product-directory)
2974 (apply 'gnus-product-save-variable-file-1 force (car list))
2975 (setq list (cdr list)))))
2977 (defun gnus-product-save-variable-file-1 (force file checking-methods coding
2979 "Save a product variable file, when need to be saved."
2981 (gnus-product-variables-dirty-p variables))
2982 (let ((product (product-find 'gnus-vers)))
2983 (set-buffer (gnus-get-buffer-create " *gnus-product*"))
2984 (make-local-variable 'version-control)
2985 (setq version-control 'never)
2986 (setq file (expand-file-name file gnus-product-directory)
2987 buffer-file-name file
2988 default-directory (file-name-directory file))
2989 (buffer-disable-undo)
2991 (gnus-message 5 "Saving %s..." file)
2992 (apply 'gnus-product-quick-file-format product checking-methods coding
2994 (save-buffer-as-coding-system coding)
2995 (kill-buffer (current-buffer))
2997 (put (car variables) 'gnus-product-variable nil)
2998 (setq variables (cdr variables)))
3000 5 "Saving %s...done" file))))
3002 (defun gnus-product-quick-file-format (product checking-methods
3003 coding &rest variables)
3004 "Insert gnus product depend variables in lisp format."
3005 (let ((print-quoted t)
3006 (print-escape-newlines t)
3007 print-length print-level variable param)
3008 (insert (format ";; -*- Mode: emacs-lisp; coding: %s -*-\n" coding))
3009 (insert (format ";; %s startup file.\n" (product-name product)))
3010 (when (setq param (cdr (assq 'product-version checking-methods)))
3011 (insert "(or (>= (product-version-compare "
3012 "(product-version (product-find 'gnus-vers))\n"
3013 "\t\t\t\t '" (apply 'prin1-to-string param) ")\n"
3015 " (error \"This file was created by later version of "
3017 (insert "(setq gnus-product-file-version\n"
3018 " '((product-version . "
3019 (prin1-to-string (product-version product)) ")\n"
3020 "\t(emacs-version . "
3021 (prin1-to-string emacs-version) ")\n"
3022 "\t(correct-string-widths . "
3023 (if gnus-use-correct-string-widths "t" "nil")
3026 (when (and (boundp (setq variable (pop variables)))
3027 (symbol-value variable))
3028 (insert "(setq " (symbol-name variable) " '")
3029 (gnus-prin1 (symbol-value variable))
3032 (defun gnus-strip-killed-list ()
3033 "Return the killed list minus the groups that match `gnus-save-killed-list'."
3034 (let ((list gnus-killed-list)
3037 (when (string-match gnus-save-killed-list (car list))
3038 (push (car list) olist))
3042 (defun gnus-gnus-to-newsrc-format ()
3043 ;; Generate and save the .newsrc file.
3045 (set-buffer (create-file-buffer gnus-current-startup-file))
3046 (let ((newsrc (cdr gnus-newsrc-alist))
3047 (standard-output (current-buffer))
3048 info ranges range method)
3049 (setq buffer-file-name gnus-current-startup-file)
3050 (setq default-directory (file-name-directory buffer-file-name))
3051 (buffer-disable-undo)
3054 (when gnus-newsrc-options
3055 (insert gnus-newsrc-options))
3056 ;; Write subscribed and unsubscribed.
3057 (while (setq info (pop newsrc))
3058 ;; Don't write foreign groups to .newsrc.
3059 (when (or (null (setq method (gnus-info-method info)))
3060 (equal method "native")
3061 (inline (gnus-server-equal method gnus-select-method)))
3062 (insert (gnus-info-group info)
3063 (if (> (gnus-info-level info) gnus-level-subscribed)
3065 (when (setq ranges (gnus-info-read info))
3067 (if (not (listp (cdr ranges)))
3068 (if (= (car ranges) (cdr ranges))
3069 (princ (car ranges))
3070 (princ (car ranges))
3072 (princ (cdr ranges)))
3073 (while (setq range (pop ranges))
3074 (if (or (atom range) (= (car range) (cdr range)))
3075 (princ (or (and (atom range) range) (car range)))
3078 (princ (cdr range)))
3082 (make-local-variable 'version-control)
3083 (setq version-control 'never)
3084 ;; It has been reported that sometime the modtime on the .newsrc
3085 ;; file seems to be off. We really do want to overwrite it, so
3086 ;; we clear the modtime here before saving. It's a bit odd,
3088 ;; sometimes the modtime clear isn't sufficient. most brute force:
3089 ;; delete the silly thing entirely first. but this fails to provide
3090 ;; such niceties as .newsrc~ creation.
3091 (if gnus-modtime-botch
3092 (delete-file gnus-startup-file)
3093 (clear-visited-file-modtime))
3094 (gnus-run-hooks 'gnus-save-standard-newsrc-hook)
3096 (kill-buffer (current-buffer)))))
3100 ;;; Slave functions.
3103 (defvar gnus-slave-mode nil)
3105 (defun gnus-slave-mode ()
3106 "Minor mode for slave Gnusae."
3107 (add-minor-mode 'gnus-slave-mode " Slave" (make-sparse-keymap))
3108 (gnus-run-hooks 'gnus-slave-mode-hook))
3110 (defun gnus-slave-save-newsrc ()
3112 (set-buffer gnus-dribble-buffer)
3114 (mm-make-temp-file (concat gnus-current-startup-file "-slave-")))
3115 (modes (ignore-errors
3116 (file-modes (concat gnus-current-startup-file ".eld")))))
3117 (gnus-write-buffer-as-coding-system gnus-ding-file-coding-system
3120 (gnus-set-file-modes slave-name modes)))))
3122 (defun gnus-master-read-slave-newsrc ()
3125 (file-name-directory gnus-current-startup-file)
3129 (file-name-nondirectory gnus-current-startup-file)
3133 (if (not slave-files)
3134 () ; There are no slave files to read.
3135 (gnus-message 7 "Reading slave newsrcs...")
3137 (set-buffer (gnus-get-buffer-create " *gnus slave*"))
3139 (sort (mapcar (lambda (file)
3140 (list (nth 5 (file-attributes file)) file))
3143 (or (< (caar f1) (caar f2))
3144 (< (nth 1 (car f1)) (nth 1 (car f2)))))))
3147 (setq file (nth 1 (car slave-files)))
3148 (nnheader-insert-file-contents file)
3149 (when (condition-case ()
3151 (eval-buffer (current-buffer))
3154 (gnus-error 3.2 "Possible error in %s" file)
3156 (unless gnus-slave ; Slaves shouldn't delete these files.
3158 (delete-file file))))
3159 (setq slave-files (cdr slave-files))))
3160 (gnus-dribble-touch)
3161 (gnus-message 7 "Reading slave newsrcs...done"))))
3165 ;;; Group description.
3168 (defun gnus-read-all-descriptions-files ()
3169 (let ((methods (cons gnus-select-method
3171 (when (gnus-archive-server-wanted-p)
3173 gnus-secondary-select-methods))))
3175 (gnus-read-descriptions-file (car methods))
3176 (setq methods (cdr methods)))
3179 (defun gnus-read-descriptions-file (&optional method)
3180 (let ((method (or method gnus-select-method))
3182 (when (stringp method)
3183 (setq method (gnus-server-to-method method)))
3184 ;; We create the hashtable whether we manage to read the desc file
3185 ;; to avoid trying to re-read after a failed read.
3186 (unless gnus-description-hashtb
3187 (setq gnus-description-hashtb
3188 (gnus-make-hashtable (length gnus-active-hashtb))))
3189 ;; Mark this method's desc file as read.
3190 (gnus-sethash (gnus-group-prefixed-name "" method) "Has read"
3191 gnus-description-hashtb)
3193 (gnus-message 5 "Reading descriptions file via %s..." (car method))
3195 ((null (gnus-get-function method 'request-list-newsgroups t))
3197 ((not (gnus-check-server method))
3198 (gnus-message 1 "Couldn't open server")
3200 ((not (gnus-request-list-newsgroups method))
3201 (gnus-message 1 "Couldn't read newsgroups descriptions")
3206 (set-buffer nntp-server-buffer)
3207 (goto-char (point-min))
3208 (when (or (search-forward "\n.\n" nil t)
3209 (goto-char (point-max)))
3211 (narrow-to-region (point-min) (point)))
3212 ;; If these are groups from a foreign select method, we insert the
3213 ;; group prefix in front of the group names.
3214 (and method (not (inline
3216 (gnus-server-get-method nil method)
3217 (gnus-server-get-method
3218 nil gnus-select-method))))
3219 (let ((prefix (gnus-group-prefixed-name "" method)))
3220 (goto-char (point-min))
3221 (while (and (not (eobp))
3222 (progn (insert prefix)
3223 (zerop (forward-line 1)))))))
3224 (goto-char (point-min))
3226 ;; If we get an error, we set group to 0, which is not a
3230 (let ((obarray gnus-description-hashtb))
3231 ;; Group is set to a symbol interned in this
3233 (read nntp-server-buffer))
3235 (skip-chars-forward " \t")
3236 ;; ... which leads to this line being effectively ignored.
3237 (when (symbolp group)
3238 (let* ((str (buffer-substring
3239 (point) (progn (end-of-line) (point))))
3240 (name (symbol-name group))
3242 (or (gnus-group-name-charset method name)
3243 (gnus-parameter-charset name)
3244 gnus-default-charset)))
3245 ;; Fixme: Don't decode in unibyte mode.
3246 (when (and str charset (featurep 'mule))
3247 (setq str (decode-coding-string str charset)))
3250 (gnus-message 5 "Reading descriptions file...done")
3253 (defun gnus-group-get-description (group)
3254 "Get the description of a group by sending XGTITLE to the server."
3255 (when (gnus-request-group-description group)
3257 (set-buffer nntp-server-buffer)
3258 (goto-char (point-min))
3259 (when (looking-at "[^ \t]+[ \t]+\\(.*\\)")
3260 (match-string 1)))))
3263 (defun gnus-declare-backend (name &rest abilities)
3264 "Declare back end NAME with ABILITIES as a Gnus back end."
3265 (setq gnus-valid-select-methods
3266 (nconc gnus-valid-select-methods
3267 (list (apply 'list name abilities))))
3268 (gnus-redefine-select-method-widget))
3270 (defun gnus-set-default-directory ()
3271 "Set the default directory in the current buffer to `gnus-default-directory'.
3272 If this variable is nil, don't do anything."
3273 (setq default-directory
3274 (if (and gnus-default-directory
3275 (file-exists-p gnus-default-directory))
3276 (file-name-as-directory (expand-file-name gnus-default-directory))
3277 default-directory)))
3280 (defalias 'gnus-display-time-event-handler
3281 (if (gnus-boundp 'display-time-timer)
3282 'display-time-event-handler
3283 (lambda () "Does nothing as `display-time-timer' is not bound.
3284 Would otherwise be an alias for `display-time-event-handler'." nil))))
3287 (defun gnus-fixup-nnimap-unread-after-getting-new-news ()
3288 (let (server group info)
3291 (when (and (setq group (symbol-name sym))
3292 (gnus-group-entry group)
3293 (setq info (symbol-value sym)))
3294 (gnus-sethash group (cons (nth 2 info) (cdr (gnus-group-entry group)))
3295 gnus-newsrc-hashtb)))
3296 (if (boundp 'nnimap-mailbox-info)
3297 (symbol-value 'nnimap-mailbox-info)
3298 (make-vector 1 0)))))
3300 (defun gnus-check-reasonable-setup ()
3301 ;; Check whether nnml and nnfolder share a directory.
3303 (if (fboundp 'display-warning)
3305 (lambda (type message)
3307 (message "Warning (%s): %s" type message)
3309 (with-current-buffer (get-buffer-create "*Warnings*")
3310 (goto-char (point-max))
3313 (insert (format "Warning (%s): %s\n" type message))
3314 (setq window (display-buffer (current-buffer)))
3318 (forward-line (- 1 (window-height window)))
3320 (goto-char (point-max))))))))))
3321 method active actives match)
3322 (dolist (server gnus-server-alist)
3323 (setq method (gnus-server-to-method server)
3324 active (intern (format "%s-active-file" (car method))))
3325 (when (and (member (car method) '(nnml nnfolder))
3326 (gnus-server-opened method)
3328 (when (setq match (assoc (symbol-value active) actives))
3329 (funcall display-warn 'gnus-server
3330 (format "%s and %s share the same active file %s"
3334 (push (list (symbol-value active) method) actives)))))
3336 (provide 'gnus-start)
3338 ;;; gnus-start.el ends here