* elmo.el: Moved obsolete variable definitions from
[elisp/wanderlust.git] / elmo / sb-fml.el
1 ;;; sb-fml.el --- shimbun backend class for fml archiver.
2
3 ;; Author: TSUCHIYA Masatoshi <tsuchiya@pine.kuee.kyoto-u.ac.jp>
4 ;;         Akihiro Arisawa    <ari@atesoft.advantest.co.jp>
5 ;;         Yuuichi Teranishi <teranisi@gohome.org>
6
7 ;; Keywords: news
8
9 ;;; Copyright:
10
11 ;; This program is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; This program is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with this program; if not, you can either send email to this
23 ;; program's maintainer or write to: The Free Software Foundation,
24 ;; Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA.
25
26 ;;; Commentary:
27
28 ;; Original code was nnshimbun.el written by
29 ;; TSUCHIYA Masatoshi <tsuchiya@pine.kuee.kyoto-u.ac.jp>.
30
31 ;;; Code:
32
33 (require 'shimbun)
34
35 (luna-define-class shimbun-fml (shimbun) ())
36
37 (luna-define-method shimbun-get-headers ((shimbun shimbun-fml))
38   (let ((case-fold-search t)
39         headers auxs aux)
40     (catch 'stop
41       ;; Only latest month.
42       (if (re-search-forward "<a href=\"\\([0-9]+\\(\\.week\\|\\.month\\)?\\)/index.html\">" nil t)
43         (setq auxs (append auxs (list (match-string 1)))))
44       (while auxs
45         (with-temp-buffer
46           (shimbun-retrieve-url
47            shimbun
48            (concat (shimbun-url-internal shimbun) (setq aux (car auxs)) "/"))
49           (subst-char-in-region (point-min) (point-max) ?\t ?  t)
50           (let ((case-fold-search t)
51                 id url date subject from)
52             (goto-char (point-min))
53             (while (re-search-forward
54                     "<LI><A HREF=\"\\([0-9]+\\.html\\)\">Article .*</A> <DIV><SPAN CLASS=article>Article <SPAN CLASS=article-value>\\([0-9]+\\)</SPAN></SPAN> at <SPAN CLASS=Date-value>\\([^<]*\\)</SPAN> <SPAN CLASS=Subject>Subject: <SPAN CLASS=Subject-value>\\([^<]*\\)</SPAN></SPAN></DIV><DIV><SPAN CLASS=From>From: <SPAN CLASS=From-value>\\([^<]*\\)</SPAN></SPAN></DIV>"
55                     nil t)
56               (setq url (concat (shimbun-url-internal shimbun)
57                                 aux "/" (match-string 1))
58                     id (format "<%s%05d%%%s>"
59                                aux
60                                (string-to-number (match-string 2))
61                                (shimbun-current-group-internal shimbun))
62                     date (match-string 3)
63                     subject (match-string 4)
64                     from (match-string 5))
65               (forward-line 1)
66               (push (shimbun-make-header
67                      0
68                      (shimbun-mime-encode-string subject)
69                      from date id "" 0 0 url)
70                     headers)))
71           (setq auxs (cdr auxs))))
72       headers)))
73
74 (luna-define-method shimbun-make-contents ((shimbun shimbun-fml) header)
75   (catch 'stop
76     (if (search-forward "<SPAN CLASS=mailheaders>" nil t)
77         (delete-region (point-min) (point))
78       (throw 'stop nil))
79     (if (search-forward "</PRE>")
80         (progn
81           (beginning-of-line)
82           (delete-region (point) (point-max)))
83       (throw 'stop nil))
84     (if (search-backward "</SPAN>")
85         (progn
86           (beginning-of-line)
87           (kill-line))
88       (throw 'stop nil))
89     (save-restriction
90       (narrow-to-region (point-min) (point))
91       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
92       (shimbun-decode-entities)
93       (goto-char (point-min))
94       (let ((header (shimbun-make-header))
95             field value start value-beg end)
96         (while (and (setq start (point))
97                     (re-search-forward "<SPAN CLASS=\\(.*\\)>\\(.*\\)</SPAN>:"
98                                        nil t)
99                     (setq field (match-string 2))
100                     (re-search-forward
101                      (concat "<SPAN CLASS=" (match-string 1) "-value>") nil t)
102                     (setq value-beg (point))
103                     (search-forward "</SPAN>" nil t)
104                     (setq end (point)))
105           (setq value (buffer-substring value-beg
106                                         (progn (search-backward "</SPAN>")
107                                                (point))))
108           (delete-region start end)
109           (cond ((string= field "Date")
110                  (shimbun-header-set-date header value))
111                 ((string= field "From")
112                  (shimbun-header-set-from header value))
113                 ((string= field "Subject")
114                  (shimbun-header-set-subject header value))
115                 ((string= field "Message-Id")
116                  (shimbun-header-set-id header value))
117                 ((string= field "References")
118                  (shimbun-header-set-references header value))
119                 (t
120                  (insert (concat field ": " value "\n")))))
121         (goto-char (point-min))
122         (shimbun-header-insert header))
123       (goto-char (point-max)))
124     ;; Processing body.
125     (save-restriction
126       (narrow-to-region (point) (point-max))
127       (shimbun-remove-markup)
128       (shimbun-decode-entities)))
129   (encode-coding-string (buffer-string)
130                         (mime-charset-to-coding-system "ISO-2022-JP")))
131
132 (provide 'sb-fml)
133
134 ;;; sb-fml.el ends here