T-gnus 6.15.18 revision 00.
[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 err
207                  (funcall (gnus-get-function gnus-command-method 'open-server)
208                           (nth 1 gnus-command-method)
209                           (nthcdr 2 gnus-command-method))
210                (error 
211                 (gnus-message 1 (format 
212                                  "Unable to open server due to: %s"
213                                  (error-message-string err)))
214                 nil)
215                (quit
216                 (gnus-message 1 "Quit trying to open server")
217                 nil))))
218         ;; If this hasn't been opened before, we add it to the list.
219         (unless elem
220           (setq elem (list gnus-command-method nil)
221                 gnus-opened-servers (cons elem gnus-opened-servers)))
222         ;; Set the status of this server.
223         (setcar (cdr elem)
224                 (if result
225                     (if (eq (cadr elem) 'offline)
226                         'offline
227                       'ok)
228                   (if (and gnus-agent
229                            (not (eq (cadr elem) 'offline))
230                            (gnus-agent-method-p gnus-command-method))
231                       (or gnus-server-unopen-status
232                           (if (gnus-y-or-n-p
233                                (format "Unable to open %s:%s, go offline? "
234                                        (car gnus-command-method)
235                                        (cadr gnus-command-method)))
236                               'offline
237                             'denied))
238                     'denied)))
239         ;; Return the result from the "open" call.
240         (cond ((eq (cadr elem) 'offline)
241                ;; I'm avoiding infinite recursion by binding unopen
242                ;; status to denied (The logic of this routine
243                ;; guarantees that I can't get to this point with
244                ;; unopen status already bound to denied).
245                (unless (eq gnus-server-unopen-status 'denied)
246                  (let ((gnus-server-unopen-status 'denied))
247                    (gnus-open-server gnus-command-method)))
248                t)
249               (t
250                result))))))
251
252 (defun gnus-close-server (gnus-command-method)
253   "Close the connection to GNUS-COMMAND-METHOD."
254   (when (stringp gnus-command-method)
255     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
256   (funcall (gnus-get-function gnus-command-method 'close-server)
257            (nth 1 gnus-command-method)))
258
259 (defun gnus-request-list (gnus-command-method)
260   "Request the active file from GNUS-COMMAND-METHOD."
261   (when (stringp gnus-command-method)
262     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
263   (funcall (gnus-get-function gnus-command-method 'request-list)
264            (nth 1 gnus-command-method)))
265
266 (defun gnus-request-list-newsgroups (gnus-command-method)
267   "Request the newsgroups file from GNUS-COMMAND-METHOD."
268   (when (stringp gnus-command-method)
269     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
270   (funcall (gnus-get-function gnus-command-method 'request-list-newsgroups)
271            (nth 1 gnus-command-method)))
272
273 (defun gnus-request-newgroups (date gnus-command-method)
274   "Request all new groups since DATE from GNUS-COMMAND-METHOD."
275   (when (stringp gnus-command-method)
276     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
277   (let ((func (gnus-get-function gnus-command-method 'request-newgroups t)))
278     (when func
279       (funcall func date (nth 1 gnus-command-method)))))
280
281 (defun gnus-server-opened (gnus-command-method)
282   "Check whether a connection to GNUS-COMMAND-METHOD has been opened."
283   (unless (eq (gnus-server-status gnus-command-method)
284               'denied)
285     (when (stringp gnus-command-method)
286       (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
287     (funcall (inline (gnus-get-function gnus-command-method 'server-opened))
288              (nth 1 gnus-command-method))))
289
290 (defun gnus-status-message (gnus-command-method)
291   "Return the status message from GNUS-COMMAND-METHOD.
292 If GNUS-COMMAND-METHOD is a string, it is interpreted as a group name.  The method
293 this group uses will be queried."
294   (let ((gnus-command-method
295          (if (stringp gnus-command-method)
296              (gnus-find-method-for-group gnus-command-method)
297            gnus-command-method)))
298     (funcall (gnus-get-function gnus-command-method 'status-message)
299              (nth 1 gnus-command-method))))
300
301 (defun gnus-request-regenerate (gnus-command-method)
302   "Request a data generation from GNUS-COMMAND-METHOD."
303   (when (stringp gnus-command-method)
304     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
305   (funcall (gnus-get-function gnus-command-method 'request-regenerate)
306            (nth 1 gnus-command-method)))
307
308 (defun gnus-request-group (group &optional dont-check gnus-command-method)
309   "Request GROUP.  If DONT-CHECK, no information is required."
310   (let ((gnus-command-method
311          (or gnus-command-method (inline (gnus-find-method-for-group group)))))
312     (when (stringp gnus-command-method)
313       (setq gnus-command-method
314             (inline (gnus-server-to-method gnus-command-method))))
315     (funcall (inline (gnus-get-function gnus-command-method 'request-group))
316              (gnus-group-real-name group) (nth 1 gnus-command-method)
317              dont-check)))
318
319 (defun gnus-list-active-group (group)
320   "Request active information on GROUP."
321   (let ((gnus-command-method (gnus-find-method-for-group group))
322         (func 'list-active-group))
323     (when (gnus-check-backend-function func group)
324       (funcall (gnus-get-function gnus-command-method func)
325                (gnus-group-real-name group) (nth 1 gnus-command-method)))))
326
327 (defun gnus-request-group-description (group)
328   "Request a description of GROUP."
329   (let ((gnus-command-method (gnus-find-method-for-group group))
330         (func 'request-group-description))
331     (when (gnus-check-backend-function func group)
332       (funcall (gnus-get-function gnus-command-method func)
333                (gnus-group-real-name group) (nth 1 gnus-command-method)))))
334
335 (defun gnus-request-group-articles (group)
336   "Request a list of existing articles in GROUP."
337   (let ((gnus-command-method (gnus-find-method-for-group group))
338         (func 'request-group-articles))
339     (when (gnus-check-backend-function func group)
340       (funcall (gnus-get-function gnus-command-method func)
341                (gnus-group-real-name group) (nth 1 gnus-command-method)))))
342
343 (defun gnus-close-group (group)
344   "Request the GROUP be closed."
345   (let ((gnus-command-method (inline (gnus-find-method-for-group group))))
346     (funcall (gnus-get-function gnus-command-method 'close-group)
347              (gnus-group-real-name group) (nth 1 gnus-command-method))))
348
349 (defun gnus-retrieve-headers (articles group &optional fetch-old)
350   "Request headers for ARTICLES in GROUP.
351 If FETCH-OLD, retrieve all headers (or some subset thereof) in the group."
352   (let ((gnus-command-method (gnus-find-method-for-group group)))
353     (cond
354      ((and gnus-use-cache (numberp (car articles)))
355       (gnus-cache-retrieve-headers articles group fetch-old))
356      ((and gnus-agent (gnus-online gnus-command-method)
357            (gnus-agent-method-p gnus-command-method))
358       (gnus-agent-retrieve-headers articles group fetch-old))
359      (t
360       (funcall (gnus-get-function gnus-command-method 'retrieve-headers)
361                articles (gnus-group-real-name group)
362                (nth 1 gnus-command-method) fetch-old)))))
363
364 (defun gnus-retrieve-articles (articles group)
365   "Request ARTICLES in GROUP."
366   (let ((gnus-command-method (gnus-find-method-for-group group)))
367     (funcall (gnus-get-function gnus-command-method 'retrieve-articles)
368              articles (gnus-group-real-name group)
369              (nth 1 gnus-command-method))))
370
371 (defun gnus-retrieve-groups (groups gnus-command-method)
372   "Request active information on GROUPS 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 'retrieve-groups)
376            groups (nth 1 gnus-command-method)))
377
378 (defun gnus-request-type (group &optional article)
379   "Return the type (`post' or `mail') of GROUP (and ARTICLE)."
380   (let ((gnus-command-method (gnus-find-method-for-group group)))
381     (if (not (gnus-check-backend-function
382               'request-type (car gnus-command-method)))
383         'unknown
384       (funcall (gnus-get-function gnus-command-method 'request-type)
385                (gnus-group-real-name group) article))))
386
387 (defun gnus-request-set-mark (group action)
388   "Set marks on articles in the backend."
389   (let ((gnus-command-method (gnus-find-method-for-group group)))
390     (if (not (gnus-check-backend-function
391               'request-set-mark (car gnus-command-method)))
392         action
393       (funcall (gnus-get-function gnus-command-method 'request-set-mark)
394                (gnus-group-real-name group) action
395                (nth 1 gnus-command-method)))))
396
397 (defun gnus-request-update-mark (group article mark)
398   "Allow the backend to change the mark the user tries to put on an article."
399   (let ((gnus-command-method (gnus-find-method-for-group group)))
400     (if (not (gnus-check-backend-function
401               'request-update-mark (car gnus-command-method)))
402         mark
403       (funcall (gnus-get-function gnus-command-method 'request-update-mark)
404                (gnus-group-real-name group) article mark))))
405
406 (defun gnus-request-article (article group &optional buffer)
407   "Request the ARTICLE in GROUP.
408 ARTICLE can either be an article number or an article Message-ID.
409 If BUFFER, insert the article in that group."
410   (let ((gnus-command-method (gnus-find-method-for-group group)))
411     (funcall (gnus-get-function gnus-command-method 'request-article)
412              article (gnus-group-real-name group)
413              (nth 1 gnus-command-method) buffer)))
414
415 (defun gnus-request-head (article group)
416   "Request the head of ARTICLE in GROUP."
417   (let* ((gnus-command-method (gnus-find-method-for-group group))
418          (head (gnus-get-function gnus-command-method 'request-head t))
419          res clean-up)
420     (cond
421      ;; Check the cache.
422      ((and gnus-use-cache
423            (numberp article)
424            (gnus-cache-request-article article group))
425       (setq res (cons group article)
426             clean-up t))
427      ;; Check the agent cache.
428      ((gnus-agent-request-article article group)
429       (setq res (cons group article)
430             clean-up t))
431      ;; Use `head' function.
432      ((fboundp head)
433       (setq res (funcall head article (gnus-group-real-name group)
434                          (nth 1 gnus-command-method))))
435      ;; Use `article' function.
436      (t
437       (setq res (gnus-request-article article group)
438             clean-up t)))
439     (when clean-up
440       (save-excursion
441         (set-buffer nntp-server-buffer)
442         (goto-char (point-min))
443         (when (search-forward "\n\n" nil t)
444           (delete-region (1- (point)) (point-max)))
445         (nnheader-fold-continuation-lines)))
446     res))
447
448 (defun gnus-request-body (article group)
449   "Request the body of ARTICLE in GROUP."
450   (let* ((gnus-command-method (gnus-find-method-for-group group))
451          (head (gnus-get-function gnus-command-method 'request-body t))
452          res clean-up)
453     (cond
454      ;; Check the cache.
455      ((and gnus-use-cache
456            (numberp article)
457            (gnus-cache-request-article article group))
458       (setq res (cons group article)
459             clean-up t))
460      ;; Check the agent cache.
461      ((gnus-agent-request-article article group)
462       (setq res (cons group article)
463             clean-up t))
464      ;; Use `head' function.
465      ((fboundp head)
466       (setq res (funcall head article (gnus-group-real-name group)
467                          (nth 1 gnus-command-method))))
468      ;; Use `article' function.
469      (t
470       (setq res (gnus-request-article article group)
471             clean-up t)))
472     (when clean-up
473       (save-excursion
474         (set-buffer nntp-server-buffer)
475         (goto-char (point-min))
476         (when (search-forward "\n\n" nil t)
477           (delete-region (point-min) (1- (point))))))
478     res))
479
480 (defun gnus-request-post (gnus-command-method)
481   "Post the current buffer using GNUS-COMMAND-METHOD."
482   (when (stringp gnus-command-method)
483     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
484   (funcall (gnus-get-function gnus-command-method 'request-post)
485            (nth 1 gnus-command-method)))
486
487 (defun gnus-request-scan (group gnus-command-method)
488   "Request a SCAN being performed in GROUP from GNUS-COMMAND-METHOD.
489 If GROUP is nil, all groups on GNUS-COMMAND-METHOD are scanned."
490   (let ((gnus-command-method
491          (if group (gnus-find-method-for-group group) gnus-command-method))
492         (gnus-inhibit-demon t)
493         (mail-source-plugged gnus-plugged))
494     (if (or gnus-plugged (not (gnus-agent-method-p gnus-command-method)))
495         (progn
496           (setq gnus-internal-registry-spool-current-method gnus-command-method)
497           (funcall (gnus-get-function gnus-command-method 'request-scan)
498                    (and group (gnus-group-real-name group))
499                    (nth 1 gnus-command-method))))))
500
501 (defsubst gnus-request-update-info (info gnus-command-method)
502   "Request that GNUS-COMMAND-METHOD update INFO."
503   (when (stringp gnus-command-method)
504     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
505   (when (gnus-check-backend-function
506          'request-update-info (car gnus-command-method))
507     (let ((group (gnus-info-group info)))
508       (and (funcall (gnus-get-function gnus-command-method
509                                        'request-update-info)
510                     (gnus-group-real-name group)
511                     info (nth 1 gnus-command-method))
512            ;; If the minimum article number is greater than 1, then all
513            ;; smaller article numbers are known not to exist; we'll
514            ;; artificially add those to the 'read range.
515            (let* ((active (gnus-active group))
516                   (min (car active)))
517              (when (> min 1)
518                (let* ((range (if (= min 2) 1 (cons 1 (1- min))))
519                       (read (gnus-info-read info))
520                       (new-read (gnus-range-add read (list range))))
521                  (gnus-info-set-read info new-read)))
522              info)))))
523
524 (defun gnus-request-expire-articles (articles group &optional force)
525   (let* ((gnus-command-method (gnus-find-method-for-group group))
526          (not-deleted
527           (funcall
528            (gnus-get-function gnus-command-method 'request-expire-articles)
529            articles (gnus-group-real-name group) (nth 1 gnus-command-method)
530            force)))
531     (when (and gnus-agent
532                (gnus-agent-method-p gnus-command-method))
533       (let ((expired-articles (gnus-sorted-difference articles not-deleted)))
534         (when expired-articles
535           (gnus-agent-expire expired-articles group 'force))))
536     not-deleted))
537
538 (defun gnus-request-move-article (article group server accept-function
539                                           &optional last)
540   (let* ((gnus-command-method (gnus-find-method-for-group group))
541          (result (funcall (gnus-get-function gnus-command-method
542                                              'request-move-article)
543                           article (gnus-group-real-name group)
544                           (nth 1 gnus-command-method) accept-function last)))
545     (when (and result gnus-agent
546                (gnus-agent-method-p gnus-command-method))
547       (gnus-agent-expire (list article) group 'force))
548     result))
549
550 (defun gnus-request-accept-article (group &optional gnus-command-method last
551                                           no-encode)
552   ;; Make sure there's a newline at the end of the article.
553   (when (stringp gnus-command-method)
554     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
555   (when (and (not gnus-command-method)
556              (stringp group))
557     (setq gnus-command-method (gnus-group-name-to-method group)))
558   (goto-char (point-max))
559   (unless (bolp)
560     (insert "\n"))
561   (let ((gnus-command-method (or gnus-command-method
562                                  (gnus-find-method-for-group group))))
563     (funcall (gnus-get-function gnus-command-method 'request-accept-article)
564              (if (stringp group) (gnus-group-real-name group) group)
565              (cadr gnus-command-method)
566              last)))
567
568 (defun gnus-request-replace-article (article group buffer &optional no-encode)
569   (let ((func (car (gnus-group-name-to-method group))))
570     (funcall (intern (format "%s-request-replace-article" func))
571              article (gnus-group-real-name group) buffer)))
572
573 (defun gnus-request-associate-buffer (group)
574   (let ((gnus-command-method (gnus-find-method-for-group group)))
575     (funcall (gnus-get-function gnus-command-method 'request-associate-buffer)
576              (gnus-group-real-name group))))
577
578 (defun gnus-request-restore-buffer (article group)
579   "Request a new buffer restored to the state of ARTICLE."
580   (let ((gnus-command-method (gnus-find-method-for-group group)))
581     (funcall (gnus-get-function gnus-command-method 'request-restore-buffer)
582              article (gnus-group-real-name group)
583              (nth 1 gnus-command-method))))
584
585 (defun gnus-request-create-group (group &optional gnus-command-method args)
586   (when (stringp gnus-command-method)
587     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
588   (let ((gnus-command-method
589          (or gnus-command-method (gnus-find-method-for-group group))))
590     (funcall (gnus-get-function gnus-command-method 'request-create-group)
591              (gnus-group-real-name group) (nth 1 gnus-command-method) args)))
592
593 (defun gnus-request-delete-group (group &optional force)
594   (let ((gnus-command-method (gnus-find-method-for-group group)))
595     (funcall (gnus-get-function gnus-command-method 'request-delete-group)
596              (gnus-group-real-name group) force (nth 1 gnus-command-method))))
597
598 (defun gnus-request-rename-group (group new-name)
599   (let ((gnus-command-method (gnus-find-method-for-group group)))
600     (funcall (gnus-get-function gnus-command-method 'request-rename-group)
601              (gnus-group-real-name group)
602              (gnus-group-real-name new-name) (nth 1 gnus-command-method))))
603
604 (defun gnus-close-backends ()
605   ;; Send a close request to all backends that support such a request.
606   (let ((methods gnus-valid-select-methods)
607         (gnus-inhibit-demon t)
608         func gnus-command-method)
609     (while (setq gnus-command-method (pop methods))
610       (when (fboundp (setq func (intern
611                                  (concat (car gnus-command-method)
612                                          "-request-close"))))
613         (funcall func)))))
614
615 (defun gnus-asynchronous-p (gnus-command-method)
616   (let ((func (gnus-get-function gnus-command-method 'asynchronous-p t)))
617     (when (fboundp func)
618       (funcall func))))
619
620 (defun gnus-remove-denial (gnus-command-method)
621   (when (stringp gnus-command-method)
622     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
623   (let* ((elem (assoc gnus-command-method gnus-opened-servers))
624          (status (cadr elem)))
625     ;; If this hasn't been opened before, we add it to the list.
626     (when (eq status 'denied)
627       ;; Set the status of this server.
628       (setcar (cdr elem) 'closed))))
629
630 (provide 'gnus-int)
631
632 ;;; gnus-int.el ends here