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)
777 ;; Add "native" to gnus-predefined-server-alist just to have a
778 ;; name for the native select method.
779 (when gnus-select-method
780 (push (cons "native" gnus-select-method)
781 gnus-predefined-server-alist))
786 (when gnus-simple-splash
787 (setq gnus-simple-splash nil)
792 (= (frame-height) (1+ (window-height))))
795 (let ((level (and (numberp arg) (> arg 0) arg))
801 (gnus-start-news-server (and arg (not level))))))
802 (if (and (not dont-connect)
805 (gnus-run-hooks 'gnus-startup-hook)
806 ;; NNTP server is successfully open.
808 ;; Find the current startup file name.
809 (setq gnus-current-startup-file
810 (gnus-make-newsrc-file gnus-startup-file))
812 ;; Read the dribble file.
813 (when (or gnus-slave gnus-use-dribble-file)
814 (gnus-dribble-read-file))
816 ;; Do the actual startup.
818 (gnus-request-create-group "queue" '(nndraft "")))
819 (gnus-request-create-group "drafts" '(nndraft ""))
820 (gnus-setup-news nil level dont-connect)
821 (gnus-run-hooks 'gnus-setup-news-hook)
822 (gnus-start-draft-setup)
823 ;; Generate the group buffer.
824 (gnus-group-list-groups level)
825 (gnus-group-first-unread-group)
826 (gnus-configure-windows 'group)
827 (gnus-group-set-mode-line)
829 (set-language-info "Japanese" 'gnus-info "gnus-ja")
830 (gnus-run-hooks 'gnus-started-hook))))))
832 (defun gnus-start-draft-setup ()
833 "Make sure the draft group exists."
834 (gnus-request-create-group "drafts" '(nndraft ""))
835 (unless (gnus-group-entry "nndraft:drafts")
836 (let ((gnus-level-default-subscribed 1))
837 (gnus-subscribe-group "nndraft:drafts" nil '(nndraft "")))
838 (gnus-group-set-parameter
839 "nndraft:drafts" 'gnus-dummy '((gnus-draft-mode)))))
846 (defvar gnus-dribble-ignore nil)
847 (defvar gnus-dribble-eval-file nil)
849 (defun gnus-dribble-file-name ()
850 "Return the dribble file for the current .newsrc."
852 (if gnus-dribble-directory
853 (concat (file-name-as-directory gnus-dribble-directory)
854 (file-name-nondirectory gnus-current-startup-file))
855 gnus-current-startup-file)
858 (defun gnus-dribble-enter (string)
859 "Enter STRING into the dribble buffer."
860 (when (and (not gnus-dribble-ignore)
862 (buffer-name gnus-dribble-buffer))
863 (let ((obuf (current-buffer)))
864 (set-buffer gnus-dribble-buffer)
865 (goto-char (point-max))
867 ;; This has been commented by Josh Huber <huber@alum.wpi.edu>
868 ;; It causes problems with both XEmacs and Emacs 21, and doesn't
869 ;; seem to be of much value. (FIXME: remove this after we make sure
871 ;; (set-window-point (get-buffer-window (current-buffer)) (point-max))
872 (bury-buffer gnus-dribble-buffer)
874 (set-buffer gnus-group-buffer)
875 (gnus-group-set-mode-line))
878 (defun gnus-dribble-touch ()
879 "Touch the dribble buffer."
880 (gnus-dribble-enter ""))
882 (defun gnus-dribble-read-file ()
883 "Read the dribble file from disk."
884 (let ((dribble-file (gnus-dribble-file-name)))
886 (set-buffer (setq gnus-dribble-buffer
887 (gnus-get-buffer-create
888 (file-name-nondirectory dribble-file))))
889 (set (make-local-variable 'file-precious-flag) t)
891 (setq buffer-file-name dribble-file)
893 (buffer-disable-undo)
894 (bury-buffer (current-buffer))
895 (set-buffer-modified-p nil)
896 (let ((auto (make-auto-save-file-name))
897 (gnus-dribble-ignore t)
900 (when (or (file-exists-p auto) (file-exists-p dribble-file))
901 ;; Load whichever file is newest -- the auto save file
902 ;; or the "real" file.
903 (if (file-newer-than-file-p auto dribble-file)
904 (nnheader-insert-file-contents auto)
905 (nnheader-insert-file-contents dribble-file))
906 (unless (zerop (buffer-size))
907 (set-buffer-modified-p t))
908 ;; Set the file modes to reflect the .newsrc file modes.
910 (when (and (file-exists-p gnus-current-startup-file)
911 (file-exists-p dribble-file)
912 (setq modes (file-modes gnus-current-startup-file)))
913 (gnus-set-file-modes dribble-file modes))
914 (goto-char (point-min))
915 (when (search-forward "Gnus was exited on purpose" nil t)
917 ;; Possibly eval the file later.
918 (when (or gnus-always-read-dribble-file
921 "Gnus exited on purpose without saving; read auto-save file anyway? "
922 "Gnus auto-save file exists. Do you want to read it? ")))
923 (setq gnus-dribble-eval-file t)))))))
925 (defun gnus-dribble-eval-file ()
926 (when gnus-dribble-eval-file
927 (setq gnus-dribble-eval-file nil)
929 (let ((gnus-dribble-ignore t))
930 (set-buffer gnus-dribble-buffer)
931 (eval-buffer (current-buffer))))))
933 (defun gnus-dribble-delete-file ()
934 (when (file-exists-p (gnus-dribble-file-name))
935 (delete-file (gnus-dribble-file-name)))
936 (when gnus-dribble-buffer
938 (set-buffer gnus-dribble-buffer)
939 (let ((auto (make-auto-save-file-name)))
940 (when (file-exists-p auto)
943 (set-buffer-modified-p nil)))))
945 (defun gnus-dribble-save ()
946 (when (and gnus-dribble-buffer
947 (buffer-name gnus-dribble-buffer))
949 (set-buffer gnus-dribble-buffer)
952 (defun gnus-dribble-clear ()
953 (when (gnus-buffer-exists-p gnus-dribble-buffer)
955 (set-buffer gnus-dribble-buffer)
957 (set-buffer-modified-p nil)
958 (setq buffer-saved-size (buffer-size)))))
962 ;;; Active & Newsrc File Handling
965 (defun gnus-setup-news (&optional rawfile level dont-connect)
966 "Setup news information.
967 If RAWFILE is non-nil, the .newsrc file will also be read.
968 If LEVEL is non-nil, the news will be set up at level LEVEL."
970 (let ((init (not (and gnus-newsrc-alist gnus-active-hashtb (not rawfile))))
971 ;; Binding this variable will inhibit multiple fetchings
972 ;; of the same mail source.
973 (nnmail-fetched-sources (list t)))
976 ;; Clear some variables to re-initialize news information.
977 (setq gnus-newsrc-alist nil
978 gnus-active-hashtb nil)
979 ;; Read the newsrc file and create `gnus-newsrc-hashtb'.
980 (gnus-read-newsrc-file rawfile))
982 ;; Make sure the archive server is available to all and sundry.
983 (when gnus-message-archive-method
984 (unless (assoc "archive" gnus-server-alist)
985 (let ((method (or (and (stringp gnus-message-archive-method)
986 (gnus-server-to-method
987 gnus-message-archive-method))
988 gnus-message-archive-method)))
989 ;; Check whether the archive method is writable.
990 (unless (or (stringp method)
991 (memq 'respool (assoc (format "%s" (car method))
992 gnus-valid-select-methods)))
993 (setq method "archive")) ;; The default.
994 (push (if (stringp method)
999 ,(nnheader-concat message-directory method))
1000 (nnfolder-active-file
1001 ,(nnheader-concat message-directory
1002 (concat method "/active")))
1003 (nnfolder-get-new-mail nil)
1004 (nnfolder-inhibit-expiry t))
1005 (cons "archive" method))
1006 gnus-server-alist))))
1008 ;; If we don't read the complete active file, we fill in the
1010 (when (or (null gnus-read-active-file)
1011 (eq gnus-read-active-file 'some))
1012 (gnus-update-active-hashtb-from-killed))
1014 ;; Validate agent covered methods now that gnus-server-alist has
1015 ;; been initialized.
1016 ;; NOTE: This is here for one purpose only. By validating the
1017 ;; agentized server's, it converts the old 5.10.3, and earlier,
1018 ;; format to the current format. That enables the agent code
1019 ;; within gnus-read-active-file to function correctly.
1021 (gnus-agent-read-servers-validate))
1023 ;; Read the active file and create `gnus-active-hashtb'.
1024 ;; If `gnus-read-active-file' is nil, then we just create an empty
1025 ;; hash table. The partial filling out of the hash table will be
1026 ;; done in `gnus-get-unread-articles'.
1027 (and gnus-read-active-file
1029 (gnus-read-active-file nil dont-connect))
1031 (unless gnus-active-hashtb
1032 (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
1034 ;; Initialize the cache.
1035 (when gnus-use-cache
1038 ;; Possibly eval the dribble file.
1040 (or gnus-use-dribble-file gnus-slave)
1041 (gnus-dribble-eval-file))
1043 ;; Slave Gnusii should then clear the dribble buffer.
1044 (when (and init gnus-slave)
1045 (gnus-dribble-clear))
1047 (gnus-update-format-specifications)
1049 ;; See whether we need to read the description file.
1050 (when (and (boundp 'gnus-group-line-format)
1051 (stringp gnus-group-line-format)
1052 (let ((case-fold-search nil))
1053 (string-match "%[-,0-9]*D" gnus-group-line-format))
1054 (not gnus-description-hashtb)
1056 gnus-read-active-file)
1057 (gnus-read-all-descriptions-files))
1059 ;; Find new newsgroups and treat them.
1060 (when (and init gnus-check-new-newsgroups (not level)
1061 (gnus-check-server gnus-select-method)
1064 (gnus-find-new-newsgroups))
1066 ;; Check and remove bogus newsgroups.
1067 (when (and init gnus-check-bogus-newsgroups
1068 gnus-read-active-file (not level)
1069 (gnus-server-opened gnus-select-method))
1070 (gnus-check-bogus-newsgroups))
1072 ;; We might read in new NoCeM messages here.
1073 (when (and gnus-use-nocem
1076 (gnus-nocem-scan-groups))
1078 ;; Read any slave files.
1079 (gnus-master-read-slave-newsrc)
1081 ;; Find the number of unread articles in each non-dead group.
1082 (let ((gnus-read-active-file (and (not level) gnus-read-active-file)))
1083 (gnus-get-unread-articles level))))
1085 (defun gnus-call-subscribe-functions (method group)
1086 "Call METHOD to subscribe GROUP.
1087 If no function returns `non-nil', call `gnus-subscribe-zombies'."
1090 (funcall method group))
1093 (dolist (func method)
1094 (if (funcall func group)
1098 (gnus-subscribe-zombies group)))
1100 (defun gnus-find-new-newsgroups (&optional arg)
1101 "Search for new newsgroups and add them.
1102 Each new newsgroup will be treated with `gnus-subscribe-newsgroup-method'.
1103 The `-n' option line from .newsrc is respected.
1105 With 1 C-u, use the `ask-server' method to query the server for new
1107 With 2 C-u's, use most complete method possible to query the server
1108 for new groups, and subscribe the new groups as zombies."
1110 (let* ((gnus-subscribe-newsgroup-method
1111 gnus-subscribe-newsgroup-method)
1113 ((or (and (= (or arg 1) 4)
1114 (not (listp gnus-check-new-newsgroups)))
1115 (null gnus-read-active-file)
1116 (eq gnus-read-active-file 'some))
1119 (setq gnus-subscribe-newsgroup-method
1120 'gnus-subscribe-zombies)
1122 (t gnus-check-new-newsgroups))))
1123 (unless (gnus-check-first-time-used)
1124 (if (or (consp check)
1125 (eq check 'ask-server))
1126 ;; Ask the server for new groups.
1127 (gnus-ask-server-for-new-groups)
1128 ;; Go through the active hashtb and look for new groups.
1130 group new-newsgroups)
1131 (gnus-message 5 "Looking for new newsgroups...")
1132 (unless gnus-have-read-active-file
1133 (gnus-read-active-file))
1134 (setq gnus-newsrc-last-checked-date (message-make-date))
1135 (unless gnus-killed-hashtb
1136 (gnus-make-hashtable-from-killed))
1137 ;; Go though every newsgroup in `gnus-active-hashtb' and compare
1138 ;; with `gnus-newsrc-hashtb' and `gnus-killed-hashtb'.
1141 (if (or (null (setq group (symbol-name sym)))
1143 (null (symbol-value sym))
1144 (gnus-gethash group gnus-killed-hashtb)
1145 (gnus-gethash group gnus-newsrc-hashtb))
1147 (let ((do-sub (gnus-matches-options-n group)))
1149 ((eq do-sub 'subscribe)
1150 (setq groups (1+ groups))
1151 (gnus-sethash group group gnus-killed-hashtb)
1152 (gnus-call-subscribe-functions
1153 gnus-subscribe-options-newsgroup-method group))
1154 ((eq do-sub 'ignore)
1157 (setq groups (1+ groups))
1158 (gnus-sethash group group gnus-killed-hashtb)
1159 (if gnus-subscribe-hierarchical-interactive
1160 (push group new-newsgroups)
1161 (gnus-call-subscribe-functions
1162 gnus-subscribe-newsgroup-method group)))))))
1164 (when new-newsgroups
1165 (gnus-subscribe-hierarchical-interactive new-newsgroups))
1167 (gnus-message 5 "%d new newsgroup%s arrived."
1168 groups (if (> groups 1) "s have" " has"))
1169 (gnus-message 5 "No new newsgroups.")))))))
1171 (defun gnus-matches-options-n (group)
1172 ;; Returns `subscribe' if the group is to be unconditionally
1173 ;; subscribed, `ignore' if it is to be ignored, and nil if there is
1174 ;; no match for the group.
1176 ;; First we check the two user variables.
1178 ((and gnus-options-subscribe
1179 (string-match gnus-options-subscribe group))
1181 ((and gnus-auto-subscribed-groups
1182 (string-match gnus-auto-subscribed-groups group))
1184 ((and gnus-options-not-subscribe
1185 (string-match gnus-options-not-subscribe group))
1187 ;; Then we go through the list that was retrieved from the .newsrc
1188 ;; file. This list has elements on the form
1189 ;; `(REGEXP . {ignore,subscribe})'. The first match found (the list
1190 ;; is in the reverse order of the options line) is returned.
1192 (let ((regs gnus-newsrc-options-n))
1194 (not (string-match (caar regs) group)))
1195 (setq regs (cdr regs)))
1196 (and regs (cdar regs))))))
1198 (defun gnus-ask-server-for-new-groups ()
1199 (let* ((new-date (message-make-date))
1200 (date (or gnus-newsrc-last-checked-date new-date))
1201 (methods (cons gnus-select-method
1203 (when (gnus-archive-server-wanted-p)
1206 (and (consp gnus-check-new-newsgroups)
1207 gnus-check-new-newsgroups)
1208 gnus-secondary-select-methods))))
1210 group new-newsgroups got-new method hashtb
1211 gnus-override-subscribe-method)
1212 (unless gnus-killed-hashtb
1213 (gnus-make-hashtable-from-killed))
1214 ;; Go through both primary and secondary select methods and
1215 ;; request new newsgroups.
1216 (while (setq method (gnus-server-get-method nil (pop methods)))
1217 (setq new-newsgroups nil
1218 gnus-override-subscribe-method method)
1219 (when (and (gnus-check-server method)
1220 (gnus-request-newgroups date method))
1223 hashtb (gnus-make-hashtable 100))
1224 (set-buffer nntp-server-buffer)
1225 ;; Enter all the new groups into a hashtable.
1226 (gnus-active-to-gnus-format method hashtb 'ignore))
1227 ;; Now all new groups from `method' are in `hashtb'.
1230 (if (or (null (setq group (symbol-name group-sym)))
1231 (not (boundp group-sym))
1232 (null (symbol-value group-sym))
1233 (gnus-gethash group gnus-newsrc-hashtb)
1234 (member group gnus-zombie-list)
1235 (member group gnus-killed-list))
1236 ;; The group is already known.
1238 ;; Make this group active.
1239 (when (symbol-value group-sym)
1240 (gnus-set-active group (symbol-value group-sym)))
1241 ;; Check whether we want it or not.
1242 (let ((do-sub (gnus-matches-options-n group)))
1244 ((eq do-sub 'subscribe)
1246 (gnus-sethash group group gnus-killed-hashtb)
1247 (gnus-call-subscribe-functions
1248 gnus-subscribe-options-newsgroup-method group))
1249 ((eq do-sub 'ignore)
1253 (gnus-sethash group group gnus-killed-hashtb)
1254 (if gnus-subscribe-hierarchical-interactive
1255 (push group new-newsgroups)
1256 (gnus-call-subscribe-functions
1257 gnus-subscribe-newsgroup-method group)))))))
1259 (when new-newsgroups
1260 (gnus-subscribe-hierarchical-interactive new-newsgroups)))
1262 (gnus-message 5 "%d new newsgroup%s arrived"
1263 groups (if (> groups 1) "s have" " has"))
1264 (gnus-message 5 "No new newsgroups"))
1266 (setq gnus-newsrc-last-checked-date new-date))
1269 (defun gnus-check-first-time-used ()
1271 ;; First check if any of the following files exist. If they do,
1272 ;; it's not the first time the user has used Gnus.
1273 (dolist (file (list (concat gnus-current-startup-file ".el")
1274 (concat gnus-current-startup-file ".eld")
1275 (concat gnus-startup-file ".el")
1276 (concat gnus-startup-file ".eld")))
1277 (when (file-exists-p file)
1278 (throw 'ended nil)))
1279 (gnus-message 6 "First time user; subscribing you to default groups")
1280 (unless (gnus-read-active-file-p)
1281 (let ((gnus-read-active-file t))
1282 (gnus-read-active-file)))
1283 (setq gnus-newsrc-last-checked-date (message-make-date))
1284 ;; Subscribe to the default newsgroups.
1285 (let ((groups (or gnus-default-subscribed-newsgroups
1286 gnus-backup-default-subscribed-newsgroups))
1289 ;; If t, we subscribe (or not) all groups as if they were new.
1292 (when (setq group (symbol-name sym))
1293 (let ((do-sub (gnus-matches-options-n group)))
1295 ((eq do-sub 'subscribe)
1296 (gnus-sethash group group gnus-killed-hashtb)
1297 (gnus-call-subscribe-functions
1298 gnus-subscribe-options-newsgroup-method group))
1299 ((eq do-sub 'ignore)
1302 (push group gnus-killed-list))))))
1304 (dolist (group groups)
1305 ;; Only subscribe the default groups that are activated.
1306 (when (gnus-active group)
1307 (gnus-group-change-level
1308 group gnus-level-default-subscribed gnus-level-killed)))
1310 (set-buffer gnus-group-buffer)
1311 ;; Don't error if the group already exists. This happens when a
1312 ;; first-time user types 'F'. -- didier
1313 (gnus-group-make-help-group t))
1314 (when gnus-novice-user
1315 (gnus-message 7 "`A k' to list killed groups"))))))
1317 (defun gnus-subscribe-group (group &optional previous method)
1318 "Subscribe GROUP and put it after PREVIOUS."
1319 (gnus-group-change-level
1321 (list t group gnus-level-default-subscribed nil nil method)
1323 gnus-level-default-subscribed gnus-level-killed previous t)
1326 ;; `gnus-group-change-level' is the fundamental function for changing
1327 ;; subscription levels of newsgroups. This might mean just changing
1328 ;; from level 1 to 2, which is pretty trivial, from 2 to 6 or back
1329 ;; again, which subscribes/unsubscribes a group, which is equally
1330 ;; trivial. Changing from 1-7 to 8-9 means that you kill a group, and
1331 ;; from 8-9 to 1-7 means that you remove the group from the list of
1332 ;; killed (or zombie) groups and add them to the (kinda) subscribed
1333 ;; groups. And last but not least, moving from 8 to 9 and 9 to 8,
1334 ;; which is trivial.
1335 ;; ENTRY can either be a string (newsgroup name) or a list (if
1336 ;; FROMKILLED is t, it's a list on the format (NUM INFO-LIST),
1337 ;; otherwise it's a list in the format of the `gnus-newsrc-hashtb'
1339 ;; LEVEL is the new level of the group, OLDLEVEL is the old level and
1340 ;; PREVIOUS is the group (in hashtb entry format) to insert this group
1342 (defun gnus-group-change-level (entry level &optional oldlevel
1343 previous fromkilled)
1344 (let (group info active num)
1345 ;; Glean what info we can from the arguments
1347 (if fromkilled (setq group (nth 1 entry))
1348 (setq group (car (nth 2 entry))))
1350 (when (and (stringp entry)
1352 (< oldlevel gnus-level-zombie))
1353 (setq entry (gnus-group-entry entry)))
1354 (if (and (not oldlevel)
1356 (setq oldlevel (gnus-info-level (nth 2 entry)))
1357 (setq oldlevel (or oldlevel gnus-level-killed)))
1358 (when (stringp previous)
1359 (setq previous (gnus-group-entry previous)))
1361 (if (and (>= oldlevel gnus-level-zombie)
1362 (gnus-group-entry group))
1363 ;; We are trying to subscribe a group that is already
1367 (unless (gnus-ephemeral-group-p group)
1369 (format "(gnus-group-change-level %S %S %S %S %S)"
1370 group level oldlevel (car (nth 2 previous)) fromkilled)))
1372 ;; Then we remove the newgroup from any old structures, if needed.
1373 ;; If the group was killed, we remove it from the killed or zombie
1374 ;; list. If not, and it is in fact going to be killed, we remove
1375 ;; it from the newsrc hash table and assoc.
1377 ((>= oldlevel gnus-level-zombie)
1378 ;; oldlevel could be wrong.
1379 (setq gnus-zombie-list (delete group gnus-zombie-list))
1380 (setq gnus-killed-list (delete group gnus-killed-list)))
1382 (when (and (>= level gnus-level-zombie)
1384 (gnus-sethash (car (nth 2 entry)) nil gnus-newsrc-hashtb)
1386 (setcdr (gnus-group-entry (car (nth 3 entry)))
1388 (setcdr (cdr entry) (cdddr entry)))))
1390 ;; Finally we enter (if needed) the list where it is supposed to
1391 ;; go, and change the subscription level. If it is to be killed,
1392 ;; we enter it into the killed or zombie list.
1394 ((>= level gnus-level-zombie)
1395 ;; Remove from the hash table.
1396 (gnus-sethash group nil gnus-newsrc-hashtb)
1397 ;; We do not enter foreign groups into the list of dead
1399 (unless (gnus-group-foreign-p group)
1400 (if (= level gnus-level-zombie)
1401 (push group gnus-zombie-list)
1402 (if (= oldlevel gnus-level-killed)
1403 ;; Remove from active hashtb.
1404 (unintern group gnus-active-hashtb)
1405 ;; Don't add it into killed-list if it was killed.
1406 (push group gnus-killed-list)))))
1408 ;; If the list is to be entered into the newsrc assoc, and
1409 ;; it was killed, we have to create an entry in the newsrc
1410 ;; hashtb format and fix the pointers in the newsrc assoc.
1411 (if (< oldlevel gnus-level-zombie)
1412 ;; It was alive, and it is going to stay alive, so we
1413 ;; just change the level and don't change any pointers or
1414 ;; hash table entries.
1415 (setcar (cdaddr entry) level)
1417 (setq info (cdr entry)
1419 (setq active (gnus-active group))
1421 (if active (- (1+ (cdr active)) (car active)) t))
1422 ;; Shorten the select method if possible, if we need to
1423 ;; store it at all (native groups).
1424 (let ((method (gnus-method-simplify
1425 (or gnus-override-subscribe-method
1426 (gnus-group-method group)))))
1428 (setq info (list group level nil nil method))
1429 (setq info (list group level nil)))))
1432 (let ((p gnus-newsrc-alist))
1436 (setq entry (cons info (cddr previous)))
1439 (setcdr (cdr previous) entry)
1440 (gnus-sethash group (cons num (cdr previous))
1441 gnus-newsrc-hashtb))
1442 (setcdr previous entry)
1443 (gnus-sethash group (cons num previous)
1444 gnus-newsrc-hashtb))
1446 (setcdr (gnus-group-entry (caadr entry)) entry))
1449 "(gnus-group-set-info '%S)" info)))))
1450 (when gnus-group-change-level-function
1451 (funcall gnus-group-change-level-function
1452 group level oldlevel previous)))))
1454 (defun gnus-kill-newsgroup (newsgroup)
1455 "Obsolete function. Kills a newsgroup."
1456 (gnus-group-change-level
1457 (gnus-group-entry newsgroup) gnus-level-killed))
1459 (defun gnus-check-bogus-newsgroups (&optional confirm)
1460 "Remove bogus newsgroups.
1461 If CONFIRM is non-nil, the user has to confirm the deletion of every
1463 (let ((newsrc (cdr gnus-newsrc-alist))
1464 bogus group entry info)
1465 (gnus-message 5 "Checking bogus newsgroups...")
1466 (unless (gnus-read-active-file-p)
1467 (gnus-read-active-file t))
1468 (when (gnus-read-active-file-p)
1469 ;; Find all bogus newsgroup that are subscribed.
1471 (setq info (pop newsrc)
1472 group (gnus-info-group info))
1473 (unless (or (gnus-active group) ; Active
1474 (and (gnus-info-method info)
1475 (not (gnus-secondary-method-p
1476 (gnus-info-method info))))) ; Foreign
1477 ;; Found a bogus newsgroup.
1478 (push group bogus)))
1481 "Remove bogus group %s? "
1483 ;; Remove all bogus subscribed groups by first killing them, and
1484 ;; then removing them from the list of killed groups.
1485 (when (setq entry (gnus-group-entry group))
1486 (gnus-group-change-level entry gnus-level-killed)
1487 (setq gnus-killed-list (delete group gnus-killed-list))))
1488 bogus '("group" "groups" "remove"))
1489 (while (setq group (pop bogus))
1490 ;; Remove all bogus subscribed groups by first killing them, and
1491 ;; then removing them from the list of killed groups.
1492 (when (setq entry (gnus-group-entry group))
1493 (gnus-group-change-level entry gnus-level-killed)
1494 (setq gnus-killed-list (delete group gnus-killed-list)))))
1495 ;; Then we remove all bogus groups from the list of killed and
1496 ;; zombie groups. They are removed without confirmation.
1497 (let ((dead-lists '(gnus-killed-list gnus-zombie-list))
1500 (setq killed (symbol-value (car dead-lists)))
1502 (unless (gnus-active (setq group (pop killed)))
1503 ;; The group is bogus.
1505 (set (car dead-lists)
1506 (delete group (symbol-value (car dead-lists))))))
1507 (setq dead-lists (cdr dead-lists))))
1508 (gnus-run-hooks 'gnus-check-bogus-groups-hook)
1509 (gnus-message 5 "Checking bogus newsgroups...done"))))
1511 (defun gnus-check-duplicate-killed-groups ()
1512 "Remove duplicates from the list of killed groups."
1514 (let ((killed gnus-killed-list))
1516 (gnus-message 9 "%d" (length killed))
1517 (setcdr killed (delete (car killed) (cdr killed)))
1518 (setq killed (cdr killed)))))
1520 ;; We want to inline a function from gnus-cache, so we cheat here:
1522 (defvar gnus-cache-active-hashtb)
1523 (defun gnus-cache-possibly-alter-active (group active)
1524 "Alter the ACTIVE info for GROUP to reflect the articles in the cache."
1525 (when gnus-cache-active-hashtb
1526 (let ((cache-active (gnus-gethash group gnus-cache-active-hashtb)))
1528 (when (< (car cache-active) (car active))
1529 (setcar active (car cache-active)))
1530 (when (> (cdr cache-active) (cdr active))
1531 (setcdr active (cdr cache-active))))))))
1533 (defun gnus-activate-group (group &optional scan dont-check method)
1534 "Check whether a group has been activated or not.
1535 If SCAN, request a scan of that group as well."
1536 (let ((method (or method (inline (gnus-find-method-for-group group))))
1538 (and (inline (gnus-check-server method))
1539 ;; We escape all bugs and quit here to make it possible to
1540 ;; continue if a group is so out-there that it reports bugs
1544 (gnus-check-backend-function 'request-scan (car method))
1545 (gnus-request-scan group method))
1547 (if (or debug-on-error debug-on-quit)
1548 (inline (gnus-request-group group dont-check method))
1550 (inline (gnus-request-group group dont-check method))
1553 (message "Quit activating %s" group)
1556 (setq active (gnus-parse-active))
1557 ;; If there are no articles in the group, the GROUP
1558 ;; command may have responded with the `(0 . 0)'. We
1559 ;; ignore this if we already have an active entry
1561 (if (and (zerop (or (car active) 0))
1562 (zerop (or (cdr active) 0))
1563 (gnus-active group))
1566 ;; If a cache is present, we may have to alter the active info.
1567 (when gnus-use-cache
1568 (inline (gnus-cache-possibly-alter-active
1571 ;; If the agent is enabled, we may have to alter the active info.
1573 (gnus-agent-possibly-alter-active group active))
1575 (gnus-set-active group active)
1576 ;; Return the new active info.
1579 (defun gnus-get-unread-articles-in-group (info active &optional update)
1580 (when (and info active)
1581 ;; Allow the backend to update the info in the group.
1583 (gnus-request-update-info
1584 info (inline (gnus-find-method-for-group
1585 (gnus-info-group info)))))
1586 (gnus-activate-group (gnus-info-group info) nil t))
1588 (let* ((range (gnus-info-read info))
1591 ;; These checks are present in gnus-activate-group but skipped
1592 ;; due to setting dont-check in the preceeding call.
1594 ;; If a cache is present, we may have to alter the active info.
1595 (when (and gnus-use-cache info)
1596 (inline (gnus-cache-possibly-alter-active
1597 (gnus-info-group info) active)))
1599 ;; If the agent is enabled, we may have to alter the active info.
1600 (when (and gnus-agent info)
1601 (gnus-agent-possibly-alter-active (gnus-info-group info) active info))
1603 ;; Modify the list of read articles according to what articles
1604 ;; are available; then tally the unread articles and add the
1605 ;; number to the group hash table entry.
1607 ((zerop (cdr active))
1610 (setq num (- (1+ (cdr active)) (car active))))
1611 ((not (listp (cdr range)))
1612 ;; Fix a single (num . num) range according to the
1613 ;; active hash table.
1614 ;; Fix by Carsten Bormann <cabo@Informatik.Uni-Bremen.DE>.
1615 (and (< (cdr range) (car active)) (setcdr range (1- (car active))))
1616 (and (> (cdr range) (cdr active)) (setcdr range (cdr active)))
1617 ;; Compute number of unread articles.
1618 (setq num (max 0 (- (cdr active) (- (1+ (cdr range)) (car range))))))
1620 ;; The read list is a list of ranges. Fix them according to
1621 ;; the active hash table.
1622 ;; First peel off any elements that are below the lower
1624 (while (and (cdr range)
1626 (or (and (atom (cadr range)) (cadr range))
1628 (if (numberp (car range))
1631 (or (and (numberp (cadr range))
1635 (or (and (numberp (nth 1 range)) (nth 1 range))
1637 (setcdr range (cddr range)))
1638 ;; Adjust the first element to be the same as the lower limit.
1639 (when (and (not (atom (car range)))
1640 (< (cdar range) (car active)))
1641 (setcdr (car range) (1- (car active))))
1642 ;; Then we want to peel off any elements that are higher
1643 ;; than the upper active limit.
1644 (let ((srange range))
1645 ;; Go past all valid elements.
1646 (while (and (cdr srange)
1647 (<= (or (and (atom (cadr srange))
1651 (setq srange (cdr srange)))
1653 ;; Nuke all remaining invalid elements.
1654 (setcdr srange nil))
1656 ;; Adjust the final element.
1657 (when (and (not (atom (car srange)))
1658 (> (cdar srange) (cdr active)))
1659 (setcdr (car srange) (cdr active))))
1660 ;; Compute the number of unread articles.
1662 (setq num (+ num (- (1+ (or (and (atom (car range)) (car range))
1664 (or (and (atom (car range)) (car range))
1666 (setq range (cdr range)))
1667 (setq num (max 0 (- (cdr active) num)))))
1668 ;; Set the number of unread articles.
1670 (gnus-group-entry (gnus-info-group info)))
1671 (setcar (gnus-group-entry (gnus-info-group info)) num))
1674 ;; Go though `gnus-newsrc-alist' and compare with `gnus-active-hashtb'
1675 ;; and compute how many unread articles there are in each group.
1676 (defun gnus-get-unread-articles (&optional level)
1677 (setq gnus-server-method-cache nil)
1678 (let* ((newsrc (cdr gnus-newsrc-alist))
1679 (level (or level gnus-activate-level (1+ gnus-level-subscribed)))
1682 (cond ((and gnus-activate-foreign-newsgroups
1683 (not (numberp gnus-activate-foreign-newsgroups)))
1684 (1+ gnus-level-subscribed))
1685 ((numberp gnus-activate-foreign-newsgroups)
1686 gnus-activate-foreign-newsgroups)
1691 scanned-methods info group active method retrieve-groups cmethod
1693 (gnus-message 6 "Checking new news...")
1696 (setq active (gnus-active (setq group (gnus-info-group
1697 (setq info (pop newsrc))))))
1699 ;; Check newsgroups. If the user doesn't want to check them, or
1700 ;; they can't be checked (for instance, if the news server can't
1701 ;; be reached) we just set the number of unread articles in this
1702 ;; newsgroup to t. This means that Gnus thinks that there are
1703 ;; unread articles, but it has no idea how many.
1705 ;; To be more explicit:
1706 ;; >0 for an active group with messages
1707 ;; 0 for an active group with no unread messages
1708 ;; nil for non-foreign groups that the user has requested not be checked
1709 ;; t for unchecked foreign groups or bogus groups, or groups that can't
1710 ;; be checked, for one reason or other.
1711 (when (setq method (gnus-info-method info))
1712 (if (setq cmethod (assoc method methods-cache))
1713 (setq method (cdr cmethod))
1714 (setq cmethod (inline (gnus-server-get-method nil method)))
1715 (push (cons method cmethod) methods-cache)
1716 (setq method cmethod)))
1718 (not (setq method-type (cdr (assoc method type-cache)))))
1721 ((gnus-secondary-method-p method)
1723 ((inline (gnus-server-equal gnus-select-method method))
1727 (push (cons method method-type) type-cache))
1730 (cond ((and method (eq method-type 'foreign))
1731 ;; These groups are foreign. Check the level.
1732 (if (<= (gnus-info-level info) foreign-level)
1733 (when (setq active (gnus-activate-group group 'scan))
1734 ;; Let the Gnus agent save the active file.
1735 (when (and gnus-agent active (gnus-online method))
1736 (gnus-agent-save-group-info
1737 method (gnus-group-real-name group) active))
1738 (unless (inline (gnus-virtual-group-p group))
1739 (inline (gnus-close-group group)))
1740 (when (fboundp (intern (concat (symbol-name (car method))
1741 "-request-update-info")))
1742 (inline (gnus-request-update-info info method))))
1744 ;; These groups are native or secondary.
1745 ((> (gnus-info-level info) level)
1746 ;; We don't want these groups.
1747 (setq active 'ignore))
1749 ((not gnus-read-active-file)
1750 (if (gnus-check-backend-function 'retrieve-groups group)
1751 ;; if server support gnus-retrieve-groups we push
1752 ;; the group onto retrievegroups for later checking
1753 (if (assoc method retrieve-groups)
1754 (setcdr (assoc method retrieve-groups)
1755 (cons group (cdr (assoc method retrieve-groups))))
1756 (push (list method group) retrieve-groups))
1757 ;; hack: `nnmail-get-new-mail' changes the mail-source depending
1758 ;; on the group, so we must perform a scan for every group
1759 ;; if the users has any directory mail sources.
1760 ;; hack: if `nnmail-scan-directory-mail-source-once' is non-nil,
1761 ;; for it scan all spool files even when the groups are
1764 (or nnmail-scan-directory-mail-source-once
1765 (null (assq 'directory
1767 (if (listp nnmail-spool-file)
1769 (list nnmail-spool-file))))))
1770 (member method scanned-methods))
1771 (setq active (gnus-activate-group group))
1772 (setq active (gnus-activate-group group 'scan))
1773 (push method scanned-methods))
1775 (gnus-close-group group)))))
1777 ;; Get the number of unread articles in the group.
1779 ((eq active 'ignore)
1780 ;; Don't do anything.
1782 ((and active ignore)
1783 ;; The level of the foreign group is higher than the specified
1787 (inline (gnus-get-unread-articles-in-group info active t)))
1789 ;; The group couldn't be reached, so we nix out the number of
1790 ;; unread articles and stuff.
1791 (gnus-set-active group nil)
1792 (let ((tmp (gnus-group-entry group)))
1796 ;; iterate through groups on methods which support gnus-retrieve-groups
1797 ;; and fetch a partial active file and use it to find new news.
1798 (dolist (rg retrieve-groups)
1799 (let ((method (or (car rg) gnus-select-method))
1801 (when (gnus-check-server method)
1802 ;; Request that the backend scan its incoming messages.
1803 (when (gnus-check-backend-function 'request-scan (car method))
1804 (gnus-request-scan nil method))
1805 (gnus-read-active-file-2
1806 (mapcar (lambda (group) (gnus-group-real-name group)) groups)
1808 (dolist (group groups)
1810 ((setq active (gnus-active (gnus-info-group
1811 (setq info (gnus-get-info group)))))
1812 (inline (gnus-get-unread-articles-in-group info active t)))
1814 ;; The group couldn't be reached, so we nix out the number of
1815 ;; unread articles and stuff.
1816 (gnus-set-active group nil)
1817 (setcar (gnus-group-entry group) t)))))))
1819 (gnus-message 6 "Checking new news...done")))
1821 ;; Create a hash table out of the newsrc alist. The `car's of the
1822 ;; alist elements are used as keys.
1823 (defun gnus-make-hashtable-from-newsrc-alist ()
1824 (let ((alist gnus-newsrc-alist)
1825 (ohashtb gnus-newsrc-hashtb)
1826 prev info method rest methods)
1827 (setq gnus-newsrc-hashtb (gnus-make-hashtable (length alist)))
1829 (setq prev (setq gnus-newsrc-alist
1830 (if (equal (caar gnus-newsrc-alist)
1833 (cons (list "dummy.group" 0 nil) alist)))))
1835 (setq info (car alist))
1836 ;; Make the same select-methods identical Lisp objects.
1837 (when (setq method (gnus-info-method info))
1838 (if (setq rest (member method methods))
1839 (gnus-info-set-method info (car rest))
1840 (push method methods)))
1843 ;; Preserve number of unread articles in groups.
1844 (cons (and ohashtb (car (gnus-gethash (car info) ohashtb)))
1849 ;; Make the same select-methods in `gnus-server-alist' identical
1852 (setq method (pop methods))
1853 (when (setq rest (rassoc method gnus-server-alist))
1854 (setcdr rest method)))))
1856 (defun gnus-make-hashtable-from-killed ()
1857 "Create a hash table from the killed and zombie lists."
1858 (let ((lists '(gnus-killed-list gnus-zombie-list))
1860 (setq gnus-killed-hashtb
1861 (gnus-make-hashtable
1862 (+ (length gnus-killed-list) (length gnus-zombie-list))))
1864 (setq list (symbol-value (pop lists)))
1866 (gnus-sethash (car list) (pop list) gnus-killed-hashtb)))))
1868 (defun gnus-parse-active ()
1869 "Parse active info in the nntp server buffer."
1871 (set-buffer nntp-server-buffer)
1872 (goto-char (point-min))
1873 ;; Parse the result we got from `gnus-request-group'.
1874 (when (looking-at "[0-9]+ [0-9]+ \\([0-9]+\\) [0-9]+")
1875 (goto-char (match-beginning 1))
1876 (cons (read (current-buffer))
1877 (read (current-buffer))))))
1879 (defun gnus-make-articles-unread (group articles)
1880 "Mark ARTICLES in GROUP as unread."
1881 (let* ((info (nth 2 (or (gnus-group-entry group)
1883 (gnus-group-real-name group)))))
1884 (ranges (gnus-info-read info))
1887 (when (gnus-member-of-range
1888 (setq article (pop articles)) ranges)
1889 (push article news)))
1891 ;; Enter this list into the group info.
1893 info (gnus-remove-from-range (gnus-info-read info) (nreverse news)))
1895 ;; Set the number of unread articles in gnus-newsrc-hashtb.
1896 (gnus-get-unread-articles-in-group info (gnus-active group))
1898 ;; Insert the change into the group buffer and the dribble file.
1899 (gnus-group-update-group group t))))
1901 (defun gnus-make-ascending-articles-unread (group articles)
1902 "Mark ascending ARTICLES in GROUP as unread."
1903 (let* ((entry (or (gnus-group-entry group)
1904 (gnus-group-entry (gnus-group-real-name group))))
1905 (info (nth 2 entry))
1906 (ranges (gnus-info-read info))
1911 (let ((article (pop articles))) ; get the next article to remove from ranges
1912 (while (let ((range (car ranges))) ; note the current range
1913 (if (atom range) ; single value range
1915 ;; the articles extend past the end of the ranges
1917 (setq articles nil))
1919 ;; this range preceeds the article. Leave the range unmodified.
1923 ;; this range exactly matches the article; REMOVE THE RANGE.
1924 ;; NOTE: When the range being removed is the last range, the list is corrupted by inserting null at its end.
1925 (setcar ranges (cadr ranges))
1926 (setcdr ranges (cddr ranges))
1927 (setq modified (if (car ranges) t 'remove-null))
1929 (let ((min (car range))
1931 ;; I have a min/max range to consider
1932 (cond ((> min max) ; invalid range introduced by splitter
1933 (setcar ranges (cadr ranges))
1934 (setcdr ranges (cddr ranges))
1935 (setq modified (if (car ranges) t 'remove-null))
1938 ;; replace min/max range with a single-value range
1942 ;; this range preceeds the article. Leave the range unmodified.
1946 ;; this article preceeds the range. Return null to move to the
1950 ;; this article splits the range into two parts
1951 (setcdr ranges (cons (cons (1+ article) max) (cdr ranges)))
1952 (setcdr range (1- article))
1957 (when (eq modified 'remove-null)
1958 (setq r (delq nil r)))
1959 ;; Enter this list into the group info.
1960 (gnus-info-set-read info r)
1962 ;; Set the number of unread articles in gnus-newsrc-hashtb.
1963 (gnus-get-unread-articles-in-group info (gnus-active group))
1965 ;; Insert the change into the group buffer and the dribble file.
1966 (gnus-group-update-group group t))))
1968 ;; Enter all dead groups into the hashtb.
1969 (defun gnus-update-active-hashtb-from-killed ()
1970 (let ((hashtb (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
1971 (lists (list gnus-killed-list gnus-zombie-list))
1974 (setq killed (car lists))
1976 (gnus-sethash (car killed) nil hashtb)
1977 (setq killed (cdr killed)))
1978 (setq lists (cdr lists)))))
1980 (defun gnus-get-killed-groups ()
1981 "Go through the active hashtb and mark all unknown groups as killed."
1982 ;; First make sure active file has been read.
1983 (unless (gnus-read-active-file-p)
1984 (let ((gnus-read-active-file t))
1985 (gnus-read-active-file)))
1986 (unless gnus-killed-hashtb
1987 (gnus-make-hashtable-from-killed))
1988 ;; Go through all newsgroups that are known to Gnus - enlarge kill list.
1992 (group (symbol-name sym)))
1993 (if (or (null group)
1994 (gnus-gethash group gnus-killed-hashtb)
1995 (gnus-gethash group gnus-newsrc-hashtb))
1997 (let ((do-sub (gnus-matches-options-n group)))
1998 (if (or (eq do-sub 'subscribe) (eq do-sub 'ignore))
2000 (setq groups (1+ groups))
2001 (push group gnus-killed-list)
2002 (gnus-sethash group group gnus-killed-hashtb))))))
2004 (gnus-dribble-touch))
2006 ;; Get the active file(s) from the backend(s).
2007 (defun gnus-read-active-file (&optional force not-native)
2008 (gnus-group-set-mode-line)
2011 (lambda (m) (if (stringp m) (gnus-server-get-method nil m) m))
2013 (if (and (not not-native)
2014 (gnus-check-server gnus-select-method))
2015 ;; The native server is available.
2016 (cons gnus-select-method gnus-secondary-select-methods)
2017 ;; The native server is down, so we just do the
2019 gnus-secondary-select-methods)
2020 ;; Also read from the archive server.
2021 (when (gnus-archive-server-wanted-p)
2022 (list "archive")))))
2024 (setq gnus-have-read-active-file nil)
2026 (set-buffer nntp-server-buffer)
2027 (while (setq method (pop methods))
2028 ;; Only do each method once, in case the methods appear more
2029 ;; than once in this list.
2030 (unless (member method methods)
2031 (if (or debug-on-error debug-on-quit)
2032 (gnus-read-active-file-1 method force)
2034 (gnus-read-active-file-1 method force)
2035 ;; We catch C-g so that we can continue past servers
2036 ;; that do not respond.
2038 (message "Quit reading the active file")
2041 (defun gnus-read-active-file-1 (method force)
2043 (setq where (nth 1 method)
2044 mesg (format "Reading active file%s via %s..."
2045 (if (and where (not (zerop (length where))))
2046 (concat " from " where) "")
2048 (gnus-message 5 mesg)
2049 (when (gnus-check-server method)
2050 ;; Request that the backend scan its incoming messages.
2051 (when (gnus-check-backend-function 'request-scan (car method))
2052 (gnus-request-scan nil method))
2054 ((and (eq gnus-read-active-file 'some)
2055 (gnus-check-backend-function 'retrieve-groups (car method))
2057 (let ((newsrc (cdr gnus-newsrc-alist))
2058 (gmethod (gnus-server-get-method nil method))
2060 (while (setq info (pop newsrc))
2064 (gnus-find-method-for-group
2065 (gnus-info-group info) info))
2067 (push (gnus-group-real-name (gnus-info-group info))
2069 (gnus-read-active-file-2 groups method)))
2073 (if (not (gnus-request-list method))
2074 (unless (equal method gnus-message-archive-method)
2075 (gnus-error 1 "Cannot read active file from %s server"
2077 (gnus-message 5 mesg)
2078 (gnus-active-to-gnus-format method gnus-active-hashtb nil t)
2079 ;; We mark this active file as read.
2080 (push method gnus-have-read-active-file)
2081 (gnus-message 5 "%sdone" mesg)))))))
2083 (defun gnus-read-active-file-2 (groups method)
2084 "Read an active file for GROUPS in METHOD using `gnus-retrieve-groups'."
2087 (set-buffer nntp-server-buffer)
2088 (gnus-check-server method)
2089 (let ((list-type (gnus-retrieve-groups groups method)))
2090 (cond ((not list-type)
2092 1.2 "Cannot read partial active file from %s server."
2094 ((eq list-type 'active)
2095 (gnus-active-to-gnus-format method gnus-active-hashtb nil t))
2097 (gnus-groups-to-gnus-format method gnus-active-hashtb t)))))))
2099 ;; Read an active file and place the results in `gnus-active-hashtb'.
2100 (defun gnus-active-to-gnus-format (&optional method hashtb ignore-errors
2103 (setq method gnus-select-method))
2104 (let ((cur (current-buffer))
2106 (if (and gnus-active-hashtb
2107 (not (equal method gnus-select-method)))
2109 (setq gnus-active-hashtb
2110 (if (equal method gnus-select-method)
2111 (gnus-make-hashtable
2112 (count-lines (point-min) (point-max)))
2113 (gnus-make-hashtable 4096)))))))
2114 ;; Delete unnecessary lines.
2115 (goto-char (point-min))
2117 ((string= gnus-ignored-newsgroups "")
2118 (delete-matching-lines "^to\\."))
2120 (delete-matching-lines (concat "^to\\.\\|" gnus-ignored-newsgroups))))
2122 (goto-char (point-min))
2123 (unless (re-search-forward "[\\\"]" nil t)
2124 ;; Make the group names readable as a lisp expression even if they
2125 ;; contain special characters.
2126 (goto-char (point-max))
2127 (while (re-search-backward "[][';?()#]" nil t)
2130 ;; Let the Gnus agent save the active file.
2131 (when (and gnus-agent real-active (gnus-online method))
2132 (gnus-agent-save-active method))
2134 ;; If these are groups from a foreign select method, we insert the
2135 ;; group prefix in front of the group names.
2136 (when (not (gnus-server-equal
2137 (gnus-server-get-method nil method)
2138 (gnus-server-get-method nil gnus-select-method)))
2139 (let ((prefix (gnus-group-prefixed-name "" method)))
2140 (goto-char (point-min))
2141 (while (and (not (eobp))
2143 (when (= (following-char) ?\")
2146 (zerop (forward-line 1)))))))
2147 ;; Store the active file in a hash table.
2148 (goto-char (point-min))
2149 (let (group max min)
2153 (narrow-to-region (point) (point-at-eol))
2154 ;; group gets set to a symbol interned in the hash table
2155 ;; (what a hack!!) - jwz
2156 (setq group (let ((obarray hashtb)) (read cur)))
2157 ;; ### The extended group name scheme makes
2158 ;; the previous optimization strategy sort of pointless...
2159 (when (stringp group)
2160 (setq group (intern group hashtb)))
2161 (if (and (numberp (setq max (read cur)))
2162 (numberp (setq min (read cur)))
2164 (skip-chars-forward " \t")
2166 (or (eq (char-after) ?=)
2167 (eq (char-after) ?x)
2168 (eq (char-after) ?j)))))
2170 (set group (cons min max))
2171 ;; if group is moderated, stick in moderation table
2172 (when (eq (char-after) ?m)
2173 (unless gnus-moderated-hashtb
2174 (setq gnus-moderated-hashtb (gnus-make-hashtable)))
2175 (gnus-sethash (symbol-name group) t
2176 gnus-moderated-hashtb)))
2182 (unless ignore-errors
2183 (gnus-message 3 "Warning - invalid active: %s"
2185 (point-at-bol) (point-at-eol))))))
2187 (forward-line 1)))))
2189 (defun gnus-groups-to-gnus-format (method &optional hashtb real-active)
2190 ;; Parse a "groups" active file.
2191 (let ((cur (current-buffer))
2193 (if (and method gnus-active-hashtb)
2195 (setq gnus-active-hashtb
2196 (gnus-make-hashtable
2197 (count-lines (point-min) (point-max)))))))
2199 (not (gnus-server-equal
2200 (gnus-server-get-method nil method)
2201 (gnus-server-get-method nil gnus-select-method)))
2202 (gnus-group-prefixed-name "" method))))
2204 ;; Let the Gnus agent save the active file.
2207 (gnus-online method)
2208 (gnus-agent-method-p method))
2210 (gnus-agent-save-active method)
2211 (gnus-active-to-gnus-format method hashtb nil real-active))
2213 (goto-char (point-min))
2214 ;; We split this into to separate loops, one with the prefix
2215 ;; and one without to speed the reading up somewhat.
2217 (let (min max opoint group)
2221 (read cur) (read cur)
2222 (setq min (read cur)
2225 (skip-chars-forward " \t")
2228 (set (let ((obarray hashtb)) (read cur))
2230 (error (and group (symbolp group) (set group nil))))
2232 (let (min max group)
2235 (when (eq (char-after) ?2)
2236 (read cur) (read cur)
2237 (setq min (read cur)
2239 (set (setq group (let ((obarray hashtb)) (read cur)))
2241 (error (and group (symbolp group) (set group nil))))
2242 (forward-line 1)))))))
2244 (defun gnus-read-newsrc-file (&optional force)
2246 If FORCE is non-nil, the .newsrc file is read."
2247 ;; Reset variables that might be defined in the .newsrc.eld file.
2248 (gnus-clear-quick-file-variables)
2249 (let* ((newsrc-file gnus-current-startup-file)
2250 (quick-file (concat newsrc-file ".el")))
2252 ;; We always load the .newsrc.eld file. If always contains
2253 ;; much information that can not be gotten from the .newsrc
2254 ;; file (ticked articles, killed groups, foreign methods, etc.)
2255 (gnus-read-newsrc-el-file quick-file)
2257 (when (and gnus-read-newsrc-file
2258 (file-exists-p gnus-current-startup-file)
2260 (and (file-newer-than-file-p newsrc-file quick-file)
2261 (file-newer-than-file-p newsrc-file
2262 (concat quick-file "d")))
2263 (not gnus-newsrc-alist)))
2264 ;; We read the .newsrc file. Note that if there if a
2265 ;; .newsrc.eld file exists, it has already been read, and
2266 ;; the `gnus-newsrc-hashtb' has been created. While reading
2267 ;; the .newsrc file, Gnus will only use the information it
2268 ;; can find there for changing the data already read -
2269 ;; i. e., reading the .newsrc file will not trash the data
2270 ;; already read (except for read articles).
2272 (gnus-message 5 "Reading %s..." newsrc-file)
2273 (set-buffer (nnheader-find-file-noselect newsrc-file))
2274 (buffer-disable-undo)
2275 (gnus-newsrc-to-gnus-format)
2276 (kill-buffer (current-buffer))
2277 (gnus-message 5 "Reading %s...done" newsrc-file))))))
2279 (quote (;; T-gnus doesn't provide those functions.
2280 (defun gnus-convert-old-newsrc ()
2281 "Convert old newsrc formats into the current format, if needed."
2282 (let ((fcv (and gnus-newsrc-file-version
2283 (gnus-continuum-version gnus-newsrc-file-version)))
2284 (gcv (gnus-continuum-version)))
2286 ;; A newsrc file was loaded.
2287 (let (prompt-displayed
2290 (mapcar (lambda (date-func)
2291 (cons (gnus-continuum-version (car date-func))
2293 ;; This is a list of converters that must be run
2294 ;; to bring the newsrc file up to the current
2295 ;; version. If you create an incompatibility
2296 ;; with older versions, you should create an
2297 ;; entry here. The entry should consist of the
2298 ;; current gnus version (hardcoded so that it
2299 ;; doesn't change with each release) and the
2300 ;; function that must be applied to convert the
2301 ;; previous version into the current version.
2302 '(("September Gnus v0.1" nil
2303 gnus-convert-old-ticks)
2304 ("Oort Gnus v0.08" "legacy-gnus-agent"
2305 gnus-agent-convert-to-compressed-agentview)
2306 ("Gnus v5.10.7" "legacy-gnus-agent"
2307 gnus-agent-unlist-expire-days)
2308 ("Gnus v5.10.7" "legacy-gnus-agent"
2309 gnus-agent-unhook-expire-days)))
2310 #'car-less-than-car)))
2311 ;; Skip converters older than the file version
2312 (while (and converters (>= fcv (caar converters)))
2315 ;; Perform converters to bring older version up to date.
2316 (when (and converters (< fcv (caar converters)))
2317 (while (and converters (< fcv (caar converters))
2318 (<= (caar converters) gcv))
2319 (let* ((converter-spec (pop converters))
2320 (convert-to (nth 1 converter-spec))
2321 (load-from (nth 2 converter-spec))
2322 (func (nth 3 converter-spec)))
2323 (when (and load-from
2324 (not (fboundp func)))
2326 (or prompt-displayed
2327 (not (gnus-convert-converter-needs-prompt func))
2329 (cursor-in-echo-area t)
2330 (echo-keystrokes 0))
2331 (message "Convert gnus from version '%s' to '%s'? (n/y/?)"
2332 gnus-newsrc-file-version gnus-version)
2333 (setq c (read-char-exclusive))
2335 (cond ((or (eq c ?n) (eq c ?N))
2336 (error "Can not start gnus without converting"))
2337 ((or (eq c ?y) (eq c ?Y))
2338 (setq prompt-displayed t)
2341 (message "This conversion is irreversible. \
2342 To be safe, you should backup your files before proceeding.")
2346 (gnus-message 3 "Ignoring unexpected input")
2350 (funcall func convert-to)))
2352 (format ";Converted gnus from version '%s' to '%s'."
2353 gnus-newsrc-file-version gnus-version)))))))
2355 (defun gnus-convert-mark-converter-prompt (converter no-prompt)
2356 "Indicate whether CONVERTER requires gnus-convert-old-newsrc to
2357 display the conversion prompt. NO-PROMPT may be nil (prompt),
2358 t (no prompt), or any form that can be called as a function.
2359 The form should return either t or nil."
2360 (put converter 'gnus-convert-no-prompt no-prompt))
2362 (defun gnus-convert-converter-needs-prompt (converter)
2363 (let ((no-prompt (get converter 'gnus-convert-no-prompt)))
2364 (not (if (memq no-prompt '(t nil))
2366 (funcall no-prompt)))))
2368 (defun gnus-convert-old-ticks (converting-to)
2369 (let ((newsrc (cdr gnus-newsrc-alist))
2370 marks info dormant ticked)
2371 (while (setq info (pop newsrc))
2372 (when (setq marks (gnus-info-marks info))
2373 (setq dormant (cdr (assq 'dormant marks))
2374 ticked (cdr (assq 'tick marks)))
2375 (when (or dormant ticked)
2379 (gnus-info-read info)
2380 (nconc (gnus-uncompress-range dormant)
2381 (gnus-uncompress-range ticked)))))))))
2384 (defun gnus-load (file &optional coding-system)
2385 "Load FILE, but in such a way that read errors can be reported."
2388 (insert-file-contents-as-coding-system coding-system file)
2389 (insert-file-contents file))
2391 (condition-case type
2392 (let ((form (read (current-buffer))))
2395 (unless (eq (car type) 'end-of-file)
2396 (let ((error (format "Error in %s line %d" file
2397 (count-lines (point-min) (point)))))
2399 (unless (gnus-yes-or-no-p (concat error "; continue? "))
2400 (error "%s" error)))))))))
2402 (defun gnus-read-newsrc-el-file (file)
2403 (let ((ding-file (concat file "d")))
2404 (when (file-exists-p ding-file)
2405 ;; We always, always read the .eld file.
2406 (gnus-message 5 "Reading %s..." ding-file)
2407 (let (gnus-newsrc-assoc)
2408 (gnus-load ding-file gnus-ding-file-coding-system)
2409 ;; ;; Older versions of `gnus-format-specs' are no longer valid
2410 ;; ;; in Oort Gnus 0.01.
2412 ;; (and gnus-newsrc-file-version
2413 ;; (gnus-continuum-version gnus-newsrc-file-version))))
2414 ;; (when (or (not version)
2415 ;; (< version 5.090009))
2416 ;; (setq gnus-format-specs gnus-default-format-specs)))
2417 (when gnus-newsrc-assoc
2418 (setq gnus-newsrc-alist gnus-newsrc-assoc))))
2419 (gnus-make-hashtable-from-newsrc-alist)
2420 (when (file-newer-than-file-p file ding-file)
2421 ;; Old format quick file
2422 (gnus-message 5 "Reading %s..." file)
2423 ;; The .el file is newer than the .eld file, so we read that one
2425 (gnus-read-old-newsrc-el-file file)))
2426 (when (and gnus-product-directory
2427 (file-directory-p gnus-product-directory))
2428 (let ((list gnus-product-variable-file-list))
2430 (apply 'gnus-product-read-variable-file-1 (car list))
2431 (setq list (cdr list)))))
2432 (gnus-run-hooks 'gnus-read-newsrc-el-hook))
2434 ;;(defun gnus-re-read-newsrc-el-file (file)
2435 ;; "Attempt to re-read .newsrc.eld file. Returns nil if successful.
2436 ;;The backup file \".newsrc.eld_\" will be created before re-reading."
2437 ;; (message "Error in %s; retrying..." file)
2439 ;; (condition-case nil
2440 ;; (let ((backup (concat file "_")))
2441 ;; (copy-file file backup 'ok-if-already-exists 'keep-time)
2442 ;; (message " (The backup file %s has been created)" backup)
2446 ;; (insert-file-contents-as-binary file nil nil nil 'replace)
2447 ;; (goto-char (point-min))
2448 ;; (when (re-search-forward
2449 ;; "^[\t ]*([\t\n\r ]*setq[\t\n\r ]+gnus-format-specs" nil t)
2450 ;; (delete-region (goto-char (match-beginning 0)) (forward-list 1))
2451 ;; (decode-coding-region (point-min) (point-max)
2452 ;; gnus-ding-file-coding-system)
2453 ;; (condition-case nil
2455 ;; (eval-region (point-min) (point-max))
2460 ;; (message "Error in %s; retrying...done" file))
2461 ;; (message "Error in %s; retrying...failed" file)
2464 (defun gnus-product-read-variable-file-1 (file checking-methods coding
2466 (let (error gnus-product-file-version method file-ver)
2467 (when (or (condition-case err
2468 (let ((coding-system-for-read coding))
2469 (load (expand-file-name file gnus-product-directory)
2473 (message "Error while reading %s: %s"
2474 (expand-file-name file gnus-product-directory)
2475 (error-message-string err))
2477 (and (setq method (assq 'product-version checking-methods))
2478 (not (and (setq file-ver
2479 (cdr (assq 'product-version
2480 gnus-product-file-version)))
2481 (zerop (product-version-compare file-ver
2483 (and (assq 'emacs-version checking-methods)
2484 (not (and (assq 'emacs-version gnus-product-file-version)
2487 (cdr (assq 'emacs-version
2488 gnus-product-file-version))))))
2489 (and (assq 'correct-string-widths checking-methods)
2490 (not (and (assq 'correct-string-widths
2491 gnus-product-file-version)
2492 (eq (and gnus-use-correct-string-widths t)
2493 (and (cdr (assq 'correct-string-widths
2494 gnus-product-file-version))
2497 (message "\"%s\" seems to have mismatched contents, updating..."
2500 (set (car variables) nil)
2501 (gnus-product-variable-touch (car variables))
2502 (setq variables (cdr variables))))))
2504 ;; Parse the old-style quick startup file
2505 (defun gnus-read-old-newsrc-el-file (file)
2506 (let (newsrc killed marked group m info)
2508 (let ((gnus-killed-assoc nil)
2509 gnus-marked-assoc gnus-newsrc-alist gnus-newsrc-assoc)
2513 (setq newsrc gnus-newsrc-assoc
2514 killed gnus-killed-assoc
2515 marked gnus-marked-assoc)))
2516 (setq gnus-newsrc-alist nil)
2517 (while (setq group (pop newsrc))
2518 (if (setq info (gnus-get-info (car group)))
2520 (gnus-info-set-read info (cddr group))
2521 (gnus-info-set-level
2522 info (if (nth 1 group) gnus-level-default-subscribed
2523 gnus-level-default-unsubscribed))
2524 (push info gnus-newsrc-alist))
2527 (if (nth 1 group) gnus-level-default-subscribed
2528 gnus-level-default-unsubscribed)
2531 ;; Copy marks into info.
2532 (when (setq m (assoc (car group) marked))
2533 (unless (nthcdr 3 info)
2534 (nconc info (list nil)))
2535 (gnus-info-set-marks
2536 info (list (cons 'tick (gnus-compress-sequence
2537 (sort (cdr m) '<) t))))))
2538 (setq newsrc killed)
2540 (setcar newsrc (caar newsrc))
2541 (setq newsrc (cdr newsrc)))
2542 (setq gnus-killed-list killed))
2543 ;; The .el file version of this variable does not begin with
2544 ;; "options", while the .eld version does, so we just add it if it
2548 (when (not (string-match "^ *options" gnus-newsrc-options))
2549 (setq gnus-newsrc-options (concat "options " gnus-newsrc-options)))
2550 (when (not (string-match "\n$" gnus-newsrc-options))
2551 (setq gnus-newsrc-options (concat gnus-newsrc-options "\n")))
2552 ;; Finally, if we read some options lines, we parse them.
2553 (unless (string= gnus-newsrc-options "")
2554 (gnus-newsrc-parse-options gnus-newsrc-options)))
2556 (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist))
2557 (gnus-make-hashtable-from-newsrc-alist)))
2559 (defun gnus-make-newsrc-file (file)
2560 "Make server dependent file name by catenating FILE and server host name."
2561 (let* ((file (expand-file-name file nil))
2562 (real-file (concat file "-" (nth 1 gnus-select-method))))
2563 (if (or (file-exists-p real-file)
2564 (file-exists-p (concat real-file ".el"))
2565 (file-exists-p (concat real-file ".eld")))
2569 (defun gnus-newsrc-to-gnus-format ()
2570 (setq gnus-newsrc-options "")
2571 (setq gnus-newsrc-options-n nil)
2573 (unless gnus-active-hashtb
2574 (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
2575 (let ((buf (current-buffer))
2576 (already-read (> (length gnus-newsrc-alist) 1))
2577 group subscribed options-symbol newsrc Options-symbol
2579 (goto-char (point-min))
2580 ;; We intern the symbol `options' in the active hashtb so that we
2581 ;; can `eq' against it later.
2582 (set (setq options-symbol (intern "options" gnus-active-hashtb)) nil)
2583 (set (setq Options-symbol (intern "Options" gnus-active-hashtb)) nil)
2586 ;; We first read the first word on the line by narrowing and
2587 ;; then reading into `gnus-active-hashtb'. Most groups will
2588 ;; already exist in that hashtb, so this will save some string
2592 (progn (skip-chars-forward "^ \t!:\n") (point)))
2593 (goto-char (point-min))
2595 (and (/= (point-min) (point-max))
2596 (let ((obarray gnus-active-hashtb)) (read buf))))
2598 ;; Now, the symbol we have read is either `options' or a group
2599 ;; name. If it is an options line, we just add it to a string.
2601 ((or (eq symbol options-symbol)
2602 (eq symbol Options-symbol))
2603 (setq gnus-newsrc-options
2604 ;; This concating is quite inefficient, but since our
2605 ;; thorough studies show that approx 99.37% of all
2606 ;; .newsrc files only contain a single options line, we
2607 ;; don't give a damn, frankly, my dear.
2608 (concat gnus-newsrc-options
2611 ;; Options may continue on the next line.
2612 (or (and (re-search-forward "^[^ \t]" nil 'move)
2617 ;; Group names can be just numbers.
2618 (when (numberp symbol)
2619 (setq symbol (intern (int-to-string symbol) gnus-active-hashtb)))
2620 (unless (boundp symbol)
2622 ;; It was a group name.
2623 (setq subscribed (eq (char-after) ?:)
2624 group (symbol-name symbol)
2627 ;; If the line ends here, this is clearly a buggy line, so
2628 ;; we put point a the beginning of line and let the cond
2629 ;; below do the error handling.
2631 ;; We skip to the beginning of the ranges.
2632 (skip-chars-forward "!: \t"))
2633 ;; We are now at the beginning of the list of read articles.
2634 ;; We read them range by range.
2637 ((looking-at "[0-9]+")
2638 ;; We narrow and read a number instead of buffer-substring/
2639 ;; string-to-number because it's faster. narrow/widen is
2640 ;; faster than save-restriction/narrow, and save-restriction
2641 ;; produces a garbage object.
2643 (narrow-to-region (match-beginning 0) (match-end 0))
2646 ;; If the next character is a dash, then this is a range.
2647 (if (eq (char-after) ?-)
2649 ;; We read the upper bound of the range.
2651 (if (not (looking-at "[0-9]+"))
2652 ;; This is a buggy line, by we pretend that
2653 ;; it's kinda OK. Perhaps the user should be
2659 (narrow-to-region (match-beginning 0)
2664 ;; It was just a simple number, so we add it to the
2667 ;; If the next char in ?\n, then we have reached the end
2668 ;; of the line and return nil.
2669 (not (eq (char-after) ?\n)))
2670 ((eq (char-after) ?\n)
2671 ;; End of line, so we end.
2674 ;; Not numbers and not eol, so this might be a buggy
2677 ;; If it was eob instead of ?\n, we allow it.
2678 ;; The line was buggy.
2680 (gnus-error 3.1 "Mangled line: %s"
2681 (buffer-substring (point-at-bol)
2684 ;; Skip past ", ". Spaces are invalid in these ranges, but
2685 ;; we allow them, because it's a common mistake to put a
2686 ;; space after the comma.
2687 (skip-chars-forward ", "))
2689 ;; We have already read .newsrc.eld, so we gently update the
2690 ;; data in the hash table with the information we have just
2693 (let ((info (gnus-get-info group))
2696 ;; There is an entry for this file in the alist.
2698 (gnus-info-set-read info (nreverse reads))
2699 ;; We update the level very gently. In fact, we
2700 ;; only change it if there's been a status change
2701 ;; from subscribed to unsubscribed, or vice versa.
2702 (setq level (gnus-info-level info))
2703 (cond ((and (<= level gnus-level-subscribed)
2705 (setq level (if reads
2706 gnus-level-default-unsubscribed
2707 (1+ gnus-level-default-unsubscribed))))
2708 ((and (> level gnus-level-subscribed) subscribed)
2709 (setq level gnus-level-default-subscribed)))
2710 (gnus-info-set-level info level))
2711 ;; This is a new group.
2712 (setq info (list group
2714 gnus-level-default-subscribed
2716 (1+ gnus-level-subscribed)
2717 gnus-level-default-unsubscribed))
2719 (push info newsrc)))))
2722 (setq newsrc (nreverse newsrc))
2724 (if (not already-read)
2726 ;; We now have two newsrc lists - `newsrc', which is what we
2727 ;; have read from .newsrc, and `gnus-newsrc-alist', which is
2728 ;; what we've read from .newsrc.eld. We have to merge these
2729 ;; lists. We do this by "attaching" any (foreign) groups in the
2730 ;; gnus-newsrc-alist to the (native) group that precedes them.
2731 (let ((rc (cdr gnus-newsrc-alist))
2732 (prev gnus-newsrc-alist)
2735 (or (null (nth 4 (car rc))) ; It's a native group.
2736 (assoc (caar rc) newsrc) ; It's already in the alist.
2737 (if (setq entry (assoc (caar prev) newsrc))
2738 (setcdr (setq mentry (memq entry newsrc))
2739 (cons (car rc) (cdr mentry)))
2740 (push (car rc) newsrc)))
2744 (setq gnus-newsrc-alist newsrc)
2745 ;; We make the newsrc hashtb.
2746 (gnus-make-hashtable-from-newsrc-alist)
2748 ;; Finally, if we read some options lines, we parse them.
2749 (unless (string= gnus-newsrc-options "")
2750 (gnus-newsrc-parse-options gnus-newsrc-options))))
2752 ;; Parse options lines to find "options -n !all rec.all" and stuff.
2753 ;; The return value will be a list on the form
2754 ;; ((regexp1 . ignore)
2755 ;; (regexp2 . subscribe)...)
2756 ;; When handling new newsgroups, groups that match a `ignore' regexp
2757 ;; will be ignored, and groups that match a `subscribe' regexp will be
2758 ;; subscribed. A line like
2759 ;; options -n !all rec.all
2760 ;; will lead to a list that looks like
2761 ;; (("^rec\\..+" . subscribe)
2762 ;; ("^.+" . ignore))
2763 ;; So all "rec.*" groups will be subscribed, while all the other
2764 ;; groups will be ignored. Note that "options -n !all rec.all" is very
2765 ;; different from "options -n rec.all !all".
2766 (defun gnus-newsrc-parse-options (options)
2769 (gnus-set-work-buffer)
2770 (insert (regexp-quote options))
2771 ;; First we treat all continuation lines.
2772 (goto-char (point-min))
2773 (while (re-search-forward "\n[ \t]+" nil t)
2774 (replace-match " " t t))
2775 ;; Then we transform all "all"s into ".+"s.
2776 (goto-char (point-min))
2777 (while (re-search-forward "\\ball\\b" nil t)
2778 (replace-match ".+" t t))
2779 (goto-char (point-min))
2780 ;; We remove all other options than the "-n" ones.
2781 (while (re-search-forward "[ \t]-[^n][^-]*" nil t)
2784 (goto-char (point-min))
2786 ;; We are only interested in "options -n" lines - we
2787 ;; ignore the other option lines.
2788 (while (re-search-forward "[ \t]-n" nil t)
2791 (and (re-search-forward "[ \t]-n" (point-at-eol) t)
2794 ;; Search for all "words"...
2795 (while (re-search-forward "[^ \t,\n]+" eol t)
2796 (if (eq (char-after (match-beginning 0)) ?!)
2797 ;; If the word begins with a bang (!), this is a "not"
2798 ;; spec. We put this spec (minus the bang) and the
2799 ;; symbol `ignore' into the list.
2801 "^" (buffer-substring
2802 (1+ (match-beginning 0))
2807 ;; There was no bang, so this is a "yes" spec.
2808 (push (cons (concat "^" (match-string 0) "\\($\\|\\.\\)")
2812 (setq gnus-newsrc-options-n out))))
2815 (defalias 'gnus-long-file-names
2816 (if (fboundp 'msdos-long-file-names)
2817 'msdos-long-file-names
2820 (defun gnus-save-newsrc-file (&optional force)
2821 "Save .newsrc file."
2822 ;; Note: We cannot save .newsrc file if all newsgroups are removed
2823 ;; from the variable gnus-newsrc-alist.
2824 (when (and (or gnus-newsrc-alist gnus-killed-list)
2825 gnus-current-startup-file)
2826 ;; Save agent range limits for the currently active method.
2828 (gnus-agent-save-local force))
2831 (if (and (or gnus-use-dribble-file gnus-slave)
2833 (or (not gnus-dribble-buffer)
2834 (not (buffer-name gnus-dribble-buffer))
2835 (zerop (save-excursion
2836 (set-buffer gnus-dribble-buffer)
2838 (gnus-message 4 "(No changes need to be saved)")
2839 (gnus-run-hooks 'gnus-save-newsrc-hook)
2841 (gnus-slave-save-newsrc)
2843 (when gnus-save-newsrc-file
2844 (gnus-message 8 "Saving %s..." gnus-current-startup-file)
2845 (gnus-gnus-to-newsrc-format)
2846 (gnus-message 8 "Saving %s...done" gnus-current-startup-file))
2848 ;; Save .newsrc.eld.
2849 (set-buffer (gnus-get-buffer-create " *Gnus-newsrc*"))
2850 (make-local-variable 'version-control)
2851 (setq version-control gnus-backup-startup-file)
2852 (setq buffer-file-name
2853 (concat gnus-current-startup-file ".eld"))
2854 (setq default-directory (file-name-directory buffer-file-name))
2855 (buffer-disable-undo)
2857 (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file)
2859 (if gnus-save-startup-file-via-temp-buffer
2860 (let ((coding-system-for-write gnus-ding-file-coding-system)
2861 (standard-output (current-buffer)))
2862 (gnus-gnus-to-quick-newsrc-format)
2863 (gnus-run-hooks 'gnus-save-quick-newsrc-hook)
2865 (let ((coding-system-for-write gnus-ding-file-coding-system)
2866 (version-control gnus-backup-startup-file)
2867 (startup-file (concat gnus-current-startup-file ".eld"))
2868 (working-dir (file-name-directory gnus-current-startup-file))
2871 ;; Generate the name of a non-existent file.
2872 (while (progn (setq working-file
2874 (if (and (eq system-type 'ms-dos)
2875 (not (gnus-long-file-names)))
2876 "%s#%d.tm#" ; MSDOS limits files to 8+3
2877 (if (memq system-type '(vax-vms axp-vms))
2880 working-dir (setq i (1+ i))))
2881 (file-exists-p working-file)))
2885 (gnus-with-output-to-file working-file
2886 (gnus-gnus-to-quick-newsrc-format)
2887 (gnus-run-hooks 'gnus-save-quick-newsrc-hook))
2889 ;; These bindings will mislead the current buffer
2890 ;; into thinking that it is visiting the startup
2892 (let ((buffer-backed-up nil)
2893 (buffer-file-name startup-file)
2894 (file-precious-flag t)
2895 (setmodes (file-modes startup-file)))
2896 ;; Backup the current version of the startup file.
2899 ;; Replace the existing startup file with the temp file.
2900 (rename-file working-file startup-file t)
2901 (gnus-set-file-modes startup-file setmodes)))
2903 (delete-file working-file)
2904 (file-error nil)))))
2906 (gnus-kill-buffer (current-buffer))
2908 5 "Saving %s.eld...done" gnus-current-startup-file))
2909 (gnus-dribble-delete-file)
2910 (gnus-group-set-mode-line))))
2911 (when gnus-product-directory
2912 (gnus-product-save-variable-file)))
2914 ;; Call the function above at C-x C-c.
2915 (defadvice save-buffers-kill-emacs (before save-gnus-newsrc-file-maybe
2916 activate preactivate)
2917 "Save .newsrc and .newsrc.eld when Emacs is killed."
2918 (when (gnus-alive-p)
2919 (gnus-run-hooks 'gnus-exit-gnus-hook)
2920 (gnus-offer-save-summaries)
2921 (gnus-save-newsrc-file)))
2923 (defun gnus-gnus-to-quick-newsrc-format (&optional minimal name &rest specific-variables)
2924 "Print Gnus variables such as `gnus-newsrc-alist' in Lisp format."
2925 (princ ";; -*- emacs-lisp -*-\n")
2927 (princ (format ";; %s\n" name))
2928 (princ ";; Gnus startup file.\n"))
2932 ;; Never delete this file -- if you want to force Gnus to read the
2933 ;; .newsrc file (if you have one), touch .newsrc instead.\n")
2934 (princ "(setq gnus-newsrc-file-version ")
2935 (princ (gnus-prin1-to-string gnus-version))
2938 (let* ((print-quoted t)
2940 (print-escape-multibyte nil)
2941 (print-escape-nonascii t)
2944 (print-escape-newlines t)
2946 (if (and gnus-save-killed-list
2947 (stringp gnus-save-killed-list))
2948 (gnus-strip-killed-list)
2951 (or specific-variables
2952 (if gnus-save-killed-list gnus-variable-list
2953 ;; Remove the `gnus-killed-list' from the list of variables
2954 ;; to be saved, if required.
2955 (delq 'gnus-killed-list (copy-sequence gnus-variable-list)))))
2956 ;; Peel off the "dummy" group.
2957 (gnus-newsrc-alist (cdr gnus-newsrc-alist))
2959 ;; Insert the variables into the file.
2961 (when (and (boundp (setq variable (pop variables)))
2962 (symbol-value variable))
2964 (princ (symbol-name variable))
2966 (prin1 (symbol-value variable))
2969 (defun gnus-product-variable-touch (&rest variables)
2971 (put (pop variables) 'gnus-product-variable 'dirty)))
2973 (defun gnus-product-variables-dirty-p (variables)
2976 (when (eq (get (car variables) 'gnus-product-variable) 'dirty)
2978 (setq variables (cdr variables)))))
2980 (defun gnus-product-save-variable-file (&optional force)
2981 "Save all product variables to files, when need to be saved."
2982 (let ((list gnus-product-variable-file-list))
2983 (gnus-make-directory gnus-product-directory)
2985 (apply 'gnus-product-save-variable-file-1 force (car list))
2986 (setq list (cdr list)))))
2988 (defun gnus-product-save-variable-file-1 (force file checking-methods coding
2990 "Save a product variable file, when need to be saved."
2992 (gnus-product-variables-dirty-p variables))
2993 (let ((product (product-find 'gnus-vers)))
2994 (set-buffer (gnus-get-buffer-create " *gnus-product*"))
2995 (make-local-variable 'version-control)
2996 (setq version-control 'never)
2997 (setq file (expand-file-name file gnus-product-directory)
2998 buffer-file-name file
2999 default-directory (file-name-directory file))
3000 (buffer-disable-undo)
3002 (gnus-message 5 "Saving %s..." file)
3003 (apply 'gnus-product-quick-file-format product checking-methods coding
3005 (save-buffer-as-coding-system coding)
3006 (kill-buffer (current-buffer))
3008 (put (car variables) 'gnus-product-variable nil)
3009 (setq variables (cdr variables)))
3011 5 "Saving %s...done" file))))
3013 (defun gnus-product-quick-file-format (product checking-methods
3014 coding &rest variables)
3015 "Insert gnus product depend variables in lisp format."
3016 (let ((print-quoted t)
3017 (print-escape-newlines t)
3018 print-length print-level variable param)
3019 (insert (format ";; -*- Mode: emacs-lisp; coding: %s -*-\n" coding))
3020 (insert (format ";; %s startup file.\n" (product-name product)))
3021 (when (setq param (cdr (assq 'product-version checking-methods)))
3022 (insert "(or (>= (product-version-compare "
3023 "(product-version (product-find 'gnus-vers))\n"
3024 "\t\t\t\t '" (apply 'prin1-to-string param) ")\n"
3026 " (error \"This file was created by later version of "
3028 (insert "(setq gnus-product-file-version\n"
3029 " '((product-version . "
3030 (prin1-to-string (product-version product)) ")\n"
3031 "\t(emacs-version . "
3032 (prin1-to-string emacs-version) ")\n"
3033 "\t(correct-string-widths . "
3034 (if gnus-use-correct-string-widths "t" "nil")
3037 (when (and (boundp (setq variable (pop variables)))
3038 (symbol-value variable))
3039 (insert "(setq " (symbol-name variable) " '")
3040 (gnus-prin1 (symbol-value variable))
3043 (defun gnus-strip-killed-list ()
3044 "Return the killed list minus the groups that match `gnus-save-killed-list'."
3045 (let ((list gnus-killed-list)
3048 (when (string-match gnus-save-killed-list (car list))
3049 (push (car list) olist))
3053 (defun gnus-gnus-to-newsrc-format ()
3054 ;; Generate and save the .newsrc file.
3056 (set-buffer (create-file-buffer gnus-current-startup-file))
3057 (let ((newsrc (cdr gnus-newsrc-alist))
3058 (standard-output (current-buffer))
3059 info ranges range method)
3060 (setq buffer-file-name gnus-current-startup-file)
3061 (setq default-directory (file-name-directory buffer-file-name))
3062 (buffer-disable-undo)
3065 (when gnus-newsrc-options
3066 (insert gnus-newsrc-options))
3067 ;; Write subscribed and unsubscribed.
3068 (while (setq info (pop newsrc))
3069 ;; Don't write foreign groups to .newsrc.
3070 (when (or (null (setq method (gnus-info-method info)))
3071 (equal method "native")
3072 (inline (gnus-server-equal method gnus-select-method)))
3073 (insert (gnus-info-group info)
3074 (if (> (gnus-info-level info) gnus-level-subscribed)
3076 (when (setq ranges (gnus-info-read info))
3078 (if (not (listp (cdr ranges)))
3079 (if (= (car ranges) (cdr ranges))
3080 (princ (car ranges))
3081 (princ (car ranges))
3083 (princ (cdr ranges)))
3084 (while (setq range (pop ranges))
3085 (if (or (atom range) (= (car range) (cdr range)))
3086 (princ (or (and (atom range) range) (car range)))
3089 (princ (cdr range)))
3093 (make-local-variable 'version-control)
3094 (setq version-control 'never)
3095 ;; It has been reported that sometime the modtime on the .newsrc
3096 ;; file seems to be off. We really do want to overwrite it, so
3097 ;; we clear the modtime here before saving. It's a bit odd,
3099 ;; sometimes the modtime clear isn't sufficient. most brute force:
3100 ;; delete the silly thing entirely first. but this fails to provide
3101 ;; such niceties as .newsrc~ creation.
3102 (if gnus-modtime-botch
3103 (delete-file gnus-startup-file)
3104 (clear-visited-file-modtime))
3105 (gnus-run-hooks 'gnus-save-standard-newsrc-hook)
3107 (kill-buffer (current-buffer)))))
3111 ;;; Slave functions.
3114 (defvar gnus-slave-mode nil)
3116 (defun gnus-slave-mode ()
3117 "Minor mode for slave Gnusae."
3118 (add-minor-mode 'gnus-slave-mode " Slave" (make-sparse-keymap))
3119 (gnus-run-hooks 'gnus-slave-mode-hook))
3121 (defun gnus-slave-save-newsrc ()
3123 (set-buffer gnus-dribble-buffer)
3125 (mm-make-temp-file (concat gnus-current-startup-file "-slave-")))
3126 (modes (ignore-errors
3127 (file-modes (concat gnus-current-startup-file ".eld")))))
3128 (gnus-write-buffer-as-coding-system gnus-ding-file-coding-system
3131 (gnus-set-file-modes slave-name modes)))))
3133 (defun gnus-master-read-slave-newsrc ()
3136 (file-name-directory gnus-current-startup-file)
3140 (file-name-nondirectory gnus-current-startup-file)
3144 (if (not slave-files)
3145 () ; There are no slave files to read.
3146 (gnus-message 7 "Reading slave newsrcs...")
3148 (set-buffer (gnus-get-buffer-create " *gnus slave*"))
3150 (sort (mapcar (lambda (file)
3151 (list (nth 5 (file-attributes file)) file))
3154 (or (< (caar f1) (caar f2))
3155 (< (nth 1 (car f1)) (nth 1 (car f2)))))))
3158 (setq file (nth 1 (car slave-files)))
3159 (nnheader-insert-file-contents file)
3160 (when (condition-case ()
3162 (eval-buffer (current-buffer))
3165 (gnus-error 3.2 "Possible error in %s" file)
3167 (unless gnus-slave ; Slaves shouldn't delete these files.
3169 (delete-file file))))
3170 (setq slave-files (cdr slave-files))))
3171 (gnus-dribble-touch)
3172 (gnus-message 7 "Reading slave newsrcs...done"))))
3176 ;;; Group description.
3179 (defun gnus-read-all-descriptions-files ()
3180 (let ((methods (cons gnus-select-method
3182 (when (gnus-archive-server-wanted-p)
3184 gnus-secondary-select-methods))))
3186 (gnus-read-descriptions-file (car methods))
3187 (setq methods (cdr methods)))
3190 (defun gnus-read-descriptions-file (&optional method)
3191 (let ((method (or method gnus-select-method))
3193 (when (stringp method)
3194 (setq method (gnus-server-to-method method)))
3195 ;; We create the hashtable whether we manage to read the desc file
3196 ;; to avoid trying to re-read after a failed read.
3197 (unless gnus-description-hashtb
3198 (setq gnus-description-hashtb
3199 (gnus-make-hashtable (length gnus-active-hashtb))))
3200 ;; Mark this method's desc file as read.
3201 (gnus-sethash (gnus-group-prefixed-name "" method) "Has read"
3202 gnus-description-hashtb)
3204 (gnus-message 5 "Reading descriptions file via %s..." (car method))
3206 ((null (gnus-get-function method 'request-list-newsgroups t))
3208 ((not (gnus-check-server method))
3209 (gnus-message 1 "Couldn't open server")
3211 ((not (gnus-request-list-newsgroups method))
3212 (gnus-message 1 "Couldn't read newsgroups descriptions")
3217 (set-buffer nntp-server-buffer)
3218 (goto-char (point-min))
3219 (when (or (search-forward "\n.\n" nil t)
3220 (goto-char (point-max)))
3222 (narrow-to-region (point-min) (point)))
3223 ;; If these are groups from a foreign select method, we insert the
3224 ;; group prefix in front of the group names.
3225 (and method (not (inline
3227 (gnus-server-get-method nil method)
3228 (gnus-server-get-method
3229 nil gnus-select-method))))
3230 (let ((prefix (gnus-group-prefixed-name "" method)))
3231 (goto-char (point-min))
3232 (while (and (not (eobp))
3233 (progn (insert prefix)
3234 (zerop (forward-line 1)))))))
3235 (goto-char (point-min))
3237 ;; If we get an error, we set group to 0, which is not a
3241 (let ((obarray gnus-description-hashtb))
3242 ;; Group is set to a symbol interned in this
3244 (read nntp-server-buffer))
3246 (skip-chars-forward " \t")
3247 ;; ... which leads to this line being effectively ignored.
3248 (when (symbolp group)
3249 (let* ((str (buffer-substring
3250 (point) (progn (end-of-line) (point))))
3251 (name (symbol-name group))
3253 (or (gnus-group-name-charset method name)
3254 (gnus-parameter-charset name)
3255 gnus-default-charset)))
3256 ;; Fixme: Don't decode in unibyte mode.
3257 (when (and str charset (featurep 'mule))
3258 (setq str (decode-coding-string str charset)))
3261 (gnus-message 5 "Reading descriptions file...done")
3264 (defun gnus-group-get-description (group)
3265 "Get the description of a group by sending XGTITLE to the server."
3266 (when (gnus-request-group-description group)
3268 (set-buffer nntp-server-buffer)
3269 (goto-char (point-min))
3270 (when (looking-at "[^ \t]+[ \t]+\\(.*\\)")
3271 (match-string 1)))))
3274 (defun gnus-declare-backend (name &rest abilities)
3275 "Declare back end NAME with ABILITIES as a Gnus back end."
3276 (setq gnus-valid-select-methods
3277 (nconc gnus-valid-select-methods
3278 (list (apply 'list name abilities))))
3279 (gnus-redefine-select-method-widget))
3281 (defun gnus-set-default-directory ()
3282 "Set the default directory in the current buffer to `gnus-default-directory'.
3283 If this variable is nil, don't do anything."
3284 (setq default-directory
3285 (if (and gnus-default-directory
3286 (file-exists-p gnus-default-directory))
3287 (file-name-as-directory (expand-file-name gnus-default-directory))
3288 default-directory)))
3290 (defun gnus-display-time-event-handler ()
3291 (if (and (fboundp 'display-time-event-handler)
3292 (gnus-boundp 'display-time-timer))
3293 (display-time-event-handler)))
3296 (defun gnus-fixup-nnimap-unread-after-getting-new-news ()
3297 (let (server group info)
3300 (when (and (setq group (symbol-name sym))
3301 (gnus-group-entry group)
3302 (setq info (symbol-value sym)))
3303 (gnus-sethash group (cons (nth 2 info) (cdr (gnus-group-entry group)))
3304 gnus-newsrc-hashtb)))
3305 (if (boundp 'nnimap-mailbox-info)
3306 (symbol-value 'nnimap-mailbox-info)
3307 (make-vector 1 0)))))
3309 (defun gnus-check-reasonable-setup ()
3310 ;; Check whether nnml and nnfolder share a directory.
3312 (if (fboundp 'display-warning)
3314 (lambda (type message)
3316 (message "Warning (%s): %s" type message)
3318 (with-current-buffer (get-buffer-create "*Warnings*")
3319 (goto-char (point-max))
3322 (insert (format "Warning (%s): %s\n" type message))
3323 (setq window (display-buffer (current-buffer)))
3327 (forward-line (- 1 (window-height window)))
3329 (goto-char (point-max))))))))))
3330 method active actives match)
3331 (dolist (server gnus-server-alist)
3332 (setq method (gnus-server-to-method server)
3333 active (intern (format "%s-active-file" (car method))))
3334 (when (and (member (car method) '(nnml nnfolder))
3335 (gnus-server-opened method)
3337 (when (setq match (assoc (symbol-value active) actives))
3338 (funcall display-warn 'gnus-server
3339 (format "%s and %s share the same active file %s"
3343 (push (list (symbol-value active) method) actives)))))
3345 (provide 'gnus-start)
3347 ;;; gnus-start.el ends here