Permalink
Browse files

Eliminate many instances of reflection via type hints

  • Loading branch information...
1 parent e9e79c6 commit 8f7454d33d0e22606e2e0513970a5e5608f17bff @jafingerhut jafingerhut committed Apr 14, 2013
Showing with 17 additions and 15 deletions.
  1. +11 −10 src/postal/message.clj
  2. +2 −2 src/postal/sendmail.clj
  3. +3 −2 src/postal/smtp.clj
  4. +1 −1 src/postal/stress.clj
View
@@ -34,17 +34,17 @@
(declare make-jmessage)
(defn recipients [msg]
- (let [jmsg (make-jmessage msg)]
+ (let [^javax.mail.Message jmsg (make-jmessage msg)]
(map str (.getAllRecipients jmsg))))
(defn sender [msg]
(or (:sender msg) (:from msg)))
(defn make-address
- ([addr]
+ ([^String addr]
(try (InternetAddress. addr)
(catch Exception _)))
- ([addr name-str]
+ ([^String addr ^String name-str]
(try (InternetAddress. addr name-str)
(catch Exception _))))
@@ -55,13 +55,14 @@
(defn message->str [msg]
(with-open [out (java.io.ByteArrayOutputStream.)]
- (let [jmsg (if (instance? MimeMessage msg) msg (make-jmessage msg))]
+ (let [^javax.mail.Message jmsg (if (instance? MimeMessage msg)
+ msg (make-jmessage msg))]
(.writeTo jmsg out)
(str out))))
(defn add-recipient! [jmsg rtype addr]
(if-let [addr (make-address addr)]
- (doto jmsg
+ (doto ^javax.mail.Message jmsg
(.addRecipient rtype addr))
jmsg))
@@ -73,7 +74,7 @@
(add-recipient! jmsg rtype addr))))
jmsg)
-(defn- fileize [x]
+(defn- ^java.io.File fileize [x]
(if (instance? java.io.File x) x (java.io.File. x)))
(declare eval-bodypart eval-multipart)
@@ -112,23 +113,23 @@
;; alternative, encrypted...
;; The caller can use the first two entries to specify a type.
;; If no type is given, we default to "mixed" (for attachments etc.)
- [multiPartType, parts] (if (keyword? (first parts))
+ [^String multiPartType, parts] (if (keyword? (first parts))
[(name (first parts)) (rest parts)]
["mixed" parts])
mp (javax.mail.internet.MimeMultipart. multiPartType)]
(doseq [part parts]
(.addBodyPart mp (eval-part part)))
mp))
-(defn add-multipart! [jmsg parts]
+(defn add-multipart! [^javax.mail.Message jmsg parts]
(.setContent jmsg (eval-multipart parts)))
-(defn add-extra! [jmsg msgrest]
+(defn add-extra! [^javax.mail.Message jmsg msgrest]
(doseq [[n v] msgrest]
(.addHeader jmsg (if (keyword? n) (name n) n) v))
jmsg)
-(defn add-body! [jmsg body]
+(defn add-body! [^javax.mail.Message jmsg body]
(if (string? body)
(doto jmsg (.setText body))
(doto jmsg (add-multipart! body))))
View
@@ -56,9 +56,9 @@
:message message}))
(defn sendmail-find []
- (first (filter #(.isFile (java.io.File. %)) sendmails)))
+ (first (filter #(.isFile (java.io.File. ^String %)) sendmails)))
-(defn sanitize [text]
+(defn sanitize [^String text]
(.replaceAll text "\r\n" (System/getProperty "line.separator")))
(defn sendmail-send [msg]
View
@@ -26,11 +26,12 @@
[postal.support :only [make-props]])
(:import [javax.mail Transport Session]))
-(defn ^:dynamic smtp-send* [session proto {:keys [host port user pass]} msgs]
+(defn ^:dynamic smtp-send* [^Session session ^String proto
+ {:keys [host port user pass]} msgs]
(with-open [transport (.getTransport session proto)]
(.connect transport host port (str user) (str pass))
(let [jmsgs (map #(make-jmessage % session) msgs)]
- (doseq [jmsg jmsgs]
+ (doseq [^javax.mail.Message jmsg jmsgs]
(.sendMessage transport jmsg (.getAllRecipients jmsg)))
{:code 0 :error :SUCCESS :message "messages sent"})))
View
@@ -28,7 +28,7 @@
(:use [postal.smtp :only [smtp-send]]
[postal.message :only [make-fixture]]))
-(def DATEFORMAT (SimpleDateFormat. "yyyy-MM-dd.HH:mm:ss"))
+(def ^SimpleDateFormat DATEFORMAT (SimpleDateFormat. "yyyy-MM-dd.HH:mm:ss"))
(defonce counter (atom 0))

0 comments on commit 8f7454d

Please sign in to comment.