* mixi.el (mixi-friend-nick-regexp): Follow the change of mixi.
[elisp/mixi.git] / mixi-gnus.el
1 ;;; mixi-gnus.el --- Gnus integration for mixi
2
3 ;; Copyright (C) 2007, 2008 OHASHI Akira
4
5 ;; Author: OHASHI Akira <bg66@koka-in.org>
6 ;; Keywords: news
7
8 ;; This file is *NOT* a part of Gnus.
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 GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
24
25 ;;; Commentary:
26
27 ;; To use, add the following lines to your ~/.emacs:
28 ;;
29 ;; (autoload 'mixi-gnus-setup "mixi-gnus")
30 ;; (add-hook 'gnus-startup-hook 'mixi-gnus-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 'message)
39
40 ;; Functions and variables which should be defined in the other module
41 ;; at run-time.
42 (eval-when-compile
43   (defvar message-bogus-addresses))
44
45 (defun message-mixi-p ()
46   "Say whether the current buffer contains a mixi message."
47   (and (not message-this-is-news)
48        (save-excursion
49          (save-restriction
50            (message-narrow-to-headers)
51            (or (message-fetch-field "mixi-to")
52                (string-match mixi-to-regexp (message-fetch-field "to")))))))
53
54 (defun message-send-via-mixi (arg)
55   "Send the current message via mixi."
56   (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
57          (case-fold-search nil)
58          (mailbuf (current-buffer)))
59     ;; Avoid matching with message-mail-p.
60     (with-current-buffer mailbuf
61       (goto-char (point-min))
62       (unless (search-forward "\nMixi-To: " nil t)
63         (when (search-forward "\nTo: " nil t)
64           (replace-match "\nMixi-To: "))))
65     (unwind-protect
66         (save-excursion
67           (set-buffer tembuf)
68           (erase-buffer)
69           ;; Avoid copying text props (except hard newlines).
70           (insert (with-current-buffer mailbuf
71                     (mml-buffer-substring-no-properties-except-hard-newlines
72                      (point-min) (point-max))))
73           (mixi-send-mail (message-fetch-field "mixi-to")
74                           (message-fetch-field "subject")
75                           (buffer-substring (message-goto-body)
76                                             (point-max))))
77       (kill-buffer tembuf))
78     (set-buffer mailbuf)
79     (push 'mixi message-sent-message-via)))
80
81 (defun mixi-gnus-setup ()
82   (let ((method '(mixi message-mixi-p message-send-via-mixi)))
83     (unless (member method message-send-method-alist)
84       (setq message-send-method-alist
85             (cons method message-send-method-alist))))
86   ;; Avoid matching with bogus addresses for `message-send-via-mixi'.
87   (setq message-bogus-addresses
88         (remove "[ \t]" message-bogus-addresses)))
89
90 (provide 'mixi-gnus)
91
92 ;;; mixi-gnus.el ends here