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)
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.
27 ;; Note: You need to have `url' and `w3' installed for this
32 (eval-when-compile (require 'cl
))
37 (require 'nnweb
)) ; requires W3
38 (autoload 'url-insert-file-contents
"nnweb"))
40 (nnoo-declare nnlistserv
43 (defvoo nnlistserv-directory
(nnheader-concat gnus-directory
"nnlistserv/")
44 "Where nnlistserv will save its files."
47 (defvoo nnlistserv-name
'kk
48 "What search engine type is being used."
51 (defvoo nnlistserv-type-definition
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")
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."
68 (defvoo nnlistserv-ephemeral-p nil
69 "Whether this nnlistserv server is ephemeral."
72 ;;; Internal variables
74 ;;; Interface functions
76 (nnoo-define-basics nnlistserv
)
78 (nnoo-import nnlistserv
81 ;;; Internal functions
87 (defun nnlistserv-kk-create-mapping ()
88 "Perform the search and create a number-to-url alist."
90 (set-buffer nnweb-buffer
)
91 (let ((case-fold-search t
)
92 (active (or (cadr (assoc nnweb-group nnweb-group-alist
))
94 (pages (nnweb-definition 'pages
))
95 map url page subject from
)
96 (while (setq page
(pop pages
))
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
)
112 (make-full-mail-header
113 (cdr active
) subject from
""
114 (concat "<" (nnweb-identifier url
) "@kk>")
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.
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)
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."
155 (provide 'nnlistserv
)
157 ;;; nnlistserv.el ends here