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