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@gnus.org>
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
))
34 (eval-when-compile (ignore-errors (require 'nnweb
)))
35 (eval '(require 'nnweb
))
37 (nnoo-declare nnlistserv
40 (defvoo nnlistserv-directory
(nnheader-concat gnus-directory
"nnlistserv/")
41 "Where nnlistserv will save its files."
44 (defvoo nnlistserv-name
'kk
45 "What search engine type is being used."
48 (defvoo nnlistserv-type-definition
50 (article . nnlistserv-kk-wash-article
)
51 (map . nnlistserv-kk-create-mapping
)
52 (search . nnlistserv-kk-search
)
53 (address .
"http://www.itk.ntnu.no/ansatte/Andresen_Trond/kk-f/%s/")
54 (pages "fra160396" "fra160796" "fra061196" "fra160197"
55 "fra090997" "fra040797" "fra130397" "nye")
57 (identifier . nnlistserv-kk-identity
)))
58 "Type-definition alist."
59 nnweb-type-definition
)
61 (defvoo nnlistserv-search nil
62 "Search string to feed to DejaNews."
65 (defvoo nnlistserv-ephemeral-p nil
66 "Whether this nnlistserv server is ephemeral."
69 ;;; Internal variables
71 ;;; Interface functions
73 (nnoo-define-basics nnlistserv
)
75 (nnoo-import nnlistserv
78 ;;; Internal functions
84 (defun nnlistserv-kk-create-mapping ()
85 "Perform the search and create an number-to-url alist."
87 (set-buffer nnweb-buffer
)
88 (let ((case-fold-search t
)
89 (active (or (cadr (assoc nnweb-group nnweb-group-alist
))
91 (pages (nnweb-definition 'pages
))
92 map url page subject from
)
93 (while (setq page
(pop pages
))
95 (when (funcall (nnweb-definition 'search
) page
)
96 ;; Go through all the article hits on this page.
97 (goto-char (point-min))
98 (nnweb-decode-entities)
99 (goto-char (point-min))
100 (while (re-search-forward "^<li> *<a href=\"\\([^\"]+\\)\"><b>\\([^\\>]+\\)</b></a> *<[^>]+><i>\\([^>]+\\)<" nil t
)
101 (setq url
(match-string 1)
102 subject
(match-string 2)
103 from
(match-string 3))
104 (setq url
(concat (format (nnweb-definition 'address
) page
) url
))
105 (unless (nnweb-get-hashtb url
)
109 (make-full-mail-header
110 (cdr active
) subject from
""
111 (concat "<" (nnweb-identifier url
) "@kk>")
114 (nnweb-set-hashtb (cadar map
) (car map
))
115 (nnheader-message 5 "%s %s %s" (cdr active
) (point) pages
)
117 ;; Return the articles in the right order.
119 (sort (nconc nnweb-articles map
) 'car-less-than-car
)))))
121 (defun nnlistserv-kk-wash-article ()
122 (let ((case-fold-search t
)
123 (headers '(sent name email subject id
))
124 sent name email subject id
)
125 (nnweb-decode-entities)
127 (goto-char (point-min))
128 (re-search-forward (format "<!-- %s=\"\\([^\"]+\\)" (car headers
) nil t
))
129 (set (pop headers
) (match-string 1)))
130 (goto-char (point-min))
131 (search-forward "<!-- body" nil t
)
132 (delete-region (point-min) (progn (forward-line 1) (point)))
133 (goto-char (point-max))
134 (search-backward "<!-- body" nil t
)
135 (delete-region (point-max) (progn (beginning-of-line) (point)))
136 (nnweb-remove-markup)
137 (goto-char (point-min))
138 (insert (format "From: %s <%s>\n" name email
)
139 (format "Subject: %s\n" subject
)
140 (format "Message-ID: %s\n" id
)
141 (format "Date: %s\n\n" sent
))))
143 (defun nnlistserv-kk-search (search)
144 (url-insert-file-contents
145 (concat (format (nnweb-definition 'address
) search
)
146 (nnweb-definition 'index
)))
149 (defun nnlistserv-kk-identity (url)
150 "Return an unique identifier based on URL."
153 (provide 'nnlistserv
)
155 ;;; nnlistserv.el ends here