imap-notify

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

commit 6a52fd64b2c29fcf857c79c9d6f45fcf128920f8
parent 34f9b5e611e7f36caf44a6c5db23c707d716e999
Author: William Casarin <jb55@jb55.com>
Date:   Tue, 18 Jul 2017 11:25:24 -0700

proper idle refresh

Diffstat:
Mindex.js | 9++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/index.js b/index.js @@ -10,6 +10,7 @@ const cmd = args[4] || process.env.IMAP_NOTIFY_CMD 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 function usage() { console.error("usage: imap-notify USER PASS CMD [HOST] [PORT]") @@ -39,11 +40,13 @@ const socket = tls.connect({host: host, port: port, rejectUnauthorized: !allow}, }) } - socket.write(`tag login ${user} ${pass}\r\n`) - socket.write("A001 SELECT INBOX\r\n") - socket.write("A002 IDLE\r\n") + socket.write(`tag login ${user} ${pass}\r\ntag SELECT INBOX\r\ntag IDLE\r\n`) handleNotifications() + setInterval(() => { + socket.write("DONE\r\ntag IDLE\r\n"); + }, timeout); + socket.on("close", () => process.exit(2)) })