1 ;;; nndb.el --- nndb access for Gnus
2 ;; Copyright (C) 1996 Free Software Foundation, Inc.
4 ;; Author: Kai Grossjohann <grossjohann@ls6.informatik.uni-dortmund.de>
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)
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.
26 ;; I have shamelessly snarfed the code of nntp.el from sgnus.
31 ;; Register nndb with known select methods.
37 (setq gnus-valid-select-methods
38 (cons '("nndb" mail address respool prompt-address)
39 gnus-valid-select-methods))
46 (eval-when-compile (require 'cl))
49 (unless (fboundp 'open-network-stream)
52 (eval-when-compile (require 'cl))
55 (autoload 'news-setup "rnewspost")
56 (autoload 'news-reply-mode "rnewspost")
57 (autoload 'cancel-timer "timer")
58 (autoload 'telnet "telnet" nil t)
59 (autoload 'telnet-send-input "telnet" nil t)
60 (autoload 'timezone-parse-date "timezone"))
62 ;; Declare nndb as derived from nntp
64 (nnoo-declare nndb nntp)
66 ;; Variables specific to nndb
68 ;;- currently not used but just in case...
69 (defvoo nndb-deliver-program "nndel"
70 "*The program used to put a message in an NNDB group.")
72 ;; Variables copied from nntp
74 (defvoo nndb-server-opened-hook '(nntp-send-authinfo-from-file)
75 "Like nntp-server-opened-hook."
76 nntp-server-opened-hook)
78 ;(defvoo nndb-rlogin-parameters '("telnet" "${NNDBSERVER:=localhost}" "9000")
79 ; "*Parameters to nndb-open-login. Like nntp-rlogin-parameters."
80 ; nntp-rlogin-parameters)
82 ;(defvoo nndb-rlogin-user-name nil
83 ; "*User name for rlogin connect method."
84 ; nntp-rlogin-user-name)
86 (defvoo nndb-address "localhost"
87 "*The name of the NNDB server."
90 (defvoo nndb-port-number 9000
91 "*Port number to connect to."
94 ;(defvoo nndb-current-group ""
95 ; "Like nntp-current-group."
98 (defvoo nndb-status-string nil "" nntp-status-string)
102 (defconst nndb-version "nndb 0.3"
103 "Version numbers of this version of NNDB.")
106 ;;; Interface functions.
108 (nnoo-define-basics nndb)
110 ;; Import other stuff from nntp as is.
115 ;;- maybe this should be mail??
116 ;;-(defun nndb-request-type (group &optional article)
119 ;;------------------------------------------------------------------
120 ;;- only new stuff below
122 ; nndb-request-update-info does not exist and is not needed
124 ; nndb-request-update-mark does not exist and is not needed
126 ; nndb-request-scan does not exist
127 ; get new mail from somewhere -- maybe this is not needed?
130 (deffoo nndb-request-create-group (group &optional server args)
131 "Creates a group if it doesn't exist yet."
132 (nntp-send-command "^[23].*\n" "MKGROUP" group))
134 ; todo -- use some other time than the creation time of the article
135 ; best is time since article has been marked as expirable
136 (deffoo nndb-request-expire-articles
137 (articles &optional group server force)
138 "Expires ARTICLES from GROUP on SERVER.
139 If FORCE, delete regardless of expiration date, otherwise use normal
142 (nntp-possibly-change-group group server) ;;-
144 (setq art (pop articles))
145 (nntp-send-command "^\\([23]\\|^423\\).*\n" "DATE" art)
146 (setq msg (nndb-status-message))
147 ;; CCC we shouldn't be using the variable nndb-status-string?
148 (if (string-match "^423" (nnheader-get-report 'nndb))
150 (or (string-match "\\([0-9]+\\) \\([0-9]+\\)$" msg)
151 (error "Not a valid response for DATE command: %s"
153 (if (nnmail-expired-article-p
156 (substring msg (match-beginning 1) (match-end 1)))
158 (substring msg (match-beginning 2) (match-end 2))))
160 (nnheader-message 5 "Deleting article %s in %s..."
162 (nntp-send-command "^[23].*\n" "DELETE" art))))))
164 (deffoo nndb-request-move-article
165 (article group server accept-form &optional last)
166 "Move ARTICLE (a number) from GROUP on SERVER.
167 Evals ACCEPT-FORM in current buffer, where the article is.
168 Optional LAST is ignored."
169 (let ((artbuf (get-buffer-create " *nndb move*"))
172 (nndb-request-article article group server artbuf)
175 (setq result (eval accept-form))
176 (kill-buffer (current-buffer))
178 (nndb-request-expire-articles (list article)
184 (deffoo nndb-request-accept-article (group server &optional last)
185 "The article in the current buffer is put into GROUP."
186 (nntp-possibly-change-group group server) ;;-
188 (when (nntp-send-command "^[23].*\r?\n" "ACCEPT" group)
191 (nntp-send-buffer "^[23].*\n")
192 (setq statmsg (nntp-status-message))
193 (or (string-match "^\\([0-9]+\\)" statmsg)
194 (error "nndb: %s" statmsg))
195 (setq art (substring statmsg
198 (message "nndb: accepted %s" art)
201 (deffoo nndb-request-replace-article (article group buffer)
202 "ARTICLE is the number of the article in GROUP to be replaced
203 with the contents of the BUFFER."
206 (when (nntp-send-command "^[23].*\r?\n" "REPLACE" (int-to-string article))
209 (nntp-send-buffer "^[23].*\n")
210 ; (setq statmsg (nntp-status-message))
211 ; (or (string-match "^\\([0-9]+\\)" statmsg)
212 ; (error "nndb: %s" statmsg))
213 ; (setq art (substring statmsg
214 ; (match-beginning 1)
216 ; (message "nndb: replaced %s" art)
217 (list (int-to-string article)))))
219 ; nndb-request-delete-group does not exist
220 ; todo -- maybe later
222 ; nndb-request-rename-group does not exist
223 ; todo -- maybe later