1 ;;; webmail.el --- interfacing with web mail
2 ;; Copyright (C) 1999-2000 Free Software Foundation, Inc.
4 ;; Author: Shenghuo Zhu <zsh@cs.rochester.edu>
5 ;; Keywords: hotmail netaddress my-deja netscape
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published
11 ;; by the Free Software Foundation; either version 2, or (at your
12 ;; option) any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful, but
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 ;; General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
26 ;; Note: You need to have `url' and `w3' installed for this backend to
27 ;; work. `w3' must be 4.0pre46+one-line-cookie patch or standalone
30 ;; Todo: To support more web mail servers.
33 ;; 1. Net@ddress may corrupt `X-Face'.
36 ;; Webmail is an experimental function, which means NO WARRANTY.
40 (eval-when-compile (require 'cl))
56 ;; Report failure to find w3 at load time if appropriate.
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 (list-snarf . webmail-hotmail-list)
78 (article-snarf . webmail-hotmail-article)
80 "%s&login=%s&f=33792&curmbox=ACTIVE&_lang=&foo=inbox&js=&page=&%s=on&_HMaction=MoveTo&tobox=trAsH&nullbox="
83 (paranoid cookie post)
84 (address . "mail.yahoo.com")
85 (open-url "http://mail.yahoo.com/")
86 (open-snarf . webmail-yahoo-open)
87 (login-url;; yahoo will not accept GET
90 ".tries=1&.src=ym&.last=&promo=&lg=us&.intl=us&.bypass=&.chkP=Y&.done=http%%253a%%2F%%2Fedit.yahoo.com%%2Fconfig%%2Fmail%%253f.intl%%3D&login=%s&passwd=%s"
92 (login-snarf . webmail-yahoo-login)
93 (list-url "%s&rb=Inbox&YN=1" webmail-aux)
94 (list-snarf . webmail-yahoo-list)
95 (article-snarf . webmail-yahoo-article)
97 "%s/ym/us/ShowFolder?YY=52107&inc=50&order=down&sort=date&pos=0&box=Inbox&DEL=Delete&destBox=&Mid=%s&destBox2="
100 (paranoid cookie post)
101 (address . "www.netaddress.com")
102 (open-url "http://www.netaddress.com/")
103 (open-snarf . webmail-netaddress-open)
107 "LoginState=2&SuccessfulLogin=%%2Ftpl&NewServerName=www.netaddress.com&JavaScript=JavaScript1.2&DomainID=4&NA31site=classic.netaddress.com&NA31port=80&UserID=%s&passwd=%s"
109 (login-snarf . webmail-netaddress-login)
111 "http://www.netaddress.com/tpl/Mail/%s/List?FolderID=-4&SortUseCase=True"
113 (list-snarf . webmail-netaddress-list)
114 (article-url "http://www.netaddress.com/")
115 (article-snarf . webmail-netaddress-article)
117 "http://www.netaddress.com/tpl/Message/%s/Move?FolderID=-4&Q=%s&N=&Sort=Date&F=-1"
120 (paranoid cookie post agent)
121 (address . "webmail.netscape.com")
122 (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")
123 (open-snarf . webmail-netscape-open)
126 ("http://ureg.netscape.com/iiop/UReg2/login/loginform")
127 "%s&U2_USERNAME=%s&U2_PASSWORD=%s"
128 webmail-aux user password)
129 (login-snarf . webmail-netaddress-login)
131 "http://webmail.netscape.com/tpl/Mail/%s/List?FolderID=-4&SortUseCase=True"
133 (list-snarf . webmail-netaddress-list)
134 (article-url "http://webmail.netscape.com/")
135 (article-snarf . webmail-netscape-article)
137 "http://webmail.netscape.com/tpl/Message/%s/Move?FolderID=-4&Q=%s&N=&Sort=Date&F=-1"
140 (paranoid cookie post)
141 (address . "www.my-deja.com")
142 (open-url "http://www.my-deja.com/")
143 (open-snarf . webmail-my-deja-open)
147 "member_name=%s&pw=%s&go=&priv_opt_MyDeja99="
149 (list-url "http://www.deja.com/rg_gotomail.xp")
150 (list-snarf . webmail-my-deja-list)
151 (article-snarf . webmail-my-deja-article)
153 "%s/gmm_multiplex.femail?%%2Fgmm_domovemesg_top.femail=Move+to%%3A&folder_top=%s%%3Azzz%%3A%%7E6trash%%3AF%%3A0&docid=%s"
154 webmail-aux user id))))
156 (defvar webmail-variables
157 '(address article-snarf article-url list-snarf list-url
158 login-url login-snarf open-url open-snarf site articles
159 post-process paranoid trash-url))
161 (defconst webmail-version "webmail 1.0")
163 (defvar webmail-newmail-only nil
164 "Only fetch new mails.")
166 (defvar webmail-move-to-trash-can t
167 "Move mail to trash can after fetch it.")
169 ;;; Internal variables
171 (defvar webmail-address nil)
172 (defvar webmail-paranoid nil)
173 (defvar webmail-aux nil)
174 (defvar webmail-session nil)
175 (defvar webmail-article-snarf nil)
176 (defvar webmail-article-url nil)
177 (defvar webmail-list-snarf nil)
178 (defvar webmail-list-url nil)
179 (defvar webmail-login-url nil)
180 (defvar webmail-login-snarf nil)
181 (defvar webmail-open-snarf nil)
182 (defvar webmail-open-url nil)
183 (defvar webmail-trash-url nil)
184 (defvar webmail-articles nil)
185 (defvar webmail-post-process nil)
187 (defvar webmail-buffer nil)
188 (defvar webmail-buffer-list nil)
190 (defvar webmail-type nil)
192 ;;; Interface functions
194 (defun webmail-error (str)
195 (message "%s HTML has changed; please get a new version of webmail (%s)"
197 (error "%s HTML has changed; please get a new version of webmail (%s)"
200 (defun webmail-setdefault (type)
201 (let ((type-def (cdr (assq type webmail-type-definition)))
202 (vars webmail-variables)
204 (setq webmail-type type)
206 (if (setq pair (assq var type-def))
207 (set (intern (concat "webmail-" (symbol-name var))) (cdr pair))
208 (set (intern (concat "webmail-" (symbol-name var))) nil)))))
210 (defun webmail-encode-www-form-urlencoded (pairs)
211 "Return PAIRS encoded for forms."
215 (concat (w3-form-encode-xwfu (car data)) "="
216 (w3-form-encode-xwfu (cdr data)))))
219 (defun webmail-fetch-simple (url content)
220 (let ((url-request-data content)
221 (url-request-method "POST")
222 (url-request-extra-headers
223 '(("Content-type" . "application/x-www-form-urlencoded"))))
227 (defun webmail-fetch-form (url pairs)
228 (let ((url-request-data (webmail-encode-www-form-urlencoded pairs))
229 (url-request-method "POST")
230 (url-request-extra-headers
231 '(("Content-type" . "application/x-www-form-urlencoded"))))
235 (defun webmail-eval (expr)
238 (cons (webmail-eval (car expr)) (webmail-eval (cdr expr))))
244 (defun webmail-url (xurl)
245 (mm-with-unibyte-current-buffer
247 ((eq (car xurl) 'content)
249 (webmail-fetch-simple (if (stringp (car xurl))
251 (apply 'format (webmail-eval (car xurl))))
252 (apply 'format (webmail-eval (cdr xurl)))))
253 ((eq (car xurl) 'post)
255 (webmail-fetch-form (car xurl) (webmail-eval (cdr xurl))))
257 (nnweb-insert (apply 'format (webmail-eval xurl)))))))
259 (defun webmail-init ()
260 "Initialize buffers and such."
261 (if (gnus-buffer-live-p webmail-buffer)
262 (set-buffer webmail-buffer)
265 (nnheader-set-temp-buffer " *webmail*")))))
267 (defvar url-package-name)
268 (defvar url-package-version)
269 (defvar url-cookie-multiple-line)
270 (defvar url-confirmation-func)
272 ;; Hack W3 POST redirect. See `url-parse-mime-headers'.
274 ;; Netscape uses "GET" as redirect method when orignal method is POST
275 ;; and status is 302, .i.e no security risks by default without
278 ;; Some web servers (at least Apache used by yahoo) return status 302
279 ;; instead of 303, though they mean 303.
281 (defun webmail-url-confirmation-func (prompt)
283 ((equal prompt (concat "Honor redirection with non-GET method "
284 "(possible security risks)? "))
286 ((equal prompt "Continue (with method of GET)? ")
290 (defun webmail-refresh-redirect ()
291 "Redirect refresh url in META."
292 (goto-char (point-min))
293 (while (re-search-forward
294 "HTTP-EQUIV=\"Refresh\"[^>]*URL=\\([^\"]+\\)\""
296 (let ((url (match-string 1)))
298 (mm-with-unibyte-current-buffer
300 (goto-char (point-min))))
302 (defun webmail-fetch (file subtype user password)
304 (webmail-setdefault subtype)
305 (let ((url-package-name (if (memq 'agent webmail-paranoid)
308 (url-package-version (if (memq 'agent webmail-paranoid)
310 url-package-version))
311 (url-cookie-multiple-line (if (memq 'cookie webmail-paranoid)
313 url-cookie-multiple-line))
314 (url-confirmation-func (if (memq 'post webmail-paranoid)
315 'webmail-url-confirmation-func
316 url-confirmation-func))
317 url-cookie-storage url-cookie-secure-storage
318 url-cookie-confirmation
321 (setq webmail-articles nil)
322 (when webmail-open-url
324 (webmail-url webmail-open-url))
325 (if webmail-open-snarf (funcall webmail-open-snarf))
326 (when webmail-login-url
328 (webmail-url webmail-login-url))
329 (if webmail-login-snarf
330 (funcall webmail-login-snarf))
331 (when webmail-list-url
333 (webmail-url webmail-list-url))
334 (if webmail-list-snarf
335 (funcall webmail-list-snarf))
336 (while (setq item (pop webmail-articles))
337 (message "Fetching mail #%d..." (setq n (1+ n)))
339 (mm-with-unibyte-current-buffer
340 (nnweb-insert (cdr item)))
342 (if webmail-article-snarf
343 (funcall webmail-article-snarf file id))
344 (when (and webmail-trash-url webmail-move-to-trash-can)
345 (message "Move mail #%d to trash can..." n)
348 (webmail-url webmail-trash-url)
350 (while (setq buf (pop webmail-buffer-list))
354 (while (setq buf (pop webmail-buffer-list))
357 (if webmail-post-process
358 (funcall webmail-post-process))))
360 (defun webmail-encode-8bit ()
361 (goto-char (point-min))
362 (skip-chars-forward "^\200-\377")
364 (insert (format "&%d;" (mm-char-int (char-after))))
366 (skip-chars-forward "^\200-\377")))
370 (defun webmail-hotmail-open ()
371 (goto-char (point-min))
372 (if (re-search-forward
373 "action=\"https?://\\([^/]+\\)/cgi-bin/dologin" nil t)
374 (setq webmail-aux (match-string 1))
375 (webmail-error "open@1")))
377 (defun webmail-hotmail-list ()
379 (goto-char (point-min))
380 (if (re-search-forward "[0-9]+ new" nil t)
381 (message "Found %s" (match-string 0))
382 (webmail-error "maybe your w3 version is too old"))
383 (goto-char (point-min))
384 (if (re-search-forward
385 "action=\"https?://\\([^/]+\\)/cgi-bin/HoTMaiL" nil t)
386 (setq site (match-string 1))
387 (webmail-error "list@1"))
388 (goto-char (point-min))
389 (if (re-search-forward "disk=\\([^&]+\\)&" nil t)
391 (concat "http://" site "/cgi-bin/HoTMaiL?disk="
393 (webmail-error "list@2"))
394 (goto-char (point-max))
395 (while (re-search-backward
396 "newmail\\.gif\\|href=\"\\(/cgi-bin/getmsg\\?[^\"]+\\)\""
398 (if (setq url (match-string 1))
400 (if (or newp (not webmail-newmail-only))
402 (if (string-match "msg=\\([^&]+\\)" url)
403 (setq id (match-string 1 url)))
404 (push (cons id (concat "http://" site url "&raw=0"))
409 ;; Thank victor@idaccr.org (Victor S. Miller) for raw=0
411 (defun webmail-hotmail-article (file id)
412 (goto-char (point-min))
413 (if (not (search-forward "<pre>" nil t))
414 (webmail-error "article@3"))
415 (skip-chars-forward "\n\r\t ")
416 (delete-region (point-min) (point))
417 (if (not (search-forward "</pre>" nil t))
418 (webmail-error "article@3.1"))
419 (delete-region (match-beginning 0) (point-max))
420 (nnweb-remove-markup)
421 (nnweb-decode-entities)
422 (goto-char (point-min))
423 (while (re-search-forward "\r\n?" nil t)
424 (replace-match "\n"))
425 (goto-char (point-min))
427 (if (not (looking-at "\n*From "))
428 (insert "From nobody " (current-time-string) "\n"))
429 (mm-append-to-file (point-min) (point-max) file))
431 (defun webmail-hotmail-article-old (file id)
432 (let (p attachment count mime hotmail-direct)
434 (webmail-encode-8bit)
435 (goto-char (point-min))
436 (if (not (search-forward "<DIV>" nil t))
437 (if (not (search-forward "Reply All" nil t))
438 (webmail-error "article@1")
439 (setq hotmail-direct t))
440 (goto-char (match-beginning 0)))
441 (narrow-to-region (point-min) (point))
442 (if (not (search-backward "<table" nil t 2))
443 (webmail-error "article@1.1"))
444 (delete-region (point-min) (match-beginning 0))
445 (while (search-forward "<a href=" nil t)
446 (setq p (match-beginning 0))
447 (search-forward "</a>" nil t)
448 (delete-region p (match-end 0)))
449 (nnweb-remove-markup)
450 (nnweb-decode-entities)
451 (goto-char (point-min))
453 (goto-char (point-min))
454 (when (search-forward "\n\n" nil t)
456 (delete-region (point) (point-max)))
457 (goto-char (point-max))
461 (while (re-search-forward
462 "<tt>\\|<div>\\|\\(http://[^/]+/cgi-bin/getmsg/\\([^\?]+\\)\?[^\"]*\\)\""
464 (if (setq attachment (match-string 1))
465 (let ((filename (match-string 2))
466 bufname);; Attachment
467 (delete-region p (match-end 0))
469 (set-buffer (generate-new-buffer " *webmail-att*"))
470 (nnweb-insert attachment)
471 (push (current-buffer) webmail-buffer-list)
472 (setq bufname (buffer-name)))
474 (insert "<#part type="
476 (string-match "\\.[^\\.]+$" filename)
477 (mailcap-extension-to-mime
478 (match-string 0 filename)))
479 "application/octet-stream"))
480 (insert " buffer=\"" bufname "\"")
481 (insert " filename=\"" filename "\"")
482 (insert " disposition=\"inline\"")
483 (insert "><#/part>\n")
485 (delete-region p (match-end 0))
487 (if (not (search-forward "</tt>" nil t))
488 (webmail-error "article@1.2")
489 (delete-region (match-beginning 0) (match-end 0)))
491 (while (and (> count 0)
492 (re-search-forward "</div>\\|\\(<div>\\)" nil t))
494 (setq count (1+ count))
495 (if (= (setq count (1- count)) 0)
496 (delete-region (match-beginning 0)
498 (narrow-to-region p (point))
499 (goto-char (point-min))
501 ((looking-at "<pre>")
502 (goto-char (match-end 0))
503 (if (looking-at "$") (forward-char))
504 (delete-region (point-min) (point))
505 (nnweb-remove-markup)
506 (nnweb-decode-entities)
510 (insert "<#part type=\"text/html\" disposition=inline>")
511 (goto-char (point-max))
512 (insert "<#/part>")))
513 (goto-char (point-max))
516 (delete-region p (point-max))
517 (goto-char (point-min))
518 ;; Some blank line to seperate mails.
519 (insert "\n\nFrom nobody " (current-time-string) "\n")
521 (insert (format "Message-ID: <%s@hotmail.com>\n" id)))
522 (unless (looking-at "$")
523 (if (search-forward "\n\n" nil t)
525 (webmail-error "article@2")))
526 (narrow-to-region (point) (point-max))
528 (insert "MIME-Version: 1.0\n"
531 (delete-region (point-min) (point-max)))))
532 (goto-char (point-min))
534 (let (case-fold-search)
535 (while (re-search-forward "^From " nil t)
538 (mm-append-to-file (point-min) (point-max) file)))
542 (defun webmail-yahoo-open ()
543 (goto-char (point-min))
544 (if (re-search-forward "action=\"\\([^\"]+\\)\"" nil t)
545 (setq webmail-aux (match-string 1))
546 (webmail-error "open@1")))
548 (defun webmail-yahoo-login ()
549 (goto-char (point-min))
550 (if (re-search-forward "http://[a-zA-Z][0-9]\\.mail\\.yahoo\\.com/" nil t)
551 (setq webmail-aux (match-string 0))
552 (webmail-error "login@1"))
553 (if (re-search-forward "YY=[0-9]+" nil t)
554 (setq webmail-aux (concat webmail-aux "ym/us/ShowFolder?"
556 (webmail-error "login@2")))
558 (defun webmail-yahoo-list ()
559 (let (url (newp t) (tofetch 0))
560 (goto-char (point-min))
561 (when (re-search-forward
562 "showing [0-9]+-\\([0-9]+\\) of \\([0-9]+\\)" nil t)
563 ;;(setq listed (match-string 1))
564 (message "Found %s mail(s)" (match-string 2)))
565 (if (string-match "http://[^/]+" webmail-aux)
566 (setq webmail-aux (match-string 0 webmail-aux))
567 (webmail-error "list@1"))
568 (goto-char (point-min))
569 (while (re-search-forward
570 "bgcolor=\"#eeeeee\"\\|href=\"\\(/ym/us/ShowLetter\\?MsgId=\\([^&]+\\)&[^\"]*\\)\""
572 (if (setq url (match-string 1))
574 (when (or newp (not webmail-newmail-only))
575 (push (cons (match-string 2) (concat webmail-aux url "&toc=1"))
577 (setq tofetch (1+ tofetch)))
580 (setq webmail-articles (nreverse webmail-articles))
581 (message "Fetching %d mail(s)" tofetch)))
583 (defun webmail-yahoo-article (file id)
586 (goto-char (point-min))
587 (if (not (search-forward "value=\"Done\"" nil t))
588 (webmail-error "article@1"))
589 (if (not (search-forward "<table" nil t))
590 (webmail-error "article@2"))
591 (delete-region (point-min) (match-beginning 0))
592 (if (not (search-forward "</table>" nil t))
593 (webmail-error "article@3"))
594 (narrow-to-region (point-min) (match-end 0))
595 (while (search-forward "<a href=" nil t)
596 (setq p (match-beginning 0))
597 (search-forward "</a>" nil t)
598 (delete-region p (match-end 0)))
599 (nnweb-remove-markup)
600 (nnweb-decode-entities)
601 (goto-char (point-min))
603 (goto-char (point-max))
607 (while (re-search-forward "[^\"]*/ShowLetter/[^\?]+\?[^\"]*" nil t)
608 (setq attachment (match-string 0))
609 (let (bufname ct ctl cd description)
610 (if (not (search-forward "<table" nil t))
611 (webmail-error "article@4"))
612 (delete-region p (match-beginning 0))
613 (if (not (search-forward "</table>" nil t))
614 (webmail-error "article@5"))
615 (narrow-to-region p (match-end 0))
616 (nnweb-remove-markup)
617 (nnweb-decode-entities)
618 (goto-char (point-min))
620 (setq ct (mail-fetch-field "content-type")
621 ctl (ignore-errors (mail-header-parse-content-type ct))
622 ;;cte (mail-fetch-field "content-transfer-encoding")
623 cd (mail-fetch-field "content-disposition")
624 description (mail-fetch-field "content-description")
625 id (mail-fetch-field "content-id"))
626 (delete-region (point-min) (point-max))
629 (set-buffer (generate-new-buffer " *webmail-att*"))
630 (nnweb-insert (concat webmail-aux attachment))
631 (push (current-buffer) webmail-buffer-list)
632 (setq bufname (buffer-name)))
634 (if (and ctl (not (equal (car ctl) "text/")))
635 (insert " type=\"" (car ctl) "\""))
636 (insert " buffer=\"" bufname "\"")
638 (insert " disposition=\"" cd "\""))
640 (insert " description=\"" description "\""))
641 (insert "><#/part>\n")
643 (delete-region p (point-max))
644 (goto-char (point-min))
645 ;; Some blank line to seperate mails.
646 (insert "\n\nFrom nobody " (current-time-string) "\n")
648 (insert (format "Message-ID: <%s@yahoo.com>\n" id)))
649 (unless (looking-at "$")
650 (if (search-forward "\n\n" nil t)
652 (webmail-error "article@2")))
653 (narrow-to-region (point) (point-max))
654 (insert "MIME-Version: 1.0\n"
657 (delete-region (point-min) (point-max))))
658 (goto-char (point-min))
660 (let (case-fold-search)
661 (while (re-search-forward "^From " nil t)
664 (mm-append-to-file (point-min) (point-max) file)))
668 (defun webmail-netscape-open ()
669 (goto-char (point-min))
670 (if (re-search-forward "login/hint\\?\\([^\"]+\\)\"" nil t)
671 (setq webmail-aux (match-string 1))
672 (webmail-error "open@1")))
674 (defun webmail-netaddress-open ()
675 (goto-char (point-min))
676 (if (re-search-forward "action=\"\\([^\"]+\\)\"" nil t)
677 (setq webmail-aux (concat (car webmail-open-url) (match-string 1)))
678 (webmail-error "open@1")))
680 (defun webmail-netaddress-login ()
681 (webmail-refresh-redirect)
682 (goto-char (point-min))
683 (if (re-search-forward "tpl/[^/]+/\\([^/]+\\)" nil t)
684 (setq webmail-session (match-string 1))
685 (webmail-error "login@1")))
687 (defun webmail-netaddress-list ()
689 (goto-char (point-min))
690 (when (re-search-forward
691 "(\\([0-9]+\\) unread, \\([0-9]+\\) total)" nil t)
692 (message "Found %s mail(s), %s unread"
693 (match-string 2) (match-string 1)))
694 (goto-char (point-min))
695 (while (re-search-forward
696 "MR\\[i\\]\\.R='\\([^']*\\)'\\|MR\\[i\\]\\.Q='\\([^']+\\)'" nil t)
697 (if (setq id (match-string 2))
700 (format "%s/tpl/Message/%s/Read?Q=%s&FolderID=-4&SortUseCase=True&Sort=Date&Headers=True"
701 (car webmail-article-url)
702 webmail-session id)))
703 (if (or (not webmail-newmail-only)
704 (equal (match-string 1) "True"))
705 (push item webmail-articles))))
706 (setq webmail-articles (nreverse webmail-articles))))
708 (defun webmail-netaddress-single-part ()
709 (goto-char (point-min))
711 ((looking-at "[\t\040\r\n]*<font face=[^>]+>[\t\040\r\n]*")
714 (while (re-search-forward "[\t\040\r\n]+" nil t)
716 (goto-char (point-min))
717 (while (re-search-forward "<br>" nil t)
718 (replace-match "\n"))
719 (nnweb-remove-markup)
720 (nnweb-decode-entities)
723 (insert "<#part type=\"text/html\" disposition=inline>")
724 (goto-char (point-max))
728 (defun webmail-netaddress-article (file id)
729 (let (p p1 attachment count mime type)
731 (webmail-encode-8bit)
732 (goto-char (point-min))
733 (if (not (search-forward "Trash" nil t))
734 (webmail-error "article@1"))
735 (if (not (search-forward "<form>" nil t))
736 (webmail-error "article@2"))
737 (delete-region (point-min) (match-beginning 0))
738 (if (not (search-forward "</form>" nil t))
739 (webmail-error "article@3"))
740 (narrow-to-region (point-min) (match-end 0))
741 (goto-char (point-min))
742 (while (re-search-forward "[\040\t\r\n]+" nil t)
744 (goto-char (point-min))
745 (while (search-forward "<b>" nil t)
746 (replace-match "\n"))
747 (nnweb-remove-markup)
748 (nnweb-decode-entities)
749 (goto-char (point-min))
751 (goto-char (point-min))
752 (while (re-search-forward "^\040+\\|\040+$" nil t)
754 (goto-char (point-min))
755 (while (re-search-forward "\040+" nil t)
757 (goto-char (point-max))
761 (unless (search-forward "<!-- Data -->" nil t)
762 (webmail-error "article@4"))
764 (delete-region p (point))
765 (goto-char (point-max))
766 (unless (re-search-backward
767 "[\040\t]*<br>[\040\t\r\n]*<br>[\040\t\r\n]*<form" p t)
768 (webmail-error "article@5"))
769 (delete-region (point) (point-max))
771 (while (search-forward
772 "<TABLE border=\"0\" WIDTH=\"98%\" cellpadding=0 cellspacing=0>"
775 (unless (search-forward "</TABLE>" nil t)
776 (webmail-error "article@6"))
778 (if (search-backward "<IMG " p t)
780 (unless (re-search-forward "HREF=\"\\(/tpl/Attachment/[^/]+/\\([^/]+/[^\?]+\\)[^\"]+\\)\"" p1 t)
781 (webmail-error "article@7"))
782 (setq attachment (match-string 1))
783 (setq type (match-string 2))
784 (unless (search-forward "</TABLE>" nil t)
785 (webmail-error "article@8"))
786 (delete-region p (point))
787 (let (bufname);; Attachment
789 (set-buffer (generate-new-buffer " *webmail-att*"))
790 (nnweb-insert (concat (car webmail-open-url) attachment))
791 (push (current-buffer) webmail-buffer-list)
792 (setq bufname (buffer-name)))
793 (insert "<#part type=" type)
794 (insert " buffer=\"" bufname "\"")
795 (insert " disposition=\"inline\"")
796 (insert "><#/part>\n")
802 "<TABLE border=\"0\" WIDTH=\"98%\" cellpadding=0 cellspacing=0>"
806 (webmail-netaddress-single-part)
807 (goto-char (point-max))
811 (narrow-to-region p (point-max))
812 (setq mime (webmail-netaddress-single-part))
814 (goto-char (point-min))
815 ;; Some blank line to seperate mails.
816 (insert "\n\nFrom nobody " (current-time-string) "\n")
818 (insert (format "Message-ID: <%s@%s>\n" id webmail-address)))
819 (unless (looking-at "$")
820 (if (search-forward "\n\n" nil t)
822 (webmail-error "article@2")))
824 (narrow-to-region (point-min) (point))
825 (goto-char (point-min))
827 (if (looking-at "MIME-Version\\|Content-Type")
828 (delete-region (point)
831 (if (re-search-forward "^[^ \t]" nil t)
832 (goto-char (match-beginning 0))
835 (goto-char (point-max))
837 (narrow-to-region (point) (point-max))
838 (insert "MIME-Version: 1.0\n"
841 (delete-region (point-min) (point-max))))
842 (goto-char (point-min))
844 (let (case-fold-search)
845 (while (re-search-forward "^From " nil t)
848 (mm-append-to-file (point-min) (point-max) file)))
850 (defun webmail-netscape-article (file id)
851 (let (p p1 attachment count mime type)
853 (webmail-encode-8bit)
854 (goto-char (point-min))
855 (if (not (search-forward "Trash" nil t))
856 (webmail-error "article@1"))
857 (if (not (search-forward "<form>" nil t))
858 (webmail-error "article@2"))
859 (delete-region (point-min) (match-beginning 0))
860 (if (not (search-forward "</form>" nil t))
861 (webmail-error "article@3"))
862 (narrow-to-region (point-min) (match-end 0))
863 (goto-char (point-min))
864 (while (re-search-forward "[\040\t\r\n]+" nil t)
866 (goto-char (point-min))
867 (while (re-search-forward "<a href=[^>]*>[^<]*</a>" nil t)
869 (goto-char (point-min))
870 (while (search-forward "<b>" nil t)
871 (replace-match "\n"))
872 (nnweb-remove-markup)
873 (nnweb-decode-entities)
874 (goto-char (point-min))
876 (goto-char (point-min))
877 (while (re-search-forward "^\040+\\|\040+$" nil t)
879 (goto-char (point-min))
880 (while (re-search-forward "\040+" nil t)
882 (goto-char (point-max))
886 (unless (search-forward "<!-- Data -->" nil t)
887 (webmail-error "article@4"))
889 (delete-region p (point))
890 (goto-char (point-max))
891 (unless (re-search-backward
892 "<form name=\"Transfer2\"" p t)
893 (webmail-error "article@5"))
894 (delete-region (point) (point-max))
896 (while (search-forward
897 "<TABLE border=\"0\" WIDTH=\"98%\" cellpadding=0 cellspacing=0>"
900 (unless (search-forward "</TABLE>" nil t)
901 (webmail-error "article@6"))
903 (if (search-backward "<IMG " p t)
905 (unless (re-search-forward "HREF=\"\\(/tpl/Attachment/[^/]+/\\([^/]+/[^\?]+\\)[^\"]+\\)\"" p1 t)
906 (webmail-error "article@7"))
907 (setq attachment (match-string 1))
908 (setq type (match-string 2))
909 (unless (search-forward "</TABLE>" nil t)
910 (webmail-error "article@8"))
911 (delete-region p (point))
912 (let (bufname);; Attachment
914 (set-buffer (generate-new-buffer " *webmail-att*"))
915 (nnweb-insert (concat (car webmail-open-url) attachment))
916 (push (current-buffer) webmail-buffer-list)
917 (setq bufname (buffer-name)))
918 (insert "<#part type=" type)
919 (insert " buffer=\"" bufname "\"")
920 (insert " disposition=\"inline\"")
921 (insert "><#/part>\n")
927 "<TABLE border=\"0\" WIDTH=\"98%\" cellpadding=0 cellspacing=0>"
931 (webmail-netaddress-single-part)
932 (goto-char (point-max))
936 (narrow-to-region p (point-max))
937 (setq mime (webmail-netaddress-single-part))
939 (goto-char (point-min))
940 ;; Some blank line to seperate mails.
941 (insert "\n\nFrom nobody " (current-time-string) "\n")
943 (insert (format "Message-ID: <%s@%s>\n" id webmail-address)))
944 (unless (looking-at "$")
945 (if (search-forward "\n\n" nil t)
947 (webmail-error "article@2")))
949 (narrow-to-region (point-min) (point))
950 (goto-char (point-min))
952 (if (looking-at "MIME-Version\\|Content-Type")
953 (delete-region (point)
956 (if (re-search-forward "^[^ \t]" nil t)
957 (goto-char (match-beginning 0))
960 (goto-char (point-max))
962 (narrow-to-region (point) (point-max))
963 (insert "MIME-Version: 1.0\n"
966 (delete-region (point-min) (point-max))))
967 (goto-char (point-min))
969 (let (case-fold-search)
970 (while (re-search-forward "^From " nil t)
973 (mm-append-to-file (point-min) (point-max) file)))
977 (defun webmail-my-deja-open ()
978 (webmail-refresh-redirect)
979 (goto-char (point-min))
980 (if (re-search-forward "action=\"\\([^\"]+login_confirm\\.xp[^\"]*\\)\""
982 (setq webmail-aux (match-string 1))
983 (webmail-error "open@1")))
985 (defun webmail-my-deja-list ()
987 (goto-char (point-min))
988 (when (re-search-forward
989 "(\\([0-9]+\\) message(s), \\([0-9]+\\) new, \\([0-9]+\\) k )"
991 (message "Found %s mail(s), %s unread, total size %s K"
992 (match-string 1) (match-string 2) (match-string 3)))
993 (goto-char (point-min))
994 (while (re-search-forward
995 "• \\|\\(http:[^\"]+\\)/display_seemesg\\.femail\\?docid=\\([^&\"]+\\)"
997 (if (setq id (match-string 2))
998 (when (or newp (not webmail-newmail-only))
1000 (cons id (format "%s/gmm_multiplex.femail?docid=%s&femail_page_name=display_page&bool_next_on_disp_pg=true&bool_prev_on_disp_pg=false&display_all_headers=false&%%2Fgmm_save.femail=Download&femail_page_name=display_page&bool_next_on_disp_pg=true&bool_prev_on_disp_pg=false&display_all_headers=false"
1001 (match-string 1) id))
1003 (setq webmail-aux (match-string 1))
1006 (setq webmail-articles (nreverse webmail-articles))))
1008 (defun webmail-my-deja-article (file id)
1010 (goto-char (point-min))
1011 (unless (re-search-forward "\\(http:[^\"]+/attachment/entire_message.txt[^\"]+\\)" nil t)
1012 (webmail-error "article@1"))
1013 (setq url (match-string 1))
1015 (mm-with-unibyte-current-buffer
1017 (goto-char (point-min))
1018 (while (search-forward "\r\n" nil t)
1019 (replace-match "\n"))
1020 (goto-char (point-min))
1021 (insert "\n\nFrom nobody " (current-time-string) "\n")
1022 (mm-append-to-file (point-min) (point-max) file)))
1026 ;;; webmail.el ends here