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