;;; Commentary:
;; 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 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+?.
-;; 3. Net@ddress may corrupt `X-Face'.
+;; 1. Net@ddress may corrupt `X-Face'.
;; Warning:
;; Webmail is an experimental function, which means NO WARRANTY.
(ignore-errors
(require 'w3)
(require 'url)
+ (require 'url-cookie)
(require 'w3-forms)
(require 'nnweb)))
;; Report failure to find w3 at load time if appropriate.
(eval '(progn
(require 'w3)
(require 'url)
+ (require 'url-cookie)
(require 'w3-forms)
(require 'nnweb)))
;; Hotmail hate other HTTP user agents and use one line 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)
+ webmail-aux user password)
(list-snarf . webmail-hotmail-list)
(article-snarf . webmail-hotmail-article)
(trash-url
(yahoo
(paranoid cookie post)
(address . "mail.yahoo.com")
- (open-url "http://mail.yahoo.com")
+ (open-url "http://mail.yahoo.com/")
(open-snarf . webmail-yahoo-open)
- (login-url ;; yahoo will not accept GET
+ (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"
(netaddress
(paranoid cookie post)
(address . "www.netaddress.com")
- (open-url "http://www.netaddress.com")
+ (open-url "http://www.netaddress.com/")
(open-snarf . webmail-netaddress-open)
- (login-url ;; yahoo will not accept GET
+ (login-url;; yahoo will not accept GET
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"
expr)))
(defun webmail-url (xurl)
- (cond
- ((eq (car xurl) 'content)
- (pop xurl)
- (webmail-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))))
- (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-with-unibyte-current-buffer
+ (cond
+ ((eq (car xurl) 'content)
+ (pop xurl)
+ (webmail-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))))
+ (t
+ (nnweb-insert (apply 'format (webmail-eval xurl)))))))
+
(defun webmail-init ()
"Initialize buffers and such."
(if (gnus-buffer-live-p webmail-buffer)
(defvar url-cookie-multiple-line)
(defvar url-confirmation-func)
-;; Hack W3 POST redirect. See `url-parse-mime-headers'.
+;; 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
(defun webmail-url-confirmation-func (prompt)
(cond
((equal prompt (concat "Honor redirection with non-GET method "
- "(possible security risks)? "))
+ "(possible security risks)? "))
nil)
((equal prompt "Continue (with method of GET)? ")
t)
"Redirect refresh url in META."
(goto-char (point-min))
(while (re-search-forward "HTTP-EQUIV=\"Refresh\"[^>]*URL=\\([^\"]+\\)\""
- nil t)
+ nil t)
(let ((url (match-string 1)))
(erase-buffer)
(nnweb-insert 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))
- (setq id (car item))
- (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)
- (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))))))
+ (message "Fetching mail #%d..." (setq n (1+ n)))
+ (erase-buffer)
+ (nnweb-insert (cdr item))
+ (setq id (car item))
+ (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)
+ (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))))
(let (p attachment count mime)
(save-restriction
(goto-char (point-min))
- (if (not (search-forward "FILE: wc_pnames.asp -->" nil t))
+ (if (not (search-forward "<DIV>" 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)
+ (narrow-to-region (point-min) (match-beginning 0))
+ (if (not (search-backward "<table" nil t 2))
+ (error "Can't find start label (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)
+ (nnweb-remove-markup)
+ (nnweb-decode-entities)
(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")
(while (re-search-forward "<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*"))
(goto-char (match-end 0))
(if (looking-at "$") (forward-char))
(delete-region (point-min) (point))
- (webmail-remove-markup)
- (webmail-decode-entities)
+ (nnweb-remove-markup)
+ (nnweb-decode-entities)
nil)
(t
(setq mime t)
(goto-char (point-min))
(when (re-search-forward
"showing [0-9]+-\\([0-9]+\\) of \\([0-9]+\\)" nil t)
- ;(setq listed (match-string 1))
+ ;;(setq listed (match-string 1))
(message "Found %s mail(s)" (match-string 2)))
(if (string-match "http://[^/]+" webmail-aux)
(setq webmail-aux (match-string 0 webmail-aux))
(setq p (match-beginning 0))
(search-forward "</a>" nil t)
(delete-region p (match-end 0)))
- (webmail-remove-markup)
- (webmail-decode-entities)
+ (nnweb-remove-markup)
+ (nnweb-decode-entities)
(goto-char (point-min))
(delete-blank-lines)
(goto-char (point-max))
(if (not (search-forward "</table>" nil t))
(error "Can't find start label (article@5)"))
(narrow-to-region p (match-end 0))
- (webmail-remove-markup)
- (webmail-decode-entities)
+ (nnweb-remove-markup)
+ (nnweb-decode-entities)
(goto-char (point-min))
(delete-blank-lines)
(setq ct (mail-fetch-field "content-type")
(cons id
(format "%s/tpl/Message/%s/Read?Q=%s&FolderID=-4&SortUseCase=True&Sort=Date&Headers=True"
(car webmail-open-url)
- webmail-session id)))
+ webmail-session id)))
(if (or (not webmail-newmail-only)
(equal (match-string 1) "True"))
(push item webmail-articles))))))
(replace-match " "))
(goto-char (point-min))
(while (re-search-forward "<br>" nil t)
- (replace-match "\n"))
- (webmail-remove-markup)
- (webmail-decode-entities)
+ (replace-match "\n"))
+ (nnweb-remove-markup)
+ (nnweb-decode-entities)
nil)
(t
(insert "<#part type=\"text/html\" disposition=inline>")
(goto-char (point-min))
(while (search-forward "<b>" nil t)
(replace-match "\n"))
- (webmail-remove-markup)
- (webmail-decode-entities)
+ (nnweb-remove-markup)
+ (nnweb-decode-entities)
(goto-char (point-min))
(delete-blank-lines)
(goto-char (point-min))
(unless (search-forward "</TABLE>" nil t)
(error "Can't find end label (article@8)"))
(delete-region p (point))
- (let (bufname) ;; Attachment
+ (let (bufname);; Attachment
(save-excursion
(set-buffer (generate-new-buffer " *webmail-att*"))
(nnweb-insert (concat (car webmail-open-url) attachment))
(setq p (point))
(widen)))
(unless mime
- (narrow-to-region p (point-max))
- (setq mime (webmail-netaddress-single-part))
- (widen))
+ (narrow-to-region p (point-max))
+ (setq mime (webmail-netaddress-single-part))
+ (widen))
(goto-char (point-min))
;; Some blank line to seperate mails.
(insert "\n\nFrom nobody " (current-time-string) "\n")