* mixi.el (mixi-expand-url): New macro.
[elisp/mixi.git] / mixi.el
diff --git a/mixi.el b/mixi.el
index ad0f923..15314c6 100644 (file)
--- a/mixi.el
+++ b/mixi.el
@@ -36,6 +36,8 @@
 ;;  * mixi-get-new-topics
 ;;  * mixi-get-comments
 ;;  * mixi-get-new-comments
+;;  * mixi-get-messages
+;;  * mixi-get-introductions
 
 ;; Example:
 ;;
 
 ;;; Code:
 
-(condition-case nil
-    (require 'url)
-  (error))
-
-(condition-case nil
-    (require 'w3m)
-  (error))
-
 (eval-when-compile (require 'cl))
 
 (defgroup mixi nil
   :type 'coding-system
   :group 'mixi)
 
-(defcustom mixi-retrieve-function
-  (if (fboundp 'url-retrieve-synchronously)
-      'mixi-w3-retrieve 'mixi-w3m-retrieve)
-  "*The function for retrieving."
-  :type '(choice (const :tag "Using w3" mixi-w3-retrieve)
-                (const :tag "Using w3m" mixi-w3m-retrieve)
-                (const :tag "Using curl" mixi-curl-retrieve)
-                (function :format "Other function: %v\n" :size 0))
-  :group 'mixi)
-
 (defcustom mixi-curl-program "curl"
   "*The program name of `curl'."
   :type 'file
   :type 'file
   :group 'mixi)
 
+(defcustom mixi-retrieve-function
+  (or (condition-case nil
+         (progn
+           (require 'url)
+           (if (fboundp 'url-retrieve-synchronously)
+               'mixi-w3-retrieve))
+       (error))
+      (condition-case nil
+         (progn
+           (require 'w3m)
+           'mixi-w3m-retrieve)
+       (error))
+      (if (and (fboundp 'executable-find)
+              (executable-find mixi-curl-program))
+         'mixi-curl-retrieve)
+      (error "Can't set `mixi-retrieve-function'"))
+  "*The function for retrieving."
+  :type '(radio (const :tag "Using w3" mixi-w3-retrieve)
+               (const :tag "Using w3m" mixi-w3m-retrieve)
+               (const :tag "Using curl" mixi-curl-retrieve)
+               (function :format "Other function: %v\n" :size 0))
+  :group 'mixi)
+
 (defcustom mixi-default-email nil
   "*Default E-mail address that is used to login automatically."
-  :type '(choice (string :tag "E-mail address")
-                (const :tag "Asked when it is necessary" nil))
+  :type '(radio (string :tag "E-mail address")
+               (const :tag "Asked when it is necessary" nil))
   :group 'mixi)
 
 (defcustom mixi-default-password nil
   "*Default password that is used to login automatically."
-  :type '(choice (string :tag "Password")
-                (const :tag "Asked when it is necessary" nil))
+  :type '(radio (string :tag "Password")
+               (const :tag "Asked when it is necessary" nil))
   :group 'mixi)
 
 (defcustom mixi-accept-adult-contents t
@@ -167,8 +174,9 @@ Increase this value when unexpected error frequently occurs."
 
 (defcustom mixi-cache-expires 3600
   "*Seconds for expiration of a cached object."
-  :type '(choice (integer :tag "Expired seconds")
-                (const :tag "Don't expire" nil))
+  :type '(radio (integer :tag "Expired seconds")
+               (const :tag "Don't expire" nil)
+               (const :tag "Don't cache" t))
   :group 'mixi)
 
 ;; FIXME: Not implemented.
@@ -213,6 +221,9 @@ Increase this value when unexpected error frequently occurs."
     (sit-for mixi-continuously-access-interval)
     (funcall mixi-retrieve-function url post-data)))
 
+(defmacro mixi-expand-url (url)
+  `(concat mixi-url ,url))
+
 (defun mixi-w3-retrieve (url &optional post-data)
   "Retrieve the URL and return gotten strings."
   (if post-data
@@ -221,7 +232,7 @@ Increase this value when unexpected error frequently occurs."
        (setq url-request-data post-data))
     (setq url-request-method "GET")
     (setq url-request-data nil))
-  (let* ((url (url-expand-file-name url mixi-url))
+  (let* ((url (mixi-expand-url url))
         (buffer (url-retrieve-synchronously url))
         ret)
     (unless (bufferp buffer)
@@ -245,7 +256,7 @@ Increase this value when unexpected error frequently occurs."
 
 (defun mixi-w3m-retrieve (url &optional post-data)
   "Retrieve the URL and return gotten strings."
-  (let ((url (w3m-expand-url url mixi-url)))
+  (let ((url (mixi-expand-url url)))
     (with-temp-buffer
       (if (not (string= (w3m-retrieve url nil nil post-data) "text/html"))
          (error (mixi-message "Cannot retrieve"))
@@ -272,7 +283,7 @@ Increase this value when unexpected error frequently occurs."
                                 (list "-i" "-L" "-s"
                                       "-b" mixi-curl-cookie-file
                                       "-c" mixi-curl-cookie-file
-                                      (concat mixi-url url)))))
+                                      (mixi-expand-url url)))))
            (set-process-sentinel process #'ignore))
        (set-default-file-modes orig-mode))
       (when post-data
@@ -327,6 +338,7 @@ Increase this value when unexpected error frequently occurs."
         (setq buffer (funcall mixi-retrieve-function ,url))))
      ,@body))
 (put 'with-mixi-retrieve 'lisp-indent-function 'defun)
+(put 'with-mixi-retrieve 'edebug-form-spec '(form body))
 
 (defun mixi-get-matched-items (url max-numbers regexp)
   "Get matched items to REGEXP in URL."
@@ -337,7 +349,7 @@ Increase this value when unexpected error frequently occurs."
        (with-mixi-retrieve (format url page)
          (let ((pos 0))
            (while (and (string-match regexp buffer pos)
-                       (< (length ids) max-numbers))
+                       (or (null max-numbers) (< (length ids) max-numbers)))
              (let ((num 1)
                    list)
                (while (match-string num buffer)
@@ -357,7 +369,7 @@ Increase this value when unexpected error frequently occurs."
 (defun mixi-remove-markup (string)
   "Remove markups from STRING."
   (with-temp-buffer
-    (insert string)
+    (insert (or string ""))
     (save-excursion
       (goto-char (point-min))
       (while (search-forward "<!--" nil t)
@@ -373,105 +385,42 @@ Increase this value when unexpected error frequently occurs."
     (buffer-string)))
 
 ;; Cache.
-
-;; stolen from time-date.el
-(defmacro with-mixi-decoded-time-value (varlist &rest body)
-  "Decode a time value and bind it according to VARLIST, then eval BODY.
-
-The value of the last form in BODY is returned.
-
-Each element of the list VARLIST is a list of the form
-\(HIGH-SYMBOL LOW-SYMBOL MICRO-SYMBOL [TYPE-SYMBOL] TIME-VALUE).
-The time value TIME-VALUE is decoded and the result it bound to
-the symbols HIGH-SYMBOL, LOW-SYMBOL and MICRO-SYMBOL.
-
-The optional TYPE-SYMBOL is bound to the type of the time value.
-Type 0 is the cons cell (HIGH . LOW), type 1 is the list (HIGH
-LOW), and type 3 is the list (HIGH LOW MICRO)."
-  (declare (indent 1)
-          (debug ((&rest (symbolp symbolp symbolp &or [symbolp form] form))
-                  body)))
-  (if varlist
-      (let* ((elt (pop varlist))
-            (high (pop elt))
-            (low (pop elt))
-            (micro (pop elt))
-            (type (unless (eq (length elt) 1)
-                    (pop elt)))
-            (time-value (car elt))
-            (gensym (make-symbol "time")))
-       `(let* ,(append `((,gensym ,time-value)
-                         (,high (pop ,gensym))
-                         ,low ,micro)
-                       (when type `(,type)))
-          (if (consp ,gensym)
-              (progn
-                (setq ,low (pop ,gensym))
-                (if ,gensym
-                    ,(append `(setq ,micro (car ,gensym))
-                             (when type `(,type 2)))
-                  ,(append `(setq ,micro 0)
-                           (when type `(,type 1)))))
-            ,(append `(setq ,low ,gensym ,micro 0)
-                     (when type `(,type 0))))
-          (with-mixi-decoded-time-value ,varlist ,@body)))
-    `(progn ,@body)))
-(put 'with-mixi-decoded-time-value 'lisp-indent-function 'defun)
-
-;; stolen from time-date.el
-(defun mixi-encode-time-value (high low micro type)
-  "Encode HIGH, LOW, and MICRO into a time value of type TYPE.
-Type 0 is the cons cell (HIGH . LOW), type 1 is the list (HIGH LOW),
-and type 3 is the list (HIGH LOW MICRO)."
-  (cond
-   ((eq type 0) (cons high low))
-   ((eq type 1) (list high low))
-   ((eq type 2) (list high low micro))))
-
 ;; stolen from time-date.el
 (defun mixi-time-less-p (t1 t2)
   "Say whether time value T1 is less than time value T2."
-  (with-mixi-decoded-time-value ((high1 low1 micro1 t1)
-                                (high2 low2 micro2 t2))
-    (or (< high1 high2)
-       (and (= high1 high2)
-            (or (< low1 low2)
-                (and (= low1 low2)
-                     (< micro1 micro2)))))))
+  (unless (numberp (cdr t1))
+    (setq t1 (cons (car t1) (car (cdr t1)))))
+  (unless (numberp (cdr t2))
+    (setq t2 (cons (car t2) (car (cdr t2)))))
+  (or (< (car t1) (car t2))
+      (and (= (car t1) (car t2))
+          (< (cdr t1) (cdr t2)))))
 
-;; stolen from time-date.el
 (defun mixi-time-add (t1 t2)
   "Add two time values.  One should represent a time difference."
-  (with-mixi-decoded-time-value ((high low micro type t1)
-                                (high2 low2 micro2 type2 t2))
-    (setq high (+ high high2)
-         low (+ low low2)
-         micro (+ micro micro2)
-         type (max type type2))
-    (when (>= micro 1000000)
-      (setq low (1+ low)
-           micro (- micro 1000000)))
-    (when (>= low 65536)
-      (setq high (1+ high)
-           low (- low 65536)))
-    (mixi-encode-time-value high low micro type)))
+  (unless (numberp (cdr t1))
+    (setq t1 (cons (car t1) (car (cdr t1)))))
+  (unless (numberp (cdr t2))
+    (setq t2 (cons (car t2) (car (cdr t2)))))
+  (let ((low (+ (cdr t1) (cdr t2))))
+    (cons (+ (car t1) (car t2) (lsh low -16)) low)))
 
 ;; stolen from time-date.el
 (defun mixi-seconds-to-time (seconds)
   "Convert SECONDS (a floating point number) to a time value."
-  (list (floor seconds 65536)
-       (floor (mod seconds 65536))
-       (floor (* (- seconds (ffloor seconds)) 1000000))))
+  (cons (floor seconds 65536)
+       (floor (mod seconds 65536))))
 
 (defun mixi-cache-expired-p (object)
   "Whether a cache of OBJECT is expired."
-  ;; FIXME: Use method instead of `(aref (cdr object) 0)'.
-  (let ((timestamp (aref (cdr object) 0)))
+  (let ((timestamp (mixi-object-timestamp object)))
     (unless (or (null mixi-cache-expires)
                 (null timestamp))
-      (mixi-time-less-p
-       (mixi-time-add timestamp (mixi-seconds-to-time mixi-cache-expires))
-       (current-time)))))
+      (if (numberp mixi-cache-expires)
+         (mixi-time-less-p
+          (mixi-time-add timestamp (mixi-seconds-to-time mixi-cache-expires))
+          (current-time))
+       t))))
 
 (defun mixi-make-cache (key value table)
   "Make a cache object and return it."
@@ -497,6 +446,13 @@ and type 3 is the list (HIGH LOW MICRO)."
   (let ((class (mixi-object-class object)))
     (substring (symbol-name class) (length mixi-object-prefix))))
 
+(defun mixi-object-timestamp (object)
+  "Return the timestamp of OJBECT."
+  (unless (mixi-object-p object)
+    (signal 'wrong-type-argument (list 'mixi-object-p object)))
+  (aref (cdr object) 0))
+(defalias 'mixi-object-realize-p 'mixi-object-timestamp)
+
 (defun mixi-object-id (object)
   "Return the id of OBJECT."
   (unless (mixi-object-p object)
@@ -505,6 +461,15 @@ and type 3 is the list (HIGH LOW MICRO)."
                              (mixi-object-name object) "-id"))))
     (funcall func object)))
 
