(in-package :kira) (defhandler ((recipient recipient-mixin) contact) (:title (render-title recipient 'contact/send)) (:authorized-p t) ((:standard-form :action (:uri-to recipient 'contact/send) :method :get) (render-challenge) (:p (submit-button nil "Continue")))) (defhandler ((recipient recipient-mixin) contact/send) (:title "Send E-mail") (:authorized-p (challenge-answered-p)) (:standard-form (:field "Your name" (text-field "from-name" nil :size 30)) (:field "Your E-mail address" (text-field "from" nil :size 30)) (:field "To" (render-title recipient) " (" (render-contact-link recipient) ")") (:field "Subject" (text-field "subject" nil)) (:field "Message" (textarea "body" nil)) (:p (submit-button nil "Send")))) (defhandler :post ((recipient recipient-mixin) contact/send) (with-query (from-name from subject body) (let ((to (email recipient)) (body (html-output (word-wrap body)))) (send-mail to subject body :from (format nil "~a <~a>" from-name from)) (send-mail from (format nil "Fwd: ~a" subject) (format nil "Your message to ~a~%Sent via ~a~%----~%~%~a" to *base-uri* body))) (redirect recipient 'contact/ok))) (defhandler ((recipient recipient-mixin) contact/ok) (:title "Send Successful") (:p "Your message has been sent to " (render-link recipient) ", and a copy has been forwarded to your address.")) (defun render-contact-link (recipient) (whereas ((email (email recipient))) (html (:if *person* (:a (:progn "mailto:" email) email) ((:a :title (render-title recipient 'contact)) (:uri-to recipient 'contact) (:let ((position (position #\@ email))) (when (and position (plusp position)) (write-char (char email 0) *html-output*)) (:b "...") (when position (write-string email *html-output* :start position)))))))) (defmethod initialize-instance-from-query progn ((node recipient-mixin)) (unless (typep node 'person) (setf (email node) (or (email (owner node)) (email *person*))))) (defmethod update-instance-from-query progn ((node recipient-mixin)) (setf-accessors-from-query node email)) (defun send-mail (to subject body &key (from +from+)) (with-open-file (stream +sendmail+ :direction :output) (format stream "From: ~a~%" from) (format stream "To: ~a~%" to) (format stream "Subject: ~a~%~%" subject) (write-string body stream) (unless (char= (char body (1- (length body))) #\Newline) (format stream "~%"))))