1 ;;; webmail.el --- interfacing with web mail
2 ;; Copyright (C) 1999 Free Software Foundation, Inc.
4 ;; Author: Shenghuo Zhu <zsh@cs.rochester.edu>
5 ;; Keywords: hotmail yahoo netaddress my-deja
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=&js=&foo=inbox&page=&%s=on&Move+To.x=Move+To&tobox=trAsH"
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-snarf . webmail-netaddress-article)
116 "http://www.netaddress.com/tpl/Message/%s/Move?FolderID=-4&Q=%s&N=&Sort=Date&F=-1"
119 (paranoid cookie post)
120 (address . "www.my-deja.com")
121 (open-url "http://www.my-deja.com/")
122 (open-snarf . webmail-my-deja-open)
126 "member_name=%s&pw=%s&go=&priv_opt_MyDeja99="
128 (list-url "http://www.deja.com/rg_gotomail.xp")
129 (list-snarf . webmail-my-deja-list)
130 (article-snarf . webmail-my-deja-article)
132 "%s/gmm_multiplex.femail?%%2Fgmm_domovemesg_top.femail=Move+to%%3A&folder_top=%s%%3Azzz%%3A%%7E6trash%%3AF%%3A0&docid=%s"
133 webmail-aux user id))))
135 (defvar webmail-variables
136 '(address article-snarf article-url list-snarf list-url
137 login-url login-snarf open-url open-snarf site articles
138 post-process paranoid trash-url))
140 (defconst webmail-version "webmail 1.0")
142 (defvar webmail-newmail-only nil
143 "Only fetch new mails.")
145 (defvar webmail-move-to-trash-can t
146 "Move mail to trash can after fetch it.")
148 ;;; Internal variables
150 (defvar webmail-address nil)
151 (defvar webmail-paranoid nil)
152 (defvar webmail-aux nil)
153 (defvar webmail-session nil)
154 (defvar webmail-article-snarf nil)
155 (defvar webmail-article-url nil)
156 (defvar webmail-list-snarf nil)
157 (defvar webmail-list-url nil)
158 (defvar webmail-login-url nil)
159 (defvar webmail-login-snarf nil)
160 (defvar webmail-open-snarf nil)
161 (defvar webmail-open-url nil)
162 (defvar webmail-trash-url nil)
163 (defvar webmail-articles nil)
164 (defvar webmail-post-process nil)
166 (defvar webmail-buffer nil)
167 (defvar webmail-buffer-list nil)
169 (defvar webmail-type nil)
171 ;;; Interface functions
173 (defun webmail-error (str)
174 (message "%s HTML has changed; please get a new version of webmail (%s)"
176 (error "%s HTML has changed; please get a new version of webmail (%s)"
179 (defun webmail-setdefault (type)
180 (let ((type-def (cdr (assq type webmail-type-definition)))
181 (vars webmail-variables)
183 (setq webmail-type type)
185 (if (setq pair (assq var type-def))
186 (set (intern (concat "webmail-" (symbol-name var))) (cdr pair))
187 (set (intern (concat "webmail-" (symbol-name var))) nil)))))
189 (defun webmail-encode-www-form-urlencoded (pairs)
190 "Return PAIRS encoded for forms."
194 (concat (w3-form-encode-xwfu (car data)) "="
195 (w3-form-encode-xwfu (cdr data)))))
198 (defun webmail-fetch-simple (url content)
199 (let ((url-request-data content)
200 (url-request-method "POST")
201 (url-request-extra-headers
202 '(("Content-type" . "application/x-www-form-urlencoded"))))
206 (defun webmail-fetch-form (url pairs)
207 (let ((url-request-data (webmail-encode-www-form-urlencoded pairs))
208 (url-request-method "POST")
209 (url-request-extra-headers
210 '(("Content-type" . "application/x-www-form-urlencoded"))))
214 (defun webmail-eval (expr)
217 (cons (webmail-eval (car expr)) (webmail-eval (cdr expr))))
223 (defun webmail-url (xurl)
224 (mm-with-unibyte-current-buffer
226 ((eq (car xurl) 'content)
228 (webmail-fetch-simple (if (stringp (car xurl))
230 (apply 'format (webmail-eval (car xurl))))
231 (apply 'format (webmail-eval (cdr xurl)))))
232 ((eq (car xurl) 'post)
234 (webmail-fetch-form (car xurl) (webmail-eval (cdr xurl))))
236 (nnweb-insert (apply 'format (webmail-eval xurl)))))))
238 (defun webmail-init ()
239 "Initialize buffers and such."
240 (if (gnus-buffer-live-p webmail-buffer)
241 (set-buffer webmail-buffer)
244 (nnheader-set-temp-buffer " *webmail*")))))
246 (defvar url-package-name)
247 (defvar url-package-version)
248 (defvar url-cookie-multiple-line)
249 (defvar url-confirmation-func)
251 ;; Hack W3 POST redirect. See `url-parse-mime-headers'.
253 ;; Netscape uses "GET" as redirect method when orignal method is POST
254 ;; and status is 302, .i.e no security risks by default without
257 ;; Some web servers (at least Apache used by yahoo) return status 302
258 ;; instead of 303, though they mean 303.
260 (defun webmail-url-confirmation-func (prompt)
262 ((equal prompt (concat "Honor redirection with non-GET method "
263 "(possible security risks)? "))
265 ((equal prompt "Continue (with method of GET)? ")
269 (defun webmail-refresh-redirect ()
270 "Redirect refresh url in META."
271 (goto-char (point-min))
272 (while (re-search-forward
273 "HTTP-EQUIV=\"Refresh\"[^>]*URL=\\([^\"]+\\)\""
275 (let ((url (match-string 1)))
277 (mm-with-unibyte-current-buffer
279 (goto-char (point-min))))
281 (defun webmail-fetch (file subtype user password)
283 (webmail-setdefault subtype)
284 (let ((url-package-name (if (memq 'agent webmail-paranoid)
287 (url-package-version (if (memq 'agent webmail-paranoid)
289 url-package-version))
290 (url-cookie-multiple-line (if (memq 'cookie webmail-paranoid)
292 url-cookie-multiple-line))
293 (url-confirmation-func (if (memq 'post webmail-paranoid)
294 'webmail-url-confirmation-func
295 url-confirmation-func))
296 url-cookie-storage url-cookie-secure-storage
297 url-cookie-confirmation
300 (setq webmail-articles nil)
301 (when webmail-open-url
303 (webmail-url webmail-open-url))
304 (if webmail-open-snarf (funcall webmail-open-snarf))
305 (when webmail-login-url
307 (webmail-url webmail-login-url))
308 (if webmail-login-snarf
309 (funcall webmail-login-snarf))
310 (when webmail-list-url
312 (webmail-url webmail-list-url))
313 (if webmail-list-snarf
314 (funcall webmail-list-snarf))
315 (while (setq item (pop webmail-articles))
316 (message "Fetching mail #%d..." (setq n (1+ n)))
318 (mm-with-unibyte-current-buffer
319 (nnweb-insert (cdr item)))
321 (if webmail-article-snarf
322 (funcall webmail-article-snarf file id))
323 (when (and webmail-trash-url webmail-move-to-trash-can)
324 (message "Move mail #%d to trash can..." n)
327 (webmail-url webmail-trash-url)
329 (while (setq buf (pop webmail-buffer-list))
333 (while (setq buf (pop webmail-buffer-list))
336 (if webmail-post-process
337 (funcall webmail-post-process))))
339 (defun webmail-encode-8bit ()
340 (goto-char (point-min))
341 (skip-chars-forward "^\200-\377")
343 (insert (format "&%d;" (mm-char-int (char-after))))
345 (skip-chars-forward "^\200-\377")))
349 (defun webmail-hotmail-open ()
350 (goto-char (point-min))
351 (if (re-search-forward
352 "action=\"https?://\\([^/]+\\)/cgi-bin/dologin" nil t)
353 (setq webmail-aux (match-string 1))
354 (webmail-error "open@1")))
356 (defun webmail-hotmail-list ()
358 (goto-char (point-min))
359 (if (re-search-forward "[0-9]+ messages, [0-9]+ new" nil t)
360 (message "Found %s" (match-string 0))
361 (webmail-error "maybe your w3 version is too old"))
362 (goto-char (point-min))
363 (if (re-search-forward
364 "action=\"https?://\\([^/]+\\)/cgi-bin/HoTMaiL" nil t)
365 (setq site (match-string 1))
366 (webmail-error "list@1"))
367 (goto-char (point-min))
368 (if (re-search-forward "disk=\\([^&]+\\)&" nil t)
370 (concat "http://" site "/cgi-bin/HoTMaiL?disk="
372 (webmail-error "list@2"))
373 (goto-char (point-max))
374 (while (re-search-backward
375 "newmail\\.gif\\|href=\"\\(/cgi-bin/getmsg\\?[^\"]+\\)\""
377 (if (setq url (match-string 1))
379 (if (or newp (not webmail-newmail-only))
381 (if (string-match "msg=\\([^&]+\\)" url)
382 (setq id (match-string 1 url)))
383 (push (cons id (concat "http://" site url "&raw=0"))
388 ;; Thank victor@idaccr.org (Victor S. Miller) for raw=0
390 (defun webmail-hotmail-article (file id)
391 (goto-char (point-min))
392 (if (not (search-forward "<pre>" nil t))
393 (webmail-error "article@3"))
394 (skip-chars-forward "\n\r\t ")
395 (delete-region (point-min) (point))
396 (if (not (search-forward "</pre>" nil t))
397 (webmail-error "article@3.1"))
398 (delete-region (match-beginning 0) (point-max))
399 (nnweb-remove-markup)
400 (nnweb-decode-entities)
401 (goto-char (point-min))
402 (while (re-search-forward "\r\n?" nil t)
403 (replace-match "\n"))
404 (goto-char (point-min))
406 (if (not (looking-at "\n*From "))
407 (insert "From nobody " (current-time-string) "\n"))
408 (mm-append-to-file (point-min) (point-max) file))
410 (defun webmail-hotmail-article-old (file id)
411 (let (p attachment count mime hotmail-direct)
413 (webmail-encode-8bit)
414 (goto-char (point-min))
415 (if (not (search-forward "<DIV>" nil t))
416 (if (not (search-forward "Reply All" nil t))
417 (webmail-error "article@1")
418 (setq hotmail-direct t))
419 (goto-char (match-beginning 0)))
420 (narrow-to-region (point-min) (point))
421 (if (not (search-backward "<table" nil t 2))
422 (webmail-error "article@1.1"))
423 (delete-region (point-min) (match-beginning 0))
424 (while (search-forward "<a href=" nil t)
425 (setq p (match-beginning 0))
426 (search-forward "</a>" nil t)
427 (delete-region p (match-end 0)))
428 (nnweb-remove-markup)
429 (nnweb-decode-entities)
430 (goto-char (point-min))
432 (goto-char (point-min))
433 (when (search-forward "\n\n" nil t)
435 (delete-region (point) (point-max)))
436 (goto-char (point-max))
440 (while (re-search-forward
441 "<tt>\\|<div>\\|\\(http://[^/]+/cgi-bin/getmsg/\\([^\?]+\\)\?[^\"]*\\)\""
443 (if (setq attachment (match-string 1))
444 (let ((filename (match-string 2))
445 bufname);; Attachment
446 (delete-region p (match-end 0))
448 (set-buffer (generate-new-buffer " *webmail-att*"))
449 (nnweb-insert attachment)
450 (push (current-buffer) webmail-buffer-list)
451 (setq bufname (buffer-name)))
453 (insert "<#part type="
455 (string-match "\\.[^\\.]+$" filename)
456 (mailcap-extension-to-mime
457 (match-string 0 filename)))
458 "application/octet-stream"))
459 (insert " buffer=\"" bufname "\"")
460 (insert " filename=\"" filename "\"")
461 (insert " disposition=\"inline\"")
462 (insert "><#/part>\n")
464 (delete-region p (match-end 0))
466 (if (not (search-forward "</tt>" nil t))
467 (webmail-error "article@1.2")
468 (delete-region (match-beginning 0) (match-end 0)))
470 (while (and (> count 0)
471 (re-search-forward "</div>\\|\\(<div>\\)" nil t))
473 (setq count (1+ count))
474 (if (= (setq count (1- count)) 0)
475 (delete-region (match-beginning 0)
477 (narrow-to-region p (point))
478 (goto-char (point-min))
480 ((looking-at "<pre>")
481 (goto-char (match-end 0))
482 (if (looking-at "$") (forward-char))
483 (delete-region (point-min) (point))
484 (nnweb-remove-markup)
485 (nnweb-decode-entities)
489 (insert "<#part type=\"text/html\" disposition=inline>")
490 (goto-char (point-max))
491 (insert "<#/part>")))
492 (goto-char (point-max))
495 (delete-region p (point-max))
496 (goto-char (point-min))
497 ;; Some blank line to seperate mails.
498 (insert "\n\nFrom nobody " (current-time-string) "\n")
500 (insert (format "Message-ID: <%s@hotmail.com>\n" id)))
501 (unless (looking-at "$")
502 (if (search-forward "\n\n" nil t)
504 (webmail-error "article@2")))
505 (narrow-to-region (point) (point-max))
507 (insert "MIME-Version: 1.0\n"
510 (delete-region (point-min) (point-max)))))
511 (goto-char (point-min))
513 (let (case-fold-search)
514 (while (re-search-forward "^From " nil t)
517 (mm-append-to-file (point-min) (point-max) file)))
521 (defun webmail-yahoo-open ()
522 (goto-char (point-min))
523 (if (re-search-forward "action=\"\\([^\"]+\\)\"" nil t)
524 (setq webmail-aux (match-string 1))
525 (webmail-error "open@1")))
527 (defun webmail-yahoo-login ()
528 (goto-char (point-min))
529 (if (re-search-forward "http://[a-zA-Z][0-9]\\.mail\\.yahoo\\.com/" nil t)
530 (setq webmail-aux (match-string 0))
531 (webmail-error "login@1"))
532 (if (re-search-forward "YY=[0-9]+" nil t)
533 (setq webmail-aux (concat webmail-aux "ym/us/ShowFolder?"
535 (webmail-error "login@2")))
537 (defun webmail-yahoo-list ()
538 (let (url (newp t) (tofetch 0))
539 (goto-char (point-min))
540 (when (re-search-forward
541 "showing [0-9]+-\\([0-9]+\\) of \\([0-9]+\\)" nil t)
542 ;;(setq listed (match-string 1))
543 (message "Found %s mail(s)" (match-string 2)))
544 (if (string-match "http://[^/]+" webmail-aux)
545 (setq webmail-aux (match-string 0 webmail-aux))
546 (webmail-error "list@1"))
547 (goto-char (point-min))
548 (while (re-search-forward
549 "bgcolor=\"#eeeeee\"\\|href=\"\\(/ym/us/ShowLetter\\?MsgId=\\([^&]+\\)&[^\"]*\\)\""
551 (if (setq url (match-string 1))
553 (when (or newp (not webmail-newmail-only))
554 (push (cons (match-string 2) (concat webmail-aux url "&toc=1"))
556 (setq tofetch (1+ tofetch)))
559 (setq webmail-articles (nreverse webmail-articles))
560 (message "Fetching %d mail(s)" tofetch)))
562 (defun webmail-yahoo-article (file id)
565 (goto-char (point-min))
566 (if (not (search-forward "value=\"Done\"" nil t))
567 (webmail-error "article@1"))
568 (if (not (search-forward "<table" nil t))
569 (webmail-error "article@2"))
570 (delete-region (point-min) (match-beginning 0))
571 (if (not (search-forward "</table>" nil t))
572 (webmail-error "article@3"))
573 (narrow-to-region (point-min) (match-end 0))
574 (while (search-forward "<a href=" nil t)
575 (setq p (match-beginning 0))
576 (search-forward "</a>" nil t)
577 (delete-region p (match-end 0)))
578 (nnweb-remove-markup)
579 (nnweb-decode-entities)
580 (goto-char (point-min))
582 (goto-char (point-max))
586 (while (re-search-forward "[^\"]*/ShowLetter/[^\?]+\?[^\"]*" nil t)
587 (setq attachment (match-string 0))
588 (let (bufname ct ctl cd description)
589 (if (not (search-forward "<table" nil t))
590 (webmail-error "article@4"))
591 (delete-region p (match-beginning 0))
592 (if (not (search-forward "</table>" nil t))
593 (webmail-error "article@5"))
594 (narrow-to-region p (match-end 0))
595 (nnweb-remove-markup)
596 (nnweb-decode-entities)
597 (goto-char (point-min))
599 (setq ct (mail-fetch-field "content-type")
600 ctl (ignore-errors (mail-header-parse-content-type ct))
601 ;;cte (mail-fetch-field "content-transfer-encoding")
602 cd (mail-fetch-field "content-disposition")
603 description (mail-fetch-field "content-description")
604 id (mail-fetch-field "content-id"))
605 (delete-region (point-min) (point-max))
608 (set-buffer (generate-new-buffer " *webmail-att*"))
609 (nnweb-insert (concat webmail-aux attachment))
610 (push (current-buffer) webmail-buffer-list)
611 (setq bufname (buffer-name)))
613 (if (and ctl (not (equal (car ctl) "text/")))
614 (insert " type=\"" (car ctl) "\""))
615 (insert " buffer=\"" bufname "\"")
617 (insert " disposition=\"" cd "\""))
619 (insert " description=\"" description "\""))
620 (insert "><#/part>\n")
622 (delete-region p (point-max))
623 (goto-char (point-min))
624 ;; Some blank line to seperate mails.
625 (insert "\n\nFrom nobody " (current-time-string) "\n")
627 (insert (format "Message-ID: <%s@yahoo.com>\n" id)))
628 (unless (looking-at "$")
629 (if (search-forward "\n\n" nil t)
631 (webmail-error "article@2")))
632 (narrow-to-region (point) (point-max))
633 (insert "MIME-Version: 1.0\n"
636 (delete-region (point-min) (point-max))))
637 (goto-char (point-min))
639 (let (case-fold-search)
640 (while (re-search-forward "^From " nil t)
643 (mm-append-to-file (point-min) (point-max) file)))
647 (defun webmail-netaddress-open ()
648 (goto-char (point-min))
649 (if (re-search-forward "action=\"\\([^\"]+\\)\"" nil t)
650 (setq webmail-aux (concat (car webmail-open-url) (match-string 1)))
651 (webmail-error "open@1")))
653 (defun webmail-netaddress-login ()
654 (webmail-refresh-redirect)
655 (goto-char (point-min))
656 (if (re-search-forward "tpl/[^/]+/\\([^/]+\\)" nil t)
657 (setq webmail-session (match-string 1))
658 (webmail-error "login@1")))
660 (defun webmail-netaddress-list ()
662 (goto-char (point-min))
663 (when (re-search-forward
664 "(\\([0-9]+\\) unread, \\([0-9]+\\) total)" nil t)
665 (message "Found %s mail(s), %s unread"
666 (match-string 2) (match-string 1)))
667 (goto-char (point-min))
668 (while (re-search-forward
669 "MR\\[i\\]\\.R='\\([^']*\\)'\\|MR\\[i\\]\\.Q='\\([^']+\\)'" nil t)
670 (if (setq id (match-string 2))
673 (format "%s/tpl/Message/%s/Read?Q=%s&FolderID=-4&SortUseCase=True&Sort=Date&Headers=True"
674 (car webmail-open-url)
675 webmail-session id)))
676 (if (or (not webmail-newmail-only)
677 (equal (match-string 1) "True"))
678 (push item webmail-articles))))
679 (setq webmail-articles (nreverse webmail-articles))))
681 (defun webmail-netaddress-single-part ()
682 (goto-char (point-min))
684 ((looking-at "[\t\040\r\n]*<font face=[^>]+>[\t\040\r\n]*")
687 (while (re-search-forward "[\t\040\r\n]+" nil t)
689 (goto-char (point-min))
690 (while (re-search-forward "<br>" nil t)
691 (replace-match "\n"))
692 (nnweb-remove-markup)
693 (nnweb-decode-entities)
696 (insert "<#part type=\"text/html\" disposition=inline>")
697 (goto-char (point-max))
701 (defun webmail-netaddress-article (file id)
702 (let (p p1 attachment count mime type)
704 (webmail-encode-8bit)
705 (goto-char (point-min))
706 (if (not (search-forward "Trash" nil t))
707 (webmail-error "article@1"))
708 (if (not (search-forward "<form>" nil t))
709 (webmail-error "article@2"))
710 (delete-region (point-min) (match-beginning 0))
711 (if (not (search-forward "</form>" nil t))
712 (webmail-error "article@3"))
713 (narrow-to-region (point-min) (match-end 0))
714 (goto-char (point-min))
715 (while (re-search-forward "[\040\t\r\n]+" nil t)
717 (goto-char (point-min))
718 (while (search-forward "<b>" nil t)
719 (replace-match "\n"))
720 (nnweb-remove-markup)
721 (nnweb-decode-entities)
722 (goto-char (point-min))
724 (goto-char (point-min))
725 (while (re-search-forward "^\040+\\|\040+$" nil t)
727 (goto-char (point-min))
728 (while (re-search-forward "\040+" nil t)
730 (goto-char (point-max))
734 (unless (search-forward "<!-- Data -->" nil t)
735 (webmail-error "article@4"))
737 (delete-region p (point))
738 (goto-char (point-max))
739 (unless (re-search-backward
740 "[\040\t]*<br>[\040\t\r\n]*<br>[\040\t\r\n]*<form" p t)
741 (webmail-error "article@5"))
742 (delete-region (point) (point-max))
744 (while (search-forward
745 "<TABLE border=\"0\" WIDTH=\"98%\" cellpadding=0 cellspacing=0>"
748 (unless (search-forward "</TABLE>" nil t)
749 (webmail-error "article@6"))
751 (if (search-backward "<IMG " p t)
753 (unless (re-search-forward "HREF=\"\\(/tpl/Attachment/[^/]+/\\([^/]+/[^\?]+\\)[^\"]+\\)\"" p1 t)
754 (webmail-error "article@7"))
755 (setq attachment (match-string 1))
756 (setq type (match-string 2))
757 (unless (search-forward "</TABLE>" nil t)
758 (webmail-error "article@8"))
759 (delete-region p (point))
760 (let (bufname);; Attachment
762 (set-buffer (generate-new-buffer " *webmail-att*"))
763 (nnweb-insert (concat (car webmail-open-url) attachment))
764 (push (current-buffer) webmail-buffer-list)
765 (setq bufname (buffer-name)))
766 (insert "<#part type=" type)
767 (insert " buffer=\"" bufname "\"")
768 (insert " disposition=\"inline\"")
769 (insert "><#/part>\n")
775 "<TABLE border=\"0\" WIDTH=\"98%\" cellpadding=0 cellspacing=0>"
779 (webmail-netaddress-single-part)
780 (goto-char (point-max))
784 (narrow-to-region p (point-max))
785 (setq mime (webmail-netaddress-single-part))
787 (goto-char (point-min))
788 ;; Some blank line to seperate mails.
789 (insert "\n\nFrom nobody " (current-time-string) "\n")
791 (insert (format "Message-ID: <%s@usa.net>\n" id)))
792 (unless (looking-at "$")
793 (if (search-forward "\n\n" nil t)
795 (webmail-error "article@2")))
797 (narrow-to-region (point-min) (point))
798 (goto-char (point-min))
800 (if (looking-at "MIME-Version\\|Content-Type")
801 (delete-region (point)
804 (if (re-search-forward "^[^ \t]" nil t)
805 (goto-char (match-beginning 0))
808 (goto-char (point-max))
810 (narrow-to-region (point) (point-max))
811 (insert "MIME-Version: 1.0\n"
814 (delete-region (point-min) (point-max))))
815 (goto-char (point-min))
817 (let (case-fold-search)
818 (while (re-search-forward "^From " nil t)
821 (mm-append-to-file (point-min) (point-max) file)))
825 (defun webmail-my-deja-open ()
826 (webmail-refresh-redirect)
827 (goto-char (point-min))
828 (if (re-search-forward "action=\"\\([^\"]+login_confirm\\.xp[^\"]*\\)\""
830 (setq webmail-aux (match-string 1))
831 (webmail-error "open@1")))
833 (defun webmail-my-deja-list ()
835 (goto-char (point-min))
836 (when (re-search-forward
837 "(\\([0-9]+\\) message(s), \\([0-9]+\\) new, \\([0-9]+\\) k )"
839 (message "Found %s mail(s), %s unread, total size %s K"
840 (match-string 1) (match-string 2) (match-string 3)))
841 (goto-char (point-min))
842 (while (re-search-forward
843 "• \\|\\(http:[^\"]+\\)/display_seemesg\\.femail\\?docid=\\([^&\"]+\\)"
845 (if (setq id (match-string 2))
846 (when (or newp (not webmail-newmail-only))
848 (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"
849 (match-string 1) id))
851 (setq webmail-aux (match-string 1))
854 (setq webmail-articles (nreverse webmail-articles))))
856 (defun webmail-my-deja-article (file id)
858 (goto-char (point-min))
859 (unless (re-search-forward "\\(http:[^\"]+/attachment/entire_message.txt[^\"]+\\)" nil t)
860 (webmail-error "article@1"))
861 (setq url (match-string 1))
863 (mm-with-unibyte-current-buffer
865 (goto-char (point-min))
866 (while (search-forward "\r\n" nil t)
867 (replace-match "\n"))
868 (goto-char (point-min))
869 (insert "\n\nFrom nobody " (current-time-string) "\n")
870 (mm-append-to-file (point-min) (point-max) file)))
874 ;;; webmail.el ends here