imap-notify

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

commit fb7c83d1ca9baa8c6736fdb34dab445de5d288b3
parent 4c75b31a7731417b7fa9b5a41764b0a2f083d564
Author: William Casarin <jb55@jb55.com>
Date:   Tue, 18 Jul 2017 09:34:13 -0700

fix brokenness

Diffstat:
Mdefault.nix | 2+-
Mindex.js | 9++++++---
2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/default.nix b/default.nix @@ -21,7 +21,7 @@ stdenv.mkDerivation rec { meta = with stdenv.lib; { description = "imap-notify"; - homepage = "https://github.com/jb55/gmail-notify"; + homepage = "https://github.com/jb55/imap-notify"; maintainers = with maintainers; [ jb55 ]; license = licenses.mit; }; diff --git a/index.js b/index.js @@ -20,6 +20,8 @@ if (!user || !pass || !cmd) { usage(); } +var hadFirst = false; + const socket = tls.connect({host: host, port: port, rejectUnauthorized: !allow}, () => { function handleNotifications() { socket.on("data", (data) => { @@ -27,9 +29,12 @@ const socket = tls.connect({host: host, port: port, rejectUnauthorized: !allow}, console.error(str) const res = /\* (\d+) EXISTS/.exec(str); - if (res && res[1]) { + + if (hadFirst && res && res[1]) { execFile(cmd, [res[1]]) } + + if (!hadFirst) hadFirst = true; }) } @@ -40,6 +45,4 @@ const socket = tls.connect({host: host, port: port, rejectUnauthorized: !allow}, handleNotifications() socket.on("close", () => process.exit(2)) - - setInterval(socket.write.bind(null, "A002 IDLE\r\n"), 300000) })