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: You need to have `url' and `w3' installed for this backend to
27 ;; work. `w3' must be 4.0pre46+one-line-cookie patch or standalone
30 ;; Todo: To support more web mail servers.
33 ;; 1. Net@ddress may corrupt `X-Face'.
36 ;; Webmail is an experimental function, which means NO WARRANTY.
40 (eval-when-compile (require 'cl))
56 ;; Report failure to find w3 at load time if appropriate.
66 (defvar webmail-type-definition
68 ;; Hotmail hate other HTTP user agents and use one line cookie
69 (paranoid agent cookie post)
70 (address . "www.hotmail.com")
71 (open-url "http://www.hotmail.com/")
72 (open-snarf . webmail-hotmail-open)
73 ;; W3 hate redirect POST
75 "http://%s/cgi-bin/dologin?login=%s&passwd=%s&enter=Sign+in&sec=no&curmbox=ACTIVE&_lang=&js=yes&id=2&tw=-10000&beta="
76 webmail-aux user password)
77 (login-snarf . webmail-hotmail-login)
78 (list-url "%s" webmail-aux)
79 (list-snarf . webmail-hotmail-list)
80 (article-snarf . webmail-hotmail-article)
82 "%s&login=%s&f=33792&curmbox=ACTIVE&_lang=&foo=inbox&js=&page=&%s=on&_HMaction=MoveTo&tobox=trAsH&nullbox="
85 (paranoid cookie post)
86 (address . "mail.yahoo.com")
87 (open-url "http://mail.yahoo.com/")
88 (open-snarf . webmail-yahoo-open)
89 (login-url;; yahoo will not accept GET
92 ".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"
94 (login-snarf . webmail-yahoo-login)
95 (list-url "%s&rb=Inbox&YN=1" webmail-aux)
96 (list-snarf . webmail-yahoo-list)
97 (article-snarf . webmail-yahoo-article)
99 "%s/ym/us/ShowFolder?YY=52107&inc=50&order=down&sort=date&pos=0&box=Inbox&DEL=Delete&destBox=&Mid=%s&destBox2="
102 (paranoid cookie post)
103 (address . "www.netaddress.com")
104 (open-url "http://www.netaddress.com/")
105 (open-snarf . webmail-netaddress-open)
109 "LoginState=2&SuccessfulLogin=%%2Ftpl&NewServerName=www.netaddress.com&JavaScript=JavaScript1.2&DomainID=4&NA31site=classic.netaddress.com&NA31port=80&UserID=%s&passwd=%s"
111 (login-snarf . webmail-netaddress-login)
113 "http://www.netaddress.com/tpl/Mail/%s/List?FolderID=-4&SortUseCase=True"
115 (list-snarf . webmail-netaddress-list)
116 (article-url "http://www.netaddress.com/")
117 (article-snarf . webmail-netaddress-article)
119 "http://www.netaddress.com/tpl/Message/%s/Move?FolderID=-4&Q=%s&N=&Sort=Date&F=-1"
122 (paranoid cookie post agent)
123 (address . "webmail.netscape.com")
124 (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")
125 (open-snarf . webmail-netscape-open)
128 ("http://ureg.netscape.com/iiop/UReg2/login/loginform")
129 "%s&U2_USERNAME=%s&U2_PASSWORD=%s"
130 webmail-aux user password)
131 (login-snarf . webmail-netaddress-login)
133 "http://webmail.netscape.com/tpl/Mail/%s/List?FolderID=-4&SortUseCase=True"
135 (list-snarf . webmail-netaddress-list)
136 (article-url "http://webmail.netscape.com/")
137 (article-snarf . webmail-netscape-article)
139 "http://webmail.netscape.com/tpl/Message/%s/Move?FolderID=-4&Q=%s&N=&Sort=Date&F=-1"
142 (paranoid cookie post)
143 (address . "www.my-deja.com")
144 (open-url "http://www.my-deja.com/")
145 (open-snarf . webmail-my-deja-open)
149 "member_name=%s&pw=%s&go=&priv_opt_MyDeja99="
151 (list-url "http://www.deja.com/rg_gotomail.xp")
152 (list-snarf . webmail-my-deja-list)
153 (article-snarf . webmail-my-deja-article)
155 "%s/gmm_multiplex.femail?%%2Fgmm_domovemesg_top.femail=Move+to%%3A&folder_top=%s%%3Azzz%%3A%%7E6trash%%3AF%%3A0&docid=%s"
156 webmail-aux user id))))
158 (defvar webmail-variables
159 '(address article-snarf article-url list-snarf list-url
160 login-url login-snarf open-url open-snarf site articles
161 post-process paranoid trash-url))
163 (defconst webmail-version "webmail 1.0")
165 (defvar webmail-newmail-only nil
166 "Only fetch new mails.")
168 (defvar webmail-move-to-trash-can t
169 "Move mail to trash can after fetch it.")
171 ;;; Internal variables
173 (defvar webmail-address nil)
174 (defvar webmail-paranoid nil)
175 (defvar webmail-aux nil)
176 (defvar webmail-session nil)
177 (defvar webmail-article-snarf nil)
178 (defvar webmail-article-url nil)
179 (defvar webmail-list-snarf nil)
180 (defvar webmail-list-url nil)
181 (defvar webmail-login-url nil)
182 (defvar webmail-login-snarf nil)
183 (defvar webmail-open-snarf nil)
184 (defvar webmail-open-url nil)
185 (defvar webmail-trash-url nil)
186 (defvar webmail-articles nil)
187 (defvar webmail-post-process nil)
189 (defvar webmail-buffer nil)
190 (defvar webmail-buffer-list nil)
192 (defvar webmail-type nil)
194 (defvar webmail-error-function nil)
196 (defvar webmail-debug-file "~/.emacs-webmail-debug")
198 ;;; Interface functions
200 (defun webmail-debug (str)
202 (insert "\n---------------- A bug at " str " ------------------\n")
203 (mapcar #'(lambda (sym)
205 (pp `(setq ,sym ',(eval sym)) (current-buffer))))
206 '(webmail-type user))
207 (insert "---------------- webmail buffer ------------------\n\n")
208 (insert-buffer-substring webmail-buffer)
209 (insert "\n---------------- end of buffer ------------------\n\n")
210 (append-to-file (point-min) (point-max) webmail-debug-file)))
212 (defun webmail-error (str)
213 (if webmail-error-function
214 (funcall webmail-error-function str))
215 (message "%s HTML has changed; please get a new version of webmail (%s)"
217 (error "%s HTML has changed; please get a new version of webmail (%s)"
220 (defun webmail-setdefault (type)
221 (let ((type-def (cdr (assq type webmail-type-definition)))
222 (vars webmail-variables)
224 (setq webmail-type type)
226 (if (setq pair (assq var type-def))
227 (set (intern (concat "webmail-" (symbol-name var))) (cdr pair))
228 (set (intern (concat "webmail-" (symbol-name var))) nil)))))
230 (defun webmail-encode-www-form-urlencoded (pairs)
231 "Return PAIRS encoded for forms."
235 (concat (w3-form-encode-xwfu (car data)) "="
236 (w3-form-encode-xwfu (cdr data)))))
239 (defun webmail-fetch-simple (url content)
240 (let ((url-request-data content)
241 (url-request-method "POST")
242 (url-request-extra-headers
243 '(("Content-type" . "application/x-www-form-urlencoded"))))
247 (defun webmail-fetch-form (url pairs)
248 (let ((url-request-data (webmail-encode-www-form-urlencoded pairs))
249 (url-request-method "POST")
250 (url-request-extra-headers
251 '(("Content-type" . "application/x-www-form-urlencoded"))))
255 (defun webmail-eval (expr)
258 (cons (webmail-eval (car expr)) (webmail-eval (cdr expr))))
264 (defun webmail-url (xurl)
265 (mm-with-unibyte-current-buffer
267 ((eq (car xurl) 'content)
269 (webmail-fetch-simple (if (stringp (car xurl))
271 (apply 'format (webmail-eval (car xurl))))
272 (apply 'format (webmail-eval (cdr xurl)))))
273 ((eq (car xurl) 'post)
275 (webmail-fetch-form (car xurl) (webmail-eval (cdr xurl))))
277 (nnweb-insert (apply 'format (webmail-eval xurl)))))))
279 (defun webmail-init ()
280 "Initialize buffers and such."
281 (if (gnus-buffer-live-p webmail-buffer)
282 (set-buffer webmail-buffer)
285 (nnheader-set-temp-buffer " *webmail*")))))
287 (defvar url-package-name)
288 (defvar url-package-version)
289 (defvar url-cookie-multiple-line)
290 (defvar url-confirmation-func)
292 ;; Hack W3 POST redirect. See `url-parse-mime-headers'.
294 ;; Netscape uses "GET" as redirect method when orignal method is POST
295 ;; and status is 302, .i.e no security risks by default without
298 ;; Some web servers (at least Apache used by yahoo) return status 302
299 ;; instead of 303, though they mean 303.
301 (defun webmail-url-confirmation-func (prompt)
303 ((equal prompt (concat "Honor redirection with non-GET method "
304 "(possible security risks)? "))
306 ((equal prompt "Continue (with method of GET)? ")
310 (defun webmail-refresh-redirect ()
311 "Redirect refresh url in META."
312 (goto-char (point-min))
313 (while (re-search-forward
314 "HTTP-EQUIV=\"Refresh\"[^>]*URL=\\([^\"]+\\)\""
316 (let ((url (match-string 1)))
318 (mm-with-unibyte-current-buffer
320 (goto-char (point-min))))
322 (defun webmail-fetch (file subtype user password)
324 (webmail-setdefault subtype)
325 (let ((url-package-name (if (memq 'agent webmail-paranoid)
328 (url-package-version (if (memq 'agent webmail-paranoid)
330 url-package-version))
331 (url-cookie-multiple-line (if (memq 'cookie webmail-paranoid)
333 url-cookie-multiple-line))
334 (url-confirmation-func (if (memq 'post webmail-paranoid)
335 'webmail-url-confirmation-func
336 url-confirmation-func))
337 url-cookie-storage url-cookie-secure-storage
338 url-cookie-confirmation
341 (setq webmail-articles nil)
342 (when webmail-open-url
344 (webmail-url webmail-open-url))
345 (if webmail-open-snarf (funcall webmail-open-snarf))
346 (when webmail-login-url
348 (webmail-url webmail-login-url))
349 (if webmail-login-snarf
350 (funcall webmail-login-snarf))
351 (when webmail-list-url
353 (webmail-url webmail-list-url))
354 (if webmail-list-snarf
355 (funcall webmail-list-snarf))
356 (while (setq item (pop webmail-articles))
357 (message "Fetching mail #%d..." (setq n (1+ n)))
359 (mm-with-unibyte-current-buffer
360 (nnweb-insert (cdr item)))
362 (if webmail-article-snarf
363 (funcall webmail-article-snarf file id))
364 (when (and webmail-trash-url webmail-move-to-trash-can)
365 (message "Move mail #%d to trash can..." n)
368 (webmail-url webmail-trash-url)
370 (while (setq buf (pop webmail-buffer-list))
374 (while (setq buf (pop webmail-buffer-list))
377 (if webmail-post-process
378 (funcall webmail-post-process))))
380 (defun webmail-encode-8bit ()
381 (goto-char (point-min))
382 (skip-chars-forward "^\200-\377")
384 (insert (format "&%d;" (mm-char-int (char-after))))
386 (skip-chars-forward "^\200-\377")))
390 (defun webmail-hotmail-open ()
391 (goto-char (point-min))
392 (if (re-search-forward
393 "action=\"https?://\\([^/]+\\)/cgi-bin/dologin" nil t)
394 (setq webmail-aux (match-string 1))
395 (webmail-error "open@1")))
397 (defun webmail-hotmail-login ()
399 (goto-char (point-min))
400 (if (re-search-forward
401 "https?://\\([^/]+hotmail\\.msn\\.com\\)/cgi-bin/" nil t)
402 (setq site (match-string 1))
403 (webmail-error "login@1"))
404 (goto-char (point-min))
405 (if (re-search-forward
406 "\\(/cgi-bin/HoTMaiL\\?[^\"]*curmbox=ACTIVE[^\"]*\\)" nil t)
407 (setq webmail-aux (concat "http://" site (match-string 1)))
408 (webmail-error "login@2"))))
410 (defun webmail-hotmail-list ()
412 (goto-char (point-min))
413 (if (re-search-forward "[0-9]+ new" nil t)
414 (message "Found %s" (match-string 0))
415 (webmail-error "maybe your w3 version is too old"))
416 (goto-char (point-min))
417 (if (re-search-forward
418 "https?://\\([^/]+hotmail\\.msn\\.com\\)/cgi-bin/" nil t)
419 (setq site (match-string 1))
420 (webmail-error "list@1"))
421 (goto-char (point-min))
422 (if (re-search-forward "disk=\\([^&]+\\)&" nil t)
424 (concat "http://" site "/cgi-bin/HoTMaiL?disk="
426 (webmail-error "list@2"))
427 (goto-char (point-max))
428 (while (re-search-backward
429 "newmail\\.gif\\|href=\"\\(/cgi-bin/getmsg\\?[^\"]+\\)\""
431 (if (setq url (match-string 1))
433 (if (or newp (not webmail-newmail-only))
435 (if (string-match "msg=\\([^&]+\\)" url)
436 (setq id (match-string 1 url)))
437 (push (cons id (concat "http://" site url "&raw=0"))
442 ;; Thank victor@idaccr.org (Victor S. Miller) for raw=0
444 (defun webmail-hotmail-article (file id)
445 (goto-char (point-min))
446 (if (not (search-forward "<pre>" nil t))
447 (webmail-error "article@3"))
448 (skip-chars-forward "\n\r\t ")
449 (delete-region (point-min) (point))
450 (if (not (search-forward "</pre>" nil t))
451 (webmail-error "article@3.1"))
452 (delete-region (match-beginning 0) (point-max))
453 (nnweb-remove-markup)
454 (nnweb-decode-entities)
455 (goto-char (point-min))
456 (while (re-search-forward "\r\n?" nil t)
457 (replace-match "\n"))
458 (goto-char (point-min))
460 (if (not (looking-at "\n*From "))
461 (insert "From nobody " (current-time-string) "\n"))
462 (mm-append-to-file (point-min) (point-max) file))
464 (defun webmail-hotmail-article-old (file id)
465 (let (p attachment count mime hotmail-direct)
467 (webmail-encode-8bit)
468 (goto-char (point-min))
469 (if (not (search-forward "<DIV>" nil t))
470 (if (not (search-forward "Reply All" nil t))
471 (webmail-error "article@1")
472 (setq hotmail-direct t))
473 (goto-char (match-beginning 0)))
474 (narrow-to-region (point-min) (point))
475 (if (not (search-backward "<table" nil t 2))
476 (webmail-error "article@1.1"))
477 (delete-region (point-min) (match-beginning 0))
478 (while (search-forward "<a href=" nil t)
479 (setq p (match-beginning 0))
480 (search-forward "</a>" nil t)
481 (delete-region p (match-end 0)))
482 (nnweb-remove-markup)
483 (nnweb-decode-entities)
484 (goto-char (point-min))
486 (goto-char (point-min))
487 (when (search-forward "\n\n" nil t)
489 (delete-region (point) (point-max)))
490 (goto-char (point-max))
494 (while (re-search-forward
495 "<tt>\\|<div>\\|\\(http://[^/]+/cgi-bin/getmsg/\\([^\?]+\\)\?[^\"]*\\)\""
497 (if (setq attachment (match-string 1))
498 (let ((filename (match-string 2))
499 bufname);; Attachment
500 (delete-region p (match-end 0))
502 (set-buffer (generate-new-buffer " *webmail-att*"))
503 (nnweb-insert attachment)
504 (push (current-buffer) webmail-buffer-list)
505 (setq bufname (buffer-name)))
507 (insert "<#part type="
509 (string-match "\\.[^\\.]+$" filename)
510 (mailcap-extension-to-mime
511 (match-string 0 filename)))
512 "application/octet-stream"))
513 (insert " buffer=\"" bufname "\"")
514 (insert " filename=\"" filename "\"")
515 (insert " disposition=\"inline\"")
516 (insert "><#/part>\n")
518 (delete-region p (match-end 0))
520 (if (not (search-forward "</tt>" nil t))
521 (webmail-error "article@1.2")
522 (delete-region (match-beginning 0) (match-end 0)))
524 (while (and (> count 0)
525 (re-search-forward "</div>\\|\\(<div>\\)" nil t))
527 (setq count (1+ count))
528 (if (= (setq count (1- count)) 0)
529 (delete-region (match-beginning 0)
531 (narrow-to-region p (point))
532 (goto-char (point-min))
534 ((looking-at "<pre>")
535 (goto-char (match-end 0))
536 (if (looking-at "$") (forward-char))
537 (delete-region (point-min) (point))
538 (nnweb-remove-markup)
539 (nnweb-decode-entities)
543 (insert "<#part type=\"text/html\" disposition=inline>")
544 (goto-char (point-max))
545 (insert "<#/part>")))
546 (goto-char (point-max))
549 (delete-region p (point-max))
550 (goto-char (point-min))
551 ;; Some blank line to seperate mails.
552 (insert "\n\nFrom nobody " (current-time-string) "\n")
554 (insert (format "Message-ID: <%s@hotmail.com>\n" id)))
555 (unless (looking-at "$")
556 (if (search-forward "\n\n" nil t)
558 (webmail-error "article@2")))
559 (narrow-to-region (point) (point-max))
561 (insert "MIME-Version: 1.0\n"
564 (delete-region (point-min) (point-max)))))
565 (goto-char (point-min))
567 (let (case-fold-search)
568 (while (re-search-forward "^From " nil t)
571 (mm-append-to-file (point-min) (point-max) file)))
575 (defun webmail-yahoo-open ()
576 (goto-char (point-min))
577 (if (re-search-forward "action=\"\\([^\"]+\\)\"" nil t)
578 (setq webmail-aux (match-string 1))
579 (webmail-error "open@1")))
581 (defun webmail-yahoo-login ()
582 (goto-char (point-min))
583 (if (re-search-forward "http://[a-zA-Z][0-9]\\.mail\\.yahoo\\.com/" nil t)
584 (setq webmail-aux (match-string 0))
585 (webmail-error "login@1"))
586 (if (re-search-forward "YY=[0-9]+" nil t)
587 (setq webmail-aux (concat webmail-aux "ym/us/ShowFolder?"
589 (webmail-error "login@2")))
591 (defun webmail-yahoo-list ()
592 (let (url (newp t) (tofetch 0))
593 (goto-char (point-min))
594 (when (re-search-forward
595 "showing [0-9]+-\\([0-9]+\\) of \\([0-9]+\\)" nil t)
596 ;;(setq listed (match-string 1))
597 (message "Found %s mail(s)" (match-string 2)))
598 (if (string-match "http://[^/]+" webmail-aux)
599 (setq webmail-aux (match-string 0 webmail-aux))
600 (webmail-error "list@1"))
601 (goto-char (point-min))
602 (while (re-search-forward
603 "bgcolor=\"#eeeeee\"\\|href=\"\\(/ym/us/ShowLetter\\?MsgId=\\([^&]+\\)&[^\"]*\\)\""
605 (if (setq url (match-string 1))
607 (when (or newp (not webmail-newmail-only))
608 (push (cons (match-string 2) (concat webmail-aux url "&toc=1"))
610 (setq tofetch (1+ tofetch)))
613 (setq webmail-articles (nreverse webmail-articles))
614 (message "Fetching %d mail(s)" tofetch)))
616 (defun webmail-yahoo-article (file id)
619 (goto-char (point-min))
620 (if (not (search-forward "value=\"Done\"" nil t))
621 (webmail-error "article@1"))
622 (if (not (search-forward "<table" nil t))
623 (webmail-error "article@2"))
624 (delete-region (point-min) (match-beginning 0))
625 (if (not (search-forward "</table>" nil t))
626 (webmail-error "article@3"))
627 (narrow-to-region (point-min) (match-end 0))
628 (while (search-forward "<a href=" nil t)
629 (setq p (match-beginning 0))
630 (search-forward "</a>" nil t)
631 (delete-region p (match-end 0)))
632 (nnweb-remove-markup)
633 (nnweb-decode-entities)
634 (goto-char (point-min))
636 (goto-char (point-max))
640 (while (re-search-forward "[^\"]*/ShowLetter/[^\?]+\?[^\"]*" nil t)
641 (setq attachment (match-string 0))
642 (let (bufname ct ctl cd description)
643 (if (not (search-forward "<table" nil t))
644 (webmail-error "article@4"))
645 (delete-region p (match-beginning 0))
646 (if (not (search-forward "</table>" nil t))
647 (webmail-error "article@5"))
648 (narrow-to-region p (match-end 0))
649 (nnweb-remove-markup)
650 (nnweb-decode-entities)
651 (goto-char (point-min))
653 (setq ct (mail-fetch-field "content-type")
654 ctl (ignore-errors (mail-header-parse-content-type ct))
655 ;;cte (mail-fetch-field "content-transfer-encoding")
656 cd (mail-fetch-field "content-disposition")
657 description (mail-fetch-field "content-description")
658 id (mail-fetch-field "content-id"))
659 (delete-region (point-min) (point-max))
662 (set-buffer (generate-new-buffer " *webmail-att*"))
663 (nnweb-insert (concat webmail-aux attachment))
664 (push (current-buffer) webmail-buffer-list)
665 (setq bufname (buffer-name)))
667 (if (and ctl (not (equal (car ctl) "text/")))
668 (insert " type=\"" (car ctl) "\""))
669 (insert " buffer=\"" bufname "\"")
671 (insert " disposition=\"" cd "\""))
673 (insert " description=\"" description "\""))
674 (insert "><#/part>\n")
676 (delete-region p (point-max))
677 (goto-char (point-min))
678 ;; Some blank line to seperate mails.
679 (insert "\n\nFrom nobody " (current-time-string) "\n")
681 (insert (format "Message-ID: <%s@yahoo.com>\n" id)))
682 (unless (looking-at "$")
683 (if (search-forward "\n\n" nil t)
685 (webmail-error "article@2")))
686 (narrow-to-region (point) (point-max))
687 (insert "MIME-Version: 1.0\n"
690 (delete-region (point-min) (point-max))))
691 (goto-char (point-min))
693 (let (case-fold-search)
694 (while (re-search-forward "^From " nil t)
697 (mm-append-to-file (point-min) (point-max) file)))
701 (defun webmail-netscape-open ()
702 (goto-char (point-min))
703 (if (re-search-forward "login/hint\\?\\([^\"]+\\)\"" nil t)
704 (setq webmail-aux (match-string 1))
705 (webmail-error "open@1")))
707 (defun webmail-netaddress-open ()
708 (goto-char (point-min))
709 (if (re-search-forward "action=\"\\([^\"]+\\)\"" nil t)
710 (setq webmail-aux (concat (car webmail-open-url) (match-string 1)))
711 (webmail-error "open@1")))
713 (defun webmail-netaddress-login ()
714 (webmail-refresh-redirect)
715 (goto-char (point-min))
716 (if (re-search-forward "tpl/[^/]+/\\([^/]+\\)" nil t)
717 (setq webmail-session (match-string 1))
718 (webmail-error "login@1")))
720 (defun webmail-netaddress-list ()
722 (goto-char (point-min))
723 (when (re-search-forward
724 "(\\([0-9]+\\) unread, \\([0-9]+\\) total)" nil t)
725 (message "Found %s mail(s), %s unread"
726 (match-string 2) (match-string 1)))
727 (goto-char (point-min))
728 (while (re-search-forward
729 "MR\\[i\\]\\.R='\\([^']*\\)'\\|MR\\[i\\]\\.Q='\\([^']+\\)'" nil t)
730 (if (setq id (match-string 2))
733 (format "%s/tpl/Message/%s/Read?Q=%s&FolderID=-4&SortUseCase=True&Sort=Date&Headers=True"
734 (car webmail-article-url)
735 webmail-session id)))
736 (if (or (not webmail-newmail-only)
737 (equal (match-string 1) "True"))
738 (push item webmail-articles))))
739 (setq webmail-articles (nreverse webmail-articles))))
741 (defun webmail-netaddress-single-part ()
742 (goto-char (point-min))
744 ((looking-at "[\t\040\r\n]*<font face=[^>]+>[\t\040\r\n]*")
747 (while (re-search-forward "[\t\040\r\n]+" nil t)
749 (goto-char (point-min))
750 (while (re-search-forward "<br>" nil t)
751 (replace-match "\n"))
752 (nnweb-remove-markup)
753 (nnweb-decode-entities)
756 (insert "<#part type=\"text/html\" disposition=inline>")
757 (goto-char (point-max))
761 (defun webmail-netaddress-article (file id)
762 (let (p p1 attachment count mime type)
764 (webmail-encode-8bit)
765 (goto-char (point-min))
766 (if (not (search-forward "Trash" nil t))
767 (webmail-error "article@1"))
768 (if (not (search-forward "<form>" nil t))
769 (webmail-error "article@2"))
770 (delete-region (point-min) (match-beginning 0))
771 (if (not (search-forward "</form>" nil t))
772 (webmail-error "article@3"))
773 (narrow-to-region (point-min) (match-end 0))
774 (goto-char (point-min))
775 (while (re-search-forward "[\040\t\r\n]+" nil t)
777 (goto-char (point-min))
778 (while (search-forward "<b>" nil t)
779 (replace-match "\n"))
780 (nnweb-remove-markup)
781 (nnweb-decode-entities)
782 (goto-char (point-min))
784 (goto-char (point-min))
785 (while (re-search-forward "^\040+\\|\040+$" nil t)
787 (goto-char (point-min))
788 (while (re-search-forward "\040+" nil t)
790 (goto-char (point-max))
794 (unless (search-forward "<!-- Data -->" nil t)
795 (webmail-error "article@4"))
797 (delete-region p (point))
798 (goto-char (point-max))
799 (unless (re-search-backward
800 "[\040\t]*<br>[\040\t\r\n]*<br>[\040\t\r\n]*<form" p t)
801 (webmail-error "article@5"))
802 (delete-region (point) (point-max))
804 (while (search-forward
805 "<TABLE border=\"0\" WIDTH=\"98%\" cellpadding=0 cellspacing=0>"
808 (unless (search-forward "</TABLE>" nil t)
809 (webmail-error "article@6"))
811 (if (search-backward "<IMG " p t)
813 (unless (re-search-forward "HREF=\"\\(/tpl/Attachment/[^/]+/\\([^/]+/[^\?]+\\)[^\"]+\\)\"" p1 t)
814 (webmail-error "article@7"))
815 (setq attachment (match-string 1))
816 (setq type (match-string 2))
817 (unless (search-forward "</TABLE>" nil t)
818 (webmail-error "article@8"))
819 (delete-region p (point))
820 (let (bufname);; Attachment
822 (set-buffer (generate-new-buffer " *webmail-att*"))
823 (nnweb-insert (concat (car webmail-open-url) attachment))
824 (push (current-buffer) webmail-buffer-list)
825 (setq bufname (buffer-name)))
826 (insert "<#part type=" type)
827 (insert " buffer=\"" bufname "\"")
828 (insert " disposition=\"inline\"")
829 (insert "><#/part>\n")
835 "<TABLE border=\"0\" WIDTH=\"98%\" cellpadding=0 cellspacing=0>"
839 (webmail-netaddress-single-part)
840 (goto-char (point-max))
844 (narrow-to-region p (point-max))
845 (setq mime (webmail-netaddress-single-part))
847 (goto-char (point-min))
848 ;; Some blank line to seperate mails.
849 (insert "\n\nFrom nobody " (current-time-string) "\n")
851 (insert (format "Message-ID: <%s@%s>\n" id webmail-address)))
852 (unless (looking-at "$")
853 (if (search-forward "\n\n" nil t)
855 (webmail-error "article@2")))
857 (narrow-to-region (point-min) (point))
858 (goto-char (point-min))
860 (if (looking-at "MIME-Version\\|Content-Type")
861 (delete-region (point)
864 (if (re-search-forward "^[^ \t]" nil t)
865 (goto-char (match-beginning 0))
868 (goto-char (point-max))
870 (narrow-to-region (point) (point-max))
871 (insert "MIME-Version: 1.0\n"
874 (delete-region (point-min) (point-max))))
875 (goto-char (point-min))
877 (let (case-fold-search)
878 (while (re-search-forward "^From " nil t)
881 (mm-append-to-file (point-min) (point-max) file)))
883 (defun webmail-netscape-article (file id)
884 (let (p p1 attachment count mime type)
886 (webmail-encode-8bit)
887 (goto-char (point-min))
888 (if (not (search-forward "Trash" nil t))
889 (webmail-error "article@1"))
890 (if (not (search-forward "<form>" nil t))
891 (webmail-error "article@2"))
892 (delete-region (point-min) (match-beginning 0))
893 (if (not (search-forward "</form>" nil t))
894 (webmail-error "article@3"))
895 (narrow-to-region (point-min) (match-end 0))
896 (goto-char (point-min))
897 (while (re-search-forward "[\040\t\r\n]+" nil t)
899 (goto-char (point-min))
900 (while (re-search-forward "<a href=[^>]*>[^<]*</a>" nil t)
902 (goto-char (point-min))
903 (while (search-forward "<b>" nil t)
904 (replace-match "\n"))
905 (nnweb-remove-markup)
906 (nnweb-decode-entities)
907 (goto-char (point-min))
909 (goto-char (point-min))
910 (while (re-search-forward "^\040+\\|\040+$" nil t)
912 (goto-char (point-min))
913 (while (re-search-forward "\040+" nil t)
915 (goto-char (point-max))
919 (unless (search-forward "<!-- Data -->" nil t)
920 (webmail-error "article@4"))
922 (delete-region p (point))
923 (goto-char (point-max))
924 (unless (re-search-backward
925 "<form name=\"Transfer2\"" p t)
926 (webmail-error "article@5"))
927 (delete-region (point) (point-max))
929 (while (search-forward
930 "<TABLE border=\"0\" WIDTH=\"98%\" cellpadding=0 cellspacing=0>"
933 (unless (search-forward "</TABLE>" nil t)
934 (webmail-error "article@6"))
936 (if (search-backward "<IMG " p t)
938 (unless (re-search-forward "HREF=\"\\(/tpl/Attachment/[^/]+/\\([^/]+/[^\?]+\\)[^\"]+\\)\"" p1 t)
939 (webmail-error "article@7"))
940 (setq attachment (match-string 1))
941 (setq type (match-string 2))
942 (unless (search-forward "</TABLE>" nil t)
943 (webmail-error "article@8"))
944 (delete-region p (point))
945 (let (bufname);; Attachment
947 (set-buffer (generate-new-buffer " *webmail-att*"))
948 (nnweb-insert (concat (car webmail-open-url) attachment))
949 (push (current-buffer) webmail-buffer-list)
950 (setq bufname (buffer-name)))
951 (insert "<#part type=" type)
952 (insert " buffer=\"" bufname "\"")
953 (insert " disposition=\"inline\"")
954 (insert "><#/part>\n")
960 "<TABLE border=\"0\" WIDTH=\"98%\" cellpadding=0 cellspacing=0>"
964 (webmail-netaddress-single-part)
965 (goto-char (point-max))
969 (narrow-to-region p (point-max))
970 (setq mime (webmail-netaddress-single-part))
972 (goto-char (point-min))
973 ;; Some blank line to seperate mails.
974 (insert "\n\nFrom nobody " (current-time-string) "\n")
976 (insert (format "Message-ID: <%s@%s>\n" id webmail-address)))
977 (unless (looking-at "$")
978 (if (search-forward "\n\n" nil t)
980 (webmail-error "article@2")))
982 (narrow-to-region (point-min) (point))
983 (goto-char (point-min))
985 (if (looking-at "MIME-Version\\|Content-Type")
986 (delete-region (point)
989 (if (re-search-forward "^[^ \t]" nil t)
990 (goto-char (match-beginning 0))
993 (goto-char (point-max))
995 (narrow-to-region (point) (point-max))
996 (insert "MIME-Version: 1.0\n"
999 (delete-region (point-min) (point-max))))
1000 (goto-char (point-min))
1002 (let (case-fold-search)
1003 (while (re-search-forward "^From " nil t)
1006 (mm-append-to-file (point-min) (point-max) file)))
1010 (defun webmail-my-deja-open ()
1011 (webmail-refresh-redirect)
1012 (goto-char (point-min))
1013 (if (re-search-forward "action=\"\\([^\"]+login_confirm\\.xp[^\"]*\\)\""
1015 (setq webmail-aux (match-string 1))
1016 (webmail-error "open@1")))
1018 (defun webmail-my-deja-list ()
1020 (goto-char (point-min))
1021 (when (re-search-forward
1022 "(\\([0-9]+\\) message(s), \\([0-9]+\\) new, \\([0-9]+\\) k )"
1024 (message "Found %s mail(s), %s unread, total size %s K"
1025 (match-string 1) (match-string 2) (match-string 3)))
1026 (goto-char (point-min))
1027 (while (re-search-forward
1028 "• \\|\\(http:[^\"]+\\)/display_seemesg\\.femail\\?docid=\\([^&\"]+\\)"
1030 (if (setq id (match-string 2))
1031 (when (or newp (not webmail-newmail-only))
1033 (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"
1034 (match-string 1) id))
1036 (setq webmail-aux (match-string 1))
1039 (setq webmail-articles (nreverse webmail-articles))))
1041 (defun webmail-my-deja-article (file id)
1043 (goto-char (point-min))
1044 (unless (re-search-forward "\\(http:[^\"]+/attachment/entire_message.txt[^\"]+\\)" nil t)
1045 (webmail-error "article@1"))
1046 (setq url (match-string 1))
1048 (mm-with-unibyte-current-buffer
1050 (goto-char (point-min))
1051 (while (search-forward "\r\n" nil t)
1052 (replace-match "\n"))
1053 (goto-char (point-min))
1054 (insert "\n\nFrom nobody " (current-time-string) "\n")
1055 (mm-append-to-file (point-min) (point-max) file)))
1059 ;;; webmail.el ends here