1 ;;; gnus-start.el --- startup functions for Gnus
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
34 (autoload 'message-make-date "message")
35 (autoload 'gnus-agent-read-servers-validate "gnus-agent")
36 (autoload 'gnus-agent-save-local "gnus-agent")
37 (autoload 'gnus-agent-possibly-alter-active "gnus-agent")
42 (defvar gnus-agent-covered-methods)
43 (defvar gnus-agent-file-loading-local)
44 (defvar gnus-agent-file-loading-cache)
46 (defcustom gnus-startup-file (nnheader-concat gnus-home-directory ".newsrc")
48 `.newsrc-SERVER' will be used instead if that exists."
52 (defcustom gnus-backup-startup-file 'never
53 "Control use of version numbers for backups of `gnus-startup-file'.
54 This variable takes the same values as the `version-control'
58 :type '(choice (const :tag "Never" never)
59 (const :tag "If existing" nil)
60 (other :tag "Always" t)))
62 (defcustom gnus-save-startup-file-via-temp-buffer t
63 "Whether to write the startup file contents to a buffer then save
64 the buffer or write directly to the file. The buffer is faster
65 because all of the contents are written at once. The direct write
66 uses considerably less memory."
69 :type '(choice (const :tag "Write via buffer" t)
70 (const :tag "Write directly to file" nil)))
72 (defcustom gnus-init-file (nnheader-concat gnus-home-directory ".gnus")
73 "Your Gnus Emacs-Lisp startup file name.
74 If a file with the `.el' or `.elc' suffixes exists, it will be read instead."
78 (defcustom gnus-site-init-file
80 (concat (file-name-directory
81 (directory-file-name installation-directory))
82 "site-lisp/gnus-init")
84 "The site-wide Gnus Emacs-Lisp startup file name, or nil if none.
85 If a file with the `.el' or `.elc' suffixes exists, it will be read instead."
87 :type '(choice file (const nil)))
89 (defcustom gnus-default-subscribed-newsgroups nil
90 "List of newsgroups to subscribe, when a user runs Gnus the first time.
91 The value should be a list of strings.
92 If it is t, Gnus will not do anything special the first time it is
93 started; it'll just use the normal newsgroups subscription methods."
95 :type '(choice (repeat string) (const :tag "Nothing special" t)))
97 (defcustom gnus-use-dribble-file t
98 "*Non-nil means that Gnus will use a dribble file to store user updates.
99 If Emacs should crash without saving the .newsrc files, complete
100 information can be restored from the dribble file."
101 :group 'gnus-dribble-file
104 (defcustom gnus-dribble-directory nil
105 "*The directory where dribble files will be saved.
106 If this variable is nil, the directory where the .newsrc files are
108 :group 'gnus-dribble-file
109 :type '(choice directory (const nil)))
111 (defcustom gnus-check-new-newsgroups 'ask-server
112 "*Non-nil means that Gnus will run `gnus-find-new-newsgroups' at startup.
113 This normally finds new newsgroups by comparing the active groups the
114 servers have already reported with those Gnus already knows, either alive
117 When any of the following are true, `gnus-find-new-newsgroups' will instead
118 ask the servers (primary, secondary, and archive servers) to list new
119 groups since the last time it checked:
120 1. This variable is `ask-server'.
121 2. This variable is a list of select methods (see below).
122 3. `gnus-read-active-file' is nil or `some'.
123 4. A prefix argument is given to `gnus-find-new-newsgroups' interactively.
125 Thus, if this variable is `ask-server' or a list of select methods or
126 `gnus-read-active-file' is nil or `some', then the killed list is no
127 longer necessary, so you could safely set `gnus-save-killed-list' to nil.
129 This variable can be a list of select methods which Gnus will query with
130 the `ask-server' method in addition to the primary, secondary, and archive
134 (setq gnus-check-new-newsgroups
135 '((nntp \"some.server\") (nntp \"other.server\")))
137 If this variable is nil, then you have to tell Gnus explicitly to
138 check for new newsgroups with \\<gnus-group-mode-map>\\[gnus-find-new-newsgroups]."
140 :type '(choice (const :tag "no" nil)
141 (const :tag "by brute force" t)
142 (const :tag "ask servers" ask-server)
143 (repeat :menu-tag "ask additional servers"
144 :tag "ask additional servers"
146 (sexp :format "%v"))))
148 (defcustom gnus-check-bogus-newsgroups nil
149 "*Non-nil means that Gnus will check and remove bogus newsgroup at startup.
150 If this variable is nil, then you have to tell Gnus explicitly to
151 check for bogus newsgroups with \\<gnus-group-mode-map>\\[gnus-group-check-bogus-groups]."
152 :group 'gnus-start-server
155 (defcustom gnus-read-active-file 'some
156 "*Non-nil means that Gnus will read the entire active file at startup.
157 If this variable is nil, Gnus will only know about the groups in your
160 If this variable is `some', Gnus will try to only read the relevant
161 parts of the active file from the server. Not all servers support
162 this, and it might be quite slow with other servers, but this should
163 generally be faster than both the t and nil value.
165 If you set this variable to nil or `some', you probably still want to
166 be told about new newsgroups that arrive. To do that, set
167 `gnus-check-new-newsgroups' to `ask-server'. This may not work
168 properly with all servers."
169 :group 'gnus-start-server
170 :type '(choice (const nil)
174 (defconst gnus-level-subscribed 5
175 "Groups with levels less than or equal to this variable are subscribed.")
177 (defconst gnus-level-unsubscribed 7
178 "Groups with levels less than or equal to this variable are unsubscribed.
180 Groups with levels less than `gnus-level-subscribed', which
181 should be less than this variable, are subscribed. Groups with
182 levels from `gnus-level-subscribed' (exclusive) upto this
183 variable (inclusive) are unsubscribed. See also
184 `gnus-level-zombie', `gnus-level-killed' and the Info node `(gnus)Group
185 Levels' for details.")
187 (defconst gnus-level-zombie 8
188 "Groups with this level are zombie groups.")
190 (defconst gnus-level-killed 9
191 "Groups with this level are killed.")
193 (defcustom gnus-level-default-subscribed 3
194 "*New subscribed groups will be subscribed at this level."
195 :group 'gnus-group-levels
198 (defcustom gnus-level-default-unsubscribed 6
199 "*New unsubscribed groups will be unsubscribed at this level."
200 :group 'gnus-group-levels
203 (defcustom gnus-activate-level (1+ gnus-level-subscribed)
204 "*Groups higher than this level won't be activated on startup.
205 Setting this variable to something low might save lots of time when
206 you have many groups that you aren't interested in."
207 :group 'gnus-group-levels
210 (defcustom gnus-activate-foreign-newsgroups 4
211 "*If nil, Gnus will not check foreign newsgroups at startup.
212 If it is non-nil, it should be a number between one and nine. Foreign
213 newsgroups that have a level lower or equal to this number will be
214 activated on startup. For instance, if you want to active all
215 subscribed newsgroups, but not the rest, you'd set this variable to
216 `gnus-level-subscribed'.
218 If you subscribe to lots of newsgroups from different servers, startup
219 might take a while. By setting this variable to nil, you'll save time,
220 but you won't be told how many unread articles there are in the
222 :group 'gnus-group-levels
223 :type '(choice integer
224 (const :tag "none" nil)))
226 (defcustom gnus-read-newsrc-file t
227 "*Non-nil means that Gnus will read the `.newsrc' file.
228 Gnus always reads its own startup file, which is called
229 \".newsrc.eld\". The file called \".newsrc\" is in a format that can
230 be readily understood by other newsreaders. If you don't plan on
231 using other newsreaders, set this variable to nil to save some time on
237 (defcustom gnus-save-newsrc-file t
238 "*Non-nil means that Gnus will save the `.newsrc' file.
239 Gnus always saves its own startup file, which is called
240 \".newsrc.eld\". The file called \".newsrc\" is in a format that can
241 be readily understood by other newsreaders. If you don't plan on
242 using other newsreaders, set this variable to nil to save some time on
247 (defcustom gnus-save-killed-list t
248 "*If non-nil, save the list of killed groups to the startup file.
249 If you set this variable to nil, you'll save both time (when starting
250 and quitting) and space (both memory and disk), but it will also mean
251 that Gnus has no record of which groups are new and which are old, so
252 the automatic new newsgroups subscription methods become meaningless.
254 You should always set `gnus-check-new-newsgroups' to `ask-server' or
255 nil if you set this variable to nil.
257 This variable can also be a regexp. In that case, all groups that do
258 not match this regexp will be removed before saving the list."
260 :type '(radio (sexp :format "Non-nil\n"
261 :match (lambda (widget value)
262 (and value (not (stringp value))))
267 (defcustom gnus-ignored-newsgroups
269 '("^to\\." ; not "real" groups
270 "^[0-9. \t]+\\( \\|$\\)" ; all digits in name
271 "^[\"][\"#'()]" ; bogus characters
274 "*A regexp to match uninteresting newsgroups in the active file.
275 Any lines in the active file matching this regular expression are
276 removed from the newsgroup list before anything else is done to it,
277 thus making them effectively non-existent."
278 :group 'gnus-group-new
281 (defcustom gnus-subscribe-newsgroup-method 'gnus-subscribe-zombies
282 "*Function(s) called with a group name when new group is detected.
283 A few pre-made functions are supplied: `gnus-subscribe-randomly'
284 inserts new groups at the beginning of the list of groups;
285 `gnus-subscribe-alphabetically' inserts new groups in strict
286 alphabetic order; `gnus-subscribe-hierarchically' inserts new groups
287 in hierarchical newsgroup order; `gnus-subscribe-interactively' asks
288 for your decision; `gnus-subscribe-killed' kills all new groups;
289 `gnus-subscribe-zombies' will make all new groups into zombies;
290 `gnus-subscribe-topics' will enter groups into the topics that
292 :group 'gnus-group-new
293 :type '(radio (function-item gnus-subscribe-randomly)
294 (function-item gnus-subscribe-alphabetically)
295 (function-item gnus-subscribe-hierarchically)
296 (function-item gnus-subscribe-interactively)
297 (function-item gnus-subscribe-killed)
298 (function-item gnus-subscribe-zombies)
299 (function-item gnus-subscribe-topics)
303 (defcustom gnus-subscribe-newsgroup-hooks nil
304 "*Hooks run after you subscribe to a new group.
305 The hooks will be called with new group's name as argument."
307 :group 'gnus-group-new
310 (defcustom gnus-subscribe-options-newsgroup-method
311 'gnus-subscribe-alphabetically
312 "*Function(s) called to subscribe newsgroups mentioned on \"options -n\" lines.
313 If, for instance, you want to subscribe to all newsgroups in the
314 \"no\" and \"alt\" hierarchies, you'd put the following in your
317 options -n no.all alt.all
319 Gnus will then subscribe all new newsgroups in these hierarchies
320 with the subscription method in this variable."
321 :group 'gnus-group-new
322 :type '(radio (function-item gnus-subscribe-randomly)
323 (function-item gnus-subscribe-alphabetically)
324 (function-item gnus-subscribe-hierarchically)
325 (function-item gnus-subscribe-interactively)
326 (function-item gnus-subscribe-killed)
327 (function-item gnus-subscribe-zombies)
328 (function-item gnus-subscribe-topics)
332 (defcustom gnus-subscribe-hierarchical-interactive nil
333 "*If non-nil, Gnus will offer to subscribe hierarchically.
334 When a new hierarchy appears, Gnus will ask the user:
336 'alt.binaries': Do you want to subscribe to this hierarchy? ([d]ys):
338 If the user pressed `d', Gnus will descend the hierarchy, `y' will
339 subscribe to all newsgroups in the hierarchy and `s' will skip this
340 hierarchy in its entirety."
341 :group 'gnus-group-new
344 (defcustom gnus-auto-subscribed-groups
345 "^nnml\\|^nnfolder\\|^nnmbox\\|^nnmh\\|^nnbabyl\\|^nnmaildir"
346 "*All new groups that match this regexp will be subscribed automatically.
347 Note that this variable only deals with new groups. It has no effect
348 whatsoever on old groups.
350 New groups that match this regexp will not be handled by
351 `gnus-subscribe-newsgroup-method'. Instead, they will
352 be subscribed using `gnus-subscribe-options-newsgroup-method'."
353 :group 'gnus-group-new
356 (defcustom gnus-options-subscribe nil
357 "*All new groups matching this regexp will be subscribed unconditionally.
358 Note that this variable deals only with new newsgroups. This variable
359 does not affect old newsgroups.
361 New groups that match this regexp will not be handled by
362 `gnus-subscribe-newsgroup-method'. Instead, they will
363 be subscribed using `gnus-subscribe-options-newsgroup-method'."
364 :group 'gnus-group-new
365 :type '(choice regexp
366 (const :tag "none" nil)))
368 (defcustom gnus-options-not-subscribe nil
369 "*All new groups matching this regexp will be ignored.
370 Note that this variable deals only with new newsgroups. This variable
371 does not affect old (already subscribed) newsgroups."
372 :group 'gnus-group-new
373 :type '(choice regexp
374 (const :tag "none" nil)))
376 (defcustom gnus-modtime-botch nil
377 "*Non-nil means .newsrc should be deleted prior to save.
378 Its use is due to the bogus appearance that .newsrc was modified on
383 (defcustom gnus-use-backend-marks nil
384 "If non-nil, Gnus will store and retrieve marks from the backends.
385 This means that marks will be stored both in .newsrc.eld and in
386 the backend, and will slow operation down somewhat."
390 (defcustom gnus-check-bogus-groups-hook nil
391 "A hook run after removing bogus groups."
392 :group 'gnus-start-server
395 (defcustom gnus-startup-hook nil
396 "A hook called at startup.
397 This hook is called after Gnus is connected to the NNTP server."
401 (defcustom gnus-before-startup-hook nil
402 "A hook called before startup.
403 This hook is called as the first thing when Gnus is started."
407 (defcustom gnus-started-hook nil
408 "A hook called as the last thing after startup."
412 (defcustom gnus-setup-news-hook nil
413 "A hook after reading the .newsrc file, but before generating the buffer."
417 (defcustom gnus-get-top-new-news-hook nil
418 "A hook run just before Gnus checks for new news globally."
420 :group 'gnus-group-new
423 (defcustom gnus-get-new-news-hook nil
424 "A hook run just before Gnus checks for new news."
425 :group 'gnus-group-new
428 (defcustom gnus-after-getting-new-news-hook
429 '(gnus-display-time-event-handler)
430 "*A hook run after Gnus checks for new news when Gnus is already running."
432 :group 'gnus-group-new
435 (defcustom gnus-read-newsrc-el-hook nil
436 "A hook called after reading the newsrc.eld? file."
440 (defcustom gnus-save-newsrc-hook nil
441 "A hook called before saving any of the newsrc files."
445 (defcustom gnus-save-quick-newsrc-hook nil
446 "A hook called just before saving the quick newsrc file.
447 Can be used to turn version control on or off."
451 (defcustom gnus-save-standard-newsrc-hook nil
452 "A hook called just before saving the standard newsrc file.
453 Can be used to turn version control on or off."
457 (defcustom gnus-group-mode-hook nil
458 "Hook for Gnus group mode."
459 :group 'gnus-group-various
460 :options '(gnus-topic-mode)
463 (defcustom gnus-always-read-dribble-file nil
464 "Unconditionally read the dribble file."
468 ;;; Internal variables
470 ;; Fixme: deal with old emacs-mule when mm-universal-coding-system is
472 (defvar gnus-ding-file-coding-system mm-universal-coding-system
473 "Coding system for ding file.")
475 (defvar gnus-newsrc-file-version nil)
476 (defvar gnus-override-subscribe-method nil)
477 (defvar gnus-dribble-buffer nil)
478 (defvar gnus-newsrc-options nil
479 "Options line in the .newsrc file.")
481 (defvar gnus-newsrc-options-n nil
482 "List of regexps representing groups to be subscribed/ignored unconditionally.")
484 (defvar gnus-newsrc-last-checked-date nil
485 "Date Gnus last asked server for new newsgroups.")
487 (defvar gnus-current-startup-file nil
488 "Startup file for the current host.")
490 ;; Byte-compiler warning.
491 (defvar gnus-group-line-format)
493 ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
494 (defvar gnus-init-inhibit nil)
495 (defun gnus-read-init-file (&optional inhibit-next)
496 ;; Don't load .gnus if the -q option was used.
498 (if gnus-init-inhibit
499 (setq gnus-init-inhibit nil)
500 (setq gnus-init-inhibit inhibit-next)
501 (dolist (file (list gnus-site-init-file gnus-init-file))
503 (locate-library file))
504 (if (or debug-on-error debug-on-quit)
509 (error "Error in %s: %s" file (cadr var))))))))))
511 ;; For subscribing new newsgroup
513 (defun gnus-subscribe-hierarchical-interactive (groups)
514 (let ((groups (sort groups 'string<))
515 prefixes prefix start ans group starts real-group)
517 (setq prefixes (list "^"))
518 (while (and groups prefixes)
519 (while (not (string-match (car prefixes)
520 (gnus-group-real-name (car groups))))
521 (setq prefixes (cdr prefixes)))
522 (setq prefix (car prefixes))
523 (setq start (1- (length prefix)))
524 (if (and (string-match "[^\\.]\\." (gnus-group-real-name (car groups))
528 (concat "^" (substring
529 (gnus-group-real-name (car groups))
531 (string-match prefix (gnus-group-real-name (cadr groups))))
533 (push prefix prefixes)
534 (message "Descend hierarchy %s? ([y]nsq): "
535 (substring prefix 1 (1- (length prefix))))
536 (while (not (memq (setq ans (read-char-exclusive))
537 '(?y ?\n ?\r ?n ?s ?q)))
539 (message "Descend hierarchy %s? ([y]nsq): "
540 (substring prefix 1 (1- (length prefix)))))
543 (setq group (car groups)
544 real-group (gnus-group-real-name group))
545 (string-match prefix real-group))
546 (push group gnus-killed-list)
547 (gnus-sethash group group gnus-killed-hashtb)
548 (setq groups (cdr groups)))
549 (setq starts (cdr starts)))
552 (setq group (car groups)
553 real-group (gnus-group-real-name group))
554 (string-match prefix real-group))
555 (gnus-sethash group group gnus-killed-hashtb)
556 (gnus-subscribe-alphabetically (car groups))
557 (setq groups (cdr groups)))
558 (setq starts (cdr starts)))
561 (setq group (car groups))
562 (push group gnus-killed-list)
563 (gnus-sethash group group gnus-killed-hashtb)
564 (setq groups (cdr groups))))
566 (message "Subscribe %s? ([n]yq)" (car groups))
567 (while (not (memq (setq ans (read-char-exclusive))
568 '(?y ?\n ?\r ?q ?n)))
570 (message "Subscribe %s? ([n]yq)" (car groups)))
571 (setq group (car groups))
573 (gnus-subscribe-alphabetically (car groups))
574 (gnus-sethash group group gnus-killed-hashtb))
577 (setq group (car groups))
578 (push group gnus-killed-list)
579 (gnus-sethash group group gnus-killed-hashtb)
580 (setq groups (cdr groups))))
582 (push group gnus-killed-list)
583 (gnus-sethash group group gnus-killed-hashtb)))
584 (setq groups (cdr groups)))))))
586 (defun gnus-subscribe-randomly (newsgroup)
587 "Subscribe new NEWSGROUP by making it the first newsgroup."
588 (gnus-subscribe-newsgroup newsgroup))
590 (defun gnus-subscribe-alphabetically (newgroup)
591 "Subscribe new NEWGROUP and insert it in alphabetical order."
592 (let ((groups (cdr gnus-newsrc-alist))
594 (while (and (not before) groups)
595 (if (string< newgroup (caar groups))
596 (setq before (caar groups))
597 (setq groups (cdr groups))))
598 (gnus-subscribe-newsgroup newgroup before)))
600 (defun gnus-subscribe-hierarchically (newgroup)
601 "Subscribe new NEWGROUP and insert it in hierarchical newsgroup order."
602 ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
603 (with-current-buffer (nnheader-find-file-noselect gnus-current-startup-file)
605 (let ((groupkey newgroup) before)
606 (while (and (not before) groupkey)
607 (goto-char (point-min))
609 (concat "^\\(" (regexp-quote groupkey) ".*\\)[!:]")))
610 (while (and (re-search-forward groupkey-re nil t)
612 (setq before (match-string 1))
613 (string< before newgroup)))))
614 ;; Remove tail of newsgroup name (eg. a.b.c -> a.b)
616 (when (string-match "^\\(.*\\)\\.[^.]+$" groupkey)
617 (substring groupkey (match-beginning 1) (match-end 1)))))
618 (gnus-subscribe-newsgroup newgroup before))
619 (kill-buffer (current-buffer)))))
621 (defun gnus-subscribe-interactively (group)
622 "Subscribe the new GROUP interactively.
623 It is inserted in hierarchical newsgroup order if subscribed. If not,
625 (if (gnus-y-or-n-p (format "Subscribe new newsgroup %s? " group))
626 (gnus-subscribe-hierarchically group)
627 (push group gnus-killed-list)))
629 (defun gnus-subscribe-zombies (group)
630 "Make the new GROUP into a zombie group."
631 (push group gnus-zombie-list))
633 (defun gnus-subscribe-killed (group)
634 "Make the new GROUP a killed group."
635 (push group gnus-killed-list))
637 (defun gnus-subscribe-newsgroup (newsgroup &optional next)
638 "Subscribe new NEWSGROUP.
639 If NEXT is non-nil, it is inserted before NEXT. Otherwise it is made
640 the first newsgroup."
642 (goto-char (point-min))
643 ;; We subscribe the group by changing its level to `subscribed'.
644 (gnus-group-change-level
645 newsgroup gnus-level-default-subscribed
646 gnus-level-killed (gnus-group-entry (or next "dummy.group")))
647 (gnus-message 5 "Subscribe newsgroup: %s" newsgroup)
648 (run-hook-with-args 'gnus-subscribe-newsgroup-hooks newsgroup)
651 (defun gnus-read-active-file-p ()
652 "Say whether the active file has been read from `gnus-select-method'."
653 (memq gnus-select-method gnus-have-read-active-file))
655 ;;; General various misc type functions.
657 ;; Silence byte-compiler.
658 (defvar gnus-current-headers)
659 (defvar gnus-thread-indent-array)
660 (defvar gnus-newsgroup-name)
661 (defvar gnus-newsgroup-headers)
662 (defvar gnus-group-list-mode)
663 (defvar gnus-group-mark-positions)
664 (defvar gnus-newsgroup-data)
665 (defvar gnus-newsgroup-unreads)
666 (defvar nnoo-state-alist)
667 (defvar gnus-current-select-method)
668 (defvar mail-sources)
669 (defvar nnmail-scan-directory-mail-source-once)
670 (defvar nnmail-split-history)
671 (defvar nnmail-spool-file)
673 (defun gnus-close-all-servers ()
676 (dolist (server gnus-opened-servers)
677 (gnus-close-server (car server))))
679 (defun gnus-clear-system ()
680 "Clear all variables and buffers."
681 ;; Clear Gnus variables.
682 (let ((variables (remove 'gnus-format-specs gnus-variable-list)))
684 (set (car variables) nil)
685 (setq variables (cdr variables))))
686 ;; Clear other internal variables.
687 (setq gnus-list-of-killed-groups nil
688 gnus-have-read-active-file nil
689 gnus-agent-covered-methods nil
690 gnus-agent-file-loading-local nil
691 gnus-agent-file-loading-cache nil
692 gnus-server-method-cache nil
693 gnus-newsrc-alist nil
694 gnus-newsrc-hashtb nil
697 gnus-killed-hashtb nil
698 gnus-active-hashtb nil
699 gnus-moderated-hashtb nil
700 gnus-description-hashtb nil
701 gnus-current-headers nil
702 gnus-thread-indent-array nil
703 gnus-newsgroup-headers nil
704 gnus-newsgroup-name nil
705 gnus-server-alist nil
706 gnus-group-list-mode nil
707 gnus-opened-servers nil
708 gnus-group-mark-positions nil
709 gnus-newsgroup-data nil
710 gnus-newsgroup-unreads nil
712 gnus-current-select-method nil
713 nnmail-split-history nil
714 gnus-extended-servers nil
715 gnus-ephemeral-servers nil)
716 (gnus-shutdown 'gnus)
717 ;; Kill the startup file.
718 (and gnus-current-startup-file
719 (get-file-buffer gnus-current-startup-file)
720 (kill-buffer (get-file-buffer gnus-current-startup-file)))
721 ;; Clear the dribble buffer.
723 ;; Kill global KILL file buffer.
724 (when (get-file-buffer (gnus-newsgroup-kill-file nil))
725 (kill-buffer (get-file-buffer (gnus-newsgroup-kill-file nil))))
726 (gnus-kill-buffer nntp-server-buffer)
727 ;; Kill Gnus buffers.
728 (dolist (buffer (gnus-buffers))
729 (gnus-kill-buffer buffer))
730 ;; Remove Gnus frames.
731 (gnus-kill-gnus-frames))
733 (defun gnus-no-server-1 (&optional arg slave)
735 If ARG is a positive number, Gnus will use that as the startup
736 level. If ARG is nil, Gnus will be started at level 2
737 \(`gnus-level-default-subscribed' minus one). If ARG is non-nil
738 and not a positive number, Gnus will prompt the user for the name
739 of an NNTP server to use. As opposed to \\[gnus], this command
740 will not connect to the local server."
742 (let ((val (or arg (1- gnus-level-default-subscribed))))
744 (make-local-variable 'gnus-group-use-permanent-levels)
745 (setq gnus-group-use-permanent-levels val)))
747 (defun gnus-1 (&optional arg dont-connect slave)
749 If ARG is non-nil and a positive number, Gnus will use that as the
750 startup level. If ARG is non-nil and not a positive number, Gnus will
751 prompt the user for the name of an NNTP server to use."
756 (switch-to-buffer gnus-group-buffer)
757 (gnus-group-get-new-news
760 (max (car gnus-group-list-mode) arg))))
764 (gnus-run-hooks 'gnus-before-startup-hook)
765 (nnheader-init-server-buffer)
766 (setq gnus-slave slave)
767 (gnus-read-init-file)
769 ;; Add "native" to gnus-predefined-server-alist just to have a
770 ;; name for the native select method.
771 (when gnus-select-method
772 (push (cons "native" gnus-select-method)
773 gnus-predefined-server-alist))
778 (let ((level (and (numberp arg) (> arg 0) arg))
784 (gnus-start-news-server (and arg (not level))))))
785 (if (and (not dont-connect)
788 (gnus-run-hooks 'gnus-startup-hook)
789 ;; NNTP server is successfully open.
791 ;; Find the current startup file name.
792 (setq gnus-current-startup-file
793 (gnus-make-newsrc-file gnus-startup-file))
795 ;; Read the dribble file.
796 (when (or gnus-slave gnus-use-dribble-file)
797 (gnus-dribble-read-file))
799 ;; Do the actual startup.
801 (gnus-request-create-group "queue" '(nndraft "")))
802 (gnus-request-create-group "drafts" '(nndraft ""))
803 (gnus-setup-news nil level dont-connect)
804 (gnus-run-hooks 'gnus-setup-news-hook)
805 (gnus-start-draft-setup)
806 ;; Generate the group buffer.
807 (gnus-group-list-groups level)
808 (gnus-group-first-unread-group)
809 (gnus-configure-windows 'group)
810 (gnus-group-set-mode-line)
811 (gnus-run-hooks 'gnus-started-hook))))))
813 (defun gnus-start-draft-setup ()
814 "Make sure the draft group exists."
816 (gnus-request-create-group "drafts" '(nndraft ""))
817 (unless (gnus-group-entry "nndraft:drafts")
818 (let ((gnus-level-default-subscribed 1))
819 (gnus-subscribe-group "nndraft:drafts" nil '(nndraft ""))))
820 (unless (equal (gnus-group-get-parameter "nndraft:drafts" 'gnus-dummy t)
821 '((gnus-draft-mode)))
822 (gnus-message 3 "Setting up drafts group")
823 (gnus-group-set-parameter
824 "nndraft:drafts" 'gnus-dummy '((gnus-draft-mode)))))
831 (defvar gnus-dribble-ignore nil)
832 (defvar gnus-dribble-eval-file nil)
834 (defun gnus-dribble-file-name ()
835 "Return the dribble file for the current .newsrc."
837 (if gnus-dribble-directory
838 (concat (file-name-as-directory gnus-dribble-directory)
839 (file-name-nondirectory gnus-current-startup-file))
840 gnus-current-startup-file)
843 (defun gnus-dribble-enter (string)
844 "Enter STRING into the dribble buffer."
845 (when (and (not gnus-dribble-ignore)
847 (buffer-name gnus-dribble-buffer))
848 (let ((obuf (current-buffer)))
849 (set-buffer gnus-dribble-buffer)
850 (goto-char (point-max))
852 ;; This has been commented by Josh Huber <huber@alum.wpi.edu>
853 ;; It causes problems with both XEmacs and Emacs 21, and doesn't
854 ;; seem to be of much value. (FIXME: remove this after we make sure
856 ;; (set-window-point (get-buffer-window (current-buffer)) (point-max))
857 (bury-buffer gnus-dribble-buffer)
858 (with-current-buffer gnus-group-buffer
859 (gnus-group-set-mode-line))
862 (defun gnus-dribble-touch ()
863 "Touch the dribble buffer."
864 (gnus-dribble-enter ""))
866 (defun gnus-dribble-read-file ()
867 "Read the dribble file from disk."
868 (let ((dribble-file (gnus-dribble-file-name)))
869 (unless (file-exists-p (file-name-directory dribble-file))
870 (make-directory (file-name-directory dribble-file) t))
871 (with-current-buffer (setq gnus-dribble-buffer
872 (gnus-get-buffer-create
873 (file-name-nondirectory dribble-file)))
874 (set (make-local-variable 'file-precious-flag) t)
876 (setq buffer-file-name dribble-file)
878 (buffer-disable-undo)
879 (bury-buffer (current-buffer))
880 (set-buffer-modified-p nil)
881 (let ((auto (make-auto-save-file-name))
882 (gnus-dribble-ignore t)
885 (when (or (file-exists-p auto) (file-exists-p dribble-file))
886 ;; Load whichever file is newest -- the auto save file
887 ;; or the "real" file.
888 (if (file-newer-than-file-p auto dribble-file)
889 (nnheader-insert-file-contents auto)
890 (nnheader-insert-file-contents dribble-file))
891 (unless (zerop (buffer-size))
892 (set-buffer-modified-p t))
893 ;; Set the file modes to reflect the .newsrc file modes.
895 (when (and (file-exists-p gnus-current-startup-file)
896 (file-exists-p dribble-file)
897 (setq modes (file-modes gnus-current-startup-file)))
898 (gnus-set-file-modes dribble-file modes))
899 (goto-char (point-min))
900 (when (search-forward "Gnus was exited on purpose" nil t)
902 ;; Possibly eval the file later.
903 (when (or gnus-always-read-dribble-file
906 "Gnus exited on purpose without saving; read auto-save file anyway? "
907 "Gnus auto-save file exists. Do you want to read it? ")))
908 (setq gnus-dribble-eval-file t)))))))
910 (defun gnus-dribble-eval-file ()
911 (when gnus-dribble-eval-file
912 (setq gnus-dribble-eval-file nil)
914 (let ((gnus-dribble-ignore t))
915 (set-buffer gnus-dribble-buffer)
916 (eval-buffer (current-buffer))))))
918 (defun gnus-dribble-delete-file ()
919 (when (file-exists-p (gnus-dribble-file-name))
920 (delete-file (gnus-dribble-file-name)))
921 (when gnus-dribble-buffer
922 (with-current-buffer gnus-dribble-buffer
923 (let ((auto (make-auto-save-file-name)))
924 (when (file-exists-p auto)
927 (set-buffer-modified-p nil)))))
929 (defun gnus-dribble-save ()
930 (when (and gnus-dribble-buffer
931 (buffer-name gnus-dribble-buffer))
932 (with-current-buffer gnus-dribble-buffer
935 (defun gnus-dribble-clear ()
936 (when (gnus-buffer-exists-p gnus-dribble-buffer)
937 (with-current-buffer gnus-dribble-buffer
939 (set-buffer-modified-p nil)
940 (setq buffer-saved-size (buffer-size)))))
944 ;;; Active & Newsrc File Handling
947 (defun gnus-setup-news (&optional rawfile level dont-connect)
948 "Setup news information.
949 If RAWFILE is non-nil, the .newsrc file will also be read.
950 If LEVEL is non-nil, the news will be set up at level LEVEL."
952 (let ((init (not (and gnus-newsrc-alist gnus-active-hashtb (not rawfile))))
953 ;; Binding this variable will inhibit multiple fetchings
954 ;; of the same mail source.
955 (nnmail-fetched-sources (list t)))
958 ;; Clear some variables to re-initialize news information.
959 (setq gnus-newsrc-alist nil
960 gnus-active-hashtb nil)
961 ;; Read the newsrc file and create `gnus-newsrc-hashtb'.
962 (gnus-read-newsrc-file rawfile))
964 ;; Make sure the archive server is available to all and sundry.
965 (let ((method (or (and (stringp gnus-message-archive-method)
966 (gnus-server-to-method
967 gnus-message-archive-method))
968 gnus-message-archive-method)))
969 ;; Check whether the archive method is writable.
970 (unless (or (not method)
972 (memq 'respool (assoc (format "%s" (car method))
973 gnus-valid-select-methods)))
974 (setq method "archive")) ;; The default.
975 (when (stringp method)
976 (setq method `(nnfolder
979 ,(nnheader-concat message-directory method))
980 (nnfolder-active-file
981 ,(nnheader-concat message-directory
982 (concat method "/active")))
983 (nnfolder-get-new-mail nil)
984 (nnfolder-inhibit-expiry t))))
985 (if (assoc "archive" gnus-server-alist)
986 (when gnus-update-message-archive-method
988 (setcdr (assoc "archive" gnus-server-alist) method)
989 (setq gnus-server-alist (delq (assoc "archive" gnus-server-alist)
990 gnus-server-alist))))
992 (push (cons "archive" method) gnus-server-alist))))
994 ;; If we don't read the complete active file, we fill in the
996 (when (or (null gnus-read-active-file)
997 (eq gnus-read-active-file 'some))
998 (gnus-update-active-hashtb-from-killed))
1000 ;; Validate agent covered methods now that gnus-server-alist has
1001 ;; been initialized.
1002 ;; NOTE: This is here for one purpose only. By validating the
1003 ;; agentized server's, it converts the old 5.10.3, and earlier,
1004 ;; format to the current format. That enables the agent code
1005 ;; within gnus-read-active-file to function correctly.
1007 (gnus-agent-read-servers-validate))
1009 ;; Read the active file and create `gnus-active-hashtb'.
1010 ;; If `gnus-read-active-file' is nil, then we just create an empty
1011 ;; hash table. The partial filling out of the hash table will be
1012 ;; done in `gnus-get-unread-articles'.
1013 (and gnus-read-active-file
1015 (gnus-read-active-file nil dont-connect))
1017 (unless gnus-active-hashtb
1018 (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
1020 ;; Initialize the cache.
1021 (when gnus-use-cache
1024 ;; Possibly eval the dribble file.
1026 (or gnus-use-dribble-file gnus-slave)
1027 (gnus-dribble-eval-file))
1029 ;; Slave Gnusii should then clear the dribble buffer.
1030 (when (and init gnus-slave)
1031 (gnus-dribble-clear))
1033 (gnus-update-format-specifications)
1035 ;; See whether we need to read the description file.
1036 (when (and (boundp 'gnus-group-line-format)
1037 (stringp gnus-group-line-format)
1038 (let ((case-fold-search nil))
1039 (string-match "%[-,0-9]*D" gnus-group-line-format))
1040 (not gnus-description-hashtb)
1042 gnus-read-active-file)
1043 (gnus-read-all-descriptions-files))
1045 ;; Find new newsgroups and treat them.
1046 (when (and init gnus-check-new-newsgroups (not level)
1047 (gnus-check-server gnus-select-method)
1050 (gnus-find-new-newsgroups))
1052 ;; Check and remove bogus newsgroups.
1053 (when (and init gnus-check-bogus-newsgroups
1054 gnus-read-active-file (not level)
1055 (gnus-server-opened gnus-select-method))
1056 (gnus-check-bogus-newsgroups))
1058 ;; Read any slave files.
1059 (gnus-master-read-slave-newsrc)
1061 ;; Find the number of unread articles in each non-dead group.
1062 (let ((gnus-read-active-file (and (not level) gnus-read-active-file)))
1063 (gnus-get-unread-articles level))))
1065 (defun gnus-call-subscribe-functions (method group)
1066 "Call METHOD to subscribe GROUP.
1067 If no function returns `non-nil', call `gnus-subscribe-zombies'."
1070 (funcall method group))
1073 (dolist (func method)
1074 (if (funcall func group)
1078 (gnus-subscribe-zombies group)))
1080 (defun gnus-find-new-newsgroups (&optional arg)
1081 "Search for new newsgroups and add them.
1082 Each new newsgroup will be treated with `gnus-subscribe-newsgroup-method'.
1083 The `-n' option line from .newsrc is respected.
1085 With 1 C-u, use the `ask-server' method to query the server for new
1087 With 2 C-u's, use most complete method possible to query the server
1088 for new groups, and subscribe the new groups as zombies."
1090 (let* ((gnus-subscribe-newsgroup-method
1091 gnus-subscribe-newsgroup-method)
1093 ((or (and (= (or arg 1) 4)
1094 (not (listp gnus-check-new-newsgroups)))
1095 (null gnus-read-active-file)
1096 (eq gnus-read-active-file 'some))
1099 (setq gnus-subscribe-newsgroup-method
1100 'gnus-subscribe-zombies)
1102 (t gnus-check-new-newsgroups))))
1103 (if (or (consp check)
1104 (eq check 'ask-server))
1105 ;; Ask the server for new groups.
1106 (gnus-ask-server-for-new-groups)
1107 ;; Go through the active hashtb and look for new groups.
1109 group new-newsgroups)
1110 (gnus-message 5 "Looking for new newsgroups...")
1111 (unless gnus-have-read-active-file
1112 (gnus-read-active-file))
1113 (setq gnus-newsrc-last-checked-date (message-make-date))