* hashcash.el (mail-add-payment): Replace mapcar called for effect with mapc.
[gnus] / lisp / webmail.el
index f81869e..52b2ed8 100644 (file)
@@ -1,5 +1,7 @@
-;;; webmail.el --- interfacing with web mail
-;; Copyright (C) 1999 Free Software Foundation, Inc.
+;;; webmail.el --- interface of web mail
+
+;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
+;;   2005, 2006, 2007 Free Software Foundation, Inc.
 
 ;; Author: Shenghuo Zhu <zsh@cs.rochester.edu>
 ;; Keywords: hotmail netaddress my-deja netscape
@@ -8,7 +10,7 @@
 
 ;; GNU Emacs is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published
-;; by the Free Software Foundation; either version 2, or (at your
+;; by the Free Software Foundation; either version 3, or (at your
 ;; option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful, but
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;;; 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'.
 
 ;; Todo: To support more web mail servers.
 
-;; Known bugs: 
+;; Known bugs:
 ;; 1. Net@ddress may corrupt `X-Face'.
 
 ;; Warning:
 (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)))
 
 ;;;
 
      (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=" 
+     (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 
+      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="
+     (trash-url
+      "%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)
      (open-url "http://www.netaddress.com/")
      (open-snarf . webmail-netaddress-open)
      (login-url
-      content 
+      content
       ("%s" webmail-aux)
-      "LoginState=2&SuccessfulLogin=%%2Ftpl&NewServerName=www.netaddress.com&JavaScript=JavaScript1.2&DomainID=4&NA31site=classic.netaddress.com&NA31port=80&UserID=%s&passwd=%s" 
+      "LoginState=2&SuccessfulLogin=%%2Ftpl&NewServerName=www.netaddress.com&JavaScript=JavaScript1.2&DomainID=4&Domain=usa.net&NA31site=classic.netaddress.com&NA31port=80&UserID=%s&passwd=%s"
       user password)
      (login-snarf . webmail-netaddress-login)
-     (list-url 
+     (list-url
       "http://www.netaddress.com/tpl/Mail/%s/List?FolderID=-4&SortUseCase=True"
       webmail-session)
      (list-snarf . webmail-netaddress-list)
      (article-url "http://www.netaddress.com/")
      (article-snarf . webmail-netaddress-article)
-     (trash-url 
+     (trash-url
       "http://www.netaddress.com/tpl/Message/%s/Move?FolderID=-4&Q=%s&N=&Sort=Date&F=-1"
       webmail-session id))
     (netscape
      (open-url "http://ureg.netscape.com/iiop/UReg2/login/login?U2_LA=en&U2_BACK_FROM_CJ=true&U2_CS=iso-8859-1&U2_ENDURL=http://webmail.netscape.com/tpl/Subscribe/Step1&U2_NEW_ENDURL=http://webmail.netscape.com/tpl/Subscribe/Step1&U2_EXITURL=http://home.netscape.com/&U2_SOURCE=Webmail")
      (open-snarf . webmail-netscape-open)
      (login-url
-      content 
+      content
       ("http://ureg.netscape.com/iiop/UReg2/login/loginform")
-      "%s&U2_USERNAME=%s&U2_PASSWORD=%s"
-      webmail-aux user password)
+      "U2_USERNAME=%s&U2_PASSWORD=%s%s"
+      user password webmail-aux)
      (login-snarf . webmail-netaddress-login)
-     (list-url 
+     (list-url
       "http://webmail.netscape.com/tpl/Mail/%s/List?FolderID=-4&SortUseCase=True"
       webmail-session)
      (list-snarf . webmail-netaddress-list)
      (article-url "http://webmail.netscape.com/")
      (article-snarf . webmail-netscape-article)
-     (trash-url 
+     (trash-url
       "http://webmail.netscape.com/tpl/Message/%s/Move?FolderID=-4&Q=%s&N=&Sort=Date&F=-1"
       webmail-session id))
     (my-deja
      (paranoid cookie post)
      (address . "www.my-deja.com")
-     (open-url "http://www.my-deja.com/")
-     (open-snarf . webmail-my-deja-open)
+     ;;(open-snarf . webmail-my-deja-open)
      (login-url
-      content 
-      ("%s" webmail-aux)
-      "member_name=%s&pw=%s&go=&priv_opt_MyDeja99="
+      content
+      ("http://mydeja.google.com/cgi-bin/deja/maillogin.py")
+      "userid=%s&password=%s"
       user password)
-     (list-url "http://www.deja.com/rg_gotomail.xp")
      (list-snarf . webmail-my-deja-list)
      (article-snarf . webmail-my-deja-article)
-     (trash-url 
-      "%s/gmm_multiplex.femail?%%2Fgmm_domovemesg_top.femail=Move+to%%3A&folder_top=%s%%3Azzz%%3A%%7E6trash%%3AF%%3A0&docid=%s"
-      webmail-aux user id))))
+     (trash-url webmail-aux id))))
 
 (defvar webmail-variables
-  '(address article-snarf article-url list-snarf list-url 
+  '(address article-snarf article-url list-snarf list-url
            login-url login-snarf open-url open-snarf site articles
            post-process paranoid trash-url))
 
 
 (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")
+    (dolist (sym '(webmail-type user))
+      (if (boundp sym)
+         (gnus-pp `(setq ,sym ',(eval sym)))))
+    (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)
-  (message "%s HTML has changed; please get a new version of webmail (%s)"
+  (if webmail-error-function
+      (funcall webmail-error-function str))
+  (message "%s HTML has changed or your w3 package is too old.(%s)"
           webmail-type str)
-  (error "%s HTML has changed; please get a new version of webmail (%s)"
+  (error "%s HTML has changed or your w3 package is too old.(%s)"
         webmail-type str))
 
 (defun webmail-setdefault (type)
          (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)
 
 (defun webmail-url (xurl)
   (mm-with-unibyte-current-buffer
-    (cond 
+    (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."
   (if (gnus-buffer-live-p webmail-buffer)
       (set-buffer webmail-buffer)
     (setq webmail-buffer
-         (mm-with-unibyte
-           (nnheader-set-temp-buffer " *webmail*")))))
+         (nnheader-set-temp-buffer " *webmail*"))
+    (mm-disable-multibyte)))
 
 (defvar url-package-name)
 (defvar url-package-version)
 ;; instead of 303, though they mean 303.
 
 (defun webmail-url-confirmation-func (prompt)
-  (cond 
+  (cond
    ((equal prompt (concat "Honor redirection with non-GET method "
                          "(possible security risks)? "))
     nil)
 (defun webmail-refresh-redirect ()
   "Redirect refresh url in META."
   (goto-char (point-min))
-  (while (re-search-forward 
-         "HTTP-EQUIV=\"Refresh\"[^>]*URL=\\([^\"]+\\)\""
+  (while (re-search-forward
+         "<meta[ \t\r\n]*http-equiv=\"Refresh\"[^>]*URL=\\([^\"]+\\)\""
          nil t)
     (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)
          (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))