1 ;;; gnus-msg.el --- mail and post interface for Gnus
3 ;; Copyright (C) 1995-2013 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 (defcustom gnus-gcc-self-resent-messages 'no-gcc-self
167 "Like `gcc-self' group parameter, only for unmodified resent messages.
168 Applied to messages sent by `gnus-summary-resend-message'. Non-nil
169 value of this variable takes precedence over any existing Gcc header.
171 If this is `none', no Gcc copy will be made. If this is t, messages
172 resent will be Gcc'd to the current group. If this is a string, it
173 specifies a group to which resent messages will be Gcc'd. If this is
174 nil, Gcc will be done according to existing Gcc header(s), if any.
175 If this is `no-gcc-self', resent messages will be Gcc'd to groups that
176 existing Gcc header specifies, except for the current group."
179 :type '(choice (const none) (const t) string (const nil)
180 (const no-gcc-self)))
182 (gnus-define-group-parameter
183 posting-charset-alist
186 "Return the permitted unencoded charsets for posting of GROUP."
187 :variable gnus-group-posting-charset-alist
189 '(("^\\(no\\|fr\\)\\.[^,]*\\(,[ \t\n]*\\(no\\|fr\\)\\.[^,]*\\)*$" iso-8859-1 (iso-8859-1))
190 ("^\\(fido7\\|relcom\\)\\.[^,]*\\(,[ \t\n]*\\(fido7\\|relcom\\)\\.[^,]*\\)*$" koi8-r (koi8-r))
191 (message-this-is-mail nil nil)
192 (message-this-is-news nil t))
194 "Alist of regexps and permitted unencoded charsets for posting.
195 Each element of the alist has the form (TEST HEADER BODY-LIST), where
196 TEST is either a regular expression matching the newsgroup header or a
198 HEADER is the charset which may be left unencoded in the header (nil
199 means encode all charsets),
200 BODY-LIST is a list of charsets which may be encoded using 8bit
201 content-transfer encoding in the body, or one of the special values
202 nil (always encode using quoted-printable) or t (always use 8bit).
204 Note that any value other than nil for HEADER infringes some RFCs, so
205 use this option with care."
206 :variable-group gnus-charset
208 '(repeat (list :tag "Permitted unencoded charsets"
210 (regexp :tag "Group")
211 (const :tag "Mail message" :value message-this-is-mail)
212 (const :tag "News article" :value message-this-is-news))
213 (choice :tag "Header"
214 (const :tag "None" nil)
215 (symbol :tag "Charset"))
217 (const :tag "Any" :value t)
218 (const :tag "None" :value nil)
219 (repeat :tag "Charsets"
220 (symbol :tag "Charset")))))
221 :parameter-type '(choice :tag "Permitted unencoded charsets"
224 :parameter-document "\
225 List of charsets that are permitted to be unencoded.")
227 (defcustom gnus-debug-files
228 '("gnus.el" "gnus-sum.el" "gnus-group.el"
229 "gnus-art.el" "gnus-start.el" "gnus-async.el"
230 "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
231 "gnus-agent.el" "gnus-cache.el" "gnus-srvr.el"
232 "mm-util.el" "mm-decode.el" "nnmail.el" "message.el")
233 "Files whose variables will be reported in `gnus-bug'."
236 :type '(repeat (string :tag "File")))
238 (defcustom gnus-debug-exclude-variables
239 '(mm-mime-mule-charset-alist
240 nnmail-split-fancy message-minibuffer-local-map)
241 "Variables that should not be reported in `gnus-bug'."
244 :type '(repeat (symbol :tag "Variable")))
246 (defcustom gnus-discouraged-post-methods
247 '(nndraft nnml nnimap nnmaildir nnmh nnfolder nndir)
248 "A list of back ends that are not used in \"real\" newsgroups.
249 This variable is used only when `gnus-post-method' is `current'."
251 :group 'gnus-group-foreign
252 :type '(repeat (symbol :tag "Back end")))
254 (defcustom gnus-message-replysign
256 "Automatically sign replies to signed messages.
257 See also the `mml-default-sign-method' variable."
261 (defcustom gnus-message-replyencrypt t
262 "Automatically encrypt replies to encrypted messages.
263 See also the `mml-default-encrypt-method' variable."
268 (defcustom gnus-message-replysignencrypted
270 "Setting this causes automatically encrypted messages to also be signed."
274 (defcustom gnus-confirm-mail-reply-to-news (and gnus-novice-user
275 (not gnus-expert-user))
276 "If non-nil, Gnus requests confirmation when replying to news.
277 This is done because new users often reply by mistake when reading
279 This can also be a function receiving the group name as the only
280 parameter, which should return non-nil if a confirmation is needed; or
281 a regexp, in which case a confirmation is asked for if the group name
283 :version "23.1" ;; No Gnus (default changed)
285 :type '(choice (const :tag "No" nil)
287 (regexp :tag "If group matches regexp")
288 (function :tag "If function evaluates to non-nil")))
290 (defcustom gnus-confirm-treat-mail-like-news
292 "If non-nil, Gnus will treat mail like news with regard to confirmation
293 when replying by mail. See the `gnus-confirm-mail-reply-to-news' variable
294 for fine-tuning this.
295 If nil, Gnus will never ask for confirmation if replying to mail."
300 (defcustom gnus-summary-resend-default-address t
301 "If non-nil, Gnus tries to suggest a default address to resend to.
302 If nil, the address field will always be empty after invoking
303 `gnus-summary-resend-message'."
308 (defcustom gnus-message-highlight-citation
309 t ;; gnus-treat-highlight-citation ;; gnus-cite dependency
310 "Enable highlighting of different citation levels in message-mode."
311 :version "23.1" ;; No Gnus
316 (defcustom gnus-gcc-pre-body-encode-hook nil
317 "A hook called before encoding the body of the Gcc copy of a message.
318 The current buffer (when the hook is run) contains the message
319 including the message header. Changes made to the message will
320 only affect the Gcc copy, but not the original message."
325 (defcustom gnus-gcc-post-body-encode-hook nil
326 "A hook called after encoding the body of the Gcc copy of a message.
327 The current buffer (when the hook is run) contains the message
328 including the message header. Changes made to the message will
329 only affect the Gcc copy, but not the original message."
334 (autoload 'gnus-message-citation-mode "gnus-cite" nil t)
336 ;;; Internal variables.
338 (defvar gnus-inhibit-posting-styles nil
339 "Inhibit the use of posting styles.")
341 (defvar gnus-article-yanked-articles nil)
342 (defvar gnus-message-buffer "*Mail Gnus*")
343 (defvar gnus-article-copy nil)
344 (defvar gnus-check-before-posting nil)
345 (defvar gnus-last-posting-server nil)
346 (defvar gnus-message-group-art nil)
348 (defvar gnus-msg-force-broken-reply-to nil)
350 (defconst gnus-bug-message
351 "Sending a bug report to the Gnus Towers.
352 ========================================
354 The buffer below is a mail buffer. When you press `C-c C-c', it will
355 be sent to the Gnus Bug Exterminators.
357 The thing near the bottom of the buffer is how the environment
358 settings will be included in the mail. Please do not delete that.
359 They will tell the Bug People what your environment is, so that it
360 will be easier to locate the bugs.
362 If you have found a bug that makes Emacs go \"beep\", set
363 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
364 and include the backtrace in your bug report.
366 Please describe the bug in annoying, painstaking detail.
368 Thank you for your help in stamping out bugs.
371 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
375 ;;; Gnus Posting Functions
378 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
379 "p" gnus-summary-post-news
380 "i" gnus-summary-news-other-window
381 "f" gnus-summary-followup
382 "F" gnus-summary-followup-with-original
383 "c" gnus-summary-cancel-article
384 "s" gnus-summary-supersede-article
385 "r" gnus-summary-reply
386 "y" gnus-summary-yank-message
387 "R" gnus-summary-reply-with-original
388 "L" gnus-summary-reply-to-list-with-original
389 "w" gnus-summary-wide-reply
390 "W" gnus-summary-wide-reply-with-original
391 "v" gnus-summary-very-wide-reply
392 "V" gnus-summary-very-wide-reply-with-original
393 "n" gnus-summary-followup-to-mail
394 "N" gnus-summary-followup-to-mail-with-original
395 "m" gnus-summary-mail-other-window
396 "u" gnus-uu-post-news
397 "\M-c" gnus-summary-mail-crosspost-complaint
398 "Br" gnus-summary-reply-broken-reply-to
399 "BR" gnus-summary-reply-broken-reply-to-with-original
400 "om" gnus-summary-mail-forward
401 "op" gnus-summary-post-forward
402 "Om" gnus-uu-digest-mail-forward
403 "Op" gnus-uu-digest-post-forward)
405 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
406 "b" gnus-summary-resend-bounced-mail
407 ;; "c" gnus-summary-send-draft
408 "r" gnus-summary-resend-message
409 "e" gnus-summary-resend-message-edit)
411 ;;; Internal functions.
413 (defun gnus-inews-make-draft (articles)
415 (gnus-inews-make-draft-meta-information
416 ,(gnus-group-decoded-name gnus-newsgroup-name) ',articles)))
418 (defvar gnus-article-reply nil)
419 (defmacro gnus-setup-message (config &rest forms)
420 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
421 (winconf-name (make-symbol "gnus-setup-message-winconf-name"))
422 (buffer (make-symbol "gnus-setup-message-buffer"))
423 (article (make-symbol "gnus-setup-message-article"))
424 (yanked (make-symbol "gnus-setup-yanked-articles"))
425 (group (make-symbol "gnus-setup-message-group")))
426 `(let ((,winconf (current-window-configuration))
427 (,winconf-name gnus-current-window-configuration)
428 (,buffer (buffer-name (current-buffer)))
429 (,article (or (when (and
430 (string-match "^nnir:" gnus-newsgroup-name)
432 (nnir-article-number gnus-article-reply))
434 (,yanked gnus-article-yanked-articles)
435 (,group (or (when (and
436 (string-match "^nnir:" gnus-newsgroup-name)
438 (nnir-article-group gnus-article-reply))
439 gnus-newsgroup-name))
440 (message-header-setup-hook
441 (copy-sequence message-header-setup-hook))
442 (mbl mml-buffer-list)
443 (message-mode-hook (copy-sequence message-mode-hook)))
444 (setq mml-buffer-list nil)
445 (add-hook 'message-header-setup-hook (lambda ()
446 (gnus-inews-insert-gcc ,group)))
447 ;; message-newsreader and message-mailer were formerly set in
448 ;; gnus-inews-add-send-actions, but this is too late when
449 ;; message-generate-headers-first is used. --ansel
450 (add-hook 'message-mode-hook
452 (setq message-newsreader
453 (setq message-mailer (gnus-extended-version)))))
454 ;; #### FIXME: for a reason that I did not manage to identify yet,
455 ;; the variable `gnus-newsgroup-name' does not honor a dynamically
456 ;; scoped or setq'ed value from a caller like `C-u gnus-summary-mail'.
457 ;; After evaluation of @forms below, it gets the value we actually want
458 ;; to override, and the posting styles are used. For that reason, I've
459 ;; added an optional argument to `gnus-configure-posting-styles' to
460 ;; make sure that the correct value for the group name is used. -- drv
461 (add-hook 'message-mode-hook
462 (if (memq ,config '(reply-yank reply))
464 (gnus-configure-posting-styles ,group))
466 ;; There may be an old " *gnus article copy*" buffer.
467 (let (gnus-article-copy)
468 (gnus-configure-posting-styles ,group)))))
469 (gnus-alist-pull ',(intern gnus-draft-meta-information-header)
470 message-required-headers)
472 (not (string= ,group "")))
474 (intern gnus-draft-meta-information-header)
475 (gnus-inews-make-draft (or ,yanked ,article)))
476 message-required-headers))
480 (gnus-inews-add-send-actions ,winconf ,buffer ,article ,config
481 ,yanked ,winconf-name)
482 (setq gnus-message-buffer (current-buffer))
483 (set (make-local-variable 'gnus-message-group-art)
484 (cons ,group ,article))
485 (set (make-local-variable 'gnus-newsgroup-name) ,group)
486 ;; Enable highlighting of different citation levels
487 (when gnus-message-highlight-citation
488 (gnus-message-citation-mode 1))
489 (gnus-run-hooks 'gnus-message-setup-hook)
490 (if (eq major-mode 'message-mode)
491 (let ((mbl1 mml-buffer-list))
492 (setq mml-buffer-list mbl) ;; Global value
493 (set (make-local-variable 'mml-buffer-list) mbl1);; Local value
494 (gnus-make-local-hook 'kill-buffer-hook)
495 (gnus-make-local-hook 'change-major-mode-hook)
496 (add-hook 'change-major-mode-hook 'mml-destroy-buffers nil t)
497 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))
498 (mml-destroy-buffers)
499 (setq mml-buffer-list mbl)))
500 (message-hide-headers)
502 (gnus-configure-windows ,config t)
503 (run-hooks 'post-command-hook)
504 (set-buffer-modified-p nil))))
506 (defun gnus-inews-make-draft-meta-information (group articles)
507 (when (numberp articles)
508 (setq articles (list articles)))
509 (concat "(\"" group "\""
523 (defun gnus-msg-mail (&optional to subject other-headers continue
524 switch-action yank-action send-actions
526 "Start editing a mail message to be sent.
527 Like `message-mail', but with Gnus paraphernalia, particularly the
528 Gcc: header for archiving purposes.
529 If Gnus isn't running, a plain `message-mail' setup is used
532 (if (not (gnus-alive-p))
534 (message "Gnus not running; using plain Message mode")
535 (message-mail to subject other-headers continue
536 nil yank-action send-actions return-action))
537 (let ((buf (current-buffer))
538 (gnus-newsgroup-name (or gnus-newsgroup-name ""))
540 (gnus-setup-message 'message
541 (message-mail to subject other-headers continue
542 nil yank-action send-actions return-action))
544 (setq mail-buf (current-buffer))
545 (switch-to-buffer buf)
546 (apply switch-action mail-buf nil))
547 ;; COMPOSEFUNC should return t if succeed. Undocumented ???