Permalink
Browse files

Browser example update, bump version to 0.0.2, misc formatting changes

  • Loading branch information...
1 parent e11eb5f commit 804ecb9d1f1fa29d49f89a6f04521a48635085a7 @manutter51 committed Oct 29, 2011
Showing with 43 additions and 38 deletions.
  1. +1 −0 .gitignore
  2. +5 −0 CHANGES.md
  3. +1 −1 README.md
  4. +1 −1 project.clj
  5. +15 −15 src/examples/browser.clj
  6. +2 −2 src/nonomail/imap.clj
  7. +7 −7 src/nonomail/session.clj
  8. +11 −12 src/nonomail/util.clj
View
@@ -14,3 +14,4 @@ src/nonomail/config.clj
.classpath
.project
bin/
+.settings/
View
@@ -0,0 +1,5 @@
+# CHANGE HISTORY
+
+## 0.0.2
+ * Renamed (nonomail.session/get-session) to simply (nonomail.session/session)
+
View
@@ -6,7 +6,7 @@ This project is not yet ready for prime time. I wouldn't use it yet if I were yo
## Leiningen project.clj settings:
- [nonomail "0.0.1-SNAPSHOT"]
+ [nonomail "0.0.2-SNAPSHOT"]
## Usage
View
@@ -1,4 +1,4 @@
-(defproject nonomail "0.0.1-SNAPSHOT"
+(defproject nonomail "0.0.2-SNAPSHOT"
:description "A simple interface to javax.mail from clojure."
:dependencies [[org.clojure/clojure "1.2.1"]
[javax.mail/mail "1.4.4"]
View
@@ -19,31 +19,31 @@
(let [msgs (get-new-mail conn)
msg (first msgs)]
(if-not msg
- "No new messages"
- (str (interpose "\n"
- "To: " (:to msg)
- "From: " (:from msg)
- "Subject: " (:subject msg)
- ""
- (:body msg))))))
+ (print "No new messages\n")
+ (print (str (interpose "\n"
+ "To: " (:to msg)
+ "From: " (:from msg)
+ "Subject: " (:subject msg)
+ ""
+ (:body msg)))))))
(defn print-multipart-msg
[conn]
(let [msgs (get-new-mail conn)
msg (first msgs)]
(if-not msg
- "No new messages"
- (str (interpose "\n"
- "To: " (:to msg)
- "From: " (:from msg)
- "Subject: " (:subject msg)
- ""
- (concat (filter #(#{:plain} (:type %)) (:body msg))))))))
+ (print "No new messages\n")
+ (print (str (interpose "\n"
+ "To: " (:to msg)
+ "From: " (:from msg)
+ "Subject: " (:subject msg)
+ ""
+ (concat (filter #(#{:plain} (:type %)) (:body msg)))))))))
(defn read-all [config]
(let [conn (mail/connect config)]
(if (mail/error? conn)
(println "Could not connect to mail server, " (apply str (mail/errors conn)))
(do
(print-first-msg conn)
- (print-multipart-msg conn))))
+ (print-multipart-msg conn)))))
View
@@ -3,7 +3,7 @@
(:require [nonomail.util :as util])
(:use nonomail.session)
(:import [com.sun.mail.imap IMAPStore IMAPFolder IMAPMessage]
- [javax.mail URLName]))
+ [javax.mail Session URLName]))
;; Convenience functions
(defn connect [config]
@@ -50,7 +50,7 @@ Example:
password (util/get-first :pass config session-config nil)
is-ssl (util/get-first :ssl config session-config false)
url (URLName. "imap" host -1 "" "" "")]
- (IMAPStore. j-sess url "" is-ssl)))
+ (IMAPStore. ^Session j-sess, ^URLName url)))
(defn find [session & params]
)
View
@@ -16,7 +16,7 @@ rather than creating a new one."
port (if (string? port) port (str port))
auth (:auth config)
auth (if (string? auth) auth (str auth))
- extra-headers (util/only-string-keys config)]
+ extra-headers (util/only-string-keys config)]
(doto props
(.put "mail.host" (:host config))
(.put "mail.port" port)
@@ -29,7 +29,7 @@ rather than creating a new one."
(doto props
(.put "mail.starttls.enable" "true")
(.put "mail.socketFactory.class"
- "javax.net.ssl.SSLSocketFactory")
+ "javax.net.ssl.SSLSocketFactory")
(.put "mail.socketFactory.fallback" "false")))
; Any user-supplied properties?
(when extra-headers
@@ -42,9 +42,9 @@ rather than creating a new one."
to use in creating a valid session."
[config]
(let [authenticator (proxy [javax.mail.Authenticator] []
- (getPasswordAuthentication
- []
- (javax.mail.PasswordAuthentication.
+ (getPasswordAuthentication
+ []
+ (javax.mail.PasswordAuthentication.
(:user config) (:pass config))))]
authenticator))
@@ -80,8 +80,8 @@ This function returns an atom containing a map with the following keys:
:props props
:authenticator authenticator
:session session
- :require-valid-recipients (get config :require-valid-recipients true)
- :error []}]
+ :require-valid-recipients (get config :require-valid-recipients true)
+ :error []}]
(atom session-map)))
(defn get-session-property
View
@@ -6,9 +6,9 @@ Map keys can be strings or keywords."
[p m]
(doseq [k (keys m)]
(let [ky (if (keyword? k)
- (name k)
- k)
- v (m k)]
+ (name k)
+ k)
+ v (m k)]
(.put p ky v))))
(defn prop-names
@@ -22,7 +22,7 @@ on the object, as strings."
set on the object, with the key names converted to keywords."
[p]
(let [keys (prop-names p)
- pull-key (fn [m k] (assoc m (keyword k) (.get p k)))]
+ pull-key (fn [m k] (assoc m (keyword k) (.get p k)))]
(reduce pull-key {} keys)))
(defn only-string-keys
@@ -38,8 +38,8 @@ are strings."
of that object, as it would be passed to a Mail Delivery Agent."
[msg]
(with-open [out (java.io.ByteArrayOutputStream.)]
- (.writeTo msg out)
- (str out)))
+ (.writeTo msg out)
+ (str out)))
(defn as-file
"If f is a java.io.File instance, return it, else convert it to an instance
@@ -87,9 +87,8 @@ use as singletons; if you leave off the #{:foo}, parse-args will assume that
(let [v (first r)
r2 (next r)]
(cond
- (nil? v) (recur (assoc m k :exists) nil nil)
- (keyword? v) (if (singleton? k)
- (recur (assoc m k :exists) v r2)
- (recur (assoc m k v) (first r2) (rest r2)))
- :else (recur (assoc m k v) (first r2) (rest r2))))))))
-
+ (nil? v) (recur (assoc m k :exists) nil nil)
+ (keyword? v) (if (singleton? k)
+ (recur (assoc m k :exists) v r2)
+ (recur (assoc m k v) (first r2) (rest r2)))
+ :else (recur (assoc m k v) (first r2) (rest r2))))))))

0 comments on commit 804ecb9

Please sign in to comment.