2001-12-07 09:00:00 ShengHuo ZHU <zsh@cs.rochester.edu>
authorShengHuo ZHU <zsh@cs.rochester.edu>
Fri, 7 Dec 2001 14:41:45 +0000 (14:41 +0000)
committerShengHuo ZHU <zsh@cs.rochester.edu>
Fri, 7 Dec 2001 14:41:45 +0000 (14:41 +0000)
* nnrss.el (nnrss-decode-entities-unibyte-string): Use
mm-url-decode-entities-nbsp.

* nnlistserv.el, nnultimate.el, nnwarchive.el, nnweb.el,
webmail.el, nnwfm.el: Use mm-url.

* mm-url.el (mm-url-fetch-form): Move from nnweb.
(mm-url-remove-markup): Move from nnweb.
(mm-url-fetch-simple): Move from webmail.

* nnslashdot.el (nnslashdot-request-post): mm-url-fetch-form.

lisp/ChangeLog
lisp/dgnushack.el
lisp/mm-url.el
lisp/nnlistserv.el
lisp/nnrss.el
lisp/nnslashdot.el
lisp/nnultimate.el
lisp/nnwarchive.el
lisp/nnweb.el
lisp/nnwfm.el
lisp/webmail.el

index e930ac7..941006a 100644 (file)
@@ -1,3 +1,17 @@
+2001-12-07 09:00:00  ShengHuo ZHU  <zsh@cs.rochester.edu>
+
+       * nnrss.el (nnrss-decode-entities-unibyte-string): Use
+       mm-url-decode-entities-nbsp.
+
+       * nnlistserv.el, nnultimate.el, nnwarchive.el, nnweb.el,
+       webmail.el, nnwfm.el: Use mm-url.
+
+       * mm-url.el (mm-url-fetch-form): Move from nnweb.
+       (mm-url-remove-markup): Move from nnweb.
+       (mm-url-fetch-simple): Move from webmail.
+
+       * nnslashdot.el (nnslashdot-request-post): mm-url-fetch-form.
+
 2001-12-07 01:00:00  ShengHuo ZHU  <zsh@cs.rochester.edu>
 
        * gnus-sum.el (gnus-summary-print-truncate-and-quote): New.
index 8efb21c..9936fb0 100644 (file)
@@ -234,9 +234,8 @@ Modify to suit your needs."))
     (condition-case code
        (require 'w3-forms)
       (error
-       (message "No w3: %s %s" code (locate-library "w3-forms"))
-       (dolist (file '("nnweb.el" "nnlistserv.el" "nnultimate.el"
-                      "nnwarchive.el" "webmail.el" "nnwfm.el"))
+       (message "No w3: %s %s" code (locate-library "w3-parse"))
+       (dolist (file '("nnultimate.el" "webmail.el" "nnwfm.el"))
         (setq files (delete file files)))))
     (condition-case code
        (require 'mh-e)
index e48d0d4..37066f3 100644 (file)
@@ -251,7 +251,11 @@ This is taken from RFC 2396.")
       (if (string-match "^file:/+" url)
          (insert-file-contents (substring url (1- (match-end 0))))
        (mm-url-insert-file-contents-external url))
-    (url-insert-file-contents url)))
+    (require 'url-handlers)
+    (let ((name buffer-file-name))
+      (prog1
+         (url-insert-file-contents url)
+       (setq buffer-file-name name)))))
 
 (defun mm-url-insert-file-contents-external (url)
   (let (program args)
@@ -266,19 +270,17 @@ This is taken from RFC 2396.")
 (defun mm-url-insert (url &optional follow-refresh)
   "Insert the contents from an URL in the current buffer.
 If FOLLOW-REFRESH is non-nil, redirect refresh url in META."
-  (let ((name buffer-file-name))
-    (if follow-refresh
-       (save-restriction
-         (narrow-to-region (point) (point))
-         (mm-url-insert-file-contents url)
-         (goto-char (point-min))
-         (when (re-search-forward
-                "<meta[ \t\r\n]*http-equiv=\"Refresh\"[^>]*URL=\\([^\"]+\\)\"" nil t)
-           (let ((url (match-string 1)))
-             (delete-region (point-min) (point-max))
-             (mm-url-insert url t))))
-      (mm-url-insert-file-contents url))
-    (setq buffer-file-name name)))
+  (if follow-refresh
+      (save-restriction
+       (narrow-to-region (point) (point))
+       (mm-url-insert-file-contents url)
+       (goto-char (point-min))
+       (when (re-search-forward
+              "<meta[ \t\r\n]*http-equiv=\"Refresh\"[^>]*URL=\\([^\"]+\\)\"" nil t)
+         (let ((url (match-string 1)))
+           (delete-region (point-min) (point-max))
+           (mm-url-insert url t))))
+    (mm-url-insert-file-contents url)))
 
 (defun mm-url-decode-entities ()
   "Decode all HTML entities."
@@ -296,6 +298,11 @@ If FOLLOW-REFRESH is non-nil, redirect refresh url in META."
        (setq elem (char-to-string elem)))
       (replace-match elem t t))))
 
