X-Git-Url: http://cgit.sxemacs.org/?a=blobdiff_plain;f=lisp%2Fnnweb.el;h=6d7576de4ee53de02f0d222ad96eda00e96d1ebe;hb=81901d17becb84f18612bd2ab9b539ee48a2250e;hp=d5bd81a872786b874628400d8571e021ebb14919;hpb=1a96d7bf660263f25557962103bc0ec2495d1d07;p=gnus diff --git a/lisp/nnweb.el b/lisp/nnweb.el index d5bd81a87..6d7576de4 100644 --- a/lisp/nnweb.el +++ b/lisp/nnweb.el @@ -31,6 +31,7 @@ (require 'nnoo) (require 'message) (require 'gnus-util) +(require 'w3) (require 'w3-forms) (require 'url) @@ -91,13 +92,22 @@ (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) @@ -122,8 +132,12 @@ 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) @@ -173,22 +187,23 @@ 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)) @@ -201,17 +216,19 @@ (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)) @@ -243,6 +260,7 @@ (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 @@ -253,9 +271,12 @@ (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))) @@ -282,7 +303,7 @@ ;; 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)) @@ -292,21 +313,22 @@ (setq nnweb-articles (nreverse map)))))) (defun nnweb-dejanews-wash-article () - (goto-char (point-min)) - (re-search-forward "
" nil t)
-  (delete-region (point-min) (point))
-  (re-search-forward "
" 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 "
" nil t)
+    (delete-region (point-min) (point))
+    (re-search-forward "
" 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 @@ -319,7 +341,8 @@ ("threaded" . "0") ("showsort" . "score") ("agesign" . "1") - ("ageweight" . "1")))) + ("ageweight" . "1"))) + t) ;;; ;;; InReference @@ -333,6 +356,7 @@ (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 @@ -340,7 +364,7 @@ (goto-char (point-min)) (search-forward "
" 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 @@ -374,71 +398,75 @@ (setq nnweb-articles (nreverse map)))))) (defun nnweb-reference-wash-article () - (goto-char (point-min)) - (re-search-forward "^
" nil t) - (delete-region (point-min) (point)) - (search-forward "
" nil t)
-  (forward-line -1)
-  (let ((body (point-marker)))
-    (search-forward "
" 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 "^
" nil t) + (delete-region (point-min) (point)) + (search-forward "
" nil t)
+    (forward-line -1)
+    (let ((body (point-marker)))
+      (search-forward "
" 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 @@ -449,44 +477,51 @@ (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 "
" nil t) - (delete-region (point-min) (match-beginning 0)) - (goto-char (point-min)) - (while (search-forward "
" nil t) - (replace-match "\n")) - (nnweb-decode-entities) - (goto-char (point-min)) - (while (re-search-forward ".*href=\"\\([^\"]+\\)\">\\([^>]*\\)
\\([^-]+\\)- \\([^<]+\\)<.*href=\"news:\\([^\"]+\\)\">.*\">\\(.+\\)

" - 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 "

" nil t) + (delete-region (point-min) (match-beginning 0)) + (goto-char (point-min)) + (while (search-forward "
" nil t) + (replace-match "\n")) + (nnweb-decode-entities) + (goto-char (point-min)) + (while (re-search-forward ".*href=\"\\([^\"]+\\)\">\\([^>]*\\)
\\([^-]+\\)- \\([^<]+\\)<.*href=\"news:\\([^\"]+\\)\">.*\">\\(.+\\)

" + 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 "

\\(.*\\)

" nil t) (setq subject (match-string 1))) (re-search-forward "^" nil t) @@ -503,19 +538,22 @@ (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)