* mixi-gnus.el (toplevel): Avoid warnings when compiling.
[elisp/mixi.git] / mixi-wl.el
index 8a59d0b..2e034f2 100644 (file)
@@ -18,9 +18,9 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with this program; if not, you can either send email to this
-;; program's maintainer or write to: The Free Software Foundation,
-;; Inc.; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+;; along with GNU Emacs; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;;; Commentary:
 
 
 ;;; Code:
 
-(require 'sb-mixi)
+(require 'mixi-utils)
 (require 'wl-draft)
 
-(defvar wl-draft-send-mail-function-original nil)
+(defsubst mixi-wl-get-recipients-from-buffer ()
+  (or (std11-field-body "mixi-to")
+      (std11-field-body "to")))
 
 (defun wl-draft-send-mail-with-mixi ()
   "Send the prepared message buffer with mixi."
   (let* ((case-fold-search t)
         (default-case-fold-search t)
-        (recipients (or (std11-field-body "mixi-to")
-                        (std11-field-body "to"))))
-    (if (string-match shimbun-mixi-to-regexp recipients)
-       (let ((delimline (save-excursion
-                          (goto-char (point-min))
-                          (re-search-forward
-                           (concat "^" (regexp-quote mail-header-separator)
-                                   "$\\|^$") nil t)
-                          (point-marker)))
-             (id (std11-field-body "message-id")))
-         (shimbun-mixi-send-mail recipients
-                                 (eword-decode-string
-                                  (std11-field-body "subject"))
-                                 (decode-mime-charset-string
-                                  (buffer-substring (1+ delimline)
-                                                    (point-max))
-                                  wl-mime-charset))
-         (wl-draft-set-sent-message 'mail 'sent)
-         (wl-draft-write-sendlog 'ok 'mixi nil recipients id))
-      (funcall wl-draft-send-mail-function-original))))
+        (recipients (mixi-wl-get-recipients-from-buffer)))
+    (let ((delimline (save-excursion
+                      (goto-char (point-min))
+                      (re-search-forward
+                       (concat "^" (regexp-quote mail-header-separator)
+                               "$\\|^$") nil t)
+                      (point-marker)))
+         (id (std11-field-body "message-id")))
+      (mixi-send-mail recipients
+                     (eword-decode-string (or (std11-field-body "subject")
+                                              ""))
+                     (decode-mime-charset-string
+                      (buffer-substring (1+ delimline) (point-max))
+                      wl-mime-charset))
+      (wl-draft-set-sent-message 'mail 'sent)
+      (wl-draft-write-sendlog 'ok 'mixi nil (list recipients) id))))
+
+(defun mixi-wl-setup-draft-buffer ()
+  (let ((recipients (mixi-wl-get-recipients-from-buffer)))
+    (when (and recipients
+              (string-match mixi-to-regexp recipients))
+      (make-local-variable 'wl-draft-send-confirm-with-preview)
+      (setq wl-draft-send-confirm-with-preview nil)
+      (make-local-variable 'wl-draft-send-mail-function)
+      (setq wl-draft-send-mail-function 'wl-draft-send-mail-with-mixi))))
 
 (defun mixi-wl-setup ()
-  ;; FIXME: Don't set it.
-  (setq wl-draft-send-confirm-with-preview nil)
-  (unless wl-draft-send-mail-function-original
-    (setq wl-draft-send-mail-function-original wl-draft-send-mail-function)
-    (setq wl-draft-send-mail-function 'wl-draft-send-mail-with-mixi)))
+  (add-hook 'wl-draft-send-hook 'mixi-wl-setup-draft-buffer))
 
 (provide 'mixi-wl)