1 ;;; gnus-start.el --- startup functions for Gnus
3 ;; Copyright (C) 1996-2013 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/>.
33 (autoload 'message-make-date
"message")
34 (autoload 'gnus-agent-read-servers-validate
"gnus-agent")
35 (autoload 'gnus-agent-save-local
"gnus-agent")
36 (autoload 'gnus-agent-possibly-alter-active
"gnus-agent")
41 (defvar gnus-agent-covered-methods
)
42 (defvar gnus-agent-file-loading-local
)
43 (defvar gnus-agent-file-loading-cache
)
45 (defcustom gnus-startup-file
(nnheader-concat gnus-home-directory
".newsrc")
47 `.newsrc-SERVER' will be used instead if that exists."
51 (defcustom gnus-backup-startup-file
'never
52 "Control use of version numbers for backups of `gnus-startup-file'.
53 This variable takes the same values as the `version-control'
57 :type
'(choice (const :tag
"Never" never
)
58 (const :tag
"If existing" nil
)
59 (other :tag
"Always" t
)))
61 (defcustom gnus-save-startup-file-via-temp-buffer t
62 "Whether to write the startup file contents to a buffer then save
63 the buffer or write directly to the file. The buffer is faster
64 because all of the contents are written at once. The direct write
65 uses considerably less memory."
68 :type
'(choice (const :tag
"Write via buffer" t
)
69 (const :tag
"Write directly to file" nil
)))
71 (defcustom gnus-init-file
(nnheader-concat gnus-home-directory
".gnus")
72 "Your Gnus Emacs-Lisp startup file name.
73 If a file with the `.el' or `.elc' suffixes exists, it will be read instead."
77 (defcustom gnus-site-init-file
79 (concat (file-name-directory
80 (directory-file-name installation-directory
))
81 "site-lisp/gnus-init")
83 "The site-wide Gnus Emacs-Lisp startup file name, or nil if none.
84 If a file with the `.el' or `.elc' suffixes exists, it will be read instead."
86 :type
'(choice file
(const nil
)))
88 (defcustom gnus-use-dribble-file t
89 "*Non-nil means that Gnus will use a dribble file to store user updates.
90 If Emacs should crash without saving the .newsrc files, complete
91 information can be restored from the dribble file."
92 :group
'gnus-dribble-file
95 (defcustom gnus-dribble-directory nil
96 "*The directory where dribble files will be saved.
97 If this variable is nil, the directory where the .newsrc files are
99 :group
'gnus-dribble-file
100 :type
'(choice directory
(const nil
)))
102 (defcustom gnus-check-new-newsgroups
'ask-server
103 "*Non-nil means that Gnus will run `gnus-find-new-newsgroups' at startup.
104 This normally finds new newsgroups by comparing the active groups the
105 servers have already reported with those Gnus already knows, either alive
108 When any of the following are true, `gnus-find-new-newsgroups' will instead
109 ask the servers (primary, secondary, and archive servers) to list new
110 groups since the last time it checked:
111 1. This variable is `ask-server'.
112 2. This variable is a list of select methods (see below).
113 3. Option `gnus-read-active-file' is nil or `some'.
114 4. A prefix argument is given to `gnus-find-new-newsgroups' interactively.
116 Thus, if this variable is `ask-server' or a list of select methods or
117 `gnus-read-active-file' is nil or `some', then the killed list is no
118 longer necessary, so you could safely set `gnus-save-killed-list' to nil.
120 This variable can be a list of select methods which Gnus will query with
121 the `ask-server' method in addition to the primary, secondary, and archive
125 (setq gnus-check-new-newsgroups
126 '((nntp \"some.server\") (nntp \"other.server\")))
128 If this variable is nil, then you have to tell Gnus explicitly to
129 check for new newsgroups with \\<gnus-group-mode-map>\\[gnus-find-new-newsgroups]."
131 :type
'(choice (const :tag
"no" nil
)
132 (const :tag
"by brute force" t
)
133 (const :tag
"ask servers" ask-server
)
134 (repeat :menu-tag
"ask additional servers"
135 :tag
"ask additional servers"
137 (sexp :format
"%v"))))
139 (defcustom gnus-check-bogus-newsgroups nil
140 "*Non-nil means that Gnus will check and remove bogus newsgroup at startup.
141 If this variable is nil, then you have to tell Gnus explicitly to
142 check for bogus newsgroups with \\<gnus-group-mode-map>\\[gnus-group-check-bogus-groups]."
143 :group
'gnus-start-server
146 (defcustom gnus-read-active-file
'some
147 "*Non-nil means that Gnus will read the entire active file at startup.
148 If this variable is nil, Gnus will only know about the groups in your
151 If this variable is `some', Gnus will try to only read the relevant
152 parts of the active file from the server. Not all servers support
153 this, and it might be quite slow with other servers, but this should
154 generally be faster than both the t and nil value.
156 If you set this variable to nil or `some', you probably still want to
157 be told about new newsgroups that arrive. To do that, set
158 `gnus-check-new-newsgroups' to `ask-server'. This may not work
159 properly with all servers."
160 :group
'gnus-start-server
161 :type
'(choice (const nil
)
165 (defconst gnus-level-subscribed
5
166 "Groups with levels less than or equal to this variable are subscribed.")
168 (defconst gnus-level-unsubscribed
7
169 "Groups with levels less than or equal to this variable are unsubscribed.
171 Groups with levels less than `gnus-level-subscribed', which
172 should be less than this variable, are subscribed. Groups with
173 levels from `gnus-level-subscribed' (exclusive) upto this
174 variable (inclusive) are unsubscribed. See also
175 `gnus-level-zombie', `gnus-level-killed' and the Info node `(gnus)Group
176 Levels' for details.")
178 (defconst gnus-level-zombie
8
179 "Groups with this level are zombie groups.")
181 (defconst gnus-level-killed
9
182 "Groups with this level are killed.")
184 (defcustom gnus-level-default-subscribed
3
185 "*New subscribed groups will be subscribed at this level."
186 :group
'gnus-group-levels
189 (defcustom gnus-level-default-unsubscribed
6
190 "*New unsubscribed groups will be unsubscribed at this level."
191 :group
'gnus-group-levels
194 (defcustom gnus-activate-level
(1+ gnus-level-subscribed
)
195 "*Groups higher than this level won't be activated on startup.
196 Setting this variable to something low might save lots of time when
197 you have many groups that you aren't interested in."
198 :group
'gnus-group-levels
201 (defcustom gnus-activate-foreign-newsgroups
4
202 "*If nil, Gnus will not check foreign newsgroups at startup.
203 If it is non-nil, it should be a number between one and nine. Foreign
204 newsgroups that have a level lower or equal to this number will be
205 activated on startup. For instance, if you want to active all
206 subscribed newsgroups, but not the rest, you'd set this variable to
207 `gnus-level-subscribed'.
209 If you subscribe to lots of newsgroups from different servers, startup
210 might take a while. By setting this variable to nil, you'll save time,
211 but you won't be told how many unread articles there are in the
213 :group
'gnus-group-levels
214 :type
'(choice integer
215 (const :tag
"none" nil
)))
217 (defcustom gnus-read-newsrc-file t
218 "*Non-nil means that Gnus will read the `.newsrc' file.
219 Gnus always reads its own startup file, which is called
220 \".newsrc.eld\". The file called \".newsrc\" is in a format that can
221 be readily understood by other newsreaders. If you don't plan on
222 using other newsreaders, set this variable to nil to save some time on
228 (defcustom gnus-save-newsrc-file t
229 "*Non-nil means that Gnus will save the `.newsrc' file.
230 Gnus always saves its own startup file, which is called
231 \".newsrc.eld\". The file called \".newsrc\" is in a format that can
232 be readily understood by other newsreaders. If you don't plan on
233 using other newsreaders, set this variable to nil to save some time on
238 (defcustom gnus-save-killed-list t
239 "*If non-nil, save the list of killed groups to the startup file.
240 If you set this variable to nil, you'll save both time (when starting
241 and quitting) and space (both memory and disk), but it will also mean
242 that Gnus has no record of which groups are new and which are old, so
243 the automatic new newsgroups subscription methods become meaningless.
245 You should always set `gnus-check-new-newsgroups' to `ask-server' or
246 nil if you set this variable to nil.
248 This variable can also be a regexp. In that case, all groups that do
249 not match this regexp will be removed before saving the list."
251 :type
'(radio (sexp :format
"Non-nil\n"
252 :match
(lambda (widget value
)
253 (and value
(not (stringp value
))))
258 (defcustom gnus-ignored-newsgroups
260 '("^to\\." ; not "real" groups
261 "^[0-9. \t]+\\( \\|$\\)" ; all digits in name
262 "^[\"][\"#'()]" ; bogus characters
265 "*A regexp to match uninteresting newsgroups in the active file.
266 Any lines in the active file matching this regular expression are
267 removed from the newsgroup list before anything else is done to it,
268 thus making them effectively non-existent."
269 :group
'gnus-group-new
272 (defcustom gnus-subscribe-newsgroup-method
'gnus-subscribe-zombies
273 "*Function(s) called with a group name when new group is detected.
274 A few pre-made functions are supplied: `gnus-subscribe-randomly'
275 inserts new groups at the beginning of the list of groups;
276 `gnus-subscribe-alphabetically' inserts new groups in strict
277 alphabetic order; `gnus-subscribe-hierarchically' inserts new groups
278 in hierarchical newsgroup order; `gnus-subscribe-interactively' asks
279 for your decision; `gnus-subscribe-killed' kills all new groups;
280 `gnus-subscribe-zombies' will make all new groups into zombies;
281 `gnus-subscribe-topics' will enter groups into the topics that
283 :group
'gnus-group-new
284 :type
'(radio (function-item gnus-subscribe-randomly
)
285 (function-item gnus-subscribe-alphabetically
)
286 (function-item gnus-subscribe-hierarchically
)
287 (function-item gnus-subscribe-interactively
)
288 (function-item gnus-subscribe-killed
)
289 (function-item gnus-subscribe-zombies
)
290 (function-item gnus-subscribe-topics
)
294 (define-obsolete-variable-alias 'gnus-subscribe-newsgroup-hooks
295 'gnus-subscribe-newsgroup-functions
"24.3")
296 (defcustom gnus-subscribe-newsgroup-functions nil
297 "*Hooks run after you subscribe to a new group.
298 The hooks will be called with new group's name as argument."
300 :group
'gnus-group-new
303 (defcustom gnus-subscribe-options-newsgroup-method
304 'gnus-subscribe-alphabetically
305 "*Function(s) called to subscribe newsgroups mentioned on \"options -n\" lines.
306 If, for instance, you want to subscribe to all newsgroups in the
307 \"no\" and \"alt\" hierarchies, you'd put the following in your
310 options -n no.all alt.all
312 Gnus will then subscribe all new newsgroups in these hierarchies
313 with the subscription method in this variable."
314 :group
'gnus-group-new
315 :type
'(radio (function-item gnus-subscribe-randomly
)
316 (function-item gnus-subscribe-alphabetically
)
317 (function-item gnus-subscribe-hierarchically
)
318 (function-item gnus-subscribe-interactively
)
319 (function-item gnus-subscribe-killed
)
320 (function-item gnus-subscribe-zombies
)
321 (function-item gnus-subscribe-topics
)
325 (defcustom gnus-subscribe-hierarchical-interactive nil
326 "*If non-nil, Gnus will offer to subscribe hierarchically.
327 When a new hierarchy appears, Gnus will ask the user:
329 'alt.binaries': Do you want to subscribe to this hierarchy? ([d]ys):
331 If the user pressed `d', Gnus will descend the hierarchy, `y' will
332 subscribe to all newsgroups in the hierarchy and `s' will skip this
333 hierarchy in its entirety."
334 :group
'gnus-group-new
337 (defcustom gnus-auto-subscribed-categories
'(mail post-mail
)
338 "*New groups from methods of these categories will be subscribed automatically.
339 Note that this variable only deals with new groups. It has no
340 effect whatsoever on old groups. The default is to automatically
341 subscribe all groups from mail-like backends."
343 :group
'gnus-group-new
344 :type
'(repeat symbol
))
346 (defcustom gnus-auto-subscribed-groups
347 "^nnml\\|^nnfolder\\|^nnmbox\\|^nnmh\\|^nnbabyl\\|^nnmaildir\\|^nnimap"
348 "*All new groups that match this regexp will be subscribed automatically.
349 Note that this variable only deals with new groups. It has no effect
350 whatsoever on old groups.
352 New groups that match this regexp will not be handled by
353 `gnus-subscribe-newsgroup-method'. Instead, they will
354 be subscribed using `gnus-subscribe-options-newsgroup-method'."
355 :group
'gnus-group-new
358 (defcustom gnus-options-subscribe nil
359 "*All new groups matching this regexp will be subscribed unconditionally.
360 Note that this variable deals only with new newsgroups. This variable
361 does not affect old newsgroups.
363 New groups that match this regexp will not be handled by
364 `gnus-subscribe-newsgroup-method'. Instead, they will
365 be subscribed using `gnus-subscribe-options-newsgroup-method'."
366 :group
'gnus-group-new
367 :type
'(choice regexp
368 (const :tag
"none" nil
)))
370 (defcustom gnus-options-not-subscribe nil
371 "*All new groups matching this regexp will be ignored.
372 Note that this variable deals only with new newsgroups. This variable
373 does not affect old (already subscribed) newsgroups."
374 :group
'gnus-group-new
375 :type
'(choice regexp
376 (const :tag
"none" nil
)))
378 (defcustom gnus-modtime-botch nil
379 "*Non-nil means .newsrc should be deleted prior to save.
380 Its use is due to the bogus appearance that .newsrc was modified on
385 (defcustom gnus-check-bogus-groups-hook nil
386 "A hook run after removing bogus groups."
387 :group
'gnus-start-server
390 (defcustom gnus-startup-hook nil
391 "A hook called at startup.
392 This hook is called after Gnus is connected to the NNTP server."
396 (defcustom gnus-before-startup-hook nil
397 "A hook called before startup.
398 This hook is called as the first thing when Gnus is started.
399 See also `gnus-before-resume-hook'."
403 (defcustom gnus-before-resume-hook nil
404 "A hook called before resuming Gnus after suspend.
405 This hook is called as the first thing when Gnus is resumed after a suspend.
406 See also `gnus-before-startup-hook'."
411 (defcustom gnus-started-hook nil
412 "A hook called as the last thing after startup."
416 (defcustom gnus-setup-news-hook nil
417 "A hook after reading the .newsrc file, but before generating the buffer."
421 (defcustom gnus-get-top-new-news-hook nil
422 "A hook run just before Gnus checks for new news globally."
424 :group
'gnus-group-new
427 (defcustom gnus-get-new-news-hook nil
428 "A hook run just before Gnus checks for new news."
429 :group
'gnus-group-new
432 (defcustom gnus-after-getting-new-news-hook
433 '(gnus-display-time-event-handler)
434 "*A hook run after Gnus checks for new news when Gnus is already running."
436 :group
'gnus-group-new
439 (defcustom gnus-read-newsrc-el-hook nil
440 "A hook called after reading the newsrc.eld? file."
444 (defcustom gnus-save-newsrc-hook nil
445 "A hook called before saving any of the newsrc files."
449 (defcustom gnus-save-quick-newsrc-hook nil
450 "A hook called just before saving the quick newsrc file.
451 Can be used to turn version control on or off."
455 (defcustom gnus-save-standard-newsrc-hook nil
456 "A hook called just before saving the standard newsrc file.
457 Can be used to turn version control on or off."
461 (defcustom gnus-group-mode-hook nil
462 "Hook for Gnus group mode."
463 :group
'gnus-group-various
464 :options
'(gnus-topic-mode)
467 (defcustom gnus-always-read-dribble-file nil
468 "Unconditionally read the dribble file."
472 ;;; Internal variables
474 ;; Fixme: deal with old emacs-mule when mm-universal-coding-system is
476 (defvar gnus-ding-file-coding-system mm-universal-coding-system
477 "Coding system for ding file.")
479 (defvar gnus-newsrc-file-version nil
)
480 (defvar gnus-override-subscribe-method nil
)
481 (defvar gnus-dribble-buffer nil
)
482 (defvar gnus-newsrc-options nil
483 "Options line in the .newsrc file.")
485 (defvar gnus-newsrc-options-n nil
486 "List of regexps representing groups to be subscribed/ignored unconditionally.")
488 (defvar gnus-newsrc-last-checked-date nil
489 "Date Gnus last asked server for new newsgroups.")
491 (defvar gnus-current-startup-file nil
492 "Startup file for the current host.")
494 ;; Byte-compiler warning.
495 (defvar gnus-group-line-format
)
497 ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
498 (defvar gnus-init-inhibit nil
)
499 (defun gnus-read-init-file (&optional inhibit-next
)
500 ;; Don't load .gnus if the -q option was used.
502 (if gnus-init-inhibit
503 (setq gnus-init-inhibit nil
)
504 (setq gnus-init-inhibit inhibit-next
)
505 (dolist (file (list gnus-site-init-file gnus-init-file
))
507 (locate-library file
))
508 (if (or debug-on-error debug-on-quit
)
513 (error "Error in %s: %s" file
(cadr var
))))))))))
515 ;; For subscribing new newsgroup
517 (defun gnus-subscribe-hierarchical-interactive (groups)
518 (let ((groups (sort groups
'string
<))
519 prefixes prefix start ans group starts real-group
)
521 (setq prefixes
(list "^"))
522 (while (and groups prefixes
)
523 (while (not (string-match (car prefixes
)
524 (gnus-group-real-name (car groups
))))
525 (setq prefixes
(cdr prefixes
)))
526 (setq prefix
(car prefixes
))
527 (setq start
(1- (length prefix
)))
528 (if (and (string-match "[^\\.]\\." (gnus-group-real-name (car groups
))
532 (concat "^" (substring
533 (gnus-group-real-name (car groups
))
535 (string-match prefix
(gnus-group-real-name (cadr groups
))))
537 (push prefix prefixes
)
538 (message "Descend hierarchy %s? ([y]nsq): "
539 (substring prefix
1 (1- (length prefix
))))
540 (while (not (memq (setq ans
(read-char-exclusive))
541 '(?y ?
\n ?
\r ?n ?s ?q
)))
543 (message "Descend hierarchy %s? ([y]nsq): "
544 (substring prefix
1 (1- (length prefix
)))))
547 (setq group
(car groups
)
548 real-group
(gnus-group-real-name group
))
549 (string-match prefix real-group
))
550 (push group gnus-killed-list
)
551 (gnus-sethash group group gnus-killed-hashtb
)
552 (setq groups
(cdr groups
)))
553 (setq starts
(cdr starts
)))
556 (setq group
(car groups
)
557 real-group
(gnus-group-real-name group
))
558 (string-match prefix real-group
))
559 (gnus-sethash group group gnus-killed-hashtb
)
560 (gnus-subscribe-alphabetically (car groups
))
561 (setq groups
(cdr groups
)))
562 (setq starts
(cdr starts
)))
565 (setq group
(car groups
))
566 (push group gnus-killed-list
)
567 (gnus-sethash group group gnus-killed-hashtb
)
568 (setq groups
(cdr groups
))))
570 (message "Subscribe %s? ([n]yq)" (car groups
))
571 (while (not (memq (setq ans
(read-char-exclusive))
572 '(?y ?
\n ?
\r ?q ?n
)))
574 (message "Subscribe %s? ([n]yq)" (car groups
)))
575 (setq group
(car groups
))
577 (gnus-subscribe-alphabetically (car groups
))
578 (gnus-sethash group group gnus-killed-hashtb
))
581 (setq group
(car groups
))
582 (push group gnus-killed-list
)
583 (gnus-sethash group group gnus-killed-hashtb
)
584 (setq groups
(cdr groups
))))
586 (push group gnus-killed-list
)
587 (gnus-sethash group group gnus-killed-hashtb
)))
588 (setq groups
(cdr groups
)))))))
590 (defun gnus-subscribe-randomly (newsgroup)
591 "Subscribe new NEWSGROUP by making it the first newsgroup."
592 (gnus-subscribe-newsgroup newsgroup
))
594 (defun gnus-subscribe-alphabetically (newgroup)
595 "Subscribe new NEWGROUP and insert it in alphabetical order."
596 (let ((groups (cdr gnus-newsrc-alist
))
598 (while (and (not before
) groups
)
599 (if (string< newgroup
(caar groups
))
600 (setq before
(caar groups
))
601 (setq groups
(cdr groups
))))
602 (gnus-subscribe-newsgroup newgroup before
)))
604 (defun gnus-subscribe-hierarchically (newgroup)
605 "Subscribe new NEWGROUP and insert it in hierarchical newsgroup order."
606 ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
607 (with-current-buffer (nnheader-find-file-noselect gnus-current-startup-file
)
609 (let ((groupkey newgroup
) before
)
610 (while (and (not before
) groupkey
)
611 (goto-char (point-min))
613 (concat "^\\(" (regexp-quote groupkey
) ".*\\)[!:]")))
614 (while (and (re-search-forward groupkey-re nil t
)
616 (setq before
(match-string 1))
617 (string< before newgroup
)))))
618 ;; Remove tail of newsgroup name (eg. a.b.c -> a.b)
620 (when (string-match "^\\(.*\\)\\.[^.]+$" groupkey
)
621 (substring groupkey
(match-beginning 1) (match-end 1)))))
622 (gnus-subscribe-newsgroup newgroup before
))
623 (kill-buffer (current-buffer)))))
625 (defun gnus-subscribe-interactively (group)
626 "Subscribe the new GROUP interactively.
627 It is inserted in hierarchical newsgroup order if subscribed. If not,
629 (if (gnus-y-or-n-p (format "Subscribe new newsgroup %s? " group
))
630 (gnus-subscribe-hierarchically group
)
631 (push group gnus-killed-list
)))
633 (defun gnus-subscribe-zombies (group)
634 "Make the new GROUP into a zombie group."
635 (push group gnus-zombie-list
))
637 (defun gnus-subscribe-killed (group)
638 "Make the new GROUP a killed group."
639 (push group gnus-killed-list
))
641 (defun gnus-subscribe-newsgroup (newsgroup &optional next
)
642 "Subscribe new NEWSGROUP.
643 If NEXT is non-nil, it is inserted before NEXT. Otherwise it is made
644 the first newsgroup."
646 (goto-char (point-min))
647 ;; We subscribe the group by changing its level to `subscribed'.
648 (gnus-group-change-level
649 newsgroup gnus-level-default-subscribed
650 gnus-level-killed
(gnus-group-entry (or next
"dummy.group")))
651 (gnus-request-update-group-status newsgroup
'subscribe
)
652 (gnus-message 5 "Subscribe newsgroup: %s" newsgroup
)
653 (run-hook-with-args 'gnus-subscribe-newsgroup-functions newsgroup
)
656 (defun gnus-read-active-file-p ()
657 "Say whether the active file has been read from `gnus-select-method'."
658 (memq gnus-select-method gnus-have-read-active-file
))
660 ;;; General various misc type functions.
662 ;; Silence byte-compiler.
663 (defvar gnus-current-headers
)
664 (defvar gnus-thread-indent-array
)
665 (defvar gnus-newsgroup-name
)
666 (defvar gnus-newsgroup-headers
)
667 (defvar gnus-group-list-mode
)
668 (defvar gnus-group-mark-positions
)
669 (defvar gnus-newsgroup-data
)
670 (defvar gnus-newsgroup-unreads
)
671 (defvar nnoo-state-alist
)
672 (defvar gnus-current-select-method
)
673 (defvar mail-sources
)
674 (defvar nnmail-scan-directory-mail-source-once
)
675 (defvar nnmail-split-history
)
676 (defvar nnmail-spool-file
)
678 (defun gnus-close-all-servers ()
681 (dolist (server gnus-opened-servers
)
682 (gnus-close-server (car server
))))
684 (defun gnus-clear-system ()
685 "Clear all variables and buffers."
686 ;; Clear Gnus variables.
687 (let ((variables (remove 'gnus-format-specs gnus-variable-list
)))
689 (set (car variables
) nil
)
690 (setq variables
(cdr variables
))))
691 ;; Clear other internal variables.
692 (setq gnus-list-of-killed-groups nil
693 gnus-have-read-active-file nil
694 gnus-agent-covered-methods nil
695 gnus-agent-file-loading-local nil
696 gnus-agent-file-loading-cache nil
697 gnus-server-method-cache nil
698 gnus-newsrc-alist nil
699 gnus-newsrc-hashtb nil
702 gnus-killed-hashtb nil
703 gnus-active-hashtb nil
704 gnus-moderated-hashtb nil
705 gnus-description-hashtb nil
706 gnus-current-headers nil
707 gnus-thread-indent-array nil
708 gnus-newsgroup-headers nil
709 gnus-newsgroup-name nil
710 gnus-server-alist nil
711 gnus-group-list-mode nil
712 gnus-opened-servers nil
713 gnus-group-mark-positions nil
714 gnus-newsgroup-data nil
715 gnus-newsgroup-unreads nil
717 gnus-current-select-method nil
718 nnmail-split-history nil
719 gnus-extended-servers nil
720 gnus-ephemeral-servers nil
)
721 (gnus-shutdown 'gnus
)
722 ;; Kill the startup file.
723 (and gnus-current-startup-file
724 (get-file-buffer gnus-current-startup-file
)
725 (kill-buffer (get-file-buffer gnus-current-startup-file
)))
726 ;; Clear the dribble buffer.
728 ;; Kill global KILL file buffer.
729 (when (get-file-buffer (gnus-newsgroup-kill-file nil
))
730 (kill-buffer (get-file-buffer (gnus-newsgroup-kill-file nil
))))
731 (gnus-kill-buffer nntp-server-buffer
)
732 ;; Kill Gnus buffers.
733 (dolist (buffer (gnus-buffers))
734 (gnus-kill-buffer buffer
))
735 ;; Remove Gnus frames.
736 (gnus-kill-gnus-frames))
738 (defun gnus-no-server-1 (&optional arg slave
)
740 If ARG is a positive number, Gnus will use that as the startup
741 level. If ARG is nil, Gnus will be started at level 2
742 \(`gnus-level-default-subscribed' minus one). If ARG is non-nil
743 and not a positive number, Gnus will prompt the user for the name
744 of an NNTP server to use. As opposed to \\[gnus], this command
745 will not connect to the local server."
747 (let ((val (or arg
(1- gnus-level-default-subscribed
))))
749 (make-local-variable 'gnus-group-use-permanent-levels
)
750 (setq gnus-group-use-permanent-levels val
)))
752 (defun gnus-1 (&optional arg dont-connect slave
)
754 If ARG is non-nil and a positive number, Gnus will use that as the
755 startup level. If ARG is non-nil and not a positive number, Gnus will
756 prompt the user for the name of an NNTP server to use."
761 (gnus-run-hooks 'gnus-before-resume-hook
)
762 (switch-to-buffer gnus-group-buffer
)
763 (gnus-group-get-new-news
766 (max (car gnus-group-list-mode
) arg
))))
770 (gnus-run-hooks 'gnus-before-startup-hook
)
771 (nnheader-init-server-buffer)
772 (setq gnus-slave slave
)
773 (gnus-read-init-file)
775 ;; Add "native" to gnus-predefined-server-alist just to have a
776 ;; name for the native select method.
777 (when gnus-select-method
778 (add-to-list 'gnus-predefined-server-alist
779 (cons "native" gnus-select-method
)))
784 (let ((level (and (numberp arg
) (> arg
0) arg
))
790 (gnus-start-news-server (and arg
(not level
))))))
791 (if (and (not dont-connect
)
793 ;; Couldn't connect to the server, so bail out.
795 (gnus-run-hooks 'gnus-startup-hook
)
796 ;; Find the current startup file name.
797 (setq gnus-current-startup-file
798 (gnus-make-newsrc-file gnus-startup-file
))
800 ;; Read the dribble file.
801 (when (or gnus-slave gnus-use-dribble-file
)
802 (gnus-dribble-read-file))
804 ;; Do the actual startup.
805 (gnus-setup-news nil level dont-connect
)
806 (gnus-run-hooks 'gnus-setup-news-hook
)
808 (gnus-request-create-group "queue" '(nndraft "")))
809 (gnus-start-draft-setup)
810 ;; Generate the group buffer.
811 (gnus-group-list-groups level
)
812 (gnus-group-first-unread-group)
813 (gnus-configure-windows 'group
)
814 (gnus-group-set-mode-line)
815 (gnus-run-hooks 'gnus-started-hook
))))))
817 (defun gnus-start-draft-setup ()
818 "Make sure the draft group exists."
820 (gnus-request-create-group "drafts" '(nndraft ""))
821 (unless (gnus-group-entry "nndraft:drafts")
822 (let ((gnus-level-default-subscribed 1))
823 (gnus-subscribe-group "nndraft:drafts" nil
'(nndraft "")))
824 (setcar (gnus-group-entry "nndraft:drafts") 0))
825 (unless (equal (gnus-group-get-parameter "nndraft:drafts" 'gnus-dummy t
)
826 '((gnus-draft-mode)))
827 (gnus-group-set-parameter
828 "nndraft:drafts" 'gnus-dummy
'((gnus-draft-mode)))))
835 (defvar gnus-dribble-ignore nil
)
836 (defvar gnus-dribble-eval-file nil
)
838 (defun gnus-dribble-file-name ()
839 "Return the dribble file for the current .newsrc."
841 (if gnus-dribble-directory
842 (concat (file-name-as-directory gnus-dribble-directory
)
843 (file-name-nondirectory gnus-current-startup-file
))
844 gnus-current-startup-file
)
847 (defun gnus-dribble-enter (string &optional regexp
)
848 "Enter STRING into the dribble buffer.
849 If REGEXP is given, lines that match it will be deleted."
850 (when (and (not gnus-dribble-ignore
)
852 (buffer-name gnus-dribble-buffer
))
853 (let ((obuf (current-buffer)))
854 (set-buffer gnus-dribble-buffer
)
856 (goto-char (point-min))
858 (while (re-search-forward regexp nil t
)
859 (unless (bolp) (forward-line 1))
861 (goto-char (match-beginning 0))
862 (delete-region (point-at-bol) end
))))
863 (goto-char (point-max))
865 ;; This has been commented by Josh Huber <huber@alum.wpi.edu>
866 ;; It causes problems with both XEmacs and Emacs 21, and doesn't
867 ;; seem to be of much value. (FIXME: remove this after we make sure
869 ;; (set-window-point (get-buffer-window (current-buffer)) (point-max))
870 (bury-buffer gnus-dribble-buffer
)
871 (with-current-buffer gnus-group-buffer
872 (gnus-group-set-mode-line))
875 (defun gnus-dribble-touch ()
876 "Touch the dribble buffer."
877 (gnus-dribble-enter ""))
879 (defun gnus-dribble-read-file ()
880 "Read the dribble file from disk."
881 (let ((dribble-file (gnus-dribble-file-name)))
882 (unless (file-exists-p (file-name-directory dribble-file
))
883 (make-directory (file-name-directory dribble-file
) t
))
884 (with-current-buffer (setq gnus-dribble-buffer
885 (gnus-get-buffer-create
886 (file-name-nondirectory dribble-file
)))
887 (set (make-local-variable 'file-precious-flag
) t
)
888 (setq buffer-save-without-query t
)
890 (setq buffer-file-name dribble-file
)
892 (buffer-disable-undo)
893 (bury-buffer (current-buffer))
894 (set-buffer-modified-p nil
)
895 (let ((auto (make-auto-save-file-name))
896 (gnus-dribble-ignore t
)
899 (when (or (file-exists-p auto
) (file-exists-p dribble-file
))
900 ;; Load whichever file is newest -- the auto save file
901 ;; or the "real" file.
902 (if (file-newer-than-file-p auto dribble-file
)
903 (nnheader-insert-file-contents auto
)
904 (nnheader-insert-file-contents dribble-file
))
905 (unless (zerop (buffer-size))
906 (set-buffer-modified-p t
))
907 ;; Set the file modes to reflect the .newsrc file modes.
909 (when (and (file-exists-p gnus-current-startup-file
)
910 (file-exists-p dribble-file
)
911 (setq modes
(file-modes gnus-current-startup-file
)))
912 (gnus-set-file-modes dribble-file modes
))
913 (goto-char (point-min))
914 (when (search-forward "Gnus was exited on purpose" nil t
)
916 ;; Possibly eval the file later.
917 (when (or gnus-always-read-dribble-file
920 "Gnus exited on purpose without saving; read auto-save file anyway? "
921 "Gnus auto-save file exists. Do you want to read it? ")))
922 (setq gnus-dribble-eval-file t
)))))))
924 (defun gnus-dribble-eval-file ()
925 (when gnus-dribble-eval-file
926 (setq gnus-dribble-eval-file nil
)
928 (let ((gnus-dribble-ignore t
))
929 (set-buffer gnus-dribble-buffer
)
930 (eval-buffer (current-buffer))))))
932 (defun gnus-dribble-delete-file ()
933 (when (file-exists-p (gnus-dribble-file-name))
934 (delete-file (gnus-dribble-file-name)))
935 (when gnus-dribble-buffer
936 (with-current-buffer gnus-dribble-buffer
937 (let ((auto (make-auto-save-file-name)))
938 (when (file-exists-p auto
)
941 (set-buffer-modified-p nil
)))))
943 (defun gnus-dribble-save ()
944 (when (and gnus-dribble-buffer
945 (buffer-name gnus-dribble-buffer
))
946 (with-current-buffer gnus-dribble-buffer
949 (defun gnus-dribble-clear ()
950 (when (gnus-buffer-exists-p gnus-dribble-buffer
)
951 (with-current-buffer gnus-dribble-buffer
953 (set-buffer-modified-p nil
)
954 (setq buffer-saved-size
(buffer-size)))))
958 ;;; Active & Newsrc File Handling
961 (defun gnus-setup-news (&optional rawfile level dont-connect
)
962 "Setup news information.
963 If RAWFILE is non-nil, the .newsrc file will also be read.
964 If LEVEL is non-nil, the news will be set up at level LEVEL."
966 (let ((init (not (and gnus-newsrc-alist gnus-active-hashtb
(not rawfile
))))
967 ;; Binding this variable will inhibit multiple fetchings
968 ;; of the same mail source.
969 (nnmail-fetched-sources (list t
)))
972 ;; Clear some variables to re-initialize news information.
973 (setq gnus-newsrc-alist nil
974 gnus-active-hashtb nil
)
975 ;; Read the newsrc file and create `gnus-newsrc-hashtb'.
976 (gnus-read-newsrc-file rawfile
))
978 ;; Make sure the archive server is available to all and sundry.
979 (let ((method (or (and (stringp gnus-message-archive-method
)
980 (gnus-server-to-method
981 gnus-message-archive-method
))
982 gnus-message-archive-method
)))
983 ;; Check whether the archive method is writable.
984 (unless (or (not method
)
986 (memq 'respool
(assoc (format "%s" (car method
))
987 gnus-valid-select-methods
)))
988 (setq method
"archive")) ;; The default.
989 (when (stringp method
)
990 (setq method
`(nnfolder
993 ,(nnheader-concat message-directory method
))
994 (nnfolder-active-file
995 ,(nnheader-concat message-directory
996 (concat method
"/active")))
997 (nnfolder-get-new-mail nil
)
998 (nnfolder-inhibit-expiry t
))))
999 (if (assoc "archive" gnus-server-alist
)
1000 (when gnus-update-message-archive-method
1002 (setcdr (assoc "archive" gnus-server-alist
) method
)
1003 (setq gnus-server-alist
(delq (assoc "archive" gnus-server-alist
)
1004 gnus-server-alist
))))
1006 (push (cons "archive" method
) gnus-server-alist
))))
1008 ;; If we don't read the complete active file, we fill in the
1010 (when (or (null gnus-read-active-file
)
1011 (eq gnus-read-active-file
'some
))
1012 (gnus-update-active-hashtb-from-killed))
1013 (unless gnus-active-hashtb
1014 (setq gnus-active-hashtb
(gnus-make-hashtable 4096)))
1015 ;; Initialize the cache.
1016 (when gnus-use-cache
1019 ;; Possibly eval the dribble file.
1021 (or gnus-use-dribble-file gnus-slave
)
1022 (gnus-dribble-eval-file))
1024 ;; Slave Gnusii should then clear the dribble buffer.
1025 (when (and init gnus-slave
)
1026 (gnus-dribble-clear))
1028 (gnus-update-format-specifications)
1030 ;; See whether we need to read the description file.
1031 (when (and (boundp 'gnus-group-line-format
)
1032 (stringp gnus-group-line-format
)
1033 (let ((case-fold-search nil
))
1034 (string-match "%[-,0-9]*D" gnus-group-line-format
))
1035 (not gnus-description-hashtb
)
1037 gnus-read-active-file
)
1038 (gnus-read-all-descriptions-files))
1040 ;; Find new newsgroups and treat them.
1041 (when (and init gnus-check-new-newsgroups
(not level
)
1042 (gnus-check-server gnus-select-method
)
1045 (gnus-find-new-newsgroups))
1047 ;; Check and remove bogus newsgroups.
1048 (when (and init gnus-check-bogus-newsgroups
1049 gnus-read-active-file
(not level
)
1050 (gnus-server-opened gnus-select-method
))
1051 (gnus-check-bogus-newsgroups))
1053 ;; Read any slave files.
1054 (gnus-master-read-slave-newsrc)
1056 ;; Find the number of unread articles in each non-dead group.
1057 (let ((gnus-read-active-file (and (not level
) gnus-read-active-file
)))
1058 (gnus-get-unread-articles level dont-connect
))))
1060 (defun gnus-call-subscribe-functions (method group
)
1061 "Call METHOD to subscribe GROUP.
1062 If no function returns `non-nil', call `gnus-subscribe-zombies'."
1065 (funcall method group
))
1068 (dolist (func method
)
1069 (if (funcall func group
)
1073 (gnus-subscribe-zombies group
)))
1075 (defun gnus-find-new-newsgroups (&optional arg
)
1076 "Search for new newsgroups and add them.
1077 Each new newsgroup will be treated with `gnus-subscribe-newsgroup-method'.
1078 The `-n' option line from .newsrc is respected.
1080 With 1 C-u, use the `ask-server' method to query the server for new
1082 With 2 C-u's, use most complete method possible to query the server
1083 for new groups, and subscribe the new groups as zombies."
1085 (let* ((gnus-subscribe-newsgroup-method
1086 gnus-subscribe-newsgroup-method
)
1088 ((or (and (= (or arg
1) 4)
1089 (not (listp gnus-check-new-newsgroups
)))
1090 (null gnus-read-active-file
)
1091 (eq gnus-read-active-file
'some
))
1094 (setq gnus-subscribe-newsgroup-method
1095 'gnus-subscribe-zombies
)
1097 (t gnus-check-new-newsgroups
))))
1098 (if (or (consp check
)
1099 (eq check
'ask-server
))
1100 ;; Ask the server for new groups.
1101 (gnus-ask-server-for-new-groups)
1102 ;; Go through the active hashtb and look for new groups.
1104 group new-newsgroups
)
1105 (gnus-message 5 "Looking for new newsgroups...")
1106 (unless gnus-have-read-active-file
1107 (gnus-read-active-file))
1108 (setq gnus-newsrc-last-checked-date
(message-make-date))
1109 (unless gnus-killed-hashtb
1110 (gnus-make-hashtable-from-killed))
1111 ;; Go though every newsgroup in `gnus-active-hashtb' and compare
1112 ;; with `gnus-newsrc-hashtb' and `gnus-killed-hashtb'.
1115 (if (or (null (setq group
(symbol-name sym
)))
1117 (null (symbol-value sym
))
1118 (gnus-gethash group gnus-killed-hashtb
)
1119 (gnus-gethash group gnus-newsrc-hashtb
))
1121 (let ((do-sub (gnus-matches-options-n group
)))
1123 ((eq do-sub
'subscribe
)
1124 (setq groups
(1+ groups
))
1125 (gnus-sethash group group gnus-killed-hashtb
)
1126 (gnus-call-subscribe-functions
1127 gnus-subscribe-options-newsgroup-method group
))
1128 ((eq do-sub
'ignore
)
1131 (setq groups
(1+ groups
))
1132 (gnus-sethash group group gnus-killed-hashtb
)
1133 (if gnus-subscribe-hierarchical-interactive
1134 (push group new-newsgroups
)
1135 (gnus-call-subscribe-functions
1136 gnus-subscribe-newsgroup-method group
)))))))
1138 (when new-newsgroups
1139 (gnus-subscribe-hierarchical-interactive new-newsgroups
))
1141 (gnus-message 5 "%d new newsgroup%s arrived."
1142 groups
(if (> groups
1) "s have" " has"))
1143 (gnus-message 5 "No new newsgroups."))
1146 (defun gnus-matches-options-n (group)
1147 ;; Returns `subscribe' if the group is to be unconditionally
1148 ;; subscribed, `ignore' if it is to be ignored, and nil if there is
1149 ;; no match for the group.
1151 ;; First we check the two user variables.
1153 ((and gnus-options-subscribe
1154 (string-match gnus-options-subscribe group
))
1156 ((let ((do-subscribe nil
))
1157 (dolist (category gnus-auto-subscribed-categories
)
1158 (when (gnus-member-of-valid category group
)
1159 (setq do-subscribe t
)))
1162 ((and gnus-auto-subscribed-groups
1163 (string-match gnus-auto-subscribed-groups group
))
1165 ((and gnus-options-not-subscribe
1166 (string-match gnus-options-not-subscribe group
))
1168 ;; Then we go through the list that was retrieved from the .newsrc
1169 ;; file. This list has elements on the form
1170 ;; `(REGEXP . {ignore,subscribe})'. The first match found (the list
1171 ;; is in the reverse order of the options line) is returned.
1173 (let ((regs gnus-newsrc-options-n
))
1175 (not (string-match (caar regs
) group
)))
1176 (setq regs
(cdr regs
)))
1177 (and regs
(cdar regs
))))))
1179 (defun gnus-ask-server-for-new-groups ()
1180 (let* ((new-date (message-make-date))
1181 (date (or gnus-newsrc-last-checked-date new-date
))
1182 (methods (cons gnus-select-method
1184 (when (gnus-archive-server-wanted-p)
1187 (and (consp gnus-check-new-newsgroups
)
1188 gnus-check-new-newsgroups
)
1189 gnus-secondary-select-methods
))))
1191 group new-newsgroups got-new method hashtb
1192 gnus-override-subscribe-method
)
1193 (unless gnus-killed-hashtb
1194 (gnus-make-hashtable-from-killed))
1195 ;; Go through both primary and secondary select methods and
1196 ;; request new newsgroups.
1197 (while (setq method
(gnus-server-get-method nil
(pop methods
)))
1198 (setq new-newsgroups nil
1199 gnus-override-subscribe-method method
)
1200 (when (and (gnus-check-server method
)
1201 (gnus-request-newgroups date method
))
1204 hashtb
(gnus-make-hashtable 100))
1205 (set-buffer nntp-server-buffer
)
1206 ;; Enter all the new groups into a hashtable.
1207 (gnus-active-to-gnus-format method hashtb
'ignore
))
1208 ;; Now all new groups from `method' are in `hashtb'.
1211 (if (or (null (setq group
(symbol-name group-sym
)))
1212 (not (boundp group-sym
))
1213 (null (symbol-value group-sym
))
1214 (gnus-gethash group gnus-newsrc-hashtb
)
1215 (member group gnus-zombie-list
)
1216 (member group gnus-killed-list
))
1217 ;; The group is already known.
1219 ;; Make this group active.
1220 (when (symbol-value group-sym
)
1221 (gnus-set-active group
(symbol-value group-sym
)))
1222 ;; Check whether we want it or not.
1223 (let ((do-sub (gnus-matches-options-n group
)))
1225 ((eq do-sub
'subscribe
)
1227 (gnus-sethash group group gnus-killed-hashtb
)
1228 (gnus-call-subscribe-functions
1229 gnus-subscribe-options-newsgroup-method group
))
1230 ((eq do-sub
'ignore
)
1234 (gnus-sethash group group gnus-killed-hashtb
)
1235 (if gnus-subscribe-hierarchical-interactive
1236 (push group new-newsgroups
)
1237 (gnus-call-subscribe-functions
1238 gnus-subscribe-newsgroup-method group
)))))))
1240 (when new-newsgroups
1241 (gnus-subscribe-hierarchical-interactive new-newsgroups
)))
1243 (gnus-message 5 "%d new newsgroup%s arrived"
1244 groups
(if (> groups
1) "s have" " has"))
1245 (gnus-message 5 "No new newsgroups"))
1247 (setq gnus-newsrc-last-checked-date new-date
))
1250 (defun gnus-subscribe-group (group &optional previous method
)
1251 "Subscribe GROUP and put it after PREVIOUS."
1252 (gnus-group-change-level
1254 (list t group gnus-level-default-subscribed nil nil method
)
1256 gnus-level-default-subscribed gnus-level-killed previous t
)
1259 ;; `gnus-group-change-level' is the fundamental function for changing
1260 ;; subscription levels of newsgroups. This might mean just changing
1261 ;; from level 1 to 2, which is pretty trivial, from 2 to 6 or back
1262 ;; again, which subscribes/unsubscribes a group, which is equally
1263 ;; trivial. Changing from 1-7 to 8-9 means that you kill a group, and
1264 ;; from 8-9 to 1-7 means that you remove the group from the list of
1265 ;; killed (or zombie) groups and add them to the (kinda) subscribed
1266 ;; groups. And last but not least, moving from 8 to 9 and 9 to 8,
1267 ;; which is trivial.
1268 ;; ENTRY can either be a string (newsgroup name) or a list (if
1269 ;; FROMKILLED is t, it's a list on the format (NUM INFO-LIST),
1270 ;; otherwise it's a list in the format of the `gnus-newsrc-hashtb'
1272 ;; LEVEL is the new level of the group, OLDLEVEL is the old level and
1273 ;; PREVIOUS is the group (in hashtb entry format) to insert this group
1275 (defun gnus-group-change-level (entry level
&optional oldlevel
1276 previous fromkilled
)
1277 (let (group info active num
)
1278 ;; Glean what info we can from the arguments
1280 (if fromkilled
(setq group
(nth 1 entry
))
1281 (setq group
(car (nth 2 entry
))))
1283 (when (and (stringp entry
)
1285 (< oldlevel gnus-level-zombie
))
1286 (setq entry
(gnus-group-entry entry
)))
1287 (if (and (not oldlevel
)
1289 (setq oldlevel
(gnus-info-level (nth 2 entry
)))
1290 (setq oldlevel
(or oldlevel gnus-level-killed
)))
1291 (when (stringp previous
)
1292 (setq previous
(gnus-group-entry previous
)))
1294 (if (and (>= oldlevel gnus-level-zombie
)
1295 (gnus-group-entry group
))
1296 ;; We are trying to subscribe a group that is already
1300 (unless (gnus-ephemeral-group-p group
)
1302 (format "(gnus-group-change-level %S %S %S %S %S)"
1303 group level oldlevel
(car (nth 2 previous
)) fromkilled
)))
1305 ;; Then we remove the newgroup from any old structures, if needed.
1306 ;; If the group was killed, we remove it from the killed or zombie
1307 ;; list. If not, and it is in fact going to be killed, we remove
1308 ;; it from the newsrc hash table and assoc.
1310 ((>= oldlevel gnus-level-zombie
)
1311 ;; oldlevel could be wrong.
1312 (setq gnus-zombie-list
(delete group gnus-zombie-list
))
1313 (setq gnus-killed-list
(delete group gnus-killed-list
)))
1315 (when (and (>= level gnus-level-zombie
)
1317 (gnus-sethash (car (nth 2 entry
)) nil gnus-newsrc-hashtb
)
1319 (setcdr (gnus-group-entry (car (nth 3 entry
)))
1321 (setcdr (cdr entry
) (cdddr entry
)))))
1323 ;; Finally we enter (if needed) the list where it is supposed to
1324 ;; go, and change the subscription level. If it is to be killed,
1325 ;; we enter it into the killed or zombie list.
1327 ((>= level gnus-level-zombie
)
1328 ;; Remove from the hash table.
1329 (gnus-sethash group nil gnus-newsrc-hashtb
)
1330 (if (= level gnus-level-zombie
)
1331 (push group gnus-zombie-list
)
1332 (if (= oldlevel gnus-level-killed
)
1333 ;; Remove from active hashtb.
1334 (unintern group gnus-active-hashtb
)
1335 ;; Don't add it into killed-list if it was killed.
1336 (push group gnus-killed-list
))))
1338 ;; If the list is to be entered into the newsrc assoc, and
1339 ;; it was killed, we have to create an entry in the newsrc
1340 ;; hashtb format and fix the pointers in the newsrc assoc.
1341 (if (< oldlevel gnus-level-zombie
)
1342 ;; It was alive, and it is going to stay alive, so we
1343 ;; just change the level and don't change any pointers or
1344 ;; hash table entries.
1345 (setcar (cdaddr entry
) level
)
1347 (setq info
(cdr entry
)
1349 (setq active
(gnus-active group
))
1351 (if active
(- (1+ (cdr active
)) (car active
)) t
))
1352 ;; Shorten the select method if possible, if we need to
1353 ;; store it at all (native groups).
1354 (let ((method (gnus-method-simplify
1355 (or gnus-override-subscribe-method
1356 (gnus-group-method group
)))))
1358 (setq info
(list group level nil nil method
))
1359 (setq info
(list group level nil
)))))
1362 (let ((p gnus-newsrc-alist
))
1366 (setq entry
(cons info
(cddr previous
)))
1369 (setcdr (cdr previous
) entry
)
1370 (gnus-sethash group
(cons num
(cdr previous
))
1371 gnus-newsrc-hashtb
))
1372 (setcdr previous entry
)
1373 (gnus-sethash group
(cons num previous
)
1374 gnus-newsrc-hashtb
))
1376 (setcdr (gnus-group-entry (caadr entry
)) entry
))
1378 (format "(gnus-group-set-info '%S)" info
)
1379 (concat "^(gnus-group-set-info '(\"" (regexp-quote group
) "\"")))))
1380 (when gnus-group-change-level-function
1381 (funcall gnus-group-change-level-function
1382 group level oldlevel previous
)))))
1384 (defun gnus-check-bogus-newsgroups (&optional confirm
)
1385 "Remove bogus newsgroups.
1386 If CONFIRM is non-nil, the user has to confirm the deletion of every
1388 (let ((newsrc (cdr gnus-newsrc-alist
))
1389 bogus group entry info
)
1390 (gnus-message 5 "Checking bogus newsgroups...")
1391 (unless (gnus-read-active-file-p)
1392 (gnus-read-active-file t
))
1393 (when (gnus-read-active-file-p)
1394 ;; Find all bogus newsgroup that are subscribed.
1396 (setq info
(pop newsrc
)
1397 group
(gnus-info-group info
))
1398 (unless (or (gnus-active group
) ; Active
1399 (and (gnus-info-method info
)
1400 (not (gnus-secondary-method-p
1401 (gnus-info-method info
))))) ; Foreign
1402 ;; Found a bogus newsgroup.
1403 (push group bogus
)))
1406 (format "Remove bogus group %%s (of %d groups)? " (length bogus
))
1408 ;; Remove all bogus subscribed groups by first killing them, and
1409 ;; then removing them from the list of killed groups.
1410 (when (setq entry
(gnus-group-entry group
))
1411 (gnus-group-change-level entry gnus-level-killed
)
1412 (setq gnus-killed-list
(delete group gnus-killed-list
))))
1413 bogus
'("group" "groups" "remove"))
1414 (while (setq group
(pop bogus
))
1415 ;; Remove all bogus subscribed groups by first killing them, and
1416 ;; then removing them from the list of killed groups.
1417 (when (setq entry
(gnus-group-entry group
))
1418 (gnus-group-change-level entry gnus-level-killed
)
1419 (setq gnus-killed-list
(delete group gnus-killed-list
)))))
1420 ;; Then we remove all bogus groups from the list of killed and
1421 ;; zombie groups. They are removed without confirmation.
1422 (let ((dead-lists '(gnus-killed-list gnus-zombie-list
))
1425 (setq killed
(symbol-value (car dead-lists
)))
1427 (unless (gnus-active (setq group
(pop killed
)))
1428 ;; The group is bogus.
1430 (set (car dead-lists
)
1431 (delete group
(symbol-value (car dead-lists
))))))
1432 (setq dead-lists
(cdr dead-lists
))))
1433 (gnus-run-hooks 'gnus-check-bogus-groups-hook
)
1434 (gnus-message 5 "Checking bogus newsgroups...done"))))
1436 (defun gnus-check-duplicate-killed-groups ()
1437 "Remove duplicates from the list of killed groups."
1439 (let ((killed gnus-killed-list
))
1441 (gnus-message 9 "%d" (length killed
))
1442 (setcdr killed
(delete (car killed
) (cdr killed
)))
1443 (setq killed
(cdr killed
)))))
1445 ;; We want to inline a function from gnus-cache, so we cheat here:
1446 (defvar gnus-cache-active-hashtb
)
1448 (defun gnus-cache-possibly-alter-active (group active
)
1449 "Alter the ACTIVE info for GROUP to reflect the articles in the cache."
1450 (when gnus-cache-active-hashtb
1451 (let ((cache-active (gnus-gethash group gnus-cache-active-hashtb
)))
1453 (when (< (car cache-active
) (car active
))
1454 (setcar active
(car cache-active
)))
1455 (when (> (cdr cache-active
) (cdr active
))
1456 (setcdr active
(cdr cache-active
))))))))
1458 (defun gnus-activate-group (group &optional scan dont-check method
1460 "Check whether a group has been activated or not.
1461 If SCAN, request a scan of that group as well. If METHOD, use
1462 that select method instead of determining the method based on the
1463 group name. If DONT-CHECK, don't check check whether the group
1464 actually exists. If DONT-SUB-CHECK or DONT-CHECK, don't let the
1465 backend check whether the group actually exists."
1466 (let ((method (or method
(inline (gnus-find-method-for-group group
))))
1468 (and (inline (gnus-check-server method
))
1469 ;; We escape all bugs and quit here to make it possible to
1470 ;; continue if a group is so out-there that it reports bugs
1474 (gnus-check-backend-function 'request-scan
(car method
))
1475 (gnus-request-scan group method
))
1477 (if (or debug-on-error debug-on-quit
)
1478 (inline (gnus-request-group group
(or dont-sub-check dont-check
)
1480 (gnus-get-info group
)))
1482 (inline (gnus-request-group group
(or dont-sub-check dont-check
)
1484 (gnus-get-info group
)))
1488 (message "Quit activating %s" group
))
1491 (setq active
(gnus-parse-active))
1492 ;; If there are no articles in the group, the GROUP
1493 ;; command may have responded with the `(0 . 0)'. We
1494 ;; ignore this if we already have an active entry
1496 (if (and (zerop (or (car active
) 0))
1497 (zerop (or (cdr active
) 0))
1498 (gnus-active group
))
1501 ;; If a cache is present, we may have to alter the active info.
1502 (when gnus-use-cache
1503 (inline (gnus-cache-possibly-alter-active
1506 ;; If the agent is enabled, we may have to alter the active info.
1508 (gnus-agent-possibly-alter-active group active
))
1510 (gnus-set-active group active
)
1511 ;; Return the new active info.
1514 (defun gnus-get-unread-articles-in-group (info active
&optional update
)
1515 (when (and info active
)
1516 ;; Allow the backend to update the info in the group.
1518 (gnus-request-update-info
1519 info
(inline (gnus-find-method-for-group
1520 (gnus-info-group info
)))))
1521 (gnus-activate-group (gnus-info-group info
) nil t
))
1523 (let* ((range (gnus-info-read info
))
1526 ;; These checks are present in gnus-activate-group but skipped
1527 ;; due to setting dont-check in the preceding call.
1529 ;; If a cache is present, we may have to alter the active info.
1530 (when (and gnus-use-cache info
)
1531 (inline (gnus-cache-possibly-alter-active
1532 (gnus-info-group info
) active
)))
1534 ;; If the agent is enabled, we may have to alter the active info.
1535 (when (and gnus-agent info
)
1536 (gnus-agent-possibly-alter-active (gnus-info-group info
) active info
))
1538 ;; Modify the list of read articles according to what articles
1539 ;; are available; then tally the unread articles and add the
1540 ;; number to the group hash table entry.
1542 ((zerop (cdr active
))
1545 (setq num
(- (1+ (cdr active
)) (car active
))))
1546 ((not (listp (cdr range
)))
1547 ;; Fix a single (num . num) range according to the
1548 ;; active hash table.
1549 ;; Fix by Carsten Bormann <cabo@Informatik.Uni-Bremen.DE>.
1550 (and (< (cdr range
) (car active
)) (setcdr range
(1- (car active
))))
1551 (and (> (cdr range
) (cdr active
)) (setcdr range
(cdr active
)))
1552 ;; Compute number of unread articles.
1553 (setq num
(max 0 (- (cdr active
) (- (1+ (cdr range
)) (car range
))))))
1555 ;; The read list is a list of ranges. Fix them according to
1556 ;; the active hash table.
1557 ;; First peel off any elements that are below the lower
1559 (while (and (cdr range
)
1561 (or (and (atom (cadr range
)) (cadr range
))
1563 (if (numberp (car range
))
1566 (or (and (numberp (cadr range
))
1570 (or (and (numberp (nth 1 range
)) (nth 1 range
))
1572 (setcdr range
(cddr range
)))
1573 ;; Adjust the first element to be the same as the lower limit.
1574 (when (and (not (atom (car range
)))
1575 (< (cdar range
) (car active
)))
1576 (setcdr (car range
) (1- (car active
))))
1577 ;; Then we want to peel off any elements that are higher
1578 ;; than the upper active limit.
1579 (let ((srange range
))
1580 ;; Go past all valid elements.
1581 (while (and (cdr srange
)
1582 (<= (or (and (atom (cadr srange
))
1586 (setq srange
(cdr srange
)))
1588 ;; Nuke all remaining invalid elements.
1589 (setcdr srange nil
))
1591 ;; Adjust the final element.
1592 (when (and (not (atom (car srange
)))
1593 (> (cdar srange
) (cdr active
)))
1594 (setcdr (car srange
) (cdr active
))))
1595 ;; Compute the number of unread articles.
1597 (setq num
(+ num
(- (1+ (or (and (atom (car range
)) (car range
))
1599 (or (and (atom (car range
)) (car range
))
1601 (setq range
(cdr range
)))
1602 (setq num
(max 0 (- (cdr active
) num
)))))
1603 ;; Set the number of unread articles.
1605 (gnus-group-entry (gnus-info-group info
)))
1606 (setcar (gnus-group-entry (gnus-info-group info
)) num
))
1609 ;; Go though `gnus-newsrc-alist' and compare with `gnus-active-hashtb'
1610 ;; and compute how many unread articles there are in each group.
1611 (defun gnus-get-unread-articles (&optional level dont-connect one-level
)
1612 (setq gnus-server-method-cache nil
)
1613 (require 'gnus-agent
)
1614 (let* ((newsrc (cdr gnus-newsrc-alist
))
1615 (alevel (or level gnus-activate-level
(1+ gnus-level-subscribed
)))
1620 (cond ((and gnus-activate-foreign-newsgroups
1621 (not (numberp gnus-activate-foreign-newsgroups
)))
1622 (1+ gnus-level-subscribed
))
1623 ((numberp gnus-activate-foreign-newsgroups
)
1624 gnus-activate-foreign-newsgroups
)
1629 (gnus-agent-article-local-times 0)
1630 (archive-method (gnus-server-to-method "archive"))
1631 infos info group active method cmethod
1632 method-type method-group-list entry
)
1633 (gnus-message 6 "Checking new news...")
1636 (setq active
(gnus-active (setq group
(gnus-info-group
1637 (setq info
(pop newsrc
))))))
1638 ;; First go through all the groups, see what select methods they
1639 ;; belong to, and then collect them into lists per unique select
1641 (if (not (setq method
(gnus-info-method info
)))
1642 (setq method gnus-select-method
)
1643 ;; There may be several similar methods. Possibly extend the
1645 (if (setq cmethod
(assoc method methods-cache
))
1646 (setq method
(cdr cmethod
))
1647 (setq cmethod
(if (stringp method
)
1648 (gnus-server-to-method method
)
1649 (inline (gnus-find-method-for-group
1650 (gnus-info-group info
) info
))))
1651 (push (cons method cmethod
) methods-cache
)
1652 (setq method cmethod
)))
1653 (setq method-group-list
(assoc method type-cache
))
1654 (unless method-group-list
1657 ((or (gnus-secondary-method-p method
)
1658 (and (gnus-archive-server-wanted-p)
1659 (gnus-methods-equal-p archive-method method
)))
1661 ((inline (gnus-server-equal gnus-select-method method
))
1665 (push (setq method-group-list
(list method method-type nil nil
))
1667 ;; Only add groups that need updating.
1668 (if (funcall (if one-level
#'= #'<=) (gnus-info-level info
)
1669 (if (eq (cadr method-group-list
) 'foreign
)
1672 (setcar (nthcdr 2 method-group-list
)
1673 (cons info
(nth 2 method-group-list
)))
1674 ;; The group is inactive, so we nix out the number of unread articles.
1675 ;; It leads `(gnus-group-unread group)' to return t. See also
1676 ;; `gnus-group-prepare-flat'.
1678 (when (setq entry
(gnus-group-entry group
))
1679 (setcar entry t
)))))
1681 ;; Sort the methods based so that the primary and secondary
1682 ;; methods come first. This is done for legacy reasons to try to
1683 ;; ensure that side-effect behavior doesn't change from previous
1686 (sort (nreverse type-cache
)
1688 (< (gnus-method-rank (cadr c1
) (car c1
))
1689 (gnus-method-rank (cadr c2
) (car c2
))))))
1690 ;; Go through the list of servers and possibly extend methods that
1691 ;; aren't equal (and that need extension; i.e., they are async).
1692 (let ((methods nil
))
1693 (dolist (elem type-cache
)
1694 (destructuring-bind (method method-type infos dummy
) elem
1695 (let ((gnus-opened-servers methods
))
1696 (when (and (gnus-similar-server-opened method
)
1697 (gnus-check-backend-function
1698 'retrieve-group-data-early
(car method
)))
1699 (setq method
(gnus-server-extend-method
1700 (gnus-info-group (car infos
))
1702 (setcar elem method
))
1703 (push (list method
'ok
) methods
)))))
1705 ;; If we have primary/secondary select methods, but no groups from
1706 ;; them, we still want to issue a retrieval request from them.
1707 (unless dont-connect
1708 (dolist (method (cons gnus-select-method
1709 gnus-secondary-select-methods
))
1710 (when (and (not (assoc method type-cache
))
1711 (gnus-check-backend-function 'request-list
(car method
)))
1712 (with-current-buffer nntp-server-buffer
1713 (gnus-read-active-file-1 method nil
)))))
1715 ;; Clear out all the early methods.
1716 (dolist (elem type-cache
)
1717 (destructuring-bind (method method-type infos dummy
) elem
1720 (gnus-check-backend-function
1721 'retrieve-group-data-early
(car method
))
1722 (not (gnus-method-denied-p method
)))
1723 (when (ignore-errors (gnus-get-function method
'open-server
))
1724 (unless (gnus-server-opened method
)
1725 (gnus-open-server method
))
1726 (when (gnus-server-opened method
)
1727 ;; Just mark this server as "cleared".
1728 (gnus-retrieve-group-data-early method nil
))))))
1730 ;; Start early async retrieval of data.
1731 (let ((done-methods nil
)
1733 (dolist (elem type-cache
)
1734 (destructuring-bind (method method-type infos dummy
) elem
1735 (setq sanity-spec
(list (car method
) (cadr method
)))
1736 (when (and method infos
1737 (not (gnus-method-denied-p method
)))
1738 ;; If the open-server method doesn't exist, then the method
1739 ;; itself doesn't exist, so we ignore it.
1740 (if (not (ignore-errors (gnus-get-function method
'open-server
)))
1741 (setq type-cache
(delq elem type-cache
))
1742 (unless (gnus-server-opened method
)
1743 (gnus-open-server method
))
1745 ;; This is a sanity check, so that we never
1746 ;; attempt to start two async requests to the
1747 ;; same server, because that will fail. This
1748 ;; should never happen, since the methods should
1749 ;; be unique at this point, but apparently it
1750 ;; does happen in the wild with some setups.
1751 (not (member sanity-spec done-methods
))
1752 (gnus-server-opened method
)
1753 (gnus-check-backend-function
1754 'retrieve-group-data-early
(car method
)))
1755 (push sanity-spec done-methods
)
1756 (when (gnus-check-backend-function 'request-scan
(car method
))
1757 (gnus-request-scan nil method
))
1758 ;; Store the token we get back from -early so that we
1759 ;; can pass it to -finish later.
1760 (setcar (nthcdr 3 elem
)
1761 (gnus-retrieve-group-data-early method infos
))))))))
1763 ;; Do the rest of the retrieval.
1764 (dolist (elem type-cache
)
1765 (destructuring-bind (method method-type infos early-data
) elem
1766 (when (and method infos
1767 (not (gnus-method-denied-p method
)))
1768 (let ((updatep (gnus-check-backend-function
1769 'request-update-info
(car method
))))
1770 ;; See if any of the groups from this method require updating.
1771 (gnus-read-active-for-groups method infos early-data
)
1772 (dolist (info infos
)
1773 (inline (gnus-get-unread-articles-in-group
1774 info
(gnus-active (gnus-info-group info
))
1776 (gnus-message 6 "Checking new news...done")))
1778 (defun gnus-method-rank (type method
)
1780 ;; Get info for virtual groups last.
1781 ((eq (car method
) 'nnvirtual
)
1785 ;; Compute the rank of the secondary methods based on where they
1786 ;; are in the secondary select list.
1787 ((eq type
'secondary
)
1790 (dolist (smethod gnus-secondary-select-methods
)
1791 (when (equal method smethod
)
1795 ;; Just say that all foreign groups have the same rank.
1799 (defun gnus-read-active-for-groups (method infos early-data
)
1800 (with-current-buffer nntp-server-buffer
1802 ;; Finish up getting the data from the methods that have -early
1806 (gnus-check-backend-function 'finish-retrieve-group-infos
(car method
))
1807 (or (not (gnus-agent-method-p method
))
1808 (gnus-online method
)))
1809 (gnus-finish-retrieve-group-infos method infos early-data
)
1810 (gnus-agent-save-active method
))
1811 ;; Most backends have -retrieve-groups.
1812 ((gnus-check-backend-function 'retrieve-groups
(car method
))
1813 (when (gnus-check-backend-function 'request-scan
(car method
))
1814 (gnus-request-scan nil method
))
1816 (gnus-read-active-file-2
1817 (dolist (info infos
(nreverse groups
))
1818 (push (gnus-group-real-name (gnus-info-group info
)) groups
))
1820 ;; Virtually all backends have -request-list.
1821 ((gnus-check-backend-function 'request-list
(car method
))
1822 (gnus-read-active-file-1 method nil
))
1823 ;; Except nnvirtual and friends, where we request each group, one
1826 (dolist (info infos
)
1827 (gnus-activate-group (gnus-info-group info
) nil nil method t
))))))
1829 ;; Create a hash table out of the newsrc alist. The `car's of the
1830 ;; alist elements are used as keys.
1831 (defun gnus-make-hashtable-from-newsrc-alist ()
1832 (let ((alist gnus-newsrc-alist
)
1833 (ohashtb gnus-newsrc-hashtb
)
1834 prev info method rest methods
)
1835 (setq gnus-newsrc-hashtb
(gnus-make-hashtable (length alist
)))
1837 (setq prev
(setq gnus-newsrc-alist
1838 (if (equal (caar gnus-newsrc-alist
)
1841 (cons (list "dummy.group" 0 nil
) alist
)))))
1843 (setq info
(car alist
))
1844 ;; Make the same select-methods identical Lisp objects.
1845 (when (setq method
(gnus-info-method info
))
1846 (if (setq rest
(member method methods
))
1847 (gnus-info-set-method info
(car rest
))
1848 (push method methods
)))
1849 ;; Check for duplicates.
1850 (if (gnus-gethash (car info
) gnus-newsrc-hashtb
)
1851 ;; Remove this entry from the alist.
1852 (setcdr prev
(cddr prev
))
1855 ;; Preserve number of unread articles in groups.
1856 (cons (and ohashtb
(car (gnus-gethash (car info
) ohashtb
)))
1860 (setq alist
(cdr alist
)))
1861 ;; Make the same select-methods in `gnus-server-alist' identical
1864 (setq method
(pop methods
))
1865 (when (setq rest
(rassoc method gnus-server-alist
))
1866 (setcdr rest method
)))))
1868 (defun gnus-make-hashtable-from-killed ()
1869 "Create a hash table from the killed and zombie lists."
1870 (let ((lists '(gnus-killed-list gnus-zombie-list
))
1872 (setq gnus-killed-hashtb
1873 (gnus-make-hashtable
1874 (+ (length gnus-killed-list
) (length gnus-zombie-list
))))
1876 (setq list
(symbol-value (pop lists
)))
1878 (gnus-sethash (car list
) (pop list
) gnus-killed-hashtb
)))))
1880 (defun gnus-parse-active ()
1881 "Parse active info in the nntp server buffer."
1882 (with-current-buffer nntp-server-buffer
1883 (goto-char (point-min))
1884 ;; Parse the result we got from `gnus-request-group'.
1885 (when (looking-at "[0-9]+ [0-9]+ \\([0-9]+\\) [0-9]+")
1886 (goto-char (match-beginning 1))
1887 (cons (read (current-buffer))
1888 (read (current-buffer))))))
1890 (defun gnus-make-articles-unread (group articles
)
1891 "Mark ARTICLES in GROUP as unread."
1892 (let* ((info (nth 2 (or (gnus-group-entry group
)
1894 (gnus-group-real-name group
)))))
1895 (ranges (gnus-info-read info
))
1898 (when (gnus-member-of-range
1899 (setq article
(pop articles
)) ranges
)
1900 (push article news
)))
1902 ;; Enter this list into the group info.
1904 info
(gnus-remove-from-range (gnus-info-read info
) (nreverse news
)))
1906 ;; Set the number of unread articles in gnus-newsrc-hashtb.
1907 (gnus-get-unread-articles-in-group info
(gnus-active group
))
1909 ;; Insert the change into the group buffer and the dribble file.
1910 (gnus-group-update-group group t
))))
1912 (defun gnus-make-ascending-articles-unread (group articles
)
1913 "Mark ascending ARTICLES in GROUP as unread."
1914 (let* ((entry (or (gnus-group-entry group
)
1915 (gnus-group-entry (gnus-group-real-name group
))))
1916 (info (nth 2 entry
))
1917 (ranges (gnus-info-read info
))
1922 (let ((article (pop articles
))) ; get the next article to remove from ranges
1923 (while (let ((range (car ranges
))) ; note the current range
1924 (if (atom range
) ; single value range
1926 ;; the articles extend past the end of the ranges
1928 (setq articles nil
))
1930 ;; this range precedes the article. Leave the range unmodified.
1934 ;; this range exactly matches the article; REMOVE THE RANGE.
1935 ;; NOTE: When the range being removed is the last range, the list is corrupted by inserting null at its end.
1936 (setcar ranges
(cadr ranges
))
1937 (setcdr ranges
(cddr ranges
))
1938 (setq modified
(if (car ranges
) t
'remove-null
))
1940 (let ((min (car range
))
1942 ;; I have a min/max range to consider
1943 (cond ((> min max
) ; invalid range introduced by splitter
1944 (setcar ranges
(cadr ranges
))
1945 (setcdr ranges
(cddr ranges
))
1946 (setq modified
(if (car ranges
) t
'remove-null
))
1949 ;; replace min/max range with a single-value range
1953 ;; this range precedes the article. Leave the range unmodified.
1957 ;; this article precedes the range. Return null to move to the
1961 ;; this article splits the range into two parts
1962 (setcdr ranges
(cons (cons (1+ article
) max
) (cdr ranges
)))
1963 (setcdr range
(1- article
))
1968 (when (eq modified
'remove-null
)
1969 (setq r
(delq nil r
)))
1970 ;; Enter this list into the group info.
1971 (gnus-info-set-read info r
)
1973 ;; Set the number of unread articles in gnus-newsrc-hashtb.
1974 (gnus-get-unread-articles-in-group info
(gnus-active group
))
1976 ;; Insert the change into the group buffer and the dribble file.
1977 (gnus-group-update-group group t
))))
1979 ;; Enter all dead groups into the hashtb.
1980 (defun gnus-update-active-hashtb-from-killed ()
1981 (let ((hashtb (setq gnus-active-hashtb
(gnus-make-hashtable 4096)))
1982 (lists (list gnus-killed-list gnus-zombie-list
))
1985 (setq killed
(car lists
))
1987 (gnus-sethash (mm-string-as-unibyte (car killed
)) nil hashtb
)
1988 (setq killed
(cdr killed
)))
1989 (setq lists
(cdr lists
)))))
1991 (defun gnus-get-killed-groups ()
1992 "Go through the active hashtb and mark all unknown groups as killed."
1993 ;; First make sure active file has been read.
1994 (unless (gnus-read-active-file-p)
1995 (let ((gnus-read-active-file t
))
1996 (gnus-read-active-file)))
1997 (unless gnus-killed-hashtb
1998 (gnus-make-hashtable-from-killed))
1999 ;; Go through all newsgroups that are known to Gnus - enlarge kill list.
2003 (group (symbol-name sym
)))
2004 (if (or (null group
)
2005 (gnus-gethash group gnus-killed-hashtb
)
2006 (gnus-gethash group gnus-newsrc-hashtb
))
2008 (let ((do-sub (gnus-matches-options-n group
)))
2009 (if (or (eq do-sub
'subscribe
) (eq do-sub
'ignore
))
2011 (setq groups
(1+ groups
))
2012 (push group gnus-killed-list
)
2013 (gnus-sethash group group gnus-killed-hashtb
))))))
2015 (gnus-dribble-touch))
2017 ;; Get the active file(s) from the backend(s).
2018 (defun gnus-read-active-file (&optional force not-native
)
2019 (gnus-group-set-mode-line)
2022 (lambda (m) (if (stringp m
) (gnus-server-get-method nil m
) m
))
2024 (if (and (not not-native
)
2025 (gnus-check-server gnus-select-method
))
2026 ;; The native server is available.
2027 (cons gnus-select-method gnus-secondary-select-methods
)
2028 ;; The native server is down, so we just do the
2030 gnus-secondary-select-methods
)
2031 ;; Also read from the archive server.
2032 (when (gnus-archive-server-wanted-p)
2033 (list "archive")))))
2035 (setq gnus-have-read-active-file nil
)
2036 (with-current-buffer nntp-server-buffer
2037 (while (setq method
(pop methods
))
2038 ;; Only do each method once, in case the methods appear more
2039 ;; than once in this list.
2040 (when (and (not (member method methods
))
2041 ;; Check whether the backend exists.
2042 (ignore-errors (gnus-get-function method
'open-server
)))
2043 (if (or debug-on-error debug-on-quit
)
2044 (gnus-read-active-file-1 method force
)
2046 (gnus-read-active-file-1 method force
)
2047 ;; We catch C-g so that we can continue past servers
2048 ;; that do not respond.
2052 (message "Quit reading the active file"))
2055 (defun gnus-read-active-file-1 (method force
)
2057 (setq where
(nth 1 method
)
2058 mesg
(format "Reading active file%s via %s..."
2059 (if (and where
(not (zerop (length where
))))
2060 (concat " from " where
) "")
2062 (gnus-message 5 "%s" mesg
)
2063 (when (gnus-check-server method
)
2064 ;; Request that the backend scan its incoming messages.
2065 (when (and (or (and gnus-agent
2066 (gnus-online method
))
2068 (gnus-check-backend-function 'request-scan
(car method
)))
2069 (gnus-request-scan nil method
))
2071 ((and (eq gnus-read-active-file
'some
)
2072 (gnus-check-backend-function 'retrieve-groups
(car method
))
2074 (let ((newsrc (cdr gnus-newsrc-alist
))
2075 (gmethod (gnus-server-get-method nil method
))
2077 (while (setq info
(pop newsrc
))
2081 (gnus-find-method-for-group
2082 (gnus-info-group info
) info
))
2084 (push (gnus-group-real-name (gnus-info-group info
))
2086 (gnus-read-active-file-2 groups method
)))
2090 (if (not (gnus-request-list method
))
2091 (unless (equal method gnus-message-archive-method
)
2092 (gnus-error 1 "Cannot read active file from %s server"
2094 (gnus-message 5 "%s" mesg
)
2095 (gnus-active-to-gnus-format method gnus-active-hashtb nil t
)
2096 ;; We mark this active file as read.
2097 (add-to-list 'gnus-have-read-active-file method
)
2098 (gnus-message 5 "%sdone" mesg
)))))))
2100 (defun gnus-read-active-file-2 (groups method
)
2101 "Read an active file for GROUPS in METHOD using `gnus-retrieve-groups'."
2103 (with-current-buffer nntp-server-buffer
2104 (gnus-check-server method
)
2105 (let ((list-type (gnus-retrieve-groups groups method
)))
2106 (cond ((not list-type
)
2108 1.2 "Cannot read partial active file from %s server."
2110 ((eq list-type
'active
)
2111 (gnus-active-to-gnus-format method gnus-active-hashtb nil t
))
2113 (gnus-groups-to-gnus-format method gnus-active-hashtb t
)))))))
2115 ;; Read an active file and place the results in `gnus-active-hashtb'.
2116 (defun gnus-active-to-gnus-format (&optional method hashtb ignore-errors
2119 (setq method gnus-select-method
))
2120 (let ((cur (current-buffer))
2122 (if (and gnus-active-hashtb
2123 (not (equal method gnus-select-method
)))
2125 (setq gnus-active-hashtb
2126 (if (equal method gnus-select-method
)
2127 (gnus-make-hashtable
2128 (count-lines (point-min) (point-max)))
2129 (gnus-make-hashtable 4096))))))
2131 ;; Delete unnecessary lines.
2132 (goto-char (point-min))
2134 ((string= gnus-ignored-newsgroups
"")
2135 (delete-matching-lines "^to\\."))
2137 (delete-matching-lines (concat "^to\\.\\|" gnus-ignored-newsgroups
))))
2139 (goto-char (point-min))
2140 (unless (re-search-forward "[\\\"]" nil t
)
2141 ;; Make the group names readable as a lisp expression even if they
2142 ;; contain special characters.
2143 (goto-char (point-max))
2144 (while (re-search-backward "[][';?()#]" nil t
)
2147 ;; Let the Gnus agent save the active file.
2148 (when (and gnus-agent real-active
(gnus-online method
))
2149 (gnus-agent-save-active method
))
2151 ;; If these are groups from a foreign select method, we insert the
2152 ;; group prefix in front of the group names.
2153 (when (not (gnus-server-equal
2154 (gnus-server-get-method nil method
)
2155 (gnus-server-get-method nil gnus-select-method
)))
2156 (let ((prefix (gnus-group-prefixed-name "" method
)))
2157 (goto-char (point-min))
2158 (while (and (not (eobp))
2160 (when (= (following-char) ?
\")
2163 (zerop (forward-line 1)))))))
2164 ;; Store the active file in a hash table.
2165 ;; Use a unibyte buffer in order to make `read' read non-ASCII
2166 ;; group names (which have been encoded) as unibyte strings.
2167 (mm-with-unibyte-buffer
2168 (insert-buffer-substring cur
)
2169 (setq cur
(current-buffer))
2170 (goto-char (point-min))
2174 (narrow-to-region (point) (point-at-eol))
2175 ;; group gets set to a symbol interned in the hash table
2176 ;; (what a hack!!) - jwz
2177 (setq group
(let ((obarray hashtb
)) (read cur
)))
2178 ;; ### The extended group name scheme makes
2179 ;; the previous optimization strategy sort of pointless...
2180 (when (stringp group
)
2181 (setq group
(intern group hashtb
)))
2182 (if (and (numberp (setq max
(read cur
)))
2183 (numberp (setq min
(read cur
)))
2185 (skip-chars-forward " \t")
2187 (or (eq (char-after) ?
=)
2188 (eq (char-after) ?x
)
2189 (eq (char-after) ?j
)))))
2191 (set group
(cons min max
))
2192 ;; if group is moderated, stick in moderation table
2193 (when (eq (char-after) ?m
)
2194 (unless gnus-moderated-hashtb
2195 (setq gnus-moderated-hashtb
(gnus-make-hashtable)))
2196 (gnus-sethash (symbol-name group
) t
2197 gnus-moderated-hashtb
)))
2203 (unless ignore-errors
2204 (gnus-message 3 "Warning - invalid active: %s"
2206 (point-at-bol) (point-at-eol))))))
2208 (forward-line 1)))))
2210 (defun gnus-groups-to-gnus-format (method &optional hashtb real-active
)
2211 ;; Parse a "groups" active file.
2212 (let ((cur (current-buffer))
2214 (if (and method gnus-active-hashtb
)
2216 (setq gnus-active-hashtb
2217 (gnus-make-hashtable
2218 (count-lines (point-min) (point-max)))))))
2220 (not (gnus-server-equal
2221 (gnus-server-get-method nil method
)
2222 (gnus-server-get-method nil gnus-select-method
)))
2223 (gnus-group-prefixed-name "" method
))))
2225 ;; Let the Gnus agent save the active file.
2228 (gnus-online method
)
2229 (gnus-agent-method-p method
))
2231 (gnus-agent-save-active method t
)
2232 (gnus-active-to-gnus-format method hashtb nil real-active
))
2234 (goto-char (point-min))
2235 ;; We split this into to separate loops, one with the prefix
2236 ;; and one without to speed the reading up somewhat.
2238 (let (min max opoint group
)
2242 (read cur
) (read cur
)
2243 (setq min
(read cur
)
2246 (skip-chars-forward " \t")
2249 (set (let ((obarray hashtb
)) (read cur
))
2251 (error (and group
(symbolp group
) (set group nil
))))
2253 (let (min max group
)
2256 (when (eq (char-after) ?
2)
2257 (read cur
) (read cur
)
2258 (setq min
(read cur
)
2260 (set (setq group
(let ((obarray hashtb
)) (read cur
)))
2262 (error (and group
(symbolp group
) (set group nil
))))
2263 (forward-line 1)))))))
2265 (defun gnus-read-newsrc-file (&optional force
)
2267 If FORCE is non-nil, the .newsrc file is read."
2268 ;; Reset variables that might be defined in the .newsrc.eld file.
2269 (let ((variables (remove 'gnus-format-specs gnus-variable-list
)))
2271 (set (car variables
) nil
)
2272 (setq variables
(cdr variables
))))
2273 (let* ((newsrc-file gnus-current-startup-file
)
2274 (quick-file (concat newsrc-file
".el")))
2276 ;; We always load the .newsrc.eld file. If always contains
2277 ;; much information that can not be gotten from the .newsrc
2278 ;; file (ticked articles, killed groups, foreign methods, etc.)
2279 (gnus-read-newsrc-el-file quick-file
)
2281 (when (and gnus-read-newsrc-file
2282 (file-exists-p gnus-current-startup-file
)
2284 (and (file-newer-than-file-p newsrc-file quick-file
)
2285 (file-newer-than-file-p newsrc-file
2286 (concat quick-file
"d")))
2287 (not gnus-newsrc-alist
)))
2288 ;; We read the .newsrc file. Note that if there if a
2289 ;; .newsrc.eld file exists, it has already been read, and
2290 ;; the `gnus-newsrc-hashtb' has been created. While reading
2291 ;; the .newsrc file, Gnus will only use the information it
2292 ;; can find there for changing the data already read -
2293 ;; i. e., reading the .newsrc file will not trash the data
2294 ;; already read (except for read articles).
2296 (gnus-message 5 "Reading %s..." newsrc-file
)
2297 (set-buffer (nnheader-find-file-noselect newsrc-file
))
2298 (buffer-disable-undo)
2299 (gnus-newsrc-to-gnus-format)
2300 (kill-buffer (current-buffer))
2301 (gnus-message 5 "Reading %s...done" newsrc-file
)))
2303 ;; Convert old to new.
2304 (gnus-convert-old-newsrc))))
2306 (defun gnus-convert-old-newsrc ()
2307 "Convert old newsrc formats into the current format, if needed."
2308 (let ((fcv (and gnus-newsrc-file-version
2309 (gnus-continuum-version gnus-newsrc-file-version
)))
2310 (gcv (gnus-continuum-version)))
2312 ;; A newsrc file was loaded.
2313 (let (prompt-displayed
2316 (mapcar (lambda (date-func)
2317 (cons (gnus-continuum-version (car date-func
))
2319 ;; This is a list of converters that must be run
2320 ;; to bring the newsrc file up to the current
2321 ;; version. If you create an incompatibility
2322 ;; with older versions, you should create an
2323 ;; entry here. The entry should consist of the
2324 ;; current gnus version (hardcoded so that it
2325 ;; doesn't change with each release) and the
2326 ;; function that must be applied to convert the
2327 ;; previous version into the current version.
2328 '(("September Gnus v0.1" nil
2329 gnus-convert-old-ticks
)
2330 ("Oort Gnus v0.08" "legacy-gnus-agent"
2331 gnus-agent-convert-to-compressed-agentview
)
2332 ("Gnus v5.10.7" "legacy-gnus-agent"
2333 gnus-agent-unlist-expire-days
)
2334 ("Gnus v5.10.7" "legacy-gnus-agent"
2335 gnus-agent-unhook-expire-days
)))
2336 #'car-less-than-car
)))
2337 ;; Skip converters older than the file version
2338 (while (and converters
(>= fcv
(caar converters
)))
2341 ;; Perform converters to bring older version up to date.
2342 (when (and converters
(< fcv
(caar converters
)))
2343 (while (and converters
(< fcv
(caar converters
))
2344 (<= (caar converters
) gcv
))
2345 (let* ((converter-spec (pop converters
))
2346 (convert-to (nth 1 converter-spec
))
2347 (load-from (nth 2 converter-spec
))
2348 (func (nth 3 converter-spec
)))
2349 (when (and load-from
2350 (not (fboundp func
)))
2352 (or prompt-displayed
2353 (not (gnus-convert-converter-needs-prompt func
))
2355 (cursor-in-echo-area t
)
2356 (echo-keystrokes 0))
2357 (message "Convert gnus from version '%s' to '%s'? (n/y/?)"
2358 gnus-newsrc-file-version gnus-version
)
2359 (setq c
(read-char-exclusive))
2361 (cond ((or (eq c ?n
) (eq c ?N
))
2362 (error "Can not start gnus without converting"))
2363 ((or (eq c ?y
) (eq c ?Y
))
2364 (setq prompt-displayed t
)
2367 (message "This conversion is irreversible. \
2368 To be safe, you should backup your files before proceeding.")
2372 (gnus-message 3 "Ignoring unexpected input")
2376 (funcall func convert-to
)))
2378 (format ";Converted gnus from version '%s' to '%s'."
2379 gnus-newsrc-file-version gnus-version
)))))))
2381 (defun gnus-convert-mark-converter-prompt (converter no-prompt
)
2382 "Indicate whether CONVERTER requires gnus-convert-old-newsrc to
2383 display the conversion prompt. NO-PROMPT may be nil (prompt),
2384 t (no prompt), or any form that can be called as a function.
2385 The form should return either t or nil."
2386 (put converter
'gnus-convert-no-prompt no-prompt
))
2388 (defun gnus-convert-converter-needs-prompt (converter)
2389 (let ((no-prompt (get converter
'gnus-convert-no-prompt
)))
2390 (not (if (memq no-prompt
'(t nil
))
2392 (funcall no-prompt
)))))
2394 (defun gnus-convert-old-ticks (converting-to)
2395 (let ((newsrc (cdr gnus-newsrc-alist
))
2396 marks info dormant ticked
)
2397 (while (setq info
(pop newsrc
))
2398 (when (setq marks
(gnus-info-marks info
))
2399 (setq dormant
(cdr (assq 'dormant marks
))
2400 ticked
(cdr (assq 'tick marks
)))
2401 (when (or dormant ticked
)
2405 (gnus-info-read info
)
2406 (nconc (gnus-uncompress-range dormant
)
2407 (gnus-uncompress-range ticked
)))))))))
2409 (defun gnus-load (file)
2410 "Load FILE, but in such a way that read errors can be reported."
2412 (insert-file-contents file
)
2414 (condition-case type
2415 (let ((form (read (current-buffer))))
2418 (unless (eq (car type
) 'end-of-file
)
2419 (let ((errmsg (format "Error in %s line %d" file
2420 (count-lines (point-min) (point)))))
2422 (unless (gnus-yes-or-no-p (concat errmsg
"; continue? "))
2423 (error "%s" errmsg
)))))))))
2425 (defun gnus-read-newsrc-el-file (file)
2426 (let ((ding-file (concat file
"d")))
2427 (when (file-exists-p ding-file
)
2428 ;; We always, always read the .eld file.
2429 (gnus-message 5 "Reading %s..." ding-file
)
2430 (let (gnus-newsrc-assoc)
2431 (gnus-load ding-file
)
2432 ;; Older versions of `gnus-format-specs' are no longer valid
2433 ;; in Oort Gnus 0.01.
2435 (and gnus-newsrc-file-version
2436 (gnus-continuum-version gnus-newsrc-file-version
))))
2437 (when (or (not version
)
2438 (< version
5.090009))
2439 (setq gnus-format-specs gnus-default-format-specs
)))
2440 (when gnus-newsrc-assoc
2441 (setq gnus-newsrc-alist gnus-newsrc-assoc
))))
2442 (dolist (elem gnus-newsrc-alist
)
2443 ;; Protect against broken .newsrc.el files.
2445 (setcar elem
(mm-string-as-unibyte (car elem
)))))
2446 (gnus-make-hashtable-from-newsrc-alist)
2447 (when (file-newer-than-file-p file ding-file
)
2448 ;; Old format quick file
2449 (gnus-message 5 "Reading %s..." file
)
2450 ;; The .el file is newer than the .eld file, so we read that one
2452 (gnus-read-old-newsrc-el-file file
)))
2453 (gnus-run-hooks 'gnus-read-newsrc-el-hook
))
2455 ;; Parse the old-style quick startup file
2456 (defun gnus-read-old-newsrc-el-file (file)
2457 (let (newsrc killed marked group m info
)
2459 (let ((gnus-killed-assoc nil
)
2460 gnus-marked-assoc gnus-newsrc-alist gnus-newsrc-assoc
)
2464 (setq newsrc gnus-newsrc-assoc
2465 killed gnus-killed-assoc
2466 marked gnus-marked-assoc
)))
2467 (setq gnus-newsrc-alist nil
)
2468 (while (setq group
(pop newsrc
))
2469 (if (setq info
(gnus-get-info (car group
)))
2471 (gnus-info-set-read info
(cddr group
))
2472 (gnus-info-set-level
2473 info
(if (nth 1 group
) gnus-level-default-subscribed
2474 gnus-level-default-unsubscribed
))
2475 (push info gnus-newsrc-alist
))
2478 (if (nth 1 group
) gnus-level-default-subscribed
2479 gnus-level-default-unsubscribed
)
2482 ;; Copy marks into info.
2483 (when (setq m
(assoc (car group
) marked
))
2484 (unless (nthcdr 3 info
)
2485 (nconc info
(list nil
)))
2486 (gnus-info-set-marks
2487 info
(list (cons 'tick
(gnus-compress-sequence
2488 (sort (cdr m
) '<) t
))))))
2489 (setq newsrc killed
)
2491 (setcar newsrc
(caar newsrc
))
2492 (setq newsrc
(cdr newsrc
)))
2493 (setq gnus-killed-list killed
))
2494 ;; The .el file version of this variable does not begin with
2495 ;; "options", while the .eld version does, so we just add it if it
2499 (when (not (string-match "^ *options" gnus-newsrc-options
))
2500 (setq gnus-newsrc-options
(concat "options " gnus-newsrc-options
)))
2501 (when (not (string-match "\n$" gnus-newsrc-options
))
2502 (setq gnus-newsrc-options
(concat gnus-newsrc-options
"\n")))
2503 ;; Finally, if we read some options lines, we parse them.
2504 (unless (string= gnus-newsrc-options
"")
2505 (gnus-newsrc-parse-options gnus-newsrc-options
)))
2507 (setq gnus-newsrc-alist
(nreverse gnus-newsrc-alist
))
2508 (gnus-make-hashtable-from-newsrc-alist)))
2510 (defun gnus-make-newsrc-file (file)
2511 "Make server dependent file name by catenating FILE and server host name."
2512 (let* ((file (expand-file-name file nil
))
2513 (real-file (concat file
"-" (nth 1 gnus-select-method
))))
2514 (if (or (file-exists-p real-file
)
2515 (file-exists-p (concat real-file
".el"))
2516 (file-exists-p (concat real-file
".eld")))
2520 (defun gnus-newsrc-to-gnus-format ()
2521 (setq gnus-newsrc-options
"")
2522 (setq gnus-newsrc-options-n nil
)
2524 (unless gnus-active-hashtb
2525 (setq gnus-active-hashtb
(gnus-make-hashtable 4096)))
2526 (let ((buf (current-buffer))
2527 (already-read (> (length gnus-newsrc-alist
) 1))
2528 group subscribed options-symbol newsrc Options-symbol
2530 (goto-char (point-min))
2531 ;; We intern the symbol `options' in the active hashtb so that we
2532 ;; can `eq' against it later.
2533 (set (setq options-symbol
(intern "options" gnus-active-hashtb
)) nil
)
2534 (set (setq Options-symbol
(intern "Options" gnus-active-hashtb
)) nil
)
2537 ;; We first read the first word on the line by narrowing and
2538 ;; then reading into `gnus-active-hashtb'. Most groups will
2539 ;; already exist in that hashtb, so this will save some string
2543 (progn (skip-chars-forward "^ \t!:\n") (point)))
2544 (goto-char (point-min))
2546 (and (/= (point-min) (point-max))
2547 (let ((obarray gnus-active-hashtb
)) (read buf
))))
2549 ;; Now, the symbol we have read is either `options' or a group
2550 ;; name. If it is an options line, we just add it to a string.
2552 ((or (eq symbol options-symbol
)
2553 (eq symbol Options-symbol
))
2554 (setq gnus-newsrc-options
2555 ;; This concatting is quite inefficient, but since our
2556 ;; thorough studies show that approx 99.37% of all
2557 ;; .newsrc files only contain a single options line, we
2558 ;; don't give a damn, frankly, my dear.
2559 (concat gnus-newsrc-options
2562 ;; Options may continue on the next line.
2563 (or (and (re-search-forward "^[^ \t]" nil
'move
)
2568 ;; Group names can be just numbers.
2569 (when (numberp symbol
)
2570 (setq symbol
(intern (int-to-string symbol
) gnus-active-hashtb
)))
2571 (unless (boundp symbol
)
2573 ;; It was a group name.
2574 (setq subscribed
(eq (char-after) ?
:)
2575 group
(symbol-name symbol
)
2578 ;; If the line ends here, this is clearly a buggy line, so
2579 ;; we put point a the beginning of line and let the cond
2580 ;; below do the error handling.
2582 ;; We skip to the beginning of the ranges.
2583 (skip-chars-forward "!: \t"))
2584 ;; We are now at the beginning of the list of read articles.
2585 ;; We read them range by range.
2588 ((looking-at "[0-9]+")
2589 ;; We narrow and read a number instead of buffer-substring/
2590 ;; string-to-number because it's faster. narrow/widen is
2591 ;; faster than save-restriction/narrow, and save-restriction
2592 ;; produces a garbage object.
2594 (narrow-to-region (match-beginning 0) (match-end 0))
2597 ;; If the next character is a dash, then this is a range.
2598 (if (eq (char-after) ?-
)
2600 ;; We read the upper bound of the range.
2602 (if (not (looking-at "[0-9]+"))
2603 ;; This is a buggy line, by we pretend that
2604 ;; it's kinda OK. Perhaps the user should be
2610 (narrow-to-region (match-beginning 0)
2615 ;; It was just a simple number, so we add it to the
2618 ;; If the next char in ?\n, then we have reached the end
2619 ;; of the line and return nil.
2620 (not (eq (char-after) ?
\n)))
2621 ((eq (char-after) ?
\n)
2622 ;; End of line, so we end.
2625 ;; Not numbers and not eol, so this might be a buggy
2628 ;; If it was eob instead of ?\n, we allow it.
2629 ;; The line was buggy.
2631 (gnus-error 3.1 "Mangled line: %s"
2632 (buffer-substring (point-at-bol)
2635 ;; Skip past ", ". Spaces are invalid in these ranges, but
2636 ;; we allow them, because it's a common mistake to put a
2637 ;; space after the comma.
2638 (skip-chars-forward ", "))
2640 ;; We have already read .newsrc.eld, so we gently update the
2641 ;; data in the hash table with the information we have just
2644 (let ((info (gnus-get-info group
))
2647 ;; There is an entry for this file in the alist.
2649 (gnus-info-set-read info
(nreverse reads
))
2650 ;; We update the level very gently. In fact, we
2651 ;; only change it if there's been a status change
2652 ;; from subscribed to unsubscribed, or vice versa.
2653 (setq level
(gnus-info-level info
))
2654 (cond ((and (<= level gnus-level-subscribed
)
2656 (setq level
(if reads
2657 gnus-level-default-unsubscribed
2658 (1+ gnus-level-default-unsubscribed
))))
2659 ((and (> level gnus-level-subscribed
) subscribed
)
2660 (setq level gnus-level-default-subscribed
)))
2661 (gnus-info-set-level info level
))
2662 ;; This is a new group.
2663 (setq info
(list group
2665 gnus-level-default-subscribed
2667 (1+ gnus-level-subscribed
)
2668 gnus-level-default-unsubscribed
))
2670 (push info newsrc
)))))
2673 (setq newsrc
(nreverse newsrc
))
2675 (if (not already-read
)
2677 ;; We now have two newsrc lists - `newsrc', which is what we
2678 ;; have read from .newsrc, and `gnus-newsrc-alist', which is
2679 ;; what we've read from .newsrc.eld. We have to merge these
2680 ;; lists. We do this by "attaching" any (foreign) groups in the
2681 ;; gnus-newsrc-alist to the (native) group that precedes them.
2682 (let ((rc (cdr gnus-newsrc-alist
))
2683 (prev gnus-newsrc-alist
)
2686 (or (null (nth 4 (car rc
))) ; It's a native group.
2687 (assoc (caar rc
) newsrc
) ; It's already in the alist.
2688 (if (setq entry
(assoc (caar prev
) newsrc
))
2689 (setcdr (setq mentry
(memq entry newsrc
))
2690 (cons (car rc
) (cdr mentry
)))
2691 (push (car rc
) newsrc
)))
2695 (setq gnus-newsrc-alist newsrc
)
2696 ;; We make the newsrc hashtb.
2697 (gnus-make-hashtable-from-newsrc-alist)
2699 ;; Finally, if we read some options lines, we parse them.
2700 (unless (string= gnus-newsrc-options
"")
2701 (gnus-newsrc-parse-options gnus-newsrc-options
))))
2703 ;; Parse options lines to find "options -n !all rec.all" and stuff.
2704 ;; The return value will be a list on the form
2705 ;; ((regexp1 . ignore)
2706 ;; (regexp2 . subscribe)...)
2707 ;; When handling new newsgroups, groups that match a `ignore' regexp
2708 ;; will be ignored, and groups that match a `subscribe' regexp will be
2709 ;; subscribed. A line like
2710 ;; options -n !all rec.all
2711 ;; will lead to a list that looks like
2712 ;; (("^rec\\..+" . subscribe)
2713 ;; ("^.+" . ignore))
2714 ;; So all "rec.*" groups will be subscribed, while all the other
2715 ;; groups will be ignored. Note that "options -n !all rec.all" is very
2716 ;; different from "options -n rec.all !all".
2717 (defun gnus-newsrc-parse-options (options)
2720 (gnus-set-work-buffer)
2721 (insert (regexp-quote options
))
2722 ;; First we treat all continuation lines.
2723 (goto-char (point-min))
2724 (while (re-search-forward "\n[ \t]+" nil t
)
2725 (replace-match " " t t
))
2726 ;; Then we transform all "all"s into ".+"s.
2727 (goto-char (point-min))
2728 (while (re-search-forward "\\ball\\b" nil t
)
2729 (replace-match ".+" t t
))
2730 (goto-char (point-min))
2731 ;; We remove all other options than the "-n" ones.
2732 (while (re-search-forward "[ \t]-[^n][^-]*" nil t
)
2735 (goto-char (point-min))
2737 ;; We are only interested in "options -n" lines - we
2738 ;; ignore the other option lines.
2739 (while (re-search-forward "[ \t]-n" nil t
)
2742 (and (re-search-forward "[ \t]-n" (point-at-eol) t
)
2745 ;; Search for all "words"...
2746 (while (re-search-forward "[^ \t,\n]+" eol t
)
2747 (if (eq (char-after (match-beginning 0)) ?
!)
2748 ;; If the word begins with a bang (!), this is a "not"
2749 ;; spec. We put this spec (minus the bang) and the
2750 ;; symbol `ignore' into the list.
2752 "^" (buffer-substring
2753 (1+ (match-beginning 0))
2758 ;; There was no bang, so this is a "yes" spec.
2759 (push (cons (concat "^" (match-string 0) "\\($\\|\\.\\)")
2763 (setq gnus-newsrc-options-n out
))))
2766 (defalias 'gnus-long-file-names
2767 (if (fboundp 'msdos-long-file-names
)
2768 'msdos-long-file-names
2771 (defun gnus-save-newsrc-file (&optional force
)
2772 "Save .newsrc file."
2773 ;; Note: We cannot save .newsrc file if all newsgroups are removed
2774 ;; from the variable gnus-newsrc-alist.
2775 (when (and (or gnus-newsrc-alist gnus-killed-list
)
2776 gnus-current-startup-file
)
2777 ;; Save agent range limits for the currently active method.
2779 (gnus-agent-save-local force
))
2782 (if (and (or gnus-use-dribble-file gnus-slave
)
2784 (or (not gnus-dribble-buffer
)
2785 (not (buffer-name gnus-dribble-buffer
))
2786 (zerop (with-current-buffer gnus-dribble-buffer
2788 (gnus-message 4 "(No changes need to be saved)")
2789 (gnus-run-hooks 'gnus-save-newsrc-hook
)
2791 (gnus-slave-save-newsrc)
2793 (when gnus-save-newsrc-file
2794 (gnus-message 8 "Saving %s..." gnus-current-startup-file
)
2795 (gnus-gnus-to-newsrc-format)
2796 (gnus-message 8 "Saving %s...done" gnus-current-startup-file
))
2798 ;; Save .newsrc.eld.
2799 (set-buffer (gnus-get-buffer-create " *Gnus-newsrc*"))
2800 (make-local-variable 'version-control
)
2801 (setq version-control gnus-backup-startup-file
)
2802 (setq buffer-file-name
2803 (concat gnus-current-startup-file
".eld"))
2804 (setq default-directory
(file-name-directory buffer-file-name
))
2805 (buffer-disable-undo)
2807 (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file
)
2809 (if gnus-save-startup-file-via-temp-buffer
2810 (let ((coding-system-for-write gnus-ding-file-coding-system
)
2811 (standard-output (current-buffer)))
2812 (gnus-gnus-to-quick-newsrc-format)
2813 (gnus-run-hooks 'gnus-save-quick-newsrc-hook
)
2815 (let ((coding-system-for-write gnus-ding-file-coding-system
)
2816 (version-control gnus-backup-startup-file
)
2817 (startup-file (concat gnus-current-startup-file
".eld"))
2818 (working-dir (file-name-directory gnus-current-startup-file
))
2821 ;; Generate the name of a non-existent file.
2822 (while (progn (setq working-file
2824 (if (and (eq system-type
'ms-dos
)
2825 (not (gnus-long-file-names)))
2826 "%s#%d.tm#" ; MSDOS limits files to 8+3
2828 working-dir
(setq i
(1+ i
))))
2829 (file-exists-p working-file
)))
2833 (gnus-with-output-to-file working-file
2834 (gnus-gnus-to-quick-newsrc-format)
2835 (gnus-run-hooks 'gnus-save-quick-newsrc-hook
))
2837 ;; These bindings will mislead the current buffer
2838 ;; into thinking that it is visiting the startup
2840 (let ((buffer-backed-up nil
)
2841 (buffer-file-name startup-file
)
2842 (file-precious-flag t
)
2843 (setmodes (file-modes startup-file
)))
2844 ;; Backup the current version of the startup file.
2847 ;; Replace the existing startup file with the temp file.
2848 (rename-file working-file startup-file t
)
2849 (gnus-set-file-modes startup-file setmodes
)))
2851 (delete-file working-file
)
2852 (file-error nil
)))))
2854 (gnus-kill-buffer (current-buffer))
2856 5 "Saving %s.eld...done" gnus-current-startup-file
))
2857 (gnus-dribble-delete-file)
2858 (gnus-group-set-mode-line)))))
2860 (defun gnus-gnus-to-quick-newsrc-format (&optional minimal name
&rest specific-variables
)
2861 "Print Gnus variables such as `gnus-newsrc-alist' in Lisp format."
2862 (princ (format ";; -*- mode:emacs-lisp; coding: %s; -*-\n"
2863 gnus-ding-file-coding-system
))
2865 (princ (format ";; %s\n" name
))
2866 (princ ";; Gnus startup file.\n"))
2870 ;; Never delete this file -- if you want to force Gnus to read the
2871 ;; .newsrc file (if you have one), touch .newsrc instead.\n")
2872 (princ "(setq gnus-newsrc-file-version ")
2873 (princ (gnus-prin1-to-string gnus-version
))
2876 (let* ((print-quoted t
)
2878 (print-escape-multibyte nil
)
2879 (print-escape-nonascii t
)
2883 (print-escape-newlines t
)
2885 (if (and gnus-save-killed-list
2886 (stringp gnus-save-killed-list
))
2887 (gnus-strip-killed-list)
2890 (or specific-variables
2891 (if gnus-save-killed-list gnus-variable-list
2892 ;; Remove the `gnus-killed-list' from the list of variables
2893 ;; to be saved, if required.
2894 (delq 'gnus-killed-list
(copy-sequence gnus-variable-list
)))))
2895 ;; Peel off the "dummy" group.
2896 (gnus-newsrc-alist (cdr gnus-newsrc-alist
))
2898 ;; Insert the variables into the file.
2900 (when (and (boundp (setq variable
(pop variables
)))
2901 (symbol-value variable
))
2903 (princ (symbol-name variable
))
2905 (prin1 (symbol-value variable
))
2908 (defun gnus-strip-killed-list ()
2909 "Return the killed list minus the groups that match `gnus-save-killed-list'."
2910 (let ((list gnus-killed-list
)
2913 (when (string-match gnus-save-killed-list
(car list
))
2914 (push (car list
) olist
))
2918 (defun gnus-gnus-to-newsrc-format (&optional foreign-ok
)
2919 (interactive (list (gnus-y-or-n-p "write foreign groups too? ")))
2920 ;; Generate and save the .newsrc file.
2921 (with-current-buffer (create-file-buffer gnus-current-startup-file
)
2922 (let ((newsrc (cdr gnus-newsrc-alist
))
2923 (standard-output (current-buffer))
2924 info ranges range method
)
2925 (setq buffer-file-name gnus-current-startup-file
)
2926 (setq default-directory
(file-name-directory buffer-file-name
))
2927 (buffer-disable-undo)
2929 ;; Use a unibyte buffer since group names are unibyte strings;
2930 ;; in particular, non-ASCII group names are the ones encoded by
2931 ;; a certain coding system.
2932 (mm-disable-multibyte)
2934 (when gnus-newsrc-options
2935 (insert gnus-newsrc-options
))
2936 ;; Write subscribed and unsubscribed.
2937 (while (setq info
(pop newsrc
))
2938 ;; Don't write foreign groups to .newsrc.
2939 (when (or (null (setq method
(gnus-info-method info
)))
2940 (equal method
"native")
2941 (inline (gnus-server-equal method gnus-select-method
))
2943 (insert (gnus-info-group info
)
2944 (if (> (gnus-info-level info
) gnus-level-subscribed
)
2946 (when (setq ranges
(gnus-info-read info
))
2948 (if (not (listp (cdr ranges
)))
2949 (if (= (car ranges
) (cdr ranges
))
2950 (princ (car ranges
))
2951 (princ (car ranges
))
2953 (princ (cdr ranges
)))
2954 (while (setq range
(pop ranges
))
2955 (if (or (atom range
) (= (car range
) (cdr range
)))
2956 (princ (or (and (atom range
) range
) (car range
)))
2959 (princ (cdr range
)))
2963 (make-local-variable 'version-control
)
2964 (setq version-control
'never
)
2965 ;; It has been reported that sometime the modtime on the .newsrc
2966 ;; file seems to be off. We really do want to overwrite it, so
2967 ;; we clear the modtime here before saving. It's a bit odd,
2969 ;; sometimes the modtime clear isn't sufficient. most brute force:
2970 ;; delete the silly thing entirely first. but this fails to provide
2971 ;; such niceties as .newsrc~ creation.
2972 (if gnus-modtime-botch
2973 (delete-file gnus-startup-file
)
2974 (clear-visited-file-modtime))
2975 (gnus-run-hooks 'gnus-save-standard-newsrc-hook
)
2976 (let ((coding-system-for-write 'raw-text
))
2978 (kill-buffer (current-buffer)))))
2982 ;;; Slave functions.
2985 (defvar gnus-slave-mode nil
)
2987 (defun gnus-slave-mode ()
2988 "Minor mode for slave Gnusae."
2989 ;; FIXME: gnus-slave-mode appears to never be set (i.e. it'll always be nil):
2990 ;; Remove, or fix and use define-minor-mode.
2991 (add-minor-mode 'gnus-slave-mode
" Slave" (make-sparse-keymap))
2992 (gnus-run-hooks 'gnus-slave-mode-hook
))
2994 (defun gnus-slave-save-newsrc ()
2995 (with-current-buffer gnus-dribble-buffer
2997 (mm-make-temp-file (concat gnus-current-startup-file
"-slave-")))
2998 (modes (ignore-errors
2999 (file-modes (concat gnus-current-startup-file
".eld")))))
3000 (let ((coding-system-for-write gnus-ding-file-coding-system
))
3001 (gnus-write-buffer slave-name
))
3003 (gnus-set-file-modes slave-name modes
)))))
3005 (defun gnus-master-read-slave-newsrc ()
3008 (file-name-directory gnus-current-startup-file
)
3012 (file-name-nondirectory gnus-current-startup-file
)
3016 (if (not slave-files
)
3017 () ; There are no slave files to read.
3018 (gnus-message 7 "Reading slave newsrcs...")
3019 (with-current-buffer (gnus-get-buffer-create " *gnus slave*")
3021 (sort (mapcar (lambda (file)
3022 (list (nth 5 (file-attributes file
)) file
))
3025 (or (< (caar f1
) (caar f2
))
3026 (< (nth 1 (car f1
)) (nth 1 (car f2
)))))))
3029 (setq file
(nth 1 (car slave-files
)))
3030 (nnheader-insert-file-contents file
)
3031 (when (condition-case ()
3033 (eval-buffer (current-buffer))
3036 (gnus-error 3.2 "Possible error in %s" file
)
3038 (unless gnus-slave
; Slaves shouldn't delete these files.
3040 (delete-file file
))))
3041 (setq slave-files
(cdr slave-files
))))
3042 (gnus-dribble-touch)
3043 (gnus-message 7 "Reading slave newsrcs...done"))))
3047 ;;; Group description.
3050 (defun gnus-read-all-descriptions-files ()
3051 (let ((methods (cons gnus-select-method
3053 (when (gnus-archive-server-wanted-p)
3055 gnus-secondary-select-methods
))))
3057 (gnus-read-descriptions-file (car methods
))
3058 (setq methods
(cdr methods
)))
3061 (defun gnus-read-descriptions-file (&optional method
)
3062 (let ((method (or method gnus-select-method
))
3064 (when (stringp method
)
3065 (setq method
(gnus-server-to-method method
)))
3066 ;; We create the hashtable whether we manage to read the desc file
3067 ;; to avoid trying to re-read after a failed read.
3068 (unless gnus-description-hashtb
3069 (setq gnus-description-hashtb
3070 (gnus-make-hashtable (length gnus-active-hashtb
))))
3071 ;; Mark this method's desc file as read.
3072 (gnus-sethash (gnus-group-prefixed-name "" method
) "Has read"
3073 gnus-description-hashtb
)
3075 (gnus-message 5 "Reading descriptions file via %s..." (car method
))
3077 ((null (gnus-get-function method
'request-list-newsgroups t
))
3079 ((not (gnus-check-server method
))
3080 (gnus-message 1 "Couldn't open server")
3082 ((not (gnus-request-list-newsgroups method
))
3083 (gnus-message 1 "Couldn't read newsgroups descriptions")
3087 ;; FIXME: Shouldn't save-restriction be done after set-buffer?
3089 (set-buffer nntp-server-buffer
)
3090 (goto-char (point-min))
3091 (when (or (search-forward "\n.\n" nil t
)
3092 (goto-char (point-max)))
3094 (narrow-to-region (point-min) (point)))
3095 ;; If these are groups from a foreign select method, we insert the
3096 ;; group prefix in front of the group names.
3097 (and method
(not (inline
3099 (gnus-server-get-method nil method
)
3100 (gnus-server-get-method
3101 nil gnus-select-method
))))
3102 (let ((prefix (gnus-group-prefixed-name "" method
)))
3103 (goto-char (point-min))
3104 (while (and (not (eobp))
3105 (progn (insert prefix
)
3106 (zerop (forward-line 1)))))))
3107 (goto-char (point-min))
3109 ;; If we get an error, we set group to 0, which is not a
3113 (let ((obarray gnus-description-hashtb
))
3114 ;; Group is set to a symbol interned in this
3116 (read nntp-server-buffer
))
3118 (skip-chars-forward " \t")
3119 ;; ... which leads to this line being effectively ignored.
3120 (when (symbolp group
)
3121 (let* ((str (buffer-substring
3122 (point) (progn (end-of-line) (point))))
3123 (name (symbol-name group
))
3125 (or (gnus-group-name-charset method name
)
3126 (gnus-parameter-charset name
)
3127 gnus-default-charset
)))
3128 ;; Fixme: Don't decode in unibyte mode.
3129 (when (and str charset
(featurep 'mule
))
3130 (setq str
(mm-decode-coding-string str charset
)))
3133 (gnus-message 5 "Reading descriptions file...done")
3136 (defun gnus-group-get-description (group)
3137 "Get the description of a group by sending XGTITLE to the server."
3138 (when (gnus-request-group-description group
)
3139 (with-current-buffer nntp-server-buffer
3140 (goto-char (point-min))
3141 (when (looking-at "[^ \t]+[ \t]+\\(.*\\)")
3142 (match-string 1)))))
3145 (defun gnus-declare-backend (name &rest abilities
)
3146 "Declare back end NAME with ABILITIES as a Gnus back end."
3147 (setq gnus-valid-select-methods
3148 (nconc gnus-valid-select-methods
3149 (list (apply 'list name abilities
))))
3150 (gnus-redefine-select-method-widget))
3152 (defun gnus-set-default-directory ()
3153 "Set the default directory in the current buffer to `gnus-default-directory'.
3154 If this variable is nil, don't do anything."
3155 (setq default-directory
3156 (if (and gnus-default-directory
3157 (file-exists-p gnus-default-directory
))
3158 (file-name-as-directory (expand-file-name gnus-default-directory
))
3159 default-directory
)))
3161 (defun gnus-display-time-event-handler ()
3162 (if (and (fboundp 'display-time-event-handler
)
3163 (gnus-boundp 'display-time-timer
))
3164 (display-time-event-handler)))
3166 (defun gnus-check-reasonable-setup ()
3167 ;; Check whether nnml and nnfolder share a directory.
3169 (if (fboundp 'display-warning
)
3171 (lambda (type message
)
3173 (message "Warning (%s): %s" type message
)
3175 (with-current-buffer (get-buffer-create "*Warnings*")
3176 (goto-char (point-max))
3179 (insert (format "Warning (%s): %s\n" type message
))
3180 (setq window
(display-buffer (current-buffer)))
3184 (forward-line (- 1 (window-height window
)))
3186 (goto-char (point-max))))))))))
3187 method active actives match
)
3188 (dolist (server gnus-server-alist
)
3189 (setq method
(gnus-server-to-method server
)
3190 active
(intern (format "%s-active-file" (car method
))))
3191 (when (and (member (car method
) '(nnml nnfolder
))
3192 (gnus-server-opened method
)
3194 (when (setq match
(assoc (symbol-value active
) actives
))
3195 (funcall display-warn
'gnus-server
3196 (format "%s and %s share the same active file %s"
3200 (push (list (symbol-value active
) method
) actives
)))))
3202 (provide 'gnus-start
)
3204 ;;; gnus-start.el ends here