Commit | Line | Data |
---|---|---|
f70de9d4 | 1 | ;;; sendmail.el --- mail sending commands for Emacs. -*- byte-compile-dynamic: t -*- |
c88ab9ce | 2 | |
67ad9438 | 3 | ;; Copyright (C) 1985, 86, 92, 93, 94, 95, 96, 98, 2000, 2001 |
a23cf8c2 | 4 | ;; Free Software Foundation, Inc. |
3a801d0c | 5 | |
e5167999 | 6 | ;; Maintainer: FSF |
d7b4d18f | 7 | ;; Keywords: mail |
e5167999 | 8 | |
20a8832d RS |
9 | ;; This file is part of GNU Emacs. |
10 | ||
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 | |
e5167999 | 13 | ;; the Free Software Foundation; either version 2, or (at your option) |
20a8832d RS |
14 | ;; any later version. |
15 | ||
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. | |
20 | ||
21 | ;; You should have received a copy of the GNU General Public License | |
b578f267 EN |
22 | ;; along with GNU Emacs; see the file COPYING. If not, write to the |
23 | ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 | ;; Boston, MA 02111-1307, USA. | |
20a8832d | 25 | |
d9ecc911 ER |
26 | ;;; Commentary: |
27 | ||
28 | ;; This mode provides mail-sending facilities from within Emacs. It is | |
29 | ;; documented in the Emacs user's manual. | |
30 | ||
e5167999 | 31 | ;;; Code: |
be0b8d69 | 32 | (eval-when-compile |
bf61662d GM |
33 | ;; Necessary to avoid recursive `require's. |
34 | (provide 'sendmail) | |
be0b8d69 DL |
35 | (require 'rmail) |
36 | (require 'mailalias)) | |
37 | ||
67ad9438 DL |
38 | (autoload 'rfc2047-encode-string "rfc2047") |
39 | ||
0b5bb3ec SE |
40 | (defgroup sendmail nil |
41 | "Mail sending commands for Emacs." | |
42 | :prefix "mail-" | |
43 | :group 'mail) | |
20a8832d | 44 | |
ea9ceb34 | 45 | ;;;###autoload |
0b5bb3ec | 46 | (defcustom mail-from-style 'angles "\ |
ea9ceb34 KH |
47 | *Specifies how \"From:\" fields look. |
48 | ||
49 | If `nil', they contain just the return address like: | |
50 | king@grassland.com | |
51 | If `parens', they look like: | |
52 | king@grassland.com (Elvis Parsley) | |
53 | If `angles', they look like: | |
cc674186 | 54 | Elvis Parsley <king@grassland.com> |
32afb744 KH |
55 | If `system-default', allows the mailer to insert its default From field |
56 | derived from the envelope-from address. | |
57 | ||
58 | In old versions of Emacs, the `system-default' setting also caused | |
59 | Emacs to pass the proper email address from `user-mail-address' | |
60 | to the mailer to specify the envelope-from address. But that is now | |
61 | controlled by a separate variable, `mail-specify-envelope-from'." | |
9a97e073 RS |
62 | :type '(choice (const nil) (const parens) (const angles) |
63 | (const system-default)) | |
2a42d160 | 64 | :version "20.3" |
0b5bb3ec | 65 | :group 'sendmail) |
ea9ceb34 | 66 | |
32afb744 | 67 | ;;;###autoload |
3d04071d | 68 | (defcustom mail-specify-envelope-from nil |
32afb744 | 69 | "*If non-nil, specify the envelope-from address when sending mail. |
c1a1fd60 GM |
70 | The value used to specify it is whatever is found in |
71 | `mail-envelope-from', with `user-mail-address' as fallback. | |
32afb744 KH |
72 | |
73 | On most systems, specifying the envelope-from address | |
74 | is a privileged operation." | |
75 | :version "21.1" | |
76 | :type 'boolean | |
77 | :group 'sendmail) | |
78 | ||
c1a1fd60 GM |
79 | (defcustom mail-envelope-from nil |
80 | "*If non-nil, designate the envelope-from address when sending mail. | |
81 | If this is nil while `mail-specify-envelope-from' is non-nil, the | |
82 | content of `user-mail-address' is used." | |
83 | :version "21.1" | |
84 | :type 'boolean | |
85 | :group 'sendmail) | |
86 | ||
20a8832d | 87 | ;;;###autoload |
0b5bb3ec | 88 | (defcustom mail-self-blind nil "\ |
9f3e5ddf | 89 | *Non-nil means insert BCC to self in messages to be sent. |
20a8832d | 90 | This is done when the message is initialized, |
0b5bb3ec SE |
91 | so you can remove or alter the BCC field to override the default." |
92 | :type 'boolean | |
93 | :group 'sendmail) | |
20a8832d RS |
94 | |
95 | ;;;###autoload | |
0b5bb3ec | 96 | (defcustom mail-interactive nil "\ |
9f3e5ddf | 97 | *Non-nil means when sending a message wait for and display errors. |
0b5bb3ec SE |
98 | nil means let mailer mail back a message to report errors." |
99 | :type 'boolean | |
100 | :group 'sendmail) | |
20a8832d RS |
101 | |
102 | ;;;###autoload | |
0b5bb3ec SE |
103 | (defcustom mail-yank-ignored-headers "^via:\\|^mail-from:\\|^origin:\\|^status:\\|^remailed\\|^received:\\|^message-id:\\|^summary-line:\\|^to:\\|^subject:\\|^in-reply-to:\\|^return-path:" "\ |
104 | *Delete these headers from old message when it's inserted in a reply." | |
105 | :type 'regexp | |
106 | :group 'sendmail) | |
20a8832d RS |
107 | |
108 | ;; Useful to set in site-init.el | |
109 | ;;;###autoload | |
67ad9438 DL |
110 | (defcustom send-mail-function 'sendmail-send-it |
111 | "Function to call to send the current buffer as mail. | |
51d541d4 | 112 | The headers should be delimited by a line which is |
67ad9438 DL |
113 | not a valid RFC822 header or continuation line. |
114 | This is used by the default mail-sending commands. See also | |
115 | `message-send-mail-function' for use with the Message package." | |
c5dfddb6 DL |
116 | :type '(radio (function-item sendmail-send-it :tag "Use Sendmail package") |
117 | (function-item smtpmail-send-it :tag "Use SMTPmail package") | |
118 | (function-item feedmail-send-it :tag "Use Feedmail package") | |
40fa0008 DL |
119 | function) |
120 | :group 'sendmail) | |
20a8832d RS |
121 | |
122 | ;;;###autoload | |
0b5bb3ec SE |
123 | (defcustom mail-header-separator "--text follows this line--" "\ |
124 | *Line used to separate headers from text in messages being composed." | |
125 | :type 'string | |
126 | :group 'sendmail) | |
20a8832d | 127 | |
6737ae74 RS |
128 | ;; Set up mail-header-separator for use as a category text property. |
129 | (put 'mail-header-separator 'rear-nonsticky '(category)) | |
f869bab8 RS |
130 | ;;; This was a nice idea, for preventing accidental modification of |
131 | ;;; the separator. But I found it also prevented or obstructed | |
132 | ;;; certain deliberate operations, such as copying the separator line | |
133 | ;;; up to the top to send myself a copy of an already sent outgoing message | |
134 | ;;; and other things. So I turned it off. --rms. | |
135 | ;;;(put 'mail-header-separator 'read-only t) | |
6737ae74 | 136 | |
20a8832d | 137 | ;;;###autoload |
0b5bb3ec | 138 | (defcustom mail-archive-file-name nil "\ |
20a8832d | 139 | *Name of file to write all outgoing messages in, or nil for none. |
0b5bb3ec SE |
140 | This can be an inbox file or an Rmail file." |
141 | :type '(choice file (const nil)) | |
142 | :group 'sendmail) | |
20a8832d | 143 | |
fe8c32a6 | 144 | ;;;###autoload |
0b5bb3ec | 145 | (defcustom mail-default-reply-to nil |
6da74aab RS |
146 | "*Address to insert as default Reply-to field of outgoing messages. |
147 | If nil, it will be initialized from the REPLYTO environment variable | |
0b5bb3ec SE |
148 | when you first send mail." |
149 | :type '(choice (const nil) string) | |
150 | :group 'sendmail) | |
20a8832d | 151 | |
a06d7943 | 152 | ;;;###autoload |
0b5bb3ec | 153 | (defcustom mail-alias-file nil |
20a8832d RS |
154 | "*If non-nil, the name of a file to use instead of `/usr/lib/aliases'. |
155 | This file defines aliases to be expanded by the mailer; this is a different | |
156 | feature from that of defining aliases in `.mailrc' to be expanded in Emacs. | |
0b5bb3ec SE |
157 | This variable has no effect unless your system uses sendmail as its mailer." |
158 | :type '(choice (const nil) file) | |
159 | :group 'sendmail) | |
20a8832d | 160 | |
8790b698 | 161 | ;;;###autoload |
0b5bb3ec | 162 | (defcustom mail-personal-alias-file "~/.mailrc" |
8790b698 NF |
163 | "*If non-nil, the name of the user's personal mail alias file. |
164 | This file typically should be in same format as the `.mailrc' file used by | |
165 | the `Mail' or `mailx' program. | |
0b5bb3ec SE |
166 | This file need not actually exist." |
167 | :type '(choice (const nil) file) | |
168 | :group 'sendmail) | |
8790b698 | 169 | |
0b5bb3ec | 170 | (defcustom mail-setup-hook nil |
8b262cbc | 171 | "Normal hook, run each time a new outgoing mail message is initialized. |
0b5bb3ec SE |
172 | The function `mail-setup' runs this hook." |
173 | :type 'hook | |
f70de9d4 | 174 | :options '(fortune-to-signature spook mail-abbrevs-setup) |
0b5bb3ec | 175 | :group 'sendmail) |
8b262cbc | 176 | |
5ef9d627 | 177 | (defvar mail-aliases t |
ade349a0 | 178 | "Alist of mail address aliases, |
de01bf7d RS |
179 | or t meaning should be initialized from your mail aliases file. |
180 | \(The file's name is normally `~/.mailrc', but your MAILRC environment | |
181 | variable can override that name.) | |
182 | The alias definitions in the file have this form: | |
ade349a0 | 183 | alias ALIAS MEANING") |
5ef9d627 | 184 | |
9cc75191 | 185 | (defvar mail-alias-modtime nil |
de01bf7d | 186 | "The modification time of your mail alias file when it was last examined.") |
9cc75191 | 187 | |
0b5bb3ec | 188 | (defcustom mail-yank-prefix nil |
20a8832d | 189 | "*Prefix insert on lines of yanked message being replied to. |
0b5bb3ec SE |
190 | nil means use indentation." |
191 | :type '(choice (const nil) string) | |
192 | :group 'sendmail) | |
193 | ||
194 | (defcustom mail-indentation-spaces 3 | |
1c24b04a | 195 | "*Number of spaces to insert at the beginning of each cited line. |
0b5bb3ec SE |
196 | Used by `mail-yank-original' via `mail-indent-citation'." |
197 | :type 'integer | |
198 | :group 'sendmail) | |
fa24a822 | 199 | (defvar mail-yank-hooks nil |
015c5c55 RS |
200 | "Obsolete hook for modifying a citation just inserted in the mail buffer. |
201 | Each hook function can find the citation between (point) and (mark t). | |
202 | And each hook function should leave point and mark around the citation | |
203 | text as modified. | |
204 | ||
205 | This is a normal hook, misnamed for historical reasons. | |
206 | It is semi-obsolete and mail agents should no longer use it.") | |
207 | ||
0b5bb3ec | 208 | (defcustom mail-citation-hook nil |
1c24b04a | 209 | "*Hook for modifying a citation just inserted in the mail buffer. |
d6bccf09 RS |
210 | Each hook function can find the citation between (point) and (mark t), |
211 | and should leave point and mark around the citation text as modified. | |
212 | The hook functions can find the header of the cited message | |
213 | in the variable `mail-citation-header', whether or not this is included | |
214 | in the cited portion of the message. | |
1c24b04a | 215 | |
015c5c55 | 216 | If this hook is entirely empty (nil), a default action is taken |
0b5bb3ec SE |
217 | instead of no action." |
218 | :type 'hook | |
219 | :group 'sendmail) | |
20a8832d | 220 | |
d6bccf09 RS |
221 | (defvar mail-citation-header nil |
222 | "While running `mail-citation-hook', this variable holds the message header. | |
223 | This enables the hook functions to see the whole message header | |
224 | regardless of what part of it (if any) is included in the cited text.") | |
225 | ||
706e3d85 RS |
226 | (defcustom mail-citation-prefix-regexp "[ \t]*[-a-z0-9A-Z]*>+[ \t]*\\|[ \t]*" |
227 | "*Regular expression to match a citation prefix plus whitespace. | |
228 | It should match whatever sort of citation prefixes you want to handle, | |
229 | with whitespace before and after; it should also match just whitespace. | |
230 | The default value matches citations like `foo-bar>' plus whitespace." | |
231 | :type 'regexp | |
232 | :group 'sendmail | |
233 | :version "20.3") | |
234 | ||
20a8832d RS |
235 | (defvar mail-abbrevs-loaded nil) |
236 | (defvar mail-mode-map nil) | |
237 | ||
5ef9d627 | 238 | (autoload 'build-mail-aliases "mailalias" |
8790b698 | 239 | "Read mail aliases from user's personal aliases file and set `mail-aliases'." |
5ef9d627 RS |
240 | nil) |
241 | ||
242 | (autoload 'expand-mail-aliases "mailalias" | |
243 | "Expand all mail aliases in suitable header fields found between BEG and END. | |
244 | Suitable header fields are `To', `Cc' and `Bcc' and their `Resent-' variants. | |
245 | Optional second arg EXCLUDE may be a regular expression defining text to be | |
246 | removed from alias expansions." | |
247 | nil) | |
248 | ||
ef15f270 | 249 | ;;;###autoload |
0b5bb3ec | 250 | (defcustom mail-signature nil |
547075d4 | 251 | "*Text inserted at end of mail buffer when a message is initialized. |
f13c1dae RS |
252 | If t, it means to insert the contents of the file `mail-signature-file'. |
253 | If a string, that string is inserted. | |
254 | (To make a proper signature, the string should begin with \\n\\n-- \\n, | |
255 | which is the standard way to delimit a signature in a message.) | |
256 | Otherwise, it should be an expression; it is evaluated | |
257 | and should insert whatever you want to insert." | |
258 | :type '(choice (const "None" nil) | |
259 | (const :tag "Use `.signature' file" t) | |
260 | (string :tag "String to insert") | |
261 | (sexp :tag "Expression to evaluate")) | |
0b5bb3ec | 262 | :group 'sendmail) |
f13c1dae | 263 | (put 'mail-signature 'risky-local-variable t) |
4ac2e032 | 264 | |
0b5bb3ec SE |
265 | (defcustom mail-signature-file "~/.signature" |
266 | "*File containing the text inserted at end of mail buffer." | |
267 | :type 'file | |
268 | :group 'sendmail) | |
20a8832d | 269 | |
c8553837 | 270 | (defvar mail-reply-action nil) |
20a8832d RS |
271 | (defvar mail-send-actions nil |
272 | "A list of actions to be performed upon successful sending of a message.") | |
c8553837 | 273 | (put 'mail-reply-action 'permanent-local t) |
98bd608d | 274 | (put 'mail-send-actions 'permanent-local t) |
20a8832d | 275 | |
0b5bb3ec | 276 | (defcustom mail-default-headers nil |
20a8832d RS |
277 | "*A string containing header lines, to be inserted in outgoing messages. |
278 | It is inserted before you edit the message, | |
0b5bb3ec SE |
279 | so you can edit or delete these lines." |
280 | :type '(choice (const nil) string) | |
281 | :group 'sendmail) | |
20a8832d | 282 | |
0b5bb3ec | 283 | (defcustom mail-bury-selects-summary t |
1f7850dd RS |
284 | "*If non-nil, try to show RMAIL summary buffer after returning from mail. |
285 | The functions \\[mail-send-on-exit] or \\[mail-dont-send] select | |
286 | the RMAIL summary buffer before returning, if it exists and this variable | |
0b5bb3ec SE |
287 | is non-nil." |
288 | :type 'boolean | |
289 | :group 'sendmail) | |
1f7850dd | 290 | |
baaa1f19 | 291 | (defcustom mail-send-nonascii 'mime |
34153d76 RS |
292 | "*Specify whether to allow sending non-ASCII characters in mail. |
293 | If t, that means do allow it. nil means don't allow it. | |
294 | `query' means ask the user each time. | |
baaa1f19 GM |
295 | `mime' means add an appropriate MIME header if none already present. |
296 | The default is `mime'. | |
34153d76 | 297 | Including non-ASCII characters in a mail message can be problematical |
0b5bb3ec | 298 | for the recipient, who may not know how to decode them properly." |
baaa1f19 | 299 | :type '(choice (const t) (const nil) (const query) (const mime)) |
0b5bb3ec | 300 | :group 'sendmail) |
34153d76 | 301 | |
7c203051 RS |
302 | ;; Note: could use /usr/ucb/mail instead of sendmail; |
303 | ;; options -t, and -v if not interactive. | |
304 | (defvar mail-mailer-swallows-blank-line | |
01b5c04d | 305 | (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)" system-configuration) |
47c5e807 | 306 | (file-readable-p "/etc/sendmail.cf") |
01b5c04d RS |
307 | (let ((buffer (get-buffer-create " *temp*"))) |
308 | (unwind-protect | |
309 | (save-excursion | |
310 | (set-buffer buffer) | |
311 | (insert-file-contents "/etc/sendmail.cf") | |
312 | (goto-char (point-min)) | |
313 | (let ((case-fold-search nil)) | |
5a853005 | 314 | (re-search-forward "^OR\\>" nil t))) |
01b5c04d | 315 | (kill-buffer buffer)))) |
9a41d08a NF |
316 | ;; According to RFC822, "The field-name must be composed of printable |
317 | ;; ASCII characters (i.e. characters that have decimal values between | |
318 | ;; 33 and 126, except colon)", i.e. any chars except ctl chars, | |
319 | ;; space, or colon. | |
320 | '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:")) | |
7c203051 RS |
321 | "Set this non-nil if the system's mailer runs the header and body together. |
322 | \(This problem exists on Sunos 4 when sendmail is run in remote mode.) | |
323 | The value should be an expression to test whether the problem will | |
324 | actually occur.") | |
325 | ||
20a8832d RS |
326 | (defvar mail-mode-syntax-table nil |
327 | "Syntax table used while in mail mode.") | |
328 | ||
8b1f1a0c | 329 | (if (not mail-mode-syntax-table) |
20a8832d RS |
330 | (progn |
331 | (setq mail-mode-syntax-table (copy-syntax-table text-mode-syntax-table)) | |
332 | (modify-syntax-entry ?% ". " mail-mode-syntax-table))) | |
333 | ||
8b1f1a0c | 334 | (defvar mail-font-lock-keywords |
70a302f8 | 335 | (eval-when-compile |
f1052d2e | 336 | (let* ((cite-chars "[>|}]") |
0eafc06c | 337 | (cite-prefix "[:alpha:]") |
f1052d2e | 338 | (cite-suffix (concat cite-prefix "0-9_.@-`'\""))) |
3d51068d SM |
339 | (list '("^\\(To\\|Newsgroups\\):" . font-lock-function-name-face) |
340 | '("^\\(B?CC\\|Reply-to\\):" . font-lock-keyword-face) | |
70a302f8 SM |
341 | '("^\\(Subject:\\)[ \t]*\\(.+\\)?" |
342 | (1 font-lock-comment-face) (2 font-lock-type-face nil t)) | |
f1052d2e | 343 | ;; Use EVAL to delay in case `mail-header-separator' gets changed. |
3d51068d | 344 | '(eval . |
e69d810c | 345 | (let ((separator (if (zerop (length mail-header-separator)) |
8646fe22 | 346 | " \\`\\' " |
e69d810c SM |
347 | (regexp-quote mail-header-separator)))) |
348 | (cons (concat "^" separator "$") 'font-lock-warning-face))) | |
f1052d2e SM |
349 | ;; Use MATCH-ANCHORED to effectively anchor the regexp left side. |
350 | `(,cite-chars | |
351 | (,(concat "\\=[ \t]*" | |
3d51068d SM |
352 | "\\(\\([" cite-prefix "]+[" cite-suffix "]*\\)?" |
353 | "\\(" cite-chars "[ \t]*\\)\\)+" | |
354 | "\\(.*\\)") | |
f1052d2e | 355 | (beginning-of-line) (end-of-line) |
883212ce | 356 | (2 font-lock-constant-face nil t) |
3d51068d | 357 | (4 font-lock-comment-face nil t))) |
70a302f8 SM |
358 | '("^\\(X-[A-Za-z0-9-]+\\|In-reply-to\\):.*" |
359 | . font-lock-string-face)))) | |
8b1f1a0c RS |
360 | "Additional expressions to highlight in Mail mode.") |
361 | ||
0b5bb3ec SE |
362 | (defcustom mail-send-hook nil |
363 | "Normal hook run before sending mail, in Mail mode." | |
364 | :type 'hook | |
365 | :group 'sendmail) | |
5b6575b7 | 366 | \f |
1498db18 | 367 | (defun sendmail-sync-aliases () |
8790b698 | 368 | (let ((modtime (nth 5 (file-attributes mail-personal-alias-file)))) |
9cc75191 KH |
369 | (or (equal mail-alias-modtime modtime) |
370 | (setq mail-alias-modtime modtime | |
371 | mail-aliases t)))) | |
372 | ||
20a8832d | 373 | (defun mail-setup (to subject in-reply-to cc replybuffer actions) |
235c2d35 | 374 | (or mail-default-reply-to |
810163a3 | 375 | (setq mail-default-reply-to (getenv "REPLYTO"))) |
1498db18 | 376 | (sendmail-sync-aliases) |
5ef9d627 RS |
377 | (if (eq mail-aliases t) |
378 | (progn | |
379 | (setq mail-aliases nil) | |
8790b698 | 380 | (if (file-exists-p mail-personal-alias-file) |
5ef9d627 | 381 | (build-mail-aliases)))) |
2813dcb9 | 382 | ;; Don't leave this around from a previous message. |
f8081291 | 383 | (kill-local-variable 'buffer-file-coding-system) |
9be82109 KH |
384 | ;; This doesn't work for enable-multibyte-characters. |
385 | ;; (kill-local-variable 'enable-multibyte-characters) | |
386 | (set-buffer-multibyte default-enable-multibyte-characters) | |
8881c1ab KH |
387 | (if current-input-method |
388 | (inactivate-input-method)) | |
20a8832d | 389 | (setq mail-send-actions actions) |
c8553837 | 390 | (setq mail-reply-action replybuffer) |
20a8832d RS |
391 | (goto-char (point-min)) |
392 | (insert "To: ") | |
393 | (save-excursion | |
394 | (if to | |
70ca75ae RS |
395 | ;; Here removed code to extract names from within <...> |
396 | ;; on the assumption that mail-strip-quoted-names | |
397 | ;; has been called and has done so. | |
398 | (let ((fill-prefix "\t") | |
399 | (address-start (point))) | |
20a8832d | 400 | (insert to "\n") |
118a3c04 RS |
401 | (fill-region-as-paragraph address-start (point-max)) |
402 | (goto-char (point-max)) | |
403 | (unless (bolp) | |
404 | (newline))) | |
20a8832d RS |
405 | (newline)) |
406 | (if cc | |
70ca75ae RS |
407 | (let ((fill-prefix "\t") |
408 | (address-start (progn (insert "CC: ") (point)))) | |
409 | (insert cc "\n") | |
118a3c04 RS |
410 | (fill-region-as-paragraph address-start (point-max)) |
411 | (goto-char (point-max)) | |
412 | (unless (bolp) | |
413 | (newline)))) | |
20a8832d | 414 | (if in-reply-to |
118a3c04 | 415 | (let ((fill-prefix "\t") |
58cabff0 | 416 | (fill-column 78) |
34046d66 RS |
417 | (address-start (point))) |
418 | (insert "In-reply-to: " in-reply-to "\n") | |
118a3c04 RS |
419 | (fill-region-as-paragraph address-start (point-max)) |
420 | (goto-char (point-max)) | |
421 | (unless (bolp) | |
422 | (newline)))) | |
20a8832d RS |
423 | (insert "Subject: " (or subject "") "\n") |
424 | (if mail-default-headers | |
425 | (insert mail-default-headers)) | |
426 | (if mail-default-reply-to | |
427 | (insert "Reply-to: " mail-default-reply-to "\n")) | |
428 | (if mail-self-blind | |
22c03d39 | 429 | (insert "BCC: " user-mail-address "\n")) |
20a8832d RS |
430 | (if mail-archive-file-name |
431 | (insert "FCC: " mail-archive-file-name "\n")) | |
6737ae74 RS |
432 | (put-text-property (point) |
433 | (progn | |
434 | (insert mail-header-separator "\n") | |
435 | (1- (point))) | |
436 | 'category 'mail-header-separator) | |
874bdb5a RS |
437 | ;; Insert the signature. But remember the beginning of the message. |
438 | (if to (setq to (point))) | |
547075d4 | 439 | (cond ((eq mail-signature t) |
4ac2e032 | 440 | (if (file-exists-p mail-signature-file) |
a5282b8f RS |
441 | (progn |
442 | (insert "\n\n-- \n") | |
4ac2e032 | 443 | (insert-file-contents mail-signature-file)))) |
f13c1dae RS |
444 | ((stringp mail-signature) |
445 | (insert mail-signature)) | |
446 | (t | |
447 | (eval mail-signature))) | |
20a8832d RS |
448 | (goto-char (point-max)) |
449 | (or (bolp) (newline))) | |
874bdb5a | 450 | (if to (goto-char to)) |
20a8832d RS |
451 | (or to subject in-reply-to |
452 | (set-buffer-modified-p nil)) | |
453 | (run-hooks 'mail-setup-hook)) | |
5b6575b7 | 454 | \f |
be0b8d69 DL |
455 | (defcustom mail-mode-hook nil |
456 | "Hook run by Mail mode." | |
457 | :group 'sendmail | |
458 | :type 'hook | |
459 | :options '(footnote-mode)) | |
460 | ||
20a8832d RS |
461 | ;;;###autoload |
462 | (defun mail-mode () | |
463 | "Major mode for editing mail to be sent. | |
464 | Like Text Mode but with these additional commands: | |
d3db616e KH |
465 | \\[mail-send] mail-send (send the message) \\[mail-send-and-exit] mail-send-and-exit |
466 | Here are commands that move to a header field (and create it if there isn't): | |
467 | \\[mail-to] move to To: \\[mail-subject] move to Subject: | |
468 | \\[mail-cc] move to CC: \\[mail-bcc] move to BCC: | |
469 | \\[mail-fcc] move to FCC: | |
470 | \\[mail-text] mail-text (move to beginning of message text). | |
471 | \\[mail-signature] mail-signature (insert `mail-signature-file' file). | |
472 | \\[mail-yank-original] mail-yank-original (insert current message, in Rmail). | |
473 | \\[mail-fill-yanked-message] mail-fill-yanked-message (fill what was yanked). | |
4deb3ba9 EZ |
474 | \\[mail-sent-via] mail-sent-via (add a Sent-via field for each To or CC). |
475 | Turning on Mail mode runs the normal hooks `text-mode-hook' and | |
476 | `mail-mode-hook' (in that order)." | |
20a8832d RS |
477 | (interactive) |
478 | (kill-all-local-variables) | |
c8553837 | 479 | (make-local-variable 'mail-reply-action) |
20a8832d RS |
480 | (make-local-variable 'mail-send-actions) |
481 | (set-syntax-table mail-mode-syntax-table) | |
482 | (use-local-map mail-mode-map) | |
483 | (setq local-abbrev-table text-mode-abbrev-table) | |
484 | (setq major-mode 'mail-mode) | |
485 | (setq mode-name "Mail") | |
486 | (setq buffer-offer-save t) | |
2667df42 | 487 | (make-local-variable 'font-lock-defaults) |
117e4b0c | 488 | (setq font-lock-defaults '(mail-font-lock-keywords t t)) |
20a8832d RS |
489 | (make-local-variable 'paragraph-separate) |
490 | (make-local-variable 'paragraph-start) | |
5b6575b7 RS |
491 | (make-local-variable 'normal-auto-fill-function) |
492 | (setq normal-auto-fill-function 'mail-mode-auto-fill) | |
b5682230 | 493 | (make-local-variable 'fill-paragraph-function) |
c8553837 | 494 | (setq fill-paragraph-function 'mail-mode-fill-paragraph) |
eba52a1a MB |
495 | ;; Allow using comment commands to add/remove quoting (this only does |
496 | ;; anything if mail-yank-prefix is set to a non-nil value). | |
497 | (set (make-local-variable 'comment-start) mail-yank-prefix) | |
1b8def58 RS |
498 | (make-local-variable 'adaptive-fill-regexp) |
499 | (setq adaptive-fill-regexp | |
ddedc4d4 | 500 | (concat "[ \t]*\\([-|#;>*]+ *\\|(?[0-9]+[.)] *\\)+" |
0eafc06c | 501 | "\\|[ \t]*[-[:alnum:]]*>+[ \t]*" |
ddedc4d4 | 502 | "\\|[ \t]*")) |
d78f466f | 503 | (make-local-variable 'adaptive-fill-first-line-regexp) |
f03ca5f5 | 504 | (setq adaptive-fill-first-line-regexp |
ddedc4d4 | 505 | (concat adaptive-fill-first-line-regexp |
0eafc06c | 506 | "\\|[ \t]*[-[:alnum:]]*>+[ \t]*")) |
df0d89b1 RS |
507 | ;; `-- ' precedes the signature. `-----' appears at the start of the |
508 | ;; lines that delimit forwarded messages. | |
509 | ;; Lines containing just >= 3 dashes, perhaps after whitespace, | |
510 | ;; are also sometimes used and should be separators. | |
0408f0ac | 511 | (setq paragraph-start (concat (regexp-quote mail-header-separator) |
75e4db34 | 512 | "$\\|\t*\\([-|#;>* ]\\|(?[0-9]+[.)]\\)+$" |
0eafc06c | 513 | "\\|[ \t]*[[:alnum:]]*>+[ \t]*$\\|[ \t]*$\\|" |
7a366296 | 514 | "-- $\\|---+$\\|" |
a8fb9940 | 515 | page-delimiter)) |
a9842346 | 516 | (setq paragraph-separate paragraph-start) |
20a8832d | 517 | (run-hooks 'text-mode-hook 'mail-mode-hook)) |
5b6575b7 | 518 | |
51d541d4 RS |
519 | |
520 | (defun mail-header-end () | |
521 | "Return the buffer location of the end of headers, as a number." | |
66191b7e RS |
522 | (save-restriction |
523 | (widen) | |
524 | (save-excursion | |
525 | (rfc822-goto-eoh) | |
526 | (point)))) | |
51d541d4 RS |
527 | |
528 | (defun mail-text-start () | |
529 | "Return the buffer location of the start of text, as a number." | |
66191b7e RS |
530 | (save-restriction |
531 | (widen) | |
532 | (save-excursion | |
533 | (rfc822-goto-eoh) | |
534 | (forward-line 1) | |
535 | (point)))) | |
51d541d4 RS |
536 | |
537 | (defun mail-sendmail-delimit-header () | |
538 | "Set up whatever header delimiter convention sendmail will use. | |
539 | Concretely: replace the first blank line in the header with the separator." | |
540 | (rfc822-goto-eoh) | |
541 | (insert mail-header-separator) | |
542 | (point)) | |
543 | ||
544 | (defun mail-sendmail-undelimit-header () | |
545 | "Remove header separator to put the message in correct form for sendmail. | |
546 | Leave point at the start of the delimiter line." | |
547 | (rfc822-goto-eoh) | |
548 | (delete-region (point) (progn (end-of-line) (point)))) | |
549 | ||
5b6575b7 RS |
550 | (defun mail-mode-auto-fill () |
551 | "Carry out Auto Fill for Mail mode. | |
552 | If within the headers, this makes the new lines into continuation lines." | |
51d541d4 | 553 | (if (< (point) (mail-header-end)) |
5b6575b7 RS |
554 | (let ((old-line-start (save-excursion (beginning-of-line) (point)))) |
555 | (if (do-auto-fill) | |
556 | (save-excursion | |
557 | (beginning-of-line) | |
558 | (while (not (eq (point) old-line-start)) | |
28afe199 RS |
559 | ;; Use insert-before-markers in case we're inserting |
560 | ;; before the saved value of point (which is common). | |
561 | (insert-before-markers " ") | |
5b6575b7 RS |
562 | (forward-line -1)) |
563 | t))) | |
564 | (do-auto-fill))) | |
c8553837 RS |
565 | |
566 | (defun mail-mode-fill-paragraph (arg) | |
567 | ;; Do something special only if within the headers. | |
51d541d4 | 568 | (if (< (point) (mail-header-end)) |
c8553837 | 569 | (let (beg end fieldname) |
8fcbbf7d GM |
570 | (when (prog1 (re-search-backward "^[-a-zA-Z]+:" nil 'yes) |
571 | (setq beg (point))) | |
c8553837 | 572 | (setq fieldname |
8fcbbf7d | 573 | (downcase (buffer-substring beg (1- (match-end 0)))))) |
c8553837 RS |
574 | (forward-line 1) |
575 | ;; Find continuation lines and get rid of their continuation markers. | |
576 | (while (looking-at "[ \t]") | |
577 | (delete-horizontal-space) | |
578 | (forward-line 1)) | |
579 | (setq end (point-marker)) | |
580 | (goto-char beg) | |
581 | ;; If this field contains addresses, | |
582 | ;; make sure we can fill after each address. | |
583 | (if (member fieldname | |
584 | '("to" "cc" "bcc" "from" "reply-to" | |
585 | "resent-to" "resent-cc" "resent-bcc" | |
586 | "resent-from" "resent-reply-to")) | |
587 | (while (search-forward "," end t) | |
588 | (or (looking-at "[ \t]") | |
589 | (insert " ")))) | |
590 | (fill-region-as-paragraph beg end) | |
591 | ;; Mark all lines except the first as continuations. | |
592 | (goto-char beg) | |
593 | (forward-line 1) | |
594 | (while (< (point) end) | |
595 | (insert " ") | |
596 | (forward-line 1)) | |
597 | (move-marker end nil) | |
598 | t))) | |
299fdd8d RS |
599 | \f |
600 | ;;; Set up keymap. | |
20a8832d RS |
601 | |
602 | (if mail-mode-map | |
603 | nil | |
604 | (setq mail-mode-map (nconc (make-sparse-keymap) text-mode-map)) | |
c21b5781 | 605 | (define-key mail-mode-map "\M-\t" 'mail-complete) |
20a8832d RS |
606 | (define-key mail-mode-map "\C-c?" 'describe-mode) |
607 | (define-key mail-mode-map "\C-c\C-f\C-t" 'mail-to) | |
608 | (define-key mail-mode-map "\C-c\C-f\C-b" 'mail-bcc) | |
70ee42f7 | 609 | (define-key mail-mode-map "\C-c\C-f\C-f" 'mail-fcc) |
20a8832d RS |
610 | (define-key mail-mode-map "\C-c\C-f\C-c" 'mail-cc) |
611 | (define-key mail-mode-map "\C-c\C-f\C-s" 'mail-subject) | |
3a3ffba4 | 612 | (define-key mail-mode-map "\C-c\C-f\C-r" 'mail-reply-to) |
20a8832d RS |
613 | (define-key mail-mode-map "\C-c\C-t" 'mail-text) |
614 | (define-key mail-mode-map "\C-c\C-y" 'mail-yank-original) | |
e39e74c0 | 615 | (define-key mail-mode-map "\C-c\C-r" 'mail-yank-region) |
20a8832d RS |
616 | (define-key mail-mode-map "\C-c\C-q" 'mail-fill-yanked-message) |
617 | (define-key mail-mode-map "\C-c\C-w" 'mail-signature) | |
618 | (define-key mail-mode-map "\C-c\C-v" 'mail-sent-via) | |
619 | (define-key mail-mode-map "\C-c\C-c" 'mail-send-and-exit) | |
f0aef6bf RS |
620 | (define-key mail-mode-map "\C-c\C-s" 'mail-send) |
621 | (define-key mail-mode-map "\C-c\C-i" 'mail-attach-file)) | |
299fdd8d RS |
622 | |
623 | (define-key mail-mode-map [menu-bar mail] | |
624 | (cons "Mail" (make-sparse-keymap "Mail"))) | |
625 | ||
626 | (define-key mail-mode-map [menu-bar mail fill] | |
627 | '("Fill Citation" . mail-fill-yanked-message)) | |
628 | ||
629 | (define-key mail-mode-map [menu-bar mail yank] | |
630 | '("Cite Original" . mail-yank-original)) | |
631 | ||
632 | (define-key mail-mode-map [menu-bar mail signature] | |
633 | '("Insert Signature" . mail-signature)) | |
634 | ||
1abf89b8 SM |
635 | (define-key mail-mode-map [menu-bar mail mail-sep] |
636 | '("--")) | |
637 | ||
1b6bb250 RS |
638 | (define-key mail-mode-map [menu-bar mail cancel] |
639 | '("Cancel" . mail-dont-send)) | |
640 | ||
299fdd8d RS |
641 | (define-key mail-mode-map [menu-bar mail send-stay] |
642 | '("Send, Keep Editing" . mail-send)) | |
643 | ||
644 | (define-key mail-mode-map [menu-bar mail send] | |
645 | '("Send Message" . mail-send-and-exit)) | |
646 | ||
647 | (define-key mail-mode-map [menu-bar headers] | |
fa8afe42 | 648 | (cons "Headers" (make-sparse-keymap "Move to Header"))) |
299fdd8d | 649 | |
1abf89b8 SM |
650 | (define-key mail-mode-map [menu-bar headers text] |
651 | '("Text" . mail-text)) | |
652 | ||
653 | (define-key mail-mode-map [menu-bar headers expand-aliases] | |
654 | '("Expand Aliases" . expand-mail-aliases)) | |
3a3ffba4 | 655 | |
299fdd8d RS |
656 | (define-key mail-mode-map [menu-bar headers sent-via] |
657 | '("Sent Via" . mail-sent-via)) | |
658 | ||
1abf89b8 SM |
659 | (define-key mail-mode-map [menu-bar headers reply-to] |
660 | '("Reply-To" . mail-reply-to)) | |
299fdd8d RS |
661 | |
662 | (define-key mail-mode-map [menu-bar headers bcc] | |
663 | '("Bcc" . mail-bcc)) | |
664 | ||
665 | (define-key mail-mode-map [menu-bar headers fcc] | |
666 | '("Fcc" . mail-fcc)) | |
667 | ||
668 | (define-key mail-mode-map [menu-bar headers cc] | |
669 | '("Cc" . mail-cc)) | |
670 | ||
671 | (define-key mail-mode-map [menu-bar headers subject] | |
672 | '("Subject" . mail-subject)) | |
673 | ||
674 | (define-key mail-mode-map [menu-bar headers to] | |
675 | '("To" . mail-to)) | |
20a8832d | 676 | \f |
5b6575b7 RS |
677 | ;; User-level commands for sending. |
678 | ||
20a8832d | 679 | (defun mail-send-and-exit (arg) |
33b4a308 | 680 | "Send message like `mail-send', then, if no errors, exit from mail buffer. |
20a8832d RS |
681 | Prefix arg means don't delete this window." |
682 | (interactive "P") | |
683 | (mail-send) | |
1b6bb250 RS |
684 | (mail-bury arg)) |
685 | ||
686 | (defun mail-dont-send (arg) | |
687 | "Don't send the message you have been editing. | |
688 | Prefix arg means don't delete this window." | |
689 | (interactive "P") | |
690 | (mail-bury arg)) | |
691 | ||
692 | (defun mail-bury (arg) | |
693 | "Bury this mail buffer." | |
e49ad9a5 RS |
694 | (let ((newbuf (other-buffer (current-buffer)))) |
695 | (bury-buffer (current-buffer)) | |
54feedaa | 696 | (if (and (or (window-dedicated-p (frame-selected-window)) |
b03a1621 | 697 | (cdr (assq 'mail-dedicated-frame (frame-parameters)))) |
9320d421 RS |
698 | (not (null (delq (selected-frame) (visible-frame-list))))) |
699 | (delete-frame (selected-frame)) | |
fdb90184 RS |
700 | (let (rmail-flag summary-buffer) |
701 | (and (not arg) | |
702 | (not (one-window-p)) | |
703 | (save-excursion | |
704 | (set-buffer (window-buffer (next-window (selected-window) 'not))) | |
705 | (setq rmail-flag (eq major-mode 'rmail-mode)) | |
706 | (setq summary-buffer | |
1f7850dd RS |
707 | (and mail-bury-selects-summary |
708 | (boundp 'rmail-summary-buffer) | |
6cfc977b | 709 | rmail-summary-buffer |
fdb90184 RS |
710 | (buffer-name rmail-summary-buffer) |
711 | (not (get-buffer-window rmail-summary-buffer)) | |
712 | rmail-summary-buffer)))) | |
713 | (if rmail-flag | |
714 | ;; If the Rmail buffer has a summary, show that. | |
715 | (if summary-buffer (switch-to-buffer summary-buffer) | |
716 | (delete-window)) | |
717 | (switch-to-buffer newbuf)))))) | |
20a8832d | 718 | |
be0b8d69 DL |
719 | (defcustom mail-send-hook nil |
720 | "Hook run just before sending mail with `mail-send'." | |
721 | :type 'hook | |
722 | :options '(flyspell-mode-off) | |
723 | :group 'sendmail) | |
724 | ||
20a8832d RS |
725 | (defun mail-send () |
726 | "Send the message in the current buffer. | |
727 | If `mail-interactive' is non-nil, wait for success indication | |
728 | or error messages, and inform user. | |
729 | Otherwise any failure is reported in a message back to | |
730 | the user from the mailer." | |
731 | (interactive) | |
e11094e6 RS |
732 | (if (if buffer-file-name |
733 | (y-or-n-p "Send buffer contents as mail message? ") | |
734 | (or (buffer-modified-p) | |
735 | (y-or-n-p "Message already sent; resend? "))) | |
34153d76 RS |
736 | (let ((inhibit-read-only t) |
737 | (opoint (point))) | |
738 | (when (and enable-multibyte-characters | |
baaa1f19 | 739 | (not (memq mail-send-nonascii '(t mime)))) |
34153d76 RS |
740 | (goto-char (point-min)) |
741 | (skip-chars-forward "\0-\177") | |
742 | (or (= (point) (point-max)) | |
743 | (if (eq mail-send-nonascii 'query) | |
744 | (or (y-or-n-p "Message contains non-ASCII characters; send anyway? ") | |
745 | (error "Aborted")) | |
746 | (error "Message contains non-ASCII characters")))) | |
413d1aa2 RS |
747 | ;; Complain about any invalid line. |
748 | (goto-char (point-min)) | |
51d541d4 | 749 | (while (< (point) (mail-header-end)) |
413d1aa2 RS |
750 | (unless (looking-at "[ \t]\\|.*:\\|$") |
751 | (push-mark opoint) | |
752 | (error "Invalid header line (maybe a continuation line lacks initial whitespace)")) | |
753 | (forward-line 1)) | |
34153d76 | 754 | (goto-char opoint) |
20a8832d | 755 | (run-hooks 'mail-send-hook) |
da5667c6 | 756 | (message "Sending...") |
20a8832d RS |
757 | (funcall send-mail-function) |
758 | ;; Now perform actions on successful sending. | |
759 | (while mail-send-actions | |
760 | (condition-case nil | |
d2561f34 RS |
761 | (apply (car (car mail-send-actions)) |
762 | (cdr (car mail-send-actions))) | |
20a8832d RS |
763 | (error)) |
764 | (setq mail-send-actions (cdr mail-send-actions))) | |
d2561f34 | 765 | (message "Sending...done") |
4e0c8650 | 766 | ;; If buffer has no file, mark it as unmodified and delete auto-save. |
d2561f34 RS |
767 | (if (not buffer-file-name) |
768 | (progn | |
769 | (set-buffer-modified-p nil) | |
770 | (delete-auto-save-file-if-necessary t)))))) | |
5b6575b7 RS |
771 | \f |
772 | ;; This does the real work of sending a message via sendmail. | |
773 | ;; It is called via the variable send-mail-function. | |
20a8832d | 774 | |
ae54d287 KH |
775 | ;;;###autoload |
776 | (defvar sendmail-coding-system nil | |
da241b5c | 777 | "*Coding system for encoding the outgoing mail. |
265f03bc | 778 | This has higher priority than `default-buffer-file-coding-system' |
da241b5c KH |
779 | and `default-sendmail-coding-system', |
780 | but lower priority than the local value of `buffer-file-coding-system'. | |
0b64a3da | 781 | See also the function `select-message-coding-system'.") |
da241b5c KH |
782 | |
783 | ;;;###autoload | |
784 | (defvar default-sendmail-coding-system 'iso-latin-1 | |
265f03bc | 785 | "Default coding system for encoding the outgoing mail. |
da241b5c KH |
786 | This variable is used only when `sendmail-coding-system' is nil. |
787 | ||
788 | This variable is set/changed by the command set-language-environment. | |
789 | User should not set this variable manually, | |
790 | instead use sendmail-coding-system to get a constant encoding | |
791 | of outgoing mails regardless of the current language environment. | |
0b64a3da | 792 | See also the function `select-message-coding-system'.") |
ee0a4f29 | 793 | |
20a8832d | 794 | (defun sendmail-send-it () |
67ad9438 DL |
795 | "Send the current mail buffer using the Sendmail package. |
796 | This is a suitable value for `send-mail-function'. It sends using the | |
797 | external program defined by `sendmail-program'." | |
8e183d5b | 798 | (require 'mail-utils) |
20a8832d RS |
799 | (let ((errbuf (if mail-interactive |
800 | (generate-new-buffer " sendmail errors") | |
538b9847 | 801 | 0)) |
20a8832d RS |
802 | (tembuf (generate-new-buffer " sendmail temp")) |
803 | (case-fold-search nil) | |
2b7573b1 KH |
804 | (coding (and (local-variable-p 'buffer-file-coding-system) |
805 | buffer-file-coding-system)) | |
5ddcadb8 | 806 | selected-coding |
180d5509 | 807 | ;;; resend-to-addresses |
20a8832d | 808 | delimline |
00365e98 | 809 | fcc-was-found |
3ff0518e GM |
810 | (mailbuf (current-buffer)) |
811 | (program (if (boundp 'sendmail-program) | |
812 | sendmail-program | |
c1a1fd60 | 813 | "/usr/lib/sendmail"))) |
20a8832d RS |
814 | (unwind-protect |
815 | (save-excursion | |
816 | (set-buffer tembuf) | |
817 | (erase-buffer) | |
818 | (insert-buffer-substring mailbuf) | |
2b7573b1 | 819 | (set-buffer-file-coding-system coding) |
20a8832d RS |
820 | (goto-char (point-max)) |
821 | ;; require one newline at the end. | |
822 | (or (= (preceding-char) ?\n) | |
823 | (insert ?\n)) | |
824 | ;; Change header-delimiter to be what sendmail expects. | |
51d541d4 RS |
825 | (goto-char (mail-header-end)) |
826 | (delete-region (point) (progn (end-of-line) (point))) | |
20a8832d | 827 | (setq delimline (point-marker)) |
1498db18 | 828 | (sendmail-sync-aliases) |
5ef9d627 RS |
829 | (if mail-aliases |
830 | (expand-mail-aliases (point-min) delimline)) | |
20a8832d | 831 | (goto-char (point-min)) |
413d1aa2 | 832 | ;; Ignore any blank lines in the header |
20a8832d RS |
833 | (while (and (re-search-forward "\n\n\n*" delimline t) |
834 | (< (point) delimline)) | |
835 | (replace-match "\n")) | |
413d1aa2 | 836 | (goto-char (point-min)) |
20a8832d | 837 | (let ((case-fold-search t)) |
180d5509 GM |
838 | ;;; (goto-char (point-min)) |
839 | ;;; (while (re-search-forward "^Resent-\\(to\\|cc\\|bcc\\):" delimline t) | |
840 | ;;; (setq resend-to-addresses | |
841 | ;;; (save-restriction | |
842 | ;;; (narrow-to-region (point) | |
843 | ;;; (save-excursion | |
844 | ;;; (forward-line 1) | |
845 | ;;; (while (looking-at "^[ \t]") | |
846 | ;;; (forward-line 1)) | |
847 | ;;; (point))) | |
848 | ;;; (append (mail-parse-comma-list) | |
849 | ;;; resend-to-addresses))) | |
850 | ;;; ;; Delete Resent-BCC ourselves | |
851 | ;;; (if (save-excursion (beginning-of-line) | |
852 | ;;; (looking-at "resent-bcc")) | |
853 | ;;; (delete-region (save-excursion (beginning-of-line) (point)) | |
854 | ;;; (save-excursion (end-of-line) (1+ (point)))))) | |
53b0c109 RS |
855 | ;;; Apparently this causes a duplicate Sender. |
856 | ;;; ;; If the From is different than current user, insert Sender. | |
857 | ;;; (goto-char (point-min)) | |
858 | ;;; (and (re-search-forward "^From:" delimline t) | |
859 | ;;; (progn | |
860 | ;;; (require 'mail-utils) | |
861 | ;;; (not (string-equal | |
862 | ;;; (mail-strip-quoted-names | |
863 | ;;; (save-restriction | |
864 | ;;; (narrow-to-region (point-min) delimline) | |
865 | ;;; (mail-fetch-field "From"))) | |
866 | ;;; (user-login-name)))) | |
867 | ;;; (progn | |
868 | ;;; (forward-line 1) | |
869 | ;;; (insert "Sender: " (user-login-name) "\n"))) | |
20a8832d RS |
870 | ;; Don't send out a blank subject line |
871 | (goto-char (point-min)) | |
66961910 | 872 | (if (re-search-forward "^Subject:\\([ \t]*\n\\)+\\b" delimline t) |
54115447 RS |
873 | (replace-match "") |
874 | ;; This one matches a Subject just before the header delimiter. | |
875 | (if (and (re-search-forward "^Subject:\\([ \t]*\n\\)+" delimline t) | |
876 | (= (match-end 0) delimline)) | |
877 | (replace-match ""))) | |
ea9ceb34 KH |
878 | ;; Put the "From:" field in unless for some odd reason |
879 | ;; they put one in themselves. | |
880 | (goto-char (point-min)) | |
881 | (if (not (re-search-forward "^From:" delimline t)) | |
cbc9f037 | 882 | (let* ((login user-mail-address) |
0d15bc31 RS |
883 | (fullname (user-full-name)) |
884 | (quote-fullname nil)) | |
67ad9438 DL |
885 | (if (string-match "[^\0-\177]" fullname) |
886 | (setq fullname (rfc2047-encode-string fullname) | |
0d15bc31 | 887 | quote-fullname t)) |
ea9ceb34 | 888 | (cond ((eq mail-from-style 'angles) |
7f1d5de2 RS |
889 | (insert "From: " fullname) |
890 | (let ((fullname-start (+ (point-min) 6)) | |
891 | (fullname-end (point-marker))) | |
892 | (goto-char fullname-start) | |
893 | ;; Look for a character that cannot appear unquoted | |
894 | ;; according to RFC 822. | |
0d15bc31 RS |
895 | (if (or (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" |
896 | fullname-end 1) | |
897 | quote-fullname) | |
7f1d5de2 RS |
898 | (progn |
899 | ;; Quote fullname, escaping specials. | |
900 | (goto-char fullname-start) | |
901 | (insert "\"") | |
902 | (while (re-search-forward "[\"\\]" | |
903 | fullname-end 1) | |
904 | (replace-match "\\\\\\&" t)) | |
905 | (insert "\"")))) | |
906 | (insert " <" login ">\n")) | |
ea9ceb34 | 907 | ((eq mail-from-style 'parens) |
7dad528a RS |
908 | (insert "From: " login " (") |
909 | (let ((fullname-start (point))) | |
0d15bc31 RS |
910 | (if quote-fullname |
911 | (insert "\"")) | |
7dad528a | 912 | (insert fullname) |
0d15bc31 RS |
913 | (if quote-fullname |
914 | (insert "\"")) | |
7dad528a RS |
915 | (let ((fullname-end (point-marker))) |
916 | (goto-char fullname-start) | |
917 | ;; RFC 822 says \ and nonmatching parentheses | |
918 | ;; must be escaped in comments. | |
919 | ;; Escape every instance of ()\ ... | |
920 | (while (re-search-forward "[()\\]" fullname-end 1) | |
921 | (replace-match "\\\\\\&" t)) | |
922 | ;; ... then undo escaping of matching parentheses, | |
923 | ;; including matching nested parentheses. | |
924 | (goto-char fullname-start) | |
925 | (while (re-search-forward | |
926 | "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)" | |
927 | fullname-end 1) | |
928 | (replace-match "\\1(\\3)" t) | |
929 | (goto-char fullname-start)))) | |
7f1d5de2 | 930 | (insert ")\n")) |
ea9ceb34 | 931 | ((null mail-from-style) |
55c3534b RS |
932 | (insert "From: " login "\n")) |
933 | ((eq mail-from-style 'system-default) | |
934 | nil) | |
e186b069 | 935 | (t (error "Invalid value for `mail-from-style'"))))) |
baaa1f19 | 936 | ;; Possibly add a MIME header for the current coding system |
5ddcadb8 | 937 | (let (charset) |
baaa1f19 GM |
938 | (goto-char (point-min)) |
939 | (and (eq mail-send-nonascii 'mime) | |
940 | (not (re-search-forward "^MIME-version:" delimline t)) | |
941 | (progn (skip-chars-forward "\0-\177") | |
942 | (/= (point) (point-max))) | |
5ddcadb8 | 943 | (setq selected-coding (select-message-coding-system)) |
baaa1f19 | 944 | (setq charset |
5ddcadb8 | 945 | (coding-system-get selected-coding 'mime-charset)) |
baaa1f19 GM |
946 | (goto-char delimline) |
947 | (insert "MIME-version: 1.0\n" | |
948 | "Content-type: text/plain; charset=" | |
949 | (symbol-name charset) "\n" | |
950 | "Content-Transfer-Encoding: 8bit\n"))) | |
7c203051 RS |
951 | ;; Insert an extra newline if we need it to work around |
952 | ;; Sun's bug that swallows newlines. | |
953 | (goto-char (1+ delimline)) | |
954 | (if (eval mail-mailer-swallows-blank-line) | |
955 | (newline)) | |
d6e000df RS |
956 | ;; Find and handle any FCC fields. |
957 | (goto-char (point-min)) | |
958 | (if (re-search-forward "^FCC:" delimline t) | |
00365e98 RS |
959 | (progn |
960 | (setq fcc-was-found t) | |
961 | (mail-do-fcc delimline))) | |
20a8832d RS |
962 | (if mail-interactive |
963 | (save-excursion | |
964 | (set-buffer errbuf) | |
965 | (erase-buffer)))) | |
00365e98 RS |
966 | (goto-char (point-min)) |
967 | (if (let ((case-fold-search t)) | |
968 | (re-search-forward "^To:\\|^cc:\\|^bcc:\\|^resent-to:\ | |
969 | \\|^resent-cc:\\|^resent-bcc:" | |
92976f67 | 970 | delimline t)) |
63b89616 | 971 | (let* ((default-directory "/") |
5ddcadb8 KH |
972 | (coding-system-for-write |
973 | (or selected-coding | |
974 | (select-message-coding-system))) | |
63b89616 KH |
975 | (args |
976 | (append (list (point-min) (point-max) | |
3ff0518e | 977 | program |
63b89616 | 978 | nil errbuf nil "-oi") |
c1a1fd60 GM |
979 | (and mail-specify-envelope-from |
980 | (list "-f" (or mail-envelope-from | |
981 | user-mail-address))) | |
63b89616 KH |
982 | ;;; ;; Don't say "from root" if running under su. |
983 | ;;; (and (equal (user-real-login-name) "root") | |
984 | ;;; (list "-f" (user-login-name))) | |
985 | (and mail-alias-file | |
986 | (list (concat "-oA" mail-alias-file))) | |
987 | (if mail-interactive | |
988 | ;; These mean "report errors to terminal" | |
989 | ;; and "deliver interactively" | |
990 | '("-oep" "-odi") | |
991 | ;; These mean "report errors by mail" | |
992 | ;; and "deliver in background". | |
993 | '("-oem" "-odb")) | |
180d5509 GM |
994 | ;;; ;; Get the addresses from the message |
995 | ;;; ;; unless this is a resend. | |
996 | ;;; ;; We must not do that for a resend | |
997 | ;;; ;; because we would find the original addresses. | |
998 | ;;; ;; For a resend, include the specific addresses. | |
999 | ;;; (or resend-to-addresses | |
1000 | '("-t") | |
1001 | ;;; ) | |
1002 | ) | |
1003 | ) | |
63b89616 | 1004 | (exit-value (apply 'call-process-region args))) |
538b9847 | 1005 | (or (null exit-value) (zerop exit-value) |
63b89616 | 1006 | (error "Sending...failed with exit value %d" exit-value))) |
00365e98 RS |
1007 | (or fcc-was-found |
1008 | (error "No recipients"))) | |
20a8832d RS |
1009 | (if mail-interactive |
1010 | (save-excursion | |
1011 | (set-buffer errbuf) | |
1012 | (goto-char (point-min)) | |
1013 | (while (re-search-forward "\n\n* *" nil t) | |
1014 | (replace-match "; ")) | |
1015 | (if (not (zerop (buffer-size))) | |
1016 | (error "Sending...failed to %s" | |
1017 | (buffer-substring (point-min) (point-max))))))) | |
1018 | (kill-buffer tembuf) | |
1019 | (if (bufferp errbuf) | |
1020 | (kill-buffer errbuf))))) | |
1021 | ||
1022 | (defun mail-do-fcc (header-end) | |
1023 | (let (fcc-list | |
1024 | (rmailbuf (current-buffer)) | |
facb137b | 1025 | (time (current-time)) |
20a8832d RS |
1026 | (tembuf (generate-new-buffer " rmail output")) |
1027 | (case-fold-search t)) | |
1028 | (save-excursion | |
1029 | (goto-char (point-min)) | |
1030 | (while (re-search-forward "^FCC:[ \t]*" header-end t) | |
1031 | (setq fcc-list (cons (buffer-substring (point) | |
1032 | (progn | |
1033 | (end-of-line) | |
1034 | (skip-chars-backward " \t") | |
1035 | (point))) | |
1036 | fcc-list)) | |
1037 | (delete-region (match-beginning 0) | |
1038 | (progn (forward-line 1) (point)))) | |
1039 | (set-buffer tembuf) | |
1040 | (erase-buffer) | |
fc23ca96 RS |
1041 | ;; This initial newline is written out if the fcc file already exists. |
1042 | (insert "\nFrom " (user-login-name) " " | |
facb137b | 1043 | (current-time-string time) "\n") |
847f73fd RS |
1044 | ;; Insert the time zone before the year. |
1045 | (forward-char -1) | |
1046 | (forward-word -1) | |
f3098917 RS |
1047 | (require 'mail-utils) |
1048 | (insert (mail-rfc822-time-zone time) " ") | |
847f73fd | 1049 | (goto-char (point-max)) |
20a8832d RS |
1050 | (insert-buffer-substring rmailbuf) |
1051 | ;; Make sure messages are separated. | |
1052 | (goto-char (point-max)) | |
1053 | (insert ?\n) | |
1054 | (goto-char 2) | |
1055 | ;; ``Quote'' "^From " as ">From " | |
1056 | ;; (note that this isn't really quoting, as there is no requirement | |
1057 | ;; that "^[>]+From " be quoted in the same transparent way.) | |
1058 | (let ((case-fold-search nil)) | |
1059 | (while (search-forward "\nFrom " nil t) | |
1060 | (forward-char -5) | |
1061 | (insert ?>))) | |
1062 | (while fcc-list | |
89901917 | 1063 | (let* ((buffer (find-buffer-visiting (car fcc-list))) |
3a3ffba4 | 1064 | (curbuf (current-buffer)) |
0d15bc31 RS |
1065 | dont-write-the-file |
1066 | buffer-matches-file | |
3a3ffba4 RS |
1067 | (beg (point-min)) (end (point-max)) |
1068 | (beg2 (save-excursion (goto-char (point-min)) | |
1069 | (forward-line 2) (point)))) | |
20a8832d RS |
1070 | (if buffer |
1071 | ;; File is present in a buffer => append to that buffer. | |
d6642dff RS |
1072 | (save-excursion |
1073 | (set-buffer buffer) | |
0d15bc31 RS |
1074 | (setq buffer-matches-file |
1075 | (and (not (buffer-modified-p)) | |
205d354f | 1076 | (verify-visited-file-modtime buffer))) |
d6642dff RS |
1077 | ;; Keep the end of the accessible portion at the same place |
1078 | ;; unless it is the end of the buffer. | |
1079 | (let ((max (if (/= (1+ (buffer-size)) (point-max)) | |
1080 | (point-max)))) | |
1081 | (unwind-protect | |
1082 | ;; Code below lifted from rmailout.el | |
1083 | ;; function rmail-output-to-rmail-file: | |
1084 | (let ((buffer-read-only nil) | |
1085 | (msg (and (boundp 'rmail-current-message) | |
1086 | rmail-current-message))) | |
1087 | ;; If MSG is non-nil, buffer is in RMAIL mode. | |
1088 | (if msg | |
1089 | (progn | |
1090 | (rmail-maybe-set-message-counters) | |
1091 | (widen) | |
1092 | (narrow-to-region (point-max) (point-max)) | |
1093 | (insert "\C-l\n0, unseen,,\n*** EOOH ***\n" | |
d6642dff RS |
1094 | "Date: " (mail-rfc822-date) "\n") |
1095 | (insert-buffer-substring curbuf beg2 end) | |
1096 | (insert "\n\C-_") | |
1097 | (goto-char (point-min)) | |
1098 | (widen) | |
1099 | (search-backward "\n\^_") | |
1100 | (narrow-to-region (point) (point-max)) | |
1101 | (rmail-count-new-messages t) | |
1102 | (rmail-show-message msg) | |
1103 | (setq max nil)) | |
1104 | ;; Output file not in rmail mode | |
1105 | ;; => just insert at the end. | |
1106 | (narrow-to-region (point-min) (1+ (buffer-size))) | |
1107 | (goto-char (point-max)) | |
0d15bc31 RS |
1108 | (insert-buffer-substring curbuf beg end)) |
1109 | (or buffer-matches-file | |
1110 | (progn | |
1111 | (if (y-or-n-p (format "Save file %s? " | |
1112 | (car fcc-list))) | |
1113 | (save-buffer)) | |
1114 | (setq dont-write-the-file t)))) | |
1115 | (if max (narrow-to-region (point-min) max)))))) | |
1116 | ;; Append to the file directly, | |
1117 | ;; unless we've already taken care of it. | |
f6f4d690 KH |
1118 | (unless dont-write-the-file |
1119 | (if (and (file-exists-p (car fcc-list)) | |
faeb73d4 GM |
1120 | ;; Check that the file isn't empty. We don't |
1121 | ;; want to insert a newline at the start of an | |
1122 | ;; empty file. | |
1123 | (not (zerop (nth 7 (file-attributes (car fcc-list))))) | |
f6f4d690 KH |
1124 | (mail-file-babyl-p (car fcc-list))) |
1125 | ;; If the file is a Babyl file, | |
1126 | ;; convert the message to Babyl format. | |
1127 | (let ((coding-system-for-write | |
1128 | (or rmail-file-coding-system | |
1129 | 'emacs-mule))) | |
1130 | (save-excursion | |
1131 | (set-buffer (get-buffer-create " mail-temp")) | |
1132 | (setq buffer-read-only nil) | |
1133 | (erase-buffer) | |
1134 | (insert "\C-l\n0, unseen,,\n*** EOOH ***\n" | |
1135 | "Date: " (mail-rfc822-date) "\n") | |
1136 | (insert-buffer-substring curbuf beg2 end) | |
1137 | (insert "\n\C-_") | |
1138 | (write-region (point-min) (point-max) (car fcc-list) t) | |
1139 | (erase-buffer))) | |
1140 | (write-region | |
1141 | (1+ (point-min)) (point-max) (car fcc-list) t))) | |
0d15bc31 RS |
1142 | (and buffer (not dont-write-the-file) |
1143 | (with-current-buffer buffer | |
1144 | (set-visited-file-modtime)))) | |
20a8832d RS |
1145 | (setq fcc-list (cdr fcc-list)))) |
1146 | (kill-buffer tembuf))) | |
1147 | ||
1148 | (defun mail-sent-via () | |
1149 | "Make a Sent-via header line from each To or CC header line." | |
1150 | (interactive) | |
1151 | (save-excursion | |
20a8832d | 1152 | ;; put a marker at the end of the header |
81f5ed32 | 1153 | (let ((end (copy-marker (mail-header-end))) |
20a8832d RS |
1154 | (case-fold-search t) |
1155 | to-line) | |
1156 | (goto-char (point-min)) | |
1157 | ;; search for the To: lines and make Sent-via: lines from them | |
1158 | ;; search for the next To: line | |
1159 | (while (re-search-forward "^\\(to\\|cc\\):" end t) | |
1160 | ;; Grab this line plus all its continuations, sans the `to:'. | |
1161 | (let ((to-line | |
1162 | (buffer-substring (point) | |
1163 | (progn | |
1164 | (if (re-search-forward "^[^ \t\n]" end t) | |
1165 | (backward-char 1) | |
1166 | (goto-char end)) | |
1167 | (point))))) | |
1168 | ;; Insert a copy, with altered header field name. | |
1169 | (insert-before-markers "Sent-via:" to-line)))))) | |
1170 | \f | |
1171 | (defun mail-to () | |
1172 | "Move point to end of To-field." | |
1173 | (interactive) | |
1174 | (expand-abbrev) | |
1175 | (mail-position-on-field "To")) | |
1176 | ||
1177 | (defun mail-subject () | |
1178 | "Move point to end of Subject-field." | |
1179 | (interactive) | |
1180 | (expand-abbrev) | |
1181 | (mail-position-on-field "Subject")) | |
1182 | ||
1183 | (defun mail-cc () | |
1184 | "Move point to end of CC-field. Create a CC field if none." | |
1185 | (interactive) | |
1186 | (expand-abbrev) | |
1187 | (or (mail-position-on-field "cc" t) | |
1188 | (progn (mail-position-on-field "to") | |
1189 | (insert "\nCC: ")))) | |
1190 | ||
1191 | (defun mail-bcc () | |
1192 | "Move point to end of BCC-field. Create a BCC field if none." | |
1193 | (interactive) | |
1194 | (expand-abbrev) | |
1195 | (or (mail-position-on-field "bcc" t) | |
1196 | (progn (mail-position-on-field "to") | |
1197 | (insert "\nBCC: ")))) | |
1198 | ||
5a31c2d2 | 1199 | (defun mail-fcc (folder) |
70ee42f7 | 1200 | "Add a new FCC field, with file name completion." |
5a31c2d2 | 1201 | (interactive "FFolder carbon copy: ") |
70ee42f7 JB |
1202 | (expand-abbrev) |
1203 | (or (mail-position-on-field "fcc" t) ;Put new field after exiting FCC. | |
1204 | (mail-position-on-field "to")) | |
5a31c2d2 | 1205 | (insert "\nFCC: " folder)) |
70ee42f7 | 1206 | |
3a3ffba4 RS |
1207 | (defun mail-reply-to () |
1208 | "Move point to end of Reply-To-field." | |
1209 | (interactive) | |
1210 | (expand-abbrev) | |
1211 | (mail-position-on-field "Reply-To")) | |
1212 | ||
20a8832d RS |
1213 | (defun mail-position-on-field (field &optional soft) |
1214 | (let (end | |
1215 | (case-fold-search t)) | |
51d541d4 | 1216 | (setq end (mail-header-end)) |
20a8832d RS |
1217 | (goto-char (point-min)) |
1218 | (if (re-search-forward (concat "^" (regexp-quote field) ":") end t) | |
1219 | (progn | |
1220 | (re-search-forward "^[^ \t]" nil 'move) | |
1221 | (beginning-of-line) | |
1222 | (skip-chars-backward "\n") | |
1223 | t) | |
1224 | (or soft | |
1225 | (progn (goto-char end) | |
08564963 JB |
1226 | (insert field ": \n") |
1227 | (skip-chars-backward "\n"))) | |
20a8832d RS |
1228 | nil))) |
1229 | ||
1230 | (defun mail-text () | |
330e9e11 | 1231 | "Move point to beginning of message text." |
20a8832d | 1232 | (interactive) |
e3b671fc | 1233 | (expand-abbrev) |
51d541d4 | 1234 | (goto-char (mail-text-start))) |
20a8832d | 1235 | \f |
0d021ccf | 1236 | (defun mail-signature (atpoint) |
4ac2e032 | 1237 | "Sign letter with contents of the file `mail-signature-file'. |
e4f794ed | 1238 | Prefix arg means put contents at point." |
0d021ccf | 1239 | (interactive "P") |
20a8832d | 1240 | (save-excursion |
0d021ccf ER |
1241 | (or atpoint |
1242 | (goto-char (point-max))) | |
20a8832d RS |
1243 | (skip-chars-backward " \t\n") |
1244 | (end-of-line) | |
0d021ccf ER |
1245 | (or atpoint |
1246 | (delete-region (point) (point-max))) | |
de3a72f6 | 1247 | (insert "\n\n-- \n") |
4ac2e032 | 1248 | (insert-file-contents (expand-file-name mail-signature-file)))) |
20a8832d RS |
1249 | |
1250 | (defun mail-fill-yanked-message (&optional justifyp) | |
1251 | "Fill the paragraphs of a message yanked into this one. | |
1252 | Numeric argument means justify as well." | |
1253 | (interactive "P") | |
1254 | (save-excursion | |
51d541d4 | 1255 | (goto-char (mail-text-start)) |
20a8832d RS |
1256 | (fill-individual-paragraphs (point) |
1257 | (point-max) | |
1258 | justifyp | |
706e3d85 | 1259 | mail-citation-prefix-regexp))) |
20a8832d | 1260 | |
374bda6b | 1261 | (defun mail-indent-citation () |
1c24b04a RS |
1262 | "Modify text just inserted from a message to be cited. |
1263 | The inserted text should be the region. | |
1264 | When this function returns, the region is again around the modified text. | |
1265 | ||
1266 | Normally, indent each nonblank line `mail-indentation-spaces' spaces. | |
1267 | However, if `mail-yank-prefix' is non-nil, insert that prefix on each line." | |
374bda6b | 1268 | (mail-yank-clear-headers (region-beginning) (region-end)) |
e39e74c0 | 1269 | (if (null mail-yank-prefix) |
374bda6b RS |
1270 | (indent-rigidly (region-beginning) (region-end) |
1271 | mail-indentation-spaces) | |
e39e74c0 | 1272 | (save-excursion |
374bda6b RS |
1273 | (let ((end (set-marker (make-marker) (region-end)))) |
1274 | (goto-char (region-beginning)) | |
1275 | (while (< (point) end) | |
1276 | (insert mail-yank-prefix) | |
1277 | (forward-line 1)))))) | |
1c24b04a | 1278 | |
20a8832d RS |
1279 | (defun mail-yank-original (arg) |
1280 | "Insert the message being replied to, if any (in rmail). | |
26adca1b | 1281 | Puts point after the text and mark before. |
20a8832d RS |
1282 | Normally, indents each nonblank line ARG spaces (default 3). |
1283 | However, if `mail-yank-prefix' is non-nil, insert that prefix on each line. | |
1284 | ||
1285 | Just \\[universal-argument] as argument means don't indent, insert no prefix, | |
1286 | and don't delete any header fields." | |
1287 | (interactive "P") | |
c8553837 RS |
1288 | (if mail-reply-action |
1289 | (let ((start (point)) | |
1290 | (original mail-reply-action)) | |
1291 | (and (consp original) (eq (car original) 'insert-buffer) | |
1292 | (setq original (nth 1 original))) | |
1293 | (if (consp original) | |
1294 | (apply (car original) (cdr original)) | |
1295 | ;; If the original message is in another window in the same frame, | |
1296 | ;; delete that window to save screen space. | |
1297 | ;; t means don't alter other frames. | |
1298 | (delete-windows-on original t) | |
75e4db34 RS |
1299 | (insert-buffer original) |
1300 | (set-text-properties (point) (mark t) nil)) | |
20a8832d RS |
1301 | (if (consp arg) |
1302 | nil | |
1c24b04a RS |
1303 | (goto-char start) |
1304 | (let ((mail-indentation-spaces (if arg (prefix-numeric-value arg) | |
ac9f0310 | 1305 | mail-indentation-spaces)) |
8761c2c4 RS |
1306 | ;; Avoid error in Transient Mark mode |
1307 | ;; on account of mark's being inactive. | |
ac9f0310 | 1308 | (mark-even-if-inactive t)) |
015c5c55 | 1309 | (if mail-citation-hook |
fab7aa63 | 1310 | ;; Bind mail-citation-header to the inserted message's header. |
d6bccf09 RS |
1311 | (let ((mail-citation-header |
1312 | (buffer-substring-no-properties | |
1313 | start | |
1314 | (save-excursion | |
1315 | (save-restriction | |
1316 | (narrow-to-region start (point-max)) | |
1317 | (goto-char start) | |
1318 | (rfc822-goto-eoh) | |
1319 | (point)))))) | |
1320 | (run-hooks 'mail-citation-hook)) | |
fa24a822 RS |
1321 | (if mail-yank-hooks |
1322 | (run-hooks 'mail-yank-hooks) | |
374bda6b | 1323 | (mail-indent-citation))))) |
3c280f48 RS |
1324 | ;; This is like exchange-point-and-mark, but doesn't activate the mark. |
1325 | ;; It is cleaner to avoid activation, even though the command | |
1326 | ;; loop would deactivate the mark because we inserted text. | |
1327 | (goto-char (prog1 (mark t) | |
1328 | (set-marker (mark-marker) (point) (current-buffer)))) | |
20a8832d RS |
1329 | (if (not (eolp)) (insert ?\n))))) |
1330 | ||
1331 | (defun mail-yank-clear-headers (start end) | |
e39e74c0 RS |
1332 | (if (< end start) |
1333 | (let (temp) | |
1334 | (setq temp start start end end temp))) | |
2b3a206d RS |
1335 | (if mail-yank-ignored-headers |
1336 | (save-excursion | |
1337 | (goto-char start) | |
1338 | (if (search-forward "\n\n" end t) | |
1339 | (save-restriction | |
1340 | (narrow-to-region start (point)) | |
1341 | (goto-char start) | |
1342 | (while (let ((case-fold-search t)) | |
1343 | (re-search-forward mail-yank-ignored-headers nil t)) | |
1344 | (beginning-of-line) | |
1345 | (delete-region (point) | |
1346 | (progn (re-search-forward "\n[^ \t]") | |
1347 | (forward-char -1) | |
1348 | (point))))))))) | |
e39e74c0 RS |
1349 | |
1350 | (defun mail-yank-region (arg) | |
1351 | "Insert the selected region from the message being replied to. | |
1352 | Puts point after the text and mark before. | |
1353 | Normally, indents each nonblank line ARG spaces (default 3). | |
1354 | However, if `mail-yank-prefix' is non-nil, insert that prefix on each line. | |
1355 | ||
1356 | Just \\[universal-argument] as argument means don't indent, insert no prefix, | |
1357 | and don't delete any header fields." | |
1358 | (interactive "P") | |
1359 | (and (consp mail-reply-action) | |
1360 | (eq (car mail-reply-action) 'insert-buffer) | |
75e4db34 RS |
1361 | (with-current-buffer (nth 1 mail-reply-action) |
1362 | (or (mark t) | |
1363 | (error "No mark set: %S" (current-buffer)))) | |
e39e74c0 | 1364 | (let ((buffer (nth 1 mail-reply-action)) |
8761c2c4 RS |
1365 | (start (point)) |
1366 | ;; Avoid error in Transient Mark mode | |
1367 | ;; on account of mark's being inactive. | |
1368 | (mark-even-if-inactive t)) | |
e39e74c0 RS |
1369 | ;; Insert the citation text. |
1370 | (insert (with-current-buffer buffer | |
d6bccf09 | 1371 | (buffer-substring-no-properties (point) (mark)))) |
e39e74c0 RS |
1372 | (push-mark start) |
1373 | ;; Indent or otherwise annotate the citation text. | |
1374 | (if (consp arg) | |
1375 | nil | |
1376 | (let ((mail-indentation-spaces (if arg (prefix-numeric-value arg) | |
1377 | mail-indentation-spaces))) | |
1378 | (if mail-citation-hook | |
d6bccf09 RS |
1379 | ;; Bind mail-citation-hook to the original message's header. |
1380 | (let ((mail-citation-header | |
1381 | (with-current-buffer buffer | |
1382 | (buffer-substring-no-properties | |
1383 | (point-min) | |
1384 | (save-excursion | |
1385 | (goto-char (point-min)) | |
1386 | (rfc822-goto-eoh) | |
1387 | (point)))))) | |
1388 | (run-hooks 'mail-citation-hook)) | |
e39e74c0 RS |
1389 | (if mail-yank-hooks |
1390 | (run-hooks 'mail-yank-hooks) | |
374bda6b | 1391 | (mail-indent-citation)))))))) |
20a8832d | 1392 | \f |
f0aef6bf RS |
1393 | (defun mail-attach-file (&optional file) |
1394 | "Insert a file at the end of the buffer, with separator lines around it." | |
1395 | (interactive "fAttach file: ") | |
1396 | (save-excursion | |
1397 | (goto-char (point-max)) | |
1398 | (or (bolp) (newline)) | |
1399 | (newline) | |
1400 | (let ((start (point)) | |
1401 | middle) | |
1402 | (insert (format "===File %s===" file)) | |
1403 | (insert-char ?= (max 0 (- 60 (current-column)))) | |
1404 | (newline) | |
1405 | (setq middle (point)) | |
1406 | (insert "============================================================\n") | |
1407 | (push-mark) | |
1408 | (goto-char middle) | |
1409 | (insert-file-contents file) | |
1410 | (or (bolp) (newline)) | |
1411 | (goto-char start)))) | |
1412 | \f | |
699adcb2 RS |
1413 | ;; Put these commands last, to reduce chance of lossage from quitting |
1414 | ;; in middle of loading the file. | |
1415 | ||
1416 | ;;;###autoload (add-hook 'same-window-buffer-names "*mail*") | |
20a8832d RS |
1417 | |
1418 | ;;;###autoload | |
1419 | (defun mail (&optional noerase to subject in-reply-to cc replybuffer actions) | |
e635fdf0 RS |
1420 | "Edit a message to be sent. Prefix arg means resume editing (don't erase). |
1421 | When this function returns, the buffer `*mail*' is selected. | |
1422 | The value is t if the message was newly initialized; otherwise, nil. | |
20a8832d | 1423 | |
4ac2e032 RS |
1424 | Optionally, the signature file `mail-signature-file' can be inserted at the |
1425 | end; see the variable `mail-signature'. | |
20a8832d RS |
1426 | |
1427 | \\<mail-mode-map> | |
1428 | While editing message, type \\[mail-send-and-exit] to send the message and exit. | |
1429 | ||
1430 | Various special commands starting with C-c are available in sendmail mode | |
1431 | to move to message header fields: | |
1432 | \\{mail-mode-map} | |
1433 | ||
1434 | If `mail-self-blind' is non-nil, a BCC to yourself is inserted | |
1435 | when the message is initialized. | |
1436 | ||
1437 | If `mail-default-reply-to' is non-nil, it should be an address (a string); | |
1438 | a Reply-to: field with that address is inserted. | |
1439 | ||
1440 | If `mail-archive-file-name' is non-nil, an FCC field with that file name | |
1441 | is inserted. | |
1442 | ||
8b262cbc KH |
1443 | The normal hook `mail-setup-hook' is run after the message is |
1444 | initialized. It can add more default fields to the message. | |
20a8832d | 1445 | |
dfdac213 RS |
1446 | When calling from a program, the first argument if non-nil says |
1447 | not to erase the existing contents of the `*mail*' buffer. | |
1448 | ||
1449 | The second through fifth arguments, | |
1450 | TO, SUBJECT, IN-REPLY-TO and CC, specify if non-nil | |
20a8832d RS |
1451 | the initial contents of those header fields. |
1452 | These arguments should not have final newlines. | |
c8553837 RS |
1453 | The sixth argument REPLYBUFFER is a buffer which contains an |
1454 | original message being replied to, or else an action | |
1455 | of the form (FUNCTION . ARGS) which says how to insert the original. | |
1456 | Or it can be nil, if not replying to anything. | |
20a8832d RS |
1457 | The seventh argument ACTIONS is a list of actions to take |
1458 | if/when the message is sent. Each action looks like (FUNCTION . ARGS); | |
1459 | when the message is sent, we apply FUNCTION to ARGS. | |
1460 | This is how Rmail arranges to mark messages `answered'." | |
1461 | (interactive "P") | |
e635fdf0 RS |
1462 | ;;; This is commented out because I found it was confusing in practice. |
1463 | ;;; It is easy enough to rename *mail* by hand with rename-buffer | |
1464 | ;;; if you want to have multiple mail buffers. | |
1465 | ;;; And then you can control which messages to save. --rms. | |
1466 | ;;; (let ((index 1) | |
1467 | ;;; buffer) | |
1468 | ;;; ;; If requested, look for a mail buffer that is modified and go to it. | |
1469 | ;;; (if noerase | |
1470 | ;;; (progn | |
1471 | ;;; (while (and (setq buffer | |
1472 | ;;; (get-buffer (if (= 1 index) "*mail*" | |
1473 | ;;; (format "*mail*<%d>" index)))) | |
1474 | ;;; (not (buffer-modified-p buffer))) | |
1475 | ;;; (setq index (1+ index))) | |
1476 | ;;; (if buffer (switch-to-buffer buffer) | |
1477 | ;;; ;; If none exists, start a new message. | |
1478 | ;;; ;; This will never re-use an existing unmodified mail buffer | |
1479 | ;;; ;; (since index is not 1 anymore). Perhaps it should. | |
1480 | ;;; (setq noerase nil)))) | |
1481 | ;;; ;; Unless we found a modified message and are happy, start a new message. | |
1482 | ;;; (if (not noerase) | |
1483 | ;;; (progn | |
1484 | ;;; ;; Look for existing unmodified mail buffer. | |
1485 | ;;; (while (and (setq buffer | |
1486 | ;;; (get-buffer (if (= 1 index) "*mail*" | |
1487 | ;;; (format "*mail*<%d>" index)))) | |
1488 | ;;; (buffer-modified-p buffer)) | |
1489 | ;;; (setq index (1+ index))) | |
1490 | ;;; ;; If none, make a new one. | |
1491 | ;;; (or buffer | |
1492 | ;;; (setq buffer (generate-new-buffer "*mail*"))) | |
1493 | ;;; ;; Go there and initialize it. | |
1494 | ;;; (switch-to-buffer buffer) | |
1495 | ;;; (erase-buffer) | |
1496 | ;;; (setq default-directory (expand-file-name "~/")) | |
1497 | ;;; (auto-save-mode auto-save-default) | |
1498 | ;;; (mail-mode) | |
1499 | ;;; (mail-setup to subject in-reply-to cc replybuffer actions) | |
1500 | ;;; (if (and buffer-auto-save-file-name | |
1501 | ;;; (file-exists-p buffer-auto-save-file-name)) | |
1502 | ;;; (message "Auto save file for draft message exists; consider M-x mail-recover")) | |
1503 | ;;; t)) | |
67a6988b | 1504 | (pop-to-buffer "*mail*") |
321eb232 RS |
1505 | ;; Put the auto-save file in the home dir |
1506 | ;; to avoid any danger that it can't be written. | |
3943fa09 RS |
1507 | (if (file-exists-p (expand-file-name "~/")) |
1508 | (setq default-directory (expand-file-name "~/"))) | |
2e78575e RS |
1509 | ;; Only call auto-save-mode if necessary, to avoid changing auto-save file. |
1510 | (if (or (and auto-save-default (not buffer-auto-save-file-name)) | |
1511 | (and (not auto-save-default) buffer-auto-save-file-name)) | |
1512 | (auto-save-mode auto-save-default)) | |
e635fdf0 | 1513 | (mail-mode) |
3b112b5e MB |
1514 | ;; Disconnect the buffer from its visited file |
1515 | ;; (in case the user has actually visited a file *mail*). | |
e4fbad4b | 1516 | ; (set-visited-file-name nil) |
e635fdf0 RS |
1517 | (let (initialized) |
1518 | (and (not noerase) | |
5e32e119 RS |
1519 | (if buffer-file-name |
1520 | (if (buffer-modified-p) | |
1521 | (when (y-or-n-p "Buffer has unsaved changes; reinitialize it and discard them? ") | |
1522 | (if (y-or-n-p "Disconnect buffer from visited file? ") | |
1523 | (set-visited-file-name nil)) | |
1524 | t) | |
1525 | (when (y-or-n-p "Reinitialize buffer, and disconnect it from the visited file? ") | |
1526 | (set-visited-file-name nil) | |
1527 | t)) | |
1528 | ;; A non-file-visiting buffer. | |
1529 | (if (buffer-modified-p) | |
1530 | (y-or-n-p "Unsent message being composed; erase it? ") | |
1531 | t)) | |
6737ae74 RS |
1532 | (let ((inhibit-read-only t)) |
1533 | (erase-buffer) | |
1534 | (mail-setup to subject in-reply-to cc replybuffer actions) | |
1535 | (setq initialized t))) | |
e635fdf0 RS |
1536 | (if (and buffer-auto-save-file-name |
1537 | (file-exists-p buffer-auto-save-file-name)) | |
1538 | (message "Auto save file for draft message exists; consider M-x mail-recover")) | |
1539 | initialized)) | |
20a8832d RS |
1540 | |
1541 | (defun mail-recover () | |
1542 | "Reread contents of current buffer from its last auto-save file." | |
1543 | (interactive) | |
1544 | (let ((file-name (make-auto-save-file-name))) | |
1545 | (cond ((save-window-excursion | |
1546 | (if (not (eq system-type 'vax-vms)) | |
1547 | (with-output-to-temp-buffer "*Directory*" | |
1548 | (buffer-disable-undo standard-output) | |
dc8cec25 KH |
1549 | (let ((default-directory "/")) |
1550 | (call-process | |
1551 | "ls" nil standard-output nil "-l" file-name)))) | |
20a8832d RS |
1552 | (yes-or-no-p (format "Recover auto save file %s? " file-name))) |
1553 | (let ((buffer-read-only nil)) | |
1554 | (erase-buffer) | |
1555 | (insert-file-contents file-name nil))) | |
3b112b5e | 1556 | (t (error "mail-recover cancelled"))))) |
20a8832d RS |
1557 | |
1558 | ;;;###autoload | |
1559 | (defun mail-other-window (&optional noerase to subject in-reply-to cc replybuffer sendactions) | |
1560 | "Like `mail' command, but display mail buffer in another window." | |
1561 | (interactive "P") | |
67a6988b RS |
1562 | (let ((pop-up-windows t) |
1563 | (special-display-buffer-names nil) | |
1564 | (special-display-regexps nil) | |
1565 | (same-window-buffer-names nil) | |
1566 | (same-window-regexps nil)) | |
20a8832d RS |
1567 | (pop-to-buffer "*mail*")) |
1568 | (mail noerase to subject in-reply-to cc replybuffer sendactions)) | |
1569 | ||
1570 | ;;;###autoload | |
0cc89026 JB |
1571 | (defun mail-other-frame (&optional noerase to subject in-reply-to cc replybuffer sendactions) |
1572 | "Like `mail' command, but display mail buffer in another frame." | |
20a8832d | 1573 | (interactive "P") |
67a6988b RS |
1574 | (let ((pop-up-frames t) |
1575 | (special-display-buffer-names nil) | |
1576 | (special-display-regexps nil) | |
1577 | (same-window-buffer-names nil) | |
1578 | (same-window-regexps nil)) | |
20a8832d RS |
1579 | (pop-to-buffer "*mail*")) |
1580 | (mail noerase to subject in-reply-to cc replybuffer sendactions)) | |
1581 | ||
20a8832d | 1582 | ;;; Do not add anything but external entries on this page. |
49116ac0 JB |
1583 | |
1584 | (provide 'sendmail) | |
1585 | ||
c88ab9ce | 1586 | ;;; sendmail.el ends here |