1 ;;; gnus-start.el --- startup functions for Gnus
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007 Free Software Foundation, Inc.
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 3, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
36 (autoload 'message-make-date
"message")
37 (autoload 'gnus-agent-read-servers-validate
"gnus-agent")
38 (autoload 'gnus-agent-save-local
"gnus-agent")
39 (autoload 'gnus-agent-possibly-alter-active
"gnus-agent")
44 (defvar gnus-agent-covered-methods nil
)
45 (defvar gnus-agent-file-loading-local nil
)
46 (defvar gnus-agent-file-loading-cache nil
))
48 (defcustom gnus-startup-file
(nnheader-concat gnus-home-directory
".newsrc")
50 `.newsrc-SERVER' will be used instead if that exists."
54 (defcustom gnus-backup-startup-file
'never
55 "Whether to create backup files.
56 This variable takes the same values as the `version-control'
60 :type
'(choice (const :tag
"Never" never
)
61 (const :tag
"If existing" nil
)
62 (other :tag
"Always" t
)))
64 (defcustom gnus-save-startup-file-via-temp-buffer t
65 "Whether to write the startup file contents to a buffer then save
66 the buffer or write directly to the file. The buffer is faster
67 because all of the contents are written at once. The direct write
68 uses considerably less memory."
71 :type
'(choice (const :tag
"Write via buffer" t
)
72 (const :tag
"Write directly to file" nil
)))
74 (defcustom gnus-init-file
(nnheader-concat gnus-home-directory
".gnus")
75 "Your Gnus Emacs-Lisp startup file name.
76 If a file with the `.el' or `.elc' suffixes exists, it will be read instead."
80 (defcustom gnus-site-init-file
82 (concat (file-name-directory
83 (directory-file-name installation-directory
))
84 "site-lisp/gnus-init")
86 "The site-wide Gnus Emacs-Lisp startup file name, or nil if none.
87 If a file with the `.el' or `.elc' suffixes exists, it will be read instead."
89 :type
'(choice file
(const nil
)))
91 (defcustom gnus-default-subscribed-newsgroups nil
92 "List of newsgroups to subscribe, when a user runs Gnus the first time.
93 The value should be a list of strings.
94 If it is t, Gnus will not do anything special the first time it is
95 started; it'll just use the normal newsgroups subscription methods."
97 :type
'(choice (repeat string
) (const :tag
"Nothing special" t
)))
99 (defcustom gnus-use-dribble-file t
100 "*Non-nil means that Gnus will use a dribble file to store user updates.
101 If Emacs should crash without saving the .newsrc files, complete
102 information can be restored from the dribble file."
103 :group
'gnus-dribble-file
106 (defcustom gnus-dribble-directory nil
107 "*The directory where dribble files will be saved.
108 If this variable is nil, the directory where the .newsrc files are
110 :group
'gnus-dribble-file
111 :type
'(choice directory
(const nil
)))
113 (defcustom gnus-check-new-newsgroups
'ask-server
114 "*Non-nil means that Gnus will run `gnus-find-new-newsgroups' at startup.
115 This normally finds new newsgroups by comparing the active groups the
116 servers have already reported with those Gnus already knows, either alive
119 When any of the following are true, `gnus-find-new-newsgroups' will instead
120 ask the servers (primary, secondary, and archive servers) to list new
121 groups since the last time it checked:
122 1. This variable is `ask-server'.
123 2. This variable is a list of select methods (see below).
124 3. `gnus-read-active-file' is nil or `some'.
125 4. A prefix argument is given to `gnus-find-new-newsgroups' interactively.
127 Thus, if this variable is `ask-server' or a list of select methods or
128 `gnus-read-active-file' is nil or `some', then the killed list is no
129 longer necessary, so you could safely set `gnus-save-killed-list' to nil.
131 This variable can be a list of select methods which Gnus will query with
132 the `ask-server' method in addition to the primary, secondary, and archive
136 (setq gnus-check-new-newsgroups
137 '((nntp \"some.server\") (nntp \"other.server\")))
139 If this variable is nil, then you have to tell Gnus explicitly to
140 check for new newsgroups with \\<gnus-group-mode-map>\\[gnus-find-new-newsgroups]."
142 :type
'(choice (const :tag
"no" nil
)
143 (const :tag
"by brute force" t
)
144 (const :tag
"ask servers" ask-server
)
145 (repeat :menu-tag
"ask additional servers"
146 :tag
"ask additional servers"
148 (sexp :format
"%v"))))
150 (defcustom gnus-check-bogus-newsgroups nil
151 "*Non-nil means that Gnus will check and remove bogus newsgroup at startup.
152 If this variable is nil, then you have to tell Gnus explicitly to
153 check for bogus newsgroups with \\<gnus-group-mode-map>\\[gnus-group-check-bogus-groups]."
154 :group
'gnus-start-server
157 (defcustom gnus-read-active-file
'some
158 "*Non-nil means that Gnus will read the entire active file at startup.
159 If this variable is nil, Gnus will only know about the groups in your
162 If this variable is `some', Gnus will try to only read the relevant
163 parts of the active file from the server. Not all servers support
164 this, and it might be quite slow with other servers, but this should
165 generally be faster than both the t and nil value.
167 If you set this variable to nil or `some', you probably still want to
168 be told about new newsgroups that arrive. To do that, set
169 `gnus-check-new-newsgroups' to `ask-server'. This may not work
170 properly with all servers."
171 :group
'gnus-start-server
172 :type
'(choice (const nil
)
176 (defconst gnus-level-subscribed
5
177 "Groups with levels less than or equal to this variable are subscribed.")
179 (defconst gnus-level-unsubscribed
7
180 "Groups with levels less than or equal to this variable are unsubscribed.
182 Groups with levels less than `gnus-level-subscribed', which
183 should be less than this variable, are subscribed. Groups with
184 levels from `gnus-level-subscribed' (exclusive) upto this
185 variable (inclusive) are unsubscribed. See also
186 `gnus-level-zombie', `gnus-level-killed' and the Info node `Group
187 Levels' for details.")
189 (defconst gnus-level-zombie
8
190 "Groups with this level are zombie groups.")
192 (defconst gnus-level-killed
9
193 "Groups with this level are killed.")
195 (defcustom gnus-level-default-subscribed
3
196 "*New subscribed groups will be subscribed at this level."
197 :group
'gnus-group-levels
200 (defcustom gnus-level-default-unsubscribed
6
201 "*New unsubscribed groups will be unsubscribed at this level."
202 :group
'gnus-group-levels
205 (defcustom gnus-activate-level
(1+ gnus-level-subscribed
)
206 "*Groups higher than this level won't be activated on startup.
207 Setting this variable to something low might save lots of time when
208 you have many groups that you aren't interested in."
209 :group
'gnus-group-levels
212 (defcustom gnus-activate-foreign-newsgroups
4
213 "*If nil, Gnus will not check foreign newsgroups at startup.
214 If it is non-nil, it should be a number between one and nine. Foreign
215 newsgroups that have a level lower or equal to this number will be
216 activated on startup. For instance, if you want to active all
217 subscribed newsgroups, but not the rest, you'd set this variable to
218 `gnus-level-subscribed'.
220 If you subscribe to lots of newsgroups from different servers, startup
221 might take a while. By setting this variable to nil, you'll save time,
222 but you won't be told how many unread articles there are in the
224 :group
'gnus-group-levels
225 :type
'(choice integer
226 (const :tag
"none" nil
)))
228 (defcustom gnus-read-newsrc-file t
229 "*Non-nil means that Gnus will read the `.newsrc' file.
230 Gnus always reads 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
239 (defcustom gnus-save-newsrc-file t
240 "*Non-nil means that Gnus will save the `.newsrc' file.
241 Gnus always saves its own startup file, which is called
242 \".newsrc.eld\". The file called \".newsrc\" is in a format that can
243 be readily understood by other newsreaders. If you don't plan on
244 using other newsreaders, set this variable to nil to save some time on
249 (defcustom gnus-save-killed-list t
250 "*If non-nil, save the list of killed groups to the startup file.
251 If you set this variable to nil, you'll save both time (when starting
252 and quitting) and space (both memory and disk), but it will also mean
253 that Gnus has no record of which groups are new and which are old, so
254 the automatic new newsgroups subscription methods become meaningless.
256 You should always set `gnus-check-new-newsgroups' to `ask-server' or
257 nil if you set this variable to nil.
259 This variable can also be a regexp. In that case, all groups that do
260 not match this regexp will be removed before saving the list."
262 :type
'(radio (sexp :format
"Non-nil\n"
263 :match
(lambda (widget value
)
264 (and value
(not (stringp value
))))
269 (defcustom gnus-ignored-newsgroups
271 '("^to\\." ; not "real" groups
272 "^[0-9. \t]+\\( \\|$\\)" ; all digits in name
273 "^[\"][]\"[#'()]" ; bogus characters
276 "*A regexp to match uninteresting newsgroups in the active file.
277 Any lines in the active file matching this regular expression are
278 removed from the newsgroup list before anything else is done to it,
279 thus making them effectively non-existent."
280 :group
'gnus-group-new
283 (defcustom gnus-subscribe-newsgroup-method
'gnus-subscribe-zombies
284 "*Function(s) called with a group name when new group is detected.
285 A few pre-made functions are supplied: `gnus-subscribe-randomly'
286 inserts new groups at the beginning of the list of groups;
287 `gnus-subscribe-alphabetically' inserts new groups in strict
288 alphabetic order; `gnus-subscribe-hierarchically' inserts new groups
289 in hierarchical newsgroup order; `gnus-subscribe-interactively' asks
290 for your decision; `gnus-subscribe-killed' kills all new groups;
291 `gnus-subscribe-zombies' will make all new groups into zombies;
292 `gnus-subscribe-topics' will enter groups into the topics that
294 :group
'gnus-group-new
295 :type
'(radio (function-item gnus-subscribe-randomly
)
296 (function-item gnus-subscribe-alphabetically
)
297 (function-item gnus-subscribe-hierarchically
)
298 (function-item gnus-subscribe-interactively
)
299 (function-item gnus-subscribe-killed
)
300 (function-item gnus-subscribe-zombies
)
301 (function-item gnus-subscribe-topics
)
305 (defcustom gnus-subscribe-newsgroup-hooks nil
306 "*Hooks run after you subscribe to a new group.
307 The hooks will be called with new group's name as argument."
309 :group
'gnus-group-new
312 (defcustom gnus-subscribe-options-newsgroup-method
313 'gnus-subscribe-alphabetically
314 "*Function(s) called to subscribe newsgroups mentioned on \"options -n\" lines.
315 If, for instance, you want to subscribe to all newsgroups in the
316 \"no\" and \"alt\" hierarchies, you'd put the following in your
319 options -n no.all alt.all
321 Gnus will then subscribe all new newsgroups in these hierarchies
322 with the subscription method in this variable."
323 :group
'gnus-group-new
324 :type
'(radio (function-item gnus-subscribe-randomly
)
325 (function-item gnus-subscribe-alphabetically
)
326 (function-item gnus-subscribe-hierarchically
)
327 (function-item gnus-subscribe-interactively
)
328 (function-item gnus-subscribe-killed
)
329 (function-item gnus-subscribe-zombies
)
330 (function-item gnus-subscribe-topics
)
334 (defcustom gnus-subscribe-hierarchical-interactive nil
335 "*If non-nil, Gnus will offer to subscribe hierarchically.
336 When a new hierarchy appears, Gnus will ask the user:
338 'alt.binaries': Do you want to subscribe to this hierarchy? ([d]ys):
340 If the user pressed `d', Gnus will descend the hierarchy, `y' will
341 subscribe to all newsgroups in the hierarchy and `s' will skip this
342 hierarchy in its entirety."
343 :group
'gnus-group-new
346 (defcustom gnus-auto-subscribed-groups
347 "^nnml\\|^nnfolder\\|^nnmbox\\|^nnmh\\|^nnbabyl\\|^nnmaildir"
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 at before startup.
398 This hook is called as the first thing when Gnus is started."
402 (defcustom gnus-started-hook nil
403 "A hook called as the last thing after startup."
407 (defcustom gnus-setup-news-hook
408 '(gnus-fixup-nnimap-unread-after-getting-new-news)
409 "A hook after reading the .newsrc file, but before generating the buffer."
413 (defcustom gnus-get-top-new-news-hook nil
414 "A hook run just before Gnus checks for new news globally."
416 :group
'gnus-group-new
419 (defcustom gnus-get-new-news-hook nil
420 "A hook run just before Gnus checks for new news."
421 :group
'gnus-group-new
424 (defcustom gnus-after-getting-new-news-hook
425 '(gnus-display-time-event-handler
426 gnus-fixup-nnimap-unread-after-getting-new-news
)
427 "*A hook run after Gnus checks for new news when Gnus is already running."
428 :group
'gnus-group-new
431 (defcustom gnus-read-newsrc-el-hook nil
432 "A hook called after reading the newsrc.eld? file."
436 (defcustom gnus-save-newsrc-hook nil
437 "A hook called before saving any of the newsrc files."
441 (defcustom gnus-save-quick-newsrc-hook nil
442 "A hook called just before saving the quick newsrc file.
443 Can be used to turn version control on or off."
447 (defcustom gnus-save-standard-newsrc-hook nil
448 "A hook called just before saving the standard newsrc file.
449 Can be used to turn version control on or off."
453 (defcustom gnus-group-mode-hook nil
454 "Hook for Gnus group mode."
455 :group
'gnus-group-various
456 :options
'(gnus-topic-mode)
459 (defcustom gnus-always-read-dribble-file nil
460 "Unconditionally read the dribble file."
464 ;;; Internal variables
466 (defvar gnus-ding-file-coding-system mm-universal-coding-system
467 "Coding system for ding file.")
469 (defvar gnus-newsrc-file-version nil
)
470 (defvar gnus-override-subscribe-method nil
)
471 (defvar gnus-dribble-buffer nil
)
472 (defvar gnus-newsrc-options nil
473 "Options line in the .newsrc file.")
475 (defvar gnus-newsrc-options-n nil
476 "List of regexps representing groups to be subscribed/ignored unconditionally.")
478 (defvar gnus-newsrc-last-checked-date nil
479 "Date Gnus last asked server for new newsgroups.")
481 (defvar gnus-current-startup-file nil
482 "Startup file for the current host.")
484 ;; Byte-compiler warning.
485 (defvar gnus-group-line-format
)
487 ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
488 (defvar gnus-init-inhibit nil
)
489 (defun gnus-read-init-file (&optional inhibit-next
)
490 ;; Don't load .gnus if the -q option was used.
492 (if gnus-init-inhibit
493 (setq gnus-init-inhibit nil
)
494 (setq gnus-init-inhibit inhibit-next
)
495 (dolist (file (list gnus-site-init-file gnus-init-file
))
497 (locate-library file
))
498 (if (or debug-on-error debug-on-quit
)
503 (error "Error in %s: %s" file
(cadr var
))))))))))
505 ;; For subscribing new newsgroup
507 (defun gnus-subscribe-hierarchical-interactive (groups)
508 (let ((groups (sort groups
'string
<))
509 prefixes prefix start ans group starts
)
511 (setq prefixes
(list "^"))
512 (while (and groups prefixes
)
513 (while (not (string-match (car prefixes
) (car groups
)))
514 (setq prefixes
(cdr prefixes
)))
515 (setq prefix
(car prefixes
))
516 (setq start
(1- (length prefix
)))
517 (if (and (string-match "[^\\.]\\." (car groups
) start
)
520 (concat "^" (substring (car groups
) 0 (match-end 0))))
521 (string-match prefix
(cadr groups
)))
523 (push prefix prefixes
)
524 (message "Descend hierarchy %s? ([y]nsq): "
525 (substring prefix
1 (1- (length prefix
))))
526 (while (not (memq (setq ans
(read-char-exclusive))
527 '(?y ?
\n ?
\r ?n ?s ?q
)))
529 (message "Descend hierarchy %s? ([y]nsq): "
530 (substring prefix
1 (1- (length prefix
)))))
534 (setq group
(car groups
))))
535 (push group gnus-killed-list
)
536 (gnus-sethash group group gnus-killed-hashtb
)
537 (setq groups
(cdr groups
)))
538 (setq starts
(cdr starts
)))
542 (setq group
(car groups
))))
543 (gnus-sethash group group gnus-killed-hashtb
)
544 (gnus-subscribe-alphabetically (car groups
))
545 (setq groups
(cdr groups
)))
546 (setq starts
(cdr starts
)))
549 (setq group
(car groups
))
550 (push group gnus-killed-list
)
551 (gnus-sethash group group gnus-killed-hashtb
)
552 (setq groups
(cdr groups
))))
554 (message "Subscribe %s? ([n]yq)" (car groups
))
555 (while (not (memq (setq ans
(read-char-exclusive))
556 '(?y ?
\n ?
\r ?q ?n
)))
558 (message "Subscribe %s? ([n]yq)" (car groups
)))
559 (setq group
(car groups
))
561 (gnus-subscribe-alphabetically (car groups
))
562 (gnus-sethash group group gnus-killed-hashtb
))
565 (setq group
(car groups
))
566 (push group gnus-killed-list
)
567 (gnus-sethash group group gnus-killed-hashtb
)
568 (setq groups
(cdr groups
))))
570 (push group gnus-killed-list
)
571 (gnus-sethash group group gnus-killed-hashtb
)))
572 (setq groups
(cdr groups
)))))))
574 (defun gnus-subscribe-randomly (newsgroup)
575 "Subscribe new NEWSGROUP by making it the first newsgroup."
576 (gnus-subscribe-newsgroup newsgroup
))
578 (defun gnus-subscribe-alphabetically (newgroup)
579 "Subscribe new NEWGROUP and insert it in alphabetical order."
580 (let ((groups (cdr gnus-newsrc-alist
))
582 (while (and (not before
) groups
)
583 (if (string< newgroup
(caar groups
))
584 (setq before
(caar groups
))
585 (setq groups
(cdr groups
))))
586 (gnus-subscribe-newsgroup newgroup before
)))
588 (defun gnus-subscribe-hierarchically (newgroup)
589 "Subscribe new NEWGROUP and insert it in hierarchical newsgroup order."
590 ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
592 (set-buffer (nnheader-find-file-noselect gnus-current-startup-file
))
594 (let ((groupkey newgroup
) before
)
595 (while (and (not before
) groupkey
)
596 (goto-char (point-min))
598 (concat "^\\(" (regexp-quote groupkey
) ".*\\)[!:]")))
599 (while (and (re-search-forward groupkey-re nil t
)
601 (setq before
(match-string 1))
602 (string< before newgroup
)))))
603 ;; Remove tail of newsgroup name (eg. a.b.c -> a.b)
605 (when (string-match "^\\(.*\\)\\.[^.]+$" groupkey
)
606 (substring groupkey
(match-beginning 1) (match-end 1)))))
607 (gnus-subscribe-newsgroup newgroup before
))
608 (kill-buffer (current-buffer)))))
610 (defun gnus-subscribe-interactively (group)
611 "Subscribe the new GROUP interactively.
612 It is inserted in hierarchical newsgroup order if subscribed. If not,
614 (if (gnus-y-or-n-p (format "Subscribe new newsgroup %s? " group
))
615 (gnus-subscribe-hierarchically group
)
616 (push group gnus-killed-list
)))
618 (defun gnus-subscribe-zombies (group)
619 "Make the new GROUP into a zombie group."
620 (push group gnus-zombie-list
))
622 (defun gnus-subscribe-killed (group)
623 "Make the new GROUP a killed group."
624 (push group gnus-killed-list
))
626 (defun gnus-subscribe-newsgroup (newsgroup &optional next
)
627 "Subscribe new NEWSGROUP.
628 If NEXT is non-nil, it is inserted before NEXT. Otherwise it is made
629 the first newsgroup."
631 (goto-char (point-min))
632 ;; We subscribe the group by changing its level to `subscribed'.
633 (gnus-group-change-level
634 newsgroup gnus-level-default-subscribed
635 gnus-level-killed
(gnus-gethash (or next
"dummy.group")
637 (gnus-message 5 "Subscribe newsgroup: %s" newsgroup
)
638 (run-hook-with-args 'gnus-subscribe-newsgroup-hooks newsgroup
)
641 (defun gnus-read-active-file-p ()
642 "Say whether the active file has been read from `gnus-select-method'."
643 (memq gnus-select-method gnus-have-read-active-file
))
645 ;;; General various misc type functions.
647 ;; Silence byte-compiler.
649 (defvar gnus-current-headers
)
650 (defvar gnus-thread-indent-array
)
651 (defvar gnus-newsgroup-name
)
652 (defvar gnus-newsgroup-headers
)
653 (defvar gnus-group-list-mode
)
654 (defvar gnus-group-mark-positions
)
655 (defvar gnus-newsgroup-data
)
656 (defvar gnus-newsgroup-unreads
)
657 (defvar nnoo-state-alist
)
658 (defvar gnus-current-select-method
)
659 (defvar mail-sources
)
660 (defvar nnmail-scan-directory-mail-source-once
)
661 (defvar nnmail-split-history
)
662 (defvar nnmail-spool-file
))
664 (defun gnus-close-all-servers ()
667 (dolist (server gnus-opened-servers
)
668 (gnus-close-server (car server
))))
670 (defun gnus-clear-system ()
671 "Clear all variables and buffers."
672 ;; Clear Gnus variables.
673 (let ((variables (remove 'gnus-format-specs gnus-variable-list
)))
675 (set (car variables
) nil
)
676 (setq variables
(cdr variables
))))
677 ;; Clear other internal variables.
678 (setq gnus-list-of-killed-groups nil
679 gnus-have-read-active-file nil
680 gnus-agent-covered-methods nil
681 gnus-agent-file-loading-local nil
682 gnus-agent-file-loading-cache nil
683 gnus-server-method-cache nil
684 gnus-newsrc-alist nil
685 gnus-newsrc-hashtb nil
688 gnus-killed-hashtb nil
689 gnus-active-hashtb nil
690 gnus-moderated-hashtb nil
691 gnus-description-hashtb nil
692 gnus-current-headers nil
693 gnus-thread-indent-array nil
694 gnus-newsgroup-headers nil
695 gnus-newsgroup-name nil
696 gnus-server-alist nil
697 gnus-group-list-mode nil
698 gnus-opened-servers nil
699 gnus-group-mark-positions nil
700 gnus-newsgroup-data nil
701 gnus-newsgroup-unreads nil
703 gnus-current-select-method nil
704 nnmail-split-history nil
705 gnus-ephemeral-servers nil
)
706 (gnus-shutdown 'gnus
)
707 ;; Kill the startup file.
708 (and gnus-current-startup-file
709 (get-file-buffer gnus-current-startup-file
)
710 (kill-buffer (get-file-buffer gnus-current-startup-file
)))
711 ;; Clear the dribble buffer.
713 ;; Kill global KILL file buffer.
714 (when (get-file-buffer (gnus-newsgroup-kill-file nil
))
715 (kill-buffer (get-file-buffer (gnus-newsgroup-kill-file nil
))))
716 (gnus-kill-buffer nntp-server-buffer
)
717 ;; Kill Gnus buffers.
718 (dolist (buffer (gnus-buffers))
719 (gnus-kill-buffer buffer
))
720 ;; Remove Gnus frames.
721 (gnus-kill-gnus-frames))
723 (defun gnus-no-server-1 (&optional arg slave
)
725 If ARG is a positive number, Gnus will use that as the startup
726 level. If ARG is nil, Gnus will be started at level 2
727 \(`gnus-level-default-subscribed' minus one). If ARG is non-nil
728 and not a positive number, Gnus will prompt the user for the name
729 of an NNTP server to use. As opposed to \\[gnus], this command
730 will not connect to the local server."
732 (let ((val (or arg
(1- gnus-level-default-subscribed
))))
734 (make-local-variable 'gnus-group-use-permanent-levels
)
735 (setq gnus-group-use-permanent-levels val
)))
737 (defun gnus-1 (&optional arg dont-connect slave
)
739 If ARG is non-nil and a positive number, Gnus will use that as the
740 startup level. If ARG is non-nil and not a positive number, Gnus will
741 prompt the user for the name of an NNTP server to use."
746 (switch-to-buffer gnus-group-buffer
)
747 (gnus-group-get-new-news
750 (max (car gnus-group-list-mode
) arg
))))
754 (gnus-run-hooks 'gnus-before-startup-hook
)
755 (nnheader-init-server-buffer)
756 (setq gnus-slave slave
)
757 (gnus-read-init-file)
761 (when gnus-simple-splash
762 (setq gnus-simple-splash nil
)
769 (let ((level (and (numberp arg
) (> arg
0) arg
))
775 (gnus-start-news-server (and arg
(not level
))))))
776 (if (and (not dont-connect
)
779 (gnus-run-hooks 'gnus-startup-hook
)
780 ;; NNTP server is successfully open.
782 ;; Find the current startup file name.
783 (setq gnus-current-startup-file
784 (gnus-make-newsrc-file gnus-startup-file
))
786 ;; Read the dribble file.
787 (when (or gnus-slave gnus-use-dribble-file
)
788 (gnus-dribble-read-file))
790 ;; Allow using GroupLens predictions.
791 (when gnus-use-grouplens
793 (add-hook 'gnus-summary-mode-hook
'gnus-grouplens-mode
))
795 ;; Do the actual startup.
797 (gnus-request-create-group "queue" '(nndraft "")))
798 (gnus-request-create-group "drafts" '(nndraft ""))
799 (gnus-setup-news nil level dont-connect
)
800 (gnus-run-hooks 'gnus-setup-news-hook
)
801 (gnus-start-draft-setup)
802 ;; Generate the group buffer.
803 (gnus-group-list-groups level
)
804 (gnus-group-first-unread-group)
805 (gnus-configure-windows 'group
)
806 (gnus-group-set-mode-line)
807 (gnus-run-hooks 'gnus-started-hook
))))))
809 (defun gnus-start-draft-setup ()
810 "Make sure the draft group exists."
811 (gnus-request-create-group "drafts" '(nndraft ""))
812 (unless (gnus-gethash "nndraft:drafts" gnus-newsrc-hashtb
)
813 (gnus-message 3 "Subscribing drafts group")
814 (let ((gnus-level-default-subscribed 1))
815 (gnus-subscribe-group "nndraft:drafts" nil
'(nndraft ""))))
816 (unless (equal (gnus-group-get-parameter "nndraft:drafts" 'gnus-dummy t
)
817 '((gnus-draft-mode)))
818 (gnus-message 3 "Setting up drafts group")
819 (gnus-group-set-parameter
820 "nndraft:drafts" 'gnus-dummy
'((gnus-draft-mode)))))
827 (defvar gnus-dribble-ignore nil
)
828 (defvar gnus-dribble-eval-file nil
)
830 (defun gnus-dribble-file-name ()
831 "Return the dribble file for the current .newsrc."
833 (if gnus-dribble-directory
834 (concat (file-name-as-directory gnus-dribble-directory
)
835 (file-name-nondirectory gnus-current-startup-file
))
836 gnus-current-startup-file
)
839 (defun gnus-dribble-enter (string)
840 "Enter STRING into the dribble buffer."
841 (when (and (not gnus-dribble-ignore
)
843 (buffer-name gnus-dribble-buffer
))
844 (let ((obuf (current-buffer)))
845 (set-buffer gnus-dribble-buffer
)
846 (goto-char (point-max))
848 ;; This has been commented by Josh Huber <huber@alum.wpi.edu>
849 ;; It causes problems with both XEmacs and Emacs 21, and doesn't
850 ;; seem to be of much value. (FIXME: remove this after we make sure
852 ;; (set-window-point (get-buffer-window (current-buffer)) (point-max))
853 (bury-buffer gnus-dribble-buffer
)
855 (set-buffer gnus-group-buffer
)
856 (gnus-group-set-mode-line))
859 (defun gnus-dribble-touch ()
860 "Touch the dribble buffer."
861 (gnus-dribble-enter ""))
863 (defun gnus-dribble-read-file ()
864 "Read the dribble file from disk."
865 (let ((dribble-file (gnus-dribble-file-name)))
867 (set-buffer (setq gnus-dribble-buffer
868 (gnus-get-buffer-create
869 (file-name-nondirectory dribble-file
))))
870 (set (make-local-variable 'file-precious-flag
) t
)
872 (setq buffer-file-name dribble-file
)
874 (buffer-disable-undo)
875 (bury-buffer (current-buffer))
876 (set-buffer-modified-p nil
)
877 (let ((auto (make-auto-save-file-name))
878 (gnus-dribble-ignore t
)
881 (when (or (file-exists-p auto
) (file-exists-p dribble-file
))
882 ;; Load whichever file is newest -- the auto save file
883 ;; or the "real" file.
884 (if (file-newer-than-file-p auto dribble-file
)
885 (nnheader-insert-file-contents auto
)
886 (nnheader-insert-file-contents dribble-file
))
887 (unless (zerop (buffer-size))
888 (set-buffer-modified-p t
))
889 ;; Set the file modes to reflect the .newsrc file modes.
891 (when (and (file-exists-p gnus-current-startup-file
)
892 (file-exists-p dribble-file
)
893 (setq modes
(file-modes gnus-current-startup-file
)))
894 (set-file-modes dribble-file modes
))
895 (goto-char (point-min))
896 (when (search-forward "Gnus was exited on purpose" nil t
)
898 ;; Possibly eval the file later.
899 (when (or gnus-always-read-dribble-file
902 "Gnus exited on purpose without saving; read auto-save file anyway? "
903 "Gnus auto-save file exists. Do you want to read it? ")))
904 (setq gnus-dribble-eval-file t
)))))))
906 (defun gnus-dribble-eval-file ()
907 (when gnus-dribble-eval-file
908 (setq gnus-dribble-eval-file nil
)
910 (let ((gnus-dribble-ignore t
))
911 (set-buffer gnus-dribble-buffer
)
912 (eval-buffer (current-buffer))))))
914 (defun gnus-dribble-delete-file ()
915 (when (file-exists-p (gnus-dribble-file-name))
916 (delete-file (gnus-dribble-file-name)))
917 (when gnus-dribble-buffer
919 (set-buffer gnus-dribble-buffer
)
920 (let ((auto (make-auto-save-file-name)))
921 (when (file-exists-p auto
)
924 (set-buffer-modified-p nil
)))))
926 (defun gnus-dribble-save ()
927 (when (and gnus-dribble-buffer
928 (buffer-name gnus-dribble-buffer
))
930 (set-buffer gnus-dribble-buffer
)
933 (defun gnus-dribble-clear ()
934 (when (gnus-buffer-exists-p gnus-dribble-buffer
)
936 (set-buffer gnus-dribble-buffer
)
938 (set-buffer-modified-p nil
)
939 (setq buffer-saved-size
(buffer-size)))))
943 ;;; Active & Newsrc File Handling
946 (defun gnus-setup-news (&optional rawfile level dont-connect
)
947 "Setup news information.
948 If RAWFILE is non-nil, the .newsrc file will also be read.
949 If LEVEL is non-nil, the news will be set up at level LEVEL."
951 (let ((init (not (and gnus-newsrc-alist gnus-active-hashtb
(not rawfile
))))
952 ;; Binding this variable will inhibit multiple fetchings
953 ;; of the same mail source.
954 (nnmail-fetched-sources (list t
)))
957 ;; Clear some variables to re-initialize news information.
958 (setq gnus-newsrc-alist nil
959 gnus-active-hashtb nil
)
960 ;; Read the newsrc file and create `gnus-newsrc-hashtb'.
961 (gnus-read-newsrc-file rawfile
))
963 ;; Make sure the archive server is available to all and sundry.
964 (when gnus-message-archive-method
965 (unless (assoc "archive" gnus-server-alist
)
966 (let ((method (or (and (stringp gnus-message-archive-method
)
967 (gnus-server-to-method
968 gnus-message-archive-method
))
969 gnus-message-archive-method
)))
970 ;; Check whether the archive method is writable.
971 (unless (or (stringp method
)
972 (memq 'respool
(assoc (format "%s" (car method
))
973 gnus-valid-select-methods
)))
974 (setq method
"archive")) ;; The default.
975 (push (if (stringp method
)
980 ,(nnheader-concat message-directory method
))
981 (nnfolder-active-file
982 ,(nnheader-concat message-directory
983 (concat method
"/active")))
984 (nnfolder-get-new-mail nil
)
985 (nnfolder-inhibit-expiry t
))
986 (cons "archive" method
))
987 gnus-server-alist
))))
989 ;; If we don't read the complete active file, we fill in the
991 (when (or (null gnus-read-active-file
)
992 (eq gnus-read-active-file
'some
))
993 (gnus-update-active-hashtb-from-killed))
995 ;; Validate agent covered methods now that gnus-server-alist has
997 ;; NOTE: This is here for one purpose only. By validating the
998 ;; agentized server's, it converts the old 5.10.3, and earlier,
999 ;; format to the current format. That enables the agent code
1000 ;; within gnus-read-active-file to function correctly.
1002 (gnus-agent-read-servers-validate))
1004 ;; Read the active file and create `gnus-active-hashtb'.
1005 ;; If `gnus-read-active-file' is nil, then we just create an empty
1006 ;; hash table. The partial filling out of the hash table will be
1007 ;; done in `gnus-get-unread-articles'.
1008 (and gnus-read-active-file
1010 (gnus-read-active-file nil dont-connect
))
1012 (unless gnus-active-hashtb
1013 (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 ;; We might read in new NoCeM messages here.
1054 (when (and (not dont-connect
)
1056 (or (and (numberp gnus-use-nocem
)
1058 (>= level gnus-use-nocem
))
1060 (gnus-nocem-scan-groups))
1062 ;; Read any slave files.
1063 (gnus-master-read-slave-newsrc)
1065 ;; Find the number of unread articles in each non-dead group.
1066 (let ((gnus-read-active-file (and (not level
) gnus-read-active-file
)))
1067 (gnus-get-unread-articles level
))))
1069 (defun gnus-call-subscribe-functions (method group
)
1070 "Call METHOD to subscribe GROUP.
1071 If no function returns `non-nil', call `gnus-subscribe-zombies'."
1074 (funcall method group
))
1077 (dolist (func method
)
1078 (if (funcall func group
)
1082 (gnus-subscribe-zombies group
)))
1084 (defun gnus-find-new-newsgroups (&optional arg
)
1085 "Search for new newsgroups and add them.
1086 Each new newsgroup will be treated with `gnus-subscribe-newsgroup-method'.
1087 The `-n' option line from .newsrc is respected.
1089 With 1 C-u, use the `ask-server' method to query the server for new
1091 With 2 C-u's, use most complete method possible to query the server
1092 for new groups, and subscribe the new groups as zombies."
1094 (let* ((gnus-subscribe-newsgroup-method
1095 gnus-subscribe-newsgroup-method
)
1097 ((or (and (= (or arg
1) 4)
1098 (not (listp gnus-check-new-newsgroups
)))
1099 (null gnus-read-active-file
)
1100 (eq gnus-read-active-file
'some
))
1103 (setq gnus-subscribe-newsgroup-method
1104 'gnus-subscribe-zombies
)
1106 (t gnus-check-new-newsgroups
))))
1107 (unless (gnus-check-first-time-used)
1108 (if (or (consp check
)
1109 (eq check
'ask-server
))
1110 ;; Ask the server for new groups.
1111 (gnus-ask-server-for-new-groups)
1112 ;; Go through the active hashtb and look for new groups.
1114 group new-newsgroups
)
1115 (gnus-message 5 "Looking for new newsgroups...")
1116 (unless gnus-have-read-active-file
1117 (gnus-read-active-file))
1118 (setq gnus-newsrc-last-checked-date
(message-make-date))
1119 (unless gnus-killed-hashtb
1120 (gnus-make-hashtable-from-killed))
1121 ;; Go though every newsgroup in `gnus-active-hashtb' and compare
1122 ;; with `gnus-newsrc-hashtb' and `gnus-killed-hashtb'.
1125 (if (or (null (setq group
(symbol-name sym
)))
1127 (null (symbol-value sym
))
1128 (gnus-gethash group gnus-killed-hashtb
)
1129 (gnus-gethash group gnus-newsrc-hashtb
))
1131 (let ((do-sub (gnus-matches-options-n group
)))
1133 ((eq do-sub
'subscribe
)
1134 (setq groups
(1+ groups
))
1135 (gnus-sethash group group gnus-killed-hashtb
)
1136 (gnus-call-subscribe-functions
1137 gnus-subscribe-options-newsgroup-method group
))
1138 ((eq do-sub
'ignore
)
1141 (setq groups
(1+ groups
))
1142 (gnus-sethash group group gnus-killed-hashtb
)
1143 (if gnus-subscribe-hierarchical-interactive
1144 (push group new-newsgroups
)
1145 (gnus-call-subscribe-functions
1146 gnus-subscribe-newsgroup-method group
)))))))
1148 (when new-newsgroups
1149 (gnus-subscribe-hierarchical-interactive new-newsgroups
))
1151 (gnus-message 5 "%d new newsgroup%s arrived."
1152 groups
(if (> groups
1) "s have" " has"))
1153 (gnus-message 5 "No new newsgroups.")))))))
1155 (defun gnus-matches-options-n (group)
1156 ;; Returns `subscribe' if the group is to be unconditionally
1157 ;; subscribed, `ignore' if it is to be ignored, and nil if there is
1158 ;; no match for the group.
1160 ;; First we check the two user variables.
1162 ((and gnus-options-subscribe
1163 (string-match gnus-options-subscribe group
))
1165 ((and gnus-auto-subscribed-groups
1166 (string-match gnus-auto-subscribed-groups group
))
1168 ((and gnus-options-not-subscribe
1169 (string-match gnus-options-not-subscribe group
))
1171 ;; Then we go through the list that was retrieved from the .newsrc
1172 ;; file. This list has elements on the form
1173 ;; `(REGEXP . {ignore,subscribe})'. The first match found (the list
1174 ;; is in the reverse order of the options line) is returned.
1176 (let ((regs gnus-newsrc-options-n
))
1178 (not (string-match (caar regs
) group
)))
1179 (setq regs
(cdr regs
)))
1180 (and regs
(cdar regs
))))))
1182 (defun gnus-ask-server-for-new-groups ()
1183 (let* ((new-date (message-make-date))
1184 (date (or gnus-newsrc-last-checked-date new-date
))
1185 (methods (cons gnus-select-method
1187 (when (gnus-archive-server-wanted-p)
1190 (and (consp gnus-check-new-newsgroups
)
1191 gnus-check-new-newsgroups
)
1192 gnus-secondary-select-methods
))))
1194 group new-newsgroups got-new method hashtb
1195 gnus-override-subscribe-method
)
1196 (unless gnus-killed-hashtb
1197 (gnus-make-hashtable-from-killed))
1198 ;; Go through both primary and secondary select methods and
1199 ;; request new newsgroups.
1200 (while (setq method
(gnus-server-get-method nil
(pop methods
)))
1201 (setq new-newsgroups nil
1202 gnus-override-subscribe-method method
)
1203 (when (and (gnus-check-server method
)
1204 (gnus-request-newgroups date method
))
1207 hashtb
(gnus-make-hashtable 100))
1208 (set-buffer nntp-server-buffer
)
1209 ;; Enter all the new groups into a hashtable.
1210 (gnus-active-to-gnus-format method hashtb
'ignore
))
1211 ;; Now all new groups from `method' are in `hashtb'.
1214 (if (or (null (setq group
(symbol-name group-sym
)))
1215 (not (boundp group-sym
))
1216 (null (symbol-value group-sym
))
1217 (gnus-gethash group gnus-newsrc-hashtb
)
1218 (member group gnus-zombie-list
)
1219 (member group gnus-killed-list
))
1220 ;; The group is already known.
1222 ;; Make this group active.
1223 (when (symbol-value group-sym
)
1224 (gnus-set-active group
(symbol-value group-sym
)))
1225 ;; Check whether we want it or not.
1226 (let ((do-sub (gnus-matches-options-n group
)))
1228 ((eq do-sub
'subscribe
)
1230 (gnus-sethash group group gnus-killed-hashtb
)
1231 (gnus-call-subscribe-functions
1232 gnus-subscribe-options-newsgroup-method group
))
1233 ((eq do-sub
'ignore
)
1237 (gnus-sethash group group gnus-killed-hashtb
)
1238 (if gnus-subscribe-hierarchical-interactive
1239 (push group new-newsgroups
)
1240 (gnus-call-subscribe-functions
1241 gnus-subscribe-newsgroup-method group
)))))))
1243 (when new-newsgroups
1244 (gnus-subscribe-hierarchical-interactive new-newsgroups
)))
1246 (gnus-message 5 "%d new newsgroup%s arrived"
1247 groups
(if (> groups
1) "s have" " has"))
1248 (gnus-message 5 "No new newsgroups"))
1250 (setq gnus-newsrc-last-checked-date new-date
))
1253 (defun gnus-check-first-time-used ()
1255 ;; First check if any of the following files exist. If they do,
1256 ;; it's not the first time the user has used Gnus.
1257 (dolist (file (list (concat gnus-current-startup-file
".el")
1258 (concat gnus-current-startup-file
".eld")
1259 (concat gnus-startup-file
".el")
1260 (concat gnus-startup-file
".eld")))
1261 (when (file-exists-p file
)
1262 (throw 'ended nil
)))
1263 (gnus-message 6 "First time user; subscribing you to default groups")
1264 (unless (gnus-read-active-file-p)
1265 (let ((gnus-read-active-file t
))
1266 (gnus-read-active-file)))
1267 (setq gnus-newsrc-last-checked-date
(message-make-date))
1268 ;; Subscribe to the default newsgroups.
1269 (let ((groups (or gnus-default-subscribed-newsgroups
1270 gnus-backup-default-subscribed-newsgroups
))
1273 ;; If t, we subscribe (or not) all groups as if they were new.
1276 (when (setq group
(symbol-name sym
))
1277 (let ((do-sub (gnus-matches-options-n group
)))
1279 ((eq do-sub
'subscribe
)
1280 (gnus-sethash group group gnus-killed-hashtb
)
1281 (gnus-call-subscribe-functions
1282 gnus-subscribe-options-newsgroup-method group
))
1283 ((eq do-sub
'ignore
)
1286 (push group gnus-killed-list
))))))
1288 (dolist (group groups
)
1289 ;; Only subscribe the default groups that are activated.
1290 (when (gnus-active group
)
1291 (gnus-group-change-level
1292 group gnus-level-default-subscribed gnus-level-killed
)))
1294 (set-buffer gnus-group-buffer
)
1295 ;; Don't error if the group already exists. This happens when a
1296 ;; first-time user types 'F'. -- didier
1297 (gnus-group-make-help-group t
))
1298 (when gnus-novice-user
1299 (gnus-message 7 "`A k' to list killed groups"))))))
1301 (defun gnus-subscribe-group (group &optional previous method
)
1302 "Subscribe GROUP and put it after PREVIOUS."
1303 (gnus-group-change-level
1305 (list t group gnus-level-default-subscribed nil nil method
)
1307 gnus-level-default-subscribed gnus-level-killed previous t
)
1310 ;; `gnus-group-change-level' is the fundamental function for changing
1311 ;; subscription levels of newsgroups. This might mean just changing
1312 ;; from level 1 to 2, which is pretty trivial, from 2 to 6 or back
1313 ;; again, which subscribes/unsubscribes a group, which is equally
1314 ;; trivial. Changing from 1-7 to 8-9 means that you kill a group, and
1315 ;; from 8-9 to 1-7 means that you remove the group from the list of
1316 ;; killed (or zombie) groups and add them to the (kinda) subscribed
1317 ;; groups. And last but not least, moving from 8 to 9 and 9 to 8,
1318 ;; which is trivial.
1319 ;; ENTRY can either be a string (newsgroup name) or a list (if
1320 ;; FROMKILLED is t, it's a list on the format (NUM INFO-LIST),
1321 ;; otherwise it's a list in the format of the `gnus-newsrc-hashtb'
1323 ;; LEVEL is the new level of the group, OLDLEVEL is the old level and
1324 ;; PREVIOUS is the group (in hashtb entry format) to insert this group
1326 (defun gnus-group-change-level (entry level
&optional oldlevel
1327 previous fromkilled
)
1328 (let (group info active num
)
1329 ;; Glean what info we can from the arguments
1331 (if fromkilled
(setq group
(nth 1 entry
))
1332 (setq group
(car (nth 2 entry
))))
1334 (when (and (stringp entry
)
1336 (< oldlevel gnus-level-zombie
))
1337 (setq entry
(gnus-gethash entry gnus-newsrc-hashtb
)))
1338 (if (and (not oldlevel
)
1340 (setq oldlevel
(gnus-info-level (nth 2 entry
)))
1341 (setq oldlevel
(or oldlevel gnus-level-killed
)))
1342 (when (stringp previous
)
1343 (setq previous
(gnus-gethash previous gnus-newsrc-hashtb
)))
1345 (if (and (>= oldlevel gnus-level-zombie
)
1346 (gnus-gethash group gnus-newsrc-hashtb
))
1347 ;; We are trying to subscribe a group that is already
1351 (unless (gnus-ephemeral-group-p group
)
1353 (format "(gnus-group-change-level %S %S %S %S %S)"
1354 group level oldlevel
(car (nth 2 previous
)) fromkilled
)))
1356 ;; Then we remove the newgroup from any old structures, if needed.
1357 ;; If the group was killed, we remove it from the killed or zombie
1358 ;; list. If not, and it is in fact going to be killed, we remove
1359 ;; it from the newsrc hash table and assoc.
1361 ((>= oldlevel gnus-level-zombie
)
1362 ;; oldlevel could be wrong.
1363 (setq gnus-zombie-list
(delete group gnus-zombie-list
))
1364 (setq gnus-killed-list
(delete group gnus-killed-list
)))
1366 (when (and (>= level gnus-level-zombie
)
1368 (gnus-sethash (car (nth 2 entry
)) nil gnus-newsrc-hashtb
)
1370 (setcdr (gnus-gethash (car (nth 3 entry
))
1373 (setcdr (cdr entry
) (cdddr entry
)))))
1375 ;; Finally we enter (if needed) the list where it is supposed to
1376 ;; go, and change the subscription level. If it is to be killed,
1377 ;; we enter it into the killed or zombie list.
1379 ((>= level gnus-level-zombie
)
1380 ;; Remove from the hash table.
1381 (gnus-sethash group nil gnus-newsrc-hashtb
)
1382 ;; We do not enter foreign groups into the list of dead
1384 (unless (gnus-group-foreign-p group
)
1385 (if (= level gnus-level-zombie
)
1386 (push group gnus-zombie-list
)
1387 (if (= oldlevel gnus-level-killed
)
1388 ;; Remove from active hashtb.
1389 (unintern group gnus-active-hashtb
)
1390 ;; Don't add it into killed-list if it was killed.
1391 (push group gnus-killed-list
)))))
1393 ;; If the list is to be entered into the newsrc assoc, and
1394 ;; it was killed, we have to create an entry in the newsrc
1395 ;; hashtb format and fix the pointers in the newsrc assoc.
1396 (if (< oldlevel gnus-level-zombie
)
1397 ;; It was alive, and it is going to stay alive, so we
1398 ;; just change the level and don't change any pointers or
1399 ;; hash table entries.
1400 (setcar (cdaddr entry
) level
)
1402 (setq info
(cdr entry
)
1404 (setq active
(gnus-active group
))
1406 (if active
(- (1+ (cdr active
)) (car active
)) t
))
1407 ;; Shorten the select method if possible, if we need to
1408 ;; store it at all (native groups).
1409 (let ((method (gnus-method-simplify
1410 (or gnus-override-subscribe-method
1411 (gnus-group-method group
)))))
1413 (setq info
(list group level nil nil method
))
1414 (setq info
(list group level nil
)))))
1417 (let ((p gnus-newsrc-alist
))
1421 (setq entry
(cons info
(cddr previous
)))
1424 (setcdr (cdr previous
) entry
)
1425 (gnus-sethash group
(cons num
(cdr previous
))
1426 gnus-newsrc-hashtb
))
1427 (setcdr previous entry
)
1428 (gnus-sethash group
(cons num previous
)
1429 gnus-newsrc-hashtb
))
1431 (setcdr (gnus-gethash (caadr entry
) gnus-newsrc-hashtb
) entry
))
1434 "(gnus-group-set-info '%S)" info
)))))
1435 (when gnus-group-change-level-function
1436 (funcall gnus-group-change-level-function
1437 group level oldlevel previous
)))))
1439 (defun gnus-kill-newsgroup (newsgroup)
1440 "Obsolete function. Kills a newsgroup."
1441 (gnus-group-change-level
1442 (gnus-gethash newsgroup gnus-newsrc-hashtb
) gnus-level-killed
))
1444 (defun gnus-check-bogus-newsgroups (&optional confirm
)
1445 "Remove bogus newsgroups.
1446 If CONFIRM is non-nil, the user has to confirm the deletion of every
1448 (let ((newsrc (cdr gnus-newsrc-alist
))
1449 bogus group entry info
)
1450 (gnus-message 5 "Checking bogus newsgroups...")
1451 (unless (gnus-read-active-file-p)
1452 (gnus-read-active-file t
))
1453 (when (gnus-read-active-file-p)
1454 ;; Find all bogus newsgroup that are subscribed.
1456 (setq info
(pop newsrc
)
1457 group
(gnus-info-group info
))
1458 (unless (or (gnus-active group
) ; Active
1459 (and (gnus-info-method info
)
1460 (not (gnus-secondary-method-p
1461 (gnus-info-method info
))))) ; Foreign
1462 ;; Found a bogus newsgroup.
1463 (push group bogus
)))
1466 "Remove bogus group %s? "
1468 ;; Remove all bogus subscribed groups by first killing them, and
1469 ;; then removing them from the list of killed groups.
1470 (when (setq entry
(gnus-gethash group gnus-newsrc-hashtb
))
1471 (gnus-group-change-level entry gnus-level-killed
)
1472 (setq gnus-killed-list
(delete group gnus-killed-list
))))
1473 bogus
'("group" "groups" "remove"))
1474 (while (setq group
(pop bogus
))
1475 ;; Remove all bogus subscribed groups by first killing them, and
1476 ;; then removing them from the list of killed groups.
1477 (when (setq entry
(gnus-gethash group gnus-newsrc-hashtb
))
1478 (gnus-group-change-level entry gnus-level-killed
)
1479 (setq gnus-killed-list
(delete group gnus-killed-list
)))))
1480 ;; Then we remove all bogus groups from the list of killed and
1481 ;; zombie groups. They are removed without confirmation.
1482 (let ((dead-lists '(gnus-killed-list gnus-zombie-list
))
1485 (setq killed
(symbol-value (car dead-lists
)))
1487 (unless (gnus-active (setq group
(pop killed
)))
1488 ;; The group is bogus.
1490 (set (car dead-lists
)
1491 (delete group
(symbol-value (car dead-lists
))))))
1492 (setq dead-lists
(cdr dead-lists
))))
1493 (gnus-run-hooks 'gnus-check-bogus-groups-hook
)
1494 (gnus-message 5 "Checking bogus newsgroups...done"))))
1496 (defun gnus-check-duplicate-killed-groups ()
1497 "Remove duplicates from the list of killed groups."
1499 (let ((killed gnus-killed-list
))
1501 (gnus-message 9 "%d" (length killed
))
1502 (setcdr killed
(delete (car killed
) (cdr killed
)))
1503 (setq killed
(cdr killed
)))))
1505 ;; We want to inline a function from gnus-cache, so we cheat here:
1507 (defvar gnus-cache-active-hashtb
)
1508 (defun gnus-cache-possibly-alter-active (group active
)
1509 "Alter the ACTIVE info for GROUP to reflect the articles in the cache."
1510 (when gnus-cache-active-hashtb
1511 (let ((cache-active (gnus-gethash group gnus-cache-active-hashtb
)))
1513 (when (< (car cache-active
) (car active
))
1514 (setcar active
(car cache-active
)))
1515 (when (> (cdr cache-active
) (cdr active
))
1516 (setcdr active
(cdr cache-active
))))))))
1518 (defun gnus-activate-group (group &optional scan dont-check method
)
1519 "Check whether a group has been activated or not.
1520 If SCAN, request a scan of that group as well."
1521 (let ((method (or method
(inline (gnus-find-method-for-group group
))))
1523 (and (inline (gnus-check-server method
))
1524 ;; We escape all bugs and quit here to make it possible to
1525 ;; continue if a group is so out-there that it reports bugs
1529 (gnus-check-backend-function 'request-scan
(car method
))
1530 (gnus-request-scan group method
))
1532 (if (or debug-on-error debug-on-quit
)
1533 (inline (gnus-request-group group dont-check method
))
1535 (inline (gnus-request-group group dont-check method
))
1538 (message "Quit activating %s" group
)
1541 (setq active
(gnus-parse-active))
1542 ;; If there are no articles in the group, the GROUP
1543 ;; command may have responded with the `(0 . 0)'. We
1544 ;; ignore this if we already have an active entry
1546 (if (and (zerop (car active
))
1547 (zerop (cdr active
))
1548 (gnus-active group
))
1551 ;; If a cache is present, we may have to alter the active info.
1552 (when gnus-use-cache
1553 (inline (gnus-cache-possibly-alter-active
1556 ;; If the agent is enabled, we may have to alter the active info.
1558 (gnus-agent-possibly-alter-active group active
))
1560 (gnus-set-active group active
)
1561 ;; Return the new active info.
1564 (defun gnus-get-unread-articles-in-group (info active
&optional update
)
1565 (when (and info active
)
1566 ;; Allow the backend to update the info in the group.
1568 (gnus-request-update-info
1569 info
(inline (gnus-find-method-for-group
1570 (gnus-info-group info
)))))
1571 (gnus-activate-group (gnus-info-group info
) nil t
))
1573 (let* ((range (gnus-info-read info
))
1576 ;; These checks are present in gnus-activate-group but skipped
1577 ;; due to setting dont-check in the preceeding call.
1579 ;; If a cache is present, we may have to alter the active info.
1580 (when (and gnus-use-cache info
)
1581 (inline (gnus-cache-possibly-alter-active
1582 (gnus-info-group info
) active
)))
1584 ;; If the agent is enabled, we may have to alter the active info.
1585 (when (and gnus-agent info
)
1586 (gnus-agent-possibly-alter-active (gnus-info-group info
) active info
))
1588 ;; Modify the list of read articles according to what articles
1589 ;; are available; then tally the unread articles and add the
1590 ;; number to the group hash table entry.
1592 ((zerop (cdr active
))
1595 (setq num
(- (1+ (cdr active
)) (car active
))))
1596 ((not (listp (cdr range
)))
1597 ;; Fix a single (num . num) range according to the
1598 ;; active hash table.
1599 ;; Fix by Carsten Bormann <cabo@Informatik.Uni-Bremen.DE>.
1600 (and (< (cdr range
) (car active
)) (setcdr range
(1- (car active
))))
1601 (and (> (cdr range
) (cdr active
)) (setcdr range
(cdr active
)))
1602 ;; Compute number of unread articles.
1603 (setq num
(max 0 (- (cdr active
) (- (1+ (cdr range
)) (car range
))))))
1605 ;; The read list is a list of ranges. Fix them according to
1606 ;; the active hash table.
1607 ;; First peel off any elements that are below the lower
1609 (while (and (cdr range
)
1611 (or (and (atom (cadr range
)) (cadr range
))
1613 (if (numberp (car range
))
1616 (or (and (numberp (cadr range
))
1620 (or (and (numberp (nth 1 range
)) (nth 1 range
))
1622 (setcdr range
(cddr range
)))
1623 ;; Adjust the first element to be the same as the lower limit.
1624 (when (and (not (atom (car range
)))
1625 (< (cdar range
) (car active
)))
1626 (setcdr (car range
) (1- (car active
))))
1627 ;; Then we want to peel off any elements that are higher
1628 ;; than the upper active limit.
1629 (let ((srange range
))
1630 ;; Go past all valid elements.
1631 (while (and (cdr srange
)
1632 (<= (or (and (atom (cadr srange
))
1636 (setq srange
(cdr srange
)))
1638 ;; Nuke all remaining invalid elements.
1639 (setcdr srange nil
))
1641 ;; Adjust the final element.
1642 (when (and (not (atom (car srange
)))
1643 (> (cdar srange
) (cdr active
)))
1644 (setcdr (car srange
) (cdr active
))))
1645 ;; Compute the number of unread articles.
1647 (setq num
(+ num
(- (1+ (or (and (atom (car range
)) (car range
))
1649 (or (and (atom (car range
)) (car range
))
1651 (setq range
(cdr range
)))
1652 (setq num
(max 0 (- (cdr active
) num
)))))
1653 ;; Set the number of unread articles.
1655 (gnus-gethash (gnus-info-group info
) gnus-newsrc-hashtb
))
1656 (setcar (gnus-gethash (gnus-info-group info
) gnus-newsrc-hashtb
) num
))
1659 ;; Go though `gnus-newsrc-alist' and compare with `gnus-active-hashtb'
1660 ;; and compute how many unread articles there are in each group.
1661 (defun gnus-get-unread-articles (&optional level
)
1662 (setq gnus-server-method-cache nil
)
1663 (let* ((newsrc (cdr gnus-newsrc-alist
))
1664 (level (or level gnus-activate-level
(1+ gnus-level-subscribed
)))
1667 (cond ((and gnus-activate-foreign-newsgroups
1668 (not (numberp gnus-activate-foreign-newsgroups
)))
1669 (1+ gnus-level-subscribed
))
1670 ((numberp gnus-activate-foreign-newsgroups
)
1671 gnus-activate-foreign-newsgroups
)
1676 scanned-methods info group active method retrieve-groups cmethod
1678 (gnus-message 6 "Checking new news...")
1681 (setq active
(gnus-active (setq group
(gnus-info-group
1682 (setq info
(pop newsrc
))))))
1684 ;; Check newsgroups. If the user doesn't want to check them, or
1685 ;; they can't be checked (for instance, if the news server can't
1686 ;; be reached) we just set the number of unread articles in this
1687 ;; newsgroup to t. This means that Gnus thinks that there are
1688 ;; unread articles, but it has no idea how many.
1690 ;; To be more explicit:
1691 ;; >0 for an active group with messages
1692 ;; 0 for an active group with no unread messages
1693 ;; nil for non-foreign groups that the user has requested not be checked
1694 ;; t for unchecked foreign groups or bogus groups, or groups that can't
1695 ;; be checked, for one reason or other.
1696 (when (setq method
(gnus-info-method info
))
1697 (if (setq cmethod
(assoc method methods-cache
))
1698 (setq method
(cdr cmethod
))
1699 (setq cmethod
(inline (gnus-server-get-method nil method
)))
1700 (push (cons method cmethod
) methods-cache
)
1701 (setq method cmethod
)))
1703 (not (setq method-type
(cdr (assoc method type-cache
)))))
1706 ((gnus-secondary-method-p method
)
1708 ((inline (gnus-server-equal gnus-select-method method
))
1712 (push (cons method method-type
) type-cache
))
1714 (cond ((and method
(eq method-type
'foreign
))
1715 ;; These groups are foreign. Check the level.
1716 (when (and (<= (gnus-info-level info
) foreign-level
)
1717 (setq active
(gnus-activate-group group
'scan
)))
1718 ;; Let the Gnus agent save the active file.
1719 (when (and gnus-agent active
(gnus-online method
))
1720 (gnus-agent-save-group-info
1721 method
(gnus-group-real-name group
) active
))
1722 (unless (inline (gnus-virtual-group-p group
))
1723 (inline (gnus-close-group group
)))
1724 (when (fboundp (intern (concat (symbol-name (car method
))
1725 "-request-update-info")))
1726 (inline (gnus-request-update-info info method
)))))
1727 ;; These groups are native or secondary.
1728 ((> (gnus-info-level info
) level
)
1729 ;; We don't want these groups.
1730 (setq active
'ignore
))
1732 ((not gnus-read-active-file
)
1733 (if (gnus-check-backend-function 'retrieve-groups group
)
1734 ;; if server support gnus-retrieve-groups we push
1735 ;; the group onto retrievegroups for later checking
1736 (if (assoc method retrieve-groups
)
1737 (setcdr (assoc method retrieve-groups
)
1738 (cons group
(cdr (assoc method retrieve-groups
))))
1739 (push (list method group
) retrieve-groups
))
1740 ;; hack: `nnmail-get-new-mail' changes the mail-source depending
1741 ;; on the group, so we must perform a scan for every group
1742 ;; if the users has any directory mail sources.
1743 ;; hack: if `nnmail-scan-directory-mail-source-once' is non-nil,
1744 ;; for it scan all spool files even when the groups are
1747 (or nnmail-scan-directory-mail-source-once
1748 (null (assq 'directory
1750 (if (listp nnmail-spool-file
)
1752 (list nnmail-spool-file
))))))
1753 (member method scanned-methods
))
1754 (setq active
(gnus-activate-group group
))
1755 (setq active
(gnus-activate-group group
'scan
))
1756 (push method scanned-methods
))
1758 (gnus-close-group group
)))))
1760 ;; Get the number of unread articles in the group.
1762 ((eq active
'ignore
)
1763 ;; Don't do anything.
1766 (inline (gnus-get-unread-articles-in-group info active t
)))
1768 ;; The group couldn't be reached, so we nix out the number of
1769 ;; unread articles and stuff.
1770 (gnus-set-active group nil
)
1771 (let ((tmp (gnus-gethash group gnus-newsrc-hashtb
)))
1775 ;; iterate through groups on methods which support gnus-retrieve-groups
1776 ;; and fetch a partial active file and use it to find new news.
1777 (dolist (rg retrieve-groups
)
1778 (let ((method (or (car rg
) gnus-select-method
))
1780 (when (gnus-check-server method
)
1781 ;; Request that the backend scan its incoming messages.
1782 (when (gnus-check-backend-function 'request-scan
(car method
))
1783 (gnus-request-scan nil method
))
1784 (gnus-read-active-file-2
1785 (mapcar (lambda (group) (gnus-group-real-name group
)) groups
)
1787 (dolist (group groups
)
1789 ((setq active
(gnus-active (gnus-info-group
1790 (setq info
(gnus-get-info group
)))))
1791 (inline (gnus-get-unread-articles-in-group info active t
)))
1793 ;; The group couldn't be reached, so we nix out the number of
1794 ;; unread articles and stuff.
1795 (gnus-set-active group nil
)
1796 (setcar (gnus-gethash group gnus-newsrc-hashtb
) t
)))))))
1798 (gnus-message 6 "Checking new news...done")))
1800 ;; Create a hash table out of the newsrc alist. The `car's of the
1801 ;; alist elements are used as keys.
1802 (defun gnus-make-hashtable-from-newsrc-alist ()
1803 (let ((alist gnus-newsrc-alist
)
1804 (ohashtb gnus-newsrc-hashtb
)
1806 (setq gnus-newsrc-hashtb
(gnus-make-hashtable (length alist
)))
1808 (setq prev
(setq gnus-newsrc-alist
1809 (if (equal (caar gnus-newsrc-alist
)
1812 (cons (list "dummy.group" 0 nil
) alist
)))))
1816 ;; Preserve number of unread articles in groups.
1817 (cons (and ohashtb
(car (gnus-gethash (caar alist
) ohashtb
)))
1821 alist
(cdr alist
)))))
1823 (defun gnus-make-hashtable-from-killed ()
1824 "Create a hash table from the killed and zombie lists."
1825 (let ((lists '(gnus-killed-list gnus-zombie-list
))
1827 (setq gnus-killed-hashtb
1828 (gnus-make-hashtable
1829 (+ (length gnus-killed-list
) (length gnus-zombie-list
))))
1831 (setq list
(symbol-value (pop lists
)))
1833 (gnus-sethash (car list
) (pop list
) gnus-killed-hashtb
)))))
1835 (defun gnus-parse-active ()
1836 "Parse active info in the nntp server buffer."
1838 (set-buffer nntp-server-buffer
)
1839 (goto-char (point-min))
1840 ;; Parse the result we got from `gnus-request-group'.
1841 (when (looking-at "[0-9]+ [0-9]+ \\([0-9]+\\) [0-9]+")
1842 (goto-char (match-beginning 1))
1843 (cons (read (current-buffer))
1844 (read (current-buffer))))))
1846 (defun gnus-make-articles-unread (group articles
)
1847 "Mark ARTICLES in GROUP as unread."
1848 (let* ((info (nth 2 (or (gnus-gethash group gnus-newsrc-hashtb
)
1849 (gnus-gethash (gnus-group-real-name group
)
1850 gnus-newsrc-hashtb
))))
1851 (ranges (gnus-info-read info
))
1854 (when (gnus-member-of-range
1855 (setq article
(pop articles
)) ranges
)
1856 (push article news
)))
1858 ;; Enter this list into the group info.
1860 info
(gnus-remove-from-range (gnus-info-read info
) (nreverse news
)))
1862 ;; Set the number of unread articles in gnus-newsrc-hashtb.
1863 (gnus-get-unread-articles-in-group info
(gnus-active group
))
1865 ;; Insert the change into the group buffer and the dribble file.
1866 (gnus-group-update-group group t
))))
1868 (defun gnus-make-ascending-articles-unread (group articles
)
1869 "Mark ascending ARTICLES in GROUP as unread."
1870 (let* ((entry (or (gnus-gethash group gnus-newsrc-hashtb
)
1871 (gnus-gethash (gnus-group-real-name group
)
1872 gnus-newsrc-hashtb
)))
1873 (info (nth 2 entry
))
1874 (ranges (gnus-info-read info
))
1879 (let ((article (pop articles
))) ; get the next article to remove from ranges
1880 (while (let ((range (car ranges
))) ; note the current range
1881 (if (atom range
) ; single value range
1883 ;; the articles extend past the end of the ranges
1885 (setq articles nil
))
1887 ;; this range preceeds the article. Leave the range unmodified.
1891 ;; this range exactly matches the article; REMOVE THE RANGE.
1892 ;; NOTE: When the range being removed is the last range, the list is corrupted by inserting null at its end.
1893 (setcar ranges
(cadr ranges
))
1894 (setcdr ranges
(cddr ranges
))
1895 (setq modified
(if (car ranges
) t
'remove-null
))
1897 (let ((min (car range
))
1899 ;; I have a min/max range to consider
1900 (cond ((> min max
) ; invalid range introduced by splitter
1901 (setcar ranges
(cadr ranges
))
1902 (setcdr ranges
(cddr ranges
))
1903 (setq modified
(if (car ranges
) t
'remove-null
))
1906 ;; replace min/max range with a single-value range
1910 ;; this range preceeds the article. Leave the range unmodified.
1914 ;; this article preceeds the range. Return null to move to the
1918 ;; this article splits the range into two parts
1919 (setcdr ranges
(cons (cons (1+ article
) max
) (cdr ranges
)))
1920 (setcdr range
(1- article
))
1925 (when (eq modified
'remove-null
)
1926 (setq r
(delq nil r
)))
1927 ;; Enter this list into the group info.
1928 (gnus-info-set-read info r
)
1930 ;; Set the number of unread articles in gnus-newsrc-hashtb.
1931 (gnus-get-unread-articles-in-group info
(gnus-active group
))
1933 ;; Insert the change into the group buffer and the dribble file.
1934 (gnus-group-update-group group t
))))
1936 ;; Enter all dead groups into the hashtb.
1937 (defun gnus-update-active-hashtb-from-killed ()
1938 (let ((hashtb (setq gnus-active-hashtb
(gnus-make-hashtable 4096)))
1939 (lists (list gnus-killed-list gnus-zombie-list
))
1942 (setq killed
(car lists
))
1944 (gnus-sethash (car killed
) nil hashtb
)
1945 (setq killed
(cdr killed
)))
1946 (setq lists
(cdr lists
)))))
1948 (defun gnus-get-killed-groups ()
1949 "Go through the active hashtb and mark all unknown groups as killed."
1950 ;; First make sure active file has been read.
1951 (unless (gnus-read-active-file-p)
1952 (let ((gnus-read-active-file t
))
1953 (gnus-read-active-file)))
1954 (unless gnus-killed-hashtb
1955 (gnus-make-hashtable-from-killed))
1956 ;; Go through all newsgroups that are known to Gnus - enlarge kill list.
1960 (group (symbol-name sym
)))
1961 (if (or (null group
)
1962 (gnus-gethash group gnus-killed-hashtb
)
1963 (gnus-gethash group gnus-newsrc-hashtb
))
1965 (let ((do-sub (gnus-matches-options-n group
)))
1966 (if (or (eq do-sub
'subscribe
) (eq do-sub
'ignore
))
1968 (setq groups
(1+ groups
))
1969 (push group gnus-killed-list
)
1970 (gnus-sethash group group gnus-killed-hashtb
))))))
1972 (gnus-dribble-touch))
1974 ;; Get the active file(s) from the backend(s).
1975 (defun gnus-read-active-file (&optional force not-native
)
1976 (gnus-group-set-mode-line)
1979 (lambda (m) (if (stringp m
) (gnus-server-get-method nil m
) m
))
1981 (if (and (not not-native
)
1982 (gnus-check-server gnus-select-method
))
1983 ;; The native server is available.
1984 (cons gnus-select-method gnus-secondary-select-methods
)
1985 ;; The native server is down, so we just do the
1987 gnus-secondary-select-methods
)
1988 ;; Also read from the archive server.
1989 (when (gnus-archive-server-wanted-p)
1990 (list "archive")))))
1992 (setq gnus-have-read-active-file nil
)
1994 (set-buffer nntp-server-buffer
)
1995 (while (setq method
(pop methods
))
1996 ;; Only do each method once, in case the methods appear more
1997 ;; than once in this list.
1998 (unless (member method methods
)
1999 (if (or debug-on-error debug-on-quit
)
2000 (gnus-read-active-file-1 method force
)
2002 (gnus-read-active-file-1 method force
)
2003 ;; We catch C-g so that we can continue past servers
2004 ;; that do not respond.
2006 (message "Quit reading the active file")
2009 (defun gnus-read-active-file-1 (method force
)
2011 (setq where
(nth 1 method
)
2012 mesg
(format "Reading active file%s via %s..."
2013 (if (and where
(not (zerop (length where
))))
2014 (concat " from " where
) "")
2016 (gnus-message 5 mesg
)
2017 (when (gnus-check-server method
)
2018 ;; Request that the backend scan its incoming messages.
2019 (when (gnus-check-backend-function 'request-scan
(car method
))
2020 (gnus-request-scan nil method
))
2022 ((and (eq gnus-read-active-file
'some
)
2023 (gnus-check-backend-function 'retrieve-groups
(car method
))
2025 (let ((newsrc (cdr gnus-newsrc-alist
))
2026 (gmethod (gnus-server-get-method nil method
))
2028 (while (setq info
(pop newsrc
))
2032 (gnus-find-method-for-group
2033 (gnus-info-group info
) info
))
2035 (push (gnus-group-real-name (gnus-info-group info
))
2037 (gnus-read-active-file-2 groups method
)))
2041 (if (not (gnus-request-list method
))
2042 (unless (equal method gnus-message-archive-method
)
2043 (gnus-error 1 "Cannot read active file from %s server"
2045 (gnus-message 5 mesg
)
2046 (gnus-active-to-gnus-format method gnus-active-hashtb nil t
)
2047 ;; We mark this active file as read.
2048 (push method gnus-have-read-active-file
)
2049 (gnus-message 5 "%sdone" mesg
)))))))
2051 (defun gnus-read-active-file-2 (groups method
)
2052 "Read an active file for GROUPS in METHOD using `gnus-retrieve-groups'."
2055 (set-buffer nntp-server-buffer
)
2056 (gnus-check-server method
)
2057 (let ((list-type (gnus-retrieve-groups groups method
)))
2058 (cond ((not list-type
)
2060 1.2 "Cannot read partial active file from %s server."
2062 ((eq list-type
'active
)
2063 (gnus-active-to-gnus-format method gnus-active-hashtb nil t
))
2065 (gnus-groups-to-gnus-format method gnus-active-hashtb t
)))))))
2067 ;; Read an active file and place the results in `gnus-active-hashtb'.
2068 (defun gnus-active-to-gnus-format (&optional method hashtb ignore-errors
2071 (setq method gnus-select-method
))
2072 (let ((cur (current-buffer))
2074 (if (and gnus-active-hashtb
2075 (not (equal method gnus-select-method
)))
2077 (setq gnus-active-hashtb
2078 (if (equal method gnus-select-method
)
2079 (gnus-make-hashtable
2080 (count-lines (point-min) (point-max)))
2081 (gnus-make-hashtable 4096)))))))
2082 ;; Delete unnecessary lines.
2083 (goto-char (point-min))
2085 ((string= gnus-ignored-newsgroups
"")
2086 (delete-matching-lines "^to\\."))
2088 (delete-matching-lines (concat "^to\\.\\|" gnus-ignored-newsgroups
))))
2090 (goto-char (point-min))
2091 (unless (re-search-forward "[\\\"]" nil t
)
2092 ;; Make the group names readable as a lisp expression even if they
2093 ;; contain special characters.
2094 (goto-char (point-max))
2095 (while (re-search-backward "[][';?()#]" nil t
)
2098 ;; Let the Gnus agent save the active file.
2099 (when (and gnus-agent real-active
(gnus-online method
))
2100 (gnus-agent-save-active method
))
2102 ;; If these are groups from a foreign select method, we insert the
2103 ;; group prefix in front of the group names.
2104 (when (not (gnus-server-equal
2105 (gnus-server-get-method nil method
)
2106 (gnus-server-get-method nil gnus-select-method
)))
2107 (let ((prefix (gnus-group-prefixed-name "" method
)))
2108 (goto-char (point-min))
2109 (while (and (not (eobp))
2111 (when (= (following-char) ?
\")
2114 (zerop (forward-line 1)))))))
2115 ;; Store the active file in a hash table.
2116 (goto-char (point-min))
2117 (let (group max min
)
2121 (narrow-to-region (point) (gnus-point-at-eol))
2122 ;; group gets set to a symbol interned in the hash table
2123 ;; (what a hack!!) - jwz
2124 (setq group
(let ((obarray hashtb
)) (read cur
)))
2125 ;; ### The extended group name scheme makes
2126 ;; the previous optimization strategy sort of pointless...
2127 (when (stringp group
)
2128 (setq group
(intern group hashtb
)))
2129 (if (and (numberp (setq max
(read cur
)))
2130 (numberp (setq min
(read cur
)))
2132 (skip-chars-forward " \t")
2134 (or (eq (char-after) ?
=)
2135 (eq (char-after) ?x
)
2136 (eq (char-after) ?j
)))))
2138 (set group
(cons min max
))
2139 ;; if group is moderated, stick in moderation table
2140 (when (eq (char-after) ?m
)
2141 (unless gnus-moderated-hashtb
2142 (setq gnus-moderated-hashtb
(gnus-make-hashtable)))
2143 (gnus-sethash (symbol-name group
) t
2144 gnus-moderated-hashtb
)))
2150 (unless ignore-errors
2151 (gnus-message 3 "Warning - invalid active: %s"
2153 (gnus-point-at-bol) (gnus-point-at-eol))))))
2155 (forward-line 1)))))
2157 (defun gnus-groups-to-gnus-format (method &optional hashtb real-active
)
2158 ;; Parse a "groups" active file.
2159 (let ((cur (current-buffer))
2161 (if (and method gnus-active-hashtb
)
2163 (setq gnus-active-hashtb
2164 (gnus-make-hashtable
2165 (count-lines (point-min) (point-max)))))))
2167 (not (gnus-server-equal
2168 (gnus-server-get-method nil method
)
2169 (gnus-server-get-method nil gnus-select-method
)))
2170 (gnus-group-prefixed-name "" method
))))
2172 ;; Let the Gnus agent save the active file.
2175 (gnus-online method
)
2176 (gnus-agent-method-p method
))
2178 (gnus-agent-save-active method
)
2179 (gnus-active-to-gnus-format method hashtb nil real-active
))
2181 (goto-char (point-min))
2182 ;; We split this into to separate loops, one with the prefix
2183 ;; and one without to speed the reading up somewhat.
2185 (let (min max opoint group
)
2189 (read cur
) (read cur
)
2190 (setq min
(read cur
)
2193 (skip-chars-forward " \t")
2196 (set (let ((obarray hashtb
)) (read cur
))
2198 (error (and group
(symbolp group
) (set group nil
))))
2200 (let (min max group
)
2203 (when (eq (char-after) ?
2)
2204 (read cur
) (read cur
)
2205 (setq min
(read cur
)
2207 (set (setq group
(let ((obarray hashtb
)) (read cur
)))
2209 (error (and group
(symbolp group
) (set group nil
))))
2210 (forward-line 1)))))))
2212 (defun gnus-read-newsrc-file (&optional force
)
2214 If FORCE is non-nil, the .newsrc file is read."
2215 ;; Reset variables that might be defined in the .newsrc.eld file.
2216 (let ((variables (remove 'gnus-format-specs gnus-variable-list
)))
2218 (set (car variables
) nil
)
2219 (setq variables
(cdr variables
))))
2220 (let* ((newsrc-file gnus-current-startup-file
)
2221 (quick-file (concat newsrc-file
".el")))
2223 ;; We always load the .newsrc.eld file. If always contains
2224 ;; much information that can not be gotten from the .newsrc
2225 ;; file (ticked articles, killed groups, foreign methods, etc.)
2226 (gnus-read-newsrc-el-file quick-file
)
2228 (when (and gnus-read-newsrc-file
2229 (file-exists-p gnus-current-startup-file
)
2231 (and (file-newer-than-file-p newsrc-file quick-file
)
2232 (file-newer-than-file-p newsrc-file
2233 (concat quick-file
"d")))
2234 (not gnus-newsrc-alist
)))
2235 ;; We read the .newsrc file. Note that if there if a
2236 ;; .newsrc.eld file exists, it has already been read, and
2237 ;; the `gnus-newsrc-hashtb' has been created. While reading
2238 ;; the .newsrc file, Gnus will only use the information it
2239 ;; can find there for changing the data already read -
2240 ;; i. e., reading the .newsrc file will not trash the data
2241 ;; already read (except for read articles).
2243 (gnus-message 5 "Reading %s..." newsrc-file
)
2244 (set-buffer (nnheader-find-file-noselect newsrc-file
))
2245 (buffer-disable-undo)
2246 (gnus-newsrc-to-gnus-format)
2247 (kill-buffer (current-buffer))
2248 (gnus-message 5 "Reading %s...done" newsrc-file
)))
2250 ;; Convert old to new.
2251 (gnus-convert-old-newsrc))))
2253 (defun gnus-convert-old-newsrc ()
2254 "Convert old newsrc formats into the current format, if needed."
2255 (let ((fcv (and gnus-newsrc-file-version
2256 (gnus-continuum-version gnus-newsrc-file-version
)))
2257 (gcv (gnus-continuum-version)))
2259 ;; A newsrc file was loaded.
2260 (let (prompt-displayed
2263 (mapcar (lambda (date-func)
2264 (cons (gnus-continuum-version (car date-func
))
2266 ;; This is a list of converters that must be run
2267 ;; to bring the newsrc file up to the current
2268 ;; version. If you create an incompatibility
2269 ;; with older versions, you should create an
2270 ;; entry here. The entry should consist of the
2271 ;; current gnus version (hardcoded so that it
2272 ;; doesn't change with each release) and the
2273 ;; function that must be applied to convert the
2274 ;; previous version into the current version.
2275 '(("September Gnus v0.1" nil
2276 gnus-convert-old-ticks
)
2277 ("Oort Gnus v0.08" "legacy-gnus-agent"
2278 gnus-agent-convert-to-compressed-agentview
)
2279 ("Gnus v5.10.7" "legacy-gnus-agent"
2280 gnus-agent-unlist-expire-days
)
2281 ("Gnus v5.10.7" "legacy-gnus-agent"
2282 gnus-agent-unhook-expire-days
)))
2283 #'car-less-than-car
)))
2284 ;; Skip converters older than the file version
2285 (while (and converters
(>= fcv
(caar converters
)))
2288 ;; Perform converters to bring older version up to date.
2289 (when (and converters
(< fcv
(caar converters
)))
2290 (while (and converters
(< fcv
(caar converters
))
2291 (<= (caar converters
) gcv
))
2292 (let* ((converter-spec (pop converters
))
2293 (convert-to (nth 1 converter-spec
))
2294 (load-from (nth 2 converter-spec
))
2295 (func (nth 3 converter-spec
)))
2296 (when (and load-from
2297 (not (fboundp func
)))
2299 (or prompt-displayed
2300 (not (gnus-convert-converter-needs-prompt func
))
2302 (cursor-in-echo-area t
)
2303 (echo-keystrokes 0))
2304 (message "Convert gnus from version '%s' to '%s'? (n/y/?)"
2305 gnus-newsrc-file-version gnus-version
)
2306 (setq c
(read-char-exclusive))
2308 (cond ((or (eq c ?n
) (eq c ?N
))
2309 (error "Can not start gnus without converting"))
2310 ((or (eq c ?y
) (eq c ?Y
))
2311 (setq prompt-displayed t
)
2314 (message "This conversion is irreversible. \
2315 To be safe, you should backup your files before proceeding.")
2319 (gnus-message 3 "Ignoring unexpected input")
2323 (funcall func convert-to
)))
2325 (format ";Converted gnus from version '%s' to '%s'."
2326 gnus-newsrc-file-version gnus-version
)))))))
2328 (defun gnus-convert-mark-converter-prompt (converter no-prompt
)
2329 "Indicate whether CONVERTER requires gnus-convert-old-newsrc to
2330 display the conversion prompt. NO-PROMPT may be nil (prompt),
2331 t (no prompt), or any form that can be called as a function.
2332 The form should return either t or nil."
2333 (put converter
'gnus-convert-no-prompt no-prompt
))
2335 (defun gnus-convert-converter-needs-prompt (converter)
2336 (let ((no-prompt (get converter
'gnus-convert-no-prompt
)))
2337 (not (if (memq no-prompt
'(t nil
))
2339 (funcall no-prompt
)))))
2341 (defun gnus-convert-old-ticks (converting-to)
2342 (let ((newsrc (cdr gnus-newsrc-alist
))
2343 marks info dormant ticked
)
2344 (while (setq info
(pop newsrc
))
2345 (when (setq marks
(gnus-info-marks info
))
2346 (setq dormant
(cdr (assq 'dormant marks
))
2347 ticked
(cdr (assq 'tick marks
)))
2348 (when (or dormant ticked
)
2352 (gnus-info-read info
)
2353 (nconc (gnus-uncompress-range dormant
)
2354 (gnus-uncompress-range ticked
)))))))))
2356 (defun gnus-load (file)
2357 "Load FILE, but in such a way that read errors can be reported."
2359 (insert-file-contents file
)
2361 (condition-case type
2362 (let ((form (read (current-buffer))))
2365 (unless (eq (car type
) 'end-of-file
)
2366 (let ((error (format "Error in %s line %d" file
2367 (count-lines (point-min) (point)))))
2369 (unless (gnus-yes-or-no-p (concat error
"; continue? "))
2370 (error "%s" error
)))))))))
2372 (defun gnus-read-newsrc-el-file (file)
2373 (let ((ding-file (concat file
"d")))
2374 (when (file-exists-p ding-file
)
2375 ;; We always, always read the .eld file.
2376 (gnus-message 5 "Reading %s..." ding-file
)
2377 (let (gnus-newsrc-assoc)
2378 (let ((coding-system-for-read gnus-ding-file-coding-system
))
2379 (gnus-load ding-file
))
2380 ;; Older versions of `gnus-format-specs' are no longer valid
2381 ;; in Oort Gnus 0.01.
2383 (and gnus-newsrc-file-version
2384 (gnus-continuum-version gnus-newsrc-file-version
))))
2385 (when (or (not version
)
2386 (< version
5.090009))
2387 (setq gnus-format-specs gnus-default-format-specs
)))
2388 (when gnus-newsrc-assoc
2389 (setq gnus-newsrc-alist gnus-newsrc-assoc
))))
2390 (gnus-make-hashtable-from-newsrc-alist)
2391 (when (file-newer-than-file-p file ding-file
)
2392 ;; Old format quick file
2393 (gnus-message 5 "Reading %s..." file
)
2394 ;; The .el file is newer than the .eld file, so we read that one
2396 (gnus-read-old-newsrc-el-file file
)))
2397 (gnus-run-hooks 'gnus-read-newsrc-el-hook
))
2399 ;; Parse the old-style quick startup file
2400 (defun gnus-read-old-newsrc-el-file (file)
2401 (let (newsrc killed marked group m info
)
2403 (let ((gnus-killed-assoc nil
)
2404 gnus-marked-assoc gnus-newsrc-alist gnus-newsrc-assoc
)
2408 (setq newsrc gnus-newsrc-assoc
2409 killed gnus-killed-assoc
2410 marked gnus-marked-assoc
)))
2411 (setq gnus-newsrc-alist nil
)
2412 (while (setq group
(pop newsrc
))
2413 (if (setq info
(gnus-get-info (car group
)))
2415 (gnus-info-set-read info
(cddr group
))
2416 (gnus-info-set-level
2417 info
(if (nth 1 group
) gnus-level-default-subscribed
2418 gnus-level-default-unsubscribed
))
2419 (push info gnus-newsrc-alist
))
2422 (if (nth 1 group
) gnus-level-default-subscribed
2423 gnus-level-default-unsubscribed
)
2426 ;; Copy marks into info.
2427 (when (setq m
(assoc (car group
) marked
))
2428 (unless (nthcdr 3 info
)
2429 (nconc info
(list nil
)))
2430 (gnus-info-set-marks
2431 info
(list (cons 'tick
(gnus-compress-sequence
2432 (sort (cdr m
) '<) t
))))))
2433 (setq newsrc killed
)
2435 (setcar newsrc
(caar newsrc
))
2436 (setq newsrc
(cdr newsrc
)))
2437 (setq gnus-killed-list killed
))
2438 ;; The .el file version of this variable does not begin with
2439 ;; "options", while the .eld version does, so we just add it if it
2443 (when (not (string-match "^ *options" gnus-newsrc-options
))
2444 (setq gnus-newsrc-options
(concat "options " gnus-newsrc-options
)))
2445 (when (not (string-match "\n$" gnus-newsrc-options
))
2446 (setq gnus-newsrc-options
(concat gnus-newsrc-options
"\n")))
2447 ;; Finally, if we read some options lines, we parse them.
2448 (unless (string= gnus-newsrc-options
"")
2449 (gnus-newsrc-parse-options gnus-newsrc-options
)))
2451 (setq gnus-newsrc-alist
(nreverse gnus-newsrc-alist
))
2452 (gnus-make-hashtable-from-newsrc-alist)))
2454 (defun gnus-make-newsrc-file (file)
2455 "Make server dependent file name by catenating FILE and server host name."
2456 (let* ((file (expand-file-name file nil
))
2457 (real-file (concat file
"-" (nth 1 gnus-select-method
))))
2458 (if (or (file-exists-p real-file
)
2459 (file-exists-p (concat real-file
".el"))
2460 (file-exists-p (concat real-file
".eld")))
2464 (defun gnus-newsrc-to-gnus-format ()
2465 (setq gnus-newsrc-options
"")
2466 (setq gnus-newsrc-options-n nil
)
2468 (unless gnus-active-hashtb
2469 (setq gnus-active-hashtb
(gnus-make-hashtable 4096)))
2470 (let ((buf (current-buffer))
2471 (already-read (> (length gnus-newsrc-alist
) 1))
2472 group subscribed options-symbol newsrc Options-symbol
2474 (goto-char (point-min))
2475 ;; We intern the symbol `options' in the active hashtb so that we
2476 ;; can `eq' against it later.
2477 (set (setq options-symbol
(intern "options" gnus-active-hashtb
)) nil
)
2478 (set (setq Options-symbol
(intern "Options" gnus-active-hashtb
)) nil
)
2481 ;; We first read the first word on the line by narrowing and
2482 ;; then reading into `gnus-active-hashtb'. Most groups will
2483 ;; already exist in that hashtb, so this will save some string
2487 (progn (skip-chars-forward "^ \t!:\n") (point)))
2488 (goto-char (point-min))
2490 (and (/= (point-min) (point-max))
2491 (let ((obarray gnus-active-hashtb
)) (read buf
))))
2493 ;; Now, the symbol we have read is either `options' or a group
2494 ;; name. If it is an options line, we just add it to a string.
2496 ((or (eq symbol options-symbol
)
2497 (eq symbol Options-symbol
))
2498 (setq gnus-newsrc-options
2499 ;; This concating is quite inefficient, but since our
2500 ;; thorough studies show that approx 99.37% of all
2501 ;; .newsrc files only contain a single options line, we
2502 ;; don't give a damn, frankly, my dear.
2503 (concat gnus-newsrc-options
2506 ;; Options may continue on the next line.
2507 (or (and (re-search-forward "^[^ \t]" nil
'move
)
2508 (progn (beginning-of-line) (point)))
2512 ;; Group names can be just numbers.
2513 (when (numberp symbol
)
2514 (setq symbol
(intern (int-to-string symbol
) gnus-active-hashtb
)))
2515 (unless (boundp symbol
)
2517 ;; It was a group name.
2518 (setq subscribed
(eq (char-after) ?
:)
2519 group
(symbol-name symbol
)
2522 ;; If the line ends here, this is clearly a buggy line, so
2523 ;; we put point a the beginning of line and let the cond
2524 ;; below do the error handling.
2526 ;; We skip to the beginning of the ranges.
2527 (skip-chars-forward "!: \t"))
2528 ;; We are now at the beginning of the list of read articles.
2529 ;; We read them range by range.
2532 ((looking-at "[0-9]+")
2533 ;; We narrow and read a number instead of buffer-substring/
2534 ;; string-to-number because it's faster. narrow/widen is
2535 ;; faster than save-restriction/narrow, and save-restriction
2536 ;; produces a garbage object.
2538 (narrow-to-region (match-beginning 0) (match-end 0))
2541 ;; If the next character is a dash, then this is a range.
2542 (if (eq (char-after) ?-
)
2544 ;; We read the upper bound of the range.
2546 (if (not (looking-at "[0-9]+"))
2547 ;; This is a buggy line, by we pretend that
2548 ;; it's kinda OK. Perhaps the user should be
2554 (narrow-to-region (match-beginning 0)
2559 ;; It was just a simple number, so we add it to the
2562 ;; If the next char in ?\n, then we have reached the end
2563 ;; of the line and return nil.
2564 (not (eq (char-after) ?
\n)))
2565 ((eq (char-after) ?
\n)
2566 ;; End of line, so we end.
2569 ;; Not numbers and not eol, so this might be a buggy
2572 ;; If it was eob instead of ?\n, we allow it.
2573 ;; The line was buggy.
2575 (gnus-error 3.1 "Mangled line: %s"
2576 (buffer-substring (gnus-point-at-bol)
2577 (gnus-point-at-eol))))
2579 ;; Skip past ", ". Spaces are invalid in these ranges, but
2580 ;; we allow them, because it's a common mistake to put a
2581 ;; space after the comma.
2582 (skip-chars-forward ", "))
2584 ;; We have already read .newsrc.eld, so we gently update the
2585 ;; data in the hash table with the information we have just
2588 (let ((info (gnus-get-info group
))
2591 ;; There is an entry for this file in the alist.
2593 (gnus-info-set-read info
(nreverse reads
))
2594 ;; We update the level very gently. In fact, we
2595 ;; only change it if there's been a status change
2596 ;; from subscribed to unsubscribed, or vice versa.
2597 (setq level
(gnus-info-level info
))
2598 (cond ((and (<= level gnus-level-subscribed
)
2600 (setq level
(if reads
2601 gnus-level-default-unsubscribed
2602 (1+ gnus-level-default-unsubscribed
))))
2603 ((and (> level gnus-level-subscribed
) subscribed
)
2604 (setq level gnus-level-default-subscribed
)))
2605 (gnus-info-set-level info level
))
2606 ;; This is a new group.
2607 (setq info
(list group
2609 gnus-level-default-subscribed
2611 (1+ gnus-level-subscribed
)
2612 gnus-level-default-unsubscribed
))
2614 (push info newsrc
)))))
2617 (setq newsrc
(nreverse newsrc
))
2619 (if (not already-read
)
2621 ;; We now have two newsrc lists - `newsrc', which is what we
2622 ;; have read from .newsrc, and `gnus-newsrc-alist', which is
2623 ;; what we've read from .newsrc.eld. We have to merge these
2624 ;; lists. We do this by "attaching" any (foreign) groups in the
2625 ;; gnus-newsrc-alist to the (native) group that precedes them.
2626 (let ((rc (cdr gnus-newsrc-alist
))
2627 (prev gnus-newsrc-alist
)
2630 (or (null (nth 4 (car rc
))) ; It's a native group.
2631 (assoc (caar rc
) newsrc
) ; It's already in the alist.
2632 (if (setq entry
(assoc (caar prev
) newsrc
))
2633 (setcdr (setq mentry
(memq entry newsrc
))
2634 (cons (car rc
) (cdr mentry
)))
2635 (push (car rc
) newsrc
)))
2639 (setq gnus-newsrc-alist newsrc
)
2640 ;; We make the newsrc hashtb.
2641 (gnus-make-hashtable-from-newsrc-alist)
2643 ;; Finally, if we read some options lines, we parse them.
2644 (unless (string= gnus-newsrc-options
"")
2645 (gnus-newsrc-parse-options gnus-newsrc-options
))))
2647 ;; Parse options lines to find "options -n !all rec.all" and stuff.
2648 ;; The return value will be a list on the form
2649 ;; ((regexp1 . ignore)
2650 ;; (regexp2 . subscribe)...)
2651 ;; When handling new newsgroups, groups that match a `ignore' regexp
2652 ;; will be ignored, and groups that match a `subscribe' regexp will be
2653 ;; subscribed. A line like
2654 ;; options -n !all rec.all
2655 ;; will lead to a list that looks like
2656 ;; (("^rec\\..+" . subscribe)
2657 ;; ("^.+" . ignore))
2658 ;; So all "rec.*" groups will be subscribed, while all the other
2659 ;; groups will be ignored. Note that "options -n !all rec.all" is very
2660 ;; different from "options -n rec.all !all".
2661 (defun gnus-newsrc-parse-options (options)
2664 (gnus-set-work-buffer)
2665 (insert (regexp-quote options
))
2666 ;; First we treat all continuation lines.
2667 (goto-char (point-min))
2668 (while (re-search-forward "\n[ \t]+" nil t
)
2669 (replace-match " " t t
))
2670 ;; Then we transform all "all"s into ".+"s.
2671 (goto-char (point-min))
2672 (while (re-search-forward "\\ball\\b" nil t
)
2673 (replace-match ".+" t t
))
2674 (goto-char (point-min))
2675 ;; We remove all other options than the "-n" ones.
2676 (while (re-search-forward "[ \t]-[^n][^-]*" nil t
)
2679 (goto-char (point-min))
2681 ;; We are only interested in "options -n" lines - we
2682 ;; ignore the other option lines.
2683 (while (re-search-forward "[ \t]-n" nil t
)
2686 (and (re-search-forward "[ \t]-n" (gnus-point-at-eol) t
)
2688 (gnus-point-at-eol)))
2689 ;; Search for all "words"...
2690 (while (re-search-forward "[^ \t,\n]+" eol t
)
2691 (if (eq (char-after (match-beginning 0)) ?
!)
2692 ;; If the word begins with a bang (!), this is a "not"
2693 ;; spec. We put this spec (minus the bang) and the
2694 ;; symbol `ignore' into the list.
2696 "^" (buffer-substring
2697 (1+ (match-beginning 0))
2702 ;; There was no bang, so this is a "yes" spec.
2703 (push (cons (concat "^" (match-string 0) "\\($\\|\\.\\)")
2707 (setq gnus-newsrc-options-n out
))))
2710 (defalias 'gnus-long-file-names
2711 (if (fboundp 'msdos-long-file-names
)
2712 'msdos-long-file-names
2715 (defun gnus-save-newsrc-file (&optional force
)
2716 "Save .newsrc file."
2717 ;; Note: We cannot save .newsrc file if all newsgroups are removed
2718 ;; from the variable gnus-newsrc-alist.
2719 (when (and (or gnus-newsrc-alist gnus-killed-list
)
2720 gnus-current-startup-file
)
2721 ;; Save agent range limits for the currently active method.
2723 (gnus-agent-save-local force
))
2726 (if (and (or gnus-use-dribble-file gnus-slave
)
2728 (or (not gnus-dribble-buffer
)
2729 (not (buffer-name gnus-dribble-buffer
))
2730 (zerop (save-excursion
2731 (set-buffer gnus-dribble-buffer
)
2733 (gnus-message 4 "(No changes need to be saved)")
2734 (gnus-run-hooks 'gnus-save-newsrc-hook
)
2736 (gnus-slave-save-newsrc)
2738 (when gnus-save-newsrc-file
2739 (gnus-message 8 "Saving %s..." gnus-current-startup-file
)
2740 (gnus-gnus-to-newsrc-format)
2741 (gnus-message 8 "Saving %s...done" gnus-current-startup-file
))
2743 ;; Save .newsrc.eld.
2744 (set-buffer (gnus-get-buffer-create " *Gnus-newsrc*"))
2745 (make-local-variable 'version-control
)
2746 (setq version-control gnus-backup-startup-file
)
2747 (setq buffer-file-name
2748 (concat gnus-current-startup-file
".eld"))
2749 (setq default-directory
(file-name-directory buffer-file-name
))
2750 (buffer-disable-undo)
2752 (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file
)
2754 (if gnus-save-startup-file-via-temp-buffer
2755 (let ((coding-system-for-write gnus-ding-file-coding-system
)
2756 (standard-output (current-buffer)))
2757 (gnus-gnus-to-quick-newsrc-format)
2758 (gnus-run-hooks 'gnus-save-quick-newsrc-hook
)
2760 (let ((coding-system-for-write gnus-ding-file-coding-system
)
2761 (version-control gnus-backup-startup-file
)
2762 (startup-file (concat gnus-current-startup-file
".eld"))
2763 (working-dir (file-name-directory gnus-current-startup-file
))
2766 ;; Generate the name of a non-existent file.
2767 (while (progn (setq working-file
2769 (if (and (eq system-type
'ms-dos
)
2770 (not (gnus-long-file-names)))
2771 "%s#%d.tm#" ; MSDOS limits files to 8+3
2772 (if (memq system-type
'(vax-vms axp-vms
))
2775 working-dir
(setq i
(1+ i
))))
2776 (file-exists-p working-file
)))
2780 (gnus-with-output-to-file working-file
2781 (gnus-gnus-to-quick-newsrc-format)
2782 (gnus-run-hooks 'gnus-save-quick-newsrc-hook
))
2784 ;; These bindings will mislead the current buffer
2785 ;; into thinking that it is visiting the startup
2787 (let ((buffer-backed-up nil
)
2788 (buffer-file-name startup-file
)
2789 (file-precious-flag t
)
2790 (setmodes (file-modes startup-file
)))
2791 ;; Backup the current version of the startup file.
2794 ;; Replace the existing startup file with the temp file.
2795 (rename-file working-file startup-file t
)
2796 (set-file-modes startup-file setmodes
)))
2798 (delete-file working-file
)
2799 (file-error nil
)))))
2801 (gnus-kill-buffer (current-buffer))
2803 5 "Saving %s.eld...done" gnus-current-startup-file
))
2804 (gnus-dribble-delete-file)
2805 (gnus-group-set-mode-line)))))
2807 (defun gnus-gnus-to-quick-newsrc-format (&optional minimal name
&rest specific-variables
)
2808 "Print Gnus variables such as `gnus-newsrc-alist' in Lisp format."
2809 (princ ";; -*- emacs-lisp -*-\n")
2811 (princ (format ";; %s\n" name
))
2812 (princ ";; Gnus startup file.\n"))
2816 ;; Never delete this file -- if you want to force Gnus to read the
2817 ;; .newsrc file (if you have one), touch .newsrc instead.\n")
2818 (princ "(setq gnus-newsrc-file-version ")
2819 (princ (gnus-prin1-to-string gnus-version
))
2822 (let* ((print-quoted t
)
2824 (print-escape-multibyte nil
)
2825 (print-escape-nonascii t
)
2829 (print-escape-newlines t
)
2831 (if (and gnus-save-killed-list
2832 (stringp gnus-save-killed-list
))
2833 (gnus-strip-killed-list)
2836 (or specific-variables
2837 (if gnus-save-killed-list gnus-variable-list
2838 ;; Remove the `gnus-killed-list' from the list of variables
2839 ;; to be saved, if required.
2840 (delq 'gnus-killed-list
(copy-sequence gnus-variable-list
)))))
2841 ;; Peel off the "dummy" group.
2842 (gnus-newsrc-alist (cdr gnus-newsrc-alist
))
2844 ;; Insert the variables into the file.
2846 (when (and (boundp (setq variable
(pop variables
)))
2847 (symbol-value variable
))
2849 (princ (symbol-name variable
))
2851 (prin1 (symbol-value variable
))
2854 (defun gnus-strip-killed-list ()
2855 "Return the killed list minus the groups that match `gnus-save-killed-list'."
2856 (let ((list gnus-killed-list
)
2859 (when (string-match gnus-save-killed-list
(car list
))
2860 (push (car list
) olist
))
2864 (defun gnus-gnus-to-newsrc-format ()
2865 ;; Generate and save the .newsrc file.
2867 (set-buffer (create-file-buffer gnus-current-startup-file
))
2868 (let ((newsrc (cdr gnus-newsrc-alist
))
2869 (standard-output (current-buffer))
2870 info ranges range method
)
2871 (setq buffer-file-name gnus-current-startup-file
)
2872 (setq default-directory
(file-name-directory buffer-file-name
))
2873 (buffer-disable-undo)
2876 (when gnus-newsrc-options
2877 (insert gnus-newsrc-options
))
2878 ;; Write subscribed and unsubscribed.
2879 (while (setq info
(pop newsrc
))
2880 ;; Don't write foreign groups to .newsrc.
2881 (when (or (null (setq method
(gnus-info-method info
)))
2882 (equal method
"native")
2883 (inline (gnus-server-equal method gnus-select-method
)))
2884 (insert (gnus-info-group info
)
2885 (if (> (gnus-info-level info
) gnus-level-subscribed
)
2887 (when (setq ranges
(gnus-info-read info
))
2889 (if (not (listp (cdr ranges
)))
2890 (if (= (car ranges
) (cdr ranges
))
2891 (princ (car ranges
))
2892 (princ (car ranges
))
2894 (princ (cdr ranges
)))
2895 (while (setq range
(pop ranges
))
2896 (if (or (atom range
) (= (car range
) (cdr range
)))
2897 (princ (or (and (atom range
) range
) (car range
)))
2900 (princ (cdr range
)))
2904 (make-local-variable 'version-control
)
2905 (setq version-control
'never
)
2906 ;; It has been reported that sometime the modtime on the .newsrc
2907 ;; file seems to be off. We really do want to overwrite it, so
2908 ;; we clear the modtime here before saving. It's a bit odd,
2910 ;; sometimes the modtime clear isn't sufficient. most brute force:
2911 ;; delete the silly thing entirely first. but this fails to provide
2912 ;; such niceties as .newsrc~ creation.
2913 (if gnus-modtime-botch
2914 (delete-file gnus-startup-file
)
2915 (clear-visited-file-modtime))
2916 (gnus-run-hooks 'gnus-save-standard-newsrc-hook
)
2918 (kill-buffer (current-buffer)))))
2922 ;;; Slave functions.
2925 (defvar gnus-slave-mode nil
)
2927 (defun gnus-slave-mode ()
2928 "Minor mode for slave Gnusae."
2929 (gnus-add-minor-mode 'gnus-slave-mode
" Slave" (make-sparse-keymap))
2930 (gnus-run-hooks 'gnus-slave-mode-hook
))
2932 (defun gnus-slave-save-newsrc ()
2934 (set-buffer gnus-dribble-buffer
)
2936 (mm-make-temp-file (concat gnus-current-startup-file
"-slave-")))
2937 (modes (ignore-errors
2938 (file-modes (concat gnus-current-startup-file
".eld")))))
2939 (let ((coding-system-for-write gnus-ding-file-coding-system
))
2940 (gnus-write-buffer slave-name
))
2942 (set-file-modes slave-name modes
)))))
2944 (defun gnus-master-read-slave-newsrc ()
2947 (file-name-directory gnus-current-startup-file
)
2951 (file-name-nondirectory gnus-current-startup-file
)
2955 (if (not slave-files
)
2956 () ; There are no slave files to read.
2957 (gnus-message 7 "Reading slave newsrcs...")
2959 (set-buffer (gnus-get-buffer-create " *gnus slave*"))
2961 (sort (mapcar (lambda (file)
2962 (list (nth 5 (file-attributes file
)) file
))
2965 (or (< (caar f1
) (caar f2
))
2966 (< (nth 1 (car f1
)) (nth 1 (car f2
)))))))
2969 (setq file
(nth 1 (car slave-files
)))
2970 (nnheader-insert-file-contents file
)
2971 (when (condition-case ()
2973 (eval-buffer (current-buffer))
2976 (gnus-error 3.2 "Possible error in %s" file
)
2978 (unless gnus-slave
; Slaves shouldn't delete these files.
2980 (delete-file file
))))
2981 (setq slave-files
(cdr slave-files
))))
2982 (gnus-dribble-touch)
2983 (gnus-message 7 "Reading slave newsrcs...done"))))
2987 ;;; Group description.
2990 (defun gnus-read-all-descriptions-files ()
2991 (let ((methods (cons gnus-select-method
2993 (when (gnus-archive-server-wanted-p)
2995 gnus-secondary-select-methods
))))
2997 (gnus-read-descriptions-file (car methods
))
2998 (setq methods
(cdr methods
)))
3001 (defun gnus-read-descriptions-file (&optional method
)
3002 (let ((method (or method gnus-select-method
))
3004 (when (stringp method
)
3005 (setq method
(gnus-server-to-method method
)))
3006 ;; We create the hashtable whether we manage to read the desc file
3007 ;; to avoid trying to re-read after a failed read.
3008 (unless gnus-description-hashtb
3009 (setq gnus-description-hashtb
3010 (gnus-make-hashtable (length gnus-active-hashtb
))))
3011 ;; Mark this method's desc file as read.
3012 (gnus-sethash (gnus-group-prefixed-name "" method
) "Has read"
3013 gnus-description-hashtb
)
3015 (gnus-message 5 "Reading descriptions file via %s..." (car method
))
3017 ((null (gnus-get-function method
'request-list-newsgroups t
))
3019 ((not (gnus-check-server method
))
3020 (gnus-message 1 "Couldn't open server")
3022 ((not (gnus-request-list-newsgroups method
))
3023 (gnus-message 1 "Couldn't read newsgroups descriptions")
3028 (set-buffer nntp-server-buffer
)
3029 (goto-char (point-min))
3030 (when (or (search-forward "\n.\n" nil t
)
3031 (goto-char (point-max)))
3033 (narrow-to-region (point-min) (point)))
3034 ;; If these are groups from a foreign select method, we insert the
3035 ;; group prefix in front of the group names.
3036 (and method
(not (inline
3038 (gnus-server-get-method nil method
)
3039 (gnus-server-get-method
3040 nil gnus-select-method
))))
3041 (let ((prefix (gnus-group-prefixed-name "" method
)))
3042 (goto-char (point-min))
3043 (while (and (not (eobp))
3044 (progn (insert prefix
)
3045 (zerop (forward-line 1)))))))
3046 (goto-char (point-min))
3048 ;; If we get an error, we set group to 0, which is not a
3052 (let ((obarray gnus-description-hashtb
))
3053 ;; Group is set to a symbol interned in this
3055 (read nntp-server-buffer
))
3057 (skip-chars-forward " \t")
3058 ;; ... which leads to this line being effectively ignored.
3059 (when (symbolp group
)
3060 (let* ((str (buffer-substring
3061 (point) (progn (end-of-line) (point))))
3062 (name (symbol-name group
))
3064 (or (gnus-group-name-charset method name
)
3065 (gnus-parameter-charset name
)
3066 gnus-default-charset
)))
3067 ;; Fixme: Don't decode in unibyte mode.
3068 (when (and str charset
(featurep 'mule
))
3069 (setq str
(mm-decode-coding-string str charset
)))
3072 (gnus-message 5 "Reading descriptions file...done")
3075 (defun gnus-group-get-description (group)
3076 "Get the description of a group by sending XGTITLE to the server."
3077 (when (gnus-request-group-description group
)
3079 (set-buffer nntp-server-buffer
)
3080 (goto-char (point-min))
3081 (when (looking-at "[^ \t]+[ \t]+\\(.*\\)")
3082 (match-string 1)))))
3085 (defun gnus-declare-backend (name &rest abilities
)
3086 "Declare back end NAME with ABILITIES as a Gnus back end."
3087 (setq gnus-valid-select-methods
3088 (nconc gnus-valid-select-methods
3089 (list (apply 'list name abilities
))))
3090 (gnus-redefine-select-method-widget))
3092 (defun gnus-set-default-directory ()
3093 "Set the default directory in the current buffer to `gnus-default-directory'.
3094 If this variable is nil, don't do anything."
3095 (setq default-directory
3096 (if (and gnus-default-directory
3097 (file-exists-p gnus-default-directory
))
3098 (file-name-as-directory (expand-file-name gnus-default-directory
))
3099 default-directory
)))
3101 (defun gnus-display-time-event-handler ()
3102 (if (and (fboundp 'display-time-event-handler
)
3103 (gnus-boundp 'display-time-timer
))
3104 (display-time-event-handler)))
3107 (defun gnus-fixup-nnimap-unread-after-getting-new-news ()
3108 (let (server group info
)
3111 (when (and (setq group
(symbol-name sym
))
3112 (gnus-group-entry group
)
3113 (setq info
(symbol-value sym
)))
3114 (gnus-sethash group
(cons (nth 2 info
) (cdr (gnus-group-entry group
)))
3115 gnus-newsrc-hashtb
)))
3116 (if (boundp 'nnimap-mailbox-info
)
3117 (symbol-value 'nnimap-mailbox-info
)
3118 (make-vector 1 0)))))
3121 (provide 'gnus-start
)
3123 ;; arch-tag: f4584a22-b7b7-4853-abfc-a637329af5d2
3124 ;;; gnus-start.el ends here