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)
520 "Request the headers in the thread containing the article specified by HEADER."
521 (let ((gnus-command-method (gnus-find-method-for-group gnus-newsgroup-name
)))
522 (funcall (gnus-get-function gnus-command-method
'request-thread
)
525 (defun gnus-warp-to-article ()
526 "Warps from an article in a virtual group to the article in its
527 real group. Does nothing on a real group."
529 (let ((gnus-command-method
530 (gnus-find-method-for-group gnus-newsgroup-name
)))
531 (when (gnus-check-backend-function
532 'warp-to-article
(car gnus-command-method
))
533 (funcall (gnus-get-function gnus-command-method
'warp-to-article
)))))
535 (defun gnus-request-head (article group
)
536 "Request the head of ARTICLE in GROUP."
537 (let* ((gnus-command-method (gnus-find-method-for-group group
))
538 (head (gnus-get-function gnus-command-method
'request-head t
))
544 (gnus-cache-request-article article group
))
545 (setq res
(cons group article
)
547 ;; Check the agent cache.
548 ((gnus-agent-request-article article group
)
549 (setq res
(cons group article
)
551 ;; Use `head' function.
553 (setq res
(funcall head article
(gnus-group-real-name group
)
554 (nth 1 gnus-command-method
))))
555 ;; Use `article' function.
557 (setq res
(gnus-request-article article group
)
560 (with-current-buffer nntp-server-buffer
561 (goto-char (point-min))
562 (when (search-forward "\n\n" nil t
)
563 (delete-region (1- (point)) (point-max)))
564 (nnheader-fold-continuation-lines)))
567 (defun gnus-request-body (article group
)
568 "Request the body of ARTICLE in GROUP."
569 (let* ((gnus-command-method (gnus-find-method-for-group group
))
570 (head (gnus-get-function gnus-command-method
'request-body t
))
576 (gnus-cache-request-article article group
))
577 (setq res
(cons group article
)
579 ;; Check the agent cache.
580 ((gnus-agent-request-article article group
)
581 (setq res
(cons group article
)
583 ;; Use `head' function.
585 (setq res
(funcall head article
(gnus-group-real-name group
)
586 (nth 1 gnus-command-method
))))
587 ;; Use `article' function.
589 (setq res
(gnus-request-article article group
)
592 (with-current-buffer nntp-server-buffer
593 (goto-char (point-min))
594 (when (search-forward "\n\n" nil t
)
595 (delete-region (point-min) (1- (point))))))
598 (defun gnus-request-post (gnus-command-method)
599 "Post the current buffer using GNUS-COMMAND-METHOD."
600 (when (stringp gnus-command-method
)
601 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
602 (funcall (gnus-get-function gnus-command-method
'request-post
)
603 (nth 1 gnus-command-method
)))
605 (defun gnus-request-expunge-group (group gnus-command-method
)
606 "Expunge GROUP, which is removing articles that have been marked as deleted."
607 (when (stringp gnus-command-method
)
608 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
609 (funcall (gnus-get-function gnus-command-method
'request-expunge-group
)
610 (gnus-group-real-name group
)
611 (nth 1 gnus-command-method
)))
613 (defun gnus-request-scan (group gnus-command-method
)
614 "Request a SCAN being performed in GROUP from GNUS-COMMAND-METHOD.
615 If GROUP is nil, all groups on GNUS-COMMAND-METHOD are scanned."
616 (let ((gnus-command-method
617 (if group
(gnus-find-method-for-group group
) gnus-command-method
))
618 (gnus-inhibit-demon t
)
619 (mail-source-plugged gnus-plugged
))
620 (when (or gnus-plugged
621 (not (gnus-agent-method-p gnus-command-method
)))
622 (setq gnus-internal-registry-spool-current-method gnus-command-method
)
623 (funcall (gnus-get-function gnus-command-method
'request-scan
)
624 (and group
(gnus-group-real-name group
))
625 (nth 1 gnus-command-method
)))))
627 (defun gnus-request-update-info (info gnus-command-method
)
628 (when (gnus-check-backend-function
629 'request-update-info
(car gnus-command-method
))
630 (when (stringp gnus-command-method
)
631 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
632 (funcall (gnus-get-function gnus-command-method
'request-update-info
)
633 (gnus-group-real-name (gnus-info-group info
)) info
634 (nth 1 gnus-command-method
))))
636 (defsubst gnus-request-marks
(info gnus-command-method
)
637 "Request that GNUS-COMMAND-METHOD update INFO."
638 (when (stringp gnus-command-method
)
639 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
640 (when (gnus-check-backend-function
641 'request-marks
(car gnus-command-method
))
642 (let ((group (gnus-info-group info
)))
643 (and (funcall (gnus-get-function gnus-command-method
'request-marks
)
644 (gnus-group-real-name group
)
645 info
(nth 1 gnus-command-method
))
646 ;; If the minimum article number is greater than 1, then all
647 ;; smaller article numbers are known not to exist; we'll
648 ;; artificially add those to the 'read range.
649 (let* ((active (gnus-active group
))
652 (let* ((range (if (= min
2) 1 (cons 1 (1- min
))))
653 (read (gnus-info-read info
))
654 (new-read (gnus-range-add read
(list range
))))
655 (gnus-info-set-read info new-read
)))
658 (defun gnus-request-expire-articles (articles group
&optional force
)
659 (let* ((gnus-command-method (gnus-find-method-for-group group
))
660 (gnus-inhibit-demon t
)
663 (gnus-get-function gnus-command-method
'request-expire-articles
)
664 articles
(gnus-group-real-name group
) (nth 1 gnus-command-method
)
666 (when (and gnus-agent
667 (gnus-agent-method-p gnus-command-method
))
668 (let ((expired-articles (gnus-sorted-difference articles not-deleted
)))
669 (when expired-articles
670 (gnus-agent-expire expired-articles group
'force
))))
673 (defun gnus-request-move-article (article group server accept-function
674 &optional last move-is-internal
)
675 (let* ((gnus-command-method (gnus-find-method-for-group group
))
676 (result (funcall (gnus-get-function gnus-command-method
677 'request-move-article
)
678 article
(gnus-group-real-name group
)
679 (nth 1 gnus-command-method
) accept-function
680 last move-is-internal
)))
681 (when (and result gnus-agent
682 (gnus-agent-method-p gnus-command-method
))
683 (gnus-agent-unfetch-articles group
(list article
)))
686 (defun gnus-request-accept-article (group &optional gnus-command-method last
688 ;; Make sure there's a newline at the end of the article.
689 (when (stringp gnus-command-method
)
690 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
691 (when (and (not gnus-command-method
)
693 (setq gnus-command-method
(or (gnus-find-method-for-group group
)
694 (gnus-group-name-to-method group
))))
695 (goto-char (point-max))
699 (let ((message-options message-options
))
700 (message-options-set-recipient)
702 (message-narrow-to-head)
703 (let ((mail-parse-charset message-default-charset
))
704 (mail-encode-encoded-word-buffer)))
705 (message-encode-message-body)))
706 (let ((gnus-command-method (or gnus-command-method
707 (gnus-find-method-for-group group
)))
710 (gnus-get-function gnus-command-method
'request-accept-article
)
711 (if (stringp group
) (gnus-group-real-name group
) group
)
712 (cadr gnus-command-method
)
714 (when (and gnus-agent
715 (gnus-agent-method-p gnus-command-method
)
717 (gnus-agent-regenerate-group group
(list (cdr result
))))
720 (defun gnus-request-replace-article (article group buffer
&optional no-encode
)
722 (let ((message-options message-options
))
723 (message-options-set-recipient)
725 (message-narrow-to-head)
726 (let ((mail-parse-charset message-default-charset
))
727 (mail-encode-encoded-word-buffer)))
728 (message-encode-message-body)))
729 (let* ((func (car (gnus-group-name-to-method group
)))
730 (result (funcall (intern (format "%s-request-replace-article" func
))
731 article
(gnus-group-real-name group
) buffer
)))
732 (when (and gnus-agent
(gnus-agent-method-p gnus-command-method
))
733 (gnus-agent-regenerate-group group
(list article
)))
736 (defun gnus-request-associate-buffer (group)
737 (let ((gnus-command-method (gnus-find-method-for-group group
)))
738 (funcall (gnus-get-function gnus-command-method
'request-associate-buffer
)
739 (gnus-group-real-name group
))))
741 (defun gnus-request-restore-buffer (article group
)
742 "Request a new buffer restored to the state of ARTICLE."
743 (let ((gnus-command-method (gnus-find-method-for-group group
)))
744 (funcall (gnus-get-function gnus-command-method
'request-restore-buffer
)
745 article
(gnus-group-real-name group
)
746 (nth 1 gnus-command-method
))))
748 (defun gnus-request-create-group (group &optional gnus-command-method args
)
749 (when (stringp gnus-command-method
)
750 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
751 (let ((gnus-command-method
752 (or gnus-command-method
(gnus-find-method-for-group group
))))
753 (funcall (gnus-get-function gnus-command-method
'request-create-group
)
754 (gnus-group-real-name group
) (nth 1 gnus-command-method
) args
)))
756 (defun gnus-request-delete-group (group &optional force
)
757 (let* ((gnus-command-method (gnus-find-method-for-group group
))
759 (funcall (gnus-get-function gnus-command-method
'request-delete-group
)
760 (gnus-group-real-name group
) force
(nth 1 gnus-command-method
))))
762 (gnus-cache-delete-group group
)
763 (gnus-agent-delete-group group
))
766 (defun gnus-request-rename-group (group new-name
)
767 (let* ((gnus-command-method (gnus-find-method-for-group group
))
769 (funcall (gnus-get-function gnus-command-method
'request-rename-group
)
770 (gnus-group-real-name group
)
771 (gnus-group-real-name new-name
) (nth 1 gnus-command-method
))))
773 (gnus-cache-rename-group group new-name
)
774 (gnus-agent-rename-group group new-name
))
777 (defun gnus-close-backends ()
778 ;; Send a close request to all backends that support such a request.
779 (let ((methods gnus-valid-select-methods
)
780 (gnus-inhibit-demon t
)
781 func gnus-command-method
)
782 (while (setq gnus-command-method
(pop methods
))
783 (when (fboundp (setq func
(intern
784 (concat (car gnus-command-method
)
788 (defun gnus-asynchronous-p (gnus-command-method)
789 (let ((func (gnus-get-function gnus-command-method
'asynchronous-p t
)))
793 (defun gnus-remove-denial (gnus-command-method)
794 (when (stringp gnus-command-method
)
795 (setq gnus-command-method
(gnus-server-to-method gnus-command-method
)))
796 (let* ((elem (assoc gnus-command-method gnus-opened-servers
))
797 (status (cadr elem
)))
798 ;; If this hasn't been opened before, we add it to the list.
799 (when (eq status
'denied
)
800 ;; Set the status of this server.
801 (setcar (cdr elem
) 'closed
))))
805 ;;; gnus-int.el ends here