Instructions to create pretest or release tarballs.
[emacs.git] / lisp / gnus / nnlistserv.el
blobbc5991c05fc331e33cd6676bd498962486c24603
1 ;;; nnlistserv.el --- retrieving articles via web mailing list archives
3 ;; Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news, mail
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
25 ;;; Commentary:
27 ;; Note: You need to have `url' and `w3' installed for this
28 ;; backend to work.
30 ;;; Code:
32 (eval-when-compile (require 'cl))
34 (require 'nnoo)
35 (eval-when-compile
36 (ignore-errors
37 (require 'nnweb)) ; requires W3
38 (autoload 'url-insert-file-contents "nnweb"))
40 (nnoo-declare nnlistserv
41 nnweb)
43 (defvoo nnlistserv-directory (nnheader-concat gnus-directory "nnlistserv/")
44 "Where nnlistserv will save its files."
45 nnweb-directory)
47 (defvoo nnlistserv-name 'kk
48 "What search engine type is being used."
49 nnweb-type)
51 (defvoo nnlistserv-type-definition
52 '((kk
53 (article . nnlistserv-kk-wash-article)
54 (map . nnlistserv-kk-create-mapping)
55 (search . nnlistserv-kk-search)
56 (address . "http://www.itk.ntnu.no/ansatte/Andresen_Trond/kk-f/%s/")
57 (pages "fra160396" "fra160796" "fra061196" "fra160197"
58 "fra090997" "fra040797" "fra130397" "nye")
59 (index . "date.html")
60 (identifier . nnlistserv-kk-identity)))
61 "Type-definition alist."
62 nnweb-type-definition)
64 (defvoo nnlistserv-search nil
65 "Search string to feed to DejaNews."
66 nnweb-search)
68 (defvoo nnlistserv-ephemeral-p nil
69 "Whether this nnlistserv server is ephemeral."
70 nnweb-ephemeral-p)
72 ;;; Internal variables
74 ;;; Interface functions
76 (nnoo-define-basics nnlistserv)
78 (nnoo-import nnlistserv
79 (nnweb))
81 ;;; Internal functions
83 ;;;
84 ;;; KK functions.
85 ;;;
87 (defun nnlistserv-kk-create-mapping ()
88 "Perform the search and create a number-to-url alist."
89 (save-excursion
90 (set-buffer nnweb-buffer)
91 (let ((case-fold-search t)
92 (active (or (cadr (assoc nnweb-group nnweb-group-alist))
93 (cons 1 0)))
94 (pages (nnweb-definition 'pages))
95 map url page subject from )
96 (while (setq page (pop pages))
97 (erase-buffer)
98 (when (funcall (nnweb-definition 'search) page)
99 ;; Go through all the article hits on this page.
100 (goto-char (point-min))
101 (nnweb-decode-entities)
102 (goto-char (point-min))
103 (while (re-search-forward "^<li> *<a href=\"\\([^\"]+\\)\"><b>\\([^\\>]+\\)</b></a> *<[^>]+><i>\\([^>]+\\)<" nil t)
104 (setq url (match-string 1)
105 subject (match-string 2)
106 from (match-string 3))
107 (setq url (concat (format (nnweb-definition 'address) page) url))
108 (unless (nnweb-get-hashtb url)
109 (push
110 (list
111 (incf (cdr active))
112 (make-full-mail-header
113 (cdr active) subject from ""
114 (concat "<" (nnweb-identifier url) "@kk>")
115 nil 0 0 url))
116 map)
117 (nnweb-set-hashtb (cadar map) (car map))
118 (nnheader-message 5 "%s %s %s" (cdr active) (point) pages)))))
119 ;; Return the articles in the right order.
120 (setq nnweb-articles
121 (sort (nconc nnweb-articles map) 'car-less-than-car)))))
123 (defun nnlistserv-kk-wash-article ()
124 (let ((case-fold-search t)
125 (headers '(sent name email subject id))
126 sent name email subject id)
127 (nnweb-decode-entities)
128 (while headers
129 (goto-char (point-min))
130 (re-search-forward (format "<!-- %s=\"\\([^\"]+\\)" (car headers) nil t))
131 (set (pop headers) (match-string 1)))
132 (goto-char (point-min))
133 (search-forward "<!-- body" nil t)
134 (delete-region (point-min) (progn (forward-line 1) (point)))
135 (goto-char (point-max))
136 (search-backward "<!-- body" nil t)
137 (delete-region (point-max) (progn (beginning-of-line) (point)))
138 (nnweb-remove-markup)
139 (goto-char (point-min))
140 (insert (format "From: %s <%s>\n" name email)
141 (format "Subject: %s\n" subject)
142 (format "Message-ID: %s\n" id)
143 (format "Date: %s\n\n" sent))))
145 (defun nnlistserv-kk-search (search)
146 (url-insert-file-contents
147 (concat (format (nnweb-definition 'address) search)
148 (nnweb-definition 'index)))
151 (defun nnlistserv-kk-identity (url)
152 "Return an unique identifier based on URL."
153 url)
155 (provide 'nnlistserv)
157 ;;; nnlistserv.el ends here