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-url "http://www.deja.com/my/pr.xp")
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 or your w3 package is too old.(%s)"
218 (error "%s HTML has changed or your w3 package is too old.(%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
)
285 (nnheader-set-temp-buffer " *webmail*"))
286 (mm-disable-multibyte)))
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 ()
413 (goto-char (point-min))
414 (skip-chars-forward " \t\n\r")
415 (let (site url newp
(total "0"))
418 (if (re-search-forward "\\([0-9]+\\) *<b>(\\([0-9]+\\) new)" nil t
)
419 (message "Found %s (%s new)" (setq total
(match-string 1))
421 (if (re-search-forward "\\([0-9]+\\) new" nil t
)
422 (message "Found %s new" (setq total
(match-string 1)))
423 (webmail-error "list@0"))))
424 (unless (equal total
"0")
425 (goto-char (point-min))
426 (if (re-search-forward
427 "https?://\\([^/]+hotmail\\.msn\\.com\\)/cgi-bin/" nil t
)
428 (setq site
(match-string 1))
429 (webmail-error "list@1"))
430 (goto-char (point-min))
431 (if (re-search-forward "disk=\\([^&]*\\)&" nil t
)
433 (concat "http://" site
"/cgi-bin/HoTMaiL?disk="
435 (webmail-error "list@2"))
436 (goto-char (point-max))
437 (while (re-search-backward
438 "newmail\\.gif\\|href=\"\\(/cgi-bin/getmsg\\?[^\"]+\\)\""
440 (if (setq url
(match-string 1))
442 (if (or newp
(not webmail-newmail-only
))
444 (if (string-match "msg=\\([^&]+\\)" url
)
445 (setq id
(match-string 1 url
)))
446 (push (cons id
(concat "http://" site url
"&raw=0"))
451 ;; Thank victor@idaccr.org (Victor S. Miller) for raw=0
453 (defun webmail-hotmail-article (file id
)
454 (goto-char (point-min))
455 (skip-chars-forward " \t\n\r")
457 (if (not (search-forward "<pre>" nil t
))
458 (webmail-error "article@3"))
459 (skip-chars-forward "\n\r\t ")
460 (delete-region (point-min) (point))
461 (if (not (search-forward "</pre>" nil t
))
462 (webmail-error "article@3.1"))
463 (delete-region (match-beginning 0) (point-max))
464 (nnweb-remove-markup)
465 (let ((w3-html-entities (cons '(nbsp .
32) w3-html-entities
)))
466 (nnweb-decode-entities))
467 (goto-char (point-min))
468 (while (re-search-forward "\r\n?" nil t
)
469 (replace-match "\n"))
470 (goto-char (point-min))
472 (if (not (looking-at "\n*From "))
473 (insert "From nobody " (current-time-string) "\n")
475 (insert "X-Gnus-Webmail: " (symbol-value 'user
)
476 "@" (symbol-name webmail-type
) "\n")
477 (mm-append-to-file (point-min) (point-max) file
)))
479 (defun webmail-hotmail-article-old (file id
)
480 (let (p attachment count mime hotmail-direct
)
482 (webmail-encode-8bit)
483 (goto-char (point-min))
484 (if (not (search-forward "<DIV>" nil t
))
485 (if (not (search-forward "Reply All" nil t
))
486 (webmail-error "article@1")
487 (setq hotmail-direct t
))
488 (goto-char (match-beginning 0)))
489 (narrow-to-region (point-min) (point))
490 (if (not (search-backward "<table" nil t
2))
491 (webmail-error "article@1.1"))
492 (delete-region (point-min) (match-beginning 0))
493 (while (search-forward "<a href=" nil t
)
494 (setq p
(match-beginning 0))
495 (search-forward "</a>" nil t
)
496 (delete-region p
(match-end 0)))
497 (nnweb-remove-markup)
498 (let ((w3-html-entities (cons '(nbsp .
32) w3-html-entities
)))
499 (nnweb-decode-entities))
500 (goto-char (point-min))
502 (goto-char (point-min))
503 (when (search-forward "\n\n" nil t
)
505 (delete-region (point) (point-max)))
506 (goto-char (point-max))
510 (while (re-search-forward
511 "<tt>\\|<div>\\|\\(http://[^/]+/cgi-bin/getmsg/\\([^\?]+\\)\?[^\"]*\\)\""
513 (if (setq attachment
(match-string 1))
514 (let ((filename (match-string 2))
515 bufname
);; Attachment
516 (delete-region p
(match-end 0))
518 (set-buffer (generate-new-buffer " *webmail-att*"))
519 (nnweb-insert attachment
)
520 (push (current-buffer) webmail-buffer-list
)
521 (setq bufname
(buffer-name)))
523 (insert "<#part type="
525 (string-match "\\.[^\\.]+$" filename
)
526 (mailcap-extension-to-mime
527 (match-string 0 filename
)))
528 "application/octet-stream"))
529 (insert " buffer=\"" bufname
"\"")
530 (insert " filename=\"" filename
"\"")
531 (insert " disposition=\"inline\"")
532 (insert "><#/part>\n")
534 (delete-region p
(match-end 0))
536 (if (not (search-forward "</tt>" nil t
))
537 (webmail-error "article@1.2")
538 (delete-region (match-beginning 0) (match-end 0)))
540 (while (and (> count
0)
541 (re-search-forward "</div>\\|\\(<div>\\)" nil t
))
543 (setq count
(1+ count
))
544 (if (= (setq count
(1- count
)) 0)
545 (delete-region (match-beginning 0)
547 (narrow-to-region p
(point))
548 (goto-char (point-min))
550 ((looking-at "<pre>")
551 (goto-char (match-end 0))
552 (if (looking-at "$") (forward-char))
553 (delete-region (point-min) (point))
554 (nnweb-remove-markup)
555 (let ((w3-html-entities (cons '(nbsp .
32) w3-html-entities
)))
556 (nnweb-decode-entities))
560 (insert "<#part type=\"text/html\" disposition=inline>")
561 (goto-char (point-max))
562 (insert "<#/part>")))
563 (goto-char (point-max))
566 (delete-region p
(point-max))
567 (goto-char (point-min))
568 ;; Some blank line to seperate mails.
569 (insert "\n\nFrom nobody " (current-time-string) "\n")
570 (insert "X-Gnus-Webmail: " (symbol-value 'user
)
571 "@" (symbol-name webmail-type
) "\n")
573 (insert (format "X-Message-ID: <%s@hotmail.com>\n" id
)))
574 (unless (looking-at "$")
575 (if (search-forward "\n\n" nil t
)
577 (webmail-error "article@2")))
578 (narrow-to-region (point) (point-max))
580 (insert "MIME-Version: 1.0\n"
583 (delete-region (point-min) (point-max)))))
584 (goto-char (point-min))
586 (let (case-fold-search)
587 (while (re-search-forward "^From " nil t
)
590 (mm-append-to-file (point-min) (point-max) file
)))
594 (defun webmail-yahoo-open ()
595 (goto-char (point-min))
596 (if (re-search-forward "action=\"\\([^\"]+\\)\"" nil t
)
597 (setq webmail-aux
(match-string 1))
598 (webmail-error "open@1")))
600 (defun webmail-yahoo-login ()
601 (goto-char (point-min))
602 (if (re-search-forward "http://[^/]+[0-9]\\.mail\\.yahoo\\.com/" nil t
)
603 (setq webmail-aux
(match-string 0))
604 (webmail-error "login@1"))
605 (if (re-search-forward "YY=[0-9]+" nil t
)
606 (setq webmail-aux
(concat webmail-aux
"ym/ShowFolder?"
608 (webmail-error "login@2")))
610 (defun webmail-yahoo-list ()
611 (let (url (newp t
) (tofetch 0))
612 (goto-char (point-min))
613 (when (re-search-forward
614 "showing [0-9]+-\\([0-9]+\\) of \\([0-9]+\\)" nil t
)
615 ;;(setq listed (match-string 1))
616 (message "Found %s mail(s)" (match-string 2)))
617 (if (string-match "http://[^/]+" webmail-aux
)
618 (setq webmail-aux
(match-string 0 webmail-aux
))
619 (webmail-error "list@1"))
620 (goto-char (point-min))
621 (while (re-search-forward
622 "bgcolor=\"#eeeeee\"\\|href=\"\\(/ym/ShowLetter\\?MsgId=\\([^&]+\\)&[^\"]*\\)\""
624 (if (setq url
(match-string 1))
626 (when (or newp
(not webmail-newmail-only
))
627 (push (cons (match-string 2) (concat webmail-aux url
"&toc=1"))
629 (setq tofetch
(1+ tofetch
)))
632 (setq webmail-articles
(nreverse webmail-articles
))
633 (message "Fetching %d mail(s)" tofetch
)))
635 (defun webmail-yahoo-article (file id
)
638 (goto-char (point-min))
639 (if (not (search-forward "value=\"Done\"" nil t
))
640 (webmail-error "article@1"))
641 (if (not (search-forward "<table" nil t
))
642 (webmail-error "article@2"))
643 (delete-region (point-min) (match-beginning 0))
644 (if (not (search-forward "</table>" nil t
))
645 (webmail-error "article@3"))
646 (narrow-to-region (point-min) (match-end 0))
647 (while (search-forward "<a href=" nil t
)
648 (setq p
(match-beginning 0))
649 (search-forward "</a>" nil t
)
650 (delete-region p
(match-end 0)))
651 (nnweb-remove-markup)
652 (let ((w3-html-entities (cons '(nbsp .
32) w3-html-entities
)))
653 (nnweb-decode-entities))
654 (goto-char (point-min))
656 (goto-char (point-max))
660 (while (re-search-forward "[^\"]*/ShowLetter/[^\?]+\?[^\"]*" nil t
)
661 (setq attachment
(match-string 0))
662 (let (bufname ct ctl cd description
)
663 (if (not (search-forward "<table" nil t
))
664 (webmail-error "article@4"))
665 (delete-region p
(match-beginning 0))
666 (if (not (search-forward "</table>" nil t
))
667 (webmail-error "article@5"))
668 (narrow-to-region p
(match-end 0))
669 (nnweb-remove-markup)
670 (let ((w3-html-entities (cons '(nbsp .
32) w3-html-entities
)))
671 (nnweb-decode-entities))
672 (goto-char (point-min))
674 (setq ct
(mail-fetch-field "content-type")
675 ctl
(ignore-errors (mail-header-parse-content-type ct
))
676 ;;cte (mail-fetch-field "content-transfer-encoding")
677 cd
(mail-fetch-field "content-disposition")
678 description
(mail-fetch-field "content-description")
679 id
(mail-fetch-field "content-id"))
680 (delete-region (point-min) (point-max))
683 (set-buffer (generate-new-buffer " *webmail-att*"))
684 (nnweb-insert (concat webmail-aux attachment
))
685 (push (current-buffer) webmail-buffer-list
)
686 (setq bufname
(buffer-name)))
688 (if (and ctl
(not (equal (car ctl
) "text/")))
689 (insert " type=\"" (car ctl
) "\""))
690 (insert " buffer=\"" bufname
"\"")
692 (insert " disposition=\"" cd
"\""))
694 (insert " description=\"" description
"\""))
695 (insert "><#/part>\n")
697 (delete-region p
(point-max))
698 (goto-char (point-min))
699 ;; Some blank line to seperate mails.
700 (insert "\n\nFrom nobody " (current-time-string) "\n")
701 (insert "X-Gnus-Webmail: " (symbol-value 'user
)
702 "@" (symbol-name webmail-type
) "\n")
704 (insert (format "X-Message-ID: <%s@yahoo.com>\n" id
)))
705 (unless (looking-at "$")
706 (if (search-forward "\n\n" nil t
)
708 (webmail-error "article@2")))
709 (narrow-to-region (point) (point-max))
710 (insert "MIME-Version: 1.0\n"
713 (delete-region (point-min) (point-max))))
714 (goto-char (point-min))
716 (let (case-fold-search)
717 (while (re-search-forward "^From " nil t
)
720 (mm-append-to-file (point-min) (point-max) file
)))
724 (defun webmail-netscape-open ()
725 (goto-char (point-min))
726 (setq webmail-aux
"")
727 (while (re-search-forward
728 "TYPE=hidden *NAME=\\([^ ]+\\) *VALUE=\"\\([^\"]+\\)"
730 (setq webmail-aux
(concat webmail-aux
"&" (match-string 1) "="
733 (defun webmail-netaddress-open ()
734 (goto-char (point-min))
735 (if (re-search-forward "action=\"\\([^\"]+\\)\"" nil t
)
736 (setq webmail-aux
(concat (car webmail-open-url
) (match-string 1)))
737 (webmail-error "open@1")))
739 (defun webmail-netaddress-login ()
740 (webmail-refresh-redirect)
741 (goto-char (point-min))
742 (if (re-search-forward "tpl/[^/]+/\\([^/]+\\)" nil t
)
743 (setq webmail-session
(match-string 1))
744 (webmail-error "login@1")))
746 (defun webmail-netaddress-list ()
747 (webmail-refresh-redirect)
749 (goto-char (point-min))
750 (when (re-search-forward
751 "(\\([0-9]+\\) unread, \\([0-9]+\\) total)" nil t
)
752 (message "Found %s mail(s), %s unread"
753 (match-string 2) (match-string 1)))
754 (goto-char (point-min))
755 (while (re-search-forward
756 "MR\\[i\\]\\.R='\\([^']*\\)'\\|MR\\[i\\]\\.Q='\\([^']+\\)'" nil t
)
757 (if (setq id
(match-string 2))
760 (format "%s/tpl/Message/%s/Read?Q=%s&FolderID=-4&SortUseCase=True&Sort=Date&Headers=True"
761 (car webmail-article-url
)
762 webmail-session id
)))
763 (if (or (not webmail-newmail-only
)
764 (equal (match-string 1) "True"))
765 (push item webmail-articles
))))
766 (setq webmail-articles
(nreverse webmail-articles
))))
768 (defun webmail-netaddress-single-part ()
769 (goto-char (point-min))
771 ((looking-at "[\t\040\r\n]*<font face=[^>]+>[\t\040\r\n]*")
774 (while (re-search-forward "[\t\040\r\n]+" nil t
)
776 (goto-char (point-min))
777 (while (re-search-forward "<br>" nil t
)
778 (replace-match "\n"))
779 (nnweb-remove-markup)
780 (let ((w3-html-entities (cons '(nbsp .
32) w3-html-entities
)))
781 (nnweb-decode-entities))
784 (insert "<#part type=\"text/html\" disposition=inline>")
785 (goto-char (point-max))
789 (defun webmail-netaddress-article (file id
)
790 (webmail-refresh-redirect)
791 (let (p p1 attachment count mime type
)
793 (webmail-encode-8bit)
794 (goto-char (point-min))
795 (if (not (search-forward "Trash" nil t
))
796 (webmail-error "article@1"))
797 (if (not (search-forward "<form>" nil t
))
798 (webmail-error "article@2"))
799 (delete-region (point-min) (match-beginning 0))
800 (if (not (search-forward "</form>" nil t
))
801 (webmail-error "article@3"))
802 (narrow-to-region (point-min) (match-end 0))
803 (goto-char (point-min))
804 (while (re-search-forward "[\040\t\r\n]+" nil t
)
806 (goto-char (point-min))
807 (while (search-forward "<b>" nil t
)
808 (replace-match "\n"))
809 (nnweb-remove-markup)
810 (let ((w3-html-entities (cons '(nbsp .
32) w3-html-entities
)))
811 (nnweb-decode-entities))
812 (goto-char (point-min))
814 (goto-char (point-min))
815 (while (re-search-forward "^\040+\\|\040+$" nil t
)
817 (goto-char (point-min))
818 (while (re-search-forward "\040+" nil t
)
820 (goto-char (point-max))
824 (unless (search-forward "<!-- Data -->" nil t
)
825 (webmail-error "article@4"))
827 (delete-region p
(point))
828 (goto-char (point-max))
829 (unless (re-search-backward
830 "[\040\t]*<br>[\040\t\r\n]*<br>[\040\t\r\n]*<form" p t
)
831 (webmail-error "article@5"))
832 (delete-region (point) (point-max))
834 (while (search-forward
835 "<TABLE border=\"0\" WIDTH=\"98%\" cellpadding=0 cellspacing=0>"
838 (unless (search-forward "</TABLE>" nil t
)
839 (webmail-error "article@6"))
841 (if (search-backward "<IMG " p t
)
843 (unless (re-search-forward "HREF=\"\\(/tpl/Attachment/[^/]+/\\([^/]+/[^\?]+\\)[^\"]+\\)\"" p1 t
)
844 (webmail-error "article@7"))
845 (setq attachment
(match-string 1))
846 (setq type
(match-string 2))
847 (unless (search-forward "</TABLE>" nil t
)
848 (webmail-error "article@8"))
849 (delete-region p
(point))
850 (let (bufname);; Attachment
852 (set-buffer (generate-new-buffer " *webmail-att*"))
853 (nnweb-insert (concat (car webmail-open-url
) attachment
))
854 (push (current-buffer) webmail-buffer-list
)
855 (setq bufname
(buffer-name)))
856 (insert "<#part type=" type
)
857 (insert " buffer=\"" bufname
"\"")
858 (insert " disposition=\"inline\"")
859 (insert "><#/part>\n")
865 "<TABLE border=\"0\" WIDTH=\"98%\" cellpadding=0 cellspacing=0>"
869 (webmail-netaddress-single-part)
870 (goto-char (point-max))
874 (narrow-to-region p
(point-max))
875 (setq mime
(webmail-netaddress-single-part))
877 (goto-char (point-min))
878 ;; Some blank line to seperate mails.
879 (insert "\n\nFrom nobody " (current-time-string) "\n")
880 (insert "X-Gnus-Webmail: " (symbol-value 'user
)
881 "@" (symbol-name webmail-type
) "\n")
883 (insert (format "X-Message-ID: <%s@%s>\n" id webmail-address
)))
884 (unless (looking-at "$")
885 (if (search-forward "\n\n" nil t
)
887 (webmail-error "article@2")))
889 (narrow-to-region (point-min) (point))
890 (goto-char (point-min))
892 (if (looking-at "MIME-Version\\|Content-Type")
893 (delete-region (point)
896 (if (re-search-forward "^[^ \t]" nil t
)
897 (goto-char (match-beginning 0))
900 (goto-char (point-max))
902 (narrow-to-region (point) (point-max))
903 (insert "MIME-Version: 1.0\n"
906 (delete-region (point-min) (point-max))))
907 (goto-char (point-min))
909 (let (case-fold-search)
910 (while (re-search-forward "^From " nil t
)
913 (mm-append-to-file (point-min) (point-max) file
)))
915 (defun webmail-netscape-article (file id
)
916 (let (p p1 attachment count mime type
)
918 (webmail-encode-8bit)
919 (goto-char (point-min))
920 (if (not (search-forward "Trash" nil t
))
921 (webmail-error "article@1"))
922 (if (not (search-forward "<form>" nil t
))
923 (webmail-error "article@2"))
924 (delete-region (point-min) (match-beginning 0))
925 (if (not (search-forward "</form>" nil t
))
926 (webmail-error "article@3"))
927 (narrow-to-region (point-min) (match-end 0))
928 (goto-char (point-min))
929 (while (re-search-forward "[\040\t\r\n]+" nil t
)
931 (goto-char (point-min))
932 (while (re-search-forward "<a href=[^>]*>[^<]*</a>" nil t
)
934 (goto-char (point-min))
935 (while (search-forward "<b>" nil t
)
936 (replace-match "\n"))
937 (nnweb-remove-markup)
938 (let ((w3-html-entities (cons '(nbsp .
32) w3-html-entities
)))
939 (nnweb-decode-entities))
940 (goto-char (point-min))
942 (goto-char (point-min))
943 (while (re-search-forward "^\040+\\|\040+$" nil t
)
945 (goto-char (point-min))
946 (while (re-search-forward "\040+" nil t
)
948 (goto-char (point-max))
952 (unless (search-forward "<!-- Data -->" nil t
)
953 (webmail-error "article@4"))
955 (delete-region p
(point))
956 (goto-char (point-max))
957 (unless (re-search-backward
958 "<form name=\"Transfer2\"" p t
)
959 (webmail-error "article@5"))
960 (delete-region (point) (point-max))
962 (while (search-forward
963 "<TABLE border=\"0\" WIDTH=\"98%\" cellpadding=0 cellspacing=0>"
966 (unless (search-forward "</TABLE>" nil t
)
967 (webmail-error "article@6"))
969 (if (search-backward "<IMG " p t
)
971 (unless (re-search-forward "HREF=\"\\(/tpl/Attachment/[^/]+/\\([^/]+/[^\?]+\\)[^\"]+\\)\"" p1 t
)
972 (webmail-error "article@7"))
973 (setq attachment
(match-string 1))
974 (setq type
(match-string 2))
975 (unless (search-forward "</TABLE>" nil t
)
976 (webmail-error "article@8"))
977 (delete-region p
(point))
978 (let (bufname);; Attachment
980 (set-buffer (generate-new-buffer " *webmail-att*"))
981 (nnweb-insert (concat (car webmail-open-url
) attachment
))
982 (push (current-buffer) webmail-buffer-list
)
983 (setq bufname
(buffer-name)))
984 (insert "<#part type=" type
)
985 (insert " buffer=\"" bufname
"\"")
986 (insert " disposition=\"inline\"")
987 (insert "><#/part>\n")
993 "<TABLE border=\"0\" WIDTH=\"98%\" cellpadding=0 cellspacing=0>"
997 (webmail-netaddress-single-part)
998 (goto-char (point-max))
1002 (narrow-to-region p
(point-max))
1003 (setq mime
(webmail-netaddress-single-part))
1005 (goto-char (point-min))
1006 ;; Some blank line to seperate mails.
1007 (insert "\n\nFrom nobody " (current-time-string) "\n")
1008 (insert "X-Gnus-Webmail: " (symbol-value 'user
)
1009 "@" (symbol-name webmail-type
) "\n")
1011 (insert (format "X-Message-ID: <%s@%s>\n" id webmail-address
)))
1012 (unless (looking-at "$")
1013 (if (search-forward "\n\n" nil t
)
1015 (webmail-error "article@2")))
1017 (narrow-to-region (point-min) (point))
1018 (goto-char (point-min))
1020 (if (looking-at "MIME-Version\\|Content-Type")
1021 (delete-region (point)
1024 (if (re-search-forward "^[^ \t]" nil t
)
1025 (goto-char (match-beginning 0))
1028 (goto-char (point-max))
1030 (narrow-to-region (point) (point-max))
1031 (insert "MIME-Version: 1.0\n"
1034 (delete-region (point-min) (point-max))))
1035 (goto-char (point-min))
1037 (let (case-fold-search)
1038 (while (re-search-forward "^From " nil t
)
1041 (mm-append-to-file (point-min) (point-max) file
)))
1045 (defun webmail-my-deja-open ()
1046 (webmail-refresh-redirect)
1047 (goto-char (point-min))
1048 (if (re-search-forward "action=\"\\([^\"]+login_confirm\\.xp[^\"]*\\)\""
1050 (setq webmail-aux
(match-string 1))
1051 (webmail-error "open@1")))
1053 (defun webmail-my-deja-list ()
1054 (let (item id newp base
)
1055 (goto-char (point-min))
1056 (when (re-search-forward "href=\"\\(\\([^\"]*\\)/mailnf\\.[^\"]*\\)\""
1058 (let ((url (match-string 1)))
1059 (setq base
(match-string 2))
1061 (nnweb-insert url
)))
1062 (goto-char (point-min))
1063 (when (re-search-forward
1064 "(\\([0-9]+\\) Message.?-[^>]*\\([0-9]+\\) New"
1066 (message "Found %s mail(s), %s unread"
1067 (match-string 1) (match-string 2)))
1068 (goto-char (point-min))
1069 (while (re-search-forward
1070 "newmail\\.gif\\|href=\"[^\"]*\\(mailnf\\.[^\"]+act=view[^\"]+mid=\\([^\"&]+\\)[^\"]+\\)\""
1072 (if (setq id
(match-string 2))
1073 (when (and (or newp
(not webmail-newmail-only
))
1074 (not (assoc id webmail-articles
)))
1075 (push (cons id
(setq webmail-aux
1076 (concat base
"/" (match-string 1))))
1080 (setq webmail-articles
(nreverse webmail-articles
))))
1082 (defun webmail-my-deja-article-part (base)
1085 ((looking-at "[\t\040\r\n]*<!--[^>]*>")
1087 ((looking-at "[\t\040\r\n]*</PRE>")
1089 ((looking-at "[\t\040\r\n]*<PRE>")
1093 (narrow-to-region (point)
1094 (if (re-search-forward "</?PRE>" nil t
)
1097 (goto-char (point-min))
1098 (nnweb-remove-markup)
1099 (let ((w3-html-entities (cons '(nbsp .
32) w3-html-entities
)))
1100 (nnweb-decode-entities))
1101 (goto-char (point-max))))
1102 ((looking-at "[\t\040\r\n]*<TABLE")
1104 (narrow-to-region (point)
1105 (if (search-forward "</TABLE>" nil t
2)
1108 (goto-char (point-min))
1109 (let (name type url bufname
)
1110 (if (and (search-forward "File Name:" nil t
)
1111 (re-search-forward "<FONT[^>]+>\\([^<]+\\)" nil t
))
1112 (setq name
(match-string 1)))
1113 (if (and (search-forward "File Type:" nil t
)
1114 (re-search-forward "<FONT[^>]+>\\([^<]+\\)" nil t
))
1115 (setq type
(match-string 1)))
1116 (unless (re-search-forward "action=\"getattach\\.cgi/\\([^\"]+\\)"
1118 (webmail-error "article@5"))
1119 (setq url
(concat base
"/getattach.cgi/" (match-string 1)
1121 (while (re-search-forward
1122 "type=hidden name=\"\\([^\"]+\\)\" value=\"\\([^\"]+\\)"
1124 (setq url
(concat url
"&" (match-string 1) "="
1126 (delete-region (point-min) (point-max))
1128 (set-buffer (generate-new-buffer " *webmail-att*"))
1130 (push (current-buffer) webmail-buffer-list
)
1131 (setq bufname
(buffer-name)))
1132 (insert "<#part type=\"" type
"\"")
1133 (if name
(insert " filename=\"" name
"\""))
1134 (insert " buffer=\"" bufname
"\"")
1135 (insert " disposition=inline><#/part>"))))
1137 (insert "<#part type=\"text/html\" disposition=inline>")
1138 (goto-char (point-max))
1139 (insert "<#/part>")))))
1141 (defun webmail-my-deja-article (file id
)
1143 (goto-char (point-min))
1144 (unless (string-match "\\([^\"]+\\)/mail" webmail-aux
)
1145 (webmail-error "article@0"))
1146 (setq base
(match-string 1 webmail-aux
))
1147 (when (re-search-forward
1148 "href=\"[^\"]*\\(mailnf\\.[^\"]+act=move[^\"]+mid=\\([^\"&]+\\)[^\"]+\\)\""
1150 (setq webmail-aux
(concat base
"/" (match-string 1)))
1151 (string-match "mid=[^\"&]+" webmail-aux
)
1152 (setq webmail-aux
(replace-match "mid=%s" nil nil webmail-aux
)))
1153 (unless (search-forward "<HR noshade>" nil t
)
1154 (webmail-error "article@1"))
1155 (delete-region (point-min) (point))
1156 (unless (search-forward "<HR noshade>" nil t
)
1157 (webmail-error "article@2"))
1159 (narrow-to-region (point-min) (point))
1160 (while (search-forward "\r\n" nil t
)
1161 (replace-match "\n"))
1162 (nnweb-remove-markup)
1163 (let ((w3-html-entities (cons '(nbsp .
32) w3-html-entities
)))
1164 (nnweb-decode-entities))
1165 (goto-char (point-min))
1166 (while (re-search-forward "\n\n+" nil t
)
1167 (replace-match "\n"))
1168 (goto-char (point-max)))
1170 (narrow-to-region (point) (point-max))
1171 (goto-char (point-max))
1172 (unless (search-backward "<HR noshade>" nil t
)
1173 (webmail-error "article@3"))
1174 (unless (search-backward "</TT>" nil t
)
1175 (webmail-error "article@4"))
1176 (delete-region (point) (point-max))
1177 (goto-char (point-min))
1179 (webmail-my-deja-article-part base
))
1180 (insert "MIME-Version: 1.0\n"
1183 (delete-region (point-min) (point-max)))))
1184 (goto-char (point-min))
1185 (insert "\n\nFrom nobody " (current-time-string) "\n")
1186 (insert "X-Gnus-Webmail: " (symbol-value 'user
)
1187 "@" (symbol-name webmail-type
) "\n")
1188 (if (eq (char-after) ?
\n)
1190 (mm-append-to-file (point-min) (point-max) file
)))
1194 ;;; webmail.el ends here