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 (nnweb-decode-entities)
458 (goto-char (point-min))
459 (while (re-search-forward "\r\n?" nil t)
460 (replace-match "\n"))
461 (goto-char (point-min))
463 (if (not (looking-at "\n*From "))
464 (insert "From nobody " (current-time-string) "\n"))
465 (mm-append-to-file (point-min) (point-max) file))
467 (defun webmail-hotmail-article-old (file id)
468 (let (p attachment count mime hotmail-direct)
470 (webmail-encode-8bit)
471 (goto-char (point-min))
472 (if (not (search-forward "<DIV>" nil t))
473 (if (not (search-forward "Reply All" nil t))
474 (webmail-error "article@1")
475 (setq hotmail-direct t))
476 (goto-char (match-beginning 0)))
477 (narrow-to-region (point-min) (point))
478 (if (not (search-backward "<table" nil t 2))
479 (webmail-error "article@1.1"))
480 (delete-region (point-min) (match-beginning 0))
481 (while (search-forward "<a href=" nil t)
482 (setq p (match-beginning 0))
483 (search-forward "</a>" nil t)
484 (delete-region p (match-end 0)))
485 (nnweb-remove-markup)
486 (nnweb-decode-entities)
487 (goto-char (point-min))
489 (goto-char (point-min))
490 (when (search-forward "\n\n" nil t)
492 (delete-region (point) (point-max)))
493 (goto-char (point-max))
497 (while (re-search-forward
498 "<tt>\\|<div>\\|\\(http://[^/]+/cgi-bin/getmsg/\\([^\?]+\\)\?[^\"]*\\)\""
500 (if (setq attachment (match-string 1))
501 (let ((filename (match-string 2))
502 bufname);; Attachment
503 (delete-region p (match-end 0))
505 (set-buffer (generate-new-buffer " *webmail-att*"))
506 (nnweb-insert attachment)
507 (push (current-buffer) webmail-buffer-list)
508 (setq bufname (buffer-name)))
510 (insert "<#part type="
512 (string-match "\\.[^\\.]+$" filename)
513 (mailcap-extension-to-mime
514 (match-string 0 filename)))
515 "application/octet-stream"))
516 (insert " buffer=\"" bufname "\"")
517 (insert " filename=\"" filename "\"")
518 (insert " disposition=\"inline\"")
519 (insert "><#/part>\n")
521 (delete-region p (match-end 0))
523 (if (not (search-forward "</tt>" nil t))
524 (webmail-error "article@1.2")
525 (delete-region (match-beginning 0) (match-end 0)))
527 (while (and (> count 0)
528 (re-search-forward "</div>\\|\\(<div>\\)" nil t))
530 (setq count (1+ count))
531 (if (= (setq count (1- count)) 0)
532 (delete-region (match-beginning 0)
534 (narrow-to-region p (point))
535 (goto-char (point-min))
537 ((looking-at "<pre>")
538 (goto-char (match-end 0))
539 (if (looking-at "$") (forward-char))
540 (delete-region (point-min) (point))
541 (nnweb-remove-markup)
542 (nnweb-decode-entities)
546 (insert "<#part type=\"text/html\" disposition=inline>")
547 (goto-char (point-max))
548 (insert "<#/part>")))
549 (goto-char (point-max))
552 (delete-region p (point-max))
553 (goto-char (point-min))
554 ;; Some blank line to seperate mails.
555 (insert "\n\nFrom nobody " (current-time-string) "\n")
557 (insert (format "Message-ID: <%s@hotmail.com>\n" id)))
558 (unless (looking-at "$")
559 (if (search-forward "\n\n" nil t)
561 (webmail-error "article@2")))
562 (narrow-to-region (point) (point-max))
564 (insert "MIME-Version: 1.0\n"
567 (delete-region (point-min) (point-max)))))
568 (goto-char (point-min))
570 (let (case-fold-search)
571 (while (re-search-forward "^From " nil t)
574 (mm-append-to-file (point-min) (point-max) file)))
578 (defun webmail-yahoo-open ()
579 (goto-char (point-min))
580 (if (re-search-forward "action=\"\\([^\"]+\\)\"" nil t)
581 (setq webmail-aux (match-string 1))
582 (webmail-error "open@1")))
584 (defun webmail-yahoo-login ()
585 (goto-char (point-min))
586 (if (re-search-forward "http://[^/]+[0-9]\\.mail\\.yahoo\\.com/" nil t)
587 (setq webmail-aux (match-string 0))
588 (webmail-error "login@1"))
589 (if (re-search-forward "YY=[0-9]+" nil t)
590 (setq webmail-aux (concat webmail-aux "ym/ShowFolder?"
592 (webmail-error "login@2")))
594 (defun webmail-yahoo-list ()
595 (let (url (newp t) (tofetch 0))
596 (goto-char (point-min))
597 (when (re-search-forward
598 "showing [0-9]+-\\([0-9]+\\) of \\([0-9]+\\)" nil t)
599 ;;(setq listed (match-string 1))
600 (message "Found %s mail(s)" (match-string 2)))
601 (if (string-match "http://[^/]+" webmail-aux)
602 (setq webmail-aux (match-string 0 webmail-aux))
603 (webmail-error "list@1"))
604 (goto-char (point-min))
605 (while (re-search-forward
606 "bgcolor=\"#eeeeee\"\\|href=\"\\(/ym/ShowLetter\\?MsgId=\\([^&]+\\)&[^\"]*\\)\""
608 (if (setq url (match-string 1))
610 (when (or newp (not webmail-newmail-only))
611 (push (cons (match-string 2) (concat webmail-aux url "&toc=1"))
613 (setq tofetch (1+ tofetch)))
616 (setq webmail-articles (nreverse webmail-articles))
617 (message "Fetching %d mail(s)" tofetch)))
619 (defun webmail-yahoo-article (file id)
622 (goto-char (point-min))
623 (if (not (search-forward "value=\"Done\"" nil t))
624 (webmail-error "article@1"))
625 (if (not (search-forward "<table" nil t))
626 (webmail-error "article@2"))
627 (delete-region (point-min) (match-beginning 0))
628 (if (not (search-forward "</table>" nil t))
629 (webmail-error "article@3"))
630 (narrow-to-region (point-min) (match-end 0))
631 (while (search-forward "<a href=" nil t)
632 (setq p (match-beginning 0))
633 (search-forward "</a>" nil t)
634 (delete-region p (match-end 0)))
635 (nnweb-remove-markup)
636 (nnweb-decode-entities)
637 (goto-char (point-min))
639 (goto-char (point-max))
643 (while (re-search-forward "[^\"]*/ShowLetter/[^\?]+\?[^\"]*" nil t)
644 (setq attachment (match-string 0))
645 (let (bufname ct ctl cd description)
646 (if (not (search-forward "<table" nil t))
647 (webmail-error "article@4"))
648 (delete-region p (match-beginning 0))
649 (if (not (search-forward "</table>" nil t))
650 (webmail-error "article@5"))
651 (narrow-to-region p (match-end 0))
652 (nnweb-remove-markup)
653 (nnweb-decode-entities)
654 (goto-char (point-min))
656 (setq ct (mail-fetch-field "content-type")
657 ctl (ignore-errors (mail-header-parse-content-type ct))
658 ;;cte (mail-fetch-field "content-transfer-encoding")
659 cd (mail-fetch-field "content-disposition")
660 description (mail-fetch-field "content-description")
661 id (mail-fetch-field "content-id"))
662 (delete-region (point-min) (point-max))
665 (set-buffer (generate-new-buffer " *webmail-att*"))
666 (nnweb-insert (concat webmail-aux attachment))
667 (push (current-buffer) webmail-buffer-list)
668 (setq bufname (buffer-name)))
670 (if (and ctl (not (equal (car ctl) "text/")))
671 (insert " type=\"" (car ctl) "\""))
672 (insert " buffer=\"" bufname "\"")
674 (insert " disposition=\"" cd "\""))
676 (insert " description=\"" description "\""))
677 (insert "><#/part>\n")
679 (delete-region p (point-max))
680 (goto-char (point-min))
681 ;; Some blank line to seperate mails.
682 (insert "\n\nFrom nobody " (current-time-string) "\n")
684 (insert (format "Message-ID: <%s@yahoo.com>\n" id)))
685 (unless (looking-at "$")
686 (if (search-forward "\n\n" nil t)
688 (webmail-error "article@2")))
689 (narrow-to-region (point) (point-max))
690 (insert "MIME-Version: 1.0\n"
693 (delete-region (point-min) (point-max))))
694 (goto-char (point-min))
696 (let (case-fold-search)
697 (while (re-search-forward "^From " nil t)
700 (mm-append-to-file (point-min) (point-max) file)))
704 (defun webmail-netscape-open ()
705 (goto-char (point-min))
706 (if (re-search-forward "login/hint\\?\\([^\"]+\\)\"" nil t)
707 (setq webmail-aux (match-string 1))
708 (webmail-error "open@1")))
710 (defun webmail-netaddress-open ()
711 (goto-char (point-min))
712 (if (re-search-forward "action=\"\\([^\"]+\\)\"" nil t)
713 (setq webmail-aux (concat (car webmail-open-url) (match-string 1)))
714 (webmail-error "open@1")))
716 (defun webmail-netaddress-login ()
717 (webmail-refresh-redirect)
718 (goto-char (point-min))
719 (if (re-search-forward "tpl/[^/]+/\\([^/]+\\)" nil t)
720 (setq webmail-session (match-string 1))
721 (webmail-error "login@1")))
723 (defun webmail-netaddress-list ()
725 (goto-char (point-min))
726 (when (re-search-forward
727 "(\\([0-9]+\\) unread, \\([0-9]+\\) total)" nil t)
728 (message "Found %s mail(s), %s unread"
729 (match-string 2) (match-string 1)))
730 (goto-char (point-min))
731 (while (re-search-forward
732 "MR\\[i\\]\\.R='\\([^']*\\)'\\|MR\\[i\\]\\.Q='\\([^']+\\)'" nil t)
733 (if (setq id (match-string 2))
736 (format "%s/tpl/Message/%s/Read?Q=%s&FolderID=-4&SortUseCase=True&Sort=Date&Headers=True"
737 (car webmail-article-url)
738 webmail-session id)))
739 (if (or (not webmail-newmail-only)
740 (equal (match-string 1) "True"))
741 (push item webmail-articles))))
742 (setq webmail-articles (nreverse webmail-articles))))
744 (defun webmail-netaddress-single-part ()
745 (goto-char (point-min))
747 ((looking-at "[\t\040\r\n]*<font face=[^>]+>[\t\040\r\n]*")
750 (while (re-search-forward "[\t\040\r\n]+" nil t)
752 (goto-char (point-min))
753 (while (re-search-forward "<br>" nil t)
754 (replace-match "\n"))
755 (nnweb-remove-markup)
756 (nnweb-decode-entities)
759 (insert "<#part type=\"text/html\" disposition=inline>")
760 (goto-char (point-max))
764 (defun webmail-netaddress-article (file id)
765 (let (p p1 attachment count mime type)
767 (webmail-encode-8bit)
768 (goto-char (point-min))
769 (if (not (search-forward "Trash" nil t))
770 (webmail-error "article@1"))
771 (if (not (search-forward "<form>" nil t))
772 (webmail-error "article@2"))
773 (delete-region (point-min) (match-beginning 0))
774 (if (not (search-forward "</form>" nil t))
775 (webmail-error "article@3"))
776 (narrow-to-region (point-min) (match-end 0))
777 (goto-char (point-min))
778 (while (re-search-forward "[\040\t\r\n]+" nil t)
780 (goto-char (point-min))
781 (while (search-forward "<b>" nil t)
782 (replace-match "\n"))
783 (nnweb-remove-markup)
784 (nnweb-decode-entities)
785 (goto-char (point-min))
787 (goto-char (point-min))
788 (while (re-search-forward "^\040+\\|\040+$" nil t)
790 (goto-char (point-min))
791 (while (re-search-forward "\040+" nil t)
793 (goto-char (point-max))
797 (unless (search-forward "<!-- Data -->" nil t)
798 (webmail-error "article@4"))
800 (delete-region p (point))
801 (goto-char (point-max))
802 (unless (re-search-backward
803 "[\040\t]*<br>[\040\t\r\n]*<br>[\040\t\r\n]*<form" p t)
804 (webmail-error "article@5"))
805 (delete-region (point) (point-max))
807 (while (search-forward
808 "<TABLE border=\"0\" WIDTH=\"98%\" cellpadding=0 cellspacing=0>"
811 (unless (search-forward "</TABLE>" nil t)
812 (webmail-error "article@6"))
814 (if (search-backward "<IMG " p t)
816 (unless (re-search-forward "HREF=\"\\(/tpl/Attachment/[^/]+/\\([^/]+/[^\?]+\\)[^\"]+\\)\"" p1 t)
817 (webmail-error "article@7"))
818 (setq attachment (match-string 1))
819 (setq type (match-string 2))
820 (unless (search-forward "</TABLE>" nil t)
821 (webmail-error "article@8"))
822 (delete-region p (point))
823 (let (bufname);; Attachment
825 (set-buffer (generate-new-buffer " *webmail-att*"))
826 (nnweb-insert (concat (car webmail-open-url) attachment))
827 (push (current-buffer) webmail-buffer-list)
828 (setq bufname (buffer-name)))
829 (insert "<#part type=" type)
830 (insert " buffer=\"" bufname "\"")
831 (insert " disposition=\"inline\"")
832 (insert "><#/part>\n")
838 "<TABLE border=\"0\" WIDTH=\"98%\" cellpadding=0 cellspacing=0>"
842 (webmail-netaddress-single-part)
843 (goto-char (point-max))
847 (narrow-to-region p (point-max))
848 (setq mime (webmail-netaddress-single-part))
850 (goto-char (point-min))
851 ;; Some blank line to seperate mails.
852 (insert "\n\nFrom nobody " (current-time-string) "\n")
854 (insert (format "Message-ID: <%s@%s>\n" id webmail-address)))
855 (unless (looking-at "$")
856 (if (search-forward "\n\n" nil t)
858 (webmail-error "article@2")))
860 (narrow-to-region (point-min) (point))
861 (goto-char (point-min))
863 (if (looking-at "MIME-Version\\|Content-Type")
864 (delete-region (point)
867 (if (re-search-forward "^[^ \t]" nil t)
868 (goto-char (match-beginning 0))
871 (goto-char (point-max))
873 (narrow-to-region (point) (point-max))
874 (insert "MIME-Version: 1.0\n"
877 (delete-region (point-min) (point-max))))
878 (goto-char (point-min))
880 (let (case-fold-search)
881 (while (re-search-forward "^From " nil t)
884 (mm-append-to-file (point-min) (point-max) file)))
886 (defun webmail-netscape-article (file id)
887 (let (p p1 attachment count mime type)
889 (webmail-encode-8bit)
890 (goto-char (point-min))
891 (if (not (search-forward "Trash" nil t))
892 (webmail-error "article@1"))
893 (if (not (search-forward "<form>" nil t))
894 (webmail-error "article@2"))
895 (delete-region (point-min) (match-beginning 0))
896 (if (not (search-forward "</form>" nil t))
897 (webmail-error "article@3"))
898 (narrow-to-region (point-min) (match-end 0))
899 (goto-char (point-min))
900 (while (re-search-forward "[\040\t\r\n]+" nil t)
902 (goto-char (point-min))
903 (while (re-search-forward "<a href=[^>]*>[^<]*</a>" nil t)
905 (goto-char (point-min))
906 (while (search-forward "<b>" nil t)
907 (replace-match "\n"))
908 (nnweb-remove-markup)
909 (nnweb-decode-entities)
910 (goto-char (point-min))
912 (goto-char (point-min))
913 (while (re-search-forward "^\040+\\|\040+$" nil t)
915 (goto-char (point-min))
916 (while (re-search-forward "\040+" nil t)
918 (goto-char (point-max))
922 (unless (search-forward "<!-- Data -->" nil t)
923 (webmail-error "article@4"))
925 (delete-region p (point))
926 (goto-char (point-max))
927 (unless (re-search-backward
928 "<form name=\"Transfer2\"" p t)
929 (webmail-error "article@5"))
930 (delete-region (point) (point-max))
932 (while (search-forward
933 "<TABLE border=\"0\" WIDTH=\"98%\" cellpadding=0 cellspacing=0>"
936 (unless (search-forward "</TABLE>" nil t)
937 (webmail-error "article@6"))
939 (if (search-backward "<IMG " p t)
941 (unless (re-search-forward "HREF=\"\\(/tpl/Attachment/[^/]+/\\([^/]+/[^\?]+\\)[^\"]+\\)\"" p1 t)
942 (webmail-error "article@7"))
943 (setq attachment (match-string 1))
944 (setq type (match-string 2))
945 (unless (search-forward "</TABLE>" nil t)
946 (webmail-error "article@8"))
947 (delete-region p (point))
948 (let (bufname);; Attachment
950 (set-buffer (generate-new-buffer " *webmail-att*"))
951 (nnweb-insert (concat (car webmail-open-url) attachment))
952 (push (current-buffer) webmail-buffer-list)
953 (setq bufname (buffer-name)))
954 (insert "<#part type=" type)
955 (insert " buffer=\"" bufname "\"")
956 (insert " disposition=\"inline\"")
957 (insert "><#/part>\n")
963 "<TABLE border=\"0\" WIDTH=\"98%\" cellpadding=0 cellspacing=0>"
967 (webmail-netaddress-single-part)
968 (goto-char (point-max))
972 (narrow-to-region p (point-max))
973 (setq mime (webmail-netaddress-single-part))
975 (goto-char (point-min))
976 ;; Some blank line to seperate mails.
977 (insert "\n\nFrom nobody " (current-time-string) "\n")
979 (insert (format "Message-ID: <%s@%s>\n" id webmail-address)))
980 (unless (looking-at "$")
981 (if (search-forward "\n\n" nil t)
983 (webmail-error "article@2")))
985 (narrow-to-region (point-min) (point))
986 (goto-char (point-min))
988 (if (looking-at "MIME-Version\\|Content-Type")
989 (delete-region (point)
992 (if (re-search-forward "^[^ \t]" nil t)
993 (goto-char (match-beginning 0))
996 (goto-char (point-max))
998 (narrow-to-region (point) (point-max))
999 (insert "MIME-Version: 1.0\n"
1002 (delete-region (point-min) (point-max))))
1003 (goto-char (point-min))
1005 (let (case-fold-search)
1006 (while (re-search-forward "^From " nil t)
1009 (mm-append-to-file (point-min) (point-max) file)))
1013 (defun webmail-my-deja-open ()
1014 (webmail-refresh-redirect)
1015 (goto-char (point-min))
1016 (if (re-search-forward "action=\"\\([^\"]+login_confirm\\.xp[^\"]*\\)\""
1018 (setq webmail-aux (match-string 1))
1019 (webmail-error "open@1")))
1021 (defun webmail-my-deja-list ()
1023 (goto-char (point-min))
1024 (when (re-search-forward
1025 "(\\([0-9]+\\) message(s), \\([0-9]+\\) new, \\([0-9]+\\) k )"
1027 (message "Found %s mail(s), %s unread, total size %s K"
1028 (match-string 1) (match-string 2) (match-string 3)))
1029 (goto-char (point-min))
1030 (while (re-search-forward
1031 "• \\|\\(http:[^\"]+\\)/display_seemesg\\.femail\\?docid=\\([^&\"]+\\)"
1033 (if (setq id (match-string 2))
1034 (when (or newp (not webmail-newmail-only))
1036 (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"
1037 (match-string 1) id))
1039 (setq webmail-aux (match-string 1))
1042 (setq webmail-articles (nreverse webmail-articles))))
1044 (defun webmail-my-deja-article (file id)
1046 (goto-char (point-min))
1047 (unless (re-search-forward "\\(http:[^\"]+/attachment/entire_message.txt[^\"]+\\)" nil t)
1048 (webmail-error "article@1"))
1049 (setq url (match-string 1))
1051 (mm-with-unibyte-current-buffer
1053 (goto-char (point-min))
1054 (while (search-forward "\r\n" nil t)
1055 (replace-match "\n"))
1056 (goto-char (point-min))
1057 (insert "\n\nFrom nobody " (current-time-string) "\n")
1058 (mm-append-to-file (point-min) (point-max) file)))
1062 ;;; webmail.el ends here