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