1 ;;; gnus-msg.el --- mail and post interface for Gnus
3 ;; Copyright (C) 1995-2011 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 3 of the License, or
14 ;; (at your option) any later version.
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. If not, see <http://www.gnu.org/licenses/>.
28 (eval-when-compile (require 'cl))
36 (defcustom gnus-post-method 'current
37 "*Preferred method for posting USENET news.
39 If this variable is `current' (which is the default), Gnus will use
40 the \"current\" select method when posting. If it is `native', Gnus
41 will use the native select method when posting.
43 This method will not be used in mail groups and the like, only in
46 If not `native' nor `current', the value must be a valid method as discussed
47 in the documentation of `gnus-select-method'. It can also be a list of
48 methods. If that is the case, the user will be queried for what select
49 method to use when posting."
50 :group 'gnus-group-foreign
51 :link '(custom-manual "(gnus)Posting Server")
52 :type `(choice (const native)
54 (sexp :tag "Methods" ,gnus-select-method)))
56 (defcustom gnus-outgoing-message-group nil
57 "All outgoing messages will be put in this group.
58 If you want to store all your outgoing mail and articles in the group
59 \"nnml:archive\", you set this variable to that value. This variable
60 can also be a list of group names.
62 If you want to have greater control over what group to put each
63 message in, you can set this variable to a function that checks the
64 current newsgroup name and then returns a suitable group name (or list
67 :type '(choice (const nil)
70 (repeat :tag "List of groups" (string :tag "Group"))))
72 (make-obsolete-variable 'gnus-outgoing-message-group 'gnus-message-archive-group "24.1")
74 (defcustom gnus-mailing-list-groups nil
75 "*If non-nil a regexp matching groups that are really mailing lists.
76 This is useful when you're reading a mailing list that has been
77 gatewayed to a newsgroup, and you want to followup to an article in
80 :type '(choice (regexp)
83 (defcustom gnus-add-to-list nil
84 "*If non-nil, add a `to-list' parameter automatically."
88 (defcustom gnus-crosspost-complaint
91 You posted the article below with the following Newsgroups header:
95 The %s group, at least, was an inappropriate recipient
96 of this message. Please trim your Newsgroups header to exclude this
97 group before posting in the future.
102 "Format string to be inserted when complaining about crossposts.
103 The first %s will be replaced by the Newsgroups header;
104 the second with the current group name."
108 (defcustom gnus-message-setup-hook nil
109 "Hook run after setting up a message buffer."
111 :options '(message-remove-blank-cited-lines)
114 (defcustom gnus-bug-create-help-buffer t
115 "*Should we create the *Gnus Help Bug* buffer?"
119 (defcustom gnus-posting-styles nil
120 "*Alist of styles to use when posting.
121 See Info node `(gnus)Posting Styles'."
123 :link '(custom-manual "(gnus)Posting Styles")
124 :type '(repeat (cons (choice (regexp)
127 (string :tag "Header")
128 (regexp :tag "Regexp"))
132 (choice (const signature)
133 (const signature-file)
140 (string :tag "Header"))
146 (defcustom gnus-gcc-mark-as-read nil
147 "If non-nil, automatically mark Gcc articles as read."
152 (make-obsolete-variable 'gnus-inews-mark-gcc-as-read
153 'gnus-gcc-mark-as-read "Emacs 22.1")
155 (defcustom gnus-gcc-externalize-attachments nil
156 "Should local-file attachments be included as external parts in Gcc copies?
157 If it is `all', attach files as external parts;
158 if a regexp and matches the Gcc group name, attach files as external parts;
159 if nil, attach files as normal parts."
162 :type '(choice (const nil :tag "None")
163 (const all :tag "Any")
164 (string :tag "Regexp")))
166 (gnus-define-group-parameter
167 posting-charset-alist
170 "Return the permitted unencoded charsets for posting of GROUP."
171 :variable gnus-group-posting-charset-alist
173 '(("^\\(no\\|fr\\)\\.[^,]*\\(,[ \t\n]*\\(no\\|fr\\)\\.[^,]*\\)*$" iso-8859-1 (iso-8859-1))
174 ("^\\(fido7\\|relcom\\)\\.[^,]*\\(,[ \t\n]*\\(fido7\\|relcom\\)\\.[^,]*\\)*$" koi8-r (koi8-r))
175 (message-this-is-mail nil nil)
176 (message-this-is-news nil t))
178 "Alist of regexps and permitted unencoded charsets for posting.
179 Each element of the alist has the form (TEST HEADER BODY-LIST), where
180 TEST is either a regular expression matching the newsgroup header or a
182 HEADER is the charset which may be left unencoded in the header (nil
183 means encode all charsets),
184 BODY-LIST is a list of charsets which may be encoded using 8bit
185 content-transfer encoding in the body, or one of the special values
186 nil (always encode using quoted-printable) or t (always use 8bit).
188 Note that any value other than nil for HEADER infringes some RFCs, so
189 use this option with care."
190 :variable-group gnus-charset
192 '(repeat (list :tag "Permitted unencoded charsets"
194 (regexp :tag "Group")
195 (const :tag "Mail message" :value message-this-is-mail)
196 (const :tag "News article" :value message-this-is-news))
197 (choice :tag "Header"
198 (const :tag "None" nil)
199 (symbol :tag "Charset"))
201 (const :tag "Any" :value t)
202 (const :tag "None" :value nil)
203 (repeat :tag "Charsets"
204 (symbol :tag "Charset")))))
205 :parameter-type '(choice :tag "Permitted unencoded charsets"
208 :parameter-document "\
209 List of charsets that are permitted to be unencoded.")
211 (defcustom gnus-debug-files
212 '("gnus.el" "gnus-sum.el" "gnus-group.el"
213 "gnus-art.el" "gnus-start.el" "gnus-async.el"
214 "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
215 "gnus-agent.el" "gnus-cache.el" "gnus-srvr.el"
216 "mm-util.el" "mm-decode.el" "nnmail.el" "message.el")
217 "Files whose variables will be reported in `gnus-bug'."
220 :type '(repeat (string :tag "File")))
222 (defcustom gnus-debug-exclude-variables
223 '(mm-mime-mule-charset-alist
224 nnmail-split-fancy message-minibuffer-local-map)
225 "Variables that should not be reported in `gnus-bug'."
228 :type '(repeat (symbol :tag "Variable")))
230 (defcustom gnus-discouraged-post-methods
231 '(nndraft nnml nnimap nnmaildir nnmh nnfolder nndir)
232 "A list of back ends that are not used in \"real\" newsgroups.
233 This variable is used only when `gnus-post-method' is `current'."
235 :group 'gnus-group-foreign
236 :type '(repeat (symbol :tag "Back end")))
238 (defcustom gnus-message-replysign
240 "Automatically sign replies to signed messages.
241 See also the `mml-default-sign-method' variable."
245 (defcustom gnus-message-replyencrypt t
246 "Automatically encrypt replies to encrypted messages.
247 See also the `mml-default-encrypt-method' variable."
252 (defcustom gnus-message-replysignencrypted
254 "Setting this causes automatically encrypted messages to also be signed."
258 (defcustom gnus-confirm-mail-reply-to-news (and gnus-novice-user
259 (not gnus-expert-user))
260 "If non-nil, Gnus requests confirmation when replying to news.
261 This is done because new users often reply by mistake when reading
263 This can also be a function receiving the group name as the only
264 parameter, which should return non-nil if a confirmation is needed; or
265 a regexp, in which case a confirmation is asked for if the group name
267 :version "23.1" ;; No Gnus (default changed)
269 :type '(choice (const :tag "No" nil)
271 (regexp :tag "If group matches regexp")
272 (function :tag "If function evaluates to non-nil")))
274 (defcustom gnus-confirm-treat-mail-like-news
276 "If non-nil, Gnus will treat mail like news with regard to confirmation
277 when replying by mail. See the `gnus-confirm-mail-reply-to-news' variable
278 for fine-tuning this.
279 If nil, Gnus will never ask for confirmation if replying to mail."
284 (defcustom gnus-summary-resend-default-address t
285 "If non-nil, Gnus tries to suggest a default address to resend to.
286 If nil, the address field will always be empty after invoking
287 `gnus-summary-resend-message'."
292 (defcustom gnus-message-highlight-citation
293 t ;; gnus-treat-highlight-citation ;; gnus-cite dependency
294 "Enable highlighting of different citation levels in message-mode."
295 :version "23.1" ;; No Gnus
300 (autoload 'gnus-message-citation-mode "gnus-cite" nil t)
302 ;;; Internal variables.
304 (defvar gnus-inhibit-posting-styles nil
305 "Inhibit the use of posting styles.")
307 (defvar gnus-article-yanked-articles nil)
308 (defvar gnus-message-buffer "*Mail Gnus*")
309 (defvar gnus-article-copy nil)
310 (defvar gnus-check-before-posting nil)
311 (defvar gnus-last-posting-server nil)
312 (defvar gnus-message-group-art nil)
314 (defvar gnus-msg-force-broken-reply-to nil)
316 (defconst gnus-bug-message
317 "Sending a bug report to the Gnus Towers.
318 ========================================
320 The buffer below is a mail buffer. When you press `C-c C-c', it will
321 be sent to the Gnus Bug Exterminators.
323 The thing near the bottom of the buffer is how the environment
324 settings will be included in the mail. Please do not delete that.
325 They will tell the Bug People what your environment is, so that it
326 will be easier to locate the bugs.
328 If you have found a bug that makes Emacs go \"beep\", set
329 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
330 and include the backtrace in your bug report.
332 Please describe the bug in annoying, painstaking detail.
334 Thank you for your help in stamping out bugs.
337 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
341 ;;; Gnus Posting Functions
344 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
345 "p" gnus-summary-post-news
346 "i" gnus-summary-news-other-window
347 "f" gnus-summary-followup
348 "F" gnus-summary-followup-with-original
349 "c" gnus-summary-cancel-article
350 "s" gnus-summary-supersede-article
351 "r" gnus-summary-reply
352 "y" gnus-summary-yank-message
353 "R" gnus-summary-reply-with-original
354 "L" gnus-summary-reply-to-list-with-original
355 "w" gnus-summary-wide-reply
356 "W" gnus-summary-wide-reply-with-original
357 "v" gnus-summary-very-wide-reply
358 "V" gnus-summary-very-wide-reply-with-original
359 "n" gnus-summary-followup-to-mail
360 "N" gnus-summary-followup-to-mail-with-original
361 "m" gnus-summary-mail-other-window
362 "u" gnus-uu-post-news
363 "\M-c" gnus-summary-mail-crosspost-complaint
364 "Br" gnus-summary-reply-broken-reply-to
365 "BR" gnus-summary-reply-broken-reply-to-with-original
366 "om" gnus-summary-mail-forward
367 "op" gnus-summary-post-forward
368 "Om" gnus-uu-digest-mail-forward
369 "Op" gnus-uu-digest-post-forward)
371 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
372 "b" gnus-summary-resend-bounced-mail
373 ;; "c" gnus-summary-send-draft
374 "r" gnus-summary-resend-message
375 "e" gnus-summary-resend-message-edit)
377 ;;; Internal functions.
379 (defun gnus-inews-make-draft (articles)
381 (gnus-inews-make-draft-meta-information
382 ,(gnus-group-decoded-name gnus-newsgroup-name) ',articles)))
384 (defvar gnus-article-reply nil)
385 (defmacro gnus-setup-message (config &rest forms)
386 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
387 (winconf-name (make-symbol "gnus-setup-message-winconf-name"))
388 (buffer (make-symbol "gnus-setup-message-buffer"))
389 (article (make-symbol "gnus-setup-message-article"))
390 (yanked (make-symbol "gnus-setup-yanked-articles"))
391 (group (make-symbol "gnus-setup-message-group")))
392 `(let ((,winconf (current-window-configuration))
393 (,winconf-name gnus-current-window-configuration)
394 (,buffer (buffer-name (current-buffer)))
395 (,article gnus-article-reply)
396 (,yanked gnus-article-yanked-articles)
397 (,group gnus-newsgroup-name)
398 (message-header-setup-hook
399 (copy-sequence message-header-setup-hook))
400 (mbl mml-buffer-list)
401 (message-mode-hook (copy-sequence message-mode-hook)))
402 (setq mml-buffer-list nil)
403 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
404 ;; message-newsreader and message-mailer were formerly set in
405 ;; gnus-inews-add-send-actions, but this is too late when
406 ;; message-generate-headers-first is used. --ansel
407 (add-hook 'message-mode-hook
409 (setq message-newsreader
410 (setq message-mailer (gnus-extended-version)))))
411 ;; #### FIXME: for a reason that I did not manage to identify yet,
412 ;; the variable `gnus-newsgroup-name' does not honor a dynamically
413 ;; scoped or setq'ed value from a caller like `C-u gnus-summary-mail'.
414 ;; After evaluation of @forms below, it gets the value we actually want
415 ;; to override, and the posting styles are used. For that reason, I've
416 ;; added an optional argument to `gnus-configure-posting-styles' to
417 ;; make sure that the correct value for the group name is used. -- drv
418 (add-hook 'message-mode-hook
419 (if (memq ,config '(reply-yank reply))
421 (gnus-configure-posting-styles ,group))
423 ;; There may be an old " *gnus article copy*" buffer.
424 (let (gnus-article-copy)
425 (gnus-configure-posting-styles ,group)))))
426 (gnus-alist-pull ',(intern gnus-draft-meta-information-header)
427 message-required-headers)
429 (not (string= ,group "")))
431 (intern gnus-draft-meta-information-header)
432 (gnus-inews-make-draft (or ,yanked ,article)))
433 message-required-headers))
437 (gnus-inews-add-send-actions ,winconf ,buffer ,article ,config
438 ,yanked ,winconf-name)
439 (setq gnus-message-buffer (current-buffer))
440 (set (make-local-variable 'gnus-message-group-art)
441 (cons ,group ,article))
442 (set (make-local-variable 'gnus-newsgroup-name) ,group)
443 ;; Enable highlighting of different citation levels
444 (when gnus-message-highlight-citation
445 (gnus-message-citation-mode 1))
446 (gnus-run-hooks 'gnus-message-setup-hook)
447 (if (eq major-mode 'message-mode)
448 (let ((mbl1 mml-buffer-list))
449 (setq mml-buffer-list mbl) ;; Global value
450 (set (make-local-variable 'mml-buffer-list) mbl1);; Local value
451 (gnus-make-local-hook 'kill-buffer-hook)
452 (gnus-make-local-hook 'change-major-mode-hook)
453 (add-hook 'change-major-mode-hook 'mml-destroy-buffers nil t)
454 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))
455 (mml-destroy-buffers)
456 (setq mml-buffer-list mbl)))
457 (message-hide-headers)
459 (gnus-configure-windows ,config t)
460 (run-hooks 'post-command-hook)
461 (set-buffer-modified-p nil))))
463 (defun gnus-inews-make-draft-meta-information (group articles)
464 (when (numberp articles)
465 (setq articles (list articles)))
466 (concat "(\"" group "\""
480 (defun gnus-msg-mail (&optional to subject other-headers continue
481 switch-action yank-action send-actions return-action)
482 "Start editing a mail message to be sent.
483 Like `message-mail', but with Gnus paraphernalia, particularly the
484 Gcc: header for archiving purposes."
486 (let ((buf (current-buffer))
488 (gnus-setup-message 'message
489 (message-mail to subject other-headers continue
490 nil yank-action send-actions return-action))
492 (setq mail-buf (current-buffer))
493 (switch-to-buffer buf)
494 (apply switch-action mail-buf nil)))
495 ;; COMPOSEFUNC should return t if succeed. Undocumented ???
499 (defun gnus-button-mailto (address)
501 (set-buffer (gnus-copy-article-buffer))
502 (gnus-setup-message 'message
503 (message-reply address)))
506 (defun gnus-button-reply (&optional to-address wide)
507 "Like `message-reply'."
509 (gnus-setup-message 'message
510 (message-reply to-address wide)))
513 (define-mail-user-agent 'gnus-user-agent
514 'gnus-msg-mail 'message-send-and-exit
515 'message-kill-buffer 'message-send-hook)
517 (defun gnus-setup-posting-charset (group)
518 (let ((alist gnus-group-posting-charset-alist)
519 (group (or group ""))
523 (while (setq elem (pop alist))
524 (when (or (and (stringp (car elem))
525 (string-match (car elem) group))
526 (and (functionp (car elem))
527 (funcall (car elem) group))
528 (and (symbolp (car elem))
529 (symbol-value (car elem))))
530 (throw 'found (cons (cadr elem) (caddr elem)))))))))
532 (defun gnus-inews-add-send-actions (winconf buffer article
533 &optional config yanked
535 (gnus-make-local-hook 'message-sent-hook)
536 (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
537 'gnus-inews-do-gcc) nil t)
539 (gnus-make-local-hook 'message-header-hook)
540 (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
541 (setq message-post-method
542 `(lambda (&optional arg)
543 (gnus-post-method arg ,gnus-newsgroup-name)))
546 (setq gnus-current-window-configuration ',winconf-name)
547 (when (gnus-buffer-exists-p ,buffer)
548 (set-window-configuration ,winconf)))
549 'exit 'postpone 'kill)
550 (let ((to-be-marked (cond
553 (lambda (x) (if (listp x) (car x) x)) yanked))
554 (article (if (listp article) article (list article)))
557 `(when (gnus-buffer-exists-p ,buffer)
558 (with-current-buffer ,buffer
560 (if (eq config 'forward)
561 `(gnus-summary-mark-article-as-forwarded ',to-be-marked)
562 `(gnus-summary-mark-article-as-replied ',to-be-marked)))))
565 (put 'gnus-setup-message 'lisp-indent-function 1)
566 (put 'gnus-setup-message 'edebug-form-spec '(form body))
568 ;;; Post news commands of Gnus group mode and summary mode
570 (defun gnus-group-mail (&optional arg)
571 "Start composing a mail.
572 If ARG, use the group under the point to find a posting style.
573 If ARG is 1, prompt for a group name to find the posting style."
575 ;; We can't `let' gnus-newsgroup-name here, since that leads
576 ;; to local variables leaking.
577 (let ((group gnus-newsgroup-name)
578 ;; make sure last viewed article doesn't affect posting styles:
580 (buffer (current-buffer)))