(mixi-event-detail-regexp): Fix regexp.
[elisp/mixi.git] / mixi.el
diff --git a/mixi.el b/mixi.el
index 7f4a1d1..8d30a24 100644 (file)
--- a/mixi.el
+++ b/mixi.el
@@ -1,6 +1,6 @@
-;; mixi.el --- API library for accessing to mixi
+;; mixi.el --- API libraries for accessing to mixi -*- coding: euc-jp -*-
 
-;; Copyright (C) 2005,2006 OHASHI Akira
+;; Copyright (C) 2005, 2006, 2007 OHASHI Akira
 
 ;; Author: OHASHI Akira <bg66@koka-in.org>
 ;; Keywords: hypermedia
@@ -24,7 +24,7 @@
 
 ;;; Commentary:
 
-;; API for getting contents:
+;; APIs for getting contents:
 ;;
 ;;  * mixi-get-friends
 ;;  * mixi-get-favorites
 ;;  * mixi-get-new-comments
 ;;  * mixi-get-messages
 ;;  * mixi-get-introductions
+;;  * mixi-get-news
+;;
+;; APIs for posting:
+;;
+;;  * mixi-post-diary
+;;  * mixi-post-topic
+;;  * mixi-post-comment
+;;  * mixi-post-message
 ;; 
 ;; Utilities:
 ;;
-;;  * mixi-remove-markup
+;;  * mixi-remove-markup (half broken)
 
-;; Example:
+;; Examples:
 ;;
 ;; Display newest 3 diaries like a mail format.
 ;;
 ;;       (buffer (get-buffer-create "*temp*"))
 ;;       (format "%Y/%m/%d %H:%M"))
 ;;   (pop-to-buffer buffer)
-;;   (mapc (lambda (diary)
-;;       (let ((subject (mixi-diary-title diary))
-;;             (from (mixi-friend-nick (mixi-diary-owner diary)))
-;;             (date (format-time-string format (mixi-diary-time diary)))
-;;             (body (mixi-remove-markup (mixi-diary-content diary))))
-;;         (insert "From: " from "\n"
-;;                 "Subject: " subject "\n"
-;;                 "Date: " date "\n\n"
-;;                 body "\n\n")))
-;;     (mixi-get-new-diaries range))
+;;   (let ((diaries (mixi-get-new-diaries range)))
+;;     (while diaries
+;;       (let* ((diary (car diaries))
+;;          (subject (mixi-diary-title diary))
+;;          (from (mixi-friend-nick (mixi-diary-owner diary)))
+;;          (date (format-time-string format (mixi-diary-time diary)))
+;;          (body (mixi-remove-markup (mixi-diary-content diary))))
+;;     (insert "From: " from "\n"
+;;             "Subject: " subject "\n"
+;;             "Date: " date "\n\n"
+;;             body "\n\n"))
+;;       (setq diaries (cdr diaries))))
 ;;   (set-buffer-modified-p nil)
 ;;   (setq buffer-read-only t)
 ;;   (goto-char (point-min)))
 ;;       (buffer (get-buffer-create "*temp*"))
 ;;       (format "%Y/%m/%d %H:%M"))
 ;;   (pop-to-buffer buffer)
