1 ;;; webmail.el --- interface of web mail
2 ;; Copyright (C) 1999, 2000, 2001 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&Domain=usa.net&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 "U2_USERNAME=%s&U2_PASSWORD=%s%s"
133 user password webmail-aux)
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-snarf . webmail-my-deja-open)
150 ("http://mydeja.google.com/cgi-bin/deja/maillogin.py")
151 "userid=%s&password=%s"
153 (list-snarf . webmail-my-deja-list)
154 (article-snarf . webmail-my-deja-article)
155 (trash-url webmail-aux id))))
157 (defvar webmail-variables
158 '(address article-snarf article-url list-snarf list-url
159 login-url login-snarf open-url open-snarf site articles
160 post-process paranoid trash-url))
162 (defconst webmail-version "webmail 1.0")
164 (defvar webmail-newmail-only nil
165 "Only fetch new mails.")
167 (defvar webmail-move-to-trash-can t
168 "Move mail to trash can after fetch it.")
170 ;;; Internal variables
172 (defvar webmail-address nil)
173 (defvar webmail-paranoid nil)
174 (defvar webmail-aux nil)
175 (defvar webmail-session nil)
176 (defvar webmail-article-snarf nil)
177 (defvar webmail-article-url nil)
178 (defvar webmail-list-snarf nil)
179 (defvar webmail-list-url nil)
180 (defvar webmail-login-url nil)
181 (defvar webmail-login-snarf nil)
182 (defvar webmail-open-snarf nil)
183 (defvar webmail-open-url nil)
184 (defvar webmail-trash-url nil)
185 (defvar webmail-articles nil)
186 (defvar webmail-post-process nil)
188 (defvar webmail-buffer nil)
189 (defvar webmail-buffer-list nil)
191 (defvar webmail-type nil)
193 (defvar webmail-error-function nil)
195 (defvar webmail-debug-file "~/.emacs-webmail-debug")
197 ;;; Interface functions
199 (defun webmail-debug (str)
201 (insert "\n---------------- A bug at " str " ------------------\n")
202 (mapcar #'(lambda (sym)
204 (pp `(setq ,sym ',(eval sym)) (current-buffer))))
205 '(webmail-type user))
206 (insert "---------------- webmail buffer ------------------\n\n")
207 (insert-buffer-substring webmail-buffer)
208 (insert "\n---------------- end of buffer ------------------\n\n")
209 (append-to-file (point-min) (point-max) webmail-debug-file)))
211 (defun webmail-error (str)
212 (if webmail-error-function
213 (funcall webmail-error-function str))
214 (message "%s HTML has changed or your w3 package is too old.(%s)"
216 (error "%s HTML has changed or your w3 package is too old.(%s)"
219 (defun webmail-setdefault (type)
220 (let ((type-def (cdr (assq type webmail-type-definition)))
221 (vars webmail-variables)
223 (setq webmail-type type)
225 (if (setq pair (assq var type-def))
226 (set (intern (concat "webmail-" (symbol-name var))) (cdr pair))
227 (set (intern (concat "webmail-" (symbol-name var))) nil)))))
229 (defun webmail-encode-www-form-urlencoded (pairs)
230 "Return PAIRS encoded for forms."
234 (concat (w3-form-encode-xwfu (car data)) "="
235 (w3-form-encode-xwfu (cdr data)))))
238 (defun webmail-fetch-simple (url content)
239 (let ((url-request-data content)
240 (url-request-method "POST")
241 (url-request-extra-headers
242 '(("Content-type" . "application/x-www-form-urlencoded"))))
246 (defun webmail-fetch-form (url pairs)
247 (let ((url-request-data (webmail-encode-www-form-urlencoded pairs))
248 (url-request-method "POST")
249 (url-request-extra-headers
250 '(("Content-type" . "application/x-www-form-urlencoded"))))
254 (defun webmail-eval (expr)
257 (cons (webmail-eval (car expr)) (webmail-eval (cdr expr))))
263 (defun webmail-url (xurl)
264 (mm-with-unibyte-current-buffer
266 ((eq (car xurl) 'content)
268 (webmail-fetch-simple (if (stringp (car xurl))
270 (apply 'format (webmail-eval (car xurl))))
271 (apply 'format (webmail-eval (cdr xurl)))))
272 ((eq (car xurl) 'post)
274 (webmail-fetch-form (car xurl) (webmail-eval (cdr xurl))))
276 (nnweb-insert (apply 'format (webmail-eval xurl)))))))
278 (defun webmail-init ()
279 "Initialize buffers and such."
280 (if (gnus-buffer-live-p webmail-buffer)
281 (set-buffer webmail-buffer)
283 (nnheader-set-temp-buffer " *webmail*"))
284 (mm-disable-multibyte)))
286 (defvar url-package-name)
287 (defvar url-package-version)
288 (defvar url-cookie-multiple-line)
289 (defvar url-confirmation-func)
291 ;; Hack W3 POST redirect. See `url-parse-mime-headers'.
293 ;; Netscape uses "GET" as redirect method when orignal method is POST
294 ;; and status is 302, .i.e no security risks by default without
297 ;; Some web servers (at least Apache used by yahoo) return status 302
298 ;; instead of 303, though they mean 303.
300 (defun webmail-url-confirmation-func (prompt)
302 ((equal prompt (concat "Honor redirection with non-GET method "
303 "(possible security risks)? "))
305 ((equal prompt "Continue (with method of GET)? ")
309 (defun webmail-refresh-redirect ()
310 "Redirect refresh url in META."
311 (goto-char (point-min))
312 (while (re-search-forward
313 "<meta[ \t\r\n]*http-equiv=\"Refresh\"[^>]*URL=\\([^\"]+\\)\""
315 (let ((url (match-string 1)))
317 (mm-with-unibyte-current-buffer
319 (goto-char (point-min))))
321 (defun webmail-fetch (file subtype user password)
323 (webmail-setdefault subtype)
324 (let ((url-package-name (if (memq 'agent webmail-paranoid)
327 (url-package-version (if (memq 'agent webmail-paranoid)
329 url-package-version))
330 (url-cookie-multiple-line (if (memq 'cookie webmail-paranoid)
332 url-cookie-multiple-line))
333 (url-confirmation-func (if (memq 'post webmail-paranoid)
334 'webmail-url-confirmation-func
335 url-confirmation-func))
336 (url-http-silence-on-insecure-redirection t)
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\\?[^\"]*a=b[^\"]*\\)" nil t)
407 (setq webmail-aux (concat "http://" site (match-string 1)))
408 (webmail-error "login@2"))))
410 (defun webmail-hotmail-list ()
411 (goto-char (point-min))
412 (skip-chars-forward " \t\n\r")
413 (let (site url newp (total "0"))
416 (if (re-search-forward "\\([0-9]+\\) *<b>(\\([0-9]+\\) new)" nil t)
417 (message "Found %s (%s new)" (setq total (match-string 1))
419 (if (re-search-forward "\\([0-9]+\\) new" nil t)
420 (message "Found %s new" (setq total (match-string 1)))
421 (webmail-error "list@0"))))
422 (unless (equal total "0")
423 (goto-char (point-min))
424 (if (re-search-forward
425 "https?://\\([^/]+hotmail\\.msn\\.com\\)/cgi-bin/" nil t)
426 (setq site (match-string 1))
427 (webmail-error "list@1"))
428 (goto-char (point-min))
429 (if (re-search-forward "disk=\\([^&]*\\)&" nil t)
431 (concat "http://" site "/cgi-bin/HoTMaiL?disk="
433 (webmail-error "list@2"))
434 (goto-char (point-max))
435 (while (re-search-backward
436 "newmail\\.gif\\|href=\"\\(/cgi-bin/getmsg\\?[^\"]+\\)\""
438 (if (setq url (match-string 1))
440 (if (or newp (not webmail-newmail-only))
442 (if (string-match "msg=\\([^&]+\\)" url)
443 (setq id (match-string 1 url)))
444 (push (cons id (concat "http://" site url "&raw=0"))
449 ;; Thank victor@idaccr.org (Victor S. Miller) for raw=0
451 (defun webmail-hotmail-article (file id)
452 (goto-char (point-min))
453 (skip-chars-forward " \t\n\r")
455 (if (not (search-forward "<pre>" nil t))
456 (webmail-error "article@3"))
457 (skip-chars-forward "\n\r\t ")
458 (delete-region (point-min) (point))
459 (if (not (search-forward "</pre>" nil t))
460 (webmail-error "article@3.1"))
461 (delete-region (match-beginning 0) (point-max))
462 (nnweb-remove-markup)
463 (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
464 (nnweb-decode-entities))
465 (goto-char (point-min))
466 (while (re-search-forward "\r\n?" nil t)
467 (replace-match "\n"))
468 (goto-char (point-min))
470 (if (not (looking-at "\n*From "))
471 (insert "From nobody " (current-time-string) "\n")
473 (insert "X-Gnus-Webmail: " (symbol-value 'user)
474 "@" (symbol-name webmail-type) "\n")
475 (mm-append-to-file (point-min) (point-max) file)))
477 (defun webmail-hotmail-article-old (file id)
478 (let (p attachment count mime hotmail-direct)
480 (webmail-encode-8bit)
481 (goto-char (point-min))
482 (if (not (search-forward "<DIV>" nil t))
483 (if (not (search-forward "Reply All" nil t))
484 (webmail-error "article@1")
485 (setq hotmail-direct t))
486 (goto-char (match-beginning 0)))
487 (narrow-to-region (point-min) (point))
488 (if (not (search-backward "<table" nil t 2))
489 (webmail-error "article@1.1"))
490 (delete-region (point-min) (match-beginning 0))
491 (while (search-forward "<a href=" nil t)
492 (setq p (match-beginning 0))
493 (search-forward "</a>" nil t)
494 (delete-region p (match-end 0)))
495 (nnweb-remove-markup)
496 (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
497 (nnweb-decode-entities))
498 (goto-char (point-min))
500 (goto-char (point-min))
501 (when (search-forward "\n\n" nil t)
503 (delete-region (point) (point-max)))
504 (goto-char (point-max))
508 (while (re-search-forward
509 "<tt>\\|<div>\\|\\(http://[^/]+/cgi-bin/getmsg/\\([^\?]+\\)\?[^\"]*\\)\""
511 (if (setq attachment (match-string 1))
512 (let ((filename (match-string 2))
513 bufname);; Attachment
514 (delete-region p (match-end 0))
516 (set-buffer (generate-new-buffer " *webmail-att*"))
517 (nnweb-insert attachment)
518 (push (current-buffer) webmail-buffer-list)
519 (setq bufname (buffer-name)))
521 (insert "<#part type="
523 (string-match "\\.[^\\.]+$" filename)
524 (mailcap-extension-to-mime
525 (match-string 0 filename)))
526 "application/octet-stream"))
527 (insert " buffer=\"" bufname "\"")
528 (insert " filename=\"" filename "\"")
529 (insert " disposition=\"inline\"")
530 (insert "><#/part>\n")
532 (delete-region p (match-end 0))
534 (if (not (search-forward "</tt>" nil t))
535 (webmail-error "article@1.2")
536 (delete-region (match-beginning 0) (match-end 0)))
538 (while (and (> count 0)
539 (re-search-forward "</div>\\|\\(<div>\\)" nil t))
541 (setq count (1+ count))
542 (if (= (setq count (1- count)) 0)
543 (delete-region (match-beginning 0)
545 (narrow-to-region p (point))
546 (goto-char (point-min))
548 ((looking-at "<pre>")
549 (goto-char (match-end 0))
550 (if (looking-at "$") (forward-char))
551 (delete-region (point-min) (point))
552 (nnweb-remove-markup)
553 (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
554 (nnweb-decode-entities))
558 (insert "<#part type=\"text/html\" disposition=inline>")
559 (goto-char (point-max))
560 (insert "<#/part>")))
561 (goto-char (point-max))
564 (delete-region p (point-max))
565 (goto-char (point-min))
566 ;; Some blank line to seperate mails.
567 (insert "\n\nFrom nobody " (current-time-string) "\n")
568 (insert "X-Gnus-Webmail: " (symbol-value 'user)
569 "@" (symbol-name webmail-type) "\n")
571 (insert (format "X-Message-ID: <%s@hotmail.com>\n" id)))
572 (unless (looking-at "$")
573 (if (search-forward "\n\n" nil t)
575 (webmail-error "article@2")))
576 (narrow-to-region (point) (point-max))
578 (insert "MIME-Version: 1.0\n"
581 (delete-region (point-min) (point-max)))))
582 (goto-char (point-min))
584 (let (case-fold-search)
585 (while (re-search-forward "^From " nil t)
588 (mm-append-to-file (point-min) (point-max) file)))
592 (defun webmail-yahoo-open ()
593 (goto-char (point-min))
594 (if (re-search-forward "action=\"\\([^\"]+\\)\"" nil t)
595 (setq webmail-aux (match-string 1))
596 (webmail-error "open@1")))
598 (defun webmail-yahoo-login ()
599 (goto-char (point-min))
600 (if (re-search-forward "http://[^/]+[0-9]\\.mail\\.yahoo\\.com/" nil t)
601 (setq webmail-aux (match-string 0))
602 (webmail-error "login@1"))
603 (if (re-search-forward "YY=[0-9]+" nil t)
604 (setq webmail-aux (concat webmail-aux "ym/ShowFolder?"
606 (webmail-error "login@2")))
608 (defun webmail-yahoo-list ()
609 (let (url (newp t) (tofetch 0))
610 (goto-char (point-min))
611 (when (re-search-forward
612 "showing [0-9]+-\\([0-9]+\\) of \\([0-9]+\\)" nil t)
613 ;;(setq listed (match-string 1))
614 (message "Found %s mail(s)" (match-string 2)))
615 (if (string-match "http://[^/]+" webmail-aux)
616 (setq webmail-aux (match-string 0 webmail-aux))
617 (webmail-error "list@1"))
618 (goto-char (point-min))
619 (while (re-search-forward
620 "bgcolor=\"#eeeeee\"\\|href=\"\\(/ym/ShowLetter\\?MsgId=\\([^&]+\\)&[^\"]*\\)\""
622 (if (setq url (match-string 1))
624 (when (or newp (not webmail-newmail-only))
625 (push (cons (match-string 2) (concat webmail-aux url "&toc=1"))
627 (setq tofetch (1+ tofetch)))
630 (setq webmail-articles (nreverse webmail-articles))
631 (message "Fetching %d mail(s)" tofetch)))
633 (defun webmail-yahoo-article (file id)
636 (goto-char (point-min))
637 (if (not (search-forward "value=\"Done\"" nil t))
638 (webmail-error "article@1"))
639 (if (not (search-forward "<table" nil t))
640 (webmail-error "article@2"))
641 (delete-region (point-min) (match-beginning 0))
642 (if (not (search-forward "</table>" nil t))
643 (webmail-error "article@3"))
644 (narrow-to-region (point-min) (match-end 0))
645 (while (search-forward "<a href=" nil t)
646 (setq p (match-beginning 0))
647 (search-forward "</a>" nil t)
648 (delete-region p (match-end 0)))
649 (nnweb-remove-markup)
650 (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
651 (nnweb-decode-entities))
652 (goto-char (point-min))
654 (goto-char (point-max))
658 (while (re-search-forward "[^\"]*/ShowLetter/[^\?]+\?[^\"]*" nil t)
659 (setq attachment (match-string 0))
660 (let (bufname ct ctl cd description)
661 (if (not (search-forward "<table" nil t))
662 (webmail-error "article@4"))
663 (delete-region p (match-beginning 0))
664 (if (not (search-forward "</table>" nil t))
665 (webmail-error "article@5"))
666 (narrow-to-region p (match-end 0))
667 (nnweb-remove-markup)
668 (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
669 (nnweb-decode-entities))
670 (goto-char (point-min))
672 (setq ct (mail-fetch-field "content-type")
673 ctl (ignore-errors (mail-header-parse-content-type ct))
674 ;;cte (mail-fetch-field "content-transfer-encoding")
675 cd (mail-fetch-field "content-disposition")
676 description (mail-fetch-field "content-description")
677 id (mail-fetch-field "content-id"))
678 (delete-region (point-min) (point-max))
681 (set-buffer (generate-new-buffer " *webmail-att*"))
682 (nnweb-insert (concat webmail-aux attachment))
683 (push (current-buffer) webmail-buffer-list)
684 (setq bufname (buffer-name)))
686 (if (and ctl (not (equal (car ctl) "text/")))
687 (insert " type=\"" (car ctl) "\""))
688 (insert " buffer=\"" bufname "\"")
690 (insert " disposition=\"" cd "\""))
692 (insert " description=\"" description "\""))
693 (insert "><#/part>\n")
695 (delete-region p (point-max))
696 (goto-char (point-min))
697 ;; Some blank line to seperate mails.
698 (insert "\n\nFrom nobody " (current-time-string) "\n")
699 (insert "X-Gnus-Webmail: " (symbol-value 'user)
700 "@" (symbol-name webmail-type) "\n")
702 (insert (format "X-Message-ID: <%s@yahoo.com>\n" id)))
703 (unless (looking-at "$")
704 (if (search-forward "\n\n" nil t)
706 (webmail-error "article@2")))
707 (narrow-to-region (point) (point-max))
708 (insert "MIME-Version: 1.0\n"
711 (delete-region (point-min) (point-max))))
712 (goto-char (point-min))
714 (let (case-fold-search)
715 (while (re-search-forward "^From " nil t)
718 (mm-append-to-file (point-min) (point-max) file)))
722 (defun webmail-netscape-open ()
723 (goto-char (point-min))
724 (setq webmail-aux "")
725 (while (re-search-forward
726 "TYPE=hidden *NAME=\\([^ ]+\\) *VALUE=\"\\([^\"]+\\)"
728 (setq webmail-aux (concat webmail-aux "&" (match-string 1) "="
731 (defun webmail-netaddress-open ()
732 (goto-char (point-min))
733 (if (re-search-forward "action=\"\\([^\"]+\\)\"" nil t)
734 (setq webmail-aux (concat (car webmail-open-url) (match-string 1)))
735 (webmail-error "open@1")))
737 (defun webmail-netaddress-login ()
738 (webmail-refresh-redirect)
739 (goto-char (point-min))
740 (if (re-search-forward "tpl/[^/]+/\\([^/]+\\)" nil t)
741 (setq webmail-session (match-string 1))
742 (webmail-error "login@1")))
744 (defun webmail-netaddress-list ()
745 (webmail-refresh-redirect)
747 (goto-char (point-min))
748 (when (re-search-forward
749 "(\\([0-9]+\\) unread, \\([0-9]+\\) total)" nil t)
750 (message "Found %s mail(s), %s unread"
751 (match-string 2) (match-string 1)))
752 (goto-char (point-min))
753 (while (re-search-forward
754 "MR\\[i\\]\\.R='\\([^']*\\)'\\|MR\\[i\\]\\.Q='\\([^']+\\)'" nil t)
755 (if (setq id (match-string 2))
758 (format "%s/tpl/Message/%s/Read?Q=%s&FolderID=-4&SortUseCase=True&Sort=Date&Headers=True"
759 (car webmail-article-url)
760 webmail-session id)))
761 (if (or (not webmail-newmail-only)
762 (equal (match-string 1) "True"))
763 (push item webmail-articles))))
764 (setq webmail-articles (nreverse webmail-articles))))
766 (defun webmail-netaddress-single-part ()
767 (goto-char (point-min))
769 ((looking-at "[\t\040\r\n]*<font face=[^>]+>[\t\040\r\n]*")
772 (while (re-search-forward "[\t\040\r\n]+" nil t)
774 (goto-char (point-min))
775 (while (re-search-forward "<br>" nil t)
776 (replace-match "\n"))
777 (nnweb-remove-markup)
778 (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
779 (nnweb-decode-entities))
782 (insert "<#part type=\"text/html\" disposition=inline>")
783 (goto-char (point-max))
787 (defun webmail-netaddress-article (file id)
788 (webmail-refresh-redirect)
789 (let (p p1 attachment count mime type)
791 (webmail-encode-8bit)
792 (goto-char (point-min))
793 (if (not (search-forward "Trash" nil t))
794 (webmail-error "article@1"))
795 (if (not (search-forward "<form>" nil t))
796 (webmail-error "article@2"))
797 (delete-region (point-min) (match-beginning 0))
798 (if (not (search-forward "</form>" nil t))
799 (webmail-error "article@3"))
800 (narrow-to-region (point-min) (match-end 0))
801 (goto-char (point-min))
802 (while (re-search-forward "[\040\t\r\n]+" nil t)
804 (goto-char (point-min))
805 (while (search-forward "<b>" nil t)
806 (replace-match "\n"))
807 (nnweb-remove-markup)
808 (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
809 (nnweb-decode-entities))
810 (goto-char (point-min))
812 (goto-char (point-min))
813 (while (re-search-forward "^\040+\\|\040+$" nil t)
815 (goto-char (point-min))
816 (while (re-search-forward "\040+" nil t)
818 (goto-char (point-max))
822 (unless (search-forward "<!-- Data -->" nil t)
823 (webmail-error "article@4"))
825 (delete-region p (point))
826 (goto-char (point-max))
827 (unless (re-search-backward
828 "[\040\t]*<br>[\040\t\r\n]*<br>[\040\t\r\n]*<form" p t)
829 (webmail-error "article@5"))
830 (delete-region (point) (point-max))
832 (while (search-forward
833 "<TABLE border=\"0\" WIDTH=\"98%\" cellpadding=0 cellspacing=0>"
836 (unless (search-forward "</TABLE>" nil t)
837 (webmail-error "article@6"))
839 (if (search-backward "<IMG " p t)
841 (unless (re-search-forward "HREF=\"\\(/tpl/Attachment/[^/]+/\\([^/]+/[^\?]+\\)[^\"]+\\)\"" p1 t)
842 (webmail-error "article@7"))
843 (setq attachment (match-string 1))
844 (setq type (match-string 2))
845 (unless (search-forward "</TABLE>" nil t)
846 (webmail-error "article@8"))
847 (delete-region p (point))
848 (let (bufname);; Attachment
850 (set-buffer (generate-new-buffer " *webmail-att*"))
851 (nnweb-insert (concat (car webmail-open-url) attachment))
852 (push (current-buffer) webmail-buffer-list)
853 (setq bufname (buffer-name)))
854 (insert "<#part type=" type)
855 (insert " buffer=\"" bufname "\"")
856 (insert " disposition=\"inline\"")
857 (insert "><#/part>\n")
863 "<TABLE border=\"0\" WIDTH=\"98%\" cellpadding=0 cellspacing=0>"
867 (webmail-netaddress-single-part)
868 (goto-char (point-max))
872 (narrow-to-region p (point-max))
873 (setq mime (webmail-netaddress-single-part))
875 (goto-char (point-min))
876 ;; Some blank line to seperate mails.
877 (insert "\n\nFrom nobody " (current-time-string) "\n")
878 (insert "X-Gnus-Webmail: " (symbol-value 'user)
879 "@" (symbol-name webmail-type) "\n")
881 (insert (format "X-Message-ID: <%s@%s>\n" id webmail-address)))
882 (unless (looking-at "$")
883 (if (search-forward "\n\n" nil t)
885 (webmail-error "article@2")))
887 (narrow-to-region (point-min) (point))
888 (goto-char (point-min))
890 (if (looking-at "MIME-Version\\|Content-Type")
891 (delete-region (point)
894 (if (re-search-forward "^[^ \t]" nil t)
895 (goto-char (match-beginning 0))
898 (goto-char (point-max))
900 (narrow-to-region (point) (point-max))
901 (insert "MIME-Version: 1.0\n"
904 (delete-region (point-min) (point-max))))
905 (goto-char (point-min))
907 (let (case-fold-search)
908 (while (re-search-forward "^From " nil t)
911 (mm-append-to-file (point-min) (point-max) file)))
913 (defun webmail-netscape-article (file id)
914 (let (p p1 attachment count mime type)
916 (webmail-encode-8bit)
917 (goto-char (point-min))
918 (if (not (search-forward "Trash" nil t))
919 (webmail-error "article@1"))
920 (if (not (search-forward "<form>" nil t))
921 (webmail-error "article@2"))
922 (delete-region (point-min) (match-beginning 0))
923 (if (not (search-forward "</form>" nil t))
924 (webmail-error "article@3"))
925 (narrow-to-region (point-min) (match-end 0))
926 (goto-char (point-min))
927 (while (re-search-forward "[\040\t\r\n]+" nil t)
929 (goto-char (point-min))
930 (while (re-search-forward "<a href=[^>]*>[^<]*</a>" nil t)
932 (goto-char (point-min))
933 (while (search-forward "<b>" nil t)
934 (replace-match "\n"))
935 (nnweb-remove-markup)
936 (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
937 (nnweb-decode-entities))
938 (goto-char (point-min))
940 (goto-char (point-min))
941 (while (re-search-forward "^\040+\\|\040+$" nil t)
943 (goto-char (point-min))
944 (while (re-search-forward "\040+" nil t)
946 (goto-char (point-max))
950 (unless (search-forward "<!-- Data -->" nil t)
951 (webmail-error "article@4"))
953 (delete-region p (point))
954 (goto-char (point-max))
955 (unless (re-search-backward
956 "<form name=\"Transfer2\"" p t)
957 (webmail-error "article@5"))
958 (delete-region (point) (point-max))
960 (while (search-forward
961 "<TABLE border=\"0\" WIDTH=\"98%\" cellpadding=0 cellspacing=0>"
964 (unless (search-forward "</TABLE>" nil t)
965 (webmail-error "article@6"))
967 (if (search-backward "<IMG " p t)
969 (unless (re-search-forward "HREF=\"\\(/tpl/Attachment/[^/]+/\\([^/]+/[^\?]+\\)[^\"]+\\)\"" p1 t)
970 (webmail-error "article@7"))
971 (setq attachment (match-string 1))
972 (setq type (match-string 2))
973 (unless (search-forward "</TABLE>" nil t)
974 (webmail-error "article@8"))
975 (delete-region p (point))
976 (let (bufname);; Attachment
978 (set-buffer (generate-new-buffer " *webmail-att*"))
979 (nnweb-insert (concat (car webmail-open-url) attachment))
980 (push (current-buffer) webmail-buffer-list)
981 (setq bufname (buffer-name)))
982 (insert "<#part type=" type)
983 (insert " buffer=\"" bufname "\"")
984 (insert " disposition=\"inline\"")
985 (insert "><#/part>\n")
991 "<TABLE border=\"0\" WIDTH=\"98%\" cellpadding=0 cellspacing=0>"
995 (webmail-netaddress-single-part)
996 (goto-char (point-max))
1000 (narrow-to-region p (point-max))
1001 (setq mime (webmail-netaddress-single-part))
1003 (goto-char (point-min))
1004 ;; Some blank line to seperate mails.
1005 (insert "\n\nFrom nobody " (current-time-string) "\n")
1006 (insert "X-Gnus-Webmail: " (symbol-value 'user)
1007 "@" (symbol-name webmail-type) "\n")
1009 (insert (format "X-Message-ID: <%s@%s>\n" id webmail-address)))
1010 (unless (looking-at "$")
1011 (if (search-forward "\n\n" nil t)
1013 (webmail-error "article@2")))
1015 (narrow-to-region (point-min) (point))
1016 (goto-char (point-min))
1018 (if (looking-at "MIME-Version\\|Content-Type")
1019 (delete-region (point)
1022 (if (re-search-forward "^[^ \t]" nil t)
1023 (goto-char (match-beginning 0))
1026 (goto-char (point-max))
1028 (narrow-to-region (point) (point-max))
1029 (insert "MIME-Version: 1.0\n"
1032 (delete-region (point-min) (point-max))))
1033 (goto-char (point-min))
1035 (let (case-fold-search)
1036 (while (re-search-forward "^From " nil t)
1039 (mm-append-to-file (point-min) (point-max) file)))
1043 (defun webmail-my-deja-open ()
1044 (webmail-refresh-redirect)
1045 (goto-char (point-min))
1046 (if (re-search-forward "action=\"\\([^\"]+maillogin\\.py[^\"]*\\)\""
1048 (setq webmail-aux (match-string 1))
1049 (webmail-error "open@1")))
1051 (defun webmail-my-deja-list ()
1052 (let (item id newp base)
1053 (goto-char (point-min))
1054 (when (re-search-forward "href=\"\\(\\([^\"]*\\)/mailnf\\.[^\"]*\\)\""
1056 (let ((url (match-string 1)))
1057 (setq base (match-string 2))
1059 (nnweb-insert url)))
1060 (goto-char (point-min))
1061 (when (re-search-forward
1062 "(\\([0-9]+\\) Message.?-[^>]*\\([0-9]+\\) New"
1064 (message "Found %s mail(s), %s unread"
1065 (match-string 1) (match-string 2)))
1066 (goto-char (point-min))
1067 (while (re-search-forward
1068 "newmail\\.gif\\|href=\"[^\"]*\\(mailnf\\.[^\"]+act=view[^\"]+mid=\\([^\"&]+\\)[^\"]+\\)\""
1070 (if (setq id (match-string 2))
1071 (when (and (or newp (not webmail-newmail-only))
1072 (not (assoc id webmail-articles)))
1073 (push (cons id (setq webmail-aux
1074 (concat base "/" (match-string 1))))
1078 (setq webmail-articles (nreverse webmail-articles))))
1080 (defun webmail-my-deja-article-part (base)
1083 ((looking-at "[\t\040\r\n]*<!--[^>]*>")
1085 ((looking-at "[\t\040\r\n]*</PRE>")
1087 ((looking-at "[\t\040\r\n]*<PRE>")
1091 (narrow-to-region (point)
1092 (if (re-search-forward "</?PRE>" nil t)
1095 (goto-char (point-min))
1096 (nnweb-remove-markup)
1097 (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
1098 (nnweb-decode-entities))
1099 (goto-char (point-max))))
1100 ((looking-at "[\t\040\r\n]*<TABLE")
1102 (narrow-to-region (point)
1103 (if (search-forward "</TABLE>" nil t 2)
1106 (goto-char (point-min))
1107 (let (name type url bufname)
1108 (if (and (search-forward "File Name:" nil t)
1109 (re-search-forward "<FONT[^>]+>\\([^<]+\\)" nil t))
1110 (setq name (match-string 1)))
1111 (if (and (search-forward "File Type:" nil t)
1112 (re-search-forward "<FONT[^>]+>\\([^<]+\\)" nil t))
1113 (setq type (match-string 1)))
1114 (unless (re-search-forward "action=\"getattach\\.cgi/\\([^\"]+\\)"
1116 (webmail-error "article@5"))
1117 (setq url (concat base "/getattach.cgi/" (match-string 1)
1119 (while (re-search-forward
1120 "type=hidden name=\"\\([^\"]+\\)\" value=\"\\([^\"]+\\)"
1122 (setq url (concat url "&" (match-string 1) "="
1124 (delete-region (point-min) (point-max))
1126 (set-buffer (generate-new-buffer " *webmail-att*"))
1128 (push (current-buffer) webmail-buffer-list)
1129 (setq bufname (buffer-name)))
1130 (insert "<#part type=\"" type "\"")
1131 (if name (insert " filename=\"" name "\""))
1132 (insert " buffer=\"" bufname "\"")
1133 (insert " disposition=inline><#/part>"))))
1135 (insert "<#part type=\"text/html\" disposition=inline>")
1136 (goto-char (point-max))
1137 (insert "<#/part>")))))
1139 (defun webmail-my-deja-article (file id)
1141 (goto-char (point-min))
1142 (unless (string-match "\\([^\"]+\\)/mail" webmail-aux)
1143 (webmail-error "article@0"))
1144 (setq base (match-string 1 webmail-aux))
1145 (when (re-search-forward
1146 "href=\"[^\"]*\\(mailnf\\.[^\"]+act=move[^\"]+mid=\\([^\"&]+\\)[^\"]+\\)\""
1148 (setq webmail-aux (concat base "/" (match-string 1)))
1149 (string-match "mid=[^\"&]+" webmail-aux)
1150 (setq webmail-aux (replace-match "mid=%s" nil nil webmail-aux)))
1151 (unless (search-forward "<HR noshade>" nil t)
1152 (webmail-error "article@1"))
1153 (delete-region (point-min) (point))
1154 (unless (search-forward "<HR noshade>" nil t)
1155 (webmail-error "article@2"))
1157 (narrow-to-region (point-min) (point))
1158 (while (search-forward "\r\n" nil t)
1159 (replace-match "\n"))
1160 (nnweb-remove-markup)
1161 (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities)))
1162 (nnweb-decode-entities))
1163 (goto-char (point-min))
1164 (while (re-search-forward "\n\n+" nil t)
1165 (replace-match "\n"))
1166 (goto-char (point-max)))
1168 (narrow-to-region (point) (point-max))
1169 (goto-char (point-max))
1170 (unless (search-backward "<HR noshade>" nil t)
1171 (webmail-error "article@3"))
1172 (unless (search-backward "</TT>" nil t)
1173 (webmail-error "article@4"))
1174 (delete-region (point) (point-max))
1175 (goto-char (point-min))
1177 (webmail-my-deja-article-part base))
1178 (insert "MIME-Version: 1.0\n"
1181 (delete-region (point-min) (point-max)))))
1182 (goto-char (point-min))
1183 (insert "\n\nFrom nobody " (current-time-string) "\n")
1184 (insert "X-Gnus-Webmail: " (symbol-value 'user)
1185 "@" (symbol-name webmail-type) "\n")
1186 (if (eq (char-after) ?\n)
1188 (mm-append-to-file (point-min) (point-max) file)))
1192 ;;; webmail.el ends here