1 ;;; gnus-int.el --- backend interface functions for Gnus
3 ;; Copyright (C) 1996-2011 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."
49 (defcustom gnus-before-update-mark-hook nil
50 "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 (defvar gnus-internal-registry-spool-current-method nil
67 "The current method, for the registry.")
70 (defun gnus-server-opened (gnus-command-method)
71 "Check whether a connection to GNUS-COMMAND-METHOD has been opened."
72 (unless (eq (gnus-server-status gnus-command-method
)
74 (when (stringp gnus-command-method
)
75 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
76 (funcall (inline (gnus-get-function gnus-command-method
'server-opened
))
77 (nth 1 gnus-command-method
))))
79 (defun gnus-status-message (gnus-command-method)
80 "Return the status message from GNUS-COMMAND-METHOD.
81 If GNUS-COMMAND-METHOD is a string, it is interpreted as a group
82 name. The method this group uses will be queried."
83 (let ((gnus-command-method
84 (if (stringp gnus-command-method
)
85 (gnus-find-method-for-group gnus-command-method
)
86 gnus-command-method
)))
87 (funcall (gnus-get-function gnus-command-method
'status-message
)
88 (nth 1 gnus-command-method
))))
91 ;;; Server Communication
94 (defun gnus-start-news-server (&optional confirm
)
95 "Open a method for getting news.
96 If CONFIRM is non-nil, the user will be asked for an NNTP server."
98 (if gnus-current-select-method
99 ;; Stream is already opened.
103 ;; Read server name with completion.
104 (setq gnus-nntp-server
105 (gnus-completing-read "NNTP server"
106 (cons gnus-nntp-server
107 gnus-secondary-servers
)
108 nil gnus-nntp-server
)))
110 (when (and gnus-nntp-server
111 (stringp gnus-nntp-server
)
112 (not (string= gnus-nntp-server
"")))
113 (setq gnus-select-method
114 (cond ((or (string= gnus-nntp-server
"")
115 (string= gnus-nntp-server
"::"))
116 (list 'nnspool
(system-name)))
117 ((string-match "^:" gnus-nntp-server
)
118 (list 'nnmh gnus-nntp-server
119 (list 'nnmh-directory
120 (file-name-as-directory
122 (substring gnus-nntp-server
1) "~/")))
123 (list 'nnmh-get-new-mail nil
)))
125 (list 'nntp gnus-nntp-server
)))))
127 (setq how
(car gnus-select-method
))
131 (gnus-message 5 "Looking up local news spool..."))
134 (gnus-message 5 "Looking up mh spool..."))
137 (setq gnus-current-select-method gnus-select-method
)
138 (gnus-run-hooks 'gnus-open-server-hook
)
140 ;; Partially validate agent covered methods now that the
141 ;; gnus-select-method is known.
144 ;; NOTE: This is here for one purpose only. By validating
145 ;; the current select method, it converts the old 5.10.3,
146 ;; and earlier, format to the current format. That enables
147 ;; the agent code within gnus-open-server to function
149 (gnus-agent-read-servers-validate-native gnus-select-method
))
152 ;; gnus-open-server-hook might have opened it
153 (gnus-server-opened gnus-select-method
)
154 (gnus-open-server gnus-select-method
)
158 "%s (%s) open error: '%s'. Continue? "
159 (car gnus-select-method
) (cadr gnus-select-method
)
160 (gnus-status-message gnus-select-method
)))
161 (gnus-error 1 "Couldn't open server on %s"
162 (nth 1 gnus-select-method
))))))
164 (defun gnus-check-group (group)
165 "Try to make sure that the server where GROUP exists is alive."
166 (let ((method (gnus-find-method-for-group group
)))
167 (or (gnus-server-opened method
)
168 (gnus-open-server method
))))
170 (defun gnus-check-server (&optional method silent
)
171 "Check whether the connection to METHOD is down.
172 If METHOD is nil, use `gnus-select-method'.
173 If it is down, start it up (again)."
174 (let ((method (or method gnus-select-method
))
176 ;; Transform virtual server names into select methods.
177 (when (stringp method
)
178 (setq method
(gnus-server-to-method method
)))
179 (if (gnus-server-opened method
)
180 ;; The stream is already opened.
184 (gnus-message 5 "Opening %s server%s..." (car method
)
185 (if (equal (nth 1 method
) "") ""
186 (format " on %s" (nth 1 method
)))))
187 (gnus-run-hooks 'gnus-open-server-hook
)
189 (setq result
(gnus-open-server method
))
193 "Opening %s server%s...%s" (car method
)
194 (if (equal (nth 1 method
) "") ""
195 (format " on %s" (nth 1 method
)))
199 (nnheader-get-report-string (car method
))))))))))
201 (defun gnus-get-function (method function
&optional noerror
)
202 "Return a function symbol based on METHOD and FUNCTION."
203 ;; Translate server names into methods.
205 (error "Attempted use of a nil select method"))
206 (when (stringp method
)
207 (setq method
(gnus-server-to-method method
)))
208 ;; Check cache of constructed names.
209 (let* ((method-sym (if gnus-agent
210 (inline (gnus-agent-get-function method
))
212 (method-fns (get method-sym
'gnus-method-functions
))
213 (func (let ((method-fnlist-elt (assq function method-fns
)))
214 (unless method-fnlist-elt
215 (setq method-fnlist-elt
217 (intern (format "%s-%s" method-sym function
))))
218 (put method-sym
'gnus-method-functions
219 (cons method-fnlist-elt method-fns
)))
220 (cdr method-fnlist-elt
))))
221 ;; Maybe complain if there is no function.
222 (unless (fboundp func
)
224 (error "Trying to require a method that doesn't exist"))
225 (require (car method
))
226 (when (not (fboundp func
))
229 (error "No such function: %s" func
))))
234 ;;; Interface functions to the backends.
237 (defun gnus-method-denied-p (method)
238 (eq (nth 1 (assoc method gnus-opened-servers
))
241 (defvar gnus-backend-trace t
)
243 (defun gnus-open-server (gnus-command-method)
244 "Open a connection to GNUS-COMMAND-METHOD."
245 (when (stringp gnus-command-method
)
246 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
247 (when gnus-backend-trace
248 (with-current-buffer (get-buffer-create "*gnus trace*")
249 (buffer-disable-undo)
250 (goto-char (point-max))
251 (insert (format-time-string "%H:%M:%S")
252 (format " %S\n" gnus-command-method
))))
253 (let ((elem (assoc gnus-command-method gnus-opened-servers
))
254 (server (gnus-method-to-server-name gnus-command-method
)))
255 ;; If this method was previously denied, we just return nil.
256 (if (eq (nth 1 elem
) 'denied
)
258 (gnus-message 1 "Denied server %s" server
)
261 (let* ((open-server-function
262 (gnus-get-function gnus-command-method
'open-server
))
265 (funcall open-server-function
266 (nth 1 gnus-command-method
)
267 (nthcdr 2 gnus-command-method
))
269 (gnus-message 1 "Unable to open server %s due to: %s"
270 server
(error-message-string err
))
275 (gnus-message 1 "Quit trying to open server %s" server
))
278 ;; If this hasn't been opened before, we add it to the list.
280 (setq elem
(list gnus-command-method nil
)
281 gnus-opened-servers
(cons elem gnus-opened-servers
)))
282 ;; Set the status of this server.
286 (if (eq open-server-function
#'nnagent-open-server
)
287 ;; The agent's backend has a "special" status
291 (gnus-agent-method-p gnus-command-method
))
293 (gnus-server-unopen-status
294 ;; Set the server's status to the unopen
295 ;; status. If that status is offline,
296 ;; recurse to open the agent's backend.
297 (setq open-offline
(eq gnus-server-unopen-status
'offline
))
298 gnus-server-unopen-status
)
299 ((not gnus-batch-mode
)
300 (setq open-offline t
)
303 ;; This agentized server was still denied
306 ;; This unagentized server must be denied
309 ;; NOTE: I MUST set the server's status to offline before this
310 ;; recursive call as this status will drive the
311 ;; gnus-get-function (called above) to return the agent's
314 ;; Recursively open this offline server to perform the
315 ;; open-server function of the agent's backend.
316 (let ((gnus-server-unopen-status 'denied
))
317 ;; Bind gnus-server-unopen-status to avoid recursively
318 ;; prompting with "go offline?". This is only a concern
319 ;; when the agent's backend fails to open the server.
320 (gnus-open-server gnus-command-method
))
321 (when (and (eq (cadr elem
) 'ok
) gnus-agent
322 (gnus-agent-method-p gnus-command-method
))
324 (gnus-agent-possibly-synchronize-flags-server
325 gnus-command-method
)))
328 (defun gnus-close-server (gnus-command-method)
329 "Close the connection to GNUS-COMMAND-METHOD."
330 (when (stringp gnus-command-method
)
331 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
332 (funcall (gnus-get-function gnus-command-method
'close-server
)
333 (nth 1 gnus-command-method
)))
335 (defun gnus-request-list (gnus-command-method)
336 "Request the active file from GNUS-COMMAND-METHOD."
337 (when (stringp gnus-command-method
)
338 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
339 (funcall (gnus-get-function gnus-command-method
'request-list
)
340 (nth 1 gnus-command-method
)))
342 (defun gnus-finish-retrieve-group-infos (gnus-command-method infos data
)
343 "Read and update infos from GNUS-COMMAND-METHOD."
344 (when (stringp gnus-command-method
)
345 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
346 (funcall (gnus-get-function gnus-command-method
'finish-retrieve-group-infos
)
347 (nth 1 gnus-command-method
)
350 (defun gnus-retrieve-group-data-early (gnus-command-method infos
)
351 "Start early async retrival of data from GNUS-COMMAND-METHOD."
352 (when (stringp gnus-command-method
)
353 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
354 (funcall (gnus-get-function gnus-command-method
'retrieve-group-data-early
)
355 (nth 1 gnus-command-method
)
358 (defun gnus-request-list-newsgroups (gnus-command-method)
359 "Request the newsgroups file from GNUS-COMMAND-METHOD."
360 (when (stringp gnus-command-method
)
361 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
362 (funcall (gnus-get-function gnus-command-method
'request-list-newsgroups
)
363 (nth 1 gnus-command-method
)))
365 (defun gnus-request-newgroups (date gnus-command-method
)
366 "Request all new groups since DATE from GNUS-COMMAND-METHOD."
367 (when (stringp gnus-command-method
)
368 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
369 (let ((func (gnus-get-function gnus-command-method
'request-newgroups t
)))
371 (funcall func date
(nth 1 gnus-command-method
)))))
373 (defun gnus-request-regenerate (gnus-command-method)
374 "Request a data generation 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
'request-regenerate
)
378 (nth 1 gnus-command-method
)))
380 (defun gnus-request-compact-group (group)
381 (let* ((method (gnus-find-method-for-group group
))
382 (gnus-command-method method
)
384 (funcall (gnus-get-function gnus-command-method
385 'request-compact-group
)
386 (gnus-group-real-name group
)
387 (nth 1 gnus-command-method
) t
)))
390 (defun gnus-request-compact (gnus-command-method)
391 "Request groups compaction from GNUS-COMMAND-METHOD."
392 (when (stringp gnus-command-method
)
393 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
394 (funcall (gnus-get-function gnus-command-method
'request-compact
)
395 (nth 1 gnus-command-method
)))
397 (defun gnus-request-group (group &optional dont-check gnus-command-method info
)
398 "Request GROUP. If DONT-CHECK, no information is required."
399 (let ((gnus-command-method
400 (or gnus-command-method
(inline (gnus-find-method-for-group group
)))))
401 (when (stringp gnus-command-method
)
402 (setq gnus-command-method
403 (inline (gnus-server-to-method gnus-command-method
))))
404 (funcall (inline (gnus-get-function gnus-command-method
'request-group
))
405 (gnus-group-real-name group
) (nth 1 gnus-command-method
)
409 (defun gnus-list-active-group (group)
410 "Request active information on GROUP."
411 (let ((gnus-command-method (gnus-find-method-for-group group
))
412 (func 'list-active-group
))
413 (when (gnus-check-backend-function func group
)
414 (funcall (gnus-get-function gnus-command-method func
)
415 (gnus-group-real-name group
) (nth 1 gnus-command-method
)))))
417 (defun gnus-request-group-description (group)
418 "Request a description of GROUP."
419 (let ((gnus-command-method (gnus-find-method-for-group group
))
420 (func 'request-group-description
))
421 (when (gnus-check-backend-function func group
)
422 (funcall (gnus-get-function gnus-command-method func
)
423 (gnus-group-real-name group
) (nth 1 gnus-command-method
)))))
425 (defun gnus-request-group-articles (group)
426 "Request a list of existing articles in GROUP."
427 (let ((gnus-command-method (gnus-find-method-for-group group
))
428 (func 'request-group-articles
))
429 (when (gnus-check-backend-function func group
)
430 (funcall (gnus-get-function gnus-command-method func
)
431 (gnus-group-real-name group
) (nth 1 gnus-command-method
)))))
433 (defun gnus-close-group (group)
434 "Request the GROUP be closed."
435 (let ((gnus-command-method (inline (gnus-find-method-for-group group
))))
436 (funcall (gnus-get-function gnus-command-method
'close-group
)
437 (gnus-group-real-name group
) (nth 1 gnus-command-method
))))
439 (defun gnus-retrieve-headers (articles group
&optional fetch-old
)
440 "Request headers for ARTICLES in GROUP.
441 If FETCH-OLD, retrieve all headers (or some subset thereof) in the group."
442 (let ((gnus-command-method (gnus-find-method-for-group group
)))
444 ((and gnus-use-cache
(numberp (car articles
)))
445 (gnus-cache-retrieve-headers articles group fetch-old
))
446 ((and gnus-agent
(gnus-online gnus-command-method
)
447 (gnus-agent-method-p gnus-command-method
))
448 (gnus-agent-retrieve-headers articles group fetch-old
))
450 (funcall (gnus-get-function gnus-command-method
'retrieve-headers
)
451 articles
(gnus-group-real-name group
)
452 (nth 1 gnus-command-method
) fetch-old
)))))
454 (defun gnus-retrieve-articles (articles group
)
455 "Request ARTICLES in GROUP."
456 (let ((gnus-command-method (gnus-find-method-for-group group
)))
457 (funcall (gnus-get-function gnus-command-method
'retrieve-articles
)
458 articles
(gnus-group-real-name group
)
459 (nth 1 gnus-command-method
))))
461 (defun gnus-retrieve-groups (groups gnus-command-method
)
462 "Request active information on GROUPS from GNUS-COMMAND-METHOD."
463 (when (stringp gnus-command-method
)
464 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
465 (funcall (gnus-get-function gnus-command-method
'retrieve-groups
)
466 groups
(nth 1 gnus-command-method
)))
468 (defun gnus-request-type (group &optional article
)
469 "Return the type (`post' or `mail') of GROUP (and ARTICLE)."
470 (let ((gnus-command-method (gnus-find-method-for-group group
)))
471 (if (not (gnus-check-backend-function
472 'request-type
(car gnus-command-method
)))
474 (funcall (gnus-get-function gnus-command-method
'request-type
)
475 (gnus-group-real-name group
) article
))))
477 (defun gnus-request-update-group-status (group status
)
478 "Change the status of a group.
479 Valid statuses include `subscribe' and `unsubscribe'."
480 (let ((gnus-command-method (gnus-find-method-for-group group
)))
481 (if (not (gnus-check-backend-function
482 'request-update-group-status
(car gnus-command-method
)))
485 (gnus-get-function gnus-command-method
'request-update-group-status
)
486 (gnus-group-real-name group
) status
487 (nth 1 gnus-command-method
)))))
489 (defun gnus-request-set-mark (group action
)
490 "Set marks on articles in the back end."
491 (let ((gnus-command-method (gnus-find-method-for-group group
)))
492 (if (not (gnus-check-backend-function
493 'request-set-mark
(car gnus-command-method
)))
495 (funcall (gnus-get-function gnus-command-method
'request-set-mark
)
496 (gnus-group-real-name group
) action
497 (nth 1 gnus-command-method
))
498 (gnus-run-hook-with-args gnus-after-set-mark-hook group action
))))
500 (defun gnus-request-update-mark (group article mark
)
501 "Allow the back end to change the mark the user tries to put on an article."
502 (let ((gnus-command-method (gnus-find-method-for-group group
)))
503 (if (not (gnus-check-backend-function
504 'request-update-mark
(car gnus-command-method
)))
506 (gnus-run-hook-with-args gnus-before-update-mark-hook group article mark
)
507 (funcall (gnus-get-function gnus-command-method
'request-update-mark
)
508 (gnus-group-real-name group
) article mark
))))
510 (defun gnus-request-article (article group
&optional buffer
)
511 "Request the ARTICLE in GROUP.
512 ARTICLE can either be an article number or an article Message-ID.
513 If BUFFER, insert the article in that group."
514 (let ((gnus-command-method (gnus-find-method-for-group group
)))
515 (funcall (gnus-get-function gnus-command-method
'request-article
)
516 article
(gnus-group-real-name group
)
517 (nth 1 gnus-command-method
) buffer
)))
519 (defun gnus-request-thread (header group
)
520 "Request the headers in the thread containing the article specified by HEADER."
521 (let ((gnus-command-method (gnus-find-method-for-group group
)))
522 (funcall (gnus-get-function gnus-command-method
'request-thread
)
524 (gnus-group-real-name group
))))
526 (defun gnus-warp-to-article ()
527 "Warps from an article in a virtual group to the article in its
528 real group. Does nothing on a real group."
530 (let ((gnus-command-method
531 (gnus-find-method-for-group gnus-newsgroup-name
)))
532 (when (gnus-check-backend-function
533 'warp-to-article
(car gnus-command-method
))
534 (funcall (gnus-get-function gnus-command-method
'warp-to-article
)))))
536 (defun gnus-request-head (article group
)
537 "Request the head of ARTICLE in GROUP."
538 (let* ((gnus-command-method (gnus-find-method-for-group group
))
539 (head (gnus-get-function gnus-command-method
'request-head t
))
545 (gnus-cache-request-article article group
))
546 (setq res
(cons group article
)
548 ;; Check the agent cache.
549 ((gnus-agent-request-article article group
)
550 (setq res
(cons group article
)
552 ;; Use `head' function.
554 (setq res
(funcall head article
(gnus-group-real-name group
)
555 (nth 1 gnus-command-method
))))
556 ;; Use `article' function.
558 (setq res
(gnus-request-article article group
)
561 (with-current-buffer nntp-server-buffer
562 (goto-char (point-min))
563 (when (search-forward "\n\n" nil t
)
564 (delete-region (1- (point)) (point-max)))
565 (nnheader-fold-continuation-lines)))
568 (defun gnus-request-body (article group
)
569 "Request the body of ARTICLE in GROUP."
570 (let* ((gnus-command-method (gnus-find-method-for-group group
))
571 (head (gnus-get-function gnus-command-method
'request-body t
))
577 (gnus-cache-request-article article group
))
578 (setq res
(cons group article
)
580 ;; Check the agent cache.
581 ((gnus-agent-request-article article group
)
582 (setq res
(cons group article
)
584 ;; Use `head' function.
586 (setq res
(funcall head article
(gnus-group-real-name group
)
587 (nth 1 gnus-command-method
))))
588 ;; Use `article' function.
590 (setq res
(gnus-request-article article group
)
593 (with-current-buffer nntp-server-buffer
594 (goto-char (point-min))
595 (when (search-forward "\n\n" nil t
)
596 (delete-region (point-min) (1- (point))))))
599 (defun gnus-request-post (gnus-command-method)
600 "Post the current buffer using GNUS-COMMAND-METHOD."
601 (when (stringp gnus-command-method
)
602 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
603 (funcall (gnus-get-function gnus-command-method
'request-post
)
604 (nth 1 gnus-command-method
)))
606 (defun gnus-request-expunge-group (group gnus-command-method
)
607 "Expunge GROUP, which is removing articles that have been marked as deleted."
608 (when (stringp gnus-command-method
)
609 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
610 (funcall (gnus-get-function gnus-command-method
'request-expunge-group
)
611 (gnus-group-real-name group
)
612 (nth 1 gnus-command-method
)))
614 (defun gnus-request-scan (group gnus-command-method
)
615 "Request a SCAN being performed in GROUP from GNUS-COMMAND-METHOD.
616 If GROUP is nil, all groups on GNUS-COMMAND-METHOD are scanned."
617 (let ((gnus-command-method
618 (if group
(gnus-find-method-for-group group
) gnus-command-method
))
619 (gnus-inhibit-demon t
)
620 (mail-source-plugged gnus-plugged
))
621 (when (or gnus-plugged
622 (not (gnus-agent-method-p gnus-command-method
)))
623 (setq gnus-internal-registry-spool-current-method gnus-command-method
)
624 (funcall (gnus-get-function gnus-command-method
'request-scan
)
625 (and group
(gnus-group-real-name group
))
626 (nth 1 gnus-command-method
)))))
628 (defun gnus-request-update-info (info gnus-command-method
)
629 (when (gnus-check-backend-function
630 'request-update-info
(car gnus-command-method
))
631 (when (stringp gnus-command-method
)
632 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
633 (funcall (gnus-get-function gnus-command-method
'request-update-info
)
634 (gnus-group-real-name (gnus-info-group info
)) info
635 (nth 1 gnus-command-method
))))
637 (defsubst gnus-request-marks
(info gnus-command-method
)
638 "Request that GNUS-COMMAND-METHOD update INFO."
639 (when (stringp gnus-command-method
)
640 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
641 (when (gnus-check-backend-function
642 'request-marks
(car gnus-command-method
))
643 (let ((group (gnus-info-group info
)))
644 (and (funcall (gnus-get-function gnus-command-method
'request-marks
)
645 (gnus-group-real-name group
)
646 info
(nth 1 gnus-command-method
))
647 ;; If the minimum article number is greater than 1, then all
648 ;; smaller article numbers are known not to exist; we'll
649 ;; artificially add those to the 'read range.
650 (let* ((active (gnus-active group
))
653 (let* ((range (if (= min
2) 1 (cons 1 (1- min
))))
654 (read (gnus-info-read info
))
655 (new-read (gnus-range-add read
(list range
))))
656 (gnus-info-set-read info new-read
)))
659 (defun gnus-request-expire-articles (articles group
&optional force
)
660 (let* ((gnus-command-method (gnus-find-method-for-group group
))
661 (gnus-inhibit-demon t
)
664 (gnus-get-function gnus-command-method
'request-expire-articles
)
665 articles
(gnus-group-real-name group
) (nth 1 gnus-command-method
)
667 (when (and gnus-agent
668 (gnus-agent-method-p gnus-command-method
))
669 (let ((expired-articles (gnus-sorted-difference articles not-deleted
)))
670 (when expired-articles
671 (gnus-agent-expire expired-articles group
'force
))))
674 (defun gnus-request-move-article (article group server accept-function
675 &optional last move-is-internal
)
676 (let* ((gnus-command-method (gnus-find-method-for-group group
))
677 (result (funcall (gnus-get-function gnus-command-method
678 'request-move-article
)
679 article
(gnus-group-real-name group
)
680 (nth 1 gnus-command-method
) accept-function
681 last move-is-internal
)))
682 (when (and result gnus-agent
683 (gnus-agent-method-p gnus-command-method
))
684 (gnus-agent-unfetch-articles group
(list article
)))
687 (defun gnus-request-accept-article (group &optional gnus-command-method last
689 ;; Make sure there's a newline at the end of the article.
690 (when (stringp gnus-command-method
)
691 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
692 (when (and (not gnus-command-method
)
694 (setq gnus-command-method
(or (gnus-find-method-for-group group
)
695 (gnus-group-name-to-method group
))))
696 (goto-char (point-max))
700 (let ((message-options message-options
))
701 (message-options-set-recipient)
703 (message-narrow-to-head)
704 (let ((mail-parse-charset message-default-charset
))
705 (mail-encode-encoded-word-buffer)))
706 (message-encode-message-body)))
707 (let ((gnus-command-method (or gnus-command-method
708 (gnus-find-method-for-group group
)))
711 (gnus-get-function gnus-command-method
'request-accept-article
)
712 (if (stringp group
) (gnus-group-real-name group
) group
)
713 (cadr gnus-command-method
)
715 (when (and gnus-agent
716 (gnus-agent-method-p gnus-command-method
)
718 (gnus-agent-regenerate-group group
(list (cdr result
))))
721 (defun gnus-request-replace-article (article group buffer
&optional no-encode
)
723 (let ((message-options message-options
))
724 (message-options-set-recipient)
726 (message-narrow-to-head)
727 (let ((mail-parse-charset message-default-charset
))
728 (mail-encode-encoded-word-buffer)))
729 (message-encode-message-body)))
730 (let* ((func (car (gnus-group-name-to-method group
)))
731 (result (funcall (intern (format "%s-request-replace-article" func
))
732 article
(gnus-group-real-name group
) buffer
)))
733 (when (and gnus-agent
(gnus-agent-method-p gnus-command-method
))
734 (gnus-agent-regenerate-group group
(list article
)))
737 (defun gnus-request-associate-buffer (group)
738 (let ((gnus-command-method (gnus-find-method-for-group group
)))
739 (funcall (gnus-get-function gnus-command-method
'request-associate-buffer
)
740 (gnus-group-real-name group
))))
742 (defun gnus-request-restore-buffer (article group
)
743 "Request a new buffer restored to the state of ARTICLE."
744 (let ((gnus-command-method (gnus-find-method-for-group group
)))
745 (funcall (gnus-get-function gnus-command-method
'request-restore-buffer
)
746 article
(gnus-group-real-name group
)
747 (nth 1 gnus-command-method
))))
749 (defun gnus-request-create-group (group &optional gnus-command-method args
)
750 (when (stringp gnus-command-method
)
751 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
752 (let ((gnus-command-method
753 (or gnus-command-method
(gnus-find-method-for-group group
))))
754 (funcall (gnus-get-function gnus-command-method
'request-create-group
)
755 (gnus-group-real-name group
) (nth 1 gnus-command-method
) args
)))
757 (defun gnus-request-delete-group (group &optional force
)
758 (let* ((gnus-command-method (gnus-find-method-for-group group
))
760 (funcall (gnus-get-function gnus-command-method
'request-delete-group
)
761 (gnus-group-real-name group
) force
(nth 1 gnus-command-method
))))
763 (gnus-cache-delete-group group
)
764 (gnus-agent-delete-group group
))
767 (defun gnus-request-rename-group (group new-name
)
768 (let* ((gnus-command-method (gnus-find-method-for-group group
))
770 (funcall (gnus-get-function gnus-command-method
'request-rename-group
)
771 (gnus-group-real-name group
)
772 (gnus-group-real-name new-name
) (nth 1 gnus-command-method
))))
774 (gnus-cache-rename-group group new-name
)
775 (gnus-agent-rename-group group new-name
))
778 (defun gnus-close-backends ()
779 ;; Send a close request to all backends that support such a request.
780 (let ((methods gnus-valid-select-methods
)
781 (gnus-inhibit-demon t
)
782 func gnus-command-method
)
783 (while (setq gnus-command-method
(pop methods
))
784 (when (fboundp (setq func
(intern
785 (concat (car gnus-command-method
)
789 (defun gnus-asynchronous-p (gnus-command-method)
790 (let ((func (gnus-get-function gnus-command-method
'asynchronous-p t
)))
794 (defun gnus-remove-denial (gnus-command-method)
795 (when (stringp gnus-command-method
)
796 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
797 (let* ((elem (assoc gnus-command-method gnus-opened-servers
))
798 (status (cadr elem
)))
799 ;; If this hasn't been opened before, we add it to the list.
800 (when (eq status
'denied
)
801 ;; Set the status of this server.
802 (setcar (cdr elem
) 'closed
))))
806 ;;; gnus-int.el ends here