diff --git a/resources/email-denylist.edn b/resources/email-denylist.edn new file mode 100644 index 00000000..0a2ea16a --- /dev/null +++ b/resources/email-denylist.edn @@ -0,0 +1,6 @@ +;; A set of addresses that we never want to send an email to. +#{ + ;; Used by GitHub on the account they use for integration testing token breach + ;; reporting, but it doesn't actually exist, resulting in monitoring noise + "secret-scanning@gmail.com" + } diff --git a/src/clojars/email.clj b/src/clojars/email.clj index 21c0a1e3..1c264c6c 100644 --- a/src/clojars/email.clj +++ b/src/clojars/email.clj @@ -1,6 +1,8 @@ (ns clojars.email (:require - [clojars.log :as log]) + [clojars.log :as log] + [clojure.edn :as edn] + [clojure.java.io :as io]) (:import (java.util.concurrent CountDownLatch @@ -8,27 +10,32 @@ (org.apache.commons.mail SimpleEmail))) +(def ^:private email-denylist + (edn/read-string (slurp (io/resource "email-denylist.edn")))) + (defn simple-mailer [{:keys [hostname username password port tls? from]}] (fn [to subject message] (log/with-context {:tag :email :email-to to :email-subject subject} (try - (let [mail (doto (SimpleEmail.) - (.setHostName (or hostname "localhost")) - (.setSmtpPort (or port 25)) - (.setStartTLSEnabled (boolean tls?)) - (.setStartTLSRequired (boolean tls?)) - (.setFrom (or from "contact@clojars.org") "Clojars") - (.addTo to) - (.setSubject subject) - (.setMsg message))] - (when tls? - (.setSslSmtpPort mail (str (or port 25)))) - (when (and username password) - (.setAuthentication mail username password)) - (.send mail) - (log/info {:status :success})) + (if (contains? email-denylist to) + (log/info {:status :denylist}) + (let [mail (doto (SimpleEmail.) + (.setHostName (or hostname "localhost")) + (.setSmtpPort (or port 25)) + (.setStartTLSEnabled (boolean tls?)) + (.setStartTLSRequired (boolean tls?)) + (.setFrom (or from "contact@clojars.org") "Clojars") + (.addTo to) + (.setSubject subject) + (.setMsg message))] + (when tls? + (.setSslSmtpPort mail (str (or port 25)))) + (when (and username password) + (.setAuthentication mail username password)) + (.send mail) + (log/info {:status :success}))) (catch Exception e (log/error {:status :failed :error e})