(mixi-diary-content-regexp): Fix regexp.
[elisp/mixi.git] / mixi.el
diff --git a/mixi.el b/mixi.el
index 8b3a4d5..bd30e30 100644 (file)
--- a/mixi.el
+++ b/mixi.el
@@ -1,4 +1,4 @@
-;; mixi.el --- API libraries for accessing to mixi
+;; mixi.el --- API libraries for accessing to mixi -*- coding: euc-jp -*-
 
 ;; Copyright (C) 2005,2006 OHASHI Akira
 
 ;;       (buffer (get-buffer-create "*temp*"))
 ;;       (format "%Y/%m/%d %H:%M"))
 ;;   (pop-to-buffer buffer)
-;;   (mapc (lambda (diary)
-;;       (let ((subject (mixi-diary-title diary))
-;;             (from (mixi-friend-nick (mixi-diary-owner diary)))
-;;             (date (format-time-string format (mixi-diary-time diary)))
-;;             (body (mixi-remove-markup (mixi-diary-content diary))))
-;;         (insert "From: " from "\n"
-;;                 "Subject: " subject "\n"
-;;                 "Date: " date "\n\n"
-;;                 body "\n\n")))
-;;     (mixi-get-new-diaries range))
+;;   (let ((diaries (mixi-get-new-diaries range)))
+;;     (while diaries
+;;       (let* ((diary (car diaries))
+;;          (subject (mixi-diary-title diary))
+;;          (from (mixi-friend-nick (mixi-diary-owner diary)))
+;;          (date (format-time-string format (mixi-diary-time diary)))
+;;          (body (mixi-remove-markup (mixi-diary-content diary))))
+;;     (insert "From: " from "\n"
+;;             "Subject: " subject "\n"
+;;             "Date: " date "\n\n"
+;;             body "\n\n"))
+;;       (setq diaries (cdr diaries))))
 ;;   (set-buffer-modified-p nil)
 ;;   (setq buffer-read-only t)
 ;;   (goto-char (point-min)))
 ;;       (buffer (get-buffer-create "*temp*"))
 ;;       (format "%Y/%m/%d %H:%M"))
 ;;   (pop-to-buffer buffer)
-;;   (mapc (lambda (diary)
-;;       (let ((subject (mixi-diary-title diary))
-;;             (from (mixi-friend-nick (mixi-diary-owner diary)))
-;;             (date (format-time-string format (mixi-diary-time diary)))
-;;             (body (mixi-remove-markup (mixi-diary-content diary))))
-;;         (insert "From: " from "\n"
-;;                 "Subject: " subject "\n"
-;;                 "Date: " date "\n\n"
-;;                 body "\n\n")
-;;         (mapc (lambda (comment)
-;;                 (let ((from (mixi-friend-nick
-;;                              (mixi-comment-owner comment)))
-;;                       (subject (concat "Re: " subject))
-;;                       (date (format-time-string
-;;                              format (mixi-comment-time comment)))
-;;                       (body (mixi-remove-markup
-;;                              (mixi-comment-content comment))))
-;;                   (insert "From: " from "\n"
-;;                           "Subject: " subject "\n"
-;;                           "Date: " date "\n\n"
-;;                           body "\n\n")))
-;;               (mixi-get-comments diary range))))
-;;     (mixi-get-new-diaries range))
+;;   (let ((diaries (mixi-get-new-diaries range)))
+;;     (while diaries
+;;       (let* ((diary (car diaries))
+;;          (subject (mixi-diary-title diary))
+;;          (from (mixi-friend-nick (mixi-diary-owner diary)))
+;;          (date (format-time-string format (mixi-diary-time diary)))
+;;          (body (mixi-remove-markup (mixi-diary-content diary))))
+;;     (insert "From: " from "\n"
+;;             "Subject: " subject "\n"
+;;             "Date: " date "\n\n"
+;;             body "\n\n")
+;;     (let ((comments (mixi-get-comments diary range)))
+;;       (while comments
+;;         (let* ((comment (car comments))
+;;                (from (mixi-friend-nick (mixi-comment-owner comment)))
+;;                (subject (concat "Re: " subject))
+;;                (date (format-time-string format
+;;                                          (mixi-comment-time comment)))
+;;                (body (mixi-remove-markup (mixi-comment-content comment))))
+;;           (insert "From: " from "\n"
+;;                   "Subject: " subject "\n"
+;;                   "Date: " date "\n\n"
+;;                   body "\n\n"))
+;;         (setq comments (cdr comments)))))
+;;       (setq diaries (cdr diaries))))
 ;;   (set-buffer-modified-p nil)
 ;;   (setq buffer-read-only t)
 ;;   (goto-char (point-min)))
