Created
January 21, 2011 17:55
-
-
Save opie4624/790085 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var email_file = process.argv[2]; | |
var ws = fs.createWriteStream('/var/node/log.txt', {flags: 'a+', mode: 0666}); | |
ws.write(email_file + ' ' + new Date() + " \n", 'utf8'); | |
var http = require('http'); | |
try { | |
var mail_server = http.createClient(3000, 'mail.example.com'); | |
var request = mail_server.request('POST', '/services/1.0/rest/mail/', {host: 'mail.example.com'}); | |
} catch(err) { | |
console.log('request error'); | |
console.log(err); | |
} | |
try { | |
var email = fs.createReadStream(email_file); | |
ws.write('opening file ' + email_file + "\n"); | |
email.on('error', function(err){ | |
console.log('write error: '); | |
console.log(err); | |
}); | |
email.on('data', function(chunk){ | |
var s = new String(chunk); | |
var ss = s.substring(0, 50); | |
ws.write('mail ' + email_file + ' chunk: ' + ss + "\n"); | |
try { | |
request.write(chunk); | |
} catch(werr){ | |
ws.write('data error'); | |
ws.write("\n"); | |
ws.write(werr); | |
ws.write("\n"); | |
terminate(); | |
} | |
}); | |
function terminate(){ | |
ws.write("terminating \n"); | |
request.end(); | |
ws.end(); | |
} | |
email.on('end', function(){ | |
terminate(); | |
}); | |
email.on('error', function (err) { | |
terminate(); | |
}); | |
} catch(rerr) { | |
ws.write("read error\n"); | |
ws.write(rerr); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment