Skip to content

Commit

Permalink
Apply charset to subject.
Browse files Browse the repository at this point in the history
Closes #36.

Conflicts:
	test/postal/test/message.clj
  • Loading branch information
drewr committed Nov 6, 2013
1 parent 0a690fc commit 705dc4f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/postal/message.clj
Expand Up @@ -176,7 +176,7 @@
(make-address (:from msg) charset)))
(.setReplyTo (when-let [reply-to (:reply-to msg)]
(make-addresses reply-to charset)))
(.setSubject (:subject msg))
(.setSubject (:subject msg) charset)
(.setSentDate (or (:date msg) (make-date)))
(.addHeader "User-Agent" (:user-agent msg (user-agent)))
(add-extra! (drop-keys msg standard))
Expand Down
40 changes: 21 additions & 19 deletions test/postal/test/message.clj
Expand Up @@ -156,25 +156,27 @@
:reply-to "yermom@bar.dom"}]
(is (re-find #"Reply-To: yermom" (message->str m)))))

(deftest test-charset-addrs
(let [m {:from "íč <p@p.com>"
:to "Böb <bob@bar.dom>"
:cc ["Plain Addr <plain@bar.dom>"]
:subject "Test"
:body "Charsets!"}]
(is (.contains (message->str m) "=?utf-8?B?w63EjQ==?="))
(is (.contains (message->str m) "=?utf-8?Q?B=C3=B6b?="))
(is (.contains (message->str m) "Plain Addr")))
(let [m {:from "íč <p@p.com>"
:to "Böb <bob@bar.dom>"
:cc ["Plain Addr <plain@bar.dom>"]
:subject "Test"
:charset "iso-8859-1"
:body "Charsets!"}]
(is (.contains (message->str m)
"Content-Type: text/plain; charset=iso-8859-1"))
(is (.contains (message->str m) "=?iso-8859-1?B?7T8=?="))
(is (.contains (message->str m) "Plain Addr")))
(deftest test-charsets
(let [m (message->str
{:from "From íč <p@p.com>"
:to "To Böb <bob@bar.dom>"
:cc ["Plain Addr <plain@bar.dom>"]
:subject "Subject æøå" ;; Norwegian
:body "Charsets!"})]
(is (.contains m "From_=C3=AD=C4=8D?="))
(is (.contains m "To_B=C3=B6b?="))
(is (.contains m "Plain Addr"))
(is (.contains m "Subject_=C3=A6=C3=B8=C3=A5?=")))
(let [m (message->str
{:from "íč <p@p.com>"
:to "Böb <bob@bar.dom>"
:cc ["Plain Addr <plain@bar.dom>"]
:subject "Test"
:charset "iso-8859-1"
:body "Charsets!"})]
(is (.contains m "Content-Type: text/plain; charset=iso-8859-1"))
(is (.contains m "=?iso-8859-1?B?7T8=?="))
(is (.contains m "Plain Addr")))
(let [m (message->str
{:from "foo@bar.dom"
:to "baz@bar.dom"
Expand Down

0 comments on commit 705dc4f

Please sign in to comment.