1 ;;; nnagent.el --- offline backend for Gnus
3 ;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 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 of the License, or
14 ;; (at your option) any later version.
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. If not, see <http://www.gnu.org/licenses/>.
30 (eval-when-compile (require 'cl
))
39 (defconst nnagent-version
"nnagent 1.0")
41 (defvoo nnagent-directory nil
45 (defvoo nnagent-active-file nil
49 (defvoo nnagent-newsgroups-file nil
53 (defvoo nnagent-get-new-mail nil
57 ;;; Interface functions.
59 (nnoo-define-basics nnagent
)
61 (defun nnagent-server (server)
62 (and server
(format "%s+%s" (car gnus-command-method
) server
)))
64 (deffoo nnagent-open-server
(server &optional defs
)
66 `((nnagent-directory ,(gnus-agent-directory))
67 (nnagent-active-file ,(gnus-agent-lib-file "active"))
68 (nnagent-newsgroups-file ,(gnus-agent-lib-file "newsgroups"))
69 (nnagent-get-new-mail nil
)))
70 (nnoo-change-server 'nnagent
71 (nnagent-server server
)
73 (let ((dir (gnus-agent-directory))
76 ((not (condition-case arg
78 (ftp-error (setq err
(format "%s" arg
)))))
79 (nnagent-close-server)
82 (format "No such file or directory: %s" dir
))))
83 ((not (file-directory-p (file-truename dir
)))
84 (nnagent-close-server)
85 (nnheader-report 'nnagent
"Not a directory: %s" dir
))
87 (nnheader-report 'nnagent
"Opened server %s using directory %s"
91 (deffoo nnagent-retrieve-groups
(groups &optional server
)
94 ((file-exists-p (gnus-agent-lib-file "groups"))
95 (nnmail-find-file (gnus-agent-lib-file "groups"))
97 ((file-exists-p (gnus-agent-lib-file "active"))
98 (nnmail-find-file (gnus-agent-lib-file "active"))
102 (defun nnagent-request-type (group article
)
103 (unless (stringp article
)
104 (let ((gnus-agent nil
))
105 (if (not (gnus-check-backend-function
106 'request-type
(car gnus-command-method
)))
108 (funcall (gnus-get-function gnus-command-method
'request-type
)
109 (gnus-group-real-name group
) article
)))))
111 (deffoo nnagent-request-newgroups
(date server
)
114 (deffoo nnagent-request-update-info
(group info
&optional server
)
117 (deffoo nnagent-request-post
(&optional server
)
118 (gnus-agent-insert-meta-information 'news gnus-command-method
)
119 (gnus-request-accept-article "nndraft:queue" nil t t
))
121 (deffoo nnagent-request-set-mark
(group action server
)
122 (mm-with-unibyte-buffer
123 (insert "(gnus-agent-synchronize-group-flags \""
128 (gnus-method-to-server gnus-command-method
)
131 (let ((coding-system-for-write nnheader-file-coding-system
))
132 (write-region (point-min) (point-max) (gnus-agent-lib-file "flags")
134 ;; Also set the marks for the original back end that keeps marks in
136 (let ((gnus-agent nil
))
137 (when (and (memq (car gnus-command-method
) '(nntp))
138 (gnus-check-backend-function 'request-set-mark
139 (car gnus-command-method
)))
140 (funcall (gnus-get-function gnus-command-method
'request-set-mark
)
141 group action server
)))
144 (deffoo nnagent-retrieve-headers
(articles &optional group server fetch-old
)
145 (let ((file (gnus-agent-article-name ".overview" group
))
148 (gnus-agent-load-alist group
)
149 (setq arts
(gnus-sorted-difference
150 articles
(mapcar 'car gnus-agent-article-alist
)))
151 ;; Assume that articles with smaller numbers than the first one
152 ;; Agent knows are gone.
153 (setq first
(caar gnus-agent-article-alist
))
155 (while (and arts
(< (car arts
) first
))
157 (set-buffer nntp-server-buffer
)
159 (let ((file-name-coding-system nnmail-pathname-coding-system
))
160 (nnheader-insert-nov-file file
(car articles
)))
161 (goto-char (point-min))
162 (gnus-parse-without-error
163 (while (and arts
(not (eobp)))
164 (setq n
(read (current-buffer)))
165 (when (> n
(car arts
))
167 (while (and arts
(> n
(car arts
)))
169 "%d\t[Undownloaded article %d]\tGnus Agent\t\t\t\n"
170 (car arts
) (car arts
)))
172 (when (and arts
(= n
(car arts
)))
177 "%d\t[Undownloaded article %d]\tGnus Agent\t\t\t\n"
178 (car arts
) (car arts
)))
181 (not (numberp fetch-old
)))
182 t
; Don't remove anything.
183 (nnheader-nov-delete-outside-range
184 (if fetch-old
(max 1 (- (car articles
) fetch-old
))
186 (car (last articles
)))
190 (deffoo nnagent-request-expire-articles
(articles group
&optional server force
)
193 (deffoo nnagent-request-group
(group &optional server dont-check
)
194 (nnoo-parent-function 'nnagent
'nnml-request-group
195 (list group
(nnagent-server server
) dont-check
)))
197 (deffoo nnagent-close-group
(group &optional server
)
198 (nnoo-parent-function 'nnagent
'nnml-close-group
199 (list group
(nnagent-server server
))))
201 (deffoo nnagent-request-accept-article
(group &optional server last
)
202 (nnoo-parent-function 'nnagent
'nnml-request-accept-article
203 (list group
(nnagent-server server
) last
)))
205 (deffoo nnagent-request-article
(id &optional group server buffer
)
206 (nnoo-parent-function 'nnagent
'nnml-request-article
207 (list id group
(nnagent-server server
) buffer
)))
209 (deffoo nnagent-request-create-group
(group &optional server args
)
210 (nnoo-parent-function 'nnagent
'nnml-request-create-group
211 (list group
(nnagent-server server
) args
)))
213 (deffoo nnagent-request-delete-group
(group &optional force server
)
214 (nnoo-parent-function 'nnagent
'nnml-request-delete-group
215 (list group force
(nnagent-server server
))))
217 (deffoo nnagent-request-list
(&optional server
)
218 (nnoo-parent-function 'nnagent
'nnml-request-list
219 (list (nnagent-server server
))))
221 (deffoo nnagent-request-list-newsgroups
(&optional server
)
222 (nnoo-parent-function 'nnagent
'nnml-request-list-newsgroups
223 (list (nnagent-server server
))))
225 (deffoo nnagent-request-move-article
226 (article group server accept-form
&optional last move-is-internal
)
227 (nnoo-parent-function 'nnagent
'nnml-request-move-article
228 (list article group
(nnagent-server server
)
229 accept-form last move-is-internal
)))
231 (deffoo nnagent-request-rename-group
(group new-name
&optional server
)
232 (nnoo-parent-function 'nnagent
'nnml-request-rename-group
233 (list group new-name
(nnagent-server server
))))
235 (deffoo nnagent-request-scan
(&optional group server
)
236 (nnoo-parent-function 'nnagent
'nnml-request-scan
237 (list group
(nnagent-server server
))))
239 (deffoo nnagent-set-status
(article name value
&optional group server
)
240 (nnoo-parent-function 'nnagent
'nnml-set-status
241 (list article name value group
(nnagent-server server
))))
243 (deffoo nnagent-server-opened
(&optional server
)
244 (nnoo-parent-function 'nnagent
'nnml-server-opened
245 (list (nnagent-server server
))))
247 (deffoo nnagent-status-message
(&optional server
)
248 (nnoo-parent-function 'nnagent
'nnml-status-message
249 (list (nnagent-server server
))))
251 (deffoo nnagent-request-regenerate
(server)
252 (nnoo-parent-function 'nnagent
'nnml-request-regenerate
253 (list (nnagent-server server
))))
255 ;; Use nnml functions for just about everything.
260 ;;; Internal functions.
264 ;; arch-tag: af710b77-f816-4969-af31-6fd94fb42245
265 ;;; nnagent.el ends here