1 ;;; nnagent.el --- offline backend for Gnus
3 ;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008 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 3, 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
)
124 (mm-with-unibyte-buffer
125 (insert "(gnus-agent-synchronize-group-flags \""
130 (gnus-method-to-server gnus-command-method
)
133 (let ((coding-system-for-write nnheader-file-coding-system
))
134 (write-region (point-min) (point-max) (gnus-agent-lib-file "flags")
136 ;; Also set the marks for the original back end that keeps marks in
138 (let ((gnus-agent nil
))
139 (when (and (memq (car gnus-command-method
) '(nntp))
140 (gnus-check-backend-function 'request-set-mark
141 (car gnus-command-method
)))
142 (funcall (gnus-get-function gnus-command-method
'request-set-mark
)
143 group action server
)))
146 (deffoo nnagent-retrieve-headers
(articles &optional group server fetch-old
)
147 (let ((file (gnus-agent-article-name ".overview" group
))
150 (gnus-agent-load-alist group
)
151 (setq arts
(gnus-sorted-difference
152 articles
(mapcar 'car gnus-agent-article-alist
)))
153 ;; Assume that articles with smaller numbers than the first one
154 ;; Agent knows are gone.
155 (setq first
(caar gnus-agent-article-alist
))
157 (while (and arts
(< (car arts
) first
))
159 (set-buffer nntp-server-buffer
)
161 (let ((file-name-coding-system nnmail-pathname-coding-system
))
162 (nnheader-insert-nov-file file
(car articles
)))
163 (goto-char (point-min))
164 (gnus-parse-without-error
165 (while (and arts
(not (eobp)))
166 (setq n
(read (current-buffer)))
167 (when (> n
(car arts
))
169 (while (and arts
(> n
(car arts
)))
171 "%d\t[Undownloaded article %d]\tGnus Agent\t\t\t\n"
172 (car arts
) (car arts
)))
174 (when (and arts
(= n
(car arts
)))
179 "%d\t[Undownloaded article %d]\tGnus Agent\t\t\t\n"
180 (car arts
) (car arts
)))
183 (not (numberp fetch-old
)))
184 t
; Don't remove anything.
185 (nnheader-nov-delete-outside-range
186 (if fetch-old
(max 1 (- (car articles
) fetch-old
))
188 (car (last articles
)))
192 (deffoo nnagent-request-expire-articles
(articles group
&optional server force
)
195 (deffoo nnagent-request-group
(group &optional server dont-check
)
196 (nnoo-parent-function 'nnagent
'nnml-request-group
197 (list group
(nnagent-server server
) dont-check
)))
199 (deffoo nnagent-close-group
(group &optional server
)
200 (nnoo-parent-function 'nnagent
'nnml-close-group
201 (list group
(nnagent-server server
))))
203 (deffoo nnagent-request-accept-article
(group &optional server last
)
204 (nnoo-parent-function 'nnagent
'nnml-request-accept-article
205 (list group
(nnagent-server server
) last
)))
207 (deffoo nnagent-request-article
(id &optional group server buffer
)
208 (nnoo-parent-function 'nnagent
'nnml-request-article
209 (list id group
(nnagent-server server
) buffer
)))
211 (deffoo nnagent-request-create-group
(group &optional server args
)
212 (nnoo-parent-function 'nnagent
'nnml-request-create-group
213 (list group
(nnagent-server server
) args
)))
215 (deffoo nnagent-request-delete-group
(group &optional force server
)
216 (nnoo-parent-function 'nnagent
'nnml-request-delete-group
217 (list group force
(nnagent-server server
))))
219 (deffoo nnagent-request-list
(&optional server
)
220 (nnoo-parent-function 'nnagent
'nnml-request-list
221 (list (nnagent-server server
))))
223 (deffoo nnagent-request-list-newsgroups
(&optional server
)
224 (nnoo-parent-function 'nnagent
'nnml-request-list-newsgroups
225 (list (nnagent-server server
))))
227 (deffoo nnagent-request-move-article
228 (article group server accept-form
&optional last move-is-internal
)
229 (nnoo-parent-function 'nnagent
'nnml-request-move-article
230 (list article group
(nnagent-server server
)
231 accept-form last move-is-internal
)))
233 (deffoo nnagent-request-rename-group
(group new-name
&optional server
)
234 (nnoo-parent-function 'nnagent
'nnml-request-rename-group
235 (list group new-name
(nnagent-server server
))))
237 (deffoo nnagent-request-scan
(&optional group server
)
238 (nnoo-parent-function 'nnagent
'nnml-request-scan
239 (list group
(nnagent-server server
))))
241 (deffoo nnagent-set-status
(article name value
&optional group server
)
242 (nnoo-parent-function 'nnagent
'nnml-set-status
243 (list article name value group
(nnagent-server server
))))
245 (deffoo nnagent-server-opened
(&optional server
)
246 (nnoo-parent-function 'nnagent
'nnml-server-opened
247 (list (nnagent-server server
))))
249 (deffoo nnagent-status-message
(&optional server
)
250 (nnoo-parent-function 'nnagent
'nnml-status-message
251 (list (nnagent-server server
))))
253 (deffoo nnagent-request-regenerate
(server)
254 (nnoo-parent-function 'nnagent
'nnml-request-regenerate
255 (list (nnagent-server server
))))
257 ;; Use nnml functions for just about everything.
262 ;;; Internal functions.
266 ;; arch-tag: af710b77-f816-4969-af31-6fd94fb42245
267 ;;; nnagent.el ends here