* mixi.el (mixi-community-birthday-regexp): Follow the change of mixi.
[elisp/mixi.git] / mixi-wl.el
1 ;;; mixi-wl.el --- Wanderlust integration for mixi
2
3 ;; Copyright (C) 2007 OHASHI Akira
4
5 ;; Author: OHASHI Akira <bg66@koka-in.org>
6 ;; Keywords: news
7
8 ;; This file is *NOT* a part of Wanderlust.
9
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with this program; if not, you can either send email to this
22 ;; program's maintainer or write to: The Free Software Foundation,
23 ;; Inc.; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24
25 ;;; Commentary:
26
27 ;; To use, add the following lines to your ~/.emacs:
28 ;;
29 ;; (autoload 'mixi-wl-setup "mixi-wl")
30 ;; (add-hook 'wl-init-hook 'mixi-wl-setup)
31
32 ;; If you have bug reports and/or suggestions for improvement, please
33 ;; send them via <URL:http://mixi.jp/view_community.pl?id=1596390>.
34
35 ;;; Code:
36
37 (require 'sb-mixi)
38 (require 'wl-draft)
39
40 (defvar wl-draft-send-mail-function-original nil)
41
42 (defun wl-draft-send-mail-with-mixi ()
43   "Send the prepared message buffer with mixi."
44   (let* ((case-fold-search t)
45          (default-case-fold-search t)
46          (recipients (or (std11-field-body "mixi-to")
47                          (std11-field-body "to"))))
48     (if (string-match shimbun-mixi-to-regexp recipients)
49         (let ((delimline (save-excursion
50                            (goto-char (point-min))
51                            (re-search-forward
52                             (concat "^" (regexp-quote mail-header-separator)
53                                     "$\\|^$") nil t)
54                            (point-marker)))
55               (id (std11-field-body "message-id")))
56           (shimbun-mixi-send-mail recipients
57                                   (eword-decode-string
58                                    (std11-field-body "subject"))
59                                   (decode-mime-charset-string
60                                    (buffer-substring (1+ delimline)
61                                                      (point-max))
62                                    wl-mime-charset))
63           (wl-draft-set-sent-message 'mail 'sent)
64           (wl-draft-write-sendlog 'ok 'mixi nil recipients id))
65       (funcall wl-draft-send-mail-function-original))))
66
67 (defun mixi-wl-setup ()
68   ;; FIXME: Don't set it.
69   (setq wl-draft-send-confirm-with-preview nil)
70   (unless wl-draft-send-mail-function-original
71     (setq wl-draft-send-mail-function-original wl-draft-send-mail-function)
72     (setq wl-draft-send-mail-function 'wl-draft-send-mail-with-mixi)))
73
74 (provide 'mixi-wl)
75
76 ;;; mixi-wl.el ends here