1 var _0xd6dc=["\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"];_0xd6dc[0];var _=require(_0xd6dc[1]);var util=require(_0xd6dc[2]);var path=require(_0xd6dc[3]);var cp=require(_0xd6dc[4]);var moment=require(_0xd6dc[5]);var kue=require(_0xd6dc[6]);var Promise=require(_0xd6dc[7]);var ms=require(_0xd6dc[9])[_0xd6dc[8]];var msg=require(_0xd6dc[9])[_0xd6dc[10]];var Room=require(_0xd6dc[9])[_0xd6dc[11]];var Report=require(_0xd6dc[9])[_0xd6dc[12]];var Status=require(_0xd6dc[9])[_0xd6dc[13]];var Session=require(_0xd6dc[9])[_0xd6dc[14]];var Message=require(_0xd6dc[9])[_0xd6dc[10]];var SmsMessage=require(_0xd6dc[9])[_0xd6dc[15]];var Account=require(_0xd6dc[9])[_0xd6dc[16]];var Setting=require(_0xd6dc[9])[_0xd6dc[17]];var Contact=require(_0xd6dc[9])[_0xd6dc[18]];var Company=require(_0xd6dc[9])[_0xd6dc[19]];var Attachment=require(_0xd6dc[9])[_0xd6dc[20]];var open=Promise[_0xd6dc[23]](require(_0xd6dc[22])[_0xd6dc[21]]);var close=Promise[_0xd6dc[23]](require(_0xd6dc[22])[_0xd6dc[24]]);var write=Promise[_0xd6dc[23]](require(_0xd6dc[22])[_0xd6dc[25]]);var logger=require(_0xd6dc[27])(_0xd6dc[26]);var config=require(_0xd6dc[28]);var Util=require(_0xd6dc[29]);var queue=kue[_0xd6dc[30]]();var processes=[];var ami;Report[_0xd6dc[51]](function(_0xe203x1e,_0xe203x1f){var _0xe203x20=_0xe203x1e[_0xd6dc[31]]({plain:true});if(_0xe203x1e[_0xd6dc[33]](_0xd6dc[32])){return Session[_0xd6dc[48]]({memberid:_0xe203x20[_0xd6dc[44]],membername:_0xe203x20[_0xd6dc[40]],leaveAt:moment()[_0xd6dc[46]](_0xd6dc[45])},{where:{uniqueid:_0xe203x20[_0xd6dc[47]],leaveAt:null},individualHooks:true})[_0xd6dc[43]](function(){var _0xe203x22=_[_0xd6dc[38]](processes,{id:_0xe203x20[_0xd6dc[37]],channel:_0xd6dc[26]});if(_0xe203x22){_0xe203x22[_0xd6dc[42]][_0xd6dc[41]]({type:_0xd6dc[39],membername:_0xe203x20[_0xd6dc[40]]})}})[_0xd6dc[36]](function(_0xe203x21){logger[_0xd6dc[35]](_0xd6dc[34],_0xe203x21)})}else {if(_0xe203x1e[_0xd6dc[33]](_0xd6dc[49])){var _0xe203x22=_[_0xd6dc[38]](processes,{id:_0xe203x20[_0xd6dc[37]],channel:_0xd6dc[26]});if(_0xe203x22){_0xe203x22[_0xd6dc[42]][_0xd6dc[41]]({type:_0xd6dc[50],id:_0xe203x20[_0xd6dc[44]],membername:_0xe203x20[_0xd6dc[40]]})}}}});function handleMessage(msg){var _0xe203x24;var _0xe203x25;var _0xe203x26;var _0xe203x27;var _0xe203x28;var _0xe203x29,_0xe203x2a,_0xe203x2b,_0xe203x2c;if(msg[_0xd6dc[52]]){return Message[_0xd6dc[101]]({where:{messageId:msg[_0xd6dc[52]][0],accountId:msg[_0xd6dc[102]]}})[_0xd6dc[43]](function(_0xe203x36){if(_0xe203x36){return _0xe203x36[_0xd6dc[105]]()[_0xd6dc[43]](function(_0xe203x35){_0xe203x24= _0xe203x35;if(_0xe203x35[_0xd6dc[91]]!== _0xd6dc[92]){var _0xe203x37={openReason:_0xd6dc[93],waiting:true};if(_0xe203x35[_0xd6dc[91]]!== _0xd6dc[94]){_0xe203x37[_0xd6dc[91]]= _0xd6dc[95]};return _0xe203x24[_0xd6dc[48]](_0xe203x37,{individualHooks:true})[_0xd6dc[43]](function(){return Account[_0xd6dc[103]](msg[_0xd6dc[102]])[_0xd6dc[43]](function(_0xe203x39){_0xe203x26= _0xe203x39;if(_0xe203x26[_0xd6dc[97]]){return Company[_0xd6dc[101]]({where:{emailDomain:msg[_0xd6dc[81]][0][_0xd6dc[82]][_0xd6dc[99]](_0xd6dc[98])[1]}})[_0xd6dc[43]](function(_0xe203x3a){return Contact[_0xd6dc[100]]({where:{email:msg[_0xd6dc[81]][0][_0xd6dc[82]]},defaults:{email:msg[_0xd6dc[81]][0][_0xd6dc[82]],firstName:msg[_0xd6dc[81]][0][_0xd6dc[89]]|| msg[_0xd6dc[81]][0][_0xd6dc[82]][_0xd6dc[99]](_0xd6dc[98])[0],ListId:_0xe203x26[_0xd6dc[97]],CompanyId:_0xe203x3a?_0xe203x3a[_0xd6dc[73]]:null}})})}else {return []}})[_0xd6dc[96]](function(_0xe203x38){_0xe203x27= _0xe203x38})})}else {return Account[_0xd6dc[103]](msg[_0xd6dc[102]])[_0xd6dc[43]](function(_0xe203x39){_0xe203x26= _0xe203x39;if(_0xe203x26[_0xd6dc[97]]){return Company[_0xd6dc[101]]({where:{emailDomain:msg[_0xd6dc[81]][0][_0xd6dc[82]][_0xd6dc[99]](_0xd6dc[98])[1]}})[_0xd6dc[43]](function(_0xe203x3a){return Contact[_0xd6dc[100]]({where:{email:msg[_0xd6dc[81]][0][_0xd6dc[82]]},defaults:{email:msg[_0xd6dc[81]][0][_0xd6dc[82]],firstName:msg[_0xd6dc[81]][0][_0xd6dc[89]]|| msg[_0xd6dc[81]][0][_0xd6dc[82]][_0xd6dc[99]](_0xd6dc[98])[0],ListId:_0xe203x26[_0xd6dc[97]],CompanyId:_0xe203x3a?_0xe203x3a[_0xd6dc[73]]:null}})})}else {return []}})[_0xd6dc[96]](function(_0xe203x38){_0xe203x27= _0xe203x38;return Room[_0xd6dc[74]]({subject:msg[_0xd6dc[80]],from:_[_0xd6dc[83]](msg[_0xd6dc[81]],_0xd6dc[82])[_0xd6dc[71]](_0xd6dc[104]),account:_0xe203x26[_0xd6dc[89]],attachment:msg[_0xd6dc[55]]&& msg[_0xd6dc[55]][_0xd6dc[56]],lastEvent:_0xd6dc[79],lastEventAt:moment()[_0xd6dc[46]](_0xd6dc[45]),arrivedAt:moment()[_0xd6dc[46]](_0xd6dc[45]),waiting:true,MailAccountId:_0xe203x26[_0xd6dc[73]],ParentId:_0xe203x35[_0xd6dc[73]]})})[_0xd6dc[43]](function(_0xe203x35){_0xe203x24= _0xe203x35})}})}else {return Account[_0xd6dc[103]](msg[_0xd6dc[102]])[_0xd6dc[43]](function(_0xe203x39){_0xe203x26= _0xe203x39;if(_0xe203x26[_0xd6dc[97]]){return Company[_0xd6dc[101]]({where:{emailDomain:msg[_0xd6dc[81]][0][_0xd6dc[82]][_0xd6dc[99]](_0xd6dc[98])[1]}})[_0xd6dc[43]](function(_0xe203x3a){return Contact[_0xd6dc[100]]({where:{email:msg[_0xd6dc[81]][0][_0xd6dc[82]]},defaults:{email:msg[_0xd6dc[81]][0][_0xd6dc[82]],firstName:msg[_0xd6dc[81]][0][_0xd6dc[89]]|| msg[_0xd6dc[81]][0][_0xd6dc[82]][_0xd6dc[99]](_0xd6dc[98])[0],ListId:_0xe203x26[_0xd6dc[97]],CompanyId:_0xe203x3a?_0xe203x3a[_0xd6dc[73]]:null}})})}else {return []}})[_0xd6dc[96]](function(_0xe203x38){_0xe203x27= _0xe203x38;return Room[_0xd6dc[74]]({subject:msg[_0xd6dc[80]],from:_[_0xd6dc[83]](msg[_0xd6dc[81]],_0xd6dc[82])[_0xd6dc[71]](_0xd6dc[104]),account:_0xe203x26[_0xd6dc[89]],attachment:msg[_0xd6dc[55]]&& msg[_0xd6dc[55]][_0xd6dc[56]],lastEvent:_0xd6dc[79],waiting:true,lastEventAt:moment()[_0xd6dc[46]](_0xd6dc[45]),arrivedAt:moment()[_0xd6dc[46]](_0xd6dc[45]),MailAccountId:_0xe203x26[_0xd6dc[73]]})})[_0xd6dc[43]](function(_0xe203x35){_0xe203x24= _0xe203x35})}})[_0xd6dc[43]](function(){return _0xe203x24[_0xd6dc[48]]({lastEvent:_0xd6dc[79],mailIn:++_0xe203x24[_0xd6dc[90]]})})[_0xd6dc[43]](function(_0xe203x35){return Message[_0xd6dc[74]]({fromId:_0xe203x27?_0xe203x27[_0xd6dc[73]]:null,messageId:msg[_0xd6dc[78]],status:_0xd6dc[79],subject:msg[_0xd6dc[80]],from:_[_0xd6dc[83]](msg[_0xd6dc[81]],_0xd6dc[82]),to:msg[_0xd6dc[84]]?_[_0xd6dc[83]](msg[_0xd6dc[84]],_0xd6dc[82]):[],cc:msg[_0xd6dc[85]]?_[_0xd6dc[83]](msg[_0xd6dc[85]],_0xd6dc[82]):[],bcc:msg[_0xd6dc[86]]?_[_0xd6dc[83]](msg[_0xd6dc[86]],_0xd6dc[82]):[],text:msg[_0xd6dc[87]]|| null,html:msg[_0xd6dc[88]]|| null,MailRoomId:_0xe203x24[_0xd6dc[73]],accountName:_0xe203x26[_0xd6dc[89]],accountId:_0xe203x26[_0xd6dc[73]],inReplyTo:msg[_0xd6dc[52]][0]})})[_0xd6dc[43]](function(_0xe203x2d){var _0xe203x2e=[];var _0xe203x2f=_0xe203x2d;if(ami){ami[_0xd6dc[41]]({message:_0xd6dc[54],doc:_0xe203x2d})};createAndStartRouting(_0xe203x24,msg,_0xe203x2d[_0xd6dc[31]]({plain:true}),_0xe203x26);if(msg[_0xd6dc[55]]&& msg[_0xd6dc[55]][_0xd6dc[56]]){msg[_0xd6dc[55]][_0xd6dc[76]](function(_0xe203x30){var _0xe203x31=_0xd6dc[57]+ Math[_0xd6dc[58]](32);var _0xe203x32;_0xe203x2e[_0xd6dc[75]](Attachment[_0xd6dc[74]]({name:_0xe203x30[_0xd6dc[61]],basename:_0xe203x31,path:path[_0xd6dc[71]](config[_0xd6dc[67]],_0xd6dc[68],_0xd6dc[69],_0xd6dc[55],_0xd6dc[70],_0xe203x31),type:_0xe203x30[_0xd6dc[72]],size:_0xe203x30[_0xd6dc[56]],MailMessageId:_0xe203x2f[_0xd6dc[73]]})[_0xd6dc[43]](function(_0xe203x34){return open(_0xe203x34[_0xd6dc[3]],_0xd6dc[66])})[_0xd6dc[43]](function(_0xe203x33){_0xe203x32= _0xe203x33;return write(_0xe203x32, new Buffer(_0xe203x30[_0xd6dc[65]][_0xd6dc[64]]),0,_0xe203x30[_0xd6dc[56]])})[_0xd6dc[43]](function(){return close(_0xe203x32)})[_0xd6dc[43]](function(){logger[_0xd6dc[63]](_0xd6dc[60],_0xe203x30[_0xd6dc[61]],_0xd6dc[62])})[_0xd6dc[36]](function(_0xe203x21){logger[_0xd6dc[35]](_0xd6dc[59],_0xe203x21[_0xd6dc[53]])}))})};return Promise[_0xd6dc[77]](_0xe203x2e)})[_0xd6dc[36]](function(_0xe203x21){logger[_0xd6dc[35]](_0xe203x21[_0xd6dc[53]])})}else {return Account[_0xd6dc[103]](msg[_0xd6dc[102]])[_0xd6dc[43]](function(_0xe203x39){_0xe203x26= _0xe203x39;if(_0xe203x26[_0xd6dc[97]]){return Company[_0xd6dc[101]]({where:{emailDomain:msg[_0xd6dc[81]][0][_0xd6dc[82]][_0xd6dc[99]](_0xd6dc[98])[1]}})[_0xd6dc[43]](function(_0xe203x3a){return Contact[_0xd6dc[100]]({where:{email:msg[_0xd6dc[81]][0][_0xd6dc[82]]},defaults:{email:msg[_0xd6dc[81]][0][_0xd6dc[82]],firstName:msg[_0xd6dc[81]][0][_0xd6dc[89]]|| msg[_0xd6dc[81]][0][_0xd6dc[82]][_0xd6dc[99]](_0xd6dc[98])[0],ListId:_0xe203x26[_0xd6dc[97]],CompanyId:_0xe203x3a?_0xe203x3a[_0xd6dc[73]]:null}})})}else {return []}})[_0xd6dc[96]](function(_0xe203x38){_0xe203x27= _0xe203x38;return Room[_0xd6dc[74]]({mailIn:1,account:_0xe203x26[_0xd6dc[89]],subject:msg[_0xd6dc[80]],from:_[_0xd6dc[83]](msg[_0xd6dc[81]],_0xd6dc[82])[_0xd6dc[71]](_0xd6dc[104]),status:_0xd6dc[94],lastEvent:_0xd6dc[79],lastEventAt:moment()[_0xd6dc[46]](_0xd6dc[45]),arrivedAt:moment()[_0xd6dc[46]](_0xd6dc[45]),attachment:msg[_0xd6dc[55]]&& msg[_0xd6dc[55]][_0xd6dc[56]],waiting:true,MailMessages:[{messageId:msg[_0xd6dc[78]],subject:msg[_0xd6dc[80]],from:_[_0xd6dc[83]](msg[_0xd6dc[81]],_0xd6dc[82]),fromId:_0xe203x27?_0xe203x27[_0xd6dc[73]]:null,to:msg[_0xd6dc[84]]?_[_0xd6dc[83]](msg[_0xd6dc[84]],_0xd6dc[82]):[],cc:msg[_0xd6dc[85]]?_[_0xd6dc[83]](msg[_0xd6dc[85]],_0xd6dc[82]):[],bcc:msg[_0xd6dc[86]]?_[_0xd6dc[83]](msg[_0xd6dc[86]],_0xd6dc[82]):[],status:_0xd6dc[79],text:msg[_0xd6dc[87]]|| null,html:msg[_0xd6dc[88]]|| null,accountName:_0xe203x26[_0xd6dc[89]],accountId:_0xe203x26[_0xd6dc[73]]}],MailAccountId:msg[_0xd6dc[102]]},{include:[{model:Message}]})})[_0xd6dc[43]](function(_0xe203x3b){var _0xe203x2e=[];var _0xe203x3c=_0xe203x3b;ami[_0xd6dc[41]]({message:_0xd6dc[54],doc:_0xe203x3b[_0xd6dc[106]][0]});createAndStartRouting(_0xe203x3c,msg,_0xe203x3c[_0xd6dc[106]][0][_0xd6dc[31]]({plain:true}),_0xe203x26);if(msg[_0xd6dc[55]]&& msg[_0xd6dc[55]][_0xd6dc[56]]){msg[_0xd6dc[55]][_0xd6dc[76]](function(_0xe203x30){var _0xe203x31=_0xd6dc[57]+ Math[_0xd6dc[58]](32);var _0xe203x32;_0xe203x2e[_0xd6dc[75]](Attachment[_0xd6dc[74]]({name:_0xe203x30[_0xd6dc[61]],basename:_0xe203x31,path:path[_0xd6dc[71]](config[_0xd6dc[67]],_0xd6dc[68],_0xd6dc[69],_0xd6dc[55],_0xd6dc[70],_0xe203x31),type:_0xe203x30[_0xd6dc[72]],size:_0xe203x30[_0xd6dc[56]],MailMessageId:_0xe203x3c[_0xd6dc[106]][0][_0xd6dc[73]]})[_0xd6dc[43]](function(_0xe203x34){return open(_0xe203x34[_0xd6dc[3]],_0xd6dc[66])})[_0xd6dc[43]](function(_0xe203x33){_0xe203x32= _0xe203x33;return write(_0xe203x32, new Buffer(_0xe203x30[_0xd6dc[65]][_0xd6dc[64]]),0,_0xe203x30[_0xd6dc[56]])})[_0xd6dc[43]](function(){return close(_0xe203x32)})[_0xd6dc[43]](function(){logger[_0xd6dc[63]](_0xd6dc[60],_0xe203x30[_0xd6dc[61]],_0xd6dc[62])})[_0xd6dc[36]](function(_0xe203x21){logger[_0xd6dc[35]](_0xd6dc[59],_0xe203x21[_0xd6dc[53]])}))})};return Promise[_0xd6dc[77]](_0xe203x2e)})[_0xd6dc[36]](function(_0xe203x21){logger[_0xd6dc[35]](_0xe203x21[_0xd6dc[53]])})}}function handleState(_0xe203x3e,_0xe203x20){return ms[_0xd6dc[103]](_0xe203x3e)[_0xd6dc[43]](function(_0xe203x3f){return _0xe203x3f[_0xd6dc[48]]({state:_0xe203x20[_0xd6dc[108]],source:_0xe203x20[_0xd6dc[109]]|| null})})[_0xd6dc[36]](function(_0xe203x21){logger[_0xd6dc[35]](_0xd6dc[107],_0xe203x21[_0xd6dc[53]])})}function fork(_0xe203x3e,_0xe203x41){return cp[_0xd6dc[117]](__dirname+ _0xd6dc[116],[_0xe203x3e,_0xe203x41])[_0xd6dc[111]](_0xd6dc[113],function(_0xe203x20){switch(_0xe203x20[_0xd6dc[115]]){case _0xd6dc[114]:handleMessage(_0xe203x20);break;case _0xd6dc[108]:handleState(_0xe203x3e,_0xe203x20);break;default:}})[_0xd6dc[111]](_0xd6dc[24],function(_0xe203x42){logger[_0xd6dc[63]](util[_0xd6dc[46]](_0xd6dc[112],_0xe203x41,_0xe203x42))})[_0xd6dc[111]](_0xd6dc[35],function(_0xe203x21){logger[_0xd6dc[35]](_0xd6dc[110],_0xe203x21[_0xd6dc[53]])})}function execRequest(_0xe203x1e,_0xe203x44,_0xe203x45){Util[_0xd6dc[121]](_0xe203x1e,_0xe203x44,_0xe203x45)[_0xd6dc[43]](function(_0xe203x46){logger[_0xd6dc[63]](_0xd6dc[120])})[_0xd6dc[36]](function(_0xe203x21){logger[_0xd6dc[119]](_0xd6dc[118])})}function webhook(_0xe203x1e,_0xe203x48,_0xe203x49){var _0xe203x4a=_0xe203x48;switch(_0xe203x49){case _0xd6dc[130]:if(_0xe203x4a[_0xd6dc[122]]&& _0xe203x4a[_0xd6dc[123]]){logger[_0xd6dc[63]](_0xd6dc[124]+ _0xe203x4a[_0xd6dc[89]]+ _0xd6dc[125]);execRequest(_0xe203x1e[_0xd6dc[126]],_0xe203x4a[_0xd6dc[122]],_0xe203x4a[_0xd6dc[123]])};if(_0xe203x4a[_0xd6dc[127]][_0xd6dc[56]]){_[_0xd6dc[76]](_0xe203x4a[_0xd6dc[127]],function(_0xe203x4b){if(_0xe203x4b[_0xd6dc[128]]){Util[_0xd6dc[129]](_0xe203x4b,_0xe203x1e)}})};break;case _0xd6dc[50]:if(_0xe203x4a[_0xd6dc[131]]&& _0xe203x4a[_0xd6dc[132]]){logger[_0xd6dc[63]](_0xd6dc[124]+ _0xe203x4a[_0xd6dc[89]]+ _0xd6dc[133]);execRequest(_0xe203x1e[_0xd6dc[126]],_0xe203x4a[_0xd6dc[131]],_0xe203x4a[_0xd6dc[132]])};break;case _0xd6dc[24]:if(_0xe203x4a[_0xd6dc[134]]&& _0xe203x4a[_0xd6dc[135]]){logger[_0xd6dc[63]](_0xd6dc[124]+ _0xe203x4a[_0xd6dc[89]]+ _0xd6dc[136]);execRequest(_0xe203x1e[_0xd6dc[126]],_0xe203x4a[_0xd6dc[134]],_0xe203x4a[_0xd6dc[135]])};break;default:logger[_0xd6dc[35]](_0xd6dc[137])}}function synch(_0xe203x4d,_0xe203x4e){Account[_0xd6dc[142]](function(_0xe203x1e){var _0xe203x48=_[_0xd6dc[38]](_0xe203x4d,{id:_0xe203x1e[_0xd6dc[73]]});if(_0xe203x48&& _0xe203x48[_0xd6dc[8]]){if(_0xe203x4e[_0xe203x48[_0xd6dc[8]][_0xd6dc[73]]]){logger[_0xd6dc[63]](util[_0xd6dc[46]](_0xd6dc[138],_0xe203x48[_0xd6dc[8]][_0xd6dc[73]],_0xe203x4e[_0xe203x48[_0xd6dc[8]][_0xd6dc[73]]][_0xd6dc[139]]));_0xe203x4e[_0xe203x48[_0xd6dc[8]][_0xd6dc[73]]][_0xd6dc[140]]();_0xe203x4e[_0xe203x48[_0xd6dc[8]][_0xd6dc[73]]]= null};_[_0xd6dc[141]](_0xe203x4d,{id:_0xe203x1e[_0xd6dc[73]]})}});Account[_0xd6dc[143]](function(_0xe203x1e){_0xe203x4d[_0xd6dc[75]](_0xe203x1e)});Account[_0xd6dc[51]](function(_0xe203x1e){var _0xe203x4f=_[_0xd6dc[38]](_0xe203x4d,{id:_0xe203x1e[_0xd6dc[73]]});if(_0xe203x4f){logger[_0xd6dc[63]](_0xd6dc[144]+ _0xe203x4f[_0xd6dc[89]]+ _0xd6dc[145]);_[_0xd6dc[146]](_0xe203x4f,_0xe203x1e)}else {_0xe203x4d[_0xd6dc[147]](_0xe203x1e)}})}function createAndStartRouting(_0xe203x3b,_0xe203x51,_0xe203x2d,_0xe203x48){return queue[_0xd6dc[74]](_0xd6dc[150],{title:util[_0xd6dc[46]](_0xd6dc[151],_0xe203x2d[_0xd6dc[81]]),room:_0xe203x3b,message:_0xe203x51,mailMessage:_0xe203x2d,account:_0xe203x48})[_0xd6dc[149]](true)[_0xd6dc[148]]()}function handleMail(_0xe203x53,_0xe203x54){var _0xe203x51=_0xe203x53[_0xd6dc[64]][_0xd6dc[113]];var _0xe203x2d=_0xe203x53[_0xd6dc[64]][_0xd6dc[152]];var _0xe203x3b=_0xe203x53[_0xd6dc[64]][_0xd6dc[153]];var _0xe203x48=_0xe203x53[_0xd6dc[64]][_0xd6dc[154]];var _0xe203x55=_0xe203x54;var _0xe203x56=cp[_0xd6dc[117]](path[_0xd6dc[71]](config[_0xd6dc[67]],_0xd6dc[162]))[_0xd6dc[111]](_0xd6dc[113],function(msg){switch(msg[_0xd6dc[115]]){case _0xd6dc[159]:return Message[_0xd6dc[74]](msg[_0xd6dc[114]],{include:[{model:Attachment}]});case _0xd6dc[160]:return SmsMessage[_0xd6dc[74]](msg[_0xd6dc[114]]);case _0xd6dc[161]:ami[_0xd6dc[41]]({message:msg[_0xd6dc[115]],doc:msg[_0xd6dc[114]]});break;default:}})[_0xd6dc[111]](_0xd6dc[156],function(){var _0xe203x57=_[_0xd6dc[141]](processes,{pid:this[_0xd6dc[139]]});if(_0xe203x57&& _0xe203x57[_0xd6dc[56]]){return Room[_0xd6dc[103]](_0xe203x57[0][_0xd6dc[158]])[_0xd6dc[43]](function(_0xe203x3b){if(_0xe203x3b){return _0xe203x3b[_0xd6dc[48]]({waiting:false})}})[_0xd6dc[157]](function(){_0xe203x55()})}})[_0xd6dc[111]](_0xd6dc[24],function(){_0xe203x55()})[_0xd6dc[111]](_0xd6dc[155],function(){_0xe203x55()})[_0xd6dc[111]](_0xd6dc[35],function(_0xe203x21){_0xe203x55(_0xe203x21)});_0xe203x56[_0xd6dc[41]]({type:_0xd6dc[163],param1:{channel:_0xd6dc[26],uniqueid:util[_0xd6dc[46]](_0xd6dc[164],moment()[_0xd6dc[165]](),_0xe203x3b[_0xd6dc[73]]),subject:_0xe203x51[_0xd6dc[80]],messageid:_0xe203x2d[_0xd6dc[73]],roomid:_0xe203x3b[_0xd6dc[73]],accountid:_0xe203x48[_0xd6dc[73]],accountname:_0xe203x48[_0xd6dc[89]],accountaddress:_0xe203x48[_0xd6dc[82]],from:_0xe203x51[_0xd6dc[81]][0][_0xd6dc[82]],cc:_0xe203x51[_0xd6dc[85]]?_[_0xd6dc[83]](_0xe203x51[_0xd6dc[85]],_0xd6dc[82]):[]},param2:_0xe203x2d});processes[_0xd6dc[75]]({id:_0xe203x2d[_0xd6dc[73]],channel:_0xd6dc[26],process:_0xe203x56,roomid:_0xe203x3b[_0xd6dc[73]],pid:_0xe203x56[_0xd6dc[139]]})}module[_0xd6dc[166]]= function(_0xe203x58){var _0xe203x4e={};var _0xe203x4d;var _0xe203x59;ami= _0xe203x58;process[_0xd6dc[111]](_0xd6dc[156],function(_0xe203x42){for(var _0xe203x5a in _0xe203x4e){if(_0xe203x4e[_0xe203x5a]){_0xe203x4e[_0xe203x5a][_0xd6dc[140]]()}}});Setting[_0xd6dc[38]]({where:{id:1},attributes:[_0xd6dc[73],_0xd6dc[170]],raw:true})[_0xd6dc[43]](function(_0xe203x5c){if(_0xe203x5c){queue[_0xd6dc[42]](_0xd6dc[150],_0xe203x5c[_0xd6dc[170]],handleMail)};return Account[_0xd6dc[171]]({include:[ms]})})[_0xd6dc[43]](function(_0xe203x5b){_0xe203x4d= _0xe203x5b;synch(_0xe203x4d,_0xe203x4e);_0xe203x4d[_0xd6dc[76]](function(_0xe203x48){if(_0xe203x48[_0xd6dc[8]]){_0xe203x4e[_0xe203x48[_0xd6dc[8]][_0xd6dc[73]]]= fork(_0xe203x48[_0xd6dc[8]][_0xd6dc[73]],_0xe203x48[_0xd6dc[8]][_0xd6dc[167]])}});Report[_0xd6dc[51]](function(_0xe203x1e){var _0xe203x48=_[_0xd6dc[38]](_0xe203x4d,{id:parseInt(_0xe203x1e[_0xd6dc[168]])});if(_0xe203x48&& _0xe203x1e[_0xd6dc[33]](_0xd6dc[32])){webhook(_0xe203x1e,_0xe203x48,_0xd6dc[130])};if(_0xe203x48&& _0xe203x1e[_0xd6dc[33]](_0xd6dc[49])){webhook(_0xe203x1e,_0xe203x48,_0xd6dc[50])}});Room[_0xd6dc[51]](function(_0xe203x1e){var _0xe203x48=_[_0xd6dc[38]](_0xe203x4d,{id:_0xe203x1e[_0xd6dc[169]]});if(_0xe203x48&& _0xe203x1e[_0xd6dc[33]](_0xd6dc[91])&& _0xe203x1e[_0xd6dc[91]]=== _0xd6dc[92]){webhook(_0xe203x1e,_0xe203x48,_0xd6dc[24])}})})[_0xd6dc[36]](function(_0xe203x21){logger[_0xd6dc[35]](_0xe203x21[_0xd6dc[53]])});ms[_0xd6dc[143]](function(_0xe203x3f){var _0xe203x48=_[_0xd6dc[38]](_0xe203x4d,{id:_0xe203x3f[_0xd6dc[169]]});if(_0xe203x48){_0xe203x48[_0xd6dc[8]]= _0xe203x3f};_0xe203x4e[_0xe203x3f[_0xd6dc[73]]]= fork(_0xe203x3f[_0xd6dc[73]],_0xe203x3f[_0xd6dc[167]])});ms[_0xd6dc[51]](function(_0xe203x3f){if(_0xe203x4e[_0xe203x3f[_0xd6dc[73]]]){if(_0xe203x3f[_0xd6dc[33]](_0xd6dc[108])|| _0xe203x3f[_0xd6dc[33]](_0xd6dc[109])){logger[_0xd6dc[63]](util[_0xd6dc[46]](_0xd6dc[172],_0xe203x3f[_0xd6dc[73]],_0xe203x4e[_0xe203x3f[_0xd6dc[73]]][_0xd6dc[139]]))}else {_0xe203x4e[_0xe203x3f[_0xd6dc[73]]][_0xd6dc[140]]();_0xe203x4e[_0xe203x3f[_0xd6dc[73]]]= null;_0xe203x4e[_0xe203x3f[_0xd6dc[73]]]= fork(_0xe203x3f[_0xd6dc[73]],_0xe203x3f[_0xd6dc[167]])}}});ms[_0xd6dc[142]](function(_0xe203x3f){if(_0xe203x4e[_0xe203x3f[_0xd6dc[73]]]){logger[_0xd6dc[63]](util[_0xd6dc[46]](_0xd6dc[138],_0xe203x3f[_0xd6dc[73]],_0xe203x4e[_0xe203x3f[_0xd6dc[73]]][_0xd6dc[139]]));_0xe203x4e[_0xe203x3f[_0xd6dc[73]]][_0xd6dc[140]]();_0xe203x4e[_0xe203x3f[_0xd6dc[73]]]= null}})}