Synch with Gnus (ChangeLog only).
[elisp/gnus.git-] / lisp / webmail.el
index f81869e..1089e2a 100644 (file)
@@ -1,5 +1,5 @@
 ;;; webmail.el --- interfacing with web mail
-;; Copyright (C) 1999 Free Software Foundation, Inc.
+;; Copyright (C) 1999, 2000 Free Software Foundation, Inc.
 
 ;; Author: Shenghuo Zhu <zsh@cs.rochester.edu>
 ;; Keywords: hotmail netaddress my-deja netscape
@@ -23,6 +23,9 @@
 
 ;;; Commentary:
 
+;; Note: Now mail.yahoo.com provides POP3 service, the webmail
+;; fetching is not going to be supported.
+
 ;; Note: You need to have `url' and `w3' installed for this backend to
 ;; work. `w3' must be 4.0pre46+one-line-cookie patch or standalone
 ;; `url'.
      (login-url
       "http://%s/cgi-bin/dologin?login=%s&passwd=%s&enter=Sign+in&sec=no&curmbox=ACTIVE&_lang=&js=yes&id=2&tw=-10000&beta="
       webmail-aux user password)
+     (login-snarf . webmail-hotmail-login)
+     (list-url "%s" webmail-aux)
      (list-snarf . webmail-hotmail-list)
      (article-snarf . webmail-hotmail-article)
      (trash-url 
       "%s&login=%s&f=33792&curmbox=ACTIVE&_lang=&foo=inbox&js=&page=&%s=on&_HMaction=MoveTo&tobox=trAsH&nullbox=" 
       webmail-aux user id))
     (yahoo
-     (paranoid cookie post)
+     (paranoid agent cookie post)
      (address . "mail.yahoo.com")
      (open-url "http://mail.yahoo.com/")
      (open-snarf . webmail-yahoo-open)
      (login-url;; yahoo will not accept GET
       content 
       ("%s" webmail-aux)
-      ".tries=1&.src=ym&.last=&promo=&lg=us&.intl=us&.bypass=&.chkP=Y&.done=http%%253a%%2F%%2Fedit.yahoo.com%%2Fconfig%%2Fmail%%253f.intl%%3D&login=%s&passwd=%s" 
+      ".tries=&.src=ym&.last=&promo=&.intl=&.bypass=&.partner=&.chkP=Y&.done=&login=%s&passwd=%s"
       user password)
      (login-snarf . webmail-yahoo-login)
      (list-url "%s&rb=Inbox&YN=1" webmail-aux)
      (list-snarf . webmail-yahoo-list)
      (article-snarf . webmail-yahoo-article)
      (trash-url 
-      "%s/ym/us/ShowFolder?YY=52107&inc=50&order=down&sort=date&pos=0&box=Inbox&DEL=Delete&destBox=&Mid=%s&destBox2="
+      "%s/ym/ShowFolder?YY=52107&inc=50&order=down&sort=date&pos=0&box=Inbox&DEL=Delete&destBox=&Mid=%s&destBox2="
       webmail-aux id))
     (netaddress
      (paranoid cookie post)
 
 (defvar webmail-type nil)
 
+(defvar webmail-error-function nil)
+
+(defvar webmail-debug-file "~/.emacs-webmail-debug")
+
 ;;; Interface functions
 
+(defun webmail-debug (str)
+  (with-temp-buffer
+    (insert "\n---------------- A bug at " str " ------------------\n")
+    (mapcar #'(lambda (sym) 
+               (if (boundp sym)
+                   (pp `(setq ,sym ',(eval sym)) (current-buffer))))
+           '(webmail-type user))
+    (insert "---------------- webmail buffer ------------------\n\n")
+    (insert-buffer-substring webmail-buffer)
+    (insert "\n---------------- end of buffer ------------------\n\n")
+    (append-to-file (point-min) (point-max) webmail-debug-file)))
+
 (defun webmail-error (str)
+  (if webmail-error-function
+      (funcall webmail-error-function str))
   (message "%s HTML has changed; please get a new version of webmail (%s)"
           webmail-type str)
   (error "%s HTML has changed; please get a new version of webmail (%s)"
       (webmail-fetch-form (car xurl) (webmail-eval (cdr xurl))))
      (t
       (nnweb-insert (apply 'format (webmail-eval xurl)))))))
-  
+
 (defun webmail-init ()
   "Initialize buffers and such."
   (if (gnus-buffer-live-p webmail-buffer)
   "Redirect refresh url in META."
   (goto-char (point-min))
   (while (re-search-forward 
-         "HTTP-EQUIV=\"Refresh\"[^>]*URL=\\([^\"]+\\)\""
+         "<meta[ \t\r\n]*http-equiv=\"Refresh\"[^>]*URL=\\([^\"]+\\)\""
          nil t)
     (let ((url (match-string 1)))
       (erase-buffer)
          (url-confirmation-func (if (memq 'post webmail-paranoid)
                                     'webmail-url-confirmation-func
                                   url-confirmation-func))
+         (url-http-silence-on-insecure-redirection t)
          url-cookie-storage url-cookie-secure-storage
          url-cookie-confirmation
          item id (n 0))
       (setq webmail-aux (match-string 1))
     (webmail-error "open@1")))
 
+(defun webmail-hotmail-login ()
+  (let (site)
+    (goto-char (point-min))
+    (if (re-search-forward 
+        "https?://\\([^/]+hotmail\\.msn\\.com\\)/cgi-bin/" nil t)
+       (setq site (match-string 1))
+      (webmail-error "login@1"))
+    (goto-char (point-min))
+    (if (re-search-forward 
+        "\\(/cgi-bin/HoTMaiL\\?[^\"]*curmbox=ACTIVE[^\"]*\\)" nil t)
+       (setq webmail-aux (concat "http://" site (match-string 1)))
+      (webmail-error "login@2"))))
+
 (defun webmail-hotmail-list ()
   (let (site url newp)
     (goto-char (point-min))
       (webmail-error "maybe your w3 version is too old"))
     (goto-char (point-min))
     (if (re-search-forward 
-        "action=\"https?://\\([^/]+\\)/cgi-bin/HoTMaiL" nil t)
+        "https?://\\([^/]+hotmail\\.msn\\.com\\)/cgi-bin/" nil t)
        (setq site (match-string 1))
       (webmail-error "list@1"))
     (goto-char (point-min))
       (webmail-error "article@3.1"))
   (delete-region (match-beginning 0) (point-max))
   (nnweb-remove-markup)
-  (nnweb-decode-entities)
+  (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
+    (nnweb-decode-entities))
   (goto-char (point-min))
   (while (re-search-forward "\r\n?" nil t)
     (replace-match "\n"))
        (search-forward "</a>" nil t)
        (delete-region p (match-end 0)))
       (nnweb-remove-markup)
-      (nnweb-decode-entities)
+      (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
+       (nnweb-decode-entities))
       (goto-char (point-min))
       (delete-blank-lines)
       (goto-char (point-min))
            (if (looking-at "$") (forward-char))
            (delete-region (point-min) (point))
            (nnweb-remove-markup)
-           (nnweb-decode-entities)
+           (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
+             (nnweb-decode-entities))
            nil)
           (t
            (setq mime t)
 
 (defun webmail-yahoo-login ()
   (goto-char (point-min))
-  (if (re-search-forward "http://[a-zA-Z][0-9]\\.mail\\.yahoo\\.com/" nil t)
+  (if (re-search-forward "http://[^/]+[0-9]\\.mail\\.yahoo\\.com/" nil t)
       (setq webmail-aux (match-string 0))
     (webmail-error "login@1"))
   (if (re-search-forward "YY=[0-9]+" nil t)
-      (setq webmail-aux (concat webmail-aux "ym/us/ShowFolder?"
+      (setq webmail-aux (concat webmail-aux "ym/ShowFolder?"
                                (match-string 0)))
     (webmail-error "login@2")))
 
       (webmail-error "list@1"))
     (goto-char (point-min))
     (while (re-search-forward 
-           "bgcolor=\"#eeeeee\"\\|href=\"\\(/ym/us/ShowLetter\\?MsgId=\\([^&]+\\)&[^\"]*\\)\""
+           "bgcolor=\"#eeeeee\"\\|href=\"\\(/ym/ShowLetter\\?MsgId=\\([^&]+\\)&[^\"]*\\)\""
            nil t)
       (if (setq url (match-string 1))
          (progn
        (search-forward "</a>" nil t)
        (delete-region p (match-end 0)))
       (nnweb-remove-markup)
-      (nnweb-decode-entities)
+      (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
+       (nnweb-decode-entities))
       (goto-char (point-min))
       (delete-blank-lines)
       (goto-char (point-max))
              (webmail-error "article@5"))
          (narrow-to-region p (match-end 0))
          (nnweb-remove-markup)
-         (nnweb-decode-entities)
+         (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
+           (nnweb-decode-entities))
          (goto-char (point-min))
          (delete-blank-lines)
          (setq ct (mail-fetch-field "content-type")
     (webmail-error "login@1")))
 
 (defun webmail-netaddress-list ()
+  (webmail-refresh-redirect)
   (let (item id)
     (goto-char (point-min))
     (when (re-search-forward 
     (while (re-search-forward "<br>" nil t)
       (replace-match "\n"))
     (nnweb-remove-markup)
-    (nnweb-decode-entities) 
+    (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
+      (nnweb-decode-entities))
     nil)
    (t
     (insert "<#part type=\"text/html\" disposition=inline>")
     t)))
 
 (defun webmail-netaddress-article (file id)
+  (webmail-refresh-redirect)
   (let (p p1 attachment count mime type)
     (save-restriction
       (webmail-encode-8bit)
       (while (search-forward "<b>" nil t)
        (replace-match "\n"))
       (nnweb-remove-markup)
-      (nnweb-decode-entities)
+      (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
+       (nnweb-decode-entities))
       (goto-char (point-min))
       (delete-blank-lines)
       (goto-char (point-min))
       (while (search-forward "<b>" nil t)
        (replace-match "\n"))
       (nnweb-remove-markup)
-      (nnweb-decode-entities)
+      (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
+       (nnweb-decode-entities))
       (goto-char (point-min))
       (delete-blank-lines)
       (goto-char (point-min))