@@ -400,7 +404,7 @@ Increase this value when unexpected error frequently occurs."
     (mixi-curl-retrieve url nil (reverse form-data))))
 
 (defconst mixi-my-id-regexp
-  "<a href=\"add_diary\\.pl\\?id=\\([0-9]+\\)")
+  "<a href=\"show_profile\\.pl\\?id=\\([0-9]+\\)")
 
 (defun mixi-login (&optional email password)
   "Login to mixi."
@@ -411,9 +415,9 @@ 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 ((url "/login.pl"))
-      (when mixi-login-use-ssl
-       (setq url (concat "https://mixi.jp" url)))
+    (let ((url (mixi-expand-url "/login.pl")))
+      (when (and mixi-login-use-ssl (string-match "^http:" url))
+       (setq url (replace-match "https:" nil nil url)))
       (let ((buffer (mixi-retrieve url
                                   (concat "email=" email
                                           "&password=" password
@@ -694,24 +698,24 @@ Increase this value when unexpected error frequently occurs."
     (unless (file-directory-p cache-directory)
       (make-directory cache-directory t))
     (let ((caches (apropos-internal mixi-cache-regexp 'boundp)))
-      (mapc (lambda (symbol)
-             (with-temp-file (expand-file-name
-                              (substring (symbol-name symbol)
-                                         (length mixi-object-prefix))
-                              cache-directory)
-               (let ((coding-system-for-write mixi-coding-system)
-                     (cache (symbol-value symbol)))
-                 (insert "#s(hash-table size "
-                         (number-to-string (hash-table-count cache))
-                         " test equal data (\n")
-                 (maphash
-                  (lambda (key value)
-                    (let (print-level print-length)
-                      (insert (prin1-to-string key) " "
-                              (prin1-to-string value) "\n")))
-                  cache))
-               (insert "))")))
-           caches))))
+      (while caches
+       (with-temp-file (expand-file-name
+                        (substring (symbol-name (car caches))
+                                   (length mixi-object-prefix))
+                        cache-directory)
+         (let ((coding-system-for-write mixi-coding-system)
+               (cache (symbol-value (car caches))))
+           (insert "#s(hash-table size "
+                   (number-to-string (hash-table-count cache))
+                   " test equal data (\n")
+           (maphash
+            (lambda (key value)
+              (let (print-level print-length)
+                (insert (prin1-to-string key) " "
+                        (prin1-to-string value) "\n")))
+            cache))
+         (insert "))"))
+       (setq caches (cdr caches))))))
 
 ;; stolen (and modified) from lsdb.el
 (defun mixi-read-cache (&optional marker)
@@ -747,17 +751,17 @@ Increase this value when unexpected error frequently occurs."
       ;; FIXME: Load friend and community first.
       (let ((files (directory-files cache-directory t
                                    mixi-cache-file-regexp)))
-       (mapc (lambda (file)
-               (let ((buffer (find-file-noselect file)))
-                 (unwind-protect
-                     (save-excursion
-                       (set-buffer buffer)
-                       (goto-char (point-min))
-                       (re-search-forward "^#s(")
-                       (goto-char (match-beginning 0))
-                       (mixi-read-cache (point-marker)))
-                   (kill-buffer buffer))))
-             files)))))
+       (while files
+         (let ((buffer (find-file-noselect (car files))))
+           (unwind-protect
+               (save-excursion
+                 (set-buffer buffer)
+                 (goto-char (point-min))
+                 (re-search-forward "^#s(")
+                 (goto-char (match-beginning 0))
+                 (mixi-read-cache (point-marker)))
+             (kill-buffer buffer)))
+         (setq files (cdr files)))))))
 
 ;; Friend object.
 (defvar mixi-friend-cache (make-hash-table :test 'equal))
@@ -775,7 +779,7 @@ Increase this value when unexpected error frequently occurs."
   "Return a my object."
   (unless mixi-me
     (with-mixi-retrieve "/home.pl"
-      (if (re-search-forward mixi-my-id-regexp)
+      (if (re-search-forward mixi-my-id-regexp nil t)
          (setq mixi-me (mixi-make-friend (match-string 1)))
        (signal 'error (list 'who-am-i)))))
   mixi-me)
@@ -1070,7 +1074,7 @@ Increase this value when unexpected error frequently occurs."
 
 (defconst mixi-favorite-list-regexp
   "<td bgcolor=\"#FDF9F2\"><font color=\"#996600\">̾Á°</font></td>
-<td colspan=\"2\" bgcolor=\"#FFFFFF\"><a href=\"show_friend.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a></td>")
+<td colspan=\"2\" bgcolor=\"#FFFFFF\"><a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a></td>")
 
 ;;;###autoload
 (defun mixi-get-favorites (&optional range)
@@ -1161,7 +1165,7 @@ Increase this value when unexpected error frequently occurs."
 (defconst mixi-diary-title-regexp
   "<td \\(bgcolor\\|BGCOLOR\\)=\"?#FFF4E0\"? width=\"?430\"?>&nbsp;\\([^<]+\\)</td>")
 (defconst mixi-diary-content-regexp
-  "<td \\(class\\|CLASS\\)=\"?h12\"?>\\(.*\\)</td>")
+  "<td \\(class\\|CLASS\\)=\"?h12\"?>\\(\\(.\\|\n\\)*?\\)</td>")
 
 (defun mixi-realize-diary (diary &optional page)
   "Realize a DIARY."
@@ -1436,25 +1440,25 @@ Increase this value when unexpected error frequently occurs."
 (defconst mixi-community-name-regexp
   "<td WIDTH=345>\\(.*\\)</td></tr>")
 (defconst mixi-community-birthday-regexp
-  "<td BGCOLOR=#F2DDB7 WIDTH=80><font COLOR=#996600>³«ÀßÆü</font></td>\r
+  "<td BGCOLOR=#F2DDB7 WIDTH=80><font COLOR=#996600>³«ÀßÆü</font></td>
 <td WIDTH=345>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü")
 ;; FIXME: Care when the owner has seceded.
 (defconst mixi-community-owner-regexp
-  "<td BGCOLOR=#F2DDB7 WIDTH=80><font COLOR=#996600>´ÉÍý¿Í</font></td>\r
-<td WIDTH=345>\r
-<table style=\"width: 100%;\"><tr><td>\r
+  "<td BGCOLOR=#F2DDB7 WIDTH=80><font COLOR=#996600>´ÉÍý¿Í</font></td>
+<td WIDTH=345>
+<table style=\"width: 100%;\"><tr><td>
 <a href=\"\\(home\\.pl\\|show_friend\\.pl\\?id=\\([0-9]+\\)\\)\">\\(.*\\)</a>")
 (defconst mixi-community-category-regexp
-  "<td BGCOLOR=#F2DDB7 WIDTH=80><font COLOR=#996600>¥«¥Æ¥´¥ê</font></td>\r
+  "<td BGCOLOR=#F2DDB7 WIDTH=80><font COLOR=#996600>¥«¥Æ¥´¥ê</font></td>
 <td WIDTH=345>\\([^<]+\\)</td>")
 (defconst mixi-community-members-regexp
-  "<td BGCOLOR=#F2DDB7 WIDTH=80><font COLOR=#996600>¥á¥ó¥Ð¡¼¿ô</font></td>\r
+  "<td BGCOLOR=#F2DDB7 WIDTH=80><font COLOR=#996600>¥á¥ó¥Ð¡¼¿ô</font></td>
 <td WIDTH=345>\\([0-9]+\\)¿Í</td></tr>")
 (defconst mixi-community-open-level-regexp
-  "<td BGCOLOR=#F2DDB7 WIDTH=80><font COLOR=#996600>»²²Ã¾ò·ï¤È<br>¸ø³«¥ì¥Ù¥ë</font></td>\r
+  "<td BGCOLOR=#F2DDB7 WIDTH=80><font COLOR=#996600>»²²Ã¾ò·ï¤È<br>¸ø³«¥ì¥Ù¥ë</font></td>
 <td WIDTH=345>\\(.+\\)</td></tr>")
 (defconst mixi-community-authority-regexp
-  "<td BGCOLOR=#F2DDB7 WIDTH=80><font COLOR=#996600>¥È¥Ô¥Ã¥¯ºîÀ®¤Î¸¢¸Â</font></td>\r
+  "<td BGCOLOR=#F2DDB7 WIDTH=80><font COLOR=#996600>¥È¥Ô¥Ã¥¯ºîÀ®¤Î¸¢¸Â</font></td>
 <td WIDTH=345>\\(.+\\)</td></tr>")
 (defconst mixi-community-description-regexp
   "<td CLASS=h120 WIDTH=345>\\(.+\\)</td>")
@@ -2766,7 +2770,7 @@ Increase this value when unexpected error frequently occurs."
 (defconst mixi-news-finished-regexp
   "<td ALIGN=center background=http://img\\.mixi\\.jp/img/bg_line\\.gif> ¿½¤·Ìõ¤´¤¶¤¤¤Þ¤»¤ó¤¬¡¢¤³¤Î¥Ë¥å¡¼¥¹¤Ï·ÇºÜ½ªÎ»¤·¤Þ¤·¤¿¡£</td>")
 (defconst mixi-news-title-regexp
-  "<td HEIGHT=\"46\" STYLE=\"font-weight: bold;font-size: 14px;\" CLASS=\"h130\">\\(.+\\)\\(\r
+  "<td HEIGHT=\"46\" STYLE=\"font-weight: bold;font-size: 14px;\" CLASS=\"h130\">\\(.+\\)\\(
 \\)?</td>")
 (defconst mixi-news-media-time-regexp
   "<td COLSPAN=\"2\" ALIGN=\"right\">(\\(.+\\)&nbsp;-&nbsp;\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\))</td></tr>")