From 32e5008c18bed355e5a885c9a8582e8f92e5da0f Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Mon, 5 Dec 2016 19:49:35 +0100 Subject: changes: enable support for multiple mail targets --- modules/changes/changes.js | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) (limited to 'modules/changes') 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\n"+ +function constructMailBody(diffs){ + var body="From: changes \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(); } -- cgit v1.2.3-70-g09d2