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