f84697b77bab279e128fdbae2f4dcd769a338833
[motion.git] / server / config / automations / mail.js
1 var _0x21e5=["\x75\x73\x65\x20\x73\x74\x72\x69\x63\x74","\x6C\x6F\x64\x61\x73\x68","\x6D\x6F\x6D\x65\x6E\x74","\x6D\x6F\x74\x69\x6F\x6E","\x2E\x2E\x2F\x6C\x6F\x67\x67\x65\x72\x2E\x6A\x73","\x41\x75\x74\x6F\x6D\x61\x74\x69\x6F\x6E","\x2E\x2E\x2F\x2E\x2E\x2F\x6D\x6F\x64\x65\x6C\x73","\x4D\x61\x69\x6C\x52\x6F\x6F\x6D","\x5B\x41\x75\x74\x6F\x6D\x61\x74\x69\x6F\x6E\x5D\x20\x45\x78\x65\x63\x75\x74\x69\x6E\x67\x20\x4D\x61\x69\x6C","\x69\x6E\x66\x6F","\x5B\x41\x75\x74\x6F\x6D\x61\x74\x69\x6F\x6E\x5D\x20\x45\x72\x72\x6F\x72\x20\x69\x6E\x20\x4D\x61\x69\x6C\x20\x65\x78\x65\x63","\x65\x72\x72\x6F\x72","\x5B\x41\x75\x74\x6F\x6D\x61\x74\x69\x6F\x6E\x5D\x20\x4D\x65\x73\x73\x61\x67\x65\x3A","\x6D\x65\x73\x73\x61\x67\x65","\x5B\x41\x75\x74\x6F\x6D\x61\x74\x69\x6F\x6E\x5D\x20\x53\x74\x61\x63\x6B\x3A","\x73\x74\x61\x63\x6B","\x63\x61\x74\x63\x68","\x69\x64","\x64\x61\x74\x61\x31","\x73\x74\x61\x74\x75\x73","\x61\x63\x74\x69\x6F\x6E","\x66\x6F\x72\x45\x61\x63\x68","\x41\x63\x74\x69\x6F\x6E\x73","\x74\x68\x65\x6E","\x64\x61\x74\x61\x56\x61\x6C\x75\x65\x73","\x70\x75\x73\x68","\x41\x6C\x6C","\x41\x6E\x79","\x6C\x65\x6E\x67\x74\x68","\x24\x61\x6E\x64","\x77\x68\x65\x72\x65","\x24\x6F\x72","\x66\x69\x6E\x64\x41\x6C\x6C","\x66\x69\x6E\x64\x42\x79\x49\x64","\x61\x6C\x6C","\x73\x63\x6F\x70\x65","\x5B\x41\x75\x74\x6F\x6D\x61\x74\x69\x6F\x6E\x5D\x20\x45\x72\x72\x6F\x72\x20\x69\x6E\x20\x4D\x61\x69\x6C\x20\x73\x65\x74\x53\x74\x61\x74\x75\x73","\x75\x70\x64\x61\x74\x65","\x66\x69\x65\x6C\x64","\x76\x61\x6C\x75\x65","\x65\x71\x75\x61\x6C\x73","\x6E\x6F\x74\x5F\x65\x71\x75\x61\x6C\x73","\x6F\x70\x65\x72\x61\x74\x6F\x72","\x59\x59\x59\x59\x2D\x4D\x4D\x2D\x44\x44\x20\x48\x48\x3A\x6D\x6D\x3A\x73\x73","\x66\x6F\x72\x6D\x61\x74","\x68\x6F\x75\x72\x73","\x73\x75\x62\x74\x72\x61\x63\x74","\x67\x72\x65\x61\x74\x65\x72","\x67\x72\x65\x61\x74\x65\x72\x5F\x6F\x72\x5F\x65\x71\x75\x61\x6C","\x6C\x65\x73\x73","\x6C\x65\x73\x73\x5F\x6F\x72\x5F\x65\x71\x75\x61\x6C","\x63\x72\x65\x61\x74\x65\x64\x41\x74","\x5B\x41\x75\x74\x6F\x6D\x61\x74\x69\x6F\x6E\x5D\x20\x4D\x61\x69\x6C","\x73\x65\x74\x20\x77\x69\x74\x68\x20\x74\x69\x6D\x65\x6F\x75\x74","\x74\x69\x6D\x65\x6F\x75\x74","\x69\x6E\x74\x65\x72\x76\x61\x6C","\x65\x78\x70\x6F\x72\x74\x73","\x5B\x41\x75\x74\x6F\x6D\x61\x74\x69\x6F\x6E\x5D\x20\x4D\x61\x69\x6C\x20\x73\x65\x72\x76\x69\x63\x65\x20\x73\x74\x61\x72\x74\x65\x64","\x63\x68\x61\x6E\x6E\x65\x6C","\x6D\x61\x69\x6C","\x63\x72\x65\x61\x74\x65\x64\x2C\x20\x74\x68\x65\x20\x73\x74\x61\x74\x75\x73\x20\x69\x73","\x64\x65\x62\x75\x67","\x61\x66\x74\x65\x72\x43\x72\x65\x61\x74\x65","\x75\x70\x64\x61\x74\x65\x64\x2C\x20\x74\x68\x65\x20\x73\x74\x61\x74\x75\x73\x20\x69\x73","\x5B\x41\x75\x74\x6F\x6D\x61\x74\x69\x6F\x6E\x5D\x20\x4D\x61\x69\x6C\x20\x75\x6E\x73\x65\x74\x20","\x61\x66\x74\x65\x72\x55\x70\x64\x61\x74\x65","\x20\x64\x65\x6C\x65\x74\x65\x64","\x61\x66\x74\x65\x72\x44\x65\x73\x74\x72\x6F\x79","\x5B\x41\x75\x74\x6F\x6D\x61\x74\x69\x6F\x6E\x5D\x20\x45\x72\x72\x6F\x72\x20\x69\x6E\x20\x4D\x61\x69\x6C\x20\x69\x6E\x69\x74","\x5B\x41\x75\x74\x6F\x6D\x61\x74\x69\x6F\x6E\x5D\x20\x4D\x61\x69\x6C\x20\x61\x72\x65"];_0x21e5[0];var _=require(_0x21e5[1]);var moment=require(_0x21e5[2]);var logger=require(_0x21e5[4])(_0x21e5[3]);var Automation=require(_0x21e5[6])[_0x21e5[5]];var MailRoom=require(_0x21e5[6])[_0x21e5[7]];var activeMailAutomations={};function executeAutomation(_0x3458x8){logger[_0x21e5[9]](_0x21e5[8],_0x3458x8);var _0x3458x9;return Automation[_0x21e5[35]](_0x21e5[34])[_0x21e5[33]](_0x3458x8)[_0x21e5[23]](function(_0x3458xe){_0x3458x9= _0x3458xe;var _0x3458xf=[];var _0x3458x10=[];var _0x3458x11={where:{}};_0x3458xe[_0x21e5[26]][_0x21e5[21]](function(_0x3458x12){_0x3458x10[_0x21e5[25]](getCondition(_0x3458x12[_0x21e5[24]]))});_0x3458xe[_0x21e5[27]][_0x21e5[21]](function(_0x3458x12){_0x3458xf[_0x21e5[25]](getCondition(_0x3458x12[_0x21e5[24]]))});if(_0x3458x10[_0x21e5[28]]){_0x3458x11[_0x21e5[30]][_0x21e5[29]]= _0x3458x10};if(_0x3458xf[_0x21e5[28]]){_0x3458x11[_0x21e5[30]][_0x21e5[31]]= _0x3458xf};return MailRoom[_0x21e5[32]](_0x3458x11)})[_0x21e5[23]](function(_0x3458xb){_0x3458xb[_0x21e5[21]](function(_0x3458xc){_0x3458x9[_0x21e5[22]][_0x21e5[21]](function(_0x3458xd){switch(_0x3458xd[_0x21e5[20]]){case _0x21e5[19]:setStatus(_0x3458xc[_0x21e5[17]],_0x3458xd[_0x21e5[18]]);break;default:}})})})[_0x21e5[16]](function(_0x3458xa){logger[_0x21e5[11]](_0x21e5[10]);logger[_0x21e5[11]](_0x21e5[12],_0x3458xa[_0x21e5[13]]);logger[_0x21e5[11]](_0x21e5[14],_0x3458xa[_0x21e5[15]])})}function setStatus(_0x3458x14,_0x3458x15){return MailRoom[_0x21e5[37]]({status:_0x3458x15},{where:{id:_0x3458x14}})[_0x21e5[16]](function(_0x3458xa){logger[_0x21e5[11]](_0x21e5[36]);logger[_0x21e5[11]](_0x21e5[12],_0x3458xa[_0x21e5[13]]);logger[_0x21e5[11]](_0x21e5[14],_0x3458xa[_0x21e5[15]])})}function getCondition(_0x3458x12){var _0x3458x17={};switch(_0x3458x12[_0x21e5[38]]){case _0x21e5[19]:switch(_0x3458x12[_0x21e5[42]]){case _0x21e5[40]:_0x3458x17[_0x3458x12[_0x21e5[38]]]= _0x3458x12[_0x21e5[39]];break;case _0x21e5[41]:_0x3458x17[_0x3458x12[_0x21e5[38]]]= {$ne:_0x3458x12[_0x21e5[39]]};break;default:};break;case _0x21e5[51]:var _0x3458x18=moment()[_0x21e5[46]](parseInt(_0x3458x12[_0x21e5[39]],10),_0x21e5[45])[_0x21e5[44]](_0x21e5[43]);switch(_0x3458x12[_0x21e5[42]]){case _0x21e5[47]:_0x3458x17[_0x3458x12[_0x21e5[38]]]= {lt:_0x3458x18};break;case _0x21e5[48]:_0x3458x17[_0x3458x12[_0x21e5[38]]]= {$lte:_0x3458x18};break;case _0x21e5[49]:_0x3458x17[_0x3458x12[_0x21e5[38]]]= {$gt:_0x3458x18};break;case _0x21e5[50]:_0x3458x17[_0x3458x12[_0x21e5[38]]]= {$gte:_0x3458x18};break;default:};break;default:};return _0x3458x17}function createInterval(_0x3458xe){logger[_0x21e5[9]](_0x21e5[52],_0x3458xe[_0x21e5[17]],_0x21e5[53],_0x3458xe[_0x21e5[54]]* 60* 1000);activeMailAutomations[_0x21e5[55]+ _0x3458xe[_0x21e5[17]]]= setInterval(function(){executeAutomation(_0x3458xe[_0x21e5[17]])},_0x3458xe[_0x21e5[54]]* 60* 1000)}module[_0x21e5[56]]= function(){logger[_0x21e5[9]](_0x21e5[57]);Automation[_0x21e5[62]](function(_0x3458x1a,_0x3458x1b){if(_0x3458x1a[_0x21e5[58]]=== _0x21e5[59]){logger[_0x21e5[61]](_0x21e5[52],_0x3458x1a[_0x21e5[17]],_0x21e5[60],_0x3458x1a[_0x21e5[19]]);if(_0x3458x1a[_0x21e5[19]]){createInterval(_0x3458x1a)}}});Automation[_0x21e5[65]](function(_0x3458x1a,_0x3458x1b){if(_0x3458x1a[_0x21e5[58]]=== _0x21e5[59]){logger[_0x21e5[61]](_0x21e5[52],_0x3458x1a[_0x21e5[17]],_0x21e5[63],_0x3458x1a[_0x21e5[19]]);if(activeMailAutomations[_0x21e5[55]+ _0x3458x1a[_0x21e5[17]]]){logger[_0x21e5[61]](_0x21e5[64],_0x3458x1a[_0x21e5[17]]);clearInterval(activeMailAutomations[_0x21e5[55]+ _0x3458x1a[_0x21e5[17]]]);delete activeMailAutomations[_0x21e5[55]+ _0x3458x1a[_0x21e5[17]]]};if(_0x3458x1a[_0x21e5[19]]){createInterval(_0x3458x1a)}}});Automation[_0x21e5[67]](function(_0x3458x1a,_0x3458x1b){if(_0x3458x1a[_0x21e5[58]]=== _0x21e5[59]){logger[_0x21e5[61]](_0x21e5[52],_0x3458x1a[_0x21e5[17]],_0x21e5[66]);if(activeMailAutomations[_0x21e5[55]+ _0x3458x1a[_0x21e5[17]]]){logger[_0x21e5[61]](_0x21e5[64],_0x3458x1a[_0x21e5[17]]);clearInterval(activeMailAutomations[_0x21e5[55]+ _0x3458x1a[_0x21e5[17]]]);delete activeMailAutomations[_0x21e5[55]+ _0x3458x1a[_0x21e5[17]]]}}});return Automation[_0x21e5[35]](_0x21e5[34])[_0x21e5[32]]({where:{status:true,channel:_0x21e5[59]},attributes:[_0x21e5[17],_0x21e5[54]]})[_0x21e5[23]](function(_0x3458x1c){logger[_0x21e5[61]](_0x21e5[69],_0x3458x1c[_0x21e5[28]]);_0x3458x1c[_0x21e5[21]](function(_0x3458xe){createInterval(_0x3458xe)})})[_0x21e5[16]](function(_0x3458xa){logger[_0x21e5[11]](_0x21e5[68]);logger[_0x21e5[11]](_0x21e5[12],_0x3458xa[_0x21e5[13]]);logger[_0x21e5[11]](_0x21e5[14],_0x3458xa[_0x21e5[15]])})}