1 ;;; sendmail.el --- mail sending commands for Emacs
3 ;; Copyright (C) 1985-1986, 1992-1996, 1998, 2000-2012
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
144 ;; Assume smtpmail is the preferred choice if it's already configured.
145 (if (and (boundp 'smtpmail-smtp-server
)
146 smtpmail-smtp-server
)
147 'smtpmail-send-it
'sendmail-query-once
)
148 "Function to call to send the current buffer as mail.
149 The headers should be delimited by a line which is
150 not a valid RFC822 header or continuation line,
151 that matches the variable `mail-header-separator'.
152 This is used by the default mail-sending commands. See also
153 `message-send-mail-function' for use with the Message package."
154 :type
'(radio (function-item sendmail-send-it
:tag
"Use Sendmail package")
155 (function-item sendmail-query-once
:tag
"Query the user")
156 (function-item smtpmail-send-it
:tag
"Use SMTPmail package")
157 (function-item feedmail-send-it
:tag
"Use Feedmail package")
158 (function-item mailclient-send-it
:tag
"Use Mailclient package")
164 (defcustom mail-header-separator
(purecopy "--text follows this line--")
165 "Line used to separate headers from text in messages being composed."
169 ;; Set up mail-header-separator for use as a category text property.
170 (put 'mail-header-separator
'rear-nonsticky
'(category))
171 ;; This was a nice idea, for preventing accidental modification of
172 ;; the separator. But I found it also prevented or obstructed
173 ;; certain deliberate operations, such as copying the separator line
174 ;; up to the top to send myself a copy of an already sent outgoing message
175 ;; and other things. So I turned it off. --rms.
176 ;;(put 'mail-header-separator 'read-only t)
179 (defcustom mail-archive-file-name nil
180 "Name of file to write all outgoing messages in, or nil for none.
181 This is normally an mbox file, but for backwards compatibility may also
183 :type
'(choice file
(const nil
))
187 (defcustom mail-default-reply-to nil
188 "Address to insert as default Reply-to field of outgoing messages.
189 If nil, it will be initialized from the REPLYTO environment variable
190 when you first send mail."
191 :type
'(choice (const nil
) string
)
194 (defcustom mail-alias-file nil
195 "If non-nil, the name of a file to use instead of the sendmail default.
196 This file defines aliases to be expanded by the mailer; this is a different
197 feature from that of defining aliases in `.mailrc' to be expanded in Emacs.
198 This variable has no effect unless your system uses sendmail as its mailer.
199 The default file is defined in sendmail's configuration file, e.g.
201 :type
'(choice (const :tag
"Sendmail default" nil
) file
)
205 (defcustom mail-personal-alias-file
(purecopy "~/.mailrc")
206 "If non-nil, the name of the user's personal mail alias file.
207 This file typically should be in same format as the `.mailrc' file used by
208 the `Mail' or `mailx' program.
209 This file need not actually exist."
210 :type
'(choice (const nil
) file
)
214 (defcustom mail-setup-hook nil
215 "Normal hook, run each time a new outgoing message is initialized."
217 :options
'(fortune-to-signature spook mail-abbrevs-setup
)
221 (defvar mail-aliases t
222 "Alist of mail address aliases,
223 or t meaning should be initialized from your mail aliases file.
224 \(The file's name is normally `~/.mailrc', but `mail-personal-alias-file'
225 can specify a different file name.)
226 The alias definitions in the file have this form:
227 alias ALIAS MEANING")
229 (defvar mail-alias-modtime nil
230 "The modification time of your mail alias file when it was last examined.")
233 (defcustom mail-yank-prefix
"> "
234 "Prefix insert on lines of yanked message being replied to.
235 If this is nil, use indentation, as specified by `mail-indentation-spaces'."
236 :type
'(choice (const nil
) string
)
240 (defcustom mail-indentation-spaces
3
241 "Number of spaces to insert at the beginning of each cited line.
242 Used by `mail-yank-original' via `mail-indent-citation'."
246 ;; FIXME make it really obsolete.
247 (defvar mail-yank-hooks nil
248 "Obsolete hook for modifying a citation just inserted in the mail buffer.
249 Each hook function can find the citation between (point) and (mark t).
250 And each hook function should leave point and mark around the citation
253 This is a normal hook, misnamed for historical reasons.
254 It is semi-obsolete and mail agents should no longer use it.")
257 (defcustom mail-citation-hook nil
258 "Hook for modifying a citation just inserted in the mail buffer.
259 Each hook function can find the citation between (point) and (mark t),
260 and should leave point and mark around the citation text as modified.
261 The hook functions can find the header of the cited message
262 in the variable `mail-citation-header', whether or not this is included
263 in the cited portion of the message.
265 If this hook is entirely empty (nil), a default action is taken
266 instead of no action."
270 (defvar mail-citation-header nil
271 "While running `mail-citation-hook', this variable holds the message header.
272 This enables the hook functions to see the whole message header
273 regardless of what part of it (if any) is included in the cited text.")
276 (defcustom mail-citation-prefix-regexp
277 (purecopy "\\([ \t]*\\(\\w\\|[_.]\\)+>+\\|[ \t]*[]>|]\\)+")
278 "Regular expression to match a citation prefix plus whitespace.
279 It should match whatever sort of citation prefixes you want to handle,
280 with whitespace before and after; it should also match just whitespace.
281 The default value matches citations like `foo-bar>' plus whitespace."
286 (defvar mail-abbrevs-loaded nil
)
287 (defvar mail-mode-map
288 (let ((map (make-sparse-keymap)))
289 (define-key map
"\M-\t" 'completion-at-point
)
290 (define-key map
"\C-c?" 'describe-mode
)
291 (define-key map
"\C-c\C-f\C-t" 'mail-to
)
292 (define-key map
"\C-c\C-f\C-b" 'mail-bcc
)
293 (define-key map
"\C-c\C-f\C-f" 'mail-fcc
)
294 (define-key map
"\C-c\C-f\C-c" 'mail-cc
)
295 (define-key map
"\C-c\C-f\C-s" 'mail-subject
)
296 (define-key map
"\C-c\C-f\C-r" 'mail-reply-to
)
297 (define-key map
"\C-c\C-f\C-a" 'mail-mail-reply-to
) ; author
298 (define-key map
"\C-c\C-f\C-l" 'mail-mail-followup-to
) ; list
299 (define-key map
"\C-c\C-t" 'mail-text
)
300 (define-key map
"\C-c\C-y" 'mail-yank-original
)
301 (define-key map
"\C-c\C-r" 'mail-yank-region
)
302 (define-key map
[remap split-line
] 'mail-split-line
)
303 (define-key map
"\C-c\C-q" 'mail-fill-yanked-message
)
304 (define-key map
"\C-c\C-w" 'mail-signature
)
305 (define-key map
"\C-c\C-c" 'mail-send-and-exit
)
306 (define-key map
"\C-c\C-s" 'mail-send
)
307 (define-key map
"\C-c\C-i" 'mail-attach-file
)
308 ;; FIXME add this? "b" = bury buffer. It's in the menu-bar.
309 ;;; (define-key map "\C-c\C-b" 'mail-dont-send)
311 (define-key map
[menu-bar mail
]
312 (cons "Mail" (make-sparse-keymap "Mail")))
314 (define-key map
[menu-bar mail attachment
]
315 '("Attach File" . mail-add-attachment
))
317 (define-key map
[menu-bar mail fill
]
318 '("Fill Citation" . mail-fill-yanked-message
))
320 (define-key map
[menu-bar mail yank
]
321 '(menu-item "Cite Original" mail-yank-original
:enable mail-reply-action
))
323 (define-key map
[menu-bar mail signature
]
324 '("Insert Signature" . mail-signature
))
326 (define-key map
[menu-bar mail mail-sep
]
329 (define-key map
[menu-bar mail cancel
]
330 '("Cancel" . mail-dont-send
))
332 (define-key map
[menu-bar mail send-stay
]
333 '("Send, Keep Editing" . mail-send
))
335 (define-key map
[menu-bar mail send
]
336 '("Send Message" . mail-send-and-exit
))
338 (define-key map
[menu-bar headers
]
339 (cons "Headers" (make-sparse-keymap "Move to Header")))
341 (define-key map
[menu-bar headers text
]
342 '("Text" . mail-text
))
344 (define-key map
[menu-bar headers expand-aliases
]
345 '("Expand Aliases" . expand-mail-aliases
))
347 (define-key map
[menu-bar headers mail-reply-to
]
348 '("Mail-Reply-To" . mail-mail-reply-to
))
350 (define-key map
[menu-bar headers mail-followup-to
]
351 '("Mail-Followup-To" . mail-mail-followup-to
))
353 (define-key map
[menu-bar headers reply-to
]
354 '("Reply-To" . mail-reply-to
))
356 (define-key map
[menu-bar headers bcc
]
359 (define-key map
[menu-bar headers fcc
]
362 (define-key map
[menu-bar headers cc
]
365 (define-key map
[menu-bar headers subject
]
366 '("Subject" . mail-subject
))
368 (define-key map
[menu-bar headers to
]
373 (autoload 'build-mail-aliases
"mailalias"
374 "Read mail aliases from personal aliases file and set `mail-aliases'.
375 By default, this is the file specified by `mail-personal-alias-file'." t
)
378 (defcustom mail-signature t
379 "Text inserted at end of mail buffer when a message is initialized.
380 If t, it means to insert the contents of the file `mail-signature-file'.
381 If a string, that string is inserted.
382 (To make a proper signature, the string should begin with \\n\\n-- \\n,
383 which is the standard way to delimit a signature in a message.)
384 Otherwise, it should be an expression; it is evaluated
385 and should insert whatever you want to insert."
386 :type
'(choice (const :tag
"None" nil
)
387 (const :tag
"Use `.signature' file" t
)
388 (string :tag
"String to insert")
389 (sexp :tag
"Expression to evaluate"))
391 (put 'mail-signature
'risky-local-variable t
)
394 (defcustom mail-signature-file
(purecopy "~/.signature")
395 "File containing the text inserted at end of mail buffer."
400 (defcustom mail-default-directory
(purecopy "~/")
401 "Value of `default-directory' for Mail mode buffers.
402 This directory is used for auto-save files of Mail mode buffers.
404 Note that Message mode does not use this variable; it auto-saves
405 in `message-auto-save-directory'."
406 :type
'(directory :tag
"Directory")
410 (defvar mail-reply-action nil
)
411 (defvar mail-send-actions nil
412 "A list of actions to be performed upon successful sending of a message.")
413 (defvar mail-return-action nil
)
416 (defcustom mail-default-headers nil
417 "A string containing header lines, to be inserted in outgoing messages.
418 It can contain newlines, and should end in one. It is inserted
419 before you edit the message, so you can edit or delete the lines."
420 :type
'(choice (const nil
) string
)
423 (defcustom mail-bury-selects-summary t
424 "If non-nil, try to show Rmail summary buffer after returning from mail.
425 The functions \\[mail-send-on-exit] or \\[mail-dont-send] select
426 the Rmail summary buffer before returning, if it exists and this variable
431 (defcustom mail-send-nonascii
'mime
432 "Specify whether to allow sending non-ASCII characters in mail.
433 If t, that means do allow it. nil means don't allow it.
434 `query' means ask the user each time.
435 `mime' means add an appropriate MIME header if none already present.
436 The default is `mime'.
437 Including non-ASCII characters in a mail message can be problematical
438 for the recipient, who may not know how to decode them properly."
439 :type
'(choice (const t
) (const nil
) (const query
) (const mime
))
442 (defcustom mail-use-dsn nil
443 "Ask MTA for notification of failed, delayed or successful delivery.
444 Note that only some MTAs (currently only recent versions of Sendmail)
445 support Delivery Status Notification."
447 :type
'(repeat (radio (const :tag
"Failure" failure
)
448 (const :tag
"Delay" delay
)
449 (const :tag
"Success" success
)))
452 ;; Note: could use /usr/ucb/mail instead of sendmail;
453 ;; options -t, and -v if not interactive.
454 (defvar mail-mailer-swallows-blank-line nil
455 "Set this non-nil if the system's mailer runs the header and body together.
456 The actual value should be an expression to evaluate that returns
457 non-nil if the problem will actually occur.
458 \(As far as we know, this is not an issue on any system still supported
461 (put 'mail-mailer-swallows-blank-line
'risky-local-variable t
) ; gets evalled
462 (make-obsolete-variable 'mail-mailer-swallows-blank-line
463 "no need to set this on any modern system."
466 (defvar mail-mode-syntax-table
467 ;; define-derived-mode will make it inherit from text-mode-syntax-table.
468 (let ((st (make-syntax-table)))
469 ;; FIXME this is probably very obsolete now ("percent hack").
470 ;; sending.texi used to say:
471 ;; Mail mode defines the character `%' as a word separator; this
472 ;; is helpful for using the word commands to edit mail addresses.
473 (modify-syntax-entry ?%
". " st
)
475 "Syntax table used while in `mail-mode'.")
477 (defvar mail-font-lock-keywords
479 (let* ((cite-chars "[>|}]")
480 (cite-prefix "[:alpha:]")
481 (cite-suffix (concat cite-prefix
"0-9_.@-`'\"")))
482 (list '("^\\(To\\|Newsgroups\\):" . font-lock-function-name-face
)
483 '("^\\(B?CC\\|Reply-to\\|Mail-\\(reply\\|followup\\)-to\\):" . font-lock-keyword-face
)
484 '("^\\(Subject:\\)[ \t]*\\(.+\\)?"
485 (1 font-lock-comment-face
)
486 ;; (2 font-lock-type-face nil t)
488 ;; Use EVAL to delay in case `mail-header-separator' gets changed.
490 (let ((separator (if (zerop (length mail-header-separator
))
492 (regexp-quote mail-header-separator
))))
493 (cons (concat "^" separator
"$") 'font-lock-warning-face
)))
494 ;; Use MATCH-ANCHORED to effectively anchor the regexp left side.
496 (,(concat "\\=[ \t]*"
497 "\\(\\(\\([" cite-prefix
"]+[" cite-suffix
"]*\\)?"
498 "\\(" cite-chars
"[ \t]*\\)\\)+\\)"
500 (beginning-of-line) (end-of-line)
501 (1 font-lock-comment-delimiter-face nil t
)
502 (5 font-lock-comment-face nil t
)))
503 '("^\\(X-[A-Za-z0-9-]+\\|In-reply-to\\):.*\\(\n[ \t]+.*\\)*$"
504 . font-lock-string-face
))))
505 "Additional expressions to highlight in Mail mode.")
509 (defun sendmail-query-once ()
510 "Query for `send-mail-function' and send mail with it.
511 This also saves the value of `send-mail-function' via Customize."
512 ;; If send-mail-function is already setup, we're incorrectly called
513 ;; a second time, probably because someone's using an old value
514 ;; of send-mail-function.
515 (when (eq send-mail-function
'sendmail-query-once
)
516 (let* ((options `(("mail client" . mailclient-send-it
)
517 ,@(when (and sendmail-program
518 (executable-find sendmail-program
))
519 '(("transport" . sendmail-send-it
)))
520 ("smtp" . smtpmail-send-it
)))
524 (rename-buffer "*Emacs Mail Setup Help*" t
)
526 Emacs is about to send an email message, but it has not been
527 configured for sending email. To tell Emacs how to send email:
530 (propertize "mail client" 'face
'bold
)
531 "' to start your default email client and
532 pass it the message text.\n\n")
533 (and sendmail-program
534 (executable-find sendmail-program
)
537 (propertize "transport" 'face
'bold
)
538 "' to invoke the system's mail transport agent
544 (propertize "smtp" 'face
'bold
)
545 "' to send mail directly to an \"outgoing mail\" server.
546 (Emacs may prompt you for SMTP settings).
548 Emacs will record your selection and will use it thereafter.
549 To change it later, customize the option `send-mail-function'.\n")
550 (goto-char (point-min))
551 (display-buffer (current-buffer))
552 (let ((completion-ignore-case t
))
553 (completing-read "Send mail via: "
554 options nil
'require-match
)))))
555 (customize-save-variable 'send-mail-function
556 (cdr (assoc-string choice options t
)))))
557 (funcall send-mail-function
))
559 (defun sendmail-sync-aliases ()
560 (when mail-personal-alias-file
561 (let ((modtime (nth 5 (file-attributes mail-personal-alias-file
))))
562 (or (equal mail-alias-modtime modtime
)
563 (setq mail-alias-modtime modtime
568 (define-mail-user-agent 'sendmail-user-agent
569 'sendmail-user-agent-compose
573 (defun sendmail-user-agent-compose (&optional to subject other-headers
574 continue switch-function yank-action
575 send-actions return-action
578 (funcall switch-function
"*mail*"))
579 (let ((cc (cdr (assoc-string "cc" other-headers t
)))
580 (in-reply-to (cdr (assoc-string "in-reply-to" other-headers t
)))
581 (body (cdr (assoc-string "body" other-headers t
))))
582 (or (mail continue to subject in-reply-to cc yank-action
583 send-actions return-action
)
585 (error "Message aborted"))
589 (unless (member-ignore-case (car (car other-headers
))
590 '("in-reply-to" "cc" "body"))
591 (insert (car (car other-headers
)) ": "
592 (cdr (car other-headers
))
593 (if use-hard-newlines hard-newline
"\n")))
594 (setq other-headers
(cdr other-headers
)))
600 (defun mail-setup (to subject in-reply-to cc replybuffer
601 actions return-action
)
602 (or mail-default-reply-to
603 (setq mail-default-reply-to
(getenv "REPLYTO")))
604 (sendmail-sync-aliases)
605 (when (eq mail-aliases t
)
606 (setq mail-aliases nil
)
607 (and mail-personal-alias-file
608 (file-exists-p mail-personal-alias-file
)
609 (build-mail-aliases)))
610 ;; Don't leave this around from a previous message.
611 (kill-local-variable 'buffer-file-coding-system
)
612 ;; This doesn't work for enable-multibyte-characters.
613 ;; (kill-local-variable 'enable-multibyte-characters)
614 (set-buffer-multibyte (default-value 'enable-multibyte-characters
))
615 (if current-input-method
616 (inactivate-input-method))
618 ;; Local variables for Mail mode.
619 (setq mail-send-actions actions
)
620 (setq mail-reply-action replybuffer
)
621 (setq mail-return-action return-action
)
623 (goto-char (point-min))
624 (if mail-setup-with-from
625 (mail-insert-from-field))
629 ;; Here removed code to extract names from within <...>
630 ;; on the assumption that mail-strip-quoted-names
631 ;; has been called and has done so.
632 (let ((fill-prefix "\t")
633 (address-start (point)))
635 (fill-region-as-paragraph address-start
(point-max))
636 (goto-char (point-max))
641 (let ((fill-prefix "\t")
642 (address-start (progn (insert "CC: ") (point))))
644 (fill-region-as-paragraph address-start
(point-max))
645 (goto-char (point-max))
649 (let ((fill-prefix "\t")
651 (address-start (point)))
652 (insert "In-reply-to: " in-reply-to
"\n")
653 (fill-region-as-paragraph address-start
(point-max))
654 (goto-char (point-max))
657 (insert "Subject: " (or subject
"") "\n")
658 (if mail-default-headers
659 (insert mail-default-headers
))
660 (if mail-default-reply-to
661 (insert "Reply-to: " mail-default-reply-to
"\n"))
663 (insert "BCC: " user-mail-address
"\n"))
664 (if mail-archive-file-name
665 (insert "FCC: " mail-archive-file-name
"\n"))
666 (put-text-property (point)
668 (insert mail-header-separator
"\n")
670 'category
'mail-header-separator
)
671 ;; Insert the signature. But remember the beginning of the message.
672 (if to
(setq to
(point)))
673 (if mail-signature
(mail-signature t
))
674 (goto-char (point-max))
675 (or (bolp) (newline)))
676 (if to
(goto-char to
))
677 (or to subject in-reply-to
678 (set-buffer-modified-p nil
))
679 (run-hooks 'mail-setup-hook
))
681 (defcustom mail-mode-hook nil
682 "Hook run by Mail mode.
683 When composing a mail, this runs immediately after creating, or
684 switching to, the `*mail*' buffer. See also `mail-setup-hook'."
687 :options
'(footnote-mode))
689 (defvar mail-mode-abbrev-table text-mode-abbrev-table
)
690 (defvar mail-encode-mml
)
692 (define-derived-mode mail-mode text-mode
"Mail"
693 "Major mode for editing mail to be sent.
694 Like Text Mode but with these additional commands:
696 \\[mail-send] mail-send (send the message)
697 \\[mail-send-and-exit] mail-send-and-exit (send the message and exit)
699 Here are commands that move to a header field (and create it if there isn't):
700 \\[mail-to] move to To: \\[mail-subject] move to Subj:
701 \\[mail-bcc] move to BCC: \\[mail-cc] move to CC:
702 \\[mail-fcc] move to FCC: \\[mail-reply-to] move to Reply-To:
703 \\[mail-mail-reply-to] move to Mail-Reply-To:
704 \\[mail-mail-followup-to] move to Mail-Followup-To:
705 \\[mail-text] move to message text.
706 \\[mail-signature] mail-signature (insert `mail-signature-file' file).
707 \\[mail-yank-original] mail-yank-original (insert current message, in Rmail).
708 \\[mail-fill-yanked-message] mail-fill-yanked-message (fill what was yanked).
709 \\[mail-insert-file] insert a text file into the message.
710 \\[mail-add-attachment] attach to the message a file as binary attachment.
711 Turning on Mail mode runs the normal hooks `text-mode-hook' and
712 `mail-mode-hook' (in that order)."
713 (make-local-variable 'mail-reply-action
)
714 (make-local-variable 'mail-send-actions
)
715 (make-local-variable 'mail-return-action
)
716 (make-local-variable 'mail-encode-mml
)
717 (setq mail-encode-mml nil
)
718 (setq buffer-offer-save t
)
719 (make-local-variable 'font-lock-defaults
)
720 (setq font-lock-defaults
'(mail-font-lock-keywords t t
))
721 (make-local-variable 'paragraph-separate
)
722 (make-local-variable 'normal-auto-fill-function
)
723 (setq normal-auto-fill-function
'mail-mode-auto-fill
)
724 (make-local-variable 'fill-paragraph-function
)
725 (setq fill-paragraph-function
'mail-mode-fill-paragraph
)
726 ;; Allow using comment commands to add/remove quoting (this only does
727 ;; anything if mail-yank-prefix is set to a non-nil value).
728 (set (make-local-variable 'comment-start
) mail-yank-prefix
)
730 (set (make-local-variable 'comment-start-skip
)
731 (concat "^" (regexp-quote mail-yank-prefix
) "[ \t]*")))
732 (make-local-variable 'adaptive-fill-regexp
)
733 (setq adaptive-fill-regexp
734 (concat "[ \t]*[-[:alnum:]]+>+[ \t]*\\|"
735 adaptive-fill-regexp
))
736 (make-local-variable 'adaptive-fill-first-line-regexp
)
737 (setq adaptive-fill-first-line-regexp
738 (concat "[ \t]*[-[:alnum:]]*>+[ \t]*\\|"
739 adaptive-fill-first-line-regexp
))
740 (add-hook 'completion-at-point-functions
#'mail-completion-at-point-function
742 ;; `-- ' precedes the signature. `-----' appears at the start of the
743 ;; lines that delimit forwarded messages.
744 ;; Lines containing just >= 3 dashes, perhaps after whitespace,
745 ;; are also sometimes used and should be separators.
746 (setq paragraph-separate
747 (concat (regexp-quote mail-header-separator
)
748 ;; This is based on adaptive-fill-regexp.
749 ;; Presumably the idea is to allow filling of cited paragraphs.
750 "$\\|\t*[-–!|#%;>*·•‣⁃◦ ]+$"
751 "\\|[ \t]*[-[:alnum:]]*>+[ \t]*$\\|[ \t]*$\\|"
756 (defun mail-header-end ()
757 "Return the buffer location of the end of headers, as a number."
764 (defun mail-text-start ()
765 "Return the buffer location of the start of text, as a number."
773 (defun mail-sendmail-delimit-header ()
774 "Set up whatever header delimiter convention sendmail will use.
775 Concretely: replace the first blank line in the header with the separator."
777 (insert mail-header-separator
)
780 (defun mail-sendmail-undelimit-header ()
781 "Remove header separator to put the message in correct form for sendmail.
782 Leave point at the start of the delimiter line."
784 (delete-region (point) (progn (end-of-line) (point))))
786 (defun mail-mode-auto-fill ()
787 "Carry out Auto Fill for Mail mode.
788 If within the headers, this makes the new lines into continuation lines."
789 (if (< (point) (mail-header-end))
790 (let ((old-line-start (line-beginning-position)))
794 (while (not (eq (point) old-line-start
))
795 ;; Use insert-before-markers in case we're inserting
796 ;; before the saved value of point (which is common).
797 (insert-before-markers " ")
802 (defun mail-mode-fill-paragraph (arg)
803 ;; Do something special only if within the headers.
804 (if (< (point) (mail-header-end))
805 (let (beg end fieldname
)
806 (when (prog1 (re-search-backward "^[-a-zA-Z]+:" nil
'yes
)
809 (downcase (buffer-substring beg
(1- (match-end 0))))))
811 ;; Find continuation lines and get rid of their continuation markers.
812 (while (looking-at "[ \t]")
813 (delete-horizontal-space)
815 (setq end
(point-marker))
817 ;; If this field contains addresses,
818 ;; make sure we can fill after each address.
819 (if (member fieldname
820 '("to" "cc" "bcc" "from" "reply-to"
821 "mail-reply-to" "mail-followup-to"
822 "resent-to" "resent-cc" "resent-bcc"
823 "resent-from" "resent-reply-to"))
824 (while (search-forward "," end t
)
825 (or (looking-at "[ \t]")
827 (fill-region-as-paragraph beg end arg
)
828 ;; Mark all lines except the first as continuations.
831 (while (< (point) end
)
834 (move-marker end nil
)
837 ;; User-level commands for sending.
839 (defun mail-send-and-exit (&optional arg
)
840 "Send message like `mail-send', then, if no errors, exit from mail buffer.
841 Prefix arg means don't delete this window."
846 (defun mail-dont-send (&optional arg
)
847 "Don't send the message you have been editing.
848 Prefix arg means don't delete this window."
852 (defun mail-bury (&optional arg
)
853 "Bury this mail buffer."
854 (let ((newbuf (other-buffer (current-buffer)))
855 (return-action mail-return-action
)
857 (bury-buffer (current-buffer))
858 ;; If there is an Rmail buffer, return to it nicely
859 ;; even if this message was not started by an Rmail command.
860 (unless return-action
861 (dolist (buffer (buffer-list))
862 (if (eq (buffer-local-value 'major-mode buffer
) 'rmail-mode
)
863 (setq return-action
`(rmail-mail-return ,newbuf
)))))
864 (if (and (null arg
) return-action
)
865 (apply (car return-action
) (cdr return-action
))
866 (switch-to-buffer newbuf
))))
868 (defcustom mail-send-hook nil
869 "Hook run just before sending a message."
871 :options
'(flyspell-mode-off)
875 (defcustom mail-mailing-lists nil
876 "List of mailing list addresses the user is subscribed to.
877 The variable is used to trigger insertion of the \"Mail-Followup-To\"
878 header when sending a message to a mailing list."
879 :type
'(repeat string
)
882 (declare-function mml-to-mime
"mml" ())
885 "Send the message in the current buffer.
886 If `mail-interactive' is non-nil, wait for success indication
887 or error messages, and inform user.
888 Otherwise any failure is reported in a message back to
889 the user from the mailer."
891 (if (if buffer-file-name
892 (y-or-n-p "Send buffer contents as mail message? ")
893 (or (buffer-modified-p)
894 (y-or-n-p "Message already sent; resend? ")))
895 (let ((inhibit-read-only t
)
897 (ml (when mail-mailing-lists
898 ;; The surrounding regexp assumes the use of
899 ;; `mail-strip-quoted-names' on addresses before matching
900 ;; Cannot deal with full RFC 822 freedom, but that is
901 ;; unlikely to be problematic.
902 (concat "\\(?:[[:space:];,]\\|\\`\\)"
903 (regexp-opt mail-mailing-lists t
)
904 "\\(?:[[:space:];,]\\|\\'\\)"))))
905 ;; If there are mailing lists defined
908 (let* ((to (mail-fetch-field "to" nil t
))
909 (cc (mail-fetch-field "cc" nil t
))
910 (new-header-values ; To: and Cc:
911 (mail-strip-quoted-names
912 (concat to
(when cc
(concat ", " cc
))))))
913 ;; If message goes to known mailing list ...
914 (when (string-match ml new-header-values
)
915 ;; Add Mail-Followup-To if none yet
916 (unless (mail-fetch-field "mail-followup-to")
917 (goto-char (mail-header-end))
918 (insert "Mail-Followup-To: "
925 (split-string new-header-values
927 (mapconcat 'identity l
", "))
929 ;; Add Mail-Reply-To if none yet
930 (unless (mail-fetch-field "mail-reply-to")
931 (goto-char (mail-header-end))
932 (insert "Mail-Reply-To: "
933 (or (mail-fetch-field "reply-to")
936 (unless (memq mail-send-nonascii
'(t mime
))
937 (goto-char (point-min))
938 (skip-chars-forward "\0-\177")
939 (or (= (point) (point-max))
940 (if (eq mail-send-nonascii
'query
)
941 (or (y-or-n-p "Message contains non-ASCII characters; send anyway? ")
943 (error "Message contains non-ASCII characters"))))
944 ;; Complain about any invalid line.
945 (goto-char (point-min))
946 (re-search-forward (regexp-quote mail-header-separator
) (point-max) t
)
947 (let ((header-end (or (match-beginning 0) (point-max))))
948 (goto-char (point-min))
949 (while (< (point) header-end
)
950 (unless (looking-at "[ \t]\\|.*:\\|$")
952 (error "Invalid header line (maybe a continuation line lacks initial whitespace)"))
955 (when mail-encode-mml
957 (setq mail-encode-mml nil
))
958 (run-hooks 'mail-send-hook
)
959 (message "Sending...")
960 (funcall send-mail-function
)
961 ;; Now perform actions on successful sending.
962 (while mail-send-actions
964 (apply (car (car mail-send-actions
))
965 (cdr (car mail-send-actions
)))
967 (setq mail-send-actions
(cdr mail-send-actions
)))
968 (message "Sending...done")
969 ;; If buffer has no file, mark it as unmodified and delete auto-save.
970 (if (not buffer-file-name
)
972 (set-buffer-modified-p nil
)
973 (delete-auto-save-file-if-necessary t
))))))
975 (defun mail-envelope-from ()
976 "Return the envelope mail address to use when sending mail.
977 This function uses `mail-envelope-from'."
978 (if (eq mail-envelope-from
'header
)
979 (nth 1 (mail-extract-address-components
980 (mail-fetch-field "From")))
983 ;; This does the real work of sending a message via sendmail.
984 ;; It is called via the variable send-mail-function.
987 (defvar sendmail-coding-system nil
988 "*Coding system for encoding the outgoing mail.
989 This has higher priority than the default `buffer-file-coding-system'
990 and `default-sendmail-coding-system',
991 but lower priority than the local value of `buffer-file-coding-system'.
992 See also the function `select-message-coding-system'.")
995 (defvar default-sendmail-coding-system
'iso-latin-1
996 "Default coding system for encoding the outgoing mail.
997 This variable is used only when `sendmail-coding-system' is nil.
999 This variable is set/changed by the command `set-language-environment'.
1000 User should not set this variable manually,
1001 instead use `sendmail-coding-system' to get a constant encoding
1002 of outgoing mails regardless of the current language environment.
1003 See also the function `select-message-coding-system'.")
1005 (defun mail-insert-from-field ()
1006 "Insert the \"From:\" field of a mail header.
1007 The style of the field is determined by the variable `mail-from-style'.
1008 This function does not perform RFC2047 encoding."
1009 (let* ((login user-mail-address
)
1010 (fullname (user-full-name))
1011 (quote-fullname nil
))
1012 (if (string-match "[^\0-\177]" fullname
)
1013 (setq quote-fullname t
))
1014 (cond ((null mail-from-style
)
1015 (insert "From: " login
"\n"))
1016 ;; This is deprecated.
1017 ((eq mail-from-style
'system-default
)
1019 ((or (eq mail-from-style
'angles
)
1020 (and (not (eq mail-from-style
'parens
))
1021 ;; Use angles if no quoting is needed, or if
1022 ;; parens would need quoting too.
1023 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname
))
1024 (let ((tmp (concat fullname nil
)))
1025 (while (string-match "([^()]*)" tmp
)
1026 (aset tmp
(match-beginning 0) ?-
)
1027 (aset tmp
(1- (match-end 0)) ?-
))
1028 (string-match "[\\()]" tmp
)))))
1029 (insert "From: " fullname
)
1030 (let ((fullname-start (+ (point-min) 6))
1031 (fullname-end (point-marker)))
1032 (goto-char fullname-start
)
1033 ;; Look for a character that cannot appear unquoted
1034 ;; according to RFC 822.
1035 (if (or (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]"
1039 ;; Quote fullname, escaping specials.
1040 (goto-char fullname-start
)
1042 (while (re-search-forward "[\"\\]"
1044 (replace-match "\\\\\\&" t
))
1046 (insert " <" login
">\n"))
1047 ;; 'parens or default
1049 (insert "From: " login
" (")
1050 (let ((fullname-start (point)))
1056 (let ((fullname-end (point-marker)))
1057 (goto-char fullname-start
)
1058 ;; RFC 822 says \ and nonmatching parentheses
1059 ;; must be escaped in comments.
1060 ;; Escape every instance of ()\ ...
1061 (while (re-search-forward "[()\\]" fullname-end
1)
1062 (replace-match "\\\\\\&" t
))
1063 ;; ... then undo escaping of matching parentheses,
1064 ;; including matching nested parentheses.
1065 (goto-char fullname-start
)
1066 (while (re-search-forward
1067 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
1069 (replace-match "\\1(\\3)" t
)
1070 (goto-char fullname-start
))))
1073 (defun mail-encode-header (beg end
)
1074 "Encode the mail header between BEG and END according to RFC2047.
1075 Return non-nil if and only if some part of the header is encoded."
1077 (narrow-to-region beg end
)
1078 (let* ((selected (select-message-coding-system))
1079 (mm-coding-system-priorities
1080 (if (and selected
(coding-system-get selected
:mime-charset
))
1081 (cons selected mm-coding-system-priorities
)
1082 mm-coding-system-priorities
))
1083 (tick (buffer-chars-modified-tick))
1084 (rfc2047-encode-encoded-words nil
))
1085 (rfc2047-encode-message-header)
1086 (= tick
(buffer-chars-modified-tick)))))
1088 ;; Normally you will not need to modify these options unless you are
1089 ;; using some non-genuine substitute for sendmail which does not
1090 ;; implement each and every option that the original supports.
1091 ;; E.g., ssmtp does not support "-odb", so, if your site uses it,
1092 ;; you will need to modify `sendmail-error-reporting-non-interactive'
1093 ;; in your site-init.el.
1094 (defvar sendmail-error-reporting-interactive
1095 ;; These mean "report errors to terminal" and "deliver interactively"
1097 (defvar sendmail-error-reporting-non-interactive
1098 ;; These mean "report errors by mail" and "deliver in background".
1101 (defun sendmail-send-it ()
1102 "Send the current mail buffer using the Sendmail package.
1103 This is a suitable value for `send-mail-function'. It sends using the
1104 external program defined by `sendmail-program'."
1105 (require 'mail-utils
)
1106 (let ((errbuf (if mail-interactive
1107 (generate-new-buffer " sendmail errors")
1109 (tembuf (generate-new-buffer " sendmail temp"))
1110 (multibyte enable-multibyte-characters
)
1111 (case-fold-search nil
)
1112 (selected-coding (select-message-coding-system))
1116 (mailbuf (current-buffer))
1117 ;; Examine these variables now, so that
1118 ;; local binding in the mail buffer will take effect.
1120 (and mail-specify-envelope-from
1121 (or (mail-envelope-from) user-mail-address
))))
1123 (with-current-buffer tembuf
1126 (set-buffer-multibyte nil
))
1127 (insert-buffer-substring mailbuf
)
1128 (set-buffer-file-coding-system selected-coding
)
1129 (goto-char (point-max))
1130 ;; require one newline at the end.
1131 (or (= (preceding-char) ?
\n)
1133 ;; Change header-delimiter to be what sendmail expects.
1134 (goto-char (mail-header-end))
1135 (delete-region (point) (progn (end-of-line) (point)))
1136 (setq delimline
(point-marker))
1137 (sendmail-sync-aliases)
1139 (expand-mail-aliases (point-min) delimline
))
1140 (goto-char (point-min))
1141 ;; Ignore any blank lines in the header
1142 (while (and (re-search-forward "\n\n\n*" delimline t
)
1143 (< (point) delimline
))
1144 (replace-match "\n"))
1145 (goto-char (point-min))
1146 ;; Look for Resent- headers. They require sending
1147 ;; the message specially.
1148 (let ((case-fold-search t
))
1149 (goto-char (point-min))
1150 (while (re-search-forward "^Resent-\\(to\\|cc\\|bcc\\):" delimline t
)
1151 ;; Put a list of such addresses in resend-to-addresses.
1152 (setq resend-to-addresses
1154 (narrow-to-region (point)
1157 (while (looking-at "^[ \t]")
1160 (append (mail-parse-comma-list)
1161 resend-to-addresses
)))
1162 ;; Delete Resent-BCC ourselves
1163 (if (save-excursion (beginning-of-line)
1164 (looking-at "resent-bcc"))
1165 (delete-region (line-beginning-position)
1166 (line-beginning-position 2))))
1167 ;; Apparently this causes a duplicate Sender.
1168 ;; ;; If the From is different than current user, insert Sender.
1169 ;; (goto-char (point-min))
1170 ;; (and (re-search-forward "^From:" delimline t)
1172 ;; (require 'mail-utils)
1173 ;; (not (string-equal
1174 ;; (mail-strip-quoted-names
1175 ;; (save-restriction
1176 ;; (narrow-to-region (point-min) delimline)
1177 ;; (mail-fetch-field "From")))
1178 ;; (user-login-name))))
1181 ;; (insert "Sender: " (user-login-name) "\n")))
1182 ;; Don't send out a blank subject line
1183 (goto-char (point-min))
1184 (if (re-search-forward "^Subject:\\([ \t]*\n\\)+\\b" delimline t
)
1186 ;; This one matches a Subject just before the header delimiter.
1187 (if (and (re-search-forward "^Subject:\\([ \t]*\n\\)+" delimline t
)
1188 (= (match-end 0) delimline
))
1189 (replace-match "")))
1190 ;; Put the "From:" field in unless for some odd reason
1191 ;; they put one in themselves.
1192 (goto-char (point-min))
1193 (if (not (re-search-forward "^From:" delimline t
))
1194 (mail-insert-from-field))
1195 ;; Possibly add a MIME header for the current coding system
1196 (let (charset where-content-type
)
1197 (goto-char (point-min))
1198 (setq where-content-type
1199 (re-search-forward "^Content-type:" delimline t
))
1200 (goto-char (point-min))
1201 (and (eq mail-send-nonascii
'mime
)
1202 (not (re-search-forward "^MIME-version:" delimline t
))
1203 (progn (skip-chars-forward "\0-\177")
1204 (/= (point) (point-max)))
1207 (coding-system-get selected-coding
:mime-charset
))
1209 (goto-char delimline
)
1210 (insert "MIME-version: 1.0\n"
1211 "Content-type: text/plain; charset="
1212 (symbol-name charset
)
1213 "\nContent-Transfer-Encoding: 8bit\n")
1214 ;; The character set we will actually use
1215 ;; should override any specified in the message itself.
1216 (when where-content-type
1217 (goto-char where-content-type
)
1218 (delete-region (point-at-bol)
1219 (progn (forward-line 1) (point)))))))
1220 ;; Insert an extra newline if we need it to work around
1221 ;; Sun's bug that swallows newlines.
1222 (goto-char (1+ delimline
))
1223 (if (eval mail-mailer-swallows-blank-line
)
1225 ;; Find and handle any FCC fields.
1226 (goto-char (point-min))
1227 (if (re-search-forward "^FCC:" delimline t
)
1229 (setq fcc-was-found t
)
1230 (mail-do-fcc delimline
)))
1231 (if mail-interactive
1232 (with-current-buffer errbuf
1234 ;; Encode the header according to RFC2047.
1235 (mail-encode-header (point-min) delimline
)
1236 (goto-char (point-min))
1237 (if (let ((case-fold-search t
))
1238 (or resend-to-addresses
1239 (re-search-forward "^To:\\|^cc:\\|^bcc:"
1241 (let* ((default-directory "/")
1242 (coding-system-for-write selected-coding
)
1244 (append (list (point-min) (point-max)
1246 nil errbuf nil
"-oi")
1248 (list "-f" envelope-from
))
1249 ;; ;; Don't say "from root" if running under su.
1250 ;; (and (equal (user-real-login-name) "root")
1251 ;; (list "-f" (user-login-name)))
1252 (and mail-alias-file
1253 (list (concat "-oA" mail-alias-file
)))
1254 (if mail-interactive
1255 sendmail-error-reporting-interactive
1256 sendmail-error-reporting-non-interactive
)
1257 ;; Get the addresses from the message
1258 ;; unless this is a resend.
1259 ;; We must not do that for a resend
1260 ;; because we would find the original addresses.
1261 ;; For a resend, include the specific addresses.
1262 (or resend-to-addresses
1266 (list "-N" (mapconcat 'symbol-name
1270 (exit-value (apply 'call-process-region args
)))
1271 (cond ((or (null exit-value
) (eq 0 exit-value
)))
1272 ((numberp exit-value
)
1273 (error "Sending...failed with exit value %d" exit-value
))
1274 ((stringp exit-value
)
1275 (error "Sending...terminated by signal: %s" exit-value
))
1277 (error "SENDMAIL-SEND-IT -- fall through: %S" exit-value
))))
1279 (error "No recipients")))
1280 (if mail-interactive
1281 (with-current-buffer errbuf
1282 (goto-char (point-min))
1283 (while (re-search-forward "\n\n* *" nil t
)
1284 (replace-match "; "))
1285 (if (not (zerop (buffer-size)))
1286 (error "Sending...failed to %s"
1287 (buffer-substring (point-min) (point-max)))))))
1288 (kill-buffer tembuf
)
1289 (if (bufferp errbuf
)
1290 (kill-buffer errbuf
)))))
1292 (autoload 'rmail-output-to-rmail-buffer
"rmailout")
1294 (defun mail-do-fcc (header-end)
1295 "Find and act on any FCC: headers in the current message before HEADER-END.
1296 If a buffer is visiting the FCC file, append to it before
1297 offering to save it, if it was modified initially. If this is an
1298 Rmail buffer, update Rmail as needed. If there is no buffer,
1299 just append to the file, in Babyl format if necessary."
1300 (unless (markerp header-end
)
1301 (error "Value of `header-end' must be a marker"))
1303 (mailbuf (current-buffer))
1304 (time (current-time)))
1306 (goto-char (point-min))
1307 (let ((case-fold-search t
))
1308 (while (re-search-forward "^FCC:[ \t]*" header-end t
)
1309 (push (buffer-substring (point)
1312 (skip-chars-backward " \t")
1315 (delete-region (match-beginning 0)
1316 (progn (forward-line 1) (point)))))
1318 ;; This initial newline is not written out if we create a new
1319 ;; file (see below).
1320 (insert "\nFrom " (user-login-name) " " (current-time-string time
) "\n")
1321 ;; Insert the time zone before the year.
1324 (require 'mail-utils
)
1325 (insert (mail-rfc822-time-zone time
) " ")
1326 (goto-char (point-max))
1327 (insert-buffer-substring mailbuf
)
1328 ;; Make sure messages are separated.
1329 (goto-char (point-max))
1332 ;; ``Quote'' "^From " as ">From "
1333 ;; (note that this isn't really quoting, as there is no requirement
1334 ;; that "^[>]+From " be quoted in the same transparent way.)
1335 (let ((case-fold-search nil
))
1336 (while (search-forward "\nFrom " nil t
)
1339 (dolist (fcc fcc-list
)
1340 (let* ((buffer (find-buffer-visiting fcc
))
1341 (curbuf (current-buffer))
1344 (beg (point-min)) ; the initial blank line
1346 ;; After the ^From line.
1347 (beg2 (save-excursion (goto-char (point-min))
1348 (forward-line 2) (point))))
1350 ;; File is present in a buffer => append to that buffer.
1351 (with-current-buffer buffer
1352 (setq buffer-matches-file
1353 (and (not (buffer-modified-p))
1354 (verify-visited-file-modtime buffer
)))
1355 (let ((msg (bound-and-true-p rmail-current-message
))
1356 (buffer-read-only nil
))
1357 ;; If MSG is non-nil, buffer is in Rmail mode.
1359 (let ((buff (generate-new-buffer " *mail-do-fcc")))
1362 (with-current-buffer buff
1363 (insert-buffer-substring curbuf
(1+ beg
) end
))
1364 (rmail-output-to-rmail-buffer buff msg
))
1365 (kill-buffer buff
)))
1366 ;; Output file not in Rmail mode => just insert
1370 (goto-char (point-max))
1371 (insert-buffer-substring curbuf beg end
)))
1372 ;; Offer to save the buffer if it was modified
1373 ;; before we started.
1374 (unless buffer-matches-file
1375 (if (y-or-n-p (format "Save file %s? " fcc
))
1377 (setq dont-write-the-file t
)))))
1378 ;; Append to the file directly, unless we've already taken
1380 (unless dont-write-the-file
1381 (if (and (file-exists-p fcc
)
1382 (mail-file-babyl-p fcc
))
1383 ;; If the file is a Babyl file, convert the message to
1384 ;; Babyl format. Even though Rmail no longer uses
1385 ;; Babyl, this code can remain for the time being, on
1386 ;; the off-chance one FCCs to a Babyl file that has
1387 ;; not yet been converted to mbox.
1388 (let ((coding-system-for-write
1389 (or rmail-file-coding-system
'emacs-mule
)))
1391 (insert "\C-l\n0, unseen,,\n*** EOOH ***\nDate: "
1392 (mail-rfc822-date) "\n")
1393 (insert-buffer-substring curbuf beg2 end
)
1395 (write-region (point-min) (point-max) fcc t
)))
1396 ;; Ensure there is a blank line between messages, but
1397 ;; not at the very start of the file.
1398 (write-region (if (file-exists-p fcc
)
1401 (point-max) fcc t
)))
1402 (and buffer
(not dont-write-the-file
)
1403 (with-current-buffer buffer
1404 (set-visited-file-modtime)))))))))
1406 (defun mail-sent-via ()
1407 "Make a Sent-via header line from each To or CC header line."
1410 ;; put a marker at the end of the header
1411 (let ((end (copy-marker (mail-header-end)))
1412 (case-fold-search t
))
1413 (goto-char (point-min))
1414 ;; search for the To: lines and make Sent-via: lines from them
1415 ;; search for the next To: line
1416 (while (re-search-forward "^\\(to\\|cc\\):" end t
)
1417 ;; Grab this line plus all its continuations, sans the `to:'.
1419 (buffer-substring (point)
1421 (if (re-search-forward "^[^ \t\n]" end t
)
1425 ;; Insert a copy, with altered header field name.
1426 (insert-before-markers "Sent-via:" to-line
))))))
1428 (make-obsolete 'mail-sent-via
"nobody can remember what it is for." "24.1")
1432 "Move point to end of To field, creating it if necessary."
1435 (mail-position-on-field "To"))
1437 (defun mail-subject ()
1438 "Move point to end of Subject field, creating it if necessary."
1441 (mail-position-on-field "Subject"))
1444 "Move point to end of CC field, creating it if necessary."
1447 (or (mail-position-on-field "cc" t
)
1448 (progn (mail-position-on-field "to")
1449 (insert "\nCC: "))))
1452 "Move point to end of BCC field, creating it if necessary."
1455 (or (mail-position-on-field "bcc" t
)
1456 (progn (mail-position-on-field "to")
1457 (insert "\nBCC: "))))
1459 (defun mail-fcc (folder)
1460 "Add a new FCC field, with file name completion."
1461 (interactive "FFolder carbon copy: ")
1463 (or (mail-position-on-field "fcc" t
) ;Put new field after exiting FCC.
1464 (mail-position-on-field "to"))
1465 (insert "\nFCC: " folder
))
1467 (defun mail-reply-to ()
1468 "Move point to end of Reply-To field, creating it if necessary."
1471 (mail-position-on-field "Reply-To"))
1473 (defun mail-mail-reply-to ()
1474 "Move point to end of Mail-Reply-To field, creating it if necessary."
1477 (or (mail-position-on-field "mail-reply-to" t
)
1478 (progn (mail-position-on-field "to")
1479 (insert "\nMail-Reply-To: "))))
1481 (defun mail-mail-followup-to ()
1482 "Move point to end of Mail-Followup-To field, creating it if necessary."
1485 (or (mail-position-on-field "mail-followup-to" t
)
1486 (progn (mail-position-on-field "to")
1487 (insert "\nMail-Followup-To: "))))
1489 (defun mail-position-on-field (field &optional soft
)
1491 (case-fold-search t
))
1492 (setq end
(mail-header-end))
1493 (goto-char (point-min))
1494 (if (re-search-forward (concat "^" (regexp-quote field
) ":") end t
)
1496 (re-search-forward "^[^ \t]" nil
'move
)
1498 (skip-chars-backward "\n")
1501 (progn (goto-char end
)
1502 (insert field
": \n")
1503 (skip-chars-backward "\n")))
1507 "Move point to beginning of text field."
1510 (goto-char (mail-text-start)))
1512 (defun mail-signature (&optional atpoint
)
1513 "Sign letter with signature.
1514 If the variable `mail-signature' is a string, inserts it.
1515 If it is t or nil, inserts the contents of the file `mail-signature-file'.
1516 Otherwise, evals `mail-signature'.
1517 Prefix argument ATPOINT means insert at point rather than the end."
1519 ;; Test for an unreadable file here, before we delete trailing
1520 ;; whitespace, so that we don't modify the buffer needlessly.
1521 (if (and (memq mail-signature
'(t nil
))
1522 (not (file-readable-p mail-signature-file
)))
1523 (if (called-interactively-p 'interactive
)
1524 (message "The signature file `%s' could not be read"
1525 mail-signature-file
))
1528 (goto-char (point-max))
1529 ;; Delete trailing whitespace and blank lines.
1530 (skip-chars-backward " \t\n")
1532 (delete-region (point) (point-max)))
1533 (cond ((stringp mail-signature
)
1534 (insert mail-signature
))
1535 ((memq mail-signature
'(t nil
))
1536 (insert "\n\n-- \n")
1537 (insert-file-contents (expand-file-name mail-signature-file
)))
1539 ;; FIXME add condition-case error handling?
1540 (eval mail-signature
))))))
1542 (defun mail-fill-yanked-message (&optional justifyp
)
1543 "Fill the paragraphs of a message yanked into this one.
1544 Numeric argument means justify as well."
1547 (goto-char (mail-text-start))
1548 (fill-individual-paragraphs (point)
1551 mail-citation-prefix-regexp
)))
1553 (defun mail-indent-citation ()
1554 "Modify text just inserted from a message to be cited.
1555 The inserted text should be the region.
1556 When this function returns, the region is again around the modified text.
1558 Normally, indent each nonblank line `mail-indentation-spaces' spaces.
1559 However, if `mail-yank-prefix' is non-nil, insert that prefix on each line."
1560 (mail-yank-clear-headers (region-beginning) (region-end))
1561 (if (null mail-yank-prefix
)
1562 (indent-rigidly (region-beginning) (region-end)
1563 mail-indentation-spaces
)
1565 (let ((end (set-marker (make-marker) (region-end))))
1566 (goto-char (region-beginning))
1567 (while (< (point) end
)
1568 (insert mail-yank-prefix
)
1569 (forward-line 1))))))
1571 (defun mail-yank-original (arg)
1572 "Insert the message being replied to, if any (in Rmail).
1573 Puts point after the text and mark before.
1574 Normally, indents each nonblank line ARG spaces (default 3).
1575 However, if `mail-yank-prefix' is non-nil, insert that prefix on each line.
1577 Just \\[universal-argument] as argument means don't indent, insert no prefix,
1578 and don't delete any header fields."
1580 (if mail-reply-action
1581 (let ((start (point))
1582 (original mail-reply-action
)
1584 (and (consp original
) (eq (car original
) 'insert-buffer
)
1585 (setq original
(nth 1 original
)))
1586 (if (consp original
)
1588 ;; Call yank function, and set the mark if it doesn't.
1589 (apply (car original
) (cdr original
))
1590 (if (eq omark
(mark t
))
1591 (push-mark (point))))
1592 ;; If the original message is in another window in the same
1593 ;; frame, delete that window to save space.
1594 (delete-windows-on original t
)
1596 ;; We really want this to set mark.
1597 (insert-buffer original
)
1598 ;; If they yank the original text, the encoding of the
1599 ;; original message is a better default than
1600 ;; the default buffer-file-coding-system.
1601 (and (coding-system-equal
1602 (default-value 'buffer-file-coding-system
)
1603 buffer-file-coding-system
)
1604 (setq buffer-file-coding-system
1605 (coding-system-change-text-conversion
1606 buffer-file-coding-system
1608 (with-current-buffer original
1609 buffer-file-coding-system
))))))
1610 (set-text-properties (point) (mark t
) nil
))
1614 (let ((mail-indentation-spaces (if arg
(prefix-numeric-value arg
)
1615 mail-indentation-spaces
))
1616 ;; Avoid error in Transient Mark mode
1617 ;; on account of mark's being inactive.
1618 (mark-even-if-inactive t
))
1619 (cond (mail-citation-hook
1620 ;; Bind mail-citation-header to the inserted
1621 ;; message's header.
1622 (let ((mail-citation-header
1623 (buffer-substring-no-properties
1627 (narrow-to-region start
(point-max))
1631 (run-hooks 'mail-citation-hook
)))
1633 (run-hooks 'mail-yank-hooks
))
1635 (mail-indent-citation)))))
1636 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
1637 ;; It is cleaner to avoid activation, even though the command
1638 ;; loop would deactivate the mark because we inserted text.
1639 (goto-char (prog1 (mark t
)
1640 (set-marker (mark-marker) (point) (current-buffer))))
1641 (if (not (eolp)) (insert ?
\n)))))
1643 (defun mail-yank-clear-headers (start end
)
1646 (setq temp start start end end temp
)))
1647 (if mail-yank-ignored-headers
1650 (if (search-forward "\n\n" end t
)
1652 (narrow-to-region start
(point))
1654 (while (let ((case-fold-search t
))
1655 (re-search-forward mail-yank-ignored-headers nil t
))
1657 (delete-region (point)
1658 (progn (re-search-forward "\n[^ \t]")
1662 (defun mail-yank-region (arg)
1663 "Insert the selected region from the message being replied to.
1664 Puts point after the text and mark before.
1665 Normally, indents each nonblank line ARG spaces (default 3).
1666 However, if `mail-yank-prefix' is non-nil, insert that prefix on each line.
1668 Just \\[universal-argument] as argument means don't indent, insert no prefix,
1669 and don't delete any header fields."
1671 (and (consp mail-reply-action
)
1672 (eq (car mail-reply-action
) 'insert-buffer
)
1673 (with-current-buffer (nth 1 mail-reply-action
)
1675 (error "No mark set: %S" (current-buffer))))
1676 (let ((buffer (nth 1 mail-reply-action
))
1678 ;; Avoid error in Transient Mark mode
1679 ;; on account of mark's being inactive.
1680 (mark-even-if-inactive t
))
1681 ;; Insert the citation text.
1682 (insert (with-current-buffer buffer
1683 (buffer-substring-no-properties (point) (mark))))
1685 ;; Indent or otherwise annotate the citation text.
1688 (let ((mail-indentation-spaces (if arg
(prefix-numeric-value arg
)
1689 mail-indentation-spaces
)))
1690 (if mail-citation-hook
1691 ;; Bind mail-citation-header to the original message's header.
1692 (let ((mail-citation-header
1693 (with-current-buffer buffer
1694 (buffer-substring-no-properties
1697 (goto-char (point-min))
1700 (run-hooks 'mail-citation-hook
))
1702 (run-hooks 'mail-yank-hooks
)
1703 (mail-indent-citation))))))))
1705 (defun mail-split-line ()
1706 "Split current line, moving portion beyond point vertically down.
1707 If the current line has `mail-yank-prefix', insert it on the new line."
1709 (split-line mail-yank-prefix
))
1712 (defun mail-insert-file (&optional file
)
1713 "Insert a file at the end of the buffer, with separator lines around it."
1714 (interactive "fAttach file: ")
1716 (goto-char (point-max))
1717 (or (bolp) (newline))
1719 (let ((start (point))
1721 (insert (format "===File %s===" file
))
1722 (insert-char ?
= (max 0 (- 60 (current-column))))
1724 (setq middle
(point))
1725 (insert "============================================================\n")
1728 (insert-file-contents file
)
1729 (or (bolp) (newline))
1730 (goto-char start
))))
1732 (define-obsolete-function-alias 'mail-attach-file
'mail-insert-file
"24.1")
1734 (declare-function mml-attach-file
"mml"
1735 (file &optional type description disposition
))
1736 (declare-function mm-default-file-encoding
"mm-encode" (file))
1738 (defun mail-add-attachment (file)
1739 "Add FILE as a MIME attachment to the end of the mail message being composed."
1740 (interactive "fAttach file: ")
1741 (mml-attach-file file
1742 (or (mm-default-file-encoding file
)
1743 "application/octet-stream") nil
)
1744 (setq mail-encode-mml t
))
1747 ;; Put these commands last, to reduce chance of lossage from quitting
1748 ;; in middle of loading the file.
1751 (defun mail (&optional noerase to subject in-reply-to cc replybuffer
1752 actions return-action
)
1753 "Edit a message to be sent. Prefix arg means resume editing (don't erase).
1754 When this function returns, the buffer `*mail*' is selected.
1755 The value is t if the message was newly initialized; otherwise, nil.
1757 Optionally, the signature file `mail-signature-file' can be inserted at the
1758 end; see the variable `mail-signature'.
1761 While editing message, type \\[mail-send-and-exit] to send the message and exit.
1763 Various special commands starting with C-c are available in sendmail mode
1764 to move to message header fields:
1767 If `mail-self-blind' is non-nil, a BCC to yourself is inserted
1768 when the message is initialized.
1770 If `mail-default-reply-to' is non-nil, it should be an address (a string);
1771 a Reply-to: field with that address is inserted.
1773 If `mail-archive-file-name' is non-nil, an FCC field with that file name
1776 The normal hook `mail-setup-hook' is run after the message is
1777 initialized. It can add more default fields to the message.
1779 The first argument, NOERASE, determines what to do when there is
1780 an existing modified `*mail*' buffer. If NOERASE is nil, the
1781 existing mail buffer is used, and the user is prompted whether to
1782 keep the old contents or to erase them. If NOERASE has the value
1783 `new', a new mail buffer will be created instead of using the old
1784 one. Any other non-nil value means to always select the old
1785 buffer without erasing the contents.
1787 The second through fifth arguments,
1788 TO, SUBJECT, IN-REPLY-TO and CC, specify if non-nil
1789 the initial contents of those header fields.
1790 These arguments should not have final newlines.
1791 The sixth argument REPLYBUFFER is a buffer which contains an
1792 original message being replied to, or else an action
1793 of the form (FUNCTION . ARGS) which says how to insert the original.
1794 Or it can be nil, if not replying to anything.
1795 The seventh argument ACTIONS is a list of actions to take
1796 if/when the message is sent. Each action looks like (FUNCTION . ARGS);
1797 when the message is sent, we apply FUNCTION to ARGS.
1798 This is how Rmail arranges to mark messages `answered'."
1800 (if (eq noerase
'new
)
1801 (pop-to-buffer-same-window (generate-new-buffer "*mail*"))
1803 (not (get-buffer "*mail*"))
1805 (pop-to-buffer-same-window "*mail*"))
1807 ;; Avoid danger that the auto-save file can't be written.
1808 (let ((dir (expand-file-name
1809 (file-name-as-directory mail-default-directory
))))
1810 (if (file-exists-p dir
)
1811 (setq default-directory dir
)))
1812 ;; Only call auto-save-mode if necessary, to avoid changing auto-save file.
1813 (if (or (and auto-save-default
(not buffer-auto-save-file-name
))
1814 (and (not auto-save-default
) buffer-auto-save-file-name
))
1815 (auto-save-mode auto-save-default
))
1817 ;; Disconnect the buffer from its visited file
1818 ;; (in case the user has actually visited a file *mail*).
1819 ;; (set-visited-file-name nil)
1821 (and (not (and noerase
1822 (not (eq noerase
'new
))))
1823 (if buffer-file-name
1824 (if (buffer-modified-p)
1825 (when (y-or-n-p "Buffer has unsaved changes; reinitialize it and discard them? ")
1826 (if (y-or-n-p "Disconnect buffer from visited file? ")
1827 (set-visited-file-name nil
))
1829 (when (y-or-n-p "Reinitialize buffer, and disconnect it from the visited file? ")
1830 (set-visited-file-name nil
)
1832 ;; A non-file-visiting buffer.
1833 (if (buffer-modified-p)
1834 (y-or-n-p "Unsent message being composed; erase it? ")
1836 (let ((inhibit-read-only t
))
1838 (mail-setup to subject in-reply-to cc replybuffer actions
1840 (setq initialized t
)))
1841 (if (and buffer-auto-save-file-name
1842 (file-exists-p buffer-auto-save-file-name
))
1843 (message "Auto save file for draft message exists; consider M-x mail-recover"))
1846 (declare-function dired-view-file
"dired" ())
1847 (declare-function dired-get-filename
"dired" (&optional localp no-error-if-not-filep
))
1849 (defun mail-recover-1 ()
1850 "Pop up a list of auto-saved draft messages so you can recover one of them."
1852 (let ((file-name (make-auto-save-file-name))
1853 (ls-lisp-support-shell-wildcards t
)
1854 non-random-len wildcard
)
1855 ;; Remove the random part from the auto-save-file-name, and
1856 ;; create a wildcard which matches possible candidates.
1857 ;; Note: this knows that make-auto-save-file-name appends
1858 ;; "#<RANDOM-STUFF>#" to the buffer name, where RANDOM-STUFF
1859 ;; is the result of (make-temp-name "").
1860 (setq non-random-len
1861 (- (length file-name
) (length (make-temp-name "")) 1))
1862 (setq wildcard
(concat (substring file-name
0 non-random-len
) "*"))
1863 (if (null (file-expand-wildcards wildcard
))
1864 (message "There are no auto-saved drafts to recover")
1865 ;; Bind dired-trivial-filenames to t because all auto-save file
1866 ;; names are normally ``trivial'', so Dired will set point after
1867 ;; all the files, at buffer bottom. We want it on the first
1869 ;; Require dired so that dired-trivial-filenames does not get
1870 ;; unbound on exit from the let.
1872 (let ((dired-trivial-filenames t
))
1873 (dired-other-window wildcard
(concat dired-listing-switches
" -t")))
1874 (rename-buffer "*Auto-saved Drafts*" t
)
1876 (goto-char (point-min))
1877 (or (looking-at " Move to the draft file you want to recover,")
1878 (let ((inhibit-read-only t
))
1879 ;; Each line starts with a space so that Font Lock mode
1880 ;; won't highlight the first character.
1882 Move to the draft file you want to recover, then type C-c C-c
1883 to recover text of message whose composition was interrupted.
1884 To browse text of a draft, type v on the draft file's line.
1886 You can also delete some of these files;
1887 type d on a line to mark that file for deletion.
1889 List of possible auto-save files for recovery:
1893 (let ((map (make-sparse-keymap)))
1894 (set-keymap-parent map
(current-local-map))
1896 (define-key (current-local-map) "v"
1899 (let ((coding-system-for-read 'utf-8-emacs-unix
))
1900 (dired-view-file))))
1901 (define-key (current-local-map) "\C-c\C-c"
1904 (let ((fname (dired-get-filename))
1905 ;; Auto-saved files are written in the internal
1906 ;; representation, so they should be read accordingly.
1907 (coding-system-for-read 'utf-8-emacs-unix
))
1908 (switch-to-buffer-other-window "*mail*")
1909 (let ((buffer-read-only nil
))
1911 (insert-file-contents fname nil
)
1912 ;; insert-file-contents will set buffer-file-coding-system
1913 ;; to utf-8-emacs, which is probably not what they want to
1914 ;; use for sending the message. But we don't know what
1915 ;; was its value before the buffer was killed or Emacs
1916 ;; crashed. We therefore reset buffer-file-coding-system
1917 ;; to the default value, so that either the default does
1918 ;; TRT, or the user will get prompted for the right
1919 ;; encoding when they send the message.
1920 (setq buffer-file-coding-system
1921 (default-value 'buffer-file-coding-system
)))))))))
1923 (declare-function dired-move-to-filename
"dired" (&optional raise-error eol
))
1924 (declare-function dired-get-filename
"dired" (&optional localp no-error-if-not-filep
))
1925 (declare-function dired-view-file
"dired" ())
1927 (defun mail-recover ()
1928 "Recover interrupted mail composition from auto-save files.
1930 If the mail buffer has a current valid auto-save file,
1931 the command recovers that file. Otherwise, it displays a
1932 buffer showing the existing auto-saved draft messages;
1933 you can move to one of them and type C-c C-c to recover that one."
1935 ;; In case they invoke us from some random buffer...
1936 (switch-to-buffer "*mail*")
1937 ;; If *mail* didn't exist, set its directory, so that auto-saved
1938 ;; drafts will be found.
1939 (let ((dir (expand-file-name
1940 (file-name-as-directory mail-default-directory
))))
1941 (if (file-exists-p dir
)
1942 (setq default-directory dir
)))
1943 (or (eq major-mode
'mail-mode
)
1945 (let ((file-name buffer-auto-save-file-name
))
1946 (cond ((and file-name
(file-exists-p file-name
))
1948 ;; This used to invoke `ls' via call-process, but
1949 ;; dired-noselect is more portable to systems where
1950 ;; `ls' is not a standard program (it will use
1951 ;; ls-lisp instead).
1952 (dired-noselect file-name
1953 (concat dired-listing-switches
" -t"))))
1954 (save-selected-window
1955 (switch-to-buffer-other-window dispbuf
)
1956 (goto-char (point-min))
1958 (dired-move-to-filename)
1959 (setq dispbuf
(rename-buffer "*Directory*" t
)))
1960 (if (not (yes-or-no-p
1961 (format "Recover mail draft from auto save file %s? "
1963 (error "mail-recover cancelled")
1964 (let ((buffer-read-only nil
)
1965 (buffer-coding buffer-file-coding-system
)
1966 ;; Auto-save files are written in internal
1967 ;; representation of non-ASCII characters.
1968 (coding-system-for-read 'utf-8-emacs-unix
))
1970 (insert-file-contents file-name nil
)
1971 (setq buffer-file-coding-system buffer-coding
)))))
1972 (t (mail-recover-1)))))
1975 (defun mail-other-window (&optional noerase to subject in-reply-to cc replybuffer sendactions
)
1976 "Like `mail' command, but display mail buffer in another window."
1978 (switch-to-buffer-other-window "*mail*")
1979 (mail noerase to subject in-reply-to cc replybuffer sendactions
))
1982 (defun mail-other-frame (&optional noerase to subject in-reply-to cc replybuffer sendactions
)
1983 "Like `mail' command, but display mail buffer in another frame."
1985 (switch-to-buffer-other-frame "*mail*")
1986 (mail noerase to subject in-reply-to cc replybuffer sendactions
))
1988 ;; Do not add anything but external entries on this page.
1993 ;; byte-compile-dynamic: t
1997 ;;; sendmail.el ends here