Pass lambdas to `skeleton-read'
[emacs.git] / lisp / gnus / gnus-int.el
blob4e870bb84bb9a1d1f4a268c08ea25d0925cefcaf
1 ;;; gnus-int.el --- backend interface functions for Gnus
3 ;; Copyright (C) 1996-2015 Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;; Commentary:
25 ;;; Code:
27 (eval-when-compile (require 'cl))
29 (require 'gnus)
30 (require 'message)
31 (require 'gnus-range)
33 (autoload 'gnus-run-hook-with-args "gnus-util")
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")
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)
44 (defcustom gnus-after-set-mark-hook nil
45 "Hook called just after marks are set in a group."
46 :version "24.1"
47 :group 'gnus-start
48 :type 'hook)
50 (defcustom gnus-before-update-mark-hook nil
51 "Hook called just before marks are updated in a group."
52 :version "24.1"
53 :group 'gnus-start
54 :type 'hook)
56 (defcustom gnus-server-unopen-status nil
57 "The default status if the server is not able to open.
58 If the server is covered by Gnus agent, the possible values are
59 `denied', set the server denied; `offline', set the server offline;
60 nil, ask user. If the server is not covered by Gnus agent, set the
61 server denied."
62 :version "22.1"
63 :group 'gnus-start
64 :type '(choice (const :tag "Ask" nil)
65 (const :tag "Deny server" denied)
66 (const :tag "Unplug Agent" offline)))
68 (defcustom gnus-nntp-server nil
69 "The name of the host running the NNTP server."
70 :group 'gnus-server
71 :type '(choice (const :tag "disable" nil)
72 string))
73 (make-obsolete-variable 'gnus-nntp-server 'gnus-select-method "24.1")
75 (defvar gnus-internal-registry-spool-current-method nil
76 "The current method, for the registry.")
79 (defun gnus-server-opened (gnus-command-method)
80 "Check whether a connection to GNUS-COMMAND-METHOD has been opened."
81 (unless (eq (gnus-server-status gnus-command-method)
82 'denied)
83 (when (stringp gnus-command-method)
84 (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
85 (funcall (inline (gnus-get-function gnus-command-method 'server-opened))
86 (nth 1 gnus-command-method))))
88 (defun gnus-status-message (gnus-command-method)
89 "Return the status message from GNUS-COMMAND-METHOD.
90 If GNUS-COMMAND-METHOD is a string, it is interpreted as a group
91 name. The method this group uses will be queried."
92 (let ((gnus-command-method
93 (if (stringp gnus-command-method)
94 (gnus-find-method-for-group gnus-command-method)
95 gnus-command-method)))
96 (funcall (gnus-get-function gnus-command-method 'status-message)
97 (nth 1 gnus-command-method))))
99 ;;;
100 ;;; Server Communication
103 (defun gnus-start-news-server (&optional confirm)
104 "Open a method for getting news.
105 If CONFIRM is non-nil, the user will be asked for an NNTP server."
106 (let (how)
107 (if gnus-current-select-method
108 ;; Stream is already opened.
110 ;; Open NNTP server.
111 (when confirm
112 ;; Read server name with completion.
113 (setq gnus-nntp-server
114 (gnus-completing-read "NNTP server"
115 (cons gnus-nntp-server
116 (if (boundp 'gnus-secondary-servers)
117 gnus-secondary-servers))
118 nil gnus-nntp-server)))
120 (when (and gnus-nntp-server
121 (stringp gnus-nntp-server)
122 (not (string= gnus-nntp-server "")))
123 (setq gnus-select-method
124 (cond ((or (string= gnus-nntp-server "")
125 (string= gnus-nntp-server "::"))
126 (list 'nnspool (system-name)))
127 ((string-match "^:" gnus-nntp-server)
128 (list 'nnmh gnus-nntp-server
129 (list 'nnmh-directory
130 (file-name-as-directory
131 (expand-file-name
132 (substring gnus-nntp-server 1) "~/")))
133 (list 'nnmh-get-new-mail nil)))
135 (list 'nntp gnus-nntp-server)))))
137 (setq how (car gnus-select-method))
138 (cond
139 ((eq how 'nnspool)
140 (require 'nnspool)
141 (gnus-message 5 "Looking up local news spool..."))
142 ((eq how 'nnmh)
143 (require 'nnmh)
144 (gnus-message 5 "Looking up mh spool..."))
146 (require 'nntp)))
147 (setq gnus-current-select-method gnus-select-method)
148 (gnus-run-hooks 'gnus-open-server-hook)
150 ;; Partially validate agent covered methods now that the
151 ;; gnus-select-method is known.
153 (if gnus-agent
154 ;; NOTE: This is here for one purpose only. By validating
155 ;; the current select method, it converts the old 5.10.3,
156 ;; and earlier, format to the current format. That enables
157 ;; the agent code within gnus-open-server to function
158 ;; correctly.
159 (gnus-agent-read-servers-validate-native gnus-select-method))
162 ;; gnus-open-server-hook might have opened it
163 (gnus-server-opened gnus-select-method)
164 (gnus-open-server gnus-select-method)
165 gnus-batch-mode
166 (gnus-y-or-n-p
167 (format
168 "%s (%s) open error: '%s'. Continue? "
169 (car gnus-select-method) (cadr gnus-select-method)
170 (gnus-status-message gnus-select-method)))
171 (gnus-error 1 "Couldn't open server on %s"
172 (nth 1 gnus-select-method))))))
174 (defun gnus-check-group (group)
175 "Try to make sure that the server where GROUP exists is alive."
176 (let ((method (gnus-find-method-for-group group)))
177 (or (gnus-server-opened method)
178 (gnus-open-server method))))
180 (defun gnus-check-server (&optional method silent)
181 "Check whether the connection to METHOD is down.
182 If METHOD is nil, use `gnus-select-method'.
183 If it is down, start it up (again)."
184 (let ((method (or method gnus-select-method))
185 result)
186 ;; Transform virtual server names into select methods.
187 (when (stringp method)
188 (setq method (gnus-server-to-method method)))
189 (if (gnus-server-opened method)
190 ;; The stream is already opened.
192 ;; Open the server.
193 (unless silent
194 (gnus-message 5 "Opening %s server%s..." (car method)
195 (if (equal (nth 1 method) "") ""
196 (format " on %s" (nth 1 method)))))
197 (gnus-run-hooks 'gnus-open-server-hook)
198 (prog1
199 (setq result (gnus-open-server method))
200 (unless silent
201 (gnus-message
202 (if result 5 3)
203 "Opening %s server%s...%s" (car method)
204 (if (equal (nth 1 method) "") ""
205 (format " on %s" (nth 1 method)))
206 (if result
207 "done"
208 (format "failed: %s"
209 (nnheader-get-report-string (car method))))))))))
211 (defun gnus-get-function (method function &optional noerror)
212 "Return a function symbol based on METHOD and FUNCTION."
213 ;; Translate server names into methods.
214 (unless method
215 (error "Attempted use of a nil select method"))
216 (when (stringp method)
217 (setq method (gnus-server-to-method method)))
218 ;; Check cache of constructed names.
219 (let* ((method-sym (if gnus-agent
220 (inline (gnus-agent-get-function method))
221 (car method)))
222 (method-fns (get method-sym 'gnus-method-functions))
223 (func (let ((method-fnlist-elt (assq function method-fns)))
224 (unless method-fnlist-elt
225 (setq method-fnlist-elt
226 (cons function
227 (intern (format "%s-%s" method-sym function))))
228 (put method-sym 'gnus-method-functions
229 (cons method-fnlist-elt method-fns)))
230 (cdr method-fnlist-elt))))
231 ;; Maybe complain if there is no function.
232 (unless (fboundp func)
233 (unless (car method)
234 (error "Trying to require a method that doesn't exist"))
235 (require (car method))
236 (when (not (fboundp func))
237 (if noerror
238 (setq func nil)
239 (error "No such function: %s" func))))
240 func))
244 ;;; Interface functions to the backends.
247 (defun gnus-method-denied-p (method)
248 (eq (nth 1 (assoc method gnus-opened-servers))
249 'denied))
251 (defvar gnus-backend-trace nil)
252 (defvar gnus-backend-trace-elapsed nil)
254 (defun gnus-backend-trace (type form)
255 (when gnus-backend-trace
256 (with-current-buffer (get-buffer-create "*gnus trace*")
257 (buffer-disable-undo)
258 (goto-char (point-max))
259 (insert (format-time-string "%H:%M:%S")
260 (format " %.2fs %s %S\n"
261 (if (numberp gnus-backend-trace-elapsed)
262 (- (float-time) gnus-backend-trace-elapsed)
264 type form))
265 (setq gnus-backend-trace-elapsed (float-time)))))
267 (defun gnus-open-server (gnus-command-method)
268 "Open a connection to GNUS-COMMAND-METHOD."
269 (when (stringp gnus-command-method)
270 (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
271 (gnus-backend-trace :opening gnus-command-method)
272 (let ((elem (assoc gnus-command-method gnus-opened-servers))
273 (server (gnus-method-to-server-name gnus-command-method)))
274 ;; If this method was previously denied, we just return nil.
275 (if (eq (nth 1 elem) 'denied)
276 (progn
277 (gnus-message
278 1 "Server %s previously determined to be down; not retrying" server)
279 nil)
280 ;; Open the server.
281 (let* ((open-server-function
282 (gnus-get-function gnus-command-method 'open-server))
283 (result
284 (condition-case err
285 (funcall open-server-function
286 (nth 1 gnus-command-method)
287 (nthcdr 2 gnus-command-method))
288 (error
289 (gnus-message 1 "Unable to open server %s due to: %s"
290 server (error-message-string err))
291 nil)
292 (quit
293 (if debug-on-quit
294 (debug "Quit")
295 (gnus-message 1 "Quit trying to open server %s" server))
296 nil)))
297 open-offline)
298 ;; If this hasn't been opened before, we add it to the list.
299 (unless elem
300 (setq elem (list gnus-command-method nil)
301 gnus-opened-servers (cons elem gnus-opened-servers)))
302 ;; Set the status of this server.
303 (setcar
304 (cdr elem)
305 (cond (result
306 (if (eq open-server-function 'nnagent-open-server)
307 ;; The agent's backend has a "special" status
308 'offline
309 'ok))
310 ((and gnus-agent
311 (gnus-agent-method-p gnus-command-method))
312 (cond
313 (gnus-server-unopen-status
314 ;; Set the server's status to the unopen
315 ;; status. If that status is offline,
316 ;; recurse to open the agent's backend.
317 (setq open-offline (eq gnus-server-unopen-status 'offline))
318 gnus-server-unopen-status)
319 ((not gnus-batch-mode)
320 (setq open-offline t)
321 'offline)
323 ;; This agentized server was still denied
324 'denied)))
326 ;; This unagentized server must be denied
327 'denied)))
329 ;; NOTE: I MUST set the server's status to offline before this
330 ;; recursive call as this status will drive the
331 ;; gnus-get-function (called above) to return the agent's
332 ;; backend.
333 (if open-offline
334 ;; Recursively open this offline server to perform the
335 ;; open-server function of the agent's backend.
336 (let ((gnus-server-unopen-status 'denied))
337 ;; Bind gnus-server-unopen-status to avoid recursively
338 ;; prompting with "go offline?". This is only a concern
339 ;; when the agent's backend fails to open the server.
340 (gnus-open-server gnus-command-method))
341 (when (and (eq (cadr elem) 'ok) gnus-agent
342 (gnus-agent-method-p gnus-command-method))
343 (save-excursion
344 (gnus-agent-possibly-synchronize-flags-server
345 gnus-command-method)))
346 (gnus-backend-trace :opened gnus-command-method)
347 result)))))
349 (defun gnus-close-server (gnus-command-method)
350 "Close the connection to GNUS-COMMAND-METHOD."
351 (when (stringp gnus-command-method)
352 (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
353 (funcall (gnus-get-function gnus-command-method 'close-server)
354 (nth 1 gnus-command-method)))
356 (defun gnus-request-list (gnus-command-method)
357 "Request the active 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)
361 (nth 1 gnus-command-method)))
363 (defun gnus-finish-retrieve-group-infos (gnus-command-method infos data)
364 "Read and update infos from GNUS-COMMAND-METHOD."
365 (when (stringp gnus-command-method)
366 (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
367 (gnus-backend-trace :finishing gnus-command-method)
368 (prog1
369 (funcall (gnus-get-function gnus-command-method
370 'finish-retrieve-group-infos)
371 (nth 1 gnus-command-method)
372 infos data)
373 (gnus-backend-trace :finished gnus-command-method)))
375 (defun gnus-retrieve-group-data-early (gnus-command-method infos)
376 "Start early async retrieval of data from GNUS-COMMAND-METHOD."
377 (when (stringp gnus-command-method)
378 (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
379 (funcall (gnus-get-function gnus-command-method 'retrieve-group-data-early)
380 (nth 1 gnus-command-method)
381 infos))
383 (defun gnus-request-list-newsgroups (gnus-command-method)
384 "Request the newsgroups file from GNUS-COMMAND-METHOD."
385 (when (stringp gnus-command-method)
386 (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
387 (funcall (gnus-get-function gnus-command-method 'request-list-newsgroups)
388 (nth 1 gnus-command-method)))
390 (defun gnus-request-newgroups (date gnus-command-method)
391 "Request all new groups since DATE from GNUS-COMMAND-METHOD."
392 (when (stringp gnus-command-method)
393 (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
394 (let ((func (gnus-get-function gnus-command-method 'request-newgroups t)))
395 (when func
396 (funcall func date (nth 1 gnus-command-method)))))
398 (defun gnus-request-regenerate (gnus-command-method)
399 "Request a data generation from GNUS-COMMAND-METHOD."
400 (when (stringp gnus-command-method)
401 (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
402 (funcall (gnus-get-function gnus-command-method 'request-regenerate)
403 (nth 1 gnus-command-method)))
405 (defun gnus-request-compact-group (group)
406 (let* ((method (gnus-find-method-for-group group))
407 (gnus-command-method method)
408 (result
409 (funcall (gnus-get-function gnus-command-method
410 'request-compact-group)
411 (gnus-group-real-name group)
412 (nth 1 gnus-command-method) t)))
413 result))
415 (defun gnus-request-compact (gnus-command-method)
416 "Request groups compaction from GNUS-COMMAND-METHOD."
417 (when (stringp gnus-command-method)
418 (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
419 (funcall (gnus-get-function gnus-command-method 'request-compact)
420 (nth 1 gnus-command-method)))
422 (defun gnus-request-group (group &optional dont-check gnus-command-method info)
423 "Request GROUP. If DONT-CHECK, no information is required."
424 (let ((gnus-command-method
425 (or gnus-command-method (inline (gnus-find-method-for-group group)))))
426 (when (stringp gnus-command-method)
427 (setq gnus-command-method
428 (inline (gnus-server-to-method gnus-command-method))))
429 (funcall (inline (gnus-get-function gnus-command-method 'request-group))
430 (gnus-group-real-name group) (nth 1 gnus-command-method)
431 dont-check
432 info)))
434 (defun gnus-request-group-description (group)
435 "Request a description of GROUP."
436 (let ((gnus-command-method (gnus-find-method-for-group group))
437 (func 'request-group-description))
438 (when (gnus-check-backend-function func group)
439 (funcall (gnus-get-function gnus-command-method func)
440 (gnus-group-real-name group) (nth 1 gnus-command-method)))))
442 (defun gnus-request-group-scan (group info)
443 "Request that GROUP get a complete rescan."
444 (let ((gnus-command-method (gnus-find-method-for-group group))
445 (func 'request-group-scan))
446 (when (gnus-check-backend-function func group)
447 (funcall (gnus-get-function gnus-command-method func)
448 (gnus-group-real-name group) (nth 1 gnus-command-method) info))))
450 (defun gnus-close-group (group)
451 "Request the GROUP be closed."
452 (let ((gnus-command-method (inline (gnus-find-method-for-group group))))
453 (funcall (gnus-get-function gnus-command-method 'close-group)
454 (gnus-group-real-name group) (nth 1 gnus-command-method))))
456 (defun gnus-retrieve-headers (articles group &optional fetch-old)
457 "Request headers for ARTICLES in GROUP.
458 If FETCH-OLD, retrieve all headers (or some subset thereof) in the group."
459 (let ((gnus-command-method (gnus-find-method-for-group group)))
460 (cond
461 ((and gnus-use-cache (numberp (car articles)))
462 (gnus-cache-retrieve-headers articles group fetch-old))
463 ((and gnus-agent (gnus-online gnus-command-method)
464 (gnus-agent-method-p gnus-command-method))
465 (gnus-agent-retrieve-headers articles group fetch-old))
467 (funcall (gnus-get-function gnus-command-method 'retrieve-headers)
468 articles (gnus-group-real-name group)
469 (nth 1 gnus-command-method) fetch-old)))))
471 (defun gnus-retrieve-articles (articles group)
472 "Request ARTICLES in GROUP."
473 (let ((gnus-command-method (gnus-find-method-for-group group)))
474 (funcall (gnus-get-function gnus-command-method 'retrieve-articles)
475 articles (gnus-group-real-name group)
476 (nth 1 gnus-command-method))))
478 (defun gnus-retrieve-groups (groups gnus-command-method)
479 "Request active information on GROUPS from GNUS-COMMAND-METHOD."
480 (when (stringp gnus-command-method)
481 (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
482 (funcall (gnus-get-function gnus-command-method 'retrieve-groups)
483 groups (nth 1 gnus-command-method)))
485 (defun gnus-request-type (group &optional article)
486 "Return the type (`post' or `mail') of GROUP (and ARTICLE)."
487 (let ((gnus-command-method (gnus-find-method-for-group group)))
488 (if (not (gnus-check-backend-function
489 'request-type (car gnus-command-method)))
490 'unknown
491 (funcall (gnus-get-function gnus-command-method 'request-type)
492 (gnus-group-real-name group) article))))
494 (defun gnus-request-update-group-status (group status)
495 "Change the status of a group.
496 Valid statuses include `subscribe' and `unsubscribe'."
497 (let ((gnus-command-method (gnus-find-method-for-group group)))
498 (if (not (gnus-check-backend-function
499 'request-update-group-status (car gnus-command-method)))
501 (funcall
502 (gnus-get-function gnus-command-method 'request-update-group-status)
503 (gnus-group-real-name group) status
504 (nth 1 gnus-command-method)))))
506 (defun gnus-request-set-mark (group action)
507 "Set marks on articles in the back end."
508 (let ((gnus-command-method (gnus-find-method-for-group group)))
509 (if (not (gnus-check-backend-function
510 'request-set-mark (car gnus-command-method)))
511 action
512 (funcall (gnus-get-function gnus-command-method 'request-set-mark)
513 (gnus-group-real-name group) action
514 (nth 1 gnus-command-method))
515 (gnus-run-hook-with-args gnus-after-set-mark-hook group action))))
517 (defun gnus-request-update-mark (group article mark)
518 "Allow the back end to change the mark the user tries to put on an article."
519 (let ((gnus-command-method (gnus-find-method-for-group group)))
520 (if (not (gnus-check-backend-function
521 'request-update-mark (car gnus-command-method)))
522 mark
523 (gnus-run-hook-with-args gnus-before-update-mark-hook group article mark)
524 (funcall (gnus-get-function gnus-command-method 'request-update-mark)
525 (gnus-group-real-name group) article mark))))
527 (defun gnus-request-article (article group &optional buffer)
528 "Request the ARTICLE in GROUP.
529 ARTICLE can either be an article number or an article Message-ID.
530 If BUFFER, insert the article in that group."
531 (let ((gnus-command-method (gnus-find-method-for-group group)))
532 (funcall (gnus-get-function gnus-command-method 'request-article)
533 article (gnus-group-real-name group)
534 (nth 1 gnus-command-method) buffer)))
536 (defun gnus-request-thread (header group)
537 "Request the headers in the thread containing the article specified by HEADER."
538 (let ((gnus-command-method (gnus-find-method-for-group group)))
539 (funcall (gnus-get-function gnus-command-method 'request-thread)
540 header
541 (gnus-group-real-name group))))
543 (defun gnus-select-group-with-message-id (group message-id)
544 "Activate and select GROUP with the given MESSAGE-ID selected.
545 Returns the article number of the message.
547 If GROUP is not already selected, the message will be the only one in
548 the group's summary.
550 ;; TODO: is there a way to know at this point whether the group will
551 ;; be newly-selected? If so we could clean up the logic at the end
553 ;; save the new group's display parameter, if any, so we
554 ;; can replace it temporarily with zero.
555 (let ((saved-display
556 (gnus-group-get-parameter group 'display :allow-list)))
558 ;; Tell gnus we really don't want any articles
559 (gnus-group-set-parameter group 'display 0)
561 (unwind-protect
562 (gnus-summary-read-group-1
563 group (not :show-all) :no-article (not :kill-buffer)
564 ;; The combination of no-display and this dummy list of
565 ;; articles to select somehow makes it possible to open a
566 ;; group with no articles in it. Black magic.
567 :no-display '(-1); select-articles
569 ;; Restore the new group's display parameter
570 (gnus-group-set-parameter group 'display saved-display)))
572 ;; The summary buffer was suppressed by :no-display above.
573 ;; Create it now and insert the message
574 (let ((group-is-new (gnus-summary-setup-buffer group)))
575 (condition-case err
576 (let ((article-number
577 (gnus-summary-insert-subject message-id)))
578 (unless article-number
579 (signal 'error "message-id not in group"))
580 (gnus-summary-select-article nil nil nil article-number)
581 article-number)
582 ;; Clean up the new summary and propagate the error
583 (error (when group-is-new (gnus-summary-exit))
584 (apply 'signal err)))))
586 (defun gnus-simplify-group-name (group)
587 "Return the simplest representation of the name of GROUP.
588 This is the string that Gnus uses to identify the group."
589 (gnus-group-prefixed-name
590 (gnus-group-real-name group)
591 (gnus-group-method group)))
593 (defun gnus-warp-to-article ()
594 "Look up the current article in the group where it originated.
595 This command only makes sense for groups shows articles gathered
596 from other groups -- for instance, search results and the like."
597 (interactive)
598 (let ((gnus-command-method
599 (gnus-find-method-for-group gnus-newsgroup-name)))
601 (when (gnus-check-backend-function
602 'warp-to-article (car gnus-command-method))
603 (funcall (gnus-get-function gnus-command-method 'warp-to-article)))
604 (and (bound-and-true-p gnus-registry-enabled)
605 (gnus-try-warping-via-registry)))))
607 (defun gnus-request-head (article group)
608 "Request the head of ARTICLE in GROUP."
609 (let* ((gnus-command-method (gnus-find-method-for-group group))
610 (head (gnus-get-function gnus-command-method 'request-head t))
611 res clean-up)
612 (cond
613 ;; Check the cache.
614 ((and gnus-use-cache
615 (numberp article)
616 (gnus-cache-request-article article group))
617 (setq res (cons group article)
618 clean-up t))
619 ;; Check the agent cache.
620 ((gnus-agent-request-article article group)
621 (setq res (cons group article)
622 clean-up t))
623 ;; Use `head' function.
624 ((fboundp head)
625 (setq res (funcall head article
626 (and (not gnus-override-method) (gnus-group-real-name group))
627 (nth 1 gnus-command-method))))
628 ;; Use `article' function.
630 (setq res (gnus-request-article article group)
631 clean-up t)))
632 (when clean-up
633 (with-current-buffer nntp-server-buffer
634 (goto-char (point-min))
635 (when (search-forward "\n\n" nil t)
636 (delete-region (1- (point)) (point-max)))
637 (nnheader-fold-continuation-lines)))
638 res))
640 (defun gnus-request-body (article group)
641 "Request the body of ARTICLE in GROUP."
642 (let* ((gnus-command-method (gnus-find-method-for-group group))
643 (head (gnus-get-function gnus-command-method 'request-body t))
644 res clean-up)
645 (cond
646 ;; Check the cache.
647 ((and gnus-use-cache
648 (numberp article)
649 (gnus-cache-request-article article group))
650 (setq res (cons group article)
651 clean-up t))
652 ;; Check the agent cache.
653 ((gnus-agent-request-article article group)
654 (setq res (cons group article)
655 clean-up t))
656 ;; Use `head' function.
657 ((fboundp head)
658 (setq res (funcall head article (gnus-group-real-name group)
659 (nth 1 gnus-command-method))))
660 ;; Use `article' function.
662 (setq res (gnus-request-article article group)
663 clean-up t)))
664 (when clean-up
665 (with-current-buffer nntp-server-buffer
666 (goto-char (point-min))
667 (when (search-forward "\n\n" nil t)
668 (delete-region (point-min) (1- (point))))))
669 res))
671 (defun gnus-request-post (gnus-command-method)
672 "Post the current buffer using GNUS-COMMAND-METHOD."
673 (when (stringp gnus-command-method)
674 (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
675 (funcall (gnus-get-function gnus-command-method 'request-post)
676 (nth 1 gnus-command-method)))
678 (defun gnus-request-expunge-group (group gnus-command-method)
679 "Expunge GROUP, which is removing articles that have been marked as deleted."
680 (when (stringp gnus-command-method)
681 (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
682 (funcall (gnus-get-function gnus-command-method 'request-expunge-group)
683 (gnus-group-real-name group)
684 (nth 1 gnus-command-method)))
686 (defun gnus-request-scan (group gnus-command-method)
687 "Request a SCAN being performed in GROUP from GNUS-COMMAND-METHOD.
688 If GROUP is nil, all groups on GNUS-COMMAND-METHOD are scanned."
689 (let ((gnus-command-method
690 (if group (gnus-find-method-for-group group) gnus-command-method))
691 (gnus-inhibit-demon t)
692 (mail-source-plugged gnus-plugged))
693 (when (or gnus-plugged
694 (not (gnus-agent-method-p gnus-command-method)))
695 (setq gnus-internal-registry-spool-current-method gnus-command-method)
696 (funcall (gnus-get-function gnus-command-method 'request-scan)
697 (and group (gnus-group-real-name group))
698 (nth 1 gnus-command-method)))))
700 (defun gnus-request-update-info (info gnus-command-method)
701 (when (gnus-check-backend-function
702 'request-update-info (car gnus-command-method))
703 (when (stringp gnus-command-method)
704 (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
705 (funcall (gnus-get-function gnus-command-method 'request-update-info)
706 (gnus-group-real-name (gnus-info-group info)) info
707 (nth 1 gnus-command-method))))
709 (defsubst gnus-request-marks (info gnus-command-method)
710 "Request that GNUS-COMMAND-METHOD update INFO."
711 (when (stringp gnus-command-method)
712 (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
713 (when (gnus-check-backend-function
714 'request-marks (car gnus-command-method))
715 (let ((group (gnus-info-group info)))
716 (and (funcall (gnus-get-function gnus-command-method 'request-marks)
717 (gnus-group-real-name group)
718 info (nth 1 gnus-command-method))
719 ;; If the minimum article number is greater than 1, then all
720 ;; smaller article numbers are known not to exist; we'll
721 ;; artificially add those to the 'read range.
722 (let* ((active (gnus-active group))
723 (min (car active)))
724 (when (> min 1)
725 (let* ((range (if (= min 2) 1 (cons 1 (1- min))))
726 (read (gnus-info-read info))
727 (new-read (gnus-range-add read (list range))))
728 (gnus-info-set-read info new-read)))
729 info)))))
731 (defun gnus-request-expire-articles (articles group &optional force)
732 (let* ((gnus-command-method (gnus-find-method-for-group group))
733 ;; Filter out any negative article numbers; they can't be
734 ;; expired here.
735 (articles
736 (delq nil (mapcar (lambda (n) (and (>= n 0) n)) articles)))
737 (gnus-inhibit-demon t)
738 (not-deleted
739 (funcall
740 (gnus-get-function gnus-command-method 'request-expire-articles)
741 articles (gnus-group-real-name group) (nth 1 gnus-command-method)
742 force)))
743 (when (and gnus-agent
744 (gnus-agent-method-p gnus-command-method))
745 (let ((expired-articles (gnus-sorted-difference articles not-deleted)))
746 (when expired-articles
747 (gnus-agent-expire expired-articles group 'force))))
748 not-deleted))
750 (defun gnus-request-move-article (article group server accept-function
751 &optional last move-is-internal)
752 (let* ((gnus-command-method (gnus-find-method-for-group group))
753 (result (funcall (gnus-get-function gnus-command-method
754 'request-move-article)
755 article (gnus-group-real-name group)
756 (nth 1 gnus-command-method) accept-function
757 last move-is-internal)))
758 (when (and result gnus-agent
759 (gnus-agent-method-p gnus-command-method))
760 (gnus-agent-unfetch-articles group (list article)))
761 result))
763 (defun gnus-request-accept-article (group &optional gnus-command-method last
764 no-encode)
765 (when (stringp gnus-command-method)
766 (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
767 (when (and (not gnus-command-method)
768 (stringp group))
769 (setq gnus-command-method (or (gnus-find-method-for-group group)
770 (gnus-group-name-to-method group))))
771 (goto-char (point-max))
772 ;; Make sure there's a newline at the end of the article.
773 (unless (bolp)
774 (insert "\n"))
775 (unless no-encode
776 (let ((message-options message-options))
777 (message-options-set-recipient)
778 (save-restriction
779 (message-narrow-to-head)
780 (let ((mail-parse-charset message-default-charset))
781 (mail-encode-encoded-word-buffer)))
782 (message-encode-message-body)))
783 (let ((gnus-command-method (or gnus-command-method
784 (gnus-find-method-for-group group)))
785 (result
786 (funcall
787 (gnus-get-function gnus-command-method 'request-accept-article)
788 (if (stringp group) (gnus-group-real-name group) group)
789 (cadr gnus-command-method)
790 last)))
791 (when (and gnus-agent
792 (gnus-agent-method-p gnus-command-method)
793 (cdr result))
794 (gnus-agent-regenerate-group group (list (cdr result))))
795 result))
797 (defun gnus-request-replace-article (article group buffer &optional no-encode)
798 (unless no-encode
799 (let ((message-options message-options))
800 (message-options-set-recipient)
801 (save-restriction
802 (message-narrow-to-head)
803 (let ((mail-parse-charset message-default-charset))
804 (mail-encode-encoded-word-buffer)))
805 (message-encode-message-body)))
806 (let* ((func (car (gnus-group-name-to-method group)))
807 (result (funcall (intern (format "%s-request-replace-article" func))
808 article (gnus-group-real-name group) buffer)))
809 (when (and gnus-agent (gnus-agent-method-p gnus-command-method))
810 (gnus-agent-regenerate-group group (list article)))
811 result))
813 (defun gnus-request-restore-buffer (article group)
814 "Request a new buffer restored to the state of ARTICLE."
815 (let ((gnus-command-method (gnus-find-method-for-group group)))
816 (funcall (gnus-get-function gnus-command-method 'request-restore-buffer)
817 article (gnus-group-real-name group)
818 (nth 1 gnus-command-method))))
820 (defun gnus-request-create-group (group &optional gnus-command-method args)
821 (when (stringp gnus-command-method)
822 (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
823 (let ((gnus-command-method
824 (or gnus-command-method (gnus-find-method-for-group group))))
825 (funcall (gnus-get-function gnus-command-method 'request-create-group)
826 (gnus-group-real-name group) (nth 1 gnus-command-method) args)))
828 (defun gnus-request-delete-group (group &optional force)
829 (let* ((gnus-command-method (gnus-find-method-for-group group))
830 (result
831 (funcall (gnus-get-function gnus-command-method 'request-delete-group)
832 (gnus-group-real-name group) force (nth 1 gnus-command-method))))
833 (when result
834 (gnus-cache-delete-group group)
835 (gnus-agent-delete-group group))
836 result))
838 (defun gnus-request-rename-group (group new-name)
839 (let* ((gnus-command-method (gnus-find-method-for-group group))
840 (result
841 (funcall (gnus-get-function gnus-command-method 'request-rename-group)
842 (gnus-group-real-name group)
843 (gnus-group-real-name new-name) (nth 1 gnus-command-method))))
844 (when result
845 (gnus-cache-rename-group group new-name)
846 (gnus-agent-rename-group group new-name))
847 result))
849 (defun gnus-close-backends ()
850 ;; Send a close request to all backends that support such a request.
851 (let ((methods gnus-valid-select-methods)
852 (gnus-inhibit-demon t)
853 func gnus-command-method)
854 (while (setq gnus-command-method (pop methods))
855 (when (fboundp (setq func (intern
856 (concat (car gnus-command-method)
857 "-request-close"))))
858 (funcall func)))))
860 (defun gnus-asynchronous-p (gnus-command-method)
861 (let ((func (gnus-get-function gnus-command-method 'asynchronous-p t)))
862 (when (fboundp func)
863 (funcall func))))
865 (defun gnus-remove-denial (gnus-command-method)
866 (when (stringp gnus-command-method)
867 (setq gnus-command-method (gnus-server-to-method gnus-command-method)))
868 (let* ((elem (assoc gnus-command-method gnus-opened-servers))
869 (status (cadr elem)))
870 ;; If this hasn't been opened before, we add it to the list.
871 (when (eq status 'denied)
872 ;; Set the status of this server.
873 (setcar (cdr elem) 'closed))))
875 (provide 'gnus-int)
877 ;;; gnus-int.el ends here