'clj-imap-observer' is a Clojure library which lets you create a
com.sun.mail.imap.IdleManager
in a more functional way. Also consider
reading doc/intro.md.
(ns com.example.your-application
(:require [com.markusaschl.imap-observer :as imap-observer]
[com.markusaschl.imap-observer.extras :as imap-extras]))
Write something like this into
<your-project>/ressources/mail-properties.edn
:
{:host "example.com",
:username "user@example.com",
:password "password",
:imap-protocol "imaps",
:session-properties
{"mail.event.scope" "application"}}
(def +observer+ (observer/make-observer
(->> (clojure.java.io/resource "mail-properties.edn")
slurp
clojure.edn/read-string)
[{:name "INBOX"
:mode (:read-write extras/folder-modes)
:on-folder-opened
(fn [folder-obj] (def +folder+ folder-obj))
:on-messages-added
#(def +message+ (first %))}]))
.
After a certain period of inactivity, the server closes the connection to the
client. To fix a possible jakarta.mail.FolderClosedException
when reading
a folder or email, I offer this solution:
(let
[ten-minutes (->> 1000 (* 60) (* 10))
idle-agent (agent (->> (imap-observer/make-observer
(->> (clojure.java.io/resource "mail-properties.edn")
slurp
clojure.edn/read-string)
[{:name "INBOX"
:mode (:read-write imap-extras/folder-modes)
:on-messages-added (fn [messages])}])))]
(prn "starting execution")
(while true
(send idle-agent component/start)
(Thread/sleep ten-minutes)
(send idle-agent component/stop)
(prn "restarting execution")))
.
GreenMail
:on-folder-opened
, :on-messages-added
and
:on-messages-removed
) with GreenMail
extras
namespaceCan you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close