T-gnus 6.15.10 revision 00.
[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               (input-coding-system 'binary)
383               emacs-lisp-mode-hook)
384           (insert-file-contents file)
385           (emacs-lisp-mode)
386           (goto-char (point-min))
387           (eval-buffer))))))
388
389 (defun nnrss-save-server-data (server)
390   (gnus-make-directory nnrss-directory)
391   (let ((file (expand-file-name
392                (nnrss-translate-file-chars
393                 (concat "nnrss" (and server
394                                      (not (equal server ""))
395                                      "-")
396                         server ".el"))
397                nnrss-directory)))
398     (let ((coding-system-for-write 'binary)
399           (output-coding-system 'binary)
400           print-level print-length)
401       (with-temp-file file
402         (insert "(setq nnrss-group-alist '"
403                 (prin1-to-string nnrss-group-alist)
404                 ")\n")
405         (insert "(setq nnrss-server-data '"
406                 (prin1-to-string nnrss-server-data)
407                 ")\n")))))
408
409 (defun nnrss-read-group-data (group server)
410   (setq nnrss-group-data nil)
411   (setq nnrss-group-hashtb (gnus-make-hashtable))
412   (let ((pair (assoc group nnrss-server-data)))
413     (setq nnrss-group-max (or (cadr pair) 0))
414     (setq nnrss-group-min (+ nnrss-group-max 1)))
415   (let ((file (expand-file-name
416                (nnrss-translate-file-chars
417                 (concat group (and server
418                                    (not (equal server ""))
419                                    "-")
420                         server ".el"))
421                nnrss-directory)))
422     (when (file-exists-p file)
423       (with-temp-buffer
424         (let ((coding-system-for-read 'binary)
425               (input-coding-system 'binary)
426               emacs-lisp-mode-hook)
427           (insert-file-contents file)
428           (emacs-lisp-mode)
429           (goto-char (point-min))
430           (eval-buffer)))
431       (dolist (e nnrss-group-data)
432         (gnus-sethash (nth 2 e) e nnrss-group-hashtb)
433         (if (and (car e) (> nnrss-group-min (car e)))
434             (setq nnrss-group-min (car e)))
435         (if (and (car e) (< nnrss-group-max (car e)))
436             (setq nnrss-group-max (car e)))))))
437
438 (defun nnrss-save-group-data (group server)
439   (gnus-make-directory nnrss-directory)
440   (let ((file (expand-file-name
441                (nnrss-translate-file-chars
442                 (concat group (and server
443                                    (not (equal server ""))
444                                    "-")
445                         server ".el"))
446                nnrss-directory)))
447     (let ((coding-system-for-write 'binary)
448           (output-coding-system 'binary)
449           print-level print-length)
450       (with-temp-file file
451         (insert "(setq nnrss-group-data '"
452                 (prin1-to-string nnrss-group-data)
453                 ")\n")))))
454
455 ;;; URL interface
456
457 (defun nnrss-no-cache (url)
458   "")
459
460 (defun nnrss-insert-w3 (url)
461   (mm-with-unibyte-current-buffer
462     (mm-url-insert url)))
463
464 (defun nnrss-decode-entities-unibyte-string (string)
465   (mm-with-unibyte-buffer
466     (insert string)
467     (mm-url-decode-entities-nbsp)
468     (buffer-substring (point-min) (point-max))))
469
470 (defalias 'nnrss-insert 'nnrss-insert-w3)
471
472 (if (featurep 'xemacs)
473     (defalias 'nnrss-string-as-multibyte 'identity)
474   (defalias 'nnrss-string-as-multibyte 'string-as-multibyte))
475
476 ;;; Snarf functions
477
478 (defun nnrss-check-group (group server)
479   (let (file xml subject url extra changed author date)
480     (condition-case err
481         (mm-with-unibyte-buffer
482           (if (and nnrss-use-local
483                    (file-exists-p (setq file (expand-file-name
484                                               (nnrss-translate-file-chars
485                                                (concat group ".xml"))
486                                               nnrss-directory))))
487               (insert-file-contents file)
488             (setq url (or (nth 2 (assoc group nnrss-server-data))
489                           (second (assoc group nnrss-group-alist))))
490             (unless url
491               (setq url
492                     (read-string (format "RSS url of %s: " group "http://")))
493               (let ((pair (assoc group nnrss-server-data)))
494                 (if pair
495                     (setcdr (cdr pair) (list url))
496                   (push (list group nnrss-group-max url) nnrss-server-data)))
497               (setq changed t))
498             (nnrss-insert url))
499           (goto-char (point-min))
500           (while (re-search-forward "\r\n?" nil t)
501             (replace-match "\n"))
502           (goto-char (point-min))
503           (if (re-search-forward "<rdf\\|<rss" nil t)
504               (goto-char (match-beginning 0)))
505           (setq xml (xml-parse-region (point) (point-max))))
506       (error
507        (nnheader-message 1 "Error in group %s: %s" group (cadr err))))
508     (while (and xml (not (assq 'item xml)))
509       (setq xml (cddar xml))
510       (while (not (listp (car xml)))
511         (setq xml (cdr xml))))
512     (dolist (item (nreverse xml))
513       (when (and (listp item)
514                  (eq 'item (car item))
515                  (setq url (nnrss-node-text (assq 'link (cddr item))))
516                  (setq url (nnrss-decode-entities-unibyte-string url))
517                  (not (gnus-gethash url nnrss-group-hashtb)))
518         (setq subject (nnrss-node-text (assq 'title (cddr item))))
519         (setq extra (or (nnrss-node-text (assq 'description (cddr item)))
520                         (nnrss-node-text (assq 'dc:description (cddr item)))))
521         (setq author (nnrss-node-text (assq 'dc:creator (cddr item))))
522         (setq date (or (nnrss-node-text (assq 'dc:date (cddr item)))
523                        (message-make-date)))
524         (push
525          (list
526           (incf nnrss-group-max)
527           (current-time)
528           url
529           (and subject (nnrss-decode-entities-unibyte-string subject))
530           (and author (nnrss-decode-entities-unibyte-string author))
531           date
532           (and extra (nnrss-decode-entities-unibyte-string extra)))
533          nnrss-group-data)
534         (gnus-sethash url (car nnrss-group-data) nnrss-group-hashtb)
535         (setq changed t)))
536     (when changed
537       (nnrss-save-group-data group server)
538       (let ((pair (assoc group nnrss-server-data)))
539         (if pair
540             (setcar (cdr pair) nnrss-group-max)
541           (push (list group nnrss-group-max) nnrss-server-data)))
542       (nnrss-save-server-data server))))
543
544 (defun nnrss-generate-download-script ()
545   "Generate a download script in the current buffer.
546 It is useful when `(setq nnrss-use-local t)'."
547   (interactive)
548   (insert "#!/bin/sh\n")
549   (insert "WGET=wget\n")
550   (insert "RSSDIR='" (expand-file-name nnrss-directory) "'\n")
551   (dolist (elem nnrss-server-data)
552     (let ((url (or (nth 2 elem)
553                    (second (assoc (car elem) nnrss-group-alist)))))
554       (insert "$WGET -q -O \"$RSSDIR\"/'"
555               (nnrss-translate-file-chars (concat (car elem) ".xml"))
556               "' '" url "'\n"))))
557
558 (defun nnrss-translate-file-chars (name)
559   (let ((nnheader-file-name-translation-alist
560          (append nnheader-file-name-translation-alist '((?' . ?_)))))
561     (nnheader-translate-file-chars name)))
562
563 (defvar nnrss-moreover-url
564   "http://w.moreover.com/categories/category_list_rss.html"
565   "The url of moreover.com categories.")
566
567 (defun nnrss-snarf-moreover-categories ()
568   "Snarf RSS links from moreover.com."
569   (interactive)
570   (let (category name url changed)
571     (with-temp-buffer
572       (nnrss-insert nnrss-moreover-url)
573       (goto-char (point-min))
574       (while (re-search-forward
575               "<A NAME=\"\\([^\"]+\\)\">\\|<A HREF=\"\\(http://[^\"]*moreover\\.com[^\"]+page\\?c=\\([^\"&]+\\)&o=rss\\)" nil t)
576         (if (match-string 1)
577             (setq category (match-string 1))
578           (setq url (match-string 2)
579                 name (mm-url-decode-entities-string
580                       (rfc2231-decode-encoded-string
581                        (match-string 3))))
582           (if category
583               (setq name (concat category "." name)))
584           (unless (assoc name nnrss-server-data)
585             (setq changed t)
586             (push (list name 0 url) nnrss-server-data)))))
587     (if changed
588         (nnrss-save-server-data ""))))
589
590 (defun nnrss-format-string (string)
591   (gnus-replace-in-string (nnrss-string-as-multibyte string) " *\n *" " "))
592
593 (defun nnrss-node-text (node)
594   (if (and node (listp node))
595       (mapconcat 'nnrss-node-text (cddr node) "")
596     node))
597
598 (provide 'nnrss)
599
600 ;;; nnrss.el ends here