From jidzikowski at common-lisp.net Wed Sep 8 14:49:10 2010 From: jidzikowski at common-lisp.net (jidzikowski) Date: Wed, 08 Sep 2010 10:49:10 -0400 Subject: [cl-smtp-cvs] CVS cl-smtp Message-ID: Update of /project/cl-smtp/cvsroot/cl-smtp In directory cl-net:/tmp/cvs-serv4206 Modified Files: CHANGELOG README cl-smtp.asd cl-smtp.lisp Log Message: Add keyword envelope-sender to send-email, if envelope-sender not set then envelope-sender = from argument. Change x-mailer header setting. ---------------------------------------------------------------------- --- /project/cl-smtp/cvsroot/cl-smtp/CHANGELOG 2010/06/21 09:06:26 1.18 +++ /project/cl-smtp/cvsroot/cl-smtp/CHANGELOG 2010/09/08 14:49:10 1.19 @@ -1,3 +1,10 @@ +Version 20100908.1 +2010.09.08 +Add keyword envelope-sender to send-email, if envelope-sender not set then +envelope-sender = from argument. +Change x-mailer header setting. +Change cl-smtp.lisp, cl-smtp.asd, CHANGELOG, README + Version 20100621.1 2010.06.21 Rewrite base64-encode-file in attachments.lisp, fixed wrap at column --- /project/cl-smtp/cvsroot/cl-smtp/README 2010/06/21 09:06:26 1.11 +++ /project/cl-smtp/cvsroot/cl-smtp/README 2010/09/08 14:49:10 1.12 @@ -49,6 +49,8 @@ - ssl (or t :starttls :tls) : if t or :STARTTLS: use the STARTTLS functionality if :TLS: use TLS directly - external-format : symbol, default :utf-8 + - envelope-sender : email adress, + if not set then envelope-sender = from ------------------------------------------------ --- /project/cl-smtp/cvsroot/cl-smtp/cl-smtp.asd 2010/06/21 09:06:27 1.18 +++ /project/cl-smtp/cvsroot/cl-smtp/cl-smtp.asd 2010/09/08 14:49:10 1.19 @@ -17,7 +17,7 @@ ;;; Description: cl-smtp ASDF system definition file (asdf:defsystem :cl-smtp - :version "20100621.1" + :version "20100908.1" :perform (load-op :after (op webpage) (pushnew :cl-smtp cl:*features*)) :depends-on (:usocket --- /project/cl-smtp/cvsroot/cl-smtp/cl-smtp.lisp 2010/08/23 15:18:34 1.18 +++ /project/cl-smtp/cvsroot/cl-smtp/cl-smtp.lisp 2010/09/08 14:49:10 1.19 @@ -18,7 +18,7 @@ (in-package :cl-smtp) -(defparameter *x-mailer* (format nil "cl-smtp (~A ~A)" +(defparameter *x-mailer* (format nil "(~A ~A)" (lisp-implementation-type) (lisp-implementation-version))) @@ -143,8 +143,7 @@ :response-message msgstr)))) lines)) -(defun do-with-smtp-mail (host from to thunk &key port authentication ssl - local-hostname (external-format :utf-8)) +(defun do-with-smtp-mail (host envelope-sender to thunk &key port authentication ssl local-hostname (external-format :utf-8)) (usocket:with-client-socket (socket stream host port :element-type '(unsigned-byte 8)) (setf stream (flexi-streams:make-flexi-stream @@ -156,11 +155,11 @@ :authentication authentication :ssl ssl :local-hostname local-hostname))) - (initiate-smtp-mail stream from to) + (initiate-smtp-mail stream envelope-sender to) (funcall thunk stream) (finish-smtp-mail stream)))) -(defmacro with-smtp-mail ((stream-var host from to &key ssl (port (if (eq :tls ssl) 465 25)) authentication local-hostname (external-format :utf-8)) +(defmacro with-smtp-mail ((stream-var host envelope-sender to &key ssl (port (if (eq :tls ssl) 465 25)) authentication local-hostname (external-format :utf-8)) &body body) "Encapsulate a SMTP MAIl conversation. A connection to the SMTP server on HOST and PORT is established and a MAIL command is @@ -168,7 +167,7 @@ recipients. BODY is evaluated with STREAM-VAR being the stream connected to the remote SMTP server. BODY is expected to write the RFC2821 message (headers and body) to STREAM-VAR." - `(do-with-smtp-mail ,host ,from ,to + `(do-with-smtp-mail ,host ,envelope-sender ,to (lambda (,stream-var) , at body) :port ,port :authentication ,authentication @@ -179,7 +178,7 @@ (defun send-email (host from to subject message &key ssl (port (if (eq :tls ssl) 465 25)) cc bcc reply-to extra-headers html-message display-name authentication - attachments (buffer-size 256) (external-format :utf-8)) + attachments (buffer-size 256) envelope-sender (external-format :utf-8)) (send-smtp host from (check-arg to "to") subject (mask-dot message) :port port :cc (check-arg cc "cc") :bcc (check-arg bcc "bcc") :reply-to reply-to @@ -191,6 +190,7 @@ :buffer-size (if (numberp buffer-size) buffer-size 256) + :envelope-sender (or envelope-sender from) :external-format external-format :ssl ssl)) @@ -199,8 +199,9 @@ reply-to extra-headers html-message display-name authentication attachments buffer-size (local-hostname (usocket::get-host-name)) - (external-format :utf-8)) - (with-smtp-mail (stream host from (append to cc bcc) + (envelope-sender from) + (external-format :utf-8)) + (with-smtp-mail (stream host envelope-sender (append to cc bcc) :port port :authentication authentication :ssl ssl @@ -380,7 +381,7 @@ (smtp-authenticate stream authentication features))) stream) -(defun initiate-smtp-mail (stream from to) +(defun initiate-smtp-mail (stream envelope-sender to) "Initiate an SMTP MAIL command, sending a MAIL FROM command for the email address in FROM and RCPT commands for all receipients in TO, which is expected to be a list. @@ -389,7 +390,7 @@ is signalled. This condition may be handled by the caller in order to send the email anyway." (smtp-command stream - (format nil "MAIL FROM:<~A>" (substitute-return-newline from)) + (format nil "MAIL FROM:<~A>" (substitute-return-newline envelope-sender)) 250) (dolist (address to) (restart-case @@ -406,6 +407,7 @@ "Finish sending an email to the SMTP server connected to on STREAM. The server is expected to be inside of the DATA SMTP command. The connection is then terminated by sending a QUIT command." + ;;(fresh-line stream) (write-to-smtp stream "") (smtp-command stream "." 250) (smtp-command stream "QUIT" 221)) @@ -430,7 +432,7 @@ (write-to-smtp stream (format nil "Subject: ~A" (rfc2045-q-encode-string subject :external-format external-format))) - (write-to-smtp stream (format nil "X-Mailer: ~A" + (write-to-smtp stream (format nil "X-Mailer: cl-smtp~A" (rfc2045-q-encode-string *x-mailer* :external-format external-format))) (when reply-to From jidzikowski at common-lisp.net Wed Sep 8 15:02:32 2010 From: jidzikowski at common-lisp.net (jidzikowski) Date: Wed, 08 Sep 2010 11:02:32 -0400 Subject: [cl-smtp-cvs] CVS cl-smtp Message-ID: Update of /project/cl-smtp/cvsroot/cl-smtp In directory cl-net:/tmp/cvs-serv8502 Modified Files: CHANGELOG README cl-smtp.asd cl-smtp.lisp package.lisp Log Message: Add write-rfc8822-message, to write a rfc8822 compatible mail to the given stream. Change x-mailer header setting. --- /project/cl-smtp/cvsroot/cl-smtp/CHANGELOG 2010/09/08 14:49:10 1.19 +++ /project/cl-smtp/cvsroot/cl-smtp/CHANGELOG 2010/09/08 15:02:32 1.20 @@ -1,3 +1,9 @@ +Version 20100908.2 +2010.09.08 +Add write-rfc8822-message, to write a rfc8822 compatible mail. +Change x-mailer header setting. +Change cl-smtp.lisp, cl-smtp.asd, package.lisp, CHANGELOG, README + Version 20100908.1 2010.09.08 Add keyword envelope-sender to send-email, if envelope-sender not set then --- /project/cl-smtp/cvsroot/cl-smtp/README 2010/09/08 14:49:10 1.12 +++ /project/cl-smtp/cvsroot/cl-smtp/README 2010/09/08 15:02:32 1.13 @@ -79,6 +79,21 @@ - external-format : symbol, default :utf-8 ------------------------------------------------ + +(cl-smtp:write-rfc8822-message stream from to subject message + :cc cc :reply-to reply-to + :extra-headers extra-headers + :html-message html-message + :display-name display-name + :attachments attachments + :buffer-size buffer-size + :external-format external-format) + +Writes a rfc8822 compatible email to the stream. + +For arguments see the cl-smtp:send-email documentation. + +------------------------------------------------ CLASS cl-smtp:attachment --- /project/cl-smtp/cvsroot/cl-smtp/cl-smtp.asd 2010/09/08 14:49:10 1.19 +++ /project/cl-smtp/cvsroot/cl-smtp/cl-smtp.asd 2010/09/08 15:02:32 1.20 @@ -17,7 +17,7 @@ ;;; Description: cl-smtp ASDF system definition file (asdf:defsystem :cl-smtp - :version "20100908.1" + :version "20100908.2" :perform (load-op :after (op webpage) (pushnew :cl-smtp cl:*features*)) :depends-on (:usocket --- /project/cl-smtp/cvsroot/cl-smtp/cl-smtp.lisp 2010/09/08 14:49:10 1.19 +++ /project/cl-smtp/cvsroot/cl-smtp/cl-smtp.lisp 2010/09/08 15:02:32 1.20 @@ -18,7 +18,7 @@ (in-package :cl-smtp) -(defparameter *x-mailer* (format nil "(~A ~A)" +(defparameter *x-mailer* (format nil "cl-smtp (~A ~A)" (lisp-implementation-type) (lisp-implementation-version))) @@ -207,70 +207,14 @@ :ssl ssl :local-hostname local-hostname :external-format external-format) - (let* ((boundary (make-random-boundary)) - (html-boundary (if (and attachments html-message) - (make-random-boundary) - boundary)) - (content-type - (format nil "text/plain; charset=~S" - (string-upcase (symbol-name external-format))))) - (send-mail-headers stream - :from from - :to to - :cc cc - :reply-to reply-to - :display-name display-name - :extra-headers extra-headers :subject subject) - (when (or attachments html-message) - (send-multipart-headers stream - :attachment-boundary (when attachments boundary) - :html-boundary html-boundary)) - ;;----------- Send the body Message --------------------------- - ;;--- Send the proper headers depending on plain-text, - ;;--- multi-part or html email - (cond ((and attachments html-message) - ;; if both present, start attachment section, - ;; then define alternative section, - ;; then write alternative header - (progn - (generate-message-header - stream :boundary boundary :include-blank-line? nil) - (generate-multipart-header stream html-boundary - :multipart-type "alternative") - (write-blank-line stream) - (generate-message-header - stream :boundary html-boundary :content-type content-type - :content-disposition "inline" :include-blank-line? nil))) - (attachments - (generate-message-header - stream :boundary boundary - :content-type content-type :content-disposition "inline" - :include-blank-line? nil)) - (html-message - (generate-message-header - stream :boundary html-boundary :content-type content-type - :content-disposition "inline")) - (t - (generate-message-header stream :content-type content-type - :include-blank-line? nil))) - (write-blank-line stream) - (write-to-smtp stream message) - (write-blank-line stream) - ;;---------- Send Html text if needed ------------------------- - (when html-message - (generate-message-header - stream :boundary html-boundary - :content-type (format nil "text/html; charset=~S" - (string-upcase (symbol-name external-format))) - :content-disposition "inline") - (write-to-smtp stream html-message) - (send-end-marker stream html-boundary)) - ;;---------- Send Attachments ----------------------------------- - (when attachments - (dolist (attachment attachments) - (send-attachment stream attachment boundary buffer-size - external-format)) - (send-end-marker stream boundary))))) + (write-rfc8822-message stream from to subject message + :cc cc :reply-to reply-to + :extra-headers extra-headers + :html-message html-message + :display-name display-name + :attachments attachments + :buffer-size buffer-size + :external-format external-format))) (define-condition no-supported-authentication-method (smtp-error) ((features :initarg :features :reader features)) @@ -407,7 +351,6 @@ "Finish sending an email to the SMTP server connected to on STREAM. The server is expected to be inside of the DATA SMTP command. The connection is then terminated by sending a QUIT command." - ;;(fresh-line stream) (write-to-smtp stream "") (smtp-command stream "." 250) (smtp-command stream "QUIT" 221)) @@ -432,7 +375,7 @@ (write-to-smtp stream (format nil "Subject: ~A" (rfc2045-q-encode-string subject :external-format external-format))) - (write-to-smtp stream (format nil "X-Mailer: cl-smtp~A" + (write-to-smtp stream (format nil "X-Mailer: ~A" (rfc2045-q-encode-string *x-mailer* :external-format external-format))) (when reply-to @@ -455,6 +398,76 @@ :multipart-type "alternative")) (t nil))) +(defun write-rfc8822-message (stream from to subject message + &key cc reply-to extra-headers html-message + display-name attachments buffer-size + (external-format :utf-8)) + (let* ((boundary (make-random-boundary)) + (html-boundary (if (and attachments html-message) + (make-random-boundary) + boundary)) + (content-type + (format nil "text/plain; charset=~S" + (string-upcase (symbol-name external-format))))) + (send-mail-headers stream + :from from + :to to + :cc cc + :reply-to reply-to + :display-name display-name + :extra-headers extra-headers :subject subject) + (when (or attachments html-message) + (send-multipart-headers stream + :attachment-boundary (when attachments boundary) + :html-boundary html-boundary) + (write-blank-line stream)) + ;;----------- Send the body Message --------------------------- + ;;--- Send the proper headers depending on plain-text, + ;;--- multi-part or html email + (cond ((and attachments html-message) + ;; if both present, start attachment section, + ;; then define alternative section, + ;; then write alternative header + (progn + (generate-message-header + stream :boundary boundary :include-blank-line? nil) + (generate-multipart-header stream html-boundary + :multipart-type "alternative") + (write-blank-line stream) + (generate-message-header + stream :boundary html-boundary :content-type content-type + :content-disposition "inline" :include-blank-line? nil))) + (attachments + (generate-message-header + stream :boundary boundary + :content-type content-type :content-disposition "inline" + :include-blank-line? nil)) + (html-message + (generate-message-header + stream :boundary html-boundary :content-type content-type + :content-disposition "inline")) + (t + (generate-message-header stream :content-type content-type + :include-blank-line? nil))) + (write-blank-line stream) + (write-to-smtp stream message) + (write-blank-line stream) + ;;---------- Send Html text if needed ------------------------- + (when html-message + (generate-message-header + stream :boundary html-boundary + :content-type (format nil "text/html; charset=~S" + (string-upcase (symbol-name external-format))) + :content-disposition "inline") + (write-to-smtp stream html-message) + (send-end-marker stream html-boundary)) + ;;---------- Send Attachments ----------------------------------- + (when attachments + (dolist (attachment attachments) + (send-attachment stream attachment boundary buffer-size + external-format)) + (send-end-marker stream boundary)))) + (defun write-to-smtp (stream command) (print-debug (format nil "to server: ~A" command)) (write-sequence command stream) --- /project/cl-smtp/cvsroot/cl-smtp/package.lisp 2010/05/06 09:24:43 1.2 +++ /project/cl-smtp/cvsroot/cl-smtp/package.lisp 2010/09/08 15:02:32 1.3 @@ -33,7 +33,8 @@ "ATTACHMENT-DATA-PATHNAME" "ATTACHMENT-MIME-TYPE" "RFC2045-Q-ENCODE-STRING" - "RFC2231-ENCODE-STRING")) + "RFC2231-ENCODE-STRING" + "WRITE-RFC8822-MESSAGE")) (in-package :cl-smtp)