How do I read my emails with clojure?
I want to parse messages from my IMAP mailbox using clojure.
I know there is a clojure-mail library, but I don't have a gmail account. Thank!
+3
source to share
1 answer
The Apache Commons IMAP Client Library is a smart choice. The kernel of their example program is trivially replicated downhole under 20 Clojure lines, if you don't worry about failover:
(ns mail-client.core
(:import [org.apache.commons.net PrintCommandListener]
[org.apache.commons.net.imap IMAPClient]))
(defn get-mail [server username password]
(doto (IMAPClient.)
(.setDefaultTimeout 60000)
(.addProtocolCommandListener (PrintCommandListener. System/out true))
(.connect server)
(.login username password)
(.setSoTimeout 6000)
(.capability)
(.select "inbox")
(.examine "inbox")
(.status "inbox" (into-array String ["MESSAGES"]))
(.logout)
(.disconnect)))
+5
source to share