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