1 var _0xa645=["\x75\x73\x65\x20\x73\x74\x72\x69\x63\x74","\x6C\x6F\x64\x61\x73\x68","\x75\x74\x69\x6C","\x70\x61\x74\x68","\x63\x68\x69\x6C\x64\x5F\x70\x72\x6F\x63\x65\x73\x73","\x6D\x6F\x6D\x65\x6E\x74","\x6B\x75\x65","\x62\x6C\x75\x65\x62\x69\x72\x64","\x4D\x61\x69\x6C\x53\x65\x72\x76\x65\x72\x49\x6E","\x2E\x2E\x2F\x2E\x2E\x2F\x6D\x6F\x64\x65\x6C\x73","\x4D\x61\x69\x6C\x4D\x65\x73\x73\x61\x67\x65","\x4D\x61\x69\x6C\x52\x6F\x6F\x6D","\x52\x65\x70\x6F\x72\x74\x4D\x61\x69\x6C","\x4D\x61\x69\x6C\x52\x6F\x6F\x6D\x53\x74\x61\x74\x75\x73","\x52\x65\x70\x6F\x72\x74\x4D\x61\x69\x6C\x53\x65\x73\x73\x69\x6F\x6E","\x53\x6D\x73\x4D\x65\x73\x73\x61\x67\x65","\x4D\x61\x69\x6C\x41\x63\x63\x6F\x75\x6E\x74","\x53\x65\x74\x74\x69\x6E\x67","\x43\x6F\x6E\x74\x61\x63\x74","\x43\x6F\x6D\x70\x61\x6E\x79","\x4D\x61\x69\x6C\x41\x74\x74\x61\x63\x68\x6D\x65\x6E\x74","\x6F\x70\x65\x6E","\x66\x73","\x70\x72\x6F\x6D\x69\x73\x69\x66\x79","\x63\x6C\x6F\x73\x65","\x77\x72\x69\x74\x65","\x6D\x61\x69\x6C","\x2E\x2E\x2F\x6C\x6F\x67\x67\x65\x72\x2E\x6A\x73","\x2E\x2E\x2F\x65\x6E\x76\x69\x72\x6F\x6E\x6D\x65\x6E\x74","\x2E\x2E\x2F\x75\x74\x69\x6C","\x63\x72\x65\x61\x74\x65\x51\x75\x65\x75\x65","\x67\x65\x74","\x63\x6F\x6E\x6E\x65\x63\x74\x69\x64","\x63\x68\x61\x6E\x67\x65\x64","\x45\x72\x72\x6F\x72\x20\x6F\x6E\x20\x6D\x61\x69\x6C\x20\x61\x63\x63\x65\x70\x74","\x65\x72\x72\x6F\x72","\x63\x61\x74\x63\x68","\x6D\x65\x73\x73\x61\x67\x65\x69\x64","\x66\x69\x6E\x64","\x73\x74\x6F\x70","\x6D\x65\x6D\x62\x65\x72\x6E\x61\x6D\x65","\x73\x65\x6E\x64","\x70\x72\x6F\x63\x65\x73\x73","\x74\x68\x65\x6E","\x6D\x65\x6D\x62\x65\x72\x69\x64","\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","\x75\x6E\x69\x71\x75\x65\x69\x64","\x75\x70\x64\x61\x74\x65","\x72\x65\x6A\x65\x63\x74\x65\x64\x41\x74","\x72\x65\x6A\x65\x63\x74","\x61\x66\x74\x65\x72\x55\x70\x64\x61\x74\x65","\x69\x6E\x52\x65\x70\x6C\x79\x54\x6F","\x73\x74\x61\x63\x6B","\x6D\x61\x69\x6C\x4D\x65\x73\x73\x61\x67\x65\x41\x66\x74\x65\x72\x43\x72\x65\x61\x74\x65","\x61\x74\x74\x61\x63\x68\x6D\x65\x6E\x74\x73","\x6C\x65\x6E\x67\x74\x68","\x64\x6F\x77\x6E\x6C\x6F\x61\x64\x5F","\x72\x61\x6E\x64\x6F\x6D","\x4D\x61\x69\x6C\x20\x68\x61\x6E\x64\x6C\x69\x6E\x67\x20\x65\x72\x72\x6F\x72","\x46\x69\x6C\x65","\x66\x69\x6C\x65\x4E\x61\x6D\x65","\x70\x72\x6F\x70\x65\x72\x6C\x79\x20\x73\x61\x76\x65\x64\x2E","\x64\x65\x62\x75\x67","\x64\x61\x74\x61","\x63\x6F\x6E\x74\x65\x6E\x74","\x77","\x72\x6F\x6F\x74","\x73\x65\x72\x76\x65\x72","\x66\x69\x6C\x65\x73","\x2F","\x6A\x6F\x69\x6E","\x63\x6F\x6E\x74\x65\x6E\x74\x54\x79\x70\x65","\x69\x64","\x63\x72\x65\x61\x74\x65","\x70\x75\x73\x68","\x66\x6F\x72\x45\x61\x63\x68","\x61\x6C\x6C","\x6D\x65\x73\x73\x61\x67\x65\x49\x64","\x52\x45\x43\x45\x49\x56\x45\x44","\x73\x75\x62\x6A\x65\x63\x74","\x66\x72\x6F\x6D","\x61\x64\x64\x72\x65\x73\x73","\x6D\x61\x70","\x74\x6F","\x63\x63","\x62\x63\x63","\x74\x65\x78\x74","\x68\x74\x6D\x6C","\x6E\x61\x6D\x65","\x6D\x61\x69\x6C\x49\x6E","\x73\x74\x61\x74\x75\x73","\x43\x4C\x4F\x53\x45\x44","\x73\x70\x72\x65\x61\x64","\x4C\x69\x73\x74\x49\x64","\x40","\x73\x70\x6C\x69\x74","\x66\x69\x6E\x64\x4F\x72\x43\x72\x65\x61\x74\x65","\x66\x69\x6E\x64\x4F\x6E\x65","\x6D\x61\x69\x6C\x41\x63\x63\x6F\x75\x6E\x74\x49\x64","\x66\x69\x6E\x64\x42\x79\x49\x64","\x4F\x50\x45\x4E","\x73\x79\x73\x74\x65\x6D","\x3B","\x67\x65\x74\x4D\x61\x69\x6C\x52\x6F\x6F\x6D","\x4D\x61\x69\x6C\x4D\x65\x73\x73\x61\x67\x65\x73","\x4E\x45\x57","\x53\x65\x72\x76\x65\x72\x20\x73\x74\x61\x74\x65\x20\x65\x72\x72\x6F\x72\x3A","\x73\x74\x61\x74\x65","\x73\x6F\x75\x72\x63\x65","\x49\x4D\x41\x50\x20\x70\x72\x6F\x63\x65\x73\x73\x20\x65\x72\x72\x6F\x72","\x6F\x6E","\x49\x4D\x41\x50\x20\x53\x45\x52\x56\x45\x52\x20\x25\x73\x20\x45\x58\x49\x54\x45\x44\x20\x57\x49\x54\x48\x20\x43\x4F\x44\x45\x20\x25\x73","\x6D\x65\x73\x73\x61\x67\x65","\x6D\x73\x67","\x74\x79\x70\x65","\x2F\x69\x6D\x61\x70","\x66\x6F\x72\x6B","\x72\x65\x71\x75\x65\x73\x74\x20\x66\x61\x69\x6C\x65\x64\x21","\x69\x6E\x66\x6F","\x72\x65\x71\x75\x65\x73\x74\x20\x73\x75\x63\x63\x65\x65\x64\x65\x64\x21","\x73\x65\x6E\x64\x52\x65\x71\x75\x65\x73\x74","\x61\x63\x63\x65\x70\x74\x4D\x65\x74\x68\x6F\x64","\x61\x63\x63\x65\x70\x74\x55\x72\x6C","\x4D\x61\x69\x6C\x20\x61\x63\x63\x6F\x75\x6E\x74\x20\x3C","\x3E\x20\x65\x78\x65\x63\x75\x74\x69\x6E\x67\x20\x61\x63\x63\x65\x70\x74\x20\x77\x65\x62\x68\x6F\x6F\x6B","\x64\x61\x74\x61\x56\x61\x6C\x75\x65\x73","\x61\x63\x74\x69\x6F\x6E\x73","\x65\x6E\x61\x62\x6C\x65\x64","\x65\x78\x65\x63\x41\x63\x74\x69\x6F\x6E","\x61\x63\x63\x65\x70\x74","\x72\x65\x6A\x65\x63\x74\x4D\x65\x74\x68\x6F\x64","\x72\x65\x6A\x65\x63\x74\x55\x72\x6C","\x3E\x20\x65\x78\x65\x63\x75\x74\x69\x6E\x67\x20\x72\x65\x6A\x65\x63\x74\x20\x77\x65\x62\x68\x6F\x6F\x6B","\x63\x6C\x6F\x73\x65\x4D\x65\x74\x68\x6F\x64","\x63\x6C\x6F\x73\x65\x55\x72\x6C","\x3E\x20\x65\x78\x65\x63\x75\x74\x69\x6E\x67\x20\x63\x6C\x6F\x73\x65\x20\x77\x65\x62\x68\x6F\x6F\x6B","\x57\x65\x62\x68\x6F\x6F\x6B\x20\x6E\x6F\x74\x20\x72\x65\x63\x6F\x67\x6E\x69\x7A\x65\x64","\x49\x4D\x41\x50\x20\x53\x45\x52\x56\x45\x52\x20\x25\x73\x20\x44\x45\x53\x54\x52\x4F\x59\x45\x44\x2C\x20\x50\x52\x4F\x43\x45\x53\x53\x20\x49\x44\x3A\x20\x25\x73\x20","\x70\x69\x64","\x6B\x69\x6C\x6C","\x72\x65\x6D\x6F\x76\x65","\x61\x66\x74\x65\x72\x44\x65\x73\x74\x72\x6F\x79","\x61\x66\x74\x65\x72\x43\x72\x65\x61\x74\x65","\x4D\x61\x69\x6C\x20\x61\x63\x63\x6F\x75\x6E\x74\x3A\x20","\x20\x55\x70\x64\x61\x74\x65","\x6D\x65\x72\x67\x65","\x75\x6E\x73\x68\x69\x66\x74","\x73\x61\x76\x65","\x72\x65\x6D\x6F\x76\x65\x4F\x6E\x43\x6F\x6D\x70\x6C\x65\x74\x65","\x65\x6D\x61\x69\x6C","\x4E\x65\x77\x20\x65\x6D\x61\x69\x6C\x20\x66\x72\x6F\x6D\x3A\x20\x25\x73","\x6D\x61\x69\x6C\x4D\x65\x73\x73\x61\x67\x65","\x72\x6F\x6F\x6D","\x61\x63\x63\x6F\x75\x6E\x74","\x64\x69\x73\x63\x6F\x6E\x6E\x65\x63\x74","\x65\x78\x69\x74","\x66\x69\x6E\x61\x6C\x6C\x79","\x72\x6F\x6F\x6D\x69\x64","\x63\x72\x65\x61\x74\x65\x4D\x61\x69\x6C","\x63\x72\x65\x61\x74\x65\x53\x6D\x73","\x63\x72\x65\x61\x74\x65\x4D\x61\x69\x6C\x51\x75\x65\x75\x65\x53\x65\x73\x73\x69\x6F\x6E","\x2F\x73\x65\x72\x76\x65\x72\x2F\x63\x6F\x6E\x66\x69\x67\x2F\x66\x6F\x72\x6B\x65\x64\x5F\x72\x6F\x75\x74\x69\x6E\x67\x2F\x6D\x61\x69\x6C\x2F\x69\x6E\x64\x65\x78\x2E\x6A\x73","\x73\x74\x61\x72\x74","\x25\x73\x2E\x25\x73","\x75\x6E\x69\x78","\x65\x78\x70\x6F\x72\x74\x73","\x75\x73\x65\x72\x6E\x61\x6D\x65","\x61\x63\x63\x6F\x75\x6E\x74\x69\x64","\x4D\x61\x69\x6C\x41\x63\x63\x6F\x75\x6E\x74\x49\x64","\x6D\x61\x69\x6C\x52\x6F\x75\x74\x69\x6E\x67\x43\x61\x70\x61\x63\x69\x74\x79","\x66\x69\x6E\x64\x41\x6C\x6C","\x49\x4D\x41\x50\x20\x53\x45\x52\x56\x45\x52\x20\x25\x73\x20\x55\x50\x44\x41\x54\x45\x44\x2C\x20\x50\x52\x4F\x43\x45\x53\x53\x20\x49\x44\x3A\x20\x25\x73\x20"];_0xa645[0];var _=require(_0xa645[1]);var util=require(_0xa645[2]);var path=require(_0xa645[3]);var cp=require(_0xa645[4]);var moment=require(_0xa645[5]);var kue=require(_0xa645[6]);var Promise=require(_0xa645[7]);var ms=require(_0xa645[9])[_0xa645[8]];var msg=require(_0xa645[9])[_0xa645[10]];var Room=require(_0xa645[9])[_0xa645[11]];var Report=require(_0xa645[9])[_0xa645[12]];var Status=require(_0xa645[9])[_0xa645[13]];var Session=require(_0xa645[9])[_0xa645[14]];var Message=require(_0xa645[9])[_0xa645[10]];var SmsMessage=require(_0xa645[9])[_0xa645[15]];var Account=require(_0xa645[9])[_0xa645[16]];var Setting=require(_0xa645[9])[_0xa645[17]];var Contact=require(_0xa645[9])[_0xa645[18]];var Company=require(_0xa645[9])[_0xa645[19]];var Attachment=require(_0xa645[9])[_0xa645[20]];var open=Promise[_0xa645[23]](require(_0xa645[22])[_0xa645[21]]);var close=Promise[_0xa645[23]](require(_0xa645[22])[_0xa645[24]]);var write=Promise[_0xa645[23]](require(_0xa645[22])[_0xa645[25]]);var logger=require(_0xa645[27])(_0xa645[26]);var config=require(_0xa645[28]);var Util=require(_0xa645[29]);var queue=kue[_0xa645[30]]();var processes=[];var ami;Report[_0xa645[51]](function(_0x90f1x1e,_0x90f1x1f){var _0x90f1x20=_0x90f1x1e[_0xa645[31]]({plain:true});if(_0x90f1x1e[_0xa645[33]](_0xa645[32])){return Session[_0xa645[48]]({memberid:_0x90f1x20[_0xa645[44]],membername:_0x90f1x20[_0xa645[40]],leaveAt:moment()[_0xa645[46]](_0xa645[45])},{where:{uniqueid:_0x90f1x20[_0xa645[47]],leaveAt:null},individualHooks:true})[_0xa645[43]](function(){var _0x90f1x22=_[_0xa645[38]](processes,{id:_0x90f1x20[_0xa645[37]],channel:_0xa645[26]});if(_0x90f1x22){_0x90f1x22[_0xa645[42]][_0xa645[41]]({type:_0xa645[39],membername:_0x90f1x20[_0xa645[40]]})}})[_0xa645[36]](function(_0x90f1x21){logger[_0xa645[35]](_0xa645[34],_0x90f1x21)})}else {if(_0x90f1x1e[_0xa645[33]](_0xa645[49])){var _0x90f1x22=_[_0xa645[38]](processes,{id:_0x90f1x20[_0xa645[37]],channel:_0xa645[26]});if(_0x90f1x22){_0x90f1x22[_0xa645[42]][_0xa645[41]]({type:_0xa645[50],id:_0x90f1x20[_0xa645[44]],membername:_0x90f1x20[_0xa645[40]]})}}}});function handleMessage(msg){var _0x90f1x24;var _0x90f1x25;var _0x90f1x26;var _0x90f1x27;var _0x90f1x28;var _0x90f1x29,_0x90f1x2a,_0x90f1x2b,_0x90f1x2c;if(msg[_0xa645[52]]){return Message[_0xa645[98]]({where:{messageId:msg[_0xa645[52]][0],accountId:msg[_0xa645[99]]}})[_0xa645[43]](function(_0x90f1x36){if(_0x90f1x36){return _0x90f1x36[_0xa645[104]]()[_0xa645[43]](function(_0x90f1x35){_0x90f1x24= _0x90f1x35;if(_0x90f1x35[_0xa645[91]]!== _0xa645[92]){return _0x90f1x24[_0xa645[48]]({status:_0xa645[101],openReason:_0xa645[102],waiting:true},{individualHooks:true})[_0xa645[43]](function(){return Account[_0xa645[100]](msg[_0xa645[99]])[_0xa645[43]](function(_0x90f1x38){_0x90f1x26= _0x90f1x38;if(_0x90f1x26[_0xa645[94]]){return Company[_0xa645[98]]({where:{emailDomain:msg[_0xa645[81]][0][_0xa645[82]][_0xa645[96]](_0xa645[95])[1]}})[_0xa645[43]](function(_0x90f1x39){return Contact[_0xa645[97]]({where:{email:msg[_0xa645[81]][0][_0xa645[82]]},defaults:{email:msg[_0xa645[81]][0][_0xa645[82]],firstName:msg[_0xa645[81]][0][_0xa645[89]]|| msg[_0xa645[81]][0][_0xa645[82]][_0xa645[96]](_0xa645[95])[0],ListId:_0x90f1x26[_0xa645[94]],CompanyId:_0x90f1x39?_0x90f1x39[_0xa645[73]]:null}})})}else {return []}})[_0xa645[93]](function(_0x90f1x37){_0x90f1x27= _0x90f1x37})})}else {return Account[_0xa645[100]](msg[_0xa645[99]])[_0xa645[43]](function(_0x90f1x38){_0x90f1x26= _0x90f1x38;if(_0x90f1x26[_0xa645[94]]){return Company[_0xa645[98]]({where:{emailDomain:msg[_0xa645[81]][0][_0xa645[82]][_0xa645[96]](_0xa645[95])[1]}})[_0xa645[43]](function(_0x90f1x39){return Contact[_0xa645[97]]({where:{email:msg[_0xa645[81]][0][_0xa645[82]]},defaults:{email:msg[_0xa645[81]][0][_0xa645[82]],firstName:msg[_0xa645[81]][0][_0xa645[89]]|| msg[_0xa645[81]][0][_0xa645[82]][_0xa645[96]](_0xa645[95])[0],ListId:_0x90f1x26[_0xa645[94]],CompanyId:_0x90f1x39?_0x90f1x39[_0xa645[73]]:null}})})}else {return []}})[_0xa645[93]](function(_0x90f1x37){_0x90f1x27= _0x90f1x37;return Room[_0xa645[74]]({subject:msg[_0xa645[80]],from:_[_0xa645[83]](msg[_0xa645[81]],_0xa645[82])[_0xa645[71]](_0xa645[103]),account:_0x90f1x26[_0xa645[89]],attachment:msg[_0xa645[55]]&& msg[_0xa645[55]][_0xa645[56]],lastEvent:_0xa645[79],lastEventAt:moment()[_0xa645[46]](_0xa645[45]),arrivedAt:moment()[_0xa645[46]](_0xa645[45]),waiting:true,MailAccountId:_0x90f1x26[_0xa645[73]],ParentId:_0x90f1x35[_0xa645[73]]})})[_0xa645[43]](function(_0x90f1x35){_0x90f1x24= _0x90f1x35})}})}else {return Account[_0xa645[100]](msg[_0xa645[99]])[_0xa645[43]](function(_0x90f1x38){_0x90f1x26= _0x90f1x38;if(_0x90f1x26[_0xa645[94]]){return Company[_0xa645[98]]({where:{emailDomain:msg[_0xa645[81]][0][_0xa645[82]][_0xa645[96]](_0xa645[95])[1]}})[_0xa645[43]](function(_0x90f1x39){return Contact[_0xa645[97]]({where:{email:msg[_0xa645[81]][0][_0xa645[82]]},defaults:{email:msg[_0xa645[81]][0][_0xa645[82]],firstName:msg[_0xa645[81]][0][_0xa645[89]]|| msg[_0xa645[81]][0][_0xa645[82]][_0xa645[96]](_0xa645[95])[0],ListId:_0x90f1x26[_0xa645[94]],CompanyId:_0x90f1x39?_0x90f1x39[_0xa645[73]]:null}})})}else {return []}})[_0xa645[93]](function(_0x90f1x37){_0x90f1x27= _0x90f1x37;return Room[_0xa645[74]]({subject:msg[_0xa645[80]],from:_[_0xa645[83]](msg[_0xa645[81]],_0xa645[82])[_0xa645[71]](_0xa645[103]),account:_0x90f1x26[_0xa645[89]],attachment:msg[_0xa645[55]]&& msg[_0xa645[55]][_0xa645[56]],lastEvent:_0xa645[79],waiting:true,lastEventAt:moment()[_0xa645[46]](_0xa645[45]),arrivedAt:moment()[_0xa645[46]](_0xa645[45]),MailAccountId:_0x90f1x26[_0xa645[73]]})})[_0xa645[43]](function(_0x90f1x35){_0x90f1x24= _0x90f1x35})}})[_0xa645[43]](function(){return _0x90f1x24[_0xa645[48]]({lastEvent:_0xa645[79],mailIn:++_0x90f1x24[_0xa645[90]]})})[_0xa645[43]](function(_0x90f1x35){return Message[_0xa645[74]]({fromId:_0x90f1x27?_0x90f1x27[_0xa645[73]]:null,messageId:msg[_0xa645[78]],status:_0xa645[79],subject:msg[_0xa645[80]],from:_[_0xa645[83]](msg[_0xa645[81]],_0xa645[82]),to:msg[_0xa645[84]]?_[_0xa645[83]](msg[_0xa645[84]],_0xa645[82]):[],cc:msg[_0xa645[85]]?_[_0xa645[83]](msg[_0xa645[85]],_0xa645[82]):[],bcc:msg[_0xa645[86]]?_[_0xa645[83]](msg[_0xa645[86]],_0xa645[82]):[],text:msg[_0xa645[87]]|| null,html:msg[_0xa645[88]]|| null,MailRoomId:_0x90f1x24[_0xa645[73]],accountName:_0x90f1x26[_0xa645[89]],accountId:_0x90f1x26[_0xa645[73]],inReplyTo:msg[_0xa645[52]][0]})})[_0xa645[43]](function(_0x90f1x2d){var _0x90f1x2e=[];var _0x90f1x2f=_0x90f1x2d;if(ami){ami[_0xa645[41]]({message:_0xa645[54],doc:_0x90f1x2d})};createAndStartRouting(_0x90f1x24,msg,_0x90f1x2d[_0xa645[31]]({plain:true}),_0x90f1x26);if(msg[_0xa645[55]]&& msg[_0xa645[55]][_0xa645[56]]){msg[_0xa645[55]][_0xa645[76]](function(_0x90f1x30){var _0x90f1x31=_0xa645[57]+ Math[_0xa645[58]](32);var _0x90f1x32;_0x90f1x2e[_0xa645[75]](Attachment[_0xa645[74]]({name:_0x90f1x30[_0xa645[61]],basename:_0x90f1x31,path:path[_0xa645[71]](config[_0xa645[67]],_0xa645[68],_0xa645[69],_0xa645[55],_0xa645[70],_0x90f1x31),type:_0x90f1x30[_0xa645[72]],size:_0x90f1x30[_0xa645[56]],MailMessageId:_0x90f1x2f[_0xa645[73]]})[_0xa645[43]](function(_0x90f1x34){return open(_0x90f1x34[_0xa645[3]],_0xa645[66])})[_0xa645[43]](function(_0x90f1x33){_0x90f1x32= _0x90f1x33;return write(_0x90f1x32, new Buffer(_0x90f1x30[_0xa645[65]][_0xa645[64]]),0,_0x90f1x30[_0xa645[56]])})[_0xa645[43]](function(){return close(_0x90f1x32)})[_0xa645[43]](function(){logger[_0xa645[63]](_0xa645[60],_0x90f1x30[_0xa645[61]],_0xa645[62])})[_0xa645[36]](function(_0x90f1x21){logger[_0xa645[35]](_0xa645[59],_0x90f1x21[_0xa645[53]])}))})};return Promise[_0xa645[77]](_0x90f1x2e)})[_0xa645[36]](function(_0x90f1x21){logger[_0xa645[35]](_0x90f1x21[_0xa645[53]])})}else {return Account[_0xa645[100]](msg[_0xa645[99]])[_0xa645[43]](function(_0x90f1x38){_0x90f1x26= _0x90f1x38;if(_0x90f1x26[_0xa645[94]]){return Company[_0xa645[98]]({where:{emailDomain:msg[_0xa645[81]][0][_0xa645[82]][_0xa645[96]](_0xa645[95])[1]}})[_0xa645[43]](function(_0x90f1x39){return Contact[_0xa645[97]]({where:{email:msg[_0xa645[81]][0][_0xa645[82]]},defaults:{email:msg[_0xa645[81]][0][_0xa645[82]],firstName:msg[_0xa645[81]][0][_0xa645[89]]|| msg[_0xa645[81]][0][_0xa645[82]][_0xa645[96]](_0xa645[95])[0],ListId:_0x90f1x26[_0xa645[94]],CompanyId:_0x90f1x39?_0x90f1x39[_0xa645[73]]:null}})})}else {return []}})[_0xa645[93]](function(_0x90f1x37){_0x90f1x27= _0x90f1x37;return Room[_0xa645[74]]({mailIn:1,account:_0x90f1x26[_0xa645[89]],subject:msg[_0xa645[80]],from:_[_0xa645[83]](msg[_0xa645[81]],_0xa645[82])[_0xa645[71]](_0xa645[103]),status:_0xa645[106],lastEvent:_0xa645[79],lastEventAt:moment()[_0xa645[46]](_0xa645[45]),arrivedAt:moment()[_0xa645[46]](_0xa645[45]),attachment:msg[_0xa645[55]]&& msg[_0xa645[55]][_0xa645[56]],waiting:true,MailMessages:[{messageId:msg[_0xa645[78]],subject:msg[_0xa645[80]],from:_[_0xa645[83]](msg[_0xa645[81]],_0xa645[82]),fromId:_0x90f1x27?_0x90f1x27[_0xa645[73]]:null,to:msg[_0xa645[84]]?_[_0xa645[83]](msg[_0xa645[84]],_0xa645[82]):[],cc:msg[_0xa645[85]]?_[_0xa645[83]](msg[_0xa645[85]],_0xa645[82]):[],bcc:msg[_0xa645[86]]?_[_0xa645[83]](msg[_0xa645[86]],_0xa645[82]):[],status:_0xa645[79],text:msg[_0xa645[87]]|| null,html:msg[_0xa645[88]]|| null,accountName:_0x90f1x26[_0xa645[89]],accountId:_0x90f1x26[_0xa645[73]]}],MailAccountId:msg[_0xa645[99]]},{include:[{model:Message}]})})[_0xa645[43]](function(_0x90f1x3a){var _0x90f1x2e=[];var _0x90f1x3b=_0x90f1x3a;ami[_0xa645[41]]({message:_0xa645[54],doc:_0x90f1x3a[_0xa645[105]][0]});createAndStartRouting(_0x90f1x3b,msg,_0x90f1x3b[_0xa645[105]][0][_0xa645[31]]({plain:true}),_0x90f1x26);if(msg[_0xa645[55]]&& msg[_0xa645[55]][_0xa645[56]]){msg[_0xa645[55]][_0xa645[76]](function(_0x90f1x30){var _0x90f1x31=_0xa645[57]+ Math[_0xa645[58]](32);var _0x90f1x32;_0x90f1x2e[_0xa645[75]](Attachment[_0xa645[74]]({name:_0x90f1x30[_0xa645[61]],basename:_0x90f1x31,path:path[_0xa645[71]](config[_0xa645[67]],_0xa645[68],_0xa645[69],_0xa645[55],_0xa645[70],_0x90f1x31),type:_0x90f1x30[_0xa645[72]],size:_0x90f1x30[_0xa645[56]],MailMessageId:_0x90f1x3b[_0xa645[105]][0][_0xa645[73]]})[_0xa645[43]](function(_0x90f1x34){return open(_0x90f1x34[_0xa645[3]],_0xa645[66])})[_0xa645[43]](function(_0x90f1x33){_0x90f1x32= _0x90f1x33;return write(_0x90f1x32, new Buffer(_0x90f1x30[_0xa645[65]][_0xa645[64]]),0,_0x90f1x30[_0xa645[56]])})[_0xa645[43]](function(){return close(_0x90f1x32)})[_0xa645[43]](function(){logger[_0xa645[63]](_0xa645[60],_0x90f1x30[_0xa645[61]],_0xa645[62])})[_0xa645[36]](function(_0x90f1x21){logger[_0xa645[35]](_0xa645[59],_0x90f1x21[_0xa645[53]])}))})};return Promise[_0xa645[77]](_0x90f1x2e)})[_0xa645[36]](function(_0x90f1x21){logger[_0xa645[35]](_0x90f1x21[_0xa645[53]])})}}function handleState(_0x90f1x3d,_0x90f1x20){return ms[_0xa645[100]](_0x90f1x3d)[_0xa645[43]](function(_0x90f1x3e){return _0x90f1x3e[_0xa645[48]]({state:_0x90f1x20[_0xa645[108]],source:_0x90f1x20[_0xa645[109]]|| null})})[_0xa645[36]](function(_0x90f1x21){logger[_0xa645[35]](_0xa645[107],_0x90f1x21[_0xa645[53]])})}function fork(_0x90f1x3d,_0x90f1x40){return cp[_0xa645[117]](__dirname+ _0xa645[116],[_0x90f1x3d,_0x90f1x40])[_0xa645[111]](_0xa645[113],function(_0x90f1x20){switch(_0x90f1x20[_0xa645[115]]){case _0xa645[114]:handleMessage(_0x90f1x20);break;case _0xa645[108]:handleState(_0x90f1x3d,_0x90f1x20);break;default:}})[_0xa645[111]](_0xa645[24],function(_0x90f1x41){logger[_0xa645[63]](util[_0xa645[46]](_0xa645[112],_0x90f1x40,_0x90f1x41))})[_0xa645[111]](_0xa645[35],function(_0x90f1x21){logger[_0xa645[35]](_0xa645[110],_0x90f1x21[_0xa645[53]])})}function execRequest(_0x90f1x1e,_0x90f1x43,_0x90f1x44){Util[_0xa645[121]](_0x90f1x1e,_0x90f1x43,_0x90f1x44)[_0xa645[43]](function(_0x90f1x45){logger[_0xa645[63]](_0xa645[120])})[_0xa645[36]](function(_0x90f1x21){logger[_0xa645[119]](_0xa645[118])})}function webhook(_0x90f1x1e,_0x90f1x47,_0x90f1x48){var _0x90f1x49=_0x90f1x47;switch(_0x90f1x48){case _0xa645[130]:if(_0x90f1x49[_0xa645[122]]&& _0x90f1x49[_0xa645[123]]){logger[_0xa645[63]](_0xa645[124]+ _0x90f1x49[_0xa645[89]]+ _0xa645[125]);execRequest(_0x90f1x1e[_0xa645[126]],_0x90f1x49[_0xa645[122]],_0x90f1x49[_0xa645[123]])};if(_0x90f1x49[_0xa645[127]][_0xa645[56]]){_[_0xa645[76]](_0x90f1x49[_0xa645[127]],function(_0x90f1x4a){if(_0x90f1x4a[_0xa645[128]]){Util[_0xa645[129]](_0x90f1x4a,_0x90f1x1e)}})};break;case _0xa645[50]:if(_0x90f1x49[_0xa645[131]]&& _0x90f1x49[_0xa645[132]]){logger[_0xa645[63]](_0xa645[124]+ _0x90f1x49[_0xa645[89]]+ _0xa645[133]);execRequest(_0x90f1x1e[_0xa645[126]],_0x90f1x49[_0xa645[131]],_0x90f1x49[_0xa645[132]])};break;case _0xa645[24]:if(_0x90f1x49[_0xa645[134]]&& _0x90f1x49[_0xa645[135]]){logger[_0xa645[63]](_0xa645[124]+ _0x90f1x49[_0xa645[89]]+ _0xa645[136]);execRequest(_0x90f1x1e[_0xa645[126]],_0x90f1x49[_0xa645[134]],_0x90f1x49[_0xa645[135]])};break;default:logger[_0xa645[35]](_0xa645[137])}}function synch(_0x90f1x4c,_0x90f1x4d){Account[_0xa645[142]](function(_0x90f1x1e){var _0x90f1x47=_[_0xa645[38]](_0x90f1x4c,{id:_0x90f1x1e[_0xa645[73]]});if(_0x90f1x47&& _0x90f1x47[_0xa645[8]]){if(_0x90f1x4d[_0x90f1x47[_0xa645[8]][_0xa645[73]]]){logger[_0xa645[63]](util[_0xa645[46]](_0xa645[138],_0x90f1x47[_0xa645[8]][_0xa645[73]],_0x90f1x4d[_0x90f1x47[_0xa645[8]][_0xa645[73]]][_0xa645[139]]));_0x90f1x4d[_0x90f1x47[_0xa645[8]][_0xa645[73]]][_0xa645[140]]();_0x90f1x4d[_0x90f1x47[_0xa645[8]][_0xa645[73]]]= null};_[_0xa645[141]](_0x90f1x4c,{id:_0x90f1x1e[_0xa645[73]]})}});Account[_0xa645[143]](function(_0x90f1x1e){_0x90f1x4c[_0xa645[75]](_0x90f1x1e)});Account[_0xa645[51]](function(_0x90f1x1e){var _0x90f1x4e=_[_0xa645[38]](_0x90f1x4c,{id:_0x90f1x1e[_0xa645[73]]});if(_0x90f1x4e){logger[_0xa645[63]](_0xa645[144]+ _0x90f1x4e[_0xa645[89]]+ _0xa645[145]);_[_0xa645[146]](_0x90f1x4e,_0x90f1x1e)}else {_0x90f1x4c[_0xa645[147]](_0x90f1x1e)}})}function createAndStartRouting(_0x90f1x3a,_0x90f1x50,_0x90f1x2d,_0x90f1x47){return queue[_0xa645[74]](_0xa645[150],{title:util[_0xa645[46]](_0xa645[151],_0x90f1x2d[_0xa645[81]]),room:_0x90f1x3a,message:_0x90f1x50,mailMessage:_0x90f1x2d,account:_0x90f1x47})[_0xa645[149]](true)[_0xa645[148]]()}function handleMail(_0x90f1x52,_0x90f1x53){var _0x90f1x50=_0x90f1x52[_0xa645[64]][_0xa645[113]];var _0x90f1x2d=_0x90f1x52[_0xa645[64]][_0xa645[152]];var _0x90f1x3a=_0x90f1x52[_0xa645[64]][_0xa645[153]];var _0x90f1x47=_0x90f1x52[_0xa645[64]][_0xa645[154]];var _0x90f1x54=_0x90f1x53;var _0x90f1x55=cp[_0xa645[117]](path[_0xa645[71]](config[_0xa645[67]],_0xa645[162]))[_0xa645[111]](_0xa645[113],function(msg){switch(msg[_0xa645[115]]){case _0xa645[159]:return Message[_0xa645[74]](msg[_0xa645[114]],{include:[{model:Attachment}]});case _0xa645[160]:return SmsMessage[_0xa645[74]](msg[_0xa645[114]]);case _0xa645[161]:ami[_0xa645[41]]({message:msg[_0xa645[115]],doc:msg[_0xa645[114]]});break;default:}})[_0xa645[111]](_0xa645[156],function(){var _0x90f1x56=_[_0xa645[141]](processes,{pid:this[_0xa645[139]]});if(_0x90f1x56&& _0x90f1x56[_0xa645[56]]){return Room[_0xa645[100]](_0x90f1x56[0][_0xa645[158]])[_0xa645[43]](function(_0x90f1x3a){if(_0x90f1x3a){return _0x90f1x3a[_0xa645[48]]({waiting:false})}})[_0xa645[157]](function(){_0x90f1x54()})}})[_0xa645[111]](_0xa645[24],function(){_0x90f1x54()})[_0xa645[111]](_0xa645[155],function(){_0x90f1x54()})[_0xa645[111]](_0xa645[35],function(_0x90f1x21){_0x90f1x54(_0x90f1x21)});_0x90f1x55[_0xa645[41]]({type:_0xa645[163],param1:{channel:_0xa645[26],uniqueid:util[_0xa645[46]](_0xa645[164],moment()[_0xa645[165]](),_0x90f1x3a[_0xa645[73]]),subject:_0x90f1x50[_0xa645[80]],messageid:_0x90f1x2d[_0xa645[73]],roomid:_0x90f1x3a[_0xa645[73]],accountid:_0x90f1x47[_0xa645[73]],accountname:_0x90f1x47[_0xa645[89]],accountaddress:_0x90f1x47[_0xa645[82]],from:_0x90f1x50[_0xa645[81]][0][_0xa645[82]],cc:_0x90f1x50[_0xa645[85]]?_[_0xa645[83]](_0x90f1x50[_0xa645[85]],_0xa645[82]):[]},param2:_0x90f1x2d});processes[_0xa645[75]]({id:_0x90f1x2d[_0xa645[73]],channel:_0xa645[26],process:_0x90f1x55,roomid:_0x90f1x3a[_0xa645[73]],pid:_0x90f1x55[_0xa645[139]]})}module[_0xa645[166]]= function(_0x90f1x57){var _0x90f1x4d={};var _0x90f1x4c;var _0x90f1x58;ami= _0x90f1x57;process[_0xa645[111]](_0xa645[156],function(_0x90f1x41){for(var _0x90f1x59 in _0x90f1x4d){if(_0x90f1x4d[_0x90f1x59]){_0x90f1x4d[_0x90f1x59][_0xa645[140]]()}}});Setting[_0xa645[38]]({where:{id:1},attributes:[_0xa645[73],_0xa645[170]],raw:true})[_0xa645[43]](function(_0x90f1x5b){if(_0x90f1x5b){queue[_0xa645[42]](_0xa645[150],_0x90f1x5b[_0xa645[170]],handleMail)};return Account[_0xa645[171]]({include:[ms]})})[_0xa645[43]](function(_0x90f1x5a){_0x90f1x4c= _0x90f1x5a;synch(_0x90f1x4c,_0x90f1x4d);_0x90f1x4c[_0xa645[76]](function(_0x90f1x47){if(_0x90f1x47[_0xa645[8]]){_0x90f1x4d[_0x90f1x47[_0xa645[8]][_0xa645[73]]]= fork(_0x90f1x47[_0xa645[8]][_0xa645[73]],_0x90f1x47[_0xa645[8]][_0xa645[167]])}});Report[_0xa645[51]](function(_0x90f1x1e){var _0x90f1x47=_[_0xa645[38]](_0x90f1x4c,{id:parseInt(_0x90f1x1e[_0xa645[168]])});if(_0x90f1x47&& _0x90f1x1e[_0xa645[33]](_0xa645[32])){webhook(_0x90f1x1e,_0x90f1x47,_0xa645[130])};if(_0x90f1x47&& _0x90f1x1e[_0xa645[33]](_0xa645[49])){webhook(_0x90f1x1e,_0x90f1x47,_0xa645[50])}});Room[_0xa645[51]](function(_0x90f1x1e){var _0x90f1x47=_[_0xa645[38]](_0x90f1x4c,{id:_0x90f1x1e[_0xa645[169]]});if(_0x90f1x47&& _0x90f1x1e[_0xa645[33]](_0xa645[91])&& _0x90f1x1e[_0xa645[91]]=== _0xa645[92]){webhook(_0x90f1x1e,_0x90f1x47,_0xa645[24])}})})[_0xa645[36]](function(_0x90f1x21){logger[_0xa645[35]](_0x90f1x21[_0xa645[53]])});ms[_0xa645[143]](function(_0x90f1x3e){var _0x90f1x47=_[_0xa645[38]](_0x90f1x4c,{id:_0x90f1x3e[_0xa645[169]]});if(_0x90f1x47){_0x90f1x47[_0xa645[8]]= _0x90f1x3e};_0x90f1x4d[_0x90f1x3e[_0xa645[73]]]= fork(_0x90f1x3e[_0xa645[73]],_0x90f1x3e[_0xa645[167]])});ms[_0xa645[51]](function(_0x90f1x3e){if(_0x90f1x4d[_0x90f1x3e[_0xa645[73]]]){if(_0x90f1x3e[_0xa645[33]](_0xa645[108])|| _0x90f1x3e[_0xa645[33]](_0xa645[109])){logger[_0xa645[63]](util[_0xa645[46]](_0xa645[172],_0x90f1x3e[_0xa645[73]],_0x90f1x4d[_0x90f1x3e[_0xa645[73]]][_0xa645[139]]))}else {_0x90f1x4d[_0x90f1x3e[_0xa645[73]]][_0xa645[140]]();_0x90f1x4d[_0x90f1x3e[_0xa645[73]]]= null;_0x90f1x4d[_0x90f1x3e[_0xa645[73]]]= fork(_0x90f1x3e[_0xa645[73]],_0x90f1x3e[_0xa645[167]])}}});ms[_0xa645[142]](function(_0x90f1x3e){if(_0x90f1x4d[_0x90f1x3e[_0xa645[73]]]){logger[_0xa645[63]](util[_0xa645[46]](_0xa645[138],_0x90f1x3e[_0xa645[73]],_0x90f1x4d[_0x90f1x3e[_0xa645[73]]][_0xa645[139]]));_0x90f1x4d[_0x90f1x3e[_0xa645[73]]][_0xa645[140]]();_0x90f1x4d[_0x90f1x3e[_0xa645[73]]]= null}})}