Skip to content

Commit

Permalink
fix: Fix not to add non-string header values
Browse files Browse the repository at this point in the history
cf. #17
  • Loading branch information
liquidz committed Sep 21, 2023
1 parent 3a5499a commit f77d39c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/tarayo/mail/mime/message.clj
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,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
10 changes: 9 additions & 1 deletion test/tarayo/mail/mime/message_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,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

0 comments on commit f77d39c

Please sign in to comment.