Commit | Line | Data |
---|---|---|
eec82323 | 1 | ;;; gnus-int.el --- backend interface 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 | |
5e809f55 | 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 | ||
249ffa67 RS |
27 | (eval-when-compile (require 'cl)) |
28 | ||
eec82323 | 29 | (require 'gnus) |
23f87bed MB |
30 | (require 'message) |
31 | (require 'gnus-range) | |
32 | ||
0be56f17 | 33 | (autoload 'gnus-run-hook-with-args "gnus-util") |
23f87bed | 34 | (autoload 'gnus-agent-expire "gnus-agent") |
54506618 | 35 | (autoload 'gnus-agent-regenerate-group "gnus-agent") |
23f87bed | 36 | (autoload 'gnus-agent-read-servers-validate-native "gnus-agent") |
b890d447 | 37 | (autoload 'gnus-agent-possibly-synchronize-flags-server "gnus-agent") |
eec82323 LMI |
38 | |
39 | (defcustom gnus-open-server-hook nil | |
40 | "Hook called just before opening connection to the news server." | |
41 | :group 'gnus-start | |
42 | :type 'hook) | |
43 | ||
cbabe91f TZ |
44 | (defcustom gnus-after-set-mark-hook nil |
45 | "Hook called just after marks are set in a group." | |
2bed3f04 | 46 | :version "24.1" |
cbabe91f TZ |
47 | :group 'gnus-start |
48 | :type 'hook) | |
49 | ||
50 | (defcustom gnus-before-update-mark-hook nil | |
51 | "Hook called just before marks are updated in a group." | |
2bed3f04 | 52 | :version "24.1" |
cbabe91f TZ |
53 | :group 'gnus-start |
54 | :type 'hook) | |
55 | ||
23f87bed MB |
56 | (defcustom gnus-server-unopen-status nil |
57 | "The default status if the server is not able to open. | |
58 | If the server is covered by Gnus agent, the possible values are | |
59 | `denied', set the server denied; `offline', set the server offline; | |
60 | nil, ask user. If the server is not covered by Gnus agent, set the | |
61 | server denied." | |
bf247b6e | 62 | :version "22.1" |
23f87bed MB |
63 | :group 'gnus-start |
64 | :type '(choice (const :tag "Ask" nil) | |
65 | (const :tag "Deny server" denied) | |
66 | (const :tag "Unplug Agent" offline))) | |
67 | ||
aa357b80 SM |
68 | (defcustom gnus-nntp-server nil |
69 | "The name of the host running the NNTP server." | |
70 | :group 'gnus-server | |
71 | :type '(choice (const :tag "disable" nil) | |
72 | string)) | |
73 | (make-obsolete-variable 'gnus-nntp-server 'gnus-select-method "24.1") | |
74 | ||
23f87bed MB |
75 | (defvar gnus-internal-registry-spool-current-method nil |
76 | "The current method, for the registry.") | |
77 | ||
fe86b5e0 GM |
78 | |
79 | (defun gnus-server-opened (gnus-command-method) | |
80 | "Check whether a connection to GNUS-COMMAND-METHOD has been opened." | |
81 | (unless (eq (gnus-server-status gnus-command-method) | |
82 | 'denied) | |
83 | (when (stringp gnus-command-method) | |
84 | (setq gnus-command-method (gnus-server-to-method gnus-command-method))) | |
85 | (funcall (inline (gnus-get-function gnus-command-method 'server-opened)) | |
86 | (nth 1 gnus-command-method)))) | |
87 | ||
88 | (defun gnus-status-message (gnus-command-method) | |
89 | "Return the status message from GNUS-COMMAND-METHOD. | |
90 | If GNUS-COMMAND-METHOD is a string, it is interpreted as a group | |
91 | name. The method this group uses will be queried." | |
92 | (let ((gnus-command-method | |
93 | (if (stringp gnus-command-method) | |
94 | (gnus-find-method-for-group gnus-command-method) | |
95 | gnus-command-method))) | |
96 | (funcall (gnus-get-function gnus-command-method 'status-message) | |
97 | (nth 1 gnus-command-method)))) | |
98 | ||
eec82323 LMI |
99 | ;;; |
100 | ;;; Server Communication | |
101 | ;;; | |
102 | ||
103 | (defun gnus-start-news-server (&optional confirm) | |
104 | "Open a method for getting news. | |
105 | If CONFIRM is non-nil, the user will be asked for an NNTP server." | |
106 | (let (how) | |
107 | (if gnus-current-select-method | |
108 | ;; Stream is already opened. | |
109 | nil | |
110 | ;; Open NNTP server. | |
eec82323 LMI |
111 | (when confirm |
112 | ;; Read server name with completion. | |
113 | (setq gnus-nntp-server | |
229b59da G |
114 | (gnus-completing-read "NNTP server" |
115 | (cons gnus-nntp-server | |
116 | gnus-secondary-servers) | |
117 | nil gnus-nntp-server))) | |
eec82323 LMI |
118 | |
119 | (when (and gnus-nntp-server | |
120 | (stringp gnus-nntp-server) | |
121 | (not (string= gnus-nntp-server ""))) | |
122 | (setq gnus-select-method | |
123 | (cond ((or (string= gnus-nntp-server "") | |
124 | (string= gnus-nntp-server "::")) | |
125 | (list 'nnspool (system-name))) | |
126 | ((string-match "^:" gnus-nntp-server) | |
127 | (list 'nnmh gnus-nntp-server | |
128 | (list 'nnmh-directory | |
129 | (file-name-as-directory | |
130 | (expand-file-name | |
31f35b6f | 131 | (substring gnus-nntp-server 1) "~/"))) |
eec82323 LMI |
132 | (list 'nnmh-get-new-mail nil))) |
133 | (t | |
134 | (list 'nntp gnus-nntp-server))))) | |
135 | ||
136 | (setq how (car gnus-select-method)) | |
137 | (cond | |
138 | ((eq how 'nnspool) | |
139 | (require 'nnspool) | |
140 | (gnus-message 5 "Looking up local news spool...")) | |
141 | ((eq how 'nnmh) | |
142 | (require 'nnmh) | |
143 | (gnus-message 5 "Looking up mh spool...")) | |
144 | (t | |
145 | (require 'nntp))) | |
146 | (setq gnus-current-select-method gnus-select-method) | |
6748645f | 147 | (gnus-run-hooks 'gnus-open-server-hook) |
23f87bed MB |
148 | |
149 | ;; Partially validate agent covered methods now that the | |
150 | ;; gnus-select-method is known. | |
151 | ||
152 | (if gnus-agent | |
153 | ;; NOTE: This is here for one purpose only. By validating | |
154 | ;; the current select method, it converts the old 5.10.3, | |
155 | ;; and earlier, format to the current format. That enables | |
156 | ;; the agent code within gnus-open-server to function | |
157 | ;; correctly. | |
158 | (gnus-agent-read-servers-validate-native gnus-select-method)) | |
159 | ||
eec82323 LMI |
160 | (or |
161 | ;; gnus-open-server-hook might have opened it | |
162 | (gnus-server-opened gnus-select-method) | |
163 | (gnus-open-server gnus-select-method) | |
16409b0b | 164 | gnus-batch-mode |
eec82323 LMI |
165 | (gnus-y-or-n-p |
166 | (format | |
167 | "%s (%s) open error: '%s'. Continue? " | |
168 | (car gnus-select-method) (cadr gnus-select-method) | |
169 | (gnus-status-message gnus-select-method))) | |
170 | (gnus-error 1 "Couldn't open server on %s" | |
171 | (nth 1 gnus-select-method)))))) | |
172 | ||
173 | (defun gnus-check-group (group) | |
174 | "Try to make sure that the server where GROUP exists is alive." | |
175 | (let ((method (gnus-find-method-for-group group))) | |
176 | (or (gnus-server-opened method) | |
177 | (gnus-open-server method)))) | |
178 | ||
179 | (defun gnus-check-server (&optional method silent) | |
180 | "Check whether the connection to METHOD is down. | |
181 | If METHOD is nil, use `gnus-select-method'. | |
182 | If it is down, start it up (again)." | |
23f87bed MB |
183 | (let ((method (or method gnus-select-method)) |
184 | result) | |
eec82323 LMI |
185 | ;; Transform virtual server names into select methods. |
186 | (when (stringp method) | |
187 | (setq method (gnus-server-to-method method))) | |
188 | (if (gnus-server-opened method) | |
189 | ;; The stream is already opened. | |
190 | t | |
191 | ;; Open the server. | |
192 | (unless silent | |
193 | (gnus-message 5 "Opening %s server%s..." (car method) | |
194 | (if (equal (nth 1 method) "") "" | |
195 | (format " on %s" (nth 1 method))))) | |
6748645f | 196 | (gnus-run-hooks 'gnus-open-server-hook) |
eec82323 | 197 | (prog1 |
20a673b2 | 198 | (setq result (gnus-open-server method)) |
eec82323 | 199 | (unless silent |
8ccbef23 G |
200 | (gnus-message |
201 | (if result 5 3) | |
202 | "Opening %s server%s...%s" (car method) | |
203 | (if (equal (nth 1 method) "") "" | |
204 | (format " on %s" (nth 1 method))) | |
205 | (if result | |
206 | "done" | |
207 | (format "failed: %s" | |
208 | (nnheader-get-report-string (car method)))))))))) | |
eec82323 LMI |
209 | |
210 | (defun gnus-get-function (method function &optional noerror) | |
211 | "Return a function symbol based on METHOD and FUNCTION." | |
212 | ;; Translate server names into methods. | |
213 | (unless method | |
214 | (error "Attempted use of a nil select method")) | |
215 | (when (stringp method) | |
216 | (setq method (gnus-server-to-method method))) | |
6748645f LMI |
217 | ;; Check cache of constructed names. |
218 | (let* ((method-sym (if gnus-agent | |
54506618 | 219 | (inline (gnus-agent-get-function method)) |
6748645f LMI |
220 | (car method))) |
221 | (method-fns (get method-sym 'gnus-method-functions)) | |
222 | (func (let ((method-fnlist-elt (assq function method-fns))) | |
223 | (unless method-fnlist-elt | |
224 | (setq method-fnlist-elt | |
225 | (cons function | |
226 | (intern (format "%s-%s" method-sym function)))) | |
227 | (put method-sym 'gnus-method-functions | |
228 | (cons method-fnlist-elt method-fns))) | |
229 | (cdr method-fnlist-elt)))) | |
230 | ;; Maybe complain if there is no function. | |
eec82323 | 231 | (unless (fboundp func) |
6748645f LMI |
232 | (unless (car method) |
233 | (error "Trying to require a method that doesn't exist")) | |
eec82323 | 234 | (require (car method)) |
6748645f LMI |
235 | (when (not (fboundp func)) |
236 | (if noerror | |
237 | (setq func nil) | |
238 | (error "No such function: %s" func)))) | |
eec82323 LMI |
239 | func)) |
240 | ||
241 | \f | |
242 | ;;; | |
243 | ;;; Interface functions to the backends. | |
244 | ;;; | |
245 | ||
20a673b2 KY |
246 | (defun gnus-method-denied-p (method) |
247 | (eq (nth 1 (assoc method gnus-opened-servers)) | |
248 | 'denied)) | |
249 | ||
cd001b8c | 250 | (defvar gnus-backend-trace nil) |
b069e5a6 | 251 | |
6748645f LMI |
252 | (defun gnus-open-server (gnus-command-method) |
253 | "Open a connection to GNUS-COMMAND-METHOD." | |
254 | (when (stringp gnus-command-method) | |
255 | (setq gnus-command-method (gnus-server-to-method gnus-command-method))) | |
b069e5a6 G |
256 | (when gnus-backend-trace |
257 | (with-current-buffer (get-buffer-create "*gnus trace*") | |
258 | (buffer-disable-undo) | |
259 | (goto-char (point-max)) | |
260 | (insert (format-time-string "%H:%M:%S") | |
261 | (format " %S\n" gnus-command-method)))) | |
01c52d31 MB |
262 | (let ((elem (assoc gnus-command-method gnus-opened-servers)) |
263 | (server (gnus-method-to-server-name gnus-command-method))) | |
eec82323 LMI |
264 | ;; If this method was previously denied, we just return nil. |
265 | (if (eq (nth 1 elem) 'denied) | |
266 | (progn | |
e21bac42 G |
267 | (gnus-message |
268 | 1 "Server %s previously determined to be down; not retrying" server) | |
eec82323 LMI |
269 | nil) |
270 | ;; Open the server. | |
04db63bc G |
271 | (let* ((open-server-function |
272 | (gnus-get-function gnus-command-method 'open-server)) | |
23f87bed | 273 | (result |
04db63bc G |
274 | (condition-case err |
275 | (funcall open-server-function | |
276 | (nth 1 gnus-command-method) | |
277 | (nthcdr 2 gnus-command-method)) | |
278 | (error | |
279 | (gnus-message 1 "Unable to open server %s due to: %s" | |
280 | server (error-message-string err)) | |
281 | nil) | |
282 | (quit | |
a123622d G |
283 | (if debug-on-quit |
284 | (debug "Quit") | |
285 | (gnus-message 1 "Quit trying to open server %s" server)) | |
04db63bc G |
286 | nil))) |
287 | open-offline) | |
eec82323 LMI |
288 | ;; If this hasn't been opened before, we add it to the list. |
289 | (unless elem | |
6748645f | 290 | (setq elem (list gnus-command-method nil) |
eec82323 LMI |
291 | gnus-opened-servers (cons elem gnus-opened-servers))) |
292 | ;; Set the status of this server. | |
8ccbef23 G |
293 | (setcar |
294 | (cdr elem) | |
295 | (cond (result | |
296 | (if (eq open-server-function #'nnagent-open-server) | |
297 | ;; The agent's backend has a "special" status | |
298 | 'offline | |
299 | 'ok)) | |
300 | ((and gnus-agent | |
301 | (gnus-agent-method-p gnus-command-method)) | |
302 | (cond | |
303 | (gnus-server-unopen-status | |
304 | ;; Set the server's status to the unopen | |
305 | ;; status. If that status is offline, | |
306 | ;; recurse to open the agent's backend. | |
307 | (setq open-offline (eq gnus-server-unopen-status 'offline)) | |
308 | gnus-server-unopen-status) | |
309 | ((not gnus-batch-mode) | |
310 | (setq open-offline t) | |
311 | 'offline) | |
312 | (t | |
313 | ;; This agentized server was still denied | |
314 | 'denied))) | |
315 | (t | |
316 | ;; This unagentized server must be denied | |
317 | 'denied))) | |
23f87bed MB |
318 | |
319 | ;; NOTE: I MUST set the server's status to offline before this | |
320 | ;; recursive call as this status will drive the | |
321 | ;; gnus-get-function (called above) to return the agent's | |
322 | ;; backend. | |
323 | (if open-offline | |
324 | ;; Recursively open this offline server to perform the | |
325 | ;; open-server function of the agent's backend. | |
326 | (let ((gnus-server-unopen-status 'denied)) | |
327 | ;; Bind gnus-server-unopen-status to avoid recursively | |
328 | ;; prompting with "go offline?". This is only a concern | |
329 | ;; when the agent's backend fails to open the server. | |
330 | (gnus-open-server gnus-command-method)) | |
b890d447 MB |
331 | (when (and (eq (cadr elem) 'ok) gnus-agent |
332 | (gnus-agent-method-p gnus-command-method)) | |
333 | (save-excursion | |
334 | (gnus-agent-possibly-synchronize-flags-server | |
335 | gnus-command-method))) | |
23f87bed | 336 | result))))) |
eec82323 | 337 | |
6748645f LMI |
338 | (defun gnus-close-server (gnus-command-method) |
339 | "Close the connection to GNUS-COMMAND-METHOD." | |
340 | (when (stringp gnus-command-method) | |
341 | (setq gnus-command-method (gnus-server-to-method gnus-command-method))) | |
342 | (funcall (gnus-get-function gnus-command-method 'close-server) | |
343 | (nth 1 gnus-command-method))) | |
344 | ||
345 | (defun gnus-request-list (gnus-command-method) | |
346 | "Request the active file from GNUS-COMMAND-METHOD." | |
347 | (when (stringp gnus-command-method) | |
348 | (setq gnus-command-method (gnus-server-to-method gnus-command-method))) | |
349 | (funcall (gnus-get-function gnus-command-method 'request-list) | |
350 | (nth 1 gnus-command-method))) | |
351 | ||
20a673b2 KY |
352 | (defun gnus-finish-retrieve-group-infos (gnus-command-method infos data) |
353 | "Read and update infos from GNUS-COMMAND-METHOD." | |
354 | (when (stringp gnus-command-method) | |
355 | (setq gnus-command-method (gnus-server-to-method gnus-command-method))) | |
356 | (funcall (gnus-get-function gnus-command-method 'finish-retrieve-group-infos) | |
357 | (nth 1 gnus-command-method) | |
358 | infos data)) | |
359 | ||
360 | (defun gnus-retrieve-group-data-early (gnus-command-method infos) | |
9858f6c3 | 361 | "Start early async retrieval of data from GNUS-COMMAND-METHOD." |
20a673b2 KY |
362 | (when (stringp gnus-command-method) |
363 | (setq gnus-command-method (gnus-server-to-method gnus-command-method))) | |
364 | (funcall (gnus-get-function gnus-command-method 'retrieve-group-data-early) | |
365 | (nth 1 gnus-command-method) | |
366 | infos)) | |
367 | ||
6748645f LMI |
368 | (defun gnus-request-list-newsgroups (gnus-command-method) |
369 | "Request the newsgroups file from GNUS-COMMAND-METHOD." | |
370 | (when (stringp gnus-command-method) | |
371 | (setq gnus-command-method (gnus-server-to-method gnus-command-method))) | |
372 | (funcall (gnus-get-function gnus-command-method 'request-list-newsgroups) | |
373 | (nth 1 gnus-command-method))) | |
374 | ||
375 | (defun gnus-request-newgroups (date gnus-command-method) | |
376 | "Request all new groups since DATE from GNUS-COMMAND-METHOD." | |
377 | (when (stringp gnus-command-method) | |
378 | (setq gnus-command-method (gnus-server-to-method gnus-command-method))) | |
379 | (let ((func (gnus-get-function gnus-command-method 'request-newgroups t))) | |
eec82323 | 380 | (when func |
6748645f LMI |
381 | (funcall func date (nth 1 gnus-command-method))))) |
382 | ||
6748645f LMI |
383 | (defun gnus-request-regenerate (gnus-command-method) |
384 | "Request a data generation from GNUS-COMMAND-METHOD." | |
385 | (when (stringp gnus-command-method) | |
386 | (setq gnus-command-method (gnus-server-to-method gnus-command-method))) | |
387 | (funcall (gnus-get-function gnus-command-method 'request-regenerate) | |
388 | (nth 1 gnus-command-method))) | |
389 | ||
01c52d31 MB |
390 | (defun gnus-request-compact-group (group) |
391 | (let* ((method (gnus-find-method-for-group group)) | |
392 | (gnus-command-method method) | |
393 | (result | |
394 | (funcall (gnus-get-function gnus-command-method | |
395 | 'request-compact-group) | |
396 | (gnus-group-real-name group) | |
397 | (nth 1 gnus-command-method) t))) | |
398 | result)) | |
399 | ||
400 | (defun gnus-request-compact (gnus-command-method) | |
e7719ea1 | 401 | "Request groups compaction from GNUS-COMMAND-METHOD." |
01c52d31 MB |
402 | (when (stringp gnus-command-method) |
403 | (setq gnus-command-method (gnus-server-to-method gnus-command-method))) | |
404 | (funcall (gnus-get-function gnus-command-method 'request-compact) | |
405 | (nth 1 gnus-command-method))) | |
406 | ||
286c4fc2 | 407 | (defun gnus-request-group (group &optional dont-check gnus-command-method info) |
eec82323 | 408 | "Request GROUP. If DONT-CHECK, no information is required." |
6748645f LMI |
409 | (let ((gnus-command-method |
410 | (or gnus-command-method (inline (gnus-find-method-for-group group))))) | |
411 | (when (stringp gnus-command-method) | |
412 | (setq gnus-command-method | |
413 | (inline (gnus-server-to-method gnus-command-method)))) | |
988818b8 | 414 | (funcall (inline (gnus-get-function gnus-command-method 'request-group)) |
6748645f | 415 | (gnus-group-real-name group) (nth 1 gnus-command-method) |
286c4fc2 LMI |
416 | dont-check |
417 | info))) | |
eec82323 LMI |
418 | |
419 | (defun gnus-list-active-group (group) | |
420 | "Request active information on GROUP." | |
6748645f | 421 | (let ((gnus-command-method (gnus-find-method-for-group group)) |
eec82323 LMI |
422 | (func 'list-active-group)) |
423 | (when (gnus-check-backend-function func group) | |
6748645f LMI |
424 | (funcall (gnus-get-function gnus-command-method func) |
425 | (gnus-group-real-name group) (nth 1 gnus-command-method))))) | |
eec82323 LMI |
426 | |
427 | (defun gnus-request-group-description (group) | |
428 | "Request a description of GROUP." | |
6748645f | 429 | (let ((gnus-command-method (gnus-find-method-for-group group)) |
eec82323 LMI |
430 | (func 'request-group-description)) |
431 | (when (gnus-check-backend-function func group) | |
6748645f LMI |
432 | (funcall (gnus-get-function gnus-command-method func) |
433 | (gnus-group-real-name group) (nth 1 gnus-command-method))))) | |
eec82323 | 434 | |
16409b0b GM |
435 | (defun gnus-request-group-articles (group) |
436 | "Request a list of existing articles in GROUP." | |
437 | (let ((gnus-command-method (gnus-find-method-for-group group)) | |
438 | (func 'request-group-articles)) | |
439 | (when (gnus-check-backend-function func group) | |
440 | (funcall (gnus-get-function gnus-command-method func) | |
441 | (gnus-group-real-name group) (nth 1 gnus-command-method))))) | |
442 | ||
eec82323 LMI |
443 | (defun gnus-close-group (group) |
444 | "Request the GROUP be closed." | |
6748645f LMI |
445 | (let ((gnus-command-method (inline (gnus-find-method-for-group group)))) |
446 | (funcall (gnus-get-function gnus-command-method 'close-group) | |
447 | (gnus-group-real-name group) (nth 1 gnus-command-method)))) | |
eec82323 LMI |
448 | |
449 | (defun gnus-retrieve-headers (articles group &optional fetch-old) | |
450 | "Request headers for ARTICLES in GROUP. | |
451 | If FETCH-OLD, retrieve all headers (or some subset thereof) in the group." | |
6748645f | 452 | (let ((gnus-command-method (gnus-find-method-for-group group))) |
23f87bed MB |
453 | (cond |
454 | ((and gnus-use-cache (numberp (car articles))) | |
455 | (gnus-cache-retrieve-headers articles group fetch-old)) | |
456 | ((and gnus-agent (gnus-online gnus-command-method) | |
457 | (gnus-agent-method-p gnus-command-method)) | |
458 | (gnus-agent-retrieve-headers articles group fetch-old)) | |
459 | (t | |
6748645f LMI |
460 | (funcall (gnus-get-function gnus-command-method 'retrieve-headers) |
461 | articles (gnus-group-real-name group) | |
23f87bed | 462 | (nth 1 gnus-command-method) fetch-old))))) |
6748645f LMI |
463 | |
464 | (defun gnus-retrieve-articles (articles group) | |
465 | "Request ARTICLES in GROUP." | |
466 | (let ((gnus-command-method (gnus-find-method-for-group group))) | |
467 | (funcall (gnus-get-function gnus-command-method 'retrieve-articles) | |
468 | articles (gnus-group-real-name group) | |
469 | (nth 1 gnus-command-method)))) | |
470 | ||
471 | (defun gnus-retrieve-groups (groups gnus-command-method) | |
472 | "Request active information on GROUPS from GNUS-COMMAND-METHOD." | |
473 | (when (stringp gnus-command-method) | |
474 | (setq gnus-command-method (gnus-server-to-method gnus-command-method))) | |
475 | (funcall (gnus-get-function gnus-command-method 'retrieve-groups) | |
476 | groups (nth 1 gnus-command-method))) | |
eec82323 LMI |
477 | |
478 | (defun gnus-request-type (group &optional article) | |
479 | "Return the type (`post' or `mail') of GROUP (and ARTICLE)." | |
6748645f LMI |
480 | (let ((gnus-command-method (gnus-find-method-for-group group))) |
481 | (if (not (gnus-check-backend-function | |
482 | 'request-type (car gnus-command-method))) | |
eec82323 | 483 | 'unknown |
6748645f | 484 | (funcall (gnus-get-function gnus-command-method 'request-type) |
eec82323 LMI |
485 | (gnus-group-real-name group) article)))) |
486 | ||
549c9aed G |
487 | (defun gnus-request-update-group-status (group status) |
488 | "Change the status of a group. | |
489 | Valid statuses include `subscribe' and `unsubscribe'." | |
490 | (let ((gnus-command-method (gnus-find-method-for-group group))) | |
491 | (if (not (gnus-check-backend-function | |
492 | 'request-update-group-status (car gnus-command-method))) | |
493 | nil | |
494 | (funcall | |
495 | (gnus-get-function gnus-command-method 'request-update-group-status) | |
496 | (gnus-group-real-name group) status | |
497 | (nth 1 gnus-command-method))))) | |
498 | ||
16409b0b | 499 | (defun gnus-request-set-mark (group action) |
23f87bed | 500 | "Set marks on articles in the back end." |
16409b0b GM |
501 | (let ((gnus-command-method (gnus-find-method-for-group group))) |
502 | (if (not (gnus-check-backend-function | |
503 | 'request-set-mark (car gnus-command-method))) | |
504 | action | |
505 | (funcall (gnus-get-function gnus-command-method 'request-set-mark) | |
506 | (gnus-group-real-name group) action | |
cbabe91f TZ |
507 | (nth 1 gnus-command-method)) |
508 | (gnus-run-hook-with-args gnus-after-set-mark-hook group action)))) | |
16409b0b | 509 | |
eec82323 | 510 | (defun gnus-request-update-mark (group article mark) |
23f87bed | 511 | "Allow the back end to change the mark the user tries to put on an article." |
6748645f LMI |
512 | (let ((gnus-command-method (gnus-find-method-for-group group))) |
513 | (if (not (gnus-check-backend-function | |
514 | 'request-update-mark (car gnus-command-method))) | |
eec82323 | 515 | mark |
cbabe91f | 516 | (gnus-run-hook-with-args gnus-before-update-mark-hook group article mark) |
6748645f | 517 | (funcall (gnus-get-function gnus-command-method 'request-update-mark) |
eec82323 LMI |
518 | (gnus-group-real-name group) article mark)))) |
519 | ||
520 | (defun gnus-request-article (article group &optional buffer) | |
521 | "Request the ARTICLE in GROUP. | |
522 | ARTICLE can either be an article number or an article Message-ID. | |
523 | If BUFFER, insert the article in that group." | |
6748645f LMI |
524 | (let ((gnus-command-method (gnus-find-method-for-group group))) |
525 | (funcall (gnus-get-function gnus-command-method 'request-article) | |
526 | article (gnus-group-real-name group) | |
527 | (nth 1 gnus-command-method) buffer))) | |
eec82323 | 528 | |
0c136286 | 529 | (defun gnus-request-thread (header group) |
b31b26b4 | 530 | "Request the headers in the thread containing the article specified by HEADER." |
0c136286 | 531 | (let ((gnus-command-method (gnus-find-method-for-group group))) |
030158f3 | 532 | (funcall (gnus-get-function gnus-command-method 'request-thread) |
0c136286 AC |
533 | header |
534 | (gnus-group-real-name group)))) | |
030158f3 | 535 | |
4ddab346 G |
536 | (defun gnus-warp-to-article () |
537 | "Warps from an article in a virtual group to the article in its | |
538 | real group. Does nothing on a real group." | |
539 | (interactive) | |
540 | (let ((gnus-command-method | |
541 | (gnus-find-method-for-group gnus-newsgroup-name))) | |
542 | (when (gnus-check-backend-function | |
543 | 'warp-to-article (car gnus-command-method)) | |
544 | (funcall (gnus-get-function gnus-command-method 'warp-to-article))))) | |
545 | ||
eec82323 LMI |
546 | (defun gnus-request-head (article group) |
547 | "Request the head of ARTICLE in GROUP." | |
6748645f LMI |
548 | (let* ((gnus-command-method (gnus-find-method-for-group group)) |
549 | (head (gnus-get-function gnus-command-method 'request-head t)) | |
eec82323 LMI |
550 | res clean-up) |
551 | (cond | |
552 | ;; Check the cache. | |
553 | ((and gnus-use-cache | |
554 | (numberp article) | |
555 | (gnus-cache-request-article article group)) | |
556 | (setq res (cons group article) | |
557 | clean-up t)) | |
23f87bed MB |
558 | ;; Check the agent cache. |
559 | ((gnus-agent-request-article article group) | |
560 | (setq res (cons group article) | |
561 | clean-up t)) | |
eec82323 LMI |
562 | ;; Use `head' function. |
563 | ((fboundp head) | |
564 | (setq res (funcall head article (gnus-group-real-name group) | |
6748645f | 565 | (nth 1 gnus-command-method)))) |
eec82323 LMI |
566 | ;; Use `article' function. |
567 | (t | |
568 | (setq res (gnus-request-article article group) | |
569 | clean-up t))) | |
570 | (when clean-up | |
20a673b2 | 571 | (with-current-buffer nntp-server-buffer |
eec82323 LMI |
572 | (goto-char (point-min)) |
573 | (when (search-forward "\n\n" nil t) | |
574 | (delete-region (1- (point)) (point-max))) | |
575 | (nnheader-fold-continuation-lines))) | |
576 | res)) | |
577 | ||
578 | (defun gnus-request-body (article group) | |
579 | "Request the body of ARTICLE in GROUP." | |
6748645f LMI |
580 | (let* ((gnus-command-method (gnus-find-method-for-group group)) |
581 | (head (gnus-get-function gnus-command-method 'request-body t)) | |
582 | res clean-up) | |
583 | (cond | |
584 | ;; Check the cache. | |
585 | ((and gnus-use-cache | |
586 | (numberp article) | |
587 | (gnus-cache-request-article article group)) | |
588 | (setq res (cons group article) | |
589 | clean-up t)) | |
23f87bed MB |
590 | ;; Check the agent cache. |
591 | ((gnus-agent-request-article article group) | |
592 | (setq res (cons group article) | |
593 | clean-up t)) | |
6748645f LMI |
594 | ;; Use `head' function. |
595 | ((fboundp head) | |
596 | (setq res (funcall head article (gnus-group-real-name group) | |
597 | (nth 1 gnus-command-method)))) | |
598 | ;; Use `article' function. | |
599 | (t | |
600 | (setq res (gnus-request-article article group) | |
601 | clean-up t))) | |
602 | (when clean-up | |
20a673b2 | 603 | (with-current-buffer nntp-server-buffer |
6748645f LMI |
604 | (goto-char (point-min)) |
605 | (when (search-forward "\n\n" nil t) | |
606 | (delete-region (point-min) (1- (point)))))) | |
607 | res)) | |
eec82323 | 608 | |
6748645f LMI |
609 | (defun gnus-request-post (gnus-command-method) |
610 | "Post the current buffer using GNUS-COMMAND-METHOD." | |
611 | (when (stringp gnus-command-method) | |
612 | (setq gnus-command-method (gnus-server-to-method gnus-command-method))) | |
613 | (funcall (gnus-get-function gnus-command-method 'request-post) | |
614 | (nth 1 gnus-command-method))) | |
615 | ||
0617bb00 LMI |
616 | (defun gnus-request-expunge-group (group gnus-command-method) |
617 | "Expunge GROUP, which is removing articles that have been marked as deleted." | |
618 | (when (stringp gnus-command-method) | |
619 | (setq gnus-command-method (gnus-server-to-method gnus-command-method))) | |
620 | (funcall (gnus-get-function gnus-command-method 'request-expunge-group) | |
621 | (gnus-group-real-name group) | |
622 | (nth 1 gnus-command-method))) | |
623 | ||
6748645f LMI |
624 | (defun gnus-request-scan (group gnus-command-method) |
625 | "Request a SCAN being performed in GROUP from GNUS-COMMAND-METHOD. | |
626 | If GROUP is nil, all groups on GNUS-COMMAND-METHOD are scanned." | |
16409b0b GM |
627 | (let ((gnus-command-method |
628 | (if group (gnus-find-method-for-group group) gnus-command-method)) | |
629 | (gnus-inhibit-demon t) | |
630 | (mail-source-plugged gnus-plugged)) | |
8c3e17f8 LMI |
631 | (when (or gnus-plugged |
632 | (not (gnus-agent-method-p gnus-command-method))) | |
01c52d31 MB |
633 | (setq gnus-internal-registry-spool-current-method gnus-command-method) |
634 | (funcall (gnus-get-function gnus-command-method 'request-scan) | |
635 | (and group (gnus-group-real-name group)) | |
636 | (nth 1 gnus-command-method))))) | |
6748645f | 637 | |
b1ae92ba G |
638 | (defun gnus-request-update-info (info gnus-command-method) |
639 | (when (gnus-check-backend-function | |
640 | 'request-update-info (car gnus-command-method)) | |
641 | (when (stringp gnus-command-method) | |
642 | (setq gnus-command-method (gnus-server-to-method gnus-command-method))) | |
643 | (funcall (gnus-get-function gnus-command-method 'request-update-info) | |
644 | (gnus-group-real-name (gnus-info-group info)) info | |
645 | (nth 1 gnus-command-method)))) | |
646 | ||
647 | (defsubst gnus-request-marks (info gnus-command-method) | |
6748645f LMI |
648 | "Request that GNUS-COMMAND-METHOD update INFO." |
649 | (when (stringp gnus-command-method) | |
650 | (setq gnus-command-method (gnus-server-to-method gnus-command-method))) | |
651 | (when (gnus-check-backend-function | |
b1ae92ba | 652 | 'request-marks (car gnus-command-method)) |
23f87bed | 653 | (let ((group (gnus-info-group info))) |
9da02ea1 | 654 | (and (funcall (gnus-get-function gnus-command-method 'request-marks) |
23f87bed MB |
655 | (gnus-group-real-name group) |
656 | info (nth 1 gnus-command-method)) | |
657 | ;; If the minimum article number is greater than 1, then all | |
658 | ;; smaller article numbers are known not to exist; we'll | |
659 | ;; artificially add those to the 'read range. | |
660 | (let* ((active (gnus-active group)) | |
661 | (min (car active))) | |
662 | (when (> min 1) | |
663 | (let* ((range (if (= min 2) 1 (cons 1 (1- min)))) | |
664 | (read (gnus-info-read info)) | |
665 | (new-read (gnus-range-add read (list range)))) | |
666 | (gnus-info-set-read info new-read))) | |
667 | info))))) | |
eec82323 LMI |
668 | |
669 | (defun gnus-request-expire-articles (articles group &optional force) | |
23f87bed | 670 | (let* ((gnus-command-method (gnus-find-method-for-group group)) |
b069e5a6 | 671 | (gnus-inhibit-demon t) |
23f87bed MB |
672 | (not-deleted |
673 | (funcall | |
674 | (gnus-get-function gnus-command-method 'request-expire-articles) | |
675 | articles (gnus-group-real-name group) (nth 1 gnus-command-method) | |
676 | force))) | |
677 | (when (and gnus-agent | |
678 | (gnus-agent-method-p gnus-command-method)) | |
679 | (let ((expired-articles (gnus-sorted-difference articles not-deleted))) | |
680 | (when expired-articles | |
681 | (gnus-agent-expire expired-articles group 'force)))) | |
682 | not-deleted)) | |
683 | ||
684 | (defun gnus-request-move-article (article group server accept-function | |
01c52d31 | 685 | &optional last move-is-internal) |
23f87bed MB |
686 | (let* ((gnus-command-method (gnus-find-method-for-group group)) |
687 | (result (funcall (gnus-get-function gnus-command-method | |
688 | 'request-move-article) | |
689 | article (gnus-group-real-name group) | |
b5c575e6 G |
690 | (nth 1 gnus-command-method) accept-function |
691 | last move-is-internal))) | |
23f87bed MB |
692 | (when (and result gnus-agent |
693 | (gnus-agent-method-p gnus-command-method)) | |
54506618 | 694 | (gnus-agent-unfetch-articles group (list article))) |
23f87bed | 695 | result)) |
bf247b6e | 696 | |
16409b0b GM |
697 | (defun gnus-request-accept-article (group &optional gnus-command-method last |
698 | no-encode) | |
eec82323 | 699 | ;; Make sure there's a newline at the end of the article. |
6748645f LMI |
700 | (when (stringp gnus-command-method) |
701 | (setq gnus-command-method (gnus-server-to-method gnus-command-method))) | |
702 | (when (and (not gnus-command-method) | |
eec82323 | 703 | (stringp group)) |
54506618 MB |
704 | (setq gnus-command-method (or (gnus-find-method-for-group group) |
705 | (gnus-group-name-to-method group)))) | |
eec82323 LMI |
706 | (goto-char (point-max)) |
707 | (unless (bolp) | |
708 | (insert "\n")) | |
16409b0b | 709 | (unless no-encode |
23f87bed MB |
710 | (let ((message-options message-options)) |
711 | (message-options-set-recipient) | |
712 | (save-restriction | |
713 | (message-narrow-to-head) | |
714 | (let ((mail-parse-charset message-default-charset)) | |
715 | (mail-encode-encoded-word-buffer))) | |
716 | (message-encode-message-body))) | |
01c52d31 | 717 | (let ((gnus-command-method (or gnus-command-method |
54506618 | 718 | (gnus-find-method-for-group group))) |
bf247b6e KS |
719 | (result |
720 | (funcall | |
54506618 MB |
721 | (gnus-get-function gnus-command-method 'request-accept-article) |
722 | (if (stringp group) (gnus-group-real-name group) group) | |
723 | (cadr gnus-command-method) | |
724 | last))) | |
c516cd6d LMI |
725 | (when (and gnus-agent |
726 | (gnus-agent-method-p gnus-command-method) | |
727 | (cdr result)) | |
54506618 MB |
728 | (gnus-agent-regenerate-group group (list (cdr result)))) |
729 | result)) | |
eec82323 | 730 | |
16409b0b GM |
731 | (defun gnus-request-replace-article (article group buffer &optional no-encode) |
732 | (unless no-encode | |
23f87bed MB |
733 | (let ((message-options message-options)) |
734 | (message-options-set-recipient) | |
735 | (save-restriction | |
736 | (message-narrow-to-head) | |
737 | (let ((mail-parse-charset message-default-charset)) | |
738 | (mail-encode-encoded-word-buffer))) | |
739 | (message-encode-message-body))) | |
54506618 MB |
740 | (let* ((func (car (gnus-group-name-to-method group))) |
741 | (result (funcall (intern (format "%s-request-replace-article" func)) | |
742 | article (gnus-group-real-name group) buffer))) | |
743 | (when (and gnus-agent (gnus-agent-method-p gnus-command-method)) | |
744 | (gnus-agent-regenerate-group group (list article))) | |
745 | result)) | |
eec82323 LMI |
746 | |
747 | (defun gnus-request-associate-buffer (group) | |
6748645f LMI |
748 | (let ((gnus-command-method (gnus-find-method-for-group group))) |
749 | (funcall (gnus-get-function gnus-command-method 'request-associate-buffer) | |
eec82323 LMI |
750 | (gnus-group-real-name group)))) |
751 | ||
752 | (defun gnus-request-restore-buffer (article group) | |
753 | "Request a new buffer restored to the state of ARTICLE." | |
6748645f LMI |
754 | (let ((gnus-command-method (gnus-find-method-for-group group))) |
755 | (funcall (gnus-get-function gnus-command-method 'request-restore-buffer) | |
756 | article (gnus-group-real-name group) | |
757 | (nth 1 gnus-command-method)))) | |
eec82323 | 758 | |
6748645f LMI |
759 | (defun gnus-request-create-group (group &optional gnus-command-method args) |
760 | (when (stringp gnus-command-method) | |
761 | (setq gnus-command-method (gnus-server-to-method gnus-command-method))) | |
762 | (let ((gnus-command-method | |
763 | (or gnus-command-method (gnus-find-method-for-group group)))) | |
764 | (funcall (gnus-get-function gnus-command-method 'request-create-group) | |
765 | (gnus-group-real-name group) (nth 1 gnus-command-method) args))) | |
eec82323 LMI |
766 | |
767 | (defun gnus-request-delete-group (group &optional force) | |
54506618 MB |
768 | (let* ((gnus-command-method (gnus-find-method-for-group group)) |
769 | (result | |
770 | (funcall (gnus-get-function gnus-command-method 'request-delete-group) | |
771 | (gnus-group-real-name group) force (nth 1 gnus-command-method)))) | |
772 | (when result | |
773 | (gnus-cache-delete-group group) | |
774 | (gnus-agent-delete-group group)) | |
775 | result)) | |
eec82323 LMI |
776 | |
777 | (defun gnus-request-rename-group (group new-name) | |
54506618 MB |
778 | (let* ((gnus-command-method (gnus-find-method-for-group group)) |
779 | (result | |
780 | (funcall (gnus-get-function gnus-command-method 'request-rename-group) | |
781 | (gnus-group-real-name group) | |
782 | (gnus-group-real-name new-name) (nth 1 gnus-command-method)))) | |
783 | (when result | |
784 | (gnus-cache-rename-group group new-name) | |
785 | (gnus-agent-rename-group group new-name)) | |
786 | result)) | |
eec82323 LMI |
787 | |
788 | (defun gnus-close-backends () | |
789 | ;; Send a close request to all backends that support such a request. | |
790 | (let ((methods gnus-valid-select-methods) | |
791 | (gnus-inhibit-demon t) | |
6748645f LMI |
792 | func gnus-command-method) |
793 | (while (setq gnus-command-method (pop methods)) | |
eec82323 | 794 | (when (fboundp (setq func (intern |
6748645f LMI |
795 | (concat (car gnus-command-method) |
796 | "-request-close")))) | |
eec82323 LMI |
797 | (funcall func))))) |
798 | ||
6748645f LMI |
799 | (defun gnus-asynchronous-p (gnus-command-method) |
800 | (let ((func (gnus-get-function gnus-command-method 'asynchronous-p t))) | |
eec82323 LMI |
801 | (when (fboundp func) |
802 | (funcall func)))) | |
803 | ||
6748645f LMI |
804 | (defun gnus-remove-denial (gnus-command-method) |
805 | (when (stringp gnus-command-method) | |
806 | (setq gnus-command-method (gnus-server-to-method gnus-command-method))) | |
807 | (let* ((elem (assoc gnus-command-method gnus-opened-servers)) | |
eec82323 LMI |
808 | (status (cadr elem))) |
809 | ;; If this hasn't been opened before, we add it to the list. | |
810 | (when (eq status 'denied) | |
811 | ;; Set the status of this server. | |
812 | (setcar (cdr elem) 'closed)))) | |
813 | ||
814 | (provide 'gnus-int) | |
815 | ||
816 | ;;; gnus-int.el ends here |