diff options
author | Teddy Wing | 2022-05-08 12:19:33 +0200 |
---|---|---|
committer | Teddy Wing | 2022-05-08 12:19:33 +0200 |
commit | 40ae5a197024253c4db06ac27a1606d21414b693 (patch) | |
tree | 305b1b5fcebb5311aad74afd37af211aa0832ee7 | |
parent | 27a205d81647c9df3c6c04f36062b87987d5ae99 (diff) | |
download | wajir-40ae5a197024253c4db06ac27a1606d21414b693.tar.bz2 |
deliver-email: Send email data to program
Allow a "sendmail" program to be configured. If set, `deliver-email`
will spawn the program and write the email its standard input.
We can thus send the email by invoking the external program.
-rw-r--r-- | src/config.lisp | 5 | ||||
-rw-r--r-- | src/email.lisp | 11 | ||||
-rw-r--r-- | src/main.lisp | 3 |
3 files changed, 17 insertions, 2 deletions
diff --git a/src/config.lisp b/src/config.lisp index 0bc6fee..b1093b6 100644 --- a/src/config.lisp +++ b/src/config.lisp @@ -14,6 +14,11 @@ :reader endpoint :documentation "Jira site URL (e.g. example.atlassian.net)") + (sendmail + :initarg :sendmail + :reader sendmail + :documentation "Email sending client command") + (email-to :initarg :email-to :reader email-to diff --git a/src/email.lisp b/src/email.lisp index 9e5929c..fe80af1 100644 --- a/src/email.lisp +++ b/src/email.lisp @@ -1,8 +1,17 @@ (in-package :wajir) (defun deliver-email (config issue) + (let ((message (with-output-to-string (message-stream) + (build-email config issue message-stream)))) + + (with-open-stream (sendmail-input (make-string-input-stream message)) + (uiop:run-program (sendmail config) + :output "/tmp/wajir.output" + :input sendmail-input)))) + +(defun build-email (config issue output-stream) (cl-smtp:write-rfc8822-message - *standard-output* + output-stream (format nil "wajir@~A" (uiop:hostname)) `(,(email-to config)) (format-subject issue) diff --git a/src/main.lisp b/src/main.lisp index 7c0f368..d700182 100644 --- a/src/main.lisp +++ b/src/main.lisp @@ -84,4 +84,5 @@ ;; 2. Send email (format t "Watching issue ~A~%" (gethash "key" issue)) - (deliver-email config issue)) + (if (sendmail config) + (deliver-email config issue))) |