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 "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-cookie-storage url-cookie-secure-storage
341 url-cookie-confirmation
344 (setq webmail-articles nil)
345 (when webmail-open-url
347 (webmail-url webmail-open-url))
348 (if webmail-open-snarf (funcall webmail-open-snarf))
349 (when webmail-login-url
351 (webmail-url webmail-login-url))
352 (if webmail-login-snarf
353 (funcall webmail-login-snarf))
354 (when webmail-list-url
356 (webmail-url webmail-list-url))
357 (if webmail-list-snarf
358 (funcall webmail-list-snarf))
359 (while (setq item (pop webmail-articles))
360 (message "Fetching mail #%d..." (setq n (1+ n)))
362 (mm-with-unibyte-current-buffer
363 (nnweb-insert (cdr item)))
365 (if webmail-article-snarf
366 (funcall webmail-article-snarf file id))
367 (when (and webmail-trash-url webmail-move-to-trash-can)
368 (message "Move mail #%d to trash can..." n)
371 (webmail-url webmail-trash-url)
373 (while (setq buf (pop webmail-buffer-list))
377 (while (setq buf (pop webmail-buffer-list))
380 (if webmail-post-process
381 (funcall webmail-post-process))))
383 (defun webmail-encode-8bit ()
384 (goto-char (point-min))
385 (skip-chars-forward "^\200-\377")
387 (insert (format "&%d;" (mm-char-int (char-after))))
389 (skip-chars-forward "^\200-\377")))
393 (defun webmail-hotmail-open ()
394 (goto-char (point-min))
395 (if (re-search-forward
396 "action=\"https?://\\([^/]+\\)/cgi-bin/dologin" nil t)
397 (setq webmail-aux (match-string 1))
398 (webmail-error "open@1")))
400 (defun webmail-hotmail-login ()
402 (goto-char (point-min))
403 (if (re-search-forward
404 "https?://\\([^/]+hotmail\\.msn\\.com\\)/cgi-bin/" nil t)
405 (setq site (match-string 1))
406 (webmail-error "login@1"))
407 (goto-char (point-min))
408 (if (re-search-forward
409 "\\(/cgi-bin/HoTMaiL\\?[^\"]*curmbox=ACTIVE[^\"]*\\)" nil t)
410 (setq webmail-aux (concat "http://" site (match-string 1)))
411 (webmail-error "login@2"))))
413 (defun webmail-hotmail-list ()
415 (goto-char (point-min))
416 (if (re-search-forward "[0-9]+ new" nil t)
417 (message "Found %s" (match-string 0))
418 (webmail-error "maybe your w3 version is too old"))
419 (goto-char (point-min))
420 (if (re-search-forward
421 "https?://\\([^/]+hotmail\\.msn\\.com\\)/cgi-bin/" nil t)
422 (setq site (match-string 1))
423 (webmail-error "list@1"))
424 (goto-char (point-min))
425 (if (re-search-forward "disk=\\([^&]+\\)&" nil t)
427 (concat "http://" site "/cgi-bin/HoTMaiL?disk="
429 (webmail-error "list@2"))
430 (goto-char (point-max))
431 (while (re-search-backward
432 "newmail\\.gif\\|href=\"\\(/cgi-bin/getmsg\\?[^\"]+\\)\""
434 (if (setq url (match-string 1))
436 (if (or newp (not webmail-newmail-only))
438 (if (string-match "msg=\\([^&]+\\)" url)
439 (setq id (match-string 1 url)))
440 (push (cons id (concat "http://" site url "&raw=0"))
445 ;; Thank victor@idaccr.org (Victor S. Miller) for raw=0
447 (defun webmail-hotmail-article (file id)
448 (goto-char (point-min))
449 (if (not (search-forward "<pre>" nil t))
450 (webmail-error "article@3"))
451 (skip-chars-forward "\n\r\t ")
452 (delete-region (point-min) (point))
453 (if (not (search-forward "</pre>" nil t))
454 (webmail-error "article@3.1"))
455 (delete-region (match-beginning 0) (point-max))
456 (nnweb-remove-markup)
457 (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
458 (nnweb-decode-entities))
459 (goto-char (point-min))
460 (while (re-search-forward "\r\n?" nil t)
461 (replace-match "\n"))
462 (goto-char (point-min))
464 (if (not (looking-at "\n*From "))
465 (insert "From nobody " (current-time-string) "\n"))
466 (mm-append-to-file (point-min) (point-max) file))
468 (defun webmail-hotmail-article-old (file id)
469 (let (p attachment count mime hotmail-direct)
471 (webmail-encode-8bit)
472 (goto-char (point-min))
473 (if (not (search-forward "<DIV>" nil t))
474 (if (not (search-forward "Reply All" nil t))
475 (webmail-error "article@1")
476 (setq hotmail-direct t))
477 (goto-char (match-beginning 0)))
478 (narrow-to-region (point-min) (point))
479 (if (not (search-backward "<table" nil t 2))
480 (webmail-error "article@1.1"))
481 (delete-region (point-min) (match-beginning 0))
482 (while (search-forward "<a href=" nil t)
483 (setq p (match-beginning 0))
484 (search-forward "</a>" nil t)
485 (delete-region p (match-end 0)))
486 (nnweb-remove-markup)
487 (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
488 (nnweb-decode-entities))
489 (goto-char (point-min))
491 (goto-char (point-min))
492 (when (search-forward "\n\n" nil t)
494 (delete-region (point) (point-max)))
495 (goto-char (point-max))
499 (while (re-search-forward
500 "<tt>\\|<div>\\|\\(http://[^/]+/cgi-bin/getmsg/\\([^\?]+\\)\?[^\"]*\\)\""
502 (if (setq attachment (match-string 1))
503 (let ((filename (match-string 2))
504 bufname);; Attachment
505 (delete-region p (match-end 0))
507 (set-buffer (generate-new-buffer " *webmail-att*"))
508 (nnweb-insert attachment)
509 (push (current-buffer) webmail-buffer-list)
510 (setq bufname (buffer-name)))
512 (insert "<#part type="
514 (string-match "\\.[^\\.]+$" filename)
515 (mailcap-extension-to-mime
516 (match-string 0 filename)))
517 "application/octet-stream"))
518 (insert " buffer=\"" bufname "\"")
519 (insert " filename=\"" filename "\"")
520 (insert " disposition=\"inline\"")
521 (insert "><#/part>\n")
523 (delete-region p (match-end 0))
525 (if (not (search-forward "</tt>" nil t))
526 (webmail-error "article@1.2")
527 (delete-region (match-beginning 0) (match-end 0)))
529 (while (and (> count 0)
530 (re-search-forward "</div>\\|\\(<div>\\)" nil t))
532 (setq count (1+ count))
533 (if (= (setq count (1- count)) 0)
534 (delete-region (match-beginning 0)
536 (narrow-to-region p (point))
537 (goto-char (point-min))
539 ((looking-at "<pre>")
540 (goto-char (match-end 0))
541 (if (looking-at "$") (forward-char))
542 (delete-region (point-min) (point))
543 (nnweb-remove-markup)
544 (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
545 (nnweb-decode-entities))
549 (insert "<#part type=\"text/html\" disposition=inline>")
550 (goto-char (point-max))
551 (insert "<#/part>")))
552 (goto-char (point-max))
555 (delete-region p (point-max))
556 (goto-char (point-min))
557 ;; Some blank line to seperate mails.
558 (insert "\n\nFrom nobody " (current-time-string) "\n")
560 (insert (format "Message-ID: <%s@hotmail.com>\n" id)))
561 (unless (looking-at "$")
562 (if (search-forward "\n\n" nil t)
564 (webmail-error "article@2")))
565 (narrow-to-region (point) (point-max))
567 (insert "MIME-Version: 1.0\n"
570 (delete-region (point-min) (point-max)))))
571 (goto-char (point-min))
573 (let (case-fold-search)
574 (while (re-search-forward "^From " nil t)
577 (mm-append-to-file (point-min) (point-max) file)))
581 (defun webmail-yahoo-open ()
582 (goto-char (point-min))
583 (if (re-search-forward "action=\"\\([^\"]+\\)\"" nil t)
584 (setq webmail-aux (match-string 1))
585 (webmail-error "open@1")))
587 (defun webmail-yahoo-login ()
588 (goto-char (point-min))
589 (if (re-search-forward "http://[^/]+[0-9]\\.mail\\.yahoo\\.com/" nil t)
590 (setq webmail-aux (match-string 0))
591 (webmail-error "login@1"))
592 (if (re-search-forward "YY=[0-9]+" nil t)
593 (setq webmail-aux (concat webmail-aux "ym/ShowFolder?"
595 (webmail-error "login@2")))
597 (defun webmail-yahoo-list ()
598 (let (url (newp t) (tofetch 0))
599 (goto-char (point-min))
600 (when (re-search-forward
601 "showing [0-9]+-\\([0-9]+\\) of \\([0-9]+\\)" nil t)
602 ;;(setq listed (match-string 1))
603 (message "Found %s mail(s)" (match-string 2)))
604 (if (string-match "http://[^/]+" webmail-aux)
605 (setq webmail-aux (match-string 0 webmail-aux))
606 (webmail-error "list@1"))
607 (goto-char (point-min))
608 (while (re-search-forward
609 "bgcolor=\"#eeeeee\"\\|href=\"\\(/ym/ShowLetter\\?MsgId=\\([^&]+\\)&[^\"]*\\)\""
611 (if (setq url (match-string 1))
613 (when (or newp (not webmail-newmail-only))
614 (push (cons (match-string 2) (concat webmail-aux url "&toc=1"))
616 (setq tofetch (1+ tofetch)))
619 (setq webmail-articles (nreverse webmail-articles))
620 (message "Fetching %d mail(s)" tofetch)))
622 (defun webmail-yahoo-article (file id)
625 (goto-char (point-min))
626 (if (not (search-forward "value=\"Done\"" nil t))
627 (webmail-error "article@1"))
628 (if (not (search-forward "<table" nil t))
629 (webmail-error "article@2"))
630 (delete-region (point-min) (match-beginning 0))
631 (if (not (search-forward "</table>" nil t))
632 (webmail-error "article@3"))
633 (narrow-to-region (point-min) (match-end 0))
634 (while (search-forward "<a href=" nil t)
635 (setq p (match-beginning 0))
636 (search-forward "</a>" nil t)
637 (delete-region p (match-end 0)))
638 (nnweb-remove-markup)
639 (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
640 (nnweb-decode-entities))
641 (goto-char (point-min))
643 (goto-char (point-max))
647 (while (re-search-forward "[^\"]*/ShowLetter/[^\?]+\?[^\"]*" nil t)
648 (setq attachment (match-string 0))
649 (let (bufname ct ctl cd description)
650 (if (not (search-forward "<table" nil t))
651 (webmail-error "article@4"))
652 (delete-region p (match-beginning 0))
653 (if (not (search-forward "</table>" nil t))
654 (webmail-error "article@5"))
655 (narrow-to-region p (match-end 0))
656 (nnweb-remove-markup)
657 (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
658 (nnweb-decode-entities))
659 (goto-char (point-min))
661 (setq ct (mail-fetch-field "content-type")
662 ctl (ignore-errors (mail-header-parse-content-type ct))
663 ;;cte (mail-fetch-field "content-transfer-encoding")
664 cd (mail-fetch-field "content-disposition")
665 description (mail-fetch-field "content-description")
666 id (mail-fetch-field "content-id"))
667 (delete-region (point-min) (point-max))
670 (set-buffer (generate-new-buffer " *webmail-att*"))
671 (nnweb-insert (concat webmail-aux attachment))
672 (push (current-buffer) webmail-buffer-list)
673 (setq bufname (buffer-name)))
675 (if (and ctl (not (equal (car ctl) "text/")))
676 (insert " type=\"" (car ctl) "\""))
677 (insert " buffer=\"" bufname "\"")
679 (insert " disposition=\"" cd "\""))
681 (insert " description=\"" description "\""))
682 (insert "><#/part>\n")
684 (delete-region p (point-max))
685 (goto-char (point-min))
686 ;; Some blank line to seperate mails.
687 (insert "\n\nFrom nobody " (current-time-string) "\n")
689 (insert (format "Message-ID: <%s@yahoo.com>\n" id)))
690 (unless (looking-at "$")
691 (if (search-forward "\n\n" nil t)
693 (webmail-error "article@2")))
694 (narrow-to-region (point) (point-max))
695 (insert "MIME-Version: 1.0\n"
698 (delete-region (point-min) (point-max))))
699 (goto-char (point-min))
701 (let (case-fold-search)
702 (while (re-search-forward "^From " nil t)
705 (mm-append-to-file (point-min) (point-max) file)))
709 (defun webmail-netscape-open ()
710 (goto-char (point-min))
711 (if (re-search-forward "login/hint\\?\\([^\"]+\\)\"" nil t)
712 (setq webmail-aux (match-string 1))
713 (webmail-error "open@1")))
715 (defun webmail-netaddress-open ()
716 (goto-char (point-min))
717 (if (re-search-forward "action=\"\\([^\"]+\\)\"" nil t)
718 (setq webmail-aux (concat (car webmail-open-url) (match-string 1)))
719 (webmail-error "open@1")))
721 (defun webmail-netaddress-login ()
722 (webmail-refresh-redirect)
723 (goto-char (point-min))
724 (if (re-search-forward "tpl/[^/]+/\\([^/]+\\)" nil t)
725 (setq webmail-session (match-string 1))
726 (webmail-error "login@1")))
728 (defun webmail-netaddress-list ()
729 (webmail-refresh-redirect)
731 (goto-char (point-min))
732 (when (re-search-forward
733 "(\\([0-9]+\\) unread, \\([0-9]+\\) total)" nil t)
734 (message "Found %s mail(s), %s unread"
735 (match-string 2) (match-string 1)))
736 (goto-char (point-min))
737 (while (re-search-forward
738 "MR\\[i\\]\\.R='\\([^']*\\)'\\|MR\\[i\\]\\.Q='\\([^']+\\)'" nil t)
739 (if (setq id (match-string 2))
742 (format "%s/tpl/Message/%s/Read?Q=%s&FolderID=-4&SortUseCase=True&Sort=Date&Headers=True"
743 (car webmail-article-url)
744 webmail-session id)))
745 (if (or (not webmail-newmail-only)
746 (equal (match-string 1) "True"))
747 (push item webmail-articles))))
748 (setq webmail-articles (nreverse webmail-articles))))
750 (defun webmail-netaddress-single-part ()
751 (goto-char (point-min))
753 ((looking-at "[\t\040\r\n]*<font face=[^>]+>[\t\040\r\n]*")
756 (while (re-search-forward "[\t\040\r\n]+" nil t)
758 (goto-char (point-min))
759 (while (re-search-forward "<br>" nil t)
760 (replace-match "\n"))
761 (nnweb-remove-markup)
762 (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
763 (nnweb-decode-entities))
766 (insert "<#part type=\"text/html\" disposition=inline>")
767 (goto-char (point-max))
771 (defun webmail-netaddress-article (file id)
772 (webmail-refresh-redirect)
773 (let (p p1 attachment count mime type)
775 (webmail-encode-8bit)
776 (goto-char (point-min))
777 (if (not (search-forward "Trash" nil t))
778 (webmail-error "article@1"))
779 (if (not (search-forward "<form>" nil t))
780 (webmail-error "article@2"))
781 (delete-region (point-min) (match-beginning 0))
782 (if (not (search-forward "</form>" nil t))
783 (webmail-error "article@3"))
784 (narrow-to-region (point-min) (match-end 0))
785 (goto-char (point-min))
786 (while (re-search-forward "[\040\t\r\n]+" nil t)
788 (goto-char (point-min))
789 (while (search-forward "<b>" nil t)
790 (replace-match "\n"))
791 (nnweb-remove-markup)
792 (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
793 (nnweb-decode-entities))
794 (goto-char (point-min))
796 (goto-char (point-min))
797 (while (re-search-forward "^\040+\\|\040+$" nil t)
799 (goto-char (point-min))
800 (while (re-search-forward "\040+" nil t)
802 (goto-char (point-max))
806 (unless (search-forward "<!-- Data -->" nil t)
807 (webmail-error "article@4"))
809 (delete-region p (point))
810 (goto-char (point-max))
811 (unless (re-search-backward
812 "[\040\t]*<br>[\040\t\r\n]*<br>[\040\t\r\n]*<form" p t)
813 (webmail-error "article@5"))
814 (delete-region (point) (point-max))
816 (while (search-forward
817 "<TABLE border=\"0\" WIDTH=\"98%\" cellpadding=0 cellspacing=0>"
820 (unless (search-forward "</TABLE>" nil t)
821 (webmail-error "article@6"))
823 (if (search-backward "<IMG " p t)
825 (unless (re-search-forward "HREF=\"\\(/tpl/Attachment/[^/]+/\\([^/]+/[^\?]+\\)[^\"]+\\)\"" p1 t)
826 (webmail-error "article@7"))
827 (setq attachment (match-string 1))
828 (setq type (match-string 2))
829 (unless (search-forward "</TABLE>" nil t)
830 (webmail-error "article@8"))
831 (delete-region p (point))
832 (let (bufname);; Attachment
834 (set-buffer (generate-new-buffer " *webmail-att*"))
835 (nnweb-insert (concat (car webmail-open-url) attachment))
836 (push (current-buffer) webmail-buffer-list)
837 (setq bufname (buffer-name)))
838 (insert "<#part type=" type)
839 (insert " buffer=\"" bufname "\"")
840 (insert " disposition=\"inline\"")
841 (insert "><#/part>\n")
847 "<TABLE border=\"0\" WIDTH=\"98%\" cellpadding=0 cellspacing=0>"
851 (webmail-netaddress-single-part)
852 (goto-char (point-max))
856 (narrow-to-region p (point-max))
857 (setq mime (webmail-netaddress-single-part))
859 (goto-char (point-min))
860 ;; Some blank line to seperate mails.
861 (insert "\n\nFrom nobody " (current-time-string) "\n")
863 (insert (format "Message-ID: <%s@%s>\n" id webmail-address)))
864 (unless (looking-at "$")
865 (if (search-forward "\n\n" nil t)
867 (webmail-error "article@2")))
869 (narrow-to-region (point-min) (point))
870 (goto-char (point-min))
872 (if (looking-at "MIME-Version\\|Content-Type")
873 (delete-region (point)
876 (if (re-search-forward "^[^ \t]" nil t)
877 (goto-char (match-beginning 0))
880 (goto-char (point-max))
882 (narrow-to-region (point) (point-max))
883 (insert "MIME-Version: 1.0\n"
886 (delete-region (point-min) (point-max))))
887 (goto-char (point-min))
889 (let (case-fold-search)
890 (while (re-search-forward "^From " nil t)
893 (mm-append-to-file (point-min) (point-max) file)))
895 (defun webmail-netscape-article (file id)
896 (let (p p1 attachment count mime type)
898 (webmail-encode-8bit)
899 (goto-char (point-min))
900 (if (not (search-forward "Trash" nil t))
901 (webmail-error "article@1"))
902 (if (not (search-forward "<form>" nil t))
903 (webmail-error "article@2"))
904 (delete-region (point-min) (match-beginning 0))
905 (if (not (search-forward "</form>" nil t))
906 (webmail-error "article@3"))
907 (narrow-to-region (point-min) (match-end 0))
908 (goto-char (point-min))
909 (while (re-search-forward "[\040\t\r\n]+" nil t)
911 (goto-char (point-min))
912 (while (re-search-forward "<a href=[^>]*>[^<]*</a>" nil t)
914 (goto-char (point-min))
915 (while (search-forward "<b>" nil t)
916 (replace-match "\n"))
917 (nnweb-remove-markup)
918 (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
919 (nnweb-decode-entities))
920 (goto-char (point-min))
922 (goto-char (point-min))
923 (while (re-search-forward "^\040+\\|\040+$" nil t)
925 (goto-char (point-min))
926 (while (re-search-forward "\040+" nil t)
928 (goto-char (point-max))
932 (unless (search-forward "<!-- Data -->" nil t)
933 (webmail-error "article@4"))
935 (delete-region p (point))
936 (goto-char (point-max))
937 (unless (re-search-backward
938 "<form name=\"Transfer2\"" p t)
939 (webmail-error "article@5"))
940 (delete-region (point) (point-max))
942 (while (search-forward
943 "<TABLE border=\"0\" WIDTH=\"98%\" cellpadding=0 cellspacing=0>"
946 (unless (search-forward "</TABLE>" nil t)
947 (webmail-error "article@6"))
949 (if (search-backward "<IMG " p t)
951 (unless (re-search-forward "HREF=\"\\(/tpl/Attachment/[^/]+/\\([^/]+/[^\?]+\\)[^\"]+\\)\"" p1 t)
952 (webmail-error "article@7"))
953 (setq attachment (match-string 1))
954 (setq type (match-string 2))
955 (unless (search-forward "</TABLE>" nil t)
956 (webmail-error "article@8"))
957 (delete-region p (point))
958 (let (bufname);; Attachment
960 (set-buffer (generate-new-buffer " *webmail-att*"))
961 (nnweb-insert (concat (car webmail-open-url) attachment))
962 (push (current-buffer) webmail-buffer-list)
963 (setq bufname (buffer-name)))
964 (insert "<#part type=" type)
965 (insert " buffer=\"" bufname "\"")
966 (insert " disposition=\"inline\"")
967 (insert "><#/part>\n")
973 "<TABLE border=\"0\" WIDTH=\"98%\" cellpadding=0 cellspacing=0>"
977 (webmail-netaddress-single-part)
978 (goto-char (point-max))
982 (narrow-to-region p (point-max))
983 (setq mime (webmail-netaddress-single-part))
985 (goto-char (point-min))
986 ;; Some blank line to seperate mails.
987 (insert "\n\nFrom nobody " (current-time-string) "\n")
989 (insert (format "Message-ID: <%s@%s>\n" id webmail-address)))
990 (unless (looking-at "$")
991 (if (search-forward "\n\n" nil t)
993 (webmail-error "article@2")))
995 (narrow-to-region (point-min) (point))
996 (goto-char (point-min))
998 (if (looking-at "MIME-Version\\|Content-Type")
999 (delete-region (point)
1002 (if (re-search-forward "^[^ \t]" nil t)
1003 (goto-char (match-beginning 0))
1006 (goto-char (point-max))
1008 (narrow-to-region (point) (point-max))
1009 (insert "MIME-Version: 1.0\n"
1012 (delete-region (point-min) (point-max))))
1013 (goto-char (point-min))
1015 (let (case-fold-search)
1016 (while (re-search-forward "^From " nil t)
1019 (mm-append-to-file (point-min) (point-max) file)))
1023 (defun webmail-my-deja-open ()
1024 (webmail-refresh-redirect)
1025 (goto-char (point-min))
1026 (if (re-search-forward "action=\"\\([^\"]+login_confirm\\.xp[^\"]*\\)\""
1028 (setq webmail-aux (match-string 1))
1029 (webmail-error "open@1")))
1031 (defun webmail-my-deja-list ()
1033 (goto-char (point-min))
1034 (when (re-search-forward
1035 "(\\([0-9]+\\) message(s), \\([0-9]+\\) new, \\([0-9]+\\) k )"
1037 (message "Found %s mail(s), %s unread, total size %s K"
1038 (match-string 1) (match-string 2) (match-string 3)))
1039 (goto-char (point-min))
1040 (while (re-search-forward
1041 "• \\|\\(http:[^\"]+\\)/display_seemesg\\.femail\\?docid=\\([^&\"]+\\)"
1043 (if (setq id (match-string 2))
1044 (when (or newp (not webmail-newmail-only))
1046 (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"
1047 (match-string 1) id))
1049 (setq webmail-aux (match-string 1))
1052 (setq webmail-articles (nreverse webmail-articles))))
1054 (defun webmail-my-deja-article (file id)
1056 (goto-char (point-min))
1057 (unless (re-search-forward "\\(http:[^\"]+/attachment/entire_message.txt[^\"]+\\)" nil t)
1058 (webmail-error "article@1"))
1059 (setq url (match-string 1))
1061 (mm-with-unibyte-current-buffer
1063 (goto-char (point-min))
1064 (while (search-forward "\r\n" nil t)
1065 (replace-match "\n"))
1066 (goto-char (point-min))
1067 (insert "\n\nFrom nobody " (current-time-string) "\n")
1068 (mm-append-to-file (point-min) (point-max) file)))
1072 ;;; webmail.el ends here