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.
33 (setq gnus-valid-select-methods
34 (cons '("nndb" mail address respool prompt-address
)
35 gnus-valid-select-methods
))
42 (eval-when-compile (require 'cl
))
45 (unless (fboundp 'open-network-stream
)
48 (eval-when-compile (require 'cl
))
51 (autoload 'news-setup
"rnewspost")
52 (autoload 'news-reply-mode
"rnewspost")
53 (autoload 'cancel-timer
"timer")
54 (autoload 'telnet
"telnet" nil t
)
55 (autoload 'telnet-send-input
"telnet" nil t
)
56 (autoload 'timezone-parse-date
"timezone"))
58 ;; Declare nndb as derived from nntp
60 (nnoo-declare nndb nntp
)
62 ;; Variables specific to nndb
64 ;;- currently not used but just in case...
65 (defvoo nndb-deliver-program
"nndel"
66 "*The program used to put a message in an NNDB group.")
68 ;; Variables copied from nntp
70 (defvoo nndb-server-opened-hook
'(nntp-send-authinfo-from-file)
71 "Like nntp-server-opened-hook."
72 nntp-server-opened-hook
)
74 ;(defvoo nndb-rlogin-parameters '("telnet" "${NNDBSERVER:=localhost}" "9000")
75 ; "*Parameters to nndb-open-login. Like nntp-rlogin-parameters."
76 ; nntp-rlogin-parameters)
78 ;(defvoo nndb-rlogin-user-name nil
79 ; "*User name for rlogin connect method."
80 ; nntp-rlogin-user-name)
82 (defvoo nndb-address
"localhost"
83 "*The name of the NNDB server."
86 (defvoo nndb-port-number
9000
87 "*Port number to connect to."
90 ;(defvoo nndb-current-group ""
91 ; "Like nntp-current-group."
94 (defvoo nndb-status-string nil
"" nntp-status-string
)
98 (defconst nndb-version
"nndb 0.3"
99 "Version numbers of this version of NNDB.")
102 ;;; Interface functions.
104 (nnoo-define-basics nndb
)
106 ;; Import other stuff from nntp as is.
111 ;;- maybe this should be mail??
112 ;;-(defun nndb-request-type (group &optional article)
115 ;;------------------------------------------------------------------
116 ;;- only new stuff below
118 ; nndb-request-update-info does not exist and is not needed
120 ; nndb-request-update-mark does not exist and is not needed
122 ; nndb-request-scan does not exist
123 ; get new mail from somewhere -- maybe this is not needed?
126 (deffoo nndb-request-create-group
(group &optional server
)
127 "Creates a group if it doesn't exist yet."
128 (nntp-send-command "^[23].*\n" "MKGROUP" group
))
130 ; todo -- use some other time than the creation time of the article
131 ; best is time since article has been marked as expirable
132 (deffoo nndb-request-expire-articles
133 (articles &optional group server force
)
134 "Expires ARTICLES from GROUP on SERVER.
135 If FORCE, delete regardless of exiration date, otherwise use normal
138 (nntp-possibly-change-server group server
) ;;-
140 (setq art
(pop articles
))
141 (nntp-send-command "^\\([23]\\|^423\\).*\n" "DATE" art
)
142 (setq msg
(nndb-status-message))
143 ;; CCC we shouldn't be using the variable nndb-status-string?
144 (if (string-match "^423" (nnheader-get-report 'nndb
))
146 (or (string-match "\\([0-9]+\\) \\([0-9]+\\)$" msg
)
147 (error "Not a valid response for DATE command: %s"
149 (if (nnmail-expired-article-p
152 (substring msg
(match-beginning 1) (match-end 1)))
154 (substring msg
(match-beginning 2) (match-end 2))))
156 (nnheader-message 5 "Deleting article %s in %s..."
158 (nntp-send-command "^[23].*\n" "DELETE" art
))))))
160 (deffoo nndb-request-move-article
161 (article group server accept-form
&optional last
)
162 "Move ARTICLE (a number) from GROUP on SERVER.
163 Evals ACCEPT-FORM in current buffer, where the article is.
164 Optional LAST is ignored."
165 (let ((artbuf (get-buffer-create " *nndb move*"))
168 (nndb-request-article article group server artbuf
)
171 (setq result
(eval accept-form
))
172 (kill-buffer (current-buffer))
174 (nndb-request-expire-articles (list article
)
180 (deffoo nndb-request-accept-article
(group server
&optional last
)
181 "The article in the current buffer is put into GROUP."
182 (nntp-possibly-change-server group server
) ;;-
184 (when (nntp-send-command "^[23].*\r?\n" "ACCEPT" group
)
187 (nntp-send-region-to-server (point-min) (point-max))
188 ;; 1.2a NNTP's post command is buggy. "^M" (\r) is not
189 ;; appended to end of the status message.
190 (nntp-wait-for-response "^[23].*\n")
191 (setq statmsg
(nntp-status-message))
192 (or (string-match "^\\([0-9]+\\)" statmsg
)
193 (error "nndb: %s" statmsg
))
194 (setq art
(substring statmsg
197 (message "nndb: accepted %s" art
)
200 (deffoo nndb-request-replace-article
(article group buffer
)
201 "ARTICLE is the number of the article in GROUP to be replaced
202 with the contents of the BUFFER."
205 (when (nntp-send-command "^[23].*\r?\n" "REPLACE" (int-to-string article
))
208 (nntp-send-region-to-server (point-min) (point-max))
209 ;; 1.2a NNTP's post command is buggy. "^M" (\r) is not
210 ;; appended to end of the status message.
211 (nntp-wait-for-response "^[23].*\n")
212 ; (setq statmsg (nntp-status-message))
213 ; (or (string-match "^\\([0-9]+\\)" statmsg)
214 ; (error "nndb: %s" statmsg))
215 ; (setq art (substring statmsg
216 ; (match-beginning 1)
218 ; (message "nndb: replaced %s" art)
219 (list (int-to-string article
)))))
221 ; nndb-request-delete-group does not exist
222 ; todo -- maybe later
224 ; nndb-request-rename-group does not exist
225 ; todo -- maybe later