1 ;;; sendmail.el --- mail sending commands for Emacs. -*- byte-compile-dynamic: t -*-
3 ;; Copyright (C) 1985, 1986, 1992, 1993, 1994, 1995, 1996, 1998, 2000,
4 ;; 2001, 2002, 2003, 2004, 2005 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 2, or (at your option)
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; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
28 ;; This mode provides mail-sending facilities from within Emacs. It is
29 ;; documented in the Emacs user's manual.
33 ;; Necessary to avoid recursive `require's.
38 (autoload 'rfc2047-encode-string
"rfc2047")
40 (defgroup sendmail nil
41 "Mail sending commands for Emacs."
45 (defcustom mail-setup-with-from t
46 "Non-nil means insert `From:' field when setting up the message."
52 (defcustom mail-from-style
'angles
"\
53 *Specifies how \"From:\" fields look.
55 If `nil', they contain just the return address like:
57 If `parens', they look like:
58 king@grassland.com (Elvis Parsley)
59 If `angles', they look like:
60 Elvis Parsley <king@grassland.com>
61 If `system-default', allows the mailer to insert its default From field
62 derived from the envelope-from address.
64 In old versions of Emacs, the `system-default' setting also caused
65 Emacs to pass the proper email address from `user-mail-address'
66 to the mailer to specify the envelope-from address. But that is now
67 controlled by a separate variable, `mail-specify-envelope-from'."
68 :type
'(choice (const nil
) (const parens
) (const angles
)
69 (const system-default
))
74 (defcustom mail-specify-envelope-from nil
75 "*If non-nil, specify the envelope-from address when sending mail.
76 The value used to specify it is whatever is found in
77 the variable `mail-envelope-from', with `user-mail-address' as fallback.
79 On most systems, specifying the envelope-from address is a
80 privileged operation. This variable affects sendmail and
81 smtpmail -- if you use feedmail to send mail, see instead the
82 variable `feedmail-deduce-envelope-from'."
87 (defcustom mail-envelope-from nil
88 "*If non-nil, designate the envelope-from address when sending mail.
89 This only has an effect if `mail-specify-envelope-from' is non-nil.
90 The value should be either a string, or the symbol `header' (in
91 which case the contents of the \"From\" header of the message
92 being sent is used), or nil (in which case the value of
93 `user-mail-address' is used)."
95 :type
'(choice (string :tag
"From-name")
96 (const :tag
"Use From: header from message" header
)
97 (const :tag
"Use `user-mail-address'" nil
))
101 (defcustom mail-self-blind nil
"\
102 *Non-nil means insert BCC to self in messages to be sent.
103 This is done when the message is initialized,
104 so you can remove or alter the BCC field to override the default."
109 (defcustom mail-interactive nil
"\
110 *Non-nil means when sending a message wait for and display errors.
111 nil means let mailer mail back a message to report errors."
116 (defcustom mail-yank-ignored-headers
"^via:\\|^mail-from:\\|^origin:\\|^status:\\|^remailed\\|^received:\\|^message-id:\\|^summary-line:\\|^to:\\|^subject:\\|^in-reply-to:\\|^return-path:\\|^mail-reply-to:\\|^mail-followup-to:" "\
117 *Delete these headers from old message when it's inserted in a reply."
121 ;; Useful to set in site-init.el
123 (defcustom send-mail-function
'sendmail-send-it
124 "Function to call to send the current buffer as mail.
125 The headers should be delimited by a line which is
126 not a valid RFC822 header or continuation line,
127 that matches the variable `mail-header-separator'.
128 This is used by the default mail-sending commands. See also
129 `message-send-mail-function' for use with the Message package."
130 :type
'(radio (function-item sendmail-send-it
:tag
"Use Sendmail package")
131 (function-item smtpmail-send-it
:tag
"Use SMTPmail package")
132 (function-item feedmail-send-it
:tag
"Use Feedmail package")
137 (defcustom mail-header-separator
"--text follows this line--" "\
138 *Line used to separate headers from text in messages being composed."
142 ;; Set up mail-header-separator for use as a category text property.
143 (put 'mail-header-separator
'rear-nonsticky
'(category))
144 ;;; This was a nice idea, for preventing accidental modification of
145 ;;; the separator. But I found it also prevented or obstructed
146 ;;; certain deliberate operations, such as copying the separator line
147 ;;; up to the top to send myself a copy of an already sent outgoing message
148 ;;; and other things. So I turned it off. --rms.
149 ;;;(put 'mail-header-separator 'read-only t)
152 (defcustom mail-archive-file-name nil
"\
153 *Name of file to write all outgoing messages in, or nil for none.
154 This can be an inbox file or an Rmail file."
155 :type
'(choice file
(const nil
))
159 (defcustom mail-default-reply-to nil
160 "*Address to insert as default Reply-to field of outgoing messages.
161 If nil, it will be initialized from the REPLYTO environment variable
162 when you first send mail."
163 :type
'(choice (const nil
) string
)
167 (defcustom mail-alias-file nil
168 "*If non-nil, the name of a file to use instead of `/usr/lib/aliases'.
169 This file defines aliases to be expanded by the mailer; this is a different
170 feature from that of defining aliases in `.mailrc' to be expanded in Emacs.
171 This variable has no effect unless your system uses sendmail as its mailer."
172 :type
'(choice (const nil
) file
)
176 (defcustom mail-personal-alias-file
"~/.mailrc"
177 "*If non-nil, the name of the user's personal mail alias file.
178 This file typically should be in same format as the `.mailrc' file used by
179 the `Mail' or `mailx' program.
180 This file need not actually exist."
181 :type
'(choice (const nil
) file
)
184 (defcustom mail-setup-hook nil
185 "Normal hook, run each time a new outgoing mail message is initialized.
186 The function `mail-setup' runs this hook."
188 :options
'(fortune-to-signature spook mail-abbrevs-setup
)
191 (defvar mail-aliases t
192 "Alist of mail address aliases,
193 or t meaning should be initialized from your mail aliases file.
194 \(The file's name is normally `~/.mailrc', but `mail-personal-alias-file'
195 can specify a different file name.)
196 The alias definitions in the file have this form:
197 alias ALIAS MEANING")
199 (defvar mail-alias-modtime nil
200 "The modification time of your mail alias file when it was last examined.")
202 (defcustom mail-yank-prefix nil
203 "*Prefix insert on lines of yanked message being replied to.
204 nil means use indentation."
205 :type
'(choice (const nil
) string
)
208 (defcustom mail-indentation-spaces
3
209 "*Number of spaces to insert at the beginning of each cited line.
210 Used by `mail-yank-original' via `mail-indent-citation'."
213 (defvar mail-yank-hooks nil
214 "Obsolete hook for modifying a citation just inserted in the mail buffer.
215 Each hook function can find the citation between (point) and (mark t).
216 And each hook function should leave point and mark around the citation
219 This is a normal hook, misnamed for historical reasons.
220 It is semi-obsolete and mail agents should no longer use it.")
223 (defcustom mail-citation-hook nil
224 "*Hook for modifying a citation just inserted in the mail buffer.
225 Each hook function can find the citation between (point) and (mark t),
226 and should leave point and mark around the citation text as modified.
227 The hook functions can find the header of the cited message
228 in the variable `mail-citation-header', whether or not this is included
229 in the cited portion of the message.
231 If this hook is entirely empty (nil), a default action is taken
232 instead of no action."
236 (defvar mail-citation-header nil
237 "While running `mail-citation-hook', this variable holds the message header.
238 This enables the hook functions to see the whole message header
239 regardless of what part of it (if any) is included in the cited text.")
241 (defcustom mail-citation-prefix-regexp
"[ \t]*[-a-z0-9A-Z]*>+[ \t]*\\|[ \t]*"
242 "*Regular expression to match a citation prefix plus whitespace.
243 It should match whatever sort of citation prefixes you want to handle,
244 with whitespace before and after; it should also match just whitespace.
245 The default value matches citations like `foo-bar>' plus whitespace."
250 (defvar mail-abbrevs-loaded nil
)
251 (defvar mail-mode-map nil
)
253 (autoload 'build-mail-aliases
"mailalias"
254 "Read mail aliases from user's personal aliases file and set `mail-aliases'."
257 (autoload 'expand-mail-aliases
"mailalias"
258 "Expand all mail aliases in suitable header fields found between BEG and END.
259 Suitable header fields are `To', `Cc' and `Bcc' and their `Resent-' variants.
260 Optional second arg EXCLUDE may be a regular expression defining text to be
261 removed from alias expansions."
265 (defcustom mail-signature nil
266 "*Text inserted at end of mail buffer when a message is initialized.
267 If t, it means to insert the contents of the file `mail-signature-file'.
268 If a string, that string is inserted.
269 (To make a proper signature, the string should begin with \\n\\n-- \\n,
270 which is the standard way to delimit a signature in a message.)
271 Otherwise, it should be an expression; it is evaluated
272 and should insert whatever you want to insert."
273 :type
'(choice (const :tag
"None" nil
)
274 (const :tag
"Use `.signature' file" t
)
275 (string :tag
"String to insert")
276 (sexp :tag
"Expression to evaluate"))
278 (put 'mail-signature
'risky-local-variable t
)
280 (defcustom mail-signature-file
"~/.signature"
281 "*File containing the text inserted at end of mail buffer."
286 (defcustom mail-default-directory
"~/"
287 "*Directory for mail buffers.
288 Value of `default-directory' for mail buffers.
289 This directory is used for auto-save files of mail buffers."
290 :type
'(directory :tag
"Directory")
294 (defvar mail-reply-action nil
)
295 (defvar mail-send-actions nil
296 "A list of actions to be performed upon successful sending of a message.")
297 (put 'mail-reply-action
'permanent-local t
)
298 (put 'mail-send-actions
'permanent-local t
)
300 (defcustom mail-default-headers nil
301 "*A string containing header lines, to be inserted in outgoing messages.
302 It is inserted before you edit the message,
303 so you can edit or delete these lines."
304 :type
'(choice (const nil
) string
)
307 (defcustom mail-bury-selects-summary t
308 "*If non-nil, try to show RMAIL summary buffer after returning from mail.
309 The functions \\[mail-send-on-exit] or \\[mail-dont-send] select
310 the RMAIL summary buffer before returning, if it exists and this variable
315 (defcustom mail-send-nonascii
'mime
316 "*Specify whether to allow sending non-ASCII characters in mail.
317 If t, that means do allow it. nil means don't allow it.
318 `query' means ask the user each time.
319 `mime' means add an appropriate MIME header if none already present.
320 The default is `mime'.
321 Including non-ASCII characters in a mail message can be problematical
322 for the recipient, who may not know how to decode them properly."
323 :type
'(choice (const t
) (const nil
) (const query
) (const mime
))
326 (defcustom mail-use-dsn nil
327 "*Ask MTA for notification of failed, delayed or successful delivery.
328 Note that only some MTAs (currently only recent versions of Sendmail)
329 support Delivery Status Notification."
331 :type
'(repeat (radio (const :tag
"Failure" failure
)
332 (const :tag
"Delay" delay
)
333 (const :tag
"Success" success
)))
336 ;; Note: could use /usr/ucb/mail instead of sendmail;
337 ;; options -t, and -v if not interactive.
338 (defvar mail-mailer-swallows-blank-line
339 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)" system-configuration
)
340 (file-readable-p "/etc/sendmail.cf")
341 (let ((buffer (get-buffer-create " *temp*")))
345 (insert-file-contents "/etc/sendmail.cf")
346 (goto-char (point-min))
347 (let ((case-fold-search nil
))
348 (re-search-forward "^OR\\>" nil t
)))
349 (kill-buffer buffer
))))
350 ;; According to RFC822, "The field-name must be composed of printable
351 ;; ASCII characters (i.e. characters that have decimal values between
352 ;; 33 and 126, except colon)", i.e. any chars except ctl chars,
354 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
355 "Set this non-nil if the system's mailer runs the header and body together.
356 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
357 The value should be an expression to test whether the problem will
360 (defvar mail-mode-syntax-table
361 (let ((st (make-syntax-table)))
362 ;; define-derived-mode will make it inherit from text-mode-syntax-table.
363 (modify-syntax-entry ?%
". " st
)
365 "Syntax table used while in `mail-mode'.")
367 (defvar mail-font-lock-keywords
369 (let* ((cite-chars "[>|}]")
370 (cite-prefix "[:alpha:]")
371 (cite-suffix (concat cite-prefix
"0-9_.@-`'\"")))
372 (list '("^\\(To\\|Newsgroups\\):" . font-lock-function-name-face
)
373 '("^\\(B?CC\\|Reply-to\\|Mail-\\(reply\\|followup\\)-to\\):" . font-lock-keyword-face
)
374 '("^\\(Subject:\\)[ \t]*\\(.+\\)?"
375 (1 font-lock-comment-face
)
376 ;; (2 font-lock-type-face nil t)
378 ;; Use EVAL to delay in case `mail-header-separator' gets changed.
380 (let ((separator (if (zerop (length mail-header-separator
))
382 (regexp-quote mail-header-separator
))))
383 (cons (concat "^" separator
"$") 'font-lock-warning-face
)))
384 ;; Use MATCH-ANCHORED to effectively anchor the regexp left side.
386 (,(concat "\\=[ \t]*"
387 "\\(\\(\\([" cite-prefix
"]+[" cite-suffix
"]*\\)?"
388 "\\(" cite-chars
"[ \t]*\\)\\)+\\)"
390 (beginning-of-line) (end-of-line)
391 (1 font-lock-comment-delimiter-face nil t
)
392 (5 font-lock-comment-face nil t
)))
393 '("^\\(X-[A-Za-z0-9-]+\\|In-reply-to\\):.*\\(\n[ \t]+.*\\)*$"
394 . font-lock-string-face
))))
395 "Additional expressions to highlight in Mail mode.")
398 (defun sendmail-sync-aliases ()
399 (when mail-personal-alias-file
400 (let ((modtime (nth 5 (file-attributes mail-personal-alias-file
))))
401 (or (equal mail-alias-modtime modtime
)
402 (setq mail-alias-modtime modtime
405 (defun mail-setup (to subject in-reply-to cc replybuffer actions
)
406 (or mail-default-reply-to
407 (setq mail-default-reply-to
(getenv "REPLYTO")))
408 (sendmail-sync-aliases)
409 (if (eq mail-aliases t
)
411 (setq mail-aliases nil
)
412 (when mail-personal-alias-file
413 (if (file-exists-p mail-personal-alias-file
)
414 (build-mail-aliases)))))
415 ;; Don't leave this around from a previous message.
416 (kill-local-variable 'buffer-file-coding-system
)
417 ;; This doesn't work for enable-multibyte-characters.
418 ;; (kill-local-variable 'enable-multibyte-characters)
419 (set-buffer-multibyte default-enable-multibyte-characters
)
420 (if current-input-method
421 (inactivate-input-method))
422 (setq mail-send-actions actions
)
423 (setq mail-reply-action replybuffer
)
424 (goto-char (point-min))
425 (if mail-setup-with-from
426 (mail-insert-from-field))
430 ;; Here removed code to extract names from within <...>
431 ;; on the assumption that mail-strip-quoted-names
432 ;; has been called and has done so.
433 (let ((fill-prefix "\t")
434 (address-start (point)))
436 (fill-region-as-paragraph address-start
(point-max))
437 (goto-char (point-max))
442 (let ((fill-prefix "\t")
443 (address-start (progn (insert "CC: ") (point))))
445 (fill-region-as-paragraph address-start
(point-max))
446 (goto-char (point-max))
450 (let ((fill-prefix "\t")
452 (address-start (point)))
453 (insert "In-reply-to: " in-reply-to
"\n")
454 (fill-region-as-paragraph address-start
(point-max))
455 (goto-char (point-max))
458 (insert "Subject: " (or subject
"") "\n")
459 (if mail-default-headers
460 (insert mail-default-headers
))
461 (if mail-default-reply-to
462 (insert "Reply-to: " mail-default-reply-to
"\n"))
464 (insert "BCC: " user-mail-address
"\n"))
465 (if mail-archive-file-name
466 (insert "FCC: " mail-archive-file-name
"\n"))
467 (put-text-property (point)
469 (insert mail-header-separator
"\n")
471 'category
'mail-header-separator
)
472 ;; Insert the signature. But remember the beginning of the message.
473 (if to
(setq to
(point)))
474 (cond ((eq mail-signature t
)
475 (if (file-exists-p mail-signature-file
)
478 (insert-file-contents mail-signature-file
))))
479 ((stringp mail-signature
)
480 (insert mail-signature
))
482 (eval mail-signature
)))
483 (goto-char (point-max))
484 (or (bolp) (newline)))
485 (if to
(goto-char to
))
486 (or to subject in-reply-to
487 (set-buffer-modified-p nil
))
488 (run-hooks 'mail-setup-hook
))
490 (defcustom mail-mode-hook nil
491 "Hook run by Mail mode."
494 :options
'(footnote-mode))
496 (defvar mail-mode-abbrev-table text-mode-abbrev-table
)
498 (define-derived-mode mail-mode text-mode
"Mail"
499 "Major mode for editing mail to be sent.
500 Like Text Mode but with these additional commands:
501 \\[mail-send] mail-send (send the message) \\[mail-send-and-exit] mail-send-and-exit
502 Here are commands that move to a header field (and create it if there isn't):
503 \\[mail-to] move to To: \\[mail-subject] move to Subject:
504 \\[mail-cc] move to CC: \\[mail-bcc] move to BCC:
505 \\[mail-fcc] move to FCC: \\[mail-reply-to] move to Reply-To:
506 \\[mail-mail-reply-to] move to Mail-Reply-To:
507 \\[mail-mail-followup-to] move to Mail-Followup-To:
508 \\[mail-text] mail-text (move to beginning of message text).
509 \\[mail-signature] mail-signature (insert `mail-signature-file' file).
510 \\[mail-yank-original] mail-yank-original (insert current message, in Rmail).
511 \\[mail-fill-yanked-message] mail-fill-yanked-message (fill what was yanked).
512 \\[mail-sent-via] mail-sent-via (add a Sent-via field for each To or CC).
513 Turning on Mail mode runs the normal hooks `text-mode-hook' and
514 `mail-mode-hook' (in that order)."
515 (make-local-variable 'mail-reply-action
)
516 (make-local-variable 'mail-send-actions
)
517 (setq buffer-offer-save t
)
518 (make-local-variable 'font-lock-defaults
)
519 (setq font-lock-defaults
'(mail-font-lock-keywords t t
))
520 (make-local-variable 'paragraph-separate
)
521 (make-local-variable 'normal-auto-fill-function
)
522 (setq normal-auto-fill-function
'mail-mode-auto-fill
)
523 (make-local-variable 'fill-paragraph-function
)
524 (setq fill-paragraph-function
'mail-mode-fill-paragraph
)
525 ;; Allow using comment commands to add/remove quoting (this only does
526 ;; anything if mail-yank-prefix is set to a non-nil value).
527 (set (make-local-variable 'comment-start
) mail-yank-prefix
)
529 (set (make-local-variable 'comment-start-skip
)
530 (concat "^" (regexp-quote mail-yank-prefix
) "[ \t]*")))
531 (make-local-variable 'adaptive-fill-regexp
)
532 (setq adaptive-fill-regexp
533 (concat "[ \t]*[-[:alnum:]]+>+[ \t]*\\|"
534 adaptive-fill-regexp
))
535 (make-local-variable 'adaptive-fill-first-line-regexp
)
536 (setq adaptive-fill-first-line-regexp
537 (concat "[ \t]*[-[:alnum:]]*>+[ \t]*\\|"
538 adaptive-fill-first-line-regexp
))
539 ;; `-- ' precedes the signature. `-----' appears at the start of the
540 ;; lines that delimit forwarded messages.
541 ;; Lines containing just >= 3 dashes, perhaps after whitespace,
542 ;; are also sometimes used and should be separators.
543 (setq paragraph-separate
(concat (regexp-quote mail-header-separator
)
544 "$\\|\t*\\([-|#;>* ]\\|(?[0-9]+[.)]\\)+$"
545 "\\|[ \t]*[[:alnum:]]*>+[ \t]*$\\|[ \t]*$\\|"
550 (defun mail-header-end ()
551 "Return the buffer location of the end of headers, as a number."
558 (defun mail-text-start ()
559 "Return the buffer location of the start of text, as a number."
567 (defun mail-sendmail-delimit-header ()
568 "Set up whatever header delimiter convention sendmail will use.
569 Concretely: replace the first blank line in the header with the separator."
571 (insert mail-header-separator
)
574 (defun mail-sendmail-undelimit-header ()
575 "Remove header separator to put the message in correct form for sendmail.
576 Leave point at the start of the delimiter line."
578 (delete-region (point) (progn (end-of-line) (point))))
580 (defun mail-mode-auto-fill ()
581 "Carry out Auto Fill for Mail mode.
582 If within the headers, this makes the new lines into continuation lines."
583 (if (< (point) (mail-header-end))
584 (let ((old-line-start (save-excursion (beginning-of-line) (point))))
588 (while (not (eq (point) old-line-start
))
589 ;; Use insert-before-markers in case we're inserting
590 ;; before the saved value of point (which is common).
591 (insert-before-markers " ")
596 (defun mail-mode-fill-paragraph (arg)
597 ;; Do something special only if within the headers.
598 (if (< (point) (mail-header-end))
599 (let (beg end fieldname
)
600 (when (prog1 (re-search-backward "^[-a-zA-Z]+:" nil
'yes
)
603 (downcase (buffer-substring beg
(1- (match-end 0))))))
605 ;; Find continuation lines and get rid of their continuation markers.
606 (while (looking-at "[ \t]")
607 (delete-horizontal-space)
609 (setq end
(point-marker))
611 ;; If this field contains addresses,
612 ;; make sure we can fill after each address.
613 (if (member fieldname
614 '("to" "cc" "bcc" "from" "reply-to"
615 "mail-reply-to" "mail-followup-to"
616 "resent-to" "resent-cc" "resent-bcc"
617 "resent-from" "resent-reply-to"))
618 (while (search-forward "," end t
)
619 (or (looking-at "[ \t]")
621 (fill-region-as-paragraph beg end
)
622 ;; Mark all lines except the first as continuations.
625 (while (< (point) end
)
628 (move-marker end nil
)
635 (setq mail-mode-map
(make-sparse-keymap))
636 (define-key mail-mode-map
"\M-\t" 'mail-complete
)
637 (define-key mail-mode-map
"\C-c?" 'describe-mode
)
638 (define-key mail-mode-map
"\C-c\C-f\C-t" 'mail-to
)
639 (define-key mail-mode-map
"\C-c\C-f\C-b" 'mail-bcc
)
640 (define-key mail-mode-map
"\C-c\C-f\C-f" 'mail-fcc
)
641 (define-key mail-mode-map
"\C-c\C-f\C-c" 'mail-cc
)
642 (define-key mail-mode-map
"\C-c\C-f\C-s" 'mail-subject
)
643 (define-key mail-mode-map
"\C-c\C-f\C-r" 'mail-reply-to
)
644 (define-key mail-mode-map
"\C-c\C-f\C-a" 'mail-mail-reply-to
) ; author
645 (define-key mail-mode-map
"\C-c\C-f\C-l" 'mail-mail-followup-to
) ; list
646 (define-key mail-mode-map
"\C-c\C-t" 'mail-text
)
647 (define-key mail-mode-map
"\C-c\C-y" 'mail-yank-original
)
648 (define-key mail-mode-map
"\C-c\C-r" 'mail-yank-region
)
649 (define-key mail-mode-map
[remap split-line
] 'mail-split-line
)
650 (define-key mail-mode-map
"\C-c\C-q" 'mail-fill-yanked-message
)
651 (define-key mail-mode-map
"\C-c\C-w" 'mail-signature
)
652 (define-key mail-mode-map
"\C-c\C-v" 'mail-sent-via
)
653 (define-key mail-mode-map
"\C-c\C-c" 'mail-send-and-exit
)
654 (define-key mail-mode-map
"\C-c\C-s" 'mail-send
)
655 (define-key mail-mode-map
"\C-c\C-i" 'mail-attach-file
))
657 (define-key mail-mode-map
[menu-bar mail
]
658 (cons "Mail" (make-sparse-keymap "Mail")))
660 (define-key mail-mode-map
[menu-bar mail fill
]
661 '("Fill Citation" . mail-fill-yanked-message
))
663 (define-key mail-mode-map
[menu-bar mail yank
]
664 '("Cite Original" . mail-yank-original
))
666 (define-key mail-mode-map
[menu-bar mail signature
]
667 '("Insert Signature" . mail-signature
))
669 (define-key mail-mode-map
[menu-bar mail mail-sep
]
672 (define-key mail-mode-map
[menu-bar mail cancel
]
673 '("Cancel" . mail-dont-send
))
675 (define-key mail-mode-map
[menu-bar mail send-stay
]
676 '("Send, Keep Editing" . mail-send
))
678 (define-key mail-mode-map
[menu-bar mail send
]
679 '("Send Message" . mail-send-and-exit
))
681 (define-key mail-mode-map
[menu-bar headers
]
682 (cons "Headers" (make-sparse-keymap "Move to Header")))
684 (define-key mail-mode-map
[menu-bar headers text
]
685 '("Text" . mail-text
))
687 (define-key mail-mode-map
[menu-bar headers expand-aliases
]
688 '("Expand Aliases" . expand-mail-aliases
))
690 (define-key mail-mode-map
[menu-bar headers sent-via
]
691 '("Sent Via" . mail-sent-via
))
693 (define-key mail-mode-map
[menu-bar headers mail-reply-to
]
694 '("Mail Reply To" . mail-mail-reply-to
))
696 (define-key mail-mode-map
[menu-bar headers mail-followup-to
]
697 '("Mail Followup To" . mail-mail-followup-to
))
699 (define-key mail-mode-map
[menu-bar headers reply-to
]
700 '("Reply-To" . mail-reply-to
))
702 (define-key mail-mode-map
[menu-bar headers bcc
]
705 (define-key mail-mode-map
[menu-bar headers fcc
]
708 (define-key mail-mode-map
[menu-bar headers cc
]
711 (define-key mail-mode-map
[menu-bar headers subject
]
712 '("Subject" . mail-subject
))
714 (define-key mail-mode-map
[menu-bar headers to
]
717 ;; User-level commands for sending.
719 (defun mail-send-and-exit (&optional arg
)
720 "Send message like `mail-send', then, if no errors, exit from mail buffer.
721 Prefix arg means don't delete this window."
726 (defun mail-dont-send (&optional arg
)
727 "Don't send the message you have been editing.
728 Prefix arg means don't delete this window."
732 (defun mail-bury (&optional arg
)
733 "Bury this mail buffer."
734 (let ((newbuf (other-buffer (current-buffer))))
735 (bury-buffer (current-buffer))
736 (if (and (or (window-dedicated-p (frame-selected-window))
737 (cdr (assq 'mail-dedicated-frame
(frame-parameters))))
738 (not (null (delq (selected-frame) (visible-frame-list)))))
740 (if (display-multi-frame-p)
741 (delete-frame (selected-frame))
742 ;; The previous frame is where normally they have the
743 ;; RMAIL buffer displayed.
745 (let (rmail-flag summary-buffer
)
749 (set-buffer (window-buffer (next-window (selected-window) 'not
)))
750 (setq rmail-flag
(eq major-mode
'rmail-mode
))
752 (and mail-bury-selects-summary
753 (boundp 'rmail-summary-buffer
)
755 (buffer-name rmail-summary-buffer
)
756 (not (get-buffer-window rmail-summary-buffer
))
757 rmail-summary-buffer
))))
759 ;; If the Rmail buffer has a summary, show that.
760 (if summary-buffer
(switch-to-buffer summary-buffer
)
762 (switch-to-buffer newbuf
))))))
764 (defcustom mail-send-hook nil
765 "Hook run just before sending mail with `mail-send'."
767 :options
'(flyspell-mode-off)
771 (defcustom mail-mailing-lists nil
"\
772 *List of mailing list addresses the user is subscribed to.
774 The variable is used to trigger insertion of the \"Mail-Followup-To\"
775 header when sending a message to a mailing list."
776 :type
'(repeat string
)
781 "Send the message in the current buffer.
782 If `mail-interactive' is non-nil, wait for success indication
783 or error messages, and inform user.
784 Otherwise any failure is reported in a message back to
785 the user from the mailer."
787 (if (if buffer-file-name
788 (y-or-n-p "Send buffer contents as mail message? ")
789 (or (buffer-modified-p)
790 (y-or-n-p "Message already sent; resend? ")))
791 (let ((inhibit-read-only t
)
793 (ml (when mail-mailing-lists
794 ;; The surrounding regexp assumes the use of
795 ;; `mail-strip-quoted-names' on addresses before matching
796 ;; Cannot deal with full RFC 822 freedom, but that is
797 ;; unlikely to be problematic.
798 (concat "\\(?:[[:space:];,]\\|\\`\\)"
799 (regexp-opt mail-mailing-lists t
)
800 "\\(?:[[:space:];,]\\|\\'\\)"))))
801 ;; If there are mailing lists defined
804 (let* ((to (mail-fetch-field "to" nil t
))
805 (cc (mail-fetch-field "cc" nil t
))
806 (new-header-values ; To: and Cc:
807 (mail-strip-quoted-names
808 (concat to
(when cc
(concat ", " cc
))))))
809 ;; If message goes to known mailing list ...
810 (when (string-match ml new-header-values
)
811 ;; Add Mail-Followup-To if none yet
812 (unless (mail-fetch-field "mail-followup-to")
813 (goto-char (mail-header-end))
814 (insert "Mail-Followup-To: "
821 (split-string new-header-values
823 (mapconcat 'identity l
", "))
825 ;; Add Mail-Reply-To if none yet
826 (unless (mail-fetch-field "mail-reply-to")
827 (goto-char (mail-header-end))
828 (insert "Mail-Reply-To: "
829 (or (mail-fetch-field "reply-to")
832 (unless (memq mail-send-nonascii
'(t mime
))
833 (goto-char (point-min))
834 (skip-chars-forward "\0-\177")
835 (or (= (point) (point-max))
836 (if (eq mail-send-nonascii
'query
)
837 (or (y-or-n-p "Message contains non-ASCII characters; send anyway? ")
839 (error "Message contains non-ASCII characters"))))
840 ;; Complain about any invalid line.
841 (goto-char (point-min))
842 (while (< (point) (mail-header-end))
843 (unless (looking-at "[ \t]\\|.*:\\|$")
845 (error "Invalid header line (maybe a continuation line lacks initial whitespace)"))
848 (run-hooks 'mail-send-hook
)
849 (message "Sending...")
850 (funcall send-mail-function
)
851 ;; Now perform actions on successful sending.
852 (while mail-send-actions
854 (apply (car (car mail-send-actions
))
855 (cdr (car mail-send-actions
)))
857 (setq mail-send-actions
(cdr mail-send-actions
)))
858 (message "Sending...done")
859 ;; If buffer has no file, mark it as unmodified and delete auto-save.
860 (if (not buffer-file-name
)
862 (set-buffer-modified-p nil
)
863 (delete-auto-save-file-if-necessary t
))))))
865 (defun mail-envelope-from ()
866 "Return the envelope mail address to use when sending mail.
867 This function uses `mail-envelope-from'."
868 (if (eq mail-envelope-from
'header
)
869 (nth 1 (mail-extract-address-components
870 (mail-fetch-field "From")))
873 ;; This does the real work of sending a message via sendmail.
874 ;; It is called via the variable send-mail-function.
877 (defvar sendmail-coding-system nil
878 "*Coding system for encoding the outgoing mail.
879 This has higher priority than `default-buffer-file-coding-system'
880 and `default-sendmail-coding-system',
881 but lower priority than the local value of `buffer-file-coding-system'.
882 See also the function `select-message-coding-system'.")
885 (defvar default-sendmail-coding-system
'iso-latin-1
886 "Default coding system for encoding the outgoing mail.
887 This variable is used only when `sendmail-coding-system' is nil.
889 This variable is set/changed by the command set-language-environment.
890 User should not set this variable manually,
891 instead use sendmail-coding-system to get a constant encoding
892 of outgoing mails regardless of the current language environment.
893 See also the function `select-message-coding-system'.")
895 (defun mail-insert-from-field ()
896 (let* ((login user-mail-address
)
897 (fullname (user-full-name))
898 (quote-fullname nil
))
899 (if (string-match "[^\0-\177]" fullname
)
900 (setq fullname
(rfc2047-encode-string fullname
)
902 (cond ((eq mail-from-style
'angles
)
903 (insert "From: " fullname
)
904 (let ((fullname-start (+ (point-min) 6))
905 (fullname-end (point-marker)))
906 (goto-char fullname-start
)
907 ;; Look for a character that cannot appear unquoted
908 ;; according to RFC 822.
909 (if (or (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]"
913 ;; Quote fullname, escaping specials.
914 (goto-char fullname-start
)
916 (while (re-search-forward "[\"\\]"
918 (replace-match "\\\\\\&" t
))
920 (insert " <" login
">\n"))
921 ((eq mail-from-style
'parens
)
922 (insert "From: " login
" (")
923 (let ((fullname-start (point)))
929 (let ((fullname-end (point-marker)))
930 (goto-char fullname-start
)
931 ;; RFC 822 says \ and nonmatching parentheses
932 ;; must be escaped in comments.
933 ;; Escape every instance of ()\ ...
934 (while (re-search-forward "[()\\]" fullname-end
1)
935 (replace-match "\\\\\\&" t
))
936 ;; ... then undo escaping of matching parentheses,
937 ;; including matching nested parentheses.
938 (goto-char fullname-start
)
939 (while (re-search-forward
940 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
942 (replace-match "\\1(\\3)" t
)
943 (goto-char fullname-start
))))
945 ((null mail-from-style
)
946 (insert "From: " login
"\n"))
947 ((eq mail-from-style
'system-default
)
949 (t (error "Invalid value for `mail-from-style'")))))
951 (defun sendmail-send-it ()
952 "Send the current mail buffer using the Sendmail package.
953 This is a suitable value for `send-mail-function'. It sends using the
954 external program defined by `sendmail-program'."
955 (require 'mail-utils
)
956 (let ((errbuf (if mail-interactive
957 (generate-new-buffer " sendmail errors")
959 (tembuf (generate-new-buffer " sendmail temp"))
960 (multibyte enable-multibyte-characters
)
961 (case-fold-search nil
)
962 (selected-coding (select-message-coding-system))
966 (mailbuf (current-buffer))
967 (program (if (boundp 'sendmail-program
)
969 "/usr/lib/sendmail"))
970 ;; Examine these variables now, so that
971 ;; local binding in the mail buffer will take effect.
973 (and mail-specify-envelope-from
974 (or (mail-envelope-from) user-mail-address
))))
980 (set-buffer-multibyte nil
))
981 (insert-buffer-substring mailbuf
)
982 (goto-char (point-max))
983 ;; require one newline at the end.
984 (or (= (preceding-char) ?
\n)
986 ;; Change header-delimiter to be what sendmail expects.
987 (goto-char (mail-header-end))
988 (delete-region (point) (progn (end-of-line) (point)))
989 (setq delimline
(point-marker))
990 (sendmail-sync-aliases)
992 (expand-mail-aliases (point-min) delimline
))
993 (goto-char (point-min))
994 ;; Ignore any blank lines in the header
995 (while (and (re-search-forward "\n\n\n*" delimline t
)
996 (< (point) delimline
))
997 (replace-match "\n"))
998 (goto-char (point-min))
999 ;; Look for Resent- headers. They require sending
1000 ;; the message specially.
1001 (let ((case-fold-search t
))
1002 (goto-char (point-min))
1003 (while (re-search-forward "^Resent-\\(to\\|cc\\|bcc\\):" delimline t
)
1004 ;; Put a list of such addresses in resend-to-addresses.
1005 (setq resend-to-addresses
1007 (narrow-to-region (point)
1010 (while (looking-at "^[ \t]")
1013 (append (mail-parse-comma-list)
1014 resend-to-addresses
)))
1015 ;; Delete Resent-BCC ourselves
1016 (if (save-excursion (beginning-of-line)
1017 (looking-at "resent-bcc"))
1018 (delete-region (save-excursion (beginning-of-line) (point))
1019 (save-excursion (end-of-line) (1+ (point))))))
1020 ;;; Apparently this causes a duplicate Sender.
1021 ;;; ;; If the From is different than current user, insert Sender.
1022 ;;; (goto-char (point-min))
1023 ;;; (and (re-search-forward "^From:" delimline t)
1025 ;;; (require 'mail-utils)
1026 ;;; (not (string-equal
1027 ;;; (mail-strip-quoted-names
1028 ;;; (save-restriction
1029 ;;; (narrow-to-region (point-min) delimline)
1030 ;;; (mail-fetch-field "From")))
1031 ;;; (user-login-name))))
1033 ;;; (forward-line 1)
1034 ;;; (insert "Sender: " (user-login-name) "\n")))
1035 ;; Don't send out a blank subject line
1036 (goto-char (point-min))
1037 (if (re-search-forward "^Subject:\\([ \t]*\n\\)+\\b" delimline t
)
1039 ;; This one matches a Subject just before the header delimiter.
1040 (if (and (re-search-forward "^Subject:\\([ \t]*\n\\)+" delimline t
)
1041 (= (match-end 0) delimline
))
1042 (replace-match "")))
1043 ;; Put the "From:" field in unless for some odd reason
1044 ;; they put one in themselves.
1045 (goto-char (point-min))
1046 (if (not (re-search-forward "^From:" delimline t
))
1047 (mail-insert-from-field))
1048 ;; Possibly add a MIME header for the current coding system
1050 (goto-char (point-min))
1051 (and (eq mail-send-nonascii
'mime
)
1052 (not (re-search-forward "^MIME-version:" delimline t
))
1053 (progn (skip-chars-forward "\0-\177")
1054 (/= (point) (point-max)))
1057 (coding-system-get selected-coding
'mime-charset
))
1058 (goto-char delimline
)
1059 (insert "MIME-version: 1.0\n"
1060 "Content-type: text/plain; charset="
1061 (symbol-name charset
) "\n"
1062 "Content-Transfer-Encoding: 8bit\n")))
1063 ;; Insert an extra newline if we need it to work around
1064 ;; Sun's bug that swallows newlines.
1065 (goto-char (1+ delimline
))
1066 (if (eval mail-mailer-swallows-blank-line
)
1068 ;; Find and handle any FCC fields.
1069 (goto-char (point-min))
1070 (if (re-search-forward "^FCC:" delimline t
)
1072 (setq fcc-was-found t
)
1073 (mail-do-fcc delimline
)))
1074 (if mail-interactive
1078 (goto-char (point-min))
1079 (if (let ((case-fold-search t
))
1080 (or resend-to-addresses
1081 (re-search-forward "^To:\\|^cc:\\|^bcc:"
1083 (let* ((default-directory "/")
1084 (coding-system-for-write selected-coding
)
1086 (append (list (point-min) (point-max)
1088 nil errbuf nil
"-oi")
1090 (list "-f" envelope-from
))
1091 ;;; ;; Don't say "from root" if running under su.
1092 ;;; (and (equal (user-real-login-name) "root")
1093 ;;; (list "-f" (user-login-name)))
1094 (and mail-alias-file
1095 (list (concat "-oA" mail-alias-file
)))
1096 (if mail-interactive
1097 ;; These mean "report errors to terminal"
1098 ;; and "deliver interactively"
1100 ;; These mean "report errors by mail"
1101 ;; and "deliver in background".
1103 ;; Get the addresses from the message
1104 ;; unless this is a resend.
1105 ;; We must not do that for a resend
1106 ;; because we would find the original addresses.
1107 ;; For a resend, include the specific addresses.
1108 (or resend-to-addresses
1112 (list "-N" (mapconcat 'symbol-name
1116 (exit-value (apply 'call-process-region args
)))
1117 (or (null exit-value
) (eq 0 exit-value
)
1118 (error "Sending...failed with exit value %d" exit-value
)))
1120 (error "No recipients")))
1121 (if mail-interactive
1124 (goto-char (point-min))
1125 (while (re-search-forward "\n\n* *" nil t
)
1126 (replace-match "; "))
1127 (if (not (zerop (buffer-size)))
1128 (error "Sending...failed to %s"
1129 (buffer-substring (point-min) (point-max)))))))
1130 (kill-buffer tembuf
)
1131 (if (bufferp errbuf
)
1132 (kill-buffer errbuf
)))))
1134 (defun mail-do-fcc (header-end)
1136 (rmailbuf (current-buffer))
1137 (time (current-time))
1138 (tembuf (generate-new-buffer " rmail output"))
1139 (case-fold-search t
))
1140 (unless (markerp header-end
)
1141 (error "Value of `header-end' must be a marker"))
1143 (goto-char (point-min))
1144 (while (re-search-forward "^FCC:[ \t]*" header-end t
)
1145 (setq fcc-list
(cons (buffer-substring (point)
1148 (skip-chars-backward " \t")
1151 (delete-region (match-beginning 0)
1152 (progn (forward-line 1) (point))))
1155 ;; This initial newline is written out if the fcc file already exists.
1156 (insert "\nFrom " (user-login-name) " "
1157 (current-time-string time
) "\n")
1158 ;; Insert the time zone before the year.
1161 (require 'mail-utils
)
1162 (insert (mail-rfc822-time-zone time
) " ")
1163 (goto-char (point-max))
1164 (insert-buffer-substring rmailbuf
)
1165 ;; Make sure messages are separated.
1166 (goto-char (point-max))
1169 ;; ``Quote'' "^From " as ">From "
1170 ;; (note that this isn't really quoting, as there is no requirement
1171 ;; that "^[>]+From " be quoted in the same transparent way.)
1172 (let ((case-fold-search nil
))
1173 (while (search-forward "\nFrom " nil t
)
1177 (let* ((buffer (find-buffer-visiting (car fcc-list
)))
1178 (curbuf (current-buffer))
1181 (beg (point-min)) (end (point-max))
1182 (beg2 (save-excursion (goto-char (point-min))
1183 (forward-line 2) (point))))
1185 ;; File is present in a buffer => append to that buffer.
1188 (setq buffer-matches-file
1189 (and (not (buffer-modified-p))
1190 (verify-visited-file-modtime buffer
)))
1191 ;; Keep the end of the accessible portion at the same place
1192 ;; unless it is the end of the buffer.
1193 (let ((max (if (/= (1+ (buffer-size)) (point-max))
1196 ;; Code below lifted from rmailout.el
1197 ;; function rmail-output-to-rmail-file:
1198 (let ((buffer-read-only nil
)
1199 (msg (and (boundp 'rmail-current-message
)
1200 rmail-current-message
)))
1201 ;; If MSG is non-nil, buffer is in RMAIL mode.
1204 ;; Append to an ordinary buffer as a
1205 ;; Unix mail message.
1206 (rmail-maybe-set-message-counters)
1208 (narrow-to-region (point-max) (point-max))
1209 (insert "\C-l\n0, unseen,,\n*** EOOH ***\n"
1210 "Date: " (mail-rfc822-date) "\n")
1211 (insert-buffer-substring curbuf beg2 end
)
1213 (goto-char (point-min))
1215 (search-backward "\n\^_")
1216 (narrow-to-region (point) (point-max))
1217 (rmail-count-new-messages t
)
1218 (rmail-show-message msg
)
1220 ;; Output file not in rmail mode
1221 ;; => just insert at the end.
1222 (narrow-to-region (point-min) (1+ (buffer-size)))
1223 (goto-char (point-max))
1224 (insert-buffer-substring curbuf beg end
))
1225 (or buffer-matches-file
1227 (if (y-or-n-p (format "Save file %s? "
1230 (setq dont-write-the-file t
))))
1231 (if max
(narrow-to-region (point-min) max
))))))
1232 ;; Append to the file directly,
1233 ;; unless we've already taken care of it.
1234 (unless dont-write-the-file
1235 (if (and (file-exists-p (car fcc-list
))
1236 ;; Check that the file isn't empty. We don't
1237 ;; want to insert a newline at the start of an
1239 (not (zerop (nth 7 (file-attributes (car fcc-list
)))))
1240 (mail-file-babyl-p (car fcc-list
)))
1241 ;; If the file is a Babyl file,
1242 ;; convert the message to Babyl format.
1243 (let ((coding-system-for-write
1244 (or rmail-file-coding-system
1247 (set-buffer (get-buffer-create " mail-temp"))
1248 (setq buffer-read-only nil
)
1250 (insert "\C-l\n0, unseen,,\n*** EOOH ***\n"
1251 "Date: " (mail-rfc822-date) "\n")
1252 (insert-buffer-substring curbuf beg2 end
)
1254 (write-region (point-min) (point-max) (car fcc-list
) t
)
1257 (1+ (point-min)) (point-max) (car fcc-list
) t
)))
1258 (and buffer
(not dont-write-the-file
)
1259 (with-current-buffer buffer
1260 (set-visited-file-modtime))))
1261 (setq fcc-list
(cdr fcc-list
))))
1262 (kill-buffer tembuf
)))
1264 (defun mail-sent-via ()
1265 "Make a Sent-via header line from each To or CC header line."
1268 ;; put a marker at the end of the header
1269 (let ((end (copy-marker (mail-header-end)))
1270 (case-fold-search t
)
1272 (goto-char (point-min))
1273 ;; search for the To: lines and make Sent-via: lines from them
1274 ;; search for the next To: line
1275 (while (re-search-forward "^\\(to\\|cc\\):" end t
)
1276 ;; Grab this line plus all its continuations, sans the `to:'.
1278 (buffer-substring (point)
1280 (if (re-search-forward "^[^ \t\n]" end t
)
1284 ;; Insert a copy, with altered header field name.
1285 (insert-before-markers "Sent-via:" to-line
))))))
1288 "Move point to end of To-field."
1291 (mail-position-on-field "To"))
1293 (defun mail-subject ()
1294 "Move point to end of Subject-field."
1297 (mail-position-on-field "Subject"))
1300 "Move point to end of CC-field. Create a CC field if none."
1303 (or (mail-position-on-field "cc" t
)
1304 (progn (mail-position-on-field "to")
1305 (insert "\nCC: "))))
1308 "Move point to end of BCC-field. Create a BCC field if none."
1311 (or (mail-position-on-field "bcc" t
)
1312 (progn (mail-position-on-field "to")
1313 (insert "\nBCC: "))))
1315 (defun mail-fcc (folder)
1316 "Add a new FCC field, with file name completion."
1317 (interactive "FFolder carbon copy: ")
1319 (or (mail-position-on-field "fcc" t
) ;Put new field after exiting FCC.
1320 (mail-position-on-field "to"))
1321 (insert "\nFCC: " folder
))
1323 (defun mail-reply-to ()
1324 "Move point to end of Reply-To-field. Create a Reply-To field if none."
1327 (mail-position-on-field "Reply-To"))
1329 (defun mail-mail-reply-to ()
1330 "Move point to end of Mail-Reply-To field.
1331 Create a Mail-Reply-To field if none."
1334 (or (mail-position-on-field "mail-reply-to" t
)
1335 (progn (mail-position-on-field "to")
1336 (insert "\nMail-Reply-To: "))))
1338 (defun mail-mail-followup-to ()
1339 "Move point to end of Mail-Followup-To field.
1340 Create a Mail-Followup-To field if none."
1343 (or (mail-position-on-field "mail-followup-to" t
)
1344 (progn (mail-position-on-field "to")
1345 (insert "\nMail-Followup-To: "))))
1347 (defun mail-position-on-field (field &optional soft
)
1349 (case-fold-search t
))
1350 (setq end
(mail-header-end))
1351 (goto-char (point-min))
1352 (if (re-search-forward (concat "^" (regexp-quote field
) ":") end t
)
1354 (re-search-forward "^[^ \t]" nil
'move
)
1356 (skip-chars-backward "\n")
1359 (progn (goto-char end
)
1360 (insert field
": \n")
1361 (skip-chars-backward "\n")))
1365 "Move point to beginning of message text."
1368 (goto-char (mail-text-start)))
1370 (defun mail-signature (&optional atpoint
)
1371 "Sign letter with signature based on `mail-signature-file'.
1372 Prefix arg means put contents at point."
1376 (goto-char (point-max)))
1377 (skip-chars-backward " \t\n")
1380 (delete-region (point) (point-max)))
1381 (if (stringp mail-signature
)
1382 (insert mail-signature
)
1383 (insert "\n\n-- \n")
1384 (insert-file-contents (expand-file-name mail-signature-file
)))))
1386 (defun mail-fill-yanked-message (&optional justifyp
)
1387 "Fill the paragraphs of a message yanked into this one.
1388 Numeric argument means justify as well."
1391 (goto-char (mail-text-start))
1392 (fill-individual-paragraphs (point)
1395 mail-citation-prefix-regexp
)))
1397 (defun mail-indent-citation ()
1398 "Modify text just inserted from a message to be cited.
1399 The inserted text should be the region.
1400 When this function returns, the region is again around the modified text.
1402 Normally, indent each nonblank line `mail-indentation-spaces' spaces.
1403 However, if `mail-yank-prefix' is non-nil, insert that prefix on each line."
1404 (mail-yank-clear-headers (region-beginning) (region-end))
1405 (if (null mail-yank-prefix
)
1406 (indent-rigidly (region-beginning) (region-end)
1407 mail-indentation-spaces
)
1409 (let ((end (set-marker (make-marker) (region-end))))
1410 (goto-char (region-beginning))
1411 (while (< (point) end
)
1412 (insert mail-yank-prefix
)
1413 (forward-line 1))))))
1415 (defun mail-yank-original (arg)
1416 "Insert the message being replied to, if any (in rmail).
1417 Puts point after the text and mark before.
1418 Normally, indents each nonblank line ARG spaces (default 3).
1419 However, if `mail-yank-prefix' is non-nil, insert that prefix on each line.
1421 Just \\[universal-argument] as argument means don't indent, insert no prefix,
1422 and don't delete any header fields."
1424 (if mail-reply-action
1425 (let ((start (point))
1426 (original mail-reply-action
))
1427 (and (consp original
) (eq (car original
) 'insert-buffer
)
1428 (setq original
(nth 1 original
)))
1429 (if (consp original
)
1430 (apply (car original
) (cdr original
))
1431 ;; If the original message is in another window in the same frame,
1432 ;; delete that window to save screen space.
1433 ;; t means don't alter other frames.
1434 (delete-windows-on original t
)
1436 ;; We really want this to set mark.
1437 (insert-buffer original
))
1438 (set-text-properties (point) (mark t
) nil
))
1442 (let ((mail-indentation-spaces (if arg
(prefix-numeric-value arg
)
1443 mail-indentation-spaces
))
1444 ;; Avoid error in Transient Mark mode
1445 ;; on account of mark's being inactive.
1446 (mark-even-if-inactive t
))
1447 (cond (mail-citation-hook
1448 ;; Bind mail-citation-header to the inserted
1449 ;; message's header.
1450 (let ((mail-citation-header
1451 (buffer-substring-no-properties
1455 (narrow-to-region start
(point-max))
1459 (run-hooks 'mail-citation-hook
)))
1461 (run-hooks 'mail-yank-hooks
))
1463 (mail-indent-citation)))))
1464 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
1465 ;; It is cleaner to avoid activation, even though the command
1466 ;; loop would deactivate the mark because we inserted text.
1467 (goto-char (prog1 (mark t
)
1468 (set-marker (mark-marker) (point) (current-buffer))))
1469 (if (not (eolp)) (insert ?
\n)))))
1471 (defun mail-yank-clear-headers (start end
)
1474 (setq temp start start end end temp
)))
1475 (if mail-yank-ignored-headers
1478 (if (search-forward "\n\n" end t
)
1480 (narrow-to-region start
(point))
1482 (while (let ((case-fold-search t
))
1483 (re-search-forward mail-yank-ignored-headers nil t
))
1485 (delete-region (point)
1486 (progn (re-search-forward "\n[^ \t]")
1490 (defun mail-yank-region (arg)
1491 "Insert the selected region from the message being replied to.
1492 Puts point after the text and mark before.
1493 Normally, indents each nonblank line ARG spaces (default 3).
1494 However, if `mail-yank-prefix' is non-nil, insert that prefix on each line.
1496 Just \\[universal-argument] as argument means don't indent, insert no prefix,
1497 and don't delete any header fields."
1499 (and (consp mail-reply-action
)
1500 (eq (car mail-reply-action
) 'insert-buffer
)
1501 (with-current-buffer (nth 1 mail-reply-action
)
1503 (error "No mark set: %S" (current-buffer))))
1504 (let ((buffer (nth 1 mail-reply-action
))
1506 ;; Avoid error in Transient Mark mode
1507 ;; on account of mark's being inactive.
1508 (mark-even-if-inactive t
))
1509 ;; Insert the citation text.
1510 (insert (with-current-buffer buffer
1511 (buffer-substring-no-properties (point) (mark))))
1513 ;; Indent or otherwise annotate the citation text.
1516 (let ((mail-indentation-spaces (if arg
(prefix-numeric-value arg
)
1517 mail-indentation-spaces
)))
1518 (if mail-citation-hook
1519 ;; Bind mail-citation-hook to the original message's header.
1520 (let ((mail-citation-header
1521 (with-current-buffer buffer
1522 (buffer-substring-no-properties
1525 (goto-char (point-min))
1528 (run-hooks 'mail-citation-hook
))
1530 (run-hooks 'mail-yank-hooks
)
1531 (mail-indent-citation))))))))
1533 (defun mail-split-line ()
1534 "Split current line, moving portion beyond point vertically down.
1535 If the current line has `mail-yank-prefix', insert it on the new line."
1537 (split-line mail-yank-prefix
))
1540 (defun mail-attach-file (&optional file
)
1541 "Insert a file at the end of the buffer, with separator lines around it."
1542 (interactive "fAttach file: ")
1544 (goto-char (point-max))
1545 (or (bolp) (newline))
1547 (let ((start (point))
1549 (insert (format "===File %s===" file
))
1550 (insert-char ?
= (max 0 (- 60 (current-column))))
1552 (setq middle
(point))
1553 (insert "============================================================\n")
1556 (insert-file-contents file
)
1557 (or (bolp) (newline))
1558 (goto-char start
))))
1560 ;; Put these commands last, to reduce chance of lossage from quitting
1561 ;; in middle of loading the file.
1563 ;;;###autoload (add-hook 'same-window-buffer-names "*mail*")
1566 (defun mail (&optional noerase to subject in-reply-to cc replybuffer actions
)
1567 "Edit a message to be sent. Prefix arg means resume editing (don't erase).
1568 When this function returns, the buffer `*mail*' is selected.
1569 The value is t if the message was newly initialized; otherwise, nil.
1571 Optionally, the signature file `mail-signature-file' can be inserted at the
1572 end; see the variable `mail-signature'.
1575 While editing message, type \\[mail-send-and-exit] to send the message and exit.
1577 Various special commands starting with C-c are available in sendmail mode
1578 to move to message header fields:
1581 If `mail-self-blind' is non-nil, a BCC to yourself is inserted
1582 when the message is initialized.
1584 If `mail-default-reply-to' is non-nil, it should be an address (a string);
1585 a Reply-to: field with that address is inserted.
1587 If `mail-archive-file-name' is non-nil, an FCC field with that file name
1590 The normal hook `mail-setup-hook' is run after the message is
1591 initialized. It can add more default fields to the message.
1593 When calling from a program, the first argument if non-nil says
1594 not to erase the existing contents of the `*mail*' buffer.
1596 The second through fifth arguments,
1597 TO, SUBJECT, IN-REPLY-TO and CC, specify if non-nil
1598 the initial contents of those header fields.
1599 These arguments should not have final newlines.
1600 The sixth argument REPLYBUFFER is a buffer which contains an
1601 original message being replied to, or else an action
1602 of the form (FUNCTION . ARGS) which says how to insert the original.
1603 Or it can be nil, if not replying to anything.
1604 The seventh argument ACTIONS is a list of actions to take
1605 if/when the message is sent. Each action looks like (FUNCTION . ARGS);
1606 when the message is sent, we apply FUNCTION to ARGS.
1607 This is how Rmail arranges to mark messages `answered'."
1609 ;;; This is commented out because I found it was confusing in practice.
1610 ;;; It is easy enough to rename *mail* by hand with rename-buffer
1611 ;;; if you want to have multiple mail buffers.
1612 ;;; And then you can control which messages to save. --rms.
1615 ;;; ;; If requested, look for a mail buffer that is modified and go to it.
1618 ;;; (while (and (setq buffer
1619 ;;; (get-buffer (if (= 1 index) "*mail*"
1620 ;;; (format "*mail*<%d>" index))))
1621 ;;; (not (buffer-modified-p buffer)))
1622 ;;; (setq index (1+ index)))
1623 ;;; (if buffer (switch-to-buffer buffer)
1624 ;;; ;; If none exists, start a new message.
1625 ;;; ;; This will never re-use an existing unmodified mail buffer
1626 ;;; ;; (since index is not 1 anymore). Perhaps it should.
1627 ;;; (setq noerase nil))))
1628 ;;; ;; Unless we found a modified message and are happy, start a new message.
1629 ;;; (if (not noerase)
1631 ;;; ;; Look for existing unmodified mail buffer.
1632 ;;; (while (and (setq buffer
1633 ;;; (get-buffer (if (= 1 index) "*mail*"
1634 ;;; (format "*mail*<%d>" index))))
1635 ;;; (buffer-modified-p buffer))
1636 ;;; (setq index (1+ index)))
1637 ;;; ;; If none, make a new one.
1639 ;;; (setq buffer (generate-new-buffer "*mail*")))
1640 ;;; ;; Go there and initialize it.
1641 ;;; (switch-to-buffer buffer)
1643 ;;; (setq default-directory (expand-file-name "~/"))
1644 ;;; (auto-save-mode auto-save-default)
1646 ;;; (mail-setup to subject in-reply-to cc replybuffer actions)
1647 ;;; (if (and buffer-auto-save-file-name
1648 ;;; (file-exists-p buffer-auto-save-file-name))
1649 ;;; (message "Auto save file for draft message exists; consider M-x mail-recover"))
1651 (pop-to-buffer "*mail*")
1652 ;; Avoid danger that the auto-save file can't be written.
1653 (let ((dir (expand-file-name
1654 (file-name-as-directory mail-default-directory
))))
1655 (if (file-exists-p dir
)
1656 (setq default-directory dir
)))
1657 ;; Only call auto-save-mode if necessary, to avoid changing auto-save file.
1658 (if (or (and auto-save-default
(not buffer-auto-save-file-name
))
1659 (and (not auto-save-default
) buffer-auto-save-file-name
))
1660 (auto-save-mode auto-save-default
))
1662 ;; Disconnect the buffer from its visited file
1663 ;; (in case the user has actually visited a file *mail*).
1664 ; (set-visited-file-name nil)
1667 (if buffer-file-name
1668 (if (buffer-modified-p)
1669 (when (y-or-n-p "Buffer has unsaved changes; reinitialize it and discard them? ")
1670 (if (y-or-n-p "Disconnect buffer from visited file? ")
1671 (set-visited-file-name nil
))
1673 (when (y-or-n-p "Reinitialize buffer, and disconnect it from the visited file? ")
1674 (set-visited-file-name nil
)
1676 ;; A non-file-visiting buffer.
1677 (if (buffer-modified-p)
1678 (y-or-n-p "Unsent message being composed; erase it? ")
1680 (let ((inhibit-read-only t
))
1682 (mail-setup to subject in-reply-to cc replybuffer actions
)
1683 (setq initialized t
)))
1684 (if (and buffer-auto-save-file-name
1685 (file-exists-p buffer-auto-save-file-name
))
1686 (message "Auto save file for draft message exists; consider M-x mail-recover"))
1689 (defun mail-recover-1 ()
1690 "Pop up a list of auto-saved draft messages so you can recover one of them."
1692 (let ((file-name (make-auto-save-file-name))
1693 (ls-lisp-support-shell-wildcards t
)
1694 non-random-len wildcard
)
1695 ;; Remove the random part from the auto-save-file-name, and
1696 ;; create a wildcard which matches possible candidates.
1697 ;; Note: this knows that make-auto-save-file-name appends
1698 ;; "#<RANDOM-STUFF>#" to the buffer name, where RANDOM-STUFF
1699 ;; is the result of (make-temp-name "").
1700 (setq non-random-len
1701 (- (length file-name
) (length (make-temp-name "")) 1))
1702 (setq wildcard
(concat (substring file-name
0 non-random-len
) "*"))
1703 (if (null (file-expand-wildcards wildcard
))
1704 (message "There are no auto-saved drafts to recover")
1705 ;; Bind dired-trivial-filenames to t because all auto-save file
1706 ;; names are normally ``trivial'', so Dired will set point after
1707 ;; all the files, at buffer bottom. We want it on the first
1709 (let ((dired-trivial-filenames t
))
1710 (dired-other-window wildcard
(concat dired-listing-switches
"t")))
1711 (rename-buffer "*Auto-saved Drafts*" t
)
1713 (goto-char (point-min))
1714 (or (looking-at " Move to the draft file you want to recover,")
1715 (let ((inhibit-read-only t
))
1716 ;; Each line starts with a space so that Font Lock mode
1717 ;; won't highlight the first character.
1719 Move to the draft file you want to recover, then type C-c C-c
1720 to recover text of message whose composition was interrupted.
1721 To browse text of a draft, type v on the draft file's line.
1723 You can also delete some of these files;
1724 type d on a line to mark that file for deletion.
1726 List of possible auto-save files for recovery:
1730 (let ((map (make-sparse-keymap)))
1731 (set-keymap-parent map
(current-local-map))
1733 (define-key (current-local-map) "v"
1736 (let ((coding-system-for-read 'emacs-mule-unix
))
1737 (dired-view-file))))
1738 (define-key (current-local-map) "\C-c\C-c"
1741 (let ((fname (dired-get-filename))
1742 ;; Auto-saved files are written in the internal
1743 ;; representation, so they should be read accordingly.
1744 (coding-system-for-read 'emacs-mule-unix
))
1745 (switch-to-buffer-other-window "*mail*")
1746 (let ((buffer-read-only nil
))
1748 (insert-file-contents fname nil
)
1749 ;; insert-file-contents will set buffer-file-coding-system
1750 ;; to emacs-mule, which is probably not what they want to
1751 ;; use for sending the message. But we don't know what
1752 ;; was its value before the buffer was killed or Emacs
1753 ;; crashed. We therefore reset buffer-file-coding-system
1754 ;; to the default value, so that either the default does
1755 ;; TRT, or the user will get prompted for the right
1756 ;; encoding when they send the message.
1757 (setq buffer-file-coding-system
1758 default-buffer-file-coding-system
))))))))
1760 (defun mail-recover ()
1761 "Recover interrupted mail composition from auto-save files.
1763 If the mail buffer has a current valid auto-save file,
1764 the command recovers that file. Otherwise, it displays a
1765 buffer showing the existing auto-saved draft messages;
1766 you can move to one of them and type C-c C-c to recover that one."
1768 ;; In case they invoke us from some random buffer...
1769 (switch-to-buffer "*mail*")
1770 ;; If *mail* didn't exist, set its directory, so that auto-saved
1771 ;; drafts will be found.
1772 (let ((dir (expand-file-name
1773 (file-name-as-directory mail-default-directory
))))
1774 (if (file-exists-p dir
)
1775 (setq default-directory dir
)))
1776 (or (eq major-mode
'mail-mode
)
1778 (let ((file-name buffer-auto-save-file-name
))
1779 (cond ((and file-name
(file-exists-p file-name
))
1781 ;; This used to invoke `ls' via call-process, but
1782 ;; dired-noselect is more portable to systems where
1783 ;; `ls' is not a standard program (it will use
1784 ;; ls-lisp instead).
1785 (dired-noselect file-name
1786 (concat dired-listing-switches
"t"))))
1787 (save-selected-window
1788 (select-window (display-buffer dispbuf t
))
1789 (goto-char (point-min))
1791 (dired-move-to-filename)
1792 (setq dispbuf
(rename-buffer "*Directory*" t
)))
1793 (if (not (yes-or-no-p
1794 (format "Recover mail draft from auto save file %s? "
1796 (error "mail-recover cancelled")
1797 (let ((buffer-read-only nil
)
1798 (buffer-coding buffer-file-coding-system
)
1799 ;; Auto-save files are written in internal
1800 ;; representation of non-ASCII characters.
1801 (coding-system-for-read 'emacs-mule-unix
))
1803 (insert-file-contents file-name nil
)
1804 (setq buffer-file-coding-system buffer-coding
)))))
1805 (t (mail-recover-1)))))
1808 (defun mail-other-window (&optional noerase to subject in-reply-to cc replybuffer sendactions
)
1809 "Like `mail' command, but display mail buffer in another window."
1811 (let ((pop-up-windows t
)
1812 (special-display-buffer-names nil
)
1813 (special-display-regexps nil
)
1814 (same-window-buffer-names nil
)
1815 (same-window-regexps nil
))
1816 (pop-to-buffer "*mail*"))
1817 (mail noerase to subject in-reply-to cc replybuffer sendactions
))
1820 (defun mail-other-frame (&optional noerase to subject in-reply-to cc replybuffer sendactions
)
1821 "Like `mail' command, but display mail buffer in another frame."
1823 (let ((pop-up-frames t
)
1824 (special-display-buffer-names nil
)
1825 (special-display-regexps nil
)
1826 (same-window-buffer-names nil
)
1827 (same-window-regexps nil
))
1828 (pop-to-buffer "*mail*"))
1829 (mail noerase to subject in-reply-to cc replybuffer sendactions
))
1831 ;;; Do not add anything but external entries on this page.
1835 ;;; arch-tag: 48bc1025-d993-4d31-8d81-2a29491f0626
1836 ;;; sendmail.el ends here