(x_create_bitmap_from_file): Fail immediately if magic.
[bpt/emacs.git] / lisp / mail / smtpmail.el
CommitLineData
092af6d8 1;;; smtpmail.el --- simple SMTP protocol (RFC 821) for sending mail
24975917 2
e2f7c221 3;; Copyright (C) 1995, 1996 Free Software Foundation, Inc.
24975917
RS
4
5;; Author: Tomoji Kagatani <kagatani@rbc.ncl.omron.co.jp>
0e2701ca 6;; Maintainer: Brian D. Carlstrom <bdc@ai.mit.edu>
c50d5ce0 7;; ESMTP support: Simon Leinen <simon@switch.ch>
24975917
RS
8;; Keywords: mail
9
10;; This file is part of GNU Emacs.
11
12;; GNU Emacs is free software; you can redistribute it and/or modify
13;; it under the terms of the GNU General Public License as published by
14;; the Free Software Foundation; either version 2, or (at your option)
15;; any later version.
16
17;; GNU Emacs is distributed in the hope that it will be useful,
18;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20;; GNU General Public License for more details.
21
22;; You should have received a copy of the GNU General Public License
23;; along with GNU Emacs; see the file COPYING. If not, write to the
24;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25;; Boston, MA 02111-1307, USA.
26
27;;; Commentary:
28
29;; Send Mail to smtp host from smtpmail temp buffer.
24975917
RS
30
31;; Please add these lines in your .emacs(_emacs).
32;;
33;;(setq send-mail-function 'smtpmail-send-it)
34;;(setq smtpmail-default-smtp-server "YOUR SMTP HOST")
35;;(setq smtpmail-smtp-service "smtp")
36;;(setq smtpmail-local-domain "YOUR DOMAIN NAME")
37;;(setq smtpmail-debug-info t)
38;;(load-library "smtpmail")
39;;(setq smtpmail-code-conv-from nil)
0e2701ca 40;;(setq user-full-name "YOUR NAME HERE")
24975917 41
308bc5d8
RS
42;; To queue mail, set smtpmail-queue-mail to t and use
43;; smtpmail-send-queued-mail to send.
44
45
24975917
RS
46;;; Code:
47
48(require 'sendmail)
308bc5d8 49(require 'time-stamp)
24975917
RS
50
51;;;
00ed33e7
RS
52(defgroup smtpmail nil
53 "SMTP protocol for sending mail."
54 :group 'mail)
24975917 55
00ed33e7
RS
56
57(defcustom smtpmail-default-smtp-server nil
58 "*Specify default SMTP server."
59 :type '(choice (const nil) string)
60 :group 'smtpmail)
61
62(defcustom smtpmail-smtp-server
e2f7c221 63 (or (getenv "SMTPSERVER") smtpmail-default-smtp-server)
00ed33e7
RS
64 "*The name of the host running SMTP server."
65 :type '(choice (const nil) string)
66 :group 'smtpmail)
24975917 67
00ed33e7
RS
68(defcustom smtpmail-smtp-service 25
69 "*SMTP service port number. smtp or 25 ."
70 :type 'integer
71 :group 'smtpmail)
24975917 72
00ed33e7 73(defcustom smtpmail-local-domain nil
24975917
RS
74 "*Local domain name without a host name.
75If the function (system-name) returns the full internet address,
00ed33e7
RS
76don't define this value."
77 :type '(choice (const nil) string)
78 :group 'smtpmail)
79
80(defcustom smtpmail-debug-info nil
81 "*smtpmail debug info printout. messages and process buffer."
82 :type 'boolean
83 :group 'smtpmail)
84
85(defcustom smtpmail-code-conv-from nil ;; *junet*
86 "*smtpmail code convert from this code to *internal*..for tiny-mime.."
87 :type 'boolean
88 :group 'smtpmail)
24975917 89
308bc5d8
RS
90(defcustom smtpmail-queue-mail nil
91 "*Specify if mail is queued (if t) or sent immediately (if nil).
92If queued, it is stored in the directory `smtpmail-queue-dir'
93and sent with `smtpmail-send-queued-mail'."
94 :type 'boolean
95 :group 'smtpmail)
96
97(defcustom smtpmail-queue-dir "~/Mail/queued-mail/"
98 "*Directory where `smtpmail.el' stores queued mail."
99 :type 'directory
100 :group 'smtpmail)
101
102(defvar smtpmail-queue-index-file "index"
103 "File name of queued mail index,
104This is relative to `smtpmail-queue-dir'.")
105
106(defvar smtpmail-queue-index (concat smtpmail-queue-dir
107 smtpmail-queue-index-file))
108
24975917
RS
109;;;
110;;;
111;;;
112
113(defun smtpmail-send-it ()
e2f7c221 114 (require 'mail-utils)
24975917
RS
115 (let ((errbuf (if mail-interactive
116 (generate-new-buffer " smtpmail errors")
117 0))
118 (tembuf (generate-new-buffer " smtpmail temp"))
119 (case-fold-search nil)
24975917
RS
120 delimline
121 (mailbuf (current-buffer)))
122 (unwind-protect
123 (save-excursion
124 (set-buffer tembuf)
125 (erase-buffer)
126 (insert-buffer-substring mailbuf)
127 (goto-char (point-max))
128 ;; require one newline at the end.
129 (or (= (preceding-char) ?\n)
130 (insert ?\n))
131 ;; Change header-delimiter to be what sendmail expects.
92a3f23d 132 (mail-sendmail-undelimit-header)
24975917 133 (setq delimline (point-marker))
e2f7c221 134;; (sendmail-synch-aliases)
24975917
RS
135 (if mail-aliases
136 (expand-mail-aliases (point-min) delimline))
137 (goto-char (point-min))
138 ;; ignore any blank lines in the header
139 (while (and (re-search-forward "\n\n\n*" delimline t)
140 (< (point) delimline))
141 (replace-match "\n"))
142 (let ((case-fold-search t))
5feeeae2
RS
143 ;; We used to process Resent-... headers here,
144 ;; but it was not done properly, and the job
145 ;; is done correctly in smtpmail-deduce-address-list.
24975917
RS
146 ;; Don't send out a blank subject line
147 (goto-char (point-min))
5feeeae2
RS
148 (if (re-search-forward "^Subject:\\([ \t]*\n\\)+\\b" delimline t)
149 (replace-match "")
150 ;; This one matches a Subject just before the header delimiter.
151 (if (and (re-search-forward "^Subject:\\([ \t]*\n\\)+" delimline t)
152 (= (match-end 0) delimline))
153 (replace-match "")))
0e2701ca
RS
154 ;; Put the "From:" field in unless for some odd reason
155 ;; they put one in themselves.
156 (goto-char (point-min))
157 (if (not (re-search-forward "^From:" delimline t))
158 (let* ((login user-mail-address)
159 (fullname (user-full-name)))
160 (cond ((eq mail-from-style 'angles)
161 (insert "From: " fullname)
162 (let ((fullname-start (+ (point-min) 6))
163 (fullname-end (point-marker)))
164 (goto-char fullname-start)
165 ;; Look for a character that cannot appear unquoted
166 ;; according to RFC 822.
167 (if (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]"
168 fullname-end 1)
169 (progn
170 ;; Quote fullname, escaping specials.
171 (goto-char fullname-start)
172 (insert "\"")
173 (while (re-search-forward "[\"\\]"
174 fullname-end 1)
175 (replace-match "\\\\\\&" t))
176 (insert "\""))))
177 (insert " <" login ">\n"))
178 ((eq mail-from-style 'parens)
179 (insert "From: " login " (")
180 (let ((fullname-start (point)))
181 (insert fullname)
182 (let ((fullname-end (point-marker)))
183 (goto-char fullname-start)
184 ;; RFC 822 says \ and nonmatching parentheses
185 ;; must be escaped in comments.
186 ;; Escape every instance of ()\ ...
187 (while (re-search-forward "[()\\]" fullname-end 1)
188 (replace-match "\\\\\\&" t))
189 ;; ... then undo escaping of matching parentheses,
190 ;; including matching nested parentheses.
191 (goto-char fullname-start)
192 (while (re-search-forward
193 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
194 fullname-end 1)
195 (replace-match "\\1(\\3)" t)
196 (goto-char fullname-start))))
197 (insert ")\n"))
198 ((null mail-from-style)
199 (insert "From: " login "\n")))))
24975917
RS
200 ;; Insert an extra newline if we need it to work around
201 ;; Sun's bug that swallows newlines.
202 (goto-char (1+ delimline))
203 (if (eval mail-mailer-swallows-blank-line)
204 (newline))
0e2701ca
RS
205 ;; Find and handle any FCC fields.
206 (goto-char (point-min))
207 (if (re-search-forward "^FCC:" delimline t)
208 (mail-do-fcc delimline))
24975917
RS
209 (if mail-interactive
210 (save-excursion
211 (set-buffer errbuf)
212 (erase-buffer))))
213 ;;
214 ;;
215 ;;
216 (setq smtpmail-address-buffer (generate-new-buffer "*smtp-mail*"))
217 (setq smtpmail-recipient-address-list
5feeeae2 218 (smtpmail-deduce-address-list tembuf (point-min) delimline))
24975917 219 (kill-buffer smtpmail-address-buffer)
308bc5d8 220
24975917 221 (smtpmail-do-bcc delimline)
308bc5d8
RS
222 ; Send or queue
223 (if (not smtpmail-queue-mail)
224 (if (not (null smtpmail-recipient-address-list))
225 (if (not (smtpmail-via-smtp
226 smtpmail-recipient-address-list tembuf))
227 (error "Sending failed; SMTP protocol error"))
228 (error "Sending failed; no recipients"))
229 (let* ((file-data (concat
230 smtpmail-queue-dir
3375a61c
KH
231 (concat (time-stamp-yyyy-mm-dd)
232 "_" (time-stamp-hh:mm:ss))))
308bc5d8
RS
233 (file-elisp (concat file-data ".el"))
234 (buffer-data (create-file-buffer file-data))
235 (buffer-elisp (create-file-buffer file-elisp))
236 (buffer-scratch "*queue-mail*"))
237 (save-excursion
238 (set-buffer buffer-data)
239 (erase-buffer)
240 (insert-buffer tembuf)
241 (write-file file-data)
242 (set-buffer buffer-elisp)
243 (erase-buffer)
244 (insert (concat
245 "(setq smtpmail-recipient-address-list '"
246 (prin1-to-string smtpmail-recipient-address-list)
247 ")\n"))
248 (write-file file-elisp)
249 (set-buffer (generate-new-buffer buffer-scratch))
250 (insert (concat file-data "\n"))
251 (append-to-file (point-min)
252 (point-max)
253 smtpmail-queue-index)
254 )
255 (kill-buffer buffer-scratch)
256 (kill-buffer buffer-data)
257 (kill-buffer buffer-elisp))))
24975917
RS
258 (kill-buffer tembuf)
259 (if (bufferp errbuf)
260 (kill-buffer errbuf)))))
261
308bc5d8
RS
262(defun smtpmail-send-queued-mail ()
263 "Send mail that was queued as a result of setting `smtpmail-queue-mail'."
264 (interactive)
265 ;;; Get index, get first mail, send it, get second mail, etc...
266 (let ((buffer-index (find-file-noselect smtpmail-queue-index))
267 (file-msg "")
268 (tembuf nil))
269 (save-excursion
270 (set-buffer buffer-index)
271 (beginning-of-buffer)
272 (while (not (eobp))
273 (setq file-msg (buffer-substring (point) (save-excursion
274 (end-of-line)
275 (point))))
276 (load file-msg)
277 (setq tembuf (find-file-noselect file-msg))
278 (if (not (null smtpmail-recipient-address-list))
279 (if (not (smtpmail-via-smtp smtpmail-recipient-address-list
280 tembuf))
281 (error "Sending failed; SMTP protocol error"))
282 (error "Sending failed; no recipients"))
283 (delete-file file-msg)
284 (delete-file (concat file-msg ".el"))
285 (kill-buffer tembuf)
286 (kill-line 1))
287 (set-buffer buffer-index)
288 (save-buffer smtpmail-queue-index)
289 (kill-buffer buffer-index)
290 )))
24975917
RS
291
292;(defun smtpmail-via-smtp (host,port,sender,destination,smtpmail-text-buffer)
293
294(defun smtpmail-fqdn ()
295 (if smtpmail-local-domain
296 (concat (system-name) "." smtpmail-local-domain)
297 (system-name)))
298
299(defun smtpmail-via-smtp (recipient smtpmail-text-buffer)
300 (let ((process nil)
8805249b
RS
301 (host smtpmail-smtp-server)
302 (port smtpmail-smtp-service)
24975917 303 response-code
8805249b 304 greeting
c50d5ce0
RS
305 process-buffer
306 (supported-extensions '()))
24975917
RS
307 (unwind-protect
308 (catch 'done
309 ;; get or create the trace buffer
310 (setq process-buffer
311 (get-buffer-create (format "*trace of SMTP session to %s*" host)))
312
313 ;; clear the trace buffer of old output
314 (save-excursion
315 (set-buffer process-buffer)
316 (erase-buffer))
317
318 ;; open the connection to the server
319 (setq process (open-network-stream "SMTP" process-buffer host port))
320 (and (null process) (throw 'done nil))
321
322 ;; set the send-filter
323 (set-process-filter process 'smtpmail-process-filter)
324
325 (save-excursion
326 (set-buffer process-buffer)
4b876894 327 (set-buffer-process-coding-system 'raw-text-unix 'raw-text-unix)
24975917
RS
328 (make-local-variable 'smtpmail-read-point)
329 (setq smtpmail-read-point (point-min))
330
331
332 (if (or (null (car (setq greeting (smtpmail-read-response process))))
333 (not (integerp (car greeting)))
334 (>= (car greeting) 400))
335 (throw 'done nil)
336 )
337
c50d5ce0
RS
338 ;; EHLO
339 (smtpmail-send-command process (format "EHLO %s" (smtpmail-fqdn)))
24975917
RS
340
341 (if (or (null (car (setq response-code (smtpmail-read-response process))))
342 (not (integerp (car response-code)))
343 (>= (car response-code) 400))
c50d5ce0
RS
344 (progn
345 ;; HELO
346 (smtpmail-send-command process (format "HELO %s" (smtpmail-fqdn)))
347
348 (if (or (null (car (setq response-code (smtpmail-read-response process))))
349 (not (integerp (car response-code)))
350 (>= (car response-code) 400))
351 (throw 'done nil)))
352 (let ((extension-lines (cdr (cdr response-code))))
353 (while extension-lines
354 (let ((name (intern (downcase (substring (car extension-lines) 4)))))
355 (and name
356 (cond ((memq name '(verb xvrb 8bitmime onex xone
357 expn size dsn etrn
358 help xusr))
359 (setq supported-extensions
360 (cons name supported-extensions)))
361 (t (message "unknown extension %s"
362 name)))))
363 (setq extension-lines (cdr extension-lines)))))
364
365 (if (or (member 'onex supported-extensions)
366 (member 'xone supported-extensions))
367 (progn
368 (smtpmail-send-command process (format "ONEX"))
369 (if (or (null (car (setq response-code (smtpmail-read-response process))))
370 (not (integerp (car response-code)))
371 (>= (car response-code) 400))
372 (throw 'done nil))))
373
374 (if (and smtpmail-debug-info
375 (or (member 'verb supported-extensions)
376 (member 'xvrb supported-extensions)))
377 (progn
378 (smtpmail-send-command process (format "VERB"))
379 (if (or (null (car (setq response-code (smtpmail-read-response process))))
380 (not (integerp (car response-code)))
381 (>= (car response-code) 400))
382 (throw 'done nil))))
383
384 (if (member 'xusr supported-extensions)
385 (progn
386 (smtpmail-send-command process (format "XUSR"))
387 (if (or (null (car (setq response-code (smtpmail-read-response process))))
388 (not (integerp (car response-code)))
389 (>= (car response-code) 400))
390 (throw 'done nil))))
24975917
RS
391
392 ;; MAIL FROM: <sender>
c50d5ce0
RS
393 (let ((size-part
394 (if (member 'size supported-extensions)
395 (format " SIZE=%d"
396 (save-excursion
397 (set-buffer smtpmail-text-buffer)
398 ;; size estimate:
399 (+ (- (point-max) (point-min))
400 ;; Add one byte for each change-of-line
401 ;; because or CR-LF representation:
402 (count-lines (point-min) (point-max))
403 ;; For some reason, an empty line is
404 ;; added to the message. Maybe this
405 ;; is a bug, but it can't hurt to add
406 ;; those two bytes anyway:
407 2)))
408 ""))
409 (body-part
410 (if (member '8bitmime supported-extensions)
411 ;; FIXME:
412 ;; Code should be added here that transforms
413 ;; the contents of the message buffer into
414 ;; something the receiving SMTP can handle.
415 ;; For a receiver that supports 8BITMIME, this
416 ;; may mean converting BINARY to BASE64, or
417 ;; adding Content-Transfer-Encoding and the
418 ;; other MIME headers. The code should also
419 ;; return an indication of what encoding the
420 ;; message buffer is now, i.e. ASCII or
421 ;; 8BITMIME.
422 (if nil
423 " BODY=8BITMIME"
424 "")
425 "")))
426; (smtpmail-send-command process (format "MAIL FROM:%s@%s" (user-login-name) (smtpmail-fqdn)))
427 (smtpmail-send-command process (format "MAIL FROM: <%s>%s%s"
428 user-mail-address
429 size-part
430 body-part))
431
432 (if (or (null (car (setq response-code (smtpmail-read-response process))))
433 (not (integerp (car response-code)))
434 (>= (car response-code) 400))
435 (throw 'done nil)
436 ))
24975917
RS
437
438 ;; RCPT TO: <recipient>
8805249b
RS
439 (let ((n 0))
440 (while (not (null (nth n recipient)))
b21dc761 441 (smtpmail-send-command process (format "RCPT TO: <%s>" (nth n recipient)))
8805249b
RS
442 (setq n (1+ n))
443
c50d5ce0
RS
444 (setq response-code (smtpmail-read-response process))
445 (if (or (null (car response-code))
8805249b
RS
446 (not (integerp (car response-code)))
447 (>= (car response-code) 400))
448 (throw 'done nil)
449 )
450 ))
24975917
RS
451
452 ;; DATA
453 (smtpmail-send-command process "DATA")
454
455 (if (or (null (car (setq response-code (smtpmail-read-response process))))
456 (not (integerp (car response-code)))
457 (>= (car response-code) 400))
458 (throw 'done nil)
459 )
460
461 ;; Mail contents
462 (smtpmail-send-data process smtpmail-text-buffer)
463
464 ;;DATA end "."
465 (smtpmail-send-command process ".")
466
467 (if (or (null (car (setq response-code (smtpmail-read-response process))))
468 (not (integerp (car response-code)))
469 (>= (car response-code) 400))
470 (throw 'done nil)
471 )
472
473 ;;QUIT
474; (smtpmail-send-command process "QUIT")
475; (and (null (car (smtpmail-read-response process)))
476; (throw 'done nil))
477 t ))
478 (if process
479 (save-excursion
480 (set-buffer (process-buffer process))
481 (smtpmail-send-command process "QUIT")
482 (smtpmail-read-response process)
483
484; (if (or (null (car (setq response-code (smtpmail-read-response process))))
485; (not (integerp (car response-code)))
486; (>= (car response-code) 400))
487; (throw 'done nil)
488; )
489 (delete-process process))))))
490
491
24975917
RS
492(defun smtpmail-process-filter (process output)
493 (save-excursion
494 (set-buffer (process-buffer process))
495 (goto-char (point-max))
496 (insert output)))
497
24975917
RS
498(defun smtpmail-read-response (process)
499 (let ((case-fold-search nil)
c50d5ce0 500 (response-strings nil)
24975917 501 (response-continue t)
c50d5ce0 502 (return-value '(nil ()))
24975917
RS
503 match-end)
504
24975917 505 (while response-continue
c8d16dbd 506 (goto-char smtpmail-read-point)
24975917
RS
507 (while (not (search-forward "\r\n" nil t))
508 (accept-process-output process)
509 (goto-char smtpmail-read-point))
510
511 (setq match-end (point))
c50d5ce0
RS
512 (setq response-strings
513 (cons (buffer-substring smtpmail-read-point (- match-end 2))
514 response-strings))
24975917
RS
515
516 (goto-char smtpmail-read-point)
517 (if (looking-at "[0-9]+ ")
c50d5ce0
RS
518 (let ((begin (match-beginning 0))
519 (end (match-end 0)))
520 (if smtpmail-debug-info
521 (message "%s" (car response-strings)))
24975917 522
c50d5ce0 523 (setq smtpmail-read-point match-end)
24975917 524
c50d5ce0
RS
525 ;; ignore lines that start with "0"
526 (if (looking-at "0[0-9]+ ")
527 nil
528 (setq response-continue nil)
529 (setq return-value
530 (cons (string-to-int
531 (buffer-substring begin end))
532 (nreverse response-strings)))))
24975917
RS
533
534 (if (looking-at "[0-9]+-")
c50d5ce0
RS
535 (progn (if smtpmail-debug-info
536 (message "%s" (car response-strings)))
537 (setq smtpmail-read-point match-end)
24975917
RS
538 (setq response-continue t))
539 (progn
540 (setq smtpmail-read-point match-end)
541 (setq response-continue nil)
542 (setq return-value
c50d5ce0 543 (cons nil (nreverse response-strings)))
24975917
RS
544 )
545 )))
546 (setq smtpmail-read-point match-end)
547 return-value))
548
549
24975917
RS
550(defun smtpmail-send-command (process command)
551 (goto-char (point-max))
552 (if (= (aref command 0) ?P)
553 (insert "PASS <omitted>\r\n")
554 (insert command "\r\n"))
555 (setq smtpmail-read-point (point))
556 (process-send-string process command)
557 (process-send-string process "\r\n"))
558
24975917
RS
559(defun smtpmail-send-data-1 (process data)
560 (goto-char (point-max))
561
562 (if (not (null smtpmail-code-conv-from))
563 (setq data (code-convert-string data smtpmail-code-conv-from *internal*)))
564
565 (if smtpmail-debug-info
566 (insert data "\r\n"))
567
568 (setq smtpmail-read-point (point))
57810560
KH
569 ;; Escape "." at start of a line
570 (if (eq (string-to-char data) ?.)
24975917 571 (process-send-string process "."))
57810560 572 (process-send-string process data)
24975917
RS
573 (process-send-string process "\r\n")
574 )
575
576(defun smtpmail-send-data (process buffer)
577 (let
578 ((data-continue t)
579 (sending-data nil)
580 this-line
581 this-line-end)
582
583 (save-excursion
584 (set-buffer buffer)
585 (goto-char (point-min)))
586
587 (while data-continue
588 (save-excursion
589 (set-buffer buffer)
590 (beginning-of-line)
591 (setq this-line (point))
592 (end-of-line)
593 (setq this-line-end (point))
594 (setq sending-data nil)
595 (setq sending-data (buffer-substring this-line this-line-end))
596 (if (/= (forward-line 1) 0)
597 (setq data-continue nil)))
598
599 (smtpmail-send-data-1 process sending-data)
600 )
601 )
602 )
603
604
605(defun smtpmail-deduce-address-list (smtpmail-text-buffer header-start header-end)
606 "Get address list suitable for smtp RCPT TO: <address>."
607 (require 'mail-utils) ;; pick up mail-strip-quoted-names
608 (let
609 ((case-fold-search t)
610 (simple-address-list "")
611 this-line
13f1d088
KH
612 this-line-end
613 addr-regexp)
24975917
RS
614
615 (unwind-protect
616 (save-excursion
617 ;;
618 (set-buffer smtpmail-address-buffer) (erase-buffer)
619 (insert-buffer-substring smtpmail-text-buffer header-start header-end)
620 (goto-char (point-min))
13f1d088
KH
621 ;; RESENT-* fields should stop processing of regular fields.
622 (save-excursion
5feeeae2
RS
623 (if (re-search-forward "^Resent-\\(to\\|cc\\|bcc\\):" header-end t)
624 (setq addr-regexp "^Resent-\\(to\\|cc\\|bcc\\):")
625 (setq addr-regexp "^\\(To:\\|Cc:\\|Bcc:\\)")))
13f1d088
KH
626
627 (while (re-search-forward addr-regexp header-end t)
24975917
RS
628 (replace-match "")
629 (setq this-line (match-beginning 0))
630 (forward-line 1)
631 ;; get any continuation lines
632 (while (and (looking-at "^[ \t]+") (< (point) header-end))
633 (forward-line 1))
634 (setq this-line-end (point-marker))
635 (setq simple-address-list
636 (concat simple-address-list " "
637 (mail-strip-quoted-names (buffer-substring this-line this-line-end))))
638 )
639 (erase-buffer)
640 (insert-string " ")
641 (insert-string simple-address-list)
642 (insert-string "\n")
643 (subst-char-in-region (point-min) (point-max) 10 ? t);; newline --> blank
644 (subst-char-in-region (point-min) (point-max) ?, ? t);; comma --> blank
645 (subst-char-in-region (point-min) (point-max) 9 ? t);; tab --> blank
646
647 (goto-char (point-min))
648 ;; tidyness in case hook is not robust when it looks at this
649 (while (re-search-forward "[ \t]+" header-end t) (replace-match " "))
650
651 (goto-char (point-min))
8805249b 652 (let (recipient-address-list)
e2f7c221 653 (while (re-search-forward " \\([^ ]+\\) " (point-max) t)
8805249b 654 (backward-char 1)
e2f7c221
RS
655 (setq recipient-address-list (cons (buffer-substring (match-beginning 1) (match-end 1))
656 recipient-address-list))
8805249b
RS
657 )
658 (setq smtpmail-recipient-address-list recipient-address-list))
24975917
RS
659
660 )
661 )
662 )
663 )
664
665
666(defun smtpmail-do-bcc (header-end)
5feeeae2 667 "Delete [Resent-]BCC: and their continuation lines from the header area.
24975917
RS
668There may be multiple BCC: lines, and each may have arbitrarily
669many continuation lines."
670 (let ((case-fold-search t))
671 (save-excursion (goto-char (point-min))
672 ;; iterate over all BCC: lines
5feeeae2 673 (while (re-search-forward "^\(RESENT-\)?BCC:" header-end t)
24975917
RS
674 (delete-region (match-beginning 0) (progn (forward-line 1) (point)))
675 ;; get rid of any continuation lines
676 (while (and (looking-at "^[ \t].*\n") (< (point) header-end))
677 (replace-match ""))
678 )
679 ) ;; save-excursion
680 ) ;; let
681 )
682
683
684
685(provide 'smtpmail)
686
092af6d8 687;;; smtpmail.el ends here