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