1 ;;; gnus-int.el --- backend interface functions for Gnus
3 ;; Copyright (C) 1996-2012 Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
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/>.
27 (eval-when-compile (require 'cl
))
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."
44 (defcustom gnus-after-set-mark-hook nil
45 "Hook called just after marks are set in a group."
50 (defcustom gnus-before-update-mark-hook nil
51 "Hook called just before marks are updated in a group."
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
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."
71 :type
'(choice (const :tag
"disable" nil
)
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
)
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
))))
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."
107 (if gnus-current-select-method
108 ;; Stream is already opened.
112 ;; Read server name with completion.
113 (setq gnus-nntp-server
114 (gnus-completing-read "NNTP server"
115 (cons gnus-nntp-server
116 gnus-secondary-servers
)
117 nil gnus-nntp-server
)))
119 (when (and gnus-nntp-server
120 (stringp gnus-nntp-server
)
121 (not (string= gnus-nntp-server
"")))
122 (setq gnus-select-method
123 (cond ((or (string= gnus-nntp-server
"")
124 (string= gnus-nntp-server
"::"))
125 (list 'nnspool
(system-name)))
126 ((string-match "^:" gnus-nntp-server
)
127 (list 'nnmh gnus-nntp-server
128 (list 'nnmh-directory
129 (file-name-as-directory
131 (substring gnus-nntp-server
1) "~/")))
132 (list 'nnmh-get-new-mail nil
)))
134 (list 'nntp gnus-nntp-server
)))))
136 (setq how
(car gnus-select-method
))
140 (gnus-message 5 "Looking up local news spool..."))
143 (gnus-message 5 "Looking up mh spool..."))
146 (setq gnus-current-select-method gnus-select-method
)
147 (gnus-run-hooks 'gnus-open-server-hook
)
149 ;; Partially validate agent covered methods now that the
150 ;; gnus-select-method is known.
153 ;; NOTE: This is here for one purpose only. By validating
154 ;; the current select method, it converts the old 5.10.3,
155 ;; and earlier, format to the current format. That enables
156 ;; the agent code within gnus-open-server to function
158 (gnus-agent-read-servers-validate-native gnus-select-method
))
161 ;; gnus-open-server-hook might have opened it
162 (gnus-server-opened gnus-select-method
)
163 (gnus-open-server gnus-select-method
)
167 "%s (%s) open error: '%s'. Continue? "
168 (car gnus-select-method
) (cadr gnus-select-method
)
169 (gnus-status-message gnus-select-method
)))
170 (gnus-error 1 "Couldn't open server on %s"
171 (nth 1 gnus-select-method
))))))
173 (defun gnus-check-group (group)
174 "Try to make sure that the server where GROUP exists is alive."
175 (let ((method (gnus-find-method-for-group group
)))
176 (or (gnus-server-opened method
)
177 (gnus-open-server method
))))
179 (defun gnus-check-server (&optional method silent
)
180 "Check whether the connection to METHOD is down.
181 If METHOD is nil, use `gnus-select-method'.
182 If it is down, start it up (again)."
183 (let ((method (or method gnus-select-method
))
185 ;; Transform virtual server names into select methods.
186 (when (stringp method
)
187 (setq method
(gnus-server-to-method method
)))
188 (if (gnus-server-opened method
)
189 ;; The stream is already opened.
193 (gnus-message 5 "Opening %s server%s..." (car method
)
194 (if (equal (nth 1 method
) "") ""
195 (format " on %s" (nth 1 method
)))))
196 (gnus-run-hooks 'gnus-open-server-hook
)
198 (setq result
(gnus-open-server method
))
202 "Opening %s server%s...%s" (car method
)
203 (if (equal (nth 1 method
) "") ""
204 (format " on %s" (nth 1 method
)))
208 (nnheader-get-report-string (car method
))))))))))
210 (defun gnus-get-function (method function
&optional noerror
)
211 "Return a function symbol based on METHOD and FUNCTION."
212 ;; Translate server names into methods.
214 (error "Attempted use of a nil select method"))
215 (when (stringp method
)
216 (setq method
(gnus-server-to-method method
)))
217 ;; Check cache of constructed names.
218 (let* ((method-sym (if gnus-agent
219 (inline (gnus-agent-get-function method
))
221 (method-fns (get method-sym
'gnus-method-functions
))
222 (func (let ((method-fnlist-elt (assq function method-fns
)))
223 (unless method-fnlist-elt
224 (setq method-fnlist-elt
226 (intern (format "%s-%s" method-sym function
))))
227 (put method-sym
'gnus-method-functions
228 (cons method-fnlist-elt method-fns
)))
229 (cdr method-fnlist-elt
))))
230 ;; Maybe complain if there is no function.
231 (unless (fboundp func
)
233 (error "Trying to require a method that doesn't exist"))
234 (require (car method
))
235 (when (not (fboundp func
))
238 (error "No such function: %s" func
))))
243 ;;; Interface functions to the backends.
246 (defun gnus-method-denied-p (method)
247 (eq (nth 1 (assoc method gnus-opened-servers
))
250 (defvar gnus-backend-trace nil
)
252 (defun gnus-open-server (gnus-command-method)
253 "Open a connection to GNUS-COMMAND-METHOD."
254 (when (stringp gnus-command-method
)
255 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
256 (when gnus-backend-trace
257 (with-current-buffer (get-buffer-create "*gnus trace*")
258 (buffer-disable-undo)
259 (goto-char (point-max))
260 (insert (format-time-string "%H:%M:%S")
261 (format " %S\n" gnus-command-method
))))
262 (let ((elem (assoc gnus-command-method gnus-opened-servers
))
263 (server (gnus-method-to-server-name gnus-command-method
)))
264 ;; If this method was previously denied, we just return nil.
265 (if (eq (nth 1 elem
) 'denied
)
268 1 "Server %s previously determined to be down; not retrying" server
)
271 (let* ((open-server-function
272 (gnus-get-function gnus-command-method
'open-server
))
275 (funcall open-server-function
276 (nth 1 gnus-command-method
)
277 (nthcdr 2 gnus-command-method
))
279 (gnus-message 1 "Unable to open server %s due to: %s"
280 server
(error-message-string err
))
285 (gnus-message 1 "Quit trying to open server %s" server
))
288 ;; If this hasn't been opened before, we add it to the list.
290 (setq elem
(list gnus-command-method nil
)
291 gnus-opened-servers
(cons elem gnus-opened-servers
)))
292 ;; Set the status of this server.
296 (if (eq open-server-function
#'nnagent-open-server
)
297 ;; The agent's backend has a "special" status
301 (gnus-agent-method-p gnus-command-method
))
303 (gnus-server-unopen-status
304 ;; Set the server's status to the unopen
305 ;; status. If that status is offline,
306 ;; recurse to open the agent's backend.
307 (setq open-offline
(eq gnus-server-unopen-status
'offline
))
308 gnus-server-unopen-status
)
309 ((not gnus-batch-mode
)
310 (setq open-offline t
)
313 ;; This agentized server was still denied
316 ;; This unagentized server must be denied
319 ;; NOTE: I MUST set the server's status to offline before this
320 ;; recursive call as this status will drive the
321 ;; gnus-get-function (called above) to return the agent's
324 ;; Recursively open this offline server to perform the
325 ;; open-server function of the agent's backend.
326 (let ((gnus-server-unopen-status 'denied
))
327 ;; Bind gnus-server-unopen-status to avoid recursively
328 ;; prompting with "go offline?". This is only a concern
329 ;; when the agent's backend fails to open the server.
330 (gnus-open-server gnus-command-method
))
331 (when (and (eq (cadr elem
) 'ok
) gnus-agent
332 (gnus-agent-method-p gnus-command-method
))
334 (gnus-agent-possibly-synchronize-flags-server
335 gnus-command-method
)))
338 (defun gnus-close-server (gnus-command-method)
339 "Close the connection to GNUS-COMMAND-METHOD."
340 (when (stringp gnus-command-method
)
341 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
342 (funcall (gnus-get-function gnus-command-method
'close-server
)
343 (nth 1 gnus-command-method
)))
345 (defun gnus-request-list (gnus-command-method)
346 "Request the active file from GNUS-COMMAND-METHOD."
347 (when (stringp gnus-command-method
)
348 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
349 (funcall (gnus-get-function gnus-command-method
'request-list
)
350 (nth 1 gnus-command-method
)))
352 (defun gnus-finish-retrieve-group-infos (gnus-command-method infos data
)
353 "Read and update infos from GNUS-COMMAND-METHOD."
354 (when (stringp gnus-command-method
)
355 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
356 (funcall (gnus-get-function gnus-command-method
'finish-retrieve-group-infos
)
357 (nth 1 gnus-command-method
)
360 (defun gnus-retrieve-group-data-early (gnus-command-method infos
)
361 "Start early async retrieval of data from GNUS-COMMAND-METHOD."
362 (when (stringp gnus-command-method
)
363 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
364 (funcall (gnus-get-function gnus-command-method
'retrieve-group-data-early
)
365 (nth 1 gnus-command-method
)
368 (defun gnus-request-list-newsgroups (gnus-command-method)
369 "Request the newsgroups file from GNUS-COMMAND-METHOD."
370 (when (stringp gnus-command-method
)
371 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
372 (funcall (gnus-get-function gnus-command-method
'request-list-newsgroups
)
373 (nth 1 gnus-command-method
)))
375 (defun gnus-request-newgroups (date gnus-command-method
)
376 "Request all new groups since DATE from GNUS-COMMAND-METHOD."
377 (when (stringp gnus-command-method
)
378 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
379 (let ((func (gnus-get-function gnus-command-method
'request-newgroups t
)))
381 (funcall func date
(nth 1 gnus-command-method
)))))
383 (defun gnus-request-regenerate (gnus-command-method)
384 "Request a data generation 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-regenerate
)
388 (nth 1 gnus-command-method
)))
390 (defun gnus-request-compact-group (group)
391 (let* ((method (gnus-find-method-for-group group
))
392 (gnus-command-method method
)
394 (funcall (gnus-get-function gnus-command-method
395 'request-compact-group
)
396 (gnus-group-real-name group
)
397 (nth 1 gnus-command-method
) t
)))
400 (defun gnus-request-compact (gnus-command-method)
401 "Request groups compaction from GNUS-COMMAND-METHOD."
402 (when (stringp gnus-command-method
)
403 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
404 (funcall (gnus-get-function gnus-command-method
'request-compact
)
405 (nth 1 gnus-command-method
)))
407 (defun gnus-request-group (group &optional dont-check gnus-command-method info
)
408 "Request GROUP. If DONT-CHECK, no information is required."
409 (let ((gnus-command-method
410 (or gnus-command-method
(inline (gnus-find-method-for-group group
)))))
411 (when (stringp gnus-command-method
)
412 (setq gnus-command-method
413 (inline (gnus-server-to-method gnus-command-method
))))
414 (funcall (inline (gnus-get-function gnus-command-method
'request-group
))
415 (gnus-group-real-name group
) (nth 1 gnus-command-method
)
419 (defun gnus-request-group-description (group)
420 "Request a description of GROUP."
421 (let ((gnus-command-method (gnus-find-method-for-group group
))
422 (func 'request-group-description
))
423 (when (gnus-check-backend-function func group
)
424 (funcall (gnus-get-function gnus-command-method func
)
425 (gnus-group-real-name group
) (nth 1 gnus-command-method
)))))
427 (defun gnus-close-group (group)
428 "Request the GROUP be closed."
429 (let ((gnus-command-method (inline (gnus-find-method-for-group group
))))
430 (funcall (gnus-get-function gnus-command-method
'close-group
)
431 (gnus-group-real-name group
) (nth 1 gnus-command-method
))))
433 (defun gnus-retrieve-headers (articles group
&optional fetch-old
)
434 "Request headers for ARTICLES in GROUP.
435 If FETCH-OLD, retrieve all headers (or some subset thereof) in the group."
436 (let ((gnus-command-method (gnus-find-method-for-group group
)))
438 ((and gnus-use-cache
(numberp (car articles
)))
439 (gnus-cache-retrieve-headers articles group fetch-old
))
440 ((and gnus-agent
(gnus-online gnus-command-method
)
441 (gnus-agent-method-p gnus-command-method
))
442 (gnus-agent-retrieve-headers articles group fetch-old
))
444 (funcall (gnus-get-function gnus-command-method
'retrieve-headers
)
445 articles
(gnus-group-real-name group
)
446 (nth 1 gnus-command-method
) fetch-old
)))))
448 (defun gnus-retrieve-articles (articles group
)
449 "Request ARTICLES in GROUP."
450 (let ((gnus-command-method (gnus-find-method-for-group group
)))
451 (funcall (gnus-get-function gnus-command-method
'retrieve-articles
)
452 articles
(gnus-group-real-name group
)
453 (nth 1 gnus-command-method
))))
455 (defun gnus-retrieve-groups (groups gnus-command-method
)
456 "Request active information on GROUPS from GNUS-COMMAND-METHOD."
457 (when (stringp gnus-command-method
)
458 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
459 (funcall (gnus-get-function gnus-command-method
'retrieve-groups
)
460 groups
(nth 1 gnus-command-method
)))
462 (defun gnus-request-type (group &optional article
)
463 "Return the type (`post' or `mail') of GROUP (and ARTICLE)."
464 (let ((gnus-command-method (gnus-find-method-for-group group
)))
465 (if (not (gnus-check-backend-function
466 'request-type
(car gnus-command-method
)))
468 (funcall (gnus-get-function gnus-command-method
'request-type
)
469 (gnus-group-real-name group
) article
))))
471 (defun gnus-request-update-group-status (group status
)
472 "Change the status of a group.
473 Valid statuses include `subscribe' and `unsubscribe'."
474 (let ((gnus-command-method (gnus-find-method-for-group group
)))
475 (if (not (gnus-check-backend-function
476 'request-update-group-status
(car gnus-command-method
)))
479 (gnus-get-function gnus-command-method
'request-update-group-status
)
480 (gnus-group-real-name group
) status
481 (nth 1 gnus-command-method
)))))
483 (defun gnus-request-set-mark (group action
)
484 "Set marks on articles in the back end."
485 (let ((gnus-command-method (gnus-find-method-for-group group
)))
486 (if (not (gnus-check-backend-function
487 'request-set-mark
(car gnus-command-method
)))
489 (funcall (gnus-get-function gnus-command-method
'request-set-mark
)
490 (gnus-group-real-name group
) action
491 (nth 1 gnus-command-method
))
492 (gnus-run-hook-with-args gnus-after-set-mark-hook group action
))))
494 (defun gnus-request-update-mark (group article mark
)
495 "Allow the back end to change the mark the user tries to put on an article."
496 (let ((gnus-command-method (gnus-find-method-for-group group
)))
497 (if (not (gnus-check-backend-function
498 'request-update-mark
(car gnus-command-method
)))
500 (gnus-run-hook-with-args gnus-before-update-mark-hook group article mark
)
501 (funcall (gnus-get-function gnus-command-method
'request-update-mark
)
502 (gnus-group-real-name group
) article mark
))))
504 (defun gnus-request-article (article group
&optional buffer
)
505 "Request the ARTICLE in GROUP.
506 ARTICLE can either be an article number or an article Message-ID.
507 If BUFFER, insert the article in that group."
508 (let ((gnus-command-method (gnus-find-method-for-group group
)))
509 (funcall (gnus-get-function gnus-command-method
'request-article
)
510 article
(gnus-group-real-name group
)
511 (nth 1 gnus-command-method
) buffer
)))
513 (defun gnus-request-thread (header group
)
514 "Request the headers in the thread containing the article specified by HEADER."
515 (let ((gnus-command-method (gnus-find-method-for-group group
)))
516 (funcall (gnus-get-function gnus-command-method
'request-thread
)
518 (gnus-group-real-name group
))))
520 (defun gnus-select-group-with-message-id (group message-id
)
521 "Activate and select GROUP with the given MESSAGE-ID selected.
522 Returns the article number of the message.
524 If GROUP is not already selected, the message will be the only one in
527 ;; TODO: is there a way to know at this point whether the group will
528 ;; be newly-selected? If so we could clean up the logic at the end
530 ;; save the new group's display parameter, if any, so we
531 ;; can replace it temporarily with zero.
533 (gnus-group-get-parameter group
'display
:allow-list
)))
535 ;; Tell gnus we really don't want any articles
536 (gnus-group-set-parameter group
'display
0)
539 (gnus-summary-read-group-1
540 group
(not :show-all
) :no-article
(not :kill-buffer
)
541 ;; The combination of no-display and this dummy list of
542 ;; articles to select somehow makes it possible to open a
543 ;; group with no articles in it. Black magic.
544 :no-display
'(-1); select-articles
546 ;; Restore the new group's display parameter
547 (gnus-group-set-parameter group
'display saved-display
)))
549 ;; The summary buffer was suppressed by :no-display above.
550 ;; Create it now and insert the message
551 (let ((group-is-new (gnus-summary-setup-buffer group
)))
553 (let ((article-number
554 (gnus-summary-insert-subject message-id
)))
555 (unless article-number
556 (signal 'error
"message-id not in group"))
557 (gnus-summary-select-article nil nil nil article-number
)
559 ;; Clean up the new summary and propagate the error
560 (error (when group-is-new
(gnus-summary-exit))
561 (apply 'signal err
)))))
563 (defun gnus-simplify-group-name (group)
564 "Return the simplest representation of the name of GROUP.
565 This is the string that Gnus uses to identify the group."
566 (gnus-group-prefixed-name
567 (gnus-group-real-name group
)
568 (gnus-group-method group
)))
570 (defun gnus-warp-to-article ()
571 "Warps from an article in a virtual group to the article in its
572 real group. Does nothing on a real group."
574 (when (gnus-virtual-group-p gnus-newsgroup-name
)
575 (let ((gnus-command-method
576 (gnus-find-method-for-group gnus-newsgroup-name
)))
578 (when (gnus-check-backend-function
579 'warp-to-article
(car gnus-command-method
))
580 (funcall (gnus-get-function gnus-command-method
'warp-to-article
)))
581 (and (bound-and-true-p gnus-registry-enabled
)
582 (gnus-try-warping-via-registry))))))
584 (defun gnus-request-head (article group
)
585 "Request the head of ARTICLE in GROUP."
586 (let* ((gnus-command-method (gnus-find-method-for-group group
))
587 (head (gnus-get-function gnus-command-method
'request-head t
))
593 (gnus-cache-request-article article group
))
594 (setq res
(cons group article
)
596 ;; Check the agent cache.
597 ((gnus-agent-request-article article group
)
598 (setq res
(cons group article
)
600 ;; Use `head' function.
602 (setq res
(funcall head article
(gnus-group-real-name group
)
603 (nth 1 gnus-command-method
))))
604 ;; Use `article' function.
606 (setq res
(gnus-request-article article group
)
609 (with-current-buffer nntp-server-buffer
610 (goto-char (point-min))
611 (when (search-forward "\n\n" nil t
)
612 (delete-region (1- (point)) (point-max)))
613 (nnheader-fold-continuation-lines)))
616 (defun gnus-request-body (article group
)
617 "Request the body of ARTICLE in GROUP."
618 (let* ((gnus-command-method (gnus-find-method-for-group group
))
619 (head (gnus-get-function gnus-command-method
'request-body t
))
625 (gnus-cache-request-article article group
))
626 (setq res
(cons group article
)
628 ;; Check the agent cache.
629 ((gnus-agent-request-article article group
)
630 (setq res
(cons group article
)
632 ;; Use `head' function.
634 (setq res
(funcall head article
(gnus-group-real-name group
)
635 (nth 1 gnus-command-method
))))
636 ;; Use `article' function.
638 (setq res
(gnus-request-article article group
)
641 (with-current-buffer nntp-server-buffer
642 (goto-char (point-min))
643 (when (search-forward "\n\n" nil t
)
644 (delete-region (point-min) (1- (point))))))
647 (defun gnus-request-post (gnus-command-method)
648 "Post the current buffer using GNUS-COMMAND-METHOD."
649 (when (stringp gnus-command-method
)
650 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
651 (funcall (gnus-get-function gnus-command-method
'request-post
)
652 (nth 1 gnus-command-method
)))
654 (defun gnus-request-expunge-group (group gnus-command-method
)
655 "Expunge GROUP, which is removing articles that have been marked as deleted."
656 (when (stringp gnus-command-method
)
657 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
658 (funcall (gnus-get-function gnus-command-method
'request-expunge-group
)
659 (gnus-group-real-name group
)
660 (nth 1 gnus-command-method
)))
662 (defun gnus-request-scan (group gnus-command-method
)
663 "Request a SCAN being performed in GROUP from GNUS-COMMAND-METHOD.
664 If GROUP is nil, all groups on GNUS-COMMAND-METHOD are scanned."
665 (let ((gnus-command-method
666 (if group
(gnus-find-method-for-group group
) gnus-command-method
))
667 (gnus-inhibit-demon t
)
668 (mail-source-plugged gnus-plugged
))
669 (when (or gnus-plugged
670 (not (gnus-agent-method-p gnus-command-method
)))
671 (setq gnus-internal-registry-spool-current-method gnus-command-method
)
672 (funcall (gnus-get-function gnus-command-method
'request-scan
)
673 (and group
(gnus-group-real-name group
))
674 (nth 1 gnus-command-method
)))))
676 (defun gnus-request-update-info (info gnus-command-method
)
677 (when (gnus-check-backend-function
678 'request-update-info
(car gnus-command-method
))
679 (when (stringp gnus-command-method
)
680 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
681 (funcall (gnus-get-function gnus-command-method
'request-update-info
)
682 (gnus-group-real-name (gnus-info-group info
)) info
683 (nth 1 gnus-command-method
))))
685 (defsubst gnus-request-marks
(info gnus-command-method
)
686 "Request that GNUS-COMMAND-METHOD update INFO."
687 (when (stringp gnus-command-method
)
688 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
689 (when (gnus-check-backend-function
690 'request-marks
(car gnus-command-method
))
691 (let ((group (gnus-info-group info
)))
692 (and (funcall (gnus-get-function gnus-command-method
'request-marks
)
693 (gnus-group-real-name group
)
694 info
(nth 1 gnus-command-method
))
695 ;; If the minimum article number is greater than 1, then all
696 ;; smaller article numbers are known not to exist; we'll
697 ;; artificially add those to the 'read range.
698 (let* ((active (gnus-active group
))
701 (let* ((range (if (= min
2) 1 (cons 1 (1- min
))))
702 (read (gnus-info-read info
))
703 (new-read (gnus-range-add read
(list range
))))
704 (gnus-info-set-read info new-read
)))
707 (defun gnus-request-expire-articles (articles group
&optional force
)
708 (let* ((gnus-command-method (gnus-find-method-for-group group
))
709 (gnus-inhibit-demon t
)
712 (gnus-get-function gnus-command-method
'request-expire-articles
)
713 articles
(gnus-group-real-name group
) (nth 1 gnus-command-method
)
715 (when (and gnus-agent
716 (gnus-agent-method-p gnus-command-method
))
717 (let ((expired-articles (gnus-sorted-difference articles not-deleted
)))
718 (when expired-articles
719 (gnus-agent-expire expired-articles group
'force
))))
722 (defun gnus-request-move-article (article group server accept-function
723 &optional last move-is-internal
)
724 (let* ((gnus-command-method (gnus-find-method-for-group group
))
725 (result (funcall (gnus-get-function gnus-command-method
726 'request-move-article
)
727 article
(gnus-group-real-name group
)
728 (nth 1 gnus-command-method
) accept-function
729 last move-is-internal
)))
730 (when (and result gnus-agent
731 (gnus-agent-method-p gnus-command-method
))
732 (gnus-agent-unfetch-articles group
(list article
)))
735 (defun gnus-request-accept-article (group &optional gnus-command-method last
737 ;; Make sure there's a newline at the end of the article.
738 (when (stringp gnus-command-method
)
739 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
740 (when (and (not gnus-command-method
)
742 (setq gnus-command-method
(or (gnus-find-method-for-group group
)
743 (gnus-group-name-to-method group
))))
744 (goto-char (point-max))
748 (let ((message-options message-options
))
749 (message-options-set-recipient)
751 (message-narrow-to-head)
752 (let ((mail-parse-charset message-default-charset
))
753 (mail-encode-encoded-word-buffer)))
754 (message-encode-message-body)))
755 (let ((gnus-command-method (or gnus-command-method
756 (gnus-find-method-for-group group
)))
759 (gnus-get-function gnus-command-method
'request-accept-article
)
760 (if (stringp group
) (gnus-group-real-name group
) group
)
761 (cadr gnus-command-method
)
763 (when (and gnus-agent
764 (gnus-agent-method-p gnus-command-method
)
766 (gnus-agent-regenerate-group group
(list (cdr result
))))
769 (defun gnus-request-replace-article (article group buffer
&optional no-encode
)
771 (let ((message-options message-options
))
772 (message-options-set-recipient)
774 (message-narrow-to-head)
775 (let ((mail-parse-charset message-default-charset
))
776 (mail-encode-encoded-word-buffer)))
777 (message-encode-message-body)))
778 (let* ((func (car (gnus-group-name-to-method group
)))
779 (result (funcall (intern (format "%s-request-replace-article" func
))
780 article
(gnus-group-real-name group
) buffer
)))
781 (when (and gnus-agent
(gnus-agent-method-p gnus-command-method
))
782 (gnus-agent-regenerate-group group
(list article
)))
785 (defun gnus-request-restore-buffer (article group
)
786 "Request a new buffer restored to the state of ARTICLE."
787 (let ((gnus-command-method (gnus-find-method-for-group group
)))
788 (funcall (gnus-get-function gnus-command-method
'request-restore-buffer
)
789 article
(gnus-group-real-name group
)
790 (nth 1 gnus-command-method
))))
792 (defun gnus-request-create-group (group &optional gnus-command-method args
)
793 (when (stringp gnus-command-method
)
794 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
795 (let ((gnus-command-method
796 (or gnus-command-method
(gnus-find-method-for-group group
))))
797 (funcall (gnus-get-function gnus-command-method
'request-create-group
)
798 (gnus-group-real-name group
) (nth 1 gnus-command-method
) args
)))
800 (defun gnus-request-delete-group (group &optional force
)
801 (let* ((gnus-command-method (gnus-find-method-for-group group
))
803 (funcall (gnus-get-function gnus-command-method
'request-delete-group
)
804 (gnus-group-real-name group
) force
(nth 1 gnus-command-method
))))
806 (gnus-cache-delete-group group
)
807 (gnus-agent-delete-group group
))
810 (defun gnus-request-rename-group (group new-name
)
811 (let* ((gnus-command-method (gnus-find-method-for-group group
))
813 (funcall (gnus-get-function gnus-command-method
'request-rename-group
)
814 (gnus-group-real-name group
)
815 (gnus-group-real-name new-name
) (nth 1 gnus-command-method
))))
817 (gnus-cache-rename-group group new-name
)
818 (gnus-agent-rename-group group new-name
))
821 (defun gnus-close-backends ()
822 ;; Send a close request to all backends that support such a request.
823 (let ((methods gnus-valid-select-methods
)
824 (gnus-inhibit-demon t
)
825 func gnus-command-method
)
826 (while (setq gnus-command-method
(pop methods
))
827 (when (fboundp (setq func
(intern
828 (concat (car gnus-command-method
)
832 (defun gnus-asynchronous-p (gnus-command-method)
833 (let ((func (gnus-get-function gnus-command-method
'asynchronous-p t
)))
837 (defun gnus-remove-denial (gnus-command-method)
838 (when (stringp gnus-command-method
)
839 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
840 (let* ((elem (assoc gnus-command-method gnus-opened-servers
))
841 (status (cadr elem
)))
842 ;; If this hasn't been opened before, we add it to the list.
843 (when (eq status
'denied
)
844 ;; Set the status of this server.
845 (setcar (cdr elem
) 'closed
))))
849 ;;; gnus-int.el ends here