* nnmaildir.el (nnmaildir-request-set-mark): Handle the "too many
[gnus] / lisp / webmail.el
index 80592cf..b98bb69 100644 (file)
@@ -1,8 +1,8 @@
-;;; webmail.el --- interfacing with web mail
-;; Copyright (C) 1999 Free Software Foundation, Inc.
+;;; webmail.el --- interface of web mail
+;; Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
 
 ;; Author: Shenghuo Zhu <zsh@cs.rochester.edu>
-;; Keywords: hotmail
+;; Keywords: hotmail netaddress my-deja netscape
 
 ;; This file is part of GNU Emacs.
 
 
 ;;; 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.
+;; work. `w3' must be 4.0pre46+one-line-cookie patch or standalone
+;; `url'.
 
-;; Todo: To support more web mail.
+;; Todo: To support more web mail servers.
 
-;; Known bugs: 
-;; 1. In w3, there are two copies of url-maybe-relative.
-;;    If it is loaded from w3.el, (load-library "url"). 
-;;    Fixed in w3 4.0pre46.
-;; 2. Hotmail only accept one line cookie, while w3 breaks cookies 
-;;    into lines.
-;;    Maybe fixed in w3 4.0pre47+?.
+;; Known bugs:
+;; 1. Net@ddress may corrupt `X-Face'.
 
 ;; Warning:
-;; webmail is an experimental function, which means NO WARRANTY.
+;; Webmail is an experimental function, which means NO WARRANTY.
 
 ;;; Code:
 
 (require 'gnus)
 (require 'nnmail)
 (require 'mm-util)
-(require 'mail-source)
+(require 'mm-url)
 (require 'mml)
 (eval-when-compile
   (ignore-errors
-    (require 'w3)
     (require 'url)
-    (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 'w3-forms)
-        (require 'nnweb)))
-
+        (require 'url-cookie)))
 
 ;;;
 
 (defvar webmail-type-definition
   '((hotmail
      ;; Hotmail hate other HTTP user agents and use one line cookie
-     (paranoid agent cookie)
+     (paranoid agent cookie post)
      (address . "www.hotmail.com")
-     (open-url "http://www.hotmail.com")
+     (open-url "http://www.hotmail.com/")
      (open-snarf . webmail-hotmail-open)
      ;; W3 hate redirect POST
      (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)
-     (trash-url 
-      "%s&login=%s&f=33792&curmbox=ACTIVE&_lang=&js=&foo=inbox&page=&%s=on&Move+To.x=Move+To&tobox=trAsH" 
-      webmail-aux user id)    
+      webmail-aux user password)
+     ;;(login-snarf . webmail-hotmail-login)
+     ;;(list-url "%s" webmail-aux)
      (list-snarf . webmail-hotmail-list)
-     (article-snarf . webmail-hotmail-article))))
+     (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 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=&.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/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)
+     (address . "www.netaddress.com")
+     (open-url "http://www.netaddress.com/")
+     (open-snarf . webmail-netaddress-open)
+     (login-url
+      content
+      ("%s" webmail-aux)
+      "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
+      "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
+      "http://www.netaddress.com/tpl/Message/%s/Move?FolderID=-4&Q=%s&N=&Sort=Date&F=-1"
+      webmail-session id))
+    (netscape
+     (paranoid cookie post agent)
+     (address . "webmail.netscape.com")
+     (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
+      ("http://ureg.netscape.com/iiop/UReg2/login/loginform")
+      "U2_USERNAME=%s&U2_PASSWORD=%s%s"
+      user password webmail-aux)
+     (login-snarf . webmail-netaddress-login)
+     (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
+      "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-snarf . webmail-my-deja-open)
+     (login-url
+      content
+      ("http://mydeja.google.com/cgi-bin/deja/maillogin.py")
+      "userid=%s&password=%s"
+      user password)
+     (list-snarf . webmail-my-deja-list)
+     (article-snarf . webmail-my-deja-article)
+     (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-address nil)
 (defvar webmail-paranoid nil)
 (defvar webmail-aux nil)
+(defvar webmail-session nil)
 (defvar webmail-article-snarf nil)
 (defvar webmail-article-url nil)
 (defvar webmail-list-snarf nil)
 (defvar webmail-post-process nil)
 
 (defvar webmail-buffer nil)
+(defvar webmail-buffer-list nil)
+
+(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 or your w3 package is too old.(%s)"
+          webmail-type str)
+  (error "%s HTML has changed or your w3 package is too old.(%s)"
+        webmail-type str))
+
 (defun webmail-setdefault (type)
   (let ((type-def (cdr (assq type webmail-type-definition)))
        (vars webmail-variables)
        pair)
+    (setq webmail-type type)
     (dolist (var vars)
       (if (setq pair (assq var type-def))
          (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)
     expr)))
 
 (defun webmail-url (xurl)
-  (let ((url-confirmation-func 'identity))
-    (cond 
+  (mm-with-unibyte-current-buffer
+    (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)))))))
-
-(defun webmail-decode-entities ()
-  (goto-char (point-min))
-  (while (re-search-forward "&\\(#[0-9]+\\|[a-z]+\\);" nil t)
-    (replace-match (char-to-string 
-                   (if (eq (aref (match-string 1) 0) ?\#)
-                       (string-to-number (substring (match-string 1) 1))
-                     (or (cdr (assq (intern (match-string 1))
-                                    w3-html-entities))
-                         ?#)))
-                  t t)))
-
-(defun webmail-decode-entities-string (str)
-  (with-temp-buffer
-    (insert str)
-    (webmail-decode-entities)
-    (buffer-substring (point-min) (point-max))))
-
-(defun webmail-remove-markup ()
-  (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)))
+      (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
-         (nnheader-set-temp-buffer " *webmail*"))))
+         (nnheader-set-temp-buffer " *webmail*"))
+    (mm-disable-multibyte)))
 
 (defvar url-package-name)
 (defvar url-package-version)
 (defvar url-cookie-multiple-line)
+(defvar url-confirmation-func)
 
-(defun webmail-fetch (file wmtype user password)
-  (webmail-setdefault wmtype)
-  (let ((url-package-name (if (memq 'agent webmail-paranoid)
-                             "Mozilla"
-                           url-package-name))
-       (url-package-version (if (memq 'agent webmail-paranoid)
-                                "4.0"
-                              url-package-version))
-       (url-cookie-multiple-line (if (memq 'cookie webmail-paranoid)
-                                     nil
-                                   url-cookie-multiple-line)))
-    (webmail-init)
-    (when webmail-open-url 
-      (erase-buffer)
-      (webmail-url webmail-open-url))
-    (if webmail-open-snarf (funcall webmail-open-snarf))
-    (when webmail-login-url 
-      (erase-buffer)
-      (webmail-url webmail-login-url))
-    (if webmail-login-snarf 
-       (funcall webmail-login-snarf))
-    (when webmail-list-url 
+;; Hack W3 POST redirect.  See `url-parse-mime-headers'.
+;;
+;; Netscape uses "GET" as redirect method when orignal method is POST
+;; and status is 302, .i.e no security risks by default without
+;; confirmation.
+;;
+;; Some web servers (at least Apache used by yahoo) return status 302
+;; instead of 303, though they mean 303.
+
+(defun webmail-url-confirmation-func (prompt)
+  (cond
+   ((equal prompt (concat "Honor redirection with non-GET method "
+                         "(possible security risks)? "))
+    nil)
+   ((equal prompt "Continue (with method of GET)? ")
+    t)
+   (t (error prompt))))
+
+(defun webmail-refresh-redirect ()
+  "Redirect refresh url in META."
+  (goto-char (point-min))
+  (while (re-search-forward
+         "<meta[ \t\r\n]*http-equiv=\"Refresh\"[^>]*URL=\\([^\"]+\\)\""
+         nil t)
+    (let ((url (match-string 1)))
       (erase-buffer)
-      (webmail-url webmail-list-url))
-    (if webmail-list-snarf 
-       (funcall webmail-list-snarf))
-    (let (item id (n 0))
+      (mm-with-unibyte-current-buffer
+       (mm-url-insert url)))
+    (goto-char (point-min))))
+
+(defun webmail-fetch (file subtype user password)
+  (save-excursion
+    (webmail-setdefault subtype)
+    (let ((url-package-name (if (memq 'agent webmail-paranoid)
+                               "Mozilla"
+                             url-package-name))
+         (url-package-version (if (memq 'agent webmail-paranoid)
+                                  "4.0"
+                                url-package-version))
+         (url-cookie-multiple-line (if (memq 'cookie webmail-paranoid)
+                                       nil
+                                     url-cookie-multiple-line))
+         (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))
+      (webmail-init)
+      (setq webmail-articles nil)
+      (when webmail-open-url
+       (erase-buffer)
+       (webmail-url webmail-open-url))
+      (if webmail-open-snarf (funcall webmail-open-snarf))
+      (when webmail-login-url
+       (erase-buffer)
+       (webmail-url webmail-login-url))
+      (if webmail-login-snarf
+         (funcall webmail-login-snarf))
+      (when webmail-list-url
+       (erase-buffer)
+       (webmail-url webmail-list-url))
+      (if webmail-list-snarf
+         (funcall webmail-list-snarf))
       (while (setq item (pop webmail-articles))
        (message "Fetching mail #%d..." (setq n (1+ n)))
        (erase-buffer)
-       (nnweb-insert (cdr item))
+       (mm-with-unibyte-current-buffer
+         (mm-url-insert (cdr item)))
        (setq id (car item))
-       (if webmail-article-snarf 
+       (if webmail-article-snarf
            (funcall webmail-article-snarf file id))
        (when (and webmail-trash-url webmail-move-to-trash-can)
          (message "Move mail #%d to trash can..." n)
-         (webmail-url webmail-trash-url))))
+         (condition-case err
+             (progn
+               (webmail-url webmail-trash-url)
+               (let (buf)
+                 (while (setq buf (pop webmail-buffer-list))
+                   (kill-buffer buf))))
+           (error
+            (let (buf)
+              (while (setq buf (pop webmail-buffer-list))
+                (kill-buffer buf)))
+            (error err))))))
     (if webmail-post-process
        (funcall webmail-post-process))))
 
+(defun webmail-encode-8bit ()
+  (goto-char (point-min))
+  (skip-chars-forward "^\200-\377")
+  (while (not (eobp))
+    (insert (format "&%d;" (mm-char-int (char-after))))
+    (delete-char 1)
+    (skip-chars-forward "^\200-\377")))
+
 ;;; hotmail
 
 (defun webmail-hotmail-open ()
   (goto-char (point-min))
-  (if (re-search-forward 
+  (if (re-search-forward
        "action=\"https?://\\([^/]+\\)/cgi-bin/dologin" nil t)
       (setq webmail-aux (match-string 1))
-    (error "Can't find login url (open@1)")))
+    (webmail-error "open@1")))
 
-(defun webmail-hotmail-list ()
-  (let (site url newp)
-    (goto-char (point-min))
-    (if (re-search-forward "[0-9]+ messages, [0-9]+ new") 
-       (message "Found %s" (match-string 0)))
+(defun webmail-hotmail-login ()
+  (let (site)
     (goto-char (point-min))
-    (if (re-search-forward 
-        "action=\"https?://\\([^/]+\\)/cgi-bin/HoTMaiL" nil t)
+    (if (re-search-forward
+        "https?://\\([^/]+hotmail\\.msn\\.com\\)/cgi-bin/" nil t)
        (setq site (match-string 1))
-      (error "Can't find server url (list@1)"))
+      (webmail-error "login@1"))
     (goto-char (point-min))
-    (if (re-search-forward "disk=\\([^&]+\\)&" nil t)
-       (setq webmail-aux 
-             (concat "http://" site "/cgi-bin/HoTMaiL?disk=" 
-                     (match-string 1)))
-      (error "Can't find disk (list@2)"))
-    (goto-char (point-max))
-    (while (re-search-backward 
-           "newmail\\.gif\\|href=\"\\(/cgi-bin/getmsg\\?[^\"]+\\)\"" 
-           nil t)
-      (if (setq url (match-string 1))
-         (progn
-           (if (or newp (not webmail-newmail-only))
-               (let (id)
-                 (if (string-match "msg=\\([^&]+\\)" url)
-                     (setq id (match-string 1 url)))
-                 (push (cons id (concat "http://" site url)) 
-                       webmail-articles)))
-           (setq newp nil))
-       (setq newp t)))))
+    (if (re-search-forward
+        "\\(/cgi-bin/HoTMaiL\\?[^\"]*a=b[^\"]*\\)" nil t)
+       (setq webmail-aux (concat "http://" site (match-string 1)))
+      (webmail-error "login@2"))))
+
+(defun webmail-hotmail-list ()
+  (goto-char (point-min))
+  (skip-chars-forward " \t\n\r")
+  (let (site url newp (total "0"))
+    (if (eobp)
+       (setq total "0")
+      (if (re-search-forward "\\([0-9]+\\) *<b>(\\([0-9]+\\) new)" nil t)
+         (message "Found %s (%s new)" (setq total (match-string 1))
+                  (match-string 2))
+       (if (re-search-forward "\\([0-9]+\\) new" nil t)
+           (message "Found %s new" (setq total (match-string 1)))
+         (webmail-error "list@0"))))
+    (unless (equal total "0")
+      (goto-char (point-min))
+      (if (re-search-forward
+        "https?://\\([^/]+hotmail\\.msn\\.com\\)/cgi-bin/" nil t)
+         (setq site (match-string 1))
+       (webmail-error "list@1"))
+      (goto-char (point-min))
+      (if (re-search-forward "disk=\\([^&]*\\)&" nil t)
+         (setq webmail-aux
+               (concat "http://" site "/cgi-bin/HoTMaiL?disk="
+                       (match-string 1)))
+       (webmail-error "list@2"))
+      (goto-char (point-max))
+      (while (re-search-backward
+             "newmail\\.gif\\|href=\"\\(/cgi-bin/getmsg\\?[^\"]+\\)\""
+             nil t)
+       (if (setq url (match-string 1))
+           (progn
+             (if (or newp (not webmail-newmail-only))
+                 (let (id)
+                   (if (string-match "msg=\\([^&]+\\)" url)
+                       (setq id (match-string 1 url)))
+                   (push (cons id (concat "http://" site url "&raw=0"))
+                         webmail-articles)))
+             (setq newp nil))
+         (setq newp t))))))
+
+;; Thank victor@idaccr.org (Victor S. Miller) for raw=0
 
 (defun webmail-hotmail-article (file id)
-  (let (p attachment count tbufs mime)
+  (goto-char (point-min))
+  (skip-chars-forward " \t\n\r")
+  (unless (eobp)
+    (if (not (search-forward "<pre>" nil t))
+       (webmail-error "article@3"))
+    (skip-chars-forward "\n\r\t ")
+    (delete-region (point-min) (point))
+    (if (not (search-forward "</pre>" nil t))
+       (webmail-error "article@3.1"))
+    (delete-region (match-beginning 0) (point-max))
+    (mm-url-remove-markup)
+    (mm-url-decode-entities-nbsp)
+    (goto-char (point-min))
+    (while (re-search-forward "\r\n?" nil t)
+      (replace-match "\n"))
+    (goto-char (point-min))
+    (insert "\n\n")
+    (if (not (looking-at "\n*From "))
+       (insert "From nobody " (current-time-string) "\n")
+      (forward-line))
+    (insert "X-Gnus-Webmail: " (symbol-value 'user)
+           "@" (symbol-name webmail-type) "\n")
+    (mm-append-to-file (point-min) (point-max) file)))
+
+(defun webmail-hotmail-article-old (file id)
+  (let (p attachment count mime hotmail-direct)
     (save-restriction
+      (webmail-encode-8bit)
       (goto-char (point-min))
-      (if (not (search-forward "FILE: wc_pnames.asp -->" nil t))
-         (error "Can't find start label (article@1)"))
-      (setq p (match-end 0))
-      (search-backward "<table" nil t)
-      (narrow-to-region (point-min) p)
-      (delete-region (point-min) (match-beginning 0)) 
+      (if (not (search-forward "<DIV>" nil t))
+         (if (not (search-forward "Reply&nbsp;All" nil t))
+             (webmail-error "article@1")
+           (setq hotmail-direct t))
+       (goto-char (match-beginning 0)))
+      (narrow-to-region (point-min) (point))
+      (if (not (search-backward "<table" nil t 2))
+         (webmail-error "article@1.1"))
+      (delete-region (point-min) (match-beginning 0))
       (while (search-forward "<a href=" nil t)
        (setq p (match-beginning 0))
        (search-forward "</a>" nil t)
        (delete-region p (match-end 0)))
-      (webmail-remove-markup)
-      (webmail-decode-entities)
+      (mm-url-remove-markup)
+      (mm-url-decode-entities-nbsp)
       (goto-char (point-min))
       (delete-blank-lines)
+      (goto-char (point-min))
+      (when (search-forward "\n\n" nil t)
+       (backward-char)
+       (delete-region (point) (point-max)))
       (goto-char (point-max))
       (widen)
       (insert "\n")
       (setq p (point))
-      (while (re-search-forward "<div>\\|\\(http://[^/]+/cgi-bin/getmsg/\\([^\?]+\\)\?[^\"]*\\)\"" nil t)
+      (while (re-search-forward
+             "<tt>\\|<div>\\|\\(http://[^/]+/cgi-bin/getmsg/\\([^\?]+\\)\?[^\"]*\\)\""
+             nil t)
        (if (setq attachment (match-string 1))
            (let ((filename (match-string 2))
-                 bufname) ;; Attachment
+                 bufname);; Attachment
              (delete-region p (match-end 0))
              (save-excursion
                (set-buffer (generate-new-buffer " *webmail-att*"))
-               (nnweb-insert attachment)
-               (push (current-buffer) tbufs)
+               (mm-url-insert attachment)
+               (push (current-buffer) webmail-buffer-list)
                (setq bufname (buffer-name)))
              (setq mime t)
-             (insert "<#part type=" 
+             (insert "<#part type="
                      (or (and filename
                               (string-match "\\.[^\\.]+$" filename)
                               (mailcap-extension-to-mime
                          "application/octet-stream"))
              (insert " buffer=\"" bufname "\"")
              (insert " filename=\"" filename "\"")
-             (insert " description=\"inline\"")
+             (insert " disposition=\"inline\"")
              (insert "><#/part>\n")
              (setq p (point)))
          (delete-region p (match-end 0))
-         (setq count 1)
-         (while (and (> count 0) 
-                     (re-search-forward "</div>\\|\\(<div>\\)" nil t))
-           (if (match-string 1)
-               (setq count (1+ count))
-             (if (= (setq count (1- count)) 0)
-                 (delete-region (match-beginning 0)
-                                (match-end 0)))))
+         (if hotmail-direct
+             (if (not (search-forward "</tt>" nil t))
+                 (webmail-error "article@1.2")
+               (delete-region (match-beginning 0) (match-end 0)))
+           (setq count 1)
+           (while (and (> count 0)
+                       (re-search-forward "</div>\\|\\(<div>\\)" nil t))
+             (if (match-string 1)
+                 (setq count (1+ count))
+               (if (= (setq count (1- count)) 0)
+                   (delete-region (match-beginning 0)
+                                  (match-end 0))))))
          (narrow-to-region p (point))
          (goto-char (point-min))
-         (cond 
+         (cond
           ((looking-at "<pre>")
            (goto-char (match-end 0))
            (if (looking-at "$") (forward-char))
            (delete-region (point-min) (point))
-           (webmail-remove-markup)
-           (webmail-decode-entities)
+           (mm-url-remove-markup)
+           (mm-url-decode-entities-nbsp)
            nil)
           (t
            (setq mime t)
<