* mixi.el (mixi-entity-alist): New constant.
[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 'mixi-utils)
38 (require 'wl-draft)
39
40 (defsubst mixi-wl-get-recipients-from-buffer ()
41   (or (std11-field-body "mixi-to")
42       (std11-field-body "to")))
43
44 (defun wl-draft-send-mail-with-mixi ()
45   "Send the prepared message buffer with mixi."
46   (let* ((case-fold-search t)
47          (default-case-fold-search t)
48          (recipients (mixi-wl-get-recipients-from-buffer)))
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       (mixi-send-mail recipients
57                       (eword-decode-string (or (std11-field-body "subject")
58                                                ""))
59                       (decode-mime-charset-string
60                        (buffer-substring (1+ delimline) (point-max))
61                        wl-mime-charset))
62       (wl-draft-set-sent-message 'mail 'sent)
63       (wl-draft-write-sendlog 'ok 'mixi nil (list recipients) id))))
64
65 (defun mixi-wl-setup-draft-buffer ()
66   (when (string-match mixi-to-regexp (mixi-wl-get-recipients-from-buffer))
67     (make-local-variable 'wl-draft-send-confirm-with-preview)
68     (setq wl-draft-send-confirm-with-preview nil)
69     (make-local-variable 'wl-draft-send-mail-function)
70     (setq wl-draft-send-mail-function 'wl-draft-send-mail-with-mixi)))
71
72 (defun mixi-wl-setup ()
73   (add-hook 'wl-draft-send-hook 'mixi-wl-setup-draft-buffer))
74
75 (provide 'mixi-wl)
76
77 ;;; mixi-wl.el ends here