]> code.delx.au - gnu-emacs/blobdiff - lisp/mail/smtpmail.el
(smtpmail-queue-counter): New variable.
[gnu-emacs] / lisp / mail / smtpmail.el
index ed4bd7c8ddd42a356fa2e652ac32798f60faae39..8353653526b48b3bf63f7f2cc5c772baba366bda 100644 (file)
@@ -35,7 +35,7 @@
 ;; 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")
@@ -191,6 +191,8 @@ This is relative to `smtpmail-queue-dir'.")
 (defvar smtpmail-address-buffer)
 (defvar smtpmail-recipient-address-list)
 
+(defvar smtpmail-queue-counter 0)
+
 ;; Buffer-local variable.
 (defvar smtpmail-read-point)
 
@@ -334,8 +336,10 @@ This is relative to `smtpmail-queue-dir'.")
            (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))
@@ -367,29 +371,30 @@ This is relative to `smtpmail-queue-dir'.")
 (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))
-    (with-current-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) (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)