Import Oort Gnus v0.09.
[elisp/gnus.git-] / lisp / nnrss.el
1 ;;; nnrss.el --- interfacing with RSS
2 ;; Copyright (C) 2001, 2002  Free Software Foundation, Inc.
3
4 ;; Author: Shenghuo Zhu <zsh@cs.rochester.edu>
5 ;; Keywords: RSS
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
11 ;; by the Free Software Foundation; either version 2, or (at your
12 ;; option) any later version.
13
14 ;; GNU Emacs is distributed in the hope that it will be useful, but
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 ;; 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 ;;; Code:
27
28 (eval-when-compile (require 'cl))
29
30 (require 'gnus)
31 (require 'nnoo)
32 (require 'nnmail)
33 (require 'message)
34 (require 'mm-util)
35 (require 'gnus-util)
36 (require 'time-date)
37 (require 'rfc2231)
38 (require 'mm-url)
39 (eval-when-compile
40   (ignore-errors
41     (require 'xml)))
42 (eval '(require 'xml))
43
44 (nnoo-declare nnrss)
45
46 (defvoo nnrss-directory (nnheader-concat gnus-directory "rss/")
47   "Where nnrss will save its files.")
48
49 ;; (group max rss-url)
50 (defvoo nnrss-server-data nil)
51
52 ;; (num timestamp url subject author date extra)
53 (defvoo nnrss-group-data nil)
54 (defvoo nnrss-group-max 0)
55 (defvoo nnrss-group-min 1)
56 (defvoo nnrss-group nil)
57 (defvoo nnrss-group-hashtb nil)
58 (defvoo nnrss-status-string "")
59
60 (defconst nnrss-version "nnrss 1.0")
61
62 (defvar nnrss-group-alist
63   '(("MacWeek"
64      "http://macweek.zdnet.com/macweek.xml"
65      "The Macintosh news authority.")
66     ("Linux.Weekly.News"
67      "http://lwn.net/headlines/rss")
68     ("Motley.Fool"
69      "http://www.fool.com/About/headlines/rss_headlines.asp")
70     ("NewsForge.rdf"
71      "http://www.newsforge.com/newsforge.rdf")
72     ("Slashdot"
73      "http://www.slashdot.com/slashdot.rdf")
74     ("CNN"
75      "http://www.cnn.com/cnn.rss"
76      "The world's news leader.")
77     ("FreshMeat"
78      "http://freshmeat.net/backend/fm-releases.rdf"
79      "The one-stop-shop for all your Linux software needs.")
80     ("The.Guardian.newspaper"
81      "http://www.guardianunlimited.co.uk/rss/1,,,00.xml"
82      "Intelligent news and comment throughout the day from The Guardian newspaper.")
83     ("MonkeyFist.rdf"
84      "http://monkeyfist.com/rdf.php3"
85      "News and opinion on politics, technology, and eclectic miscellany.")
86     ("NewsForge"
87      "http://www.newsforge.com/newsforge.rss")
88     ("Reuters.Health"
89      "http://www.reutershealth.com/eline.rss"
90      "Consumer-oriented health-related news stories.")
91     ("Salon"
92      "http://www.salon.com/feed/RDF/salon_use.rdf")
93     ("Wired"
94      "http://www.wired.com/news_drop/netcenter/netcenter.rdf")
95     ("ITN"
96      "http://www.itn.co.uk/itn.rdf")
97     ("Meerkat"
98      "http://www.oreillynet.com/meerkat/?_fl=rss10"
99      "An Open Wire Service")
100     ("MonkeyFist"
101      "http://monkeyfist.com/rss1.php3"
102      "News and opinion on politics, technology, and eclectic miscellany.")
103     ("Reuters.Health.rdf"
104      "http://www.reutershealth.com/eline.rdf"
105      "Consumer-oriented health-related news stories.")
106 ;;("4xt" "http://4xt.org/news/general.rss10" "Resources for XT users.")
107     ("Aaronland" "http://aaronland.net/xml/abhb.rdf" "A boy and his basement.")
108     ("Art of the Mix" "http://www.artofthemix.org/xml/rss.asp" "A website devoted to the art of making mixed tapes and cds.")
109     ("Dave Beckett's RDF Resource Guide" "http://www.ilrt.bristol.ac.uk/discovery/rdf/resources/rss.rdf" "A comprehensive guide to resources about RDF.")
110     ("David Chess" "http://www.davidchess.com/words/log.rss" "Mostly-daily musings on philosophy, children, culture, technology, the emergence of life from matter, chocolate, Nomic, and all that sort of thing.")
111 ;;("Dublin Core Metadata Intitiative" "http://www.dublincore.org/news.rss" "Latest news from DCMI.")
112     ("Figby Articles" "http://www.figby.com/index-rss.php" "A weblog with daily stories about technology, books and publishing, privacy, science, and occasional humor.")
113 ;;("Figby News" "http://www.figby.com/news.php" "Categorized RSS feeds from various sources.")
114     ("Figby Quickies" "http://www.figby.com/quickies-rss.php" "Quick commented links to other sites from Figby.com.")
115     ("Flutterby!" "http://www.flutterby.com/main.rdf" "News and views from Dan Lyke.")
116     ("Groovelog" "http://groovelog.agora.co.uk/groove+log/groovelog.nsf/today.rss.xml" "The open-access groove users' weblog.")
117 ;;("Groovelog.rss10" "http://groovelog.agora.co.uk/groove+log/groovelog.nsf/today.rss10.xml" "The open-access groove users' weblog.")
118     ("Hit or Miss" "http://hit-or-miss.org/rss/" "Daily weblog and journal.")
119 ;;("Internet.com Feeds" "http://www.webreference.com/services/news/" "News from ")
120     ("Larkfarm News" "http://www.larkfarm.com/Larkfarm.rdf" "Mike Gunderloy's web site.")
121     ("Latest RFCs" "http://x42.com/rss/rfc.rss")
122     ("Linux Today" "http://linuxtoday.com/backend/biglt.rss")
123     ("Linux Today.rdf" "http://linuxtoday.com/backend/my-netscape10.rdf")
124     ("More Like This WebLog" "http://www.whump.com/moreLikeThis/RSS" "Because the more you know, the more jokes you get.")
125     ("Motivational Quotes of the Day" "http://www.quotationspage.com/data/mqotd.rss" "Four motivational quotations each day from the Quotations Page.")
126 ;;("My Netscape Network" "http://www.dmoz.org/Netscape/My_Netscape_Network/")
127     ;;("My UserLand" "http://my.userland.com/choose")
128     ("Network World Fusion NetFlash" "http://www.nwfusion.com/netflash.rss" "Daily breaking news about networking products, technologies and services.")
129 ;;("News Feeds" "http://newsfeeds.manilasites.com/" "Jeff Barr highlights high quality RSS feeds.")
130     ;;("News Is Free Export" "http://www.newsisfree.com/export.php3")
131     ("News Is Free" "http://www.newsisfree.com/news.rdf.php3")
132 ;;("News is Free XML Export" "http://www.newsisfree.com/ocs/directory.xml")
133     ("O'Reilly Network Articles" "http://www.oreillynet.com/cs/rss/query/q/260?x-ver=1.0")
134     ("Quotes of the Day" "http://www.quotationspage.com/data/qotd.rss" "Four humorous quotations each day from the Quotations Page.")
135     ("RDF Interest Group" "http://ilrt.org/discovery/rdf-dev/roads/cgi-bin/desire/ig2rss?list=www-rdf-interest" "An experimental channel scraped from the RDF Interest Group mail archives.")
136     ("RDF Logic List" "http://ilrt.org/discovery/rdf-dev/roads/cgi-bin/desire/ig2rss?list=www-rdf-logic" "An experimental channel scraped from the RDF Logic mail archives.")
137     ("RSS Info" "http://www.blogspace.com/rss/rss10" "News and information on the RSS format")
138 ;;("RSS-DEV listing" "http://www.egroups.com/links/rss-dev/Feeds_000966335046/" "A listing of RSS files from the RSS-DEV list.")
139     ("Semantic Web List" "http://ilrt.org/discovery/rdf-dev/roads/cgi-bin/desire/ig2rss?list=semantic-web" "An experimental channel scraped from the W3C's Semantic Web mail archives.")
140 ;;("Sherch!" "http://www.sherch.com/~pldms/cgi-bin/sherch.pl" "Sherlock for the rest of us.")
141 ;;("Street Fusion Archived Financial Webcasts" "http://partners.streetfusion.com/rdf/archive.rdf")
142 ;;("Street Fusion Upcoming Financial Webcasts" "http://partners.streetfusion.com/rdf/live.rdf")
143 ;;("TNL.net newsletter" "http://www.tnl.net/newsletter/channel100.asp" "A newsletter about Internet technology and issues.")
144     ("W3C" "http://www.w3.org/2000/08/w3c-synd/home.rss" "The latest news at the World Wide Web Consortium.")
145 ;;("XML News: RSS Live Content" "http://www.xmlnews.org/RSS/content.html" "A listing of well-known RSS feeds.")
146     ("|fr| XMLfr" "http://xmlfr.org/actualites/general.rss10"
147      "French speaking portal site dedicated to XML.")
148     ("XMLhack" "http://xmlhack.com/rss10.php"
149      "Developer news from the XML community.")
150     ("The Register"
151      "http://www.theregister.co.uk/tonys/slashdot.rdf"
152      "The Register -- Biting the hand that feeds IT.")
153     ("|de| Heise-Ticker"
154      "http://www.heise.de/newsticker/heise.rdf"
155      "German news ticker about technology.")
156     ("|de| Telepolis News"
157      "http://www.heise.de/tp/news.rdf"
158      "German background news about technology.")
159     ("Kuro5hin"
160      "http://www.kuro5hin.org/backend.rdf"
161      "Technology and culture, from the trenches.")
162     ("Jabber Software Foundation News"
163      "http://www.jabber.org/news/rss.xml"
164      "News and announcements from the Jabber Software Foundation.")
165     ))
166
167 (defvar nnrss-use-local nil)
168
169 (defvar nnrss-description-field 'X-Gnus-Description
170   "Field name used for DESCRIPTION.
171 To use the description in headers, put this name into `nnmail-extra-headers'.")
172
173 (defvar nnrss-url-field 'X-Gnus-Url
174   "Field name used for URL.
175 To use the description in headers, put this name into `nnmail-extra-headers'.")
176
177 (defvar nnrss-content-function nil
178   "A function which is called in `nnrss-request-article'.
179 The arguments are (ENTRY GROUP ARTICLE).
180 ENTRY is the record of the current headline. GROUP is the group name.
181 ARTICLE is the article number of the current headline.")
182
183 (nnoo-define-basics nnrss)
184
185 ;;; Interface functions
186
187 (deffoo nnrss-retrieve-headers (articles &optional group server fetch-old)
188   (nnrss-possibly-change-group group server)
189   (let (e)
190     (save-excursion
191       (set-buffer nntp-server-buffer)
192       (erase-buffer)
193       (dolist (article articles)
194         (if (setq e (assq article nnrss-group-data))
195             (insert (number-to-string (car e)) "\t" ;; number
196                     (if (nth 3 e)
197                         (nnrss-format-string (nth 3 e)) "")
198                     "\t" ;; subject
199                     (if (nth 4 e)
200                         (nnrss-format-string (nth 4 e))
201                       "(nobody)")
202                     "\t" ;;from
203                     (or (nth 5 e) "")
204                     "\t" ;; date
205                     (format "<%d@%s.nnrss>" (car e) group)
206                     "\t" ;; id
207                     "\t" ;; refs
208                     "-1" "\t" ;; chars
209                     "-1" "\t" ;; lines
210                     "" "\t" ;; Xref
211                     (if (and (nth 6 e)
212                              (memq nnrss-description-field
213                                    nnmail-extra-headers))
214                         (concat (symbol-name nnrss-description-field)
215                                 ": "
216                                 (nnrss-format-string (nth 6 e))
217                                 "\t")
218                       "")
219                     (if (and (nth 2 e)
220                              (memq nnrss-url-field
221                                    nnmail-extra-headers))
222                         (concat (symbol-name nnrss-url-field)
223                                 ": "
224                                 (nnrss-format-string (nth 2 e))
225                                 "\t")
226                       "")
227                     "\n")))))
228   'nov)
229
230 (deffoo nnrss-request-group (group &optional server dont-check)
231   (nnrss-possibly-change-group group server)
232   (if dont-check
233       t
234     (nnrss-check-group group server)
235     (nnheader-report 'nnrss "Opened group %s" group)
236     (nnheader-insert
237      "211 %d %d %d %s\n" nnrss-group-max nnrss-group-min nnrss-group-max
238      (prin1-to-string group)
239      t)))
240
241 (deffoo nnrss-close-group (group &optional server)
242   t)
243
244 (deffoo nnrss-request-article (article &optional group server buffer)
245   (nnrss-possibly-change-group group server)
246   (let ((e (assq article nnrss-group-data))
247         (nntp-server-buffer (or buffer nntp-server-buffer))
248         post err)
249     (when e
250       (catch 'error
251         (with-current-buffer nntp-server-buffer
252           (erase-buffer)
253           (goto-char (point-min))
254           (if group
255               (insert "Newsgroups: " group "\n"))
256           (if (nth 3 e)
257               (insert "Subject: " (nnrss-format-string (nth 3 e)) "\n"))
258           (if (nth 4 e)
259               (insert "From: " (nnrss-format-string (nth 4 e)) "\n"))
260           (if (nth 5 e)
261               (insert "Date: " (nnrss-format-string (nth 5 e)) "\n"))
262           (insert "Message-ID: " (format "<%d@%s.nnrss>" (car e) group) "\n")
263           (insert "\n")
264           (if (nth 6 e)
265               (let ((point (point)))
266                 (insert (nnrss-string-as-multibyte (nth 6 e)))
267                 (goto-char point)
268                 (while (search-forward "\n" nil t)
269                   (delete-char -1))
270                 (goto-char (point-max))
271                 (insert "\n\n")
272                 (fill-region point (point))))
273           (if (nth 2 e)
274               (insert (nth 2 e) "\n"))
275           (if nnrss-content-function
276               (funcall nnrss-content-function e group article)))))
277     (cond
278      (err
279       (nnheader-report 'nnrss err))
280      ((not e)
281       (nnheader-report 'nnrss "No such id: %d" article))
282      (t
283       (nnheader-report 'nnrss "Article %s retrieved" (car e))
284       ;; We return the article number.
285       (cons nnrss-group (car e))))))
286
287 (deffoo nnrss-request-list (&optional server)
288   (nnrss-possibly-change-group nil server)
289   (nnrss-generate-active)
290   t)
291
292 (deffoo nnrss-open-server (server &optional defs connectionless)
293   (nnrss-read-server-data server)
294   (nnoo-change-server 'nnrss server defs)
295   t)
296
297 (deffoo nnrss-request-expire-articles
298     (articles group &optional server force)
299   (nnrss-possibly-change-group group server)
300   (let (e days not-expirable changed)
301     (dolist (art articles)
302       (if (and (setq e (assq art nnrss-group-data))
303                (nnmail-expired-article-p
304                 group
305                 (if (listp (setq days (nth 1 e))) days
306                   (days-to-time (- days (time-to-days '(0 0)))))
307                 force))
308           (setq nnrss-group-data (delq e nnrss-group-data)
309                 changed t)
310         (push art not-expirable)))
311     (if changed
312         (nnrss-save-group-data group server))
313     not-expirable))
314
315 (deffoo nnrss-request-delete-group (group &optional force server)
316   (nnrss-possibly-change-group group server)
317   (setq nnrss-server-data
318         (delq (assoc group nnrss-server-data) nnrss-server-data))
319   (nnrss-save-server-data server)
320   (let ((file (expand-file-name
321                (nnrss-translate-file-chars
322                 (concat group (and server
323                                    (not (equal server ""))
324                                    "-")
325                         server ".el")) nnrss-directory)))
326     (ignore-errors
327       (delete-file file)))
328   t)
329
330 (deffoo nnrss-request-list-newsgroups (&optional server)
331   (nnrss-possibly-change-group nil server)
332   (save-excursion
333     (set-buffer nntp-server-buffer)
334     (erase-buffer)
335     (dolist (elem nnrss-group-alist)
336       (if (third elem)
337           (insert (car elem) "\t" (third elem) "\n"))))
338   t)
339
340 (nnoo-define-skeleton nnrss)
341
342 ;;; Internal functions
343
344 (defun nnrss-possibly-change-group (&optional group server)
345   (when (and server
346              (not (nnrss-server-opened server)))
347     (nnrss-open-server server))
348   (when (and group (not (equal group nnrss-group)))
349     (nnrss-read-group-data group server)
350     (setq nnrss-group group)))
351
352 (defvar nnrss-extra-categories '(nnrss-snarf-moreover-categories))
353
354 (defun nnrss-generate-active ()
355   (if (y-or-n-p "Fetch extra categories? ")
356       (dolist (func nnrss-extra-categories)
357         (funcall func)))
358   (save-excursion
359     (set-buffer nntp-server-buffer)
360     (erase-buffer)
361     (dolist (elem nnrss-group-alist)
362       (insert (prin1-to-string (car elem)) " 0 1 y\n"))
363     (dolist (elem nnrss-server-data)
364       (unless (assoc (car elem) nnrss-group-alist)
365         (insert (prin1-to-string (car elem)) " 0 1 y\n")))))
366
367 ;;; Data functions
368
369 (defun nnrss-read-server-data (server)
370   (setq nnrss-server-data nil)
371   (let ((file (expand-file-name
372                (nnrss-translate-file-chars
373                 (concat "nnrss" (and server
374                                      (not (equal server ""))
375                                      "-")
376                         server
377                         ".el"))
378                nnrss-directory)))
379     (when (file-exists-p file)
380       (with-temp-buffer
381         (let ((coding-system-for-read 'binary)
382               emacs-lisp-mode-hook)
383           (insert-file-contents file)
384           (emacs-lisp-mode)
385           (goto-char (point-min))
386           (eval-buffer))))))
387
388 (defun nnrss-save-server-data (server)
389   (gnus-make-directory nnrss-directory)
390   (let ((file (expand-file-name
391                (nnrss-translate-file-chars
392                 (concat "nnrss" (and server
393                                      (not (equal server ""))
394                                      "-")
395                         server ".el"))
396                nnrss-directory)))
397     (let ((coding-system-for-write 'binary)
398           print-level print-length)
399       (with-temp-file file
400         (insert "(setq nnrss-group-alist '"
401                 (prin1-to-string nnrss-group-alist)
402                 ")\n")
403         (insert "(setq nnrss-server-data '"
404                 (prin1-to-string nnrss-server-data)
405                 ")\n")))))
406
407 (defun nnrss-read-group-data (group server)
408   (setq nnrss-group-data nil)
409   (setq nnrss-group-hashtb (gnus-make-hashtable))
410   (let ((pair (assoc group nnrss-server-data)))
411     (setq nnrss-group-max (or (cadr pair) 0))
412     (setq nnrss-group-min (+ nnrss-group-max 1)))
413   (let ((file (expand-file-name
414                (nnrss-translate-file-chars
415                 (concat group (and server
416                                    (not (equal server ""))
417                                    "-")
418                         server ".el"))
419                nnrss-directory)))
420     (when (file-exists-p file)
421       (with-temp-buffer
422         (let ((coding-system-for-read 'binary)
423               emacs-lisp-mode-hook)
424           (insert-file-contents file)
425           (emacs-lisp-mode)
426           (goto-char (point-min))
427           (eval-buffer)))
428       (dolist (e nnrss-group-data)
429         (gnus-sethash (nth 2 e) e nnrss-group-hashtb)
430         (if (and (car e) (> nnrss-group-min (car e)))
431             (setq nnrss-group-min (car e)))
432         (if (and (car e) (< nnrss-group-max (car e)))
433             (setq nnrss-group-max (car e)))))))
434
435 (defun nnrss-save-group-data (group server)
436   (gnus-make-directory nnrss-directory)
437   (let ((file (expand-file-name
438                (nnrss-translate-file-chars
439                 (concat group (and server
440                                    (not (equal server ""))
441                                    "-")
442                         server ".el"))
443                nnrss-directory)))
444     (let ((coding-system-for-write 'binary)
445           print-level print-length)
446       (with-temp-file file
447         (insert "(setq nnrss-group-data '"
448                 (prin1-to-string nnrss-group-data)
449                 ")\n")))))
450
451 ;;; URL interface
452
453 (defun nnrss-no-cache (url)
454   "")
455
456 (defun nnrss-insert-w3 (url)
457   (mm-with-unibyte-current-buffer
458     (mm-url-insert url)))
459
460 (defun nnrss-decode-entities-unibyte-string (string)
461   (mm-with-unibyte-buffer
462     (insert string)
463     (mm-url-decode-entities-nbsp)
464     (buffer-substring (point-min) (point-max))))
465
466 (defalias 'nnrss-insert 'nnrss-insert-w3)
467
468 (if (featurep 'xemacs)
469     (defalias 'nnrss-string-as-multibyte 'identity)
470   (defalias 'nnrss-string-as-multibyte 'string-as-multibyte))
471
472 ;;; Snarf functions
473
474 (defun nnrss-check-group (group server)
475   (let (file xml subject url extra changed author date)
476     (condition-case err
477         (mm-with-unibyte-buffer
478           (if (and nnrss-use-local
479                    (file-exists-p (setq file (expand-file-name
480                                               (nnrss-translate-file-chars
481                                                (concat group ".xml"))
482                                               nnrss-directory))))
483               (insert-file-contents file)
484             (setq url (or (nth 2 (assoc group nnrss-server-data))
485                           (second (assoc group nnrss-group-alist))))
486             (unless url
487               (setq url
488                     (read-string (format "RSS url of %s: " group "http://")))
489               (let ((pair (assoc group nnrss-server-data)))
490                 (if pair
491                     (setcdr (cdr pair) (list url))
492                   (push (list group nnrss-group-max url) nnrss-server-data)))
493               (setq changed t))
494             (nnrss-insert url))
495           (goto-char (point-min))
496           (while (re-search-forward "\r\n?" nil t)
497             (replace-match "\n"))
498           (goto-char (point-min))
499           (if (re-search-forward "<rdf\\|<rss" nil t)
500               (goto-char (match-beginning 0)))
501           (setq xml (xml-parse-region (point) (point-max))))
502       (error
503        (nnheader-message 1 "Error in group %s: %s" group (cadr err))))
504     (while (and xml (not (assq 'item xml)))
505       (setq xml (cddar xml))
506       (while (not (listp (car xml)))
507         (setq xml (cdr xml))))
508     (dolist (item (nreverse xml))
509       (when (and (listp item)
510                  (eq 'item (car item))
511                  (setq url (nnrss-node-text (assq 'link (cddr item))))
512                  (setq url (nnrss-decode-entities-unibyte-string url))
513                  (not (gnus-gethash url nnrss-group-hashtb)))
514         (setq subject (nnrss-node-text (assq 'title (cddr item))))
515         (setq extra (or (nnrss-node-text (assq 'description (cddr item)))
516                         (nnrss-node-text (assq 'dc:description (cddr item)))))
517         (setq author (nnrss-node-text (assq 'dc:creator (cddr item))))
518         (setq date (or (nnrss-node-text (assq 'dc:date (cddr item)))
519                        (message-make-date)))
520         (push
521          (list
522           (incf nnrss-group-max)
523           (current-time)
524           url
525           (and subject (nnrss-decode-entities-unibyte-string subject))
526           (and author (nnrss-decode-entities-unibyte-string author))
527           date
528           (and extra (nnrss-decode-entities-unibyte-string extra)))
529          nnrss-group-data)
530         (gnus-sethash url (car nnrss-group-data) nnrss-group-hashtb)
531         (setq changed t)))
532     (when changed
533       (nnrss-save-group-data group server)
534       (let ((pair (assoc group nnrss-server-data)))
535         (if pair
536             (setcar (cdr pair) nnrss-group-max)
537           (push (list group nnrss-group-max) nnrss-server-data)))
538       (nnrss-save-server-data server))))
539
540 (defun nnrss-generate-download-script ()
541   "Generate a download script in the current buffer.
542 It is useful when `(setq nnrss-use-local t)'."
543   (interactive)
544   (insert "#!/bin/sh\n")
545   (insert "WGET=wget\n")
546   (insert "RSSDIR='" (expand-file-name nnrss-directory) "'\n")
547   (dolist (elem nnrss-server-data)
548     (let ((url (or (nth 2 elem)
549                    (second (assoc (car elem) nnrss-group-alist)))))
550       (insert "$WGET -q -O \"$RSSDIR\"/'"
551               (nnrss-translate-file-chars (concat (car elem) ".xml"))
552               "' '" url "'\n"))))
553
554 (defun nnrss-translate-file-chars (name)
555   (let ((nnheader-file-name-translation-alist
556          (append nnheader-file-name-translation-alist '((?' . ?_)))))
557     (nnheader-translate-file-chars name)))
558
559 (defvar nnrss-moreover-url
560   "http://w.moreover.com/categories/category_list_rss.html"
561   "The url of moreover.com categories.")
562
563 (defun nnrss-snarf-moreover-categories ()
564   "Snarf RSS links from moreover.com."
565   (interactive)
566   (let (category name url changed)
567     (with-temp-buffer
568       (nnrss-insert nnrss-moreover-url)
569       (goto-char (point-min))
570       (while (re-search-forward
571               "<A NAME=\"\\([^\"]+\\)\">\\|<A HREF=\"\\(http://[^\"]*moreover\\.com[^\"]+page\\?c=\\([^\"&]+\\)&o=rss\\)" nil t)
572         (if (match-string 1)
573             (setq category (match-string 1))
574           (setq url (match-string 2)
575                 name (mm-url-decode-entities-string
576                       (rfc2231-decode-encoded-string
577                        (match-string 3))))
578           (if category
579               (setq name (concat category "." name)))
580           (unless (assoc name nnrss-server-data)
581             (setq changed t)
582             (push (list name 0 url) nnrss-server-data)))))
583     (if changed
584         (nnrss-save-server-data ""))))
585
586 (defun nnrss-format-string (string)
587   (gnus-replace-in-string (nnrss-string-as-multibyte string) " *\n *" " "))
588
589 (defun nnrss-node-text (node)
590   (if (and node (listp node))
591       (mapconcat 'nnrss-node-text (cddr node) "")
592     node))
593
594 (provide 'nnrss)
595
596 ;;; nnrss.el ends here