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