diff options
author | tomsmeding <tom.smeding@gmail.com> | 2016-12-05 19:49:35 +0100 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2016-12-05 19:49:35 +0100 |
commit | 32e5008c18bed355e5a885c9a8582e8f92e5da0f (patch) | |
tree | a95ce712994c942794a88cfa3a4d6dda972dc507 | |
parent | 6d760d4d654b2cd26649aa5f196d00f983c2e5a8 (diff) |
changes: enable support for multiple mail targets
-rw-r--r-- | modules/changes/changes.js | 35 |
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(); } |