1 ;;; gnus-start.el --- startup functions for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
29 (eval-when-compile (require 'cl))
30 (eval-when-compile (require 'static))
38 (autoload 'message-make-date "message")
39 (autoload 'gnus-agent-read-servers-validate "gnus-agent")
40 (autoload 'gnus-agent-save-local "gnus-agent")
41 (autoload 'gnus-agent-possibly-alter-active "gnus-agent")
43 (defvar gnus-agent-covered-methods nil)
44 (defvar gnus-agent-file-loading-local nil)
45 (defvar gnus-agent-file-loading-cache nil))
47 (defcustom gnus-startup-file (nnheader-concat gnus-home-directory ".newsrc")
49 `.newsrc-SERVER' will be used instead if that exists."
53 (defcustom gnus-product-directory
54 (nnheader-concat gnus-directory (concat "." gnus-product-name))
55 "Product depend data files directory."
57 :type '(choice directory (const nil)))
59 (defcustom gnus-backup-startup-file 'never
60 "Whether to create backup files.
61 This variable takes the same values as the `version-control'
65 :type '(choice (const :tag "Never" never)
66 (const :tag "If existing" nil)
67 (other :tag "Always" t)))
69 (defcustom gnus-save-startup-file-via-temp-buffer t
70 "Whether to write the startup file contents to a buffer then save
71 the buffer or write directly to the file. The buffer is faster
72 because all of the contents are written at once. The direct write
73 uses considerably less memory."
76 :type '(choice (const :tag "Write via buffer" t)
77 (const :tag "Write directly to file" nil)))
79 (defcustom gnus-init-file (nnheader-concat gnus-home-directory ".gnus")
80 "Your Gnus Emacs-Lisp startup file name.
81 If a file with the `.el' or `.elc' suffixes exists, it will be read instead."
85 (defcustom gnus-site-init-file
87 (concat (file-name-directory
88 (directory-file-name installation-directory))
89 "site-lisp/gnus-init")
91 "The site-wide Gnus Emacs-Lisp startup file name, or nil if none.
92 If a file with the `.el' or `.elc' suffixes exists, it will be read instead."
94 :type '(choice file (const nil)))
96 (defcustom gnus-default-subscribed-newsgroups nil
97 "List of newsgroups to subscribe, when a user runs Gnus the first time.
98 The value should be a list of strings.
99 If it is t, Gnus will not do anything special the first time it is
100 started; it'll just use the normal newsgroups subscription methods."
102 :type '(choice (repeat string) (const :tag "Nothing special" t)))
104 (defcustom gnus-use-dribble-file t
105 "*Non-nil means that Gnus will use a dribble file to store user updates.
106 If Emacs should crash without saving the .newsrc files, complete
107 information can be restored from the dribble file."
108 :group 'gnus-dribble-file
111 (defcustom gnus-dribble-directory nil
112 "*The directory where dribble files will be saved.
113 If this variable is nil, the directory where the .newsrc files are
115 :group 'gnus-dribble-file
116 :type '(choice directory (const nil)))
118 (defcustom gnus-check-new-newsgroups 'ask-server
119 "*Non-nil means that Gnus will run `gnus-find-new-newsgroups' at startup.
120 This normally finds new newsgroups by comparing the active groups the
121 servers have already reported with those Gnus already knows, either alive
124 When any of the following are true, `gnus-find-new-newsgroups' will instead
125 ask the servers (primary, secondary, and archive servers) to list new
126 groups since the last time it checked:
127 1. This variable is `ask-server'.
128 2. This variable is a list of select methods (see below).
129 3. `gnus-read-active-file' is nil or `some'.
130 4. A prefix argument is given to `gnus-find-new-newsgroups' interactively.
132 Thus, if this variable is `ask-server' or a list of select methods or
133 `gnus-read-active-file' is nil or `some', then the killed list is no
134 longer necessary, so you could safely set `gnus-save-killed-list' to nil.
136 This variable can be a list of select methods which Gnus will query with
137 the `ask-server' method in addition to the primary, secondary, and archive
141 (setq gnus-check-new-newsgroups
142 '((nntp \"some.server\") (nntp \"other.server\")))
144 If this variable is nil, then you have to tell Gnus explicitly to
145 check for new newsgroups with \\<gnus-group-mode-map>\\[gnus-find-new-newsgroups]."
147 :type '(choice (const :tag "no" nil)
148 (const :tag "by brute force" t)
149 (const :tag "ask servers" ask-server)
150 (repeat :menu-tag "ask additional servers"
151 :tag "ask additional servers"
153 (sexp :format "%v"))))
155 (defcustom gnus-check-bogus-newsgroups nil
156 "*Non-nil means that Gnus will check and remove bogus newsgroup at startup.
157 If this variable is nil, then you have to tell Gnus explicitly to
158 check for bogus newsgroups with \\<gnus-group-mode-map>\\[gnus-group-check-bogus-groups]."
159 :group 'gnus-start-server
162 (defcustom gnus-read-active-file 'some
163 "*Non-nil means that Gnus will read the entire active file at startup.
164 If this variable is nil, Gnus will only know about the groups in your
167 If this variable is `some', Gnus will try to only read the relevant
168 parts of the active file from the server. Not all servers support
169 this, and it might be quite slow with other servers, but this should
170 generally be faster than both the t and nil value.
172 If you set this variable to nil or `some', you probably still want to
173 be told about new newsgroups that arrive. To do that, set
174 `gnus-check-new-newsgroups' to `ask-server'. This may not work
175 properly with all servers."
176 :group 'gnus-start-server
177 :type '(choice (const nil)
181 (defconst gnus-level-subscribed 5
182 "Groups with levels less than or equal to this variable are subscribed.")
184 (defconst gnus-level-unsubscribed 7
185 "Groups with levels less than or equal to this variable are unsubscribed.
186 Groups with levels less than `gnus-level-subscribed', which should be
187 less than this variable, are subscribed.")
189 (defconst gnus-level-zombie 8
190 "Groups with this level are zombie groups.")
192 (defconst gnus-level-killed 9
193 "Groups with this level are killed.")
195 (defcustom gnus-level-default-subscribed 3
196 "*New subscribed groups will be subscribed at this level."
197 :group 'gnus-group-levels
200 (defcustom gnus-level-default-unsubscribed 6
201 "*New unsubscribed groups will be unsubscribed at this level."
202 :group 'gnus-group-levels
205 (defcustom gnus-activate-level (1+ gnus-level-subscribed)
206 "*Groups higher than this level won't be activated on startup.
207 Setting this variable to something low might save lots of time when
208 you have many groups that you aren't interested in."
209 :group 'gnus-group-levels
212 (defcustom gnus-activate-foreign-newsgroups 4
213 "*If nil, Gnus will not check foreign newsgroups at startup.
214 If it is non-nil, it should be a number between one and nine. Foreign
215 newsgroups that have a level lower or equal to this number will be
216 activated on startup. For instance, if you want to active all
217 subscribed newsgroups, but not the rest, you'd set this variable to
218 `gnus-level-subscribed'.
220 If you subscribe to lots of newsgroups from different servers, startup
221 might take a while. By setting this variable to nil, you'll save time,
222 but you won't be told how many unread articles there are in the
224 :group 'gnus-group-levels
225 :type '(choice integer
226 (const :tag "none" nil)))
228 (defcustom gnus-read-newsrc-file t
229 "*Non-nil means that Gnus will read the `.newsrc' file.
230 Gnus always reads its own startup file, which is called
231 \".newsrc.eld\". The file called \".newsrc\" is in a format that can
232 be readily understood by other newsreaders. If you don't plan on
233 using other newsreaders, set this variable to nil to save some time on
239 (defcustom gnus-save-newsrc-file t
240 "*Non-nil means that Gnus will save the `.newsrc' file.
241 Gnus always saves its own startup file, which is called
242 \".newsrc.eld\". The file called \".newsrc\" is in a format that can
243 be readily understood by other newsreaders. If you don't plan on
244 using other newsreaders, set this variable to nil to save some time on
249 (defcustom gnus-save-killed-list t
250 "*If non-nil, save the list of killed groups to the startup file.
251 If you set this variable to nil, you'll save both time (when starting
252 and quitting) and space (both memory and disk), but it will also mean
253 that Gnus has no record of which groups are new and which are old, so
254 the automatic new newsgroups subscription methods become meaningless.
256 You should always set `gnus-check-new-newsgroups' to `ask-server' or
257 nil if you set this variable to nil.
259 This variable can also be a regexp. In that case, all groups that do
260 not match this regexp will be removed before saving the list."
262 :type '(radio (sexp :format "Non-nil\n"
263 :match (lambda (widget value)
264 (and value (not (stringp value))))
267 (regexp :format "%t: %v\n" :size 0)))
269 (defcustom gnus-ignored-newsgroups
271 '("^to\\." ; not "real" groups
272 "^[0-9. \t]+\\( \\|$\\)" ; all digits in name
273 "^[\"][]\"[#'()]" ; bogus characters
276 "*A regexp to match uninteresting newsgroups in the active file.
277 Any lines in the active file matching this regular expression are
278 removed from the newsgroup list before anything else is done to it,
279 thus making them effectively non-existent."
280 :group 'gnus-group-new
283 (defcustom gnus-subscribe-newsgroup-method 'gnus-subscribe-zombies
284 "*Function(s) called with a group name when new group is detected.
285 A few pre-made functions are supplied: `gnus-subscribe-randomly'
286 inserts new groups at the beginning of the list of groups;
287 `gnus-subscribe-alphabetically' inserts new groups in strict
288 alphabetic order; `gnus-subscribe-hierarchically' inserts new groups
289 in hierarchical newsgroup order; `gnus-subscribe-interactively' asks
290 for your decision; `gnus-subscribe-killed' kills all new groups;
291 `gnus-subscribe-zombies' will make all new groups into zombies;
292 `gnus-subscribe-topics' will enter groups into the topics that
294 :group 'gnus-group-new
295 :type '(radio (function-item gnus-subscribe-randomly)
296 (function-item gnus-subscribe-alphabetically)
297 (function-item gnus-subscribe-hierarchically)
298 (function-item gnus-subscribe-interactively)
299 (function-item gnus-subscribe-killed)
300 (function-item gnus-subscribe-zombies)
301 (function-item gnus-subscribe-topics)
305 (defcustom gnus-subscribe-newsgroup-hooks nil
306 "*Hooks run after you subscribe to a new group.
307 The hooks will be called with new group's name as argument."
308 :group 'gnus-group-new
311 (defcustom gnus-subscribe-options-newsgroup-method
312 'gnus-subscribe-alphabetically
313 "*Function(s) called to subscribe newsgroups mentioned on \"options -n\" lines.
314 If, for instance, you want to subscribe to all newsgroups in the
315 \"no\" and \"alt\" hierarchies, you'd put the following in your
318 options -n no.all alt.all
320 Gnus will the subscribe all new newsgroups in these hierarchies with
321 the subscription method in this variable."
322 :group 'gnus-group-new
323 :type '(radio (function-item gnus-subscribe-randomly)
324 (function-item gnus-subscribe-alphabetically)
325 (function-item gnus-subscribe-hierarchically)
326 (function-item gnus-subscribe-interactively)
327 (function-item gnus-subscribe-killed)
328 (function-item gnus-subscribe-zombies)
329 (function-item gnus-subscribe-topics)
333 (defcustom gnus-subscribe-hierarchical-interactive nil
334 "*If non-nil, Gnus will offer to subscribe hierarchically.
335 When a new hierarchy appears, Gnus will ask the user:
337 'alt.binaries': Do you want to subscribe to this hierarchy? ([d]ys):
339 If the user pressed `d', Gnus will descend the hierarchy, `y' will
340 subscribe to all newsgroups in the hierarchy and `s' will skip this
341 hierarchy in its entirety."
342 :group 'gnus-group-new
345 (defcustom gnus-auto-subscribed-groups
346 "^nnml\\|^nnfolder\\|^nnmbox\\|^nnmh\\|^nnbabyl\\|^nnmaildir"
347 "*All new groups that match this regexp will be subscribed automatically.
348 Note that this variable only deals with new groups. It has no effect
349 whatsoever on old groups.
351 New groups that match this regexp will not be handled by
352 `gnus-subscribe-newsgroup-method'. Instead, they will
353 be subscribed using `gnus-subscribe-options-newsgroup-method'."
354 :group 'gnus-group-new
357 (defcustom gnus-options-subscribe nil
358 "*All new groups matching this regexp will be subscribed unconditionally.
359 Note that this variable deals only with new newsgroups. This variable
360 does not affect old newsgroups.
362 New groups that match this regexp will not be handled by
363 `gnus-subscribe-newsgroup-method'. Instead, they will
364 be subscribed using `gnus-subscribe-options-newsgroup-method'."
365 :group 'gnus-group-new
366 :type '(choice regexp
367 (const :tag "none" nil)))
369 (defcustom gnus-options-not-subscribe nil
370 "*All new groups matching this regexp will be ignored.
371 Note that this variable deals only with new newsgroups. This variable
372 does not affect old (already subscribed) newsgroups."
373 :group 'gnus-group-new
374 :type '(choice regexp
375 (const :tag "none" nil)))
377 (defcustom gnus-modtime-botch nil
378 "*Non-nil means .newsrc should be deleted prior to save.
379 Its use is due to the bogus appearance that .newsrc was modified on
384 (defcustom gnus-check-bogus-groups-hook nil
385 "A hook run after removing bogus groups."
386 :group 'gnus-start-server
389 (defcustom gnus-startup-hook nil
390 "A hook called at startup.
391 This hook is called after Gnus is connected to the NNTP server."
395 (defcustom gnus-before-startup-hook nil
396 "A hook called at before startup.
397 This hook is called as the first thing when Gnus is started."
401 (defcustom gnus-started-hook nil
402 "A hook called as the last thing after startup."
406 (defcustom gnus-setup-news-hook
407 '(gnus-fixup-nnimap-unread-after-getting-new-news)
408 "A hook after reading the .newsrc file, but before generating the buffer."
412 (defcustom gnus-get-top-new-news-hook nil
413 "A hook run just before Gnus checks for new news globally."
414 :group 'gnus-group-new
417 (defcustom gnus-get-new-news-hook nil
418 "A hook run just before Gnus checks for new news."
419 :group 'gnus-group-new
422 (defcustom gnus-after-getting-new-news-hook
423 '(gnus-display-time-event-handler
424 gnus-fixup-nnimap-unread-after-getting-new-news)
425 "A hook run after Gnus checks for new news when Gnus is already running."
426 :group 'gnus-group-new
429 (defcustom gnus-read-newsrc-el-hook nil
430 "A hook called after reading the newsrc.eld? file."
434 (defcustom gnus-save-newsrc-hook nil
435 "A hook called before saving any of the newsrc files."
439 (defcustom gnus-save-quick-newsrc-hook nil
440 "A hook called just before saving the quick newsrc file.
441 Can be used to turn version control on or off."
445 (defcustom gnus-save-standard-newsrc-hook nil
446 "A hook called just before saving the standard newsrc file.
447 Can be used to turn version control on or off."
451 (defcustom gnus-group-mode-hook nil
452 "Hook for Gnus group mode."
453 :group 'gnus-group-various
454 :options '(gnus-topic-mode)
457 (defcustom gnus-always-read-dribble-file nil
458 "Unconditionally read the dribble file."
462 ;;; Internal variables
464 (defvar gnus-ding-file-coding-system 'ctext
465 "Coding system for ding file.")
466 ;; Note that the ding file for T-gnus ought not to have byte-codes.
468 (defvar gnus-newsrc-file-version nil)
469 (defvar gnus-override-subscribe-method nil)
470 (defvar gnus-dribble-buffer nil)
471 (defvar gnus-newsrc-options nil
472 "Options line in the .newsrc file.")
474 (defvar gnus-newsrc-options-n nil
475 "List of regexps representing groups to be subscribed/ignored unconditionally.")
477 (defvar gnus-newsrc-last-checked-date nil
478 "Date Gnus last asked server for new newsgroups.")
480 (defvar gnus-current-startup-file nil
481 "Startup file for the current host.")
483 ;; Byte-compiler warning.
484 (defvar gnus-group-line-format)
486 ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
487 (defvar gnus-init-inhibit nil)
488 (defun gnus-read-init-file (&optional inhibit-next)
489 ;; Don't load .gnus if the -q option was used.
491 (if gnus-init-inhibit
492 (setq gnus-init-inhibit nil)
493 (setq gnus-init-inhibit inhibit-next)
494 (dolist (file (list gnus-site-init-file gnus-init-file))
496 (locate-library file))
497 (if (or debug-on-error debug-on-quit)
502 (error "Error in %s: %s" file (cadr var))))))))))
504 ;; For subscribing new newsgroup
506 (defun gnus-subscribe-hierarchical-interactive (groups)
507 (let ((groups (sort groups 'string<))
508 prefixes prefix start ans group starts real-group)
510 (setq prefixes (list "^"))
511 (while (and groups prefixes)
512 (while (not (string-match (car prefixes)
513 (gnus-group-real-name (car groups))))
514 (setq prefixes (cdr prefixes)))
515 (setq prefix (car prefixes))
516 (setq start (1- (length prefix)))
517 (if (and (string-match "[^\\.]\\." (gnus-group-real-name (car groups))
521 (concat "^" (substring
522 (gnus-group-real-name (car groups))
524 (string-match prefix (gnus-group-real-name (cadr groups))))
526 (push prefix prefixes)
527 (message "Descend hierarchy %s? ([y]nsq): "
528 (substring prefix 1 (1- (length prefix))))
529 (while (not (memq (setq ans (read-char-exclusive))
530 '(?y ?\n ?\r ?n ?s ?q)))
532 (message "Descend hierarchy %s? ([y]nsq): "
533 (substring prefix 1 (1- (length prefix)))))
536 (setq group (car groups)
537 real-group (gnus-group-real-name group))
538 (string-match prefix real-group))
539 (push group gnus-killed-list)
540 (gnus-sethash group group gnus-killed-hashtb)
541 (setq groups (cdr groups)))
542 (setq starts (cdr starts)))
545 (setq group (car groups)
546 real-group (gnus-group-real-name group))
547 (string-match prefix real-group))
548 (gnus-sethash group group gnus-killed-hashtb)
549 (gnus-subscribe-alphabetically (car groups))
550 (setq groups (cdr groups)))
551 (setq starts (cdr starts)))
554 (setq group (car groups))
555 (push group gnus-killed-list)
556 (gnus-sethash group group gnus-killed-hashtb)
557 (setq groups (cdr groups))))
559 (message "Subscribe %s? ([n]yq)" (car groups))
560 (while (not (memq (setq ans (read-char-exclusive))
561 '(?y ?\n ?\r ?q ?n)))
563 (message "Subscribe %s? ([n]yq)" (car groups)))
564 (setq group (car groups))
566 (gnus-subscribe-alphabetically (car groups))
567 (gnus-sethash group group gnus-killed-hashtb))
570 (setq group (car groups))
571 (push group gnus-killed-list)
572 (gnus-sethash group group gnus-killed-hashtb)
573 (setq groups (cdr groups))))
575 (push group gnus-killed-list)
576 (gnus-sethash group group gnus-killed-hashtb)))
577 (setq groups (cdr groups)))))))
579 (defun gnus-subscribe-randomly (newsgroup)
580 "Subscribe new NEWSGROUP by making it the first newsgroup."
581 (gnus-subscribe-newsgroup newsgroup))
583 (defun gnus-subscribe-alphabetically (newgroup)
584 "Subscribe new NEWGROUP and insert it in alphabetical order."
585 (let ((groups (cdr gnus-newsrc-alist))
587 (while (and (not before) groups)
588 (if (string< newgroup (caar groups))
589 (setq before (caar groups))
590 (setq groups (cdr groups))))
591 (gnus-subscribe-newsgroup newgroup before)))
593 (defun gnus-subscribe-hierarchically (newgroup)
594 "Subscribe new NEWGROUP and insert it in hierarchical newsgroup order."
595 ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
597 (set-buffer (nnheader-find-file-noselect gnus-current-startup-file))
599 (let ((groupkey newgroup) before)
600 (while (and (not before) groupkey)
601 (goto-char (point-min))
603 (concat "^\\(" (regexp-quote groupkey) ".*\\)[!:]")))
604 (while (and (re-search-forward groupkey-re nil t)
606 (setq before (match-string 1))
607 (string< before newgroup)))))
608 ;; Remove tail of newsgroup name (eg. a.b.c -> a.b)
610 (when (string-match "^\\(.*\\)\\.[^.]+$" groupkey)
611 (substring groupkey (match-beginning 1) (match-end 1)))))
612 (gnus-subscribe-newsgroup newgroup before))
613 (kill-buffer (current-buffer)))))
615 (defun gnus-subscribe-interactively (group)
616 "Subscribe the new GROUP interactively.
617 It is inserted in hierarchical newsgroup order if subscribed. If not,
619 (if (gnus-y-or-n-p (format "Subscribe new newsgroup: %s " group))
620 (gnus-subscribe-hierarchically group)
621 (push group gnus-killed-list)))
623 (defun gnus-subscribe-zombies (group)
624 "Make the new GROUP into a zombie group."
625 (push group gnus-zombie-list))
627 (defun gnus-subscribe-killed (group)
628 "Make the new GROUP a killed group."
629 (push group gnus-killed-list))
631 (defun gnus-subscribe-newsgroup (newsgroup &optional next)
632 "Subscribe new NEWSGROUP.
633 If NEXT is non-nil, it is inserted before NEXT. Otherwise it is made
634 the first newsgroup."
636 (goto-char (point-min))
637 ;; We subscribe the group by changing its level to `subscribed'.
638 (gnus-group-change-level
639 newsgroup gnus-level-default-subscribed
640 gnus-level-killed (gnus-group-entry (or next "dummy.group")))
641 (gnus-message 5 "Subscribe newsgroup: %s" newsgroup)
642 (run-hook-with-args 'gnus-subscribe-newsgroup-hooks newsgroup)
645 (defun gnus-read-active-file-p ()
646 "Say whether the active file has been read from `gnus-select-method'."
647 (memq gnus-select-method gnus-have-read-active-file))
649 ;;; General various misc type functions.
651 ;; Silence byte-compiler.
653 (defvar gnus-current-headers)
654 (defvar gnus-thread-indent-array)
655 (defvar gnus-newsgroup-name)
656 (defvar gnus-newsgroup-headers)
657 (defvar gnus-group-list-mode)
658 (defvar gnus-group-mark-positions)
659 (defvar gnus-newsgroup-data)
660 (defvar gnus-newsgroup-unreads)
661 (defvar nnoo-state-alist)
662 (defvar gnus-current-select-method)
663 (defvar mail-sources)
664 (defvar nnmail-scan-directory-mail-source-once)
665 (defvar nnmail-split-history)
666 (defvar nnmail-spool-file))
668 (defun gnus-clear-quick-file-variables ()
669 "Clear all variables in quick startup files."
670 (let ((variables gnus-variable-list))
671 ;; Clear Gnus variables.
673 (set (car variables) nil)
674 (setq variables (cdr variables))))
675 (let ((files gnus-product-variable-file-list))
677 (let ((variables (nthcdr 3 (car files))))
679 (set (car variables) nil)
680 (setq variables (cdr variables))))
681 (setq files (cdr files)))))
683 (defun gnus-close-all-servers ()
686 (dolist (server gnus-opened-servers)
687 (gnus-close-server (car server))))
689 (defun gnus-clear-system ()
690 "Clear all variables and buffers."
691 ;; Clear gnus variables.
692 (gnus-clear-quick-file-variables)
693 ;; Clear other internal variables.
694 (setq gnus-list-of-killed-groups nil
695 gnus-have-read-active-file nil
696 gnus-agent-covered-methods nil
697 gnus-agent-file-loading-local nil
698 gnus-agent-file-loading-cache nil
699 gnus-server-method-cache nil
700 gnus-newsrc-alist nil
701 gnus-newsrc-hashtb nil
704 gnus-killed-hashtb nil
705 gnus-active-hashtb nil
706 gnus-moderated-hashtb nil
707 gnus-description-hashtb nil
708 gnus-current-headers nil
709 gnus-thread-indent-array nil
710 gnus-newsgroup-headers nil
711 gnus-newsgroup-name nil
712 gnus-server-alist nil
713 gnus-group-list-mode nil
714 gnus-opened-servers nil
715 gnus-group-mark-positions nil
716 gnus-newsgroup-data nil
717 gnus-newsgroup-unreads nil
719 gnus-current-select-method nil
720 nnmail-split-history nil
721 gnus-ephemeral-servers nil)
722 (gnus-shutdown 'gnus)
723 ;; Kill the startup file.
724 (and gnus-current-startup-file
725 (get-file-buffer gnus-current-startup-file)
726 (kill-buffer (get-file-buffer gnus-current-startup-file)))
727 ;; Clear the dribble buffer.
729 ;; Kill global KILL file buffer.
730 (when (get-file-buffer (gnus-newsgroup-kill-file nil))
731 (kill-buffer (get-file-buffer (gnus-newsgroup-kill-file nil))))
732 (gnus-kill-buffer nntp-server-buffer)
733 ;; Kill Gnus buffers.
734 (dolist (buffer (gnus-buffers))
735 (gnus-kill-buffer buffer))
736 ;; Remove Gnus frames.
737 (gnus-kill-gnus-frames))
739 (defun gnus-no-server-1 (&optional arg slave)
741 If ARG is a positive number, Gnus will use that as the
742 startup level. If ARG is nil, Gnus will be started at level 2.
743 If ARG is non-nil and not a positive number, Gnus will
744 prompt the user for the name of an NNTP server to use.
745 As opposed to `gnus', this command will not connect to the local server."
747 (let ((val (or arg (1- gnus-level-default-subscribed))))
749 (make-local-variable 'gnus-group-use-permanent-levels)
750 (setq gnus-group-use-permanent-levels val)))
752 (defun gnus-1 (&optional arg dont-connect slave)
754 If ARG is non-nil and a positive number, Gnus will use that as the
755 startup level. If ARG is non-nil and not a positive number, Gnus will
756 prompt the user for the name of an NNTP server to use."
761 (switch-to-buffer gnus-group-buffer)
762 (gnus-group-get-new-news
765 (max (car gnus-group-list-mode) arg))))
769 (gnus-run-hooks 'gnus-before-startup-hook)
770 (nnheader-init-server-buffer)
771 (setq gnus-slave slave)
772 (gnus-read-init-file)
776 (when gnus-simple-splash
777 (setq gnus-simple-splash nil)
782 (= (frame-height) (1+ (window-height))))
785 (let ((level (and (numberp arg) (> arg 0) arg))
791 (gnus-start-news-server (and arg (not level))))))
792 (if (and (not dont-connect)
795 (gnus-run-hooks 'gnus-startup-hook)
796 ;; NNTP server is successfully open.
798 ;; Find the current startup file name.
799 (setq gnus-current-startup-file
800 (gnus-make-newsrc-file gnus-startup-file))
802 ;; Read the dribble file.
803 (when (or gnus-slave gnus-use-dribble-file)
804 (gnus-dribble-read-file))
806 ;; Do the actual startup.
808 (gnus-request-create-group "queue" '(nndraft "")))
809 (gnus-request-create-group "drafts" '(nndraft ""))
810 (gnus-setup-news nil level dont-connect)
811 (gnus-run-hooks 'gnus-setup-news-hook)
812 (gnus-start-draft-setup)
813 ;; Generate the group buffer.
814 (gnus-group-list-groups level)
815 (gnus-group-first-unread-group)
816 (gnus-configure-windows 'group)
817 (gnus-group-set-mode-line)
819 (set-language-info "Japanese" 'gnus-info "gnus-ja")
820 (gnus-run-hooks 'gnus-started-hook))))))
822 (defun gnus-start-draft-setup ()
823 "Make sure the draft group exists."
824 (gnus-request-create-group "drafts" '(nndraft ""))
825 (unless (gnus-group-entry "nndraft:drafts")
826 (let ((gnus-level-default-subscribed 1))
827 (gnus-subscribe-group "nndraft:drafts" nil '(nndraft "")))
828 (gnus-group-set-parameter
829 "nndraft:drafts" 'gnus-dummy '((gnus-draft-mode)))))
836 (defvar gnus-dribble-ignore nil)
837 (defvar gnus-dribble-eval-file nil)
839 (defun gnus-dribble-file-name ()
840 "Return the dribble file for the current .newsrc."
842 (if gnus-dribble-directory
843 (concat (file-name-as-directory gnus-dribble-directory)
844 (file-name-nondirectory gnus-current-startup-file))
845 gnus-current-startup-file)
848 (defun gnus-dribble-enter (string)
849 "Enter STRING into the dribble buffer."
850 (when (and (not gnus-dribble-ignore)
852 (buffer-name gnus-dribble-buffer))
853 (let ((obuf (current-buffer)))
854 (set-buffer gnus-dribble-buffer)
855 (goto-char (point-max))
857 ;; This has been commented by Josh Huber <huber@alum.wpi.edu>
858 ;; It causes problems with both XEmacs and Emacs 21, and doesn't
859 ;; seem to be of much value. (FIXME: remove this after we make sure
861 ;; (set-window-point (get-buffer-window (current-buffer)) (point-max))
862 (bury-buffer gnus-dribble-buffer)
864 (set-buffer gnus-group-buffer)
865 (gnus-group-set-mode-line))
868 (defun gnus-dribble-touch ()
869 "Touch the dribble buffer."
870 (gnus-dribble-enter ""))
872 (defun gnus-dribble-read-file ()
873 "Read the dribble file from disk."
874 (let ((dribble-file (gnus-dribble-file-name)))
876 (set-buffer (setq gnus-dribble-buffer
877 (gnus-get-buffer-create
878 (file-name-nondirectory dribble-file))))
880 (setq buffer-file-name dribble-file)
882 (buffer-disable-undo)
883 (bury-buffer (current-buffer))
884 (set-buffer-modified-p nil)
885 (let ((auto (make-auto-save-file-name))
886 (gnus-dribble-ignore t)
889 (when (or (file-exists-p auto) (file-exists-p dribble-file))
890 ;; Load whichever file is newest -- the auto save file
891 ;; or the "real" file.
892 (if (file-newer-than-file-p auto dribble-file)
893 (nnheader-insert-file-contents auto)
894 (nnheader-insert-file-contents dribble-file))
895 (unless (zerop (buffer-size))
896 (set-buffer-modified-p t))
897 ;; Set the file modes to reflect the .newsrc file modes.
899 (when (and (file-exists-p gnus-current-startup-file)
900 (file-exists-p dribble-file)
901 (setq modes (file-modes gnus-current-startup-file)))
902 (gnus-set-file-modes dribble-file modes))
903 (goto-char (point-min))
904 (when (search-forward "Gnus was exited on purpose" nil t)
906 ;; Possibly eval the file later.
907 (when (or gnus-always-read-dribble-file
910 "Gnus exited on purpose without saving; read auto-save file anyway? "
911 "Gnus auto-save file exists. Do you want to read it? ")))
912 (setq gnus-dribble-eval-file t)))))))
914 (defun gnus-dribble-eval-file ()
915 (when gnus-dribble-eval-file
916 (setq gnus-dribble-eval-file nil)
918 (let ((gnus-dribble-ignore t))
919 (set-buffer gnus-dribble-buffer)
920 (eval-buffer (current-buffer))))))
922 (defun gnus-dribble-delete-file ()
923 (when (file-exists-p (gnus-dribble-file-name))
924 (delete-file (gnus-dribble-file-name)))
925 (when gnus-dribble-buffer
927 (set-buffer gnus-dribble-buffer)
928 (let ((auto (make-auto-save-file-name)))
929 (when (file-exists-p auto)
932 (set-buffer-modified-p nil)))))
934 (defun gnus-dribble-save ()
935 (when (and gnus-dribble-buffer
936 (buffer-name gnus-dribble-buffer))
938 (set-buffer gnus-dribble-buffer)
941 (defun gnus-dribble-clear ()
942 (when (gnus-buffer-exists-p gnus-dribble-buffer)
944 (set-buffer gnus-dribble-buffer)
946 (set-buffer-modified-p nil)
947 (setq buffer-saved-size (buffer-size)))))
951 ;;; Active & Newsrc File Handling
954 (defun gnus-setup-news (&optional rawfile level dont-connect)
955 "Setup news information.
956 If RAWFILE is non-nil, the .newsrc file will also be read.
957 If LEVEL is non-nil, the news will be set up at level LEVEL."
959 (let ((init (not (and gnus-newsrc-alist gnus-active-hashtb (not rawfile))))
960 ;; Binding this variable will inhibit multiple fetchings
961 ;; of the same mail source.
962 (nnmail-fetched-sources (list t)))
965 ;; Clear some variables to re-initialize news information.
966 (setq gnus-newsrc-alist nil
967 gnus-active-hashtb nil)
968 ;; Read the newsrc file and create `gnus-newsrc-hashtb'.
969 (gnus-read-newsrc-file rawfile))
971 ;; Make sure the archive server is available to all and sundry.
972 (when gnus-message-archive-method
973 (unless (assoc "archive" gnus-server-alist)
978 ,(nnheader-concat message-directory "archive"))
979 (nnfolder-active-file
980 ,(nnheader-concat message-directory "archive/active"))
981 (nnfolder-get-new-mail nil)
982 (nnfolder-inhibit-expiry t))
985 ;; If we don't read the complete active file, we fill in the
987 (when (or (null gnus-read-active-file)
988 (eq gnus-read-active-file 'some))
989 (gnus-update-active-hashtb-from-killed))
991 ;; Validate agent covered methods now that gnus-server-alist has
993 ;; NOTE: This is here for one purpose only. By validating the
994 ;; agentized server's, it converts the old 5.10.3, and earlier,
995 ;; format to the current format. That enables the agent code
996 ;; within gnus-read-active-file to function correctly.
998 (gnus-agent-read-servers-validate))
1000 ;; Read the active file and create `gnus-active-hashtb'.
1001 ;; If `gnus-read-active-file' is nil, then we just create an empty
1002 ;; hash table. The partial filling out of the hash table will be
1003 ;; done in `gnus-get-unread-articles'.
1004 (and gnus-read-active-file
1006 (gnus-read-active-file nil dont-connect))
1008 (unless gnus-active-hashtb
1009 (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
1011 ;; Initialize the cache.
1012 (when gnus-use-cache
1015 ;; Possibly eval the dribble file.
1017 (or gnus-use-dribble-file gnus-slave)
1018 (gnus-dribble-eval-file))
1020 ;; Slave Gnusii should then clear the dribble buffer.
1021 (when (and init gnus-slave)
1022 (gnus-dribble-clear))
1024 (gnus-update-format-specifications)
1026 ;; See whether we need to read the description file.
1027 (when (and (boundp 'gnus-group-line-format)
1028 (stringp gnus-group-line-format)
1029 (let ((case-fold-search nil))
1030 (string-match "%[-,0-9]*D" gnus-group-line-format))
1031 (not gnus-description-hashtb)
1033 gnus-read-active-file)
1034 (gnus-read-all-descriptions-files))
1036 ;; Find new newsgroups and treat them.
1037 (when (and init gnus-check-new-newsgroups (not level)
1038 (gnus-check-server gnus-select-method)
1041 (gnus-find-new-newsgroups))
1043 ;; Check and remove bogus newsgroups.
1044 (when (and init gnus-check-bogus-newsgroups
1045 gnus-read-active-file (not level)
1046 (gnus-server-opened gnus-select-method))
1047 (gnus-check-bogus-newsgroups))
1049 ;; We might read in new NoCeM messages here.
1050 (when (and gnus-use-nocem
1053 (gnus-nocem-scan-groups))
1055 ;; Read any slave files.
1056 (gnus-master-read-slave-newsrc)
1058 ;; Find the number of unread articles in each non-dead group.
1059 (let ((gnus-read-active-file (and (not level) gnus-read-active-file)))
1060 (gnus-get-unread-articles level))))
1062 (defun gnus-call-subscribe-functions (method group)
1063 "Call METHOD to subscribe GROUP.
1064 If no function returns `non-nil', call `gnus-subscribe-zombies'."
1067 (funcall method group))
1070 (dolist (func method)
1071 (if (funcall func group)
1075 (gnus-subscribe-zombies group)))
1077 (defun gnus-find-new-newsgroups (&optional arg)
1078 "Search for new newsgroups and add them.
1079 Each new newsgroup will be treated with `gnus-subscribe-newsgroup-method'.
1080 The `-n' option line from .newsrc is respected.
1082 With 1 C-u, use the `ask-server' method to query the server for new
1084 With 2 C-u's, use most complete method possible to query the server
1085 for new groups, and subscribe the new groups as zombies."
1087 (let* ((gnus-subscribe-newsgroup-method
1088 gnus-subscribe-newsgroup-method)
1090 ((or (and (= (or arg 1) 4)
1091 (not (listp gnus-check-new-newsgroups)))
1092 (null gnus-read-active-file)
1093 (eq gnus-read-active-file 'some))
1096 (setq gnus-subscribe-newsgroup-method
1097 'gnus-subscribe-zombies)
1099 (t gnus-check-new-newsgroups))))
1100 (unless (gnus-check-first-time-used)
1101 (if (or (consp check)
1102 (eq check 'ask-server))
1103 ;; Ask the server for new groups.
1104 (gnus-ask-server-for-new-groups)
1105 ;; Go through the active hashtb and look for new groups.
1107 group new-newsgroups)
1108 (gnus-message 5 "Looking for new newsgroups...")
1109 (unless gnus-have-read-active-file
1110 (gnus-read-active-file))
1111 (setq gnus-newsrc-last-checked-date (message-make-date))
1112 (unless gnus-killed-hashtb
1113 (gnus-make-hashtable-from-killed))
1114 ;; Go though every newsgroup in `gnus-active-hashtb' and compare
1115 ;; with `gnus-newsrc-hashtb' and `gnus-killed-hashtb'.
1118 (if (or (null (setq group (symbol-name sym)))
1120 (null (symbol-value sym))
1121 (gnus-gethash group gnus-killed-hashtb)
1122 (gnus-gethash group gnus-newsrc-hashtb))
1124 (let ((do-sub (gnus-matches-options-n group)))
1126 ((eq do-sub 'subscribe)
1127 (setq groups (1+ groups))
1128 (gnus-sethash group group gnus-killed-hashtb)
1129 (gnus-call-subscribe-functions
1130 gnus-subscribe-options-newsgroup-method group))
1131 ((eq do-sub 'ignore)
1134 (setq groups (1+ groups))
1135 (gnus-sethash group group gnus-killed-hashtb)
1136 (if gnus-subscribe-hierarchical-interactive
1137 (push group new-newsgroups)
1138 (gnus-call-subscribe-functions
1139 gnus-subscribe-newsgroup-method group)))))))
1141 (when new-newsgroups
1142 (gnus-subscribe-hierarchical-interactive new-newsgroups))
1144 (gnus-message 5 "%d new newsgroup%s arrived."
1145 groups (if (> groups 1) "s have" " has"))
1146 (gnus-message 5 "No new newsgroups.")))))))
1148 (defun gnus-matches-options-n (group)
1149 ;; Returns `subscribe' if the group is to be unconditionally
1150 ;; subscribed, `ignore' if it is to be ignored, and nil if there is
1151 ;; no match for the group.
1153 ;; First we check the two user variables.
1155 ((and gnus-options-subscribe
1156 (string-match gnus-options-subscribe group))
1158 ((and gnus-auto-subscribed-groups
1159 (string-match gnus-auto-subscribed-groups group))
1161 ((and gnus-options-not-subscribe
1162 (string-match gnus-options-not-subscribe group))
1164 ;; Then we go through the list that was retrieved from the .newsrc
1165 ;; file. This list has elements on the form
1166 ;; `(REGEXP . {ignore,subscribe})'. The first match found (the list
1167 ;; is in the reverse order of the options line) is returned.
1169 (let ((regs gnus-newsrc-options-n))
1171 (not (string-match (caar regs) group)))
1172 (setq regs (cdr regs)))
1173 (and regs (cdar regs))))))
1175 (defun gnus-ask-server-for-new-groups ()
1176 (let* ((new-date (message-make-date))
1177 (date (or gnus-newsrc-last-checked-date new-date))
1178 (methods (cons gnus-select-method
1180 (when (gnus-archive-server-wanted-p)
1183 (and (consp gnus-check-new-newsgroups)
1184 gnus-check-new-newsgroups)
1185 gnus-secondary-select-methods))))
1187 group new-newsgroups got-new method hashtb
1188 gnus-override-subscribe-method)
1189 (unless gnus-killed-hashtb
1190 (gnus-make-hashtable-from-killed))
1191 ;; Go through both primary and secondary select methods and
1192 ;; request new newsgroups.
1193 (while (setq method (gnus-server-get-method nil (pop methods)))
1194 (setq new-newsgroups nil
1195 gnus-override-subscribe-method method)
1196 (when (and (gnus-check-server method)
1197 (gnus-request-newgroups date method))
1200 hashtb (gnus-make-hashtable 100))
1201 (set-buffer nntp-server-buffer)
1202 ;; Enter all the new groups into a hashtable.
1203 (gnus-active-to-gnus-format method hashtb 'ignore))
1204 ;; Now all new groups from `method' are in `hashtb'.
1207 (if (or (null (setq group (symbol-name group-sym)))
1208 (not (boundp group-sym))
1209 (null (symbol-value group-sym))
1210 (gnus-gethash group gnus-newsrc-hashtb)
1211 (member group gnus-zombie-list)
1212 (member group gnus-killed-list))
1213 ;; The group is already known.
1215 ;; Make this group active.
1216 (when (symbol-value group-sym)
1217 (gnus-set-active group (symbol-value group-sym)))
1218 ;; Check whether we want it or not.
1219 (let ((do-sub (gnus-matches-options-n group)))
1221 ((eq do-sub 'subscribe)
1223 (gnus-sethash group group gnus-killed-hashtb)
1224 (gnus-call-subscribe-functions
1225 gnus-subscribe-options-newsgroup-method group))
1226 ((eq do-sub 'ignore)
1230 (gnus-sethash group group gnus-killed-hashtb)
1231 (if gnus-subscribe-hierarchical-interactive
1232 (push group new-newsgroups)
1233 (gnus-call-subscribe-functions
1234 gnus-subscribe-newsgroup-method group)))))))
1236 (when new-newsgroups
1237 (gnus-subscribe-hierarchical-interactive new-newsgroups)))
1239 (gnus-message 5 "%d new newsgroup%s arrived"
1240 groups (if (> groups 1) "s have" " has"))
1241 (gnus-message 5 "No new newsgroups"))
1243 (setq gnus-newsrc-last-checked-date new-date))
1246 (defun gnus-check-first-time-used ()
1248 ;; First check if any of the following files exist. If they do,
1249 ;; it's not the first time the user has used Gnus.
1250 (dolist (file (list (concat gnus-current-startup-file ".el")
1251 (concat gnus-current-startup-file ".eld")
1252 (concat gnus-startup-file ".el")
1253 (concat gnus-startup-file ".eld")))
1254 (when (file-exists-p file)
1255 (throw 'ended nil)))
1256 (gnus-message 6 "First time user; subscribing you to default groups")
1257 (unless (gnus-read-active-file-p)
1258 (let ((gnus-read-active-file t))
1259 (gnus-read-active-file)))
1260 (setq gnus-newsrc-last-checked-date (message-make-date))
1261 ;; Subscribe to the default newsgroups.
1262 (let ((groups (or gnus-default-subscribed-newsgroups
1263 gnus-backup-default-subscribed-newsgroups))
1266 ;; If t, we subscribe (or not) all groups as if they were new.
1269 (when (setq group (symbol-name sym))
1270 (let ((do-sub (gnus-matches-options-n group)))
1272 ((eq do-sub 'subscribe)
1273 (gnus-sethash group group gnus-killed-hashtb)
1274 (gnus-call-subscribe-functions
1275 gnus-subscribe-options-newsgroup-method group))
1276 ((eq do-sub 'ignore)
1279 (push group gnus-killed-list))))))
1281 (dolist (group groups)
1282 ;; Only subscribe the default groups that are activated.
1283 (when (gnus-active group)
1284 (gnus-group-change-level
1285 group gnus-level-default-subscribed gnus-level-killed)))
1287 (set-buffer gnus-group-buffer)
1288 ;; Don't error if the group already exists. This happens when a
1289 ;; first-time user types 'F'. -- didier
1290 (gnus-group-make-help-group t))
1291 (when gnus-novice-user
1292 (gnus-message 7 "`A k' to list killed groups"))))))
1294 (defun gnus-subscribe-group (group &optional previous method)
1295 "Subscribe GROUP and put it after PREVIOUS."
1296 (gnus-group-change-level
1298 (list t group gnus-level-default-subscribed nil nil method)
1300 gnus-level-default-subscribed gnus-level-killed previous t)
1303 ;; `gnus-group-change-level' is the fundamental function for changing
1304 ;; subscription levels of newsgroups. This might mean just changing
1305 ;; from level 1 to 2, which is pretty trivial, from 2 to 6 or back
1306 ;; again, which subscribes/unsubscribes a group, which is equally
1307 ;; trivial. Changing from 1-7 to 8-9 means that you kill a group, and
1308 ;; from 8-9 to 1-7 means that you remove the group from the list of
1309 ;; killed (or zombie) groups and add them to the (kinda) subscribed
1310 ;; groups. And last but not least, moving from 8 to 9 and 9 to 8,
1311 ;; which is trivial.
1312 ;; ENTRY can either be a string (newsgroup name) or a list (if
1313 ;; FROMKILLED is t, it's a list on the format (NUM INFO-LIST),
1314 ;; otherwise it's a list in the format of the `gnus-newsrc-hashtb'
1316 ;; LEVEL is the new level of the group, OLDLEVEL is the old level and
1317 ;; PREVIOUS is the group (in hashtb entry format) to insert this group
1319 (defun gnus-group-change-level (entry level &optional oldlevel
1320 previous fromkilled)
1321 (let (group info active num)
1322 ;; Glean what info we can from the arguments
1324 (if fromkilled (setq group (nth 1 entry))
1325 (setq group (car (nth 2 entry))))
1327 (when (and (stringp entry)
1329 (< oldlevel gnus-level-zombie))
1330 (setq entry (gnus-group-entry entry)))
1331 (if (and (not oldlevel)
1333 (setq oldlevel (gnus-info-level (nth 2 entry)))
1334 (setq oldlevel (or oldlevel gnus-level-killed)))
1335 (when (stringp previous)
1336 (setq previous (gnus-group-entry previous)))
1338 (if (and (>= oldlevel gnus-level-zombie)
1339 (gnus-group-entry group))
1340 ;; We are trying to subscribe a group that is already
1344 (unless (gnus-ephemeral-group-p group)
1346 (format "(gnus-group-change-level %S %S %S %S %S)"
1347 group level oldlevel (car (nth 2 previous)) fromkilled)))
1349 ;; Then we remove the newgroup from any old structures, if needed.
1350 ;; If the group was killed, we remove it from the killed or zombie
1351 ;; list. If not, and it is in fact going to be killed, we remove
1352 ;; it from the newsrc hash table and assoc.
1354 ((>= oldlevel gnus-level-zombie)
1355 ;; oldlevel could be wrong.
1356 (setq gnus-zombie-list (delete group gnus-zombie-list))
1357 (setq gnus-killed-list (delete group gnus-killed-list)))
1359 (when (and (>= level gnus-level-zombie)
1361 (gnus-sethash (car (nth 2 entry)) nil gnus-newsrc-hashtb)
1363 (setcdr (gnus-group-entry (car (nth 3 entry)))
1365 (setcdr (cdr entry) (cdddr entry)))))
1367 ;; Finally we enter (if needed) the list where it is supposed to
1368 ;; go, and change the subscription level. If it is to be killed,
1369 ;; we enter it into the killed or zombie list.
1371 ((>= level gnus-level-zombie)
1372 ;; Remove from the hash table.
1373 (gnus-sethash group nil gnus-newsrc-hashtb)
1374 ;; We do not enter foreign groups into the list of dead
1376 (unless (gnus-group-foreign-p group)
1377 (if (= level gnus-level-zombie)
1378 (push group gnus-zombie-list)
1379 (if (= oldlevel gnus-level-killed)
1380 ;; Remove from active hashtb.
1381 (unintern group gnus-active-hashtb)
1382 ;; Don't add it into killed-list if it was killed.
1383 (push group gnus-killed-list)))))
1385 ;; If the list is to be entered into the newsrc assoc, and
1386 ;; it was killed, we have to create an entry in the newsrc
1387 ;; hashtb format and fix the pointers in the newsrc assoc.
1388 (if (< oldlevel gnus-level-zombie)
1389 ;; It was alive, and it is going to stay alive, so we
1390 ;; just change the level and don't change any pointers or
1391 ;; hash table entries.
1392 (setcar (cdaddr entry) level)
1394 (setq info (cdr entry)
1396 (setq active (gnus-active group))
1398 (if active (- (1+ (cdr active)) (car active)) t))
1399 ;; Shorten the select method if possible, if we need to
1400 ;; store it at all (native groups).
1401 (let ((method (gnus-method-simplify
1402 (or gnus-override-subscribe-method
1403 (gnus-group-method group)))))
1405 (setq info (list group level nil nil method))
1406 (setq info (list group level nil)))))
1409 (let ((p gnus-newsrc-alist))
1413 (setq entry (cons info (cddr previous)))
1416 (setcdr (cdr previous) entry)
1417 (gnus-sethash group (cons num (cdr previous))
1418 gnus-newsrc-hashtb))
1419 (setcdr previous entry)
1420 (gnus-sethash group (cons num previous)
1421 gnus-newsrc-hashtb))
1423 (setcdr (gnus-group-entry (caadr entry)) entry))
1426 "(gnus-group-set-info '%S)" info)))))
1427 (when gnus-group-change-level-function
1428 (funcall gnus-group-change-level-function
1429 group level oldlevel previous)))))
1431 (defun gnus-kill-newsgroup (newsgroup)
1432 "Obsolete function. Kills a newsgroup."
1433 (gnus-group-change-level
1434 (gnus-group-entry newsgroup) gnus-level-killed))
1436 (defun gnus-check-bogus-newsgroups (&optional confirm)
1437 "Remove bogus newsgroups.
1438 If CONFIRM is non-nil, the user has to confirm the deletion of every
1440 (let ((newsrc (cdr gnus-newsrc-alist))
1441 bogus group entry info)
1442 (gnus-message 5 "Checking bogus newsgroups...")
1443 (unless (gnus-read-active-file-p)
1444 (gnus-read-active-file t))
1445 (when (gnus-read-active-file-p)
1446 ;; Find all bogus newsgroup that are subscribed.
1448 (setq info (pop newsrc)
1449 group (gnus-info-group info))
1450 (unless (or (gnus-active group) ; Active
1451 (and (gnus-info-method info)
1452 (not (gnus-secondary-method-p
1453 (gnus-info-method info))))) ; Foreign
1454 ;; Found a bogus newsgroup.
1455 (push group bogus)))
1458 "Remove bogus group %s? "
1460 ;; Remove all bogus subscribed groups by first killing them, and
1461 ;; then removing them from the list of killed groups.
1462 (when (setq entry (gnus-group-entry group))
1463 (gnus-group-change-level entry gnus-level-killed)
1464 (setq gnus-killed-list (delete group gnus-killed-list))))
1465 bogus '("group" "groups" "remove"))
1466 (while (setq group (pop bogus))
1467 ;; Remove all bogus subscribed groups by first killing them, and
1468 ;; then removing them from the list of killed groups.
1469 (when (setq entry (gnus-group-entry group))
1470 (gnus-group-change-level entry gnus-level-killed)
1471 (setq gnus-killed-list (delete group gnus-killed-list)))))
1472 ;; Then we remove all bogus groups from the list of killed and
1473 ;; zombie groups. They are removed without confirmation.
1474 (let ((dead-lists '(gnus-killed-list gnus-zombie-list))
1477 (setq killed (symbol-value (car dead-lists)))
1479 (unless (gnus-active (setq group (pop killed)))
1480 ;; The group is bogus.
1482 (set (car dead-lists)
1483 (delete group (symbol-value (car dead-lists))))))
1484 (setq dead-lists (cdr dead-lists))))
1485 (gnus-run-hooks 'gnus-check-bogus-groups-hook)
1486 (gnus-message 5 "Checking bogus newsgroups...done"))))
1488 (defun gnus-check-duplicate-killed-groups ()
1489 "Remove duplicates from the list of killed groups."
1491 (let ((killed gnus-killed-list))
1493 (gnus-message 9 "%d" (length killed))
1494 (setcdr killed (delete (car killed) (cdr killed)))
1495 (setq killed (cdr killed)))))
1497 ;; We want to inline a function from gnus-cache, so we cheat here:
1499 (defvar gnus-cache-active-hashtb)
1500 (defun gnus-cache-possibly-alter-active (group active)
1501 "Alter the ACTIVE info for GROUP to reflect the articles in the cache."
1502 (when gnus-cache-active-hashtb
1503 (let ((cache-active (gnus-gethash group gnus-cache-active-hashtb)))
1505 (when (< (car cache-active) (car active))
1506 (setcar active (car cache-active)))
1507 (when (> (cdr cache-active) (cdr active))
1508 (setcdr active (cdr cache-active))))))))
1510 (defun gnus-activate-group (group &optional scan dont-check method)
1511 "Check whether a group has been activated or not.
1512 If SCAN, request a scan of that group as well."
1513 (let ((method (or method (inline (gnus-find-method-for-group group))))
1515 (and (inline (gnus-check-server method))
1516 ;; We escape all bugs and quit here to make it possible to
1517 ;; continue if a group is so out-there that it reports bugs
1521 (gnus-check-backend-function 'request-scan (car method))
1522 (gnus-request-scan group method))
1524 (if (or debug-on-error debug-on-quit)
1525 (inline (gnus-request-group group dont-check method))
1527 (inline (gnus-request-group group dont-check method))
1530 (message "Quit activating %s" group)
1533 (setq active (gnus-parse-active))
1534 ;; If there are no articles in the group, the GROUP
1535 ;; command may have responded with the `(0 . 0)'. We
1536 ;; ignore this if we already have an active entry
1538 (if (and (zerop (car active))
1539 (zerop (cdr active))
1540 (gnus-active group))
1543 ;; If a cache is present, we may have to alter the active info.
1544 (when gnus-use-cache
1545 (inline (gnus-cache-possibly-alter-active
1548 ;; If the agent is enabled, we may have to alter the active info.
1550 (gnus-agent-possibly-alter-active group active))
1552 (gnus-set-active group active)
1553 ;; Return the new active info.
1556 (defun gnus-get-unread-articles-in-group (info active &optional update)
1557 (when (and info active)
1558 ;; Allow the backend to update the info in the group.
1560 (gnus-request-update-info
1561 info (inline (gnus-find-method-for-group
1562 (gnus-info-group info)))))
1563 (gnus-activate-group (gnus-info-group info) nil t))
1565 (let* ((range (gnus-info-read info))
1568 ;; These checks are present in gnus-activate-group but skipped
1569 ;; due to setting dont-check in the preceeding call.
1571 ;; If a cache is present, we may have to alter the active info.
1572 (when (and gnus-use-cache info)
1573 (inline (gnus-cache-possibly-alter-active
1574 (gnus-info-group info) active)))
1576 ;; If the agent is enabled, we may have to alter the active info.
1577 (when (and gnus-agent info)
1578 (gnus-agent-possibly-alter-active (gnus-info-group info) active info))
1580 ;; Modify the list of read articles according to what articles
1581 ;; are available; then tally the unread articles and add the
1582 ;; number to the group hash table entry.
1584 ((zerop (cdr active))
1587 (setq num (- (1+ (cdr active)) (car active))))
1588 ((not (listp (cdr range)))
1589 ;; Fix a single (num . num) range according to the
1590 ;; active hash table.
1591 ;; Fix by Carsten Bormann <cabo@Informatik.Uni-Bremen.DE>.
1592 (and (< (cdr range) (car active)) (setcdr range (1- (car active))))
1593 (and (> (cdr range) (cdr active)) (setcdr range (cdr active)))
1594 ;; Compute number of unread articles.
1595 (setq num (max 0 (- (cdr active) (- (1+ (cdr range)) (car range))))))
1597 ;; The read list is a list of ranges. Fix them according to
1598 ;; the active hash table.
1599 ;; First peel off any elements that are below the lower
1601 (while (and (cdr range)
1603 (or (and (atom (cadr range)) (cadr range))
1605 (if (numberp (car range))
1608 (or (and (numberp (cadr range))
1612 (or (and (numberp (nth 1 range)) (nth 1 range))
1614 (setcdr range (cddr range)))
1615 ;; Adjust the first element to be the same as the lower limit.
1616 (when (and (not (atom (car range)))
1617 (< (cdar range) (car active)))
1618 (setcdr (car range) (1- (car active))))
1619 ;; Then we want to peel off any elements that are higher
1620 ;; than the upper active limit.
1621 (let ((srange range))
1622 ;; Go past all valid elements.
1623 (while (and (cdr srange)
1624 (<= (or (and (atom (cadr srange))
1628 (setq srange (cdr srange)))
1630 ;; Nuke all remaining invalid elements.
1631 (setcdr srange nil))
1633 ;; Adjust the final element.
1634 (when (and (not (atom (car srange)))
1635 (> (cdar srange) (cdr active)))
1636 (setcdr (car srange) (cdr active))))
1637 ;; Compute the number of unread articles.
1639 (setq num (+ num (- (1+ (or (and (atom (car range)) (car range))
1641 (or (and (atom (car range)) (car range))
1643 (setq range (cdr range)))
1644 (setq num (max 0 (- (cdr active) num)))))
1645 ;; Set the number of unread articles.
1647 (gnus-group-entry (gnus-info-group info)))
1648 (setcar (gnus-group-entry (gnus-info-group info)) num))
1651 ;; Go though `gnus-newsrc-alist' and compare with `gnus-active-hashtb'
1652 ;; and compute how many unread articles there are in each group.
1653 (defun gnus-get-unread-articles (&optional level)
1654 (setq gnus-server-method-cache nil)
1655 (let* ((newsrc (cdr gnus-newsrc-alist))
1656 (level (or level gnus-activate-level (1+ gnus-level-subscribed)))
1659 (cond ((and gnus-activate-foreign-newsgroups
1660 (not (numberp gnus-activate-foreign-newsgroups)))
1661 (1+ gnus-level-subscribed))
1662 ((numberp gnus-activate-foreign-newsgroups)
1663 gnus-activate-foreign-newsgroups)
1668 scanned-methods info group active method retrieve-groups cmethod
1670 (gnus-message 6 "Checking new news...")
1673 (setq active (gnus-active (setq group (gnus-info-group
1674 (setq info (pop newsrc))))))
1676 ;; Check newsgroups. If the user doesn't want to check them, or
1677 ;; they can't be checked (for instance, if the news server can't
1678 ;; be reached) we just set the number of unread articles in this
1679 ;; newsgroup to t. This means that Gnus thinks that there are
1680 ;; unread articles, but it has no idea how many.
1682 ;; To be more explicit:
1683 ;; >0 for an active group with messages
1684 ;; 0 for an active group with no unread messages
1685 ;; nil for non-foreign groups that the user has requested not be checked
1686 ;; t for unchecked foreign groups or bogus groups, or groups that can't
1687 ;; be checked, for one reason or other.
1688 (when (setq method (gnus-info-method info))
1689 (if (setq cmethod (assoc method methods-cache))
1690 (setq method (cdr cmethod))
1691 (setq cmethod (inline (gnus-server-get-method nil method)))
1692 (push (cons method cmethod) methods-cache)
1693 (setq method cmethod)))
1695 (not (setq method-type (cdr (assoc method type-cache)))))
1698 ((gnus-secondary-method-p method)
1700 ((inline (gnus-server-equal gnus-select-method method))
1704 (push (cons method method-type) type-cache))
1707 (cond ((and method (eq method-type 'foreign))
1708 ;; These groups are foreign. Check the level.
1709 (if (<= (gnus-info-level info) foreign-level)
1710 (when (and (<= (gnus-info-level info) foreign-level)
1711 (setq active (gnus-activate-group group 'scan)))
1712 ;; Let the Gnus agent save the active file.
1713 (when (and gnus-agent active (gnus-online method))
1714 (gnus-agent-save-group-info
1715 method (gnus-group-real-name group) active))
1716 (unless (inline (gnus-virtual-group-p group))
1717 (inline (gnus-close-group group)))
1718 (when (fboundp (intern (concat (symbol-name (car method))
1719 "-request-update-info")))
1720 (inline (gnus-request-update-info info method))))
1722 ;; These groups are native or secondary.
1723 ((> (gnus-info-level info) level)
1724 ;; We don't want these groups.
1725 (setq active 'ignore))
1727 ((not gnus-read-active-file)
1728 (if (gnus-check-backend-function 'retrieve-groups group)
1729 ;; if server support gnus-retrieve-groups we push
1730 ;; the group onto retrievegroups for later checking
1731 (if (assoc method retrieve-groups)
1732 (setcdr (assoc method retrieve-groups)
1733 (cons group (cdr (assoc method retrieve-groups))))
1734 (push (list method group) retrieve-groups))
1735 ;; hack: `nnmail-get-new-mail' changes the mail-source depending
1736 ;; on the group, so we must perform a scan for every group
1737 ;; if the users has any directory mail sources.
1738 ;; hack: if `nnmail-scan-directory-mail-source-once' is non-nil,
1739 ;; for it scan all spool files even when the groups are
1742 (or nnmail-scan-directory-mail-source-once
1743 (null (assq 'directory
1745 (if (listp nnmail-spool-file)
1747 (list nnmail-spool-file))))))
1748 (member method scanned-methods))
1749 (setq active (gnus-activate-group group))
1750 (setq active (gnus-activate-group group 'scan))
1751 (push method scanned-methods))
1753 (gnus-close-group group)))))
1755 ;; Get the number of unread articles in the group.
1757 ((eq active 'ignore)
1758 ;; Don't do anything.
1760 ((and active ignore)
1761 ;; The level of the foreign group is higher than the specified
1765 (inline (gnus-get-unread-articles-in-group info active t)))
1767 ;; The group couldn't be reached, so we nix out the number of
1768 ;; unread articles and stuff.
1769 (gnus-set-active group nil)
1770 (let ((tmp (gnus-group-entry group)))
1774 ;; iterate through groups on methods which support gnus-retrieve-groups
1775 ;; and fetch a partial active file and use it to find new news.
1776 (dolist (rg retrieve-groups)
1777 (let ((method (or (car rg) gnus-select-method))
1779 (when (gnus-check-server method)
1780 ;; Request that the backend scan its incoming messages.
1781 (when (gnus-check-backend-function 'request-scan (car method))
1782 (gnus-request-scan nil method))
1783 (gnus-read-active-file-2
1784 (mapcar (lambda (group) (gnus-group-real-name group)) groups)
1786 (dolist (group groups)
1788 ((setq active (gnus-active (gnus-info-group
1789 (setq info (gnus-get-info group)))))
1790 (inline (gnus-get-unread-articles-in-group info active t)))
1792 ;; The group couldn't be reached, so we nix out the number of
1793 ;; unread articles and stuff.
1794 (gnus-set-active group nil)
1795 (setcar (gnus-group-entry group) t)))))))
1797 (gnus-message 6 "Checking new news...done")))
1799 ;; Create a hash table out of the newsrc alist. The `car's of the
1800 ;; alist elements are used as keys.
1801 (defun gnus-make-hashtable-from-newsrc-alist ()
1802 (let ((alist gnus-newsrc-alist)
1803 (ohashtb gnus-newsrc-hashtb)
1804 prev info method rest methods)
1805 (setq gnus-newsrc-hashtb (gnus-make-hashtable (length alist)))
1807 (setq prev (setq gnus-newsrc-alist
1808 (if (equal (caar gnus-newsrc-alist)
1811 (cons (list "dummy.group" 0 nil) alist)))))
1813 (setq info (car alist))
1814 ;; Make the same select-methods identical Lisp objects.
1815 (when (setq method (gnus-info-method info))
1816 (if (setq rest (member method methods))
1817 (gnus-info-set-method info (car rest))
1818 (push method methods)))
1821 ;; Preserve number of unread articles in groups.
1822 (cons (and ohashtb (car (gnus-gethash (car info) ohashtb)))
1827 ;; Make the same select-methods in `gnus-server-alist' identical
1830 (setq method (pop methods))
1831 (when (setq rest (rassoc method gnus-server-alist))
1832 (setcdr rest method)))))
1834 (defun gnus-make-hashtable-from-killed ()
1835 "Create a hash table from the killed and zombie lists."
1836 (let ((lists '(gnus-killed-list gnus-zombie-list))
1838 (setq gnus-killed-hashtb
1839 (gnus-make-hashtable
1840 (+ (length gnus-killed-list) (length gnus-zombie-list))))
1842 (setq list (symbol-value (pop lists)))
1844 (gnus-sethash (car list) (pop list) gnus-killed-hashtb)))))
1846 (defun gnus-parse-active ()
1847 "Parse active info in the nntp server buffer."
1849 (set-buffer nntp-server-buffer)
1850 (goto-char (point-min))
1851 ;; Parse the result we got from `gnus-request-group'.
1852 (when (looking-at "[0-9]+ [0-9]+ \\([0-9]+\\) [0-9]+")
1853 (goto-char (match-beginning 1))
1854 (cons (read (current-buffer))
1855 (read (current-buffer))))))
1857 (defun gnus-make-articles-unread (group articles)
1858 "Mark ARTICLES in GROUP as unread."
1859 (let* ((info (nth 2 (or (gnus-group-entry group)
1861 (gnus-group-real-name group)))))
1862 (ranges (gnus-info-read info))
1865 (when (gnus-member-of-range
1866 (setq article (pop articles)) ranges)
1867 (push article news)))
1869 ;; Enter this list into the group info.
1871 info (gnus-remove-from-range (gnus-info-read info) (nreverse news)))
1873 ;; Set the number of unread articles in gnus-newsrc-hashtb.
1874 (gnus-get-unread-articles-in-group info (gnus-active group))
1876 ;; Insert the change into the group buffer and the dribble file.
1877 (gnus-group-update-group group t))))
1879 (defun gnus-make-ascending-articles-unread (group articles)
1880 "Mark ascending ARTICLES in GROUP as unread."
1881 (let* ((entry (or (gnus-group-entry group)
1882 (gnus-group-entry (gnus-group-real-name group))))
1883 (info (nth 2 entry))
1884 (ranges (gnus-info-read info))
1889 (let ((article (pop articles))) ; get the next article to remove from ranges
1890 (while (let ((range (car ranges))) ; note the current range
1891 (if (atom range) ; single value range
1893 ;; the articles extend past the end of the ranges
1895 (setq articles nil))
1897 ;; this range preceeds the article. Leave the range unmodified.
1901 ;; this range exactly matches the article; REMOVE THE RANGE.
1902 ;; NOTE: When the range being removed is the last range, the list is corrupted by inserting null at its end.
1903 (setcar ranges (cadr ranges))
1904 (setcdr ranges (cddr ranges))
1905 (setq modified (if (car ranges) t 'remove-null))
1907 (let ((min (car range))
1909 ;; I have a min/max range to consider
1910 (cond ((> min max) ; invalid range introduced by splitter
1911 (setcar ranges (cadr ranges))
1912 (setcdr ranges (cddr ranges))
1913 (setq modified (if (car ranges) t 'remove-null))
1916 ;; replace min/max range with a single-value range
1920 ;; this range preceeds the article. Leave the range unmodified.
1924 ;; this article preceeds the range. Return null to move to the
1928 ;; this article splits the range into two parts
1929 (setcdr ranges (cons (cons (1+ article) max) (cdr ranges)))
1930 (setcdr range (1- article))
1935 (when (eq modified 'remove-null)
1936 (setq r (delq nil r)))
1937 ;; Enter this list into the group info.
1938 (gnus-info-set-read info r)
1940 ;; Set the number of unread articles in gnus-newsrc-hashtb.
1941 (gnus-get-unread-articles-in-group info (gnus-active group))
1943 ;; Insert the change into the group buffer and the dribble file.
1944 (gnus-group-update-group group t))))
1946 ;; Enter all dead groups into the hashtb.
1947 (defun gnus-update-active-hashtb-from-killed ()
1948 (let ((hashtb (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
1949 (lists (list gnus-killed-list gnus-zombie-list))
1952 (setq killed (car lists))
1954 (gnus-sethash (car killed) nil hashtb)
1955 (setq killed (cdr killed)))
1956 (setq lists (cdr lists)))))
1958 (defun gnus-get-killed-groups ()
1959 "Go through the active hashtb and mark all unknown groups as killed."
1960 ;; First make sure active file has been read.
1961 (unless (gnus-read-active-file-p)
1962 (let ((gnus-read-active-file t))
1963 (gnus-read-active-file)))
1964 (unless gnus-killed-hashtb
1965 (gnus-make-hashtable-from-killed))
1966 ;; Go through all newsgroups that are known to Gnus - enlarge kill list.
1970 (group (symbol-name sym)))
1971 (if (or (null group)
1972 (gnus-gethash group gnus-killed-hashtb)
1973 (gnus-gethash group gnus-newsrc-hashtb))
1975 (let ((do-sub (gnus-matches-options-n group)))
1976 (if (or (eq do-sub 'subscribe) (eq do-sub 'ignore))
1978 (setq groups (1+ groups))
1979 (push group gnus-killed-list)
1980 (gnus-sethash group group gnus-killed-hashtb))))))
1982 (gnus-dribble-touch))
1984 ;; Get the active file(s) from the backend(s).
1985 (defun gnus-read-active-file (&optional force not-native)
1986 (gnus-group-set-mode-line)
1989 (lambda (m) (if (stringp m) (gnus-server-get-method nil m) m))
1991 (if (and (not not-native)
1992 (gnus-check-server gnus-select-method))
1993 ;; The native server is available.
1994 (cons gnus-select-method gnus-secondary-select-methods)
1995 ;; The native server is down, so we just do the
1997 gnus-secondary-select-methods)
1998 ;; Also read from the archive server.
1999 (when (gnus-archive-server-wanted-p)
2000 (list "archive")))))
2002 (setq gnus-have-read-active-file nil)
2004 (set-buffer nntp-server-buffer)
2005 (while (setq method (pop methods))
2006 ;; Only do each method once, in case the methods appear more
2007 ;; than once in this list.
2008 (unless (member method methods)
2009 (if (or debug-on-error debug-on-quit)
2010 (gnus-read-active-file-1 method force)
2012 (gnus-read-active-file-1 method force)
2013 ;; We catch C-g so that we can continue past servers
2014 ;; that do not respond.
2016 (message "Quit reading the active file")
2019 (defun gnus-read-active-file-1 (method force)
2021 (setq where (nth 1 method)
2022 mesg (format "Reading active file%s via %s..."
2023 (if (and where (not (zerop (length where))))
2024 (concat " from " where) "")
2026 (gnus-message 5 mesg)
2027 (when (gnus-check-server method)
2028 ;; Request that the backend scan its incoming messages.
2029 (when (gnus-check-backend-function 'request-scan (car method))
2030 (gnus-request-scan nil method))
2032 ((and (eq gnus-read-active-file 'some)
2033 (gnus-check-backend-function 'retrieve-groups (car method))
2035 (let ((newsrc (cdr gnus-newsrc-alist))
2036 (gmethod (gnus-server-get-method nil method))
2038 (while (setq info (pop newsrc))
2042 (gnus-find-method-for-group
2043 (gnus-info-group info) info))
2045 (push (gnus-group-real-name (gnus-info-group info))
2047 (gnus-read-active-file-2 groups method)))
2051 (if (not (gnus-request-list method))
2052 (unless (equal method gnus-message-archive-method)
2053 (gnus-error 1 "Cannot read active file from %s server"
2055 (gnus-message 5 mesg)
2056 (gnus-active-to-gnus-format method gnus-active-hashtb nil t)
2057 ;; We mark this active file as read.
2058 (push method gnus-have-read-active-file)
2059 (gnus-message 5 "%sdone" mesg)))))))
2061 (defun gnus-read-active-file-2 (groups method)
2062 "Read an active file for GROUPS in METHOD using `gnus-retrieve-groups'."
2065 (set-buffer nntp-server-buffer)
2066 (gnus-check-server method)
2067 (let ((list-type (gnus-retrieve-groups groups method)))
2068 (cond ((not list-type)
2070 1.2 "Cannot read partial active file from %s server."
2072 ((eq list-type 'active)
2073 (gnus-active-to-gnus-format method gnus-active-hashtb nil t))
2075 (gnus-groups-to-gnus-format method gnus-active-hashtb t)))))))
2077 ;; Read an active file and place the results in `gnus-active-hashtb'.
2078 (defun gnus-active-to-gnus-format (&optional method hashtb ignore-errors
2081 (setq method gnus-select-method))
2082 (let ((cur (current-buffer))
2084 (if (and gnus-active-hashtb
2085 (not (equal method gnus-select-method)))
2087 (setq gnus-active-hashtb
2088 (if (equal method gnus-select-method)
2089 (gnus-make-hashtable
2090 (count-lines (point-min) (point-max)))
2091 (gnus-make-hashtable 4096)))))))
2092 ;; Delete unnecessary lines.
2093 (goto-char (point-min))
2095 ((string= gnus-ignored-newsgroups "")
2096 (delete-matching-lines "^to\\."))
2098 (delete-matching-lines (concat "^to\\.\\|" gnus-ignored-newsgroups))))
2100 (goto-char (point-min))
2101 (unless (re-search-forward "[\\\"]" nil t)
2102 ;; Make the group names readable as a lisp expression even if they
2103 ;; contain special characters.
2104 (goto-char (point-max))
2105 (while (re-search-backward "[][';?()#]" nil t)
2108 ;; Let the Gnus agent save the active file.
2109 (when (and gnus-agent real-active (gnus-online method))
2110 (gnus-agent-save-active method))
2112 ;; If these are groups from a foreign select method, we insert the
2113 ;; group prefix in front of the group names.
2114 (when (not (gnus-server-equal
2115 (gnus-server-get-method nil method)
2116 (gnus-server-get-method nil gnus-select-method)))
2117 (let ((prefix (gnus-group-prefixed-name "" method)))
2118 (goto-char (point-min))
2119 (while (and (not (eobp))
2121 (when (= (following-char) ?\")
2124 (zerop (forward-line 1)))))))
2125 ;; Store the active file in a hash table.
2126 (goto-char (point-min))
2127 (let (group max min)
2131 (narrow-to-region (point) (point-at-eol))
2132 ;; group gets set to a symbol interned in the hash table
2133 ;; (what a hack!!) - jwz
2134 (setq group (let ((obarray hashtb)) (read cur)))
2135 ;; ### The extended group name scheme makes
2136 ;; the previous optimization strategy sort of pointless...
2137 (when (stringp group)
2138 (setq group (intern group hashtb)))
2139 (if (and (numberp (setq max (read cur)))
2140 (numberp (setq min (read cur)))
2142 (skip-chars-forward " \t")
2144 (or (eq (char-after) ?=)
2145 (eq (char-after) ?x)
2146 (eq (char-after) ?j)))))
2148 (set group (cons min max))
2149 ;; if group is moderated, stick in moderation table
2150 (when (eq (char-after) ?m)
2151 (unless gnus-moderated-hashtb
2152 (setq gnus-moderated-hashtb (gnus-make-hashtable)))
2153 (gnus-sethash (symbol-name group) t
2154 gnus-moderated-hashtb)))
2160 (unless ignore-errors
2161 (gnus-message 3 "Warning - invalid active: %s"
2163 (point-at-bol) (point-at-eol))))))
2165 (forward-line 1)))))
2167 (defun gnus-groups-to-gnus-format (method &optional hashtb real-active)
2168 ;; Parse a "groups" active file.
2169 (let ((cur (current-buffer))
2171 (if (and method gnus-active-hashtb)
2173 (setq gnus-active-hashtb
2174 (gnus-make-hashtable
2175 (count-lines (point-min) (point-max)))))))
2177 (not (gnus-server-equal
2178 (gnus-server-get-method nil method)
2179 (gnus-server-get-method nil gnus-select-method)))
2180 (gnus-group-prefixed-name "" method))))
2182 ;; Let the Gnus agent save the active file.
2185 (gnus-online method)
2186 (gnus-agent-method-p method))
2188 (gnus-agent-save-active method)
2189 (gnus-active-to-gnus-format method hashtb nil real-active))
2191 (goto-char (point-min))
2192 ;; We split this into to separate loops, one with the prefix
2193 ;; and one without to speed the reading up somewhat.
2195 (let (min max opoint group)
2199 (read cur) (read cur)
2200 (setq min (read cur)
2203 (skip-chars-forward " \t")
2206 (set (let ((obarray hashtb)) (read cur))
2208 (error (and group (symbolp group) (set group nil))))
2210 (let (min max group)
2213 (when (eq (char-after) ?2)
2214 (read cur) (read cur)
2215 (setq min (read cur)
2217 (set (setq group (let ((obarray hashtb)) (read cur)))
2219 (error (and group (symbolp group) (set group nil))))
2220 (forward-line 1)))))))
2222 (defun gnus-read-newsrc-file (&optional force)
2224 If FORCE is non-nil, the .newsrc file is read."
2225 ;; Reset variables that might be defined in the .newsrc.eld file.
2226 (gnus-clear-quick-file-variables)
2227 (let* ((newsrc-file gnus-current-startup-file)
2228 (quick-file (concat newsrc-file ".el")))
2230 ;; We always load the .newsrc.eld file. If always contains
2231 ;; much information that can not be gotten from the .newsrc
2232 ;; file (ticked articles, killed groups, foreign methods, etc.)
2233 (gnus-read-newsrc-el-file quick-file)
2235 (when (and gnus-read-newsrc-file
2236 (file-exists-p gnus-current-startup-file)
2238 (and (file-newer-than-file-p newsrc-file quick-file)
2239 (file-newer-than-file-p newsrc-file
2240 (concat quick-file "d")))
2241 (not gnus-newsrc-alist)))
2242 ;; We read the .newsrc file. Note that if there if a
2243 ;; .newsrc.eld file exists, it has already been read, and
2244 ;; the `gnus-newsrc-hashtb' has been created. While reading
2245 ;; the .newsrc file, Gnus will only use the information it
2246 ;; can find there for changing the data already read -
2247 ;; i. e., reading the .newsrc file will not trash the data
2248 ;; already read (except for read articles).
2250 (gnus-message 5 "Reading %s..." newsrc-file)
2251 (set-buffer (nnheader-find-file-noselect newsrc-file))
2252 (buffer-disable-undo)
2253 (gnus-newsrc-to-gnus-format)
2254 (kill-buffer (current-buffer))
2255 (gnus-message 5 "Reading %s...done" newsrc-file))))))
2257 (quote (;; T-gnus doesn't provide those functions.
2258 (defun gnus-convert-old-newsrc ()
2259 "Convert old newsrc formats into the current format, if needed."
2260 (let ((fcv (and gnus-newsrc-file-version
2261 (gnus-continuum-version gnus-newsrc-file-version))))
2263 ;; A newsrc file was loaded.
2264 (let (prompt-displayed
2267 (mapcar (lambda (date-func)
2268 (cons (gnus-continuum-version (car date-func))
2270 ;; This is a list of converters that must be run
2271 ;; to bring the newsrc file up to the current
2272 ;; version. If you create an incompatibility
2273 ;; with older versions, you should create an
2274 ;; entry here. The entry should consist of the
2275 ;; current gnus version (hardcoded so that it
2276 ;; doesn't change with each release) and the
2277 ;; function that must be applied to convert the
2278 ;; previous version into the current version.
2279 '(("September Gnus v0.1" nil
2280 gnus-convert-old-ticks)
2281 ("Oort Gnus v0.08" "legacy-gnus-agent"
2282 gnus-agent-convert-to-compressed-agentview)
2283 ("No Gnus v0.2" "legacy-gnus-agent"
2284 gnus-agent-unlist-expire-days)
2285 ("No Gnus v0.2" "legacy-gnus-agent"
2286 gnus-agent-unhook-expire-days)))
2287 #'car-less-than-car)))
2288 ;; Skip converters older than the file version
2289 (while (and converters (>= fcv (caar converters)))
2292 ;; Perform converters to bring older version up to date.
2293 (when (and converters (< fcv (caar converters)))
2294 (while (and converters (< fcv (caar converters)))
2295 (let* ((converter-spec (pop converters))
2296 (convert-to (nth 1 converter-spec))
2297 (load-from (nth 2 converter-spec))
2298 (func (nth 3 converter-spec)))
2299 (when (and load-from
2300 (not (fboundp func)))
2303 (or prompt-displayed
2304 (not (gnus-convert-converter-needs-prompt func))
2306 (cursor-in-echo-area t)
2307 (echo-keystrokes 0))
2308 (message "Convert gnus from version '%s' to '%s'? (n/y/?)"
2309 gnus-newsrc-file-version gnus-version)
2310 (setq c (read-char-exclusive))
2312 (cond ((or (eq c ?n) (eq c ?N))
2313 (error "Can not start gnus without converting"))
2314 ((or (eq c ?y) (eq c ?Y))
2315 (setq prompt-displayed t)
2318 (message "This conversion is irreversible. \
2319 To be safe, you should backup your files before proceeding.")
2323 (gnus-message 3 "Ignoring unexpected input")
2327 (funcall func convert-to)))
2329 (format ";Converted gnus from version '%s' to '%s'."
2330 gnus-newsrc-file-version gnus-version)))))))
2332 (defun gnus-convert-mark-converter-prompt (converter no-prompt)
2333 "Indicate whether CONVERTER requires gnus-convert-old-newsrc to
2334 display the conversion prompt. NO-PROMPT may be nil (prompt),
2335 t (no prompt), or any form that can be called as a function.
2336 The form should return either t or nil."
2337 (put converter 'gnus-convert-no-prompt no-prompt))
2339 (defun gnus-convert-converter-needs-prompt (converter)
2340 (let ((no-prompt (get converter 'gnus-convert-no-prompt)))
2341 (not (if (memq no-prompt '(t nil))
2343 (funcall no-prompt)))))
2345 (defun gnus-convert-old-ticks (converting-to)
2346 (let ((newsrc (cdr gnus-newsrc-alist))
2347 marks info dormant ticked)
2348 (while (setq info (pop newsrc))
2349 (when (setq marks (gnus-info-marks info))
2350 (setq dormant (cdr (assq 'dormant marks))
2351 ticked (cdr (assq 'tick marks)))
2352 (when (or dormant ticked)
2356 (gnus-info-read info)
2357 (nconc (gnus-uncompress-range dormant)
2358 (gnus-uncompress-range ticked)))))))))
2361 (defun gnus-load (file &optional coding-system)
2362 "Load FILE, but in such a way that read errors can be reported."
2365 (insert-file-contents-as-coding-system coding-system file)
2366 (insert-file-contents file))
2368 (condition-case type
2369 (let ((form (read (current-buffer))))
2372 (unless (eq (car type) 'end-of-file)
2373 (let ((error (format "Error in %s line %d" file
2374 (count-lines (point-min) (point)))))
2376 (unless (gnus-yes-or-no-p (concat error "; continue? "))
2377 (error "%s" error)))))))))
2379 (defun gnus-read-newsrc-el-file (file)
2380 (let ((ding-file (concat file "d")))
2381 (when (file-exists-p ding-file)
2382 ;; We always, always read the .eld file.
2383 (gnus-message 5 "Reading %s..." ding-file)
2384 (let (gnus-newsrc-assoc)
2385 (gnus-load ding-file gnus-ding-file-coding-system)
2386 ;; ;; Older versions of `gnus-format-specs' are no longer valid
2387 ;; ;; in Oort Gnus 0.01.
2389 ;; (and gnus-newsrc-file-version
2390 ;; (gnus-continuum-version gnus-newsrc-file-version))))
2391 ;; (when (or (not version)
2392 ;; (< version 5.090009))
2393 ;; (setq gnus-format-specs gnus-default-format-specs)))
2394 (when gnus-newsrc-assoc
2395 (setq gnus-newsrc-alist gnus-newsrc-assoc))))
2396 (gnus-make-hashtable-from-newsrc-alist)
2397 (when (file-newer-than-file-p file ding-file)
2398 ;; Old format quick file
2399 (gnus-message 5 "Reading %s..." file)
2400 ;; The .el file is newer than the .eld file, so we read that one
2402 (gnus-read-old-newsrc-el-file file)))
2403 (when (and gnus-product-directory
2404 (file-directory-p gnus-product-directory))
2405 (let ((list gnus-product-variable-file-list))
2407 (apply 'gnus-product-read-variable-file-1 (car list))
2408 (setq list (cdr list)))))
2409 (gnus-run-hooks 'gnus-read-newsrc-el-hook))
2411 ;;(defun gnus-re-read-newsrc-el-file (file)
2412 ;; "Attempt to re-read .newsrc.eld file. Returns nil if successful.
2413 ;;The backup file \".newsrc.eld_\" will be created before re-reading."
2414 ;; (message "Error in %s; retrying..." file)
2416 ;; (condition-case nil
2417 ;; (let ((backup (concat file "_")))
2418 ;; (copy-file file backup 'ok-if-already-exists 'keep-time)
2419 ;; (message " (The backup file %s has been created)" backup)
2423 ;; (insert-file-contents-as-binary file nil nil nil 'replace)
2424 ;; (goto-char (point-min))
2425 ;; (when (re-search-forward
2426 ;; "^[\t ]*([\t\n\r ]*setq[\t\n\r ]+gnus-format-specs" nil t)
2427 ;; (delete-region (goto-char (match-beginning 0)) (forward-list 1))
2428 ;; (decode-coding-region (point-min) (point-max)
2429 ;; gnus-ding-file-coding-system)
2430 ;; (condition-case nil
2432 ;; (eval-region (point-min) (point-max))
2437 ;; (message "Error in %s; retrying...done" file))
2438 ;; (message "Error in %s; retrying...failed" file)
2441 (defun gnus-product-read-variable-file-1 (file checking-methods coding
2443 (let (error gnus-product-file-version method file-ver)
2444 (when (or (condition-case err
2445 (let ((coding-system-for-read coding))
2446 (load (expand-file-name file gnus-product-directory)
2450 (message "Error while reading %s: %s"
2451 (expand-file-name file gnus-product-directory)
2452 (error-message-string err))
2454 (and (setq method (assq 'product-version checking-methods))
2455 (not (and (setq file-ver
2456 (cdr (assq 'product-version
2457 gnus-product-file-version)))
2458 (zerop (product-version-compare file-ver
2460 (and (assq 'emacs-version checking-methods)
2461 (not (and (assq 'emacs-version gnus-product-file-version)
2464 (cdr (assq 'emacs-version
2465 gnus-product-file-version))))))
2466 (and (assq 'correct-string-widths checking-methods)
2467 (not (and (assq 'correct-string-widths
2468 gnus-product-file-version)
2469 (eq (and gnus-use-correct-string-widths t)
2470 (and (cdr (assq 'correct-string-widths
2471 gnus-product-file-version))
2474 (message "\"%s\" seems to have mismatched contents, updating..."
2477 (set (car variables) nil)
2478 (gnus-product-variable-touch (car variables))
2479 (setq variables (cdr variables))))))
2481 ;; Parse the old-style quick startup file
2482 (defun gnus-read-old-newsrc-el-file (file)
2483 (let (newsrc killed marked group m info)
2485 (let ((gnus-killed-assoc nil)
2486 gnus-marked-assoc gnus-newsrc-alist gnus-newsrc-assoc)
2490 (setq newsrc gnus-newsrc-assoc
2491 killed gnus-killed-assoc
2492 marked gnus-marked-assoc)))
2493 (setq gnus-newsrc-alist nil)
2494 (while (setq group (pop newsrc))
2495 (if (setq info (gnus-get-info (car group)))
2497 (gnus-info-set-read info (cddr group))
2498 (gnus-info-set-level
2499 info (if (nth 1 group) gnus-level-default-subscribed
2500 gnus-level-default-unsubscribed))
2501 (push info gnus-newsrc-alist))
2504 (if (nth 1 group) gnus-level-default-subscribed
2505 gnus-level-default-unsubscribed)
2508 ;; Copy marks into info.
2509 (when (setq m (assoc (car group) marked))
2510 (unless (nthcdr 3 info)
2511 (nconc info (list nil)))
2512 (gnus-info-set-marks
2513 info (list (cons 'tick (gnus-compress-sequence
2514 (sort (cdr m) '<) t))))))
2515 (setq newsrc killed)
2517 (setcar newsrc (caar newsrc))
2518 (setq newsrc (cdr newsrc)))
2519 (setq gnus-killed-list killed))
2520 ;; The .el file version of this variable does not begin with
2521 ;; "options", while the .eld version does, so we just add it if it
2525 (when (not (string-match "^ *options" gnus-newsrc-options))
2526 (setq gnus-newsrc-options (concat "options " gnus-newsrc-options)))
2527 (when (not (string-match "\n$" gnus-newsrc-options))
2528 (setq gnus-newsrc-options (concat gnus-newsrc-options "\n")))
2529 ;; Finally, if we read some options lines, we parse them.
2530 (unless (string= gnus-newsrc-options "")
2531 (gnus-newsrc-parse-options gnus-newsrc-options)))
2533 (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist))
2534 (gnus-make-hashtable-from-newsrc-alist)))
2536 (defun gnus-make-newsrc-file (file)
2537 "Make server dependent file name by catenating FILE and server host name."
2538 (let* ((file (expand-file-name file nil))
2539 (real-file (concat file "-" (nth 1 gnus-select-method))))
2540 (if (or (file-exists-p real-file)
2541 (file-exists-p (concat real-file ".el"))
2542 (file-exists-p (concat real-file ".eld")))
2546 (defun gnus-newsrc-to-gnus-format ()
2547 (setq gnus-newsrc-options "")
2548 (setq gnus-newsrc-options-n nil)
2550 (unless gnus-active-hashtb
2551 (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
2552 (let ((buf (current-buffer))
2553 (already-read (> (length gnus-newsrc-alist) 1))
2554 group subscribed options-symbol newsrc Options-symbol
2556 (goto-char (point-min))
2557 ;; We intern the symbol `options' in the active hashtb so that we
2558 ;; can `eq' against it later.
2559 (set (setq options-symbol (intern "options" gnus-active-hashtb)) nil)
2560 (set (setq Options-symbol (intern "Options" gnus-active-hashtb)) nil)
2563 ;; We first read the first word on the line by narrowing and
2564 ;; then reading into `gnus-active-hashtb'. Most groups will
2565 ;; already exist in that hashtb, so this will save some string
2569 (progn (skip-chars-forward "^ \t!:\n") (point)))
2570 (goto-char (point-min))
2572 (and (/= (point-min) (point-max))
2573 (let ((obarray gnus-active-hashtb)) (read buf))))
2575 ;; Now, the symbol we have read is either `options' or a group
2576 ;; name. If it is an options line, we just add it to a string.
2578 ((or (eq symbol options-symbol)
2579 (eq symbol Options-symbol))
2580 (setq gnus-newsrc-options
2581 ;; This concating is quite inefficient, but since our
2582 ;; thorough studies show that approx 99.37% of all
2583 ;; .newsrc files only contain a single options line, we
2584 ;; don't give a damn, frankly, my dear.
2585 (concat gnus-newsrc-options
2588 ;; Options may continue on the next line.
2589 (or (and (re-search-forward "^[^ \t]" nil 'move)
2594 ;; Group names can be just numbers.
2595 (when (numberp symbol)
2596 (setq symbol (intern (int-to-string symbol) gnus-active-hashtb)))
2597 (unless (boundp symbol)
2599 ;; It was a group name.
2600 (setq subscribed (eq (char-after) ?:)
2601 group (symbol-name symbol)
2604 ;; If the line ends here, this is clearly a buggy line, so
2605 ;; we put point a the beginning of line and let the cond
2606 ;; below do the error handling.
2608 ;; We skip to the beginning of the ranges.
2609 (skip-chars-forward "!: \t"))
2610 ;; We are now at the beginning of the list of read articles.
2611 ;; We read them range by range.
2614 ((looking-at "[0-9]+")
2615 ;; We narrow and read a number instead of buffer-substring/
2616 ;; string-to-int because it's faster. narrow/widen is
2617 ;; faster than save-restriction/narrow, and save-restriction
2618 ;; produces a garbage object.
2620 (narrow-to-region (match-beginning 0) (match-end 0))
2623 ;; If the next character is a dash, then this is a range.
2624 (if (eq (char-after) ?-)
2626 ;; We read the upper bound of the range.
2628 (if (not (looking-at "[0-9]+"))
2629 ;; This is a buggy line, by we pretend that
2630 ;; it's kinda OK. Perhaps the user should be
2636 (narrow-to-region (match-beginning 0)
2641 ;; It was just a simple number, so we add it to the
2644 ;; If the next char in ?\n, then we have reached the end
2645 ;; of the line and return nil.
2646 (not (eq (char-after) ?\n)))
2647 ((eq (char-after) ?\n)
2648 ;; End of line, so we end.
2651 ;; Not numbers and not eol, so this might be a buggy
2654 ;; If it was eob instead of ?\n, we allow it.
2655 ;; The line was buggy.
2657 (gnus-error 3.1 "Mangled line: %s"
2658 (buffer-substring (point-at-bol)
2661 ;; Skip past ", ". Spaces are invalid in these ranges, but
2662 ;; we allow them, because it's a common mistake to put a
2663 ;; space after the comma.
2664 (skip-chars-forward ", "))
2666 ;; We have already read .newsrc.eld, so we gently update the
2667 ;; data in the hash table with the information we have just
2670 (let ((info (gnus-get-info group))
2673 ;; There is an entry for this file in the alist.
2675 (gnus-info-set-read info (nreverse reads))
2676 ;; We update the level very gently. In fact, we
2677 ;; only change it if there's been a status change
2678 ;; from subscribed to unsubscribed, or vice versa.
2679 (setq level (gnus-info-level info))
2680 (cond ((and (<= level gnus-level-subscribed)
2682 (setq level (if reads
2683 gnus-level-default-unsubscribed
2684 (1+ gnus-level-default-unsubscribed))))
2685 ((and (> level gnus-level-subscribed) subscribed)
2686 (setq level gnus-level-default-subscribed)))
2687 (gnus-info-set-level info level))
2688 ;; This is a new group.
2689 (setq info (list group
2691 gnus-level-default-subscribed
2693 (1+ gnus-level-subscribed)
2694 gnus-level-default-unsubscribed))
2696 (push info newsrc)))))
2699 (setq newsrc (nreverse newsrc))
2701 (if (not already-read)
2703 ;; We now have two newsrc lists - `newsrc', which is what we
2704 ;; have read from .newsrc, and `gnus-newsrc-alist', which is
2705 ;; what we've read from .newsrc.eld. We have to merge these
2706 ;; lists. We do this by "attaching" any (foreign) groups in the
2707 ;; gnus-newsrc-alist to the (native) group that precedes them.
2708 (let ((rc (cdr gnus-newsrc-alist))
2709 (prev gnus-newsrc-alist)
2712 (or (null (nth 4 (car rc))) ; It's a native group.
2713 (assoc (caar rc) newsrc) ; It's already in the alist.
2714 (if (setq entry (assoc (caar prev) newsrc))
2715 (setcdr (setq mentry (memq entry newsrc))
2716 (cons (car rc) (cdr mentry)))
2717 (push (car rc) newsrc)))
2721 (setq gnus-newsrc-alist newsrc)
2722 ;; We make the newsrc hashtb.
2723 (gnus-make-hashtable-from-newsrc-alist)
2725 ;; Finally, if we read some options lines, we parse them.
2726 (unless (string= gnus-newsrc-options "")
2727 (gnus-newsrc-parse-options gnus-newsrc-options))))
2729 ;; Parse options lines to find "options -n !all rec.all" and stuff.
2730 ;; The return value will be a list on the form
2731 ;; ((regexp1 . ignore)
2732 ;; (regexp2 . subscribe)...)
2733 ;; When handling new newsgroups, groups that match a `ignore' regexp
2734 ;; will be ignored, and groups that match a `subscribe' regexp will be
2735 ;; subscribed. A line like
2736 ;; options -n !all rec.all
2737 ;; will lead to a list that looks like
2738 ;; (("^rec\\..+" . subscribe)
2739 ;; ("^.+" . ignore))
2740 ;; So all "rec.*" groups will be subscribed, while all the other
2741 ;; groups will be ignored. Note that "options -n !all rec.all" is very
2742 ;; different from "options -n rec.all !all".
2743 (defun gnus-newsrc-parse-options (options)
2746 (gnus-set-work-buffer)
2747 (insert (regexp-quote options))
2748 ;; First we treat all continuation lines.
2749 (goto-char (point-min))
2750 (while (re-search-forward "\n[ \t]+" nil t)
2751 (replace-match " " t t))
2752 ;; Then we transform all "all"s into ".+"s.
2753 (goto-char (point-min))
2754 (while (re-search-forward "\\ball\\b" nil t)
2755 (replace-match ".+" t t))
2756 (goto-char (point-min))
2757 ;; We remove all other options than the "-n" ones.
2758 (while (re-search-forward "[ \t]-[^n][^-]*" nil t)
2761 (goto-char (point-min))
2763 ;; We are only interested in "options -n" lines - we
2764 ;; ignore the other option lines.
2765 (while (re-search-forward "[ \t]-n" nil t)
2768 (and (re-search-forward "[ \t]-n" (point-at-eol) t)
2771 ;; Search for all "words"...
2772 (while (re-search-forward "[^ \t,\n]+" eol t)
2773 (if (eq (char-after (match-beginning 0)) ?!)
2774 ;; If the word begins with a bang (!), this is a "not"
2775 ;; spec. We put this spec (minus the bang) and the
2776 ;; symbol `ignore' into the list.
2778 "^" (buffer-substring
2779 (1+ (match-beginning 0))
2784 ;; There was no bang, so this is a "yes" spec.
2785 (push (cons (concat "^" (match-string 0) "\\($\\|\\.\\)")
2789 (setq gnus-newsrc-options-n out))))
2792 (defalias 'gnus-long-file-names
2793 (if (fboundp 'msdos-long-file-names)
2794 'msdos-long-file-names
2797 (defun gnus-save-newsrc-file (&optional force)
2798 "Save .newsrc file."
2799 ;; Note: We cannot save .newsrc file if all newsgroups are removed
2800 ;; from the variable gnus-newsrc-alist.
2801 (when (and (or gnus-newsrc-alist gnus-killed-list)
2802 gnus-current-startup-file)
2803 ;; Save agent range limits for the currently active method.
2805 (gnus-agent-save-local force))
2808 (if (and (or gnus-use-dribble-file gnus-slave)
2810 (or (not gnus-dribble-buffer)
2811 (not (buffer-name gnus-dribble-buffer))
2812 (zerop (save-excursion
2813 (set-buffer gnus-dribble-buffer)
2815 (gnus-message 4 "(No changes need to be saved)")
2816 (gnus-run-hooks 'gnus-save-newsrc-hook)
2818 (gnus-slave-save-newsrc)
2820 (when gnus-save-newsrc-file
2821 (gnus-message 8 "Saving %s..." gnus-current-startup-file)
2822 (gnus-gnus-to-newsrc-format)
2823 (gnus-message 8 "Saving %s...done" gnus-current-startup-file))
2825 ;; Save .newsrc.eld.
2826 (set-buffer (gnus-get-buffer-create " *Gnus-newsrc*"))
2827 (make-local-variable 'version-control)
2828 (setq version-control gnus-backup-startup-file)
2829 (setq buffer-file-name
2830 (concat gnus-current-startup-file ".eld"))
2831 (setq default-directory (file-name-directory buffer-file-name))
2832 (buffer-disable-undo)
2834 (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file)
2836 (if gnus-save-startup-file-via-temp-buffer
2837 (let ((coding-system-for-write gnus-ding-file-coding-system)
2838 (standard-output (current-buffer)))
2839 (gnus-gnus-to-quick-newsrc-format)
2840 (gnus-run-hooks 'gnus-save-quick-newsrc-hook)
2842 (let ((coding-system-for-write gnus-ding-file-coding-system)
2843 (version-control gnus-backup-startup-file)
2844 (startup-file (concat gnus-current-startup-file ".eld"))
2845 (working-dir (file-name-directory gnus-current-startup-file))
2848 ;; Generate the name of a non-existent file.
2849 (while (progn (setq working-file
2851 (if (and (eq system-type 'ms-dos)
2852 (not (gnus-long-file-names)))
2853 "%s#%d.tm#" ; MSDOS limits files to 8+3
2854 (if (memq system-type '(vax-vms axp-vms))
2857 working-dir (setq i (1+ i))))
2858 (file-exists-p working-file)))
2862 (gnus-with-output-to-file working-file
2863 (gnus-gnus-to-quick-newsrc-format)
2864 (gnus-run-hooks 'gnus-save-quick-newsrc-hook))
2866 ;; These bindings will mislead the current buffer
2867 ;; into thinking that it is visiting the startup
2869 (let ((buffer-backed-up nil)
2870 (buffer-file-name startup-file)
2871 (file-precious-flag t)
2872 (setmodes (file-modes startup-file)))
2873 ;; Backup the current version of the startup file.
2876 ;; Replace the existing startup file with the temp file.
2877 (rename-file working-file startup-file t)
2878 (gnus-set-file-modes startup-file setmodes)))
2880 (delete-file working-file)
2881 (file-error nil)))))
2883 (gnus-kill-buffer (current-buffer))
2885 5 "Saving %s.eld...done" gnus-current-startup-file))
2886 (gnus-dribble-delete-file)
2887 (gnus-group-set-mode-line))))
2888 (when gnus-product-directory
2889 (gnus-product-save-variable-file)))
2891 ;; Call the function above at C-x C-c.
2892 (defadvice save-buffers-kill-emacs (before save-gnus-newsrc-file-maybe
2893 activate preactivate)
2894 "Save .newsrc and .newsrc.eld when Emacs is killed."
2895 (when (gnus-alive-p)
2896 (gnus-run-hooks 'gnus-exit-gnus-hook)
2897 (gnus-offer-save-summaries)
2898 (gnus-save-newsrc-file)))
2900 (defun gnus-gnus-to-quick-newsrc-format (&optional minimal name &rest specific-variables)
2901 "Print Gnus variables such as `gnus-newsrc-alist' in Lisp format."
2902 (princ ";; -*- emacs-lisp -*-\n")
2904 (princ (format ";; %s\n" name))
2905 (princ ";; Gnus startup file.\n"))
2909 ;; Never delete this file -- if you want to force Gnus to read the
2910 ;; .newsrc file (if you have one), touch .newsrc instead.\n")
2911 (princ "(setq gnus-newsrc-file-version ")
2912 (princ (gnus-prin1-to-string gnus-version))
2915 (let* ((print-quoted t)
2917 (print-escape-multibyte nil)
2918 (print-escape-nonascii t)
2921 (print-escape-newlines t)
2923 (if (and gnus-save-killed-list
2924 (stringp gnus-save-killed-list))
2925 (gnus-strip-killed-list)
2928 (or specific-variables
2929 (if gnus-save-killed-list gnus-variable-list
2930 ;; Remove the `gnus-killed-list' from the list of variables
2931 ;; to be saved, if required.
2932 (delq 'gnus-killed-list (copy-sequence gnus-variable-list)))))
2933 ;; Peel off the "dummy" group.
2934 (gnus-newsrc-alist (cdr gnus-newsrc-alist))
2936 ;; Insert the variables into the file.
2938 (when (and (boundp (setq variable (pop variables)))
2939 (symbol-value variable))
2941 (princ (symbol-name variable))
2943 (prin1 (symbol-value variable))
2946 (defun gnus-product-variable-touch (&rest variables)
2948 (put (pop variables) 'gnus-product-variable 'dirty)))
2950 (defun gnus-product-variables-dirty-p (variables)
2953 (when (eq (get (car variables) 'gnus-product-variable) 'dirty)
2955 (setq variables (cdr variables)))))
2957 (defun gnus-product-save-variable-file (&optional force)
2958 "Save all product variables to files, when need to be saved."
2959 (let ((list gnus-product-variable-file-list))
2960 (gnus-make-directory gnus-product-directory)
2962 (apply 'gnus-product-save-variable-file-1 force (car list))
2963 (setq list (cdr list)))))
2965 (defun gnus-product-save-variable-file-1 (force file checking-methods coding
2967 "Save a product variable file, when need to be saved."
2969 (gnus-product-variables-dirty-p variables))
2970 (let ((product (product-find 'gnus-vers)))
2971 (set-buffer (gnus-get-buffer-create " *gnus-product*"))
2972 (make-local-variable 'version-control)
2973 (setq version-control 'never)
2974 (setq file (expand-file-name file gnus-product-directory)
2975 buffer-file-name file
2976 default-directory (file-name-directory file))
2977 (buffer-disable-undo)
2979 (gnus-message 5 "Saving %s..." file)
2980 (apply 'gnus-product-quick-file-format product checking-methods coding
2982 (save-buffer-as-coding-system coding)
2983 (kill-buffer (current-buffer))
2985 (put (car variables) 'gnus-product-variable nil)
2986 (setq variables (cdr variables)))
2988 5 "Saving %s...done" file))))
2990 (defun gnus-product-quick-file-format (product checking-methods
2991 coding &rest variables)
2992 "Insert gnus product depend variables in lisp format."
2993 (let ((print-quoted t)
2994 (print-escape-newlines t)
2995 print-length print-level variable param)
2996 (insert (format ";; -*- Mode: emacs-lisp; coding: %s -*-\n" coding))
2997 (insert (format ";; %s startup file.\n" (product-name product)))
2998 (when (setq param (cdr (assq 'product-version checking-methods)))
2999 (insert "(or (>= (product-version-compare "
3000 "(product-version (product-find 'gnus-vers))\n"
3001 "\t\t\t\t '" (apply 'prin1-to-string param) ")\n"
3003 " (error \"This file was created by later version of "
3005 (insert "(setq gnus-product-file-version\n"
3006 " '((product-version . "
3007 (prin1-to-string (product-version product)) ")\n"
3008 "\t(emacs-version . "
3009 (prin1-to-string emacs-version) ")\n"
3010 "\t(correct-string-widths . "
3011 (if gnus-use-correct-string-widths "t" "nil")
3014 (when (and (boundp (setq variable (pop variables)))
3015 (symbol-value variable))
3016 (insert "(setq " (symbol-name variable) " '")
3017 (gnus-prin1 (symbol-value variable))
3020 (defun gnus-strip-killed-list ()
3021 "Return the killed list minus the groups that match `gnus-save-killed-list'."
3022 (let ((list gnus-killed-list)
3025 (when (string-match gnus-save-killed-list (car list))
3026 (push (car list) olist))
3030 (defun gnus-gnus-to-newsrc-format ()
3031 ;; Generate and save the .newsrc file.
3033 (set-buffer (create-file-buffer gnus-current-startup-file))
3034 (let ((newsrc (cdr gnus-newsrc-alist))
3035 (standard-output (current-buffer))
3036 info ranges range method)
3037 (setq buffer-file-name gnus-current-startup-file)
3038 (setq default-directory (file-name-directory buffer-file-name))
3039 (buffer-disable-undo)
3042 (when gnus-newsrc-options
3043 (insert gnus-newsrc-options))
3044 ;; Write subscribed and unsubscribed.
3045 (while (setq info (pop newsrc))
3046 ;; Don't write foreign groups to .newsrc.
3047 (when (or (null (setq method (gnus-info-method info)))
3048 (equal method "native")
3049 (inline (gnus-server-equal method gnus-select-method)))
3050 (insert (gnus-info-group info)
3051 (if (> (gnus-info-level info) gnus-level-subscribed)
3053 (when (setq ranges (gnus-info-read info))
3055 (if (not (listp (cdr ranges)))
3056 (if (= (car ranges) (cdr ranges))
3057 (princ (car ranges))
3058 (princ (car ranges))
3060 (princ (cdr ranges)))
3061 (while (setq range (pop ranges))
3062 (if (or (atom range) (= (car range) (cdr range)))
3063 (princ (or (and (atom range) range) (car range)))
3066 (princ (cdr range)))
3070 (make-local-variable 'version-control)
3071 (setq version-control 'never)
3072 ;; It has been reported that sometime the modtime on the .newsrc
3073 ;; file seems to be off. We really do want to overwrite it, so
3074 ;; we clear the modtime here before saving. It's a bit odd,
3076 ;; sometimes the modtime clear isn't sufficient. most brute force:
3077 ;; delete the silly thing entirely first. but this fails to provide
3078 ;; such niceties as .newsrc~ creation.
3079 (if gnus-modtime-botch
3080 (delete-file gnus-startup-file)
3081 (clear-visited-file-modtime))
3082 (gnus-run-hooks 'gnus-save-standard-newsrc-hook)
3084 (kill-buffer (current-buffer)))))
3088 ;;; Slave functions.
3091 (defvar gnus-slave-mode nil)
3093 (defun gnus-slave-mode ()
3094 "Minor mode for slave Gnusae."
3095 (add-minor-mode 'gnus-slave-mode " Slave" (make-sparse-keymap))
3096 (gnus-run-hooks 'gnus-slave-mode-hook))
3098 (defun gnus-slave-save-newsrc ()
3100 (set-buffer gnus-dribble-buffer)
3102 (mm-make-temp-file (concat gnus-current-startup-file "-slave-")))
3103 (modes (ignore-errors
3104 (file-modes (concat gnus-current-startup-file ".eld")))))
3105 (gnus-write-buffer-as-coding-system gnus-ding-file-coding-system
3108 (gnus-set-file-modes slave-name modes)))))
3110 (defun gnus-master-read-slave-newsrc ()
3113 (file-name-directory gnus-current-startup-file)
3117 (file-name-nondirectory gnus-current-startup-file)
3121 (if (not slave-files)
3122 () ; There are no slave files to read.
3123 (gnus-message 7 "Reading slave newsrcs...")
3125 (set-buffer (gnus-get-buffer-create " *gnus slave*"))
3127 (sort (mapcar (lambda (file)
3128 (list (nth 5 (file-attributes file)) file))
3131 (or (< (caar f1) (caar f2))
3132 (< (nth 1 (car f1)) (nth 1 (car f2)))))))
3135 (setq file (nth 1 (car slave-files)))
3136 (nnheader-insert-file-contents file)
3137 (when (condition-case ()
3139 (eval-buffer (current-buffer))
3142 (gnus-error 3.2 "Possible error in %s" file)
3144 (unless gnus-slave ; Slaves shouldn't delete these files.
3146 (delete-file file))))
3147 (setq slave-files (cdr slave-files))))
3148 (gnus-dribble-touch)
3149 (gnus-message 7 "Reading slave newsrcs...done"))))
3153 ;;; Group description.
3156 (defun gnus-read-all-descriptions-files ()
3157 (let ((methods (cons gnus-select-method
3159 (when (gnus-archive-server-wanted-p)
3161 gnus-secondary-select-methods))))
3163 (gnus-read-descriptions-file (car methods))
3164 (setq methods (cdr methods)))
3167 (defun gnus-read-descriptions-file (&optional method)
3168 (let ((method (or method gnus-select-method))
3170 (when (stringp method)
3171 (setq method (gnus-server-to-method method)))
3172 ;; We create the hashtable whether we manage to read the desc file
3173 ;; to avoid trying to re-read after a failed read.
3174 (unless gnus-description-hashtb
3175 (setq gnus-description-hashtb
3176 (gnus-make-hashtable (length gnus-active-hashtb))))
3177 ;; Mark this method's desc file as read.
3178 (gnus-sethash (gnus-group-prefixed-name "" method) "Has read"
3179 gnus-description-hashtb)
3181 (gnus-message 5 "Reading descriptions file via %s..." (car method))
3183 ((null (gnus-get-function method 'request-list-newsgroups t))
3185 ((not (gnus-check-server method))
3186 (gnus-message 1 "Couldn't open server")
3188 ((not (gnus-request-list-newsgroups method))
3189 (gnus-message 1 "Couldn't read newsgroups descriptions")
3194 (set-buffer nntp-server-buffer)
3195 (goto-char (point-min))
3196 (when (or (search-forward "\n.\n" nil t)
3197 (goto-char (point-max)))
3199 (narrow-to-region (point-min) (point)))
3200 ;; If these are groups from a foreign select method, we insert the
3201 ;; group prefix in front of the group names.
3202 (and method (not (inline
3204 (gnus-server-get-method nil method)
3205 (gnus-server-get-method
3206 nil gnus-select-method))))
3207 (let ((prefix (gnus-group-prefixed-name "" method)))
3208 (goto-char (point-min))
3209 (while (and (not (eobp))
3210 (progn (insert prefix)
3211 (zerop (forward-line 1)))))))
3212 (goto-char (point-min))
3214 ;; If we get an error, we set group to 0, which is not a
3218 (let ((obarray gnus-description-hashtb))
3219 ;; Group is set to a symbol interned in this
3221 (read nntp-server-buffer))
3223 (skip-chars-forward " \t")
3224 ;; ... which leads to this line being effectively ignored.
3225 (when (symbolp group)
3226 (let* ((str (buffer-substring
3227 (point) (progn (end-of-line) (point))))
3228 (name (symbol-name group))
3230 (or (gnus-group-name-charset method name)
3231 (gnus-parameter-charset name)
3232 gnus-default-charset)))
3233 ;; Fixme: Don't decode in unibyte mode.
3234 (when (and str charset (featurep 'mule))
3235 (setq str (decode-coding-string str charset)))
3238 (gnus-message 5 "Reading descriptions file...done")
3241 (defun gnus-group-get-description (group)
3242 "Get the description of a group by sending XGTITLE to the server."
3243 (when (gnus-request-group-description group)
3245 (set-buffer nntp-server-buffer)
3246 (goto-char (point-min))
3247 (when (looking-at "[^ \t]+[ \t]+\\(.*\\)")
3248 (match-string 1)))))
3251 (defun gnus-declare-backend (name &rest abilities)
3252 "Declare back end NAME with ABILITIES as a Gnus back end."
3253 (setq gnus-valid-select-methods
3254 (nconc gnus-valid-select-methods
3255 (list (apply 'list name abilities))))
3256 (gnus-redefine-select-method-widget))
3258 (defun gnus-set-default-directory ()
3259 "Set the default directory in the current buffer to `gnus-default-directory'.
3260 If this variable is nil, don't do anything."
3261 (setq default-directory
3262 (if (and gnus-default-directory
3263 (file-exists-p gnus-default-directory))
3264 (file-name-as-directory (expand-file-name gnus-default-directory))
3265 default-directory)))
3268 (defalias 'gnus-display-time-event-handler
3269 (if (gnus-boundp 'display-time-timer)
3270 'display-time-event-handler
3271 (lambda () "Does nothing as `display-time-timer' is not bound.
3272 Would otherwise be an alias for `display-time-event-handler'." nil))))
3275 (defun gnus-fixup-nnimap-unread-after-getting-new-news ()
3276 (let (server group info)
3279 (when (and (setq group (symbol-name sym))
3280 (gnus-group-entry group)
3281 (setq info (symbol-value sym)))
3282 (gnus-sethash group (cons (nth 2 info) (cdr (gnus-group-entry group)))
3283 gnus-newsrc-hashtb)))
3284 (if (boundp 'nnimap-mailbox-info)
3285 (symbol-value 'nnimap-mailbox-info)
3286 (make-vector 1 0)))))
3288 (defun gnus-check-reasonable-setup ()
3289 ;; Check whether nnml and nnfolder share a directory.
3291 (if (boundp 'display-warning)
3293 (lambda (type message)
3295 (message "Warning (%s): %s" type message)
3297 (with-current-buffer (get-buffer-create "*Warnings*")
3298 (goto-char (point-max))
3301 (insert (format "Warning (%s): %s\n" type message))
3302 (setq window (display-buffer (current-buffer)))
3306 (forward-line (- 1 (window-height window)))
3308 (goto-char (point-max))))))))))
3309 method active actives match)
3310 (dolist (server gnus-server-alist)
3311 (setq method (gnus-server-to-method server)
3312 active (intern (format "%s-active-file" (car method))))
3313 (when (and (member (car method) '(nnml nnfolder))
3314 (gnus-server-opened method)
3316 (when (setq match (assoc (symbol-value active) actives))
3317 (funcall display-warn 'gnus-server
3318 (format "%s and %s share the same active file %s"
3322 (push (list (symbol-value active) method) actives)))))
3324 (provide 'gnus-start)
3326 ;;; gnus-start.el ends here