;;; nnslashdot.el --- interfacing with Slashdot ;; Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc. ;; Author: Lars Magne Ingebrigtsen ;; Keywords: news ;; This file is part of GNU Emacs. ;; GNU Emacs 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. ;; GNU Emacs 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. ;;; Commentary: ;;; Code: (eval-when-compile (require 'cl)) (eval-when-compile (require 'gnus-clfns)) (require 'nnoo) (require 'message) (require 'gnus-util) (require 'gnus) (require 'nnmail) (require 'mm-util) (require 'mm-url) (nnoo-declare nnslashdot) (defvoo nnslashdot-directory (nnheader-concat gnus-directory "slashdot/") "Where nnslashdot will save its files.") (defvoo nnslashdot-active-url "http://slashdot.org/search.pl?section=&min=%d" "Where nnslashdot will fetch the active file from.") (defvoo nnslashdot-comments-url "http://slashdot.org/comments.pl?sid=%s&threshold=%d&commentsort=%d&mode=flat&startat=%d" "Where nnslashdot will fetch comments from.") (defvoo nnslashdot-article-url "http://slashdot.org/article.pl?sid=%s&mode=nocomment" "Where nnslashdot will fetch the article from.") (defvoo nnslashdot-backslash-url "http://slashdot.org/slashdot.xml" "Where nnslashdot will fetch the stories from.") (defvoo nnslashdot-threshold -1 "The article threshold.") (defvoo nnslashdot-threaded t "Whether the nnslashdot groups should be threaded or not.") (defvoo nnslashdot-group-number 0 "The number of non-fresh groups to keep updated.") (defvoo nnslashdot-login-name "" "The login name to use when posting.") (defvoo nnslashdot-password "" "The password to use when posting.") ;;; Internal variables (defvar nnslashdot-groups nil) (defvar nnslashdot-buffer nil) (defvar nnslashdot-headers nil) ;;; Interface functions (nnoo-define-basics nnslashdot) (deffoo nnslashdot-retrieve-headers (articles &optional group server fetch-old) (nnslashdot-possibly-change-server group server) (condition-case why (unless gnus-nov-is-evil (nnslashdot-retrieve-headers-1 articles group)) (search-failed (nnslashdot-lose why)))) (deffoo nnslashdot-retrieve-headers-1 (articles group) (let* ((last (car (last articles))) (start (if nnslashdot-threaded 1 (pop articles))) (entry (assoc group nnslashdot-groups)) (sid (nth 2 entry)) (first-comments t) headers article subject score from date lines parent point cid s startats changed) (save-excursion (set-buffer nnslashdot-buffer) (let ((case-fold-search t)) (erase-buffer) (when (= start 1) (mm-url-insert (format nnslashdot-article-url sid) t) (goto-char (point-min)) (if (eobp) (error "Couldn't open connection to slashdot")) (re-search-forward "Posted by[ \t\r\n]+") (when (looking-at "\\(]+>\\)?[ \t\r\n]*\\([^<\r\n]+\\)") (setq from (mm-url-decode-entities-string (match-string 2)))) (search-forward "on ") (setq date (nnslashdot-date-to-date (buffer-substring (point) (1- (search-forward "<"))))) (setq lines (/ (- (point) (progn (forward-line 1) (point))) 60)) (push (cons 1 (make-full-mail-header 1 group from date (concat "<" sid "%1@slashdot>") "" 0 lines nil nil)) headers) (setq start (if nnslashdot-threaded 2 (pop articles)))) (while (and start (<= start last)) (setq point (goto-char (point-max))) (mm-url-insert (format nnslashdot-comments-url sid nnslashdot-threshold 0 (- start 2)) t) (when (and nnslashdot-threaded first-comments) (setq first-comments nil) (goto-char (point-max)) (while (re-search-backward "startat=\\([0-9]+\\)" nil t) (setq s (string-to-number (match-string 1))) (unless (memq s startats) (push s startats))) (setq startats (sort startats '<))) (setq article (if (and article (< start article)) article start)) (goto-char point) (while (re-search-forward "<\\(b\\|H4\\)>\\([^<]+\\).*score:\\([^)]+\\))" nil t) (setq cid (match-string 1) subject (match-string 3) score (match-string 5)) (unless (assq article (nth 4 entry)) (setcar (nthcdr 4 entry) (cons (cons article cid) (nth 4 entry))) (setq changed t)) (when (string-match "^Re: *" subject) (setq subject (concat "Re: " (substring subject (match-end 0))))) (setq subject (mm-url-decode-entities-string subject)) (search-forward "
") (if (looking-at "by[ \t\n]+]+>\\([^<]+\\)
[ \t\n]*(\\(<[^>]+>\\)*\\([^<>)]+\\))") (progn (goto-char (- (match-end 0) 5)) (setq from (concat (mm-url-decode-entities-string (match-string 1)) " <" (match-string 3) ">"))) (setq from "") (when (looking-at "by \\([^<>]*\\) on ") (goto-char (- (match-end 0) 5)) (setq from (mm-url-decode-entities-string (match-string 1))))) (search-forward " on ") (setq date (nnslashdot-date-to-date (buffer-substring (point) (progn (skip-chars-forward "^()<>\n\r") (point))))) (setq lines (/ (abs (- (search-forward ""))) 70)) (if (not (re-search-forward ".*cid=\\([0-9]+\\)\">Parent" nil t)) (setq parent nil) (setq parent (match-string 1)) (when (string= parent "0") (setq parent nil))) (push (cons article (make-full-mail-header article (concat subject " (" score ")") from date (concat "<" sid "%" cid "@slashdot>") (if parent (concat "<" sid "%" parent "@slashdot>") "") 0 lines nil nil)) headers) (while (and articles (<= (car articles) article)) (pop articles)) (setq article (1+ article))) (if nnslashdot-threaded (progn (setq start (pop startats)) (if start (setq start (+ start 2)))) (setq start (pop articles)))))) (if changed (nnslashdot-write-groups)) (setq nnslashdot-headers (sort headers 'car-less-than-car)) (save-excursion (set-buffer nntp-server-buffer) (erase-buffer) (mm-with-unibyte-current-buffer (dolist (header nnslashdot-headers) (nnheader-insert-nov (cdr header))))) 'nov)) (deffoo nnslashdot-request-group (group &optional server dont-check) (nnslashdot-possibly-change-server nil server) (let ((elem (assoc group nnslashdot-groups))) (cond ((not elem) (nnheader-report 'nnslashdot "Group does not exist")) (t (nnheader-report 'nnslashdot "Opened group %s" group) (nnheader-insert "211 %d %d %d %s\n" (cadr elem) 1 (cadr elem) (prin1-to-string group)))))) (deffoo nnslashdot-close-group (group &optional server) (nnslashdot-possibly-change-server group server) (when (gnus-buffer-live-p nnslashdot-buffer) (save-excursion (set-buffer nnslashdot-buffer) (kill-buffer nnslashdot-buffer))) t) (deffoo nnslashdot-request-article (article &optional group server buffer) (nnslashdot-possibly-change-server group server) (let (contents cid) (condition-case why (save-excursion (set-buffer nnslashdot-buffer) (let ((case-fold-search t)) (goto-char (point-min)) (when (and (stringp article) (string-match "%\\([0-9]+\\)@" article)) (setq cid (match-string 1 article)) (let ((map (nth 4 (assoc group nnslashdot-groups)))) (while map (if (equal (cdar map) cid) (setq article (caar map) map nil) (setq map (cdr map)))))) (when (numberp article) (if (= article 1) (progn (re-search-forward "Posted by") (search-forward "
") (setq contents (buffer-substring (point) (progn (re-search-forward "