Synch to No Gnus 200602242253.
[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, 2006 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                              ((and
255                                (not gnus-batch-mode)
256                                (gnus-y-or-n-p
257                                 (format "Unable to open %s:%s, go offline? "
258                                         (car gnus-command-method)
259                                         (cadr gnus-command-method))))
260                               (setq open-offline t)
261                               'offline)
262                              (t
263                               ;; This agentized server was still denied
264                               'denied)))
265                       (t
266                        ;; This unagentized server must be denied
267                        'denied)))
268
269         ;; NOTE: I MUST set the server's status to offline before this
270         ;; recursive call as this status will drive the
271         ;; gnus-get-function (called above) to return the agent's
272         ;; backend.
273         (if open-offline
274             ;; Recursively open this offline server to perform the
275             ;; open-server function of the agent's backend.
276             (let ((gnus-server-unopen-status 'denied))
277               ;; Bind gnus-server-unopen-status to avoid recursively
278               ;; prompting with "go offline?".  This is only a concern
279               ;; when the agent's backend fails to open the server.
280               (gnus-open-server gnus-command-method))
281           result)))))
282
283 (defun gnus-close-server (gnus-command-method)
284   "Close the connection to GNUS-COMMAND-METHOD."
285   (when (stringp gnus-command-method)
286     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
287   (funcall (gnus-get-function gnus-command-method 'close-server)
288            (nth 1 gnus-command-method)))
289
290 (defun gnus-request-list (gnus-command-method)
291   "Request the active file from GNUS-COMMAND-METHOD."
292   (when (stringp gnus-command-method)
293     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
294   (funcall (gnus-get-function gnus-command-method 'request-list)
295            (nth 1 gnus-command-method)))
296
297 (defun gnus-request-list-newsgroups (gnus-command-method)
298   "Request the newsgroups file from GNUS-COMMAND-METHOD."
299   (when (stringp gnus-command-method)
300     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
301   (funcall (gnus-get-function gnus-command-method 'request-list-newsgroups)
302            (nth 1 gnus-command-method)))
303
304 (defun gnus-request-newgroups (date gnus-command-method)
305   "Request all new groups since DATE from GNUS-COMMAND-METHOD."
306   (when (stringp gnus-command-method)
307     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
308   (let ((func (gnus-get-function gnus-command-method 'request-newgroups t)))
309     (when func
310       (funcall func date (nth 1 gnus-command-method)))))
311
312 (defun gnus-server-opened (gnus-command-method)
313   "Check whether a connection to GNUS-COMMAND-METHOD has been opened."
314   (unless (eq (gnus-server-status gnus-command-method)
315               'denied)
316     (when (stringp gnus-command-method)
317       (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
318     (funcall (inline (gnus-get-function gnus-command-method 'server-opened))
319              (nth 1 gnus-command-method))))
320
321 (defun gnus-status-message (gnus-command-method)
322   "Return the status message from GNUS-COMMAND-METHOD.
323 If GNUS-COMMAND-METHOD is a string, it is interpreted as a group
324 name.  The method this group uses will be queried."
325   (let ((gnus-command-method
326          (if (stringp gnus-command-method)
327              (gnus-find-method-for-group gnus-command-method)
328            gnus-command-method)))
329     (funcall (gnus-get-function gnus-command-method 'status-message)
330              (nth 1 gnus-command-method))))
331
332 (defun gnus-request-regenerate (gnus-command-method)
333   "Request a data generation from GNUS-COMMAND-METHOD."
334   (when (stringp gnus-command-method)
335     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
336   (funcall (gnus-get-function gnus-command-method 'request-regenerate)
337            (nth 1 gnus-command-method)))
338
339 (defun gnus-request-compact-group (group)
340   (let* ((method (gnus-find-method-for-group group))
341          (gnus-command-method method)
342          (result
343           (funcall (gnus-get-function gnus-command-method
344                                       'request-compact-group)
345                    (gnus-group-real-name group)
346                    (nth 1 gnus-command-method) t)))
347     result))
348
349 (defun gnus-request-compact (gnus-command-method)
350   "Request groups compaction  from GNUS-COMMAND-METHOD."
351   (when (stringp gnus-command-method)
352     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
353   (funcall (gnus-get-function gnus-command-method 'request-compact)
354            (nth 1 gnus-command-method)))
355
356 (defun gnus-request-group (group &optional dont-check gnus-command-method)
357   "Request GROUP.  If DONT-CHECK, no information is required."
358   (let ((gnus-command-method
359          (or gnus-command-method (inline (gnus-find-method-for-group group)))))
360     (when (stringp gnus-command-method)
361       (setq gnus-command-method
362             (inline (gnus-server-to-method gnus-command-method))))
363          (funcall (inline (gnus-get-function gnus-command-method 'request-group))
364              (gnus-group-real-name group) (nth 1 gnus-command-method)
365              dont-check)))
366
367 (defun gnus-list-active-group (group)
368   "Request active information on GROUP."
369   (let ((gnus-command-method (gnus-find-method-for-group group))
370         (func 'list-active-group))
371     (when (gnus-check-backend-function func group)
372       (funcall (gnus-get-function gnus-command-method func)
373                (gnus-group-real-name group) (nth 1 gnus-command-method)))))
374
375 (defun gnus-request-group-description (group)
376   "Request a description of GROUP."
377   (let ((gnus-command-method (gnus-find-method-for-group group))
378         (func 'request-group-description))
379     (when (gnus-check-backend-function func group)
380       (funcall (gnus-get-function gnus-command-method func)
381                (gnus-group-real-name group) (nth 1 gnus-command-method)))))
382
383 (defun gnus-request-group-articles (group)
384   "Request a list of existing articles in GROUP."
385   (let ((gnus-command-method (gnus-find-method-for-group group))
386         (func 'request-group-articles))
387     (when (gnus-check-backend-function func group)
388       (funcall (gnus-get-function gnus-command-method func)
389                (gnus-group-real-name group) (nth 1 gnus-command-method)))))
390
391 (defun gnus-close-group (group)
392   "Request the GROUP be closed."
393   (let ((gnus-command-method (inline (gnus-find-method-for-group group))))
394     (funcall (gnus-get-function gnus-command-method 'close-group)
395              (gnus-group-real-name group) (nth 1 gnus-command-method))))
396
397 (defun gnus-retrieve-headers (articles group &optional fetch-old)
398   "Request headers for ARTICLES in GROUP.
399 If FETCH-OLD, retrieve all headers (or some subset thereof) in the group."
400   (let ((gnus-command-method (gnus-find-method-for-group group)))
401     (cond
402      ((and gnus-use-cache (numberp (car articles)))
403       (gnus-cache-retrieve-headers articles group fetch-old))
404      ((and gnus-agent (gnus-online gnus-command-method)
405            (gnus-agent-method-p gnus-command-method))
406       (gnus-agent-retrieve-headers articles group fetch-old))
407      (t
408       (funcall (gnus-get-function gnus-command-method 'retrieve-headers)
409                articles (gnus-group-real-name group)
410                (nth 1 gnus-command-method) fetch-old)))))
411
412 (defun gnus-retrieve-articles (articles group)
413   "Request ARTICLES in GROUP."
414   (let ((gnus-command-method (gnus-find-method-for-group group)))
415     (funcall (gnus-get-function gnus-command-method 'retrieve-articles)
416              articles (gnus-group-real-name group)
417              (nth 1 gnus-command-method))))
418
419 (defun gnus-retrieve-groups (groups gnus-command-method)
420   "Request active information on GROUPS from GNUS-COMMAND-METHOD."
421   (when (stringp gnus-command-method)
422     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
423   (funcall (gnus-get-function gnus-command-method 'retrieve-groups)
424            groups (nth 1 gnus-command-method)))
425
426 (defun gnus-request-type (group &optional article)
427   "Return the type (`post' or `mail') of GROUP (and ARTICLE)."
428   (let ((gnus-command-method (gnus-find-method-for-group group)))
429     (if (not (gnus-check-backend-function
430               'request-type (car gnus-command-method)))
431         'unknown
432       (funcall (gnus-get-function gnus-command-method 'request-type)
433                (gnus-group-real-name group) article))))
434
435 (defun gnus-request-set-mark (group action)
436   "Set marks on articles in the back end."
437   (let ((gnus-command-method (gnus-find-method-for-group group)))
438     (if (not (gnus-check-backend-function
439               'request-set-mark (car gnus-command-method)))
440         action
441       (funcall (gnus-get-function gnus-command-method 'request-set-mark)
442                (gnus-group-real-name group) action
443                (nth 1 gnus-command-method)))))
444
445 (defun gnus-request-update-mark (group article mark)
446   "Allow the back end to change the mark the user tries to put on an article."
447   (let ((gnus-command-method (gnus-find-method-for-group group)))
448     (if (not (gnus-check-backend-function
449               'request-update-mark (car gnus-command-method)))
450         mark
451       (funcall (gnus-get-function gnus-command-method 'request-update-mark)
452                (gnus-group-real-name group) article mark))))
453
454 (defun gnus-request-article (article group &optional buffer)
455   "Request the ARTICLE in GROUP.
456 ARTICLE can either be an article number or an article Message-ID.
457 If BUFFER, insert the article in that group."
458   (let ((gnus-command-method (gnus-find-method-for-group group)))
459     (funcall (gnus-get-function gnus-command-method 'request-article)
460              article (gnus-group-real-name group)
461              (nth 1 gnus-command-method) buffer)))
462
463 (defun gnus-request-head (article group)
464   "Request the head of ARTICLE in GROUP."
465   (let* ((gnus-command-method (gnus-find-method-for-group group))
466          (head (gnus-get-function gnus-command-method 'request-head t))
467          res clean-up)
468     (cond
469      ;; Check the cache.
470      ((and gnus-use-cache
471            (numberp article)
472            (gnus-cache-request-article article group))
473       (setq res (cons group article)
474             clean-up t))
475      ;; Check the agent cache.
476      ((gnus-agent-request-article article group)
477       (setq res (cons group article)
478             clean-up t))
479      ;; Use `head' function.
480      ((fboundp head)
481       (setq res (funcall head article (gnus-group-real-name group)
482                          (nth 1 gnus-command-method))))
483      ;; Use `article' function.
484      (t
485       (setq res (gnus-request-article article group)
486             clean-up t)))
487     (when clean-up
488       (save-excursion
489         (set-buffer nntp-server-buffer)
490         (goto-char (point-min))
491         (when (search-forward "\n\n" nil t)
492           (delete-region (1- (point)) (point-max)))
493         (nnheader-fold-continuation-lines)))
494     res))
495
496 (defun gnus-request-body (article group)
497   "Request the body of ARTICLE in GROUP."
498   (let* ((gnus-command-method (gnus-find-method-for-group group))
499          (head (gnus-get-function gnus-command-method 'request-body t))
500          res clean-up)
501     (cond
502      ;; Check the cache.
503      ((and gnus-use-cache
504            (numberp article)
505            (gnus-cache-request-article article group))
506       (setq res (cons group article)
507             clean-up t))
508      ;; Check the agent cache.
509      ((gnus-agent-request-article article group)
510       (setq res (cons group article)
511             clean-up t))
512      ;; Use `head' function.
513      ((fboundp head)
514       (setq res (funcall head article (gnus-group-real-name group)
515                          (nth 1 gnus-command-method))))
516      ;; Use `article' function.
517      (t
518       (setq res (gnus-request-article article group)
519             clean-up t)))
520     (when clean-up
521       (save-excursion
522         (set-buffer nntp-server-buffer)
523         (goto-char (point-min))
524         (when (search-forward "\n\n" nil t)
525           (delete-region (point-min) (1- (point))))))
526     res))
527
528 (defun gnus-request-post (gnus-command-method)
529   "Post the current buffer using GNUS-COMMAND-METHOD."
530   (when (stringp gnus-command-method)
531     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
532   (funcall (gnus-get-function gnus-command-method 'request-post)
533            (nth 1 gnus-command-method)))
534
535 (defun gnus-request-scan (group gnus-command-method)
536   "Request a SCAN being performed in GROUP from GNUS-COMMAND-METHOD.
537 If GROUP is nil, all groups on GNUS-COMMAND-METHOD are scanned."
538   (let ((gnus-command-method
539          (if group (gnus-find-method-for-group group) gnus-command-method))
540         (gnus-inhibit-demon t)
541         (mail-source-plugged gnus-plugged))
542     (when (or gnus-plugged (not (gnus-agent-method-p gnus-command-method)))
543       (setq gnus-internal-registry-spool-current-method gnus-command-method)
544       (funcall (gnus-get-function gnus-command-method 'request-scan)
545                (and group (gnus-group-real-name group))
546                (nth 1 gnus-command-method)))))
547
548 (defsubst gnus-request-update-info (info gnus-command-method)
549   "Request that GNUS-COMMAND-METHOD update INFO."
550   (when (stringp gnus-command-method)
551     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
552   (when (gnus-check-backend-function
553          'request-update-info (car gnus-command-method))
554     (let ((group (gnus-info-group info)))
555       (and (funcall (gnus-get-function gnus-command-method
556                                        'request-update-info)
557                     (gnus-group-real-name group)
558                     info (nth 1 gnus-command-method))
559            ;; If the minimum article number is greater than 1, then all
560            ;; smaller article numbers are known not to exist; we'll
561            ;; artificially add those to the 'read range.
562            (let* ((active (gnus-active group))
563                   (min (car active)))
564              (when (> min 1)
565                (let* ((range (if (= min 2) 1 (cons 1 (1- min))))
566                       (read (gnus-info-read info))
567                       (new-read (gnus-range-add read (list range))))
568                  (gnus-info-set-read info new-read)))
569              info)))))
570
571 (defun gnus-request-expire-articles (articles group &optional force)
572   (let* ((gnus-command-method (gnus-find-method-for-group group))
573          (not-deleted
574           (funcall
575            (gnus-get-function gnus-command-method 'request-expire-articles)
576            articles (gnus-group-real-name group) (nth 1 gnus-command-method)
577            force)))
578     (when (and gnus-agent
579                (gnus-agent-method-p gnus-command-method))
580       (let ((expired-articles (gnus-sorted-difference articles not-deleted)))
581         (when expired-articles
582           (gnus-agent-expire expired-articles group 'force))))
583     not-deleted))
584
585 (defun gnus-request-move-article (article group server accept-function
586                                           &optional last move-is-internal)
587   (let* ((gnus-command-method (gnus-find-method-for-group group))
588          (result (funcall (gnus-get-function gnus-command-method
589                                              'request-move-article)
590                           article (gnus-group-real-name group)
591                           (nth 1 gnus-command-method) accept-function last move-is-internal)))
592     (when (and result gnus-agent
593                (gnus-agent-method-p gnus-command-method))
594       (gnus-agent-unfetch-articles group (list article)))
595     result))
596
597 (defun gnus-request-accept-article (group &optional gnus-command-method last
598                                           no-encode)
599   ;; Make sure there's a newline at the end of the article.
600   (when (stringp gnus-command-method)
601     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
602   (when (and (not gnus-command-method)
603              (stringp group))
604     (setq gnus-command-method (or (gnus-find-method-for-group group)
605                                   (gnus-group-name-to-method group))))
606   (goto-char (point-max))
607   (unless (bolp)
608     (insert "\n"))
609   (let ((gnus-command-method (or gnus-command-method
610                                  (gnus-find-method-for-group group)))
611         (result
612          (funcall
613           (gnus-get-function gnus-command-method 'request-accept-article)
614           (if (stringp group) (gnus-group-real-name group) group)
615           (cadr gnus-command-method)
616           last)))
617     (when (and gnus-agent (gnus-agent-method-p gnus-command-method))
618       (gnus-agent-regenerate-group group (list (cdr result))))
619     result))
620
621 (defun gnus-request-replace-article (article group buffer &optional no-encode)
622   (let* ((func (car (gnus-group-name-to-method group)))
623          (result (funcall (intern (format "%s-request-replace-article" func))
624                           article (gnus-group-real-name group) buffer)))
625     (when (and gnus-agent (gnus-agent-method-p gnus-command-method))
626       (gnus-agent-regenerate-group group (list article)))
627     result))
628
629 (defun gnus-request-associate-buffer (group)
630   (let ((gnus-command-method (gnus-find-method-for-group group)))
631     (funcall (gnus-get-function gnus-command-method 'request-associate-buffer)
632              (gnus-group-real-name group))))
633
634 (defun gnus-request-restore-buffer (article group)
635   "Request a new buffer restored to the state of ARTICLE."
636   (let ((gnus-command-method (gnus-find-method-for-group group)))
637     (funcall (gnus-get-function gnus-command-method 'request-restore-buffer)
638              article (gnus-group-real-name group)
639              (nth 1 gnus-command-method))))
640
641 (defun gnus-request-create-group (group &optional gnus-command-method args)
642   (when (stringp gnus-command-method)
643     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
644   (let ((gnus-command-method
645          (or gnus-command-method (gnus-find-method-for-group group))))
646     (funcall (gnus-get-function gnus-command-method 'request-create-group)
647              (gnus-group-real-name group) (nth 1 gnus-command-method) args)))
648
649 (defun gnus-request-delete-group (group &optional force)
650   (let* ((gnus-command-method (gnus-find-method-for-group group))
651          (result
652           (funcall (gnus-get-function gnus-command-method 'request-delete-group)
653                    (gnus-group-real-name group) force (nth 1 gnus-command-method))))
654     (when result
655       (gnus-cache-delete-group group)
656       (gnus-agent-delete-group group))
657     result))
658
659 (defun gnus-request-rename-group (group new-name)
660   (let* ((gnus-command-method (gnus-find-method-for-group group))
661          (result
662           (funcall (gnus-get-function gnus-command-method 'request-rename-group)
663                    (gnus-group-real-name group)
664                    (gnus-group-real-name new-name) (nth 1 gnus-command-method))))
665     (when result
666       (gnus-cache-rename-group group new-name)
667       (gnus-agent-rename-group group new-name))
668     result))
669
670 (defun gnus-close-backends ()
671   ;; Send a close request to all backends that support such a request.
672   (let ((methods gnus-valid-select-methods)
673         (gnus-inhibit-demon t)
674         func gnus-command-method)
675     (while (setq gnus-command-method (pop methods))
676       (when (fboundp (setq func (intern
677                                  (concat (car gnus-command-method)
678                                          "-request-close"))))
679         (funcall func)))))
680
681 (defun gnus-asynchronous-p (gnus-command-method)
682   (let ((func (gnus-get-function gnus-command-method 'asynchronous-p t)))
683     (when (fboundp func)
684       (funcall func))))
685
686 (defun gnus-remove-denial (gnus-command-method)
687   (when (stringp gnus-command-method)
688     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
689   (let* ((elem (assoc gnus-command-method gnus-opened-servers))
690          (status (cadr elem)))
691     ;; If this hasn't been opened before, we add it to the list.
692     (when (eq status 'denied)
693       ;; Set the status of this server.
694       (setcar (cdr elem) 'closed))))
695
696 (provide 'gnus-int)
697
698 ;;; gnus-int.el ends here