From 19b7403174410cb5f0b04b11f8e2eb00d6ebc633 Mon Sep 17 00:00:00 2001 From: Ian Webster Date: Wed, 2 Dec 2015 23:36:39 -0800 Subject: [PATCH] switch to mutt --- lib/text.js | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/text.js b/lib/text.js index 818bd83..ca4caae 100644 --- a/lib/text.js +++ b/lib/text.js @@ -53,30 +53,30 @@ function sendText(phone, message, region, cb) { var providers_list = providers[region]; - var done = _.after(providers_list.length, function() { + var emails = providers_list.map(function(provider) { + return provider.replace('%s', phone); + }).join(','); + //var child = spawn('mail', ['-s', 'txt', '-a', 'From:' + fromAddress, email]); + var args = ['-s', 'txt', '-e', 'set from=' + fromAddress, + '-e', 'set use_from=yes', '-e', 'set envelope_from=yes', '-b', emails]; + var child = spawn('mutt', args); + var decoder = new StringDecoder('utf8'); + child.stdout.on('data', function(data) { + output(decoder.write(data)); + }); + child.stderr.on('data', function(data) { + output(decoder.write(data)); + }); + child.on('error', function(data) { + output('mutt failed', {email: email, data: decoder.write(data)}); cb(false); }); - - _.each(providers_list, function(provider) { - var email = provider.replace('%s', phone); - var child = spawn('mail', ['-s', 'txt', '-a', 'From:' + fromAddress, email]); - var decoder = new StringDecoder('utf8'); - child.stdout.on('data', function(data) { - output(decoder.write(data)); - }); - child.stderr.on('data', function(data) { - output(decoder.write(data)); - }); - child.on('error', function(data) { - output('sendmail failed', {email: email, data: decoder.write(data)}); - done(); - }); - child.on('exit', function(code, signal) { - done(); - }); - child.stdin.write(message + '\n'); - child.stdin.end(); + child.on('exit', function(code, signal) { + cb(false); }); + console.log(message); + child.stdin.write(message); + child.stdin.end(); } module.exports = {