Mercurial > emacs
annotate lisp/gnus/nnweb.el @ 23364:aa359fe9fe1e
(gnus-valid-select-methods): Fix type.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Thu, 01 Oct 1998 21:01:15 +0000 |
parents | f075bf0ae873 |
children | eeae7444a853 |
rev | line source |
---|---|
17493 | 1 ;;; nnweb.el --- retrieving articles via web search engines |
2 ;; Copyright (C) 1996,97 Free Software Foundation, Inc. | |
3 | |
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no> | |
5 ;; Keywords: news | |
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 | |
19521
6f6cf9184e93
Require cl at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
17493
diff
changeset
|
31 (eval-when-compile (require 'cl)) |
6f6cf9184e93
Require cl at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
17493
diff
changeset
|
32 |
17493 | 33 (require 'nnoo) |
34 (require 'message) | |
35 (require 'gnus-util) | |
36 (require 'gnus) | |
37 (require 'w3) | |
38 (require 'url) | |
39 (require 'nnmail) | |
23214
f075bf0ae873
(require): Wrap requirement of w3 and url in
Dave Love <fx@gnu.org>
parents:
19969
diff
changeset
|
40 (eval-when-compile |
f075bf0ae873
(require): Wrap requirement of w3 and url in
Dave Love <fx@gnu.org>
parents:
19969
diff
changeset
|
41 (ignore-errors |
f075bf0ae873
(require): Wrap requirement of w3 and url in
Dave Love <fx@gnu.org>
parents:
19969
diff
changeset
|
42 (require 'w3) |
f075bf0ae873
(require): Wrap requirement of w3 and url in
Dave Love <fx@gnu.org>
parents:
19969
diff
changeset
|
43 (require 'url) |
f075bf0ae873
(require): Wrap requirement of w3 and url in
Dave Love <fx@gnu.org>
parents:
19969
diff
changeset
|
44 (require 'w3-forms))) |
f075bf0ae873
(require): Wrap requirement of w3 and url in
Dave Love <fx@gnu.org>
parents:
19969
diff
changeset
|
45 ;; Report failure to find w3 at load time if appropriate. |
f075bf0ae873
(require): Wrap requirement of w3 and url in
Dave Love <fx@gnu.org>
parents:
19969
diff
changeset
|
46 (eval '(progn |
f075bf0ae873
(require): Wrap requirement of w3 and url in
Dave Love <fx@gnu.org>
parents:
19969
diff
changeset
|
47 (require 'w3) |
f075bf0ae873
(require): Wrap requirement of w3 and url in
Dave Love <fx@gnu.org>
parents:
19969
diff
changeset
|
48 (require 'url) |
f075bf0ae873
(require): Wrap requirement of w3 and url in
Dave Love <fx@gnu.org>
parents:
19969
diff
changeset
|
49 (require 'w3-forms))) |
17493 | 50 |
51 (nnoo-declare nnweb) | |
52 | |
53 (defvoo nnweb-directory (nnheader-concat gnus-directory "nnweb/") | |
54 "Where nnweb will save its files.") | |
55 | |
56 (defvoo nnweb-type 'dejanews | |
57 "What search engine type is being used.") | |
58 | |
59 (defvar nnweb-type-definition | |
60 '((dejanews | |
61 (article . nnweb-dejanews-wash-article) | |
62 (map . nnweb-dejanews-create-mapping) | |
63 (search . nnweb-dejanews-search) | |
64 (address . "http://xp9.dejanews.com/dnquery.xp") | |
65 (identifier . nnweb-dejanews-identity)) | |
66 (reference | |
67 (article . nnweb-reference-wash-article) | |
68 (map . nnweb-reference-create-mapping) | |
69 (search . nnweb-reference-search) | |
70 (address . "http://www.reference.com/cgi-bin/pn/go") | |
71 (identifier . identity)) | |
72 (altavista | |
73 (article . nnweb-altavista-wash-article) | |
74 (map . nnweb-altavista-create-mapping) | |
75 (search . nnweb-altavista-search) | |
76 (address . "http://www.altavista.digital.com/cgi-bin/query") | |
77 (id . "/cgi-bin/news?id@%s") | |
78 (identifier . identity))) | |
79 "Type-definition alist.") | |
80 | |
81 (defvoo nnweb-search nil | |
82 "Search string to feed to DejaNews.") | |
83 | |
84 (defvoo nnweb-max-hits 100 | |
85 "Maximum number of hits to display.") | |
86 | |
87 (defvoo nnweb-ephemeral-p nil | |
88 "Whether this nnweb server is ephemeral.") | |
89 | |
90 ;;; Internal variables | |
91 | |
92 (defvoo nnweb-articles nil) | |
93 (defvoo nnweb-buffer nil) | |
94 (defvoo nnweb-group-alist nil) | |
95 (defvoo nnweb-group nil) | |
96 (defvoo nnweb-hashtb nil) | |
97 | |
98 ;;; Interface functions | |
99 | |
100 (nnoo-define-basics nnweb) | |
101 | |
102 (deffoo nnweb-retrieve-headers (articles &optional group server fetch-old) | |
103 (nnweb-possibly-change-server group server) | |
104 (save-excursion | |
105 (set-buffer nntp-server-buffer) | |
106 (erase-buffer) | |
107 (let (article header) | |
108 (while (setq article (pop articles)) | |
109 (when (setq header (cadr (assq article nnweb-articles))) | |
110 (nnheader-insert-nov header))) | |
111 'nov))) | |
112 | |
113 (deffoo nnweb-request-scan (&optional group server) | |
114 (nnweb-possibly-change-server group server) | |
115 (setq nnweb-hashtb (gnus-make-hashtable 4095)) | |
116 (funcall (nnweb-definition 'map)) | |
117 (unless nnweb-ephemeral-p | |
118 (nnweb-write-active) | |
119 (nnweb-write-overview group))) | |
120 | |
121 (deffoo nnweb-request-group (group &optional server dont-check) | |
122 (nnweb-possibly-change-server nil server) | |
123 (when (and group | |
124 (not (equal group nnweb-group)) | |
125 (not nnweb-ephemeral-p)) | |
126 (let ((info (assoc group nnweb-group-alist))) | |
127 (setq nnweb-group group) | |
128 (setq nnweb-type (nth 2 info)) | |
129 (setq nnweb-search (nth 3 info)) | |
130 (unless dont-check | |
131 (nnweb-read-overview group)))) | |
132 (cond | |
133 ((not nnweb-articles) | |
134 (nnheader-report 'nnweb "No matching articles")) | |
135 (t | |
136 (let ((active (if nnweb-ephemeral-p | |
137 (cons (caar nnweb-articles) | |
138 (caar (last nnweb-articles))) | |
139 (cadr (assoc group nnweb-group-alist))))) | |
140 (nnheader-report 'nnweb "Opened group %s" group) | |
141 (nnheader-insert | |
142 "211 %d %d %d %s\n" (length nnweb-articles) | |
143 (car active) (cdr active) group))))) | |
144 | |
145 (deffoo nnweb-close-group (group &optional server) | |
146 (nnweb-possibly-change-server group server) | |
147 (when (gnus-buffer-live-p nnweb-buffer) | |
148 (save-excursion | |
149 (set-buffer nnweb-buffer) | |
150 (set-buffer-modified-p nil) | |
151 (kill-buffer nnweb-buffer))) | |
152 t) | |
153 | |
154 (deffoo nnweb-request-article (article &optional group server buffer) | |
155 (nnweb-possibly-change-server group server) | |
156 (save-excursion | |
157 (set-buffer (or buffer nntp-server-buffer)) | |
158 (let* ((header (cadr (assq article nnweb-articles))) | |
159 (url (and header (mail-header-xref header)))) | |
160 (when (or (and url | |
161 (nnweb-fetch-url url)) | |
162 (and (stringp article) | |
163 (nnweb-definition 'id t) | |
164 (let ((fetch (nnweb-definition 'id)) | |
165 art) | |
166 (when (string-match "^<\\(.*\\)>$" article) | |
167 (setq art (match-string 1 article))) | |
168 (and fetch | |
169 art | |
170 (nnweb-fetch-url | |
171 (format fetch article)))))) | |
172 (unless nnheader-callback-function | |
173 (funcall (nnweb-definition 'article)) | |
174 (nnweb-decode-entities)) | |
175 (nnheader-report 'nnweb "Fetched article %s" article) | |
176 t)))) | |
177 | |
178 (deffoo nnweb-close-server (&optional server) | |
179 (when (and (nnweb-server-opened server) | |
180 (gnus-buffer-live-p nnweb-buffer)) | |
181 (save-excursion | |
182 (set-buffer nnweb-buffer) | |
183 (set-buffer-modified-p nil) | |
184 (kill-buffer nnweb-buffer))) | |
185 (nnoo-close-server 'nnweb server)) | |
186 | |
187 (deffoo nnweb-request-list (&optional server) | |
188 (nnweb-possibly-change-server nil server) | |
189 (save-excursion | |
190 (set-buffer nntp-server-buffer) | |
191 (nnmail-generate-active nnweb-group-alist) | |
192 t)) | |
193 | |
194 (deffoo nnweb-request-update-info (group info &optional server) | |
195 (nnweb-possibly-change-server group server) | |
196 ;;(setcar (cddr info) nil) | |
197 ) | |
198 | |
199 (deffoo nnweb-asynchronous-p () | |
200 t) | |
201 | |
202 (deffoo nnweb-request-create-group (group &optional server args) | |
203 (nnweb-possibly-change-server nil server) | |
204 (nnweb-request-delete-group group) | |
205 (push `(,group ,(cons 1 0) ,@args) nnweb-group-alist) | |
206 (nnweb-write-active) | |
207 t) | |
208 | |
209 (deffoo nnweb-request-delete-group (group &optional force server) | |
210 (nnweb-possibly-change-server group server) | |
211 (gnus-delete-assoc group nnweb-group-alist) | |
212 (gnus-delete-file (nnweb-overview-file group)) | |
213 t) | |
214 | |
215 (nnoo-define-skeleton nnweb) | |
216 | |
217 ;;; Internal functions | |
218 | |
219 (defun nnweb-read-overview (group) | |
220 "Read the overview of GROUP and build the map." | |
221 (when (file-exists-p (nnweb-overview-file group)) | |
222 (nnheader-temp-write nil | |
223 (nnheader-insert-file-contents (nnweb-overview-file group)) | |
224 (goto-char (point-min)) | |
225 (let (header) | |
226 (while (not (eobp)) | |
227 (setq header (nnheader-parse-nov)) | |
228 (forward-line 1) | |
229 (push (list (mail-header-number header) | |
230 header (mail-header-xref header)) | |
231 nnweb-articles) | |
232 (nnweb-set-hashtb header (car nnweb-articles))))))) | |
233 | |
234 (defun nnweb-write-overview (group) | |
235 "Write the overview file for GROUP." | |
236 (nnheader-temp-write (nnweb-overview-file group) | |
237 (let ((articles nnweb-articles)) | |
238 (while articles | |
239 (nnheader-insert-nov (cadr (pop articles))))))) | |
240 | |
241 (defun nnweb-set-hashtb (header data) | |
242 (gnus-sethash (nnweb-identifier (mail-header-xref header)) | |
243 data nnweb-hashtb)) | |
244 | |
245 (defun nnweb-get-hashtb (url) | |
246 (gnus-gethash (nnweb-identifier url) nnweb-hashtb)) | |
247 | |
248 (defun nnweb-identifier (ident) | |
249 (funcall (nnweb-definition 'identifier) ident)) | |
250 | |
251 (defun nnweb-overview-file (group) | |
252 "Return the name of the overview file of GROUP." | |
253 (nnheader-concat nnweb-directory group ".overview")) | |
254 | |
255 (defun nnweb-write-active () | |
256 "Save the active file." | |
257 (nnheader-temp-write (nnheader-concat nnweb-directory "active") | |
258 (prin1 `(setq nnweb-group-alist ',nnweb-group-alist) (current-buffer)))) | |
259 | |
260 (defun nnweb-read-active () | |
261 "Read the active file." | |
262 (load (nnheader-concat nnweb-directory "active") t t t)) | |
263 | |
264 (defun nnweb-definition (type &optional noerror) | |
265 "Return the definition of TYPE." | |
266 (let ((def (cdr (assq type (assq nnweb-type nnweb-type-definition))))) | |
267 (when (and (not def) | |
268 (not noerror)) | |
269 (error "Undefined definition %s" type)) | |
270 def)) | |
271 | |
272 (defun nnweb-possibly-change-server (&optional group server) | |
273 (nnweb-init server) | |
274 (when server | |
275 (unless (nnweb-server-opened server) | |
276 (nnweb-open-server server))) | |
277 (unless nnweb-group-alist | |
278 (nnweb-read-active)) | |
279 (when group | |
280 (when (and (not nnweb-ephemeral-p) | |
281 (not (equal group nnweb-group))) | |
282 (nnweb-request-group group nil t)))) | |
283 | |
284 (defun nnweb-init (server) | |
285 "Initialize buffers and such." | |
286 (unless (gnus-buffer-live-p nnweb-buffer) | |
287 (setq nnweb-buffer | |
288 (save-excursion | |
289 (nnheader-set-temp-buffer | |
290 (format " *nnweb %s %s %s*" nnweb-type nnweb-search server)))))) | |
291 | |
292 (defun nnweb-fetch-url (url) | |
293 (save-excursion | |
294 (if (not nnheader-callback-function) | |
295 (let ((buf (current-buffer))) | |
296 (save-excursion | |
297 (set-buffer nnweb-buffer) | |
298 (erase-buffer) | |
19969
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
299 (url-insert-file-contents url) |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
300 (copy-to-buffer buf (point-min) (point-max)) |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
301 t)) |
17493 | 302 (nnweb-url-retrieve-asynch |
303 url 'nnweb-callback (current-buffer) nnheader-callback-function) | |
304 t))) | |
305 | |
306 (defun nnweb-callback (buffer callback) | |
307 (when (gnus-buffer-live-p url-working-buffer) | |
308 (save-excursion | |
309 (set-buffer url-working-buffer) | |
310 (funcall (nnweb-definition 'article)) | |
311 (nnweb-decode-entities) | |
312 (set-buffer buffer) | |
313 (goto-char (point-max)) | |
314 (insert-buffer-substring url-working-buffer)) | |
315 (funcall callback t) | |
316 (gnus-kill-buffer url-working-buffer))) | |
317 | |
318 (defun nnweb-url-retrieve-asynch (url callback &rest data) | |
319 (let ((url-request-method "GET") | |
320 (old-asynch url-be-asynchronous) | |
321 (url-request-data nil) | |
322 (url-request-extra-headers nil) | |
323 (url-working-buffer (generate-new-buffer-name " *nnweb*"))) | |
324 (setq-default url-be-asynchronous t) | |
325 (save-excursion | |
326 (set-buffer (get-buffer-create url-working-buffer)) | |
327 (setq url-current-callback-data data | |
328 url-be-asynchronous t | |
329 url-current-callback-func callback) | |
330 (url-retrieve url)) | |
331 (setq-default url-be-asynchronous old-asynch))) | |
332 | |
333 (defun nnweb-encode-www-form-urlencoded (pairs) | |
334 "Return PAIRS encoded for forms." | |
335 (mapconcat | |
336 (function | |
337 (lambda (data) | |
338 (concat (w3-form-encode-xwfu (car data)) "=" | |
339 (w3-form-encode-xwfu (cdr data))))) | |
340 pairs "&")) | |
341 | |
342 (defun nnweb-fetch-form (url pairs) | |
343 (let ((url-request-data (nnweb-encode-www-form-urlencoded pairs)) | |
344 (url-request-method "POST") | |
345 (url-request-extra-headers | |
346 '(("Content-type" . "application/x-www-form-urlencoded")))) | |
347 (url-insert-file-contents url) | |
348 (setq buffer-file-name nil)) | |
349 t) | |
350 | |
351 (defun nnweb-decode-entities () | |
352 (goto-char (point-min)) | |
353 (while (re-search-forward "&\\([a-z]+\\);" nil t) | |
354 (replace-match (char-to-string (or (cdr (assq (intern (match-string 1)) | |
19969
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
355 w3-html-entities)) |
17493 | 356 ?#)) |
357 t t))) | |
358 | |
359 (defun nnweb-remove-markup () | |
360 (goto-char (point-min)) | |
361 (while (search-forward "<!--" nil t) | |
362 (delete-region (match-beginning 0) | |
363 (or (search-forward "-->" nil t) | |
364 (point-max)))) | |
365 (goto-char (point-min)) | |
366 (while (re-search-forward "<[^>]+>" nil t) | |
367 (replace-match "" t t))) | |
368 | |
369 ;;; | |
370 ;;; DejaNews functions. | |
371 ;;; | |
372 | |
373 (defun nnweb-dejanews-create-mapping () | |
374 "Perform the search and create an number-to-url alist." | |
375 (save-excursion | |
376 (set-buffer nnweb-buffer) | |
377 (erase-buffer) | |
378 (when (funcall (nnweb-definition 'search) nnweb-search) | |
379 (let ((i 0) | |
380 (more t) | |
381 (case-fold-search t) | |
382 (active (or (cadr (assoc nnweb-group nnweb-group-alist)) | |
383 (cons 1 0))) | |
384 Subject Score Date Newsgroup Author | |
385 map url) | |
386 (while more | |
387 ;; Go through all the article hits on this page. | |
388 (goto-char (point-min)) | |
389 (nnweb-decode-entities) | |
390 (goto-char (point-min)) | |
391 (while (re-search-forward "^ +[0-9]+\\." nil t) | |
392 (narrow-to-region | |
393 (point) | |
394 (cond ((re-search-forward "^ +[0-9]+\\." nil t) | |
395 (match-beginning 0)) | |
396 ((search-forward "\n\n" nil t) | |
397 (point)) | |
398 (t | |
399 (point-max)))) | |
400 (goto-char (point-min)) | |
401 (when (looking-at ".*HREF=\"\\([^\"]+\\)\"") | |
402 (setq url (match-string 1))) | |
403 (nnweb-remove-markup) | |
404 (goto-char (point-min)) | |
405 (while (search-forward "\t" nil t) | |
406 (replace-match " ")) | |
407 (goto-char (point-min)) | |
408 (while (re-search-forward "^ +\\([^:]+\\): +\\(.*\\)$" nil t) | |
409 (set (intern (match-string 1)) (match-string 2))) | |
410 (widen) | |
411 (when (string-match "#[0-9]+/[0-9]+ *$" Subject) | |
412 (setq Subject (substring Subject 0 (match-beginning 0)))) | |
413 (incf i) | |
414 (unless (nnweb-get-hashtb url) | |
415 (push | |
416 (list | |
417 (incf (cdr active)) | |
418 (make-full-mail-header | |
419 (cdr active) (concat "(" Newsgroup ") " Subject) Author Date | |
420 (concat "<" (nnweb-identifier url) "@dejanews>") | |
421 nil 0 (string-to-int Score) url)) | |
422 map) | |
423 (nnweb-set-hashtb (cadar map) (car map)))) | |
424 ;; See whether there is a "Get next 20 hits" button here. | |
425 (if (or (not (re-search-forward | |
426 "HREF=\"\\([^\"]+\\)\">Get next" nil t)) | |
427 (>= i nnweb-max-hits)) | |
428 (setq more nil) | |
429 ;; Yup -- fetch it. | |
430 (setq more (match-string 1)) | |
431 (erase-buffer) | |
432 (url-insert-file-contents more))) | |
433 ;; Return the articles in the right order. | |
434 (setq nnweb-articles | |
435 (sort (nconc nnweb-articles map) | |
436 (lambda (s1 s2) (< (car s1) (car s2))))))))) | |
437 | |
438 (defun nnweb-dejanews-wash-article () | |
439 (let ((case-fold-search t)) | |
440 (goto-char (point-min)) | |
441 (re-search-forward "<PRE>" nil t) | |
442 (delete-region (point-min) (point)) | |
443 (re-search-forward "</PRE>" nil t) | |
444 (delete-region (point) (point-max)) | |
445 (nnweb-remove-markup) | |
446 (goto-char (point-min)) | |
447 (while (and (looking-at " *$") | |
448 (not (eobp))) | |
449 (gnus-delete-line)) | |
450 (while (looking-at "\\(^[^ ]+:\\) *") | |
451 (replace-match "\\1 " t) | |
452 (forward-line 1)) | |
453 (when (re-search-forward "\n\n+" nil t) | |
19969
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
454 (replace-match "\n" t t)) |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
455 (goto-char (point-min)) |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
456 (when (search-forward "[More Headers]" nil t) |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
457 (replace-match "" t t)))) |
17493 | 458 |
459 (defun nnweb-dejanews-search (search) | |
460 (nnweb-fetch-form | |
461 (nnweb-definition 'address) | |
462 `(("query" . ,search) | |
463 ("defaultOp" . "AND") | |
464 ("svcclass" . "dncurrent") | |
465 ("maxhits" . "100") | |
466 ("format" . "verbose") | |
467 ("threaded" . "0") | |
468 ("showsort" . "score") | |
469 ("agesign" . "1") | |
470 ("ageweight" . "1"))) | |
471 t) | |
472 | |
473 (defun nnweb-dejanews-identity (url) | |
474 "Return an unique identifier based on URL." | |
475 (if (string-match "recnum=\\([0-9]+\\)" url) | |
476 (match-string 1 url) | |
477 url)) | |
478 | |
479 ;;; | |
480 ;;; InReference | |
481 ;;; | |
482 | |
483 (defun nnweb-reference-create-mapping () | |
484 "Perform the search and create an number-to-url alist." | |
485 (save-excursion | |
486 (set-buffer nnweb-buffer) | |
487 (erase-buffer) | |
488 (when (funcall (nnweb-definition 'search) nnweb-search) | |
489 (let ((i 0) | |
490 (more t) | |
491 (case-fold-search t) | |
492 (active (or (cadr (assoc nnweb-group nnweb-group-alist)) | |
493 (cons 1 0))) | |
494 Subject Score Date Newsgroups From Message-ID | |
495 map url) | |
496 (while more | |
497 ;; Go through all the article hits on this page. | |
498 (goto-char (point-min)) | |
499 (search-forward "</pre><hr>" nil t) | |
500 (delete-region (point-min) (point)) | |
501 ;(nnweb-decode-entities) | |
502 (goto-char (point-min)) | |
503 (while (re-search-forward "^ +[0-9]+\\." nil t) | |
504 (narrow-to-region | |
505 (point) | |
506 (if (re-search-forward "^$" nil t) | |
507 (match-beginning 0) | |
508 (point-max))) | |
509 (goto-char (point-min)) | |
510 (when (looking-at ".*href=\"\\([^\"]+\\)\"") | |
511 (setq url (match-string 1))) | |
512 (nnweb-remove-markup) | |
513 (goto-char (point-min)) | |
514 (while (search-forward "\t" nil t) | |
515 (replace-match " ")) | |
516 (goto-char (point-min)) | |
517 (while (re-search-forward "^\\([^:]+\\): \\(.*\\)$" nil t) | |
518 (set (intern (match-string 1)) (match-string 2))) | |
519 (widen) | |
520 (search-forward "</pre>" nil t) | |
521 (incf i) | |
522 (unless (nnweb-get-hashtb url) | |
523 (push | |
524 (list | |
525 (incf (cdr active)) | |
526 (make-full-mail-header | |
527 (cdr active) (concat "(" Newsgroups ") " Subject) From Date | |
528 Message-ID | |
529 nil 0 (string-to-int Score) url)) | |
530 map) | |
531 (nnweb-set-hashtb (cadar map) (car map)))) | |
532 (setq more nil)) | |
533 ;; Return the articles in the right order. | |
534 (setq nnweb-articles | |
535 (sort (nconc nnweb-articles map) | |
536 (lambda (s1 s2) (< (car s1) (car s2))))))))) | |
537 | |
538 (defun nnweb-reference-wash-article () | |
539 (let ((case-fold-search t)) | |
540 (goto-char (point-min)) | |
541 (re-search-forward "^</center><hr>" nil t) | |
542 (delete-region (point-min) (point)) | |
543 (search-forward "<pre>" nil t) | |
544 (forward-line -1) | |
545 (let ((body (point-marker))) | |
546 (search-forward "</pre>" nil t) | |
547 (delete-region (point) (point-max)) | |
548 (nnweb-remove-markup) | |
549 (goto-char (point-min)) | |
550 (while (looking-at " *$") | |
551 (gnus-delete-line)) | |
552 (narrow-to-region (point-min) body) | |
553 (while (and (re-search-forward "^$" nil t) | |
554 (not (eobp))) | |
555 (gnus-delete-line)) | |
556 (goto-char (point-min)) | |
557 (while (looking-at "\\(^[^ ]+:\\) *") | |
558 (replace-match "\\1 " t) | |
559 (forward-line 1)) | |
560 (goto-char (point-min)) | |
561 (when (re-search-forward "^References:" nil t) | |
562 (narrow-to-region | |
563 (point) (if (re-search-forward "^$\\|^[^:]+:" nil t) | |
564 (match-beginning 0) | |
565 (point-max))) | |
566 (goto-char (point-min)) | |
567 (while (not (eobp)) | |
568 (unless (looking-at "References") | |
569 (insert "\t") | |
570 (forward-line 1))) | |
571 (goto-char (point-min)) | |
572 (while (search-forward "," nil t) | |
573 (replace-match " " t t))) | |
574 (widen) | |
575 (set-marker body nil)))) | |
576 | |
577 (defun nnweb-reference-search (search) | |
19969
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
578 (url-insert-file-contents |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
579 (concat |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
580 (nnweb-definition 'address) |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
581 "?" |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
582 (nnweb-encode-www-form-urlencoded |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
583 `(("search" . "advanced") |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
584 ("querytext" . ,search) |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
585 ("subj" . "") |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
586 ("name" . "") |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
587 ("login" . "") |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
588 ("host" . "") |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
589 ("organization" . "") |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
590 ("groups" . "") |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
591 ("keywords" . "") |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
592 ("choice" . "Search") |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
593 ("startmonth" . "Jul") |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
594 ("startday" . "25") |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
595 ("startyear" . "1996") |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
596 ("endmonth" . "Aug") |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
597 ("endday" . "24") |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
598 ("endyear" . "1996") |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
599 ("mode" . "Quick") |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
600 ("verbosity" . "Verbose") |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
601 ("ranking" . "Relevance") |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
602 ("first" . "1") |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
603 ("last" . "25") |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
604 ("score" . "50"))))) |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
605 (setq buffer-file-name nil) |
17493 | 606 t) |
607 | |
608 ;;; | |
609 ;;; Alta Vista | |
610 ;;; | |
611 | |
612 (defun nnweb-altavista-create-mapping () | |
613 "Perform the search and create an number-to-url alist." | |
614 (save-excursion | |
615 (set-buffer nnweb-buffer) | |
616 (erase-buffer) | |
617 (let ((part 0)) | |
618 (when (funcall (nnweb-definition 'search) nnweb-search part) | |
619 (let ((i 0) | |
620 (more t) | |
621 (case-fold-search t) | |
622 (active (or (cadr (assoc nnweb-group nnweb-group-alist)) | |
623 (cons 1 0))) | |
624 subject date from id group | |
625 map url) | |
626 (while more | |
627 ;; Go through all the article hits on this page. | |
628 (goto-char (point-min)) | |
629 (search-forward "<dt>" nil t) | |
630 (delete-region (point-min) (match-beginning 0)) | |
631 (goto-char (point-min)) | |
632 (while (search-forward "<dt>" nil t) | |
633 (replace-match "\n<blubb>")) | |
634 (nnweb-decode-entities) | |
635 (goto-char (point-min)) | |
636 (while (re-search-forward "<blubb>.*href=\"\\([^\"]+\\)\"><strong>\\([^>]*\\)</strong></a><dd>\\([^-]+\\)- <b>\\([^<]+\\)<.*href=\"news:\\([^\"]+\\)\">.*\">\\(.+\\)</a><P>" | |
637 nil t) | |
638 (setq url (match-string 1) | |
639 subject (match-string 2) | |
640 date (match-string 3) | |
641 group (match-string 4) | |
642 id (concat "<" (match-string 5) ">") | |
643 from (match-string 6)) | |
644 (incf i) | |
645 (unless (nnweb-get-hashtb url) | |
646 (push | |
647 (list | |
648 (incf (cdr active)) | |
649 (make-full-mail-header | |
650 (cdr active) (concat "(" group ") " subject) from date | |
651 id nil 0 0 url)) | |
652 map) | |
653 (nnweb-set-hashtb (cadar map) (car map)))) | |
654 ;; See if we want more. | |
655 (when (or (not nnweb-articles) | |
656 (>= i nnweb-max-hits) | |
657 (not (funcall (nnweb-definition 'search) | |
658 nnweb-search (incf part)))) | |
659 (setq more nil))) | |
660 ;; Return the articles in the right order. | |
661 (setq nnweb-articles | |
662 (sort (nconc nnweb-articles map) | |
663 (lambda (s1 s2) (< (car s1) (car s2)))))))))) | |
664 | |
665 (defun nnweb-altavista-wash-article () | |
666 (goto-char (point-min)) | |
667 (let ((case-fold-search t)) | |
668 (when (re-search-forward "^<strong>" nil t) | |
669 (delete-region (point-min) (match-beginning 0))) | |
670 (goto-char (point-min)) | |
671 (while (looking-at "<strong>\\([^ ]+\\) +</strong> +\\(.*\\)$") | |
672 (replace-match "\\1: \\2" t) | |
673 (forward-line 1)) | |
674 (when (re-search-backward "^References:" nil t) | |
675 (narrow-to-region (point) (progn (forward-line 1) (point))) | |
676 (goto-char (point-min)) | |
677 (while (re-search-forward "<A.*\\?id@\\([^\"]+\\)\">[0-9]+</A>" nil t) | |
678 (replace-match "<\\1> " t))) | |
679 (widen) | |
680 (nnweb-remove-markup))) | |
681 | |
682 (defun nnweb-altavista-search (search &optional part) | |
19969
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
683 (url-insert-file-contents |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
684 (concat |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
685 (nnweb-definition 'address) |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
686 "?" |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
687 (nnweb-encode-www-form-urlencoded |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
688 `(("pg" . "aq") |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
689 ("what" . "news") |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
690 ,@(when part `(("stq" . ,(int-to-string (* part 30))))) |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
691 ("fmt" . "d") |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
692 ("q" . ,search) |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
693 ("r" . "") |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
694 ("d0" . "") |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
695 ("d1" . ""))))) |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
696 (setq buffer-file-name nil) |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
697 t) |
17493 | 698 |
699 (provide 'nnweb) | |
700 | |
701 ;;; nnweb.el ends here |