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