* sb-mixi.el (shimbun-mixi-get-headers): Get headers of comments
[elisp/mixi.git] / mixi.el
diff --git a/mixi.el b/mixi.el
index 0011d90..8d52aa3 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")
@@ -225,14 +241,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 +396,76 @@ 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)
-     (when ,url
-       (setq buffer (mixi-retrieve ,url))
-       (when (string-match "<form action=\"login\\.pl\" method=\"post\">"
-                          buffer)
+  `(when ,url
+     (with-temp-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))))
-     ,@body))
+        (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)
-     (when ,url
-       (setq buffer (mixi-post-form ,url ,fields))
-       (when (string-match "<form action=\"login\\.pl\" method=\"post\">"
-                          buffer)
+  `(when ,url
+     (with-temp-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))))
-     ,@body))
+        (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)
+         (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 +749,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 +769,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 +805,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)
@@ -1130,24 +1144,23 @@ Increase this value when unexpected error frequently occurs."
   ;; 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))
+      (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)))
 
@@ -1211,21 +1224,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 +1254,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 +1350,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 +1359,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.
@@ -1423,41 +1422,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)))
 
@@ -1671,28 +1669,27 @@ Increase this value when unexpected error frequently occurs."
   ;; 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)
+      (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)))
 
@@ -1779,15 +1776,15 @@ 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.
@@ -1860,46 +1857,44 @@ Increase this value when unexpected error frequently occurs."
   ;; 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)
+      (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)))
 
@@ -2246,16 +2241,7 @@ Increase this value when unexpected error frequently occurs."
         (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)))
+                 (funcall list-page parent) regexp range t)))
       (mapcar (lambda (item)
                (mixi-make-comment parent (mixi-make-friend
                                           (nth 7 item) (nth 8 item))
@@ -2312,8 +2298,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 +2311,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 +2353,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 +2364,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 +2498,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 +2507,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.
@@ -2663,25 +2649,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)))