;;; nnwarchive.el --- interfacing with web archives
-;; Copyright (C) 1999 Free Software Foundation, Inc.
+;; Copyright (C) 1999-2000 Free Software Foundation, Inc.
;; Author: Shenghuo Zhu <zsh@cs.rochester.edu>
-;; Keywords: news
+;; Keywords: news egroups mail-archive
;; This file is part of GNU Emacs.
;;; Commentary:
-;; Note: You need to have `url' and `w3' 0.46 or greater version
+;; Note: You need to have `url' (w3 0.46) or greater version
;; installed for this backend to work.
-;; A lot of codes stolen from mail-source, nnslashdot, nnweb.
-
;; Todo:
;; 1. To support more web archives.
-;; 2. Support nnwarchive-xover-is-evil.
-;; 3. Generalize webmail to other MHonArc archive.
+;; 2. Generalize webmail to other MHonArc archive.
;;; Code:
(require 'message)
(require 'gnus-util)
(require 'gnus)
+(require 'gnus-bcklg)
(require 'nnmail)
(require 'mm-util)
(require 'mail-source)
'((egroups
(address . "www.egroups.com")
(open-url
- "http://www.egroups.com/register?method=loginAction&email=%s&password=%s"
+ "http://www.egroups.com/login.cgi?&login_email=%s&login_password=%s"
nnwarchive-login nnwarchive-passwd)
(list-url
- "http://www.egroups.com/UserGroupsPage?")
+ "http://www.egroups.com/mygroups")
(list-dissect . nnwarchive-egroups-list)
(list-groups . nnwarchive-egroups-list-groups)
(xover-url
- "http://www.egroups.com/group/%s/?fetchForward=1&start=%d" group aux)
+ "http://www.egroups.com/message/%s/%d" group aux)
(xover-last-url
- "http://www.egroups.com/group/%s/?fetchForward=1" group)
+ "http://www.egroups.com/message/%s/" group)
(xover-page-size . 13)
(xover-dissect . nnwarchive-egroups-xover)
(article-url
- "http://www.egroups.com/group/%s/%d.html?raw=1" group article)
+ "http://www.egroups.com/message/%s/%d?source=1" group article)
(article-dissect . nnwarchive-egroups-article)
(authentication . t)
+ (article-offset . 0)
(xover-files . nnwarchive-egroups-xover-files))
(mail-archive
(address . "www.mail-archive.com")
+ (open-url)
(list-url
"http://www.mail-archive.com/lists.html")
(list-dissect . nnwarchive-mail-archive-list)
"http://www.mail-archive.com/%s/mail%d.html" group aux)
(xover-last-url
"http://www.mail-archive.com/%s/maillist.html" group)
+ (xover-page-size)
(xover-dissect . nnwarchive-mail-archive-xover)
(article-url
"http://www.mail-archive.com/%s/msg%05d.html" group article1)
(article-dissect . nnwarchive-mail-archive-article)
(xover-files . nnwarchive-mail-archive-xover-files)
+ (authentication)
(article-offset . 1))))
(defvar nnwarchive-default-type 'egroups)
(defvoo nnwarchive-headers-cache nil)
-(defvoo nnwarchive-opened nil)
-
(defvoo nnwarchive-authentication nil)
-(defvoo nnwarchive-xover-is-evil nil) ;; not implemented
+(defvoo nnwarchive-nov-is-evil nil)
(defconst nnwarchive-version "nnwarchive 1.0")
(defvoo nnwarchive-buffer nil)
-(defvar nnwarchive-headers nil)
+(defvoo nnwarchive-keep-backlog 300)
+(defvar nnwarchive-backlog-articles nil)
+(defvar nnwarchive-backlog-hashtb nil)
+
+(defvoo nnwarchive-headers nil)
;;; Interface functions
(set (intern (concat "nnwarchive-" (symbol-name (car def))))
(cdr def)))))
+(defmacro nnwarchive-backlog (&rest form)
+ `(let ((gnus-keep-backlog nnwarchive-keep-backlog)
+ (gnus-backlog-buffer
+ (format " *nnwarchive backlog %s*" nnwarchive-address))
+ (gnus-backlog-articles nnwarchive-backlog-articles)
+ (gnus-backlog-hashtb nnwarchive-backlog-hashtb))
+ (unwind-protect
+ (progn ,@form)
+ (setq nnwarchive-backlog-articles gnus-backlog-articles
+ nnwarchive-backlog-hashtb gnus-backlog-hashtb))))
+(put 'nnwarchive-backlog 'lisp-indent-function 0)
+(put 'nnwarchive-backlog 'edebug-form-spec '(form body))
+
+(defun nnwarchive-backlog-enter-article (group number buffer)
+ (nnwarchive-backlog
+ (gnus-backlog-enter-article group number buffer)))
+
+(defun nnwarchive-get-article (article &optional group server buffer)
+ (if (numberp article)
+ (if (nnwarchive-backlog
+ (gnus-backlog-request-article group article
+ (or buffer nntp-server-buffer)))
+ (cons group article)
+ (let (contents)
+ (save-excursion
+ (set-buffer nnwarchive-buffer)
+ (goto-char (point-min))
+ (let ((article1 (- article nnwarchive-article-offset)))
+ (nnwarchive-url nnwarchive-article-url))
+ (setq contents (funcall nnwarchive-article-dissect group article)))
+ (when contents
+ (save-excursion
+ (set-buffer (or buffer nntp-server-buffer))
+ (erase-buffer)
+ (insert contents)
+ (nnwarchive-backlog-enter-article group article (current-buffer))
+ (nnheader-report 'nnwarchive "Fetched article %s" article)
+ (cons group article)))))
+ nil))
+
(deffoo nnwarchive-retrieve-headers (articles &optional group server fetch-old)
(nnwarchive-possibly-change-server group server)
- (setq nnwarchive-headers (cdr (assoc group nnwarchive-headers-cache)))
- (save-excursion
- (set-buffer nnwarchive-buffer)
- (erase-buffer)
- (funcall nnwarchive-xover-files group articles))
- (save-excursion
- (set-buffer nntp-server-buffer)
- (erase-buffer)
- (let (header)
+ (if (or gnus-nov-is-evil nnwarchive-nov-is-evil)
+ (with-temp-buffer
+ (with-current-buffer nntp-server-buffer
+ (erase-buffer))
+ (let ((buf (current-buffer)) b e)
+ (dolist (art articles)
+ (nnwarchive-get-article art group server buf)
+ (setq b (goto-char (point-min)))
+ (if (search-forward "\n\n" nil t)
+ (forward-char -1)
+ (goto-char (point-max)))
+ (setq e (point))
+ (with-current-buffer nntp-server-buffer
+ (insert (format "221 %d Article retrieved.\n" art))
+ (insert-buffer-substring buf b e)
+ (insert ".\n"))))
+ 'headers)
+ (setq nnwarchive-headers (cdr (assoc group nnwarchive-headers-cache)))
+ (save-excursion
+ (set-buffer nnwarchive-buffer)
+ (erase-buffer)
+ (funcall nnwarchive-xover-files group articles))
+ (save-excursion
+ (set-buffer nntp-server-buffer)
+ (erase-buffer)
+ (let (header)
(dolist (art articles)
(if (setq header (assq art nnwarchive-headers))
(nnheader-insert-nov (cdr header))))))
- (let ((elem (assoc group nnwarchive-headers-cache)))
- (if elem
- (setcdr elem nnwarchive-headers)
- (push (cons group nnwarchive-headers) nnwarchive-headers-cache)))
- 'nov)
-
-(deffoo nnwarchive-retrieve-groups (groups &optional server)
- "Retrieve group info on GROUPS."
- (nnwarchive-possibly-change-server nil server)
- (if nnwarchive-list-groups
- (funcall nnwarchive-list-groups groups))
- (nnwarchive-write-groups)
- (nnwarchive-generate-active)
- 'active)
+ (let ((elem (assoc group nnwarchive-headers-cache)))
+ (if elem
+ (setcdr elem nnwarchive-headers)
+ (push (cons group nnwarchive-headers) nnwarchive-headers-cache)))
+ 'nov))
(deffoo nnwarchive-request-group (group &optional server dont-check)
(nnwarchive-possibly-change-server nil server)
- (if nnwarchive-list-groups
- (funcall nnwarchive-list-groups (list group)))
- (nnwarchive-write-groups)
+ (when (and (not dont-check) nnwarchive-list-groups)
+ (funcall nnwarchive-list-groups (list group))
+ (nnwarchive-write-groups))
(let ((elem (assoc group nnwarchive-groups)))
(cond
((not elem)
(prin1-to-string group))
t))))
-(deffoo nnwarchive-close-group (group &optional server)
- (nnwarchive-possibly-change-server group server)
- (when (gnus-buffer-live-p nnwarchive-buffer)
- (save-excursion
- (set-buffer nnwarchive-buffer)
- (kill-buffer nnwarchive-buffer)))
- t)
-
(deffoo nnwarchive-request-article (article &optional group server buffer)
(nnwarchive-possibly-change-server group server)
- (let (contents)
- (save-excursion
- (set-buffer nnwarchive-buffer)
- (goto-char (point-min))
- (let ((article1 (- article nnwarchive-article-offset)))
- (nnwarchive-url nnwarchive-article-url))
- (setq contents (funcall nnwarchive-article-dissect group article)))
- (when contents
- (save-excursion
- (set-buffer (or buffer nntp-server-buffer))
- (erase-buffer)
- (insert contents)
- (nnheader-report 'nnwarchive "Fetched article %s" article)
- (cons group article)))))
+ (nnwarchive-get-article article group server buffer))
(deffoo nnwarchive-close-server (&optional server)
(when (and (nnwarchive-server-opened server)
(save-excursion
(set-buffer nnwarchive-buffer)
(kill-buffer nnwarchive-buffer)))
+ (nnwarchive-backlog
+ (gnus-backlog-shutdown))
(nnoo-close-server 'nnwarchive server))
(deffoo nnwarchive-request-list (&optional server)
(funcall nnwarchive-list-dissect))
(nnwarchive-write-groups)
(nnwarchive-generate-active))
- 'active)
-
-(deffoo nnwarchive-request-newgroups (date &optional server)
- (nnwarchive-possibly-change-server nil server)
- (nnwarchive-write-groups)
- (nnwarchive-generate-active)
- 'active)
-
-(deffoo nnwarchive-asynchronous-p ()
- nil)
-
-(deffoo nnwarchive-server-opened (&optional server)
- nnwarchive-opened)
+ t)
(deffoo nnwarchive-open-server (server &optional defs connectionless)
+ (nnoo-change-server 'nnwarchive server defs)
(nnwarchive-init server)
- (unless (nnwarchive-server-opened server)
- (when nnwarchive-authentication
- (setq nnwarchive-login
- (or nnwarchive-login
- (read-string
+ (when nnwarchive-authentication
+ (setq nnwarchive-login
+ (or nnwarchive-login
+ (read-string
(format "Login at %s: " server)
user-mail-address)))
- (setq nnwarchive-passwd
- (or nnwarchive-passwd
- (mail-source-read-passwd
- (format "Password for %s at %s: "
- nnwarchive-login server)))))
- (unless nnwarchive-groups
- (nnwarchive-read-groups))
- (save-excursion
- (set-buffer nnwarchive-buffer)
- (erase-buffer)
- (if nnwarchive-open-url
- (nnwarchive-url nnwarchive-open-url))
- (if nnwarchive-open-dissect
- (funcall nnwarchive-open-dissect))
- (setq nnwarchive-opened t)))
+ (setq nnwarchive-passwd
+ (or nnwarchive-passwd
+ (mail-source-read-passwd
+ (format "Password for %s at %s: "
+ nnwarchive-login server)))))
+ (unless nnwarchive-groups
+ (nnwarchive-read-groups))
+ (save-excursion
+ (set-buffer nnwarchive-buffer)
+ (erase-buffer)
+ (if nnwarchive-open-url
+ (nnwarchive-url nnwarchive-open-url))
+ (if nnwarchive-open-dissect
+ (funcall nnwarchive-open-dissect)))
t)
(nnoo-define-skeleton nnwarchive)
expr)))
(defun nnwarchive-url (xurl)
- (let ((url-confirmation-func 'identity))
- (cond
- ((eq (car xurl) 'post)
- (pop xurl)
- (nnwarchive-fetch-form (car xurl) (nnwarchive-eval (cdr xurl))))
- (t
- (nnweb-insert (apply 'format (nnwarchive-eval xurl)))))))
-
-(defun nnwarchive-decode-entities ()
- (goto-char (point-min))
- (while (re-search-forward "&\\(#[0-9]+\\|[a-z]+\\);" nil t)
- (replace-match (char-to-string
- (if (eq (aref (match-string 1) 0) ?\#)
- (string-to-number (substring (match-string 1) 1))
- (or (cdr (assq (intern (match-string 1))
- w3-html-entities))
- ?#)))
- t t)))
-
-(defun nnwarchive-decode-entities-string (str)
- (with-temp-buffer
- (insert str)
- (nnwarchive-decode-entities)
- (buffer-substring (point-min) (point-max))))
-
-(defun nnwarchive-remove-markup ()
- (goto-char (point-min))
- (while (search-forward "<!--" nil t)
- (delete-region (match-beginning 0)
- (or (search-forward "-->" nil t)
- (point-max))))
- (goto-char (point-min))
- (while (re-search-forward "<[^>]+>" nil t)
- (replace-match "" t t)))
-
-(defun nnwarchive-date-to-date (sdate)
- (let ((elem (split-string sdate)))
- (concat (substring (nth 0 elem) 0 3) " "
- (substring (nth 1 elem) 0 3) " "
- (substring (nth 2 elem) 0 2) " "
- (substring (nth 3 elem) 1 6) " "
- (format-time-string "%Y") " "
- (nth 4 elem))))
-
+ (mm-with-unibyte-current-buffer
+ (let ((url-confirmation-func 'identity)
+ (url-cookie-multiple-line nil))
+ (cond
+ ((eq (car xurl) 'post)
+ (pop xurl)
+ (nnwarchive-fetch-form (car xurl) (nnwarchive-eval (cdr xurl))))
+ (t
+ (nnweb-insert (apply 'format (nnwarchive-eval xurl))))))))
+
(defun nnwarchive-generate-active ()
(save-excursion
(set-buffer nntp-server-buffer)
(erase-buffer)
(nnwarchive-url nnwarchive-xover-last-url)
(goto-char (point-min))
- (when (re-search-forward "of \\([0-9]+\\)</title>" nil t)
+ (when (re-search-forward "of \\([0-9]+\\)[ \t\n\r]*</title>" nil t)
(setq articles (string-to-number (match-string 1))))
(let ((elem (assoc group nnwarchive-groups)))
(if elem
group description elem articles)
(goto-char (point-min))
(while
- (re-search-forward
- "/group/\\([^/]+\\)/info\\.html[^>]+>[^>]+>[\040\t]*-[\040\t]*\\([^<]+\\)<"
- nil t)
+ (re-search-forward "href=\"/group/\\([^/\"\> ]+\\)" nil t)
(setq group (match-string 1)
description (match-string 2))
- (forward-line 1)
- (when (re-search-forward ">\\([0-9]+\\)<" nil t)
- (setq articles (string-to-number (match-string 1))))
(if (setq elem (assoc group nnwarchive-groups))
- (setcar (cdr elem) articles)
+ (setcar (cdr elem) 0)
(push (list group articles description) nnwarchive-groups))))
t)
(let (article subject from date)
(goto-char (point-min))
(while (re-search-forward
- "<a href=\"/group/\\([^/]+\\)/\\([0-9]+\\)\\.html[^>]+>\\([^<]+\\)<"
+ "<a href=\"/group/\\([^/]+\\)/\\([0-9]+\\)[^>]+>\\([^<]+\\)<"
nil t)
(setq group (match-string 1)
article (string-to-number (match-string 2))
article
(make-full-mail-header
article
- (nnwarchive-decode-entities-string subject)
- (nnwarchive-decode-entities-string from)
+ (nnweb-decode-entities-string subject)
+ (nnweb-decode-entities-string from)
date
(concat "<" group "%"
(number-to-string article)
(goto-char (point-min))
(while (re-search-forward "<a[^>]+>\\([^<]+\\)</a>" nil t)
(replace-match "<\\1>"))
- (nnwarchive-decode-entities)
+ (nnweb-decode-entities)
(buffer-string))
(defun nnwarchive-egroups-xover-files (group articles)
article
(make-full-mail-header
article
- (nnwarchive-decode-entities-string subject)
- (nnwarchive-decode-entities-string from)
+ (nnweb-decode-entities-string subject)
+ (nnweb-decode-entities-string from)
date
(format "<%05d%%%s>\n" (1- article) group)
""
(when (search-forward "X-Head-End" nil t)
(beginning-of-line)
(narrow-to-region (point-min) (point))
- (nnwarchive-decode-entities)
+ (nnweb-decode-entities)
(goto-char (point-min))
(while (search-forward "<!--X-" nil t)
(replace-match ""))
(search-forward "</ul>" nil t)
(end-of-line)
(narrow-to-region (point-min) (point))
- (nnwarchive-remove-markup)
- (nnwarchive-decode-entities)
+ (nnweb-remove-markup)
+ (nnweb-decode-entities)
(goto-char (point-min))
(delete-blank-lines)
(when from
(delete-region (match-beginning 0) (match-end 0))
(save-restriction
(narrow-to-region p (point))
- (nnwarchive-remove-markup)
- (nnwarchive-decode-entities)
+ (nnweb-remove-markup)
+ (nnweb-decode-entities)
(goto-char (point-max)))))
((looking-at "<P><A HREF=\"\\([^\"]+\\)")
(setq url (match-string 1))