;; -*- emacs-lisp -*-
;;; gnus-mst-kuro5hin.el --- read kuro5hin digests as a group

;; Author: Mark Triggs <mst@dishevelled.net>
;; Keywords: news
;; $Id: gnus-mst-kuro5hin.el,v 1.11 2003/04/16 07:06:06 mrbump Exp $

;; This file 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 file 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 GNU Emacs; see the file COPYING.  If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.

;;; Code:

(defun nndoc-generate-kuro5hin-head (article)
  (let ((entry (cdr (assq article nndoc-dissection-alist)))
        (e-mail "no address given")
        subject author)
    (save-excursion
      (set-buffer nndoc-current-buffer)
      (save-restriction
        (narrow-to-region (car entry) (nth 1 entry))
        (goto-char (point-min))

        ;; Get the subject
        (re-search-forward "^\\(.*\\)$" nil t)
        (setq subject (match-string 1))

        ;; Get the author
        (forward-line 1)
        (re-search-forward "^ *\\(By\\)? \\(.*\\)$" nil t)
        (setq author (match-string 2))))

    (insert "From: "  (or author "unknown")
            "\nSubject: " (or subject "(no subject)") "\n")))


(nndoc-add-type
 '(kuro5hin
   (first-article
    . "---------------------------------------------------------\n\n")
   (article-begin . "----\n\n")
   (generate-head-function . nndoc-generate-kuro5hin-head)
   (body-end . "----"))t)


(defun nndoc-kuro5hin-type-p ()
  (goto-char (point-min))
  (while (and (not (looking-at "This is the Weekly digest for Kuro5hin.org."))
              (not (eobp)))
    (forward-line 1))

  (if (not (eobp))
      t
    nil))


(provide 'gnus-mst-kuro5hin)
