1 ;;; gnus-start.el --- startup functions for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
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'
64 :type '(choice (const :tag "Never" never)
65 (const :tag "If existing" nil)
66 (other :tag "Always" t)))
68 (defcustom gnus-save-startup-file-via-temp-buffer t
69 "Whether to write the startup file contents to a buffer then save
70 the buffer or write directly to the file. The buffer is faster
71 because all of the contents are written at once. The direct write
72 uses considerably less memory."
74 :type '(choice (const :tag "Write via buffer" t)
75 (const :tag "Write directly to file" nil)))
77 (defcustom gnus-init-file (nnheader-concat gnus-home-directory ".gnus")
78 "Your Gnus Emacs-Lisp startup file name.
79 If a file with the `.el' or `.elc' suffixes exists, it will be read instead."
83 (defcustom gnus-site-init-file
85 (concat (file-name-directory
86 (directory-file-name installation-directory))
87 "site-lisp/gnus-init")
89 "The site-wide Gnus Emacs-Lisp startup file name, or nil if none.
90 If a file with the `.el' or `.elc' suffixes exists, it will be read instead."
92 :type '(choice file (const nil)))
94 (defcustom gnus-default-subscribed-newsgroups nil
95 "List of newsgroups to subscribe, when a user runs Gnus the first time.
96 The value should be a list of strings.
97 If it is t, Gnus will not do anything special the first time it is
98 started; it'll just use the normal newsgroups subscription methods."
100 :type '(choice (repeat string) (const :tag "Nothing special" t)))
102 (defcustom gnus-use-dribble-file t
103 "*Non-nil means that Gnus will use a dribble file to store user updates.
104 If Emacs should crash without saving the .newsrc files, complete
105 information can be restored from the dribble file."
106 :group 'gnus-dribble-file
109 (defcustom gnus-dribble-directory nil
110 "*The directory where dribble files will be saved.
111 If this variable is nil, the directory where the .newsrc files are
113 :group 'gnus-dribble-file
114 :type '(choice directory (const nil)))
116 (defcustom gnus-check-new-newsgroups 'ask-server
117 "*Non-nil means that Gnus will run `gnus-find-new-newsgroups' at startup.
118 This normally finds new newsgroups by comparing the active groups the
119 servers have already reported with those Gnus already knows, either alive
122 When any of the following are true, `gnus-find-new-newsgroups' will instead
123 ask the servers (primary, secondary, and archive servers) to list new
124 groups since the last time it checked:
125 1. This variable is `ask-server'.
126 2. This variable is a list of select methods (see below).
127 3. `gnus-read-active-file' is nil or `some'.
128 4. A prefix argument is given to `gnus-find-new-newsgroups' interactively.
130 Thus, if this variable is `ask-server' or a list of select methods or
131 `gnus-read-active-file' is nil or `some', then the killed list is no
132 longer necessary, so you could safely set `gnus-save-killed-list' to nil.
134 This variable can be a list of select methods which Gnus will query with
135 the `ask-server' method in addition to the primary, secondary, and archive
139 (setq gnus-check-new-newsgroups
140 '((nntp \"some.server\") (nntp \"other.server\")))
142 If this variable is nil, then you have to tell Gnus explicitly to
143 check for new newsgroups with \\<gnus-group-mode-map>\\[gnus-find-new-newsgroups]."
145 :type '(choice (const :tag "no" nil)
146 (const :tag "by brute force" t)
147 (const :tag "ask servers" ask-server)
148 (repeat :menu-tag "ask additional servers"
149 :tag "ask additional servers"
151 (sexp :format "%v"))))
153 (defcustom gnus-check-bogus-newsgroups nil
154 "*Non-nil means that Gnus will check and remove bogus newsgroup at startup.
155 If this variable is nil, then you have to tell Gnus explicitly to
156 check for bogus newsgroups with \\<gnus-group-mode-map>\\[gnus-group-check-bogus-groups]."
157 :group 'gnus-start-server
160 (defcustom gnus-read-active-file 'some
161 "*Non-nil means that Gnus will read the entire active file at startup.
162 If this variable is nil, Gnus will only know about the groups in your
165 If this variable is `some', Gnus will try to only read the relevant
166 parts of the active file from the server. Not all servers support
167 this, and it might be quite slow with other servers, but this should
168 generally be faster than both the t and nil value.
170 If you set this variable to nil or `some', you probably still want to
171 be told about new newsgroups that arrive. To do that, set
172 `gnus-check-new-newsgroups' to `ask-server'. This may not work
173 properly with all servers."
174 :group 'gnus-start-server
175 :type '(choice (const nil)
179 (defconst gnus-level-subscribed 5
180 "Groups with levels less than or equal to this variable are subscribed.")
182 (defconst gnus-level-unsubscribed 7
183 "Groups with levels less than or equal to this variable are unsubscribed.
184 Groups with levels less than `gnus-level-subscribed', which should be
185 less than this variable, are subscribed.")
187 (defconst gnus-level-zombie 8
188 "Groups with this level are zombie groups.")
190 (defconst gnus-level-killed 9
191 "Groups with this level are killed.")
193 (defcustom gnus-level-default-subscribed 3
194 "*New subscribed groups will be subscribed at this level."
195 :group 'gnus-group-levels
198 (defcustom gnus-level-default-unsubscribed 6
199 "*New unsubscribed groups will be unsubscribed at this level."
200 :group 'gnus-group-levels
203 (defcustom gnus-activate-level (1+ gnus-level-subscribed)
204 "*Groups higher than this level won't be activated on startup.
205 Setting this variable to something low might save lots of time when
206 you have many groups that you aren't interested in."
207 :group 'gnus-group-levels
210 (defcustom gnus-activate-foreign-newsgroups 4
211 "*If nil, Gnus will not check foreign newsgroups at startup.
212 If it is non-nil, it should be a number between one and nine. Foreign
213 newsgroups that have a level lower or equal to this number will be
214 activated on startup. For instance, if you want to active all
215 subscribed newsgroups, but not the rest, you'd set this variable to
216 `gnus-level-subscribed'.
218 If you subscribe to lots of newsgroups from different servers, startup
219 might take a while. By setting this variable to nil, you'll save time,
220 but you won't be told how many unread articles there are in the
222 :group 'gnus-group-levels
223 :type '(choice integer
224 (const :tag "none" nil)))
226 (defcustom gnus-read-newsrc-file t
227 "*Non-nil means that Gnus will read the `.newsrc' file.
228 Gnus always reads its own startup file, which is called
229 \".newsrc.eld\". The file called \".newsrc\" is in a format that can
230 be readily understood by other newsreaders. If you don't plan on
231 using other newsreaders, set this variable to nil to save some time on
237 (defcustom gnus-save-newsrc-file t
238 "*Non-nil means that Gnus will save the `.newsrc' file.
239 Gnus always saves its own startup file, which is called
240 \".newsrc.eld\". The file called \".newsrc\" is in a format that can
241 be readily understood by other newsreaders. If you don't plan on
242 using other newsreaders, set this variable to nil to save some time on
247 (defcustom gnus-save-killed-list t
248 "*If non-nil, save the list of killed groups to the startup file.
249 If you set this variable to nil, you'll save both time (when starting
250 and quitting) and space (both memory and disk), but it will also mean
251 that Gnus has no record of which groups are new and which are old, so
252 the automatic new newsgroups subscription methods become meaningless.
254 You should always set `gnus-check-new-newsgroups' to `ask-server' or
255 nil if you set this variable to nil.
257 This variable can also be a regexp. In that case, all groups that do
258 not match this regexp will be removed before saving the list."
260 :type '(radio (sexp :format "Non-nil\n"
261 :match (lambda (widget value)
262 (and value (not (stringp value))))
265 (regexp :format "%t: %v\n" :size 0)))
267 (defcustom gnus-ignored-newsgroups
269 '("^to\\." ; not "real" groups
270 "^[0-9. \t]+\\( \\|$\\)" ; all digits in name
271 "^[\"][]\"[#'()]" ; bogus characters
274 "*A regexp to match uninteresting newsgroups in the active file.
275 Any lines in the active file matching this regular expression are
276 removed from the newsgroup list before anything else is done to it,
277 thus making them effectively non-existent."
278 :group 'gnus-group-new
281 (defcustom gnus-subscribe-newsgroup-method 'gnus-subscribe-zombies
282 "*Function(s) called with a group name when new group is detected.
283 A few pre-made functions are supplied: `gnus-subscribe-randomly'
284 inserts new groups at the beginning of the list of groups;
285 `gnus-subscribe-alphabetically' inserts new groups in strict
286 alphabetic order; `gnus-subscribe-hierarchically' inserts new groups
287 in hierarchical newsgroup order; `gnus-subscribe-interactively' asks
288 for your decision; `gnus-subscribe-killed' kills all new groups;
289 `gnus-subscribe-zombies' will make all new groups into zombies;
290 `gnus-subscribe-topics' will enter groups into the topics that
292 :group 'gnus-group-new
293 :type '(radio (function-item gnus-subscribe-randomly)
294 (function-item gnus-subscribe-alphabetically)
295 (function-item gnus-subscribe-hierarchically)
296 (function-item gnus-subscribe-interactively)
297 (function-item gnus-subscribe-killed)
298 (function-item gnus-subscribe-zombies)
299 (function-item gnus-subscribe-topics)
303 (defcustom gnus-subscribe-newsgroup-hooks nil
304 "*Hooks run after you subscribe to a new group.
305 The hooks will be called with new group's name as argument."
306 :group 'gnus-group-new
309 (defcustom gnus-subscribe-options-newsgroup-method
310 'gnus-subscribe-alphabetically
311 "*Function(s) called to subscribe newsgroups mentioned on \"options -n\" lines.
312 If, for instance, you want to subscribe to all newsgroups in the
313 \"no\" and \"alt\" hierarchies, you'd put the following in your
316 options -n no.all alt.all
318 Gnus will the subscribe all new newsgroups in these hierarchies with
319 the subscription method in this variable."
320 :group 'gnus-group-new
321 :type '(radio (function-item gnus-subscribe-randomly)
322 (function-item gnus-subscribe-alphabetically)
323 (function-item gnus-subscribe-hierarchically)
324 (function-item gnus-subscribe-interactively)
325 (function-item gnus-subscribe-killed)
326 (function-item gnus-subscribe-zombies)
327 (function-item gnus-subscribe-topics)
331 (defcustom gnus-subscribe-hierarchical-interactive nil
332 "*If non-nil, Gnus will offer to subscribe hierarchically.
333 When a new hierarchy appears, Gnus will ask the user:
335 'alt.binaries': Do you want to subscribe to this hierarchy? ([d]ys):
337 If the user pressed `d', Gnus will descend the hierarchy, `y' will
338 subscribe to all newsgroups in the hierarchy and `s' will skip this
339 hierarchy in its entirety."
340 :group 'gnus-group-new
343 (defcustom gnus-auto-subscribed-groups
344 "^nnml\\|^nnfolder\\|^nnmbox\\|^nnmh\\|^nnbabyl\\|^nnmaildir"
345 "*All new groups that match this regexp will be subscribed automatically.
346 Note that this variable only deals with new groups. It has no effect
347 whatsoever on old groups.
349 New groups that match this regexp will not be handled by
350 `gnus-subscribe-newsgroup-method'. Instead, they will
351 be subscribed using `gnus-subscribe-options-newsgroup-method'."
352 :group 'gnus-group-new
355 (defcustom gnus-options-subscribe nil
356 "*All new groups matching this regexp will be subscribed unconditionally.
357 Note that this variable deals only with new newsgroups. This variable
358 does not affect old newsgroups.
360 New groups that match this regexp will not be handled by
361 `gnus-subscribe-newsgroup-method'. Instead, they will
362 be subscribed using `gnus-subscribe-options-newsgroup-method'."
363 :group 'gnus-group-new
364 :type '(choice regexp
365 (const :tag "none" nil)))
367 (defcustom gnus-options-not-subscribe nil
368 "*All new groups matching this regexp will be ignored.
369 Note that this variable deals only with new newsgroups. This variable
370 does not affect old (already subscribed) newsgroups."
371 :group 'gnus-group-new
372 :type '(choice regexp
373 (const :tag "none" nil)))
375 (defcustom gnus-modtime-botch nil
376 "*Non-nil means .newsrc should be deleted prior to save.
377 Its use is due to the bogus appearance that .newsrc was modified on
382 (defcustom gnus-check-bogus-groups-hook nil
383 "A hook run after removing bogus groups."
384 :group 'gnus-start-server
387 (defcustom gnus-startup-hook nil
388 "A hook called at startup.
389 This hook is called after Gnus is connected to the NNTP server."
393 (defcustom gnus-before-startup-hook nil
394 "A hook called at before startup.
395 This hook is called as the first thing when Gnus is started."
399 (defcustom gnus-started-hook nil
400 "A hook called as the last thing after startup."
404 (defcustom gnus-setup-news-hook
405 '(gnus-fixup-nnimap-unread-after-getting-new-news)
406 "A hook after reading the .newsrc file, but before generating the buffer."
410 (defcustom gnus-get-top-new-news-hook nil
411 "A hook run just before Gnus checks for new news globally."
412 :group 'gnus-group-new
415 (defcustom gnus-get-new-news-hook nil
416 "A hook run just before Gnus checks for new news."
417 :group 'gnus-group-new
420 (defcustom gnus-after-getting-new-news-hook
421 '(gnus-display-time-event-handler
422 gnus-fixup-nnimap-unread-after-getting-new-news)
423 "A hook run after Gnus checks for new news when Gnus is already running."
424 :group 'gnus-group-new
427 (defcustom gnus-read-newsrc-el-hook nil
428 "A hook called after reading the newsrc.eld? file."
432 (defcustom gnus-save-newsrc-hook nil
433 "A hook called before saving any of the newsrc files."
437 (defcustom gnus-save-quick-newsrc-hook nil
438 "A hook called just before saving the quick newsrc file.
439 Can be used to turn version control on or off."
443 (defcustom gnus-save-standard-newsrc-hook nil
444 "A hook called just before saving the standard newsrc file.
445 Can be used to turn version control on or off."
449 (defcustom gnus-group-mode-hook nil
450 "Hook for Gnus group mode."
451 :group 'gnus-group-various
452 :options '(gnus-topic-mode)
455 (defcustom gnus-always-read-dribble-file nil
456 "Unconditionally read the dribble file."
460 ;;; Internal variables
462 (defvar gnus-ding-file-coding-system 'ctext
463 "Coding system for ding file.")
464 ;; Note that the ding file for T-gnus ought not to have byte-codes.
466 (defvar gnus-newsrc-file-version nil)
467 (defvar gnus-override-subscribe-method nil)
468 (defvar gnus-dribble-buffer nil)
469 (defvar gnus-newsrc-options nil
470 "Options line in the .newsrc file.")
472 (defvar gnus-newsrc-options-n nil
473 "List of regexps representing groups to be subscribed/ignored unconditionally.")
475 (defvar gnus-newsrc-last-checked-date nil
476 "Date Gnus last asked server for new newsgroups.")
478 (defvar gnus-current-startup-file nil
479 "Startup file for the current host.")
481 ;; Byte-compiler warning.
482 (defvar gnus-group-line-format)
484 ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
485 (defvar gnus-init-inhibit nil)
486 (defun gnus-read-init-file (&optional inhibit-next)
487 ;; Don't load .gnus if the -q option was used.
489 (if gnus-init-inhibit
490 (setq gnus-init-inhibit nil)
491 (setq gnus-init-inhibit inhibit-next)
492 (dolist (file (list gnus-site-init-file gnus-init-file))
494 (locate-library file))
495 (if (or debug-on-error debug-on-quit)
500 (error "Error in %s: %s" file (cadr var))))))))))
502 ;; For subscribing new newsgroup
504 (defun gnus-subscribe-hierarchical-interactive (groups)
505 (let ((groups (sort groups 'string<))
506 prefixes prefix start ans group starts)
508 (setq prefixes (list "^"))
509 (while (and groups prefixes)
510 (while (not (string-match (car prefixes) (car groups)))
511 (setq prefixes (cdr prefixes)))
512 (setq prefix (car prefixes))
513 (setq start (1- (length prefix)))
514 (if (and (string-match "[^\\.]\\." (car groups) start)
517 (concat "^" (substring (car groups) 0 (match-end 0))))
518 (string-match prefix (cadr groups)))
520 (push prefix prefixes)
521 (message "Descend hierarchy %s? ([y]nsq): "
522 (substring prefix 1 (1- (length prefix))))
523 (while (not (memq (setq ans (read-char-exclusive))
524 '(?y ?\n ?\r ?n ?s ?q)))
526 (message "Descend hierarchy %s? ([y]nsq): "
527 (substring prefix 1 (1- (length prefix)))))
531 (setq group (car groups))))
532 (push group gnus-killed-list)
533 (gnus-sethash group group gnus-killed-hashtb)
534 (setq groups (cdr groups)))
535 (setq starts (cdr starts)))
539 (setq group (car groups))))
540 (gnus-sethash group group gnus-killed-hashtb)
541 (gnus-subscribe-alphabetically (car groups))
542 (setq groups (cdr groups)))
543 (setq starts (cdr starts)))
546 (setq group (car groups))
547 (push group gnus-killed-list)
548 (gnus-sethash group group gnus-killed-hashtb)
549 (setq groups (cdr groups))))
551 (message "Subscribe %s? ([n]yq)" (car groups))
552 (while (not (memq (setq ans (read-char-exclusive))
553 '(?y ?\n ?\r ?q ?n)))
555 (message "Subscribe %s? ([n]yq)" (car groups)))
556 (setq group (car groups))
558 (gnus-subscribe-alphabetically (car groups))
559 (gnus-sethash group group gnus-killed-hashtb))
562 (setq group (car groups))
563 (push group gnus-killed-list)
564 (gnus-sethash group group gnus-killed-hashtb)
565 (setq groups (cdr groups))))
567 (push group gnus-killed-list)
568 (gnus-sethash group group gnus-killed-hashtb)))
569 (setq groups (cdr groups)))))))
571 (defun gnus-subscribe-randomly (newsgroup)
572 "Subscribe new NEWSGROUP by making it the first newsgroup."
573 (gnus-subscribe-newsgroup newsgroup))
575 (defun gnus-subscribe-alphabetically (newgroup)
576 "Subscribe new NEWGROUP and insert it in alphabetical order."
577 (let ((groups (cdr gnus-newsrc-alist))
579 (while (and (not before) groups)
580 (if (string< newgroup (caar groups))
581 (setq before (caar groups))
582 (setq groups (cdr groups))))
583 (gnus-subscribe-newsgroup newgroup before)))
585 (defun gnus-subscribe-hierarchically (newgroup)
586 "Subscribe new NEWGROUP and insert it in hierarchical newsgroup order."
587 ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
589 (set-buffer (nnheader-find-file-noselect gnus-current-startup-file))
591 (let ((groupkey newgroup) before)
592 (while (and (not before) groupkey)
593 (goto-char (point-min))
595 (concat "^\\(" (regexp-quote groupkey) ".*\\)[!:]")))
596 (while (and (re-search-forward groupkey-re nil t)
598 (setq before (match-string 1))
599 (string< before newgroup)))))
600 ;; Remove tail of newsgroup name (eg. a.b.c -> a.b)
602 (when (string-match "^\\(.*\\)\\.[^.]+$" groupkey)
603 (substring groupkey (match-beginning 1) (match-end 1)))))
604 (gnus-subscribe-newsgroup newgroup before))
605 (kill-buffer (current-buffer)))))
607 (defun gnus-subscribe-interactively (group)
608 "Subscribe the new GROUP interactively.
609 It is inserted in hierarchical newsgroup order if subscribed. If not,
611 (if (gnus-y-or-n-p (format "Subscribe new newsgroup: %s " group))
612 (gnus-subscribe-hierarchically group)
613 (push group gnus-killed-list)))
615 (defun gnus-subscribe-zombies (group)
616 "Make the new GROUP into a zombie group."
617 (push group gnus-zombie-list))
619 (defun gnus-subscribe-killed (group)
620 "Make the new GROUP a killed group."
621 (push group gnus-killed-list))
623 (defun gnus-subscribe-newsgroup (newsgroup &optional next)
624 "Subscribe new NEWSGROUP.
625 If NEXT is non-nil, it is inserted before NEXT. Otherwise it is made
626 the first newsgroup."
628 (goto-char (point-min))
629 ;; We subscribe the group by changing its level to `subscribed'.
630 (gnus-group-change-level
631 newsgroup gnus-level-default-subscribed
632 gnus-level-killed (gnus-group-entry (or next "dummy.group")))
633 (gnus-message 5 "Subscribe newsgroup: %s" newsgroup)
634 (run-hook-with-args 'gnus-subscribe-newsgroup-hooks newsgroup)
637 (defun gnus-read-active-file-p ()
638 "Say whether the active file has been read from `gnus-select-method'."
639 (memq gnus-select-method gnus-have-read-active-file))
641 ;;; General various misc type functions.
643 ;; Silence byte-compiler.
645 (defvar gnus-current-headers)
646 (defvar gnus-thread-indent-array)
647 (defvar gnus-newsgroup-name)
648 (defvar gnus-newsgroup-headers)
649 (defvar gnus-group-list-mode)
650 (defvar gnus-group-mark-positions)
651 (defvar gnus-newsgroup-data)
652 (defvar gnus-newsgroup-unreads)
653 (defvar nnoo-state-alist)
654 (defvar gnus-current-select-method)
655 (defvar mail-sources)
656 (defvar nnmail-scan-directory-mail-source-once)
657 (defvar nnmail-split-history)
658 (defvar nnmail-spool-file))
660 (defun gnus-clear-quick-file-variables ()
661 "Clear all variables in quick startup files."
662 (let ((variables gnus-variable-list))
663 ;; Clear Gnus variables.
665 (set (car variables) nil)
666 (setq variables (cdr variables))))
667 (let ((files gnus-product-variable-file-list))
669 (let ((variables (nthcdr 3 (car files))))
671 (set (car variables) nil)
672 (setq variables (cdr variables))))
673 (setq files (cdr files)))))
675 (defun gnus-close-all-servers ()
678 (dolist (server gnus-opened-servers)
679 (gnus-close-server (car server))))
681 (defun gnus-clear-system ()
682 "Clear all variables and buffers."
683 ;; Clear gnus variables.
684 (gnus-clear-quick-file-variables)
685 ;; Clear other internal variables.
686 (setq gnus-list-of-killed-groups nil
687 gnus-have-read-active-file nil
688 gnus-agent-covered-methods nil
689 gnus-agent-file-loading-local nil
690 gnus-agent-file-loading-cache nil
691 gnus-server-method-cache nil
692 gnus-newsrc-alist nil
693 gnus-newsrc-hashtb nil
696 gnus-killed-hashtb nil
697 gnus-active-hashtb nil
698 gnus-moderated-hashtb nil
699 gnus-description-hashtb nil
700 gnus-current-headers nil
701 gnus-thread-indent-array nil
702 gnus-newsgroup-headers nil
703 gnus-newsgroup-name nil
704 gnus-server-alist nil
705 gnus-group-list-mode nil
706 gnus-opened-servers nil
707 gnus-group-mark-positions nil
708 gnus-newsgroup-data nil
709 gnus-newsgroup-unreads nil
711 gnus-current-select-method nil
712 nnmail-split-history nil
713 gnus-ephemeral-servers nil)
714 (gnus-shutdown 'gnus)
715 ;; Kill the startup file.
716 (and gnus-current-startup-file
717 (get-file-buffer gnus-current-startup-file)
718 (kill-buffer (get-file-buffer gnus-current-startup-file)))
719 ;; Clear the dribble buffer.
721 ;; Kill global KILL file buffer.
722 (when (get-file-buffer (gnus-newsgroup-kill-file nil))
723 (kill-buffer (get-file-buffer (gnus-newsgroup-kill-file nil))))
724 (gnus-kill-buffer nntp-server-buffer)
725 ;; Kill Gnus buffers.
726 (dolist (buffer (gnus-buffers))
727 (gnus-kill-buffer buffer))
728 ;; Remove Gnus frames.
729 (gnus-kill-gnus-frames))
731 (defun gnus-no-server-1 (&optional arg slave)
733 If ARG is a positive number, Gnus will use that as the
734 startup level. If ARG is nil, Gnus will be started at level 2.
735 If ARG is non-nil and not a positive number, Gnus will
736 prompt the user for the name of an NNTP server to use.
737 As opposed to `gnus', this command will not connect to the local server."
739 (let ((val (or arg (1- gnus-level-default-subscribed))))
741 (make-local-variable 'gnus-group-use-permanent-levels)
742 (setq gnus-group-use-permanent-levels val)))
744 (defun gnus-1 (&optional arg dont-connect slave)
746 If ARG is non-nil and a positive number, Gnus will use that as the
747 startup level. If ARG is non-nil and not a positive number, Gnus will
748 prompt the user for the name of an NNTP server to use."
753 (switch-to-buffer gnus-group-buffer)
754 (gnus-group-get-new-news
757 (max (car gnus-group-list-mode) arg))))
761 (gnus-run-hooks 'gnus-before-startup-hook)
762 (nnheader-init-server-buffer)
763 (setq gnus-slave slave)
764 (gnus-read-init-file)
768 (when gnus-simple-splash
769 (setq gnus-simple-splash nil)
774 (= (frame-height) (1+ (window-height))))
777 (let ((level (and (numberp arg) (> arg 0) arg))
783 (gnus-start-news-server (and arg (not level))))))
784 (if (and (not dont-connect)
787 (gnus-run-hooks 'gnus-startup-hook)
788 ;; NNTP server is successfully open.
790 ;; Find the current startup file name.
791 (setq gnus-current-startup-file
792 (gnus-make-newsrc-file gnus-startup-file))
794 ;; Read the dribble file.
795 (when (or gnus-slave gnus-use-dribble-file)
796 (gnus-dribble-read-file))
798 ;; Do the actual startup.
800 (gnus-request-create-group "queue" '(nndraft "")))
801 (gnus-request-create-group "drafts" '(nndraft ""))
802 (gnus-setup-news nil level dont-connect)
803 (gnus-run-hooks 'gnus-setup-news-hook)
804 (gnus-start-draft-setup)
805 ;; Generate the group buffer.
806 (gnus-group-list-groups level)
807 (gnus-group-first-unread-group)
808 (gnus-configure-windows 'group)
809 (gnus-group-set-mode-line)
811 (set-language-info "Japanese" 'gnus-info "gnus-ja")
812 (gnus-run-hooks 'gnus-started-hook))))))
814 (defun gnus-start-draft-setup ()
815 "Make sure the draft group exists."
816 (gnus-request-create-group "drafts" '(nndraft ""))
817 (unless (gnus-group-entry "nndraft:drafts")
818 (let ((gnus-level-default-subscribed 1))
819 (gnus-subscribe-group "nndraft:drafts" nil '(nndraft "")))
820 (gnus-group-set-parameter
821 "nndraft:drafts" 'gnus-dummy '((gnus-draft-mode)))))
828 (defvar gnus-dribble-ignore nil)
829 (defvar gnus-dribble-eval-file nil)
831 (defun gnus-dribble-file-name ()
832 "Return the dribble file for the current .newsrc."
834 (if gnus-dribble-directory
835 (concat (file-name-as-directory gnus-dribble-directory)
836 (file-name-nondirectory gnus-current-startup-file))
837 gnus-current-startup-file)
840 (defun gnus-dribble-enter (string)
841 "Enter STRING into the dribble buffer."
842 (when (and (not gnus-dribble-ignore)
844 (buffer-name gnus-dribble-buffer))
845 (let ((obuf (current-buffer)))
846 (set-buffer gnus-dribble-buffer)
847 (goto-char (point-max))
849 ;; This has been commented by Josh Huber <huber@alum.wpi.edu>
850 ;; It causes problems with both XEmacs and Emacs 21, and doesn't
851 ;; seem to be of much value. (FIXME: remove this after we make sure
853 ;; (set-window-point (get-buffer-window (current-buffer)) (point-max))
854 (bury-buffer gnus-dribble-buffer)
856 (set-buffer gnus-group-buffer)
857 (gnus-group-set-mode-line))
860 (defun gnus-dribble-touch ()
861 "Touch the dribble buffer."
862 (gnus-dribble-enter ""))
864 (defun gnus-dribble-read-file ()
865 "Read the dribble file from disk."
866 (let ((dribble-file (gnus-dribble-file-name)))
868 (set-buffer (setq gnus-dribble-buffer
869 (gnus-get-buffer-create
870 (file-name-nondirectory dribble-file))))
872 (setq buffer-file-name dribble-file)
874 (buffer-disable-undo)
875 (bury-buffer (current-buffer))
876 (set-buffer-modified-p nil)
877 (let ((auto (make-auto-save-file-name))
878 (gnus-dribble-ignore t)
881 (when (or (file-exists-p auto) (file-exists-p dribble-file))
882 ;; Load whichever file is newest -- the auto save file
883 ;; or the "real" file.
884 (if (file-newer-than-file-p auto dribble-file)
885 (nnheader-insert-file-contents auto)
886 (nnheader-insert-file-contents dribble-file))
887 (unless (zerop (buffer-size))
888 (set-buffer-modified-p t))
889 ;; Set the file modes to reflect the .newsrc file modes.
891 (when (and (file-exists-p gnus-current-startup-file)
892 (file-exists-p dribble-file)
893 (setq modes (file-modes gnus-current-startup-file)))
894 (set-file-modes dribble-file modes))
895 (goto-char (point-min))
896 (when (search-forward "Gnus was exited on purpose" nil t)
898 ;; Possibly eval the file later.
899 (when (or gnus-always-read-dribble-file
902 "Gnus exited on purpose without saving; read auto-save file anyway? "
903 "Gnus auto-save file exists. Do you want to read it? ")))
904 (setq gnus-dribble-eval-file t)))))))
906 (defun gnus-dribble-eval-file ()
907 (when gnus-dribble-eval-file
908 (setq gnus-dribble-eval-file nil)
910 (let ((gnus-dribble-ignore t))
911 (set-buffer gnus-dribble-buffer)
912 (eval-buffer (current-buffer))))))
914 (defun gnus-dribble-delete-file ()
915 (when (file-exists-p (gnus-dribble-file-name))
916 (delete-file (gnus-dribble-file-name)))
917 (when gnus-dribble-buffer
919 (set-buffer gnus-dribble-buffer)
920 (let ((auto (make-auto-save-file-name)))
921 (when (file-exists-p auto)
924 (set-buffer-modified-p nil)))))
926 (defun gnus-dribble-save ()
927 (when (and gnus-dribble-buffer
928 (buffer-name gnus-dribble-buffer))
930 (set-buffer gnus-dribble-buffer)
933 (defun gnus-dribble-clear ()
934 (when (gnus-buffer-exists-p gnus-dribble-buffer)
936 (set-buffer gnus-dribble-buffer)
938 (set-buffer-modified-p nil)
939 (setq buffer-saved-size (buffer-size)))))
943 ;;; Active & Newsrc File Handling
946 (defun gnus-setup-news (&optional rawfile level dont-connect)
947 "Setup news information.
948 If RAWFILE is non-nil, the .newsrc file will also be read.
949 If LEVEL is non-nil, the news will be set up at level LEVEL."
951 (let ((init (not (and gnus-newsrc-alist gnus-active-hashtb (not rawfile))))
952 ;; Binding this variable will inhibit multiple fetchings
953 ;; of the same mail source.
954 (nnmail-fetched-sources (list t)))
957 ;; Clear some variables to re-initialize news information.
958 (setq gnus-newsrc-alist nil
959 gnus-active-hashtb nil)
960 ;; Read the newsrc file and create `gnus-newsrc-hashtb'.
961 (gnus-read-newsrc-file rawfile))
963 ;; Make sure the archive server is available to all and sundry.
964 (when gnus-message-archive-method
965 (unless (assoc "archive" gnus-server-alist)
970 ,(nnheader-concat message-directory "archive"))
971 (nnfolder-active-file
972 ,(nnheader-concat message-directory "archive/active"))
973 (nnfolder-get-new-mail nil)
974 (nnfolder-inhibit-expiry t))
977 ;; If we don't read the complete active file, we fill in the
979 (when (or (null gnus-read-active-file)
980 (eq gnus-read-active-file 'some))
981 (gnus-update-active-hashtb-from-killed))
983 ;; Validate agent covered methods now that gnus-server-alist has
985 ;; NOTE: This is here for one purpose only. By validating the
986 ;; agentized server's, it converts the old 5.10.3, and earlier,
987 ;; format to the current format. That enables the agent code
988 ;; within gnus-read-active-file to function correctly.
990 (gnus-agent-read-servers-validate))
992 ;; Read the active file and create `gnus-active-hashtb'.
993 ;; If `gnus-read-active-file' is nil, then we just create an empty
994 ;; hash table. The partial filling out of the hash table will be
995 ;; done in `gnus-get-unread-articles'.
996 (and gnus-read-active-file
998 (gnus-read-active-file nil dont-connect))
1000 (unless gnus-active-hashtb
1001 (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
1003 ;; Initialize the cache.
1004 (when gnus-use-cache
1007 ;; Possibly eval the dribble file.
1009 (or gnus-use-dribble-file gnus-slave)
1010 (gnus-dribble-eval-file))
1012 ;; Slave Gnusii should then clear the dribble buffer.
1013 (when (and init gnus-slave)
1014 (gnus-dribble-clear))
1016 (gnus-update-format-specifications)
1018 ;; See whether we need to read the description file.
1019 (when (and (boundp 'gnus-group-line-format)
1020 (stringp gnus-group-line-format)
1021 (let ((case-fold-search nil))
1022 (string-match "%[-,0-9]*D" gnus-group-line-format))
1023 (not gnus-description-hashtb)
1025 gnus-read-active-file)
1026 (gnus-read-all-descriptions-files))
1028 ;; Find new newsgroups and treat them.
1029 (when (and init gnus-check-new-newsgroups (not level)
1030 (gnus-check-server gnus-select-method)
1033 (gnus-find-new-newsgroups))
1035 ;; Check and remove bogus newsgroups.
1036 (when (and init gnus-check-bogus-newsgroups
1037 gnus-read-active-file (not level)
1038 (gnus-server-opened gnus-select-method))
1039 (gnus-check-bogus-newsgroups))
1041 ;; We might read in new NoCeM messages here.
1042 (when (and gnus-use-nocem
1045 (gnus-nocem-scan-groups))
1047 ;; Read any slave files.
1048 (gnus-master-read-slave-newsrc)
1050 ;; Find the number of unread articles in each non-dead group.
1051 (let ((gnus-read-active-file (and (not level) gnus-read-active-file)))
1052 (gnus-get-unread-articles level))))
1054 (defun gnus-call-subscribe-functions (method group)
1055 "Call METHOD to subscribe GROUP.
1056 If no function returns `non-nil', call `gnus-subscribe-zombies'."
1059 (funcall method group))
1062 (dolist (func method)
1063 (if (funcall func group)
1067 (gnus-subscribe-zombies group)))
1069 (defun gnus-find-new-newsgroups (&optional arg)
1070 "Search for new newsgroups and add them.
1071 Each new newsgroup will be treated with `gnus-subscribe-newsgroup-method'.
1072 The `-n' option line from .newsrc is respected.
1074 With 1 C-u, use the `ask-server' method to query the server for new
1076 With 2 C-u's, use most complete method possible to query the server
1077 for new groups, and subscribe the new groups as zombies."
1079 (let* ((gnus-subscribe-newsgroup-method
1080 gnus-subscribe-newsgroup-method)
1082 ((or (and (= (or arg 1) 4)
1083 (not (listp gnus-check-new-newsgroups)))
1084 (null gnus-read-active-file)
1085 (eq gnus-read-active-file 'some))
1088 (setq gnus-subscribe-newsgroup-method
1089 'gnus-subscribe-zombies)
1091 (t gnus-check-new-newsgroups))))
1092 (unless (gnus-check-first-time-used)
1093 (if (or (consp check)
1094 (eq check 'ask-server))
1095 ;; Ask the server for new groups.
1096 (gnus-ask-server-for-new-groups)
1097 ;; Go through the active hashtb and look for new groups.
1099 group new-newsgroups)
1100 (gnus-message 5 "Looking for new newsgroups...")
1101 (unless gnus-have-read-active-file
1102 (gnus-read-active-file))
1103 (setq gnus-newsrc-last-checked-date (message-make-date))
1104 (unless gnus-killed-hashtb
1105 (gnus-make-hashtable-from-killed))
1106 ;; Go though every newsgroup in `gnus-active-hashtb' and compare
1107 ;; with `gnus-newsrc-hashtb' and `gnus-killed-hashtb'.
1110 (if (or (null (setq group (symbol-name sym)))
1112 (null (symbol-value sym))
1113 (gnus-gethash group gnus-killed-hashtb)
1114 (gnus-gethash group gnus-newsrc-hashtb))
1116 (let ((do-sub (gnus-matches-options-n group)))
1118 ((eq do-sub 'subscribe)
1119 (setq groups (1+ groups))
1120 (gnus-sethash group group gnus-killed-hashtb)
1121 (gnus-call-subscribe-functions
1122 gnus-subscribe-options-newsgroup-method group))
1123 ((eq do-sub 'ignore)
1126 (setq groups (1+ groups))
1127 (gnus-sethash group group gnus-killed-hashtb)
1128 (if gnus-subscribe-hierarchical-interactive
1129 (push group new-newsgroups)
1130 (gnus-call-subscribe-functions
1131 gnus-subscribe-newsgroup-method group)))))))
1133 (when new-newsgroups
1134 (gnus-subscribe-hierarchical-interactive new-newsgroups))
1136 (gnus-message 5 "%d new newsgroup%s arrived."
1137 groups (if (> groups 1) "s have" " has"))
1138 (gnus-message 5 "No new newsgroups.")))))))
1140 (defun gnus-matches-options-n (group)
1141 ;; Returns `subscribe' if the group is to be unconditionally
1142 ;; subscribed, `ignore' if it is to be ignored, and nil if there is
1143 ;; no match for the group.
1145 ;; First we check the two user variables.
1147 ((and gnus-options-subscribe
1148 (string-match gnus-options-subscribe group))
1150 ((and gnus-auto-subscribed-groups
1151 (string-match gnus-auto-subscribed-groups group))
1153 ((and gnus-options-not-subscribe
1154 (string-match gnus-options-not-subscribe group))
1156 ;; Then we go through the list that was retrieved from the .newsrc
1157 ;; file. This list has elements on the form
1158 ;; `(REGEXP . {ignore,subscribe})'. The first match found (the list
1159 ;; is in the reverse order of the options line) is returned.
1161 (let ((regs gnus-newsrc-options-n))
1163 (not (string-match (caar regs) group)))
1164 (setq regs (cdr regs)))
1165 (and regs (cdar regs))))))
1167 (defun gnus-ask-server-for-new-groups ()
1168 (let* ((new-date (message-make-date))
1169 (date (or gnus-newsrc-last-checked-date new-date))
1170 (methods (cons gnus-select-method
1172 (when (gnus-archive-server-wanted-p)
1175 (and (consp gnus-check-new-newsgroups)
1176 gnus-check-new-newsgroups)
1177 gnus-secondary-select-methods))))
1179 group new-newsgroups got-new method hashtb
1180 gnus-override-subscribe-method)
1181 (unless gnus-killed-hashtb
1182 (gnus-make-hashtable-from-killed))
1183 ;; Go through both primary and secondary select methods and
1184 ;; request new newsgroups.
1185 (while (setq method (gnus-server-get-method nil (pop methods)))
1186 (setq new-newsgroups nil
1187 gnus-override-subscribe-method method)
1188 (when (and (gnus-check-server method)
1189 (gnus-request-newgroups date method))
1192 hashtb (gnus-make-hashtable 100))
1193 (set-buffer nntp-server-buffer)
1194 ;; Enter all the new groups into a hashtable.
1195 (gnus-active-to-gnus-format method hashtb 'ignore))
1196 ;; Now all new groups from `method' are in `hashtb'.
1199 (if (or (null (setq group (symbol-name group-sym)))
1200 (not (boundp group-sym))
1201 (null (symbol-value group-sym))
1202 (gnus-gethash group gnus-newsrc-hashtb)
1203 (member group gnus-zombie-list)
1204 (member group gnus-killed-list))
1205 ;; The group is already known.
1207 ;; Make this group active.
1208 (when (symbol-value group-sym)
1209 (gnus-set-active group (symbol-value group-sym)))
1210 ;; Check whether we want it or not.
1211 (let ((do-sub (gnus-matches-options-n group)))
1213 ((eq do-sub 'subscribe)
1215 (gnus-sethash group group gnus-killed-hashtb)
1216 (gnus-call-subscribe-functions
1217 gnus-subscribe-options-newsgroup-method group))
1218 ((eq do-sub 'ignore)
1222 (gnus-sethash group group gnus-killed-hashtb)
1223 (if gnus-subscribe-hierarchical-interactive
1224 (push group new-newsgroups)
1225 (gnus-call-subscribe-functions
1226 gnus-subscribe-newsgroup-method group)))))))
1228 (when new-newsgroups
1229 (gnus-subscribe-hierarchical-interactive new-newsgroups)))
1231 (gnus-message 5 "%d new newsgroup%s arrived"
1232 groups (if (> groups 1) "s have" " has"))
1233 (gnus-message 5 "No new newsgroups"))
1235 (setq gnus-newsrc-last-checked-date new-date))
1238 (defun gnus-check-first-time-used ()
1240 ;; First check if any of the following files exist. If they do,
1241 ;; it's not the first time the user has used Gnus.
1242 (dolist (file (list (concat gnus-current-startup-file ".el")
1243 (concat gnus-current-startup-file ".eld")
1244 (concat gnus-startup-file ".el")
1245 (concat gnus-startup-file ".eld")))
1246 (when (file-exists-p file)
1247 (throw 'ended nil)))
1248 (gnus-message 6 "First time user; subscribing you to default groups")
1249 (unless (gnus-read-active-file-p)
1250 (let ((gnus-read-active-file t))
1251 (gnus-read-active-file)))
1252 (setq gnus-newsrc-last-checked-date (message-make-date))
1253 ;; Subscribe to the default newsgroups.
1254 (let ((groups (or gnus-default-subscribed-newsgroups
1255 gnus-backup-default-subscribed-newsgroups))
1258 ;; If t, we subscribe (or not) all groups as if they were new.
1261 (when (setq group (symbol-name sym))
1262 (let ((do-sub (gnus-matches-options-n group)))
1264 ((eq do-sub 'subscribe)
1265 (gnus-sethash group group gnus-killed-hashtb)
1266 (gnus-call-subscribe-functions
1267 gnus-subscribe-options-newsgroup-method group))
1268 ((eq do-sub 'ignore)
1271 (push group gnus-killed-list))))))
1273 (dolist (group groups)
1274 ;; Only subscribe the default groups that are activated.
1275 (when (gnus-active group)
1276 (gnus-group-change-level
1277 group gnus-level-default-subscribed gnus-level-killed)))
1279 (set-buffer gnus-group-buffer)
1280 ;; Don't error if the group already exists. This happens when a
1281 ;; first-time user types 'F'. -- didier
1282 (gnus-group-make-help-group t))
1283 (when gnus-novice-user
1284 (gnus-message 7 "`A k' to list killed groups"))))))
1286 (defun gnus-subscribe-group (group &optional previous method)
1287 "Subscribe GROUP and put it after PREVIOUS."
1288 (gnus-group-change-level
1290 (list t group gnus-level-default-subscribed nil nil method)
1292 gnus-level-default-subscribed gnus-level-killed previous t)
1295 ;; `gnus-group-change-level' is the fundamental function for changing
1296 ;; subscription levels of newsgroups. This might mean just changing
1297 ;; from level 1 to 2, which is pretty trivial, from 2 to 6 or back
1298 ;; again, which subscribes/unsubscribes a group, which is equally
1299 ;; trivial. Changing from 1-7 to 8-9 means that you kill a group, and
1300 ;; from 8-9 to 1-7 means that you remove the group from the list of
1301 ;; killed (or zombie) groups and add them to the (kinda) subscribed
1302 ;; groups. And last but not least, moving from 8 to 9 and 9 to 8,
1303 ;; which is trivial.
1304 ;; ENTRY can either be a string (newsgroup name) or a list (if
1305 ;; FROMKILLED is t, it's a list on the format (NUM INFO-LIST),
1306 ;; otherwise it's a list in the format of the `gnus-newsrc-hashtb'
1308 ;; LEVEL is the new level of the group, OLDLEVEL is the old level and
1309 ;; PREVIOUS is the group (in hashtb entry format) to insert this group
1311 (defun gnus-group-change-level (entry level &optional oldlevel
1312 previous fromkilled)
1313 (let (group info active num)
1314 ;; Glean what info we can from the arguments
1316 (if fromkilled (setq group (nth 1 entry))
1317 (setq group (car (nth 2 entry))))
1319 (when (and (stringp entry)
1321 (< oldlevel gnus-level-zombie))
1322 (setq entry (gnus-group-entry entry)))
1323 (if (and (not oldlevel)
1325 (setq oldlevel (gnus-info-level (nth 2 entry)))
1326 (setq oldlevel (or oldlevel gnus-level-killed)))
1327 (when (stringp previous)
1328 (setq previous (gnus-group-entry previous)))
1330 (if (and (>= oldlevel gnus-level-zombie)
1331 (gnus-group-entry group))
1332 ;; We are trying to subscribe a group that is already
1336 (unless (gnus-ephemeral-group-p group)
1338 (format "(gnus-group-change-level %S %S %S %S %S)"
1339 group level oldlevel (car (nth 2 previous)) fromkilled)))
1341 ;; Then we remove the newgroup from any old structures, if needed.
1342 ;; If the group was killed, we remove it from the killed or zombie
1343 ;; list. If not, and it is in fact going to be killed, we remove
1344 ;; it from the newsrc hash table and assoc.
1346 ((>= oldlevel gnus-level-zombie)
1347 ;; oldlevel could be wrong.
1348 (setq gnus-zombie-list (delete group gnus-zombie-list))
1349 (setq gnus-killed-list (delete group gnus-killed-list)))
1351 (when (and (>= level gnus-level-zombie)
1353 (gnus-sethash (car (nth 2 entry)) nil gnus-newsrc-hashtb)
1355 (setcdr (gnus-group-entry (car (nth 3 entry)))
1357 (setcdr (cdr entry) (cdddr entry)))))
1359 ;; Finally we enter (if needed) the list where it is supposed to
1360 ;; go, and change the subscription level. If it is to be killed,
1361 ;; we enter it into the killed or zombie list.
1363 ((>= level gnus-level-zombie)
1364 ;; Remove from the hash table.
1365 (gnus-sethash group nil gnus-newsrc-hashtb)
1366 ;; We do not enter foreign groups into the list of dead
1368 (unless (gnus-group-foreign-p group)
1369 (if (= level gnus-level-zombie)
1370 (push group gnus-zombie-list)
1371 (if (= oldlevel gnus-level-killed)
1372 ;; Remove from active hashtb.
1373 (unintern group gnus-active-hashtb)
1374 ;; Don't add it into killed-list if it was killed.
1375 (push group gnus-killed-list)))))
1377 ;; If the list is to be entered into the newsrc assoc, and
1378 ;; it was killed, we have to create an entry in the newsrc
1379 ;; hashtb format and fix the pointers in the newsrc assoc.
1380 (if (< oldlevel gnus-level-zombie)
1381 ;; It was alive, and it is going to stay alive, so we
1382 ;; just change the level and don't change any pointers or
1383 ;; hash table entries.
1384 (setcar (cdaddr entry) level)
1386 (setq info (cdr entry)
1388 (setq active (gnus-active group))
1390 (if active (- (1+ (cdr active)) (car active)) t))
1391 ;; Shorten the select method if possible, if we need to
1392 ;; store it at all (native groups).
1393 (let ((method (gnus-method-simplify
1394 (or gnus-override-subscribe-method
1395 (gnus-group-method group)))))
1397 (setq info (list group level nil nil method))
1398 (setq info (list group level nil)))))
1401 (let ((p gnus-newsrc-alist))
1405 (setq entry (cons info (cddr previous)))
1408 (setcdr (cdr previous) entry)
1409 (gnus-sethash group (cons num (cdr previous))
1410 gnus-newsrc-hashtb))
1411 (setcdr previous entry)
1412 (gnus-sethash group (cons num previous)
1413 gnus-newsrc-hashtb))
1415 (setcdr (gnus-group-entry (caadr entry)) entry))
1418 "(gnus-group-set-info '%S)" info)))))
1419 (when gnus-group-change-level-function
1420 (funcall gnus-group-change-level-function
1421 group level oldlevel previous)))))
1423 (defun gnus-kill-newsgroup (newsgroup)
1424 "Obsolete function. Kills a newsgroup."
1425 (gnus-group-change-level
1426 (gnus-group-entry newsgroup) gnus-level-killed))
1428 (defun gnus-check-bogus-newsgroups (&optional confirm)
1429 "Remove bogus newsgroups.
1430 If CONFIRM is non-nil, the user has to confirm the deletion of every
1432 (let ((newsrc (cdr gnus-newsrc-alist))
1433 bogus group entry info)
1434 (gnus-message 5 "Checking bogus newsgroups...")
1435 (unless (gnus-read-active-file-p)
1436 (gnus-read-active-file t))
1437 (when (gnus-read-active-file-p)
1438 ;; Find all bogus newsgroup that are subscribed.
1440 (setq info (pop newsrc)
1441 group (gnus-info-group info))
1442 (unless (or (gnus-active group) ; Active
1443 (and (gnus-info-method info)
1444 (not (gnus-secondary-method-p
1445 (gnus-info-method info))))) ; Foreign
1446 ;; Found a bogus newsgroup.
1447 (push group bogus)))
1450 "Remove bogus group %s? "
1452 ;; Remove all bogus subscribed groups by first killing them, and
1453 ;; then removing them from the list of killed groups.
1454 (when (setq entry (gnus-group-entry group))
1455 (gnus-group-change-level entry gnus-level-killed)
1456 (setq gnus-killed-list (delete group gnus-killed-list))))
1457 bogus '("group" "groups" "remove"))
1458 (while (setq group (pop bogus))
1459 ;; Remove all bogus subscribed groups by first killing them, and
1460 ;; then removing them from the list of killed groups.
1461 (when (setq entry (gnus-group-entry group))
1462 (gnus-group-change-level entry gnus-level-killed)
1463 (setq gnus-killed-list (delete group gnus-killed-list)))))
1464 ;; Then we remove all bogus groups from the list of killed and
1465 ;; zombie groups. They are removed without confirmation.
1466 (let ((dead-lists '(gnus-killed-list gnus-zombie-list))
1469 (setq killed (symbol-value (car dead-lists)))
1471 (unless (gnus-active (setq group (pop killed)))
1472 ;; The group is bogus.
1474 (set (car dead-lists)
1475 (delete group (symbol-value (car dead-lists))))))
1476 (setq dead-lists (cdr dead-lists))))
1477 (gnus-run-hooks 'gnus-check-bogus-groups-hook)
1478 (gnus-message 5 "Checking bogus newsgroups...done"))))
1480 (defun gnus-check-duplicate-killed-groups ()
1481 "Remove duplicates from the list of killed groups."
1483 (let ((killed gnus-killed-list))
1485 (gnus-message 9 "%d" (length killed))
1486 (setcdr killed (delete (car killed) (cdr killed)))
1487 (setq killed (cdr killed)))))
1489 ;; We want to inline a function from gnus-cache, so we cheat here:
1491 (defvar gnus-cache-active-hashtb)
1492 (defun gnus-cache-possibly-alter-active (group active)
1493 "Alter the ACTIVE info for GROUP to reflect the articles in the cache."
1494 (when gnus-cache-active-hashtb
1495 (let ((cache-active (gnus-gethash group gnus-cache-active-hashtb)))
1497 (when (< (car cache-active) (car active))
1498 (setcar active (car cache-active)))
1499 (when (> (cdr cache-active) (cdr active))
1500 (setcdr active (cdr cache-active))))))))
1502 (defun gnus-activate-group (group &optional scan dont-check method)
1503 ;; Check whether a group has been activated or not.
1504 ;; If SCAN, request a scan of that group as well.
1505 (let ((method (or method (inline (gnus-find-method-for-group group))))
1507 (and (inline (gnus-check-server method))
1508 ;; We escape all bugs and quit here to make it possible to
1509 ;; continue if a group is so out-there that it reports bugs
1513 (gnus-check-backend-function 'request-scan (car method))
1514 (gnus-request-scan group method))
1516 (if (or debug-on-error debug-on-quit)
1517 (inline (gnus-request-group group dont-check method))
1519 (inline (gnus-request-group group dont-check method))
1522 (message "Quit activating %s" group)
1525 (setq active (gnus-parse-active))
1526 ;; If there are no articles in the group, the GROUP
1527 ;; command may have responded with the `(0 . 0)'. We
1528 ;; ignore this if we already have an active entry
1530 (if (and (zerop (car active))
1531 (zerop (cdr active))
1532 (gnus-active group))
1535 ;; If a cache is present, we may have to alter the active info.
1536 (when gnus-use-cache
1537 (inline (gnus-cache-possibly-alter-active
1540 ;; If the agent is enabled, we may have to alter the active info.
1542 (gnus-agent-possibly-alter-active group active))
1544 (gnus-set-active group active)
1545 ;; Return the new active info.
1548 (defun gnus-get-unread-articles-in-group (info active &optional update)
1550 ;; Allow the backend to update the info in the group.
1552 (gnus-request-update-info
1553 info (inline (gnus-find-method-for-group
1554 (gnus-info-group info)))))
1555 (gnus-activate-group (gnus-info-group info) nil t))
1557 (let* ((range (gnus-info-read info))
1560 ;; These checks are present in gnus-activate-group but skipped
1561 ;; due to setting dont-check in the preceeding call.
1563 ;; If a cache is present, we may have to alter the active info.
1564 (when (and gnus-use-cache info)
1565 (inline (gnus-cache-possibly-alter-active
1566 (gnus-info-group info) active)))
1568 ;; If the agent is enabled, we may have to alter the active info.
1569 (when (and gnus-agent info)
1570 (gnus-agent-possibly-alter-active (gnus-info-group info) active info))
1572 ;; Modify the list of read articles according to what articles
1573 ;; are available; then tally the unread articles and add the
1574 ;; number to the group hash table entry.
1576 ((zerop (cdr active))
1579 (setq num (- (1+ (cdr active)) (car active))))
1580 ((not (listp (cdr range)))
1581 ;; Fix a single (num . num) range according to the
1582 ;; active hash table.
1583 ;; Fix by Carsten Bormann <cabo@Informatik.Uni-Bremen.DE>.
1584 (and (< (cdr range) (car active)) (setcdr range (1- (car active))))
1585 (and (> (cdr range) (cdr active)) (setcdr range (cdr active)))
1586 ;; Compute number of unread articles.
1587 (setq num (max 0 (- (cdr active) (- (1+ (cdr range)) (car range))))))
1589 ;; The read list is a list of ranges. Fix them according to
1590 ;; the active hash table.
1591 ;; First peel off any elements that are below the lower
1593 (while (and (cdr range)
1595 (or (and (atom (cadr range)) (cadr range))
1597 (if (numberp (car range))
1600 (or (and (numberp (cadr range))
1604 (or (and (numberp (nth 1 range)) (nth 1 range))
1606 (setcdr range (cddr range)))
1607 ;; Adjust the first element to be the same as the lower limit.
1608 (when (and (not (atom (car range)))
1609 (< (cdar range) (car active)))
1610 (setcdr (car range) (1- (car active))))
1611 ;; Then we want to peel off any elements that are higher
1612 ;; than the upper active limit.
1613 (let ((srange range))
1614 ;; Go past all valid elements.
1615 (while (and (cdr srange)
1616 (<= (or (and (atom (cadr srange))
1620 (setq srange (cdr srange)))
1622 ;; Nuke all remaining invalid elements.
1623 (setcdr srange nil))
1625 ;; Adjust the final element.
1626 (when (and (not (atom (car srange)))
1627 (> (cdar srange) (cdr active)))
1628 (setcdr (car srange) (cdr active))))
1629 ;; Compute the number of unread articles.
1631 (setq num (+ num (- (1+ (or (and (atom (car range)) (car range))
1633 (or (and (atom (car range)) (car range))
1635 (setq range (cdr range)))
1636 (setq num (max 0 (- (cdr active) num)))))
1637 ;; Set the number of unread articles.
1639 (gnus-group-entry (gnus-info-group info)))
1640 (setcar (gnus-group-entry (gnus-info-group info)) num))
1643 ;; Go though `gnus-newsrc-alist' and compare with `gnus-active-hashtb'
1644 ;; and compute how many unread articles there are in each group.
1645 (defun gnus-get-unread-articles (&optional level)
1646 (setq gnus-server-method-cache nil)
1647 (let* ((newsrc (cdr gnus-newsrc-alist))
1648 (level (or level gnus-activate-level (1+ gnus-level-subscribed)))
1651 (cond ((and gnus-activate-foreign-newsgroups
1652 (not (numberp gnus-activate-foreign-newsgroups)))
1653 (1+ gnus-level-subscribed))
1654 ((numberp gnus-activate-foreign-newsgroups)
1655 gnus-activate-foreign-newsgroups)
1660 scanned-methods info group active method retrieve-groups cmethod
1662 (gnus-message 6 "Checking new news...")
1665 (setq active (gnus-active (setq group (gnus-info-group
1666 (setq info (pop newsrc))))))
1668 ;; Check newsgroups. If the user doesn't want to check them, or
1669 ;; they can't be checked (for instance, if the news server can't
1670 ;; be reached) we just set the number of unread articles in this
1671 ;; newsgroup to t. This means that Gnus thinks that there are
1672 ;; unread articles, but it has no idea how many.
1674 ;; To be more explicit:
1675 ;; >0 for an active group with messages
1676 ;; 0 for an active group with no unread messages
1677 ;; nil for non-foreign groups that the user has requested not be checked
1678 ;; t for unchecked foreign groups or bogus groups, or groups that can't
1679 ;; be checked, for one reason or other.
1680 (when (setq method (gnus-info-method info))
1681 (if (setq cmethod (assoc method methods-cache))
1682 (setq method (cdr cmethod))
1683 (setq cmethod (inline (gnus-server-get-method nil method)))
1684 (push (cons method cmethod) methods-cache)
1685 (setq method cmethod)))
1687 (not (setq method-type (cdr (assoc method type-cache)))))
1690 ((gnus-secondary-method-p method)
1692 ((inline (gnus-server-equal gnus-select-method method))
1696 (push (cons method method-type) type-cache))
1698 (eq method-type 'foreign))
1699 ;; These groups are foreign. Check the level.
1700 (when (and (<= (gnus-info-level info) foreign-level)
1701 (setq active (gnus-activate-group group 'scan)))
1702 ;; Let the Gnus agent save the active file.
1703 (when (and gnus-agent active (gnus-online method))
1704 (gnus-agent-save-group-info
1705 method (gnus-group-real-name group) active))
1706 (unless (inline (gnus-virtual-group-p group))
1707 (inline (gnus-close-group group)))
1708 (when (fboundp (intern (concat (symbol-name (car method))
1709 "-request-update-info")))
1710 (inline (gnus-request-update-info info method))))
1711 ;; These groups are native or secondary.
1713 ;; We don't want these groups.
1714 ((> (gnus-info-level info) level)
1715 (setq active 'ignore))
1717 ((not gnus-read-active-file)
1718 (if (gnus-check-backend-function 'retrieve-groups group)
1719 ;; if server support gnus-retrieve-groups we push
1720 ;; the group onto retrievegroups for later checking
1721 (if (assoc method retrieve-groups)
1722 (setcdr (assoc method retrieve-groups)
1723 (cons group (cdr (assoc method retrieve-groups))))
1724 (push (list method group) retrieve-groups))
1725 ;; hack: `nnmail-get-new-mail' changes the mail-source depending
1726 ;; on the group, so we must perform a scan for every group
1727 ;; if the users has any directory mail sources.
1728 ;; hack: if `nnmail-scan-directory-mail-source-once' is non-nil,
1729 ;; for it scan all spool files even when the groups are
1732 (or nnmail-scan-directory-mail-source-once
1733 (null (assq 'directory
1735 (if (listp nnmail-spool-file)
1737 (list nnmail-spool-file))))))
1738 (member method scanned-methods))
1739 (setq active (gnus-activate-group group))
1740 (setq active (gnus-activate-group group 'scan))
1741 (push method scanned-methods))
1743 (gnus-close-group group))))))
1745 ;; Get the number of unread articles in the group.
1747 ((eq active 'ignore)
1748 ;; Don't do anything.
1751 (inline (gnus-get-unread-articles-in-group info active t)))
1753 ;; The group couldn't be reached, so we nix out the number of
1754 ;; unread articles and stuff.
1755 (gnus-set-active group nil)
1756 (let ((tmp (gnus-group-entry group)))
1760 ;; iterate through groups on methods which support gnus-retrieve-groups
1761 ;; and fetch a partial active file and use it to find new news.
1762 (dolist (rg retrieve-groups)
1763 (let ((method (or (car rg) gnus-select-method))
1765 (when (gnus-check-server method)
1766 ;; Request that the backend scan its incoming messages.
1767 (when (gnus-check-backend-function 'request-scan (car method))
1768 (gnus-request-scan nil method))
1769 (gnus-read-active-file-2
1770 (mapcar (lambda (group) (gnus-group-real-name group)) groups)
1772 (dolist (group groups)
1774 ((setq active (gnus-active (gnus-info-group
1775 (setq info (gnus-get-info group)))))
1776 (inline (gnus-get-unread-articles-in-group info active t)))
1778 ;; The group couldn't be reached, so we nix out the number of
1779 ;; unread articles and stuff.
1780 (gnus-set-active group nil)
1781 (setcar (gnus-group-entry group) t)))))))
1783 (gnus-message 6 "Checking new news...done")))
1785 ;; Create a hash table out of the newsrc alist. The `car's of the
1786 ;; alist elements are used as keys.
1787 (defun gnus-make-hashtable-from-newsrc-alist ()
1788 (let ((alist gnus-newsrc-alist)
1789 (ohashtb gnus-newsrc-hashtb)
1791 (setq gnus-newsrc-hashtb (gnus-make-hashtable (length alist)))
1793 (setq prev (setq gnus-newsrc-alist
1794 (if (equal (caar gnus-newsrc-alist)
1797 (cons (list "dummy.group" 0 nil) alist)))))
1801 ;; Preserve number of unread articles in groups.
1802 (cons (and ohashtb (car (gnus-gethash (caar alist) ohashtb)))
1806 alist (cdr alist)))))
1808 (defun gnus-make-hashtable-from-killed ()
1809 "Create a hash table from the killed and zombie lists."
1810 (let ((lists '(gnus-killed-list gnus-zombie-list))
1812 (setq gnus-killed-hashtb
1813 (gnus-make-hashtable
1814 (+ (length gnus-killed-list) (length gnus-zombie-list))))
1816 (setq list (symbol-value (pop lists)))
1818 (gnus-sethash (car list) (pop list) gnus-killed-hashtb)))))
1820 (defun gnus-parse-active ()
1821 "Parse active info in the nntp server buffer."
1823 (set-buffer nntp-server-buffer)
1824 (goto-char (point-min))
1825 ;; Parse the result we got from `gnus-request-group'.
1826 (when (looking-at "[0-9]+ [0-9]+ \\([0-9]+\\) [0-9]+")
1827 (goto-char (match-beginning 1))
1828 (cons (read (current-buffer))
1829 (read (current-buffer))))))
1831 (defun gnus-make-articles-unread (group articles)
1832 "Mark ARTICLES in GROUP as unread."
1833 (let* ((info (nth 2 (or (gnus-group-entry group)
1835 (gnus-group-real-name group)))))
1836 (ranges (gnus-info-read info))
1839 (when (gnus-member-of-range
1840 (setq article (pop articles)) ranges)
1841 (push article news)))
1843 ;; Enter this list into the group info.
1845 info (gnus-remove-from-range (gnus-info-read info) (nreverse news)))
1847 ;; Set the number of unread articles in gnus-newsrc-hashtb.
1848 (gnus-get-unread-articles-in-group info (gnus-active group))
1850 ;; Insert the change into the group buffer and the dribble file.
1851 (gnus-group-update-group group t))))
1853 (defun gnus-make-ascending-articles-unread (group articles)
1854 "Mark ascending ARTICLES in GROUP as unread."
1855 (let* ((entry (or (gnus-group-entry group)
1856 (gnus-group-entry (gnus-group-real-name group))))
1857 (info (nth 2 entry))
1858 (ranges (gnus-info-read info))
1863 (let ((article (pop articles))) ; get the next article to remove from ranges
1864 (while (let ((range (car ranges))) ; note the current range
1865 (if (atom range) ; single value range
1867 ;; the articles extend past the end of the ranges
1869 (setq articles nil))
1871 ;; this range preceeds the article. Leave the range unmodified.
1875 ;; this range exactly matches the article; REMOVE THE RANGE.
1876 ;; NOTE: When the range being removed is the last range, the list is corrupted by inserting null at its end.
1877 (setcar ranges (cadr ranges))
1878 (setcdr ranges (cddr ranges))
1879 (setq modified (if (car ranges) t 'remove-null))
1881 (let ((min (car range))
1883 ;; I have a min/max range to consider
1884 (cond ((> min max) ; invalid range introduced by splitter
1885 (setcar ranges (cadr ranges))
1886 (setcdr ranges (cddr ranges))
1887 (setq modified (if (car ranges) t 'remove-null))
1890 ;; replace min/max range with a single-value range
1894 ;; this range preceeds the article. Leave the range unmodified.
1898 ;; this article preceeds the range. Return null to move to the
1902 ;; this article splits the range into two parts
1903 (setcdr ranges (cons (cons (1+ article) max) (cdr ranges)))
1904 (setcdr range (1- article))
1909 (when (eq modified 'remove-null)
1910 (setq r (delq nil r)))
1911 ;; Enter this list into the group info.
1912 (gnus-info-set-read info r)
1914 ;; Set the number of unread articles in gnus-newsrc-hashtb.
1915 (gnus-get-unread-articles-in-group info (gnus-active group))
1917 ;; Insert the change into the group buffer and the dribble file.
1918 (gnus-group-update-group group t))))
1920 ;; Enter all dead groups into the hashtb.
1921 (defun gnus-update-active-hashtb-from-killed ()
1922 (let ((hashtb (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
1923 (lists (list gnus-killed-list gnus-zombie-list))
1926 (setq killed (car lists))
1928 (gnus-sethash (car killed) nil hashtb)
1929 (setq killed (cdr killed)))
1930 (setq lists (cdr lists)))))
1932 (defun gnus-get-killed-groups ()
1933 "Go through the active hashtb and mark all unknown groups as killed."
1934 ;; First make sure active file has been read.
1935 (unless (gnus-read-active-file-p)
1936 (let ((gnus-read-active-file t))
1937 (gnus-read-active-file)))
1938 (unless gnus-killed-hashtb
1939 (gnus-make-hashtable-from-killed))
1940 ;; Go through all newsgroups that are known to Gnus - enlarge kill list.
1944 (group (symbol-name sym)))
1945 (if (or (null group)
1946 (gnus-gethash group gnus-killed-hashtb)
1947 (gnus-gethash group gnus-newsrc-hashtb))
1949 (let ((do-sub (gnus-matches-options-n group)))
1950 (if (or (eq do-sub 'subscribe) (eq do-sub 'ignore))
1952 (setq groups (1+ groups))
1953 (push group gnus-killed-list)
1954 (gnus-sethash group group gnus-killed-hashtb))))))
1956 (gnus-dribble-touch))
1958 ;; Get the active file(s) from the backend(s).
1959 (defun gnus-read-active-file (&optional force not-native)
1960 (gnus-group-set-mode-line)
1963 (lambda (m) (if (stringp m) (gnus-server-get-method nil m) m))
1965 (if (and (not not-native)
1966 (gnus-check-server gnus-select-method))
1967 ;; The native server is available.
1968 (cons gnus-select-method gnus-secondary-select-methods)
1969 ;; The native server is down, so we just do the
1971 gnus-secondary-select-methods)
1972 ;; Also read from the archive server.
1973 (when (gnus-archive-server-wanted-p)
1974 (list "archive")))))
1976 (setq gnus-have-read-active-file nil)
1978 (set-buffer nntp-server-buffer)
1979 (while (setq method (pop methods))
1980 ;; Only do each method once, in case the methods appear more
1981 ;; than once in this list.
1982 (unless (member method methods)
1983 (if (or debug-on-error debug-on-quit)
1984 (gnus-read-active-file-1 method force)
1986 (gnus-read-active-file-1 method force)
1987 ;; We catch C-g so that we can continue past servers
1988 ;; that do not respond.
1990 (message "Quit reading the active file")
1993 (defun gnus-read-active-file-1 (method force)
1995 (setq where (nth 1 method)
1996 mesg (format "Reading active file%s via %s..."
1997 (if (and where (not (zerop (length where))))
1998 (concat " from " where) "")
2000 (gnus-message 5 mesg)
2001 (when (gnus-check-server method)
2002 ;; Request that the backend scan its incoming messages.
2003 (when (gnus-check-backend-function 'request-scan (car method))
2004 (gnus-request-scan nil method))
2006 ((and (eq gnus-read-active-file 'some)
2007 (gnus-check-backend-function 'retrieve-groups (car method))
2009 (let ((newsrc (cdr gnus-newsrc-alist))
2010 (gmethod (gnus-server-get-method nil method))
2012 (while (setq info (pop newsrc))
2016 (gnus-find-method-for-group
2017 (gnus-info-group info) info))
2019 (push (gnus-group-real-name (gnus-info-group info))
2021 (gnus-read-active-file-2 groups method)))
2025 (if (not (gnus-request-list method))
2026 (unless (equal method gnus-message-archive-method)
2027 (gnus-error 1 "Cannot read active file from %s server"
2029 (gnus-message 5 mesg)
2030 (gnus-active-to-gnus-format method gnus-active-hashtb nil t)
2031 ;; We mark this active file as read.
2032 (push method gnus-have-read-active-file)
2033 (gnus-message 5 "%sdone" mesg)))))))
2035 (defun gnus-read-active-file-2 (groups method)
2036 "Read an active file for GROUPS in METHOD using `gnus-retrieve-groups'."
2039 (set-buffer nntp-server-buffer)
2040 (gnus-check-server method)
2041 (let ((list-type (gnus-retrieve-groups groups method)))
2042 (cond ((not list-type)
2044 1.2 "Cannot read partial active file from %s server."
2046 ((eq list-type 'active)
2047 (gnus-active-to-gnus-format method gnus-active-hashtb nil t))
2049 (gnus-groups-to-gnus-format method gnus-active-hashtb t)))))))
2051 ;; Read an active file and place the results in `gnus-active-hashtb'.
2052 (defun gnus-active-to-gnus-format (&optional method hashtb ignore-errors
2055 (setq method gnus-select-method))
2056 (let ((cur (current-buffer))
2058 (if (and gnus-active-hashtb
2059 (not (equal method gnus-select-method)))
2061 (setq gnus-active-hashtb
2062 (if (equal method gnus-select-method)
2063 (gnus-make-hashtable
2064 (count-lines (point-min) (point-max)))
2065 (gnus-make-hashtable 4096)))))))
2066 ;; Delete unnecessary lines.
2067 (goto-char (point-min))
2069 ((string= gnus-ignored-newsgroups "")
2070 (delete-matching-lines "^to\\."))
2072 (delete-matching-lines (concat "^to\\.\\|" gnus-ignored-newsgroups))))
2074 (goto-char (point-min))
2075 (unless (re-search-forward "[\\\"]" nil t)
2076 ;; Make the group names readable as a lisp expression even if they
2077 ;; contain special characters.
2078 (goto-char (point-max))
2079 (while (re-search-backward "[][';?()#]" nil t)
2082 ;; Let the Gnus agent save the active file.
2083 (when (and gnus-agent real-active (gnus-online method))
2084 (gnus-agent-save-active method))
2086 ;; If these are groups from a foreign select method, we insert the
2087 ;; group prefix in front of the group names.
2088 (when (not (gnus-server-equal
2089 (gnus-server-get-method nil method)
2090 (gnus-server-get-method nil gnus-select-method)))
2091 (let ((prefix (gnus-group-prefixed-name "" method)))
2092 (goto-char (point-min))
2093 (while (and (not (eobp))
2095 (when (= (following-char) ?\")
2098 (zerop (forward-line 1)))))))
2099 ;; Store the active file in a hash table.
2100 (goto-char (point-min))
2101 (let (group max min)
2105 (narrow-to-region (point) (point-at-eol))
2106 ;; group gets set to a symbol interned in the hash table
2107 ;; (what a hack!!) - jwz
2108 (setq group (let ((obarray hashtb)) (read cur)))
2109 ;; ### The extended group name scheme makes
2110 ;; the previous optimization strategy sort of pointless...
2111 (when (stringp group)
2112 (setq group (intern group hashtb)))
2113 (if (and (numberp (setq max (read cur)))
2114 (numberp (setq min (read cur)))
2116 (skip-chars-forward " \t")
2118 (or (eq (char-after) ?=)
2119 (eq (char-after) ?x)
2120 (eq (char-after) ?j)))))
2122 (set group (cons min max))
2123 ;; if group is moderated, stick in moderation table
2124 (when (eq (char-after) ?m)
2125 (unless gnus-moderated-hashtb
2126 (setq gnus-moderated-hashtb (gnus-make-hashtable)))
2127 (gnus-sethash (symbol-name group) t
2128 gnus-moderated-hashtb)))
2134 (unless ignore-errors
2135 (gnus-message 3 "Warning - invalid active: %s"
2137 (point-at-bol) (point-at-eol))))))
2139 (forward-line 1)))))
2141 (defun gnus-groups-to-gnus-format (method &optional hashtb real-active)
2142 ;; Parse a "groups" active file.
2143 (let ((cur (current-buffer))
2145 (if (and method gnus-active-hashtb)
2147 (setq gnus-active-hashtb
2148 (gnus-make-hashtable
2149 (count-lines (point-min) (point-max)))))))
2151 (not (gnus-server-equal
2152 (gnus-server-get-method nil method)
2153 (gnus-server-get-method nil gnus-select-method)))
2154 (gnus-group-prefixed-name "" method))))
2156 ;; Let the Gnus agent save the active file.
2159 (gnus-online method)
2160 (gnus-agent-method-p method))
2162 (gnus-agent-save-active method)
2163 (gnus-active-to-gnus-format method hashtb nil real-active))
2165 (goto-char (point-min))
2166 ;; We split this into to separate loops, one with the prefix
2167 ;; and one without to speed the reading up somewhat.
2169 (let (min max opoint group)
2173 (read cur) (read cur)
2174 (setq min (read cur)
2177 (skip-chars-forward " \t")
2180 (set (let ((obarray hashtb)) (read cur))
2182 (error (and group (symbolp group) (set group nil))))
2184 (let (min max group)
2187 (when (eq (char-after) ?2)
2188 (read cur) (read cur)
2189 (setq min (read cur)
2191 (set (setq group (let ((obarray hashtb)) (read cur)))
2193 (error (and group (symbolp group) (set group nil))))
2194 (forward-line 1)))))))
2196 (defun gnus-read-newsrc-file (&optional force)
2198 If FORCE is non-nil, the .newsrc file is read."
2199 ;; Reset variables that might be defined in the .newsrc.eld file.
2200 (gnus-clear-quick-file-variables)
2201 (let* ((newsrc-file gnus-current-startup-file)
2202 (quick-file (concat newsrc-file ".el")))
2204 ;; We always load the .newsrc.eld file. If always contains
2205 ;; much information that can not be gotten from the .newsrc
2206 ;; file (ticked articles, killed groups, foreign methods, etc.)
2207 (gnus-read-newsrc-el-file quick-file)
2209 (when (and gnus-read-newsrc-file
2210 (file-exists-p gnus-current-startup-file)
2212 (and (file-newer-than-file-p newsrc-file quick-file)
2213 (file-newer-than-file-p newsrc-file
2214 (concat quick-file "d")))
2215 (not gnus-newsrc-alist)))
2216 ;; We read the .newsrc file. Note that if there if a
2217 ;; .newsrc.eld file exists, it has already been read, and
2218 ;; the `gnus-newsrc-hashtb' has been created. While reading
2219 ;; the .newsrc file, Gnus will only use the information it
2220 ;; can find there for changing the data already read -
2221 ;; i. e., reading the .newsrc file will not trash the data
2222 ;; already read (except for read articles).
2224 (gnus-message 5 "Reading %s..." newsrc-file)
2225 (set-buffer (nnheader-find-file-noselect newsrc-file))
2226 (buffer-disable-undo)
2227 (gnus-newsrc-to-gnus-format)
2228 (kill-buffer (current-buffer))
2229 (gnus-message 5 "Reading %s...done" newsrc-file))))))
2231 (quote (;; T-gnus doesn't provide those functions.
2232 (defun gnus-convert-old-newsrc ()
2233 "Convert old newsrc formats into the current format, if needed."
2234 (let ((fcv (and gnus-newsrc-file-version
2235 (gnus-continuum-version gnus-newsrc-file-version))))
2237 ;; A .newsrc.eld file was loaded.
2238 (let (prompt-displayed
2241 (mapcar (lambda (date-func)
2242 (cons (gnus-continuum-version (car date-func))
2244 ;; This is a list of converters that must be run
2245 ;; to bring the newsrc file up to the current
2246 ;; version. If you create an incompatibility
2247 ;; with older versions, you should create an
2248 ;; entry here. The entry should consist of the
2249 ;; current gnus version (hardcoded so that it
2250 ;; doesn't change with each release) and the
2251 ;; function that must be applied to convert the
2252 ;; previous version into the current version.
2253 '(("September Gnus v0.1" nil
2254 gnus-convert-old-ticks)
2255 ("Oort Gnus v0.08" "legacy-gnus-agent"
2256 gnus-agent-convert-to-compressed-agentview)
2257 ("No Gnus v0.2" "legacy-gnus-agent"
2258 gnus-agent-unlist-expire-days)
2259 ("No Gnus v0.2" "legacy-gnus-agent"
2260 gnus-agent-unhook-expire-days)))
2261 #'car-less-than-car)))
2262 ;; Skip converters older than the file version
2263 (while (and converters (>= fcv (caar converters)))
2266 ;; Perform converters to bring older version up to date.
2267 (while (and converters (< fcv (caar converters)))
2268 (let* ((converter-spec (pop converters))
2269 (convert-to (nth 1 converter-spec))
2270 (load-from (nth 2 converter-spec))
2271 (func (nth 3 converter-spec)))
2272 (when (and load-from
2273 (not (fboundp func)))
2276 (or prompt-displayed
2277 (not (gnus-convert-converter-needs-prompt func))
2279 (cursor-in-echo-area t)
2280 (echo-keystrokes 0))
2281 (message "Convert newsrc from version '%s' to '%s'? (n/y/?)"
2282 gnus-newsrc-file-version gnus-version)
2283 (setq c (read-char-exclusive))
2285 (cond ((or (eq c ?n) (eq c ?N))
2286 (error "Can not start gnus using old (unconverted) newsrc"))
2287 ((or (eq c ?y) (eq c ?Y))
2288 (setq prompt-displayed t)
2291 (message "This conversion is irreversible. \
2292 You should backup your files before proceeding.")
2296 (gnus-message 3 "Ignoring unexpected input")
2300 (funcall func convert-to)))
2302 (format ";Converted newsrc from version '%s' to '%s'? (n/y/?)"
2303 gnus-newsrc-file-version gnus-version))))))
2305 (defun gnus-convert-mark-converter-prompt (converter no-prompt)
2307 (let* ((symbol 'gnus-convert-no-prompt)
2308 (value (delq symbol (symbol-plist converter))))
2313 (defun gnus-convert-converter-needs-prompt (converter)
2314 (not (memq 'gnus-convert-no-prompt (symbol-plist converter))))
2316 (defun gnus-convert-old-ticks (converting-to)
2317 (let ((newsrc (cdr gnus-newsrc-alist))
2318 marks info dormant ticked)
2319 (while (setq info (pop newsrc))
2320 (when (setq marks (gnus-info-marks info))
2321 (setq dormant (cdr (assq 'dormant marks))
2322 ticked (cdr (assq 'tick marks)))
2323 (when (or dormant ticked)
2327 (gnus-info-read info)
2328 (nconc (gnus-uncompress-range dormant)
2329 (gnus-uncompress-range ticked)))))))))
2332 (defun gnus-load (file &optional coding-system)
2333 "Load FILE, but in such a way that read errors can be reported."
2336 (insert-file-contents-as-coding-system coding-system file)
2337 (insert-file-contents file))
2339 (condition-case type
2340 (let ((form (read (current-buffer))))
2343 (unless (eq (car type) 'end-of-file)
2344 (let ((error (format "Error in %s line %d" file
2345 (count-lines (point-min) (point)))))
2347 (unless (gnus-yes-or-no-p (concat error "; continue? "))
2348 (error "%s" error)))))))))
2350 (defun gnus-read-newsrc-el-file (file)
2351 (let ((ding-file (concat file "d")))
2352 (when (file-exists-p ding-file)
2353 ;; We always, always read the .eld file.
2354 (gnus-message 5 "Reading %s..." ding-file)
2355 (let (gnus-newsrc-assoc)
2356 (gnus-load ding-file gnus-ding-file-coding-system)
2357 ;; ;; Older versions of `gnus-format-specs' are no longer valid
2358 ;; ;; in Oort Gnus 0.01.
2360 ;; (and gnus-newsrc-file-version
2361 ;; (gnus-continuum-version gnus-newsrc-file-version))))
2362 ;; (when (or (not version)
2363 ;; (< version 5.090009))
2364 ;; (setq gnus-format-specs gnus-default-format-specs)))
2365 (when gnus-newsrc-assoc
2366 (setq gnus-newsrc-alist gnus-newsrc-assoc))))
2367 (gnus-make-hashtable-from-newsrc-alist)
2368 (when (file-newer-than-file-p file ding-file)
2369 ;; Old format quick file
2370 (gnus-message 5 "Reading %s..." file)
2371 ;; The .el file is newer than the .eld file, so we read that one
2373 (gnus-read-old-newsrc-el-file file)))
2374 (when (and gnus-product-directory
2375 (file-directory-p gnus-product-directory))
2376 (let ((list gnus-product-variable-file-list))
2378 (apply 'gnus-product-read-variable-file-1 (car list))
2379 (setq list (cdr list)))))
2380 (gnus-run-hooks 'gnus-read-newsrc-el-hook))
2382 ;;(defun gnus-re-read-newsrc-el-file (file)
2383 ;; "Attempt to re-read .newsrc.eld file. Returns nil if successful.
2384 ;;The backup file \".newsrc.eld_\" will be created before re-reading."
2385 ;; (message "Error in %s; retrying..." file)
2387 ;; (condition-case nil
2388 ;; (let ((backup (concat file "_")))
2389 ;; (copy-file file backup 'ok-if-already-exists 'keep-time)
2390 ;; (message " (The backup file %s has been created)" backup)
2394 ;; (insert-file-contents-as-binary file nil nil nil 'replace)
2395 ;; (goto-char (point-min))
2396 ;; (when (re-search-forward
2397 ;; "^[\t ]*([\t\n\r ]*setq[\t\n\r ]+gnus-format-specs" nil t)
2398 ;; (delete-region (goto-char (match-beginning 0)) (forward-list 1))
2399 ;; (decode-coding-region (point-min) (point-max)
2400 ;; gnus-ding-file-coding-system)
2401 ;; (condition-case nil
2403 ;; (eval-region (point-min) (point-max))
2408 ;; (message "Error in %s; retrying...done" file))
2409 ;; (message "Error in %s; retrying...failed" file)
2412 (defun gnus-product-read-variable-file-1 (file checking-methods coding
2414 (let (error gnus-product-file-version method file-ver)
2415 (when (or (condition-case err
2416 (let ((coding-system-for-read coding))
2417 (load (expand-file-name file gnus-product-directory)
2421 (message "Error while reading %s: %s"
2422 (expand-file-name file gnus-product-directory)
2423 (error-message-string err))
2425 (and (setq method (assq 'product-version checking-methods))
2426 (not (and (setq file-ver
2427 (cdr (assq 'product-version
2428 gnus-product-file-version)))
2429 (zerop (product-version-compare file-ver
2431 (and (assq 'emacs-version checking-methods)
2432 (not (and (assq 'emacs-version gnus-product-file-version)
2435 (cdr (assq 'emacs-version
2436 gnus-product-file-version))))))
2437 (and (assq 'correct-string-widths checking-methods)
2438 (not (and (assq 'correct-string-widths
2439 gnus-product-file-version)
2440 (eq (and gnus-use-correct-string-widths t)
2441 (and (cdr (assq 'correct-string-widths
2442 gnus-product-file-version))
2445 (message "\"%s\" seems to have mismatched contents, updating..."
2448 (set (car variables) nil)
2449 (gnus-product-variable-touch (car variables))
2450 (setq variables (cdr variables))))))
2452 ;; Parse the old-style quick startup file
2453 (defun gnus-read-old-newsrc-el-file (file)
2454 (let (newsrc killed marked group m info)
2456 (let ((gnus-killed-assoc nil)
2457 gnus-marked-assoc gnus-newsrc-alist gnus-newsrc-assoc)
2461 (setq newsrc gnus-newsrc-assoc
2462 killed gnus-killed-assoc
2463 marked gnus-marked-assoc)))
2464 (setq gnus-newsrc-alist nil)
2465 (while (setq group (pop newsrc))
2466 (if (setq info (gnus-get-info (car group)))
2468 (gnus-info-set-read info (cddr group))
2469 (gnus-info-set-level
2470 info (if (nth 1 group) gnus-level-default-subscribed
2471 gnus-level-default-unsubscribed))
2472 (push info gnus-newsrc-alist))
2475 (if (nth 1 group) gnus-level-default-subscribed
2476 gnus-level-default-unsubscribed)
2479 ;; Copy marks into info.
2480 (when (setq m (assoc (car group) marked))
2481 (unless (nthcdr 3 info)
2482 (nconc info (list nil)))
2483 (gnus-info-set-marks
2484 info (list (cons 'tick (gnus-compress-sequence
2485 (sort (cdr m) '<) t))))))
2486 (setq newsrc killed)
2488 (setcar newsrc (caar newsrc))
2489 (setq newsrc (cdr newsrc)))
2490 (setq gnus-killed-list killed))
2491 ;; The .el file version of this variable does not begin with
2492 ;; "options", while the .eld version does, so we just add it if it
2496 (when (not (string-match "^ *options" gnus-newsrc-options))
2497 (setq gnus-newsrc-options (concat "options " gnus-newsrc-options)))
2498 (when (not (string-match "\n$" gnus-newsrc-options))
2499 (setq gnus-newsrc-options (concat gnus-newsrc-options "\n")))
2500 ;; Finally, if we read some options lines, we parse them.
2501 (unless (string= gnus-newsrc-options "")
2502 (gnus-newsrc-parse-options gnus-newsrc-options)))
2504 (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist))
2505 (gnus-make-hashtable-from-newsrc-alist)))
2507 (defun gnus-make-newsrc-file (file)
2508 "Make server dependent file name by catenating FILE and server host name."
2509 (let* ((file (expand-file-name file nil))
2510 (real-file (concat file "-" (nth 1 gnus-select-method))))
2511 (if (or (file-exists-p real-file)
2512 (file-exists-p (concat real-file ".el"))
2513 (file-exists-p (concat real-file ".eld")))
2517 (defun gnus-newsrc-to-gnus-format ()
2518 (setq gnus-newsrc-options "")
2519 (setq gnus-newsrc-options-n nil)
2521 (unless gnus-active-hashtb
2522 (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
2523 (let ((buf (current-buffer))
2524 (already-read (> (length gnus-newsrc-alist) 1))
2525 group subscribed options-symbol newsrc Options-symbol
2527 (goto-char (point-min))
2528 ;; We intern the symbol `options' in the active hashtb so that we
2529 ;; can `eq' against it later.
2530 (set (setq options-symbol (intern "options" gnus-active-hashtb)) nil)
2531 (set (setq Options-symbol (intern "Options" gnus-active-hashtb)) nil)
2534 ;; We first read the first word on the line by narrowing and
2535 ;; then reading into `gnus-active-hashtb'. Most groups will
2536 ;; already exist in that hashtb, so this will save some string
2540 (progn (skip-chars-forward "^ \t!:\n") (point)))
2541 (goto-char (point-min))
2543 (and (/= (point-min) (point-max))
2544 (let ((obarray gnus-active-hashtb)) (read buf))))
2546 ;; Now, the symbol we have read is either `options' or a group
2547 ;; name. If it is an options line, we just add it to a string.
2549 ((or (eq symbol options-symbol)
2550 (eq symbol Options-symbol))
2551 (setq gnus-newsrc-options
2552 ;; This concating is quite inefficient, but since our
2553 ;; thorough studies show that approx 99.37% of all
2554 ;; .newsrc files only contain a single options line, we
2555 ;; don't give a damn, frankly, my dear.
2556 (concat gnus-newsrc-options
2559 ;; Options may continue on the next line.
2560 (or (and (re-search-forward "^[^ \t]" nil 'move)
2565 ;; Group names can be just numbers.
2566 (when (numberp symbol)
2567 (setq symbol (intern (int-to-string symbol) gnus-active-hashtb)))
2568 (unless (boundp symbol)
2570 ;; It was a group name.
2571 (setq subscribed (eq (char-after) ?:)
2572 group (symbol-name symbol)
2575 ;; If the line ends here, this is clearly a buggy line, so
2576 ;; we put point a the beginning of line and let the cond
2577 ;; below do the error handling.
2579 ;; We skip to the beginning of the ranges.
2580 (skip-chars-forward "!: \t"))
2581 ;; We are now at the beginning of the list of read articles.
2582 ;; We read them range by range.
2585 ((looking-at "[0-9]+")
2586 ;; We narrow and read a number instead of buffer-substring/
2587 ;; string-to-int because it's faster. narrow/widen is
2588 ;; faster than save-restriction/narrow, and save-restriction
2589 ;; produces a garbage object.
2591 (narrow-to-region (match-beginning 0) (match-end 0))
2594 ;; If the next character is a dash, then this is a range.
2595 (if (eq (char-after) ?-)
2597 ;; We read the upper bound of the range.
2599 (if (not (looking-at "[0-9]+"))
2600 ;; This is a buggy line, by we pretend that
2601 ;; it's kinda OK. Perhaps the user should be
2607 (narrow-to-region (match-beginning 0)
2612 ;; It was just a simple number, so we add it to the
2615 ;; If the next char in ?\n, then we have reached the end
2616 ;; of the line and return nil.
2617 (not (eq (char-after) ?\n)))
2618 ((eq (char-after) ?\n)
2619 ;; End of line, so we end.
2622 ;; Not numbers and not eol, so this might be a buggy
2625 ;; If it was eob instead of ?\n, we allow it.
2626 ;; The line was buggy.
2628 (gnus-error 3.1 "Mangled line: %s"
2629 (buffer-substring (point-at-bol)
2632 ;; Skip past ", ". Spaces are invalid in these ranges, but
2633 ;; we allow them, because it's a common mistake to put a
2634 ;; space after the comma.
2635 (skip-chars-forward ", "))
2637 ;; We have already read .newsrc.eld, so we gently update the
2638 ;; data in the hash table with the information we have just
2641 (let ((info (gnus-get-info group))
2644 ;; There is an entry for this file in the alist.
2646 (gnus-info-set-read info (nreverse reads))
2647 ;; We update the level very gently. In fact, we
2648 ;; only change it if there's been a status change
2649 ;; from subscribed to unsubscribed, or vice versa.
2650 (setq level (gnus-info-level info))
2651 (cond ((and (<= level gnus-level-subscribed)
2653 (setq level (if reads
2654 gnus-level-default-unsubscribed
2655 (1+ gnus-level-default-unsubscribed))))
2656 ((and (> level gnus-level-subscribed) subscribed)
2657 (setq level gnus-level-default-subscribed)))
2658 (gnus-info-set-level info level))
2659 ;; This is a new group.
2660 (setq info (list group
2662 gnus-level-default-subscribed
2664 (1+ gnus-level-subscribed)
2665 gnus-level-default-unsubscribed))
2667 (push info newsrc)))))
2670 (setq newsrc (nreverse newsrc))
2672 (if (not already-read)
2674 ;; We now have two newsrc lists - `newsrc', which is what we
2675 ;; have read from .newsrc, and `gnus-newsrc-alist', which is
2676 ;; what we've read from .newsrc.eld. We have to merge these
2677 ;; lists. We do this by "attaching" any (foreign) groups in the
2678 ;; gnus-newsrc-alist to the (native) group that precedes them.
2679 (let ((rc (cdr gnus-newsrc-alist))
2680 (prev gnus-newsrc-alist)
2683 (or (null (nth 4 (car rc))) ; It's a native group.
2684 (assoc (caar rc) newsrc) ; It's already in the alist.
2685 (if (setq entry (assoc (caar prev) newsrc))
2686 (setcdr (setq mentry (memq entry newsrc))
2687 (cons (car rc) (cdr mentry)))
2688 (push (car rc) newsrc)))
2692 (setq gnus-newsrc-alist newsrc)
2693 ;; We make the newsrc hashtb.
2694 (gnus-make-hashtable-from-newsrc-alist)
2696 ;; Finally, if we read some options lines, we parse them.
2697 (unless (string= gnus-newsrc-options "")
2698 (gnus-newsrc-parse-options gnus-newsrc-options))))
2700 ;; Parse options lines to find "options -n !all rec.all" and stuff.
2701 ;; The return value will be a list on the form
2702 ;; ((regexp1 . ignore)
2703 ;; (regexp2 . subscribe)...)
2704 ;; When handling new newsgroups, groups that match a `ignore' regexp
2705 ;; will be ignored, and groups that match a `subscribe' regexp will be
2706 ;; subscribed. A line like
2707 ;; options -n !all rec.all
2708 ;; will lead to a list that looks like
2709 ;; (("^rec\\..+" . subscribe)
2710 ;; ("^.+" . ignore))
2711 ;; So all "rec.*" groups will be subscribed, while all the other
2712 ;; groups will be ignored. Note that "options -n !all rec.all" is very
2713 ;; different from "options -n rec.all !all".
2714 (defun gnus-newsrc-parse-options (options)
2717 (gnus-set-work-buffer)
2718 (insert (regexp-quote options))
2719 ;; First we treat all continuation lines.
2720 (goto-char (point-min))
2721 (while (re-search-forward "\n[ \t]+" nil t)
2722 (replace-match " " t t))
2723 ;; Then we transform all "all"s into ".+"s.
2724 (goto-char (point-min))
2725 (while (re-search-forward "\\ball\\b" nil t)
2726 (replace-match ".+" t t))
2727 (goto-char (point-min))
2728 ;; We remove all other options than the "-n" ones.
2729 (while (re-search-forward "[ \t]-[^n][^-]*" nil t)
2732 (goto-char (point-min))
2734 ;; We are only interested in "options -n" lines - we
2735 ;; ignore the other option lines.
2736 (while (re-search-forward "[ \t]-n" nil t)
2739 (and (re-search-forward "[ \t]-n" (point-at-eol) t)
2742 ;; Search for all "words"...
2743 (while (re-search-forward "[^ \t,\n]+" eol t)
2744 (if (eq (char-after (match-beginning 0)) ?!)
2745 ;; If the word begins with a bang (!), this is a "not"
2746 ;; spec. We put this spec (minus the bang) and the
2747 ;; symbol `ignore' into the list.
2749 "^" (buffer-substring
2750 (1+ (match-beginning 0))
2755 ;; There was no bang, so this is a "yes" spec.
2756 (push (cons (concat "^" (match-string 0) "\\($\\|\\.\\)")
2760 (setq gnus-newsrc-options-n out))))
2763 (defalias 'gnus-long-file-names
2764 (if (fboundp 'msdos-long-file-names)
2765 'msdos-long-file-names
2768 (defun gnus-save-newsrc-file (&optional force)
2769 "Save .newsrc file."
2770 ;; Note: We cannot save .newsrc file if all newsgroups are removed
2771 ;; from the variable gnus-newsrc-alist.
2772 (when (and (or gnus-newsrc-alist gnus-killed-list)
2773 gnus-current-startup-file)
2774 ;; Save agent range limits for the currently active method.
2776 (gnus-agent-save-local force))
2779 (if (and (or gnus-use-dribble-file gnus-slave)
2781 (or (not gnus-dribble-buffer)
2782 (not (buffer-name gnus-dribble-buffer))
2783 (zerop (save-excursion
2784 (set-buffer gnus-dribble-buffer)
2786 (gnus-message 4 "(No changes need to be saved)")
2787 (gnus-run-hooks 'gnus-save-newsrc-hook)
2789 (gnus-slave-save-newsrc)
2791 (when gnus-save-newsrc-file
2792 (gnus-message 8 "Saving %s..." gnus-current-startup-file)
2793 (gnus-gnus-to-newsrc-format)
2794 (gnus-message 8 "Saving %s...done" gnus-current-startup-file))
2796 ;; Save .newsrc.eld.
2797 (set-buffer (gnus-get-buffer-create " *Gnus-newsrc*"))
2798 (make-local-variable 'version-control)
2799 (setq version-control gnus-backup-startup-file)
2800 (setq buffer-file-name
2801 (concat gnus-current-startup-file ".eld"))
2802 (setq default-directory (file-name-directory buffer-file-name))
2803 (buffer-disable-undo)
2805 (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file)
2807 (if gnus-save-startup-file-via-temp-buffer
2808 (let ((coding-system-for-write gnus-ding-file-coding-system)
2809 (standard-output (current-buffer)))
2810 (gnus-gnus-to-quick-newsrc-format)
2811 (gnus-run-hooks 'gnus-save-quick-newsrc-hook)
2813 (let ((coding-system-for-write gnus-ding-file-coding-system)
2814 (version-control gnus-backup-startup-file)
2815 (startup-file (concat gnus-current-startup-file ".eld"))
2816 (working-dir (file-name-directory gnus-current-startup-file))
2819 ;; Generate the name of a non-existent file.
2820 (while (progn (setq working-file
2822 (if (and (eq system-type 'ms-dos)
2823 (not (gnus-long-file-names)))
2824 "%s#%d.tm#" ; MSDOS limits files to 8+3
2825 (if (memq system-type '(vax-vms axp-vms))
2828 working-dir (setq i (1+ i))))
2829 (file-exists-p working-file)))
2833 (gnus-with-output-to-file working-file
2834 (gnus-gnus-to-quick-newsrc-format)
2835 (gnus-run-hooks 'gnus-save-quick-newsrc-hook))
2837 ;; These bindings will mislead the current buffer
2838 ;; into thinking that it is visiting the startup
2840 (let ((buffer-backed-up nil)
2841 (buffer-file-name startup-file)
2842 (file-precious-flag t)
2843 (setmodes (file-modes startup-file)))
2844 ;; Backup the current version of the startup file.
2847 ;; Replace the existing startup file with the temp file.
2848 (rename-file working-file startup-file t)
2849 (set-file-modes startup-file setmodes)))
2851 (delete-file working-file)
2852 (file-error nil)))))
2854 (gnus-kill-buffer (current-buffer))
2856 5 "Saving %s.eld...done" gnus-current-startup-file))
2857 (gnus-dribble-delete-file)
2858 (gnus-group-set-mode-line))))
2859 (when gnus-product-directory
2860 (gnus-product-save-variable-file)))
2862 ;; Call the function above at C-x C-c.
2863 (defadvice save-buffers-kill-emacs (before save-gnus-newsrc-file-maybe
2864 activate preactivate)
2865 "Save .newsrc and .newsrc.eld when Emacs is killed."
2866 (when (gnus-alive-p)
2867 (gnus-run-hooks 'gnus-exit-gnus-hook)
2868 (gnus-offer-save-summaries)
2869 (gnus-save-newsrc-file)))
2871 (defun gnus-gnus-to-quick-newsrc-format (&optional minimal name &rest specific-variables)
2872 "Print Gnus variables such as `gnus-newsrc-alist' in Lisp format."
2873 (princ ";; -*- emacs-lisp -*-\n")
2875 (princ (format ";; %s\n" name))
2876 (princ ";; Gnus startup file.\n"))
2880 ;; Never delete this file -- if you want to force Gnus to read the
2881 ;; .newsrc file (if you have one), touch .newsrc instead.\n")
2882 (princ "(setq gnus-newsrc-file-version ")
2883 (princ (gnus-prin1-to-string gnus-version))
2886 (let* ((print-quoted t)
2888 (print-escape-multibyte nil)
2889 (print-escape-nonascii t)
2892 (print-escape-newlines t)
2894 (if (and gnus-save-killed-list
2895 (stringp gnus-save-killed-list))
2896 (gnus-strip-killed-list)
2899 (or specific-variables
2900 (if gnus-save-killed-list gnus-variable-list
2901 ;; Remove the `gnus-killed-list' from the list of variables
2902 ;; to be saved, if required.
2903 (delq 'gnus-killed-list (copy-sequence gnus-variable-list)))))
2904 ;; Peel off the "dummy" group.
2905 (gnus-newsrc-alist (cdr gnus-newsrc-alist))
2907 ;; Insert the variables into the file.
2909 (when (and (boundp (setq variable (pop variables)))
2910 (symbol-value variable))
2912 (princ (symbol-name variable))
2914 (prin1 (symbol-value variable))
2917 (defun gnus-product-variable-touch (&rest variables)
2919 (put (pop variables) 'gnus-product-variable 'dirty)))
2921 (defun gnus-product-variables-dirty-p (variables)
2924 (when (eq (get (car variables) 'gnus-product-variable) 'dirty)
2926 (setq variables (cdr variables)))))
2928 (defun gnus-product-save-variable-file (&optional force)
2929 "Save all product variables to files, when need to be saved."
2930 (let ((list gnus-product-variable-file-list))
2931 (gnus-make-directory gnus-product-directory)
2933 (apply 'gnus-product-save-variable-file-1 force (car list))
2934 (setq list (cdr list)))))
2936 (defun gnus-product-save-variable-file-1 (force file checking-methods coding
2938 "Save a product variable file, when need to be saved."
2940 (gnus-product-variables-dirty-p variables))
2941 (let ((product (product-find 'gnus-vers)))
2942 (set-buffer (gnus-get-buffer-create " *gnus-product*"))
2943 (make-local-variable 'version-control)
2944 (setq version-control 'never)
2945 (setq file (expand-file-name file gnus-product-directory)
2946 buffer-file-name file
2947 default-directory (file-name-directory file))
2948 (buffer-disable-undo)
2950 (gnus-message 5 "Saving %s..." file)
2951 (apply 'gnus-product-quick-file-format product checking-methods coding
2953 (save-buffer-as-coding-system coding)
2954 (kill-buffer (current-buffer))
2956 (put (car variables) 'gnus-product-variable nil)
2957 (setq variables (cdr variables)))
2959 5 "Saving %s...done" file))))
2961 (defun gnus-product-quick-file-format (product checking-methods
2962 coding &rest variables)
2963 "Insert gnus product depend variables in lisp format."
2964 (let ((print-quoted t)
2965 (print-escape-newlines t)
2966 print-length print-level variable param)
2967 (insert (format ";; -*- Mode: emacs-lisp; coding: %s -*-\n" coding))
2968 (insert (format ";; %s startup file.\n" (product-name product)))
2969 (when (setq param (cdr (assq 'product-version checking-methods)))
2970 (insert "(or (>= (product-version-compare "
2971 "(product-version (product-find 'gnus-vers))\n"
2972 "\t\t\t\t '" (apply 'prin1-to-string param) ")\n"
2974 " (error \"This file was created by later version of "
2976 (insert "(setq gnus-product-file-version\n"
2977 " '((product-version . "
2978 (prin1-to-string (product-version product)) ")\n"
2979 "\t(emacs-version . "
2980 (prin1-to-string emacs-version) ")\n"
2981 "\t(correct-string-widths . "
2982 (if gnus-use-correct-string-widths "t" "nil")
2985 (when (and (boundp (setq variable (pop variables)))
2986 (symbol-value variable))
2987 (insert "(setq " (symbol-name variable) " '")
2988 (gnus-prin1 (symbol-value variable))
2991 (defun gnus-strip-killed-list ()
2992 "Return the killed list minus the groups that match `gnus-save-killed-list'."
2993 (let ((list gnus-killed-list)
2996 (when (string-match gnus-save-killed-list (car list))
2997 (push (car list) olist))
3001 (defun gnus-gnus-to-newsrc-format ()
3002 ;; Generate and save the .newsrc file.
3004 (set-buffer (create-file-buffer gnus-current-startup-file))
3005 (let ((newsrc (cdr gnus-newsrc-alist))
3006 (standard-output (current-buffer))
3007 info ranges range method)
3008 (setq buffer-file-name gnus-current-startup-file)
3009 (setq default-directory (file-name-directory buffer-file-name))
3010 (buffer-disable-undo)
3013 (when gnus-newsrc-options
3014 (insert gnus-newsrc-options))
3015 ;; Write subscribed and unsubscribed.
3016 (while (setq info (pop newsrc))
3017 ;; Don't write foreign groups to .newsrc.
3018 (when (or (null (setq method (gnus-info-method info)))
3019 (equal method "native")
3020 (inline (gnus-server-equal method gnus-select-method)))
3021 (insert (gnus-info-group info)
3022 (if (> (gnus-info-level info) gnus-level-subscribed)
3024 (when (setq ranges (gnus-info-read info))
3026 (if (not (listp (cdr ranges)))
3027 (if (= (car ranges) (cdr ranges))
3028 (princ (car ranges))
3029 (princ (car ranges))
3031 (princ (cdr ranges)))
3032 (while (setq range (pop ranges))
3033 (if (or (atom range) (= (car range) (cdr range)))
3034 (princ (or (and (atom range) range) (car range)))
3037 (princ (cdr range)))
3041 (make-local-variable 'version-control)
3042 (setq version-control 'never)
3043 ;; It has been reported that sometime the modtime on the .newsrc
3044 ;; file seems to be off. We really do want to overwrite it, so
3045 ;; we clear the modtime here before saving. It's a bit odd,
3047 ;; sometimes the modtime clear isn't sufficient. most brute force:
3048 ;; delete the silly thing entirely first. but this fails to provide
3049 ;; such niceties as .newsrc~ creation.
3050 (if gnus-modtime-botch
3051 (delete-file gnus-startup-file)
3052 (clear-visited-file-modtime))
3053 (gnus-run-hooks 'gnus-save-standard-newsrc-hook)
3055 (kill-buffer (current-buffer)))))
3059 ;;; Slave functions.
3062 (defvar gnus-slave-mode nil)
3064 (defun gnus-slave-mode ()
3065 "Minor mode for slave Gnusae."
3066 (add-minor-mode 'gnus-slave-mode " Slave" (make-sparse-keymap))
3067 (gnus-run-hooks 'gnus-slave-mode-hook))
3069 (defun gnus-slave-save-newsrc ()
3071 (set-buffer gnus-dribble-buffer)
3073 (mm-make-temp-file (concat gnus-current-startup-file "-slave-")))
3074 (modes (ignore-errors
3075 (file-modes (concat gnus-current-startup-file ".eld")))))
3076 (gnus-write-buffer-as-coding-system gnus-ding-file-coding-system
3079 (set-file-modes slave-name modes)))))
3081 (defun gnus-master-read-slave-newsrc ()
3084 (file-name-directory gnus-current-startup-file)
3088 (file-name-nondirectory gnus-current-startup-file)
3092 (if (not slave-files)
3093 () ; There are no slave files to read.
3094 (gnus-message 7 "Reading slave newsrcs...")
3096 (set-buffer (gnus-get-buffer-create " *gnus slave*"))
3098 (sort (mapcar (lambda (file)
3099 (list (nth 5 (file-attributes file)) file))
3102 (or (< (caar f1) (caar f2))
3103 (< (nth 1 (car f1)) (nth 1 (car f2)))))))
3106 (setq file (nth 1 (car slave-files)))
3107 (nnheader-insert-file-contents file)
3108 (when (condition-case ()
3110 (eval-buffer (current-buffer))
3113 (gnus-error 3.2 "Possible error in %s" file)
3115 (unless gnus-slave ; Slaves shouldn't delete these files.
3117 (delete-file file))))
3118 (setq slave-files (cdr slave-files))))
3119 (gnus-dribble-touch)
3120 (gnus-message 7 "Reading slave newsrcs...done"))))
3124 ;;; Group description.
3127 (defun gnus-read-all-descriptions-files ()
3128 (let ((methods (cons gnus-select-method
3130 (when (gnus-archive-server-wanted-p)
3132 gnus-secondary-select-methods))))
3134 (gnus-read-descriptions-file (car methods))
3135 (setq methods (cdr methods)))
3138 (defun gnus-read-descriptions-file (&optional method)
3139 (let ((method (or method gnus-select-method))
3141 (when (stringp method)
3142 (setq method (gnus-server-to-method method)))
3143 ;; We create the hashtable whether we manage to read the desc file
3144 ;; to avoid trying to re-read after a failed read.
3145 (unless gnus-description-hashtb
3146 (setq gnus-description-hashtb
3147 (gnus-make-hashtable (length gnus-active-hashtb))))
3148 ;; Mark this method's desc file as read.
3149 (gnus-sethash (gnus-group-prefixed-name "" method) "Has read"
3150 gnus-description-hashtb)
3152 (gnus-message 5 "Reading descriptions file via %s..." (car method))
3154 ((null (gnus-get-function method 'request-list-newsgroups t))
3156 ((not (gnus-check-server method))
3157 (gnus-message 1 "Couldn't open server")
3159 ((not (gnus-request-list-newsgroups method))
3160 (gnus-message 1 "Couldn't read newsgroups descriptions")
3165 (set-buffer nntp-server-buffer)
3166 (goto-char (point-min))
3167 (when (or (search-forward "\n.\n" nil t)
3168 (goto-char (point-max)))
3170 (narrow-to-region (point-min) (point)))
3171 ;; If these are groups from a foreign select method, we insert the
3172 ;; group prefix in front of the group names.
3173 (and method (not (inline
3175 (gnus-server-get-method nil method)
3176 (gnus-server-get-method
3177 nil gnus-select-method))))
3178 (let ((prefix (gnus-group-prefixed-name "" method)))
3179 (goto-char (point-min))
3180 (while (and (not (eobp))
3181 (progn (insert prefix)
3182 (zerop (forward-line 1)))))))
3183 (goto-char (point-min))
3185 ;; If we get an error, we set group to 0, which is not a
3189 (let ((obarray gnus-description-hashtb))
3190 ;; Group is set to a symbol interned in this
3192 (read nntp-server-buffer))
3194 (skip-chars-forward " \t")
3195 ;; ... which leads to this line being effectively ignored.
3196 (when (symbolp group)
3197 (let* ((str (buffer-substring
3198 (point) (progn (end-of-line) (point))))
3199 (name (symbol-name group))
3201 (or (gnus-group-name-charset method name)
3202 (gnus-parameter-charset name)
3203 gnus-default-charset)))
3204 ;; Fixme: Don't decode in unibyte mode.
3205 (when (and str charset (featurep 'mule))
3206 (setq str (decode-coding-string str charset)))
3209 (gnus-message 5 "Reading descriptions file...done")
3212 (defun gnus-group-get-description (group)
3213 "Get the description of a group by sending XGTITLE to the server."
3214 (when (gnus-request-group-description group)
3216 (set-buffer nntp-server-buffer)
3217 (goto-char (point-min))
3218 (when (looking-at "[^ \t]+[ \t]+\\(.*\\)")
3219 (match-string 1)))))
3222 (defun gnus-declare-backend (name &rest abilities)
3223 "Declare back end NAME with ABILITIES as a Gnus back end."
3224 (setq gnus-valid-select-methods
3225 (nconc gnus-valid-select-methods
3226 (list (apply 'list name abilities))))
3227 (gnus-redefine-select-method-widget))
3229 (defun gnus-set-default-directory ()
3230 "Set the default directory in the current buffer to `gnus-default-directory'.
3231 If this variable is nil, don't do anything."
3232 (setq default-directory
3233 (if (and gnus-default-directory
3234 (file-exists-p gnus-default-directory))
3235 (file-name-as-directory (expand-file-name gnus-default-directory))
3236 default-directory)))
3239 (defalias 'gnus-display-time-event-handler
3240 (if (gnus-boundp 'display-time-timer)
3241 'display-time-event-handler
3242 (lambda () "Does nothing as `display-time-timer' is not bound.
3243 Would otherwise be an alias for `display-time-event-handler'." nil))))
3246 (defun gnus-fixup-nnimap-unread-after-getting-new-news ()
3247 (let (server group info)
3250 (when (and (setq group (symbol-name sym))
3251 (gnus-group-entry group)
3252 (setq info (symbol-value sym)))
3253 (gnus-sethash group (cons (nth 2 info) (cdr (gnus-group-entry group)))
3254 gnus-newsrc-hashtb)))
3255 (if (boundp 'nnimap-mailbox-info)
3256 (symbol-value 'nnimap-mailbox-info)
3257 (make-vector 1 0)))))
3260 (provide 'gnus-start)
3262 ;;; gnus-start.el ends here