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