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