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