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)
157 (trash-url webmail-aux id))))
159 (defvar webmail-variables
160 '(address article-snarf article-url list-snarf list-url
161 login-url login-snarf open-url open-snarf site articles
162 post-process paranoid trash-url))
164 (defconst webmail-version "webmail 1.0")
166 (defvar webmail-newmail-only nil
167 "Only fetch new mails.")
169 (defvar webmail-move-to-trash-can t
170 "Move mail to trash can after fetch it.")
172 ;;; Internal variables
174 (defvar webmail-address nil)
175 (defvar webmail-paranoid nil)
176 (defvar webmail-aux nil)
177 (defvar webmail-session nil)
178 (defvar webmail-article-snarf nil)
179 (defvar webmail-article-url nil)
180 (defvar webmail-list-snarf nil)
181 (defvar webmail-list-url nil)
182 (defvar webmail-login-url nil)
183 (defvar webmail-login-snarf nil)
184 (defvar webmail-open-snarf nil)
185 (defvar webmail-open-url nil)
186 (defvar webmail-trash-url nil)
187 (defvar webmail-articles nil)
188 (defvar webmail-post-process nil)
190 (defvar webmail-buffer nil)
191 (defvar webmail-buffer-list nil)
193 (defvar webmail-type nil)
195 (defvar webmail-error-function nil)
197 (defvar webmail-debug-file "~/.emacs-webmail-debug")
199 ;;; Interface functions
201 (defun webmail-debug (str)
203 (insert "\n---------------- A bug at " str " ------------------\n")
204 (mapcar #'(lambda (sym)
206 (pp `(setq ,sym ',(eval sym)) (current-buffer))))
207 '(webmail-type user))
208 (insert "---------------- webmail buffer ------------------\n\n")
209 (insert-buffer-substring webmail-buffer)
210 (insert "\n---------------- end of buffer ------------------\n\n")
211 (append-to-file (point-min) (point-max) webmail-debug-file)))
213 (defun webmail-error (str)
214 (if webmail-error-function
215 (funcall webmail-error-function str))
216 (message "%s HTML has changed; please get a new version of webmail (%s)"
218 (error "%s HTML has changed; please get a new version of webmail (%s)"
221 (defun webmail-setdefault (type)
222 (let ((type-def (cdr (assq type webmail-type-definition)))
223 (vars webmail-variables)
225 (setq webmail-type type)
227 (if (setq pair (assq var type-def))
228 (set (intern (concat "webmail-" (symbol-name var))) (cdr pair))
229 (set (intern (concat "webmail-" (symbol-name var))) nil)))))
231 (defun webmail-encode-www-form-urlencoded (pairs)
232 "Return PAIRS encoded for forms."
236 (concat (w3-form-encode-xwfu (car data)) "="
237 (w3-form-encode-xwfu (cdr data)))))
240 (defun webmail-fetch-simple (url content)
241 (let ((url-request-data content)
242 (url-request-method "POST")
243 (url-request-extra-headers
244 '(("Content-type" . "application/x-www-form-urlencoded"))))
248 (defun webmail-fetch-form (url pairs)
249 (let ((url-request-data (webmail-encode-www-form-urlencoded pairs))
250 (url-request-method "POST")
251 (url-request-extra-headers
252 '(("Content-type" . "application/x-www-form-urlencoded"))))
256 (defun webmail-eval (expr)
259 (cons (webmail-eval (car expr)) (webmail-eval (cdr expr))))
265 (defun webmail-url (xurl)
266 (mm-with-unibyte-current-buffer
268 ((eq (car xurl) 'content)
270 (webmail-fetch-simple (if (stringp (car xurl))
272 (apply 'format (webmail-eval (car xurl))))
273 (apply 'format (webmail-eval (cdr xurl)))))
274 ((eq (car xurl) 'post)
276 (webmail-fetch-form (car xurl) (webmail-eval (cdr xurl))))
278 (nnweb-insert (apply 'format (webmail-eval xurl)))))))
280 (defun webmail-init ()
281 "Initialize buffers and such."
282 (if (gnus-buffer-live-p webmail-buffer)
283 (set-buffer webmail-buffer)
286 (nnheader-set-temp-buffer " *webmail*")))))
288 (defvar url-package-name)
289 (defvar url-package-version)
290 (defvar url-cookie-multiple-line)
291 (defvar url-confirmation-func)
293 ;; Hack W3 POST redirect. See `url-parse-mime-headers'.
295 ;; Netscape uses "GET" as redirect method when orignal method is POST
296 ;; and status is 302, .i.e no security risks by default without
299 ;; Some web servers (at least Apache used by yahoo) return status 302
300 ;; instead of 303, though they mean 303.
302 (defun webmail-url-confirmation-func (prompt)
304 ((equal prompt (concat "Honor redirection with non-GET method "
305 "(possible security risks)? "))
307 ((equal prompt "Continue (with method of GET)? ")
311 (defun webmail-refresh-redirect ()
312 "Redirect refresh url in META."
313 (goto-char (point-min))
314 (while (re-search-forward
315 "<meta[ \t\r\n]*http-equiv=\"Refresh\"[^>]*URL=\\([^\"]+\\)\""
317 (let ((url (match-string 1)))
319 (mm-with-unibyte-current-buffer
321 (goto-char (point-min))))
323 (defun webmail-fetch (file subtype user password)
325 (webmail-setdefault subtype)
326 (let ((url-package-name (if (memq 'agent webmail-paranoid)
329 (url-package-version (if (memq 'agent webmail-paranoid)
331 url-package-version))
332 (url-cookie-multiple-line (if (memq 'cookie webmail-paranoid)
334 url-cookie-multiple-line))
335 (url-confirmation-func (if (memq 'post webmail-paranoid)
336 'webmail-url-confirmation-func
337 url-confirmation-func))
338 (url-http-silence-on-insecure-redirection t)
339 url-cookie-storage url-cookie-secure-storage
340 url-cookie-confirmation
343 (setq webmail-articles nil)
344 (when webmail-open-url
346 (webmail-url webmail-open-url))
347 (if webmail-open-snarf (funcall webmail-open-snarf))
348 (when webmail-login-url
350 (webmail-url webmail-login-url))
351 (if webmail-login-snarf
352 (funcall webmail-login-snarf))
353 (when webmail-list-url
355 (webmail-url webmail-list-url))
356 (if webmail-list-snarf
357 (funcall webmail-list-snarf))
358 (while (setq item (pop webmail-articles))
359 (message "Fetching mail #%d..." (setq n (1+ n)))
361 (mm-with-unibyte-current-buffer
362 (nnweb-insert (cdr item)))
364 (if webmail-article-snarf
365 (funcall webmail-article-snarf file id))
366 (when (and webmail-trash-url webmail-move-to-trash-can)
367 (message "Move mail #%d to trash can..." n)
370 (webmail-url webmail-trash-url)
372 (while (setq buf (pop webmail-buffer-list))
376 (while (setq buf (pop webmail-buffer-list))
379 (if webmail-post-process
380 (funcall webmail-post-process))))
382 (defun webmail-encode-8bit ()
383 (goto-char (point-min))
384 (skip-chars-forward "^\200-\377")
386 (insert (format "&%d;" (mm-char-int (char-after))))
388 (skip-chars-forward "^\200-\377")))
392 (defun webmail-hotmail-open ()
393 (goto-char (point-min))
394 (if (re-search-forward
395 "action=\"https?://\\([^/]+\\)/cgi-bin/dologin" nil t)
396 (setq webmail-aux (match-string 1))
397 (webmail-error "open@1")))
399 (defun webmail-hotmail-login ()
401 (goto-char (point-min))
402 (if (re-search-forward
403 "https?://\\([^/]+hotmail\\.msn\\.com\\)/cgi-bin/" nil t)
404 (setq site (match-string 1))
405 (webmail-error "login@1"))
406 (goto-char (point-min))
407 (if (re-search-forward
408 "\\(/cgi-bin/HoTMaiL\\?[^\"]*a=b[^\"]*\\)" nil t)
409 (setq webmail-aux (concat "http://" site (match-string 1)))
410 (webmail-error "login@2"))))
412 (defun webmail-hotmail-list ()
414 (goto-char (point-min))
415 (if (re-search-forward "[0-9]+ new" nil t)
416 (message "Found %s" (match-string 0))
417 (webmail-error "maybe your w3 version is too old"))
418 (goto-char (point-min))
419 (if (re-search-forward
420 "https?://\\([^/]+hotmail\\.msn\\.com\\)/cgi-bin/" nil t)
421 (setq site (match-string 1))
422 (webmail-error "list@1"))
423 (goto-char (point-min))
424 (if (re-search-forward "disk=\\([^&]+\\)&" nil t)
426 (concat "http://" site "/cgi-bin/HoTMaiL?disk="
428 (webmail-error "list@2"))
429 (goto-char (point-max))
430 (while (re-search-backward
431 "newmail\\.gif\\|href=\"\\(/cgi-bin/getmsg\\?[^\"]+\\)\""
433 (if (setq url (match-string 1))
435 (if (or newp (not webmail-newmail-only))
437 (if (string-match "msg=\\([^&]+\\)" url)
438 (setq id (match-string 1 url)))
439 (push (cons id (concat "http://" site url "&raw=0"))
444 ;; Thank victor@idaccr.org (Victor S. Miller) for raw=0
446 (defun webmail-hotmail-article (file id)
447 (goto-char (point-min))
448 (if (not (search-forward "<pre>" nil t))
449 (webmail-error "article@3"))
450 (skip-chars-forward "\n\r\t ")
451 (delete-region (point-min) (point))
452 (if (not (search-forward "</pre>" nil t))
453 (webmail-error "article@3.1"))
454 (delete-region (match-beginning 0) (point-max))
455 (nnweb-remove-markup)
456 (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
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")
466 (insert "X-Gnus-Webmail: " (symbol-value 'user)
467 "@" (symbol-name webmail-type) "\n")
468 (mm-append-to-file (point-min) (point-max) file))
470 (defun webmail-hotmail-article-old (file id)
471 (let (p attachment count mime hotmail-direct)
473 (webmail-encode-8bit)
474 (goto-char (point-min))
475 (if (not (search-forward "<DIV>" nil t))
476 (if (not (search-forward "Reply All" nil t))
477 (webmail-error "article@1")
478 (setq hotmail-direct t))
479 (goto-char (match-beginning 0)))
480 (narrow-to-region (point-min) (point))
481 (if (not (search-backward "<table" nil t 2))
482 (webmail-error "article@1.1"))
483 (delete-region (point-min) (match-beginning 0))
484 (while (search-forward "<a href=" nil t)
485 (setq p (match-beginning 0))
486 (search-forward "</a>" nil t)
487 (delete-region p (match-end 0)))
488 (nnweb-remove-markup)
489 (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
490 (nnweb-decode-entities))
491 (goto-char (point-min))
493 (goto-char (point-min))
494 (when (search-forward "\n\n" nil t)
496 (delete-region (point) (point-max)))
497 (goto-char (point-max))
501 (while (re-search-forward
502 "<tt>\\|<div>\\|\\(http://[^/]+/cgi-bin/getmsg/\\([^\?]+\\)\?[^\"]*\\)\""
504 (if (setq attachment (match-string 1))
505 (let ((filename (match-string 2))
506 bufname);; Attachment
507 (delete-region p (match-end 0))
509 (set-buffer (generate-new-buffer " *webmail-att*"))
510 (nnweb-insert attachment)
511 (push (current-buffer) webmail-buffer-list)
512 (setq bufname (buffer-name)))
514 (insert "<#part type="
516 (string-match "\\.[^\\.]+$" filename)
517 (mailcap-extension-to-mime
518 (match-string 0 filename)))
519 "application/octet-stream"))
520 (insert " buffer=\"" bufname "\"")
521 (insert " filename=\"" filename "\"")
522 (insert " disposition=\"inline\"")
523 (insert "><#/part>\n")
525 (delete-region p (match-end 0))
527 (if (not (search-forward "</tt>" nil t))
528 (webmail-error "article@1.2")
529 (delete-region (match-beginning 0) (match-end 0)))
531 (while (and (> count 0)
532 (re-search-forward "</div>\\|\\(<div>\\)" nil t))
534 (setq count (1+ count))
535 (if (= (setq count (1- count)) 0)
536 (delete-region (match-beginning 0)
538 (narrow-to-region p (point))
539 (goto-char (point-min))
541 ((looking-at "<pre>")
542 (goto-char (match-end 0))
543 (if (looking-at "$") (forward-char))
544 (delete-region (point-min) (point))
545 (nnweb-remove-markup)
546 (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
547 (nnweb-decode-entities))
551 (insert "<#part type=\"text/html\" disposition=inline>")
552 (goto-char (point-max))
553 (insert "<#/part>")))
554 (goto-char (point-max))
557 (delete-region p (point-max))
558 (goto-char (point-min))
559 ;; Some blank line to seperate mails.
560 (insert "\n\nFrom nobody " (current-time-string) "\n")
561 (insert "X-Gnus-Webmail: " (symbol-value 'user)
562 "@" (symbol-name webmail-type) "\n")
564 (insert (format "X-Message-ID: <%s@hotmail.com>\n" id)))
565 (unless (looking-at "$")
566 (if (search-forward "\n\n" nil t)
568 (webmail-error "article@2")))
569 (narrow-to-region (point) (point-max))
571 (insert "MIME-Version: 1.0\n"
574 (delete-region (point-min) (point-max)))))
575 (goto-char (point-min))
577 (let (case-fold-search)
578 (while (re-search-forward "^From " nil t)
581 (mm-append-to-file (point-min) (point-max) file)))
585 (defun webmail-yahoo-open ()
586 (goto-char (point-min))
587 (if (re-search-forward "action=\"\\([^\"]+\\)\"" nil t)
588 (setq webmail-aux (match-string 1))
589 (webmail-error "open@1")))
591 (defun webmail-yahoo-login ()
592 (goto-char (point-min))
593 (if (re-search-forward "http://[^/]+[0-9]\\.mail\\.yahoo\\.com/" nil t)
594 (setq webmail-aux (match-string 0))
595 (webmail-error "login@1"))
596 (if (re-search-forward "YY=[0-9]+" nil t)
597 (setq webmail-aux (concat webmail-aux "ym/ShowFolder?"
599 (webmail-error "login@2")))
601 (defun webmail-yahoo-list ()
602 (let (url (newp t) (tofetch 0))
603 (goto-char (point-min))
604 (when (re-search-forward
605 "showing [0-9]+-\\([0-9]+\\) of \\([0-9]+\\)" nil t)
606 ;;(setq listed (match-string 1))
607 (message "Found %s mail(s)" (match-string 2)))
608 (if (string-match "http://[^/]+" webmail-aux)
609 (setq webmail-aux (match-string 0 webmail-aux))
610 (webmail-error "list@1"))
611 (goto-char (point-min))
612 (while (re-search-forward
613 "bgcolor=\"#eeeeee\"\\|href=\"\\(/ym/ShowLetter\\?MsgId=\\([^&]+\\)&[^\"]*\\)\""
615 (if (setq url (match-string 1))
617 (when (or newp (not webmail-newmail-only))
618 (push (cons (match-string 2) (concat webmail-aux url "&toc=1"))
620 (setq tofetch (1+ tofetch)))
623 (setq webmail-articles (nreverse webmail-articles))
624 (message "Fetching %d mail(s)" tofetch)))
626 (defun webmail-yahoo-article (file id)
629 (goto-char (point-min))
630 (if (not (search-forward "value=\"Done\"" nil t))
631 (webmail-error "article@1"))
632 (if (not (search-forward "<table" nil t))
633 (webmail-error "article@2"))
634 (delete-region (point-min) (match-beginning 0))
635 (if (not (search-forward "</table>" nil t))
636 (webmail-error "article@3"))
637 (narrow-to-region (point-min) (match-end 0))
638 (while (search-forward "<a href=" nil t)
639 (setq p (match-beginning 0))
640 (search-forward "</a>" nil t)
641 (delete-region p (match-end 0)))
642 (nnweb-remove-markup)
643 (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
644 (nnweb-decode-entities))
645 (goto-char (point-min))
647 (goto-char (point-max))
651 (while (re-search-forward "[^\"]*/ShowLetter/[^\?]+\?[^\"]*" nil t)
652 (setq attachment (match-string 0))
653 (let (bufname ct ctl cd description)
654 (if (not (search-forward "<table" nil t))
655 (webmail-error "article@4"))
656 (delete-region p (match-beginning 0))
657 (if (not (search-forward "</table>" nil t))
658 (webmail-error "article@5"))
659 (narrow-to-region p (match-end 0))
660 (nnweb-remove-markup)
661 (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
662 (nnweb-decode-entities))
663 (goto-char (point-min))
665 (setq ct (mail-fetch-field "content-type")
666 ctl (ignore-errors (mail-header-parse-content-type ct))
667 ;;cte (mail-fetch-field "content-transfer-encoding")
668 cd (mail-fetch-field "content-disposition")
669 description (mail-fetch-field "content-description")
670 id (mail-fetch-field "content-id"))
671 (delete-region (point-min) (point-max))
674 (set-buffer (generate-new-buffer " *webmail-att*"))
675 (nnweb-insert (concat webmail-aux attachment))
676 (push (current-buffer) webmail-buffer-list)
677 (setq bufname (buffer-name)))
679 (if (and ctl (not (equal (car ctl) "text/")))
680 (insert " type=\"" (car ctl) "\""))
681 (insert " buffer=\"" bufname "\"")
683 (insert " disposition=\"" cd "\""))
685 (insert " description=\"" description "\""))
686 (insert "><#/part>\n")
688 (delete-region p (point-max))
689 (goto-char (point-min))
690 ;; Some blank line to seperate mails.
691 (insert "\n\nFrom nobody " (current-time-string) "\n")
692 (insert "X-Gnus-Webmail: " (symbol-value 'user)
693 "@" (symbol-name webmail-type) "\n")
695 (insert (format "X-Message-ID: <%s@yahoo.com>\n" id)))
696 (unless (looking-at "$")
697 (if (search-forward "\n\n" nil t)
699 (webmail-error "article@2")))
700 (narrow-to-region (point) (point-max))
701 (insert "MIME-Version: 1.0\n"
704 (delete-region (point-min) (point-max))))
705 (goto-char (point-min))
707 (let (case-fold-search)
708 (while (re-search-forward "^From " nil t)
711 (mm-append-to-file (point-min) (point-max) file)))
715 (defun webmail-netscape-open ()
716 (goto-char (point-min))
717 (if (re-search-forward "login/hint\\?\\([^\"]+\\)\"" nil t)
718 (setq webmail-aux (match-string 1))
719 (webmail-error "open@1")))
721 (defun webmail-netaddress-open ()
722 (goto-char (point-min))
723 (if (re-search-forward "action=\"\\([^\"]+\\)\"" nil t)
724 (setq webmail-aux (concat (car webmail-open-url) (match-string 1)))
725 (webmail-error "open@1")))
727 (defun webmail-netaddress-login ()
728 (webmail-refresh-redirect)
729 (goto-char (point-min))
730 (if (re-search-forward "tpl/[^/]+/\\([^/]+\\)" nil t)
731 (setq webmail-session (match-string 1))
732 (webmail-error "login@1")))
734 (defun webmail-netaddress-list ()
735 (webmail-refresh-redirect)
737 (goto-char (point-min))
738 (when (re-search-forward
739 "(\\([0-9]+\\) unread, \\([0-9]+\\) total)" nil t)
740 (message "Found %s mail(s), %s unread"
741 (match-string 2) (match-string 1)))
742 (goto-char (point-min))
743 (while (re-search-forward
744 "MR\\[i\\]\\.R='\\([^']*\\)'\\|MR\\[i\\]\\.Q='\\([^']+\\)'" nil t)
745 (if (setq id (match-string 2))
748 (format "%s/tpl/Message/%s/Read?Q=%s&FolderID=-4&SortUseCase=True&Sort=Date&Headers=True"
749 (car webmail-article-url)
750 webmail-session id)))
751 (if (or (not webmail-newmail-only)
752 (equal (match-string 1) "True"))
753 (push item webmail-articles))))
754 (setq webmail-articles (nreverse webmail-articles))))
756 (defun webmail-netaddress-single-part ()
757 (goto-char (point-min))
759 ((looking-at "[\t\040\r\n]*<font face=[^>]+>[\t\040\r\n]*")
762 (while (re-search-forward "[\t\040\r\n]+" nil t)
764 (goto-char (point-min))
765 (while (re-search-forward "<br>" nil t)
766 (replace-match "\n"))
767 (nnweb-remove-markup)
768 (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
769 (nnweb-decode-entities))
772 (insert "<#part type=\"text/html\" disposition=inline>")
773 (goto-char (point-max))
777 (defun webmail-netaddress-article (file id)
778 (webmail-refresh-redirect)
779 (let (p p1 attachment count mime type)
781 (webmail-encode-8bit)
782 (goto-char (point-min))
783 (if (not (search-forward "Trash" nil t))
784 (webmail-error "article@1"))
785 (if (not (search-forward "<form>" nil t))
786 (webmail-error "article@2"))
787 (delete-region (point-min) (match-beginning 0))
788 (if (not (search-forward "</form>" nil t))
789 (webmail-error "article@3"))
790 (narrow-to-region (point-min) (match-end 0))
791 (goto-char (point-min))
792 (while (re-search-forward "[\040\t\r\n]+" nil t)
794 (goto-char (point-min))
795 (while (search-forward "<b>" nil t)
796 (replace-match "\n"))
797 (nnweb-remove-markup)
798 (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
799 (nnweb-decode-entities))
800 (goto-char (point-min))
802 (goto-char (point-min))
803 (while (re-search-forward "^\040+\\|\040+$" nil t)
805 (goto-char (point-min))
806 (while (re-search-forward "\040+" nil t)
808 (goto-char (point-max))
812 (unless (search-forward "<!-- Data -->" nil t)
813 (webmail-error "article@4"))
815 (delete-region p (point))
816 (goto-char (point-max))
817 (unless (re-search-backward
818 "[\040\t]*<br>[\040\t\r\n]*<br>[\040\t\r\n]*<form" p t)
819 (webmail-error "article@5"))
820 (delete-region (point) (point-max))
822 (while (search-forward
823 "<TABLE border=\"0\" WIDTH=\"98%\" cellpadding=0 cellspacing=0>"
826 (unless (search-forward "</TABLE>" nil t)
827 (webmail-error "article@6"))
829 (if (search-backward "<IMG " p t)
831 (unless (re-search-forward "HREF=\"\\(/tpl/Attachment/[^/]+/\\([^/]+/[^\?]+\\)[^\"]+\\)\"" p1 t)
832 (webmail-error "article@7"))
833 (setq attachment (match-string 1))
834 (setq type (match-string 2))
835 (unless (search-forward "</TABLE>" nil t)
836 (webmail-error "article@8"))
837 (delete-region p (point))
838 (let (bufname);; Attachment
840 (set-buffer (generate-new-buffer " *webmail-att*"))
841 (nnweb-insert (concat (car webmail-open-url) attachment))
842 (push (current-buffer) webmail-buffer-list)
843 (setq bufname (buffer-name)))
844 (insert "<#part type=" type)
845 (insert " buffer=\"" bufname "\"")
846 (insert " disposition=\"inline\"")
847 (insert "><#/part>\n")
853 "<TABLE border=\"0\" WIDTH=\"98%\" cellpadding=0 cellspacing=0>"
857 (webmail-netaddress-single-part)
858 (goto-char (point-max))
862 (narrow-to-region p (point-max))
863 (setq mime (webmail-netaddress-single-part))
865 (goto-char (point-min))
866 ;; Some blank line to seperate mails.
867 (insert "\n\nFrom nobody " (current-time-string) "\n")
868 (insert "X-Gnus-Webmail: " (symbol-value 'user)
869 "@" (symbol-name webmail-type) "\n")
871 (insert (format "X-Message-ID: <%s@%s>\n" id webmail-address)))
872 (unless (looking-at "$")
873 (if (search-forward "\n\n" nil t)
875 (webmail-error "article@2")))
877 (narrow-to-region (point-min) (point))
878 (goto-char (point-min))
880 (if (looking-at "MIME-Version\\|Content-Type")
881 (delete-region (point)
884 (if (re-search-forward "^[^ \t]" nil t)
885 (goto-char (match-beginning 0))
888 (goto-char (point-max))
890 (narrow-to-region (point) (point-max))
891 (insert "MIME-Version: 1.0\n"
894 (delete-region (point-min) (point-max))))
895 (goto-char (point-min))
897 (let (case-fold-search)
898 (while (re-search-forward "^From " nil t)
901 (mm-append-to-file (point-min) (point-max) file)))
903 (defun webmail-netscape-article (file id)
904 (let (p p1 attachment count mime type)
906 (webmail-encode-8bit)
907 (goto-char (point-min))
908 (if (not (search-forward "Trash" nil t))
909 (webmail-error "article@1"))
910 (if (not (search-forward "<form>" nil t))
911 (webmail-error "article@2"))
912 (delete-region (point-min) (match-beginning 0))
913 (if (not (search-forward "</form>" nil t))
914 (webmail-error "article@3"))
915 (narrow-to-region (point-min) (match-end 0))
916 (goto-char (point-min))
917 (while (re-search-forward "[\040\t\r\n]+" nil t)
919 (goto-char (point-min))
920 (while (re-search-forward "<a href=[^>]*>[^<]*</a>" nil t)
922 (goto-char (point-min))
923 (while (search-forward "<b>" nil t)
924 (replace-match "\n"))
925 (nnweb-remove-markup)
926 (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
927 (nnweb-decode-entities))
928 (goto-char (point-min))
930 (goto-char (point-min))
931 (while (re-search-forward "^\040+\\|\040+$" nil t)
933 (goto-char (point-min))
934 (while (re-search-forward "\040+" nil t)
936 (goto-char (point-max))
940 (unless (search-forward "<!-- Data -->" nil t)
941 (webmail-error "article@4"))
943 (delete-region p (point))
944 (goto-char (point-max))
945 (unless (re-search-backward
946 "<form name=\"Transfer2\"" p t)
947 (webmail-error "article@5"))
948 (delete-region (point) (point-max))
950 (while (search-forward
951 "<TABLE border=\"0\" WIDTH=\"98%\" cellpadding=0 cellspacing=0>"
954 (unless (search-forward "</TABLE>" nil t)
955 (webmail-error "article@6"))
957 (if (search-backward "<IMG " p t)
959 (unless (re-search-forward "HREF=\"\\(/tpl/Attachment/[^/]+/\\([^/]+/[^\?]+\\)[^\"]+\\)\"" p1 t)
960 (webmail-error "article@7"))
961 (setq attachment (match-string 1))
962 (setq type (match-string 2))
963 (unless (search-forward "</TABLE>" nil t)
964 (webmail-error "article@8"))
965 (delete-region p (point))
966 (let (bufname);; Attachment
968 (set-buffer (generate-new-buffer " *webmail-att*"))
969 (nnweb-insert (concat (car webmail-open-url) attachment))
970 (push (current-buffer) webmail-buffer-list)
971 (setq bufname (buffer-name)))
972 (insert "<#part type=" type)
973 (insert " buffer=\"" bufname "\"")
974 (insert " disposition=\"inline\"")
975 (insert "><#/part>\n")
981 "<TABLE border=\"0\" WIDTH=\"98%\" cellpadding=0 cellspacing=0>"
985 (webmail-netaddress-single-part)
986 (goto-char (point-max))
990 (narrow-to-region p (point-max))
991 (setq mime (webmail-netaddress-single-part))
993 (goto-char (point-min))
994 ;; Some blank line to seperate mails.
995 (insert "\n\nFrom nobody " (current-time-string) "\n")
996 (insert "X-Gnus-Webmail: " (symbol-value 'user)
997 "@" (symbol-name webmail-type) "\n")
999 (insert (format "X-Message-ID: <%s@%s>\n" id webmail-address)))
1000 (unless (looking-at "$")
1001 (if (search-forward "\n\n" nil t)
1003 (webmail-error "article@2")))
1005 (narrow-to-region (point-min) (point))
1006 (goto-char (point-min))
1008 (if (looking-at "MIME-Version\\|Content-Type")
1009 (delete-region (point)
1012 (if (re-search-forward "^[^ \t]" nil t)
1013 (goto-char (match-beginning 0))
1016 (goto-char (point-max))
1018 (narrow-to-region (point) (point-max))
1019 (insert "MIME-Version: 1.0\n"
1022 (delete-region (point-min) (point-max))))
1023 (goto-char (point-min))
1025 (let (case-fold-search)
1026 (while (re-search-forward "^From " nil t)
1029 (mm-append-to-file (point-min) (point-max) file)))
1033 (defun webmail-my-deja-open ()
1034 (webmail-refresh-redirect)
1035 (goto-char (point-min))
1036 (if (re-search-forward "action=\"\\([^\"]+login_confirm\\.xp[^\"]*\\)\""
1038 (setq webmail-aux (match-string 1))
1039 (webmail-error "open@1")))
1041 (defun webmail-my-deja-list ()
1042 (let (item id newp base)
1043 (goto-char (point-min))
1044 (when (re-search-forward "href=\"\\(\\([^\"]*\\)/mailnf\\.[^\"]*\\)\""
1046 (let ((url (match-string 1)))
1047 (setq base (match-string 2))
1049 (nnweb-insert url)))
1050 (goto-char (point-min))
1051 (when (re-search-forward
1052 "(\\([0-9]+\\) Message.?-[^>]*\\([0-9]+\\) New"
1054 (message "Found %s mail(s), %s unread"
1055 (match-string 1) (match-string 2)))
1056 (goto-char (point-min))
1057 (while (re-search-forward
1058 "newmail\\.gif\\|href=\"[^\"]*\\(mailnf\\.[^\"]+act=view[^\"]+mid=\\([^\"&]+\\)[^\"]+\\)\""
1060 (if (setq id (match-string 2))
1061 (when (and (or newp (not webmail-newmail-only))
1062 (not (assoc id webmail-articles)))
1063 (push (cons id (setq webmail-aux
1064 (concat base "/" (match-string 1))))
1068 (setq webmail-articles (nreverse webmail-articles))))
1070 (defun webmail-my-deja-article-part (base)
1073 ((looking-at "[\t\040\r\n]*<!--[^>]*>")
1075 ((looking-at "[\t\040\r\n]*</PRE>")
1077 ((looking-at "[\t\040\r\n]*<PRE>")
1081 (narrow-to-region (point)
1082 (if (re-search-forward "</?PRE>" nil t)
1085 (goto-char (point-min))
1086 (nnweb-remove-markup)
1087 (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
1088 (nnweb-decode-entities))
1089 (goto-char (point-max))))
1090 ((looking-at "[\t\040\r\n]*<TABLE")
1092 (narrow-to-region (point)
1093 (if (search-forward "</TABLE>" nil t 2)
1096 (goto-char (point-min))
1097 (let (name type url bufname)
1098 (if (and (search-forward "File Name:" nil t)
1099 (re-search-forward "<FONT[^>]+>\\([^<]+\\)" nil t))
1100 (setq name (match-string 1)))
1101 (if (and (search-forward "File Type:" nil t)
1102 (re-search-forward "<FONT[^>]+>\\([^<]+\\)" nil t))
1103 (setq type (match-string 1)))
1104 (unless (re-search-forward "action=\"getattach\\.cgi/\\([^\"]+\\)"
1106 (webmail-error "article@5"))
1107 (setq url (concat base "/getattach.cgi/" (match-string 1)
1109 (while (re-search-forward
1110 "type=hidden name=\"\\([^\"]+\\)\" value=\"\\([^\"]+\\)"
1112 (setq url (concat url "&" (match-string 1) "="
1114 (delete-region (point-min) (point-max))
1116 (set-buffer (generate-new-buffer " *webmail-att*"))
1118 (push (current-buffer) webmail-buffer-list)
1119 (setq bufname (buffer-name)))
1120 (insert "<#part type=\"" type "\"")
1121 (if name (insert " filename=\"" name "\""))
1122 (insert " buffer=\"" bufname "\"")
1123 (insert " disposition=inline><#/part>"))))
1125 (insert "<#part type=\"text/html\" disposition=inline>")
1126 (goto-char (point-max))
1127 (insert "<#/part>")))))
1129 (defun webmail-my-deja-article (file id)
1131 (goto-char (point-min))
1132 (unless (string-match "\\([^\"]+\\)/mail" webmail-aux)
1133 (webmail-error "article@0"))
1134 (setq base (match-string 1 webmail-aux))
1135 (when (re-search-forward
1136 "href=\"[^\"]*\\(mailnf\\.[^\"]+act=move[^\"]+mid=\\([^\"&]+\\)[^\"]+\\)\""
1138 (setq webmail-aux (concat base "/" (match-string 1)))
1139 (string-match "mid=[^\"&]+" webmail-aux)
1140 (setq webmail-aux (replace-match "mid=%s" nil nil webmail-aux)))
1141 (unless (search-forward "<HR noshade>" nil t)
1142 (webmail-error "article@1"))
1143 (delete-region (point-min) (point))
1144 (unless (search-forward "<HR noshade>" nil t)
1145 (webmail-error "article@2"))
1147 (narrow-to-region (point-min) (point))
1148 (while (search-forward "\r\n" nil t)
1149 (replace-match "\n"))
1150 (nnweb-remove-markup)
1151 (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
1152 (nnweb-decode-entities))
1153 (goto-char (point-min))
1154 (while (re-search-forward "\n\n+" nil t)
1155 (replace-match "\n"))
1156 (goto-char (point-max)))
1158 (narrow-to-region (point) (point-max))
1159 (goto-char (point-max))
1160 (unless (search-backward "<HR noshade>" nil t)
1161 (webmail-error "article@3"))
1162 (unless (search-backward "</TT>" nil t)
1163 (webmail-error "article@4"))
1164 (delete-region (point) (point-max))
1165 (goto-char (point-min))
1167 (webmail-my-deja-article-part base))
1168 (insert "MIME-Version: 1.0\n"
1171 (delete-region (point-min) (point-max)))))
1172 (goto-char (point-min))
1173 (insert "\n\nFrom nobody " (current-time-string) "\n")
1174 (insert "X-Gnus-Webmail: " (symbol-value 'user)
1175 "@" (symbol-name webmail-type) "\n")
1176 (if (eq (char-after) ?\n)
1178 (mm-append-to-file (point-min) (point-max) file)))
1182 ;;; webmail.el ends here