6db71e21ec81cf6e74ac39b5cb388188a0d847c0
[motion.git] / server / config / imap / index.js
1 var _0x85b4=["\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","\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","\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","\x52\x65\x70\x6F\x72\x74\x4D\x61\x69\x6C\x52\x6F\x6F\x6D","\x62\x6C\x75\x65\x62\x69\x72\x64","\x6D\x6F\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","\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","\x65\x78\x69\x74","\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","\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","\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"];_0x85b4[0];var _=require(_0x85b4[1]);var util=require(_0x85b4[2]);var path=require(_0x85b4[3]);var cp=require(_0x85b4[4]);var ms=require(_0x85b4[6])[_0x85b4[5]];var msg=require(_0x85b4[6])[_0x85b4[7]];var Room=require(_0x85b4[6])[_0x85b4[8]];var Report=require(_0x85b4[6])[_0x85b4[9]];var Status=require(_0x85b4[6])[_0x85b4[10]];var Session=require(_0x85b4[6])[_0x85b4[11]];var Message=require(_0x85b4[6])[_0x85b4[7]];var SmsMessage=require(_0x85b4[6])[_0x85b4[12]];var Account=require(_0x85b4[6])[_0x85b4[13]];var Contact=require(_0x85b4[6])[_0x85b4[14]];var Company=require(_0x85b4[6])[_0x85b4[15]];var Attachment=require(_0x85b4[6])[_0x85b4[16]];var ReportMail=require(_0x85b4[6])[_0x85b4[9]];var ReportMailRoom=require(_0x85b4[6])[_0x85b4[17]];var ReportMailSession=require(_0x85b4[6])[_0x85b4[11]];var Promise=require(_0x85b4[18]);var moment=require(_0x85b4[19]);var open=Promise[_0x85b4[22]](require(_0x85b4[21])[_0x85b4[20]]);var close=Promise[_0x85b4[22]](require(_0x85b4[21])[_0x85b4[23]]);var write=Promise[_0x85b4[22]](require(_0x85b4[21])[_0x85b4[24]]);var logger=require(_0x85b4[26])(_0x85b4[25]);var config=require(_0x85b4[27]);var Util=require(_0x85b4[28]);var processes=[];ReportMail[_0x85b4[49]](function(_0xb379x1d,_0xb379x1e){var _0xb379x1f=_0xb379x1d[_0x85b4[29]]({plain:true});if(_0xb379x1d[_0x85b4[31]](_0x85b4[30])){return Session[_0x85b4[46]]({memberid:_0xb379x1f[_0x85b4[42]],membername:_0xb379x1f[_0x85b4[38]],leaveAt:moment()[_0x85b4[44]](_0x85b4[43])},{where:{uniqueid:_0xb379x1f[_0x85b4[45]],leaveAt:null},individualHooks:true})[_0x85b4[41]](function(){var _0xb379x21=_[_0x85b4[36]](processes,{id:_0xb379x1f[_0x85b4[35]],channel:_0x85b4[25]});if(_0xb379x21){_0xb379x21[_0x85b4[40]][_0x85b4[39]]({type:_0x85b4[37],membername:_0xb379x1f[_0x85b4[38]]})}})[_0x85b4[34]](function(_0xb379x20){logger[_0x85b4[33]](_0x85b4[32],_0xb379x20)})}else {if(_0xb379x1d[_0x85b4[31]](_0x85b4[47])){var _0xb379x21=_[_0x85b4[36]](processes,{id:_0xb379x1f[_0x85b4[35]],channel:_0x85b4[25]});if(_0xb379x21){_0xb379x21[_0x85b4[40]][_0x85b4[39]]({type:_0x85b4[48],id:_0xb379x1f[_0x85b4[42]],membername:_0xb379x1f[_0x85b4[38]]})}}}});function handleMessage(msg,_0xb379x23){var _0xb379x24;var _0xb379x25;var _0xb379x26;var _0xb379x27;var _0xb379x28;var _0xb379x29,_0xb379x2a,_0xb379x2b,_0xb379x2c;if(msg[_0x85b4[50]]){return Message[_0x85b4[96]]({where:{messageId:msg[_0x85b4[50]][0],accountId:msg[_0x85b4[97]]}})[_0x85b4[41]](function(_0xb379x36){if(_0xb379x36){return _0xb379x36[_0x85b4[102]]()[_0x85b4[41]](function(_0xb379x35){_0xb379x24= _0xb379x35;if(_0xb379x35[_0x85b4[89]]!== _0x85b4[90]){return _0xb379x24[_0x85b4[46]]({status:_0x85b4[99],openReason:_0x85b4[100],waiting:true},{individualHooks:true})[_0x85b4[41]](function(){return Account[_0x85b4[98]](msg[_0x85b4[97]])[_0x85b4[41]](function(_0xb379x38){_0xb379x26= _0xb379x38;if(_0xb379x26[_0x85b4[92]]){return Company[_0x85b4[96]]({where:{emailDomain:msg[_0x85b4[79]][0][_0x85b4[80]][_0x85b4[94]](_0x85b4[93])[1]}})[_0x85b4[41]](function(_0xb379x39){return Contact[_0x85b4[95]]({where:{email:msg[_0x85b4[79]][0][_0x85b4[80]]},defaults:{email:msg[_0x85b4[79]][0][_0x85b4[80]],firstName:msg[_0x85b4[79]][0][_0x85b4[87]]|| msg[_0x85b4[79]][0][_0x85b4[80]][_0x85b4[94]](_0x85b4[93])[0],ListId:_0xb379x26[_0x85b4[92]],CompanyId:_0xb379x39?_0xb379x39[_0x85b4[71]]:null}})})}else {return []}})[_0x85b4[91]](function(_0xb379x37){_0xb379x27= _0xb379x37})})}else {return Account[_0x85b4[98]](msg[_0x85b4[97]])[_0x85b4[41]](function(_0xb379x38){_0xb379x26= _0xb379x38;if(_0xb379x26[_0x85b4[92]]){return Company[_0x85b4[96]]({where:{emailDomain:msg[_0x85b4[79]][0][_0x85b4[80]][_0x85b4[94]](_0x85b4[93])[1]}})[_0x85b4[41]](function(_0xb379x39){return Contact[_0x85b4[95]]({where:{email:msg[_0x85b4[79]][0][_0x85b4[80]]},defaults:{email:msg[_0x85b4[79]][0][_0x85b4[80]],firstName:msg[_0x85b4[79]][0][_0x85b4[87]]|| msg[_0x85b4[79]][0][_0x85b4[80]][_0x85b4[94]](_0x85b4[93])[0],ListId:_0xb379x26[_0x85b4[92]],CompanyId:_0xb379x39?_0xb379x39[_0x85b4[71]]:null}})})}else {return []}})[_0x85b4[91]](function(_0xb379x37){_0xb379x27= _0xb379x37;return Room[_0x85b4[72]]({subject:msg[_0x85b4[78]],from:_[_0x85b4[81]](msg[_0x85b4[79]],_0x85b4[80])[_0x85b4[69]](_0x85b4[101]),account:_0xb379x26[_0x85b4[87]],attachment:msg[_0x85b4[53]]&& msg[_0x85b4[53]][_0x85b4[54]],lastEvent:_0x85b4[77],lastEventAt:moment()[_0x85b4[44]](_0x85b4[43]),arrivedAt:moment()[_0x85b4[44]](_0x85b4[43]),waiting:true,MailAccountId:_0xb379x26[_0x85b4[71]],ParentId:_0xb379x35[_0x85b4[71]]})})[_0x85b4[41]](function(_0xb379x35){_0xb379x24= _0xb379x35})}})}else {return Account[_0x85b4[98]](msg[_0x85b4[97]])[_0x85b4[41]](function(_0xb379x38){_0xb379x26= _0xb379x38;if(_0xb379x26[_0x85b4[92]]){return Company[_0x85b4[96]]({where:{emailDomain:msg[_0x85b4[79]][0][_0x85b4[80]][_0x85b4[94]](_0x85b4[93])[1]}})[_0x85b4[41]](function(_0xb379x39){return Contact[_0x85b4[95]]({where:{email:msg[_0x85b4[79]][0][_0x85b4[80]]},defaults:{email:msg[_0x85b4[79]][0][_0x85b4[80]],firstName:msg[_0x85b4[79]][0][_0x85b4[87]]|| msg[_0x85b4[79]][0][_0x85b4[80]][_0x85b4[94]](_0x85b4[93])[0],ListId:_0xb379x26[_0x85b4[92]],CompanyId:_0xb379x39?_0xb379x39[_0x85b4[71]]:null}})})}else {return []}})[_0x85b4[91]](function(_0xb379x37){_0xb379x27= _0xb379x37;return Room[_0x85b4[72]]({subject:msg[_0x85b4[78]],from:_[_0x85b4[81]](msg[_0x85b4[79]],_0x85b4[80])[_0x85b4[69]](_0x85b4[101]),account:_0xb379x26[_0x85b4[87]],attachment:msg[_0x85b4[53]]&& msg[_0x85b4[53]][_0x85b4[54]],lastEvent:_0x85b4[77],waiting:true,lastEventAt:moment()[_0x85b4[44]](_0x85b4[43]),arrivedAt:moment()[_0x85b4[44]](_0x85b4[43]),MailAccountId:_0xb379x26[_0x85b4[71]]})})[_0x85b4[41]](function(_0xb379x35){_0xb379x24= _0xb379x35})}})[_0x85b4[41]](function(){return _0xb379x24[_0x85b4[46]]({lastEvent:_0x85b4[77],mailIn:++_0xb379x24[_0x85b4[88]]})})[_0x85b4[41]](function(_0xb379x35){return Message[_0x85b4[72]]({fromId:_0xb379x27?_0xb379x27[_0x85b4[71]]:null,messageId:msg[_0x85b4[76]],status:_0x85b4[77],subject:msg[_0x85b4[78]],from:_[_0x85b4[81]](msg[_0x85b4[79]],_0x85b4[80]),to:msg[_0x85b4[82]]?_[_0x85b4[81]](msg[_0x85b4[82]],_0x85b4[80]):[],cc:msg[_0x85b4[83]]?_[_0x85b4[81]](msg[_0x85b4[83]],_0x85b4[80]):[],bcc:msg[_0x85b4[84]]?_[_0x85b4[81]](msg[_0x85b4[84]],_0x85b4[80]):[],text:msg[_0x85b4[85]]|| null,html:msg[_0x85b4[86]]|| null,MailRoomId:_0xb379x24[_0x85b4[71]],accountName:_0xb379x26[_0x85b4[87]],accountId:_0xb379x26[_0x85b4[71]],inReplyTo:msg[_0x85b4[50]][0]})})[_0x85b4[41]](function(_0xb379x2d){var _0xb379x2e=[];var _0xb379x2f=_0xb379x2d;_0xb379x23[_0x85b4[39]]({message:_0x85b4[52],doc:_0xb379x2d});createAndStartRouting(_0xb379x24,msg,_0xb379x2d[_0x85b4[29]]({plain:true}),_0xb379x26);if(msg[_0x85b4[53]]&& msg[_0x85b4[53]][_0x85b4[54]]){msg[_0x85b4[53]][_0x85b4[74]](function(_0xb379x30){var _0xb379x31=_0x85b4[55]+ Math[_0x85b4[56]](32);var _0xb379x32;_0xb379x2e[_0x85b4[73]](Attachment[_0x85b4[72]]({name:_0xb379x30[_0x85b4[59]],basename:_0xb379x31,path:path[_0x85b4[69]](config[_0x85b4[65]],_0x85b4[66],_0x85b4[67],_0x85b4[53],_0x85b4[68],_0xb379x31),type:_0xb379x30[_0x85b4[70]],size:_0xb379x30[_0x85b4[54]],MailMessageId:_0xb379x2f[_0x85b4[71]]})[_0x85b4[41]](function(_0xb379x34){return open(_0xb379x34[_0x85b4[3]],_0x85b4[64])})[_0x85b4[41]](function(_0xb379x33){_0xb379x32= _0xb379x33;return write(_0xb379x32, new Buffer(_0xb379x30[_0x85b4[63]][_0x85b4[62]]),0,_0xb379x30[_0x85b4[54]])})[_0x85b4[41]](function(){return close(_0xb379x32)})[_0x85b4[41]](function(){logger[_0x85b4[61]](_0x85b4[58],_0xb379x30[_0x85b4[59]],_0x85b4[60])})[_0x85b4[34]](function(_0xb379x20){logger[_0x85b4[33]](_0x85b4[57],_0xb379x20[_0x85b4[51]])}))})};return Promise[_0x85b4[75]](_0xb379x2e)})[_0x85b4[34]](function(_0xb379x20){logger[_0x85b4[33]](_0xb379x20[_0x85b4[51]])})}else {return Account[_0x85b4[98]](msg[_0x85b4[97]])[_0x85b4[41]](function(_0xb379x38){_0xb379x26= _0xb379x38;if(_0xb379x26[_0x85b4[92]]){return Company[_0x85b4[96]]({where:{emailDomain:msg[_0x85b4[79]][0][_0x85b4[80]][_0x85b4[94]](_0x85b4[93])[1]}})[_0x85b4[41]](function(_0xb379x39){return Contact[_0x85b4[95]]({where:{email:msg[_0x85b4[79]][0][_0x85b4[80]]},defaults:{email:msg[_0x85b4[79]][0][_0x85b4[80]],firstName:msg[_0x85b4[79]][0][_0x85b4[87]]|| msg[_0x85b4[79]][0][_0x85b4[80]][_0x85b4[94]](_0x85b4[93])[0],ListId:_0xb379x26[_0x85b4[92]],CompanyId:_0xb379x39?_0xb379x39[_0x85b4[71]]:null}})})}else {return []}})[_0x85b4[91]](function(_0xb379x37){_0xb379x27= _0xb379x37;return Room[_0x85b4[72]]({mailIn:1,account:_0xb379x26[_0x85b4[87]],subject:msg[_0x85b4[78]],from:_[_0x85b4[81]](msg[_0x85b4[79]],_0x85b4[80])[_0x85b4[69]](_0x85b4[101]),status:_0x85b4[104],lastEvent:_0x85b4[77],lastEventAt:moment()[_0x85b4[44]](_0x85b4[43]),arrivedAt:moment()[_0x85b4[44]](_0x85b4[43]),attachment:msg[_0x85b4[53]]&& msg[_0x85b4[53]][_0x85b4[54]],waiting:true,MailMessages:[{messageId:msg[_0x85b4[76]],subject:msg[_0x85b4[78]],from:_[_0x85b4[81]](msg[_0x85b4[79]],_0x85b4[80]),fromId:_0xb379x27?_0xb379x27[_0x85b4[71]]:null,to:msg[_0x85b4[82]]?_[_0x85b4[81]](msg[_0x85b4[82]],_0x85b4[80]):[],cc:msg[_0x85b4[83]]?_[_0x85b4[81]](msg[_0x85b4[83]],_0x85b4[80]):[],bcc:msg[_0x85b4[84]]?_[_0x85b4[81]](msg[_0x85b4[84]],_0x85b4[80]):[],status:_0x85b4[77],text:msg[_0x85b4[85]]|| null,html:msg[_0x85b4[86]]|| null,accountName:_0xb379x26[_0x85b4[87]],accountId:_0xb379x26[_0x85b4[71]]}],MailAccountId:msg[_0x85b4[97]]},{include:[{model:Message}]})})[_0x85b4[41]](function(_0xb379x3a){var _0xb379x2e=[];var _0xb379x3b=_0xb379x3a;_0xb379x23[_0x85b4[39]]({message:_0x85b4[52],doc:_0xb379x3a[_0x85b4[103]][0]});createAndStartRouting(_0xb379x3b,msg,_0xb379x3b[_0x85b4[103]][0][_0x85b4[29]]({plain:true}),_0xb379x26);if(msg[_0x85b4[53]]&& msg[_0x85b4[53]][_0x85b4[54]]){msg[_0x85b4[53]][_0x85b4[74]](function(_0xb379x30){var _0xb379x31=_0x85b4[55]+ Math[_0x85b4[56]](32);var _0xb379x32;_0xb379x2e[_0x85b4[73]](Attachment[_0x85b4[72]]({name:_0xb379x30[_0x85b4[59]],basename:_0xb379x31,path:path[_0x85b4[69]](config[_0x85b4[65]],_0x85b4[66],_0x85b4[67],_0x85b4[53],_0x85b4[68],_0xb379x31),type:_0xb379x30[_0x85b4[70]],size:_0xb379x30[_0x85b4[54]],MailMessageId:_0xb379x3b[_0x85b4[103]][0][_0x85b4[71]]})[_0x85b4[41]](function(_0xb379x34){return open(_0xb379x34[_0x85b4[3]],_0x85b4[64])})[_0x85b4[41]](function(_0xb379x33){_0xb379x32= _0xb379x33;return write(_0xb379x32, new Buffer(_0xb379x30[_0x85b4[63]][_0x85b4[62]]),0,_0xb379x30[_0x85b4[54]])})[_0x85b4[41]](function(){return close(_0xb379x32)})[_0x85b4[41]](function(){logger[_0x85b4[61]](_0x85b4[58],_0xb379x30[_0x85b4[59]],_0x85b4[60])})[_0x85b4[34]](function(_0xb379x20){logger[_0x85b4[33]](_0x85b4[57],_0xb379x20[_0x85b4[51]])}))})};return Promise[_0x85b4[75]](_0xb379x2e)})[_0x85b4[34]](function(_0xb379x20){logger[_0x85b4[33]](_0xb379x20[_0x85b4[51]])})}}function handleState(_0xb379x3d,_0xb379x1f){return ms[_0x85b4[98]](_0xb379x3d)[_0x85b4[41]](function(_0xb379x3e){return _0xb379x3e[_0x85b4[46]]({state:_0xb379x1f[_0x85b4[106]],source:_0xb379x1f[_0x85b4[107]]|| null})})[_0x85b4[34]](function(_0xb379x20){logger[_0x85b4[33]](_0x85b4[105],_0xb379x20[_0x85b4[51]])})}function fork(_0xb379x3d,_0xb379x40,_0xb379x23){return cp[_0x85b4[115]](__dirname+ _0x85b4[114],[_0xb379x3d,_0xb379x40])[_0x85b4[109]](_0x85b4[111],function(_0xb379x1f){switch(_0xb379x1f[_0x85b4[113]]){case _0x85b4[112]:handleMessage(_0xb379x1f,_0xb379x23);break;case _0x85b4[106]:handleState(_0xb379x3d,_0xb379x1f);break;default:}})[_0x85b4[109]](_0x85b4[23],function(_0xb379x41){logger[_0x85b4[61]](util[_0x85b4[44]](_0x85b4[110],_0xb379x40,_0xb379x41))})[_0x85b4[109]](_0x85b4[33],function(_0xb379x20){logger[_0x85b4[33]](_0x85b4[108],_0xb379x20[_0x85b4[51]])})}function execRequest(_0xb379x1d,_0xb379x43,_0xb379x44){Util[_0x85b4[119]](_0xb379x1d,_0xb379x43,_0xb379x44)[_0x85b4[41]](function(_0xb379x45){logger[_0x85b4[61]](_0x85b4[118])})[_0x85b4[34]](function(_0xb379x20){logger[_0x85b4[117]](_0x85b4[116])})}function webhook(_0xb379x1d,_0xb379x47,_0xb379x48){var _0xb379x49=_0xb379x47;switch(_0xb379x48){case _0x85b4[128]:if(_0xb379x49[_0x85b4[120]]&& _0xb379x49[_0x85b4[121]]){logger[_0x85b4[61]](_0x85b4[122]+ _0xb379x49[_0x85b4[87]]+ _0x85b4[123]);execRequest(_0xb379x1d[_0x85b4[124]],_0xb379x49[_0x85b4[120]],_0xb379x49[_0x85b4[121]])};if(_0xb379x49[_0x85b4[125]][_0x85b4[54]]){_[_0x85b4[74]](_0xb379x49[_0x85b4[125]],function(_0xb379x4a){if(_0xb379x4a[_0x85b4[126]]){Util[_0x85b4[127]](_0xb379x4a,_0xb379x1d)}})};break;case _0x85b4[48]:if(_0xb379x49[_0x85b4[129]]&& _0xb379x49[_0x85b4[130]]){logger[_0x85b4[61]](_0x85b4[122]+ _0xb379x49[_0x85b4[87]]+ _0x85b4[131]);execRequest(_0xb379x1d[_0x85b4[124]],_0xb379x49[_0x85b4[129]],_0xb379x49[_0x85b4[130]])};break;case _0x85b4[23]:if(_0xb379x49[_0x85b4[132]]&& _0xb379x49[_0x85b4[133]]){logger[_0x85b4[61]](_0x85b4[122]+ _0xb379x49[_0x85b4[87]]+ _0x85b4[134]);execRequest(_0xb379x1d[_0x85b4[124]],_0xb379x49[_0x85b4[132]],_0xb379x49[_0x85b4[133]])};break;default:logger[_0x85b4[33]](_0x85b4[135])}}function synch(_0xb379x4c,_0xb379x4d){Account[_0x85b4[140]](function(_0xb379x1d){var _0xb379x47=_[_0x85b4[36]](_0xb379x4c,{id:_0xb379x1d[_0x85b4[71]]});if(_0xb379x47&& _0xb379x47[_0x85b4[5]]){if(_0xb379x4d[_0xb379x47[_0x85b4[5]][_0x85b4[71]]]){logger[_0x85b4[61]](util[_0x85b4[44]](_0x85b4[136],_0xb379x47[_0x85b4[5]][_0x85b4[71]],_0xb379x4d[_0xb379x47[_0x85b4[5]][_0x85b4[71]]][_0x85b4[137]]));_0xb379x4d[_0xb379x47[_0x85b4[5]][_0x85b4[71]]][_0x85b4[138]]();_0xb379x4d[_0xb379x47[_0x85b4[5]][_0x85b4[71]]]= null};_[_0x85b4[139]](_0xb379x4c,{id:_0xb379x1d[_0x85b4[71]]})}});Account[_0x85b4[141]](function(_0xb379x1d){_0xb379x4c[_0x85b4[73]](_0xb379x1d)});Account[_0x85b4[49]](function(_0xb379x1d){var _0xb379x4e=_[_0x85b4[36]](_0xb379x4c,{id:_0xb379x1d[_0x85b4[71]]});if(_0xb379x4e){logger[_0x85b4[61]](_0x85b4[142]+ _0xb379x4e[_0x85b4[87]]+ _0x85b4[143]);_[_0x85b4[144]](_0xb379x4e,_0xb379x1d)}else {_0xb379x4c[_0x85b4[145]](_0xb379x1d)}})}function createAndStartRouting(_0xb379x3a,_0xb379x50,_0xb379x2d,_0xb379x47){var _0xb379x51=cp[_0x85b4[115]](path[_0x85b4[69]](config[_0x85b4[65]],_0x85b4[150]))[_0x85b4[109]](_0x85b4[111],function(msg){switch(msg[_0x85b4[113]]){case _0x85b4[148]:return Message[_0x85b4[72]](msg[_0x85b4[112]],{include:[{model:Attachment}]});case _0x85b4[149]:return SmsMessage[_0x85b4[72]](msg[_0x85b4[112]]);default:}})[_0x85b4[109]](_0x85b4[146],function(){var _0xb379x52=_[_0x85b4[139]](processes,{pid:this[_0x85b4[137]]});if(_0xb379x52&& _0xb379x52[_0x85b4[54]]){return Room[_0x85b4[98]](_0xb379x52[0][_0x85b4[147]])[_0x85b4[41]](function(_0xb379x3a){if(_0xb379x3a){return _0xb379x3a[_0x85b4[46]]({waiting:false})}})}});_0xb379x51[_0x85b4[39]]({type:_0x85b4[151],param1:{channel:_0x85b4[25],uniqueid:util[_0x85b4[44]](_0x85b4[152],moment()[_0x85b4[153]](),_0xb379x3a[_0x85b4[71]]),subject:_0xb379x50[_0x85b4[78]],messageid:_0xb379x2d[_0x85b4[71]],roomid:_0xb379x3a[_0x85b4[71]],accountid:_0xb379x47[_0x85b4[71]],accountname:_0xb379x47[_0x85b4[87]],accountaddress:_0xb379x47[_0x85b4[80]],from:_0xb379x50[_0x85b4[79]][0][_0x85b4[80]],cc:_0xb379x50[_0x85b4[83]]?_[_0x85b4[81]](_0xb379x50[_0x85b4[83]],_0x85b4[80]):[]},param2:_0xb379x2d});processes[_0x85b4[73]]({id:_0xb379x2d[_0x85b4[71]],channel:_0x85b4[25],process:_0xb379x51,roomid:_0xb379x3a[_0x85b4[71]],pid:_0xb379x51[_0x85b4[137]]})}module[_0x85b4[154]]= function(_0xb379x23){var _0xb379x4d={};var _0xb379x4c;var _0xb379x53;process[_0x85b4[109]](_0x85b4[146],function(_0xb379x41){for(var _0xb379x54 in _0xb379x4d){if(_0xb379x4d[_0xb379x54]){_0xb379x4d[_0xb379x54][_0x85b4[138]]()}}});Account[_0x85b4[158]]({include:[ms]})[_0x85b4[41]](function(_0xb379x55){_0xb379x4c= _0xb379x55;synch(_0xb379x4c,_0xb379x4d);_0xb379x4c[_0x85b4[74]](function(_0xb379x47){if(_0xb379x47[_0x85b4[5]]){_0xb379x4d[_0xb379x47[_0x85b4[5]][_0x85b4[71]]]= fork(_0xb379x47[_0x85b4[5]][_0x85b4[71]],_0xb379x47[_0x85b4[5]][_0x85b4[155]],_0xb379x23)}});ReportMail[_0x85b4[49]](function(_0xb379x1d){var _0xb379x47=_[_0x85b4[36]](_0xb379x4c,{id:parseInt(_0xb379x1d[_0x85b4[156]])});if(_0xb379x47&& _0xb379x1d[_0x85b4[31]](_0x85b4[30])){webhook(_0xb379x1d,_0xb379x47,_0x85b4[128])};if(_0xb379x47&& _0xb379x1d[_0x85b4[31]](_0x85b4[47])){webhook(_0xb379x1d,_0xb379x47,_0x85b4[48])}});Room[_0x85b4[49]](function(_0xb379x1d){var _0xb379x47=_[_0x85b4[36]](_0xb379x4c,{id:_0xb379x1d[_0x85b4[157]]});if(_0xb379x47&& _0xb379x1d[_0x85b4[31]](_0x85b4[89])&& _0xb379x1d[_0x85b4[89]]=== _0x85b4[90]){webhook(_0xb379x1d,_0xb379x47,_0x85b4[23])}})})[_0x85b4[34]](function(_0xb379x20){logger[_0x85b4[33]](_0xb379x20[_0x85b4[51]])});ms[_0x85b4[141]](function(_0xb379x3e){var _0xb379x47=_[_0x85b4[36]](_0xb379x4c,{id:_0xb379x3e[_0x85b4[157]]});if(_0xb379x47){_0xb379x47[_0x85b4[5]]= _0xb379x3e};_0xb379x4d[_0xb379x3e[_0x85b4[71]]]= fork(_0xb379x3e[_0x85b4[71]],_0xb379x3e[_0x85b4[155]],_0xb379x23)});ms[_0x85b4[49]](function(_0xb379x3e){if(_0xb379x4d[_0xb379x3e[_0x85b4[71]]]){if(_0xb379x3e[_0x85b4[31]](_0x85b4[106])|| _0xb379x3e[_0x85b4[31]](_0x85b4[107])){logger[_0x85b4[61]](util[_0x85b4[44]](_0x85b4[159],_0xb379x3e[_0x85b4[71]],_0xb379x4d[_0xb379x3e[_0x85b4[71]]][_0x85b4[137]]))}else {_0xb379x4d[_0xb379x3e[_0x85b4[71]]][_0x85b4[138]]();_0xb379x4d[_0xb379x3e[_0x85b4[71]]]= null;_0xb379x4d[_0xb379x3e[_0x85b4[71]]]= fork(_0xb379x3e[_0x85b4[71]],_0xb379x3e[_0x85b4[155]],_0xb379x23)}}});ms[_0x85b4[140]](function(_0xb379x3e){if(_0xb379x4d[_0xb379x3e[_0x85b4[71]]]){logger[_0x85b4[61]](util[_0x85b4[44]](_0x85b4[136],_0xb379x3e[_0x85b4[71]],_0xb379x4d[_0xb379x3e[_0x85b4[71]]][_0x85b4[137]]));_0xb379x4d[_0xb379x3e[_0x85b4[71]]][_0x85b4[138]]();_0xb379x4d[_0xb379x3e[_0x85b4[71]]]= null}})}