Commit | Line | Data |
---|---|---|
eec82323 | 1 | ;;; gnus-int.el --- backend interface functions for Gnus |
e84b4b86 TTN |
2 | |
3 | ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 | |
e3fe4da0 | 4 | ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
eec82323 | 5 | |
6748645f | 6 | ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org> |
eec82323 LMI |
7 | ;; Keywords: news |
8 | ||
9 | ;; This file is part of GNU Emacs. | |
10 | ||
11 | ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 | ;; it under the terms of the GNU General Public License as published by | |
5a9dffec | 13 | ;; the Free Software Foundation; either version 3, or (at your option) |
eec82323 LMI |
14 | ;; any later version. |
15 | ||
16 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | ;; GNU General Public License for more details. | |
20 | ||
21 | ;; You should have received a copy of the GNU General Public License | |
22 | ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
3a35cf56 LK |
23 | ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
24 | ;; Boston, MA 02110-1301, USA. | |
eec82323 LMI |
25 | |
26 | ;;; Commentary: | |
27 | ||
28 | ;;; Code: | |
29 | ||
249ffa67 RS |
30 | (eval-when-compile (require 'cl)) |
31 | ||
eec82323 | 32 | (require 'gnus) |
23f87bed MB |
33 | (require 'message) |
34 | (require 'gnus-range) | |
35 | ||
36 | (autoload 'gnus-agent-expire "gnus-agent") | |
54506618 | 37 | (autoload 'gnus-agent-regenerate-group "gnus-agent") |
23f87bed | 38 | (autoload 'gnus-agent-read-servers-validate-native "gnus-agent") |
b890d447 | 39 | (autoload 'gnus-agent-possibly-synchronize-flags-server "gnus-agent") |
eec82323 LMI |
40 | |
41 | (defcustom gnus-open-server-hook nil | |
42 | "Hook called just before opening connection to the news server." | |
43 | :group 'gnus-start | |
44 | :type 'hook) | |
45 | ||
23f87bed MB |
46 | (defcustom gnus-server-unopen-status nil |
47 | "The default status if the server is not able to open. | |
48 | If the server is covered by Gnus agent, the possible values are | |
49 | `denied', set the server denied; `offline', set the server offline; | |
50 | nil, ask user. If the server is not covered by Gnus agent, set the | |
51 | server denied." | |
bf247b6e | 52 | :version "22.1" |
23f87bed MB |
53 | :group 'gnus-start |
54 | :type '(choice (const :tag "Ask" nil) | |
55 | (const :tag "Deny server" denied) | |
56 | (const :tag "Unplug Agent" offline))) | |
57 | ||
58 | (defvar gnus-internal-registry-spool-current-method nil | |
59 | "The current method, for the registry.") | |
60 | ||
fe86b5e0 GM |
61 | |
62 | (defun gnus-server-opened (gnus-command-method) | |
63 | "Check whether a connection to GNUS-COMMAND-METHOD has been opened." | |
64 | (unless (eq (gnus-server-status gnus-command-method) | |
65 | 'denied) | |
66 | (when (stringp gnus-command-method) | |
67 | (setq gnus-command-method (gnus-server-to-method gnus-command-method))) | |
68 | (funcall (inline (gnus-get-function gnus-command-method 'server-opened)) | |
69 | (nth 1 gnus-command-method)))) | |
70 | ||
71 | (defun gnus-status-message (gnus-command-method) | |
72 | "Return the status message from GNUS-COMMAND-METHOD. | |
73 | If GNUS-COMMAND-METHOD is a string, it is interpreted as a group | |
74 | name. The method this group uses will be queried." | |
75 | (let ((gnus-command-method | |
76 | (if (stringp gnus-command-method) | |
77 | (gnus-find-method-for-group gnus-command-method) | |
78 | gnus-command-method))) | |
79 | (funcall (gnus-get-function gnus-command-method 'status-message) | |
80 | (nth 1 gnus-command-method)))) | |
81 | ||
eec82323 LMI |
82 | ;;; |
83 | ;;; Server Communication | |
84 | ;;; | |
85 | ||
86 | (defun gnus-start-news-server (&optional confirm) | |
87 | "Open a method for getting news. | |
88 | If CONFIRM is non-nil, the user will be asked for an NNTP server." | |
89 | (let (how) | |
90 | (if gnus-current-select-method | |
91 | ;; Stream is already opened. | |
92 | nil | |
93 | ;; Open NNTP server. | |
94 | (unless gnus-nntp-service | |
95 | (setq gnus-nntp-server nil)) | |
96 | (when confirm | |
97 | ;; Read server name with completion. | |
98 | (setq gnus-nntp-server | |
99 | (completing-read "NNTP server: " | |
01c52d31 | 100 | (mapcar 'list |
eec82323 LMI |
101 | (cons (list gnus-nntp-server) |
102 | gnus-secondary-servers)) | |
103 | nil nil gnus-nntp-server))) | |
104 | ||
105 | (when (and gnus-nntp-server | |
106 | (stringp gnus-nntp-server) | |
107 | (not (string= gnus-nntp-server ""))) | |
108 | (setq gnus-select-method | |
109 | (cond ((or (string= gnus-nntp-server "") | |
110 | (string= gnus-nntp-server "::")) | |
111 | (list 'nnspool (system-name))) | |
112 | ((string-match "^:" gnus-nntp-server) | |
113 | (list 'nnmh gnus-nntp-server | |
114 | (list 'nnmh-directory | |
115 | (file-name-as-directory | |
116 | (expand-file-name | |
31f35b6f | 117 | (substring gnus-nntp-server 1) "~/"))) |
eec82323 LMI |
118 | (list 'nnmh-get-new-mail nil))) |
119 | (t | |
120 | (list 'nntp gnus-nntp-server))))) | |
121 | ||
122 | (setq how (car gnus-select-method)) | |
123 | (cond | |
124 | ((eq how 'nnspool) | |
125 | (require 'nnspool) | |
126 | (gnus-message 5 "Looking up local news spool...")) | |
127 | ((eq how 'nnmh) | |
128 | (require 'nnmh) | |
129 | (gnus-message 5 "Looking up mh spool...")) | |
130 | (t | |
131 | (require 'nntp))) | |
132 | (setq gnus-current-select-method gnus-select-method) | |
6748645f | 133 | (gnus-run-hooks 'gnus-open-server-hook) |
23f87bed MB |
134 | |
135 | ;; Partially validate agent covered methods now that the | |
136 | ;; gnus-select-method is known. | |
137 | ||
138 | (if gnus-agent | |
139 | ;; NOTE: This is here for one purpose only. By validating | |
140 | ;; the current select method, it converts the old 5.10.3, | |
141 | ;; and earlier, format to the current format. That enables | |
142 | ;; the agent code within gnus-open-server to function | |
143 | ;; correctly. | |
144 | (gnus-agent-read-servers-validate-native gnus-select-method)) | |
145 | ||
eec82323 LMI |
146 | (or |
147 | ;; gnus-open-server-hook might have opened it | |
148 | (gnus-server-opened gnus-select-method) | |
149 | (gnus-open-server gnus-select-method) | |
16409b0b | 150 | gnus-batch-mode |
eec82323 LMI |
151 | (gnus-y-or-n-p |
152 | (format | |
153 | "%s (%s) open error: '%s'. Continue? " | |
154 | (car gnus-select-method) (cadr gnus-select-method) | |
155 | (gnus-status-message gnus-select-method))) | |
156 | (gnus-error 1 "Couldn't open server on %s" | |
157 | (nth 1 gnus-select-method)))))) | |
158 | ||
159 | (defun gnus-check-group (group) | |
160 | "Try to make sure that the server where GROUP exists is alive." | |
161 | (let ((method (gnus-find-method-for-group group))) | |
162 | (or (gnus-server-opened method) | |
163 | (gnus-open-server method)))) | |
164 | ||
165 | (defun gnus-check-server (&optional method silent) | |
166 | "Check whether the connection to METHOD is down. | |
167 | If METHOD is nil, use `gnus-select-method'. | |
168 | If it is down, start it up (again)." | |
23f87bed MB |
169 | (let ((method (or method gnus-select-method)) |
170 | result) | |
eec82323 LMI |
171 | ;; Transform virtual server names into select methods. |
172 | (when (stringp method) | |
173 | (setq method (gnus-server-to-method method))) | |
174 | (if (gnus-server-opened method) | |
175 | ;; The stream is already opened. | |
176 | t | |
177 | ;; Open the server. | |
178 | (unless silent | |
179 | (gnus-message 5 "Opening %s server%s..." (car method) | |
180 | (if (equal (nth 1 method) "") "" | |
181 | (format " on %s" (nth 1 method))))) | |
6748645f | 182 | (gnus-run-hooks 'gnus-open-server-hook) |
eec82323 | 183 | (prog1 |
23f87bed MB |
184 | (condition-case () |
185 | (setq result (gnus-open-server method)) | |
186 | (quit (message "Quit gnus-check-server") | |
187 | nil)) | |
eec82323 | 188 | (unless silent |
23f87bed MB |
189 | (gnus-message 5 "Opening %s server%s...%s" (car method) |
190 | (if (equal (nth 1 method) "") "" | |
191 | (format " on %s" (nth 1 method))) | |
192 | (if result "done" "failed"))))))) | |
eec82323 LMI |
193 | |
194 | (defun gnus-get-function (method function &optional noerror) | |
195 | "Return a function symbol based on METHOD and FUNCTION." | |
196 | ;; Translate server names into methods. | |
197 | (unless method | |
198 | (error "Attempted use of a nil select method")) | |
199 | (when (stringp method) | |
200 | (setq method (gnus-server-to-method method))) | |
6748645f LMI |
201 | ;; Check cache of constructed names. |
202 | (let* ((method-sym (if gnus-agent | |
54506618 | 203 | (inline (gnus-agent-get-function method)) |
6748645f LMI |
204 | (car method))) |
205 | (method-fns (get method-sym 'gnus-method-functions)) | |
206 | (func (let ((method-fnlist-elt (assq function method-fns))) | |
207 | (unless method-fnlist-elt | |
208 | (setq method-fnlist-elt | |
209 | (cons function | |
210 | (intern (format "%s-%s" method-sym function)))) | |
211 | (put method-sym 'gnus-method-functions | |
212 | (cons method-fnlist-elt method-fns))) | |
213 | (cdr method-fnlist-elt)))) | |
214 | ;; Maybe complain if there is no function. | |
eec82323 | 215 | (unless (fboundp func) |
6748645f LMI |
216 | (unless (car method) |
217 | (error "Trying to require a method that doesn't exist")) | |
eec82323 | 218 | (require (car method)) |
6748645f LMI |
219 | (when (not (fboundp func)) |
220 | (if noerror | |
221 | (setq func nil) | |
222 | (error "No such function: %s" func)))) | |
eec82323 LMI |
223 | func)) |
224 | ||
225 | \f | |
226 | ;;; | |
227 | ;;; Interface functions to the backends. | |
228 | ;;; | |
229 | ||
6748645f LMI |
230 | (defun gnus-open-server (gnus-command-method) |
231 | "Open a connection to GNUS-COMMAND-METHOD." | |
232 | (when (stringp gnus-command-method) | |
233 | (setq gnus-command-method (gnus-server-to-method gnus-command-method))) | |
01c52d31 MB |
234 | (let ((elem (assoc gnus-command-method gnus-opened-servers)) |
235 | (server (gnus-method-to-server-name gnus-command-method))) | |
eec82323 LMI |
236 | ;; If this method was previously denied, we just return nil. |
237 | (if (eq (nth 1 elem) 'denied) | |
238 | (progn | |
01c52d31 | 239 | (gnus-message 1 "Denied server %s" server) |
eec82323 LMI |
240 | nil) |
241 | ;; Open the server. | |
23f87bed MB |
242 | (let* ((open-server-function (gnus-get-function gnus-command-method 'open-server)) |
243 | (result | |
244 | (condition-case err | |
245 | (funcall open-server-function | |
246 | (nth 1 gnus-command-method) | |
247 | (nthcdr 2 gnus-command-method)) | |
248 | (error | |
249 | (gnus-message 1 (format | |
01c52d31 MB |
250 | "Unable to open server %s due to: %s" |
251 | server (error-message-string err))) | |
23f87bed MB |
252 | nil) |
253 | (quit | |
01c52d31 | 254 | (gnus-message 1 "Quit trying to open server %s" server) |
23f87bed MB |
255 | nil))) |
256 | open-offline) | |
eec82323 LMI |
257 | ;; If this hasn't been opened before, we add it to the list. |
258 | (unless elem | |
6748645f | 259 | (setq elem (list gnus-command-method nil) |
eec82323 LMI |
260 | gnus-opened-servers (cons elem gnus-opened-servers))) |
261 | ;; Set the status of this server. | |
23f87bed MB |
262 | (setcar (cdr elem) |
263 | (cond (result | |
264 | (if (eq open-server-function #'nnagent-open-server) | |
265 | ;; The agent's backend has a "special" status | |
266 | 'offline | |
267 | 'ok)) | |
268 | ((and gnus-agent | |
269 | (gnus-agent-method-p gnus-command-method)) | |
270 | (cond (gnus-server-unopen-status | |
271 | ;; Set the server's status to the unopen | |
272 | ;; status. If that status is offline, | |
273 | ;; recurse to open the agent's backend. | |
274 | (setq open-offline (eq gnus-server-unopen-status 'offline)) | |
275 | gnus-server-unopen-status) | |
719120ef MB |
276 | ((and |
277 | (not gnus-batch-mode) | |
278 | (gnus-y-or-n-p | |
01c52d31 MB |
279 | (format |
280 | "Unable to open server %s, go offline? " | |
281 | server))) | |
23f87bed MB |
282 | (setq open-offline t) |
283 | 'offline) | |
284 | (t | |
285 | ;; This agentized server was still denied | |
286 | 'denied))) | |
287 | (t | |
288 | ;; This unagentized server must be denied | |
289 | 'denied))) | |
290 | ||
291 | ;; NOTE: I MUST set the server's status to offline before this | |
292 | ;; recursive call as this status will drive the | |
293 | ;; gnus-get-function (called above) to return the agent's | |
294 | ;; backend. | |
295 | (if open-offline | |
296 | ;; Recursively open this offline server to perform the | |
297 | ;; open-server function of the agent's backend. | |
298 | (let ((gnus-server-unopen-status 'denied)) | |
299 | ;; Bind gnus-server-unopen-status to avoid recursively | |
300 | ;; prompting with "go offline?". This is only a concern | |
301 | ;; when the agent's backend fails to open the server. | |
302 | (gnus-open-server gnus-command-method)) | |
b890d447 MB |
303 | (when (and (eq (cadr elem) 'ok) gnus-agent |
304 | (gnus-agent-method-p gnus-command-method)) | |
305 | (save-excursion | |
306 | (gnus-agent-possibly-synchronize-flags-server | |
307 | gnus-command-method))) | |
23f87bed | 308 | result))))) |
eec82323 | 309 | |
6748645f LMI |
310 | (defun gnus-close-server (gnus-command-method) |
311 | "Close the connection to GNUS-COMMAND-METHOD." | |
312 | (when (stringp gnus-command-method) | |
313 | (setq gnus-command-method (gnus-server-to-method gnus-command-method))) | |
314 | (funcall (gnus-get-function gnus-command-method 'close-server) | |
315 | (nth 1 gnus-command-method))) | |
316 | ||
317 | (defun gnus-request-list (gnus-command-method) | |
318 | "Request the active file from GNUS-COMMAND-METHOD." | |
319 | (when (stringp gnus-command-method) | |
320 | (setq gnus-command-method (gnus-server-to-method gnus-command-method))) | |
321 | (funcall (gnus-get-function gnus-command-method 'request-list) | |
322 | (nth 1 gnus-command-method))) | |
323 | ||
324 | (defun gnus-request-list-newsgroups (gnus-command-method) | |
325 | "Request the newsgroups file from GNUS-COMMAND-METHOD." | |
326 | (when (stringp gnus-command-method) | |
327 | (setq gnus-command-method (gnus-server-to-method gnus-command-method))) | |
328 | (funcall (gnus-get-function gnus-command-method 'request-list-newsgroups) | |
329 | (nth 1 gnus-command-method))) | |
330 | ||
331 | (defun gnus-request-newgroups (date gnus-command-method) | |
332 | "Request all new groups since DATE from GNUS-COMMAND-METHOD." | |
333 | (when (stringp gnus-command-method) | |
334 | (setq gnus-command-method (gnus-server-to-method gnus-command-method))) | |
335 | (let ((func (gnus-get-function gnus-command-method 'request-newgroups t))) | |
eec82323 | 336 | (when func |
6748645f LMI |
337 | (funcall func date (nth 1 gnus-command-method))))) |
338 | ||
6748645f LMI |
339 | (defun gnus-request-regenerate (gnus-command-method) |
340 | "Request a data generation from GNUS-COMMAND-METHOD." | |
341 | (when (stringp gnus-command-method) | |
342 | (setq gnus-command-method (gnus-server-to-method gnus-command-method))) | |
343 | (funcall (gnus-get-function gnus-command-method 'request-regenerate) | |
344 | (nth 1 gnus-command-method))) | |
345 | ||
01c52d31 MB |
346 | (defun gnus-request-compact-group (group) |
347 | (let* ((method (gnus-find-method-for-group group)) | |
348 | (gnus-command-method method) | |
349 | (result | |
350 | (funcall (gnus-get-function gnus-command-method | |
351 | 'request-compact-group) | |
352 | (gnus-group-real-name group) | |
353 | (nth 1 gnus-command-method) t))) | |
354 | result)) | |
355 | ||
356 | (defun gnus-request-compact (gnus-command-method) | |
357 | "Request groups compaction from GNUS-COMMAND-METHOD." | |
358 | (when (stringp gnus-command-method) | |
359 | (setq gnus-command-method (gnus-server-to-method gnus-command-method))) | |
360 | (funcall (gnus-get-function gnus-command-method 'request-compact) | |
361 | (nth 1 gnus-command-method))) | |
362 | ||
6748645f | 363 | (defun gnus-request-group (group &optional dont-check gnus-command-method) |
eec82323 | 364 | "Request GROUP. If DONT-CHECK, no information is required." |
6748645f LMI |
365 | (let ((gnus-command-method |
366 | (or gnus-command-method (inline (gnus-find-method-for-group group))))) | |
367 | (when (stringp gnus-command-method) | |
368 | (setq gnus-command-method | |
369 | (inline (gnus-server-to-method gnus-command-method)))) | |
01c52d31 | 370 | (funcall (inline (gnus-get-function gnus-command-method 'request-group)) |
6748645f LMI |
371 | (gnus-group-real-name group) (nth 1 gnus-command-method) |
372 | dont-check))) | |
eec82323 LMI |
373 | |
374 | (defun gnus-list-active-group (group) | |
375 | "Request active information on GROUP." | |
6748645f | 376 | (let ((gnus-command-method (gnus-find-method-for-group group)) |
eec82323 LMI |
377 | (func 'list-active-group)) |
378 | (when (gnus-check-backend-function func group) | |
6748645f LMI |
379 | (funcall (gnus-get-function gnus-command-method func) |
380 | (gnus-group-real-name group) (nth 1 gnus-command-method))))) | |
eec82323 LMI |
381 | |
382 | (defun gnus-request-group-description (group) | |
383 | "Request a description of GROUP." | |
6748645f | 384 | (let ((gnus-command-method (gnus-find-method-for-group group)) |
eec82323 LMI |
385 | (func 'request-group-description)) |
386 | (when (gnus-check-backend-function func group) | |
6748645f LMI |
387 | (funcall (gnus-get-function gnus-command-method func) |
388 | (gnus-group-real-name group) (nth 1 gnus-command-method))))) | |
eec82323 | 389 | |
16409b0b GM |
390 | (defun gnus-request-group-articles (group) |
391 | "Request a list of existing articles in GROUP." | |
392 | (let ((gnus-command-method (gnus-find-method-for-group group)) | |
393 | (func 'request-group-articles)) | |
394 | (when (gnus-check-backend-function func group) | |
395 | (funcall (gnus-get-function gnus-command-method func) | |
396 | (gnus-group-real-name group) (nth 1 gnus-command-method))))) | |
397 | ||
eec82323 LMI |
398 | (defun gnus-close-group (group) |
399 | "Request the GROUP be closed." | |
6748645f LMI |
400 | (let ((gnus-command-method (inline (gnus-find-method-for-group group)))) |
401 | (funcall (gnus-get-function gnus-command-method 'close-group) | |
402 | (gnus-group-real-name group) (nth 1 gnus-command-method)))) | |
eec82323 LMI |
403 | |
404 | (defun gnus-retrieve-headers (articles group &optional fetch-old) | |
405 | "Request headers for ARTICLES in GROUP. | |
406 | If FETCH-OLD, retrieve all headers (or some subset thereof) in the group." | |
6748645f | 407 | (let ((gnus-command-method (gnus-find-method-for-group group))) |
23f87bed MB |
408 | (cond |
409 | ((and gnus-use-cache (numberp (car articles))) | |
410 | (gnus-cache-retrieve-headers articles group fetch-old)) | |
411 | ((and gnus-agent (gnus-online gnus-command-method) | |
412 | (gnus-agent-method-p gnus-command-method)) | |
413 | (gnus-agent-retrieve-headers articles group fetch-old)) | |
414 | (t | |
6748645f LMI |
415 | (funcall (gnus-get-function gnus-command-method 'retrieve-headers) |
416 | articles (gnus-group-real-name group) | |
23f87bed | 417 | (nth 1 gnus-command-method) fetch-old))))) |
6748645f LMI |
418 | |
419 | (defun gnus-retrieve-articles (articles group) | |
420 | "Request ARTICLES in GROUP." | |
421 | (let ((gnus-command-method (gnus-find-method-for-group group))) | |
422 | (funcall (gnus-get-function gnus-command-method 'retrieve-articles) | |
423 | articles (gnus-group-real-name group) | |
424 | (nth 1 gnus-command-method)))) | |
425 | ||
426 | (defun gnus-retrieve-groups (groups gnus-command-method) | |
427 | "Request active information on GROUPS from GNUS-COMMAND-METHOD." | |
428 | (when (stringp gnus-command-method) | |
429 | (setq gnus-command-method (gnus-server-to-method gnus-command-method))) | |
430 | (funcall (gnus-get-function gnus-command-method 'retrieve-groups) | |
431 | groups (nth 1 gnus-command-method))) | |
eec82323 LMI |
432 | |
433 | (defun gnus-request-type (group &optional article) | |
434 | "Return the type (`post' or `mail') of GROUP (and ARTICLE)." | |
6748645f LMI |
435 | (let ((gnus-command-method (gnus-find-method-for-group group))) |
436 | (if (not (gnus-check-backend-function | |
437 | 'request-type (car gnus-command-method))) | |
eec82323 | 438 | 'unknown |
6748645f | 439 | (funcall (gnus-get-function gnus-command-method 'request-type) |
eec82323 LMI |
440 | (gnus-group-real-name group) article)))) |
441 | ||
16409b0b | 442 | (defun gnus-request-set-mark (group action) |
23f87bed | 443 | "Set marks on articles in the back end." |
16409b0b GM |
444 | (let ((gnus-command-method (gnus-find-method-for-group group))) |
445 | (if (not (gnus-check-backend-function | |
446 | 'request-set-mark (car gnus-command-method))) | |
447 | action | |
448 | (funcall (gnus-get-function gnus-command-method 'request-set-mark) | |
449 | (gnus-group-real-name group) action | |
450 | (nth 1 gnus-command-method))))) | |
451 | ||
eec82323 | 452 | (defun gnus-request-update-mark (group article mark) |
23f87bed | 453 | "Allow the back end to change the mark the user tries to put on an article." |
6748645f LMI |
454 | (let ((gnus-command-method (gnus-find-method-for-group group))) |
455 | (if (not (gnus-check-backend-function | |
456 | 'request-update-mark (car gnus-command-method))) | |
eec82323 | 457 | mark |
6748645f | 458 | (funcall (gnus-get-function gnus-command-method 'request-update-mark) |
eec82323 LMI |
459 | (gnus-group-real-name group) article mark)))) |
460 | ||
461 | (defun gnus-request-article (article group &optional buffer) | |
462 | "Request the ARTICLE in GROUP. | |
463 | ARTICLE can either be an article number or an article Message-ID. | |
464 | If BUFFER, insert the article in that group." | |
6748645f LMI |
465 | (let ((gnus-command-method (gnus-find-method-for-group group))) |
466 | (funcall (gnus-get-function gnus-command-method 'request-article) | |
467 | article (gnus-group-real-name group) | |
468 | (nth 1 gnus-command-method) buffer))) | |
eec82323 LMI |
469 | |
470 | (defun gnus-request-head (article group) | |
471 | "Request the head of ARTICLE in GROUP." | |
6748645f LMI |
472 | (let* ((gnus-command-method (gnus-find-method-for-group group)) |
473 | (head (gnus-get-function gnus-command-method 'request-head t)) | |
eec82323 LMI |
474 | res clean-up) |
475 | (cond | |
476 | ;; Check the cache. | |
477 | ((and gnus-use-cache | |
478 | (numberp article) | |
479 | (gnus-cache-request-article article group)) | |
480 | (setq res (cons group article) | |
481 | clean-up t)) | |
23f87bed MB |
482 | ;; Check the agent cache. |
483 | ((gnus-agent-request-article article group) | |
484 | (setq res (cons group article) | |
485 | clean-up t)) | |
eec82323 LMI |
486 | ;; Use `head' function. |
487 | ((fboundp head) | |
488 | (setq res (funcall head article (gnus-group-real-name group) | |
6748645f | 489 | (nth 1 gnus-command-method)))) |
eec82323 LMI |
490 | ;; Use `article' function. |
491 | (t | |
492 | (setq res (gnus-request-article article group) | |
493 | clean-up t))) | |
494 | (when clean-up | |
495 | (save-excursion | |
496 | (set-buffer nntp-server-buffer) | |
497 | (goto-char (point-min)) | |
498 | (when (search-forward "\n\n" nil t) | |
499 | (delete-region (1- (point)) (point-max))) | |
500 | (nnheader-fold-continuation-lines))) | |
501 | res)) | |
502 | ||
503 | (defun gnus-request-body (article group) | |
504 | "Request the body of ARTICLE in GROUP." | |
6748645f LMI |
505 | (let* ((gnus-command-method (gnus-find-method-for-group group)) |
506 | (head (gnus-get-function gnus-command-method 'request-body t)) | |
507 | res clean-up) | |
508 | (cond | |
509 | ;; Check the cache. | |
510 | ((and gnus-use-cache | |
511 | (numberp article) | |
512 | (gnus-cache-request-article article group)) | |
513 | (setq res (cons group article) | |
514 | clean-up t)) | |
23f87bed MB |
515 | ;; Check the agent cache. |
516 | ((gnus-agent-request-article article group) | |
517 | (setq res (cons group article) | |
518 | clean-up t)) | |
6748645f LMI |
519 | ;; Use `head' function. |
520 | ((fboundp head) | |
521 | (setq res (funcall head article (gnus-group-real-name group) | |
522 | (nth 1 gnus-command-method)))) | |
523 | ;; Use `article' function. | |
524 | (t | |
525 | (setq res (gnus-request-article article group) | |
526 | clean-up t))) | |
527 | (when clean-up | |
528 | (save-excursion | |
529 | (set-buffer nntp-server-buffer) | |
530 | (goto-char (point-min)) | |
531 | (when (search-forward "\n\n" nil t) | |
532 | (delete-region (point-min) (1- (point)))))) | |
533 | res)) | |
eec82323 | 534 | |
6748645f LMI |
535 | (defun gnus-request-post (gnus-command-method) |
536 | "Post the current buffer using GNUS-COMMAND-METHOD." | |
537 | (when (stringp gnus-command-method) | |
538 | (setq gnus-command-method (gnus-server-to-method gnus-command-method))) | |
539 | (funcall (gnus-get-function gnus-command-method 'request-post) | |
540 | (nth 1 gnus-command-method))) | |
541 | ||
542 | (defun gnus-request-scan (group gnus-command-method) | |
543 | "Request a SCAN being performed in GROUP from GNUS-COMMAND-METHOD. | |
544 | If GROUP is nil, all groups on GNUS-COMMAND-METHOD are scanned." | |
16409b0b GM |
545 | (let ((gnus-command-method |
546 | (if group (gnus-find-method-for-group group) gnus-command-method)) | |
547 | (gnus-inhibit-demon t) | |
548 | (mail-source-plugged gnus-plugged)) | |
01c52d31 MB |
549 | (when (or gnus-plugged (not (gnus-agent-method-p gnus-command-method))) |
550 | (setq gnus-internal-registry-spool-current-method gnus-command-method) | |
551 | (funcall (gnus-get-function gnus-command-method 'request-scan) | |
552 | (and group (gnus-group-real-name group)) | |
553 | (nth 1 gnus-command-method))))) | |
6748645f LMI |
554 | |
555 | (defsubst gnus-request-update-info (info gnus-command-method) | |
556 | "Request that GNUS-COMMAND-METHOD update INFO." | |
557 | (when (stringp gnus-command-method) | |
558 | (setq gnus-command-method (gnus-server-to-method gnus-command-method))) | |
559 | (when (gnus-check-backend-function | |
560 | 'request-update-info (car gnus-command-method)) | |
23f87bed MB |
561 | (let ((group (gnus-info-group info))) |
562 | (and (funcall (gnus-get-function gnus-command-method | |
563 | 'request-update-info) | |
564 | (gnus-group-real-name group) | |
565 | info (nth 1 gnus-command-method)) | |
566 | ;; If the minimum article number is greater than 1, then all | |
567 | ;; smaller article numbers are known not to exist; we'll | |
568 | ;; artificially add those to the 'read range. | |
569 | (let* ((active (gnus-active group)) | |
570 | (min (car active))) | |
571 | (when (> min 1) | |
572 | (let* ((range (if (= min 2) 1 (cons 1 (1- min)))) | |
573 | (read (gnus-info-read info)) | |
574 | (new-read (gnus-range-add read (list range)))) | |
575 | (gnus-info-set-read info new-read))) | |
576 | info))))) | |
eec82323 LMI |
577 | |
578 | (defun gnus-request-expire-articles (articles group &optional force) | |
23f87bed MB |
579 | (let* ((gnus-command-method (gnus-find-method-for-group group)) |
580 | (not-deleted | |
581 | (funcall | |
582 | (gnus-get-function gnus-command-method 'request-expire-articles) | |
583 | articles (gnus-group-real-name group) (nth 1 gnus-command-method) | |
584 | force))) | |
585 | (when (and gnus-agent | |
586 | (gnus-agent-method-p gnus-command-method)) | |
587 | (let ((expired-articles (gnus-sorted-difference articles not-deleted))) | |
588 | (when expired-articles | |
589 | (gnus-agent-expire expired-articles group 'force)))) | |
590 | not-deleted)) | |
591 | ||
592 | (defun gnus-request-move-article (article group server accept-function | |
01c52d31 | 593 | &optional last move-is-internal) |
23f87bed MB |
594 | (let* ((gnus-command-method (gnus-find-method-for-group group)) |
595 | (result (funcall (gnus-get-function gnus-command-method | |
596 | 'request-move-article) | |
597 | article (gnus-group-real-name group) | |
01c52d31 | 598 | (nth 1 gnus-command-method) accept-function last move-is-internal))) |
23f87bed MB |
599 | (when (and result gnus-agent |
600 | (gnus-agent-method-p gnus-command-method)) | |
54506618 | 601 | (gnus-agent-unfetch-articles group (list article))) |
23f87bed | 602 | result)) |
bf247b6e | 603 | |
16409b0b GM |
604 | (defun gnus-request-accept-article (group &optional gnus-command-method last |
605 | no-encode) | |
eec82323 | 606 | ;; Make sure there's a newline at the end of the article. |
6748645f LMI |
607 | (when (stringp gnus-command-method) |
608 | (setq gnus-command-method (gnus-server-to-method gnus-command-method))) | |
609 | (when (and (not gnus-command-method) | |
eec82323 | 610 | (stringp group)) |
54506618 MB |
611 | (setq gnus-command-method (or (gnus-find-method-for-group group) |
612 | (gnus-group-name-to-method group)))) | |
eec82323 LMI |
613 | (goto-char (point-max)) |
614 | (unless (bolp) | |
615 | (insert "\n")) | |
16409b0b | 616 | (unless no-encode |
23f87bed MB |
617 | (let ((message-options message-options)) |
618 | (message-options-set-recipient) | |
619 | (save-restriction | |
620 | (message-narrow-to-head) | |
621 | (let ((mail-parse-charset message-default-charset)) | |
622 | (mail-encode-encoded-word-buffer))) | |
623 | (message-encode-message-body))) | |
01c52d31 | 624 | (let ((gnus-command-method (or gnus-command-method |
54506618 | 625 | (gnus-find-method-for-group group))) |
bf247b6e KS |
626 | (result |
627 | (funcall | |
54506618 MB |
628 | (gnus-get-function gnus-command-method 'request-accept-article) |
629 | (if (stringp group) (gnus-group-real-name group) group) | |
630 | (cadr gnus-command-method) | |
631 | last))) | |
632 | (when (and gnus-agent (gnus-agent-method-p gnus-command-method)) | |
633 | (gnus-agent-regenerate-group group (list (cdr result)))) | |
634 | result)) | |
eec82323 | 635 | |
16409b0b GM |
636 | (defun gnus-request-replace-article (article group buffer &optional no-encode) |
637 | (unless no-encode | |
23f87bed MB |
638 | (let ((message-options message-options)) |
639 | (message-options-set-recipient) | |
640 | (save-restriction | |
641 | (message-narrow-to-head) | |
642 | (let ((mail-parse-charset message-default-charset)) | |
643 | (mail-encode-encoded-word-buffer))) | |
644 | (message-encode-message-body))) | |
54506618 MB |
645 | (let* ((func (car (gnus-group-name-to-method group))) |
646 | (result (funcall (intern (format "%s-request-replace-article" func)) | |
647 | article (gnus-group-real-name group) buffer))) | |
648 | (when (and gnus-agent (gnus-agent-method-p gnus-command-method)) | |
649 | (gnus-agent-regenerate-group group (list article))) | |
650 | result)) | |
eec82323 LMI |
651 | |
652 | (defun gnus-request-associate-buffer (group) | |
6748645f LMI |
653 | (let ((gnus-command-method (gnus-find-method-for-group group))) |
654 | (funcall (gnus-get-function gnus-command-method 'request-associate-buffer) | |
eec82323 LMI |
655 | (gnus-group-real-name group)))) |
656 | ||
657 | (defun gnus-request-restore-buffer (article group) | |
658 | "Request a new buffer restored to the state of ARTICLE." | |
6748645f LMI |
659 | (let ((gnus-command-method (gnus-find-method-for-group group))) |
660 | (funcall (gnus-get-function gnus-command-method 'request-restore-buffer) | |
661 | article (gnus-group-real-name group) | |
662 | (nth 1 gnus-command-method)))) | |
eec82323 | 663 | |
6748645f LMI |
664 | (defun gnus-request-create-group (group &optional gnus-command-method args) |
665 | (when (stringp gnus-command-method) | |
666 | (setq gnus-command-method (gnus-server-to-method gnus-command-method))) | |
667 | (let ((gnus-command-method | |
668 | (or gnus-command-method (gnus-find-method-for-group group)))) | |
669 | (funcall (gnus-get-function gnus-command-method 'request-create-group) | |
670 | (gnus-group-real-name group) (nth 1 gnus-command-method) args))) | |
eec82323 LMI |
671 | |
672 | (defun gnus-request-delete-group (group &optional force) | |
54506618 MB |
673 | (let* ((gnus-command-method (gnus-find-method-for-group group)) |
674 | (result | |
675 | (funcall (gnus-get-function gnus-command-method 'request-delete-group) | |
676 | (gnus-group-real-name group) force (nth 1 gnus-command-method)))) | |
677 | (when result | |
678 | (gnus-cache-delete-group group) | |
679 | (gnus-agent-delete-group group)) | |
680 | result)) | |
eec82323 LMI |
681 | |
682 | (defun gnus-request-rename-group (group new-name) | |
54506618 MB |
683 | (let* ((gnus-command-method (gnus-find-method-for-group group)) |
684 | (result | |
685 | (funcall (gnus-get-function gnus-command-method 'request-rename-group) | |
686 | (gnus-group-real-name group) | |
687 | (gnus-group-real-name new-name) (nth 1 gnus-command-method)))) | |
688 | (when result | |
689 | (gnus-cache-rename-group group new-name) | |
690 | (gnus-agent-rename-group group new-name)) | |
691 | result)) | |
eec82323 LMI |
692 | |
693 | (defun gnus-close-backends () | |
694 | ;; Send a close request to all backends that support such a request. | |
695 | (let ((methods gnus-valid-select-methods) | |
696 | (gnus-inhibit-demon t) | |
6748645f LMI |
697 | func gnus-command-method) |
698 | (while (setq gnus-command-method (pop methods)) | |
eec82323 | 699 | (when (fboundp (setq func (intern |
6748645f LMI |
700 | (concat (car gnus-command-method) |
701 | "-request-close")))) | |
eec82323 LMI |
702 | (funcall func))))) |
703 | ||
6748645f LMI |
704 | (defun gnus-asynchronous-p (gnus-command-method) |
705 | (let ((func (gnus-get-function gnus-command-method 'asynchronous-p t))) | |
eec82323 LMI |
706 | (when (fboundp func) |
707 | (funcall func)))) | |
708 | ||
6748645f LMI |
709 | (defun gnus-remove-denial (gnus-command-method) |
710 | (when (stringp gnus-command-method) | |
711 | (setq gnus-command-method (gnus-server-to-method gnus-command-method))) | |
712 | (let* ((elem (assoc gnus-command-method gnus-opened-servers)) | |
eec82323 LMI |
713 | (status (cadr elem))) |
714 | ;; If this hasn't been opened before, we add it to the list. | |
715 | (when (eq status 'denied) | |
716 | ;; Set the status of this server. | |
717 | (setcar (cdr elem) 'closed)))) | |
718 | ||
719 | (provide 'gnus-int) | |
720 | ||
cbee283d | 721 | ;; arch-tag: bbc90087-9b7f-4017-a92c-3abf180ac86d |
eec82323 | 722 | ;;; gnus-int.el ends here |