1 ;;; webmail.el --- interfacing with web mail
2 ;; Copyright (C) 1999, 2000 Free Software Foundation, Inc.
4 ;; Author: Shenghuo Zhu <zsh@cs.rochester.edu>
5 ;; Keywords: hotmail netaddress my-deja netscape
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published
11 ;; by the Free Software Foundation; either version 2, or (at your
12 ;; option) any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful, but
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 ;; General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
26 ;; Note: Now mail.yahoo.com provides POP3 service, the webmail
27 ;; fetching is not going to be supported.
29 ;; Note: You need to have `url' and `w3' installed for this backend to
30 ;; work. `w3' must be 4.0pre46+one-line-cookie patch or standalone
33 ;; Todo: To support more web mail servers.
36 ;; 1. Net@ddress may corrupt `X-Face'.
39 ;; Webmail is an experimental function, which means NO WARRANTY.
43 (eval-when-compile (require 'cl))
59 ;; Report failure to find w3 at load time if appropriate.
69 (defvar webmail-type-definition
71 ;; Hotmail hate other HTTP user agents and use one line cookie
72 (paranoid agent cookie post)
73 (address . "www.hotmail.com")
74 (open-url "http://www.hotmail.com/")
75 (open-snarf . webmail-hotmail-open)
76 ;; W3 hate redirect POST
78 "http://%s/cgi-bin/dologin?login=%s&passwd=%s&enter=Sign+in&sec=no&curmbox=ACTIVE&_lang=&js=yes&id=2&tw=-10000&beta="
79 webmail-aux user password)
80 (login-snarf . webmail-hotmail-login)
81 (list-url "%s" webmail-aux)
82 (list-snarf . webmail-hotmail-list)
83 (article-snarf . webmail-hotmail-article)
85 "%s&login=%s&f=33792&curmbox=ACTIVE&_lang=&foo=inbox&js=&page=&%s=on&_HMaction=MoveTo&tobox=trAsH&nullbox="
88 (paranoid agent cookie post)
89 (address . "mail.yahoo.com")
90 (open-url "http://mail.yahoo.com/")
91 (open-snarf . webmail-yahoo-open)
92 (login-url;; yahoo will not accept GET
95 ".tries=&.src=ym&.last=&promo=&.intl=&.bypass=&.partner=&.chkP=Y&.done=&login=%s&passwd=%s"
97 (login-snarf . webmail-yahoo-login)
98 (list-url "%s&rb=Inbox&YN=1" webmail-aux)
99 (list-snarf . webmail-yahoo-list)
100 (article-snarf . webmail-yahoo-article)
102 "%s/ym/ShowFolder?YY=52107&inc=50&order=down&sort=date&pos=0&box=Inbox&DEL=Delete&destBox=&Mid=%s&destBox2="
105 (paranoid cookie post)
106 (address . "www.netaddress.com")
107 (open-url "http://www.netaddress.com/")
108 (open-snarf . webmail-netaddress-open)
112 "LoginState=2&SuccessfulLogin=%%2Ftpl&NewServerName=www.netaddress.com&JavaScript=JavaScript1.2&DomainID=4&NA31site=classic.netaddress.com&NA31port=80&UserID=%s&passwd=%s"
114 (login-snarf . webmail-netaddress-login)
116 "http://www.netaddress.com/tpl/Mail/%s/List?FolderID=-4&SortUseCase=True"
118 (list-snarf . webmail-netaddress-list)
119 (article-url "http://www.netaddress.com/")
120 (article-snarf . webmail-netaddress-article)
122 "http://www.netaddress.com/tpl/Message/%s/Move?FolderID=-4&Q=%s&N=&Sort=Date&F=-1"
125 (paranoid cookie post agent)
126 (address . "webmail.netscape.com")
127 (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")
128 (open-snarf . webmail-netscape-open)
131 ("http://ureg.netscape.com/iiop/UReg2/login/loginform")
132 "%s&U2_USERNAME=%s&U2_PASSWORD=%s"
133 webmail-aux user password)
134 (login-snarf . webmail-netaddress-login)
136 "http://webmail.netscape.com/tpl/Mail/%s/List?FolderID=-4&SortUseCase=True"
138 (list-snarf . webmail-netaddress-list)
139 (article-url "http://webmail.netscape.com/")
140 (article-snarf . webmail-netscape-article)
142 "http://webmail.netscape.com/tpl/Message/%s/Move?FolderID=-4&Q=%s&N=&Sort=Date&F=-1"
145 (paranoid cookie post)
146 (address . "www.my-deja.com")
147 (open-url "http://www.my-deja.com/")
148 (open-snarf . webmail-my-deja-open)
152 "member_name=%s&pw=%s&go=&priv_opt_MyDeja99="
154 (list-url "http://www.deja.com/rg_gotomail.xp")
155 (list-snarf . webmail-my-deja-list)
156 (article-snarf . webmail-my-deja-article)
158 "%s/gmm_multiplex.femail?%%2Fgmm_domovemesg_top.femail=Move+to%%3A&folder_top=%s%%3Azzz%%3A%%7E6trash%%3AF%%3A0&docid=%s"
159 webmail-aux user id))))
161 (defvar webmail-variables
162 '(address article-snarf article-url list-snarf list-url
163 login-url login-snarf open-url open-snarf site articles
164 post-process paranoid trash-url))
166 (defconst webmail-version "webmail 1.0")
168 (defvar webmail-newmail-only nil
169 "Only fetch new mails.")
171 (defvar webmail-move-to-trash-can t
172 "Move mail to trash can after fetch it.")
174 ;;; Internal variables
176 (defvar webmail-address nil)
177 (defvar webmail-paranoid nil)
178 (defvar webmail-aux nil)
179 (defvar webmail-session nil)
180 (defvar webmail-article-snarf nil)
181 (defvar webmail-article-url nil)
182 (defvar webmail-list-snarf nil)
183 (defvar webmail-list-url nil)
184 (defvar webmail-login-url nil)
185 (defvar webmail-login-snarf nil)
186 (defvar webmail-open-snarf nil)
187 (defvar webmail-open-url nil)
188 (defvar webmail-trash-url nil)
189 (defvar webmail-articles nil)
190 (defvar webmail-post-process nil)
192 (defvar webmail-buffer nil)
193 (defvar webmail-buffer-list nil)
195 (defvar webmail-type nil)
197 (defvar webmail-error-function nil)
199 (defvar webmail-debug-file "~/.emacs-webmail-debug")
201 ;;; Interface functions
203 (defun webmail-debug (str)
205 (insert "\n---------------- A bug at " str " ------------------\n")
206 (mapcar #'(lambda (sym)
208 (pp `(setq ,sym ',(eval sym)) (current-buffer))))
209 '(webmail-type user))
210 (insert "---------------- webmail buffer ------------------\n\n")
211 (insert-buffer-substring webmail-buffer)
212 (insert "\n---------------- end of buffer ------------------\n\n")
213 (append-to-file (point-min) (point-max) webmail-debug-file)))
215 (defun webmail-error (str)
216 (if webmail-error-function
217 (funcall webmail-error-function str))
218 (message "%s HTML has changed; please get a new version of webmail (%s)"
220 (error "%s HTML has changed; please get a new version of webmail (%s)"
223 (defun webmail-setdefault (type)
224 (let ((type-def (cdr (assq type webmail-type-definition)))
225 (vars webmail-variables)
227 (setq webmail-type type)
229 (if (setq pair (assq var type-def))
230 (set (intern (concat "webmail-" (symbol-name var))) (cdr pair))
231 (set (intern (concat "webmail-" (symbol-name var))) nil)))))
233 (defun webmail-encode-www-form-urlencoded (pairs)
234 "Return PAIRS encoded for forms."
238 (concat (w3-form-encode-xwfu (car data)) "="
239 (w3-form-encode-xwfu (cdr data)))))
242 (defun webmail-fetch-simple (url content)
243 (let ((url-request-data content)
244 (url-request-method "POST")
245 (url-request-extra-headers
246 '(("Content-type" . "application/x-www-form-urlencoded"))))
250 (defun webmail-fetch-form (url pairs)
251 (let ((url-request-data (webmail-encode-www-form-urlencoded pairs))
252 (url-request-method "POST")
253 (url-request-extra-headers
254 '(("Content-type" . "application/x-www-form-urlencoded"))))
258 (defun webmail-eval (expr)
261 (cons (webmail-eval (car expr)) (webmail-eval (cdr expr))))
267 (defun webmail-url (xurl)
268 (mm-with-unibyte-current-buffer
270 ((eq (car xurl) 'content)
272 (webmail-fetch-simple (if (stringp (car xurl))
274 (apply 'format (webmail-eval (car xurl))))
275 (apply 'format (webmail-eval (cdr xurl)))))
276 ((eq (car xurl) 'post)
278 (webmail-fetch-form (car xurl) (webmail-eval (cdr xurl))))
280 (nnweb-insert (apply 'format (webmail-eval xurl)))))))
282 (defun webmail-init ()
283 "Initialize buffers and such."
284 (if (gnus-buffer-live-p webmail-buffer)
285 (set-buffer webmail-buffer)
288 (nnheader-set-temp-buffer " *webmail*")))))
290 (defvar url-package-name)
291 (defvar url-package-version)
292 (defvar url-cookie-multiple-line)
293 (defvar url-confirmation-func)
295 ;; Hack W3 POST redirect. See `url-parse-mime-headers'.
297 ;; Netscape uses "GET" as redirect method when orignal method is POST
298 ;; and status is 302, .i.e no security risks by default without
301 ;; Some web servers (at least Apache used by yahoo) return status 302
302 ;; instead of 303, though they mean 303.
304 (defun webmail-url-confirmation-func (prompt)
306 ((equal prompt (concat "Honor redirection with non-GET method "
307 "(possible security risks)? "))
309 ((equal prompt "Continue (with method of GET)? ")
313 (defun webmail-refresh-redirect ()
314 "Redirect refresh url in META."
315 (goto-char (point-min))
316 (while (re-search-forward
317 "<meta[ \t\r\n]*http-equiv=\"Refresh\"[^>]*URL=\\([^\"]+\\)\""
319 (let ((url (match-string 1)))
321 (mm-with-unibyte-current-buffer
323 (goto-char (point-min))))
325 (defun webmail-fetch (file subtype user password)
327 (webmail-setdefault subtype)
328 (let ((url-package-name (if (memq 'agent webmail-paranoid)
331 (url-package-version (if (memq 'agent webmail-paranoid)
333 url-package-version))
334 (url-cookie-multiple-line (if (memq 'cookie webmail-paranoid)
336 url-cookie-multiple-line))
337 (url-confirmation-func (if (memq 'post webmail-paranoid)
338 'webmail-url-confirmation-func
339 url-confirmation-func))
340 (url-http-silence-on-insecure-redirection t)
341 url-cookie-storage url-cookie-secure-storage
342 url-cookie-confirmation
345 (setq webmail-articles nil)
346 (when webmail-open-url
348 (webmail-url webmail-open-url))
349 (if webmail-open-snarf (funcall webmail-open-snarf))
350 (when webmail-login-url
352 (webmail-url webmail-login-url))
353 (if webmail-login-snarf
354 (funcall webmail-login-snarf))
355 (when webmail-list-url
357 (webmail-url webmail-list-url))
358 (if webmail-list-snarf
359 (funcall webmail-list-snarf))
360 (while (setq item (pop webmail-articles))
361 (message "Fetching mail #%d..." (setq n (1+ n)))
363 (mm-with-unibyte-current-buffer
364 (nnweb-insert (cdr item)))
366 (if webmail-article-snarf
367 (funcall webmail-article-snarf file id))
368 (when (and webmail-trash-url webmail-move-to-trash-can)
369 (message "Move mail #%d to trash can..." n)
372 (webmail-url webmail-trash-url)
374 (while (setq buf (pop webmail-buffer-list))
378 (while (setq buf (pop webmail-buffer-list))
381 (if webmail-post-process
382 (funcall webmail-post-process))))
384 (defun webmail-encode-8bit ()
385 (goto-char (point-min))
386 (skip-chars-forward "^\200-\377")
388 (insert (format "&%d;" (mm-char-int (char-after))))
390 (skip-chars-forward "^\200-\377")))
394 (defun webmail-hotmail-open ()
395 (goto-char (point-min))
396 (if (re-search-forward
397 "action=\"https?://\\([^/]+\\)/cgi-bin/dologin" nil t)
398 (setq webmail-aux (match-string 1))
399 (webmail-error "open@1")))
401 (defun webmail-hotmail-login ()
403 (goto-char (point-min))
404 (if (re-search-forward
405 "https?://\\([^/]+hotmail\\.msn\\.com\\)/cgi-bin/" nil t)
406 (setq site (match-string 1))
407 (webmail-error "login@1"))
408 (goto-char (point-min))
409 (if (re-search-forward
410 "\\(/cgi-bin/HoTMaiL\\?[^\"]*curmbox=ACTIVE[^\"]*\\)" nil t)
411 (setq webmail-aux (concat "http://" site (match-string 1)))
412 (webmail-error "login@2"))))
414 (defun webmail-hotmail-list ()
416 (goto-char (point-min))
417 (if (re-search-forward "[0-9]+ new" nil t)
418 (message "Found %s" (match-string 0))
419 (webmail-error "maybe your w3 version is too old"))
420 (goto-char (point-min))
421 (if (re-search-forward
422 "https?://\\([^/]+hotmail\\.msn\\.com\\)/cgi-bin/" nil t)
423 (setq site (match-string 1))
424 (webmail-error "list@1"))
425 (goto-char (point-min))
426 (if (re-search-forward "disk=\\([^&]+\\)&" nil t)
428 (concat "http://" site "/cgi-bin/HoTMaiL?disk="
430 (webmail-error "list@2"))
431 (goto-char (point-max))
432 (while (re-search-backward
433 "newmail\\.gif\\|href=\"\\(/cgi-bin/getmsg\\?[^\"]+\\)\""
435 (if (setq url (match-string 1))
437 (if (or newp (not webmail-newmail-only))
439 (if (string-match "msg=\\([^&]+\\)" url)
440 (setq id (match-string 1 url)))
441 (push (cons id (concat "http://" site url "&raw=0"))
446 ;; Thank victor@idaccr.org (Victor S. Miller) for raw=0
448 (defun webmail-hotmail-article (file id)
449 (goto-char (point-min))
450 (if (not (search-forward "<pre>" nil t))
451 (webmail-error "article@3"))
452 (skip-chars-forward "\n\r\t ")
453 (delete-region (point-min) (point))
454 (if (not (search-forward "</pre>" nil t))
455 (webmail-error "article@3.1"))
456 (delete-region (match-beginning 0) (point-max))
457 (nnweb-remove-markup)
458 (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
459 (nnweb-decode-entities))
460 (goto-char (point-min))
461 (while (re-search-forward "\r\n?" nil t)
462 (replace-match "\n"))
463 (goto-char (point-min))
465 (if (not (looking-at "\n*From "))
466 (insert "From nobody " (current-time-string) "\n"))
467 (mm-append-to-file (point-min) (point-max) file))
469 (defun webmail-hotmail-article-old (file id)
470 (let (p attachment count mime hotmail-direct)
472 (webmail-encode-8bit)
473 (goto-char (point-min))
474 (if (not (search-forward "<DIV>" nil t))
475 (if (not (search-forward "Reply All" nil t))
476 (webmail-error "article@1")
477 (setq hotmail-direct t))
478 (goto-char (match-beginning 0)))
479 (narrow-to-region (point-min) (point))
480 (if (not (search-backward "<table" nil t 2))
481 (webmail-error "article@1.1"))
482 (delete-region (point-min) (match-beginning 0))
483 (while (search-forward "<a href=" nil t)
484 (setq p (match-beginning 0))
485 (search-forward "</a>" nil t)
486 (delete-region p (match-end 0)))
487 (nnweb-remove-markup)
488 (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
489 (nnweb-decode-entities))
490 (goto-char (point-min))
492 (goto-char (point-min))
493 (when (search-forward "\n\n" nil t)
495 (delete-region (point) (point-max)))
496 (goto-char (point-max))
500 (while (re-search-forward
501 "<tt>\\|<div>\\|\\(http://[^/]+/cgi-bin/getmsg/\\([^\?]+\\)\?[^\"]*\\)\""
503 (if (setq attachment (match-string 1))
504 (let ((filename (match-string 2))
505 bufname);; Attachment
506 (delete-region p (match-end 0))
508 (set-buffer (generate-new-buffer " *webmail-att*"))
509 (nnweb-insert attachment)
510 (push (current-buffer) webmail-buffer-list)
511 (setq bufname (buffer-name)))
513 (insert "<#part type="
515 (string-match "\\.[^\\.]+$" filename)
516 (mailcap-extension-to-mime
517 (match-string 0 filename)))
518 "application/octet-stream"))
519 (insert " buffer=\"" bufname "\"")
520 (insert " filename=\"" filename "\"")
521 (insert " disposition=\"inline\"")
522 (insert "><#/part>\n")
524 (delete-region p (match-end 0))
526 (if (not (search-forward "</tt>" nil t))
527 (webmail-error "article@1.2")
528 (delete-region (match-beginning 0) (match-end 0)))
530 (while (and (> count 0)
531 (re-search-forward "</div>\\|\\(<div>\\)" nil t))
533 (setq count (1+ count))
534 (if (= (setq count (1- count)) 0)
535 (delete-region (match-beginning 0)
537 (narrow-to-region p (point))
538 (goto-char (point-min))
540 ((looking-at "<pre>")
541 (goto-char (match-end 0))
542 (if (looking-at "$") (forward-char))
543 (delete-region (point-min) (point))
544 (nnweb-remove-markup)
545 (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
546 (nnweb-decode-entities))
550 (insert "<#part type=\"text/html\" disposition=inline>")
551 (goto-char (point-max))
552 (insert "<#/part>")))
553 (goto-char (point-max))
556 (delete-region p (point-max))
557 (goto-char (point-min))
558 ;; Some blank line to seperate mails.
559 (insert "\n\nFrom nobody " (current-time-string) "\n")
561 (insert (format "Message-ID: <%s@hotmail.com>\n" id)))
562 (unless (looking-at "$")
563 (if (search-forward "\n\n" nil t)
565 (webmail-error "article@2")))
566 (narrow-to-region (point) (point-max))
568 (insert "MIME-Version: 1.0\n"
571 (delete-region (point-min) (point-max)))))
572 (goto-char (point-min))
574 (let (case-fold-search)
575 (while (re-search-forward "^From " nil t)
578 (mm-append-to-file (point-min) (point-max) file)))
582 (defun webmail-yahoo-open ()
583 (goto-char (point-min))
584 (if (re-search-forward "action=\"\\([^\"]+\\)\"" nil t)
585 (setq webmail-aux (match-string 1))
586 (webmail-error "open@1")))
588 (defun webmail-yahoo-login ()
589 (goto-char (point-min))
590 (if (re-search-forward "http://[^/]+[0-9]\\.mail\\.yahoo\\.com/" nil t)
591 (setq webmail-aux (match-string 0))
592 (webmail-error "login@1"))
593 (if (re-search-forward "YY=[0-9]+" nil t)
594 (setq webmail-aux (concat webmail-aux "ym/ShowFolder?"
596 (webmail-error "login@2")))
598 (defun webmail-yahoo-list ()
599 (let (url (newp t) (tofetch 0))
600 (goto-char (point-min))
601 (when (re-search-forward
602 "showing [0-9]+-\\([0-9]+\\) of \\([0-9]+\\)" nil t)
603 ;;(setq listed (match-string 1))
604 (message "Found %s mail(s)" (match-string 2)))
605 (if (string-match "http://[^/]+" webmail-aux)
606 (setq webmail-aux (match-string 0 webmail-aux))
607 (webmail-error "list@1"))
608 (goto-char (point-min))
609 (while (re-search-forward
610 "bgcolor=\"#eeeeee\"\\|href=\"\\(/ym/ShowLetter\\?MsgId=\\([^&]+\\)&[^\"]*\\)\""
612 (if (setq url (match-string 1))
614 (when (or newp (not webmail-newmail-only))
615 (push (cons (match-string 2) (concat webmail-aux url "&toc=1"))
617 (setq tofetch (1+ tofetch)))
620 (setq webmail-articles (nreverse webmail-articles))
621 (message "Fetching %d mail(s)" tofetch)))
623 (defun webmail-yahoo-article (file id)
626 (goto-char (point-min))
627 (if (not (search-forward "value=\"Done\"" nil t))
628 (webmail-error "article@1"))
629 (if (not (search-forward "<table" nil t))
630 (webmail-error "article@2"))
631 (delete-region (point-min) (match-beginning 0))
632 (if (not (search-forward "</table>" nil t))
633 (webmail-error "article@3"))
634 (narrow-to-region (point-min) (match-end 0))
635 (while (search-forward "<a href=" nil t)
636 (setq p (match-beginning 0))
637 (search-forward "</a>" nil t)
638 (delete-region p (match-end 0)))
639 (nnweb-remove-markup)
640 (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
641 (nnweb-decode-entities))
642 (goto-char (point-min))
644 (goto-char (point-max))
648 (while (re-search-forward "[^\"]*/ShowLetter/[^\?]+\?[^\"]*" nil t)
649 (setq attachment (match-string 0))
650 (let (bufname ct ctl cd description)
651 (if (not (search-forward "<table" nil t))
652 (webmail-error "article@4"))
653 (delete-region p (match-beginning 0))
654 (if (not (search-forward "</table>" nil t))
655 (webmail-error "article@5"))
656 (narrow-to-region p (match-end 0))
657 (nnweb-remove-markup)
658 (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
659 (nnweb-decode-entities))
660 (goto-char (point-min))
662 (setq ct (mail-fetch-field "content-type")
663 ctl (ignore-errors (mail-header-parse-content-type ct))
664 ;;cte (mail-fetch-field "content-transfer-encoding")
665 cd (mail-fetch-field "content-disposition")
666 description (mail-fetch-field "content-description")
667 id (mail-fetch-field "content-id"))
668 (delete-region (point-min) (point-max))
671 (set-buffer (generate-new-buffer " *webmail-att*"))
672 (nnweb-insert (concat webmail-aux attachment))
673 (push (current-buffer) webmail-buffer-list)
674 (setq bufname (buffer-name)))
676 (if (and ctl (not (equal (car ctl) "text/")))
677 (insert " type=\"" (car ctl) "\""))
678 (insert " buffer=\"" bufname "\"")
680 (insert " disposition=\"" cd "\""))
682 (insert " description=\"" description "\""))
683 (insert "><#/part>\n")
685 (delete-region p (point-max))
686 (goto-char (point-min))
687 ;; Some blank line to seperate mails.
688 (insert "\n\nFrom nobody " (current-time-string) "\n")
690 (insert (format "Message-ID: <%s@yahoo.com>\n" id)))
691 (unless (looking-at "$")
692 (if (search-forward "\n\n" nil t)
694 (webmail-error "article@2")))
695 (narrow-to-region (point) (point-max))
696 (insert "MIME-Version: 1.0\n"
699 (delete-region (point-min) (point-max))))
700 (goto-char (point-min))
702 (let (case-fold-search)
703 (while (re-search-forward "^From " nil t)
706 (mm-append-to-file (point-min) (point-max) file)))
710 (defun webmail-netscape-open ()
711 (goto-char (point-min))
712 (if (re-search-forward "login/hint\\?\\([^\"]+\\)\"" nil t)
713 (setq webmail-aux (match-string 1))
714 (webmail-error "open@1")))
716 (defun webmail-netaddress-open ()
717 (goto-char (point-min))
718 (if (re-search-forward "action=\"\\([^\"]+\\)\"" nil t)
719 (setq webmail-aux (concat (car webmail-open-url) (match-string 1)))
720 (webmail-error "open@1")))
722 (defun webmail-netaddress-login ()
723 (webmail-refresh-redirect)
724 (goto-char (point-min))
725 (if (re-search-forward "tpl/[^/]+/\\([^/]+\\)" nil t)
726 (setq webmail-session (match-string 1))
727 (webmail-error "login@1")))
729 (defun webmail-netaddress-list ()
730 (webmail-refresh-redirect)
732 (goto-char (point-min))
733 (when (re-search-forward
734 "(\\([0-9]+\\) unread, \\([0-9]+\\) total)" nil t)
735 (message "Found %s mail(s), %s unread"
736 (match-string 2) (match-string 1)))
737 (goto-char (point-min))
738 (while (re-search-forward
739 "MR\\[i\\]\\.R='\\([^']*\\)'\\|MR\\[i\\]\\.Q='\\([^']+\\)'" nil t)
740 (if (setq id (match-string 2))
743 (format "%s/tpl/Message/%s/Read?Q=%s&FolderID=-4&SortUseCase=True&Sort=Date&Headers=True"
744 (car webmail-article-url)
745 webmail-session id)))
746 (if (or (not webmail-newmail-only)
747 (equal (match-string 1) "True"))
748 (push item webmail-articles))))
749 (setq webmail-articles (nreverse webmail-articles))))
751 (defun webmail-netaddress-single-part ()
752 (goto-char (point-min))
754 ((looking-at "[\t\040\r\n]*<font face=[^>]+>[\t\040\r\n]*")
757 (while (re-search-forward "[\t\040\r\n]+" nil t)
759 (goto-char (point-min))
760 (while (re-search-forward "<br>" nil t)
761 (replace-match "\n"))
762 (nnweb-remove-markup)
763 (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
764 (nnweb-decode-entities))
767 (insert "<#part type=\"text/html\" disposition=inline>")
768 (goto-char (point-max))
772 (defun webmail-netaddress-article (file id)
773 (webmail-refresh-redirect)
774 (let (p p1 attachment count mime type)
776 (webmail-encode-8bit)
777 (goto-char (point-min))
778 (if (not (search-forward "Trash" nil t))
779 (webmail-error "article@1"))
780 (if (not (search-forward "<form>" nil t))
781 (webmail-error "article@2"))
782 (delete-region (point-min) (match-beginning 0))
783 (if (not (search-forward "</form>" nil t))
784 (webmail-error "article@3"))
785 (narrow-to-region (point-min) (match-end 0))
786 (goto-char (point-min))
787 (while (re-search-forward "[\040\t\r\n]+" nil t)
789 (goto-char (point-min))
790 (while (search-forward "<b>" nil t)
791 (replace-match "\n"))
792 (nnweb-remove-markup)
793 (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
794 (nnweb-decode-entities))
795 (goto-char (point-min))
797 (goto-char (point-min))
798 (while (re-search-forward "^\040+\\|\040+$" nil t)
800 (goto-char (point-min))
801 (while (re-search-forward "\040+" nil t)
803 (goto-char (point-max))
807 (unless (search-forward "<!-- Data -->" nil t)
808 (webmail-error "article@4"))
810 (delete-region p (point))
811 (goto-char (point-max))
812 (unless (re-search-backward
813 "[\040\t]*<br>[\040\t\r\n]*<br>[\040\t\r\n]*<form" p t)
814 (webmail-error "article@5"))
815 (delete-region (point) (point-max))
817 (while (search-forward
818 "<TABLE border=\"0\" WIDTH=\"98%\" cellpadding=0 cellspacing=0>"
821 (unless (search-forward "</TABLE>" nil t)
822 (webmail-error "article@6"))
824 (if (search-backward "<IMG " p t)
826 (unless (re-search-forward "HREF=\"\\(/tpl/Attachment/[^/]+/\\([^/]+/[^\?]+\\)[^\"]+\\)\"" p1 t)
827 (webmail-error "article@7"))
828 (setq attachment (match-string 1))
829 (setq type (match-string 2))
830 (unless (search-forward "</TABLE>" nil t)
831 (webmail-error "article@8"))
832 (delete-region p (point))
833 (let (bufname);; Attachment
835 (set-buffer (generate-new-buffer " *webmail-att*"))
836 (nnweb-insert (concat (car webmail-open-url) attachment))
837 (push (current-buffer) webmail-buffer-list)
838 (setq bufname (buffer-name)))
839 (insert "<#part type=" type)
840 (insert " buffer=\"" bufname "\"")
841 (insert " disposition=\"inline\"")
842 (insert "><#/part>\n")
848 "<TABLE border=\"0\" WIDTH=\"98%\" cellpadding=0 cellspacing=0>"
852 (webmail-netaddress-single-part)
853 (goto-char (point-max))
857 (narrow-to-region p (point-max))
858 (setq mime (webmail-netaddress-single-part))
860 (goto-char (point-min))
861 ;; Some blank line to seperate mails.
862 (insert "\n\nFrom nobody " (current-time-string) "\n")
864 (insert (format "Message-ID: <%s@%s>\n" id webmail-address)))
865 (unless (looking-at "$")
866 (if (search-forward "\n\n" nil t)
868 (webmail-error "article@2")))
870 (narrow-to-region (point-min) (point))
871 (goto-char (point-min))
873 (if (looking-at "MIME-Version\\|Content-Type")
874 (delete-region (point)
877 (if (re-search-forward "^[^ \t]" nil t)
878 (goto-char (match-beginning 0))
881 (goto-char (point-max))
883 (narrow-to-region (point) (point-max))
884 (insert "MIME-Version: 1.0\n"
887 (delete-region (point-min) (point-max))))
888 (goto-char (point-min))
890 (let (case-fold-search)
891 (while (re-search-forward "^From " nil t)
894 (mm-append-to-file (point-min) (point-max) file)))
896 (defun webmail-netscape-article (file id)
897 (let (p p1 attachment count mime type)
899 (webmail-encode-8bit)
900 (goto-char (point-min))
901 (if (not (search-forward "Trash" nil t))
902 (webmail-error "article@1"))
903 (if (not (search-forward "<form>" nil t))
904 (webmail-error "article@2"))
905 (delete-region (point-min) (match-beginning 0))
906 (if (not (search-forward "</form>" nil t))
907 (webmail-error "article@3"))
908 (narrow-to-region (point-min) (match-end 0))
909 (goto-char (point-min))
910 (while (re-search-forward "[\040\t\r\n]+" nil t)
912 (goto-char (point-min))
913 (while (re-search-forward "<a href=[^>]*>[^<]*</a>" nil t)
915 (goto-char (point-min))
916 (while (search-forward "<b>" nil t)
917 (replace-match "\n"))
918 (nnweb-remove-markup)
919 (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
920 (nnweb-decode-entities))
921 (goto-char (point-min))
923 (goto-char (point-min))
924 (while (re-search-forward "^\040+\\|\040+$" nil t)
926 (goto-char (point-min))
927 (while (re-search-forward "\040+" nil t)
929 (goto-char (point-max))
933 (unless (search-forward "<!-- Data -->" nil t)
934 (webmail-error "article@4"))
936 (delete-region p (point))
937 (goto-char (point-max))
938 (unless (re-search-backward
939 "<form name=\"Transfer2\"" p t)
940 (webmail-error "article@5"))
941 (delete-region (point) (point-max))
943 (while (search-forward
944 "<TABLE border=\"0\" WIDTH=\"98%\" cellpadding=0 cellspacing=0>"
947 (unless (search-forward "</TABLE>" nil t)
948 (webmail-error "article@6"))
950 (if (search-backward "<IMG " p t)
952 (unless (re-search-forward "HREF=\"\\(/tpl/Attachment/[^/]+/\\([^/]+/[^\?]+\\)[^\"]+\\)\"" p1 t)
953 (webmail-error "article@7"))
954 (setq attachment (match-string 1))
955 (setq type (match-string 2))
956 (unless (search-forward "</TABLE>" nil t)
957 (webmail-error "article@8"))
958 (delete-region p (point))
959 (let (bufname);; Attachment
961 (set-buffer (generate-new-buffer " *webmail-att*"))
962 (nnweb-insert (concat (car webmail-open-url) attachment))
963 (push (current-buffer) webmail-buffer-list)
964 (setq bufname (buffer-name)))
965 (insert "<#part type=" type)
966 (insert " buffer=\"" bufname "\"")
967 (insert " disposition=\"inline\"")
968 (insert "><#/part>\n")
974 "<TABLE border=\"0\" WIDTH=\"98%\" cellpadding=0 cellspacing=0>"
978 (webmail-netaddress-single-part)
979 (goto-char (point-max))
983 (narrow-to-region p (point-max))
984 (setq mime (webmail-netaddress-single-part))
986 (goto-char (point-min))
987 ;; Some blank line to seperate mails.
988 (insert "\n\nFrom nobody " (current-time-string) "\n")
990 (insert (format "Message-ID: <%s@%s>\n" id webmail-address)))
991 (unless (looking-at "$")
992 (if (search-forward "\n\n" nil t)
994 (webmail-error "article@2")))
996 (narrow-to-region (point-min) (point))
997 (goto-char (point-min))
999 (if (looking-at "MIME-Version\\|Content-Type")
1000 (delete-region (point)
1003 (if (re-search-forward "^[^ \t]" nil t)
1004 (goto-char (match-beginning 0))
1007 (goto-char (point-max))
1009 (narrow-to-region (point) (point-max))
1010 (insert "MIME-Version: 1.0\n"
1013 (delete-region (point-min) (point-max))))
1014 (goto-char (point-min))
1016 (let (case-fold-search)
1017 (while (re-search-forward "^From " nil t)
1020 (mm-append-to-file (point-min) (point-max) file)))
1024 (defun webmail-my-deja-open ()
1025 (webmail-refresh-redirect)
1026 (goto-char (point-min))
1027 (if (re-search-forward "action=\"\\([^\"]+login_confirm\\.xp[^\"]*\\)\""
1029 (setq webmail-aux (match-string 1))
1030 (webmail-error "open@1")))
1032 (defun webmail-my-deja-list ()
1034 (goto-char (point-min))
1035 (when (re-search-forward
1036 "(\\([0-9]+\\) message(s), \\([0-9]+\\) new, \\([0-9]+\\) k )"
1038 (message "Found %s mail(s), %s unread, total size %s K"
1039 (match-string 1) (match-string 2) (match-string 3)))
1040 (goto-char (point-min))
1041 (while (re-search-forward
1042 "• \\|\\(http:[^\"]+\\)/display_seemesg\\.femail\\?docid=\\([^&\"]+\\)"
1044 (if (setq id (match-string 2))
1045 (when (or newp (not webmail-newmail-only))
1047 (cons id (format "%s/gmm_multiplex.femail?docid=%s&femail_page_name=display_page&bool_next_on_disp_pg=true&bool_prev_on_disp_pg=false&display_all_headers=false&%%2Fgmm_save.femail=Download&femail_page_name=display_page&bool_next_on_disp_pg=true&bool_prev_on_disp_pg=false&display_all_headers=false"
1048 (match-string 1) id))
1050 (setq webmail-aux (match-string 1))
1053 (setq webmail-articles (nreverse webmail-articles))))
1055 (defun webmail-my-deja-article (file id)
1057 (goto-char (point-min))
1058 (unless (re-search-forward "\\(http:[^\"]+/attachment/entire_message.txt[^\"]+\\)" nil t)
1059 (webmail-error "article@1"))
1060 (setq url (match-string 1))
1062 (mm-with-unibyte-current-buffer
1064 (goto-char (point-min))
1065 (while (search-forward "\r\n" nil t)
1066 (replace-match "\n"))
1067 (goto-char (point-min))
1068 (insert "\n\nFrom nobody " (current-time-string) "\n")
1069 (mm-append-to-file (point-min) (point-max) file)))
1073 ;;; webmail.el ends here