1 ;;; webmail.el --- interface of web mail
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007 Free Software Foundation, Inc.
6 ;; Author: Shenghuo Zhu <zsh@cs.rochester.edu>
7 ;; Keywords: hotmail netaddress my-deja netscape
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published
13 ;; by the Free Software Foundation; either version 3, or (at your
14 ;; option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
28 ;; Note: Now mail.yahoo.com provides POP3 service, the webmail
29 ;; fetching is not going to be supported.
31 ;; Note: You need to have `url' and `w3' installed for this backend to
32 ;; work. `w3' must be 4.0pre46+one-line-cookie patch or standalone
35 ;; Todo: To support more web mail servers.
38 ;; 1. Net@ddress may corrupt `X-Face'.
41 ;; Webmail is an experimental function, which means NO WARRANTY.
45 (eval-when-compile (require 'cl
))
58 (require 'url-cookie
)))
59 ;; Report failure to find w3 at load time if appropriate.
62 (require 'url-cookie
)))
66 (defvar webmail-type-definition
68 ;; Hotmail hate other HTTP user agents and use one line cookie
69 (paranoid agent cookie post
)
70 (address .
"www.hotmail.com")
71 (open-url "http://www.hotmail.com/")
72 (open-snarf . webmail-hotmail-open
)
73 ;; W3 hate redirect POST
75 "http://%s/cgi-bin/dologin?login=%s&passwd=%s&enter=Sign+in&sec=no&curmbox=ACTIVE&_lang=&js=yes&id=2&tw=-10000&beta="
76 webmail-aux user password
)
77 ;;(login-snarf . webmail-hotmail-login)
78 ;;(list-url "%s" webmail-aux)
79 (list-snarf . webmail-hotmail-list
)
80 (article-snarf . webmail-hotmail-article
)
82 "%s&login=%s&f=33792&curmbox=ACTIVE&_lang=&foo=inbox&js=&page=&%s=on&_HMaction=MoveTo&tobox=trAsH&nullbox="
85 (paranoid agent cookie post
)
86 (address .
"mail.yahoo.com")
87 (open-url "http://mail.yahoo.com/")
88 (open-snarf . webmail-yahoo-open
)
89 (login-url;; yahoo will not accept GET
92 ".tries=&.src=ym&.last=&promo=&.intl=&.bypass=&.partner=&.chkP=Y&.done=&login=%s&passwd=%s"
94 (login-snarf . webmail-yahoo-login
)
95 (list-url "%s&rb=Inbox&YN=1" webmail-aux
)
96 (list-snarf . webmail-yahoo-list
)
97 (article-snarf . webmail-yahoo-article
)
99 "%s/ym/ShowFolder?YY=52107&inc=50&order=down&sort=date&pos=0&box=Inbox&DEL=Delete&destBox=&Mid=%s&destBox2="
102 (paranoid cookie post
)
103 (address .
"www.netaddress.com")
104 (open-url "http://www.netaddress.com/")
105 (open-snarf . webmail-netaddress-open
)
109 "LoginState=2&SuccessfulLogin=%%2Ftpl&NewServerName=www.netaddress.com&JavaScript=JavaScript1.2&DomainID=4&Domain=usa.net&NA31site=classic.netaddress.com&NA31port=80&UserID=%s&passwd=%s"
111 (login-snarf . webmail-netaddress-login
)
113 "http://www.netaddress.com/tpl/Mail/%s/List?FolderID=-4&SortUseCase=True"
115 (list-snarf . webmail-netaddress-list
)
116 (article-url "http://www.netaddress.com/")
117 (article-snarf . webmail-netaddress-article
)
119 "http://www.netaddress.com/tpl/Message/%s/Move?FolderID=-4&Q=%s&N=&Sort=Date&F=-1"
122 (paranoid cookie post agent
)
123 (address .
"webmail.netscape.com")
124 (open-url "http://ureg.netscape.com/iiop/UReg2/login/login?U2_LA=en&U2_BACK_FROM_CJ=true&U2_CS=iso-8859-1&U2_ENDURL=http://webmail.netscape.com/tpl/Subscribe/Step1&U2_NEW_ENDURL=http://webmail.netscape.com/tpl/Subscribe/Step1&U2_EXITURL=http://home.netscape.com/&U2_SOURCE=Webmail")
125 (open-snarf . webmail-netscape-open
)
128 ("http://ureg.netscape.com/iiop/UReg2/login/loginform")
129 "U2_USERNAME=%s&U2_PASSWORD=%s%s"
130 user password webmail-aux
)
131 (login-snarf . webmail-netaddress-login
)
133 "http://webmail.netscape.com/tpl/Mail/%s/List?FolderID=-4&SortUseCase=True"
135 (list-snarf . webmail-netaddress-list
)
136 (article-url "http://webmail.netscape.com/")
137 (article-snarf . webmail-netscape-article
)
139 "http://webmail.netscape.com/tpl/Message/%s/Move?FolderID=-4&Q=%s&N=&Sort=Date&F=-1"
142 (paranoid cookie post
)
143 (address .
"www.my-deja.com")
144 ;;(open-snarf . webmail-my-deja-open)
147 ("http://mydeja.google.com/cgi-bin/deja/maillogin.py")
148 "userid=%s&password=%s"
150 (list-snarf . webmail-my-deja-list
)
151 (article-snarf . webmail-my-deja-article
)
152 (trash-url webmail-aux id
))))
154 (defvar webmail-variables
155 '(address article-snarf article-url list-snarf list-url
156 login-url login-snarf open-url open-snarf site articles
157 post-process paranoid trash-url
))
159 (defconst webmail-version
"webmail 1.0")
161 (defvar webmail-newmail-only nil
162 "Only fetch new mails.")
164 (defvar webmail-move-to-trash-can t
165 "Move mail to trash can after fetch it.")
167 ;;; Internal variables
169 (defvar webmail-address nil
)
170 (defvar webmail-paranoid nil
)
171 (defvar webmail-aux nil
)
172 (defvar webmail-session nil
)
173 (defvar webmail-article-snarf nil
)
174 (defvar webmail-article-url nil
)
175 (defvar webmail-list-snarf nil
)
176 (defvar webmail-list-url nil
)
177 (defvar webmail-login-url nil
)
178 (defvar webmail-login-snarf nil
)
179 (defvar webmail-open-snarf nil
)
180 (defvar webmail-open-url nil
)
181 (defvar webmail-trash-url nil
)
182 (defvar webmail-articles nil
)
183 (defvar webmail-post-process nil
)
185 (defvar webmail-buffer nil
)
186 (defvar webmail-buffer-list nil
)
188 (defvar webmail-type nil
)
190 (defvar webmail-error-function nil
)
192 (defvar webmail-debug-file
"~/.emacs-webmail-debug")
194 ;;; Interface functions
196 (defun webmail-debug (str)
198 (insert "\n---------------- A bug at " str
" ------------------\n")
199 (dolist (sym '(webmail-type user
))
201 (gnus-pp `(setq ,sym
',(eval sym
)))))
202 (insert "---------------- webmail buffer ------------------\n\n")
203 (insert-buffer-substring webmail-buffer
)
204 (insert "\n---------------- end of buffer ------------------\n\n")
205 (append-to-file (point-min) (point-max) webmail-debug-file
)))
207 (defun webmail-error (str)
208 (if webmail-error-function
209 (funcall webmail-error-function str
))
210 (message "%s HTML has changed or your w3 package is too old.(%s)"
212 (error "%s HTML has changed or your w3 package is too old.(%s)"
215 (defun webmail-setdefault (type)
216 (let ((type-def (cdr (assq type webmail-type-definition
)))
217 (vars webmail-variables
)
219 (setq webmail-type type
)
221 (if (setq pair
(assq var type-def
))
222 (set (intern (concat "webmail-" (symbol-name var
))) (cdr pair
))
223 (set (intern (concat "webmail-" (symbol-name var
))) nil
)))))
225 (defun webmail-eval (expr)
228 (cons (webmail-eval (car expr
)) (webmail-eval (cdr expr
))))
234 (defun webmail-url (xurl)
235 (mm-with-unibyte-current-buffer
237 ((eq (car xurl
) 'content
)
239 (mm-url-fetch-simple (if (stringp (car xurl
))
241 (apply 'format
(webmail-eval (car xurl
))))
242 (apply 'format
(webmail-eval (cdr xurl
)))))
243 ((eq (car xurl
) 'post
)
245 (mm-url-fetch-form (car xurl
) (webmail-eval (cdr xurl
))))
247 (mm-url-insert (apply 'format
(webmail-eval xurl
)))))))
249 (defun webmail-init ()
250 "Initialize buffers and such."
251 (if (gnus-buffer-live-p webmail-buffer
)
252 (set-buffer webmail-buffer
)
254 (nnheader-set-temp-buffer " *webmail*"))
255 (mm-disable-multibyte)))
257 (defvar url-package-name
)
258 (defvar url-package-version
)
259 (defvar url-cookie-multiple-line
)
260 (defvar url-confirmation-func
)
262 ;; Hack W3 POST redirect. See `url-parse-mime-headers'.
264 ;; Netscape uses "GET" as redirect method when orignal method is POST
265 ;; and status is 302, .i.e no security risks by default without
268 ;; Some web servers (at least Apache used by yahoo) return status 302
269 ;; instead of 303, though they mean 303.
271 (defun webmail-url-confirmation-func (prompt)
273 ((equal prompt
(concat "Honor redirection with non-GET method "
274 "(possible security risks)? "))
276 ((equal prompt
"Continue (with method of GET)? ")
280 (defun webmail-refresh-redirect ()
281 "Redirect refresh url in META."
282 (goto-char (point-min))
283 (while (re-search-forward
284 "<meta[ \t\r\n]*http-equiv=\"Refresh\"[^>]*URL=\\([^\"]+\\)\""
286 (let ((url (match-string 1)))
288 (mm-with-unibyte-current-buffer
289 (mm-url-insert url
)))
290 (goto-char (point-min))))
292 (defun webmail-fetch (file subtype user password
)
294 (webmail-setdefault subtype
)
295 (let ((url-package-name (if (memq 'agent webmail-paranoid
)
298 (url-package-version (if (memq 'agent webmail-paranoid
)
300 url-package-version
))
301 (url-cookie-multiple-line (if (memq 'cookie webmail-paranoid
)
303 url-cookie-multiple-line
))
304 (url-confirmation-func (if (memq 'post webmail-paranoid
)
305 'webmail-url-confirmation-func
306 url-confirmation-func
))
307 (url-http-silence-on-insecure-redirection t
)
308 url-cookie-storage url-cookie-secure-storage
309 url-cookie-confirmation
312 (setq webmail-articles nil
)
313 (when webmail-open-url
315 (webmail-url webmail-open-url
))
316 (if webmail-open-snarf
(funcall webmail-open-snarf
))
317 (when webmail-login-url
319 (webmail-url webmail-login-url
))
320 (if webmail-login-snarf
321 (funcall webmail-login-snarf
))
322 (when webmail-list-url
324 (webmail-url webmail-list-url
))
325 (if webmail-list-snarf
326 (funcall webmail-list-snarf
))
327 (while (setq item
(pop webmail-articles
))
328 (message "Fetching mail #%d..." (setq n
(1+ n
)))
330 (mm-with-unibyte-current-buffer
331 (mm-url-insert (cdr item
)))
333 (if webmail-article-snarf
334 (funcall webmail-article-snarf file id
))
335 (when (and webmail-trash-url webmail-move-to-trash-can
)
336 (message "Move mail #%d to trash can..." n
)
339 (webmail-url webmail-trash-url
)
341 (while (setq buf
(pop webmail-buffer-list
))
345 (while (setq buf
(pop webmail-buffer-list
))
348 (if webmail-post-process
349 (funcall webmail-post-process
))))
351 (defun webmail-encode-8bit ()
352 (goto-char (point-min))
353 (skip-chars-forward "^\200-\377")
355 (insert (format "&%d;" (mm-char-int (char-after))))
357 (skip-chars-forward "^\200-\377")))
361 (defun webmail-hotmail-open ()
362 (goto-char (point-min))
363 (if (re-search-forward
364 "action=\"https?://\\([^/]+\\)/cgi-bin/dologin" nil t
)
365 (setq webmail-aux
(match-string 1))
366 (webmail-error "open@1")))
368 (defun webmail-hotmail-login ()
370 (goto-char (point-min))
371 (if (re-search-forward
372 "https?://\\([^/]+hotmail\\.msn\\.com\\)/cgi-bin/" nil t
)
373 (setq site
(match-string 1))
374 (webmail-error "login@1"))
375 (goto-char (point-min))
376 (if (re-search-forward
377 "\\(/cgi-bin/HoTMaiL\\?[^\"]*a=b[^\"]*\\)" nil t
)
378 (setq webmail-aux
(concat "http://" site
(match-string 1)))
379 (webmail-error "login@2"))))
381 (defun webmail-hotmail-list ()
382 (goto-char (point-min))
383 (skip-chars-forward " \t\n\r")
384 (let (site url newp
(total "0"))
387 (if (re-search-forward "\\([0-9]+\\) *<b>(\\([0-9]+\\) new)" nil t
)
388 (message "Found %s (%s new)" (setq total
(match-string 1))
390 (if (re-search-forward "\\([0-9]+\\) new" nil t
)
391 (message "Found %s new" (setq total
(match-string 1)))
392 (webmail-error "list@0"))))
393 (unless (equal total
"0")
394 (goto-char (point-min))
395 (if (re-search-forward
396 "https?://\\([^/]+hotmail\\.msn\\.com\\)/cgi-bin/" nil t
)
397 (setq site
(match-string 1))
398 (webmail-error "list@1"))
399 (goto-char (point-min))
400 (if (re-search-forward "disk=\\([^&]*\\)&" nil t
)
402 (concat "http://" site
"/cgi-bin/HoTMaiL?disk="
404 (webmail-error "list@2"))
405 (goto-char (point-max))
406 (while (re-search-backward
407 "newmail\\.gif\\|href=\"\\(/cgi-bin/getmsg\\?[^\"]+\\)\""
409 (if (setq url
(match-string 1))
411 (if (or newp
(not webmail-newmail-only
))
413 (if (string-match "msg=\\([^&]+\\)" url
)
414 (setq id
(match-string 1 url
)))
415 (push (cons id
(concat "http://" site url
"&raw=0"))
420 ;; Thank victor@idaccr.org (Victor S. Miller) for raw=0
422 (defun webmail-hotmail-article (file id
)
423 (goto-char (point-min))
424 (skip-chars-forward " \t\n\r")
426 (if (not (search-forward "<pre>" nil t
))
427 (webmail-error "article@3"))
428 (skip-chars-forward "\n\r\t ")
429 (delete-region (point-min) (point))
430 (if (not (search-forward "</pre>" nil t
))
431 (webmail-error "article@3.1"))
432 (delete-region (match-beginning 0) (point-max))
433 (mm-url-remove-markup)
434 (mm-url-decode-entities-nbsp)
435 (goto-char (point-min))
436 (while (re-search-forward "\r\n?" nil t
)
437 (replace-match "\n"))
438 (goto-char (point-min))
440 (if (not (looking-at "\n*From "))
441 (insert "From nobody " (current-time-string) "\n")
443 (insert "X-Gnus-Webmail: " (symbol-value 'user
)
444 "@" (symbol-name webmail-type
) "\n")
445 (mm-append-to-file (point-min) (point-max) file
)))
447 (defun webmail-hotmail-article-old (file id
)
448 (let (p attachment count mime hotmail-direct
)
450 (webmail-encode-8bit)
451 (goto-char (point-min))
452 (if (not (search-forward "<DIV>" nil t
))
453 (if (not (search-forward "Reply All" nil t
))
454 (webmail-error "article@1")
455 (setq hotmail-direct t
))
456 (goto-char (match-beginning 0)))
457 (narrow-to-region (point-min) (point))
458 (if (not (search-backward "<table" nil t
2))
459 (webmail-error "article@1.1"))
460 (delete-region (point-min) (match-beginning 0))
461 (while (search-forward "<a href=" nil t
)
462 (setq p
(match-beginning 0))
463 (search-forward "</a>" nil t
)
464 (delete-region p
(match-end 0)))
465 (mm-url-remove-markup)
466 (mm-url-decode-entities-nbsp)
467 (goto-char (point-min))
469 (goto-char (point-min))
470 (when (search-forward "\n\n" nil t
)
472 (delete-region (point) (point-max)))
473 (goto-char (point-max))
477 (while (re-search-forward
478 "<tt>\\|<div>\\|\\(http://[^/]+/cgi-bin/getmsg/\\([^\?]+\\)\?[^\"]*\\)\""
480 (if (setq attachment
(match-string 1))
481 (let ((filename (match-string 2))
482 bufname
);; Attachment
483 (delete-region p
(match-end 0))
485 (set-buffer (generate-new-buffer " *webmail-att*"))
486 (mm-url-insert attachment
)
487 (push (current-buffer) webmail-buffer-list
)
488 (setq bufname
(buffer-name)))
490 (insert "<#part type="
492 (string-match "\\.[^\\.]+$" filename
)
493 (mailcap-extension-to-mime
494 (match-string 0 filename
)))
495 "application/octet-stream"))
496 (insert " buffer=\"" bufname
"\"")
497 (insert " filename=\"" filename
"\"")
498 (insert " disposition=\"inline\"")
499 (insert "><#/part>\n")
501 (delete-region p
(match-end 0))
503 (if (not (search-forward "</tt>" nil t
))
504 (webmail-error "article@1.2")
505 (delete-region (match-beginning 0) (match-end 0)))
507 (while (and (> count
0)
508 (re-search-forward "</div>\\|\\(<div>\\)" nil t
))
510 (setq count
(1+ count
))
511 (if (= (setq count
(1- count
)) 0)
512 (delete-region (match-beginning 0)
514 (narrow-to-region p
(point))
515 (goto-char (point-min))
517 ((looking-at "<pre>")
518 (goto-char (match-end 0))
519 (if (looking-at "$") (forward-char))
520 (delete-region (point-min) (point))
521 (mm-url-remove-markup)
522 (mm-url-decode-entities-nbsp)
526 (insert "<#part type=\"text/html\" disposition=inline>")
527 (goto-char (point-max))
528 (insert "<#/part>")))
529 (goto-char (point-max))
532 (delete-region p
(point-max))
533 (goto-char (point-min))
534 ;; Some blank line to seperate mails.
535 (insert "\n\nFrom nobody " (current-time-string) "\n")
536 (insert "X-Gnus-Webmail: " (symbol-value 'user
)
537 "@" (symbol-name webmail-type
) "\n")
539 (insert (format "X-Message-ID: <%s@hotmail.com>\n" id
)))
540 (unless (looking-at "$")
541 (if (search-forward "\n\n" nil t
)
543 (webmail-error "article@2")))
544 (narrow-to-region (point) (point-max))
546 (insert "MIME-Version: 1.0\n"
549 (delete-region (point-min) (point-max)))))
550 (goto-char (point-min))
552 (let (case-fold-search)
553 (while (re-search-forward "^From " nil t
)
556 (mm-append-to-file (point-min) (point-max) file
)))
560 (defun webmail-yahoo-open ()
561 (goto-char (point-min))
562 (if (re-search-forward "action=\"\\([^\"]+\\)\"" nil t
)
563 (setq webmail-aux
(match-string 1))
564 (webmail-error "open@1")))
566 (defun webmail-yahoo-login ()
567 (goto-char (point-min))
568 (if (re-search-forward "http://[^/]+[0-9]\\.mail\\.yahoo\\.com/" nil t
)
569 (setq webmail-aux
(match-string 0))
570 (webmail-error "login@1"))
571 (if (re-search-forward "YY=[0-9]+" nil t
)
572 (setq webmail-aux
(concat webmail-aux
"ym/ShowFolder?"
574 (webmail-error "login@2")))
576 (defun webmail-yahoo-list ()
577 (let (url (newp t
) (tofetch 0))
578 (goto-char (point-min))
579 (when (re-search-forward
580 "showing [0-9]+-\\([0-9]+\\) of \\([0-9]+\\)" nil t
)
581 ;;(setq listed (match-string 1))
582 (message "Found %s mail(s)" (match-string 2)))
583 (if (string-match "http://[^/]+" webmail-aux
)
584 (setq webmail-aux
(match-string 0 webmail-aux
))
585 (webmail-error "list@1"))
586 (goto-char (point-min))
587 (while (re-search-forward
588 "bgcolor=\"#eeeeee\"\\|href=\"\\(/ym/ShowLetter\\?MsgId=\\([^&]+\\)&[^\"]*\\)\""
590 (if (setq url
(match-string 1))
592 (when (or newp
(not webmail-newmail-only
))
593 (push (cons (match-string 2) (concat webmail-aux url
"&toc=1"))
595 (setq tofetch
(1+ tofetch
)))
598 (setq webmail-articles
(nreverse webmail-articles
))
599 (message "Fetching %d mail(s)" tofetch
)))
601 (defun webmail-yahoo-article (file id
)
604 (goto-char (point-min))
605 (if (not (search-forward "value=\"Done\"" nil t
))
606 (webmail-error "article@1"))
607 (if (not (search-forward "<table" nil t
))
608 (webmail-error "article@2"))
609 (delete-region (point-min) (match-beginning 0))
610 (if (not (search-forward "</table>" nil t
))
611 (webmail-error "article@3"))
612 (narrow-to-region (point-min) (match-end 0))
613 (while (search-forward "<a href=" nil t
)
614 (setq p
(match-beginning 0))
615 (search-forward "</a>" nil t
)
616 (delete-region p
(match-end 0)))
617 (mm-url-remove-markup)
618 (mm-url-decode-entities-nbsp)
619 (goto-char (point-min))
621 (goto-char (point-max))
625 (while (re-search-forward "[^\"]*/ShowLetter/[^\?]+\?[^\"]*" nil t
)
626 (setq attachment
(match-string 0))
627 (let (bufname ct ctl cd description
)
628 (if (not (search-forward "<table" nil t
))
629 (webmail-error "article@4"))
630 (delete-region p
(match-beginning 0))
631 (if (not (search-forward "</table>" nil t
))
632 (webmail-error "article@5"))
633 (narrow-to-region p
(match-end 0))
634 (mm-url-remove-markup)
635 (mm-url-decode-entities-nbsp)
636 (goto-char (point-min))
638 (setq ct
(mail-fetch-field "content-type")
639 ctl
(and ct
(mail-header-parse-content-type ct
))
640 ;;cte (mail-fetch-field "content-transfer-encoding")
641 cd
(mail-fetch-field "content-disposition")
642 description
(mail-fetch-field "content-description")
643 id
(mail-fetch-field "content-id"))
644 (delete-region (point-min) (point-max))
647 (set-buffer (generate-new-buffer " *webmail-att*"))
648 (mm-url-insert (concat webmail-aux attachment
))
649 (push (current-buffer) webmail-buffer-list
)
650 (setq bufname
(buffer-name)))
652 (if (and ctl
(not (equal (car ctl
) "text/")))
653 (insert " type=\"" (car ctl
) "\""))
654 (insert " buffer=\"" bufname
"\"")
656 (insert " disposition=\"" cd
"\""))
658 (insert " description=\"" description
"\""))
659 (insert "><#/part>\n")
661 (delete-region p
(point-max))
662 (goto-char (point-min))
663 ;; Some blank line to seperate mails.
664 (insert "\n\nFrom nobody " (current-time-string) "\n")
665 (insert "X-Gnus-Webmail: " (symbol-value 'user
)
666 "@" (symbol-name webmail-type
) "\n")
668 (insert (format "X-Message-ID: <%s@yahoo.com>\n" id
)))
669 (unless (looking-at "$")
670 (if (search-forward "\n\n" nil t
)
672 (webmail-error "article@2")))
673 (narrow-to-region (point) (point-max))
674 (insert "MIME-Version: 1.0\n"
677 (delete-region (point-min) (point-max))))
678 (goto-char (point-min))
680 (let (case-fold-search)
681 (while (re-search-forward "^From " nil t
)
684 (mm-append-to-file (point-min) (point-max) file
)))
688 (defun webmail-netscape-open ()
689 (goto-char (point-min))
690 (setq webmail-aux
"")
691 (while (re-search-forward
692 "TYPE=hidden *NAME=\\([^ ]+\\) *VALUE=\"\\([^\"]+\\)"
694 (setq webmail-aux
(concat webmail-aux
"&" (match-string 1) "="
697 (defun webmail-netaddress-open ()
698 (goto-char (point-min))
699 (if (re-search-forward "action=\"\\([^\"]+\\)\"" nil t
)
700 (setq webmail-aux
(concat (car webmail-open-url
) (match-string 1)))
701 (webmail-error "open@1")))
703 (defun webmail-netaddress-login ()
704 (webmail-refresh-redirect)
705 (goto-char (point-min))
706 (if (re-search-forward "tpl/[^/]+/\\([^/]+\\)" nil t
)
707 (setq webmail-session
(match-string 1))
708 (webmail-error "login@1")))
710 (defun webmail-netaddress-list ()
711 (webmail-refresh-redirect)
713 (goto-char (point-min))
714 (when (re-search-forward
715 "(\\([0-9]+\\) unread, \\([0-9]+\\) total)" nil t
)
716 (message "Found %s mail(s), %s unread"
717 (match-string 2) (match-string 1)))
718 (goto-char (point-min))
719 (while (re-search-forward
720 "MR\\[i\\]\\.R='\\([^']*\\)'\\|MR\\[i\\]\\.Q='\\([^']+\\)'" nil t
)
721 (if (setq id
(match-string 2))
724 (format "%s/tpl/Message/%s/Read?Q=%s&FolderID=-4&SortUseCase=True&Sort=Date&Headers=True"
725 (car webmail-article-url
)
726 webmail-session id
)))
727 (if (or (not webmail-newmail-only
)
728 (equal (match-string 1) "True"))
729 (push item webmail-articles
))))
730 (setq webmail-articles
(nreverse webmail-articles
))))
732 (defun webmail-netaddress-single-part ()
733 (goto-char (point-min))
735 ((looking-at "[\t\040\r\n]*<font face=[^>]+>[\t\040\r\n]*")
738 (while (re-search-forward "[\t\040\r\n]+" nil t
)
740 (goto-char (point-min))
741 (while (re-search-forward "<br>" nil t
)
742 (replace-match "\n"))
743 (mm-url-remove-markup)
744 (mm-url-decode-entities-nbsp)
747 (insert "<#part type=\"text/html\" disposition=inline>")
748 (goto-char (point-max))
752 (defun webmail-netaddress-article (file id
)
753 (webmail-refresh-redirect)
754 (let (p p1 attachment count mime type
)
756 (webmail-encode-8bit)
757 (goto-char (point-min))
758 (if (not (search-forward "Trash" nil t
))
759 (webmail-error "article@1"))
760 (if (not (search-forward "<form>" nil t
))
761 (webmail-error "article@2"))
762 (delete-region (point-min) (match-beginning 0))
763 (if (not (search-forward "</form>" nil t
))
764 (webmail-error "article@3"))
765 (narrow-to-region (point-min) (match-end 0))
766 (goto-char (point-min))
767 (while (re-search-forward "[\040\t\r\n]+" nil t
)
769 (goto-char (point-min))
770 (while (search-forward "<b>" nil t
)
771 (replace-match "\n"))
772 (mm-url-remove-markup)
773 (mm-url-decode-entities-nbsp)
774 (goto-char (point-min))
776 (goto-char (point-min))
777 (while (re-search-forward "^\040+\\|\040+$" nil t
)
779 (goto-char (point-min))
780 (while (re-search-forward "\040+" nil t
)
782 (goto-char (point-max))
786 (unless (search-forward "<!-- Data -->" nil t
)
787 (webmail-error "article@4"))
789 (delete-region p
(point))
790 (goto-char (point-max))
791 (unless (re-search-backward
792 "[\040\t]*<br>[\040\t\r\n]*<br>[\040\t\r\n]*<form" p t
)
793 (webmail-error "article@5"))
794 (delete-region (point) (point-max))
796 (while (search-forward
797 "<TABLE border=\"0\" WIDTH=\"98%\" cellpadding=0 cellspacing=0>"
800 (unless (search-forward "</TABLE>" nil t
)
801 (webmail-error "article@6"))
803 (if (search-backward "<IMG " p t
)
805 (unless (re-search-forward "HREF=\"\\(/tpl/Attachment/[^/]+/\\([^/]+/[^\?]+\\)[^\"]+\\)\"" p1 t
)
806 (webmail-error "article@7"))
807 (setq attachment
(match-string 1))
808 (setq type
(match-string 2))
809 (unless (search-forward "</TABLE>" nil t
)
810 (webmail-error "article@8"))
811 (delete-region p
(point))
812 (let (bufname);; Attachment
814 (set-buffer (generate-new-buffer " *webmail-att*"))
815 (mm-url-insert (concat (car webmail-open-url
) attachment
))
816 (push (current-buffer) webmail-buffer-list
)
817 (setq bufname
(buffer-name)))
818 (insert "<#part type=" type
)
819 (insert " buffer=\"" bufname
"\"")
820 (insert " disposition=\"inline\"")
821 (insert "><#/part>\n")
827 "<TABLE border=\"0\" WIDTH=\"98%\" cellpadding=0 cellspacing=0>"
831 (webmail-netaddress-single-part)
832 (goto-char (point-max))
836 (narrow-to-region p
(point-max))
837 (setq mime
(webmail-netaddress-single-part))
839 (goto-char (point-min))
840 ;; Some blank line to seperate mails.
841 (insert "\n\nFrom nobody " (current-time-string) "\n")
842 (insert "X-Gnus-Webmail: " (symbol-value 'user
)
843 "@" (symbol-name webmail-type
) "\n")
845 (insert (format "X-Message-ID: <%s@%s>\n" id webmail-address
)))
846 (unless (looking-at "$")
847 (if (search-forward "\n\n" nil t
)
849 (webmail-error "article@2")))
851 (narrow-to-region (point-min) (point))
852 (goto-char (point-min))
854 (if (looking-at "MIME-Version\\|Content-Type")
855 (delete-region (point)
858 (if (re-search-forward "^[^ \t]" nil t
)
859 (goto-char (match-beginning 0))
862 (goto-char (point-max))
864 (narrow-to-region (point) (point-max))
865 (insert "MIME-Version: 1.0\n"
868 (delete-region (point-min) (point-max))))
869 (goto-char (point-min))
871 (let (case-fold-search)
872 (while (re-search-forward "^From " nil t
)
875 (mm-append-to-file (point-min) (point-max) file
)))
877 (defun webmail-netscape-article (file id
)
878 (let (p p1 attachment count mime type
)
880 (webmail-encode-8bit)
881 (goto-char (point-min))
882 (if (not (search-forward "Trash" nil t
))
883 (webmail-error "article@1"))
884 (if (not (search-forward "<form>" nil t
))
885 (webmail-error "article@2"))
886 (delete-region (point-min) (match-beginning 0))
887 (if (not (search-forward "</form>" nil t
))
888 (webmail-error "article@3"))
889 (narrow-to-region (point-min) (match-end 0))
890 (goto-char (point-min))
891 (while (re-search-forward "[\040\t\r\n]+" nil t
)
893 (goto-char (point-min))
894 (while (re-search-forward "<a href=[^>]*>[^<]*</a>" nil t
)
896 (goto-char (point-min))
897 (while (search-forward "<b>" nil t
)
898 (replace-match "\n"))
899 (mm-url-remove-markup)
900 (mm-url-decode-entities-nbsp)
901 (goto-char (point-min))
903 (goto-char (point-min))
904 (while (re-search-forward "^\040+\\|\040+$" nil t
)
906 (goto-char (point-min))
907 (while (re-search-forward "\040+" nil t
)
909 (goto-char (point-max))
913 (unless (search-forward "<!-- Data -->" nil t
)
914 (webmail-error "article@4"))
916 (delete-region p
(point))
917 (goto-char (point-max))
918 (unless (re-search-backward
919 "<form name=\"Transfer2\"" p t
)
920 (webmail-error "article@5"))
921 (delete-region (point) (point-max))
923 (while (search-forward
924 "<TABLE border=\"0\" WIDTH=\"98%\" cellpadding=0 cellspacing=0>"
927 (unless (search-forward "</TABLE>" nil t
)
928 (webmail-error "article@6"))
930 (if (search-backward "<IMG " p t
)
932 (unless (re-search-forward "HREF=\"\\(/tpl/Attachment/[^/]+/\\([^/]+/[^\?]+\\)[^\"]+\\)\"" p1 t
)
933 (webmail-error "article@7"))
934 (setq attachment
(match-string 1))
935 (setq type
(match-string 2))
936 (unless (search-forward "</TABLE>" nil t
)
937 (webmail-error "article@8"))
938 (delete-region p
(point))
939 (let (bufname);; Attachment
941 (set-buffer (generate-new-buffer " *webmail-att*"))
942 (mm-url-insert (concat (car webmail-open-url
) attachment
))
943 (push (current-buffer) webmail-buffer-list
)
944 (setq bufname
(buffer-name)))
945 (insert "<#part type=" type
)
946 (insert " buffer=\"" bufname
"\"")
947 (insert " disposition=\"inline\"")
948 (insert "><#/part>\n")
954 "<TABLE border=\"0\" WIDTH=\"98%\" cellpadding=0 cellspacing=0>"
958 (webmail-netaddress-single-part)
959 (goto-char (point-max))
963 (narrow-to-region p
(point-max))
964 (setq mime
(webmail-netaddress-single-part))
966 (goto-char (point-min))
967 ;; Some blank line to seperate mails.
968 (insert "\n\nFrom nobody " (current-time-string) "\n")
969 (insert "X-Gnus-Webmail: " (symbol-value 'user
)
970 "@" (symbol-name webmail-type
) "\n")
972 (insert (format "X-Message-ID: <%s@%s>\n" id webmail-address
)))
973 (unless (looking-at "$")
974 (if (search-forward "\n\n" nil t
)
976 (webmail-error "article@2")))
978 (narrow-to-region (point-min) (point))
979 (goto-char (point-min))
981 (if (looking-at "MIME-Version\\|Content-Type")
982 (delete-region (point)
985 (if (re-search-forward "^[^ \t]" nil t
)
986 (goto-char (match-beginning 0))
989 (goto-char (point-max))
991 (narrow-to-region (point) (point-max))
992 (insert "MIME-Version: 1.0\n"
995 (delete-region (point-min) (point-max))))
996 (goto-char (point-min))
998 (let (case-fold-search)
999 (while (re-search-forward "^From " nil t
)
1002 (mm-append-to-file (point-min) (point-max) file
)))
1006 (defun webmail-my-deja-open ()
1007 (webmail-refresh-redirect)
1008 (goto-char (point-min))
1009 (if (re-search-forward "action=\"\\([^\"]+maillogin\\.py[^\"]*\\)\""
1011 (setq webmail-aux
(match-string 1))
1012 (webmail-error "open@1")))
1014 (defun webmail-my-deja-list ()
1015 (let (item id newp base
)
1016 (goto-char (point-min))
1017 (when (re-search-forward "href=\"\\(\\([^\"]*\\)/mailnf\\.[^\"]*\\)\""
1019 (let ((url (match-string 1)))
1020 (setq base
(match-string 2))
1022 (mm-url-insert url
)))
1023 (goto-char (point-min))
1024 (when (re-search-forward
1025 "(\\([0-9]+\\) Message.?-[^>]*\\([0-9]+\\) New"
1027 (message "Found %s mail(s), %s unread"
1028 (match-string 1) (match-string 2)))
1029 (goto-char (point-min))
1030 (while (re-search-forward
1031 "newmail\\.gif\\|href=\"[^\"]*\\(mailnf\\.[^\"]+act=view[^\"]+mid=\\([^\"&]+\\)[^\"]+\\)\""
1033 (if (setq id
(match-string 2))
1034 (when (and (or newp
(not webmail-newmail-only
))
1035 (not (assoc id webmail-articles
)))
1036 (push (cons id
(setq webmail-aux
1037 (concat base
"/" (match-string 1))))
1041 (setq webmail-articles
(nreverse webmail-articles
))))
1043 (defun webmail-my-deja-article-part (base)
1046 ((looking-at "[\t\040\r\n]*<!--[^>]*>")
1048 ((looking-at "[\t\040\r\n]*</PRE>")
1050 ((looking-at "[\t\040\r\n]*<PRE>")
1054 (narrow-to-region (point)
1055 (if (re-search-forward "</?PRE>" nil t
)
1058 (goto-char (point-min))
1059 (mm-url-remove-markup)
1060 (mm-url-decode-entities-nbsp)
1061 (goto-char (point-max))))
1062 ((looking-at "[\t\040\r\n]*<TABLE")
1064 (narrow-to-region (point)
1065 (if (search-forward "</TABLE>" nil t
2)
1068 (goto-char (point-min))
1069 (let (name type url bufname
)
1070 (if (and (search-forward "File Name:" nil t
)
1071 (re-search-forward "<FONT[^>]+>\\([^<]+\\)" nil t
))
1072 (setq name
(match-string 1)))
1073 (if (and (search-forward "File Type:" nil t
)
1074 (re-search-forward "<FONT[^>]+>\\([^<]+\\)" nil t
))
1075 (setq type
(match-string 1)))
1076 (unless (re-search-forward "action=\"getattach\\.cgi/\\([^\"]+\\)"
1078 (webmail-error "article@5"))
1079 (setq url
(concat base
"/getattach.cgi/" (match-string 1)
1081 (while (re-search-forward
1082 "type=hidden name=\"\\([^\"]+\\)\" value=\"\\([^\"]+\\)"
1084 (setq url
(concat url
"&" (match-string 1) "="
1086 (delete-region (point-min) (point-max))
1088 (set-buffer (generate-new-buffer " *webmail-att*"))
1090 (push (current-buffer) webmail-buffer-list
)
1091 (setq bufname
(buffer-name)))
1092 (insert "<#part type=\"" type
"\"")
1093 (if name
(insert " filename=\"" name
"\""))
1094 (insert " buffer=\"" bufname
"\"")
1095 (insert " disposition=inline><#/part>"))))
1097 (insert "<#part type=\"text/html\" disposition=inline>")
1098 (goto-char (point-max))
1099 (insert "<#/part>")))))
1101 (defun webmail-my-deja-article (file id
)
1103 (goto-char (point-min))
1104 (unless (string-match "\\([^\"]+\\)/mail" webmail-aux
)
1105 (webmail-error "article@0"))
1106 (setq base
(match-string 1 webmail-aux
))
1107 (when (re-search-forward
1108 "href=\"[^\"]*\\(mailnf\\.[^\"]+act=move[^\"]+mid=\\([^\"&]+\\)[^\"]+\\)\""
1110 (setq webmail-aux
(concat base
"/" (match-string 1)))
1111 (string-match "mid=[^\"&]+" webmail-aux
)
1112 (setq webmail-aux
(replace-match "mid=%s" nil nil webmail-aux
)))
1113 (unless (search-forward "<HR noshade>" nil t
)
1114 (webmail-error "article@1"))
1115 (delete-region (point-min) (point))
1116 (unless (search-forward "<HR noshade>" nil t
)
1117 (webmail-error "article@2"))
1119 (narrow-to-region (point-min) (point))
1120 (while (search-forward "\r\n" nil t
)
1121 (replace-match "\n"))
1122 (mm-url-remove-markup)
1123 (mm-url-decode-entities-nbsp)
1124 (goto-char (point-min))
1125 (while (re-search-forward "\n\n+" nil t
)
1126 (replace-match "\n"))
1127 (goto-char (point-max)))
1129 (narrow-to-region (point) (point-max))
1130 (goto-char (point-max))
1131 (unless (search-backward "<HR noshade>" nil t
)
1132 (webmail-error "article@3"))
1133 (unless (search-backward "</TT>" nil t
)
1134 (webmail-error "article@4"))
1135 (delete-region (point) (point-max))
1136 (goto-char (point-min))
1138 (webmail-my-deja-article-part base
))
1139 (insert "MIME-Version: 1.0\n"
1142 (delete-region (point-min) (point-max)))))
1143 (goto-char (point-min))
1144 (insert "\n\nFrom nobody " (current-time-string) "\n")
1145 (insert "X-Gnus-Webmail: " (symbol-value 'user
)
1146 "@" (symbol-name webmail-type
) "\n")
1147 (if (eq (char-after) ?
\n)
1149 (mm-append-to-file (point-min) (point-max) file
)))
1153 ;;; arch-tag: f75a4558-a8f6-46ec-b1c3-7a6434b3dd71
1154 ;;; webmail.el ends here