Subject: [[email-masked]: Re: smtpmail_delay.el: queues messages instead of sending them immediately]

From: Richard Stallman <[email-masked]>
Date: Mon, 27 Jan 1997 01:12:52 -0500

Here is the queueing patch for which I am awaiting papers.
What do you think of it?

------- Start of forwarded message -------
Date: Tue, 21 Jan 1997 19:37:57 +0800 (CST)
From: Georges KO <[email-masked]>
Reply-To: [email-masked], [email-masked]
X-Machine: Linux gabegie 2.0.0 #7 Mon Nov 11 22:38:50 CST 1996 i586
MIME-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfert-Encoding: 8bit
To: [email-masked]
In-reply-to: <[email-masked]> (message from
	Richard Stallman on Tue, 21 Jan 1997 03:55:17 -0500)
Subject: Re: smtpmail_delay.el: queues messages instead of sending them immediately

> Could you possibly rewrite this
> into a version of smtpmail.el which uses a Lisp variable
> to control whether to queue or not?

	OK, it's called smtpmail_off.el in the patch.

> I think that interface is more convenient, and I'd like to install
> the changes in Emacs if you do them that way.

	Great!

gko@gabegie:~/elisp 501 $ diff -c smtpmail.el smtpmail_off.el
*** smtpmail.el	Tue Jan 21 19:16:48 1997
- --- smtpmail_off.el	Tue Jan 21 19:15:46 1997
***************
*** 38,46 ****
- --- 38,51 ----
  ;;(setq smtpmail-code-conv-from nil)
  ;;(setq user-full-name "YOUR NAME HERE")
  
+ ;; To queue mail, set smtpmail-queue-mail to t and use 
+ ;; smtpmail-send-queued-mail to send.
+ 
+ 
  ;;; Code:
  
  (require 'sendmail)
+ (require 'time-stamp)
  
  ;;;
  (defvar smtpmail-default-smtp-server nil
***************
*** 64,73 ****
- --- 69,91 ----
  (defvar smtpmail-code-conv-from nil ;; *junet*
    "*smtpmail code convert from this code to *internal*..for tiny-mime..")
  
+ (defvar smtpmail-queue-mail nil 
+   "*Specify if mail is queued (if t) or sent immediately (if nil).
+ If queued, it is stored in the directory `smtpmail-queue-dir'
+ and sent with `smtpmail-send-queued-mail'.")
+ 
+ (defvar smtpmail-queue-dir "~/Mail/queued-mail/"
+   "Directory where queued mail is stored.")
+ (defvar smtpmail-queue-index-file "index"
+   "Filename of queued mail index")
+ 
  ;;;
  ;;;
  ;;;
  
+ (defvar smtpmail-queue-index (concat smtpmail-queue-dir
+ 					    smtpmail-queue-index-file))
+ 
  (defun smtpmail-send-it ()
    (require 'mail-utils)
    (let ((errbuf (if mail-interactive
***************
*** 200,217 ****
  		(or resend-to-addresses
  		    (smtpmail-deduce-address-list tembuf (point-min) delimline)))
  	  (kill-buffer smtpmail-address-buffer)
! 
  	  (smtpmail-do-bcc delimline)
! 
! 	  (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"))
! 	  )
        (kill-buffer tembuf)
        (if (bufferp errbuf)
  	  (kill-buffer errbuf)))))

  ;(defun smtpmail-via-smtp (host,port,sender,destination,smtpmail-text-buffer)
  
- --- 218,294 ----
  		(or resend-to-addresses
  		    (smtpmail-deduce-address-list tembuf (point-min) delimline)))
  	  (kill-buffer smtpmail-address-buffer)
! 	  
  	  (smtpmail-do-bcc delimline)
! 	  ; Send or queue
! 	  (if (not smtpmail-queue-mail)
! 	      (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"))
! 	    (let* ((file-data (concat 
! 			       smtpmail-queue-dir
! 			       (time-stamp-strftime 
! 				"%02y%02m%02d-%02H%02M%02S")))
! 		   (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)
! 		(erase-buffer)
! 		(insert-buffer tembuf)
! 		(write-file file-data)
! 		(set-buffer buffer-elisp)
! 		(erase-buffer)
! 		(insert (concat
! 			 "(setq smtpmail-recipient-address-list '"
! 			 (prin1-to-string smtpmail-recipient-address-list)
! 			 ")\n"))	    	    
! 		(write-file file-elisp)
! 		(set-buffer (generate-new-buffer buffer-scratch))
! 		(insert (concat file-data "\n"))
! 		(append-to-file (point-min) 
! 				(point-max) 
! 				smtpmail-queue-index)
! 		)
! 	      (kill-buffer buffer-scratch)
! 	      (kill-buffer buffer-data)
! 	      (kill-buffer buffer-elisp))))
        (kill-buffer tembuf)
        (if (bufferp errbuf)
  	  (kill-buffer errbuf)))))
  
+ (defun smtpmail-send-queued-mail ()
+   "Sends mail queued by smtpmail-send-it with smtpmail-queue-mail set to t."
+   (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)
+       (beginning-of-buffer)
+       (while (not (eobp))
+ 	(setq file-msg (buffer-substring (point) (save-excursion
+ 						   (end-of-line)
+ 						   (point))))
+ 	(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"))  
+ 	(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)
+       )))
  
  ;(defun smtpmail-via-smtp (host,port,sender,destination,smtpmail-text-buffer)
- -- 
 Georges KO at mailto:[email-masked] and mailto:[email-masked]
 http://mtc.ntnu.edu.tw:52021/~m52021
------- End of forwarded message -------

- -- 
We are holding the second free software conference in San Francisco on
February 20-21.  We hope you can come.  For more info, see
http://www.gnu.ai.mit.edu/conferences/97san-fran/announcement.html or
write to [email-masked].