515a583f25fd136aa71878d79f8af3fc9d896756
[motion.git] / server / config / imap / index.js
1 var _0x17c3=["\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"];_0x17c3[0];var _=require(_0x17c3[1]);var util=require(_0x17c3[2]);var path=require(_0x17c3[3]);var cp=require(_0x17c3[4]);var moment=require(_0x17c3[5]);var kue=require(_0x17c3[6]);var Promise=require(_0x17c3[7]);var ms=require(_0x17c3[9])[_0x17c3[8]];var msg=require(_0x17c3[9])[_0x17c3[10]];var Room=require(_0x17c3[9])[_0x17c3[11]];var Report=require(_0x17c3[9])[_0x17c3[12]];var Status=require(_0x17c3[9])[_0x17c3[13]];var Session=require(_0x17c3[9])[_0x17c3[14]];var Message=require(_0x17c3[9])[_0x17c3[10]];var SmsMessage=require(_0x17c3[9])[_0x17c3[15]];var Account=require(_0x17c3[9])[_0x17c3[16]];var Setting=require(_0x17c3[9])[_0x17c3[17]];var Contact=require(_0x17c3[9])[_0x17c3[18]];var Company=require(_0x17c3[9])[_0x17c3[19]];var Attachment=require(_0x17c3[9])[_0x17c3[20]];var open=Promise[_0x17c3[23]](require(_0x17c3[22])[_0x17c3[21]]);var close=Promise[_0x17c3[23]](require(_0x17c3[22])[_0x17c3[24]]);var write=Promise[_0x17c3[23]](require(_0x17c3[22])[_0x17c3[25]]);var logger=require(_0x17c3[27])(_0x17c3[26]);var config=require(_0x17c3[28]);var Util=require(_0x17c3[29]);var queue=kue[_0x17c3[30]]();var processes=[];var ami;Report[_0x17c3[51]](function(_0x3290x1e,_0x3290x1f){var _0x3290x20=_0x3290x1e[_0x17c3[31]]({plain:true});if(_0x3290x1e[_0x17c3[33]](_0x17c3[32])){return Session[_0x17c3[48]]({memberid:_0x3290x20[_0x17c3[44]],membername:_0x3290x20[_0x17c3[40]],leaveAt:moment()[_0x17c3[46]](_0x17c3[45])},{where:{uniqueid:_0x3290x20[_0x17c3[47]],leaveAt:null},individualHooks:true})[_0x17c3[43]](function(){var _0x3290x22=_[_0x17c3[38]](processes,{id:_0x3290x20[_0x17c3[37]],channel:_0x17c3[26]});if(_0x3290x22){_0x3290x22[_0x17c3[42]][_0x17c3[41]]({type:_0x17c3[39],membername:_0x3290x20[_0x17c3[40]]})}})[_0x17c3[36]](function(_0x3290x21){logger[_0x17c3[35]](_0x17c3[34],_0x3290x21)})}else {if(_0x3290x1e[_0x17c3[33]](_0x17c3[49])){var _0x3290x22=_[_0x17c3[38]](processes,{id:_0x3290x20[_0x17c3[37]],channel:_0x17c3[26]});if(_0x3290x22){_0x3290x22[_0x17c3[42]][_0x17c3[41]]({type:_0x17c3[50],id:_0x3290x20[_0x17c3[44]],membername:_0x3290x20[_0x17c3[40]]})}}}});function handleMessage(msg){var _0x3290x24;var _0x3290x25;var _0x3290x26;var _0x3290x27;var _0x3290x28;var _0x3290x29,_0x3290x2a,_0x3290x2b,_0x3290x2c;if(msg[_0x17c3[52]]){return Message[_0x17c3[101]]({where:{messageId:msg[_0x17c3[52]][0],accountId:msg[_0x17c3[102]]}})[_0x17c3[43]](function(_0x3290x36){if(_0x3290x36){return _0x3290x36[_0x17c3[105]]()[_0x17c3[43]](function(_0x3290x35){_0x3290x24= _0x3290x35;if(_0x3290x35[_0x17c3[91]]!== _0x17c3[92]){var _0x3290x37={openReason:_0x17c3[93],waiting:true};if(_0x3290x35[_0x17c3[91]]!== _0x17c3[94]){_0x3290x37[_0x17c3[91]]= _0x17c3[95]};return _0x3290x24[_0x17c3[48]](_0x3290x37,{individualHooks:true})[_0x17c3[43]](function(){return Account[_0x17c3[103]](msg[_0x17c3[102]])[_0x17c3[43]](function(_0x3290x39){_0x3290x26= _0x3290x39;if(_0x3290x26[_0x17c3[97]]){return Company[_0x17c3[101]]({where:{emailDomain:msg[_0x17c3[81]][0][_0x17c3[82]][_0x17c3[99]](_0x17c3[98])[1]}})[_0x17c3[43]](function(_0x3290x3a){return Contact[_0x17c3[100]]({where:{email:msg[_0x17c3[81]][0][_0x17c3[82]]},defaults:{email:msg[_0x17c3[81]][0][_0x17c3[82]],firstName:msg[_0x17c3[81]][0][_0x17c3[89]]|| msg[_0x17c3[81]][0][_0x17c3[82]][_0x17c3[99]](_0x17c3[98])[0],ListId:_0x3290x26[_0x17c3[97]],CompanyId:_0x3290x3a?_0x3290x3a[_0x17c3[73]]:null}})})}else {return []}})[_0x17c3[96]](function(_0x3290x38){_0x3290x27= _0x3290x38})})}else {return Account[_0x17c3[103]](msg[_0x17c3[102]])[_0x17c3[43]](function(_0x3290x39){_0x3290x26= _0x3290x39;if(_0x3290x26[_0x17c3[97]]){return Company[_0x17c3[101]]({where:{emailDomain:msg[_0x17c3[81]][0][_0x17c3[82]][_0x17c3[99]](_0x17c3[98])[1]}})[_0x17c3[43]](function(_0x3290x3a){return Contact[_0x17c3[100]]({where:{email:msg[_0x17c3[81]][0][_0x17c3[82]]},defaults:{email:msg[_0x17c3[81]][0][_0x17c3[82]],firstName:msg[_0x17c3[81]][0][_0x17c3[89]]|| msg[_0x17c3[81]][0][_0x17c3[82]][_0x17c3[99]](_0x17c3[98])[0],ListId:_0x3290x26[_0x17c3[97]],CompanyId:_0x3290x3a?_0x3290x3a[_0x17c3[73]]:null}})})}else {return []}})[_0x17c3[96]](function(_0x3290x38){_0x3290x27= _0x3290x38;return Room[_0x17c3[74]]({subject:msg[_0x17c3[80]],from:_[_0x17c3[83]](msg[_0x17c3[81]],_0x17c3[82])[_0x17c3[71]](_0x17c3[104]),account:_0x3290x26[_0x17c3[89]],attachment:msg[_0x17c3[55]]&& msg[_0x17c3[55]][_0x17c3[56]],lastEvent:_0x17c3[79],lastEventAt:moment()[_0x17c3[46]](_0x17c3[45]),arrivedAt:moment()[_0x17c3[46]](_0x17c3[45]),waiting:true,MailAccountId:_0x3290x26[_0x17c3[73]],ParentId:_0x3290x35[_0x17c3[73]]})})[_0x17c3[43]](function(_0x3290x35){_0x3290x24= _0x3290x35})}})}else {return Account[_0x17c3[103]](msg[_0x17c3[102]])[_0x17c3[43]](function(_0x3290x39){_0x3290x26= _0x3290x39;if(_0x3290x26[_0x17c3[97]]){return Company[_0x17c3[101]]({where:{emailDomain:msg[_0x17c3[81]][0][_0x17c3[82]][_0x17c3[99]](_0x17c3[98])[1]}})[_0x17c3[43]](function(_0x3290x3a){return Contact[_0x17c3[100]]({where:{email:msg[_0x17c3[81]][0][_0x17c3[82]]},defaults:{email:msg[_0x17c3[81]][0][_0x17c3[82]],firstName:msg[_0x17c3[81]][0][_0x17c3[89]]|| msg[_0x17c3[81]][0][_0x17c3[82]][_0x17c3[99]](_0x17c3[98])[0],ListId:_0x3290x26[_0x17c3[97]],CompanyId:_0x3290x3a?_0x3290x3a[_0x17c3[73]]:null}})})}else {return []}})[_0x17c3[96]](function(_0x3290x38){_0x3290x27= _0x3290x38;return Room[_0x17c3[74]]({subject:msg[_0x17c3[80]],from:_[_0x17c3[83]](msg[_0x17c3[81]],_0x17c3[82])[_0x17c3[71]](_0x17c3[104]),account:_0x3290x26[_0x17c3[89]],attachment:msg[_0x17c3[55]]&& msg[_0x17c3[55]][_0x17c3[56]],lastEvent:_0x17c3[79],waiting:true,lastEventAt:moment()[_0x17c3[46]](_0x17c3[45]),arrivedAt:moment()[_0x17c3[46]](_0x17c3[45]),MailAccountId:_0x3290x26[_0x17c3[73]]})})[_0x17c3[43]](function(_0x3290x35){_0x3290x24= _0x3290x35})}})[_0x17c3[43]](function(){return _0x3290x24[_0x17c3[48]]({lastEvent:_0x17c3[79],mailIn:++_0x3290x24[_0x17c3[90]]})})[_0x17c3[43]](function(_0x3290x35){return Message[_0x17c3[74]]({fromId:_0x3290x27?_0x3290x27[_0x17c3[73]]:null,messageId:msg[_0x17c3[78]],status:_0x17c3[79],subject:msg[_0x17c3[80]],from:_[_0x17c3[83]](msg[_0x17c3[81]],_0x17c3[82]),to:msg[_0x17c3[84]]?_[_0x17c3[83]](msg[_0x17c3[84]],_0x17c3[82]):[],cc:msg[_0x17c3[85]]?_[_0x17c3[83]](msg[_0x17c3[85]],_0x17c3[82]):[],bcc:msg[_0x17c3[86]]?_[_0x17c3[83]](msg[_0x17c3[86]],_0x17c3[82]):[],text:msg[_0x17c3[87]]|| null,html:msg[_0x17c3[88]]|| null,MailRoomId:_0x3290x24[_0x17c3[73]],accountName:_0x3290x26[_0x17c3[89]],accountId:_0x3290x26[_0x17c3[73]],inReplyTo:msg[_0x17c3[52]][0]})})[_0x17c3[43]](function(_0x3290x2d){var _0x3290x2e=[];var _0x3290x2f=_0x3290x2d;if(ami){ami[_0x17c3[41]]({message:_0x17c3[54],doc:_0x3290x2d})};createAndStartRouting(_0x3290x24,msg,_0x3290x2d[_0x17c3[31]]({plain:true}),_0x3290x26);if(msg[_0x17c3[55]]&& msg[_0x17c3[55]][_0x17c3[56]]){msg[_0x17c3[55]][_0x17c3[76]](function(_0x3290x30){var _0x3290x31=_0x17c3[57]+ Math[_0x17c3[58]](32);var _0x3290x32;_0x3290x2e[_0x17c3[75]](Attachment[_0x17c3[74]]({name:_0x3290x30[_0x17c3[61]],basename:_0x3290x31,path:path[_0x17c3[71]](config[_0x17c3[67]],_0x17c3[68],_0x17c3[69],_0x17c3[55],_0x17c3[70],_0x3290x31),type:_0x3290x30[_0x17c3[72]],size:_0x3290x30[_0x17c3[56]],MailMessageId:_0x3290x2f[_0x17c3[73]]})[_0x17c3[43]](function(_0x3290x34){return open(_0x3290x34[_0x17c3[3]],_0x17c3[66])})[_0x17c3[43]](function(_0x3290x33){_0x3290x32= _0x3290x33;return write(_0x3290x32, new Buffer(_0x3290x30[_0x17c3[65]][_0x17c3[64]]),0,_0x3290x30[_0x17c3[56]])})[_0x17c3[43]](function(){return close(_0x3290x32)})[_0x17c3[43]](function(){logger[_0x17c3[63]](_0x17c3[60],_0x3290x30[_0x17c3[61]],_0x17c3[62])})[_0x17c3[36]](function(_0x3290x21){logger[_0x17c3[35]](_0x17c3[59],_0x3290x21[_0x17c3[53]])}))})};return Promise[_0x17c3[77]](_0x3290x2e)})[_0x17c3[36]](function(_0x3290x21){logger[_0x17c3[35]](_0x3290x21[_0x17c3[53]])})}else {return Account[_0x17c3[103]](msg[_0x17c3[102]])[_0x17c3[43]](function(_0x3290x39){_0x3290x26= _0x3290x39;if(_0x3290x26[_0x17c3[97]]){return Company[_0x17c3[101]]({where:{emailDomain:msg[_0x17c3[81]][0][_0x17c3[82]][_0x17c3[99]](_0x17c3[98])[1]}})[_0x17c3[43]](function(_0x3290x3a){return Contact[_0x17c3[100]]({where:{email:msg[_0x17c3[81]][0][_0x17c3[82]]},defaults:{email:msg[_0x17c3[81]][0][_0x17c3[82]],firstName:msg[_0x17c3[81]][0][_0x17c3[89]]|| msg[_0x17c3[81]][0][_0x17c3[82]][_0x17c3[99]](_0x17c3[98])[0],ListId:_0x3290x26[_0x17c3[97]],CompanyId:_0x3290x3a?_0x3290x3a[_0x17c3[73]]:null}})})}else {return []}})[_0x17c3[96]](function(_0x3290x38){_0x3290x27= _0x3290x38;return Room[_0x17c3[74]]({mailIn:1,account:_0x3290x26[_0x17c3[89]],subject:msg[_0x17c3[80]],from:_[_0x17c3[83]](msg[_0x17c3[81]],_0x17c3[82])[_0x17c3[71]](_0x17c3[104]),status:_0x17c3[94],lastEvent:_0x17c3[79],lastEventAt:moment()[_0x17c3[46]](_0x17c3[45]),arrivedAt:moment()[_0x17c3[46]](_0x17c3[45]),attachment:msg[_0x17c3[55]]&& msg[_0x17c3[55]][_0x17c3[56]],waiting:true,MailMessages:[{messageId:msg[_0x17c3[78]],subject:msg[_0x17c3[80]],from:_[_0x17c3[83]](msg[_0x17c3[81]],_0x17c3[82]),fromId:_0x3290x27?_0x3290x27[_0x17c3[73]]:null,to:msg[_0x17c3[84]]?_[_0x17c3[83]](msg[_0x17c3[84]],_0x17c3[82]):[],cc:msg[_0x17c3[85]]?_[_0x17c3[83]](msg[_0x17c3[85]],_0x17c3[82]):[],bcc:msg[_0x17c3[86]]?_[_0x17c3[83]](msg[_0x17c3[86]],_0x17c3[82]):[],status:_0x17c3[79],text:msg[_0x17c3[87]]|| null,html:msg[_0x17c3[88]]|| null,accountName:_0x3290x26[_0x17c3[89]],accountId:_0x3290x26[_0x17c3[73]]}],MailAccountId:msg[_0x17c3[102]]},{include:[{model:Message}]})})[_0x17c3[43]](function(_0x3290x3b){var _0x3290x2e=[];var _0x3290x3c=_0x3290x3b;ami[_0x17c3[41]]({message:_0x17c3[54],doc:_0x3290x3b[_0x17c3[106]][0]});createAndStartRouting(_0x3290x3c,msg,_0x3290x3c[_0x17c3[106]][0][_0x17c3[31]]({plain:true}),_0x3290x26);if(msg[_0x17c3[55]]&& msg[_0x17c3[55]][_0x17c3[56]]){msg[_0x17c3[55]][_0x17c3[76]](function(_0x3290x30){var _0x3290x31=_0x17c3[57]+ Math[_0x17c3[58]](32);var _0x3290x32;_0x3290x2e[_0x17c3[75]](Attachment[_0x17c3[74]]({name:_0x3290x30[_0x17c3[61]],basename:_0x3290x31,path:path[_0x17c3[71]](config[_0x17c3[67]],_0x17c3[68],_0x17c3[69],_0x17c3[55],_0x17c3[70],_0x3290x31),type:_0x3290x30[_0x17c3[72]],size:_0x3290x30[_0x17c3[56]],MailMessageId:_0x3290x3c[_0x17c3[106]][0][_0x17c3[73]]})[_0x17c3[43]](function(_0x3290x34){return open(_0x3290x34[_0x17c3[3]],_0x17c3[66])})[_0x17c3[43]](function(_0x3290x33){_0x3290x32= _0x3290x33;return write(_0x3290x32, new Buffer(_0x3290x30[_0x17c3[65]][_0x17c3[64]]),0,_0x3290x30[_0x17c3[56]])})[_0x17c3[43]](function(){return close(_0x3290x32)})[_0x17c3[43]](function(){logger[_0x17c3[63]](_0x17c3[60],_0x3290x30[_0x17c3[61]],_0x17c3[62])})[_0x17c3[36]](function(_0x3290x21){logger[_0x17c3[35]](_0x17c3[59],_0x3290x21[_0x17c3[53]])}))})};return Promise[_0x17c3[77]](_0x3290x2e)})[_0x17c3[36]](function(_0x3290x21){logger[_0x17c3[35]](_0x3290x21[_0x17c3[53]])})}}function handleState(_0x3290x3e,_0x3290x20){return ms[_0x17c3[103]](_0x3290x3e)[_0x17c3[43]](function(_0x3290x3f){return _0x3290x3f[_0x17c3[48]]({state:_0x3290x20[_0x17c3[108]],source:_0x3290x20[_0x17c3[109]]|| null})})[_0x17c3[36]](function(_0x3290x21){logger[_0x17c3[35]](_0x17c3[107],_0x3290x21[_0x17c3[53]])})}function fork(_0x3290x3e,_0x3290x41){return cp[_0x17c3[117]](__dirname+ _0x17c3[116],[_0x3290x3e,_0x3290x41])[_0x17c3[111]](_0x17c3[113],function(_0x3290x20){switch(_0x3290x20[_0x17c3[115]]){case _0x17c3[114]:handleMessage(_0x3290x20);break;case _0x17c3[108]:handleState(_0x3290x3e,_0x3290x20);break;default:}})[_0x17c3[111]](_0x17c3[24],function(_0x3290x42){logger[_0x17c3[63]](util[_0x17c3[46]](_0x17c3[112],_0x3290x41,_0x3290x42))})[_0x17c3[111]](_0x17c3[35],function(_0x3290x21){logger[_0x17c3[35]](_0x17c3[110],_0x3290x21[_0x17c3[53]])})}function execRequest(_0x3290x1e,_0x3290x44,_0x3290x45){Util[_0x17c3[121]](_0x3290x1e,_0x3290x44,_0x3290x45)[_0x17c3[43]](function(_0x3290x46){logger[_0x17c3[63]](_0x17c3[120])})[_0x17c3[36]](function(_0x3290x21){logger[_0x17c3[119]](_0x17c3[118])})}function webhook(_0x3290x1e,_0x3290x48,_0x3290x49){var _0x3290x4a=_0x3290x48;switch(_0x3290x49){case _0x17c3[130]:if(_0x3290x4a[_0x17c3[122]]&& _0x3290x4a[_0x17c3[123]]){logger[_0x17c3[63]](_0x17c3[124]+ _0x3290x4a[_0x17c3[89]]+ _0x17c3[125]);execRequest(_0x3290x1e[_0x17c3[126]],_0x3290x4a[_0x17c3[122]],_0x3290x4a[_0x17c3[123]])};if(_0x3290x4a[_0x17c3[127]][_0x17c3[56]]){_[_0x17c3[76]](_0x3290x4a[_0x17c3[127]],function(_0x3290x4b){if(_0x3290x4b[_0x17c3[128]]){Util[_0x17c3[129]](_0x3290x4b,_0x3290x1e)}})};break;case _0x17c3[50]:if(_0x3290x4a[_0x17c3[131]]&& _0x3290x4a[_0x17c3[132]]){logger[_0x17c3[63]](_0x17c3[124]+ _0x3290x4a[_0x17c3[89]]+ _0x17c3[133]);execRequest(_0x3290x1e[_0x17c3[126]],_0x3290x4a[_0x17c3[131]],_0x3290x4a[_0x17c3[132]])};break;case _0x17c3[24]:if(_0x3290x4a[_0x17c3[134]]&& _0x3290x4a[_0x17c3[135]]){logger[_0x17c3[63]](_0x17c3[124]+ _0x3290x4a[_0x17c3[89]]+ _0x17c3[136]);execRequest(_0x3290x1e[_0x17c3[126]],_0x3290x4a[_0x17c3[134]],_0x3290x4a[_0x17c3[135]])};break;default:logger[_0x17c3[35]](_0x17c3[137])}}function synch(_0x3290x4d,_0x3290x4e){Account[_0x17c3[142]](function(_0x3290x1e){var _0x3290x48=_[_0x17c3[38]](_0x3290x4d,{id:_0x3290x1e[_0x17c3[73]]});if(_0x3290x48&& _0x3290x48[_0x17c3[8]]){if(_0x3290x4e[_0x3290x48[_0x17c3[8]][_0x17c3[73]]]){logger[_0x17c3[63]](util[_0x17c3[46]](_0x17c3[138],_0x3290x48[_0x17c3[8]][_0x17c3[73]],_0x3290x4e[_0x3290x48[_0x17c3[8]][_0x17c3[73]]][_0x17c3[139]]));_0x3290x4e[_0x3290x48[_0x17c3[8]][_0x17c3[73]]][_0x17c3[140]]();_0x3290x4e[_0x3290x48[_0x17c3[8]][_0x17c3[73]]]= null};_[_0x17c3[141]](_0x3290x4d,{id:_0x3290x1e[_0x17c3[73]]})}});Account[_0x17c3[143]](function(_0x3290x1e){_0x3290x4d[_0x17c3[75]](_0x3290x1e)});Account[_0x17c3[51]](function(_0x3290x1e){var _0x3290x4f=_[_0x17c3[38]](_0x3290x4d,{id:_0x3290x1e[_0x17c3[73]]});if(_0x3290x4f){logger[_0x17c3[63]](_0x17c3[144]+ _0x3290x4f[_0x17c3[89]]+ _0x17c3[145]);_[_0x17c3[146]](_0x3290x4f,_0x3290x1e)}else {_0x3290x4d[_0x17c3[147]](_0x3290x1e)}})}function createAndStartRouting(_0x3290x3b,_0x3290x51,_0x3290x2d,_0x3290x48){return queue[_0x17c3[74]](_0x17c3[150],{title:util[_0x17c3[46]](_0x17c3[151],_0x3290x2d[_0x17c3[81]]),room:_0x3290x3b,message:_0x3290x51,mailMessage:_0x3290x2d,account:_0x3290x48})[_0x17c3[149]](true)[_0x17c3[148]]()}function handleMail(_0x3290x53,_0x3290x54){var _0x3290x51=_0x3290x53[_0x17c3[64]][_0x17c3[113]];var _0x3290x2d=_0x3290x53[_0x17c3[64]][_0x17c3[152]];var _0x3290x3b=_0x3290x53[_0x17c3[64]][_0x17c3[153]];var _0x3290x48=_0x3290x53[_0x17c3[64]][_0x17c3[154]];var _0x3290x55=_0x3290x54;var _0x3290x56=cp[_0x17c3[117]](path[_0x17c3[71]](config[_0x17c3[67]],_0x17c3[162]))[_0x17c3[111]](_0x17c3[113],function(msg){switch(msg[_0x17c3[115]]){case _0x17c3[159]:return Message[_0x17c3[74]](msg[_0x17c3[114]],{include:[{model:Attachment}]});case _0x17c3[160]:return SmsMessage[_0x17c3[74]](msg[_0x17c3[114]]);case _0x17c3[161]:ami[_0x17c3[41]]({message:msg[_0x17c3[115]],doc:msg[_0x17c3[114]]});break;default:}})[_0x17c3[111]](_0x17c3[156],function(){var _0x3290x57=_[_0x17c3[141]](processes,{pid:this[_0x17c3[139]]});if(_0x3290x57&& _0x3290x57[_0x17c3[56]]){return Room[_0x17c3[103]](_0x3290x57[0][_0x17c3[158]])[_0x17c3[43]](function(_0x3290x3b){if(_0x3290x3b){return _0x3290x3b[_0x17c3[48]]({waiting:false})}})[_0x17c3[157]](function(){_0x3290x55()})}})[_0x17c3[111]](_0x17c3[24],function(){_0x3290x55()})[_0x17c3[111]](_0x17c3[155],function(){_0x3290x55()})[_0x17c3[111]](_0x17c3[35],function(_0x3290x21){_0x3290x55(_0x3290x21)});_0x3290x56[_0x17c3[41]]({type:_0x17c3[163],param1:{channel:_0x17c3[26],uniqueid:util[_0x17c3[46]](_0x17c3[164],moment()[_0x17c3[165]](),_0x3290x3b[_0x17c3[73]]),subject:_0x3290x51[_0x17c3[80]],messageid:_0x3290x2d[_0x17c3[73]],roomid:_0x3290x3b[_0x17c3[73]],accountid:_0x3290x48[_0x17c3[73]],accountname:_0x3290x48[_0x17c3[89]],accountaddress:_0x3290x48[_0x17c3[82]],from:_0x3290x51[_0x17c3[81]][0][_0x17c3[82]],cc:_0x3290x51[_0x17c3[85]]?_[_0x17c3[83]](_0x3290x51[_0x17c3[85]],_0x17c3[82]):[]},param2:_0x3290x2d});processes[_0x17c3[75]]({id:_0x3290x2d[_0x17c3[73]],channel:_0x17c3[26],process:_0x3290x56,roomid:_0x3290x3b[_0x17c3[73]],pid:_0x3290x56[_0x17c3[139]]})}module[_0x17c3[166]]= function(_0x3290x58){var _0x3290x4e={};var _0x3290x4d;var _0x3290x59;ami= _0x3290x58;process[_0x17c3[111]](_0x17c3[156],function(_0x3290x42){for(var _0x3290x5a in _0x3290x4e){if(_0x3290x4e[_0x3290x5a]){_0x3290x4e[_0x3290x5a][_0x17c3[140]]()}}});Setting[_0x17c3[38]]({where:{id:1},attributes:[_0x17c3[73],_0x17c3[170]],raw:true})[_0x17c3[43]](function(_0x3290x5c){if(_0x3290x5c){queue[_0x17c3[42]](_0x17c3[150],_0x3290x5c[_0x17c3[170]],handleMail)};return Account[_0x17c3[171]]({include:[ms]})})[_0x17c3[43]](function(_0x3290x5b){_0x3290x4d= _0x3290x5b;synch(_0x3290x4d,_0x3290x4e);_0x3290x4d[_0x17c3[76]](function(_0x3290x48){if(_0x3290x48[_0x17c3[8]]){_0x3290x4e[_0x3290x48[_0x17c3[8]][_0x17c3[73]]]= fork(_0x3290x48[_0x17c3[8]][_0x17c3[73]],_0x3290x48[_0x17c3[8]][_0x17c3[167]])}});Report[_0x17c3[51]](function(_0x3290x1e){var _0x3290x48=_[_0x17c3[38]](_0x3290x4d,{id:parseInt(_0x3290x1e[_0x17c3[168]])});if(_0x3290x48&& _0x3290x1e[_0x17c3[33]](_0x17c3[32])){webhook(_0x3290x1e,_0x3290x48,_0x17c3[130])};if(_0x3290x48&& _0x3290x1e[_0x17c3[33]](_0x17c3[49])){webhook(_0x3290x1e,_0x3290x48,_0x17c3[50])}});Room[_0x17c3[51]](function(_0x3290x1e){var _0x3290x48=_[_0x17c3[38]](_0x3290x4d,{id:_0x3290x1e[_0x17c3[169]]});if(_0x3290x48&& _0x3290x1e[_0x17c3[33]](_0x17c3[91])&& _0x3290x1e[_0x17c3[91]]=== _0x17c3[92]){webhook(_0x3290x1e,_0x3290x48,_0x17c3[24])}})})[_0x17c3[36]](function(_0x3290x21){logger[_0x17c3[35]](_0x3290x21[_0x17c3[53]])});ms[_0x17c3[143]](function(_0x3290x3f){var _0x3290x48=_[_0x17c3[38]](_0x3290x4d,{id:_0x3290x3f[_0x17c3[169]]});if(_0x3290x48){_0x3290x48[_0x17c3[8]]= _0x3290x3f};_0x3290x4e[_0x3290x3f[_0x17c3[73]]]= fork(_0x3290x3f[_0x17c3[73]],_0x3290x3f[_0x17c3[167]])});ms[_0x17c3[51]](function(_0x3290x3f){if(_0x3290x4e[_0x3290x3f[_0x17c3[73]]]){if(_0x3290x3f[_0x17c3[33]](_0x17c3[108])|| _0x3290x3f[_0x17c3[33]](_0x17c3[109])){logger[_0x17c3[63]](util[_0x17c3[46]](_0x17c3[172],_0x3290x3f[_0x17c3[73]],_0x3290x4e[_0x3290x3f[_0x17c3[73]]][_0x17c3[139]]))}else {_0x3290x4e[_0x3290x3f[_0x17c3[73]]][_0x17c3[140]]();_0x3290x4e[_0x3290x3f[_0x17c3[73]]]= null;_0x3290x4e[_0x3290x3f[_0x17c3[73]]]= fork(_0x3290x3f[_0x17c3[73]],_0x3290x3f[_0x17c3[167]])}}});ms[_0x17c3[142]](function(_0x3290x3f){if(_0x3290x4e[_0x3290x3f[_0x17c3[73]]]){logger[_0x17c3[63]](util[_0x17c3[46]](_0x17c3[138],_0x3290x3f[_0x17c3[73]],_0x3290x4e[_0x3290x3f[_0x17c3[73]]][_0x17c3[139]]));_0x3290x4e[_0x3290x3f[_0x17c3[73]]][_0x17c3[140]]();_0x3290x4e[_0x3290x3f[_0x17c3[73]]]= null}})}