3d6c73523e9e33409e336b38e50a2398bf4bd56a
[elisp/gnus.git-] / lisp / gnus-int.el
1 ;;; gnus-int.el --- backend interface functions for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;;         MORIOKA Tomohiko <morioka@jaist.ac.jp>
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
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Commentary:
27
28 ;;; Code:
29
30 (eval-when-compile (require 'cl))
31
32 (require 'gnus)
33 (require 'message)
34 (require 'gnus-range)
35
36 (eval-when-compile
37   (defun gnus-agent-expire (&optional a b c)))
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
44 (defcustom gnus-server-unopen-status nil
45   "The default status if the server is not able to open.
46 If the server is covered by Gnus agent, the possible values are
47 `denied', set the server denied; `offline', set the server offline;
48 nil, ask user.  If the server is not covered by Gnus agent, set the
49 server denied."
50   :group 'gnus-start
51   :type '(choice (const :tag "Ask" nil)
52                  (const :tag "Deny server" denied)
53                  (const :tag "Unplug Agent" offline)))
54
55 (defvar gnus-internal-registry-spool-current-method nil
56   "The current method, for the registry.")
57
58 ;;;
59 ;;; Server Communication
60 ;;;
61
62 (defun gnus-start-news-server (&optional confirm)
63   "Open a method for getting news.
64 If CONFIRM is non-nil, the user will be asked for an NNTP server."
65   (let (how)
66     (if gnus-current-select-method
67         ;; Stream is already opened.
68         nil
69       ;; Open NNTP server.
70       (unless gnus-nntp-service
71         (setq gnus-nntp-server nil))
72       (when confirm
73         ;; Read server name with completion.
74         (setq gnus-nntp-server
75               (completing-read "NNTP server: "
76                                (mapcar (lambda (server) (list server))
77                                        (cons (list gnus-nntp-server)
78                                              gnus-secondary-servers))
79                                nil nil gnus-nntp-server)))
80
81       (when (and gnus-nntp-server
82                  (stringp gnus-nntp-server)
83                  (not (string= gnus-nntp-server "")))
84         (setq gnus-select-method
85               (cond ((or (string= gnus-nntp-server "")
86                          (string= gnus-nntp-server "::"))
87                      (list 'nnspool (system-name)))
88                     ((string-match "^:" gnus-nntp-server)
89                      (list 'nnmh gnus-nntp-server
90                            (list 'nnmh-directory
91                                  (file-name-as-directory
92                                   (expand-file-name
93                                    (substring gnus-nntp-server 1) "~/")))
94                            (list 'nnmh-get-new-mail nil)))
95                     (t
96                      (list 'nntp gnus-nntp-server)))))
97
98       (setq how (car gnus-select-method))
99       (cond
100        ((eq how 'nnspool)
101         (require 'nnspool)
102         (gnus-message 5 "Looking up local news spool..."))
103        ((eq how 'nnmh)
104         (require 'nnmh)
105         (gnus-message 5 "Looking up mh spool..."))
106        (t
107         (require 'nntp)))
108       (setq gnus-current-select-method gnus-select-method)
109       (gnus-run-hooks 'gnus-open-server-hook)
110       (or
111        ;; gnus-open-server-hook might have opened it
112        (gnus-server-opened gnus-select-method)
113        (gnus-open-server gnus-select-method)
114        gnus-batch-mode
115        (gnus-y-or-n-p
116         (format
117          "%s (%s) open error: '%s'.  Continue? "
118          (car gnus-select-method) (cadr gnus-select-method)
119          (gnus-status-message gnus-select-method)))
120        (gnus-error 1 "Couldn't open server on %s"
121                    (nth 1 gnus-select-method))))))
122
123 (defun gnus-check-group (group)
124   "Try to make sure that the server where GROUP exists is alive."
125   (let ((method (gnus-find-method-for-group group)))
126     (or (gnus-server-opened method)
127         (gnus-open-server method))))
128
129 (defun gnus-check-server (&optional method silent)
130   "Check whether the connection to METHOD is down.
131 If METHOD is nil, use `gnus-select-method'.
132 If it is down, start it up (again)."
133   (let ((method (or method gnus-select-method))
134         result)
135     ;; Transform virtual server names into select methods.
136     (when (stringp method)
137       (setq method (gnus-server-to-method method)))
138     (if (gnus-server-opened method)
139         ;; The stream is already opened.
140         t
141       ;; Open the server.
142       (unless silent
143         (gnus-message 5 "Opening %s server%s..." (car method)
144                       (if (equal (nth 1 method) "") ""
145                         (format " on %s" (nth 1 method)))))
146       (gnus-run-hooks 'gnus-open-server-hook)
147       (prog1
148           (condition-case ()
149               (setq result (gnus-open-server method))
150             (quit (message "Quit gnus-check-server")
151                   nil))
152         (unless silent
153           (gnus-message 5 "Opening %s server%s...%s" (car method)
154                         (if (equal (nth 1 method) "") ""
155                           (format " on %s" (nth 1 method)))
156                         (if result "done" "failed")))))))
157
158 (defun gnus-get-function (method function &optional noerror)
159   "Return a function symbol based on METHOD and FUNCTION."
160   ;; Translate server names into methods.
161   (unless method
162     (error "Attempted use of a nil select method"))
163   (when (stringp method)
164     (setq method (gnus-server-to-method method)))
165   ;; Check cache of constructed names.
166   (let* ((method-sym (if gnus-agent
167                          (gnus-agent-get-function method)
168                        (car method)))
169          (method-fns (get method-sym 'gnus-method-functions))
170          (func (let ((method-fnlist-elt (assq function method-fns)))
171                  (unless method-fnlist-elt
172                    (setq method-fnlist-elt
173                          (cons function
174                                (intern (format "%s-%s" method-sym function))))
175                    (put method-sym 'gnus-method-functions
176                         (cons method-fnlist-elt method-fns)))
177                  (cdr method-fnlist-elt))))
178     ;; Maybe complain if there is no function.
179     (unless (fboundp func)
180       (unless (car method)
181         (error "Trying to require a method that doesn't exist"))
182       (require (car method))
183       (when (not (fboundp func))
184         (if noerror
185             (setq func nil)
186           (error "No such function: %s" func))))
187     func))
188
189 \f
190 ;;;
191 ;;; Interface functions to the backends.
192 ;;;
193
194 (defun gnus-open-server (gnus-command-method)
195   "Open a connection to GNUS-COMMAND-METHOD."
196   (when (stringp gnus-command-method)
197     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
198   (let ((elem (assoc gnus-command-method gnus-opened-servers)))
199     ;; If this method was previously denied, we just return nil.
200     (if (eq (nth 1 elem) 'denied)
201         (progn
202           (gnus-message 1 "Denied server")
203           nil)
204       ;; Open the server.
205       (let ((result
206              (condition-case ()
207                  (funcall (gnus-get-function gnus-command-method 'open-server)
208                           (nth 1 gnus-command-method)
209                           (nthcdr 2 gnus-command-method))
210                (error nil)
211                (quit
212                 (message "Quit trying to open server")
213                 nil))))
214         ;; If this hasn't been opened before, we add it to the list.
215         (unless elem
216           (setq elem (list gnus-command-method nil)
217                 gnus-opened-servers (cons elem gnus-opened-servers)))
218         ;; Set the status of this server.
219         (setcar (cdr elem)
220                 (if result
221                     (if (eq (cadr elem) 'offline)
222                         'offline
223                       'ok)
224                   (if (and gnus-agent
225                            (not (eq (cadr elem) 'offline))
226                            (gnus-agent-method-p gnus-command-method))
227                       (or gnus-server-unopen-status
228                           (if (gnus-y-or-n-p
229                                (format "Unable to open %s:%s, go offline? "
230                                        (car gnus-command-method)
231                                        (cadr gnus-command-method)))
232                               'offline
233                             'denied))
234                     'denied)))
235         ;; Return the result from the "open" call.
236         (cond ((eq (cadr elem) 'offline)
237                ;; I'm avoiding infinite recursion by binding unopen
238                ;; status to denied (The logic of this routine
239                ;; guarantees that I can't get to this point with
240                ;; unopen status already bound to denied).
241                (unless (eq gnus-server-unopen-status 'denied)
242                  (let ((gnus-server-unopen-status 'denied))
243                    (gnus-open-server gnus-command-method)))
244                t)
245               (t
246                result))))))
247
248 (defun gnus-close-server (gnus-command-method)
249   "Close the connection to GNUS-COMMAND-METHOD."
250   (when (stringp gnus-command-method)
251     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
252   (funcall (gnus-get-function gnus-command-method 'close-server)
253            (nth 1 gnus-command-method)))
254
255 (defun gnus-request-list (gnus-command-method)
256   "Request the active file from GNUS-COMMAND-METHOD."
257   (when (stringp gnus-command-method)
258     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
259   (funcall (gnus-get-function gnus-command-method 'request-list)
260            (nth 1 gnus-command-method)))
261
262 (defun gnus-request-list-newsgroups (gnus-command-method)
263   "Request the newsgroups file from GNUS-COMMAND-METHOD."
264   (when (stringp gnus-command-method)
265     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
266   (funcall (gnus-get-function gnus-command-method 'request-list-newsgroups)
267            (nth 1 gnus-command-method)))
268
269 (defun gnus-request-newgroups (date gnus-command-method)
270   "Request all new groups since DATE from GNUS-COMMAND-METHOD."
271   (when (stringp gnus-command-method)
272     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
273   (let ((func (gnus-get-function gnus-command-method 'request-newgroups t)))
274     (when func
275       (funcall func date (nth 1 gnus-command-method)))))
276
277 (defun gnus-server-opened (gnus-command-method)
278   "Check whether a connection to GNUS-COMMAND-METHOD has been opened."
279   (unless (eq (gnus-server-status gnus-command-method)
280               'denied)
281     (when (stringp gnus-command-method)
282       (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
283     (funcall (inline (gnus-get-function gnus-command-method 'server-opened))
284              (nth 1 gnus-command-method))))
285
286 (defun gnus-status-message (gnus-command-method)
287   "Return the status message from GNUS-COMMAND-METHOD.
288 If GNUS-COMMAND-METHOD is a string, it is interpreted as a group name.  The method
289 this group uses will be queried."
290   (let ((gnus-command-method
291          (if (stringp gnus-command-method)
292              (gnus-find-method-for-group gnus-command-method)
293            gnus-command-method)))
294     (funcall (gnus-get-function gnus-command-method 'status-message)
295              (nth 1 gnus-command-method))))
296
297 (defun gnus-request-regenerate (gnus-command-method)
298   "Request a data generation from GNUS-COMMAND-METHOD."
299   (when (stringp gnus-command-method)
300     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
301   (funcall (gnus-get-function gnus-command-method 'request-regenerate)
302            (nth 1 gnus-command-method)))
303
304 (defun gnus-request-group (group &optional dont-check gnus-command-method)
305   "Request GROUP.  If DONT-CHECK, no information is required."
306   (let ((gnus-command-method
307          (or gnus-command-method (inline (gnus-find-method-for-group group)))))
308     (when (stringp gnus-command-method)
309       (setq gnus-command-method
310             (inline (gnus-server-to-method gnus-command-method))))
311     (funcall (inline (gnus-get-function gnus-command-method 'request-group))
312              (gnus-group-real-name group) (nth 1 gnus-command-method)
313              dont-check)))
314
315 (defun gnus-list-active-group (group)
316   "Request active information on GROUP."
317   (let ((gnus-command-method (gnus-find-method-for-group group))
318         (func 'list-active-group))
319     (when (gnus-check-backend-function func group)
320       (funcall (gnus-get-function gnus-command-method func)
321                (gnus-group-real-name group) (nth 1 gnus-command-method)))))
322
323 (defun gnus-request-group-description (group)
324   "Request a description of GROUP."
325   (let ((gnus-command-method (gnus-find-method-for-group group))
326         (func 'request-group-description))
327     (when (gnus-check-backend-function func group)
328       (funcall (gnus-get-function gnus-command-method func)
329                (gnus-group-real-name group) (nth 1 gnus-command-method)))))
330
331 (defun gnus-request-group-articles (group)
332   "Request a list of existing articles in GROUP."
333   (let ((gnus-command-method (gnus-find-method-for-group group))
334         (func 'request-group-articles))
335     (when (gnus-check-backend-function func group)
336       (funcall (gnus-get-function gnus-command-method func)
337                (gnus-group-real-name group) (nth 1 gnus-command-method)))))
338
339 (defun gnus-close-group (group)
340   "Request the GROUP be closed."
341   (let ((gnus-command-method (inline (gnus-find-method-for-group group))))
342     (funcall (gnus-get-function gnus-command-method 'close-group)
343              (gnus-group-real-name group) (nth 1 gnus-command-method))))
344
345 (defun gnus-retrieve-headers (articles group &optional fetch-old)
346   "Request headers for ARTICLES in GROUP.
347 If FETCH-OLD, retrieve all headers (or some subset thereof) in the group."
348   (let ((gnus-command-method (gnus-find-method-for-group group)))
349     (cond
350      ((and gnus-use-cache (numberp (car articles)))
351       (gnus-cache-retrieve-headers articles group fetch-old))
352      ((and gnus-agent (gnus-online gnus-command-method)
353            (gnus-agent-method-p gnus-command-method))
354       (gnus-agent-retrieve-headers articles group fetch-old))
355      (t
356       (funcall (gnus-get-function gnus-command-method 'retrieve-headers)
357                articles (gnus-group-real-name group)
358                (nth 1 gnus-command-method) fetch-old)))))
359
360 (defun gnus-retrieve-articles (articles group)
361   "Request ARTICLES in GROUP."
362   (let ((gnus-command-method (gnus-find-method-for-group group)))
363     (funcall (gnus-get-function gnus-command-method 'retrieve-articles)
364              articles (gnus-group-real-name group)
365              (nth 1 gnus-command-method))))
366
367 (defun gnus-retrieve-groups (groups gnus-command-method)
368   "Request active information on GROUPS from GNUS-COMMAND-METHOD."
369   (when (stringp gnus-command-method)
370     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
371   (funcall (gnus-get-function gnus-command-method 'retrieve-groups)
372            groups (nth 1 gnus-command-method)))
373
374 (defun gnus-request-type (group &optional article)
375   "Return the type (`post' or `mail') of GROUP (and ARTICLE)."
376   (let ((gnus-command-method (gnus-find-method-for-group group)))
377     (if (not (gnus-check-backend-function
378               'request-type (car gnus-command-method)))
379         'unknown
380       (funcall (gnus-get-function gnus-command-method 'request-type)
381                (gnus-group-real-name group) article))))
382
383 (defun gnus-request-set-mark (group action)
384   "Set marks on articles in the backend."
385   (let ((gnus-command-method (gnus-find-method-for-group group)))
386     (if (not (gnus-check-backend-function
387               'request-set-mark (car gnus-command-method)))
388         action
389       (funcall (gnus-get-function gnus-command-method 'request-set-mark)
390                (gnus-group-real-name group) action
391                (nth 1 gnus-command-method)))))
392
393 (defun gnus-request-update-mark (group article mark)
394   "Allow the backend to change the mark the user tries to put on an article."
395   (let ((gnus-command-method (gnus-find-method-for-group group)))
396     (if (not (gnus-check-backend-function
397               'request-update-mark (car gnus-command-method)))
398         mark
399       (funcall (gnus-get-function gnus-command-method 'request-update-mark)
400                (gnus-group-real-name group) article mark))))
401
402 (defun gnus-request-article (article group &optional buffer)
403   "Request the ARTICLE in GROUP.
404 ARTICLE can either be an article number or an article Message-ID.
405 If BUFFER, insert the article in that group."
406   (let ((gnus-command-method (gnus-find-method-for-group group)))
407     (funcall (gnus-get-function gnus-command-method 'request-article)
408              article (gnus-group-real-name group)
409              (nth 1 gnus-command-method) buffer)))
410
411 (defun gnus-request-head (article group)
412   "Request the head of ARTICLE in GROUP."
413   (let* ((gnus-command-method (gnus-find-method-for-group group))
414          (head (gnus-get-function gnus-command-method 'request-head t))
415          res clean-up)
416     (cond
417      ;; Check the cache.
418      ((and gnus-use-cache
419            (numberp article)
420            (gnus-cache-request-article article group))
421       (setq res (cons group article)
422             clean-up t))
423      ;; Check the agent cache.
424      ((gnus-agent-request-article article group)
425       (setq res (cons group article)
426             clean-up t))
427      ;; Use `head' function.
428      ((fboundp head)
429       (setq res (funcall head article (gnus-group-real-name group)
430                          (nth 1 gnus-command-method))))
431      ;; Use `article' function.
432      (t
433       (setq res (gnus-request-article article group)
434             clean-up t)))
435     (when clean-up
436       (save-excursion
437         (set-buffer nntp-server-buffer)
438         (goto-char (point-min))
439         (when (search-forward "\n\n" nil t)
440           (delete-region (1- (point)) (point-max)))
441         (nnheader-fold-continuation-lines)))
442     res))
443
444 (defun gnus-request-body (article group)
445   "Request the body of ARTICLE in GROUP."
446   (let* ((gnus-command-method (gnus-find-method-for-group group))
447          (head (gnus-get-function gnus-command-method 'request-body t))
448          res clean-up)
449     (cond
450      ;; Check the cache.
451      ((and gnus-use-cache
452            (numberp article)
453            (gnus-cache-request-article article group))
454       (setq res (cons group article)
455             clean-up t))
456      ;; Check the agent cache.
457      ((gnus-agent-request-article article group)
458       (setq res (cons group article)
459             clean-up t))
460      ;; Use `head' function.
461      ((fboundp head)
462       (setq res (funcall head article (gnus-group-real-name group)
463                          (nth 1 gnus-command-method))))
464      ;; Use `article' function.
465      (t
466       (setq res (gnus-request-article article group)
467             clean-up t)))
468     (when clean-up
469       (save-excursion
470         (set-buffer nntp-server-buffer)
471         (goto-char (point-min))
472         (when (search-forward "\n\n" nil t)
473           (delete-region (point-min) (1- (point))))))
474     res))
475
476 (defun gnus-request-post (gnus-command-method)
477   "Post the current buffer using GNUS-COMMAND-METHOD."
478   (when (stringp gnus-command-method)
479     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
480   (funcall (gnus-get-function gnus-command-method 'request-post)
481            (nth 1 gnus-command-method)))
482
483 (defun gnus-request-scan (group gnus-command-method)
484   "Request a SCAN being performed in GROUP from GNUS-COMMAND-METHOD.
485 If GROUP is nil, all groups on GNUS-COMMAND-METHOD are scanned."
486   (let ((gnus-command-method
487          (if group (gnus-find-method-for-group group) gnus-command-method))
488         (gnus-inhibit-demon t)
489         (mail-source-plugged gnus-plugged))
490     (if (or gnus-plugged (not (gnus-agent-method-p gnus-command-method)))
491         (progn
492           (setq gnus-internal-registry-spool-current-method gnus-command-method)
493           (funcall (gnus-get-function gnus-command-method 'request-scan)
494                    (and group (gnus-group-real-name group))
495                    (nth 1 gnus-command-method))))))
496
497 (defsubst gnus-request-update-info (info gnus-command-method)
498   "Request that GNUS-COMMAND-METHOD update INFO."
499   (when (stringp gnus-command-method)
500     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
501   (when (gnus-check-backend-function
502          'request-update-info (car gnus-command-method))
503     (let ((group (gnus-info-group info)))
504       (and (funcall (gnus-get-function gnus-command-method
505                                        'request-update-info)
506                     (gnus-group-real-name group)
507                     info (nth 1 gnus-command-method))
508            ;; If the minimum article number is greater than 1, then all
509            ;; smaller article numbers are known not to exist; we'll
510            ;; artificially add those to the 'read range.
511            (let* ((active (gnus-active group))
512                   (min (car active)))
513              (when (> min 1)
514                (let* ((range (if (= min 2) 1 (cons 1 (1- min))))
515                       (read (gnus-info-read info))
516                       (new-read (gnus-range-add read (list range))))
517                  (gnus-info-set-read info new-read)))
518              info)))))
519
520 (defun gnus-request-expire-articles (articles group &optional force)
521   (let* ((gnus-command-method (gnus-find-method-for-group group))
522          (not-deleted
523           (funcall
524            (gnus-get-function gnus-command-method 'request-expire-articles)
525            articles (gnus-group-real-name group) (nth 1 gnus-command-method)
526            force)))
527     (when (and gnus-agent
528                (gnus-agent-method-p gnus-command-method))
529       (let ((expired-articles (gnus-sorted-difference articles not-deleted)))
530         (when expired-articles
531           (gnus-agent-expire expired-articles group 'force))))
532     not-deleted))
533
534 (defun gnus-request-move-article (article group server accept-function
535                                           &optional last)
536   (let* ((gnus-command-method (gnus-find-method-for-group group))
537          (result (funcall (gnus-get-function gnus-command-method
538                                              'request-move-article)
539                           article (gnus-group-real-name group)
540                           (nth 1 gnus-command-method) accept-function last)))
541     (when (and result gnus-agent
542                (gnus-agent-method-p gnus-command-method))
543       (gnus-agent-expire (list article) group 'force))
544     result))
545
546 (defun gnus-request-accept-article (group &optional gnus-command-method last
547                                           no-encode)
548   ;; Make sure there's a newline at the end of the article.
549   (when (stringp gnus-command-method)
550     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
551   (when (and (not gnus-command-method)
552              (stringp group))
553     (setq gnus-command-method (gnus-group-name-to-method group)))
554   (goto-char (point-max))
555   (unless (bolp)
556     (insert "\n"))
557   (let ((gnus-command-method (or gnus-command-method
558                                  (gnus-find-method-for-group group))))
559     (funcall (gnus-get-function gnus-command-method 'request-accept-article)
560              (if (stringp group) (gnus-group-real-name group) group)
561              (cadr gnus-command-method)
562              last)))
563
564 (defun gnus-request-replace-article (article group buffer &optional no-encode)
565   (let ((func (car (gnus-group-name-to-method group))))
566     (funcall (intern (format "%s-request-replace-article" func))
567              article (gnus-group-real-name group) buffer)))
568
569 (defun gnus-request-associate-buffer (group)
570   (let ((gnus-command-method (gnus-find-method-for-group group)))
571     (funcall (gnus-get-function gnus-command-method 'request-associate-buffer)
572              (gnus-group-real-name group))))
573
574 (defun gnus-request-restore-buffer (article group)
575   "Request a new buffer restored to the state of ARTICLE."
576   (let ((gnus-command-method (gnus-find-method-for-group group)))
577     (funcall (gnus-get-function gnus-command-method 'request-restore-buffer)
578              article (gnus-group-real-name group)
579              (nth 1 gnus-command-method))))
580
581 (defun gnus-request-create-group (group &optional gnus-command-method args)
582   (when (stringp gnus-command-method)
583     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
584   (let ((gnus-command-method
585          (or gnus-command-method (gnus-find-method-for-group group))))
586     (funcall (gnus-get-function gnus-command-method 'request-create-group)
587              (gnus-group-real-name group) (nth 1 gnus-command-method) args)))
588
589 (defun gnus-request-delete-group (group &optional force)
590   (let ((gnus-command-method (gnus-find-method-for-group group)))
591     (funcall (gnus-get-function gnus-command-method 'request-delete-group)
592              (gnus-group-real-name group) force (nth 1 gnus-command-method))))
593
594 (defun gnus-request-rename-group (group new-name)
595   (let ((gnus-command-method (gnus-find-method-for-group group)))
596     (funcall (gnus-get-function gnus-command-method 'request-rename-group)
597              (gnus-group-real-name group)
598              (gnus-group-real-name new-name) (nth 1 gnus-command-method))))
599
600 (defun gnus-close-backends ()
601   ;; Send a close request to all backends that support such a request.
602   (let ((methods gnus-valid-select-methods)
603         (gnus-inhibit-demon t)
604         func gnus-command-method)
605     (while (setq gnus-command-method (pop methods))
606       (when (fboundp (setq func (intern
607                                  (concat (car gnus-command-method)
608                                          "-request-close"))))
609         (funcall func)))))
610
611 (defun gnus-asynchronous-p (gnus-command-method)
612   (let ((func (gnus-get-function gnus-command-method 'asynchronous-p t)))
613     (when (fboundp func)
614       (funcall func))))
615
616 (defun gnus-remove-denial (gnus-command-method)
617   (when (stringp gnus-command-method)
618     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
619   (let* ((elem (assoc gnus-command-method gnus-opened-servers))
620          (status (cadr elem)))
621     ;; If this hasn't been opened before, we add it to the list.
622     (when (eq status 'denied)
623       ;; Set the status of this server.
624       (setcar (cdr elem) 'closed))))
625
626 (provide 'gnus-int)
627
628 ;;; gnus-int.el ends here