imap-notify

run a command when email is received
git clone git://jb55.com/imap-notify
Log | Files | Refs | README

commit c0936c0bb4b7e283bbfeccdbac77f4cb50f71b3b
parent 6a52fd64b2c29fcf857c79c9d6f45fcf128920f8
Author: William Casarin <jb55@jb55.com>
Date:   Tue, 18 Jul 2017 16:17:11 -0700

figure out this error

Diffstat:
Mindex.js | 12++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/index.js b/index.js @@ -11,6 +11,7 @@ const host = args[5] || process.env.IMAP_NOTIFY_HOST || "imap.gmail.com" const port = args[6] || process.env.IMAP_NOTIFY_PORT || 993 const allow = process.env.IMAP_ALLOW_UNAUTHORIZED == null? false : !!process.env.IMAP_ALLOW_UNAUTHORIZED const timeout = process.env.IMAP_IDLE_TIMEOUT || 300000; // 5 mins +const verbose = !!process.env.IMAP_VERBOSE; function usage() { console.error("usage: imap-notify USER PASS CMD [HOST] [PORT]") @@ -27,12 +28,19 @@ const socket = tls.connect({host: host, port: port, rejectUnauthorized: !allow}, function handleNotifications() { socket.on("data", (data) => { var str = data.toString(); - console.error(str) + if (verbose) + console.error(str) const res = /\* (\d+) EXISTS/.exec(str); if (ready && res && res[1]) { - execFile(cmd, [res[1]]) + execFile(cmd, [res[1]], (error, stdout, stderr) => { + if (error) { + console.log(stdout) + console.error(stderr) + process.exit(3) + } + }) } if (/\+ idling/.test(str))