Liking cljdoc? Tell your friends :D
Clojure only.

mailseq.maildir.watch

Watch a Maildir for new messages using java.nio.file.WatchService.

This is the Maildir counterpart of mailseq.imap.idle: a blocking (or async) loop that calls a user-supplied function each time a new message file appears in cur/ or new/.

Internally, files are delivered to Maildir via an atomic rename from tmp/ into new/ (or directly into cur/ by some MDAs). The WatchService sees an ENTRY_CREATE event for each such rename.

A set of already-seen stable ids prevents processing the same message twice — for instance when another MUA moves a file from new/ to cur/, which produces a CREATE in cur/ for a message we already saw in new/.

Watch a Maildir for new messages using `java.nio.file.WatchService`.

This is the Maildir counterpart of `mailseq.imap.idle`: a blocking
(or async) loop that calls a user-supplied function each time a new
message file appears in `cur/` or `new/`.

Internally, files are delivered to Maildir via an atomic rename from
`tmp/` into `new/` (or directly into `cur/` by some MDAs). The
WatchService sees an `ENTRY_CREATE` event for each such rename.

A set of already-seen stable ids prevents processing the same
message twice — for instance when another MUA moves a file from
`new/` to `cur/`, which produces a CREATE in `cur/` for a message
we already saw in `new/`.
raw docstring

watchclj

(watch path on-message)
(watch path on-message opts)
(watch path on-message opts closed?)

Watch a Maildir for new messages, calling on-message for each.

Blocks the current thread. Monitors cur/ and new/ for new files using Java's WatchService (inotify on Linux, kqueue on macOS).

Existing messages at startup are recorded as seen — only truly new files trigger on-message.

Options: :parse-opts - options for message->map (default: {}) :on-error - function called with Exception on errors (default: log/error) :settle-ms - delay in ms after ENTRY_CREATE before reading the file (default: 50). Handles rare cases where the filesystem hasn't fully committed the rename.

Returns nil when the thread is interrupted, leaving the interrupt flag set, or when cur/ or new/ disappears, after reporting it to on-error. With a closed? atom, also returns within a second of it becoming true: mailseq/close stops the watch that way.

Example: (watch "/home/me/Mail" (fn [msg] (println "New:" (:subject msg))) {:parse-opts {:attachments? false}})

Watch a Maildir for new messages, calling `on-message` for each.

Blocks the current thread. Monitors `cur/` and `new/` for new files
using Java's WatchService (inotify on Linux, kqueue on macOS).

Existing messages at startup are recorded as seen — only truly new
files trigger `on-message`.

Options:
  :parse-opts  - options for message->map (default: {})
  :on-error    - function called with Exception on errors
                 (default: log/error)
  :settle-ms   - delay in ms after ENTRY_CREATE before reading
                 the file (default: 50). Handles rare cases where
                 the filesystem hasn't fully committed the rename.

Returns nil when the thread is interrupted, leaving the interrupt
flag set, or when `cur/` or `new/` disappears, after reporting it
to `on-error`. With a `closed?` atom, also returns within a second
of it becoming true: `mailseq/close` stops the watch that way.

Example:
  (watch "/home/me/Mail"
         (fn [msg] (println "New:" (:subject msg)))
         {:parse-opts {:attachments? false}})
sourceraw docstring

watch-asyncclj

(watch-async path on-message)
(watch-async path on-message opts)
(watch-async path on-message opts closed?)

Start watching a Maildir in a new daemon thread. Returns a java.io.Closeable: .close stops the watch and waits up to 5 s for the thread.

The watch is set up in the calling thread: an invalid path throws here, and every message delivered after this returns is reported.

Example: (def watcher (watch-async "/home/me/Mail" (fn [msg] (println "New:" (:subject msg))))) ;; Later: (.close watcher)

Start watching a Maildir in a new daemon thread. Returns a
`java.io.Closeable`: `.close` stops the watch and waits up to 5 s
for the thread.

The watch is set up in the calling thread: an invalid path throws
here, and every message delivered after this returns is reported.

Example:
  (def watcher
    (watch-async "/home/me/Mail"
                 (fn [msg] (println "New:" (:subject msg)))))
  ;; Later:
  (.close watcher)
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close