+(defun mm-url-decode-entities-nbsp ()
+  "Decode all HTML entities and &nbsp; to a space."
+  (let ((mm-url-html-entities (cons '(nbsp . 32) mm-url-html-entities)))
+    (mm-url-decode-entities)))
+
 (defun mm-url-decode-entities-string (string)
   (with-temp-buffer
     (insert string)
@@ -327,6 +334,46 @@ spaces.  Die Die Die."
      chunk)
    ""))
 
+(defun mm-url-encode-www-form-urlencoded (pairs)
+  "Return PAIRS encoded for forms."
+  (mapconcat
+   (lambda (data)
+     (concat (mm-url-form-encode-xwfu (car data)) "="
+            (mm-url-form-encode-xwfu (cdr data))))
+   pairs "&"))
+
+(defun mm-url-fetch-form (url pairs)
+  "Fetch a form from URL with PAIRS as the data using the POST method."
+  (require 'url-handlers)
+  (let ((url-request-data (mm-url-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)
+    (setq buffer-file-name nil))
+  t)
+
+(defun mm-url-fetch-simple (url content)
+  (require 'url-handlers)
+  (let ((url-request-data content)
+       (url-request-method "POST")
+       (url-request-extra-headers
+        '(("Content-type" . "application/x-www-form-urlencoded"))))
+    (url-insert-file-contents url)
+    (setq buffer-file-name nil))
+  t)
+
+(defun mm-url-remove-markup ()
+  "Remove all HTML markup, leaving just plain text."
+  (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)))
+
 (provide 'mm-url)
 
 ;;; mm-url.el ends here
index 666cd70..3098bf0 100644 (file)
 
 ;;; Commentary:
 
-;; Note: You need to have `url' and `w3' installed for this
-;; backend to work.
-
 ;;; Code:
 
 (eval-when-compile (require 'cl))
 
 (require 'nnoo)
-(eval-when-compile
-  (ignore-errors
-   (require 'nnweb))                   ; requires W3
-  (autoload 'url-insert-file-contents "nnweb"))
+(require 'mm-url)
+(require 'nnweb)
 
 (nnoo-declare nnlistserv
   nnweb)
@@ -98,7 +93,7 @@
        (when (funcall (nnweb-definition 'search) page)
          ;; Go through all the article hits on this page.
          (goto-char (point-min))
-         (nnweb-decode-entities)
+         (mm-url-decode-entities)
          (goto-char (point-min))
          (while (re-search-forward "^<li> *<a href=\"\\([^\"]+\\)\"><b>\\([^\\>]+\\)</b></a> *<[^>]+><i>\\([^>]+\\)<" nil t)
            (setq url (match-string 1)
   (let ((case-fold-search t)
        (headers '(sent name email subject id))
        sent name email subject id)
-    (nnweb-decode-entities)
+    (mm-url-decode-entities)
     (while headers
       (goto-char (point-min))
       (re-search-forward (format "<!-- %s=\"\\([^\"]+\\)" (car headers) nil t))
     (goto-char (point-max))
     (search-backward "<!-- body" nil t)
     (delete-region (point-max) (progn (beginning-of-line) (point)))
-    (nnweb-remove-markup)
+    (mm-url-remove-markup)
     (goto-char (point-min))
     (insert (format "From: %s <%s>\n" name email)
            (format "Subject: %s\n" subject)
            (format "Date: %s\n\n" sent))))
 
 (defun nnlistserv-kk-search (search)
-  (url-insert-file-contents
+  (mm-url-insert
    (concat (format (nnweb-definition 'address) search)
           (nnweb-definition 'index)))
   t)
index 367cfce..0eddab6 100644 (file)
@@ -449,7 +449,7 @@ To use the description in headers, put this name into `nnmail-extra-headers'.")
 (defun nnrss-decode-entities-unibyte-string (string)
   (mm-with-unibyte-buffer
     (insert string)
-    (mm-url-decode-entities)
+    (mm-url-decode-entities-nbsp)
     (buffer-substring (point-min) (point-max))))
 
 (defalias 'nnrss-insert 'nnrss-insert-w3)
@@ -461,8 +461,7 @@ To use the description in headers, put this name into `nnmail-extra-headers'.")
 ;;; Snarf functions
 
 (defun nnrss-check-group (group server)
-  (let ((mm-url-html-entities (cons '(nbsp . 32) mm-url-html-entities))
-       file xml subject url extra changed author date)
+  (let (file xml subject url extra changed author date)
     (condition-case err
        (mm-with-unibyte-buffer
          (if (and nnrss-use-local
index 910b38e..f3a6f6f 100644 (file)
   t)
 
 (deffoo nnslashdot-request-post (&optional server)
-  (require 'nnweb)
   (nnslashdot-possibly-change-server nil server)
   (let ((sid (nnslashdot-sid-strip (message-fetch-field "newsgroups")))
        (subject (message-fetch-field "subject"))
     (message-goto-body)
     (setq body (buffer-substring (point) (point-max)))
     (erase-buffer)
-    (nnweb-fetch-form
+    (mm-url-fetch-form
      "http://slashdot.org/comments.pl"
      `(("sid" . ,sid)
        ("pid" . ,pid)
index e0533c1..6a8aac8 100644 (file)
 (require 'gnus)
 (require 'nnmail)
 (require 'mm-util)
-(eval-when-compile
-  (ignore-errors
-    (require 'nnweb)))
-;; Report failure to find w3 at load time if appropriate.
-(eval '(require 'nnweb))
+(require 'mm-url)
+(require 'nnweb)
+(autoload 'w3-parse-buffer "w3-parse")
 
 (nnoo-declare nnultimate)
 
              (setq subject (nth 2 (assq (car elem) topics)))
              (setq href (nth 3 (assq (car elem) topics)))
              (if (= current-page 1)
-                 (nnweb-insert href)
+                 (mm-url-insert href)
                (string-match "\\.html$" href)
-               (nnweb-insert (concat (substring href 0 (match-beginning 0))
+               (mm-url-insert (concat (substring href 0 (match-beginning 0))
                                      "-" (number-to-string current-page)
                                      (match-string 0 href))))
              (goto-char (point-min))
 (deffoo nnultimate-request-list (&optional server)
   (nnultimate-possibly-change-server nil server)
   (mm-with-unibyte-buffer
-    (nnweb-insert
+    (mm-url-insert
      (if (string-match "/$" nnultimate-address)
         (concat nnultimate-address "Ultimate.cgi")
        nnultimate-address))
     (mm-with-unibyte-buffer
       (while furls
        (erase-buffer)
-       (nnweb-insert (pop furls))
+       (mm-url-insert (pop furls))
        (goto-char (point-min))
        (setq parse (w3-parse-buffer (current-buffer)))
        (setq contents
index 1abc4dd..c8f2449 100644 (file)
@@ -24,7 +24,7 @@
 ;;; Commentary:
 
 ;; Note: You need to have `url' (w3 0.46) or greater version
-;; installed for this backend to work.
+;; installed for some functions of this backend to work.
 
 ;; Todo:
 ;; 1. To support more web archives.
 (require 'nnmail)
 (require 'mm-util)
 (require 'mail-source)
-(eval-when-compile
-  (ignore-errors
-    (require 'w3)
-    (require 'url)
-    (require 'w3-forms)
-    (require 'nnweb)))
-;; Report failure to find w3 at load time if appropriate.
-(eval '(progn
-        (require 'w3)
-        (require 'url)
-        (require 'w3-forms)
-        (require 'nnweb)))
+(require 'mm-url)
 
 (nnoo-declare nnwarchive)
 
             (format " *nnwarchive %s %s*" nnwarchive-type server)))))
   (nnwarchive-set-default nnwarchive-type))
 
-(defun nnwarchive-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 "&"))
-
-(defun nnwarchive-fetch-form (url pairs)
-  (let ((url-request-data (nnwarchive-encode-www-form-urlencoded pairs))
-       (url-request-method "POST")
-       (url-request-extra-headers
-        '(("Content-type" . "application/x-www-form-urlencoded"))))
-    (nnweb-insert url))
-  t)
-
 (defun nnwarchive-eval (expr)
   (cond
    ((consp expr)
 
 (defun nnwarchive-url (xurl)
   (mm-with-unibyte-current-buffer
-    (let ((url-confirmation-func 'identity)
+    (let ((url-confirmation-func 'identity) ;; Some hacks.
          (url-cookie-multiple-line nil))
       (cond
        ((eq (car xurl) 'post)
        (pop xurl)
-       (nnwarchive-fetch-form (car xurl) (nnwarchive-eval (cdr xurl))))
+       (mm-url-fetch-form (car xurl) (nnwarchive-eval (cdr xurl))))
        (t
-       (nnweb-insert (apply 'format (nnwarchive-eval xurl))))))))
+       (mm-url-insert (apply 'format (nnwarchive-eval xurl))))))))
 
 (defun nnwarchive-generate-active ()
   (save-excursion
               article
               (make-full-mail-header
                article
-               (nnweb-decode-entities-string subject)
-               (nnweb-decode-entities-string from)
+               (mm-url-decode-entities-string subject)
+               (mm-url-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"))
-  (nnweb-decode-entities)
+  (mm-url-decode-entities)
   (buffer-string))
 
 (defun nnwarchive-egroups-xover-files (group articles)
               article
               (make-full-mail-header
                article
-               (nnweb-decode-entities-string subject)
-               (nnweb-decode-entities-string from)
+               (mm-url-decode-entities-string subject)
+               (mm-url-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))
-       (nnweb-decode-entities)
+       (mm-url-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))
-       (nnweb-remove-markup)
-       (nnweb-decode-entities)
+       (mm-url-remove-markup)
+       (mm-url-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))
-                 (nnweb-remove-markup)
-                 (nnweb-decode-entities)
+                 (mm-url-remove-markup)
+                 (mm-url-decode-entities)
                  (goto-char (point-max)))))
             ((looking-at "<P><A HREF=\"\\([^\"]+\\)")
              (setq url (match-string 1))
index 277e24e..fe32198 100644 (file)
@@ -24,8 +24,7 @@
 
 ;;; Commentary:
 
-;; Note: You need to have `url' and `w3' installed for this
-;; backend to work.
+;; Note: You need to have `w3' installed for some functions to work.
 
 ;;; Code:
 
 (require 'gnus)
 (require 'nnmail)
 (require 'mm-util)
-(eval-when-compile
-  (ignore-errors
-    (require 'w3)
-    (require 'url)
-    (require 'w3-forms)))
-
-;; Report failure to find w3 at load time if appropriate.
-(unless noninteractive
-  (eval '(progn
-          (require 'w3)
-          (require 'url)
-          (require 'w3-forms))))
+(require 'mm-url)
+(autoload 'w3-parse-buffer "w3-parse")
 
 (nnoo-declare nnweb)
 
@@ -197,7 +186,7 @@ and `altavista'.")
           (url (and header (mail-header-xref header))))
       (when (or (and url
                     (mm-with-unibyte-current-buffer
-                      (nnweb-fetch-url url)))
+                      (mm-url-insert url)))
                (and (stringp article)
                     (nnweb-definition 'id t)
                     (let ((fetch (nnweb-definition 'id))
@@ -207,7 +196,7 @@ and `altavista'.")
                       (when (and fetch art)
                         (setq url (format fetch art))
                         (mm-with-unibyte-current-buffer
-                          (nnweb-fetch-url url))
+                          (mm-url-insert url))
                         (if (nnweb-definition 'reference t)
                             (setq article
                                   (funcall (nnweb-definition
@@ -336,55 +325,55 @@ and `altavista'.")
                       nnweb-type nnweb-search server))
              (current-buffer))))))
 
-(defun nnweb-fetch-url (url)
-  (let (buf)
-    (save-excursion
-      (if (not nnheader-callback-function)
-         (progn
-           (with-temp-buffer
-             (mm-enable-multibyte)
-             (let ((coding-system-for-read 'binary)
-                   (coding-system-for-write 'binary)
-                   (default-process-coding-system 'binary))
-               (nnweb-insert url))
-             (setq buf (buffer-string)))
-           (erase-buffer)
-           (insert buf)
-           t)
-       (nnweb-url-retrieve-asynch
-        url 'nnweb-callback (current-buffer) nnheader-callback-function)
-       t))))
-
-(defun nnweb-callback (buffer callback)
-  (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 " *nnweb*")))
-    (setq-default url-be-asynchronous t)
-    (save-excursion
-      (set-buffer (get-buffer-create url-working-buffer))
-      (setq url-current-callback-data data
-           url-be-asynchronous t
-           url-current-callback-func callback)
-      (url-retrieve url nil))
-    (setq-default url-be-asynchronous old-asynch)))
-
-(if (fboundp 'url-retrieve-synchronously)
-    (defun nnweb-url-retrieve-asynch (url callback &rest data)
-      (url-retrieve url callback data)))
+;; (defun nnweb-fetch-url (url)
+;;   (let (buf)
+;;     (save-excursion
+;;       (if (not nnheader-callback-function)
+;;       (progn
+;;         (with-temp-buffer
+;;           (mm-enable-multibyte)
+;;           (let ((coding-system-for-read 'binary)
+;;                 (coding-system-for-write 'binary)
+;;                 (default-process-coding-system 'binary))
+;;             (nnweb-insert url))
+;;           (setq buf (buffer-string)))
+;;         (erase-buffer)
+;;         (insert buf)
+;;         t)
+;;     (nnweb-url-retrieve-asynch
+;;      url 'nnweb-callback (current-buffer) nnheader-callback-function)
+;;     t))))
+
+;; (defun nnweb-callback (buffer callback)
+;;   (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 " *nnweb*")))
+;;     (setq-default url-be-asynchronous t)
+;;     (save-excursion
+;;       (set-buffer (get-buffer-create url-working-buffer))
+;;       (setq url-current-callback-data data
+;;         url-be-asynchronous t
+;;         url-current-callback-func callback)
+;;       (url-retrieve url nil))
+;;     (setq-default url-be-asynchronous old-asynch)))
+
+;; (if (fboundp 'url-retrieve-synchronously)
+;;     (defun nnweb-url-retrieve-asynch (url callback &rest data)
+;;       (url-retrieve url callback data)))
 
 ;;;
 ;;; DejaNews functions.
@@ -448,17 +437,17 @@ and `altavista'.")
            ;; Yup -- fetch it.
            (setq more (match-string 1))
            (erase-buffer)
-           (url-insert-file-contents more)))
+           (mm-url-insert more)))
        ;; Return the articles in the right order.
        (setq nnweb-articles
              (sort (nconc nnweb-articles map) 'car-less-than-car))))))
 
 (defun nnweb-dejanews-search (search)
-  (nnweb-insert
+  (mm-url-insert
    (concat
     (nnweb-definition 'address)
     "?"
-    (nnweb-encode-www-form-urlencoded
+    (mm-url-encode-www-form-urlencoded
      `(("ST" . "PS")
        ("svcclass" . "dnyr")
        ("QRY" . ,search)
@@ -474,19 +463,19 @@ and `altavista'.")
        ("ageweight" . "1")))))
   t)
 
-(defun nnweb-dejanewsold-search (search)
-  (nnweb-fetch-form
-   (nnweb-definition 'address)
-   `(("query" . ,search)
-     ("defaultOp" . "AND")
-     ("svcclass" . "dnold")
-     ("maxhits" . "100")
-     ("format" . "verbose2")
-     ("threaded" . "0")
-     ("showsort" . "date")
-     ("agesign" . "1")
-     ("ageweight" . "1")))
-  t)
+;; (defun nnweb-dejanewsold-search (search)
+;;   (nnweb-fetch-form
+;;    (nnweb-definition 'address)
+;;    `(("query" . ,search)
+;;      ("defaultOp" . "AND")
+;;      ("svcclass" . "dnold")
+;;      ("maxhits" . "100")
+;;      ("format" . "verbose2")
+;;      ("threaded" . "0")
+;;      ("showsort" . "date")
+;;      ("agesign" . "1")
+;;      ("ageweight" . "1")))
+;;   t)
 
 (defun nnweb-dejanews-identity (url)
   "Return an unique identifier based on URL."
@@ -526,7 +515,7 @@ and `altavista'.")
            (goto-char (point-min))
            (when (looking-at ".*href=\"\\([^\"]+\\)\"")
              (setq url (match-string 1)))
-           (nnweb-remove-markup)
+           (mm-url-remove-markup)
            (goto-char (point-min))
            (while (search-forward "\t" nil t)
              (replace-match " "))
@@ -561,7 +550,7 @@ and `altavista'.")
     (let ((body (point-marker)))
       (search-forward "</pre>" nil t)
       (delete-region (point) (point-max))
-      (nnweb-remove-markup)
+      (mm-url-remove-markup)
       (goto-char (point-min))
       (while (looking-at " *$")
        (gnus-delete-line))
@@ -588,15 +577,15 @@ and `altavista'.")
        (while (search-forward "," nil t)
          (replace-match " " t t)))
       (widen)
-      (nnweb-decode-entities)
+      (mm-url-decode-entities)
       (set-marker body nil))))
 
 (defun nnweb-reference-search (search)
-  (url-insert-file-contents
+  (mm-url-insert
    (concat
     (nnweb-definition 'address)
     "?"
-    (nnweb-encode-www-form-urlencoded
+    (mm-url-encode-www-form-urlencoded
      `(("search" . "advanced")
        ("querytext" . ,search)
        ("subj" . "")
@@ -648,7 +637,7 @@ and `altavista'.")
            (goto-char (point-min))
            (while (search-forward "<dt>" nil t)
              (replace-match "\n<blubb>"))
-           (nnweb-decode-entities)
+           (mm-url-decode-entities)
            (goto-char (point-min))
            (while (re-search-forward "<blubb>.*href=\"\\([^\"]+\\)\"><strong>\\([^>]*\\)</strong></a><dd>\\([^-]+\\)- <b>\\([^<]+\\)<.*href=\"news:\\([^\"]+\\)\">.*\">\\(.+\\)</a><P>"
                                      nil t)
@@ -693,15 +682,15 @@ and `altavista'.")
       (while (re-search-forward "<A.*\\?id@\\([^\"]+\\)\">[0-9]+</A>" nil t)
        (replace-match "&lt;\\1&gt; " t)))
     (widen)
-    (nnweb-remove-markup)
-    (nnweb-decode-entities)))
+    (mm-url-remove-markup)
+    (mm-url-decode-entities)))
 
 (defun nnweb-altavista-search (search &optional part)
-  (url-insert-file-contents
+  (mm-url-insert
    (concat
     (nnweb-definition 'address)
     "?"
-    (nnweb-encode-www-form-urlencoded
+    (mm-url-encode-www-form-urlencoded
      `(("pg" . "aq")
        ("what" . "news")
        ,@(when part `(("stq" . ,(int-to-string (* part 30)))))
@@ -731,7 +720,7 @@ and `altavista'.")
     (goto-char (point-min))
     (while (search-forward "<br>" nil t)
       (replace-match "\n"))
-    (nnweb-remove-markup)
+    (mm-url-remove-markup)
     (goto-char (point-min))
     (while (re-search-forward "^[ \t]*\n" nil t)
       (replace-match ""))
@@ -741,7 +730,7 @@ and `altavista'.")
     (narrow-to-region (point) (point-max))
     (search-forward "</pre>" nil t)
     (delete-region (point) (point-max))
-    (nnweb-remove-markup)
+    (mm-url-remove-markup)
     (widen)))
 
 (defun nnweb-google-parse-1 (&optional Message-ID)
@@ -763,8 +752,8 @@ and `altavista'.")
                 "http://groups.google.com/groups?selm=%s&output=gplain" mid))
       (narrow-to-region (search-forward ">" nil t)
                        (search-forward "</a>" nil t))
-      (nnweb-remove-markup)
-      (nnweb-decode-entities)
+      (mm-url-remove-markup)
+      (mm-url-decode-entities)
       (setq Subject (buffer-string))
       (goto-char (point-max))
       (widen)
@@ -775,8 +764,8 @@ and `altavista'.")
          (skip-chars-forward " \t")
        (narrow-to-region (point)
                          (search-forward "</a>" nil t))
-       (nnweb-remove-markup)
-       (nnweb-decode-entities)
+       (mm-url-remove-markup)
+       (mm-url-decode-entities)
        (setq Newsgroups (buffer-string))
        (goto-char (point-max))
        (widen)
@@ -807,7 +796,7 @@ and `altavista'.")
          (nconc nnweb-articles map))
     (when (setq header (cadar map))
       (mm-with-unibyte-current-buffer
-       (nnweb-fetch-url (mail-header-xref header)))
+       (mm-url-insert (mail-header-xref header)))
       (caar map))))
 
 (defun nnweb-google-create-mapping ()
@@ -827,11 +816,11 @@ and `altavista'.")
                (sort nnweb-articles 'car-less-than-car))))))
 
 (defun nnweb-google-search (search)
-  (nnweb-insert
+  (mm-url-insert
    (concat
     (nnweb-definition 'address)
     "?"
-    (nnweb-encode-www-form-urlencoded
+    (mm-url-encode-www-form-urlencoded
      `(("q" . ,search)
        ("num". "100")
        ("hq" . "")
@@ -869,75 +858,6 @@ and `altavista'.")
     (mapcar 'nnweb-insert-html (nth 2 parse))
     (insert "</" (symbol-name (car parse)) ">\n")))
 
-(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 "&"))
-
-(defun nnweb-fetch-form (url pairs)
-  "Fetch a form from URL with PAIRS as the data using the POST method."
-  (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)
-    (setq buffer-file-name nil))
-  t)
-
-(defun nnweb-decode-entities ()
-  "Decode all HTML entities."
-  (goto-char (point-min))
-  (while (re-search-forward "&\\(#[0-9]+\\|[a-z]+\\);" nil t)
-    (let ((elem (if (eq (aref (match-string 1) 0) ?\#)
-                       (let ((c
-                              (string-to-number (substring
-                                                 (match-string 1) 1))))
-                         (if (mm-char-or-char-int-p c) c 32))
-                     (or (cdr (assq (intern (match-string 1))
-                                    w3-html-entities))
-                         ?#))))
-      (unless (stringp elem)
-       (setq elem (char-to-string elem)))
-      (replace-match elem t t))))
-
-(defun nnweb-decode-entities-string (string)
-  (with-temp-buffer
-    (insert string)
-    (nnweb-decode-entities)
-    (buffer-substring (point-min) (point-max))))
-
-(defun nnweb-remove-markup ()
-  "Remove all HTML markup, leaving just plain text."
-  (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 nnweb-insert (url &optional follow-refresh)
-  "Insert the contents from an URL in the current buffer.
-If FOLLOW-REFRESH is non-nil, redirect refresh url in META."
-  (let ((name buffer-file-name))
-    (if follow-refresh 
-       (save-restriction
-         (narrow-to-region (point) (point))
-         (url-insert-file-contents url)
-         (goto-char (point-min))
-         (when (re-search-forward
-                "<meta[ \t\r\n]*http-equiv=\"Refresh\"[^>]*URL=\\([^\"]+\\)\"" nil t)
-           (let ((url (match-string 1)))
-             (delete-region (point-min) (point-max))
-             (nnweb-insert url t))))
-      (url-insert-file-contents url))
-    (setq buffer-file-name name)))
-
 (defun nnweb-parse-find (type parse &optional maxdepth)
   "Find the element of TYPE in PARSE."
   (catch 'found
index 27d2b72..4df938b 100644 (file)
 (require 'gnus)
 (require 'nnmail)
 (require 'mm-util)
-(eval-when-compile
-  (ignore-errors
-    (require 'nnweb)))
-;; Report failure to find w3 at load time if appropriate.
-(eval '(require 'nnweb))
+(require 'mm-url)
+(require 'nnweb)
+(autoload 'w3-parse-buffer "w3-parse")
 
 (nnoo-declare nnwfm)
 
            (erase-buffer)
            (setq subject (nth 2 (assq (car elem) topics))
                  thread-id (nth 0 (assq (car elem) topics)))
-           (nnweb-insert
+           (mm-url-insert
             (concat nnwfm-address
                     (format "Item.asp?GroupID=%d&ThreadID=%d" sid
                             thread-id)))
 (deffoo nnwfm-request-list (&optional server)
   (nnwfm-possibly-change-server nil server)
   (mm-with-unibyte-buffer
-    (nnweb-insert
+    (mm-url-insert
      (if (string-match "/$" nnwfm-address)
         (concat nnwfm-address "Group.asp")
        nnwfm-address))
       (while furls
        (erase-buffer)
        (push (car furls) fetched-urls)
-       (nnweb-insert (pop furls))
+       (mm-url-insert (pop furls))
        (goto-char (point-min))
        (while (re-search-forward "  wr(" nil t)
          (forward-char -1)
                     (not (member
                           (setq url (concat
                                      nnwfm-address
-                                     (nnweb-decode-entities-string url)))
+                                     (mm-url-decode-entities-string url)))
                           fetched-urls)))
            (push url furls))))
       ;; The main idea here is to map Gnus article numbers to
index 27fc0eb..b98bb69 100644 (file)
 (require 'gnus)
 (require 'nnmail)
 (require 'mm-util)
+(require 'mm-url)
 (require 'mml)
 (eval-when-compile
   (ignore-errors
-    (require 'w3)
     (require 'url)
-    (require 'url-cookie)
-    (require 'w3-forms)
-    (require 'nnweb)))
+    (require 'url-cookie)))
 ;; Report failure to find w3 at load time if appropriate.
 (eval '(progn
-        (require 'w3)
         (require 'url)
-        (require 'url-cookie)
-        (require 'w3-forms)
-        (require 'nnweb)))
+        (require 'url-cookie)))
 
 ;;;
 
          (set (intern (concat "webmail-" (symbol-name var))) (cdr pair))
        (set (intern (concat "webmail-" (symbol-name var))) nil)))))
 
-(defun webmail-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 "&"))
-
-(defun webmail-fetch-simple (url content)
-  (let ((url-request-data content)
-       (url-request-method "POST")
-       (url-request-extra-headers
-        '(("Content-type" . "application/x-www-form-urlencoded"))))
-    (nnweb-insert url))
-  t)
-
-(defun webmail-fetch-form (url pairs)
-  (let ((url-request-data (webmail-encode-www-form-urlencoded pairs))
-       (url-request-method "POST")
-       (url-request-extra-headers
-        '(("Content-type" . "application/x-www-form-urlencoded"))))
-    (nnweb-insert url))
-  t)
-
 (defun webmail-eval (expr)
   (cond
    ((consp expr)
     (cond
      ((eq (car xurl) 'content)
       (pop xurl)
-      (webmail-fetch-simple (if (stringp (car xurl))
+      (mm-url-fetch-simple (if (stringp (car xurl))
                                (car xurl)
                              (apply 'format (webmail-eval (car xurl))))
                            (apply 'format (webmail-eval (cdr xurl)))))
      ((eq (car xurl) 'post)
       (pop xurl)
-      (webmail-fetch-form (car xurl) (webmail-eval (cdr xurl))))
+      (mm-url-fetch-form (car xurl) (webmail-eval (cdr xurl))))
      (t
-      (nnweb-insert (apply 'format (webmail-eval xurl)))))))
+      (mm-url-insert (apply 'format (webmail-eval xurl)))))))
 
 (defun webmail-init ()
   "Initialize buffers and such."
     (let ((url (match-string 1)))
       (erase-buffer)
       (mm-with-unibyte-current-buffer
-       (nnweb-insert url)))
+       (mm-url-insert url)))
     (goto-char (point-min))))
 
 (defun webmail-fetch (file subtype user password)
        (message "Fetching mail #%d..." (setq n (1+ n)))
        (erase-buffer)
        (mm-with-unibyte-current-buffer
-         (nnweb-insert (cdr item)))
+         (mm-url-insert (cdr item)))
        (setq id (car item))
        (if webmail-article-snarf
            (funcall webmail-article-snarf file id))
     (if (not (search-forward "</pre>" nil t))
        (webmail-error "article@3.1"))
     (delete-region (match-beginning 0) (point-max))
-    (nnweb-remove-markup)
-    (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
-      (nnweb-decode-entities))
+    (mm-url-remove-markup)
+    (mm-url-decode-entities-nbsp)
     (goto-char (point-min))
     (while (re-search-forward "\r\n?" nil t)
       (replace-match "\n"))
        (setq p (match-beginning 0))
        (search-forward "</a>" nil t)
        (delete-region p (match-end 0)))
-      (nnweb-remove-markup)
-      (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
-       (nnweb-decode-entities))
+      (mm-url-remove-markup)
+      (mm-url-decode-entities-nbsp)
       (goto-char (point-min))
       (delete-blank-lines)
       (goto-char (point-min))
              (delete-region p (match-end 0))
              (save-excursion
                (set-buffer (generate-new-buffer " *webmail-att*"))
-               (nnweb-insert attachment)
+               (mm-url-insert attachment)
                (push (current-buffer) webmail-buffer-list)
                (setq bufname (buffer-name)))
              (setq mime t)
            (goto-char (match-end 0))
            (if (looking-at "$") (forward-char))
            (delete-region (point-min) (point))
-           (nnweb-remove-markup)
-           (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
-             (nnweb-decode-entities))
+           (mm-url-remove-markup)
+           (mm-url-decode-entities-nbsp)
            nil)
           (t
            (setq mime t)
        (setq p (match-beginning 0))
        (search-forward "</a>" nil t)
        (delete-region p (match-end 0)))
-      (nnweb-remove-markup)
-      (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
-       (nnweb-decode-entities))
+      (mm-url-remove-markup)
+      (mm-url-decode-entities-nbsp)
       (goto-char (point-min))
       (delete-blank-lines)
       (goto-char (point-max))
          (if (not (search-forward "</table>" nil t))
              (webmail-error "article@5"))
          (narrow-to-region p (match-end 0))
-         (nnweb-remove-markup)
-         (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
-           (nnweb-decode-entities))
+         (mm-url-remove-markup)
+         (mm-url-decode-entities-nbsp)
          (goto-char (point-min))
          (delete-blank-lines)
          (setq ct (mail-fetch-field "content-type")
          (widen)
          (save-excursion
            (set-buffer (generate-new-buffer " *webmail-att*"))
-           (nnweb-insert (concat webmail-aux attachment))
+           (mm-url-insert (concat webmail-aux attachment))
            (push (current-buffer) webmail-buffer-list)
            (setq bufname (buffer-name)))
          (insert "<#part")
     (goto-char (point-min))
     (while (re-search-forward "<br>" nil t)
       (replace-match "\n"))
-    (nnweb-remove-markup)
-    (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
-      (nnweb-decode-entities))
+    (mm-url-remove-markup)
+    (mm-url-decode-entities-nbsp)
     nil)
    (t
     (insert "<#part type=\"text/html\" disposition=inline>")
       (goto-char (point-min))
       (while (search-forward "<b>" nil t)
        (replace-match "\n"))
-      (nnweb-remove-markup)
-      (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
-       (nnweb-decode-entities))
+      (mm-url-remove-markup)
+      (mm-url-decode-entities-nbsp)
       (goto-char (point-min))
       (delete-blank-lines)
       (goto-char (point-min))
              (let (bufname);; Attachment
                (save-excursion
                  (set-buffer (generate-new-buffer " *webmail-att*"))
-                 (nnweb-insert (concat (car webmail-open-url) attachment))
+                 (mm-url-insert (concat (car webmail-open-url) attachment))
                  (push (current-buffer) webmail-buffer-list)
                  (setq bufname (buffer-name)))
                (insert "<#part type=" type)
       (goto-char (point-min))
       (while (search-forward "<b>" nil t)
        (replace-match "\n"))
-      (nnweb-remove-markup)
-      (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
-       (nnweb-decode-entities))
+      (mm-url-remove-markup)
+      (mm-url-decode-entities-nbsp)
       (goto-char (point-min))
       (delete-blank-lines)
       (goto-char (point-min))
              (let (bufname);; Attachment
                (save-excursion
                  (set-buffer (generate-new-buffer " *webmail-att*"))
-                 (nnweb-insert (concat (car webmail-open-url) attachment))
+                 (mm-url-insert (concat (car webmail-open-url) attachment))
                  (push (current-buffer) webmail-buffer-list)
                  (setq bufname (buffer-name)))
                (insert "<#part type=" type)
       (let ((url (match-string 1)))
        (setq base (match-string 2))
        (erase-buffer)
-       (nnweb-insert url)))
+       (mm-url-insert url)))
     (goto-char (point-min))
     (when (re-search-forward
           "(\\([0-9]+\\) Message.?-[^>]*\\([0-9]+\\) New"
                              (match-beginning 0)
                            (point-max)))
        (goto-char (point-min))
-       (nnweb-remove-markup)
-       (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
-         (nnweb-decode-entities))
+       (mm-url-remove-markup)
+       (mm-url-decode-entities-nbsp)
        (goto-char (point-max))))
      ((looking-at "[\t\040\r\n]*<TABLE")
       (save-restriction
          (delete-region (point-min) (point-max))
          (save-excursion
            (set-buffer (generate-new-buffer " *webmail-att*"))
-           (nnweb-insert url)
+           (mm-url-insert url)
            (push (current-buffer) webmail-buffer-list)
            (setq bufname (buffer-name)))
          (insert "<#part type=\"" type "\"")
       (narrow-to-region (point-min) (point))
       (while (search-forward "\r\n" nil t)
        (replace-match "\n"))
-      (nnweb-remove-markup)
-      (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
-       (nnweb-decode-entities))
+      (mm-url-remove-markup)
+      (mm-url-decode-entities-nbsp)
       (goto-char (point-min))
       (while (re-search-forward "\n\n+" nil t)
        (replace-match "\n"))