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