Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/postal/message.clj
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@
(.setDescription (:description part)))))
(doto (javax.mail.internet.MimeBodyPart.)
(.setContent (:content part) (:type part))
(cond-> (:content-id part)
(.setContentID (str "<" (:content-id part) ">")))
(cond-> (:file-name part)
(.setFileName (encode-filename (:file-name part))))
(cond-> (:description part)
Expand Down
15 changes: 15 additions & 0 deletions test/postal/test/message.clj
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@
(:use [postal.message]
[clojure.test :only [run-tests deftest is]]
[clojure.java.io :as io]
[clojure.string :as str]
[clojure.data.codec.base64 :as b64]
[postal.date :only [make-date]])
(:import [java.util Properties UUID]
[java.lang String]
[javax.mail Session Message$RecipientType]
[javax.mail.internet MimeMessage InternetAddress
AddressException]
Expand Down Expand Up @@ -85,6 +88,18 @@
(is (.contains m "tempfile"))
(.delete f)))

(deftest test-inline-stream
; https://github.com/mathiasbynens/small/blob/master/png-transparent.png
(let [png-bytes (byte-array (map byte [-119 80 78 71 13 10 26 10 0 0 0 13 73 72 68 82 0 0 0 1 0 0 0 1 8 6 0 0 0 31 21 -60 -119 0 0 0 10 73 68 65 84 120 -100 99 0 1 0 0 5 0 1 13 10 45 -76 0 0 0 0 73 69 78 68 -82 66 96 -126]))
m (message->str
{:from "foo@bar.dom"
:to "baz@bar.dom"
:subject "Test"
:body [{:type "image/png"
:content png-bytes}]})]
(is (.contains (str/replace m #"[\r\n]" "") ; remove newlines to enable exact match using .contains
(String. ^bytes (b64/encode png-bytes))))))

(deftest test-attachment
(let [f1 (doto (java.io.File/createTempFile "_postal-" ".txt"))
_ (doto (java.io.PrintWriter. f1)
Expand Down