4a8761e6be6f0f111e415f18f9f9f2cf0b4f83cd
[motion2.git] / server / api / mailAccount / mailAccount.controller.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0xbc19=['smtp.gmail.com','smtp-mail.outlook.com','smtp.office365.com','user','username','password','modernAuthentication','CloudProviderId','pass','host','port','secure','service','authentication','Imap','Smtp','index','MailServerIn','MailServerOut','Pause','mandatoryDispositionPause','MailAccount','fieldName','type','key','model','map','query','keys','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','sort','where','pick','filter','merge','VIRTUAL','includeAll','include','findAll','rows','show','params','options','find','body','provider','describe','MailAccountId','Disposition','getDispositions','findOne','rawAttributes','order','removeDispositions','ids','addAnswer','CannedAnswer','getAnswers','removeAnswers','custom','email','isNil','active','description','create','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','UserProfileResource','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','getImap','removeImap','setImap','getSmtp','addSmtp','addInteraction','MailInteraction','getInteractions','Contact','User','fullname','internal','Tag','Tags','color','tag','addApplications','sequelize','transaction','Transaction','ISOLATION_LEVELS','MailApplication','bulkCreate','findAndCountAll','finally','getApplications','getMessages','MailMessage','$gte','split','format','YYYY-MM-DD\x20HH:mm:ss','true','CmList','List','CmContact','Contacts','DESC','CloudProvider','Smtp\x20configuration\x20not\x20found','from','attachments','join','root','server/files/attachments','basename','getSmtpOptions','SendMail','List\x20not\x20found','ListId','messageId','subject','attach','out','Interaction','Messages','verifySmtp','VerifySmtp','Sequelize','ValidationError','You\x20can\x27t\x20remove\x20the\x20mail\x20service\x20account','addAgents','omit','spread','userMailAccount:save','removeAgents','emit','getAgents','moment','bluebird','path','lodash','juice','ioredis','../../components/parsers/qs','../../config/logger','api','../../mysqldb','redis','defaults','localhost','./mailAccount.socket','register','jayson/promise','http','info','MailAccount,\x20%s,\x20%s','request\x20sent','debug','MailAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','catch','sendStatus','status','json','offset','undefined','count','limit','set','Content-Range','update','then','destroy','get','MailAccounts','end','stack','name','send','gmail','imap.gmail.com','yahoo','imap.mail.yahoo.com','hotmail','imap-mail.outlook.com','outlook365','outlook.office365.com','Unknown\x20email\x20service\x20provider'];(function(_0x51057a,_0x2c8c27){var _0x3cbdaa=function(_0x168adf){while(--_0x168adf){_0x51057a['push'](_0x51057a['shift']());}};_0x3cbdaa(++_0x2c8c27);}(_0xbc19,0x92));var _0x9bc1=function(_0x2641f9,_0x26715f){_0x2641f9=_0x2641f9-0x0;var _0x585741=_0xbc19[_0x2641f9];return _0x585741;};'use strict';var moment=require(_0x9bc1('0x0'));var BPromise=require(_0x9bc1('0x1'));var util=require('util');var path=require(_0x9bc1('0x2'));var _=require(_0x9bc1('0x3'));var juice=require(_0x9bc1('0x4'));var Redis=require(_0x9bc1('0x5'));var qs=require(_0x9bc1('0x6'));var logger=require(_0x9bc1('0x7'))(_0x9bc1('0x8'));var config=require('../../config/environment');var db=require(_0x9bc1('0x9'))['db'];config[_0x9bc1('0xa')]=_[_0x9bc1('0xb')](config[_0x9bc1('0xa')],{'host':_0x9bc1('0xc'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x9bc1('0xa')]));require(_0x9bc1('0xd'))[_0x9bc1('0xe')](socket);var jayson=require(_0x9bc1('0xf'));var client=jayson['client'][_0x9bc1('0x10')]({'port':0x232b});function respondWithRpcPromise(_0x38f753,_0x29a5e3,_0x174efa,_0x3de8ef){return new BPromise(function(_0xdcdb77,_0x17e7a2){var _0x2612e9=_0x3de8ef||client;return _0x2612e9['request'](_0x38f753,_0x174efa)['then'](function(_0x536aef){logger[_0x9bc1('0x11')](_0x9bc1('0x12'),_0x29a5e3,_0x9bc1('0x13'));logger[_0x9bc1('0x14')](_0x9bc1('0x15'),_0x29a5e3,'request\x20sent',JSON[_0x9bc1('0x16')](_0x536aef));if(_0x536aef['error']){if(_0x536aef[_0x9bc1('0x17')][_0x9bc1('0x18')]===0x1f4){logger['error'](_0x9bc1('0x12'),_0x29a5e3,_0x536aef[_0x9bc1('0x17')][_0x9bc1('0x19')]);return _0x17e7a2(_0x536aef[_0x9bc1('0x17')][_0x9bc1('0x19')]);}logger[_0x9bc1('0x17')](_0x9bc1('0x12'),_0x29a5e3,_0x536aef[_0x9bc1('0x17')][_0x9bc1('0x19')]);return _0xdcdb77(_0x536aef['error']['message']);}else{logger[_0x9bc1('0x11')](_0x9bc1('0x12'),_0x29a5e3,_0x9bc1('0x13'));_0xdcdb77(_0x536aef['result'][_0x9bc1('0x19')]);}})[_0x9bc1('0x1a')](function(_0x39dedc){logger[_0x9bc1('0x17')](_0x9bc1('0x12'),_0x29a5e3,_0x39dedc);_0x17e7a2(_0x39dedc);});});}function respondWithStatusCode(_0x29da12,_0xbf9946){_0xbf9946=_0xbf9946||0xcc;return function(_0x2717e3){if(_0x2717e3){return _0x29da12[_0x9bc1('0x1b')](_0xbf9946);}return _0x29da12[_0x9bc1('0x1c')](_0xbf9946)['end']();};}function respondWithResult(_0x4d2677,_0x5e15cd){_0x5e15cd=_0x5e15cd||0xc8;return function(_0x1a4cac){if(_0x1a4cac){return _0x4d2677[_0x9bc1('0x1c')](_0x5e15cd)[_0x9bc1('0x1d')](_0x1a4cac);}};}function respondWithFilteredResult(_0x298cb3,_0x2e311a){return function(_0x198c93){if(_0x198c93){var _0x26d83a=typeof _0x2e311a[_0x9bc1('0x1e')]==='undefined'&&typeof _0x2e311a['limit']===_0x9bc1('0x1f');var _0x1ea610=_0x198c93['count'];var _0x2c1f39=_0x26d83a?0x0:_0x2e311a[_0x9bc1('0x1e')];var _0x2bad92=_0x26d83a?_0x198c93[_0x9bc1('0x20')]:_0x2e311a[_0x9bc1('0x1e')]+_0x2e311a[_0x9bc1('0x21')];var _0x5df866;if(_0x2bad92>=_0x1ea610){_0x2bad92=_0x1ea610;_0x5df866=0xc8;}else{_0x5df866=0xce;}_0x298cb3[_0x9bc1('0x1c')](_0x5df866);return _0x298cb3[_0x9bc1('0x22')](_0x9bc1('0x23'),_0x2c1f39+'-'+_0x2bad92+'/'+_0x1ea610)[_0x9bc1('0x1d')](_0x198c93);}return null;};}function saveUpdates(_0x73954c){return function(_0x3d9f0a){if(_0x3d9f0a){return _0x3d9f0a[_0x9bc1('0x24')](_0x73954c)[_0x9bc1('0x25')](function(_0x29a89d){return _0x29a89d;});}return null;};}function removeEntity(_0xf2317a){return function(_0x2e60dc){if(_0x2e60dc){return _0x2e60dc[_0x9bc1('0x26')]()['then'](function(){var _0x47dd93=_0x2e60dc[_0x9bc1('0x27')]({'plain':!![]});var _0x24c2bb=_0x9bc1('0x28');return db['UserProfileResource'][_0x9bc1('0x26')]({'where':{'type':_0x24c2bb,'resourceId':_0x47dd93['id']}})[_0x9bc1('0x25')](function(){return _0x2e60dc;});})[_0x9bc1('0x25')](function(){_0xf2317a[_0x9bc1('0x1c')](0xcc)[_0x9bc1('0x29')]();});}};}function handleEntityNotFound(_0x31acfa){return function(_0x4bbf3a){if(!_0x4bbf3a){_0x31acfa[_0x9bc1('0x1b')](0x194);}return _0x4bbf3a;};}function handleError(_0xedcba0,_0x3b77e2){_0x3b77e2=_0x3b77e2||0x1f4;return function(_0x2ea010){logger[_0x9bc1('0x17')](_0x2ea010[_0x9bc1('0x2a')]);if(_0x2ea010[_0x9bc1('0x2b')]){delete _0x2ea010[_0x9bc1('0x2b')];}_0xedcba0['status'](_0x3b77e2)[_0x9bc1('0x2c')](_0x2ea010);};}function getImapHost(_0x4d4f8e){switch(_0x4d4f8e){case _0x9bc1('0x2d'):return _0x9bc1('0x2e');case _0x9bc1('0x2f'):return _0x9bc1('0x30');case _0x9bc1('0x31'):return _0x9bc1('0x32');case _0x9bc1('0x33'):return _0x9bc1('0x34');}throw new Error(_0x9bc1('0x35'),_0x4d4f8e);}function getSmtpHost(_0x53ecc8){switch(_0x53ecc8){case _0x9bc1('0x2d'):return _0x9bc1('0x36');case'yahoo':return'smtp.mail.yahoo.com';case _0x9bc1('0x31'):return _0x9bc1('0x37');case _0x9bc1('0x33'):return _0x9bc1('0x38');}throw new Error(_0x9bc1('0x35'),_0x53ecc8);}function getAuthenticationOptions(_0x1ab640,_0x544f51){var _0x2cbac2={};var _0x217df3={};if(_0x1ab640){_0x2cbac2[_0x9bc1('0x39')]=_0x217df3['user']=_0x544f51[_0x9bc1('0x3a')];_0x2cbac2[_0x9bc1('0x3b')]=_0x217df3['pass']=_0x544f51[_0x9bc1('0x3b')];if(_0x544f51['modernAuthentication']){_0x2cbac2[_0x9bc1('0x3c')]=_0x217df3[_0x9bc1('0x3c')]=!![];_0x2cbac2['CloudProviderId']=_0x217df3[_0x9bc1('0x3d')]=_0x544f51[_0x9bc1('0x3d')];_0x2cbac2[_0x9bc1('0x3b')]=_0x217df3[_0x9bc1('0x3e')]=null;}else{_0x2cbac2[_0x9bc1('0x3d')]=_0x217df3[_0x9bc1('0x3d')]=null;}_0x2cbac2[_0x9bc1('0x3f')]=getImapHost(_0x1ab640);_0x2cbac2['port']=0x3e1;_0x217df3[_0x9bc1('0x3f')]=getSmtpHost(_0x1ab640);_0x217df3[_0x9bc1('0x40')]=0x24b;_0x217df3[_0x9bc1('0x41')]=![];_0x2cbac2[_0x9bc1('0x42')]=_0x217df3[_0x9bc1('0x42')]=null;}else{if(_0x544f51[_0x9bc1('0x43')]){_0x2cbac2[_0x9bc1('0x39')]=_0x217df3['user']=_0x544f51['username'];_0x2cbac2[_0x9bc1('0x3b')]=_0x217df3[_0x9bc1('0x3e')]=_0x544f51[_0x9bc1('0x3b')];}else{_0x2cbac2['authentication']=_0x217df3['authentication']=![];_0x2cbac2['user']=_0x217df3[_0x9bc1('0x39')]=null;_0x2cbac2[_0x9bc1('0x3b')]=_0x217df3[_0x9bc1('0x3e')]=null;}_0x2cbac2['host']=_0x544f51[_0x9bc1('0x44')][_0x9bc1('0x3f')];_0x2cbac2[_0x9bc1('0x40')]=_0x544f51[_0x9bc1('0x44')][_0x9bc1('0x40')];_0x217df3[_0x9bc1('0x3f')]=_0x544f51[_0x9bc1('0x45')][_0x9bc1('0x3f')];_0x217df3[_0x9bc1('0x40')]=_0x544f51['Smtp'][_0x9bc1('0x40')];}return{'Imap':_0x2cbac2,'Smtp':_0x217df3};}exports[_0x9bc1('0x46')]=function(_0x303e77,_0x2bb3ce){var _0x2c152a={'include':[{'model':db[_0x9bc1('0x47')],'as':_0x9bc1('0x44')},{'model':db[_0x9bc1('0x48')],'as':_0x9bc1('0x45')},{'model':db[_0x9bc1('0x49')],'as':_0x9bc1('0x4a')}]},_0x5c8d3d={},_0xdce37a={'count':0x0,'rows':[]};var _0x8750d1=_['map'](db[_0x9bc1('0x4b')]['rawAttributes'],function(_0x27885b){return{'name':_0x27885b[_0x9bc1('0x4c')],'type':_0x27885b[_0x9bc1('0x4d')][_0x9bc1('0x4e')]};});_0x5c8d3d[_0x9bc1('0x4f')]=_[_0x9bc1('0x50')](_0x8750d1,_0x9bc1('0x2b'));_0x5c8d3d[_0x9bc1('0x51')]=_[_0x9bc1('0x52')](_0x303e77[_0x9bc1('0x51')]);_0x5c8d3d[_0x9bc1('0x53')]=_['intersection'](_0x5c8d3d[_0x9bc1('0x4f')],_0x5c8d3d[_0x9bc1('0x51')]);_0x2c152a['attributes']=_[_0x9bc1('0x54')](_0x5c8d3d[_0x9bc1('0x4f')],qs['fields'](_0x303e77[_0x9bc1('0x51')][_0x9bc1('0x55')]));_0x2c152a[_0x9bc1('0x56')]=_0x2c152a[_0x9bc1('0x56')][_0x9bc1('0x57')]?_0x2c152a[_0x9bc1('0x56')]:_0x5c8d3d[_0x9bc1('0x4f')];if(!_0x303e77[_0x9bc1('0x51')][_0x9bc1('0x58')](_0x9bc1('0x59'))){_0x2c152a[_0x9bc1('0x21')]=qs['limit'](_0x303e77[_0x9bc1('0x51')]['limit']);_0x2c152a[_0x9bc1('0x1e')]=qs[_0x9bc1('0x1e')](_0x303e77['query'][_0x9bc1('0x1e')]);}_0x2c152a['order']=qs[_0x9bc1('0x5a')](_0x303e77['query'][_0x9bc1('0x5a')]);_0x2c152a[_0x9bc1('0x5b')]=qs['filters'](_[_0x9bc1('0x5c')](_0x303e77[_0x9bc1('0x51')],_0x5c8d3d[_0x9bc1('0x53')]),_0x8750d1);if(_0x303e77[_0x9bc1('0x51')][_0x9bc1('0x5d')]){_0x2c152a[_0x9bc1('0x5b')]=_[_0x9bc1('0x5e')](_0x2c152a[_0x9bc1('0x5b')],{'$or':_[_0x9bc1('0x50')](_0x8750d1,function(_0x302012){if(_0x302012[_0x9bc1('0x4d')]!==_0x9bc1('0x5f')){var _0x355c8f={};_0x355c8f[_0x302012[_0x9bc1('0x2b')]]={'$like':'%'+_0x303e77[_0x9bc1('0x51')][_0x9bc1('0x5d')]+'%'};return _0x355c8f;}})});}_0x2c152a=_[_0x9bc1('0x5e')]({},_0x2c152a,_0x303e77['options']);var _0x2401e7={'where':_0x2c152a['where']};return db[_0x9bc1('0x4b')]['count'](_0x2401e7)[_0x9bc1('0x25')](function(_0xa04ddc){_0xdce37a[_0x9bc1('0x20')]=_0xa04ddc;if(_0x303e77['query'][_0x9bc1('0x60')]){_0x2c152a[_0x9bc1('0x61')]=[{'all':!![]}];}return db[_0x9bc1('0x4b')][_0x9bc1('0x62')](_0x2c152a);})['then'](function(_0x52440a){_0xdce37a[_0x9bc1('0x63')]=_0x52440a;return _0xdce37a;})[_0x9bc1('0x25')](respondWithFilteredResult(_0x2bb3ce,_0x2c152a))[_0x9bc1('0x1a')](handleError(_0x2bb3ce,null));};exports[_0x9bc1('0x64')]=function(_0x574550,_0x4ade8e){var _0x3742f5={'raw':![],'where':{'id':_0x574550[_0x9bc1('0x65')]['id']},'include':[{'model':db['MailServerIn'],'as':_0x9bc1('0x44')},{'model':db[_0x9bc1('0x48')],'as':_0x9bc1('0x45')},{'model':db[_0x9bc1('0x49')],'as':_0x9bc1('0x4a')}]},_0x5f3bdc={};_0x5f3bdc[_0x9bc1('0x4f')]=_[_0x9bc1('0x52')](db[_0x9bc1('0x4b')]['rawAttributes']);_0x5f3bdc[_0x9bc1('0x51')]=_[_0x9bc1('0x52')](_0x574550['query']);_0x5f3bdc[_0x9bc1('0x53')]=_[_0x9bc1('0x54')](_0x5f3bdc[_0x9bc1('0x4f')],_0x5f3bdc['query']);_0x3742f5['attributes']=_[_0x9bc1('0x54')](_0x5f3bdc[_0x9bc1('0x4f')],qs[_0x9bc1('0x55')](_0x574550[_0x9bc1('0x51')][_0x9bc1('0x55')]));_0x3742f5[_0x9bc1('0x56')]=_0x3742f5[_0x9bc1('0x56')][_0x9bc1('0x57')]?_0x3742f5[_0x9bc1('0x56')]:_0x5f3bdc['model'];if(_0x574550[_0x9bc1('0x51')][_0x9bc1('0x60')]){_0x3742f5['include']=[{'all':!![]}];}_0x3742f5=_[_0x9bc1('0x5e')]({},_0x3742f5,_0x574550[_0x9bc1('0x66')]);return db[_0x9bc1('0x4b')][_0x9bc1('0x67')](_0x3742f5)[_0x9bc1('0x25')](handleEntityNotFound(_0x4ade8e,null))[_0x9bc1('0x25')](respondWithResult(_0x4ade8e,null))[_0x9bc1('0x1a')](handleError(_0x4ade8e,null));};exports[_0x9bc1('0x24')]=function(_0x490e2b,_0x38b045){if(_0x490e2b[_0x9bc1('0x68')]['id']){delete _0x490e2b[_0x9bc1('0x68')]['id'];}var _0x1d99cc=_0x490e2b[_0x9bc1('0x68')][_0x9bc1('0x69')]==='custom'?null:_0x490e2b[_0x9bc1('0x68')][_0x9bc1('0x69')];var _0x16943f=_0x490e2b['body'][_0x9bc1('0x44')]||{};var _0x15e42a=_0x490e2b[_0x9bc1('0x68')][_0x9bc1('0x45')]||{};if(_0x1d99cc){_0x16943f[_0x9bc1('0x3f')]=getImapHost(_0x1d99cc);_0x16943f[_0x9bc1('0x40')]=0x3e1;_0x15e42a[_0x9bc1('0x3f')]=getSmtpHost(_0x1d99cc);_0x15e42a[_0x9bc1('0x40')]=0x24b;_0x15e42a[_0x9bc1('0x41')]=![];}if(_0x15e42a[_0x9bc1('0x3c')]){_0x15e42a['secure']=![];}else{_0x15e42a[_0x9bc1('0x3d')]=null;}if(!_0x16943f[_0x9bc1('0x3c')])_0x16943f['CloudProviderId']=null;_0x490e2b[_0x9bc1('0x68')]['Imap']=_0x16943f;_0x490e2b[_0x9bc1('0x68')][_0x9bc1('0x45')]=_0x15e42a;return db[_0x9bc1('0x4b')][_0x9bc1('0x67')]({'where':{'id':_0x490e2b[_0x9bc1('0x65')]['id']},'include':[{'model':db[_0x9bc1('0x47')],'as':'Imap'},{'model':db[_0x9bc1('0x48')],'as':'Smtp'},{'model':db[_0x9bc1('0x49')],'as':_0x9bc1('0x4a')}]})[_0x9bc1('0x25')](handleEntityNotFound(_0x38b045,null))['then'](function(_0x425d36){if(!_0x425d36)throw new Error('Mail\x20Account\x20not\x20found');if(_0x425d36['service'])delete _0x490e2b['body']['Imap'];return _0x425d36;})[_0x9bc1('0x25')](saveUpdates(_0x490e2b[_0x9bc1('0x68')],null))[_0x9bc1('0x25')](function(_0x3c4fc5){if(!_0x490e2b[_0x9bc1('0x68')][_0x9bc1('0x44')])return _0x3c4fc5;return db[_0x9bc1('0x47')][_0x9bc1('0x24')](_0x490e2b[_0x9bc1('0x68')][_0x9bc1('0x44')],{'where':{'MailAccountId':_0x3c4fc5['id']}})[_0x9bc1('0x25')](function(){return _0x3c4fc5;});})[_0x9bc1('0x25')](function(_0x5ebdcd){if(!_0x490e2b['body']['Smtp'])return _0x5ebdcd;return db[_0x9bc1('0x48')][_0x9bc1('0x24')](_0x490e2b[_0x9bc1('0x68')]['Smtp'],{'where':{'MailAccountId':_0x5ebdcd['id']}})[_0x9bc1('0x25')](function(){return _0x5ebdcd;});})['then'](respondWithResult(_0x38b045,null))['catch'](handleError(_0x38b045,null));};exports[_0x9bc1('0x6a')]=function(_0x51bfbd,_0x47dbd9){return db[_0x9bc1('0x4b')][_0x9bc1('0x6a')]()[_0x9bc1('0x25')](respondWithResult(_0x47dbd9,null))['catch'](handleError(_0x47dbd9,null));};exports['addDisposition']=function(_0x5135a1,_0x312564){if(_0x5135a1[_0x9bc1('0x68')]['id']){delete _0x5135a1[_0x9bc1('0x68')]['id'];}return db[_0x9bc1('0x4b')][_0x9bc1('0x67')]({'where':{'id':_0x5135a1['params']['id']}})['then'](handleEntityNotFound(_0x312564,null))[_0x9bc1('0x25')](function(_0x3b113c){if(_0x3b113c){_0x5135a1[_0x9bc1('0x68')][_0x9bc1('0x6b')]=_0x3b113c['id'];return db[_0x9bc1('0x6c')]['create'](_0x5135a1[_0x9bc1('0x68')]);}})[_0x9bc1('0x25')](respondWithResult(_0x312564,null))[_0x9bc1('0x1a')](handleError(_0x312564,null));};exports[_0x9bc1('0x6d')]=function(_0x28944c,_0x30b611){var _0x48533f={'raw':![],'where':{}};var _0x194f8c={};var _0x555a82={'count':0x0,'rows':[]};return db[_0x9bc1('0x4b')][_0x9bc1('0x6e')]({'where':{'id':_0x28944c['params']['id']}})['then'](handleEntityNotFound(_0x30b611,null))[_0x9bc1('0x25')](function(_0x156a5e){if(_0x156a5e){_0x194f8c[_0x9bc1('0x4f')]=_['keys'](db[_0x9bc1('0x6c')][_0x9bc1('0x6f')]);_0x194f8c['query']=_[_0x9bc1('0x52')](_0x28944c[_0x9bc1('0x51')]);_0x194f8c[_0x9bc1('0x53')]=_[_0x9bc1('0x54')](_0x194f8c[_0x9bc1('0x4f')],_0x194f8c[_0x9bc1('0x51')]);_0x48533f[_0x9bc1('0x56')]=_['intersection'](_0x194f8c[_0x9bc1('0x4f')],qs[_0x9bc1('0x55')](_0x28944c[_0x9bc1('0x51')][_0x9bc1('0x55')]));_0x48533f[_0x9bc1('0x56')]=_0x48533f['attributes'][_0x9bc1('0x57')]?_0x48533f[_0x9bc1('0x56')]:_0x194f8c[_0x9bc1('0x4f')];if(!_0x28944c[_0x9bc1('0x51')][_0x9bc1('0x58')](_0x9bc1('0x59'))){_0x48533f[_0x9bc1('0x21')]=qs['limit'](_0x28944c[_0x9bc1('0x51')][_0x9bc1('0x21')]);_0x48533f[_0x9bc1('0x1e')]=qs[_0x9bc1('0x1e')](_0x28944c['query'][_0x9bc1('0x1e')]);}_0x48533f[_0x9bc1('0x70')]=qs[_0x9bc1('0x5a')](_0x28944c['query'][_0x9bc1('0x5a')]);_0x48533f[_0x9bc1('0x5b')]=qs[_0x9bc1('0x53')](_[_0x9bc1('0x5c')](_0x28944c['query'],_0x194f8c['filters']));_0x48533f[_0x9bc1('0x5b')]['MailAccountId']=_0x156a5e['id'];if(_0x28944c[_0x9bc1('0x51')][_0x9bc1('0x5d')]){_0x48533f['where']=_[_0x9bc1('0x5e')](_0x48533f[_0x9bc1('0x5b')],{'$or':_['map'](_0x48533f[_0x9bc1('0x56')],function(_0x47eae0){var _0x5da009={};_0x5da009[_0x47eae0]={'$like':'%'+_0x28944c[_0x9bc1('0x51')][_0x9bc1('0x5d')]+'%'};return _0x5da009;})});}_0x48533f=_[_0x9bc1('0x5e')]({},_0x48533f,_0x28944c[_0x9bc1('0x66')]);return db[_0x9bc1('0x6c')]['count']({'where':_0x48533f[_0x9bc1('0x5b')]})['then'](function(_0x3f4e70){_0x555a82[_0x9bc1('0x20')]=_0x3f4e70;if(_0x28944c['query'][_0x9bc1('0x60')]){_0x48533f[_0x9bc1('0x61')]=[{'all':!![]}];}return db[_0x9bc1('0x6c')]['findAll'](_0x48533f);})[_0x9bc1('0x25')](function(_0x3d0dba){_0x555a82[_0x9bc1('0x63')]=_0x3d0dba;return _0x555a82;});}})[_0x9bc1('0x25')](respondWithFilteredResult(_0x30b611,_0x48533f))[_0x9bc1('0x1a')](handleError(_0x30b611,null));};exports['removeDispositions']=function(_0x29d000,_0x5c61f4){return db[_0x9bc1('0x4b')][_0x9bc1('0x67')]({'where':{'id':_0x29d000[_0x9bc1('0x65')]['id']}})[_0x9bc1('0x25')](handleEntityNotFound(_0x5c61f4,null))['then'](function(_0x1e8012){if(_0x1e8012){return _0x1e8012[_0x9bc1('0x71')](_0x29d000[_0x9bc1('0x51')][_0x9bc1('0x72')]);}})[_0x9bc1('0x25')](respondWithStatusCode(_0x5c61f4,null))[_0x9bc1('0x1a')](handleError(_0x5c61f4,null));};exports[_0x9bc1('0x73')]=function(_0x599a2d,_0x4617e7){if(_0x599a2d[_0x9bc1('0x68')]['id']){delete _0x599a2d['body']['id'];}return db[_0x9bc1('0x4b')][_0x9bc1('0x67')]({'where':{'id':_0x599a2d[_0x9bc1('0x65')]['id']}})[_0x9bc1('0x25')](handleEntityNotFound(_0x4617e7,null))[_0x9bc1('0x25')](function(_0x4cd035){if(_0x4cd035){_0x599a2d['body'][_0x9bc1('0x6b')]=_0x4cd035['id'];return db[_0x9bc1('0x74')]['create'](_0x599a2d['body']);}})[_0x9bc1('0x25')](respondWithResult(_0x4617e7,null))[_0x9bc1('0x1a')](handleError(_0x4617e7,null));};exports[_0x9bc1('0x75')]=function(_0x54ed4,_0x58b11c){var _0x4a3eb7={'raw':![],'where':{}};var _0x2bae24={};var _0x4d6319={'count':0x0,'rows':[]};return db[_0x9bc1('0x4b')][_0x9bc1('0x6e')]({'where':{'id':_0x54ed4[_0x9bc1('0x65')]['id']}})[_0x9bc1('0x25')](handleEntityNotFound(_0x58b11c,null))[_0x9bc1('0x25')](function(_0x175553){if(_0x175553){_0x2bae24[_0x9bc1('0x4f')]=_[_0x9bc1('0x52')](db[_0x9bc1('0x74')][_0x9bc1('0x6f')]);_0x2bae24['query']=_[_0x9bc1('0x52')](_0x54ed4[_0x9bc1('0x51')]);_0x2bae24[_0x9bc1('0x53')]=_['intersection'](_0x2bae24[_0x9bc1('0x4f')],_0x2bae24['query']);_0x4a3eb7[_0x9bc1('0x56')]=_['intersection'](_0x2bae24['model'],qs['fields'](_0x54ed4[_0x9bc1('0x51')][_0x9bc1('0x55')]));_0x4a3eb7[_0x9bc1('0x56')]=_0x4a3eb7[_0x9bc1('0x56')][_0x9bc1('0x57')]?_0x4a3eb7[_0x9bc1('0x56')]:_0x2bae24[_0x9bc1('0x4f')];if(!_0x54ed4['query'][_0x9bc1('0x58')](_0x9bc1('0x59'))){_0x4a3eb7['limit']=qs[_0x9bc1('0x21')](_0x54ed4[_0x9bc1('0x51')][_0x9bc1('0x21')]);_0x4a3eb7[_0x9bc1('0x1e')]=qs[_0x9bc1('0x1e')](_0x54ed4[_0x9bc1('0x51')]['offset']);}_0x4a3eb7[_0x9bc1('0x70')]=qs[_0x9bc1('0x5a')](_0x54ed4[_0x9bc1('0x51')]['sort']);_0x4a3eb7[_0x9bc1('0x5b')]=qs[_0x9bc1('0x53')](_[_0x9bc1('0x5c')](_0x54ed4[_0x9bc1('0x51')],_0x2bae24[_0x9bc1('0x53')]));_0x4a3eb7['where']['MailAccountId']=_0x175553['id'];if(_0x54ed4[_0x9bc1('0x51')]['filter']){_0x4a3eb7['where']=_['merge'](_0x4a3eb7['where'],{'$or':_['map'](_0x4a3eb7[_0x9bc1('0x56')],function(_0x35c8d4){var _0x34452b={};_0x34452b[_0x35c8d4]={'$like':'%'+_0x54ed4['query']['filter']+'%'};return _0x34452b;})});}_0x4a3eb7=_[_0x9bc1('0x5e')]({},_0x4a3eb7,_0x54ed4[_0x9bc1('0x66')]);return db['CannedAnswer'][_0x9bc1('0x20')]({'where':_0x4a3eb7[_0x9bc1('0x5b')]})[_0x9bc1('0x25')](function(_0x5f5204){_0x4d6319[_0x9bc1('0x20')]=_0x5f5204;if(_0x54ed4[_0x9bc1('0x51')][_0x9bc1('0x60')]){_0x4a3eb7[_0x9bc1('0x61')]=[{'all':!![]}];}return db[_0x9bc1('0x74')][_0x9bc1('0x62')](_0x4a3eb7);})['then'](function(_0x45093e){_0x4d6319['rows']=_0x45093e;return _0x4d6319;});}})[_0x9bc1('0x25')](respondWithFilteredResult(_0x58b11c,_0x4a3eb7))[_0x9bc1('0x1a')](handleError(_0x58b11c,null));};exports[_0x9bc1('0x76')]=function(_0x5f511a,_0x7007db){return db[_0x9bc1('0x4b')][_0x9bc1('0x67')]({'where':{'id':_0x5f511a[_0x9bc1('0x65')]['id']}})[_0x9bc1('0x25')](handleEntityNotFound(_0x7007db,null))[_0x9bc1('0x25')](function(_0x556f99){if(_0x556f99){return _0x556f99[_0x9bc1('0x76')](_0x5f511a[_0x9bc1('0x51')]['ids']);}})['then'](respondWithStatusCode(_0x7007db,null))['catch'](handleError(_0x7007db,null));};exports['create']=function(_0x25462f,_0x2ed637){var _0x53515b={'name':_0x25462f[_0x9bc1('0x68')]['name'],'key':_0x25462f['body'][_0x9bc1('0x4e')],'provider':_0x25462f[_0x9bc1('0x68')]['provider']===_0x9bc1('0x77')?null:_0x25462f[_0x9bc1('0x68')]['provider'],'email':_0x25462f[_0x9bc1('0x68')][_0x9bc1('0x78')],'ListId':_0x25462f[_0x9bc1('0x68')]['ListId'],'active':!_[_0x9bc1('0x79')](_0x25462f[_0x9bc1('0x68')]['active'])?_0x25462f[_0x9bc1('0x68')][_0x9bc1('0x7a')]:!![],'description':_0x25462f[_0x9bc1('0x68')][_0x9bc1('0x7b')]||null};var _0x2a1f6c=getAuthenticationOptions(_0x53515b['provider'],_0x25462f['body']);_0x53515b['Imap']=_0x2a1f6c['Imap'];_0x53515b[_0x9bc1('0x45')]=_0x2a1f6c[_0x9bc1('0x45')];return db[_0x9bc1('0x4b')][_0x9bc1('0x7c')](_0x53515b,{'include':[{'model':db['MailServerOut'],'as':'Smtp'},{'model':db['MailServerIn'],'as':'Imap'}]})[_0x9bc1('0x25')](function(_0x4ce56e){var _0x3f4b24=_0x25462f[_0x9bc1('0x39')][_0x9bc1('0x27')]({'plain':!![]});if(!_0x3f4b24)throw new Error(_0x9bc1('0x7d'));if(_0x3f4b24[_0x9bc1('0x7e')]===_0x9bc1('0x39')){var _0x38f888=_0x4ce56e[_0x9bc1('0x27')]({'plain':!![]});return db[_0x9bc1('0x7f')][_0x9bc1('0x67')]({'where':{'name':'MailAccounts','userProfileId':_0x3f4b24[_0x9bc1('0x80')]},'raw':!![]})['then'](function(_0x183766){if(_0x183766&&_0x183766[_0x9bc1('0x81')]===0x0){return db[_0x9bc1('0x82')][_0x9bc1('0x7c')]({'name':_0x38f888[_0x9bc1('0x2b')],'resourceId':_0x38f888['id'],'type':_0x183766[_0x9bc1('0x2b')],'sectionId':_0x183766['id']},{})[_0x9bc1('0x25')](function(){return _0x4ce56e;});}else{return _0x4ce56e;}})['catch'](function(_0x430c40){logger['error'](_0x9bc1('0x83'),_0x430c40);throw _0x430c40;});}return _0x4ce56e;})['then'](respondWithResult(_0x2ed637,0xc9))[_0x9bc1('0x1a')](handleError(_0x2ed637,null));};exports[_0x9bc1('0x84')]=function(_0x13b37b,_0xb0f47e){return db[_0x9bc1('0x4b')][_0x9bc1('0x6e')]({'where':{'id':_0x13b37b[_0x9bc1('0x65')]['id']}})[_0x9bc1('0x25')](handleEntityNotFound(_0xb0f47e,null))[_0x9bc1('0x25')](function(_0x5f56f0){if(_0x5f56f0){return _0x5f56f0['getImap']();}return null;})[_0x9bc1('0x25')](respondWithResult(_0xb0f47e,null))['catch'](handleError(_0xb0f47e,null));};exports['addImap']=function(_0x27c6e5,_0x1eb04e){if(_0x27c6e5[_0x9bc1('0x68')]['id']){delete _0x27c6e5[_0x9bc1('0x68')]['id'];}return db[_0x9bc1('0x4b')][_0x9bc1('0x67')]({'where':{'id':_0x27c6e5[_0x9bc1('0x65')]['id']}})[_0x9bc1('0x25')](handleEntityNotFound(_0x1eb04e,null))[_0x9bc1('0x25')](function(_0x2670d6){if(_0x2670d6){_0x27c6e5[_0x9bc1('0x68')][_0x9bc1('0x6b')]=_0x2670d6['id'];return db['MailServerIn']['create'](_0x27c6e5[_0x9bc1('0x68')]);}})[_0x9bc1('0x25')](respondWithResult(_0x1eb04e,null))[_0x9bc1('0x1a')](handleError(_0x1eb04e,null));};exports[_0x9bc1('0x85')]=function(_0x2583d1,_0x4c7030){return db[_0x9bc1('0x4b')]['findOne']({'where':{'id':_0x2583d1[_0x9bc1('0x65')]['id']}})[_0x9bc1('0x25')](handleEntityNotFound(_0x4c7030,null))[_0x9bc1('0x25')](function(_0x142be0){if(_0x142be0){return _0x142be0[_0x9bc1('0x86')](null);}return null;})['then'](respondWithStatusCode(_0x4c7030,null))[_0x9bc1('0x1a')](handleError(_0x4c7030,null));};exports[_0x9bc1('0x87')]=function(_0x591e5b,_0xf87ee3){return db['MailAccount'][_0x9bc1('0x6e')]({'where':{'id':_0x591e5b[_0x9bc1('0x65')]['id']}})[_0x9bc1('0x25')](handleEntityNotFound(_0xf87ee3,null))[_0x9bc1('0x25')](function(_0x2cf872){if(_0x2cf872){return _0x2cf872['getSmtp']();}return null;})[_0x9bc1('0x25')](respondWithResult(_0xf87ee3,null))[_0x9bc1('0x1a')](handleError(_0xf87ee3,null));};exports[_0x9bc1('0x88')]=function(_0x231736,_0x3f4b97){if(_0x231736[_0x9bc1('0x68')]['id']){delete _0x231736[_0x9bc1('0x68')]['id'];}return db['MailAccount'][_0x9bc1('0x67')]({'where':{'id':_0x231736[_0x9bc1('0x65')]['id']}})[_0x9bc1('0x25')](handleEntityNotFound(_0x3f4b97,null))['then'](function(_0x134913){if(_0x134913){_0x231736[_0x9bc1('0x68')][_0x9bc1('0x6b')]=_0x134913['id'];return db[_0x9bc1('0x48')][_0x9bc1('0x7c')](_0x231736[_0x9bc1('0x68')]);}})['then'](respondWithResult(_0x3f4b97,null))[_0x9bc1('0x1a')](handleError(_0x3f4b97,null));};exports['removeSmtp']=function(_0x3d8e5e,_0x8aee8b){return db['MailAccount'][_0x9bc1('0x6e')]({'where':{'id':_0x3d8e5e['params']['id']}})['then'](handleEntityNotFound(_0x8aee8b,null))[_0x9bc1('0x25')](function(_0x4f7059){if(_0x4f7059){return _0x4f7059['setSmtp'](null);}return null;})[_0x9bc1('0x25')](respondWithStatusCode(_0x8aee8b,null))[_0x9bc1('0x1a')](handleError(_0x8aee8b,null));};exports[_0x9bc1('0x89')]=function(_0x5377fc,_0x547005){return db[_0x9bc1('0x8a')]['find']({'where':{'id':_0x5377fc[_0x9bc1('0x65')]['id']}})[_0x9bc1('0x25')](handleEntityNotFound(_0x547005,null))[_0x9bc1('0x25')](function(_0x1c23ec){if(_0x1c23ec){return _0x1c23ec[_0x9bc1('0x89')](_0x5377fc[_0x9bc1('0x68')]['ids'],_['omit'](_0x5377fc[_0x9bc1('0x68')],[_0x9bc1('0x72'),'id'])||{});}})[_0x9bc1('0x25')](respondWithResult(_0x547005,null))['catch'](handleError(_0x547005,null));};exports[_0x9bc1('0x8b')]=function(_0x9c46b8,_0x58aea9){var _0x1c020c={'raw':![],'where':{}};var _0x1982bf={};var _0x272d22={'count':0x0,'rows':[]};return db[_0x9bc1('0x4b')][_0x9bc1('0x6e')]({'where':{'id':_0x9c46b8[_0x9bc1('0x65')]['id']}})[_0x9bc1('0x25')](handleEntityNotFound(_0x58aea9,null))[_0x9bc1('0x25')](function(_0x267724){if(_0x267724){_0x1982bf['model']=_[_0x9bc1('0x52')](db['MailInteraction']['rawAttributes']);_0x1982bf['query']=_['keys'](_0x9c46b8['query']);_0x1982bf[_0x9bc1('0x53')]=_['intersection'](_0x1982bf[_0x9bc1('0x4f')],_0x1982bf['query']);_0x1c020c['attributes']=_[_0x9bc1('0x54')](_0x1982bf[_0x9bc1('0x4f')],qs['fields'](_0x9c46b8[_0x9bc1('0x51')][_0x9bc1('0x55')]));_0x1c020c['attributes']=_0x1c020c[_0x9bc1('0x56')]['length']?_0x1c020c[_0x9bc1('0x56')]:_0x1982bf[_0x9bc1('0x4f')];if(!_0x9c46b8['query'][_0x9bc1('0x58')]('nolimit')){_0x1c020c[_0x9bc1('0x21')]=qs[_0x9bc1('0x21')](_0x9c46b8[_0x9bc1('0x51')][_0x9bc1('0x21')]);_0x1c020c['offset']=qs[_0x9bc1('0x1e')](_0x9c46b8[_0x9bc1('0x51')][_0x9bc1('0x1e')]);}_0x1c020c[_0x9bc1('0x70')]=qs[_0x9bc1('0x5a')](_0x9c46b8[_0x9bc1('0x51')]['sort']);_0x1c020c['where']=qs[_0x9bc1('0x53')](_[_0x9bc1('0x5c')](_0x9c46b8[_0x9bc1('0x51')],_0x1982bf[_0x9bc1('0x53')]));_0x1c020c[_0x9bc1('0x5b')][_0x9bc1('0x6b')]=_0x267724['id'];if(_0x9c46b8[_0x9bc1('0x51')][_0x9bc1('0x5d')]){_0x1c020c[_0x9bc1('0x5b')]=_[_0x9bc1('0x5e')](_0x1c020c['where'],{'$or':_['map'](_0x1c020c[_0x9bc1('0x56')],function(_0xc8c7b8){var _0x1f0862={};_0x1f0862[_0xc8c7b8]={'$like':'%'+_0x9c46b8[_0x9bc1('0x51')]['filter']+'%'};return _0x1f0862;})});}_0x1c020c=_[_0x9bc1('0x5e')]({},_0x1c020c,_0x9c46b8['options']);return db[_0x9bc1('0x8a')][_0x9bc1('0x20')]({'where':_0x1c020c['where']})[_0x9bc1('0x25')](function(_0x227f27){_0x272d22['count']=_0x227f27;if(_0x9c46b8[_0x9bc1('0x51')][_0x9bc1('0x60')]){_0x1c020c[_0x9bc1('0x61')]=[{'model':db['CmContact'],'as':_0x9bc1('0x8c'),'required':![]},{'model':db[_0x9bc1('0x8d')],'as':'Owner','attributes':['name',_0x9bc1('0x8e'),_0x9bc1('0x8f')],'required':![]},{'model':db[_0x9bc1('0x90')],'as':_0x9bc1('0x91'),'attributes':['id',_0x9bc1('0x2b'),_0x9bc1('0x92')],'where':_0x9c46b8['query'][_0x9bc1('0x93')]?{'id':_0x9c46b8['query'][_0x9bc1('0x93')]}:undefined,'required':_0x9c46b8[_0x9bc1('0x51')]['tag']?!![]:![]}];}return db[_0x9bc1('0x8a')][_0x9bc1('0x62')](_0x1c020c);})[_0x9bc1('0x25')](function(_0x47b653){_0x272d22['rows']=_0x47b653;return _0x272d22;});}})[_0x9bc1('0x25')](respondWithFilteredResult(_0x58aea9,_0x1c020c))[_0x9bc1('0x1a')](handleError(_0x58aea9,null));};exports[_0x9bc1('0x94')]=function addApplications(_0x1f743e,_0x4f6d0c){var _0x196f70=_0x1f743e[_0x9bc1('0x65')]['id'];var _0x29e0e6=_0x1f743e['body'];var _0x537c5b=0xc8;var _0x1d8195=null;return db[_0x9bc1('0x95')][_0x9bc1('0x96')]({'isolationLevel':db[_0x9bc1('0x95')][_0x9bc1('0x97')][_0x9bc1('0x98')]['READ_COMMITTED']},function(_0x394c4e){return db[_0x9bc1('0x4b')]['findOne']({'where':{'id':_0x196f70},'transaction':_0x394c4e})[_0x9bc1('0x25')](function(_0x1ba01c){if(_0x1ba01c){return db[_0x9bc1('0x99')][_0x9bc1('0x26')]({'where':{'MailAccountId':_0x196f70},'transaction':_0x394c4e})['then'](function(){var _0x22b166=_[_0x9bc1('0x50')](_0x29e0e6,function(_0x576935){_0x576935['MailAccountId']=_0x196f70;return _0x576935;});return db[_0x9bc1('0x99')][_0x9bc1('0x9a')](_0x22b166,{'transaction':_0x394c4e});});}else{_0x537c5b=0x194;_0x1d8195=[];}});})['then'](function(){if(_0x537c5b!==0x194){return db[_0x9bc1('0x99')][_0x9bc1('0x9b')]({'where':{'MailAccountId':_0x196f70},'order':'priority'})[_0x9bc1('0x25')](function(_0x40d7de){_0x1d8195=_0x40d7de;});}})[_0x9bc1('0x1a')](function(_0x31abe2){_0x537c5b=0x1f4;logger[_0x9bc1('0x17')](_0x31abe2[_0x9bc1('0x2a')]);if(_0x31abe2['name']){delete _0x31abe2['name'];}_0x1d8195=_0x31abe2;})[_0x9bc1('0x9c')](function(){if(_0x1d8195===null){_0x4f6d0c[_0x9bc1('0x1b')](_0x537c5b);}else{if(_0x537c5b===0x1f4){_0x4f6d0c['status'](_0x537c5b)[_0x9bc1('0x2c')](_0x1d8195);}else{_0x4f6d0c[_0x9bc1('0x1c')](_0x537c5b)[_0x9bc1('0x1d')](_0x1d8195);}}});};exports[_0x9bc1('0x9d')]=function(_0x4cbcc5,_0x39b4da){var _0x5546e1={};var _0x1ccbb3={};var _0x124cdb;var _0x178517;return db[_0x9bc1('0x4b')]['findOne']({'where':{'id':_0x4cbcc5[_0x9bc1('0x65')]['id']}})[_0x9bc1('0x25')](handleEntityNotFound(_0x39b4da,null))[_0x9bc1('0x25')](function(_0x57bae9){if(_0x57bae9){_0x124cdb=_0x57bae9;_0x1ccbb3['model']=_[_0x9bc1('0x52')](db[_0x9bc1('0x99')]['rawAttributes']);_0x1ccbb3[_0x9bc1('0x51')]=_[_0x9bc1('0x52')](_0x4cbcc5[_0x9bc1('0x51')]);_0x1ccbb3[_0x9bc1('0x53')]=_[_0x9bc1('0x54')](_0x1ccbb3[_0x9bc1('0x4f')],_0x1ccbb3['query']);_0x5546e1[_0x9bc1('0x56')]=_[_0x9bc1('0x54')](_0x1ccbb3[_0x9bc1('0x4f')],qs[_0x9bc1('0x55')](_0x4cbcc5[_0x9bc1('0x51')][_0x9bc1('0x55')]));_0x5546e1[_0x9bc1('0x56')]=_0x5546e1[_0x9bc1('0x56')][_0x9bc1('0x57')]?_0x5546e1[_0x9bc1('0x56')]:_0x1ccbb3[_0x9bc1('0x4f')];_0x5546e1[_0x9bc1('0x70')]=qs['sort'](_0x4cbcc5['query'][_0x9bc1('0x5a')]);_0x5546e1[_0x9bc1('0x5b')]=qs['filters'](_['pick'](_0x4cbcc5[_0x9bc1('0x51')],_0x1ccbb3[_0x9bc1('0x53')]));if(_0x4cbcc5[_0x9bc1('0x51')][_0x9bc1('0x5d')]){_0x5546e1[_0x9bc1('0x5b')]=_['merge'](_0x5546e1[_0x9bc1('0x5b')],{'$or':_[_0x9bc1('0x50')](_0x5546e1[_0x9bc1('0x56')],function(_0x25488b){var _0x5e21e3={};_0x5e21e3[_0x25488b]={'$like':'%'+_0x4cbcc5[_0x9bc1('0x51')][_0x9bc1('0x5d')]+'%'};return _0x5e21e3;})});}_0x5546e1=_[_0x9bc1('0x5e')]({},_0x5546e1,_0x4cbcc5[_0x9bc1('0x66')]);return _0x124cdb[_0x9bc1('0x9d')](_0x5546e1);}})[_0x9bc1('0x25')](function(_0x140d41){if(_0x140d41){_0x178517=_0x140d41[_0x9bc1('0x57')];if(!_0x4cbcc5['query'][_0x9bc1('0x58')]('nolimit')){_0x5546e1[_0x9bc1('0x21')]=qs[_0x9bc1('0x21')](_0x4cbcc5[_0x9bc1('0x51')][_0x9bc1('0x21')]);_0x5546e1[_0x9bc1('0x1e')]=qs[_0x9bc1('0x1e')](_0x4cbcc5[_0x9bc1('0x51')]['offset']);}return _0x124cdb['getApplications'](_0x5546e1);}})[_0x9bc1('0x25')](function(_0x21d974){if(_0x21d974){return _0x21d974?{'count':_0x178517,'rows':_0x21d974}:null;}})[_0x9bc1('0x25')](respondWithResult(_0x39b4da,null))[_0x9bc1('0x1a')](handleError(_0x39b4da,null));};exports[_0x9bc1('0x9e')]=function(_0x17ca2a,_0x3ee09d){var _0x3c3995={'raw':!![],'where':{}};var _0x4bc196={};var _0x184022={'count':0x0,'rows':[]};return db[_0x9bc1('0x4b')][_0x9bc1('0x6e')]({'where':{'id':_0x17ca2a['params']['id']}})[_0x9bc1('0x25')](handleEntityNotFound(_0x3ee09d,null))[_0x9bc1('0x25')](function(_0x2e278f){if(_0x2e278f){_0x4bc196['model']=_['keys'](db[_0x9bc1('0x9f')][_0x9bc1('0x6f')]);_0x4bc196[_0x9bc1('0x51')]=_['keys'](_0x17ca2a[_0x9bc1('0x51')]);_0x4bc196[_0x9bc1('0x53')]=_['intersection'](_0x4bc196[_0x9bc1('0x4f')],_0x4bc196[_0x9bc1('0x51')]);_0x3c3995['attributes']=_[_0x9bc1('0x54')](_0x4bc196[_0x9bc1('0x4f')],qs[_0x9bc1('0x55')](_0x17ca2a['query'][_0x9bc1('0x55')]));_0x3c3995[_0x9bc1('0x56')]=_0x3c3995[_0x9bc1('0x56')][_0x9bc1('0x57')]?_0x3c3995['attributes']:_0x4bc196[_0x9bc1('0x4f')];if(!_0x17ca2a[_0x9bc1('0x51')]['hasOwnProperty'](_0x9bc1('0x59'))){_0x3c3995[_0x9bc1('0x21')]=qs[_0x9bc1('0x21')](_0x17ca2a[_0x9bc1('0x51')][_0x9bc1('0x21')]);_0x3c3995[_0x9bc1('0x1e')]=qs[_0x9bc1('0x1e')](_0x17ca2a['query'][_0x9bc1('0x1e')]);}_0x3c3995[_0x9bc1('0x70')]=qs[_0x9bc1('0x5a')](_0x17ca2a[_0x9bc1('0x51')]['sort']);_0x3c3995[_0x9bc1('0x5b')]=qs[_0x9bc1('0x53')](_[_0x9bc1('0x5c')](_0x17ca2a['query'],_0x4bc196[_0x9bc1('0x53')]));_0x3c3995[_0x9bc1('0x5b')][_0x9bc1('0x6b')]=_0x2e278f['id'];if(_0x17ca2a['query']['filter']){_0x3c3995[_0x9bc1('0x5b')]=_['merge'](_0x3c3995['where'],{'$or':_['map'](_0x3c3995['attributes'],function(_0xe96acb){var _0x47f897={};_0x47f897[_0xe96acb]={'$like':'%'+_0x17ca2a['query'][_0x9bc1('0x5d')]+'%'};return _0x47f897;})});}if(_0x17ca2a[_0x9bc1('0x51')]['$gte']){var _0x344e9b=_0x17ca2a[_0x9bc1('0x51')][_0x9bc1('0xa0')][_0x9bc1('0xa1')](',');var _0x3cf5b6={};_0x3cf5b6[_0x344e9b[0x0]]={'$gte':moment(_0x344e9b[0x1])[_0x9bc1('0xa2')](_0x9bc1('0xa3'))};_0x3c3995[_0x9bc1('0x5b')]=_[_0x9bc1('0x5e')](_0x3c3995[_0x9bc1('0x5b')],_0x3cf5b6);}_0x3c3995=_[_0x9bc1('0x5e')]({},_0x3c3995,_0x17ca2a[_0x9bc1('0x66')]);return db[_0x9bc1('0x9f')][_0x9bc1('0x20')]({'where':_0x3c3995[_0x9bc1('0x5b')]})[_0x9bc1('0x25')](function(_0x2b14ad){_0x184022['count']=_0x2b14ad;if(_0x17ca2a[_0x9bc1('0x51')]['includeAll']){_0x3c3995[_0x9bc1('0x61')]=[{'all':!![]}];}return db[_0x9bc1('0x9f')][_0x9bc1('0x62')](_0x3c3995);})['then'](function(_0x4c0354){if(_0x17ca2a[_0x9bc1('0x51')]['inlineCss']===_0x9bc1('0xa4')){for(var _0x2263d0=0x0;_0x2263d0<_0x4c0354['length'];_0x2263d0++){_0x4c0354[_0x2263d0][_0x9bc1('0x68')]=juice(_0x4c0354[_0x2263d0][_0x9bc1('0x68')]);}}_0x184022[_0x9bc1('0x63')]=_0x4c0354;return _0x184022;});}})['then'](respondWithFilteredResult(_0x3ee09d,_0x3c3995))[_0x9bc1('0x1a')](handleError(_0x3ee09d,null));};exports['send']=function(_0x2275ae,_0x10b152){var _0x5187ce,_0x41db49={},_0x5cb708;if(_0x2275ae[_0x9bc1('0x68')]['to']){_0x5cb708=_0x2275ae['body']['to']['split'](',')[0x0];}return db[_0x9bc1('0x4b')]['find']({'where':{'id':_0x2275ae[_0x9bc1('0x65')]['id']},'include':[{'model':db[_0x9bc1('0xa5')],'as':_0x9bc1('0xa6'),'include':[{'model':db[_0x9bc1('0xa7')],'as':_0x9bc1('0xa8'),'where':{'email':_0x5cb708},'limit':0x1,'order':[['updatedAt',_0x9bc1('0xa9')]]}]},{'model':db[_0x9bc1('0x48')],'as':_0x9bc1('0x45'),'raw':!![],'include':[{'model':db[_0x9bc1('0xaa')],'as':_0x9bc1('0xaa'),'raw':!![]}]}]})[_0x9bc1('0x25')](handleEntityNotFound(_0x10b152,null))[_0x9bc1('0x25')](function(_0x112317){if(!_0x112317)return;_0x5187ce=_0x112317;if(!_0x112317['Smtp'])throw new Error(_0x9bc1('0xab'));if(_[_0x9bc1('0x79')](_0x2275ae[_0x9bc1('0x68')][_0x9bc1('0xac')])){_0x2275ae['body'][_0x9bc1('0xac')]=util[_0x9bc1('0xa2')]('%s\x20<%s>',_0x112317[_0x9bc1('0x2b')],_0x112317[_0x9bc1('0x78')]||_0x112317[_0x9bc1('0x45')][_0x9bc1('0x39')]);}if(_0x2275ae[_0x9bc1('0x68')][_0x9bc1('0xad')]&&_0x2275ae['body'][_0x9bc1('0xad')]['length']){for(var _0x382a29=0x0;_0x382a29<_0x2275ae[_0x9bc1('0x68')][_0x9bc1('0xad')][_0x9bc1('0x57')];_0x382a29+=0x1){_0x2275ae['body'][_0x9bc1('0xad')][_0x382a29]={'filename':_0x2275ae[_0x9bc1('0x68')]['attachments'][_0x382a29][_0x9bc1('0x2b')],'path':path[_0x9bc1('0xae')](config[_0x9bc1('0xaf')],_0x9bc1('0xb0'),_0x2275ae['body']['attachments'][_0x382a29][_0x9bc1('0xb1')])};}}var _0x502df2=_0x112317[_0x9bc1('0xb2')]();return respondWithRpcPromise(_0x9bc1('0xb3'),'sendMail',{'account':_0x502df2,'message':_0x2275ae[_0x9bc1('0x68')]});})[_0x9bc1('0x25')](function(_0x3e115e){if(!_0x3e115e)return;_0x41db49=_0x3e115e;if(!_0x5187ce[_0x9bc1('0xa6')])throw new Error(_0x9bc1('0xb4'));if(_0x5187ce[_0x9bc1('0xa6')][_0x9bc1('0xa8')][_0x9bc1('0x57')])return _0x5187ce[_0x9bc1('0xa6')][_0x9bc1('0xa8')][0x0];return db[_0x9bc1('0xa7')][_0x9bc1('0x7c')](_[_0x9bc1('0xb')](_0x2275ae[_0x9bc1('0x68')],{'firstName':_0x2275ae[_0x9bc1('0x68')]['to'],'email':_0x2275ae[_0x9bc1('0x68')]['to'],'phone':_0x2275ae['body']['to'],'ListId':_0x5187ce[_0x9bc1('0xb5')]}));})[_0x9bc1('0x25')](function(_0x47e472){if(!_0x47e472)return;var _0x35af67={'UserId':_0x2275ae[_0x9bc1('0x39')]['id'],'ContactId':_0x47e472['id'],'MailAccountId':_0x5187ce['id'],'inReplyTo':_0x41db49[_0x9bc1('0xb6')],'to':_0x2275ae[_0x9bc1('0x68')][_0x9bc1('0xac')],'cc':_0x2275ae[_0x9bc1('0x68')]['cc'],'subject':_0x2275ae['body'][_0x9bc1('0xb7')],'attach':_0x2275ae['body'][_0x9bc1('0xb8')],'firstMsgDirection':_0x9bc1('0xb9'),'lastMsgAt':moment()[_0x9bc1('0xa2')](_0x9bc1('0xa3')),'lastMsgDirection':_0x9bc1('0xb9'),'Messages':[_[_0x9bc1('0x5e')](_0x2275ae[_0x9bc1('0x68')],{'messageId':_0x41db49[_0x9bc1('0xb6')],'sentAt':moment()[_0x9bc1('0xa2')](_0x9bc1('0xa3')),'read':!![],'MailAccountId':_0x5187ce['id'],'UserId':_0x2275ae[_0x9bc1('0x39')]['id'],'ContactId':_0x47e472['id']})]};if(_0x2275ae['body'][_0x9bc1('0xba')]){_0x35af67=_[_0x9bc1('0x5e')](_0x35af67,_0x2275ae[_0x9bc1('0x68')][_0x9bc1('0xba')]);}return db[_0x9bc1('0x8a')][_0x9bc1('0x7c')](_0x35af67,{'include':[{'model':db[_0x9bc1('0x9f')],'as':_0x9bc1('0xbb')}]});})['then'](respondWithResult(_0x10b152,null))[_0x9bc1('0x1a')](handleError(_0x10b152,null));};exports[_0x9bc1('0xbc')]=function(_0x1cef0e,_0x45598e){return db[_0x9bc1('0x4b')][_0x9bc1('0x67')]({'where':{'id':_0x1cef0e[_0x9bc1('0x65')]['id']},'include':[{'model':db[_0x9bc1('0x48')],'as':'Smtp','raw':!![],'include':[{'model':db['CloudProvider'],'as':_0x9bc1('0xaa'),'raw':!![]}]}]})[_0x9bc1('0x25')](handleEntityNotFound(_0x45598e,null))['then'](function(_0x1089c2){if(!_0x1089c2[_0x9bc1('0x45')])return;var _0x95695f=_0x1089c2[_0x9bc1('0xb2')]();return respondWithRpcPromise(_0x9bc1('0xbd'),_0x9bc1('0xbc'),{'account':_0x95695f});})[_0x9bc1('0x25')](respondWithResult(_0x45598e,null))[_0x9bc1('0x1a')](handleError(_0x45598e,null));};exports[_0x9bc1('0x26')]=function(_0x2d9fb5,_0xa3bc51){return db['MailAccount']['find']({'where':{'id':_0x2d9fb5[_0x9bc1('0x65')]['id']}})['then'](handleEntityNotFound(_0xa3bc51,null))[_0x9bc1('0x25')](function(_0x22f479){if(_0x22f479&&_0x22f479[_0x9bc1('0x42')]){throw new db[(_0x9bc1('0xbe'))][(_0x9bc1('0xbf'))](_0x9bc1('0xc0'));}return _0x22f479;})[_0x9bc1('0x25')](removeEntity(_0xa3bc51,null))[_0x9bc1('0x1a')](handleError(_0xa3bc51,null));};exports[_0x9bc1('0xc1')]=function(_0x15ad7b,_0x4be0a2){return db[_0x9bc1('0x4b')][_0x9bc1('0x67')]({'where':{'id':_0x15ad7b[_0x9bc1('0x65')]['id']}})[_0x9bc1('0x25')](handleEntityNotFound(_0x4be0a2,null))[_0x9bc1('0x25')](function(_0x41d6ee){if(_0x41d6ee){return _0x41d6ee[_0x9bc1('0xc1')](_0x15ad7b['body']['ids'],_[_0x9bc1('0xc2')](_0x15ad7b['body'],['ids','id'])||{})[_0x9bc1('0xc3')](function(_0x49757e){for(var _0x1873f4=0x0;_0x1873f4<_0x15ad7b['body'][_0x9bc1('0x72')][_0x9bc1('0x57')];_0x1873f4+=0x1){socket['emit'](_0x9bc1('0xc4'),{'UserId':Number(_0x15ad7b['body'][_0x9bc1('0x72')][_0x1873f4]),'MailAccountId':Number(_0x15ad7b[_0x9bc1('0x65')]['id'])});}return _0x49757e;});}})[_0x9bc1('0x25')](respondWithResult(_0x4be0a2,null))[_0x9bc1('0x1a')](handleError(_0x4be0a2,null));};exports[_0x9bc1('0xc5')]=function(_0x563973,_0x3e206e){return db[_0x9bc1('0x4b')]['find']({'where':{'id':_0x563973['params']['id']}})['then'](handleEntityNotFound(_0x3e206e,null))[_0x9bc1('0x25')](function(_0xcc4daa){if(_0xcc4daa){return _0xcc4daa[_0x9bc1('0xc5')](_0x563973[_0x9bc1('0x51')][_0x9bc1('0x72')])['then'](function(){if(_['isArray'](_0x563973[_0x9bc1('0x51')]['ids'])){for(var _0x1c722b=0x0;_0x1c722b<_0x563973['query'][_0x9bc1('0x72')][_0x9bc1('0x57')];_0x1c722b+=0x1){socket[_0x9bc1('0xc6')]('userMailAccount:remove',{'UserId':Number(_0x563973['query']['ids'][_0x1c722b]),'MailAccountId':Number(_0x563973['params']['id'])});}}else{socket[_0x9bc1('0xc6')]('userMailAccount:remove',{'UserId':Number(_0x563973[_0x9bc1('0x51')][_0x9bc1('0x72')]),'MailAccountId':Number(_0x563973[_0x9bc1('0x65')]['id'])});}});}})['then'](respondWithStatusCode(_0x3e206e,null))['catch'](handleError(_0x3e206e,null));};exports[_0x9bc1('0xc7')]=function(_0x22dab8,_0x2e57d3){var _0x8f2a10={};var _0x18d072={};var _0x2489a3;var _0x1c3628;return db['MailAccount'][_0x9bc1('0x6e')]({'where':{'id':_0x22dab8[_0x9bc1('0x65')]['id']}})[_0x9bc1('0x25')](handleEntityNotFound(_0x2e57d3,null))[_0x9bc1('0x25')](function(_0x309881){if(_0x309881){_0x2489a3=_0x309881;_0x18d072[_0x9bc1('0x4f')]=_[_0x9bc1('0x52')](db[_0x9bc1('0x8d')][_0x9bc1('0x6f')]);_0x18d072[_0x9bc1('0x51')]=_[_0x9bc1('0x52')](_0x22dab8[_0x9bc1('0x51')]);_0x18d072[_0x9bc1('0x53')]=_[_0x9bc1('0x54')](_0x18d072[_0x9bc1('0x4f')],_0x18d072[_0x9bc1('0x51')]);_0x8f2a10[_0x9bc1('0x56')]=_[_0x9bc1('0x54')](_0x18d072[_0x9bc1('0x4f')],qs['fields'](_0x22dab8['query'][_0x9bc1('0x55')]));_0x8f2a10[_0x9bc1('0x56')]=_0x8f2a10[_0x9bc1('0x56')][_0x9bc1('0x57')]?_0x8f2a10[_0x9bc1('0x56')]:_0x18d072['model'];_0x8f2a10[_0x9bc1('0x70')]=qs[_0x9bc1('0x5a')](_0x22dab8[_0x9bc1('0x51')][_0x9bc1('0x5a')]);_0x8f2a10[_0x9bc1('0x5b')]=qs[_0x9bc1('0x53')](_[_0x9bc1('0x5c')](_0x22dab8[_0x9bc1('0x51')],_0x18d072[_0x9bc1('0x53')]));if(_0x22dab8[_0x9bc1('0x51')][_0x9bc1('0x5d')]){_0x8f2a10[_0x9bc1('0x5b')]=_[_0x9bc1('0x5e')](_0x8f2a10[_0x9bc1('0x5b')],{'$or':_[_0x9bc1('0x50')](_0x8f2a10[_0x9bc1('0x56')],function(_0x51922d){var _0x411398={};_0x411398[_0x51922d]={'$like':'%'+_0x22dab8[_0x9bc1('0x51')][_0x9bc1('0x5d')]+'%'};return _0x411398;})});}_0x8f2a10=_[_0x9bc1('0x5e')]({},_0x8f2a10,_0x22dab8[_0x9bc1('0x66')]);return _0x2489a3[_0x9bc1('0xc7')](_0x8f2a10);}})[_0x9bc1('0x25')](function(_0x497d6e){if(_0x497d6e){_0x1c3628=_0x497d6e[_0x9bc1('0x57')];if(!_0x22dab8[_0x9bc1('0x51')][_0x9bc1('0x58')](_0x9bc1('0x59'))){_0x8f2a10[_0x9bc1('0x21')]=qs[_0x9bc1('0x21')](_0x22dab8[_0x9bc1('0x51')][_0x9bc1('0x21')]);_0x8f2a10[_0x9bc1('0x1e')]=qs[_0x9bc1('0x1e')](_0x22dab8[_0x9bc1('0x51')][_0x9bc1('0x1e')]);}return _0x2489a3[_0x9bc1('0xc7')](_0x8f2a10);}})['then'](function(_0xfa97aa){if(_0xfa97aa){return _0xfa97aa?{'count':_0x1c3628,'rows':_0xfa97aa}:null;}})['then'](respondWithResult(_0x2e57d3,null))[_0x9bc1('0x1a')](handleError(_0x2e57d3,null));};