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