Synch to No Gnus 200409220316.
[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-plugged (or gnus-plugged 
426                            (member (car gnus-command-method)
427                                    gnus-servers-that-use-local-marks))))
428     (if (not (gnus-check-backend-function
429               'request-set-mark (car gnus-command-method)))
430         action
431       (funcall (gnus-get-function gnus-command-method 'request-set-mark)
432                (gnus-group-real-name group) action
433                (nth 1 gnus-command-method)))))
434
435 (defun gnus-request-update-mark (group article mark)
436   "Allow the back end to change the mark the user tries to put on an article."
437   (let* ((gnus-command-method (gnus-find-method-for-group group))
438          (gnus-plugged (or gnus-plugged 
439                            (member (car gnus-command-method)
440                                    gnus-servers-that-use-local-marks))))
441     (if (not (gnus-check-backend-function
442               'request-update-mark (car gnus-command-method)))
443         mark
444       (funcall (gnus-get-function gnus-command-method 'request-update-mark)
445                (gnus-group-real-name group) article mark))))
446
447 (defun gnus-request-article (article group &optional buffer)
448   "Request the ARTICLE in GROUP.
449 ARTICLE can either be an article number or an article Message-ID.
450 If BUFFER, insert the article in that group."
451   (let ((gnus-command-method (gnus-find-method-for-group group)))
452     (funcall (gnus-get-function gnus-command-method 'request-article)
453              article (gnus-group-real-name group)
454              (nth 1 gnus-command-method) buffer)))
455
456 (defun gnus-request-head (article group)
457   "Request the head of ARTICLE in GROUP."
458   (let* ((gnus-command-method (gnus-find-method-for-group group))
459          (head (gnus-get-function gnus-command-method 'request-head t))
460          res clean-up)
461     (cond
462      ;; Check the cache.
463      ((and gnus-use-cache
464            (numberp article)
465            (gnus-cache-request-article article group))
466       (setq res (cons group article)
467             clean-up t))
468      ;; Check the agent cache.
469      ((gnus-agent-request-article article group)
470       (setq res (cons group article)
471             clean-up t))
472      ;; Use `head' function.
473      ((fboundp head)
474       (setq res (funcall head article (gnus-group-real-name group)
475                          (nth 1 gnus-command-method))))
476      ;; Use `article' function.
477      (t
478       (setq res (gnus-request-article article group)
479             clean-up t)))
480     (when clean-up
481       (save-excursion
482         (set-buffer nntp-server-buffer)
483         (goto-char (point-min))
484         (when (search-forward "\n\n" nil t)
485           (delete-region (1- (point)) (point-max)))
486         (nnheader-fold-continuation-lines)))
487     res))
488
489 (defun gnus-request-body (article group)
490   "Request the body of ARTICLE in GROUP."
491   (let* ((gnus-command-method (gnus-find-method-for-group group))
492          (head (gnus-get-function gnus-command-method 'request-body t))
493          res clean-up)
494     (cond
495      ;; Check the cache.
496      ((and gnus-use-cache
497            (numberp article)
498            (gnus-cache-request-article article group))
499       (setq res (cons group article)
500             clean-up t))
501      ;; Check the agent cache.
502      ((gnus-agent-request-article article group)
503       (setq res (cons group article)
504             clean-up t))
505      ;; Use `head' function.
506      ((fboundp head)
507       (setq res (funcall head article (gnus-group-real-name group)
508                          (nth 1 gnus-command-method))))
509      ;; Use `article' function.
510      (t
511       (setq res (gnus-request-article article group)
512             clean-up t)))
513     (when clean-up
514       (save-excursion
515         (set-buffer nntp-server-buffer)
516         (goto-char (point-min))
517         (when (search-forward "\n\n" nil t)
518           (delete-region (point-min) (1- (point))))))
519     res))
520
521 (defun gnus-request-post (gnus-command-method)
522   "Post the current buffer using GNUS-COMMAND-METHOD."
523   (when (stringp gnus-command-method)
524     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
525   (funcall (gnus-get-function gnus-command-method 'request-post)
526            (nth 1 gnus-command-method)))
527
528 (defun gnus-request-scan (group gnus-command-method)
529   "Request a SCAN being performed in GROUP from GNUS-COMMAND-METHOD.
530 If GROUP is nil, all groups on GNUS-COMMAND-METHOD are scanned."
531   (let ((gnus-command-method
532          (if group (gnus-find-method-for-group group) gnus-command-method))
533         (gnus-inhibit-demon t)
534         (mail-source-plugged gnus-plugged))
535     (when (or gnus-plugged (not (gnus-agent-method-p gnus-command-method)))
536       (setq gnus-internal-registry-spool-current-method gnus-command-method)
537       (funcall (gnus-get-function gnus-command-method 'request-scan)
538                (and group (gnus-group-real-name group))
539                (nth 1 gnus-command-method)))))
540
541 (defsubst gnus-request-update-info (info gnus-command-method)
542   "Request that GNUS-COMMAND-METHOD update INFO."
543   (when (stringp gnus-command-method)
544     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
545   (when (gnus-check-backend-function
546          'request-update-info (car gnus-command-method))
547     (let ((group (gnus-info-group info)))
548       (and (funcall (gnus-get-function gnus-command-method
549                                        'request-update-info)
550                     (gnus-group-real-name group)
551                     info (nth 1 gnus-command-method))
552            ;; If the minimum article number is greater than 1, then all
553            ;; smaller article numbers are known not to exist; we'll
554            ;; artificially add those to the 'read range.
555            (let* ((active (gnus-active group))
556                   (min (car active)))
557              (when (> min 1)
558                (let* ((range (if (= min 2) 1 (cons 1 (1- min))))
559                       (read (gnus-info-read info))
560                       (new-read (gnus-range-add read (list range))))
561                  (gnus-info-set-read info new-read)))
562              info)))))
563
564 (defun gnus-request-expire-articles (articles group &optional force)
565   (let* ((gnus-command-method (gnus-find-method-for-group group))
566          (not-deleted
567           (funcall
568            (gnus-get-function gnus-command-method 'request-expire-articles)
569            articles (gnus-group-real-name group) (nth 1 gnus-command-method)
570            force)))
571     (when (and gnus-agent
572                (gnus-agent-method-p gnus-command-method))
573       (let ((expired-articles (gnus-sorted-difference articles not-deleted)))
574         (when expired-articles
575           (gnus-agent-expire expired-articles group 'force))))
576     not-deleted))
577
578 (defun gnus-request-move-article (article group server accept-function
579                                           &optional last)
580   (let* ((gnus-command-method (gnus-find-method-for-group group))
581          (result (funcall (gnus-get-function gnus-command-method
582                                              'request-move-article)
583                           article (gnus-group-real-name group)
584                           (nth 1 gnus-command-method) accept-function last)))
585     (when (and result gnus-agent
586                (gnus-agent-method-p gnus-command-method))
587       (gnus-agent-unfetch-articles group (list article)))
588     result))
589
590 (defun gnus-request-accept-article (group &optional gnus-command-method last
591                                           no-encode)
592   ;; Make sure there's a newline at the end of the article.
593   (when (stringp gnus-command-method)
594     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
595   (when (and (not gnus-command-method)
596              (stringp group))
597     (setq gnus-command-method (or (gnus-find-method-for-group group)
598                                   (gnus-group-name-to-method group))))
599   (goto-char (point-max))
600   (unless (bolp)
601     (insert "\n"))
602   (let ((gnus-command-method (or gnus-command-method
603                                  (gnus-find-method-for-group group)))
604         (result 
605          (funcall 
606           (gnus-get-function gnus-command-method 'request-accept-article)
607           (if (stringp group) (gnus-group-real-name group) group)
608           (cadr gnus-command-method)
609           last)))
610     (when (and gnus-agent (gnus-agent-method-p gnus-command-method))
611       (gnus-agent-regenerate-group group (list (cdr result))))
612     result))
613
614 (defun gnus-request-replace-article (article group buffer &optional no-encode)
615   (let* ((func (car (gnus-group-name-to-method group)))
616          (result (funcall (intern (format "%s-request-replace-article" func))
617                           article (gnus-group-real-name group) buffer)))
618     (when (and gnus-agent (gnus-agent-method-p gnus-command-method))
619       (gnus-agent-regenerate-group group (list article)))
620     result))
621
622 (defun gnus-request-associate-buffer (group)
623   (let ((gnus-command-method (gnus-find-method-for-group group)))
624     (funcall (gnus-get-function gnus-command-method 'request-associate-buffer)
625              (gnus-group-real-name group))))
626
627 (defun gnus-request-restore-buffer (article group)
628   "Request a new buffer restored to the state of ARTICLE."
629   (let ((gnus-command-method (gnus-find-method-for-group group)))
630     (funcall (gnus-get-function gnus-command-method 'request-restore-buffer)
631              article (gnus-group-real-name group)
632              (nth 1 gnus-command-method))))
633
634 (defun gnus-request-create-group (group &optional gnus-command-method args)
635   (when (stringp gnus-command-method)
636     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
637   (let ((gnus-command-method
638          (or gnus-command-method (gnus-find-method-for-group group))))
639     (funcall (gnus-get-function gnus-command-method 'request-create-group)
640              (gnus-group-real-name group) (nth 1 gnus-command-method) args)))
641
642 (defun gnus-request-delete-group (group &optional force)
643   (let* ((gnus-command-method (gnus-find-method-for-group group))
644          (result
645           (funcall (gnus-get-function gnus-command-method 'request-delete-group)
646                    (gnus-group-real-name group) force (nth 1 gnus-command-method))))
647     (when result
648       (gnus-cache-delete-group group)
649       (gnus-agent-delete-group group))
650     result))
651
652 (defun gnus-request-rename-group (group new-name)
653   (let* ((gnus-command-method (gnus-find-method-for-group group))
654          (result
655           (funcall (gnus-get-function gnus-command-method 'request-rename-group)
656                    (gnus-group-real-name group)
657                    (gnus-group-real-name new-name) (nth 1 gnus-command-method))))
658     (when result
659       (gnus-cache-rename-group group new-name)
660       (gnus-agent-rename-group group new-name))
661     result))
662
663 (defun gnus-close-backends ()
664   ;; Send a close request to all backends that support such a request.
665   (let ((methods gnus-valid-select-methods)
666         (gnus-inhibit-demon t)
667         func gnus-command-method)
668     (while (setq gnus-command-method (pop methods))
669       (when (fboundp (setq func (intern
670                                  (concat (car gnus-command-method)
671                                          "-request-close"))))
672         (funcall func)))))
673
674 (defun gnus-asynchronous-p (gnus-command-method)
675   (let ((func (gnus-get-function gnus-command-method 'asynchronous-p t)))
676     (when (fboundp func)
677       (funcall func))))
678
679 (defun gnus-remove-denial (gnus-command-method)
680   (when (stringp gnus-command-method)
681     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
682   (let* ((elem (assoc gnus-command-method gnus-opened-servers))
683          (status (cadr elem)))
684     ;; If this hasn't been opened before, we add it to the list.
685     (when (eq status 'denied)
686       ;; Set the status of this server.
687       (setcar (cdr elem) 'closed))))
688
689 (provide 'gnus-int)
690
691 ;;; gnus-int.el ends here