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