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