1 ;;; gnus-start.el --- startup functions for Gnus
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005 Free Software Foundation, Inc.
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
30 (eval-when-compile (require 'cl))
31 (eval-when-compile (require 'static))
39 (autoload 'message-make-date "message")
40 (autoload 'gnus-agent-read-servers-validate "gnus-agent")
41 (autoload 'gnus-agent-save-local "gnus-agent")
42 (autoload 'gnus-agent-possibly-alter-active "gnus-agent")
44 (defvar gnus-agent-covered-methods nil)
45 (defvar gnus-agent-file-loading-local nil)
46 (defvar gnus-agent-file-loading-cache nil))
48 (defcustom gnus-startup-file (nnheader-concat gnus-home-directory ".newsrc")
50 `.newsrc-SERVER' will be used instead if that exists."
54 (defcustom gnus-product-directory
55 (nnheader-concat gnus-directory (concat "." gnus-product-name))
56 "Product depend data files directory."
58 :type '(choice directory (const nil)))
60 (defcustom gnus-backup-startup-file 'never
61 "Whether to create backup files.
62 This variable takes the same values as the `version-control'
66 :type '(choice (const :tag "Never" never)
67 (const :tag "If existing" nil)
68 (other :tag "Always" t)))
70 (defcustom gnus-save-startup-file-via-temp-buffer t
71 "Whether to write the startup file contents to a buffer then save
72 the buffer or write directly to the file. The buffer is faster
73 because all of the contents are written at once. The direct write
74 uses considerably less memory."
77 :type '(choice (const :tag "Write via buffer" t)
78 (const :tag "Write directly to file" nil)))
80 (defcustom gnus-init-file (nnheader-concat gnus-home-directory ".gnus")
81 "Your Gnus Emacs-Lisp startup file name.
82 If a file with the `.el' or `.elc' suffixes exists, it will be read instead."
86 (defcustom gnus-site-init-file
88 (concat (file-name-directory
89 (directory-file-name installation-directory))
90 "site-lisp/gnus-init")
92 "The site-wide Gnus Emacs-Lisp startup file name, or nil if none.
93 If a file with the `.el' or `.elc' suffixes exists, it will be read instead."
95 :type '(choice file (const nil)))
97 (defcustom gnus-default-subscribed-newsgroups nil
98 "List of newsgroups to subscribe, when a user runs Gnus the first time.
99 The value should be a list of strings.
100 If it is t, Gnus will not do anything special the first time it is
101 started; it'll just use the normal newsgroups subscription methods."
103 :type '(choice (repeat string) (const :tag "Nothing special" t)))
105 (defcustom gnus-use-dribble-file t
106 "*Non-nil means that Gnus will use a dribble file to store user updates.
107 If Emacs should crash without saving the .newsrc files, complete
108 information can be restored from the dribble file."
109 :group 'gnus-dribble-file
112 (defcustom gnus-dribble-directory nil
113 "*The directory where dribble files will be saved.
114 If this variable is nil, the directory where the .newsrc files are
116 :group 'gnus-dribble-file
117 :type '(choice directory (const nil)))
119 (defcustom gnus-check-new-newsgroups 'ask-server
120 "*Non-nil means that Gnus will run `gnus-find-new-newsgroups' at startup.
121 This normally finds new newsgroups by comparing the active groups the
122 servers have already reported with those Gnus already knows, either alive
125 When any of the following are true, `gnus-find-new-newsgroups' will instead
126 ask the servers (primary, secondary, and archive servers) to list new
127 groups since the last time it checked:
128 1. This variable is `ask-server'.
129 2. This variable is a list of select methods (see below).
130 3. `gnus-read-active-file' is nil or `some'.
131 4. A prefix argument is given to `gnus-find-new-newsgroups' interactively.
133 Thus, if this variable is `ask-server' or a list of select methods or
134 `gnus-read-active-file' is nil or `some', then the killed list is no
135 longer necessary, so you could safely set `gnus-save-killed-list' to nil.
137 This variable can be a list of select methods which Gnus will query with
138 the `ask-server' method in addition to the primary, secondary, and archive
142 (setq gnus-check-new-newsgroups
143 '((nntp \"some.server\") (nntp \"other.server\")))
145 If this variable is nil, then you have to tell Gnus explicitly to
146 check for new newsgroups with \\<gnus-group-mode-map>\\[gnus-find-new-newsgroups]."
148 :type '(choice (const :tag "no" nil)
149 (const :tag "by brute force" t)
150 (const :tag "ask servers" ask-server)
151 (repeat :menu-tag "ask additional servers"
152 :tag "ask additional servers"
154 (sexp :format "%v"))))
156 (defcustom gnus-check-bogus-newsgroups nil
157 "*Non-nil means that Gnus will check and remove bogus newsgroup at startup.
158 If this variable is nil, then you have to tell Gnus explicitly to
159 check for bogus newsgroups with \\<gnus-group-mode-map>\\[gnus-group-check-bogus-groups]."
160 :group 'gnus-start-server
163 (defcustom gnus-read-active-file 'some
164 "*Non-nil means that Gnus will read the entire active file at startup.
165 If this variable is nil, Gnus will only know about the groups in your
168 If this variable is `some', Gnus will try to only read the relevant
169 parts of the active file from the server. Not all servers support
170 this, and it might be quite slow with other servers, but this should
171 generally be faster than both the t and nil value.
173 If you set this variable to nil or `some', you probably still want to
174 be told about new newsgroups that arrive. To do that, set
175 `gnus-check-new-newsgroups' to `ask-server'. This may not work
176 properly with all servers."
177 :group 'gnus-start-server
178 :type '(choice (const nil)
182 (defconst gnus-level-subscribed 5
183 "Groups with levels less than or equal to this variable are subscribed.")
185 (defconst gnus-level-unsubscribed 7
186 "Groups with levels less than or equal to this variable are unsubscribed.
187 Groups with levels less than `gnus-level-subscribed', which should be
188 less than this variable, are subscribed.")
190 (defconst gnus-level-zombie 8
191 "Groups with this level are zombie groups.")
193 (defconst gnus-level-killed 9
194 "Groups with this level are killed.")
196 (defcustom gnus-level-default-subscribed 3
197 "*New subscribed groups will be subscribed at this level."
198 :group 'gnus-group-levels
201 (defcustom gnus-level-default-unsubscribed 6
202 "*New unsubscribed groups will be unsubscribed at this level."
203 :group 'gnus-group-levels
206 (defcustom gnus-activate-level (1+ gnus-level-subscribed)
207 "*Groups higher than this level won't be activated on startup.
208 Setting this variable to something low might save lots of time when
209 you have many groups that you aren't interested in."
210 :group 'gnus-group-levels
213 (defcustom gnus-activate-foreign-newsgroups 4
214 "*If nil, Gnus will not check foreign newsgroups at startup.
215 If it is non-nil, it should be a number between one and nine. Foreign
216 newsgroups that have a level lower or equal to this number will be
217 activated on startup. For instance, if you want to active all
218 subscribed newsgroups, but not the rest, you'd set this variable to
219 `gnus-level-subscribed'.
221 If you subscribe to lots of newsgroups from different servers, startup
222 might take a while. By setting this variable to nil, you'll save time,
223 but you won't be told how many unread articles there are in the
225 :group 'gnus-group-levels
226 :type '(choice integer
227 (const :tag "none" nil)))
229 (defcustom gnus-read-newsrc-file t
230 "*Non-nil means that Gnus will read the `.newsrc' file.
231 Gnus always reads its own startup file, which is called
232 \".newsrc.eld\". The file called \".newsrc\" is in a format that can
233 be readily understood by other newsreaders. If you don't plan on
234 using other newsreaders, set this variable to nil to save some time on
240 (defcustom gnus-save-newsrc-file t
241 "*Non-nil means that Gnus will save the `.newsrc' file.
242 Gnus always saves its own startup file, which is called
243 \".newsrc.eld\". The file called \".newsrc\" is in a format that can
244 be readily understood by other newsreaders. If you don't plan on
245 using other newsreaders, set this variable to nil to save some time on
250 (defcustom gnus-save-killed-list t
251 "*If non-nil, save the list of killed groups to the startup file.
252 If you set this variable to nil, you'll save both time (when starting
253 and quitting) and space (both memory and disk), but it will also mean
254 that Gnus has no record of which groups are new and which are old, so
255 the automatic new newsgroups subscription methods become meaningless.
257 You should always set `gnus-check-new-newsgroups' to `ask-server' or
258 nil if you set this variable to nil.
260 This variable can also be a regexp. In that case, all groups that do
261 not match this regexp will be removed before saving the list."
263 :type '(radio (sexp :format "Non-nil\n"
264 :match (lambda (widget value)
265 (and value (not (stringp value))))
270 (defcustom gnus-ignored-newsgroups
272 '("^to\\." ; not "real" groups
273 "^[0-9. \t]+\\( \\|$\\)" ; all digits in name
274 "^[\"][]\"[#'()]" ; bogus characters
277 "*A regexp to match uninteresting newsgroups in the active file.
278 Any lines in the active file matching this regular expression are
279 removed from the newsgroup list before anything else is done to it,
280 thus making them effectively non-existent."
281 :group 'gnus-group-new
284 (defcustom gnus-subscribe-newsgroup-method 'gnus-subscribe-zombies
285 "*Function(s) called with a group name when new group is detected.
286 A few pre-made functions are supplied: `gnus-subscribe-randomly'
287 inserts new groups at the beginning of the list of groups;
288 `gnus-subscribe-alphabetically' inserts new groups in strict
289 alphabetic order; `gnus-subscribe-hierarchically' inserts new groups
290 in hierarchical newsgroup order; `gnus-subscribe-interactively' asks
291 for your decision; `gnus-subscribe-killed' kills all new groups;
292 `gnus-subscribe-zombies' will make all new groups into zombies;
293 `gnus-subscribe-topics' will enter groups into the topics that
295 :group 'gnus-group-new
296 :type '(radio (function-item gnus-subscribe-randomly)
297 (function-item gnus-subscribe-alphabetically)
298 (function-item gnus-subscribe-hierarchically)
299 (function-item gnus-subscribe-interactively)
300 (function-item gnus-subscribe-killed)
301 (function-item gnus-subscribe-zombies)
302 (function-item gnus-subscribe-topics)
306 (defcustom gnus-subscribe-newsgroup-hooks nil
307 "*Hooks run after you subscribe to a new group.
308 The hooks will be called with new group's name as argument."
310 :group 'gnus-group-new
313 (defcustom gnus-subscribe-options-newsgroup-method
314 'gnus-subscribe-alphabetically
315 "*Function(s) called to subscribe newsgroups mentioned on \"options -n\" lines.
316 If, for instance, you want to subscribe to all newsgroups in the
317 \"no\" and \"alt\" hierarchies, you'd put the following in your
320 options -n no.all alt.all
322 Gnus will the subscribe all new newsgroups in these hierarchies with
323 the subscription method in this variable."
324 :group 'gnus-group-new
325 :type '(radio (function-item gnus-subscribe-randomly)
326 (function-item gnus-subscribe-alphabetically)
327 (function-item gnus-subscribe-hierarchically)
328 (function-item gnus-subscribe-interactively)
329 (function-item gnus-subscribe-killed)
330 (function-item gnus-subscribe-zombies)
331 (function-item gnus-subscribe-topics)
335 (defcustom gnus-subscribe-hierarchical-interactive nil
336 "*If non-nil, Gnus will offer to subscribe hierarchically.
337 When a new hierarchy appears, Gnus will ask the user:
339 'alt.binaries': Do you want to subscribe to this hierarchy? ([d]ys):
341 If the user pressed `d', Gnus will descend the hierarchy, `y' will
342 subscribe to all newsgroups in the hierarchy and `s' will skip this
343 hierarchy in its entirety."
344 :group 'gnus-group-new
347 (defcustom gnus-auto-subscribed-groups
348 "^nnml\\|^nnfolder\\|^nnmbox\\|^nnmh\\|^nnbabyl\\|^nnmaildir"
349 "*All new groups that match this regexp will be subscribed automatically.
350 Note that this variable only deals with new groups. It has no effect
351 whatsoever on old groups.
353 New groups that match this regexp will not be handled by
354 `gnus-subscribe-newsgroup-method'. Instead, they will
355 be subscribed using `gnus-subscribe-options-newsgroup-method'."
356 :group 'gnus-group-new
359 (defcustom gnus-options-subscribe nil
360 "*All new groups matching this regexp will be subscribed unconditionally.
361 Note that this variable deals only with new newsgroups. This variable
362 does not affect old newsgroups.
364 New groups that match this regexp will not be handled by
365 `gnus-subscribe-newsgroup-method'. Instead, they will
366 be subscribed using `gnus-subscribe-options-newsgroup-method'."
367 :group 'gnus-group-new
368 :type '(choice regexp
369 (const :tag "none" nil)))
371 (defcustom gnus-options-not-subscribe nil
372 "*All new groups matching this regexp will be ignored.
373 Note that this variable deals only with new newsgroups. This variable
374 does not affect old (already subscribed) newsgroups."
375 :group 'gnus-group-new
376 :type '(choice regexp
377 (const :tag "none" nil)))
379 (defcustom gnus-modtime-botch nil
380 "*Non-nil means .newsrc should be deleted prior to save.
381 Its use is due to the bogus appearance that .newsrc was modified on
386 (defcustom gnus-check-bogus-groups-hook nil
387 "A hook run after removing bogus groups."
388 :group 'gnus-start-server
391 (defcustom gnus-startup-hook nil
392 "A hook called at startup.
393 This hook is called after Gnus is connected to the NNTP server."
397 (defcustom gnus-before-startup-hook nil
398 "A hook called at before startup.
399 This hook is called as the first thing when Gnus is started."
403 (defcustom gnus-started-hook nil
404 "A hook called as the last thing after startup."
408 (defcustom gnus-setup-news-hook
409 '(gnus-fixup-nnimap-unread-after-getting-new-news)
410 "A hook after reading the .newsrc file, but before generating the buffer."
414 (defcustom gnus-get-top-new-news-hook nil
415 "A hook run just before Gnus checks for new news globally."
417 :group 'gnus-group-new
420 (defcustom gnus-get-new-news-hook nil
421 "A hook run just before Gnus checks for new news."
422 :group 'gnus-group-new
425 (defcustom gnus-after-getting-new-news-hook
426 '(gnus-display-time-event-handler
427 gnus-fixup-nnimap-unread-after-getting-new-news)
428 "A hook run after Gnus checks for new news when Gnus is already running."
429 :group 'gnus-group-new
432 (defcustom gnus-read-newsrc-el-hook nil
433 "A hook called after reading the newsrc.eld? file."
437 (defcustom gnus-save-newsrc-hook nil
438 "A hook called before saving any of the newsrc files."
442 (defcustom gnus-save-quick-newsrc-hook nil
443 "A hook called just before saving the quick newsrc file.
444 Can be used to turn version control on or off."
448 (defcustom gnus-save-standard-newsrc-hook nil
449 "A hook called just before saving the standard newsrc file.
450 Can be used to turn version control on or off."
454 (defcustom gnus-group-mode-hook nil
455 "Hook for Gnus group mode."
456 :group 'gnus-group-various
457 :options '(gnus-topic-mode)
460 (defcustom gnus-always-read-dribble-file nil
461 "Unconditionally read the dribble file."
465 ;;; Internal variables
467 (defvar gnus-ding-file-coding-system 'ctext
468 "Coding system for ding file.")
469 ;; Note that the ding file for T-gnus ought not to have byte-codes.
471 (defvar gnus-newsrc-file-version nil)
472 (defvar gnus-override-subscribe-method nil)
473 (defvar gnus-dribble-buffer nil)
474 (defvar gnus-newsrc-options nil
475 "Options line in the .newsrc file.")
477 (defvar gnus-newsrc-options-n nil
478 "List of regexps representing groups to be subscribed/ignored unconditionally.")
480 (defvar gnus-newsrc-last-checked-date nil
481 "Date Gnus last asked server for new newsgroups.")
483 (defvar gnus-current-startup-file nil
484 "Startup file for the current host.")
486 ;; Byte-compiler warning.
487 (defvar gnus-group-line-format)
489 ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
490 (defvar gnus-init-inhibit nil)
491 (defun gnus-read-init-file (&optional inhibit-next)
492 ;; Don't load .gnus if the -q option was used.
494 (if gnus-init-inhibit
495 (setq gnus-init-inhibit nil)
496 (setq gnus-init-inhibit inhibit-next)
497 (dolist (file (list gnus-site-init-file gnus-init-file))
499 (locate-library file))
500 (if (or debug-on-error debug-on-quit)
505 (error "Error in %s: %s" file (cadr var))))))))))
507 ;; For subscribing new newsgroup
509 (defun gnus-subscribe-hierarchical-interactive (groups)
510 (let ((groups (sort groups 'string<))
511 prefixes prefix start ans group starts real-group)
513 (setq prefixes (list "^"))
514 (while (and groups prefixes)
515 (while (not (string-match (car prefixes)
516 (gnus-group-real-name (car groups))))
517 (setq prefixes (cdr prefixes)))
518 (setq prefix (car prefixes))
519 (setq start (1- (length prefix)))
520 (if (and (string-match "[^\\.]\\." (gnus-group-real-name (car groups))
524 (concat "^" (substring
525 (gnus-group-real-name (car groups))
527 (string-match prefix (gnus-group-real-name (cadr groups))))
529 (push prefix prefixes)
530 (message "Descend hierarchy %s? ([y]nsq): "
531 (substring prefix 1 (1- (length prefix))))
532 (while (not (memq (setq ans (read-char-exclusive))
533 '(?y ?\n ?\r ?n ?s ?q)))
535 (message "Descend hierarchy %s? ([y]nsq): "
536 (substring prefix 1 (1- (length prefix)))))
539 (setq group (car groups)
540 real-group (gnus-group-real-name group))
541 (string-match prefix real-group))
542 (push group gnus-killed-list)
543 (gnus-sethash group group gnus-killed-hashtb)
544 (setq groups (cdr groups)))
545 (setq starts (cdr starts)))
548 (setq group (car groups)
549 real-group (gnus-group-real-name group))
550 (string-match prefix real-group))
551 (gnus-sethash group group gnus-killed-hashtb)
552 (gnus-subscribe-alphabetically (car groups))
553 (setq groups (cdr groups)))
554 (setq starts (cdr starts)))
557 (setq group (car groups))
558 (push group gnus-killed-list)
559 (gnus-sethash group group gnus-killed-hashtb)
560 (setq groups (cdr groups))))
562 (message "Subscribe %s? ([n]yq)" (car groups))
563 (while (not (memq (setq ans (read-char-exclusive))
564 '(?y ?\n ?\r ?q ?n)))
566 (message "Subscribe %s? ([n]yq)" (car groups)))
567 (setq group (car groups))
569 (gnus-subscribe-alphabetically (car groups))
570 (gnus-sethash group group gnus-killed-hashtb))
573 (setq group (car groups))
574 (push group gnus-killed-list)
575 (gnus-sethash group group gnus-killed-hashtb)
576 (setq groups (cdr groups))))
578 (push group gnus-killed-list)
579 (gnus-sethash group group gnus-killed-hashtb)))
580 (setq groups (cdr groups)))))))
582 (defun gnus-subscribe-randomly (newsgroup)
583 "Subscribe new NEWSGROUP by making it the first newsgroup."
584 (gnus-subscribe-newsgroup newsgroup))
586 (defun gnus-subscribe-alphabetically (newgroup)
587 "Subscribe new NEWGROUP and insert it in alphabetical order."
588 (let ((groups (cdr gnus-newsrc-alist))
590 (while (and (not before) groups)
591 (if (string< newgroup (caar groups))
592 (setq before (caar groups))
593 (setq groups (cdr groups))))
594 (gnus-subscribe-newsgroup newgroup before)))
596 (defun gnus-subscribe-hierarchically (newgroup)
597 "Subscribe new NEWGROUP and insert it in hierarchical newsgroup order."
598 ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
600 (set-buffer (nnheader-find-file-noselect gnus-current-startup-file))
602 (let ((groupkey newgroup) before)
603 (while (and (not before) groupkey)
604 (goto-char (point-min))
606 (concat "^\\(" (regexp-quote groupkey) ".*\\)[!:]")))
607 (while (and (re-search-forward groupkey-re nil t)
609 (setq before (match-string 1))
610 (string< before newgroup)))))
611 ;; Remove tail of newsgroup name (eg. a.b.c -> a.b)
613 (when (string-match "^\\(.*\\)\\.[^.]+$" groupkey)
614 (substring groupkey (match-beginning 1) (match-end 1)))))
615 (gnus-subscribe-newsgroup newgroup before))
616 (kill-buffer (current-buffer)))))
618 (defun gnus-subscribe-interactively (group)
619 "Subscribe the new GROUP interactively.
620 It is inserted in hierarchical newsgroup order if subscribed. If not,
622 (if (gnus-y-or-n-p (format "Subscribe new newsgroup %s? " group))
623 (gnus-subscribe-hierarchically group)
624 (push group gnus-killed-list)))
626 (defun gnus-subscribe-zombies (group)
627 "Make the new GROUP into a zombie group."
628 (push group gnus-zombie-list))
630 (defun gnus-subscribe-killed (group)
631 "Make the new GROUP a killed group."
632 (push group gnus-killed-list))
634 (defun gnus-subscribe-newsgroup (newsgroup &optional next)
635 "Subscribe new NEWSGROUP.
636 If NEXT is non-nil, it is inserted before NEXT. Otherwise it is made
637 the first newsgroup."
639 (goto-char (point-min))
640 ;; We subscribe the group by changing its level to `subscribed'.
641 (gnus-group-change-level
642 newsgroup gnus-level-default-subscribed
643 gnus-level-killed (gnus-group-entry (or next "dummy.group")))
644 (gnus-message 5 "Subscribe newsgroup: %s" newsgroup)
645 (run-hook-with-args 'gnus-subscribe-newsgroup-hooks newsgroup)
648 (defun gnus-read-active-file-p ()
649 "Say whether the active file has been read from `gnus-select-method'."
650 (memq gnus-select-method gnus-have-read-active-file))
652 ;;; General various misc type functions.
654 ;; Silence byte-compiler.
656 (defvar gnus-current-headers)
657 (defvar gnus-thread-indent-array)
658 (defvar gnus-newsgroup-name)
659 (defvar gnus-newsgroup-headers)
660 (defvar gnus-group-list-mode)
661 (defvar gnus-group-mark-positions)
662 (defvar gnus-newsgroup-data)
663 (defvar gnus-newsgroup-unreads)
664 (defvar nnoo-state-alist)
665 (defvar gnus-current-select-method)
666 (defvar mail-sources)
667 (defvar nnmail-scan-directory-mail-source-once)
668 (defvar nnmail-split-history)
669 (defvar nnmail-spool-file))
671 (defun gnus-clear-quick-file-variables ()
672 "Clear all variables in quick startup files."
673 (let ((variables gnus-variable-list))
674 ;; Clear Gnus variables.
676 (set (car variables) nil)
677 (setq variables (cdr variables))))
678 (let ((files gnus-product-variable-file-list))
680 (let ((variables (nthcdr 3 (car files))))
682 (set (car variables) nil)
683 (setq variables (cdr variables))))
684 (setq files (cdr files)))))
686 (defun gnus-close-all-servers ()
689 (dolist (server gnus-opened-servers)
690 (gnus-close-server (car server))))
692 (defun gnus-clear-system ()
693 "Clear all variables and buffers."
694 ;; Clear gnus variables.
695 (gnus-clear-quick-file-variables)
696 ;; Clear other internal variables.
697 (setq gnus-list-of-killed-groups nil
698 gnus-have-read-active-file nil
699 gnus-agent-covered-methods nil
700 gnus-agent-file-loading-local nil
701 gnus-agent-file-loading-cache nil
702 gnus-server-method-cache nil
703 gnus-newsrc-alist nil
704 gnus-newsrc-hashtb nil
707 gnus-killed-hashtb nil
708 gnus-active-hashtb nil
709 gnus-moderated-hashtb nil
710 gnus-description-hashtb nil
711 gnus-current-headers nil
712 gnus-thread-indent-array nil
713 gnus-newsgroup-headers nil
714 gnus-newsgroup-name nil
715 gnus-server-alist nil
716 gnus-group-list-mode nil
717 gnus-opened-servers nil
718 gnus-group-mark-positions nil
719 gnus-newsgroup-data nil
720 gnus-newsgroup-unreads nil
722 gnus-current-select-method nil
723 nnmail-split-history nil
724 gnus-ephemeral-servers nil)
725 (gnus-shutdown 'gnus)
726 ;; Kill the startup file.
727 (and gnus-current-startup-file
728 (get-file-buffer gnus-current-startup-file)
729 (kill-buffer (get-file-buffer gnus-current-startup-file)))
730 ;; Clear the dribble buffer.
732 ;; Kill global KILL file buffer.
733 (when (get-file-buffer (gnus-newsgroup-kill-file nil))
734 (kill-buffer (get-file-buffer (gnus-newsgroup-kill-file nil))))
735 (gnus-kill-buffer nntp-server-buffer)
736 ;; Kill Gnus buffers.
737 (dolist (buffer (gnus-buffers))
738 (gnus-kill-buffer buffer))
739 ;; Remove Gnus frames.
740 (gnus-kill-gnus-frames))
742 (defun gnus-no-server-1 (&optional arg slave)
744 If ARG is a positive number, Gnus will use that as the
745 startup level. If ARG is nil, Gnus will be started at level 2.
746 If ARG is non-nil and not a positive number, Gnus will
747 prompt the user for the name of an NNTP server to use.
748 As opposed to `gnus', this command will not connect to the local server."
750 (let ((val (or arg (1- gnus-level-default-subscribed))))
752 (make-local-variable 'gnus-group-use-permanent-levels)
753 (setq gnus-group-use-permanent-levels val)))
755 (defun gnus-1 (&optional arg dont-connect slave)
757 If ARG is non-nil and a positive number, Gnus will use that as the
758 startup level. If ARG is non-nil and not a positive number, Gnus will
759 prompt the user for the name of an NNTP server to use."
764 (switch-to-buffer gnus-group-buffer)
765 (gnus-group-get-new-news
768 (max (car gnus-group-list-mode) arg))))
772 (gnus-run-hooks 'gnus-before-startup-hook)
773 (nnheader-init-server-buffer)
774 (setq gnus-slave slave)
775 (gnus-read-init-file)
779 (when gnus-simple-splash
780 (setq gnus-simple-splash nil)
785 (= (frame-height) (1+ (window-height))))
788 (let ((level (and (numberp arg) (> arg 0) arg))
794 (gnus-start-news-server (and arg (not level))))))
795 (if (and (not dont-connect)
798 (gnus-run-hooks 'gnus-startup-hook)
799 ;; NNTP server is successfully open.
801 ;; Find the current startup file name.
802 (setq gnus-current-startup-file
803 (gnus-make-newsrc-file gnus-startup-file))
805 ;; Read the dribble file.
806 (when (or gnus-slave gnus-use-dribble-file)
807 (gnus-dribble-read-file))
809 ;; Do the actual startup.
811 (gnus-request-create-group "queue" '(nndraft "")))
812 (gnus-request-create-group "drafts" '(nndraft ""))
813 (gnus-setup-news nil level dont-connect)
814 (gnus-run-hooks 'gnus-setup-news-hook)
815 (gnus-start-draft-setup)
816 ;; Generate the group buffer.
817 (gnus-group-list-groups level)
818 (gnus-group-first-unread-group)
819 (gnus-configure-windows 'group)
820 (gnus-group-set-mode-line)
822 (set-language-info "Japanese" 'gnus-info "gnus-ja")
823 (gnus-run-hooks 'gnus-started-hook))))))
825 (defun gnus-start-draft-setup ()
826 "Make sure the draft group exists."
827 (gnus-request-create-group "drafts" '(nndraft ""))
828 (unless (gnus-group-entry "nndraft:drafts")
829 (let ((gnus-level-default-subscribed 1))
830 (gnus-subscribe-group "nndraft:drafts" nil '(nndraft "")))
831 (gnus-group-set-parameter
832 "nndraft:drafts" 'gnus-dummy '((gnus-draft-mode)))))
839 (defvar gnus-dribble-ignore nil)
840 (defvar gnus-dribble-eval-file nil)
842 (defun gnus-dribble-file-name ()
843 "Return the dribble file for the current .newsrc."
845 (if gnus-dribble-directory
846 (concat (file-name-as-directory gnus-dribble-directory)
847 (file-name-nondirectory gnus-current-startup-file))
848 gnus-current-startup-file)
851 (defun gnus-dribble-enter (string)
852 "Enter STRING into the dribble buffer."
853 (when (and (not gnus-dribble-ignore)
855 (buffer-name gnus-dribble-buffer))
856 (let ((obuf (current-buffer)))
857 (set-buffer gnus-dribble-buffer)
858 (goto-char (point-max))
860 ;; This has been commented by Josh Huber <huber@alum.wpi.edu>
861 ;; It causes problems with both XEmacs and Emacs 21, and doesn't
862 ;; seem to be of much value. (FIXME: remove this after we make sure
864 ;; (set-window-point (get-buffer-window (current-buffer)) (point-max))
865 (bury-buffer gnus-dribble-buffer)
867 (set-buffer gnus-group-buffer)
868 (gnus-group-set-mode-line))
871 (defun gnus-dribble-touch ()
872 "Touch the dribble buffer."
873 (gnus-dribble-enter ""))
875 (defun gnus-dribble-read-file ()
876 "Read the dribble file from disk."
877 (let ((dribble-file (gnus-dribble-file-name)))
879 (set-buffer (setq gnus-dribble-buffer
880 (gnus-get-buffer-create
881 (file-name-nondirectory dribble-file))))
883 (setq buffer-file-name dribble-file)
885 (buffer-disable-undo)
886 (bury-buffer (current-buffer))
887 (set-buffer-modified-p nil)
888 (let ((auto (make-auto-save-file-name))
889 (gnus-dribble-ignore t)
892 (when (or (file-exists-p auto) (file-exists-p dribble-file))
893 ;; Load whichever file is newest -- the auto save file
894 ;; or the "real" file.
895 (if (file-newer-than-file-p auto dribble-file)
896 (nnheader-insert-file-contents auto)
897 (nnheader-insert-file-contents dribble-file))
898 (unless (zerop (buffer-size))
899 (set-buffer-modified-p t))
900 ;; Set the file modes to reflect the .newsrc file modes.
902 (when (and (file-exists-p gnus-current-startup-file)
903 (file-exists-p dribble-file)
904 (setq modes (file-modes gnus-current-startup-file)))
905 (gnus-set-file-modes dribble-file modes))
906 (goto-char (point-min))
907 (when (search-forward "Gnus was exited on purpose" nil t)
909 ;; Possibly eval the file later.
910 (when (or gnus-always-read-dribble-file
913 "Gnus exited on purpose without saving; read auto-save file anyway? "
914 "Gnus auto-save file exists. Do you want to read it? ")))
915 (setq gnus-dribble-eval-file t)))))))
917 (defun gnus-dribble-eval-file ()
918 (when gnus-dribble-eval-file
919 (setq gnus-dribble-eval-file nil)
921 (let ((gnus-dribble-ignore t))
922 (set-buffer gnus-dribble-buffer)
923 (eval-buffer (current-buffer))))))
925 (defun gnus-dribble-delete-file ()
926 (when (file-exists-p (gnus-dribble-file-name))
927 (delete-file (gnus-dribble-file-name)))
928 (when gnus-dribble-buffer
930 (set-buffer gnus-dribble-buffer)
931 (let ((auto (make-auto-save-file-name)))
932 (when (file-exists-p auto)
935 (set-buffer-modified-p nil)))))
937 (defun gnus-dribble-save ()
938 (when (and gnus-dribble-buffer
939 (buffer-name gnus-dribble-buffer))
941 (set-buffer gnus-dribble-buffer)
944 (defun gnus-dribble-clear ()
945 (when (gnus-buffer-exists-p gnus-dribble-buffer)
947 (set-buffer gnus-dribble-buffer)
949 (set-buffer-modified-p nil)
950 (setq buffer-saved-size (buffer-size)))))
954 ;;; Active & Newsrc File Handling
957 (defun gnus-setup-news (&optional rawfile level dont-connect)
958 "Setup news information.
959 If RAWFILE is non-nil, the .newsrc file will also be read.
960 If LEVEL is non-nil, the news will be set up at level LEVEL."
962 (let ((init (not (and gnus-newsrc-alist gnus-active-hashtb (not rawfile))))
963 ;; Binding this variable will inhibit multiple fetchings
964 ;; of the same mail source.
965 (nnmail-fetched-sources (list t)))
968 ;; Clear some variables to re-initialize news information.
969 (setq gnus-newsrc-alist nil
970 gnus-active-hashtb nil)
971 ;; Read the newsrc file and create `gnus-newsrc-hashtb'.
972 (gnus-read-newsrc-file rawfile))
974 ;; Make sure the archive server is available to all and sundry.
975 (when gnus-message-archive-method
976 (unless (assoc "archive" gnus-server-alist)
977 (let ((method (or (and (stringp gnus-message-archive-method)
978 (gnus-server-to-method
979 gnus-message-archive-method))
980 gnus-message-archive-method)))
981 ;; Check whether the archive method is writable.
982 (unless (or (stringp method)
983 (memq 'respool (assoc (format "%s" (car method))
984 gnus-valid-select-methods)))
985 (setq method "archive")) ;; The default.
986 (push (if (stringp method)
991 ,(nnheader-concat message-directory method))
992 (nnfolder-active-file
993 ,(nnheader-concat message-directory
994 (concat method "/active")))
995 (nnfolder-get-new-mail nil)
996 (nnfolder-inhibit-expiry t))
997 (cons "archive" method))
998 gnus-server-alist))))
1000 ;; If we don't read the complete active file, we fill in the
1002 (when (or (null gnus-read-active-file)
1003 (eq gnus-read-active-file 'some))
1004 (gnus-update-active-hashtb-from-killed))
1006 ;; Validate agent covered methods now that gnus-server-alist has
1007 ;; been initialized.
1008 ;; NOTE: This is here for one purpose only. By validating the
1009 ;; agentized server's, it converts the old 5.10.3, and earlier,
1010 ;; format to the current format. That enables the agent code
1011 ;; within gnus-read-active-file to function correctly.
1013 (gnus-agent-read-servers-validate))
1015 ;; Read the active file and create `gnus-active-hashtb'.
1016 ;; If `gnus-read-active-file' is nil, then we just create an empty
1017 ;; hash table. The partial filling out of the hash table will be
1018 ;; done in `gnus-get-unread-articles'.
1019 (and gnus-read-active-file
1021 (gnus-read-active-file nil dont-connect))
1023 (unless gnus-active-hashtb
1024 (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
1026 ;; Initialize the cache.
1027 (when gnus-use-cache
1030 ;; Possibly eval the dribble file.
1032 (or gnus-use-dribble-file gnus-slave)
1033 (gnus-dribble-eval-file))
1035 ;; Slave Gnusii should then clear the dribble buffer.
1036 (when (and init gnus-slave)
1037 (gnus-dribble-clear))
1039 (gnus-update-format-specifications)
1041 ;; See whether we need to read the description file.
1042 (when (and (boundp 'gnus-group-line-format)
1043 (stringp gnus-group-line-format)
1044 (let ((case-fold-search nil))
1045 (string-match "%[-,0-9]*D" gnus-group-line-format))
1046 (not gnus-description-hashtb)
1048 gnus-read-active-file)
1049 (gnus-read-all-descriptions-files))
1051 ;; Find new newsgroups and treat them.
1052 (when (and init gnus-check-new-newsgroups (not level)
1053 (gnus-check-server gnus-select-method)
1056 (gnus-find-new-newsgroups))
1058 ;; Check and remove bogus newsgroups.
1059 (when (and init gnus-check-bogus-newsgroups
1060 gnus-read-active-file (not level)
1061 (gnus-server-opened gnus-select-method))
1062 (gnus-check-bogus-newsgroups))
1064 ;; We might read in new NoCeM messages here.
1065 (when (and gnus-use-nocem
1068 (gnus-nocem-scan-groups))
1070 ;; Read any slave files.
1071 (gnus-master-read-slave-newsrc)
1073 ;; Find the number of unread articles in each non-dead group.
1074 (let ((gnus-read-active-file (and (not level) gnus-read-active-file)))
1075 (gnus-get-unread-articles level))))
1077 (defun gnus-call-subscribe-functions (method group)
1078 "Call METHOD to subscribe GROUP.
1079 If no function returns `non-nil', call `gnus-subscribe-zombies'."
1082 (funcall method group))
1085 (dolist (func method)
1086 (if (funcall func group)
1090 (gnus-subscribe-zombies group)))
1092 (defun gnus-find-new-newsgroups (&optional arg)
1093 "Search for new newsgroups and add them.
1094 Each new newsgroup will be treated with `gnus-subscribe-newsgroup-method'.
1095 The `-n' option line from .newsrc is respected.
1097 With 1 C-u, use the `ask-server' method to query the server for new
1099 With 2 C-u's, use most complete method possible to query the server
1100 for new groups, and subscribe the new groups as zombies."
1102 (let* ((gnus-subscribe-newsgroup-method
1103 gnus-subscribe-newsgroup-method)
1105 ((or (and (= (or arg 1) 4)
1106 (not (listp gnus-check-new-newsgroups)))
1107 (null gnus-read-active-file)
1108 (eq gnus-read-active-file 'some))
1111 (setq gnus-subscribe-newsgroup-method
1112 'gnus-subscribe-zombies)
1114 (t gnus-check-new-newsgroups))))
1115 (unless (gnus-check-first-time-used)
1116 (if (or (consp check)
1117 (eq check 'ask-server))
1118 ;; Ask the server for new groups.
1119 (gnus-ask-server-for-new-groups)
1120 ;; Go through the active hashtb and look for new groups.
1122 group new-newsgroups)
1123 (gnus-message 5 "Looking for new newsgroups...")
1124 (unless gnus-have-read-active-file
1125 (gnus-read-active-file))
1126 (setq gnus-newsrc-last-checked-date (message-make-date))
1127 (unless gnus-killed-hashtb
1128 (gnus-make-hashtable-from-killed))
1129 ;; Go though every newsgroup in `gnus-active-hashtb' and compare
1130 ;; with `gnus-newsrc-hashtb' and `gnus-killed-hashtb'.
1133 (if (or (null (setq group (symbol-name sym)))
1135 (null (symbol-value sym))
1136 (gnus-gethash group gnus-killed-hashtb)
1137 (gnus-gethash group gnus-newsrc-hashtb))
1139 (let ((do-sub (gnus-matches-options-n group)))
1141 ((eq do-sub 'subscribe)
1142 (setq groups (1+ groups))
1143 (gnus-sethash group group gnus-killed-hashtb)
1144 (gnus-call-subscribe-functions
1145 gnus-subscribe-options-newsgroup-method group))
1146 ((eq do-sub 'ignore)
1149 (setq groups (1+ groups))
1150 (gnus-sethash group group gnus-killed-hashtb)
1151 (if gnus-subscribe-hierarchical-interactive
1152 (push group new-newsgroups)
1153 (gnus-call-subscribe-functions
1154 gnus-subscribe-newsgroup-method group)))))))
1156 (when new-newsgroups
1157 (gnus-subscribe-hierarchical-interactive new-newsgroups))
1159 (gnus-message 5 "%d new newsgroup%s arrived."
1160 groups (if (> groups 1) "s have" " has"))
1161 (gnus-message 5 "No new newsgroups.")))))))
1163 (defun gnus-matches-options-n (group)
1164 ;; Returns `subscribe' if the group is to be unconditionally
1165 ;; subscribed, `ignore' if it is to be ignored, and nil if there is
1166 ;; no match for the group.
1168 ;; First we check the two user variables.
1170 ((and gnus-options-subscribe
1171 (string-match gnus-options-subscribe group))
1173 ((and gnus-auto-subscribed-groups
1174 (string-match gnus-auto-subscribed-groups group))
1176 ((and gnus-options-not-subscribe
1177 (string-match gnus-options-not-subscribe group))
1179 ;; Then we go through the list that was retrieved from the .newsrc
1180 ;; file. This list has elements on the form
1181 ;; `(REGEXP . {ignore,subscribe})'. The first match found (the list
1182 ;; is in the reverse order of the options line) is returned.
1184 (let ((regs gnus-newsrc-options-n))
1186 (not (string-match (caar regs) group)))
1187 (setq regs (cdr regs)))
1188 (and regs (cdar regs))))))
1190 (defun gnus-ask-server-for-new-groups ()
1191 (let* ((new-date (message-make-date))
1192 (date (or gnus-newsrc-last-checked-date new-date))
1193 (methods (cons gnus-select-method
1195 (when (gnus-archive-server-wanted-p)
1198 (and (consp gnus-check-new-newsgroups)
1199 gnus-check-new-newsgroups)
1200 gnus-secondary-select-methods))))
1202 group new-newsgroups got-new method hashtb
1203 gnus-override-subscribe-method)
1204 (unless gnus-killed-hashtb
1205 (gnus-make-hashtable-from-killed))
1206 ;; Go through both primary and secondary select methods and
1207 ;; request new newsgroups.
1208 (while (setq method (gnus-server-get-method nil (pop methods)))
1209 (setq new-newsgroups nil
1210 gnus-override-subscribe-method method)
1211 (when (and (gnus-check-server method)
1212 (gnus-request-newgroups date method))
1215 hashtb (gnus-make-hashtable 100))
1216 (set-buffer nntp-server-buffer)
1217 ;; Enter all the new groups into a hashtable.
1218 (gnus-active-to-gnus-format method hashtb 'ignore))
1219 ;; Now all new groups from `method' are in `hashtb'.
1222 (if (or (null (setq group (symbol-name group-sym)))
1223 (not (boundp group-sym))
1224 (null (symbol-value group-sym))
1225 (gnus-gethash group gnus-newsrc-hashtb)
1226 (member group gnus-zombie-list)
1227 (member group gnus-killed-list))
1228 ;; The group is already known.
1230 ;; Make this group active.
1231 (when (symbol-value group-sym)
1232 (gnus-set-active group (symbol-value group-sym)))
1233 ;; Check whether we want it or not.
1234 (let ((do-sub (gnus-matches-options-n group)))
1236 ((eq do-sub 'subscribe)
1238 (gnus-sethash group group gnus-killed-hashtb)
1239 (gnus-call-subscribe-functions
1240 gnus-subscribe-options-newsgroup-method group))
1241 ((eq do-sub 'ignore)
1245 (gnus-sethash group group gnus-killed-hashtb)
1246 (if gnus-subscribe-hierarchical-interactive
1247 (push group new-newsgroups)
1248 (gnus-call-subscribe-functions
1249 gnus-subscribe-newsgroup-method group)))))))
1251 (when new-newsgroups
1252 (gnus-subscribe-hierarchical-interactive new-newsgroups)))
1254 (gnus-message 5 "%d new newsgroup%s arrived"
1255 groups (if (> groups 1) "s have" " has"))
1256 (gnus-message 5 "No new newsgroups"))
1258 (setq gnus-newsrc-last-checked-date new-date))
1261 (defun gnus-check-first-time-used ()
1263 ;; First check if any of the following files exist. If they do,
1264 ;; it's not the first time the user has used Gnus.
1265 (dolist (file (list (concat gnus-current-startup-file ".el")
1266 (concat gnus-current-startup-file ".eld")
1267 (concat gnus-startup-file ".el")
1268 (concat gnus-startup-file ".eld")))
1269 (when (file-exists-p file)
1270 (throw 'ended nil)))
1271 (gnus-message 6 "First time user; subscribing you to default groups")
1272 (unless (gnus-read-active-file-p)
1273 (let ((gnus-read-active-file t))
1274 (gnus-read-active-file)))
1275 (setq gnus-newsrc-last-checked-date (message-make-date))
1276 ;; Subscribe to the default newsgroups.
1277 (let ((groups (or gnus-default-subscribed-newsgroups
1278 gnus-backup-default-subscribed-newsgroups))
1281 ;; If t, we subscribe (or not) all groups as if they were new.
1284 (when (setq group (symbol-name sym))
1285 (let ((do-sub (gnus-matches-options-n group)))
1287 ((eq do-sub 'subscribe)
1288 (gnus-sethash group group gnus-killed-hashtb)
1289 (gnus-call-subscribe-functions
1290 gnus-subscribe-options-newsgroup-method group))
1291 ((eq do-sub 'ignore)
1294 (push group gnus-killed-list))))))
1296 (dolist (group groups)
1297 ;; Only subscribe the default groups that are activated.
1298 (when (gnus-active group)
1299 (gnus-group-change-level
1300 group gnus-level-default-subscribed gnus-level-killed)))
1302 (set-buffer gnus-group-buffer)
1303 ;; Don't error if the group already exists. This happens when a
1304 ;; first-time user types 'F'. -- didier
1305 (gnus-group-make-help-group t))
1306 (when gnus-novice-user
1307 (gnus-message 7 "`A k' to list killed groups"))))))
1309 (defun gnus-subscribe-group (group &optional previous method)
1310 "Subscribe GROUP and put it after PREVIOUS."
1311 (gnus-group-change-level
1313 (list t group gnus-level-default-subscribed nil nil method)
1315 gnus-level-default-subscribed gnus-level-killed previous t)
1318 ;; `gnus-group-change-level' is the fundamental function for changing
1319 ;; subscription levels of newsgroups. This might mean just changing
1320 ;; from level 1 to 2, which is pretty trivial, from 2 to 6 or back
1321 ;; again, which subscribes/unsubscribes a group, which is equally
1322 ;; trivial. Changing from 1-7 to 8-9 means that you kill a group, and
1323 ;; from 8-9 to 1-7 means that you remove the group from the list of
1324 ;; killed (or zombie) groups and add them to the (kinda) subscribed
1325 ;; groups. And last but not least, moving from 8 to 9 and 9 to 8,
1326 ;; which is trivial.
1327 ;; ENTRY can either be a string (newsgroup name) or a list (if
1328 ;; FROMKILLED is t, it's a list on the format (NUM INFO-LIST),
1329 ;; otherwise it's a list in the format of the `gnus-newsrc-hashtb'
1331 ;; LEVEL is the new level of the group, OLDLEVEL is the old level and
1332 ;; PREVIOUS is the group (in hashtb entry format) to insert this group
1334 (defun gnus-group-change-level (entry level &optional oldlevel
1335 previous fromkilled)
1336 (let (group info active num)
1337 ;; Glean what info we can from the arguments
1339 (if fromkilled (setq group (nth 1 entry))
1340 (setq group (car (nth 2 entry))))
1342 (when (and (stringp entry)
1344 (< oldlevel gnus-level-zombie))
1345 (setq entry (gnus-group-entry entry)))
1346 (if (and (not oldlevel)
1348 (setq oldlevel (gnus-info-level (nth 2 entry)))
1349 (setq oldlevel (or oldlevel gnus-level-killed)))
1350 (when (stringp previous)
1351 (setq previous (gnus-group-entry previous)))
1353 (if (and (>= oldlevel gnus-level-zombie)
1354 (gnus-group-entry group))
1355 ;; We are trying to subscribe a group that is already
1359 (unless (gnus-ephemeral-group-p group)
1361 (format "(gnus-group-change-level %S %S %S %S %S)"
1362 group level oldlevel (car (nth 2 previous)) fromkilled)))
1364 ;; Then we remove the newgroup from any old structures, if needed.
1365 ;; If the group was killed, we remove it from the killed or zombie
1366 ;; list. If not, and it is in fact going to be killed, we remove
1367 ;; it from the newsrc hash table and assoc.
1369 ((>= oldlevel gnus-level-zombie)
1370 ;; oldlevel could be wrong.
1371 (setq gnus-zombie-list (delete group gnus-zombie-list))
1372 (setq gnus-killed-list (delete group gnus-killed-list)))
1374 (when (and (>= level gnus-level-zombie)
1376 (gnus-sethash (car (nth 2 entry)) nil gnus-newsrc-hashtb)
1378 (setcdr (gnus-group-entry (car (nth 3 entry)))
1380 (setcdr (cdr entry) (cdddr entry)))))
1382 ;; Finally we enter (if needed) the list where it is supposed to
1383 ;; go, and change the subscription level. If it is to be killed,
1384 ;; we enter it into the killed or zombie list.
1386 ((>= level gnus-level-zombie)
1387 ;; Remove from the hash table.
1388 (gnus-sethash group nil gnus-newsrc-hashtb)
1389 ;; We do not enter foreign groups into the list of dead
1391 (unless (gnus-group-foreign-p group)
1392 (if (= level gnus-level-zombie)
1393 (push group gnus-zombie-list)
1394 (if (= oldlevel gnus-level-killed)
1395 ;; Remove from active hashtb.
1396 (unintern group gnus-active-hashtb)
1397 ;; Don't add it into killed-list if it was killed.
1398 (push group gnus-killed-list)))))
1400 ;; If the list is to be entered into the newsrc assoc, and
1401 ;; it was killed, we have to create an entry in the newsrc
1402 ;; hashtb format and fix the pointers in the newsrc assoc.
1403 (if (< oldlevel gnus-level-zombie)
1404 ;; It was alive, and it is going to stay alive, so we
1405 ;; just change the level and don't change any pointers or
1406 ;; hash table entries.
1407 (setcar (cdaddr entry) level)
1409 (setq info (cdr entry)
1411 (setq active (gnus-active group))
1413 (if active (- (1+ (cdr active)) (car active)) t))
1414 ;; Shorten the select method if possible, if we need to
1415 ;; store it at all (native groups).
1416 (let ((method (gnus-method-simplify
1417 (or gnus-override-subscribe-method
1418 (gnus-group-method group)))))
1420 (setq info (list group level nil nil method))
1421 (setq info (list group level nil)))))
1424 (let ((p gnus-newsrc-alist))
1428 (setq entry (cons info (cddr previous)))
1431 (setcdr (cdr previous) entry)
1432 (gnus-sethash group (cons num (cdr previous))
1433 gnus-newsrc-hashtb))
1434 (setcdr previous entry)
1435 (gnus-sethash group (cons num previous)
1436 gnus-newsrc-hashtb))
1438 (setcdr (gnus-group-entry (caadr entry)) entry))
1441 "(gnus-group-set-info '%S)" info)))))
1442 (when gnus-group-change-level-function
1443 (funcall gnus-group-change-level-function
1444 group level oldlevel previous)))))
1446 (defun gnus-kill-newsgroup (newsgroup)
1447 "Obsolete function. Kills a newsgroup."
1448 (gnus-group-change-level
1449 (gnus-group-entry newsgroup) gnus-level-killed))
1451 (defun gnus-check-bogus-newsgroups (&optional confirm)
1452 "Remove bogus newsgroups.
1453 If CONFIRM is non-nil, the user has to confirm the deletion of every
1455 (let ((newsrc (cdr gnus-newsrc-alist))
1456 bogus group entry info)
1457 (gnus-message 5 "Checking bogus newsgroups...")
1458 (unless (gnus-read-active-file-p)
1459 (gnus-read-active-file t))
1460 (when (gnus-read-active-file-p)
1461 ;; Find all bogus newsgroup that are subscribed.
1463 (setq info (pop newsrc)
1464 group (gnus-info-group info))
1465 (unless (or (gnus-active group) ; Active
1466 (and (gnus-info-method info)
1467 (not (gnus-secondary-method-p
1468 (gnus-info-method info))))) ; Foreign
1469 ;; Found a bogus newsgroup.
1470 (push group bogus)))
1473 "Remove bogus group %s? "
1475 ;; Remove all bogus subscribed groups by first killing them, and
1476 ;; then removing them from the list of killed groups.
1477 (when (setq entry (gnus-group-entry group))
1478 (gnus-group-change-level entry gnus-level-killed)
1479 (setq gnus-killed-list (delete group gnus-killed-list))))
1480 bogus '("group" "groups" "remove"))
1481 (while (setq group (pop bogus))
1482 ;; Remove all bogus subscribed groups by first killing them, and
1483 ;; then removing them from the list of killed groups.
1484 (when (setq entry (gnus-group-entry group))
1485 (gnus-group-change-level entry gnus-level-killed)
1486 (setq gnus-killed-list (delete group gnus-killed-list)))))
1487 ;; Then we remove all bogus groups from the list of killed and
1488 ;; zombie groups. They are removed without confirmation.
1489 (let ((dead-lists '(gnus-killed-list gnus-zombie-list))
1492 (setq killed (symbol-value (car dead-lists)))
1494 (unless (gnus-active (setq group (pop killed)))
1495 ;; The group is bogus.
1497 (set (car dead-lists)
1498 (delete group (symbol-value (car dead-lists))))))
1499 (setq dead-lists (cdr dead-lists))))
1500 (gnus-run-hooks 'gnus-check-bogus-groups-hook)
1501 (gnus-message 5 "Checking bogus newsgroups...done"))))
1503 (defun gnus-check-duplicate-killed-groups ()
1504 "Remove duplicates from the list of killed groups."
1506 (let ((killed gnus-killed-list))
1508 (gnus-message 9 "%d" (length killed))
1509 (setcdr killed (delete (car killed) (cdr killed)))
1510 (setq killed (cdr killed)))))
1512 ;; We want to inline a function from gnus-cache, so we cheat here:
1514 (defvar gnus-cache-active-hashtb)
1515 (defun gnus-cache-possibly-alter-active (group active)
1516 "Alter the ACTIVE info for GROUP to reflect the articles in the cache."
1517 (when gnus-cache-active-hashtb
1518 (let ((cache-active (gnus-gethash group gnus-cache-active-hashtb)))
1520 (when (< (car cache-active) (car active))
1521 (setcar active (car cache-active)))
1522 (when (> (cdr cache-active) (cdr active))
1523 (setcdr active (cdr cache-active))))))))
1525 (defun gnus-activate-group (group &optional scan dont-check method)
1526 "Check whether a group has been activated or not.
1527 If SCAN, request a scan of that group as well."
1528 (let ((method (or method (inline (gnus-find-method-for-group group))))
1530 (and (inline (gnus-check-server method))
1531 ;; We escape all bugs and quit here to make it possible to
1532 ;; continue if a group is so out-there that it reports bugs
1536 (gnus-check-backend-function 'request-scan (car method))
1537 (gnus-request-scan group method))
1539 (if (or debug-on-error debug-on-quit)
1540 (inline (gnus-request-group group dont-check method))
1542 (inline (gnus-request-group group dont-check method))
1545 (message "Quit activating %s" group)
1548 (setq active (gnus-parse-active))
1549 ;; If there are no articles in the group, the GROUP
1550 ;; command may have responded with the `(0 . 0)'. We
1551 ;; ignore this if we already have an active entry
1553 (if (and (zerop (or (car active) 0))
1554 (zerop (or (cdr active) 0))
1555 (gnus-active group))
1558 ;; If a cache is present, we may have to alter the active info.
1559 (when gnus-use-cache
1560 (inline (gnus-cache-possibly-alter-active
1563 ;; If the agent is enabled, we may have to alter the active info.
1565 (gnus-agent-possibly-alter-active group active))
1567 (gnus-set-active group active)
1568 ;; Return the new active info.
1571 (defun gnus-get-unread-articles-in-group (info active &optional update)
1572 (when (and info active)
1573 ;; Allow the backend to update the info in the group.
1575 (gnus-request-update-info
1576 info (inline (gnus-find-method-for-group
1577 (gnus-info-group info)))))
1578 (gnus-activate-group (gnus-info-group info) nil t))
1580 (let* ((range (gnus-info-read info))
1583 ;; These checks are present in gnus-activate-group but skipped
1584 ;; due to setting dont-check in the preceeding call.
1586 ;; If a cache is present, we may have to alter the active info.
1587 (when (and gnus-use-cache info)
1588 (inline (gnus-cache-possibly-alter-active
1589 (gnus-info-group info) active)))
1591 ;; If the agent is enabled, we may have to alter the active info.
1592 (when (and gnus-agent info)
1593 (gnus-agent-possibly-alter-active (gnus-info-group info) active info))
1595 ;; Modify the list of read articles according to what articles
1596 ;; are available; then tally the unread articles and add the
1597 ;; number to the group hash table entry.
1599 ((zerop (cdr active))
1602 (setq num (- (1+ (cdr active)) (car active))))
1603 ((not (listp (cdr range)))
1604 ;; Fix a single (num . num) range according to the
1605 ;; active hash table.
1606 ;; Fix by Carsten Bormann <cabo@Informatik.Uni-Bremen.DE>.
1607 (and (< (cdr range) (car active)) (setcdr range (1- (car active))))
1608 (and (> (cdr range) (cdr active)) (setcdr range (cdr active)))
1609 ;; Compute number of unread articles.
1610 (setq num (max 0 (- (cdr active) (- (1+ (cdr range)) (car range))))))
1612 ;; The read list is a list of ranges. Fix them according to
1613 ;; the active hash table.
1614 ;; First peel off any elements that are below the lower
1616 (while (and (cdr range)
1618 (or (and (atom (cadr range)) (cadr range))
1620 (if (numberp (car range))
1623 (or (and (numberp (cadr range))
1627 (or (and (numberp (nth 1 range)) (nth 1 range))
1629 (setcdr range (cddr range)))
1630 ;; Adjust the first element to be the same as the lower limit.
1631 (when (and (not (atom (car range)))
1632 (< (cdar range) (car active)))
1633 (setcdr (car range) (1- (car active))))
1634 ;; Then we want to peel off any elements that are higher
1635 ;; than the upper active limit.
1636 (let ((srange range))
1637 ;; Go past all valid elements.
1638 (while (and (cdr srange)
1639 (<= (or (and (atom (cadr srange))
1643 (setq srange (cdr srange)))
1645 ;; Nuke all remaining invalid elements.
1646 (setcdr srange nil))
1648 ;; Adjust the final element.
1649 (when (and (not (atom (car srange)))
1650 (> (cdar srange) (cdr active)))
1651 (setcdr (car srange) (cdr active))))
1652 ;; Compute the number of unread articles.
1654 (setq num (+ num (- (1+ (or (and (atom (car range)) (car range))
1656 (or (and (atom (car range)) (car range))
1658 (setq range (cdr range)))
1659 (setq num (max 0 (- (cdr active) num)))))
1660 ;; Set the number of unread articles.
1662 (gnus-group-entry (gnus-info-group info)))
1663 (setcar (gnus-group-entry (gnus-info-group info)) num))
1666 ;; Go though `gnus-newsrc-alist' and compare with `gnus-active-hashtb'
1667 ;; and compute how many unread articles there are in each group.
1668 (defun gnus-get-unread-articles (&optional level)
1669 (setq gnus-server-method-cache nil)
1670 (let* ((newsrc (cdr gnus-newsrc-alist))
1671 (level (or level gnus-activate-level (1+ gnus-level-subscribed)))
1674 (cond ((and gnus-activate-foreign-newsgroups
1675 (not (numberp gnus-activate-foreign-newsgroups)))
1676 (1+ gnus-level-subscribed))
1677 ((numberp gnus-activate-foreign-newsgroups)
1678 gnus-activate-foreign-newsgroups)
1683 scanned-methods info group active method retrieve-groups cmethod
1685 (gnus-message 6 "Checking new news...")
1688 (setq active (gnus-active (setq group (gnus-info-group
1689 (setq info (pop newsrc))))))
1691 ;; Check newsgroups. If the user doesn't want to check them, or
1692 ;; they can't be checked (for instance, if the news server can't
1693 ;; be reached) we just set the number of unread articles in this
1694 ;; newsgroup to t. This means that Gnus thinks that there are
1695 ;; unread articles, but it has no idea how many.
1697 ;; To be more explicit:
1698 ;; >0 for an active group with messages
1699 ;; 0 for an active group with no unread messages
1700 ;; nil for non-foreign groups that the user has requested not be checked
1701 ;; t for unchecked foreign groups or bogus groups, or groups that can't
1702 ;; be checked, for one reason or other.
1703 (when (setq method (gnus-info-method info))
1704 (if (setq cmethod (assoc method methods-cache))
1705 (setq method (cdr cmethod))
1706 (setq cmethod (inline (gnus-server-get-method nil method)))
1707 (push (cons method cmethod) methods-cache)
1708 (setq method cmethod)))
1710 (not (setq method-type (cdr (assoc method type-cache)))))
1713 ((gnus-secondary-method-p method)
1715 ((inline (gnus-server-equal gnus-select-method method))
1719 (push (cons method method-type) type-cache))
1722 (cond ((and method (eq method-type 'foreign))
1723 ;; These groups are foreign. Check the level.
1724 (if (<= (gnus-info-level info) foreign-level)
1725 (when (setq active (gnus-activate-group group 'scan))
1726 ;; Let the Gnus agent save the active file.
1727 (when (and gnus-agent active (gnus-online method))
1728 (gnus-agent-save-group-info
1729 method (gnus-group-real-name group) active))
1730 (unless (inline (gnus-virtual-group-p group))
1731 (inline (gnus-close-group group)))
1732 (when (fboundp (intern (concat (symbol-name (car method))
1733 "-request-update-info")))
1734 (inline (gnus-request-update-info info method))))
1736 ;; These groups are native or secondary.
1737 ((> (gnus-info-level info) level)
1738 ;; We don't want these groups.
1739 (setq active 'ignore))
1741 ((not gnus-read-active-file)
1742 (if (gnus-check-backend-function 'retrieve-groups group)
1743 ;; if server support gnus-retrieve-groups we push
1744 ;; the group onto retrievegroups for later checking
1745 (if (assoc method retrieve-groups)
1746 (setcdr (assoc method retrieve-groups)
1747 (cons group (cdr (assoc method retrieve-groups))))
1748 (push (list method group) retrieve-groups))
1749 ;; hack: `nnmail-get-new-mail' changes the mail-source depending
1750 ;; on the group, so we must perform a scan for every group
1751 ;; if the users has any directory mail sources.
1752 ;; hack: if `nnmail-scan-directory-mail-source-once' is non-nil,
1753 ;; for it scan all spool files even when the groups are
1756 (or nnmail-scan-directory-mail-source-once
1757 (null (assq 'directory
1759 (if (listp nnmail-spool-file)
1761 (list nnmail-spool-file))))))
1762 (member method scanned-methods))
1763 (setq active (gnus-activate-group group))
1764 (setq active (gnus-activate-group group 'scan))
1765 (push method scanned-methods))
1767 (gnus-close-group group)))))
1769 ;; Get the number of unread articles in the group.
1771 ((eq active 'ignore)
1772 ;; Don't do anything.
1774 ((and active ignore)
1775 ;; The level of the foreign group is higher than the specified
1779 (inline (gnus-get-unread-articles-in-group info active t)))
1781 ;; The group couldn't be reached, so we nix out the number of
1782 ;; unread articles and stuff.
1783 (gnus-set-active group nil)
1784 (let ((tmp (gnus-group-entry group)))
1788 ;; iterate through groups on methods which support gnus-retrieve-groups
1789 ;; and fetch a partial active file and use it to find new news.
1790 (dolist (rg retrieve-groups)
1791 (let ((method (or (car rg) gnus-select-method))
1793 (when (gnus-check-server method)
1794 ;; Request that the backend scan its incoming messages.
1795 (when (gnus-check-backend-function 'request-scan (car method))
1796 (gnus-request-scan nil method))
1797 (gnus-read-active-file-2
1798 (mapcar (lambda (group) (gnus-group-real-name group)) groups)
1800 (dolist (group groups)
1802 ((setq active (gnus-active (gnus-info-group
1803 (setq info (gnus-get-info group)))))
1804 (inline (gnus-get-unread-articles-in-group info active t)))
1806 ;; The group couldn't be reached, so we nix out the number of
1807 ;; unread articles and stuff.
1808 (gnus-set-active group nil)
1809 (setcar (gnus-group-entry group) t)))))))
1811 (gnus-message 6 "Checking new news...done")))
1813 ;; Create a hash table out of the newsrc alist. The `car's of the
1814 ;; alist elements are used as keys.
1815 (defun gnus-make-hashtable-from-newsrc-alist ()
1816 (let ((alist gnus-newsrc-alist)
1817 (ohashtb gnus-newsrc-hashtb)
1818 prev info method rest methods)
1819 (setq gnus-newsrc-hashtb (gnus-make-hashtable (length alist)))
1821 (setq prev (setq gnus-newsrc-alist
1822 (if (equal (caar gnus-newsrc-alist)
1825 (cons (list "dummy.group" 0 nil) alist)))))
1827 (setq info (car alist))
1828 ;; Make the same select-methods identical Lisp objects.
1829 (when (setq method (gnus-info-method info))
1830 (if (setq rest (member method methods))
1831 (gnus-info-set-method info (car rest))
1832 (push method methods)))
1835 ;; Preserve number of unread articles in groups.
1836 (cons (and ohashtb (car (gnus-gethash (car info) ohashtb)))
1841 ;; Make the same select-methods in `gnus-server-alist' identical
1844 (setq method (pop methods))
1845 (when (setq rest (rassoc method gnus-server-alist))
1846 (setcdr rest method)))))
1848 (defun gnus-make-hashtable-from-killed ()
1849 "Create a hash table from the killed and zombie lists."
1850 (let ((lists '(gnus-killed-list gnus-zombie-list))
1852 (setq gnus-killed-hashtb
1853 (gnus-make-hashtable
1854 (+ (length gnus-killed-list) (length gnus-zombie-list))))
1856 (setq list (symbol-value (pop lists)))
1858 (gnus-sethash (car list) (pop list) gnus-killed-hashtb)))))
1860 (defun gnus-parse-active ()
1861 "Parse active info in the nntp server buffer."
1863 (set-buffer nntp-server-buffer)
1864 (goto-char (point-min))
1865 ;; Parse the result we got from `gnus-request-group'.
1866 (when (looking-at "[0-9]+ [0-9]+ \\([0-9]+\\) [0-9]+")
1867 (goto-char (match-beginning 1))
1868 (cons (read (current-buffer))
1869 (read (current-buffer))))))
1871 (defun gnus-make-articles-unread (group articles)
1872 "Mark ARTICLES in GROUP as unread."
1873 (let* ((info (nth 2 (or (gnus-group-entry group)
1875 (gnus-group-real-name group)))))
1876 (ranges (gnus-info-read info))
1879 (when (gnus-member-of-range
1880 (setq article (pop articles)) ranges)
1881 (push article news)))
1883 ;; Enter this list into the group info.
1885 info (gnus-remove-from-range (gnus-info-read info) (nreverse news)))
1887 ;; Set the number of unread articles in gnus-newsrc-hashtb.
1888 (gnus-get-unread-articles-in-group info (gnus-active group))
1890 ;; Insert the change into the group buffer and the dribble file.
1891 (gnus-group-update-group group t))))
1893 (defun gnus-make-ascending-articles-unread (group articles)
1894 "Mark ascending ARTICLES in GROUP as unread."
1895 (let* ((entry (or (gnus-group-entry group)
1896 (gnus-group-entry (gnus-group-real-name group))))
1897 (info (nth 2 entry))
1898 (ranges (gnus-info-read info))
1903 (let ((article (pop articles))) ; get the next article to remove from ranges
1904 (while (let ((range (car ranges))) ; note the current range
1905 (if (atom range) ; single value range
1907 ;; the articles extend past the end of the ranges
1909 (setq articles nil))
1911 ;; this range preceeds the article. Leave the range unmodified.
1915 ;; this range exactly matches the article; REMOVE THE RANGE.
1916 ;; NOTE: When the range being removed is the last range, the list is corrupted by inserting null at its end.
1917 (setcar ranges (cadr ranges))
1918 (setcdr ranges (cddr ranges))
1919 (setq modified (if (car ranges) t 'remove-null))
1921 (let ((min (car range))
1923 ;; I have a min/max range to consider
1924 (cond ((> min max) ; invalid range introduced by splitter
1925 (setcar ranges (cadr ranges))
1926 (setcdr ranges (cddr ranges))
1927 (setq modified (if (car ranges) t 'remove-null))
1930 ;; replace min/max range with a single-value range
1934 ;; this range preceeds the article. Leave the range unmodified.
1938 ;; this article preceeds the range. Return null to move to the
1942 ;; this article splits the range into two parts
1943 (setcdr ranges (cons (cons (1+ article) max) (cdr ranges)))
1944 (setcdr range (1- article))
1949 (when (eq modified 'remove-null)
1950 (setq r (delq nil r)))
1951 ;; Enter this list into the group info.
1952 (gnus-info-set-read info r)
1954 ;; Set the number of unread articles in gnus-newsrc-hashtb.
1955 (gnus-get-unread-articles-in-group info (gnus-active group))
1957 ;; Insert the change into the group buffer and the dribble file.
1958 (gnus-group-update-group group t))))
1960 ;; Enter all dead groups into the hashtb.
1961 (defun gnus-update-active-hashtb-from-killed ()
1962 (let ((hashtb (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
1963 (lists (list gnus-killed-list gnus-zombie-list))
1966 (setq killed (car lists))
1968 (gnus-sethash (car killed) nil hashtb)
1969 (setq killed (cdr killed)))
1970 (setq lists (cdr lists)))))
1972 (defun gnus-get-killed-groups ()
1973 "Go through the active hashtb and mark all unknown groups as killed."
1974 ;; First make sure active file has been read.
1975 (unless (gnus-read-active-file-p)
1976 (let ((gnus-read-active-file t))
1977 (gnus-read-active-file)))
1978 (unless gnus-killed-hashtb
1979 (gnus-make-hashtable-from-killed))
1980 ;; Go through all newsgroups that are known to Gnus - enlarge kill list.
1984 (group (symbol-name sym)))
1985 (if (or (null group)
1986 (gnus-gethash group gnus-killed-hashtb)
1987 (gnus-gethash group gnus-newsrc-hashtb))
1989 (let ((do-sub (gnus-matches-options-n group)))
1990 (if (or (eq do-sub 'subscribe) (eq do-sub 'ignore))
1992 (setq groups (1+ groups))
1993 (push group gnus-killed-list)
1994 (gnus-sethash group group gnus-killed-hashtb))))))
1996 (gnus-dribble-touch))
1998 ;; Get the active file(s) from the backend(s).
1999 (defun gnus-read-active-file (&optional force not-native)
2000 (gnus-group-set-mode-line)
2003 (lambda (m) (if (stringp m) (gnus-server-get-method nil m) m))
2005 (if (and (not not-native)
2006 (gnus-check-server gnus-select-method))
2007 ;; The native server is available.
2008 (cons gnus-select-method gnus-secondary-select-methods)
2009 ;; The native server is down, so we just do the
2011 gnus-secondary-select-methods)
2012 ;; Also read from the archive server.
2013 (when (gnus-archive-server-wanted-p)
2014 (list "archive")))))
2016 (setq gnus-have-read-active-file nil)
2018 (set-buffer nntp-server-buffer)
2019 (while (setq method (pop methods))
2020 ;; Only do each method once, in case the methods appear more
2021 ;; than once in this list.
2022 (unless (member method methods)
2023 (if (or debug-on-error debug-on-quit)
2024 (gnus-read-active-file-1 method force)
2026 (gnus-read-active-file-1 method force)
2027 ;; We catch C-g so that we can continue past servers
2028 ;; that do not respond.
2030 (message "Quit reading the active file")
2033 (defun gnus-read-active-file-1 (method force)
2035 (setq where (nth 1 method)
2036 mesg (format "Reading active file%s via %s..."
2037 (if (and where (not (zerop (length where))))
2038 (concat " from " where) "")
2040 (gnus-message 5 mesg)
2041 (when (gnus-check-server method)
2042 ;; Request that the backend scan its incoming messages.
2043 (when (gnus-check-backend-function 'request-scan (car method))
2044 (gnus-request-scan nil method))
2046 ((and (eq gnus-read-active-file 'some)
2047 (gnus-check-backend-function 'retrieve-groups (car method))
2049 (let ((newsrc (cdr gnus-newsrc-alist))
2050 (gmethod (gnus-server-get-method nil method))
2052 (while (setq info (pop newsrc))
2056 (gnus-find-method-for-group
2057 (gnus-info-group info) info))
2059 (push (gnus-group-real-name (gnus-info-group info))
2061 (gnus-read-active-file-2 groups method)))
2065 (if (not (gnus-request-list method))
2066 (unless (equal method gnus-message-archive-method)
2067 (gnus-error 1 "Cannot read active file from %s server"
2069 (gnus-message 5 mesg)
2070 (gnus-active-to-gnus-format method gnus-active-hashtb nil t)
2071 ;; We mark this active file as read.
2072 (push method gnus-have-read-active-file)
2073 (gnus-message 5 "%sdone" mesg)))))))
2075 (defun gnus-read-active-file-2 (groups method)
2076 "Read an active file for GROUPS in METHOD using `gnus-retrieve-groups'."
2079 (set-buffer nntp-server-buffer)
2080 (gnus-check-server method)
2081 (let ((list-type (gnus-retrieve-groups groups method)))
2082 (cond ((not list-type)
2084 1.2 "Cannot read partial active file from %s server."
2086 ((eq list-type 'active)
2087 (gnus-active-to-gnus-format method gnus-active-hashtb nil t))
2089 (gnus-groups-to-gnus-format method gnus-active-hashtb t)))))))
2091 ;; Read an active file and place the results in `gnus-active-hashtb'.
2092 (defun gnus-active-to-gnus-format (&optional method hashtb ignore-errors
2095 (setq method gnus-select-method))
2096 (let ((cur (current-buffer))
2098 (if (and gnus-active-hashtb
2099 (not (equal method gnus-select-method)))
2101 (setq gnus-active-hashtb
2102 (if (equal method gnus-select-method)
2103 (gnus-make-hashtable
2104 (count-lines (point-min) (point-max)))
2105 (gnus-make-hashtable 4096)))))))
2106 ;; Delete unnecessary lines.
2107 (goto-char (point-min))
2109 ((string= gnus-ignored-newsgroups "")
2110 (delete-matching-lines "^to\\."))
2112 (delete-matching-lines (concat "^to\\.\\|" gnus-ignored-newsgroups))))
2114 (goto-char (point-min))
2115 (unless (re-search-forward "[\\\"]" nil t)
2116 ;; Make the group names readable as a lisp expression even if they
2117 ;; contain special characters.
2118 (goto-char (point-max))
2119 (while (re-search-backward "[][';?()#]" nil t)
2122 ;; Let the Gnus agent save the active file.
2123 (when (and gnus-agent real-active (gnus-online method))
2124 (gnus-agent-save-active method))
2126 ;; If these are groups from a foreign select method, we insert the
2127 ;; group prefix in front of the group names.
2128 (when (not (gnus-server-equal
2129 (gnus-server-get-method nil method)
2130 (gnus-server-get-method nil gnus-select-method)))
2131 (let ((prefix (gnus-group-prefixed-name "" method)))
2132 (goto-char (point-min))
2133 (while (and (not (eobp))
2135 (when (= (following-char) ?\")
2138 (zerop (forward-line 1)))))))
2139 ;; Store the active file in a hash table.
2140 (goto-char (point-min))
2141 (let (group max min)
2145 (narrow-to-region (point) (point-at-eol))
2146 ;; group gets set to a symbol interned in the hash table
2147 ;; (what a hack!!) - jwz
2148 (setq group (let ((obarray hashtb)) (read cur)))
2149 ;; ### The extended group name scheme makes
2150 ;; the previous optimization strategy sort of pointless...
2151 (when (stringp group)
2152 (setq group (intern group hashtb)))
2153 (if (and (numberp (setq max (read cur)))
2154 (numberp (setq min (read cur)))
2156 (skip-chars-forward " \t")
2158 (or (eq (char-after) ?=)
2159 (eq (char-after) ?x)
2160 (eq (char-after) ?j)))))
2162 (set group (cons min max))
2163 ;; if group is moderated, stick in moderation table
2164 (when (eq (char-after) ?m)
2165 (unless gnus-moderated-hashtb
2166 (setq gnus-moderated-hashtb (gnus-make-hashtable)))
2167 (gnus-sethash (symbol-name group) t
2168 gnus-moderated-hashtb)))
2174 (unless ignore-errors
2175 (gnus-message 3 "Warning - invalid active: %s"
2177 (point-at-bol) (point-at-eol))))))
2179 (forward-line 1)))))
2181 (defun gnus-groups-to-gnus-format (method &optional hashtb real-active)
2182 ;; Parse a "groups" active file.
2183 (let ((cur (current-buffer))
2185 (if (and method gnus-active-hashtb)
2187 (setq gnus-active-hashtb
2188 (gnus-make-hashtable
2189 (count-lines (point-min) (point-max)))))))
2191 (not (gnus-server-equal
2192 (gnus-server-get-method nil method)
2193 (gnus-server-get-method nil gnus-select-method)))
2194 (gnus-group-prefixed-name "" method))))
2196 ;; Let the Gnus agent save the active file.
2199 (gnus-online method)
2200 (gnus-agent-method-p method))
2202 (gnus-agent-save-active method)
2203 (gnus-active-to-gnus-format method hashtb nil real-active))
2205 (goto-char (point-min))
2206 ;; We split this into to separate loops, one with the prefix
2207 ;; and one without to speed the reading up somewhat.
2209 (let (min max opoint group)
2213 (read cur) (read cur)
2214 (setq min (read cur)
2217 (skip-chars-forward " \t")
2220 (set (let ((obarray hashtb)) (read cur))
2222 (error (and group (symbolp group) (set group nil))))
2224 (let (min max group)
2227 (when (eq (char-after) ?2)
2228 (read cur) (read cur)
2229 (setq min (read cur)
2231 (set (setq group (let ((obarray hashtb)) (read cur)))
2233 (error (and group (symbolp group) (set group nil))))
2234 (forward-line 1)))))))
2236 (defun gnus-read-newsrc-file (&optional force)
2238 If FORCE is non-nil, the .newsrc file is read."
2239 ;; Reset variables that might be defined in the .newsrc.eld file.
2240 (gnus-clear-quick-file-variables)
2241 (let* ((newsrc-file gnus-current-startup-file)
2242 (quick-file (concat newsrc-file ".el")))
2244 ;; We always load the .newsrc.eld file. If always contains
2245 ;; much information that can not be gotten from the .newsrc
2246 ;; file (ticked articles, killed groups, foreign methods, etc.)
2247 (gnus-read-newsrc-el-file quick-file)
2249 (when (and gnus-read-newsrc-file
2250 (file-exists-p gnus-current-startup-file)
2252 (and (file-newer-than-file-p newsrc-file quick-file)
2253 (file-newer-than-file-p newsrc-file
2254 (concat quick-file "d")))
2255 (not gnus-newsrc-alist)))
2256 ;; We read the .newsrc file. Note that if there if a
2257 ;; .newsrc.eld file exists, it has already been read, and
2258 ;; the `gnus-newsrc-hashtb' has been created. While reading
2259 ;; the .newsrc file, Gnus will only use the information it
2260 ;; can find there for changing the data already read -
2261 ;; i. e., reading the .newsrc file will not trash the data
2262 ;; already read (except for read articles).
2264 (gnus-message 5 "Reading %s..." newsrc-file)
2265 (set-buffer (nnheader-find-file-noselect newsrc-file))
2266 (buffer-disable-undo)
2267 (gnus-newsrc-to-gnus-format)
2268 (kill-buffer (current-buffer))
2269 (gnus-message 5 "Reading %s...done" newsrc-file))))))
2271 (quote (;; T-gnus doesn't provide those functions.
2272 (defun gnus-convert-old-newsrc ()
2273 "Convert old newsrc formats into the current format, if needed."
2274 (let ((fcv (and gnus-newsrc-file-version
2275 (gnus-continuum-version gnus-newsrc-file-version)))
2276 (gcv (gnus-continuum-version)))
2278 ;; A newsrc file was loaded.
2279 (let (prompt-displayed
2282 (mapcar (lambda (date-func)
2283 (cons (gnus-continuum-version (car date-func))
2285 ;; This is a list of converters that must be run
2286 ;; to bring the newsrc file up to the current
2287 ;; version. If you create an incompatibility
2288 ;; with older versions, you should create an
2289 ;; entry here. The entry should consist of the
2290 ;; current gnus version (hardcoded so that it
2291 ;; doesn't change with each release) and the
2292 ;; function that must be applied to convert the
2293 ;; previous version into the current version.
2294 '(("September Gnus v0.1" nil
2295 gnus-convert-old-ticks)
2296 ("Oort Gnus v0.08" "legacy-gnus-agent"
2297 gnus-agent-convert-to-compressed-agentview)
2298 ("Gnus v5.10.7" "legacy-gnus-agent"
2299 gnus-agent-unlist-expire-days)
2300 ("Gnus v5.10.7" "legacy-gnus-agent"
2301 gnus-agent-unhook-expire-days)))
2302 #'car-less-than-car)))
2303 ;; Skip converters older than the file version
2304 (while (and converters (>= fcv (caar converters)))
2307 ;; Perform converters to bring older version up to date.
2308 (when (and converters (< fcv (caar converters)))
2309 (while (and converters (< fcv (caar converters))
2310 (<= (caar converters) gcv))
2311 (let* ((converter-spec (pop converters))
2312 (convert-to (nth 1 converter-spec))
2313 (load-from (nth 2 converter-spec))
2314 (func (nth 3 converter-spec)))
2315 (when (and load-from
2316 (not (fboundp func)))
2318 (or prompt-displayed
2319 (not (gnus-convert-converter-needs-prompt func))
2321 (cursor-in-echo-area t)
2322 (echo-keystrokes 0))
2323 (message "Convert gnus from version '%s' to '%s'? (n/y/?)"
2324 gnus-newsrc-file-version gnus-version)
2325 (setq c (read-char-exclusive))
2327 (cond ((or (eq c ?n) (eq c ?N))
2328 (error "Can not start gnus without converting"))
2329 ((or (eq c ?y) (eq c ?Y))
2330 (setq prompt-displayed t)
2333 (message "This conversion is irreversible. \
2334 To be safe, you should backup your files before proceeding.")
2338 (gnus-message 3 "Ignoring unexpected input")
2342 (funcall func convert-to)))
2344 (format ";Converted gnus from version '%s' to '%s'."
2345 gnus-newsrc-file-version gnus-version)))))))
2347 (defun gnus-convert-mark-converter-prompt (converter no-prompt)
2348 "Indicate whether CONVERTER requires gnus-convert-old-newsrc to
2349 display the conversion prompt. NO-PROMPT may be nil (prompt),
2350 t (no prompt), or any form that can be called as a function.
2351 The form should return either t or nil."
2352 (put converter 'gnus-convert-no-prompt no-prompt))
2354 (defun gnus-convert-converter-needs-prompt (converter)
2355 (let ((no-prompt (get converter 'gnus-convert-no-prompt)))
2356 (not (if (memq no-prompt '(t nil))
2358 (funcall no-prompt)))))
2360 (defun gnus-convert-old-ticks (converting-to)
2361 (let ((newsrc (cdr gnus-newsrc-alist))
2362 marks info dormant ticked)
2363 (while (setq info (pop newsrc))
2364 (when (setq marks (gnus-info-marks info))
2365 (setq dormant (cdr (assq 'dormant marks))
2366 ticked (cdr (assq 'tick marks)))
2367 (when (or dormant ticked)
2371 (gnus-info-read info)
2372 (nconc (gnus-uncompress-range dormant)
2373 (gnus-uncompress-range ticked)))))))))
2376 (defun gnus-load (file &optional coding-system)
2377 "Load FILE, but in such a way that read errors can be reported."
2380 (insert-file-contents-as-coding-system coding-system file)
2381 (insert-file-contents file))
2383 (condition-case type
2384 (let ((form (read (current-buffer))))
2387 (unless (eq (car type) 'end-of-file)
2388 (let ((error (format "Error in %s line %d" file
2389 (count-lines (point-min) (point)))))
2391 (unless (gnus-yes-or-no-p (concat error "; continue? "))
2392 (error "%s" error)))))))))
2394 (defun gnus-read-newsrc-el-file (file)
2395 (let ((ding-file (concat file "d")))
2396 (when (file-exists-p ding-file)
2397 ;; We always, always read the .eld file.
2398 (gnus-message 5 "Reading %s..." ding-file)
2399 (let (gnus-newsrc-assoc)
2400 (gnus-load ding-file gnus-ding-file-coding-system)
2401 ;; ;; Older versions of `gnus-format-specs' are no longer valid
2402 ;; ;; in Oort Gnus 0.01.
2404 ;; (and gnus-newsrc-file-version
2405 ;; (gnus-continuum-version gnus-newsrc-file-version))))
2406 ;; (when (or (not version)
2407 ;; (< version 5.090009))
2408 ;; (setq gnus-format-specs gnus-default-format-specs)))
2409 (when gnus-newsrc-assoc
2410 (setq gnus-newsrc-alist gnus-newsrc-assoc))))
2411 (gnus-make-hashtable-from-newsrc-alist)
2412 (when (file-newer-than-file-p file ding-file)
2413 ;; Old format quick file
2414 (gnus-message 5 "Reading %s..." file)
2415 ;; The .el file is newer than the .eld file, so we read that one
2417 (gnus-read-old-newsrc-el-file file)))
2418 (when (and gnus-product-directory
2419 (file-directory-p gnus-product-directory))
2420 (let ((list gnus-product-variable-file-list))
2422 (apply 'gnus-product-read-variable-file-1 (car list))
2423 (setq list (cdr list)))))
2424 (gnus-run-hooks 'gnus-read-newsrc-el-hook))
2426 ;;(defun gnus-re-read-newsrc-el-file (file)
2427 ;; "Attempt to re-read .newsrc.eld file. Returns nil if successful.
2428 ;;The backup file \".newsrc.eld_\" will be created before re-reading."
2429 ;; (message "Error in %s; retrying..." file)
2431 ;; (condition-case nil
2432 ;; (let ((backup (concat file "_")))
2433 ;; (copy-file file backup 'ok-if-already-exists 'keep-time)
2434 ;; (message " (The backup file %s has been created)" backup)
2438 ;; (insert-file-contents-as-binary file nil nil nil 'replace)
2439 ;; (goto-char (point-min))
2440 ;; (when (re-search-forward
2441 ;; "^[\t ]*([\t\n\r ]*setq[\t\n\r ]+gnus-format-specs" nil t)
2442 ;; (delete-region (goto-char (match-beginning 0)) (forward-list 1))
2443 ;; (decode-coding-region (point-min) (point-max)
2444 ;; gnus-ding-file-coding-system)
2445 ;; (condition-case nil
2447 ;; (eval-region (point-min) (point-max))
2452 ;; (message "Error in %s; retrying...done" file))
2453 ;; (message "Error in %s; retrying...failed" file)
2456 (defun gnus-product-read-variable-file-1 (file checking-methods coding
2458 (let (error gnus-product-file-version method file-ver)
2459 (when (or (condition-case err
2460 (let ((coding-system-for-read coding))
2461 (load (expand-file-name file gnus-product-directory)
2465 (message "Error while reading %s: %s"
2466 (expand-file-name file gnus-product-directory)
2467 (error-message-string err))
2469 (and (setq method (assq 'product-version checking-methods))
2470 (not (and (setq file-ver
2471 (cdr (assq 'product-version
2472 gnus-product-file-version)))
2473 (zerop (product-version-compare file-ver
2475 (and (assq 'emacs-version checking-methods)
2476 (not (and (assq 'emacs-version gnus-product-file-version)
2479 (cdr (assq 'emacs-version
2480 gnus-product-file-version))))))
2481 (and (assq 'correct-string-widths checking-methods)
2482 (not (and (assq 'correct-string-widths
2483 gnus-product-file-version)
2484 (eq (and gnus-use-correct-string-widths t)
2485 (and (cdr (assq 'correct-string-widths
2486 gnus-product-file-version))
2489 (message "\"%s\" seems to have mismatched contents, updating..."
2492 (set (car variables) nil)
2493 (gnus-product-variable-touch (car variables))
2494 (setq variables (cdr variables))))))
2496 ;; Parse the old-style quick startup file
2497 (defun gnus-read-old-newsrc-el-file (file)
2498 (let (newsrc killed marked group m info)
2500 (let ((gnus-killed-assoc nil)
2501 gnus-marked-assoc gnus-newsrc-alist gnus-newsrc-assoc)
2505 (setq newsrc gnus-newsrc-assoc
2506 killed gnus-killed-assoc
2507 marked gnus-marked-assoc)))
2508 (setq gnus-newsrc-alist nil)
2509 (while (setq group (pop newsrc))
2510 (if (setq info (gnus-get-info (car group)))
2512 (gnus-info-set-read info (cddr group))
2513 (gnus-info-set-level
2514 info (if (nth 1 group) gnus-level-default-subscribed
2515 gnus-level-default-unsubscribed))
2516 (push info gnus-newsrc-alist))
2519 (if (nth 1 group) gnus-level-default-subscribed
2520 gnus-level-default-unsubscribed)
2523 ;; Copy marks into info.
2524 (when (setq m (assoc (car group) marked))
2525 (unless (nthcdr 3 info)
2526 (nconc info (list nil)))
2527 (gnus-info-set-marks
2528 info (list (cons 'tick (gnus-compress-sequence
2529 (sort (cdr m) '<) t))))))
2530 (setq newsrc killed)
2532 (setcar newsrc (caar newsrc))
2533 (setq newsrc (cdr newsrc)))
2534 (setq gnus-killed-list killed))
2535 ;; The .el file version of this variable does not begin with
2536 ;; "options", while the .eld version does, so we just add it if it
2540 (when (not (string-match "^ *options" gnus-newsrc-options))
2541 (setq gnus-newsrc-options (concat "options " gnus-newsrc-options)))
2542 (when (not (string-match "\n$" gnus-newsrc-options))
2543 (setq gnus-newsrc-options (concat gnus-newsrc-options "\n")))
2544 ;; Finally, if we read some options lines, we parse them.
2545 (unless (string= gnus-newsrc-options "")
2546 (gnus-newsrc-parse-options gnus-newsrc-options)))
2548 (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist))
2549 (gnus-make-hashtable-from-newsrc-alist)))
2551 (defun gnus-make-newsrc-file (file)
2552 "Make server dependent file name by catenating FILE and server host name."
2553 (let* ((file (expand-file-name file nil))
2554 (real-file (concat file "-" (nth 1 gnus-select-method))))
2555 (if (or (file-exists-p real-file)
2556 (file-exists-p (concat real-file ".el"))
2557 (file-exists-p (concat real-file ".eld")))
2561 (defun gnus-newsrc-to-gnus-format ()
2562 (setq gnus-newsrc-options "")
2563 (setq gnus-newsrc-options-n nil)
2565 (unless gnus-active-hashtb
2566 (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
2567 (let ((buf (current-buffer))
2568 (already-read (> (length gnus-newsrc-alist) 1))
2569 group subscribed options-symbol newsrc Options-symbol
2571 (goto-char (point-min))
2572 ;; We intern the symbol `options' in the active hashtb so that we
2573 ;; can `eq' against it later.
2574 (set (setq options-symbol (intern "options" gnus-active-hashtb)) nil)
2575 (set (setq Options-symbol (intern "Options" gnus-active-hashtb)) nil)
2578 ;; We first read the first word on the line by narrowing and
2579 ;; then reading into `gnus-active-hashtb'. Most groups will
2580 ;; already exist in that hashtb, so this will save some string
2584 (progn (skip-chars-forward "^ \t!:\n") (point)))
2585 (goto-char (point-min))
2587 (and (/= (point-min) (point-max))
2588 (let ((obarray gnus-active-hashtb)) (read buf))))
2590 ;; Now, the symbol we have read is either `options' or a group
2591 ;; name. If it is an options line, we just add it to a string.
2593 ((or (eq symbol options-symbol)
2594 (eq symbol Options-symbol))
2595 (setq gnus-newsrc-options
2596 ;; This concating is quite inefficient, but since our
2597 ;; thorough studies show that approx 99.37% of all
2598 ;; .newsrc files only contain a single options line, we
2599 ;; don't give a damn, frankly, my dear.
2600 (concat gnus-newsrc-options
2603 ;; Options may continue on the next line.
2604 (or (and (re-search-forward "^[^ \t]" nil 'move)
2609 ;; Group names can be just numbers.
2610 (when (numberp symbol)
2611 (setq symbol (intern (int-to-string symbol) gnus-active-hashtb)))
2612 (unless (boundp symbol)
2614 ;; It was a group name.
2615 (setq subscribed (eq (char-after) ?:)
2616 group (symbol-name symbol)
2619 ;; If the line ends here, this is clearly a buggy line, so
2620 ;; we put point a the beginning of line and let the cond
2621 ;; below do the error handling.
2623 ;; We skip to the beginning of the ranges.
2624 (skip-chars-forward "!: \t"))
2625 ;; We are now at the beginning of the list of read articles.
2626 ;; We read them range by range.
2629 ((looking-at "[0-9]+")
2630 ;; We narrow and read a number instead of buffer-substring/
2631 ;; string-to-number because it's faster. narrow/widen is
2632 ;; faster than save-restriction/narrow, and save-restriction
2633 ;; produces a garbage object.
2635 (narrow-to-region (match-beginning 0) (match-end 0))
2638 ;; If the next character is a dash, then this is a range.
2639 (if (eq (char-after) ?-)
2641 ;; We read the upper bound of the range.
2643 (if (not (looking-at "[0-9]+"))
2644 ;; This is a buggy line, by we pretend that
2645 ;; it's kinda OK. Perhaps the user should be
2651 (narrow-to-region (match-beginning 0)
2656 ;; It was just a simple number, so we add it to the
2659 ;; If the next char in ?\n, then we have reached the end
2660 ;; of the line and return nil.
2661 (not (eq (char-after) ?\n)))
2662 ((eq (char-after) ?\n)
2663 ;; End of line, so we end.
2666 ;; Not numbers and not eol, so this might be a buggy
2669 ;; If it was eob instead of ?\n, we allow it.
2670 ;; The line was buggy.
2672 (gnus-error 3.1 "Mangled line: %s"
2673 (buffer-substring (point-at-bol)
2676 ;; Skip past ", ". Spaces are invalid in these ranges, but
2677 ;; we allow them, because it's a common mistake to put a
2678 ;; space after the comma.
2679 (skip-chars-forward ", "))
2681 ;; We have already read .newsrc.eld, so we gently update the
2682 ;; data in the hash table with the information we have just
2685 (let ((info (gnus-get-info group))
2688 ;; There is an entry for this file in the alist.
2690 (gnus-info-set-read info (nreverse reads))
2691 ;; We update the level very gently. In fact, we
2692 ;; only change it if there's been a status change
2693 ;; from subscribed to unsubscribed, or vice versa.
2694 (setq level (gnus-info-level info))
2695 (cond ((and (<= level gnus-level-subscribed)
2697 (setq level (if reads
2698 gnus-level-default-unsubscribed
2699 (1+ gnus-level-default-unsubscribed))))
2700 ((and (> level gnus-level-subscribed) subscribed)
2701 (setq level gnus-level-default-subscribed)))
2702 (gnus-info-set-level info level))
2703 ;; This is a new group.
2704 (setq info (list group
2706 gnus-level-default-subscribed
2708 (1+ gnus-level-subscribed)
2709 gnus-level-default-unsubscribed))
2711 (push info newsrc)))))
2714 (setq newsrc (nreverse newsrc))
2716 (if (not already-read)
2718 ;; We now have two newsrc lists - `newsrc', which is what we
2719 ;; have read from .newsrc, and `gnus-newsrc-alist', which is
2720 ;; what we've read from .newsrc.eld. We have to merge these
2721 ;; lists. We do this by "attaching" any (foreign) groups in the
2722 ;; gnus-newsrc-alist to the (native) group that precedes them.
2723 (let ((rc (cdr gnus-newsrc-alist))
2724 (prev gnus-newsrc-alist)
2727 (or (null (nth 4 (car rc))) ; It's a native group.
2728 (assoc (caar rc) newsrc) ; It's already in the alist.
2729 (if (setq entry (assoc (caar prev) newsrc))
2730 (setcdr (setq mentry (memq entry newsrc))
2731 (cons (car rc) (cdr mentry)))
2732 (push (car rc) newsrc)))
2736 (setq gnus-newsrc-alist newsrc)
2737 ;; We make the newsrc hashtb.
2738 (gnus-make-hashtable-from-newsrc-alist)
2740 ;; Finally, if we read some options lines, we parse them.
2741 (unless (string= gnus-newsrc-options "")
2742 (gnus-newsrc-parse-options gnus-newsrc-options))))
2744 ;; Parse options lines to find "options -n !all rec.all" and stuff.
2745 ;; The return value will be a list on the form
2746 ;; ((regexp1 . ignore)
2747 ;; (regexp2 . subscribe)...)
2748 ;; When handling new newsgroups, groups that match a `ignore' regexp
2749 ;; will be ignored, and groups that match a `subscribe' regexp will be
2750 ;; subscribed. A line like
2751 ;; options -n !all rec.all
2752 ;; will lead to a list that looks like
2753 ;; (("^rec\\..+" . subscribe)
2754 ;; ("^.+" . ignore))
2755 ;; So all "rec.*" groups will be subscribed, while all the other
2756 ;; groups will be ignored. Note that "options -n !all rec.all" is very
2757 ;; different from "options -n rec.all !all".
2758 (defun gnus-newsrc-parse-options (options)
2761 (gnus-set-work-buffer)
2762 (insert (regexp-quote options))
2763 ;; First we treat all continuation lines.
2764 (goto-char (point-min))
2765 (while (re-search-forward "\n[ \t]+" nil t)
2766 (replace-match " " t t))
2767 ;; Then we transform all "all"s into ".+"s.
2768 (goto-char (point-min))
2769 (while (re-search-forward "\\ball\\b" nil t)
2770 (replace-match ".+" t t))
2771 (goto-char (point-min))
2772 ;; We remove all other options than the "-n" ones.
2773 (while (re-search-forward "[ \t]-[^n][^-]*" nil t)
2776 (goto-char (point-min))
2778 ;; We are only interested in "options -n" lines - we
2779 ;; ignore the other option lines.
2780 (while (re-search-forward "[ \t]-n" nil t)
2783 (and (re-search-forward "[ \t]-n" (point-at-eol) t)
2786 ;; Search for all "words"...
2787 (while (re-search-forward "[^ \t,\n]+" eol t)
2788 (if (eq (char-after (match-beginning 0)) ?!)
2789 ;; If the word begins with a bang (!), this is a "not"
2790 ;; spec. We put this spec (minus the bang) and the
2791 ;; symbol `ignore' into the list.
2793 "^" (buffer-substring
2794 (1+ (match-beginning 0))
2799 ;; There was no bang, so this is a "yes" spec.
2800 (push (cons (concat "^" (match-string 0) "\\($\\|\\.\\)")
2804 (setq gnus-newsrc-options-n out))))
2807 (defalias 'gnus-long-file-names
2808 (if (fboundp 'msdos-long-file-names)
2809 'msdos-long-file-names
2812 (defun gnus-save-newsrc-file (&optional force)
2813 "Save .newsrc file."
2814 ;; Note: We cannot save .newsrc file if all newsgroups are removed
2815 ;; from the variable gnus-newsrc-alist.
2816 (when (and (or gnus-newsrc-alist gnus-killed-list)
2817 gnus-current-startup-file)
2818 ;; Save agent range limits for the currently active method.
2820 (gnus-agent-save-local force))
2823 (if (and (or gnus-use-dribble-file gnus-slave)
2825 (or (not gnus-dribble-buffer)
2826 (not (buffer-name gnus-dribble-buffer))
2827 (zerop (save-excursion
2828 (set-buffer gnus-dribble-buffer)
2830 (gnus-message 4 "(No changes need to be saved)")
2831 (gnus-run-hooks 'gnus-save-newsrc-hook)
2833 (gnus-slave-save-newsrc)
2835 (when gnus-save-newsrc-file
2836 (gnus-message 8 "Saving %s..." gnus-current-startup-file)
2837 (gnus-gnus-to-newsrc-format)
2838 (gnus-message 8 "Saving %s...done" gnus-current-startup-file))
2840 ;; Save .newsrc.eld.
2841 (set-buffer (gnus-get-buffer-create " *Gnus-newsrc*"))
2842 (make-local-variable 'version-control)
2843 (setq version-control gnus-backup-startup-file)
2844 (setq buffer-file-name
2845 (concat gnus-current-startup-file ".eld"))
2846 (setq default-directory (file-name-directory buffer-file-name))
2847 (buffer-disable-undo)
2849 (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file)
2851 (if gnus-save-startup-file-via-temp-buffer
2852 (let ((coding-system-for-write gnus-ding-file-coding-system)
2853 (standard-output (current-buffer)))
2854 (gnus-gnus-to-quick-newsrc-format)
2855 (gnus-run-hooks 'gnus-save-quick-newsrc-hook)
2857 (let ((coding-system-for-write gnus-ding-file-coding-system)
2858 (version-control gnus-backup-startup-file)
2859 (startup-file (concat gnus-current-startup-file ".eld"))
2860 (working-dir (file-name-directory gnus-current-startup-file))
2863 ;; Generate the name of a non-existent file.
2864 (while (progn (setq working-file
2866 (if (and (eq system-type 'ms-dos)
2867 (not (gnus-long-file-names)))
2868 "%s#%d.tm#" ; MSDOS limits files to 8+3
2869 (if (memq system-type '(vax-vms axp-vms))
2872 working-dir (setq i (1+ i))))
2873 (file-exists-p working-file)))
2877 (gnus-with-output-to-file working-file
2878 (gnus-gnus-to-quick-newsrc-format)
2879 (gnus-run-hooks 'gnus-save-quick-newsrc-hook))
2881 ;; These bindings will mislead the current buffer
2882 ;; into thinking that it is visiting the startup
2884 (let ((buffer-backed-up nil)
2885 (buffer-file-name startup-file)
2886 (file-precious-flag t)
2887 (setmodes (file-modes startup-file)))
2888 ;; Backup the current version of the startup file.
2891 ;; Replace the existing startup file with the temp file.
2892 (rename-file working-file startup-file t)
2893 (gnus-set-file-modes startup-file setmodes)))
2895 (delete-file working-file)
2896 (file-error nil)))))
2898 (gnus-kill-buffer (current-buffer))
2900 5 "Saving %s.eld...done" gnus-current-startup-file))
2901 (gnus-dribble-delete-file)
2902 (gnus-group-set-mode-line))))
2903 (when gnus-product-directory
2904 (gnus-product-save-variable-file)))
2906 ;; Call the function above at C-x C-c.
2907 (defadvice save-buffers-kill-emacs (before save-gnus-newsrc-file-maybe
2908 activate preactivate)
2909 "Save .newsrc and .newsrc.eld when Emacs is killed."
2910 (when (gnus-alive-p)
2911 (gnus-run-hooks 'gnus-exit-gnus-hook)
2912 (gnus-offer-save-summaries)
2913 (gnus-save-newsrc-file)))
2915 (defun gnus-gnus-to-quick-newsrc-format (&optional minimal name &rest specific-variables)
2916 "Print Gnus variables such as `gnus-newsrc-alist' in Lisp format."
2917 (princ ";; -*- emacs-lisp -*-\n")
2919 (princ (format ";; %s\n" name))
2920 (princ ";; Gnus startup file.\n"))
2924 ;; Never delete this file -- if you want to force Gnus to read the
2925 ;; .newsrc file (if you have one), touch .newsrc instead.\n")
2926 (princ "(setq gnus-newsrc-file-version ")
2927 (princ (gnus-prin1-to-string gnus-version))
2930 (let* ((print-quoted t)
2932 (print-escape-multibyte nil)
2933 (print-escape-nonascii t)
2936 (print-escape-newlines t)
2938 (if (and gnus-save-killed-list
2939 (stringp gnus-save-killed-list))
2940 (gnus-strip-killed-list)
2943 (or specific-variables
2944 (if gnus-save-killed-list gnus-variable-list
2945 ;; Remove the `gnus-killed-list' from the list of variables
2946 ;; to be saved, if required.
2947 (delq 'gnus-killed-list (copy-sequence gnus-variable-list)))))
2948 ;; Peel off the "dummy" group.
2949 (gnus-newsrc-alist (cdr gnus-newsrc-alist))
2951 ;; Insert the variables into the file.
2953 (when (and (boundp (setq variable (pop variables)))
2954 (symbol-value variable))
2956 (princ (symbol-name variable))
2958 (prin1 (symbol-value variable))
2961 (defun gnus-product-variable-touch (&rest variables)
2963 (put (pop variables) 'gnus-product-variable 'dirty)))
2965 (defun gnus-product-variables-dirty-p (variables)
2968 (when (eq (get (car variables) 'gnus-product-variable) 'dirty)
2970 (setq variables (cdr variables)))))
2972 (defun gnus-product-save-variable-file (&optional force)
2973 "Save all product variables to files, when need to be saved."
2974 (let ((list gnus-product-variable-file-list))
2975 (gnus-make-directory gnus-product-directory)
2977 (apply 'gnus-product-save-variable-file-1 force (car list))
2978 (setq list (cdr list)))))
2980 (defun gnus-product-save-variable-file-1 (force file checking-methods coding
2982 "Save a product variable file, when need to be saved."
2984 (gnus-product-variables-dirty-p variables))
2985 (let ((product (product-find 'gnus-vers)))
2986 (set-buffer (gnus-get-buffer-create " *gnus-product*"))
2987 (make-local-variable 'version-control)
2988 (setq version-control 'never)
2989 (setq file (expand-file-name file gnus-product-directory)
2990 buffer-file-name file
2991 default-directory (file-name-directory file))
2992 (buffer-disable-undo)
2994 (gnus-message 5 "Saving %s..." file)
2995 (apply 'gnus-product-quick-file-format product checking-methods coding
2997 (save-buffer-as-coding-system coding)
2998 (kill-buffer (current-buffer))
3000 (put (car variables) 'gnus-product-variable nil)
3001 (setq variables (cdr variables)))
3003 5 "Saving %s...done" file))))
3005 (defun gnus-product-quick-file-format (product checking-methods
3006 coding &rest variables)
3007 "Insert gnus product depend variables in lisp format."
3008 (let ((print-quoted t)
3009 (print-escape-newlines t)
3010 print-length print-level variable param)
3011 (insert (format ";; -*- Mode: emacs-lisp; coding: %s -*-\n" coding))
3012 (insert (format ";; %s startup file.\n" (product-name product)))
3013 (when (setq param (cdr (assq 'product-version checking-methods)))
3014 (insert "(or (>= (product-version-compare "
3015 "(product-version (product-find 'gnus-vers))\n"
3016 "\t\t\t\t '" (apply 'prin1-to-string param) ")\n"
3018 " (error \"This file was created by later version of "
3020 (insert "(setq gnus-product-file-version\n"
3021 " '((product-version . "
3022 (prin1-to-string (product-version product)) ")\n"
3023 "\t(emacs-version . "
3024 (prin1-to-string emacs-version) ")\n"
3025 "\t(correct-string-widths . "
3026 (if gnus-use-correct-string-widths "t" "nil")
3029 (when (and (boundp (setq variable (pop variables)))
3030 (symbol-value variable))
3031 (insert "(setq " (symbol-name variable) " '")
3032 (gnus-prin1 (symbol-value variable))
3035 (defun gnus-strip-killed-list ()
3036 "Return the killed list minus the groups that match `gnus-save-killed-list'."
3037 (let ((list gnus-killed-list)
3040 (when (string-match gnus-save-killed-list (car list))
3041 (push (car list) olist))
3045 (defun gnus-gnus-to-newsrc-format ()
3046 ;; Generate and save the .newsrc file.
3048 (set-buffer (create-file-buffer gnus-current-startup-file))
3049 (let ((newsrc (cdr gnus-newsrc-alist))
3050 (standard-output (current-buffer))
3051 info ranges range method)
3052 (setq buffer-file-name gnus-current-startup-file)
3053 (setq default-directory (file-name-directory buffer-file-name))
3054 (buffer-disable-undo)
3057 (when gnus-newsrc-options
3058 (insert gnus-newsrc-options))
3059 ;; Write subscribed and unsubscribed.
3060 (while (setq info (pop newsrc))
3061 ;; Don't write foreign groups to .newsrc.
3062 (when (or (null (setq method (gnus-info-method info)))
3063 (equal method "native")
3064 (inline (gnus-server-equal method gnus-select-method)))
3065 (insert (gnus-info-group info)
3066 (if (> (gnus-info-level info) gnus-level-subscribed)
3068 (when (setq ranges (gnus-info-read info))
3070 (if (not (listp (cdr ranges)))
3071 (if (= (car ranges) (cdr ranges))
3072 (princ (car ranges))
3073 (princ (car ranges))
3075 (princ (cdr ranges)))
3076 (while (setq range (pop ranges))
3077 (if (or (atom range) (= (car range) (cdr range)))
3078 (princ (or (and (atom range) range) (car range)))
3081 (princ (cdr range)))
3085 (make-local-variable 'version-control)
3086 (setq version-control 'never)
3087 ;; It has been reported that sometime the modtime on the .newsrc
3088 ;; file seems to be off. We really do want to overwrite it, so
3089 ;; we clear the modtime here before saving. It's a bit odd,
3091 ;; sometimes the modtime clear isn't sufficient. most brute force:
3092 ;; delete the silly thing entirely first. but this fails to provide
3093 ;; such niceties as .newsrc~ creation.
3094 (if gnus-modtime-botch
3095 (delete-file gnus-startup-file)
3096 (clear-visited-file-modtime))
3097 (gnus-run-hooks 'gnus-save-standard-newsrc-hook)
3099 (kill-buffer (current-buffer)))))
3103 ;;; Slave functions.
3106 (defvar gnus-slave-mode nil)
3108 (defun gnus-slave-mode ()
3109 "Minor mode for slave Gnusae."
3110 (add-minor-mode 'gnus-slave-mode " Slave" (make-sparse-keymap))
3111 (gnus-run-hooks 'gnus-slave-mode-hook))
3113 (defun gnus-slave-save-newsrc ()
3115 (set-buffer gnus-dribble-buffer)
3117 (mm-make-temp-file (concat gnus-current-startup-file "-slave-")))
3118 (modes (ignore-errors
3119 (file-modes (concat gnus-current-startup-file ".eld")))))
3120 (gnus-write-buffer-as-coding-system gnus-ding-file-coding-system
3123 (gnus-set-file-modes slave-name modes)))))
3125 (defun gnus-master-read-slave-newsrc ()
3128 (file-name-directory gnus-current-startup-file)
3132 (file-name-nondirectory gnus-current-startup-file)
3136 (if (not slave-files)
3137 () ; There are no slave files to read.
3138 (gnus-message 7 "Reading slave newsrcs...")
3140 (set-buffer (gnus-get-buffer-create " *gnus slave*"))
3142 (sort (mapcar (lambda (file)
3143 (list (nth 5 (file-attributes file)) file))
3146 (or (< (caar f1) (caar f2))
3147 (< (nth 1 (car f1)) (nth 1 (car f2)))))))
3150 (setq file (nth 1 (car slave-files)))
3151 (nnheader-insert-file-contents file)
3152 (when (condition-case ()
3154 (eval-buffer (current-buffer))
3157 (gnus-error 3.2 "Possible error in %s" file)
3159 (unless gnus-slave ; Slaves shouldn't delete these files.
3161 (delete-file file))))
3162 (setq slave-files (cdr slave-files))))
3163 (gnus-dribble-touch)
3164 (gnus-message 7 "Reading slave newsrcs...done"))))
3168 ;;; Group description.
3171 (defun gnus-read-all-descriptions-files ()
3172 (let ((methods (cons gnus-select-method
3174 (when (gnus-archive-server-wanted-p)
3176 gnus-secondary-select-methods))))
3178 (gnus-read-descriptions-file (car methods))
3179 (setq methods (cdr methods)))
3182 (defun gnus-read-descriptions-file (&optional method)
3183 (let ((method (or method gnus-select-method))
3185 (when (stringp method)
3186 (setq method (gnus-server-to-method method)))
3187 ;; We create the hashtable whether we manage to read the desc file
3188 ;; to avoid trying to re-read after a failed read.
3189 (unless gnus-description-hashtb
3190 (setq gnus-description-hashtb
3191 (gnus-make-hashtable (length gnus-active-hashtb))))
3192 ;; Mark this method's desc file as read.
3193 (gnus-sethash (gnus-group-prefixed-name "" method) "Has read"
3194 gnus-description-hashtb)
3196 (gnus-message 5 "Reading descriptions file via %s..." (car method))
3198 ((null (gnus-get-function method 'request-list-newsgroups t))
3200 ((not (gnus-check-server method))
3201 (gnus-message 1 "Couldn't open server")
3203 ((not (gnus-request-list-newsgroups method))
3204 (gnus-message 1 "Couldn't read newsgroups descriptions")
3209 (set-buffer nntp-server-buffer)
3210 (goto-char (point-min))
3211 (when (or (search-forward "\n.\n" nil t)
3212 (goto-char (point-max)))
3214 (narrow-to-region (point-min) (point)))
3215 ;; If these are groups from a foreign select method, we insert the
3216 ;; group prefix in front of the group names.
3217 (and method (not (inline
3219 (gnus-server-get-method nil method)
3220 (gnus-server-get-method
3221 nil gnus-select-method))))
3222 (let ((prefix (gnus-group-prefixed-name "" method)))
3223 (goto-char (point-min))
3224 (while (and (not (eobp))
3225 (progn (insert prefix)
3226 (zerop (forward-line 1)))))))
3227 (goto-char (point-min))
3229 ;; If we get an error, we set group to 0, which is not a
3233 (let ((obarray gnus-description-hashtb))
3234 ;; Group is set to a symbol interned in this
3236 (read nntp-server-buffer))
3238 (skip-chars-forward " \t")
3239 ;; ... which leads to this line being effectively ignored.
3240 (when (symbolp group)
3241 (let* ((str (buffer-substring
3242 (point) (progn (end-of-line) (point))))
3243 (name (symbol-name group))
3245 (or (gnus-group-name-charset method name)
3246 (gnus-parameter-charset name)
3247 gnus-default-charset)))
3248 ;; Fixme: Don't decode in unibyte mode.
3249 (when (and str charset (featurep 'mule))
3250 (setq str (decode-coding-string str charset)))
3253 (gnus-message 5 "Reading descriptions file...done")
3256 (defun gnus-group-get-description (group)
3257 "Get the description of a group by sending XGTITLE to the server."
3258 (when (gnus-request-group-description group)
3260 (set-buffer nntp-server-buffer)
3261 (goto-char (point-min))
3262 (when (looking-at "[^ \t]+[ \t]+\\(.*\\)")
3263 (match-string 1)))))
3266 (defun gnus-declare-backend (name &rest abilities)
3267 "Declare back end NAME with ABILITIES as a Gnus back end."
3268 (setq gnus-valid-select-methods
3269 (nconc gnus-valid-select-methods
3270 (list (apply 'list name abilities))))
3271 (gnus-redefine-select-method-widget))
3273 (defun gnus-set-default-directory ()
3274 "Set the default directory in the current buffer to `gnus-default-directory'.
3275 If this variable is nil, don't do anything."
3276 (setq default-directory
3277 (if (and gnus-default-directory
3278 (file-exists-p gnus-default-directory))
3279 (file-name-as-directory (expand-file-name gnus-default-directory))
3280 default-directory)))
3282 (defun gnus-display-time-event-handler ()
3283 (if (and (fboundp 'display-time-event-handler)
3284 (gnus-boundp 'display-time-timer))
3285 (display-time-event-handler)))
3288 (defun gnus-fixup-nnimap-unread-after-getting-new-news ()
3289 (let (server group info)
3292 (when (and (setq group (symbol-name sym))
3293 (gnus-group-entry group)
3294 (setq info (symbol-value sym)))
3295 (gnus-sethash group (cons (nth 2 info) (cdr (gnus-group-entry group)))
3296 gnus-newsrc-hashtb)))
3297 (if (boundp 'nnimap-mailbox-info)
3298 (symbol-value 'nnimap-mailbox-info)
3299 (make-vector 1 0)))))
3301 (defun gnus-check-reasonable-setup ()
3302 ;; Check whether nnml and nnfolder share a directory.
3304 (if (fboundp 'display-warning)
3306 (lambda (type message)
3308 (message "Warning (%s): %s" type message)
3310 (with-current-buffer (get-buffer-create "*Warnings*")
3311 (goto-char (point-max))
3314 (insert (format "Warning (%s): %s\n" type message))
3315 (setq window (display-buffer (current-buffer)))
3319 (forward-line (- 1 (window-height window)))
3321 (goto-char (point-max))))))))))
3322 method active actives match)
3323 (dolist (server gnus-server-alist)
3324 (setq method (gnus-server-to-method server)
3325 active (intern (format "%s-active-file" (car method))))
3326 (when (and (member (car method) '(nnml nnfolder))
3327 (gnus-server-opened method)
3329 (when (setq match (assoc (symbol-value active) actives))
3330 (funcall display-warn 'gnus-server
3331 (format "%s and %s share the same active file %s"
3335 (push (list (symbol-value active) method) actives)))))
3337 (provide 'gnus-start)
3339 ;;; gnus-start.el ends here