-;;   (mapc (lambda (diary)
-;;       (let ((subject (mixi-diary-title diary))
-;;             (from (mixi-friend-nick (mixi-diary-owner diary)))
-;;             (date (format-time-string format (mixi-diary-time diary)))
-;;             (body (mixi-remove-markup (mixi-diary-content diary))))
-;;         (insert "From: " from "\n"
-;;                 "Subject: " subject "\n"
-;;                 "Date: " date "\n\n"
-;;                 body "\n\n")
-;;         (mapc (lambda (comment)
-;;                 (let ((from (mixi-friend-nick
-;;                              (mixi-comment-owner comment)))
-;;                       (subject (concat "Re: " subject))
-;;                       (date (format-time-string
-;;                              format (mixi-comment-time comment)))
-;;                       (body (mixi-remove-markup
-;;                              (mixi-comment-content comment))))
-;;                   (insert "From: " from "\n"
-;;                           "Subject: " subject "\n"
-;;                           "Date: " date "\n\n"
-;;                           body "\n\n")))
-;;               (mixi-get-comments diary range))))
-;;     (mixi-get-new-diaries range))
+;;   (let ((diaries (mixi-get-new-diaries range)))
+;;     (while diaries
+;;       (let* ((diary (car diaries))
+;;          (subject (mixi-diary-title diary))
+;;          (from (mixi-friend-nick (mixi-diary-owner diary)))
+;;          (date (format-time-string format (mixi-diary-time diary)))
+;;          (body (mixi-remove-markup (mixi-diary-content diary))))
+;;     (insert "From: " from "\n"
+;;             "Subject: " subject "\n"
+;;             "Date: " date "\n\n"
+;;             body "\n\n")
+;;     (let ((comments (mixi-get-comments diary range)))
+;;       (while comments
+;;         (let* ((comment (car comments))
+;;                (from (mixi-friend-nick (mixi-comment-owner comment)))
+;;                (subject (concat "Re: " subject))
+;;                (date (format-time-string format
+;;                                          (mixi-comment-time comment)))
+;;                (body (mixi-remove-markup (mixi-comment-content comment))))
+;;           (insert "From: " from "\n"
+;;                   "Subject: " subject "\n"
+;;                   "Date: " date "\n\n"
+;;                   body "\n\n"))
+;;         (setq comments (cdr comments)))))
+;;       (setq diaries (cdr diaries))))
 ;;   (set-buffer-modified-p nil)
 ;;   (setq buffer-read-only t)
 ;;   (goto-char (point-min)))
 
 (eval-when-compile (require 'cl))
 
+;; Functions and variables which should be defined in the other module
+;; at run-time.
+(eval-when-compile
+  (defvar w3m-use-cookies)
+  (defvar url-request-method)
+  (defvar url-request-data)
+  (defvar url-request-extra-headers)
+  (defvar url-show-status)
+  (autoload 'w3m-decode-buffer "w3m")
+  (autoload 'w3m-retrieve "w3m")
+  (autoload 'url-retrieve-synchronously "url"))
+
 (defgroup mixi nil
   "API library for accessing to mixi."
   :group 'hypermedia)
   :type 'file
   :group 'mixi)
 
-(defcustom mixi-curl-cookie-file (expand-file-name "~/.mixi-cookies.txt")
+(defcustom mixi-curl-cookie-file (expand-file-name "cookies.txt"
+                                                  mixi-directory)
   "*The location of cookie file created by `curl'."
   :type 'file
   :group 'mixi)
 
-(defcustom mixi-retrieve-function
+(defcustom mixi-backend
   (or (condition-case nil
          (progn
-           (require 'url)
-           (if (fboundp 'url-retrieve-synchronously)
-               'mixi-url-retrieve))
+           (require 'w3m)
+           'w3m)
        (error))
       (condition-case nil
          (progn
-           (require 'w3m)
-           'mixi-w3m-retrieve)
+           (require 'url)
+           (if (fboundp 'url-retrieve-synchronously)
+               'url))
        (error))
       (if (and (fboundp 'executable-find)
               (executable-find mixi-curl-program))
-         'mixi-curl-retrieve)
-      (error "Can't set `mixi-retrieve-function'"))
-  "*The function for retrieving."
-  :type '(radio (const :tag "Using url" mixi-url-retrieve)
-               (const :tag "Using w3m" mixi-w3m-retrieve)
-               (const :tag "Using curl" mixi-curl-retrieve)
-               (function :format "Other function: %v\n" :size 0))
+         'curl)
+      (error "Cannot set `mixi-backend'."))
+  "*The backend for accessing to mixi."
+  :type '(radio (const :tag "Use emacs-w3m" w3m)
+               (const :tag "Use url.el" url)
+               (const :tag "Use curl" curl)
+               (symbol :tag "The other backend"))
+  :group 'mixi)
+
+(defcustom mixi-login-use-ssl nil
+  "*If non-ni, login using SSL."
+  :type 'boolean
   :group 'mixi)
 
 (defcustom mixi-default-email nil
@@ -199,12 +229,36 @@ Increase this value when unexpected error frequently occurs."
   :type 'boolean
   :group 'mixi)
 
+(defvar mixi-temp-buffer-name " *mixi temp*")
 (defvar mixi-me nil)
 
 ;; Utilities.
 (defmacro mixi-message (&rest strings)
   `(concat "[mixi] " ,@strings))
 
+(put 'mixi-realization-error
+     'error-message (mixi-message "Cannot realize object"))
+(put 'mixi-realization-error
+     'error-conditions '(mixi-realization-error error))
+
+(put 'mixi-post-error
+     'error-message (mixi-message "Cannot post"))
+(put 'mixi-post-error
+     'error-conditions '(mixi-post-error error))
+
+(defmacro mixi-realization-error (type object)
+  `(let ((data (if debug-on-error
+                  (list ,type ,object (buffer-string))
+                (list ,type ,object))))
+     (signal 'mixi-realization-error data)))
+
+(defmacro mixi-post-error (type &optional object)
+  `(let ((data (when debug-on-error (list (buffer-string)))))
+     (if ,object
+        (setq data (cons ,type (cons ,object data)))
+       (setq data (cons ,type data)))
+     (signal 'mixi-post-error data)))
+
 (defconst mixi-message-adult-contents
   "¤³¤Î¥Ú¡¼¥¸¤«¤éÀè¤Ï¥¢¥À¥ë¥È¡ÊÀ®¿Í¸þ¤±¡Ë¥³¥ó¥Æ¥ó¥Ä¤¬´Þ¤Þ¤ì¤Æ¤¤¤Þ¤¹¡£<br>
 ±ÜÍ÷¤ËƱ°Õ¤µ¤ì¤¿Êý¤Î¤ß¡¢Àè¤Ø¤ª¿Ê¤ß¤¯¤À¤µ¤¤¡£")
@@ -218,7 +272,12 @@ Increase this value when unexpected error frequently occurs."
 ¤»¤ó¤¬¡¢¤·¤Ð¤é¤¯¤Î´Ö¤ªÂÔ¤Á¤¯¤À¤µ¤¤¡£")
 
 (defmacro mixi-retrieve (url &optional post-data)
-  `(funcall mixi-retrieve-function ,url ,post-data))
+  `(funcall (intern (concat "mixi-" (symbol-name mixi-backend) "-retrieve"))
+           ,url ,post-data))
+
+(defmacro mixi-post-form (url fields)
+  `(funcall (intern (concat "mixi-" (symbol-name mixi-backend) "-post-form"))
+           ,url ,fields))
 
 (defun mixi-parse-buffer (url buffer &optional post-data)
   (when (string-match mixi-message-adult-contents buffer)
@@ -231,49 +290,72 @@ Increase this value when unexpected error frequently occurs."
   (if (not (string-match mixi-message-continuously-accessing buffer))
       buffer
     (message (mixi-message "Waiting for continuously accessing..."))
-    (sit-for mixi-continuously-access-interval)
+    (sleep-for mixi-continuously-access-interval)
     (mixi-retrieve url post-data)))
 
 (defmacro mixi-expand-url (url)
-  `(if (string-match (concat "^" mixi-url) ,url)
+  `(if (string-match "^http" ,url)
        ,url
      (concat mixi-url ,url)))
 
-(defun mixi-url-retrieve (url &optional post-data)
+;; FIXME: Support files.
+(defun mixi-make-form-data (fields)
+  "Make form data and return (CONTENT-TYPE . FORM-DATA)."
+  (let* ((boundary (apply 'format "--_%d_%d_%d" (current-time)))
+        (content-type (concat "multipart/form-data; boundary=" boundary))
+        (form-data
+         (mapconcat
+          (lambda (field)
+            (concat "--" boundary "\r\n"
+                    "Content-Disposition: form-data; name=\""
+                    (car field) "\"\r\n"
+                    "\r\n"
+                    (encode-coding-string (cdr field) mixi-coding-system)))
+          fields "\r\n")))
+    (cons content-type (concat form-data "\r\n--" boundary "--"))))
+
+(defun mixi-url-retrieve (url &optional post-data extra-headers)
   "Retrieve the URL and return gotten strings."
-  (if post-data
-      (progn
-       (setq url-request-method "POST")
-       (setq url-request-data post-data))
-    (setq url-request-method "GET")
-    (setq url-request-data nil))
-  (let* ((url (mixi-expand-url url))
+  (let* ((url-request-method (if post-data "POST" "GET"))
+        (url-request-data post-data)
+        (url-request-extra-headers extra-headers)
+        (url (mixi-expand-url url))
+        url-show-status
         (buffer (url-retrieve-synchronously url))
         ret)
     (unless (bufferp buffer)
-      (error (mixi-message "Cannot retrieve")))
+      (error (mixi-message "Cannot retrieve: " url)))
     (with-current-buffer buffer
       (goto-char (point-min))
       (while (looking-at "HTTP/[0-9]+\\.[0-9]+ [13][0-9][0-9]")
        (delete-region (point) (re-search-forward "\r?\n\r?\n")))
       (unless (looking-at "HTTP/[0-9]+\\.[0-9]+ 200")
-       (error (mixi-message "Cannot retrieve")))
+       (error (mixi-message "Cannot retrieve: " url)))
       (delete-region (point) (re-search-forward "\r?\n\r?\n"))
       (setq ret (decode-coding-string (buffer-string) mixi-coding-system))
       (kill-buffer buffer)
       (mixi-parse-buffer url ret post-data))))
 
+(defun mixi-url-post-form (url fields)
+  (let* ((form-data (mixi-make-form-data fields))
+        (extra-headers `(("Content-Type" . ,(car form-data)))))
+    (mixi-url-retrieve url (cdr form-data) extra-headers)))
+
 (defun mixi-w3m-retrieve (url &optional post-data)
   "Retrieve the URL and return gotten strings."
   (let ((url (mixi-expand-url url)))
     (with-temp-buffer
       (if (not (string= (w3m-retrieve url nil nil post-data) "text/html"))
-         (error (mixi-message "Cannot retrieve"))
+         (error (mixi-message "Cannot retrieve: " url))
        (w3m-decode-buffer url)
        (let ((ret (buffer-substring-no-properties (point-min) (point-max))))
          (mixi-parse-buffer url ret post-data))))))
 
-(defun mixi-curl-retrieve (url &optional post-data)
+(defun mixi-w3m-post-form (url fields)
+  (let ((form-data (mixi-make-form-data fields)))
+    (mixi-w3m-retrieve url form-data)))
+
+(defun mixi-curl-retrieve (url &optional post-data form-data)
   "Retrieve the URL and return gotten strings."
   (with-temp-buffer
     (if (fboundp 'set-buffer-multibyte)
@@ -289,6 +371,7 @@ Increase this value when unexpected error frequently occurs."
                  (apply #'start-process "curl" (current-buffer)
                         mixi-curl-program
                         (append (if post-data '("-d" "@-"))
+                                form-data
                                 (list "-i" "-L" "-s"
                                       "-b" mixi-curl-cookie-file
                                       "-c" mixi-curl-cookie-file
@@ -304,70 +387,106 @@ Increase this value when unexpected error frequently occurs."
       (while (looking-at "HTTP/[0-9]+\\.[0-9]+ [13][0-9][0-9]")
        (delete-region (point) (re-search-forward "\r?\n\r?\n")))
       (unless (looking-at "HTTP/[0-9]+\\.[0-9]+ 200")
-       (error (mixi-message "Cannot retrieve")))
+       (error (mixi-message "Cannot retrieve: " url)))
       (delete-region (point) (re-search-forward "\r?\n\r?\n"))
       (setq ret (decode-coding-string (buffer-string) mixi-coding-system))
       (mixi-parse-buffer url ret post-data))))
 
+(defun mixi-curl-post-form (url fields)
+  (let (form-data)
+    (mapcar (lambda (field)
+             (push "-F" form-data)
+             (push (concat (car field) "="
+                           (encode-coding-string (cdr field)
+                                                 mixi-coding-system))
+                   form-data))
+           fields)
+    (mixi-curl-retrieve url nil (reverse form-data))))
+
 (defconst mixi-my-id-regexp
-  "<a href=\"add_diary\\.pl\\?id=\\([0-9]+\\)")
+  "<a href=\"show_profile\\.pl\\?id=\\([0-9]+\\)")
 
 (defun mixi-login (&optional email password)
   "Login to mixi."
-  (when (and (eq mixi-retrieve-function 'mixi-w3m-retrieve)
-            (not w3m-use-cookies))
+  (when (and (eq mixi-backend 'w3m) (not w3m-use-cookies))
     (error (mixi-message "Require to accept cookies.  Please set "
                         "`w3m-use-cookies' to t.")))
   (let ((email (or email mixi-default-email
                   (read-from-minibuffer (mixi-message "Login Email: "))))
        (password (or password mixi-default-password
                      (read-passwd (mixi-message "Login Password: ")))))
-    (let ((buffer (mixi-retrieve "/login.pl"
-                                (concat "email=" email
-                                        "&password=" password
-                                        "&next_url=/home.pl"
-                                        "&sticky=on"))))
-      (unless (string-match "url=/check\\.pl\\?n=" buffer)
-       (error (mixi-message "Cannot login")))
-      (setq buffer (mixi-retrieve "/check.pl?n=home.pl"))
-      (if (string-match mixi-my-id-regexp buffer)
-         (setq mixi-me (mixi-make-friend (match-string 1 buffer)))
-       (error (mixi-message "Cannot login"))))))
+    (let ((url (mixi-expand-url "/login.pl")))
+      (when (and mixi-login-use-ssl (string-match "^http:" url))
+       (setq url (replace-match "https:" nil nil url)))
+      (let ((buffer (mixi-retrieve url
+                                  (concat "email=" email
+                                          "&password=" password
+                                          "&next_url=/home.pl"
+                                          "&sticky=on"))))
+       (unless (string-match "url=/check\\.pl\\?n=" buffer)
+         (error (mixi-message "Cannot login")))
+       (setq buffer (mixi-retrieve "/check.pl?n=home.pl"))
+       (if (string-match mixi-my-id-regexp buffer)
+           (setq mixi-me (mixi-make-friend (match-string 1 buffer)))
+         (error (mixi-message "Cannot login")))))))
 
 (defun mixi-logout ()
   (mixi-retrieve "/logout.pl"))
 
+(defconst mixi-login-form "<form action=\"/login.pl\" method=\"post\">")
+
 (defmacro with-mixi-retrieve (url &rest body)
-  `(let (buffer)
+  `(with-current-buffer (get-buffer-create mixi-temp-buffer-name)
      (when ,url
-       (setq buffer (mixi-retrieve ,url))
-       (when (string-match "login.pl" buffer)
+       (erase-buffer)
+       (insert (mixi-retrieve ,url))
+       (goto-char (point-min))
+       (when (search-forward mixi-login-form nil t)
         (mixi-login)
-        (setq buffer (mixi-retrieve ,url))))
+        (erase-buffer)
+        (insert (mixi-retrieve ,url))))
+     (goto-char (point-min))
      ,@body))
 (put 'with-mixi-retrieve 'lisp-indent-function 'defun)
-(put 'with-mixi-retrieve 'edebug-form-spec '(form body))
+(put 'with-mixi-retrieve 'edebug-form-spec '(body))
 
-(defun mixi-get-matched-items (url regexp &optional range)
+(defmacro with-mixi-post-form (url fields &rest body)
+  `(with-current-buffer (get-buffer-create mixi-temp-buffer-name)
+     (when ,url
+       (erase-buffer)
+       (insert (mixi-post-form ,url ,fields))
+       (goto-char (point-min))
+       (when (search-forward mixi-login-form nil t)
+        (mixi-login)
+        (erase-buffer)
+        (insert (mixi-post-form ,url ,fields))))
+     (goto-char (point-min))
+     ,@body))
+(put 'with-mixi-post-form 'lisp-indent-function 'defun)
+(put 'with-mixi-post-form 'edebug-form-spec '(body))
+
+(defun mixi-get-matched-items (url regexp &optional range reverse)
   "Get matched items to REGEXP in URL."
   (let ((page 1)
        ids)
     (catch 'end
       (while (or (null range) (< (length ids) range))
-       (with-mixi-retrieve (format url page)
-         (let ((pos 0)
+       (with-mixi-retrieve (when url (format url page))
+         (let ((func (if reverse (progn
+                                   (goto-char (point-max))
+                                   're-search-backward)
+                       're-search-forward))
                found)
-           (while (and (string-match regexp buffer pos)
+           (while (and (funcall func regexp nil t)
                        (or (null range) (< (length ids) range)))
              (let ((num 1)
                    list)
-               (while (match-string num buffer)
-                 (setq list (cons (match-string num buffer) list))
+               (while (match-string num)
+                 (setq list (cons (match-string num) list))
                  (incf num))
                (when (not (member (reverse list) ids))
                  (setq found t)
-                 (setq ids (cons (reverse list) ids)))
-               (setq pos (match-end (1- num)))))
+                 (setq ids (cons (reverse list) ids)))))
            (when (not found)
              (throw 'end ids))))
        (incf page)))
@@ -394,24 +513,54 @@ Increase this value when unexpected error frequently occurs."
     (buffer-string)))
 
 ;; stolen (and modified) from w3m.el
-;; FIXME: Hmm.
-(defun mixi-url-encode-and-quote-percent-string (string)
+(defconst mixi-entity-alist '(("gt" . ">")
+                             ("lt" . "<")
+                             ("amp" . "&"))
+  "Alist of html character entities and values.")
+
+;; stolen (and modified) from w3m.el
+(defun mixi-encode-specials-string (str)
+  "Encode special characters in the string STR."
+  (let ((pos 0)
+       (buf))
+    (while (string-match "[<>&]" str pos)
+      (setq buf
+           (cons ";"
+                 (cons (car (rassoc (match-string 0 str) mixi-entity-alist))
+                       (cons "&"
+                             (cons (substring str pos (match-beginning 0))
+                                   buf))))
+           pos (match-end 0)))
+    (if buf
+       (apply 'concat (nreverse (cons (substring str pos) buf)))
+      str)))
+
+;; stolen (and modified) from w3m.el
+(defun mixi-url-encode-string (string)
   (apply (function concat)
         (mapcar
          (lambda (char)
            (cond
             ((eq char ?\n)             ; newline
-             "%%0D%%0A")
+             "%0D%0A")
             ((string-match "[-a-zA-Z0-9_:/.]" (char-to-string char)) ; xxx?
              (char-to-string char))    ; printable
             ((char-equal char ?\x20)   ; space
              "+")
             (t
-             (format "%%%%%02x" char))))       ; escape
+             (format "%%%02x" char)))) ; escape
          ;; Coerce a string into a list of chars.
          (append (encode-coding-string (or string "") mixi-coding-system)
                  nil))))
 
+(defun mixi-url-encode-and-quote-percent-string (string)
+  (let ((string (mixi-url-encode-string string))
+       (pos 0))
+    (while (string-match "%" string pos)
+      (setq string (replace-match "%%" nil nil string))
+      (setq pos (+ (match-end 0) 1)))
+    string))
+
 ;; Object.
 (defconst mixi-object-prefix "mixi-")
 
@@ -450,7 +599,7 @@ Increase this value when unexpected error frequently occurs."
   (unless (mixi-object-p object)
     (signal 'wrong-type-argument (list 'mixi-object-p object)))
   (aref (cdr object) 0))
-(defalias 'mixi-object-realize-p 'mixi-object-timestamp)
+(defalias 'mixi-object-realized-p 'mixi-object-timestamp)
 
 (defun mixi-object-owner (object)
   "Return the owner of OBJECT."
@@ -508,8 +657,10 @@ Increase this value when unexpected error frequently occurs."
   "Return a mixi object from URL."
   (if (string-match mixi-object-url-regexp url)
       (let ((name (match-string 2 url)))
-       (when (string= name "bbs")
-         (setq name "topic"))
+       (cond ((string= name "bbs")
+              (setq name "topic"))
+             ((string= name "profile")
+              (setq name "friend")))
        (let ((func (intern (concat mixi-object-prefix "make-" name
                                    "-from-url"))))
          (funcall func url)))
@@ -566,27 +717,28 @@ Increase this value when unexpected error frequently occurs."
                                    mixi-cache-file-regexp))
 
 (defun mixi-save-cache ()
-  (unless (file-directory-p mixi-directory)
-    (make-directory mixi-directory t))
-  (let ((caches (apropos-internal mixi-cache-regexp 'boundp)))
-    (mapc (lambda (symbol)
-           (with-temp-file (expand-file-name
-                            (substring (symbol-name symbol)
-                                       (length mixi-object-prefix))
-                            mixi-directory)
-             (let ((coding-system-for-write mixi-coding-system)
-                   (cache (symbol-value symbol)))
-               (insert "#s(hash-table size "
-                       (number-to-string (hash-table-count cache))
-                       " test equal data (\n")
-               (maphash
-                (lambda (key value)
-                  (let (print-level print-length)
-                    (insert (prin1-to-string key) " "
-                            (prin1-to-string value) "\n")))
-                cache))
-             (insert "))")))
-         caches)))
+  (let ((cache-directory (expand-file-name "cache" mixi-directory)))
+    (unless (file-directory-p cache-directory)
+      (make-directory cache-directory t))
+    (let ((caches (apropos-internal mixi-cache-regexp 'boundp)))
+      (while caches
+       (with-temp-file (expand-file-name
+                        (substring (symbol-name (car caches))
+                                   (length mixi-object-prefix))
+                        cache-directory)
+         (let ((coding-system-for-write mixi-coding-system)
+               (cache (symbol-value (car caches))))
+           (insert "#s(hash-table size "
+                   (number-to-string (hash-table-count cache))
+                   " test equal data (\n")
+           (maphash
+            (lambda (key value)
+              (let (print-level print-length)
+                (insert (prin1-to-string key) " "
+                        (prin1-to-string value) "\n")))
+            cache))
+         (insert "))"))
+       (setq caches (cdr caches))))))
 
 ;; stolen (and modified) from lsdb.el
 (defun mixi-read-cache (&optional marker)
@@ -617,20 +769,22 @@ Increase this value when unexpected error frequently occurs."
       (read marker))))
 
 (defun mixi-load-cache ()
-  (when (file-directory-p mixi-directory)
-    ;; FIXME: Load friend and community first.
-    (let ((files (directory-files mixi-directory t mixi-cache-file-regexp)))
-      (mapc (lambda (file)
-             (let ((buffer (find-file-noselect file)))
-               (unwind-protect
-                   (save-excursion
-                     (set-buffer buffer)
-                     (goto-char (point-min))
-                     (re-search-forward "^#s(")
-                     (goto-char (match-beginning 0))
-                     (mixi-read-cache (point-marker)))
-                 (kill-buffer buffer))))
-           files))))
+  (let ((cache-directory (expand-file-name "cache" mixi-directory)))
+    (when (file-directory-p cache-directory)
+      ;; FIXME: Load friend and community first.
+      (let ((files (directory-files cache-directory t
+                                   mixi-cache-file-regexp)))
+       (while files
+         (let ((buffer (find-file-noselect (car files))))
+           (unwind-protect
+               (save-excursion
+                 (set-buffer buffer)
+                 (goto-char (point-min))
+                 (re-search-forward "^#s(")
+                 (goto-char (match-beginning 0))
+                 (mixi-read-cache (point-marker)))
+             (kill-buffer buffer)))
+         (setq files (cdr files)))))))
 
 ;; Friend object.
 (defvar mixi-friend-cache (make-hash-table :test 'equal))
@@ -648,18 +802,18 @@ Increase this value when unexpected error frequently occurs."
   "Return a my object."
   (unless mixi-me
     (with-mixi-retrieve "/home.pl"
-      (if (string-match mixi-my-id-regexp buffer)
-         (setq mixi-me (mixi-make-friend (match-string 1 buffer)))
+      (if (re-search-forward mixi-my-id-regexp nil t)
+         (setq mixi-me (mixi-make-friend (match-string 1)))
        (signal 'error (list 'who-am-i)))))
   mixi-me)
 
 (defconst mixi-friend-url-regexp
-  "/show_friend\\.pl\\?id=\\([0-9]+\\)")
+  "/show_\\(friend\\|profile\\)\\.pl\\?id=\\([0-9]+\\)")
 
 (defun mixi-make-friend-from-url (url)
   "Return a friend object from URL."
   (if (string-match mixi-friend-url-regexp url)
-      (let ((id (match-string 1 url)))
+      (let ((id (match-string 2 url)))
        (mixi-make-friend id))
     (when (string-match "/home\\.pl" url)
       (mixi-make-me))))
@@ -668,75 +822,74 @@ Increase this value when unexpected error frequently occurs."
   `(eq (mixi-object-class ,friend) 'mixi-friend))
 
 (defmacro mixi-friend-page (friend)
-  `(concat "/show_friend.pl?id=" (mixi-friend-id ,friend)))
+  `(concat "/show_profile.pl?id=" (mixi-friend-id ,friend)))
 
 (defconst mixi-friend-nick-regexp
-  "<img alt=\"\\*\" src=\"http://img\\.mixi\\.jp/img/dot0\\.gif\" width=\"1\" height=\"5\"><br>\r?\n\\(.*\\)¤µ¤ó([0-9]+)")
-(defconst mixi-friend-name-sex-regexp
-  "<td BGCOLOR=#F2DDB7 WIDTH=80 NOWRAP><font COLOR=#996600>̾\\(&nbsp;\\| \\)Á°</font></td>\n+<td WIDTH=345>\\([^<]+\\) (\\([Ã˽÷]\\)À­)</td>")
+  "<img \\(alt=\"\\*\" \\)?src=\"?http://img\\.mixi\\.jp/img/dot0\\.gif\"? width=\"?1\"? height=\"?5\"?\\( /\\)?><br\\( /\\)?>\r?
+\\(.*\\)¤µ¤ó([0-9]+)")
+(defconst mixi-friend-name-regexp
+  "̾\\(&nbsp;\\| \\)Á°</font></td>
+
+?<td width=\"?345\"?>\\(.+?\\)\\(</td>\\| <img\\)")
+(defconst mixi-friend-sex-regexp
+  "À­\\(&nbsp;\\| \\)ÊÌ</font></td>
+
+?<td width=\"?345\"?>\\([Ã˽÷]\\)À­\\(</td>\\| <img\\)")
 (defconst mixi-friend-address-regexp
-  "<td BGCOLOR=#F2DDB7><font COLOR=#996600>¸½½»½ê</font></td>\n<td>\\(.+\\)\\(\n.+\n\\)?</td></tr>")
+  "¸½½»½ê</font></td>
+<td>\\(.+?\\)\\(</td>\\| <img\\)")
 (defconst mixi-friend-age-regexp
-  "<td BGCOLOR=#F2DDB7><font COLOR=#996600>ǯ\\(&nbsp;\\| \\)Îð</font></td>\n<td>\\([0-9]+\\)ºÐ\\(\n.+\n\\)?</td></tr>")
+  "ǯ\\(&nbsp;\\| \\)Îð</font></td>\n<td>\\([0-9]+\\)ºÐ\\(</td>\\| <img\\)")
 (defconst mixi-friend-birthday-regexp
-  "<td BGCOLOR=#F2DDB7><font COLOR=#996600>ÃÂÀ¸Æü</font></td>\n<td>\\([0-9]+\\)·î\\([0-9]+\\)Æü\\(\n.+\n\\)?</td></tr>")
+  "ÃÂÀ¸Æü</font></td>\n<td>\\([0-9]+\\)·î\\([0-9]+\\)Æü\\(</td>\\| <img\\)")
 (defconst mixi-friend-blood-type-regexp
-  "<td BGCOLOR=#F2DDB7><font COLOR=#996600>·ì±Õ·¿</font></td>\n<td>\\([ABO]B?\\)·¿\\(\n\n\\)?</td></tr>")
+  "·ì±Õ·¿</font></td>\n<td>\\([ABO]B?\\)·¿\\(</td>\\| <img\\)")
 (defconst mixi-friend-birthplace-regexp
-  "<td BGCOLOR=#F2DDB7><font COLOR=#996600>½Ð¿ÈÃÏ</font>\n?</td>\n<td>\\(.+\\)\\(\n.+\n\\)?</td></tr>")
+  "½Ð¿ÈÃÏ</font>\n?</td>\n<td>\\(.+?\\)\\(</td>\\| <img\\)")
 (defconst mixi-friend-hobby-regexp
-  "<td BGCOLOR=#F2DDB7><font COLOR=#996600>¼ñ\\(&nbsp;\\| \\)Ì£</font></td>\n<td>\\(.+\\)</td></tr>")
+  "¼ñ\\(&nbsp;\\| \\)Ì£</font></td>\n<td>\\(.+?\\)\\(</td>\\| <img\\)")
 (defconst mixi-friend-job-regexp
-  "<td BGCOLOR=#F2DDB7><font COLOR=#996600>¿¦\\(&nbsp;\\| \\)¶È</font></td>\n<td>\\(.+\\)\\(\n.+\n\\)?</td></tr>")
+  "¿¦\\(&nbsp;\\| \\)¶È</font></td>\n<td>\\(.+?\\)\\(</td>\\| <img\\)")
 (defconst mixi-friend-organization-regexp
-  "<td BGCOLOR=#F2DDB7><font COLOR=#996600>½ê\\(&nbsp;\\| \\)°</font></td>\n<td[^>]*>\\(.+\\)\\(\n.+\n\\)?</td></tr>")
+  "½ê\\(&nbsp;\\| \\)°</font></td>\n<td[^>]*>\\(.+?\\)\\(</td>\\| <img\\)")
 (defconst mixi-friend-profile-regexp
-  "<td BGCOLOR=#F2DDB7><font COLOR=#996600>¼«¸Ê¾Ò²ð</font></td>\n<td CLASS=h120>\\(.+\\)</td></tr>")
+  "¼«¸Ê¾Ò²ð</font></td>
+<td class=\"?h120\"? width=\"?345\"?>\\(\\(.\\|\r?\n\\)*?\\)</td></tr>")
 
-(defun mixi-friend-realize (friend)
+(defun mixi-realize-friend (friend)
   "Realize a FRIEND."
   ;; FIXME: Check a expiration of cache?
-  (unless (mixi-object-realize-p friend)
-    (let (buf)
-      (with-mixi-retrieve (mixi-friend-page friend)
-       (setq buf buffer))
-      (if (string-match mixi-friend-nick-regexp buf)
-         (mixi-friend-set-nick friend (match-string 1 buf))
-       (signal 'error (list 'cannot-find-nick friend)))
-      ;; For getting my profile.
-      (unless (string-match mixi-friend-name-sex-regexp buf)
-       (with-mixi-retrieve (concat "/show_profile.pl?id="
-                                   (mixi-friend-id friend))
-         (setq buf buffer)))
-      (if (string-match mixi-friend-name-sex-regexp buf)
-         (progn
-           (mixi-friend-set-name friend (match-string 2 buf))
-           (mixi-friend-set-sex friend
-                                (if (string= (match-string 3 buf) "ÃË")
-                                    'male 'female)))
-       (signal 'error (list 'cannot-find-name-or-sex friend)))
-      (when (string-match mixi-friend-address-regexp buf)
-       (mixi-friend-set-address friend (match-string 1 buf)))
-      (when (string-match mixi-friend-age-regexp buf)
-       (mixi-friend-set-age
-        friend (string-to-number (match-string 2 buf))))
-      (when (string-match mixi-friend-birthday-regexp buf)
-       (mixi-friend-set-birthday
-        friend (list (string-to-number (match-string 1 buf))
-                     (string-to-number (match-string 2 buf)))))
-      (when (string-match mixi-friend-blood-type-regexp buf)
-       (mixi-friend-set-blood-type friend (intern (match-string 1 buf))))
-      (when (string-match mixi-friend-birthplace-regexp buf)
-       (mixi-friend-set-birthplace friend (match-string 1 buf)))
-      (when (string-match mixi-friend-hobby-regexp buf)
-       (mixi-friend-set-hobby
-        friend (split-string (match-string 2 buf) ", ")))
-      (when (string-match mixi-friend-job-regexp buf)
-       (mixi-friend-set-job friend (match-string 2 buf)))
-      (when (string-match mixi-friend-organization-regexp buf)
-       (mixi-friend-set-organization friend (match-string 2 buf)))
-      (when (string-match mixi-friend-profile-regexp buf)
-       (mixi-friend-set-profile friend (match-string 1 buf))))
+  (unless (mixi-object-realized-p friend)
+    (with-mixi-retrieve (mixi-friend-page friend)
+      (let ((case-fold-search t))
+       (if (re-search-forward mixi-friend-nick-regexp nil t)
+           (mixi-friend-set-nick friend (match-string 4))
+         (mixi-realization-error 'cannot-find-nick friend))
+       (when (re-search-forward mixi-friend-name-regexp nil t)
+         (mixi-friend-set-name friend (match-string 2)))
+       (when (re-search-forward mixi-friend-sex-regexp nil t)
+         (mixi-friend-set-sex friend (if (string= (match-string 2) "ÃË")
+                                         'male 'female)))
+       (when (re-search-forward mixi-friend-address-regexp nil t)
+         (mixi-friend-set-address friend (match-string 1)))
+       (when (re-search-forward mixi-friend-age-regexp nil t)
+         (mixi-friend-set-age friend (string-to-number (match-string 2))))
+       (when (re-search-forward mixi-friend-birthday-regexp nil t)
+         (mixi-friend-set-birthday
+          friend (list (string-to-number (match-string 1))
+                       (string-to-number (match-string 2)))))
+       (when (re-search-forward mixi-friend-blood-type-regexp nil t)
+         (mixi-friend-set-blood-type friend (intern (match-string 1))))
+       (when (re-search-forward mixi-friend-birthplace-regexp nil t)
+         (mixi-friend-set-birthplace friend (match-string 1)))
+       (when (re-search-forward mixi-friend-hobby-regexp nil t)
+         (mixi-friend-set-hobby friend (split-string (match-string 2) ", ")))
+       (when (re-search-forward mixi-friend-job-regexp nil t)
+         (mixi-friend-set-job friend (match-string 2)))
+       (when (re-search-forward mixi-friend-organization-regexp nil t)
+         (mixi-friend-set-organization friend (match-string 2)))
+       (when (re-search-forward mixi-friend-profile-regexp nil t)
+         (mixi-friend-set-profile friend (match-string 1)))))
     (mixi-object-touch friend)))
 
 (defun mixi-friend-id (friend)
@@ -750,84 +903,84 @@ Increase this value when unexpected error frequently occurs."
   (unless (mixi-friend-p friend)
     (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
   (unless (aref (cdr friend) 2)
-    (mixi-friend-realize friend))
+    (mixi-realize-friend friend))
   (aref (cdr friend) 2))
 
 (defun mixi-friend-name (friend)
   "Return the name of FRIEND."
   (unless (mixi-friend-p friend)
     (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
-  (mixi-friend-realize friend)
+  (mixi-realize-friend friend)
   (aref (cdr friend) 3))
 
 (defun mixi-friend-sex (friend)
   "Return the sex of FRIEND."
   (unless (mixi-friend-p friend)
     (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
-  (mixi-friend-realize friend)
+  (mixi-realize-friend friend)
   (aref (cdr friend) 4))
 
 (defun mixi-friend-address (friend)
   "Return the address of FRIEND."
   (unless (mixi-friend-p friend)
     (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
-  (mixi-friend-realize friend)
+  (mixi-realize-friend friend)
   (aref (cdr friend) 5))
 
 (defun mixi-friend-age (friend)
   "Return the age of FRIEND."
   (unless (mixi-friend-p friend)
     (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
-  (mixi-friend-realize friend)
+  (mixi-realize-friend friend)
   (aref (cdr friend) 6))
 
 (defun mixi-friend-birthday (friend)
   "Return the birthday of FRIEND."
   (unless (mixi-friend-p friend)
     (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
-  (mixi-friend-realize friend)
+  (mixi-realize-friend friend)
   (aref (cdr friend) 7))
 
 (defun mixi-friend-blood-type (friend)
   "Return the blood type of FRIEND."
   (unless (mixi-friend-p friend)
     (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
-  (mixi-friend-realize friend)
+  (mixi-realize-friend friend)
   (aref (cdr friend) 8))
 
 (defun mixi-friend-birthplace (friend)
   "Return the birthplace of FRIEND."
   (unless (mixi-friend-p friend)
     (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
-  (mixi-friend-realize friend)
+  (mixi-realize-friend friend)
   (aref (cdr friend) 9))
 
 (defun mixi-friend-hobby (friend)
   "Return the hobby of FRIEND."
   (unless (mixi-friend-p friend)
     (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
-  (mixi-friend-realize friend)
+  (mixi-realize-friend friend)
   (aref (cdr friend) 10))
 
 (defun mixi-friend-job (friend)
   "Return the job of FRIEND."
   (unless (mixi-friend-p friend)
     (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
-  (mixi-friend-realize friend)
+  (mixi-realize-friend friend)
   (aref (cdr friend) 11))
 
 (defun mixi-friend-organization (friend)
   "Return the organization of FRIEND."
   (unless (mixi-friend-p friend)
     (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
-  (mixi-friend-realize friend)
+  (mixi-realize-friend friend)
   (aref (cdr friend) 12))
 
 (defun mixi-friend-profile (friend)
-  "Return the pforile of FRIEND."
+  "Return the profile of FRIEND."
   (unless (mixi-friend-p friend)
     (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
-  (mixi-friend-realize friend)
+  (mixi-realize-friend friend)
   (aref (cdr friend) 13))
 
 (defun mixi-friend-set-nick (friend nick)
@@ -907,19 +1060,21 @@ Increase this value when unexpected error frequently occurs."
           (when ,friend (concat "&id=" (mixi-friend-id ,friend)))))
 
 (defconst mixi-friend-list-id-regexp
-  "<a href=show_friend\\.pl\\?id=\\([0-9]+\\)")
+  "<a href=\"?show_friend\\.pl\\?id=\\([0-9]+\\)\"?")
 (defconst mixi-friend-list-nick-regexp
-  "<td valign=middle>\\(.+\\)¤µ¤ó([0-9]+)<br />")
+  "<td valign=\"?top\"?>\\(.+\\)¤µ¤ó([0-9]+)")
 
-(defun mixi-get-friends (&rest args)
+;;;###autoload
+(defun mixi-get-friends (&rest friend-or-range)
   "Get friends of FRIEND."
-  (when (> (length args) 2)
-    (signal 'wrong-number-of-arguments (list 'mixi-get-friends (length args))))
-  (let ((friend (nth 0 args))
-       (range (nth 1 args)))
+  (when (> (length friend-or-range) 2)
+    (signal 'wrong-number-of-arguments (list 'mixi-get-friends
+                                            (length friend-or-range))))
+  (let ((friend (nth 0 friend-or-range))
+       (range (nth 1 friend-or-range)))
     (when (or (not (mixi-friend-p friend)) (mixi-friend-p range))
-      (setq friend (nth 1 args))
-      (setq range (nth 0 args)))
+      (setq friend (nth 1 friend-or-range))
+      (setq range (nth 0 friend-or-range)))
     (unless (or (null friend) (mixi-friend-p friend))
       (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
     (let ((ids (mixi-get-matched-items (mixi-friend-list-page friend)
@@ -940,27 +1095,19 @@ Increase this value when unexpected error frequently occurs."
 (defmacro mixi-favorite-list-page ()
   `(concat "/list_bookmark.pl?page=%d"))
 
-(defconst mixi-favorite-list-id-regexp
-  "<td ALIGN=center BGCOLOR=#FDF9F2 width=330><a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">")
-(defconst mixi-favorite-list-nick-regexp
-  "<td BGCOLOR=#FDF9F2><font COLOR=#996600>̾&nbsp;&nbsp;Á°</font></td>
-<td COLSPAN=2 BGCOLOR=#FFFFFF>\\(.+\\)</td></tr>")
+(defconst mixi-favorite-list-regexp
+  "<td bgcolor=\"#FDF9F2\"><font color=\"#996600\">̾Á°</font></td>
+<td colspan=\"2\" bgcolor=\"#FFFFFF\"><a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a></td>")
 
+;;;###autoload
 (defun mixi-get-favorites (&optional range)
   "Get favorites."
-  (let ((ids (mixi-get-matched-items (mixi-favorite-list-page)
-                                    mixi-favorite-list-id-regexp
-                                    range))
-       (nicks (mixi-get-matched-items (mixi-favorite-list-page)
-                                      mixi-favorite-list-nick-regexp
+  (let ((items (mixi-get-matched-items (mixi-favorite-list-page)
+                                      mixi-favorite-list-regexp
                                       range)))
-    (let ((index 0)
-         ret)
-      (while (< index (length ids))
-       (setq ret (cons (mixi-make-friend (nth 0 (nth index ids))
-                                         (nth 0 (nth index nicks))) ret))
-       (incf index))
-      (reverse ret))))
+    (mapcar (lambda (item)
+             (mixi-make-friend (nth 0 item) (nth 1 item)))
+           items)))
 
 ;; Log object.
 (defun mixi-make-log (friend time)
@@ -986,8 +1133,9 @@ Increase this value when unexpected error frequently occurs."
   `(concat "/show_log.pl"))
 
 (defconst mixi-log-list-regexp
-  "\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\) <a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a></li>")
+  "\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\) <a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*?\\)</a>")
 
+;;;###autoload
 (defun mixi-get-logs (&optional range)
   "Get logs."
   (let ((items (mixi-get-matched-items (mixi-log-list-page)
@@ -1005,23 +1153,24 @@ Increase this value when unexpected error frequently occurs."
 
 ;; Diary object.
 (defvar mixi-diary-cache (make-hash-table :test 'equal))
-(defun mixi-make-diary (owner id &optional time title content)
+(defun mixi-make-diary (owner id &optional comment-count time title content)
   "Return a diary object."
   (let ((owner (or owner (mixi-make-me))))
     (mixi-make-cache (list (mixi-friend-id owner) id)
-                    (cons 'mixi-diary (vector nil owner id time title
-                                              content))
+                    (cons 'mixi-diary (vector nil owner id comment-count time
+                                              title content))
                     mixi-diary-cache)))
 
 (defconst mixi-diary-url-regexp
-  "/view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=\\([0-9]+\\)")
+  "/view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=\\([0-9]+\\)\\(&comment_count=\\([0-9]+\\)\\)?")
 
 (defun mixi-make-diary-from-url (url)
   "Return a diary object from URL."
   (when (string-match mixi-diary-url-regexp url)
     (let ((id (match-string 1 url))
-         (owner-id (match-string 2 url)))
-      (mixi-make-diary (mixi-make-friend owner-id) id))))
+         (owner-id (match-string 2 url))
+         (comment-count (match-string 4 url)))
+      (mixi-make-diary (mixi-make-friend owner-id) id comment-count))))
 
 (defmacro mixi-diary-p (diary)
   `(eq (mixi-object-class ,diary) 'mixi-diary))
@@ -1031,40 +1180,41 @@ Increase this value when unexpected error frequently occurs."
           "&owner_id=" (mixi-friend-id (mixi-diary-owner ,diary))))
 
 (defconst mixi-diary-closed-regexp
-  "<td>ͧ¿Í\\(¤Îͧ¿Í\\)?¤Þ¤Ç¸ø³«¤Î¤¿¤áÆɤळ¤È¤¬½ÐÍè¤Þ¤»¤ó¡£</td></tr>")
+  "<td>ͧ¿Í\\(¤Îͧ¿Í\\)?¤Þ¤Ç¸ø³«¤Î¤¿¤áÆɤळ¤È¤¬½ÐÍè¤Þ¤»¤ó¡£</td>")
 (defconst mixi-diary-owner-nick-regexp
-  "<td WIDTH=490 background=http://img\\.mixi\\.jp/img/bg_w\\.gif><b><font COLOR=#605048>\\(.+?\\)\\(¤µ¤ó\\)?¤ÎÆüµ­</font></b></td>")
+  "<td width=\"?490\"? background=\"?http://img\\.mixi\\.jp/img/bg_w\\.gif\"?><b><font color=\"?#605048\"?>\\(.+?\\)\\(¤µ¤ó\\)?¤ÎÆüµ­</font></b></td>")
 (defconst mixi-diary-time-regexp
-  "<td \\(align\\|ALIGN\\)=\"?center\"? \\(rowspan\\|ROWSPAN\\)=\"?[23]\"? \\(nowrap=\"nowrap\"\\|NOWRAP\\) \\(width\\|WIDTH\\)=\"?95\"? bgcolor=\"?#FFD8B0\"?>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü\\(<br />\\|<br>\\)\\([0-9]+\\):\\([0-9]+\\)</td>")
+  "<td align=\"?center\"? rowspan=\"?[23]\"? nowrap\\(=\"?nowrap\"?\\)? width=\"?95\"? bgcolor=\"?#FFD8B0\"?>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü<br\\( /\\)?>\\([0-9]+\\):\\([0-9]+\\)</td>")
 (defconst mixi-diary-title-regexp
-  "<td \\(bgcolor\\|BGCOLOR\\)=\"?#FFF4E0\"? width=\"?430\"?>&nbsp;\\([^<]+\\)</td>")
+  "<td bgcolor=\"?#FFF4E0\"? width=\"?430\"?>&nbsp;\\([^<]+\\)</td>")
 (defconst mixi-diary-content-regexp
-  "<td \\(class\\|CLASS\\)=\"?h12\"?>\\(.*\\)</td>")
+  "<table border=\"?0\"? cellspacing=\"?0\"? cellpadding=\"?3\"? width=\"?410\"?>\\(\\(.\\|\r?\n\\)*?\\)\\(\t\\|</tr>\r?\n\\)</table>")
 
-(defun mixi-diary-realize (diary)
+(defun mixi-realize-diary (diary &optional page)
   "Realize a DIARY."
   ;; FIXME: Check a expiration of cache?
-  (unless (mixi-object-realize-p diary)
-    (with-mixi-retrieve (mixi-diary-page diary)
-      (unless (string-match mixi-diary-closed-regexp buffer)
-       (if (string-match mixi-diary-owner-nick-regexp buffer)
-           (mixi-friend-set-nick (mixi-diary-owner diary)
-                                 (match-string 1 buffer))
-         (signal 'error (list 'cannot-find-owner-nick diary)))
-       (if (string-match mixi-diary-time-regexp buffer)
-           (mixi-diary-set-time
-            diary (encode-time 0 (string-to-number (match-string 10 buffer))
-                               (string-to-number (match-string 9 buffer))
-                               (string-to-number (match-string 7 buffer))
-                               (string-to-number (match-string 6 buffer))
-                               (string-to-number (match-string 5 buffer))))
-         (signal 'error (list 'cannot-find-time diary)))
-       (if (string-match mixi-diary-title-regexp buffer)
-           (mixi-diary-set-title diary (match-string 2 buffer))
-         (signal 'error (list 'cannot-find-title diary)))
-       (if (string-match mixi-diary-content-regexp buffer)
-           (mixi-diary-set-content diary (match-string 2 buffer))
-         (signal 'error (list 'cannot-find-content diary)))))
+  (unless (mixi-object-realized-p diary)
+    (with-mixi-retrieve (or page (mixi-diary-page diary))
+      (let ((case-fold-search t))
+       (unless (re-search-forward mixi-diary-closed-regexp nil t)
+         (if (re-search-forward mixi-diary-owner-nick-regexp nil t)
+             (mixi-friend-set-nick (mixi-diary-owner diary)
+                                   (match-string 1))
+           (mixi-realization-error 'cannot-find-owner-nick diary))
+         (if (re-search-forward mixi-diary-time-regexp nil t)
+             (mixi-diary-set-time
+              diary (encode-time 0 (string-to-number (match-string 7))
+                                 (string-to-number (match-string 6))
+                                 (string-to-number (match-string 4))
+                                 (string-to-number (match-string 3))
+                                 (string-to-number (match-string 2))))
+           (mixi-realization-error 'cannot-find-time diary))
+         (if (re-search-forward mixi-diary-title-regexp nil t)
+             (mixi-diary-set-title diary (match-string 1))
+           (mixi-realization-error 'cannot-find-title diary))
+         (if (re-search-forward mixi-diary-content-regexp nil t)
+             (mixi-diary-set-content diary (match-string 1))
+           (mixi-realization-error 'cannot-find-content diary)))))
     (mixi-object-touch diary)))
 
 (defun mixi-diary-owner (diary)
@@ -1079,101 +1229,205 @@ Increase this value when unexpected error frequently occurs."
     (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
   (aref (cdr diary) 2))
 
+(defun mixi-diary-comment-count (diary)
+  "Return the comment-count of DIARY."
+  (unless (mixi-diary-p diary)
+    (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
+  (aref (cdr diary) 3))
+
 (defun mixi-diary-time (diary)
   "Return the time of DIARY."
   (unless (mixi-diary-p diary)
     (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
-  (mixi-diary-realize diary)
-  (aref (cdr diary) 3))
+  (unless (aref (cdr diary) 3)
+    (mixi-realize-diary diary))
+  (aref (cdr diary) 4))
 
 (defun mixi-diary-title (diary)
   "Return the title of DIARY."
   (unless (mixi-diary-p diary)
     (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
-  (mixi-diary-realize diary)
-  (aref (cdr diary) 4))
+  (unless (aref (cdr diary) 4)
+    (mixi-realize-diary diary))
+  (aref (cdr diary) 5))
 
 (defun mixi-diary-content (diary)
   "Return the content of DIARY."
   (unless (mixi-diary-p diary)
     (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
-  (mixi-diary-realize diary)
-  (aref (cdr diary) 5))
+  (mixi-realize-diary diary)
+  (aref (cdr diary) 6))
+
+(defun mixi-diary-set-comment-count (diary comment-count)
+  "Set the comment-count of DIARY."
+  (unless (mixi-diary-p diary)
+    (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
+  (aset (cdr diary) 3 comment-count))
 
 (defun mixi-diary-set-time (diary time)
   "Set the time of DIARY."
   (unless (mixi-diary-p diary)
     (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
-  (aset (cdr diary) 3 time))
+  (aset (cdr diary) 4 time))
 
 (defun mixi-diary-set-title (diary title)
   "Set the title of DIARY."
   (unless (mixi-diary-p diary)
     (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
-  (aset (cdr diary) 4 title))
+  (aset (cdr diary) 5 title))
 
 (defun mixi-diary-set-content (diary content)
   "Set the content of DIARY."
   (unless (mixi-diary-p diary)
     (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
-  (aset (cdr diary) 5 content))
+  (aset (cdr diary) 6 content))
 
 (defmacro mixi-diary-list-page (&optional friend)
   `(concat "/list_diary.pl?page=%d"
           (when ,friend (concat "&id=" (mixi-friend-id ,friend)))))
 
 (defconst mixi-diary-list-regexp
-  "<a href=\"view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=[0-9]+\">")
+  "<tr VALIGN=top>
+<td ALIGN=center ROWSPAN=3 NOWRAP bgcolor=#F2DDB7><font COLOR=#996600>\\([0-9]+\\)ǯ<br />\\([0-9]+\\)·î\\([0-9]+\\)Æü<br>\\([0-9]+\\):\\([0-9]+\\)</font>\\(<br><input type=\"checkbox\" name=\"diary_id\" value=\"[0-9]+\">\\|\\)</td>
+<td bgcolor=\"#FFF4E0\">&nbsp;<a href=\"view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=[0-9]+\">\\(.*\\)</a></td>")
 
-(defun mixi-get-diaries (&rest args)
+;;;###autoload
+(defun mixi-get-diaries (&rest friend-or-range)
   "Get diaries of FRIEND."
-  (when (> (length args) 2)
+  (when (> (length friend-or-range) 2)
     (signal 'wrong-number-of-arguments
-           (list 'mixi-get-diaries (length args))))
-  (let ((friend (nth 0 args))
-       (range (nth 1 args)))
+           (list 'mixi-get-diaries (length friend-or-range))))
+  (let ((friend (nth 0 friend-or-range))
+       (range (nth 1 friend-or-range)))
     (when (or (not (mixi-friend-p friend)) (mixi-friend-p range))
-      (setq friend (nth 1 args))
-      (setq range (nth 0 args)))
+      (setq friend (nth 1 friend-or-range))
+      (setq range (nth 0 friend-or-range)))
     (unless (or (null friend) (mixi-friend-p friend))
       (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
     (let ((items (mixi-get-matched-items (mixi-diary-list-page friend)
                                         mixi-diary-list-regexp
                                         range)))
       (mapcar (lambda (item)
-               (mixi-make-diary friend (nth 0 item)))
+               (mixi-make-diary friend (nth 6 item) nil
+                                (encode-time
+                                 0 (string-to-number (nth 4 item))
+                                 (string-to-number (nth 3 item))
+                                 (string-to-number (nth 2 item))
+                                 (string-to-number (nth 1 item))
+                                 (string-to-number (nth 0 item)))
+                                 (nth 7 item)))
              items))))
 
 (defmacro mixi-new-diary-list-page ()
   `(concat "/new_friend_diary.pl?page=%d"))
 
 (defconst mixi-new-diary-list-regexp
-  "<a class=\"new_link\" href=view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=\\([0-9]+\\)>")
+  "<td WIDTH=180><img src=http://img\\.mixi\\.jp/img/pen\\.gif ALIGN=left WIDTH=14 HEIGHT=16>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</td>
+<td WIDTH=450><a class=\"new_link\" href=view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=\\([0-9]+\\)>\\(.+\\)</a> (\\(.*\\)) ")
 
+;;;###autoload
 (defun mixi-get-new-diaries (&optional range)
   "Get new diaries."
   (let ((items (mixi-get-matched-items (mixi-new-diary-list-page)
                                       mixi-new-diary-list-regexp
                                       range)))
     (mapcar (lambda (item)
-             (mixi-make-diary (mixi-make-friend (nth 1 item)) (nth 0 item)))
+             (mixi-make-diary (mixi-make-friend (nth 6 item) (nth 8 item))
+                              (nth 5 item)
+                              nil
+                              (encode-time
+                               0 (string-to-number (nth 4 item))
+                               (string-to-number (nth 3 item))
+                               (string-to-number (nth 2 item))
+                               (string-to-number (nth 1 item))
+                               (string-to-number (nth 0 item)))
+                              (nth 7 item)))
            items)))
 
 (defmacro mixi-search-diary-list-page (keyword)
   `(concat "/search_diary.pl?page=%d&submit=search&keyword="
-            (mixi-url-encode-and-quote-percent-string keyword)))
+            (mixi-url-encode-and-quote-percent-string ,keyword)))
 
 (defconst mixi-search-diary-list-regexp
-  "<a href=\"view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=\\([0-9]+\\)\">")
+  "<td BGCOLOR=#FDF9F2><font COLOR=#996600>̾&nbsp;&nbsp;Á°</font></td>
+<td COLSPAN=2 BGCOLOR=#FFFFFF>\\(.*\\)
+
+</td></tr>
+
+<tr>
+<td BGCOLOR=#FDF9F2><font COLOR=#996600>¥¿¥¤¥È¥ë</font></td>
+<td COLSPAN=2 BGCOLOR=#FFFFFF>\\(.+\\)</td></tr>
+
+<tr>
+<td BGCOLOR=#FDF9F2><font COLOR=#996600>ËÜ&nbsp;&nbsp;ʸ</font></td>
+<td COLSPAN=2 BGCOLOR=#FFFFFF width=\"380\">\\(.*\\)</td></tr>
+
+
+<tr>
+<td NOWRAP BGCOLOR=#FDF9F2 WIDTH=80><font COLOR=#996600>ºîÀ®Æü»þ</font></td>
+<td BGCOLOR=#FFFFFF WIDTH=220>\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</td>
+<td ALIGN=center BGCOLOR=#FDF9F2 width=250><a href=\"view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=\\([0-9]+\\)\"><img src=http://img\\.mixi\\.jp/img/shbtn\\.gif ALT=¾ÜºÙ¤ò¸«¤ë BORDER=0 WIDTH=104 HEIGHT=19></a></td></tr>
+</table>
+</td></tr></table>")
 
+;;;###autoload
 (defun mixi-search-diaries (keyword &optional range)
   (let ((items (mixi-get-matched-items (mixi-search-diary-list-page keyword)
                                       mixi-search-diary-list-regexp
-                                      range)))
+                                      range))
+       (year (nth 5 (decode-time (current-time))))
+       (month (nth 4 (decode-time (current-time)))))
     (mapcar (lambda (item)
-             (mixi-make-diary (mixi-make-friend (nth 1 item)) (nth 0 item)))
+               (let ((month-of-item (string-to-number (nth 3 item))))
+                 (when (> month-of-item month)
+                   (decf year))
+                 (setq month month-of-item)
+                 (mixi-make-diary (mixi-make-friend (nth 8 item) (nth 0 item))
+                                  (nth 7 item)
+                                  nil
+                                  (encode-time
+                                   0 (string-to-number (nth 6 item))
+                                   (string-to-number (nth 5 item))
+                                   (string-to-number (nth 4 item))
+                                   month year)
+                                  (nth 1 item)
+                                  (nth 2 item))))
            items)))
 
+(defmacro mixi-post-diary-page ()
+  `(concat "/add_diary.pl"))
+
+(defconst mixi-post-key-regexp
+  "<input type=\"?hidden\"? name=\"?post_key\"? +value=\"\\([a-z0-9]+\\)\"")
+(defconst mixi-post-succeed-regexp
+  "<b>\\(ºîÀ®\\|½ñ¤­¹þ¤ß\\)¤¬´°Î»¤·¤Þ¤·¤¿¡£È¿±Ç¤Ë»þ´Ö¤¬¤«¤«¤ë¤³¤È¤¬¤¢¤ê¤Þ¤¹¤Î¤Ç¡¢É½¼¨¤µ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ï¾¯¡¹¤ªÂÔ¤Á¤¯¤À¤µ¤¤¡£</b>")
+
+;; FIXME: Support photos.
+;;;###autoload
+(defun mixi-post-diary (title content)
+  "Post a diary."
+  (unless (stringp title)
+    (signal 'wrong-type-argument (list 'stringp title)))
+  (unless (stringp content)
+    (signal 'wrong-type-argument (list 'stringp content)))
+  (let ((fields `(("id" . ,(mixi-friend-id (mixi-make-me)))
+                 ("diary_title" . ,title)
+                 ("diary_body" . ,content)
+                 ("submit" . "main")))
+       post-key)
+    (with-mixi-post-form (mixi-post-diary-page) fields
+      (if (re-search-forward mixi-post-key-regexp nil t)
+         (setq post-key (match-string 1))
+       (mixi-post-error 'cannot-find-key)))
+    (setq fields `(("post_key" . ,post-key)
+                  ("id" . ,(mixi-friend-id (mixi-make-me)))
+                  ("diary_title" . ,title)
+                  ("diary_body" . ,content)
+                  ("submit" . "confirm")))
+    (with-mixi-post-form (mixi-post-diary-page) fields
+      (unless (re-search-forward mixi-post-succeed-regexp nil t)
+       (mixi-post-error 'cannot-find-succeed)))))
+
 ;; Community object.
 (defvar mixi-community-cache (make-hash-table :test 'equal))
 (defun mixi-make-community (id &optional name birthday owner category members
@@ -1204,65 +1458,83 @@ Increase this value when unexpected error frequently occurs."
 (defconst mixi-community-nodata-regexp
   "^¥Ç¡¼¥¿¤¬¤¢¤ê¤Þ¤»¤ó")
 (defconst mixi-community-name-regexp
-  "<td WIDTH=345>\\(.*\\)</td></tr>")
+  "<td width=\"?345\"?>\\(.*\\)</td></tr>")
 (defconst mixi-community-birthday-regexp
-  "<td BGCOLOR=#F2DDB7><font COLOR=#996600>³«ÀßÆü</font></td>\n<td>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü</td>")
+  "<td bgcolor=\"?#F2DDB7\"? width=\"?80\"?><font color=\"?#996600\"?>³«ÀßÆü</font></td>
+<td width=\"?345\"?>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü")
 ;; FIXME: Care when the owner has seceded.
 (defconst mixi-community-owner-regexp
-  "<td BGCOLOR=#F2DDB7><font COLOR=#996600>´ÉÍý¿Í</font></td>\n<td>\n\n<a href=\"\\(home\\.pl\\|show_friend\\.pl\\?id=\\([0-9]+\\)\\)\">\n\\(.*\\)</a>")
+  "<td bgcolor=\"?#F2DDB7\"? width=\"?80\"?><font color=\"?#996600\"?>´ÉÍý¿Í</font></td>
+<td width=\"?345\"?>
+<table style=\"width: 100%;\"><tr><td>
+<a href=\"\\(home\\.pl\\|show_friend\\.pl\\?id=\\([0-9]+\\)\\)\">\\(.*\\)</a>")
 (defconst mixi-community-category-regexp
-  "<td BGCOLOR=#F2DDB7><font COLOR=#996600>¥«¥Æ¥´¥ê</font></td>\n<td>\\([^<]+\\)</td>")
+  "<td bgcolor=\"?#F2DDB7\"? width=\"?80\"?><font color=\"?#996600\"?>¥«¥Æ¥´¥ê</font></td>
+<td width=\"?345\"?>
+\\(.+\\)
+</td>")
 (defconst mixi-community-members-regexp
-  "<td BGCOLOR=#F2DDB7><font COLOR=#996600>¥á¥ó¥Ð¡¼¿ô</font></td>\n<td>\\([0-9]+\\)¿Í</td></tr>")
+  "<td bgcolor=\"?#F2DDB7\"? width=\"?80\"?><font color=\"?#996600\"?>¥á¥ó¥Ð¡¼¿ô</font></td>
+<td width=\"?345\"?>
+\\([0-9]+\\)¿Í
+</td>")
 (defconst mixi-community-open-level-regexp
-  "<td BGCOLOR=#F2DDB7><font COLOR=#996600>»²²Ã¾ò·ï¤È<br>¸ø³«¥ì¥Ù¥ë</font></td>
-<td>\\(.+\\)</td></tr>")
+  "<td bgcolor=\"?#F2DDB7\"? width=\"?80\"?><font color=\"?#996600\"?>»²²Ã¾ò·ï¤È<br />¸ø³«¥ì¥Ù¥ë</font></td>
+<td width=\"?345\"?>
+\\(.+\\)
+</td>")
 (defconst mixi-community-authority-regexp
-  "<td BGCOLOR=#F2DDB7><font COLOR=#996600>¥È¥Ô¥Ã¥¯ºîÀ®¤Î¸¢¸Â</font></td>\n<td>\\(.+\\)</td></tr>")
+  "<td bgcolor=\"?#F2DDB7\"? width=\"?80\"?><font color=\"?#996600\"?>¥È¥Ô¥Ã¥¯ºîÀ®¤Î¸¢¸Â</font></td>
+<td width=\"?345\"?>
+\\(.+\\)
+
+
+</td>")
 (defconst mixi-community-description-regexp
-  "<td CLASS=h120>\\(.+\\)</td>")
+  "<td class=\"?h120\"? width=\"?345\"?>\\(.+\\)</td>")
 
-(defun mixi-community-realize (community)
+(defun mixi-realize-community (community)
   "Realize a COMMUNITY."
   ;; FIXME: Check a expiration of cache?
-  (unless (mixi-object-realize-p community)
+  (unless (mixi-object-realized-p community)
     (with-mixi-retrieve (mixi-community-page community)
-      (if (string-match mixi-community-nodata-regexp buffer)
-         ;; FIXME: Set all members?
-         (mixi-community-set-name community "¥Ç¡¼¥¿¤¬¤¢¤ê¤Þ¤»¤ó")
-       (if (string-match mixi-community-name-regexp buffer)
-           (mixi-community-set-name community (match-string 1 buffer))
-         (signal 'error (list 'cannot-find-name community)))
-       (if (string-match mixi-community-birthday-regexp buffer)
-           (mixi-community-set-birthday
-            community
-            (encode-time 0 0 0 (string-to-number (match-string 3 buffer))
-                         (string-to-number (match-string 2 buffer))
-                         (string-to-number (match-string 1 buffer))))
-         (signal 'error (list 'cannot-find-birthday community)))
-       (if (string-match mixi-community-owner-regexp buffer)
-           (if (string= (match-string 1 buffer) "home.pl")
-               (mixi-community-set-owner community (mixi-make-me))
-             (mixi-community-set-owner
-              community (mixi-make-friend (match-string 2 buffer)
-                                          (match-string 3 buffer))))
-         (signal 'error (list 'cannot-find-owner community)))
-       (if (string-match mixi-community-category-regexp buffer)
-           (mixi-community-set-category community (match-string 1 buffer))
-         (signal 'error (list 'cannot-find-category community)))
-       (if (string-match mixi-community-members-regexp buffer)
-           (mixi-community-set-members
-            community (string-to-number (match-string 1 buffer)))
-         (signal 'error (list 'cannot-find-members community)))
-       (if (string-match mixi-community-open-level-regexp buffer)
-           (mixi-community-set-open-level community (match-string 1 buffer))
-         (signal 'error (list 'cannot-find-open-level community)))
-       (if (string-match mixi-community-authority-regexp buffer)
-           (mixi-community-set-authority community (match-string 1 buffer))
-         (signal 'error (list 'cannot-find-authority community)))
-       (if (string-match mixi-community-description-regexp buffer)
-           (mixi-community-set-description community (match-string 1 buffer))
-         (signal 'error (list 'cannot-find-description community)))))
+      (let ((case-fold-search t))
+       (if (re-search-forward mixi-community-nodata-regexp nil t)
+           ;; FIXME: Set all members?
+           (mixi-community-set-name community "¥Ç¡¼¥¿¤¬¤¢¤ê¤Þ¤»¤ó")
+         (if (re-search-forward mixi-community-name-regexp nil t)
+             (mixi-community-set-name community (match-string 1))
+           (mixi-realization-error 'cannot-find-name community))
+         (if (re-search-forward mixi-community-birthday-regexp nil t)
+             (mixi-community-set-birthday
+              community (encode-time 0 0 0
+                                     (string-to-number (match-string 3))
+                                     (string-to-number (match-string 2))
+                                     (string-to-number (match-string 1))))
+           (mixi-realization-error 'cannot-find-birthday community))
+         (if (re-search-forward mixi-community-owner-regexp nil t)
+             (if (string= (match-string 1) "home.pl")
+                 (mixi-community-set-owner community (mixi-make-me))
+               (mixi-community-set-owner community (mixi-make-friend
+                                                    (match-string 2)
+                                                    (match-string 3))))
+           (mixi-realization-error 'cannot-find-owner community))
+         (if (re-search-forward mixi-community-category-regexp nil t)
+             (mixi-community-set-category community (match-string 1))
+           (mixi-realization-error 'cannot-find-category community))
+         (if (re-search-forward mixi-community-members-regexp nil t)
+             (mixi-community-set-members community
+                                         (string-to-number (match-string 1)))
+           (mixi-realization-error 'cannot-find-members community))
+         (if (re-search-forward mixi-community-open-level-regexp nil t)
+             (mixi-community-set-open-level community (match-string 1))
+           (mixi-realization-error 'cannot-find-open-level community))
+         (if (re-search-forward mixi-community-authority-regexp nil t)
+             (mixi-community-set-authority community (match-string 1))
+           (mixi-realization-error 'cannot-find-authority community))
+         (if (re-search-forward mixi-community-description-regexp nil t)
+             (mixi-community-set-description community (match-string 1))
+           (mixi-realization-error 'cannot-find-description community)))))
     (mixi-object-touch community)))
 
 (defun mixi-community-id (community)
@@ -1276,56 +1548,56 @@ Increase this value when unexpected error frequently occurs."
   (unless (mixi-community-p community)
     (signal 'wrong-type-argument (list 'mixi-community-p community)))
   (unless (aref (cdr community) 2)
-    (mixi-community-realize community))
+    (mixi-realize-community community))
   (aref (cdr community) 2))
 
 (defun mixi-community-birthday (community)
   "Return the birthday of COMMUNITY."
   (unless (mixi-community-p community)
     (signal 'wrong-type-argument (list 'mixi-community-p community)))
-  (mixi-community-realize community)
+  (mixi-realize-community community)
   (aref (cdr community) 3))
 
 (defun mixi-community-owner (community)
   "Return the owner of COMMUNITY."
   (unless (mixi-community-p community)
     (signal 'wrong-type-argument (list 'mixi-community-p community)))
-  (mixi-community-realize community)
+  (mixi-realize-community community)
   (aref (cdr community) 4))
 
 (defun mixi-community-category (community)
   "Return the category of COMMUNITY."
   (unless (mixi-community-p community)
     (signal 'wrong-type-argument (list 'mixi-community-p community)))
-  (mixi-community-realize community)
+  (mixi-realize-community community)
   (aref (cdr community) 5))
 
 (defun mixi-community-members (community)
   "Return the members of COMMUNITY."
   (unless (mixi-community-p community)
     (signal 'wrong-type-argument (list 'mixi-community-p community)))
-  (mixi-community-realize community)
+  (mixi-realize-community community)
   (aref (cdr community) 6))
 
 (defun mixi-community-open-level (community)
   "Return the open-level of COMMUNITY."
   (unless (mixi-community-p community)
     (signal 'wrong-type-argument (list 'mixi-community-p community)))
-  (mixi-community-realize community)
+  (mixi-realize-community community)
   (aref (cdr community) 7))
 
 (defun mixi-community-authority (community)
   "Return the authority of COMMUNITY."
   (unless (mixi-community-p community)
     (signal 'wrong-type-argument (list 'mixi-community-p community)))
-  (mixi-community-realize community)
+  (mixi-realize-community community)
   (aref (cdr community) 8))
 
 (defun mixi-community-description (community)
   "Return the description of COMMUNITY."
   (unless (mixi-community-p community)
     (signal 'wrong-type-argument (list 'mixi-community-p community)))
-  (mixi-community-realize community)
+  (mixi-realize-community community)
   (aref (cdr community) 9))
 
 (defun mixi-community-set-name (community name)
@@ -1383,20 +1655,21 @@ Increase this value when unexpected error frequently occurs."
           (when ,friend (concat "&id=" (mixi-friend-id ,friend)))))
 
 (defconst mixi-community-list-id-regexp
-  "<a href=view_community\\.pl\\?id=\\([0-9]+\\)")
+  "<a href=\"?view_community\\.pl\\?id=\\([0-9]+\\)\"?")
 (defconst mixi-community-list-name-regexp
-  "<td valign=middle>\\(.+\\)([0-9]+)</td>")
+  "<td valign=\"?top\"?>\\(.+\\)([0-9]+)")
 
-(defun mixi-get-communities (&rest args)
+;;;###autoload
+(defun mixi-get-communities (&rest friend-or-range)
   "Get communities of FRIEND."
-  (when (> (length args) 2)
+  (when (> (length friend-or-range) 2)
     (signal 'wrong-number-of-arguments
-           (list 'mixi-get-communities (length args))))
-  (let ((friend (nth 0 args))
-       (range (nth 1 args)))
+           (list 'mixi-get-communities (length friend-or-range))))
+  (let ((friend (nth 0 friend-or-range))
+       (range (nth 1 friend-or-range)))
     (when (or (not (mixi-friend-p friend)) (mixi-friend-p range))
-      (setq friend (nth 1 args))
-      (setq range (nth 0 args)))
+      (setq friend (nth 1 friend-or-range))
+      (setq range (nth 0 friend-or-range)))
     (unless (or (null friend) (mixi-friend-p friend))
       (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
     (let ((ids (mixi-get-matched-items (mixi-community-list-page friend)
@@ -1415,7 +1688,7 @@ Increase this value when unexpected error frequently occurs."
 
 (defmacro mixi-search-community-list-page (keyword)
   `(concat "/search_community.pl?page=%d&&sort=date&type=com&submit=main"
-          "&keyword=" (mixi-url-encode-and-quote-percent-string keyword)
+          "&keyword=" (mixi-url-encode-and-quote-percent-string ,keyword)
           "&category_id=0"))
 
 (defconst mixi-search-community-list-regexp
@@ -1424,6 +1697,7 @@ Increase this value when unexpected error frequently occurs."
 <td COLSPAN=2 WIDTH=370 BGCOLOR=#FFFFFF>\\([^<]+\\)</td></tr>")
 
 ;; FIXME: Support category.
+;;;###autoload
 (defun mixi-search-communities (keyword &optional range)
   (let ((items (mixi-get-matched-items (mixi-search-community-list-page
                                        keyword)
@@ -1435,22 +1709,24 @@ Increase this value when unexpected error frequently occurs."
 
 ;; Topic object.
 (defvar mixi-topic-cache (make-hash-table :test 'equal))
-(defun mixi-make-topic (community id &optional time title owner content)
+(defun mixi-make-topic (community id &optional comment-count time title owner
+                                 content)
   "Return a topic object."
   (mixi-make-cache (list (mixi-community-id community) id)
-                  (cons 'mixi-topic (vector nil community id time title owner
-                                            content))
+                  (cons 'mixi-topic (vector nil community id comment-count
+                                            time title owner content))
                   mixi-topic-cache))
 
 (defconst mixi-topic-url-regexp
-  "/view_bbs\\.pl\\?id=\\([0-9]+\\)\\(&comment_count=[0-9]+\\)?&comm_id=\\([0-9]+\\)")
+  "/view_bbs\\.pl\\?id=\\([0-9]+\\)\\(&comment_count=\\([0-9]+\\)\\)?&comm_id=\\([0-9]+\\)")
 
 (defun mixi-make-topic-from-url (url)
   "Return a topic object from URL."
   (when (string-match mixi-topic-url-regexp url)
     (let ((id (match-string 1 url))
-         (community-id (match-string 3 url)))
-      (mixi-make-topic (mixi-make-community community-id) id))))
+         (comment-count (match-string 3 url))
+         (community-id (match-string 4 url)))
+      (mixi-make-topic (mixi-make-community community-id) id comment-count))))
 
 (defmacro mixi-topic-p (topic)
   `(eq (mixi-object-class ,topic) 'mixi-topic))
@@ -1459,6 +1735,8 @@ Increase this value when unexpected error frequently occurs."
   `(concat "/view_bbs.pl?id=" (mixi-topic-id ,topic)
           "&comm_id=" (mixi-community-id (mixi-topic-community ,topic))))
 
+(defconst mixi-topic-community-regexp
+  "<td width=\"595\" background=\"http://img\\.mixi\\.jp/img/bg_w\\.gif\"><b>\\[\\(.+\\)\\] ¥È¥Ô¥Ã¥¯</b></td>")
 (defconst mixi-topic-time-regexp
   "<td rowspan=\"3\" width=\"110\" bgcolor=\"#ffd8b0\" align=\"center\" valign=\"top\" nowrap>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü<br>\\([0-9]+\\):\\([0-9]+\\)</td>")
 (defconst mixi-topic-title-regexp
@@ -1466,32 +1744,35 @@ Increase this value when unexpected error frequently occurs."
 (defconst mixi-topic-owner-regexp
   "<td bgcolor=\"#fdf9f2\">&nbsp;<font color=\"#dfb479\"></font>&nbsp;<a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*?\\)\\(¤µ¤ó\\)?</a>")
 (defconst mixi-topic-content-regexp
-  "<table width=\"500\" border=\"0\" cellspacing=\"0\" cellpadding=\"5\"><tr><td class=\"h120\"><table><tr>\\(<td width=\"130\" height=\"140\" align=\"center\" valign=\"middle\"><a href=\"javascript:void(0)\" onClick=\"MM_openBrWindow('show_bbs_picture\\.pl\\?id=[0-9]+&number=[0-9]+','pict','width=680,height=660,toolbar=no,scrollbars=yes,left=5,top=5')\"><img src=\"http://ic[0-9]+\\.mixi\\.jp/[^.]+\\.jpg\" border=\"0\"></a></td>\n\\)*</tr></table>\\(.+\\)</td></tr></table>")
+  "<table width=\"500\" border=\"0\" cellspacing=\"0\" cellpadding=\"5\"><tr><td class=\"h120\" width=\"500\"><table><tr>\\(\\(.\\|\r?\n\\)*?\\)</td></tr></table>")
 
-(defun mixi-topic-realize (topic)
+(defun mixi-realize-topic (topic &optional page)
   "Realize a TOPIC."
   ;; FIXME: Check a expiration of cache?
-  (unless (mixi-object-realize-p topic)
-    (with-mixi-retrieve (mixi-topic-page topic)
-      (if (string-match mixi-topic-time-regexp buffer)
+  (unless (mixi-object-realized-p topic)
+    (with-mixi-retrieve (or page (mixi-topic-page topic))
+      (if (re-search-forward mixi-topic-community-regexp nil t)
+         (mixi-community-set-name (mixi-topic-community topic)
+                                  (match-string 1))
+       (mixi-realization-error 'cannot-find-community topic))
+      (if (re-search-forward mixi-topic-time-regexp nil t)
          (mixi-topic-set-time
-          topic (encode-time 0 (string-to-number (match-string 5 buffer))
-                             (string-to-number (match-string 4 buffer))
-                             (string-to-number (match-string 3 buffer))
-                             (string-to-number (match-string 2 buffer))
-                             (string-to-number (match-string 1 buffer))))
-       (signal 'error (list 'cannot-find-time topic)))
-      (if (string-match mixi-topic-title-regexp buffer)
-         (mixi-topic-set-title topic (match-string 1 buffer))
-       (signal 'error (list 'cannot-find-title topic)))
-      (if (string-match mixi-topic-owner-regexp buffer)
-         (mixi-topic-set-owner topic
-                               (mixi-make-friend (match-string 1 buffer)
-                                                 (match-string 2 buffer)))
-       (signal 'error (list 'cannot-find-owner topic)))
-      (if (string-match mixi-topic-content-regexp buffer)
-         (mixi-topic-set-content topic (match-string 2 buffer))
-       (signal 'error (list 'cannot-find-content topic))))
+          topic (encode-time 0 (string-to-number (match-string 5))
+                             (string-to-number (match-string 4))
+                             (string-to-number (match-string 3))
+                             (string-to-number (match-string 2))
+                             (string-to-number (match-string 1))))
+       (mixi-realization-error 'cannot-find-time topic))
+      (if (re-search-forward mixi-topic-title-regexp nil t)
+         (mixi-topic-set-title topic (match-string 1))
+       (mixi-realization-error 'cannot-find-title topic))
+      (if (re-search-forward mixi-topic-owner-regexp nil t)
+         (mixi-topic-set-owner topic (mixi-make-friend (match-string 1)
+                                                       (match-string 2)))
+       (mixi-realization-error 'cannot-find-owner topic))
+      (if (re-search-forward mixi-topic-content-regexp nil t)
+         (mixi-topic-set-content topic (match-string 1))
+       (mixi-realization-error 'cannot-find-content topic)))
     (mixi-object-touch topic)))
 
 (defun mixi-topic-community (topic)
@@ -1506,45 +1787,57 @@ Increase this value when unexpected error frequently occurs."
     (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
   (aref (cdr topic) 2))
 
+(defun mixi-topic-comment-count (topic)
+  "Return the comment-count of TOPIC."
+  (unless (mixi-topic-p topic)
+    (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
+  (aref (cdr topic) 3))
+
 (defun mixi-topic-time (topic)
   "Return the time of TOPIC."
   (unless (mixi-topic-p topic)
     (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
-  (mixi-topic-realize topic)
-  (aref (cdr topic) 3))
+  (mixi-realize-topic topic)
+  (aref (cdr topic) 4))
 
 (defun mixi-topic-title (topic)
   "Return the title of TOPIC."
   (unless (mixi-topic-p topic)
     (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
-  (mixi-topic-realize topic)
-  (aref (cdr topic) 4))
+  (mixi-realize-topic topic)
+  (aref (cdr topic) 5))
 
 (defun mixi-topic-owner (topic)
   "Return the owner of TOPIC."
   (unless (mixi-topic-p topic)
     (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
-  (mixi-topic-realize topic)
-  (aref (cdr topic) 5))
+  (mixi-realize-topic topic)
+  (aref (cdr topic) 6))
 
 (defun mixi-topic-content (topic)
   "Return the content of TOPIC."
   (unless (mixi-topic-p topic)
     (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
-  (mixi-topic-realize topic)
-  (aref (cdr topic) 6))
+  (mixi-realize-topic topic)
+  (aref (cdr topic) 7))
+
+(defun mixi-topic-set-comment-count (topic comment-count)
+  "Set the comment-count of TOPIC."
+  (unless (mixi-topic-p topic)
+    (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
+  (aset (cdr topic) 3 comment-count))
 
 (defun mixi-topic-set-time (topic time)
   "Set the time of TOPIC."
   (unless (mixi-topic-p topic)
     (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
-  (aset (cdr topic) 3 time))
+  (aset (cdr topic) 4 time))
 
 (defun mixi-topic-set-title (topic title)
   "Set the title of TOPIC."
   (unless (mixi-topic-p topic)
     (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
-  (aset (cdr topic) 4 title))
+  (aset (cdr topic) 5 title))
 
 (defun mixi-topic-set-owner (topic owner)
   "Set the owner of TOPIC."
@@ -1552,33 +1845,64 @@ Increase this value when unexpected error frequently occurs."
     (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
   (unless (mixi-friend-p owner)
     (signal 'wrong-type-argument (list 'mixi-friend-p owner)))
-  (aset (cdr topic) 5 owner))
+  (aset (cdr topic) 6 owner))
 
 (defun mixi-topic-set-content (topic content)
   "Set the content of TOPIC."
   (unless (mixi-topic-p topic)
     (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
-  (aset (cdr topic) 6 content))
+  (aset (cdr topic) 7 content))
+
+(defmacro mixi-post-topic-page (community)
+  `(concat "/add_bbs.pl?id=" (mixi-community-id community)))
+
+;; FIXME: Support photos.
+;;;###autoload
+(defun mixi-post-topic (community title content)
+  "Post a topic to COMMUNITY."
+  (unless (mixi-community-p community)
+    (signal 'wrong-type-argument (list 'mixi-community-p community)))
+  (unless (stringp title)
+    (signal 'wrong-type-argument (list 'stringp title)))
+  (unless (stringp content)
+    (signal 'wrong-type-argument (list 'stringp content)))
+  (let ((fields `(("bbs_title" . ,title)
+                 ("bbs_body" . ,content)
+                 ("submit" . "main")))
+       post-key)
+    (with-mixi-post-form (mixi-post-topic-page community) fields
+      (if (re-search-forward mixi-post-key-regexp nil t)
+         (setq post-key (match-string 1))
+       (mixi-post-error 'cannot-find-key community)))
+    (setq fields `(("post_key" . ,post-key)
+                  ("bbs_title" . ,title)
+                  ("bbs_body" . ,content)
+                  ("submit" . "confirm")))
+    (with-mixi-post-form (mixi-post-topic-page community) fields
+      (unless (re-search-forward mixi-post-succeed-regexp nil t)
+       (mixi-post-error 'cannot-find-succeed community)))))
 
 ;; Event object.
 (defvar mixi-event-cache (make-hash-table :test 'equal))
-(defun mixi-make-event (community id &optional time title owner date place
-                                 detail limit members)
+(defun mixi-make-event (community id &optional comment-count time title owner
+                                 date place detail limit members)
   "Return a event object."
   (mixi-make-cache (list (mixi-community-id community) id)
-                  (cons 'mixi-event (vector nil community id time title owner
-                                            date place detail limit members))
+                  (cons 'mixi-event (vector nil community id comment-count
+                                            time title owner date place
+                                            detail limit members))
                   mixi-event-cache))
 
 (defconst mixi-event-url-regexp
-  "/view_event\\.pl\\?id=\\([0-9]+\\)\\(&comment_count=[0-9]+\\)?&comm_id=\\([0-9]+\\)")
+  "/view_event\\.pl\\?id=\\([0-9]+\\)\\(&comment_count=\\([0-9]+\\)\\)?&comm_id=\\([0-9]+\\)")
 
 (defun mixi-make-event-from-url (url)
   "Return a event object from URL."
   (when (string-match mixi-event-url-regexp url)
     (let ((id (match-string 1 url))
-         (community-id (match-string 3 url)))
-      (mixi-make-event (mixi-make-community community-id) id))))
+         (comment-count (match-string 3 url))
+         (community-id (match-string 4 url)))
+      (mixi-make-event (mixi-make-community community-id) id comment-count))))
 
 (defmacro mixi-event-p (event)
   `(eq (mixi-object-class ,event) 'mixi-event))
@@ -1587,75 +1911,91 @@ Increase this value when unexpected error frequently occurs."
   `(concat "/view_event.pl?id=" (mixi-event-id ,event)
           "&comm_id=" (mixi-community-id (mixi-event-community ,event))))
 
+(defconst mixi-event-community-regexp
+  "<td width=\"?595\"? background=\"?http://img\\.mixi\\.jp/img/bg_w\\.gif\"?><b>\\[\\(.+\\)\\] ¥¤¥Ù¥ó¥È</b></td>")
 (defconst mixi-event-time-regexp
-  "<td ROWSPAN=11 BGCOLOR=#FFD8B0 ALIGN=center VALIGN=top WIDTH=110>
-\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü<br>
-\\([0-9]+\\):\\([0-9]+\\)</td>")
+  "<td rowspan=\"?11\"? bgcolor=\"?#FFD8B0\"? align=\"?center\"? valign=\"?top\"? width=\"?110\"?>
+?\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü<br>
+?\\([0-9]+\\):\\([0-9]+\\)
+</td>")
 (defconst mixi-event-title-regexp
-  "<td bgcolor=#FFF4E0 width=410>&nbsp;\\([^<]+\\)</td>")
+  "<td bgcolor=\"?#FFF4E0\"?\\( width=\"?410\"?\\)?>&nbsp;\\([^<]+\\)</td>")
 (defconst mixi-event-owner-regexp
-  "<td BGCOLOR=#FDF9F2>&nbsp;<a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a>")
+  "<td bgcolor=\"?#FDF9F2\"?>&nbsp;<a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a>")
+(defconst mixi-event-owner-seceded-regexp
+  "<td bgcolor=\"?#FDF9F2\"?>&nbsp;\\((mixi Âà²ñºÑ)\\)")
 (defconst mixi-event-date-regexp
-  "<td BGCOLOR=#FFFFFF ALIGN=center NOWRAP>³«ºÅÆü»þ</td>
-<td BGCOLOR=#FFFFFF>
+  "<td bgcolor=\"?#FFFFFF\"? align=\"?center\"? nowrap>³«ºÅÆü»þ</td>
+<td bgcolor=\"?#FFFFFF\"?>
 &nbsp;\\(.+\\)
 </td>")
 (defconst mixi-event-place-regexp
-  "<td BGCOLOR=#FFFFFF ALIGN=center NOWRAP>³«ºÅ¾ì½ê</td>
-<td BGCOLOR=#FFFFFF>
+  "<td bgcolor=\"?#FFFFFF\"? align=\"?center\"? nowrap>³«ºÅ¾ì½ê</td>
+<td bgcolor=\"?#FFFFFF\"?>
 &nbsp;\\(.+\\)
 </td>")
 (defconst mixi-event-detail-regexp
-  "<td BGCOLOR=#FFFFFF ALIGN=center NOWRAP>¾ÜºÙ</td>
-<td BGCOLOR=#FFFFFF><table BORDER=0 CELLSPACING=0 CELLPADDING=5><tr><td CLASS=h120>\\(.+\\)</td></tr></table></td>")
+  "<td bgcolor=\"?#FFFFFF\"? align=\"?center\"? nowrap>¾ÜºÙ</td>
+<td bgcolor=\"?#FFFFFF\"? class=\"?h120\"? width=\"?410\"?>
+<div style=\"?padding:5px\"?>\\(\\(.\\|\r?\n\\)*?\\)</div>")
 (defconst mixi-event-limit-regexp
-  "<td BGCOLOR=#FFFFFF ALIGN=center NOWRAP>Ê罸´ü¸Â</td>
-<td BGCOLOR=#FFFFFF>&nbsp;\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü</td>")
+  "<td bgcolor=\"?#FFFFFF\"? align=\"?center\"? nowrap>Ê罸´ü¸Â</td>
+?<td bgcolor=\"?#FFFFFF\"?>&nbsp;\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü</td>")
 (defconst mixi-event-members-regexp
-  "<td BGCOLOR=#FFFFFF ALIGN=center NOWRAP>»²²Ã¼Ô</td>
-<td BGCOLOR=#FFFFFF>
-<table BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=100%>
+  "<td bgcolor=\"?#FFFFFF\"? align=\"?center\"? nowrap>»²²Ã¼Ô</td>
+<td bgcolor=\"?#FFFFFF\"?>
+
+?
+?<table border=\"?0\"? cellspacing=\"?0\"? cellpadding=\"?0\"? width=\"?100%\"?>
 <tr>
-<td>&nbsp;\\(.+\\)</td>")
 
-(defun mixi-event-realize (event)
+?<td>&nbsp;\\(.+\\)</td>")
+
+(defun mixi-realize-event (event &optional page)
   "Realize a EVENT."
   ;; FIXME: Check a expiration of cache?
-  (unless (mixi-object-realize-p event)
-    (with-mixi-retrieve (mixi-event-page event)
-      (if (string-match mixi-event-time-regexp buffer)
-         (mixi-event-set-time
-          event (encode-time 0 (string-to-number (match-string 5 buffer))
-                             (string-to-number (match-string 4 buffer))
-                             (string-to-number (match-string 3 buffer))
-                             (string-to-number (match-string 2 buffer))
-                             (string-to-number (match-string 1 buffer))))
-       (signal 'error (list 'cannot-find-time event)))
-      (if (string-match mixi-event-title-regexp buffer)
-         (mixi-event-set-title event (match-string 1 buffer))
-       (signal 'error (list 'cannot-find-title event)))
-      (if (string-match mixi-event-owner-regexp buffer)
-         (mixi-event-set-owner event
-                               (mixi-make-friend (match-string 1 buffer)
-                                                 (match-string 2 buffer)))
-       (signal 'error (list 'cannot-find-owner event)))
-      (if (string-match mixi-event-date-regexp buffer)
-         (mixi-event-set-date event (match-string 1 buffer))
-       (signal 'error (list 'cannot-find-date event)))
-      (if (string-match mixi-event-place-regexp buffer)
-         (mixi-event-set-place event (match-string 1 buffer))
-       (signal 'error (list 'cannot-find-place event)))
-      (if (string-match mixi-event-detail-regexp buffer)
-         (mixi-event-set-detail event (match-string 1 buffer))
-       (signal 'error (list 'cannot-find-detail event)))
-      (when (string-match mixi-event-limit-regexp buffer)
-       (mixi-event-set-limit
-        event (encode-time 0 0 0 (string-to-number (match-string 3 buffer))
-                           (string-to-number (match-string 2 buffer))
-                           (string-to-number (match-string 1 buffer)))))
-      (if (string-match mixi-event-members-regexp buffer)
-         (mixi-event-set-members event (match-string 1 buffer))
-       (signal 'error (list 'cannot-find-members event))))
+  (unless (mixi-object-realized-p event)
+    (with-mixi-retrieve (or page (mixi-event-page event))
+      (let ((case-fold-search t))
+       (if (re-search-forward mixi-event-community-regexp nil t)
+           (mixi-community-set-name (mixi-event-community event)
+                                    (match-string 1))
+         (mixi-realization-error 'cannot-find-community event))
+       (if (re-search-forward mixi-event-time-regexp nil t)
+           (mixi-event-set-time
+            event (encode-time 0 (string-to-number (match-string 5))
+                               (string-to-number (match-string 4))
+                               (string-to-number (match-string 3))
+                               (string-to-number (match-string 2))
+                               (string-to-number (match-string 1))))
+         (mixi-realization-error 'cannot-find-time event))
+       (if (re-search-forward mixi-event-title-regexp nil t)
+           (mixi-event-set-title event (match-string 2))
+         (mixi-realization-error 'cannot-find-title event))
+       (if (re-search-forward mixi-event-owner-regexp nil t)
+           (mixi-event-set-owner event (mixi-make-friend (match-string 1)
+                                                         (match-string 2)))
+         (if (re-search-forward mixi-event-owner-seceded-regexp nil t)
+             (mixi-event-set-owner event
+                                   (mixi-make-friend nil (match-string 1)))
+           (mixi-realization-error 'cannot-find-owner event)))
+       (if (re-search-forward mixi-event-date-regexp nil t)
+           (mixi-event-set-date event (match-string 1))
+         (mixi-realization-error 'cannot-find-date event))
+       (if (re-search-forward mixi-event-place-regexp nil t)
+           (mixi-event-set-place event (match-string 1))
+         (mixi-realization-error 'cannot-find-place event))
+       (if (re-search-forward mixi-event-detail-regexp nil t)
+           (mixi-event-set-detail event (match-string 1))
+         (mixi-realization-error 'cannot-find-detail event))
+       (when (re-search-forward mixi-event-limit-regexp nil t)
+         (mixi-event-set-limit
+          event (encode-time 0 0 0 (string-to-number (match-string 3))
+                             (string-to-number (match-string 2))
+                             (string-to-number (match-string 1)))))
+       (if (re-search-forward mixi-event-members-regexp nil t)
+           (mixi-event-set-members event (match-string 1))
+         (mixi-realization-error 'cannot-find-members event))))
     (mixi-object-touch event)))
 
 (defun mixi-event-community (event)
@@ -1670,73 +2010,85 @@ Increase this value when unexpected error frequently occurs."
     (signal 'wrong-type-argument (list 'mixi-event-p event)))
   (aref (cdr event) 2))
 
+(defun mixi-event-comment-count (event)
+  "Return the comment-count of EVENT."
+  (unless (mixi-event-p event)
+    (signal 'wrong-type-argument (list 'mixi-event-p event)))
+  (aref (cdr event) 3))
+
 (defun mixi-event-time (event)
   "Return the time of EVENT."
   (unless (mixi-event-p event)
     (signal 'wrong-type-argument (list 'mixi-event-p event)))
-  (mixi-event-realize event)
-  (aref (cdr event) 3))
+  (mixi-realize-event event)
+  (aref (cdr event) 4))
 
 (defun mixi-event-title (event)
   "Return the title of EVENT."
   (unless (mixi-event-p event)
     (signal 'wrong-type-argument (list 'mixi-event-p event)))
-  (mixi-event-realize event)
-  (aref (cdr event) 4))
+  (mixi-realize-event event)
+  (aref (cdr event) 5))
 
 (defun mixi-event-owner (event)
   "Return the owner of EVENT."
   (unless (mixi-event-p event)
     (signal 'wrong-type-argument (list 'mixi-event-p event)))
-  (mixi-event-realize event)
-  (aref (cdr event) 5))
+  (mixi-realize-event event)
+  (aref (cdr event) 6))
 
 (defun mixi-event-date (event)
   "Return the date of EVENT."
   (unless (mixi-event-p event)
     (signal 'wrong-type-argument (list 'mixi-event-p event)))
-  (mixi-event-realize event)
-  (aref (cdr event) 6))
+  (mixi-realize-event event)
+  (aref (cdr event) 7))
 
 (defun mixi-event-place (event)
   "Return the place of EVENT."
   (unless (mixi-event-p event)
     (signal 'wrong-type-argument (list 'mixi-event-p event)))
-  (mixi-event-realize event)
-  (aref (cdr event) 7))
+  (mixi-realize-event event)
+  (aref (cdr event) 8))
 
 (defun mixi-event-detail (event)
   "Return the detail of EVENT."
   (unless (mixi-event-p event)
     (signal 'wrong-type-argument (list 'mixi-event-p event)))
-  (mixi-event-realize event)
-  (aref (cdr event) 8))
+  (mixi-realize-event event)
+  (aref (cdr event) 9))
 
 (defun mixi-event-limit (event)
   "Return the limit of EVENT."
   (unless (mixi-event-p event)
     (signal 'wrong-type-argument (list 'mixi-event-p event)))
-  (mixi-event-realize event)
-  (aref (cdr event) 9))
+  (mixi-realize-event event)
+  (aref (cdr event) 10))
 
 (defun mixi-event-members (event)
   "Return the members of EVENT."
   (unless (mixi-event-p event)
     (signal 'wrong-type-argument (list 'mixi-event-p event)))
-  (mixi-event-realize event)
-  (aref (cdr event) 10))
+  (mixi-realize-event event)
+  (aref (cdr event) 11))
+
+(defun mixi-event-set-comment-count (event comment-count)
+  "Set the comment-count of EVENT."
+  (unless (mixi-event-p event)
+    (signal 'wrong-type-argument (list 'mixi-event-p event)))
+  (aset (cdr event) 3 comment-count))
 
 (defun mixi-event-set-time (event time)
   "Set the time of EVENT."
   (unless (mixi-event-p event)
     (signal 'wrong-type-argument (list 'mixi-event-p event)))
-  (aset (cdr event) 3 time))
+  (aset (cdr event) 4 time))
 
 (defun mixi-event-set-title (event title)
   "Set the title of EVENT."
   (unless (mixi-event-p event)
     (signal 'wrong-type-argument (list 'mixi-event-p event)))
-  (aset (cdr event) 4 title))
+  (aset (cdr event) 5 title))
 
 (defun mixi-event-set-owner (event owner)
   "Set the owner of EVENT."
@@ -1744,43 +2096,72 @@ Increase this value when unexpected error frequently occurs."
     (signal 'wrong-type-argument (list 'mixi-event-p event)))
   (unless (mixi-friend-p owner)
     (signal 'wrong-type-argument (list 'mixi-friend-p owner)))
-  (aset (cdr event) 5 owner))
+  (aset (cdr event) 6 owner))
 
 (defun mixi-event-set-date (event date)
   "Set the date of EVENT."
   (unless (mixi-event-p event)
     (signal 'wrong-type-argument (list 'mixi-event-p event)))
-  (aset (cdr event) 6 date))
+  (aset (cdr event) 7 date))
 
 (defun mixi-event-set-place (event place)
   "Set the place of EVENT."
   (unless (mixi-event-p event)
     (signal 'wrong-type-argument (list 'mixi-event-p event)))
-  (aset (cdr event) 7 place))
+  (aset (cdr event) 8 place))
 
 (defun mixi-event-set-detail (event detail)
   "Set the detail of EVENT."
   (unless (mixi-event-p event)
     (signal 'wrong-type-argument (list 'mixi-event-p event)))
-  (aset (cdr event) 8 detail))
+  (aset (cdr event) 9 detail))
 
 (defun mixi-event-set-limit (event limit)
   "Set the limit of EVENT."
   (unless (mixi-event-p event)
     (signal 'wrong-type-argument (list 'mixi-event-p event)))
-  (aset (cdr event) 9 limit))
+  (aset (cdr event) 10 limit))
 
 (defun mixi-event-set-members (event members)
   "Set the members of EVENT."
   (unless (mixi-event-p event)
     (signal 'wrong-type-argument (list 'mixi-event-p event)))
-  (aset (cdr event) 10 members))
+  (aset (cdr event) 11 members))
+
+;; BBS object.
+(defconst mixi-bbs-list '(mixi-topic mixi-event))
+
+(defmacro mixi-bbs-p (bbs)
+  `(memq (mixi-object-class ,bbs) mixi-bbs-list))
+
+(defun mixi-bbs-community (bbs)
+  "Return the community of BBS."
+  (unless (mixi-bbs-p bbs)
+    (signal 'wrong-type-argument (list 'mixi-bbs-p bbs)))
+  (let ((func (intern (concat mixi-object-prefix
+                             (mixi-object-name bbs) "-community"))))
+    (funcall func bbs)))
+
+(defun mixi-bbs-comment-count (bbs)
+  "Return the comment-count of BBS."
+  (unless (mixi-bbs-p bbs)
+    (signal 'wrong-type-argument (list 'mixi-bbs-p bbs)))
+  (let ((func (intern (concat mixi-object-prefix
+                             (mixi-object-name bbs) "-comment-count"))))
+    (funcall func bbs)))
+
+(defun mixi-bbs-set-comment-count (bbs count)
+  "Set the comment-count of BBS."
+  (unless (mixi-bbs-p bbs)
+    (signal 'wrong-type-argument (list 'mixi-bbs-p bbs)))
+  (let ((func (intern (concat mixi-object-prefix
+                             (mixi-object-name bbs) "-set-comment-count"))))
+    (funcall func bbs count)))
 
-;; Bbs object.
-(defalias 'mixi-bbs-owner 'mixi-object-owner)
 (defalias 'mixi-bbs-id 'mixi-object-id)
 (defalias 'mixi-bbs-time 'mixi-object-time)
 (defalias 'mixi-bbs-title 'mixi-object-title)
+(defalias 'mixi-bbs-owner 'mixi-object-owner)
 (defalias 'mixi-bbs-content 'mixi-object-content)
 
 (defmacro mixi-bbs-list-page (community)
@@ -1790,6 +2171,7 @@ Increase this value when unexpected error frequently occurs."
 (defconst mixi-bbs-list-regexp
   "<a href=view_\\(bbs\\|event\\)\\.pl\\?id=\\([0-9]+\\)")
 
+;;;###autoload
 (defun mixi-get-bbses (community &optional range)
   "Get bbese of COMMUNITY."
   (unless (mixi-community-p community)
@@ -1809,31 +2191,41 @@ Increase this value when unexpected error frequently occurs."
   `(concat "/new_bbs.pl?page=%d"))
 
 (defconst mixi-new-bbs-list-regexp
-  "<a href=\"view_\\(bbs\\|event\\)\\.pl\\?id=\\([0-9]+\\)&comment_count=[0-9]+&comm_id=\\([0-9]+\\)\" class=\"new_link\">")
+  "<a href=\"view_\\(bbs\\|event\\)\\.pl\\?id=\\([0-9]+\\)&comment_count=\\([0-9]+\\)&comm_id=\\([0-9]+\\)\" class=\"new_link\">")
 
+;;;###autoload
 (defun mixi-get-new-bbses (&optional range)
   "Get new topics."
   (let ((items (mixi-get-matched-items (mixi-new-bbs-list-page)
                                       mixi-new-bbs-list-regexp
                                       range)))
-    (mapcar (lambda (item)
-             (let ((name (nth 0 item)))
-               (when (string= name "bbs")
-                 (setq name "topic"))
-               (let ((func (intern (concat "mixi-make-" name))))
-                 (funcall func (mixi-make-community (nth 2 item))
-                          (nth 1 item)))))
-           items)))
-
+    (delq nil
+         (mapcar (lambda (item)
+                   (let ((name (nth 0 item)))
+                     (when (string= name "bbs")
+                       (setq name "topic"))
+                     (let* ((func (intern (concat "mixi-make-" name)))
+                            (bbs (funcall func
+                                          (mixi-make-community (nth 3 item))
+                                          (nth 1 item)))
+                            (comment-count (mixi-bbs-comment-count bbs))
+                            (count (string-to-number (nth 2 item))))
+                       (when (or (null comment-count)
+                                 (< comment-count count))
+                         (mixi-bbs-set-comment-count bbs count)
+                         bbs))))
+                 items))))
 (defmacro mixi-search-bbs-list-page (keyword)
   `(concat "/search_topic.pl?page=%d&type=top&submit=search"
-          "&keyword=" (mixi-url-encode-and-quote-percent-string keyword)
+          "&keyword=" (mixi-url-encode-and-quote-percent-string ,keyword)
           "&community_id=0&category_id=0"))
 
 (defconst mixi-search-bbs-list-regexp
   "<a href=\"view_\\(bbs\\|event\\)\\.pl\\?id=\\([0-9]+\\)&comm_id=\\([0-9]+\\)\"><img src=http://img\\.mixi\\.jp/img/shbtn\\.gif ALT=¾ÜºÙ¤ò¸«¤ë BORDER=0 WIDTH=104 HEIGHT=19></a>")
 
 ;; FIXME: Support community and category.
+;;;###autoload
 (defun mixi-search-bbses (keyword &optional range)
   (let ((items (mixi-get-matched-items (mixi-search-bbs-list-page keyword)
                                       mixi-search-bbs-list-regexp
@@ -1847,6 +2239,19 @@ Increase this value when unexpected error frequently occurs."
                           (nth 1 item)))))
            items)))
 
+;; Parent object.
+(defmacro mixi-parent-p (object)
+  `(or (eq (mixi-object-class ,object) 'mixi-diary)
+       (mixi-bbs-p ,object)))
+
+(defun mixi-realize-parent (parent &optional page)
+  "Realize a PARENT."
+  (unless (mixi-parent-p parent)
+    (signal 'wrong-type-argument (list 'mixi-parent-p parent)))
+  (let ((func (intern (concat mixi-object-prefix "realize-"
+                             (mixi-object-name parent)))))
+    (funcall func parent page)))
+
 ;; Comment object.
 (defun mixi-make-comment (parent owner time content)
   "Return a comment object."
@@ -1886,7 +2291,7 @@ Increase this value when unexpected error frequently occurs."
 
 ;; FIXME: Split regexp to time, owner(id and nick) and contents.
 (defconst mixi-diary-comment-list-regexp
-"<td rowspan=\"2\" align=\"center\" width=\"95\" bgcolor=\"#f2ddb7\" nowrap>
+  "<td rowspan=\"2\" align=\"center\" width=\"95\" bgcolor=\"#f2ddb7\" nowrap>
 \\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü<br>\\([0-9]+\\):\\([0-9]+\\)\\(<br>
 <input type=checkbox name=comment_id value=\".+\">
 \\|\\)
@@ -1904,12 +2309,12 @@ Increase this value when unexpected error frequently occurs."
 </table>
 </td>
 </tr>
-<!-- ËÜʸ : start -->
+<!-- [^ ]+ : start -->
 <tr>
 <td bgcolor=\"#ffffff\">
 <table BORDER=0 CELLSPACING=0 CELLPADDING=[35] WIDTH=410>
 <tr>
-<td CLASS=h12>
+<td CLASS=h12 width=\"410\">
 \\(.+\\)
 </td></tr></table>")
 
@@ -1940,9 +2345,8 @@ Increase this value when unexpected error frequently occurs."
 <td bgcolor=\"#ffffff\" align=\"center\">
 <table border=\"0\" cellspacing=\"0\" cellpadding=\"5\" width=\"500\">
 <tr>
-<td class=\"h120\">
-
-\\(.+\\)
+<td class=\"h120\" width=\"500\">
+\\(\\(.\\|\r?\n\\)*?\\)
 </td>
 </tr>
 </table>
@@ -1965,36 +2369,39 @@ Increase this value when unexpected error frequently occurs."
 <font COLOR=#F8A448><b>[^<]+</b> :</font>
 <a HREF=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a>
 
-</td>
+\\(<font COLOR=#F2DDB7>|</font>
+<a href=\"delete_bbs_comment\\.pl\\?id=[0-9]+&comm_id=[0-9]+&comment_id=[0-9]+&type=event\">ºï½ü</a>
+
+\\|\\)</td>
 </tr>
-\\(<tr>\\)
+<tr>
 <td ALIGN=center BGCOLOR=#FFFFFF>
 <table BORDER=0 CELLSPACING=0 CELLPADDING=5 WIDTH=500>
-<tr><td CLASS=h120>\\(.+\\)</td></tr>
+<tr>
+<td CLASS=h120 width=\"500\">
+
+\\(.+\\)
+</td>
+</tr>
 </table>
 </td>
 </tr>")
 
+;;;###autoload
 (defun mixi-get-comments (parent &optional range)
   "Get comments of PARENT."
-  (unless (mixi-object-p parent)
-    (signal 'wrong-type-argument (list 'mixi-object-p parent)))
+  (unless (mixi-parent-p parent)
+    (signal 'wrong-type-argument (list 'mixi-parent-p parent)))
   (let* ((name (mixi-object-name parent))
         (list-page (intern (concat mixi-object-prefix name
                                    "-comment-list-page")))
         (regexp (eval (intern (concat mixi-object-prefix name
-                                      "-comment-list-regexp")))))
-    (let ((items (mixi-get-matched-items
-                 (funcall list-page parent) regexp)))
-      (let (list)
-       (catch 'stop
-         (mapc (lambda (item)
-                 (when (and (numberp range)
-                            (>= (length list) range))
-                   (throw 'stop nil))
-                 (setq list (cons item list)))
-               (reverse items)))
-       (setq items (reverse list)))
+                                      "-comment-list-regexp"))))
+        (page (funcall list-page parent)))
+    (unless (mixi-object-realized-p parent)
+      (mixi-realize-parent parent page)
+      (setq page nil))
+    (let ((items (mixi-get-matched-items page regexp range t)))
       (mapcar (lambda (item)
                (mixi-make-comment parent (mixi-make-friend
                                           (nth 7 item) (nth 8 item))
@@ -2012,23 +2419,77 @@ Increase this value when unexpected error frequently occurs."
   `(concat "/new_comment.pl?page=%d"))
 
 (defconst mixi-new-comment-list-regexp
-  "<a href=\"view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=\\([0-9]+\\)&comment_count=[0-9]+\" class=\"new_link\">")
+  "<a href=\"view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=\\([0-9]+\\)&comment_count=\\([0-9]+\\)\" class=\"new_link\">")
 
+;;;###autoload
 (defun mixi-get-new-comments (&optional range)
   "Get new comments."
   (let ((items (mixi-get-matched-items (mixi-new-comment-list-page)
                                       mixi-new-comment-list-regexp
                                       range)))
-    (mapcar (lambda (item)
-             (mixi-make-diary (mixi-make-friend (nth 1 item)) (nth 0 item)))
-           items)))
+    (delq nil
+         (mapcar (lambda (item)
+                   (let* ((diary (mixi-make-diary
+                                  (mixi-make-friend (nth 1 item))
+                                  (nth 0 item)))
+                          (comment-count (mixi-diary-comment-count diary))
+                          (count (string-to-number (nth 2 item))))
+                     (when (or (null comment-count)
+                               (< comment-count count))
+                       (mixi-diary-set-comment-count diary count)
+                       diary)))
+                 items))))
+
+(defun mixi-post-diary-comment-page (diary)
+  (concat "/add_comment.pl?&diary_id=" (mixi-diary-id diary)))
+
+(defun mixi-post-topic-comment-page (topic)
+  (concat "/add_bbs_comment.pl?id=" (mixi-topic-id topic)
+         "&comm_id=" (mixi-community-id (mixi-topic-community topic))))
+
+(defun mixi-post-event-comment-page (event)
+  (concat "/add_event_comment.pl?id=" (mixi-event-id event)
+         "&comm_id=" (mixi-community-id (mixi-event-community event))))
+
+;; FIXME: Support photos.
+;;;###autoload
+(defun mixi-post-comment (parent content)
+  "Post a comment to PARENT."
+  (unless (mixi-object-p parent)
+    (signal 'wrong-type-argument (list 'mixi-object-p parent)))
+  (unless (stringp content)
+    (signal 'wrong-type-argument (list 'stringp content)))
+  (let* ((name (mixi-object-name parent))
+        (page (intern (concat mixi-object-prefix "post-" name
+                              "-comment-page")))
+        fields post-key)
+    (if (mixi-diary-p parent)
+       (setq fields
+             `(("owner_id" . ,(mixi-friend-id (mixi-diary-owner parent)))
+               ("comment_body" . ,content)))
+      (setq fields `(("comment" . ,content))))
+    (with-mixi-post-form (funcall page parent) fields
+      (if (re-search-forward mixi-post-key-regexp nil t)
+         (setq post-key (match-string 1))
+       (mixi-post-error 'cannot-find-key parent)))
+    (if (mixi-diary-p parent)
+       (setq fields
+             `(("post_key" . ,post-key)
+               ("owner_id" . ,(mixi-friend-id (mixi-diary-owner parent)))
+               ("comment_body" . ,content)
+               ("submit" . "confirm")))
+      (setq fields `(("post_key" . ,post-key)
+                    ("comment" . ,content)
+                    ("submit" . "confirm"))))
+    (with-mixi-post-form (funcall page parent) fields
+      (unless (re-search-forward mixi-post-succeed-regexp nil t)
+       (mixi-post-error 'cannot-find-succeed parent)))))
 
 ;; Message object.
 (defconst mixi-message-box-list '(inbox outbox savebox thrash)) ; thrash?
 
 (defmacro mixi-message-box-p (box)
-  `(when (memq ,box mixi-message-box-list)
-     t))
+  `(memq ,box mixi-message-box-list))
 
 (defun mixi-message-box-name (box)
   "Return the name of BOX."
@@ -2063,36 +2524,36 @@ Increase this value when unexpected error frequently occurs."
 
 (defconst mixi-message-owner-regexp
   "<font COLOR=#996600>\\(º¹½Ð¿Í\\|°¸&nbsp;Àè\\)</font>&nbsp;:&nbsp;<a HREF=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)\\(</a>\\|</td>\\)")
-(defconst mixi-message-title-regexp
-"<font COLOR=#996600>·ï\\(¡¡\\|&nbsp;\\)̾</font>&nbsp;:&nbsp;\\(.+\\)\n?</td>")
 (defconst mixi-message-time-regexp
 "<font COLOR=#996600>Æü\\(¡¡\\|&nbsp;\\)ÉÕ</font>&nbsp;:&nbsp;\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\)»þ\\([0-9]+\\)ʬ&nbsp;&nbsp;")
+(defconst mixi-message-title-regexp
+"<font COLOR=#996600>·ï\\(¡¡\\|&nbsp;\\)̾</font>&nbsp;:&nbsp;\\(.*\\)\n?</td>")
 (defconst mixi-message-content-regexp
-  "<tr><td CLASS=h120>\\(.+\\)</td></tr>")
+  "<tr><td CLASS=h120 width=\"500\">\\(.*\\)</td></tr>")
 
-(defun mixi-message-realize (message)
+(defun mixi-realize-message (message)
   "Realize a MESSAGE."
-  (unless (mixi-object-realize-p message)
+  (unless (mixi-object-realized-p message)
     (with-mixi-retrieve (mixi-message-page message)
-      (if (string-match mixi-message-owner-regexp buffer)
+      (if (re-search-forward mixi-message-owner-regexp nil t)
          (mixi-message-set-owner message
-                                 (mixi-make-friend (match-string 2 buffer)
-                                                   (match-string 3 buffer)))
-       (signal 'error (list 'cannot-find-owner message)))
-      (if (string-match mixi-message-title-regexp buffer)
-         (mixi-message-set-title message (match-string 2 buffer))
-       (signal 'error (list 'cannot-find-title message)))
-      (if (string-match mixi-message-time-regexp buffer)
+                                 (mixi-make-friend (match-string 2)
+                                                   (match-string 3)))
+       (mixi-realization-error 'cannot-find-owner message))
+      (if (re-search-forward mixi-message-time-regexp nil t)
          (mixi-message-set-time
-          message (encode-time 0 (string-to-number (match-string 6 buffer))
-                               (string-to-number (match-string 5 buffer))
-                               (string-to-number (match-string 4 buffer))
-                               (string-to-number (match-string 3 buffer))
-                               (string-to-number (match-string 2 buffer))))
-       (signal 'error (list 'cannot-find-time message)))
-      (if (string-match mixi-message-content-regexp buffer)
-         (mixi-message-set-content message (match-string 1 buffer))
-       (signal 'error (list 'cannot-find-content message))))
+          message (encode-time 0 (string-to-number (match-string 6))
+                               (string-to-number (match-string 5))
+                               (string-to-number (match-string 4))
+                               (string-to-number (match-string 3))
+                               (string-to-number (match-string 2))))
+       (mixi-realization-error 'cannot-find-time message))
+      (if (re-search-forward mixi-message-title-regexp nil t)
+         (mixi-message-set-title message (match-string 2))
+       (mixi-realization-error 'cannot-find-title message))
+      (if (re-search-forward mixi-message-content-regexp nil t)
+         (mixi-message-set-content message (match-string 1))
+       (mixi-realization-error 'cannot-find-content message)))
     (mixi-object-touch message)))
 
 (defun mixi-message-id (message)
@@ -2111,28 +2572,28 @@ Increase this value when unexpected error frequently occurs."
   "Return the owner of MESSAGE."
   (unless (mixi-message-p message)
     (signal 'wrong-type-argument (list 'mixi-message-p message)))
-  (mixi-message-realize message)
+  (mixi-realize-message message)
   (aref (cdr message) 3))
 
 (defun mixi-message-title (message)
   "Return the title of MESSAGE."
   (unless (mixi-message-p message)
     (signal 'wrong-type-argument (list 'mixi-message-p message)))
-  (mixi-message-realize message)
+  (mixi-realize-message message)
   (aref (cdr message) 4))
 
 (defun mixi-message-time (message)
   "Return the date of MESSAGE."
   (unless (mixi-message-p message)
     (signal 'wrong-type-argument (list 'mixi-message-p message)))
-  (mixi-message-realize message)
+  (mixi-realize-message message)
   (aref (cdr message) 5))
 
 (defun mixi-message-content (message)
   "Return the content of MESSAGE."
   (unless (mixi-message-p message)
     (signal 'wrong-type-argument (list 'mixi-message-p message)))
-  (mixi-message-realize message)
+  (mixi-realize-message message)
   (aref (cdr message) 6))
 
 (defun mixi-message-set-owner (message owner)
@@ -2166,17 +2627,18 @@ Increase this value when unexpected error frequently occurs."
 (defconst mixi-message-list-regexp
   "<td><a HREF=\"view_message\\.pl\\?id=\\(.+\\)&box=\\(.+\\)\">")
 
-(defun mixi-get-messages (&rest args)
-  "Get messages."
-  (when (> (length args) 2)
+;;;###autoload
+(defun mixi-get-messages (&rest box-or-range)
+  "Get messages of BOX."
+  (when (> (length box-or-range) 2)
     (signal 'wrong-number-of-arguments
-           (list 'mixi-get-messages (length args))))
-  (let ((box (nth 0 args))
-       (range (nth 1 args)))
+           (list 'mixi-get-messages (length box-or-range))))
+  (let ((box (nth 0 box-or-range))
+       (range (nth 1 box-or-range)))
     (when (or (not (mixi-message-box-p box))
              (mixi-message-box-p range))
-      (setq box (nth 1 args))
-      (setq range (nth 0 args)))
+      (setq box (nth 1 box-or-range))
+      (setq range (nth 0 box-or-range)))
     (let ((items (mixi-get-matched-items
                  (mixi-message-list-page
                   (when box (mixi-message-box-name box)))
@@ -2186,6 +2648,41 @@ Increase this value when unexpected error frequently occurs."
                (mixi-make-message (nth 0 item) (nth 1 item)))
              items))))
 
+(defmacro mixi-post-message-page (friend)
+  `(concat "/send_message.pl?id=" (mixi-friend-id friend)))
+
+(defconst mixi-post-message-key-regexp
+  "<input name=post_key type=hidden value=\\([a-z0-9]+\\)>")
+
+(defconst mixi-post-message-succeed-regexp
+  "<b>Á÷¿®´°Î»</b>¤·¤Þ¤·¤¿¡£")
+
+;;;###autoload
+(defun mixi-post-message (friend title content)
+  "Post a message to FRIEND."
+  (unless (mixi-friend-p friend)
+    (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
+  (unless (stringp title)
+    (signal 'wrong-type-argument (list 'stringp title)))
+  (unless (stringp content)
+    (signal 'wrong-type-argument (list 'stringp content)))
+  (let ((fields `(("subject" . ,title)
+                 ("body" . ,content)
+                 ("submit" . "main")))
+       post-key)
+    (with-mixi-post-form (mixi-post-message-page friend) fields
+      (if (re-search-forward mixi-post-message-key-regexp nil t)
+         (setq post-key (match-string 1))
+       (mixi-post-error 'cannot-find-key friend)))
+    (setq fields `(("post_key" . ,post-key)
+                  ("subject" . ,title)
+                  ("body" . ,content)
+                  ("yes" . "¡¡Á÷¡¡¿®¡¡")
+                  ("submit" . "confirm")))
+    (with-mixi-post-form (mixi-post-message-page friend) fields
+      (unless (re-search-forward mixi-post-message-succeed-regexp nil t)
+       (mixi-post-error 'cannot-find-succeed friend)))))
+
 ;; Introduction object.
 (defun mixi-make-introduction (parent owner content)
   "Return a introduction object."
@@ -2257,16 +2754,17 @@ Increase this value when unexpected error frequently occurs."
 </td>
 </tr>")
 
-(defun mixi-get-introductions (&rest args)
-  "Get introductions."
-  (when (> (length args) 2)
+;;;###autoload
+(defun mixi-get-introductions (&rest friend-or-range)
+  "Get introductions of FRIEND."
+  (when (> (length friend-or-range) 2)
     (signal 'wrong-number-of-arguments
-           (list 'mixi-get-introduction (length args))))
-  (let ((friend (nth 0 args))
-       (range (nth 1 args)))
+           (list 'mixi-get-introduction (length friend-or-range))))
+  (let ((friend (nth 0 friend-or-range))
+       (range (nth 1 friend-or-range)))
     (when (or (not (mixi-friend-p friend)) (mixi-friend-p range))
-      (setq friend (nth 1 args))
-      (setq range (nth 0 args)))
+      (setq friend (nth 1 friend-or-range))
+      (setq range (nth 0 friend-or-range)))
     (unless (or (null friend) (mixi-friend-p friend))
       (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
     (let* ((regexp (if friend mixi-introduction-list-regexp
@@ -2281,6 +2779,215 @@ Increase this value when unexpected error frequently occurs."
                                        (nth 2 item)))
              items))))
 
+;; News object.
+(defvar mixi-news-cache (make-hash-table :test 'equal))
+(defun mixi-make-news (media-id id &optional media time title content)
+  "Return a news object."
+  (mixi-make-cache (list media-id id)
+                  (cons 'mixi-news (vector nil media-id id media time title
+                                           content))
+                  mixi-news-cache))
+
+(defconst mixi-news-url-regexp
+  "/view_news\\.pl\\?id=\\([0-9]+\\)&media_id=\\([0-9]+\\)")
+
+(defun mixi-make-news-from-url (url)
+  "Return a news object from URL."
+  (when (string-match mixi-news-url-regexp url)
+    (let ((id (match-string 1 url))
+         (media-id (match-string 2 url)))
+      (mixi-make-news media-id id))))
+
+(defmacro mixi-news-p (news)
+  `(eq (mixi-object-class ,news) 'mixi-news))
+
+(defmacro mixi-news-page (news)
+  `(concat "http://news.mixi.jp/view_news.pl?id=" (mixi-news-id ,news)
+          "&media_id=" (mixi-news-media-id ,news)))
+
+
+(defconst mixi-news-finished-regexp
+  "¿½¤·Ìõ¤´¤¶¤¤¤Þ¤»¤ó¤¬¡¢¤³¤Î¥Ë¥å¡¼¥¹¤Ï·ÇºÜ¤¬½ªÎ»¤·¤¿¤«¡¢URL¤¬´Ö°ã¤Ã¤Æ¤¤¤¤¤ë¤¿¤á¤´Í÷¤¤¤¿¤À¤±¤Þ¤»¤ó¡£</td>")
+(defconst mixi-news-title-regexp
+  "<td HEIGHT=\"46\" STYLE=\"font-weight: bold;font-size: 14px;\" CLASS=\"h130\">\\(.+\\)\\(
+\\)?</td>")
+(defconst mixi-news-media-time-regexp
+  "<td COLSPAN=\"2\" ALIGN=\"right\">(\\(.+\\)&nbsp;-&nbsp;\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\))</td></tr>")
+(defconst mixi-news-content-regexp
+  "<td CLASS=\"h150\">
+
+\\(.+\\)
+<br>
+\\(.*
+\\)?
+
+\\(</td>\\|<br>\\)")
+
+(defun mixi-realize-news (news)
+  "Realize a NEWS."
+  ;; FIXME: Check a expiration of cache?
+  (unless (mixi-object-realized-p news)
+    (with-mixi-retrieve (mixi-news-page news)
+      (if (re-search-forward mixi-news-finished-regexp nil t)
+         (mixi-news-set-content news (match-string 0))
+       (if (re-search-forward mixi-news-title-regexp nil t)
+           (mixi-news-set-title news (match-string 1))
+         (mixi-realization-error 'cannot-find-title news))
+       (if (re-search-forward mixi-news-media-time-regexp nil t)
+           (progn
+             (mixi-news-set-media news (match-string 1))
+             (let ((year (nth 5 (decode-time (current-time))))
+                   (month (nth 4 (decode-time (current-time))))
+                   (month-of-item (string-to-number (match-string 2))))
+               (when (> month-of-item month)
+                 (decf year))
+               (mixi-news-set-time
+                news (encode-time 0 (string-to-number (match-string 5))
+                                  (string-to-number (match-string 4))
+                                  (string-to-number (match-string 3))
+                                  month year))))
+         (mixi-realization-error 'cannot-find-media-time news))
+       (if (re-search-forward mixi-news-content-regexp nil t)
+           (mixi-news-set-content news (match-string 1))
+         (mixi-realization-error 'cannot-find-content news))))
+    (mixi-object-touch news)))
+
+(defun mixi-news-media-id (news)
+  "Return the media-id of NEWS."
+  (unless (mixi-news-p news)
+    (signal 'wrong-type-argument (list 'mixi-news-p news)))
+  (aref (cdr news) 1))
+
+(defun mixi-news-id (news)
+  "Return the id of NEWS."
+  (unless (mixi-news-p news)
+    (signal 'wrong-type-argument (list 'mixi-news-p news)))
+  (aref (cdr news) 2))
+
+(defun mixi-news-media (news)
+  "Return the media of NEWS."
+  (unless (mixi-news-p news)
+    (signal 'wrong-type-argument (list 'mixi-news-p news)))
+  (unless (aref (cdr news) 3)
+    (mixi-realize-news news))
+  (aref (cdr news) 3))
+
+(defun mixi-news-time (news)
+  "Return the time of NEWS."
+  (unless (mixi-news-p news)
+    (signal 'wrong-type-argument (list 'mixi-news-p news)))
+  (unless (aref (cdr news) 4)
+    (mixi-realize-news news))
+  (aref (cdr news) 4))
+
+(defun mixi-news-title (news)
+  "Return the title of NEWS."
+  (unless (mixi-news-p news)
+    (signal 'wrong-type-argument (list 'mixi-news-p news)))
+  (unless (aref (cdr news) 5)
+    (mixi-realize-news news))
+  (aref (cdr news) 5))
+
+(defun mixi-news-content (news)
+  "Return the content of NEWS."
+  (unless (mixi-news-p news)
+    (signal 'wrong-type-argument (list 'mixi-news-p news)))
+  (mixi-realize-news news)
+  (aref (cdr news) 6))
+
+(defun mixi-news-set-media (news media)
+  "Set the media of NEWS."
+  (unless (mixi-news-p news)
+    (signal 'wrong-type-argument (list 'mixi-news-p news)))
+  (aset (cdr news) 3 media))
+
+(defun mixi-news-set-time (news time)
+  "Set the time of NEWS."
+  (unless (mixi-news-p news)
+    (signal 'wrong-type-argument (list 'mixi-news-p news)))
+  (aset (cdr news) 4 time))
+
+(defun mixi-news-set-title (news title)
+  "Set the title of NEWS."
+  (unless (mixi-news-p news)
+    (signal 'wrong-type-argument (list 'mixi-news-p news)))
+  (aset (cdr news) 5 title))
+
+(defun mixi-news-set-content (news content)
+  "Set the content of NEWS."
+  (unless (mixi-news-p news)
+    (signal 'wrong-type-argument (list 'mixi-news-p news)))
+  (aset (cdr news) 6 content))
+
+(defconst mixi-news-category-list '(domestic politics economy area abroad
+                                            sports entertainment IT))
+
+(defmacro mixi-news-category-p (category)
+  `(memq ,category mixi-news-category-list))
+
+(defun mixi-news-category-id (category)
+  "Return the id of CATEGORY."
+  (unless (mixi-news-category-p category)
+    (signal 'wrong-type-argument (list 'mixi-news-category-p category)))
+  (number-to-string
+   (1+ (- (length mixi-news-category-list)
+         (length (memq category mixi-news-category-list))))))
+
+(defconst mixi-news-sort-list '(newest pickup))
+
+(defmacro mixi-news-sort-p (sort)
+  `(memq ,sort mixi-news-sort-list))
+
+(defun mixi-news-sort-id (sort)
+  "Return the id of SORT."
+  (unless (mixi-news-sort-p sort)
+    (signal 'wrong-type-argument (list 'mixi-news-sort-p sort)))
+  (number-to-string
+   (- (length mixi-news-sort-list)
+      (length (memq sort mixi-news-sort-list)))))
+
+(defmacro mixi-news-list-page (category sort)
+  `(concat "http://news.mixi.jp/list_news_category.pl?page=%d"
+          "&sort=" (mixi-news-sort-id ,sort)
+          "&id=" (mixi-news-category-id ,category)
+          "&type=bn"))
+
+(defconst mixi-news-list-regexp
+  "<tr bgcolor=\"\\(#FCF5EB\\|#FFFFFF\\)\">
+<td WIDTH=\"1%\" valign=top CLASS=\"h120\">¡¦</td>
+<td WIDTH=\"97%\" CLASS=\"h120\"><A HREF=\"view_news\\.pl\\?id=\\([0-9]+\\)&media_id=\\([0-9]+\\)\"class=\"new_link\">\\(.+\\)</A>
+\\(<IMG SRC=\"http://img\\.mixi\\.jp/img/news_camera3\\.gif\" WIDTH=\"11\" HEIGHT=\"12\">\\|\\)
+
+</td>
+<td WIDTH=\"1%\" nowrap CLASS=\"f08\"><A HREF=\"list_news_media\\.pl\\?id=[0-9]+\">\\(.+\\)</A></td>
+<td WIDTH=\"1%\" nowrap CLASS=\"f08\">\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</td></tr>")
+
+;;;###autoload
+(defun mixi-get-news (category sort &optional range)
+  "Get news of CATEGORY and SORT."
+  (unless (mixi-news-category-p category)
+    (signal 'wrong-type-argument (list 'mixi-news-category-p category)))
+  (unless (mixi-news-sort-p sort)
+    (signal 'wrong-type-argument (list 'mixi-news-sort-p sort)))
+  (let ((items (mixi-get-matched-items (mixi-news-list-page category sort)
+                                      mixi-news-list-regexp
+                                      range))
+       (year (nth 5 (decode-time (current-time))))
+       (month (nth 4 (decode-time (current-time)))))
+    (mapcar (lambda (item)
+             (let ((month-of-item (string-to-number (nth 6 item))))
+               (when (> month-of-item month)
+                 (decf year))
+               (setq month month-of-item)
+               (mixi-make-news (nth 2 item) (nth 1 item) (nth 5 item)
+                               (encode-time
+                                0 (string-to-number (nth 9 item))
+                                (string-to-number (nth 8 item))
+                                (string-to-number (nth 7 item))
+                                month year)
+                               (nth 3 item))))
+           items)))
+
 (provide 'mixi)
 
 ;;; mixi.el ends here