1 ;;; sendmail.el --- mail sending commands for Emacs. -*- byte-compile-dynamic: t -*-
3 ;; Copyright (C) 1985, 1986, 1992, 1993, 1994, 1995, 1996, 1998, 2000,
4 ;; 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
5 ;; Free Software Foundation, Inc.
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
27 ;; This mode provides mail-sending facilities from within Emacs. It is
28 ;; documented in the Emacs user's manual.
32 ;; Necessary to avoid recursive `require's.
37 (autoload 'rfc2047-encode-string
"rfc2047")
39 (defgroup sendmail nil
40 "Mail sending commands for Emacs."
44 (defcustom mail-setup-with-from t
45 "Non-nil means insert `From:' field when setting up the message."
50 (defcustom sendmail-program
52 ((file-exists-p "/usr/sbin/sendmail") "/usr/sbin/sendmail")
53 ((file-exists-p "/usr/lib/sendmail") "/usr/lib/sendmail")
54 ((file-exists-p "/usr/ucblib/sendmail") "/usr/ucblib/sendmail")
55 (t "fakemail")) ;In ../etc, to interface to /bin/mail.
56 "Program used to send messages."
61 (defcustom mail-from-style
'default
62 "Specifies how \"From:\" fields look.
64 If `nil', they contain just the return address like:
66 If `parens', they look like:
67 king@grassland.com (Elvis Parsley)
68 If `angles', they look like:
69 Elvis Parsley <king@grassland.com>
71 Otherwise, most addresses look like `angles', but they look like
72 `parens' if `angles' would need quoting and `parens' would not."
73 ;; The value `system-default' is now deprecated.
74 :type
'(choice (const :tag
"simple" nil
)
82 (defcustom mail-specify-envelope-from nil
83 "If non-nil, specify the envelope-from address when sending mail.
84 The value used to specify it is whatever is found in
85 the variable `mail-envelope-from', with `user-mail-address' as fallback.
87 On most systems, specifying the envelope-from address is a
88 privileged operation. This variable affects sendmail and
89 smtpmail -- if you use feedmail to send mail, see instead the
90 variable `feedmail-deduce-envelope-from'."
95 (defcustom mail-envelope-from nil
96 "If non-nil, designate the envelope-from address when sending mail.
97 This only has an effect if `mail-specify-envelope-from' is non-nil.
98 The value should be either a string, or the symbol `header' (in
99 which case the contents of the \"From\" header of the message
100 being sent is used), or nil (in which case the value of
101 `user-mail-address' is used)."
103 :type
'(choice (string :tag
"From-name")
104 (const :tag
"Use From: header from message" header
)
105 (const :tag
"Use `user-mail-address'" nil
))
109 (defcustom mail-self-blind nil
110 "Non-nil means insert BCC to self in messages to be sent.
111 This is done when the message is initialized,
112 so you can remove or alter the BCC field to override the default."
117 (defcustom mail-interactive t
118 ;; We used to use a default of nil rather than t, but nowadays it is very
119 ;; common for sendmail to be misconfigured, so one cannot rely on the
120 ;; bounce message to be delivered anywhere, least of all to the
122 "Non-nil means when sending a message wait for and display errors.
123 Otherwise, let mailer send back a message to report errors."
125 :version
"23.1" ; changed from nil to t
128 (defcustom mail-yank-ignored-headers
130 (regexp-opt '("via" "mail-from" "origin" "status" "remailed"
131 "received" "message-id" "summary-line" "to" "subject"
132 "in-reply-to" "return-path" "mail-reply-to"
133 ;; Should really be rmail-attribute-header and
134 ;; rmail-keyword-header, but this file does not
135 ;; require rmail (at run time).
136 "x-rmail-attributes" "x-rmail-keywords"
137 "mail-followup-to") "\\(?:")
139 "Delete these headers from old message when it's inserted in a reply."
144 ;; Prevent problems with `window-system' not having the correct value
145 ;; when loaddefs.el is loaded. `custom-reevaluate-setting' needs the
148 (put 'send-mail-function
'standard-value
149 '((if (and window-system
(memq system-type
'(darwin windows-nt
)))
153 ;; Useful to set in site-init.el
155 (defcustom send-mail-function
156 (if (and window-system
(memq system-type
'(darwin windows-nt
)))
159 "Function to call to send the current buffer as mail.
160 The headers should be delimited by a line which is
161 not a valid RFC822 header or continuation line,
162 that matches the variable `mail-header-separator'.
163 This is used by the default mail-sending commands. See also
164 `message-send-mail-function' for use with the Message package."
165 :type
'(radio (function-item sendmail-send-it
:tag
"Use Sendmail package")
166 (function-item smtpmail-send-it
:tag
"Use SMTPmail package")
167 (function-item feedmail-send-it
:tag
"Use Feedmail package")
168 (function-item mailclient-send-it
:tag
"Use Mailclient package")
170 :initialize
'custom-initialize-delay
173 ;;;###autoload(custom-initialize-delay 'send-mail-function nil)
176 (defcustom mail-header-separator
(purecopy "--text follows this line--")
177 "Line used to separate headers from text in messages being composed."
181 ;; Set up mail-header-separator for use as a category text property.
182 (put 'mail-header-separator
'rear-nonsticky
'(category))
183 ;; This was a nice idea, for preventing accidental modification of
184 ;; the separator. But I found it also prevented or obstructed
185 ;; certain deliberate operations, such as copying the separator line
186 ;; up to the top to send myself a copy of an already sent outgoing message
187 ;; and other things. So I turned it off. --rms.
188 ;;(put 'mail-header-separator 'read-only t)
191 (defcustom mail-archive-file-name nil
192 "Name of file to write all outgoing messages in, or nil for none.
193 This is normally an mbox file, but for backwards compatibility may also
195 :type
'(choice file
(const nil
))
199 (defcustom mail-default-reply-to nil
200 "Address to insert as default Reply-to field of outgoing messages.
201 If nil, it will be initialized from the REPLYTO environment variable
202 when you first send mail."
203 :type
'(choice (const nil
) string
)
207 (defcustom mail-alias-file nil
208 "If non-nil, the name of a file to use instead of `/usr/lib/aliases'.
209 This file defines aliases to be expanded by the mailer; this is a different
210 feature from that of defining aliases in `.mailrc' to be expanded in Emacs.
211 This variable has no effect unless your system uses sendmail as its mailer."
212 :type
'(choice (const nil
) file
)
216 (defcustom mail-personal-alias-file
(purecopy "~/.mailrc")
217 "If non-nil, the name of the user's personal mail alias file.
218 This file typically should be in same format as the `.mailrc' file used by
219 the `Mail' or `mailx' program.
220 This file need not actually exist."
221 :type
'(choice (const nil
) file
)
225 (defcustom mail-setup-hook nil
226 "Normal hook, run each time a new outgoing message is initialized."
228 :options
'(fortune-to-signature spook mail-abbrevs-setup
)
232 (defvar mail-aliases t
233 "Alist of mail address aliases,
234 or t meaning should be initialized from your mail aliases file.
235 \(The file's name is normally `~/.mailrc', but `mail-personal-alias-file'
236 can specify a different file name.)
237 The alias definitions in the file have this form:
238 alias ALIAS MEANING")
240 (defvar mail-alias-modtime nil
241 "The modification time of your mail alias file when it was last examined.")
244 (defcustom mail-yank-prefix
"> "
245 "Prefix insert on lines of yanked message being replied to.
246 If this is nil, use indentation, as specified by `mail-indentation-spaces'."
247 :type
'(choice (const nil
) string
)
251 (defcustom mail-indentation-spaces
3
252 "Number of spaces to insert at the beginning of each cited line.
253 Used by `mail-yank-original' via `mail-indent-citation'."
257 ;; FIXME make it really obsolete.
258 (defvar mail-yank-hooks nil
259 "Obsolete hook for modifying a citation just inserted in the mail buffer.
260 Each hook function can find the citation between (point) and (mark t).
261 And each hook function should leave point and mark around the citation
264 This is a normal hook, misnamed for historical reasons.
265 It is semi-obsolete and mail agents should no longer use it.")
268 (defcustom mail-citation-hook nil
269 "Hook for modifying a citation just inserted in the mail buffer.
270 Each hook function can find the citation between (point) and (mark t),
271 and should leave point and mark around the citation text as modified.
272 The hook functions can find the header of the cited message
273 in the variable `mail-citation-header', whether or not this is included
274 in the cited portion of the message.
276 If this hook is entirely empty (nil), a default action is taken
277 instead of no action."
281 (defvar mail-citation-header nil
282 "While running `mail-citation-hook', this variable holds the message header.
283 This enables the hook functions to see the whole message header
284 regardless of what part of it (if any) is included in the cited text.")
287 (defcustom mail-citation-prefix-regexp
288 (purecopy "\\([ \t]*\\(\\w\\|[_.]\\)+>+\\|[ \t]*[]>|}]\\)+")
289 "Regular expression to match a citation prefix plus whitespace.
290 It should match whatever sort of citation prefixes you want to handle,
291 with whitespace before and after; it should also match just whitespace.
292 The default value matches citations like `foo-bar>' plus whitespace."
297 (defvar mail-abbrevs-loaded nil
)
298 (defvar mail-mode-map
299 (let ((map (make-sparse-keymap)))
300 (define-key map
"\M-\t" 'mail-complete
)
301 (define-key map
"\C-c?" 'describe-mode
)
302 (define-key map
"\C-c\C-f\C-t" 'mail-to
)
303 (define-key map
"\C-c\C-f\C-b" 'mail-bcc
)
304 (define-key map
"\C-c\C-f\C-f" 'mail-fcc
)
305 (define-key map
"\C-c\C-f\C-c" 'mail-cc
)
306 (define-key map
"\C-c\C-f\C-s" 'mail-subject
)
307 (define-key map
"\C-c\C-f\C-r" 'mail-reply-to
)
308 (define-key map
"\C-c\C-f\C-a" 'mail-mail-reply-to
) ; author
309 (define-key map
"\C-c\C-f\C-l" 'mail-mail-followup-to
) ; list
310 (define-key map
"\C-c\C-t" 'mail-text
)
311 (define-key map
"\C-c\C-y" 'mail-yank-original
)
312 (define-key map
"\C-c\C-r" 'mail-yank-region
)
313 (define-key map
[remap split-line
] 'mail-split-line
)
314 (define-key map
"\C-c\C-q" 'mail-fill-yanked-message
)
315 (define-key map
"\C-c\C-w" 'mail-signature
)
316 (define-key map
"\C-c\C-v" 'mail-sent-via
)
317 (define-key map
"\C-c\C-c" 'mail-send-and-exit
)
318 (define-key map
"\C-c\C-s" 'mail-send
)
319 (define-key map
"\C-c\C-i" 'mail-attach-file
)
320 ;; FIXME add this? "b" = bury buffer. It's in the menu-bar.
321 ;;; (define-key map "\C-c\C-b" 'mail-dont-send)
323 (define-key map
[menu-bar mail
]
324 (cons "Mail" (make-sparse-keymap "Mail")))
326 (define-key map
[menu-bar mail fill
]
327 '("Fill Citation" . mail-fill-yanked-message
))
329 (define-key map
[menu-bar mail yank
]
330 '(menu-item "Cite Original" mail-yank-original
:enable mail-reply-action
))
332 (define-key map
[menu-bar mail signature
]
333 '("Insert Signature" . mail-signature
))
335 (define-key map
[menu-bar mail mail-sep
]
338 (define-key map
[menu-bar mail cancel
]
339 '("Cancel" . mail-dont-send
))
341 (define-key map
[menu-bar mail send-stay
]
342 '("Send, Keep Editing" . mail-send
))
344 (define-key map
[menu-bar mail send
]
345 '("Send Message" . mail-send-and-exit
))
347 (define-key map
[menu-bar headers
]
348 (cons "Headers" (make-sparse-keymap "Move to Header")))
350 (define-key map
[menu-bar headers text
]
351 '("Text" . mail-text
))
353 (define-key map
[menu-bar headers expand-aliases
]
354 '("Expand Aliases" . expand-mail-aliases
))
356 (define-key map
[menu-bar headers sent-via
]
357 '("Sent-Via" . mail-sent-via
))
359 (define-key map
[menu-bar headers mail-reply-to
]
360 '("Mail-Reply-To" . mail-mail-reply-to
))
362 (define-key map
[menu-bar headers mail-followup-to
]
363 '("Mail-Followup-To" . mail-mail-followup-to
))
365 (define-key map
[menu-bar headers reply-to
]
366 '("Reply-To" . mail-reply-to
))
368 (define-key map
[menu-bar headers bcc
]
371 (define-key map
[menu-bar headers fcc
]
374 (define-key map
[menu-bar headers cc
]
377 (define-key map
[menu-bar headers subject
]
378 '("Subject" . mail-subject
))
380 (define-key map
[menu-bar headers to
]
385 (autoload 'build-mail-aliases
"mailalias"
386 "Read mail aliases from user's personal aliases file and set `mail-aliases'."
389 (autoload 'expand-mail-aliases
"mailalias"
390 "Expand all mail aliases in suitable header fields found between BEG and END.
391 Suitable header fields are `To', `Cc' and `Bcc' and their `Resent-' variants.
392 Optional second arg EXCLUDE may be a regular expression defining text to be
393 removed from alias expansions."
397 (defcustom mail-signature t
398 "Text inserted at end of mail buffer when a message is initialized.
399 If t, it means to insert the contents of the file `mail-signature-file'.
400 If a string, that string is inserted.
401 (To make a proper signature, the string should begin with \\n\\n-- \\n,
402 which is the standard way to delimit a signature in a message.)
403 Otherwise, it should be an expression; it is evaluated
404 and should insert whatever you want to insert."
405 :type
'(choice (const :tag
"None" nil
)
406 (const :tag
"Use `.signature' file" t
)
407 (string :tag
"String to insert")
408 (sexp :tag
"Expression to evaluate"))
410 (put 'mail-signature
'risky-local-variable t
)
413 (defcustom mail-signature-file
(purecopy "~/.signature")
414 "File containing the text inserted at end of mail buffer."
419 (defcustom mail-default-directory
(purecopy "~/")
420 "Directory for mail buffers.
421 Value of `default-directory' for mail buffers.
422 This directory is used for auto-save files of mail buffers."
423 :type
'(directory :tag
"Directory")
427 (defvar mail-reply-action nil
)
428 (defvar mail-send-actions nil
429 "A list of actions to be performed upon successful sending of a message.")
430 (put 'mail-reply-action
'permanent-local t
)
431 (put 'mail-send-actions
'permanent-local t
)
434 (defcustom mail-default-headers nil
435 "A string containing header lines, to be inserted in outgoing messages.
436 It can contain newlines, and should end in one. It is inserted
437 before you edit the message, so you can edit or delete the lines."
438 :type
'(choice (const nil
) string
)
441 ;; FIXME no need for autoload
443 (defcustom mail-bury-selects-summary t
444 "If non-nil, try to show Rmail summary buffer after returning from mail.
445 The functions \\[mail-send-on-exit] or \\[mail-dont-send] select
446 the Rmail summary buffer before returning, if it exists and this variable
451 ;; FIXME no need for autoload
453 (defcustom mail-send-nonascii
'mime
454 "Specify whether to allow sending non-ASCII characters in mail.
455 If t, that means do allow it. nil means don't allow it.
456 `query' means ask the user each time.
457 `mime' means add an appropriate MIME header if none already present.
458 The default is `mime'.
459 Including non-ASCII characters in a mail message can be problematical
460 for the recipient, who may not know how to decode them properly."
461 :type
'(choice (const t
) (const nil
) (const query
) (const mime
))
464 (defcustom mail-use-dsn nil
465 "Ask MTA for notification of failed, delayed or successful delivery.
466 Note that only some MTAs (currently only recent versions of Sendmail)
467 support Delivery Status Notification."
469 :type
'(repeat (radio (const :tag
"Failure" failure
)
470 (const :tag
"Delay" delay
)
471 (const :tag
"Success" success
)))
474 ;; Note: could use /usr/ucb/mail instead of sendmail;
475 ;; options -t, and -v if not interactive.
476 (defvar mail-mailer-swallows-blank-line
477 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)" system-configuration
)
478 (file-readable-p "/etc/sendmail.cf")
480 (insert-file-contents "/etc/sendmail.cf")
481 (goto-char (point-min))
482 (let ((case-fold-search nil
))
483 (re-search-forward "^OR\\>" nil t
))))
484 ;; According to RFC822, "The field-name must be composed of printable
485 ;; ASCII characters (i.e. characters that have decimal values between
486 ;; 33 and 126, except colon)", i.e. any chars except ctl chars,
488 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
489 "Set this non-nil if the system's mailer runs the header and body together.
490 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
491 The value should be an expression to test whether the problem will
494 (defvar mail-mode-syntax-table
495 ;; define-derived-mode will make it inherit from text-mode-syntax-table.
496 (let ((st (make-syntax-table)))
497 ;; FIXME this is probably very obsolete now ("percent hack").
498 ;; sending.texi used to say:
499 ;; Mail mode defines the character `%' as a word separator; this
500 ;; is helpful for using the word commands to edit mail addresses.
501 (modify-syntax-entry ?%
". " st
)
503 "Syntax table used while in `mail-mode'.")
505 (defvar mail-font-lock-keywords
507 (let* ((cite-chars "[>|}]")
508 (cite-prefix "[:alpha:]")
509 (cite-suffix (concat cite-prefix
"0-9_.@-`'\"")))
510 (list '("^\\(To\\|Newsgroups\\):" . font-lock-function-name-face
)
511 '("^\\(B?CC\\|Reply-to\\|Mail-\\(reply\\|followup\\)-to\\):" . font-lock-keyword-face
)
512 '("^\\(Subject:\\)[ \t]*\\(.+\\)?"
513 (1 font-lock-comment-face
)
514 ;; (2 font-lock-type-face nil t)
516 ;; Use EVAL to delay in case `mail-header-separator' gets changed.
518 (let ((separator (if (zerop (length mail-header-separator
))
520 (regexp-quote mail-header-separator
))))
521 (cons (concat "^" separator
"$") 'font-lock-warning-face
)))
522 ;; Use MATCH-ANCHORED to effectively anchor the regexp left side.
524 (,(concat "\\=[ \t]*"
525 "\\(\\(\\([" cite-prefix
"]+[" cite-suffix
"]*\\)?"
526 "\\(" cite-chars
"[ \t]*\\)\\)+\\)"
528 (beginning-of-line) (end-of-line)
529 (1 font-lock-comment-delimiter-face nil t
)
530 (5 font-lock-comment-face nil t
)))
531 '("^\\(X-[A-Za-z0-9-]+\\|In-reply-to\\):.*\\(\n[ \t]+.*\\)*$"
532 . font-lock-string-face
))))
533 "Additional expressions to highlight in Mail mode.")
536 (defun sendmail-sync-aliases ()
537 (when mail-personal-alias-file
538 (let ((modtime (nth 5 (file-attributes mail-personal-alias-file
))))
539 (or (equal mail-alias-modtime modtime
)
540 (setq mail-alias-modtime modtime
543 (defun mail-setup (to subject in-reply-to cc replybuffer actions
)
544 (or mail-default-reply-to
545 (setq mail-default-reply-to
(getenv "REPLYTO")))
546 (sendmail-sync-aliases)
547 (if (eq mail-aliases t
)
549 (setq mail-aliases nil
)
550 (when mail-personal-alias-file
551 (if (file-exists-p mail-personal-alias-file
)
552 (build-mail-aliases)))))
553 ;; Don't leave this around from a previous message.
554 (kill-local-variable 'buffer-file-coding-system
)
555 ;; This doesn't work for enable-multibyte-characters.
556 ;; (kill-local-variable 'enable-multibyte-characters)
557 (set-buffer-multibyte (default-value 'enable-multibyte-characters
))
558 (if current-input-method
559 (inactivate-input-method))
560 (setq mail-send-actions actions
)
561 (setq mail-reply-action replybuffer
)
562 (goto-char (point-min))
563 (if mail-setup-with-from
564 (mail-insert-from-field))
568 ;; Here removed code to extract names from within <...>
569 ;; on the assumption that mail-strip-quoted-names
570 ;; has been called and has done so.
571 (let ((fill-prefix "\t")
572 (address-start (point)))
574 (fill-region-as-paragraph address-start
(point-max))
575 (goto-char (point-max))
580 (let ((fill-prefix "\t")
581 (address-start (progn (insert "CC: ") (point))))
583 (fill-region-as-paragraph address-start
(point-max))
584 (goto-char (point-max))
588 (let ((fill-prefix "\t")
590 (address-start (point)))
591 (insert "In-reply-to: " in-reply-to
"\n")
592 (fill-region-as-paragraph address-start
(point-max))
593 (goto-char (point-max))
596 (insert "Subject: " (or subject
"") "\n")
597 (if mail-default-headers
598 (insert mail-default-headers
))
599 (if mail-default-reply-to
600 (insert "Reply-to: " mail-default-reply-to
"\n"))
602 (insert "BCC: " user-mail-address
"\n"))
603 (if mail-archive-file-name
604 (insert "FCC: " mail-archive-file-name
"\n"))
605 (put-text-property (point)
607 (insert mail-header-separator
"\n")
609 'category
'mail-header-separator
)
610 ;; Insert the signature. But remember the beginning of the message.
611 (if to
(setq to
(point)))
612 (if mail-signature
(mail-signature t
))
613 (goto-char (point-max))
614 (or (bolp) (newline)))
615 (if to
(goto-char to
))
616 (or to subject in-reply-to
617 (set-buffer-modified-p nil
))
618 (run-hooks 'mail-setup-hook
))
620 (defcustom mail-mode-hook nil
621 "Hook run by Mail mode.
622 When composing a mail, this runs immediately after creating, or
623 switching to, the `*mail*' buffer. See also `mail-setup-hook'."
626 :options
'(footnote-mode))
628 (defvar mail-mode-abbrev-table text-mode-abbrev-table
)
630 (define-derived-mode mail-mode text-mode
"Mail"
631 "Major mode for editing mail to be sent.
632 Like Text Mode but with these additional commands:
634 \\[mail-send] mail-send (send the message)
635 \\[mail-send-and-exit] mail-send-and-exit (send the message and exit)
637 Here are commands that move to a header field (and create it if there isn't):
638 \\[mail-to] move to To: \\[mail-subject] move to Subj:
639 \\[mail-bcc] move to BCC: \\[mail-cc] move to CC:
640 \\[mail-fcc] move to FCC: \\[mail-reply-to] move to Reply-To:
641 \\[mail-mail-reply-to] move to Mail-Reply-To:
642 \\[mail-mail-followup-to] move to Mail-Followup-To:
643 \\[mail-text] move to message text.
644 \\[mail-signature] mail-signature (insert `mail-signature-file' file).
645 \\[mail-yank-original] mail-yank-original (insert current message, in Rmail).
646 \\[mail-fill-yanked-message] mail-fill-yanked-message (fill what was yanked).
647 \\[mail-sent-via] mail-sent-via (add a sent-via field for each To or CC).
648 Turning on Mail mode runs the normal hooks `text-mode-hook' and
649 `mail-mode-hook' (in that order)."
650 (make-local-variable 'mail-reply-action
)
651 (make-local-variable 'mail-send-actions
)
652 (setq buffer-offer-save t
)
653 (make-local-variable 'font-lock-defaults
)
654 (setq font-lock-defaults
'(mail-font-lock-keywords t t
))
655 (make-local-variable 'paragraph-separate
)
656 (make-local-variable 'normal-auto-fill-function
)
657 (setq normal-auto-fill-function
'mail-mode-auto-fill
)
658 (make-local-variable 'fill-paragraph-function
)
659 (setq fill-paragraph-function
'mail-mode-fill-paragraph
)
660 ;; Allow using comment commands to add/remove quoting (this only does
661 ;; anything if mail-yank-prefix is set to a non-nil value).
662 (set (make-local-variable 'comment-start
) mail-yank-prefix
)
664 (set (make-local-variable 'comment-start-skip
)
665 (concat "^" (regexp-quote mail-yank-prefix
) "[ \t]*")))
666 (make-local-variable 'adaptive-fill-regexp
)
667 (setq adaptive-fill-regexp
668 (concat "[ \t]*[-[:alnum:]]+>+[ \t]*\\|"
669 adaptive-fill-regexp
))
670 (make-local-variable 'adaptive-fill-first-line-regexp
)
671 (setq adaptive-fill-first-line-regexp
672 (concat "[ \t]*[-[:alnum:]]*>+[ \t]*\\|"
673 adaptive-fill-first-line-regexp
))
674 ;; `-- ' precedes the signature. `-----' appears at the start of the
675 ;; lines that delimit forwarded messages.
676 ;; Lines containing just >= 3 dashes, perhaps after whitespace,
677 ;; are also sometimes used and should be separators.
678 (setq paragraph-separate
(concat (regexp-quote mail-header-separator
)
679 "$\\|\t*\\([-|#;>* ]\\|(?[0-9]+[.)]\\)+$"
680 "\\|[ \t]*[[:alnum:]]*>+[ \t]*$\\|[ \t]*$\\|"
685 (defun mail-header-end ()
686 "Return the buffer location of the end of headers, as a number."
693 (defun mail-text-start ()
694 "Return the buffer location of the start of text, as a number."
702 (defun mail-sendmail-delimit-header ()
703 "Set up whatever header delimiter convention sendmail will use.
704 Concretely: replace the first blank line in the header with the separator."
706 (insert mail-header-separator
)
709 (defun mail-sendmail-undelimit-header ()
710 "Remove header separator to put the message in correct form for sendmail.
711 Leave point at the start of the delimiter line."
713 (delete-region (point) (progn (end-of-line) (point))))
715 (defun mail-mode-auto-fill ()
716 "Carry out Auto Fill for Mail mode.
717 If within the headers, this makes the new lines into continuation lines."
718 (if (< (point) (mail-header-end))
719 (let ((old-line-start (save-excursion (beginning-of-line) (point))))
723 (while (not (eq (point) old-line-start
))
724 ;; Use insert-before-markers in case we're inserting
725 ;; before the saved value of point (which is common).
726 (insert-before-markers " ")
731 (defun mail-mode-fill-paragraph (arg)
732 ;; Do something special only if within the headers.
733 (if (< (point) (mail-header-end))
734 (let (beg end fieldname
)
735 (when (prog1 (re-search-backward "^[-a-zA-Z]+:" nil
'yes
)
738 (downcase (buffer-substring beg
(1- (match-end 0))))))
740 ;; Find continuation lines and get rid of their continuation markers.
741 (while (looking-at "[ \t]")
742 (delete-horizontal-space)
744 (setq end
(point-marker))
746 ;; If this field contains addresses,
747 ;; make sure we can fill after each address.
748 (if (member fieldname
749 '("to" "cc" "bcc" "from" "reply-to"
750 "mail-reply-to" "mail-followup-to"
751 "resent-to" "resent-cc" "resent-bcc"
752 "resent-from" "resent-reply-to"))
753 (while (search-forward "," end t
)
754 (or (looking-at "[ \t]")
756 (fill-region-as-paragraph beg end arg
)
757 ;; Mark all lines except the first as continuations.
760 (while (< (point) end
)
763 (move-marker end nil
)
766 ;; User-level commands for sending.
768 (defun mail-send-and-exit (&optional arg
)
769 "Send message like `mail-send', then, if no errors, exit from mail buffer.
770 Prefix arg means don't delete this window."
775 (defun mail-dont-send (&optional arg
)
776 "Don't send the message you have been editing.
777 Prefix arg means don't delete this window."
781 (defun mail-bury (&optional arg
)
782 "Bury this mail buffer."
783 (let ((newbuf (other-buffer (current-buffer))))
784 (bury-buffer (current-buffer))
786 ;; In this case, we need to go to a different frame.
787 (window-dedicated-p (frame-selected-window))
788 ;; In this mode of operation, the frame was probably
789 ;; made for this buffer, so the user probably wants
791 (and pop-up-frames
(one-window-p))
792 (cdr (assq 'mail-dedicated-frame
(frame-parameters))))
793 (not (null (delq (selected-frame) (visible-frame-list)))))
795 (if (display-multi-frame-p)
796 (delete-frame (selected-frame))
797 ;; The previous frame is where normally they have the
798 ;; Rmail buffer displayed.
800 (let (rmail-flag summary-buffer
)
804 (window-buffer (next-window (selected-window) 'not
))
805 (setq rmail-flag
(eq major-mode
'rmail-mode
))
807 (and mail-bury-selects-summary
808 (boundp 'rmail-summary-buffer
)
810 (buffer-name rmail-summary-buffer
)
811 (not (get-buffer-window rmail-summary-buffer
))
812 rmail-summary-buffer
))))
814 ;; If the Rmail buffer has a summary, show that.
815 (if summary-buffer
(switch-to-buffer summary-buffer
)
817 (switch-to-buffer newbuf
))))))
819 (defcustom mail-send-hook nil
820 "Hook run just before sending a message."
822 :options
'(flyspell-mode-off)
826 (defcustom mail-mailing-lists nil
827 "List of mailing list addresses the user is subscribed to.
828 The variable is used to trigger insertion of the \"Mail-Followup-To\"
829 header when sending a message to a mailing list."
830 :type
'(repeat string
)
835 "Send the message in the current buffer.
836 If `mail-interactive' is non-nil, wait for success indication
837 or error messages, and inform user.
838 Otherwise any failure is reported in a message back to
839 the user from the mailer."
841 (if (if buffer-file-name
842 (y-or-n-p "Send buffer contents as mail message? ")
843 (or (buffer-modified-p)
844 (y-or-n-p "Message already sent; resend? ")))
845 (let ((inhibit-read-only t
)
847 (ml (when mail-mailing-lists
848 ;; The surrounding regexp assumes the use of
849 ;; `mail-strip-quoted-names' on addresses before matching
850 ;; Cannot deal with full RFC 822 freedom, but that is
851 ;; unlikely to be problematic.
852 (concat "\\(?:[[:space:];,]\\|\\`\\)"
853 (regexp-opt mail-mailing-lists t
)
854 "\\(?:[[:space:];,]\\|\\'\\)"))))
855 ;; If there are mailing lists defined
858 (let* ((to (mail-fetch-field "to" nil t
))
859 (cc (mail-fetch-field "cc" nil t
))
860 (new-header-values ; To: and Cc:
861 (mail-strip-quoted-names
862 (concat to
(when cc
(concat ", " cc
))))))
863 ;; If message goes to known mailing list ...
864 (when (string-match ml new-header-values
)
865 ;; Add Mail-Followup-To if none yet
866 (unless (mail-fetch-field "mail-followup-to")
867 (goto-char (mail-header-end))
868 (insert "Mail-Followup-To: "
875 (split-string new-header-values
877 (mapconcat 'identity l
", "))
879 ;; Add Mail-Reply-To if none yet
880 (unless (mail-fetch-field "mail-reply-to")
881 (goto-char (mail-header-end))
882 (insert "Mail-Reply-To: "
883 (or (mail-fetch-field "reply-to")
886 (unless (memq mail-send-nonascii
'(t mime
))
887 (goto-char (point-min))
888 (skip-chars-forward "\0-\177")
889 (or (= (point) (point-max))
890 (if (eq mail-send-nonascii
'query
)
891 (or (y-or-n-p "Message contains non-ASCII characters; send anyway? ")
893 (error "Message contains non-ASCII characters"))))
894 ;; Complain about any invalid line.
895 (goto-char (point-min))
896 (re-search-forward (regexp-quote mail-header-separator
) (point-max) t
)
897 (let ((header-end (or (match-beginning 0) (point-max))))
898 (goto-char (point-min))
899 (while (< (point) header-end
)
900 (unless (looking-at "[ \t]\\|.*:\\|$")
902 (error "Invalid header line (maybe a continuation line lacks initial whitespace)"))
905 (run-hooks 'mail-send-hook
)
906 (message "Sending...")
907 (funcall send-mail-function
)
908 ;; Now perform actions on successful sending.
909 (while mail-send-actions
911 (apply (car (car mail-send-actions
))
912 (cdr (car mail-send-actions
)))
914 (setq mail-send-actions
(cdr mail-send-actions
)))
915 (message "Sending...done")
916 ;; If buffer has no file, mark it as unmodified and delete auto-save.
917 (if (not buffer-file-name
)
919 (set-buffer-modified-p nil
)
920 (delete-auto-save-file-if-necessary t
))))))
922 (defun mail-envelope-from ()
923 "Return the envelope mail address to use when sending mail.
924 This function uses `mail-envelope-from'."
925 (if (eq mail-envelope-from
'header
)
926 (nth 1 (mail-extract-address-components
927 (mail-fetch-field "From")))
930 ;; This does the real work of sending a message via sendmail.
931 ;; It is called via the variable send-mail-function.
934 (defvar sendmail-coding-system nil
935 "*Coding system for encoding the outgoing mail.
936 This has higher priority than the default `buffer-file-coding-system'
937 and `default-sendmail-coding-system',
938 but lower priority than the local value of `buffer-file-coding-system'.
939 See also the function `select-message-coding-system'.")
942 (defvar default-sendmail-coding-system
'iso-latin-1
943 "Default coding system for encoding the outgoing mail.
944 This variable is used only when `sendmail-coding-system' is nil.
946 This variable is set/changed by the command `set-language-environment'.
947 User should not set this variable manually,
948 instead use `sendmail-coding-system' to get a constant encoding
949 of outgoing mails regardless of the current language environment.
950 See also the function `select-message-coding-system'.")
952 (defun mail-insert-from-field ()
953 (let* ((login user-mail-address
)
954 (fullname (user-full-name))
955 (quote-fullname nil
))
956 (if (string-match "[^\0-\177]" fullname
)
957 (setq fullname
(rfc2047-encode-string fullname
)
959 (cond ((null mail-from-style
)
960 (insert "From: " login
"\n"))
961 ;; This is deprecated.
962 ((eq mail-from-style
'system-default
)
964 ((or (eq mail-from-style
'angles
)
965 (and (not (eq mail-from-style
'parens
))
966 ;; Use angles if no quoting is needed, or if
967 ;; parens would need quoting too.
968 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname
))
969 (let ((tmp (concat fullname nil
)))
970 (while (string-match "([^()]*)" tmp
)
971 (aset tmp
(match-beginning 0) ?-
)
972 (aset tmp
(1- (match-end 0)) ?-
))
973 (string-match "[\\()]" tmp
)))))
974 (insert "From: " fullname
)
975 (let ((fullname-start (+ (point-min) 6))
976 (fullname-end (point-marker)))
977 (goto-char fullname-start
)
978 ;; Look for a character that cannot appear unquoted
979 ;; according to RFC 822.
980 (if (or (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]"
984 ;; Quote fullname, escaping specials.
985 (goto-char fullname-start
)
987 (while (re-search-forward "[\"\\]"
989 (replace-match "\\\\\\&" t
))
991 (insert " <" login
">\n"))
992 ;; 'parens or default
994 (insert "From: " login
" (")
995 (let ((fullname-start (point)))
1001 (let ((fullname-end (point-marker)))
1002 (goto-char fullname-start
)
1003 ;; RFC 822 says \ and nonmatching parentheses
1004 ;; must be escaped in comments.
1005 ;; Escape every instance of ()\ ...
1006 (while (re-search-forward "[()\\]" fullname-end
1)
1007 (replace-match "\\\\\\&" t
))
1008 ;; ... then undo escaping of matching parentheses,
1009 ;; including matching nested parentheses.
1010 (goto-char fullname-start
)
1011 (while (re-search-forward
1012 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
1014 (replace-match "\\1(\\3)" t
)
1015 (goto-char fullname-start
))))
1018 ;; Normally you will not need to modify these options unless you are
1019 ;; using some non-genuine substitute for sendmail which does not
1020 ;; implement each and every option that the original supports.
1021 ;; E.g., ssmtp does not support "-odb", so, if your site uses it,
1022 ;; you will need to modify `sendmail-error-reporting-non-interactive'
1023 ;; in your site-init.el.
1024 (defvar sendmail-error-reporting-interactive
1025 ;; These mean "report errors to terminal" and "deliver interactively"
1027 (defvar sendmail-error-reporting-non-interactive
1028 ;; These mean "report errors by mail" and "deliver in background".
1031 (defun sendmail-send-it ()
1032 "Send the current mail buffer using the Sendmail package.
1033 This is a suitable value for `send-mail-function'. It sends using the
1034 external program defined by `sendmail-program'."
1035 (require 'mail-utils
)
1036 (let ((errbuf (if mail-interactive
1037 (generate-new-buffer " sendmail errors")
1039 (tembuf (generate-new-buffer " sendmail temp"))
1040 (multibyte enable-multibyte-characters
)
1041 (case-fold-search nil
)
1042 (selected-coding (select-message-coding-system))
1046 (mailbuf (current-buffer))
1047 (program (if (boundp 'sendmail-program
)
1049 "/usr/lib/sendmail"))
1050 ;; Examine these variables now, so that
1051 ;; local binding in the mail buffer will take effect.
1053 (and mail-specify-envelope-from
1054 (or (mail-envelope-from) user-mail-address
))))
1056 (with-current-buffer tembuf
1059 (set-buffer-multibyte nil
))
1060 (insert-buffer-substring mailbuf
)
1061 (goto-char (point-max))
1062 ;; require one newline at the end.
1063 (or (= (preceding-char) ?
\n)
1065 ;; Change header-delimiter to be what sendmail expects.
1066 (goto-char (mail-header-end))
1067 (delete-region (point) (progn (end-of-line) (point)))
1068 (setq delimline
(point-marker))
1069 (sendmail-sync-aliases)
1071 (expand-mail-aliases (point-min) delimline
))
1072 (goto-char (point-min))
1073 ;; Ignore any blank lines in the header
1074 (while (and (re-search-forward "\n\n\n*" delimline t
)
1075 (< (point) delimline
))
1076 (replace-match "\n"))
1077 (goto-char (point-min))
1078 ;; Look for Resent- headers. They require sending
1079 ;; the message specially.
1080 (let ((case-fold-search t
))
1081 (goto-char (point-min))
1082 (while (re-search-forward "^Resent-\\(to\\|cc\\|bcc\\):" delimline t
)
1083 ;; Put a list of such addresses in resend-to-addresses.
1084 (setq resend-to-addresses
1086 (narrow-to-region (point)
1089 (while (looking-at "^[ \t]")
1092 (append (mail-parse-comma-list)
1093 resend-to-addresses
)))
1094 ;; Delete Resent-BCC ourselves
1095 (if (save-excursion (beginning-of-line)
1096 (looking-at "resent-bcc"))
1097 (delete-region (save-excursion (beginning-of-line) (point))
1098 (save-excursion (end-of-line) (1+ (point))))))
1099 ;;; Apparently this causes a duplicate Sender.
1100 ;;; ;; If the From is different than current user, insert Sender.
1101 ;;; (goto-char (point-min))
1102 ;;; (and (re-search-forward "^From:" delimline t)
1104 ;;; (require 'mail-utils)
1105 ;;; (not (string-equal
1106 ;;; (mail-strip-quoted-names
1107 ;;; (save-restriction
1108 ;;; (narrow-to-region (point-min) delimline)
1109 ;;; (mail-fetch-field "From")))
1110 ;;; (user-login-name))))
1112 ;;; (forward-line 1)
1113 ;;; (insert "Sender: " (user-login-name) "\n")))
1114 ;; Don't send out a blank subject line
1115 (goto-char (point-min))
1116 (if (re-search-forward "^Subject:\\([ \t]*\n\\)+\\b" delimline t
)
1118 ;; This one matches a Subject just before the header delimiter.
1119 (if (and (re-search-forward "^Subject:\\([ \t]*\n\\)+" delimline t
)
1120 (= (match-end 0) delimline
))
1121 (replace-match "")))
1122 ;; Put the "From:" field in unless for some odd reason
1123 ;; they put one in themselves.
1124 (goto-char (point-min))
1125 (if (not (re-search-forward "^From:" delimline t
))
1126 (mail-insert-from-field))
1127 ;; Possibly add a MIME header for the current coding system
1128 (let (charset where-content-type
)
1129 (goto-char (point-min))
1130 (setq where-content-type
1131 (re-search-forward "^Content-type:" delimline t
))
1132 (goto-char (point-min))
1133 (and (eq mail-send-nonascii
'mime
)
1134 (not (re-search-forward "^MIME-version:" delimline t
))
1135 (progn (skip-chars-forward "\0-\177")
1136 (/= (point) (point-max)))
1139 (coding-system-get selected-coding
:mime-charset
))
1141 (goto-char delimline
)
1142 (insert "MIME-version: 1.0\n"
1143 "Content-type: text/plain; charset="
1144 (symbol-name charset
)
1145 "\nContent-Transfer-Encoding: 8bit\n")
1146 ;; The character set we will actually use
1147 ;; should override any specified in the message itself.
1148 (when where-content-type
1149 (goto-char where-content-type
)
1151 (delete-region (point)
1152 (progn (forward-line 1) (point)))))))
1153 ;; Insert an extra newline if we need it to work around
1154 ;; Sun's bug that swallows newlines.
1155 (goto-char (1+ delimline
))
1156 (if (eval mail-mailer-swallows-blank-line
)
1158 ;; Find and handle any FCC fields.
1159 (goto-char (point-min))
1160 (if (re-search-forward "^FCC:" delimline t
)
1162 (setq fcc-was-found t
)
1163 (mail-do-fcc delimline
)))
1164 (if mail-interactive
1165 (with-current-buffer errbuf
1167 (goto-char (point-min))
1168 (if (let ((case-fold-search t
))
1169 (or resend-to-addresses
1170 (re-search-forward "^To:\\|^cc:\\|^bcc:"
1172 (let* ((default-directory "/")
1173 (coding-system-for-write selected-coding
)
1175 (append (list (point-min) (point-max)
1177 nil errbuf nil
"-oi")
1179 (list "-f" envelope-from
))
1180 ;;; ;; Don't say "from root" if running under su.
1181 ;;; (and (equal (user-real-login-name) "root")
1182 ;;; (list "-f" (user-login-name)))
1183 (and mail-alias-file
1184 (list (concat "-oA" mail-alias-file
)))
1185 (if mail-interactive
1186 sendmail-error-reporting-interactive
1187 sendmail-error-reporting-non-interactive
)
1188 ;; Get the addresses from the message
1189 ;; unless this is a resend.
1190 ;; We must not do that for a resend
1191 ;; because we would find the original addresses.
1192 ;; For a resend, include the specific addresses.
1193 (or resend-to-addresses
1197 (list "-N" (mapconcat 'symbol-name
1201 (exit-value (apply 'call-process-region args
)))
1202 (cond ((or (null exit-value
) (eq 0 exit-value
)))
1203 ((numberp exit-value
)
1204 (error "Sending...failed with exit value %d" exit-value
))
1205 ((stringp exit-value
)
1206 (error "Sending...terminated by signal: %s" exit-value
))
1208 (error "SENDMAIL-SEND-IT -- fall through: %S" exit-value
))))
1210 (error "No recipients")))
1211 (if mail-interactive
1212 (with-current-buffer errbuf
1213 (goto-char (point-min))
1214 (while (re-search-forward "\n\n* *" nil t
)
1215 (replace-match "; "))
1216 (if (not (zerop (buffer-size)))
1217 (error "Sending...failed to %s"
1218 (buffer-substring (point-min) (point-max)))))))
1219 (kill-buffer tembuf
)
1220 (if (bufferp errbuf
)
1221 (kill-buffer errbuf
)))))
1223 (autoload 'rmail-output-to-rmail-buffer
"rmailout")
1225 (defun mail-do-fcc (header-end)
1226 "Find and act on any FCC: headers in the current message before HEADER-END.
1227 If a buffer is visiting the FCC file, append to it before
1228 offering to save it, if it was modified initially. If this is an
1229 Rmail buffer, update Rmail as needed. If there is no buffer,
1230 just append to the file, in Babyl format if necessary."
1231 (unless (markerp header-end
)
1232 (error "Value of `header-end' must be a marker"))
1234 (mailbuf (current-buffer))
1235 (time (current-time)))
1237 (goto-char (point-min))
1238 (let ((case-fold-search t
))
1239 (while (re-search-forward "^FCC:[ \t]*" header-end t
)
1240 (push (buffer-substring (point)
1243 (skip-chars-backward " \t")
1246 (delete-region (match-beginning 0)
1247 (progn (forward-line 1) (point)))))
1249 ;; This initial newline is not written out if we create a new
1250 ;; file (see below).
1251 (insert "\nFrom " (user-login-name) " " (current-time-string time
) "\n")
1252 ;; Insert the time zone before the year.
1255 (require 'mail-utils
)
1256 (insert (mail-rfc822-time-zone time
) " ")
1257 (goto-char (point-max))
1258 (insert-buffer-substring mailbuf
)
1259 ;; Make sure messages are separated.
1260 (goto-char (point-max))
1263 ;; ``Quote'' "^From " as ">From "
1264 ;; (note that this isn't really quoting, as there is no requirement
1265 ;; that "^[>]+From " be quoted in the same transparent way.)
1266 (let ((case-fold-search nil
))
1267 (while (search-forward "\nFrom " nil t
)
1270 (dolist (fcc fcc-list
)
1271 (let* ((buffer (find-buffer-visiting fcc
))
1272 (curbuf (current-buffer))
1275 (beg (point-min)) ; the initial blank line
1277 ;; After the ^From line.
1278 (beg2 (save-excursion (goto-char (point-min))
1279 (forward-line 2) (point))))
1281 ;; File is present in a buffer => append to that buffer.
1282 (with-current-buffer buffer
1283 (setq buffer-matches-file
1284 (and (not (buffer-modified-p))
1285 (verify-visited-file-modtime buffer
)))
1286 (let ((msg (bound-and-true-p rmail-current-message
))
1287 (buffer-read-only nil
))
1288 ;; If MSG is non-nil, buffer is in Rmail mode.
1290 (let ((buff (generate-new-buffer " *mail-do-fcc")))
1293 (with-current-buffer buff
1294 (insert-buffer-substring curbuf
(1+ beg
) end
))
1295 (rmail-output-to-rmail-buffer buff msg
))
1296 (kill-buffer buff
)))
1297 ;; Output file not in Rmail mode => just insert
1301 (goto-char (point-max))
1302 (insert-buffer-substring curbuf beg end
)))
1303 ;; Offer to save the buffer if it was modified
1304 ;; before we started.
1305 (unless buffer-matches-file
1306 (if (y-or-n-p (format "Save file %s? " fcc
))
1308 (setq dont-write-the-file t
)))))
1309 ;; Append to the file directly, unless we've already taken
1311 (unless dont-write-the-file
1312 (if (and (file-exists-p fcc
)
1313 (mail-file-babyl-p fcc
))
1314 ;; If the file is a Babyl file, convert the message to
1315 ;; Babyl format. Even though Rmail no longer uses
1316 ;; Babyl, this code can remain for the time being, on
1317 ;; the off-chance one FCCs to a Babyl file that has
1318 ;; not yet been converted to mbox.
1319 (let ((coding-system-for-write
1320 (or rmail-file-coding-system
'emacs-mule
)))
1322 (insert "\C-l\n0, unseen,,\n*** EOOH ***\nDate: "
1323 (mail-rfc822-date) "\n")
1324 (insert-buffer-substring curbuf beg2 end
)
1326 (write-region (point-min) (point-max) fcc t
)))
1327 ;; Ensure there is a blank line between messages, but
1328 ;; not at the very start of the file.
1329 (write-region (if (file-exists-p fcc
)
1332 (point-max) fcc t
)))
1333 (and buffer
(not dont-write-the-file
)
1334 (with-current-buffer buffer
1335 (set-visited-file-modtime)))))))))
1337 (defun mail-sent-via ()
1338 "Make a Sent-via header line from each To or CC header line."
1341 ;; put a marker at the end of the header
1342 (let ((end (copy-marker (mail-header-end)))
1343 (case-fold-search t
))
1344 (goto-char (point-min))
1345 ;; search for the To: lines and make Sent-via: lines from them
1346 ;; search for the next To: line
1347 (while (re-search-forward "^\\(to\\|cc\\):" end t
)
1348 ;; Grab this line plus all its continuations, sans the `to:'.
1350 (buffer-substring (point)
1352 (if (re-search-forward "^[^ \t\n]" end t
)
1356 ;; Insert a copy, with altered header field name.
1357 (insert-before-markers "Sent-via:" to-line
))))))
1360 "Move point to end of To field, creating it if necessary."
1363 (mail-position-on-field "To"))
1365 (defun mail-subject ()
1366 "Move point to end of Subject field, creating it if necessary."
1369 (mail-position-on-field "Subject"))
1372 "Move point to end of CC field, creating it if necessary."
1375 (or (mail-position-on-field "cc" t
)
1376 (progn (mail-position-on-field "to")
1377 (insert "\nCC: "))))
1380 "Move point to end of BCC field, creating it if necessary."
1383 (or (mail-position-on-field "bcc" t
)
1384 (progn (mail-position-on-field "to")
1385 (insert "\nBCC: "))))
1387 (defun mail-fcc (folder)
1388 "Add a new FCC field, with file name completion."
1389 (interactive "FFolder carbon copy: ")
1391 (or (mail-position-on-field "fcc" t
) ;Put new field after exiting FCC.
1392 (mail-position-on-field "to"))
1393 (insert "\nFCC: " folder
))
1395 (defun mail-reply-to ()
1396 "Move point to end of Reply-To field, creating it if necessary."
1399 (mail-position-on-field "Reply-To"))
1401 (defun mail-mail-reply-to ()
1402 "Move point to end of Mail-Reply-To field, creating it if necessary."
1405 (or (mail-position-on-field "mail-reply-to" t
)
1406 (progn (mail-position-on-field "to")
1407 (insert "\nMail-Reply-To: "))))
1409 (defun mail-mail-followup-to ()
1410 "Move point to end of Mail-Followup-To field, creating it if necessary."
1413 (or (mail-position-on-field "mail-followup-to" t
)
1414 (progn (mail-position-on-field "to")
1415 (insert "\nMail-Followup-To: "))))
1417 (defun mail-position-on-field (field &optional soft
)
1419 (case-fold-search t
))
1420 (setq end
(mail-header-end))
1421 (goto-char (point-min))
1422 (if (re-search-forward (concat "^" (regexp-quote field
) ":") end t
)
1424 (re-search-forward "^[^ \t]" nil
'move
)
1426 (skip-chars-backward "\n")
1429 (progn (goto-char end
)
1430 (insert field
": \n")
1431 (skip-chars-backward "\n")))
1435 "Move point to beginning of text field."
1438 (goto-char (mail-text-start)))
1440 (defun mail-signature (&optional atpoint
)
1441 "Sign letter with signature.
1442 If the variable `mail-signature' is a string, inserts it.
1443 If it is t or nil, inserts the contents of the file `mail-signature-file'.
1444 Otherwise, evals `mail-signature'.
1445 Prefix argument ATPOINT means insert at point rather than the end."
1447 ;; Test for an unreadable file here, before we delete trailing
1448 ;; whitespace, so that we don't modify the buffer needlessly.
1449 (if (and (memq mail-signature
'(t nil
))
1450 (not (file-readable-p mail-signature-file
)))
1451 (if (called-interactively-p 'interactive
)
1452 (message "The signature file `%s' could not be read"
1453 mail-signature-file
))
1456 (goto-char (point-max))
1457 ;; Delete trailing whitespace and blank lines.
1458 (skip-chars-backward " \t\n")
1460 (delete-region (point) (point-max)))
1461 (cond ((stringp mail-signature
)
1462 (insert mail-signature
))
1463 ((memq mail-signature
'(t nil
))
1464 (insert "\n\n-- \n")
1465 (insert-file-contents (expand-file-name mail-signature-file
)))
1467 ;; FIXME add condition-case error handling?
1468 (eval mail-signature
))))))
1470 (defun mail-fill-yanked-message (&optional justifyp
)
1471 "Fill the paragraphs of a message yanked into this one.
1472 Numeric argument means justify as well."
1475 (goto-char (mail-text-start))
1476 (fill-individual-paragraphs (point)
1479 mail-citation-prefix-regexp
)))
1481 (defun mail-indent-citation ()
1482 "Modify text just inserted from a message to be cited.
1483 The inserted text should be the region.
1484 When this function returns, the region is again around the modified text.
1486 Normally, indent each nonblank line `mail-indentation-spaces' spaces.
1487 However, if `mail-yank-prefix' is non-nil, insert that prefix on each line."
1488 (mail-yank-clear-headers (region-beginning) (region-end))
1489 (if (null mail-yank-prefix
)
1490 (indent-rigidly (region-beginning) (region-end)
1491 mail-indentation-spaces
)
1493 (let ((end (set-marker (make-marker) (region-end))))
1494 (goto-char (region-beginning))
1495 (while (< (point) end
)
1496 (insert mail-yank-prefix
)
1497 (forward-line 1))))))
1499 (defun mail-yank-original (arg)
1500 "Insert the message being replied to, if any (in Rmail).
1501 Puts point after the text and mark before.
1502 Normally, indents each nonblank line ARG spaces (default 3).
1503 However, if `mail-yank-prefix' is non-nil, insert that prefix on each line.
1505 Just \\[universal-argument] as argument means don't indent, insert no prefix,
1506 and don't delete any header fields."
1508 (if mail-reply-action
1509 (let ((start (point))
1510 (original mail-reply-action
)
1512 (and (consp original
) (eq (car original
) 'insert-buffer
)
1513 (setq original
(nth 1 original
)))
1514 (if (consp original
)
1516 ;; Call yank function, and set the mark if it doesn't.
1517 (apply (car original
) (cdr original
))
1518 (if (eq omark
(mark t
))
1519 (push-mark (point))))
1520 ;; If the original message is in another window in the same
1521 ;; frame, delete that window to save space.
1522 (delete-windows-on original t
)
1524 ;; We really want this to set mark.
1525 (insert-buffer original
)
1526 ;; If they yank the original text, the encoding of the
1527 ;; original message is a better default than
1528 ;; the default buffer-file-coding-system.
1529 (and (coding-system-equal
1530 (default-value 'buffer-file-coding-system
)
1531 buffer-file-coding-system
)
1532 (setq buffer-file-coding-system
1533 (coding-system-change-text-conversion
1534 buffer-file-coding-system
1536 (with-current-buffer original
1537 buffer-file-coding-system
))))))
1538 (set-text-properties (point) (mark t
) nil
))
1542 (let ((mail-indentation-spaces (if arg
(prefix-numeric-value arg
)
1543 mail-indentation-spaces
))
1544 ;; Avoid error in Transient Mark mode
1545 ;; on account of mark's being inactive.
1546 (mark-even-if-inactive t
))
1547 (cond (mail-citation-hook
1548 ;; Bind mail-citation-header to the inserted
1549 ;; message's header.
1550 (let ((mail-citation-header
1551 (buffer-substring-no-properties
1555 (narrow-to-region start
(point-max))
1559 (run-hooks 'mail-citation-hook
)))
1561 (run-hooks 'mail-yank-hooks
))
1563 (mail-indent-citation)))))
1564 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
1565 ;; It is cleaner to avoid activation, even though the command
1566 ;; loop would deactivate the mark because we inserted text.
1567 (goto-char (prog1 (mark t
)
1568 (set-marker (mark-marker) (point) (current-buffer))))
1569 (if (not (eolp)) (insert ?
\n)))))
1571 (defun mail-yank-clear-headers (start end
)
1574 (setq temp start start end end temp
)))
1575 (if mail-yank-ignored-headers
1578 (if (search-forward "\n\n" end t
)
1580 (narrow-to-region start
(point))
1582 (while (let ((case-fold-search t
))
1583 (re-search-forward mail-yank-ignored-headers nil t
))
1585 (delete-region (point)
1586 (progn (re-search-forward "\n[^ \t]")
1590 (defun mail-yank-region (arg)
1591 "Insert the selected region from the message being replied to.
1592 Puts point after the text and mark before.
1593 Normally, indents each nonblank line ARG spaces (default 3).
1594 However, if `mail-yank-prefix' is non-nil, insert that prefix on each line.
1596 Just \\[universal-argument] as argument means don't indent, insert no prefix,
1597 and don't delete any header fields."
1599 (and (consp mail-reply-action
)
1600 (eq (car mail-reply-action
) 'insert-buffer
)
1601 (with-current-buffer (nth 1 mail-reply-action
)
1603 (error "No mark set: %S" (current-buffer))))
1604 (let ((buffer (nth 1 mail-reply-action
))
1606 ;; Avoid error in Transient Mark mode
1607 ;; on account of mark's being inactive.
1608 (mark-even-if-inactive t
))
1609 ;; Insert the citation text.
1610 (insert (with-current-buffer buffer
1611 (buffer-substring-no-properties (point) (mark))))
1613 ;; Indent or otherwise annotate the citation text.
1616 (let ((mail-indentation-spaces (if arg
(prefix-numeric-value arg
)
1617 mail-indentation-spaces
)))
1618 (if mail-citation-hook
1619 ;; Bind mail-citation-header to the original message's header.
1620 (let ((mail-citation-header
1621 (with-current-buffer buffer
1622 (buffer-substring-no-properties
1625 (goto-char (point-min))
1628 (run-hooks 'mail-citation-hook
))
1630 (run-hooks 'mail-yank-hooks
)
1631 (mail-indent-citation))))))))
1633 (defun mail-split-line ()
1634 "Split current line, moving portion beyond point vertically down.
1635 If the current line has `mail-yank-prefix', insert it on the new line."
1637 (split-line mail-yank-prefix
))
1640 (defun mail-attach-file (&optional file
)
1641 "Insert a file at the end of the buffer, with separator lines around it."
1642 (interactive "fAttach file: ")
1644 (goto-char (point-max))
1645 (or (bolp) (newline))
1647 (let ((start (point))
1649 (insert (format "===File %s===" file
))
1650 (insert-char ?
= (max 0 (- 60 (current-column))))
1652 (setq middle
(point))
1653 (insert "============================================================\n")
1656 (insert-file-contents file
)
1657 (or (bolp) (newline))
1658 (goto-char start
))))
1660 ;; Put these commands last, to reduce chance of lossage from quitting
1661 ;; in middle of loading the file.
1663 ;;;###autoload (add-hook 'same-window-buffer-names (purecopy "*mail*"))
1666 (defun mail (&optional noerase to subject in-reply-to cc replybuffer actions
)
1667 "Edit a message to be sent. Prefix arg means resume editing (don't erase).
1668 When this function returns, the buffer `*mail*' is selected.
1669 The value is t if the message was newly initialized; otherwise, nil.
1671 Optionally, the signature file `mail-signature-file' can be inserted at the
1672 end; see the variable `mail-signature'.
1675 While editing message, type \\[mail-send-and-exit] to send the message and exit.
1677 Various special commands starting with C-c are available in sendmail mode
1678 to move to message header fields:
1681 If `mail-self-blind' is non-nil, a BCC to yourself is inserted
1682 when the message is initialized.
1684 If `mail-default-reply-to' is non-nil, it should be an address (a string);
1685 a Reply-to: field with that address is inserted.
1687 If `mail-archive-file-name' is non-nil, an FCC field with that file name
1690 The normal hook `mail-setup-hook' is run after the message is
1691 initialized. It can add more default fields to the message.
1693 The first argument, NOERASE, determines what to do when there is
1694 an existing modified `*mail*' buffer. If NOERASE is nil, the
1695 existing mail buffer is used, and the user is prompted whether to
1696 keep the old contents or to erase them. If NOERASE has the value
1697 `new', a new mail buffer will be created instead of using the old
1698 one. Any other non-nil value means to always select the old
1699 buffer without erasing the contents.
1701 The second through fifth arguments,
1702 TO, SUBJECT, IN-REPLY-TO and CC, specify if non-nil
1703 the initial contents of those header fields.
1704 These arguments should not have final newlines.
1705 The sixth argument REPLYBUFFER is a buffer which contains an
1706 original message being replied to, or else an action
1707 of the form (FUNCTION . ARGS) which says how to insert the original.
1708 Or it can be nil, if not replying to anything.
1709 The seventh argument ACTIONS is a list of actions to take
1710 if/when the message is sent. Each action looks like (FUNCTION . ARGS);
1711 when the message is sent, we apply FUNCTION to ARGS.
1712 This is how Rmail arranges to mark messages `answered'."
1714 ;;; This is commented out because I found it was confusing in practice.
1715 ;;; It is easy enough to rename *mail* by hand with rename-buffer
1716 ;;; if you want to have multiple mail buffers.
1717 ;;; And then you can control which messages to save. --rms.
1720 ;;; ;; If requested, look for a mail buffer that is modified and go to it.
1723 ;;; (while (and (setq buffer
1724 ;;; (get-buffer (if (= 1 index) "*mail*"
1725 ;;; (format "*mail*<%d>" index))))
1726 ;;; (not (buffer-modified-p buffer)))
1727 ;;; (setq index (1+ index)))
1728 ;;; (if buffer (switch-to-buffer buffer)
1729 ;;; ;; If none exists, start a new message.
1730 ;;; ;; This will never re-use an existing unmodified mail buffer
1731 ;;; ;; (since index is not 1 anymore). Perhaps it should.
1732 ;;; (setq noerase nil))))
1733 ;;; ;; Unless we found a modified message and are happy, start a new message.
1734 ;;; (if (not noerase)
1736 ;;; ;; Look for existing unmodified mail buffer.
1737 ;;; (while (and (setq buffer
1738 ;;; (get-buffer (if (= 1 index) "*mail*"
1739 ;;; (format "*mail*<%d>" index))))
1740 ;;; (buffer-modified-p buffer))
1741 ;;; (setq index (1+ index)))
1742 ;;; ;; If none, make a new one.
1744 ;;; (setq buffer (generate-new-buffer "*mail*")))
1745 ;;; ;; Go there and initialize it.
1746 ;;; (switch-to-buffer buffer)
1748 ;;; (setq default-directory (expand-file-name "~/"))
1749 ;;; (auto-save-mode auto-save-default)
1751 ;;; (mail-setup to subject in-reply-to cc replybuffer actions)
1752 ;;; (if (and buffer-auto-save-file-name
1753 ;;; (file-exists-p buffer-auto-save-file-name))
1754 ;;; (message "Auto save file for draft message exists; consider M-x mail-recover"))
1757 (if (eq noerase
'new
)
1758 (pop-to-buffer (generate-new-buffer "*mail*"))
1760 (not (get-buffer "*mail*"))
1762 (pop-to-buffer "*mail*"))
1764 ;; Avoid danger that the auto-save file can't be written.
1765 (let ((dir (expand-file-name
1766 (file-name-as-directory mail-default-directory
))))
1767 (if (file-exists-p dir
)
1768 (setq default-directory dir
)))
1769 ;; Only call auto-save-mode if necessary, to avoid changing auto-save file.
1770 (if (or (and auto-save-default
(not buffer-auto-save-file-name
))
1771 (and (not auto-save-default
) buffer-auto-save-file-name
))
1772 (auto-save-mode auto-save-default
))
1774 ;; Disconnect the buffer from its visited file
1775 ;; (in case the user has actually visited a file *mail*).
1776 ;;; (set-visited-file-name nil)
1778 (and (not (and noerase
1779 (not (eq noerase
'new
))))
1780 (if buffer-file-name
1781 (if (buffer-modified-p)
1782 (when (y-or-n-p "Buffer has unsaved changes; reinitialize it and discard them? ")
1783 (if (y-or-n-p "Disconnect buffer from visited file? ")
1784 (set-visited-file-name nil
))
1786 (when (y-or-n-p "Reinitialize buffer, and disconnect it from the visited file? ")
1787 (set-visited-file-name nil
)
1789 ;; A non-file-visiting buffer.
1790 (if (buffer-modified-p)
1791 (y-or-n-p "Unsent message being composed; erase it? ")
1793 (let ((inhibit-read-only t
))
1795 (mail-setup to subject in-reply-to cc replybuffer actions
)
1796 (setq initialized t
)))
1797 (if (and buffer-auto-save-file-name
1798 (file-exists-p buffer-auto-save-file-name
))
1799 (message "Auto save file for draft message exists; consider M-x mail-recover"))
1802 (declare-function dired-view-file
"dired" ())
1803 (declare-function dired-get-filename
"dired" (&optional localp no-error-if-not-filep
))
1805 (defun mail-recover-1 ()
1806 "Pop up a list of auto-saved draft messages so you can recover one of them."
1808 (let ((file-name (make-auto-save-file-name))
1809 (ls-lisp-support-shell-wildcards t
)
1810 non-random-len wildcard
)
1811 ;; Remove the random part from the auto-save-file-name, and
1812 ;; create a wildcard which matches possible candidates.
1813 ;; Note: this knows that make-auto-save-file-name appends
1814 ;; "#<RANDOM-STUFF>#" to the buffer name, where RANDOM-STUFF
1815 ;; is the result of (make-temp-name "").
1816 (setq non-random-len
1817 (- (length file-name
) (length (make-temp-name "")) 1))
1818 (setq wildcard
(concat (substring file-name
0 non-random-len
) "*"))
1819 (if (null (file-expand-wildcards wildcard
))
1820 (message "There are no auto-saved drafts to recover")
1821 ;; Bind dired-trivial-filenames to t because all auto-save file
1822 ;; names are normally ``trivial'', so Dired will set point after
1823 ;; all the files, at buffer bottom. We want it on the first
1825 (let ((dired-trivial-filenames t
))
1826 (dired-other-window wildcard
(concat dired-listing-switches
"t")))
1827 (rename-buffer "*Auto-saved Drafts*" t
)
1829 (goto-char (point-min))
1830 (or (looking-at " Move to the draft file you want to recover,")
1831 (let ((inhibit-read-only t
))
1832 ;; Each line starts with a space so that Font Lock mode
1833 ;; won't highlight the first character.
1835 Move to the draft file you want to recover, then type C-c C-c
1836 to recover text of message whose composition was interrupted.
1837 To browse text of a draft, type v on the draft file's line.
1839 You can also delete some of these files;
1840 type d on a line to mark that file for deletion.
1842 List of possible auto-save files for recovery:
1846 (let ((map (make-sparse-keymap)))
1847 (set-keymap-parent map
(current-local-map))
1849 (define-key (current-local-map) "v"
1852 (let ((coding-system-for-read 'utf-8-emacs-unix
))
1853 (dired-view-file))))
1854 (define-key (current-local-map) "\C-c\C-c"
1857 (let ((fname (dired-get-filename))
1858 ;; Auto-saved files are written in the internal
1859 ;; representation, so they should be read accordingly.
1860 (coding-system-for-read 'utf-8-emacs-unix
))
1861 (switch-to-buffer-other-window "*mail*")
1862 (let ((buffer-read-only nil
))
1864 (insert-file-contents fname nil
)
1865 ;; insert-file-contents will set buffer-file-coding-system
1866 ;; to utf-8-emacs, which is probably not what they want to
1867 ;; use for sending the message. But we don't know what
1868 ;; was its value before the buffer was killed or Emacs
1869 ;; crashed. We therefore reset buffer-file-coding-system
1870 ;; to the default value, so that either the default does
1871 ;; TRT, or the user will get prompted for the right
1872 ;; encoding when they send the message.
1873 (setq buffer-file-coding-system
1874 (default-value 'buffer-file-coding-system
)))))))))
1876 (declare-function dired-move-to-filename
"dired" (&optional raise-error eol
))
1877 (declare-function dired-get-filename
"dired" (&optional localp no-error-if-not-filep
))
1878 (declare-function dired-view-file
"dired" ())
1880 (defun mail-recover ()
1881 "Recover interrupted mail composition from auto-save files.
1883 If the mail buffer has a current valid auto-save file,
1884 the command recovers that file. Otherwise, it displays a
1885 buffer showing the existing auto-saved draft messages;
1886 you can move to one of them and type C-c C-c to recover that one."
1888 ;; In case they invoke us from some random buffer...
1889 (switch-to-buffer "*mail*")
1890 ;; If *mail* didn't exist, set its directory, so that auto-saved
1891 ;; drafts will be found.
1892 (let ((dir (expand-file-name
1893 (file-name-as-directory mail-default-directory
))))
1894 (if (file-exists-p dir
)
1895 (setq default-directory dir
)))
1896 (or (eq major-mode
'mail-mode
)
1898 (let ((file-name buffer-auto-save-file-name
))
1899 (cond ((and file-name
(file-exists-p file-name
))
1901 ;; This used to invoke `ls' via call-process, but
1902 ;; dired-noselect is more portable to systems where
1903 ;; `ls' is not a standard program (it will use
1904 ;; ls-lisp instead).
1905 (dired-noselect file-name
1906 (concat dired-listing-switches
"t"))))
1907 (save-selected-window
1908 (select-window (display-buffer dispbuf t
))
1909 (goto-char (point-min))
1911 (dired-move-to-filename)
1912 (setq dispbuf
(rename-buffer "*Directory*" t
)))
1913 (if (not (yes-or-no-p
1914 (format "Recover mail draft from auto save file %s? "
1916 (error "mail-recover cancelled")
1917 (let ((buffer-read-only nil
)
1918 (buffer-coding buffer-file-coding-system
)
1919 ;; Auto-save files are written in internal
1920 ;; representation of non-ASCII characters.
1921 (coding-system-for-read 'utf-8-emacs-unix
))
1923 (insert-file-contents file-name nil
)
1924 (setq buffer-file-coding-system buffer-coding
)))))
1925 (t (mail-recover-1)))))
1928 (defun mail-other-window (&optional noerase to subject in-reply-to cc replybuffer sendactions
)
1929 "Like `mail' command, but display mail buffer in another window."
1931 (let ((pop-up-windows t
)
1932 (special-display-buffer-names nil
)
1933 (special-display-regexps nil
)
1934 (same-window-buffer-names nil
)
1935 (same-window-regexps nil
))
1936 (pop-to-buffer "*mail*"))
1937 (mail noerase to subject in-reply-to cc replybuffer sendactions
))
1940 (defun mail-other-frame (&optional noerase to subject in-reply-to cc replybuffer sendactions
)
1941 "Like `mail' command, but display mail buffer in another frame."
1943 (let ((pop-up-frames t
)
1944 (special-display-buffer-names nil
)
1945 (special-display-regexps nil
)
1946 (same-window-buffer-names nil
)
1947 (same-window-regexps nil
))
1948 (pop-to-buffer "*mail*"))
1949 (mail noerase to subject in-reply-to cc replybuffer sendactions
))
1951 ;; Do not add anything but external entries on this page.
1955 ;; arch-tag: 48bc1025-d993-4d31-8d81-2a29491f0626
1956 ;;; sendmail.el ends here