+(defun mixi-object-set-timestamp (object timestamp)
+  "Set the timestamp of OBJECT."
+  (unless (mixi-object-p object)
+    (signal 'wrong-type-argument (list 'mixi-object-p object)))
+  (aset (cdr object) 0 timestamp))
+
+(defmacro mixi-object-touch (object)
+  `(mixi-object-set-timestamp ,object (current-time)))
+
 ;; Friend object.
 (defvar mixi-friend-cache (make-hash-table :test 'equal))
 (defun mixi-make-friend (id &optional nick)
@@ -553,7 +518,7 @@ and type 3 is the list (HIGH LOW MICRO)."
 (defun mixi-friend-realize (friend)
   "Realize a FRIEND."
   ;; FIXME: Check a expiration of cache?
-  (unless (mixi-friend-realize-p friend)
+  (unless (mixi-object-realize-p friend)
     (let (buf)
       (with-mixi-retrieve (mixi-friend-page friend)
        (setq buf buffer))
@@ -594,13 +559,7 @@ and type 3 is the list (HIGH LOW MICRO)."
       (when (string-match mixi-friend-profile-regexp buf)
        (mixi-friend-set-profile
         friend (mixi-remove-markup (match-string 1 buf)))))
-    (mixi-friend-touch friend)))
-
-(defun mixi-friend-realize-p (friend)
-  "Return the timestamp of FRIEND."
-  (unless (mixi-friend-p friend)
-    (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
-  (aref (cdr friend) 0))
+    (mixi-object-touch friend)))
 
 (defun mixi-friend-id (friend)
   "Return the id of FRIEND."
@@ -693,12 +652,6 @@ and type 3 is the list (HIGH LOW MICRO)."
   (mixi-friend-realize friend)
   (aref (cdr friend) 13))
 
-(defun mixi-friend-touch (friend)
-  "Set the timestamp of FRIEND."
-  (unless (mixi-friend-p friend)
-    (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
-  (aset (cdr friend) 0 (current-time)))
-
 (defun mixi-friend-set-nick (friend nick)
   "Set the nick of FRIEND."
   (unless (mixi-friend-p friend)
@@ -901,7 +854,7 @@ and type 3 is the list (HIGH LOW MICRO)."
 (defun mixi-diary-realize (diary)
   "Realize a DIARY."
   ;; FIXME: Check a expiration of cache?
-  (unless (mixi-diary-realize-p diary)
+  (unless (mixi-object-realize-p diary)
     (with-mixi-retrieve (mixi-diary-page diary)
       (if (string-match mixi-diary-owner-nick-regexp buffer)
          (mixi-friend-set-nick (mixi-diary-owner diary)
@@ -922,13 +875,7 @@ and type 3 is the list (HIGH LOW MICRO)."
          (mixi-diary-set-content diary (mixi-remove-markup
                                         (match-string 1 buffer)))
        (signal 'error (list 'cannot-find-content diary))))
-    (mixi-diary-touch diary)))
-
-(defun mixi-diary-realize-p (diary)
-  "Return the timestamp of DIARY."
-  (unless (mixi-diary-p diary)
-    (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
-  (aref (cdr diary) 0))
+    (mixi-object-touch diary)))
 
 (defun mixi-diary-owner (diary)
   "Return the owner of DIARY."
@@ -963,12 +910,6 @@ and type 3 is the list (HIGH LOW MICRO)."
   (mixi-diary-realize diary)
   (aref (cdr diary) 5))
 
-(defun mixi-diary-touch (diary)
-  "Set the timestamp of DIARY."
-  (unless (mixi-diary-p diary)
-    (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
-  (aset (cdr diary) 0 (current-time)))
-
 (defun mixi-diary-set-time (diary time)
   "Set the time of DIARY."
   (unless (mixi-diary-p diary)
@@ -997,7 +938,8 @@ and type 3 is the list (HIGH LOW MICRO)."
 (defun mixi-get-diaries (&rest args)
   "Get diaries of FRIEND."
   (when (> (length args) 2)
-    (signal 'wrong-number-of-arguments (list 'mixi-get-friends (length args))))
+    (signal 'wrong-number-of-arguments
+           (list 'mixi-get-diaries (length args))))
   (let ((friend (nth 0 args))
        (max-numbers (nth 1 args)))
     (when (or (not (mixi-friend-p friend)) (mixi-friend-p max-numbers))
@@ -1065,7 +1007,7 @@ and type 3 is the list (HIGH LOW MICRO)."
 (defun mixi-community-realize (community)
   "Realize a COMMUNITY."
   ;; FIXME: Check a expiration of cache?
-  (unless (mixi-community-realize-p community)
+  (unless (mixi-object-realize-p community)
     (with-mixi-retrieve (mixi-community-page community)
       (if (string-match mixi-community-nodata-regexp buffer)
          ;; FIXME: Set all members?
@@ -1104,13 +1046,7 @@ and type 3 is the list (HIGH LOW MICRO)."
            (mixi-community-set-description
             community (mixi-remove-markup (match-string 1 buffer)))
          (signal 'error (list 'cannot-find-description community)))))
-    (mixi-community-touch community)))
-
-(defun mixi-community-realize-p (community)
-  "Return the timestamp of COMMUNITY."
-  (unless (mixi-community-p community)
-    (signal 'wrong-type-argument (list 'mixi-community-p community)))
-  (aref (cdr community) 0))
+    (mixi-object-touch community)))
 
 (defun mixi-community-id (community)
   "Return the id of COMMUNITY."
@@ -1175,12 +1111,6 @@ and type 3 is the list (HIGH LOW MICRO)."
   (mixi-community-realize community)
   (aref (cdr community) 9))
 
-(defun mixi-community-touch (community)
-  "Set the timestamp of COMMUNITY."
-  (unless (mixi-community-p community)
-    (signal 'wrong-type-argument (list 'mixi-community-p community)))
-  (aset (cdr community) 0 (current-time)))
-
 (defun mixi-community-set-name (community name)
   "Set the name of COMMUNITY."
   (unless (mixi-community-p community)
@@ -1243,7 +1173,8 @@ and type 3 is the list (HIGH LOW MICRO)."
 (defun mixi-get-communities (&rest args)
   "Get communities of FRIEND."
   (when (> (length args) 2)
-    (signal 'wrong-number-of-arguments (list 'mixi-get-friends (length args))))
+    (signal 'wrong-number-of-arguments
+           (list 'mixi-get-communities (length args))))
   (let ((friend (nth 0 args))
        (max-numbers (nth 1 args)))
     (when (or (not (mixi-friend-p friend)) (mixi-friend-p max-numbers))
@@ -1293,7 +1224,7 @@ and type 3 is the list (HIGH LOW MICRO)."
 (defun mixi-topic-realize (topic)
   "Realize a TOPIC."
   ;; FIXME: Check a expiration of cache?
-  (unless (mixi-topic-realize-p topic)
+  (unless (mixi-object-realize-p topic)
     (with-mixi-retrieve (mixi-topic-page topic)
       (if (string-match mixi-topic-time-regexp buffer)
          (mixi-topic-set-time
@@ -1315,13 +1246,7 @@ and type 3 is the list (HIGH LOW MICRO)."
          (mixi-topic-set-content topic (mixi-remove-markup
                                         (match-string 2 buffer)))
        (signal 'error (list 'cannot-find-content topic))))
-    (mixi-topic-touch topic)))
-
-(defun mixi-topic-realize-p (topic)
-  "Return the timestamp of TOPIC."
-  (unless (mixi-topic-p topic)
-    (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
-  (aref (cdr topic) 0))
+    (mixi-object-touch topic)))
 
 (defun mixi-topic-community (topic)
   "Return the community of TOPIC."
@@ -1363,12 +1288,6 @@ and type 3 is the list (HIGH LOW MICRO)."
   (mixi-topic-realize topic)
   (aref (cdr topic) 6))
 
-(defun mixi-topic-touch (topic)
-  "Set the timestamp of TOPIC."
-  (unless (mixi-topic-p topic)
-    (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
-  (aset (cdr topic) 0 (current-time)))
-
 (defun mixi-topic-set-time (topic time)
   "Set the time of TOPIC."
   (unless (mixi-topic-p topic)
@@ -1479,7 +1398,9 @@ and type 3 is the list (HIGH LOW MICRO)."
 <td>
 <a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.+\\)</a>
 
-</td>
+\\(<font color=\"#f2ddb7\">|</font> <a href=[^>]+>ºï½ü</a>
+
+\\|\\)</td>
 </tr>
 </table>
 </td>
@@ -1504,15 +1425,15 @@ and type 3 is the list (HIGH LOW MICRO)."
 <td rowspan=\"2\" width=\"110\" bgcolor=\"#f2ddb7\" align=\"center\" nowrap>
 \\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü<br>
 \\([0-9]+\\):\\([0-9]+\\)<br>
-\\(</td>\\)
+</td>
 <td bgcolor=\"#fdf9f2\">&nbsp;<font color=\"#f8a448\">
-<b>&nbsp;&nbsp;[0-9]+</b>:</font>&nbsp;
-
-<a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.+\\)</a>
+<b>[^<]+</b>:</font>&nbsp;
+\\(
+\\|\\)<a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.+\\)</a>
 
+\\(
 
-
-</td>
+\\|\\)</td>
 </tr>
 <tr>
 <td bgcolor=\"#ffffff\" align=\"center\">
@@ -1548,7 +1469,7 @@ and type 3 is the list (HIGH LOW MICRO)."
                                    (string-to-number (nth 2 item))
                                    (string-to-number (nth 1 item))
                                    (string-to-number (nth 0 item)))
-                                  (mixi-remove-markup (nth 8 item))))
+                                  (mixi-remove-markup (nth 9 item))))
              items))))
 
 (defmacro mixi-new-comment-list-page ()
@@ -1569,6 +1490,255 @@ and type 3 is the list (HIGH LOW MICRO)."
                (mixi-get-comments diary)))
            items)))
 
+;; Message object.
+(defconst mixi-message-box-list '(inbox outbox savebox thrash)) ; thrash?
+
+(defmacro mixi-message-box-p (box)
+  `(when (memq ,box mixi-message-box-list)
+     t))
+
+(defun mixi-message-box-name (box)
+  "Return the name of BOX."
+  (unless (mixi-message-box-p box)
+    (signal 'wrong-type-argument (list 'mixi-message-box-p box)))
+  (symbol-name box))
+
+(defvar mixi-message-cache (make-hash-table :test 'equal))
+(defun mixi-make-message (id box)
+  "Return a message object."
+  (mixi-make-cache (list id box)
+                  (cons 'mixi-message (vector nil id box nil nil nil nil))
+                  mixi-message-cache))
+
+(defmacro mixi-message-p (message)
+  `(eq (mixi-object-class ,message) 'mixi-message))
+
+(defmacro mixi-message-page (message)
+  `(concat "/view_message.pl?id=" (mixi-message-id ,message)
+          "&box=" (mixi-message-box ,message)))
+
+(defconst mixi-message-owner-regexp
+  "<font COLOR=#996600>º¹½Ð¿Í</font>&nbsp;:&nbsp;<a HREF=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.+\\)</a>")
+(defconst mixi-message-title-regexp
+  "<font COLOR=#996600>·ï¡¡Ì¾</font>&nbsp;:&nbsp;\\(.+\\)
+</td>")
+(defconst mixi-message-time-regexp
+  "<font COLOR=#996600>Æü¡¡ÉÕ</font>&nbsp;:&nbsp;\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\)»þ\\([0-9]+\\)ʬ&nbsp;&nbsp;")
+(defconst mixi-message-content-regexp
+  "<tr><td CLASS=h120>\\(.+\\)</td></tr>")
+
+(defun mixi-message-realize (message)
+  "Realize a MESSAGE."
+  (unless (mixi-object-realize-p message)
+    (with-mixi-retrieve (mixi-message-page message)
+      (if (string-match mixi-message-owner-regexp buffer)
+         (mixi-message-set-owner message
+                                 (mixi-make-friend (match-string 1 buffer)
+                                                   (match-string 2 buffer)))
+       (signal 'error (list 'cannot-find-owner message)))
+      (if (string-match mixi-message-title-regexp buffer)
+         (mixi-message-set-title message (match-string 1 buffer))
+       (signal 'error (list 'cannot-find-title message)))
+      (if (string-match mixi-message-time-regexp buffer)
+         (mixi-message-set-time
+          message (encode-time 0 (string-to-number (match-string 5 buffer))
+                               (string-to-number (match-string 4 buffer))
+                               (string-to-number (match-string 3 buffer))
+                               (string-to-number (match-string 2 buffer))
+                               (string-to-number (match-string 1 buffer))))
+       (signal 'error (list 'cannot-find-time message)))
+      (if (string-match mixi-message-content-regexp buffer)
+         (mixi-message-set-content message (mixi-remove-markup
+                                            (match-string 1 buffer)))
+       (signal 'error (list 'cannot-find-content message))))
+    (mixi-object-touch message)))
+
+(defun mixi-message-id (message)
+  "Return the id of MESSAGE."
+  (unless (mixi-message-p message)
+    (signal 'wrong-type-argument (list 'mixi-message-p message)))
+  (aref (cdr message) 1))
+
+(defun mixi-message-box (message)
+  "Return the box of MESSAGE."
+  (unless (mixi-message-p message)
+    (signal 'wrong-type-argument (list 'mixi-message-p message)))
+  (aref (cdr message) 2))
+
+(defun mixi-message-owner (message)
+  "Return the owner of MESSAGE."
+  (unless (mixi-message-p message)
+    (signal 'wrong-type-argument (list 'mixi-message-p message)))
+  (mixi-message-realize message)
+  (aref (cdr message) 3))
+
+(defun mixi-message-title (message)
+  "Return the title of MESSAGE."
+  (unless (mixi-message-p message)
+    (signal 'wrong-type-argument (list 'mixi-message-p message)))
+  (mixi-message-realize message)
+  (aref (cdr message) 4))
+
+(defun mixi-message-time (message)
+  "Return the date of MESSAGE."
+  (unless (mixi-message-p message)
+    (signal 'wrong-type-argument (list 'mixi-message-p message)))
+  (mixi-message-realize message)
+  (aref (cdr message) 5))
+
+(defun mixi-message-content (message)
+  "Return the content of MESSAGE."
+  (unless (mixi-message-p message)
+    (signal 'wrong-type-argument (list 'mixi-message-p message)))
+  (mixi-message-realize message)
+  (aref (cdr message) 6))
+
+(defun mixi-message-set-owner (message owner)
+  "Set the owner of MESSAGE."
+  (unless (mixi-message-p message)
+    (signal 'wrong-type-argument (list 'mixi-message-p message)))
+  (aset (cdr message) 3 owner))
+
+(defun mixi-message-set-title (message title)
+  "Set the title of MESSAGE."
+  (unless (mixi-message-p message)
+    (signal 'wrong-type-argument (list 'mixi-message-p message)))
+  (aset (cdr message) 4 title))
+
+(defun mixi-message-set-time (message time)
+  "Set the date of MESSAGE."
+  (unless (mixi-message-p message)
+    (signal 'wrong-type-argument (list 'mixi-message-p message)))
+  (aset (cdr message) 5 time))
+
+(defun mixi-message-set-content (message content)
+  "Set the content of MESSAGE."
+  (unless (mixi-message-p message)
+    (signal 'wrong-type-argument (list 'mixi-message-p message)))
+  (aset (cdr message) 6 content))
+
+(defmacro mixi-message-list-page (&optional box)
+  `(concat "/list_message.pl?page=%d"
+          (when ,box (concat "&box=" ,box))))
+
+(defconst mixi-message-list-regexp
+  "<td><a HREF=\"view_message\\.pl\\?id=\\(.+\\)&box=\\(.+\\)\">")
+
+(defun mixi-get-messages (&rest args)
+  "Get messages."
+  (when (> (length args) 2)
+    (signal 'wrong-number-of-arguments
+           (list 'mixi-get-messages (length args))))
+  (let ((box (nth 0 args))
+       (max-numbers (nth 1 args)))
+    (when (or (not (mixi-message-box-p box))
+             (mixi-message-box-p max-numbers))
+      (setq box (nth 1 args))
+      (setq max-numbers (nth 0 args)))
+    (let ((items (mixi-get-matched-items
+                 (mixi-message-list-page
+                  (when box (mixi-message-box-name box)))
+                 max-numbers
+                 mixi-message-list-regexp)))
+      (mapcar (lambda (item)
+               (mixi-make-message (nth 0 item) (nth 1 item)))
+             items))))
+
+;; Introduction object.
+(defun mixi-make-introduction (parent owner content)
+  "Return a introduction object."
+  (cons 'mixi-introduction (vector parent owner content)))
+
+(defmacro mixi-introduction-p (introduction)
+  `(eq (mixi-object-class ,introduction) 'mixi-introduction))
+
+(defun mixi-introduction-parent (introduction)
+  "Return the parent of INTRODUCTION."
+  (unless (mixi-introduction-p introduction)
+    (signal 'wrong-type-argument (list 'mixi-introduction-p introduction)))
+  (aref (cdr introduction) 0))
+
+(defun mixi-introduction-owner (introduction)
+  "Return the owner of INTRODUCTION."
+  (unless (mixi-introduction-p introduction)
+    (signal 'wrong-type-argument (list 'mixi-introduction-p introduction)))
+  (aref (cdr introduction) 1))
+
+(defun mixi-introduction-content (introduction)
+  "Return the content of INTRODUCTION."
+  (unless (mixi-introduction-p introduction)
+    (signal 'wrong-type-argument (list 'mixi-introduction-p introduction)))
+  (aref (cdr introduction) 3))
+
+(defmacro mixi-introduction-list-page (&optional friend)
+  `(concat "/show_intro.pl?page=%d"
+          (when ,friend (concat "&id=" (mixi-friend-id ,friend)))))
+
+(defconst mixi-introduction-list-regexp
+  "<tr bgcolor=#FFFFFF>
+<td WIDTH=150 background=http://img\\.mixi\\.jp/img/bg_line\\.gif align=\"center\"><a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\"><img src=\".+\" border=0><br>
+\\(.+\\)</td></a>
+
+<td WIDTH=480>
+\\(´Ø·¸¡§.+<br>
+
+
+\\(\\(.\\|\n<br>\\)+\\)\\|
+\\(\\(.\\|\n<br>\\)+\\)\\)
+
+
+
+
+</td>
+</tr>")
+(defconst mixi-my-introduction-list-regexp
+  "<tr bgcolor=#FFFFFF>
+<td WIDTH=150 background=http://img\\.mixi\\.jp/img/bg_line\\.gif align=\"center\"><a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\"><img src=\".+\" border=0><br>
+\\(.+\\)</td></a>
+
+
+<td WIDTH=480>
+\\(´Ø·¸¡§.+<br>
+
+
+\\(\\(.\\|\n<br>\\)+\\)\\|
+\\(\\(.\\|\n<br>\\)+\\)\\)
+
+
+<br>
+<a href=\"edit_intro\\.pl\\?id=\\1&type=edit\">¤³¤Îͧ¿Í¤ò¾Ò²ð¤¹¤ë</a>
+
+
+<BR>
+<a href=\"delete_intro\\.pl\\?id=\\1\">ºï½ü</a>
+
+</td>
+</tr>")
+
+(defun mixi-get-introductions (&rest args)
+  "Get introductions."
+  (when (> (length args) 2)
+    (signal 'wrong-number-of-arguments
+           (list 'mixi-get-introduction (length args))))
+  (let ((friend (nth 0 args))
+       (max-numbers (nth 1 args)))
+    (when (or (not (mixi-friend-p friend)) (mixi-friend-p max-numbers))
+      (setq friend (nth 1 args))
+      (setq max-numbers (nth 0 args)))
+    (unless (or (null friend) (mixi-friend-p friend))
+      (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
+    (let* ((regexp (if friend mixi-introduction-list-regexp
+                    mixi-my-introduction-list-regexp))
+          (items (mixi-get-matched-items (mixi-introduction-list-page friend)
+                                         max-numbers
+                                         regexp)))
+      (mapcar (lambda (item)
+               (mixi-make-introduction (or friend (mixi-make-me))
+                                       (mixi-make-friend (nth 0 item)
+                                                         (nth 1 item))
+                                       (mixi-remove-markup (nth 2 item))))
+             items))))
+
 (provide 'mixi)
 
 ;;; mixi.el ends here