1 ;;; gnus-start.el --- startup functions for Gnus
3 ;; Copyright (C) 1996-2015 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 3 of the License, or
13 ;; (at your option) any later version.
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. 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-use-dribble-file t
90 "*Non-nil means that Gnus will use a dribble file to store user updates.
91 If Emacs should crash without saving the .newsrc files, complete
92 information can be restored from the dribble file."
93 :group
'gnus-dribble-file
96 (defcustom gnus-dribble-directory nil
97 "*The directory where dribble files will be saved.
98 If this variable is nil, the directory where the .newsrc files are
100 :group
'gnus-dribble-file
101 :type
'(choice directory
(const nil
)))
103 (defcustom gnus-check-new-newsgroups
'ask-server
104 "*Non-nil means that Gnus will run `gnus-find-new-newsgroups' at startup.
105 This normally finds new newsgroups by comparing the active groups the
106 servers have already reported with those Gnus already knows, either alive
109 When any of the following are true, `gnus-find-new-newsgroups' will instead
110 ask the servers (primary, secondary, and archive servers) to list new
111 groups since the last time it checked:
112 1. This variable is `ask-server'.
113 2. This variable is a list of select methods (see below).
114 3. Option `gnus-read-active-file' is nil or `some'.
115 4. A prefix argument is given to `gnus-find-new-newsgroups' interactively.
117 Thus, if this variable is `ask-server' or a list of select methods or
118 `gnus-read-active-file' is nil or `some', then the killed list is no
119 longer necessary, so you could safely set `gnus-save-killed-list' to nil.
121 This variable can be a list of select methods which Gnus will query with
122 the `ask-server' method in addition to the primary, secondary, and archive
127 (setq gnus-check-new-newsgroups
128 \\='((nntp \"some.server\") (nntp \"other.server\")))
130 If this variable is nil, then you have to tell Gnus explicitly to
131 check for new newsgroups with \\<gnus-group-mode-map>\\[gnus-find-new-newsgroups]."
133 :type
'(choice (const :tag
"no" nil
)
134 (const :tag
"by brute force" t
)
135 (const :tag
"ask servers" ask-server
)
136 (repeat :menu-tag
"ask additional servers"
137 :tag
"ask additional servers"
139 (sexp :format
"%v"))))
141 (defcustom gnus-check-bogus-newsgroups nil
142 "*Non-nil means that Gnus will check and remove bogus newsgroup at startup.
143 If this variable is nil, then you have to tell Gnus explicitly to
144 check for bogus newsgroups with \\<gnus-group-mode-map>\\[gnus-group-check-bogus-groups]."
145 :group
'gnus-start-server
148 (defcustom gnus-read-active-file
'some
149 "*Non-nil means that Gnus will read the entire active file at startup.
150 If this variable is nil, Gnus will only know about the groups in your
153 If this variable is `some', Gnus will try to only read the relevant
154 parts of the active file from the server. Not all servers support
155 this, and it might be quite slow with other servers, but this should
156 generally be faster than both the t and nil value.
158 If you set this variable to nil or `some', you probably still want to
159 be told about new newsgroups that arrive. To do that, set
160 `gnus-check-new-newsgroups' to `ask-server'. This may not work
161 properly with all servers."
162 :group
'gnus-start-server
163 :type
'(choice (const nil
)
167 (defconst gnus-level-subscribed
5
168 "Groups with levels less than or equal to this variable are subscribed.")
170 (defconst gnus-level-unsubscribed
7
171 "Groups with levels less than or equal to this variable are unsubscribed.
173 Groups with levels less than `gnus-level-subscribed', which
174 should be less than this variable, are subscribed. Groups with
175 levels from `gnus-level-subscribed' (exclusive) upto this
176 variable (inclusive) are unsubscribed. See also
177 `gnus-level-zombie', `gnus-level-killed' and the Info node `(gnus)Group
178 Levels' for details.")
180 (defconst gnus-level-zombie
8
181 "Groups with this level are zombie groups.")
183 (defconst gnus-level-killed
9
184 "Groups with this level are killed.")
186 (defcustom gnus-level-default-subscribed
3
187 "*New subscribed groups will be subscribed at this level."
188 :group
'gnus-group-levels
191 (defcustom gnus-level-default-unsubscribed
6
192 "*New unsubscribed groups will be unsubscribed at this level."
193 :group
'gnus-group-levels
196 (defcustom gnus-activate-level
(1+ gnus-level-subscribed
)
197 "*Groups higher than this level won't be activated on startup.
198 Setting this variable to something low might save lots of time when
199 you have many groups that you aren't interested in."
200 :group
'gnus-group-levels
203 (defcustom gnus-activate-foreign-newsgroups
4
204 "*If nil, Gnus will not check foreign newsgroups at startup.
205 If it is non-nil, it should be a number between one and nine. Foreign
206 newsgroups that have a level lower or equal to this number will be
207 activated on startup. For instance, if you want to active all
208 subscribed newsgroups, but not the rest, you'd set this variable to
209 `gnus-level-subscribed'.
211 If you subscribe to lots of newsgroups from different servers, startup
212 might take a while. By setting this variable to nil, you'll save time,
213 but you won't be told how many unread articles there are in the
215 :group
'gnus-group-levels
216 :type
'(choice integer
217 (const :tag
"none" nil
)))
219 (defcustom gnus-read-newsrc-file t
220 "*Non-nil means that Gnus will read the `.newsrc' file.
221 Gnus always reads its own startup file, which is called
222 \".newsrc.eld\". The file called \".newsrc\" is in a format that can
223 be readily understood by other newsreaders. If you don't plan on
224 using other newsreaders, set this variable to nil to save some time on
230 (defcustom gnus-save-newsrc-file t
231 "*Non-nil means that Gnus will save the `.newsrc' file.
232 Gnus always saves its own startup file, which is called
233 \".newsrc.eld\". The file called \".newsrc\" is in a format that can
234 be readily understood by other newsreaders. If you don't plan on
235 using other newsreaders, set this variable to nil to save some time on
240 (defcustom gnus-save-killed-list t
241 "*If non-nil, save the list of killed groups to the startup file.
242 If you set this variable to nil, you'll save both time (when starting
243 and quitting) and space (both memory and disk), but it will also mean
244 that Gnus has no record of which groups are new and which are old, so
245 the automatic new newsgroups subscription methods become meaningless.
247 You should always set `gnus-check-new-newsgroups' to `ask-server' or
248 nil if you set this variable to nil.
250 This variable can also be a regexp. In that case, all groups that do
251 not match this regexp will be removed before saving the list."
253 :type
'(radio (sexp :format
"Non-nil\n"
254 :match
(lambda (widget value
)
255 (and value
(not (stringp value
))))
260 (defcustom gnus-ignored-newsgroups
262 '("^to\\." ; not "real" groups
263 "^[0-9. \t]+\\( \\|$\\)" ; all digits in name
264 "^[\"][\"#'()]" ; bogus characters
267 "*A regexp to match uninteresting newsgroups in the active file.
268 Any lines in the active file matching this regular expression are
269 removed from the newsgroup list before anything else is done to it,
270 thus making them effectively non-existent."
271 :group
'gnus-group-new
274 (defcustom gnus-subscribe-newsgroup-method
'gnus-subscribe-zombies
275 "*Function(s) called with a group name when new group is detected.
276 A few pre-made functions are supplied: `gnus-subscribe-randomly'
277 inserts new groups at the beginning of the list of groups;
278 `gnus-subscribe-alphabetically' inserts new groups in strict
279 alphabetic order; `gnus-subscribe-hierarchically' inserts new groups
280 in hierarchical newsgroup order; `gnus-subscribe-interactively' asks
281 for your decision; `gnus-subscribe-killed' kills all new groups;
282 `gnus-subscribe-zombies' will make all new groups into zombies;
283 `gnus-subscribe-topics' will enter groups into the topics that
285 :group
'gnus-group-new
286 :type
'(radio (function-item gnus-subscribe-randomly
)
287 (function-item gnus-subscribe-alphabetically
)
288 (function-item gnus-subscribe-hierarchically
)
289 (function-item gnus-subscribe-interactively
)
290 (function-item gnus-subscribe-killed
)
291 (function-item gnus-subscribe-zombies
)
292 (function-item gnus-subscribe-topics
)
296 (define-obsolete-variable-alias 'gnus-subscribe-newsgroup-hooks
297 'gnus-subscribe-newsgroup-functions
"24.3")
298 (defcustom gnus-subscribe-newsgroup-functions nil
299 "*Hooks run after you subscribe to a new group.
300 The hooks will be called with new group's name as argument."
302 :group
'gnus-group-new
305 (defcustom gnus-subscribe-options-newsgroup-method
306 'gnus-subscribe-alphabetically
307 "*Function(s) called to subscribe newsgroups mentioned on \"options -n\" lines.
308 If, for instance, you want to subscribe to all newsgroups in the
309 \"no\" and \"alt\" hierarchies, you'd put the following in your
312 options -n no.all alt.all
314 Gnus will then subscribe all new newsgroups in these hierarchies
315 with the subscription method in this variable."
316 :group
'gnus-group-new
317 :type
'(radio (function-item gnus-subscribe-randomly
)
318 (function-item gnus-subscribe-alphabetically
)
319 (function-item gnus-subscribe-hierarchically
)
320 (function-item gnus-subscribe-interactively
)
321 (function-item gnus-subscribe-killed
)
322 (function-item gnus-subscribe-zombies
)
323 (function-item gnus-subscribe-topics
)
327 (defcustom gnus-subscribe-hierarchical-interactive nil
328 "*If non-nil, Gnus will offer to subscribe hierarchically.
329 When a new hierarchy appears, Gnus will ask the user:
331 'alt.binaries': Do you want to subscribe to this hierarchy? ([d]ys):
333 If the user pressed `d', Gnus will descend the hierarchy, `y' will
334 subscribe to all newsgroups in the hierarchy and `s' will skip this
335 hierarchy in its entirety."
336 :group
'gnus-group-new
339 (defcustom gnus-auto-subscribed-categories
'(mail post-mail
)
340 "*New groups from methods of these categories will be subscribed automatically.
341 Note that this variable only deals with new groups. It has no
342 effect whatsoever on old groups. The default is to automatically
343 subscribe all groups from mail-like backends."
345 :group
'gnus-group-new
346 :type
'(repeat symbol
))
348 (defcustom gnus-auto-subscribed-groups
349 "^nnml\\|^nnfolder\\|^nnmbox\\|^nnmh\\|^nnbabyl\\|^nnmaildir\\|^nnimap"
350 "*All new groups that match this regexp will be subscribed automatically.
351 Note that this variable only deals with new groups. It has no effect
352 whatsoever on old groups.
354 New groups that match this regexp will not be handled by
355 `gnus-subscribe-newsgroup-method'. Instead, they will
356 be subscribed using `gnus-subscribe-options-newsgroup-method'."
357 :group
'gnus-group-new
360 (defcustom gnus-options-subscribe nil
361 "*All new groups matching this regexp will be subscribed unconditionally.
362 Note that this variable deals only with new newsgroups. This variable
363 does not affect old newsgroups.
365 New groups that match this regexp will not be handled by
366 `gnus-subscribe-newsgroup-method'. Instead, they will
367 be subscribed using `gnus-subscribe-options-newsgroup-method'."
368 :group
'gnus-group-new
369 :type
'(choice regexp
370 (const :tag
"none" nil
)))
372 (defcustom gnus-options-not-subscribe nil
373 "*All new groups matching this regexp will be ignored.
374 Note that this variable deals only with new newsgroups. This variable
375 does not affect old (already subscribed) newsgroups."
376 :group
'gnus-group-new
377 :type
'(choice regexp
378 (const :tag
"none" nil
)))
380 (defcustom gnus-modtime-botch nil
381 "*Non-nil means .newsrc should be deleted prior to save.
382 Its use is due to the bogus appearance that .newsrc was modified on
387 (defcustom gnus-check-bogus-groups-hook nil
388 "A hook run after removing bogus groups."
389 :group
'gnus-start-server
392 (defcustom gnus-startup-hook nil
393 "A hook called at startup.
394 This hook is called after Gnus is connected to the NNTP server."
398 (defcustom gnus-before-startup-hook nil
399 "A hook called before startup.
400 This hook is called as the first thing when Gnus is started.
401 See also `gnus-before-resume-hook'."
405 (defcustom gnus-before-resume-hook nil
406 "A hook called before resuming Gnus after suspend.
407 This hook is called as the first thing when Gnus is resumed after a suspend.
408 See also `gnus-before-startup-hook'."
413 (defcustom gnus-started-hook nil
414 "A hook called as the last thing after startup."
418 (defcustom gnus-setup-news-hook nil
419 "A hook after reading the .newsrc file, but before generating the buffer."
423 (defcustom gnus-get-top-new-news-hook nil
424 "A hook run just before Gnus checks for new news globally."
426 :group
'gnus-group-new
429 (defcustom gnus-get-new-news-hook nil
430 "A hook run just before Gnus checks for new news."
431 :group
'gnus-group-new
434 (defcustom gnus-after-getting-new-news-hook
435 '(gnus-display-time-event-handler)
436 "*A hook run after Gnus checks for new news when Gnus is already running."
438 :group
'gnus-group-new
441 (defcustom gnus-read-newsrc-el-hook nil
442 "A hook called after reading the newsrc.eld? file."
446 (defcustom gnus-save-newsrc-hook nil
447 "A hook called before saving any of the newsrc files."
451 (defcustom gnus-save-quick-newsrc-hook nil
452 "A hook called just before saving the quick newsrc file.
453 Can be used to turn version control on or off."
457 (defcustom gnus-save-standard-newsrc-hook nil
458 "A hook called just before saving the standard newsrc file.
459 Can be used to turn version control on or off."
463 (defcustom gnus-group-mode-hook nil
464 "Hook for Gnus group mode."
465 :group
'gnus-group-various
466 :options
'(gnus-topic-mode)
469 (defcustom gnus-always-read-dribble-file nil
470 "Unconditionally read the dribble file."
474 ;;; Internal variables
476 ;; Fixme: deal with old emacs-mule when mm-universal-coding-system is
478 (defvar gnus-ding-file-coding-system mm-universal-coding-system
479 "Coding system for ding file.")
481 (defvar gnus-newsrc-file-version nil
)
482 (defvar gnus-override-subscribe-method nil
)
483 (defvar gnus-dribble-buffer nil
)
484 (defvar gnus-newsrc-options nil
485 "Options line in the .newsrc file.")
487 (defvar gnus-newsrc-options-n nil
488 "List of regexps representing groups to be subscribed/ignored unconditionally.")
490 (defvar gnus-newsrc-last-checked-date nil
491 "Date Gnus last asked server for new newsgroups.")
493 (defvar gnus-current-startup-file nil
494 "Startup file for the current host.")
496 ;; Byte-compiler warning.
497 (defvar gnus-group-line-format
)
499 ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
500 (defvar gnus-init-inhibit nil
)
501 (defun gnus-read-init-file (&optional inhibit-next
)
502 ;; Don't load .gnus if the -q option was used.
504 (if gnus-init-inhibit
505 (setq gnus-init-inhibit nil
)
506 (setq gnus-init-inhibit inhibit-next
)
507 (dolist (file (list gnus-site-init-file gnus-init-file
))
509 (locate-library file
))
510 (if (or debug-on-error debug-on-quit
)
515 (error "Error in %s: %s" file
(cadr var
))))))))))
517 ;; For subscribing new newsgroup
519 (defun gnus-subscribe-hierarchical-interactive (groups)
520 (let ((groups (sort groups
'string
<))
521 prefixes prefix start ans group starts real-group
)
523 (setq prefixes
(list "^"))
524 (while (and groups prefixes
)
525 (while (not (string-match (car prefixes
)
526 (gnus-group-real-name (car groups
))))
527 (setq prefixes
(cdr prefixes
)))
528 (setq prefix
(car prefixes
))
529 (setq start
(1- (length prefix
)))
530 (if (and (string-match "[^\\.]\\." (gnus-group-real-name (car groups
))
534 (concat "^" (substring
535 (gnus-group-real-name (car groups
))
537 (string-match prefix
(gnus-group-real-name (cadr groups
))))
539 (push prefix prefixes
)
540 (message "Descend hierarchy %s? ([y]nsq): "
541 (substring prefix
1 (1- (length prefix
))))
542 (while (not (memq (setq ans
(read-char-exclusive))
543 '(?y ?
\n ?
\r ?n ?s ?q
)))
545 (message "Descend hierarchy %s? ([y]nsq): "
546 (substring prefix
1 (1- (length prefix
)))))
549 (setq group
(car groups
)
550 real-group
(gnus-group-real-name group
))
551 (string-match prefix real-group
))
552 (push group gnus-killed-list
)
553 (gnus-sethash group group gnus-killed-hashtb
)
554 (setq groups
(cdr groups
)))
555 (setq starts
(cdr starts
)))
558 (setq group
(car groups
)
559 real-group
(gnus-group-real-name group
))
560 (string-match prefix real-group
))
561 (gnus-sethash group group gnus-killed-hashtb
)
562 (gnus-subscribe-alphabetically (car groups
))
563 (setq groups
(cdr groups
)))
564 (setq starts
(cdr starts
)))
567 (setq group
(car groups
))
568 (push group gnus-killed-list
)
569 (gnus-sethash group group gnus-killed-hashtb
)
570 (setq groups
(cdr groups
))))
572 (message "Subscribe %s? ([n]yq)" (car groups
))
573 (while (not (memq (setq ans
(read-char-exclusive))
574 '(?y ?
\n ?
\r ?q ?n
)))
576 (message "Subscribe %s? ([n]yq)" (car groups
)))
577 (setq group
(car groups
))
579 (gnus-subscribe-alphabetically (car groups
))
580 (gnus-sethash group group gnus-killed-hashtb
))
583 (setq group
(car groups
))
584 (push group gnus-killed-list
)
585 (gnus-sethash group group gnus-killed-hashtb
)
586 (setq groups
(cdr groups
))))
588 (push group gnus-killed-list
)
589 (gnus-sethash group group gnus-killed-hashtb
)))
590 (setq groups
(cdr groups
)))))))
592 (defun gnus-subscribe-randomly (newsgroup)
593 "Subscribe new NEWSGROUP by making it the first newsgroup."
594 (gnus-subscribe-newsgroup newsgroup
))
596 (defun gnus-subscribe-alphabetically (newgroup)
597 "Subscribe new NEWGROUP and insert it in alphabetical order."
598 (let ((groups (cdr gnus-newsrc-alist
))
600 (while (and (not before
) groups
)
601 (if (string< newgroup
(caar groups
))
602 (setq before
(caar groups
))
603 (setq groups
(cdr groups
))))
604 (gnus-subscribe-newsgroup newgroup before
)))
606 (defun gnus-subscribe-hierarchically (newgroup)
607 "Subscribe new NEWGROUP and insert it in hierarchical newsgroup order."
608 ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
609 (with-current-buffer (nnheader-find-file-noselect gnus-current-startup-file
)
611 (let ((groupkey newgroup
) before
)
612 (while (and (not before
) groupkey
)
613 (goto-char (point-min))
615 (concat "^\\(" (regexp-quote groupkey
) ".*\\)[!:]")))
616 (while (and (re-search-forward groupkey-re nil t
)
618 (setq before
(match-string 1))
619 (string< before newgroup
)))))
620 ;; Remove tail of newsgroup name (eg. a.b.c -> a.b)
622 (when (string-match "^\\(.*\\)\\.[^.]+$" groupkey
)
623 (substring groupkey
(match-beginning 1) (match-end 1)))))
624 (gnus-subscribe-newsgroup newgroup before
))
625 (kill-buffer (current-buffer)))))
627 (defun gnus-subscribe-interactively (group)
628 "Subscribe the new GROUP interactively.
629 It is inserted in hierarchical newsgroup order if subscribed. If not,
631 (if (gnus-y-or-n-p (format "Subscribe new newsgroup %s? " group
))
632 (gnus-subscribe-hierarchically group
)
633 (push group gnus-killed-list
)))
635 (defun gnus-subscribe-zombies (group)
636 "Make the new GROUP into a zombie group."
637 (push group gnus-zombie-list
))
639 (defun gnus-subscribe-killed (group)
640 "Make the new GROUP a killed group."
641 (push group gnus-killed-list
))
643 (defun gnus-subscribe-newsgroup (newsgroup &optional next
)
644 "Subscribe new NEWSGROUP.
645 If NEXT is non-nil, it is inserted before NEXT. Otherwise it is made
646 the first newsgroup."
648 (goto-char (point-min))
649 ;; We subscribe the group by changing its level to `subscribed'.
650 (gnus-group-change-level
651 newsgroup gnus-level-default-subscribed
652 gnus-level-killed
(gnus-group-entry (or next
"dummy.group")))
653 (gnus-request-update-group-status newsgroup
'subscribe
)
654 (gnus-message 5 "Subscribe newsgroup: %s" newsgroup
)
655 (run-hook-with-args 'gnus-subscribe-newsgroup-functions newsgroup
)
658 (defun gnus-read-active-file-p ()
659 "Say whether the active file has been read from `gnus-select-method'."
660 (memq gnus-select-method gnus-have-read-active-file
))
662 ;;; General various misc type functions.
664 ;; Silence byte-compiler.
665 (defvar gnus-current-headers
)
666 (defvar gnus-thread-indent-array
)
667 (defvar gnus-newsgroup-name
)
668 (defvar gnus-newsgroup-headers
)
669 (defvar gnus-group-list-mode
)
670 (defvar gnus-group-mark-positions
)
671 (defvar gnus-newsgroup-data
)
672 (defvar gnus-newsgroup-unreads
)
673 (defvar nnoo-state-alist
)
674 (defvar gnus-current-select-method
)
675 (defvar mail-sources
)
676 (defvar nnmail-scan-directory-mail-source-once
)
677 (defvar nnmail-split-history
)
678 (defvar nnmail-spool-file
)
680 (defun gnus-close-all-servers ()
683 (dolist (server gnus-opened-servers
)
684 (gnus-close-server (car server
))))
686 (defun gnus-clear-system ()
687 "Clear all variables and buffers."
688 ;; Clear Gnus variables.
689 (let ((variables (remove 'gnus-format-specs gnus-variable-list
)))
691 (set (car variables
) nil
)
692 (setq variables
(cdr variables
))))
693 ;; Clear other internal variables.
694 (setq gnus-list-of-killed-groups nil
695 gnus-have-read-active-file nil
696 gnus-agent-covered-methods nil
697 gnus-agent-file-loading-local nil
698 gnus-agent-file-loading-cache nil
699 gnus-server-method-cache nil
700 gnus-newsrc-alist nil
701 gnus-newsrc-hashtb nil
704 gnus-killed-hashtb nil
705 gnus-active-hashtb nil
706 gnus-moderated-hashtb nil
707 gnus-description-hashtb nil
708 gnus-current-headers nil
709 gnus-thread-indent-array nil
710 gnus-newsgroup-headers nil
711 gnus-newsgroup-name nil
712 gnus-server-alist nil
713 gnus-group-list-mode nil
714 gnus-opened-servers nil
715 gnus-group-mark-positions nil
716 gnus-newsgroup-data nil
717 gnus-newsgroup-unreads nil
719 gnus-current-select-method nil
720 nnmail-split-history nil
721 gnus-extended-servers nil
722 gnus-ephemeral-servers nil
)
723 (gnus-shutdown 'gnus
)
724 ;; Kill the startup file.
725 (and gnus-current-startup-file
726 (get-file-buffer gnus-current-startup-file
)
727 (kill-buffer (get-file-buffer gnus-current-startup-file
)))
728 ;; Clear the dribble buffer.
730 ;; Kill global KILL file buffer.
731 (when (get-file-buffer (gnus-newsgroup-kill-file nil
))
732 (kill-buffer (get-file-buffer (gnus-newsgroup-kill-file nil
))))
733 (gnus-kill-buffer nntp-server-buffer
)
734 ;; Kill Gnus buffers.
735 (dolist (buffer (gnus-buffers))
736 (gnus-kill-buffer buffer
))
737 ;; Remove Gnus frames.
738 (gnus-kill-gnus-frames))
740 (defun gnus-no-server-1 (&optional arg slave
)
742 If ARG is a positive number, Gnus will use that as the startup
743 level. If ARG is nil, Gnus will be started at level 2
744 \(`gnus-level-default-subscribed' minus one). If ARG is non-nil
745 and not a positive number, Gnus will prompt the user for the name
746 of an NNTP server to use. As opposed to \\[gnus], this command
747 will not connect to the local server."
749 (let ((val (or arg
(1- gnus-level-default-subscribed
))))
751 (make-local-variable 'gnus-group-use-permanent-levels
)
752 (setq gnus-group-use-permanent-levels val
)))
754 (defun gnus-1 (&optional arg dont-connect slave
)
756 If ARG is non-nil and a positive number, Gnus will use that as the
757 startup level. If ARG is non-nil and not a positive number, Gnus will
758 prompt the user for the name of an NNTP server to use."
763 (gnus-run-hooks 'gnus-before-resume-hook
)
764 (switch-to-buffer gnus-group-buffer
)
765 (gnus-group-get-new-news
768 (max (car gnus-group-list-mode
) arg
))))
772 (gnus-run-hooks 'gnus-before-startup-hook
)
773 (nnheader-init-server-buffer)
774 (setq gnus-slave slave
)
775 (gnus-read-init-file)
777 ;; Add "native" to gnus-predefined-server-alist just to have a
778 ;; name for the native select method.
779 (when gnus-select-method
780 (add-to-list 'gnus-predefined-server-alist
781 (cons "native" gnus-select-method
)))
786 (let ((level (and (numberp arg
) (> arg
0) arg
))
792 (gnus-start-news-server (and arg
(not level
))))))
793 (if (and (not dont-connect
)
795 ;; Couldn't connect to the server, so bail out.
797 (gnus-run-hooks 'gnus-startup-hook
)
798 ;; Find the current startup file name.
799 (setq gnus-current-startup-file
800 (gnus-make-newsrc-file gnus-startup-file
))
802 ;; Read the dribble file.
803 (when (or gnus-slave gnus-use-dribble-file
)
804 (gnus-dribble-read-file))
806 ;; Do the actual startup.
807 (gnus-setup-news nil level dont-connect
)
808 (gnus-run-hooks 'gnus-setup-news-hook
)
810 (gnus-request-create-group "queue" '(nndraft "")))
811 (gnus-start-draft-setup)
812 ;; Generate the group buffer.
813 (gnus-group-list-groups level
)
814 (gnus-group-first-unread-group)
815 (gnus-configure-windows 'group
)
816 (gnus-group-set-mode-line)
817 (gnus-run-hooks 'gnus-started-hook
))))))
819 (defun gnus-start-draft-setup ()
820 "Make sure the draft group exists."
822 (gnus-request-create-group "drafts" '(nndraft ""))
823 (unless (gnus-group-entry "nndraft:drafts")
824 (let ((gnus-level-default-subscribed 1))
825 (gnus-subscribe-group "nndraft:drafts" nil
'(nndraft "")))
826 (setcar (gnus-group-entry "nndraft:drafts") 0))
827 (unless (equal (gnus-group-get-parameter "nndraft:drafts" 'gnus-dummy t
)
828 '((gnus-draft-mode)))
829 (gnus-group-set-parameter
830 "nndraft:drafts" 'gnus-dummy
'((gnus-draft-mode)))))
837 (defvar gnus-dribble-ignore nil
)
838 (defvar gnus-dribble-eval-file nil
)
840 (defun gnus-dribble-file-name ()
841 "Return the dribble file for the current .newsrc."
843 (if gnus-dribble-directory
844 (concat (file-name-as-directory gnus-dribble-directory
)
845 (file-name-nondirectory gnus-current-startup-file
))
846 gnus-current-startup-file
)
849 (defun gnus-dribble-enter (string &optional regexp
)
850 "Enter STRING into the dribble buffer.
851 If REGEXP is given, lines that match it will be deleted."
852 (when (and (not gnus-dribble-ignore
)
854 (buffer-name gnus-dribble-buffer
))
855 (let ((obuf (current-buffer)))
856 (set-buffer gnus-dribble-buffer
)
858 (goto-char (point-min))
860 (while (re-search-forward regexp nil t
)
861 (unless (bolp) (forward-line 1))
863 (goto-char (match-beginning 0))
864 (delete-region (point-at-bol) end
))))
865 (goto-char (point-max))
867 ;; This has been commented by Josh Huber <huber@alum.wpi.edu>
868 ;; It causes problems with both XEmacs and Emacs 21, and doesn't
869 ;; seem to be of much value. (FIXME: remove this after we make sure
871 ;; (set-window-point (get-buffer-window (current-buffer)) (point-max))
872 (bury-buffer gnus-dribble-buffer
)
873 (with-current-buffer gnus-group-buffer
874 (gnus-group-set-mode-line))
877 (defun gnus-dribble-touch ()
878 "Touch the dribble buffer."
879 (gnus-dribble-enter ""))
881 (defun gnus-dribble-read-file ()
882 "Read the dribble file from disk."
883 (let ((dribble-file (gnus-dribble-file-name)))
884 (unless (file-exists-p (file-name-directory dribble-file
))
885 (make-directory (file-name-directory dribble-file
) t
))
886 (with-current-buffer (setq gnus-dribble-buffer
887 (gnus-get-buffer-create
888 (file-name-nondirectory dribble-file
)))
889 (set (make-local-variable 'file-precious-flag
) t
)
890 (setq buffer-save-without-query t
)
892 (setq buffer-file-name dribble-file
)
893 ;; The buffer may be shrunk a lot when deleting old entries.
894 ;; It caused the auto-saving to stop.
895 (if (featurep 'emacs
)
896 (set (make-local-variable 'auto-save-include-big-deletions
) t
)
897 (set (make-local-variable 'disable-auto-save-when-buffer-shrinks
) nil
))
899 (buffer-disable-undo)
900 (bury-buffer (current-buffer))
901 (set-buffer-modified-p nil
)
902 (let ((auto (make-auto-save-file-name))
903 (gnus-dribble-ignore t
)
906 (when (or (file-exists-p auto
) (file-exists-p dribble-file
))
907 ;; Load whichever file is newest -- the auto save file
908 ;; or the "real" file.
909 (if (file-newer-than-file-p auto dribble-file
)
910 (nnheader-insert-file-contents auto
)
911 (nnheader-insert-file-contents dribble-file
))
912 (unless (zerop (buffer-size))
913 (set-buffer-modified-p t
))
914 ;; Set the file modes to reflect the .newsrc file modes.
916 (when (and (file-exists-p gnus-current-startup-file
)
917 (file-exists-p dribble-file
)
918 (setq modes
(file-modes gnus-current-startup-file
)))
919 (gnus-set-file-modes dribble-file modes
))
920 (goto-char (point-min))
921 (when (search-forward "Gnus was exited on purpose" nil t
)
923 ;; Possibly eval the file later.
924 (when (or gnus-always-read-dribble-file
927 "Gnus exited on purpose without saving; read auto-save file anyway? "
928 "Gnus auto-save file exists. Do you want to read it? ")))
929 (setq gnus-dribble-eval-file t
)))))))
931 (defun gnus-dribble-eval-file ()
932 (when gnus-dribble-eval-file
933 (setq gnus-dribble-eval-file nil
)
935 (let ((gnus-dribble-ignore t
))
936 (set-buffer gnus-dribble-buffer
)
937 (eval-buffer (current-buffer))))))
939 (defun gnus-dribble-delete-file ()
940 (when (file-exists-p (gnus-dribble-file-name))
941 (delete-file (gnus-dribble-file-name)))
942 (when gnus-dribble-buffer
943 (with-current-buffer gnus-dribble-buffer
944 (let ((auto (make-auto-save-file-name)))
945 (when (file-exists-p auto
)
948 (set-buffer-modified-p nil
)))))
950 (defun gnus-dribble-save ()
951 (when (and gnus-dribble-buffer
952 (buffer-name gnus-dribble-buffer
))
953 (with-current-buffer gnus-dribble-buffer
954 (when (> (buffer-size) 0)
957 (defun gnus-dribble-clear ()
958 (when (gnus-buffer-exists-p gnus-dribble-buffer
)
959 (with-current-buffer gnus-dribble-buffer
961 (set-buffer-modified-p nil
)
962 (setq buffer-saved-size
(buffer-size)))))
966 ;;; Active & Newsrc File Handling
969 (defun gnus-setup-news (&optional rawfile level dont-connect
)
970 "Setup news information.
971 If RAWFILE is non-nil, the .newsrc file will also be read.
972 If LEVEL is non-nil, the news will be set up at level LEVEL."
974 (let ((init (not (and gnus-newsrc-alist gnus-active-hashtb
(not rawfile
))))
975 ;; Binding this variable will inhibit multiple fetchings
976 ;; of the same mail source.
977 (nnmail-fetched-sources (list t
)))
980 ;; Clear some variables to re-initialize news information.
981 (setq gnus-newsrc-alist nil
982 gnus-active-hashtb nil
)
983 ;; Read the newsrc file and create `gnus-newsrc-hashtb'.
984 (gnus-read-newsrc-file rawfile
))
986 ;; Make sure the archive server is available to all and sundry.
987 (let ((method (or (and (stringp gnus-message-archive-method
)
988 (gnus-server-to-method
989 gnus-message-archive-method
))
990 gnus-message-archive-method
)))
991 ;; Check whether the archive method is writable.
992 (unless (or (not method
)
994 (memq 'respool
(assoc (format "%s" (car method
))
995 gnus-valid-select-methods
)))
996 (setq method
"archive")) ;; The default.
997 (when (stringp method
)
998 (setq method
`(nnfolder
1001 ,(nnheader-concat message-directory method
))
1002 (nnfolder-active-file
1003 ,(nnheader-concat message-directory
1004 (concat method
"/active")))
1005 (nnfolder-get-new-mail nil
)
1006 (nnfolder-inhibit-expiry t
))))
1007 (if (assoc "archive" gnus-server-alist
)
1008 (when gnus-update-message-archive-method
1010 (setcdr (assoc "archive" gnus-server-alist
) method
)
1011 (setq gnus-server-alist
(delq (assoc "archive" gnus-server-alist
)
1012 gnus-server-alist
))))
1014 (push (cons "archive" method
) gnus-server-alist
))))
1016 ;; If we don't read the complete active file, we fill in the
1018 (when (or (null gnus-read-active-file
)
1019 (eq gnus-read-active-file
'some
))
1020 (gnus-update-active-hashtb-from-killed))
1021 (unless gnus-active-hashtb
1022 (setq gnus-active-hashtb
(gnus-make-hashtable 4096)))
1023 ;; Initialize the cache.
1024 (when gnus-use-cache
1027 ;; Possibly eval the dribble file.
1029 (or gnus-use-dribble-file gnus-slave
)
1030 (gnus-dribble-eval-file))
1032 ;; Slave Gnusii should then clear the dribble buffer.
1033 (when (and init gnus-slave
)
1034 (gnus-dribble-clear))
1036 (gnus-update-format-specifications)
1038 ;; See whether we need to read the description file.
1039 (when (and (boundp 'gnus-group-line-format
)
1040 (stringp gnus-group-line-format
)
1041 (let ((case-fold-search nil
))
1042 (string-match "%[-,0-9]*D" gnus-group-line-format
))
1043 (not gnus-description-hashtb
)
1045 gnus-read-active-file
)
1046 (gnus-read-all-descriptions-files))
1048 ;; Find new newsgroups and treat them.
1049 (when (and init gnus-check-new-newsgroups
(not level
)
1050 (gnus-check-server gnus-select-method
)
1053 (gnus-find-new-newsgroups))
1055 ;; Check and remove bogus newsgroups.
1056 (when (and init gnus-check-bogus-newsgroups
1057 gnus-read-active-file
(not level
)
1058 (gnus-server-opened gnus-select-method
))
1059 (gnus-check-bogus-newsgroups))
1061 ;; Read any slave files.
1062 (gnus-master-read-slave-newsrc)
1064 ;; Find the number of unread articles in each non-dead group.
1065 (let ((gnus-read-active-file (and (not level
) gnus-read-active-file
)))
1066 (gnus-get-unread-articles level dont-connect
))))
1068 (defun gnus-call-subscribe-functions (method group
)
1069 "Call METHOD to subscribe GROUP.
1070 If no function returns `non-nil', call `gnus-subscribe-zombies'."
1073 (funcall method group
))
1076 (dolist (func method
)
1077 (if (funcall func group
)
1081 (gnus-subscribe-zombies group
)))
1083 (defun gnus-find-new-newsgroups (&optional arg
)
1084 "Search for new newsgroups and add them.
1085 Each new newsgroup will be treated with `gnus-subscribe-newsgroup-method'.
1086 The `-n' option line from .newsrc is respected.
1088 With 1 C-u, use the `ask-server' method to query the server for new
1090 With 2 C-u's, use most complete method possible to query the server
1091 for new groups, and subscribe the new groups as zombies."
1093 (let* ((gnus-subscribe-newsgroup-method
1094 gnus-subscribe-newsgroup-method
)
1096 ((or (and (= (or arg
1) 4)
1097 (not (listp gnus-check-new-newsgroups
)))
1098 (null gnus-read-active-file
)
1099 (eq gnus-read-active-file
'some
))
1102 (setq gnus-subscribe-newsgroup-method
1103 'gnus-subscribe-zombies
)
1105 (t gnus-check-new-newsgroups
))))
1106 (if (or (consp check
)
1107 (eq check
'ask-server
))
1108 ;; Ask the server for new groups.
1109 (gnus-ask-server-for-new-groups)
1110 ;; Go through the active hashtb and look for new groups.
1112 group new-newsgroups
)
1113 (gnus-message 5 "Looking for new newsgroups...")
1114 (unless gnus-have-read-active-file
1115 (gnus-read-active-file))
1116 (setq gnus-newsrc-last-checked-date
(message-make-date))
1117 (unless gnus-killed-hashtb
1118 (gnus-make-hashtable-from-killed))
1119 ;; Go though every newsgroup in `gnus-active-hashtb' and compare
1120 ;; with `gnus-newsrc-hashtb' and `gnus-killed-hashtb'.
1123 (if (or (null (setq group
(symbol-name sym
)))
1125 (null (symbol-value sym
))
1126 (gnus-gethash group gnus-killed-hashtb
)
1127 (gnus-gethash group gnus-newsrc-hashtb
))
1129 (let ((do-sub (gnus-matches-options-n group
)))
1131 ((eq do-sub
'subscribe
)
1132 (setq groups
(1+ groups
))
1133 (gnus-sethash group group gnus-killed-hashtb
)
1134 (gnus-call-subscribe-functions
1135 gnus-subscribe-options-newsgroup-method group
))
1136 ((eq do-sub
'ignore
)
1139 (setq groups
(1+ groups
))
1140 (gnus-sethash group group gnus-killed-hashtb
)
1141 (if gnus-subscribe-hierarchical-interactive
1142 (push group new-newsgroups
)
1143 (gnus-call-subscribe-functions
1144 gnus-subscribe-newsgroup-method group
)))))))
1146 (when new-newsgroups
1147 (gnus-subscribe-hierarchical-interactive new-newsgroups
))
1149 (gnus-message 5 "%d new newsgroup%s arrived."
1150 groups
(if (> groups
1) "s have" " has"))
1151 (gnus-message 5 "No new newsgroups."))
1154 (defun gnus-matches-options-n (group)
1155 ;; Returns `subscribe' if the group is to be unconditionally
1156 ;; subscribed, `ignore' if it is to be ignored, and nil if there is
1157 ;; no match for the group.
1159 ;; First we check the two user variables.
1161 ((and gnus-options-subscribe
1162 (string-match gnus-options-subscribe group
))
1164 ((let ((do-subscribe nil
))
1165 (dolist (category gnus-auto-subscribed-categories
)
1166 (when (gnus-member-of-valid category group
)
1167 (setq do-subscribe t
)))
1170 ((and gnus-auto-subscribed-groups
1171 (string-match gnus-auto-subscribed-groups group
))
1173 ((and gnus-options-not-subscribe
1174 (string-match gnus-options-not-subscribe group
))
1176 ;; Then we go through the list that was retrieved from the .newsrc
1177 ;; file. This list has elements on the form
1178 ;; `(REGEXP . {ignore,subscribe})'. The first match found (the list
1179 ;; is in the reverse order of the options line) is returned.
1181 (let ((regs gnus-newsrc-options-n
))
1183 (not (string-match (caar regs
) group
)))
1184 (setq regs
(cdr regs
)))
1185 (and regs
(cdar regs
))))))
1187 (defun gnus-ask-server-for-new-groups ()
1188 (let* ((new-date (message-make-date))
1189 (date (or gnus-newsrc-last-checked-date new-date
))
1190 (methods (cons gnus-select-method
1192 (when (gnus-archive-server-wanted-p)
1195 (and (consp gnus-check-new-newsgroups
)
1196 gnus-check-new-newsgroups
)
1197 gnus-secondary-select-methods
))))
1199 group new-newsgroups got-new method hashtb
1200 gnus-override-subscribe-method
)
1201 (unless gnus-killed-hashtb
1202 (gnus-make-hashtable-from-killed))
1203 ;; Go through both primary and secondary select methods and
1204 ;; request new newsgroups.
1205 (while (setq method
(gnus-server-get-method nil
(pop methods
)))
1206 (setq new-newsgroups nil
1207 gnus-override-subscribe-method method
)
1208 (when (and (gnus-check-server method
)
1209 (gnus-request-newgroups date method
))
1212 hashtb
(gnus-make-hashtable 100))
1213 (set-buffer nntp-server-buffer
)
1214 ;; Enter all the new groups into a hashtable.
1215 (gnus-active-to-gnus-format method hashtb
'ignore
))
1216 ;; Now all new groups from `method' are in `hashtb'.
1219 (if (or (null (setq group
(symbol-name group-sym
)))
1220 (not (boundp group-sym
))
1221 (null (symbol-value group-sym
))
1222 (gnus-gethash group gnus-newsrc-hashtb
)
1223 (member group gnus-zombie-list
)
1224 (member group gnus-killed-list
))
1225 ;; The group is already known.
1227 ;; Make this group active.
1228 (when (symbol-value group-sym
)
1229 (gnus-set-active group
(symbol-value group-sym
)))
1230 ;; Check whether we want it or not.
1231 (let ((do-sub (gnus-matches-options-n group
)))
1233 ((eq do-sub
'subscribe
)
1235 (gnus-sethash group group gnus-killed-hashtb
)
1236 (gnus-call-subscribe-functions
1237 gnus-subscribe-options-newsgroup-method group
))
1238 ((eq do-sub
'ignore
)
1242 (gnus-sethash group group gnus-killed-hashtb
)
1243 (if gnus-subscribe-hierarchical-interactive
1244 (push group new-newsgroups
)
1245 (gnus-call-subscribe-functions
1246 gnus-subscribe-newsgroup-method group
)))))))
1248 (when new-newsgroups
1249 (gnus-subscribe-hierarchical-interactive new-newsgroups
)))
1251 (gnus-message 5 "%d new newsgroup%s arrived"
1252 groups
(if (> groups
1) "s have" " has"))
1253 (gnus-message 5 "No new newsgroups"))
1255 (setq gnus-newsrc-last-checked-date new-date
))
1258 (defun gnus-subscribe-group (group &optional previous method
)
1259 "Subscribe GROUP and put it after PREVIOUS."
1260 (gnus-group-change-level
1262 (list t group gnus-level-default-subscribed nil nil method
)
1264 gnus-level-default-subscribed gnus-level-killed previous t
)
1267 ;; `gnus-group-change-level' is the fundamental function for changing
1268 ;; subscription levels of newsgroups. This might mean just changing
1269 ;; from level 1 to 2, which is pretty trivial, from 2 to 6 or back
1270 ;; again, which subscribes/unsubscribes a group, which is equally
1271 ;; trivial. Changing from 1-7 to 8-9 means that you kill a group, and
1272 ;; from 8-9 to 1-7 means that you remove the group from the list of
1273 ;; killed (or zombie) groups and add them to the (kinda) subscribed
1274 ;; groups. And last but not least, moving from 8 to 9 and 9 to 8,
1275 ;; which is trivial.
1276 ;; ENTRY can either be a string (newsgroup name) or a list (if
1277 ;; FROMKILLED is t, it's a list on the format (NUM INFO-LIST),
1278 ;; otherwise it's a list in the format of the `gnus-newsrc-hashtb'
1280 ;; LEVEL is the new level of the group, OLDLEVEL is the old level and
1281 ;; PREVIOUS is the group (in hashtb entry format) to insert this group
1283 (defun gnus-group-change-level (entry level
&optional oldlevel
1284 previous fromkilled
)
1285 (let (group info active num
)
1286 ;; Glean what info we can from the arguments
1288 (if fromkilled
(setq group
(nth 1 entry
))
1289 (setq group
(car (nth 2 entry
))))
1291 (when (and (stringp entry
)
1293 (< oldlevel gnus-level-zombie
))
1294 (setq entry
(gnus-group-entry entry
)))
1295 (if (and (not oldlevel
)
1297 (setq oldlevel
(gnus-info-level (nth 2 entry
)))
1298 (setq oldlevel
(or oldlevel gnus-level-killed
)))
1299 (when (stringp previous
)
1300 (setq previous
(gnus-group-entry previous
)))
1302 (if (and (>= oldlevel gnus-level-zombie
)
1303 (gnus-group-entry group
))
1304 ;; We are trying to subscribe a group that is already
1308 (unless (gnus-ephemeral-group-p group
)
1310 (format "(gnus-group-change-level %S %S %S %S %S)"
1311 group level oldlevel
(car (nth 2 previous
)) fromkilled
)))
1313 ;; Then we remove the newgroup from any old structures, if needed.
1314 ;; If the group was killed, we remove it from the killed or zombie
1315 ;; list. If not, and it is in fact going to be killed, we remove
1316 ;; it from the newsrc hash table and assoc.
1318 ((>= oldlevel gnus-level-zombie
)
1319 ;; oldlevel could be wrong.
1320 (setq gnus-zombie-list
(delete group gnus-zombie-list
))
1321 (setq gnus-killed-list
(delete group gnus-killed-list
)))
1323 (when (and (>= level gnus-level-zombie
)
1325 (gnus-sethash (car (nth 2 entry
)) nil gnus-newsrc-hashtb
)
1327 (setcdr (gnus-group-entry (car (nth 3 entry
)))
1329 (setcdr (cdr entry
) (cdddr entry
)))))
1331 ;; Finally we enter (if needed) the list where it is supposed to
1332 ;; go, and change the subscription level. If it is to be killed,
1333 ;; we enter it into the killed or zombie list.
1335 ((>= level gnus-level-zombie
)
1336 ;; Remove from the hash table.
1337 (gnus-sethash group nil gnus-newsrc-hashtb
)
1338 (if (= level gnus-level-zombie
)
1339 (push group gnus-zombie-list
)
1340 (if (= oldlevel gnus-level-killed
)
1341 ;; Remove from active hashtb.
1342 (unintern group gnus-active-hashtb
)
1343 ;; Don't add it into killed-list if it was killed.
1344 (push group gnus-killed-list
))))
1346 ;; If the list is to be entered into the newsrc assoc, and
1347 ;; it was killed, we have to create an entry in the newsrc
1348 ;; hashtb format and fix the pointers in the newsrc assoc.
1349 (if (< oldlevel gnus-level-zombie
)
1350 ;; It was alive, and it is going to stay alive, so we
1351 ;; just change the level and don't change any pointers or
1352 ;; hash table entries.
1353 (setcar (cdaddr entry
) level
)
1355 (setq info
(cdr entry
)
1357 (setq active
(gnus-active group
))
1359 (if active
(- (1+ (cdr active
)) (car active
)) t
))
1360 ;; Shorten the select method if possible, if we need to
1361 ;; store it at all (native groups).
1362 (let ((method (gnus-method-simplify
1363 (or gnus-override-subscribe-method
1364 (gnus-group-method group
)))))
1366 (setq info
(list group level nil nil method
))
1367 (setq info
(list group level nil
)))))
1370 (let ((p gnus-newsrc-alist
))
1374 (setq entry
(cons info
(cddr previous
)))
1377 (setcdr (cdr previous
) entry
)
1378 (gnus-sethash group
(cons num
(cdr previous
))
1379 gnus-newsrc-hashtb
))
1380 (setcdr previous entry
)
1381 (gnus-sethash group
(cons num previous
)
1382 gnus-newsrc-hashtb
))
1384 (setcdr (gnus-group-entry (caadr entry
)) entry
))
1386 (format "(gnus-group-set-info '%S)" info
)
1387 (concat "^(gnus-group-set-info '(\"" (regexp-quote group
) "\"")))))
1388 (when gnus-group-change-level-function
1389 (funcall gnus-group-change-level-function
1390 group level oldlevel previous
)))))
1392 (defun gnus-check-bogus-newsgroups (&optional confirm
)
1393 "Remove bogus newsgroups.
1394 If CONFIRM is non-nil, the user has to confirm the deletion of every
1396 (let ((newsrc (cdr gnus-newsrc-alist
))
1397 bogus group entry info
)
1398 (gnus-message 5 "Checking bogus newsgroups...")
1399 (unless (gnus-read-active-file-p)
1400 (gnus-read-active-file t
))
1401 (when (gnus-read-active-file-p)
1402 ;; Find all bogus newsgroup that are subscribed.
1404 (setq info
(pop newsrc
)
1405 group
(gnus-info-group info
))
1406 (unless (or (gnus-active group
) ; Active
1407 (and (gnus-info-method info
)
1408 (not (gnus-secondary-method-p
1409 (gnus-info-method info
))))) ; Foreign
1410 ;; Found a bogus newsgroup.
1411 (push group bogus
)))
1414 (format "Remove bogus group %%s (of %d groups)? " (length bogus
))
1416 ;; Remove all bogus subscribed groups by first killing them, and
1417 ;; then removing them from the list of killed groups.
1418 (when (setq entry
(gnus-group-entry group
))
1419 (gnus-group-change-level entry gnus-level-killed
)
1420 (setq gnus-killed-list
(delete group gnus-killed-list
))))
1421 bogus
'("group" "groups" "remove"))
1422 (while (setq group
(pop bogus
))
1423 ;; Remove all bogus subscribed groups by first killing them, and
1424 ;; then removing them from the list of killed groups.
1425 (when (setq entry
(gnus-group-entry group
))
1426 (gnus-group-change-level entry gnus-level-killed
)
1427 (setq gnus-killed-list
(delete group gnus-killed-list
)))))
1428 ;; Then we remove all bogus groups from the list of killed and
1429 ;; zombie groups. They are removed without confirmation.
1430 (let ((dead-lists '(gnus-killed-list gnus-zombie-list
))
1433 (setq killed
(symbol-value (car dead-lists
)))
1435 (unless (gnus-active (setq group
(pop killed
)))
1436 ;; The group is bogus.
1438 (set (car dead-lists
)
1439 (delete group
(symbol-value (car dead-lists
))))))
1440 (setq dead-lists
(cdr dead-lists
))))
1441 (gnus-run-hooks 'gnus-check-bogus-groups-hook
)
1442 (gnus-message 5 "Checking bogus newsgroups...done"))))
1444 (defun gnus-check-duplicate-killed-groups ()
1445 "Remove duplicates from the list of killed groups."
1447 (let ((killed gnus-killed-list
))
1449 (gnus-message 9 "%d" (length killed
))
1450 (setcdr killed
(delete (car killed
) (cdr killed
)))
1451 (setq killed
(cdr killed
)))))
1453 ;; We want to inline a function from gnus-cache, so we cheat here:
1454 (defvar gnus-cache-active-hashtb
)
1456 (defun gnus-cache-possibly-alter-active (group active
)
1457 "Alter the ACTIVE info for GROUP to reflect the articles in the cache."
1458 (when gnus-cache-active-hashtb
1459 (let ((cache-active (gnus-gethash group gnus-cache-active-hashtb
)))
1461 (when (< (car cache-active
) (car active
))
1462 (setcar active
(car cache-active
)))
1463 (when (> (cdr cache-active
) (cdr active
))
1464 (setcdr active
(cdr cache-active
))))))))
1466 (defun gnus-activate-group (group &optional scan dont-check method
1468 "Check whether a group has been activated or not.
1469 If SCAN, request a scan of that group as well. If METHOD, use
1470 that select method instead of determining the method based on the
1471 group name. If DONT-CHECK, don't check whether the group
1472 actually exists. If DONT-SUB-CHECK or DONT-CHECK, don't let the
1473 backend check whether the group actually exists."
1474 (let ((method (or method
(inline (gnus-find-method-for-group group
))))
1476 (and (inline (gnus-check-server method
))
1477 ;; We escape all bugs and quit here to make it possible to
1478 ;; continue if a group is so out-there that it reports bugs
1482 (gnus-check-backend-function 'request-scan
(car method
))
1483 (gnus-request-scan group method
))
1485 (if (or debug-on-error debug-on-quit
)
1486 (inline (gnus-request-group group
(or dont-sub-check dont-check
)
1488 (gnus-get-info group
)))
1490 (inline (gnus-request-group group
(or dont-sub-check dont-check
)
1492 (gnus-get-info group
)))
1496 (message "Quit activating %s" group
))
1499 (setq active
(gnus-parse-active))
1500 ;; If there are no articles in the group, the GROUP
1501 ;; command may have responded with the `(0 . 0)'. We
1502 ;; ignore this if we already have an active entry
1504 (if (and (zerop (or (car active
) 0))
1505 (zerop (or (cdr active
) 0))
1506 (gnus-active group
))
1509 ;; If a cache is present, we may have to alter the active info.
1510 (when gnus-use-cache
1511 (inline (gnus-cache-possibly-alter-active
1514 ;; If the agent is enabled, we may have to alter the active info.
1516 (gnus-agent-possibly-alter-active group active
))
1518 (gnus-set-active group active
)
1519 ;; Return the new active info.
1522 (defun gnus-get-unread-articles-in-group (info active
&optional update
)
1523 (when (and info active
)
1524 ;; Allow the backend to update the info in the group.
1526 (gnus-request-update-info
1527 info
(inline (gnus-find-method-for-group
1528 (gnus-info-group info
)))))
1529 (gnus-activate-group (gnus-info-group info
) nil t
))
1531 (let* ((range (gnus-info-read info
))
1534 ;; These checks are present in gnus-activate-group but skipped
1535 ;; due to setting dont-check in the preceding call.
1537 ;; If a cache is present, we may have to alter the active info.
1538 (when (and gnus-use-cache info
)
1539 (inline (gnus-cache-possibly-alter-active
1540 (gnus-info-group info
) active
)))
1542 ;; If the agent is enabled, we may have to alter the active info.
1543 (when (and gnus-agent info
)
1544 (gnus-agent-possibly-alter-active (gnus-info-group info
) active info
))
1546 ;; Modify the list of read articles according to what articles
1547 ;; are available; then tally the unread articles and add the
1548 ;; number to the group hash table entry.
1550 ((zerop (cdr active
))
1553 (setq num
(- (1+ (cdr active
)) (car active
))))
1554 ((not (listp (cdr range
)))
1555 ;; Fix a single (num . num) range according to the
1556 ;; active hash table.
1557 ;; Fix by Carsten Bormann <cabo@Informatik.Uni-Bremen.DE>.
1558 (and (< (cdr range
) (car active
)) (setcdr range
(1- (car active
))))
1559 (and (> (cdr range
) (cdr active
)) (setcdr range
(cdr active
)))
1560 ;; Compute number of unread articles.
1561 (setq num
(max 0 (- (cdr active
) (- (1+ (cdr range
)) (car range
))))))
1563 ;; The read list is a list of ranges. Fix them according to
1564 ;; the active hash table.
1565 ;; First peel off any elements that are below the lower
1567 (while (and (cdr range
)
1569 (or (and (atom (cadr range
)) (cadr range
))
1571 (if (numberp (car range
))
1574 (or (and (numberp (cadr range
))
1578 (or (and (numberp (nth 1 range
)) (nth 1 range
))
1580 (setcdr range
(cddr range
)))
1581 ;; Adjust the first element to be the same as the lower limit.
1582 (when (and (not (atom (car range
)))
1583 (< (cdar range
) (car active
)))
1584 (setcdr (car range
) (1- (car active
))))
1585 ;; Then we want to peel off any elements that are higher
1586 ;; than the upper active limit.
1587 (let ((srange range
))
1588 ;; Go past all valid elements.
1589 (while (and (cdr srange
)
1590 (<= (or (and (atom (cadr srange
))
1594 (setq srange
(cdr srange
)))
1596 ;; Nuke all remaining invalid elements.
1597 (setcdr srange nil
))
1599 ;; Adjust the final element.
1600 (when (and (not (atom (car srange
)))
1601 (> (cdar srange
) (cdr active
)))
1602 (setcdr (car srange
) (cdr active
))))
1603 ;; Compute the number of unread articles.
1605 (setq num
(+ num
(- (1+ (or (and (atom (car range
)) (car range
))
1607 (or (and (atom (car range
)) (car range
))
1609 (setq range
(cdr range
)))
1610 (setq num
(max 0 (- (cdr active
) num
)))))
1611 ;; Set the number of unread articles.
1613 (gnus-group-entry (gnus-info-group info
)))
1614 (setcar (gnus-group-entry (gnus-info-group info
)) num
))
1617 ;; Go though `gnus-newsrc-alist' and compare with `gnus-active-hashtb'
1618 ;; and compute how many unread articles there are in each group.
1619 (defun gnus-get-unread-articles (&optional level dont-connect one-level
)
1620 (setq gnus-server-method-cache nil
)
1621 (require 'gnus-agent
)
1622 (let* ((newsrc (cdr gnus-newsrc-alist
))
1623 (alevel (or level gnus-activate-level
(1+ gnus-level-subscribed
)))
1628 (cond ((and gnus-activate-foreign-newsgroups
1629 (not (numberp gnus-activate-foreign-newsgroups
)))
1630 (1+ gnus-level-subscribed
))
1631 ((numberp gnus-activate-foreign-newsgroups
)
1632 gnus-activate-foreign-newsgroups
)
1637 (gnus-agent-article-local-times 0)
1638 (archive-method (gnus-server-to-method "archive"))
1639 infos info group active method cmethod
1640 method-type method-group-list entry
)
1641 (gnus-message 6 "Checking new news...")
1644 (setq active
(gnus-active (setq group
(gnus-info-group
1645 (setq info
(pop newsrc
))))))
1646 ;; First go through all the groups, see what select methods they
1647 ;; belong to, and then collect them into lists per unique select
1649 (if (not (setq method
(gnus-info-method info
)))
1650 (setq method gnus-select-method
)
1651 ;; There may be several similar methods. Possibly extend the
1653 (if (setq cmethod
(assoc method methods-cache
))
1654 (setq method
(cdr cmethod
))
1655 (setq cmethod
(if (stringp method
)
1656 (gnus-server-to-method method
)
1657 (inline (gnus-find-method-for-group
1658 (gnus-info-group info
) info
))))
1659 (push (cons method cmethod
) methods-cache
)
1660 (setq method cmethod
)))
1661 (setq method-group-list
(assoc method type-cache
))
1662 (unless method-group-list
1665 ((or (gnus-secondary-method-p method
)
1666 (and (gnus-archive-server-wanted-p)
1667 (gnus-methods-equal-p archive-method method
)))
1669 ((inline (gnus-server-equal gnus-select-method method
))
1673 (push (setq method-group-list
(list method method-type nil nil
))
1675 ;; Only add groups that need updating.
1676 (if (funcall (if one-level
#'= #'<=) (gnus-info-level info
)
1677 (if (eq (cadr method-group-list
) 'foreign
)
1680 (setcar (nthcdr 2 method-group-list
)
1681 (cons info
(nth 2 method-group-list
)))
1682 ;; The group is inactive, so we nix out the number of unread articles.
1683 ;; It leads `(gnus-group-unread group)' to return t. See also
1684 ;; `gnus-group-prepare-flat'.
1686 (when (setq entry
(gnus-group-entry group
))
1687 (setcar entry t
)))))
1689 ;; Sort the methods based so that the primary and secondary
1690 ;; methods come first. This is done for legacy reasons to try to
1691 ;; ensure that side-effect behavior doesn't change from previous
1694 (sort (nreverse type-cache
)
1696 (< (gnus-method-rank (cadr c1
) (car c1
))
1697 (gnus-method-rank (cadr c2
) (car c2
))))))
1698 ;; Go through the list of servers and possibly extend methods that
1699 ;; aren't equal (and that need extension; i.e., they are async).
1700 (let ((methods nil
))
1701 (dolist (elem type-cache
)
1702 (destructuring-bind (method method-type infos dummy
) elem
1703 (let ((gnus-opened-servers methods
))
1704 (when (and (gnus-similar-server-opened method
)
1705 (gnus-check-backend-function
1706 'retrieve-group-data-early
(car method
)))
1707 (setq method
(gnus-server-extend-method
1708 (gnus-info-group (car infos
))
1710 (setcar elem method
))
1711 (push (list method
'ok
) methods
)))))
1713 ;; If we have primary/secondary select methods, but no groups from
1714 ;; them, we still want to issue a retrieval request from them.
1715 (unless dont-connect
1716 (dolist (method (cons gnus-select-method
1717 gnus-secondary-select-methods
))
1718 (when (and (not (assoc method type-cache
))
1719 (gnus-check-backend-function 'request-list
(car method
)))
1720 (with-current-buffer nntp-server-buffer
1721 (gnus-read-active-file-1 method nil
)))))
1723 ;; Clear out all the early methods.
1724 (dolist (elem type-cache
)
1725 (destructuring-bind (method method-type infos dummy
) elem
1728 (gnus-check-backend-function
1729 'retrieve-group-data-early
(car method
))
1730 (not (gnus-method-denied-p method
)))
1731 (when (ignore-errors (gnus-get-function method
'open-server
))
1732 (unless (gnus-server-opened method
)
1733 (gnus-open-server method
))
1734 (when (gnus-server-opened method
)
1735 ;; Just mark this server as "cleared".
1736 (gnus-retrieve-group-data-early method nil
))))))
1738 ;; Start early async retrieval of data.
1739 (let ((done-methods nil
)
1741 (dolist (elem type-cache
)
1742 (destructuring-bind (method method-type infos dummy
) elem
1743 (setq sanity-spec
(list (car method
) (cadr method
)))
1744 (when (and method infos
1745 (not (gnus-method-denied-p method
)))
1746 ;; If the open-server method doesn't exist, then the method
1747 ;; itself doesn't exist, so we ignore it.
1748 (if (not (ignore-errors (gnus-get-function method
'open-server
)))
1749 (setq type-cache
(delq elem type-cache
))
1750 (unless (gnus-server-opened method
)
1751 (gnus-open-server method
))
1753 ;; This is a sanity check, so that we never
1754 ;; attempt to start two async requests to the
1755 ;; same server, because that will fail. This
1756 ;; should never happen, since the methods should
1757 ;; be unique at this point, but apparently it
1758 ;; does happen in the wild with some setups.
1759 (not (member sanity-spec done-methods
))
1760 (gnus-server-opened method
)
1761 (gnus-check-backend-function
1762 'retrieve-group-data-early
(car method
)))
1763 (push sanity-spec done-methods
)
1764 (when (gnus-check-backend-function 'request-scan
(car method
))
1765 (gnus-request-scan nil method
))
1766 ;; Store the token we get back from -early so that we
1767 ;; can pass it to -finish later.
1768 (setcar (nthcdr 3 elem
)
1769 (gnus-retrieve-group-data-early method infos
))))))))
1771 ;; Do the rest of the retrieval.
1772 (dolist (elem type-cache
)
1773 (destructuring-bind (method method-type infos early-data
) elem
1774 (when (and method infos
1775 (not (gnus-method-denied-p method
)))
1776 (let ((updatep (gnus-check-backend-function
1777 'request-update-info
(car method
))))
1778 ;; See if any of the groups from this method require updating.
1779 (gnus-read-active-for-groups method infos early-data
)
1780 (dolist (info infos
)
1781 (inline (gnus-get-unread-articles-in-group
1782 info
(gnus-active (gnus-info-group info
))
1784 (gnus-message 6 "Checking new news...done")))
1786 (defun gnus-method-rank (type method
)
1788 ;; Get info for virtual groups last.
1789 ((eq (car method
) 'nnvirtual
)
1793 ;; Compute the rank of the secondary methods based on where they
1794 ;; are in the secondary select list.
1795 ((eq type
'secondary
)
1798 (dolist (smethod gnus-secondary-select-methods
)
1799 (when (equal method smethod
)
1803 ;; Just say that all foreign groups have the same rank.
1807 (defun gnus-read-active-for-groups (method infos early-data
)
1808 (with-current-buffer nntp-server-buffer
1810 ;; Finish up getting the data from the methods that have -early
1814 (gnus-check-backend-function 'finish-retrieve-group-infos
(car method
))
1815 (or (not (gnus-agent-method-p method
))
1816 (gnus-online method
)))
1817 (gnus-finish-retrieve-group-infos method infos early-data
)
1818 ;; We may have altered the data now, so mark the dribble buffer
1819 ;; as dirty so that it gets saved.
1820 (gnus-dribble-touch)
1821 (gnus-agent-save-active method
))
1822 ;; Most backends have -retrieve-groups.
1823 ((gnus-check-backend-function 'retrieve-groups
(car method
))
1824 (when (gnus-check-backend-function 'request-scan
(car method
))
1825 (gnus-request-scan nil method
))
1827 (gnus-read-active-file-2
1828 (dolist (info infos
(nreverse groups
))
1829 (push (gnus-group-real-name (gnus-info-group info
)) groups
))
1831 ;; Virtually all backends have -request-list.
1832 ((gnus-check-backend-function 'request-list
(car method
))
1833 (gnus-read-active-file-1 method nil
))
1834 ;; Except nnvirtual and friends, where we request each group, one
1837 (dolist (info infos
)
1838 (gnus-activate-group (gnus-info-group info
) nil nil method t
))))))
1840 ;; Create a hash table out of the newsrc alist. The `car's of the
1841 ;; alist elements are used as keys.
1842 (defun gnus-make-hashtable-from-newsrc-alist ()
1843 (let ((alist gnus-newsrc-alist
)
1844 (ohashtb gnus-newsrc-hashtb
)
1845 prev info method rest methods
)
1846 (setq gnus-newsrc-hashtb
(gnus-make-hashtable (length alist
)))
1848 (setq prev
(setq gnus-newsrc-alist
1849 (if (equal (caar gnus-newsrc-alist
)
1852 (cons (list "dummy.group" 0 nil
) alist
)))))
1854 (setq info
(car alist
))
1855 ;; Make the same select-methods identical Lisp objects.
1856 (when (setq method
(gnus-info-method info
))
1857 (if (setq rest
(member method methods
))
1858 (gnus-info-set-method info
(car rest
))
1859 (push method methods
)))
1860 ;; Check for duplicates.
1861 (if (gnus-gethash (car info
) gnus-newsrc-hashtb
)
1862 ;; Remove this entry from the alist.
1863 (setcdr prev
(cddr prev
))
1866 ;; Preserve number of unread articles in groups.
1867 (cons (and ohashtb
(car (gnus-gethash (car info
) ohashtb
)))
1871 (setq alist
(cdr alist
)))
1872 ;; Make the same select-methods in `gnus-server-alist' identical
1875 (setq method
(pop methods
))
1876 (when (setq rest
(rassoc method gnus-server-alist
))
1877 (setcdr rest method
)))))
1879 (defun gnus-make-hashtable-from-killed ()
1880 "Create a hash table from the killed and zombie lists."
1881 (let ((lists '(gnus-killed-list gnus-zombie-list
))
1883 (setq gnus-killed-hashtb
1884 (gnus-make-hashtable
1885 (+ (length gnus-killed-list
) (length gnus-zombie-list
))))
1887 (setq list
(symbol-value (pop lists
)))
1889 (gnus-sethash (car list
) (pop list
) gnus-killed-hashtb
)))))
1891 (defun gnus-parse-active ()
1892 "Parse active info in the nntp server buffer."
1893 (with-current-buffer nntp-server-buffer
1894 (goto-char (point-min))
1895 ;; Parse the result we got from `gnus-request-group'.
1896 (when (looking-at "[0-9]+ [0-9]+ \\([0-9]+\\) [0-9]+")
1897 (goto-char (match-beginning 1))
1898 (cons (read (current-buffer))
1899 (read (current-buffer))))))
1901 (defun gnus-make-articles-unread (group articles
)
1902 "Mark ARTICLES in GROUP as unread."
1903 (let* ((info (nth 2 (or (gnus-group-entry group
)
1905 (gnus-group-real-name group
)))))
1906 (ranges (gnus-info-read info
))
1909 (when (gnus-member-of-range
1910 (setq article
(pop articles
)) ranges
)
1911 (push article news
)))
1913 ;; Enter this list into the group info.
1915 info
(gnus-remove-from-range (gnus-info-read info
) (nreverse news
)))
1917 ;; Set the number of unread articles in gnus-newsrc-hashtb.
1918 (gnus-get-unread-articles-in-group info
(gnus-active group
))
1920 ;; Insert the change into the group buffer and the dribble file.
1921 (gnus-group-update-group group t
))))
1923 (defun gnus-make-ascending-articles-unread (group articles
)
1924 "Mark ascending ARTICLES in GROUP as unread."
1925 (let* ((entry (or (gnus-group-entry group
)
1926 (gnus-group-entry (gnus-group-real-name group
))))
1927 (info (nth 2 entry
))
1928 (ranges (gnus-info-read info
))
1933 (let ((article (pop articles
))) ; get the next article to remove from ranges
1934 (while (let ((range (car ranges
))) ; note the current range
1935 (if (atom range
) ; single value range
1937 ;; the articles extend past the end of the ranges
1939 (setq articles nil
))
1941 ;; this range precedes the article. Leave the range unmodified.
1945 ;; this range exactly matches the article; REMOVE THE RANGE.
1946 ;; NOTE: When the range being removed is the last range, the list is corrupted by inserting null at its end.
1947 (setcar ranges
(cadr ranges
))
1948 (setcdr ranges
(cddr ranges
))
1949 (setq modified
(if (car ranges
) t
'remove-null
))
1951 (let ((min (car range
))
1953 ;; I have a min/max range to consider
1954 (cond ((> min max
) ; invalid range introduced by splitter
1955 (setcar ranges
(cadr ranges
))
1956 (setcdr ranges
(cddr ranges
))
1957 (setq modified
(if (car ranges
) t
'remove-null
))
1960 ;; replace min/max range with a single-value range
1964 ;; this range precedes the article. Leave the range unmodified.
1968 ;; this article precedes the range. Return null to move to the
1972 ;; this article splits the range into two parts
1973 (setcdr ranges
(cons (cons (1+ article
) max
) (cdr ranges
)))
1974 (setcdr range
(1- article
))
1979 (when (eq modified
'remove-null
)
1980 (setq r
(delq nil r
)))
1981 ;; Enter this list into the group info.
1982 (gnus-info-set-read info r
)
1984 ;; Set the number of unread articles in gnus-newsrc-hashtb.
1985 (gnus-get-unread-articles-in-group info
(gnus-active group
))
1987 ;; Insert the change into the group buffer and the dribble file.
1988 (gnus-group-update-group group t
))))
1990 ;; Enter all dead groups into the hashtb.
1991 (defun gnus-update-active-hashtb-from-killed ()
1992 (let ((hashtb (setq gnus-active-hashtb
(gnus-make-hashtable 4096)))
1993 (lists (list gnus-killed-list gnus-zombie-list
))
1996 (setq killed
(car lists
))
1998 (gnus-sethash (mm-string-as-unibyte (car killed
)) nil hashtb
)
1999 (setq killed
(cdr killed
)))
2000 (setq lists
(cdr lists
)))))
2002 (defun gnus-get-killed-groups ()
2003 "Go through the active hashtb and mark all unknown groups as killed."
2004 ;; First make sure active file has been read.
2005 (unless (gnus-read-active-file-p)
2006 (let ((gnus-read-active-file t
))
2007 (gnus-read-active-file)))
2008 (unless gnus-killed-hashtb
2009 (gnus-make-hashtable-from-killed))
2010 ;; Go through all newsgroups that are known to Gnus - enlarge kill list.
2014 (group (symbol-name sym
)))
2015 (if (or (null group
)
2016 (gnus-gethash group gnus-killed-hashtb
)
2017 (gnus-gethash group gnus-newsrc-hashtb
))
2019 (let ((do-sub (gnus-matches-options-n group
)))
2020 (if (or (eq do-sub
'subscribe
) (eq do-sub
'ignore
))
2022 (setq groups
(1+ groups
))
2023 (push group gnus-killed-list
)
2024 (gnus-sethash group group gnus-killed-hashtb
))))))
2026 (gnus-dribble-touch))
2028 ;; Get the active file(s) from the backend(s).
2029 (defun gnus-read-active-file (&optional force not-native
)
2030 (gnus-group-set-mode-line)
2033 (lambda (m) (if (stringp m
) (gnus-server-get-method nil m
) m
))
2035 (if (and (not not-native
)
2036 (gnus-check-server gnus-select-method
))
2037 ;; The native server is available.
2038 (cons gnus-select-method gnus-secondary-select-methods
)
2039 ;; The native server is down, so we just do the
2041 gnus-secondary-select-methods
)
2042 ;; Also read from the archive server.
2043 (when (gnus-archive-server-wanted-p)
2044 (list "archive")))))
2046 (setq gnus-have-read-active-file nil
)
2047 (with-current-buffer nntp-server-buffer
2048 (while (setq method
(pop methods
))
2049 ;; Only do each method once, in case the methods appear more
2050 ;; than once in this list.
2051 (when (and (not (member method methods
))
2052 ;; Check whether the backend exists.
2053 (ignore-errors (gnus-get-function method
'open-server
)))
2054 (if (or debug-on-error debug-on-quit
)
2055 (gnus-read-active-file-1 method force
)
2057 (gnus-read-active-file-1 method force
)
2058 ;; We catch C-g so that we can continue past servers
2059 ;; that do not respond.
2063 (message "Quit reading the active file"))
2066 (defun gnus-read-active-file-1 (method force
)
2068 (setq where
(nth 1 method
)
2069 mesg
(format "Reading active file%s via %s..."
2070 (if (and where
(not (zerop (length where
))))
2071 (concat " from " where
) "")
2073 (gnus-message 5 "%s" mesg
)
2074 (when (gnus-check-server method
)
2075 ;; Request that the backend scan its incoming messages.
2076 (when (and (or (and gnus-agent
2077 (gnus-online method
))
2079 (gnus-check-backend-function 'request-scan
(car method
)))
2080 (gnus-request-scan nil method
))
2082 ((and (eq gnus-read-active-file
'some
)
2083 (gnus-check-backend-function 'retrieve-groups
(car method
))
2085 (let ((newsrc (cdr gnus-newsrc-alist
))
2086 (gmethod (gnus-server-get-method nil method
))
2088 (while (setq info
(pop newsrc
))
2092 (gnus-find-method-for-group
2093 (gnus-info-group info
) info
))
2095 (push (gnus-group-real-name (gnus-info-group info
))
2097 (gnus-read-active-file-2 groups method
)))
2101 (if (not (gnus-request-list method
))
2102 (unless (equal method gnus-message-archive-method
)
2103 (gnus-error 1 "Cannot read active file from %s server"
2105 (gnus-message 5 "%s" mesg
)
2106 (gnus-active-to-gnus-format method gnus-active-hashtb nil t
)
2107 ;; We mark this active file as read.
2108 (add-to-list 'gnus-have-read-active-file method
)
2109 (gnus-message 5 "%sdone" mesg
)))))))
2111 (defun gnus-read-active-file-2 (groups method
)
2112 "Read an active file for GROUPS in METHOD using `gnus-retrieve-groups'."
2114 (with-current-buffer nntp-server-buffer
2115 (gnus-check-server method
)
2116 (let ((list-type (gnus-retrieve-groups groups method
)))
2117 (cond ((not list-type
)
2119 1.2 "Cannot read partial active file from %s server."
2121 ((eq list-type
'active
)
2122 (gnus-active-to-gnus-format method gnus-active-hashtb nil t
))
2124 (gnus-groups-to-gnus-format method gnus-active-hashtb t
)))))))
2126 ;; Read an active file and place the results in `gnus-active-hashtb'.
2127 (defun gnus-active-to-gnus-format (&optional method hashtb ignore-errors
2130 (setq method gnus-select-method
))
2131 (let ((cur (current-buffer))
2133 (if (and gnus-active-hashtb
2134 (not (equal method gnus-select-method
)))
2136 (setq gnus-active-hashtb
2137 (if (equal method gnus-select-method
)
2138 (gnus-make-hashtable
2139 (count-lines (point-min) (point-max)))
2140 (gnus-make-hashtable 4096))))))
2142 ;; Delete unnecessary lines.
2143 (goto-char (point-min))
2145 ((string= gnus-ignored-newsgroups
"")
2146 (delete-matching-lines "^to\\."))
2148 (delete-matching-lines (concat "^to\\.\\|" gnus-ignored-newsgroups
))))
2150 (goto-char (point-min))
2151 (unless (re-search-forward "[\\\"]" nil t
)
2152 ;; Make the group names readable as a lisp expression even if they
2153 ;; contain special characters.
2154 (goto-char (point-max))
2155 (while (re-search-backward "[][';?()#]" nil t
)
2158 ;; Let the Gnus agent save the active file.
2159 (when (and gnus-agent real-active
(gnus-online method
))
2160 (gnus-agent-save-active method
))
2162 ;; If these are groups from a foreign select method, we insert the
2163 ;; group prefix in front of the group names.
2164 (when (not (gnus-server-equal
2165 (gnus-server-get-method nil method
)
2166 (gnus-server-get-method nil gnus-select-method
)))
2167 (let ((prefix (gnus-group-prefixed-name "" method
)))
2168 (goto-char (point-min))
2169 (while (and (not (eobp))
2171 (when (= (following-char) ?
\")
2174 (zerop (forward-line 1)))))))
2175 ;; Store the active file in a hash table.
2176 ;; Use a unibyte buffer in order to make `read' read non-ASCII
2177 ;; group names (which have been encoded) as unibyte strings.
2178 (mm-with-unibyte-buffer
2179 (insert-buffer-substring cur
)
2180 (setq cur
(current-buffer))
2181 (goto-char (point-min))
2185 (narrow-to-region (point) (point-at-eol))
2186 ;; group gets set to a symbol interned in the hash table
2187 ;; (what a hack!!) - jwz
2188 (setq group
(let ((obarray hashtb
)) (read cur
)))
2189 ;; ### The extended group name scheme makes
2190 ;; the previous optimization strategy sort of pointless...
2191 (when (stringp group
)
2192 (setq group
(intern group hashtb
)))
2193 (if (and (numberp (setq max
(read cur
)))
2194 (numberp (setq min
(read cur
)))
2196 (skip-chars-forward " \t")
2198 (or (eq (char-after) ?
=)
2199 (eq (char-after) ?x
)
2200 (eq (char-after) ?j
)))))
2202 (set group
(cons min max
))
2203 ;; if group is moderated, stick in moderation table
2204 (when (eq (char-after) ?m
)
2205 (unless gnus-moderated-hashtb
2206 (setq gnus-moderated-hashtb
(gnus-make-hashtable)))
2207 (gnus-sethash (symbol-name group
) t
2208 gnus-moderated-hashtb
)))
2214 (unless ignore-errors
2215 (gnus-message 3 "Warning - invalid active: %s"
2217 (point-at-bol) (point-at-eol))))))
2219 (forward-line 1)))))
2221 (defun gnus-groups-to-gnus-format (method &optional hashtb real-active
)
2222 ;; Parse a "groups" active file.
2223 (let ((cur (current-buffer))
2225 (if (and method gnus-active-hashtb
)
2227 (setq gnus-active-hashtb
2228 (gnus-make-hashtable
2229 (count-lines (point-min) (point-max)))))))
2231 (not (gnus-server-equal
2232 (gnus-server-get-method nil method
)
2233 (gnus-server-get-method nil gnus-select-method
)))
2234 (gnus-group-prefixed-name "" method
))))
2236 ;; Let the Gnus agent save the active file.
2239 (gnus-online method
)
2240 (gnus-agent-method-p method
))
2242 (gnus-agent-save-active method t
)
2243 (gnus-active-to-gnus-format method hashtb nil real-active
))
2245 (goto-char (point-min))
2246 ;; We split this into to separate loops, one with the prefix
2247 ;; and one without to speed the reading up somewhat.
2249 (let (min max opoint group
)
2253 (read cur
) (read cur
)
2254 (setq min
(read cur
)
2257 (skip-chars-forward " \t")
2260 (set (let ((obarray hashtb
)) (read cur
))
2262 (error (and group
(symbolp group
) (set group nil
))))
2264 (let (min max group
)
2267 (when (eq (char-after) ?
2)
2268 (read cur
) (read cur
)
2269 (setq min
(read cur
)
2271 (set (setq group
(let ((obarray hashtb
)) (read cur
)))
2273 (error (and group
(symbolp group
) (set group nil
))))
2274 (forward-line 1)))))))
2276 (defun gnus-read-newsrc-file (&optional force
)
2278 If FORCE is non-nil, the .newsrc file is read."
2279 ;; Reset variables that might be defined in the .newsrc.eld file.
2280 (let ((variables (remove 'gnus-format-specs gnus-variable-list
)))
2282 (set (car variables
) nil
)
2283 (setq variables
(cdr variables
))))
2284 (let* ((newsrc-file gnus-current-startup-file
)
2285 (quick-file (concat newsrc-file
".el")))
2287 ;; We always load the .newsrc.eld file. If always contains
2288 ;; much information that can not be gotten from the .newsrc
2289 ;; file (ticked articles, killed groups, foreign methods, etc.)
2290 (gnus-read-newsrc-el-file quick-file
)
2292 (when (and gnus-read-newsrc-file
2293 (file-exists-p gnus-current-startup-file
)
2295 (and (file-newer-than-file-p newsrc-file quick-file
)
2296 (file-newer-than-file-p newsrc-file
2297 (concat quick-file
"d")))
2298 (not gnus-newsrc-alist
)))
2299 ;; We read the .newsrc file. Note that if there if a
2300 ;; .newsrc.eld file exists, it has already been read, and
2301 ;; the `gnus-newsrc-hashtb' has been created. While reading
2302 ;; the .newsrc file, Gnus will only use the information it
2303 ;; can find there for changing the data already read -
2304 ;; i. e., reading the .newsrc file will not trash the data
2305 ;; already read (except for read articles).
2307 (gnus-message 5 "Reading %s..." newsrc-file
)
2308 (set-buffer (nnheader-find-file-noselect newsrc-file
))
2309 (buffer-disable-undo)
2310 (gnus-newsrc-to-gnus-format)
2311 (kill-buffer (current-buffer))
2312 (gnus-message 5 "Reading %s...done" newsrc-file
)))
2314 ;; Convert old to new.
2315 (gnus-convert-old-newsrc)
2316 (gnus-clean-old-newsrc))))
2318 (defun gnus-clean-old-newsrc (&optional force
)
2319 ;; Currently no cleanups.
2322 (defun gnus-convert-old-newsrc ()
2323 "Convert old newsrc formats into the current format, if needed."
2324 (let ((fcv (and gnus-newsrc-file-version
2325 (gnus-continuum-version gnus-newsrc-file-version
)))
2326 (gcv (gnus-continuum-version)))
2328 ;; A newsrc file was loaded.
2329 (let (prompt-displayed
2332 (mapcar (lambda (date-func)
2333 (cons (gnus-continuum-version (car date-func
))
2335 ;; This is a list of converters that must be run
2336 ;; to bring the newsrc file up to the current
2337 ;; version. If you create an incompatibility
2338 ;; with older versions, you should create an
2339 ;; entry here. The entry should consist of the
2340 ;; current gnus version (hardcoded so that it
2341 ;; doesn't change with each release) and the
2342 ;; function that must be applied to convert the
2343 ;; previous version into the current version.
2344 '(("September Gnus v0.1" nil
2345 gnus-convert-old-ticks
)
2346 ("Oort Gnus v0.08" "legacy-gnus-agent"
2347 gnus-agent-convert-to-compressed-agentview
)
2348 ("Gnus v5.10.7" "legacy-gnus-agent"
2349 gnus-agent-unlist-expire-days
)
2350 ("Gnus v5.10.7" "legacy-gnus-agent"
2351 gnus-agent-unhook-expire-days
)))
2352 #'car-less-than-car
)))
2353 ;; Skip converters older than the file version
2354 (while (and converters
(>= fcv
(caar converters
)))
2357 ;; Perform converters to bring older version up to date.
2358 (when (and converters
(< fcv
(caar converters
)))
2359 (while (and converters
(< fcv
(caar converters
))
2360 (<= (caar converters
) gcv
))
2361 (let* ((converter-spec (pop converters
))
2362 (convert-to (nth 1 converter-spec
))
2363 (load-from (nth 2 converter-spec
))
2364 (func (nth 3 converter-spec
)))
2365 (when (and load-from
2366 (not (fboundp func
)))
2368 (or prompt-displayed
2369 (not (gnus-convert-converter-needs-prompt func
))
2371 (cursor-in-echo-area t
)
2372 (echo-keystrokes 0))
2373 (message "Convert gnus from version `%s' to `%s'? (n/y/?)"
2374 gnus-newsrc-file-version gnus-version
)
2375 (setq c
(read-char-exclusive))
2377 (cond ((or (eq c ?n
) (eq c ?N
))
2378 (error "Can not start gnus without converting"))
2379 ((or (eq c ?y
) (eq c ?Y
))
2380 (setq prompt-displayed t
)
2383 (message "This conversion is irreversible. \
2384 To be safe, you should backup your files before proceeding.")
2388 (gnus-message 3 "Ignoring unexpected input")
2392 (funcall func convert-to
)))
2394 (gnus-format-message ";Converted gnus from version `%s' to `%s'."
2395 gnus-newsrc-file-version gnus-version
)))))))
2397 (defun gnus-convert-mark-converter-prompt (converter no-prompt
)
2398 "Indicate whether CONVERTER requires gnus-convert-old-newsrc to
2399 display the conversion prompt. NO-PROMPT may be nil (prompt),
2400 t (no prompt), or any form that can be called as a function.
2401 The form should return either t or nil."
2402 (put converter
'gnus-convert-no-prompt no-prompt
))
2404 (defun gnus-convert-converter-needs-prompt (converter)
2405 (let ((no-prompt (get converter
'gnus-convert-no-prompt
)))
2406 (not (if (memq no-prompt
'(t nil
))
2408 (funcall no-prompt
)))))
2410 (defun gnus-convert-old-ticks (converting-to)
2411 (let ((newsrc (cdr gnus-newsrc-alist
))
2412 marks info dormant ticked
)
2413 (while (setq info
(pop newsrc
))
2414 (when (setq marks
(gnus-info-marks info
))
2415 (setq dormant
(cdr (assq 'dormant marks
))
2416 ticked
(cdr (assq 'tick marks
)))
2417 (when (or dormant ticked
)
2421 (gnus-info-read info
)
2422 (nconc (gnus-uncompress-range dormant
)
2423 (gnus-uncompress-range ticked
)))))))))
2425 (defun gnus-load (file)
2426 "Load FILE, but in such a way that read errors can be reported."
2428 (insert-file-contents file
)
2430 (condition-case type
2431 (let ((form (read (current-buffer))))
2434 (unless (eq (car type
) 'end-of-file
)
2435 (let ((errmsg (format "Error in %s line %d" file
2436 (count-lines (point-min) (point)))))
2438 (unless (gnus-yes-or-no-p (concat errmsg
"; continue? "))
2439 (error "%s" errmsg
)))))))))
2441 (defun gnus-read-newsrc-el-file (file)
2442 (let ((ding-file (concat file
"d")))
2443 (when (file-exists-p ding-file
)
2444 ;; We always, always read the .eld file.
2445 (gnus-message 5 "Reading %s..." ding-file
)
2446 (let (gnus-newsrc-assoc)
2447 (gnus-load ding-file
)
2448 ;; Older versions of `gnus-format-specs' are no longer valid
2449 ;; in Oort Gnus 0.01.
2451 (and gnus-newsrc-file-version
2452 (gnus-continuum-version gnus-newsrc-file-version
))))
2453 (when (or (not version
)
2454 (< version
5.090009))
2455 (setq gnus-format-specs gnus-default-format-specs
)))
2456 (when gnus-newsrc-assoc
2457 (setq gnus-newsrc-alist gnus-newsrc-assoc
))))
2458 (dolist (elem gnus-newsrc-alist
)
2459 ;; Protect against broken .newsrc.el files.
2461 (setcar elem
(mm-string-as-unibyte (car elem
)))))
2462 (gnus-make-hashtable-from-newsrc-alist)
2463 (when (file-newer-than-file-p file ding-file
)
2464 ;; Old format quick file
2465 (gnus-message 5 "Reading %s..." file
)
2466 ;; The .el file is newer than the .eld file, so we read that one
2468 (gnus-read-old-newsrc-el-file file
)))
2469 (gnus-run-hooks 'gnus-read-newsrc-el-hook
))
2471 ;; Parse the old-style quick startup file
2472 (defun gnus-read-old-newsrc-el-file (file)
2473 (let (newsrc killed marked group m info
)
2475 (let ((gnus-killed-assoc nil
)
2476 gnus-marked-assoc gnus-newsrc-alist gnus-newsrc-assoc
)
2480 (setq newsrc gnus-newsrc-assoc
2481 killed gnus-killed-assoc
2482 marked gnus-marked-assoc
)))
2483 (setq gnus-newsrc-alist nil
)
2484 (while (setq group
(pop newsrc
))
2485 (if (setq info
(gnus-get-info (car group
)))
2487 (gnus-info-set-read info
(cddr group
))
2488 (gnus-info-set-level
2489 info
(if (nth 1 group
) gnus-level-default-subscribed
2490 gnus-level-default-unsubscribed
))
2491 (push info gnus-newsrc-alist
))
2494 (if (nth 1 group
) gnus-level-default-subscribed
2495 gnus-level-default-unsubscribed
)
2498 ;; Copy marks into info.
2499 (when (setq m
(assoc (car group
) marked
))
2500 (unless (nthcdr 3 info
)
2501 (nconc info
(list nil
)))
2502 (gnus-info-set-marks
2503 info
(list (cons 'tick
(gnus-compress-sequence
2504 (sort (cdr m
) '<) t
))))))
2505 (setq newsrc killed
)
2507 (setcar newsrc
(caar newsrc
))
2508 (setq newsrc
(cdr newsrc
)))
2509 (setq gnus-killed-list killed
))
2510 ;; The .el file version of this variable does not begin with
2511 ;; "options", while the .eld version does, so we just add it if it
2515 (when (not (string-match "^ *options" gnus-newsrc-options
))
2516 (setq gnus-newsrc-options
(concat "options " gnus-newsrc-options
)))
2517 (when (not (string-match "\n$" gnus-newsrc-options
))
2518 (setq gnus-newsrc-options
(concat gnus-newsrc-options
"\n")))
2519 ;; Finally, if we read some options lines, we parse them.
2520 (unless (string= gnus-newsrc-options
"")
2521 (gnus-newsrc-parse-options gnus-newsrc-options
)))
2523 (setq gnus-newsrc-alist
(nreverse gnus-newsrc-alist
))
2524 (gnus-make-hashtable-from-newsrc-alist)))
2526 (defun gnus-make-newsrc-file (file)
2527 "Make server dependent file name by catenating FILE and server host name."
2528 (let* ((file (expand-file-name file nil
))
2529 (real-file (concat file
"-" (nth 1 gnus-select-method
))))
2530 (if (or (file-exists-p real-file
)
2531 (file-exists-p (concat real-file
".el"))
2532 (file-exists-p (concat real-file
".eld")))
2536 (defun gnus-newsrc-to-gnus-format ()
2537 (setq gnus-newsrc-options
"")
2538 (setq gnus-newsrc-options-n nil
)
2540 (unless gnus-active-hashtb
2541 (setq gnus-active-hashtb
(gnus-make-hashtable 4096)))
2542 (let ((buf (current-buffer))
2543 (already-read (> (length gnus-newsrc-alist
) 1))
2544 group subscribed options-symbol newsrc Options-symbol
2546 (goto-char (point-min))
2547 ;; We intern the symbol `options' in the active hashtb so that we
2548 ;; can `eq' against it later.
2549 (set (setq options-symbol
(intern "options" gnus-active-hashtb
)) nil
)
2550 (set (setq Options-symbol
(intern "Options" gnus-active-hashtb
)) nil
)
2553 ;; We first read the first word on the line by narrowing and
2554 ;; then reading into `gnus-active-hashtb'. Most groups will
2555 ;; already exist in that hashtb, so this will save some string
2559 (progn (skip-chars-forward "^ \t!:\n") (point)))
2560 (goto-char (point-min))
2562 (and (/= (point-min) (point-max))
2563 (let ((obarray gnus-active-hashtb
)) (read buf
))))
2565 ;; Now, the symbol we have read is either `options' or a group
2566 ;; name. If it is an options line, we just add it to a string.
2568 ((or (eq symbol options-symbol
)
2569 (eq symbol Options-symbol
))
2570 (setq gnus-newsrc-options
2571 ;; This concatting is quite inefficient, but since our
2572 ;; thorough studies show that approx 99.37% of all
2573 ;; .newsrc files only contain a single options line, we
2574 ;; don't give a damn, frankly, my dear.
2575 (concat gnus-newsrc-options
2578 ;; Options may continue on the next line.
2579 (or (and (re-search-forward "^[^ \t]" nil
'move
)
2584 ;; Group names can be just numbers.
2585 (when (numberp symbol
)
2586 (setq symbol
(intern (int-to-string symbol
) gnus-active-hashtb
)))
2587 (unless (boundp symbol
)
2589 ;; It was a group name.
2590 (setq subscribed
(eq (char-after) ?
:)
2591 group
(symbol-name symbol
)
2594 ;; If the line ends here, this is clearly a buggy line, so
2595 ;; we put point a the beginning of line and let the cond
2596 ;; below do the error handling.
2598 ;; We skip to the beginning of the ranges.
2599 (skip-chars-forward "!: \t"))
2600 ;; We are now at the beginning of the list of read articles.
2601 ;; We read them range by range.
2604 ((looking-at "[0-9]+")
2605 ;; We narrow and read a number instead of buffer-substring/
2606 ;; string-to-number because it's faster. narrow/widen is
2607 ;; faster than save-restriction/narrow, and save-restriction
2608 ;; produces a garbage object.
2610 (narrow-to-region (match-beginning 0) (match-end 0))
2613 ;; If the next character is a dash, then this is a range.
2614 (if (eq (char-after) ?-
)
2616 ;; We read the upper bound of the range.
2618 (if (not (looking-at "[0-9]+"))
2619 ;; This is a buggy line, by we pretend that
2620 ;; it's kinda OK. Perhaps the user should be
2626 (narrow-to-region (match-beginning 0)
2631 ;; It was just a simple number, so we add it to the
2634 ;; If the next char in ?\n, then we have reached the end
2635 ;; of the line and return nil.
2636 (not (eq (char-after) ?
\n)))
2637 ((eq (char-after) ?
\n)
2638 ;; End of line, so we end.
2641 ;; Not numbers and not eol, so this might be a buggy
2644 ;; If it was eob instead of ?\n, we allow it.
2645 ;; The line was buggy.
2647 (gnus-error 3.1 "Mangled line: %s"
2648 (buffer-substring (point-at-bol)
2651 ;; Skip past ", ". Spaces are invalid in these ranges, but
2652 ;; we allow them, because it's a common mistake to put a
2653 ;; space after the comma.
2654 (skip-chars-forward ", "))
2656 ;; We have already read .newsrc.eld, so we gently update the
2657 ;; data in the hash table with the information we have just
2660 (let ((info (gnus-get-info group
))
2663 ;; There is an entry for this file in the alist.
2665 (gnus-info-set-read info
(nreverse reads
))
2666 ;; We update the level very gently. In fact, we
2667 ;; only change it if there's been a status change
2668 ;; from subscribed to unsubscribed, or vice versa.
2669 (setq level
(gnus-info-level info
))
2670 (cond ((and (<= level gnus-level-subscribed
)
2672 (setq level
(if reads
2673 gnus-level-default-unsubscribed
2674 (1+ gnus-level-default-unsubscribed
))))
2675 ((and (> level gnus-level-subscribed
) subscribed
)
2676 (setq level gnus-level-default-subscribed
)))
2677 (gnus-info-set-level info level
))
2678 ;; This is a new group.
2679 (setq info
(list group
2681 gnus-level-default-subscribed
2683 (1+ gnus-level-subscribed
)
2684 gnus-level-default-unsubscribed
))
2686 (push info newsrc
)))))
2689 (setq newsrc
(nreverse newsrc
))
2691 (if (not already-read
)
2693 ;; We now have two newsrc lists - `newsrc', which is what we
2694 ;; have read from .newsrc, and `gnus-newsrc-alist', which is
2695 ;; what we've read from .newsrc.eld. We have to merge these
2696 ;; lists. We do this by "attaching" any (foreign) groups in the
2697 ;; gnus-newsrc-alist to the (native) group that precedes them.
2698 (let ((rc (cdr gnus-newsrc-alist
))
2699 (prev gnus-newsrc-alist
)
2702 (or (null (nth 4 (car rc
))) ; It's a native group.
2703 (assoc (caar rc
) newsrc
) ; It's already in the alist.
2704 (if (setq entry
(assoc (caar prev
) newsrc
))
2705 (setcdr (setq mentry
(memq entry newsrc
))
2706 (cons (car rc
) (cdr mentry
)))
2707 (push (car rc
) newsrc
)))
2711 (setq gnus-newsrc-alist newsrc
)
2712 ;; We make the newsrc hashtb.
2713 (gnus-make-hashtable-from-newsrc-alist)
2715 ;; Finally, if we read some options lines, we parse them.
2716 (unless (string= gnus-newsrc-options
"")
2717 (gnus-newsrc-parse-options gnus-newsrc-options
))))
2719 ;; Parse options lines to find "options -n !all rec.all" and stuff.
2720 ;; The return value will be a list on the form
2721 ;; ((regexp1 . ignore)
2722 ;; (regexp2 . subscribe)...)
2723 ;; When handling new newsgroups, groups that match a `ignore' regexp
2724 ;; will be ignored, and groups that match a `subscribe' regexp will be
2725 ;; subscribed. A line like
2726 ;; options -n !all rec.all
2727 ;; will lead to a list that looks like
2728 ;; (("^rec\\..+" . subscribe)
2729 ;; ("^.+" . ignore))
2730 ;; So all "rec.*" groups will be subscribed, while all the other
2731 ;; groups will be ignored. Note that "options -n !all rec.all" is very
2732 ;; different from "options -n rec.all !all".
2733 (defun gnus-newsrc-parse-options (options)
2736 (gnus-set-work-buffer)
2737 (insert (regexp-quote options
))
2738 ;; First we treat all continuation lines.
2739 (goto-char (point-min))
2740 (while (re-search-forward "\n[ \t]+" nil t
)
2741 (replace-match " " t t
))
2742 ;; Then we transform all "all"s into ".+"s.
2743 (goto-char (point-min))
2744 (while (re-search-forward "\\ball\\b" nil t
)
2745 (replace-match ".+" t t
))
2746 (goto-char (point-min))
2747 ;; We remove all other options than the "-n" ones.
2748 (while (re-search-forward "[ \t]-[^n][^-]*" nil t
)
2751 (goto-char (point-min))
2753 ;; We are only interested in "options -n" lines - we
2754 ;; ignore the other option lines.
2755 (while (re-search-forward "[ \t]-n" nil t
)
2758 (and (re-search-forward "[ \t]-n" (point-at-eol) t
)
2761 ;; Search for all "words"...
2762 (while (re-search-forward "[^ \t,\n]+" eol t
)
2763 (if (eq (char-after (match-beginning 0)) ?
!)
2764 ;; If the word begins with a bang (!), this is a "not"
2765 ;; spec. We put this spec (minus the bang) and the
2766 ;; symbol `ignore' into the list.
2768 "^" (buffer-substring
2769 (1+ (match-beginning 0))
2774 ;; There was no bang, so this is a "yes" spec.
2775 (push (cons (concat "^" (match-string 0) "\\($\\|\\.\\)")
2779 (setq gnus-newsrc-options-n out
))))
2782 (defalias 'gnus-long-file-names
2783 (if (fboundp 'msdos-long-file-names
)
2784 'msdos-long-file-names
2787 (defvar gnus-save-newsrc-file-last-timestamp nil
)
2788 (defun gnus-save-newsrc-file (&optional force
)
2789 "Save .newsrc file."
2790 ;; Note: We cannot save .newsrc file if all newsgroups are removed
2791 ;; from the variable gnus-newsrc-alist.
2792 (when (and (or gnus-newsrc-alist gnus-killed-list
)
2793 gnus-current-startup-file
)
2794 ;; Save agent range limits for the currently active method.
2796 (gnus-agent-save-local force
))
2799 (if (and (or gnus-use-dribble-file gnus-slave
)
2801 (or (not gnus-dribble-buffer
)
2802 (not (buffer-name gnus-dribble-buffer
))
2803 (zerop (with-current-buffer gnus-dribble-buffer
2805 (gnus-message 4 "(No changes need to be saved)")
2806 (gnus-run-hooks 'gnus-save-newsrc-hook
)
2808 (gnus-slave-save-newsrc)
2810 (when gnus-save-newsrc-file
2811 (gnus-message 8 "Saving %s..." gnus-current-startup-file
)
2812 (gnus-gnus-to-newsrc-format)
2813 (gnus-message 8 "Saving %s...done" gnus-current-startup-file
))
2815 ;; Save .newsrc.eld.
2816 (set-buffer (gnus-get-buffer-create " *Gnus-newsrc*"))
2817 (make-local-variable 'version-control
)
2818 (setq version-control gnus-backup-startup-file
)
2819 (setq buffer-file-name
2820 (concat gnus-current-startup-file
".eld"))
2821 (setq default-directory
(file-name-directory buffer-file-name
))
2822 (buffer-disable-undo)
2824 (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file
)
2826 ;; check timestamp of `gnus-current-startup-file'.eld against
2827 ;; `gnus-save-newsrc-file-last-timestamp'
2828 (let* ((checkfile (concat gnus-current-startup-file
".eld"))
2829 (mtime (nth 5 (file-attributes checkfile
))))
2830 (when (and gnus-save-newsrc-file-last-timestamp
2831 (time-less-p gnus-save-newsrc-file-last-timestamp
2834 (format "%s was updated externally after %s, save?"
2838 gnus-save-newsrc-file-last-timestamp
)))
2839 (error "Couldn't save %s: updated externally" checkfile
))))
2841 (if gnus-save-startup-file-via-temp-buffer
2842 (let ((coding-system-for-write gnus-ding-file-coding-system
)
2843 (standard-output (current-buffer)))
2844 (gnus-gnus-to-quick-newsrc-format)
2845 (gnus-run-hooks 'gnus-save-quick-newsrc-hook
)
2847 (setq gnus-save-newsrc-file-last-timestamp
2848 (nth 5 (file-attributes buffer-file-name
))))
2849 (let ((coding-system-for-write gnus-ding-file-coding-system
)
2850 (version-control gnus-backup-startup-file
)
2851 (startup-file (concat gnus-current-startup-file
".eld"))
2852 (working-dir (file-name-directory gnus-current-startup-file
))
2855 ;; Generate the name of a non-existent file.
2856 (while (progn (setq working-file
2858 (if (and (eq system-type
'ms-dos
)
2859 (not (gnus-long-file-names)))
2860 "%s#%d.tm#" ; MSDOS limits files to 8+3
2862 working-dir
(setq i
(1+ i
))))
2863 (file-exists-p working-file
)))
2867 (gnus-with-output-to-file working-file
2868 (gnus-gnus-to-quick-newsrc-format)
2869 (gnus-run-hooks 'gnus-save-quick-newsrc-hook
))
2871 ;; These bindings will mislead the current buffer
2872 ;; into thinking that it is visiting the startup
2874 (let ((buffer-backed-up nil
)
2875 (buffer-file-name startup-file
)
2876 (file-precious-flag t
)
2877 (setmodes (file-modes startup-file
)))
2878 ;; Backup the current version of the startup file.
2881 ;; Replace the existing startup file with the temp file.
2882 (rename-file working-file startup-file t
)
2883 (gnus-set-file-modes startup-file setmodes
)
2884 (setq gnus-save-newsrc-file-last-timestamp
2885 (nth 5 (file-attributes startup-file
)))))
2887 (delete-file working-file
)
2888 (file-error nil
)))))
2890 (gnus-kill-buffer (current-buffer))
2892 5 "Saving %s.eld...done" gnus-current-startup-file
))
2893 (gnus-dribble-delete-file)
2894 (gnus-group-set-mode-line)))))
2896 (defun gnus-gnus-to-quick-newsrc-format (&optional minimal name
&rest specific-variables
)
2897 "Print Gnus variables such as `gnus-newsrc-alist' in Lisp format."
2898 (princ (format ";; -*- mode:emacs-lisp; coding: %s; -*-\n"
2899 gnus-ding-file-coding-system
))
2901 (princ (format ";; %s\n" name
))
2902 (princ ";; Gnus startup file.\n"))
2906 ;; Never delete this file -- if you want to force Gnus to read the
2907 ;; .newsrc file (if you have one), touch .newsrc instead.\n")
2908 (princ "(setq gnus-newsrc-file-version ")
2909 (princ (gnus-prin1-to-string gnus-version
))
2912 (let* ((print-quoted t
)
2914 (print-escape-multibyte nil
)
2915 (print-escape-nonascii t
)
2919 (print-escape-newlines t
)
2921 (if (and gnus-save-killed-list
2922 (stringp gnus-save-killed-list
))
2923 (gnus-strip-killed-list)
2926 (or specific-variables
2927 (if gnus-save-killed-list gnus-variable-list
2928 ;; Remove the `gnus-killed-list' from the list of variables
2929 ;; to be saved, if required.
2930 (delq 'gnus-killed-list
(copy-sequence gnus-variable-list
)))))
2931 ;; Peel off the "dummy" group.
2932 (gnus-newsrc-alist (cdr gnus-newsrc-alist
))
2934 ;; Insert the variables into the file.
2936 (when (and (boundp (setq variable
(pop variables
)))
2937 (symbol-value variable
))
2939 (princ (symbol-name variable
))
2941 (prin1 (symbol-value variable
))
2944 (defun gnus-strip-killed-list ()
2945 "Return the killed list minus the groups that match `gnus-save-killed-list'."
2946 (let ((list gnus-killed-list
)
2949 (when (string-match gnus-save-killed-list
(car list
))
2950 (push (car list
) olist
))
2954 (defun gnus-gnus-to-newsrc-format (&optional foreign-ok
)
2955 (interactive (list (gnus-y-or-n-p "write foreign groups too? ")))
2956 ;; Generate and save the .newsrc file.
2957 (with-current-buffer (create-file-buffer gnus-current-startup-file
)
2958 (let ((newsrc (cdr gnus-newsrc-alist
))
2959 (standard-output (current-buffer))
2960 info ranges range method
)
2961 (setq buffer-file-name gnus-current-startup-file
)
2962 (setq default-directory
(file-name-directory buffer-file-name
))
2963 (buffer-disable-undo)
2965 ;; Use a unibyte buffer since group names are unibyte strings;
2966 ;; in particular, non-ASCII group names are the ones encoded by
2967 ;; a certain coding system.
2968 (mm-disable-multibyte)
2970 (when gnus-newsrc-options
2971 (insert gnus-newsrc-options
))
2972 ;; Write subscribed and unsubscribed.
2973 (while (setq info
(pop newsrc
))
2974 ;; Don't write foreign groups to .newsrc.
2975 (when (or (null (setq method
(gnus-info-method info
)))
2976 (equal method
"native")
2977 (inline (gnus-server-equal method gnus-select-method
))
2979 (insert (gnus-info-group info
)
2980 (if (> (gnus-info-level info
) gnus-level-subscribed
)
2982 (when (setq ranges
(gnus-info-read info
))
2984 (if (not (listp (cdr ranges
)))
2985 (if (= (car ranges
) (cdr ranges
))
2986 (princ (car ranges
))
2987 (princ (car ranges
))
2989 (princ (cdr ranges
)))
2990 (while (setq range
(pop ranges
))
2991 (if (or (atom range
) (= (car range
) (cdr range
)))
2992 (princ (or (and (atom range
) range
) (car range
)))
2995 (princ (cdr range
)))
2999 (make-local-variable 'version-control
)
3000 (setq version-control
'never
)
3001 ;; It has been reported that sometime the modtime on the .newsrc
3002 ;; file seems to be off. We really do want to overwrite it, so
3003 ;; we clear the modtime here before saving. It's a bit odd,
3005 ;; sometimes the modtime clear isn't sufficient. most brute force:
3006 ;; delete the silly thing entirely first. but this fails to provide
3007 ;; such niceties as .newsrc~ creation.
3008 (if gnus-modtime-botch
3009 (delete-file gnus-startup-file
)
3010 (clear-visited-file-modtime))
3011 (gnus-run-hooks 'gnus-save-standard-newsrc-hook
)
3012 (let ((coding-system-for-write 'raw-text
))
3014 (kill-buffer (current-buffer)))))
3018 ;;; Slave functions.
3021 (defvar gnus-slave-mode nil
)
3023 (defun gnus-slave-mode ()
3024 "Minor mode for slave Gnusae."
3025 ;; FIXME: gnus-slave-mode appears to never be set (i.e. it'll always be nil):
3026 ;; Remove, or fix and use define-minor-mode.
3027 (add-minor-mode 'gnus-slave-mode
" Slave" (make-sparse-keymap))
3028 (gnus-run-hooks 'gnus-slave-mode-hook
))
3030 (defun gnus-slave-save-newsrc ()
3031 (with-current-buffer gnus-dribble-buffer
3033 (mm-make-temp-file (concat gnus-current-startup-file
"-slave-")))
3034 (modes (ignore-errors
3035 (file-modes (concat gnus-current-startup-file
".eld")))))
3036 (let ((coding-system-for-write gnus-ding-file-coding-system
))
3037 (gnus-write-buffer slave-name
))
3039 (gnus-set-file-modes slave-name modes
)))))
3041 (defun gnus-master-read-slave-newsrc ()
3044 (file-name-directory gnus-current-startup-file
)
3048 (file-name-nondirectory gnus-current-startup-file
)
3052 (if (not slave-files
)
3053 () ; There are no slave files to read.
3054 (gnus-message 7 "Reading slave newsrcs...")
3055 (with-current-buffer (gnus-get-buffer-create " *gnus slave*")
3057 (sort (mapcar (lambda (file)
3058 (list (nth 5 (file-attributes file
)) file
))
3061 (or (< (caar f1
) (caar f2
))
3062 (< (nth 1 (car f1
)) (nth 1 (car f2
)))))))
3065 (setq file
(nth 1 (car slave-files
)))
3066 (nnheader-insert-file-contents file
)
3067 (when (condition-case ()
3069 (eval-buffer (current-buffer))
3072 (gnus-error 3.2 "Possible error in %s" file
)
3074 (unless gnus-slave
; Slaves shouldn't delete these files.
3076 (delete-file file
))))
3077 (setq slave-files
(cdr slave-files
))))
3078 (gnus-dribble-touch)
3079 (gnus-message 7 "Reading slave newsrcs...done"))))
3083 ;;; Group description.
3086 (defun gnus-read-all-descriptions-files ()
3087 (let ((methods (cons gnus-select-method
3089 (when (gnus-archive-server-wanted-p)
3091 gnus-secondary-select-methods
))))
3093 (gnus-read-descriptions-file (car methods
))
3094 (setq methods
(cdr methods
)))
3097 (defun gnus-read-descriptions-file (&optional method
)
3098 (let ((method (or method gnus-select-method
))
3100 (when (stringp method
)
3101 (setq method
(gnus-server-to-method method
)))
3102 ;; We create the hashtable whether we manage to read the desc file
3103 ;; to avoid trying to re-read after a failed read.
3104 (unless gnus-description-hashtb
3105 (setq gnus-description-hashtb
3106 (gnus-make-hashtable (length gnus-active-hashtb
))))
3107 ;; Mark this method's desc file as read.
3108 (gnus-sethash (gnus-group-prefixed-name "" method
) "Has read"
3109 gnus-description-hashtb
)
3111 (gnus-message 5 "Reading descriptions file via %s..." (car method
))
3113 ((null (gnus-get-function method
'request-list-newsgroups t
))
3115 ((not (gnus-check-server method
))
3116 (gnus-message 1 "Couldn't open server")
3118 ((not (gnus-request-list-newsgroups method
))
3119 (gnus-message 1 "Couldn't read newsgroups descriptions")
3123 ;; FIXME: Shouldn't save-restriction be done after set-buffer?
3125 (set-buffer nntp-server-buffer
)
3126 (goto-char (point-min))
3127 (when (or (search-forward "\n.\n" nil t
)
3128 (goto-char (point-max)))
3130 (narrow-to-region (point-min) (point)))
3131 ;; If these are groups from a foreign select method, we insert the
3132 ;; group prefix in front of the group names.
3133 (and method
(not (inline
3135 (gnus-server-get-method nil method
)
3136 (gnus-server-get-method
3137 nil gnus-select-method
))))
3138 (let ((prefix (gnus-group-prefixed-name "" method
)))
3139 (goto-char (point-min))
3140 (while (and (not (eobp))
3141 (progn (insert prefix
)
3142 (zerop (forward-line 1)))))))
3143 (goto-char (point-min))
3145 ;; If we get an error, we set group to 0, which is not a
3149 (let ((obarray gnus-description-hashtb
))
3150 ;; Group is set to a symbol interned in this
3152 (read nntp-server-buffer
))
3154 (skip-chars-forward " \t")
3155 ;; ... which leads to this line being effectively ignored.
3156 (when (symbolp group
)
3157 (let* ((str (buffer-substring
3158 (point) (progn (end-of-line) (point))))
3159 (name (symbol-name group
))
3161 (or (gnus-group-name-charset method name
)
3162 (gnus-parameter-charset name
)
3163 gnus-default-charset
)))
3164 ;; Fixme: Don't decode in unibyte mode.
3165 (when (and str charset
(featurep 'mule
))
3166 (setq str
(mm-decode-coding-string str charset
)))
3169 (gnus-message 5 "Reading descriptions file...done")
3172 (defun gnus-group-get-description (group)
3173 "Get the description of a group by sending XGTITLE to the server."
3174 (when (gnus-request-group-description group
)
3175 (with-current-buffer nntp-server-buffer
3176 (goto-char (point-min))
3177 (when (looking-at "[^ \t]+[ \t]+\\(.*\\)")
3178 (match-string 1)))))
3181 (defun gnus-declare-backend (name &rest abilities
)
3182 "Declare back end NAME with ABILITIES as a Gnus back end."
3183 (setq gnus-valid-select-methods
3184 (nconc gnus-valid-select-methods
3185 (list (apply 'list name abilities
))))
3186 (gnus-redefine-select-method-widget))
3188 (defun gnus-set-default-directory ()
3189 "Set the default directory in the current buffer to `gnus-default-directory'.
3190 If this variable is nil, don't do anything."
3191 (setq default-directory
3192 (if (and gnus-default-directory
3193 (file-exists-p gnus-default-directory
))
3194 (file-name-as-directory (expand-file-name gnus-default-directory
))
3195 default-directory
)))
3197 (defun gnus-display-time-event-handler ()
3198 (if (and (fboundp 'display-time-event-handler
)
3199 (gnus-boundp 'display-time-timer
))
3200 (display-time-event-handler)))
3202 (defun gnus-check-reasonable-setup ()
3203 ;; Check whether nnml and nnfolder share a directory.
3205 (if (fboundp 'display-warning
)
3207 (lambda (type message
)
3209 (message "Warning (%s): %s" type message
)
3211 (with-current-buffer (get-buffer-create "*Warnings*")
3212 (goto-char (point-max))
3215 (insert (format "Warning (%s): %s\n" type message
))
3216 (setq window
(display-buffer (current-buffer)))
3220 (forward-line (- 1 (window-height window
)))
3222 (goto-char (point-max))))))))))
3223 method active actives match
)
3224 (dolist (server gnus-server-alist
)
3225 (setq method
(gnus-server-to-method server
)
3226 active
(intern (format "%s-active-file" (car method
))))
3227 (when (and (member (car method
) '(nnml nnfolder
))
3228 (gnus-server-opened method
)
3230 (when (setq match
(assoc (symbol-value active
) actives
))
3231 (funcall display-warn
'gnus-server
3232 (format "%s and %s share the same active file %s"
3236 (push (list (symbol-value active
) method
) actives
)))))
3238 (provide 'gnus-start
)
3240 ;;; gnus-start.el ends here