;;; sb-rss.el --- shimbun backend for RSS (Rich Site Summary). ;; Copyright (C) 2003 NAKAJIMA Mikio ;; Author: NAKAJIMA Mikio ;; Keywords: news ;; Created: Jun 14, 2003 ;; This file is a part of shimbun. ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 2, or (at your option) ;; any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program; if not, you can either send email to this ;; program's maintainer or write to: The Free Software Foundation, ;; Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA. ;;; Commentary: ;;; Code: (require 'shimbun) (luna-define-class shimbun-rss (shimbun) ()) (luna-define-generic shimbun-rss-get-date (shimbun-rss) "Process and return Date string in each item node of RSS file.") (luna-define-generic shimbun-rss-process-channel (shimbun-rss) "Process channel type elements in RSS file.") (luna-define-generic shimbun-rss-build-message-id (shimbun-rss) "Building message-id.") ;;(luna-define-generic shimbun-rss-from (shimbun-rss) ;; "") (luna-define-method shimbun-rss-process-channel ((shimbun shimbun-rss)) nil) (luna-define-method shimbun-headers ((shimbun shimbun-rss) &optional range) (with-temp-buffer (let ((case-fold-search t) encoding) (shimbun-retrieve-url (shimbun-index-url shimbun) 'no-cache 'no-decode) (if (not (looking-at ;;"<\\?xml version=\"1.0\" encoding=\"\\(.+\\)\" *\\?>")) "<\\?xml version=\"1.0\" encoding=\"\\(.+\\)\"")) (error "invalid xml") (setq encoding (intern-soft (downcase (match-string 1))))) (decode-coding-region (point-min) (point-max) encoding) (set-buffer-multibyte t) (shimbun-get-headers shimbun range)))) (luna-define-method shimbun-get-headers ((shimbun shimbun-rss) &optional range) (let ((case-fold-search t) date start end url subject date id headers) (goto-char (point-min)) (setq start (re-search-forward "" nil t nil)) (when (and start end) (save-excursion (save-restriction (narrow-to-region start end) (shimbun-rss-process-channel shimbun)))) (catch 'stop (while (re-search-forward "" nil t nil) (setq url (match-string 1) start (match-beginning 0) end (or (re-search-forward "<\\/item>" nil t nil) (point-max))) (save-excursion (save-restriction (narrow-to-region start end) (goto-char start) (when (re-search-forward "" nil t nil) (setq subject (buffer-substring (point) (and (re-search-forward "<\\/title>" nil t nil) (match-beginning 0))))) (setq date (shimbun-rss-get-date shimbun) id (shimbun-rss-build-message-id shimbun) ;;from (shimbun-rss-from shimbun) ))) (if (shimbun-search-id shimbun id) (throw 'stop nil)) (push (shimbun-make-header 0 (shimbun-mime-encode-string subject) ;;XXX from (shimbun-from-address shimbun) date id "" 0 0 url) headers))) headers)) (provide 'sb-rss) ;; end of sb-rss.el