message.el 297 KB
Newer Older
1
;;; message.el --- composing mail and news messages -*- lexical-binding: t -*-
2

Paul Eggert's avatar
Paul Eggert committed
3
;; Copyright (C) 1996-2019 Free Software Foundation, Inc.
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
4

5
;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
6 7 8 9
;; Keywords: mail, news

;; This file is part of GNU Emacs.

10
;; GNU Emacs is free software: you can redistribute it and/or modify
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
11
;; it under the terms of the GNU General Public License as published by
12 13
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
14 15 16

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
18 19 20
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
21
;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
22 23 24 25 26 27 28 29 30

;;; Commentary:

;; This mode provides mail-sending facilities from within Emacs.  It
;; consists mainly of large chunks of code from the sendmail.el,
;; gnus-msg.el and rnewspost.el files.

;;; Code:

31
(require 'cl-lib)
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
32
(require 'mailheader)
33
(require 'gmm-utils)
34 35 36 37
(require 'mail-utils)
;; Only for the trivial macros mail-header-from, mail-header-date
;; mail-header-references, mail-header-subject, mail-header-id
(eval-when-compile (require 'nnheader))
38 39 40
;; This is apparently necessary even though things are autoloaded.
;; Because we dynamically bind mail-abbrev-mode-regexp, we'd better
;; require mailabbrev here.
41
(require 'mailabbrev)
42 43
(require 'mail-parse)
(require 'mml)
44
(require 'rfc822)
45
(require 'format-spec)
Gnus developers's avatar
Gnus developers committed
46
(require 'dired)
47 48
(require 'mm-util)
(require 'rfc2047)
49
(require 'puny)
50
(require 'rmc)			; read-multiple-choice
51
(eval-when-compile (require 'subr-x))	; when-let*
52

53
(autoload 'mailclient-send-it "mailclient")
54

Dan Nicolaescu's avatar
Dan Nicolaescu committed
55 56 57
(defvar gnus-message-group-art)
(defvar gnus-list-identifiers) ; gnus-sum is required where necessary
(defvar rmail-enable-mime-composing)
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
58 59 60 61 62 63 64 65 66

(defgroup message '((user-mail-address custom-variable)
		    (user-full-name custom-variable))
  "Mail and news message composing."
  :link '(custom-manual "(message)Top")
  :group 'mail
  :group 'news)

(defgroup message-various nil
67
  "Various Message Variables."
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
68 69 70 71
  :link '(custom-manual "(message)Various Message Variables")
  :group 'message)

(defgroup message-buffers nil
72
  "Message Buffers."
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
73 74 75 76
  :link '(custom-manual "(message)Message Buffers")
  :group 'message)

(defgroup message-sending nil
77
  "Message Sending."
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
78 79 80 81
  :link '(custom-manual "(message)Sending Variables")
  :group 'message)

(defgroup message-interface nil
82
  "Message Interface."
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
83 84 85 86
  :link '(custom-manual "(message)Interface")
  :group 'message)

(defgroup message-forwarding nil
87
  "Message Forwarding."
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
88 89 90 91
  :link '(custom-manual "(message)Forwarding")
  :group 'message-interface)

(defgroup message-insertion nil
92
  "Message Insertion."
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
93 94 95 96
  :link '(custom-manual "(message)Insertion")
  :group 'message)

(defgroup message-headers nil
97
  "Message Headers."
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
98 99 100 101
  :link '(custom-manual "(message)Message Headers")
  :group 'message)

(defgroup message-news nil
102
  "Composing News Messages."
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
103 104 105
  :group 'message)

(defgroup message-mail nil
106
  "Composing Mail Messages."
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
107 108 109 110 111 112 113 114
  :group 'message)

(defgroup message-faces nil
  "Faces used for message composing."
  :group 'message
  :group 'faces)

(defcustom message-directory "~/Mail/"
115
  "Directory from which all other mail file variables are derived."
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
116 117 118 119
  :group 'message-various
  :type 'directory)

(defcustom message-max-buffers 10
120
  "How many buffers to keep before starting to kill them off."
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
121 122 123 124 125 126
  :group 'message-buffers
  :type 'integer)

(defcustom message-send-rename-function nil
  "Function called to rename the buffer after sending it."
  :group 'message-buffers
Dave Love's avatar
Dave Love committed
127
  :type '(choice function (const nil)))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
128 129

(defcustom message-fcc-handler-function 'message-output
130
  "A function called to save outgoing articles.
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
131 132 133 134 135 136 137
This function will be called with the name of the file to store the
article in.  The default function is `message-output' which saves in Unix
mailbox format."
  :type '(radio (function-item message-output)
		(function :tag "Other"))
  :group 'message-sending)

138 139
(defcustom message-fcc-externalize-attachments nil
  "If non-nil, attachments are included as external parts in Fcc copies."
140
  :version "22.1"
141 142 143
  :type 'boolean
  :group 'message-sending)

Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
144
(defcustom message-courtesy-message
145
  "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
146
  "This is inserted at the start of a mailed copy of a posted message.
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
147 148 149 150
If the string contains the format spec \"%s\", the Newsgroups
the article has been posted to will be inserted there.
If this variable is nil, no such courtesy message will be added."
  :group 'message-sending
151
  :type '(radio string (const nil)))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
152

153 154
(defcustom message-ignored-bounced-headers
  "^\\(Received\\|Return-Path\\|Delivered-To\\):"
155
  "Regexp that matches headers to be removed in resent bounced mail."
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
156 157 158
  :group 'message-interface
  :type 'regexp)

159
(defcustom message-from-style 'angles
160
  "Specifies how \"From\" headers look.
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
161

Dave Love's avatar
Dave Love committed
162
If nil, they contain just the return address like:
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
163 164 165 166 167 168 169 170
	king@grassland.com
If `parens', they look like:
	king@grassland.com (Elvis Parsley)
If `angles', they look like:
	Elvis Parsley <king@grassland.com>

Otherwise, most addresses look like `angles', but they look like
`parens' if `angles' would need quoting and `parens' would not."
171
  :version "27.1"
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
172 173 174 175 176
  :type '(choice (const :tag "simple" nil)
		 (const parens)
		 (const angles)
		 (const default))
  :group 'message-headers)
177 178 179 180
(make-obsolete-variable
 'message-from-style
 "Only the `angles' value is valid according to RFC2822" "27.1")

Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
181

182 183
(defcustom message-insert-canlock t
  "Whether to insert a Cancel-Lock header in news postings."
184
  :version "22.1"
185 186 187 188 189
  :group 'message-headers
  :type 'boolean)

(defcustom message-syntax-checks
  (if message-insert-canlock '((sender . disabled)) nil)
190
  ;; Guess this one shouldn't be easy to customize...
191
  "Controls what syntax checks should not be performed on outgoing posts.
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
192 193 194 195 196
To disable checking of long signatures, for instance, add
 `(signature . disabled)' to this list.

Don't touch this variable unless you really know what you're doing.

Miles Bader's avatar
Miles Bader committed
197 198
Checks include `approved', `bogus-recipient', `continuation-headers',
`control-chars', `empty', `existing-newsgroups', `from', `illegible-text',
Miles Bader's avatar
Miles Bader committed
199 200
`invisible-text', `long-header-lines', `long-lines', `message-id',
`multiple-headers', `new-text', `newsgroups', `quoting-style',
Miles Bader's avatar
Miles Bader committed
201
`repeated-newsgroups', `reply-to', `sender', `sendsys', `shoot',
Miles Bader's avatar
Miles Bader committed
202 203
`shorten-followup-to', `signature', `size', `subject', `subject-cmsg'
and `valid-newsgroups'."
204
  :group 'message-news
Dave Love's avatar
Dave Love committed
205
  :type '(repeat sexp))			; Fixme: improve this
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
206

207 208
(defcustom message-required-headers '((optional . References)
				      From)
209
  "Headers to be generated or prompted for when sending a message.
210 211
Also see `message-required-news-headers' and
`message-required-mail-headers'."
212
  :version "22.1"
213 214 215 216 217
  :group 'message-news
  :group 'message-headers
  :link '(custom-manual "(message)Message Headers")
  :type '(repeat sexp))

218
(defcustom message-draft-headers '(References From Date)
219
  "Headers to be generated when saving a draft message."
220
  :version "22.1"
221 222 223 224 225
  :group 'message-news
  :group 'message-headers
  :link '(custom-manual "(message)Message Headers")
  :type '(repeat sexp))

Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
226 227
(defcustom message-required-news-headers
  '(From Newsgroups Subject Date Message-ID
228
	 (optional . Organization)
229
	 (optional . User-Agent))
230
  "Headers to be generated or prompted for when posting an article.
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
231 232
RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
Message-ID.  Organization, Lines, In-Reply-To, Expires, and
Miles Bader's avatar
Miles Bader committed
233
User-Agent are optional.  If you don't want message to insert some
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
234 235 236
header, remove it from this list."
  :group 'message-news
  :group 'message-headers
237
  :link '(custom-manual "(message)Message Headers")
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
238 239 240
  :type '(repeat sexp))

(defcustom message-required-mail-headers
241
  '(From Subject Date (optional . In-Reply-To) Message-ID
242
	 (optional . User-Agent))
243
  "Headers to be generated or prompted for when mailing a message.
244 245
It is recommended that From, Date, To, Subject and Message-ID be
included.  Organization and User-Agent are optional."
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
246 247
  :group 'message-mail
  :group 'message-headers
248
  :link '(custom-manual "(message)Message Headers")
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
249 250
  :type '(repeat sexp))

251 252 253
(defcustom message-prune-recipient-rules nil
  "Rules for how to prune the list of recipients when doing wide replies.
This is a list of regexps and regexp matches."
254
  :version "24.1"
255 256 257 258 259
  :group 'message-mail
  :group 'message-headers
  :link '(custom-manual "(message)Wide Reply")
  :type '(repeat regexp))

Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
260
(defcustom message-deletable-headers '(Message-ID Date Lines)
261
  "Headers to delete if present and previously generated by message."
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
262
  :group 'message-headers
263
  :link '(custom-manual "(message)Message Headers")
264
  :type '(repeat (symbol :tag "Header")))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
265 266

(defcustom message-ignored-news-headers
267
  "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:\\|^X-Message-SMTP-Method:\\|^X-Gnus-Delayed:"
268
  "Regexp of headers to be removed unconditionally before posting."
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
269 270
  :group 'message-news
  :group 'message-headers
271
  :link '(custom-manual "(message)Message Headers")
272 273 274 275 276 277
  :type '(repeat :value-to-internal (lambda (widget value)
				      (custom-split-regexp-maybe value))
		 :match (lambda (widget value)
			  (or (stringp value)
			      (widget-editable-list-match widget value)))
		 regexp))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
278

279
(defcustom message-ignored-mail-headers
280
  "^\\([GF]cc\\|Resent-Fcc\\|Xref\\|X-Draft-From\\|X-Gnus-Agent-Meta-Information\\):"
281
  "Regexp of headers to be removed unconditionally before mailing."
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
282 283
  :group 'message-mail
  :group 'message-headers
284
  :link '(custom-manual "(message)Mail Headers")
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
285 286
  :type 'regexp)

287
(defcustom message-ignored-supersedes-headers "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Xref:\\|^Lines:\\|^Received:\\|^X-From-Line:\\|^X-Trace:\\|^X-ID:\\|^X-Complaints-To:\\|Return-Path:\\|^Supersedes:\\|^NNTP-Posting-Date:\\|^X-Trace:\\|^X-Complaints-To:\\|^Cancel-Lock:\\|^Cancel-Key:\\|^X-Hashcash:\\|^X-Payment:\\|^Approved:\\|^Injection-Date:\\|^Injection-Info:"
288
  "Header lines matching this regexp will be deleted before posting.
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
289 290 291
It's best to delete old Path and Date headers before posting to avoid
any confusion."
  :group 'message-interface
292
  :link '(custom-manual "(message)Superseding")
293 294 295 296 297 298
  :type '(repeat :value-to-internal (lambda (widget value)
				      (custom-split-regexp-maybe value))
		 :match (lambda (widget value)
			  (or (stringp value)
			      (widget-editable-list-match widget value)))
		 regexp))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
299

300
(defcustom message-subject-re-regexp
301
  "^[ \t]*\\([Rr][Ee]\\(\\[[0-9]*\\]\\)* ?:[ \t]*\\)*[ \t]*"
302
  "Regexp matching \"Re: \" in the subject line."
303
  :group 'message-various
304
  :link '(custom-manual "(message)Message Headers")
305 306
  :type 'regexp)

307 308
;;; Start of variables adopted from `message-utils.el'.

309
(defcustom message-subject-trailing-was-query t
310
  "What to do with trailing \"(was: <old subject>)\" in subject lines.
311
If nil, leave the subject unchanged.  If it is the symbol `ask', query
312
the user what to do.  In this case, the subject is matched against
313 314 315 316
`message-subject-trailing-was-ask-regexp'.  If
`message-subject-trailing-was-query' is t, always strip the trailing
old subject.  In this case, `message-subject-trailing-was-regexp' is
used."
317
  :version "24.1"
318 319
  :type '(choice (const :tag "never" nil)
		 (const :tag "always strip" t)
320
		 (const ask))
321 322 323 324
  :link '(custom-manual "(message)Message Headers")
  :group 'message-various)

(defcustom message-subject-trailing-was-ask-regexp
325
  "[ \t]*\\([[(]+[Ww][Aa][Ss]:?[ \t]*.*[])]+\\)"
326
  "Regexp matching \"(was: <old subject>)\" in the subject line.
327 328 329 330 331 332 333

The function `message-strip-subject-trailing-was' uses this regexp if
`message-subject-trailing-was-query' is set to the symbol `ask'.  If
the variable is t instead of `ask', use
`message-subject-trailing-was-regexp' instead.

It is okay to create some false positives here, as the user is asked."
334
  :version "22.1"
335 336 337 338 339
  :group 'message-various
  :link '(custom-manual "(message)Message Headers")
  :type 'regexp)

(defcustom message-subject-trailing-was-regexp
340
  "[ \t]*\\((*[Ww][Aa][Ss]:[ \t]*.*)\\)"
341
  "Regexp matching \"(was: <old subject>)\" in the subject line.
342 343 344 345 346

If `message-subject-trailing-was-query' is set to t, the subject is
matched against `message-subject-trailing-was-regexp' in
`message-strip-subject-trailing-was'.  You should use a regexp creating very
few false positives here."
347
  :version "22.1"
348 349 350 351 352 353 354
  :group 'message-various
  :link '(custom-manual "(message)Message Headers")
  :type 'regexp)

;;; marking inserted text

(defcustom message-mark-insert-begin
355
  "--8<---------------cut here---------------start------------->8---\n"
356
  "How to mark the beginning of some inserted text."
357
  :version "22.1"
358 359 360 361 362
  :type 'string
  :link '(custom-manual "(message)Insertion Variables")
  :group 'message-various)

(defcustom message-mark-insert-end
363
  "--8<---------------cut here---------------end--------------->8---\n"
364
  "How to mark the end of some inserted text."
365
  :version "22.1"
366 367 368 369
  :type 'string
  :link '(custom-manual "(message)Insertion Variables")
  :group 'message-various)

370
(defcustom message-archive-header "X-No-Archive: Yes\n"
371
  "Header to insert when you don't want your article to be archived.
372
Archives \(such as groups.google.com) respect this header."
373
  :version "22.1"
374 375 376 377 378 379 380 381
  :type 'string
  :link '(custom-manual "(message)Header Commands")
  :group 'message-various)

(defcustom message-archive-note
  "X-No-Archive: Yes - save http://groups.google.com/"
  "Note to insert why you wouldn't want this posting archived.
If nil, don't insert any text in the body."
382
  :version "22.1"
383
  :type '(radio string (const nil))
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399
  :link '(custom-manual "(message)Header Commands")
  :group 'message-various)

;;; Crossposts and Followups
;; inspired by JoH-followup-to by Jochem Huhman <joh  at gmx.de>
;; new suggestions by R. Weikusat <rw at another.de>

(defvar message-cross-post-old-target nil
  "Old target for cross-posts or follow-ups.")
(make-variable-buffer-local 'message-cross-post-old-target)

(defcustom message-cross-post-default t
  "When non-nil `message-cross-post-followup-to' will perform a crosspost.
If nil, `message-cross-post-followup-to' will only do a followup.  Note that
you can explicitly override this setting by calling
`message-cross-post-followup-to' with a prefix."
400
  :version "22.1"
401 402 403
  :type 'boolean
  :group 'message-various)

404
(defcustom message-cross-post-note "Crosspost & Followup-To: "
405
  "Note to insert before signature to notify of cross-post and follow-up."
406
  :version "22.1"
407 408 409
  :type 'string
  :group 'message-various)

410
(defcustom message-followup-to-note "Followup-To: "
411
  "Note to insert before signature to notify of follow-up only."
412
  :version "22.1"
413 414 415
  :type 'string
  :group 'message-various)

416
(defcustom message-cross-post-note-function 'message-cross-post-insert-note
417 418 419 420
  "Function to use to insert note about Crosspost or Followup-To.
The function will be called with four arguments.  The function should not only
insert a note, but also ensure old notes are deleted.  See the documentation
for `message-cross-post-insert-note'."
421
  :version "22.1"
422 423 424 425 426
  :type 'function
  :group 'message-various)

;;; End of variables adopted from `message-utils.el'.

Miles Bader's avatar
Miles Bader committed
427 428 429 430 431 432 433 434 435 436
(defcustom message-signature-separator "^-- $"
  "Regexp matching the signature separator.
This variable is used to strip off the signature from quoted text
when `message-cite-function' is
`message-cite-original-without-signature'.  Most useful values
are \"^-- $\" (strict) and \"^-- *$\" (loose; allow missing
whitespace)."
  :type '(choice (const :tag "strict" "^-- $")
		 (const :tag "loose" "^-- *$")
		 regexp)
Miles Bader's avatar
Miles Bader committed
437
  :version "22.3" ;; Gnus 5.10.12 (changed default)
438
  :link '(custom-manual "(message)Various Message Variables")
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
439 440
  :group 'message-various)

441
(defcustom message-elide-ellipsis "\n[...]\n\n"
442
  "The string which is inserted for elided text.
443 444 445
This is a format-spec string, and you can use %l to say how many
lines were removed, and %c to say how many characters were
removed."
446
  :type 'string
447
  :link '(custom-manual "(message)Various Commands")
448
  :group 'message-various)
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
449

450
(defcustom message-interactive mail-interactive
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
451
  "Non-nil means when sending a message wait for and display errors.
Juanma Barranquero's avatar
Juanma Barranquero committed
452
A value of nil means let mailer mail back a message to report errors."
453
  :version "23.2"
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
454 455
  :group 'message-sending
  :group 'message-mail
456
  :link '(custom-manual "(message)Sending Variables")
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
457 458
  :type 'boolean)

Miles Bader's avatar
Miles Bader committed
459
(defcustom message-confirm-send nil
Miles Bader's avatar
Miles Bader committed
460
  "When non-nil, ask for confirmation when sending a message."
Miles Bader's avatar
Miles Bader committed
461 462
  :group 'message-sending
  :group 'message-mail
Miles Bader's avatar
Miles Bader committed
463
  :version "23.1" ;; No Gnus
Miles Bader's avatar
Miles Bader committed
464 465 466
  :link '(custom-manual "(message)Sending Variables")
  :type 'boolean)

467
(defcustom message-generate-new-buffers 'unsent
468
  "Say whether to create a new message buffer to compose a message.
Miles Bader's avatar
Miles Bader committed
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489
Valid values include:

nil
  Generate the buffer name in the Message way (e.g., *mail*, *news*,
  *mail to whom*, *news on group*, etc.) and continue editing in the
  existing buffer of that name.  If there is no such buffer, it will
  be newly created.

`unique' or t
  Create the new buffer with the name generated in the Message way.

`unsent'
  Similar to `unique' but the buffer name begins with \"*unsent \".

`standard'
  Similar to nil but the buffer name is simpler like *mail message*.

function
  If this is a function, call that function with three parameters:
  The type, the To address and the group name (any of these may be nil).
  The function should return the new buffer name."
490
  :version "24.1"
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
491
  :group 'message-buffers
492
  :link '(custom-manual "(message)Message Buffers")
Miles Bader's avatar
Miles Bader committed
493 494 495 496 497 498
  :type '(choice (const nil)
		 (sexp :tag "unique" :format "unique\n" :value unique
		       :match (lambda (widget value) (memq value '(unique t))))
		 (const unsent)
		 (const standard)
		 (function :format "\n    %{%t%}: %v")))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
499 500

(defcustom message-kill-buffer-on-exit nil
501
  "Non-nil means that the message buffer will be killed after sending a message."
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
502
  :group 'message-buffers
503
  :link '(custom-manual "(message)Message Buffers")
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
504 505
  :type 'boolean)

506
(defcustom message-kill-buffer-query t
507
  "Non-nil means that killing a modified message buffer has to be confirmed.
508
This is used by `message-kill-buffer'."
509
  :version "23.1" ;; No Gnus
510 511 512
  :group 'message-buffers
  :type 'boolean)

Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
513
(defcustom message-user-organization
514 515
  (or (getenv "ORGANIZATION") t)
  "String to be used as an Organization header.
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
516 517 518 519 520
If t, use `message-user-organization-file'."
  :group 'message-headers
  :type '(choice string
		 (const :tag "consult file" t)))

521 522 523 524 525 526 527 528
(defcustom message-user-organization-file
  (let (orgfile)
    (dolist (f (list "/etc/organization"
		     "/etc/news/organization"
		     "/usr/lib/news/organization"))
      (when (file-readable-p f)
	(setq orgfile f)))
    orgfile)
529
  "Local news organization file."
530
  :type '(choice (const nil) file)
531
  :link '(custom-manual "(message)News Headers")
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
532 533
  :group 'message-headers)

534
(defcustom message-make-forward-subject-function
535
  #'message-forward-subject-name-subject
536
  "List of functions called to generate subject headers for forwarded messages.
537 538 539 540 541
The subject generated by the previous function is passed into each
successive function.

The provided functions are:

542 543 544 545
* `message-forward-subject-author-subject' Source of article (author or
      newsgroup), in brackets followed by the subject
* `message-forward-subject-name-subject' Source of article (name of author
      or newsgroup), in brackets followed by the subject
546
* `message-forward-subject-fwd' Subject of article with `Fwd:' prepended
547
      to it."
548
  :group 'message-forwarding
549
  :link '(custom-manual "(message)Forwarding")
550
  :type '(radio (function-item message-forward-subject-author-subject)
Dave Love's avatar
Dave Love committed
551
		(function-item message-forward-subject-fwd)
552
		(function-item message-forward-subject-name-subject)
Dave Love's avatar
Dave Love committed
553
		(repeat :tag "List of functions" function)))
554

555
(defcustom message-forward-as-mime nil
556
  "Non-nil means forward messages as an inline/rfc822 MIME section.
557 558 559 560 561 562
Otherwise, directly inline the old message in the forwarded
message.

When forwarding as MIME, certain MIME-related headers in the
forwarded message may be removed/altered to ensure that the
resulting mail is syntactically valid."
563
  :version "27.1"
564
  :group 'message-forwarding
565
  :link '(custom-manual "(message)Forwarding")
566 567
  :type 'boolean)

568
(defcustom message-forward-show-mml 'best
569
  "Non-nil means show forwarded messages as MML (decoded from MIME).
570 571 572 573 574 575
Otherwise, forwarded messages are unchanged.
Can also be the symbol `best' to indicate that MML should be
used, except when it is a bad idea to use MML.  One example where
it is a bad idea is when forwarding a signed or encrypted
message, because converting MIME to MML would invalidate the
digital signature."
576
  :version "21.1"
577
  :group 'message-forwarding
578 579 580
  :type '(choice (const :tag "use MML" t)
		 (const :tag "don't use MML " nil)
		 (const :tag "use MML when appropriate" best)))
581 582

(defcustom message-forward-before-signature t
583
  "Non-nil means put forwarded message before signature, else after."
584 585
  :group 'message-forwarding
  :type 'boolean)
586 587

(defcustom message-wash-forwarded-subjects nil
588
  "Non-nil means try to remove as much cruft as possible from the subject.
589
Done before generating the new subject of a forward."
590
  :group 'message-forwarding
591
  :link '(custom-manual "(message)Forwarding")
592 593
  :type 'boolean)

594 595 596 597 598 599
(defcustom message-ignored-resent-headers
  ;; `Delivered-To' needs to be removed because some mailers use it to
  ;; detect loops, so if you resend a message to an address that ultimately
  ;; comes back to you (e.g. a mailing-list to which you subscribe, in which
  ;; case you may be removed from the list on the grounds that mail to you
  ;; bounced with a "mailing loop" error).
600 601
  "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:\\|^>?From \\|^Delivered-To:\
\\|^X-Content-Length:\\|^X-UIDL:"
602
  "All headers that match this regexp will be deleted when resending a message."
603
  :version "24.4"
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
604
  :group 'message-interface
605
  :link '(custom-manual "(message)Resending")
606 607 608 609 610 611
  :type '(repeat :value-to-internal (lambda (widget value)
				      (custom-split-regexp-maybe value))
		 :match (lambda (widget value)
			  (or (stringp value)
			      (widget-editable-list-match widget value)))
		 regexp))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
612

613
(defcustom message-forward-ignored-headers "^Content-Transfer-Encoding:\\|^X-Gnus"
614
  "All headers that match this regexp will be deleted when forwarding a message.
615 616 617
This variable is only consulted when forwarding \"normally\", not
when forwarding as MIME or the like.

Gnus developers's avatar
Gnus developers committed
618
This may also be a list of regexps."
619
  :version "21.1"
620
  :group 'message-forwarding
621 622 623 624 625
  :type '(repeat :value-to-internal (lambda (widget value)
				      (custom-split-regexp-maybe value))
		 :match (lambda (widget value)
			  (or (stringp value)
			      (widget-editable-list-match widget value)))
626 627
		 regexp))

628 629
(defcustom message-forward-included-headers
  '("^From:" "^Subject:" "^Date:")
Gnus developers's avatar
Gnus developers committed
630 631 632
  "If non-nil, delete non-matching headers when forwarding a message.
Only headers that match this regexp will be included.  This
variable should be a regexp or a list of regexps."
633
  :version "27.1"
Gnus developers's avatar
Gnus developers committed
634 635 636 637 638 639 640 641
  :group 'message-forwarding
  :type '(repeat :value-to-internal (lambda (widget value)
				      (custom-split-regexp-maybe value))
		 :match (lambda (widget value)
			  (or (stringp value)
			      (widget-editable-list-match widget value)))
		 regexp))

Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
642
(defcustom message-ignored-cited-headers "."
643
  "Delete these headers from the messages you yank."
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
644
  :group 'message-insertion
645 646 647
  :link '(custom-manual "(message)Insertion Variables")
  :type 'regexp)

648
(defcustom message-cite-prefix-regexp mail-citation-prefix-regexp
649
  "Regexp matching the longest possible citation prefix on a line."
650
  :version "24.1"
651 652
  :group 'message-insertion
  :link '(custom-manual "(message)Insertion Variables")
653 654 655 656 657 658 659
  :type 'regexp
  :set (lambda (symbol value)
	 (prog1
	     (custom-set-default symbol value)
	   (if (boundp 'gnus-message-cite-prefix-regexp)
	       (setq gnus-message-cite-prefix-regexp
		     (concat "^\\(?:" value "\\)"))))))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
660

661
(defcustom message-cancel-message "I am canceling my own article.\n"
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
662 663
  "Message to be inserted in the cancel message."
  :group 'message-interface
664
  :link '(custom-manual "(message)Canceling News")
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
665 666
  :type 'string)

667 668
(defun message-send-mail-function ()
  "Return suitable value for the variable `message-send-mail-function'."
669
  (cond ((and (require 'sendmail)
670
	      (boundp 'sendmail-program)
671
	      sendmail-program
672
	      (executable-find sendmail-program))
673
	 'message-send-mail-with-sendmail)
674
	((and (locate-library "smtpmail")
675
	      (boundp 'smtpmail-default-smtp-server)
676 677 678
	      smtpmail-default-smtp-server)
	 'message-smtpmail-send-it)
	((locate-library "mailclient")
679 680
	 'message-send-mail-with-mailclient)
	(t
681
	 (error "Don't know how to send mail.  Please customize `message-send-mail-function'"))))
682

683
(defun message-default-send-mail-function ()
Glenn Morris's avatar
Glenn Morris committed
684 685
  (cond ((eq send-mail-function 'smtpmail-send-it) 'message-smtpmail-send-it)
	((eq send-mail-function 'feedmail-send-it) 'feedmail-send-it)
686
	((eq send-mail-function 'sendmail-query-once) 'sendmail-query-once)
Glenn Morris's avatar
Glenn Morris committed
687 688
	((eq send-mail-function 'mailclient-send-it)
	 'message-send-mail-with-mailclient)
689 690 691 692
	(t (message-send-mail-function))))

;; Useful to set in site-init.el
(defcustom message-send-mail-function (message-default-send-mail-function)
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
693 694 695 696
  "Function to call to send the current buffer as mail.
The headers should be delimited by a line whose contents match the
variable `mail-header-separator'.

697
Valid values include `message-send-mail-with-sendmail'
Dave Love's avatar
Dave Love committed
698
`message-send-mail-with-mh', `message-send-mail-with-qmail',
699 700
`message-smtpmail-send-it', `smtpmail-send-it',
`feedmail-send-it' and `message-send-mail-with-mailclient'.  The
Miles Bader's avatar
Miles Bader committed
701 702
default is system dependent and determined by the function
`message-send-mail-function'.
Dave Love's avatar
Dave Love committed
703 704

See also `send-mail-function'."
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
705 706 707
  :type '(radio (function-item message-send-mail-with-sendmail)
		(function-item message-send-mail-with-mh)
		(function-item message-send-mail-with-qmail)
708
		(function-item message-smtpmail-send-it)
709
		(function-item smtpmail-send-it)
Dave Love's avatar
Dave Love committed
710
		(function-item feedmail-send-it)
711 712 713
		(function-item message-send-mail-with-mailclient
			       :tag "Use Mailclient package")
 		(function :tag "Other"))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
714
  :group 'message-sending
Glenn Morris's avatar
Glenn Morris committed
715
  :version "23.2"
716
  :initialize 'custom-initialize-default
717
  :link '(custom-manual "(message)Mail Variables")
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
718 719 720 721 722 723 724 725
  :group 'message-mail)

(defcustom message-send-news-function 'message-send-news
  "Function to call to send the current buffer as news.
The headers should be delimited by a line whose contents match the
variable `mail-header-separator'."
  :group 'message-sending
  :group 'message-news
726
  :link '(custom-manual "(message)News Variables")
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
727 728 729
  :type 'function)

(defcustom message-reply-to-function nil
Dave Love's avatar
Dave Love committed
730
  "If non-nil, function that should return a list of headers.
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
731 732 733
This function should pick out addresses from the To, Cc, and From headers
and respond with new To and Cc headers."
  :group 'message-interface
734
  :link '(custom-manual "(message)Reply")
Dave Love's avatar
Dave Love committed
735
  :type '(choice function (const nil)))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
736 737

(defcustom message-wide-reply-to-function nil
Dave Love's avatar
Dave Love committed
738
  "If non-nil, function that should return a list of headers.
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
739 740 741
This function should pick out addresses from the To, Cc, and From headers
and respond with new To and Cc headers."
  :group 'message-interface
742
  :link '(custom-manual "(message)Wide Reply")
Dave Love's avatar
Dave Love committed
743
  :type '(choice function (const nil)))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
744 745

(defcustom message-followup-to-function nil
Dave Love's avatar
Dave Love committed
746
  "If non-nil, function that should return a list of headers.
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
747 748 749
This function should pick out addresses from the To, Cc, and From headers
and respond with new To and Cc headers."
  :group 'message-interface
750
  :link '(custom-manual "(message)Followup")
Dave Love's avatar
Dave Love committed
751
  :type '(choice function (const nil)))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
752

753 754 755 756 757 758
(defcustom message-extra-wide-headers nil
  "If non-nil, a list of additional address headers.
These are used when composing a wide reply."
  :group 'message-sending
  :type '(repeat string))

Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
759
(defcustom message-use-followup-to 'ask
760
  "Specifies what to do with Followup-To header.
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
761 762 763 764 765
If nil, always ignore the header.  If it is t, use its value, but
query before using the \"poster\" value.  If it is the symbol `ask',
always query the user whether to use the value.  If it is the symbol
`use', always use the value."
  :group 'message-interface
766
  :link '(custom-manual "(message)Followup")
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
767
  :type '(choice (const :tag "ignore" nil)
768
		 (const :tag "use & query" t)
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
769 770 771
		 (const use)
		 (const ask)))

772
(defcustom message-use-mail-followup-to 'use
773
  "Specifies what to do with Mail-Followup-To header.
774 775 776
If nil, always ignore the header.  If it is the symbol `ask', always
query the user whether to use the value.  If it is the symbol `use',
always use the value."
777
  :version "22.1"
778 779 780 781 782 783 784
  :group 'message-interface
  :link '(custom-manual "(message)Mailing Lists")
  :type '(choice (const :tag "ignore" nil)
		 (const use)
		 (const ask)))

(defcustom message-subscribed-address-functions nil
785
  "Specifies functions for determining list subscription.
786 787 788 789 790
If nil, do not attempt to determine list subscription with functions.
If non-nil, this variable contains a list of functions which return
regular expressions to match lists.  These functions can be used in
conjunction with `message-subscribed-regexps' and
`message-subscribed-addresses'."
791
  :version "22.1"
792 793 794 795 796
  :group 'message-interface
  :link '(custom-manual "(message)Mailing Lists")
  :type '(repeat sexp))

(defcustom message-subscribed-address-file nil
797
  "A file containing addresses the user is subscribed to.
798 799
If nil, do not look at any files to determine list subscriptions.  If
non-nil, each line of this file should be a mailing list address."
800
  :version "22.1"
801 802
  :group 'message-interface
  :link '(custom-manual "(message)Mailing Lists")
803
  :type '(radio file (const nil)))
804 805

(defcustom message-subscribed-addresses nil
806
  "Specifies a list of addresses the user is subscribed to.
807 808 809
If nil, do not use any predefined list subscriptions.  This list of
addresses can be used in conjunction with
`message-subscribed-address-functions' and `message-subscribed-regexps'."
810
  :version "22.1"
811 812 813 814 815
  :group 'message-interface
  :link '(custom-manual "(message)Mailing Lists")
  :type '(repeat string))

(defcustom message-subscribed-regexps nil
816
  "Specifies a list of addresses the user is subscribed to.
817 818 819
If nil, do not use any predefined list subscriptions.  This list of
regular expressions can be used in conjunction with
`message-subscribed-address-functions' and `message-subscribed-addresses'."
820
  :version "22.1"
821 822 823 824 825 826 827 828 829
  :group 'message-interface
  :link '(custom-manual "(message)Mailing Lists")
  :type '(repeat regexp))

(defcustom message-allow-no-recipients 'ask
  "Specifies what to do when there are no recipients other than Gcc/Fcc.
If it is the symbol `always', the posting is allowed.  If it is the
symbol `never', the posting is not allowed.  If it is the symbol
`ask', you are prompted."
830
  :version "22.1"
831 832 833 834 835 836
  :group 'message-interface
  :link '(custom-manual "(message)Message Headers")
  :type '(choice (const always)
		 (const never)
		 (const ask)))

Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
837
(defcustom message-sendmail-f-is-evil nil
838
  "Non-nil means don't add \"-f username\" to the sendmail command line.
839
Doing so would be even more evil than leaving it out."
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
840
  :group 'message-sending
841
  :link '(custom-manual "(message)Mail Variables")
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
842 843
  :type 'boolean)

844
(defcustom message-sendmail-envelope-from
845
  ;; `mail-envelope-from' is unavailable unless sendmail.el is loaded.
846
  (if (boundp 'mail-envelope-from) mail-envelope-from)
847
  "Envelope-from when sending mail with sendmail.
848 849
If this is nil, use `user-mail-address'.  If it is the symbol
`header', use the From: header of the message."
850
  :version "23.2"
851 852 853 854 855 856
  :type '(choice (string :tag "From name")
		 (const :tag "Use From: header from message" header)
		 (const :tag "Use `user-mail-address'" nil))
  :link '(custom-manual "(message)Mail Variables")
  :group 'message-sending)

857 858 859
(defcustom message-sendmail-extra-arguments nil
  "Additional arguments to `sendmail-program'."
  ;; E.g. '("-a" "account") for msmtp
860
  :version "23.1" ;; No Gnus
861 862 863 864
  :type '(repeat string)
  ;; :link '(custom-manual "(message)Mail Variables")
  :group 'message-sending)

Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
865 866 867 868
;; qmail-related stuff
(defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
  "Location of the qmail-inject program."
  :group 'message-sending
869
  :link '(custom-manual "(message)Mail Variables")
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
870 871 872 873
  :type 'file)

(defcustom message-qmail-inject-args nil
  "Arguments passed to qmail-inject programs.
Juanma Barranquero's avatar
Juanma Barranquero committed
874 875
This should be a list of strings, one string for each argument.
It may also be a function.
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
876 877 878

For e.g., if you wish to set the envelope sender address so that bounces
go to the right place or to deal with listserv's usage of that address, you
879
might set this variable to (\"-f\" \"you@some.where\")."
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
880
  :group 'message-sending
881 882 883
  :link '(custom-manual "(message)Mail Variables")
  :type '(choice (function)
		 (repeat string)))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
884

Dan Nicolaescu's avatar
Dan Nicolaescu committed
885 886
(defvar gnus-post-method)
(defvar gnus-select-method)
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
887 888
(defcustom message-post-method
  (cond ((and (boundp 'gnus-post-method)
889
	      (listp gnus-post-method)
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
890 891 892 893 894
	      gnus-post-method)
	 gnus-post-method)
	((boundp 'gnus-select-method)
	 gnus-select-method)
	(t '(nnspool "")))
895
  "Method used to post news.
896 897
Note that when posting from inside Gnus, for instance, this
variable isn't used."
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
898 899 900 901 902 903
  :group 'message-news
  :group 'message-sending
  ;; This should be the `gnus-select-method' widget, but that might
  ;; create a dependence to `gnus.el'.
  :type 'sexp)

904
(defcustom message-generate-headers-first nil
905
  "Which headers should be generated before starting to compose a message.
906
If t, generate all required headers.  This can also be a list of headers to
907 908 909 910 911 912
generate.  The variables `message-required-news-headers' and
`message-required-mail-headers' specify which headers to generate.

Note that the variable `message-deletable-headers' specifies headers which
are to be deleted and then re-generated before sending, so this variable
will not have a visible effect for those headers."
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
913
  :group 'message-headers
914 915
  :link '(custom-manual "(message)Message Headers")
  :type '(choice (const :tag "None" nil)
916 917 918 919 920 921 922 923 924 925 926
		 (const :tag "All" t)
		 (repeat (sexp :tag "Header"))))

(defcustom message-fill-column 72
  "Column beyond which automatic line-wrapping should happen.
Local value for message buffers.  If non-nil, also turn on
auto-fill in message buffers."
  :group 'message-various
  ;; :link '(custom-manual "(message)Message Headers")
  :type '(choice (const :tag "Don't turn on auto fill" nil)
		 (integer)))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
927

928 929 930 931 932 933
(defcustom message-setup-hook nil
  "Normal hook, run each time a new outgoing message is initialized.
The function `message-setup' runs this hook."
  :group 'message-various
  :link '(custom-manual "(message)Various Message Variables")
  :type 'hook)
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
934

935
(defcustom message-cancel-hook nil
Paul Eggert's avatar
Paul Eggert committed