Enhance hotmail-snarf.
authorShengHuo ZHU <zsh@cs.rochester.edu>
Fri, 17 Dec 1999 16:58:06 +0000 (16:58 +0000)
committerShengHuo ZHU <zsh@cs.rochester.edu>
Fri, 17 Dec 1999 16:58:06 +0000 (16:58 +0000)
lisp/ChangeLog
lisp/webmail.el

index a6c3bf4..8d9a616 100644 (file)
@@ -1,3 +1,7 @@
+1999-12-17 11:54:41  Shenghuo ZHU  <zsh@cs.rochester.edu>
+
+       * webmail.el: Enhance hotmail-snarf.
+
 1999-12-17 10:38:10  Shenghuo ZHU  <zsh@cs.rochester.edu>
 
        * rfc2047.el (rfc2047-dissect-region): Rewrite.
index 5770ea7..1810f8e 100644 (file)
 ;;; Interface functions
 
 (defun webmail-error (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-type str))
 
   (if (gnus-buffer-live-p webmail-buffer)
       (set-buffer webmail-buffer)
     (setq webmail-buffer
-         (nnheader-set-temp-buffer " *webmail*"))))
+         (mm-with-unibyte
+           (nnheader-set-temp-buffer " *webmail*")))))
 
 (defvar url-package-name)
 (defvar url-package-version)
     (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 ()
        (setq newp t)))))
 
 (defun webmail-hotmail-article (file id)
-  (let (p attachment count mime)
+  (let (p attachment count mime hotmail-direct)
     (save-restriction
+      (webmail-encode-8bit)
       (goto-char (point-min))
       (if (not (search-forward "<DIV>" nil t))
-         (webmail-error "article@1"))
-      (narrow-to-region (point-min) (match-beginning 0))
+         (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)) 
       (insert "\n")
       (setq p (point))
       (while (re-search-forward 
-             "<div>\\|\\(http://[^/]+/cgi-bin/getmsg/\\([^\?]+\\)\?[^\"]*\\)\"" 
+             "<tt>\\|<div>\\|\\(http://[^/]+/cgi-bin/getmsg/\\([^\?]+\\)\?[^\"]*\\)\"" 
              nil t)
        (if (setq attachment (match-string 1))
            (let ((filename (match-string 2))
              (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 
       ;; Some blank line to seperate mails.
       (insert "\n\nFrom nobody " (current-time-string) "\n")
       (if id
-         (insert "Message-ID: <" id "@hotmail.com>\n"))
+         (insert (format "Message-ID: <%s@hotmail.com>\n" id)))
       (unless (looking-at "$") 
        (if (search-forward "\n\n" nil t)
            (forward-line -1)
              (setq tofetch (1+ tofetch)))
            (setq newp t))
        (setq newp nil)))
+    (setq webmail-articles (nreverse webmail-articles))
     (message "Fetching %d mail(s)" tofetch)))
 
 (defun webmail-yahoo-article (file id)
       ;; Some blank line to seperate mails.
       (insert "\n\nFrom nobody " (current-time-string) "\n")
       (if id
-         (insert "Message-ID: <" id "@yahoo.com>\n"))
+         (insert (format "Message-ID: <%s@yahoo.com>\n" id)))
       (unless (looking-at "$") 
        (if (search-forward "\n\n" nil t)
            (forward-line -1)
                              webmail-session id)))
        (if (or (not webmail-newmail-only)
                (equal (match-string 1) "True"))
-           (push item webmail-articles))))))
+           (push item webmail-articles))))
+    (setq webmail-articles (nreverse webmail-articles))))
 
 (defun webmail-netaddress-single-part ()
   (goto-char (point-min))
 (defun webmail-netaddress-article (file id)
   (let (p p1 attachment count mime type)
     (save-restriction
+      (webmail-encode-8bit)
       (goto-char (point-min))
       (if (not (search-forward "Trash" nil t))
          (webmail-error "article@1"))
       ;; Some blank line to seperate mails.
       (insert "\n\nFrom nobody " (current-time-string) "\n")
       (if id
-         (insert "Message-ID: <" id "@usa.net>\n"))
+         (insert (format "Message-ID: <%s@usa.net>\n" id)))
       (unless (looking-at "$") 
        (if (search-forward "\n\n" nil t)
            (forward-line -1)