* sb-mixi.el (shimbun-mixi-group-alist): Add `messages.sent' and
[elisp/mixi.git] / mixi.el
diff --git a/mixi.el b/mixi.el
index 0011d90..719ce50 100644 (file)
--- a/mixi.el
+++ b/mixi.el
 
 (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)
+  (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)
                (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
   "*Default E-mail address that is used to login automatically."
   :type '(radio (string :tag "E-mail address")
@@ -208,6 +224,7 @@ Increase this value when unexpected error frequently occurs."
   :type 'boolean
   :group 'mixi)
 
+(defvar mixi-temp-buffer-name " *mixi temp*")
 (defvar mixi-me nil)
 
 ;; Utilities.
@@ -225,14 +242,13 @@ Increase this value when unexpected error frequently occurs."
      'error-conditions '(mixi-post-error error))
 
 (defmacro mixi-realization-error (type object)
-  `(let ((data (if (and (boundp 'buffer) debug-on-error)
-                  (list ,type ,object buffer)
+  `(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 (and (boundp 'buffer) debug-on-error)
-                (list buffer))))
+  `(let ((data (when debug-on-error (list (buffer-string)))))
      (if ,object
         (setq data (cons ,type (cons ,object data)))
        (setq data (cons ,type data)))
@@ -381,65 +397,78 @@ Increase this value when unexpected error frequently occurs."
                   (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 "/login.pl"))
+      (when mixi-login-use-ssl
+       (setq url (concat "https://mixi.jp" 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"))
 
 (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 "<form action=\"login\\.pl\" method=\"post\">"
-                          buffer)
+       (erase-buffer)
+       (insert (mixi-retrieve ,url))
+       (goto-char (point-min))
+       (when (search-forward
+             "<form action=\"login.pl\" method=\"post\">" 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))
 
 (defmacro with-mixi-post-form (url fields &rest body)
-  `(let (buffer)
+  `(with-current-buffer (get-buffer-create mixi-temp-buffer-name)
      (when ,url
-       (setq buffer (mixi-post-form ,url ,fields))
-       (when (string-match "<form action=\"login\\.pl\" method=\"post\">"
-                          buffer)
+       (erase-buffer)
+       (insert (mixi-post-form ,url ,fields))
+       (goto-char (point-min))
+       (when (search-forward
+             "<form action=\"login.pl\" method=\"post\">" nil t)
         (mixi-login)
-        (setq buffer (mixi-post-form ,url ,fields))))
+        (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 '(form body))
+(put 'with-mixi-post-form 'edebug-form-spec '(body))
 
-(defun mixi-get-matched-items (url regexp &optional range)
+(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)))
@@ -723,8 +752,8 @@ 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)
+         (setq mixi-me (mixi-make-friend (match-string 1)))
        (signal 'error (list 'who-am-i)))))
   mixi-me)
 
@@ -743,10 +772,10 @@ 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?
+  "<img \\(alt=\"\\*\" \\)?src=\"?http://img\\.mixi\\.jp/img/dot0\\.gif\"? \\(width\\|WIDTH\\)=\"?1\"? \\(height\\|HEIGHT\\)=\"?5\"?><br>\r?
 \\(.*\\)¤µ¤ó([0-9]+)")
 (defconst mixi-friend-name-regexp
   "<td BGCOLOR=#F2DDB7 WIDTH=80 NOWRAP><font COLOR=#996600>̾\\(&nbsp;\\| \\)Á°</font></td>
@@ -779,47 +808,35 @@ Increase this value when unexpected error frequently occurs."
   "Realize a FRIEND."
   ;; FIXME: Check a expiration of cache?
   (unless (mixi-object-realized-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))
+    (with-mixi-retrieve (mixi-friend-page friend)
+      (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))
-      ;; For getting my profile.
-      (unless (string-match mixi-friend-name-regexp buf)
-       (with-mixi-retrieve (concat "/show_profile.pl?id="
-                                   (mixi-friend-id friend))
-         (setq buf buffer)))
-      (if (string-match mixi-friend-name-regexp buf)
-           (mixi-friend-set-name friend (match-string 2 buf))
-       (mixi-realization-error 'cannot-find-name friend))
-      (if (string-match mixi-friend-sex-regexp buf)
-         (mixi-friend-set-sex friend
-                              (if (string= (match-string 3 buf) "ÃË")
-                                  'male 'female))
-       (mixi-realization-error 'cannot-find-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))))
+      (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 3) "ÃË")
+                                       '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)
@@ -1089,23 +1106,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))
@@ -1125,29 +1143,28 @@ Increase this value when unexpected error frequently occurs."
 (defconst mixi-diary-content-regexp
   "<td \\(class\\|CLASS\\)=\"?h12\"?>\\(.*\\)</td>")
 
-(defun mixi-realize-diary (diary)
+(defun mixi-realize-diary (diary &optional page)
   "Realize a DIARY."
   ;; FIXME: Check a expiration of cache?
   (unless (mixi-object-realized-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))
+    (with-mixi-retrieve (or page (mixi-diary-page diary))
+      (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 (string-match mixi-diary-time-regexp buffer)
+       (if (re-search-forward mixi-diary-time-regexp nil t)
            (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))))
+            diary (encode-time 0 (string-to-number (match-string 10))
+                               (string-to-number (match-string 9))
+                               (string-to-number (match-string 7))
+                               (string-to-number (match-string 6))
+                               (string-to-number (match-string 5))))
          (mixi-realization-error 'cannot-find-time diary))
-       (if (string-match mixi-diary-title-regexp buffer)
-           (mixi-diary-set-title diary (match-string 2 buffer))
+       (if (re-search-forward mixi-diary-title-regexp nil t)
+           (mixi-diary-set-title diary (match-string 2))
          (mixi-realization-error 'cannot-find-title diary))
-       (if (string-match mixi-diary-content-regexp buffer)
-           (mixi-diary-set-content diary (match-string 2 buffer))
+       (if (re-search-forward mixi-diary-content-regexp nil t)
+           (mixi-diary-set-content diary (match-string 2))
          (mixi-realization-error 'cannot-find-content diary))))
     (mixi-object-touch diary)))
 
@@ -1163,13 +1180,19 @@ 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)))
   (unless (aref (cdr diary) 3)
     (mixi-realize-diary diary))
-  (aref (cdr diary) 3))
+  (aref (cdr diary) 4))
 
 (defun mixi-diary-title (diary)
   "Return the title of DIARY."
@@ -1177,32 +1200,38 @@ Increase this value when unexpected error frequently occurs."
     (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
   (unless (aref (cdr diary) 4)
     (mixi-realize-diary diary))
-  (aref (cdr diary) 4))
+  (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-realize-diary diary)
-  (aref (cdr diary) 5))
+  (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"
@@ -1211,21 +1240,7 @@ Increase this value when unexpected error frequently occurs."
 (defconst mixi-diary-list-regexp
   "<tr VALIGN=top>
 <td ALIGN=center ROWSPAN=3 NOWRAP bgcolor=#F2DDB7><font COLOR=#996600>\\([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>
-</tr>
-<tr>
-<td ALIGN=center BGCOLOR=#FFFFFF>
-<table BORDER=0 CELLSPACING=0 CELLPADDING=3 WIDTH=410>
-<tr>
-<td CLASS=h120>
-
-\\(.*\\)
-
-?<br>
-
-</td></tr>
-</table>
-</td></tr>")
+<td bgcolor=\"#FFF4E0\">&nbsp;<a href=\"view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=[0-9]+\">\\(.*\\)</a></td>")
 
 (defun mixi-get-diaries (&rest friend-or-range)
   "Get diaries of FRIEND."
@@ -1255,7 +1270,7 @@ Increase this value when unexpected error frequently occurs."
                                    (string-to-number (nth 2 item))
                                    (string-to-number (nth 1 item))
                                    month year)
-                                  (nth 6 item) (nth 7 item))))
+                                  (nth 6 item))))
              items))))
 
 (defmacro mixi-new-diary-list-page ()
@@ -1351,8 +1366,8 @@ Increase this value when unexpected error frequently occurs."
                  ("submit" . "main")))
        post-key)
     (with-mixi-post-form (mixi-post-diary-page) fields
-      (if (string-match mixi-post-key-regexp buffer)
-         (setq post-key (match-string 1 buffer))
+      (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)))
@@ -1360,7 +1375,7 @@ Increase this value when unexpected error frequently occurs."
                   ("diary_body" . ,content)
                   ("submit" . "confirm")))
     (with-mixi-post-form (mixi-post-diary-page) fields
-      (unless (string-match mixi-post-succeed-regexp buffer)
+      (unless (re-search-forward mixi-post-succeed-regexp nil t)
        (mixi-post-error 'cannot-find-succeed)))))
 
 ;; Community object.
@@ -1396,7 +1411,7 @@ Increase this value when unexpected error frequently occurs."
   "<td WIDTH=345>\\(.*\\)</td></tr>")
 (defconst mixi-community-birthday-regexp
   "<td BGCOLOR=#F2DDB7 WIDTH=80><font COLOR=#996600>³«ÀßÆü</font></td>\r
-<td WIDTH=345>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü</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 WIDTH=80><font COLOR=#996600>´ÉÍý¿Í</font></td>\r
@@ -1423,41 +1438,40 @@ Increase this value when unexpected error frequently occurs."
   ;; FIXME: Check a expiration of cache?
   (unless (mixi-object-realized-p community)
     (with-mixi-retrieve (mixi-community-page community)
-      (if (string-match mixi-community-nodata-regexp buffer)
+      (if (re-search-forward mixi-community-nodata-regexp nil t)
          ;; 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))
+       (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 (string-match mixi-community-birthday-regexp buffer)
+       (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 buffer))
-                         (string-to-number (match-string 2 buffer))
-                         (string-to-number (match-string 1 buffer))))
+            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 (string-match mixi-community-owner-regexp buffer)
-           (if (string= (match-string 1 buffer) "home.pl")
+       (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 buffer)
-                                          (match-string 3 buffer))))
+             (mixi-community-set-owner community
+                                       (mixi-make-friend (match-string 2)
+                                                         (match-string 3))))
          (mixi-realization-error 'cannot-find-owner community))
-       (if (string-match mixi-community-category-regexp buffer)
-           (mixi-community-set-category community (match-string 1 buffer))
+       (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 (string-match mixi-community-members-regexp buffer)
-           (mixi-community-set-members
-            community (string-to-number (match-string 1 buffer)))
+       (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 (string-match mixi-community-open-level-regexp buffer)
-           (mixi-community-set-open-level community (match-string 1 buffer))
+       (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 (string-match mixi-community-authority-regexp buffer)
-           (mixi-community-set-authority community (match-string 1 buffer))
+       (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 (string-match mixi-community-description-regexp buffer)
-           (mixi-community-set-description community (match-string 1 buffer))
+       (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)))
 
@@ -1631,22 +1645,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))
@@ -1666,33 +1682,32 @@ Increase this value when unexpected error frequently occurs."
 (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]+&comm_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>")
 
-(defun mixi-realize-topic (topic)
+(defun mixi-realize-topic (topic &optional page)
   "Realize a TOPIC."
   ;; FIXME: Check a expiration of cache?
   (unless (mixi-object-realized-p topic)
-    (with-mixi-retrieve (mixi-topic-page topic)
-      (if (string-match mixi-topic-community-regexp buffer)
+    (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 buffer))
+                                  (match-string 1))
        (mixi-realization-error 'cannot-find-community topic))
-      (if (string-match mixi-topic-time-regexp buffer)
+      (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))))
+          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 (string-match mixi-topic-title-regexp buffer)
-         (mixi-topic-set-title topic (match-string 1 buffer))
+      (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 (string-match mixi-topic-owner-regexp buffer)
-         (mixi-topic-set-owner topic
-                               (mixi-make-friend (match-string 1 buffer)
-                                                 (match-string 2 buffer)))
+      (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 (string-match mixi-topic-content-regexp buffer)
-         (mixi-topic-set-content topic (match-string 2 buffer))
+      (if (re-search-forward mixi-topic-content-regexp nil t)
+         (mixi-topic-set-content topic (match-string 2))
        (mixi-realization-error 'cannot-find-content topic)))
     (mixi-object-touch topic)))
 
@@ -1708,45 +1723,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-realize-topic topic)
-  (aref (cdr topic) 3))
+  (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-realize-topic topic)
-  (aref (cdr topic) 4))
+  (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-realize-topic topic)
-  (aref (cdr topic) 5))
+  (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-realize-topic topic)
-  (aref (cdr topic) 6))
+  (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."
@@ -1754,13 +1781,13 @@ 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)))
@@ -1779,36 +1806,38 @@ Increase this value when unexpected error frequently occurs."
                  ("submit" . "main")))
        post-key)
     (with-mixi-post-form (mixi-post-topic-page community) fields
-      (if (string-match mixi-post-key-regexp buffer)
-         (setq post-key (match-string 1 buffer))
+      (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 (string-match mixi-post-succeed-regexp buffer)
+      (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))
@@ -1855,51 +1884,49 @@ Increase this value when unexpected error frequently occurs."
 
 ?<td>&nbsp;\\(.+\\)</td>")
 
-(defun mixi-realize-event (event)
+(defun mixi-realize-event (event &optional page)
   "Realize a EVENT."
   ;; FIXME: Check a expiration of cache?
   (unless (mixi-object-realized-p event)
-    (with-mixi-retrieve (mixi-event-page event)
-      (if (string-match mixi-event-community-regexp buffer)
+    (with-mixi-retrieve (or page (mixi-event-page event))
+      (if (re-search-forward mixi-event-community-regexp nil t)
          (mixi-community-set-name (mixi-event-community event)
-                                  (match-string 1 buffer))
+                                  (match-string 1))
        (mixi-realization-error 'cannot-find-community event))
-      (if (string-match mixi-event-time-regexp buffer)
+      (if (re-search-forward mixi-event-time-regexp nil t)
          (mixi-event-set-time
-          event (encode-time 0 (string-to-number (match-string 8 buffer))
-                             (string-to-number (match-string 7 buffer))
-                             (string-to-number (match-string 6 buffer))
-                             (string-to-number (match-string 5 buffer))
-                             (string-to-number (match-string 4 buffer))))
+          event (encode-time 0 (string-to-number (match-string 8))
+                             (string-to-number (match-string 7))
+                             (string-to-number (match-string 6))
+                             (string-to-number (match-string 5))
+                             (string-to-number (match-string 4))))
        (mixi-realization-error 'cannot-find-time event))
-      (if (string-match mixi-event-title-regexp buffer)
-         (mixi-event-set-title event (match-string 2 buffer))
+      (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 (string-match mixi-event-owner-regexp buffer)
-         (mixi-event-set-owner event
-                               (mixi-make-friend (match-string 2 buffer)
-                                                 (match-string 3 buffer)))
-       (if (string-match mixi-event-owner-seceded-regexp buffer)
+      (if (re-search-forward mixi-event-owner-regexp nil t)
+         (mixi-event-set-owner event (mixi-make-friend (match-string 2)
+                                                       (match-string 3)))
+       (if (re-search-forward mixi-event-owner-seceded-regexp nil t)
            (mixi-event-set-owner event
-                                 (mixi-make-friend nil
-                                                   (match-string 2 buffer)))
+                                 (mixi-make-friend nil (match-string 2)))
          (mixi-realization-error 'cannot-find-owner event)))
-      (if (string-match mixi-event-date-regexp buffer)
-         (mixi-event-set-date event (match-string 6 buffer))
+      (if (re-search-forward mixi-event-date-regexp nil t)
+         (mixi-event-set-date event (match-string 6))
        (mixi-realization-error 'cannot-find-date event))
-      (if (string-match mixi-event-place-regexp buffer)
-         (mixi-event-set-place event (match-string 6 buffer))
+      (if (re-search-forward mixi-event-place-regexp nil t)
+         (mixi-event-set-place event (match-string 6))
        (mixi-realization-error 'cannot-find-place event))
-      (if (string-match mixi-event-detail-regexp buffer)
-         (mixi-event-set-detail event (match-string 6 buffer))
+      (if (re-search-forward mixi-event-detail-regexp nil t)
+         (mixi-event-set-detail event (match-string 6))
        (mixi-realization-error 'cannot-find-detail event))
-      (when (string-match mixi-event-limit-regexp buffer)
+      (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 8 buffer))
-                           (string-to-number (match-string 7 buffer))
-                           (string-to-number (match-string 6 buffer)))))
-      (if (string-match mixi-event-members-regexp buffer)
-         (mixi-event-set-members event (match-string 6 buffer))
+        event (encode-time 0 0 0 (string-to-number (match-string 8))
+                           (string-to-number (match-string 7))
+                           (string-to-number (match-string 6)))))
+      (if (re-search-forward mixi-event-members-regexp nil t)
+         (mixi-event-set-members event (match-string 6))
        (mixi-realization-error 'cannot-find-members event)))
     (mixi-object-touch event)))
 
@@ -1915,73 +1942,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-realize-event event)
-  (aref (cdr event) 3))
+  (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-realize-event event)
-  (aref (cdr event) 4))
+  (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-realize-event event)
-  (aref (cdr event) 5))
+  (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-realize-event event)
-  (aref (cdr event) 6))
+  (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-realize-event event)
-  (aref (cdr event) 7))
+  (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-realize-event event)
-  (aref (cdr event) 8))
+  (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-realize-event event)
-  (aref (cdr event) 9))
+  (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-realize-event event)
-  (aref (cdr event) 10))
+  (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."
@@ -1989,51 +2028,67 @@ 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.
+;; BBS object.
 (defconst mixi-bbs-list '(mixi-topic mixi-event))
 
-(defmacro mixi-bbs-p (object)
-  `(memq (mixi-object-class ,object) mixi-bbs-list))
+(defmacro mixi-bbs-p (bbs)
+  `(memq (mixi-object-class ,bbs) mixi-bbs-list))
 
-(defun mixi-bbs-community (object)
-  "Return the community of OBJECT."
-  (unless (mixi-bbs-p object)
-    (signal 'wrong-type-argument (list 'mixi-bbs-p object)))
+(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 object) "-community"))))
-    (funcall func object)))
+                             (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)))
 
 (defalias 'mixi-bbs-id 'mixi-object-id)
 (defalias 'mixi-bbs-time 'mixi-object-time)
@@ -2067,22 +2122,30 @@ 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\">")
 
 (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)
@@ -2105,6 +2168,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."
@@ -2238,24 +2314,18 @@ Increase this value when unexpected error frequently occurs."
 
 (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))
@@ -2273,16 +2343,25 @@ 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\">")
 
 (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)))
+                                       mixi-new-comment-list-regexp
+                                       range)))
+    (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)))
@@ -2312,8 +2391,8 @@ Increase this value when unexpected error frequently occurs."
                ("comment_body" . ,content)))
       (setq fields `(("comment" . ,content))))
     (with-mixi-post-form (funcall page parent) fields
-      (if (string-match mixi-post-key-regexp buffer)
-         (setq post-key (match-string 1 buffer))
+      (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
@@ -2325,7 +2404,7 @@ Increase this value when unexpected error frequently occurs."
                     ("comment" . ,content)
                     ("submit" . "confirm"))))
     (with-mixi-post-form (funcall page parent) fields
-      (unless (string-match mixi-post-succeed-regexp buffer)
+      (unless (re-search-forward mixi-post-succeed-regexp nil t)
        (mixi-post-error 'cannot-find-succeed parent)))))
 
 ;; Message object.
@@ -2367,10 +2446,10 @@ 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>")
 
@@ -2378,24 +2457,24 @@ Increase this value when unexpected error frequently occurs."
   "Realize a 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)))
+                                 (mixi-make-friend (match-string 2)
+                                                   (match-string 3)))
        (mixi-realization-error 'cannot-find-owner message))
-      (if (string-match mixi-message-title-regexp buffer)
-         (mixi-message-set-title message (match-string 2 buffer))
-       (mixi-realization-error 'cannot-find-title message))
-      (if (string-match mixi-message-time-regexp buffer)
+      (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))))
+          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 (string-match mixi-message-content-regexp buffer)
-         (mixi-message-set-content message (match-string 1 buffer))
+      (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)))
 
@@ -2512,8 +2591,8 @@ Increase this value when unexpected error frequently occurs."
                  ("submit" . "main")))
        post-key)
     (with-mixi-post-form (mixi-post-message-page friend) fields
-      (if (string-match mixi-post-message-key-regexp buffer)
-         (setq post-key (match-string 1 buffer))
+      (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)
@@ -2521,7 +2600,7 @@ Increase this value when unexpected error frequently occurs."
                   ("yes" . "¡¡Á÷¡¡¿®¡¡")
                   ("submit" . "confirm")))
     (with-mixi-post-form (mixi-post-message-page friend) fields
-      (unless (string-match mixi-post-message-succeed-regexp buffer)
+      (unless (re-search-forward mixi-post-message-succeed-regexp nil t)
        (mixi-post-error 'cannot-find-succeed friend)))))
 
 ;; Introduction object.
@@ -2646,15 +2725,17 @@ Increase this value when unexpected error frequently occurs."
           "&media_id=" (mixi-news-media-id ,news)))
 
 (defconst mixi-news-title-regexp
-  "<td HEIGHT=\"46\" STYLE=\"font-weight: bold;font-size: 14px;\" CLASS=\"h130\">\\(.+\\)</td>")
+  "<td HEIGHT=\"46\" STYLE=\"font-weight: bold;font-size: 14px;\" CLASS=\"h130\">\\(.+\\)\\(\r
+\\)?</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>\\)")
 
@@ -2663,25 +2744,25 @@ Increase this value when unexpected error frequently occurs."
   ;; FIXME: Check a expiration of cache?
   (unless (mixi-object-realized-p news)
     (with-mixi-retrieve (mixi-news-page news)
-      (if (string-match mixi-news-title-regexp buffer)
-         (mixi-news-set-title news (match-string 1 buffer))
+      (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 (string-match mixi-news-media-time-regexp buffer)
+      (if (re-search-forward mixi-news-media-time-regexp nil t)
          (progn
-           (mixi-news-set-media news (match-string 1 buffer))
+           (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 buffer))))
+                 (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 buffer))
-                                (string-to-number (match-string 4 buffer))
-                                (string-to-number (match-string 3 buffer))
+              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 (string-match mixi-news-content-regexp buffer)
-         (mixi-news-set-content news (match-string 1 buffer))
+      (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)))