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