(gnus-dribble-read-file): Quote file-precious-flag.
[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 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 2, 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     ;; If this method was previously denied, we just return nil.
214     (if (eq (nth 1 elem) 'denied)
215         (progn
216           (gnus-message 1 "Denied server")
217           nil)
218       ;; Open the server.
219       (let* ((open-server-function (gnus-get-function gnus-command-method 'open-server))
220              (result
221              (condition-case err
222                  (funcall open-server-function
223                           (nth 1 gnus-command-method)
224                           (nthcdr 2 gnus-command-method))
225                (error
226                 (gnus-message 1 (format
227                                  "Unable to open server due to: %s"
228                                  (error-message-string err)))
229                 nil)
230                (quit
231                 (gnus-message 1 "Quit trying to open server")
232                 nil)))
233             open-offline)
234         ;; If this hasn't been opened before, we add it to the list.
235         (unless elem
236           (setq elem (list gnus-command-method nil)
237                 gnus-opened-servers (cons elem gnus-opened-servers)))
238         ;; Set the status of this server.
239         (setcar (cdr elem)
240                 (cond (result
241                        (if (eq open-server-function #'nnagent-open-server)
242                            ;; The agent's backend has a "special" status
243                            'offline
244                          'ok))
245                       ((and gnus-agent
246                             (gnus-agent-method-p gnus-command-method))
247                        (cond (gnus-server-unopen-status
248                               ;; Set the server's status to the unopen
249                               ;; status.  If that status is offline,
250                               ;; recurse to open the agent's backend.
251                               (setq open-offline (eq gnus-server-unopen-status 'offline))
252                               gnus-server-unopen-status)
253                              ((gnus-y-or-n-p
254                                (format "Unable to open %s:%s, go offline? "
255                                        (car gnus-command-method)
256                                        (cadr gnus-command-method)))
257                               (setq open-offline t)
258                               'offline)
259                              (t
260                               ;; This agentized server was still denied
261                               'denied)))
262                       (t
263                        ;; This unagentized server must be denied
264                        'denied)))
265
266         ;; NOTE: I MUST set the server's status to offline before this
267         ;; recursive call as this status will drive the
268         ;; gnus-get-function (called above) to return the agent's
269         ;; backend.
270         (if open-offline
271             ;; Recursively open this offline server to perform the
272             ;; open-server function of the agent's backend.
273             (let ((gnus-server-unopen-status 'denied))
274               ;; Bind gnus-server-unopen-status to avoid recursively
275               ;; prompting with "go offline?".  This is only a concern
276               ;; when the agent's backend fails to open the server.
277               (gnus-open-server gnus-command-method))
278           result)))))
279
280 (defun gnus-close-server (gnus-command-method)
281   "Close the connection to GNUS-COMMAND-METHOD."
282   (when (stringp gnus-command-method)
283     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
284   (funcall (gnus-get-function gnus-command-method 'close-server)
285            (nth 1 gnus-command-method)))
286
287 (defun gnus-request-list (gnus-command-method)
288   "Request the active file from GNUS-COMMAND-METHOD."
289   (when (stringp gnus-command-method)
290     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
291   (funcall (gnus-get-function gnus-command-method 'request-list)
292            (nth 1 gnus-command-method)))
293
294 (defun gnus-request-list-newsgroups (gnus-command-method)
295   "Request the newsgroups file from GNUS-COMMAND-METHOD."
296   (when (stringp gnus-command-method)
297     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
298   (funcall (gnus-get-function gnus-command-method 'request-list-newsgroups)
299            (nth 1 gnus-command-method)))
300
301 (defun gnus-request-newgroups (date gnus-command-method)
302   "Request all new groups since DATE from GNUS-COMMAND-METHOD."
303   (when (stringp gnus-command-method)
304     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
305   (let ((func (gnus-get-function gnus-command-method 'request-newgroups t)))
306     (when func
307       (funcall func date (nth 1 gnus-command-method)))))
308
309 (defun gnus-server-opened (gnus-command-method)
310   "Check whether a connection to GNUS-COMMAND-METHOD has been opened."
311   (unless (eq (gnus-server-status gnus-command-method)
312               'denied)
313     (when (stringp gnus-command-method)
314       (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
315     (funcall (inline (gnus-get-function gnus-command-method 'server-opened))
316              (nth 1 gnus-command-method))))
317
318 (defun gnus-status-message (gnus-command-method)
319   "Return the status message from GNUS-COMMAND-METHOD.
320 If GNUS-COMMAND-METHOD is a string, it is interpreted as a group
321 name.  The method this group uses will be queried."
322   (let ((gnus-command-method
323          (if (stringp gnus-command-method)
324              (gnus-find-method-for-group gnus-command-method)
325            gnus-command-method)))
326     (funcall (gnus-get-function gnus-command-method 'status-message)
327              (nth 1 gnus-command-method))))
328
329 (defun gnus-request-regenerate (gnus-command-method)
330   "Request a data generation from GNUS-COMMAND-METHOD."
331   (when (stringp gnus-command-method)
332     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
333   (funcall (gnus-get-function gnus-command-method 'request-regenerate)
334            (nth 1 gnus-command-method)))
335
336 (defun gnus-request-compact-group (group)
337   (let* ((method (gnus-find-method-for-group group))
338          (gnus-command-method method)
339          (result
340           (funcall (gnus-get-function gnus-command-method
341                                       'request-compact-group)
342                    (gnus-group-real-name group)
343                    (nth 1 gnus-command-method) t)))
344     result))
345
346 (defun gnus-request-compact (gnus-command-method)
347   "Request groups compaction  from GNUS-COMMAND-METHOD."
348   (when (stringp gnus-command-method)
349     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
350   (funcall (gnus-get-function gnus-command-method 'request-compact)
351            (nth 1 gnus-command-method)))
352
353 (defun gnus-request-group (group &optional dont-check gnus-command-method)
354   "Request GROUP.  If DONT-CHECK, no information is required."
355   (let ((gnus-command-method
356          (or gnus-command-method (inline (gnus-find-method-for-group group)))))
357     (when (stringp gnus-command-method)
358       (setq gnus-command-method
359             (inline (gnus-server-to-method gnus-command-method))))
360          (funcall (inline (gnus-get-function gnus-command-method 'request-group))
361              (gnus-group-real-name group) (nth 1 gnus-command-method)
362              dont-check)))
363
364 (defun gnus-list-active-group (group)
365   "Request active information on GROUP."
366   (let ((gnus-command-method (gnus-find-method-for-group group))
367         (func 'list-active-group))
368     (when (gnus-check-backend-function func group)
369       (funcall (gnus-get-function gnus-command-method func)
370                (gnus-group-real-name group) (nth 1 gnus-command-method)))))
371
372 (defun gnus-request-group-description (group)
373   "Request a description of GROUP."
374   (let ((gnus-command-method (gnus-find-method-for-group group))
375         (func 'request-group-description))
376     (when (gnus-check-backend-function func group)
377       (funcall (gnus-get-function gnus-command-method func)
378                (gnus-group-real-name group) (nth 1 gnus-command-method)))))
379
380 (defun gnus-request-group-articles (group)
381   "Request a list of existing articles in GROUP."
382   (let ((gnus-command-method (gnus-find-method-for-group group))
383         (func 'request-group-articles))
384     (when (gnus-check-backend-function func group)
385       (funcall (gnus-get-function gnus-command-method func)
386                (gnus-group-real-name group) (nth 1 gnus-command-method)))))
387
388 (defun gnus-close-group (group)
389   "Request the GROUP be closed."
390   (let ((gnus-command-method (inline (gnus-find-method-for-group group))))
391     (funcall (gnus-get-function gnus-command-method 'close-group)
392              (gnus-group-real-name group) (nth 1 gnus-command-method))))
393
394 (defun gnus-retrieve-headers (articles group &optional fetch-old)
395   "Request headers for ARTICLES in GROUP.
396 If FETCH-OLD, retrieve all headers (or some subset thereof) in the group."
397   (let ((gnus-command-method (gnus-find-method-for-group group)))
398     (cond
399      ((and gnus-use-cache (numberp (car articles)))
400       (gnus-cache-retrieve-headers articles group fetch-old))
401      ((and gnus-agent (gnus-online gnus-command-method)
402            (gnus-agent-method-p gnus-command-method))
403       (gnus-agent-retrieve-headers articles group fetch-old))
404      (t
405       (funcall (gnus-get-function gnus-command-method 'retrieve-headers)
406                articles (gnus-group-real-name group)
407                (nth 1 gnus-command-method) fetch-old)))))
408
409 (defun gnus-retrieve-articles (articles group)
410   "Request ARTICLES in GROUP."
411   (let ((gnus-command-method (gnus-find-method-for-group group)))
412     (funcall (gnus-get-function gnus-command-method 'retrieve-articles)
413              articles (gnus-group-real-name group)
414              (nth 1 gnus-command-method))))
415
416 (defun gnus-retrieve-groups (groups gnus-command-method)
417   "Request active information on GROUPS from GNUS-COMMAND-METHOD."
418   (when (stringp gnus-command-method)
419     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
420   (funcall (gnus-get-function gnus-command-method 'retrieve-groups)
421            groups (nth 1 gnus-command-method)))
422
423 (defun gnus-request-type (group &optional article)
424   "Return the type (`post' or `mail') of GROUP (and ARTICLE)."
425   (let ((gnus-command-method (gnus-find-method-for-group group)))
426     (if (not (gnus-check-backend-function
427               'request-type (car gnus-command-method)))
428         'unknown
429       (funcall (gnus-get-function gnus-command-method 'request-type)
430                (gnus-group-real-name group) article))))
431
432 (defun gnus-request-set-mark (group action)
433   "Set marks on articles in the back end."
434   (let ((gnus-command-method (gnus-find-method-for-group group)))
435     (if (not (gnus-check-backend-function
436               'request-set-mark (car gnus-command-method)))
437         action
438       (funcall (gnus-get-function gnus-command-method 'request-set-mark)
439                (gnus-group-real-name group) action
440                (nth 1 gnus-command-method)))))
441
442 (defun gnus-request-update-mark (group article mark)
443   "Allow the back end to change the mark the user tries to put on an article."
444   (let ((gnus-command-method (gnus-find-method-for-group group)))
445     (if (not (gnus-check-backend-function
446               'request-update-mark (car gnus-command-method)))
447         mark
448       (funcall (gnus-get-function gnus-command-method 'request-update-mark)
449                (gnus-group-real-name group) article mark))))
450
451 (defun gnus-request-article (article group &optional buffer)
452   "Request the ARTICLE in GROUP.
453 ARTICLE can either be an article number or an article Message-ID.
454 If BUFFER, insert the article in that group."
455   (let ((gnus-command-method (gnus-find-method-for-group group)))
456     (funcall (gnus-get-function gnus-command-method 'request-article)
457              article (gnus-group-real-name group)
458              (nth 1 gnus-command-method) buffer)))
459
460 (defun gnus-request-head (article group)
461   "Request the head of ARTICLE in GROUP."
462   (let* ((gnus-command-method (gnus-find-method-for-group group))
463          (head (gnus-get-function gnus-command-method 'request-head t))
464          res clean-up)
465     (cond
466      ;; Check the cache.
467      ((and gnus-use-cache
468            (numberp article)
469            (gnus-cache-request-article article group))
470       (setq res (cons group article)
471             clean-up t))
472      ;; Check the agent cache.
473      ((gnus-agent-request-article article group)
474       (setq res (cons group article)
475             clean-up t))
476      ;; Use `head' function.
477      ((fboundp head)
478       (setq res (funcall head article (gnus-group-real-name group)
479                          (nth 1 gnus-command-method))))
480      ;; Use `article' function.
481      (t
482       (setq res (gnus-request-article article group)
483             clean-up t)))
484     (when clean-up
485       (save-excursion
486         (set-buffer nntp-server-buffer)
487         (goto-char (point-min))
488         (when (search-forward "\n\n" nil t)
489           (delete-region (1- (point)) (point-max)))
490         (nnheader-fold-continuation-lines)))
491     res))
492
493 (defun gnus-request-body (article group)
494   "Request the body of ARTICLE in GROUP."
495   (let* ((gnus-command-method (gnus-find-method-for-group group))
496          (head (gnus-get-function gnus-command-method 'request-body t))
497          res clean-up)
498     (cond
499      ;; Check the cache.
500      ((and gnus-use-cache
501            (numberp article)
502            (gnus-cache-request-article article group))
503       (setq res (cons group article)
504             clean-up t))
505      ;; Check the agent cache.
506      ((gnus-agent-request-article article group)
507       (setq res (cons group article)
508             clean-up t))
509      ;; Use `head' function.
510      ((fboundp head)
511       (setq res (funcall head article (gnus-group-real-name group)
512                          (nth 1 gnus-command-method))))
513      ;; Use `article' function.
514      (t
515       (setq res (gnus-request-article article group)
516             clean-up t)))
517     (when clean-up
518       (save-excursion
519         (set-buffer nntp-server-buffer)
520         (goto-char (point-min))
521         (when (search-forward "\n\n" nil t)
522           (delete-region (point-min) (1- (point))))))
523     res))
524
525 (defun gnus-request-post (gnus-command-method)
526   "Post the current buffer using GNUS-COMMAND-METHOD."
527   (when (stringp gnus-command-method)
528     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
529   (funcall (gnus-get-function gnus-command-method 'request-post)
530            (nth 1 gnus-command-method)))
531
532 (defun gnus-request-scan (group gnus-command-method)
533   "Request a SCAN being performed in GROUP from GNUS-COMMAND-METHOD.
534 If GROUP is nil, all groups on GNUS-COMMAND-METHOD are scanned."
535   (let ((gnus-command-method
536          (if group (gnus-find-method-for-group group) gnus-command-method))
537         (gnus-inhibit-demon t)
538         (mail-source-plugged gnus-plugged))
539     (when (or gnus-plugged (not (gnus-agent-method-p gnus-command-method)))
540       (setq gnus-internal-registry-spool-current-method gnus-command-method)
541       (funcall (gnus-get-function gnus-command-method 'request-scan)
542                (and group (gnus-group-real-name group))
543                (nth 1 gnus-command-method)))))
544
545 (defsubst gnus-request-update-info (info gnus-command-method)
546   "Request that GNUS-COMMAND-METHOD update INFO."
547   (when (stringp gnus-command-method)
548     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
549   (when (gnus-check-backend-function
550          'request-update-info (car gnus-command-method))
551     (let ((group (gnus-info-group info)))
552       (and (funcall (gnus-get-function gnus-command-method
553                                        'request-update-info)
554                     (gnus-group-real-name group)
555                     info (nth 1 gnus-command-method))
556            ;; If the minimum article number is greater than 1, then all
557            ;; smaller article numbers are known not to exist; we'll
558            ;; artificially add those to the 'read range.
559            (let* ((active (gnus-active group))
560                   (min (car active)))
561              (when (> min 1)
562                (let* ((range (if (= min 2) 1 (cons 1 (1- min))))
563                       (read (gnus-info-read info))
564                       (new-read (gnus-range-add read (list range))))
565                  (gnus-info-set-read info new-read)))
566              info)))))
567
568 (defun gnus-request-expire-articles (articles group &optional force)
569   (let* ((gnus-command-method (gnus-find-method-for-group group))
570          (not-deleted
571           (funcall
572            (gnus-get-function gnus-command-method 'request-expire-articles)
573            articles (gnus-group-real-name group) (nth 1 gnus-command-method)
574            force)))
575     (when (and gnus-agent
576                (gnus-agent-method-p gnus-command-method))
577       (let ((expired-articles (gnus-sorted-difference articles not-deleted)))
578         (when expired-articles
579           (gnus-agent-expire expired-articles group 'force))))
580     not-deleted))
581
582 (defun gnus-request-move-article (article group server accept-function
583                                           &optional last move-is-internal)
584   (let* ((gnus-command-method (gnus-find-method-for-group group))
585          (result (funcall (gnus-get-function gnus-command-method
586                                              'request-move-article)
587                           article (gnus-group-real-name group)
588                           (nth 1 gnus-command-method) accept-function last move-is-internal)))
589     (when (and result gnus-agent
590                (gnus-agent-method-p gnus-command-method))
591       (gnus-agent-unfetch-articles group (list article)))
592     result))
593
594 (defun gnus-request-accept-article (group &optional gnus-command-method last
595                                           no-encode)
596   ;; Make sure there's a newline at the end of the article.
597   (when (stringp gnus-command-method)
598     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
599   (when (and (not gnus-command-method)
600              (stringp group))
601     (setq gnus-command-method (or (gnus-find-method-for-group group)
602                                   (gnus-group-name-to-method group))))
603   (goto-char (point-max))
604   (unless (bolp)
605     (insert "\n"))
606   (unless no-encode
607     (let ((message-options message-options))
608       (message-options-set-recipient)
609       (save-restriction
610         (message-narrow-to-head)
611         (let ((mail-parse-charset message-default-charset))
612           (mail-encode-encoded-word-buffer)))
613       (message-encode-message-body)))
614   (let ((gnus-command-method (or gnus-command-method
615                                  (gnus-find-method-for-group group)))
616         (result
617          (funcall
618           (gnus-get-function gnus-command-method 'request-accept-article)
619           (if (stringp group) (gnus-group-real-name group) group)
620           (cadr gnus-command-method)
621           last)))
622     (when (and gnus-agent (gnus-agent-method-p gnus-command-method))
623       (gnus-agent-regenerate-group group (list (cdr result))))
624     result))
625
626 (defun gnus-request-replace-article (article group buffer &optional no-encode)
627   (unless no-encode
628     (let ((message-options message-options))
629       (message-options-set-recipient)
630       (save-restriction
631         (message-narrow-to-head)
632         (let ((mail-parse-charset message-default-charset))
633           (mail-encode-encoded-word-buffer)))
634       (message-encode-message-body)))
635   (let* ((func (car (gnus-group-name-to-method group)))
636          (result (funcall (intern (format "%s-request-replace-article" func))
637                           article (gnus-group-real-name group) buffer)))
638     (when (and gnus-agent (gnus-agent-method-p gnus-command-method))
639       (gnus-agent-regenerate-group group (list article)))
640     result))
641
642 (defun gnus-request-associate-buffer (group)
643   (let ((gnus-command-method (gnus-find-method-for-group group)))
644     (funcall (gnus-get-function gnus-command-method 'request-associate-buffer)
645              (gnus-group-real-name group))))
646
647 (defun gnus-request-restore-buffer (article group)
648   "Request a new buffer restored to the state of ARTICLE."
649   (let ((gnus-command-method (gnus-find-method-for-group group)))
650     (funcall (gnus-get-function gnus-command-method 'request-restore-buffer)
651              article (gnus-group-real-name group)
652              (nth 1 gnus-command-method))))
653
654 (defun gnus-request-create-group (group &optional gnus-command-method args)
655   (when (stringp gnus-command-method)
656     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
657   (let ((gnus-command-method
658          (or gnus-command-method (gnus-find-method-for-group group))))
659     (funcall (gnus-get-function gnus-command-method 'request-create-group)
660              (gnus-group-real-name group) (nth 1 gnus-command-method) args)))
661
662 (defun gnus-request-delete-group (group &optional force)
663   (let* ((gnus-command-method (gnus-find-method-for-group group))
664          (result
665           (funcall (gnus-get-function gnus-command-method 'request-delete-group)
666                    (gnus-group-real-name group) force (nth 1 gnus-command-method))))
667     (when result
668       (gnus-cache-delete-group group)
669       (gnus-agent-delete-group group))
670     result))
671
672 (defun gnus-request-rename-group (group new-name)
673   (let* ((gnus-command-method (gnus-find-method-for-group group))
674          (result
675           (funcall (gnus-get-function gnus-command-method 'request-rename-group)
676                    (gnus-group-real-name group)
677                    (gnus-group-real-name new-name) (nth 1 gnus-command-method))))
678     (when result
679       (gnus-cache-rename-group group new-name)
680       (gnus-agent-rename-group group new-name))
681     result))
682
683 (defun gnus-close-backends ()
684   ;; Send a close request to all backends that support such a request.
685   (let ((methods gnus-valid-select-methods)
686         (gnus-inhibit-demon t)
687         func gnus-command-method)
688     (while (setq gnus-command-method (pop methods))
689       (when (fboundp (setq func (intern
690                                  (concat (car gnus-command-method)
691                                          "-request-close"))))
692         (funcall func)))))
693
694 (defun gnus-asynchronous-p (gnus-command-method)
695   (let ((func (gnus-get-function gnus-command-method 'asynchronous-p t)))
696     (when (fboundp func)
697       (funcall func))))
698
699 (defun gnus-remove-denial (gnus-command-method)
700   (when (stringp gnus-command-method)
701     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
702   (let* ((elem (assoc gnus-command-method gnus-opened-servers))
703          (status (cadr elem)))
704     ;; If this hasn't been opened before, we add it to the list.
705     (when (eq status 'denied)
706       ;; Set the status of this server.
707       (setcar (cdr elem) 'closed))))
708
709 (provide 'gnus-int)
710
711 ;;; arch-tag: bbc90087-9b7f-4017-a92c-3abf180ac86d
712 ;;; gnus-int.el ends here