Skip to content

Commit

Permalink
Merge pull request #10 from toyokumo/develop
Browse files Browse the repository at this point in the history
ver 0.2.3
  • Loading branch information
liquidz authored Jul 16, 2020
2 parents 8f137af + 3b4b3e2 commit 2f1ed2c
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 24 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file. This change

== Unreleased (dev)

== 0.2.3
=== Added
* https://github.com/liquidz/tarayo/issues/9[#9] Added support to specify `reply-to`.

=== Fixed
* Fixed type hint for `tarayo.core/connect`.
** `ClassCastException` could be thrown when using a dummy connection on testing so far.
* Fixed some reflection warnings.

== 0.2.2
=== Changed
* Bump testdoc.
Expand Down
15 changes: 14 additions & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,19 @@ Connection with user authentication::
;; => {:result :success, :code 250, :message "250 OK\n"}
----

==== Reply to

[source,clojure]
----
(with-open [conn (tarayo/connect {:host "localhost" :port 25})]
(tarayo/send! conn {:from "[email protected]"
:to "[email protected]"
:reply-to "[email protected]"
:subject "hello"
:body "world"}))
;; => {:result :success, :code 250, :message "250 OK\n"}
----

==== Attachment file

[source,clojure]
Expand Down Expand Up @@ -167,7 +180,7 @@ To generate this parameter, you can use `tarayo.mail.mime`.
'[tarayo.mail.session :as session])
;; => nil
(defn- mime-message->raw-string [mime-msg]
(defn- mime-message->raw-string [^javax.mail.internet.MimeMessage mime-msg]
(let [buf (java.io.ByteArrayOutputStream.)]
(.writeTo mime-msg buf)
(org.apache.commons.codec.binary.Base64/encodeBase64URLSafeString (.toByteArray buf))))
Expand Down
32 changes: 16 additions & 16 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@
:1.9 {:dependencies [[org.clojure/clojure "1.9.0"]]}
:1.10 {:dependencies [[org.clojure/clojure "1.10.1"]]}

:dev [:1.10
{:dependencies [[com.github.kirviq/dumbster "1.7.1"]
[testdoc "1.3.0"]
;; for stubbing
[com.gearswithingears/shrubbery "0.4.1"]]
:source-paths ["dev/src" "src"]
:resource-paths ["dev/resources"]
:global-vars {*warn-on-reflection* true}}]

:it [:dev {:dependencies [[org.clojure/data.json "1.0.0"]
[camel-snake-kebab "0.4.1"]
[http-kit "2.3.0"]]
:test-paths ["integration/test"]}]

:benchmark {:dependencies [[criterium "0.4.5"]
:dev {:dependencies [[org.clojure/clojure "1.10.1"]
[com.github.kirviq/dumbster "1.7.1"]
[testdoc "1.4.0"]
;; for stubbing
[com.gearswithingears/shrubbery "0.4.1"]]
:source-paths ["dev/src" "src"]
:resource-paths ["dev/resources"]
:global-vars {*warn-on-reflection* true}}

:it {:dependencies [[org.clojure/data.json "1.0.0"]
[camel-snake-kebab "0.4.1"]
[http-kit "2.3.0"]]
:test-paths ["integration/test"]}

:benchmark {:dependencies [[criterium "0.4.6"]
[com.draines/postal "2.0.3"]]}

:antq {:dependencies [[antq "RELEASE"]]}}
:aliases
{"test-all" ["with-profile" "1.8,dev:1.9,dev:1.10,dev" "test"]
"test-integration" ["with-profile" "1.9,it:1.10,it" "test"]
"test-integration" ["with-profile" "1.9,dev,it:1.10,dev,it" "test"]
"benchmark" ["with-profile" "+benchmark" "run" "-m" "benchmark"]
"antq" ["with-profile" "+antq" "run" "-m" "antq.core"]}

Expand Down
2 changes: 1 addition & 1 deletion resources/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.2
0.2.3
4 changes: 2 additions & 2 deletions src/tarayo/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
`message` is a map containing following keys.
* `:from`, `:to`, `:subject` and `:body` are REQUIRED.
* `:content-type`, `:multipart` and `:message-id-fn` are OPTIONAL.
* `reply-to`, `:content-type`, `:multipart` and `:message-id-fn` are OPTIONAL.
## Content-type
`:content-type` is used when `:body` is a String. (Default: \"text/plain\")
Expand Down Expand Up @@ -75,7 +75,7 @@
:else 25)
:auth (some? user)})

(defn ^SMTPConnection
(defn ^tarayo.core.ISMTPConnection
connect
"Connect to the specified SMTP server.
If the connection is successful, an open `SMTPConnection` is returned.
Expand Down
3 changes: 2 additions & 1 deletion src/tarayo/mail/mime.clj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

(defn ^MimeMessage make-message
[^Session session message]
(let [{:keys [charset content-type cc bcc body multipart]} message
(let [{:keys [charset content-type reply-to cc bcc body multipart]} message
charset (or charset constant/default-charset)
content-type (or content-type constant/default-content-type)
multipart (or multipart constant/default-multipart)]
Expand All @@ -33,6 +33,7 @@
(message/add-headers (-> (apply dissoc message non-extra-headers)
(update :user-agent #(or % default-user-agent))
(set/rename-keys {:user-agent "User-Agent"})))
(cond-> reply-to (message/set-reply-to (address/make-addresses reply-to charset)))
(cond-> cc (message/add-cc (address/make-addresses cc charset)))
(cond-> bcc (message/add-bcc (address/make-addresses bcc charset)))
(cond-> (string? body) (message/set-content body (format "%s; charset=%s" content-type charset))
Expand Down
9 changes: 7 additions & 2 deletions src/tarayo/mail/mime/message.clj
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,15 @@
(.addRecipients msg Message$RecipientType/BCC addresses))

(defn set-from
[^MimeMessage msg ^InternetAddress
^"[Ljavax.mail.internet.InternetAddress;" address]
[^MimeMessage msg
^InternetAddress address]
(.setFrom msg address))

(defn set-reply-to
[^MimeMessage msg
^"[Ljavax.mail.internet.InternetAddress;" addresses]
(.setReplyTo msg addresses))

(defn set-subject
[^MimeMessage msg ^String subject ^String charset]
(.setSubject msg subject charset))
Expand Down
2 changes: 1 addition & 1 deletion src/tarayo/mail/mime/multipart/body.clj
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
[^URL url ^String charset]
(-> (.getPath url)
(.split separator)
last
^String last
(URLDecoder/decode charset)
(MimeUtility/encodeText charset nil)))

Expand Down
6 changes: 6 additions & 0 deletions test/tarayo/mail/mime/message_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
(sut/add-cc (addr/make-addresses ["[email protected]" "[email protected]"] "utf-8"))
(sut/add-bcc (addr/make-addresses ["[email protected]" "[email protected]"] "utf-8"))
(sut/set-from (addr/make-address "[email protected]" "utf-8"))
(sut/set-reply-to (addr/make-addresses ["[email protected]" "[email protected]"] "utf-8"))
(sut/set-subject "hello, world" "utf-8")
(sut/set-sent-date (.getTime cal))
(sut/add-headers {"Foo" "Bar" "Bar" "Baz"}))))
Expand All @@ -58,6 +59,11 @@
(let [msg (gen-test-message)]
(t/is (= #{"[email protected]"} (addrs->set (.getFrom msg))))))

(t/deftest set-reply-to-test
(let [msg (gen-test-message)
reply-tos (addrs->set (.getReplyTo msg))]
(t/is (= #{"[email protected]" "[email protected]"} reply-tos))))

(t/deftest set-subject-test
(let [msg (gen-test-message)]
(t/is (= "hello, world" (.getSubject msg)))))
Expand Down
11 changes: 11 additions & 0 deletions test/tarayo/mail/mime_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@
(t/is (= "alice" (.getAddress ^InternetAddress (first ccs))))
(t/is (= "bob" (.getAddress ^InternetAddress (first bccs)))))))

(t/deftest make-message-with-reply-to-test
(let [{:keys [session]} (h/test-connection)
opts {:from "foo" :to "bar" :subject "hello" :body "world" :charset "UTF-8"
:reply-to "charlie"}
msg (sut/make-message session opts)]
(t/is (instance? MimeMessage msg))

(let [reply-to (.getReplyTo msg)]
(t/is (= 1 (count reply-to)))
(t/is (= "charlie" (.getAddress ^InternetAddress (first reply-to)))))))

(t/deftest make-message-with-custom-user-agent-test
(let [{:keys [session]} (h/test-connection)
opts {:from "foo" :to "bar" :subject "hello" :body "world" :charset "UTF-8"
Expand Down

0 comments on commit 2f1ed2c

Please sign in to comment.