1 ;;; gnus-msg.el --- mail and post interface for Gnus
2 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000
3 ;; Free Software Foundation, Inc.
5 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
6 ;; Lars Magne Ingebrigtsen <larsi@gnus.org>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
30 (eval-when-compile (require 'cl))
37 (defcustom gnus-post-method 'current
38 "*Preferred method for posting USENET news.
40 If this variable is `current', Gnus will use the \"current\" select
41 method when posting. If it is nil (which is the default), Gnus will
42 use the native select method when posting.
44 This method will not be used in mail groups and the like, only in
47 If not nil nor `native', the value must be a valid method as discussed
48 in the documentation of `gnus-select-method'. It can also be a list of
49 methods. If that is the case, the user will be queried for what select
50 method to use when posting."
51 :group 'gnus-group-foreign
52 :type `(choice (const nil)
55 (sexp :tag "Methods" ,gnus-select-method)))
57 (defvar gnus-outgoing-message-group nil
58 "*All outgoing messages will be put in this group.
59 If you want to store all your outgoing mail and articles in the group
60 \"nnml:archive\", you set this variable to that value. This variable
61 can also be a list of group names.
63 If you want to have greater control over what group to put each
64 message in, you can set this variable to a function that checks the
65 current newsgroup name and then returns a suitable group name (or list
68 (defvar gnus-mailing-list-groups nil
69 "*Regexp matching groups that are really mailing lists.
70 This is useful when you're reading a mailing list that has been
71 gatewayed to a newsgroup, and you want to followup to an article in
74 (defvar gnus-add-to-list nil
75 "*If non-nil, add a `to-list' parameter automatically.")
77 (defvar gnus-crosspost-complaint
80 You posted the article below with the following Newsgroups header:
84 The %s group, at least, was an inappropriate recipient
85 of this message. Please trim your Newsgroups header to exclude this
86 group before posting in the future.
91 "Format string to be inserted when complaining about crossposts.
92 The first %s will be replaced by the Newsgroups header;
93 the second with the current group name.")
95 (defvar gnus-message-setup-hook nil
96 "Hook run after setting up a message buffer.")
98 (defvar gnus-bug-create-help-buffer t
99 "*Should we create the *Gnus Help Bug* buffer?")
101 (defvar gnus-posting-styles nil
102 "*Alist of styles to use when posting.")
104 (defcustom gnus-group-posting-charset-alist
105 '(("^\\(no\\|fr\\|dk\\)\\.[^,]*\\(,[ \t\n]*\\(no\\|fr\\|dk\\)\\.[^,]*\\)*$" iso-8859-1 (iso-8859-1))
106 ("^\\(fido7\\|relcom\\)\\.[^,]*\\(,[ \t\n]*\\(fido7\\|relcom\\)\\.[^,]*\\)*$" koi8-r (koi8-r))
107 (message-this-is-mail nil nil)
108 (message-this-is-news nil t))
109 "Alist of regexps and permitted unencoded charsets for posting.
110 Each element of the alist has the form (TEST HEADER BODY-LIST), where
111 TEST is either a regular expression matching the newsgroup header or a
113 HEADER is the charset which may be left unencoded in the header (nil
114 means encode all charsets),
115 BODY-LIST is a list of charsets which may be encoded using 8bit
116 content-transfer encoding in the body, or one of the special values
117 nil (always encode using quoted-printable) or t (always use 8bit).
119 Note that any value other than nil for HEADER infringes some RFCs, so
120 use this option with care."
121 :type '(repeat (list :tag "Permitted unencoded charsets"
123 (regexp :tag "Group")
124 (const :tag "Mail message" :value message-this-is-mail)
125 (const :tag "News article" :value message-this-is-news))
126 (choice :tag "Header"
127 (const :tag "None" nil)
128 (symbol :tag "Charset"))
130 (const :tag "Any" :value t)
131 (const :tag "None" :value nil)
132 (repeat :tag "Charsets"
133 (symbol :tag "Charset")))))
134 :group 'gnus-charset)
136 ;;; Internal variables.
138 (defvar gnus-inhibit-posting-styles nil
139 "Inhibit the use of posting styles.")
141 (defvar gnus-message-buffer "*Mail Gnus*")
142 (defvar gnus-article-copy nil)
143 (defvar gnus-last-posting-server nil)
144 (defvar gnus-message-group-art nil)
146 (defconst gnus-bug-message
147 "Sending a bug report to the Gnus Towers.
148 ========================================
150 The buffer below is a mail buffer. When you press `C-c C-c', it will
151 be sent to the Gnus Bug Exterminators.
153 The thing near the bottom of the buffer is how the environment
154 settings will be included in the mail. Please do not delete that.
155 They will tell the Bug People what your environment is, so that it
156 will be easier to locate the bugs.
158 If you have found a bug that makes Emacs go \"beep\", set
159 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
160 and include the backtrace in your bug report.
162 Please describe the bug in annoying, painstaking detail.
164 Thank you for your help in stamping out bugs.
168 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
169 (autoload 'news-setup "rnewspost")
170 (autoload 'news-reply-mode "rnewspost")
171 (autoload 'rmail-dont-reply-to "mail-utils")
172 (autoload 'rmail-output "rmailout"))
176 ;;; Gnus Posting Functions
179 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
180 "p" gnus-summary-post-news
181 "f" gnus-summary-followup
182 "F" gnus-summary-followup-with-original
183 "c" gnus-summary-cancel-article
184 "s" gnus-summary-supersede-article
185 "r" gnus-summary-reply
186 "y" gnus-summary-yank-message
187 "R" gnus-summary-reply-with-original
188 "w" gnus-summary-wide-reply
189 "W" gnus-summary-wide-reply-with-original
190 "n" gnus-summary-followup-to-mail
191 "N" gnus-summary-followup-to-mail-with-original
192 "m" gnus-summary-mail-other-window
193 "u" gnus-uu-post-news
194 "\M-c" gnus-summary-mail-crosspost-complaint
195 "om" gnus-summary-mail-forward
196 "op" gnus-summary-post-forward
197 "Om" gnus-uu-digest-mail-forward
198 "Op" gnus-uu-digest-post-forward)
200 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
201 "b" gnus-summary-resend-bounced-mail
202 ;; "c" gnus-summary-send-draft
203 "r" gnus-summary-resend-message)
206 (defun gnus-msg-mail (&rest args)
207 "Start editing a mail message to be sent.
208 Like `message-mail', but with Gnus paraphernalia, particularly the
209 the Gcc: header for archiving purposes."
211 (gnus-setup-message 'message
212 (apply 'message-mail args)))
215 (define-mail-user-agent 'gnus-user-agent
216 'gnus-msg-mail 'message-send-and-exit
217 'message-kill-buffer 'message-send-hook)
219 ;;; Internal functions.
221 (defvar gnus-article-reply nil)
222 (defmacro gnus-setup-message (config &rest forms)
223 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
224 (buffer (make-symbol "gnus-setup-message-buffer"))
225 (article (make-symbol "gnus-setup-message-article"))
226 (group (make-symbol "gnus-setup-message-group")))
227 `(let ((,winconf (current-window-configuration))
228 (,buffer (buffer-name (current-buffer)))
229 (,article (and gnus-article-reply (gnus-summary-article-number)))
230 (,group gnus-newsgroup-name)
231 (message-header-setup-hook
232 (copy-sequence message-header-setup-hook))
233 (mbl mml-buffer-list)
234 (message-mode-hook (copy-sequence message-mode-hook)))
235 (setq mml-buffer-list nil)
236 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
237 (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
238 (add-hook 'message-mode-hook 'gnus-configure-posting-styles)
242 (gnus-inews-add-send-actions ,winconf ,buffer ,article)
243 (setq gnus-message-buffer (current-buffer))
244 (set (make-local-variable 'gnus-message-group-art)
245 (cons ,group ,article))
246 (set (make-local-variable 'gnus-newsgroup-name) ,group)
247 (gnus-run-hooks 'gnus-message-setup-hook)
248 (if (eq major-mode 'message-mode)
249 ;; Make mml-buffer-list local.
250 ;; Restore global mml-buffer-list value as mbl.
251 ;; What a hack! -- Shenghuo
252 (let ((mml-buffer-list mml-buffer-list))
253 (setq mml-buffer-list mbl)
254 (make-local-variable 'mml-buffer-list)
255 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))
256 (mml-destroy-buffers)
257 (setq mml-buffer-list mbl)))
259 (gnus-configure-windows ,config t)
260 (set-buffer-modified-p nil))))
262 (defun gnus-setup-posting-charset (group)
263 (let ((alist gnus-group-posting-charset-alist)
264 (group (or group ""))
268 (while (setq elem (pop alist))
269 (when (or (and (stringp (car elem))
270 (string-match (car elem) group))
271 (and (gnus-functionp (car elem))
272 (funcall (car elem) group))
273 (and (symbolp (car elem))
274 (symbol-value (car elem))))
275 (throw 'found (cons (cadr elem) (caddr elem)))))))))
277 (defun gnus-inews-add-send-actions (winconf buffer article)
278 (make-local-hook 'message-sent-hook)
279 (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
280 'gnus-inews-do-gcc) nil t)
282 (make-local-hook 'message-header-hook)
283 (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
284 (setq message-post-method
286 (gnus-post-method arg ,gnus-newsgroup-name)))
287 (setq message-newsreader (setq message-mailer (gnus-extended-version)))
289 `(set-window-configuration ,winconf) 'exit 'postpone 'kill)
291 `(when (gnus-buffer-exists-p ,buffer)
295 `(gnus-summary-mark-article-as-replied ,article))))
298 (put 'gnus-setup-message 'lisp-indent-function 1)
299 (put 'gnus-setup-message 'edebug-form-spec '(form body))
301 ;;; Post news commands of Gnus group mode and summary mode
303 (defun gnus-group-mail (&optional arg)
304 "Start composing a mail.
305 If ARG, use the group under the point to find a posting style.
306 If ARG is 1, prompt for a group name to find the posting style."
308 ;; We can't `let' gnus-newsgroup-name here, since that leads
309 ;; to local variables leaking.
310 (let ((group gnus-newsgroup-name)
311 (buffer (current-buffer)))
314 (setq gnus-newsgroup-name
316 (if (= 1 (prefix-numeric-value arg))
317 (completing-read "Use posting style of group: "
318 gnus-active-hashtb nil
319 (gnus-read-active-file-p))
320 (gnus-group-group-name))
322 (gnus-setup-message 'message (message-mail)))
325 (setq gnus-newsgroup-name group)))))
327 (defun gnus-group-post-news (&optional arg)
328 "Start composing a news message.
329 If ARG, post to the group under point.
330 If ARG is 1, prompt for a group name."
332 ;; Bind this variable here to make message mode hooks work ok.
333 (let ((gnus-newsgroup-name
335 (if (= 1 (prefix-numeric-value arg))
336 (completing-read "Newsgroup: " gnus-active-hashtb nil
337 (gnus-read-active-file-p))
338 (gnus-group-group-name))
340 (gnus-post-news 'post gnus-newsgroup-name)))
342 (defun gnus-summary-post-news ()
343 "Start composing a news message."
345 (gnus-post-news 'post gnus-newsgroup-name))
347 (defun gnus-summary-followup (yank &optional force-news)
348 "Compose a followup to an article.
349 If prefix argument YANK is non-nil, original article is yanked automatically."
351 (list (and current-prefix-arg
352 (gnus-summary-work-articles 1))))
354 (gnus-summary-goto-subject (car yank)))
355 (save-window-excursion
356 (gnus-summary-select-article))
357 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
358 (gnus-newsgroup-name gnus-newsgroup-name))
360 (gnus-post-news nil gnus-newsgroup-name
361 headers gnus-article-buffer
362 yank nil force-news)))
364 (defun gnus-summary-followup-with-original (n &optional force-news)
365 "Compose a followup to an article and include the original article."
367 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
369 (defun gnus-summary-followup-to-mail (&optional arg)
370 "Followup to the current mail message via news."
372 (list (and current-prefix-arg
373 (gnus-summary-work-articles 1))))
374 (gnus-summary-followup arg t))
376 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
377 "Followup to the current mail message via news."
379 (gnus-summary-followup (gnus-summary-work-articles arg) t))
381 (defun gnus-inews-yank-articles (articles)
384 (while (setq article (pop articles))
385 (save-window-excursion
386 (set-buffer gnus-summary-buffer)
387 (gnus-summary-select-article nil nil nil article)
388 (gnus-summary-remove-process-mark article))