1 ;;; nnweb.el --- retrieving articles via web search engines
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;; Note: You need to have `w3' installed for some functions to work.
31 (eval-when-compile (require 'cl))
32 (eval-when-compile (require 'gnus-clfns))
41 (autoload 'w3-parse-buffer "w3-parse")
45 (defvoo nnweb-directory (nnheader-concat gnus-directory "nnweb/")
46 "Where nnweb will save its files.")
48 (defvoo nnweb-type 'google
49 "What search engine type is being used.
50 Valid types include `google', `dejanews', `dejanewsold', `reference',
53 (defvar nnweb-type-definition
56 ;;(article . nnweb-google-wash-article)
57 ;;(id . "http://groups.google.com/groups?as_umsgid=%s")
59 (id . "http://groups.google.com/groups?selm=%s&output=gplain")
60 ;;(reference . nnweb-google-reference)
61 (reference . identity)
62 (map . nnweb-google-create-mapping)
63 (search . nnweb-google-search)
64 (address . "http://groups.google.com/groups")
65 (identifier . nnweb-google-identity))
66 (dejanews ;; alias of google
67 ;;(article . nnweb-google-wash-article)
68 ;;(id . "http://groups.google.com/groups?as_umsgid=%s")
70 (id . "http://groups.google.com/groups?selm=%s&output=gplain")
71 ;;(reference . nnweb-google-reference)
72 (reference . identity)
73 (map . nnweb-google-create-mapping)
74 (search . nnweb-google-search)
75 (address . "http://groups.google.com/groups")
76 (identifier . nnweb-google-identity))
78 ;;; (article . ignore)
79 ;;; (id . "http://search.dejanews.com/msgid.xp?MID=%s&fmt=text")
80 ;;; (map . nnweb-dejanews-create-mapping)
81 ;;; (search . nnweb-dejanews-search)
82 ;;; (address . "http://www.deja.com/=dnc/qs.xp")
83 ;;; (identifier . nnweb-dejanews-identity))
85 ;;; (article . ignore)
86 ;;; (map . nnweb-dejanews-create-mapping)
87 ;;; (search . nnweb-dejanewsold-search)
88 ;;; (address . "http://www.deja.com/dnquery.xp")
89 ;;; (identifier . nnweb-dejanews-identity))
91 (article . nnweb-reference-wash-article)
92 (map . nnweb-reference-create-mapping)
93 (search . nnweb-reference-search)
94 (address . "http://www.reference.com/cgi-bin/pn/go")
95 (identifier . identity))
97 (article . nnweb-altavista-wash-article)
98 (map . nnweb-altavista-create-mapping)
99 (search . nnweb-altavista-search)
100 (address . "http://www.altavista.digital.com/cgi-bin/query")
101 (id . "/cgi-bin/news?id@%s")
102 (identifier . identity)))
103 "Type-definition alist.")
105 (defvoo nnweb-search nil
106 "Search string to feed to DejaNews.")
108 (defvoo nnweb-max-hits 999
109 "Maximum number of hits to display.")
111 (defvoo nnweb-ephemeral-p nil
112 "Whether this nnweb server is ephemeral.")
114 ;;; Internal variables
116 (defvoo nnweb-articles nil)
117 (defvoo nnweb-buffer nil)
118 (defvoo nnweb-group-alist nil)
119 (defvoo nnweb-group nil)
120 (defvoo nnweb-hashtb nil)
122 ;;; Interface functions
124 (nnoo-define-basics nnweb)
126 (deffoo nnweb-retrieve-headers (articles &optional group server fetch-old)
127 (nnweb-possibly-change-server group server)
129 (set-buffer nntp-server-buffer)
131 (let (article header)
132 (mm-with-unibyte-current-buffer
133 (while (setq article (pop articles))
134 (when (setq header (cadr (assq article nnweb-articles)))
135 (nnheader-insert-nov header))))
138 (deffoo nnweb-request-scan (&optional group server)
139 (nnweb-possibly-change-server group server)
140 (if nnweb-ephemeral-p
141 (setq nnweb-hashtb (gnus-make-hashtable 4095)))
142 (funcall (nnweb-definition 'map))
143 (unless nnweb-ephemeral-p
145 (nnweb-write-overview group)))
147 (deffoo nnweb-request-group (group &optional server dont-check)
148 (nnweb-possibly-change-server nil server)
150 (not (equal group nnweb-group))
151 (not nnweb-ephemeral-p))
152 (setq nnweb-group group
154 (let ((info (assoc group nnweb-group-alist)))
156 (setq nnweb-type (nth 2 info))
157 (setq nnweb-search (nth 3 info))
159 (nnweb-read-overview group)))))
161 ((not nnweb-articles)
162 (nnheader-report 'nnweb "No matching articles"))
164 (let ((active (if nnweb-ephemeral-p
165 (cons (caar nnweb-articles)
166 (caar (last nnweb-articles)))
167 (cadr (assoc group nnweb-group-alist)))))
168 (nnheader-report 'nnweb "Opened group %s" group)
170 "211 %d %d %d %s\n" (length nnweb-articles)
171 (car active) (cdr active) group)))))
173 (deffoo nnweb-close-group (group &optional server)
174 (nnweb-possibly-change-server group server)
175 (when (gnus-buffer-live-p nnweb-buffer)
177 (set-buffer nnweb-buffer)
178 (set-buffer-modified-p nil)
179 (kill-buffer nnweb-buffer)))
182 (deffoo nnweb-request-article (article &optional group server buffer)
183 (nnweb-possibly-change-server group server)
185 (set-buffer (or buffer nntp-server-buffer))
186 (let* ((header (cadr (assq article nnweb-articles)))
187 (url (and header (mail-header-xref header))))
189 (mm-with-unibyte-current-buffer
190 (mm-url-insert url)))
191 (and (stringp article)
192 (nnweb-definition 'id t)
193 (let ((fetch (nnweb-definition 'id))
195 (when (string-match "^<\\(.*\\)>$" article)
196 (setq art (match-string 1 article)))
197 (when (and fetch art)
198 (setq url (format fetch art))
199 (mm-with-unibyte-current-buffer
201 (if (nnweb-definition 'reference t)
203 (funcall (nnweb-definition
204 'reference) article)))))))
205 (unless nnheader-callback-function
206 (funcall (nnweb-definition 'article)))
207 (nnheader-report 'nnweb "Fetched article %s" article)
208 (cons group (and (numberp article) article))))))
210 (deffoo nnweb-close-server (&optional server)
211 (when (and (nnweb-server-opened server)
212 (gnus-buffer-live-p nnweb-buffer))
214 (set-buffer nnweb-buffer)
215 (set-buffer-modified-p nil)
216 (kill-buffer nnweb-buffer)))
217 (nnoo-close-server 'nnweb server))
219 (deffoo nnweb-request-list (&optional server)
220 (nnweb-possibly-change-server nil server)
222 (set-buffer nntp-server-buffer)
223 (nnmail-generate-active nnweb-group-alist)
226 (deffoo nnweb-request-update-info (group info &optional server)
227 (nnweb-possibly-change-server group server))
229 (deffoo nnweb-asynchronous-p ()
232 (deffoo nnweb-request-create-group (group &optional server args)
233 (nnweb-possibly-change-server nil server)
234 (nnweb-request-delete-group group)
235 (push `(,group ,(cons 1 0) ,@args) nnweb-group-alist)
239 (deffoo nnweb-request-delete-group (group &optional force server)
240 (nnweb-possibly-change-server group server)
241 (gnus-pull group nnweb-group-alist t)
243 (gnus-delete-file (nnweb-overview-file group))
246 (nnoo-define-skeleton nnweb)
248 ;;; Internal functions
250 (defun nnweb-read-overview (group)
251 "Read the overview of GROUP and build the map."
252 (when (file-exists-p (nnweb-overview-file group))
253 (mm-with-unibyte-buffer
254 (nnheader-insert-file-contents (nnweb-overview-file group))
255 (goto-char (point-min))
258 (setq header (nnheader-parse-nov))
260 (push (list (mail-header-number header)
261 header (mail-header-xref header))
263 (nnweb-set-hashtb header (car nnweb-articles)))))))
265 (defun nnweb-write-overview (group)
266 "Write the overview file for GROUP."
267 (with-temp-file (nnweb-overview-file group)
268 (let ((articles nnweb-articles))
270 (nnheader-insert-nov (cadr (pop articles)))))))
272 (defun nnweb-set-hashtb (header data)
273 (gnus-sethash (nnweb-identifier (mail-header-xref header))
276 (defun nnweb-get-hashtb (url)
277 (gnus-gethash (nnweb-identifier url) nnweb-hashtb))
279 (defun nnweb-identifier (ident)
280 (funcall (nnweb-definition 'identifier) ident))
282 (defun nnweb-overview-file (group)
283 "Return the name of the overview file of GROUP."
284 (nnheader-concat nnweb-directory group ".overview"))
286 (defun nnweb-write-active ()
287 "Save the active file."
288 (gnus-make-directory nnweb-directory)
289 (with-temp-file (nnheader-concat nnweb-directory "active")
290 (prin1 `(setq nnweb-group-alist ',nnweb-group-alist) (current-buffer))))
292 (defun nnweb-read-active ()
293 "Read the active file."
294 (load (nnheader-concat nnweb-directory "active") t t t))
296 (defun nnweb-definition (type &optional noerror)
297 "Return the definition of TYPE."
298 (let ((def (cdr (assq type (assq nnweb-type nnweb-type-definition)))))
301 (error "Undefined definition %s" type))
304 (defun nnweb-possibly-change-server (&optional group server)
307 (unless (nnweb-server-opened server)
308 (nnweb-open-server server)))
309 (unless nnweb-group-alist
312 (setq nnweb-hashtb (gnus-make-hashtable 4095)))
314 (when (and (not nnweb-ephemeral-p)
315 (equal group nnweb-group))
316 (nnweb-request-group group nil t))))
318 (defun nnweb-init (server)
319 "Initialize buffers and such."
320 (unless (gnus-buffer-live-p nnweb-buffer)
324 (nnheader-set-temp-buffer
325 (format " *nnweb %s %s %s*"
326 nnweb-type nnweb-search server))
327 (current-buffer))))))
329 ;; (defun nnweb-fetch-url (url)
332 ;; (if (not nnheader-callback-function)
335 ;; (mm-enable-multibyte)
336 ;; (let ((coding-system-for-read 'binary)
337 ;; (coding-system-for-write 'binary)
338 ;; (input-coding-system 'binary)
339 ;; (output-coding-system 'binary)
340 ;; (default-process-coding-system 'binary))
341 ;; (nnweb-insert url))
342 ;; (setq buf (buffer-string)))
346 ;; (nnweb-url-retrieve-asynch
347 ;; url 'nnweb-callback (current-buffer) nnheader-callback-function)
350 ;; (defun nnweb-callback (buffer callback)
351 ;; (when (gnus-buffer-live-p url-working-buffer)
353 ;; (set-buffer url-working-buffer)
354 ;; (funcall (nnweb-definition 'article))
355 ;; (nnweb-decode-entities)
356 ;; (set-buffer buffer)
357 ;; (goto-char (point-max))
358 ;; (insert-buffer-substring url-working-buffer))
359 ;; (funcall callback t)
360 ;; (gnus-kill-buffer url-working-buffer)))
362 ;; (defun nnweb-url-retrieve-asynch (url callback &rest data)
363 ;; (let ((url-request-method "GET")
364 ;; (old-asynch url-be-asynchronous)
365 ;; (url-request-data nil)
366 ;; (url-request-extra-headers nil)
367 ;; (url-working-buffer (generate-new-buffer-name " *nnweb*")))
368 ;; (setq-default url-be-asynchronous t)
370 ;; (set-buffer (get-buffer-create url-working-buffer))
371 ;; (setq url-current-callback-data data
372 ;; url-be-asynchronous t
373 ;; url-current-callback-func callback)
374 ;; (url-retrieve url nil))
375 ;; (setq-default url-be-asynchronous old-asynch)))
377 ;; (if (fboundp 'url-retrieve-synchronously)
378 ;; (defun nnweb-url-retrieve-asynch (url callback &rest data)
379 ;; (url-retrieve url callback data)))
382 ;;; DejaNews functions.
385 (defun nnweb-dejanews-create-mapping ()
386 "Perform the search and create an number-to-url alist."
388 (set-buffer nnweb-buffer)
390 (when (funcall (nnweb-definition 'search) nnweb-search)
394 (active (or (cadr (assoc nnweb-group nnweb-group-alist))
397 map url parse a table group text)
399 ;; Go through all the article hits on this page.
400 (goto-char (point-min))
401 (setq parse (w3-parse-buffer (current-buffer))
402 table (nth 1 (nnweb-parse-find-all 'table parse)))
403 (dolist (row (nth 2 (car (nth 2 table))))
404 (setq a (nnweb-parse-find 'a row)
405 url (cdr (assq 'href (nth 1 a)))
406 text (nreverse (nnweb-text row)))
408 (setq subject (nth 4 text)
412 (if (string-match "\\([0-9]+\\)/\\([0-9]+\\)/\\([0-9]+\\)" date)
413 (setq date (format "%s %s 00:00:00 %s"
414 (car (rassq (string-to-number
415 (match-string 2 date))
417 (match-string 3 date)
418 (match-string 1 date)))
419 (setq date "Jan 1 00:00:00 0000"))
421 (setq url (concat url "&fmt=text"))
422 (when (string-match "&context=[^&]+" url)
423 (setq url (replace-match "" t t url)))
424 (unless (nnweb-get-hashtb url)
428 (make-full-mail-header
429 (cdr active) (concat subject " (" group ")") from date
430 (concat "<" (nnweb-identifier url) "@dejanews>")
433 (nnweb-set-hashtb (cadar map) (car map)))))
434 ;; See whether there is a "Get next 20 hits" button here.
435 (goto-char (point-min))
436 (if (or (not (re-search-forward
437 "HREF=\"\\([^\"]+\\)\"[<>b]+Next result" nil t))
438 (>= i nnweb-max-hits))
441 (setq more (match-string 1))
443 (mm-url-insert more)))
444 ;; Return the articles in the right order.
446 (sort (nconc nnweb-articles map) 'car-less-than-car))))))
448 (defun nnweb-dejanews-search (search)
451 (nnweb-definition 'address)
453 (mm-url-encode-www-form-urlencoded
455 ("svcclass" . "dnyr")
457 ("defaultOp" . "AND")
459 ("OP" . "dnquery.xp")
463 ("format" . "verbose2")
464 ("showsort" . "date")
466 ("ageweight" . "1")))))
469 ;; (defun nnweb-dejanewsold-search (search)
471 ;; (nnweb-definition 'address)
472 ;; `(("query" . ,search)
473 ;; ("defaultOp" . "AND")
474 ;; ("svcclass" . "dnold")
475 ;; ("maxhits" . "100")
476 ;; ("format" . "verbose2")
477 ;; ("threaded" . "0")
478 ;; ("showsort" . "date")
480 ;; ("ageweight" . "1")))
483 (defun nnweb-dejanews-identity (url)
484 "Return an unique identifier based on URL."
485 (if (string-match "AN=\\([0-9]+\\)" url)
493 (defun nnweb-reference-create-mapping ()
494 "Perform the search and create an number-to-url alist."
496 (set-buffer nnweb-buffer)
498 (when (funcall (nnweb-definition 'search) nnweb-search)
502 (active (or (cadr (assoc nnweb-group nnweb-group-alist))
504 Subject Score Date Newsgroups From Message-ID
507 ;; Go through all the article hits on this page.
508 (goto-char (point-min))
509 (search-forward "</pre><hr>" nil t)
510 (delete-region (point-min) (point))
511 (goto-char (point-min))
512 (while (re-search-forward "^ +[0-9]+\\." nil t)
515 (if (re-search-forward "^$" nil t)
518 (goto-char (point-min))
519 (when (looking-at ".*href=\"\\([^\"]+\\)\"")
520 (setq url (match-string 1)))
521 (mm-url-remove-markup)
522 (goto-char (point-min))
523 (while (search-forward "\t" nil t)
525 (goto-char (point-min))
526 (while (re-search-forward "^\\([^:]+\\): \\(.*\\)$" nil t)
527 (set (intern (match-string 1)) (match-string 2)))
529 (search-forward "</pre>" nil t)
531 (unless (nnweb-get-hashtb url)
535 (make-full-mail-header
536 (cdr active) (concat "(" Newsgroups ") " Subject) From Date
538 nil 0 (string-to-int Score) url))
540 (nnweb-set-hashtb (cadar map) (car map))))
542 ;; Return the articles in the right order.
544 (sort (nconc nnweb-articles map) 'car-less-than-car))))))
546 (defun nnweb-reference-wash-article ()
547 (let ((case-fold-search t))
548 (goto-char (point-min))
549 (re-search-forward "^</center><hr>" nil t)
550 (delete-region (point-min) (point))
551 (search-forward "<pre>" nil t)
553 (let ((body (point-marker)))
554 (search-forward "</pre>" nil t)
555 (delete-region (point) (point-max))
556 (mm-url-remove-markup)
557 (goto-char (point-min))
558 (while (looking-at " *$")
560 (narrow-to-region (point-min) body)
561 (while (and (re-search-forward "^$" nil t)
564 (goto-char (point-min))
565 (while (looking-at "\\(^[^ ]+:\\) *")
566 (replace-match "\\1 " t)
568 (goto-char (point-min))
569 (when (re-search-forward "^References:" nil t)
571 (point) (if (re-search-forward "^$\\|^[^:]+:" nil t)
574 (goto-char (point-min))
576 (unless (looking-at "References")
579 (goto-char (point-min))
580 (while (search-forward "," nil t)
581 (replace-match " " t t)))
583 (mm-url-decode-entities)
584 (set-marker body nil))))
586 (defun nnweb-reference-search (search)
589 (nnweb-definition 'address)
591 (mm-url-encode-www-form-urlencoded
592 `(("search" . "advanced")
593 ("querytext" . ,search)
598 ("organization" . "")
601 ("choice" . "Search")
602 ("startmonth" . "Jul")
604 ("startyear" . "1996")
609 ("verbosity" . "Verbose")
610 ("ranking" . "Relevance")
614 (setq buffer-file-name nil)
621 (defun nnweb-altavista-create-mapping ()
622 "Perform the search and create an number-to-url alist."
624 (set-buffer nnweb-buffer)
627 (when (funcall (nnweb-definition 'search) nnweb-search part)
631 (active (or (cadr (assoc nnweb-group nnweb-group-alist))
633 subject date from id group
636 ;; Go through all the article hits on this page.
637 (goto-char (point-min))
638 (search-forward "<dt>" nil t)
639 (delete-region (point-min) (match-beginning 0))
640 (goto-char (point-min))
641 (while (search-forward "<dt>" nil t)
642 (replace-match "\n<blubb>"))
643 (mm-url-decode-entities)
644 (goto-char (point-min))
645 (while (re-search-forward "<blubb>.*href=\"\\([^\"]+\\)\"><strong>\\([^>]*\\)</strong></a><dd>\\([^-]+\\)- <b>\\([^<]+\\)<.*href=\"news:\\([^\"]+\\)\">.*\">\\(.+\\)</a><P>"
647 (setq url (match-string 1)
648 subject (match-string 2)
649 date (match-string 3)
650 group (match-string 4)
651 id (concat "<" (match-string 5) ">")
652 from (match-string 6))
654 (unless (nnweb-get-hashtb url)
658 (make-full-mail-header
659 (cdr active) (concat "(" group ") " subject) from date
662 (nnweb-set-hashtb (cadar map) (car map))))
663 ;; See if we want more.
664 (when (or (not nnweb-articles)
665 (>= i nnweb-max-hits)
666 (not (funcall (nnweb-definition 'search)
667 nnweb-search (incf part))))
669 ;; Return the articles in the right order.
671 (sort (nconc nnweb-articles map) 'car-less-than-car)))))))
673 (defun nnweb-altavista-wash-article ()
674 (goto-char (point-min))
675 (let ((case-fold-search t))
676 (when (re-search-forward "^<strong>" nil t)
677 (delete-region (point-min) (match-beginning 0)))
678 (goto-char (point-min))
679 (while (looking-at "<strong>\\([^ ]+\\) +</strong> +\\(.*\\)$")
680 (replace-match "\\1: \\2" t)
682 (when (re-search-backward "^References:" nil t)
683 (narrow-to-region (point) (progn (forward-line 1) (point)))
684 (goto-char (point-min))
685 (while (re-search-forward "<A.*\\?id@\\([^\"]+\\)\">[0-9]+</A>" nil t)
686 (replace-match "<\\1> " t)))
688 (mm-url-remove-markup)
689 (mm-url-decode-entities)))
691 (defun nnweb-altavista-search (search &optional part)
694 (nnweb-definition 'address)
696 (mm-url-encode-www-form-urlencoded
699 ,@(when part `(("stq" . ,(int-to-string (* part 30)))))
705 (setq buffer-file-name nil)
709 ;;; Deja bought by google.com
712 (defun nnweb-google-wash-article ()
713 (let ((case-fold-search t) url)
714 (goto-char (point-min))
715 (re-search-forward "^<pre>" nil t)
716 (narrow-to-region (point-min) (point))
717 (search-backward "<table " nil t 2)
718 (delete-region (point-min) (point))
719 (if (re-search-forward "Search Result [0-9]+" nil t)
721 (if (re-search-forward "View complete thread ([0-9]+ articles?)" nil t)
723 (goto-char (point-min))
724 (while (search-forward "<br>" nil t)
725 (replace-match "\n"))
726 (mm-url-remove-markup)
727 (goto-char (point-min))
728 (while (re-search-forward "^[ \t]*\n" nil t)
730 (goto-char (point-max))
733 (narrow-to-region (point) (point-max))
734 (search-forward "</pre>" nil t)
735 (delete-region (point) (point-max))
736 (mm-url-remove-markup)
739 (defun nnweb-google-parse-1 (&optional Message-ID)
742 (active (cadr (assoc nnweb-group nnweb-group-alist)))
743 Subject Score Date Newsgroups From
746 (push (list nnweb-group (setq active (cons 1 0))
747 nnweb-type nnweb-search)
749 ;; Go through all the article hits on this page.
750 (goto-char (point-min))
751 (while (re-search-forward
752 "a href=/groups\\(\\?[^ \">]*selm=\\([^ &\">]+\\)\\)" nil t)
753 (setq mid (match-string 2)
755 "http://groups.google.com/groups?selm=%s&output=gplain" mid))
756 (narrow-to-region (search-forward ">" nil t)
757 (search-forward "</a>" nil t))
758 (mm-url-remove-markup)
759 (mm-url-decode-entities)
760 (setq Subject (buffer-string))
761 (goto-char (point-max))
764 (when (looking-at "<br><font[^>]+>")
765 (goto-char (match-end 0)))
766 (if (not (looking-at "<a[^>]+>"))
767 (skip-chars-forward " \t")
768 (narrow-to-region (point)
769 (search-forward "</a>" nil t))
770 (mm-url-remove-markup)
771 (mm-url-decode-entities)
772 (setq Newsgroups (buffer-string))
773 (goto-char (point-max))
775 (skip-chars-forward "- \t"))
777 "\\([0-9]+[/ ][A-Za-z]+[/ ][0-9]+\\)[ \t]*by[ \t]*\\([^<]*\\) - <a")
778 (setq From (match-string 2)
779 Date (match-string 1)))
782 (unless (nnweb-get-hashtb url)
786 (make-full-mail-header
787 (cdr active) (if Newsgroups
788 (concat "(" Newsgroups ") " Subject)
790 From Date (or Message-ID mid)
793 (nnweb-set-hashtb (cadar map) (car map))))
796 (defun nnweb-google-reference (id)
797 (let ((map (nnweb-google-parse-1 id)) header)
799 (nconc nnweb-articles map))
800 (when (setq header (cadar map))
801 (mm-with-unibyte-current-buffer
802 (mm-url-insert (mail-header-xref header)))
805 (defun nnweb-google-create-mapping ()
806 "Perform the search and create an number-to-url alist."
808 (set-buffer nnweb-buffer)
810 (when (funcall (nnweb-definition 'search) nnweb-search)
814 (nconc nnweb-articles (nnweb-google-parse-1)))
815 ;; FIXME: There is more.
817 ;; Return the articles in the right order.
819 (sort nnweb-articles 'car-less-than-car))))))
821 (defun nnweb-google-search (search)
824 (nnweb-definition 'address)
826 (mm-url-encode-www-form-urlencoded
833 ("sites" . "groups")))))
836 (defun nnweb-google-identity (url)
837 "Return an unique identifier based on URL."
838 (if (string-match "selm=\\([^ &>]+\\)" url)
843 ;;; General web/w3 interface utility functions
846 (defun nnweb-insert-html (parse)
847 "Insert HTML based on a w3 parse tree."
849 (insert (nnheader-string-as-multibyte parse))
850 (insert "<" (symbol-name (car parse)) " ")
853 (concat (symbol-name (car param)) "="
855 (if (consp (cdr param))
861 (mapcar 'nnweb-insert-html (nth 2 parse))
862 (insert "</" (symbol-name (car parse)) ">\n")))
864 (defun nnweb-parse-find (type parse &optional maxdepth)
865 "Find the element of TYPE in PARSE."
867 (nnweb-parse-find-1 type parse maxdepth)))
869 (defun nnweb-parse-find-1 (type contents maxdepth)
870 (when (or (null maxdepth)
871 (not (zerop maxdepth)))
872 (when (consp contents)
873 (when (eq (car contents) type)
874 (throw 'found contents))
875 (when (listp (cdr contents))
876 (dolist (element contents)
877 (when (consp element)
878 (nnweb-parse-find-1 type element
879 (and maxdepth (1- maxdepth)))))))))
881 (defun nnweb-parse-find-all (type parse)
882 "Find all elements of TYPE in PARSE."
884 (nnweb-parse-find-all-1 type parse)))
886 (defun nnweb-parse-find-all-1 (type contents)
888 (when (consp contents)
889 (if (eq (car contents) type)
890 (push contents result)
891 (when (listp (cdr contents))
892 (dolist (element contents)
893 (when (consp element)
895 (nconc result (nnweb-parse-find-all-1 type element))))))))
899 (defun nnweb-text (parse)
900 "Return a list of text contents in PARSE."
901 (let ((nnweb-text nil))
903 (nreverse nnweb-text)))
905 (defun nnweb-text-1 (contents)
906 (dolist (element contents)
907 (if (stringp element)
908 (push element nnweb-text)
909 (when (and (consp element)
910 (listp (cdr element)))
911 (nnweb-text-1 element)))))
915 ;;; nnweb.el ends here