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