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