1 ;;; nnwarchive.el --- interfacing with web archives
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 ;; Author: Shenghuo Zhu <zsh@cs.rochester.edu>
7 ;; Keywords: news egroups mail-archive
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/>.
26 ;; Note: You need to have `url' (w3 0.46) or greater version
27 ;; installed for some functions of this backend to work.
30 ;; 1. To support more web archives.
31 ;; 2. Generalize webmail to other MHonArc archive.
35 (eval-when-compile (require 'cl))
46 (nnoo-declare nnwarchive)
48 (defvar nnwarchive-type-definition
50 (address . "www.egroups.com")
52 "http://www.egroups.com/login.cgi?&login_email=%s&login_password=%s"
53 nnwarchive-login nnwarchive-passwd)
55 "http://www.egroups.com/mygroups")
56 (list-dissect . nnwarchive-egroups-list)
57 (list-groups . nnwarchive-egroups-list-groups)
59 "http://www.egroups.com/messages/%s/%d" group aux)
61 "http://www.egroups.com/messages/%s/" group)
62 (xover-page-size . 13)
63 (xover-dissect . nnwarchive-egroups-xover)
65 "http://www.egroups.com/message/%s/%d?source=1" group article)
66 (article-dissect . nnwarchive-egroups-article)
69 (xover-files . nnwarchive-egroups-xover-files))
71 (address . "www.mail-archive.com")
74 "http://www.mail-archive.com/lists.html")
75 (list-dissect . nnwarchive-mail-archive-list)
76 (list-groups . nnwarchive-mail-archive-list-groups)
78 "http://www.mail-archive.com/%s/mail%d.html" group aux)
80 "http://www.mail-archive.com/%s/maillist.html" group)
82 (xover-dissect . nnwarchive-mail-archive-xover)
84 "http://www.mail-archive.com/%s/msg%05d.html" group article1)
85 (article-dissect . nnwarchive-mail-archive-article)
86 (xover-files . nnwarchive-mail-archive-xover-files)
88 (article-offset . 1))))
90 (defvar nnwarchive-default-type 'egroups)
92 (defvoo nnwarchive-directory (nnheader-concat gnus-directory "warchive/")
93 "Where nnwarchive will save its files.")
95 (defvoo nnwarchive-type nil
96 "The type of nnwarchive.")
98 (defvoo nnwarchive-address ""
99 "The address of nnwarchive.")
101 (defvoo nnwarchive-login nil
102 "Your login name for the group.")
104 (defvoo nnwarchive-passwd nil
105 "Your password for the group.")
107 (defvoo nnwarchive-groups nil)
109 (defvoo nnwarchive-headers-cache nil)
111 (defvoo nnwarchive-authentication nil)
113 (defvoo nnwarchive-nov-is-evil nil)
115 (defconst nnwarchive-version "nnwarchive 1.0")
117 ;;; Internal variables
119 (defvoo nnwarchive-open-url nil)
120 (defvoo nnwarchive-open-dissect nil)
122 (defvoo nnwarchive-list-url nil)
123 (defvoo nnwarchive-list-dissect nil)
124 (defvoo nnwarchive-list-groups nil)
126 (defvoo nnwarchive-xover-files nil)
127 (defvoo nnwarchive-xover-url nil)
128 (defvoo nnwarchive-xover-last-url nil)
129 (defvoo nnwarchive-xover-dissect nil)
130 (defvoo nnwarchive-xover-page-size nil)
132 (defvoo nnwarchive-article-url nil)
133 (defvoo nnwarchive-article-dissect nil)
134 (defvoo nnwarchive-xover-files nil)
135 (defvoo nnwarchive-article-offset 0)
137 (defvoo nnwarchive-buffer nil)
139 (defvoo nnwarchive-keep-backlog 300)
140 (defvar nnwarchive-backlog-articles nil)
141 (defvar nnwarchive-backlog-hashtb nil)
143 (defvoo nnwarchive-headers nil)
146 ;;; Interface functions
148 (nnoo-define-basics nnwarchive)
150 (defun nnwarchive-set-default (type)
151 (let ((defs (cdr (assq type nnwarchive-type-definition)))
154 (set (intern (concat "nnwarchive-" (symbol-name (car def))))
157 (defmacro nnwarchive-backlog (&rest form)
158 `(let ((gnus-keep-backlog nnwarchive-keep-backlog)
160 (format " *nnwarchive backlog %s*" nnwarchive-address))
161 (gnus-backlog-articles nnwarchive-backlog-articles)
162 (gnus-backlog-hashtb nnwarchive-backlog-hashtb))
165 (setq nnwarchive-backlog-articles gnus-backlog-articles
166 nnwarchive-backlog-hashtb gnus-backlog-hashtb))))
167 (put 'nnwarchive-backlog 'lisp-indent-function 0)
168 (put 'nnwarchive-backlog 'edebug-form-spec '(form body))
170 (defun nnwarchive-backlog-enter-article (group number buffer)
172 (gnus-backlog-enter-article group number buffer)))
174 (defun nnwarchive-get-article (article &optional group server buffer)
175 (if (numberp article)
176 (if (nnwarchive-backlog
177 (gnus-backlog-request-article group article
178 (or buffer nntp-server-buffer)))
182 (set-buffer nnwarchive-buffer)
183 (goto-char (point-min))
184 (let ((article1 (- article nnwarchive-article-offset)))
185 (nnwarchive-url nnwarchive-article-url))
186 (setq contents (funcall nnwarchive-article-dissect group article)))
189 (set-buffer (or buffer nntp-server-buffer))
192 (nnwarchive-backlog-enter-article group article (current-buffer))
193 (nnheader-report 'nnwarchive "Fetched article %s" article)
194 (cons group article)))))
197 (deffoo nnwarchive-retrieve-headers (articles &optional group server fetch-old)
198 (nnwarchive-possibly-change-server group server)
199 (if (or gnus-nov-is-evil nnwarchive-nov-is-evil)
201 (with-current-buffer nntp-server-buffer
203 (let ((buf (current-buffer)) b e)
204 (dolist (art articles)
205 (nnwarchive-get-article art group server buf)
206 (setq b (goto-char (point-min)))
207 (if (search-forward "\n\n" nil t)
209 (goto-char (point-max)))
211 (with-current-buffer nntp-server-buffer
212 (insert (format "221 %d Article retrieved.\n" art))
213 (insert-buffer-substring buf b e)
216 (setq nnwarchive-headers (cdr (assoc group nnwarchive-headers-cache)))
218 (set-buffer nnwarchive-buffer)
220 (funcall nnwarchive-xover-files group articles))
222 (set-buffer nntp-server-buffer)
225 (dolist (art articles)
226 (if (setq header (assq art nnwarchive-headers))
227 (nnheader-insert-nov (cdr header))))))
228 (let ((elem (assoc group nnwarchive-headers-cache)))
230 (setcdr elem nnwarchive-headers)
231 (push (cons group nnwarchive-headers) nnwarchive-headers-cache)))
234 (deffoo nnwarchive-request-group (group &optional server dont-check)
235 (nnwarchive-possibly-change-server nil server)
236 (when (and (not dont-check) nnwarchive-list-groups)
237 (funcall nnwarchive-list-groups (list group))
238 (nnwarchive-write-groups))
239 (let ((elem (assoc group nnwarchive-groups)))
242 (nnheader-report 'nnwarchive "Group does not exist"))
244 (nnheader-report 'nnwarchive "Opened group %s" group)
246 "211 %d %d %d %s\n" (or (cadr elem) 0) 1 (or (cadr elem) 0)
247 (prin1-to-string group))
250 (deffoo nnwarchive-request-article (article &optional group server buffer)
251 (nnwarchive-possibly-change-server group server)
252 (nnwarchive-get-article article group server buffer))
254 (deffoo nnwarchive-close-server (&optional server)
255 (when (and (nnwarchive-server-opened server)
256 (gnus-buffer-live-p nnwarchive-buffer))
258 (set-buffer nnwarchive-buffer)
259 (kill-buffer nnwarchive-buffer)))
261 (gnus-backlog-shutdown))
262 (nnoo-close-server 'nnwarchive server))
264 (deffoo nnwarchive-request-list (&optional server)
265 (nnwarchive-possibly-change-server nil server)
267 (set-buffer nnwarchive-buffer)
269 (if nnwarchive-list-url
270 (nnwarchive-url nnwarchive-list-url))
271 (if nnwarchive-list-dissect
272 (funcall nnwarchive-list-dissect))
273 (nnwarchive-write-groups)
274 (nnwarchive-generate-active))
277 (deffoo nnwarchive-open-server (server &optional defs connectionless)
278 (nnoo-change-server 'nnwarchive server defs)
279 (nnwarchive-init server)
280 (when nnwarchive-authentication
281 (setq nnwarchive-login
284 (format "Login at %s: " server)
286 (setq nnwarchive-passwd
287 (or nnwarchive-passwd
289 (format "Password for %s at %s: "
290 nnwarchive-login server)))))
291 (unless nnwarchive-groups
292 (nnwarchive-read-groups))
294 (set-buffer nnwarchive-buffer)
296 (if nnwarchive-open-url
297 (nnwarchive-url nnwarchive-open-url))
298 (if nnwarchive-open-dissect
299 (funcall nnwarchive-open-dissect)))
302 (nnoo-define-skeleton nnwarchive)
304 ;;; Internal functions
306 (defun nnwarchive-possibly-change-server (&optional group server)
307 (nnwarchive-init server)
309 (not (nnwarchive-server-opened server)))