node-imapnotify icon indicating copy to clipboard operation
node-imapnotify copied to clipboard

pass_eval is not working with pass

Open 2Belette opened this issue 8 years ago • 13 comments

Hi,

I switched from python-imapnotify to your node-imapnotify as the one on python is not working.

Only one (important) thing for me is that I am unable to make it work with pass.

"password_eval": "/usr/bin/pass servers/email",

is failling for me :

{"name":"imap_inotify","hostname":"x","pid":27719,"level":50,"box":"INBOX","msg":"Error registered","time":"2017-10-30T12:31:52.486Z","v":0}
{"name":"imap_inotify","hostname":"x","pid":27719,"level":50,"box":"INBOX","msg":"{ Error: No supported authentication method(s) available. Unable to login.\n    at Connection.<anonymous> (/usr/lib/node_modules/imapnotify/node_modules/imap/lib/Connection.js:1679:15)\n    at Connection._resTagged (/usr/lib/node_modules/imapnotify/node_modules/imap/lib/Connection.js:1535:22)\n    at Parser.<anonymous> (/usr/lib/node_modules/imapnotify/node_modules/imap/lib/Connection.js:194:10)\n    at emitOne (events.js:96:13)\n    at Parser.emit (events.js:191:7)\n    at Parser._resTagged (/usr/lib/node_modules/imapnotify/node_modules/imap/lib/Parser.js:175:10)\n    at Parser._parse (/usr/lib/node_modules/imapnotify/node_modules/imap/lib/Parser.js:139:16)\n    at Parser._tryread (/usr/lib/node_modules/imapnotify/node_modules/imap/lib/Parser.js:82:15)\n    at TLSSocket.Parser._cbReadable (/usr/lib/node_modules/imapnotify/node_modules/imap/lib/Parser.js:53:12)\n    at emitNone (events.js:86:13) source: 'authentication' }","time":"2017-10-30T12:31:52.487Z","v":0}

I am missing a proper format to use it ? It is like the parsing of the command is failling.

Many thanks!

2Belette avatar Oct 31 '17 15:10 2Belette

any idea?

2Belette avatar Nov 27 '17 15:11 2Belette

https://github.com/a-sk/node-imapnotify/blob/master/README.md

renatofdds avatar Dec 12 '17 16:12 renatofdds

@renatofdds : thanks but it is not very useful comment as you can imagine I already took a look on this! If I am asking and tried it is because I am not finding the answers.. If you have the command to test instead I would greatly appreciate :)

2Belette avatar Dec 13 '17 14:12 2Belette

I figured you haven't read it because of the configuration keys you are trying to use: there is no mention of some "pass_eval" key.

You should use it like imapnotify -c /path/to/your/config.js, and on your config.js something like (as described on the readme):

var child_process = require('child_process');

function getStdout(cmd) {
    var stdout = child_process.execSync(cmd);
    return stdout.toString().trim();
}

exports.host = "imap.gmail.com"
exports.port = 993;
exports.tls = true;
exports.tlsOptions = {
    "rejectUnauthorized": false
};
exports.username = "[email protected]";
exports.password = getStdout("/usr/bin/pass servers/email | head -n1");
exports.onNotify = "/usr/bin/mbsync -q gmail-inbox"
exports.onNotifyPost = { mail: "pgrep Xorg &>/dev/null && notify-send '<b>Gmail</b>\nNew mail'" }
exports.boxes = ["INBOX"];

renatofdds avatar Dec 13 '17 17:12 renatofdds

oki thanks! I misunderstood as I thought it was possible to use JSON format instead of the one described on the readme. or perhaps you have a trick for that? If I remember it was working with JSON format if the pass is in clear text so I am only missing a way to eval pass in JSON...

many thanks

2Belette avatar Dec 13 '17 18:12 2Belette

JSON configuration is not executed because ultimately it gets just require()'d from imapnotify JS code and there are currently no configuration keys parsed and executed as commands by the code, so therefore the pass needs to be in plain text.

I think you are confusing this as a port of python-imapnotify, it is not.

renatofdds avatar Dec 13 '17 18:12 renatofdds

got it! you are right, I had two concurrent installation (python and node). I have been able to make it work many thanks

2Belette avatar Dec 14 '17 09:12 2Belette

by the way I have tried to react only on IMAP event and tried: exports.onNewMail = "/usr/local/bin/mbsync test"; but it doesn't see to work as /usr/local/bin/mbsync test is launched for every event.

Another thing I noticed is that for a single event it seems that the command is launched twice:

{"name":"imap_inotify","hostname":"x","pid":18679,"level":30,"box":"INBOX","msg":"New Mail","time":"2017-12-14T12:25:38.345Z","v":0}
{"name":"imap_inotify","hostname":"x","pid":18679,"level":30,"msg":"Running /usr/local/bin/mbsync test","time":"2017-12-14T12:25:38.349Z","v":0}
{"name":"imap_inotify","hostname":"x","pid":18679,"level":30,"msg":"Running /usr/local/bin/mbsync test","time":"2017-12-14T12:25:39.573Z","v":0}

Any idea on what I am doing wrong? It seems I am very close now..

Many thanks

2Belette avatar Dec 14 '17 12:12 2Belette

onNewMail is an alias for onNotify. To trigger callback on specific events use the next form:

"onNotify": {"mail": "/usr/local/bin/mbsync test"},

For more details, see README.md.

rasendubi avatar Dec 18 '17 14:12 rasendubi

Thanks, I tried to put exports.onNotify = {"mail": "/usr/local/bin/mbsync test"}; in my config.js file and I get this error:

/usr/lib/node_modules/imapnotify/node_modules/printf/lib/printf.js:31
  content = str.slice(lastIndex);
                ^

TypeError: str.slice is not a function
    at tokenize (/usr/lib/node_modules/imapnotify/node_modules/printf/lib/printf.js:31:17)
    at new Formatter (/usr/lib/node_modules/imapnotify/node_modules/printf/lib/printf.js:41:18)
    at module.exports (/usr/lib/node_modules/imapnotify/node_modules/printf/lib/printf.js:459:19)
    at notify (/usr/lib/node_modules/imapnotify/bin/imapnotify:243:28)
    at Connection.<anonymous> (/usr/lib/node_modules/imapnotify/bin/imapnotify:66:4)
    at emitOne (events.js:96:13)
    at Connection.emit (events.js:191:7)
    at Connection._resUntagged (/usr/lib/node_modules/imapnotify/node_modules/imap/lib/Connection.js:1287:14)
    at Parser.<anonymous> (/usr/lib/node_modules/imapnotify/node_modules/imap/lib/Connection.js:191:10)
    at emitOne (events.js:96:13)


2Belette avatar Dec 18 '17 14:12 2Belette

Looks like an instance of #15

rasendubi avatar Dec 18 '17 15:12 rasendubi

@rasendubi thanks and good tips!

I was using exports.onNotifyPost = "/usr/bin/true"; but it seems that all events need to be defined if not I got the empty error occured.

This seems to do the trick: exports.onNotifyPost = {"mail": "/usr/bin/true", "update": "/usr/bin/true", "expunge": "/usr/bin/true"};

2Belette avatar Dec 18 '17 15:12 2Belette

@2Belette, I believe #20 should fix that.

rasendubi avatar Dec 27 '17 13:12 rasendubi