1 var _0x348b=["\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\x79\x73\x74\x65\x6D","\x4E\x45\x57","\x4F\x50\x45\x4E","\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","\x3B","\x67\x65\x74\x4D\x61\x69\x6C\x52\x6F\x6F\x6D","\x4D\x61\x69\x6C\x4D\x65\x73\x73\x61\x67\x65\x73","\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"];_0x348b[0];var _=require(_0x348b[1]);var util=require(_0x348b[2]);var path=require(_0x348b[3]);var cp=require(_0x348b[4]);var moment=require(_0x348b[5]);var kue=require(_0x348b[6]);var Promise=require(_0x348b[7]);var ms=require(_0x348b[9])[_0x348b[8]];var msg=require(_0x348b[9])[_0x348b[10]];var Room=require(_0x348b[9])[_0x348b[11]];var Report=require(_0x348b[9])[_0x348b[12]];var Status=require(_0x348b[9])[_0x348b[13]];var Session=require(_0x348b[9])[_0x348b[14]];var Message=require(_0x348b[9])[_0x348b[10]];var SmsMessage=require(_0x348b[9])[_0x348b[15]];var Account=require(_0x348b[9])[_0x348b[16]];var Setting=require(_0x348b[9])[_0x348b[17]];var Contact=require(_0x348b[9])[_0x348b[18]];var Company=require(_0x348b[9])[_0x348b[19]];var Attachment=require(_0x348b[9])[_0x348b[20]];var open=Promise[_0x348b[23]](require(_0x348b[22])[_0x348b[21]]);var close=Promise[_0x348b[23]](require(_0x348b[22])[_0x348b[24]]);var write=Promise[_0x348b[23]](require(_0x348b[22])[_0x348b[25]]);var logger=require(_0x348b[27])(_0x348b[26]);var config=require(_0x348b[28]);var Util=require(_0x348b[29]);var queue=kue[_0x348b[30]]();var processes=[];var ami;Report[_0x348b[51]](function(_0xd328x1e,_0xd328x1f){var _0xd328x20=_0xd328x1e[_0x348b[31]]({plain:true});if(_0xd328x1e[_0x348b[33]](_0x348b[32])){return Session[_0x348b[48]]({memberid:_0xd328x20[_0x348b[44]],membername:_0xd328x20[_0x348b[40]],leaveAt:moment()[_0x348b[46]](_0x348b[45])},{where:{uniqueid:_0xd328x20[_0x348b[47]],leaveAt:null},individualHooks:true})[_0x348b[43]](function(){var _0xd328x22=_[_0x348b[38]](processes,{id:_0xd328x20[_0x348b[37]],channel:_0x348b[26]});if(_0xd328x22){_0xd328x22[_0x348b[42]][_0x348b[41]]({type:_0x348b[39],membername:_0xd328x20[_0x348b[40]]})}})[_0x348b[36]](function(_0xd328x21){logger[_0x348b[35]](_0x348b[34],_0xd328x21)})}else {if(_0xd328x1e[_0x348b[33]](_0x348b[49])){var _0xd328x22=_[_0x348b[38]](processes,{id:_0xd328x20[_0x348b[37]],channel:_0x348b[26]});if(_0xd328x22){_0xd328x22[_0x348b[42]][_0x348b[41]]({type:_0x348b[50],id:_0xd328x20[_0x348b[44]],membername:_0xd328x20[_0x348b[40]]})}}}});function handleMessage(msg){var _0xd328x24;var _0xd328x25;var _0xd328x26;var _0xd328x27;var _0xd328x28;var _0xd328x29,_0xd328x2a,_0xd328x2b,_0xd328x2c;if(msg[_0x348b[52]]){return Message[_0x348b[101]]({where:{messageId:msg[_0x348b[52]][0],accountId:msg[_0x348b[102]]}})[_0x348b[43]](function(_0xd328x36){if(_0xd328x36){return _0xd328x36[_0x348b[105]]()[_0x348b[43]](function(_0xd328x35){_0xd328x24= _0xd328x35;if(_0xd328x35[_0x348b[91]]!== _0x348b[92]){var _0xd328x37={openReason:_0x348b[93],waiting:true};if(_0xd328x35[_0x348b[91]]!== _0x348b[94]){_0xd328x37[_0x348b[91]]= _0x348b[95]};return _0xd328x24[_0x348b[48]](_0xd328x37,{individualHooks:true})[_0x348b[43]](function(){return Account[_0x348b[103]](msg[_0x348b[102]])[_0x348b[43]](function(_0xd328x39){_0xd328x26= _0xd328x39;if(_0xd328x26[_0x348b[97]]){return Company[_0x348b[101]]({where:{emailDomain:msg[_0x348b[81]][0][_0x348b[82]][_0x348b[99]](_0x348b[98])[1]}})[_0x348b[43]](function(_0xd328x3a){return Contact[_0x348b[100]]({where:{email:msg[_0x348b[81]][0][_0x348b[82]]},defaults:{email:msg[_0x348b[81]][0][_0x348b[82]],firstName:msg[_0x348b[81]][0][_0x348b[89]]|| msg[_0x348b[81]][0][_0x348b[82]][_0x348b[99]](_0x348b[98])[0],ListId:_0xd328x26[_0x348b[97]],CompanyId:_0xd328x3a?_0xd328x3a[_0x348b[73]]:null}})})}else {return []}})[_0x348b[96]](function(_0xd328x38){_0xd328x27= _0xd328x38})})}else {return Account[_0x348b[103]](msg[_0x348b[102]])[_0x348b[43]](function(_0xd328x39){_0xd328x26= _0xd328x39;if(_0xd328x26[_0x348b[97]]){return Company[_0x348b[101]]({where:{emailDomain:msg[_0x348b[81]][0][_0x348b[82]][_0x348b[99]](_0x348b[98])[1]}})[_0x348b[43]](function(_0xd328x3a){return Contact[_0x348b[100]]({where:{email:msg[_0x348b[81]][0][_0x348b[82]]},defaults:{email:msg[_0x348b[81]][0][_0x348b[82]],firstName:msg[_0x348b[81]][0][_0x348b[89]]|| msg[_0x348b[81]][0][_0x348b[82]][_0x348b[99]](_0x348b[98])[0],ListId:_0xd328x26[_0x348b[97]],CompanyId:_0xd328x3a?_0xd328x3a[_0x348b[73]]:null}})})}else {return []}})[_0x348b[96]](function(_0xd328x38){_0xd328x27= _0xd328x38;return Room[_0x348b[74]]({subject:msg[_0x348b[80]],from:_[_0x348b[83]](msg[_0x348b[81]],_0x348b[82])[_0x348b[71]](_0x348b[104]),account:_0xd328x26[_0x348b[89]],attachment:msg[_0x348b[55]]&& msg[_0x348b[55]][_0x348b[56]],lastEvent:_0x348b[79],lastEventAt:moment()[_0x348b[46]](_0x348b[45]),arrivedAt:moment()[_0x348b[46]](_0x348b[45]),waiting:true,MailAccountId:_0xd328x26[_0x348b[73]],ParentId:_0xd328x35[_0x348b[73]]})})[_0x348b[43]](function(_0xd328x35){_0xd328x24= _0xd328x35})}})}else {return Account[_0x348b[103]](msg[_0x348b[102]])[_0x348b[43]](function(_0xd328x39){_0xd328x26= _0xd328x39;if(_0xd328x26[_0x348b[97]]){return Company[_0x348b[101]]({where:{emailDomain:msg[_0x348b[81]][0][_0x348b[82]][_0x348b[99]](_0x348b[98])[1]}})[_0x348b[43]](function(_0xd328x3a){return Contact[_0x348b[100]]({where:{email:msg[_0x348b[81]][0][_0x348b[82]]},defaults:{email:msg[_0x348b[81]][0][_0x348b[82]],firstName:msg[_0x348b[81]][0][_0x348b[89]]|| msg[_0x348b[81]][0][_0x348b[82]][_0x348b[99]](_0x348b[98])[0],ListId:_0xd328x26[_0x348b[97]],CompanyId:_0xd328x3a?_0xd328x3a[_0x348b[73]]:null}})})}else {return []}})[_0x348b[96]](function(_0xd328x38){_0xd328x27= _0xd328x38;return Room[_0x348b[74]]({subject:msg[_0x348b[80]],from:_[_0x348b[83]](msg[_0x348b[81]],_0x348b[82])[_0x348b[71]](_0x348b[104]),account:_0xd328x26[_0x348b[89]],attachment:msg[_0x348b[55]]&& msg[_0x348b[55]][_0x348b[56]],lastEvent:_0x348b[79],waiting:true,lastEventAt:moment()[_0x348b[46]](_0x348b[45]),arrivedAt:moment()[_0x348b[46]](_0x348b[45]),MailAccountId:_0xd328x26[_0x348b[73]]})})[_0x348b[43]](function(_0xd328x35){_0xd328x24= _0xd328x35})}})[_0x348b[43]](function(){return _0xd328x24[_0x348b[48]]({lastEvent:_0x348b[79],mailIn:++_0xd328x24[_0x348b[90]]})})[_0x348b[43]](function(_0xd328x35){return Message[_0x348b[74]]({fromId:_0xd328x27?_0xd328x27[_0x348b[73]]:null,messageId:msg[_0x348b[78]],status:_0x348b[79],subject:msg[_0x348b[80]],from:_[_0x348b[83]](msg[_0x348b[81]],_0x348b[82]),to:msg[_0x348b[84]]?_[_0x348b[83]](msg[_0x348b[84]],_0x348b[82]):[],cc:msg[_0x348b[85]]?_[_0x348b[83]](msg[_0x348b[85]],_0x348b[82]):[],bcc:msg[_0x348b[86]]?_[_0x348b[83]](msg[_0x348b[86]],_0x348b[82]):[],text:msg[_0x348b[87]]|| null,html:msg[_0x348b[88]]|| null,MailRoomId:_0xd328x24[_0x348b[73]],accountName:_0xd328x26[_0x348b[89]],accountId:_0xd328x26[_0x348b[73]],inReplyTo:msg[_0x348b[52]][0]})})[_0x348b[43]](function(_0xd328x2d){var _0xd328x2e=[];var _0xd328x2f=_0xd328x2d;if(ami){ami[_0x348b[41]]({message:_0x348b[54],doc:_0xd328x2d})};createAndStartRouting(_0xd328x24,msg,_0xd328x2d[_0x348b[31]]({plain:true}),_0xd328x26);if(msg[_0x348b[55]]&& msg[_0x348b[55]][_0x348b[56]]){msg[_0x348b[55]][_0x348b[76]](function(_0xd328x30){var _0xd328x31=_0x348b[57]+ Math[_0x348b[58]](32);var _0xd328x32;_0xd328x2e[_0x348b[75]](Attachment[_0x348b[74]]({name:_0xd328x30[_0x348b[61]],basename:_0xd328x31,path:path[_0x348b[71]](config[_0x348b[67]],_0x348b[68],_0x348b[69],_0x348b[55],_0x348b[70],_0xd328x31),type:_0xd328x30[_0x348b[72]],size:_0xd328x30[_0x348b[56]],MailMessageId:_0xd328x2f[_0x348b[73]]})[_0x348b[43]](function(_0xd328x34){return open(_0xd328x34[_0x348b[3]],_0x348b[66])})[_0x348b[43]](function(_0xd328x33){_0xd328x32= _0xd328x33;return write(_0xd328x32, new Buffer(_0xd328x30[_0x348b[65]][_0x348b[64]]),0,_0xd328x30[_0x348b[56]])})[_0x348b[43]](function(){return close(_0xd328x32)})[_0x348b[43]](function(){logger[_0x348b[63]](_0x348b[60],_0xd328x30[_0x348b[61]],_0x348b[62])})[_0x348b[36]](function(_0xd328x21){logger[_0x348b[35]](_0x348b[59],_0xd328x21[_0x348b[53]])}))})};return Promise[_0x348b[77]](_0xd328x2e)})[_0x348b[36]](function(_0xd328x21){logger[_0x348b[35]](_0xd328x21[_0x348b[53]])})}else {return Account[_0x348b[103]](msg[_0x348b[102]])[_0x348b[43]](function(_0xd328x39){_0xd328x26= _0xd328x39;if(_0xd328x26[_0x348b[97]]){return Company[_0x348b[101]]({where:{emailDomain:msg[_0x348b[81]][0][_0x348b[82]][_0x348b[99]](_0x348b[98])[1]}})[_0x348b[43]](function(_0xd328x3a){return Contact[_0x348b[100]]({where:{email:msg[_0x348b[81]][0][_0x348b[82]]},defaults:{email:msg[_0x348b[81]][0][_0x348b[82]],firstName:msg[_0x348b[81]][0][_0x348b[89]]|| msg[_0x348b[81]][0][_0x348b[82]][_0x348b[99]](_0x348b[98])[0],ListId:_0xd328x26[_0x348b[97]],CompanyId:_0xd328x3a?_0xd328x3a[_0x348b[73]]:null}})})}else {return []}})[_0x348b[96]](function(_0xd328x38){_0xd328x27= _0xd328x38;return Room[_0x348b[74]]({mailIn:1,account:_0xd328x26[_0x348b[89]],subject:msg[_0x348b[80]],from:_[_0x348b[83]](msg[_0x348b[81]],_0x348b[82])[_0x348b[71]](_0x348b[104]),status:_0x348b[94],lastEvent:_0x348b[79],lastEventAt:moment()[_0x348b[46]](_0x348b[45]),arrivedAt:moment()[_0x348b[46]](_0x348b[45]),attachment:msg[_0x348b[55]]&& msg[_0x348b[55]][_0x348b[56]],waiting:true,MailMessages:[{messageId:msg[_0x348b[78]],subject:msg[_0x348b[80]],from:_[_0x348b[83]](msg[_0x348b[81]],_0x348b[82]),fromId:_0xd328x27?_0xd328x27[_0x348b[73]]:null,to:msg[_0x348b[84]]?_[_0x348b[83]](msg[_0x348b[84]],_0x348b[82]):[],cc:msg[_0x348b[85]]?_[_0x348b[83]](msg[_0x348b[85]],_0x348b[82]):[],bcc:msg[_0x348b[86]]?_[_0x348b[83]](msg[_0x348b[86]],_0x348b[82]):[],status:_0x348b[79],text:msg[_0x348b[87]]|| null,html:msg[_0x348b[88]]|| null,accountName:_0xd328x26[_0x348b[89]],accountId:_0xd328x26[_0x348b[73]]}],MailAccountId:msg[_0x348b[102]]},{include:[{model:Message}]})})[_0x348b[43]](function(_0xd328x3b){var _0xd328x2e=[];var _0xd328x3c=_0xd328x3b;ami[_0x348b[41]]({message:_0x348b[54],doc:_0xd328x3b[_0x348b[106]][0]});createAndStartRouting(_0xd328x3c,msg,_0xd328x3c[_0x348b[106]][0][_0x348b[31]]({plain:true}),_0xd328x26);if(msg[_0x348b[55]]&& msg[_0x348b[55]][_0x348b[56]]){msg[_0x348b[55]][_0x348b[76]](function(_0xd328x30){var _0xd328x31=_0x348b[57]+ Math[_0x348b[58]](32);var _0xd328x32;_0xd328x2e[_0x348b[75]](Attachment[_0x348b[74]]({name:_0xd328x30[_0x348b[61]],basename:_0xd328x31,path:path[_0x348b[71]](config[_0x348b[67]],_0x348b[68],_0x348b[69],_0x348b[55],_0x348b[70],_0xd328x31),type:_0xd328x30[_0x348b[72]],size:_0xd328x30[_0x348b[56]],MailMessageId:_0xd328x3c[_0x348b[106]][0][_0x348b[73]]})[_0x348b[43]](function(_0xd328x34){return open(_0xd328x34[_0x348b[3]],_0x348b[66])})[_0x348b[43]](function(_0xd328x33){_0xd328x32= _0xd328x33;return write(_0xd328x32, new Buffer(_0xd328x30[_0x348b[65]][_0x348b[64]]),0,_0xd328x30[_0x348b[56]])})[_0x348b[43]](function(){return close(_0xd328x32)})[_0x348b[43]](function(){logger[_0x348b[63]](_0x348b[60],_0xd328x30[_0x348b[61]],_0x348b[62])})[_0x348b[36]](function(_0xd328x21){logger[_0x348b[35]](_0x348b[59],_0xd328x21[_0x348b[53]])}))})};return Promise[_0x348b[77]](_0xd328x2e)})[_0x348b[36]](function(_0xd328x21){logger[_0x348b[35]](_0xd328x21[_0x348b[53]])})}}function handleState(_0xd328x3e,_0xd328x20){return ms[_0x348b[103]](_0xd328x3e)[_0x348b[43]](function(_0xd328x3f){return _0xd328x3f[_0x348b[48]]({state:_0xd328x20[_0x348b[108]],source:_0xd328x20[_0x348b[109]]|| null})})[_0x348b[36]](function(_0xd328x21){logger[_0x348b[35]](_0x348b[107],_0xd328x21[_0x348b[53]])})}function fork(_0xd328x3e,_0xd328x41){return cp[_0x348b[117]](__dirname+ _0x348b[116],[_0xd328x3e,_0xd328x41])[_0x348b[111]](_0x348b[113],function(_0xd328x20){switch(_0xd328x20[_0x348b[115]]){case _0x348b[114]:handleMessage(_0xd328x20);break;case _0x348b[108]:handleState(_0xd328x3e,_0xd328x20);break;default:}})[_0x348b[111]](_0x348b[24],function(_0xd328x42){logger[_0x348b[63]](util[_0x348b[46]](_0x348b[112],_0xd328x41,_0xd328x42))})[_0x348b[111]](_0x348b[35],function(_0xd328x21){logger[_0x348b[35]](_0x348b[110],_0xd328x21[_0x348b[53]])})}function execRequest(_0xd328x1e,_0xd328x44,_0xd328x45){Util[_0x348b[121]](_0xd328x1e,_0xd328x44,_0xd328x45)[_0x348b[43]](function(_0xd328x46){logger[_0x348b[63]](_0x348b[120])})[_0x348b[36]](function(_0xd328x21){logger[_0x348b[119]](_0x348b[118])})}function webhook(_0xd328x1e,_0xd328x48,_0xd328x49){var _0xd328x4a=_0xd328x48;switch(_0xd328x49){case _0x348b[130]:if(_0xd328x4a[_0x348b[122]]&& _0xd328x4a[_0x348b[123]]){logger[_0x348b[63]](_0x348b[124]+ _0xd328x4a[_0x348b[89]]+ _0x348b[125]);execRequest(_0xd328x1e[_0x348b[126]],_0xd328x4a[_0x348b[122]],_0xd328x4a[_0x348b[123]])};if(_0xd328x4a[_0x348b[127]][_0x348b[56]]){_[_0x348b[76]](_0xd328x4a[_0x348b[127]],function(_0xd328x4b){if(_0xd328x4b[_0x348b[128]]){Util[_0x348b[129]](_0xd328x4b,_0xd328x1e)}})};break;case _0x348b[50]:if(_0xd328x4a[_0x348b[131]]&& _0xd328x4a[_0x348b[132]]){logger[_0x348b[63]](_0x348b[124]+ _0xd328x4a[_0x348b[89]]+ _0x348b[133]);execRequest(_0xd328x1e[_0x348b[126]],_0xd328x4a[_0x348b[131]],_0xd328x4a[_0x348b[132]])};break;case _0x348b[24]:if(_0xd328x4a[_0x348b[134]]&& _0xd328x4a[_0x348b[135]]){logger[_0x348b[63]](_0x348b[124]+ _0xd328x4a[_0x348b[89]]+ _0x348b[136]);execRequest(_0xd328x1e[_0x348b[126]],_0xd328x4a[_0x348b[134]],_0xd328x4a[_0x348b[135]])};break;default:logger[_0x348b[35]](_0x348b[137])}}function synch(_0xd328x4d,_0xd328x4e){Account[_0x348b[142]](function(_0xd328x1e){var _0xd328x48=_[_0x348b[38]](_0xd328x4d,{id:_0xd328x1e[_0x348b[73]]});if(_0xd328x48&& _0xd328x48[_0x348b[8]]){if(_0xd328x4e[_0xd328x48[_0x348b[8]][_0x348b[73]]]){logger[_0x348b[63]](util[_0x348b[46]](_0x348b[138],_0xd328x48[_0x348b[8]][_0x348b[73]],_0xd328x4e[_0xd328x48[_0x348b[8]][_0x348b[73]]][_0x348b[139]]));_0xd328x4e[_0xd328x48[_0x348b[8]][_0x348b[73]]][_0x348b[140]]();_0xd328x4e[_0xd328x48[_0x348b[8]][_0x348b[73]]]= null};_[_0x348b[141]](_0xd328x4d,{id:_0xd328x1e[_0x348b[73]]})}});Account[_0x348b[143]](function(_0xd328x1e){_0xd328x4d[_0x348b[75]](_0xd328x1e)});Account[_0x348b[51]](function(_0xd328x1e){var _0xd328x4f=_[_0x348b[38]](_0xd328x4d,{id:_0xd328x1e[_0x348b[73]]});if(_0xd328x4f){logger[_0x348b[63]](_0x348b[144]+ _0xd328x4f[_0x348b[89]]+ _0x348b[145]);_[_0x348b[146]](_0xd328x4f,_0xd328x1e)}else {_0xd328x4d[_0x348b[147]](_0xd328x1e)}})}function createAndStartRouting(_0xd328x3b,_0xd328x51,_0xd328x2d,_0xd328x48){return queue[_0x348b[74]](_0x348b[150],{title:util[_0x348b[46]](_0x348b[151],_0xd328x2d[_0x348b[81]]),room:_0xd328x3b,message:_0xd328x51,mailMessage:_0xd328x2d,account:_0xd328x48})[_0x348b[149]](true)[_0x348b[148]]()}function handleMail(_0xd328x53,_0xd328x54){var _0xd328x51=_0xd328x53[_0x348b[64]][_0x348b[113]];var _0xd328x2d=_0xd328x53[_0x348b[64]][_0x348b[152]];var _0xd328x3b=_0xd328x53[_0x348b[64]][_0x348b[153]];var _0xd328x48=_0xd328x53[_0x348b[64]][_0x348b[154]];var _0xd328x55=_0xd328x54;var _0xd328x56=cp[_0x348b[117]](path[_0x348b[71]](config[_0x348b[67]],_0x348b[162]))[_0x348b[111]](_0x348b[113],function(msg){switch(msg[_0x348b[115]]){case _0x348b[159]:return Message[_0x348b[74]](msg[_0x348b[114]],{include:[{model:Attachment}]});case _0x348b[160]:return SmsMessage[_0x348b[74]](msg[_0x348b[114]]);case _0x348b[161]:ami[_0x348b[41]]({message:msg[_0x348b[115]],doc:msg[_0x348b[114]]});break;default:}})[_0x348b[111]](_0x348b[156],function(){var _0xd328x57=_[_0x348b[141]](processes,{pid:this[_0x348b[139]]});if(_0xd328x57&& _0xd328x57[_0x348b[56]]){return Room[_0x348b[103]](_0xd328x57[0][_0x348b[158]])[_0x348b[43]](function(_0xd328x3b){if(_0xd328x3b){return _0xd328x3b[_0x348b[48]]({waiting:false})}})[_0x348b[157]](function(){_0xd328x55()})}})[_0x348b[111]](_0x348b[24],function(){_0xd328x55()})[_0x348b[111]](_0x348b[155],function(){_0xd328x55()})[_0x348b[111]](_0x348b[35],function(_0xd328x21){_0xd328x55(_0xd328x21)});_0xd328x56[_0x348b[41]]({type:_0x348b[163],param1:{channel:_0x348b[26],uniqueid:util[_0x348b[46]](_0x348b[164],moment()[_0x348b[165]](),_0xd328x3b[_0x348b[73]]),subject:_0xd328x51[_0x348b[80]],messageid:_0xd328x2d[_0x348b[73]],roomid:_0xd328x3b[_0x348b[73]],accountid:_0xd328x48[_0x348b[73]],accountname:_0xd328x48[_0x348b[89]],accountaddress:_0xd328x48[_0x348b[82]],from:_0xd328x51[_0x348b[81]][0][_0x348b[82]],cc:_0xd328x51[_0x348b[85]]?_[_0x348b[83]](_0xd328x51[_0x348b[85]],_0x348b[82]):[]},param2:_0xd328x2d});processes[_0x348b[75]]({id:_0xd328x2d[_0x348b[73]],channel:_0x348b[26],process:_0xd328x56,roomid:_0xd328x3b[_0x348b[73]],pid:_0xd328x56[_0x348b[139]]})}module[_0x348b[166]]= function(_0xd328x58){var _0xd328x4e={};var _0xd328x4d;var _0xd328x59;ami= _0xd328x58;process[_0x348b[111]](_0x348b[156],function(_0xd328x42){for(var _0xd328x5a in _0xd328x4e){if(_0xd328x4e[_0xd328x5a]){_0xd328x4e[_0xd328x5a][_0x348b[140]]()}}});Setting[_0x348b[38]]({where:{id:1},attributes:[_0x348b[73],_0x348b[170]],raw:true})[_0x348b[43]](function(_0xd328x5c){if(_0xd328x5c){queue[_0x348b[42]](_0x348b[150],_0xd328x5c[_0x348b[170]],handleMail)};return Account[_0x348b[171]]({include:[ms]})})[_0x348b[43]](function(_0xd328x5b){_0xd328x4d= _0xd328x5b;synch(_0xd328x4d,_0xd328x4e);_0xd328x4d[_0x348b[76]](function(_0xd328x48){if(_0xd328x48[_0x348b[8]]){_0xd328x4e[_0xd328x48[_0x348b[8]][_0x348b[73]]]= fork(_0xd328x48[_0x348b[8]][_0x348b[73]],_0xd328x48[_0x348b[8]][_0x348b[167]])}});Report[_0x348b[51]](function(_0xd328x1e){var _0xd328x48=_[_0x348b[38]](_0xd328x4d,{id:parseInt(_0xd328x1e[_0x348b[168]])});if(_0xd328x48&& _0xd328x1e[_0x348b[33]](_0x348b[32])){webhook(_0xd328x1e,_0xd328x48,_0x348b[130])};if(_0xd328x48&& _0xd328x1e[_0x348b[33]](_0x348b[49])){webhook(_0xd328x1e,_0xd328x48,_0x348b[50])}});Room[_0x348b[51]](function(_0xd328x1e){var _0xd328x48=_[_0x348b[38]](_0xd328x4d,{id:_0xd328x1e[_0x348b[169]]});if(_0xd328x48&& _0xd328x1e[_0x348b[33]](_0x348b[91])&& _0xd328x1e[_0x348b[91]]=== _0x348b[92]){webhook(_0xd328x1e,_0xd328x48,_0x348b[24])}})})[_0x348b[36]](function(_0xd328x21){logger[_0x348b[35]](_0xd328x21[_0x348b[53]])});ms[_0x348b[143]](function(_0xd328x3f){var _0xd328x48=_[_0x348b[38]](_0xd328x4d,{id:_0xd328x3f[_0x348b[169]]});if(_0xd328x48){_0xd328x48[_0x348b[8]]= _0xd328x3f};_0xd328x4e[_0xd328x3f[_0x348b[73]]]= fork(_0xd328x3f[_0x348b[73]],_0xd328x3f[_0x348b[167]])});ms[_0x348b[51]](function(_0xd328x3f){if(_0xd328x4e[_0xd328x3f[_0x348b[73]]]){if(_0xd328x3f[_0x348b[33]](_0x348b[108])|| _0xd328x3f[_0x348b[33]](_0x348b[109])){logger[_0x348b[63]](util[_0x348b[46]](_0x348b[172],_0xd328x3f[_0x348b[73]],_0xd328x4e[_0xd328x3f[_0x348b[73]]][_0x348b[139]]))}else {_0xd328x4e[_0xd328x3f[_0x348b[73]]][_0x348b[140]]();_0xd328x4e[_0xd328x3f[_0x348b[73]]]= null;_0xd328x4e[_0xd328x3f[_0x348b[73]]]= fork(_0xd328x3f[_0x348b[73]],_0xd328x3f[_0x348b[167]])}}});ms[_0x348b[142]](function(_0xd328x3f){if(_0xd328x4e[_0xd328x3f[_0x348b[73]]]){logger[_0x348b[63]](util[_0x348b[46]](_0x348b[138],_0xd328x3f[_0x348b[73]],_0xd328x4e[_0xd328x3f[_0x348b[73]]][_0x348b[139]]));_0xd328x4e[_0xd328x3f[_0x348b[73]]][_0x348b[140]]();_0xd328x4e[_0xd328x3f[_0x348b[73]]]= null}})}