*** empty log message ***
[emacs.git] / lisp / gnus / nnagent.el
blob8cc48f15f6b87c67c1f0f22ce424d366c5bb3bc7
1 ;;; nnagent.el --- offline backend for Gnus
2 ;; Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; Keywords: news, mail
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
24 ;;; Commentary:
26 ;;; Code:
28 (require 'nnheader)
29 (require 'nnoo)
30 (eval-when-compile (require 'cl))
31 (require 'gnus-agent)
32 (require 'nnml)
34 (nnoo-declare nnagent
35 nnml)
39 (defconst nnagent-version "nnagent 1.0")
41 (defvoo nnagent-directory nil
42 "Internal variable."
43 nnml-directory)
45 (defvoo nnagent-active-file nil
46 "Internal variable."
47 nnml-active-file)
49 (defvoo nnagent-newsgroups-file nil
50 "Internal variable."
51 nnml-newsgroups-file)
53 (defvoo nnagent-get-new-mail nil
54 "Internal variable."
55 nnml-get-new-mail)
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)
65 (setq 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)
72 defs)
73 (let ((dir (gnus-agent-directory))
74 err)
75 (cond
76 ((not (condition-case arg
77 (file-exists-p dir)
78 (ftp-error (setq err (format "%s" arg)))))
79 (nnagent-close-server)
80 (nnheader-report
81 'nnagent (or err
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"
88 server dir)
89 t))))
91 (deffoo nnagent-retrieve-groups (groups &optional server)
92 (save-excursion
93 (cond
94 ((file-exists-p (gnus-agent-lib-file "groups"))
95 (nnmail-find-file (gnus-agent-lib-file "groups"))
96 'groups)
97 ((file-exists-p (gnus-agent-lib-file "active"))
98 (nnmail-find-file (gnus-agent-lib-file "active"))
99 'active)
100 (t nil))))
102 (defun nnagent-request-type (group article)
103 (unless (stringp article)
104 (let ((gnus-plugged t))
105 (if (not (gnus-check-backend-function
106 'request-type (car gnus-command-method)))
107 'unknown
108 (funcall (gnus-get-function gnus-command-method 'request-type)
109 (gnus-group-real-name group) article)))))
111 (deffoo nnagent-request-newgroups (date server)
112 nil)
114 (deffoo nnagent-request-update-info (group info &optional server)
115 nil)
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 (with-temp-buffer
123 (insert (format "(%s-request-set-mark \"%s\" '%s \"%s\")\n"
124 (nth 0 gnus-command-method) group action
125 (or server (nth 1 gnus-command-method))))
126 (append-to-file (point-min) (point-max) (gnus-agent-lib-file "flags")))
127 nil)
129 (deffoo nnagent-request-group (group &optional server dont-check)
130 (nnoo-parent-function 'nnagent 'nnml-request-group
131 (list group (nnagent-server server) dont-check)))
133 (deffoo nnagent-close-group (group &optional server)
134 (nnoo-parent-function 'nnagent 'nnml-close-group
135 (list group (nnagent-server server))))
137 (deffoo nnagent-request-accept-article (group &optional server last)
138 (nnoo-parent-function 'nnagent 'nnml-request-accept-article
139 (list group (nnagent-server server) last)))
141 (deffoo nnagent-request-article (id &optional group server buffer)
142 (nnoo-parent-function 'nnagent 'nnml-request-article
143 (list id group (nnagent-server server) buffer)))
145 (deffoo nnagent-request-create-group (group &optional server args)
146 (nnoo-parent-function 'nnagent 'nnml-request-create-group
147 (list group (nnagent-server server) args)))
149 (deffoo nnagent-request-delete-group (group &optional force server)
150 (nnoo-parent-function 'nnagent 'nnml-request-delete-group
151 (list group force (nnagent-server server))))
153 (deffoo nnagent-request-expire-articles (articles group &optional server force)
154 (nnoo-parent-function 'nnagent 'nnml-request-expire-articles
155 (list articles group (nnagent-server server) force)))
157 (deffoo nnagent-request-list (&optional server)
158 (nnoo-parent-function 'nnagent 'nnml-request-list
159 (list (nnagent-server server))))
161 (deffoo nnagent-request-list-newsgroups (&optional server)
162 (nnoo-parent-function 'nnagent 'nnml-request-list-newsgroups
163 (list (nnagent-server server))))
165 (deffoo nnagent-request-move-article
166 (article group server accept-form &optional last)
167 (nnoo-parent-function 'nnagent 'nnml-request-move-article
168 (list article group (nnagent-server server)
169 accept-form last)))
171 (deffoo nnagent-request-rename-group (group new-name &optional server)
172 (nnoo-parent-function 'nnagent 'nnml-request-rename-group
173 (list group new-name (nnagent-server server))))
175 (deffoo nnagent-request-scan (&optional group server)
176 (nnoo-parent-function 'nnagent 'nnml-request-scan
177 (list group (nnagent-server server))))
179 (deffoo nnagent-retrieve-headers (sequence &optional group server fetch-old)
180 (nnoo-parent-function 'nnagent 'nnml-retrieve-headers
181 (list sequence group (nnagent-server server) fetch-old)))
183 (deffoo nnagent-set-status (article name value &optional group server)
184 (nnoo-parent-function 'nnagent 'nnml-set-status
185 (list article name value group (nnagent-server server))))
187 (deffoo nnagent-server-opened (&optional server)
188 (nnoo-parent-function 'nnagent 'nnml-server-opened
189 (list (nnagent-server server))))
191 (deffoo nnagent-status-message (&optional server)
192 (nnoo-parent-function 'nnagent 'nnml-status-message
193 (list (nnagent-server server))))
195 ;; Use nnml functions for just about everything.
196 (nnoo-import nnagent
197 (nnml))
200 ;;; Internal functions.
202 (provide 'nnagent)
204 ;;; nnagent.el ends here