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