Mercurial > emacs
annotate lisp/mail/sendmail.el @ 782:a6d00bdb2b60
*** empty log message ***
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Wed, 15 Jul 1992 17:54:00 +0000 |
parents | c2dbf1fe0506 |
children | 4f28bd14272c |
rev | line source |
---|---|
658
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
604
diff
changeset
|
1 ;;; sendmail.el --- mail sending commands for Emacs. |
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
604
diff
changeset
|
2 |
573 | 3 ;; Copyright (C) 1985, 1986, 1992 Free Software Foundation, Inc. |
455 | 4 |
5 ;; This file is part of GNU Emacs. | |
6 | |
7 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
8 ;; it under the terms of the GNU General Public License as published by | |
9 ;; the Free Software Foundation; either version 1, or (at your option) | |
10 ;; any later version. | |
11 | |
12 ;; GNU Emacs is distributed in the hope that it will be useful, | |
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 ;; GNU General Public License for more details. | |
16 | |
17 ;; You should have received a copy of the GNU General Public License | |
18 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
19 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
20 | |
21 | |
22 ;;;###autoload | |
23 (defconst mail-self-blind nil "\ | |
24 Non-nil means insert BCC to self in messages to be sent. | |
25 This is done when the message is initialized, | |
26 so you can remove or alter the BCC field to override the default.") | |
27 | |
28 ;;;###autoload | |
29 (defconst mail-interactive nil "\ | |
30 Non-nil means when sending a message wait for and display errors. | |
31 nil means let mailer mail back a message to report errors.") | |
32 | |
33 ;;;###autoload | |
34 (defconst mail-yank-ignored-headers "^via:\\|^mail-from:\\|^origin:\\|^status:\\|^remailed\\|^received:\\|^message-id:\\|^summary-line:\\|^to:\\|^subject:\\|^in-reply-to:\\|^return-path:" "\ | |
35 Delete these headers from old message when it's inserted in a reply.") | |
36 | |
37 ;; Useful to set in site-init.el | |
38 ;;;###autoload | |
39 (defconst send-mail-function 'sendmail-send-it "\ | |
40 Function to call to send the current buffer as mail. | |
41 The headers are be delimited by a line which is mail-header-separator.") | |
42 | |
43 ;;;###autoload | |
44 (defvar mail-header-separator "--text follows this line--" "\ | |
45 *Line used to separate headers from text in messages being composed.") | |
46 | |
47 ;;;###autoload | |
48 (defvar mail-archive-file-name nil "\ | |
49 *Name of file to write all outgoing messages in, or nil for none. | |
50 Do not use an rmail file here! Instead, use its inbox file.") | |
51 | |
52 (defvar mail-default-reply-to nil | |
53 "*Address to insert as default Reply-to field of outgoing messages.") | |
54 | |
55 (defvar mail-alias-file nil | |
56 "*If non-nil, the name of a file to use instead of `/usr/lib/aliases'. | |
57 This file defines aliases to be expanded by the mailer; this is a different | |
58 feature from that of defining aliases in `.mailrc' to be expanded in Emacs. | |
59 This variable has no effect unless your system uses sendmail as its mailer.") | |
60 | |
61 (defvar mail-yank-prefix nil | |
62 "*Prefix insert on lines of yanked message being replied to. | |
63 nil means use indentation.") | |
64 | |
65 (defvar mail-abbrevs-loaded nil) | |
66 (defvar mail-mode-map nil) | |
67 | |
68 (defvar mail-signature nil | |
69 "*Text inserted at end of mail buffer when a message is initialized. | |
70 If t, it means to insert the contents of the file `~/.signature'.") | |
71 | |
72 (defvar mail-reply-buffer nil) | |
73 (defvar mail-send-actions nil | |
74 "A list of actions to be performed upon successful sending of a message.") | |
75 | |
76 (defvar mail-default-headers nil | |
77 "*A string containing header lines, to be inserted in outgoing messages. | |
78 It is inserted before you edit the message, | |
79 so you can edit or delete these lines.") | |
80 | |
81 (defvar mail-mode-syntax-table nil | |
82 "Syntax table used while in mail mode.") | |
83 | |
84 (if (null mail-mode-syntax-table) | |
85 (progn | |
86 (setq mail-mode-syntax-table (copy-syntax-table text-mode-syntax-table)) | |
87 (modify-syntax-entry ?% ". " mail-mode-syntax-table))) | |
88 | |
89 (defun mail-setup (to subject in-reply-to cc replybuffer actions) | |
90 (setq mail-send-actions actions) | |
474 | 91 (mail-aliases-setup) |
455 | 92 (setq mail-reply-buffer replybuffer) |
93 (goto-char (point-min)) | |
94 (insert "To: ") | |
95 (save-excursion | |
96 (if to | |
97 (progn | |
98 (insert to "\n") | |
99 ;;; Here removed code to extract names from within <...> | |
100 ;;; on the assumption that mail-strip-quoted-names | |
101 ;;; has been called and has done so. | |
102 (let ((fill-prefix "\t")) | |
103 (fill-region (point-min) (point-max)))) | |
104 (newline)) | |
105 (if cc | |
106 (let ((opos (point)) | |
107 (fill-prefix "\t")) | |
108 (insert "CC: " cc "\n") | |
109 (fill-region-as-paragraph opos (point-max)))) | |
110 (if in-reply-to | |
111 (insert "In-reply-to: " in-reply-to "\n")) | |
112 (insert "Subject: " (or subject "") "\n") | |
113 (if mail-default-headers | |
114 (insert mail-default-headers)) | |
115 (if mail-default-reply-to | |
116 (insert "Reply-to: " mail-default-reply-to "\n")) | |
117 (if mail-self-blind | |
118 (insert "BCC: " (user-login-name) "\n")) | |
119 (if mail-archive-file-name | |
120 (insert "FCC: " mail-archive-file-name "\n")) | |
121 (insert mail-header-separator "\n") | |
122 ;; Read the .signature file if we haven't already done so | |
123 ;; (and if the user has not overridden it). | |
124 (cond ((eq mail-signature t) | |
125 (insert "--\n") | |
126 (insert-file-contents "~/.signature")) | |
127 (mail-signature | |
128 (insert mail-signature))) | |
129 (goto-char (point-max)) | |
130 (or (bolp) (newline))) | |
131 (if to (goto-char (point-max))) | |
132 (or to subject in-reply-to | |
133 (set-buffer-modified-p nil)) | |
134 (run-hooks 'mail-setup-hook)) | |
135 | |
136 ;;;###autoload | |
137 (defun mail-mode () | |
138 "Major mode for editing mail to be sent. | |
139 Like Text Mode but with these additional commands: | |
140 C-c C-s mail-send (send the message) C-c C-c mail-send-and-exit | |
141 C-c C-f move to a header field (and create it if there isn't): | |
142 C-c C-f C-t move to To: C-c C-f C-s move to Subj: | |
143 C-c C-f C-b move to BCC: C-c C-f C-c move to CC: | |
144 C-c C-t move to message text. | |
145 C-c C-y mail-yank-original (insert current message, in Rmail). | |
146 C-c C-q mail-fill-yanked-message (fill what was yanked). | |
147 C-c C-v mail-sent-via (add a sent-via field for each To or CC)." | |
148 (interactive) | |
149 (kill-all-local-variables) | |
150 (make-local-variable 'mail-reply-buffer) | |
151 (setq mail-reply-buffer nil) | |
152 (make-local-variable 'mail-send-actions) | |
153 (set-syntax-table mail-mode-syntax-table) | |
154 (use-local-map mail-mode-map) | |
155 (setq local-abbrev-table text-mode-abbrev-table) | |
156 (setq major-mode 'mail-mode) | |
157 (setq mode-name "Mail") | |
158 (setq buffer-offer-save t) | |
159 (make-local-variable 'paragraph-separate) | |
160 (make-local-variable 'paragraph-start) | |
161 (setq paragraph-start (concat "^" mail-header-separator | |
162 "$\\|^[ \t]*[-_][-_][-_]+$\\|" | |
163 paragraph-start)) | |
164 (setq paragraph-separate (concat "^" mail-header-separator | |
165 "$\\|^[ \t]*[-_][-_][-_]+$\\|" | |
166 paragraph-separate)) | |
167 (run-hooks 'text-mode-hook 'mail-mode-hook)) | |
168 | |
169 (if mail-mode-map | |
170 nil | |
171 (setq mail-mode-map (nconc (make-sparse-keymap) text-mode-map)) | |
172 (define-key mail-mode-map "\C-c?" 'describe-mode) | |
173 (define-key mail-mode-map "\C-c\C-f\C-t" 'mail-to) | |
174 (define-key mail-mode-map "\C-c\C-f\C-b" 'mail-bcc) | |
573 | 175 (define-key mail-mode-map "\C-c\C-f\C-f" 'mail-fcc) |
455 | 176 (define-key mail-mode-map "\C-c\C-f\C-c" 'mail-cc) |
177 (define-key mail-mode-map "\C-c\C-f\C-s" 'mail-subject) | |
178 (define-key mail-mode-map "\C-c\C-t" 'mail-text) | |
179 (define-key mail-mode-map "\C-c\C-y" 'mail-yank-original) | |
180 (define-key mail-mode-map "\C-c\C-q" 'mail-fill-yanked-message) | |
181 (define-key mail-mode-map "\C-c\C-w" 'mail-signature) | |
182 (define-key mail-mode-map "\C-c\C-v" 'mail-sent-via) | |
183 (define-key mail-mode-map "\C-c\C-c" 'mail-send-and-exit) | |
184 (define-key mail-mode-map "\C-c\C-s" 'mail-send)) | |
185 | |
186 (defun mail-send-and-exit (arg) | |
187 "Send message like mail-send, then, if no errors, exit from mail buffer. | |
188 Prefix arg means don't delete this window." | |
189 (interactive "P") | |
190 (mail-send) | |
191 (bury-buffer (current-buffer)) | |
192 (if (or (one-window-p) arg) | |
193 (switch-to-buffer (other-buffer (current-buffer))) | |
194 (delete-window))) | |
195 | |
196 (defun mail-send () | |
197 "Send the message in the current buffer. | |
198 If `mail-interactive' is non-nil, wait for success indication | |
199 or error messages, and inform user. | |
200 Otherwise any failure is reported in a message back to | |
201 the user from the mailer." | |
202 (interactive) | |
203 (if (or (buffer-modified-p) | |
204 (y-or-n-p "Message already sent; resend? ")) | |
205 (progn | |
206 (message "Sending...") | |
207 (run-hooks 'mail-send-hook) | |
208 (funcall send-mail-function) | |
209 ;; Now perform actions on successful sending. | |
210 (while mail-send-actions | |
211 (condition-case nil | |
212 (apply (car (car mail-send-actions)) (cdr (car mail-send-actions))) | |
213 (error)) | |
214 (setq mail-send-actions (cdr mail-send-actions))) | |
215 (set-buffer-modified-p nil) | |
216 (delete-auto-save-file-if-necessary t) | |
217 (message "Sending...done")))) | |
218 | |
219 (defun sendmail-send-it () | |
220 (let ((errbuf (if mail-interactive | |
221 (generate-new-buffer " sendmail errors") | |
222 0)) | |
223 (tembuf (generate-new-buffer " sendmail temp")) | |
224 (case-fold-search nil) | |
225 delimline | |
226 (mailbuf (current-buffer))) | |
227 (unwind-protect | |
228 (save-excursion | |
229 (set-buffer tembuf) | |
230 (erase-buffer) | |
231 (insert-buffer-substring mailbuf) | |
232 (goto-char (point-max)) | |
233 ;; require one newline at the end. | |
234 (or (= (preceding-char) ?\n) | |
235 (insert ?\n)) | |
236 ;; Change header-delimiter to be what sendmail expects. | |
237 (goto-char (point-min)) | |
238 (re-search-forward | |
239 (concat "^" (regexp-quote mail-header-separator) "\n")) | |
240 (replace-match "\n") | |
241 (backward-char 1) | |
242 (setq delimline (point-marker)) | |
243 (goto-char (point-min)) | |
244 ;; ignore any blank lines in the header | |
245 (while (and (re-search-forward "\n\n\n*" delimline t) | |
246 (< (point) delimline)) | |
247 (replace-match "\n")) | |
248 (let ((case-fold-search t)) | |
249 (goto-char (point-min)) | |
250 (if (re-search-forward "^Sender:" delimline t) | |
251 (error "Sender may not be specified.")) | |
252 ;; Find and handle any FCC fields. | |
253 (goto-char (point-min)) | |
254 (if (re-search-forward "^FCC:" delimline t) | |
255 (mail-do-fcc delimline)) | |
256 ;; If the From is different than current user, insert Sender. | |
257 (goto-char (point-min)) | |
258 (and (re-search-forward "^From:" delimline t) | |
259 (progn | |
260 (require 'mail-utils) | |
261 (not (string-equal | |
262 (mail-strip-quoted-names | |
263 (save-restriction | |
264 (narrow-to-region (point-min) delimline) | |
265 (mail-fetch-field "From"))) | |
266 (user-login-name)))) | |
267 (progn | |
268 (forward-line 1) | |
269 (insert "Sender: " (user-login-name) "\n"))) | |
270 ;; "S:" is an abbreviation for "Subject:". | |
271 (goto-char (point-min)) | |
272 (if (re-search-forward "^S:" delimline t) | |
273 (replace-match "Subject:")) | |
274 ;; Don't send out a blank subject line | |
275 (goto-char (point-min)) | |
276 (if (re-search-forward "^Subject:[ \t]*\n" delimline t) | |
277 (replace-match "")) | |
278 (if mail-interactive | |
279 (save-excursion | |
280 (set-buffer errbuf) | |
281 (erase-buffer)))) | |
282 (apply 'call-process-region | |
283 (append (list (point-min) (point-max) | |
284 (if (boundp 'sendmail-program) | |
285 sendmail-program | |
286 "/usr/lib/sendmail") | |
287 nil errbuf nil | |
288 "-oi" "-t") | |
289 ;; Always specify who from, | |
290 ;; since some systems have broken sendmails. | |
291 (list "-f" (user-login-name)) | |
292 ;;; ;; Don't say "from root" if running under su. | |
293 ;;; (and (equal (user-real-login-name) "root") | |
294 ;;; (list "-f" (user-login-name))) | |
295 (and mail-alias-file | |
296 (list (concat "-oA" mail-alias-file))) | |
297 ;; These mean "report errors by mail" | |
298 ;; and "deliver in background". | |
299 (if (null mail-interactive) '("-oem" "-odb")))) | |
300 (if mail-interactive | |
301 (save-excursion | |
302 (set-buffer errbuf) | |
303 (goto-char (point-min)) | |
304 (while (re-search-forward "\n\n* *" nil t) | |
305 (replace-match "; ")) | |
306 (if (not (zerop (buffer-size))) | |
307 (error "Sending...failed to %s" | |
308 (buffer-substring (point-min) (point-max))))))) | |
309 (kill-buffer tembuf) | |
310 (if (bufferp errbuf) | |
311 (kill-buffer errbuf))))) | |
312 | |
313 (defun mail-do-fcc (header-end) | |
314 (let (fcc-list | |
315 (rmailbuf (current-buffer)) | |
316 (tembuf (generate-new-buffer " rmail output")) | |
317 (case-fold-search t)) | |
318 (save-excursion | |
319 (goto-char (point-min)) | |
320 (while (re-search-forward "^FCC:[ \t]*" header-end t) | |
321 (setq fcc-list (cons (buffer-substring (point) | |
322 (progn | |
323 (end-of-line) | |
324 (skip-chars-backward " \t") | |
325 (point))) | |
326 fcc-list)) | |
327 (delete-region (match-beginning 0) | |
328 (progn (forward-line 1) (point)))) | |
329 (set-buffer tembuf) | |
330 (erase-buffer) | |
331 (insert "\nFrom " (user-login-name) " " | |
332 (current-time-string) "\n") | |
333 (insert-buffer-substring rmailbuf) | |
334 ;; Make sure messages are separated. | |
335 (goto-char (point-max)) | |
336 (insert ?\n) | |
337 (goto-char 2) | |
338 ;; ``Quote'' "^From " as ">From " | |
339 ;; (note that this isn't really quoting, as there is no requirement | |
340 ;; that "^[>]+From " be quoted in the same transparent way.) | |
341 (let ((case-fold-search nil)) | |
342 (while (search-forward "\nFrom " nil t) | |
343 (forward-char -5) | |
344 (insert ?>))) | |
345 (while fcc-list | |
346 (let ((buffer (get-file-buffer (car fcc-list)))) | |
347 (if buffer | |
348 ;; File is present in a buffer => append to that buffer. | |
349 (let ((curbuf (current-buffer)) | |
350 (beg (point-min)) (end (point-max))) | |
351 (save-excursion | |
352 (set-buffer buffer) | |
353 ;; Keep the end of the accessible portion at the same place | |
354 ;; unless it is the end of the buffer. | |
355 (let ((max (if (/= (1+ (buffer-size)) (point-max)) | |
356 (point-max)))) | |
357 (unwind-protect | |
358 (progn | |
359 (narrow-to-region (point-min) (1+ (buffer-size))) | |
360 (goto-char (point-max)) | |
361 (if (eq major-mode 'rmail-mode) | |
362 ;; Append as a message to an RMAIL file | |
363 (let ((buffer-read-only nil)) | |
364 ;; This forces RMAIL's message counters to be | |
365 ;; recomputed when the next RMAIL operation is | |
366 ;; done on the buffer. | |
367 ;; See rmail-maybe-set-message-counters. | |
368 (setq rmail-total-messages nil) | |
369 (insert "\C-l\n0, unseen,,\n*** EOOH ***\n" | |
370 "From: " (user-login-name) "\n" | |
371 "Date: " (current-time-string) "\n") | |
372 (insert-buffer-substring curbuf beg end) | |
746
1b0748ff6f65
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
705
diff
changeset
|
373 (insert "\n\C-_") |
1b0748ff6f65
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
705
diff
changeset
|
374 (rmail-set-message-counters)) |
455 | 375 (insert-buffer-substring curbuf beg end))) |
376 (if max (narrow-to-region (point-min) max)))))) | |
377 ;; Else append to the file directly. | |
378 (write-region | |
379 ;; Include a blank line before if file already exists. | |
380 (if (file-exists-p (car fcc-list)) (point-min) (1+ (point-min))) | |
381 (point-max) (car fcc-list) t))) | |
382 (setq fcc-list (cdr fcc-list)))) | |
383 (kill-buffer tembuf))) | |
384 | |
385 (defun mail-sent-via () | |
386 "Make a Sent-via header line from each To or CC header line." | |
387 (interactive) | |
388 (save-excursion | |
389 (goto-char (point-min)) | |
390 ;; find the header-separator | |
391 (search-forward (concat "\n" mail-header-separator "\n")) | |
392 (forward-line -1) | |
393 ;; put a marker at the end of the header | |
394 (let ((end (point-marker)) | |
395 (case-fold-search t) | |
396 to-line) | |
397 (goto-char (point-min)) | |
398 ;; search for the To: lines and make Sent-via: lines from them | |
399 ;; search for the next To: line | |
400 (while (re-search-forward "^\\(to\\|cc\\):" end t) | |
401 ;; Grab this line plus all its continuations, sans the `to:'. | |
402 (let ((to-line | |
403 (buffer-substring (point) | |
404 (progn | |
405 (if (re-search-forward "^[^ \t\n]" end t) | |
406 (backward-char 1) | |
407 (goto-char end)) | |
408 (point))))) | |
409 ;; Insert a copy, with altered header field name. | |
410 (insert-before-markers "Sent-via:" to-line)))))) | |
411 | |
412 (defun mail-to () | |
413 "Move point to end of To-field." | |
414 (interactive) | |
415 (expand-abbrev) | |
416 (mail-position-on-field "To")) | |
417 | |
418 (defun mail-subject () | |
419 "Move point to end of Subject-field." | |
420 (interactive) | |
421 (expand-abbrev) | |
422 (mail-position-on-field "Subject")) | |
423 | |
424 (defun mail-cc () | |
425 "Move point to end of CC-field. Create a CC field if none." | |
426 (interactive) | |
427 (expand-abbrev) | |
428 (or (mail-position-on-field "cc" t) | |
429 (progn (mail-position-on-field "to") | |
430 (insert "\nCC: ")))) | |
431 | |
432 (defun mail-bcc () | |
433 "Move point to end of BCC-field. Create a BCC field if none." | |
434 (interactive) | |
435 (expand-abbrev) | |
436 (or (mail-position-on-field "bcc" t) | |
437 (progn (mail-position-on-field "to") | |
438 (insert "\nBCC: ")))) | |
439 | |
573 | 440 (defun mail-fcc () |
441 "Add a new FCC field, with file name completion." | |
442 (interactive) | |
443 (expand-abbrev) | |
444 (or (mail-position-on-field "fcc" t) ;Put new field after exiting FCC. | |
445 (mail-position-on-field "to")) | |
446 (insert "\nFCC: " (read-file-name "Folder carbon copy: "))) | |
447 | |
455 | 448 (defun mail-position-on-field (field &optional soft) |
449 (let (end | |
450 (case-fold-search t)) | |
451 (goto-char (point-min)) | |
604 | 452 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "\n")) |
455 | 453 (setq end (match-beginning 0)) |
454 (goto-char (point-min)) | |
455 (if (re-search-forward (concat "^" (regexp-quote field) ":") end t) | |
456 (progn | |
457 (re-search-forward "^[^ \t]" nil 'move) | |
458 (beginning-of-line) | |
459 (skip-chars-backward "\n") | |
460 t) | |
461 (or soft | |
462 (progn (goto-char end) | |
463 (skip-chars-backward "\n") | |
604 | 464 (insert field ": \n") |
465 (skip-chars-backward "\n"))) | |
455 | 466 nil))) |
467 | |
468 (defun mail-text () | |
469 "Move point to beginning of text field." | |
470 (interactive) | |
471 (goto-char (point-min)) | |
472 (search-forward (concat "\n" mail-header-separator "\n"))) | |
473 | |
679
046f1a6867e7
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
474 (defun mail-signature (atpoint) |
455 | 475 "Sign letter with contents of ~/.signature file." |
679
046f1a6867e7
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
476 (interactive "P") |
455 | 477 (save-excursion |
679
046f1a6867e7
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
478 (or atpoint |
046f1a6867e7
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
479 (goto-char (point-max))) |
455 | 480 (skip-chars-backward " \t\n") |
481 (end-of-line) | |
679
046f1a6867e7
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
482 (or atpoint |
046f1a6867e7
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
483 (delete-region (point) (point-max))) |
455 | 484 (insert "\n\n--\n") |
485 (insert-file-contents (expand-file-name "~/.signature")))) | |
486 | |
487 (defun mail-fill-yanked-message (&optional justifyp) | |
488 "Fill the paragraphs of a message yanked into this one. | |
489 Numeric argument means justify as well." | |
490 (interactive "P") | |
491 (save-excursion | |
492 (goto-char (point-min)) | |
493 (search-forward (concat "\n" mail-header-separator "\n") nil t) | |
494 (fill-individual-paragraphs (point) | |
495 (point-max) | |
496 justifyp | |
497 t))) | |
498 | |
499 (defun mail-yank-original (arg) | |
500 "Insert the message being replied to, if any (in rmail). | |
501 Puts point before the text and mark after. | |
502 Normally, indents each nonblank line ARG spaces (default 3). | |
503 However, if `mail-yank-prefix' is non-nil, insert that prefix on each line. | |
504 | |
505 Just \\[universal-argument] as argument means don't indent, insert no prefix, | |
506 and don't delete any header fields." | |
507 (interactive "P") | |
508 (if mail-reply-buffer | |
509 (let ((start (point))) | |
510 (delete-windows-on mail-reply-buffer) | |
511 (insert-buffer mail-reply-buffer) | |
512 (if (consp arg) | |
513 nil | |
514 (mail-yank-clear-headers start (mark)) | |
515 (if (null mail-yank-prefix) | |
516 (indent-rigidly start (mark) | |
517 (if arg (prefix-numeric-value arg) 3)) | |
518 (save-excursion | |
519 (goto-char start) | |
520 (while (< (point) (mark)) | |
521 (insert mail-yank-prefix) | |
522 (forward-line 1))))) | |
523 (exchange-point-and-mark) | |
524 (if (not (eolp)) (insert ?\n))))) | |
525 | |
526 (defun mail-yank-clear-headers (start end) | |
527 (save-excursion | |
528 (goto-char start) | |
529 (if (search-forward "\n\n" end t) | |
530 (save-restriction | |
531 (narrow-to-region start (point)) | |
532 (goto-char start) | |
533 (while (let ((case-fold-search t)) | |
534 (re-search-forward mail-yank-ignored-headers nil t)) | |
535 (beginning-of-line) | |
536 (delete-region (point) | |
537 (progn (re-search-forward "\n[^ \t]") | |
538 (forward-char -1) | |
539 (point)))))))) | |
540 | |
541 ;; Put these last, to reduce chance of lossage from quitting in middle of loading the file. | |
542 | |
543 ;;;###autoload | |
544 (defun mail (&optional noerase to subject in-reply-to cc replybuffer actions) | |
545 "Edit a message to be sent. Argument means resume editing (don't erase). | |
546 Search for an existing mail buffer currently not in use and initialize it, | |
547 or make a new one if all existing mail buffers are busy. | |
548 With an argument, search for a busy existing mail buffer and re-select it. | |
549 | |
550 Returns with message buffer selected; value t if message freshly initialized. | |
551 By default, the signature file `~/.signature' is inserted at the end; | |
552 see the variable `mail-signature'. | |
553 | |
554 \\<mail-mode-map> | |
555 While editing message, type \\[mail-send-and-exit] to send the message and exit. | |
556 | |
557 Various special commands starting with C-c are available in sendmail mode | |
558 to move to message header fields: | |
559 \\{mail-mode-map} | |
560 | |
561 If `mail-self-blind' is non-nil, a BCC to yourself is inserted | |
562 when the message is initialized. | |
563 | |
564 If `mail-default-reply-to' is non-nil, it should be an address (a string); | |
565 a Reply-to: field with that address is inserted. | |
566 | |
567 If `mail-archive-file-name' is non-nil, an FCC field with that file name | |
568 is inserted. | |
569 | |
570 If `mail-setup-hook' is bound, its value is called with no arguments | |
571 after the message is initialized. It can add more default fields. | |
572 | |
573 When calling from a program, the second through fifth arguments | |
574 TO, SUBJECT, IN-REPLY-TO and CC specify if non-nil | |
575 the initial contents of those header fields. | |
576 These arguments should not have final newlines. | |
577 The sixth argument REPLYBUFFER is a buffer whose contents | |
578 should be yanked if the user types C-c C-y. | |
579 The seventh argument ACTIONS is a list of actions to take | |
580 if/when the message is sent. Each action looks like (FUNCTION . ARGS); | |
581 when the message is sent, we apply FUNCTION to ARGS. | |
582 This is how Rmail arranges to mark messages `answered'." | |
583 (interactive "P") | |
584 (let ((index 1) | |
585 buffer) | |
586 ;; If requested, look for a mail buffer that is modified and go to it. | |
587 (if noerase | |
588 (progn | |
589 (while (and (setq buffer | |
590 (get-buffer (if (= 1 index) "*mail*" | |
591 (format "*mail*<%d>" index)))) | |
592 (not (buffer-modified-p buffer))) | |
593 (setq index (1+ index))) | |
594 (if buffer (switch-to-buffer buffer) | |
595 ;; If none exists, start a new message. | |
596 ;; This will never re-use an existing unmodified mail buffer | |
597 ;; (since index is not 1 anymore). Perhaps it should. | |
598 (setq noerase nil)))) | |
599 ;; Unless we found a modified message and are happy, start a new message. | |
600 (if (not noerase) | |
601 (progn | |
602 ;; Look for existing unmodified mail buffer. | |
603 (while (and (setq buffer | |
604 (get-buffer (if (= 1 index) "*mail*" | |
605 (format "*mail*<%d>" index)))) | |
606 (buffer-modified-p buffer)) | |
607 (setq index (1+ index))) | |
608 ;; If none, make a new one. | |
609 (or buffer | |
610 (setq buffer (generate-new-buffer "*mail*"))) | |
611 ;; Go there and initialize it. | |
612 (switch-to-buffer buffer) | |
613 (erase-buffer) | |
614 (setq default-directory (expand-file-name "~/")) | |
615 (auto-save-mode auto-save-default) | |
616 (mail-mode) | |
617 (mail-setup to subject in-reply-to cc replybuffer actions) | |
618 (if (and buffer-auto-save-file-name | |
619 (file-exists-p buffer-auto-save-file-name)) | |
620 (message "Auto save file for draft message exists; consider M-x mail-recover")) | |
621 t)))) | |
622 | |
623 ;;;###autoload | |
624 (define-key ctl-x-map "m" 'mail) | |
625 | |
626 (defun mail-recover () | |
627 "Reread contents of current buffer from its last auto-save file." | |
628 (interactive) | |
629 (let ((file-name (make-auto-save-file-name))) | |
630 (cond ((save-window-excursion | |
631 (if (not (eq system-type 'vax-vms)) | |
632 (with-output-to-temp-buffer "*Directory*" | |
633 (buffer-disable-undo standard-output) | |
634 (call-process "ls" nil standard-output nil "-l" file-name))) | |
635 (yes-or-no-p (format "Recover auto save file %s? " file-name))) | |
636 (let ((buffer-read-only nil)) | |
637 (erase-buffer) | |
638 (insert-file-contents file-name nil))) | |
639 (t (error "mail-recover cancelled."))))) | |
640 | |
641 ;;;###autoload | |
642 (defun mail-other-window (&optional noerase to subject in-reply-to cc replybuffer sendactions) | |
643 "Like `mail' command, but display mail buffer in another window." | |
644 (interactive "P") | |
645 (let ((pop-up-windows t)) | |
646 (pop-to-buffer "*mail*")) | |
647 (mail noerase to subject in-reply-to cc replybuffer sendactions)) | |
648 | |
649 ;;;###autoload | |
779 | 650 (defun mail-other-frame (&optional noerase to subject in-reply-to cc replybuffer sendactions) |
651 "Like `mail' command, but display mail buffer in another frame." | |
455 | 652 (interactive "P") |
779 | 653 (let ((pop-up-frames t)) |
455 | 654 (pop-to-buffer "*mail*")) |
655 (mail noerase to subject in-reply-to cc replybuffer sendactions)) | |
656 | |
657 | |
658 ;;;###autoload | |
659 (define-key ctl-x-4-map "m" 'mail-other-window) | |
660 | |
661 ;;;###autoload | |
779 | 662 (define-key ctl-x-5-map "m" 'mail-other-frame) |
455 | 663 |
664 | |
665 ;;; Do not add anything but external entries on this page. | |
584 | 666 |
667 (provide 'sendmail) | |
668 | |
658
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
604
diff
changeset
|
669 ;;; sendmail.el ends here |