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