*** 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@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 '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://x8.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://x8.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 999
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-pull 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 "0") 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 "^ <P>\n" nil t)
390             (narrow-to-region
391              (point)
392              (cond ((re-search-forward "^ <P>\n" 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             (looking-at ".*HREF=\"\\([^\"]+\\)\"\\(.*\\)")
400             (setq url (match-string 1))
401             (let ((begin (point)))
402               (nnweb-remove-markup)
403               (goto-char begin)
404               (while (search-forward "\t" nil t)
405                 (replace-match " "))
406               (goto-char begin)
407               (end-of-line)
408               (setq Subject (buffer-substring begin (point)))
409               (if (re-search-forward
410                    "^ Newsgroup: \\(.*\\)\n Posted on \\([0-9/]+\\) by \\(.*\\)$" nil t)
411                   (setq Newsgroup (match-string 1)
412                         Date (match-string 2)
413                         Author (match-string 3))))
414             (widen)
415             (incf i)
416             (unless (nnweb-get-hashtb url)
417               (push
418                (list
419                 (incf (cdr active))
420                 (make-full-mail-header
421                  (cdr active) Subject Author Date
422                  (concat "<" (nnweb-identifier url) "@dejanews>")
423                  nil 0 (string-to-int Score) url))
424                map)
425               (nnweb-set-hashtb (cadar map) (car map))))
426           ;; See whether there is a "Get next 20 hits" button here.
427           (if (or (not (re-search-forward
428                         "HREF=\"\\([^\"]+\\)\"[<>b]+Next result" nil t))
429                   (>= i nnweb-max-hits))
430               (setq more nil)
431             ;; Yup -- fetch it.
432             (setq more (match-string 1))
433             (erase-buffer)
434             (url-insert-file-contents more)))
435         ;; Return the articles in the right order.
436         (setq nnweb-articles
437               (sort (nconc nnweb-articles map) 'car-less-than-car))))))
438
439 (defun nnweb-dejanews-wash-article ()
440   (let ((case-fold-search t))
441     (goto-char (point-min))
442     (re-search-forward "<PRE>" nil t)
443     (delete-region (point-min) (point))
444     (re-search-forward "</PRE>" nil t)
445     (delete-region (point) (point-max))
446     (nnweb-remove-markup)
447     (goto-char (point-min))
448     (while (and (looking-at " *$")
449                 (not (eobp)))
450       (gnus-delete-line))
451     (while (looking-at "\\(^[^ ]+:\\) *")
452       (replace-match "\\1 " t)
453       (forward-line 1))
454     (when (re-search-forward "\n\n+" nil t)
455       (replace-match "\n" t t))
456     (goto-char (point-min))
457     (when (search-forward "[More Headers]" nil t)
458       (replace-match "" t t))))
459
460 (defun nnweb-dejanews-search (search)
461   (nnweb-fetch-form
462    (nnweb-definition 'address)
463    `(("query" . ,search)
464      ("defaultOp" . "AND")
465      ("svcclass" . "dncurrent")
466      ("maxhits" . "100")
467      ("format" . "verbose2")
468      ("threaded" . "0")
469      ("showsort" . "date")
470      ("agesign" . "1")
471      ("ageweight" . "1")))
472   t)
473
474 (defun nnweb-dejanewsold-search (search)
475   (nnweb-fetch-form
476    (nnweb-definition 'address)
477    `(("query" . ,search)
478      ("defaultOp" . "AND")
479      ("svcclass" . "dnold")
480      ("maxhits" . "100")
481      ("format" . "verbose2")
482      ("threaded" . "0")
483      ("showsort" . "date")
484      ("agesign" . "1")
485      ("ageweight" . "1")))
486   t)
487
488 (defun nnweb-dejanews-identity (url)
489   "Return an unique identifier based on URL."
490   (if (string-match "recnum=\\([0-9]+\\)" url)
491       (match-string 1 url)
492     url))
493
494 ;;;
495 ;;; InReference
496 ;;;
497
498 (defun nnweb-reference-create-mapping ()
499   "Perform the search and create an number-to-url alist."
500   (save-excursion
501     (set-buffer nnweb-buffer)
502     (erase-buffer)
503     (when (funcall (nnweb-definition 'search) nnweb-search)
504       (let ((i 0)
505             (more t)
506             (case-fold-search t)
507             (active (or (cadr (assoc nnweb-group nnweb-group-alist))
508                         (cons 1 0)))
509             Subject Score Date Newsgroups From Message-ID
510             map url)
511         (while more
512           ;; Go through all the article hits on this page.
513           (goto-char (point-min))
514           (search-forward "</pre><hr>" nil t)
515           (delete-region (point-min) (point))
516                                         ;(nnweb-decode-entities)
517           (goto-char (point-min))
518           (while (re-search-forward "^ +[0-9]+\\." nil t)
519             (narrow-to-region
520              (point)
521              (if (re-search-forward "^$" nil t)
522                  (match-beginning 0)
523                (point-max)))
524             (goto-char (point-min))
525             (when (looking-at ".*href=\"\\([^\"]+\\)\"")
526               (setq url (match-string 1)))
527             (nnweb-remove-markup)
528             (goto-char (point-min))
529             (while (search-forward "\t" nil t)
530               (replace-match " "))
531             (goto-char (point-min))
532             (while (re-search-forward "^\\([^:]+\\): \\(.*\\)$" nil t)
533               (set (intern (match-string 1)) (match-string 2)))
534             (widen)
535             (search-forward "</pre>" nil t)
536             (incf i)
537             (unless (nnweb-get-hashtb url)
538               (push
539                (list
540                 (incf (cdr active))
541                 (make-full-mail-header
542                  (cdr active) (concat  "(" Newsgroups ") " Subject) From Date
543                  Message-ID
544                  nil 0 (string-to-int Score) url))
545                map)
546               (nnweb-set-hashtb (cadar map) (car map))))
547           (setq more nil))
548         ;; Return the articles in the right order.
549         (setq nnweb-articles
550               (sort (nconc nnweb-articles map) 'car-less-than-car))))))
551
552 (defun nnweb-reference-wash-article ()
553   (let ((case-fold-search t))
554     (goto-char (point-min))
555     (re-search-forward "^</center><hr>" nil t)
556     (delete-region (point-min) (point))
557     (search-forward "<pre>" nil t)
558     (forward-line -1)
559     (let ((body (point-marker)))
560       (search-forward "</pre>" nil t)
561       (delete-region (point) (point-max))
562       (nnweb-remove-markup)
563       (goto-char (point-min))
564       (while (looking-at " *$")
565         (gnus-delete-line))
566       (narrow-to-region (point-min) body)
567       (while (and (re-search-forward "^$" nil t)
568                   (not (eobp)))
569         (gnus-delete-line))
570       (goto-char (point-min))
571       (while (looking-at "\\(^[^ ]+:\\) *")
572         (replace-match "\\1 " t)
573         (forward-line 1))
574       (goto-char (point-min))
575       (when (re-search-forward "^References:" nil t)
576         (narrow-to-region
577          (point) (if (re-search-forward "^$\\|^[^:]+:" nil t)
578                      (match-beginning 0)
579                    (point-max)))
580         (goto-char (point-min))
581         (while (not (eobp))
582           (unless (looking-at "References")
583             (insert "\t")
584             (forward-line 1)))
585         (goto-char (point-min))
586         (while (search-forward "," nil t)
587           (replace-match " " t t)))
588       (widen)
589       (set-marker body nil))))
590
591 (defun nnweb-reference-search (search)
592   (url-insert-file-contents
593    (concat
594     (nnweb-definition 'address)
595     "?"
596     (nnweb-encode-www-form-urlencoded
597      `(("search" . "advanced")
598        ("querytext" . ,search)
599        ("subj" . "")
600        ("name" . "")
601        ("login" . "")
602        ("host" . "")
603        ("organization" . "")
604        ("groups" . "")
605        ("keywords" . "")
606        ("choice" . "Search")
607        ("startmonth" . "Jul")
608        ("startday" . "25")
609        ("startyear" . "1996")
610        ("endmonth" . "Aug")
611        ("endday" . "24")
612        ("endyear" . "1996")
613        ("mode" . "Quick")
614        ("verbosity" . "Verbose")
615        ("ranking" . "Relevance")
616        ("first" . "1")
617        ("last" . "25")
618        ("score" . "50")))))
619   (setq buffer-file-name nil)
620   t)
621
622 ;;;
623 ;;; Alta Vista
624 ;;;
625
626 (defun nnweb-altavista-create-mapping ()
627   "Perform the search and create an number-to-url alist."
628   (save-excursion
629     (set-buffer nnweb-buffer)
630     (erase-buffer)
631     (let ((part 0))
632       (when (funcall (nnweb-definition 'search) nnweb-search part)
633         (let ((i 0)
634               (more t)
635               (case-fold-search t)
636               (active (or (cadr (assoc nnweb-group nnweb-group-alist))
637                           (cons 1 0)))
638               subject date from id group
639               map url)
640           (while more
641             ;; Go through all the article hits on this page.
642             (goto-char (point-min))
643             (search-forward "<dt>" nil t)
644             (delete-region (point-min) (match-beginning 0))
645             (goto-char (point-min))
646             (while (search-forward "<dt>" nil t)
647               (replace-match "\n<blubb>"))
648             (nnweb-decode-entities)
649             (goto-char (point-min))
650             (while (re-search-forward "<blubb>.*href=\"\\([^\"]+\\)\"><strong>\\([^>]*\\)</strong></a><dd>\\([^-]+\\)- <b>\\([^<]+\\)<.*href=\"news:\\([^\"]+\\)\">.*\">\\(.+\\)</a><P>"
651                                       nil t)
652               (setq url (match-string 1)
653                     subject (match-string 2)
654                     date (match-string 3)
655                     group (match-string 4)
656                     id (concat "<" (match-string 5) ">")
657                     from (match-string 6))
658               (incf i)
659               (unless (nnweb-get-hashtb url)
660                 (push
661                  (list
662                   (incf (cdr active))
663                   (make-full-mail-header
664                    (cdr active) (concat  "(" group ") " subject) from date
665                    id nil 0 0 url))
666                  map)
667                 (nnweb-set-hashtb (cadar map) (car map))))
668             ;; See if we want more.
669             (when (or (not nnweb-articles)
670                       (>= i nnweb-max-hits)
671                       (not (funcall (nnweb-definition 'search)
672                                     nnweb-search (incf part))))
673               (setq more nil)))
674           ;; Return the articles in the right order.
675           (setq nnweb-articles
676                 (sort (nconc nnweb-articles map) 'car-less-than-car)))))))
677
678 (defun nnweb-altavista-wash-article ()
679   (goto-char (point-min))
680   (let ((case-fold-search t))
681     (when (re-search-forward "^<strong>" nil t)
682       (delete-region (point-min) (match-beginning 0)))
683     (goto-char (point-min))
684     (while (looking-at "<strong>\\([^ ]+\\) +</strong> +\\(.*\\)$")
685       (replace-match "\\1: \\2" t)
686       (forward-line 1))
687     (when (re-search-backward "^References:" nil t)
688       (narrow-to-region (point) (progn (forward-line 1) (point)))
689       (goto-char (point-min))
690       (while (re-search-forward "<A.*\\?id@\\([^\"]+\\)\">[0-9]+</A>" nil t)
691         (replace-match "&lt;\\1&gt; " t)))
692     (widen)
693     (nnweb-remove-markup)))
694
695 (defun nnweb-altavista-search (search &optional part)
696   (url-insert-file-contents
697    (concat
698     (nnweb-definition 'address)
699     "?"
700     (nnweb-encode-www-form-urlencoded
701      `(("pg" . "aq")
702        ("what" . "news")
703        ,@(when part `(("stq" . ,(int-to-string (* part 30)))))
704        ("fmt" . "d")
705        ("q" . ,search)
706        ("r" . "")
707        ("d0" . "")
708        ("d1" . "")))))
709   (setq buffer-file-name nil)
710   t)
711
712 (provide 'nnweb)
713
714 ;;; nnweb.el ends here