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 real-group)
508 (setq prefixes (list "^"))
509 (while (and groups prefixes)
510 (while (not (string-match (car prefixes)
511 (gnus-group-real-name (car groups))))
512 (setq prefixes (cdr prefixes)))
513 (setq prefix (car prefixes))
514 (setq start (1- (length prefix)))
515 (if (and (string-match "[^\\.]\\." (gnus-group-real-name (car groups))
519 (concat "^" (substring
520 (gnus-group-real-name (car groups))
522 (string-match prefix (gnus-group-real-name (cadr groups))))
524 (push prefix prefixes)
525 (message "Descend hierarchy %s? ([y]nsq): "
526 (substring prefix 1 (1- (length prefix))))
527 (while (not (memq (setq ans (read-char-exclusive))
528 '(?y ?\n ?\r ?n ?s ?q)))
530 (message "Descend hierarchy %s? ([y]nsq): "
531 (substring prefix 1 (1- (length prefix)))))
534 (setq group (car groups)
535 real-group (gnus-group-real-name group))
536 (string-match prefix real-group))
537 (push group gnus-killed-list)
538 (gnus-sethash group group gnus-killed-hashtb)
539 (setq groups (cdr groups)))
540 (setq starts (cdr starts)))
543 (setq group (car groups)
544 real-group (gnus-group-real-name group))
545 (string-match prefix real-group))
546 (gnus-sethash group group gnus-killed-hashtb)
547 (gnus-subscribe-alphabetically (car groups))
548 (setq groups (cdr groups)))
549 (setq starts (cdr starts)))
552 (setq group (car groups))
553 (push group gnus-killed-list)
554 (gnus-sethash group group gnus-killed-hashtb)
555 (setq groups (cdr groups))))
557 (message "Subscribe %s? ([n]yq)" (car groups))
558 (while (not (memq (setq ans (read-char-exclusive))
559 '(?y ?\n ?\r ?q ?n)))
561 (message "Subscribe %s? ([n]yq)" (car groups)))
562 (setq group (car groups))
564 (gnus-subscribe-alphabetically (car groups))
565 (gnus-sethash group group gnus-killed-hashtb))
568 (setq group (car groups))
569 (push group gnus-killed-list)
570 (gnus-sethash group group gnus-killed-hashtb)
571 (setq groups (cdr groups))))
573 (push group gnus-killed-list)
574 (gnus-sethash group group gnus-killed-hashtb)))
575 (setq groups (cdr groups)))))))
577 (defun gnus-subscribe-randomly (newsgroup)
578 "Subscribe new NEWSGROUP by making it the first newsgroup."
579 (gnus-subscribe-newsgroup newsgroup))
581 (defun gnus-subscribe-alphabetically (newgroup)
582 "Subscribe new NEWGROUP and insert it in alphabetical order."
583 (let ((groups (cdr gnus-newsrc-alist))
585 (while (and (not before) groups)
586 (if (string< newgroup (caar groups))
587 (setq before (caar groups))
588 (setq groups (cdr groups))))
589 (gnus-subscribe-newsgroup newgroup before)))
591 (defun gnus-subscribe-hierarchically (newgroup)
592 "Subscribe new NEWGROUP and insert it in hierarchical newsgroup order."
593 ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
595 (set-buffer (nnheader-find-file-noselect gnus-current-startup-file))
597 (let ((groupkey newgroup) before)
598 (while (and (not before) groupkey)
599 (goto-char (point-min))
601 (concat "^\\(" (regexp-quote groupkey) ".*\\)[!:]")))
602 (while (and (re-search-forward groupkey-re nil t)
604 (setq before (match-string 1))
605 (string< before newgroup)))))
606 ;; Remove tail of newsgroup name (eg. a.b.c -> a.b)
608 (when (string-match "^\\(.*\\)\\.[^.]+$" groupkey)
609 (substring groupkey (match-beginning 1) (match-end 1)))))
610 (gnus-subscribe-newsgroup newgroup before))
611 (kill-buffer (current-buffer)))))
613 (defun gnus-subscribe-interactively (group)
614 "Subscribe the new GROUP interactively.
615 It is inserted in hierarchical newsgroup order if subscribed. If not,
617 (if (gnus-y-or-n-p (format "Subscribe new newsgroup: %s " group))
618 (gnus-subscribe-hierarchically group)
619 (push group gnus-killed-list)))
621 (defun gnus-subscribe-zombies (group)
622 "Make the new GROUP into a zombie group."
623 (push group gnus-zombie-list))
625 (defun gnus-subscribe-killed (group)
626 "Make the new GROUP a killed group."
627 (push group gnus-killed-list))
629 (defun gnus-subscribe-newsgroup (newsgroup &optional next)
630 "Subscribe new NEWSGROUP.
631 If NEXT is non-nil, it is inserted before NEXT. Otherwise it is made
632 the first newsgroup."
634 (goto-char (point-min))
635 ;; We subscribe the group by changing its level to `subscribed'.
636 (gnus-group-change-level
637 newsgroup gnus-level-default-subscribed
638 gnus-level-killed (gnus-group-entry (or next "dummy.group")))
639 (gnus-message 5 "Subscribe newsgroup: %s" newsgroup)
640 (run-hook-with-args 'gnus-subscribe-newsgroup-hooks newsgroup)
643 (defun gnus-read-active-file-p ()
644 "Say whether the active file has been read from `gnus-select-method'."
645 (memq gnus-select-method gnus-have-read-active-file))
647 ;;; General various misc type functions.
649 ;; Silence byte-compiler.
651 (defvar gnus-current-headers)
652 (defvar gnus-thread-indent-array)
653 (defvar gnus-newsgroup-name)
654 (defvar gnus-newsgroup-headers)
655 (defvar gnus-group-list-mode)
656 (defvar gnus-group-mark-positions)
657 (defvar gnus-newsgroup-data)
658 (defvar gnus-newsgroup-unreads)
659 (defvar nnoo-state-alist)
660 (defvar gnus-current-select-method)
661 (defvar mail-sources)
662 (defvar nnmail-scan-directory-mail-source-once)
663 (defvar nnmail-split-history)
664 (defvar nnmail-spool-file))
666 (defun gnus-clear-quick-file-variables ()
667 "Clear all variables in quick startup files."
668 (let ((variables gnus-variable-list))
669 ;; Clear Gnus variables.
671 (set (car variables) nil)
672 (setq variables (cdr variables))))
673 (let ((files gnus-product-variable-file-list))
675 (let ((variables (nthcdr 3 (car files))))
677 (set (car variables) nil)
678 (setq variables (cdr variables))))
679 (setq files (cdr files)))))
681 (defun gnus-close-all-servers ()
684 (dolist (server gnus-opened-servers)
685 (gnus-close-server (car server))))
687 (defun gnus-clear-system ()
688 "Clear all variables and buffers."
689 ;; Clear gnus variables.
690 (gnus-clear-quick-file-variables)
691 ;; Clear other internal variables.
692 (setq gnus-list-of-killed-groups nil
693 gnus-have-read-active-file nil
694 gnus-agent-covered-methods nil
695 gnus-agent-file-loading-local nil
696 gnus-agent-file-loading-cache nil
697 gnus-server-method-cache nil
698 gnus-newsrc-alist nil
699 gnus-newsrc-hashtb nil
702 gnus-killed-hashtb nil
703 gnus-active-hashtb nil
704 gnus-moderated-hashtb nil
705 gnus-description-hashtb nil
706 gnus-current-headers nil
707 gnus-thread-indent-array nil
708 gnus-newsgroup-headers nil
709 gnus-newsgroup-name nil
710 gnus-server-alist nil
711 gnus-group-list-mode nil
712 gnus-opened-servers nil
713 gnus-group-mark-positions nil
714 gnus-newsgroup-data nil
715 gnus-newsgroup-unreads nil
717 gnus-current-select-method nil
718 nnmail-split-history nil
719 gnus-ephemeral-servers nil)
720 (gnus-shutdown 'gnus)
721 ;; Kill the startup file.
722 (and gnus-current-startup-file
723 (get-file-buffer gnus-current-startup-file)
724 (kill-buffer (get-file-buffer gnus-current-startup-file)))
725 ;; Clear the dribble buffer.
727 ;; Kill global KILL file buffer.
728 (when (get-file-buffer (gnus-newsgroup-kill-file nil))
729 (kill-buffer (get-file-buffer (gnus-newsgroup-kill-file nil))))
730 (gnus-kill-buffer nntp-server-buffer)
731 ;; Kill Gnus buffers.
732 (dolist (buffer (gnus-buffers))
733 (gnus-kill-buffer buffer))
734 ;; Remove Gnus frames.
735 (gnus-kill-gnus-frames))
737 (defun gnus-no-server-1 (&optional arg slave)
739 If ARG is a positive number, Gnus will use that as the
740 startup level. If ARG is nil, Gnus will be started at level 2.
741 If ARG is non-nil and not a positive number, Gnus will
742 prompt the user for the name of an NNTP server to use.
743 As opposed to `gnus', this command will not connect to the local server."
745 (let ((val (or arg (1- gnus-level-default-subscribed))))
747 (make-local-variable 'gnus-group-use-permanent-levels)
748 (setq gnus-group-use-permanent-levels val)))
750 (defun gnus-1 (&optional arg dont-connect slave)
752 If ARG is non-nil and a positive number, Gnus will use that as the
753 startup level. If ARG is non-nil and not a positive number, Gnus will
754 prompt the user for the name of an NNTP server to use."
759 (switch-to-buffer gnus-group-buffer)
760 (gnus-group-get-new-news
763 (max (car gnus-group-list-mode) arg))))
767 (gnus-run-hooks 'gnus-before-startup-hook)
768 (nnheader-init-server-buffer)
769 (setq gnus-slave slave)
770 (gnus-read-init-file)
774 (when gnus-simple-splash
775 (setq gnus-simple-splash nil)
780 (= (frame-height) (1+ (window-height))))
783 (let ((level (and (numberp arg) (> arg 0) arg))
789 (gnus-start-news-server (and arg (not level))))))
790 (if (and (not dont-connect)
793 (gnus-run-hooks 'gnus-startup-hook)
794 ;; NNTP server is successfully open.
796 ;; Find the current startup file name.
797 (setq gnus-current-startup-file
798 (gnus-make-newsrc-file gnus-startup-file))
800 ;; Read the dribble file.
801 (when (or gnus-slave gnus-use-dribble-file)
802 (gnus-dribble-read-file))
804 ;; Do the actual startup.
806 (gnus-request-create-group "queue" '(nndraft "")))
807 (gnus-request-create-group "drafts" '(nndraft ""))
808 (gnus-setup-news nil level dont-connect)
809 (gnus-run-hooks 'gnus-setup-news-hook)
810 (gnus-start-draft-setup)
811 ;; Generate the group buffer.
812 (gnus-group-list-groups level)
813 (gnus-group-first-unread-group)
814 (gnus-configure-windows 'group)
815 (gnus-group-set-mode-line)
817 (set-language-info "Japanese" 'gnus-info "gnus-ja")
818 (gnus-run-hooks 'gnus-started-hook))))))
820 (defun gnus-start-draft-setup ()
821 "Make sure the draft group exists."
822 (gnus-request-create-group "drafts" '(nndraft ""))
823 (unless (gnus-group-entry "nndraft:drafts")
824 (let ((gnus-level-default-subscribed 1))
825 (gnus-subscribe-group "nndraft:drafts" nil '(nndraft "")))
826 (gnus-group-set-parameter
827 "nndraft:drafts" 'gnus-dummy '((gnus-draft-mode)))))
834 (defvar gnus-dribble-ignore nil)
835 (defvar gnus-dribble-eval-file nil)
837 (defun gnus-dribble-file-name ()
838 "Return the dribble file for the current .newsrc."
840 (if gnus-dribble-directory
841 (concat (file-name-as-directory gnus-dribble-directory)
842 (file-name-nondirectory gnus-current-startup-file))
843 gnus-current-startup-file)
846 (defun gnus-dribble-enter (string)
847 "Enter STRING into the dribble buffer."
848 (when (and (not gnus-dribble-ignore)
850 (buffer-name gnus-dribble-buffer))
851 (let ((obuf (current-buffer)))
852 (set-buffer gnus-dribble-buffer)
853 (goto-char (point-max))
855 ;; This has been commented by Josh Huber <huber@alum.wpi.edu>
856 ;; It causes problems with both XEmacs and Emacs 21, and doesn't
857 ;; seem to be of much value. (FIXME: remove this after we make sure
859 ;; (set-window-point (get-buffer-window (current-buffer)) (point-max))
860 (bury-buffer gnus-dribble-buffer)
862 (set-buffer gnus-group-buffer)
863 (gnus-group-set-mode-line))
866 (defun gnus-dribble-touch ()
867 "Touch the dribble buffer."
868 (gnus-dribble-enter ""))
870 (defun gnus-dribble-read-file ()
871 "Read the dribble file from disk."
872 (let ((dribble-file (gnus-dribble-file-name)))
874 (set-buffer (setq gnus-dribble-buffer
875 (gnus-get-buffer-create
876 (file-name-nondirectory dribble-file))))
878 (setq buffer-file-name dribble-file)
880 (buffer-disable-undo)
881 (bury-buffer (current-buffer))
882 (set-buffer-modified-p nil)
883 (let ((auto (make-auto-save-file-name))
884 (gnus-dribble-ignore t)
887 (when (or (file-exists-p auto) (file-exists-p dribble-file))
888 ;; Load whichever file is newest -- the auto save file
889 ;; or the "real" file.
890 (if (file-newer-than-file-p auto dribble-file)
891 (nnheader-insert-file-contents auto)
892 (nnheader-insert-file-contents dribble-file))
893 (unless (zerop (buffer-size))
894 (set-buffer-modified-p t))
895 ;; Set the file modes to reflect the .newsrc file modes.
897 (when (and (file-exists-p gnus-current-startup-file)
898 (file-exists-p dribble-file)
899 (setq modes (file-modes gnus-current-startup-file)))
900 (set-file-modes dribble-file modes))
901 (goto-char (point-min))
902 (when (search-forward "Gnus was exited on purpose" nil t)
904 ;; Possibly eval the file later.
905 (when (or gnus-always-read-dribble-file
908 "Gnus exited on purpose without saving; read auto-save file anyway? "
909 "Gnus auto-save file exists. Do you want to read it? ")))
910 (setq gnus-dribble-eval-file t)))))))
912 (defun gnus-dribble-eval-file ()
913 (when gnus-dribble-eval-file
914 (setq gnus-dribble-eval-file nil)
916 (let ((gnus-dribble-ignore t))
917 (set-buffer gnus-dribble-buffer)
918 (eval-buffer (current-buffer))))))
920 (defun gnus-dribble-delete-file ()
921 (when (file-exists-p (gnus-dribble-file-name))
922 (delete-file (gnus-dribble-file-name)))
923 (when gnus-dribble-buffer
925 (set-buffer gnus-dribble-buffer)
926 (let ((auto (make-auto-save-file-name)))
927 (when (file-exists-p auto)
930 (set-buffer-modified-p nil)))))
932 (defun gnus-dribble-save ()
933 (when (and gnus-dribble-buffer
934 (buffer-name gnus-dribble-buffer))
936 (set-buffer gnus-dribble-buffer)
939 (defun gnus-dribble-clear ()
940 (when (gnus-buffer-exists-p gnus-dribble-buffer)
942 (set-buffer gnus-dribble-buffer)
944 (set-buffer-modified-p nil)
945 (setq buffer-saved-size (buffer-size)))))
949 ;;; Active & Newsrc File Handling
952 (defun gnus-setup-news (&optional rawfile level dont-connect)
953 "Setup news information.
954 If RAWFILE is non-nil, the .newsrc file will also be read.
955 If LEVEL is non-nil, the news will be set up at level LEVEL."
957 (let ((init (not (and gnus-newsrc-alist gnus-active-hashtb (not rawfile))))
958 ;; Binding this variable will inhibit multiple fetchings
959 ;; of the same mail source.
960 (nnmail-fetched-sources (list t)))
963 ;; Clear some variables to re-initialize news information.
964 (setq gnus-newsrc-alist nil
965 gnus-active-hashtb nil)
966 ;; Read the newsrc file and create `gnus-newsrc-hashtb'.
967 (gnus-read-newsrc-file rawfile))
969 ;; Make sure the archive server is available to all and sundry.
970 (when gnus-message-archive-method
971 (unless (assoc "archive" gnus-server-alist)
976 ,(nnheader-concat message-directory "archive"))
977 (nnfolder-active-file
978 ,(nnheader-concat message-directory "archive/active"))
979 (nnfolder-get-new-mail nil)
980 (nnfolder-inhibit-expiry t))
983 ;; If we don't read the complete active file, we fill in the
985 (when (or (null gnus-read-active-file)
986 (eq gnus-read-active-file 'some))
987 (gnus-update-active-hashtb-from-killed))
989 ;; Validate agent covered methods now that gnus-server-alist has
991 ;; NOTE: This is here for one purpose only. By validating the
992 ;; agentized server's, it converts the old 5.10.3, and earlier,
993 ;; format to the current format. That enables the agent code
994 ;; within gnus-read-active-file to function correctly.
996 (gnus-agent-read-servers-validate))
998 ;; Read the active file and create `gnus-active-hashtb'.
999 ;; If `gnus-read-active-file' is nil, then we just create an empty
1000 ;; hash table. The partial filling out of the hash table will be
1001 ;; done in `gnus-get-unread-articles'.
1002 (and gnus-read-active-file
1004 (gnus-read-active-file nil dont-connect))
1006 (unless gnus-active-hashtb
1007 (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
1009 ;; Initialize the cache.
1010 (when gnus-use-cache
1013 ;; Possibly eval the dribble file.
1015 (or gnus-use-dribble-file gnus-slave)
1016 (gnus-dribble-eval-file))
1018 ;; Slave Gnusii should then clear the dribble buffer.
1019 (when (and init gnus-slave)
1020 (gnus-dribble-clear))
1022 (gnus-update-format-specifications)
1024 ;; See whether we need to read the description file.
1025 (when (and (boundp 'gnus-group-line-format)
1026 (stringp gnus-group-line-format)
1027 (let ((case-fold-search nil))
1028 (string-match "%[-,0-9]*D" gnus-group-line-format))
1029 (not gnus-description-hashtb)
1031 gnus-read-active-file)
1032 (gnus-read-all-descriptions-files))
1034 ;; Find new newsgroups and treat them.
1035 (when (and init gnus-check-new-newsgroups (not level)
1036 (gnus-check-server gnus-select-method)
1039 (gnus-find-new-newsgroups))
1041 ;; Check and remove bogus newsgroups.
1042 (when (and init gnus-check-bogus-newsgroups
1043 gnus-read-active-file (not level)
1044 (gnus-server-opened gnus-select-method))
1045 (gnus-check-bogus-newsgroups))
1047 ;; We might read in new NoCeM messages here.
1048 (when (and gnus-use-nocem
1051 (gnus-nocem-scan-groups))
1053 ;; Read any slave files.
1054 (gnus-master-read-slave-newsrc)
1056 ;; Find the number of unread articles in each non-dead group.
1057 (let ((gnus-read-active-file (and (not level) gnus-read-active-file)))
1058 (gnus-get-unread-articles level))))
1060 (defun gnus-call-subscribe-functions (method group)
1061 "Call METHOD to subscribe GROUP.
1062 If no function returns `non-nil', call `gnus-subscribe-zombies'."
1065 (funcall method group))
1068 (dolist (func method)
1069 (if (funcall func group)
1073 (gnus-subscribe-zombies group)))
1075 (defun gnus-find-new-newsgroups (&optional arg)
1076 "Search for new newsgroups and add them.
1077 Each new newsgroup will be treated with `gnus-subscribe-newsgroup-method'.
1078 The `-n' option line from .newsrc is respected.
1080 With 1 C-u, use the `ask-server' method to query the server for new
1082 With 2 C-u's, use most complete method possible to query the server
1083 for new groups, and subscribe the new groups as zombies."
1085 (let* ((gnus-subscribe-newsgroup-method
1086 gnus-subscribe-newsgroup-method)
1088 ((or (and (= (or arg 1) 4)
1089 (not (listp gnus-check-new-newsgroups)))
1090 (null gnus-read-active-file)
1091 (eq gnus-read-active-file 'some))
1094 (setq gnus-subscribe-newsgroup-method
1095 'gnus-subscribe-zombies)
1097 (t gnus-check-new-newsgroups))))
1098 (unless (gnus-check-first-time-used)
1099 (if (or (consp check)
1100 (eq check 'ask-server))
1101 ;; Ask the server for new groups.
1102 (gnus-ask-server-for-new-groups)
1103 ;; Go through the active hashtb and look for new groups.
1105 group new-newsgroups)
1106 (gnus-message 5 "Looking for new newsgroups...")
1107 (unless gnus-have-read-active-file
1108 (gnus-read-active-file))
1109 (setq gnus-newsrc-last-checked-date (message-make-date))
1110 (unless gnus-killed-hashtb
1111 (gnus-make-hashtable-from-killed))
1112 ;; Go though every newsgroup in `gnus-active-hashtb' and compare
1113 ;; with `gnus-newsrc-hashtb' and `gnus-killed-hashtb'.
1116 (if (or (null (setq group (symbol-name sym)))
1118 (null (symbol-value sym))
1119 (gnus-gethash group gnus-killed-hashtb)
1120 (gnus-gethash group gnus-newsrc-hashtb))
1122 (let ((do-sub (gnus-matches-options-n group)))
1124 ((eq do-sub 'subscribe)
1125 (setq groups (1+ groups))
1126 (gnus-sethash group group gnus-killed-hashtb)
1127 (gnus-call-subscribe-functions
1128 gnus-subscribe-options-newsgroup-method group))
1129 ((eq do-sub 'ignore)
1132 (setq groups (1+ groups))
1133 (gnus-sethash group group gnus-killed-hashtb)
1134 (if gnus-subscribe-hierarchical-interactive
1135 (push group new-newsgroups)
1136 (gnus-call-subscribe-functions
1137 gnus-subscribe-newsgroup-method group)))))))
1139 (when new-newsgroups
1140 (gnus-subscribe-hierarchical-interactive new-newsgroups))
1142 (gnus-message 5 "%d new newsgroup%s arrived."
1143 groups (if (> groups 1) "s have" " has"))
1144 (gnus-message 5 "No new newsgroups.")))))))
1146 (defun gnus-matches-options-n (group)
1147 ;; Returns `subscribe' if the group is to be unconditionally
1148 ;; subscribed, `ignore' if it is to be ignored, and nil if there is
1149 ;; no match for the group.
1151 ;; First we check the two user variables.
1153 ((and gnus-options-subscribe
1154 (string-match gnus-options-subscribe group))
1156 ((and gnus-auto-subscribed-groups
1157 (string-match gnus-auto-subscribed-groups group))
1159 ((and gnus-options-not-subscribe
1160 (string-match gnus-options-not-subscribe group))
1162 ;; Then we go through the list that was retrieved from the .newsrc
1163 ;; file. This list has elements on the form
1164 ;; `(REGEXP . {ignore,subscribe})'. The first match found (the list
1165 ;; is in the reverse order of the options line) is returned.
1167 (let ((regs gnus-newsrc-options-n))
1169 (not (string-match (caar regs) group)))
1170 (setq regs (cdr regs)))
1171 (and regs (cdar regs))))))
1173 (defun gnus-ask-server-for-new-groups ()
1174 (let* ((new-date (message-make-date))
1175 (date (or gnus-newsrc-last-checked-date new-date))
1176 (methods (cons gnus-select-method
1178 (when (gnus-archive-server-wanted-p)
1181 (and (consp gnus-check-new-newsgroups)
1182 gnus-check-new-newsgroups)
1183 gnus-secondary-select-methods))))
1185 group new-newsgroups got-new method hashtb
1186 gnus-override-subscribe-method)
1187 (unless gnus-killed-hashtb
1188 (gnus-make-hashtable-from-killed))
1189 ;; Go through both primary and secondary select methods and
1190 ;; request new newsgroups.
1191 (while (setq method (gnus-server-get-method nil (pop methods)))
1192 (setq new-newsgroups nil
1193 gnus-override-subscribe-method method)
1194 (when (and (gnus-check-server method)
1195 (gnus-request-newgroups date method))
1198 hashtb (gnus-make-hashtable 100))
1199 (set-buffer nntp-server-buffer)
1200 ;; Enter all the new groups into a hashtable.
1201 (gnus-active-to-gnus-format method hashtb 'ignore))
1202 ;; Now all new groups from `method' are in `hashtb'.
1205 (if (or (null (setq group (symbol-name group-sym)))
1206 (not (boundp group-sym))
1207 (null (symbol-value group-sym))
1208 (gnus-gethash group gnus-newsrc-hashtb)
1209 (member group gnus-zombie-list)
1210 (member group gnus-killed-list))
1211 ;; The group is already known.
1213 ;; Make this group active.
1214 (when (symbol-value group-sym)
1215 (gnus-set-active group (symbol-value group-sym)))
1216 ;; Check whether we want it or not.
1217 (let ((do-sub (gnus-matches-options-n group)))
1219 ((eq do-sub 'subscribe)
1221 (gnus-sethash group group gnus-killed-hashtb)
1222 (gnus-call-subscribe-functions
1223 gnus-subscribe-options-newsgroup-method group))
1224 ((eq do-sub 'ignore)
1228 (gnus-sethash group group gnus-killed-hashtb)
1229 (if gnus-subscribe-hierarchical-interactive
1230 (push group new-newsgroups)
1231 (gnus-call-subscribe-functions
1232 gnus-subscribe-newsgroup-method group)))))))
1234 (when new-newsgroups
1235 (gnus-subscribe-hierarchical-interactive new-newsgroups)))
1237 (gnus-message 5 "%d new newsgroup%s arrived"
1238 groups (if (> groups 1) "s have" " has"))
1239 (gnus-message 5 "No new newsgroups"))
1241 (setq gnus-newsrc-last-checked-date new-date))
1244 (defun gnus-check-first-time-used ()
1246 ;; First check if any of the following files exist. If they do,
1247 ;; it's not the first time the user has used Gnus.
1248 (dolist (file (list (concat gnus-current-startup-file ".el")
1249 (concat gnus-current-startup-file ".eld")
1250 (concat gnus-startup-file ".el")
1251 (concat gnus-startup-file ".eld")))
1252 (when (file-exists-p file)
1253 (throw 'ended nil)))
1254 (gnus-message 6 "First time user; subscribing you to default groups")
1255 (unless (gnus-read-active-file-p)
1256 (let ((gnus-read-active-file t))
1257 (gnus-read-active-file)))
1258 (setq gnus-newsrc-last-checked-date (message-make-date))
1259 ;; Subscribe to the default newsgroups.
1260 (let ((groups (or gnus-default-subscribed-newsgroups
1261 gnus-backup-default-subscribed-newsgroups))
1264 ;; If t, we subscribe (or not) all groups as if they were new.
1267 (when (setq group (symbol-name sym))
1268 (let ((do-sub (gnus-matches-options-n group)))
1270 ((eq do-sub 'subscribe)
1271 (gnus-sethash group group gnus-killed-hashtb)
1272 (gnus-call-subscribe-functions
1273 gnus-subscribe-options-newsgroup-method group))
1274 ((eq do-sub 'ignore)
1277 (push group gnus-killed-list))))))
1279 (dolist (group groups)
1280 ;; Only subscribe the default groups that are activated.
1281 (when (gnus-active group)
1282 (gnus-group-change-level
1283 group gnus-level-default-subscribed gnus-level-killed)))
1285 (set-buffer gnus-group-buffer)
1286 ;; Don't error if the group already exists. This happens when a
1287 ;; first-time user types 'F'. -- didier
1288 (gnus-group-make-help-group t))
1289 (when gnus-novice-user
1290 (gnus-message 7 "`A k' to list killed groups"))))))
1292 (defun gnus-subscribe-group (group &optional previous method)
1293 "Subscribe GROUP and put it after PREVIOUS."
1294 (gnus-group-change-level
1296 (list t group gnus-level-default-subscribed nil nil method)
1298 gnus-level-default-subscribed gnus-level-killed previous t)
1301 ;; `gnus-group-change-level' is the fundamental function for changing
1302 ;; subscription levels of newsgroups. This might mean just changing
1303 ;; from level 1 to 2, which is pretty trivial, from 2 to 6 or back
1304 ;; again, which subscribes/unsubscribes a group, which is equally
1305 ;; trivial. Changing from 1-7 to 8-9 means that you kill a group, and
1306 ;; from 8-9 to 1-7 means that you remove the group from the list of
1307 ;; killed (or zombie) groups and add them to the (kinda) subscribed
1308 ;; groups. And last but not least, moving from 8 to 9 and 9 to 8,
1309 ;; which is trivial.
1310 ;; ENTRY can either be a string (newsgroup name) or a list (if
1311 ;; FROMKILLED is t, it's a list on the format (NUM INFO-LIST),
1312 ;; otherwise it's a list in the format of the `gnus-newsrc-hashtb'
1314 ;; LEVEL is the new level of the group, OLDLEVEL is the old level and
1315 ;; PREVIOUS is the group (in hashtb entry format) to insert this group
1317 (defun gnus-group-change-level (entry level &optional oldlevel
1318 previous fromkilled)
1319 (let (group info active num)
1320 ;; Glean what info we can from the arguments
1322 (if fromkilled (setq group (nth 1 entry))
1323 (setq group (car (nth 2 entry))))
1325 (when (and (stringp entry)
1327 (< oldlevel gnus-level-zombie))
1328 (setq entry (gnus-group-entry entry)))
1329 (if (and (not oldlevel)
1331 (setq oldlevel (gnus-info-level (nth 2 entry)))
1332 (setq oldlevel (or oldlevel gnus-level-killed)))
1333 (when (stringp previous)
1334 (setq previous (gnus-group-entry previous)))
1336 (if (and (>= oldlevel gnus-level-zombie)
1337 (gnus-group-entry group))
1338 ;; We are trying to subscribe a group that is already
1342 (unless (gnus-ephemeral-group-p group)
1344 (format "(gnus-group-change-level %S %S %S %S %S)"
1345 group level oldlevel (car (nth 2 previous)) fromkilled)))
1347 ;; Then we remove the newgroup from any old structures, if needed.
1348 ;; If the group was killed, we remove it from the killed or zombie
1349 ;; list. If not, and it is in fact going to be killed, we remove
1350 ;; it from the newsrc hash table and assoc.
1352 ((>= oldlevel gnus-level-zombie)
1353 ;; oldlevel could be wrong.
1354 (setq gnus-zombie-list (delete group gnus-zombie-list))
1355 (setq gnus-killed-list (delete group gnus-killed-list)))
1357 (when (and (>= level gnus-level-zombie)
1359 (gnus-sethash (car (nth 2 entry)) nil gnus-newsrc-hashtb)
1361 (setcdr (gnus-group-entry (car (nth 3 entry)))
1363 (setcdr (cdr entry) (cdddr entry)))))
1365 ;; Finally we enter (if needed) the list where it is supposed to
1366 ;; go, and change the subscription level. If it is to be killed,
1367 ;; we enter it into the killed or zombie list.
1369 ((>= level gnus-level-zombie)
1370 ;; Remove from the hash table.
1371 (gnus-sethash group nil gnus-newsrc-hashtb)
1372 ;; We do not enter foreign groups into the list of dead
1374 (unless (gnus-group-foreign-p group)
1375 (if (= level gnus-level-zombie)
1376 (push group gnus-zombie-list)
1377 (if (= oldlevel gnus-level-killed)
1378 ;; Remove from active hashtb.
1379 (unintern group gnus-active-hashtb)
1380 ;; Don't add it into killed-list if it was killed.
1381 (push group gnus-killed-list)))))
1383 ;; If the list is to be entered into the newsrc assoc, and
1384 ;; it was killed, we have to create an entry in the newsrc
1385 ;; hashtb format and fix the pointers in the newsrc assoc.
1386 (if (< oldlevel gnus-level-zombie)
1387 ;; It was alive, and it is going to stay alive, so we
1388 ;; just change the level and don't change any pointers or
1389 ;; hash table entries.
1390 (setcar (cdaddr entry) level)
1392 (setq info (cdr entry)
1394 (setq active (gnus-active group))
1396 (if active (- (1+ (cdr active)) (car active)) t))
1397 ;; Shorten the select method if possible, if we need to
1398 ;; store it at all (native groups).
1399 (let ((method (gnus-method-simplify
1400 (or gnus-override-subscribe-method
1401 (gnus-group-method group)))))
1403 (setq info (list group level nil nil method))
1404 (setq info (list group level nil)))))
1407 (let ((p gnus-newsrc-alist))
1411 (setq entry (cons info (cddr previous)))
1414 (setcdr (cdr previous) entry)
1415 (gnus-sethash group (cons num (cdr previous))
1416 gnus-newsrc-hashtb))
1417 (setcdr previous entry)
1418 (gnus-sethash group (cons num previous)
1419 gnus-newsrc-hashtb))
1421 (setcdr (gnus-group-entry (caadr entry)) entry))
1424 "(gnus-group-set-info '%S)" info)))))
1425 (when gnus-group-change-level-function
1426 (funcall gnus-group-change-level-function
1427 group level oldlevel previous)))))
1429 (defun gnus-kill-newsgroup (newsgroup)
1430 "Obsolete function. Kills a newsgroup."
1431 (gnus-group-change-level
1432 (gnus-group-entry newsgroup) gnus-level-killed))
1434 (defun gnus-check-bogus-newsgroups (&optional confirm)
1435 "Remove bogus newsgroups.
1436 If CONFIRM is non-nil, the user has to confirm the deletion of every
1438 (let ((newsrc (cdr gnus-newsrc-alist))
1439 bogus group entry info)
1440 (gnus-message 5 "Checking bogus newsgroups...")
1441 (unless (gnus-read-active-file-p)
1442 (gnus-read-active-file t))
1443 (when (gnus-read-active-file-p)
1444 ;; Find all bogus newsgroup that are subscribed.
1446 (setq info (pop newsrc)
1447 group (gnus-info-group info))
1448 (unless (or (gnus-active group) ; Active
1449 (and (gnus-info-method info)
1450 (not (gnus-secondary-method-p
1451 (gnus-info-method info))))) ; Foreign
1452 ;; Found a bogus newsgroup.
1453 (push group bogus)))
1456 "Remove bogus group %s? "
1458 ;; Remove all bogus subscribed groups by first killing them, and
1459 ;; then removing them from the list of killed groups.
1460 (when (setq entry (gnus-group-entry group))
1461 (gnus-group-change-level entry gnus-level-killed)
1462 (setq gnus-killed-list (delete group gnus-killed-list))))
1463 bogus '("group" "groups" "remove"))
1464 (while (setq group (pop bogus))
1465 ;; Remove all bogus subscribed groups by first killing them, and
1466 ;; then removing them from the list of killed groups.
1467 (when (setq entry (gnus-group-entry group))
1468 (gnus-group-change-level entry gnus-level-killed)
1469 (setq gnus-killed-list (delete group gnus-killed-list)))))
1470 ;; Then we remove all bogus groups from the list of killed and
1471 ;; zombie groups. They are removed without confirmation.
1472 (let ((dead-lists '(gnus-killed-list gnus-zombie-list))
1475 (setq killed (symbol-value (car dead-lists)))
1477 (unless (gnus-active (setq group (pop killed)))
1478 ;; The group is bogus.
1480 (set (car dead-lists)
1481 (delete group (symbol-value (car dead-lists))))))
1482 (setq dead-lists (cdr dead-lists))))
1483 (gnus-run-hooks 'gnus-check-bogus-groups-hook)
1484 (gnus-message 5 "Checking bogus newsgroups...done"))))
1486 (defun gnus-check-duplicate-killed-groups ()
1487 "Remove duplicates from the list of killed groups."
1489 (let ((killed gnus-killed-list))
1491 (gnus-message 9 "%d" (length killed))
1492 (setcdr killed (delete (car killed) (cdr killed)))
1493 (setq killed (cdr killed)))))
1495 ;; We want to inline a function from gnus-cache, so we cheat here:
1497 (defvar gnus-cache-active-hashtb)
1498 (defun gnus-cache-possibly-alter-active (group active)
1499 "Alter the ACTIVE info for GROUP to reflect the articles in the cache."
1500 (when gnus-cache-active-hashtb
1501 (let ((cache-active (gnus-gethash group gnus-cache-active-hashtb)))
1503 (when (< (car cache-active) (car active))
1504 (setcar active (car cache-active)))
1505 (when (> (cdr cache-active) (cdr active))
1506 (setcdr active (cdr cache-active))))))))
1508 (defun gnus-activate-group (group &optional scan dont-check method)
1509 ;; Check whether a group has been activated or not.
1510 ;; If SCAN, request a scan of that group as well.
1511 (let ((method (or method (inline (gnus-find-method-for-group group))))
1513 (and (inline (gnus-check-server method))
1514 ;; We escape all bugs and quit here to make it possible to
1515 ;; continue if a group is so out-there that it reports bugs
1519 (gnus-check-backend-function 'request-scan (car method))
1520 (gnus-request-scan group method))
1522 (if (or debug-on-error debug-on-quit)
1523 (inline (gnus-request-group group dont-check method))
1525 (inline (gnus-request-group group dont-check method))
1528 (message "Quit activating %s" group)
1531 (setq active (gnus-parse-active))
1532 ;; If there are no articles in the group, the GROUP
1533 ;; command may have responded with the `(0 . 0)'. We
1534 ;; ignore this if we already have an active entry
1536 (if (and (zerop (car active))
1537 (zerop (cdr active))
1538 (gnus-active group))
1541 ;; If a cache is present, we may have to alter the active info.
1542 (when gnus-use-cache
1543 (inline (gnus-cache-possibly-alter-active
1546 ;; If the agent is enabled, we may have to alter the active info.
1548 (gnus-agent-possibly-alter-active group active))
1550 (gnus-set-active group active)
1551 ;; Return the new active info.
1554 (defun gnus-get-unread-articles-in-group (info active &optional update)
1555 (when (and info active)
1556 ;; Allow the backend to update the info in the group.
1558 (gnus-request-update-info
1559 info (inline (gnus-find-method-for-group
1560 (gnus-info-group info)))))
1561 (gnus-activate-group (gnus-info-group info) nil t))
1563 (let* ((range (gnus-info-read info))
1566 ;; These checks are present in gnus-activate-group but skipped
1567 ;; due to setting dont-check in the preceeding call.
1569 ;; If a cache is present, we may have to alter the active info.
1570 (when (and gnus-use-cache info)
1571 (inline (gnus-cache-possibly-alter-active
1572 (gnus-info-group info) active)))
1574 ;; If the agent is enabled, we may have to alter the active info.
1575 (when (and gnus-agent info)
1576 (gnus-agent-possibly-alter-active (gnus-info-group info) active info))
1578 ;; Modify the list of read articles according to what articles
1579 ;; are available; then tally the unread articles and add the
1580 ;; number to the group hash table entry.
1582 ((zerop (cdr active))
1585 (setq num (- (1+ (cdr active)) (car active))))
1586 ((not (listp (cdr range)))
1587 ;; Fix a single (num . num) range according to the
1588 ;; active hash table.
1589 ;; Fix by Carsten Bormann <cabo@Informatik.Uni-Bremen.DE>.
1590 (and (< (cdr range) (car active)) (setcdr range (1- (car active))))
1591 (and (> (cdr range) (cdr active)) (setcdr range (cdr active)))
1592 ;; Compute number of unread articles.
1593 (setq num (max 0 (- (cdr active) (- (1+ (cdr range)) (car range))))))
1595 ;; The read list is a list of ranges. Fix them according to
1596 ;; the active hash table.
1597 ;; First peel off any elements that are below the lower
1599 (while (and (cdr range)
1601 (or (and (atom (cadr range)) (cadr range))
1603 (if (numberp (car range))
1606 (or (and (numberp (cadr range))
1610 (or (and (numberp (nth 1 range)) (nth 1 range))
1612 (setcdr range (cddr range)))
1613 ;; Adjust the first element to be the same as the lower limit.
1614 (when (and (not (atom (car range)))
1615 (< (cdar range) (car active)))
1616 (setcdr (car range) (1- (car active))))
1617 ;; Then we want to peel off any elements that are higher
1618 ;; than the upper active limit.
1619 (let ((srange range))
1620 ;; Go past all valid elements.
1621 (while (and (cdr srange)
1622 (<= (or (and (atom (cadr srange))
1626 (setq srange (cdr srange)))
1628 ;; Nuke all remaining invalid elements.
1629 (setcdr srange nil))
1631 ;; Adjust the final element.
1632 (when (and (not (atom (car srange)))
1633 (> (cdar srange) (cdr active)))
1634 (setcdr (car srange) (cdr active))))
1635 ;; Compute the number of unread articles.
1637 (setq num (+ num (- (1+ (or (and (atom (car range)) (car range))
1639 (or (and (atom (car range)) (car range))
1641 (setq range (cdr range)))
1642 (setq num (max 0 (- (cdr active) num)))))
1643 ;; Set the number of unread articles.
1645 (gnus-group-entry (gnus-info-group info)))
1646 (setcar (gnus-group-entry (gnus-info-group info)) num))
1649 ;; Go though `gnus-newsrc-alist' and compare with `gnus-active-hashtb'
1650 ;; and compute how many unread articles there are in each group.
1651 (defun gnus-get-unread-articles (&optional level)
1652 (setq gnus-server-method-cache nil)
1653 (let* ((newsrc (cdr gnus-newsrc-alist))
1654 (level (or level gnus-activate-level (1+ gnus-level-subscribed)))
1657 (cond ((and gnus-activate-foreign-newsgroups
1658 (not (numberp gnus-activate-foreign-newsgroups)))
1659 (1+ gnus-level-subscribed))
1660 ((numberp gnus-activate-foreign-newsgroups)
1661 gnus-activate-foreign-newsgroups)
1666 scanned-methods info group active method retrieve-groups cmethod
1668 (gnus-message 6 "Checking new news...")
1671 (setq active (gnus-active (setq group (gnus-info-group
1672 (setq info (pop newsrc))))))
1674 ;; Check newsgroups. If the user doesn't want to check them, or
1675 ;; they can't be checked (for instance, if the news server can't
1676 ;; be reached) we just set the number of unread articles in this
1677 ;; newsgroup to t. This means that Gnus thinks that there are
1678 ;; unread articles, but it has no idea how many.
1680 ;; To be more explicit:
1681 ;; >0 for an active group with messages
1682 ;; 0 for an active group with no unread messages
1683 ;; nil for non-foreign groups that the user has requested not be checked
1684 ;; t for unchecked foreign groups or bogus groups, or groups that can't
1685 ;; be checked, for one reason or other.
1686 (when (setq method (gnus-info-method info))
1687 (if (setq cmethod (assoc method methods-cache))
1688 (setq method (cdr cmethod))
1689 (setq cmethod (inline (gnus-server-get-method nil method)))
1690 (push (cons method cmethod) methods-cache)
1691 (setq method cmethod)))
1693 (not (setq method-type (cdr (assoc method type-cache)))))
1696 ((gnus-secondary-method-p method)
1698 ((inline (gnus-server-equal gnus-select-method method))
1702 (push (cons method method-type) type-cache))
1704 (cond ((and method (eq method-type 'foreign))
1705 ;; These groups are foreign. Check the level.
1706 (if (<= (gnus-info-level info) foreign-level)
1707 (when (and (<= (gnus-info-level info) foreign-level)
1708 (setq active (gnus-activate-group group 'scan)))
1709 ;; Let the Gnus agent save the active file.
1710 (when (and gnus-agent active (gnus-online method))
1711 (gnus-agent-save-group-info
1712 method (gnus-group-real-name group) active))
1713 (unless (inline (gnus-virtual-group-p group))
1714 (inline (gnus-close-group group)))
1715 (when (fboundp (intern (concat (symbol-name (car method))
1716 "-request-update-info")))
1717 (inline (gnus-request-update-info info method))))
1718 (setq active 'ignore)))
1719 ;; These groups are native or secondary.
1720 ((> (gnus-info-level info) level)
1721 ;; We don't want these groups.
1722 (setq active 'ignore))
1724 ((not gnus-read-active-file)
1725 (if (gnus-check-backend-function 'retrieve-groups group)
1726 ;; if server support gnus-retrieve-groups we push
1727 ;; the group onto retrievegroups for later checking
1728 (if (assoc method retrieve-groups)
1729 (setcdr (assoc method retrieve-groups)
1730 (cons group (cdr (assoc method retrieve-groups))))
1731 (push (list method group) retrieve-groups))
1732 ;; hack: `nnmail-get-new-mail' changes the mail-source depending
1733 ;; on the group, so we must perform a scan for every group
1734 ;; if the users has any directory mail sources.
1735 ;; hack: if `nnmail-scan-directory-mail-source-once' is non-nil,
1736 ;; for it scan all spool files even when the groups are
1739 (or nnmail-scan-directory-mail-source-once
1740 (null (assq 'directory
1742 (if (listp nnmail-spool-file)
1744 (list nnmail-spool-file))))))
1745 (member method scanned-methods))
1746 (setq active (gnus-activate-group group))
1747 (setq active (gnus-activate-group group 'scan))
1748 (push method scanned-methods))
1750 (gnus-close-group group)))))
1752 ;; Get the number of unread articles in the group.
1754 ((eq active 'ignore)
1755 ;; Don't do anything.
1758 (inline (gnus-get-unread-articles-in-group info active t)))
1760 ;; The group couldn't be reached, so we nix out the number of
1761 ;; unread articles and stuff.
1762 (gnus-set-active group nil)
1763 (let ((tmp (gnus-group-entry group)))
1767 ;; iterate through groups on methods which support gnus-retrieve-groups
1768 ;; and fetch a partial active file and use it to find new news.
1769 (dolist (rg retrieve-groups)
1770 (let ((method (or (car rg) gnus-select-method))
1772 (when (gnus-check-server method)
1773 ;; Request that the backend scan its incoming messages.
1774 (when (gnus-check-backend-function 'request-scan (car method))
1775 (gnus-request-scan nil method))
1776 (gnus-read-active-file-2
1777 (mapcar (lambda (group) (gnus-group-real-name group)) groups)
1779 (dolist (group groups)
1781 ((setq active (gnus-active (gnus-info-group
1782 (setq info (gnus-get-info group)))))
1783 (inline (gnus-get-unread-articles-in-group info active t)))
1785 ;; The group couldn't be reached, so we nix out the number of
1786 ;; unread articles and stuff.
1787 (gnus-set-active group nil)
1788 (setcar (gnus-group-entry group) t)))))))
1790 (gnus-message 6 "Checking new news...done")))
1792 ;; Create a hash table out of the newsrc alist. The `car's of the
1793 ;; alist elements are used as keys.
1794 (defun gnus-make-hashtable-from-newsrc-alist ()
1795 (let ((alist gnus-newsrc-alist)
1796 (ohashtb gnus-newsrc-hashtb)
1798 (setq gnus-newsrc-hashtb (gnus-make-hashtable (length alist)))
1800 (setq prev (setq gnus-newsrc-alist
1801 (if (equal (caar gnus-newsrc-alist)
1804 (cons (list "dummy.group" 0 nil) alist)))))
1808 ;; Preserve number of unread articles in groups.
1809 (cons (and ohashtb (car (gnus-gethash (caar alist) ohashtb)))
1813 alist (cdr alist)))))
1815 (defun gnus-make-hashtable-from-killed ()
1816 "Create a hash table from the killed and zombie lists."
1817 (let ((lists '(gnus-killed-list gnus-zombie-list))
1819 (setq gnus-killed-hashtb
1820 (gnus-make-hashtable
1821 (+ (length gnus-killed-list) (length gnus-zombie-list))))
1823 (setq list (symbol-value (pop lists)))
1825 (gnus-sethash (car list) (pop list) gnus-killed-hashtb)))))
1827 (defun gnus-parse-active ()
1828 "Parse active info in the nntp server buffer."
1830 (set-buffer nntp-server-buffer)
1831 (goto-char (point-min))
1832 ;; Parse the result we got from `gnus-request-group'.
1833 (when (looking-at "[0-9]+ [0-9]+ \\([0-9]+\\) [0-9]+")
1834 (goto-char (match-beginning 1))
1835 (cons (read (current-buffer))
1836 (read (current-buffer))))))
1838 (defun gnus-make-articles-unread (group articles)
1839 "Mark ARTICLES in GROUP as unread."
1840 (let* ((info (nth 2 (or (gnus-group-entry group)
1842 (gnus-group-real-name group)))))
1843 (ranges (gnus-info-read info))
1846 (when (gnus-member-of-range
1847 (setq article (pop articles)) ranges)
1848 (push article news)))
1850 ;; Enter this list into the group info.
1852 info (gnus-remove-from-range (gnus-info-read info) (nreverse news)))
1854 ;; Set the number of unread articles in gnus-newsrc-hashtb.
1855 (gnus-get-unread-articles-in-group info (gnus-active group))
1857 ;; Insert the change into the group buffer and the dribble file.
1858 (gnus-group-update-group group t))))
1860 (defun gnus-make-ascending-articles-unread (group articles)
1861 "Mark ascending ARTICLES in GROUP as unread."
1862 (let* ((entry (or (gnus-group-entry group)
1863 (gnus-group-entry (gnus-group-real-name group))))
1864 (info (nth 2 entry))
1865 (ranges (gnus-info-read info))
1870 (let ((article (pop articles))) ; get the next article to remove from ranges
1871 (while (let ((range (car ranges))) ; note the current range
1872 (if (atom range) ; single value range
1874 ;; the articles extend past the end of the ranges
1876 (setq articles nil))
1878 ;; this range preceeds the article. Leave the range unmodified.
1882 ;; this range exactly matches the article; REMOVE THE RANGE.
1883 ;; NOTE: When the range being removed is the last range, the list is corrupted by inserting null at its end.
1884 (setcar ranges (cadr ranges))
1885 (setcdr ranges (cddr ranges))
1886 (setq modified (if (car ranges) t 'remove-null))
1888 (let ((min (car range))
1890 ;; I have a min/max range to consider
1891 (cond ((> min max) ; invalid range introduced by splitter
1892 (setcar ranges (cadr ranges))
1893 (setcdr ranges (cddr ranges))
1894 (setq modified (if (car ranges) t 'remove-null))
1897 ;; replace min/max range with a single-value range
1901 ;; this range preceeds the article. Leave the range unmodified.
1905 ;; this article preceeds the range. Return null to move to the
1909 ;; this article splits the range into two parts
1910 (setcdr ranges (cons (cons (1+ article) max) (cdr ranges)))
1911 (setcdr range (1- article))
1916 (when (eq modified 'remove-null)
1917 (setq r (delq nil r)))
1918 ;; Enter this list into the group info.
1919 (gnus-info-set-read info r)
1921 ;; Set the number of unread articles in gnus-newsrc-hashtb.
1922 (gnus-get-unread-articles-in-group info (gnus-active group))
1924 ;; Insert the change into the group buffer and the dribble file.
1925 (gnus-group-update-group group t))))
1927 ;; Enter all dead groups into the hashtb.
1928 (defun gnus-update-active-hashtb-from-killed ()
1929 (let ((hashtb (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
1930 (lists (list gnus-killed-list gnus-zombie-list))
1933 (setq killed (car lists))
1935 (gnus-sethash (car killed) nil hashtb)
1936 (setq killed (cdr killed)))
1937 (setq lists (cdr lists)))))
1939 (defun gnus-get-killed-groups ()
1940 "Go through the active hashtb and mark all unknown groups as killed."
1941 ;; First make sure active file has been read.
1942 (unless (gnus-read-active-file-p)
1943 (let ((gnus-read-active-file t))
1944 (gnus-read-active-file)))
1945 (unless gnus-killed-hashtb
1946 (gnus-make-hashtable-from-killed))
1947 ;; Go through all newsgroups that are known to Gnus - enlarge kill list.
1951 (group (symbol-name sym)))
1952 (if (or (null group)
1953 (gnus-gethash group gnus-killed-hashtb)
1954 (gnus-gethash group gnus-newsrc-hashtb))
1956 (let ((do-sub (gnus-matches-options-n group)))
1957 (if (or (eq do-sub 'subscribe) (eq do-sub 'ignore))
1959 (setq groups (1+ groups))
1960 (push group gnus-killed-list)
1961 (gnus-sethash group group gnus-killed-hashtb))))))
1963 (gnus-dribble-touch))
1965 ;; Get the active file(s) from the backend(s).
1966 (defun gnus-read-active-file (&optional force not-native)
1967 (gnus-group-set-mode-line)
1970 (lambda (m) (if (stringp m) (gnus-server-get-method nil m) m))
1972 (if (and (not not-native)
1973 (gnus-check-server gnus-select-method))
1974 ;; The native server is available.
1975 (cons gnus-select-method gnus-secondary-select-methods)
1976 ;; The native server is down, so we just do the
1978 gnus-secondary-select-methods)
1979 ;; Also read from the archive server.
1980 (when (gnus-archive-server-wanted-p)
1981 (list "archive")))))
1983 (setq gnus-have-read-active-file nil)
1985 (set-buffer nntp-server-buffer)
1986 (while (setq method (pop methods))
1987 ;; Only do each method once, in case the methods appear more
1988 ;; than once in this list.
1989 (unless (member method methods)
1990 (if (or debug-on-error debug-on-quit)
1991 (gnus-read-active-file-1 method force)
1993 (gnus-read-active-file-1 method force)
1994 ;; We catch C-g so that we can continue past servers
1995 ;; that do not respond.
1997 (message "Quit reading the active file")
2000 (defun gnus-read-active-file-1 (method force)
2002 (setq where (nth 1 method)
2003 mesg (format "Reading active file%s via %s..."
2004 (if (and where (not (zerop (length where))))
2005 (concat " from " where) "")
2007 (gnus-message 5 mesg)
2008 (when (gnus-check-server method)
2009 ;; Request that the backend scan its incoming messages.
2010 (when (gnus-check-backend-function 'request-scan (car method))
2011 (gnus-request-scan nil method))
2013 ((and (eq gnus-read-active-file 'some)
2014 (gnus-check-backend-function 'retrieve-groups (car method))
2016 (let ((newsrc (cdr gnus-newsrc-alist))
2017 (gmethod (gnus-server-get-method nil method))
2019 (while (setq info (pop newsrc))
2023 (gnus-find-method-for-group
2024 (gnus-info-group info) info))
2026 (push (gnus-group-real-name (gnus-info-group info))
2028 (gnus-read-active-file-2 groups method)))
2032 (if (not (gnus-request-list method))
2033 (unless (equal method gnus-message-archive-method)
2034 (gnus-error 1 "Cannot read active file from %s server"
2036 (gnus-message 5 mesg)
2037 (gnus-active-to-gnus-format method gnus-active-hashtb nil t)
2038 ;; We mark this active file as read.
2039 (push method gnus-have-read-active-file)
2040 (gnus-message 5 "%sdone" mesg)))))))
2042 (defun gnus-read-active-file-2 (groups method)
2043 "Read an active file for GROUPS in METHOD using `gnus-retrieve-groups'."
2046 (set-buffer nntp-server-buffer)
2047 (gnus-check-server method)
2048 (let ((list-type (gnus-retrieve-groups groups method)))
2049 (cond ((not list-type)
2051 1.2 "Cannot read partial active file from %s server."
2053 ((eq list-type 'active)
2054 (gnus-active-to-gnus-format method gnus-active-hashtb nil t))
2056 (gnus-groups-to-gnus-format method gnus-active-hashtb t)))))))
2058 ;; Read an active file and place the results in `gnus-active-hashtb'.
2059 (defun gnus-active-to-gnus-format (&optional method hashtb ignore-errors
2062 (setq method gnus-select-method))
2063 (let ((cur (current-buffer))
2065 (if (and gnus-active-hashtb
2066 (not (equal method gnus-select-method)))
2068 (setq gnus-active-hashtb
2069 (if (equal method gnus-select-method)
2070 (gnus-make-hashtable
2071 (count-lines (point-min) (point-max)))
2072 (gnus-make-hashtable 4096)))))))
2073 ;; Delete unnecessary lines.
2074 (goto-char (point-min))
2076 ((string= gnus-ignored-newsgroups "")
2077 (delete-matching-lines "^to\\."))
2079 (delete-matching-lines (concat "^to\\.\\|" gnus-ignored-newsgroups))))
2081 (goto-char (point-min))
2082 (unless (re-search-forward "[\\\"]" nil t)
2083 ;; Make the group names readable as a lisp expression even if they
2084 ;; contain special characters.
2085 (goto-char (point-max))
2086 (while (re-search-backward "[][';?()#]" nil t)
2089 ;; Let the Gnus agent save the active file.
2090 (when (and gnus-agent real-active (gnus-online method))
2091 (gnus-agent-save-active method))
2093 ;; If these are groups from a foreign select method, we insert the
2094 ;; group prefix in front of the group names.
2095 (when (not (gnus-server-equal
2096 (gnus-server-get-method nil method)
2097 (gnus-server-get-method nil gnus-select-method)))
2098 (let ((prefix (gnus-group-prefixed-name "" method)))
2099 (goto-char (point-min))
2100 (while (and (not (eobp))
2102 (when (= (following-char) ?\")
2105 (zerop (forward-line 1)))))))
2106 ;; Store the active file in a hash table.
2107 (goto-char (point-min))
2108 (let (group max min)
2112 (narrow-to-region (point) (point-at-eol))
2113 ;; group gets set to a symbol interned in the hash table
2114 ;; (what a hack!!) - jwz
2115 (setq group (let ((obarray hashtb)) (read cur)))
2116 ;; ### The extended group name scheme makes
2117 ;; the previous optimization strategy sort of pointless...
2118 (when (stringp group)
2119 (setq group (intern group hashtb)))
2120 (if (and (numberp (setq max (read cur)))
2121 (numberp (setq min (read cur)))
2123 (skip-chars-forward " \t")
2125 (or (eq (char-after) ?=)
2126 (eq (char-after) ?x)
2127 (eq (char-after) ?j)))))
2129 (set group (cons min max))
2130 ;; if group is moderated, stick in moderation table
2131 (when (eq (char-after) ?m)
2132 (unless gnus-moderated-hashtb
2133 (setq gnus-moderated-hashtb (gnus-make-hashtable)))
2134 (gnus-sethash (symbol-name group) t
2135 gnus-moderated-hashtb)))
2141 (unless ignore-errors
2142 (gnus-message 3 "Warning - invalid active: %s"
2144 (point-at-bol) (point-at-eol))))))
2146 (forward-line 1)))))
2148 (defun gnus-groups-to-gnus-format (method &optional hashtb real-active)
2149 ;; Parse a "groups" active file.
2150 (let ((cur (current-buffer))
2152 (if (and method gnus-active-hashtb)
2154 (setq gnus-active-hashtb
2155 (gnus-make-hashtable
2156 (count-lines (point-min) (point-max)))))))
2158 (not (gnus-server-equal
2159 (gnus-server-get-method nil method)
2160 (gnus-server-get-method nil gnus-select-method)))
2161 (gnus-group-prefixed-name "" method))))
2163 ;; Let the Gnus agent save the active file.
2166 (gnus-online method)
2167 (gnus-agent-method-p method))
2169 (gnus-agent-save-active method)
2170 (gnus-active-to-gnus-format method hashtb nil real-active))
2172 (goto-char (point-min))
2173 ;; We split this into to separate loops, one with the prefix
2174 ;; and one without to speed the reading up somewhat.
2176 (let (min max opoint group)
2180 (read cur) (read cur)
2181 (setq min (read cur)
2184 (skip-chars-forward " \t")
2187 (set (let ((obarray hashtb)) (read cur))
2189 (error (and group (symbolp group) (set group nil))))
2191 (let (min max group)
2194 (when (eq (char-after) ?2)
2195 (read cur) (read cur)
2196 (setq min (read cur)
2198 (set (setq group (let ((obarray hashtb)) (read cur)))
2200 (error (and group (symbolp group) (set group nil))))
2201 (forward-line 1)))))))
2203 (defun gnus-read-newsrc-file (&optional force)
2205 If FORCE is non-nil, the .newsrc file is read."
2206 ;; Reset variables that might be defined in the .newsrc.eld file.
2207 (gnus-clear-quick-file-variables)
2208 (let* ((newsrc-file gnus-current-startup-file)
2209 (quick-file (concat newsrc-file ".el")))
2211 ;; We always load the .newsrc.eld file. If always contains
2212 ;; much information that can not be gotten from the .newsrc
2213 ;; file (ticked articles, killed groups, foreign methods, etc.)
2214 (gnus-read-newsrc-el-file quick-file)
2216 (when (and gnus-read-newsrc-file
2217 (file-exists-p gnus-current-startup-file)
2219 (and (file-newer-than-file-p newsrc-file quick-file)
2220 (file-newer-than-file-p newsrc-file
2221 (concat quick-file "d")))
2222 (not gnus-newsrc-alist)))
2223 ;; We read the .newsrc file. Note that if there if a
2224 ;; .newsrc.eld file exists, it has already been read, and
2225 ;; the `gnus-newsrc-hashtb' has been created. While reading
2226 ;; the .newsrc file, Gnus will only use the information it
2227 ;; can find there for changing the data already read -
2228 ;; i. e., reading the .newsrc file will not trash the data
2229 ;; already read (except for read articles).
2231 (gnus-message 5 "Reading %s..." newsrc-file)
2232 (set-buffer (nnheader-find-file-noselect newsrc-file))
2233 (buffer-disable-undo)
2234 (gnus-newsrc-to-gnus-format)
2235 (kill-buffer (current-buffer))
2236 (gnus-message 5 "Reading %s...done" newsrc-file))))))
2238 (quote (;; T-gnus doesn't provide those functions.
2239 (defun gnus-convert-old-newsrc ()
2240 "Convert old newsrc formats into the current format, if needed."
2241 (let ((fcv (and gnus-newsrc-file-version
2242 (gnus-continuum-version gnus-newsrc-file-version))))
2244 ;; A .newsrc.eld file was loaded.
2245 (let (prompt-displayed
2248 (mapcar (lambda (date-func)
2249 (cons (gnus-continuum-version (car date-func))
2251 ;; This is a list of converters that must be run
2252 ;; to bring the newsrc file up to the current
2253 ;; version. If you create an incompatibility
2254 ;; with older versions, you should create an
2255 ;; entry here. The entry should consist of the
2256 ;; current gnus version (hardcoded so that it
2257 ;; doesn't change with each release) and the
2258 ;; function that must be applied to convert the
2259 ;; previous version into the current version.
2260 '(("September Gnus v0.1" nil
2261 gnus-convert-old-ticks)
2262 ("Oort Gnus v0.08" "legacy-gnus-agent"
2263 gnus-agent-convert-to-compressed-agentview)
2264 ("No Gnus v0.2" "legacy-gnus-agent"
2265 gnus-agent-unlist-expire-days)
2266 ("No Gnus v0.2" "legacy-gnus-agent"
2267 gnus-agent-unhook-expire-days)))
2268 #'car-less-than-car)))
2269 ;; Skip converters older than the file version
2270 (while (and converters (>= fcv (caar converters)))
2273 ;; Perform converters to bring older version up to date.
2274 (when (and converters (< fcv (caar converters)))
2275 (while (and converters (< fcv (caar converters)))
2276 (let* ((converter-spec (pop converters))
2277 (convert-to (nth 1 converter-spec))
2278 (load-from (nth 2 converter-spec))
2279 (func (nth 3 converter-spec)))
2280 (when (and load-from
2281 (not (fboundp func)))
2284 (or prompt-displayed
2285 (not (gnus-convert-converter-needs-prompt func))
2287 (cursor-in-echo-area t)
2288 (echo-keystrokes 0))
2289 (message "Convert newsrc from version '%s' to '%s'? (n/y/?)"
2290 gnus-newsrc-file-version gnus-version)
2291 (setq c (read-char-exclusive))
2293 (cond ((or (eq c ?n) (eq c ?N))
2294 (error "Can not start gnus using old (unconverted) newsrc"))
2295 ((or (eq c ?y) (eq c ?Y))
2296 (setq prompt-displayed t)
2299 (message "This conversion is irreversible. \
2300 You should backup your files before proceeding.")
2304 (gnus-message 3 "Ignoring unexpected input")
2308 (funcall func convert-to)))
2310 (format ";Converted newsrc from version '%s' to '%s'? (n/y/?)"
2311 gnus-newsrc-file-version gnus-version)))))))
2313 (defun gnus-convert-mark-converter-prompt (converter no-prompt)
2315 (let* ((symbol 'gnus-convert-no-prompt)
2316 (value (delq symbol (symbol-plist converter))))
2321 (defun gnus-convert-converter-needs-prompt (converter)
2322 (not (memq 'gnus-convert-no-prompt (symbol-plist converter))))
2324 (defun gnus-convert-old-ticks (converting-to)
2325 (let ((newsrc (cdr gnus-newsrc-alist))
2326 marks info dormant ticked)
2327 (while (setq info (pop newsrc))
2328 (when (setq marks (gnus-info-marks info))
2329 (setq dormant (cdr (assq 'dormant marks))
2330 ticked (cdr (assq 'tick marks)))
2331 (when (or dormant ticked)
2335 (gnus-info-read info)
2336 (nconc (gnus-uncompress-range dormant)
2337 (gnus-uncompress-range ticked)))))))))
2340 (defun gnus-load (file &optional coding-system)
2341 "Load FILE, but in such a way that read errors can be reported."
2344 (insert-file-contents-as-coding-system coding-system file)
2345 (insert-file-contents file))
2347 (condition-case type
2348 (let ((form (read (current-buffer))))
2351 (unless (eq (car type) 'end-of-file)
2352 (let ((error (format "Error in %s line %d" file
2353 (count-lines (point-min) (point)))))
2355 (unless (gnus-yes-or-no-p (concat error "; continue? "))
2356 (error "%s" error)))))))))
2358 (defun gnus-read-newsrc-el-file (file)
2359 (let ((ding-file (concat file "d")))
2360 (when (file-exists-p ding-file)
2361 ;; We always, always read the .eld file.
2362 (gnus-message 5 "Reading %s..." ding-file)
2363 (let (gnus-newsrc-assoc)
2364 (gnus-load ding-file gnus-ding-file-coding-system)
2365 ;; ;; Older versions of `gnus-format-specs' are no longer valid
2366 ;; ;; in Oort Gnus 0.01.
2368 ;; (and gnus-newsrc-file-version
2369 ;; (gnus-continuum-version gnus-newsrc-file-version))))
2370 ;; (when (or (not version)
2371 ;; (< version 5.090009))
2372 ;; (setq gnus-format-specs gnus-default-format-specs)))
2373 (when gnus-newsrc-assoc
2374 (setq gnus-newsrc-alist gnus-newsrc-assoc))))
2375 (gnus-make-hashtable-from-newsrc-alist)
2376 (when (file-newer-than-file-p file ding-file)
2377 ;; Old format quick file
2378 (gnus-message 5 "Reading %s..." file)
2379 ;; The .el file is newer than the .eld file, so we read that one
2381 (gnus-read-old-newsrc-el-file file)))
2382 (when (and gnus-product-directory
2383 (file-directory-p gnus-product-directory))
2384 (let ((list gnus-product-variable-file-list))
2386 (apply 'gnus-product-read-variable-file-1 (car list))
2387 (setq list (cdr list)))))
2388 (gnus-run-hooks 'gnus-read-newsrc-el-hook))
2390 ;;(defun gnus-re-read-newsrc-el-file (file)
2391 ;; "Attempt to re-read .newsrc.eld file. Returns nil if successful.
2392 ;;The backup file \".newsrc.eld_\" will be created before re-reading."
2393 ;; (message "Error in %s; retrying..." file)
2395 ;; (condition-case nil
2396 ;; (let ((backup (concat file "_")))
2397 ;; (copy-file file backup 'ok-if-already-exists 'keep-time)
2398 ;; (message " (The backup file %s has been created)" backup)
2402 ;; (insert-file-contents-as-binary file nil nil nil 'replace)
2403 ;; (goto-char (point-min))
2404 ;; (when (re-search-forward
2405 ;; "^[\t ]*([\t\n\r ]*setq[\t\n\r ]+gnus-format-specs" nil t)
2406 ;; (delete-region (goto-char (match-beginning 0)) (forward-list 1))
2407 ;; (decode-coding-region (point-min) (point-max)
2408 ;; gnus-ding-file-coding-system)
2409 ;; (condition-case nil
2411 ;; (eval-region (point-min) (point-max))
2416 ;; (message "Error in %s; retrying...done" file))
2417 ;; (message "Error in %s; retrying...failed" file)
2420 (defun gnus-product-read-variable-file-1 (file checking-methods coding
2422 (let (error gnus-product-file-version method file-ver)
2423 (when (or (condition-case err
2424 (let ((coding-system-for-read coding))
2425 (load (expand-file-name file gnus-product-directory)
2429 (message "Error while reading %s: %s"
2430 (expand-file-name file gnus-product-directory)
2431 (error-message-string err))
2433 (and (setq method (assq 'product-version checking-methods))
2434 (not (and (setq file-ver
2435 (cdr (assq 'product-version
2436 gnus-product-file-version)))
2437 (zerop (product-version-compare file-ver
2439 (and (assq 'emacs-version checking-methods)
2440 (not (and (assq 'emacs-version gnus-product-file-version)
2443 (cdr (assq 'emacs-version
2444 gnus-product-file-version))))))
2445 (and (assq 'correct-string-widths checking-methods)
2446 (not (and (assq 'correct-string-widths
2447 gnus-product-file-version)
2448 (eq (and gnus-use-correct-string-widths t)
2449 (and (cdr (assq 'correct-string-widths
2450 gnus-product-file-version))
2453 (message "\"%s\" seems to have mismatched contents, updating..."
2456 (set (car variables) nil)
2457 (gnus-product-variable-touch (car variables))
2458 (setq variables (cdr variables))))))
2460 ;; Parse the old-style quick startup file
2461 (defun gnus-read-old-newsrc-el-file (file)
2462 (let (newsrc killed marked group m info)
2464 (let ((gnus-killed-assoc nil)
2465 gnus-marked-assoc gnus-newsrc-alist gnus-newsrc-assoc)
2469 (setq newsrc gnus-newsrc-assoc
2470 killed gnus-killed-assoc
2471 marked gnus-marked-assoc)))
2472 (setq gnus-newsrc-alist nil)
2473 (while (setq group (pop newsrc))
2474 (if (setq info (gnus-get-info (car group)))
2476 (gnus-info-set-read info (cddr group))
2477 (gnus-info-set-level
2478 info (if (nth 1 group) gnus-level-default-subscribed
2479 gnus-level-default-unsubscribed))
2480 (push info gnus-newsrc-alist))
2483 (if (nth 1 group) gnus-level-default-subscribed
2484 gnus-level-default-unsubscribed)
2487 ;; Copy marks into info.
2488 (when (setq m (assoc (car group) marked))
2489 (unless (nthcdr 3 info)
2490 (nconc info (list nil)))
2491 (gnus-info-set-marks
2492 info (list (cons 'tick (gnus-compress-sequence
2493 (sort (cdr m) '<) t))))))
2494 (setq newsrc killed)
2496 (setcar newsrc (caar newsrc))
2497 (setq newsrc (cdr newsrc)))
2498 (setq gnus-killed-list killed))
2499 ;; The .el file version of this variable does not begin with
2500 ;; "options", while the .eld version does, so we just add it if it
2504 (when (not (string-match "^ *options" gnus-newsrc-options))
2505 (setq gnus-newsrc-options (concat "options " gnus-newsrc-options)))
2506 (when (not (string-match "\n$" gnus-newsrc-options))
2507 (setq gnus-newsrc-options (concat gnus-newsrc-options "\n")))
2508 ;; Finally, if we read some options lines, we parse them.
2509 (unless (string= gnus-newsrc-options "")
2510 (gnus-newsrc-parse-options gnus-newsrc-options)))
2512 (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist))
2513 (gnus-make-hashtable-from-newsrc-alist)))
2515 (defun gnus-make-newsrc-file (file)
2516 "Make server dependent file name by catenating FILE and server host name."
2517 (let* ((file (expand-file-name file nil))
2518 (real-file (concat file "-" (nth 1 gnus-select-method))))
2519 (if (or (file-exists-p real-file)
2520 (file-exists-p (concat real-file ".el"))
2521 (file-exists-p (concat real-file ".eld")))
2525 (defun gnus-newsrc-to-gnus-format ()
2526 (setq gnus-newsrc-options "")
2527 (setq gnus-newsrc-options-n nil)
2529 (unless gnus-active-hashtb
2530 (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
2531 (let ((buf (current-buffer))
2532 (already-read (> (length gnus-newsrc-alist) 1))
2533 group subscribed options-symbol newsrc Options-symbol
2535 (goto-char (point-min))
2536 ;; We intern the symbol `options' in the active hashtb so that we
2537 ;; can `eq' against it later.
2538 (set (setq options-symbol (intern "options" gnus-active-hashtb)) nil)
2539 (set (setq Options-symbol (intern "Options" gnus-active-hashtb)) nil)
2542 ;; We first read the first word on the line by narrowing and
2543 ;; then reading into `gnus-active-hashtb'. Most groups will
2544 ;; already exist in that hashtb, so this will save some string
2548 (progn (skip-chars-forward "^ \t!:\n") (point)))
2549 (goto-char (point-min))
2551 (and (/= (point-min) (point-max))
2552 (let ((obarray gnus-active-hashtb)) (read buf))))
2554 ;; Now, the symbol we have read is either `options' or a group
2555 ;; name. If it is an options line, we just add it to a string.
2557 ((or (eq symbol options-symbol)
2558 (eq symbol Options-symbol))
2559 (setq gnus-newsrc-options
2560 ;; This concating is quite inefficient, but since our
2561 ;; thorough studies show that approx 99.37% of all
2562 ;; .newsrc files only contain a single options line, we
2563 ;; don't give a damn, frankly, my dear.
2564 (concat gnus-newsrc-options
2567 ;; Options may continue on the next line.
2568 (or (and (re-search-forward "^[^ \t]" nil 'move)
2573 ;; Group names can be just numbers.
2574 (when (numberp symbol)
2575 (setq symbol (intern (int-to-string symbol) gnus-active-hashtb)))
2576 (unless (boundp symbol)
2578 ;; It was a group name.
2579 (setq subscribed (eq (char-after) ?:)
2580 group (symbol-name symbol)
2583 ;; If the line ends here, this is clearly a buggy line, so
2584 ;; we put point a the beginning of line and let the cond
2585 ;; below do the error handling.
2587 ;; We skip to the beginning of the ranges.
2588 (skip-chars-forward "!: \t"))
2589 ;; We are now at the beginning of the list of read articles.
2590 ;; We read them range by range.
2593 ((looking-at "[0-9]+")
2594 ;; We narrow and read a number instead of buffer-substring/
2595 ;; string-to-int because it's faster. narrow/widen is
2596 ;; faster than save-restriction/narrow, and save-restriction
2597 ;; produces a garbage object.
2599 (narrow-to-region (match-beginning 0) (match-end 0))
2602 ;; If the next character is a dash, then this is a range.
2603 (if (eq (char-after) ?-)
2605 ;; We read the upper bound of the range.
2607 (if (not (looking-at "[0-9]+"))
2608 ;; This is a buggy line, by we pretend that
2609 ;; it's kinda OK. Perhaps the user should be
2615 (narrow-to-region (match-beginning 0)
2620 ;; It was just a simple number, so we add it to the
2623 ;; If the next char in ?\n, then we have reached the end
2624 ;; of the line and return nil.
2625 (not (eq (char-after) ?\n)))
2626 ((eq (char-after) ?\n)
2627 ;; End of line, so we end.
2630 ;; Not numbers and not eol, so this might be a buggy
2633 ;; If it was eob instead of ?\n, we allow it.
2634 ;; The line was buggy.
2636 (gnus-error 3.1 "Mangled line: %s"
2637 (buffer-substring (point-at-bol)
2640 ;; Skip past ", ". Spaces are invalid in these ranges, but
2641 ;; we allow them, because it's a common mistake to put a
2642 ;; space after the comma.
2643 (skip-chars-forward ", "))
2645 ;; We have already read .newsrc.eld, so we gently update the
2646 ;; data in the hash table with the information we have just
2649 (let ((info (gnus-get-info group))
2652 ;; There is an entry for this file in the alist.
2654 (gnus-info-set-read info (nreverse reads))
2655 ;; We update the level very gently. In fact, we
2656 ;; only change it if there's been a status change
2657 ;; from subscribed to unsubscribed, or vice versa.
2658 (setq level (gnus-info-level info))
2659 (cond ((and (<= level gnus-level-subscribed)
2661 (setq level (if reads
2662 gnus-level-default-unsubscribed
2663 (1+ gnus-level-default-unsubscribed))))
2664 ((and (> level gnus-level-subscribed) subscribed)
2665 (setq level gnus-level-default-subscribed)))
2666 (gnus-info-set-level info level))
2667 ;; This is a new group.
2668 (setq info (list group
2670 gnus-level-default-subscribed
2672 (1+ gnus-level-subscribed)
2673 gnus-level-default-unsubscribed))
2675 (push info newsrc)))))
2678 (setq newsrc (nreverse newsrc))
2680 (if (not already-read)
2682 ;; We now have two newsrc lists - `newsrc', which is what we
2683 ;; have read from .newsrc, and `gnus-newsrc-alist', which is
2684 ;; what we've read from .newsrc.eld. We have to merge these
2685 ;; lists. We do this by "attaching" any (foreign) groups in the
2686 ;; gnus-newsrc-alist to the (native) group that precedes them.
2687 (let ((rc (cdr gnus-newsrc-alist))
2688 (prev gnus-newsrc-alist)
2691 (or (null (nth 4 (car rc))) ; It's a native group.
2692 (assoc (caar rc) newsrc) ; It's already in the alist.
2693 (if (setq entry (assoc (caar prev) newsrc))
2694 (setcdr (setq mentry (memq entry newsrc))
2695 (cons (car rc) (cdr mentry)))
2696 (push (car rc) newsrc)))
2700 (setq gnus-newsrc-alist newsrc)
2701 ;; We make the newsrc hashtb.
2702 (gnus-make-hashtable-from-newsrc-alist)
2704 ;; Finally, if we read some options lines, we parse them.
2705 (unless (string= gnus-newsrc-options "")
2706 (gnus-newsrc-parse-options gnus-newsrc-options))))
2708 ;; Parse options lines to find "options -n !all rec.all" and stuff.
2709 ;; The return value will be a list on the form
2710 ;; ((regexp1 . ignore)
2711 ;; (regexp2 . subscribe)...)
2712 ;; When handling new newsgroups, groups that match a `ignore' regexp
2713 ;; will be ignored, and groups that match a `subscribe' regexp will be
2714 ;; subscribed. A line like
2715 ;; options -n !all rec.all
2716 ;; will lead to a list that looks like
2717 ;; (("^rec\\..+" . subscribe)
2718 ;; ("^.+" . ignore))
2719 ;; So all "rec.*" groups will be subscribed, while all the other
2720 ;; groups will be ignored. Note that "options -n !all rec.all" is very
2721 ;; different from "options -n rec.all !all".
2722 (defun gnus-newsrc-parse-options (options)
2725 (gnus-set-work-buffer)
2726 (insert (regexp-quote options))
2727 ;; First we treat all continuation lines.
2728 (goto-char (point-min))
2729 (while (re-search-forward "\n[ \t]+" nil t)
2730 (replace-match " " t t))
2731 ;; Then we transform all "all"s into ".+"s.
2732 (goto-char (point-min))
2733 (while (re-search-forward "\\ball\\b" nil t)
2734 (replace-match ".+" t t))
2735 (goto-char (point-min))
2736 ;; We remove all other options than the "-n" ones.
2737 (while (re-search-forward "[ \t]-[^n][^-]*" nil t)
2740 (goto-char (point-min))
2742 ;; We are only interested in "options -n" lines - we
2743 ;; ignore the other option lines.
2744 (while (re-search-forward "[ \t]-n" nil t)
2747 (and (re-search-forward "[ \t]-n" (point-at-eol) t)
2750 ;; Search for all "words"...
2751 (while (re-search-forward "[^ \t,\n]+" eol t)
2752 (if (eq (char-after (match-beginning 0)) ?!)
2753 ;; If the word begins with a bang (!), this is a "not"
2754 ;; spec. We put this spec (minus the bang) and the
2755 ;; symbol `ignore' into the list.
2757 "^" (buffer-substring
2758 (1+ (match-beginning 0))
2763 ;; There was no bang, so this is a "yes" spec.
2764 (push (cons (concat "^" (match-string 0) "\\($\\|\\.\\)")
2768 (setq gnus-newsrc-options-n out))))
2771 (defalias 'gnus-long-file-names
2772 (if (fboundp 'msdos-long-file-names)
2773 'msdos-long-file-names
2776 (defun gnus-save-newsrc-file (&optional force)
2777 "Save .newsrc file."
2778 ;; Note: We cannot save .newsrc file if all newsgroups are removed
2779 ;; from the variable gnus-newsrc-alist.
2780 (when (and (or gnus-newsrc-alist gnus-killed-list)
2781 gnus-current-startup-file)
2782 ;; Save agent range limits for the currently active method.
2784 (gnus-agent-save-local force))
2787 (if (and (or gnus-use-dribble-file gnus-slave)
2789 (or (not gnus-dribble-buffer)
2790 (not (buffer-name gnus-dribble-buffer))
2791 (zerop (save-excursion
2792 (set-buffer gnus-dribble-buffer)
2794 (gnus-message 4 "(No changes need to be saved)")
2795 (gnus-run-hooks 'gnus-save-newsrc-hook)
2797 (gnus-slave-save-newsrc)
2799 (when gnus-save-newsrc-file
2800 (gnus-message 8 "Saving %s..." gnus-current-startup-file)
2801 (gnus-gnus-to-newsrc-format)
2802 (gnus-message 8 "Saving %s...done" gnus-current-startup-file))
2804 ;; Save .newsrc.eld.
2805 (set-buffer (gnus-get-buffer-create " *Gnus-newsrc*"))
2806 (make-local-variable 'version-control)
2807 (setq version-control gnus-backup-startup-file)
2808 (setq buffer-file-name
2809 (concat gnus-current-startup-file ".eld"))
2810 (setq default-directory (file-name-directory buffer-file-name))
2811 (buffer-disable-undo)
2813 (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file)
2815 (if gnus-save-startup-file-via-temp-buffer
2816 (let ((coding-system-for-write gnus-ding-file-coding-system)
2817 (standard-output (current-buffer)))
2818 (gnus-gnus-to-quick-newsrc-format)
2819 (gnus-run-hooks 'gnus-save-quick-newsrc-hook)
2821 (let ((coding-system-for-write gnus-ding-file-coding-system)
2822 (version-control gnus-backup-startup-file)
2823 (startup-file (concat gnus-current-startup-file ".eld"))
2824 (working-dir (file-name-directory gnus-current-startup-file))
2827 ;; Generate the name of a non-existent file.
2828 (while (progn (setq working-file
2830 (if (and (eq system-type 'ms-dos)
2831 (not (gnus-long-file-names)))
2832 "%s#%d.tm#" ; MSDOS limits files to 8+3
2833 (if (memq system-type '(vax-vms axp-vms))
2836 working-dir (setq i (1+ i))))
2837 (file-exists-p working-file)))
2841 (gnus-with-output-to-file working-file
2842 (gnus-gnus-to-quick-newsrc-format)
2843 (gnus-run-hooks 'gnus-save-quick-newsrc-hook))
2845 ;; These bindings will mislead the current buffer
2846 ;; into thinking that it is visiting the startup
2848 (let ((buffer-backed-up nil)
2849 (buffer-file-name startup-file)
2850 (file-precious-flag t)
2851 (setmodes (file-modes startup-file)))
2852 ;; Backup the current version of the startup file.
2855 ;; Replace the existing startup file with the temp file.
2856 (rename-file working-file startup-file t)
2857 (set-file-modes startup-file setmodes)))
2859 (delete-file working-file)
2860 (file-error nil)))))
2862 (gnus-kill-buffer (current-buffer))
2864 5 "Saving %s.eld...done" gnus-current-startup-file))
2865 (gnus-dribble-delete-file)
2866 (gnus-group-set-mode-line))))
2867 (when gnus-product-directory
2868 (gnus-product-save-variable-file)))
2870 ;; Call the function above at C-x C-c.
2871 (defadvice save-buffers-kill-emacs (before save-gnus-newsrc-file-maybe
2872 activate preactivate)
2873 "Save .newsrc and .newsrc.eld when Emacs is killed."
2874 (when (gnus-alive-p)
2875 (gnus-run-hooks 'gnus-exit-gnus-hook)
2876 (gnus-offer-save-summaries)
2877 (gnus-save-newsrc-file)))
2879 (defun gnus-gnus-to-quick-newsrc-format (&optional minimal name &rest specific-variables)
2880 "Print Gnus variables such as `gnus-newsrc-alist' in Lisp format."
2881 (princ ";; -*- emacs-lisp -*-\n")
2883 (princ (format ";; %s\n" name))
2884 (princ ";; Gnus startup file.\n"))
2888 ;; Never delete this file -- if you want to force Gnus to read the
2889 ;; .newsrc file (if you have one), touch .newsrc instead.\n")
2890 (princ "(setq gnus-newsrc-file-version ")
2891 (princ (gnus-prin1-to-string gnus-version))
2894 (let* ((print-quoted t)
2896 (print-escape-multibyte nil)
2897 (print-escape-nonascii t)
2900 (print-escape-newlines t)
2902 (if (and gnus-save-killed-list
2903 (stringp gnus-save-killed-list))
2904 (gnus-strip-killed-list)
2907 (or specific-variables
2908 (if gnus-save-killed-list gnus-variable-list
2909 ;; Remove the `gnus-killed-list' from the list of variables
2910 ;; to be saved, if required.
2911 (delq 'gnus-killed-list (copy-sequence gnus-variable-list)))))
2912 ;; Peel off the "dummy" group.
2913 (gnus-newsrc-alist (cdr gnus-newsrc-alist))
2915 ;; Insert the variables into the file.
2917 (when (and (boundp (setq variable (pop variables)))
2918 (symbol-value variable))
2920 (princ (symbol-name variable))
2922 (prin1 (symbol-value variable))
2925 (defun gnus-product-variable-touch (&rest variables)
2927 (put (pop variables) 'gnus-product-variable 'dirty)))
2929 (defun gnus-product-variables-dirty-p (variables)
2932 (when (eq (get (car variables) 'gnus-product-variable) 'dirty)
2934 (setq variables (cdr variables)))))
2936 (defun gnus-product-save-variable-file (&optional force)
2937 "Save all product variables to files, when need to be saved."
2938 (let ((list gnus-product-variable-file-list))
2939 (gnus-make-directory gnus-product-directory)
2941 (apply 'gnus-product-save-variable-file-1 force (car list))
2942 (setq list (cdr list)))))
2944 (defun gnus-product-save-variable-file-1 (force file checking-methods coding
2946 "Save a product variable file, when need to be saved."
2948 (gnus-product-variables-dirty-p variables))
2949 (let ((product (product-find 'gnus-vers)))
2950 (set-buffer (gnus-get-buffer-create " *gnus-product*"))
2951 (make-local-variable 'version-control)
2952 (setq version-control 'never)
2953 (setq file (expand-file-name file gnus-product-directory)
2954 buffer-file-name file
2955 default-directory (file-name-directory file))
2956 (buffer-disable-undo)
2958 (gnus-message 5 "Saving %s..." file)
2959 (apply 'gnus-product-quick-file-format product checking-methods coding
2961 (save-buffer-as-coding-system coding)
2962 (kill-buffer (current-buffer))
2964 (put (car variables) 'gnus-product-variable nil)
2965 (setq variables (cdr variables)))
2967 5 "Saving %s...done" file))))
2969 (defun gnus-product-quick-file-format (product checking-methods
2970 coding &rest variables)
2971 "Insert gnus product depend variables in lisp format."
2972 (let ((print-quoted t)
2973 (print-escape-newlines t)
2974 print-length print-level variable param)
2975 (insert (format ";; -*- Mode: emacs-lisp; coding: %s -*-\n" coding))
2976 (insert (format ";; %s startup file.\n" (product-name product)))
2977 (when (setq param (cdr (assq 'product-version checking-methods)))
2978 (insert "(or (>= (product-version-compare "
2979 "(product-version (product-find 'gnus-vers))\n"
2980 "\t\t\t\t '" (apply 'prin1-to-string param) ")\n"
2982 " (error \"This file was created by later version of "
2984 (insert "(setq gnus-product-file-version\n"
2985 " '((product-version . "
2986 (prin1-to-string (product-version product)) ")\n"
2987 "\t(emacs-version . "
2988 (prin1-to-string emacs-version) ")\n"
2989 "\t(correct-string-widths . "
2990 (if gnus-use-correct-string-widths "t" "nil")
2993 (when (and (boundp (setq variable (pop variables)))
2994 (symbol-value variable))
2995 (insert "(setq " (symbol-name variable) " '")
2996 (gnus-prin1 (symbol-value variable))
2999 (defun gnus-strip-killed-list ()
3000 "Return the killed list minus the groups that match `gnus-save-killed-list'."
3001 (let ((list gnus-killed-list)
3004 (when (string-match gnus-save-killed-list (car list))
3005 (push (car list) olist))
3009 (defun gnus-gnus-to-newsrc-format ()
3010 ;; Generate and save the .newsrc file.
3012 (set-buffer (create-file-buffer gnus-current-startup-file))
3013 (let ((newsrc (cdr gnus-newsrc-alist))
3014 (standard-output (current-buffer))
3015 info ranges range method)
3016 (setq buffer-file-name gnus-current-startup-file)
3017 (setq default-directory (file-name-directory buffer-file-name))
3018 (buffer-disable-undo)
3021 (when gnus-newsrc-options
3022 (insert gnus-newsrc-options))
3023 ;; Write subscribed and unsubscribed.
3024 (while (setq info (pop newsrc))
3025 ;; Don't write foreign groups to .newsrc.
3026 (when (or (null (setq method (gnus-info-method info)))
3027 (equal method "native")
3028 (inline (gnus-server-equal method gnus-select-method)))
3029 (insert (gnus-info-group info)
3030 (if (> (gnus-info-level info) gnus-level-subscribed)
3032 (when (setq ranges (gnus-info-read info))
3034 (if (not (listp (cdr ranges)))
3035 (if (= (car ranges) (cdr ranges))
3036 (princ (car ranges))
3037 (princ (car ranges))
3039 (princ (cdr ranges)))
3040 (while (setq range (pop ranges))
3041 (if (or (atom range) (= (car range) (cdr range)))
3042 (princ (or (and (atom range) range) (car range)))
3045 (princ (cdr range)))
3049 (make-local-variable 'version-control)
3050 (setq version-control 'never)
3051 ;; It has been reported that sometime the modtime on the .newsrc
3052 ;; file seems to be off. We really do want to overwrite it, so
3053 ;; we clear the modtime here before saving. It's a bit odd,
3055 ;; sometimes the modtime clear isn't sufficient. most brute force:
3056 ;; delete the silly thing entirely first. but this fails to provide
3057 ;; such niceties as .newsrc~ creation.
3058 (if gnus-modtime-botch
3059 (delete-file gnus-startup-file)
3060 (clear-visited-file-modtime))
3061 (gnus-run-hooks 'gnus-save-standard-newsrc-hook)
3063 (kill-buffer (current-buffer)))))
3067 ;;; Slave functions.
3070 (defvar gnus-slave-mode nil)
3072 (defun gnus-slave-mode ()
3073 "Minor mode for slave Gnusae."
3074 (add-minor-mode 'gnus-slave-mode " Slave" (make-sparse-keymap))
3075 (gnus-run-hooks 'gnus-slave-mode-hook))
3077 (defun gnus-slave-save-newsrc ()
3079 (set-buffer gnus-dribble-buffer)
3081 (mm-make-temp-file (concat gnus-current-startup-file "-slave-")))
3082 (modes (ignore-errors
3083 (file-modes (concat gnus-current-startup-file ".eld")))))
3084 (gnus-write-buffer-as-coding-system gnus-ding-file-coding-system
3087 (set-file-modes slave-name modes)))))
3089 (defun gnus-master-read-slave-newsrc ()
3092 (file-name-directory gnus-current-startup-file)
3096 (file-name-nondirectory gnus-current-startup-file)
3100 (if (not slave-files)
3101 () ; There are no slave files to read.
3102 (gnus-message 7 "Reading slave newsrcs...")
3104 (set-buffer (gnus-get-buffer-create " *gnus slave*"))
3106 (sort (mapcar (lambda (file)
3107 (list (nth 5 (file-attributes file)) file))
3110 (or (< (caar f1) (caar f2))
3111 (< (nth 1 (car f1)) (nth 1 (car f2)))))))
3114 (setq file (nth 1 (car slave-files)))
3115 (nnheader-insert-file-contents file)
3116 (when (condition-case ()
3118 (eval-buffer (current-buffer))
3121 (gnus-error 3.2 "Possible error in %s" file)
3123 (unless gnus-slave ; Slaves shouldn't delete these files.
3125 (delete-file file))))
3126 (setq slave-files (cdr slave-files))))
3127 (gnus-dribble-touch)
3128 (gnus-message 7 "Reading slave newsrcs...done"))))
3132 ;;; Group description.
3135 (defun gnus-read-all-descriptions-files ()
3136 (let ((methods (cons gnus-select-method
3138 (when (gnus-archive-server-wanted-p)
3140 gnus-secondary-select-methods))))
3142 (gnus-read-descriptions-file (car methods))
3143 (setq methods (cdr methods)))
3146 (defun gnus-read-descriptions-file (&optional method)
3147 (let ((method (or method gnus-select-method))
3149 (when (stringp method)
3150 (setq method (gnus-server-to-method method)))
3151 ;; We create the hashtable whether we manage to read the desc file
3152 ;; to avoid trying to re-read after a failed read.
3153 (unless gnus-description-hashtb
3154 (setq gnus-description-hashtb
3155 (gnus-make-hashtable (length gnus-active-hashtb))))
3156 ;; Mark this method's desc file as read.
3157 (gnus-sethash (gnus-group-prefixed-name "" method) "Has read"
3158 gnus-description-hashtb)
3160 (gnus-message 5 "Reading descriptions file via %s..." (car method))
3162 ((null (gnus-get-function method 'request-list-newsgroups t))
3164 ((not (gnus-check-server method))
3165 (gnus-message 1 "Couldn't open server")
3167 ((not (gnus-request-list-newsgroups method))
3168 (gnus-message 1 "Couldn't read newsgroups descriptions")
3173 (set-buffer nntp-server-buffer)
3174 (goto-char (point-min))
3175 (when (or (search-forward "\n.\n" nil t)
3176 (goto-char (point-max)))
3178 (narrow-to-region (point-min) (point)))
3179 ;; If these are groups from a foreign select method, we insert the
3180 ;; group prefix in front of the group names.
3181 (and method (not (inline
3183 (gnus-server-get-method nil method)
3184 (gnus-server-get-method
3185 nil gnus-select-method))))
3186 (let ((prefix (gnus-group-prefixed-name "" method)))
3187 (goto-char (point-min))
3188 (while (and (not (eobp))
3189 (progn (insert prefix)
3190 (zerop (forward-line 1)))))))
3191 (goto-char (point-min))
3193 ;; If we get an error, we set group to 0, which is not a
3197 (let ((obarray gnus-description-hashtb))
3198 ;; Group is set to a symbol interned in this
3200 (read nntp-server-buffer))
3202 (skip-chars-forward " \t")
3203 ;; ... which leads to this line being effectively ignored.
3204 (when (symbolp group)
3205 (let* ((str (buffer-substring
3206 (point) (progn (end-of-line) (point))))
3207 (name (symbol-name group))
3209 (or (gnus-group-name-charset method name)
3210 (gnus-parameter-charset name)
3211 gnus-default-charset)))
3212 ;; Fixme: Don't decode in unibyte mode.
3213 (when (and str charset (featurep 'mule))
3214 (setq str (decode-coding-string str charset)))
3217 (gnus-message 5 "Reading descriptions file...done")
3220 (defun gnus-group-get-description (group)
3221 "Get the description of a group by sending XGTITLE to the server."
3222 (when (gnus-request-group-description group)
3224 (set-buffer nntp-server-buffer)
3225 (goto-char (point-min))
3226 (when (looking-at "[^ \t]+[ \t]+\\(.*\\)")
3227 (match-string 1)))))
3230 (defun gnus-declare-backend (name &rest abilities)
3231 "Declare back end NAME with ABILITIES as a Gnus back end."
3232 (setq gnus-valid-select-methods
3233 (nconc gnus-valid-select-methods
3234 (list (apply 'list name abilities))))
3235 (gnus-redefine-select-method-widget))
3237 (defun gnus-set-default-directory ()
3238 "Set the default directory in the current buffer to `gnus-default-directory'.
3239 If this variable is nil, don't do anything."
3240 (setq default-directory
3241 (if (and gnus-default-directory
3242 (file-exists-p gnus-default-directory))
3243 (file-name-as-directory (expand-file-name gnus-default-directory))
3244 default-directory)))
3247 (defalias 'gnus-display-time-event-handler
3248 (if (gnus-boundp 'display-time-timer)
3249 'display-time-event-handler
3250 (lambda () "Does nothing as `display-time-timer' is not bound.
3251 Would otherwise be an alias for `display-time-event-handler'." nil))))
3254 (defun gnus-fixup-nnimap-unread-after-getting-new-news ()
3255 (let (server group info)
3258 (when (and (setq group (symbol-name sym))
3259 (gnus-group-entry group)
3260 (setq info (symbol-value sym)))
3261 (gnus-sethash group (cons (nth 2 info) (cdr (gnus-group-entry group)))
3262 gnus-newsrc-hashtb)))
3263 (if (boundp 'nnimap-mailbox-info)
3264 (symbol-value 'nnimap-mailbox-info)
3265 (make-vector 1 0)))))
3268 (provide 'gnus-start)
3270 ;;; gnus-start.el ends here