1 ;;; webmail.el --- interface of web mail
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
6 ;; Author: Shenghuo Zhu <zsh@cs.rochester.edu>
7 ;; Keywords: hotmail netaddress
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 by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
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))
56 (require 'url-cookie)))
57 ;; Report failure to find w3 at load time if appropriate.
60 (require 'url-cookie)))
64 (defvar webmail-type-definition
66 ;; Hotmail hate other HTTP user agents and use one line cookie
67 (paranoid agent cookie post)
68 (address . "www.hotmail.com")
69 (open-url "http://www.hotmail.com/")
70 (open-snarf . webmail-hotmail-open)
71 ;; W3 hate redirect POST
73 "http://%s/cgi-bin/dologin?login=%s&passwd=%s&enter=Sign+in&sec=no&curmbox=ACTIVE&_lang=&js=yes&id=2&tw=-10000&beta="
74 webmail-aux user password)
75 ;;(login-snarf . webmail-hotmail-login)
76 ;;(list-url "%s" webmail-aux)
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 agent 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=&.src=ym&.last=&promo=&.intl=&.bypass=&.partner=&.chkP=Y&.done=&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/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&Domain=usa.net&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"
118 webmail-session id))))
120 (defvar webmail-variables
121 '(address article-snarf article-url list-snarf list-url
122 login-url login-snarf open-url open-snarf site articles
123 post-process paranoid trash-url))
125 (defconst webmail-version "webmail 1.0")
127 (defvar webmail-newmail-only nil
128 "Only fetch new mails.")
130 (defvar webmail-move-to-trash-can t
131 "Move mail to trash can after fetch it.")
133 ;;; Internal variables
135 (defvar webmail-address nil)
136 (defvar webmail-paranoid nil)
137 (defvar webmail-aux nil)
138 (defvar webmail-session nil)
139 (defvar webmail-article-snarf nil)
140 (defvar webmail-article-url nil)
141 (defvar webmail-list-snarf nil)
142 (defvar webmail-list-url nil)
143 (defvar webmail-login-url nil)
144 (defvar webmail-login-snarf nil)
145 (defvar webmail-open-snarf nil)
146 (defvar webmail-open-url nil)
147 (defvar webmail-trash-url nil)
148 (defvar webmail-articles nil)
149 (defvar webmail-post-process nil)
151 (defvar webmail-buffer nil)
152 (defvar webmail-buffer-list nil)
154 (defvar webmail-type nil)
156 (defvar webmail-error-function nil)
158 (defvar webmail-debug-file "~/.emacs-webmail-debug")
160 ;;; Interface functions
162 (defun webmail-debug (str)
164 (insert "\n---------------- A bug at " str " ------------------\n")
165 (dolist (sym '(webmail-type user))
167 (gnus-pp `(setq ,sym ',(eval sym)))))
168 (insert "---------------- webmail buffer ------------------\n\n")
169 (insert-buffer-substring webmail-buffer)
170 (insert "\n---------------- end of buffer ------------------\n\n")
171 (append-to-file (point-min) (point-max) webmail-debug-file)))
173 (defun webmail-error (str)
174 (if webmail-error-function
175 (funcall webmail-error-function str))
176 (message "%s HTML has changed or your w3 package is too old.(%s)"
178 (error "%s HTML has changed or your w3 package is too old.(%s)"
181 (defun webmail-setdefault (type)
182 (let ((type-def (cdr (assq type webmail-type-definition)))
183 (vars webmail-variables)
185 (setq webmail-type type)
187 (if (setq pair (assq var type-def))
188 (set (intern (concat "webmail-" (symbol-name var))) (cdr pair))
189 (set (intern (concat "webmail-" (symbol-name var))) nil)))))
191 (defun webmail-eval (expr)
194 (cons (webmail-eval (car expr)) (webmail-eval (cdr expr))))
200 (defun webmail-url (xurl)
201 (mm-with-unibyte-current-buffer
203 ((eq (car xurl) 'content)
205 (mm-url-fetch-simple (if (stringp (car xurl))
207 (apply 'format (webmail-eval (car xurl))))
208 (apply 'format (webmail-eval (cdr xurl)))))
209 ((eq (car xurl) 'post)
211 (mm-url-fetch-form (car xurl) (webmail-eval (cdr xurl))))
213 (mm-url-insert (apply 'format (webmail-eval xurl)))))))
215 (defun webmail-init ()
216 "Initialize buffers and such."
217 (if (gnus-buffer-live-p webmail-buffer)
218 (set-buffer webmail-buffer)
220 (nnheader-set-temp-buffer " *webmail*"))
221 (mm-disable-multibyte)))
223 (defvar url-package-name)
224 (defvar url-package-version)
225 (defvar url-cookie-multiple-line)
226 (defvar url-confirmation-func)
228 ;; Hack W3 POST redirect. See `url-parse-mime-headers'.
230 ;; Netscape uses "GET" as redirect method when orignal method is POST
231 ;; and status is 302, .i.e no security risks by default without
234 ;; Some web servers (at least Apache used by yahoo) return status 302
235 ;; instead of 303, though they mean 303.
237 (defun webmail-url-confirmation-func (prompt)
239 ((equal prompt (concat "Honor redirection with non-GET method "
240 "(possible security risks)? "))
242 ((equal prompt "Continue (with method of GET)? ")
246 (defun webmail-refresh-redirect ()
247 "Redirect refresh url in META."
248 (goto-char (point-min))
249 (while (re-search-forward
250 "<meta[ \t\r\n]*http-equiv=\"Refresh\"[^>]*URL=\\([^\"]+\\)\""
252 (let ((url (match-string 1)))
254 (mm-with-unibyte-current-buffer
255 (mm-url-insert url)))
256 (goto-char (point-min))))
258 (defun webmail-fetch (file subtype user password)
260 (webmail-setdefault subtype)
261 (let ((url-package-name (if (memq 'agent webmail-paranoid)
264 (url-package-version (if (memq 'agent webmail-paranoid)
266 url-package-version))
267 (url-cookie-multiple-line (if (memq 'cookie webmail-paranoid)
269 url-cookie-multiple-line))
270 (url-confirmation-func (if (memq 'post webmail-paranoid)
271 'webmail-url-confirmation-func
272 url-confirmation-func))
273 (url-http-silence-on-insecure-redirection t)
274 url-cookie-storage url-cookie-secure-storage
275 url-cookie-confirmation
278 (setq webmail-articles nil)
279 (when webmail-open-url
281 (webmail-url webmail-open-url))
282 (if webmail-open-snarf (funcall webmail-open-snarf))
283 (when webmail-login-url
285 (webmail-url webmail-login-url))
286 (if webmail-login-snarf
287 (funcall webmail-login-snarf))
288 (when webmail-list-url
290 (webmail-url webmail-list-url))
291 (if webmail-list-snarf
292 (funcall webmail-list-snarf))
293 (while (setq item (pop webmail-articles))
294 (message "Fetching mail #%d..." (setq n (1+ n)))
296 (mm-with-unibyte-current-buffer
297 (mm-url-insert (cdr item)))
299 (if webmail-article-snarf
300 (funcall webmail-article-snarf file id))
301 (when (and webmail-trash-url webmail-move-to-trash-can)
302 (message "Move mail #%d to trash can..." n)
305 (webmail-url webmail-trash-url)
307 (while (setq buf (pop webmail-buffer-list))
311 (while (setq buf (pop webmail-buffer-list))
314 (if webmail-post-process
315 (funcall webmail-post-process))))
317 (defun webmail-encode-8bit ()
318 (goto-char (point-min))
319 (skip-chars-forward "^\200-\377")
321 (insert (format "&%d;" (mm-char-int (char-after))))
323 (skip-chars-forward "^\200-\377")))
327 (defun webmail-hotmail-open ()
328 (goto-char (point-min))
329 (if (re-search-forward
330 "action=\"https?://\\([^/]+\\)/cgi-bin/dologin" nil t)
331 (setq webmail-aux (match-string 1))
332 (webmail-error "open@1")))
334 (defun webmail-hotmail-login ()
336 (goto-char (point-min))
337 (if (re-search-forward
338 "https?://\\([^/]+hotmail\\.msn\\.com\\)/cgi-bin/" nil t)
339 (setq site (match-string 1))
340 (webmail-error "login@1"))
341 (goto-char (point-min))
342 (if (re-search-forward
343 "\\(/cgi-bin/HoTMaiL\\?[^\"]*a=b[^\"]*\\)" nil t)
344 (setq webmail-aux (concat "http://" site (match-string 1)))
345 (webmail-error "login@2"))))
347 (defun webmail-hotmail-list ()
348 (goto-char (point-min))
349 (skip-chars-forward " \t\n\r")
350 (let (site url newp (total "0"))
353 (if (re-search-forward "\\([0-9]+\\) *<b>(\\([0-9]+\\) new)" nil t)
354 (message "Found %s (%s new)" (setq total (match-string 1))
356 (if (re-search-forward "\\([0-9]+\\) new" nil t)
357 (message "Found %s new" (setq total (match-string 1)))
358 (webmail-error "list@0"))))
359 (unless (equal total "0")
360 (goto-char (point-min))
361 (if (re-search-forward
362 "https?://\\([^/]+hotmail\\.msn\\.com\\)/cgi-bin/" nil t)
363 (setq site (match-string 1))
364 (webmail-error "list@1"))
365 (goto-char (point-min))
366 (if (re-search-forward "disk=\\([^&]*\\)&" nil t)
368 (concat "http://" site "/cgi-bin/HoTMaiL?disk="
370 (webmail-error "list@2"))
371 (goto-char (point-max))
372 (while (re-search-backward
373 "newmail\\.gif\\|href=\"\\(/cgi-bin/getmsg\\?[^\"]+\\)\""
375 (if (setq url (match-string 1))
377 (if (or newp (not webmail-newmail-only))
379 (if (string-match "msg=\\([^&]+\\)" url)
380 (setq id (match-string 1 url)))
381 (push (cons id (concat "http://" site url "&raw=0"))
386 ;; Thank victor@idaccr.org (Victor S. Miller) for raw=0
388 (defun webmail-hotmail-article (file id)
389 (goto-char (point-min))
390 (skip-chars-forward " \t\n\r")
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 (mm-url-remove-markup)
400 (mm-url-decode-entities-nbsp)
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")
409 (insert "X-Gnus-Webmail: " (symbol-value 'user)
410 "@" (symbol-name webmail-type) "\n")
411 (mm-append-to-file (point-min) (point-max) file)))
413 (defun webmail-hotmail-article-old (file id)
414 (let (p attachment count mime hotmail-direct)
416 (webmail-encode-8bit)
417 (goto-char (point-min))
418 (if (not (search-forward "<DIV>" nil t))
419 (if (not (search-forward "Reply All" nil t))
420 (webmail-error "article@1")
421 (setq hotmail-direct t))
422 (goto-char (match-beginning 0)))
423 (narrow-to-region (point-min) (point))
424 (if (not (search-backward "<table" nil t 2))
425 (webmail-error "article@1.1"))
426 (delete-region (point-min) (match-beginning 0))
427 (while (search-forward "<a href=" nil t)
428 (setq p (match-beginning 0))
429 (search-forward "</a>" nil t)
430 (delete-region p (match-end 0)))
431 (mm-url-remove-markup)
432 (mm-url-decode-entities-nbsp)
433 (goto-char (point-min))
435 (goto-char (point-min))
436 (when (search-forward "\n\n" nil t)
438 (delete-region (point) (point-max)))
439 (goto-char (point-max))
443 (while (re-search-forward
444 "<tt>\\|<div>\\|\\(http://[^/]+/cgi-bin/getmsg/\\([^\?]+\\)\?[^\"]*\\)\""
446 (if (setq attachment (match-string 1))
447 (let ((filename (match-string 2))
448 bufname);; Attachment
449 (delete-region p (match-end 0))
451 (set-buffer (generate-new-buffer " *webmail-att*"))
452 (mm-url-insert attachment)
453 (push (current-buffer) webmail-buffer-list)
454 (setq bufname (buffer-name)))
456 (insert "<#part type="
458 (string-match "\\.[^\\.]+$" filename)
459 (mailcap-extension-to-mime
460 (match-string 0 filename)))
461 "application/octet-stream"))
462 (insert " buffer=\"" bufname "\"")
463 (insert " filename=\"" filename "\"")
464 (insert " disposition=\"inline\"")
465 (insert "><#/part>\n")
467 (delete-region p (match-end 0))
469 (if (not (search-forward "</tt>" nil t))
470 (webmail-error "article@1.2")
471 (delete-region (match-beginning 0) (match-end 0)))
473 (while (and (> count 0)
474 (re-search-forward "</div>\\|\\(<div>\\)" nil t))
476 (setq count (1+ count))
477 (if (= (setq count (1- count)) 0)
478 (delete-region (match-beginning 0)
480 (narrow-to-region p (point))
481 (goto-char (point-min))
483 ((looking-at "<pre>")
484 (goto-char (match-end 0))
485 (if (looking-at "$") (forward-char))
486 (delete-region (point-min) (point))
487 (mm-url-remove-markup)
488 (mm-url-decode-entities-nbsp)
492 (insert "<#part type=\"text/html\" disposition=inline>")
493 (goto-char (point-max))
494 (insert "<#/part>")))
495 (goto-char (point-max))
498 (delete-region p (point-max))
499 (goto-char (point-min))
500 ;; Some blank line to separate mails.
501 (insert "\n\nFrom nobody " (current-time-string) "\n")
502 (insert "X-Gnus-Webmail: " (symbol-value 'user)
503 "@" (symbol-name webmail-type) "\n")
505 (insert (format "X-Message-ID: <%s@hotmail.com>\n" id)))
506 (unless (looking-at "$")
507 (if (search-forward "\n\n" nil t)
509 (webmail-error "article@2")))
510 (narrow-to-region (point) (point-max))
512 (insert "MIME-Version: 1.0\n"
515 (delete-region (point-min) (point-max)))))
516 (goto-char (point-min))
518 (let (case-fold-search)
519 (while (re-search-forward "^From " nil t)
522 (mm-append-to-file (point-min) (point-max) file)))
526 (defun webmail-yahoo-open ()
527 (goto-char (point-min))
528 (if (re-search-forward "action=\"\\([^\"]+\\)\"" nil t)
529 (setq webmail-aux (match-string 1))
530 (webmail-error "open@1")))
532 (defun webmail-yahoo-login ()
533 (goto-char (point-min))
534 (if (re-search-forward "http://[^/]+[0-9]\\.mail\\.yahoo\\.com/" nil t)
535 (setq webmail-aux (match-string 0))
536 (webmail-error "login@1"))
537 (if (re-search-forward "YY=[0-9]+" nil t)
538 (setq webmail-aux (concat webmail-aux "ym/ShowFolder?"
540 (webmail-error "login@2")))
542 (defun webmail-yahoo-list ()
543 (let (url (newp t) (tofetch 0))
544 (goto-char (point-min))
545 (when (re-search-forward
546 "showing [0-9]+-\\([0-9]+\\) of \\([0-9]+\\)" nil t)
547 ;;(setq listed (match-string 1))
548 (message "Found %s mail(s)" (match-string 2)))
549 (if (string-match "http://[^/]+" webmail-aux)
550 (setq webmail-aux (match-string 0 webmail-aux))
551 (webmail-error "list@1"))
552 (goto-char (point-min))
553 (while (re-search-forward
554 "bgcolor=\"#eeeeee\"\\|href=\"\\(/ym/ShowLetter\\?MsgId=\\([^&]+\\)&[^\"]*\\)\""
556 (if (setq url (match-string 1))
558 (when (or newp (not webmail-newmail-only))
559 (push (cons (match-string 2) (concat webmail-aux url "&toc=1"))
561 (setq tofetch (1+ tofetch)))
564 (setq webmail-articles (nreverse webmail-articles))
565 (message "Fetching %d mail(s)" tofetch)))
567 (defun webmail-yahoo-article (file id)
570 (goto-char (point-min))
571 (if (not (search-forward "value=\"Done\"" nil t))
572 (webmail-error "article@1"))
573 (if (not (search-forward "<table" nil t))
574 (webmail-error "article@2"))
575 (delete-region (point-min) (match-beginning 0))
576 (if (not (search-forward "</table>" nil t))
577 (webmail-error "article@3"))
578 (narrow-to-region (point-min) (match-end 0))
579 (while (search-forward "<a href=" nil t)
580 (setq p (match-beginning 0))
581 (search-forward "</a>" nil t)
582 (delete-region p (match-end 0)))
583 (mm-url-remove-markup)
584 (mm-url-decode-entities-nbsp)
585 (goto-char (point-min))
587 (goto-char (point-max))
591 (while (re-search-forward "[^\"]*/ShowLetter/[^\?]+\?[^\"]*" nil t)
592 (setq attachment (match-string 0))
593 (let (bufname ct ctl cd description)
594 (if (not (search-forward "<table" nil t))
595 (webmail-error "article@4"))
596 (delete-region p (match-beginning 0))
597 (if (not (search-forward "</table>" nil t))
598 (webmail-error "article@5"))
599 (narrow-to-region p (match-end 0))
600 (mm-url-remove-markup)
601 (mm-url-decode-entities-nbsp)
602 (goto-char (point-min))
604 (setq ct (mail-fetch-field "content-type")
605 ctl (and ct (mail-header-parse-content-type ct))
606 ;;cte (mail-fetch-field "content-transfer-encoding")
607 cd (mail-fetch-field "content-disposition")
608 description (mail-fetch-field "content-description")
609 id (mail-fetch-field "content-id"))
610 (delete-region (point-min) (point-max))
613 (set-buffer (generate-new-buffer " *webmail-att*"))
614 (mm-url-insert (concat webmail-aux attachment))
615 (push (current-buffer) webmail-buffer-list)
616 (setq bufname (buffer-name)))
618 (if (and ctl (not (equal (car ctl) "text/")))
619 (insert " type=\"" (car ctl) "\""))
620 (insert " buffer=\"" bufname "\"")
622 (insert " disposition=\"" cd "\""))
624 (insert " description=\"" description "\""))
625 (insert "><#/part>\n")
627 (delete-region p (point-max))
628 (goto-char (point-min))
629 ;; Some blank line to separate mails.
630 (insert "\n\nFrom nobody " (current-time-string) "\n")
631 (insert "X-Gnus-Webmail: " (symbol-value 'user)
632 "@" (symbol-name webmail-type) "\n")
634 (insert (format "X-Message-ID: <%s@yahoo.com>\n" id)))
635 (unless (looking-at "$")
636 (if (search-forward "\n\n" nil t)
638 (webmail-error "article@2")))
639 (narrow-to-region (point) (point-max))
640 (insert "MIME-Version: 1.0\n"
643 (delete-region (point-min) (point-max))))
644 (goto-char (point-min))
646 (let (case-fold-search)
647 (while (re-search-forward "^From " nil t)
650 (mm-append-to-file (point-min) (point-max) file)))
654 (defun webmail-netaddress-open ()
655 (goto-char (point-min))
656 (if (re-search-forward "action=\"\\([^\"]+\\)\"" nil t)
657 (setq webmail-aux (concat (car webmail-open-url) (match-string 1)))
658 (webmail-error "open@1")))
660 (defun webmail-netaddress-login ()
661 (webmail-refresh-redirect)
662 (goto-char (point-min))
663 (if (re-search-forward "tpl/[^/]+/\\([^/]+\\)" nil t)
664 (setq webmail-session (match-string 1))
665 (webmail-error "login@1")))
667 (defun webmail-netaddress-list ()
668 (webmail-refresh-redirect)
670 (goto-char (point-min))
671 (when (re-search-forward
672 "(\\([0-9]+\\) unread, \\([0-9]+\\) total)" nil t)
673 (message "Found %s mail(s), %s unread"
674 (match-string 2) (match-string 1)))
675 (goto-char (point-min))
676 (while (re-search-forward
677 "MR\\[i\\]\\.R='\\([^']*\\)'\\|MR\\[i\\]\\.Q='\\([^']+\\)'" nil t)
678 (if (setq id (match-string 2))
681 (format "%s/tpl/Message/%s/Read?Q=%s&FolderID=-4&SortUseCase=True&Sort=Date&Headers=True"
682 (car webmail-article-url)
683 webmail-session id)))
684 (if (or (not webmail-newmail-only)
685 (equal (match-string 1) "True"))
686 (push item webmail-articles))))
687 (setq webmail-articles (nreverse webmail-articles))))
689 (defun webmail-netaddress-single-part ()
690 (goto-char (point-min))
692 ((looking-at "[\t\040\r\n]*<font face=[^>]+>[\t\040\r\n]*")
695 (while (re-search-forward "[\t\040\r\n]+" nil t)
697 (goto-char (point-min))
698 (while (re-search-forward "<br>" nil t)
699 (replace-match "\n"))
700 (mm-url-remove-markup)
701 (mm-url-decode-entities-nbsp)
704 (insert "<#part type=\"text/html\" disposition=inline>")
705 (goto-char (point-max))
709 (defun webmail-netaddress-article (file id)
710 (webmail-refresh-redirect)
711 (let (p p1 attachment count mime type)
713 (webmail-encode-8bit)
714 (goto-char (point-min))
715 (if (not (search-forward "Trash" nil t))
716 (webmail-error "article@1"))
717 (if (not (search-forward "<form>" nil t))
718 (webmail-error "article@2"))
719 (delete-region (point-min) (match-beginning 0))
720 (if (not (search-forward "</form>" nil t))
721 (webmail-error "article@3"))
722 (narrow-to-region (point-min) (match-end 0))
723 (goto-char (point-min))
724 (while (re-search-forward "[\040\t\r\n]+" nil t)
726 (goto-char (point-min))
727 (while (search-forward "<b>" nil t)
728 (replace-match "\n"))
729 (mm-url-remove-markup)
730 (mm-url-decode-entities-nbsp)
731 (goto-char (point-min))
733 (goto-char (point-min))
734 (while (re-search-forward "^\040+\\|\040+$" nil t)
736 (goto-char (point-min))
737 (while (re-search-forward "\040+" nil t)
739 (goto-char (point-max))
743 (unless (search-forward "<!-- Data -->" nil t)
744 (webmail-error "article@4"))
746 (delete-region p (point))
747 (goto-char (point-max))
748 (unless (re-search-backward
749 "[\040\t]*<br>[\040\t\r\n]*<br>[\040\t\r\n]*<form" p t)
750 (webmail-error "article@5"))
751 (delete-region (point) (point-max))
753 (while (search-forward
754 "<TABLE border=\"0\" WIDTH=\"98%\" cellpadding=0 cellspacing=0>"
757 (unless (search-forward "</TABLE>" nil t)
758 (webmail-error "article@6"))
760 (if (search-backward "<IMG " p t)
762 (unless (re-search-forward "HREF=\"\\(/tpl/Attachment/[^/]+/\\([^/]+/[^\?]+\\)[^\"]+\\)\"" p1 t)
763 (webmail-error "article@7"))
764 (setq attachment (match-string 1))
765 (setq type (match-string 2))
766 (unless (search-forward "</TABLE>" nil t)
767 (webmail-error "article@8"))
768 (delete-region p (point))
769 (let (bufname);; Attachment
771 (set-buffer (generate-new-buffer " *webmail-att*"))
772 (mm-url-insert (concat (car webmail-open-url) attachment))
773 (push (current-buffer) webmail-buffer-list)
774 (setq bufname (buffer-name)))
775 (insert "<#part type=" type)
776 (insert " buffer=\"" bufname "\"")
777 (insert " disposition=\"inline\"")
778 (insert "><#/part>\n")
784 "<TABLE border=\"0\" WIDTH=\"98%\" cellpadding=0 cellspacing=0>"
788 (webmail-netaddress-single-part)
789 (goto-char (point-max))
793 (narrow-to-region p (point-max))
794 (setq mime (webmail-netaddress-single-part))
796 (goto-char (point-min))
797 ;; Some blank line to separate mails.
798 (insert "\n\nFrom nobody " (current-time-string) "\n")
799 (insert "X-Gnus-Webmail: " (symbol-value 'user)
800 "@" (symbol-name webmail-type) "\n")
802 (insert (format "X-Message-ID: <%s@%s>\n" id webmail-address)))
803 (unless (looking-at "$")
804 (if (search-forward "\n\n" nil t)
806 (webmail-error "article@2")))
808 (narrow-to-region (point-min) (point))
809 (goto-char (point-min))
811 (if (looking-at "MIME-Version\\|Content-Type")
812 (delete-region (point)
815 (if (re-search-forward "^[^ \t]" nil t)
816 (goto-char (match-beginning 0))
819 (goto-char (point-max))
821 (narrow-to-region (point) (point-max))
822 (insert "MIME-Version: 1.0\n"
825 (delete-region (point-min) (point-max))))
826 (goto-char (point-min))
828 (let (case-fold-search)
829 (while (re-search-forward "^From " nil t)
832 (mm-append-to-file (point-min) (point-max) file)))
836 ;;; webmail.el ends here