]> code.delx.au - gnu-emacs/blob - lisp/gnus/gnus-start.el
Fix compilation warning in gnus-start
[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 (bury-buffer gnus-dribble-buffer)
869 (with-current-buffer gnus-group-buffer
870 (gnus-group-set-mode-line))
871 (set-buffer obuf))))
872
873 (defun gnus-dribble-touch ()
874 "Touch the dribble buffer."
875 (gnus-dribble-enter ""))
876
877 (defun gnus-dribble-read-file ()
878 "Read the dribble file from disk."
879 (let ((dribble-file (gnus-dribble-file-name)))
880 (unless (file-exists-p (file-name-directory dribble-file))
881 (make-directory (file-name-directory dribble-file) t))
882 (with-current-buffer (setq gnus-dribble-buffer
883 (gnus-get-buffer-create
884 (file-name-nondirectory dribble-file)))
885 (set (make-local-variable 'file-precious-flag) t)
886 (setq buffer-save-without-query t)
887 (erase-buffer)
888 (setq buffer-file-name dribble-file)
889 ;; The buffer may be shrunk a lot when deleting old entries.
890 ;; It caused the auto-saving to stop.
891 (if (featurep 'emacs)
892 (set (make-local-variable 'auto-save-include-big-deletions) t)
893 (set (make-local-variable 'disable-auto-save-when-buffer-shrinks) nil))
894 (auto-save-mode t)
895 (buffer-disable-undo)
896 (bury-buffer (current-buffer))
897 (set-buffer-modified-p nil)
898 (let ((auto (make-auto-save-file-name))
899 (gnus-dribble-ignore t)
900 (purpose nil)
901 modes)
902 (when (or (file-exists-p auto) (file-exists-p dribble-file))
903 ;; Load whichever file is newest -- the auto save file
904 ;; or the "real" file.
905 (if (file-newer-than-file-p auto dribble-file)
906 (nnheader-insert-file-contents auto)
907 (nnheader-insert-file-contents dribble-file))
908 (unless (zerop (buffer-size))
909 (set-buffer-modified-p t))
910 ;; Set the file modes to reflect the .newsrc file modes.
911 (save-buffer)
912 (when (and (file-exists-p gnus-current-startup-file)
913 (file-exists-p dribble-file)
914 (setq modes (file-modes gnus-current-startup-file)))
915 (gnus-set-file-modes dribble-file modes))
916 (goto-char (point-min))
917 (when (search-forward "Gnus was exited on purpose" nil t)
918 (setq purpose t))
919 ;; Possibly eval the file later.
920 (when (or gnus-always-read-dribble-file
921 (gnus-y-or-n-p
922 (if purpose
923 "Gnus exited on purpose without saving; read auto-save file anyway? "
924 "Gnus auto-save file exists. Do you want to read it? ")))
925 (setq gnus-dribble-eval-file t)))))))
926
927 (defun gnus-dribble-eval-file ()
928 (when gnus-dribble-eval-file
929 (setq gnus-dribble-eval-file nil)
930 (save-excursion
931 (let ((gnus-dribble-ignore t))
932 (set-buffer gnus-dribble-buffer)
933 (eval-buffer (current-buffer))))))
934
935 (defun gnus-dribble-delete-file ()
936 (when (file-exists-p (gnus-dribble-file-name))
937 (delete-file (gnus-dribble-file-name)))
938 (when gnus-dribble-buffer
939 (with-current-buffer gnus-dribble-buffer
940 (let ((auto (make-auto-save-file-name)))
941 (when (file-exists-p auto)
942 (delete-file auto))
943 (erase-buffer)
944 (set-buffer-modified-p nil)))))
945
946 (defun gnus-dribble-save ()
947 (when (and gnus-dribble-buffer
948 (buffer-name gnus-dribble-buffer))
949 (with-current-buffer gnus-dribble-buffer
950 (when (> (buffer-size) 0)
951 (save-buffer)))))
952
953 (defun gnus-dribble-clear ()
954 (when (gnus-buffer-exists-p gnus-dribble-buffer)
955 (with-current-buffer gnus-dribble-buffer
956 (erase-buffer)
957 (set-buffer-modified-p nil)
958 (setq buffer-saved-size (buffer-size)))))
959
960 \f
961 ;;;
962 ;;; Active & Newsrc File Handling
963 ;;;
964
965 (defun gnus-setup-news (&optional rawfile level dont-connect)
966 "Setup news information.
967 If RAWFILE is non-nil, the .newsrc file will also be read.
968 If LEVEL is non-nil, the news will be set up at level LEVEL."
969 (require 'nnmail)
970 (let ((init (not (and gnus-newsrc-alist gnus-active-hashtb (not rawfile))))
971 ;; Binding this variable will inhibit multiple fetchings
972 ;; of the same mail source.
973 (nnmail-fetched-sources (list t)))
974
975 (when init
976 ;; Clear some variables to re-initialize news information.
977 (setq gnus-newsrc-alist nil
978 gnus-active-hashtb nil)
979 ;; Read the newsrc file and create `gnus-newsrc-hashtb'.
980 (gnus-read-newsrc-file rawfile))
981
982 ;; Make sure the archive server is available to all and sundry.
983 (let ((method (or (and (stringp gnus-message-archive-method)
984 (gnus-server-to-method
985 gnus-message-archive-method))
986 gnus-message-archive-method)))
987 ;; Check whether the archive method is writable.
988 (unless (or (not method)
989 (stringp method)
990 (memq 'respool (assoc (format "%s" (car method))
991 gnus-valid-select-methods)))
992 (setq method "archive")) ;; The default.
993 (when (stringp method)
994 (setq method `(nnfolder
995 ,method
996 (nnfolder-directory
997 ,(nnheader-concat message-directory method))
998 (nnfolder-active-file
999 ,(nnheader-concat message-directory
1000 (concat method "/active")))
1001 (nnfolder-get-new-mail nil)
1002 (nnfolder-inhibit-expiry t))))
1003 (if (assoc "archive" gnus-server-alist)
1004 (when gnus-update-message-archive-method
1005 (if method
1006 (setcdr (assoc "archive" gnus-server-alist) method)
1007 (setq gnus-server-alist (delq (assoc "archive" gnus-server-alist)
1008 gnus-server-alist))))
1009 (when method
1010 (push (cons "archive" method) gnus-server-alist))))
1011
1012 ;; If we don't read the complete active file, we fill in the
1013 ;; hashtb here.
1014 (when (or (null gnus-read-active-file)
1015 (eq gnus-read-active-file 'some))
1016 (gnus-update-active-hashtb-from-killed))
1017 (unless gnus-active-hashtb
1018 (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
1019 ;; Initialize the cache.
1020 (when gnus-use-cache
1021 (gnus-cache-open))
1022
1023 ;; Possibly eval the dribble file.
1024 (and init
1025 (or gnus-use-dribble-file gnus-slave)
1026 (gnus-dribble-eval-file))
1027
1028 ;; Slave Gnusii should then clear the dribble buffer.
1029 (when (and init gnus-slave)
1030 (gnus-dribble-clear))
1031
1032 (gnus-update-format-specifications)
1033
1034 ;; See whether we need to read the description file.
1035 (when (and (boundp 'gnus-group-line-format)
1036 (stringp gnus-group-line-format)
1037 (let ((case-fold-search nil))
1038 (string-match "%[-,0-9]*D" gnus-group-line-format))
1039 (not gnus-description-hashtb)
1040 (not dont-connect)
1041 gnus-read-active-file)
1042 (gnus-read-all-descriptions-files))
1043
1044 ;; Find new newsgroups and treat them.
1045 (when (and init gnus-check-new-newsgroups (not level)
1046 (gnus-check-server gnus-select-method)
1047 (not gnus-slave)
1048 gnus-plugged)
1049 (gnus-find-new-newsgroups))
1050
1051 ;; Check and remove bogus newsgroups.
1052 (when (and init gnus-check-bogus-newsgroups
1053 gnus-read-active-file (not level)
1054 (gnus-server-opened gnus-select-method))
1055 (gnus-check-bogus-newsgroups))
1056
1057 ;; Read any slave files.
1058 (gnus-master-read-slave-newsrc)
1059
1060 ;; Find the number of unread articles in each non-dead group.
1061 (let ((gnus-read-active-file (and (not level) gnus-read-active-file)))
1062 (gnus-get-unread-articles level dont-connect))))
1063
1064 (defun gnus-call-subscribe-functions (method group)
1065 "Call METHOD to subscribe GROUP.
1066 If no function returns `non-nil', call `gnus-subscribe-zombies'."
1067 (unless (cond
1068 ((functionp method)
1069 (funcall method group))
1070 ((listp method)
1071 (catch 'found
1072 (dolist (func method)
1073 (if (funcall func group)
1074 (throw 'found t)))
1075 nil))
1076 (t nil))
1077 (gnus-subscribe-zombies group)))
1078
1079 (defun gnus-find-new-newsgroups (&optional arg)
1080 "Search for new newsgroups and add them.
1081 Each new newsgroup will be treated with `gnus-subscribe-newsgroup-method'.
1082 The `-n' option line from .newsrc is respected.
1083
1084 With 1 C-u, use the `ask-server' method to query the server for new
1085 groups.
1086 With 2 C-u's, use most complete method possible to query the server
1087 for new groups, and subscribe the new groups as zombies."
1088 (interactive "p")
1089 (let* ((gnus-subscribe-newsgroup-method
1090 gnus-subscribe-newsgroup-method)
1091 (check (cond
1092 ((or (and (= (or arg 1) 4)
1093 (not (listp gnus-check-new-newsgroups)))
1094 (null gnus-read-active-file)
1095 (eq gnus-read-active-file 'some))
1096 'ask-server)
1097 ((= (or arg 1) 16)
1098 (setq gnus-subscribe-newsgroup-method
1099 'gnus-subscribe-zombies)
1100 t)
1101 (t gnus-check-new-newsgroups))))
1102 (if (or (consp check)
1103 (eq check 'ask-server))
1104 ;; Ask the server for new groups.
1105 (gnus-ask-server-for-new-groups)
1106 ;; Go through the active hashtb and look for new groups.
1107 (let ((groups 0)
1108 group new-newsgroups)
1109 (gnus-message 5 "Looking for new newsgroups...")
1110 (unless gnus-have-read-active-file
1111 (gnus-read-active-file))
1112 (setq gnus-newsrc-last-checked-date (message-make-date))
1113 (unless gnus-killed-hashtb
1114 (gnus-make-hashtable-from-killed))
1115 ;; Go though every newsgroup in `gnus-active-hashtb' and compare
1116 ;; with `gnus-newsrc-hashtb' and `gnus-killed-hashtb'.
1117 (mapatoms
1118 (lambda (sym)
1119 (if (or (null (setq group (symbol-name sym)))
1120 (not (boundp sym))
1121 (null (symbol-value sym))
1122 (gnus-gethash group gnus-killed-hashtb)
1123 (gnus-gethash group gnus-newsrc-hashtb))
1124 ()
1125 (let ((do-sub (gnus-matches-options-n group)))
1126 (cond
1127 ((eq do-sub 'subscribe)
1128 (setq groups (1+ groups))
1129 (gnus-sethash group group gnus-killed-hashtb)
1130 (gnus-call-subscribe-functions
1131 gnus-subscribe-options-newsgroup-method group))
1132 ((eq do-sub 'ignore)
1133 nil)
1134 (t
1135 (setq groups (1+ groups))
1136 (gnus-sethash group group gnus-killed-hashtb)
1137 (if gnus-subscribe-hierarchical-interactive
1138 (push group new-newsgroups)
1139 (gnus-call-subscribe-functions
1140 gnus-subscribe-newsgroup-method group)))))))
1141 gnus-active-hashtb)
1142 (when new-newsgroups
1143 (gnus-subscribe-hierarchical-interactive new-newsgroups))
1144 (if (> groups 0)
1145 (gnus-message 5 "%d new newsgroup%s arrived."
1146 groups (if (> groups 1) "s have" " has"))
1147 (gnus-message 5 "No new newsgroups."))
1148 groups))))
1149
1150 (defun gnus-matches-options-n (group)
1151 ;; Returns `subscribe' if the group is to be unconditionally
1152 ;; subscribed, `ignore' if it is to be ignored, and nil if there is
1153 ;; no match for the group.
1154
1155 ;; First we check the two user variables.
1156 (cond
1157 ((and gnus-options-subscribe
1158 (string-match gnus-options-subscribe group))
1159 'subscribe)
1160 ((let ((do-subscribe nil))
1161 (dolist (category gnus-auto-subscribed-categories)
1162 (when (gnus-member-of-valid category group)
1163 (setq do-subscribe t)))
1164 do-subscribe)
1165 'subscribe)
1166 ((and gnus-auto-subscribed-groups
1167 (string-match gnus-auto-subscribed-groups group))
1168 'subscribe)
1169 ((and gnus-options-not-subscribe
1170 (string-match gnus-options-not-subscribe group))
1171 'ignore)
1172 ;; Then we go through the list that was retrieved from the .newsrc
1173 ;; file. This list has elements on the form
1174 ;; `(REGEXP . {ignore,subscribe})'. The first match found (the list
1175 ;; is in the reverse order of the options line) is returned.
1176 (t
1177 (let ((regs gnus-newsrc-options-n))
1178 (while (and regs
1179 (not (string-match (caar regs) group)))
1180 (setq regs (cdr regs)))
1181 (and regs (cdar regs))))))
1182
1183 (defun gnus-ask-server-for-new-groups ()
1184 (let* ((new-date (message-make-date))
1185 (date (or gnus-newsrc-last-checked-date new-date))
1186 (methods (cons gnus-select-method
1187 (nconc
1188 (when (gnus-archive-server-wanted-p)
1189 (list "archive"))
1190 (append
1191 (and (consp gnus-check-new-newsgroups)
1192 gnus-check-new-newsgroups)
1193 gnus-secondary-select-methods))))
1194 (groups 0)
1195 group new-newsgroups got-new method hashtb
1196 gnus-override-subscribe-method)
1197 (unless gnus-killed-hashtb
1198 (gnus-make-hashtable-from-killed))
1199 ;; Go through both primary and secondary select methods and
1200 ;; request new newsgroups.
1201 (while (setq method (gnus-server-get-method nil (pop methods)))
1202 (setq new-newsgroups nil
1203 gnus-override-subscribe-method method)
1204 (when (and (gnus-check-server method)
1205 (gnus-request-newgroups date method))
1206 (save-excursion
1207 (setq got-new t
1208 hashtb (gnus-make-hashtable 100))
1209 (set-buffer nntp-server-buffer)
1210 ;; Enter all the new groups into a hashtable.
1211 (gnus-active-to-gnus-format method hashtb 'ignore))
1212 ;; Now all new groups from `method' are in `hashtb'.
1213 (mapatoms
1214 (lambda (group-sym)
1215 (if (or (null (setq group (symbol-name group-sym)))
1216 (not (boundp group-sym))
1217 (null (symbol-value group-sym))
1218 (gnus-gethash group gnus-newsrc-hashtb)
1219 (member group gnus-zombie-list)
1220 (member group gnus-killed-list))
1221 ;; The group is already known.
1222 ()
1223 ;; Make this group active.
1224 (when (symbol-value group-sym)
1225 (gnus-set-active group (symbol-value group-sym)))
1226 ;; Check whether we want it or not.
1227 (let ((do-sub (gnus-matches-options-n group)))
1228 (cond
1229 ((eq do-sub 'subscribe)
1230 (incf groups)
1231 (gnus-sethash group group gnus-killed-hashtb)
1232 (gnus-call-subscribe-functions
1233 gnus-subscribe-options-newsgroup-method group))
1234 ((eq do-sub 'ignore)
1235 nil)
1236 (t
1237 (incf groups)
1238 (gnus-sethash group group gnus-killed-hashtb)
1239 (if gnus-subscribe-hierarchical-interactive
1240 (push group new-newsgroups)
1241 (gnus-call-subscribe-functions
1242 gnus-subscribe-newsgroup-method group)))))))
1243 hashtb))
1244 (when new-newsgroups
1245 (gnus-subscribe-hierarchical-interactive new-newsgroups)))
1246 (if (> groups 0)
1247 (gnus-message 5 "%d new newsgroup%s arrived"
1248 groups (if (> groups 1) "s have" " has"))
1249 (gnus-message 5 "No new newsgroups"))
1250 (when got-new
1251 (setq gnus-newsrc-last-checked-date new-date))
1252 new-newsgroups))
1253
1254 (defun gnus-subscribe-group (group &optional previous method)
1255 "Subscribe GROUP and put it after PREVIOUS."
1256 (gnus-group-change-level
1257 (if method
1258 (list t group gnus-level-default-subscribed nil nil method)
1259 group)
1260 gnus-level-default-subscribed gnus-level-killed previous t)
1261 t)
1262
1263 ;; `gnus-group-change-level' is the fundamental function for changing
1264 ;; subscription levels of newsgroups. This might mean just changing
1265 ;; from level 1 to 2, which is pretty trivial, from 2 to 6 or back
1266 ;; again, which subscribes/unsubscribes a group, which is equally
1267 ;; trivial. Changing from 1-7 to 8-9 means that you kill a group, and
1268 ;; from 8-9 to 1-7 means that you remove the group from the list of
1269 ;; killed (or zombie) groups and add them to the (kinda) subscribed
1270 ;; groups. And last but not least, moving from 8 to 9 and 9 to 8,
1271 ;; which is trivial.
1272 ;; ENTRY can either be a string (newsgroup name) or a list (if
1273 ;; FROMKILLED is t, it's a list on the format (NUM INFO-LIST),
1274 ;; otherwise it's a list in the format of the `gnus-newsrc-hashtb'
1275 ;; entries.
1276 ;; LEVEL is the new level of the group, OLDLEVEL is the old level and
1277 ;; PREVIOUS is the group (in hashtb entry format) to insert this group
1278 ;; after.
1279 (defun gnus-group-change-level (entry level &optional oldlevel
1280 previous fromkilled)
1281 (let (group info active num)
1282 ;; Glean what info we can from the arguments
1283 (if (consp entry)
1284 (if fromkilled (setq group (nth 1 entry))
1285 (setq group (car (nth 2 entry))))
1286 (setq group entry))
1287 (when (and (stringp entry)
1288 oldlevel
1289 (< oldlevel gnus-level-zombie))
1290 (setq entry (gnus-group-entry entry)))
1291 (if (and (not oldlevel)
1292 (consp entry))
1293 (setq oldlevel (gnus-info-level (nth 2 entry)))
1294 (setq oldlevel (or oldlevel gnus-level-killed)))
1295 (when (stringp previous)
1296 (setq previous (gnus-group-entry previous)))
1297
1298 (if (and (>= oldlevel gnus-level-zombie)
1299 (gnus-group-entry group))
1300 ;; We are trying to subscribe a group that is already
1301 ;; subscribed.
1302 () ; Do nothing.
1303
1304 (unless (gnus-ephemeral-group-p group)
1305 (gnus-dribble-enter
1306 (format "(gnus-group-change-level %S %S %S %S %S)"
1307 group level oldlevel (car (nth 2 previous)) fromkilled)))
1308
1309 ;; Then we remove the newgroup from any old structures, if needed.
1310 ;; If the group was killed, we remove it from the killed or zombie
1311 ;; list. If not, and it is in fact going to be killed, we remove
1312 ;; it from the newsrc hash table and assoc.
1313 (cond
1314 ((>= oldlevel gnus-level-zombie)
1315 ;; oldlevel could be wrong.
1316 (setq gnus-zombie-list (delete group gnus-zombie-list))
1317 (setq gnus-killed-list (delete group gnus-killed-list)))
1318 (t
1319 (when (and (>= level gnus-level-zombie)
1320 entry)
1321 (gnus-sethash (car (nth 2 entry)) nil gnus-newsrc-hashtb)
1322 (when (nth 3 entry)
1323 (setcdr (gnus-group-entry (car (nth 3 entry)))
1324 (cdr entry)))
1325 (setcdr (cdr entry) (cdddr entry)))))
1326
1327 ;; Finally we enter (if needed) the list where it is supposed to
1328 ;; go, and change the subscription level. If it is to be killed,
1329 ;; we enter it into the killed or zombie list.
1330 (cond
1331 ((>= level gnus-level-zombie)
1332 ;; Remove from the hash table.
1333 (gnus-sethash group nil gnus-newsrc-hashtb)
1334 (if (= level gnus-level-zombie)
1335 (push group gnus-zombie-list)
1336 (if (= oldlevel gnus-level-killed)
1337 ;; Remove from active hashtb.
1338 (unintern group gnus-active-hashtb)
1339 ;; Don't add it into killed-list if it was killed.
1340 (push group gnus-killed-list))))
1341 (t
1342 ;; If the list is to be entered into the newsrc assoc, and
1343 ;; it was killed, we have to create an entry in the newsrc
1344 ;; hashtb format and fix the pointers in the newsrc assoc.
1345 (if (< oldlevel gnus-level-zombie)
1346 ;; It was alive, and it is going to stay alive, so we
1347 ;; just change the level and don't change any pointers or
1348 ;; hash table entries.
1349 (setcar (cdaddr entry) level)
1350 (if (listp entry)
1351 (setq info (cdr entry)
1352 num (car entry))
1353 (setq active (gnus-active group))
1354 (setq num
1355 (if active (- (1+ (cdr active)) (car active)) t))
1356 ;; Shorten the select method if possible, if we need to
1357 ;; store it at all (native groups).
1358 (let ((method (gnus-method-simplify
1359 (or gnus-override-subscribe-method
1360 (gnus-group-method group)))))
1361 (if method
1362 (setq info (list group level nil nil method))
1363 (setq info (list group level nil)))))
1364 (unless previous
1365 (setq previous
1366 (let ((p gnus-newsrc-alist))
1367 (while (cddr p)
1368 (setq p (cdr p)))
1369 p)))
1370 (setq entry (cons info (cddr previous)))
1371 (if (cdr previous)
1372 (progn
1373 (setcdr (cdr previous) entry)
1374 (gnus-sethash group (cons num (cdr previous))
1375 gnus-newsrc-hashtb))
1376 (setcdr previous entry)
1377 (gnus-sethash group (cons num previous)
1378 gnus-newsrc-hashtb))
1379 (when (cdr entry)
1380 (setcdr (gnus-group-entry (caadr entry)) entry))
1381 (gnus-dribble-enter
1382 (format "(gnus-group-set-info '%S)" info)
1383 (concat "^(gnus-group-set-info '(\"" (regexp-quote group) "\"")))))
1384 (when gnus-group-change-level-function
1385 (funcall gnus-group-change-level-function
1386 group level oldlevel previous)))))
1387
1388 (defun gnus-check-bogus-newsgroups (&optional confirm)
1389 "Remove bogus newsgroups.
1390 If CONFIRM is non-nil, the user has to confirm the deletion of every
1391 newsgroup."
1392 (let ((newsrc (cdr gnus-newsrc-alist))
1393 bogus group entry info)
1394 (gnus-message 5 "Checking bogus newsgroups...")
1395 (unless (gnus-read-active-file-p)
1396 (gnus-read-active-file t))
1397 (when (gnus-read-active-file-p)
1398 ;; Find all bogus newsgroup that are subscribed.
1399 (while newsrc
1400 (setq info (pop newsrc)
1401 group (gnus-info-group info))
1402 (unless (or (gnus-active group) ; Active
1403 (and (gnus-info-method info)
1404 (not (gnus-secondary-method-p
1405 (gnus-info-method info))))) ; Foreign
1406 ;; Found a bogus newsgroup.
1407 (push group bogus)))
1408 (if confirm
1409 (map-y-or-n-p
1410 (format "Remove bogus group %%s (of %d groups)? " (length bogus))
1411 (lambda (group)
1412 ;; Remove all bogus subscribed groups by first killing them, and
1413 ;; then removing them from the list of killed groups.
1414 (when (setq entry (gnus-group-entry group))
1415 (gnus-group-change-level entry gnus-level-killed)
1416 (setq gnus-killed-list (delete group gnus-killed-list))))
1417 bogus '("group" "groups" "remove"))
1418 (while (setq group (pop bogus))
1419 ;; Remove all bogus subscribed groups by first killing them, and
1420 ;; then removing them from the list of killed groups.
1421 (when (setq entry (gnus-group-entry group))
1422 (gnus-group-change-level entry gnus-level-killed)
1423 (setq gnus-killed-list (delete group gnus-killed-list)))))
1424 ;; Then we remove all bogus groups from the list of killed and
1425 ;; zombie groups. They are removed without confirmation.
1426 (let ((dead-lists '(gnus-killed-list gnus-zombie-list))
1427 killed)
1428 (while dead-lists
1429 (setq killed (symbol-value (car dead-lists)))
1430 (while killed
1431 (unless (gnus-active (setq group (pop killed)))
1432 ;; The group is bogus.
1433 ;; !!!Slow as hell.
1434 (set (car dead-lists)
1435 (delete group (symbol-value (car dead-lists))))))
1436 (setq dead-lists (cdr dead-lists))))
1437 (gnus-run-hooks 'gnus-check-bogus-groups-hook)
1438 (gnus-message 5 "Checking bogus newsgroups...done"))))
1439
1440 (defun gnus-check-duplicate-killed-groups ()
1441 "Remove duplicates from the list of killed groups."
1442 (interactive)
1443 (let ((killed gnus-killed-list))
1444 (while killed
1445 (gnus-message 9 "%d" (length killed))
1446 (setcdr killed (delete (car killed) (cdr killed)))
1447 (setq killed (cdr killed)))))
1448
1449 ;; We want to inline a function from gnus-cache, so we cheat here:
1450 (defvar gnus-cache-active-hashtb)
1451 (eval-when-compile
1452 (defun gnus-cache-possibly-alter-active (group active)
1453 "Alter the ACTIVE info for GROUP to reflect the articles in the cache."
1454 (when gnus-cache-active-hashtb
1455 (let ((cache-active (gnus-gethash group gnus-cache-active-hashtb)))
1456 (when cache-active
1457 (when (< (car cache-active) (car active))
1458 (setcar active (car cache-active)))
1459 (when (> (cdr cache-active) (cdr active))
1460 (setcdr active (cdr cache-active))))))))
1461
1462 (defun gnus-activate-group (group &optional scan dont-check method
1463 dont-sub-check)
1464 "Check whether a group has been activated or not.
1465 If SCAN, request a scan of that group as well. If METHOD, use
1466 that select method instead of determining the method based on the
1467 group name. If DONT-CHECK, don't check whether the group
1468 actually exists. If DONT-SUB-CHECK or DONT-CHECK, don't let the
1469 backend check whether the group actually exists."
1470 (let ((method (or method (inline (gnus-find-method-for-group group))))
1471 active)
1472 (and (inline (gnus-check-server method))
1473 ;; We escape all bugs and quit here to make it possible to
1474 ;; continue if a group is so out-there that it reports bugs
1475 ;; and stuff.
1476 (progn
1477 (and scan
1478 (gnus-check-backend-function 'request-scan (car method))
1479 (gnus-request-scan group method))
1480 t)
1481 (if (or debug-on-error debug-on-quit)
1482 (inline (gnus-request-group group (or dont-sub-check dont-check)
1483 method
1484 (gnus-get-info group)))
1485 (condition-case nil
1486 (inline (gnus-request-group group (or dont-sub-check dont-check)
1487 method
1488 (gnus-get-info group)))
1489 (quit
1490 (if debug-on-quit
1491 (debug "Quit")
1492 (message "Quit activating %s" group))
1493 nil)))
1494 (unless dont-check
1495 (setq active (gnus-parse-active))
1496 ;; If there are no articles in the group, the GROUP
1497 ;; command may have responded with the `(0 . 0)'. We
1498 ;; ignore this if we already have an active entry
1499 ;; for the group.
1500 (if (and (zerop (or (car active) 0))
1501 (zerop (or (cdr active) 0))
1502 (gnus-active group))
1503 (gnus-active group)
1504
1505 ;; If a cache is present, we may have to alter the active info.
1506 (when gnus-use-cache
1507 (inline (gnus-cache-possibly-alter-active
1508 group active)))
1509
1510 ;; If the agent is enabled, we may have to alter the active info.
1511 (when gnus-agent
1512 (gnus-agent-possibly-alter-active group active))
1513
1514 (gnus-set-active group active)
1515 ;; Return the new active info.
1516 active)))))
1517
1518 (defun gnus-get-unread-articles-in-group (info active &optional update)
1519 (when (and info active)
1520 ;; Allow the backend to update the info in the group.
1521 (when (and update
1522 (gnus-request-update-info
1523 info (inline (gnus-find-method-for-group
1524 (gnus-info-group info)))))
1525 (gnus-activate-group (gnus-info-group info) nil t))
1526
1527 (let* ((range (gnus-info-read info))
1528 (num 0))
1529
1530 ;; These checks are present in gnus-activate-group but skipped
1531 ;; due to setting dont-check in the preceding call.
1532
1533 ;; If a cache is present, we may have to alter the active info.
1534 (when (and gnus-use-cache info)
1535 (inline (gnus-cache-possibly-alter-active
1536 (gnus-info-group info) active)))
1537
1538 ;; If the agent is enabled, we may have to alter the active info.
1539 (when (and gnus-agent info)
1540 (gnus-agent-possibly-alter-active (gnus-info-group info) active info))
1541
1542 ;; Modify the list of read articles according to what articles
1543 ;; are available; then tally the unread articles and add the
1544 ;; number to the group hash table entry.
1545 (cond
1546 ((zerop (cdr active))
1547 (setq num 0))
1548 ((not range)
1549 (setq num (- (1+ (cdr active)) (car active))))
1550 ((not (listp (cdr range)))
1551 ;; Fix a single (num . num) range according to the
1552 ;; active hash table.
1553 ;; Fix by Carsten Bormann <cabo@Informatik.Uni-Bremen.DE>.
1554 (and (< (cdr range) (car active)) (setcdr range (1- (car active))))
1555 (and (> (cdr range) (cdr active)) (setcdr range (cdr active)))
1556 ;; Compute number of unread articles.
1557 (setq num (max 0 (- (cdr active) (- (1+ (cdr range)) (car range))))))
1558 (t
1559 ;; The read list is a list of ranges. Fix them according to
1560 ;; the active hash table.
1561 ;; First peel off any elements that are below the lower
1562 ;; active limit.
1563 (while (and (cdr range)
1564 (>= (car active)
1565 (or (and (atom (cadr range)) (cadr range))
1566 (caadr range))))
1567 (if (numberp (car range))
1568 (setcar range
1569 (cons (car range)
1570 (or (and (numberp (cadr range))
1571 (cadr range))
1572 (cdadr range))))
1573 (setcdr (car range)
1574 (or (and (numberp (nth 1 range)) (nth 1 range))
1575 (cdadr range))))
1576 (setcdr range (cddr range)))
1577 ;; Adjust the first element to be the same as the lower limit.
1578 (when (and (not (atom (car range)))
1579 (< (cdar range) (car active)))
1580 (setcdr (car range) (1- (car active))))
1581 ;; Then we want to peel off any elements that are higher
1582 ;; than the upper active limit.
1583 (let ((srange range))
1584 ;; Go past all valid elements.
1585 (while (and (cdr srange)
1586 (<= (or (and (atom (cadr srange))
1587 (cadr srange))
1588 (caadr srange))
1589 (cdr active)))
1590 (setq srange (cdr srange)))
1591 (when (cdr srange)
1592 ;; Nuke all remaining invalid elements.
1593 (setcdr srange nil))
1594
1595 ;; Adjust the final element.
1596 (when (and (not (atom (car srange)))
1597 (> (cdar srange) (cdr active)))
1598 (setcdr (car srange) (cdr active))))
1599 ;; Compute the number of unread articles.
1600 (while range
1601 (setq num (+ num (- (1+ (or (and (atom (car range)) (car range))
1602 (cdar range)))
1603 (or (and (atom (car range)) (car range))
1604 (caar range)))))
1605 (setq range (cdr range)))
1606 (setq num (max 0 (- (cdr active) num)))))
1607 ;; Set the number of unread articles.
1608 (when (and info
1609 (gnus-group-entry (gnus-info-group info)))
1610 (setcar (gnus-group-entry (gnus-info-group info)) num))
1611 num)))
1612
1613 ;; Go though `gnus-newsrc-alist' and compare with `gnus-active-hashtb'
1614 ;; and compute how many unread articles there are in each group.
1615 (defun gnus-get-unread-articles (&optional level dont-connect one-level)
1616 (setq gnus-server-method-cache nil)
1617 (require 'gnus-agent)
1618 (let* ((newsrc (cdr gnus-newsrc-alist))
1619 (alevel (or level gnus-activate-level (1+ gnus-level-subscribed)))
1620 (foreign-level
1621 (or
1622 level
1623 (min
1624 (cond ((and gnus-activate-foreign-newsgroups
1625 (not (numberp gnus-activate-foreign-newsgroups)))
1626 (1+ gnus-level-subscribed))
1627 ((numberp gnus-activate-foreign-newsgroups)
1628 gnus-activate-foreign-newsgroups)
1629 (t 0))
1630 alevel)))
1631 (methods-cache nil)
1632 (type-cache nil)
1633 (gnus-agent-article-local-times 0)
1634 (archive-method (gnus-server-to-method "archive"))
1635 infos info group active method cmethod
1636 method-type method-group-list entry)
1637 (gnus-message 6 "Checking new news...")
1638
1639 (while newsrc
1640 (setq active (gnus-active (setq group (gnus-info-group
1641 (setq info (pop newsrc))))))
1642 ;; First go through all the groups, see what select methods they
1643 ;; belong to, and then collect them into lists per unique select
1644 ;; method.
1645 (if (not (setq method (gnus-info-method info)))
1646 (setq method gnus-select-method)
1647 ;; There may be several similar methods. Possibly extend the
1648 ;; method.
1649 (if (setq cmethod (assoc method methods-cache))
1650 (setq method (cdr cmethod))
1651 (setq cmethod (if (stringp method)
1652 (gnus-server-to-method method)
1653 (inline (gnus-find-method-for-group
1654 (gnus-info-group info) info))))
1655 (push (cons method cmethod) methods-cache)
1656 (setq method cmethod)))
1657 (setq method-group-list (assoc method type-cache))
1658 (unless method-group-list
1659 (setq method-type
1660 (cond
1661 ((or (gnus-secondary-method-p method)
1662 (and (gnus-archive-server-wanted-p)
1663 (gnus-methods-equal-p archive-method method)))
1664 'secondary)
1665 ((inline (gnus-server-equal gnus-select-method method))
1666 'primary)
1667 (t
1668 'foreign)))
1669 (push (setq method-group-list (list method method-type nil nil))
1670 type-cache))
1671 ;; Only add groups that need updating.
1672 (if (or (and foreign-level (null (numberp foreign-level)))
1673 (funcall (if one-level #'= #'<=) (gnus-info-level info)
1674 (if (eq (cadr method-group-list) 'foreign)
1675 foreign-level
1676 alevel)))
1677 (setcar (nthcdr 2 method-group-list)
1678 (cons info (nth 2 method-group-list)))
1679 ;; The group is inactive, so we nix out the number of unread articles.
1680 ;; It leads `(gnus-group-unread group)' to return t. See also
1681 ;; `gnus-group-prepare-flat'.
1682 (unless active
1683 (when (setq entry (gnus-group-entry group))
1684 (setcar entry t)))))
1685
1686 ;; Sort the methods based so that the primary and secondary
1687 ;; methods come first. This is done for legacy reasons to try to
1688 ;; ensure that side-effect behavior doesn't change from previous
1689 ;; Gnus versions.
1690 (setq type-cache
1691 (sort (nreverse type-cache)
1692 (lambda (c1 c2)
1693 (< (gnus-method-rank (cadr c1) (car c1))
1694 (gnus-method-rank (cadr c2) (car c2))))))
1695 ;; Go through the list of servers and possibly extend methods that
1696 ;; aren't equal (and that need extension; i.e., they are async).
1697 (let ((methods nil))
1698 (dolist (elem type-cache)
1699 (destructuring-bind (method method-type infos dummy) elem
1700 (let ((gnus-opened-servers methods))
1701 (when (and (gnus-similar-server-opened method)
1702 (gnus-check-backend-function
1703 'retrieve-group-data-early (car method)))
1704 (setq method (gnus-server-extend-method
1705 (gnus-info-group (car infos))
1706 method))
1707 (setcar elem method))
1708 (push (list method 'ok) methods)))))
1709
1710 ;; If we have primary/secondary select methods, but no groups from
1711 ;; them, we still want to issue a retrieval request from them.
1712 (unless dont-connect
1713 (dolist (method (cons gnus-select-method
1714 gnus-secondary-select-methods))
1715 (when (and (not (assoc method type-cache))
1716 (gnus-check-backend-function 'request-list (car method)))
1717 (with-current-buffer nntp-server-buffer
1718 (gnus-read-active-file-1 method nil)))))
1719
1720 ;; Clear out all the early methods.
1721 (dolist (elem type-cache)
1722 (destructuring-bind (method method-type infos dummy) elem
1723 (when (and method
1724 infos
1725 (gnus-check-backend-function
1726 'retrieve-group-data-early (car method))
1727 (not (gnus-method-denied-p method)))
1728 (when (ignore-errors (gnus-get-function method 'open-server))
1729 (unless (gnus-server-opened method)
1730 (gnus-open-server method))
1731 (when (gnus-server-opened method)
1732 ;; Just mark this server as "cleared".
1733 (gnus-retrieve-group-data-early method nil))))))
1734
1735 ;; Start early async retrieval of data.
1736 (let ((done-methods nil)
1737 sanity-spec)
1738 (dolist (elem type-cache)
1739 (destructuring-bind (method method-type infos dummy) elem
1740 (setq sanity-spec (list (car method) (cadr method)))
1741 (when (and method infos
1742 (not (gnus-method-denied-p method)))
1743 ;; If the open-server method doesn't exist, then the method
1744 ;; itself doesn't exist, so we ignore it.
1745 (if (not (ignore-errors (gnus-get-function method 'open-server)))
1746 (setq type-cache (delq elem type-cache))
1747 (unless (gnus-server-opened method)
1748 (gnus-open-server method))
1749 (when (and
1750 ;; This is a sanity check, so that we never
1751 ;; attempt to start two async requests to the
1752 ;; same server, because that will fail. This
1753 ;; should never happen, since the methods should
1754 ;; be unique at this point, but apparently it
1755 ;; does happen in the wild with some setups.
1756 (not (member sanity-spec done-methods))
1757 (gnus-server-opened method)
1758 (gnus-check-backend-function
1759 'retrieve-group-data-early (car method)))
1760 (push sanity-spec done-methods)
1761 (when (gnus-check-backend-function 'request-scan (car method))
1762 (gnus-request-scan nil method))
1763 ;; Store the token we get back from -early so that we
1764 ;; can pass it to -finish later.
1765 (setcar (nthcdr 3 elem)
1766 (gnus-retrieve-group-data-early method infos))))))))
1767
1768 ;; Do the rest of the retrieval.
1769 (dolist (elem type-cache)
1770 (destructuring-bind (method method-type infos early-data) elem
1771 (when (and method infos
1772 (not (gnus-method-denied-p method)))
1773 (let ((updatep (gnus-check-backend-function
1774 'request-update-info (car method))))
1775 ;; See if any of the groups from this method require updating.
1776 (gnus-read-active-for-groups method infos early-data)
1777 (dolist (info infos)
1778 (inline (gnus-get-unread-articles-in-group
1779 info (gnus-active (gnus-info-group info))
1780 updatep)))))))
1781 (gnus-message 6 "Checking new news...done")))
1782
1783 (defun gnus-method-rank (type method)
1784 (cond
1785 ;; Get info for virtual groups last.
1786 ((eq (car method) 'nnvirtual)
1787 200)
1788 ((eq type 'primary)
1789 1)
1790 ;; Compute the rank of the secondary methods based on where they
1791 ;; are in the secondary select list.
1792 ((eq type 'secondary)
1793 (let ((i 2))
1794 (block nil
1795 (dolist (smethod gnus-secondary-select-methods)
1796 (when (equal method smethod)
1797 (return i))
1798 (incf i))
1799 i)))
1800 ;; Just say that all foreign groups have the same rank.
1801 (t
1802 100)))
1803
1804 (defun gnus-read-active-for-groups (method infos early-data)
1805 (with-current-buffer nntp-server-buffer
1806 (cond
1807 ;; Finish up getting the data from the methods that have -early
1808 ;; methods.
1809 ((and
1810 early-data
1811 (gnus-check-backend-function 'finish-retrieve-group-infos (car method))
1812 (or (not (gnus-agent-method-p method))
1813 (gnus-online method)))
1814 (gnus-finish-retrieve-group-infos method infos early-data)
1815 ;; We may have altered the data now, so mark the dribble buffer
1816 ;; as dirty so that it gets saved.
1817 (gnus-dribble-touch)
1818 (gnus-agent-save-active method))
1819 ;; Most backends have -retrieve-groups.
1820 ((gnus-check-backend-function 'retrieve-groups (car method))
1821 (when (gnus-check-backend-function 'request-scan (car method))
1822 (gnus-request-scan nil method))
1823 (let (groups)
1824 (gnus-read-active-file-2
1825 (dolist (info infos (nreverse groups))
1826 (push (gnus-group-real-name (gnus-info-group info)) groups))
1827 method)))
1828 ;; Virtually all backends have -request-list.
1829 ((gnus-check-backend-function 'request-list (car method))
1830 (gnus-read-active-file-1 method nil))
1831 ;; Except nnvirtual and friends, where we request each group, one
1832 ;; by one.
1833 (t
1834 (dolist (info infos)
1835 (gnus-activate-group (gnus-info-group info) nil nil method t))))))
1836
1837 ;; Create a hash table out of the newsrc alist. The `car's of the
1838 ;; alist elements are used as keys.
1839 (defun gnus-make-hashtable-from-newsrc-alist ()
1840 (let ((alist gnus-newsrc-alist)
1841 (ohashtb gnus-newsrc-hashtb)
1842 prev info method rest methods)
1843 (setq gnus-newsrc-hashtb (gnus-make-hashtable (length alist)))
1844 (setq alist
1845 (setq prev (setq gnus-newsrc-alist
1846 (if (equal (caar gnus-newsrc-alist)
1847 "dummy.group")
1848 gnus-newsrc-alist
1849 (cons (list "dummy.group" 0 nil) alist)))))
1850 (while alist
1851 (setq info (car alist))
1852 ;; Make the same select-methods identical Lisp objects.
1853 (when (setq method (gnus-info-method info))
1854 (if (setq rest (member method methods))
1855 (gnus-info-set-method info (car rest))
1856 (push method methods)))
1857 ;; Check for duplicates.
1858 (if (gnus-gethash (car info) gnus-newsrc-hashtb)
1859 ;; Remove this entry from the alist.
1860 (setcdr prev (cddr prev))
1861 (gnus-sethash
1862 (car info)
1863 ;; Preserve number of unread articles in groups.
1864 (cons (and ohashtb (car (gnus-gethash (car info) ohashtb)))
1865 prev)
1866 gnus-newsrc-hashtb)
1867 (setq prev alist))
1868 (setq alist (cdr alist)))
1869 ;; Make the same select-methods in `gnus-server-alist' identical
1870 ;; as well.
1871 (while methods
1872 (setq method (pop methods))
1873 (when (setq rest (rassoc method gnus-server-alist))
1874 (setcdr rest method)))))
1875
1876 (defun gnus-make-hashtable-from-killed ()
1877 "Create a hash table from the killed and zombie lists."
1878 (let ((lists '(gnus-killed-list gnus-zombie-list))
1879 list)
1880 (setq gnus-killed-hashtb
1881 (gnus-make-hashtable
1882 (+ (length gnus-killed-list) (length gnus-zombie-list))))
1883 (while lists
1884 (setq list (symbol-value (pop lists)))
1885 (while list
1886 (gnus-sethash (car list) (pop list) gnus-killed-hashtb)))))
1887
1888 (defun gnus-parse-active ()
1889 "Parse active info in the nntp server buffer."
1890 (with-current-buffer nntp-server-buffer
1891 (goto-char (point-min))
1892 ;; Parse the result we got from `gnus-request-group'.
1893 (when (looking-at "[0-9]+ [0-9]+ \\([0-9]+\\) [0-9]+")
1894 (goto-char (match-beginning 1))
1895 (cons (read (current-buffer))
1896 (read (current-buffer))))))
1897
1898 (defun gnus-make-articles-unread (group articles)
1899 "Mark ARTICLES in GROUP as unread."
1900 (let* ((info (nth 2 (or (gnus-group-entry group)
1901 (gnus-group-entry
1902 (gnus-group-real-name group)))))
1903 (ranges (gnus-info-read info))
1904 news article)
1905 (while articles
1906 (when (gnus-member-of-range
1907 (setq article (pop articles)) ranges)
1908 (push article news)))
1909 (when news
1910 ;; Enter this list into the group info.
1911 (gnus-info-set-read
1912 info (gnus-remove-from-range (gnus-info-read info) (nreverse news)))
1913
1914 ;; Set the number of unread articles in gnus-newsrc-hashtb.
1915 (gnus-get-unread-articles-in-group info (gnus-active group))
1916
1917 ;; Insert the change into the group buffer and the dribble file.
1918 (gnus-group-update-group group t))))
1919
1920 (defun gnus-make-ascending-articles-unread (group articles)
1921 "Mark ascending ARTICLES in GROUP as unread."
1922 (let* ((entry (or (gnus-group-entry group)
1923 (gnus-group-entry (gnus-group-real-name group))))
1924 (info (nth 2 entry))
1925 (ranges (gnus-info-read info))
1926 (r ranges)
1927 modified)
1928
1929 (while articles
1930 (let ((article (pop articles))) ; get the next article to remove from ranges
1931 (while (let ((range (car ranges))) ; note the current range
1932 (if (atom range) ; single value range
1933 (cond ((not range)
1934 ;; the articles extend past the end of the ranges
1935 ;; OK - I'm done
1936 (setq articles nil))
1937 ((< range article)
1938 ;; this range precedes the article. Leave the range unmodified.
1939 (pop ranges)
1940 ranges)
1941 ((= range article)
1942 ;; this range exactly matches the article; REMOVE THE RANGE.
1943 ;; NOTE: When the range being removed is the last range, the list is corrupted by inserting null at its end.
1944 (setcar ranges (cadr ranges))
1945 (setcdr ranges (cddr ranges))
1946 (setq modified (if (car ranges) t 'remove-null))
1947 nil))
1948 (let ((min (car range))
1949 (max (cdr range)))
1950 ;; I have a min/max range to consider
1951 (cond ((> min max) ; invalid range introduced by splitter
1952 (setcar ranges (cadr ranges))
1953 (setcdr ranges (cddr ranges))
1954 (setq modified (if (car ranges) t 'remove-null))
1955 ranges)
1956 ((= min max)
1957 ;; replace min/max range with a single-value range
1958 (setcar ranges min)
1959 ranges)
1960 ((< max article)
1961 ;; this range precedes the article. Leave the range unmodified.
1962 (pop ranges)
1963 ranges)
1964 ((< article min)
1965 ;; this article precedes the range. Return null to move to the
1966 ;; next article
1967 nil)
1968 (t
1969 ;; this article splits the range into two parts
1970 (setcdr ranges (cons (cons (1+ article) max) (cdr ranges)))
1971 (setcdr range (1- article))
1972 (setq modified t)
1973 ranges))))))))
1974
1975 (when modified
1976 (when (eq modified 'remove-null)
1977 (setq r (delq nil r)))
1978 ;; Enter this list into the group info.
1979 (gnus-info-set-read info r)
1980
1981 ;; Set the number of unread articles in gnus-newsrc-hashtb.
1982 (gnus-get-unread-articles-in-group info (gnus-active group))
1983
1984 ;; Insert the change into the group buffer and the dribble file.
1985 (gnus-group-update-group group t))))
1986
1987 ;; Enter all dead groups into the hashtb.
1988 (defun gnus-update-active-hashtb-from-killed ()
1989 (let ((hashtb (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
1990 (lists (list gnus-killed-list gnus-zombie-list))
1991 killed)
1992 (while lists
1993 (setq killed (car lists))
1994 (while killed
1995 (gnus-sethash (string-as-unibyte (car killed)) nil hashtb)
1996 (setq killed (cdr killed)))
1997 (setq lists (cdr lists)))))
1998
1999 (defun gnus-get-killed-groups ()
2000 "Go through the active hashtb and mark all unknown groups as killed."
2001 ;; First make sure active file has been read.
2002 (unless (gnus-read-active-file-p)
2003 (let ((gnus-read-active-file t))
2004 (gnus-read-active-file)))
2005 (unless gnus-killed-hashtb
2006 (gnus-make-hashtable-from-killed))
2007 ;; Go through all newsgroups that are known to Gnus - enlarge kill list.
2008 (mapatoms
2009 (lambda (sym)
2010 (let ((groups 0)
2011 (group (symbol-name sym)))
2012 (if (or (null group)
2013 (gnus-gethash group gnus-killed-hashtb)
2014 (gnus-gethash group gnus-newsrc-hashtb))
2015 ()
2016 (let ((do-sub (gnus-matches-options-n group)))
2017 (if (or (eq do-sub 'subscribe) (eq do-sub 'ignore))
2018 ()
2019 (setq groups (1+ groups))
2020 (push group gnus-killed-list)
2021 (gnus-sethash group group gnus-killed-hashtb))))))
2022 gnus-active-hashtb)
2023 (gnus-dribble-touch))
2024
2025 ;; Get the active file(s) from the backend(s).
2026 (defun gnus-read-active-file (&optional force not-native)
2027 (gnus-group-set-mode-line)
2028 (let ((methods
2029 (mapcar
2030 (lambda (m) (if (stringp m) (gnus-server-get-method nil m) m))
2031 (append
2032 (if (and (not not-native)
2033 (gnus-check-server gnus-select-method))
2034 ;; The native server is available.
2035 (cons gnus-select-method gnus-secondary-select-methods)
2036 ;; The native server is down, so we just do the
2037 ;; secondary ones.
2038 gnus-secondary-select-methods)
2039 ;; Also read from the archive server.
2040 (when (gnus-archive-server-wanted-p)
2041 (list "archive")))))
2042 method)
2043 (setq gnus-have-read-active-file nil)
2044 (with-current-buffer nntp-server-buffer
2045 (while (setq method (pop methods))
2046 ;; Only do each method once, in case the methods appear more
2047 ;; than once in this list.
2048 (when (and (not (member method methods))
2049 ;; Check whether the backend exists.
2050 (ignore-errors (gnus-get-function method 'open-server)))
2051 (if (or debug-on-error debug-on-quit)
2052 (gnus-read-active-file-1 method force)
2053 (condition-case ()
2054 (gnus-read-active-file-1 method force)
2055 ;; We catch C-g so that we can continue past servers
2056 ;; that do not respond.
2057 (quit
2058 (if debug-on-quit
2059 (debug "Quit")
2060 (message "Quit reading the active file"))
2061 nil))))))))
2062
2063 (defun gnus-read-active-file-1 (method force)
2064 (let (where mesg)
2065 (setq where (nth 1 method)
2066 mesg (format "Reading active file%s via %s..."
2067 (if (and where (not (zerop (length where))))
2068 (concat " from " where) "")
2069 (car method)))
2070 (gnus-message 5 "%s" mesg)
2071 (when (gnus-check-server method)
2072 ;; Request that the backend scan its incoming messages.
2073 (when (and (or (and gnus-agent
2074 (gnus-online method))
2075 (not gnus-agent))
2076 (gnus-check-backend-function 'request-scan (car method)))
2077 (gnus-request-scan nil method))
2078 (cond
2079 ((and (eq gnus-read-active-file 'some)
2080 (gnus-check-backend-function 'retrieve-groups (car method))
2081 (not force))
2082 (let ((newsrc (cdr gnus-newsrc-alist))
2083 (gmethod (gnus-server-get-method nil method))
2084 groups info)
2085 (while (setq info (pop newsrc))
2086 (when (inline
2087 (gnus-server-equal
2088 (inline
2089 (gnus-find-method-for-group
2090 (gnus-info-group info) info))
2091 gmethod))
2092 (push (gnus-group-real-name (gnus-info-group info))
2093 groups)))
2094 (gnus-read-active-file-2 groups method)))
2095 ((null method)
2096 t)
2097 (t
2098 (if (not (gnus-request-list method))
2099 (unless (equal method gnus-message-archive-method)
2100 (gnus-error 1 "Cannot read active file from %s server"
2101 (car method)))
2102 (gnus-message 5 "%s" mesg)
2103 (gnus-active-to-gnus-format method gnus-active-hashtb nil t)
2104 ;; We mark this active file as read.
2105 (add-to-list 'gnus-have-read-active-file method)
2106 (gnus-message 5 "%sdone" mesg)))))))
2107
2108 (defun gnus-read-active-file-2 (groups method)
2109 "Read an active file for GROUPS in METHOD using `gnus-retrieve-groups'."
2110 (when groups
2111 (with-current-buffer nntp-server-buffer
2112 (gnus-check-server method)
2113 (let ((list-type (gnus-retrieve-groups groups method)))
2114 (cond ((not list-type)
2115 (gnus-error
2116 1.2 "Cannot read partial active file from %s server."
2117 (car method)))
2118 ((eq list-type 'active)
2119 (gnus-active-to-gnus-format method gnus-active-hashtb nil t))
2120 (t
2121 (gnus-groups-to-gnus-format method gnus-active-hashtb t)))))))
2122
2123 ;; Read an active file and place the results in `gnus-active-hashtb'.
2124 (defun gnus-active-to-gnus-format (&optional method hashtb ignore-errors
2125 real-active)
2126 (unless method
2127 (setq method gnus-select-method))
2128 (let ((cur (current-buffer))
2129 (hashtb (or hashtb
2130 (if (and gnus-active-hashtb
2131 (not (equal method gnus-select-method)))
2132 gnus-active-hashtb
2133 (setq gnus-active-hashtb
2134 (if (equal method gnus-select-method)
2135 (gnus-make-hashtable
2136 (count-lines (point-min) (point-max)))
2137 (gnus-make-hashtable 4096))))))
2138 group max min)
2139 ;; Delete unnecessary lines.
2140 (goto-char (point-min))
2141 (cond
2142 ((string= gnus-ignored-newsgroups "")
2143 (delete-matching-lines "^to\\."))
2144 (t
2145 (delete-matching-lines (concat "^to\\.\\|" gnus-ignored-newsgroups))))
2146
2147 (goto-char (point-min))
2148 (unless (re-search-forward "[\\\"]" nil t)
2149 ;; Make the group names readable as a lisp expression even if they
2150 ;; contain special characters.
2151 (goto-char (point-max))
2152 (while (re-search-backward "[][';?()#]" nil t)
2153 (insert ?\\)))
2154
2155 ;; Let the Gnus agent save the active file.
2156 (when (and gnus-agent real-active (gnus-online method))
2157 (gnus-agent-save-active method))
2158
2159 ;; If these are groups from a foreign select method, we insert the
2160 ;; group prefix in front of the group names.
2161 (when (not (gnus-server-equal
2162 (gnus-server-get-method nil method)
2163 (gnus-server-get-method nil gnus-select-method)))
2164 (let ((prefix (gnus-group-prefixed-name "" method)))
2165 (goto-char (point-min))
2166 (while (and (not (eobp))
2167 (progn
2168 (when (= (following-char) ?\")
2169 (forward-char 1))
2170 (insert prefix)
2171 (zerop (forward-line 1)))))))
2172 ;; Store the active file in a hash table.
2173 ;; Use a unibyte buffer in order to make `read' read non-ASCII
2174 ;; group names (which have been encoded) as unibyte strings.
2175 (mm-with-unibyte-buffer
2176 (insert-buffer-substring cur)
2177 (setq cur (current-buffer))
2178 (goto-char (point-min))
2179 (while (not (eobp))
2180 (condition-case ()
2181 (progn
2182 (narrow-to-region (point) (point-at-eol))
2183 ;; group gets set to a symbol interned in the hash table
2184 ;; (what a hack!!) - jwz
2185 (setq group (let ((obarray hashtb)) (read cur)))
2186 ;; ### The extended group name scheme makes
2187 ;; the previous optimization strategy sort of pointless...
2188 (when (stringp group)
2189 (setq group (intern group hashtb)))
2190 (if (and (numberp (setq max (read cur)))
2191 (numberp (setq min (read cur)))
2192 (progn
2193 (skip-chars-forward " \t")
2194 (not
2195 (or (eq (char-after) ?=)
2196 (eq (char-after) ?x)
2197 (eq (char-after) ?j)))))
2198 (progn
2199 (set group (cons min max))
2200 ;; if group is moderated, stick in moderation table
2201 (when (eq (char-after) ?m)
2202 (unless gnus-moderated-hashtb
2203 (setq gnus-moderated-hashtb (gnus-make-hashtable)))
2204 (gnus-sethash (symbol-name group) t
2205 gnus-moderated-hashtb)))
2206 (set group nil)))
2207 (error
2208 (and group
2209 (symbolp group)
2210 (set group nil))
2211 (unless ignore-errors
2212 (gnus-message 3 "Warning - invalid active: %s"
2213 (buffer-substring
2214 (point-at-bol) (point-at-eol))))))
2215 (widen)
2216 (forward-line 1)))))
2217
2218 (defun gnus-groups-to-gnus-format (method &optional hashtb real-active)
2219 ;; Parse a "groups" active file.
2220 (let ((cur (current-buffer))
2221 (hashtb (or hashtb
2222 (if (and method gnus-active-hashtb)
2223 gnus-active-hashtb
2224 (setq gnus-active-hashtb
2225 (gnus-make-hashtable
2226 (count-lines (point-min) (point-max)))))))
2227 (prefix (and method
2228 (not (gnus-server-equal
2229 (gnus-server-get-method nil method)
2230 (gnus-server-get-method nil gnus-select-method)))
2231 (gnus-group-prefixed-name "" method))))
2232
2233 ;; Let the Gnus agent save the active file.
2234 (if (and gnus-agent
2235 real-active
2236 (gnus-online method)
2237 (gnus-agent-method-p method))
2238 (progn
2239 (gnus-agent-save-active method t)
2240 (gnus-active-to-gnus-format method hashtb nil real-active))
2241
2242 (goto-char (point-min))
2243 ;; We split this into to separate loops, one with the prefix
2244 ;; and one without to speed the reading up somewhat.
2245 (if prefix
2246 (let (min max opoint group)
2247 (while (not (eobp))
2248 (condition-case ()
2249 (progn
2250 (read cur) (read cur)
2251 (setq min (read cur)
2252 max (read cur)
2253 opoint (point))
2254 (skip-chars-forward " \t")
2255 (insert prefix)
2256 (goto-char opoint)
2257 (set (let ((obarray hashtb)) (read cur))
2258 (cons min max)))
2259 (error (and group (symbolp group) (set group nil))))
2260 (forward-line 1)))
2261 (let (min max group)
2262 (while (not (eobp))
2263 (condition-case ()
2264 (when (eq (char-after) ?2)
2265 (read cur) (read cur)
2266 (setq min (read cur)
2267 max (read cur))
2268 (set (setq group (let ((obarray hashtb)) (read cur)))
2269 (cons min max)))
2270 (error (and group (symbolp group) (set group nil))))
2271 (forward-line 1)))))))
2272
2273 (defun gnus-read-newsrc-file (&optional force)
2274 "Read startup file.
2275 If FORCE is non-nil, the .newsrc file is read."
2276 ;; Reset variables that might be defined in the .newsrc.eld file.
2277 (let ((variables (remove 'gnus-format-specs gnus-variable-list)))
2278 (while variables
2279 (set (car variables) nil)
2280 (setq variables (cdr variables))))
2281 (let* ((newsrc-file gnus-current-startup-file)
2282 (quick-file (concat newsrc-file ".el")))
2283 (save-excursion
2284 ;; We always load the .newsrc.eld file. If always contains
2285 ;; much information that can not be gotten from the .newsrc
2286 ;; file (ticked articles, killed groups, foreign methods, etc.)
2287 (gnus-read-newsrc-el-file quick-file)
2288
2289 (when (and gnus-read-newsrc-file
2290 (file-exists-p gnus-current-startup-file)
2291 (or force
2292 (and (file-newer-than-file-p newsrc-file quick-file)
2293 (file-newer-than-file-p newsrc-file
2294 (concat quick-file "d")))
2295 (not gnus-newsrc-alist)))
2296 ;; We read the .newsrc file. Note that if there if a
2297 ;; .newsrc.eld file exists, it has already been read, and
2298 ;; the `gnus-newsrc-hashtb' has been created. While reading
2299 ;; the .newsrc file, Gnus will only use the information it
2300 ;; can find there for changing the data already read -
2301 ;; i. e., reading the .newsrc file will not trash the data
2302 ;; already read (except for read articles).
2303 (save-excursion
2304 (gnus-message 5 "Reading %s..." newsrc-file)
2305 (set-buffer (nnheader-find-file-noselect newsrc-file))
2306 (buffer-disable-undo)
2307 (gnus-newsrc-to-gnus-format)
2308 (kill-buffer (current-buffer))
2309 (gnus-message 5 "Reading %s...done" newsrc-file)))
2310
2311 ;; Convert old to new.
2312 (gnus-convert-old-newsrc)
2313 (gnus-clean-old-newsrc))))
2314
2315 (defun gnus-clean-old-newsrc (&optional force)
2316 ;; Currently no cleanups.
2317 )
2318
2319 (defun gnus-convert-old-newsrc ()
2320 "Convert old newsrc formats into the current format, if needed."
2321 (let ((fcv (and gnus-newsrc-file-version
2322 (gnus-continuum-version gnus-newsrc-file-version)))
2323 (gcv (gnus-continuum-version)))
2324 (when fcv
2325 ;; A newsrc file was loaded.
2326 (let (prompt-displayed
2327 (converters
2328 (sort
2329 (mapcar (lambda (date-func)
2330 (cons (gnus-continuum-version (car date-func))
2331 date-func))
2332 ;; This is a list of converters that must be run
2333 ;; to bring the newsrc file up to the current
2334 ;; version. If you create an incompatibility
2335 ;; with older versions, you should create an
2336 ;; entry here. The entry should consist of the
2337 ;; current gnus version (hardcoded so that it
2338 ;; doesn't change with each release) and the
2339 ;; function that must be applied to convert the
2340 ;; previous version into the current version.
2341 '(("September Gnus v0.1" nil
2342 gnus-convert-old-ticks)
2343 ("Oort Gnus v0.08" "legacy-gnus-agent"
2344 gnus-agent-convert-to-compressed-agentview)
2345 ("Gnus v5.10.7" "legacy-gnus-agent"
2346 gnus-agent-unlist-expire-days)
2347 ("Gnus v5.10.7" "legacy-gnus-agent"
2348 gnus-agent-unhook-expire-days)))
2349 #'car-less-than-car)))
2350 ;; Skip converters older than the file version
2351 (while (and converters (>= fcv (caar converters)))
2352 (pop converters))
2353
2354 ;; Perform converters to bring older version up to date.
2355 (when (and converters (< fcv (caar converters)))
2356 (while (and converters (< fcv (caar converters))
2357 (<= (caar converters) gcv))
2358 (let* ((converter-spec (pop converters))
2359 (convert-to (nth 1 converter-spec))
2360 (load-from (nth 2 converter-spec))
2361 (func (nth 3 converter-spec)))
2362 (when (and load-from
2363 (not (fboundp func)))
2364 (load load-from t))
2365 (or prompt-displayed
2366 (not (gnus-convert-converter-needs-prompt func))
2367 (while (let (c
2368 (cursor-in-echo-area t)
2369 (echo-keystrokes 0))
2370 (message "Convert gnus from version `%s' to `%s'? (n/y/?)"
2371 gnus-newsrc-file-version gnus-version)
2372 (setq c (read-char-exclusive))
2373
2374 (cond ((or (eq c ?n) (eq c ?N))
2375 (error "Can not start gnus without converting"))
2376 ((or (eq c ?y) (eq c ?Y))
2377 (setq prompt-displayed t)
2378 nil)
2379 ((eq c ?\?)
2380 (message "This conversion is irreversible. \
2381 To be safe, you should backup your files before proceeding.")
2382 (sit-for 5)
2383 t)
2384 (t
2385 (gnus-message 3 "Ignoring unexpected input")
2386 (sit-for 3)
2387 t)))))
2388
2389 (funcall func convert-to)))
2390 (gnus-dribble-enter
2391 (format-message ";Converted gnus from version `%s' to `%s'."
2392 gnus-newsrc-file-version gnus-version)))))))
2393
2394 (defun gnus-convert-mark-converter-prompt (converter no-prompt)
2395 "Indicate whether CONVERTER requires gnus-convert-old-newsrc to
2396 display the conversion prompt. NO-PROMPT may be nil (prompt),
2397 t (no prompt), or any form that can be called as a function.
2398 The form should return either t or nil."
2399 (put converter 'gnus-convert-no-prompt no-prompt))
2400
2401 (defun gnus-convert-converter-needs-prompt (converter)
2402 (let ((no-prompt (get converter 'gnus-convert-no-prompt)))
2403 (not (if (memq no-prompt '(t nil))
2404 no-prompt
2405 (funcall no-prompt)))))
2406
2407 (defun gnus-convert-old-ticks (converting-to)
2408 (let ((newsrc (cdr gnus-newsrc-alist))
2409 marks info dormant ticked)
2410 (while (setq info (pop newsrc))
2411 (when (setq marks (gnus-info-marks info))
2412 (setq dormant (cdr (assq 'dormant marks))
2413 ticked (cdr (assq 'tick marks)))
2414 (when (or dormant ticked)
2415 (gnus-info-set-read
2416 info
2417 (gnus-add-to-range
2418 (gnus-info-read info)
2419 (nconc (gnus-uncompress-range dormant)
2420 (gnus-uncompress-range ticked)))))))))
2421
2422 (defun gnus-load (file)
2423 "Load FILE, but in such a way that read errors can be reported."
2424 (with-temp-buffer
2425 (insert-file-contents file)
2426 (while (not (eobp))
2427 (condition-case type
2428 (let ((form (read (current-buffer))))
2429 (eval form))
2430 (error
2431 (unless (eq (car type) 'end-of-file)
2432 (let ((errmsg (format "Error in %s line %d" file
2433 (count-lines (point-min) (point)))))
2434 (ding)
2435 (unless (gnus-yes-or-no-p (concat errmsg "; continue? "))
2436 (error "%s" errmsg)))))))))
2437
2438 (defun gnus-read-newsrc-el-file (file)
2439 (let ((ding-file (concat file "d")))
2440 (when (file-exists-p ding-file)
2441 ;; We always, always read the .eld file.
2442 (gnus-message 5 "Reading %s..." ding-file)
2443 (let (gnus-newsrc-assoc)
2444 (gnus-load ding-file)
2445 ;; Older versions of `gnus-format-specs' are no longer valid
2446 ;; in Oort Gnus 0.01.
2447 (let ((version
2448 (and gnus-newsrc-file-version
2449 (gnus-continuum-version gnus-newsrc-file-version))))
2450 (when (or (not version)
2451 (< version 5.090009))
2452 (setq gnus-format-specs gnus-default-format-specs)))
2453 (when gnus-newsrc-assoc
2454 (setq gnus-newsrc-alist gnus-newsrc-assoc))))
2455 (dolist (elem gnus-newsrc-alist)
2456 ;; Protect against broken .newsrc.el files.
2457 (when (car elem)
2458 (setcar elem (string-as-unibyte (car elem)))))
2459 (gnus-make-hashtable-from-newsrc-alist)
2460 (when (file-newer-than-file-p file ding-file)
2461 ;; Old format quick file
2462 (gnus-message 5 "Reading %s..." file)
2463 ;; The .el file is newer than the .eld file, so we read that one
2464 ;; as well.
2465 (gnus-read-old-newsrc-el-file file)))
2466 (gnus-run-hooks 'gnus-read-newsrc-el-hook))
2467
2468 ;; Parse the old-style quick startup file
2469 (defun gnus-read-old-newsrc-el-file (file)
2470 (let (newsrc killed marked group m info)
2471 (prog1
2472 (let ((gnus-killed-assoc nil)
2473 gnus-marked-assoc gnus-newsrc-alist gnus-newsrc-assoc)
2474 (prog1
2475 (ignore-errors
2476 (load file t t t))
2477 (setq newsrc gnus-newsrc-assoc
2478 killed gnus-killed-assoc
2479 marked gnus-marked-assoc)))
2480 (setq gnus-newsrc-alist nil)
2481 (while (setq group (pop newsrc))
2482 (if (setq info (gnus-get-info (car group)))
2483 (progn
2484 (gnus-info-set-read info (cddr group))
2485 (gnus-info-set-level
2486 info (if (nth 1 group) gnus-level-default-subscribed
2487 gnus-level-default-unsubscribed))
2488 (push info gnus-newsrc-alist))
2489 (push (setq info
2490 (list (car group)
2491 (if (nth 1 group) gnus-level-default-subscribed
2492 gnus-level-default-unsubscribed)
2493 (cddr group)))
2494 gnus-newsrc-alist))
2495 ;; Copy marks into info.
2496 (when (setq m (assoc (car group) marked))
2497 (unless (nthcdr 3 info)
2498 (nconc info (list nil)))
2499 (gnus-info-set-marks
2500 info (list (cons 'tick (gnus-compress-sequence
2501 (sort (cdr m) '<) t))))))
2502 (setq newsrc killed)
2503 (while newsrc
2504 (setcar newsrc (caar newsrc))
2505 (setq newsrc (cdr newsrc)))
2506 (setq gnus-killed-list killed))
2507 ;; The .el file version of this variable does not begin with
2508 ;; "options", while the .eld version does, so we just add it if it
2509 ;; isn't there.
2510 (when
2511 gnus-newsrc-options
2512 (when (not (string-match "^ *options" gnus-newsrc-options))
2513 (setq gnus-newsrc-options (concat "options " gnus-newsrc-options)))
2514 (when (not (string-match "\n$" gnus-newsrc-options))
2515 (setq gnus-newsrc-options (concat gnus-newsrc-options "\n")))
2516 ;; Finally, if we read some options lines, we parse them.
2517 (unless (string= gnus-newsrc-options "")
2518 (gnus-newsrc-parse-options gnus-newsrc-options)))
2519
2520 (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist))
2521 (gnus-make-hashtable-from-newsrc-alist)))
2522
2523 (defun gnus-make-newsrc-file (file)
2524 "Make server dependent file name by catenating FILE and server host name."
2525 (let* ((file (expand-file-name file nil))
2526 (real-file (concat file "-" (nth 1 gnus-select-method))))
2527 (if (or (file-exists-p real-file)
2528 (file-exists-p (concat real-file ".el"))
2529 (file-exists-p (concat real-file ".eld")))
2530 real-file
2531 file)))
2532
2533 (defun gnus-newsrc-to-gnus-format ()
2534 (setq gnus-newsrc-options "")
2535 (setq gnus-newsrc-options-n nil)
2536
2537 (unless gnus-active-hashtb
2538 (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
2539 (let ((buf (current-buffer))
2540 (already-read (> (length gnus-newsrc-alist) 1))
2541 group subscribed options-symbol newsrc Options-symbol
2542 symbol reads num1)
2543 (goto-char (point-min))
2544 ;; We intern the symbol `options' in the active hashtb so that we
2545 ;; can `eq' against it later.
2546 (set (setq options-symbol (intern "options" gnus-active-hashtb)) nil)
2547 (set (setq Options-symbol (intern "Options" gnus-active-hashtb)) nil)
2548
2549 (while (not (eobp))
2550 ;; We first read the first word on the line by narrowing and
2551 ;; then reading into `gnus-active-hashtb'. Most groups will
2552 ;; already exist in that hashtb, so this will save some string
2553 ;; space.
2554 (narrow-to-region
2555 (point)
2556 (progn (skip-chars-forward "^ \t!:\n") (point)))
2557 (goto-char (point-min))
2558 (setq symbol
2559 (and (/= (point-min) (point-max))
2560 (let ((obarray gnus-active-hashtb)) (read buf))))
2561 (widen)
2562 ;; Now, the symbol we have read is either `options' or a group
2563 ;; name. If it is an options line, we just add it to a string.
2564 (cond
2565 ((or (eq symbol options-symbol)
2566 (eq symbol Options-symbol))
2567 (setq gnus-newsrc-options
2568 ;; This concatting is quite inefficient, but since our
2569 ;; thorough studies show that approx 99.37% of all
2570 ;; .newsrc files only contain a single options line, we
2571 ;; don't give a damn, frankly, my dear.
2572 (concat gnus-newsrc-options
2573 (buffer-substring
2574 (point-at-bol)
2575 ;; Options may continue on the next line.
2576 (or (and (re-search-forward "^[^ \t]" nil 'move)
2577 (point-at-bol))
2578 (point)))))
2579 (forward-line -1))
2580 (symbol
2581 ;; Group names can be just numbers.
2582 (when (numberp symbol)
2583 (setq symbol (intern (int-to-string symbol) gnus-active-hashtb)))
2584 (unless (boundp symbol)
2585 (set symbol nil))
2586 ;; It was a group name.
2587 (setq subscribed (eq (char-after) ?:)
2588 group (symbol-name symbol)
2589 reads nil)
2590 (if (eolp)
2591 ;; If the line ends here, this is clearly a buggy line, so
2592 ;; we put point a the beginning of line and let the cond
2593 ;; below do the error handling.
2594 (beginning-of-line)
2595 ;; We skip to the beginning of the ranges.
2596 (skip-chars-forward "!: \t"))
2597 ;; We are now at the beginning of the list of read articles.
2598 ;; We read them range by range.
2599 (while
2600 (cond
2601 ((looking-at "[0-9]+")
2602 ;; We narrow and read a number instead of buffer-substring/
2603 ;; string-to-number because it's faster. narrow/widen is
2604 ;; faster than save-restriction/narrow, and save-restriction
2605 ;; produces a garbage object.
2606 (setq num1 (progn
2607 (narrow-to-region (match-beginning 0) (match-end 0))
2608 (read buf)))
2609 (widen)
2610 ;; If the next character is a dash, then this is a range.
2611 (if (eq (char-after) ?-)
2612 (progn
2613 ;; We read the upper bound of the range.
2614 (forward-char 1)
2615 (if (not (looking-at "[0-9]+"))
2616 ;; This is a buggy line, by we pretend that
2617 ;; it's kinda OK. Perhaps the user should be
2618 ;; dinged?
2619 (push num1 reads)
2620 (push
2621 (cons num1
2622 (progn
2623 (narrow-to-region (match-beginning 0)
2624 (match-end 0))
2625 (read buf)))
2626 reads)
2627 (widen)))
2628 ;; It was just a simple number, so we add it to the
2629 ;; list of ranges.
2630 (push num1 reads))
2631 ;; If the next char in ?\n, then we have reached the end
2632 ;; of the line and return nil.
2633 (not (eq (char-after) ?\n)))
2634 ((eq (char-after) ?\n)
2635 ;; End of line, so we end.
2636 nil)
2637 (t
2638 ;; Not numbers and not eol, so this might be a buggy
2639 ;; line...
2640 (unless (eobp)
2641 ;; If it was eob instead of ?\n, we allow it.
2642 ;; The line was buggy.
2643 (setq group nil)
2644 (gnus-error 3.1 "Mangled line: %s"
2645 (buffer-substring (point-at-bol)
2646 (point-at-eol))))
2647 nil))
2648 ;; Skip past ", ". Spaces are invalid in these ranges, but
2649 ;; we allow them, because it's a common mistake to put a
2650 ;; space after the comma.
2651 (skip-chars-forward ", "))
2652
2653 ;; We have already read .newsrc.eld, so we gently update the
2654 ;; data in the hash table with the information we have just
2655 ;; read.
2656 (when group
2657 (let ((info (gnus-get-info group))
2658 level)
2659 (if info
2660 ;; There is an entry for this file in the alist.
2661 (progn
2662 (gnus-info-set-read info (nreverse reads))
2663 ;; We update the level very gently. In fact, we
2664 ;; only change it if there's been a status change
2665 ;; from subscribed to unsubscribed, or vice versa.
2666 (setq level (gnus-info-level info))
2667 (cond ((and (<= level gnus-level-subscribed)
2668 (not subscribed))
2669 (setq level (if reads
2670 gnus-level-default-unsubscribed
2671 (1+ gnus-level-default-unsubscribed))))
2672 ((and (> level gnus-level-subscribed) subscribed)
2673 (setq level gnus-level-default-subscribed)))
2674 (gnus-info-set-level info level))
2675 ;; This is a new group.
2676 (setq info (list group
2677 (if subscribed
2678 gnus-level-default-subscribed
2679 (if reads
2680 (1+ gnus-level-subscribed)
2681 gnus-level-default-unsubscribed))
2682 (nreverse reads))))
2683 (push info newsrc)))))
2684 (forward-line 1))
2685
2686 (setq newsrc (nreverse newsrc))
2687
2688 (if (not already-read)
2689 ()
2690 ;; We now have two newsrc lists - `newsrc', which is what we
2691 ;; have read from .newsrc, and `gnus-newsrc-alist', which is
2692 ;; what we've read from .newsrc.eld. We have to merge these
2693 ;; lists. We do this by "attaching" any (foreign) groups in the
2694 ;; gnus-newsrc-alist to the (native) group that precedes them.
2695 (let ((rc (cdr gnus-newsrc-alist))
2696 (prev gnus-newsrc-alist)
2697 entry mentry)
2698 (while rc
2699 (or (null (nth 4 (car rc))) ; It's a native group.
2700 (assoc (caar rc) newsrc) ; It's already in the alist.
2701 (if (setq entry (assoc (caar prev) newsrc))
2702 (setcdr (setq mentry (memq entry newsrc))
2703 (cons (car rc) (cdr mentry)))
2704 (push (car rc) newsrc)))
2705 (setq prev rc
2706 rc (cdr rc)))))
2707
2708 (setq gnus-newsrc-alist newsrc)
2709 ;; We make the newsrc hashtb.
2710 (gnus-make-hashtable-from-newsrc-alist)
2711
2712 ;; Finally, if we read some options lines, we parse them.
2713 (unless (string= gnus-newsrc-options "")
2714 (gnus-newsrc-parse-options gnus-newsrc-options))))
2715
2716 ;; Parse options lines to find "options -n !all rec.all" and stuff.
2717 ;; The return value will be a list on the form
2718 ;; ((regexp1 . ignore)
2719 ;; (regexp2 . subscribe)...)
2720 ;; When handling new newsgroups, groups that match a `ignore' regexp
2721 ;; will be ignored, and groups that match a `subscribe' regexp will be
2722 ;; subscribed. A line like
2723 ;; options -n !all rec.all
2724 ;; will lead to a list that looks like
2725 ;; (("^rec\\..+" . subscribe)
2726 ;; ("^.+" . ignore))
2727 ;; So all "rec.*" groups will be subscribed, while all the other
2728 ;; groups will be ignored. Note that "options -n !all rec.all" is very
2729 ;; different from "options -n rec.all !all".
2730 (defun gnus-newsrc-parse-options (options)
2731 (let (out eol)
2732 (save-excursion
2733 (gnus-set-work-buffer)
2734 (insert (regexp-quote options))
2735 ;; First we treat all continuation lines.
2736 (goto-char (point-min))
2737 (while (re-search-forward "\n[ \t]+" nil t)
2738 (replace-match " " t t))
2739 ;; Then we transform all "all"s into ".+"s.
2740 (goto-char (point-min))
2741 (while (re-search-forward "\\ball\\b" nil t)
2742 (replace-match ".+" t t))
2743 (goto-char (point-min))
2744 ;; We remove all other options than the "-n" ones.
2745 (while (re-search-forward "[ \t]-[^n][^-]*" nil t)
2746 (replace-match " ")
2747 (forward-char -1))
2748 (goto-char (point-min))
2749
2750 ;; We are only interested in "options -n" lines - we
2751 ;; ignore the other option lines.
2752 (while (re-search-forward "[ \t]-n" nil t)
2753 (setq eol
2754 (or (save-excursion
2755 (and (re-search-forward "[ \t]-n" (point-at-eol) t)
2756 (- (point) 2)))
2757 (point-at-eol)))
2758 ;; Search for all "words"...
2759 (while (re-search-forward "[^ \t,\n]+" eol t)
2760 (if (eq (char-after (match-beginning 0)) ?!)
2761 ;; If the word begins with a bang (!), this is a "not"
2762 ;; spec. We put this spec (minus the bang) and the
2763 ;; symbol `ignore' into the list.
2764 (push (cons (concat
2765 "^" (buffer-substring
2766 (1+ (match-beginning 0))
2767 (match-end 0))
2768 "\\($\\|\\.\\)")
2769 'ignore)
2770 out)
2771 ;; There was no bang, so this is a "yes" spec.
2772 (push (cons (concat "^" (match-string 0) "\\($\\|\\.\\)")
2773 'subscribe)
2774 out))))
2775
2776 (setq gnus-newsrc-options-n out))))
2777
2778 (eval-and-compile
2779 (defalias 'gnus-long-file-names
2780 (if (fboundp 'msdos-long-file-names)
2781 'msdos-long-file-names
2782 (lambda () t))))
2783
2784 (defvar gnus-save-newsrc-file-last-timestamp nil)
2785 (defun gnus-save-newsrc-file (&optional force)
2786 "Save .newsrc file."
2787 ;; Note: We cannot save .newsrc file if all newsgroups are removed
2788 ;; from the variable gnus-newsrc-alist.
2789 (when (and (or gnus-newsrc-alist gnus-killed-list)
2790 gnus-current-startup-file)
2791 ;; Save agent range limits for the currently active method.
2792 (when gnus-agent
2793 (gnus-agent-save-local force))
2794
2795 (save-excursion
2796 (if (and (or gnus-use-dribble-file gnus-slave)
2797 (not force)
2798 (or (not gnus-dribble-buffer)
2799 (not (buffer-name gnus-dribble-buffer))
2800 (zerop (with-current-buffer gnus-dribble-buffer
2801 (buffer-size)))))
2802 (gnus-message 4 "(No changes need to be saved)")
2803 (gnus-run-hooks 'gnus-save-newsrc-hook)
2804 (if gnus-slave
2805 (gnus-slave-save-newsrc)
2806 ;; Save .newsrc.
2807 (when gnus-save-newsrc-file
2808 (gnus-message 8 "Saving %s..." gnus-current-startup-file)
2809 (gnus-gnus-to-newsrc-format)
2810 (gnus-message 8 "Saving %s...done" gnus-current-startup-file))
2811
2812 ;; Save .newsrc.eld.
2813 (set-buffer (gnus-get-buffer-create " *Gnus-newsrc*"))
2814 (make-local-variable 'version-control)
2815 (setq version-control gnus-backup-startup-file)
2816 (setq buffer-file-name
2817 (concat gnus-current-startup-file ".eld"))
2818 (setq default-directory (file-name-directory buffer-file-name))
2819 (buffer-disable-undo)
2820 (erase-buffer)
2821 (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file)
2822
2823 ;; check timestamp of `gnus-current-startup-file'.eld against
2824 ;; `gnus-save-newsrc-file-last-timestamp'
2825 (let* ((checkfile (concat gnus-current-startup-file ".eld"))
2826 (mtime (nth 5 (file-attributes checkfile))))
2827 (when (and gnus-save-newsrc-file-last-timestamp
2828 (time-less-p gnus-save-newsrc-file-last-timestamp
2829 mtime))
2830 (unless (y-or-n-p
2831 (format "%s was updated externally after %s, save?"
2832 checkfile
2833 (format-time-string
2834 "%c"
2835 gnus-save-newsrc-file-last-timestamp)))
2836 (error "Couldn't save %s: updated externally" checkfile))))
2837
2838 (if gnus-save-startup-file-via-temp-buffer
2839 (let ((coding-system-for-write gnus-ding-file-coding-system)
2840 (standard-output (current-buffer)))
2841 (gnus-gnus-to-quick-newsrc-format)
2842 (gnus-run-hooks 'gnus-save-quick-newsrc-hook)
2843 (save-buffer)
2844 (setq gnus-save-newsrc-file-last-timestamp
2845 (nth 5 (file-attributes buffer-file-name))))
2846 (let ((coding-system-for-write gnus-ding-file-coding-system)
2847 (version-control gnus-backup-startup-file)
2848 (startup-file (concat gnus-current-startup-file ".eld"))
2849 (working-dir (file-name-directory gnus-current-startup-file))
2850 working-file
2851 (i -1))
2852 ;; Generate the name of a non-existent file.
2853 (while (progn (setq working-file
2854 (format
2855 (if (and (eq system-type 'ms-dos)
2856 (not (gnus-long-file-names)))
2857 "%s#%d.tm#" ; MSDOS limits files to 8+3
2858 "%s#tmp#%d")
2859 working-dir (setq i (1+ i))))
2860 (file-exists-p working-file)))
2861
2862 (unwind-protect
2863 (progn
2864 (gnus-with-output-to-file working-file
2865 (gnus-gnus-to-quick-newsrc-format)
2866 (gnus-run-hooks 'gnus-save-quick-newsrc-hook))
2867
2868 ;; These bindings will mislead the current buffer
2869 ;; into thinking that it is visiting the startup
2870 ;; file.
2871 (let ((buffer-backed-up nil)
2872 (buffer-file-name startup-file)
2873 (file-precious-flag t)
2874 (setmodes (file-modes startup-file)))
2875 ;; Backup the current version of the startup file.
2876 (backup-buffer)
2877
2878 ;; Replace the existing startup file with the temp file.
2879 (rename-file working-file startup-file t)
2880 (gnus-set-file-modes startup-file setmodes)
2881 (setq gnus-save-newsrc-file-last-timestamp
2882 (nth 5 (file-attributes startup-file)))))
2883 (condition-case nil
2884 (delete-file working-file)
2885 (file-error nil)))))
2886
2887 (gnus-kill-buffer (current-buffer))
2888 (gnus-message
2889 5 "Saving %s.eld...done" gnus-current-startup-file))
2890 (gnus-dribble-delete-file)
2891 (gnus-group-set-mode-line)))))
2892
2893 (defun gnus-gnus-to-quick-newsrc-format (&optional minimal name &rest specific-variables)
2894 "Print Gnus variables such as `gnus-newsrc-alist' in Lisp format."
2895 (princ (format ";; -*- mode:emacs-lisp; coding: %s; -*-\n"
2896 gnus-ding-file-coding-system))
2897 (if name
2898 (princ (format ";; %s\n" name))
2899 (princ ";; Gnus startup file.\n"))
2900
2901 (unless minimal
2902 (princ "\
2903 ;; Never delete this file -- if you want to force Gnus to read the
2904 ;; .newsrc file (if you have one), touch .newsrc instead.\n")
2905 (princ "(setq gnus-newsrc-file-version ")
2906 (princ (gnus-prin1-to-string gnus-version))
2907 (princ ")\n"))
2908
2909 (let* ((print-quoted t)
2910 (print-readably t)
2911 (print-escape-multibyte nil)
2912 (print-escape-nonascii t)
2913 (print-length nil)
2914 (print-level nil)
2915 (print-circle nil)
2916 (print-escape-newlines t)
2917 (gnus-killed-list
2918 (if (and gnus-save-killed-list
2919 (stringp gnus-save-killed-list))
2920 (gnus-strip-killed-list)
2921 gnus-killed-list))
2922 (variables
2923 (or specific-variables
2924 (if gnus-save-killed-list gnus-variable-list
2925 ;; Remove the `gnus-killed-list' from the list of variables
2926 ;; to be saved, if required.
2927 (delq 'gnus-killed-list (copy-sequence gnus-variable-list)))))
2928 ;; Peel off the "dummy" group.
2929 (gnus-newsrc-alist (cdr gnus-newsrc-alist))
2930 variable)
2931 ;; Insert the variables into the file.
2932 (while variables
2933 (when (and (boundp (setq variable (pop variables)))
2934 (symbol-value variable))
2935 (princ "\n(setq ")
2936 (princ (symbol-name variable))
2937 (princ " '")
2938 (prin1 (symbol-value variable))
2939 (princ ")\n")))))
2940
2941 (defun gnus-strip-killed-list ()
2942 "Return the killed list minus the groups that match `gnus-save-killed-list'."
2943 (let ((list gnus-killed-list)
2944 olist)
2945 (while list
2946 (when (string-match gnus-save-killed-list (car list))
2947 (push (car list) olist))
2948 (pop list))
2949 (nreverse olist)))
2950
2951 (defun gnus-gnus-to-newsrc-format (&optional foreign-ok)
2952 (interactive (list (gnus-y-or-n-p "write foreign groups too? ")))
2953 ;; Generate and save the .newsrc file.
2954 (with-current-buffer (create-file-buffer gnus-current-startup-file)
2955 (let ((newsrc (cdr gnus-newsrc-alist))
2956 (standard-output (current-buffer))
2957 info ranges range method)
2958 (setq buffer-file-name gnus-current-startup-file)
2959 (setq default-directory (file-name-directory buffer-file-name))
2960 (buffer-disable-undo)
2961 (erase-buffer)
2962 ;; Use a unibyte buffer since group names are unibyte strings;
2963 ;; in particular, non-ASCII group names are the ones encoded by
2964 ;; a certain coding system.
2965 (mm-disable-multibyte)
2966 ;; Write options.
2967 (when gnus-newsrc-options
2968 (insert gnus-newsrc-options))
2969 ;; Write subscribed and unsubscribed.
2970 (while (setq info (pop newsrc))
2971 ;; Don't write foreign groups to .newsrc.
2972 (when (or (null (setq method (gnus-info-method info)))
2973 (equal method "native")
2974 (inline (gnus-server-equal method gnus-select-method))
2975 foreign-ok)
2976 (insert (gnus-info-group info)
2977 (if (> (gnus-info-level info) gnus-level-subscribed)
2978 "!" ":"))
2979 (when (setq ranges (gnus-info-read info))
2980 (insert " ")
2981 (if (not (listp (cdr ranges)))
2982 (if (= (car ranges) (cdr ranges))
2983 (princ (car ranges))
2984 (princ (car ranges))
2985 (insert "-")
2986 (princ (cdr ranges)))
2987 (while (setq range (pop ranges))
2988 (if (or (atom range) (= (car range) (cdr range)))
2989 (princ (or (and (atom range) range) (car range)))
2990 (princ (car range))
2991 (insert "-")
2992 (princ (cdr range)))
2993 (when ranges
2994 (insert ",")))))
2995 (insert "\n")))
2996 (make-local-variable 'version-control)
2997 (setq version-control 'never)
2998 ;; It has been reported that sometime the modtime on the .newsrc
2999 ;; file seems to be off. We really do want to overwrite it, so
3000 ;; we clear the modtime here before saving. It's a bit odd,
3001 ;; though...
3002 ;; sometimes the modtime clear isn't sufficient. most brute force:
3003 ;; delete the silly thing entirely first. but this fails to provide
3004 ;; such niceties as .newsrc~ creation.
3005 (if gnus-modtime-botch
3006 (delete-file gnus-startup-file)
3007 (clear-visited-file-modtime))
3008 (gnus-run-hooks 'gnus-save-standard-newsrc-hook)
3009 (let ((coding-system-for-write 'raw-text))
3010 (save-buffer))
3011 (kill-buffer (current-buffer)))))
3012
3013 \f
3014 ;;;
3015 ;;; Slave functions.
3016 ;;;
3017
3018 (defvar gnus-slave-mode nil)
3019
3020 (defun gnus-slave-mode ()
3021 "Minor mode for slave Gnusae."
3022 ;; FIXME: gnus-slave-mode appears to never be set (i.e. it'll always be nil):
3023 ;; Remove, or fix and use define-minor-mode.
3024 (add-minor-mode 'gnus-slave-mode " Slave" (make-sparse-keymap))
3025 (gnus-run-hooks 'gnus-slave-mode-hook))
3026
3027 (defun gnus-slave-save-newsrc ()
3028 (with-current-buffer gnus-dribble-buffer
3029 (let ((slave-name
3030 (make-temp-file (concat gnus-current-startup-file "-slave-")))
3031 (modes (ignore-errors
3032 (file-modes (concat gnus-current-startup-file ".eld")))))
3033 (let ((coding-system-for-write gnus-ding-file-coding-system))
3034 (gnus-write-buffer slave-name))
3035 (when modes
3036 (gnus-set-file-modes slave-name modes)))))
3037
3038 (defun gnus-master-read-slave-newsrc ()
3039 (let ((slave-files
3040 (directory-files
3041 (file-name-directory gnus-current-startup-file)
3042 t (concat
3043 "^" (regexp-quote
3044 (concat
3045 (file-name-nondirectory gnus-current-startup-file)
3046 "-slave-")))
3047 t))
3048 file)
3049 (if (not slave-files)
3050 () ; There are no slave files to read.
3051 (gnus-message 7 "Reading slave newsrcs...")
3052 (with-current-buffer (gnus-get-buffer-create " *gnus slave*")
3053 (setq slave-files
3054 (sort (mapcar (lambda (file)
3055 (list (nth 5 (file-attributes file)) file))
3056 slave-files)
3057 (lambda (f1 f2)
3058 (or (< (caar f1) (caar f2))
3059 (< (nth 1 (car f1)) (nth 1 (car f2)))))))
3060 (while slave-files
3061 (erase-buffer)
3062 (setq file (nth 1 (car slave-files)))
3063 (nnheader-insert-file-contents file)
3064 (when (condition-case ()
3065 (progn
3066 (eval-buffer (current-buffer))
3067 t)
3068 (error
3069 (gnus-error 3.2 "Possible error in %s" file)
3070 nil))
3071 (unless gnus-slave ; Slaves shouldn't delete these files.
3072 (ignore-errors
3073 (delete-file file))))
3074 (setq slave-files (cdr slave-files))))
3075 (gnus-dribble-touch)
3076 (gnus-message 7 "Reading slave newsrcs...done"))))
3077
3078 \f
3079 ;;;
3080 ;;; Group description.
3081 ;;;
3082
3083 (defun gnus-read-all-descriptions-files ()
3084 (let ((methods (cons gnus-select-method
3085 (nconc
3086 (when (gnus-archive-server-wanted-p)
3087 (list "archive"))
3088 gnus-secondary-select-methods))))
3089 (while methods
3090 (gnus-read-descriptions-file (car methods))
3091 (setq methods (cdr methods)))
3092 t))
3093
3094 (defun gnus-read-descriptions-file (&optional method)
3095 (let ((method (or method gnus-select-method))
3096 group)
3097 (when (stringp method)
3098 (setq method (gnus-server-to-method method)))
3099 ;; We create the hashtable whether we manage to read the desc file
3100 ;; to avoid trying to re-read after a failed read.
3101 (unless gnus-description-hashtb
3102 (setq gnus-description-hashtb
3103 (gnus-make-hashtable (length gnus-active-hashtb))))
3104 ;; Mark this method's desc file as read.
3105 (gnus-sethash (gnus-group-prefixed-name "" method) "Has read"
3106 gnus-description-hashtb)
3107
3108 (gnus-message 5 "Reading descriptions file via %s..." (car method))
3109 (cond
3110 ((null (gnus-get-function method 'request-list-newsgroups t))
3111 t)
3112 ((not (gnus-check-server method))
3113 (gnus-message 1 "Couldn't open server")
3114 nil)
3115 ((not (gnus-request-list-newsgroups method))
3116 (gnus-message 1 "Couldn't read newsgroups descriptions")
3117 nil)
3118 (t
3119 (save-excursion
3120 ;; FIXME: Shouldn't save-restriction be done after set-buffer?
3121 (save-restriction
3122 (set-buffer nntp-server-buffer)
3123 (goto-char (point-min))
3124 (when (or (search-forward "\n.\n" nil t)
3125 (goto-char (point-max)))
3126 (beginning-of-line)
3127 (narrow-to-region (point-min) (point)))
3128 ;; If these are groups from a foreign select method, we insert the
3129 ;; group prefix in front of the group names.
3130 (and method (not (inline
3131 (gnus-server-equal
3132 (gnus-server-get-method nil method)
3133 (gnus-server-get-method
3134 nil gnus-select-method))))
3135 (let ((prefix (gnus-group-prefixed-name "" method)))
3136 (goto-char (point-min))
3137 (while (and (not (eobp))
3138 (progn (insert prefix)
3139 (zerop (forward-line 1)))))))
3140 (goto-char (point-min))
3141 (while (not (eobp))
3142 ;; If we get an error, we set group to 0, which is not a
3143 ;; symbol...
3144 (setq group
3145 (condition-case ()
3146 (let ((obarray gnus-description-hashtb))
3147 ;; Group is set to a symbol interned in this
3148 ;; hash table.
3149 (read nntp-server-buffer))
3150 (error 0)))
3151 (skip-chars-forward " \t")
3152 ;; ... which leads to this line being effectively ignored.
3153 (when (symbolp group)
3154 (let* ((str (buffer-substring
3155 (point) (progn (end-of-line) (point))))
3156 (name (symbol-name group))
3157 (charset
3158 (or (gnus-group-name-charset method name)
3159 (gnus-parameter-charset name)
3160 gnus-default-charset)))
3161 ;; Fixme: Don't decode in unibyte mode.
3162 (when (and str charset (featurep 'mule))
3163 (setq str (decode-coding-string str charset)))
3164 (set group str)))
3165 (forward-line 1))))
3166 (gnus-message 5 "Reading descriptions file...done")
3167 t))))
3168
3169 (defun gnus-group-get-description (group)
3170 "Get the description of a group by sending XGTITLE to the server."
3171 (when (gnus-request-group-description group)
3172 (with-current-buffer nntp-server-buffer
3173 (goto-char (point-min))
3174 (when (looking-at "[^ \t]+[ \t]+\\(.*\\)")
3175 (match-string 1)))))
3176
3177 ;;;###autoload
3178 (defun gnus-declare-backend (name &rest abilities)
3179 "Declare back end NAME with ABILITIES as a Gnus back end."
3180 (setq gnus-valid-select-methods
3181 (nconc gnus-valid-select-methods
3182 (list (apply 'list name abilities))))
3183 (gnus-redefine-select-method-widget))
3184
3185 (defun gnus-set-default-directory ()
3186 "Set the default directory in the current buffer to `gnus-default-directory'.
3187 If this variable is nil, don't do anything."
3188 (setq default-directory
3189 (if (and gnus-default-directory
3190 (file-exists-p gnus-default-directory))
3191 (file-name-as-directory (expand-file-name gnus-default-directory))
3192 default-directory)))
3193
3194 (defun gnus-display-time-event-handler ()
3195 (if (and (fboundp 'display-time-event-handler)
3196 (gnus-boundp 'display-time-timer))
3197 (display-time-event-handler)))
3198
3199 (defun gnus-check-reasonable-setup ()
3200 ;; Check whether nnml and nnfolder share a directory.
3201 (let ((display-warn
3202 (if (fboundp 'display-warning)
3203 'display-warning
3204 (lambda (type message)
3205 (if noninteractive
3206 (message "Warning (%s): %s" type message)
3207 (let (window)
3208 (with-current-buffer (get-buffer-create "*Warnings*")
3209 (goto-char (point-max))
3210 (unless (bolp)
3211 (insert "\n"))
3212 (insert (format "Warning (%s): %s\n" type message))
3213 (setq window (display-buffer (current-buffer)))
3214 (set-window-start
3215 window
3216 (prog2
3217 (forward-line (- 1 (window-height window)))
3218 (point)
3219 (goto-char (point-max))))))))))
3220 method active actives match)
3221 (dolist (server gnus-server-alist)
3222 (setq method (gnus-server-to-method server)
3223 active (intern (format "%s-active-file" (car method))))
3224 (when (and (member (car method) '(nnml nnfolder))
3225 (gnus-server-opened method)
3226 (boundp active))
3227 (when (setq match (assoc (symbol-value active) actives))
3228 (funcall display-warn 'gnus-server
3229 (format "%s and %s share the same active file %s"
3230 (car method)
3231 (cadr match)
3232 (car match))))
3233 (push (list (symbol-value active) method) actives)))))
3234
3235 (provide 'gnus-start)
3236
3237 ;;; gnus-start.el ends here