Built motion from commit 5fcd269f5146f10cf3129722d518881dfac64576. Version 3.0.0...
[motion-next.git] / server / api / mailAccount / mailAccount.controller.js
1 const a394_0x553e=['email','basename','Smtp','MailServerOut','userMailAccount:remove','../../rediscache','addAgents','includeAll','authentication','isNil','User','MailAccount,\x20%s,\x20%s,\x20%s','verifySmtp','userMailAccount:save','stringify','filters','MailInteraction','key','cservice','findOne','findAll','Disposition','addApplications','addImap','MailAccounts','MailApplication','root','user','setImap','get','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','CmList','describe','tag','active','getDispositions','getMessages','addSmtp','index','%s\x20<%s>','omit','include','pass','transaction','getApplications','out','name','CannedAnswer','subject','intersection','removeAgents','status','getSmtp','removeImap','from','Tag','messageId','List','fullname','getImap','defaults','getInteractions','password','mandatoryDispositionPause','lodash','Unable\x20to\x20retrieve\x20the\x20current\x20user','host','server/files/attachments','order','create','addInteraction','color','You\x20can\x27t\x20remove\x20the\x20mail\x20service\x20account','getAgents','set','rawAttributes','attachments','undefined','UserProfileResource','params','sendStatus','service','cpassword','CmContact','length','fields','MailMessage','merge','ids','query','MailAccount,\x20%s,\x20%s','updatedAt','end','keys','UserProfileSection','path','../../config/logger','Owner','type','register','Content-Range','priority','VerifySmtp','send','Contact','../../components/parsers/qs','port','map','json','Interaction','YYYY-MM-DD\x20HH:mm:ss','MailAccount','Imap','cuser','filter','auth','where','../../config/environment','info','body','VIRTUAL','options','MailServerIn','offset','attributes','addDisposition','MailAccountId','message','result','List\x20not\x20found','stack','removeSmtp','Contacts','update','like','pick','client','nolimit','cauthentication','http','ListId','DESC','destroy','moment','limit','secure','sequelize','catch','removeDispositions','emit','model','description','Pause','attach','sort','split','setSmtp','Messages','util','api','rows','request\x20sent','role','format','error','count','isArray','then'];(function(_0x5825b0,_0x553eb6){const _0xf7b3df=function(_0x5df22c){while(--_0x5df22c){_0x5825b0['push'](_0x5825b0['shift']());}};_0xf7b3df(++_0x553eb6);}(a394_0x553e,0x1de));const a394_0xf7b3=function(_0x5825b0,_0x553eb6){_0x5825b0=_0x5825b0-0x0;let _0xf7b3df=a394_0x553e[_0x5825b0];return _0xf7b3df;};const _0x415480=a394_0xf7b3;'use strict';const moment=require(_0x415480('0x1')),util=require(_0x415480('0x10')),path=require(_0x415480('0x79')),_=require(_0x415480('0x5a')),{getSocket}=require(_0x415480('0x1f')),socket=getSocket(),qs=require(_0x415480('0x83')),logger=require(_0x415480('0x7a'))(_0x415480('0x11')),config=require(_0x415480('0x8f')),db=require('../../mysqldb')['db'],{Op,ValidationError}=require(_0x415480('0x4'));require('./mailAccount.socket')[_0x415480('0x7d')](socket);const jayson=require('jayson/promise'),client=jayson[_0x415480('0xa2')][_0x415480('0xa5')]({'port':0x232b});function respondWithRpcPromise(_0x5df22c,_0x3d7c56,_0x5e2ab5,_0x55143f){return new Promise(function(_0x3219c2,_0x23975a){const _0x58caec=a394_0xf7b3,_0x5001bc=_0x55143f||client;return _0x5001bc['request'](_0x5df22c,_0x5e2ab5)['then'](function(_0x4c51c9){const _0x1761c8=a394_0xf7b3;logger['info']('MailAccount,\x20%s,\x20%s',_0x3d7c56,_0x1761c8('0x13')),logger['debug'](_0x1761c8('0x25'),_0x3d7c56,_0x1761c8('0x13'),JSON[_0x1761c8('0x28')](_0x4c51c9));if(_0x4c51c9['error']){if(_0x4c51c9[_0x1761c8('0x16')]['code']===0x1f4)return logger[_0x1761c8('0x16')](_0x1761c8('0x74'),_0x3d7c56,_0x4c51c9['error']['message']),_0x23975a(_0x4c51c9[_0x1761c8('0x16')]['message']);return logger[_0x1761c8('0x16')]('MailAccount,\x20%s,\x20%s',_0x3d7c56,_0x4c51c9['error'][_0x1761c8('0x99')]),_0x3219c2(_0x4c51c9['error'][_0x1761c8('0x99')]);}else logger[_0x1761c8('0x90')](_0x1761c8('0x74'),_0x3d7c56,_0x1761c8('0x13')),_0x3219c2(_0x4c51c9[_0x1761c8('0x9a')][_0x1761c8('0x99')]);})[_0x58caec('0x5')](function(_0x2702d7){const _0x58ddd5=_0x58caec;logger[_0x58ddd5('0x16')](_0x58ddd5('0x74'),_0x3d7c56,_0x2702d7),_0x23975a(_0x2702d7);});});}function respondWithStatusCode(_0x3384b1,_0x2bac6d){return _0x2bac6d=_0x2bac6d||0xcc,function(_0x471c79){const _0xe57def=a394_0xf7b3;if(_0x471c79)return _0x3384b1[_0xe57def('0x6a')](_0x2bac6d);return _0x3384b1[_0xe57def('0x4d')](_0x2bac6d)[_0xe57def('0x76')]();};}function respondWithResult(_0x3d7b4a,_0x41d17a){return _0x41d17a=_0x41d17a||0xc8,function(_0x37c02e){const _0x15c0cf=a394_0xf7b3;if(_0x37c02e)return _0x3d7b4a['status'](_0x41d17a)[_0x15c0cf('0x86')](_0x37c02e);};}function respondWithFilteredResult(_0x1e2a30,_0x86dbe){return function(_0x13c53b){const _0x35f7b1=a394_0xf7b3;if(_0x13c53b){const _0x5d2732=_0x13c53b['count'],_0x4d7018=_0x86dbe[_0x35f7b1('0x95')];let _0xfa640c=_0x86dbe[_0x35f7b1('0x95')]+_0x86dbe[_0x35f7b1('0x2')],_0x399e08;return _0xfa640c>=_0x5d2732?(_0xfa640c=_0x5d2732,_0x399e08=0xc8):_0x399e08=0xce,_0x1e2a30['status'](_0x399e08),_0x1e2a30[_0x35f7b1('0x64')](_0x35f7b1('0x7e'),_0x4d7018+'-'+_0xfa640c+'/'+_0x5d2732)[_0x35f7b1('0x86')](_0x13c53b);}return null;};}function saveUpdates(_0x36ec82){return function(_0x1e19d3){const _0x4e1116=a394_0xf7b3;if(_0x1e19d3)return _0x1e19d3[_0x4e1116('0x9f')](_0x36ec82)[_0x4e1116('0x19')](function(_0x41dda1){return _0x41dda1;});return null;};}function removeEntity(_0x29a8c1){return function(_0x51bfc6){const _0x53b827=a394_0xf7b3;if(_0x51bfc6)return _0x51bfc6[_0x53b827('0x0')]()['then'](function(){const _0x110fea=_0x53b827,_0x246ab9=_0x51bfc6['get']({'plain':!![]}),_0x204531=_0x110fea('0x32');return db[_0x110fea('0x68')][_0x110fea('0x0')]({'where':{'type':_0x204531,'resourceId':_0x246ab9['id']}})[_0x110fea('0x19')](function(){return _0x51bfc6;});})['then'](function(){const _0x536611=_0x53b827;_0x29a8c1[_0x536611('0x4d')](0xcc)[_0x536611('0x76')]();});};}function handleEntityNotFound(_0x6ffbf5){return function(_0x5e8a23){return!_0x5e8a23&&_0x6ffbf5['sendStatus'](0x194),_0x5e8a23;};}function handleError(_0x13e7d2,_0x5b66e8){return _0x5b66e8=_0x5b66e8||0x1f4,function(_0x47d94e){const _0x12abbc=a394_0xf7b3;logger['error'](_0x47d94e[_0x12abbc('0x9c')]),_0x47d94e[_0x12abbc('0x48')]&&delete _0x47d94e[_0x12abbc('0x48')],_0x13e7d2[_0x12abbc('0x4d')](_0x5b66e8)[_0x12abbc('0x81')](_0x47d94e);};}exports[_0x415480('0x40')]=function(_0x47a0fd,_0x2a3032){const _0x215fb9=_0x415480;let _0x409b42={'include':[{'model':db[_0x215fb9('0x94')],'as':_0x215fb9('0x8a')},{'model':db[_0x215fb9('0x1d')],'as':_0x215fb9('0x1c')},{'model':db[_0x215fb9('0xa')],'as':_0x215fb9('0x59')}]};const _0x4d452e={},_0x20eca7={'count':0x0,'rows':[]},_0x205cc2=_[_0x215fb9('0x85')](db[_0x215fb9('0x89')][_0x215fb9('0x65')],function(_0x41cbea){const _0x3a04cf=_0x215fb9;return{'name':_0x41cbea['fieldName'],'type':_0x41cbea['type'][_0x3a04cf('0x2b')]};});_0x4d452e[_0x215fb9('0x8')]=_[_0x215fb9('0x85')](_0x205cc2,'name'),_0x4d452e['query']=_[_0x215fb9('0x77')](_0x47a0fd['query']),_0x4d452e[_0x215fb9('0x29')]=_['intersection'](_0x4d452e[_0x215fb9('0x8')],_0x4d452e[_0x215fb9('0x73')]),_0x409b42['attributes']=_[_0x215fb9('0x4b')](_0x4d452e[_0x215fb9('0x8')],qs['fields'](_0x47a0fd[_0x215fb9('0x73')][_0x215fb9('0x6f')])),_0x409b42[_0x215fb9('0x96')]=_0x409b42[_0x215fb9('0x96')][_0x215fb9('0x6e')]?_0x409b42[_0x215fb9('0x96')]:_0x4d452e['model'];typeof _0x47a0fd[_0x215fb9('0x73')]['nolimit']===_0x215fb9('0x67')&&(_0x409b42['limit']=qs[_0x215fb9('0x2')](_0x47a0fd[_0x215fb9('0x73')][_0x215fb9('0x2')]),_0x409b42[_0x215fb9('0x95')]=qs[_0x215fb9('0x95')](_0x47a0fd[_0x215fb9('0x73')][_0x215fb9('0x95')]));_0x409b42['order']=qs[_0x215fb9('0xc')](_0x47a0fd[_0x215fb9('0x73')][_0x215fb9('0xc')]),_0x409b42[_0x215fb9('0x8e')]=qs['filters'](_[_0x215fb9('0xa1')](_0x47a0fd[_0x215fb9('0x73')],_0x4d452e[_0x215fb9('0x29')]),_0x205cc2);_0x47a0fd[_0x215fb9('0x73')][_0x215fb9('0x8c')]&&(_0x409b42['where']=_['merge'](_0x409b42[_0x215fb9('0x8e')],{[Op['or']]:_[_0x215fb9('0x85')](_0x205cc2,function(_0x174e27){const _0x3ab879=_0x215fb9;if(_0x174e27[_0x3ab879('0x7c')]!==_0x3ab879('0x92')){const _0x53f574={};return _0x53f574[_0x174e27[_0x3ab879('0x48')]]={[Op[_0x3ab879('0xa0')]]:'%'+_0x47a0fd[_0x3ab879('0x73')]['filter']+'%'},_0x53f574;}})}));_0x409b42=_[_0x215fb9('0x71')]({},_0x409b42,_0x47a0fd[_0x215fb9('0x93')]);const _0x2d4c67={'where':_0x409b42['where']};return db[_0x215fb9('0x89')][_0x215fb9('0x17')](_0x2d4c67)[_0x215fb9('0x19')](function(_0xacc344){const _0x4d91ac=_0x215fb9;return _0x20eca7[_0x4d91ac('0x17')]=_0xacc344,_0x47a0fd[_0x4d91ac('0x73')][_0x4d91ac('0x21')]&&(_0x409b42[_0x4d91ac('0x43')]=[{'all':!![]}]),db['MailAccount'][_0x4d91ac('0x2e')](_0x409b42);})[_0x215fb9('0x19')](function(_0x1706db){const _0x20070f=_0x215fb9;return _0x20eca7[_0x20070f('0x12')]=_0x1706db,_0x20eca7;})[_0x215fb9('0x19')](respondWithFilteredResult(_0x2a3032,_0x409b42))['catch'](handleError(_0x2a3032,null));},exports['show']=function(_0x5bc356,_0x3e8467){const _0x31ba82=_0x415480;let _0x3cd0bb={'raw':![],'where':{'id':_0x5bc356[_0x31ba82('0x69')]['id']},'include':[{'model':db['MailServerIn'],'as':_0x31ba82('0x8a')},{'model':db[_0x31ba82('0x1d')],'as':_0x31ba82('0x1c')},{'model':db[_0x31ba82('0xa')],'as':_0x31ba82('0x59')}]};const _0x53d003={};return _0x53d003[_0x31ba82('0x8')]=_[_0x31ba82('0x77')](db[_0x31ba82('0x89')][_0x31ba82('0x65')]),_0x53d003['query']=_[_0x31ba82('0x77')](_0x5bc356[_0x31ba82('0x73')]),_0x53d003[_0x31ba82('0x29')]=_['intersection'](_0x53d003[_0x31ba82('0x8')],_0x53d003[_0x31ba82('0x73')]),_0x3cd0bb[_0x31ba82('0x96')]=_[_0x31ba82('0x4b')](_0x53d003[_0x31ba82('0x8')],qs[_0x31ba82('0x6f')](_0x5bc356[_0x31ba82('0x73')][_0x31ba82('0x6f')])),_0x3cd0bb[_0x31ba82('0x96')]=_0x3cd0bb['attributes'][_0x31ba82('0x6e')]?_0x3cd0bb['attributes']:_0x53d003[_0x31ba82('0x8')],_0x5bc356['query'][_0x31ba82('0x21')]&&(_0x3cd0bb[_0x31ba82('0x43')]=[{'all':!![]}]),_0x3cd0bb=_['merge']({},_0x3cd0bb,_0x5bc356[_0x31ba82('0x93')]),db[_0x31ba82('0x89')]['findOne'](_0x3cd0bb)[_0x31ba82('0x19')](handleEntityNotFound(_0x3e8467,null))['then'](respondWithResult(_0x3e8467,null))[_0x31ba82('0x5')](handleError(_0x3e8467,null));},exports[_0x415480('0x9f')]=function(_0x17631d,_0x2be7ea){const _0x1e68bb=_0x415480;return _0x17631d[_0x1e68bb('0x91')]['id']&&delete _0x17631d[_0x1e68bb('0x91')]['id'],db['MailAccount'][_0x1e68bb('0x2d')]({'where':{'id':_0x17631d[_0x1e68bb('0x69')]['id']},'include':[{'model':db[_0x1e68bb('0x94')],'as':_0x1e68bb('0x8a')},{'model':db[_0x1e68bb('0x1d')],'as':_0x1e68bb('0x1c')},{'model':db[_0x1e68bb('0xa')],'as':_0x1e68bb('0x59')}]})[_0x1e68bb('0x19')](handleEntityNotFound(_0x2be7ea,null))['then'](saveUpdates(_0x17631d[_0x1e68bb('0x91')],null))['then'](function(_0x47583a){const _0x15ec04=_0x1e68bb;if(_0x47583a&&_0x17631d[_0x15ec04('0x91')][_0x15ec04('0x8a')])return db['MailServerIn'][_0x15ec04('0x9f')](_0x17631d['body'][_0x15ec04('0x8a')],{'where':{'MailAccountId':_0x47583a['id']}})['then'](function(){return _0x47583a;});return _0x47583a;})['then'](function(_0x3e8e8a){const _0x10170c=_0x1e68bb;if(_0x3e8e8a&&_0x17631d[_0x10170c('0x91')]['Smtp'])return db[_0x10170c('0x1d')]['update'](_0x17631d[_0x10170c('0x91')][_0x10170c('0x1c')],{'where':{'MailAccountId':_0x3e8e8a['id']}})[_0x10170c('0x19')](function(){return _0x3e8e8a;});return _0x3e8e8a;})[_0x1e68bb('0x19')](respondWithResult(_0x2be7ea,null))[_0x1e68bb('0x5')](handleError(_0x2be7ea,null));},exports[_0x415480('0x3a')]=function(_0x54066d,_0x4bb482){const _0x399e4e=_0x415480;return db[_0x399e4e('0x89')][_0x399e4e('0x3a')]()[_0x399e4e('0x19')](respondWithResult(_0x4bb482,null))[_0x399e4e('0x5')](handleError(_0x4bb482,null));},exports[_0x415480('0x97')]=function(_0x382f1b,_0x2a6055){const _0x4102ef=_0x415480;return _0x382f1b['body']['id']&&delete _0x382f1b[_0x4102ef('0x91')]['id'],db[_0x4102ef('0x89')][_0x4102ef('0x2d')]({'where':{'id':_0x382f1b[_0x4102ef('0x69')]['id']}})[_0x4102ef('0x19')](handleEntityNotFound(_0x2a6055,null))['then'](function(_0x52fd3d){const _0x18bd60=_0x4102ef;if(_0x52fd3d)return _0x382f1b[_0x18bd60('0x91')][_0x18bd60('0x98')]=_0x52fd3d['id'],db[_0x18bd60('0x2f')]['create'](_0x382f1b[_0x18bd60('0x91')]);})[_0x4102ef('0x19')](respondWithResult(_0x2a6055,null))['catch'](handleError(_0x2a6055,null));},exports[_0x415480('0x3d')]=function(_0xe61a86,_0x360c34){const _0x48f926=_0x415480;let _0xacf588={'raw':![],'where':{}};const _0x571990={},_0x4bc271={'count':0x0,'rows':[]};return db[_0x48f926('0x89')][_0x48f926('0x2d')]({'where':{'id':_0xe61a86[_0x48f926('0x69')]['id']}})['then'](handleEntityNotFound(_0x360c34,null))['then'](function(_0xca6dc2){const _0x257866=_0x48f926;if(_0xca6dc2)return _0x571990[_0x257866('0x8')]=_[_0x257866('0x77')](db[_0x257866('0x2f')]['rawAttributes']),_0x571990[_0x257866('0x73')]=_['keys'](_0xe61a86[_0x257866('0x73')]),_0x571990[_0x257866('0x29')]=_[_0x257866('0x4b')](_0x571990['model'],_0x571990['query']),_0xacf588[_0x257866('0x96')]=_[_0x257866('0x4b')](_0x571990[_0x257866('0x8')],qs[_0x257866('0x6f')](_0xe61a86[_0x257866('0x73')][_0x257866('0x6f')])),_0xacf588[_0x257866('0x96')]=_0xacf588[_0x257866('0x96')][_0x257866('0x6e')]?_0xacf588[_0x257866('0x96')]:_0x571990[_0x257866('0x8')],typeof _0xe61a86[_0x257866('0x73')]['nolimit']==='undefined'&&(_0xacf588[_0x257866('0x2')]=qs[_0x257866('0x2')](_0xe61a86[_0x257866('0x73')][_0x257866('0x2')]),_0xacf588[_0x257866('0x95')]=qs[_0x257866('0x95')](_0xe61a86[_0x257866('0x73')][_0x257866('0x95')])),_0xacf588[_0x257866('0x5e')]=qs[_0x257866('0xc')](_0xe61a86[_0x257866('0x73')][_0x257866('0xc')]),_0xacf588[_0x257866('0x8e')]=qs['filters'](_['pick'](_0xe61a86[_0x257866('0x73')],_0x571990['filters'])),_0xacf588[_0x257866('0x8e')][_0x257866('0x98')]=_0xca6dc2['id'],_0xe61a86[_0x257866('0x73')][_0x257866('0x8c')]&&(_0xacf588[_0x257866('0x8e')]=_['merge'](_0xacf588[_0x257866('0x8e')],{[Op['or']]:_['map'](_0xacf588[_0x257866('0x96')],function(_0x340692){const _0x137d8a=_0x257866,_0x5917e5={};return _0x5917e5[_0x340692]={[Op[_0x137d8a('0xa0')]]:'%'+_0xe61a86[_0x137d8a('0x73')][_0x137d8a('0x8c')]+'%'},_0x5917e5;})})),_0xacf588=_[_0x257866('0x71')]({},_0xacf588,_0xe61a86[_0x257866('0x93')]),db['Disposition'][_0x257866('0x17')]({'where':_0xacf588[_0x257866('0x8e')]})[_0x257866('0x19')](function(_0x310eaf){const _0x2f90b1=_0x257866;return _0x4bc271[_0x2f90b1('0x17')]=_0x310eaf,_0xe61a86[_0x2f90b1('0x73')][_0x2f90b1('0x21')]&&(_0xacf588['include']=[{'all':!![]}]),db[_0x2f90b1('0x2f')][_0x2f90b1('0x2e')](_0xacf588);})[_0x257866('0x19')](function(_0x533006){const _0x4027d=_0x257866;return _0x4bc271[_0x4027d('0x12')]=_0x533006,_0x4bc271;});})[_0x48f926('0x19')](respondWithFilteredResult(_0x360c34,_0xacf588))['catch'](handleError(_0x360c34,null));},exports[_0x415480('0x6')]=function(_0x2b75d1,_0x265490){const _0x2b6a4c=_0x415480;return db[_0x2b6a4c('0x89')]['findOne']({'where':{'id':_0x2b75d1['params']['id']}})[_0x2b6a4c('0x19')](handleEntityNotFound(_0x265490,null))[_0x2b6a4c('0x19')](function(_0x59f21a){const _0xb5d64e=_0x2b6a4c;if(_0x59f21a)return _0x59f21a[_0xb5d64e('0x6')](_0x2b75d1[_0xb5d64e('0x73')]['ids']);})['then'](respondWithStatusCode(_0x265490,null))['catch'](handleError(_0x265490,null));},exports['addAnswer']=function(_0x528b65,_0x1d772e){const _0x37f0ce=_0x415480;return _0x528b65[_0x37f0ce('0x91')]['id']&&delete _0x528b65['body']['id'],db[_0x37f0ce('0x89')][_0x37f0ce('0x2d')]({'where':{'id':_0x528b65[_0x37f0ce('0x69')]['id']}})[_0x37f0ce('0x19')](handleEntityNotFound(_0x1d772e,null))[_0x37f0ce('0x19')](function(_0x5de0c4){const _0x3b8223=_0x37f0ce;if(_0x5de0c4)return _0x528b65[_0x3b8223('0x91')][_0x3b8223('0x98')]=_0x5de0c4['id'],db[_0x3b8223('0x49')]['create'](_0x528b65[_0x3b8223('0x91')]);})[_0x37f0ce('0x19')](respondWithResult(_0x1d772e,null))[_0x37f0ce('0x5')](handleError(_0x1d772e,null));},exports['getAnswers']=function(_0x58dc3b,_0x1b3ca7){const _0x183a53=_0x415480;let _0x3003e3={'raw':![],'where':{}};const _0x30a535={},_0x4e6e39={'count':0x0,'rows':[]};return db[_0x183a53('0x89')][_0x183a53('0x2d')]({'where':{'id':_0x58dc3b['params']['id']}})[_0x183a53('0x19')](handleEntityNotFound(_0x1b3ca7,null))['then'](function(_0x3f5050){const _0x52bb70=_0x183a53;if(_0x3f5050)return _0x30a535['model']=_['keys'](db[_0x52bb70('0x49')]['rawAttributes']),_0x30a535[_0x52bb70('0x73')]=_[_0x52bb70('0x77')](_0x58dc3b[_0x52bb70('0x73')]),_0x30a535['filters']=_[_0x52bb70('0x4b')](_0x30a535['model'],_0x30a535[_0x52bb70('0x73')]),_0x3003e3[_0x52bb70('0x96')]=_[_0x52bb70('0x4b')](_0x30a535[_0x52bb70('0x8')],qs[_0x52bb70('0x6f')](_0x58dc3b[_0x52bb70('0x73')][_0x52bb70('0x6f')])),_0x3003e3['attributes']=_0x3003e3[_0x52bb70('0x96')][_0x52bb70('0x6e')]?_0x3003e3[_0x52bb70('0x96')]:_0x30a535[_0x52bb70('0x8')],typeof _0x58dc3b['query'][_0x52bb70('0xa3')]===_0x52bb70('0x67')&&(_0x3003e3[_0x52bb70('0x2')]=qs['limit'](_0x58dc3b[_0x52bb70('0x73')]['limit']),_0x3003e3[_0x52bb70('0x95')]=qs['offset'](_0x58dc3b['query'][_0x52bb70('0x95')])),_0x3003e3[_0x52bb70('0x5e')]=qs[_0x52bb70('0xc')](_0x58dc3b[_0x52bb70('0x73')]['sort']),_0x3003e3[_0x52bb70('0x8e')]=qs[_0x52bb70('0x29')](_[_0x52bb70('0xa1')](_0x58dc3b[_0x52bb70('0x73')],_0x30a535[_0x52bb70('0x29')])),_0x3003e3[_0x52bb70('0x8e')][_0x52bb70('0x98')]=_0x3f5050['id'],_0x58dc3b[_0x52bb70('0x73')][_0x52bb70('0x8c')]&&(_0x3003e3[_0x52bb70('0x8e')]=_[_0x52bb70('0x71')](_0x3003e3[_0x52bb70('0x8e')],{[Op['or']]:_[_0x52bb70('0x85')](_0x3003e3['attributes'],function(_0x17301e){const _0x2b199e=_0x52bb70,_0x2c020f={};return _0x2c020f[_0x17301e]={[Op[_0x2b199e('0xa0')]]:'%'+_0x58dc3b['query'][_0x2b199e('0x8c')]+'%'},_0x2c020f;})})),_0x3003e3=_[_0x52bb70('0x71')]({},_0x3003e3,_0x58dc3b['options']),db[_0x52bb70('0x49')][_0x52bb70('0x17')]({'where':_0x3003e3[_0x52bb70('0x8e')]})[_0x52bb70('0x19')](function(_0x46ac2c){const _0xd4cd37=_0x52bb70;return _0x4e6e39[_0xd4cd37('0x17')]=_0x46ac2c,_0x58dc3b[_0xd4cd37('0x73')][_0xd4cd37('0x21')]&&(_0x3003e3[_0xd4cd37('0x43')]=[{'all':!![]}]),db['CannedAnswer'][_0xd4cd37('0x2e')](_0x3003e3);})[_0x52bb70('0x19')](function(_0x402f35){const _0x3b6233=_0x52bb70;return _0x4e6e39[_0x3b6233('0x12')]=_0x402f35,_0x4e6e39;});})[_0x183a53('0x19')](respondWithFilteredResult(_0x1b3ca7,_0x3003e3))['catch'](handleError(_0x1b3ca7,null));},exports['removeAnswers']=function(_0x49d807,_0x13f8ac){const _0x352d5f=_0x415480;return db[_0x352d5f('0x89')][_0x352d5f('0x2d')]({'where':{'id':_0x49d807['params']['id']}})[_0x352d5f('0x19')](handleEntityNotFound(_0x13f8ac,null))[_0x352d5f('0x19')](function(_0x466787){const _0x33220c=_0x352d5f;if(_0x466787)return _0x466787['removeAnswers'](_0x49d807[_0x33220c('0x73')][_0x33220c('0x72')]);})[_0x352d5f('0x19')](respondWithStatusCode(_0x13f8ac,null))[_0x352d5f('0x5')](handleError(_0x13f8ac,null));},exports[_0x415480('0x5f')]=function(_0x486e1d,_0x1dd5b3){const _0x4b19e3=_0x415480,_0x2ee0a0={'name':_0x486e1d['body'][_0x4b19e3('0x48')],'key':_0x486e1d[_0x4b19e3('0x91')][_0x4b19e3('0x2b')],'email':_0x486e1d[_0x4b19e3('0x91')][_0x4b19e3('0x1a')],'ListId':_0x486e1d[_0x4b19e3('0x91')][_0x4b19e3('0xa6')],'active':!_['isNil'](_0x486e1d[_0x4b19e3('0x91')][_0x4b19e3('0x3c')])?_0x486e1d['body'][_0x4b19e3('0x3c')]:!![],'description':_0x486e1d['body'][_0x4b19e3('0x9')]||null,'Imap':{},'Smtp':{}};return _[_0x4b19e3('0x23')](_0x486e1d[_0x4b19e3('0x91')][_0x4b19e3('0x2c')])?(_0x486e1d[_0x4b19e3('0x91')][_0x4b19e3('0xa4')]?(_0x2ee0a0['Imap'][_0x4b19e3('0x35')]=_0x486e1d[_0x4b19e3('0x91')][_0x4b19e3('0x8b')],_0x2ee0a0[_0x4b19e3('0x1c')][_0x4b19e3('0x35')]=_0x486e1d[_0x4b19e3('0x91')][_0x4b19e3('0x8b')],_0x2ee0a0[_0x4b19e3('0x8a')][_0x4b19e3('0x58')]=_0x486e1d[_0x4b19e3('0x91')][_0x4b19e3('0x6c')],_0x2ee0a0['Smtp'][_0x4b19e3('0x44')]=_0x486e1d[_0x4b19e3('0x91')]['cpassword']):(_0x2ee0a0['Imap'][_0x4b19e3('0x22')]=![],_0x2ee0a0['Smtp']['authentication']=![]),_0x2ee0a0[_0x4b19e3('0x8a')][_0x4b19e3('0x5c')]=_0x486e1d['body'][_0x4b19e3('0x8a')]['host'],_0x2ee0a0['Imap'][_0x4b19e3('0x84')]=_0x486e1d['body'][_0x4b19e3('0x8a')][_0x4b19e3('0x84')],_0x2ee0a0['Smtp'][_0x4b19e3('0x5c')]=_0x486e1d[_0x4b19e3('0x91')][_0x4b19e3('0x1c')][_0x4b19e3('0x5c')],_0x2ee0a0[_0x4b19e3('0x1c')]['port']=_0x486e1d[_0x4b19e3('0x91')][_0x4b19e3('0x1c')][_0x4b19e3('0x84')]):(_0x2ee0a0[_0x4b19e3('0x8a')][_0x4b19e3('0x6b')]=_0x486e1d[_0x4b19e3('0x91')][_0x4b19e3('0x2c')],_0x2ee0a0[_0x4b19e3('0x1c')][_0x4b19e3('0x6b')]=_0x486e1d[_0x4b19e3('0x91')][_0x4b19e3('0x2c')],_0x2ee0a0['Imap'][_0x4b19e3('0x35')]=_0x486e1d[_0x4b19e3('0x91')][_0x4b19e3('0x8b')],_0x2ee0a0[_0x4b19e3('0x1c')][_0x4b19e3('0x35')]=_0x486e1d[_0x4b19e3('0x91')][_0x4b19e3('0x8b')],_0x2ee0a0[_0x4b19e3('0x8a')][_0x4b19e3('0x58')]=_0x486e1d[_0x4b19e3('0x91')][_0x4b19e3('0x6c')],_0x2ee0a0['Smtp'][_0x4b19e3('0x44')]=_0x486e1d['body'][_0x4b19e3('0x6c')]),db[_0x4b19e3('0x89')][_0x4b19e3('0x5f')](_0x2ee0a0,{'include':[{'model':db[_0x4b19e3('0x1d')],'as':_0x4b19e3('0x1c')},{'model':db[_0x4b19e3('0x94')],'as':_0x4b19e3('0x8a')}]})[_0x4b19e3('0x19')](function(_0x25e2e9){const _0x7508c4=_0x4b19e3,_0x26c2b2=_0x486e1d['user'][_0x7508c4('0x37')]({'plain':!![]});if(!_0x26c2b2)throw new Error(_0x7508c4('0x5b'));if(_0x26c2b2[_0x7508c4('0x14')]===_0x7508c4('0x35')){const _0x1a1a53=_0x25e2e9[_0x7508c4('0x37')]({'plain':!![]});return db[_0x7508c4('0x78')][_0x7508c4('0x2d')]({'where':{'name':_0x7508c4('0x32'),'userProfileId':_0x26c2b2['userProfileId']},'raw':!![]})['then'](function(_0x7d2bc4){const _0x7b021f=_0x7508c4;return _0x7d2bc4&&_0x7d2bc4['autoAssociation']===0x0?db[_0x7b021f('0x68')][_0x7b021f('0x5f')]({'name':_0x1a1a53[_0x7b021f('0x48')],'resourceId':_0x1a1a53['id'],'type':_0x7d2bc4[_0x7b021f('0x48')],'sectionId':_0x7d2bc4['id']},{})[_0x7b021f('0x19')](function(){return _0x25e2e9;}):_0x25e2e9;})[_0x7508c4('0x5')](function(_0x15af96){const _0xff3bb6=_0x7508c4;logger['error'](_0xff3bb6('0x38'),_0x15af96);throw _0x15af96;});}return _0x25e2e9;})[_0x4b19e3('0x19')](respondWithResult(_0x1dd5b3,0xc9))[_0x4b19e3('0x5')](handleError(_0x1dd5b3,null));},exports[_0x415480('0x55')]=function(_0x3ba5b8,_0x2947e8){const _0xa0e8f3=_0x415480;return db[_0xa0e8f3('0x89')][_0xa0e8f3('0x2d')]({'where':{'id':_0x3ba5b8[_0xa0e8f3('0x69')]['id']}})[_0xa0e8f3('0x19')](handleEntityNotFound(_0x2947e8,null))['then'](function(_0x31bd1c){const _0x371046=_0xa0e8f3;if(_0x31bd1c)return _0x31bd1c[_0x371046('0x55')]();return null;})[_0xa0e8f3('0x19')](respondWithResult(_0x2947e8,null))[_0xa0e8f3('0x5')](handleError(_0x2947e8,null));},exports[_0x415480('0x31')]=function(_0x3e4a6a,_0x53ea8e){const _0x585e18=_0x415480;return _0x3e4a6a[_0x585e18('0x91')]['id']&&delete _0x3e4a6a[_0x585e18('0x91')]['id'],db[_0x585e18('0x89')]['findOne']({'where':{'id':_0x3e4a6a[_0x585e18('0x69')]['id']}})['then'](handleEntityNotFound(_0x53ea8e,null))[_0x585e18('0x19')](function(_0x4031c1){const _0x38156f=_0x585e18;if(_0x4031c1)return _0x3e4a6a['body']['MailAccountId']=_0x4031c1['id'],db['MailServerIn']['create'](_0x3e4a6a[_0x38156f('0x91')]);})['then'](respondWithResult(_0x53ea8e,null))[_0x585e18('0x5')](handleError(_0x53ea8e,null));},exports[_0x415480('0x4f')]=function(_0x407250,_0x3f4cc0){const _0x1fe282=_0x415480;return db['MailAccount']['findOne']({'where':{'id':_0x407250['params']['id']}})[_0x1fe282('0x19')](handleEntityNotFound(_0x3f4cc0,null))[_0x1fe282('0x19')](function(_0x113e09){const _0x17b6e3=_0x1fe282;if(_0x113e09)return _0x113e09[_0x17b6e3('0x36')](null);return null;})[_0x1fe282('0x19')](respondWithStatusCode(_0x3f4cc0,null))['catch'](handleError(_0x3f4cc0,null));},exports[_0x415480('0x4e')]=function(_0x2fc6c8,_0x1e22ce){const _0x453f18=_0x415480;return db[_0x453f18('0x89')][_0x453f18('0x2d')]({'where':{'id':_0x2fc6c8[_0x453f18('0x69')]['id']}})[_0x453f18('0x19')](handleEntityNotFound(_0x1e22ce,null))[_0x453f18('0x19')](function(_0x4e86b6){const _0x5dbd54=_0x453f18;if(_0x4e86b6)return _0x4e86b6[_0x5dbd54('0x4e')]();return null;})[_0x453f18('0x19')](respondWithResult(_0x1e22ce,null))[_0x453f18('0x5')](handleError(_0x1e22ce,null));},exports[_0x415480('0x3f')]=function(_0x1db42b,_0x3e28f3){const _0x3f5acd=_0x415480;return _0x1db42b[_0x3f5acd('0x91')]['id']&&delete _0x1db42b['body']['id'],db[_0x3f5acd('0x89')]['findOne']({'where':{'id':_0x1db42b[_0x3f5acd('0x69')]['id']}})[_0x3f5acd('0x19')](handleEntityNotFound(_0x3e28f3,null))['then'](function(_0x5d0284){const _0x46cef6=_0x3f5acd;if(_0x5d0284)return _0x1db42b['body'][_0x46cef6('0x98')]=_0x5d0284['id'],db['MailServerOut'][_0x46cef6('0x5f')](_0x1db42b[_0x46cef6('0x91')]);})[_0x3f5acd('0x19')](respondWithResult(_0x3e28f3,null))['catch'](handleError(_0x3e28f3,null));},exports[_0x415480('0x9d')]=function(_0x584c2b,_0x283476){const _0x1e4b6a=_0x415480;return db[_0x1e4b6a('0x89')][_0x1e4b6a('0x2d')]({'where':{'id':_0x584c2b[_0x1e4b6a('0x69')]['id']}})[_0x1e4b6a('0x19')](handleEntityNotFound(_0x283476,null))[_0x1e4b6a('0x19')](function(_0x5735d2){const _0x36df9a=_0x1e4b6a;if(_0x5735d2)return _0x5735d2[_0x36df9a('0xe')](null);return null;})['then'](respondWithStatusCode(_0x283476,null))[_0x1e4b6a('0x5')](handleError(_0x283476,null));},exports[_0x415480('0x60')]=function(_0x59bf62,_0x3863ea){const _0x335d3a=_0x415480;return db[_0x335d3a('0x2a')][_0x335d3a('0x2d')]({'where':{'id':_0x59bf62[_0x335d3a('0x69')]['id']}})[_0x335d3a('0x19')](function(_0x515400){const _0x501241=_0x335d3a;if(_0x515400)return _0x515400[_0x501241('0x60')](_0x59bf62[_0x501241('0x91')][_0x501241('0x72')],{'through':_[_0x501241('0x42')](_0x59bf62['body'],[_0x501241('0x72'),'id'])});})[_0x335d3a('0x19')](respondWithResult(_0x3863ea,null))[_0x335d3a('0x5')](handleError(_0x3863ea,null));},exports[_0x415480('0x57')]=function(_0x39dc9b,_0x4323d5){const _0x3df475=_0x415480;let _0x140a15={'raw':![],'where':{}};const _0xffb2bd={},_0x3c22c2={'count':0x0,'rows':[]};return db[_0x3df475('0x89')][_0x3df475('0x2d')]({'where':{'id':_0x39dc9b['params']['id']}})[_0x3df475('0x19')](handleEntityNotFound(_0x4323d5,null))[_0x3df475('0x19')](function(_0x2903c2){const _0x1295a3=_0x3df475;if(_0x2903c2)return _0xffb2bd[_0x1295a3('0x8')]=_[_0x1295a3('0x77')](db[_0x1295a3('0x2a')]['rawAttributes']),_0xffb2bd[_0x1295a3('0x73')]=_['keys'](_0x39dc9b[_0x1295a3('0x73')]),_0xffb2bd[_0x1295a3('0x29')]=_[_0x1295a3('0x4b')](_0xffb2bd[_0x1295a3('0x8')],_0xffb2bd[_0x1295a3('0x73')]),_0x140a15[_0x1295a3('0x96')]=_[_0x1295a3('0x4b')](_0xffb2bd['model'],qs[_0x1295a3('0x6f')](_0x39dc9b[_0x1295a3('0x73')][_0x1295a3('0x6f')])),_0x140a15[_0x1295a3('0x96')]=_0x140a15[_0x1295a3('0x96')][_0x1295a3('0x6e')]?_0x140a15[_0x1295a3('0x96')]:_0xffb2bd[_0x1295a3('0x8')],typeof _0x39dc9b[_0x1295a3('0x73')]['nolimit']==='undefined'&&(_0x140a15[_0x1295a3('0x2')]=qs[_0x1295a3('0x2')](_0x39dc9b['query']['limit']),_0x140a15[_0x1295a3('0x95')]=qs[_0x1295a3('0x95')](_0x39dc9b['query'][_0x1295a3('0x95')])),_0x140a15[_0x1295a3('0x5e')]=qs['sort'](_0x39dc9b['query'][_0x1295a3('0xc')]),_0x140a15[_0x1295a3('0x8e')]=qs['filters'](_[_0x1295a3('0xa1')](_0x39dc9b[_0x1295a3('0x73')],_0xffb2bd[_0x1295a3('0x29')])),_0x140a15[_0x1295a3('0x8e')][_0x1295a3('0x98')]=_0x2903c2['id'],_0x39dc9b['query']['filter']&&(_0x140a15[_0x1295a3('0x8e')]=_[_0x1295a3('0x71')](_0x140a15[_0x1295a3('0x8e')],{[Op['or']]:_[_0x1295a3('0x85')](_0x140a15[_0x1295a3('0x96')],function(_0x5bc7bc){const _0x413f23=_0x1295a3,_0x14b3c4={};return _0x14b3c4[_0x5bc7bc]={[Op['like']]:'%'+_0x39dc9b[_0x413f23('0x73')]['filter']+'%'},_0x14b3c4;})})),_0x140a15=_[_0x1295a3('0x71')]({},_0x140a15,_0x39dc9b[_0x1295a3('0x93')]),db[_0x1295a3('0x2a')][_0x1295a3('0x17')]({'where':_0x140a15['where']})['then'](function(_0x7ae475){const _0x490fee=_0x1295a3;return _0x3c22c2[_0x490fee('0x17')]=_0x7ae475,_0x39dc9b[_0x490fee('0x73')][_0x490fee('0x21')]&&(_0x140a15['include']=[{'model':db['CmContact'],'as':_0x490fee('0x82'),'required':![]},{'model':db[_0x490fee('0x24')],'as':_0x490fee('0x7b'),'attributes':[_0x490fee('0x48'),_0x490fee('0x54'),'internal'],'required':![]},{'model':db[_0x490fee('0x51')],'as':'Tags','attributes':['id',_0x490fee('0x48'),_0x490fee('0x61')],'where':_0x39dc9b[_0x490fee('0x73')][_0x490fee('0x3b')]?{'id':_0x39dc9b[_0x490fee('0x73')][_0x490fee('0x3b')]}:undefined,'required':_0x39dc9b[_0x490fee('0x73')][_0x490fee('0x3b')]?!![]:![]}]),db['MailInteraction'][_0x490fee('0x2e')](_0x140a15);})[_0x1295a3('0x19')](function(_0x3fc4b9){return _0x3c22c2['rows']=_0x3fc4b9,_0x3c22c2;});})[_0x3df475('0x19')](respondWithFilteredResult(_0x4323d5,_0x140a15))[_0x3df475('0x5')](handleError(_0x4323d5,null));},exports[_0x415480('0x30')]=function(_0x36529d,_0x3373e0){const _0x36796b=_0x415480;return db[_0x36796b('0x89')][_0x36796b('0x2d')]({'where':{'id':_0x36529d[_0x36796b('0x69')]['id']}})[_0x36796b('0x19')](handleEntityNotFound(_0x3373e0,null))['then'](function(_0x280e1e){const _0x107bc0=_0x36796b;if(_0x280e1e)return db[_0x107bc0('0x4')][_0x107bc0('0x45')](function(_0x3d7d91){const _0x374c6b=_0x107bc0;return db[_0x374c6b('0x33')][_0x374c6b('0x0')]({'where':{'MailAccountId':_0x36529d[_0x374c6b('0x69')]['id']},'transaction':_0x3d7d91})['then'](function(){const _0x3367bd=_0x374c6b,_0x4ad488=_[_0x3367bd('0x85')](_0x36529d['body'],function(_0x1ea55e){const _0x3160fa=_0x3367bd;return _0x1ea55e[_0x3160fa('0x98')]=_0x36529d[_0x3160fa('0x69')]['id'],_0x1ea55e;});return db[_0x3367bd('0x33')]['bulkCreate'](_0x4ad488,{'transaction':_0x3d7d91});});})[_0x107bc0('0x19')](function(){const _0x2832dc=_0x107bc0;return db[_0x2832dc('0x33')]['findAndCountAll']({'where':{'MailAccountId':_0x36529d[_0x2832dc('0x69')]['id']},'order':_0x2832dc('0x7f')});});})[_0x36796b('0x19')](respondWithResult(_0x3373e0,null))[_0x36796b('0x5')](handleError(_0x3373e0,null));},exports[_0x415480('0x46')]=function(_0x359b09,_0x1bd0dc){const _0x4777c3=_0x415480;let _0x37fdc3={};const _0x1f9c7b={};let _0x2d12a8,_0x27426e;return db[_0x4777c3('0x89')]['findOne']({'where':{'id':_0x359b09['params']['id']}})[_0x4777c3('0x19')](handleEntityNotFound(_0x1bd0dc,null))[_0x4777c3('0x19')](function(_0x5397f4){const _0x3682e8=_0x4777c3;if(_0x5397f4)return _0x2d12a8=_0x5397f4,_0x1f9c7b[_0x3682e8('0x8')]=_[_0x3682e8('0x77')](db[_0x3682e8('0x33')]['rawAttributes']),_0x1f9c7b[_0x3682e8('0x73')]=_['keys'](_0x359b09['query']),_0x1f9c7b[_0x3682e8('0x29')]=_['intersection'](_0x1f9c7b[_0x3682e8('0x8')],_0x1f9c7b[_0x3682e8('0x73')]),_0x37fdc3[_0x3682e8('0x96')]=_[_0x3682e8('0x4b')](_0x1f9c7b['model'],qs[_0x3682e8('0x6f')](_0x359b09[_0x3682e8('0x73')]['fields'])),_0x37fdc3['attributes']=_0x37fdc3['attributes'][_0x3682e8('0x6e')]?_0x37fdc3[_0x3682e8('0x96')]:_0x1f9c7b[_0x3682e8('0x8')],_0x37fdc3[_0x3682e8('0x5e')]=qs[_0x3682e8('0xc')](_0x359b09[_0x3682e8('0x73')][_0x3682e8('0xc')]),_0x37fdc3[_0x3682e8('0x8e')]=qs[_0x3682e8('0x29')](_[_0x3682e8('0xa1')](_0x359b09[_0x3682e8('0x73')],_0x1f9c7b[_0x3682e8('0x29')])),_0x359b09[_0x3682e8('0x73')][_0x3682e8('0x8c')]&&(_0x37fdc3[_0x3682e8('0x8e')]=_[_0x3682e8('0x71')](_0x37fdc3['where'],{[Op['or']]:_[_0x3682e8('0x85')](_0x37fdc3[_0x3682e8('0x96')],function(_0x24e35b){const _0x1dad1e=_0x3682e8,_0xb2e8ff={};return _0xb2e8ff[_0x24e35b]={[Op[_0x1dad1e('0xa0')]]:'%'+_0x359b09[_0x1dad1e('0x73')][_0x1dad1e('0x8c')]+'%'},_0xb2e8ff;})})),_0x37fdc3=_[_0x3682e8('0x71')]({},_0x37fdc3,_0x359b09[_0x3682e8('0x93')]),_0x2d12a8[_0x3682e8('0x46')](_0x37fdc3);})[_0x4777c3('0x19')](function(_0x26ca2e){const _0x23f1fa=_0x4777c3;if(_0x26ca2e)return _0x27426e=_0x26ca2e[_0x23f1fa('0x6e')],typeof _0x359b09[_0x23f1fa('0x73')][_0x23f1fa('0xa3')]===_0x23f1fa('0x67')&&(_0x37fdc3[_0x23f1fa('0x2')]=qs['limit'](_0x359b09[_0x23f1fa('0x73')][_0x23f1fa('0x2')]),_0x37fdc3[_0x23f1fa('0x95')]=qs[_0x23f1fa('0x95')](_0x359b09['query'][_0x23f1fa('0x95')])),_0x2d12a8['getApplications'](_0x37fdc3);})[_0x4777c3('0x19')](function(_0x17e900){if(_0x17e900)return _0x17e900?{'count':_0x27426e,'rows':_0x17e900}:null;})['then'](respondWithResult(_0x1bd0dc,null))[_0x4777c3('0x5')](handleError(_0x1bd0dc,null));},exports[_0x415480('0x3e')]=function(_0x4a65c5,_0x593b9b){const _0x3c31fe=_0x415480;let _0x2b288a={'raw':!![],'where':{}};const _0x4a9b99={},_0xb623aa={'count':0x0,'rows':[]};return db[_0x3c31fe('0x89')][_0x3c31fe('0x2d')]({'where':{'id':_0x4a65c5[_0x3c31fe('0x69')]['id']}})['then'](handleEntityNotFound(_0x593b9b,null))[_0x3c31fe('0x19')](function(_0x315c1c){const _0x5e1bb6=_0x3c31fe;if(_0x315c1c){_0x4a9b99[_0x5e1bb6('0x8')]=_[_0x5e1bb6('0x77')](db[_0x5e1bb6('0x70')]['rawAttributes']),_0x4a9b99[_0x5e1bb6('0x73')]=_[_0x5e1bb6('0x77')](_0x4a65c5[_0x5e1bb6('0x73')]),_0x4a9b99[_0x5e1bb6('0x29')]=_[_0x5e1bb6('0x4b')](_0x4a9b99[_0x5e1bb6('0x8')],_0x4a9b99[_0x5e1bb6('0x73')]),_0x2b288a[_0x5e1bb6('0x96')]=_['intersection'](_0x4a9b99[_0x5e1bb6('0x8')],qs[_0x5e1bb6('0x6f')](_0x4a65c5['query'][_0x5e1bb6('0x6f')])),_0x2b288a['attributes']=_0x2b288a[_0x5e1bb6('0x96')]['length']?_0x2b288a['attributes']:_0x4a9b99[_0x5e1bb6('0x8')];typeof _0x4a65c5['query'][_0x5e1bb6('0xa3')]===_0x5e1bb6('0x67')&&(_0x2b288a[_0x5e1bb6('0x2')]=qs[_0x5e1bb6('0x2')](_0x4a65c5[_0x5e1bb6('0x73')][_0x5e1bb6('0x2')]),_0x2b288a['offset']=qs[_0x5e1bb6('0x95')](_0x4a65c5[_0x5e1bb6('0x73')][_0x5e1bb6('0x95')]));_0x2b288a[_0x5e1bb6('0x5e')]=qs['sort'](_0x4a65c5[_0x5e1bb6('0x73')][_0x5e1bb6('0xc')]),_0x2b288a[_0x5e1bb6('0x8e')]=qs['filters'](_['pick'](_0x4a65c5[_0x5e1bb6('0x73')],_0x4a9b99[_0x5e1bb6('0x29')])),_0x2b288a[_0x5e1bb6('0x8e')]['MailAccountId']=_0x315c1c['id'];_0x4a65c5['query']['filter']&&(_0x2b288a['where']=_[_0x5e1bb6('0x71')](_0x2b288a[_0x5e1bb6('0x8e')],{[Op['or']]:_[_0x5e1bb6('0x85')](_0x2b288a[_0x5e1bb6('0x96')],function(_0x179179){const _0x18716f=_0x5e1bb6,_0x320b1f={};return _0x320b1f[_0x179179]={[Op['like']]:'%'+_0x4a65c5[_0x18716f('0x73')][_0x18716f('0x8c')]+'%'},_0x320b1f;})}));if(_0x4a65c5['query']['$gte']){const _0x1cce7c=_0x4a65c5[_0x5e1bb6('0x73')]['$gte'][_0x5e1bb6('0xd')](','),_0x59f6ba={};_0x59f6ba[_0x1cce7c[0x0]]={[Op['gte']]:moment(_0x1cce7c[0x1])[_0x5e1bb6('0x15')](_0x5e1bb6('0x88'))},_0x2b288a[_0x5e1bb6('0x8e')]=_[_0x5e1bb6('0x71')](_0x2b288a['where'],_0x59f6ba);}return _0x2b288a=_['merge']({},_0x2b288a,_0x4a65c5[_0x5e1bb6('0x93')]),db[_0x5e1bb6('0x70')]['count']({'where':_0x2b288a[_0x5e1bb6('0x8e')]})[_0x5e1bb6('0x19')](function(_0x5172bb){const _0x3134a8=_0x5e1bb6;return _0xb623aa['count']=_0x5172bb,_0x4a65c5['query'][_0x3134a8('0x21')]&&(_0x2b288a[_0x3134a8('0x43')]=[{'all':!![]}]),db[_0x3134a8('0x70')][_0x3134a8('0x2e')](_0x2b288a);})[_0x5e1bb6('0x19')](function(_0x3de9ab){const _0x25e473=_0x5e1bb6;return _0xb623aa[_0x25e473('0x12')]=_0x3de9ab,_0xb623aa;});}})[_0x3c31fe('0x19')](respondWithFilteredResult(_0x593b9b,_0x2b288a))['catch'](handleError(_0x593b9b,null));},exports['send']=function(_0x4b4050,_0x115d97){const _0xbd78d=_0x415480;let _0x3074f2,_0x1422fa={},_0x4bd56a;return _0x4b4050['body']['to']&&(_0x4bd56a=_0x4b4050['body']['to'][_0xbd78d('0xd')](',')[0x0]),db[_0xbd78d('0x89')]['findOne']({'where':{'id':_0x4b4050[_0xbd78d('0x69')]['id']},'include':[{'model':db[_0xbd78d('0x39')],'as':_0xbd78d('0x53'),'include':[{'model':db['CmContact'],'as':_0xbd78d('0x9e'),'where':{'email':_0x4bd56a},'limit':0x1,'order':[[_0xbd78d('0x75'),_0xbd78d('0xa7')]]}]},{'model':db[_0xbd78d('0x1d')],'as':_0xbd78d('0x1c'),'raw':!![]}]})[_0xbd78d('0x19')](handleEntityNotFound(_0x115d97,null))[_0xbd78d('0x19')](function(_0x5e44ad){const _0x6771ee=_0xbd78d;if(_0x5e44ad){_0x3074f2=_0x5e44ad;if(_0x5e44ad[_0x6771ee('0x1c')]){_[_0x6771ee('0x23')](_0x4b4050[_0x6771ee('0x91')][_0x6771ee('0x50')])&&(_0x4b4050['body'][_0x6771ee('0x50')]=util['format'](_0x6771ee('0x41'),_0x5e44ad[_0x6771ee('0x48')],_0x5e44ad[_0x6771ee('0x1a')]||_0x5e44ad['Smtp'][_0x6771ee('0x35')]));if(_0x4b4050[_0x6771ee('0x91')]['attachments']&&_0x4b4050[_0x6771ee('0x91')][_0x6771ee('0x66')][_0x6771ee('0x6e')])for(let _0x23bb4f=0x0;_0x23bb4f<_0x4b4050[_0x6771ee('0x91')]['attachments'][_0x6771ee('0x6e')];_0x23bb4f+=0x1){_0x4b4050[_0x6771ee('0x91')][_0x6771ee('0x66')][_0x23bb4f]={'filename':_0x4b4050[_0x6771ee('0x91')][_0x6771ee('0x66')][_0x23bb4f][_0x6771ee('0x48')],'path':path['join'](config[_0x6771ee('0x34')],_0x6771ee('0x5d'),_0x4b4050['body'][_0x6771ee('0x66')][_0x23bb4f][_0x6771ee('0x1b')])};}const _0x1a3a83={'tls':{'rejectUnauthorized':![]}};return _[_0x6771ee('0x23')](_0x5e44ad[_0x6771ee('0x1c')][_0x6771ee('0x6b')])?(_0x5e44ad[_0x6771ee('0x1c')]['authentication']&&(_0x1a3a83[_0x6771ee('0x8d')]={'user':_0x5e44ad[_0x6771ee('0x1c')][_0x6771ee('0x35')],'pass':_0x5e44ad[_0x6771ee('0x1c')][_0x6771ee('0x44')]}),_0x1a3a83[_0x6771ee('0x5c')]=_0x5e44ad['Smtp']['host'],_0x1a3a83[_0x6771ee('0x84')]=_0x5e44ad[_0x6771ee('0x1c')]['port'],_0x1a3a83[_0x6771ee('0x3')]=_0x5e44ad[_0x6771ee('0x1c')][_0x6771ee('0x3')]):(_0x1a3a83[_0x6771ee('0x6b')]=_0x5e44ad[_0x6771ee('0x1c')][_0x6771ee('0x6b')],_0x1a3a83[_0x6771ee('0x8d')]={'user':_0x5e44ad['Smtp'][_0x6771ee('0x35')],'pass':_0x5e44ad['Smtp']['pass']}),respondWithRpcPromise('SendMail','sendMail',{'account':_0x1a3a83,'message':_0x4b4050[_0x6771ee('0x91')]});}else throw new Error('List\x20not\x20found');}})[_0xbd78d('0x19')](function(_0x1fb964){const _0x56acec=_0xbd78d;if(_0x1fb964){_0x1422fa=_0x1fb964;if(_0x3074f2[_0x56acec('0x53')])return _0x3074f2['List'][_0x56acec('0x9e')][_0x56acec('0x6e')]?_0x3074f2[_0x56acec('0x53')][_0x56acec('0x9e')][0x0]:db[_0x56acec('0x6d')][_0x56acec('0x5f')](_[_0x56acec('0x56')](_0x4b4050[_0x56acec('0x91')],{'firstName':_0x4b4050['body']['to'],'email':_0x4b4050[_0x56acec('0x91')]['to'],'phone':_0x4b4050[_0x56acec('0x91')]['to'],'ListId':_0x3074f2[_0x56acec('0xa6')]}));else throw new Error(_0x56acec('0x9b'));}})[_0xbd78d('0x19')](function(_0x52ac82){const _0x364813=_0xbd78d;if(_0x52ac82){let _0x25fd6c={'UserId':_0x4b4050[_0x364813('0x35')]['id'],'ContactId':_0x52ac82['id'],'MailAccountId':_0x3074f2['id'],'inReplyTo':_0x1422fa[_0x364813('0x52')],'to':_0x4b4050['body']['from'],'cc':_0x4b4050['body']['cc'],'subject':_0x4b4050[_0x364813('0x91')][_0x364813('0x4a')],'attach':_0x4b4050[_0x364813('0x91')][_0x364813('0xb')],'firstMsgDirection':_0x364813('0x47'),'lastMsgAt':moment()[_0x364813('0x15')]('YYYY-MM-DD\x20HH:mm:ss'),'lastMsgDirection':_0x364813('0x47'),'lastMsgBody':_0x4b4050[_0x364813('0x91')]['body'],'Messages':[_[_0x364813('0x71')](_0x4b4050[_0x364813('0x91')],{'messageId':_0x1422fa[_0x364813('0x52')],'sentAt':moment()[_0x364813('0x15')]('YYYY-MM-DD\x20HH:mm:ss'),'read':!![],'MailAccountId':_0x3074f2['id'],'UserId':_0x4b4050[_0x364813('0x35')]['id'],'ContactId':_0x52ac82['id']})]};return _0x4b4050[_0x364813('0x91')]['Interaction']&&(_0x25fd6c=_['merge'](_0x25fd6c,_0x4b4050[_0x364813('0x91')][_0x364813('0x87')])),db[_0x364813('0x2a')][_0x364813('0x5f')](_0x25fd6c,{'include':[{'model':db[_0x364813('0x70')],'as':_0x364813('0xf')}]});}})[_0xbd78d('0x19')](respondWithResult(_0x115d97,null))['catch'](handleError(_0x115d97,null));},exports[_0x415480('0x26')]=function(_0x3a8c37,_0xcc97bf){const _0x1c09ff=_0x415480;return db[_0x1c09ff('0x89')][_0x1c09ff('0x2d')]({'where':{'id':_0x3a8c37[_0x1c09ff('0x69')]['id']},'include':[{'model':db[_0x1c09ff('0x1d')],'as':'Smtp','raw':!![]}]})['then'](handleEntityNotFound(_0xcc97bf,null))['then'](function(_0x5952eb){const _0x54990f=_0x1c09ff;if(_0x5952eb&&_0x5952eb['Smtp']){const _0x380967={'id':_0x5952eb['id'],'tls':{'rejectUnauthorized':![]}};return _0x5952eb['Smtp'][_0x54990f('0x6b')]?_0x380967[_0x54990f('0x6b')]=_0x5952eb[_0x54990f('0x1c')][_0x54990f('0x6b')]:(_0x380967[_0x54990f('0x5c')]=_0x5952eb[_0x54990f('0x1c')]['host'],_0x380967[_0x54990f('0x84')]=_0x5952eb['Smtp']['port'],_0x380967[_0x54990f('0x3')]=_0x5952eb[_0x54990f('0x1c')][_0x54990f('0x3')]),_0x5952eb[_0x54990f('0x1c')][_0x54990f('0x22')]&&(_0x380967[_0x54990f('0x8d')]={'user':_0x5952eb[_0x54990f('0x1c')][_0x54990f('0x35')],'pass':_0x5952eb['Smtp'][_0x54990f('0x44')]}),respondWithRpcPromise(_0x54990f('0x80'),_0x54990f('0x26'),{'account':_0x380967});}})['then'](respondWithResult(_0xcc97bf,null))[_0x1c09ff('0x5')](handleError(_0xcc97bf,null));},exports[_0x415480('0x0')]=function(_0x144eda,_0x18ec91){const _0x54fb85=_0x415480;return db[_0x54fb85('0x89')][_0x54fb85('0x2d')]({'where':{'id':_0x144eda[_0x54fb85('0x69')]['id']}})['then'](handleEntityNotFound(_0x18ec91,null))[_0x54fb85('0x19')](function(_0x4d8336){const _0x12ddab=_0x54fb85;if(_0x4d8336&&_0x4d8336[_0x12ddab('0x6b')])throw new ValidationError(_0x12ddab('0x62'));return _0x4d8336;})[_0x54fb85('0x19')](removeEntity(_0x18ec91,null))[_0x54fb85('0x5')](handleError(_0x18ec91,null));},exports['addAgents']=function(_0x4d874b,_0x34cd23){const _0x4b69fc=_0x415480;return db[_0x4b69fc('0x89')]['findOne']({'where':{'id':_0x4d874b[_0x4b69fc('0x69')]['id']}})[_0x4b69fc('0x19')](function(_0x148067){const _0x3f8d67=_0x4b69fc;if(_0x148067)return _0x148067[_0x3f8d67('0x20')](_0x4d874b['body'][_0x3f8d67('0x72')],{'through':_['omit'](_0x4d874b[_0x3f8d67('0x91')],[_0x3f8d67('0x72'),'id'])})['then'](function(_0x4fb0b1){const _0x16a40d=_0x3f8d67;for(let _0x50513a=0x0;_0x50513a<_0x4d874b[_0x16a40d('0x91')][_0x16a40d('0x72')][_0x16a40d('0x6e')];_0x50513a+=0x1){socket[_0x16a40d('0x7')](_0x16a40d('0x27'),{'UserId':_0x4d874b['body'][_0x16a40d('0x72')][_0x50513a],'MailAccountId':_0x4d874b[_0x16a40d('0x69')]['id']});}return _0x4fb0b1;});})['then'](respondWithResult(_0x34cd23,null))['catch'](handleError(_0x34cd23,null));},exports[_0x415480('0x4c')]=function(_0x5f51ef,_0x53ab85){const _0x56a4ec=_0x415480;return db[_0x56a4ec('0x89')]['findOne']({'where':{'id':_0x5f51ef[_0x56a4ec('0x69')]['id']}})[_0x56a4ec('0x19')](handleEntityNotFound(_0x53ab85,null))[_0x56a4ec('0x19')](function(_0x5be176){const _0x2045f7=_0x56a4ec;if(_0x5be176)return _0x5be176['removeAgents'](_0x5f51ef[_0x2045f7('0x73')][_0x2045f7('0x72')])['then'](function(){const _0x325c25=_0x2045f7;if(_[_0x325c25('0x18')](_0x5f51ef[_0x325c25('0x73')][_0x325c25('0x72')]))for(let _0x2ff72c=0x0;_0x2ff72c<_0x5f51ef[_0x325c25('0x73')]['ids'][_0x325c25('0x6e')];_0x2ff72c+=0x1){socket[_0x325c25('0x7')]('userMailAccount:remove',{'UserId':Number(_0x5f51ef[_0x325c25('0x73')][_0x325c25('0x72')][_0x2ff72c]),'MailAccountId':Number(_0x5f51ef['params']['id'])});}else socket[_0x325c25('0x7')](_0x325c25('0x1e'),{'UserId':Number(_0x5f51ef[_0x325c25('0x73')][_0x325c25('0x72')]),'MailAccountId':Number(_0x5f51ef['params']['id'])});});})[_0x56a4ec('0x19')](respondWithStatusCode(_0x53ab85,null))[_0x56a4ec('0x5')](handleError(_0x53ab85,null));},exports['getAgents']=function(_0x53f5d9,_0x45f5fb){const _0x38dea9=_0x415480;let _0x50043b={};const _0x20e732={};let _0x3030c3,_0x55968c;return db[_0x38dea9('0x89')]['findOne']({'where':{'id':_0x53f5d9[_0x38dea9('0x69')]['id']}})[_0x38dea9('0x19')](handleEntityNotFound(_0x45f5fb,null))[_0x38dea9('0x19')](function(_0x1f963b){const _0x428f94=_0x38dea9;if(_0x1f963b)return _0x3030c3=_0x1f963b,_0x20e732['model']=_[_0x428f94('0x77')](db[_0x428f94('0x24')][_0x428f94('0x65')]),_0x20e732[_0x428f94('0x73')]=_[_0x428f94('0x77')](_0x53f5d9[_0x428f94('0x73')]),_0x20e732[_0x428f94('0x29')]=_[_0x428f94('0x4b')](_0x20e732[_0x428f94('0x8')],_0x20e732['query']),_0x50043b[_0x428f94('0x96')]=_['intersection'](_0x20e732['model'],qs[_0x428f94('0x6f')](_0x53f5d9[_0x428f94('0x73')][_0x428f94('0x6f')])),_0x50043b['attributes']=_0x50043b[_0x428f94('0x96')][_0x428f94('0x6e')]?_0x50043b[_0x428f94('0x96')]:_0x20e732[_0x428f94('0x8')],_0x50043b['order']=qs[_0x428f94('0xc')](_0x53f5d9[_0x428f94('0x73')][_0x428f94('0xc')]),_0x50043b[_0x428f94('0x8e')]=qs[_0x428f94('0x29')](_[_0x428f94('0xa1')](_0x53f5d9[_0x428f94('0x73')],_0x20e732['filters'])),_0x53f5d9[_0x428f94('0x73')][_0x428f94('0x8c')]&&(_0x50043b[_0x428f94('0x8e')]=_[_0x428f94('0x71')](_0x50043b['where'],{[Op['or']]:_[_0x428f94('0x85')](_0x50043b[_0x428f94('0x96')],function(_0x4a22bc){const _0x52101b=_0x428f94,_0x369044={};return _0x369044[_0x4a22bc]={[Op[_0x52101b('0xa0')]]:'%'+_0x53f5d9['query'][_0x52101b('0x8c')]+'%'},_0x369044;})})),_0x50043b=_['merge']({},_0x50043b,_0x53f5d9[_0x428f94('0x93')]),_0x3030c3[_0x428f94('0x63')](_0x50043b);})[_0x38dea9('0x19')](function(_0x28fb8f){const _0x3dfea1=_0x38dea9;if(_0x28fb8f)return _0x55968c=_0x28fb8f[_0x3dfea1('0x6e')],typeof _0x53f5d9[_0x3dfea1('0x73')][_0x3dfea1('0xa3')]===_0x3dfea1('0x67')&&(_0x50043b[_0x3dfea1('0x2')]=qs[_0x3dfea1('0x2')](_0x53f5d9[_0x3dfea1('0x73')]['limit']),_0x50043b[_0x3dfea1('0x95')]=qs['offset'](_0x53f5d9[_0x3dfea1('0x73')][_0x3dfea1('0x95')])),_0x3030c3['getAgents'](_0x50043b);})[_0x38dea9('0x19')](function(_0x6542c6){if(_0x6542c6)return _0x6542c6?{'count':_0x55968c,'rows':_0x6542c6}:null;})['then'](respondWithResult(_0x45f5fb,null))['catch'](handleError(_0x45f5fb,null));};