]> code.delx.au - gnu-emacs/blob - lisp/gnus/gnus-int.el
Update copyright notices of all files in the gnus directory.
[gnu-emacs] / lisp / gnus / gnus-int.el
1 ;;; gnus-int.el --- backend interface functions for Gnus
2
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
4 ;; 2005, 2006 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 (lambda (server) (list server))
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 (if (or gnus-plugged (not (gnus-agent-method-p gnus-command-method)))
523 (progn
524 (setq gnus-internal-registry-spool-current-method gnus-command-method)
525 (funcall (gnus-get-function gnus-command-method 'request-scan)
526 (and group (gnus-group-real-name group))
527 (nth 1 gnus-command-method))))))
528
529 (defsubst gnus-request-update-info (info gnus-command-method)
530 "Request that GNUS-COMMAND-METHOD update INFO."
531 (when (stringp gnus-command-method)
532 (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
533 (when (gnus-check-backend-function
534 'request-update-info (car gnus-command-method))
535 (let ((group (gnus-info-group info)))
536 (and (funcall (gnus-get-function gnus-command-method
537 'request-update-info)
538 (gnus-group-real-name group)
539 info (nth 1 gnus-command-method))
540 ;; If the minimum article number is greater than 1, then all
541 ;; smaller article numbers are known not to exist; we'll
542 ;; artificially add those to the 'read range.
543 (let* ((active (gnus-active group))
544 (min (car active)))
545 (when (> min 1)
546 (let* ((range (if (= min 2) 1 (cons 1 (1- min))))
547 (read (gnus-info-read info))
548 (new-read (gnus-range-add read (list range))))
549 (gnus-info-set-read info new-read)))
550 info)))))
551
552 (defun gnus-request-expire-articles (articles group &optional force)
553 (let* ((gnus-command-method (gnus-find-method-for-group group))
554 (not-deleted
555 (funcall
556 (gnus-get-function gnus-command-method 'request-expire-articles)
557 articles (gnus-group-real-name group) (nth 1 gnus-command-method)
558 force)))
559 (when (and gnus-agent
560 (gnus-agent-method-p gnus-command-method))
561 (let ((expired-articles (gnus-sorted-difference articles not-deleted)))
562 (when expired-articles
563 (gnus-agent-expire expired-articles group 'force))))
564 not-deleted))
565
566 (defun gnus-request-move-article (article group server accept-function
567 &optional last)
568 (let* ((gnus-command-method (gnus-find-method-for-group group))
569 (result (funcall (gnus-get-function gnus-command-method
570 'request-move-article)
571 article (gnus-group-real-name group)
572 (nth 1 gnus-command-method) accept-function last)))
573 (when (and result gnus-agent
574 (gnus-agent-method-p gnus-command-method))
575 (gnus-agent-unfetch-articles group (list article)))
576 result))
577
578 (defun gnus-request-accept-article (group &optional gnus-command-method last
579 no-encode)
580 ;; Make sure there's a newline at the end of the article.
581 (when (stringp gnus-command-method)
582 (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
583 (when (and (not gnus-command-method)
584 (stringp group))
585 (setq gnus-command-method (or (gnus-find-method-for-group group)
586 (gnus-group-name-to-method group))))
587 (goto-char (point-max))
588 (unless (bolp)
589 (insert "\n"))
590 (unless no-encode
591 (let ((message-options message-options))
592 (message-options-set-recipient)
593 (save-restriction
594 (message-narrow-to-head)
595 (let ((mail-parse-charset message-default-charset))
596 (mail-encode-encoded-word-buffer)))
597 (message-encode-message-body)))
598 (let ((gnus-command-method (or gnus-command-method
599 (gnus-find-method-for-group group)))
600 (result
601 (funcall
602 (gnus-get-function gnus-command-method 'request-accept-article)
603 (if (stringp group) (gnus-group-real-name group) group)
604 (cadr gnus-command-method)
605 last)))
606 (when (and gnus-agent (gnus-agent-method-p gnus-command-method))
607 (gnus-agent-regenerate-group group (list (cdr result))))
608 result))
609
610 (defun gnus-request-replace-article (article group buffer &optional no-encode)
611 (unless no-encode
612 (let ((message-options message-options))
613 (message-options-set-recipient)
614 (save-restriction
615 (message-narrow-to-head)
616 (let ((mail-parse-charset message-default-charset))
617 (mail-encode-encoded-word-buffer)))
618 (message-encode-message-body)))
619 (let* ((func (car (gnus-group-name-to-method group)))
620 (result (funcall (intern (format "%s-request-replace-article" func))
621 article (gnus-group-real-name group) buffer)))
622 (when (and gnus-agent (gnus-agent-method-p gnus-command-method))
623 (gnus-agent-regenerate-group group (list article)))
624 result))
625
626 (defun gnus-request-associate-buffer (group)
627 (let ((gnus-command-method (gnus-find-method-for-group group)))
628 (funcall (gnus-get-function gnus-command-method 'request-associate-buffer)
629 (gnus-group-real-name group))))
630
631 (defun gnus-request-restore-buffer (article group)
632 "Request a new buffer restored to the state of ARTICLE."
633 (let ((gnus-command-method (gnus-find-method-for-group group)))
634 (funcall (gnus-get-function gnus-command-method 'request-restore-buffer)
635 article (gnus-group-real-name group)
636 (nth 1 gnus-command-method))))
637
638 (defun gnus-request-create-group (group &optional gnus-command-method args)
639 (when (stringp gnus-command-method)
640 (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
641 (let ((gnus-command-method
642 (or gnus-command-method (gnus-find-method-for-group group))))
643 (funcall (gnus-get-function gnus-command-method 'request-create-group)
644 (gnus-group-real-name group) (nth 1 gnus-command-method) args)))
645
646 (defun gnus-request-delete-group (group &optional force)
647 (let* ((gnus-command-method (gnus-find-method-for-group group))
648 (result
649 (funcall (gnus-get-function gnus-command-method 'request-delete-group)
650 (gnus-group-real-name group) force (nth 1 gnus-command-method))))
651 (when result
652 (gnus-cache-delete-group group)
653 (gnus-agent-delete-group group))
654 result))
655
656 (defun gnus-request-rename-group (group new-name)
657 (let* ((gnus-command-method (gnus-find-method-for-group group))
658 (result
659 (funcall (gnus-get-function gnus-command-method 'request-rename-group)
660 (gnus-group-real-name group)
661 (gnus-group-real-name new-name) (nth 1 gnus-command-method))))
662 (when result
663 (gnus-cache-rename-group group new-name)
664 (gnus-agent-rename-group group new-name))
665 result))
666
667 (defun gnus-close-backends ()
668 ;; Send a close request to all backends that support such a request.
669 (let ((methods gnus-valid-select-methods)
670 (gnus-inhibit-demon t)
671 func gnus-command-method)
672 (while (setq gnus-command-method (pop methods))
673 (when (fboundp (setq func (intern
674 (concat (car gnus-command-method)
675 "-request-close"))))
676 (funcall func)))))
677
678 (defun gnus-asynchronous-p (gnus-command-method)
679 (let ((func (gnus-get-function gnus-command-method 'asynchronous-p t)))
680 (when (fboundp func)
681 (funcall func))))
682
683 (defun gnus-remove-denial (gnus-command-method)
684 (when (stringp gnus-command-method)
685 (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
686 (let* ((elem (assoc gnus-command-method gnus-opened-servers))
687 (status (cadr elem)))
688 ;; If this hasn't been opened before, we add it to the list.
689 (when (eq status 'denied)
690 ;; Set the status of this server.
691 (setcar (cdr elem) 'closed))))
692
693 (provide 'gnus-int)
694
695 ;;; arch-tag: bbc90087-9b7f-4017-a92c-3abf180ac86d
696 ;;; gnus-int.el ends here