mirror of
https://github.com/penpot/penpot.git
synced 2025-05-13 15:26:39 +02:00
🐛 Fix email from handling.
This commit is contained in:
parent
d120af2c81
commit
ca63ff621a
2 changed files with 29 additions and 40 deletions
|
@ -44,8 +44,8 @@
|
||||||
:rlimits-image 2
|
:rlimits-image 2
|
||||||
|
|
||||||
:smtp-enabled false
|
:smtp-enabled false
|
||||||
:smtp-default-reply-to "no-reply@example.com"
|
:smtp-default-reply-to "Penpot <no-reply@example.com>"
|
||||||
:smtp-default-from "no-reply@example.com"
|
:smtp-default-from "Penpot <no-reply@example.com>"
|
||||||
|
|
||||||
:allow-demo-users true
|
:allow-demo-users true
|
||||||
:registration-enabled true
|
:registration-enabled true
|
||||||
|
@ -92,8 +92,8 @@
|
||||||
|
|
||||||
(s/def ::error-report-webhook ::us/string)
|
(s/def ::error-report-webhook ::us/string)
|
||||||
(s/def ::smtp-enabled ::us/boolean)
|
(s/def ::smtp-enabled ::us/boolean)
|
||||||
(s/def ::smtp-default-reply-to ::us/email)
|
(s/def ::smtp-default-reply-to ::us/string)
|
||||||
(s/def ::smtp-default-from ::us/email)
|
(s/def ::smtp-default-from ::us/string)
|
||||||
(s/def ::smtp-host ::us/string)
|
(s/def ::smtp-host ::us/string)
|
||||||
(s/def ::smtp-port ::us/integer)
|
(s/def ::smtp-port ::us/integer)
|
||||||
(s/def ::smtp-username (s/nilable ::us/string))
|
(s/def ::smtp-username (s/nilable ::us/string))
|
||||||
|
|
|
@ -29,24 +29,11 @@
|
||||||
;; Email Building
|
;; Email Building
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(defn build-address
|
(defn- parse-address
|
||||||
[v charset]
|
[v]
|
||||||
(try
|
(InternetAddress/parse ^String v))
|
||||||
(cond
|
|
||||||
(string? v)
|
|
||||||
(InternetAddress. v nil charset)
|
|
||||||
|
|
||||||
(map? v)
|
(defn- ^Message$RecipientType resolve-recipient-type
|
||||||
(InternetAddress. (:addr v)
|
|
||||||
(:name v)
|
|
||||||
(:charset v charset))
|
|
||||||
|
|
||||||
:else
|
|
||||||
(throw (ex-info "Invalid address" {:data v})))
|
|
||||||
(catch Exception e
|
|
||||||
(throw (ex-info "Invalid address" {:data v} e)))))
|
|
||||||
|
|
||||||
(defn- resolve-recipient-type
|
|
||||||
[type]
|
[type]
|
||||||
(case type
|
(case type
|
||||||
:to Message$RecipientType/TO
|
:to Message$RecipientType/TO
|
||||||
|
@ -54,33 +41,33 @@
|
||||||
:bcc Message$RecipientType/BCC))
|
:bcc Message$RecipientType/BCC))
|
||||||
|
|
||||||
(defn- assign-recipient
|
(defn- assign-recipient
|
||||||
[^MimeMessage mmsg type address charset]
|
[^MimeMessage mmsg type address]
|
||||||
(if (sequential? address)
|
(if (sequential? address)
|
||||||
(reduce #(assign-recipient %1 type %2 charset) mmsg address)
|
(reduce #(assign-recipient %1 type %2) mmsg address)
|
||||||
(let [address (build-address address charset)
|
(let [address (parse-address address)
|
||||||
type (resolve-recipient-type type)]
|
type (resolve-recipient-type type)]
|
||||||
(.addRecipient mmsg type address)
|
(.addRecipients mmsg type address)
|
||||||
mmsg)))
|
mmsg)))
|
||||||
|
|
||||||
(defn- assign-recipients
|
(defn- assign-recipients
|
||||||
[mmsg {:keys [to cc bcc charset] :or {charset "utf-8"} :as params}]
|
[mmsg {:keys [to cc bcc] :as params}]
|
||||||
(cond-> mmsg
|
(cond-> mmsg
|
||||||
(some? to) (assign-recipient :to to charset)
|
(some? to) (assign-recipient :to to)
|
||||||
(some? cc) (assign-recipient :cc cc charset)
|
(some? cc) (assign-recipient :cc cc)
|
||||||
(some? bcc) (assign-recipient :bcc bcc charset)))
|
(some? bcc) (assign-recipient :bcc bcc)))
|
||||||
|
|
||||||
(defn- assign-from
|
(defn- assign-from
|
||||||
[mmsg {:keys [from charset] :or {charset "utf-8"}}]
|
[mmsg {:keys [default-from]} {:keys [from] :as props}]
|
||||||
(when from
|
(let [from (or from default-from)]
|
||||||
(let [from (build-address from charset)]
|
(when from
|
||||||
(.setFrom ^MimeMessage mmsg ^InternetAddress from))))
|
(let [from (parse-address from)]
|
||||||
|
(.addFrom ^MimeMessage mmsg from)))))
|
||||||
|
|
||||||
(defn- assign-reply-to
|
(defn- assign-reply-to
|
||||||
[mmsg {:keys [defaut-reply-to]} {:keys [reply-to charset] :or {charset "utf-8"}}]
|
[mmsg {:keys [default-reply-to] :as cfg} {:keys [reply-to] :as params}]
|
||||||
(let [reply-to (or reply-to defaut-reply-to)]
|
(let [reply-to (or reply-to default-reply-to)]
|
||||||
(when reply-to
|
(when reply-to
|
||||||
(let [reply-to (build-address reply-to charset)
|
(let [reply-to (parse-address reply-to)]
|
||||||
reply-to (into-array InternetAddress [reply-to])]
|
|
||||||
(.setReplyTo ^MimeMessage mmsg reply-to)))))
|
(.setReplyTo ^MimeMessage mmsg reply-to)))))
|
||||||
|
|
||||||
(defn- assign-subject
|
(defn- assign-subject
|
||||||
|
@ -136,7 +123,7 @@
|
||||||
[cfg session params]
|
[cfg session params]
|
||||||
(let [mmsg (MimeMessage. ^Session session)]
|
(let [mmsg (MimeMessage. ^Session session)]
|
||||||
(assign-recipients mmsg params)
|
(assign-recipients mmsg params)
|
||||||
(assign-from mmsg params)
|
(assign-from mmsg cfg params)
|
||||||
(assign-reply-to mmsg cfg params)
|
(assign-reply-to mmsg cfg params)
|
||||||
(assign-subject mmsg params)
|
(assign-subject mmsg params)
|
||||||
(assign-extra-headers mmsg params)
|
(assign-extra-headers mmsg params)
|
||||||
|
@ -156,12 +143,12 @@
|
||||||
(Properties.)
|
(Properties.)
|
||||||
{"mail.user" username
|
{"mail.user" username
|
||||||
"mail.host" host
|
"mail.host" host
|
||||||
|
"mail.from" default-from
|
||||||
"mail.smtp.auth" (boolean username)
|
"mail.smtp.auth" (boolean username)
|
||||||
"mail.smtp.starttls.enable" tls
|
"mail.smtp.starttls.enable" tls
|
||||||
"mail.smtp.starttls.required" tls
|
"mail.smtp.starttls.required" tls
|
||||||
"mail.smtp.host" host
|
"mail.smtp.host" host
|
||||||
"mail.smtp.port" port
|
"mail.smtp.port" port
|
||||||
"mail.smtp.from" default-from
|
|
||||||
"mail.smtp.user" username
|
"mail.smtp.user" username
|
||||||
"mail.smtp.timeout" timeout
|
"mail.smtp.timeout" timeout
|
||||||
"mail.smtp.connectiontimeout" timeout}))
|
"mail.smtp.connectiontimeout" timeout}))
|
||||||
|
@ -183,7 +170,9 @@
|
||||||
(defn send!
|
(defn send!
|
||||||
[cfg message]
|
[cfg message]
|
||||||
(let [^MimeMessage message (smtp-message cfg message)]
|
(let [^MimeMessage message (smtp-message cfg message)]
|
||||||
(Transport/send message (:username cfg) (:password cfg))
|
(Transport/send message
|
||||||
|
(:username cfg)
|
||||||
|
(:password cfg))
|
||||||
nil))
|
nil))
|
||||||
|
|
||||||
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue