Skip to content

Commit

Permalink
Merge pull request #18 from toyokumo/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
liquidz committed Oct 2, 2023
2 parents 3a5499a + 3868b0e commit 45f45bc
Show file tree
Hide file tree
Showing 19 changed files with 88 additions and 54 deletions.
20 changes: 11 additions & 9 deletions .github/workflows/lint-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@ jobs:
clj_style:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: 0918nobita/setup-cljstyle@v0.5.2
- uses: actions/checkout@v4
- uses: DeLaGuardo/setup-clojure@master
with:
cljstyle-version: 0.15.0
cljstyle: latest
- run: cljstyle check --report -v

clj_kondo:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: DeLaGuardo/setup-clj-kondo@master
- uses: actions/checkout@v4
- uses: DeLaGuardo/setup-clojure@master
with:
version: '2021.10.19'
clj-kondo: latest
- run: clj-kondo --lint src:test:integration



test:
needs: [clj_style, clj_kondo]
runs-on: ubuntu-latest
Expand All @@ -32,9 +34,9 @@ jobs:
- 8025:8025

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- uses: actions/setup-java@v2
- uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '8'
Expand All @@ -43,7 +45,7 @@ jobs:

- uses: DeLaGuardo/setup-clojure@master
with:
lein: '2.9.7'
lein: '2.10.0'

- name: Show versions
run: |
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ install:
test:
lein test-all

.PHONY: test-integration
test-integration:
lein test-integration

.PHONY: outdated
outdated:
lein antq
Expand Down
2 changes: 1 addition & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ Example using https://github.com/bguthrie/shrubbery[shrubbery].

== License

Copyright 2020-2021 Toyokumo,Inc.
Copyright 2020-2023 Toyokumo,Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
7 changes: 7 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: "3"
services:
mailhog:
image: mailhog/mailhog:v1.0.0
ports:
- "1025:1025"
- "8025:8025"
18 changes: 9 additions & 9 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
:license {:name "Apache, Version 2.0"
:url "http://www.apache.org/licenses/LICENSE-2.0"}

:dependencies [[camel-snake-kebab "0.4.2"]
[com.sun.mail/jakarta.mail "2.0.1"]
[commons-codec "1.15"]
[jakarta.mail/jakarta.mail-api "2.0.1"]
:dependencies [[camel-snake-kebab "0.4.3"]
[org.eclipse.angus/angus-mail "2.0.2"]
[commons-codec "1.16.0"]
[jakarta.mail/jakarta.mail-api "2.1.2"]
[nano-id "1.0.0"]
[org.apache.tika/tika-core "2.1.0"]]
[org.apache.tika/tika-core "2.9.0"]]

:profiles
{:1.8 {:dependencies [[org.clojure/clojure "1.8.0"]]}
:1.9 {:dependencies [[org.clojure/clojure "1.9.0"]]}
:1.10 {:dependencies [[org.clojure/clojure "1.10.3"]]}

:dev {:dependencies [[org.clojure/clojure "1.10.3"]
:dev {:dependencies [[org.clojure/clojure "1.11.1"]
[com.github.kirviq/dumbster "1.7.1"]
[testdoc "1.4.1"]
;; for stubbing
Expand All @@ -27,16 +27,16 @@
:global-vars {*warn-on-reflection* true}}

:it {:dependencies [[org.clojure/data.json "2.4.0"]
[http-kit "2.5.3"]]
[http-kit "2.7.0"]]
:test-paths ["integration/test"]}

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

:plugins [[lein-cloverage "1.2.2"]]
:plugins [[lein-cloverage "1.2.4"]]
:cloverage {:ns-exclude-regex [#"benchmark"]}

:release-tasks [["vcs" "assert-committed"]
Expand Down
7 changes: 3 additions & 4 deletions src/tarayo/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@
:else 25)
:auth (some? user)})

(defn ^tarayo.core.ISMTPConnection
connect
(defn connect
"Connect to the specified SMTP server.
If the connection is successful, an open `SMTPConnection` is returned.
Expand All @@ -89,8 +88,8 @@
* :starttls.enable
For more information, please see https://jakarta.ee/specifications/mail/1.6/apidocs/com/sun/mail/smtp/package-summary.html"
([] (connect {}))
([smtp-server]
(^tarayo.core.ISMTPConnection [] (connect {}))
(^tarayo.core.ISMTPConnection [smtp-server]
(let [smtp-server (merge (get-defaults smtp-server)
smtp-server)
sess (session/make-session smtp-server)]
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 @@ -19,7 +19,8 @@
(->> (io/resource "VERSION") slurp str/trim
(str "tarayo/")))

(defn ^MimeMessage make-message
(defn make-message
^MimeMessage
[^Session session message]
(let [{:keys [charset content-type reply-to cc bcc body multipart]} message
charset (or charset constant/default-charset)
Expand Down
4 changes: 2 additions & 2 deletions src/tarayo/mail/mime/address.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
(jakarta.mail.internet
InternetAddress)))

(defn ^InternetAddress
make-address
(defn make-address
^InternetAddress
[addr charset]
(let [^InternetAddress addr (cond-> addr
(not (instance? InternetAddress addr))
Expand Down
3 changes: 2 additions & 1 deletion src/tarayo/mail/mime/id.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
16))

(defn ^String get-random
(defn get-random
^String
[]
(let [hostname (.getHostName (java.net.InetAddress/getLocalHost))]
(format "<%s.%s@%s>" (generate-id) (.getTime (java.util.Date.)) (str "tarayo." hostname))))
6 changes: 4 additions & 2 deletions src/tarayo/mail/mime/message.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
MimeMessage)
java.util.Date))

(defn ^MimeMessage make-message
(defn make-message
^MimeMessage
[^Session session message]
(proxy [MimeMessage] [^Session session]
(updateMessageID
Expand Down Expand Up @@ -60,7 +61,8 @@
(defn add-headers
[^MimeMessage msg headers]
(doseq [[k v] headers]
(.addHeader msg (cond-> k (keyword? k) name) v)))
(when (string? v)
(.addHeader msg (cond-> k (keyword? k) name) v))))

(defn set-content
([^MimeMessage msg ^Multipart multipart]
Expand Down
3 changes: 2 additions & 1 deletion src/tarayo/mail/mime/multipart.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
(doseq [part parts]
(.addBodyPart multipart (body/make-bodypart part charset))))

(defn ^MimeMultipart make-multipart
(defn make-multipart
^MimeMultipart
[^String multipart-type parts charset]
(doto (MimeMultipart. multipart-type)
(add-body-parts parts charset)))
15 changes: 10 additions & 5 deletions src/tarayo/mail/mime/multipart/body.clj
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
[^URL url]
(.detect mime-detector url))

(defn- ^String ensure-string
(defn- ensure-string
^String
[x]
(if (keyword? x)
(str (.sym ^clojure.lang.Keyword x))
x))

(defn- ^URL ensure-url
(defn- ensure-url
^URL
[x]
(try
(io/as-url x)
Expand All @@ -54,7 +56,8 @@
(URLDecoder/decode charset)
(MimeUtility/encodeText charset nil)))

(defn- ^MimeBodyPart make-attachment-bodypart-by-url
(defn- make-attachment-bodypart-by-url
^MimeBodyPart
[part charset]
(let [{:keys [content filename]} part
url (ensure-url content)]
Expand All @@ -63,7 +66,8 @@
(.setFileName (or filename (extract-file-name url charset)))
(.setHeader "Content-Type" (get part :content-type (detect-mime-type url))))))

(defn- ^MimeBodyPart make-attachment-bodypart-by-byte-array
(defn- make-attachment-bodypart-by-byte-array
^MimeBodyPart
[part]
(assert (contains? part :content-type) ":content-type is required for byte array content.")
(assert (contains? part :filename) ":filename is required for byte array content.")
Expand All @@ -88,7 +92,8 @@
(cond-> id (.setContentID (str "<" id ">")))
(cond-> content-encoding (.setHeader "Content-Transfer-Encoding" content-encoding)))))

(defn ^MimeBodyPart make-bodypart
(defn make-bodypart
^MimeBodyPart
[part charset]
(let [string-content? (-> part :content string?)
has-id? (contains? part :id)]
Expand Down
6 changes: 3 additions & 3 deletions src/tarayo/mail/mime/multipart/data_source.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
(:import
jakarta.activation.DataSource))

(defn ^DataSource byte-array-data-source
(defn byte-array-data-source
"Return jakarta.activation.DataSource instance by byte array."
([^"[B" buf]
(^DataSource [^"[B" buf]
(byte-array-data-source buf "application/octet-stream"))
([^"[B" buf ^String content-type]
(^DataSource [^"[B" buf ^String content-type]
(proxy [DataSource] []
(getInputStream []
(io/input-stream buf))
Expand Down
6 changes: 3 additions & 3 deletions src/tarayo/mail/session.clj
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
(.put props k v))
props))

(defn ^Session make-session
(defn make-session
"Create `jakarta.mail.Session` instance and return it."
([] (make-session {}))
([smtp-server]
(^Session [] (make-session {}))
(^Session [smtp-server]
(let [props (session-properties smtp-server)]
(doto (Session/getInstance props)
(.setDebug (get smtp-server :debug false))))))
12 changes: 7 additions & 5 deletions src/tarayo/mail/transport.clj
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
(ns tarayo.mail.transport
(:import
(com.sun.mail.smtp
SMTPTransport)
jakarta.mail.Session
(jakarta.mail.internet
MimeMessage)))
MimeMessage)
(org.eclipse.angus.mail.smtp
SMTPTransport)))

(defn- ^String get-protocol
(defn- get-protocol
^String
[^Session session]
;; c.f. https://jakarta.ee/specifications/mail/1.6/apidocs/com/sun/mail/smtp/package-summary.html
(if (= "true" (.getProperty session "mail.smtp.ssl.enable"))
"smtps"
"smtp"))

(defn ^SMTPTransport make-transport
(defn make-transport
^SMTPTransport
[^Session session]
(.getTransport session (get-protocol session)))

Expand Down
6 changes: 3 additions & 3 deletions test/tarayo/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
[tarayo.test-helper :as h]
[testdoc.core])
(:import
(com.sun.mail.smtp
SMTPTransport)
jakarta.mail.Session))
jakarta.mail.Session
(org.eclipse.angus.mail.smtp
SMTPTransport)))

(t/deftest README-test
(with-redefs [transport/make-transport (constantly (h/test-transport))]
Expand Down
13 changes: 11 additions & 2 deletions test/tarayo/mail/mime/message_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
(.saveChanges msg)
(t/is (= "foo" (.getMessageID msg)))))))

(defn- ^MimeMessage gen-test-message
(defn- gen-test-message
^MimeMessage
[]
(let [{:keys [session]} (h/test-connection)
^Calendar cal (doto (Calendar/getInstance)
Expand Down Expand Up @@ -80,7 +81,15 @@
(t/deftest add-headers-test
(let [msg (gen-test-message)]
(t/is (= ["Bar"] (seq (.getHeader msg "Foo"))))
(t/is (= ["Baz"] (seq (.getHeader msg "Bar"))))))
(t/is (= ["Baz"] (seq (.getHeader msg "Bar")))))

(t/testing "not string values"
(let [{:keys [session]} (h/test-connection)
headers {"num" 1
"fn" (constantly "foo")}
msg (doto (sut/make-message session {})
(sut/add-headers headers))]
(t/is (every? #(nil? (.getHeader msg %)) (keys headers))))))

(t/deftest set-content-test
(t/testing "multipart"
Expand Down
2 changes: 1 addition & 1 deletion test/tarayo/mail/transport_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[tarayo.mail.transport :as sut]
[tarayo.test-helper :as h])
(:import
(com.sun.mail.smtp
(org.eclipse.angus.mail.smtp
SMTPSSLTransport
SMTPTransport)))

Expand Down
5 changes: 3 additions & 2 deletions test/tarayo/test_helper.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
(com.dumbster.smtp
SimpleSmtpServer
SmtpMessage)
(com.sun.mail.smtp
(org.eclipse.angus.mail.smtp
SMTPTransport)))

(defrecord TestConnection
Expand Down Expand Up @@ -61,7 +61,8 @@
(tarayo-user-agent? (first x))
(some? (re-seq #"^tarayo/.+$" x))))

(defn ^SMTPTransport test-transport
(defn test-transport
^SMTPTransport
[]
(proxy [SMTPTransport] [(session/make-session) (jakarta.mail.URLName. "localhost")]
(connect
Expand Down

0 comments on commit 45f45bc

Please sign in to comment.