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