Revision: miles@gnu.org--gnu-2005/gnus--devo--0--patch-182
[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-group (group &optional dont-check gnus-command-method)
337   "Request GROUP.  If DONT-CHECK, no information is required."
338   (let ((gnus-command-method
339          (or gnus-command-method (inline (gnus-find-method-for-group group)))))
340     (when (stringp gnus-command-method)
341       (setq gnus-command-method
342             (inline (gnus-server-to-method gnus-command-method))))
343          (funcall (inline (gnus-get-function gnus-command-method 'request-group))
344              (gnus-group-real-name group) (nth 1 gnus-command-method)
345              dont-check)))
346
347 (defun gnus-list-active-group (group)
348   "Request active information on GROUP."
349   (let ((gnus-command-method (gnus-find-method-for-group group))
350         (func 'list-active-group))
351     (when (gnus-check-backend-function func group)
352       (funcall (gnus-get-function gnus-command-method func)
353                (gnus-group-real-name group) (nth 1 gnus-command-method)))))
354
355 (defun gnus-request-group-description (group)
356   "Request a description of GROUP."
357   (let ((gnus-command-method (gnus-find-method-for-group group))
358         (func 'request-group-description))
359     (when (gnus-check-backend-function func group)
360       (funcall (gnus-get-function gnus-command-method func)
361                (gnus-group-real-name group) (nth 1 gnus-command-method)))))
362
363 (defun gnus-request-group-articles (group)
364   "Request a list of existing articles in GROUP."
365   (let ((gnus-command-method (gnus-find-method-for-group group))
366         (func 'request-group-articles))
367     (when (gnus-check-backend-function func group)
368       (funcall (gnus-get-function gnus-command-method func)
369                (gnus-group-real-name group) (nth 1 gnus-command-method)))))
370
371 (defun gnus-close-group (group)
372   "Request the GROUP be closed."
373   (let ((gnus-command-method (inline (gnus-find-method-for-group group))))
374     (funcall (gnus-get-function gnus-command-method 'close-group)
375              (gnus-group-real-name group) (nth 1 gnus-command-method))))
376
377 (defun gnus-retrieve-headers (articles group &optional fetch-old)
378   "Request headers for ARTICLES in GROUP.
379 If FETCH-OLD, retrieve all headers (or some subset thereof) in the group."
380   (let ((gnus-command-method (gnus-find-method-for-group group)))
381     (cond
382      ((and gnus-use-cache (numberp (car articles)))
383       (gnus-cache-retrieve-headers articles group fetch-old))
384      ((and gnus-agent (gnus-online gnus-command-method)
385            (gnus-agent-method-p gnus-command-method))
386       (gnus-agent-retrieve-headers articles group fetch-old))
387      (t
388       (funcall (gnus-get-function gnus-command-method 'retrieve-headers)
389                articles (gnus-group-real-name group)
390                (nth 1 gnus-command-method) fetch-old)))))
391
392 (defun gnus-retrieve-articles (articles group)
393   "Request ARTICLES in GROUP."
394   (let ((gnus-command-method (gnus-find-method-for-group group)))
395     (funcall (gnus-get-function gnus-command-method 'retrieve-articles)
396              articles (gnus-group-real-name group)
397              (nth 1 gnus-command-method))))
398
399 (defun gnus-retrieve-groups (groups gnus-command-method)
400   "Request active information on GROUPS from GNUS-COMMAND-METHOD."
401   (when (stringp gnus-command-method)
402     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
403   (funcall (gnus-get-function gnus-command-method 'retrieve-groups)
404            groups (nth 1 gnus-command-method)))
405
406 (defun gnus-request-type (group &optional article)
407   "Return the type (`post' or `mail') of GROUP (and ARTICLE)."
408   (let ((gnus-command-method (gnus-find-method-for-group group)))
409     (if (not (gnus-check-backend-function
410               'request-type (car gnus-command-method)))
411         'unknown
412       (funcall (gnus-get-function gnus-command-method 'request-type)
413                (gnus-group-real-name group) article))))
414
415 (defun gnus-request-set-mark (group action)
416   "Set marks on articles in the back end."
417   (let ((gnus-command-method (gnus-find-method-for-group group)))
418     (if (not (gnus-check-backend-function
419               'request-set-mark (car gnus-command-method)))
420         action
421       (funcall (gnus-get-function gnus-command-method 'request-set-mark)
422                (gnus-group-real-name group) action
423                (nth 1 gnus-command-method)))))
424
425 (defun gnus-request-update-mark (group article mark)
426   "Allow the back end to change the mark the user tries to put on an article."
427   (let ((gnus-command-method (gnus-find-method-for-group group)))
428     (if (not (gnus-check-backend-function
429               'request-update-mark (car gnus-command-method)))
430         mark
431       (funcall (gnus-get-function gnus-command-method 'request-update-mark)
432                (gnus-group-real-name group) article mark))))
433
434 (defun gnus-request-article (article group &optional buffer)
435   "Request the ARTICLE in GROUP.
436 ARTICLE can either be an article number or an article Message-ID.
437 If BUFFER, insert the article in that group."
438   (let ((gnus-command-method (gnus-find-method-for-group group)))
439     (funcall (gnus-get-function gnus-command-method 'request-article)
440              article (gnus-group-real-name group)
441              (nth 1 gnus-command-method) buffer)))
442
443 (defun gnus-request-head (article group)
444   "Request the head of ARTICLE in GROUP."
445   (let* ((gnus-command-method (gnus-find-method-for-group group))
446          (head (gnus-get-function gnus-command-method 'request-head t))
447          res clean-up)
448     (cond
449      ;; Check the cache.
450      ((and gnus-use-cache
451            (numberp article)
452            (gnus-cache-request-article article group))
453       (setq res (cons group article)
454             clean-up t))
455      ;; Check the agent cache.
456      ((gnus-agent-request-article article group)
457       (setq res (cons group article)
458             clean-up t))
459      ;; Use `head' function.
460      ((fboundp head)
461       (setq res (funcall head article (gnus-group-real-name group)
462                          (nth 1 gnus-command-method))))
463      ;; Use `article' function.
464      (t
465       (setq res (gnus-request-article article group)
466             clean-up t)))
467     (when clean-up
468       (save-excursion
469         (set-buffer nntp-server-buffer)
470         (goto-char (point-min))
471         (when (search-forward "\n\n" nil t)
472           (delete-region (1- (point)) (point-max)))
473         (nnheader-fold-continuation-lines)))
474     res))
475
476 (defun gnus-request-body (article group)
477   "Request the body of ARTICLE in GROUP."
478   (let* ((gnus-command-method (gnus-find-method-for-group group))
479          (head (gnus-get-function gnus-command-method 'request-body t))
480          res clean-up)
481     (cond
482      ;; Check the cache.
483      ((and gnus-use-cache
484            (numberp article)
485            (gnus-cache-request-article article group))
486       (setq res (cons group article)
487             clean-up t))
488      ;; Check the agent cache.
489      ((gnus-agent-request-article article group)
490       (setq res (cons group article)
491             clean-up t))
492      ;; Use `head' function.
493      ((fboundp head)
494       (setq res (funcall head article (gnus-group-real-name group)
495                          (nth 1 gnus-command-method))))
496      ;; Use `article' function.
497      (t
498       (setq res (gnus-request-article article group)
499             clean-up t)))
500     (when clean-up
501       (save-excursion
502         (set-buffer nntp-server-buffer)
503         (goto-char (point-min))
504         (when (search-forward "\n\n" nil t)
505           (delete-region (point-min) (1- (point))))))
506     res))
507
508 (defun gnus-request-post (gnus-command-method)
509   "Post the current buffer using GNUS-COMMAND-METHOD."
510   (when (stringp gnus-command-method)
511     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
512   (funcall (gnus-get-function gnus-command-method 'request-post)
513            (nth 1 gnus-command-method)))
514
515 (defun gnus-request-scan (group gnus-command-method)
516   "Request a SCAN being performed in GROUP from GNUS-COMMAND-METHOD.
517 If GROUP is nil, all groups on GNUS-COMMAND-METHOD are scanned."
518   (let ((gnus-command-method
519          (if group (gnus-find-method-for-group group) gnus-command-method))
520         (gnus-inhibit-demon t)
521         (mail-source-plugged gnus-plugged))
522     (when (or gnus-plugged (not (gnus-agent-method-p gnus-command-method)))
523       (setq gnus-internal-registry-spool-current-method gnus-command-method)
524       (funcall (gnus-get-function gnus-command-method 'request-scan)
525                (and group (gnus-group-real-name group))
526                (nth 1 gnus-command-method)))))
527
528 (defsubst gnus-request-update-info (info gnus-command-method)
529   "Request that GNUS-COMMAND-METHOD update INFO."
530   (when (stringp gnus-command-method)
531     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
532   (when (gnus-check-backend-function
533          'request-update-info (car gnus-command-method))
534     (let ((group (gnus-info-group info)))
535       (and (funcall (gnus-get-function gnus-command-method
536                                        'request-update-info)
537                     (gnus-group-real-name group)
538                     info (nth 1 gnus-command-method))
539            ;; If the minimum article number is greater than 1, then all
540            ;; smaller article numbers are known not to exist; we'll
541            ;; artificially add those to the 'read range.
542            (let* ((active (gnus-active group))
543                   (min (car active)))
544              (when (> min 1)
545                (let* ((range (if (= min 2) 1 (cons 1 (1- min))))
546                       (read (gnus-info-read info))
547                       (new-read (gnus-range-add read (list range))))
548                  (gnus-info-set-read info new-read)))
549              info)))))
550
551 (defun gnus-request-expire-articles (articles group &optional force)
552   (let* ((gnus-command-method (gnus-find-method-for-group group))
553          (not-deleted
554           (funcall
555            (gnus-get-function gnus-command-method 'request-expire-articles)
556            articles (gnus-group-real-name group) (nth 1 gnus-command-method)
557            force)))
558     (when (and gnus-agent
559                (gnus-agent-method-p gnus-command-method))
560       (let ((expired-articles (gnus-sorted-difference articles not-deleted)))
561         (when expired-articles
562           (gnus-agent-expire expired-articles group 'force))))
563     not-deleted))
564
565 (defun gnus-request-move-article (article group server accept-function
566                                           &optional last move-is-internal)
567   (let* ((gnus-command-method (gnus-find-method-for-group group))
568          (result (funcall (gnus-get-function gnus-command-method
569                                              'request-move-article)
570                           article (gnus-group-real-name group)
571                           (nth 1 gnus-command-method) accept-function last move-is-internal)))
572     (when (and result gnus-agent
573                (gnus-agent-method-p gnus-command-method))
574       (gnus-agent-unfetch-articles group (list article)))
575     result))
576
577 (defun gnus-request-accept-article (group &optional gnus-command-method last
578                                           no-encode)
579   ;; Make sure there's a newline at the end of the article.
580   (when (stringp gnus-command-method)
581     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
582   (when (and (not gnus-command-method)
583              (stringp group))
584     (setq gnus-command-method (or (gnus-find-method-for-group group)
585                                   (gnus-group-name-to-method group))))
586   (goto-char (point-max))
587   (unless (bolp)
588     (insert "\n"))
589   (unless no-encode
590     (let ((message-options message-options))
591       (message-options-set-recipient)
592       (save-restriction
593         (message-narrow-to-head)
594         (let ((mail-parse-charset message-default-charset))
595           (mail-encode-encoded-word-buffer)))
596       (message-encode-message-body)))
597   (let ((gnus-command-method (or gnus-command-method
598                                  (gnus-find-method-for-group group)))
599         (result
600          (funcall
601           (gnus-get-function gnus-command-method 'request-accept-article)
602           (if (stringp group) (gnus-group-real-name group) group)
603           (cadr gnus-command-method)
604           last)))
605     (when (and gnus-agent (gnus-agent-method-p gnus-command-method))
606       (gnus-agent-regenerate-group group (list (cdr result))))
607     result))
608
609 (defun gnus-request-replace-article (article group buffer &optional no-encode)
610   (unless no-encode
611     (let ((message-options message-options))
612       (message-options-set-recipient)
613       (save-restriction
614         (message-narrow-to-head)
615         (let ((mail-parse-charset message-default-charset))
616           (mail-encode-encoded-word-buffer)))
617       (message-encode-message-body)))
618   (let* ((func (car (gnus-group-name-to-method group)))
619          (result (funcall (intern (format "%s-request-replace-article" func))
620                           article (gnus-group-real-name group) buffer)))
621     (when (and gnus-agent (gnus-agent-method-p gnus-command-method))
622       (gnus-agent-regenerate-group group (list article)))
623     result))
624
625 (defun gnus-request-associate-buffer (group)
626   (let ((gnus-command-method (gnus-find-method-for-group group)))
627     (funcall (gnus-get-function gnus-command-method 'request-associate-buffer)
628              (gnus-group-real-name group))))
629
630 (defun gnus-request-restore-buffer (article group)
631   "Request a new buffer restored to the state of ARTICLE."
632   (let ((gnus-command-method (gnus-find-method-for-group group)))
633     (funcall (gnus-get-function gnus-command-method 'request-restore-buffer)
634              article (gnus-group-real-name group)
635              (nth 1 gnus-command-method))))
636
637 (defun gnus-request-create-group (group &optional gnus-command-method args)
638   (when (stringp gnus-command-method)
639     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
640   (let ((gnus-command-method
641          (or gnus-command-method (gnus-find-method-for-group group))))
642     (funcall (gnus-get-function gnus-command-method 'request-create-group)
643              (gnus-group-real-name group) (nth 1 gnus-command-method) args)))
644
645 (defun gnus-request-delete-group (group &optional force)
646   (let* ((gnus-command-method (gnus-find-method-for-group group))
647          (result
648           (funcall (gnus-get-function gnus-command-method 'request-delete-group)
649                    (gnus-group-real-name group) force (nth 1 gnus-command-method))))
650     (when result
651       (gnus-cache-delete-group group)
652       (gnus-agent-delete-group group))
653     result))
654
655 (defun gnus-request-rename-group (group new-name)
656   (let* ((gnus-command-method (gnus-find-method-for-group group))
657          (result
658           (funcall (gnus-get-function gnus-command-method 'request-rename-group)
659                    (gnus-group-real-name group)
660                    (gnus-group-real-name new-name) (nth 1 gnus-command-method))))
661     (when result
662       (gnus-cache-rename-group group new-name)
663       (gnus-agent-rename-group group new-name))
664     result))
665
666 (defun gnus-close-backends ()
667   ;; Send a close request to all backends that support such a request.
668   (let ((methods gnus-valid-select-methods)
669         (gnus-inhibit-demon t)
670         func gnus-command-method)
671     (while (setq gnus-command-method (pop methods))
672       (when (fboundp (setq func (intern
673                                  (concat (car gnus-command-method)
674                                          "-request-close"))))
675         (funcall func)))))
676
677 (defun gnus-asynchronous-p (gnus-command-method)
678   (let ((func (gnus-get-function gnus-command-method 'asynchronous-p t)))
679     (when (fboundp func)
680       (funcall func))))
681
682 (defun gnus-remove-denial (gnus-command-method)
683   (when (stringp gnus-command-method)
684     (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
685   (let* ((elem (assoc gnus-command-method gnus-opened-servers))
686          (status (cadr elem)))
687     ;; If this hasn't been opened before, we add it to the list.
688     (when (eq status 'denied)
689       ;; Set the status of this server.
690       (setcar (cdr elem) 'closed))))
691
692 (provide 'gnus-int)
693
694 ;;; arch-tag: bbc90087-9b7f-4017-a92c-3abf180ac86d
695 ;;; gnus-int.el ends here