1 ;;; nnlistserv.el --- retrieving articles via web mailing list archives
2 ;; Copyright (C) 1997,98 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
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)
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 ;; Note: You need to have `url' and `w3' installed for this
31 (eval-when-compile (require 'cl))
33 (push '("nnlistserv" none) gnus-valid-select-methods)
38 (nnoo-declare nnlistserv
41 (defvoo nnlistserv-directory (nnheader-concat gnus-directory "nnlistserv/")
42 "Where nnlistserv will save its files."
45 (defvoo nnlistserv-name 'kk
46 "What search engine type is being used."
49 (defvoo nnlistserv-type-definition
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")
58 (identifier . nnlistserv-kk-identity)))
59 "Type-definition alist."
60 nnweb-type-definition)
62 (defvoo nnlistserv-search nil
63 "Search string to feed to DejaNews."
66 (defvoo nnlistserv-ephemeral-p nil
67 "Whether this nnlistserv server is ephemeral."
70 ;;; Internal variables
72 ;;; Interface functions
74 (nnoo-define-basics nnlistserv)
76 (nnoo-import nnlistserv
79 ;;; Internal functions
85 (defun nnlistserv-kk-create-mapping ()
86 "Perform the search and create an number-to-url alist."
88 (set-buffer nnweb-buffer)
89 (let ((case-fold-search t)
90 (active (or (cadr (assoc nnweb-group nnweb-group-alist))
92 (pages (nnweb-definition 'pages))
93 map url page subject from )
94 (while (setq page (pop pages))
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)
110 (make-full-mail-header
111 (cdr active) subject from ""
112 (concat "<" (nnweb-identifier url) "@kk>")
115 (nnweb-set-hashtb (cadar map) (car map))
116 (message "%s %s %s" (cdr active) (point) pages)
118 ;; Return the articles in the right order.
120 (sort (nconc nnweb-articles map) 'car-less-than-car)))))
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)
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))))
144 (defun nnlistserv-kk-search (search)
145 (url-insert-file-contents
146 (concat (format (nnweb-definition 'address) search)
147 (nnweb-definition 'index)))
150 (defun nnlistserv-kk-identity (url)
151 "Return an unique identifier based on URL."
154 (provide 'nnlistserv)
156 ;;; nnlistserv.el ends here