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