1 ;;; gnus-start.el --- startup functions for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
35 (autoload 'message-make-date "message")
36 (autoload 'gnus-agent-read-servers-validate "gnus-agent")
37 (autoload 'gnus-agent-save-local "gnus-agent")
38 (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-backup-startup-file 'never
54 "Whether to create backup files.
55 This variable takes the same values as the `version-control'
59 :type '(choice (const :tag "Never" never)
60 (const :tag "If existing" nil)
61 (other :tag "Always" t)))
63 (defcustom gnus-save-startup-file-via-temp-buffer t
64 "Whether to write the startup file contents to a buffer then save
65 the buffer or write directly to the file. The buffer is faster
66 because all of the contents are written at once. The direct write
67 uses considerably less memory."
70 :type '(choice (const :tag "Write via buffer" t)
71 (const :tag "Write directly to file" nil)))
73 (defcustom gnus-init-file (nnheader-concat gnus-home-directory ".gnus")
74 "Your Gnus Emacs-Lisp startup file name.
75 If a file with the `.el' or `.elc' suffixes exists, it will be read instead."
79 (defcustom gnus-site-init-file
81 (concat (file-name-directory
82 (directory-file-name installation-directory))
83 "site-lisp/gnus-init")
85 "The site-wide Gnus Emacs-Lisp startup file name, or nil if none.
86 If a file with the `.el' or `.elc' suffixes exists, it will be read instead."
88 :type '(choice file (const nil)))
90 (defcustom gnus-default-subscribed-newsgroups nil
91 "List of newsgroups to subscribe, when a user runs Gnus the first time.
92 The value should be a list of strings.
93 If it is t, Gnus will not do anything special the first time it is
94 started; it'll just use the normal newsgroups subscription methods."
96 :type '(choice (repeat string) (const :tag "Nothing special" t)))
98 (defcustom gnus-use-dribble-file t
99 "*Non-nil means that Gnus will use a dribble file to store user updates.
100 If Emacs should crash without saving the .newsrc files, complete
101 information can be restored from the dribble file."
102 :group 'gnus-dribble-file
105 (defcustom gnus-dribble-directory nil
106 "*The directory where dribble files will be saved.
107 If this variable is nil, the directory where the .newsrc files are
109 :group 'gnus-dribble-file
110 :type '(choice directory (const nil)))
112 (defcustom gnus-check-new-newsgroups 'ask-server
113 "*Non-nil means that Gnus will run `gnus-find-new-newsgroups' at startup.
114 This normally finds new newsgroups by comparing the active groups the
115 servers have already reported with those Gnus already knows, either alive
118 When any of the following are true, `gnus-find-new-newsgroups' will instead
119 ask the servers (primary, secondary, and archive servers) to list new
120 groups since the last time it checked:
121 1. This variable is `ask-server'.
122 2. This variable is a list of select methods (see below).
123 3. `gnus-read-active-file' is nil or `some'.
124 4. A prefix argument is given to `gnus-find-new-newsgroups' interactively.
126 Thus, if this variable is `ask-server' or a list of select methods or
127 `gnus-read-active-file' is nil or `some', then the killed list is no
128 longer necessary, so you could safely set `gnus-save-killed-list' to nil.
130 This variable can be a list of select methods which Gnus will query with
131 the `ask-server' method in addition to the primary, secondary, and archive
135 (setq gnus-check-new-newsgroups
136 '((nntp \"some.server\") (nntp \"other.server\")))
138 If this variable is nil, then you have to tell Gnus explicitly to
139 check for new newsgroups with \\<gnus-group-mode-map>\\[gnus-find-new-newsgroups]."
141 :type '(choice (const :tag "no" nil)
142 (const :tag "by brute force" t)
143 (const :tag "ask servers" ask-server)
144 (repeat :menu-tag "ask additional servers"
145 :tag "ask additional servers"
147 (sexp :format "%v"))))
149 (defcustom gnus-check-bogus-newsgroups nil
150 "*Non-nil means that Gnus will check and remove bogus newsgroup at startup.
151 If this variable is nil, then you have to tell Gnus explicitly to
152 check for bogus newsgroups with \\<gnus-group-mode-map>\\[gnus-group-check-bogus-groups]."
153 :group 'gnus-start-server
156 (defcustom gnus-read-active-file 'some
157 "*Non-nil means that Gnus will read the entire active file at startup.
158 If this variable is nil, Gnus will only know about the groups in your
161 If this variable is `some', Gnus will try to only read the relevant
162 parts of the active file from the server. Not all servers support
163 this, and it might be quite slow with other servers, but this should
164 generally be faster than both the t and nil value.
166 If you set this variable to nil or `some', you probably still want to
167 be told about new newsgroups that arrive. To do that, set
168 `gnus-check-new-newsgroups' to `ask-server'. This may not work
169 properly with all servers."
170 :group 'gnus-start-server
171 :type '(choice (const nil)
175 (defconst gnus-level-subscribed 5
176 "Groups with levels less than or equal to this variable are subscribed.")
178 (defconst gnus-level-unsubscribed 7
179 "Groups with levels less than or equal to this variable are unsubscribed.
180 Groups with levels less than `gnus-level-subscribed', which should be
181 less than this variable, are subscribed.")
183 (defconst gnus-level-zombie 8
184 "Groups with this level are zombie groups.")
186 (defconst gnus-level-killed 9
187 "Groups with this level are killed.")
189 (defcustom gnus-level-default-subscribed 3
190 "*New subscribed groups will be subscribed at this level."
191 :group 'gnus-group-levels
194 (defcustom gnus-level-default-unsubscribed 6
195 "*New unsubscribed groups will be unsubscribed at this level."
196 :group 'gnus-group-levels
199 (defcustom gnus-activate-level (1+ gnus-level-subscribed)
200 "*Groups higher than this level won't be activated on startup.
201 Setting this variable to something low might save lots of time when
202 you have many groups that you aren't interested in."
203 :group 'gnus-group-levels
206 (defcustom gnus-activate-foreign-newsgroups 4
207 "*If nil, Gnus will not check foreign newsgroups at startup.
208 If it is non-nil, it should be a number between one and nine. Foreign
209 newsgroups that have a level lower or equal to this number will be
210 activated on startup. For instance, if you want to active all
211 subscribed newsgroups, but not the rest, you'd set this variable to
212 `gnus-level-subscribed'.
214 If you subscribe to lots of newsgroups from different servers, startup
215 might take a while. By setting this variable to nil, you'll save time,
216 but you won't be told how many unread articles there are in the
218 :group 'gnus-group-levels
219 :type '(choice integer
220 (const :tag "none" nil)))
222 (defcustom gnus-read-newsrc-file t
223 "*Non-nil means that Gnus will read the `.newsrc' file.
224 Gnus always reads its own startup file, which is called
225 \".newsrc.eld\". The file called \".newsrc\" is in a format that can
226 be readily understood by other newsreaders. If you don't plan on
227 using other newsreaders, set this variable to nil to save some time on
233 (defcustom gnus-save-newsrc-file t
234 "*Non-nil means that Gnus will save the `.newsrc' file.
235 Gnus always saves its own startup file, which is called
236 \".newsrc.eld\". The file called \".newsrc\" is in a format that can
237 be readily understood by other newsreaders. If you don't plan on
238 using other newsreaders, set this variable to nil to save some time on
243 (defcustom gnus-save-killed-list t
244 "*If non-nil, save the list of killed groups to the startup file.
245 If you set this variable to nil, you'll save both time (when starting
246 and quitting) and space (both memory and disk), but it will also mean
247 that Gnus has no record of which groups are new and which are old, so
248 the automatic new newsgroups subscription methods become meaningless.
250 You should always set `gnus-check-new-newsgroups' to `ask-server' or
251 nil if you set this variable to nil.
253 This variable can also be a regexp. In that case, all groups that do
254 not match this regexp will be removed before saving the list."
256 :type '(radio (sexp :format "Non-nil\n"
257 :match (lambda (widget value)
258 (and value (not (stringp value))))
263 (defcustom gnus-ignored-newsgroups
265 '("^to\\." ; not "real" groups
266 "^[0-9. \t]+\\( \\|$\\)" ; all digits in name
267 "^[\"][]\"[#'()]" ; bogus characters
270 "*A regexp to match uninteresting newsgroups in the active file.
271 Any lines in the active file matching this regular expression are
272 removed from the newsgroup list before anything else is done to it,
273 thus making them effectively non-existent."
274 :group 'gnus-group-new
277 (defcustom gnus-subscribe-newsgroup-method 'gnus-subscribe-zombies
278 "*Function(s) called with a group name when new group is detected.
279 A few pre-made functions are supplied: `gnus-subscribe-randomly'
280 inserts new groups at the beginning of the list of groups;
281 `gnus-subscribe-alphabetically' inserts new groups in strict
282 alphabetic order; `gnus-subscribe-hierarchically' inserts new groups
283 in hierarchical newsgroup order; `gnus-subscribe-interactively' asks
284 for your decision; `gnus-subscribe-killed' kills all new groups;
285 `gnus-subscribe-zombies' will make all new groups into zombies;
286 `gnus-subscribe-topics' will enter groups into the topics that
288 :group 'gnus-group-new
289 :type '(radio (function-item gnus-subscribe-randomly)
290 (function-item gnus-subscribe-alphabetically)
291 (function-item gnus-subscribe-hierarchically)
292 (function-item gnus-subscribe-interactively)
293 (function-item gnus-subscribe-killed)
294 (function-item gnus-subscribe-zombies)
295 (function-item gnus-subscribe-topics)
299 (defcustom gnus-subscribe-newsgroup-hooks nil
300 "*Hooks run after you subscribe to a new group.
301 The hooks will be called with new group's name as argument."
303 :group 'gnus-group-new
306 (defcustom gnus-subscribe-options-newsgroup-method
307 'gnus-subscribe-alphabetically
308 "*Function(s) called to subscribe newsgroups mentioned on \"options -n\" lines.
309 If, for instance, you want to subscribe to all newsgroups in the
310 \"no\" and \"alt\" hierarchies, you'd put the following in your
313 options -n no.all alt.all
315 Gnus will the subscribe all new newsgroups in these hierarchies with
316 the subscription method in this variable."
317 :group 'gnus-group-new
318 :type '(radio (function-item gnus-subscribe-randomly)
319 (function-item gnus-subscribe-alphabetically)
320 (function-item gnus-subscribe-hierarchically)
321 (function-item gnus-subscribe-interactively)
322 (function-item gnus-subscribe-killed)
323 (function-item gnus-subscribe-zombies)
324 (function-item gnus-subscribe-topics)
328 (defcustom gnus-subscribe-hierarchical-interactive nil
329 "*If non-nil, Gnus will offer to subscribe hierarchically.
330 When a new hierarchy appears, Gnus will ask the user:
332 'alt.binaries': Do you want to subscribe to this hierarchy? ([d]ys):
334 If the user pressed `d', Gnus will descend the hierarchy, `y' will
335 subscribe to all newsgroups in the hierarchy and `s' will skip this
336 hierarchy in its entirety."
337 :group 'gnus-group-new
340 (defcustom gnus-auto-subscribed-groups
341 "^nnml\\|^nnfolder\\|^nnmbox\\|^nnmh\\|^nnbabyl\\|^nnmaildir"
342 "*All new groups that match this regexp will be subscribed automatically.
343 Note that this variable only deals with new groups. It has no effect
344 whatsoever on old groups.
346 New groups that match this regexp will not be handled by
347 `gnus-subscribe-newsgroup-method'. Instead, they will
348 be subscribed using `gnus-subscribe-options-newsgroup-method'."
349 :group 'gnus-group-new
352 (defcustom gnus-options-subscribe nil
353 "*All new groups matching this regexp will be subscribed unconditionally.
354 Note that this variable deals only with new newsgroups. This variable
355 does not affect old newsgroups.
357 New groups that match this regexp will not be handled by
358 `gnus-subscribe-newsgroup-method'. Instead, they will
359 be subscribed using `gnus-subscribe-options-newsgroup-method'."
360 :group 'gnus-group-new
361 :type '(choice regexp
362 (const :tag "none" nil)))
364 (defcustom gnus-options-not-subscribe nil
365 "*All new groups matching this regexp will be ignored.
366 Note that this variable deals only with new newsgroups. This variable
367 does not affect old (already subscribed) newsgroups."
368 :group 'gnus-group-new
369 :type '(choice regexp
370 (const :tag "none" nil)))
372 (defcustom gnus-modtime-botch nil
373 "*Non-nil means .newsrc should be deleted prior to save.
374 Its use is due to the bogus appearance that .newsrc was modified on
379 (defcustom gnus-check-bogus-groups-hook nil
380 "A hook run after removing bogus groups."
381 :group 'gnus-start-server
384 (defcustom gnus-startup-hook nil
385 "A hook called at startup.
386 This hook is called after Gnus is connected to the NNTP server."
390 (defcustom gnus-before-startup-hook nil
391 "A hook called at before startup.
392 This hook is called as the first thing when Gnus is started."
396 (defcustom gnus-started-hook nil
397 "A hook called as the last thing after startup."
401 (defcustom gnus-setup-news-hook
402 '(gnus-fixup-nnimap-unread-after-getting-new-news)
403 "A hook after reading the .newsrc file, but before generating the buffer."
407 (defcustom gnus-get-top-new-news-hook nil
408 "A hook run just before Gnus checks for new news globally."
410 :group 'gnus-group-new
413 (defcustom gnus-get-new-news-hook nil
414 "A hook run just before Gnus checks for new news."
415 :group 'gnus-group-new
418 (defcustom gnus-after-getting-new-news-hook
419 '(gnus-display-time-event-handler
420 gnus-fixup-nnimap-unread-after-getting-new-news)
421 "*A hook run after Gnus checks for new news when Gnus is already running."
422 :group 'gnus-group-new
425 (defcustom gnus-read-newsrc-el-hook nil
426 "A hook called after reading the newsrc.eld? file."
430 (defcustom gnus-save-newsrc-hook nil
431 "A hook called before saving any of the newsrc files."
435 (defcustom gnus-save-quick-newsrc-hook nil
436 "A hook called just before saving the quick newsrc file.
437 Can be used to turn version control on or off."
441 (defcustom gnus-save-standard-newsrc-hook nil
442 "A hook called just before saving the standard newsrc file.
443 Can be used to turn version control on or off."
447 (defcustom gnus-group-mode-hook nil
448 "Hook for Gnus group mode."
449 :group 'gnus-group-various
450 :options '(gnus-topic-mode)
453 (defcustom gnus-always-read-dribble-file nil
454 "Unconditionally read the dribble file."
458 ;;; Internal variables
460 (defvar gnus-ding-file-coding-system mm-universal-coding-system
461 "Coding system for ding file.")
463 (defvar gnus-newsrc-file-version nil)
464 (defvar gnus-override-subscribe-method nil)
465 (defvar gnus-dribble-buffer nil)
466 (defvar gnus-newsrc-options nil
467 "Options line in the .newsrc file.")
469 (defvar gnus-newsrc-options-n nil
470 "List of regexps representing groups to be subscribed/ignored unconditionally.")
472 (defvar gnus-newsrc-last-checked-date nil
473 "Date Gnus last asked server for new newsgroups.")
475 (defvar gnus-current-startup-file nil
476 "Startup file for the current host.")
478 ;; Byte-compiler warning.
479 (defvar gnus-group-line-format)
481 ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
482 (defvar gnus-init-inhibit nil)
483 (defun gnus-read-init-file (&optional inhibit-next)
484 ;; Don't load .gnus if the -q option was used.
486 (if gnus-init-inhibit
487 (setq gnus-init-inhibit nil)
488 (setq gnus-init-inhibit inhibit-next)
489 (dolist (file (list gnus-site-init-file gnus-init-file))
491 (locate-library file))
492 (if (or debug-on-error debug-on-quit)
497 (error "Error in %s: %s" file (cadr var))))))))))
499 ;; For subscribing new newsgroup
501 (defun gnus-subscribe-hierarchical-interactive (groups)
502 (let ((groups (sort groups 'string<))
503 prefixes prefix start ans group starts real-group)
505 (setq prefixes (list "^"))
506 (while (and groups prefixes)
507 (while (not (string-match (car prefixes)
508 (gnus-group-real-name (car groups))))
509 (setq prefixes (cdr prefixes)))
510 (setq prefix (car prefixes))
511 (setq start (1- (length prefix)))
512 (if (and (string-match "[^\\.]\\." (gnus-group-real-name (car groups))
516 (concat "^" (substring
517 (gnus-group-real-name (car groups))
519 (string-match prefix (gnus-group-real-name (cadr groups))))
521 (push prefix prefixes)
522 (message "Descend hierarchy %s? ([y]nsq): "
523 (substring prefix 1 (1- (length prefix))))
524 (while (not (memq (setq ans (read-char-exclusive))
525 '(?y ?\n ?\r ?n ?s ?q)))
527 (message "Descend hierarchy %s? ([y]nsq): "
528 (substring prefix 1 (1- (length prefix)))))
531 (setq group (car groups)
532 real-group (gnus-group-real-name group))
533 (string-match prefix real-group))
534 (push group gnus-killed-list)
535 (gnus-sethash group group gnus-killed-hashtb)
536 (setq groups (cdr groups)))
537 (setq starts (cdr starts)))
540 (setq group (car groups)
541 real-group (gnus-group-real-name group))
542 (string-match prefix real-group))
543 (gnus-sethash group group gnus-killed-hashtb)
544 (gnus-subscribe-alphabetically (car groups))
545 (setq groups (cdr groups)))
546 (setq starts (cdr starts)))
549 (setq group (car groups))
550 (push group gnus-killed-list)
551 (gnus-sethash group group gnus-killed-hashtb)
552 (setq groups (cdr groups))))
554 (message "Subscribe %s? ([n]yq)" (car groups))
555 (while (not (memq (setq ans (read-char-exclusive))
556 '(?y ?\n ?\r ?q ?n)))
558 (message "Subscribe %s? ([n]yq)" (car groups)))
559 (setq group (car groups))
561 (gnus-subscribe-alphabetically (car groups))
562 (gnus-sethash group group gnus-killed-hashtb))
565 (setq group (car groups))
566 (push group gnus-killed-list)
567 (gnus-sethash group group gnus-killed-hashtb)
568 (setq groups (cdr groups))))
570 (push group gnus-killed-list)
571 (gnus-sethash group group gnus-killed-hashtb)))
572 (setq groups (cdr groups)))))))
574 (defun gnus-subscribe-randomly (newsgroup)
575 "Subscribe new NEWSGROUP by making it the first newsgroup."
576 (gnus-subscribe-newsgroup newsgroup))
578 (defun gnus-subscribe-alphabetically (newgroup)
579 "Subscribe new NEWGROUP and insert it in alphabetical order."
580 (let ((groups (cdr gnus-newsrc-alist))
582 (while (and (not before) groups)
583 (if (string< newgroup (caar groups))
584 (setq before (caar groups))
585 (setq groups (cdr groups))))
586 (gnus-subscribe-newsgroup newgroup before)))
588 (defun gnus-subscribe-hierarchically (newgroup)
589 "Subscribe new NEWGROUP and insert it in hierarchical newsgroup order."
590 ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
592 (set-buffer (nnheader-find-file-noselect gnus-current-startup-file))
594 (let ((groupkey newgroup) before)
595 (while (and (not before) groupkey)
596 (goto-char (point-min))
598 (concat "^\\(" (regexp-quote groupkey) ".*\\)[!:]")))
599 (while (and (re-search-forward groupkey-re nil t)
601 (setq before (match-string 1))
602 (string< before newgroup)))))
603 ;; Remove tail of newsgroup name (eg. a.b.c -> a.b)
605 (when (string-match "^\\(.*\\)\\.[^.]+$" groupkey)
606 (substring groupkey (match-beginning 1) (match-end 1)))))
607 (gnus-subscribe-newsgroup newgroup before))
608 (kill-buffer (current-buffer)))))
610 (defun gnus-subscribe-interactively (group)
611 "Subscribe the new GROUP interactively.
612 It is inserted in hierarchical newsgroup order if subscribed. If not,
614 (if (gnus-y-or-n-p (format "Subscribe new newsgroup: %s " group))
615 (gnus-subscribe-hierarchically group)
616 (push group gnus-killed-list)))
618 (defun gnus-subscribe-zombies (group)
619 "Make the new GROUP into a zombie group."
620 (push group gnus-zombie-list))
622 (defun gnus-subscribe-killed (group)
623 "Make the new GROUP a killed group."
624 (push group gnus-killed-list))
626 (defun gnus-subscribe-newsgroup (newsgroup &optional next)
627 "Subscribe new NEWSGROUP.
628 If NEXT is non-nil, it is inserted before NEXT. Otherwise it is made
629 the first newsgroup."
631 (goto-char (point-min))
632 ;; We subscribe the group by changing its level to `subscribed'.
633 (gnus-group-change-level
634 newsgroup gnus-level-default-subscribed
635 gnus-level-killed (gnus-group-entry (or next "dummy.group")))
636 (gnus-message 5 "Subscribe newsgroup: %s" newsgroup)
637 (run-hook-with-args 'gnus-subscribe-newsgroup-hooks newsgroup)
640 (defun gnus-read-active-file-p ()
641 "Say whether the active file has been read from `gnus-select-method'."
642 (memq gnus-select-method gnus-have-read-active-file))
644 ;;; General various misc type functions.
646 ;; Silence byte-compiler.
648 (defvar gnus-current-headers)
649 (defvar gnus-thread-indent-array)
650 (defvar gnus-newsgroup-name)
651 (defvar gnus-newsgroup-headers)
652 (defvar gnus-group-list-mode)
653 (defvar gnus-group-mark-positions)
654 (defvar gnus-newsgroup-data)
655 (defvar gnus-newsgroup-unreads)
656 (defvar nnoo-state-alist)
657 (defvar gnus-current-select-method)
658 (defvar mail-sources)
659 (defvar nnmail-scan-directory-mail-source-once)
660 (defvar nnmail-split-history)
661 (defvar nnmail-spool-file))
663 (defun gnus-close-all-servers ()
666 (dolist (server gnus-opened-servers)
667 (gnus-close-server (car server))))
669 (defun gnus-clear-system ()
670 "Clear all variables and buffers."
671 ;; Clear Gnus variables.
672 (let ((variables (remove 'gnus-format-specs gnus-variable-list)))
674 (set (car variables) nil)
675 (setq variables (cdr variables))))
676 ;; Clear other internal variables.
677 (setq gnus-list-of-killed-groups nil
678 gnus-have-read-active-file nil
679 gnus-agent-covered-methods nil
680 gnus-agent-file-loading-local nil
681 gnus-agent-file-loading-cache nil
682 gnus-server-method-cache nil
683 gnus-newsrc-alist nil
684 gnus-newsrc-hashtb nil
687 gnus-killed-hashtb nil
688 gnus-active-hashtb nil
689 gnus-moderated-hashtb nil
690 gnus-description-hashtb nil
691 gnus-current-headers nil
692 gnus-thread-indent-array nil
693 gnus-newsgroup-headers nil
694 gnus-newsgroup-name nil
695 gnus-server-alist nil
696 gnus-group-list-mode nil
697 gnus-opened-servers nil
698 gnus-group-mark-positions nil
699 gnus-newsgroup-data nil
700 gnus-newsgroup-unreads nil
702 gnus-current-select-method nil
703 nnmail-split-history nil
704 gnus-ephemeral-servers nil)
705 (gnus-shutdown 'gnus)
706 ;; Kill the startup file.
707 (and gnus-current-startup-file
708 (get-file-buffer gnus-current-startup-file)
709 (kill-buffer (get-file-buffer gnus-current-startup-file)))
710 ;; Clear the dribble buffer.
712 ;; Kill global KILL file buffer.
713 (when (get-file-buffer (gnus-newsgroup-kill-file nil))
714 (kill-buffer (get-file-buffer (gnus-newsgroup-kill-file nil))))
715 (gnus-kill-buffer nntp-server-buffer)
716 ;; Kill Gnus buffers.
717 (dolist (buffer (gnus-buffers))
718 (gnus-kill-buffer buffer))
719 ;; Remove Gnus frames.
720 (gnus-kill-gnus-frames))
722 (defun gnus-no-server-1 (&optional arg slave)
724 If ARG is a positive number, Gnus will use that as the
725 startup level. If ARG is nil, Gnus will be started at level 2.
726 If ARG is non-nil and not a positive number, Gnus will
727 prompt the user for the name of an NNTP server to use.
728 As opposed to `gnus', this command will not connect to the local server."
730 (let ((val (or arg (1- gnus-level-default-subscribed))))
732 (make-local-variable 'gnus-group-use-permanent-levels)
733 (setq gnus-group-use-permanent-levels val)))
735 (defun gnus-1 (&optional arg dont-connect slave)
737 If ARG is non-nil and a positive number, Gnus will use that as the
738 startup level. If ARG is non-nil and not a positive number, Gnus will
739 prompt the user for the name of an NNTP server to use."
744 (switch-to-buffer gnus-group-buffer)
745 (gnus-group-get-new-news
748 (max (car gnus-group-list-mode) arg))))
752 (gnus-run-hooks 'gnus-before-startup-hook)
753 (nnheader-init-server-buffer)
754 (setq gnus-slave slave)
755 (gnus-read-init-file)
759 (when gnus-simple-splash
760 (setq gnus-simple-splash nil)
765 (= (frame-height) (1+ (window-height))))
768 (let ((level (and (numberp arg) (> arg 0) arg))
774 (gnus-start-news-server (and arg (not level))))))
775 (if (and (not dont-connect)
778 (gnus-run-hooks 'gnus-startup-hook)
779 ;; NNTP server is successfully open.
781 ;; Find the current startup file name.
782 (setq gnus-current-startup-file
783 (gnus-make-newsrc-file gnus-startup-file))
785 ;; Read the dribble file.
786 (when (or gnus-slave gnus-use-dribble-file)
787 (gnus-dribble-read-file))
789 ;; Do the actual startup.
791 (gnus-request-create-group "queue" '(nndraft "")))
792 (gnus-request-create-group "drafts" '(nndraft ""))
793 (gnus-setup-news nil level dont-connect)
794 (gnus-run-hooks 'gnus-setup-news-hook)
795 (gnus-start-draft-setup)
796 ;; Generate the group buffer.
797 (gnus-group-list-groups level)
798 (gnus-group-first-unread-group)
799 (gnus-configure-windows 'group)
800 (gnus-group-set-mode-line)
801 (gnus-run-hooks 'gnus-started-hook))))))
803 (defun gnus-start-draft-setup ()
804 "Make sure the draft group exists."
805 (gnus-request-create-group "drafts" '(nndraft ""))
806 (unless (gnus-group-entry "nndraft:drafts")
807 (let ((gnus-level-default-subscribed 1))
808 (gnus-subscribe-group "nndraft:drafts" nil '(nndraft "")))
809 (gnus-group-set-parameter
810 "nndraft:drafts" 'gnus-dummy '((gnus-draft-mode)))))
817 (defvar gnus-dribble-ignore nil)
818 (defvar gnus-dribble-eval-file nil)
820 (defun gnus-dribble-file-name ()
821 "Return the dribble file for the current .newsrc."
823 (if gnus-dribble-directory
824 (concat (file-name-as-directory gnus-dribble-directory)
825 (file-name-nondirectory gnus-current-startup-file))
826 gnus-current-startup-file)
829 (defun gnus-dribble-enter (string)
830 "Enter STRING into the dribble buffer."
831 (when (and (not gnus-dribble-ignore)
833 (buffer-name gnus-dribble-buffer))
834 (let ((obuf (current-buffer)))
835 (set-buffer gnus-dribble-buffer)
836 (goto-char (point-max))
838 ;; This has been commented by Josh Huber <huber@alum.wpi.edu>
839 ;; It causes problems with both XEmacs and Emacs 21, and doesn't
840 ;; seem to be of much value. (FIXME: remove this after we make sure
842 ;; (set-window-point (get-buffer-window (current-buffer)) (point-max))
843 (bury-buffer gnus-dribble-buffer)
845 (set-buffer gnus-group-buffer)
846 (gnus-group-set-mode-line))
849 (defun gnus-dribble-touch ()
850 "Touch the dribble buffer."
851 (gnus-dribble-enter ""))
853 (defun gnus-dribble-read-file ()
854 "Read the dribble file from disk."
855 (let ((dribble-file (gnus-dribble-file-name)))
857 (set-buffer (setq gnus-dribble-buffer
858 (gnus-get-buffer-create
859 (file-name-nondirectory dribble-file))))
861 (setq buffer-file-name dribble-file)
863 (buffer-disable-undo)
864 (bury-buffer (current-buffer))
865 (set-buffer-modified-p nil)
866 (let ((auto (make-auto-save-file-name))
867 (gnus-dribble-ignore t)
870 (when (or (file-exists-p auto) (file-exists-p dribble-file))
871 ;; Load whichever file is newest -- the auto save file
872 ;; or the "real" file.
873 (if (file-newer-than-file-p auto dribble-file)
874 (nnheader-insert-file-contents auto)
875 (nnheader-insert-file-contents dribble-file))
876 (unless (zerop (buffer-size))
877 (set-buffer-modified-p t))
878 ;; Set the file modes to reflect the .newsrc file modes.
880 (when (and (file-exists-p gnus-current-startup-file)
881 (file-exists-p dribble-file)
882 (setq modes (file-modes gnus-current-startup-file)))
883 (gnus-set-file-modes dribble-file modes))
884 (goto-char (point-min))
885 (when (search-forward "Gnus was exited on purpose" nil t)
887 ;; Possibly eval the file later.
888 (when (or gnus-always-read-dribble-file
891 "Gnus exited on purpose without saving; read auto-save file anyway? "
892 "Gnus auto-save file exists. Do you want to read it? ")))
893 (setq gnus-dribble-eval-file t)))))))
895 (defun gnus-dribble-eval-file ()
896 (when gnus-dribble-eval-file
897 (setq gnus-dribble-eval-file nil)
899 (let ((gnus-dribble-ignore t))
900 (set-buffer gnus-dribble-buffer)
901 (eval-buffer (current-buffer))))))
903 (defun gnus-dribble-delete-file ()
904 (when (file-exists-p (gnus-dribble-file-name))
905 (delete-file (gnus-dribble-file-name)))
906 (when gnus-dribble-buffer
908 (set-buffer gnus-dribble-buffer)
909 (let ((auto (make-auto-save-file-name)))
910 (when (file-exists-p auto)
913 (set-buffer-modified-p nil)))))
915 (defun gnus-dribble-save ()
916 (when (and gnus-dribble-buffer
917 (buffer-name gnus-dribble-buffer))
919 (set-buffer gnus-dribble-buffer)
922 (defun gnus-dribble-clear ()
923 (when (gnus-buffer-exists-p gnus-dribble-buffer)
925 (set-buffer gnus-dribble-buffer)
927 (set-buffer-modified-p nil)
928 (setq buffer-saved-size (buffer-size)))))
932 ;;; Active & Newsrc File Handling
935 (defun gnus-setup-news (&optional rawfile level dont-connect)
936 "Setup news information.
937 If RAWFILE is non-nil, the .newsrc file will also be read.
938 If LEVEL is non-nil, the news will be set up at level LEVEL."
940 (let ((init (not (and gnus-newsrc-alist gnus-active-hashtb (not rawfile))))
941 ;; Binding this variable will inhibit multiple fetchings
942 ;; of the same mail source.
943 (nnmail-fetched-sources (list t)))
946 ;; Clear some variables to re-initialize news information.
947 (setq gnus-newsrc-alist nil
948 gnus-active-hashtb nil)
949 ;; Read the newsrc file and create `gnus-newsrc-hashtb'.
950 (gnus-read-newsrc-file rawfile))
952 ;; Make sure the archive server is available to all and sundry.
953 (when gnus-message-archive-method
954 (unless (assoc "archive" gnus-server-alist)
955 (let ((method (or (and (stringp gnus-message-archive-method)
956 (gnus-server-to-method
957 gnus-message-archive-method))
958 gnus-message-archive-method)))
959 ;; Check whether the archive method is writable.
960 (unless (or (stringp method)
961 (memq 'respool (assoc (format "%s" (car method))
962 gnus-valid-select-methods)))
963 (setq method "archive")) ;; The default.
964 (push (if (stringp method)
969 ,(nnheader-concat message-directory method))
970 (nnfolder-active-file
971 ,(nnheader-concat message-directory
972 (concat method "/active")))
973 (nnfolder-get-new-mail nil)
974 (nnfolder-inhibit-expiry t))
975 (cons "archive" method))
976 gnus-server-alist))))
978 ;; If we don't read the complete active file, we fill in the
980 (when (or (null gnus-read-active-file)
981 (eq gnus-read-active-file 'some))
982 (gnus-update-active-hashtb-from-killed))
984 ;; Validate agent covered methods now that gnus-server-alist has
986 ;; NOTE: This is here for one purpose only. By validating the
987 ;; agentized server's, it converts the old 5.10.3, and earlier,
988 ;; format to the current format. That enables the agent code
989 ;; within gnus-read-active-file to function correctly.
991 (gnus-agent-read-servers-validate))
993 ;; Read the active file and create `gnus-active-hashtb'.
994 ;; If `gnus-read-active-file' is nil, then we just create an empty
995 ;; hash table. The partial filling out of the hash table will be
996 ;; done in `gnus-get-unread-articles'.
997 (and gnus-read-active-file
999 (gnus-read-active-file nil dont-connect))
1001 (unless gnus-active-hashtb
1002 (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
1004 ;; Initialize the cache.
1005 (when gnus-use-cache
1008 ;; Possibly eval the dribble file.
1010 (or gnus-use-dribble-file gnus-slave)
1011 (gnus-dribble-eval-file))
1013 ;; Slave Gnusii should then clear the dribble buffer.
1014 (when (and init gnus-slave)
1015 (gnus-dribble-clear))
1017 (gnus-update-format-specifications)
1019 ;; See whether we need to read the description file.
1020 (when (and (boundp 'gnus-group-line-format)
1021 (stringp gnus-group-line-format)
1022 (let ((case-fold-search nil))
1023 (string-match "%[-,0-9]*D" gnus-group-line-format))
1024 (not gnus-description-hashtb)
1026 gnus-read-active-file)
1027 (gnus-read-all-descriptions-files))
1029 ;; Find new newsgroups and treat them.
1030 (when (and init gnus-check-new-newsgroups (not level)
1031 (gnus-check-server gnus-select-method)
1034 (gnus-find-new-newsgroups))
1036 ;; Check and remove bogus newsgroups.
1037 (when (and init gnus-check-bogus-newsgroups
1038 gnus-read-active-file (not level)
1039 (gnus-server-opened gnus-select-method))
1040 (gnus-check-bogus-newsgroups))
1042 ;; We might read in new NoCeM messages here.
1043 (when (and gnus-use-nocem
1046 (gnus-nocem-scan-groups))
1048 ;; Read any slave files.
1049 (gnus-master-read-slave-newsrc)
1051 ;; Find the number of unread articles in each non-dead group.
1052 (let ((gnus-read-active-file (and (not level) gnus-read-active-file)))
1053 (gnus-get-unread-articles level))))
1055 (defun gnus-call-subscribe-functions (method group)
1056 "Call METHOD to subscribe GROUP.
1057 If no function returns `non-nil', call `gnus-subscribe-zombies'."
1060 (funcall method group))
1063 (dolist (func method)
1064 (if (funcall func group)
1068 (gnus-subscribe-zombies group)))
1070 (defun gnus-find-new-newsgroups (&optional arg)
1071 "Search for new newsgroups and add them.
1072 Each new newsgroup will be treated with `gnus-subscribe-newsgroup-method'.
1073 The `-n' option line from .newsrc is respected.
1075 With 1 C-u, use the `ask-server' method to query the server for new
1077 With 2 C-u's, use most complete method possible to query the server
1078 for new groups, and subscribe the new groups as zombies."
1080 (let* ((gnus-subscribe-newsgroup-method
1081 gnus-subscribe-newsgroup-method)
1083 ((or (and (= (or arg 1) 4)
1084 (not (listp gnus-check-new-newsgroups)))
1085 (null gnus-read-active-file)
1086 (eq gnus-read-active-file 'some))
1089 (setq gnus-subscribe-newsgroup-method
1090 'gnus-subscribe-zombies)
1092 (t gnus-check-new-newsgroups))))
1093 (unless (gnus-check-first-time-used)
1094 (if (or (consp check)
1095 (eq check 'ask-server))
1096 ;; Ask the server for new groups.
1097 (gnus-ask-server-for-new-groups)
1098 ;; Go through the active hashtb and look for new groups.
1100 group new-newsgroups)
1101 (gnus-message 5 "Looking for new newsgroups...")
1102 (unless gnus-have-read-active-file
1103 (gnus-read-active-file))
1104 (setq gnus-newsrc-last-checked-date (message-make-date))
1105 (unless gnus-killed-hashtb
1106 (gnus-make-hashtable-from-killed))
1107 ;; Go though every newsgroup in `gnus-active-hashtb' and compare
1108 ;; with `gnus-newsrc-hashtb' and `gnus-killed-hashtb'.
1111 (if (or (null (setq group (symbol-name sym)))
1113 (null (symbol-value sym))
1114 (gnus-gethash group gnus-killed-hashtb)
1115 (gnus-gethash group gnus-newsrc-hashtb))
1117 (let ((do-sub (gnus-matches-options-n group)))
1119 ((eq do-sub 'subscribe)
1120 (setq groups (1+ groups))
1121 (gnus-sethash group group gnus-killed-hashtb)
1122 (gnus-call-subscribe-functions
1123 gnus-subscribe-options-newsgroup-method group))
1124 ((eq do-sub 'ignore)
1127 (setq groups (1+ groups))
1128 (gnus-sethash group group gnus-killed-hashtb)
1129 (if gnus-subscribe-hierarchical-interactive
1130 (push group new-newsgroups)
1131 (gnus-call-subscribe-functions
1132 gnus-subscribe-newsgroup-method group)))))))
1134 (when new-newsgroups
1135 (gnus-subscribe-hierarchical-interactive new-newsgroups))
1137 (gnus-message 5 "%d new newsgroup%s arrived."
1138 groups (if (> groups 1) "s have" " has"))
1139 (gnus-message 5 "No new newsgroups.")))))))
1141 (defun gnus-matches-options-n (group)
1142 ;; Returns `subscribe' if the group is to be unconditionally
1143 ;; subscribed, `ignore' if it is to be ignored, and nil if there is
1144 ;; no match for the group.
1146 ;; First we check the two user variables.
1148 ((and gnus-options-subscribe
1149 (string-match gnus-options-subscribe group))
1151 ((and gnus-auto-subscribed-groups
1152 (string-match gnus-auto-subscribed-groups group))
1154 ((and gnus-options-not-subscribe
1155 (string-match gnus-options-not-subscribe group))
1157 ;; Then we go through the list that was retrieved from the .newsrc
1158 ;; file. This list has elements on the form
1159 ;; `(REGEXP . {ignore,subscribe})'. The first match found (the list
1160 ;; is in the reverse order of the options line) is returned.
1162 (let ((regs gnus-newsrc-options-n))
1164 (not (string-match (caar regs) group)))
1165 (setq regs (cdr regs)))
1166 (and regs (cdar regs))))))
1168 (defun gnus-ask-server-for-new-groups ()
1169 (let* ((new-date (message-make-date))
1170 (date (or gnus-newsrc-last-checked-date new-date))
1171 (methods (cons gnus-select-method
1173 (when (gnus-archive-server-wanted-p)
1176 (and (consp gnus-check-new-newsgroups)
1177 gnus-check-new-newsgroups)
1178 gnus-secondary-select-methods))))
1180 group new-newsgroups got-new method hashtb
1181 gnus-override-subscribe-method)
1182 (unless gnus-killed-hashtb
1183 (gnus-make-hashtable-from-killed))
1184 ;; Go through both primary and secondary select methods and
1185 ;; request new newsgroups.
1186 (while (setq method (gnus-server-get-method nil (pop methods)))
1187 (setq new-newsgroups nil
1188 gnus-override-subscribe-method method)
1189 (when (and (gnus-check-server method)
1190 (gnus-request-newgroups date method))
1193 hashtb (gnus-make-hashtable 100))
1194 (set-buffer nntp-server-buffer)
1195 ;; Enter all the new groups into a hashtable.
1196 (gnus-active-to-gnus-format method hashtb 'ignore))
1197 ;; Now all new groups from `method' are in `hashtb'.
1200 (if (or (null (setq group (symbol-name group-sym)))
1201 (not (boundp group-sym))
1202 (null (symbol-value group-sym))
1203 (gnus-gethash group gnus-newsrc-hashtb)
1204 (member group gnus-zombie-list)
1205 (member group gnus-killed-list))
1206 ;; The group is already known.
1208 ;; Make this group active.
1209 (when (symbol-value group-sym)
1210 (gnus-set-active group (symbol-value group-sym)))
1211 ;; Check whether we want it or not.
1212 (let ((do-sub (gnus-matches-options-n group)))
1214 ((eq do-sub 'subscribe)
1216 (gnus-sethash group group gnus-killed-hashtb)
1217 (gnus-call-subscribe-functions
1218 gnus-subscribe-options-newsgroup-method group))
1219 ((eq do-sub 'ignore)
1223 (gnus-sethash group group gnus-killed-hashtb)
1224 (if gnus-subscribe-hierarchical-interactive
1225 (push group new-newsgroups)
1226 (gnus-call-subscribe-functions
1227 gnus-subscribe-newsgroup-method group)))))))
1229 (when new-newsgroups
1230 (gnus-subscribe-hierarchical-interactive new-newsgroups)))
1232 (gnus-message 5 "%d new newsgroup%s arrived"
1233 groups (if (> groups 1) "s have" " has"))
1234 (gnus-message 5 "No new newsgroups"))
1236 (setq gnus-newsrc-last-checked-date new-date))
1239 (defun gnus-check-first-time-used ()
1241 ;; First check if any of the following files exist. If they do,
1242 ;; it's not the first time the user has used Gnus.
1243 (dolist (file (list (concat gnus-current-startup-file ".el")
1244 (concat gnus-current-startup-file ".eld")
1245 (concat gnus-startup-file ".el")
1246 (concat gnus-startup-file ".eld")))
1247 (when (file-exists-p file)
1248 (throw 'ended nil)))
1249 (gnus-message 6 "First time user; subscribing you to default groups")
1250 (unless (gnus-read-active-file-p)
1251 (let ((gnus-read-active-file t))
1252 (gnus-read-active-file)))
1253 (setq gnus-newsrc-last-checked-date (message-make-date))
1254 ;; Subscribe to the default newsgroups.
1255 (let ((groups (or gnus-default-subscribed-newsgroups
1256 gnus-backup-default-subscribed-newsgroups))
1259 ;; If t, we subscribe (or not) all groups as if they were new.
1262 (when (setq group (symbol-name sym))
1263 (let ((do-sub (gnus-matches-options-n group)))
1265 ((eq do-sub 'subscribe)
1266 (gnus-sethash group group gnus-killed-hashtb)
1267 (gnus-call-subscribe-functions
1268 gnus-subscribe-options-newsgroup-method group))
1269 ((eq do-sub 'ignore)
1272 (push group gnus-killed-list))))))
1274 (dolist (group groups)
1275 ;; Only subscribe the default groups that are activated.
1276 (when (gnus-active group)
1277 (gnus-group-change-level
1278 group gnus-level-default-subscribed gnus-level-killed)))
1280 (set-buffer gnus-group-buffer)
1281 ;; Don't error if the group already exists. This happens when a
1282 ;; first-time user types 'F'. -- didier
1283 (gnus-group-make-help-group t))
1284 (when gnus-novice-user
1285 (gnus-message 7 "`A k' to list killed groups"))))))
1287 (defun gnus-subscribe-group (group &optional previous method)
1288 "Subscribe GROUP and put it after PREVIOUS."
1289 (gnus-group-change-level
1291 (list t group gnus-level-default-subscribed nil nil method)
1293 gnus-level-default-subscribed gnus-level-killed previous t)
1296 ;; `gnus-group-change-level' is the fundamental function for changing
1297 ;; subscription levels of newsgroups. This might mean just changing
1298 ;; from level 1 to 2, which is pretty trivial, from 2 to 6 or back
1299 ;; again, which subscribes/unsubscribes a group, which is equally
1300 ;; trivial. Changing from 1-7 to 8-9 means that you kill a group, and
1301 ;; from 8-9 to 1-7 means that you remove the group from the list of
1302 ;; killed (or zombie) groups and add them to the (kinda) subscribed
1303 ;; groups. And last but not least, moving from 8 to 9 and 9 to 8,
1304 ;; which is trivial.
1305 ;; ENTRY can either be a string (newsgroup name) or a list (if
1306 ;; FROMKILLED is t, it's a list on the format (NUM INFO-LIST),
1307 ;; otherwise it's a list in the format of the `gnus-newsrc-hashtb'
1309 ;; LEVEL is the new level of the group, OLDLEVEL is the old level and
1310 ;; PREVIOUS is the group (in hashtb entry format) to insert this group
1312 (defun gnus-group-change-level (entry level &optional oldlevel
1313 previous fromkilled)
1314 (let (group info active num)
1315 ;; Glean what info we can from the arguments
1317 (if fromkilled (setq group (nth 1 entry))
1318 (setq group (car (nth 2 entry))))
1320 (when (and (stringp entry)
1322 (< oldlevel gnus-level-zombie))
1323 (setq entry (gnus-group-entry entry)))
1324 (if (and (not oldlevel)
1326 (setq oldlevel (gnus-info-level (nth 2 entry)))
1327 (setq oldlevel (or oldlevel gnus-level-killed)))
1328 (when (stringp previous)
1329 (setq previous (gnus-group-entry previous)))
1331 (if (and (>= oldlevel gnus-level-zombie)
1332 (gnus-group-entry group))
1333 ;; We are trying to subscribe a group that is already
1337 (unless (gnus-ephemeral-group-p group)
1339 (format "(gnus-group-change-level %S %S %S %S %S)"
1340 group level oldlevel (car (nth 2 previous)) fromkilled)))
1342 ;; Then we remove the newgroup from any old structures, if needed.
1343 ;; If the group was killed, we remove it from the killed or zombie
1344 ;; list. If not, and it is in fact going to be killed, we remove
1345 ;; it from the newsrc hash table and assoc.
1347 ((>= oldlevel gnus-level-zombie)
1348 ;; oldlevel could be wrong.
1349 (setq gnus-zombie-list (delete group gnus-zombie-list))
1350 (setq gnus-killed-list (delete group gnus-killed-list)))
1352 (when (and (>= level gnus-level-zombie)
1354 (gnus-sethash (car (nth 2 entry)) nil gnus-newsrc-hashtb)
1356 (setcdr (gnus-group-entry (car (nth 3 entry)))
1358 (setcdr (cdr entry) (cdddr entry)))))
1360 ;; Finally we enter (if needed) the list where it is supposed to
1361 ;; go, and change the subscription level. If it is to be killed,
1362 ;; we enter it into the killed or zombie list.
1364 ((>= level gnus-level-zombie)
1365 ;; Remove from the hash table.
1366 (gnus-sethash group nil gnus-newsrc-hashtb)
1367 ;; We do not enter foreign groups into the list of dead
1369 (unless (gnus-group-foreign-p group)
1370 (if (= level gnus-level-zombie)
1371 (push group gnus-zombie-list)
1372 (if (= oldlevel gnus-level-killed)
1373 ;; Remove from active hashtb.
1374 (unintern group gnus-active-hashtb)
1375 ;; Don't add it into killed-list if it was killed.
1376 (push group gnus-killed-list)))))
1378 ;; If the list is to be entered into the newsrc assoc, and
1379 ;; it was killed, we have to create an entry in the newsrc
1380 ;; hashtb format and fix the pointers in the newsrc assoc.
1381 (if (< oldlevel gnus-level-zombie)
1382 ;; It was alive, and it is going to stay alive, so we
1383 ;; just change the level and don't change any pointers or
1384 ;; hash table entries.
1385 (setcar (cdaddr entry) level)
1387 (setq info (cdr entry)
1389 (setq active (gnus-active group))
1391 (if active (- (1+ (cdr active)) (car active)) t))
1392 ;; Shorten the select method if possible, if we need to
1393 ;; store it at all (native groups).
1394 (let ((method (gnus-method-simplify
1395 (or gnus-override-subscribe-method
1396 (gnus-group-method group)))))
1398 (setq info (list group level nil nil method))
1399 (setq info (list group level nil)))))
1402 (let ((p gnus-newsrc-alist))
1406 (setq entry (cons info (cddr previous)))
1409 (setcdr (cdr previous) entry)
1410 (gnus-sethash group (cons num (cdr previous))
1411 gnus-newsrc-hashtb))
1412 (setcdr previous entry)
1413 (gnus-sethash group (cons num previous)
1414 gnus-newsrc-hashtb))
1416 (setcdr (gnus-group-entry (caadr entry)) entry))
1419 "(gnus-group-set-info '%S)" info)))))
1420 (when gnus-group-change-level-function
1421 (funcall gnus-group-change-level-function
1422 group level oldlevel previous)))))
1424 (defun gnus-kill-newsgroup (newsgroup)
1425 "Obsolete function. Kills a newsgroup."
1426 (gnus-group-change-level
1427 (gnus-group-entry newsgroup) gnus-level-killed))
1429 (defun gnus-check-bogus-newsgroups (&optional confirm)
1430 "Remove bogus newsgroups.
1431 If CONFIRM is non-nil, the user has to confirm the deletion of every
1433 (let ((newsrc (cdr gnus-newsrc-alist))
1434 bogus group entry info)
1435 (gnus-message 5 "Checking bogus newsgroups...")
1436 (unless (gnus-read-active-file-p)
1437 (gnus-read-active-file t))
1438 (when (gnus-read-active-file-p)
1439 ;; Find all bogus newsgroup that are subscribed.
1441 (setq info (pop newsrc)
1442 group (gnus-info-group info))
1443 (unless (or (gnus-active group) ; Active
1444 (and (gnus-info-method info)
1445 (not (gnus-secondary-method-p
1446 (gnus-info-method info))))) ; Foreign
1447 ;; Found a bogus newsgroup.
1448 (push group bogus)))
1451 "Remove bogus group %s? "
1453 ;; Remove all bogus subscribed groups by first killing them, and
1454 ;; then removing them from the list of killed groups.
1455 (when (setq entry (gnus-group-entry group))
1456 (gnus-group-change-level entry gnus-level-killed)
1457 (setq gnus-killed-list (delete group gnus-killed-list))))
1458 bogus '("group" "groups" "remove"))
1459 (while (setq group (pop bogus))
1460 ;; Remove all bogus subscribed groups by first killing them, and
1461 ;; then removing them from the list of killed groups.
1462 (when (setq entry (gnus-group-entry group))
1463 (gnus-group-change-level entry gnus-level-killed)
1464 (setq gnus-killed-list (delete group gnus-killed-list)))))
1465 ;; Then we remove all bogus groups from the list of killed and
1466 ;; zombie groups. They are removed without confirmation.
1467 (let ((dead-lists '(gnus-killed-list gnus-zombie-list))
1470 (setq killed (symbol-value (car dead-lists)))
1472 (unless (gnus-active (setq group (pop killed)))
1473 ;; The group is bogus.
1475 (set (car dead-lists)
1476 (delete group (symbol-value (car dead-lists))))))
1477 (setq dead-lists (cdr dead-lists))))
1478 (gnus-run-hooks 'gnus-check-bogus-groups-hook)
1479 (gnus-message 5 "Checking bogus newsgroups...done"))))
1481 (defun gnus-check-duplicate-killed-groups ()
1482 "Remove duplicates from the list of killed groups."
1484 (let ((killed gnus-killed-list))
1486 (gnus-message 9 "%d" (length killed))
1487 (setcdr killed (delete (car killed) (cdr killed)))
1488 (setq killed (cdr killed)))))
1490 ;; We want to inline a function from gnus-cache, so we cheat here:
1492 (defvar gnus-cache-active-hashtb)
1493 (defun gnus-cache-possibly-alter-active (group active)
1494 "Alter the ACTIVE info for GROUP to reflect the articles in the cache."
1495 (when gnus-cache-active-hashtb
1496 (let ((cache-active (gnus-gethash group gnus-cache-active-hashtb)))
1498 (when (< (car cache-active) (car active))
1499 (setcar active (car cache-active)))
1500 (when (> (cdr cache-active) (cdr active))
1501 (setcdr active (cdr cache-active))))))))
1503 (defun gnus-activate-group (group &optional scan dont-check method)
1504 "Check whether a group has been activated or not.
1505 If SCAN, request a scan of that group as well."
1506 (let ((method (or method (inline (gnus-find-method-for-group group))))
1508 (and (inline (gnus-check-server method))
1509 ;; We escape all bugs and quit here to make it possible to
1510 ;; continue if a group is so out-there that it reports bugs
1514 (gnus-check-backend-function 'request-scan (car method))
1515 (gnus-request-scan group method))
1517 (if (or debug-on-error debug-on-quit)
1518 (inline (gnus-request-group group dont-check method))
1520 (inline (gnus-request-group group dont-check method))
1523 (message "Quit activating %s" group)
1526 (setq active (gnus-parse-active))
1527 ;; If there are no articles in the group, the GROUP
1528 ;; command may have responded with the `(0 . 0)'. We
1529 ;; ignore this if we already have an active entry
1531 (if (and (zerop (car active))
1532 (zerop (cdr active))
1533 (gnus-active group))
1536 ;; If a cache is present, we may have to alter the active info.
1537 (when gnus-use-cache
1538 (inline (gnus-cache-possibly-alter-active
1541 ;; If the agent is enabled, we may have to alter the active info.
1543 (gnus-agent-possibly-alter-active group active))
1545 (gnus-set-active group active)
1546 ;; Return the new active info.
1549 (defun gnus-get-unread-articles-in-group (info active &optional update)
1550 (when (and info active)
1551 ;; Allow the backend to update the info in the group.
1553 (gnus-request-update-info
1554 info (inline (gnus-find-method-for-group
1555 (gnus-info-group info)))))
1556 (gnus-activate-group (gnus-info-group info) nil t))
1558 (let* ((range (gnus-info-read info))
1561 ;; These checks are present in gnus-activate-group but skipped
1562 ;; due to setting dont-check in the preceeding call.
1564 ;; If a cache is present, we may have to alter the active info.
1565 (when (and gnus-use-cache info)
1566 (inline (gnus-cache-possibly-alter-active
1567 (gnus-info-group info) active)))
1569 ;; If the agent is enabled, we may have to alter the active info.
1570 (when (and gnus-agent info)
1571 (gnus-agent-possibly-alter-active (gnus-info-group info) active info))
1573 ;; Modify the list of read articles according to what articles
1574 ;; are available; then tally the unread articles and add the
1575 ;; number to the group hash table entry.
1577 ((zerop (cdr active))
1580 (setq num (- (1+ (cdr active)) (car active))))
1581 ((not (listp (cdr range)))
1582 ;; Fix a single (num . num) range according to the
1583 ;; active hash table.
1584 ;; Fix by Carsten Bormann <cabo@Informatik.Uni-Bremen.DE>.
1585 (and (< (cdr range) (car active)) (setcdr range (1- (car active))))
1586 (and (> (cdr range) (cdr active)) (setcdr range (cdr active)))
1587 ;; Compute number of unread articles.
1588 (setq num (max 0 (- (cdr active) (- (1+ (cdr range)) (car range))))))
1590 ;; The read list is a list of ranges. Fix them according to
1591 ;; the active hash table.
1592 ;; First peel off any elements that are below the lower
1594 (while (and (cdr range)
1596 (or (and (atom (cadr range)) (cadr range))
1598 (if (numberp (car range))
1601 (or (and (numberp (cadr range))
1605 (or (and (numberp (nth 1 range)) (nth 1 range))
1607 (setcdr range (cddr range)))
1608 ;; Adjust the first element to be the same as the lower limit.
1609 (when (and (not (atom (car range)))
1610 (< (cdar range) (car active)))
1611 (setcdr (car range) (1- (car active))))
1612 ;; Then we want to peel off any elements that are higher
1613 ;; than the upper active limit.
1614 (let ((srange range))
1615 ;; Go past all valid elements.
1616 (while (and (cdr srange)
1617 (<= (or (and (atom (cadr srange))
1621 (setq srange (cdr srange)))
1623 ;; Nuke all remaining invalid elements.
1624 (setcdr srange nil))
1626 ;; Adjust the final element.
1627 (when (and (not (atom (car srange)))
1628 (> (cdar srange) (cdr active)))
1629 (setcdr (car srange) (cdr active))))
1630 ;; Compute the number of unread articles.
1632 (setq num (+ num (- (1+ (or (and (atom (car range)) (car range))
1634 (or (and (atom (car range)) (car range))
1636 (setq range (cdr range)))
1637 (setq num (max 0 (- (cdr active) num)))))
1638 ;; Set the number of unread articles.
1640 (gnus-group-entry (gnus-info-group info)))
1641 (setcar (gnus-group-entry (gnus-info-group info)) num))
1644 ;; Go though `gnus-newsrc-alist' and compare with `gnus-active-hashtb'
1645 ;; and compute how many unread articles there are in each group.
1646 (defun gnus-get-unread-articles (&optional level)
1647 (setq gnus-server-method-cache nil)
1648 (let* ((newsrc (cdr gnus-newsrc-alist))
1649 (level (or level gnus-activate-level (1+ gnus-level-subscribed)))
1652 (cond ((and gnus-activate-foreign-newsgroups
1653 (not (numberp gnus-activate-foreign-newsgroups)))
1654 (1+ gnus-level-subscribed))
1655 ((numberp gnus-activate-foreign-newsgroups)
1656 gnus-activate-foreign-newsgroups)
1661 scanned-methods info group active method retrieve-groups cmethod
1663 (gnus-message 6 "Checking new news...")
1666 (setq active (gnus-active (setq group (gnus-info-group
1667 (setq info (pop newsrc))))))
1669 ;; Check newsgroups. If the user doesn't want to check them, or
1670 ;; they can't be checked (for instance, if the news server can't
1671 ;; be reached) we just set the number of unread articles in this
1672 ;; newsgroup to t. This means that Gnus thinks that there are
1673 ;; unread articles, but it has no idea how many.
1675 ;; To be more explicit:
1676 ;; >0 for an active group with messages
1677 ;; 0 for an active group with no unread messages
1678 ;; nil for non-foreign groups that the user has requested not be checked
1679 ;; t for unchecked foreign groups or bogus groups, or groups that can't
1680 ;; be checked, for one reason or other.
1681 (when (setq method (gnus-info-method info))
1682 (if (setq cmethod (assoc method methods-cache))
1683 (setq method (cdr cmethod))
1684 (setq cmethod (inline (gnus-server-get-method nil method)))
1685 (push (cons method cmethod) methods-cache)
1686 (setq method cmethod)))
1688 (not (setq method-type (cdr (assoc method type-cache)))))
1691 ((gnus-secondary-method-p method)
1693 ((inline (gnus-server-equal gnus-select-method method))
1697 (push (cons method method-type) type-cache))
1700 (cond ((and method (eq method-type 'foreign))
1701 ;; These groups are foreign. Check the level.
1702 (if (<= (gnus-info-level info) foreign-level)
1703 (when (setq active (gnus-activate-group group 'scan))
1704 ;; Let the Gnus agent save the active file.
1705 (when (and gnus-agent active (gnus-online method))
1706 (gnus-agent-save-group-info
1707 method (gnus-group-real-name group) active))
1708 (unless (inline (gnus-virtual-group-p group))
1709 (inline (gnus-close-group group)))
1710 (when (fboundp (intern (concat (symbol-name (car method))
1711 "-request-update-info")))
1712 (inline (gnus-request-update-info info method))))
1714 ;; These groups are native or secondary.
1715 ((> (gnus-info-level info) level)
1716 ;; We don't want these groups.
1717 (setq active 'ignore))
1719 ((not gnus-read-active-file)
1720 (if (gnus-check-backend-function 'retrieve-groups group)
1721 ;; if server support gnus-retrieve-groups we push
1722 ;; the group onto retrievegroups for later checking
1723 (if (assoc method retrieve-groups)
1724 (setcdr (assoc method retrieve-groups)
1725 (cons group (cdr (assoc method retrieve-groups))))
1726 (push (list method group) retrieve-groups))
1727 ;; hack: `nnmail-get-new-mail' changes the mail-source depending
1728 ;; on the group, so we must perform a scan for every group
1729 ;; if the users has any directory mail sources.
1730 ;; hack: if `nnmail-scan-directory-mail-source-once' is non-nil,
1731 ;; for it scan all spool files even when the groups are
1734 (or nnmail-scan-directory-mail-source-once
1735 (null (assq 'directory
1737 (if (listp nnmail-spool-file)
1739 (list nnmail-spool-file))))))
1740 (member method scanned-methods))
1741 (setq active (gnus-activate-group group))
1742 (setq active (gnus-activate-group group 'scan))
1743 (push method scanned-methods))
1745 (gnus-close-group group)))))
1747 ;; Get the number of unread articles in the group.
1749 ((eq active 'ignore)
1750 ;; Don't do anything.
1752 ((and active ignore)
1753 ;; The level of the foreign group is higher than the specified
1757 (inline (gnus-get-unread-articles-in-group info active t)))
1759 ;; The group couldn't be reached, so we nix out the number of
1760 ;; unread articles and stuff.
1761 (gnus-set-active group nil)
1762 (let ((tmp (gnus-group-entry group)))
1766 ;; iterate through groups on methods which support gnus-retrieve-groups
1767 ;; and fetch a partial active file and use it to find new news.
1768 (dolist (rg retrieve-groups)
1769 (let ((method (or (car rg) gnus-select-method))
1771 (when (gnus-check-server method)
1772 ;; Request that the backend scan its incoming messages.
1773 (when (gnus-check-backend-function 'request-scan (car method))
1774 (gnus-request-scan nil method))
1775 (gnus-read-active-file-2
1776 (mapcar (lambda (group) (gnus-group-real-name group)) groups)
1778 (dolist (group groups)
1780 ((setq active (gnus-active (gnus-info-group
1781 (setq info (gnus-get-info group)))))
1782 (inline (gnus-get-unread-articles-in-group info active t)))
1784 ;; The group couldn't be reached, so we nix out the number of
1785 ;; unread articles and stuff.
1786 (gnus-set-active group nil)
1787 (setcar (gnus-group-entry group) t)))))))
1789 (gnus-message 6 "Checking new news...done")))
1791 ;; Create a hash table out of the newsrc alist. The `car's of the
1792 ;; alist elements are used as keys.
1793 (defun gnus-make-hashtable-from-newsrc-alist ()
1794 (let ((alist gnus-newsrc-alist)
1795 (ohashtb gnus-newsrc-hashtb)
1796 prev info method rest methods)
1797 (setq gnus-newsrc-hashtb (gnus-make-hashtable (length alist)))
1799 (setq prev (setq gnus-newsrc-alist
1800 (if (equal (caar gnus-newsrc-alist)
1803 (cons (list "dummy.group" 0 nil) alist)))))
1805 (setq info (car alist))
1806 ;; Make the same select-methods identical Lisp objects.
1807 (when (setq method (gnus-info-method info))
1808 (if (setq rest (member method methods))
1809 (gnus-info-set-method info (car rest))
1810 (push method methods)))
1813 ;; Preserve number of unread articles in groups.
1814 (cons (and ohashtb (car (gnus-gethash (car info) ohashtb)))
1819 ;; Make the same select-methods in `gnus-server-alist' identical
1822 (setq method (pop methods))
1823 (when (setq rest (rassoc method gnus-server-alist))
1824 (setcdr rest method)))))
1826 (defun gnus-make-hashtable-from-killed ()
1827 "Create a hash table from the killed and zombie lists."
1828 (let ((lists '(gnus-killed-list gnus-zombie-list))
1830 (setq gnus-killed-hashtb
1831 (gnus-make-hashtable
1832 (+ (length gnus-killed-list) (length gnus-zombie-list))))
1834 (setq list (symbol-value (pop lists)))
1836 (gnus-sethash (car list) (pop list) gnus-killed-hashtb)))))
1838 (defun gnus-parse-active ()
1839 "Parse active info in the nntp server buffer."
1841 (set-buffer nntp-server-buffer)
1842 (goto-char (point-min))
1843 ;; Parse the result we got from `gnus-request-group'.
1844 (when (looking-at "[0-9]+ [0-9]+ \\([0-9]+\\) [0-9]+")
1845 (goto-char (match-beginning 1))
1846 (cons (read (current-buffer))
1847 (read (current-buffer))))))
1849 (defun gnus-make-articles-unread (group articles)
1850 "Mark ARTICLES in GROUP as unread."
1851 (let* ((info (nth 2 (or (gnus-group-entry group)
1853 (gnus-group-real-name group)))))
1854 (ranges (gnus-info-read info))
1857 (when (gnus-member-of-range
1858 (setq article (pop articles)) ranges)
1859 (push article news)))
1861 ;; Enter this list into the group info.
1863 info (gnus-remove-from-range (gnus-info-read info) (nreverse news)))
1865 ;; Set the number of unread articles in gnus-newsrc-hashtb.
1866 (gnus-get-unread-articles-in-group info (gnus-active group))
1868 ;; Insert the change into the group buffer and the dribble file.
1869 (gnus-group-update-group group t))))
1871 (defun gnus-make-ascending-articles-unread (group articles)
1872 "Mark ascending ARTICLES in GROUP as unread."
1873 (let* ((entry (or (gnus-group-entry group)
1874 (gnus-group-entry (gnus-group-real-name group))))
1875 (info (nth 2 entry))
1876 (ranges (gnus-info-read info))
1881 (let ((article (pop articles))) ; get the next article to remove from ranges
1882 (while (let ((range (car ranges))) ; note the current range
1883 (if (atom range) ; single value range
1885 ;; the articles extend past the end of the ranges
1887 (setq articles nil))
1889 ;; this range preceeds the article. Leave the range unmodified.
1893 ;; this range exactly matches the article; REMOVE THE RANGE.
1894 ;; NOTE: When the range being removed is the last range, the list is corrupted by inserting null at its end.
1895 (setcar ranges (cadr ranges))
1896 (setcdr ranges (cddr ranges))
1897 (setq modified (if (car ranges) t 'remove-null))
1899 (let ((min (car range))
1901 ;; I have a min/max range to consider
1902 (cond ((> min max) ; invalid range introduced by splitter
1903 (setcar ranges (cadr ranges))
1904 (setcdr ranges (cddr ranges))
1905 (setq modified (if (car ranges) t 'remove-null))
1908 ;; replace min/max range with a single-value range
1912 ;; this range preceeds the article. Leave the range unmodified.
1916 ;; this article preceeds the range. Return null to move to the
1920 ;; this article splits the range into two parts
1921 (setcdr ranges (cons (cons (1+ article) max) (cdr ranges)))
1922 (setcdr range (1- article))
1927 (when (eq modified 'remove-null)
1928 (setq r (delq nil r)))
1929 ;; Enter this list into the group info.
1930 (gnus-info-set-read info r)
1932 ;; Set the number of unread articles in gnus-newsrc-hashtb.
1933 (gnus-get-unread-articles-in-group info (gnus-active group))
1935 ;; Insert the change into the group buffer and the dribble file.
1936 (gnus-group-update-group group t))))
1938 ;; Enter all dead groups into the hashtb.
1939 (defun gnus-update-active-hashtb-from-killed ()
1940 (let ((hashtb (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
1941 (lists (list gnus-killed-list gnus-zombie-list))
1944 (setq killed (car lists))
1946 (gnus-sethash (car killed) nil hashtb)
1947 (setq killed (cdr killed)))
1948 (setq lists (cdr lists)))))
1950 (defun gnus-get-killed-groups ()
1951 "Go through the active hashtb and mark all unknown groups as killed."
1952 ;; First make sure active file has been read.
1953 (unless (gnus-read-active-file-p)
1954 (let ((gnus-read-active-file t))
1955 (gnus-read-active-file)))
1956 (unless gnus-killed-hashtb
1957 (gnus-make-hashtable-from-killed))
1958 ;; Go through all newsgroups that are known to Gnus - enlarge kill list.
1962 (group (symbol-name sym)))
1963 (if (or (null group)
1964 (gnus-gethash group gnus-killed-hashtb)
1965 (gnus-gethash group gnus-newsrc-hashtb))
1967 (let ((do-sub (gnus-matches-options-n group)))
1968 (if (or (eq do-sub 'subscribe) (eq do-sub 'ignore))
1970 (setq groups (1+ groups))
1971 (push group gnus-killed-list)
1972 (gnus-sethash group group gnus-killed-hashtb))))))
1974 (gnus-dribble-touch))
1976 ;; Get the active file(s) from the backend(s).
1977 (defun gnus-read-active-file (&optional force not-native)
1978 (gnus-group-set-mode-line)
1981 (lambda (m) (if (stringp m) (gnus-server-get-method nil m) m))
1983 (if (and (not not-native)
1984 (gnus-check-server gnus-select-method))
1985 ;; The native server is available.
1986 (cons gnus-select-method gnus-secondary-select-methods)
1987 ;; The native server is down, so we just do the
1989 gnus-secondary-select-methods)
1990 ;; Also read from the archive server.
1991 (when (gnus-archive-server-wanted-p)
1992 (list "archive")))))
1994 (setq gnus-have-read-active-file nil)
1996 (set-buffer nntp-server-buffer)
1997 (while (setq method (pop methods))
1998 ;; Only do each method once, in case the methods appear more
1999 ;; than once in this list.
2000 (unless (member method methods)
2001 (if (or debug-on-error debug-on-quit)
2002 (gnus-read-active-file-1 method force)
2004 (gnus-read-active-file-1 method force)
2005 ;; We catch C-g so that we can continue past servers
2006 ;; that do not respond.
2008 (message "Quit reading the active file")
2011 (defun gnus-read-active-file-1 (method force)
2013 (setq where (nth 1 method)
2014 mesg (format "Reading active file%s via %s..."
2015 (if (and where (not (zerop (length where))))
2016 (concat " from " where) "")
2018 (gnus-message 5 mesg)
2019 (when (gnus-check-server method)
2020 ;; Request that the backend scan its incoming messages.
2021 (when (gnus-check-backend-function 'request-scan (car method))
2022 (gnus-request-scan nil method))
2024 ((and (eq gnus-read-active-file 'some)
2025 (gnus-check-backend-function 'retrieve-groups (car method))
2027 (let ((newsrc (cdr gnus-newsrc-alist))
2028 (gmethod (gnus-server-get-method nil method))
2030 (while (setq info (pop newsrc))
2034 (gnus-find-method-for-group
2035 (gnus-info-group info) info))
2037 (push (gnus-group-real-name (gnus-info-group info))
2039 (gnus-read-active-file-2 groups method)))
2043 (if (not (gnus-request-list method))
2044 (unless (equal method gnus-message-archive-method)
2045 (gnus-error 1 "Cannot read active file from %s server"
2047 (gnus-message 5 mesg)
2048 (gnus-active-to-gnus-format method gnus-active-hashtb nil t)
2049 ;; We mark this active file as read.
2050 (push method gnus-have-read-active-file)
2051 (gnus-message 5 "%sdone" mesg)))))))
2053 (defun gnus-read-active-file-2 (groups method)
2054 "Read an active file for GROUPS in METHOD using `gnus-retrieve-groups'."
2057 (set-buffer nntp-server-buffer)
2058 (gnus-check-server method)
2059 (let ((list-type (gnus-retrieve-groups groups method)))
2060 (cond ((not list-type)
2062 1.2 "Cannot read partial active file from %s server."
2064 ((eq list-type 'active)
2065 (gnus-active-to-gnus-format method gnus-active-hashtb nil t))
2067 (gnus-groups-to-gnus-format method gnus-active-hashtb t)))))))
2069 ;; Read an active file and place the results in `gnus-active-hashtb'.
2070 (defun gnus-active-to-gnus-format (&optional method hashtb ignore-errors
2073 (setq method gnus-select-method))
2074 (let ((cur (current-buffer))
2076 (if (and gnus-active-hashtb
2077 (not (equal method gnus-select-method)))
2079 (setq gnus-active-hashtb
2080 (if (equal method gnus-select-method)
2081 (gnus-make-hashtable
2082 (count-lines (point-min) (point-max)))
2083 (gnus-make-hashtable 4096)))))))
2084 ;; Delete unnecessary lines.
2085 (goto-char (point-min))
2087 ((string= gnus-ignored-newsgroups "")
2088 (delete-matching-lines "^to\\."))
2090 (delete-matching-lines (concat "^to\\.\\|" gnus-ignored-newsgroups))))
2092 (goto-char (point-min))
2093 (unless (re-search-forward "[\\\"]" nil t)
2094 ;; Make the group names readable as a lisp expression even if they
2095 ;; contain special characters.
2096 (goto-char (point-max))
2097 (while (re-search-backward "[][';?()#]" nil t)
2100 ;; Let the Gnus agent save the active file.
2101 (when (and gnus-agent real-active (gnus-online method))
2102 (gnus-agent-save-active method))
2104 ;; If these are groups from a foreign select method, we insert the
2105 ;; group prefix in front of the group names.
2106 (when (not (gnus-server-equal
2107 (gnus-server-get-method nil method)
2108 (gnus-server-get-method nil gnus-select-method)))
2109 (let ((prefix (gnus-group-prefixed-name "" method)))
2110 (goto-char (point-min))
2111 (while (and (not (eobp))
2113 (when (= (following-char) ?\")
2116 (zerop (forward-line 1)))))))
2117 ;; Store the active file in a hash table.
2118 (goto-char (point-min))
2119 (let (group max min)
2123 (narrow-to-region (point) (point-at-eol))
2124 ;; group gets set to a symbol interned in the hash table
2125 ;; (what a hack!!) - jwz
2126 (setq group (let ((obarray hashtb)) (read cur)))
2127 ;; ### The extended group name scheme makes
2128 ;; the previous optimization strategy sort of pointless...
2129 (when (stringp group)
2130 (setq group (intern group hashtb)))
2131 (if (and (numberp (setq max (read cur)))
2132 (numberp (setq min (read cur)))
2134 (skip-chars-forward " \t")
2136 (or (eq (char-after) ?=)
2137 (eq (char-after) ?x)
2138 (eq (char-after) ?j)))))
2140 (set group (cons min max))
2141 ;; if group is moderated, stick in moderation table
2142 (when (eq (char-after) ?m)
2143 (unless gnus-moderated-hashtb
2144 (setq gnus-moderated-hashtb (gnus-make-hashtable)))
2145 (gnus-sethash (symbol-name group) t
2146 gnus-moderated-hashtb)))
2152 (unless ignore-errors
2153 (gnus-message 3 "Warning - invalid active: %s"
2155 (point-at-bol) (point-at-eol))))))
2157 (forward-line 1)))))
2159 (defun gnus-groups-to-gnus-format (method &optional hashtb real-active)
2160 ;; Parse a "groups" active file.
2161 (let ((cur (current-buffer))
2163 (if (and method gnus-active-hashtb)
2165 (setq gnus-active-hashtb
2166 (gnus-make-hashtable
2167 (count-lines (point-min) (point-max)))))))
2169 (not (gnus-server-equal
2170 (gnus-server-get-method nil method)
2171 (gnus-server-get-method nil gnus-select-method)))
2172 (gnus-group-prefixed-name "" method))))
2174 ;; Let the Gnus agent save the active file.
2177 (gnus-online method)
2178 (gnus-agent-method-p method))
2180 (gnus-agent-save-active method)
2181 (gnus-active-to-gnus-format method hashtb nil real-active))
2183 (goto-char (point-min))
2184 ;; We split this into to separate loops, one with the prefix
2185 ;; and one without to speed the reading up somewhat.
2187 (let (min max opoint group)
2191 (read cur) (read cur)
2192 (setq min (read cur)
2195 (skip-chars-forward " \t")
2198 (set (let ((obarray hashtb)) (read cur))
2200 (error (and group (symbolp group) (set group nil))))
2202 (let (min max group)
2205 (when (eq (char-after) ?2)
2206 (read cur) (read cur)
2207 (setq min (read cur)
2209 (set (setq group (let ((obarray hashtb)) (read cur)))
2211 (error (and group (symbolp group) (set group nil))))
2212 (forward-line 1)))))))
2214 (defun gnus-read-newsrc-file (&optional force)
2216 If FORCE is non-nil, the .newsrc file is read."
2217 ;; Reset variables that might be defined in the .newsrc.eld file.
2218 (let ((variables (remove 'gnus-format-specs gnus-variable-list)))
2220 (set (car variables) nil)
2221 (setq variables (cdr variables))))
2222 (let* ((newsrc-file gnus-current-startup-file)
2223 (quick-file (concat newsrc-file ".el")))
2225 ;; We always load the .newsrc.eld file. If always contains
2226 ;; much information that can not be gotten from the .newsrc
2227 ;; file (ticked articles, killed groups, foreign methods, etc.)
2228 (gnus-read-newsrc-el-file quick-file)
2230 (when (and gnus-read-newsrc-file
2231 (file-exists-p gnus-current-startup-file)
2233 (and (file-newer-than-file-p newsrc-file quick-file)
2234 (file-newer-than-file-p newsrc-file
2235 (concat quick-file "d")))
2236 (not gnus-newsrc-alist)))
2237 ;; We read the .newsrc file. Note that if there if a
2238 ;; .newsrc.eld file exists, it has already been read, and
2239 ;; the `gnus-newsrc-hashtb' has been created. While reading
2240 ;; the .newsrc file, Gnus will only use the information it
2241 ;; can find there for changing the data already read -
2242 ;; i. e., reading the .newsrc file will not trash the data
2243 ;; already read (except for read articles).
2245 (gnus-message 5 "Reading %s..." newsrc-file)
2246 (set-buffer (nnheader-find-file-noselect newsrc-file))
2247 (buffer-disable-undo)
2248 (gnus-newsrc-to-gnus-format)
2249 (kill-buffer (current-buffer))
2250 (gnus-message 5 "Reading %s...done" newsrc-file)))
2252 ;; Convert old to new.
2253 (gnus-convert-old-newsrc))))
2255 (defun gnus-convert-old-newsrc ()
2256 "Convert old newsrc formats into the current format, if needed."
2257 (let ((fcv (and gnus-newsrc-file-version
2258 (gnus-continuum-version gnus-newsrc-file-version))))
2260 ;; A newsrc file was loaded.
2261 (let (prompt-displayed
2264 (mapcar (lambda (date-func)
2265 (cons (gnus-continuum-version (car date-func))
2267 ;; This is a list of converters that must be run
2268 ;; to bring the newsrc file up to the current
2269 ;; version. If you create an incompatibility
2270 ;; with older versions, you should create an
2271 ;; entry here. The entry should consist of the
2272 ;; current gnus version (hardcoded so that it
2273 ;; doesn't change with each release) and the
2274 ;; function that must be applied to convert the
2275 ;; previous version into the current version.
2276 '(("September Gnus v0.1" nil
2277 gnus-convert-old-ticks)
2278 ("Oort Gnus v0.08" "legacy-gnus-agent"
2279 gnus-agent-convert-to-compressed-agentview)
2280 ("Gnus v5.10.7" "legacy-gnus-agent"
2281 gnus-agent-unlist-expire-days)
2282 ("Gnus v5.10.7" "legacy-gnus-agent"
2283 gnus-agent-unhook-expire-days)))
2284 #'car-less-than-car)))
2285 ;; Skip converters older than the file version
2286 (while (and converters (>= fcv (caar converters)))
2289 ;; Perform converters to bring older version up to date.
2290 (when (and converters (< fcv (caar converters)))
2291 (while (and converters (< fcv (caar converters)))
2292 (let* ((converter-spec (pop converters))
2293 (convert-to (nth 1 converter-spec))
2294 (load-from (nth 2 converter-spec))
2295 (func (nth 3 converter-spec)))
2296 (when (and load-from
2297 (not (fboundp func)))
2299 (or prompt-displayed
2300 (not (gnus-convert-converter-needs-prompt func))
2302 (cursor-in-echo-area t)
2303 (echo-keystrokes 0))
2304 (message "Convert gnus from version '%s' to '%s'? (n/y/?)"
2305 gnus-newsrc-file-version gnus-version)
2306 (setq c (read-char-exclusive))
2308 (cond ((or (eq c ?n) (eq c ?N))
2309 (error "Can not start gnus without converting"))
2310 ((or (eq c ?y) (eq c ?Y))
2311 (setq prompt-displayed t)
2314 (message "This conversion is irreversible. \
2315 To be safe, you should backup your files before proceeding.")
2319 (gnus-message 3 "Ignoring unexpected input")
2323 (funcall func convert-to)))
2325 (format ";Converted gnus from version '%s' to '%s'."
2326 gnus-newsrc-file-version gnus-version)))))))
2328 (defun gnus-convert-mark-converter-prompt (converter no-prompt)
2329 "Indicate whether CONVERTER requires gnus-convert-old-newsrc to
2330 display the conversion prompt. NO-PROMPT may be nil (prompt),
2331 t (no prompt), or any form that can be called as a function.
2332 The form should return either t or nil."
2333 (put converter 'gnus-convert-no-prompt no-prompt))
2335 (defun gnus-convert-converter-needs-prompt (converter)
2336 (let ((no-prompt (get converter 'gnus-convert-no-prompt)))
2337 (not (if (memq no-prompt '(t nil))
2339 (funcall no-prompt)))))
2341 (defun gnus-convert-old-ticks (converting-to)
2342 (let ((newsrc (cdr gnus-newsrc-alist))
2343 marks info dormant ticked)
2344 (while (setq info (pop newsrc))
2345 (when (setq marks (gnus-info-marks info))
2346 (setq dormant (cdr (assq 'dormant marks))
2347 ticked (cdr (assq 'tick marks)))
2348 (when (or dormant ticked)
2352 (gnus-info-read info)
2353 (nconc (gnus-uncompress-range dormant)
2354 (gnus-uncompress-range ticked)))))))))
2356 (defun gnus-load (file)
2357 "Load FILE, but in such a way that read errors can be reported."
2359 (insert-file-contents file)
2361 (condition-case type
2362 (let ((form (read (current-buffer))))
2365 (unless (eq (car type) 'end-of-file)
2366 (let ((error (format "Error in %s line %d" file
2367 (count-lines (point-min) (point)))))
2369 (unless (gnus-yes-or-no-p (concat error "; continue? "))
2370 (error "%s" error)))))))))
2372 (defun gnus-read-newsrc-el-file (file)
2373 (let ((ding-file (concat file "d")))
2374 (when (file-exists-p ding-file)
2375 ;; We always, always read the .eld file.
2376 (gnus-message 5 "Reading %s..." ding-file)
2377 (let (gnus-newsrc-assoc)
2378 (let ((coding-system-for-read gnus-ding-file-coding-system))
2379 (gnus-load ding-file))
2380 ;; Older versions of `gnus-format-specs' are no longer valid
2381 ;; in Oort Gnus 0.01.
2383 (and gnus-newsrc-file-version
2384 (gnus-continuum-version gnus-newsrc-file-version))))
2385 (when (or (not version)
2386 (< version 5.090009))
2387 (setq gnus-format-specs gnus-default-format-specs)))
2388 (when gnus-newsrc-assoc
2389 (setq gnus-newsrc-alist gnus-newsrc-assoc))))
2390 (gnus-make-hashtable-from-newsrc-alist)
2391 (when (file-newer-than-file-p file ding-file)
2392 ;; Old format quick file
2393 (gnus-message 5 "Reading %s..." file)
2394 ;; The .el file is newer than the .eld file, so we read that one
2396 (gnus-read-old-newsrc-el-file file)))
2397 (gnus-run-hooks 'gnus-read-newsrc-el-hook))
2399 ;; Parse the old-style quick startup file
2400 (defun gnus-read-old-newsrc-el-file (file)
2401 (let (newsrc killed marked group m info)
2403 (let ((gnus-killed-assoc nil)
2404 gnus-marked-assoc gnus-newsrc-alist gnus-newsrc-assoc)
2408 (setq newsrc gnus-newsrc-assoc
2409 killed gnus-killed-assoc
2410 marked gnus-marked-assoc)))
2411 (setq gnus-newsrc-alist nil)
2412 (while (setq group (pop newsrc))
2413 (if (setq info (gnus-get-info (car group)))
2415 (gnus-info-set-read info (cddr group))
2416 (gnus-info-set-level
2417 info (if (nth 1 group) gnus-level-default-subscribed
2418 gnus-level-default-unsubscribed))
2419 (push info gnus-newsrc-alist))
2422 (if (nth 1 group) gnus-level-default-subscribed
2423 gnus-level-default-unsubscribed)
2426 ;; Copy marks into info.
2427 (when (setq m (assoc (car group) marked))
2428 (unless (nthcdr 3 info)
2429 (nconc info (list nil)))
2430 (gnus-info-set-marks
2431 info (list (cons 'tick (gnus-compress-sequence
2432 (sort (cdr m) '<) t))))))
2433 (setq newsrc killed)
2435 (setcar newsrc (caar newsrc))
2436 (setq newsrc (cdr newsrc)))
2437 (setq gnus-killed-list killed))
2438 ;; The .el file version of this variable does not begin with
2439 ;; "options", while the .eld version does, so we just add it if it
2443 (when (not (string-match "^ *options" gnus-newsrc-options))
2444 (setq gnus-newsrc-options (concat "options " gnus-newsrc-options)))
2445 (when (not (string-match "\n$" gnus-newsrc-options))
2446 (setq gnus-newsrc-options (concat gnus-newsrc-options "\n")))
2447 ;; Finally, if we read some options lines, we parse them.
2448 (unless (string= gnus-newsrc-options "")
2449 (gnus-newsrc-parse-options gnus-newsrc-options)))
2451 (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist))
2452 (gnus-make-hashtable-from-newsrc-alist)))
2454 (defun gnus-make-newsrc-file (file)
2455 "Make server dependent file name by catenating FILE and server host name."
2456 (let* ((file (expand-file-name file nil))
2457 (real-file (concat file "-" (nth 1 gnus-select-method))))
2458 (if (or (file-exists-p real-file)
2459 (file-exists-p (concat real-file ".el"))
2460 (file-exists-p (concat real-file ".eld")))
2464 (defun gnus-newsrc-to-gnus-format ()
2465 (setq gnus-newsrc-options "")
2466 (setq gnus-newsrc-options-n nil)
2468 (unless gnus-active-hashtb
2469 (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
2470 (let ((buf (current-buffer))
2471 (already-read (> (length gnus-newsrc-alist) 1))
2472 group subscribed options-symbol newsrc Options-symbol
2474 (goto-char (point-min))
2475 ;; We intern the symbol `options' in the active hashtb so that we
2476 ;; can `eq' against it later.
2477 (set (setq options-symbol (intern "options" gnus-active-hashtb)) nil)
2478 (set (setq Options-symbol (intern "Options" gnus-active-hashtb)) nil)
2481 ;; We first read the first word on the line by narrowing and
2482 ;; then reading into `gnus-active-hashtb'. Most groups will
2483 ;; already exist in that hashtb, so this will save some string
2487 (progn (skip-chars-forward "^ \t!:\n") (point)))
2488 (goto-char (point-min))
2490 (and (/= (point-min) (point-max))
2491 (let ((obarray gnus-active-hashtb)) (read buf))))
2493 ;; Now, the symbol we have read is either `options' or a group
2494 ;; name. If it is an options line, we just add it to a string.
2496 ((or (eq symbol options-symbol)
2497 (eq symbol Options-symbol))
2498 (setq gnus-newsrc-options
2499 ;; This concating is quite inefficient, but since our
2500 ;; thorough studies show that approx 99.37% of all
2501 ;; .newsrc files only contain a single options line, we
2502 ;; don't give a damn, frankly, my dear.
2503 (concat gnus-newsrc-options
2506 ;; Options may continue on the next line.
2507 (or (and (re-search-forward "^[^ \t]" nil 'move)
2512 ;; Group names can be just numbers.
2513 (when (numberp symbol)
2514 (setq symbol (intern (int-to-string symbol) gnus-active-hashtb)))
2515 (unless (boundp symbol)
2517 ;; It was a group name.
2518 (setq subscribed (eq (char-after) ?:)
2519 group (symbol-name symbol)
2522 ;; If the line ends here, this is clearly a buggy line, so
2523 ;; we put point a the beginning of line and let the cond
2524 ;; below do the error handling.
2526 ;; We skip to the beginning of the ranges.
2527 (skip-chars-forward "!: \t"))
2528 ;; We are now at the beginning of the list of read articles.
2529 ;; We read them range by range.
2532 ((looking-at "[0-9]+")
2533 ;; We narrow and read a number instead of buffer-substring/
2534 ;; string-to-int because it's faster. narrow/widen is
2535 ;; faster than save-restriction/narrow, and save-restriction
2536 ;; produces a garbage object.
2538 (narrow-to-region (match-beginning 0) (match-end 0))
2541 ;; If the next character is a dash, then this is a range.
2542 (if (eq (char-after) ?-)
2544 ;; We read the upper bound of the range.
2546 (if (not (looking-at "[0-9]+"))
2547 ;; This is a buggy line, by we pretend that
2548 ;; it's kinda OK. Perhaps the user should be
2554 (narrow-to-region (match-beginning 0)
2559 ;; It was just a simple number, so we add it to the
2562 ;; If the next char in ?\n, then we have reached the end
2563 ;; of the line and return nil.
2564 (not (eq (char-after) ?\n)))
2565 ((eq (char-after) ?\n)
2566 ;; End of line, so we end.
2569 ;; Not numbers and not eol, so this might be a buggy
2572 ;; If it was eob instead of ?\n, we allow it.
2573 ;; The line was buggy.
2575 (gnus-error 3.1 "Mangled line: %s"
2576 (buffer-substring (point-at-bol)
2579 ;; Skip past ", ". Spaces are invalid in these ranges, but
2580 ;; we allow them, because it's a common mistake to put a
2581 ;; space after the comma.
2582 (skip-chars-forward ", "))
2584 ;; We have already read .newsrc.eld, so we gently update the
2585 ;; data in the hash table with the information we have just
2588 (let ((info (gnus-get-info group))
2591 ;; There is an entry for this file in the alist.
2593 (gnus-info-set-read info (nreverse reads))
2594 ;; We update the level very gently. In fact, we
2595 ;; only change it if there's been a status change
2596 ;; from subscribed to unsubscribed, or vice versa.
2597 (setq level (gnus-info-level info))
2598 (cond ((and (<= level gnus-level-subscribed)
2600 (setq level (if reads
2601 gnus-level-default-unsubscribed
2602 (1+ gnus-level-default-unsubscribed))))
2603 ((and (> level gnus-level-subscribed) subscribed)
2604 (setq level gnus-level-default-subscribed)))
2605 (gnus-info-set-level info level))
2606 ;; This is a new group.
2607 (setq info (list group
2609 gnus-level-default-subscribed
2611 (1+ gnus-level-subscribed)
2612 gnus-level-default-unsubscribed))
2614 (push info newsrc)))))
2617 (setq newsrc (nreverse newsrc))
2619 (if (not already-read)
2621 ;; We now have two newsrc lists - `newsrc', which is what we
2622 ;; have read from .newsrc, and `gnus-newsrc-alist', which is
2623 ;; what we've read from .newsrc.eld. We have to merge these
2624 ;; lists. We do this by "attaching" any (foreign) groups in the
2625 ;; gnus-newsrc-alist to the (native) group that precedes them.
2626 (let ((rc (cdr gnus-newsrc-alist))
2627 (prev gnus-newsrc-alist)
2630 (or (null (nth 4 (car rc))) ; It's a native group.
2631 (assoc (caar rc) newsrc) ; It's already in the alist.
2632 (if (setq entry (assoc (caar prev) newsrc))
2633 (setcdr (setq mentry (memq entry newsrc))
2634 (cons (car rc) (cdr mentry)))
2635 (push (car rc) newsrc)))
2639 (setq gnus-newsrc-alist newsrc)
2640 ;; We make the newsrc hashtb.
2641 (gnus-make-hashtable-from-newsrc-alist)
2643 ;; Finally, if we read some options lines, we parse them.
2644 (unless (string= gnus-newsrc-options "")
2645 (gnus-newsrc-parse-options gnus-newsrc-options))))
2647 ;; Parse options lines to find "options -n !all rec.all" and stuff.
2648 ;; The return value will be a list on the form
2649 ;; ((regexp1 . ignore)
2650 ;; (regexp2 . subscribe)...)
2651 ;; When handling new newsgroups, groups that match a `ignore' regexp
2652 ;; will be ignored, and groups that match a `subscribe' regexp will be
2653 ;; subscribed. A line like
2654 ;; options -n !all rec.all
2655 ;; will lead to a list that looks like
2656 ;; (("^rec\\..+" . subscribe)
2657 ;; ("^.+" . ignore))
2658 ;; So all "rec.*" groups will be subscribed, while all the other
2659 ;; groups will be ignored. Note that "options -n !all rec.all" is very
2660 ;; different from "options -n rec.all !all".
2661 (defun gnus-newsrc-parse-options (options)
2664 (gnus-set-work-buffer)
2665 (insert (regexp-quote options))
2666 ;; First we treat all continuation lines.
2667 (goto-char (point-min))
2668 (while (re-search-forward "\n[ \t]+" nil t)
2669 (replace-match " " t t))
2670 ;; Then we transform all "all"s into ".+"s.
2671 (goto-char (point-min))
2672 (while (re-search-forward "\\ball\\b" nil t)
2673 (replace-match ".+" t t))
2674 (goto-char (point-min))
2675 ;; We remove all other options than the "-n" ones.
2676 (while (re-search-forward "[ \t]-[^n][^-]*" nil t)
2679 (goto-char (point-min))
2681 ;; We are only interested in "options -n" lines - we
2682 ;; ignore the other option lines.
2683 (while (re-search-forward "[ \t]-n" nil t)
2686 (and (re-search-forward "[ \t]-n" (point-at-eol) t)
2689 ;; Search for all "words"...
2690 (while (re-search-forward "[^ \t,\n]+" eol t)
2691 (if (eq (char-after (match-beginning 0)) ?!)
2692 ;; If the word begins with a bang (!), this is a "not"
2693 ;; spec. We put this spec (minus the bang) and the
2694 ;; symbol `ignore' into the list.
2696 "^" (buffer-substring
2697 (1+ (match-beginning 0))
2702 ;; There was no bang, so this is a "yes" spec.
2703 (push (cons (concat "^" (match-string 0) "\\($\\|\\.\\)")
2707 (setq gnus-newsrc-options-n out))))
2710 (defalias 'gnus-long-file-names
2711 (if (fboundp 'msdos-long-file-names)
2712 'msdos-long-file-names
2715 (defun gnus-save-newsrc-file (&optional force)
2716 "Save .newsrc file."
2717 ;; Note: We cannot save .newsrc file if all newsgroups are removed
2718 ;; from the variable gnus-newsrc-alist.
2719 (when (and (or gnus-newsrc-alist gnus-killed-list)
2720 gnus-current-startup-file)
2721 ;; Save agent range limits for the currently active method.
2723 (gnus-agent-save-local force))
2726 (if (and (or gnus-use-dribble-file gnus-slave)
2728 (or (not gnus-dribble-buffer)
2729 (not (buffer-name gnus-dribble-buffer))
2730 (zerop (save-excursion
2731 (set-buffer gnus-dribble-buffer)
2733 (gnus-message 4 "(No changes need to be saved)")
2734 (gnus-run-hooks 'gnus-save-newsrc-hook)
2736 (gnus-slave-save-newsrc)
2738 (when gnus-save-newsrc-file
2739 (gnus-message 8 "Saving %s..." gnus-current-startup-file)
2740 (gnus-gnus-to-newsrc-format)
2741 (gnus-message 8 "Saving %s...done" gnus-current-startup-file))
2743 ;; Save .newsrc.eld.
2744 (set-buffer (gnus-get-buffer-create " *Gnus-newsrc*"))
2745 (make-local-variable 'version-control)
2746 (setq version-control gnus-backup-startup-file)
2747 (setq buffer-file-name
2748 (concat gnus-current-startup-file ".eld"))
2749 (setq default-directory (file-name-directory buffer-file-name))
2750 (buffer-disable-undo)
2752 (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file)
2754 (if gnus-save-startup-file-via-temp-buffer
2755 (let ((coding-system-for-write gnus-ding-file-coding-system)
2756 (standard-output (current-buffer)))
2757 (gnus-gnus-to-quick-newsrc-format)
2758 (gnus-run-hooks 'gnus-save-quick-newsrc-hook)
2760 (let ((coding-system-for-write gnus-ding-file-coding-system)
2761 (version-control gnus-backup-startup-file)
2762 (startup-file (concat gnus-current-startup-file ".eld"))
2763 (working-dir (file-name-directory gnus-current-startup-file))
2766 ;; Generate the name of a non-existent file.
2767 (while (progn (setq working-file
2769 (if (and (eq system-type 'ms-dos)
2770 (not (gnus-long-file-names)))
2771 "%s#%d.tm#" ; MSDOS limits files to 8+3
2772 (if (memq system-type '(vax-vms axp-vms))
2775 working-dir (setq i (1+ i))))
2776 (file-exists-p working-file)))
2780 (gnus-with-output-to-file working-file
2781 (gnus-gnus-to-quick-newsrc-format)
2782 (gnus-run-hooks 'gnus-save-quick-newsrc-hook))
2784 ;; These bindings will mislead the current buffer
2785 ;; into thinking that it is visiting the startup
2787 (let ((buffer-backed-up nil)
2788 (buffer-file-name startup-file)
2789 (file-precious-flag t)
2790 (setmodes (file-modes startup-file)))
2791 ;; Backup the current version of the startup file.
2794 ;; Replace the existing startup file with the temp file.
2795 (rename-file working-file startup-file t)
2796 (gnus-set-file-modes startup-file setmodes)))
2798 (delete-file working-file)
2799 (file-error nil)))))
2801 (gnus-kill-buffer (current-buffer))
2803 5 "Saving %s.eld...done" gnus-current-startup-file))
2804 (gnus-dribble-delete-file)
2805 (gnus-group-set-mode-line)))))
2807 (defun gnus-gnus-to-quick-newsrc-format (&optional minimal name &rest specific-variables)
2808 "Print Gnus variables such as `gnus-newsrc-alist' in Lisp format."
2809 (princ ";; -*- emacs-lisp -*-\n")
2811 (princ (format ";; %s\n" name))
2812 (princ ";; Gnus startup file.\n"))
2816 ;; Never delete this file -- if you want to force Gnus to read the
2817 ;; .newsrc file (if you have one), touch .newsrc instead.\n")
2818 (princ "(setq gnus-newsrc-file-version ")
2819 (princ (gnus-prin1-to-string gnus-version))
2822 (let* ((print-quoted t)
2824 (print-escape-multibyte nil)
2825 (print-escape-nonascii t)
2828 (print-escape-newlines t)
2830 (if (and gnus-save-killed-list
2831 (stringp gnus-save-killed-list))
2832 (gnus-strip-killed-list)
2835 (or specific-variables
2836 (if gnus-save-killed-list gnus-variable-list
2837 ;; Remove the `gnus-killed-list' from the list of variables
2838 ;; to be saved, if required.
2839 (delq 'gnus-killed-list (copy-sequence gnus-variable-list)))))
2840 ;; Peel off the "dummy" group.
2841 (gnus-newsrc-alist (cdr gnus-newsrc-alist))
2843 ;; Insert the variables into the file.
2845 (when (and (boundp (setq variable (pop variables)))
2846 (symbol-value variable))
2848 (princ (symbol-name variable))
2850 (prin1 (symbol-value variable))
2853 (defun gnus-strip-killed-list ()
2854 "Return the killed list minus the groups that match `gnus-save-killed-list'."
2855 (let ((list gnus-killed-list)
2858 (when (string-match gnus-save-killed-list (car list))
2859 (push (car list) olist))
2863 (defun gnus-gnus-to-newsrc-format ()
2864 ;; Generate and save the .newsrc file.
2866 (set-buffer (create-file-buffer gnus-current-startup-file))
2867 (let ((newsrc (cdr gnus-newsrc-alist))
2868 (standard-output (current-buffer))
2869 info ranges range method)
2870 (setq buffer-file-name gnus-current-startup-file)
2871 (setq default-directory (file-name-directory buffer-file-name))
2872 (buffer-disable-undo)
2875 (when gnus-newsrc-options
2876 (insert gnus-newsrc-options))
2877 ;; Write subscribed and unsubscribed.
2878 (while (setq info (pop newsrc))
2879 ;; Don't write foreign groups to .newsrc.
2880 (when (or (null (setq method (gnus-info-method info)))
2881 (equal method "native")
2882 (inline (gnus-server-equal method gnus-select-method)))
2883 (insert (gnus-info-group info)
2884 (if (> (gnus-info-level info) gnus-level-subscribed)
2886 (when (setq ranges (gnus-info-read info))
2888 (if (not (listp (cdr ranges)))
2889 (if (= (car ranges) (cdr ranges))
2890 (princ (car ranges))
2891 (princ (car ranges))
2893 (princ (cdr ranges)))
2894 (while (setq range (pop ranges))
2895 (if (or (atom range) (= (car range) (cdr range)))
2896 (princ (or (and (atom range) range) (car range)))
2899 (princ (cdr range)))
2903 (make-local-variable 'version-control)
2904 (setq version-control 'never)
2905 ;; It has been reported that sometime the modtime on the .newsrc
2906 ;; file seems to be off. We really do want to overwrite it, so
2907 ;; we clear the modtime here before saving. It's a bit odd,
2909 ;; sometimes the modtime clear isn't sufficient. most brute force:
2910 ;; delete the silly thing entirely first. but this fails to provide
2911 ;; such niceties as .newsrc~ creation.
2912 (if gnus-modtime-botch
2913 (delete-file gnus-startup-file)
2914 (clear-visited-file-modtime))
2915 (gnus-run-hooks 'gnus-save-standard-newsrc-hook)
2917 (kill-buffer (current-buffer)))))
2921 ;;; Slave functions.
2924 (defvar gnus-slave-mode nil)
2926 (defun gnus-slave-mode ()
2927 "Minor mode for slave Gnusae."
2928 (add-minor-mode 'gnus-slave-mode " Slave" (make-sparse-keymap))
2929 (gnus-run-hooks 'gnus-slave-mode-hook))
2931 (defun gnus-slave-save-newsrc ()
2933 (set-buffer gnus-dribble-buffer)
2935 (mm-make-temp-file (concat gnus-current-startup-file "-slave-")))
2936 (modes (ignore-errors
2937 (file-modes (concat gnus-current-startup-file ".eld")))))
2938 (let ((coding-system-for-write gnus-ding-file-coding-system))
2939 (gnus-write-buffer slave-name))
2941 (gnus-set-file-modes slave-name modes)))))
2943 (defun gnus-master-read-slave-newsrc ()
2946 (file-name-directory gnus-current-startup-file)
2950 (file-name-nondirectory gnus-current-startup-file)
2954 (if (not slave-files)
2955 () ; There are no slave files to read.
2956 (gnus-message 7 "Reading slave newsrcs...")
2958 (set-buffer (gnus-get-buffer-create " *gnus slave*"))
2960 (sort (mapcar (lambda (file)
2961 (list (nth 5 (file-attributes file)) file))
2964 (or (< (caar f1) (caar f2))
2965 (< (nth 1 (car f1)) (nth 1 (car f2)))))))
2968 (setq file (nth 1 (car slave-files)))
2969 (nnheader-insert-file-contents file)
2970 (when (condition-case ()
2972 (eval-buffer (current-buffer))
2975 (gnus-error 3.2 "Possible error in %s" file)
2977 (unless gnus-slave ; Slaves shouldn't delete these files.
2979 (delete-file file))))
2980 (setq slave-files (cdr slave-files))))
2981 (gnus-dribble-touch)
2982 (gnus-message 7 "Reading slave newsrcs...done"))))
2986 ;;; Group description.
2989 (defun gnus-read-all-descriptions-files ()
2990 (let ((methods (cons gnus-select-method
2992 (when (gnus-archive-server-wanted-p)
2994 gnus-secondary-select-methods))))
2996 (gnus-read-descriptions-file (car methods))
2997 (setq methods (cdr methods)))
3000 (defun gnus-read-descriptions-file (&optional method)
3001 (let ((method (or method gnus-select-method))
3003 (when (stringp method)
3004 (setq method (gnus-server-to-method method)))
3005 ;; We create the hashtable whether we manage to read the desc file
3006 ;; to avoid trying to re-read after a failed read.
3007 (unless gnus-description-hashtb
3008 (setq gnus-description-hashtb
3009 (gnus-make-hashtable (length gnus-active-hashtb))))
3010 ;; Mark this method's desc file as read.
3011 (gnus-sethash (gnus-group-prefixed-name "" method) "Has read"
3012 gnus-description-hashtb)
3014 (gnus-message 5 "Reading descriptions file via %s..." (car method))
3016 ((null (gnus-get-function method 'request-list-newsgroups t))
3018 ((not (gnus-check-server method))
3019 (gnus-message 1 "Couldn't open server")
3021 ((not (gnus-request-list-newsgroups method))
3022 (gnus-message 1 "Couldn't read newsgroups descriptions")
3027 (set-buffer nntp-server-buffer)
3028 (goto-char (point-min))
3029 (when (or (search-forward "\n.\n" nil t)
3030 (goto-char (point-max)))
3032 (narrow-to-region (point-min) (point)))
3033 ;; If these are groups from a foreign select method, we insert the
3034 ;; group prefix in front of the group names.
3035 (and method (not (inline
3037 (gnus-server-get-method nil method)
3038 (gnus-server-get-method
3039 nil gnus-select-method))))
3040 (let ((prefix (gnus-group-prefixed-name "" method)))
3041 (goto-char (point-min))
3042 (while (and (not (eobp))
3043 (progn (insert prefix)
3044 (zerop (forward-line 1)))))))
3045 (goto-char (point-min))
3047 ;; If we get an error, we set group to 0, which is not a
3051 (let ((obarray gnus-description-hashtb))
3052 ;; Group is set to a symbol interned in this
3054 (read nntp-server-buffer))
3056 (skip-chars-forward " \t")
3057 ;; ... which leads to this line being effectively ignored.
3058 (when (symbolp group)
3059 (let* ((str (buffer-substring
3060 (point) (progn (end-of-line) (point))))
3061 (name (symbol-name group))
3063 (or (gnus-group-name-charset method name)
3064 (gnus-parameter-charset name)
3065 gnus-default-charset)))
3066 ;; Fixme: Don't decode in unibyte mode.
3067 (when (and str charset (featurep 'mule))
3068 (setq str (mm-decode-coding-string str charset)))
3071 (gnus-message 5 "Reading descriptions file...done")
3074 (defun gnus-group-get-description (group)
3075 "Get the description of a group by sending XGTITLE to the server."
3076 (when (gnus-request-group-description group)
3078 (set-buffer nntp-server-buffer)
3079 (goto-char (point-min))
3080 (when (looking-at "[^ \t]+[ \t]+\\(.*\\)")
3081 (match-string 1)))))
3084 (defun gnus-declare-backend (name &rest abilities)
3085 "Declare back end NAME with ABILITIES as a Gnus back end."
3086 (setq gnus-valid-select-methods
3087 (nconc gnus-valid-select-methods
3088 (list (apply 'list name abilities))))
3089 (gnus-redefine-select-method-widget))
3091 (defun gnus-set-default-directory ()
3092 "Set the default directory in the current buffer to `gnus-default-directory'.
3093 If this variable is nil, don't do anything."
3094 (setq default-directory
3095 (if (and gnus-default-directory
3096 (file-exists-p gnus-default-directory))
3097 (file-name-as-directory (expand-file-name gnus-default-directory))
3098 default-directory)))
3101 (defalias 'gnus-display-time-event-handler
3102 (if (gnus-boundp 'display-time-timer)
3103 'display-time-event-handler
3104 (lambda () "Does nothing as `display-time-timer' is not bound.
3105 Would otherwise be an alias for `display-time-event-handler'." nil))))
3108 (defun gnus-fixup-nnimap-unread-after-getting-new-news ()
3109 (let (server group info)
3112 (when (and (setq group (symbol-name sym))
3113 (gnus-group-entry group)
3114 (setq info (symbol-value sym)))
3115 (gnus-sethash group (cons (nth 2 info) (cdr (gnus-group-entry group)))
3116 gnus-newsrc-hashtb)))
3117 (if (boundp 'nnimap-mailbox-info)
3118 (symbol-value 'nnimap-mailbox-info)
3119 (make-vector 1 0)))))
3121 (defun gnus-check-reasonable-setup ()
3122 ;; Check whether nnml and nnfolder share a directory.
3124 (if (fboundp 'display-warning)
3126 (lambda (type message)
3128 (message "Warning (%s): %s" type message)
3130 (with-current-buffer (get-buffer-create "*Warnings*")
3131 (goto-char (point-max))
3134 (insert (format "Warning (%s): %s\n" type message))
3135 (setq window (display-buffer (current-buffer)))
3139 (forward-line (- 1 (window-height window)))
3141 (goto-char (point-max))))))))))
3142 method active actives match)
3143 (dolist (server gnus-server-alist)
3144 (setq method (gnus-server-to-method server)
3145 active (intern (format "%s-active-file" (car method))))
3146 (when (and (member (car method) '(nnml nnfolder))
3147 (gnus-server-opened method)
3149 (when (setq match (assoc (symbol-value active) actives))
3150 (funcall display-warn 'gnus-server
3151 (format "%s and %s share the same active file %s"
3155 (push (list (symbol-value active) method) actives)))))
3157 (provide 'gnus-start)
3159 ;;; arch-tag: f4584a22-b7b7-4853-abfc-a637329af5d2
3160 ;;; gnus-start.el ends here