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