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