* mixi.el: Add autoload cookies.
[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
39 ;; Functions and variables which should be defined in the other module
40 ;; at run-time.
41 (eval-when-compile
42   (defvar mail-header-separator)
43   (defvar wl-mime-charset)
44   (defvar wl-draft-send-confirm-with-preview)
45   (defvar wl-draft-send-mail-function)
46   (autoload 'std11-field-body "std11")
47   (autoload 'eword-decode-string "eword-decode")
48   (autoload 'wl-draft-set-sent-message "wl-draft")
49   (autoload 'wl-draft-write-sendlog "wl-draft")
50   (autoload 'decode-mime-charset-string "mcharset"))
51
52 (defsubst mixi-wl-get-recipients-from-buffer ()
53   (or (std11-field-body "mixi-to")
54       (std11-field-body "to")))
55
56 (defun wl-draft-send-mail-with-mixi ()
57   "Send the prepared message buffer with mixi."
58   (let* ((case-fold-search t)
59          (default-case-fold-search t)
60          (recipients (mixi-wl-get-recipients-from-buffer)))
61     (let ((delimline (save-excursion
62                        (goto-char (point-min))
63                        (re-search-forward
64                         (concat "^" (regexp-quote mail-header-separator)
65                                 "$\\|^$") nil t)
66                        (point-marker)))
67           (id (std11-field-body "message-id")))
68       (shimbun-mixi-send-mail recipients
69                               (eword-decode-string
70                                (std11-field-body "subject"))
71                               (decode-mime-charset-string
72                                (buffer-substring (1+ delimline)
73                                                  (point-max))
74                                wl-mime-charset))
75       (wl-draft-set-sent-message 'mail 'sent)
76       (wl-draft-write-sendlog 'ok 'mixi nil (list recipients) id))))
77
78 (defun mixi-wl-setup-draft-buffer ()
79   (when (string-match shimbun-mixi-to-regexp
80                       (mixi-wl-get-recipients-from-buffer))
81     (make-local-variable 'wl-draft-send-confirm-with-preview)
82     (setq wl-draft-send-confirm-with-preview nil)
83     (make-local-variable 'wl-draft-send-mail-function)
84     (setq wl-draft-send-mail-function 'wl-draft-send-mail-with-mixi)))
85
86 (defun mixi-wl-setup ()
87   (add-hook 'wl-draft-send-hook 'mixi-wl-setup-draft-buffer))
88
89 (provide 'mixi-wl)
90
91 ;;; mixi-wl.el ends here