(mixi-friend-profile-regexp): Fix regexp.
[elisp/mixi.git] / mixi-utils.el
index f2bc944..34a1f07 100644 (file)
@@ -1,4 +1,4 @@
-;; mixi-utils.el --- Utilities for mixi object
+;; mixi-utils.el --- Utilities for mixi object -*- coding: euc-jp -*-
 
 ;; Copyright (C) 2007 OHASHI Akira
 
 (put 'with-mixi-class 'lisp-indent-function 'defun)
 (put 'with-mixi-class 'edebug-form-spec '(body))
 
-(defun mixi-make-title (object &optional add-suffix)
+(defun mixi-make-objects (url-or-function &optional range)
+  (if (stringp url-or-function)
+      (let ((object (mixi-make-object-from-url url-or-function)))
+       (with-mixi-class object
+         (cond ((eq class 'mixi-friend)
+                (mixi-get-diaries object range))
+               ((eq class 'mixi-community)
+                (mixi-get-bbses object range))
+               ((mixi-parent-p object)
+                (mixi-get-comments object range))
+               (t (error (concat (symbol-name class)
+                                 " is not supported yet."))))))
+    (funcall url-or-function range)))
+
+(defun mixi-make-title (object &optional add-parent)
   (with-mixi-class object
     (cond ((eq class 'mixi-comment)
           (concat "Re: " (mixi-make-title
-                          (mixi-comment-parent object) add-suffix)))
+                          (mixi-comment-parent object) add-parent)))
          ((eq class 'mixi-log)
           (mixi-friend-nick (mixi-log-friend object)))
          (t
           (let ((prefix (when (eq class 'mixi-event) "[¥¤¥Ù¥ó¥È]"))
                 (subject (mixi-object-title object))
-                (suffix (when add-suffix
+                (suffix (when add-parent
                           (concat " ("
-                                  (if (eq class 'mixi-diary)
-                                      (mixi-friend-nick
-                                       (mixi-diary-owner object))
-                                    (mixi-community-name
-                                     (mixi-bbs-community object)))
+                                  (cond ((eq class 'mixi-diary)
+                                         (mixi-friend-nick
+                                          (mixi-diary-owner object)))
+                                        ((eq class 'mixi-news)
+                                         (mixi-news-media object))
+                                        (t
+                                         (mixi-community-name
+                                          (mixi-bbs-community object))))
                                   ")"))))
             (concat prefix subject suffix))))))
 
            month " "
            (format-time-string "%Y %H:%M:%S %z" time))))
 
-(defun mixi-make-message-id (object)
+(defun mixi-make-id-1 (object)
   (with-mixi-class object
     (concat
-     (format-time-string "<%Y%m%d%H%M" (mixi-object-time object)) "."
+     (format-time-string "%Y%m%d%H%M" (mixi-object-time object)) "."
      (cond ((eq class 'mixi-comment)
            (concat (mixi-friend-id (mixi-comment-owner object)) "@"
                    (mixi-object-id (mixi-comment-parent object)) "."
                    (if (eq class 'mixi-news)
                        (mixi-news-media-id object)
                      (mixi-object-id (mixi-object-owner object))) ".")))
-     (mixi-object-name object) ".mixi.jp>")))
+     (mixi-object-name object))))
+
+(defun mixi-make-message-id (object)
+  (format "<%s.mixi.jp>" (mixi-make-id-1 object)))
+
+(defun mixi-make-tag-uri (object)
+  (format "tag:mixi.jp,%s:%s"
+         (format-time-string "%Y-%m-%d" (mixi-object-time object))
+         (mixi-make-id-1 object)))
 
 (defun mixi-make-url (object)
   (with-mixi-class object
          ((eq class 'mixi-friend)
           (mixi-expand-url (mixi-friend-page object))))))
 
+(defun mixi-make-encoded-url (object)
+  (mixi-url-encode-string (mixi-make-url object)))
+
 (defun mixi-make-content (object)
   (with-mixi-class object
     (cond ((eq class 'mixi-event)
          ((eq class 'mixi-friend)
           (if (mixi-object-realized-p object)
               (let ((sex (if (eq (mixi-friend-sex object) 'male) "ÃË" "½÷"))
-                    (age (number-to-string (mixi-friend-age object)))
-                    (birthday
-                     (concat (mapconcat (lambda (number)
-                                          (number-to-string number))
-                                        (mixi-friend-birthday object) "·î")
-                             "Æü"))
+                    (age (if (numberp (mixi-friend-age object))
+                             (number-to-string (mixi-friend-age object))
+                           "??"))
+                    (birthday (if (mixi-friend-birthday object)
+                                  (concat
+                                   (mapconcat (lambda (number)
+                                                (number-to-string number))
+                                              (mixi-friend-birthday object)
+                                              "·î") "Æü")
+                                "??·î??Æü"))
                     (blood-type (symbol-name
                                  (mixi-friend-blood-type object)))
                     (hobby (mapconcat 'identity
                         "</dl>"))
             (concat "<a href=\"" (mixi-make-url object)
                     "\">¥×¥í¥Õ¥£¡¼¥ë¤òɽ¼¨¤¹¤ë</a>")))
+         ((eq class 'mixi-log)
+          (mixi-make-content (mixi-log-friend object)))
          (t (mixi-object-content object)))))
 
 (defun mixi-make-reply-to (object)
                  (concat mixi-reply-to "message;"
                          (mixi-friend-id object))))))))
 
+(defconst mixi-to-regexp
+  "^mixi;\\([a-z]+\\);?\\([a-z0-9]+\\)?;?\\([0-9]+\\)?;?\\([0-9]+\\)?")
+
+(defun mixi-send-mail (to title content)
+  (when (string-match mixi-to-regexp to)
+    (let ((method (match-string 1 to)))
+      (cond ((string= method "comment")
+            (let ((parent (match-string 2 to))
+                  (owner-id (match-string 3 to))
+                  (id (match-string 4 to)))
+              (if (string= parent "diary")
+                  (mixi-post-comment
+                   (mixi-make-diary (mixi-make-friend owner-id) id) content)
+                (let ((func (intern
+                             (concat mixi-object-prefix "make-" parent))))
+                  (mixi-post-comment
+                   (funcall func (mixi-make-community owner-id) id)
+                   content)))))
+           ((string= method "topic")
+            (mixi-post-topic (mixi-make-community (match-string 2 to))
+                             title content))
+           ((string= method "diary")
+            (mixi-post-diary title content))
+           ((string= method "message")
+            (mixi-post-message (mixi-make-friend (match-string 2 to))
+                               title content))))))
+
 (provide 'mixi-utils)
 
 ;;; mixi-utils.el ends here