summaryrefslogtreecommitdiff
path: root/modules/changes
diff options
context:
space:
mode:
Diffstat (limited to 'modules/changes')
-rw-r--r--modules/changes/changes.js35
1 files changed, 21 insertions, 14 deletions
diff --git a/modules/changes/changes.js b/modules/changes/changes.js
index 49e2420..dde20da 100644
--- a/modules/changes/changes.js
+++ b/modules/changes/changes.js
@@ -182,21 +182,28 @@ function collectLastHashes(){
return lasthashes;
}
-function sendMail(tomail,body,cb){
- var proc=child_process.spawn("sendmail",[tomail],{stdio:["pipe",process.stdout,process.stderr]});
- proc.stdin.on("error",function(e){
- console.log(e);
- cb(e);
- });
- proc.stdin.write(body,function(){
- proc.stdin.end();
- cb();
- });
+function sendMail(tomails,body,cb){
+ if(typeof tomails=="string")tomails=[tomails];
+ else if(!Array.isArray(tomails)){
+ throw new Error("tomails argument in sendMail not an array!");
+ }
+ var i;
+ for(i=0;i<tomails.length;i++){
+ var proc=child_process.spawn("sendmail",[tomails[i]],{stdio:["pipe",process.stdout,process.stderr]});
+ proc.stdin.on("error",function(e){
+ console.log(e);
+ cb(e);
+ });
+ proc.stdin.write("To: "+tomails[i]+"\n"+body,function(){
+ proc.stdin.end();
+ cb();
+ });
+ //process will linger till it's finished
+ }
}
-function constructMailBody(tomail,diffs){
- var body="To: "+tomail+"\n"+
- "From: changes <changes_module@tomsmeding.com>\n"+
+function constructMailBody(diffs){
+ var body="From: changes <changes_module@tomsmeding.com>\n"+
"Subject: changes notification mail\n\n"+
"The changes module recorded some changes in watched webpages.\n"+
"The URLs and their old and new content hashes are shown below.\n\n";
@@ -229,7 +236,7 @@ function performNotify(settings,cb){
}
console.log("performNotify: diffs = "+JSON.stringify(diffs));
if(diffs.length!=0){
- sendMail(settings.to,constructMailBody(settings.to,diffs),cb);
+ sendMail(settings.to,constructMailBody(diffs),cb);
} else {
cb();
}