;; Please add these lines in your .emacs(_emacs) or use customize.
;;
;;(setq send-mail-function 'smtpmail-send-it) ; if you use `mail'
-;;(setq message-send-mail-function 'smtpmail-send-it) ; if you are using Gnus.
+;;(setq message-send-mail-function 'smtpmail-send-it) ; if you use message/Gnus
;;(setq smtpmail-default-smtp-server "YOUR SMTP HOST")
;;(setq smtpmail-local-domain "YOUR DOMAIN NAME")
;;(setq smtpmail-sendto-domain "YOUR DOMAIN NAME")
(autoload 'starttls-open-stream "starttls")
(autoload 'starttls-negotiate "starttls")
(autoload 'mail-strip-quoted-names "mail-utils")
+(autoload 'message-make-date "message")
+(autoload 'message-make-message-id "message")
(autoload 'rfc2104-hash "rfc2104")
;;;
(defvar smtpmail-address-buffer)
(defvar smtpmail-recipient-address-list)
+(defvar smtpmail-queue-counter 0)
+
;; Buffer-local variable.
(defvar smtpmail-read-point)
(insert ")\n"))
((null mail-from-style)
(insert "From: " login "\n")))))
+ ;; Insert a `Message-Id:' field if there isn't one yet.
+ (goto-char (point-min))
+ (unless (re-search-forward "^Message-Id:" delimline t)
+ (insert "Message-Id: " (message-make-message-id) "\n"))
+ ;; Insert a `Date:' field if there isn't one yet.
+ (goto-char (point-min))
+ (unless (re-search-forward "^Date:" delimline t)
+ (insert "Date: " (message-make-date) "\n"))
;; Insert an extra newline if we need it to work around
;; Sun's bug that swallows newlines.
(goto-char (1+ delimline))
(if (re-search-forward "^FCC:" delimline t)
(mail-do-fcc delimline))
(if mail-interactive
- (save-excursion
- (set-buffer errbuf)
+ (with-current-buffer errbuf
(erase-buffer))))
;;
;;
(let* ((file-data (concat
smtpmail-queue-dir
(concat (time-stamp-yyyy-mm-dd)
- "_" (time-stamp-hh:mm:ss))))
- (file-data (convert-standard-filename file-data))
+ "_" (time-stamp-hh:mm:ss)
+ "_"
+ (setq smtpmail-queue-counter
+ (1+ smtpmail-queue-counter)))))
(file-elisp (concat file-data ".el"))
(buffer-data (create-file-buffer file-data))
(buffer-elisp (create-file-buffer file-elisp))
(buffer-scratch "*queue-mail*"))
- (save-excursion
- (set-buffer buffer-data)
+ (with-current-buffer buffer-data
(erase-buffer)
(insert-buffer tembuf)
(write-file file-data)
(defun smtpmail-send-queued-mail ()
"Send mail that was queued as a result of setting `smtpmail-queue-mail'."
(interactive)
- ;;; Get index, get first mail, send it, get second mail, etc...
- (let ((buffer-index (find-file-noselect smtpmail-queue-index))
- (file-msg "")
- (tembuf nil))
- (save-excursion
- (set-buffer buffer-index)
+ (with-temp-buffer
+ ;;; Get index, get first mail, send it, update index, get second
+ ;;; mail, send it, etc...
+ (let ((file-msg ""))
+ (insert-file-contents smtpmail-queue-index)
(beginning-of-buffer)
(while (not (eobp))
- (setq file-msg (buffer-substring (point) (save-excursion
- (end-of-line)
- (point))))
+ (setq file-msg (buffer-substring (point) (line-end-position)))
(load file-msg)
- (setq tembuf (find-file-noselect file-msg))
- (if (not (null smtpmail-recipient-address-list))
- (if (not (smtpmail-via-smtp smtpmail-recipient-address-list
- tembuf))
- (error "Sending failed; SMTP protocol error"))
- (error "Sending failed; no recipients"))
+ ;; Insert the message literally: it is already encoded as per
+ ;; the MIME headers, and code conversions might guess the
+ ;; encoding wrongly.
+ (with-temp-buffer
+ (let ((coding-system-for-read 'no-conversion))
+ (insert-file-contents file-msg))
+ (if (not (null smtpmail-recipient-address-list))
+ (if (not (smtpmail-via-smtp smtpmail-recipient-address-list
+ (current-buffer)))
+ (error "Sending failed; SMTP protocol error"))
+ (error "Sending failed; no recipients")))
(delete-file file-msg)
(delete-file (concat file-msg ".el"))
- (kill-buffer tembuf)
- (kill-line 1))
- (set-buffer buffer-index)
- (save-buffer smtpmail-queue-index)
- (kill-buffer buffer-index)
- )))
+ (kill-line 1))
+ (write-region (point-min) (point-max) smtpmail-queue-index))))
;(defun smtpmail-via-smtp (host,port,sender,destination,smtpmail-text-buffer)
(get-buffer-create (format "*trace of SMTP session to %s*" host)))
;; clear the trace buffer of old output
- (save-excursion
- (set-buffer process-buffer)
+ (with-current-buffer process-buffer
(erase-buffer))
;; open the connection to the server
;; set the send-filter
(set-process-filter process 'smtpmail-process-filter)
- (save-excursion
- (set-buffer process-buffer)
+ (with-current-buffer process-buffer
(set-buffer-process-coding-system 'raw-text-unix 'raw-text-unix)
(make-local-variable 'smtpmail-read-point)
(setq smtpmail-read-point (point-min))
(if (or (member 'size supported-extensions)
(assoc 'size supported-extensions))
(format " SIZE=%d"
- (save-excursion
- (set-buffer smtpmail-text-buffer)
+ (with-current-buffer smtpmail-text-buffer
;; size estimate:
(+ (- (point-max) (point-min))
;; Add one byte for each change-of-line
; (throw 'done nil))
t ))
(if process
- (save-excursion
- (set-buffer (process-buffer process))
+ (with-current-buffer (process-buffer process)
(smtpmail-send-command process "QUIT")
(smtpmail-read-response process)
(defun smtpmail-process-filter (process output)
- (save-excursion
- (set-buffer (process-buffer process))
+ (with-current-buffer (process-buffer process)
(goto-char (point-max))
(insert output)))
this-line
this-line-end)
- (save-excursion
- (set-buffer buffer)
+ (with-current-buffer buffer
(goto-char (point-min)))
(while data-continue
- (save-excursion
- (set-buffer buffer)
+ (with-current-buffer buffer
(beginning-of-line)
(setq this-line (point))
(end-of-line)
(defun smtpmail-deduce-address-list (smtpmail-text-buffer header-start header-end)
"Get address list suitable for smtp RCPT TO: <address>."
(unwind-protect
- (save-excursion
- (set-buffer smtpmail-address-buffer) (erase-buffer)
+ (with-current-buffer smtpmail-address-buffer
+ (erase-buffer)
(let
((case-fold-search t)
(simple-address-list "")
(goto-char (point-min))
;; RESENT-* fields should stop processing of regular fields.
(save-excursion
- (if (re-search-forward "^Resent-\\(to\\|cc\\|bcc\\):" header-end t)
- (setq addr-regexp "^Resent-\\(to\\|cc\\|bcc\\):")
- (setq addr-regexp "^\\(To:\\|Cc:\\|Bcc:\\)")))
+ (setq addr-regexp
+ (if (re-search-forward "^Resent-\\(to\\|cc\\|bcc\\):"
+ header-end t)
+ "^Resent-\\(to\\|cc\\|bcc\\):"
+ "^\\(To:\\|Cc:\\|Bcc:\\)")))
(while (re-search-forward addr-regexp header-end t)
(replace-match "")
(mail-strip-quoted-names (buffer-substring this-line this-line-end))))
)
(erase-buffer)
- (insert-string " ")
- (insert-string simple-address-list)
- (insert-string "\n")
+ (insert " " simple-address-list "\n")
(subst-char-in-region (point-min) (point-max) 10 ? t);; newline --> blank
(subst-char-in-region (point-min) (point-max) ?, ? t);; comma --> blank
(subst-char-in-region (point-min) (point-max) 9 ? t);; tab --> blank