]> code.delx.au - gnu-emacs/blob - lisp/gnus/gnus-start.el
; Auto-commit of loaddefs files.
[gnu-emacs] / lisp / gnus / gnus-start.el
1 ;;; gnus-start.el --- startup functions for Gnus
2
3 ;; Copyright (C) 1996-2016 Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22
23 ;;; Commentary:
24
25 ;;; Code:
26
27 (require 'gnus)
28 (require 'gnus-win)
29 (require 'gnus-int)
30 (require 'gnus-spec)
31 (require 'gnus-range)
32 (require 'gnus-util)
33 (require 'gnus-cloud)
34 (autoload 'message-make-date "message")
35 (autoload 'gnus-agent-read-servers-validate "gnus-agent")
36 (autoload 'gnus-agent-save-local "gnus-agent")
37 (autoload 'gnus-agent-possibly-alter-active "gnus-agent")
38
39 (eval-when-compile
40 (require 'cl))
41
42 (defvar gnus-agent-covered-methods)
43 (defvar gnus-agent-file-loading-local)
44 (defvar gnus-agent-file-loading-cache)
45
46 (defcustom gnus-startup-file (nnheader-concat gnus-home-directory ".newsrc")
47 "Your `.newsrc' file.
48 `.newsrc-SERVER' will be used instead if that exists."
49 :group 'gnus-start
50 :type 'file)
51
52 (defcustom gnus-backup-startup-file 'never
53 "Control use of version numbers for backups of `gnus-startup-file'.
54 This variable takes the same values as the `version-control'
55 variable."
56 :version "22.1"
57 :group 'gnus-start
58 :type '(choice (const :tag "Never" never)
59 (const :tag "If existing" nil)
60 (other :tag "Always" t)))
61
62 (defcustom gnus-save-startup-file-via-temp-buffer t
63 "Whether to write the startup file contents to a buffer then save
64 the buffer or write directly to the file. The buffer is faster
65 because all of the contents are written at once. The direct write
66 uses considerably less memory."
67 :version "22.1"
68 :group 'gnus-start
69 :type '(choice (const :tag "Write via buffer" t)
70 (const :tag "Write directly to file" nil)))
71
72 (defcustom gnus-init-file (nnheader-concat gnus-home-directory ".gnus")
73 "Your Gnus Emacs-Lisp startup file name.
74 If a file with the `.el' or `.elc' suffixes exists, it will be read instead."
75 :group 'gnus-start
76 :type 'file)
77
78 (defcustom gnus-site-init-file
79 (condition-case nil
80 (concat (file-name-directory
81 (directory-file-name installation-directory))
82 "site-lisp/gnus-init")
83 (error nil))
84 "The site-wide Gnus Emacs-Lisp startup file name, or nil if none.
85 If a file with the `.el' or `.elc' suffixes exists, it will be read instead."
86 :group 'gnus-start
87 :type '(choice file (const nil)))
88
89 (defcustom gnus-use-dribble-file t
90 "*Non-nil means that Gnus will use a dribble file to store user updates.
91 If Emacs should crash without saving the .newsrc files, complete
92 information can be restored from the dribble file."
93 :group 'gnus-dribble-file
94 :type 'boolean)
95
96 (defcustom gnus-dribble-directory nil
97 "*The directory where dribble files will be saved.
98 If this variable is nil, the directory where the .newsrc files are
99 saved will be used."
100 :group 'gnus-dribble-file
101 :type '(choice directory (const nil)))
102
103 (defcustom gnus-check-new-newsgroups 'ask-server
104 "*Non-nil means that Gnus will run `gnus-find-new-newsgroups' at startup.
105 This normally finds new newsgroups by comparing the active groups the
106 servers have already reported with those Gnus already knows, either alive
107 or killed.
108
109 When any of the following are true, `gnus-find-new-newsgroups' will instead
110 ask the servers (primary, secondary, and archive servers) to list new
111 groups since the last time it checked:
112 1. This variable is `ask-server'.
113 2. This variable is a list of select methods (see below).
114 3. Option `gnus-read-active-file' is nil or `some'.
115 4. A prefix argument is given to `gnus-find-new-newsgroups' interactively.
116
117 Thus, if this variable is `ask-server' or a list of select methods or
118 `gnus-read-active-file' is nil or `some', then the killed list is no
119 longer necessary, so you could safely set `gnus-save-killed-list' to nil.
120
121 This variable can be a list of select methods which Gnus will query with
122 the `ask-server' method in addition to the primary, secondary, and archive
123 servers.
124
125 E.g.:
126 (setq gnus-check-new-newsgroups
127 \\='((nntp \"some.server\") (nntp \"other.server\")))
128
129 If this variable is nil, then you have to tell Gnus explicitly to
130 check for new newsgroups with \\<gnus-group-mode-map>\\[gnus-find-new-newsgroups]."
131 :group 'gnus-start
132 :type '(choice (const :tag "no" nil)
133 (const :tag "by brute force" t)
134 (const :tag "ask servers" ask-server)
135 (repeat :menu-tag "ask additional servers"
136 :tag "ask additional servers"
137 :value ((nntp ""))
138 (sexp :format "%v"))))
139
140 (defcustom gnus-check-bogus-newsgroups nil
141 "*Non-nil means that Gnus will check and remove bogus newsgroup at startup.
142 If this variable is nil, then you have to tell Gnus explicitly to
143 check for bogus newsgroups with \\<gnus-group-mode-map>\\[gnus-group-check-bogus-groups]."
144 :group 'gnus-start-server
145 :type 'boolean)
146
147 (defcustom gnus-read-active-file 'some
148 "*Non-nil means that Gnus will read the entire active file at startup.
149 If this variable is nil, Gnus will only know about the groups in your
150 `.newsrc' file.
151
152 If this variable is `some', Gnus will try to only read the relevant
153 parts of the active file from the server. Not all servers support
154 this, and it might be quite slow with other servers, but this should
155 generally be faster than both the t and nil value.
156
157 If you set this variable to nil or `some', you probably still want to
158 be told about new newsgroups that arrive. To do that, set
159 `gnus-check-new-newsgroups' to `ask-server'. This may not work
160 properly with all servers."
161 :group 'gnus-start-server
162 :type '(choice (const nil)
163 (const some)
164 (const t)))
165
166 (defconst gnus-level-subscribed 5
167 "Groups with levels less than or equal to this variable are subscribed.")
168
169 (defconst gnus-level-unsubscribed 7
170 "Groups with levels less than or equal to this variable are unsubscribed.
171
172 Groups with levels less than `gnus-level-subscribed', which
173 should be less than this variable, are subscribed. Groups with
174 levels from `gnus-level-subscribed' (exclusive) upto this
175 variable (inclusive) are unsubscribed. See also
176 `gnus-level-zombie', `gnus-level-killed' and the Info node `(gnus)Group
177 Levels' for details.")
178
179 (defconst gnus-level-zombie 8
180 "Groups with this level are zombie groups.")
181
182 (defconst gnus-level-killed 9
183 "Groups with this level are killed.")
184
185 (defcustom gnus-level-default-subscribed 3
186 "*New subscribed groups will be subscribed at this level."
187 :group 'gnus-group-levels
188 :type 'integer)
189
190 (defcustom gnus-level-default-unsubscribed 6
191 "*New unsubscribed groups will be unsubscribed at this level."
192 :group 'gnus-group-levels
193 :type 'integer)
194
195 (defcustom gnus-activate-level (1+ gnus-level-subscribed)
196 "*Groups higher than this level won't be activated on startup.
197 Setting this variable to something low might save lots of time when
198 you have many groups that you aren't interested in."
199 :group 'gnus-group-levels
200 :type 'integer)
201
202 (defcustom gnus-activate-foreign-newsgroups 4
203 "*If nil, Gnus will not check foreign newsgroups at startup.
204 If it is non-nil, it should be a number between one and nine. Foreign
205 newsgroups that have a level lower or equal to this number will be
206 activated on startup. For instance, if you want to active all
207 subscribed newsgroups, but not the rest, you'd set this variable to
208 `gnus-level-subscribed'.
209
210 If you subscribe to lots of newsgroups from different servers, startup
211 might take a while. By setting this variable to nil, you'll save time,
212 but you won't be told how many unread articles there are in the
213 groups."
214 :group 'gnus-group-levels
215 :type '(choice integer
216 (const :tag "none" nil)))
217
218 (defcustom gnus-read-newsrc-file t
219 "*Non-nil means that Gnus will read the `.newsrc' file.
220 Gnus always reads its own startup file, which is called
221 \".newsrc.eld\". The file called \".newsrc\" is in a format that can
222 be readily understood by other newsreaders. If you don't plan on
223 using other newsreaders, set this variable to nil to save some time on
224 entry."
225 :version "21.1"
226 :group 'gnus-newsrc
227 :type 'boolean)
228
229 (defcustom gnus-save-newsrc-file t
230 "*Non-nil means that Gnus will save the `.newsrc' file.
231 Gnus always saves its own startup file, which is called
232 \".newsrc.eld\". The file called \".newsrc\" is in a format that can
233 be readily understood by other newsreaders. If you don't plan on
234 using other newsreaders, set this variable to nil to save some time on
235 exit."
236 :group 'gnus-newsrc
237 :type 'boolean)
238
239 (defcustom gnus-save-killed-list t
240 "*If non-nil, save the list of killed groups to the startup file.
241 If you set this variable to nil, you'll save both time (when starting
242 and quitting) and space (both memory and disk), but it will also mean
243 that Gnus has no record of which groups are new and which are old, so
244 the automatic new newsgroups subscription methods become meaningless.
245
246 You should always set `gnus-check-new-newsgroups' to `ask-server' or
247 nil if you set this variable to nil.
248
249 This variable can also be a regexp. In that case, all groups that do
250 not match this regexp will be removed before saving the list."
251 :group 'gnus-newsrc
252 :type '(radio (sexp :format "Non-nil\n"
253 :match (lambda (widget value)
254 (and value (not (stringp value))))
255 :value t)
256 (const nil)
257 regexp))
258
259 (defcustom gnus-ignored-newsgroups
260 (mapconcat 'identity
261 '("^to\\." ; not "real" groups
262 "^[0-9. \t]+\\( \\|$\\)" ; all digits in name
263 "^[\"][\"#'()]" ; bogus characters
264 )
265 "\\|")
266 "*A regexp to match uninteresting newsgroups in the active file.
267 Any lines in the active file matching this regular expression are
268 removed from the newsgroup list before anything else is done to it,
269 thus making them effectively non-existent."
270 :group 'gnus-group-new
271 :type 'regexp)
272
273 (defcustom gnus-subscribe-newsgroup-method 'gnus-subscribe-zombies
274 "*Function(s) called with a group name when new group is detected.
275 A few pre-made functions are supplied: `gnus-subscribe-randomly'
276 inserts new groups at the beginning of the list of groups;
277 `gnus-subscribe-alphabetically' inserts new groups in strict
278 alphabetic order; `gnus-subscribe-hierarchically' inserts new groups
279 in hierarchical newsgroup order; `gnus-subscribe-interactively' asks
280 for your decision; `gnus-subscribe-killed' kills all new groups;
281 `gnus-subscribe-zombies' will make all new groups into zombies;
282 `gnus-subscribe-topics' will enter groups into the topics that
283 claim them."
284 :group 'gnus-group-new
285 :type '(radio (function-item gnus-subscribe-randomly)
286 (function-item gnus-subscribe-alphabetically)
287 (function-item gnus-subscribe-hierarchically)
288 (function-item gnus-subscribe-interactively)
289 (function-item gnus-subscribe-killed)
290 (function-item gnus-subscribe-zombies)
291 (function-item gnus-subscribe-topics)
292 function
293 (repeat function)))
294
295 (define-obsolete-variable-alias 'gnus-subscribe-newsgroup-hooks
296 'gnus-subscribe-newsgroup-functions "24.3")
297 (defcustom gnus-subscribe-newsgroup-functions nil
298 "*Hooks run after you subscribe to a new group.
299 The hooks will be called with new group's name as argument."
300 :version "22.1"
301 :group 'gnus-group-new
302 :type 'hook)
303
304 (defcustom gnus-subscribe-options-newsgroup-method
305 'gnus-subscribe-alphabetically
306 "*Function(s) called to subscribe newsgroups mentioned on \"options -n\" lines.
307 If, for instance, you want to subscribe to all newsgroups in the
308 \"no\" and \"alt\" hierarchies, you'd put the following in your
309 .newsrc file:
310
311 options -n no.all alt.all
312
313 Gnus will then subscribe all new newsgroups in these hierarchies
314 with the subscription method in this variable."
315 :group 'gnus-group-new
316 :type '(radio (function-item gnus-subscribe-randomly)
317 (function-item gnus-subscribe-alphabetically)
318 (function-item gnus-subscribe-hierarchically)
319 (function-item gnus-subscribe-interactively)
320 (function-item gnus-subscribe-killed)
321 (function-item gnus-subscribe-zombies)
322 (function-item gnus-subscribe-topics)
323 function
324 (repeat function)))
325
326 (defcustom gnus-subscribe-hierarchical-interactive nil
327 "*If non-nil, Gnus will offer to subscribe hierarchically.
328 When a new hierarchy appears, Gnus will ask the user:
329
330 'alt.binaries': Do you want to subscribe to this hierarchy? ([d]ys):
331
332 If the user pressed `d', Gnus will descend the hierarchy, `y' will
333 subscribe to all newsgroups in the hierarchy and `s' will skip this
334 hierarchy in its entirety."
335 :group 'gnus-group-new
336 :type 'boolean)
337
338 (defcustom gnus-auto-subscribed-categories '(mail post-mail)
339 "*New groups from methods of these categories will be subscribed automatically.
340 Note that this variable only deals with new groups. It has no
341 effect whatsoever on old groups. The default is to automatically
342 subscribe all groups from mail-like backends."
343 :version "24.1"
344 :group 'gnus-group-new
345 :type '(repeat symbol))
346
347 (defcustom gnus-auto-subscribed-groups
348 "^nnml\\|^nnfolder\\|^nnmbox\\|^nnmh\\|^nnbabyl\\|^nnmaildir\\|^nnimap"
349 "*All new groups that match this regexp will be subscribed automatically.
350 Note that this variable only deals with new groups. It has no effect
351 whatsoever on old groups.
352
353 New groups that match this regexp will not be handled by
354 `gnus-subscribe-newsgroup-method'. Instead, they will
355 be subscribed using `gnus-subscribe-options-newsgroup-method'."
356 :group 'gnus-group-new
357 :type 'regexp)
358
359 (defcustom gnus-options-subscribe nil
360 "*All new groups matching this regexp will be subscribed unconditionally.
361 Note that this variable deals only with new newsgroups. This variable
362 does not affect old newsgroups.
363
364 New groups that match this regexp will not be handled by
365 `gnus-subscribe-newsgroup-method'. Instead, they will
366 be subscribed using `gnus-subscribe-options-newsgroup-method'."
367 :group 'gnus-group-new
368 :type '(choice regexp
369 (const :tag "none" nil)))
370
371 (defcustom gnus-options-not-subscribe nil
372 "*All new groups matching this regexp will be ignored.
373 Note that this variable deals only with new newsgroups. This variable
374 does not affect old (already subscribed) newsgroups."
375 :group 'gnus-group-new
376 :type '(choice regexp
377 (const :tag "none" nil)))
378
379 (defcustom gnus-modtime-botch nil
380 "*Non-nil means .newsrc should be deleted prior to save.
381 Its use is due to the bogus appearance that .newsrc was modified on
382 disc."
383 :group 'gnus-newsrc
384 :type 'boolean)
385
386 (defcustom gnus-check-bogus-groups-hook nil
387 "A hook run after removing bogus groups."
388 :group 'gnus-start-server
389 :type 'hook)
390
391 (defcustom gnus-startup-hook nil
392 "A hook called at startup.
393 This hook is called after Gnus is connected to the NNTP server."
394 :group 'gnus-start
395 :type 'hook)
396
397 (defcustom gnus-before-startup-hook nil
398 "A hook called before startup.
399 This hook is called as the first thing when Gnus is started.
400 See also `gnus-before-resume-hook'."
401 :group 'gnus-start
402 :type 'hook)
403
404 (defcustom gnus-before-resume-hook nil
405 "A hook called before resuming Gnus after suspend.
406 This hook is called as the first thing when Gnus is resumed after a suspend.
407 See also `gnus-before-startup-hook'."
408 :version "24.4"
409 :group 'gnus-start
410 :type 'hook)
411
412 (defcustom gnus-started-hook nil
413 "A hook called as the last thing after startup."
414 :group 'gnus-start
415 :type 'hook)
416
417 (defcustom gnus-setup-news-hook nil
418 "A hook after reading the .newsrc file, but before generating the buffer."
419 :group 'gnus-start
420 :type 'hook)
421
422 (defcustom gnus-get-top-new-news-hook nil
423 "A hook run just before Gnus checks for new news globally."
424 :version "22.1"
425 :group 'gnus-group-new
426 :type 'hook)
427
428 (defcustom gnus-get-new-news-hook nil
429 "A hook run just before Gnus checks for new news."
430 :group 'gnus-group-new
431 :type 'hook)
432
433 (defcustom gnus-after-getting-new-news-hook
434 '(gnus-display-time-event-handler)
435 "*A hook run after Gnus checks for new news when Gnus is already running."
436 :version "24.1"
437 :group 'gnus-group-new
438 :type 'hook)
439
440 (defcustom gnus-read-newsrc-el-hook nil
441 "A hook called after reading the newsrc.eld? file."
442 :group 'gnus-newsrc
443 :type 'hook)
444
445 (defcustom gnus-save-newsrc-hook nil
446 "A hook called before saving any of the newsrc files."
447 :group 'gnus-newsrc
448 :type 'hook)
449
450 (defcustom gnus-save-quick-newsrc-hook nil
451 "A hook called just before saving the quick newsrc file.
452 Can be used to turn version control on or off."
453 :group 'gnus-newsrc
454 :type 'hook)
455
456 (defcustom gnus-save-standard-newsrc-hook nil
457 "A hook called just before saving the standard newsrc file.
458 Can be used to turn version control on or off."
459 :group 'gnus-newsrc
460 :type 'hook)
461
462 (defcustom gnus-group-mode-hook nil
463 "Hook for Gnus group mode."
464 :group 'gnus-group-various
465 :options '(gnus-topic-mode)
466 :type 'hook)
467
468 (defcustom gnus-always-read-dribble-file nil
469 "Unconditionally read the dribble file."
470 :group 'gnus-newsrc
471 :type 'boolean)
472
473 ;;; Internal variables
474
475 ;; Fixme: deal with old emacs-mule when mm-universal-coding-system is
476 ;; utf-8-emacs.
477 (defvar gnus-ding-file-coding-system mm-universal-coding-system
478 "Coding system for ding file.")
479
480 (defvar gnus-newsrc-file-version nil)
481 (defvar gnus-override-subscribe-method nil)
482 (defvar gnus-dribble-buffer nil)
483 (defvar gnus-newsrc-options nil
484 "Options line in the .newsrc file.")
485
486 (defvar gnus-newsrc-options-n nil
487 "List of regexps representing groups to be subscribed/ignored unconditionally.")
488
489 (defvar gnus-newsrc-last-checked-date nil
490 "Date Gnus last asked server for new newsgroups.")
491
492 (defvar gnus-current-startup-file nil
493 "Startup file for the current host.")
494
495 ;; Byte-compiler warning.
496 (defvar gnus-group-line-format)
497
498 ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
499 (defvar gnus-init-inhibit nil)
500 (defun gnus-read-init-file (&optional inhibit-next)
501 ;; Don't load .gnus if the -q option was used.
502 (when init-file-user
503 (if gnus-init-inhibit
504 (setq gnus-init-inhibit nil)
505 (setq gnus-init-inhibit inhibit-next)
506 (dolist (file (list gnus-site-init-file gnus-init-file))
507 (when (and file
508 (locate-library file))
509 (if (or debug-on-error debug-on-quit)
510 (load file nil t)
511 (condition-case var
512 (load file nil t)
513 (error
514 (error "Error in %s: %s" file (cadr var))))))))))
515
516 ;; For subscribing new newsgroup
517
518 (defun gnus-subscribe-hierarchical-interactive (groups)
519 (let ((groups (sort groups 'string<))
520 prefixes prefix start ans group starts real-group)
521 (while groups
522 (setq prefixes (list "^"))
523 (while (and groups prefixes)
524 (while (not (string-match (car prefixes)
525 (gnus-group-real-name (car groups))))
526 (setq prefixes (cdr prefixes)))
527 (setq prefix (car prefixes))
528 (setq start (1- (length prefix)))
529 (if (and (string-match "[^\\.]\\." (gnus-group-real-name (car groups))
530 start)
531 (cdr groups)
532 (setq prefix
533 (concat "^" (substring
534 (gnus-group-real-name (car groups))
535 0 (match-end 0))))
536 (string-match prefix (gnus-group-real-name (cadr groups))))
537 (progn
538 (push prefix prefixes)
539 (message "Descend hierarchy %s? ([y]nsq): "
540 (substring prefix 1 (1- (length prefix))))
541 (while (not (memq (setq ans (read-char-exclusive))
542 '(?y ?\n ?\r ?n ?s ?q)))
543 (ding)
544 (message "Descend hierarchy %s? ([y]nsq): "
545 (substring prefix 1 (1- (length prefix)))))
546 (cond ((= ans ?n)
547 (while (and groups
548 (setq group (car groups)
549 real-group (gnus-group-real-name group))
550 (string-match prefix real-group))
551 (push group gnus-killed-list)
552 (gnus-sethash group group gnus-killed-hashtb)
553 (setq groups (cdr groups)))
554 (setq starts (cdr starts)))
555 ((= ans ?s)
556 (while (and groups
557 (setq group (car groups)
558 real-group (gnus-group-real-name group))
559 (string-match prefix real-group))
560 (gnus-sethash group group gnus-killed-hashtb)
561 (gnus-subscribe-alphabetically (car groups))
562 (setq groups (cdr groups)))
563 (setq starts (cdr starts)))
564 ((= ans ?q)
565 (while groups
566 (setq group (car groups))
567 (push group gnus-killed-list)
568 (gnus-sethash group group gnus-killed-hashtb)
569 (setq groups (cdr groups))))
570 (t nil)))
571 (message "Subscribe %s? ([n]yq)" (car groups))
572 (while (not (memq (setq ans (read-char-exclusive))
573 '(?y ?\n ?\r ?q ?n)))
574 (ding)
575 (message "Subscribe %s? ([n]yq)" (car groups)))
576 (setq group (car groups))
577 (cond ((= ans ?y)
578 (gnus-subscribe-alphabetically (car groups))
579 (gnus-sethash group group gnus-killed-hashtb))
580 ((= ans ?q)
581 (while groups
582 (setq group (car groups))
583 (push group gnus-killed-list)
584 (gnus-sethash group group gnus-killed-hashtb)
585 (setq groups (cdr groups))))
586 (t
587 (push group gnus-killed-list)
588 (gnus-sethash group group gnus-killed-hashtb)))
589 (setq groups (cdr groups)))))))
590
591 (defun gnus-subscribe-randomly (newsgroup)
592 "Subscribe new NEWSGROUP by making it the first newsgroup."
593 (gnus-subscribe-newsgroup newsgroup))
594
595 (defun gnus-subscribe-alphabetically (newgroup)
596 "Subscribe new NEWGROUP and insert it in alphabetical order."
597 (let ((groups (cdr gnus-newsrc-alist))
598 before)
599 (while (and (not before) groups)
600 (if (string< newgroup (caar groups))
601 (setq before (caar groups))
602 (setq groups (cdr groups))))
603 (gnus-subscribe-newsgroup newgroup before)))
604
605 (defun gnus-subscribe-hierarchically (newgroup)
606 "Subscribe new NEWGROUP and insert it in hierarchical newsgroup order."
607 ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
608 (with-current-buffer (nnheader-find-file-noselect gnus-current-startup-file)
609 (prog1
610 (let ((groupkey newgroup) before)
611 (while (and (not before) groupkey)
612 (goto-char (point-min))
613 (let ((groupkey-re
614 (concat "^\\(" (regexp-quote groupkey) ".*\\)[!:]")))
615 (while (and (re-search-forward groupkey-re nil t)
616 (progn
617 (setq before (match-string 1))
618 (string< before newgroup)))))
619 ;; Remove tail of newsgroup name (eg. a.b.c -> a.b)
620 (setq groupkey
621 (when (string-match "^\\(.*\\)\\.[^.]+$" groupkey)
622 (substring groupkey (match-beginning 1) (match-end 1)))))
623 (gnus-subscribe-newsgroup newgroup before))
624 (kill-buffer (current-buffer)))))
625
626 (defun gnus-subscribe-interactively (group)
627 "Subscribe the new GROUP interactively.
628 It is inserted in hierarchical newsgroup order if subscribed. If not,
629 it is killed."
630 (if (gnus-y-or-n-p (format "Subscribe new newsgroup %s? " group))
631 (gnus-subscribe-hierarchically group)
632 (push group gnus-killed-list)))
633
634 (defun gnus-subscribe-zombies (group)
635 "Make the new GROUP into a zombie group."
636 (push group gnus-zombie-list))
637
638 (defun gnus-subscribe-killed (group)
639 "Make the new GROUP a killed group."
640 (push group gnus-killed-list))
641
642 (defun gnus-subscribe-newsgroup (newsgroup &optional next)
643 "Subscribe new NEWSGROUP.
644 If NEXT is non-nil, it is inserted before NEXT. Otherwise it is made
645 the first newsgroup."
646 (save-excursion
647 (goto-char (point-min))
648 ;; We subscribe the group by changing its level to `subscribed'.
649 (gnus-group-change-level
650 newsgroup gnus-level-default-subscribed
651 gnus-level-killed (gnus-group-entry (or next "dummy.group")))
652 (gnus-request-update-group-status newsgroup 'subscribe)
653 (gnus-message 5 "Subscribe newsgroup: %s" newsgroup)
654 (run-hook-with-args 'gnus-subscribe-newsgroup-functions newsgroup)
655 t))
656
657 (defun gnus-read-active-file-p ()
658 "Say whether the active file has been read from `gnus-select-method'."
659 (memq gnus-select-method gnus-have-read-active-file))
660
661 ;;; General various misc type functions.
662
663 ;; Silence byte-compiler.
664 (defvar gnus-current-headers)
665 (defvar gnus-thread-indent-array)
666 (defvar gnus-newsgroup-name)
667 (defvar gnus-newsgroup-headers)
668 (defvar gnus-group-list-mode)
669 (defvar gnus-group-mark-positions)
670 (defvar gnus-newsgroup-data)
671 (defvar gnus-newsgroup-unreads)
672 (defvar nnoo-state-alist)
673 (defvar gnus-current-select-method)
674 (defvar mail-sources)
675 (defvar nnmail-scan-directory-mail-source-once)
676 (defvar nnmail-split-history)
677 (defvar nnmail-spool-file)
678
679 (defun gnus-close-all-servers ()
680 "Close all servers."
681 (interactive)
682 (dolist (server gnus-opened-servers)
683 (gnus-close-server (car server))))
684
685 (defun gnus-clear-system ()
686 "Clear all variables and buffers."
687 ;; Clear Gnus variables.
688 (let ((variables (remove 'gnus-format-specs gnus-variable-list)))
689 (while variables
690 (set (car variables) nil)
691 (setq variables (cdr variables))))
692 ;; Clear other internal variables.
693 (setq gnus-list-of-killed-groups nil
694 gnus-have-read-active-file nil
695 gnus-agent-covered-methods nil
696 gnus-agent-file-loading-local nil
697 gnus-agent-file-loading-cache nil
698 gnus-server-method-cache nil
699 gnus-newsrc-alist nil
700 gnus-newsrc-hashtb nil
701 gnus-killed-list nil
702 gnus-zombie-list nil
703 gnus-killed-hashtb nil
704 gnus-active-hashtb nil
705 gnus-moderated-hashtb nil
706 gnus-description-hashtb nil
707 gnus-current-headers nil
708 gnus-thread-indent-array nil
709 gnus-newsgroup-headers nil
710 gnus-newsgroup-name nil
711 gnus-server-alist nil
712 gnus-group-list-mode nil
713 gnus-opened-servers nil
714 gnus-group-mark-positions nil
715 gnus-newsgroup-data nil
716 gnus-newsgroup-unreads nil
717 nnoo-state-alist nil
718 gnus-current-select-method nil
719 nnmail-split-history nil
720 gnus-extended-servers nil
721 gnus-ephemeral-servers nil)
722 (gnus-shutdown 'gnus)
723 ;; Kill the startup file.
724 (and gnus-current-startup-file
725 (get-file-buffer gnus-current-startup-file)
726 (kill-buffer (get-file-buffer gnus-current-startup-file)))
727 ;; Clear the dribble buffer.
728 (gnus-dribble-clear)
729 ;; Kill global KILL file buffer.
730 (when (get-file-buffer (gnus-newsgroup-kill-file nil))
731 (kill-buffer (get-file-buffer (gnus-newsgroup-kill-file nil))))
732 (gnus-kill-buffer nntp-server-buffer)
733 ;; Kill Gnus buffers.
734 (dolist (buffer (gnus-buffers))
735 (gnus-kill-buffer buffer))
736 ;; Remove Gnus frames.
737 (gnus-kill-gnus-frames))
738
739 (defun gnus-no-server-1 (&optional arg slave)
740 "Read network news.
741 If ARG is a positive number, Gnus will use that as the startup
742 level. If ARG is nil, Gnus will be started at level 2
743 \(`gnus-level-default-subscribed' minus one). If ARG is non-nil
744 and not a positive number, Gnus will prompt the user for the name
745 of an NNTP server to use. As opposed to \\[gnus], this command
746 will not connect to the local server."
747 (interactive "P")
748 (let ((val (or arg (1- gnus-level-default-subscribed))))
749 (gnus val t slave)
750 (make-local-variable 'gnus-group-use-permanent-levels)
751 (setq gnus-group-use-permanent-levels val)))
752
753 (defun gnus-1 (&optional arg dont-connect slave)
754 "Read network news.
755 If ARG is non-nil and a positive number, Gnus will use that as the
756 startup level. If ARG is non-nil and not a positive number, Gnus will
757 prompt the user for the name of an NNTP server to use."
758 (interactive "P")
759
760 (if (gnus-alive-p)
761 (progn
762 (gnus-run-hooks 'gnus-before-resume-hook)
763 (switch-to-buffer gnus-group-buffer)
764 (gnus-group-get-new-news
765 (and (numberp arg)
766 (> arg 0)
767 (max (car gnus-group-list-mode) arg))))
768
769 (gnus-clear-system)
770 (gnus-splash)
771 (gnus-run-hooks 'gnus-before-startup-hook)
772 (nnheader-init-server-buffer)
773 (setq gnus-slave slave)
774 (gnus-read-init-file)
775
776 ;; Add "native" to gnus-predefined-server-alist just to have a
777 ;; name for the native select method.
778 (when gnus-select-method
779 (add-to-list 'gnus-predefined-server-alist
780 (cons "native" gnus-select-method)))
781
782 (if gnus-agent
783 (gnus-agentize))
784
785 (let ((level (and (numberp arg) (> arg 0) arg))
786 did-connect)
787 (unwind-protect
788 (progn
789 (unless dont-connect
790 (setq did-connect
791 (gnus-start-news-server (and arg (not level))))))
792 (if (and (not dont-connect)
793 (not did-connect))
794 ;; Couldn't connect to the server, so bail out.
795 (gnus-group-quit)
796 (gnus-run-hooks 'gnus-startup-hook)
797 ;; Find the current startup file name.
798 (setq gnus-current-startup-file
799 (gnus-make-newsrc-file gnus-startup-file))
800
801 ;; Read the dribble file.
802 (when (or gnus-slave gnus-use-dribble-file)
803 (gnus-dribble-read-file))
804
805 ;; Do the actual startup.
806 (gnus-setup-news nil level dont-connect)
807 (gnus-run-hooks 'gnus-setup-news-hook)
808 (when gnus-agent
809 (gnus-request-create-group "queue" '(nndraft "")))
810 (gnus-start-draft-setup)
811 ;; Generate the group buffer.
812 (gnus-group-list-groups level)
813 (gnus-group-first-unread-group)
814 (gnus-configure-windows 'group)
815 (gnus-group-set-mode-line)
816 (gnus-run-hooks 'gnus-started-hook))))))
817
818 (defun gnus-start-draft-setup ()
819 "Make sure the draft group exists."
820 (interactive)
821 (gnus-request-create-group "drafts" '(nndraft ""))
822 (unless (gnus-group-entry "nndraft:drafts")
823 (let ((gnus-level-default-subscribed 1))
824 (gnus-subscribe-group "nndraft:drafts" nil '(nndraft "")))
825 (setcar (gnus-group-entry "nndraft:drafts") 0))
826 (unless (equal (gnus-group-get-parameter "nndraft:drafts" 'gnus-dummy t)
827 '((gnus-draft-mode)))
828 (gnus-group-set-parameter
829 "nndraft:drafts" 'gnus-dummy '((gnus-draft-mode)))))
830
831 \f
832 ;;;
833 ;;; Dribble file
834 ;;;
835
836 (defvar gnus-dribble-ignore nil)
837 (defvar gnus-dribble-eval-file nil)
838
839 (defun gnus-dribble-file-name ()
840 "Return the dribble file for the current .newsrc."
841 (concat
842 (if gnus-dribble-directory
843 (concat (file-name-as-directory gnus-dribble-directory)
844 (file-name-nondirectory gnus-current-startup-file))
845 gnus-current-startup-file)
846 "-dribble"))
847
848 (defun gnus-dribble-enter (string &optional regexp)
849 "Enter STRING into the dribble buffer.
850 If REGEXP is given, lines that match it will be deleted."
851 (when (and (not gnus-dribble-ignore)
852 gnus-dribble-buffer
853 (buffer-name gnus-dribble-buffer))
854 (let ((obuf (current-buffer)))
855 (set-buffer gnus-dribble-buffer)
856 (when regexp
857 (goto-char (point-min))
858 (let (end)
859 (while (re-search-forward regexp nil t)
860 (unless (bolp) (forward-line 1))
861 (setq end (point))
862 (goto-char (match-beginning 0))
863 (delete-region (point-at-bol) end))))
864 (goto-char (point-max))
865 ;; Make sure that each dribble entry is a single line, so that
866 ;; the "remove" code above works.
867 (insert (replace-regexp-in-string "\n" "\\\\n" string) "\n")
868 ;; This has been commented by Josh Huber <huber@alum.wpi.edu>
869 ;; It causes problems with both XEmacs and Emacs 21, and doesn't
870 ;; seem to be of much value. (FIXME: remove this after we make sure
871 ;; it's not needed).
872 ;; (set-window-point (get-buffer-window (current-buffer)) (point-max))
873 (bury-buffer gnus-dribble-buffer)
874 (with-current-buffer gnus-group-buffer
875 (gnus-group-set-mode-line))
876 (set-buffer obuf))))
877
878 (defun gnus-dribble-touch ()
879 "Touch the dribble buffer."
880 (gnus-dribble-enter ""))
881
882 (defun gnus-dribble-read-file ()
883 "Read the dribble file from disk."
884 (let ((dribble-file (gnus-dribble-file-name)))
885 (unless (file-exists-p (file-name-directory dribble-file))
886 (make-directory (file-name-directory dribble-file) t))
887 (with-current-buffer (setq gnus-dribble-buffer
888 (gnus-get-buffer-create
889 (file-name-nondirectory dribble-file)))
890 (set (make-local-variable 'file-precious-flag) t)
891 (setq buffer-save-without-query t)
892 (erase-buffer)
893 (setq buffer-file-name dribble-file)
894 ;; The buffer may be shrunk a lot when deleting old entries.
895 ;; It caused the auto-saving to stop.
896 (if (featurep 'emacs)
897 (set (make-local-variable 'auto-save-include-big-deletions) t)
898 (set (make-local-variable 'disable-auto-save-when-buffer-shrinks) nil))
899 (auto-save-mode t)
900 (buffer-disable-undo)
901 (bury-buffer (current-buffer))
902 (set-buffer-modified-p nil)
903 (let ((auto (make-auto-save-file-name))
904 (gnus-dribble-ignore t)
905 (purpose nil)
906 modes)
907 (when (or (file-exists-p auto) (file-exists-p dribble-file))
908 ;; Load whichever file is newest -- the auto save file
909 ;; or the "real" file.
910 (if (file-newer-than-file-p auto dribble-file)
911 (nnheader-insert-file-contents auto)
912 (nnheader-insert-file-contents dribble-file))
913 (unless (zerop (buffer-size))
914 (set-buffer-modified-p t))
915 ;; Set the file modes to reflect the .newsrc file modes.
916 (save-buffer)
917 (when (and (file-exists-p gnus-current-startup-file)
918 (file-exists-p dribble-file)
919 (setq modes (file-modes gnus-current-startup-file)))
920 (gnus-set-file-modes dribble-file modes))
921 (goto-char (point-min))
922 (when (search-forward "Gnus was exited on purpose" nil t)
923 (setq purpose t))
924 ;; Possibly eval the file later.
925 (when (or gnus-always-read-dribble-file
926 (gnus-y-or-n-p
927 (if purpose
928 "Gnus exited on purpose without saving; read auto-save file anyway? "
929 "Gnus auto-save file exists. Do you want to read it? ")))
930 (setq gnus-dribble-eval-file t)))))))
931
932 (defun gnus-dribble-eval-file ()
933 (when gnus-dribble-eval-file
934 (setq gnus-dribble-eval-file nil)
935 (save-excursion
936 (let ((gnus-dribble-ignore t))
937 (set-buffer gnus-dribble-buffer)
938 (eval-buffer (current-buffer))))))
939
940 (defun gnus-dribble-delete-file ()
941 (when (file-exists-p (gnus-dribble-file-name))
942 (delete-file (gnus-dribble-file-name)))
943 (when gnus-dribble-buffer
944 (with-current-buffer gnus-dribble-buffer
945 (let ((auto (make-auto-save-file-name)))
946 (when (file-exists-p auto)
947 (delete-file auto))
948 (erase-buffer)
949 (set-buffer-modified-p nil)))))
950
951 (defun gnus-dribble-save ()
952 (when (and gnus-dribble-buffer
953 (buffer-name gnus-dribble-buffer))
954 (with-current-buffer gnus-dribble-buffer
955 (when (> (buffer-size) 0)
956 (save-buffer)))))
957
958 (defun gnus-dribble-clear ()
959 (when (gnus-buffer-exists-p gnus-dribble-buffer)
960 (with-current-buffer gnus-dribble-buffer
961 (erase-buffer)
962 (set-buffer-modified-p nil)
963 (setq buffer-saved-size (buffer-size)))))
964
965 \f
966 ;;;
967 ;;; Active & Newsrc File Handling
968 ;;;
969
970 (defun gnus-setup-news (&optional rawfile level dont-connect)
971 "Setup news information.
972 If RAWFILE is non-nil, the .newsrc file will also be read.
973 If LEVEL is non-nil, the news will be set up at level LEVEL."
974 (require 'nnmail)
975 (let ((init (not (and gnus-newsrc-alist gnus-active-hashtb (not rawfile))))
976 ;; Binding this variable will inhibit multiple fetchings
977 ;; of the same mail source.
978 (nnmail-fetched-sources (list t)))
979
980 (when init
981 ;; Clear some variables to re-initialize news information.
982 (setq gnus-newsrc-alist nil
983 gnus-active-hashtb nil)
984 ;; Read the newsrc file and create `gnus-newsrc-hashtb'.
985 (gnus-read-newsrc-file rawfile))
986
987 ;; Make sure the archive server is available to all and sundry.
988 (let ((method (or (and (stringp gnus-message-archive-method)
989 (gnus-server-to-method
990 gnus-message-archive-method))
991 gnus-message-archive-method)))
992 ;; Check whether the archive method is writable.
993 (unless (or (not method)
994 (stringp method)
995 (memq 'respool (assoc (format "%s" (car method))
996 gnus-valid-select-methods)))
997 (setq method "archive")) ;; The default.
998 (when (stringp method)
999 (setq method `(nnfolder
1000 ,method
1001 (nnfolder-directory
1002 ,(nnheader-concat message-directory method))
1003 (nnfolder-active-file
1004 ,(nnheader-concat message-directory
1005 (concat method "/active")))
1006 (nnfolder-get-new-mail nil)
1007 (nnfolder-inhibit-expiry t))))
1008 (if (assoc "archive" gnus-server-alist)
1009 (when gnus-update-message-archive-method
1010 (if method
1011 (setcdr (assoc "archive" gnus-server-alist) method)
1012 (setq gnus-server-alist (delq (assoc "archive" gnus-server-alist)
1013 gnus-server-alist))))
1014 (when method
1015 (push (cons "archive" method) gnus-server-alist))))
1016
1017 ;; If we don't read the complete active file, we fill in the
1018 ;; hashtb here.
1019 (when (or (null gnus-read-active-file)
1020 (eq gnus-read-active-file 'some))
1021 (gnus-update-active-hashtb-from-killed))
1022 (unless gnus-active-hashtb
1023 (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
1024 ;; Initialize the cache.
1025 (when gnus-use-cache
1026 (gnus-cache-open))
1027
1028 ;; Possibly eval the dribble file.
1029 (and init
1030 (or gnus-use-dribble-file gnus-slave)
1031 (gnus-dribble-eval-file))
1032
1033 ;; Slave Gnusii should then clear the dribble buffer.
1034 (when (and init gnus-slave)
1035 (gnus-dribble-clear))
1036
1037 (gnus-update-format-specifications)
1038
1039 ;; See whether we need to read the description file.
1040 (when (and (boundp 'gnus-group-line-format)
1041 (stringp gnus-group-line-format)
1042 (let ((case-fold-search nil))
1043 (string-match "%[-,0-9]*D" gnus-group-line-format))
1044 (not gnus-description-hashtb)
1045 (not dont-connect)
1046 gnus-read-active-file)
1047 (gnus-read-all-descriptions-files))
1048
1049 ;; Find new newsgroups and treat them.
1050 (when (and init gnus-check-new-newsgroups (not level)
1051 (gnus-check-server gnus-select-method)
1052 (not gnus-slave)
1053 gnus-plugged)
1054 (gnus-find-new-newsgroups))
1055
1056 ;; Check and remove bogus newsgroups.
1057 (when (and init gnus-check-bogus-newsgroups
1058 gnus-read-active-file (not level)
1059 (gnus-server-opened gnus-select-method))
1060 (gnus-check-bogus-newsgroups))
1061
1062 ;; Read any slave files.
1063 (gnus-master-read-slave-newsrc)
1064
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 dont-connect))))
1068
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'."
1072 (unless (cond
1073 ((functionp method)
1074 (funcall method group))
1075 ((listp method)
1076 (catch 'found
1077 (dolist (func method)
1078 (if (funcall func group)
1079 (throw 'found t)))
1080 nil))
1081 (t nil))
1082 (gnus-subscribe-zombies group)))
1083
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.
1088
1089 With 1 C-u, use the `ask-server' method to query the server for new
1090 groups.
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."
1093 (interactive "p")
1094 (let* ((gnus-subscribe-newsgroup-method
1095 gnus-subscribe-newsgroup-method)
1096 (check (cond
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))
1101 'ask-server)
1102 ((= (or arg 1) 16)
1103 (setq gnus-subscribe-newsgroup-method
1104 'gnus-subscribe-zombies)
1105 t)
1106 (t gnus-check-new-newsgroups))))
1107 (if (or (consp check)
1108 (eq check 'ask-server))
1109 ;; Ask the server for new groups.
1110 (gnus-ask-server-for-new-groups)
1111 ;; Go through the active hashtb and look for new groups.
1112 (let ((groups 0)
1113 group new-newsgroups)
1114 (gnus-message 5 "Looking for new newsgroups...")
1115 (unless gnus-have-read-active-file
1116 (gnus-read-active-file))
1117 (setq gnus-newsrc-last-checked-date (message-make-date))
1118 (unless gnus-killed-hashtb
1119 (gnus-make-hashtable-from-killed))
1120 ;; Go though every newsgroup in `gnus-active-hashtb' and compare
1121 ;; with `gnus-newsrc-hashtb' and `gnus-killed-hashtb'.
1122 (mapatoms
1123 (lambda (sym)
1124 (if (or (null (setq group (symbol-name sym)))
1125 (not (boundp sym))
1126 (null (symbol-value sym))
1127 (gnus-gethash group gnus-killed-hashtb)
1128 (gnus-gethash group gnus-newsrc-hashtb))
1129 ()
1130 (let ((do-sub (gnus-matches-options-n group)))
1131 (cond
1132 ((eq do-sub 'subscribe)
1133 (setq groups (1+ groups))
1134 (gnus-sethash group group gnus-killed-hashtb)
1135 (gnus-call-subscribe-functions
1136 gnus-subscribe-options-newsgroup-method group))
1137 ((eq do-sub 'ignore)
1138 nil)
1139 (t
1140 (setq groups (1+ groups))
1141 (gnus-sethash group group gnus-killed-hashtb)
1142 (if gnus-subscribe-hierarchical-interactive
1143 (push group new-newsgroups)
1144 (gnus-call-subscribe-functions
1145 gnus-subscribe-newsgroup-method group)))))))
1146 gnus-active-hashtb)
1147 (when new-newsgroups
1148 (gnus-subscribe-hierarchical-interactive new-newsgroups))
1149 (if (> groups 0)
1150 (gnus-message 5 "%d new newsgroup%s arrived."
1151 groups (if (> groups 1) "s have" " has"))
1152 (gnus-message 5 "No new newsgroups."))
1153 groups))))
1154
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.
1159
1160 ;; First we check the two user variables.
1161 (cond
1162 ((and gnus-options-subscribe
1163 (string-match gnus-options-subscribe group))
1164 'subscribe)
1165 ((let ((do-subscribe nil))
1166 (dolist (category gnus-auto-subscribed-categories)
1167 (when (gnus-member-of-valid category group)
1168 (setq do-subscribe t)))
1169 do-subscribe)
1170 'subscribe)
1171 ((and gnus-auto-subscribed-groups
1172 (string-match gnus-auto-subscribed-groups group))
1173 'subscribe)
1174 ((and gnus-options-not-subscribe
1175 (string-match gnus-options-not-subscribe group))
1176 'ignore)
1177 ;; Then we go through the list that was retrieved from the .newsrc
1178 ;; file. This list has elements on the form
1179 ;; `(REGEXP . {ignore,subscribe})'. The first match found (the list
1180 ;; is in the reverse order of the options line) is returned.
1181 (t
1182 (let ((regs gnus-newsrc-options-n))
1183 (while (and regs
1184 (not (string-match (caar regs) group)))
1185 (setq regs (cdr regs)))
1186 (and regs (cdar regs))))))
1187
1188 (defun gnus-ask-server-for-new-groups ()
1189 (let* ((new-date (message-make-date))
1190 (date (or gnus-newsrc-last-checked-date new-date))
1191 (methods (cons gnus-select-method
1192 (nconc
1193 (when (gnus-archive-server-wanted-p)
1194 (list "archive"))
1195 (append
1196 (and (consp gnus-check-new-newsgroups)
1197 gnus-check-new-newsgroups)
1198 gnus-secondary-select-methods))))
1199 (groups 0)
1200 group new-newsgroups got-new method hashtb
1201 gnus-override-subscribe-method)
1202 (unless gnus-killed-hashtb
1203 (gnus-make-hashtable-from-killed))
1204 ;; Go through both primary and secondary select methods and
1205 ;; request new newsgroups.
1206 (while (setq method (gnus-server-get-method nil (pop methods)))
1207 (setq new-newsgroups nil
1208 gnus-override-subscribe-method method)
1209 (when (and (gnus-check-server method)
1210 (gnus-request-newgroups date method))
1211 (save-excursion
1212 (setq got-new t
1213 hashtb (gnus-make-hashtable 100))
1214 (set-buffer nntp-server-buffer)
1215 ;; Enter all the new groups into a hashtable.
1216 (gnus-active-to-gnus-format method hashtb 'ignore))
1217 ;; Now all new groups from `method' are in `hashtb'.
1218 (mapatoms
1219 (lambda (group-sym)
1220 (if (or (null (setq group (symbol-name group-sym)))
1221 (not (boundp group-sym))
1222 (null (symbol-value group-sym))
1223 (gnus-gethash group gnus-newsrc-hashtb)
1224 (member group gnus-zombie-list)
1225 (member group gnus-killed-list))
1226 ;; The group is already known.
1227 ()
1228 ;; Make this group active.
1229 (when (symbol-value group-sym)
1230 (gnus-set-active group (symbol-value group-sym)))
1231 ;; Check whether we want it or not.
1232 (let ((do-sub (gnus-matches-options-n group)))
1233 (cond
1234 ((eq do-sub 'subscribe)
1235 (incf groups)
1236 (gnus-sethash group group gnus-killed-hashtb)
1237 (gnus-call-subscribe-functions
1238 gnus-subscribe-options-newsgroup-method group))
1239 ((eq do-sub 'ignore)
1240 nil)
1241 (t
1242 (incf groups)
1243 (gnus-sethash group group gnus-killed-hashtb)
1244 (if gnus-subscribe-hierarchical-interactive
1245 (push group new-newsgroups)
1246 (gnus-call-subscribe-functions
1247 gnus-subscribe-newsgroup-method group)))))))
1248 hashtb))
1249 (when new-newsgroups
1250 (gnus-subscribe-hierarchical-interactive new-newsgroups)))
1251 (if (> groups 0)
1252 (gnus-message 5 "%d new newsgroup%s arrived"
1253 groups (if (> groups 1) "s have" " has"))
1254 (gnus-message 5 "No new newsgroups"))
1255 (when got-new
1256 (setq gnus-newsrc-last-checked-date new-date))
1257 new-newsgroups))
1258
1259 (defun gnus-subscribe-group (group &optional previous method)
1260 "Subscribe GROUP and put it after PREVIOUS."
1261 (gnus-group-change-level
1262 (if method
1263 (list t group gnus-level-default-subscribed nil nil method)
1264 group)
1265 gnus-level-default-subscribed gnus-level-killed previous t)
1266 t)
1267
1268 ;; `gnus-group-change-level' is the fundamental function for changing
1269 ;; subscription levels of newsgroups. This might mean just changing
1270 ;; from level 1 to 2, which is pretty trivial, from 2 to 6 or back
1271 ;; again, which subscribes/unsubscribes a group, which is equally
1272 ;; trivial. Changing from 1-7 to 8-9 means that you kill a group, and
1273 ;; from 8-9 to 1-7 means that you remove the group from the list of
1274 ;; killed (or zombie) groups and add them to the (kinda) subscribed
1275 ;; groups. And last but not least, moving from 8 to 9 and 9 to 8,
1276 ;; which is trivial.
1277 ;; ENTRY can either be a string (newsgroup name) or a list (if
1278 ;; FROMKILLED is t, it's a list on the format (NUM INFO-LIST),
1279 ;; otherwise it's a list in the format of the `gnus-newsrc-hashtb'
1280 ;; entries.
1281 ;; LEVEL is the new level of the group, OLDLEVEL is the old level and
1282 ;; PREVIOUS is the group (in hashtb entry format) to insert this group
1283 ;; after.
1284 (defun gnus-group-change-level (entry level &optional oldlevel
1285 previous fromkilled)
1286 (let (group info active num)
1287 ;; Glean what info we can from the arguments
1288 (if (consp entry)
1289 (if fromkilled (setq group (nth 1 entry))
1290 (setq group (car (nth 2 entry))))
1291 (setq group entry))
1292 (when (and (stringp entry)
1293 oldlevel
1294 (< oldlevel gnus-level-zombie))
1295 (setq entry (gnus-group-entry entry)))
1296 (if (and (not oldlevel)
1297 (consp entry))
1298 (setq oldlevel (gnus-info-level (nth 2 entry)))
1299 (setq oldlevel (or oldlevel gnus-level-killed)))
1300 (when (stringp previous)
1301 (setq previous (gnus-group-entry previous)))
1302
1303 (if (and (>= oldlevel gnus-level-zombie)
1304 (gnus-group-entry group))
1305 ;; We are trying to subscribe a group that is already
1306 ;; subscribed.
1307 () ; Do nothing.
1308
1309 (unless (gnus-ephemeral-group-p group)
1310 (gnus-dribble-enter
1311 (format "(gnus-group-change-level %S %S %S %S %S)"
1312 group level oldlevel (car (nth 2 previous)) fromkilled)))
1313
1314 ;; Then we remove the newgroup from any old structures, if needed.
1315 ;; If the group was killed, we remove it from the killed or zombie
1316 ;; list. If not, and it is in fact going to be killed, we remove
1317 ;; it from the newsrc hash table and assoc.
1318 (cond
1319 ((>= oldlevel gnus-level-zombie)
1320 ;; oldlevel could be wrong.
1321 (setq gnus-zombie-list (delete group gnus-zombie-list))
1322 (setq gnus-killed-list (delete group gnus-killed-list)))
1323 (t
1324 (when (and (>= level gnus-level-zombie)
1325 entry)
1326 (gnus-sethash (car (nth 2 entry)) nil gnus-newsrc-hashtb)
1327 (when (nth 3 entry)
1328 (setcdr (gnus-group-entry (car (nth 3 entry)))
1329 (cdr entry)))
1330 (setcdr (cdr entry) (cdddr entry)))))
1331
1332 ;; Finally we enter (if needed) the list where it is supposed to
1333 ;; go, and change the subscription level. If it is to be killed,
1334 ;; we enter it into the killed or zombie list.
1335 (cond
1336 ((>= level gnus-level-zombie)
1337 ;; Remove from the hash table.
1338 (gnus-sethash group nil gnus-newsrc-hashtb)
1339 (if (= level gnus-level-zombie)
1340 (push group gnus-zombie-list)
1341 (if (= oldlevel gnus-level-killed)
1342 ;; Remove from active hashtb.
1343 (unintern group gnus-active-hashtb)
1344 ;; Don't add it into killed-list if it was killed.
1345 (push group gnus-killed-list))))
1346 (t
1347 ;; If the list is to be entered into the newsrc assoc, and
1348 ;; it was killed, we have to create an entry in the newsrc
1349 ;; hashtb format and fix the pointers in the newsrc assoc.
1350 (if (< oldlevel gnus-level-zombie)
1351 ;; It was alive, and it is going to stay alive, so we
1352 ;; just change the level and don't change any pointers or
1353 ;; hash table entries.
1354 (setcar (cdaddr entry) level)
1355 (if (listp entry)
1356 (setq info (cdr entry)
1357 num (car entry))
1358 (setq active (gnus-active group))
1359 (setq num
1360 (if active (- (1+ (cdr active)) (car active)) t))
1361 ;; Shorten the select method if possible, if we need to
1362 ;; store it at all (native groups).
1363 (let ((method (gnus-method-simplify
1364 (or gnus-override-subscribe-method
1365 (gnus-group-method group)))))
1366 (if method
1367 (setq info (list group level nil nil method))
1368 (setq info (list group level nil)))))
1369 (unless previous
1370 (setq previous
1371 (let ((p gnus-newsrc-alist))
1372 (while (cddr p)
1373 (setq p (cdr p)))
1374 p)))
1375 (setq entry (cons info (cddr previous)))
1376 (if (cdr previous)
1377 (progn
1378 (setcdr (cdr previous) entry)
1379 (gnus-sethash group (cons num (cdr previous))
1380 gnus-newsrc-hashtb))
1381 (setcdr previous entry)
1382 (gnus-sethash group (cons num previous)
1383 gnus-newsrc-hashtb))
1384 (when (cdr entry)
1385 (setcdr (gnus-group-entry (caadr entry)) entry))
1386 (gnus-dribble-enter
1387 (format "(gnus-group-set-info '%S)" info)
1388 (concat "^(gnus-group-set-info '(\"" (regexp-quote group) "\"")))))
1389 (when gnus-group-change-level-function
1390 (funcall gnus-group-change-level-function
1391 group level oldlevel previous)))))
1392
1393 (defun gnus-check-bogus-newsgroups (&optional confirm)
1394 "Remove bogus newsgroups.
1395 If CONFIRM is non-nil, the user has to confirm the deletion of every
1396 newsgroup."
1397 (let ((newsrc (cdr gnus-newsrc-alist))
1398 bogus group entry info)
1399 (gnus-message 5 "Checking bogus newsgroups...")
1400 (unless (gnus-read-active-file-p)
1401 (gnus-read-active-file t))
1402 (when (gnus-read-active-file-p)
1403 ;; Find all bogus newsgroup that are subscribed.
1404 (while newsrc
1405 (setq info (pop newsrc)
1406 group (gnus-info-group info))
1407 (unless (or (gnus-active group) ; Active
1408 (and (gnus-info-method info)
1409 (not (gnus-secondary-method-p
1410 (gnus-info-method info))))) ; Foreign
1411 ;; Found a bogus newsgroup.
1412 (push group bogus)))
1413 (if confirm
1414 (map-y-or-n-p
1415 (format "Remove bogus group %%s (of %d groups)? " (length bogus))
1416 (lambda (group)
1417 ;; Remove all bogus subscribed groups by first killing them, and
1418 ;; then removing them from the list of killed groups.
1419 (when (setq entry (gnus-group-entry group))
1420 (gnus-group-change-level entry gnus-level-killed)
1421 (setq gnus-killed-list (delete group gnus-killed-list))))
1422 bogus '("group" "groups" "remove"))
1423 (while (setq group (pop bogus))
1424 ;; Remove all bogus subscribed groups by first killing them, and
1425 ;; then removing them from the list of killed groups.
1426 (when (setq entry (gnus-group-entry group))
1427 (gnus-group-change-level entry gnus-level-killed)
1428 (setq gnus-killed-list (delete group gnus-killed-list)))))
1429 ;; Then we remove all bogus groups from the list of killed and
1430 ;; zombie groups. They are removed without confirmation.
1431 (let ((dead-lists '(gnus-killed-list gnus-zombie-list))
1432 killed)
1433 (while dead-lists
1434 (setq killed (symbol-value (car dead-lists)))
1435 (while killed
1436 (unless (gnus-active (setq group (pop killed)))
1437 ;; The group is bogus.
1438 ;; !!!Slow as hell.
1439 (set (car dead-lists)
1440 (delete group (symbol-value (car dead-lists))))))
1441 (setq dead-lists (cdr dead-lists))))
1442 (gnus-run-hooks 'gnus-check-bogus-groups-hook)
1443 (gnus-message 5 "Checking bogus newsgroups...done"))))
1444
1445 (defun gnus-check-duplicate-killed-groups ()
1446 "Remove duplicates from the list of killed groups."
1447 (interactive)
1448 (let ((killed gnus-killed-list))
1449 (while killed
1450 (gnus-message 9 "%d" (length killed))
1451 (setcdr killed (delete (car killed) (cdr killed)))
1452 (setq killed (cdr killed)))))
1453
1454 ;; We want to inline a function from gnus-cache, so we cheat here:
1455 (defvar gnus-cache-active-hashtb)
1456 (eval-when-compile
1457 (defun gnus-cache-possibly-alter-active (group active)
1458 "Alter the ACTIVE info for GROUP to reflect the articles in the cache."
1459 (when gnus-cache-active-hashtb
1460 (let ((cache-active (gnus-gethash group gnus-cache-active-hashtb)))
1461 (when cache-active
1462 (when (< (car cache-active) (car active))
1463 (setcar active (car cache-active)))
1464 (when (> (cdr cache-active) (cdr active))
1465 (setcdr active (cdr cache-active))))))))
1466
1467 (defun gnus-activate-group (group &optional scan dont-check method
1468 dont-sub-check)
1469 "Check whether a group has been activated or not.
1470 If SCAN, request a scan of that group as well. If METHOD, use
1471 that select method instead of determining the method based on the
1472 group name. If DONT-CHECK, don't check whether the group
1473 actually exists. If DONT-SUB-CHECK or DONT-CHECK, don't let the
1474 backend check whether the group actually exists."
1475 (let ((method (or method (inline (gnus-find-method-for-group group))))
1476 active)
1477 (and (inline (gnus-check-server method))
1478 ;; We escape all bugs and quit here to make it possible to
1479 ;; continue if a group is so out-there that it reports bugs
1480 ;; and stuff.
1481 (progn
1482 (and scan
1483 (gnus-check-backend-function 'request-scan (car method))
1484 (gnus-request-scan group method))
1485 t)
1486 (if (or debug-on-error debug-on-quit)
1487 (inline (gnus-request-group group (or dont-sub-check dont-check)
1488 method
1489 (gnus-get-info group)))
1490 (condition-case nil
1491 (inline (gnus-request-group group (or dont-sub-check dont-check)
1492 method
1493 (gnus-get-info group)))
1494 (quit
1495 (if debug-on-quit
1496 (debug "Quit")
1497 (message "Quit activating %s" group))
1498 nil)))
1499 (unless dont-check
1500 (setq active (gnus-parse-active))
1501 ;; If there are no articles in the group, the GROUP
1502 ;; command may have responded with the `(0 . 0)'. We
1503 ;; ignore this if we already have an active entry
1504 ;; for the group.
1505 (if (and (zerop (or (car active) 0))
1506 (zerop (or (cdr active) 0))
1507 (gnus-active group))
1508 (gnus-active group)
1509
1510 ;; If a cache is present, we may have to alter the active info.
1511 (when gnus-use-cache
1512 (inline (gnus-cache-possibly-alter-active
1513 group active)))
1514
1515 ;; If the agent is enabled, we may have to alter the active info.
1516 (when gnus-agent
1517 (gnus-agent-possibly-alter-active group active))
1518
1519 (gnus-set-active group active)
1520 ;; Return the new active info.
1521 active)))))
1522
1523 (defun gnus-get-unread-articles-in-group (info active &optional update)
1524 (when (and info active)
1525 ;; Allow the backend to update the info in the group.
1526 (when (and update
1527 (gnus-request-update-info
1528 info (inline (gnus-find-method-for-group
1529 (gnus-info-group info)))))
1530 (gnus-activate-group (gnus-info-group info) nil t))
1531
1532 (let* ((range (gnus-info-read info))
1533 (num 0))
1534
1535 ;; These checks are present in gnus-activate-group but skipped
1536 ;; due to setting dont-check in the preceding call.
1537
1538 ;; If a cache is present, we may have to alter the active info.
1539 (when (and gnus-use-cache info)
1540 (inline (gnus-cache-possibly-alter-active
1541 (gnus-info-group info) active)))
1542
1543 ;; If the agent is enabled, we may have to alter the active info.
1544 (when (and gnus-agent info)
1545 (gnus-agent-possibly-alter-active (gnus-info-group info) active info))
1546
1547 ;; Modify the list of read articles according to what articles
1548 ;; are available; then tally the unread articles and add the
1549 ;; number to the group hash table entry.
1550 (cond
1551 ((zerop (cdr active))
1552 (setq num 0))
1553 ((not range)
1554 (setq num (- (1+ (cdr active)) (car active))))
1555 ((not (listp (cdr range)))
1556 ;; Fix a single (num . num) range according to the
1557 ;; active hash table.
1558 ;; Fix by Carsten Bormann <cabo@Informatik.Uni-Bremen.DE>.
1559 (and (< (cdr range) (car active)) (setcdr range (1- (car active))))
1560 (and (> (cdr range) (cdr active)) (setcdr range (cdr active)))
1561 ;; Compute number of unread articles.
1562 (setq num (max 0 (- (cdr active) (- (1+ (cdr range)) (car range))))))
1563 (t
1564 ;; The read list is a list of ranges. Fix them according to
1565 ;; the active hash table.
1566 ;; First peel off any elements that are below the lower
1567 ;; active limit.
1568 (while (and (cdr range)
1569 (>= (car active)
1570 (or (and (atom (cadr range)) (cadr range))
1571 (caadr range))))
1572 (if (numberp (car range))
1573 (setcar range
1574 (cons (car range)
1575 (or (and (numberp (cadr range))
1576 (cadr range))
1577 (cdadr range))))
1578 (setcdr (car range)
1579 (or (and (numberp (nth 1 range)) (nth 1 range))
1580 (cdadr range))))
1581 (setcdr range (cddr range)))
1582 ;; Adjust the first element to be the same as the lower limit.
1583 (when (and (not (atom (car range)))
1584 (< (cdar range) (car active)))
1585 (setcdr (car range) (1- (car active))))
1586 ;; Then we want to peel off any elements that are higher
1587 ;; than the upper active limit.
1588 (let ((srange range))
1589 ;; Go past all valid elements.
1590 (while (and (cdr srange)
1591 (<= (or (and (atom (cadr srange))
1592 (cadr srange))
1593 (caadr srange))
1594 (cdr active)))
1595 (setq srange (cdr srange)))
1596 (when (cdr srange)
1597 ;; Nuke all remaining invalid elements.
1598 (setcdr srange nil))
1599
1600 ;; Adjust the final element.
1601 (when (and (not (atom (car srange)))
1602 (> (cdar srange) (cdr active)))
1603 (setcdr (car srange) (cdr active))))
1604 ;; Compute the number of unread articles.
1605 (while range
1606 (setq num (+ num (- (1+ (or (and (atom (car range)) (car range))
1607 (cdar range)))
1608 (or (and (atom (car range)) (car range))
1609 (caar range)))))
1610 (setq range (cdr range)))
1611 (setq num (max 0 (- (cdr active) num)))))
1612 ;; Set the number of unread articles.
1613 (when (and info
1614 (gnus-group-entry (gnus-info-group info)))
1615 (setcar (gnus-group-entry (gnus-info-group info)) num))
1616 num)))
1617
1618 ;; Go though `gnus-newsrc-alist' and compare with `gnus-active-hashtb'
1619 ;; and compute how many unread articles there are in each group.
1620 (defun gnus-get-unread-articles (&optional level dont-connect one-level)
1621 (setq gnus-server-method-cache nil)
1622 (require 'gnus-agent)
1623 (let* ((newsrc (cdr gnus-newsrc-alist))
1624 (alevel (or level gnus-activate-level (1+ gnus-level-subscribed)))
1625 (foreign-level
1626 (or
1627 level
1628 (min
1629 (cond ((and gnus-activate-foreign-newsgroups
1630 (not (numberp gnus-activate-foreign-newsgroups)))
1631 (1+ gnus-level-subscribed))
1632 ((numberp gnus-activate-foreign-newsgroups)
1633 gnus-activate-foreign-newsgroups)
1634 (t 0))
1635 alevel)))
1636 (methods-cache nil)
1637 (type-cache nil)
1638 (gnus-agent-article-local-times 0)
1639 (archive-method (gnus-server-to-method "archive"))
1640 infos info group active method cmethod
1641 method-type method-group-list entry)
1642 (gnus-message 6 "Checking new news...")
1643
1644 (while newsrc
1645 (setq active (gnus-active (setq group (gnus-info-group
1646 (setq info (pop newsrc))))))
1647 ;; First go through all the groups, see what select methods they
1648 ;; belong to, and then collect them into lists per unique select
1649 ;; method.
1650 (if (not (setq method (gnus-info-method info)))
1651 (setq method gnus-select-method)
1652 ;; There may be several similar methods. Possibly extend the
1653 ;; method.
1654 (if (setq cmethod (assoc method methods-cache))
1655 (setq method (cdr cmethod))
1656 (setq cmethod (if (stringp method)
1657 (gnus-server-to-method method)
1658 (inline (gnus-find-method-for-group
1659 (gnus-info-group info) info))))
1660 (push (cons method cmethod) methods-cache)
1661 (setq method cmethod)))
1662 (setq method-group-list (assoc method type-cache))
1663 (unless method-group-list
1664 (setq method-type
1665 (cond
1666 ((or (gnus-secondary-method-p method)
1667 (and (gnus-archive-server-wanted-p)
1668 (gnus-methods-equal-p archive-method method)))
1669 'secondary)
1670 ((inline (gnus-server-equal gnus-select-method method))
1671 'primary)
1672 (t
1673 'foreign)))
1674 (push (setq method-group-list (list method method-type nil nil))
1675 type-cache))
1676 ;; Only add groups that need updating.
1677 (if (or (and foreign-level (null (numberp foreign-level)))
1678 (funcall (if one-level #'= #'<=) (gnus-info-level info)
1679 (if (eq (cadr method-group-list) 'foreign)
1680 foreign-level
1681 alevel)))
1682 (setcar (nthcdr 2 method-group-list)
1683 (cons info (nth 2 method-group-list)))
1684 ;; The group is inactive, so we nix out the number of unread articles.
1685 ;; It leads `(gnus-group-unread group)' to return t. See also
1686 ;; `gnus-group-prepare-flat'.
1687 (unless active
1688 (when (setq entry (gnus-group-entry group))
1689 (setcar entry t)))))
1690
1691 ;; Sort the methods based so that the primary and secondary
1692 ;; methods come first. This is done for legacy reasons to try to
1693 ;; ensure that side-effect behavior doesn't change from previous
1694 ;; Gnus versions.
1695 (setq type-cache
1696 (sort (nreverse type-cache)
1697 (lambda (c1 c2)
1698 (< (gnus-method-rank (cadr c1) (car c1))
1699 (gnus-method-rank (cadr c2) (car c2))))))
1700 ;; Go through the list of servers and possibly extend methods that
1701 ;; aren't equal (and that need extension; i.e., they are async).
1702 (let ((methods nil))
1703 (dolist (elem type-cache)
1704 (destructuring-bind (method method-type infos dummy) elem
1705 (let ((gnus-opened-servers methods))
1706 (when (and (gnus-similar-server-opened method)
1707 (gnus-check-backend-function
1708 'retrieve-group-data-early (car method)))
1709 (setq method (gnus-server-extend-method
1710 (gnus-info-group (car infos))
1711 method))
1712 (setcar elem method))
1713 (push (list method 'ok) methods)))))
1714
1715 ;; If we have primary/secondary select methods, but no groups from
1716 ;; them, we still want to issue a retrieval request from them.
1717 (unless dont-connect
1718 (dolist (method (cons gnus-select-method
1719 gnus-secondary-select-methods))
1720 (when (and (not (assoc method type-cache))
1721 (gnus-check-backend-function 'request-list (car method)))
1722 (with-current-buffer nntp-server-buffer
1723 (gnus-read-active-file-1 method nil)))))
1724
1725 ;; Clear out all the early methods.
1726 (dolist (elem type-cache)
1727 (destructuring-bind (method method-type infos dummy) elem
1728 (when (and method
1729 infos
1730 (gnus-check-backend-function
1731 'retrieve-group-data-early (car method))
1732 (not (gnus-method-denied-p method)))
1733 (when (ignore-errors (gnus-get-function method 'open-server))
1734 (unless (gnus-server-opened method)
1735 (gnus-open-server method))
1736 (when (gnus-server-opened method)
1737 ;; Just mark this server as "cleared".
1738 (gnus-retrieve-group-data-early method nil))))))
1739
1740 ;; Start early async retrieval of data.
1741 (let ((done-methods nil)
1742 sanity-spec)
1743 (dolist (elem type-cache)
1744 (destructuring-bind (method method-type infos dummy) elem
1745 (setq sanity-spec (list (car method) (cadr method)))
1746 (when (and method infos
1747 (not (gnus-method-denied-p method)))
1748 ;; If the open-server method doesn't exist, then the method
1749 ;; itself doesn't exist, so we ignore it.
1750 (if (not (ignore-errors (gnus-get-function method 'open-server)))
1751 (setq type-cache (delq elem type-cache))
1752 (unless (gnus-server-opened method)
1753 (gnus-open-server method))
1754 (when (and
1755 ;; This is a sanity check, so that we never
1756 ;; attempt to start two async requests to the
1757 ;; same server, because that will fail. This
1758 ;; should never happen, since the methods should
1759 ;; be unique at this point, but apparently it
1760 ;; does happen in the wild with some setups.
1761 (not (member sanity-spec done-methods))
1762 (gnus-server-opened method)
1763 (gnus-check-backend-function
1764 'retrieve-group-data-early (car method)))
1765 (push sanity-spec done-methods)
1766 (when (gnus-check-backend-function 'request-scan (car method))
1767 (gnus-request-scan nil method))
1768 ;; Store the token we get back from -early so that we
1769 ;; can pass it to -finish later.
1770 (setcar (nthcdr 3 elem)
1771 (gnus-retrieve-group-data-early method infos))))))))
1772
1773 ;; Do the rest of the retrieval.
1774 (dolist (elem type-cache)
1775 (destructuring-bind (method method-type infos early-data) elem
1776 (when (and method infos
1777 (not (gnus-method-denied-p method)))
1778 (let ((updatep (gnus-check-backend-function
1779 'request-update-info (car method))))
1780 ;; See if any of the groups from this method require updating.
1781 (gnus-read-active-for-groups method infos early-data)
1782 (dolist (info infos)
1783 (inline (gnus-get-unread-articles-in-group
1784 info (gnus-active (gnus-info-group info))
1785 updatep)))))))
1786 (gnus-message 6 "Checking new news...done")))
1787
1788 (defun gnus-method-rank (type method)
1789 (cond
1790 ;; Get info for virtual groups last.
1791 ((eq (car method) 'nnvirtual)
1792 200)
1793 ((eq type 'primary)
1794 1)
1795 ;; Compute the rank of the secondary methods based on where they
1796 ;; are in the secondary select list.
1797 ((eq type 'secondary)
1798 (let ((i 2))
1799 (block nil
1800 (dolist (smethod gnus-secondary-select-methods)
1801 (when (equal method smethod)
1802 (return i))
1803 (incf i))
1804 i)))
1805 ;; Just say that all foreign groups have the same rank.
1806 (t
1807 100)))
1808
1809 (defun gnus-read-active-for-groups (method infos early-data)
1810 (with-current-buffer nntp-server-buffer
1811 (cond
1812 ;; Finish up getting the data from the methods that have -early
1813 ;; methods.
1814 ((and
1815 early-data
1816 (gnus-check-backend-function 'finish-retrieve-group-infos (car method))
1817 (or (not (gnus-agent-method-p method))
1818 (gnus-online method)))
1819 (gnus-finish-retrieve-group-infos method infos early-data)
1820 ;; We may have altered the data now, so mark the dribble buffer
1821 ;; as dirty so that it gets saved.
1822 (gnus-dribble-touch)
1823 (gnus-agent-save-active method))
1824 ;; Most backends have -retrieve-groups.
1825 ((gnus-check-backend-function 'retrieve-groups (car method))
1826 (when (gnus-check-backend-function 'request-scan (car method))
1827 (gnus-request-scan nil method))
1828 (let (groups)
1829 (gnus-read-active-file-2
1830 (dolist (info infos (nreverse groups))
1831 (push (gnus-group-real-name (gnus-info-group info)) groups))
1832 method)))
1833 ;; Virtually all backends have -request-list.
1834 ((gnus-check-backend-function 'request-list (car method))
1835 (gnus-read-active-file-1 method nil))
1836 ;; Except nnvirtual and friends, where we request each group, one
1837 ;; by one.
1838 (t
1839 (dolist (info infos)
1840 (gnus-activate-group (gnus-info-group info) nil nil method t))))))
1841
1842 ;; Create a hash table out of the newsrc alist. The `car's of the
1843 ;; alist elements are used as keys.
1844 (defun gnus-make-hashtable-from-newsrc-alist ()
1845 (let ((alist gnus-newsrc-alist)
1846 (ohashtb gnus-newsrc-hashtb)
1847 prev info method rest methods)
1848 (setq gnus-newsrc-hashtb (gnus-make-hashtable (length alist)))
1849 (setq alist
1850 (setq prev (setq gnus-newsrc-alist
1851 (if (equal (caar gnus-newsrc-alist)
1852 "dummy.group")
1853 gnus-newsrc-alist
1854 (cons (list "dummy.group" 0 nil) alist)))))
1855 (while alist
1856 (setq info (car alist))
1857 ;; Make the same select-methods identical Lisp objects.
1858 (when (setq method (gnus-info-method info))
1859 (if (setq rest (member method methods))
1860 (gnus-info-set-method info (car rest))
1861 (push method methods)))
1862 ;; Check for duplicates.
1863 (if (gnus-gethash (car info) gnus-newsrc-hashtb)
1864 ;; Remove this entry from the alist.
1865 (setcdr prev (cddr prev))
1866 (gnus-sethash
1867 (car info)
1868 ;; Preserve number of unread articles in groups.
1869 (cons (and ohashtb (car (gnus-gethash (car info) ohashtb)))
1870 prev)
1871 gnus-newsrc-hashtb)
1872 (setq prev alist))
1873 (setq alist (cdr alist)))
1874 ;; Make the same select-methods in `gnus-server-alist' identical
1875 ;; as well.
1876 (while methods
1877 (setq method (pop methods))
1878 (when (setq rest (rassoc method gnus-server-alist))
1879 (setcdr rest method)))))
1880
1881 (defun gnus-make-hashtable-from-killed ()
1882 "Create a hash table from the killed and zombie lists."
1883 (let ((lists '(gnus-killed-list gnus-zombie-list))
1884 list)
1885 (setq gnus-killed-hashtb
1886 (gnus-make-hashtable
1887 (+ (length gnus-killed-list) (length gnus-zombie-list))))
1888 (while lists
1889 (setq list (symbol-value (pop lists)))
1890 (while list
1891 (gnus-sethash (car list) (pop list) gnus-killed-hashtb)))))
1892
1893 (defun gnus-parse-active ()
1894 "Parse active info in the nntp server buffer."
1895 (with-current-buffer nntp-server-buffer
1896 (goto-char (point-min))
1897 ;; Parse the result we got from `gnus-request-group'.
1898 (when (looking-at "[0-9]+ [0-9]+ \\([0-9]+\\) [0-9]+")
1899 (goto-char (match-beginning 1))
1900 (cons (read (current-buffer))
1901 (read (current-buffer))))))
1902
1903 (defun gnus-make-articles-unread (group articles)
1904 "Mark ARTICLES in GROUP as unread."
1905 (let* ((info (nth 2 (or (gnus-group-entry group)
1906 (gnus-group-entry
1907 (gnus-group-real-name group)))))
1908 (ranges (gnus-info-read info))
1909 news article)
1910 (while articles
1911 (when (gnus-member-of-range
1912 (setq article (pop articles)) ranges)
1913 (push article news)))
1914 (when news
1915 ;; Enter this list into the group info.
1916 (gnus-info-set-read
1917 info (gnus-remove-from-range (gnus-info-read info) (nreverse news)))
1918
1919 ;; Set the number of unread articles in gnus-newsrc-hashtb.
1920 (gnus-get-unread-articles-in-group info (gnus-active group))
1921
1922 ;; Insert the change into the group buffer and the dribble file.
1923 (gnus-group-update-group group t))))
1924
1925 (defun gnus-make-ascending-articles-unread (group articles)
1926 "Mark ascending ARTICLES in GROUP as unread."
1927 (let* ((entry (or (gnus-group-entry group)
1928 (gnus-group-entry (gnus-group-real-name group))))
1929 (info (nth 2 entry))
1930 (ranges (gnus-info-read info))
1931 (r ranges)
1932 modified)
1933
1934 (while articles
1935 (let ((article (pop articles))) ; get the next article to remove from ranges
1936 (while (let ((range (car ranges))) ; note the current range
1937 (if (atom range) ; single value range
1938 (cond ((not range)
1939 ;; the articles extend past the end of the ranges
1940 ;; OK - I'm done
1941 (setq articles nil))
1942 ((< range article)
1943 ;; this range precedes the article. Leave the range unmodified.
1944 (pop ranges)
1945 ranges)
1946 ((= range article)
1947 ;; this range exactly matches the article; REMOVE THE RANGE.
1948 ;; NOTE: When the range being removed is the last range, the list is corrupted by inserting null at its end.
1949 (setcar ranges (cadr ranges))
1950 (setcdr ranges (cddr ranges))
1951 (setq modified (if (car ranges) t 'remove-null))
1952 nil))
1953 (let ((min (car range))
1954 (max (cdr range)))
1955 ;; I have a min/max range to consider
1956 (cond ((> min max) ; invalid range introduced by splitter
1957 (setcar ranges (cadr ranges))
1958 (setcdr ranges (cddr ranges))
1959 (setq modified (if (car ranges) t 'remove-null))
1960 ranges)
1961 ((= min max)
1962 ;; replace min/max range with a single-value range
1963 (setcar ranges min)
1964 ranges)
1965 ((< max article)
1966 ;; this range precedes the article. Leave the range unmodified.
1967 (pop ranges)
1968 ranges)
1969 ((< article min)
1970 ;; this article precedes the range. Return null to move to the
1971 ;; next article
1972 nil)
1973 (t
1974 ;; this article splits the range into two parts
1975 (setcdr ranges (cons (cons (1+ article) max) (cdr ranges)))
1976 (setcdr range (1- article))
1977 (setq modified t)
1978 ranges))))))))
1979
1980 (when modified
1981 (when (eq modified 'remove-null)
1982 (setq r (delq nil r)))
1983 ;; Enter this list into the group info.
1984 (gnus-info-set-read info r)
1985
1986 ;; Set the number of unread articles in gnus-newsrc-hashtb.
1987 (gnus-get-unread-articles-in-group info (gnus-active group))
1988
1989 ;; Insert the change into the group buffer and the dribble file.
1990 (gnus-group-update-group group t))))
1991
1992 ;; Enter all dead groups into the hashtb.
1993 (defun gnus-update-active-hashtb-from-killed ()
1994 (let ((hashtb (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
1995 (lists (list gnus-killed-list gnus-zombie-list))
1996 killed)
1997 (while lists
1998 (setq killed (car lists))
1999 (while killed
2000 (gnus-sethash (mm-string-as-unibyte (car killed)) nil hashtb)
2001 (setq killed (cdr killed)))
2002 (setq lists (cdr lists)))))
2003
2004 (defun gnus-get-killed-groups ()
2005 "Go through the active hashtb and mark all unknown groups as killed."
2006 ;; First make sure active file has been read.
2007 (unless (gnus-read-active-file-p)
2008 (let ((gnus-read-active-file t))
2009 (gnus-read-active-file)))
2010 (unless gnus-killed-hashtb
2011 (gnus-make-hashtable-from-killed))
2012 ;; Go through all newsgroups that are known to Gnus - enlarge kill list.
2013 (mapatoms
2014 (lambda (sym)
2015 (let ((groups 0)
2016 (group (symbol-name sym)))
2017 (if (or (null group)
2018 (gnus-gethash group gnus-killed-hashtb)
2019 (gnus-gethash group gnus-newsrc-hashtb))
2020 ()
2021 (let ((do-sub (gnus-matches-options-n group)))
2022 (if (or (eq do-sub 'subscribe) (eq do-sub 'ignore))
2023 ()
2024 (setq groups (1+ groups))
2025 (push group gnus-killed-list)
2026 (gnus-sethash group group gnus-killed-hashtb))))))
2027 gnus-active-hashtb)
2028 (gnus-dribble-touch))
2029
2030 ;; Get the active file(s) from the backend(s).
2031 (defun gnus-read-active-file (&optional force not-native)
2032 (gnus-group-set-mode-line)
2033 (let ((methods
2034 (mapcar
2035 (lambda (m) (if (stringp m) (gnus-server-get-method nil m) m))
2036 (append
2037 (if (and (not not-native)
2038 (gnus-check-server gnus-select-method))
2039 ;; The native server is available.
2040 (cons gnus-select-method gnus-secondary-select-methods)
2041 ;; The native server is down, so we just do the
2042 ;; secondary ones.
2043 gnus-secondary-select-methods)
2044 ;; Also read from the archive server.
2045 (when (gnus-archive-server-wanted-p)
2046 (list "archive")))))
2047 method)
2048 (setq gnus-have-read-active-file nil)
2049 (with-current-buffer nntp-server-buffer
2050 (while (setq method (pop methods))
2051 ;; Only do each method once, in case the methods appear more
2052 ;; than once in this list.
2053 (when (and (not (member method methods))
2054 ;; Check whether the backend exists.
2055 (ignore-errors (gnus-get-function method 'open-server)))
2056 (if (or debug-on-error debug-on-quit)
2057 (gnus-read-active-file-1 method force)
2058 (condition-case ()
2059 (gnus-read-active-file-1 method force)
2060 ;; We catch C-g so that we can continue past servers
2061 ;; that do not respond.
2062 (quit
2063 (if debug-on-quit
2064 (debug "Quit")
2065 (message "Quit reading the active file"))
2066 nil))))))))
2067
2068 (defun gnus-read-active-file-1 (method force)
2069 (let (where mesg)
2070 (setq where (nth 1 method)
2071 mesg (format "Reading active file%s via %s..."
2072 (if (and where (not (zerop (length where))))
2073 (concat " from " where) "")
2074 (car method)))
2075 (gnus-message 5 "%s" mesg)
2076 (when (gnus-check-server method)
2077 ;; Request that the backend scan its incoming messages.
2078 (when (and (or (and gnus-agent
2079 (gnus-online method))
2080 (not gnus-agent))
2081 (gnus-check-backend-function 'request-scan (car method)))
2082 (gnus-request-scan nil method))
2083 (cond
2084 ((and (eq gnus-read-active-file 'some)
2085 (gnus-check-backend-function 'retrieve-groups (car method))
2086 (not force))
2087 (let ((newsrc (cdr gnus-newsrc-alist))
2088 (gmethod (gnus-server-get-method nil method))
2089 groups info)
2090 (while (setq info (pop newsrc))
2091 (when (inline
2092 (gnus-server-equal
2093 (inline
2094 (gnus-find-method-for-group
2095 (gnus-info-group info) info))
2096 gmethod))
2097 (push (gnus-group-real-name (gnus-info-group info))
2098 groups)))
2099 (gnus-read-active-file-2 groups method)))
2100 ((null method)
2101 t)
2102 (t
2103 (if (not (gnus-request-list method))
2104 (unless (equal method gnus-message-archive-method)
2105 (gnus-error 1 "Cannot read active file from %s server"
2106 (car method)))
2107 (gnus-message 5 "%s" mesg)
2108 (gnus-active-to-gnus-format method gnus-active-hashtb nil t)
2109 ;; We mark this active file as read.
2110 (add-to-list 'gnus-have-read-active-file method)
2111 (gnus-message 5 "%sdone" mesg)))))))
2112
2113 (defun gnus-read-active-file-2 (groups method)
2114 "Read an active file for GROUPS in METHOD using `gnus-retrieve-groups'."
2115 (when groups
2116 (with-current-buffer nntp-server-buffer
2117 (gnus-check-server method)
2118 (let ((list-type (gnus-retrieve-groups groups method)))
2119 (cond ((not list-type)
2120 (gnus-error
2121 1.2 "Cannot read partial active file from %s server."
2122 (car method)))
2123 ((eq list-type 'active)
2124 (gnus-active-to-gnus-format method gnus-active-hashtb nil t))
2125 (t
2126 (gnus-groups-to-gnus-format method gnus-active-hashtb t)))))))
2127
2128 ;; Read an active file and place the results in `gnus-active-hashtb'.
2129 (defun gnus-active-to-gnus-format (&optional method hashtb ignore-errors
2130 real-active)
2131 (unless method
2132 (setq method gnus-select-method))
2133 (let ((cur (current-buffer))
2134 (hashtb (or hashtb
2135 (if (and gnus-active-hashtb
2136 (not (equal method gnus-select-method)))
2137 gnus-active-hashtb
2138 (setq gnus-active-hashtb
2139 (if (equal method gnus-select-method)
2140 (gnus-make-hashtable
2141 (count-lines (point-min) (point-max)))
2142 (gnus-make-hashtable 4096))))))
2143 group max min)
2144 ;; Delete unnecessary lines.
2145 (goto-char (point-min))
2146 (cond
2147 ((string= gnus-ignored-newsgroups "")
2148 (delete-matching-lines "^to\\."))
2149 (t
2150 (delete-matching-lines (concat "^to\\.\\|" gnus-ignored-newsgroups))))
2151
2152 (goto-char (point-min))
2153 (unless (re-search-forward "[\\\"]" nil t)
2154 ;; Make the group names readable as a lisp expression even if they
2155 ;; contain special characters.
2156 (goto-char (point-max))
2157 (while (re-search-backward "[][';?()#]" nil t)
2158 (insert ?\\)))
2159
2160 ;; Let the Gnus agent save the active file.
2161 (when (and gnus-agent real-active (gnus-online method))
2162 (gnus-agent-save-active method))
2163
2164 ;; If these are groups from a foreign select method, we insert the
2165 ;; group prefix in front of the group names.
2166 (when (not (gnus-server-equal
2167 (gnus-server-get-method nil method)
2168 (gnus-server-get-method nil gnus-select-method)))
2169 (let ((prefix (gnus-group-prefixed-name "" method)))
2170 (goto-char (point-min))
2171 (while (and (not (eobp))
2172 (progn
2173 (when (= (following-char) ?\")
2174 (forward-char 1))
2175 (insert prefix)
2176 (zerop (forward-line 1)))))))
2177 ;; Store the active file in a hash table.
2178 ;; Use a unibyte buffer in order to make `read' read non-ASCII
2179 ;; group names (which have been encoded) as unibyte strings.
2180 (mm-with-unibyte-buffer
2181 (insert-buffer-substring cur)
2182 (setq cur (current-buffer))
2183 (goto-char (point-min))
2184 (while (not (eobp))
2185 (condition-case ()
2186 (progn
2187 (narrow-to-region (point) (point-at-eol))
2188 ;; group gets set to a symbol interned in the hash table
2189 ;; (what a hack!!) - jwz
2190 (setq group (let ((obarray hashtb)) (read cur)))
2191 ;; ### The extended group name scheme makes
2192 ;; the previous optimization strategy sort of pointless...
2193 (when (stringp group)
2194 (setq group (intern group hashtb)))
2195 (if (and (numberp (setq max (read cur)))
2196 (numberp (setq min (read cur)))
2197 (progn
2198 (skip-chars-forward " \t")
2199 (not
2200 (or (eq (char-after) ?=)
2201 (eq (char-after) ?x)
2202 (eq (char-after) ?j)))))
2203 (progn
2204 (set group (cons min max))
2205 ;; if group is moderated, stick in moderation table
2206 (when (eq (char-after) ?m)
2207 (unless gnus-moderated-hashtb
2208 (setq gnus-moderated-hashtb (gnus-make-hashtable)))
2209 (gnus-sethash (symbol-name group) t
2210 gnus-moderated-hashtb)))
2211 (set group nil)))
2212 (error
2213 (and group
2214 (symbolp group)
2215 (set group nil))
2216 (unless ignore-errors
2217 (gnus-message 3 "Warning - invalid active: %s"
2218 (buffer-substring
2219 (point-at-bol) (point-at-eol))))))
2220 (widen)
2221 (forward-line 1)))))
2222
2223 (defun gnus-groups-to-gnus-format (method &optional hashtb real-active)
2224 ;; Parse a "groups" active file.
2225 (let ((cur (current-buffer))
2226 (hashtb (or hashtb
2227 (if (and method gnus-active-hashtb)
2228 gnus-active-hashtb
2229 (setq gnus-active-hashtb
2230 (gnus-make-hashtable
2231 (count-lines (point-min) (point-max)))))))
2232 (prefix (and method
2233 (not (gnus-server-equal
2234 (gnus-server-get-method nil method)
2235 (gnus-server-get-method nil gnus-select-method)))
2236 (gnus-group-prefixed-name "" method))))
2237
2238 ;; Let the Gnus agent save the active file.
2239 (if (and gnus-agent
2240 real-active
2241 (gnus-online method)
2242 (gnus-agent-method-p method))
2243 (progn
2244 (gnus-agent-save-active method t)
2245 (gnus-active-to-gnus-format method hashtb nil real-active))
2246
2247 (goto-char (point-min))
2248 ;; We split this into to separate loops, one with the prefix
2249 ;; and one without to speed the reading up somewhat.
2250 (if prefix
2251 (let (min max opoint group)
2252 (while (not (eobp))
2253 (condition-case ()
2254 (progn
2255 (read cur) (read cur)
2256 (setq min (read cur)
2257 max (read cur)
2258 opoint (point))
2259 (skip-chars-forward " \t")
2260 (insert prefix)
2261 (goto-char opoint)
2262 (set (let ((obarray hashtb)) (read cur))
2263 (cons min max)))
2264 (error (and group (symbolp group) (set group nil))))
2265 (forward-line 1)))
2266 (let (min max group)
2267 (while (not (eobp))
2268 (condition-case ()
2269 (when (eq (char-after) ?2)
2270 (read cur) (read cur)
2271 (setq min (read cur)
2272 max (read cur))
2273 (set (setq group (let ((obarray hashtb)) (read cur)))
2274 (cons min max)))
2275 (error (and group (symbolp group) (set group nil))))
2276 (forward-line 1)))))))
2277
2278 (defun gnus-read-newsrc-file (&optional force)
2279 "Read startup file.
2280 If FORCE is non-nil, the .newsrc file is read."
2281 ;; Reset variables that might be defined in the .newsrc.eld file.
2282 (let ((variables (remove 'gnus-format-specs gnus-variable-list)))
2283 (while variables
2284 (set (car variables) nil)
2285 (setq variables (cdr variables))))
2286 (let* ((newsrc-file gnus-current-startup-file)
2287 (quick-file (concat newsrc-file ".el")))
2288 (save-excursion
2289 ;; We always load the .newsrc.eld file. If always contains
2290 ;; much information that can not be gotten from the .newsrc
2291 ;; file (ticked articles, killed groups, foreign methods, etc.)
2292 (gnus-read-newsrc-el-file quick-file)
2293
2294 (when (and gnus-read-newsrc-file
2295 (file-exists-p gnus-current-startup-file)
2296 (or force
2297 (and (file-newer-than-file-p newsrc-file quick-file)
2298 (file-newer-than-file-p newsrc-file
2299 (concat quick-file "d")))
2300 (not gnus-newsrc-alist)))
2301 ;; We read the .newsrc file. Note that if there if a
2302 ;; .newsrc.eld file exists, it has already been read, and
2303 ;; the `gnus-newsrc-hashtb' has been created. While reading
2304 ;; the .newsrc file, Gnus will only use the information it
2305 ;; can find there for changing the data already read -
2306 ;; i. e., reading the .newsrc file will not trash the data
2307 ;; already read (except for read articles).
2308 (save-excursion
2309 (gnus-message 5 "Reading %s..." newsrc-file)
2310 (set-buffer (nnheader-find-file-noselect newsrc-file))
2311 (buffer-disable-undo)
2312 (gnus-newsrc-to-gnus-format)
2313 (kill-buffer (current-buffer))
2314 (gnus-message 5 "Reading %s...done" newsrc-file)))
2315
2316 ;; Convert old to new.
2317 (gnus-convert-old-newsrc)
2318 (gnus-clean-old-newsrc))))
2319
2320 (defun gnus-clean-old-newsrc (&optional force)
2321 ;; Currently no cleanups.
2322 )
2323
2324 (defun gnus-convert-old-newsrc ()
2325 "Convert old newsrc formats into the current format, if needed."
2326 (let ((fcv (and gnus-newsrc-file-version
2327 (gnus-continuum-version gnus-newsrc-file-version)))
2328 (gcv (gnus-continuum-version)))
2329 (when fcv
2330 ;; A newsrc file was loaded.
2331 (let (prompt-displayed
2332 (converters
2333 (sort
2334 (mapcar (lambda (date-func)
2335 (cons (gnus-continuum-version (car date-func))
2336 date-func))
2337 ;; This is a list of converters that must be run
2338 ;; to bring the newsrc file up to the current
2339 ;; version. If you create an incompatibility
2340 ;; with older versions, you should create an
2341 ;; entry here. The entry should consist of the
2342 ;; current gnus version (hardcoded so that it
2343 ;; doesn't change with each release) and the
2344 ;; function that must be applied to convert the
2345 ;; previous version into the current version.
2346 '(("September Gnus v0.1" nil
2347 gnus-convert-old-ticks)
2348 ("Oort Gnus v0.08" "legacy-gnus-agent"
2349 gnus-agent-convert-to-compressed-agentview)
2350 ("Gnus v5.10.7" "legacy-gnus-agent"
2351 gnus-agent-unlist-expire-days)
2352 ("Gnus v5.10.7" "legacy-gnus-agent"
2353 gnus-agent-unhook-expire-days)))
2354 #'car-less-than-car)))
2355 ;; Skip converters older than the file version
2356 (while (and converters (>= fcv (caar converters)))
2357 (pop converters))
2358
2359 ;; Perform converters to bring older version up to date.
2360 (when (and converters (< fcv (caar converters)))
2361 (while (and converters (< fcv (caar converters))
2362 (<= (caar converters) gcv))
2363 (let* ((converter-spec (pop converters))
2364 (convert-to (nth 1 converter-spec))
2365 (load-from (nth 2 converter-spec))
2366 (func (nth 3 converter-spec)))
2367 (when (and load-from
2368 (not (fboundp func)))
2369 (load load-from t))
2370 (or prompt-displayed
2371 (not (gnus-convert-converter-needs-prompt func))
2372 (while (let (c
2373 (cursor-in-echo-area t)
2374 (echo-keystrokes 0))
2375 (message "Convert gnus from version `%s' to `%s'? (n/y/?)"
2376 gnus-newsrc-file-version gnus-version)
2377 (setq c (read-char-exclusive))
2378
2379 (cond ((or (eq c ?n) (eq c ?N))
2380 (error "Can not start gnus without converting"))
2381 ((or (eq c ?y) (eq c ?Y))
2382 (setq prompt-displayed t)
2383 nil)
2384 ((eq c ?\?)
2385 (message "This conversion is irreversible. \
2386 To be safe, you should backup your files before proceeding.")
2387 (sit-for 5)
2388 t)
2389 (t
2390 (gnus-message 3 "Ignoring unexpected input")
2391 (sit-for 3)
2392 t)))))
2393
2394 (funcall func convert-to)))
2395 (gnus-dribble-enter
2396 (gnus-format-message ";Converted gnus from version `%s' to `%s'."
2397 gnus-newsrc-file-version gnus-version)))))))
2398
2399 (defun gnus-convert-mark-converter-prompt (converter no-prompt)
2400 "Indicate whether CONVERTER requires gnus-convert-old-newsrc to
2401 display the conversion prompt. NO-PROMPT may be nil (prompt),
2402 t (no prompt), or any form that can be called as a function.
2403 The form should return either t or nil."
2404 (put converter 'gnus-convert-no-prompt no-prompt))
2405
2406 (defun gnus-convert-converter-needs-prompt (converter)
2407 (let ((no-prompt (get converter 'gnus-convert-no-prompt)))
2408 (not (if (memq no-prompt '(t nil))
2409 no-prompt
2410 (funcall no-prompt)))))
2411
2412 (defun gnus-convert-old-ticks (converting-to)
2413 (let ((newsrc (cdr gnus-newsrc-alist))
2414 marks info dormant ticked)
2415 (while (setq info (pop newsrc))
2416 (when (setq marks (gnus-info-marks info))
2417 (setq dormant (cdr (assq 'dormant marks))
2418 ticked (cdr (assq 'tick marks)))
2419 (when (or dormant ticked)
2420 (gnus-info-set-read
2421 info
2422 (gnus-add-to-range
2423 (gnus-info-read info)
2424 (nconc (gnus-uncompress-range dormant)
2425 (gnus-uncompress-range ticked)))))))))
2426
2427 (defun gnus-load (file)
2428 "Load FILE, but in such a way that read errors can be reported."
2429 (with-temp-buffer
2430 (insert-file-contents file)
2431 (while (not (eobp))
2432 (condition-case type
2433 (let ((form (read (current-buffer))))
2434 (eval form))
2435 (error
2436 (unless (eq (car type) 'end-of-file)
2437 (let ((errmsg (format "Error in %s line %d" file
2438 (count-lines (point-min) (point)))))
2439 (ding)
2440 (unless (gnus-yes-or-no-p (concat errmsg "; continue? "))
2441 (error "%s" errmsg)))))))))
2442
2443 (defun gnus-read-newsrc-el-file (file)
2444 (let ((ding-file (concat file "d")))
2445 (when (file-exists-p ding-file)
2446 ;; We always, always read the .eld file.
2447 (gnus-message 5 "Reading %s..." ding-file)
2448 (let (gnus-newsrc-assoc)
2449 (gnus-load ding-file)
2450 ;; Older versions of `gnus-format-specs' are no longer valid
2451 ;; in Oort Gnus 0.01.
2452 (let ((version
2453 (and gnus-newsrc-file-version
2454 (gnus-continuum-version gnus-newsrc-file-version))))
2455 (when (or (not version)
2456 (< version 5.090009))
2457 (setq gnus-format-specs gnus-default-format-specs)))
2458 (when gnus-newsrc-assoc
2459 (setq gnus-newsrc-alist gnus-newsrc-assoc))))
2460 (dolist (elem gnus-newsrc-alist)
2461 ;; Protect against broken .newsrc.el files.
2462 (when (car elem)
2463 (setcar elem (mm-string-as-unibyte (car elem)))))
2464 (gnus-make-hashtable-from-newsrc-alist)
2465 (when (file-newer-than-file-p file ding-file)
2466 ;; Old format quick file
2467 (gnus-message 5 "Reading %s..." file)
2468 ;; The .el file is newer than the .eld file, so we read that one
2469 ;; as well.
2470 (gnus-read-old-newsrc-el-file file)))
2471 (gnus-run-hooks 'gnus-read-newsrc-el-hook))
2472
2473 ;; Parse the old-style quick startup file
2474 (defun gnus-read-old-newsrc-el-file (file)
2475 (let (newsrc killed marked group m info)
2476 (prog1
2477 (let ((gnus-killed-assoc nil)
2478 gnus-marked-assoc gnus-newsrc-alist gnus-newsrc-assoc)
2479 (prog1
2480 (ignore-errors
2481 (load file t t t))
2482 (setq newsrc gnus-newsrc-assoc
2483 killed gnus-killed-assoc
2484 marked gnus-marked-assoc)))
2485 (setq gnus-newsrc-alist nil)
2486 (while (setq group (pop newsrc))
2487 (if (setq info (gnus-get-info (car group)))
2488 (progn
2489 (gnus-info-set-read info (cddr group))
2490 (gnus-info-set-level
2491 info (if (nth 1 group) gnus-level-default-subscribed
2492 gnus-level-default-unsubscribed))
2493 (push info gnus-newsrc-alist))
2494 (push (setq info
2495 (list (car group)
2496 (if (nth 1 group) gnus-level-default-subscribed
2497 gnus-level-default-unsubscribed)
2498 (cddr group)))
2499 gnus-newsrc-alist))
2500 ;; Copy marks into info.
2501 (when (setq m (assoc (car group) marked))
2502 (unless (nthcdr 3 info)
2503 (nconc info (list nil)))
2504 (gnus-info-set-marks
2505 info (list (cons 'tick (gnus-compress-sequence
2506 (sort (cdr m) '<) t))))))
2507 (setq newsrc killed)
2508 (while newsrc
2509 (setcar newsrc (caar newsrc))
2510 (setq newsrc (cdr newsrc)))
2511 (setq gnus-killed-list killed))
2512 ;; The .el file version of this variable does not begin with
2513 ;; "options", while the .eld version does, so we just add it if it
2514 ;; isn't there.
2515 (when
2516 gnus-newsrc-options
2517 (when (not (string-match "^ *options" gnus-newsrc-options))
2518 (setq gnus-newsrc-options (concat "options " gnus-newsrc-options)))
2519 (when (not (string-match "\n$" gnus-newsrc-options))
2520 (setq gnus-newsrc-options (concat gnus-newsrc-options "\n")))
2521 ;; Finally, if we read some options lines, we parse them.
2522 (unless (string= gnus-newsrc-options "")
2523 (gnus-newsrc-parse-options gnus-newsrc-options)))
2524
2525 (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist))
2526 (gnus-make-hashtable-from-newsrc-alist)))
2527
2528 (defun gnus-make-newsrc-file (file)
2529 "Make server dependent file name by catenating FILE and server host name."
2530 (let* ((file (expand-file-name file nil))
2531 (real-file (concat file "-" (nth 1 gnus-select-method))))
2532 (if (or (file-exists-p real-file)
2533 (file-exists-p (concat real-file ".el"))
2534 (file-exists-p (concat real-file ".eld")))
2535 real-file
2536 file)))
2537
2538 (defun gnus-newsrc-to-gnus-format ()
2539 (setq gnus-newsrc-options "")
2540 (setq gnus-newsrc-options-n nil)
2541
2542 (unless gnus-active-hashtb
2543 (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
2544 (let ((buf (current-buffer))
2545 (already-read (> (length gnus-newsrc-alist) 1))
2546 group subscribed options-symbol newsrc Options-symbol
2547 symbol reads num1)
2548 (goto-char (point-min))
2549 ;; We intern the symbol `options' in the active hashtb so that we
2550 ;; can `eq' against it later.
2551 (set (setq options-symbol (intern "options" gnus-active-hashtb)) nil)
2552 (set (setq Options-symbol (intern "Options" gnus-active-hashtb)) nil)
2553
2554 (while (not (eobp))
2555 ;; We first read the first word on the line by narrowing and
2556 ;; then reading into `gnus-active-hashtb'. Most groups will
2557 ;; already exist in that hashtb, so this will save some string
2558 ;; space.
2559 (narrow-to-region
2560 (point)
2561 (progn (skip-chars-forward "^ \t!:\n") (point)))
2562 (goto-char (point-min))
2563 (setq symbol
2564 (and (/= (point-min) (point-max))
2565 (let ((obarray gnus-active-hashtb)) (read buf))))
2566 (widen)
2567 ;; Now, the symbol we have read is either `options' or a group
2568 ;; name. If it is an options line, we just add it to a string.
2569 (cond
2570 ((or (eq symbol options-symbol)
2571 (eq symbol Options-symbol))
2572 (setq gnus-newsrc-options
2573 ;; This concatting is quite inefficient, but since our
2574 ;; thorough studies show that approx 99.37% of all
2575 ;; .newsrc files only contain a single options line, we
2576 ;; don't give a damn, frankly, my dear.
2577 (concat gnus-newsrc-options
2578 (buffer-substring
2579 (point-at-bol)
2580 ;; Options may continue on the next line.
2581 (or (and (re-search-forward "^[^ \t]" nil 'move)
2582 (point-at-bol))
2583 (point)))))
2584 (forward-line -1))
2585 (symbol
2586 ;; Group names can be just numbers.
2587 (when (numberp symbol)
2588 (setq symbol (intern (int-to-string symbol) gnus-active-hashtb)))
2589 (unless (boundp symbol)
2590 (set symbol nil))
2591 ;; It was a group name.
2592 (setq subscribed (eq (char-after) ?:)
2593 group (symbol-name symbol)
2594 reads nil)
2595 (if (eolp)
2596 ;; If the line ends here, this is clearly a buggy line, so
2597 ;; we put point a the beginning of line and let the cond
2598 ;; below do the error handling.
2599 (beginning-of-line)
2600 ;; We skip to the beginning of the ranges.
2601 (skip-chars-forward "!: \t"))
2602 ;; We are now at the beginning of the list of read articles.
2603 ;; We read them range by range.
2604 (while
2605 (cond
2606 ((looking-at "[0-9]+")
2607 ;; We narrow and read a number instead of buffer-substring/
2608 ;; string-to-number because it's faster. narrow/widen is
2609 ;; faster than save-restriction/narrow, and save-restriction
2610 ;; produces a garbage object.
2611 (setq num1 (progn
2612 (narrow-to-region (match-beginning 0) (match-end 0))
2613 (read buf)))
2614 (widen)
2615 ;; If the next character is a dash, then this is a range.
2616 (if (eq (char-after) ?-)
2617 (progn
2618 ;; We read the upper bound of the range.
2619 (forward-char 1)
2620 (if (not (looking-at "[0-9]+"))
2621 ;; This is a buggy line, by we pretend that
2622 ;; it's kinda OK. Perhaps the user should be
2623 ;; dinged?
2624 (push num1 reads)
2625 (push
2626 (cons num1
2627 (progn
2628 (narrow-to-region (match-beginning 0)
2629 (match-end 0))
2630 (read buf)))
2631 reads)
2632 (widen)))
2633 ;; It was just a simple number, so we add it to the
2634 ;; list of ranges.
2635 (push num1 reads))
2636 ;; If the next char in ?\n, then we have reached the end
2637 ;; of the line and return nil.
2638 (not (eq (char-after) ?\n)))
2639 ((eq (char-after) ?\n)
2640 ;; End of line, so we end.
2641 nil)
2642 (t
2643 ;; Not numbers and not eol, so this might be a buggy
2644 ;; line...
2645 (unless (eobp)
2646 ;; If it was eob instead of ?\n, we allow it.
2647 ;; The line was buggy.
2648 (setq group nil)
2649 (gnus-error 3.1 "Mangled line: %s"
2650 (buffer-substring (point-at-bol)
2651 (point-at-eol))))
2652 nil))
2653 ;; Skip past ", ". Spaces are invalid in these ranges, but
2654 ;; we allow them, because it's a common mistake to put a
2655 ;; space after the comma.
2656 (skip-chars-forward ", "))
2657
2658 ;; We have already read .newsrc.eld, so we gently update the
2659 ;; data in the hash table with the information we have just
2660 ;; read.
2661 (when group
2662 (let ((info (gnus-get-info group))
2663 level)
2664 (if info
2665 ;; There is an entry for this file in the alist.
2666 (progn
2667 (gnus-info-set-read info (nreverse reads))
2668 ;; We update the level very gently. In fact, we
2669 ;; only change it if there's been a status change
2670 ;; from subscribed to unsubscribed, or vice versa.
2671 (setq level (gnus-info-level info))
2672 (cond ((and (<= level gnus-level-subscribed)
2673 (not subscribed))
2674 (setq level (if reads
2675 gnus-level-default-unsubscribed
2676 (1+ gnus-level-default-unsubscribed))))
2677 ((and (> level gnus-level-subscribed) subscribed)
2678 (setq level gnus-level-default-subscribed)))
2679 (gnus-info-set-level info level))
2680 ;; This is a new group.
2681 (setq info (list group
2682 (if subscribed
2683 gnus-level-default-subscribed
2684 (if reads
2685 (1+ gnus-level-subscribed)
2686 gnus-level-default-unsubscribed))
2687 (nreverse reads))))
2688 (push info newsrc)))))
2689 (forward-line 1))
2690
2691 (setq newsrc (nreverse newsrc))
2692
2693 (if (not already-read)
2694 ()
2695 ;; We now have two newsrc lists - `newsrc', which is what we
2696 ;; have read from .newsrc, and `gnus-newsrc-alist', which is
2697 ;; what we've read from .newsrc.eld. We have to merge these
2698 ;; lists. We do this by "attaching" any (foreign) groups in the
2699 ;; gnus-newsrc-alist to the (native) group that precedes them.
2700 (let ((rc (cdr gnus-newsrc-alist))
2701 (prev gnus-newsrc-alist)
2702 entry mentry)
2703 (while rc
2704 (or (null (nth 4 (car rc))) ; It's a native group.
2705 (assoc (caar rc) newsrc) ; It's already in the alist.
2706 (if (setq entry (assoc (caar prev) newsrc))
2707 (setcdr (setq mentry (memq entry newsrc))
2708 (cons (car rc) (cdr mentry)))
2709 (push (car rc) newsrc)))
2710 (setq prev rc
2711 rc (cdr rc)))))
2712
2713 (setq gnus-newsrc-alist newsrc)
2714 ;; We make the newsrc hashtb.
2715 (gnus-make-hashtable-from-newsrc-alist)
2716
2717 ;; Finally, if we read some options lines, we parse them.
2718 (unless (string= gnus-newsrc-options "")
2719 (gnus-newsrc-parse-options gnus-newsrc-options))))
2720
2721 ;; Parse options lines to find "options -n !all rec.all" and stuff.
2722 ;; The return value will be a list on the form
2723 ;; ((regexp1 . ignore)
2724 ;; (regexp2 . subscribe)...)
2725 ;; When handling new newsgroups, groups that match a `ignore' regexp
2726 ;; will be ignored, and groups that match a `subscribe' regexp will be
2727 ;; subscribed. A line like
2728 ;; options -n !all rec.all
2729 ;; will lead to a list that looks like
2730 ;; (("^rec\\..+" . subscribe)
2731 ;; ("^.+" . ignore))
2732 ;; So all "rec.*" groups will be subscribed, while all the other
2733 ;; groups will be ignored. Note that "options -n !all rec.all" is very
2734 ;; different from "options -n rec.all !all".
2735 (defun gnus-newsrc-parse-options (options)
2736 (let (out eol)
2737 (save-excursion
2738 (gnus-set-work-buffer)
2739 (insert (regexp-quote options))
2740 ;; First we treat all continuation lines.
2741 (goto-char (point-min))
2742 (while (re-search-forward "\n[ \t]+" nil t)
2743 (replace-match " " t t))
2744 ;; Then we transform all "all"s into ".+"s.
2745 (goto-char (point-min))
2746 (while (re-search-forward "\\ball\\b" nil t)
2747 (replace-match ".+" t t))
2748 (goto-char (point-min))
2749 ;; We remove all other options than the "-n" ones.
2750 (while (re-search-forward "[ \t]-[^n][^-]*" nil t)
2751 (replace-match " ")
2752 (forward-char -1))
2753 (goto-char (point-min))
2754
2755 ;; We are only interested in "options -n" lines - we
2756 ;; ignore the other option lines.
2757 (while (re-search-forward "[ \t]-n" nil t)
2758 (setq eol
2759 (or (save-excursion
2760 (and (re-search-forward "[ \t]-n" (point-at-eol) t)
2761 (- (point) 2)))
2762 (point-at-eol)))
2763 ;; Search for all "words"...
2764 (while (re-search-forward "[^ \t,\n]+" eol t)
2765 (if (eq (char-after (match-beginning 0)) ?!)
2766 ;; If the word begins with a bang (!), this is a "not"
2767 ;; spec. We put this spec (minus the bang) and the
2768 ;; symbol `ignore' into the list.
2769 (push (cons (concat
2770 "^" (buffer-substring
2771 (1+ (match-beginning 0))
2772 (match-end 0))
2773 "\\($\\|\\.\\)")
2774 'ignore)
2775 out)
2776 ;; There was no bang, so this is a "yes" spec.
2777 (push (cons (concat "^" (match-string 0) "\\($\\|\\.\\)")
2778 'subscribe)
2779 out))))
2780
2781 (setq gnus-newsrc-options-n out))))
2782
2783 (eval-and-compile
2784 (defalias 'gnus-long-file-names
2785 (if (fboundp 'msdos-long-file-names)
2786 'msdos-long-file-names
2787 (lambda () t))))
2788
2789 (defvar gnus-save-newsrc-file-last-timestamp nil)
2790 (defun gnus-save-newsrc-file (&optional force)
2791 "Save .newsrc file."
2792 ;; Note: We cannot save .newsrc file if all newsgroups are removed
2793 ;; from the variable gnus-newsrc-alist.
2794 (when (and (or gnus-newsrc-alist gnus-killed-list)
2795 gnus-current-startup-file)
2796 ;; Save agent range limits for the currently active method.
2797 (when gnus-agent
2798 (gnus-agent-save-local force))
2799
2800 (save-excursion
2801 (if (and (or gnus-use-dribble-file gnus-slave)
2802 (not force)
2803 (or (not gnus-dribble-buffer)
2804 (not (buffer-name gnus-dribble-buffer))
2805 (zerop (with-current-buffer gnus-dribble-buffer
2806 (buffer-size)))))
2807 (gnus-message 4 "(No changes need to be saved)")
2808 (gnus-run-hooks 'gnus-save-newsrc-hook)
2809 (if gnus-slave
2810 (gnus-slave-save-newsrc)
2811 ;; Save .newsrc.
2812 (when gnus-save-newsrc-file
2813 (gnus-message 8 "Saving %s..." gnus-current-startup-file)
2814 (gnus-gnus-to-newsrc-format)
2815 (gnus-message 8 "Saving %s...done" gnus-current-startup-file))
2816
2817 ;; Save .newsrc.eld.
2818 (set-buffer (gnus-get-buffer-create " *Gnus-newsrc*"))
2819 (make-local-variable 'version-control)
2820 (setq version-control gnus-backup-startup-file)
2821 (setq buffer-file-name
2822 (concat gnus-current-startup-file ".eld"))
2823 (setq default-directory (file-name-directory buffer-file-name))
2824 (buffer-disable-undo)
2825 (erase-buffer)
2826 (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file)
2827
2828 ;; check timestamp of `gnus-current-startup-file'.eld against
2829 ;; `gnus-save-newsrc-file-last-timestamp'
2830 (let* ((checkfile (concat gnus-current-startup-file ".eld"))
2831 (mtime (nth 5 (file-attributes checkfile))))
2832 (when (and gnus-save-newsrc-file-last-timestamp
2833 (time-less-p gnus-save-newsrc-file-last-timestamp
2834 mtime))
2835 (unless (y-or-n-p
2836 (format "%s was updated externally after %s, save?"
2837 checkfile
2838 (format-time-string
2839 "%c"
2840 gnus-save-newsrc-file-last-timestamp)))
2841 (error "Couldn't save %s: updated externally" checkfile))))
2842
2843 (if gnus-save-startup-file-via-temp-buffer
2844 (let ((coding-system-for-write gnus-ding-file-coding-system)
2845 (standard-output (current-buffer)))
2846 (gnus-gnus-to-quick-newsrc-format)
2847 (gnus-run-hooks 'gnus-save-quick-newsrc-hook)
2848 (save-buffer)
2849 (setq gnus-save-newsrc-file-last-timestamp
2850 (nth 5 (file-attributes buffer-file-name))))
2851 (let ((coding-system-for-write gnus-ding-file-coding-system)
2852 (version-control gnus-backup-startup-file)
2853 (startup-file (concat gnus-current-startup-file ".eld"))
2854 (working-dir (file-name-directory gnus-current-startup-file))
2855 working-file
2856 (i -1))
2857 ;; Generate the name of a non-existent file.
2858 (while (progn (setq working-file
2859 (format
2860 (if (and (eq system-type 'ms-dos)
2861 (not (gnus-long-file-names)))
2862 "%s#%d.tm#" ; MSDOS limits files to 8+3
2863 "%s#tmp#%d")
2864 working-dir (setq i (1+ i))))
2865 (file-exists-p working-file)))
2866
2867 (unwind-protect
2868 (progn
2869 (gnus-with-output-to-file working-file
2870 (gnus-gnus-to-quick-newsrc-format)
2871 (gnus-run-hooks 'gnus-save-quick-newsrc-hook))
2872
2873 ;; These bindings will mislead the current buffer
2874 ;; into thinking that it is visiting the startup
2875 ;; file.
2876 (let ((buffer-backed-up nil)
2877 (buffer-file-name startup-file)
2878 (file-precious-flag t)
2879 (setmodes (file-modes startup-file)))
2880 ;; Backup the current version of the startup file.
2881 (backup-buffer)
2882
2883 ;; Replace the existing startup file with the temp file.
2884 (rename-file working-file startup-file t)
2885 (gnus-set-file-modes startup-file setmodes)
2886 (setq gnus-save-newsrc-file-last-timestamp
2887 (nth 5 (file-attributes startup-file)))))
2888 (condition-case nil
2889 (delete-file working-file)
2890 (file-error nil)))))
2891
2892 (gnus-kill-buffer (current-buffer))
2893 (gnus-message
2894 5 "Saving %s.eld...done" gnus-current-startup-file))
2895 (gnus-dribble-delete-file)
2896 (gnus-group-set-mode-line)))))
2897
2898 (defun gnus-gnus-to-quick-newsrc-format (&optional minimal name &rest specific-variables)
2899 "Print Gnus variables such as `gnus-newsrc-alist' in Lisp format."
2900 (princ (format ";; -*- mode:emacs-lisp; coding: %s; -*-\n"
2901 gnus-ding-file-coding-system))
2902 (if name
2903 (princ (format ";; %s\n" name))
2904 (princ ";; Gnus startup file.\n"))
2905
2906 (unless minimal
2907 (princ "\
2908 ;; Never delete this file -- if you want to force Gnus to read the
2909 ;; .newsrc file (if you have one), touch .newsrc instead.\n")
2910 (princ "(setq gnus-newsrc-file-version ")
2911 (princ (gnus-prin1-to-string gnus-version))
2912 (princ ")\n"))
2913
2914 (let* ((print-quoted t)
2915 (print-readably t)
2916 (print-escape-multibyte nil)
2917 (print-escape-nonascii t)
2918 (print-length nil)
2919 (print-level nil)
2920 (print-circle nil)
2921 (print-escape-newlines t)
2922 (gnus-killed-list
2923 (if (and gnus-save-killed-list
2924 (stringp gnus-save-killed-list))
2925 (gnus-strip-killed-list)
2926 gnus-killed-list))
2927 (variables
2928 (or specific-variables
2929 (if gnus-save-killed-list gnus-variable-list
2930 ;; Remove the `gnus-killed-list' from the list of variables
2931 ;; to be saved, if required.
2932 (delq 'gnus-killed-list (copy-sequence gnus-variable-list)))))
2933 ;; Peel off the "dummy" group.
2934 (gnus-newsrc-alist (cdr gnus-newsrc-alist))
2935 variable)
2936 ;; Insert the variables into the file.
2937 (while variables
2938 (when (and (boundp (setq variable (pop variables)))
2939 (symbol-value variable))
2940 (princ "\n(setq ")
2941 (princ (symbol-name variable))
2942 (princ " '")
2943 (prin1 (symbol-value variable))
2944 (princ ")\n")))))
2945
2946 (defun gnus-strip-killed-list ()
2947 "Return the killed list minus the groups that match `gnus-save-killed-list'."
2948 (let ((list gnus-killed-list)
2949 olist)
2950 (while list
2951 (when (string-match gnus-save-killed-list (car list))
2952 (push (car list) olist))
2953 (pop list))
2954 (nreverse olist)))
2955
2956 (defun gnus-gnus-to-newsrc-format (&optional foreign-ok)
2957 (interactive (list (gnus-y-or-n-p "write foreign groups too? ")))
2958 ;; Generate and save the .newsrc file.
2959 (with-current-buffer (create-file-buffer gnus-current-startup-file)
2960 (let ((newsrc (cdr gnus-newsrc-alist))
2961 (standard-output (current-buffer))
2962 info ranges range method)
2963 (setq buffer-file-name gnus-current-startup-file)
2964 (setq default-directory (file-name-directory buffer-file-name))
2965 (buffer-disable-undo)
2966 (erase-buffer)
2967 ;; Use a unibyte buffer since group names are unibyte strings;
2968 ;; in particular, non-ASCII group names are the ones encoded by
2969 ;; a certain coding system.
2970 (mm-disable-multibyte)
2971 ;; Write options.
2972 (when gnus-newsrc-options
2973 (insert gnus-newsrc-options))
2974 ;; Write subscribed and unsubscribed.
2975 (while (setq info (pop newsrc))
2976 ;; Don't write foreign groups to .newsrc.
2977 (when (or (null (setq method (gnus-info-method info)))
2978 (equal method "native")
2979 (inline (gnus-server-equal method gnus-select-method))
2980 foreign-ok)
2981 (insert (gnus-info-group info)
2982 (if (> (gnus-info-level info) gnus-level-subscribed)
2983 "!" ":"))
2984 (when (setq ranges (gnus-info-read info))
2985 (insert " ")
2986 (if (not (listp (cdr ranges)))
2987 (if (= (car ranges) (cdr ranges))
2988 (princ (car ranges))
2989 (princ (car ranges))
2990 (insert "-")
2991 (princ (cdr ranges)))
2992 (while (setq range (pop ranges))
2993 (if (or (atom range) (= (car range) (cdr range)))
2994 (princ (or (and (atom range) range) (car range)))
2995 (princ (car range))
2996 (insert "-")
2997 (princ (cdr range)))
2998 (when ranges
2999 (insert ",")))))
3000 (insert "\n")))
3001 (make-local-variable 'version-control)
3002 (setq version-control 'never)
3003 ;; It has been reported that sometime the modtime on the .newsrc
3004 ;; file seems to be off. We really do want to overwrite it, so
3005 ;; we clear the modtime here before saving. It's a bit odd,
3006 ;; though...
3007 ;; sometimes the modtime clear isn't sufficient. most brute force:
3008 ;; delete the silly thing entirely first. but this fails to provide
3009 ;; such niceties as .newsrc~ creation.
3010 (if gnus-modtime-botch
3011 (delete-file gnus-startup-file)
3012 (clear-visited-file-modtime))
3013 (gnus-run-hooks 'gnus-save-standard-newsrc-hook)
3014 (let ((coding-system-for-write 'raw-text))
3015 (save-buffer))
3016 (kill-buffer (current-buffer)))))
3017
3018 \f
3019 ;;;
3020 ;;; Slave functions.
3021 ;;;
3022
3023 (defvar gnus-slave-mode nil)
3024
3025 (defun gnus-slave-mode ()
3026 "Minor mode for slave Gnusae."
3027 ;; FIXME: gnus-slave-mode appears to never be set (i.e. it'll always be nil):
3028 ;; Remove, or fix and use define-minor-mode.
3029 (add-minor-mode 'gnus-slave-mode " Slave" (make-sparse-keymap))
3030 (gnus-run-hooks 'gnus-slave-mode-hook))
3031
3032 (defun gnus-slave-save-newsrc ()
3033 (with-current-buffer gnus-dribble-buffer
3034 (let ((slave-name
3035 (mm-make-temp-file (concat gnus-current-startup-file "-slave-")))
3036 (modes (ignore-errors
3037 (file-modes (concat gnus-current-startup-file ".eld")))))
3038 (let ((coding-system-for-write gnus-ding-file-coding-system))
3039 (gnus-write-buffer slave-name))
3040 (when modes
3041 (gnus-set-file-modes slave-name modes)))))
3042
3043 (defun gnus-master-read-slave-newsrc ()
3044 (let ((slave-files
3045 (directory-files
3046 (file-name-directory gnus-current-startup-file)
3047 t (concat
3048 "^" (regexp-quote
3049 (concat
3050 (file-name-nondirectory gnus-current-startup-file)
3051 "-slave-")))
3052 t))
3053 file)
3054 (if (not slave-files)
3055 () ; There are no slave files to read.
3056 (gnus-message 7 "Reading slave newsrcs...")
3057 (with-current-buffer (gnus-get-buffer-create " *gnus slave*")
3058 (setq slave-files
3059 (sort (mapcar (lambda (file)
3060 (list (nth 5 (file-attributes file)) file))
3061 slave-files)
3062 (lambda (f1 f2)
3063 (or (< (caar f1) (caar f2))
3064 (< (nth 1 (car f1)) (nth 1 (car f2)))))))
3065 (while slave-files
3066 (erase-buffer)
3067 (setq file (nth 1 (car slave-files)))
3068 (nnheader-insert-file-contents file)
3069 (when (condition-case ()
3070 (progn
3071 (eval-buffer (current-buffer))
3072 t)
3073 (error
3074 (gnus-error 3.2 "Possible error in %s" file)
3075 nil))
3076 (unless gnus-slave ; Slaves shouldn't delete these files.
3077 (ignore-errors
3078 (delete-file file))))
3079 (setq slave-files (cdr slave-files))))
3080 (gnus-dribble-touch)
3081 (gnus-message 7 "Reading slave newsrcs...done"))))
3082
3083 \f
3084 ;;;
3085 ;;; Group description.
3086 ;;;
3087
3088 (defun gnus-read-all-descriptions-files ()
3089 (let ((methods (cons gnus-select-method
3090 (nconc
3091 (when (gnus-archive-server-wanted-p)
3092 (list "archive"))
3093 gnus-secondary-select-methods))))
3094 (while methods
3095 (gnus-read-descriptions-file (car methods))
3096 (setq methods (cdr methods)))
3097 t))
3098
3099 (defun gnus-read-descriptions-file (&optional method)
3100 (let ((method (or method gnus-select-method))
3101 group)
3102 (when (stringp method)
3103 (setq method (gnus-server-to-method method)))
3104 ;; We create the hashtable whether we manage to read the desc file
3105 ;; to avoid trying to re-read after a failed read.
3106 (unless gnus-description-hashtb
3107 (setq gnus-description-hashtb
3108 (gnus-make-hashtable (length gnus-active-hashtb))))
3109 ;; Mark this method's desc file as read.
3110 (gnus-sethash (gnus-group-prefixed-name "" method) "Has read"
3111 gnus-description-hashtb)
3112
3113 (gnus-message 5 "Reading descriptions file via %s..." (car method))
3114 (cond
3115 ((null (gnus-get-function method 'request-list-newsgroups t))
3116 t)
3117 ((not (gnus-check-server method))
3118 (gnus-message 1 "Couldn't open server")
3119 nil)
3120 ((not (gnus-request-list-newsgroups method))
3121 (gnus-message 1 "Couldn't read newsgroups descriptions")
3122 nil)
3123 (t
3124 (save-excursion
3125 ;; FIXME: Shouldn't save-restriction be done after set-buffer?
3126 (save-restriction
3127 (set-buffer nntp-server-buffer)
3128 (goto-char (point-min))
3129 (when (or (search-forward "\n.\n" nil t)
3130 (goto-char (point-max)))
3131 (beginning-of-line)
3132 (narrow-to-region (point-min) (point)))
3133 ;; If these are groups from a foreign select method, we insert the
3134 ;; group prefix in front of the group names.
3135 (and method (not (inline
3136 (gnus-server-equal
3137 (gnus-server-get-method nil method)
3138 (gnus-server-get-method
3139 nil gnus-select-method))))
3140 (let ((prefix (gnus-group-prefixed-name "" method)))
3141 (goto-char (point-min))
3142 (while (and (not (eobp))
3143 (progn (insert prefix)
3144 (zerop (forward-line 1)))))))
3145 (goto-char (point-min))
3146 (while (not (eobp))
3147 ;; If we get an error, we set group to 0, which is not a
3148 ;; symbol...
3149 (setq group
3150 (condition-case ()
3151 (let ((obarray gnus-description-hashtb))
3152 ;; Group is set to a symbol interned in this
3153 ;; hash table.
3154 (read nntp-server-buffer))
3155 (error 0)))
3156 (skip-chars-forward " \t")
3157 ;; ... which leads to this line being effectively ignored.
3158 (when (symbolp group)
3159 (let* ((str (buffer-substring
3160 (point) (progn (end-of-line) (point))))
3161 (name (symbol-name group))
3162 (charset
3163 (or (gnus-group-name-charset method name)
3164 (gnus-parameter-charset name)
3165 gnus-default-charset)))
3166 ;; Fixme: Don't decode in unibyte mode.
3167 (when (and str charset (featurep 'mule))
3168 (setq str (mm-decode-coding-string str charset)))
3169 (set group str)))
3170 (forward-line 1))))
3171 (gnus-message 5 "Reading descriptions file...done")
3172 t))))
3173
3174 (defun gnus-group-get-description (group)
3175 "Get the description of a group by sending XGTITLE to the server."
3176 (when (gnus-request-group-description group)
3177 (with-current-buffer nntp-server-buffer
3178 (goto-char (point-min))
3179 (when (looking-at "[^ \t]+[ \t]+\\(.*\\)")
3180 (match-string 1)))))
3181
3182 ;;;###autoload
3183 (defun gnus-declare-backend (name &rest abilities)
3184 "Declare back end NAME with ABILITIES as a Gnus back end."
3185 (setq gnus-valid-select-methods
3186 (nconc gnus-valid-select-methods
3187 (list (apply 'list name abilities))))
3188 (gnus-redefine-select-method-widget))
3189
3190 (defun gnus-set-default-directory ()
3191 "Set the default directory in the current buffer to `gnus-default-directory'.
3192 If this variable is nil, don't do anything."
3193 (setq default-directory
3194 (if (and gnus-default-directory
3195 (file-exists-p gnus-default-directory))
3196 (file-name-as-directory (expand-file-name gnus-default-directory))
3197 default-directory)))
3198
3199 (defun gnus-display-time-event-handler ()
3200 (if (and (fboundp 'display-time-event-handler)
3201 (gnus-boundp 'display-time-timer))
3202 (display-time-event-handler)))
3203
3204 (defun gnus-check-reasonable-setup ()
3205 ;; Check whether nnml and nnfolder share a directory.
3206 (let ((display-warn
3207 (if (fboundp 'display-warning)
3208 'display-warning
3209 (lambda (type message)
3210 (if noninteractive
3211 (message "Warning (%s): %s" type message)
3212 (let (window)
3213 (with-current-buffer (get-buffer-create "*Warnings*")
3214 (goto-char (point-max))
3215 (unless (bolp)
3216 (insert "\n"))
3217 (insert (format "Warning (%s): %s\n" type message))
3218 (setq window (display-buffer (current-buffer)))
3219 (set-window-start
3220 window
3221 (prog2
3222 (forward-line (- 1 (window-height window)))
3223 (point)
3224 (goto-char (point-max))))))))))
3225 method active actives match)
3226 (dolist (server gnus-server-alist)
3227 (setq method (gnus-server-to-method server)
3228 active (intern (format "%s-active-file" (car method))))
3229 (when (and (member (car method) '(nnml nnfolder))
3230 (gnus-server-opened method)
3231 (boundp active))
3232 (when (setq match (assoc (symbol-value active) actives))
3233 (funcall display-warn 'gnus-server
3234 (format "%s and %s share the same active file %s"
3235 (car method)
3236 (cadr match)
3237 (car match))))
3238 (push (list (symbol-value active) method) actives)))))
3239
3240 (provide 'gnus-start)
3241
3242 ;;; gnus-start.el ends here