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