1 ;;; nnagent.el --- offline backend for Gnus
3 ;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007 Free Software Foundation, Inc.
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Keywords: news, mail
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
32 (eval-when-compile (require 'cl
))
41 (defconst nnagent-version
"nnagent 1.0")
43 (defvoo nnagent-directory nil
47 (defvoo nnagent-active-file nil
51 (defvoo nnagent-newsgroups-file nil
55 (defvoo nnagent-get-new-mail nil
59 ;;; Interface functions.
61 (nnoo-define-basics nnagent
)
63 (defun nnagent-server (server)
64 (and server
(format "%s+%s" (car gnus-command-method
) server
)))
66 (deffoo nnagent-open-server
(server &optional defs
)
68 `((nnagent-directory ,(gnus-agent-directory))
69 (nnagent-active-file ,(gnus-agent-lib-file "active"))
70 (nnagent-newsgroups-file ,(gnus-agent-lib-file "newsgroups"))
71 (nnagent-get-new-mail nil
)))
72 (nnoo-change-server 'nnagent
73 (nnagent-server server
)
75 (let ((dir (gnus-agent-directory))
78 ((not (condition-case arg
80 (ftp-error (setq err
(format "%s" arg
)))))
81 (nnagent-close-server)
84 (format "No such file or directory: %s" dir
))))
85 ((not (file-directory-p (file-truename dir
)))
86 (nnagent-close-server)
87 (nnheader-report 'nnagent
"Not a directory: %s" dir
))
89 (nnheader-report 'nnagent
"Opened server %s using directory %s"
93 (deffoo nnagent-retrieve-groups
(groups &optional server
)
96 ((file-exists-p (gnus-agent-lib-file "groups"))
97 (nnmail-find-file (gnus-agent-lib-file "groups"))
99 ((file-exists-p (gnus-agent-lib-file "active"))
100 (nnmail-find-file (gnus-agent-lib-file "active"))
104 (defun nnagent-request-type (group article
)
105 (unless (stringp article
)
106 (let ((gnus-agent nil
))
107 (if (not (gnus-check-backend-function
108 'request-type
(car gnus-command-method
)))
110 (funcall (gnus-get-function gnus-command-method
'request-type
)
111 (gnus-group-real-name group
) article
)))))
113 (deffoo nnagent-request-newgroups
(date server
)
116 (deffoo nnagent-request-update-info
(group info
&optional server
)
119 (deffoo nnagent-request-post
(&optional server
)
120 (gnus-agent-insert-meta-information 'news gnus-command-method
)
121 (gnus-request-accept-article "nndraft:queue" nil t t
))
123 (deffoo nnagent-request-set-mark
(group action server
)
125 (insert "(gnus-agent-synchronize-group-flags \""
130 (gnus-method-to-server gnus-command-method
)
133 (append-to-file (point-min) (point-max) (gnus-agent-lib-file "flags")))
136 (deffoo nnagent-retrieve-headers
(articles &optional group server fetch-old
)
137 (let ((file (gnus-agent-article-name ".overview" group
))
140 (gnus-agent-load-alist group
)
141 (setq arts
(gnus-sorted-difference
142 articles
(mapcar 'car gnus-agent-article-alist
)))
143 ;; Assume that articles with smaller numbers than the first one
144 ;; Agent knows are gone.
145 (setq first
(caar gnus-agent-article-alist
))
147 (while (and arts
(< (car arts
) first
))
149 (set-buffer nntp-server-buffer
)
151 (nnheader-insert-nov-file file
(car articles
))
152 (goto-char (point-min))
153 (gnus-parse-without-error
154 (while (and arts
(not (eobp)))
155 (setq n
(read (current-buffer)))
156 (when (> n
(car arts
))
158 (while (and arts
(> n
(car arts
)))
160 "%d\t[Undownloaded article %d]\tGnus Agent\t\t\t\n"
161 (car arts
) (car arts
)))
163 (when (and arts
(= n
(car arts
)))
168 "%d\t[Undownloaded article %d]\tGnus Agent\t\t\t\n"
169 (car arts
) (car arts
)))
172 (not (numberp fetch-old
)))
173 t
; Don't remove anything.
174 (nnheader-nov-delete-outside-range
175 (if fetch-old
(max 1 (- (car articles
) fetch-old
))
177 (car (last articles
)))
181 (deffoo nnagent-request-expire-articles
(articles group
&optional server force
)
184 (deffoo nnagent-request-group
(group &optional server dont-check
)
185 (nnoo-parent-function 'nnagent
'nnml-request-group
186 (list group
(nnagent-server server
) dont-check
)))
188 (deffoo nnagent-close-group
(group &optional server
)
189 (nnoo-parent-function 'nnagent
'nnml-close-group
190 (list group
(nnagent-server server
))))
192 (deffoo nnagent-request-accept-article
(group &optional server last
)
193 (nnoo-parent-function 'nnagent
'nnml-request-accept-article
194 (list group
(nnagent-server server
) last
)))
196 (deffoo nnagent-request-article
(id &optional group server buffer
)
197 (nnoo-parent-function 'nnagent
'nnml-request-article
198 (list id group
(nnagent-server server
) buffer
)))
200 (deffoo nnagent-request-create-group
(group &optional server args
)
201 (nnoo-parent-function 'nnagent
'nnml-request-create-group
202 (list group
(nnagent-server server
) args
)))
204 (deffoo nnagent-request-delete-group
(group &optional force server
)
205 (nnoo-parent-function 'nnagent
'nnml-request-delete-group
206 (list group force
(nnagent-server server
))))
208 (deffoo nnagent-request-list
(&optional server
)
209 (nnoo-parent-function 'nnagent
'nnml-request-list
210 (list (nnagent-server server
))))
212 (deffoo nnagent-request-list-newsgroups
(&optional server
)
213 (nnoo-parent-function 'nnagent
'nnml-request-list-newsgroups
214 (list (nnagent-server server
))))
216 (deffoo nnagent-request-move-article
217 (article group server accept-form
&optional last
)
218 (nnoo-parent-function 'nnagent
'nnml-request-move-article
219 (list article group
(nnagent-server server
)
222 (deffoo nnagent-request-rename-group
(group new-name
&optional server
)
223 (nnoo-parent-function 'nnagent
'nnml-request-rename-group
224 (list group new-name
(nnagent-server server
))))
226 (deffoo nnagent-request-scan
(&optional group server
)
227 (nnoo-parent-function 'nnagent
'nnml-request-scan
228 (list group
(nnagent-server server
))))
230 (deffoo nnagent-set-status
(article name value
&optional group server
)
231 (nnoo-parent-function 'nnagent
'nnml-set-status
232 (list article name value group
(nnagent-server server
))))
234 (deffoo nnagent-server-opened
(&optional server
)
235 (nnoo-parent-function 'nnagent
'nnml-server-opened
236 (list (nnagent-server server
))))
238 (deffoo nnagent-status-message
(&optional server
)
239 (nnoo-parent-function 'nnagent
'nnml-status-message
240 (list (nnagent-server server
))))
242 (deffoo nnagent-request-regenerate
(server)
243 (nnoo-parent-function 'nnagent
'nnml-request-regenerate
244 (list (nnagent-server server
))))
246 ;; Use nnml functions for just about everything.
251 ;;; Internal functions.
255 ;;; arch-tag: af710b77-f816-4969-af31-6fd94fb42245
256 ;;; nnagent.el ends here