1 ;;; gnus-int.el --- backend interface functions for Gnus
3 ;; Copyright (C) 1996-2018 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 <https://www.gnu.org/licenses/>.
31 (autoload 'gnus-run-hook-with-args
"gnus-util")
32 (autoload 'gnus-agent-expire
"gnus-agent")
33 (autoload 'gnus-agent-regenerate-group
"gnus-agent")
34 (autoload 'gnus-agent-read-servers-validate-native
"gnus-agent")
35 (autoload 'gnus-agent-possibly-synchronize-flags-server
"gnus-agent")
37 (defcustom gnus-open-server-hook nil
38 "Hook called just before opening connection to the news server."
42 (defcustom gnus-after-set-mark-hook nil
43 "Hook called just after marks are set in a group."
48 (defcustom gnus-before-update-mark-hook nil
49 "Hook called just before marks are updated in a group."
54 (defcustom gnus-server-unopen-status nil
55 "The default status if the server is not able to open.
56 If the server is covered by Gnus agent, the possible values are
57 `denied', set the server denied; `offline', set the server offline;
58 nil, ask user. If the server is not covered by Gnus agent, set the
62 :type
'(choice (const :tag
"Ask" nil
)
63 (const :tag
"Deny server" denied
)
64 (const :tag
"Unplug Agent" offline
)))
66 (defcustom gnus-nntp-server nil
67 "The name of the host running the NNTP server."
69 :type
'(choice (const :tag
"disable" nil
)
71 (make-obsolete-variable 'gnus-nntp-server
'gnus-select-method
"24.1")
73 (defvar gnus-internal-registry-spool-current-method nil
74 "The current method, for the registry.")
77 (defun gnus-server-opened (gnus-command-method)
78 "Check whether a connection to GNUS-COMMAND-METHOD has been opened."
79 (unless (eq (gnus-server-status gnus-command-method
)
81 (when (stringp gnus-command-method
)
82 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
83 (funcall (inline (gnus-get-function gnus-command-method
'server-opened
))
84 (nth 1 gnus-command-method
))))
86 (defun gnus-status-message (gnus-command-method)
87 "Return the status message from GNUS-COMMAND-METHOD.
88 If GNUS-COMMAND-METHOD is a string, it is interpreted as a group
89 name. The method this group uses will be queried."
90 (let ((gnus-command-method
91 (if (stringp gnus-command-method
)
92 (gnus-find-method-for-group gnus-command-method
)
93 gnus-command-method
)))
94 (funcall (gnus-get-function gnus-command-method
'status-message
)
95 (nth 1 gnus-command-method
))))
98 ;;; Server Communication
101 (defun gnus-start-news-server (&optional confirm
)
102 "Open a method for getting news.
103 If CONFIRM is non-nil, the user will be asked for an NNTP server."
105 (if gnus-current-select-method
106 ;; Stream is already opened.
110 ;; Read server name with completion.
111 (setq gnus-nntp-server
112 (gnus-completing-read "NNTP server"
113 (cons gnus-nntp-server
114 (if (boundp 'gnus-secondary-servers
)
115 gnus-secondary-servers
))
116 nil gnus-nntp-server
)))
118 (when (and gnus-nntp-server
119 (stringp gnus-nntp-server
)
120 (not (string= gnus-nntp-server
"")))
121 (setq gnus-select-method
122 (cond ((or (string= gnus-nntp-server
"")
123 (string= gnus-nntp-server
"::"))
124 (list 'nnspool
(system-name)))
125 ((string-match "^:" gnus-nntp-server
)
126 (list 'nnmh gnus-nntp-server
127 (list 'nnmh-directory
128 (file-name-as-directory
130 (substring gnus-nntp-server
1) "~/")))
131 (list 'nnmh-get-new-mail nil
)))
133 (list 'nntp gnus-nntp-server
)))))
135 (setq how
(car gnus-select-method
))
139 (gnus-message 5 "Looking up local news spool..."))
142 (gnus-message 5 "Looking up mh spool..."))
145 (setq gnus-current-select-method gnus-select-method
)
146 (gnus-run-hooks 'gnus-open-server-hook
)
148 ;; Partially validate agent covered methods now that the
149 ;; gnus-select-method is known.
152 ;; NOTE: This is here for one purpose only. By validating
153 ;; the current select method, it converts the old 5.10.3,
154 ;; and earlier, format to the current format. That enables
155 ;; the agent code within gnus-open-server to function
157 (gnus-agent-read-servers-validate-native gnus-select-method
))
160 ;; gnus-open-server-hook might have opened it
161 (gnus-server-opened gnus-select-method
)
162 (gnus-open-server gnus-select-method
)
166 "%s (%s) open error: `%s'. Continue? "
167 (car gnus-select-method
) (cadr gnus-select-method
)
168 (gnus-status-message gnus-select-method
)))
169 (gnus-error 1 "Couldn't open server on %s"
170 (nth 1 gnus-select-method
))))))
172 (defun gnus-check-group (group)
173 "Try to make sure that the server where GROUP exists is alive."
174 (let ((method (gnus-find-method-for-group group
)))
175 (or (gnus-server-opened method
)
176 (gnus-open-server method
))))
178 (defun gnus-check-server (&optional method silent
)
179 "Check whether the connection to METHOD is down.
180 If METHOD is nil, use `gnus-select-method'.
181 If it is down, start it up (again)."
182 (let ((method (or method gnus-select-method
))
184 ;; Transform virtual server names into select methods.
185 (when (stringp method
)
186 (setq method
(gnus-server-to-method method
)))
187 (if (gnus-server-opened method
)
188 ;; The stream is already opened.
192 (gnus-message 5 "Opening %s server%s..." (car method
)
193 (if (equal (nth 1 method
) "") ""
194 (format " on %s" (nth 1 method
)))))
195 (gnus-run-hooks 'gnus-open-server-hook
)
197 (setq result
(gnus-open-server method
))
201 "Opening %s server%s...%s" (car method
)
202 (if (equal (nth 1 method
) "") ""
203 (format " on %s" (nth 1 method
)))
207 (nnheader-get-report-string (car method
))))))))))
209 (defun gnus-get-function (method function
&optional noerror
)
210 "Return a function symbol based on METHOD and FUNCTION."
211 ;; Translate server names into methods.
213 (error "Attempted use of a nil select method"))
214 (when (stringp method
)
215 (setq method
(gnus-server-to-method method
)))
216 ;; Check cache of constructed names.
217 (let* ((method-sym (if gnus-agent
218 (inline (gnus-agent-get-function method
))
220 (method-fns (get method-sym
'gnus-method-functions
))
221 (func (let ((method-fnlist-elt (assq function method-fns
)))
222 (unless method-fnlist-elt
223 (setq method-fnlist-elt
225 (intern (format "%s-%s" method-sym function
))))
226 (put method-sym
'gnus-method-functions
227 (cons method-fnlist-elt method-fns
)))
228 (cdr method-fnlist-elt
))))
229 ;; Maybe complain if there is no function.
230 (unless (fboundp func
)
232 (error "Trying to require a method that doesn't exist"))
233 (require (car method
))
234 (when (not (fboundp func
))
237 (error "No such function: %s" func
))))
242 ;;; Interface functions to the backends.
245 (defun gnus-method-denied-p (method)
246 (eq (nth 1 (assoc method gnus-opened-servers
))
249 (defvar gnus-backend-trace nil
)
250 (defvar gnus-backend-trace-elapsed nil
)
252 (defun gnus-backend-trace (type form
)
253 (when gnus-backend-trace
254 (with-current-buffer (get-buffer-create "*gnus trace*")
255 (buffer-disable-undo)
256 (goto-char (point-max))
257 (insert (format-time-string "%H:%M:%S")
258 (format " %.2fs %s %S\n"
259 (if (numberp gnus-backend-trace-elapsed
)
260 (- (float-time) gnus-backend-trace-elapsed
)
263 (setq gnus-backend-trace-elapsed
(float-time)))))
265 (defun gnus-open-server (gnus-command-method)
266 "Open a connection to GNUS-COMMAND-METHOD."
267 (when (stringp gnus-command-method
)
268 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
269 (gnus-backend-trace :opening gnus-command-method
)
270 (let ((elem (assoc gnus-command-method gnus-opened-servers
))
271 (server (gnus-method-to-server-name gnus-command-method
)))
272 ;; If this method was previously denied, we just return nil.
273 (if (eq (nth 1 elem
) 'denied
)
276 1 "Server %s previously determined to be down; not retrying" server
)
279 (let* ((open-server-function
280 (gnus-get-function gnus-command-method
'open-server
))
283 (funcall open-server-function
284 (nth 1 gnus-command-method
)
285 (nthcdr 2 gnus-command-method
))
287 (gnus-message 1 "Unable to open server %s due to: %s"
288 server
(error-message-string err
))
293 (gnus-message 1 "Quit trying to open server %s" server
))
296 ;; If this hasn't been opened before, we add it to the list.
298 (setq elem
(list gnus-command-method nil
)
299 gnus-opened-servers
(cons elem gnus-opened-servers
)))
300 ;; Set the status of this server.
304 (if (eq open-server-function
'nnagent-open-server
)
305 ;; The agent's backend has a "special" status
309 (gnus-agent-method-p gnus-command-method
))
311 (gnus-server-unopen-status
312 ;; Set the server's status to the unopen
313 ;; status. If that status is offline,
314 ;; recurse to open the agent's backend.
315 (setq open-offline
(eq gnus-server-unopen-status
'offline
))
316 gnus-server-unopen-status
)
317 ((not gnus-batch-mode
)
318 (setq open-offline t
)
321 ;; This agentized server was still denied
324 ;; This unagentized server must be denied
327 ;; NOTE: I MUST set the server's status to offline before this
328 ;; recursive call as this status will drive the
329 ;; gnus-get-function (called above) to return the agent's
332 ;; Recursively open this offline server to perform the
333 ;; open-server function of the agent's backend.
334 (let ((gnus-server-unopen-status 'denied
))
335 ;; Bind gnus-server-unopen-status to avoid recursively
336 ;; prompting with "go offline?". This is only a concern
337 ;; when the agent's backend fails to open the server.
338 (gnus-open-server gnus-command-method
))
339 (when (and (eq (cadr elem
) 'ok
) gnus-agent
340 (gnus-agent-method-p gnus-command-method
))
342 (gnus-agent-possibly-synchronize-flags-server
343 gnus-command-method
)))
344 (gnus-backend-trace :opened gnus-command-method
)
347 (defun gnus-close-server (gnus-command-method)
348 "Close the connection to GNUS-COMMAND-METHOD."
349 (when (stringp gnus-command-method
)
350 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
351 (funcall (gnus-get-function gnus-command-method
'close-server
)
352 (nth 1 gnus-command-method
)))
354 (defun gnus-request-list (gnus-command-method)
355 "Request the active file from GNUS-COMMAND-METHOD."
356 (when (stringp gnus-command-method
)
357 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
358 (funcall (gnus-get-function gnus-command-method
'request-list
)
359 (nth 1 gnus-command-method
)))
361 (defun gnus-finish-retrieve-group-infos (gnus-command-method infos data
)
362 "Read and update infos from GNUS-COMMAND-METHOD."
363 (when (stringp gnus-command-method
)
364 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
365 (gnus-backend-trace :finishing gnus-command-method
)
367 (funcall (gnus-get-function gnus-command-method
368 'finish-retrieve-group-infos
)
369 (nth 1 gnus-command-method
)
371 (gnus-backend-trace :finished gnus-command-method
)))
373 (defun gnus-retrieve-group-data-early (gnus-command-method infos
)
374 "Start early async retrieval of data from GNUS-COMMAND-METHOD."
375 (when (stringp gnus-command-method
)
376 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
377 (funcall (gnus-get-function gnus-command-method
'retrieve-group-data-early
)
378 (nth 1 gnus-command-method
)
381 (defun gnus-request-list-newsgroups (gnus-command-method)
382 "Request the newsgroups file from GNUS-COMMAND-METHOD."
383 (when (stringp gnus-command-method
)
384 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
385 (funcall (gnus-get-function gnus-command-method
'request-list-newsgroups
)
386 (nth 1 gnus-command-method
)))
388 (defun gnus-request-newgroups (date gnus-command-method
)
389 "Request all new groups since DATE from GNUS-COMMAND-METHOD."
390 (when (stringp gnus-command-method
)
391 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
392 (let ((func (gnus-get-function gnus-command-method
'request-newgroups t
)))
394 (funcall func date
(nth 1 gnus-command-method
)))))
396 (defun gnus-request-regenerate (gnus-command-method)
397 "Request a data generation from GNUS-COMMAND-METHOD."
398 (when (stringp gnus-command-method
)
399 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
400 (funcall (gnus-get-function gnus-command-method
'request-regenerate
)
401 (nth 1 gnus-command-method
)))
403 (defun gnus-request-compact-group (group)
404 (let* ((method (gnus-find-method-for-group group
))
405 (gnus-command-method method
)
407 (funcall (gnus-get-function gnus-command-method
408 'request-compact-group
)
409 (gnus-group-real-name group
)
410 (nth 1 gnus-command-method
) t
)))
413 (defun gnus-request-compact (gnus-command-method)
414 "Request groups compaction from GNUS-COMMAND-METHOD."
415 (when (stringp gnus-command-method
)
416 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
417 (funcall (gnus-get-function gnus-command-method
'request-compact
)
418 (nth 1 gnus-command-method
)))
420 (defun gnus-request-group (group &optional dont-check gnus-command-method info
)
421 "Request GROUP. If DONT-CHECK, no information is required."
422 (let ((gnus-command-method
423 (or gnus-command-method
(inline (gnus-find-method-for-group group
)))))
424 (when (stringp gnus-command-method
)
425 (setq gnus-command-method
426 (inline (gnus-server-to-method gnus-command-method
))))
427 (funcall (inline (gnus-get-function gnus-command-method
'request-group
))
428 (gnus-group-real-name group
) (nth 1 gnus-command-method
)
432 (defun gnus-request-group-description (group)
433 "Request a description of GROUP."
434 (let ((gnus-command-method (gnus-find-method-for-group group
))
435 (func 'request-group-description
))
436 (when (gnus-check-backend-function func group
)
437 (funcall (gnus-get-function gnus-command-method func
)
438 (gnus-group-real-name group
) (nth 1 gnus-command-method
)))))
440 (defun gnus-request-group-scan (group info
)
441 "Request that GROUP get a complete rescan."
442 (let ((gnus-command-method (gnus-find-method-for-group group
))
443 (func 'request-group-scan
))
444 (when (gnus-check-backend-function func group
)
445 (funcall (gnus-get-function gnus-command-method func
)
446 (gnus-group-real-name group
) (nth 1 gnus-command-method
) info
))))
448 (defun gnus-close-group (group)
449 "Request the GROUP be closed."
450 (let ((gnus-command-method (inline (gnus-find-method-for-group group
))))
451 (funcall (gnus-get-function gnus-command-method
'close-group
)
452 (gnus-group-real-name group
) (nth 1 gnus-command-method
))))
454 (defun gnus-retrieve-headers (articles group
&optional fetch-old
)
455 "Request headers for ARTICLES in GROUP.
456 If FETCH-OLD, retrieve all headers (or some subset thereof) in the group."
457 (let ((gnus-command-method (gnus-find-method-for-group group
)))
459 ((and gnus-use-cache
(numberp (car articles
)))
460 (gnus-cache-retrieve-headers articles group fetch-old
))
461 ((and gnus-agent
(gnus-online gnus-command-method
)
462 (gnus-agent-method-p gnus-command-method
))
463 (gnus-agent-retrieve-headers articles group fetch-old
))
465 (funcall (gnus-get-function gnus-command-method
'retrieve-headers
)
466 articles
(gnus-group-real-name group
)
467 (nth 1 gnus-command-method
) fetch-old
)))))
469 (defun gnus-retrieve-articles (articles group
)
470 "Request ARTICLES in GROUP."
471 (let ((gnus-command-method (gnus-find-method-for-group group
)))
472 (funcall (gnus-get-function gnus-command-method
'retrieve-articles
)
473 articles
(gnus-group-real-name group
)
474 (nth 1 gnus-command-method
))))
476 (defun gnus-retrieve-groups (groups gnus-command-method
)
477 "Request active information on GROUPS from GNUS-COMMAND-METHOD."
478 (when (stringp gnus-command-method
)
479 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
480 (funcall (gnus-get-function gnus-command-method
'retrieve-groups
)
481 groups
(nth 1 gnus-command-method
)))
483 (defun gnus-request-type (group &optional article
)
484 "Return the type (`post' or `mail') of GROUP (and ARTICLE)."
485 (let ((gnus-command-method (gnus-find-method-for-group group
)))
486 (if (not (gnus-check-backend-function
487 'request-type
(car gnus-command-method
)))
489 (funcall (gnus-get-function gnus-command-method
'request-type
)
490 (gnus-group-real-name group
) article
))))
492 (defun gnus-request-update-group-status (group status
)
493 "Change the status of a group.
494 Valid statuses include `subscribe' and `unsubscribe'."
495 (let ((gnus-command-method (gnus-find-method-for-group group
)))
496 (if (not (gnus-check-backend-function
497 'request-update-group-status
(car gnus-command-method
)))
500 (gnus-get-function gnus-command-method
'request-update-group-status
)
501 (gnus-group-real-name group
) status
502 (nth 1 gnus-command-method
)))))
504 (defun gnus-request-set-mark (group action
)
505 "Set marks on articles in the back end."
506 (let ((gnus-command-method (gnus-find-method-for-group group
)))
507 (if (not (gnus-check-backend-function
508 'request-set-mark
(car gnus-command-method
)))
510 (funcall (gnus-get-function gnus-command-method
'request-set-mark
)
511 (gnus-group-real-name group
) action
512 (nth 1 gnus-command-method
))
513 (gnus-run-hook-with-args gnus-after-set-mark-hook group action
))))
515 (defun gnus-request-update-mark (group article mark
)
516 "Allow the back end to change the mark the user tries to put on an article."
517 (let ((gnus-command-method (gnus-find-method-for-group group
)))
518 (if (not (gnus-check-backend-function
519 'request-update-mark
(car gnus-command-method
)))
521 (gnus-run-hook-with-args gnus-before-update-mark-hook group article mark
)
522 (funcall (gnus-get-function gnus-command-method
'request-update-mark
)
523 (gnus-group-real-name group
) article mark
))))
525 (defun gnus-request-article (article group
&optional buffer
)
526 "Request the ARTICLE in GROUP.
527 ARTICLE can either be an article number or an article Message-ID.
528 If BUFFER, insert the article in that group."
529 (let ((gnus-command-method (gnus-find-method-for-group group
)))
530 (funcall (gnus-get-function gnus-command-method
'request-article
)
531 article
(gnus-group-real-name group
)
532 (nth 1 gnus-command-method
) buffer
)))
534 (defun gnus-request-thread (header group
)
535 "Request the headers in the thread containing the article specified by HEADER."
536 (let ((gnus-command-method (gnus-find-method-for-group group
)))
537 (funcall (gnus-get-function gnus-command-method
'request-thread
)
539 (gnus-group-real-name group
))))
541 (defun gnus-select-group-with-message-id (group message-id
)
542 "Activate and select GROUP with the given MESSAGE-ID selected.
543 Returns the article number of the message.
545 If GROUP is not already selected, the message will be the only one in
548 ;; TODO: is there a way to know at this point whether the group will
549 ;; be newly-selected? If so we could clean up the logic at the end
551 ;; save the new group's display parameter, if any, so we
552 ;; can replace it temporarily with zero.
554 (gnus-group-get-parameter group
'display
:allow-list
)))
556 ;; Tell gnus we really don't want any articles
557 (gnus-group-set-parameter group
'display
0)
560 (gnus-summary-read-group-1
561 group
(not :show-all
) :no-article
(not :kill-buffer
)
562 ;; The combination of no-display and this dummy list of
563 ;; articles to select somehow makes it possible to open a
564 ;; group with no articles in it. Black magic.
565 :no-display
'(-1); select-articles
567 ;; Restore the new group's display parameter
568 (gnus-group-set-parameter group
'display saved-display
)))
570 ;; The summary buffer was suppressed by :no-display above.
571 ;; Create it now and insert the message
572 (let ((group-is-new (gnus-summary-setup-buffer group
)))
574 (let ((article-number
575 (gnus-summary-insert-subject message-id
)))
576 (unless article-number
577 (signal 'error
"message-id not in group"))
578 (gnus-summary-select-article nil nil nil article-number
)
580 ;; Clean up the new summary and propagate the error
581 (error (when group-is-new
(gnus-summary-exit))
582 (apply 'signal err
)))))
584 (defun gnus-simplify-group-name (group)
585 "Return the simplest representation of the name of GROUP.
586 This is the string that Gnus uses to identify the group."
587 (gnus-group-prefixed-name
588 (gnus-group-real-name group
)
589 (gnus-group-method group
)))
591 (defun gnus-warp-to-article ()
592 "Look up the current article in the group where it originated.
593 This command only makes sense for groups shows articles gathered
594 from other groups -- for instance, search results and the like."
596 (let ((gnus-command-method
597 (gnus-find-method-for-group gnus-newsgroup-name
)))
599 (when (gnus-check-backend-function
600 'warp-to-article
(car gnus-command-method
))
601 (funcall (gnus-get-function gnus-command-method
'warp-to-article
)))
602 (and (bound-and-true-p gnus-registry-enabled
)
603 (gnus-try-warping-via-registry)))))
605 (defun gnus-request-head (article group
)
606 "Request the head of ARTICLE in GROUP."
607 (let* ((gnus-command-method (gnus-find-method-for-group group
))
608 (head (gnus-get-function gnus-command-method
'request-head t
))
614 (gnus-cache-request-article article group
))
615 (setq res
(cons group article
)
617 ;; Check the agent cache.
618 ((gnus-agent-request-article article group
)
619 (setq res
(cons group article
)
621 ;; Use `head' function.
623 (setq res
(funcall head article
624 (and (not gnus-override-method
) (gnus-group-real-name group
))
625 (nth 1 gnus-command-method
))))
626 ;; Use `article' function.
628 (setq res
(gnus-request-article article group
)
631 (with-current-buffer nntp-server-buffer
632 (goto-char (point-min))
633 (when (search-forward "\n\n" nil t
)
634 (delete-region (1- (point)) (point-max)))
635 (nnheader-fold-continuation-lines)))
638 (defun gnus-request-body (article group
)
639 "Request the body of ARTICLE in GROUP."
640 (let* ((gnus-command-method (gnus-find-method-for-group group
))
641 (head (gnus-get-function gnus-command-method
'request-body t
))
647 (gnus-cache-request-article article group
))
648 (setq res
(cons group article
)
650 ;; Check the agent cache.
651 ((gnus-agent-request-article article group
)
652 (setq res
(cons group article
)
654 ;; Use `head' function.
656 (setq res
(funcall head article
(gnus-group-real-name group
)
657 (nth 1 gnus-command-method
))))
658 ;; Use `article' function.
660 (setq res
(gnus-request-article article group
)
663 (with-current-buffer nntp-server-buffer
664 (goto-char (point-min))
665 (when (search-forward "\n\n" nil t
)
666 (delete-region (point-min) (1- (point))))))
669 (defun gnus-request-post (gnus-command-method)
670 "Post the current buffer using GNUS-COMMAND-METHOD."
671 (when (stringp gnus-command-method
)
672 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
673 (funcall (gnus-get-function gnus-command-method
'request-post
)
674 (nth 1 gnus-command-method
)))
676 (defun gnus-request-expunge-group (group gnus-command-method
)
677 "Expunge GROUP, which is removing articles that have been marked as deleted."
678 (when (stringp gnus-command-method
)
679 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
680 (funcall (gnus-get-function gnus-command-method
'request-expunge-group
)
681 (gnus-group-real-name group
)
682 (nth 1 gnus-command-method
)))
684 (defun gnus-request-scan (group gnus-command-method
)
685 "Request a SCAN being performed in GROUP from GNUS-COMMAND-METHOD.
686 If GROUP is nil, all groups on GNUS-COMMAND-METHOD are scanned."
687 (let ((gnus-command-method
688 (if group
(gnus-find-method-for-group group
) gnus-command-method
))
689 (gnus-inhibit-demon t
)
690 (mail-source-plugged gnus-plugged
))
691 (when (or gnus-plugged
692 (not (gnus-agent-method-p gnus-command-method
)))
693 (setq gnus-internal-registry-spool-current-method gnus-command-method
)
694 (funcall (gnus-get-function gnus-command-method
'request-scan
)
695 (and group
(gnus-group-real-name group
))
696 (nth 1 gnus-command-method
)))))
698 (defun gnus-request-update-info (info gnus-command-method
)
699 (when (gnus-check-backend-function
700 'request-update-info
(car gnus-command-method
))
701 (when (stringp gnus-command-method
)
702 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
703 (funcall (gnus-get-function gnus-command-method
'request-update-info
)
704 (gnus-group-real-name (gnus-info-group info
)) info
705 (nth 1 gnus-command-method
))))
707 (defsubst gnus-request-marks
(info gnus-command-method
)
708 "Request that GNUS-COMMAND-METHOD update INFO."
709 (when (stringp gnus-command-method
)
710 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
711 (when (gnus-check-backend-function
712 'request-marks
(car gnus-command-method
))
713 (let ((group (gnus-info-group info
)))
714 (and (funcall (gnus-get-function gnus-command-method
'request-marks
)
715 (gnus-group-real-name group
)
716 info
(nth 1 gnus-command-method
))
717 ;; If the minimum article number is greater than 1, then all
718 ;; smaller article numbers are known not to exist; we'll
719 ;; artificially add those to the 'read range.
720 (let* ((active (gnus-active group
))
723 (let* ((range (if (= min
2) 1 (cons 1 (1- min
))))
724 (read (gnus-info-read info
))
725 (new-read (gnus-range-add read
(list range
))))
726 (gnus-info-set-read info new-read
)))
729 (defun gnus-request-expire-articles (articles group
&optional force
)
730 (let* ((gnus-command-method (gnus-find-method-for-group group
))
731 ;; Filter out any negative article numbers; they can't be
734 (delq nil
(mapcar (lambda (n) (and (>= n
0) n
)) articles
)))
735 (gnus-inhibit-demon t
)
738 (gnus-get-function gnus-command-method
'request-expire-articles
)
739 articles
(gnus-group-real-name group
) (nth 1 gnus-command-method
)
741 (when (and gnus-agent
742 (gnus-agent-method-p gnus-command-method
))
743 (let ((expired-articles (gnus-sorted-difference articles not-deleted
)))
744 (when expired-articles
745 (gnus-agent-expire expired-articles group
'force
))))
748 (defun gnus-request-move-article (article group server accept-function
749 &optional last move-is-internal
)
750 (let* ((gnus-command-method (gnus-find-method-for-group group
))
751 (result (funcall (gnus-get-function gnus-command-method
752 'request-move-article
)
753 article
(gnus-group-real-name group
)
754 (nth 1 gnus-command-method
) accept-function
755 last move-is-internal
)))
756 (when (and result gnus-agent
757 (gnus-agent-method-p gnus-command-method
))
758 (gnus-agent-unfetch-articles group
(list article
)))
761 (defun gnus-request-accept-article (group &optional gnus-command-method last
763 (when (stringp gnus-command-method
)
764 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
765 (when (and (not gnus-command-method
)
767 (setq gnus-command-method
(or (gnus-find-method-for-group group
)
768 (gnus-group-name-to-method group
))))
769 (goto-char (point-max))
770 ;; Make sure there's a newline at the end of the article.
774 (let ((message-options message-options
))
775 (message-options-set-recipient)
777 (message-narrow-to-head)
778 (mail-encode-encoded-word-buffer))
779 (message-encode-message-body)))
780 (let ((gnus-command-method (or gnus-command-method
781 (gnus-find-method-for-group group
)))
784 (gnus-get-function gnus-command-method
'request-accept-article
)
785 (if (stringp group
) (gnus-group-real-name group
) group
)
786 (cadr gnus-command-method
)
788 (when (and gnus-agent
789 (gnus-agent-method-p gnus-command-method
)
791 (gnus-agent-regenerate-group group
(list (cdr result
))))
794 (defun gnus-request-replace-article (article group buffer
&optional no-encode
)
796 (let ((message-options message-options
))
797 (message-options-set-recipient)
799 (message-narrow-to-head)
800 (mail-encode-encoded-word-buffer))
801 (message-encode-message-body)))
802 (let* ((func (car (gnus-group-name-to-method group
)))
803 (result (funcall (intern (format "%s-request-replace-article" func
))
804 article
(gnus-group-real-name group
) buffer
)))
805 (when (and gnus-agent
(gnus-agent-method-p gnus-command-method
))
806 (gnus-agent-regenerate-group group
(list article
)))
809 (defun gnus-request-restore-buffer (article group
)
810 "Request a new buffer restored to the state of ARTICLE."
811 (let ((gnus-command-method (gnus-find-method-for-group group
)))
812 (funcall (gnus-get-function gnus-command-method
'request-restore-buffer
)
813 article
(gnus-group-real-name group
)
814 (nth 1 gnus-command-method
))))
816 (defun gnus-request-create-group (group &optional gnus-command-method args
)
817 (when (stringp gnus-command-method
)
818 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
819 (let ((gnus-command-method
820 (or gnus-command-method
(gnus-find-method-for-group group
))))
821 (funcall (gnus-get-function gnus-command-method
'request-create-group
)
822 (gnus-group-real-name group
) (nth 1 gnus-command-method
) args
)))
824 (defun gnus-request-delete-group (group &optional force
)
825 (let* ((gnus-command-method (gnus-find-method-for-group group
))
827 (funcall (gnus-get-function gnus-command-method
'request-delete-group
)
828 (gnus-group-real-name group
) force
(nth 1 gnus-command-method
))))
830 (gnus-cache-delete-group group
)
831 (gnus-agent-delete-group group
))
834 (defun gnus-request-rename-group (group new-name
)
835 (let* ((gnus-command-method (gnus-find-method-for-group group
))
837 (funcall (gnus-get-function gnus-command-method
'request-rename-group
)
838 (gnus-group-real-name group
)
839 (gnus-group-real-name new-name
) (nth 1 gnus-command-method
))))
841 (gnus-cache-rename-group group new-name
)
842 (gnus-agent-rename-group group new-name
))
845 (defun gnus-close-backends ()
846 ;; Send a close request to all backends that support such a request.
847 (let ((methods gnus-valid-select-methods
)
848 (gnus-inhibit-demon t
)
849 func gnus-command-method
)
850 (while (setq gnus-command-method
(pop methods
))
851 (when (fboundp (setq func
(intern
852 (concat (car gnus-command-method
)
856 (defun gnus-asynchronous-p (gnus-command-method)
857 (let ((func (gnus-get-function gnus-command-method
'asynchronous-p t
)))
861 (defun gnus-remove-denial (gnus-command-method)
862 (when (stringp gnus-command-method
)
863 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
864 (let* ((elem (assoc gnus-command-method gnus-opened-servers
))
865 (status (cadr elem
)))
866 ;; If this hasn't been opened before, we add it to the list.
867 (when (eq status
'denied
)
868 ;; Set the status of this server.
869 (setcar (cdr elem
) 'closed
))))
873 ;;; gnus-int.el ends here