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