1 ;;; sendmail.el --- mail sending commands for Emacs. -*- byte-compile-dynamic: t -*-
3 ;; Copyright (C) 1985-1986, 1992-1996, 1998, 2000-2011
4 ;; Free Software Foundation, Inc.
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;; This mode provides mail-sending facilities from within Emacs. It is
27 ;; documented in the Emacs user's manual.
34 (defgroup sendmail nil
35 "Mail sending commands for Emacs."
39 (defcustom mail-setup-with-from t
40 "Non-nil means insert `From:' field when setting up the message."
45 (defcustom sendmail-program
46 (or (executable-find "sendmail")
48 ((file-exists-p "/usr/sbin/sendmail") "/usr/sbin/sendmail")
49 ((file-exists-p "/usr/lib/sendmail") "/usr/lib/sendmail")
50 ((file-exists-p "/usr/ucblib/sendmail") "/usr/ucblib/sendmail")
52 "Program used to send messages."
53 :version
"24.1" ; add executable-find, remove fakemail
58 (defcustom mail-from-style
'default
59 "Specifies how \"From:\" fields look.
61 If `nil', they contain just the return address like:
63 If `parens', they look like:
64 king@grassland.com (Elvis Parsley)
65 If `angles', they look like:
66 Elvis Parsley <king@grassland.com>
68 Otherwise, most addresses look like `angles', but they look like
69 `parens' if `angles' would need quoting and `parens' would not."
70 ;; The value `system-default' is now deprecated.
71 :type
'(choice (const :tag
"simple" nil
)
79 (defcustom mail-specify-envelope-from nil
80 "If non-nil, specify the envelope-from address when sending mail.
81 The value used to specify it is whatever is found in
82 the variable `mail-envelope-from', with `user-mail-address' as fallback.
84 On most systems, specifying the envelope-from address is a
85 privileged operation. This variable affects sendmail and
86 smtpmail -- if you use feedmail to send mail, see instead the
87 variable `feedmail-deduce-envelope-from'."
92 (defcustom mail-envelope-from nil
93 "If non-nil, designate the envelope-from address when sending mail.
94 This only has an effect if `mail-specify-envelope-from' is non-nil.
95 The value should be either a string, or the symbol `header' (in
96 which case the contents of the \"From\" header of the message
97 being sent is used), or nil (in which case the value of
98 `user-mail-address' is used)."
100 :type
'(choice (string :tag
"From-name")
101 (const :tag
"Use From: header from message" header
)
102 (const :tag
"Use `user-mail-address'" nil
))
106 (defcustom mail-self-blind nil
107 "Non-nil means insert BCC to self in messages to be sent.
108 This is done when the message is initialized,
109 so you can remove or alter the BCC field to override the default."
114 (defcustom mail-interactive t
115 ;; We used to use a default of nil rather than t, but nowadays it is very
116 ;; common for sendmail to be misconfigured, so one cannot rely on the
117 ;; bounce message to be delivered anywhere, least of all to the
119 "Non-nil means when sending a message wait for and display errors.
120 Otherwise, let mailer send back a message to report errors."
122 :version
"23.1" ; changed from nil to t
125 (defcustom mail-yank-ignored-headers
127 (regexp-opt '("via" "mail-from" "origin" "status" "remailed"
128 "received" "message-id" "summary-line" "to" "subject"
129 "in-reply-to" "return-path" "mail-reply-to"
130 ;; Should really be rmail-attribute-header and
131 ;; rmail-keyword-header, but this file does not
132 ;; require rmail (at run time).
133 "x-rmail-attributes" "x-rmail-keywords"
134 "mail-followup-to") "\\(?:")
136 "Delete these headers from old message when it's inserted in a reply."
141 ;; Useful to set in site-init.el
143 (defcustom send-mail-function
'sendmail-query-once
144 "Function to call to send the current buffer as mail.
145 The headers should be delimited by a line which is
146 not a valid RFC822 header or continuation line,
147 that matches the variable `mail-header-separator'.
148 This is used by the default mail-sending commands. See also
149 `message-send-mail-function' for use with the Message package."
150 :type
'(radio (function-item sendmail-send-it
:tag
"Use Sendmail package")
151 (function-item sendmail-query-once
:tag
"Query the user")
152 (function-item smtpmail-send-it
:tag
"Use SMTPmail package")
153 (function-item feedmail-send-it
:tag
"Use Feedmail package")
154 (function-item mailclient-send-it
:tag
"Use Mailclient package")
159 (defvar sendmail-query-once-function
'query
160 "Either a function to send email, or the symbol `query'.")
163 (defun sendmail-query-once ()
164 "Send an email via `sendmail-query-once-function'.
165 If `sendmail-query-once-function' is `query', ask the user what
166 function to use, and then save that choice."
167 (when (equal sendmail-query-once-function
'query
)
168 (let* ((mail-buffer (current-buffer))
171 ((or (and window-system
(eq system-type
'darwin
))
172 (eq system-type
'windows-nt
))
174 ((and sendmail-program
175 (executable-find sendmail-program
))
178 (if (or (not default
)
179 ;; We have detected no OS-level mail senders, or we
180 ;; have already configured smtpmail, so we use the
181 ;; internal SMTP service.
182 (and (boundp 'smtpmail-smtp-server
)
183 smtpmail-smtp-server
))
188 (pop-to-buffer "*Mail Help*")
190 (insert "Sending mail from Emacs hasn't been set up yet.\n\n"
191 "Type `y' to configure outgoing SMTP, or `n' to use\n"
192 "the default mail sender on your system.\n\n"
193 "To change this again at a later date, customize the\n"
194 "`send-mail-function' variable.\n")
195 (goto-char (point-min))
196 (if (y-or-n-p "Configure outgoing SMTP in Emacs? ")
199 (kill-buffer (current-buffer))
200 (set-buffer mail-buffer
)))))
201 (customize-save-variable 'sendmail-query-once-function function
)))
202 (funcall sendmail-query-once-function
))
205 (defcustom mail-header-separator
(purecopy "--text follows this line--")
206 "Line used to separate headers from text in messages being composed."
210 ;; Set up mail-header-separator for use as a category text property.
211 (put 'mail-header-separator
'rear-nonsticky
'(category))
212 ;; This was a nice idea, for preventing accidental modification of
213 ;; the separator. But I found it also prevented or obstructed
214 ;; certain deliberate operations, such as copying the separator line
215 ;; up to the top to send myself a copy of an already sent outgoing message
216 ;; and other things. So I turned it off. --rms.
217 ;;(put 'mail-header-separator 'read-only t)
220 (defcustom mail-archive-file-name nil
221 "Name of file to write all outgoing messages in, or nil for none.
222 This is normally an mbox file, but for backwards compatibility may also
224 :type
'(choice file
(const nil
))
228 (defcustom mail-default-reply-to nil
229 "Address to insert as default Reply-to field of outgoing messages.
230 If nil, it will be initialized from the REPLYTO environment variable
231 when you first send mail."
232 :type
'(choice (const nil
) string
)
235 (defcustom mail-alias-file nil
236 "If non-nil, the name of a file to use instead of the sendmail default.
237 This file defines aliases to be expanded by the mailer; this is a different
238 feature from that of defining aliases in `.mailrc' to be expanded in Emacs.
239 This variable has no effect unless your system uses sendmail as its mailer.
240 The default file is defined in sendmail's configuration file, e.g.
242 :type
'(choice (const :tag
"Sendmail default" nil
) file
)
246 (defcustom mail-personal-alias-file
(purecopy "~/.mailrc")
247 "If non-nil, the name of the user's personal mail alias file.
248 This file typically should be in same format as the `.mailrc' file used by
249 the `Mail' or `mailx' program.
250 This file need not actually exist."
251 :type
'(choice (const nil
) file
)
255 (defcustom mail-setup-hook nil
256 "Normal hook, run each time a new outgoing message is initialized."
258 :options
'(fortune-to-signature spook mail-abbrevs-setup
)
262 (defvar mail-aliases t
263 "Alist of mail address aliases,
264 or t meaning should be initialized from your mail aliases file.
265 \(The file's name is normally `~/.mailrc', but `mail-personal-alias-file'
266 can specify a different file name.)
267 The alias definitions in the file have this form:
268 alias ALIAS MEANING")
270 (defvar mail-alias-modtime nil
271 "The modification time of your mail alias file when it was last examined.")
274 (defcustom mail-yank-prefix
"> "
275 "Prefix insert on lines of yanked message being replied to.
276 If this is nil, use indentation, as specified by `mail-indentation-spaces'."
277 :type
'(choice (const nil
) string
)
281 (defcustom mail-indentation-spaces
3
282 "Number of spaces to insert at the beginning of each cited line.
283 Used by `mail-yank-original' via `mail-indent-citation'."
287 ;; FIXME make it really obsolete.
288 (defvar mail-yank-hooks nil
289 "Obsolete hook for modifying a citation just inserted in the mail buffer.
290 Each hook function can find the citation between (point) and (mark t).
291 And each hook function should leave point and mark around the citation
294 This is a normal hook, misnamed for historical reasons.
295 It is semi-obsolete and mail agents should no longer use it.")
298 (defcustom mail-citation-hook nil
299 "Hook for modifying a citation just inserted in the mail buffer.
300 Each hook function can find the citation between (point) and (mark t),
301 and should leave point and mark around the citation text as modified.
302 The hook functions can find the header of the cited message
303 in the variable `mail-citation-header', whether or not this is included
304 in the cited portion of the message.
306 If this hook is entirely empty (nil), a default action is taken
307 instead of no action."
311 (defvar mail-citation-header nil
312 "While running `mail-citation-hook', this variable holds the message header.
313 This enables the hook functions to see the whole message header
314 regardless of what part of it (if any) is included in the cited text.")
317 (defcustom mail-citation-prefix-regexp
318 (purecopy "\\([ \t]*\\(\\w\\|[_.]\\)+>+\\|[ \t]*[]>|]\\)+")
319 "Regular expression to match a citation prefix plus whitespace.
320 It should match whatever sort of citation prefixes you want to handle,
321 with whitespace before and after; it should also match just whitespace.
322 The default value matches citations like `foo-bar>' plus whitespace."
327 (defvar mail-abbrevs-loaded nil
)
328 (defvar mail-mode-map
329 (let ((map (make-sparse-keymap)))
330 (define-key map
"\M-\t" 'completion-at-point
)
331 (define-key map
"\C-c?" 'describe-mode
)
332 (define-key map
"\C-c\C-f\C-t" 'mail-to
)
333 (define-key map
"\C-c\C-f\C-b" 'mail-bcc
)
334 (define-key map
"\C-c\C-f\C-f" 'mail-fcc
)
335 (define-key map
"\C-c\C-f\C-c" 'mail-cc
)
336 (define-key map
"\C-c\C-f\C-s" 'mail-subject
)
337 (define-key map
"\C-c\C-f\C-r" 'mail-reply-to
)
338 (define-key map
"\C-c\C-f\C-a" 'mail-mail-reply-to
) ; author
339 (define-key map
"\C-c\C-f\C-l" 'mail-mail-followup-to
) ; list
340 (define-key map
"\C-c\C-t" 'mail-text
)
341 (define-key map
"\C-c\C-y" 'mail-yank-original
)
342 (define-key map
"\C-c\C-r" 'mail-yank-region
)
343 (define-key map
[remap split-line
] 'mail-split-line
)
344 (define-key map
"\C-c\C-q" 'mail-fill-yanked-message
)
345 (define-key map
"\C-c\C-w" 'mail-signature
)
346 (define-key map
"\C-c\C-c" 'mail-send-and-exit
)
347 (define-key map
"\C-c\C-s" 'mail-send
)
348 (define-key map
"\C-c\C-i" 'mail-attach-file
)
349 ;; FIXME add this? "b" = bury buffer. It's in the menu-bar.
350 ;;; (define-key map "\C-c\C-b" 'mail-dont-send)
352 (define-key map
[menu-bar mail
]
353 (cons "Mail" (make-sparse-keymap "Mail")))
355 (define-key map
[menu-bar mail fill
]
356 '("Fill Citation" . mail-fill-yanked-message
))
358 (define-key map
[menu-bar mail yank
]
359 '(menu-item "Cite Original" mail-yank-original
:enable mail-reply-action
))
361 (define-key map
[menu-bar mail signature
]
362 '("Insert Signature" . mail-signature
))
364 (define-key map
[menu-bar mail mail-sep
]
367 (define-key map
[menu-bar mail cancel
]
368 '("Cancel" . mail-dont-send
))
370 (define-key map
[menu-bar mail send-stay
]
371 '("Send, Keep Editing" . mail-send
))
373 (define-key map
[menu-bar mail send
]
374 '("Send Message" . mail-send-and-exit
))
376 (define-key map
[menu-bar headers
]
377 (cons "Headers" (make-sparse-keymap "Move to Header")))
379 (define-key map
[menu-bar headers text
]
380 '("Text" . mail-text
))
382 (define-key map
[menu-bar headers expand-aliases
]
383 '("Expand Aliases" . expand-mail-aliases
))
385 (define-key map
[menu-bar headers mail-reply-to
]
386 '("Mail-Reply-To" . mail-mail-reply-to
))
388 (define-key map
[menu-bar headers mail-followup-to
]
389 '("Mail-Followup-To" . mail-mail-followup-to
))
391 (define-key map
[menu-bar headers reply-to
]
392 '("Reply-To" . mail-reply-to
))
394 (define-key map
[menu-bar headers bcc
]
397 (define-key map
[menu-bar headers fcc
]
400 (define-key map
[menu-bar headers cc
]
403 (define-key map
[menu-bar headers subject
]
404 '("Subject" . mail-subject
))
406 (define-key map
[menu-bar headers to
]
411 (autoload 'build-mail-aliases
"mailalias"
412 "Read mail aliases from personal aliases file and set `mail-aliases'.
413 By default, this is the file specified by `mail-personal-alias-file'." t
)
416 (defcustom mail-signature t
417 "Text inserted at end of mail buffer when a message is initialized.
418 If t, it means to insert the contents of the file `mail-signature-file'.
419 If a string, that string is inserted.
420 (To make a proper signature, the string should begin with \\n\\n-- \\n,
421 which is the standard way to delimit a signature in a message.)
422 Otherwise, it should be an expression; it is evaluated
423 and should insert whatever you want to insert."
424 :type
'(choice (const :tag
"None" nil
)
425 (const :tag
"Use `.signature' file" t
)
426 (string :tag
"String to insert")
427 (sexp :tag
"Expression to evaluate"))
429 (put 'mail-signature
'risky-local-variable t
)
432 (defcustom mail-signature-file
(purecopy "~/.signature")
433 "File containing the text inserted at end of mail buffer."
438 (defcustom mail-default-directory
(purecopy "~/")
439 "Value of `default-directory' for Mail mode buffers.
440 This directory is used for auto-save files of Mail mode buffers.
442 Note that Message mode does not use this variable; it auto-saves
443 in `message-auto-save-directory'."
444 :type
'(directory :tag
"Directory")
448 (defvar mail-reply-action nil
)
449 (defvar mail-send-actions nil
450 "A list of actions to be performed upon successful sending of a message.")
451 (defvar mail-return-action nil
)
454 (defcustom mail-default-headers nil
455 "A string containing header lines, to be inserted in outgoing messages.
456 It can contain newlines, and should end in one. It is inserted
457 before you edit the message, so you can edit or delete the lines."
458 :type
'(choice (const nil
) string
)
461 (defcustom mail-bury-selects-summary t
462 "If non-nil, try to show Rmail summary buffer after returning from mail.
463 The functions \\[mail-send-on-exit] or \\[mail-dont-send] select
464 the Rmail summary buffer before returning, if it exists and this variable
469 (defcustom mail-send-nonascii
'mime
470 "Specify whether to allow sending non-ASCII characters in mail.
471 If t, that means do allow it. nil means don't allow it.
472 `query' means ask the user each time.
473 `mime' means add an appropriate MIME header if none already present.
474 The default is `mime'.
475 Including non-ASCII characters in a mail message can be problematical
476 for the recipient, who may not know how to decode them properly."
477 :type
'(choice (const t
) (const nil
) (const query
) (const mime
))
480 (defcustom mail-use-dsn nil
481 "Ask MTA for notification of failed, delayed or successful delivery.
482 Note that only some MTAs (currently only recent versions of Sendmail)
483 support Delivery Status Notification."
485 :type
'(repeat (radio (const :tag
"Failure" failure
)
486 (const :tag
"Delay" delay
)
487 (const :tag
"Success" success
)))
490 ;; Note: could use /usr/ucb/mail instead of sendmail;
491 ;; options -t, and -v if not interactive.
492 (defvar mail-mailer-swallows-blank-line nil
493 "Set this non-nil if the system's mailer runs the header and body together.
494 The actual value should be an expression to evaluate that returns
495 non-nil if the problem will actually occur.
496 \(As far as we know, this is not an issue on any system still supported
499 (put 'mail-mailer-swallows-blank-line
'risky-local-variable t
) ; gets evalled
500 (make-obsolete-variable 'mail-mailer-swallows-blank-line
501 "no need to set this on any modern system."
504 (defvar mail-mode-syntax-table
505 ;; define-derived-mode will make it inherit from text-mode-syntax-table.
506 (let ((st (make-syntax-table)))
507 ;; FIXME this is probably very obsolete now ("percent hack").
508 ;; sending.texi used to say:
509 ;; Mail mode defines the character `%' as a word separator; this
510 ;; is helpful for using the word commands to edit mail addresses.
511 (modify-syntax-entry ?%
". " st
)
513 "Syntax table used while in `mail-mode'.")
515 (defvar mail-font-lock-keywords
517 (let* ((cite-chars "[>|}]")
518 (cite-prefix "[:alpha:]")
519 (cite-suffix (concat cite-prefix
"0-9_.@-`'\"")))
520 (list '("^\\(To\\|Newsgroups\\):" . font-lock-function-name-face
)
521 '("^\\(B?CC\\|Reply-to\\|Mail-\\(reply\\|followup\\)-to\\):" . font-lock-keyword-face
)
522 '("^\\(Subject:\\)[ \t]*\\(.+\\)?"
523 (1 font-lock-comment-face
)
524 ;; (2 font-lock-type-face nil t)
526 ;; Use EVAL to delay in case `mail-header-separator' gets changed.
528 (let ((separator (if (zerop (length mail-header-separator
))
530 (regexp-quote mail-header-separator
))))
531 (cons (concat "^" separator
"$") 'font-lock-warning-face
)))
532 ;; Use MATCH-ANCHORED to effectively anchor the regexp left side.
534 (,(concat "\\=[ \t]*"
535 "\\(\\(\\([" cite-prefix
"]+[" cite-suffix
"]*\\)?"
536 "\\(" cite-chars
"[ \t]*\\)\\)+\\)"
538 (beginning-of-line) (end-of-line)
539 (1 font-lock-comment-delimiter-face nil t
)
540 (5 font-lock-comment-face nil t
)))
541 '("^\\(X-[A-Za-z0-9-]+\\|In-reply-to\\):.*\\(\n[ \t]+.*\\)*$"
542 . font-lock-string-face
))))
543 "Additional expressions to highlight in Mail mode.")
546 (defun sendmail-sync-aliases ()
547 (when mail-personal-alias-file
548 (let ((modtime (nth 5 (file-attributes mail-personal-alias-file
))))
549 (or (equal mail-alias-modtime modtime
)
550 (setq mail-alias-modtime modtime
555 (define-mail-user-agent 'sendmail-user-agent
556 'sendmail-user-agent-compose
560 (defun sendmail-user-agent-compose (&optional to subject other-headers
561 continue switch-function yank-action
562 send-actions return-action
565 (let ((special-display-buffer-names nil
)
566 (special-display-regexps nil
)
567 (same-window-buffer-names nil
)
568 (same-window-regexps nil
))
569 (funcall switch-function
"*mail*")))
570 (let ((cc (cdr (assoc-string "cc" other-headers t
)))
571 (in-reply-to (cdr (assoc-string "in-reply-to" other-headers t
)))
572 (body (cdr (assoc-string "body" other-headers t
))))
573 (or (mail continue to subject in-reply-to cc yank-action
574 send-actions return-action
)
576 (error "Message aborted"))
580 (unless (member-ignore-case (car (car other-headers
))
581 '("in-reply-to" "cc" "body"))
582 (insert (car (car other-headers
)) ": "
583 (cdr (car other-headers
))
584 (if use-hard-newlines hard-newline
"\n")))
585 (setq other-headers
(cdr other-headers
)))
591 (defun mail-setup (to subject in-reply-to cc replybuffer
592 actions return-action
)
593 (or mail-default-reply-to
594 (setq mail-default-reply-to
(getenv "REPLYTO")))
595 (sendmail-sync-aliases)
596 (when (eq mail-aliases t
)
597 (setq mail-aliases nil
)
598 (and mail-personal-alias-file
599 (file-exists-p mail-personal-alias-file
)
600 (build-mail-aliases)))
601 ;; Don't leave this around from a previous message.
602 (kill-local-variable 'buffer-file-coding-system
)
603 ;; This doesn't work for enable-multibyte-characters.
604 ;; (kill-local-variable 'enable-multibyte-characters)
605 (set-buffer-multibyte (default-value 'enable-multibyte-characters
))
606 (if current-input-method
607 (inactivate-input-method))
609 ;; Local variables for Mail mode.
610 (setq mail-send-actions actions
)
611 (setq mail-reply-action replybuffer
)
612 (setq mail-return-action return-action
)
614 (goto-char (point-min))
615 (if mail-setup-with-from
616 (mail-insert-from-field))
620 ;; Here removed code to extract names from within <...>
621 ;; on the assumption that mail-strip-quoted-names
622 ;; has been called and has done so.
623 (let ((fill-prefix "\t")
624 (address-start (point)))
626 (fill-region-as-paragraph address-start
(point-max))
627 (goto-char (point-max))
632 (let ((fill-prefix "\t")
633 (address-start (progn (insert "CC: ") (point))))
635 (fill-region-as-paragraph address-start
(point-max))
636 (goto-char (point-max))
640 (let ((fill-prefix "\t")
642 (address-start (point)))
643 (insert "In-reply-to: " in-reply-to
"\n")
644 (fill-region-as-paragraph address-start
(point-max))
645 (goto-char (point-max))
648 (insert "Subject: " (or subject
"") "\n")
649 (if mail-default-headers
650 (insert mail-default-headers
))
651 (if mail-default-reply-to
652 (insert "Reply-to: " mail-default-reply-to
"\n"))
654 (insert "BCC: " user-mail-address
"\n"))
655 (if mail-archive-file-name
656 (insert "FCC: " mail-archive-file-name
"\n"))
657 (put-text-property (point)
659 (insert mail-header-separator
"\n")
661 'category
'mail-header-separator
)
662 ;; Insert the signature. But remember the beginning of the message.
663 (if to
(setq to
(point)))
664 (if mail-signature
(mail-signature t
))
665 (goto-char (point-max))
666 (or (bolp) (newline)))
667 (if to
(goto-char to
))
668 (or to subject in-reply-to
669 (set-buffer-modified-p nil
))
670 (run-hooks 'mail-setup-hook
))
672 (defcustom mail-mode-hook nil
673 "Hook run by Mail mode.
674 When composing a mail, this runs immediately after creating, or
675 switching to, the `*mail*' buffer. See also `mail-setup-hook'."
678 :options
'(footnote-mode))
680 (defvar mail-mode-abbrev-table text-mode-abbrev-table
)
682 (define-derived-mode mail-mode text-mode
"Mail"
683 "Major mode for editing mail to be sent.
684 Like Text Mode but with these additional commands:
686 \\[mail-send] mail-send (send the message)
687 \\[mail-send-and-exit] mail-send-and-exit (send the message and exit)
689 Here are commands that move to a header field (and create it if there isn't):
690 \\[mail-to] move to To: \\[mail-subject] move to Subj:
691 \\[mail-bcc] move to BCC: \\[mail-cc] move to CC:
692 \\[mail-fcc] move to FCC: \\[mail-reply-to] move to Reply-To:
693 \\[mail-mail-reply-to] move to Mail-Reply-To:
694 \\[mail-mail-followup-to] move to Mail-Followup-To:
695 \\[mail-text] move to message text.
696 \\[mail-signature] mail-signature (insert `mail-signature-file' file).
697 \\[mail-yank-original] mail-yank-original (insert current message, in Rmail).
698 \\[mail-fill-yanked-message] mail-fill-yanked-message (fill what was yanked).
699 Turning on Mail mode runs the normal hooks `text-mode-hook' and
700 `mail-mode-hook' (in that order)."
701 (make-local-variable 'mail-reply-action
)
702 (make-local-variable 'mail-send-actions
)
703 (make-local-variable 'mail-return-action
)
704 (setq buffer-offer-save t
)
705 (make-local-variable 'font-lock-defaults
)
706 (setq font-lock-defaults
'(mail-font-lock-keywords t t
))
707 (make-local-variable 'paragraph-separate
)
708 (make-local-variable 'normal-auto-fill-function
)
709 (setq normal-auto-fill-function
'mail-mode-auto-fill
)
710 (make-local-variable 'fill-paragraph-function
)
711 (setq fill-paragraph-function
'mail-mode-fill-paragraph
)
712 ;; Allow using comment commands to add/remove quoting (this only does
713 ;; anything if mail-yank-prefix is set to a non-nil value).
714 (set (make-local-variable 'comment-start
) mail-yank-prefix
)
716 (set (make-local-variable 'comment-start-skip
)
717 (concat "^" (regexp-quote mail-yank-prefix
) "[ \t]*")))
718 (make-local-variable 'adaptive-fill-regexp
)
719 (setq adaptive-fill-regexp
720 (concat "[ \t]*[-[:alnum:]]+>+[ \t]*\\|"
721 adaptive-fill-regexp
))
722 (make-local-variable 'adaptive-fill-first-line-regexp
)
723 (setq adaptive-fill-first-line-regexp
724 (concat "[ \t]*[-[:alnum:]]*>+[ \t]*\\|"
725 adaptive-fill-first-line-regexp
))
726 (add-hook 'completion-at-point-functions
#'mail-completion-at-point-function
728 ;; `-- ' precedes the signature. `-----' appears at the start of the
729 ;; lines that delimit forwarded messages.
730 ;; Lines containing just >= 3 dashes, perhaps after whitespace,
731 ;; are also sometimes used and should be separators.
732 (setq paragraph-separate
(concat (regexp-quote mail-header-separator
)
733 "$\\|\t*\\([-|#;>* ]\\|(?[0-9]+[.)]\\)+$"
734 "\\|[ \t]*[[:alnum:]]*>+[ \t]*$\\|[ \t]*$\\|"
739 (defun mail-header-end ()
740 "Return the buffer location of the end of headers, as a number."
747 (defun mail-text-start ()
748 "Return the buffer location of the start of text, as a number."
756 (defun mail-sendmail-delimit-header ()
757 "Set up whatever header delimiter convention sendmail will use.
758 Concretely: replace the first blank line in the header with the separator."
760 (insert mail-header-separator
)
763 (defun mail-sendmail-undelimit-header ()
764 "Remove header separator to put the message in correct form for sendmail.
765 Leave point at the start of the delimiter line."
767 (delete-region (point) (progn (end-of-line) (point))))
769 (defun mail-mode-auto-fill ()
770 "Carry out Auto Fill for Mail mode.
771 If within the headers, this makes the new lines into continuation lines."
772 (if (< (point) (mail-header-end))
773 (let ((old-line-start (line-beginning-position)))
777 (while (not (eq (point) old-line-start
))
778 ;; Use insert-before-markers in case we're inserting
779 ;; before the saved value of point (which is common).
780 (insert-before-markers " ")
785 (defun mail-mode-fill-paragraph (arg)
786 ;; Do something special only if within the headers.
787 (if (< (point) (mail-header-end))
788 (let (beg end fieldname
)
789 (when (prog1 (re-search-backward "^[-a-zA-Z]+:" nil
'yes
)
792 (downcase (buffer-substring beg
(1- (match-end 0))))))
794 ;; Find continuation lines and get rid of their continuation markers.
795 (while (looking-at "[ \t]")
796 (delete-horizontal-space)
798 (setq end
(point-marker))
800 ;; If this field contains addresses,
801 ;; make sure we can fill after each address.
802 (if (member fieldname
803 '("to" "cc" "bcc" "from" "reply-to"
804 "mail-reply-to" "mail-followup-to"
805 "resent-to" "resent-cc" "resent-bcc"
806 "resent-from" "resent-reply-to"))
807 (while (search-forward "," end t
)
808 (or (looking-at "[ \t]")
810 (fill-region-as-paragraph beg end arg
)
811 ;; Mark all lines except the first as continuations.
814 (while (< (point) end
)
817 (move-marker end nil
)
820 ;; User-level commands for sending.
822 (defun mail-send-and-exit (&optional arg
)
823 "Send message like `mail-send', then, if no errors, exit from mail buffer.
824 Prefix arg means don't delete this window."
829 (defun mail-dont-send (&optional arg
)
830 "Don't send the message you have been editing.
831 Prefix arg means don't delete this window."
835 (defun mail-bury (&optional arg
)
836 "Bury this mail buffer."
837 (let ((newbuf (other-buffer (current-buffer)))
838 (return-action mail-return-action
)
840 (bury-buffer (current-buffer))
841 ;; If there is an Rmail buffer, return to it nicely
842 ;; even if this message was not started by an Rmail command.
843 (unless return-action
844 (dolist (buffer (buffer-list))
845 (if (eq (buffer-local-value 'major-mode buffer
) 'rmail-mode
)
846 (setq return-action
`(rmail-mail-return ,newbuf
)))))
847 (if (and (null arg
) return-action
)
848 (apply (car return-action
) (cdr return-action
))
849 (switch-to-buffer newbuf
))))
851 (defcustom mail-send-hook nil
852 "Hook run just before sending a message."
854 :options
'(flyspell-mode-off)
858 (defcustom mail-mailing-lists nil
859 "List of mailing list addresses the user is subscribed to.
860 The variable is used to trigger insertion of the \"Mail-Followup-To\"
861 header when sending a message to a mailing list."
862 :type
'(repeat string
)
867 "Send the message in the current buffer.
868 If `mail-interactive' is non-nil, wait for success indication
869 or error messages, and inform user.
870 Otherwise any failure is reported in a message back to
871 the user from the mailer."
873 (if (if buffer-file-name
874 (y-or-n-p "Send buffer contents as mail message? ")
875 (or (buffer-modified-p)
876 (y-or-n-p "Message already sent; resend? ")))
877 (let ((inhibit-read-only t
)
879 (ml (when mail-mailing-lists
880 ;; The surrounding regexp assumes the use of
881 ;; `mail-strip-quoted-names' on addresses before matching
882 ;; Cannot deal with full RFC 822 freedom, but that is
883 ;; unlikely to be problematic.
884 (concat "\\(?:[[:space:];,]\\|\\`\\)"
885 (regexp-opt mail-mailing-lists t
)
886 "\\(?:[[:space:];,]\\|\\'\\)"))))
887 ;; If there are mailing lists defined
890 (let* ((to (mail-fetch-field "to" nil t
))
891 (cc (mail-fetch-field "cc" nil t
))
892 (new-header-values ; To: and Cc:
893 (mail-strip-quoted-names
894 (concat to
(when cc
(concat ", " cc
))))))
895 ;; If message goes to known mailing list ...
896 (when (string-match ml new-header-values
)
897 ;; Add Mail-Followup-To if none yet
898 (unless (mail-fetch-field "mail-followup-to")
899 (goto-char (mail-header-end))
900 (insert "Mail-Followup-To: "
907 (split-string new-header-values
909 (mapconcat 'identity l
", "))
911 ;; Add Mail-Reply-To if none yet
912 (unless (mail-fetch-field "mail-reply-to")
913 (goto-char (mail-header-end))
914 (insert "Mail-Reply-To: "
915 (or (mail-fetch-field "reply-to")
918 (unless (memq mail-send-nonascii
'(t mime
))
919 (goto-char (point-min))
920 (skip-chars-forward "\0-\177")
921 (or (= (point) (point-max))
922 (if (eq mail-send-nonascii
'query
)
923 (or (y-or-n-p "Message contains non-ASCII characters; send anyway? ")
925 (error "Message contains non-ASCII characters"))))
926 ;; Complain about any invalid line.
927 (goto-char (point-min))
928 (re-search-forward (regexp-quote mail-header-separator
) (point-max) t
)
929 (let ((header-end (or (match-beginning 0) (point-max))))
930 (goto-char (point-min))
931 (while (< (point) header-end
)
932 (unless (looking-at "[ \t]\\|.*:\\|$")
934 (error "Invalid header line (maybe a continuation line lacks initial whitespace)"))
937 (run-hooks 'mail-send-hook
)
938 (message "Sending...")
939 (funcall send-mail-function
)
940 ;; Now perform actions on successful sending.
941 (while mail-send-actions
943 (apply (car (car mail-send-actions
))
944 (cdr (car mail-send-actions
)))
946 (setq mail-send-actions
(cdr mail-send-actions
)))
947 (message "Sending...done")
948 ;; If buffer has no file, mark it as unmodified and delete auto-save.
949 (if (not buffer-file-name
)
951 (set-buffer-modified-p nil
)
952 (delete-auto-save-file-if-necessary t
))))))
954 (defun mail-envelope-from ()
955 "Return the envelope mail address to use when sending mail.
956 This function uses `mail-envelope-from'."
957 (if (eq mail-envelope-from
'header
)
958 (nth 1 (mail-extract-address-components
959 (mail-fetch-field "From")))
962 ;; This does the real work of sending a message via sendmail.
963 ;; It is called via the variable send-mail-function.
966 (defvar sendmail-coding-system nil
967 "*Coding system for encoding the outgoing mail.
968 This has higher priority than the default `buffer-file-coding-system'
969 and `default-sendmail-coding-system',
970 but lower priority than the local value of `buffer-file-coding-system'.
971 See also the function `select-message-coding-system'.")
974 (defvar default-sendmail-coding-system
'iso-latin-1
975 "Default coding system for encoding the outgoing mail.
976 This variable is used only when `sendmail-coding-system' is nil.
978 This variable is set/changed by the command `set-language-environment'.
979 User should not set this variable manually,
980 instead use `sendmail-coding-system' to get a constant encoding
981 of outgoing mails regardless of the current language environment.
982 See also the function `select-message-coding-system'.")
984 (defun mail-insert-from-field ()
985 "Insert the \"From:\" field of a mail header.
986 The style of the field is determined by the variable `mail-from-style'.
987 This function does not perform RFC2047 encoding."
988 (let* ((login user-mail-address
)
989 (fullname (user-full-name))
990 (quote-fullname nil
))
991 (if (string-match "[^\0-\177]" fullname
)
992 (setq quote-fullname t
))
993 (cond ((null mail-from-style
)
994 (insert "From: " login
"\n"))
995 ;; This is deprecated.
996 ((eq mail-from-style
'system-default
)
998 ((or (eq mail-from-style
'angles
)
999 (and (not (eq mail-from-style
'parens
))
1000 ;; Use angles if no quoting is needed, or if
1001 ;; parens would need quoting too.
1002 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname
))
1003 (let ((tmp (concat fullname nil
)))
1004 (while (string-match "([^()]*)" tmp
)
1005 (aset tmp
(match-beginning 0) ?-
)
1006 (aset tmp
(1- (match-end 0)) ?-
))
1007 (string-match "[\\()]" tmp
)))))
1008 (insert "From: " fullname
)
1009 (let ((fullname-start (+ (point-min) 6))
1010 (fullname-end (point-marker)))
1011 (goto-char fullname-start
)
1012 ;; Look for a character that cannot appear unquoted
1013 ;; according to RFC 822.
1014 (if (or (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]"
1018 ;; Quote fullname, escaping specials.
1019 (goto-char fullname-start
)
1021 (while (re-search-forward "[\"\\]"
1023 (replace-match "\\\\\\&" t
))
1025 (insert " <" login
">\n"))
1026 ;; 'parens or default
1028 (insert "From: " login
" (")
1029 (let ((fullname-start (point)))
1035 (let ((fullname-end (point-marker)))
1036 (goto-char fullname-start
)
1037 ;; RFC 822 says \ and nonmatching parentheses
1038 ;; must be escaped in comments.
1039 ;; Escape every instance of ()\ ...
1040 (while (re-search-forward "[()\\]" fullname-end
1)
1041 (replace-match "\\\\\\&" t
))
1042 ;; ... then undo escaping of matching parentheses,
1043 ;; including matching nested parentheses.
1044 (goto-char fullname-start
)
1045 (while (re-search-forward
1046 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
1048 (replace-match "\\1(\\3)" t
)
1049 (goto-char fullname-start
))))
1052 (defun mail-encode-header (beg end
)
1053 "Encode the mail header between BEG and END according to RFC2047.
1054 Return non-nil if and only if some part of the header is encoded."
1056 (narrow-to-region beg end
)
1057 (let* ((selected (select-message-coding-system))
1058 (mm-coding-system-priorities
1059 (if (and selected
(coding-system-get selected
:mime-charset
))
1060 (cons selected mm-coding-system-priorities
)
1061 mm-coding-system-priorities
))
1062 (tick (buffer-chars-modified-tick))
1063 (rfc2047-encode-encoded-words nil
))
1064 (rfc2047-encode-message-header)
1065 (= tick
(buffer-chars-modified-tick)))))
1067 ;; Normally you will not need to modify these options unless you are
1068 ;; using some non-genuine substitute for sendmail which does not
1069 ;; implement each and every option that the original supports.
1070 ;; E.g., ssmtp does not support "-odb", so, if your site uses it,
1071 ;; you will need to modify `sendmail-error-reporting-non-interactive'
1072 ;; in your site-init.el.
1073 (defvar sendmail-error-reporting-interactive
1074 ;; These mean "report errors to terminal" and "deliver interactively"
1076 (defvar sendmail-error-reporting-non-interactive
1077 ;; These mean "report errors by mail" and "deliver in background".
1080 (defun sendmail-send-it ()
1081 "Send the current mail buffer using the Sendmail package.
1082 This is a suitable value for `send-mail-function'. It sends using the
1083 external program defined by `sendmail-program'."
1084 (require 'mail-utils
)
1085 (let ((errbuf (if mail-interactive
1086 (generate-new-buffer " sendmail errors")
1088 (tembuf (generate-new-buffer " sendmail temp"))
1089 (multibyte enable-multibyte-characters
)
1090 (case-fold-search nil
)
1091 (selected-coding (select-message-coding-system))
1095 (mailbuf (current-buffer))
1096 ;; Examine these variables now, so that
1097 ;; local binding in the mail buffer will take effect.
1099 (and mail-specify-envelope-from
1100 (or (mail-envelope-from) user-mail-address
))))
1102 (with-current-buffer tembuf
1105 (set-buffer-multibyte nil
))
1106 (insert-buffer-substring mailbuf
)
1107 (set-buffer-file-coding-system selected-coding
)
1108 (goto-char (point-max))
1109 ;; require one newline at the end.
1110 (or (= (preceding-char) ?
\n)
1112 ;; Change header-delimiter to be what sendmail expects.
1113 (goto-char (mail-header-end))
1114 (delete-region (point) (progn (end-of-line) (point)))
1115 (setq delimline
(point-marker))
1116 (sendmail-sync-aliases)
1118 (expand-mail-aliases (point-min) delimline
))
1119 (goto-char (point-min))
1120 ;; Ignore any blank lines in the header
1121 (while (and (re-search-forward "\n\n\n*" delimline t
)
1122 (< (point) delimline
))
1123 (replace-match "\n"))
1124 (goto-char (point-min))
1125 ;; Look for Resent- headers. They require sending
1126 ;; the message specially.
1127 (let ((case-fold-search t
))
1128 (goto-char (point-min))
1129 (while (re-search-forward "^Resent-\\(to\\|cc\\|bcc\\):" delimline t
)
1130 ;; Put a list of such addresses in resend-to-addresses.
1131 (setq resend-to-addresses
1133 (narrow-to-region (point)
1136 (while (looking-at "^[ \t]")
1139 (append (mail-parse-comma-list)
1140 resend-to-addresses
)))
1141 ;; Delete Resent-BCC ourselves
1142 (if (save-excursion (beginning-of-line)
1143 (looking-at "resent-bcc"))
1144 (delete-region (line-beginning-position)
1145 (line-beginning-position 2))))
1146 ;; Apparently this causes a duplicate Sender.
1147 ;; ;; If the From is different than current user, insert Sender.
1148 ;; (goto-char (point-min))
1149 ;; (and (re-search-forward "^From:" delimline t)
1151 ;; (require 'mail-utils)
1152 ;; (not (string-equal
1153 ;; (mail-strip-quoted-names
1154 ;; (save-restriction
1155 ;; (narrow-to-region (point-min) delimline)
1156 ;; (mail-fetch-field "From")))
1157 ;; (user-login-name))))
1160 ;; (insert "Sender: " (user-login-name) "\n")))
1161 ;; Don't send out a blank subject line
1162 (goto-char (point-min))
1163 (if (re-search-forward "^Subject:\\([ \t]*\n\\)+\\b" delimline t
)
1165 ;; This one matches a Subject just before the header delimiter.
1166 (if (and (re-search-forward "^Subject:\\([ \t]*\n\\)+" delimline t
)
1167 (= (match-end 0) delimline
))
1168 (replace-match "")))
1169 ;; Put the "From:" field in unless for some odd reason
1170 ;; they put one in themselves.
1171 (goto-char (point-min))
1172 (if (not (re-search-forward "^From:" delimline t
))
1173 (mail-insert-from-field))
1174 ;; Possibly add a MIME header for the current coding system
1175 (let (charset where-content-type
)
1176 (goto-char (point-min))
1177 (setq where-content-type
1178 (re-search-forward "^Content-type:" delimline t
))
1179 (goto-char (point-min))
1180 (and (eq mail-send-nonascii
'mime
)
1181 (not (re-search-forward "^MIME-version:" delimline t
))
1182 (progn (skip-chars-forward "\0-\177")
1183 (/= (point) (point-max)))
1186 (coding-system-get selected-coding
:mime-charset
))
1188 (goto-char delimline
)
1189 (insert "MIME-version: 1.0\n"
1190 "Content-type: text/plain; charset="
1191 (symbol-name charset
)
1192 "\nContent-Transfer-Encoding: 8bit\n")
1193 ;; The character set we will actually use
1194 ;; should override any specified in the message itself.
1195 (when where-content-type
1196 (goto-char where-content-type
)
1197 (delete-region (point-at-bol)
1198 (progn (forward-line 1) (point)))))))
1199 ;; Insert an extra newline if we need it to work around
1200 ;; Sun's bug that swallows newlines.
1201 (goto-char (1+ delimline
))
1202 (if (eval mail-mailer-swallows-blank-line
)
1204 ;; Find and handle any FCC fields.
1205 (goto-char (point-min))
1206 (if (re-search-forward "^FCC:" delimline t
)
1208 (setq fcc-was-found t
)
1209 (mail-do-fcc delimline
)))
1210 (if mail-interactive
1211 (with-current-buffer errbuf
1213 ;; Encode the header according to RFC2047.
1214 (mail-encode-header (point-min) delimline
)
1215 (goto-char (point-min))
1216 (if (let ((case-fold-search t
))
1217 (or resend-to-addresses
1218 (re-search-forward "^To:\\|^cc:\\|^bcc:"
1220 (let* ((default-directory "/")
1221 (coding-system-for-write selected-coding
)
1223 (append (list (point-min) (point-max)
1225 nil errbuf nil
"-oi")
1227 (list "-f" envelope-from
))
1228 ;; ;; Don't say "from root" if running under su.
1229 ;; (and (equal (user-real-login-name) "root")
1230 ;; (list "-f" (user-login-name)))
1231 (and mail-alias-file
1232 (list (concat "-oA" mail-alias-file
)))
1233 (if mail-interactive
1234 sendmail-error-reporting-interactive
1235 sendmail-error-reporting-non-interactive
)
1236 ;; Get the addresses from the message
1237 ;; unless this is a resend.
1238 ;; We must not do that for a resend
1239 ;; because we would find the original addresses.
1240 ;; For a resend, include the specific addresses.
1241 (or resend-to-addresses
1245 (list "-N" (mapconcat 'symbol-name
1249 (exit-value (apply 'call-process-region args
)))
1250 (cond ((or (null exit-value
) (eq 0 exit-value
)))
1251 ((numberp exit-value
)
1252 (error "Sending...failed with exit value %d" exit-value
))
1253 ((stringp exit-value
)
1254 (error "Sending...terminated by signal: %s" exit-value
))
1256 (error "SENDMAIL-SEND-IT -- fall through: %S" exit-value
))))
1258 (error "No recipients")))
1259 (if mail-interactive
1260 (with-current-buffer errbuf
1261 (goto-char (point-min))
1262 (while (re-search-forward "\n\n* *" nil t
)
1263 (replace-match "; "))
1264 (if (not (zerop (buffer-size)))
1265 (error "Sending...failed to %s"
1266 (buffer-substring (point-min) (point-max)))))))
1267 (kill-buffer tembuf
)
1268 (if (bufferp errbuf
)
1269 (kill-buffer errbuf
)))))
1271 (autoload 'rmail-output-to-rmail-buffer
"rmailout")
1273 (defun mail-do-fcc (header-end)
1274 "Find and act on any FCC: headers in the current message before HEADER-END.
1275 If a buffer is visiting the FCC file, append to it before
1276 offering to save it, if it was modified initially. If this is an
1277 Rmail buffer, update Rmail as needed. If there is no buffer,
1278 just append to the file, in Babyl format if necessary."
1279 (unless (markerp header-end
)
1280 (error "Value of `header-end' must be a marker"))
1282 (mailbuf (current-buffer))
1283 (time (current-time)))
1285 (goto-char (point-min))
1286 (let ((case-fold-search t
))
1287 (while (re-search-forward "^FCC:[ \t]*" header-end t
)
1288 (push (buffer-substring (point)
1291 (skip-chars-backward " \t")
1294 (delete-region (match-beginning 0)
1295 (progn (forward-line 1) (point)))))
1297 ;; This initial newline is not written out if we create a new
1298 ;; file (see below).
1299 (insert "\nFrom " (user-login-name) " " (current-time-string time
) "\n")
1300 ;; Insert the time zone before the year.
1303 (require 'mail-utils
)
1304 (insert (mail-rfc822-time-zone time
) " ")
1305 (goto-char (point-max))
1306 (insert-buffer-substring mailbuf
)
1307 ;; Make sure messages are separated.
1308 (goto-char (point-max))
1311 ;; ``Quote'' "^From " as ">From "
1312 ;; (note that this isn't really quoting, as there is no requirement
1313 ;; that "^[>]+From " be quoted in the same transparent way.)
1314 (let ((case-fold-search nil
))
1315 (while (search-forward "\nFrom " nil t
)
1318 (dolist (fcc fcc-list
)
1319 (let* ((buffer (find-buffer-visiting fcc
))
1320 (curbuf (current-buffer))
1323 (beg (point-min)) ; the initial blank line
1325 ;; After the ^From line.
1326 (beg2 (save-excursion (goto-char (point-min))
1327 (forward-line 2) (point))))
1329 ;; File is present in a buffer => append to that buffer.
1330 (with-current-buffer buffer
1331 (setq buffer-matches-file
1332 (and (not (buffer-modified-p))
1333 (verify-visited-file-modtime buffer
)))
1334 (let ((msg (bound-and-true-p rmail-current-message
))
1335 (buffer-read-only nil
))
1336 ;; If MSG is non-nil, buffer is in Rmail mode.
1338 (let ((buff (generate-new-buffer " *mail-do-fcc")))
1341 (with-current-buffer buff
1342 (insert-buffer-substring curbuf
(1+ beg
) end
))
1343 (rmail-output-to-rmail-buffer buff msg
))
1344 (kill-buffer buff
)))
1345 ;; Output file not in Rmail mode => just insert
1349 (goto-char (point-max))
1350 (insert-buffer-substring curbuf beg end
)))
1351 ;; Offer to save the buffer if it was modified
1352 ;; before we started.
1353 (unless buffer-matches-file
1354 (if (y-or-n-p (format "Save file %s? " fcc
))
1356 (setq dont-write-the-file t
)))))
1357 ;; Append to the file directly, unless we've already taken
1359 (unless dont-write-the-file
1360 (if (and (file-exists-p fcc
)
1361 (mail-file-babyl-p fcc
))
1362 ;; If the file is a Babyl file, convert the message to
1363 ;; Babyl format. Even though Rmail no longer uses
1364 ;; Babyl, this code can remain for the time being, on
1365 ;; the off-chance one FCCs to a Babyl file that has
1366 ;; not yet been converted to mbox.
1367 (let ((coding-system-for-write
1368 (or rmail-file-coding-system
'emacs-mule
)))
1370 (insert "\C-l\n0, unseen,,\n*** EOOH ***\nDate: "
1371 (mail-rfc822-date) "\n")
1372 (insert-buffer-substring curbuf beg2 end
)
1374 (write-region (point-min) (point-max) fcc t
)))
1375 ;; Ensure there is a blank line between messages, but
1376 ;; not at the very start of the file.
1377 (write-region (if (file-exists-p fcc
)
1380 (point-max) fcc t
)))
1381 (and buffer
(not dont-write-the-file
)
1382 (with-current-buffer buffer
1383 (set-visited-file-modtime)))))))))
1385 (defun mail-sent-via ()
1386 "Make a Sent-via header line from each To or CC header line."
1389 ;; put a marker at the end of the header
1390 (let ((end (copy-marker (mail-header-end)))
1391 (case-fold-search t
))
1392 (goto-char (point-min))
1393 ;; search for the To: lines and make Sent-via: lines from them
1394 ;; search for the next To: line
1395 (while (re-search-forward "^\\(to\\|cc\\):" end t
)
1396 ;; Grab this line plus all its continuations, sans the `to:'.
1398 (buffer-substring (point)
1400 (if (re-search-forward "^[^ \t\n]" end t
)
1404 ;; Insert a copy, with altered header field name.
1405 (insert-before-markers "Sent-via:" to-line
))))))
1407 (make-obsolete 'mail-sent-via
"nobody can remember what it is for." "24.1")
1411 "Move point to end of To field, creating it if necessary."
1414 (mail-position-on-field "To"))
1416 (defun mail-subject ()
1417 "Move point to end of Subject field, creating it if necessary."
1420 (mail-position-on-field "Subject"))
1423 "Move point to end of CC field, creating it if necessary."
1426 (or (mail-position-on-field "cc" t
)
1427 (progn (mail-position-on-field "to")
1428 (insert "\nCC: "))))
1431 "Move point to end of BCC field, creating it if necessary."
1434 (or (mail-position-on-field "bcc" t
)
1435 (progn (mail-position-on-field "to")
1436 (insert "\nBCC: "))))
1438 (defun mail-fcc (folder)
1439 "Add a new FCC field, with file name completion."
1440 (interactive "FFolder carbon copy: ")
1442 (or (mail-position-on-field "fcc" t
) ;Put new field after exiting FCC.
1443 (mail-position-on-field "to"))
1444 (insert "\nFCC: " folder
))
1446 (defun mail-reply-to ()
1447 "Move point to end of Reply-To field, creating it if necessary."
1450 (mail-position-on-field "Reply-To"))
1452 (defun mail-mail-reply-to ()
1453 "Move point to end of Mail-Reply-To field, creating it if necessary."
1456 (or (mail-position-on-field "mail-reply-to" t
)
1457 (progn (mail-position-on-field "to")
1458 (insert "\nMail-Reply-To: "))))
1460 (defun mail-mail-followup-to ()
1461 "Move point to end of Mail-Followup-To field, creating it if necessary."
1464 (or (mail-position-on-field "mail-followup-to" t
)
1465 (progn (mail-position-on-field "to")
1466 (insert "\nMail-Followup-To: "))))
1468 (defun mail-position-on-field (field &optional soft
)
1470 (case-fold-search t
))
1471 (setq end
(mail-header-end))
1472 (goto-char (point-min))
1473 (if (re-search-forward (concat "^" (regexp-quote field
) ":") end t
)
1475 (re-search-forward "^[^ \t]" nil
'move
)
1477 (skip-chars-backward "\n")
1480 (progn (goto-char end
)
1481 (insert field
": \n")
1482 (skip-chars-backward "\n")))
1486 "Move point to beginning of text field."
1489 (goto-char (mail-text-start)))
1491 (defun mail-signature (&optional atpoint
)
1492 "Sign letter with signature.
1493 If the variable `mail-signature' is a string, inserts it.
1494 If it is t or nil, inserts the contents of the file `mail-signature-file'.
1495 Otherwise, evals `mail-signature'.
1496 Prefix argument ATPOINT means insert at point rather than the end."
1498 ;; Test for an unreadable file here, before we delete trailing
1499 ;; whitespace, so that we don't modify the buffer needlessly.
1500 (if (and (memq mail-signature
'(t nil
))
1501 (not (file-readable-p mail-signature-file
)))
1502 (if (called-interactively-p 'interactive
)
1503 (message "The signature file `%s' could not be read"
1504 mail-signature-file
))
1507 (goto-char (point-max))
1508 ;; Delete trailing whitespace and blank lines.
1509 (skip-chars-backward " \t\n")
1511 (delete-region (point) (point-max)))
1512 (cond ((stringp mail-signature
)
1513 (insert mail-signature
))
1514 ((memq mail-signature
'(t nil
))
1515 (insert "\n\n-- \n")
1516 (insert-file-contents (expand-file-name mail-signature-file
)))
1518 ;; FIXME add condition-case error handling?
1519 (eval mail-signature
))))))
1521 (defun mail-fill-yanked-message (&optional justifyp
)
1522 "Fill the paragraphs of a message yanked into this one.
1523 Numeric argument means justify as well."
1526 (goto-char (mail-text-start))
1527 (fill-individual-paragraphs (point)
1530 mail-citation-prefix-regexp
)))
1532 (defun mail-indent-citation ()
1533 "Modify text just inserted from a message to be cited.
1534 The inserted text should be the region.
1535 When this function returns, the region is again around the modified text.
1537 Normally, indent each nonblank line `mail-indentation-spaces' spaces.
1538 However, if `mail-yank-prefix' is non-nil, insert that prefix on each line."
1539 (mail-yank-clear-headers (region-beginning) (region-end))
1540 (if (null mail-yank-prefix
)
1541 (indent-rigidly (region-beginning) (region-end)
1542 mail-indentation-spaces
)
1544 (let ((end (set-marker (make-marker) (region-end))))
1545 (goto-char (region-beginning))
1546 (while (< (point) end
)
1547 (insert mail-yank-prefix
)
1548 (forward-line 1))))))
1550 (defun mail-yank-original (arg)
1551 "Insert the message being replied to, if any (in Rmail).
1552 Puts point after the text and mark before.
1553 Normally, indents each nonblank line ARG spaces (default 3).
1554 However, if `mail-yank-prefix' is non-nil, insert that prefix on each line.
1556 Just \\[universal-argument] as argument means don't indent, insert no prefix,
1557 and don't delete any header fields."
1559 (if mail-reply-action
1560 (let ((start (point))
1561 (original mail-reply-action
)
1563 (and (consp original
) (eq (car original
) 'insert-buffer
)
1564 (setq original
(nth 1 original
)))
1565 (if (consp original
)
1567 ;; Call yank function, and set the mark if it doesn't.
1568 (apply (car original
) (cdr original
))
1569 (if (eq omark
(mark t
))
1570 (push-mark (point))))
1571 ;; If the original message is in another window in the same
1572 ;; frame, delete that window to save space.
1573 (delete-windows-on original t
)
1575 ;; We really want this to set mark.
1576 (insert-buffer original
)
1577 ;; If they yank the original text, the encoding of the
1578 ;; original message is a better default than
1579 ;; the default buffer-file-coding-system.
1580 (and (coding-system-equal
1581 (default-value 'buffer-file-coding-system
)
1582 buffer-file-coding-system
)
1583 (setq buffer-file-coding-system
1584 (coding-system-change-text-conversion
1585 buffer-file-coding-system
1587 (with-current-buffer original
1588 buffer-file-coding-system
))))))
1589 (set-text-properties (point) (mark t
) nil
))
1593 (let ((mail-indentation-spaces (if arg
(prefix-numeric-value arg
)
1594 mail-indentation-spaces
))
1595 ;; Avoid error in Transient Mark mode
1596 ;; on account of mark's being inactive.
1597 (mark-even-if-inactive t
))
1598 (cond (mail-citation-hook
1599 ;; Bind mail-citation-header to the inserted
1600 ;; message's header.
1601 (let ((mail-citation-header
1602 (buffer-substring-no-properties
1606 (narrow-to-region start
(point-max))
1610 (run-hooks 'mail-citation-hook
)))
1612 (run-hooks 'mail-yank-hooks
))
1614 (mail-indent-citation)))))
1615 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
1616 ;; It is cleaner to avoid activation, even though the command
1617 ;; loop would deactivate the mark because we inserted text.
1618 (goto-char (prog1 (mark t
)
1619 (set-marker (mark-marker) (point) (current-buffer))))
1620 (if (not (eolp)) (insert ?
\n)))))
1622 (defun mail-yank-clear-headers (start end
)
1625 (setq temp start start end end temp
)))
1626 (if mail-yank-ignored-headers
1629 (if (search-forward "\n\n" end t
)
1631 (narrow-to-region start
(point))
1633 (while (let ((case-fold-search t
))
1634 (re-search-forward mail-yank-ignored-headers nil t
))
1636 (delete-region (point)
1637 (progn (re-search-forward "\n[^ \t]")
1641 (defun mail-yank-region (arg)
1642 "Insert the selected region from the message being replied to.
1643 Puts point after the text and mark before.
1644 Normally, indents each nonblank line ARG spaces (default 3).
1645 However, if `mail-yank-prefix' is non-nil, insert that prefix on each line.
1647 Just \\[universal-argument] as argument means don't indent, insert no prefix,
1648 and don't delete any header fields."
1650 (and (consp mail-reply-action
)
1651 (eq (car mail-reply-action
) 'insert-buffer
)
1652 (with-current-buffer (nth 1 mail-reply-action
)
1654 (error "No mark set: %S" (current-buffer))))
1655 (let ((buffer (nth 1 mail-reply-action
))
1657 ;; Avoid error in Transient Mark mode
1658 ;; on account of mark's being inactive.
1659 (mark-even-if-inactive t
))
1660 ;; Insert the citation text.
1661 (insert (with-current-buffer buffer
1662 (buffer-substring-no-properties (point) (mark))))
1664 ;; Indent or otherwise annotate the citation text.
1667 (let ((mail-indentation-spaces (if arg
(prefix-numeric-value arg
)
1668 mail-indentation-spaces
)))
1669 (if mail-citation-hook
1670 ;; Bind mail-citation-header to the original message's header.
1671 (let ((mail-citation-header
1672 (with-current-buffer buffer
1673 (buffer-substring-no-properties
1676 (goto-char (point-min))
1679 (run-hooks 'mail-citation-hook
))
1681 (run-hooks 'mail-yank-hooks
)
1682 (mail-indent-citation))))))))
1684 (defun mail-split-line ()
1685 "Split current line, moving portion beyond point vertically down.
1686 If the current line has `mail-yank-prefix', insert it on the new line."
1688 (split-line mail-yank-prefix
))
1691 (defun mail-attach-file (&optional file
)
1692 "Insert a file at the end of the buffer, with separator lines around it."
1693 (interactive "fAttach file: ")
1695 (goto-char (point-max))
1696 (or (bolp) (newline))
1698 (let ((start (point))
1700 (insert (format "===File %s===" file
))
1701 (insert-char ?
= (max 0 (- 60 (current-column))))
1703 (setq middle
(point))
1704 (insert "============================================================\n")
1707 (insert-file-contents file
)
1708 (or (bolp) (newline))
1709 (goto-char start
))))
1711 ;; Put these commands last, to reduce chance of lossage from quitting
1712 ;; in middle of loading the file.
1714 ;;;###autoload (add-hook 'same-window-buffer-names (purecopy "*mail*"))
1715 ;;;###autoload (add-hook 'same-window-buffer-names (purecopy "*unsent mail*"))
1718 (defun mail (&optional noerase to subject in-reply-to cc replybuffer
1719 actions return-action
)
1720 "Edit a message to be sent. Prefix arg means resume editing (don't erase).
1721 When this function returns, the buffer `*mail*' is selected.
1722 The value is t if the message was newly initialized; otherwise, nil.
1724 Optionally, the signature file `mail-signature-file' can be inserted at the
1725 end; see the variable `mail-signature'.
1728 While editing message, type \\[mail-send-and-exit] to send the message and exit.
1730 Various special commands starting with C-c are available in sendmail mode
1731 to move to message header fields:
1734 If `mail-self-blind' is non-nil, a BCC to yourself is inserted
1735 when the message is initialized.
1737 If `mail-default-reply-to' is non-nil, it should be an address (a string);
1738 a Reply-to: field with that address is inserted.
1740 If `mail-archive-file-name' is non-nil, an FCC field with that file name
1743 The normal hook `mail-setup-hook' is run after the message is
1744 initialized. It can add more default fields to the message.
1746 The first argument, NOERASE, determines what to do when there is
1747 an existing modified `*mail*' buffer. If NOERASE is nil, the
1748 existing mail buffer is used, and the user is prompted whether to
1749 keep the old contents or to erase them. If NOERASE has the value
1750 `new', a new mail buffer will be created instead of using the old
1751 one. Any other non-nil value means to always select the old
1752 buffer without erasing the contents.
1754 The second through fifth arguments,
1755 TO, SUBJECT, IN-REPLY-TO and CC, specify if non-nil
1756 the initial contents of those header fields.
1757 These arguments should not have final newlines.
1758 The sixth argument REPLYBUFFER is a buffer which contains an
1759 original message being replied to, or else an action
1760 of the form (FUNCTION . ARGS) which says how to insert the original.
1761 Or it can be nil, if not replying to anything.
1762 The seventh argument ACTIONS is a list of actions to take
1763 if/when the message is sent. Each action looks like (FUNCTION . ARGS);
1764 when the message is sent, we apply FUNCTION to ARGS.
1765 This is how Rmail arranges to mark messages `answered'."
1767 (if (eq noerase
'new
)
1768 (pop-to-buffer (generate-new-buffer "*mail*"))
1770 (not (get-buffer "*mail*"))
1772 (pop-to-buffer "*mail*"))
1774 ;; Avoid danger that the auto-save file can't be written.
1775 (let ((dir (expand-file-name
1776 (file-name-as-directory mail-default-directory
))))
1777 (if (file-exists-p dir
)
1778 (setq default-directory dir
)))
1779 ;; Only call auto-save-mode if necessary, to avoid changing auto-save file.
1780 (if (or (and auto-save-default
(not buffer-auto-save-file-name
))
1781 (and (not auto-save-default
) buffer-auto-save-file-name
))
1782 (auto-save-mode auto-save-default
))
1784 ;; Disconnect the buffer from its visited file
1785 ;; (in case the user has actually visited a file *mail*).
1786 ;; (set-visited-file-name nil)
1788 (and (not (and noerase
1789 (not (eq noerase
'new
))))
1790 (if buffer-file-name
1791 (if (buffer-modified-p)
1792 (when (y-or-n-p "Buffer has unsaved changes; reinitialize it and discard them? ")
1793 (if (y-or-n-p "Disconnect buffer from visited file? ")
1794 (set-visited-file-name nil
))
1796 (when (y-or-n-p "Reinitialize buffer, and disconnect it from the visited file? ")
1797 (set-visited-file-name nil
)
1799 ;; A non-file-visiting buffer.
1800 (if (buffer-modified-p)
1801 (y-or-n-p "Unsent message being composed; erase it? ")
1803 (let ((inhibit-read-only t
))
1805 (mail-setup to subject in-reply-to cc replybuffer actions
1807 (setq initialized t
)))
1808 (if (and buffer-auto-save-file-name
1809 (file-exists-p buffer-auto-save-file-name
))
1810 (message "Auto save file for draft message exists; consider M-x mail-recover"))
1813 (declare-function dired-view-file
"dired" ())
1814 (declare-function dired-get-filename
"dired" (&optional localp no-error-if-not-filep
))
1816 (defun mail-recover-1 ()
1817 "Pop up a list of auto-saved draft messages so you can recover one of them."
1819 (let ((file-name (make-auto-save-file-name))
1820 (ls-lisp-support-shell-wildcards t
)
1821 non-random-len wildcard
)
1822 ;; Remove the random part from the auto-save-file-name, and
1823 ;; create a wildcard which matches possible candidates.
1824 ;; Note: this knows that make-auto-save-file-name appends
1825 ;; "#<RANDOM-STUFF>#" to the buffer name, where RANDOM-STUFF
1826 ;; is the result of (make-temp-name "").
1827 (setq non-random-len
1828 (- (length file-name
) (length (make-temp-name "")) 1))
1829 (setq wildcard
(concat (substring file-name
0 non-random-len
) "*"))
1830 (if (null (file-expand-wildcards wildcard
))
1831 (message "There are no auto-saved drafts to recover")
1832 ;; Bind dired-trivial-filenames to t because all auto-save file
1833 ;; names are normally ``trivial'', so Dired will set point after
1834 ;; all the files, at buffer bottom. We want it on the first
1836 ;; Require dired so that dired-trivial-filenames does not get
1837 ;; unbound on exit from the let.
1839 (let ((dired-trivial-filenames t
))
1840 (dired-other-window wildcard
(concat dired-listing-switches
" -t")))
1841 (rename-buffer "*Auto-saved Drafts*" t
)
1843 (goto-char (point-min))
1844 (or (looking-at " Move to the draft file you want to recover,")
1845 (let ((inhibit-read-only t
))
1846 ;; Each line starts with a space so that Font Lock mode
1847 ;; won't highlight the first character.
1849 Move to the draft file you want to recover, then type C-c C-c
1850 to recover text of message whose composition was interrupted.
1851 To browse text of a draft, type v on the draft file's line.
1853 You can also delete some of these files;
1854 type d on a line to mark that file for deletion.
1856 List of possible auto-save files for recovery:
1860 (let ((map (make-sparse-keymap)))
1861 (set-keymap-parent map
(current-local-map))
1863 (define-key (current-local-map) "v"
1866 (let ((coding-system-for-read 'utf-8-emacs-unix
))
1867 (dired-view-file))))
1868 (define-key (current-local-map) "\C-c\C-c"
1871 (let ((fname (dired-get-filename))
1872 ;; Auto-saved files are written in the internal
1873 ;; representation, so they should be read accordingly.
1874 (coding-system-for-read 'utf-8-emacs-unix
))
1875 (switch-to-buffer-other-window "*mail*")
1876 (let ((buffer-read-only nil
))
1878 (insert-file-contents fname nil
)
1879 ;; insert-file-contents will set buffer-file-coding-system
1880 ;; to utf-8-emacs, which is probably not what they want to
1881 ;; use for sending the message. But we don't know what
1882 ;; was its value before the buffer was killed or Emacs
1883 ;; crashed. We therefore reset buffer-file-coding-system
1884 ;; to the default value, so that either the default does
1885 ;; TRT, or the user will get prompted for the right
1886 ;; encoding when they send the message.
1887 (setq buffer-file-coding-system
1888 (default-value 'buffer-file-coding-system
)))))))))
1890 (declare-function dired-move-to-filename
"dired" (&optional raise-error eol
))
1891 (declare-function dired-get-filename
"dired" (&optional localp no-error-if-not-filep
))
1892 (declare-function dired-view-file
"dired" ())
1894 (defun mail-recover ()
1895 "Recover interrupted mail composition from auto-save files.
1897 If the mail buffer has a current valid auto-save file,
1898 the command recovers that file. Otherwise, it displays a
1899 buffer showing the existing auto-saved draft messages;
1900 you can move to one of them and type C-c C-c to recover that one."
1902 ;; In case they invoke us from some random buffer...
1903 (switch-to-buffer "*mail*")
1904 ;; If *mail* didn't exist, set its directory, so that auto-saved
1905 ;; drafts will be found.
1906 (let ((dir (expand-file-name
1907 (file-name-as-directory mail-default-directory
))))
1908 (if (file-exists-p dir
)
1909 (setq default-directory dir
)))
1910 (or (eq major-mode
'mail-mode
)
1912 (let ((file-name buffer-auto-save-file-name
))
1913 (cond ((and file-name
(file-exists-p file-name
))
1915 ;; This used to invoke `ls' via call-process, but
1916 ;; dired-noselect is more portable to systems where
1917 ;; `ls' is not a standard program (it will use
1918 ;; ls-lisp instead).
1919 (dired-noselect file-name
1920 (concat dired-listing-switches
" -t"))))
1921 (save-selected-window
1922 (select-window (display-buffer dispbuf t
))
1923 (goto-char (point-min))
1925 (dired-move-to-filename)
1926 (setq dispbuf
(rename-buffer "*Directory*" t
)))
1927 (if (not (yes-or-no-p
1928 (format "Recover mail draft from auto save file %s? "
1930 (error "mail-recover cancelled")
1931 (let ((buffer-read-only nil
)
1932 (buffer-coding buffer-file-coding-system
)
1933 ;; Auto-save files are written in internal
1934 ;; representation of non-ASCII characters.
1935 (coding-system-for-read 'utf-8-emacs-unix
))
1937 (insert-file-contents file-name nil
)
1938 (setq buffer-file-coding-system buffer-coding
)))))
1939 (t (mail-recover-1)))))
1942 (defun mail-other-window (&optional noerase to subject in-reply-to cc replybuffer sendactions
)
1943 "Like `mail' command, but display mail buffer in another window."
1945 (let ((pop-up-windows t
)
1946 (special-display-buffer-names nil
)
1947 (special-display-regexps nil
)
1948 (same-window-buffer-names nil
)
1949 (same-window-regexps nil
))
1950 (pop-to-buffer "*mail*"))
1951 (mail noerase to subject in-reply-to cc replybuffer sendactions
))
1954 (defun mail-other-frame (&optional noerase to subject in-reply-to cc replybuffer sendactions
)
1955 "Like `mail' command, but display mail buffer in another frame."
1957 (let ((pop-up-frames t
)
1958 (special-display-buffer-names nil
)
1959 (special-display-regexps nil
)
1960 (same-window-buffer-names nil
)
1961 (same-window-regexps nil
))
1962 (pop-to-buffer "*mail*"))
1963 (mail noerase to subject in-reply-to cc replybuffer sendactions
))
1965 ;; Do not add anything but external entries on this page.
1969 ;;; sendmail.el ends here