*** empty log message ***
[gnus] / lisp / nnweb.el
index d5bd81a..6d7576d 100644 (file)
@@ -31,6 +31,7 @@
 (require 'nnoo)
 (require 'message)
 (require 'gnus-util)
+(require 'w3)
 (require 'w3-forms)
 (require 'url)
 
     (funcall (nnweb-definition 'map)))
   (cond
    ((not nnweb-articles)
-    (nnheader-report 'nnweb "Couldn't request search"))
+    (nnheader-report 'nnweb "No matching articles"))
    (t
     (nnheader-report 'nnweb "Opened group %s" group)
     (nnheader-insert
      "211 %d %d %d %s\n" (length nnweb-articles)
      (caar nnweb-articles) (caar (last nnweb-articles))
-      group))))
+     group))))
+
+(deffoo nnweb-close-group (group &optional server)
+  (nnweb-possibly-change-server server)
+  (when (gnus-buffer-live-p nnweb-buffer)
+    (save-excursion
+      (set-buffer nnweb-buffer)
+      (set-buffer-modified-p nil)
+      (kill-buffer nnweb-buffer)))
+  t)
 
 (deffoo nnweb-request-article (article &optional group server buffer)
   (nnweb-possibly-change-server server)
        t))))
 
 (deffoo nnweb-close-server (&optional server)
-  (when (nnweb-server-opened server)
-    (gnus-kill-buffer nnweb-buffer))
+  (when (and (nnweb-server-opened server)
+            (gnus-buffer-live-p nnweb-buffer))
+    (save-excursion
+      (set-buffer nnweb-buffer)
+      (set-buffer-modified-p nil)
+      (kill-buffer nnweb-buffer)))
   (nnoo-close-server 'nnweb server))
 
 (deffoo nnweb-request-update-info (group info &optional server)
       t)))
 
 (defun nnweb-callback (buffer callback)
-  (save-excursion
-    (set-buffer url-working-buffer)
-    (funcall (nnweb-definition 'article))
-    (nnweb-decode-entities)
-    (set-buffer buffer)
-    (goto-char (point-max))
-    (insert-buffer-substring url-working-buffer))
-  (funcall callback t)
-  (gnus-kill-buffer url-working-buffer))
+  (when (gnus-buffer-live-p url-working-buffer)
+    (save-excursion
+      (set-buffer url-working-buffer)
+      (funcall (nnweb-definition 'article))
+      (nnweb-decode-entities)
+      (set-buffer buffer)
+      (goto-char (point-max))
+      (insert-buffer-substring url-working-buffer))
+    (funcall callback t)
+    (gnus-kill-buffer url-working-buffer)))
 
 (defun nnweb-url-retrieve-asynch (url callback &rest data)
   (let ((url-request-method "GET")
        (old-asynch url-be-asynchronous)
        (url-request-data nil)
        (url-request-extra-headers nil)
-       (url-working-buffer (generate-new-buffer-name " *dejanews*")))
+       (url-working-buffer (generate-new-buffer-name " *nnweb*")))
     (setq-default url-be-asynchronous t)
     (save-excursion
       (set-buffer (get-buffer-create url-working-buffer))
 (defun nnweb-encode-www-form-urlencoded (pairs)
   "Return PAIRS encoded for forms."
   (mapconcat 
-    (function
-      (lambda (data)
-        (concat (w3-form-encode-xwfu (car data)) "="
-                (w3-form-encode-xwfu (cdr data))))) pairs "&"))
+   (function
+    (lambda (data)
+      (concat (w3-form-encode-xwfu (car data)) "="
+             (w3-form-encode-xwfu (cdr data))))) pairs "&"))
 
 (defun nnweb-fetch-form (url pairs)
   (let ((url-request-data (nnweb-encode-www-form-urlencoded pairs))
        (url-request-method 'POST)
        (url-request-extra-headers 
         '(("Content-type" . "application/x-www-form-urlencoded"))))
-    (url-insert-file-contents url)))
+    (url-insert-file-contents url)
+    (setq buffer-file-name nil))
+  t)
 
 (defun nnweb-decode-entities ()
   (goto-char (point-min))
     (when (funcall (nnweb-definition 'search) nnweb-search)
       (let ((i 0)
            (more t)
+           (case-fold-search t)
            Subject Score Date Newsgroup Author
            map url)
        (while more
          (while (re-search-forward "^ +[0-9]+\\." nil t)
            (narrow-to-region 
             (point) 
-            (if (re-search-forward "^ +[0-9]+\\." nil t)
-                (match-beginning 0)
-              (point-max)))
+            (cond ((re-search-forward "^ +[0-9]+\\." nil t)
+                   (match-beginning 0))
+                  ((search-forward "\n\n" nil t)
+                   (point))
+                  (t
+                   (point-max))))
            (goto-char (point-min))
            (when (looking-at ".*HREF=\"\\([^\"]+\\)\"")
              (setq url (match-string 1)))
          ;; See whether there is a "Get next 20 hits" button here.
          (if (or (not (re-search-forward
                        "HREF=\"\\([^\"]+\\)\">Get next" nil t))
-                 (> i nnweb-max-hits))
+                 (>= i nnweb-max-hits))
              (setq more nil)
            ;; Yup -- fetch it.
            (setq more (match-string 1))
        (setq nnweb-articles (nreverse map))))))
 
 (defun nnweb-dejanews-wash-article ()
-  (goto-char (point-min))
-  (re-search-forward "<PRE>" nil t)
-  (delete-region (point-min) (point))
-  (re-search-forward "</PRE>" nil t)
-  (delete-region (point) (point-max))
-  (nnweb-remove-markup)
-  (goto-char (point-min))
-  (while (and (looking-at " *$")
-             (not (eobp)))
-    (gnus-delete-line))
-  (while (looking-at "\\(^[^ ]+:\\) *")
-    (replace-match "\\1 " t)
-    (forward-line 1))
-  (when (re-search-forward "\n\n+" nil t)
-    (replace-match "\n" t t)))
+  (let ((case-fold-search t))
+    (goto-char (point-min))
+    (re-search-forward "<PRE>" nil t)
+    (delete-region (point-min) (point))
+    (re-search-forward "</PRE>" nil t)
+    (delete-region (point) (point-max))
+    (nnweb-remove-markup)
+    (goto-char (point-min))
+    (while (and (looking-at " *$")
+               (not (eobp)))
+      (gnus-delete-line))
+    (while (looking-at "\\(^[^ ]+:\\) *")
+      (replace-match "\\1 " t)
+      (forward-line 1))
+    (when (re-search-forward "\n\n+" nil t)
+      (replace-match "\n" t t))))
 
 (defun nnweb-dejanews-search (search)
   (nnweb-fetch-form 
      ("threaded" . "0")
      ("showsort" . "score")
      ("agesign" . "1")
-     ("ageweight" . "1"))))
+     ("ageweight" . "1")))
+  t)
 
 ;;;
 ;;; InReference
     (when (funcall (nnweb-definition 'search) nnweb-search)
       (let ((i 0)
            (more t)
+           (case-fold-search t)
            Subject Score Date Newsgroups From Message-ID
            map url)
        (while more
          (goto-char (point-min))
          (search-forward "</pre><hr>" nil t)
          (delete-region (point-min) (point))
-         ;(nnweb-decode-entities)
+                                       ;(nnweb-decode-entities)
          (goto-char (point-min))
          (while (re-search-forward "^ +[0-9]+\\." nil t)
            (narrow-to-region 
        (setq nnweb-articles (nreverse map))))))
 
 (defun nnweb-reference-wash-article ()
-  (goto-char (point-min))
-  (re-search-forward "^</center><hr>" nil t)
-  (delete-region (point-min) (point))
-  (search-forward "<pre>" nil t)
-  (forward-line -1)
-  (let ((body (point-marker)))
-    (search-forward "</pre>" nil t)
-    (delete-region (point) (point-max))
-    (nnweb-remove-markup)
+  (let ((case-fold-search t))
     (goto-char (point-min))
-    (while (looking-at " *$")
-      (gnus-delete-line))
-    (narrow-to-region (point-min) body)
-    (while (and (re-search-forward "^$" nil t)
-               (not (eobp)))
-      (gnus-delete-line))
-    (goto-char (point-min))
-    (while (looking-at "\\(^[^ ]+:\\) *")
-      (replace-match "\\1 " t)
-      (forward-line 1))
-    (goto-char (point-min))
-    (when (re-search-forward "^References:" nil t)
-      (narrow-to-region
-       (point) (if (re-search-forward "^$\\|^[^:]+:" nil t)
-                  (match-beginning 0)
-                (point-max)))
+    (re-search-forward "^</center><hr>" nil t)
+    (delete-region (point-min) (point))
+    (search-forward "<pre>" nil t)
+    (forward-line -1)
+    (let ((body (point-marker)))
+      (search-forward "</pre>" nil t)
+      (delete-region (point) (point-max))
+      (nnweb-remove-markup)
+      (goto-char (point-min))
+      (while (looking-at " *$")
+       (gnus-delete-line))
+      (narrow-to-region (point-min) body)
+      (while (and (re-search-forward "^$" nil t)
+                 (not (eobp)))
+       (gnus-delete-line))
       (goto-char (point-min))
-      (while (not (eobp))
-       (unless (looking-at "References")
-         (insert "\t")
-         (forward-line 1)))
+      (while (looking-at "\\(^[^ ]+:\\) *")
+       (replace-match "\\1 " t)
+       (forward-line 1))
       (goto-char (point-min))
-      (while (search-forward "," nil t)
-       (replace-match " " t t)))
-    (widen)
-    (set-marker body nil)))
+      (when (re-search-forward "^References:" nil t)
+       (narrow-to-region
+        (point) (if (re-search-forward "^$\\|^[^:]+:" nil t)
+                    (match-beginning 0)
+                  (point-max)))
+       (goto-char (point-min))
+       (while (not (eobp))
+         (unless (looking-at "References")
+           (insert "\t")
+           (forward-line 1)))
+       (goto-char (point-min))
+       (while (search-forward "," nil t)
+         (replace-match " " t t)))
+      (widen)
+      (set-marker body nil))))
 
 (defun nnweb-reference-search (search)
-  (url-insert-file-contents
-   (concat 
-    (nnweb-definition 'address)
-    "?"
-    (nnweb-encode-www-form-urlencoded 
-     `(("search" . "advanced")
-       ("querytext" . ,search)
-       ("subj" . "")
-       ("name" . "")
-       ("login" . "")
-       ("host" . "")
-       ("organization" . "")
-       ("groups" . "")
-       ("keywords" . "")
-       ("choice" . "Search")
-       ("startmonth" . "Jul")
-       ("startday" . "25")
-       ("startyear" . "1996")
-       ("endmonth" . "Aug")
-       ("endday" . "24")
-       ("endyear" . "1996")
-       ("mode" . "Quick")
-       ("verbosity" . "Verbose")
-       ("ranking" . "Relevance")
-       ("first" . "1")
-       ("last" . "25")
-       ("score" . "50"))))))
+  (prog1
+      (url-insert-file-contents
+       (concat 
+       (nnweb-definition 'address)
+       "?"
+       (nnweb-encode-www-form-urlencoded 
+        `(("search" . "advanced")
+          ("querytext" . ,search)
+          ("subj" . "")
+          ("name" . "")
+          ("login" . "")
+          ("host" . "")
+          ("organization" . "")
+          ("groups" . "")
+          ("keywords" . "")
+          ("choice" . "Search")
+          ("startmonth" . "Jul")
+          ("startday" . "25")
+          ("startyear" . "1996")
+          ("endmonth" . "Aug")
+          ("endday" . "24")
+          ("endyear" . "1996")
+          ("mode" . "Quick")
+          ("verbosity" . "Verbose")
+          ("ranking" . "Relevance")
+          ("first" . "1")
+          ("last" . "25")
+          ("score" . "50")))))
+    (setq buffer-file-name nil))
+  t)
 
 ;;;
 ;;; Alta Vista
   (save-excursion
     (set-buffer nnweb-buffer)
     (erase-buffer)
-    (when (funcall (nnweb-definition 'search) nnweb-search)
-      (let ((i 0)
-           (more t)
-           Subject Score Date Newsgroups From Message-ID
-           map url)
-       (while more
-         ;; Go through all the article hits on this page.
-         (goto-char (point-min))
-         (search-forward "<dt>" nil t)
-         (delete-region (point-min) (match-beginning 0))
-         (goto-char (point-min))
-         (while (search-forward "<dt>" nil t)
-           (replace-match "\n<blubb>"))
-         (nnweb-decode-entities)
-         (goto-char (point-min))
-         (while (re-search-forward "<blubb>.*href=\"\\([^\"]+\\)\"><strong>\\([^>]*\\)</strong></a><dd>\\([^-]+\\)- <b>\\([^<]+\\)<.*href=\"news:\\([^\"]+\\)\">.*\">\\(.+\\)</a><P>"
-                                   nil t)
-           (setq url (match-string 1)
-                 subject (match-string 2)
-                 date (match-string 3)
-                 group (match-string 4)
-                 id (concat "<" (match-string 5) ">")
-                 from (match-string 6))
-           (push
-            (list
-             (incf i)
-             (make-full-mail-header
-              i (concat  "(" group ") " subject) from date
-              id nil 0 0 nil)
-             url)
-            map))
-         (setq more nil))
-       ;; Return the articles in the right order.
-       (setq nnweb-articles (nreverse map))))))
+    (let ((part 0))
+      (when (funcall (nnweb-definition 'search) nnweb-search part)
+       (let ((i 0)
+             (more t)
+             (case-fold-search t)
+             subject date from id group
+             map url)
+         (while more
+           ;; Go through all the article hits on this page.
+           (goto-char (point-min))
+           (search-forward "<dt>" nil t)
+           (delete-region (point-min) (match-beginning 0))
+           (goto-char (point-min))
+           (while (search-forward "<dt>" nil t)
+             (replace-match "\n<blubb>"))
+           (nnweb-decode-entities)
+           (goto-char (point-min))
+           (while (re-search-forward "<blubb>.*href=\"\\([^\"]+\\)\"><strong>\\([^>]*\\)</strong></a><dd>\\([^-]+\\)- <b>\\([^<]+\\)<.*href=\"news:\\([^\"]+\\)\">.*\">\\(.+\\)</a><P>"
+                                     nil t)
+             (setq url (match-string 1)
+                   subject (match-string 2)
+                   date (match-string 3)
+                   group (match-string 4)
+                   id (concat "<" (match-string 5) ">")
+                   from (match-string 6))
+             (push
+              (list
+               (incf i)
+               (make-full-mail-header
+                i (concat  "(" group ") " subject) from date
+                id nil 0 0 nil)
+               url)
+              map))
+           ;; See if we want more.
+           (when (or (not nnweb-articles)
+                     (>= i nnweb-max-hits)
+                     (not (funcall (nnweb-definition 'search)
+                                   nnweb-search (incf part))))
+             (setq more nil)))
+         ;; Return the articles in the right order.
+         (setq nnweb-articles (nreverse map)))))))
 
 (defun nnweb-altavista-wash-article ()
   (goto-char (point-min))
-  (let (subject)
+  (let ((case-fold-search t))
     (when (re-search-forward "<H1>\\(.*\\)</H1>" nil t)
       (setq subject (match-string 1)))
     (re-search-forward "^<strong>" nil t)
       (widen)
       (nnweb-remove-markup))))
 
-(defun nnweb-altavista-search (search)
-  (url-insert-file-contents
-   (concat 
-    (nnweb-definition 'address)
-    "?"
-    (nnweb-encode-www-form-urlencoded 
-     `(("pg" . "aq")
-       ("what" . "news")
-       ("fmt" . "d")
-       ("q" . ,search)
-       ("r" . "")
-       ("d0" . "")
-       ("d1" . ""))))))
+(defun nnweb-altavista-search (search &optional part)
+  (prog1
+      (url-insert-file-contents
+       (concat 
+       (nnweb-definition 'address)
+       "?"
+       (nnweb-encode-www-form-urlencoded 
+        `(("pg" . "aq")
+          ("what" . "news")
+          ,@(if part `(("stq" . ,(int-to-string (* part 30)))))
+          ("fmt" . "d")
+          ("q" . ,search)
+          ("r" . "")
+          ("d0" . "")
+          ("d1" . "")))))
+    (setq buffer-file-name nil)))
 
 (provide 'nnweb)