1 var _0x4a60=["\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"];_0x4a60[0];var _=require(_0x4a60[1]);var util=require(_0x4a60[2]);var path=require(_0x4a60[3]);var cp=require(_0x4a60[4]);var moment=require(_0x4a60[5]);var kue=require(_0x4a60[6]);var Promise=require(_0x4a60[7]);var ms=require(_0x4a60[9])[_0x4a60[8]];var msg=require(_0x4a60[9])[_0x4a60[10]];var Room=require(_0x4a60[9])[_0x4a60[11]];var Report=require(_0x4a60[9])[_0x4a60[12]];var Status=require(_0x4a60[9])[_0x4a60[13]];var Session=require(_0x4a60[9])[_0x4a60[14]];var Message=require(_0x4a60[9])[_0x4a60[10]];var SmsMessage=require(_0x4a60[9])[_0x4a60[15]];var Account=require(_0x4a60[9])[_0x4a60[16]];var Setting=require(_0x4a60[9])[_0x4a60[17]];var Contact=require(_0x4a60[9])[_0x4a60[18]];var Company=require(_0x4a60[9])[_0x4a60[19]];var Attachment=require(_0x4a60[9])[_0x4a60[20]];var open=Promise[_0x4a60[23]](require(_0x4a60[22])[_0x4a60[21]]);var close=Promise[_0x4a60[23]](require(_0x4a60[22])[_0x4a60[24]]);var write=Promise[_0x4a60[23]](require(_0x4a60[22])[_0x4a60[25]]);var logger=require(_0x4a60[27])(_0x4a60[26]);var config=require(_0x4a60[28]);var Util=require(_0x4a60[29]);var queue=kue[_0x4a60[30]]();var processes=[];var ami;Report[_0x4a60[51]](function(_0xd3afx1e,_0xd3afx1f){var _0xd3afx20=_0xd3afx1e[_0x4a60[31]]({plain:true});if(_0xd3afx1e[_0x4a60[33]](_0x4a60[32])){return Session[_0x4a60[48]]({memberid:_0xd3afx20[_0x4a60[44]],membername:_0xd3afx20[_0x4a60[40]],leaveAt:moment()[_0x4a60[46]](_0x4a60[45])},{where:{uniqueid:_0xd3afx20[_0x4a60[47]],leaveAt:null},individualHooks:true})[_0x4a60[43]](function(){var _0xd3afx22=_[_0x4a60[38]](processes,{id:_0xd3afx20[_0x4a60[37]],channel:_0x4a60[26]});if(_0xd3afx22){_0xd3afx22[_0x4a60[42]][_0x4a60[41]]({type:_0x4a60[39],membername:_0xd3afx20[_0x4a60[40]]})}})[_0x4a60[36]](function(_0xd3afx21){logger[_0x4a60[35]](_0x4a60[34],_0xd3afx21)})}else {if(_0xd3afx1e[_0x4a60[33]](_0x4a60[49])){var _0xd3afx22=_[_0x4a60[38]](processes,{id:_0xd3afx20[_0x4a60[37]],channel:_0x4a60[26]});if(_0xd3afx22){_0xd3afx22[_0x4a60[42]][_0x4a60[41]]({type:_0x4a60[50],id:_0xd3afx20[_0x4a60[44]],membername:_0xd3afx20[_0x4a60[40]]})}}}});function handleMessage(msg){var _0xd3afx24;var _0xd3afx25;var _0xd3afx26;var _0xd3afx27;var _0xd3afx28;var _0xd3afx29,_0xd3afx2a,_0xd3afx2b,_0xd3afx2c;if(msg[_0x4a60[52]]){return Message[_0x4a60[98]]({where:{messageId:msg[_0x4a60[52]][0],accountId:msg[_0x4a60[99]]}})[_0x4a60[43]](function(_0xd3afx36){if(_0xd3afx36){return _0xd3afx36[_0x4a60[104]]()[_0x4a60[43]](function(_0xd3afx35){_0xd3afx24= _0xd3afx35;if(_0xd3afx35[_0x4a60[91]]!== _0x4a60[92]){return _0xd3afx24[_0x4a60[48]]({status:_0x4a60[101],openReason:_0x4a60[102],waiting:true},{individualHooks:true})[_0x4a60[43]](function(){return Account[_0x4a60[100]](msg[_0x4a60[99]])[_0x4a60[43]](function(_0xd3afx38){_0xd3afx26= _0xd3afx38;if(_0xd3afx26[_0x4a60[94]]){return Company[_0x4a60[98]]({where:{emailDomain:msg[_0x4a60[81]][0][_0x4a60[82]][_0x4a60[96]](_0x4a60[95])[1]}})[_0x4a60[43]](function(_0xd3afx39){return Contact[_0x4a60[97]]({where:{email:msg[_0x4a60[81]][0][_0x4a60[82]]},defaults:{email:msg[_0x4a60[81]][0][_0x4a60[82]],firstName:msg[_0x4a60[81]][0][_0x4a60[89]]|| msg[_0x4a60[81]][0][_0x4a60[82]][_0x4a60[96]](_0x4a60[95])[0],ListId:_0xd3afx26[_0x4a60[94]],CompanyId:_0xd3afx39?_0xd3afx39[_0x4a60[73]]:null}})})}else {return []}})[_0x4a60[93]](function(_0xd3afx37){_0xd3afx27= _0xd3afx37})})}else {return Account[_0x4a60[100]](msg[_0x4a60[99]])[_0x4a60[43]](function(_0xd3afx38){_0xd3afx26= _0xd3afx38;if(_0xd3afx26[_0x4a60[94]]){return Company[_0x4a60[98]]({where:{emailDomain:msg[_0x4a60[81]][0][_0x4a60[82]][_0x4a60[96]](_0x4a60[95])[1]}})[_0x4a60[43]](function(_0xd3afx39){return Contact[_0x4a60[97]]({where:{email:msg[_0x4a60[81]][0][_0x4a60[82]]},defaults:{email:msg[_0x4a60[81]][0][_0x4a60[82]],firstName:msg[_0x4a60[81]][0][_0x4a60[89]]|| msg[_0x4a60[81]][0][_0x4a60[82]][_0x4a60[96]](_0x4a60[95])[0],ListId:_0xd3afx26[_0x4a60[94]],CompanyId:_0xd3afx39?_0xd3afx39[_0x4a60[73]]:null}})})}else {return []}})[_0x4a60[93]](function(_0xd3afx37){_0xd3afx27= _0xd3afx37;return Room[_0x4a60[74]]({subject:msg[_0x4a60[80]],from:_[_0x4a60[83]](msg[_0x4a60[81]],_0x4a60[82])[_0x4a60[71]](_0x4a60[103]),account:_0xd3afx26[_0x4a60[89]],attachment:msg[_0x4a60[55]]&& msg[_0x4a60[55]][_0x4a60[56]],lastEvent:_0x4a60[79],lastEventAt:moment()[_0x4a60[46]](_0x4a60[45]),arrivedAt:moment()[_0x4a60[46]](_0x4a60[45]),waiting:true,MailAccountId:_0xd3afx26[_0x4a60[73]],ParentId:_0xd3afx35[_0x4a60[73]]})})[_0x4a60[43]](function(_0xd3afx35){_0xd3afx24= _0xd3afx35})}})}else {return Account[_0x4a60[100]](msg[_0x4a60[99]])[_0x4a60[43]](function(_0xd3afx38){_0xd3afx26= _0xd3afx38;if(_0xd3afx26[_0x4a60[94]]){return Company[_0x4a60[98]]({where:{emailDomain:msg[_0x4a60[81]][0][_0x4a60[82]][_0x4a60[96]](_0x4a60[95])[1]}})[_0x4a60[43]](function(_0xd3afx39){return Contact[_0x4a60[97]]({where:{email:msg[_0x4a60[81]][0][_0x4a60[82]]},defaults:{email:msg[_0x4a60[81]][0][_0x4a60[82]],firstName:msg[_0x4a60[81]][0][_0x4a60[89]]|| msg[_0x4a60[81]][0][_0x4a60[82]][_0x4a60[96]](_0x4a60[95])[0],ListId:_0xd3afx26[_0x4a60[94]],CompanyId:_0xd3afx39?_0xd3afx39[_0x4a60[73]]:null}})})}else {return []}})[_0x4a60[93]](function(_0xd3afx37){_0xd3afx27= _0xd3afx37;return Room[_0x4a60[74]]({subject:msg[_0x4a60[80]],from:_[_0x4a60[83]](msg[_0x4a60[81]],_0x4a60[82])[_0x4a60[71]](_0x4a60[103]),account:_0xd3afx26[_0x4a60[89]],attachment:msg[_0x4a60[55]]&& msg[_0x4a60[55]][_0x4a60[56]],lastEvent:_0x4a60[79],waiting:true,lastEventAt:moment()[_0x4a60[46]](_0x4a60[45]),arrivedAt:moment()[_0x4a60[46]](_0x4a60[45]),MailAccountId:_0xd3afx26[_0x4a60[73]]})})[_0x4a60[43]](function(_0xd3afx35){_0xd3afx24= _0xd3afx35})}})[_0x4a60[43]](function(){return _0xd3afx24[_0x4a60[48]]({lastEvent:_0x4a60[79],mailIn:++_0xd3afx24[_0x4a60[90]]})})[_0x4a60[43]](function(_0xd3afx35){return Message[_0x4a60[74]]({fromId:_0xd3afx27?_0xd3afx27[_0x4a60[73]]:null,messageId:msg[_0x4a60[78]],status:_0x4a60[79],subject:msg[_0x4a60[80]],from:_[_0x4a60[83]](msg[_0x4a60[81]],_0x4a60[82]),to:msg[_0x4a60[84]]?_[_0x4a60[83]](msg[_0x4a60[84]],_0x4a60[82]):[],cc:msg[_0x4a60[85]]?_[_0x4a60[83]](msg[_0x4a60[85]],_0x4a60[82]):[],bcc:msg[_0x4a60[86]]?_[_0x4a60[83]](msg[_0x4a60[86]],_0x4a60[82]):[],text:msg[_0x4a60[87]]|| null,html:msg[_0x4a60[88]]|| null,MailRoomId:_0xd3afx24[_0x4a60[73]],accountName:_0xd3afx26[_0x4a60[89]],accountId:_0xd3afx26[_0x4a60[73]],inReplyTo:msg[_0x4a60[52]][0]})})[_0x4a60[43]](function(_0xd3afx2d){var _0xd3afx2e=[];var _0xd3afx2f=_0xd3afx2d;if(ami){ami[_0x4a60[41]]({message:_0x4a60[54],doc:_0xd3afx2d})};createAndStartRouting(_0xd3afx24,msg,_0xd3afx2d[_0x4a60[31]]({plain:true}),_0xd3afx26);if(msg[_0x4a60[55]]&& msg[_0x4a60[55]][_0x4a60[56]]){msg[_0x4a60[55]][_0x4a60[76]](function(_0xd3afx30){var _0xd3afx31=_0x4a60[57]+ Math[_0x4a60[58]](32);var _0xd3afx32;_0xd3afx2e[_0x4a60[75]](Attachment[_0x4a60[74]]({name:_0xd3afx30[_0x4a60[61]],basename:_0xd3afx31,path:path[_0x4a60[71]](config[_0x4a60[67]],_0x4a60[68],_0x4a60[69],_0x4a60[55],_0x4a60[70],_0xd3afx31),type:_0xd3afx30[_0x4a60[72]],size:_0xd3afx30[_0x4a60[56]],MailMessageId:_0xd3afx2f[_0x4a60[73]]})[_0x4a60[43]](function(_0xd3afx34){return open(_0xd3afx34[_0x4a60[3]],_0x4a60[66])})[_0x4a60[43]](function(_0xd3afx33){_0xd3afx32= _0xd3afx33;return write(_0xd3afx32, new Buffer(_0xd3afx30[_0x4a60[65]][_0x4a60[64]]),0,_0xd3afx30[_0x4a60[56]])})[_0x4a60[43]](function(){return close(_0xd3afx32)})[_0x4a60[43]](function(){logger[_0x4a60[63]](_0x4a60[60],_0xd3afx30[_0x4a60[61]],_0x4a60[62])})[_0x4a60[36]](function(_0xd3afx21){logger[_0x4a60[35]](_0x4a60[59],_0xd3afx21[_0x4a60[53]])}))})};return Promise[_0x4a60[77]](_0xd3afx2e)})[_0x4a60[36]](function(_0xd3afx21){logger[_0x4a60[35]](_0xd3afx21[_0x4a60[53]])})}else {return Account[_0x4a60[100]](msg[_0x4a60[99]])[_0x4a60[43]](function(_0xd3afx38){_0xd3afx26= _0xd3afx38;if(_0xd3afx26[_0x4a60[94]]){return Company[_0x4a60[98]]({where:{emailDomain:msg[_0x4a60[81]][0][_0x4a60[82]][_0x4a60[96]](_0x4a60[95])[1]}})[_0x4a60[43]](function(_0xd3afx39){return Contact[_0x4a60[97]]({where:{email:msg[_0x4a60[81]][0][_0x4a60[82]]},defaults:{email:msg[_0x4a60[81]][0][_0x4a60[82]],firstName:msg[_0x4a60[81]][0][_0x4a60[89]]|| msg[_0x4a60[81]][0][_0x4a60[82]][_0x4a60[96]](_0x4a60[95])[0],ListId:_0xd3afx26[_0x4a60[94]],CompanyId:_0xd3afx39?_0xd3afx39[_0x4a60[73]]:null}})})}else {return []}})[_0x4a60[93]](function(_0xd3afx37){_0xd3afx27= _0xd3afx37;return Room[_0x4a60[74]]({mailIn:1,account:_0xd3afx26[_0x4a60[89]],subject:msg[_0x4a60[80]],from:_[_0x4a60[83]](msg[_0x4a60[81]],_0x4a60[82])[_0x4a60[71]](_0x4a60[103]),status:_0x4a60[106],lastEvent:_0x4a60[79],lastEventAt:moment()[_0x4a60[46]](_0x4a60[45]),arrivedAt:moment()[_0x4a60[46]](_0x4a60[45]),attachment:msg[_0x4a60[55]]&& msg[_0x4a60[55]][_0x4a60[56]],waiting:true,MailMessages:[{messageId:msg[_0x4a60[78]],subject:msg[_0x4a60[80]],from:_[_0x4a60[83]](msg[_0x4a60[81]],_0x4a60[82]),fromId:_0xd3afx27?_0xd3afx27[_0x4a60[73]]:null,to:msg[_0x4a60[84]]?_[_0x4a60[83]](msg[_0x4a60[84]],_0x4a60[82]):[],cc:msg[_0x4a60[85]]?_[_0x4a60[83]](msg[_0x4a60[85]],_0x4a60[82]):[],bcc:msg[_0x4a60[86]]?_[_0x4a60[83]](msg[_0x4a60[86]],_0x4a60[82]):[],status:_0x4a60[79],text:msg[_0x4a60[87]]|| null,html:msg[_0x4a60[88]]|| null,accountName:_0xd3afx26[_0x4a60[89]],accountId:_0xd3afx26[_0x4a60[73]]}],MailAccountId:msg[_0x4a60[99]]},{include:[{model:Message}]})})[_0x4a60[43]](function(_0xd3afx3a){var _0xd3afx2e=[];var _0xd3afx3b=_0xd3afx3a;ami[_0x4a60[41]]({message:_0x4a60[54],doc:_0xd3afx3a[_0x4a60[105]][0]});createAndStartRouting(_0xd3afx3b,msg,_0xd3afx3b[_0x4a60[105]][0][_0x4a60[31]]({plain:true}),_0xd3afx26);if(msg[_0x4a60[55]]&& msg[_0x4a60[55]][_0x4a60[56]]){msg[_0x4a60[55]][_0x4a60[76]](function(_0xd3afx30){var _0xd3afx31=_0x4a60[57]+ Math[_0x4a60[58]](32);var _0xd3afx32;_0xd3afx2e[_0x4a60[75]](Attachment[_0x4a60[74]]({name:_0xd3afx30[_0x4a60[61]],basename:_0xd3afx31,path:path[_0x4a60[71]](config[_0x4a60[67]],_0x4a60[68],_0x4a60[69],_0x4a60[55],_0x4a60[70],_0xd3afx31),type:_0xd3afx30[_0x4a60[72]],size:_0xd3afx30[_0x4a60[56]],MailMessageId:_0xd3afx3b[_0x4a60[105]][0][_0x4a60[73]]})[_0x4a60[43]](function(_0xd3afx34){return open(_0xd3afx34[_0x4a60[3]],_0x4a60[66])})[_0x4a60[43]](function(_0xd3afx33){_0xd3afx32= _0xd3afx33;return write(_0xd3afx32, new Buffer(_0xd3afx30[_0x4a60[65]][_0x4a60[64]]),0,_0xd3afx30[_0x4a60[56]])})[_0x4a60[43]](function(){return close(_0xd3afx32)})[_0x4a60[43]](function(){logger[_0x4a60[63]](_0x4a60[60],_0xd3afx30[_0x4a60[61]],_0x4a60[62])})[_0x4a60[36]](function(_0xd3afx21){logger[_0x4a60[35]](_0x4a60[59],_0xd3afx21[_0x4a60[53]])}))})};return Promise[_0x4a60[77]](_0xd3afx2e)})[_0x4a60[36]](function(_0xd3afx21){logger[_0x4a60[35]](_0xd3afx21[_0x4a60[53]])})}}function handleState(_0xd3afx3d,_0xd3afx20){return ms[_0x4a60[100]](_0xd3afx3d)[_0x4a60[43]](function(_0xd3afx3e){return _0xd3afx3e[_0x4a60[48]]({state:_0xd3afx20[_0x4a60[108]],source:_0xd3afx20[_0x4a60[109]]|| null})})[_0x4a60[36]](function(_0xd3afx21){logger[_0x4a60[35]](_0x4a60[107],_0xd3afx21[_0x4a60[53]])})}function fork(_0xd3afx3d,_0xd3afx40){return cp[_0x4a60[117]](__dirname+ _0x4a60[116],[_0xd3afx3d,_0xd3afx40])[_0x4a60[111]](_0x4a60[113],function(_0xd3afx20){switch(_0xd3afx20[_0x4a60[115]]){case _0x4a60[114]:handleMessage(_0xd3afx20);break;case _0x4a60[108]:handleState(_0xd3afx3d,_0xd3afx20);break;default:}})[_0x4a60[111]](_0x4a60[24],function(_0xd3afx41){logger[_0x4a60[63]](util[_0x4a60[46]](_0x4a60[112],_0xd3afx40,_0xd3afx41))})[_0x4a60[111]](_0x4a60[35],function(_0xd3afx21){logger[_0x4a60[35]](_0x4a60[110],_0xd3afx21[_0x4a60[53]])})}function execRequest(_0xd3afx1e,_0xd3afx43,_0xd3afx44){Util[_0x4a60[121]](_0xd3afx1e,_0xd3afx43,_0xd3afx44)[_0x4a60[43]](function(_0xd3afx45){logger[_0x4a60[63]](_0x4a60[120])})[_0x4a60[36]](function(_0xd3afx21){logger[_0x4a60[119]](_0x4a60[118])})}function webhook(_0xd3afx1e,_0xd3afx47,_0xd3afx48){var _0xd3afx49=_0xd3afx47;switch(_0xd3afx48){case _0x4a60[130]:if(_0xd3afx49[_0x4a60[122]]&& _0xd3afx49[_0x4a60[123]]){logger[_0x4a60[63]](_0x4a60[124]+ _0xd3afx49[_0x4a60[89]]+ _0x4a60[125]);execRequest(_0xd3afx1e[_0x4a60[126]],_0xd3afx49[_0x4a60[122]],_0xd3afx49[_0x4a60[123]])};if(_0xd3afx49[_0x4a60[127]][_0x4a60[56]]){_[_0x4a60[76]](_0xd3afx49[_0x4a60[127]],function(_0xd3afx4a){if(_0xd3afx4a[_0x4a60[128]]){Util[_0x4a60[129]](_0xd3afx4a,_0xd3afx1e)}})};break;case _0x4a60[50]:if(_0xd3afx49[_0x4a60[131]]&& _0xd3afx49[_0x4a60[132]]){logger[_0x4a60[63]](_0x4a60[124]+ _0xd3afx49[_0x4a60[89]]+ _0x4a60[133]);execRequest(_0xd3afx1e[_0x4a60[126]],_0xd3afx49[_0x4a60[131]],_0xd3afx49[_0x4a60[132]])};break;case _0x4a60[24]:if(_0xd3afx49[_0x4a60[134]]&& _0xd3afx49[_0x4a60[135]]){logger[_0x4a60[63]](_0x4a60[124]+ _0xd3afx49[_0x4a60[89]]+ _0x4a60[136]);execRequest(_0xd3afx1e[_0x4a60[126]],_0xd3afx49[_0x4a60[134]],_0xd3afx49[_0x4a60[135]])};break;default:logger[_0x4a60[35]](_0x4a60[137])}}function synch(_0xd3afx4c,_0xd3afx4d){Account[_0x4a60[142]](function(_0xd3afx1e){var _0xd3afx47=_[_0x4a60[38]](_0xd3afx4c,{id:_0xd3afx1e[_0x4a60[73]]});if(_0xd3afx47&& _0xd3afx47[_0x4a60[8]]){if(_0xd3afx4d[_0xd3afx47[_0x4a60[8]][_0x4a60[73]]]){logger[_0x4a60[63]](util[_0x4a60[46]](_0x4a60[138],_0xd3afx47[_0x4a60[8]][_0x4a60[73]],_0xd3afx4d[_0xd3afx47[_0x4a60[8]][_0x4a60[73]]][_0x4a60[139]]));_0xd3afx4d[_0xd3afx47[_0x4a60[8]][_0x4a60[73]]][_0x4a60[140]]();_0xd3afx4d[_0xd3afx47[_0x4a60[8]][_0x4a60[73]]]= null};_[_0x4a60[141]](_0xd3afx4c,{id:_0xd3afx1e[_0x4a60[73]]})}});Account[_0x4a60[143]](function(_0xd3afx1e){_0xd3afx4c[_0x4a60[75]](_0xd3afx1e)});Account[_0x4a60[51]](function(_0xd3afx1e){var _0xd3afx4e=_[_0x4a60[38]](_0xd3afx4c,{id:_0xd3afx1e[_0x4a60[73]]});if(_0xd3afx4e){logger[_0x4a60[63]](_0x4a60[144]+ _0xd3afx4e[_0x4a60[89]]+ _0x4a60[145]);_[_0x4a60[146]](_0xd3afx4e,_0xd3afx1e)}else {_0xd3afx4c[_0x4a60[147]](_0xd3afx1e)}})}function createAndStartRouting(_0xd3afx3a,_0xd3afx50,_0xd3afx2d,_0xd3afx47){return queue[_0x4a60[74]](_0x4a60[150],{title:util[_0x4a60[46]](_0x4a60[151],_0xd3afx2d[_0x4a60[81]]),room:_0xd3afx3a,message:_0xd3afx50,mailMessage:_0xd3afx2d,account:_0xd3afx47})[_0x4a60[149]](true)[_0x4a60[148]]()}function handleMail(_0xd3afx52,_0xd3afx53){var _0xd3afx50=_0xd3afx52[_0x4a60[64]][_0x4a60[113]];var _0xd3afx2d=_0xd3afx52[_0x4a60[64]][_0x4a60[152]];var _0xd3afx3a=_0xd3afx52[_0x4a60[64]][_0x4a60[153]];var _0xd3afx47=_0xd3afx52[_0x4a60[64]][_0x4a60[154]];var _0xd3afx54=_0xd3afx53;var _0xd3afx55=cp[_0x4a60[117]](path[_0x4a60[71]](config[_0x4a60[67]],_0x4a60[162]))[_0x4a60[111]](_0x4a60[113],function(msg){switch(msg[_0x4a60[115]]){case _0x4a60[159]:return Message[_0x4a60[74]](msg[_0x4a60[114]],{include:[{model:Attachment}]});case _0x4a60[160]:return SmsMessage[_0x4a60[74]](msg[_0x4a60[114]]);case _0x4a60[161]:ami[_0x4a60[41]]({message:msg[_0x4a60[115]],doc:msg[_0x4a60[114]]});break;default:}})[_0x4a60[111]](_0x4a60[156],function(){var _0xd3afx56=_[_0x4a60[141]](processes,{pid:this[_0x4a60[139]]});if(_0xd3afx56&& _0xd3afx56[_0x4a60[56]]){return Room[_0x4a60[100]](_0xd3afx56[0][_0x4a60[158]])[_0x4a60[43]](function(_0xd3afx3a){if(_0xd3afx3a){return _0xd3afx3a[_0x4a60[48]]({waiting:false})}})[_0x4a60[157]](function(){_0xd3afx54()})}})[_0x4a60[111]](_0x4a60[24],function(){_0xd3afx54()})[_0x4a60[111]](_0x4a60[155],function(){_0xd3afx54()})[_0x4a60[111]](_0x4a60[35],function(_0xd3afx21){_0xd3afx54(_0xd3afx21)});_0xd3afx55[_0x4a60[41]]({type:_0x4a60[163],param1:{channel:_0x4a60[26],uniqueid:util[_0x4a60[46]](_0x4a60[164],moment()[_0x4a60[165]](),_0xd3afx3a[_0x4a60[73]]),subject:_0xd3afx50[_0x4a60[80]],messageid:_0xd3afx2d[_0x4a60[73]],roomid:_0xd3afx3a[_0x4a60[73]],accountid:_0xd3afx47[_0x4a60[73]],accountname:_0xd3afx47[_0x4a60[89]],accountaddress:_0xd3afx47[_0x4a60[82]],from:_0xd3afx50[_0x4a60[81]][0][_0x4a60[82]],cc:_0xd3afx50[_0x4a60[85]]?_[_0x4a60[83]](_0xd3afx50[_0x4a60[85]],_0x4a60[82]):[]},param2:_0xd3afx2d});processes[_0x4a60[75]]({id:_0xd3afx2d[_0x4a60[73]],channel:_0x4a60[26],process:_0xd3afx55,roomid:_0xd3afx3a[_0x4a60[73]],pid:_0xd3afx55[_0x4a60[139]]})}module[_0x4a60[166]]= function(_0xd3afx57){var _0xd3afx4d={};var _0xd3afx4c;var _0xd3afx58;ami= _0xd3afx57;process[_0x4a60[111]](_0x4a60[156],function(_0xd3afx41){for(var _0xd3afx59 in _0xd3afx4d){if(_0xd3afx4d[_0xd3afx59]){_0xd3afx4d[_0xd3afx59][_0x4a60[140]]()}}});Setting[_0x4a60[38]]({where:{id:1},attributes:[_0x4a60[73],_0x4a60[170]],raw:true})[_0x4a60[43]](function(_0xd3afx5b){if(_0xd3afx5b){queue[_0x4a60[42]](_0x4a60[150],_0xd3afx5b[_0x4a60[170]],handleMail)};return Account[_0x4a60[171]]({include:[ms]})})[_0x4a60[43]](function(_0xd3afx5a){_0xd3afx4c= _0xd3afx5a;synch(_0xd3afx4c,_0xd3afx4d);_0xd3afx4c[_0x4a60[76]](function(_0xd3afx47){if(_0xd3afx47[_0x4a60[8]]){_0xd3afx4d[_0xd3afx47[_0x4a60[8]][_0x4a60[73]]]= fork(_0xd3afx47[_0x4a60[8]][_0x4a60[73]],_0xd3afx47[_0x4a60[8]][_0x4a60[167]])}});Report[_0x4a60[51]](function(_0xd3afx1e){var _0xd3afx47=_[_0x4a60[38]](_0xd3afx4c,{id:parseInt(_0xd3afx1e[_0x4a60[168]])});if(_0xd3afx47&& _0xd3afx1e[_0x4a60[33]](_0x4a60[32])){webhook(_0xd3afx1e,_0xd3afx47,_0x4a60[130])};if(_0xd3afx47&& _0xd3afx1e[_0x4a60[33]](_0x4a60[49])){webhook(_0xd3afx1e,_0xd3afx47,_0x4a60[50])}});Room[_0x4a60[51]](function(_0xd3afx1e){var _0xd3afx47=_[_0x4a60[38]](_0xd3afx4c,{id:_0xd3afx1e[_0x4a60[169]]});if(_0xd3afx47&& _0xd3afx1e[_0x4a60[33]](_0x4a60[91])&& _0xd3afx1e[_0x4a60[91]]=== _0x4a60[92]){webhook(_0xd3afx1e,_0xd3afx47,_0x4a60[24])}})})[_0x4a60[36]](function(_0xd3afx21){logger[_0x4a60[35]](_0xd3afx21[_0x4a60[53]])});ms[_0x4a60[143]](function(_0xd3afx3e){var _0xd3afx47=_[_0x4a60[38]](_0xd3afx4c,{id:_0xd3afx3e[_0x4a60[169]]});if(_0xd3afx47){_0xd3afx47[_0x4a60[8]]= _0xd3afx3e};_0xd3afx4d[_0xd3afx3e[_0x4a60[73]]]= fork(_0xd3afx3e[_0x4a60[73]],_0xd3afx3e[_0x4a60[167]])});ms[_0x4a60[51]](function(_0xd3afx3e){if(_0xd3afx4d[_0xd3afx3e[_0x4a60[73]]]){if(_0xd3afx3e[_0x4a60[33]](_0x4a60[108])|| _0xd3afx3e[_0x4a60[33]](_0x4a60[109])){logger[_0x4a60[63]](util[_0x4a60[46]](_0x4a60[172],_0xd3afx3e[_0x4a60[73]],_0xd3afx4d[_0xd3afx3e[_0x4a60[73]]][_0x4a60[139]]))}else {_0xd3afx4d[_0xd3afx3e[_0x4a60[73]]][_0x4a60[140]]();_0xd3afx4d[_0xd3afx3e[_0x4a60[73]]]= null;_0xd3afx4d[_0xd3afx3e[_0x4a60[73]]]= fork(_0xd3afx3e[_0x4a60[73]],_0xd3afx3e[_0x4a60[167]])}}});ms[_0x4a60[142]](function(_0xd3afx3e){if(_0xd3afx4d[_0xd3afx3e[_0x4a60[73]]]){logger[_0x4a60[63]](util[_0x4a60[46]](_0x4a60[138],_0xd3afx3e[_0x4a60[73]],_0xd3afx4d[_0xd3afx3e[_0x4a60[73]]][_0x4a60[139]]));_0xd3afx4d[_0xd3afx3e[_0x4a60[73]]][_0x4a60[140]]();_0xd3afx4d[_0xd3afx3e[_0x4a60[73]]]= null}})}