1 ;;; nnweb.el --- retrieving articles via web search engines
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002
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))
44 (autoload 'w3-parse-buffer "w3-parse")
48 (defvoo nnweb-directory (nnheader-concat gnus-directory "nnweb/")
49 "Where nnweb will save its files.")
51 (defvoo nnweb-type 'google
52 "What search engine type is being used.
53 Valid types include `google', `dejanews', `reference', and `altavista'.")
55 (defvar nnweb-type-definition
58 (id . "http://groups.google.com/groups?selm=%s&output=gplain")
59 (reference . identity)
60 (map . nnweb-google-create-mapping)
61 (search . nnweb-google-search)
62 (address . "http://groups.google.com/groups")
63 (identifier . nnweb-google-identity))
64 (dejanews ;; alias of google
65 ;;(article . nnweb-google-wash-article)
66 ;;(id . "http://groups.google.com/groups?as_umsgid=%s")
68 (id . "http://groups.google.com/groups?selm=%s&output=gplain")
69 ;;(reference . nnweb-google-reference)
70 (reference . identity)
71 (map . nnweb-google-create-mapping)
72 (search . nnweb-google-search)
73 (address . "http://groups.google.com/groups")
74 (identifier . nnweb-google-identity))
76 (article . nnweb-reference-wash-article)
77 (map . nnweb-reference-create-mapping)
78 (search . nnweb-reference-search)
79 (address . "http://www.reference.com/cgi-bin/pn/go")
80 (identifier . identity))
82 (article . nnweb-altavista-wash-article)
83 (map . nnweb-altavista-create-mapping)
84 (search . nnweb-altavista-search)
85 (address . "http://www.altavista.digital.com/cgi-bin/query")
86 (id . "/cgi-bin/news?id@%s")
87 (identifier . identity)))
88 "Type-definition alist.")
90 (defvoo nnweb-search nil
91 "Search string to feed to DejaNews.")
93 (defvoo nnweb-max-hits 999
94 "Maximum number of hits to display.")
96 (defvoo nnweb-ephemeral-p nil
97 "Whether this nnweb server is ephemeral.")
99 ;;; Internal variables
101 (defvoo nnweb-articles nil)
102 (defvoo nnweb-buffer nil)
103 (defvoo nnweb-group-alist nil)
104 (defvoo nnweb-group nil)
105 (defvoo nnweb-hashtb nil)
107 ;;; Interface functions
109 (nnoo-define-basics nnweb)
111 (deffoo nnweb-retrieve-headers (articles &optional group server fetch-old)
112 (nnweb-possibly-change-server group server)
114 (set-buffer nntp-server-buffer)
116 (let (article header)
117 (mm-with-unibyte-current-buffer
118 (while (setq article (pop articles))
119 (when (setq header (cadr (assq article nnweb-articles)))
120 (nnheader-insert-nov header))))
123 (deffoo nnweb-request-scan (&optional group server)
124 (nnweb-possibly-change-server group server)
125 (if nnweb-ephemeral-p
126 (setq nnweb-hashtb (gnus-make-hashtable 4095)))
127 (funcall (nnweb-definition 'map))
128 (unless nnweb-ephemeral-p
130 (nnweb-write-overview group)))
132 (deffoo nnweb-request-group (group &optional server dont-check)
133 (nnweb-possibly-change-server nil server)
135 (not (equal group nnweb-group))
136 (not nnweb-ephemeral-p))
137 (setq nnweb-group group
139 (let ((info (assoc group nnweb-group-alist)))
141 (setq nnweb-type (nth 2 info))
142 (setq nnweb-search (nth 3 info))
144 (nnweb-read-overview group)))))
146 ((not nnweb-articles)
147 (nnheader-report 'nnweb "No matching articles"))
149 (let ((active (if nnweb-ephemeral-p
150 (cons (caar nnweb-articles)
151 (caar (last nnweb-articles)))
152 (cadr (assoc group nnweb-group-alist)))))
153 (nnheader-report 'nnweb "Opened group %s" group)
155 "211 %d %d %d %s\n" (length nnweb-articles)
156 (car active) (cdr active) group)))))
158 (deffoo nnweb-close-group (group &optional server)
159 (nnweb-possibly-change-server group server)
160 (when (gnus-buffer-live-p nnweb-buffer)
162 (set-buffer nnweb-buffer)
163 (set-buffer-modified-p nil)
164 (kill-buffer nnweb-buffer)))
167 (deffoo nnweb-request-article (article &optional group server buffer)
168 (nnweb-possibly-change-server group server)
170 (set-buffer (or buffer nntp-server-buffer))
171 (let* ((header (cadr (assq article nnweb-articles)))
172 (url (and header (mail-header-xref header))))
174 (mm-with-unibyte-current-buffer
175 (mm-url-insert url)))
176 (and (stringp article)
177 (nnweb-definition 'id t)
178 (let ((fetch (nnweb-definition 'id))
180 (when (string-match "^<\\(.*\\)>$" article)
181 (setq art (match-string 1 article)))
182 (when (and fetch art)
183 (setq url (format fetch art))
184 (mm-with-unibyte-current-buffer
186 (if (nnweb-definition 'reference t)
188 (funcall (nnweb-definition
189 'reference) article)))))))
190 (unless nnheader-callback-function
191 (funcall (nnweb-definition 'article)))
192 (nnheader-report 'nnweb "Fetched article %s" article)
193 (cons group (and (numberp article) article))))))
195 (deffoo nnweb-close-server (&optional server)
196 (when (and (nnweb-server-opened server)
197 (gnus-buffer-live-p nnweb-buffer))
199 (set-buffer nnweb-buffer)
200 (set-buffer-modified-p nil)
201 (kill-buffer nnweb-buffer)))
202 (nnoo-close-server 'nnweb server))
204 (deffoo nnweb-request-list (&optional server)
205 (nnweb-possibly-change-server nil server)
207 (set-buffer nntp-server-buffer)
208 (nnmail-generate-active nnweb-group-alist)
211 (deffoo nnweb-request-update-info (group info &optional server)
212 (nnweb-possibly-change-server group server))
214 (deffoo nnweb-asynchronous-p ()
217 (deffoo nnweb-request-create-group (group &optional server args)
218 (nnweb-possibly-change-server nil server)
219 (nnweb-request-delete-group group)
220 (push `(,group ,(cons 1 0) ,@args) nnweb-group-alist)
224 (deffoo nnweb-request-delete-group (group &optional force server)
225 (nnweb-possibly-change-server group server)
226 (gnus-pull group nnweb-group-alist t)
228 (gnus-delete-file (nnweb-overview-file group))
231 (nnoo-define-skeleton nnweb)
233 ;;; Internal functions
235 (defun nnweb-read-overview (group)
236 "Read the overview of GROUP and build the map."
237 (when (file-exists-p (nnweb-overview-file group))
238 (mm-with-unibyte-buffer
239 (nnheader-insert-file-contents (nnweb-overview-file group))
240 (goto-char (point-min))
243 (setq header (nnheader-parse-nov))
245 (push (list (mail-header-number header)
246 header (mail-header-xref header))
248 (nnweb-set-hashtb header (car nnweb-articles)))))))
250 (defun nnweb-write-overview (group)
251 "Write the overview file for GROUP."
252 (with-temp-file (nnweb-overview-file group)
253 (let ((articles nnweb-articles))
255 (nnheader-insert-nov (cadr (pop articles)))))))
257 (defun nnweb-set-hashtb (header data)
258 (gnus-sethash (nnweb-identifier (mail-header-xref header))
261 (defun nnweb-get-hashtb (url)
262 (gnus-gethash (nnweb-identifier url) nnweb-hashtb))
264 (defun nnweb-identifier (ident)
265 (funcall (nnweb-definition 'identifier) ident))
267 (defun nnweb-overview-file (group)
268 "Return the name of the overview file of GROUP."
269 (nnheader-concat nnweb-directory group ".overview"))
271 (defun nnweb-write-active ()
272 "Save the active file."
273 (gnus-make-directory nnweb-directory)
274 (with-temp-file (nnheader-concat nnweb-directory "active")
275 (prin1 `(setq nnweb-group-alist ',nnweb-group-alist) (current-buffer))))
277 (defun nnweb-read-active ()
278 "Read the active file."
279 (load (nnheader-concat nnweb-directory "active") t t t))
281 (defun nnweb-definition (type &optional noerror)
282 "Return the definition of TYPE."
283 (let ((def (cdr (assq type (assq nnweb-type nnweb-type-definition)))))
286 (error "Undefined definition %s" type))
289 (defun nnweb-possibly-change-server (&optional group server)
292 (unless (nnweb-server-opened server)
293 (nnweb-open-server server)))
294 (unless nnweb-group-alist
297 (setq nnweb-hashtb (gnus-make-hashtable 4095)))
299 (when (and (not nnweb-ephemeral-p)
300 (equal group nnweb-group))
301 (nnweb-request-group group nil t))))
303 (defun nnweb-init (server)
304 "Initialize buffers and such."
305 (unless (gnus-buffer-live-p nnweb-buffer)
309 (nnheader-set-temp-buffer
310 (format " *nnweb %s %s %s*"
311 nnweb-type nnweb-search server))
312 (current-buffer))))))
314 ;; (defun nnweb-fetch-url (url)
317 ;; (if (not nnheader-callback-function)
320 ;; (mm-enable-multibyte)
321 ;; (let ((coding-system-for-read 'binary)
322 ;; (coding-system-for-write 'binary)
323 ;; (input-coding-system 'binary)
324 ;; (output-coding-system 'binary)
325 ;; (default-process-coding-system 'binary))
326 ;; (nnweb-insert url))
327 ;; (setq buf (buffer-string)))
331 ;; (nnweb-url-retrieve-asynch
332 ;; url 'nnweb-callback (current-buffer) nnheader-callback-function)
335 ;; (defun nnweb-callback (buffer callback)
336 ;; (when (gnus-buffer-live-p url-working-buffer)
338 ;; (set-buffer url-working-buffer)
339 ;; (funcall (nnweb-definition 'article))
340 ;; (nnweb-decode-entities)
341 ;; (set-buffer buffer)
342 ;; (goto-char (point-max))
343 ;; (insert-buffer-substring url-working-buffer))
344 ;; (funcall callback t)
345 ;; (gnus-kill-buffer url-working-buffer)))
347 ;; (defun nnweb-url-retrieve-asynch (url callback &rest data)
348 ;; (let ((url-request-method "GET")
349 ;; (old-asynch url-be-asynchronous)
350 ;; (url-request-data nil)
351 ;; (url-request-extra-headers nil)
352 ;; (url-working-buffer (generate-new-buffer-name " *nnweb*")))
353 ;; (setq-default url-be-asynchronous t)
355 ;; (set-buffer (get-buffer-create url-working-buffer))
356 ;; (setq url-current-callback-data data
357 ;; url-be-asynchronous t
358 ;; url-current-callback-func callback)
359 ;; (url-retrieve url nil))
360 ;; (setq-default url-be-asynchronous old-asynch)))
362 ;; (if (fboundp 'url-retrieve-synchronously)
363 ;; (defun nnweb-url-retrieve-asynch (url callback &rest data)
364 ;; (url-retrieve url callback data)))
367 ;;; DejaNews functions.
370 (defun nnweb-dejanews-create-mapping ()
371 "Perform the search and create an number-to-url alist."
373 (set-buffer nnweb-buffer)
375 (when (funcall (nnweb-definition 'search) nnweb-search)
379 (active (or (cadr (assoc nnweb-group nnweb-group-alist))
382 map url parse a table group text)
384 ;; Go through all the article hits on this page.
385 (goto-char (point-min))
386 (setq parse (w3-parse-buffer (current-buffer))
387 table (nth 1 (nnweb-parse-find-all 'table parse)))
388 (dolist (row (nth 2 (car (nth 2 table))))
389 (setq a (nnweb-parse-find 'a row)
390 url (cdr (assq 'href (nth 1 a)))
391 text (nreverse (nnweb-text row)))
393 (setq subject (nth 4 text)
397 (if (string-match "\\([0-9]+\\)/\\([0-9]+\\)/\\([0-9]+\\)" date)
398 (setq date (format "%s %s 00:00:00 %s"
399 (car (rassq (string-to-number
400 (match-string 2 date))
402 (match-string 3 date)
403 (match-string 1 date)))
404 (setq date "Jan 1 00:00:00 0000"))
406 (setq url (concat url "&fmt=text"))
407 (when (string-match "&context=[^&]+" url)
408 (setq url (replace-match "" t t url)))
409 (unless (nnweb-get-hashtb url)
413 (make-full-mail-header
414 (cdr active) (concat subject " (" group ")") from date
415 (concat "<" (nnweb-identifier url) "@dejanews>")
418 (nnweb-set-hashtb (cadar map) (car map)))))
419 ;; See whether there is a "Get next 20 hits" button here.
420 (goto-char (point-min))
421 (if (or (not (re-search-forward
422 "HREF=\"\\([^\"]+\\)\"[<>b]+Next result" nil t))
423 (>= i nnweb-max-hits))
426 (setq more (match-string 1))
428 (mm-url-insert more)))
429 ;; Return the articles in the right order.
431 (sort (nconc nnweb-articles map) 'car-less-than-car))))))
433 (defun nnweb-dejanews-search (search)
436 (nnweb-definition 'address)
438 (mm-url-encode-www-form-urlencoded
440 ("svcclass" . "dnyr")
442 ("defaultOp" . "AND")
444 ("OP" . "dnquery.xp")
448 ("format" . "verbose2")
449 ("showsort" . "date")
451 ("ageweight" . "1")))))
454 ;; (defun nnweb-dejanewsold-search (search)
456 ;; (nnweb-definition 'address)
457 ;; `(("query" . ,search)
458 ;; ("defaultOp" . "AND")
459 ;; ("svcclass" . "dnold")
460 ;; ("maxhits" . "100")
461 ;; ("format" . "verbose2")
462 ;; ("threaded" . "0")
463 ;; ("showsort" . "date")
465 ;; ("ageweight" . "1")))
468 (defun nnweb-dejanews-identity (url)
469 "Return an unique identifier based on URL."
470 (if (string-match "AN=\\([0-9]+\\)" url)
478 (defun nnweb-reference-create-mapping ()
479 "Perform the search and create an number-to-url alist."
481 (set-buffer nnweb-buffer)
483 (when (funcall (nnweb-definition 'search) nnweb-search)
487 (active (or (cadr (assoc nnweb-group nnweb-group-alist))
489 Subject Score Date Newsgroups From Message-ID
492 ;; Go through all the article hits on this page.
493 (goto-char (point-min))
494 (search-forward "</pre><hr>" nil t)
495 (delete-region (point-min) (point))
496 (goto-char (point-min))
497 (while (re-search-forward "^ +[0-9]+\\." nil t)
500 (if (re-search-forward "^$" nil t)
503 (goto-char (point-min))
504 (when (looking-at ".*href=\"\\([^\"]+\\)\"")
505 (setq url (match-string 1)))
506 (mm-url-remove-markup)
507 (goto-char (point-min))
508 (while (search-forward "\t" nil t)
510 (goto-char (point-min))
511 (while (re-search-forward "^\\([^:]+\\): \\(.*\\)$" nil t)
512 (set (intern (match-string 1)) (match-string 2)))
514 (search-forward "</pre>" nil t)
516 (unless (nnweb-get-hashtb url)
520 (make-full-mail-header
521 (cdr active) (concat "(" Newsgroups ") " Subject) From Date
523 nil 0 (string-to-int Score) url))
525 (nnweb-set-hashtb (cadar map) (car map))))
527 ;; Return the articles in the right order.
529 (sort (nconc nnweb-articles map) 'car-less-than-car))))))
531 (defun nnweb-reference-wash-article ()
532 (let ((case-fold-search t))
533 (goto-char (point-min))
534 (re-search-forward "^</center><hr>" nil t)
535 (delete-region (point-min) (point))
536 (search-forward "<pre>" nil t)
538 (let ((body (point-marker)))
539 (search-forward "</pre>" nil t)
540 (delete-region (point) (point-max))
541 (mm-url-remove-markup)
542 (goto-char (point-min))
543 (while (looking-at " *$")
545 (narrow-to-region (point-min) body)
546 (while (and (re-search-forward "^$" nil t)
549 (goto-char (point-min))
550 (while (looking-at "\\(^[^ ]+:\\) *")
551 (replace-match "\\1 " t)
553 (goto-char (point-min))
554 (when (re-search-forward "^References:" nil t)
556 (point) (if (re-search-forward "^$\\|^[^:]+:" nil t)
559 (goto-char (point-min))
561 (unless (looking-at "References")
564 (goto-char (point-min))
565 (while (search-forward "," nil t)
566 (replace-match " " t t)))
568 (mm-url-decode-entities)
569 (set-marker body nil))))
571 (defun nnweb-reference-search (search)
574 (nnweb-definition 'address)
576 (mm-url-encode-www-form-urlencoded
577 `(("search" . "advanced")
578 ("querytext" . ,search)
583 ("organization" . "")
586 ("choice" . "Search")
587 ("startmonth" . "Jul")
589 ("startyear" . "1996")
594 ("verbosity" . "Verbose")
595 ("ranking" . "Relevance")
599 (setq buffer-file-name nil)
606 (defun nnweb-altavista-create-mapping ()
607 "Perform the search and create an number-to-url alist."
609 (set-buffer nnweb-buffer)
612 (when (funcall (nnweb-definition 'search) nnweb-search part)
616 (active (or (cadr (assoc nnweb-group nnweb-group-alist))
618 subject date from id group
621 ;; Go through all the article hits on this page.
622 (goto-char (point-min))
623 (search-forward "<dt>" nil t)
624 (delete-region (point-min) (match-beginning 0))
625 (goto-char (point-min))
626 (while (search-forward "<dt>" nil t)
627 (replace-match "\n<blubb>"))
628 (mm-url-decode-entities)
629 (goto-char (point-min))
630 (while (re-search-forward "<blubb>.*href=\"\\([^\"]+\\)\"><strong>\\([^>]*\\)</strong></a><dd>\\([^-]+\\)- <b>\\([^<]+\\)<.*href=\"news:\\([^\"]+\\)\">.*\">\\(.+\\)</a><P>"
632 (setq url (match-string 1)
633 subject (match-string 2)
634 date (match-string 3)
635 group (match-string 4)
636 id (concat "<" (match-string 5) ">")
637 from (match-string 6))
639 (unless (nnweb-get-hashtb url)
643 (make-full-mail-header
644 (cdr active) (concat "(" group ") " subject) from date
647 (nnweb-set-hashtb (cadar map) (car map))))
648 ;; See if we want more.
649 (when (or (not nnweb-articles)
650 (>= i nnweb-max-hits)
651 (not (funcall (nnweb-definition 'search)
652 nnweb-search (incf part))))
654 ;; Return the articles in the right order.
656 (sort (nconc nnweb-articles map) 'car-less-than-car)))))))
658 (defun nnweb-altavista-wash-article ()
659 (goto-char (point-min))
660 (let ((case-fold-search t))
661 (when (re-search-forward "^<strong>" nil t)
662 (delete-region (point-min) (match-beginning 0)))
663 (goto-char (point-min))
664 (while (looking-at "<strong>\\([^ ]+\\) +</strong> +\\(.*\\)$")
665 (replace-match "\\1: \\2" t)
667 (when (re-search-backward "^References:" nil t)
668 (narrow-to-region (point) (progn (forward-line 1) (point)))
669 (goto-char (point-min))
670 (while (re-search-forward "<A.*\\?id@\\([^\"]+\\)\">[0-9]+</A>" nil t)
671 (replace-match "<\\1> " t)))
673 (mm-url-remove-markup)
674 (mm-url-decode-entities)))
676 (defun nnweb-altavista-search (search &optional part)
679 (nnweb-definition 'address)
681 (mm-url-encode-www-form-urlencoded
684 ,@(when part `(("stq" . ,(int-to-string (* part 30)))))
690 (setq buffer-file-name nil)
694 ;;; Deja bought by google.com
697 (defun nnweb-google-wash-article ()
698 (let ((case-fold-search t) url)
699 (goto-char (point-min))
700 (re-search-forward "^<pre>" nil t)
701 (narrow-to-region (point-min) (point))
702 (search-backward "<table " nil t 2)
703 (delete-region (point-min) (point))
704 (if (re-search-forward "Search Result [0-9]+" nil t)
706 (if (re-search-forward "View complete thread ([0-9]+ articles?)" nil t)
708 (goto-char (point-min))
709 (while (search-forward "<br>" nil t)
710 (replace-match "\n"))
711 (mm-url-remove-markup)
712 (goto-char (point-min))
713 (while (re-search-forward "^[ \t]*\n" nil t)
715 (goto-char (point-max))
718 (narrow-to-region (point) (point-max))
719 (search-forward "</pre>" nil t)
720 (delete-region (point) (point-max))
721 (mm-url-remove-markup)
724 (defun nnweb-google-parse-1 (&optional Message-ID)
727 (active (cadr (assoc nnweb-group nnweb-group-alist)))
728 Subject Score Date Newsgroups From
731 (push (list nnweb-group (setq active (cons 1 0))
732 nnweb-type nnweb-search)
734 ;; Go through all the article hits on this page.
735 (goto-char (point-min))
736 (while (re-search-forward
737 "a href=/groups\\(\\?[^ \">]*selm=\\([^ &\">]+\\)\\)" nil t)
738 (setq mid (match-string 2)
740 "http://groups.google.com/groups?selm=%s&output=gplain" mid))
741 (narrow-to-region (search-forward ">" nil t)
742 (search-forward "</a>" nil t))
743 (mm-url-remove-markup)
744 (mm-url-decode-entities)
745 (setq Subject (buffer-string))
746 (goto-char (point-max))
749 (when (looking-at "<br><font[^>]+>")
750 (goto-char (match-end 0)))
751 (if (not (looking-at "<a[^>]+>"))
752 (skip-chars-forward " \t")
753 (narrow-to-region (point)
754 (search-forward "</a>" nil t))
755 (mm-url-remove-markup)
756 (mm-url-decode-entities)
757 (setq Newsgroups (buffer-string))
758 (goto-char (point-max))
760 (skip-chars-forward "- \t"))
762 "\\([0-9]+\\)[/ ]\\([A-Za-z]+\\)[/ ]\\([0-9]+\\)[ \t]*by[ \t]*\\([^<]*\\) - <a")
763 (setq From (match-string 4)
764 Date (format "%s %s 00:00:00 %s"
765 (match-string 2) (match-string 1)
769 (unless (nnweb-get-hashtb url)
773 (make-full-mail-header
774 (cdr active) (if Newsgroups
775 (concat "(" Newsgroups ") " Subject)
777 From Date (or Message-ID mid)
780 (nnweb-set-hashtb (cadar map) (car map))))
783 (defun nnweb-google-reference (id)
784 (let ((map (nnweb-google-parse-1 id)) header)
786 (nconc nnweb-articles map))
787 (when (setq header (cadar map))
788 (mm-with-unibyte-current-buffer
789 (mm-url-insert (mail-header-xref header)))
792 (defun nnweb-google-create-mapping ()
793 "Perform the search and create an number-to-url alist."
795 (set-buffer nnweb-buffer)
797 (when (funcall (nnweb-definition 'search) nnweb-search)
802 (nconc nnweb-articles (nnweb-google-parse-1)))
803 ;; Check if there are more articles to fetch
804 (goto-char (point-min))
806 (if (or (not (re-search-forward
807 "<td nowrap><a href=\\([^>]+\\).*<span class=b>Next</span>" nil t))
808 (>= i nnweb-max-hits))
810 ;; Yup, there are more articles
811 (setq more (concat "http://groups.google.com" (match-string 1)))
814 (mm-url-insert more))))
815 ;; Return the articles in the right order.
817 (sort nnweb-articles 'car-less-than-car))))))
819 (defun nnweb-google-search (search)
822 (nnweb-definition 'address)
824 (mm-url-encode-www-form-urlencoded
831 ("sites" . "groups")))))
834 (defun nnweb-google-identity (url)
835 "Return an unique identifier based on URL."
836 (if (string-match "selm=\\([^ &>]+\\)" url)
841 ;;; General web/w3 interface utility functions
844 (defun nnweb-insert-html (parse)
845 "Insert HTML based on a w3 parse tree."
847 (insert (nnheader-string-as-multibyte parse))
848 (insert "<" (symbol-name (car parse)) " ")
851 (concat (symbol-name (car param)) "="
853 (if (consp (cdr param))
859 (mapcar 'nnweb-insert-html (nth 2 parse))
860 (insert "</" (symbol-name (car parse)) ">\n")))
862 (defun nnweb-parse-find (type parse &optional maxdepth)
863 "Find the element of TYPE in PARSE."
865 (nnweb-parse-find-1 type parse maxdepth)))
867 (defun nnweb-parse-find-1 (type contents maxdepth)
868 (when (or (null maxdepth)
869 (not (zerop maxdepth)))
870 (when (consp contents)
871 (when (eq (car contents) type)
872 (throw 'found contents))
873 (when (listp (cdr contents))
874 (dolist (element contents)
875 (when (consp element)
876 (nnweb-parse-find-1 type element
877 (and maxdepth (1- maxdepth)))))))))
879 (defun nnweb-parse-find-all (type parse)
880 "Find all elements of TYPE in PARSE."
882 (nnweb-parse-find-all-1 type parse)))
884 (defun nnweb-parse-find-all-1 (type contents)
886 (when (consp contents)
887 (if (eq (car contents) type)
888 (push contents result)
889 (when (listp (cdr contents))
890 (dolist (element contents)
891 (when (consp element)
893 (nconc result (nnweb-parse-find-all-1 type element))))))))
897 (defun nnweb-text (parse)
898 "Return a list of text contents in PARSE."
899 (let ((nnweb-text nil))
901 (nreverse nnweb-text)))
903 (defun nnweb-text-1 (contents)
904 (dolist (element contents)
905 (if (stringp element)
906 (push element nnweb-text)
907 (when (and (consp element)
908 (listp (cdr element)))
909 (nnweb-text-1 element)))))
913 ;;; nnweb.el ends here