1 ;;; nnslashdot.el --- interfacing with Slashdot
2 ;; Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; This file is part of GNU Emacs.
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 by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
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.
28 (eval-when-compile (require 'cl))
38 (nnoo-declare nnslashdot)
40 (defvoo nnslashdot-directory (nnheader-concat gnus-directory "slashdot/")
41 "Where nnslashdot will save its files.")
43 (defvoo nnslashdot-active-url "http://slashdot.org/search.pl?section=&min=%d"
44 "Where nnslashdot will fetch the active file from.")
46 (defvoo nnslashdot-comments-url "http://slashdot.org/comments.pl?sid=%s&threshold=%d&commentsort=%d&mode=flat&startat=%d"
47 "Where nnslashdot will fetch comments from.")
49 (defvoo nnslashdot-article-url
50 "http://slashdot.org/article.pl?sid=%s&mode=nocomment"
51 "Where nnslashdot will fetch the article from.")
53 (defvoo nnslashdot-backslash-url "http://slashdot.org/slashdot.xml"
54 "Where nnslashdot will fetch the stories from.")
56 (defvoo nnslashdot-use-front-page nil
57 "Use the front page in addition to the backslash page.")
59 (defvoo nnslashdot-threshold -1
60 "The article threshold.")
62 (defvoo nnslashdot-threaded t
63 "Whether the nnslashdot groups should be threaded or not.")
65 (defvoo nnslashdot-group-number 0
66 "The number of non-fresh groups to keep updated.")
68 (defvoo nnslashdot-login-name ""
69 "The login name to use when posting.")
71 (defvoo nnslashdot-password ""
72 "The password to use when posting.")
74 ;;; Internal variables
76 (defvar nnslashdot-groups nil)
77 (defvar nnslashdot-buffer nil)
78 (defvar nnslashdot-headers nil)
80 ;;; Interface functions
82 (nnoo-define-basics nnslashdot)
84 (deffoo nnslashdot-retrieve-headers (articles &optional group server fetch-old)
85 (nnslashdot-possibly-change-server group server)
87 (unless gnus-nov-is-evil
88 (nnslashdot-retrieve-headers-1 articles group))
89 (search-failed (nnslashdot-lose why))))
91 (deffoo nnslashdot-retrieve-headers-1 (articles group)
92 (let* ((last (car (last articles)))
93 (start (if nnslashdot-threaded 1 (pop articles)))
94 (entry (assoc group nnslashdot-groups))
97 headers article subject score from date lines parent point cid
100 (set-buffer nnslashdot-buffer)
101 (let ((case-fold-search t))
104 (mm-url-insert (format nnslashdot-article-url sid) t)
105 (goto-char (point-min))
107 (error "Couldn't open connection to slashdot"))
108 (re-search-forward "Posted by[ \t\r\n]+")
109 (when (looking-at "\\(<a[^>]+>\\)?[ \t\r\n]*\\([^<\r\n]+\\)")
110 (setq from (mm-url-decode-entities-string (match-string 2))))
111 (search-forward "on ")
112 (setq date (nnslashdot-date-to-date
113 (buffer-substring (point) (1- (search-forward "<")))))
114 (setq lines (/ (- (point)
115 (progn (forward-line 1) (point)))
120 (make-full-mail-header
122 (concat "<" sid "%1@slashdot>")
125 (setq start (if nnslashdot-threaded 2 (pop articles))))
126 (while (and start (<= start last))
127 (setq point (goto-char (point-max)))
129 (format nnslashdot-comments-url sid
130 nnslashdot-threshold 0 (- start 2))
132 (when (and nnslashdot-threaded first-comments)
133 (setq first-comments nil)
134 (goto-char (point-max))
135 (while (re-search-backward "startat=\\([0-9]+\\)" nil t)
136 (setq s (string-to-number (match-string 1)))
137 (unless (memq s startats)
139 (setq startats (sort startats '<)))
140 (setq article (if (and article (< start article)) article start))
142 (while (re-search-forward
143 "<a name=\"\\([0-9]+\\)\"><\\(b\\|H4\\)>\\([^<]+\\)</\\(b\\|H4\\)>.*score:\\([^)]+\\))"
145 (setq cid (match-string 1)
146 subject (match-string 3)
147 score (match-string 5))
148 (unless (assq article (nth 4 entry))
149 (setcar (nthcdr 4 entry) (cons (cons article cid) (nth 4 entry)))
151 (when (string-match "^Re: *" subject)
152 (setq subject (concat "Re: " (substring subject (match-end 0)))))
153 (setq subject (mm-url-decode-entities-string subject))
154 (search-forward "<BR>")
156 "by[ \t\n]+<a[^>]+>\\([^<]+\\)</a>[ \t\n]*(\\(<[^>]+>\\)*\\([^<>)]+\\))")
158 (goto-char (- (match-end 0) 5))
160 (mm-url-decode-entities-string (match-string 1))
161 " <" (match-string 3) ">")))
163 (when (looking-at "by \\([^<>]*\\) on ")
164 (goto-char (- (match-end 0) 5))
165 (setq from (mm-url-decode-entities-string (match-string 1)))))
166 (search-forward " on ")
168 (nnslashdot-date-to-date
169 (buffer-substring (point) (progn (skip-chars-forward "^()<>\n\r") (point)))))
170 (setq lines (/ (abs (- (search-forward "<td")
171 (search-forward "</td>")))
174 (re-search-forward ".*cid=\\([0-9]+\\)\">Parent</A>" nil t))
176 (setq parent (match-string 1))
177 (when (string= parent "0")
182 (make-full-mail-header
184 (concat subject " (" score ")")
186 (concat "<" sid "%" cid "@slashdot>")
188 (concat "<" sid "%" parent "@slashdot>")
192 (while (and articles (<= (car articles) article))
194 (setq article (1+ article)))
195 (if nnslashdot-threaded
197 (setq start (pop startats))
198 (if start (setq start (+ start 2))))
199 (setq start (pop articles))))))
200 (if changed (nnslashdot-write-groups))
201 (setq nnslashdot-headers (sort headers 'car-less-than-car))
203 (set-buffer nntp-server-buffer)
205 (mm-with-unibyte-current-buffer
206 (dolist (header nnslashdot-headers)
207 (nnheader-insert-nov (cdr header)))))
210 (deffoo nnslashdot-request-group (group &optional server dont-check)
211 (nnslashdot-possibly-change-server nil server)
212 (let ((elem (assoc group nnslashdot-groups)))
215 (nnheader-report 'nnslashdot "Group does not exist"))
217 (nnheader-report 'nnslashdot "Opened group %s" group)
219 "211 %d %d %d %s\n" (cadr elem) 1 (cadr elem)
220 (prin1-to-string group))))))
222 (deffoo nnslashdot-close-group (group &optional server)
223 (nnslashdot-possibly-change-server group server)
224 (when (gnus-buffer-live-p nnslashdot-buffer)