delete_temp_file fix
[bpt/emacs.git] / lisp / gnus / gnus-ml.el
CommitLineData
23f87bed 1;;; gnus-ml.el --- Mailing list minor mode for Gnus
c113de23 2
ba318903 3;; Copyright (C) 2000-2014 Free Software Foundation, Inc.
c113de23
GM
4
5;; Author: Julien Gilles <jgilles@free.fr>
26c9afc3 6;; Keywords: news, mail
c113de23
GM
7
8;; This file is part of GNU Emacs.
9
5e809f55 10;; GNU Emacs is free software: you can redistribute it and/or modify
c113de23 11;; it under the terms of the GNU General Public License as published by
5e809f55
GM
12;; the Free Software Foundation, either version 3 of the License, or
13;; (at your option) any later version.
c113de23
GM
14
15;; GNU Emacs 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
5e809f55 21;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
c113de23
GM
22
23;;; Commentary:
24
25;; implement (small subset of) RFC 2369
26
27;;; Code:
28
29(require 'gnus)
1464e703 30(require 'gnus-msg)
c113de23 31(eval-when-compile (require 'cl))
d029b5d2
KY
32(eval-when-compile
33 (when (featurep 'xemacs)
34 (require 'easy-mmode))) ; for `define-minor-mode'
c113de23
GM
35
36;;; Mailing list minor mode
37
bbf52f1e
SM
38(defvar gnus-mailing-list-mode-map
39 (let ((map (make-sparse-keymap)))
40 (gnus-define-keys map
41 "\C-c\C-nh" gnus-mailing-list-help
42 "\C-c\C-ns" gnus-mailing-list-subscribe
43 "\C-c\C-nu" gnus-mailing-list-unsubscribe
44 "\C-c\C-np" gnus-mailing-list-post
45 "\C-c\C-no" gnus-mailing-list-owner
46 "\C-c\C-na" gnus-mailing-list-archive)
47 map))
c113de23 48
1464e703
DL
49(defvar gnus-mailing-list-menu)
50
c113de23
GM
51(defun gnus-mailing-list-make-menu-bar ()
52 (unless (boundp 'gnus-mailing-list-menu)
53 (easy-menu-define
54 gnus-mailing-list-menu gnus-mailing-list-mode-map ""
55 '("Mailing-Lists"
56 ["Get help" gnus-mailing-list-help t]
57 ["Subscribe" gnus-mailing-list-subscribe t]
58 ["Unsubscribe" gnus-mailing-list-unsubscribe t]
59 ["Post a message" gnus-mailing-list-post t]
60 ["Mail to owner" gnus-mailing-list-owner t]
61 ["Browse archive" gnus-mailing-list-archive t]))))
62
1464e703 63;;;###autoload
c113de23 64(defun turn-on-gnus-mailing-list-mode ()
23f87bed 65 (when (gnus-group-find-parameter gnus-newsgroup-name 'to-list)
c113de23
GM
66 (gnus-mailing-list-mode 1)))
67
23f87bed
MB
68;;;###autoload
69(defun gnus-mailing-list-insinuate (&optional force)
70 "Setup group parameters from List-Post header.
71If FORCE is non-nil, replace the old ones."
72 (interactive "P")
73 (let ((list-post
74 (with-current-buffer gnus-original-article-buffer
75 (gnus-fetch-field "list-post"))))
76 (if list-post
77 (if (and (not force)
78 (gnus-group-get-parameter gnus-newsgroup-name 'to-list))
79 (gnus-message 1 "to-list is non-nil.")
80 (if (string-match "<mailto:\\([^>]*\\)>" list-post)
81 (setq list-post (match-string 1 list-post)))
82 (gnus-group-add-parameter gnus-newsgroup-name
83 (cons 'to-list list-post))
84 (gnus-mailing-list-mode 1))
85 (gnus-message 1 "no list-post in this message."))))
86
765d4319
KY
87(eval-when-compile
88 (when (featurep 'xemacs)
89 (defvar gnus-mailing-list-mode-hook)
90 (defvar gnus-mailing-list-mode-on-hook)
91 (defvar gnus-mailing-list-mode-off-hook)))
92
1464e703 93;;;###autoload
bbf52f1e 94(define-minor-mode gnus-mailing-list-mode
c113de23
GM
95 "Minor mode for providing mailing-list commands.
96
97\\{gnus-mailing-list-mode-map}"
bbf52f1e
SM
98 :lighter " Mailing-List"
99 :keymap gnus-mailing-list-mode-map
100 (cond
101 ((not (derived-mode-p 'gnus-summary-mode))
102 (setq gnus-mailing-list-mode nil))
103 (gnus-mailing-list-mode
104 ;; Set up the menu.
105 (when (gnus-visual-p 'mailing-list-menu 'menu)
106 (gnus-mailing-list-make-menu-bar)))))
c113de23
GM
107
108;;; Commands
109
110(defun gnus-mailing-list-help ()
111 "Get help from mailing list server."
a1506d29
JB
112 (interactive)
113 (let ((list-help
1464e703
DL
114 (with-current-buffer gnus-original-article-buffer
115 (gnus-fetch-field "list-help"))))
116 (cond (list-help (gnus-mailing-list-message list-help))
117 (t (gnus-message 1 "no list-help in this group")))))
c113de23
GM
118
119(defun gnus-mailing-list-subscribe ()
26c9afc3 120 "Subscribe to mailing list."
c113de23 121 (interactive)
a1506d29 122 (let ((list-subscribe
1464e703
DL
123 (with-current-buffer gnus-original-article-buffer
124 (gnus-fetch-field "list-subscribe"))))
125 (cond (list-subscribe (gnus-mailing-list-message list-subscribe))
126 (t (gnus-message 1 "no list-subscribe in this group")))))
c113de23
GM
127
128(defun gnus-mailing-list-unsubscribe ()
26c9afc3 129 "Unsubscribe from mailing list."
c113de23 130 (interactive)
a1506d29 131 (let ((list-unsubscribe
1464e703
DL
132 (with-current-buffer gnus-original-article-buffer
133 (gnus-fetch-field "list-unsubscribe"))))
134 (cond (list-unsubscribe (gnus-mailing-list-message list-unsubscribe))
135 (t (gnus-message 1 "no list-unsubscribe in this group")))))
c113de23
GM
136
137(defun gnus-mailing-list-post ()
138 "Post message (really useful ?)"
139 (interactive)
a1506d29 140 (let ((list-post
1464e703
DL
141 (with-current-buffer gnus-original-article-buffer
142 (gnus-fetch-field "list-post"))))
143 (cond (list-post (gnus-mailing-list-message list-post))
144 (t (gnus-message 1 "no list-post in this group")))))
c113de23
GM
145
146(defun gnus-mailing-list-owner ()
26c9afc3 147 "Mail to the mailing list owner."
c113de23 148 (interactive)
a1506d29 149 (let ((list-owner
1464e703
DL
150 (with-current-buffer gnus-original-article-buffer
151 (gnus-fetch-field "list-owner"))))
152 (cond (list-owner (gnus-mailing-list-message list-owner))
153 (t (gnus-message 1 "no list-owner in this group")))))
c113de23
GM
154
155(defun gnus-mailing-list-archive ()
26c9afc3 156 "Browse archive."
c113de23 157 (interactive)
23f87bed 158 (require 'browse-url)
a1506d29 159 (let ((list-archive
1464e703
DL
160 (with-current-buffer gnus-original-article-buffer
161 (gnus-fetch-field "list-archive"))))
23f87bed
MB
162 (cond (list-archive
163 (if (string-match "<\\(http:[^>]*\\)>" list-archive)
164 (browse-url (match-string 1 list-archive))
165 (browse-url list-archive)))
166 (t (gnus-message 1 "no list-archive in this group")))))
c113de23
GM
167
168;;; Utility functions
169
c113de23 170(defun gnus-mailing-list-message (address)
26c9afc3
MB
171 "Send message to ADDRESS.
172ADDRESS is specified by a \"mailto:\" URL."
173 (cond
174 ((string-match "<\\(mailto:[^>]*\\)>" address)
175 (require 'gnus-art)
176 (gnus-url-mailto (match-string 1 address)))
177 ;; other case <http://...> to be done.
178 (t nil)))
c113de23
GM
179
180(provide 'gnus-ml)
181
182;;; gnus-ml.el ends here