;;; sb-ruby.el --- shimbun backend class for ruby ML archiver. ;; Copyright (C) 2001, 2002 NAKAJIMA Mikio ;; Author: NAKAJIMA Mikio ;; Keywords: news ;; 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-ruby (shimbun) ()) (defvar shimbun-ruby-url "http://blade.nagaokaut.ac.jp") (defconst shimbun-ruby-group-path-alist '(("comp.lang.ruby" . "ruby/comp.lang.ruby") ("fj.comp.lang.ruby" . "ruby/fj.comp.lang.ruby") ("ruby-dev" . "ruby/ruby-dev") ("ruby-ext" . "ruby/ruby-ext") ("ruby-list" . "ruby/ruby-list") ("ruby-math" . "ruby/ruby-math") ("ruby-talk" . "ruby/ruby-talk"))) (defvar shimbun-ruby-groups (mapcar 'car shimbun-ruby-group-path-alist)) (defvar shimbun-ruby-optional-headers '("in-reply-to" "x-mail-count" "x-ml-name" "user-agent" "x-mailer")) ;;(luna-define-method shimbun-reply-to ((shimbun shimbun-ruby)) ;; ;;) (defsubst shimbun-ruby-parse-time (str) (save-match-data (if (string-match "\\([0-9]+\\)/\\([0-9]+\\)/\\([0-9]+\\) \\([0-9]+:[0-9]+:[0-9]+\\)" str) (shimbun-make-date-string (string-to-number (match-string 1 str)) (string-to-number (match-string 2 str)) (string-to-number (match-string 3 str)) (match-string 4 str)) str))) (defun shimbun-ruby-original-headers (url header) (let ((case-fold-search t) (headers '(("subject" . shimbun-header-set-subject) ("from" . shimbun-header-set-from) ("date" . shimbun-header-set-date) ("message-id" . shimbun-header-set-id) ("references" . shimbun-header-set-references))) (opt "") regexp key value) (setq regexp (concat "^\\(" (mapconcat 'car headers "\\|") "\\): +")) (with-temp-buffer (shimbun-retrieve-url url) (std11-narrow-to-header) (goto-char (point-min)) (while (re-search-forward regexp nil t) (setq key (downcase (match-string 1))) (setq value (buffer-substring (match-end 0) (std11-field-end))) (funcall (cdr (assoc key headers)) header value)) (goto-char (point-min)) (setq regexp (concat "^\\(" (mapconcat 'identity shimbun-ruby-optional-headers "\\|") "\\): +")) (while (re-search-forward regexp nil t) (setq opt (concat opt (buffer-substring (match-beginning 0) (std11-field-end)) "\n")))) (list header opt))) (luna-define-method shimbun-index-url ((shimbun shimbun-ruby)) (concat (shimbun-url-internal shimbun) "/" (cdr (assoc (shimbun-current-group-internal shimbun) shimbun-ruby-group-path-alist)) "/index.shtml")) (luna-define-method shimbun-get-headers ((shimbun shimbun-ruby) &optional range) (let ((case-fold-search t) (start (progn (re-search-forward "" nil t nil) (point))) (pages (shimbun-header-index-pages range)) (count 0) headers auxs aux) ;; Use entire archive. (while (and (if pages (<= (incf count) pages) t) (re-search-backward "" start t)) (setq auxs (append auxs (list (match-string 1))))) (catch 'stop (while auxs (with-temp-buffer (shimbun-retrieve-url (concat (shimbun-url-internal shimbun) "/" (cdr (assoc (shimbun-current-group-internal shimbun) shimbun-ruby-group-path-alist)) "/" (setq aux (car auxs)))) (subst-char-in-region (point-min) (point-max) ?\t ? t) (let ((case-fold-search t) id url date subject from) (goto-char (point-max)) (while (re-search-backward "^
\\(\\)?]+\\)\">\\([0-9]+\\) \\([ /:0-9]+\\) \\[\\([^[]+\\)\\][ !]\\(.+\\)$" nil t) (setq url (concat shimbun-ruby-url (match-string 2)) id (format "<%s%05d%%%s>" aux (string-to-number (match-string 3)) (shimbun-current-group-internal shimbun)) date (shimbun-ruby-parse-time (match-string 4)) from (match-string 5) subject (match-string 6)) (if (shimbun-search-id shimbun id) (throw 'stop nil)) (push (shimbun-make-header 0 (shimbun-mime-encode-string subject) from date id "" 0 0 url) headers))) (setq auxs (cdr auxs))))) (nreverse headers))) (luna-define-method shimbun-make-contents ((shimbun shimbun-ruby) header) (let (headers charset) (when (re-search-forward "\"\\[Original\\]\"") (setq headers (shimbun-ruby-original-headers (concat shimbun-ruby-url (match-string 1)) header)) (setq header (car headers))) (when (search-forward "
" nil t) (delete-region (point-min) (point))) (when (re-search-forward "^
" nil t nil) (delete-region (match-beginning 0) (point-max))) (setq charset (upcase (symbol-name (detect-mime-charset-region (point-min) (point-max))))) (goto-char (point-min)) (shimbun-header-insert shimbun header) (if headers (insert (cadr headers))) (insert "Content-Type: text/html; charset=" charset "\n" "MIME-Version: 1.0\n") (insert "\n
\n")
    (goto-char (point-max))
    (insert "
") (encode-coding-string (buffer-string) (mime-charset-to-coding-system charset)))) (provide 'sb-ruby) ;;; sb-ruby.el ends here