+;;; my-deja
+
+(defun webmail-my-deja-open ()
+ (webmail-refresh-redirect)
+ (goto-char (point-min))
+ (if (re-search-forward "action=\"\\([^\"]+maillogin\\.py[^\"]*\\)\""
+ nil t)
+ (setq webmail-aux (match-string 1))
+ (webmail-error "open@1")))
+
+(defun webmail-my-deja-list ()
+ (let (item id newp base)
+ (goto-char (point-min))
+ (when (re-search-forward "href=\"\\(\\([^\"]*\\)/mailnf\\.[^\"]*\\)\""
+ nil t)
+ (let ((url (match-string 1)))
+ (setq base (match-string 2))
+ (erase-buffer)
+ (mm-url-insert url)))
+ (goto-char (point-min))
+ (when (re-search-forward
+ "(\\([0-9]+\\) Message.?-[^>]*\\([0-9]+\\) New"
+ nil t)
+ (message "Found %s mail(s), %s unread"
+ (match-string 1) (match-string 2)))
+ (goto-char (point-min))
+ (while (re-search-forward
+ "newmail\\.gif\\|href=\"[^\"]*\\(mailnf\\.[^\"]+act=view[^\"]+mid=\\([^\"&]+\\)[^\"]+\\)\""
+ nil t)
+ (if (setq id (match-string 2))
+ (when (and (or newp (not webmail-newmail-only))
+ (not (assoc id webmail-articles)))
+ (push (cons id (setq webmail-aux
+ (concat base "/" (match-string 1))))
+ webmail-articles)
+ (setq newp nil))
+ (setq newp t)))
+ (setq webmail-articles (nreverse webmail-articles))))
+
+(defun webmail-my-deja-article-part (base)
+ (let (p)
+ (cond
+ ((looking-at "[\t\040\r\n]*<!--[^>]*>")
+ (replace-match ""))
+ ((looking-at "[\t\040\r\n]*</PRE>")
+ (replace-match ""))
+ ((looking-at "[\t\040\r\n]*<PRE>")
+ ;; text/plain
+ (replace-match "")
+ (save-restriction
+ (narrow-to-region (point)
+ (if (re-search-forward "</?PRE>" nil t)
+ (match-beginning 0)
+ (point-max)))
+ (goto-char (point-min))
+ (mm-url-remove-markup)
+ (mm-url-decode-entities-nbsp)
+ (goto-char (point-max))))
+ ((looking-at "[\t\040\r\n]*<TABLE")
+ (save-restriction
+ (narrow-to-region (point)
+ (if (search-forward "</TABLE>" nil t 2)
+ (point)
+ (point-max)))
+ (goto-char (point-min))
+ (let (name type url bufname)
+ (if (and (search-forward "File Name:" nil t)
+ (re-search-forward "<FONT[^>]+>\\([^<]+\\)" nil t))
+ (setq name (match-string 1)))
+ (if (and (search-forward "File Type:" nil t)
+ (re-search-forward "<FONT[^>]+>\\([^<]+\\)" nil t))
+ (setq type (match-string 1)))
+ (unless (re-search-forward "action=\"getattach\\.cgi/\\([^\"]+\\)"
+ nil t)
+ (webmail-error "article@5"))
+ (setq url (concat base "/getattach.cgi/" (match-string 1)
+ "?sm=Download"))
+ (while (re-search-forward
+ "type=hidden name=\"\\([^\"]+\\)\" value=\"\\([^\"]+\\)"
+ nil t)
+ (setq url (concat url "&" (match-string 1) "="
+ (match-string 2))))
+ (delete-region (point-min) (point-max))
+ (save-excursion
+ (set-buffer (generate-new-buffer " *webmail-att*"))
+ (mm-url-insert url)
+ (push (current-buffer) webmail-buffer-list)
+ (setq bufname (buffer-name)))
+ (insert "<#part type=\"" type "\"")
+ (if name (insert " filename=\"" name "\""))
+ (insert " buffer=\"" bufname "\"")
+ (insert " disposition=inline><#/part>"))))
+ (t
+ (insert "<#part type=\"text/html\" disposition=inline>")
+ (goto-char (point-max))
+ (insert "<#/part>")))))
+
+(defun webmail-my-deja-article (file id)
+ (let (base)
+ (goto-char (point-min))
+ (unless (string-match "\\([^\"]+\\)/mail" webmail-aux)
+ (webmail-error "article@0"))
+ (setq base (match-string 1 webmail-aux))
+ (when (re-search-forward
+ "href=\"[^\"]*\\(mailnf\\.[^\"]+act=move[^\"]+mid=\\([^\"&]+\\)[^\"]+\\)\""
+ nil t)
+ (setq webmail-aux (concat base "/" (match-string 1)))
+ (string-match "mid=[^\"&]+" webmail-aux)
+ (setq webmail-aux (replace-match "mid=%s" nil nil webmail-aux)))
+ (unless (search-forward "<HR noshade>" nil t)
+ (webmail-error "article@1"))
+ (delete-region (point-min) (point))
+ (unless (search-forward "<HR noshade>" nil t)
+ (webmail-error "article@2"))
+ (save-restriction
+ (narrow-to-region (point-min) (point))
+ (while (search-forward "\r\n" nil t)
+ (replace-match "\n"))
+ (mm-url-remove-markup)
+ (mm-url-decode-entities-nbsp)
+ (goto-char (point-min))
+ (while (re-search-forward "\n\n+" nil t)
+ (replace-match "\n"))
+ (goto-char (point-max)))
+ (save-restriction
+ (narrow-to-region (point) (point-max))
+ (goto-char (point-max))
+ (unless (search-backward "<HR noshade>" nil t)
+ (webmail-error "article@3"))
+ (unless (search-backward "</TT>" nil t)
+ (webmail-error "article@4"))
+ (delete-region (point) (point-max))
+ (goto-char (point-min))
+ (while (not (eobp))
+ (webmail-my-deja-article-part base))
+ (insert "MIME-Version: 1.0\n"
+ (prog1
+ (mml-generate-mime)
+ (delete-region (point-min) (point-max)))))
+ (goto-char (point-min))
+ (insert "\n\nFrom nobody " (current-time-string) "\n")
+ (insert "X-Gnus-Webmail: " (symbol-value 'user)
+ "@" (symbol-name webmail-type) "\n")
+ (if (eq (char-after) ?\n)
+ (delete-char 1))
+ (mm-append-to-file (point-min) (point-max) file)))
+