IMAP IDLE support for receiving push notifications when new messages arrive.
IDLE keeps a connection open and the server notifies the client when the folder state changes (new messages, deletions, flag changes).
A heartbeat thread periodically breaks out of IDLE to force a NOOP roundtrip, preventing NATs/firewalls/servers from killing the connection.
IMAP IDLE support for receiving push notifications when new messages arrive. IDLE keeps a connection open and the server notifies the client when the folder state changes (new messages, deletions, flag changes). A heartbeat thread periodically breaks out of IDLE to force a NOOP roundtrip, preventing NATs/firewalls/servers from killing the connection.
(idle conn folder-name on-message)(idle conn folder-name on-message opts)Start an IDLE loop on a folder, calling on-message for each new message.
This function blocks the current thread. A heartbeat thread periodically breaks IDLE and forces a NOOP roundtrip to keep the connection alive.
Options: :parse-opts - options to pass to message->map (default: {}) :on-error - function called with Exception on errors, including those thrown by on-message (default: log/error) :heartbeat-ms - interval between NOOP heartbeats in ms (default: 1200000 = 20 minutes)
Returns nil when the folder or store is closed; a lost connection
is reported to on-error first, and is not retried. Interrupting the
thread does not break a pending IDLE: disconnect conn, or use
idle-async.
Example: (future (idle conn "INBOX" (fn [msg] (println "New:" (:subject msg))) {:parse-opts {:attachments? false} :heartbeat-ms 900000}))
Start an IDLE loop on a folder, calling on-message for each new message.
This function blocks the current thread. A heartbeat thread periodically
breaks IDLE and forces a NOOP roundtrip to keep the connection alive.
Options:
:parse-opts - options to pass to message->map (default: {})
:on-error - function called with Exception on errors, including
those thrown by on-message (default: log/error)
:heartbeat-ms - interval between NOOP heartbeats in ms
(default: 1200000 = 20 minutes)
Returns nil when the folder or store is closed; a lost connection
is reported to on-error first, and is not retried. Interrupting the
thread does not break a pending IDLE: disconnect `conn`, or use
`idle-async`.
Example:
(future
(idle conn "INBOX"
(fn [msg] (println "New:" (:subject msg)))
{:parse-opts {:attachments? false}
:heartbeat-ms 900000}))(idle-async conn folder-name on-message)(idle-async conn folder-name on-message opts)Start IDLE in a new daemon thread. Returns a java.io.Closeable:
.close closes the folder, which breaks the pending IDLE, and waits
up to 5 s for the thread. An unknown folder throws here, in the
calling thread.
Example: (def watcher (idle-async conn "INBOX" (fn [msg] (println "New:" (:subject msg))))) ;; Later: (.close watcher)
Start IDLE in a new daemon thread. Returns a `java.io.Closeable`:
`.close` closes the folder, which breaks the pending IDLE, and waits
up to 5 s for the thread. An unknown folder throws here, in the
calling thread.
Example:
(def watcher
(idle-async conn "INBOX"
(fn [msg] (println "New:" (:subject msg)))))
;; Later:
(.close watcher)cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |