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