*** empty log message ***
[gnus] / lisp / nnlistserv.el
1 ;;; nnlistserv.el --- retrieving articles via web mailing list archives
2 ;; Copyright (C) 1997,98 Free Software Foundation, Inc.
3
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
5 ;; Keywords: news, mail
6
7 ;; This file is part of GNU Emacs.
8
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.
13
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.
18
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.
23
24 ;;; Commentary:
25
26 ;; Note: You need to have `url' and `w3' installed for this
27 ;; backend to work.
28
29 ;;; Code:
30
31 (eval-when-compile (require 'cl))
32
33 (push '("nnlistserv" none) gnus-valid-select-methods)
34
35 (require 'nnoo)
36 (require 'nnweb)
37
38 (nnoo-declare nnlistserv
39   nnweb)
40
41 (defvoo nnlistserv-directory (nnheader-concat gnus-directory "nnlistserv/")
42   "Where nnlistserv will save its files."
43   nnweb-directory)
44
45 (defvoo nnlistserv-name 'kk
46   "What search engine type is being used."
47   nnweb-type)
48
49 (defvoo nnlistserv-type-definition
50   '((kk
51      (article . nnlistserv-kk-wash-article)
52      (map . nnlistserv-kk-create-mapping)
53      (search . nnlistserv-kk-search)
54      (address . "http://www.itk.ntnu.no/ansatte/Andresen_Trond/kk-f/%s/")
55      (pages "fra160396" "fra160796" "fra061196" "fra160197"
56             "fra090997" "fra040797" "fra130397" "nye")
57      (index . "date.html")
58      (identifier . nnlistserv-kk-identity)))
59   "Type-definition alist."
60   nnweb-type-definition)
61
62 (defvoo nnlistserv-search nil
63   "Search string to feed to DejaNews."
64   nnweb-search)
65
66 (defvoo nnlistserv-ephemeral-p nil
67   "Whether this nnlistserv server is ephemeral."
68   nnweb-ephemeral-p)
69
70 ;;; Internal variables
71
72 ;;; Interface functions
73
74 (nnoo-define-basics nnlistserv)
75
76 (nnoo-import nnlistserv
77   (nnweb))
78
79 ;;; Internal functions
80
81 ;;;
82 ;;; KK functions.
83 ;;;
84
85 (defun nnlistserv-kk-create-mapping ()
86   "Perform the search and create an number-to-url alist."
87   (save-excursion
88     (set-buffer nnweb-buffer)
89     (let ((case-fold-search t)
90           (active (or (cadr (assoc nnweb-group nnweb-group-alist))
91                       (cons 1 0)))
92           (pages (nnweb-definition 'pages))
93           map url page subject from )
94       (while (setq page (pop pages))
95         (erase-buffer)
96         (when (funcall (nnweb-definition 'search) page)
97           ;; Go through all the article hits on this page.
98           (goto-char (point-min))
99           (nnweb-decode-entities)
100           (goto-char (point-min))
101           (while (re-search-forward "^<li> *<a href=\"\\([^\"]+\\)\"><b>\\([^\\>]+\\)</b></a> *<[^>]+><i>\\([^>]+\\)<" nil t)
102             (setq url (match-string 1)
103                   subject (match-string 2)
104                   from (match-string 3))
105             (setq url (concat (format (nnweb-definition 'address) page) url))
106             (unless (nnweb-get-hashtb url)
107               (push
108                (list
109                 (incf (cdr active))
110                 (make-full-mail-header
111                  (cdr active) subject from ""
112                  (concat "<" (nnweb-identifier url) "@kk>")
113                  nil 0 0 url))
114                map)
115               (nnweb-set-hashtb (cadar map) (car map))
116               (message "%s %s %s" (cdr active) (point) pages)
117               ))))
118       ;; Return the articles in the right order.
119       (setq nnweb-articles
120             (sort (nconc nnweb-articles map) 'car-less-than-car)))))
121
122 (defun nnlistserv-kk-wash-article ()
123   (let ((case-fold-search t)
124         (headers '(sent name email subject id))
125         sent name email subject id)
126     (nnweb-decode-entities)
127     (while headers
128       (goto-char (point-min))
129       (re-search-forward (format "<!-- %s=\"\\([^\"]+\\)" (car headers) nil t))
130       (set (pop headers) (match-string 1)))
131     (goto-char (point-min))
132     (search-forward "<!-- body" nil t)
133     (delete-region (point-min) (progn (forward-line 1) (point)))
134     (goto-char (point-max))
135     (search-backward "<!-- body" nil t)
136     (delete-region (point-max) (progn (beginning-of-line) (point)))
137     (nnweb-remove-markup)
138     (goto-char (point-min))
139     (insert (format "From: %s <%s>\n" name email)
140             (format "Subject: %s\n" subject)
141             (format "Message-ID: %s\n" id)
142             (format "Date: %s\n\n" sent))))
143
144 (defun nnlistserv-kk-search (search)
145   (url-insert-file-contents
146    (concat (format (nnweb-definition 'address) search) 
147            (nnweb-definition 'index)))
148   t)
149
150 (defun nnlistserv-kk-identity (url)
151   "Return an unique identifier based on URL."
152   url)
153
154 (provide 'nnlistserv)
155
156 ;;; nnlistserv.el ends here