Built motion from commit 953226e6.|2.6.32
[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 _0x2d6d=['CmContact','User','Owner','fullname','internal','Tag','tag','transaction','sequelize','Transaction','ISOLATION_LEVELS','MailApplication','destroy','findAndCountAll','priority','send','getApplications','MailMessage','$gte','format','YYYY-MM-DD\x20HH:mm:ss','inlineCss','true','split','CmList','List','Contacts','updatedAt','DESC','CloudProvider','Smtp\x20configuration\x20not\x20found','from','%s\x20<%s>','attachments','join','getSmtpOptions','List\x20not\x20found','defaults','messageId','subject','out','Messages','verifySmtp','VerifySmtp','Sequelize','You\x20can\x27t\x20remove\x20the\x20mail\x20service\x20account','addAgents','spread','emit','userMailAccount:save','userMailAccount:remove','getAgents','moment','bluebird','lodash','ioredis','../../components/parsers/qs','../../config/logger','../../config/environment','../../mysqldb','redis','localhost','socket.io-emitter','./mailAccount.socket','register','jayson/promise','client','http','MailAccount,\x20%s,\x20%s','request\x20sent','debug','MailAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','info','catch','sendStatus','end','status','json','offset','undefined','count','limit','update','then','get','MailAccounts','UserProfileResource','stack','imap.gmail.com','yahoo','hotmail','imap-mail.outlook.com','outlook365','outlook.office365.com','Unknown\x20email\x20service\x20provider','gmail','smtp.gmail.com','smtp.mail.yahoo.com','smtp-mail.outlook.com','smtp.office365.com','user','username','password','pass','modernAuthentication','CloudProviderId','host','port','secure','service','authentication','Imap','Smtp','index','MailServerIn','MailServerOut','mandatoryDispositionPause','map','fieldName','key','model','query','filters','intersection','attributes','length','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','name','options','includeAll','include','MailAccount','findAll','show','params','Pause','keys','rawAttributes','fields','find','body','provider','custom','describe','addDisposition','MailAccountId','Disposition','create','getDispositions','findOne','hasOwnProperty','rows','removeDispositions','ids','addAnswer','CannedAnswer','removeAnswers','isNil','Unable\x20to\x20retrieve\x20the\x20current\x20user','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','getImap','addImap','setImap','getSmtp','addSmtp','removeSmtp','setSmtp','addInteraction','MailInteraction','omit'];(function(_0x43bb57,_0x1bd572){var _0x260a1e=function(_0x41f80b){while(--_0x41f80b){_0x43bb57['push'](_0x43bb57['shift']());}};_0x260a1e(++_0x1bd572);}(_0x2d6d,0xec));var _0xd2d6=function(_0x13b7fd,_0x4eaf7f){_0x13b7fd=_0x13b7fd-0x0;var _0x32a74a=_0x2d6d[_0x13b7fd];return _0x32a74a;};'use strict';var moment=require(_0xd2d6('0x0'));var BPromise=require(_0xd2d6('0x1'));var util=require('util');var path=require('path');var _=require(_0xd2d6('0x2'));var juice=require('juice');var Redis=require(_0xd2d6('0x3'));var qs=require(_0xd2d6('0x4'));var logger=require(_0xd2d6('0x5'))('api');var config=require(_0xd2d6('0x6'));var db=require(_0xd2d6('0x7'))['db'];config[_0xd2d6('0x8')]=_['defaults'](config[_0xd2d6('0x8')],{'host':_0xd2d6('0x9'),'port':0x18eb});var socket=require(_0xd2d6('0xa'))(new Redis(config['redis']));require(_0xd2d6('0xb'))[_0xd2d6('0xc')](socket);var jayson=require(_0xd2d6('0xd'));var client=jayson[_0xd2d6('0xe')][_0xd2d6('0xf')]({'port':0x232b});function respondWithRpcPromise(_0x26db10,_0x19eb2c,_0x41b41e,_0x5cf8b6){return new BPromise(function(_0xe3e2b9,_0x3914b4){var _0x51d1a7=_0x5cf8b6||client;return _0x51d1a7['request'](_0x26db10,_0x41b41e)['then'](function(_0x18e746){logger['info'](_0xd2d6('0x10'),_0x19eb2c,_0xd2d6('0x11'));logger[_0xd2d6('0x12')](_0xd2d6('0x13'),_0x19eb2c,_0xd2d6('0x11'),JSON[_0xd2d6('0x14')](_0x18e746));if(_0x18e746['error']){if(_0x18e746[_0xd2d6('0x15')][_0xd2d6('0x16')]===0x1f4){logger['error'](_0xd2d6('0x10'),_0x19eb2c,_0x18e746[_0xd2d6('0x15')][_0xd2d6('0x17')]);return _0x3914b4(_0x18e746[_0xd2d6('0x15')][_0xd2d6('0x17')]);}logger[_0xd2d6('0x15')]('MailAccount,\x20%s,\x20%s',_0x19eb2c,_0x18e746[_0xd2d6('0x15')][_0xd2d6('0x17')]);return _0xe3e2b9(_0x18e746[_0xd2d6('0x15')]['message']);}else{logger[_0xd2d6('0x18')](_0xd2d6('0x10'),_0x19eb2c,_0xd2d6('0x11'));_0xe3e2b9(_0x18e746['result']['message']);}})[_0xd2d6('0x19')](function(_0x55c328){logger[_0xd2d6('0x15')](_0xd2d6('0x10'),_0x19eb2c,_0x55c328);_0x3914b4(_0x55c328);});});}function respondWithStatusCode(_0x18f0e8,_0x5df1ab){_0x5df1ab=_0x5df1ab||0xcc;return function(_0x1a9e17){if(_0x1a9e17){return _0x18f0e8[_0xd2d6('0x1a')](_0x5df1ab);}return _0x18f0e8['status'](_0x5df1ab)[_0xd2d6('0x1b')]();};}function respondWithResult(_0x95ca,_0x652790){_0x652790=_0x652790||0xc8;return function(_0x56821f){if(_0x56821f){return _0x95ca[_0xd2d6('0x1c')](_0x652790)[_0xd2d6('0x1d')](_0x56821f);}};}function respondWithFilteredResult(_0x545445,_0x3f56af){return function(_0x5ffcd5){if(_0x5ffcd5){var _0x2f0a67=typeof _0x3f56af[_0xd2d6('0x1e')]===_0xd2d6('0x1f')&&typeof _0x3f56af['limit']==='undefined';var _0x21ba09=_0x5ffcd5[_0xd2d6('0x20')];var _0x4d1cee=_0x2f0a67?0x0:_0x3f56af['offset'];var _0x185531=_0x2f0a67?_0x5ffcd5[_0xd2d6('0x20')]:_0x3f56af[_0xd2d6('0x1e')]+_0x3f56af[_0xd2d6('0x21')];var _0x2ff225;if(_0x185531>=_0x21ba09){_0x185531=_0x21ba09;_0x2ff225=0xc8;}else{_0x2ff225=0xce;}_0x545445[_0xd2d6('0x1c')](_0x2ff225);return _0x545445['set']('Content-Range',_0x4d1cee+'-'+_0x185531+'/'+_0x21ba09)['json'](_0x5ffcd5);}return null;};}function saveUpdates(_0x3531ec){return function(_0x1b21a0){if(_0x1b21a0){return _0x1b21a0[_0xd2d6('0x22')](_0x3531ec)[_0xd2d6('0x23')](function(_0x22d85a){return _0x22d85a;});}return null;};}function removeEntity(_0x3f5cd2){return function(_0x3174d3){if(_0x3174d3){return _0x3174d3['destroy']()[_0xd2d6('0x23')](function(){var _0x5c98da=_0x3174d3[_0xd2d6('0x24')]({'plain':!![]});var _0x1cba5d=_0xd2d6('0x25');return db[_0xd2d6('0x26')]['destroy']({'where':{'type':_0x1cba5d,'resourceId':_0x5c98da['id']}})[_0xd2d6('0x23')](function(){return _0x3174d3;});})[_0xd2d6('0x23')](function(){_0x3f5cd2[_0xd2d6('0x1c')](0xcc)['end']();});}};}function handleEntityNotFound(_0xef95c0){return function(_0x1e3eb5){if(!_0x1e3eb5){_0xef95c0[_0xd2d6('0x1a')](0x194);}return _0x1e3eb5;};}function handleError(_0xbed937,_0x2bade1){_0x2bade1=_0x2bade1||0x1f4;return function(_0x4bde24){logger[_0xd2d6('0x15')](_0x4bde24[_0xd2d6('0x27')]);if(_0x4bde24['name']){delete _0x4bde24['name'];}_0xbed937[_0xd2d6('0x1c')](_0x2bade1)['send'](_0x4bde24);};}function getImapHost(_0xaec960){switch(_0xaec960){case'gmail':return _0xd2d6('0x28');case _0xd2d6('0x29'):return'imap.mail.yahoo.com';case _0xd2d6('0x2a'):return _0xd2d6('0x2b');case _0xd2d6('0x2c'):return _0xd2d6('0x2d');}throw new Error(_0xd2d6('0x2e'),_0xaec960);}function getSmtpHost(_0x22a9a2){switch(_0x22a9a2){case _0xd2d6('0x2f'):return _0xd2d6('0x30');case _0xd2d6('0x29'):return _0xd2d6('0x31');case'hotmail':return _0xd2d6('0x32');case'outlook365':return _0xd2d6('0x33');}throw new Error(_0xd2d6('0x2e'),_0x22a9a2);}function getAuthenticationOptions(_0xc4ce7e,_0x1ea9e7){var _0x2eb7f6={};var _0x32033d={};if(_0xc4ce7e){_0x2eb7f6[_0xd2d6('0x34')]=_0x32033d[_0xd2d6('0x34')]=_0x1ea9e7[_0xd2d6('0x35')];_0x2eb7f6[_0xd2d6('0x36')]=_0x32033d[_0xd2d6('0x37')]=_0x1ea9e7[_0xd2d6('0x36')];if(_0x1ea9e7['modernAuthentication']){_0x2eb7f6[_0xd2d6('0x38')]=_0x32033d[_0xd2d6('0x38')]=!![];_0x2eb7f6[_0xd2d6('0x39')]=_0x32033d[_0xd2d6('0x39')]=_0x1ea9e7['CloudProviderId'];_0x2eb7f6[_0xd2d6('0x36')]=_0x32033d[_0xd2d6('0x37')]=null;}else{_0x2eb7f6[_0xd2d6('0x39')]=_0x32033d[_0xd2d6('0x39')]=null;}_0x2eb7f6[_0xd2d6('0x3a')]=getImapHost(_0xc4ce7e);_0x2eb7f6['port']=0x3e1;_0x32033d[_0xd2d6('0x3a')]=getSmtpHost(_0xc4ce7e);_0x32033d[_0xd2d6('0x3b')]=0x24b;_0x32033d[_0xd2d6('0x3c')]=![];_0x2eb7f6[_0xd2d6('0x3d')]=_0x32033d[_0xd2d6('0x3d')]=null;}else{if(_0x1ea9e7[_0xd2d6('0x3e')]){_0x2eb7f6[_0xd2d6('0x34')]=_0x32033d['user']=_0x1ea9e7[_0xd2d6('0x35')];_0x2eb7f6['password']=_0x32033d[_0xd2d6('0x37')]=_0x1ea9e7[_0xd2d6('0x36')];}else{_0x2eb7f6[_0xd2d6('0x3e')]=_0x32033d[_0xd2d6('0x3e')]=![];_0x2eb7f6[_0xd2d6('0x34')]=_0x32033d['user']=null;_0x2eb7f6['password']=_0x32033d['pass']=null;}_0x2eb7f6[_0xd2d6('0x3a')]=_0x1ea9e7[_0xd2d6('0x3f')][_0xd2d6('0x3a')];_0x2eb7f6[_0xd2d6('0x3b')]=_0x1ea9e7['Imap']['port'];_0x32033d[_0xd2d6('0x3a')]=_0x1ea9e7[_0xd2d6('0x40')]['host'];_0x32033d['port']=_0x1ea9e7['Smtp']['port'];}return{'Imap':_0x2eb7f6,'Smtp':_0x32033d};}exports[_0xd2d6('0x41')]=function(_0x4fea03,_0x1c1ecc){var _0x3138f3={'include':[{'model':db[_0xd2d6('0x42')],'as':_0xd2d6('0x3f')},{'model':db[_0xd2d6('0x43')],'as':_0xd2d6('0x40')},{'model':db['Pause'],'as':_0xd2d6('0x44')}]},_0x16d58e={},_0x98e7e5={'count':0x0,'rows':[]};var _0x49e65e=_[_0xd2d6('0x45')](db['MailAccount']['rawAttributes'],function(_0x40e1f9){return{'name':_0x40e1f9[_0xd2d6('0x46')],'type':_0x40e1f9['type'][_0xd2d6('0x47')]};});_0x16d58e[_0xd2d6('0x48')]=_[_0xd2d6('0x45')](_0x49e65e,'name');_0x16d58e[_0xd2d6('0x49')]=_['keys'](_0x4fea03[_0xd2d6('0x49')]);_0x16d58e[_0xd2d6('0x4a')]=_[_0xd2d6('0x4b')](_0x16d58e[_0xd2d6('0x48')],_0x16d58e[_0xd2d6('0x49')]);_0x3138f3['attributes']=_['intersection'](_0x16d58e[_0xd2d6('0x48')],qs['fields'](_0x4fea03[_0xd2d6('0x49')]['fields']));_0x3138f3[_0xd2d6('0x4c')]=_0x3138f3['attributes'][_0xd2d6('0x4d')]?_0x3138f3[_0xd2d6('0x4c')]:_0x16d58e['model'];if(!_0x4fea03[_0xd2d6('0x49')]['hasOwnProperty'](_0xd2d6('0x4e'))){_0x3138f3[_0xd2d6('0x21')]=qs['limit'](_0x4fea03['query'][_0xd2d6('0x21')]);_0x3138f3['offset']=qs[_0xd2d6('0x1e')](_0x4fea03['query']['offset']);}_0x3138f3[_0xd2d6('0x4f')]=qs[_0xd2d6('0x50')](_0x4fea03[_0xd2d6('0x49')][_0xd2d6('0x50')]);_0x3138f3[_0xd2d6('0x51')]=qs['filters'](_[_0xd2d6('0x52')](_0x4fea03[_0xd2d6('0x49')],_0x16d58e[_0xd2d6('0x4a')]),_0x49e65e);if(_0x4fea03[_0xd2d6('0x49')][_0xd2d6('0x53')]){_0x3138f3[_0xd2d6('0x51')]=_[_0xd2d6('0x54')](_0x3138f3[_0xd2d6('0x51')],{'$or':_[_0xd2d6('0x45')](_0x49e65e,function(_0x334230){if(_0x334230['type']!==_0xd2d6('0x55')){var _0x598675={};_0x598675[_0x334230[_0xd2d6('0x56')]]={'$like':'%'+_0x4fea03[_0xd2d6('0x49')]['filter']+'%'};return _0x598675;}})});}_0x3138f3=_['merge']({},_0x3138f3,_0x4fea03[_0xd2d6('0x57')]);var _0x2cba4e={'where':_0x3138f3[_0xd2d6('0x51')]};return db['MailAccount'][_0xd2d6('0x20')](_0x2cba4e)[_0xd2d6('0x23')](function(_0x507608){_0x98e7e5['count']=_0x507608;if(_0x4fea03[_0xd2d6('0x49')][_0xd2d6('0x58')]){_0x3138f3[_0xd2d6('0x59')]=[{'all':!![]}];}return db[_0xd2d6('0x5a')][_0xd2d6('0x5b')](_0x3138f3);})[_0xd2d6('0x23')](function(_0x1790c0){_0x98e7e5['rows']=_0x1790c0;return _0x98e7e5;})['then'](respondWithFilteredResult(_0x1c1ecc,_0x3138f3))[_0xd2d6('0x19')](handleError(_0x1c1ecc,null));};exports[_0xd2d6('0x5c')]=function(_0x8a4fc8,_0x1de4e7){var _0x12b75e={'raw':![],'where':{'id':_0x8a4fc8[_0xd2d6('0x5d')]['id']},'include':[{'model':db[_0xd2d6('0x42')],'as':_0xd2d6('0x3f')},{'model':db['MailServerOut'],'as':_0xd2d6('0x40')},{'model':db[_0xd2d6('0x5e')],'as':_0xd2d6('0x44')}]},_0x231b7b={};_0x231b7b[_0xd2d6('0x48')]=_[_0xd2d6('0x5f')](db[_0xd2d6('0x5a')][_0xd2d6('0x60')]);_0x231b7b[_0xd2d6('0x49')]=_['keys'](_0x8a4fc8['query']);_0x231b7b['filters']=_[_0xd2d6('0x4b')](_0x231b7b['model'],_0x231b7b[_0xd2d6('0x49')]);_0x12b75e[_0xd2d6('0x4c')]=_[_0xd2d6('0x4b')](_0x231b7b['model'],qs['fields'](_0x8a4fc8[_0xd2d6('0x49')][_0xd2d6('0x61')]));_0x12b75e[_0xd2d6('0x4c')]=_0x12b75e['attributes'][_0xd2d6('0x4d')]?_0x12b75e[_0xd2d6('0x4c')]:_0x231b7b[_0xd2d6('0x48')];if(_0x8a4fc8[_0xd2d6('0x49')][_0xd2d6('0x58')]){_0x12b75e['include']=[{'all':!![]}];}_0x12b75e=_[_0xd2d6('0x54')]({},_0x12b75e,_0x8a4fc8[_0xd2d6('0x57')]);return db[_0xd2d6('0x5a')][_0xd2d6('0x62')](_0x12b75e)['then'](handleEntityNotFound(_0x1de4e7,null))[_0xd2d6('0x23')](respondWithResult(_0x1de4e7,null))['catch'](handleError(_0x1de4e7,null));};exports[_0xd2d6('0x22')]=function(_0x38929b,_0x2ebf90){if(_0x38929b[_0xd2d6('0x63')]['id']){delete _0x38929b[_0xd2d6('0x63')]['id'];}var _0xd23946=_0x38929b[_0xd2d6('0x63')][_0xd2d6('0x64')]===_0xd2d6('0x65')?null:_0x38929b[_0xd2d6('0x63')]['provider'];var _0x31c149=_0x38929b[_0xd2d6('0x63')][_0xd2d6('0x3f')]||{};var _0x10bdcc=_0x38929b[_0xd2d6('0x63')]['Smtp']||{};if(_0xd23946){_0x31c149['host']=getImapHost(_0xd23946);_0x31c149[_0xd2d6('0x3b')]=0x3e1;_0x10bdcc[_0xd2d6('0x3a')]=getSmtpHost(_0xd23946);_0x10bdcc['port']=0x24b;_0x10bdcc[_0xd2d6('0x3c')]=![];}if(_0x10bdcc[_0xd2d6('0x38')]){_0x10bdcc['secure']=![];}else{_0x10bdcc[_0xd2d6('0x39')]=null;}if(!_0x31c149['modernAuthentication'])_0x31c149[_0xd2d6('0x39')]=null;_0x38929b[_0xd2d6('0x63')][_0xd2d6('0x3f')]=_0x31c149;_0x38929b['body'][_0xd2d6('0x40')]=_0x10bdcc;return db[_0xd2d6('0x5a')][_0xd2d6('0x62')]({'where':{'id':_0x38929b[_0xd2d6('0x5d')]['id']},'include':[{'model':db[_0xd2d6('0x42')],'as':_0xd2d6('0x3f')},{'model':db[_0xd2d6('0x43')],'as':'Smtp'},{'model':db[_0xd2d6('0x5e')],'as':_0xd2d6('0x44')}]})['then'](handleEntityNotFound(_0x2ebf90,null))['then'](function(_0x449918){if(!_0x449918)throw new Error('Mail\x20Account\x20not\x20found');if(_0x449918[_0xd2d6('0x3d')])delete _0x38929b[_0xd2d6('0x63')]['Imap'];return _0x449918;})[_0xd2d6('0x23')](saveUpdates(_0x38929b['body'],null))[_0xd2d6('0x23')](function(_0x1fb96f){if(!_0x38929b[_0xd2d6('0x63')][_0xd2d6('0x3f')])return _0x1fb96f;return db[_0xd2d6('0x42')][_0xd2d6('0x22')](_0x38929b[_0xd2d6('0x63')][_0xd2d6('0x3f')],{'where':{'MailAccountId':_0x1fb96f['id']}})[_0xd2d6('0x23')](function(){return _0x1fb96f;});})[_0xd2d6('0x23')](function(_0x61299d){if(!_0x38929b[_0xd2d6('0x63')][_0xd2d6('0x40')])return _0x61299d;return db[_0xd2d6('0x43')][_0xd2d6('0x22')](_0x38929b['body'][_0xd2d6('0x40')],{'where':{'MailAccountId':_0x61299d['id']}})[_0xd2d6('0x23')](function(){return _0x61299d;});})[_0xd2d6('0x23')](respondWithResult(_0x2ebf90,null))[_0xd2d6('0x19')](handleError(_0x2ebf90,null));};exports[_0xd2d6('0x66')]=function(_0x286c46,_0x2739eb){return db['MailAccount'][_0xd2d6('0x66')]()[_0xd2d6('0x23')](respondWithResult(_0x2739eb,null))[_0xd2d6('0x19')](handleError(_0x2739eb,null));};exports[_0xd2d6('0x67')]=function(_0x2ed5e4,_0xfbd19e){if(_0x2ed5e4[_0xd2d6('0x63')]['id']){delete _0x2ed5e4['body']['id'];}return db[_0xd2d6('0x5a')][_0xd2d6('0x62')]({'where':{'id':_0x2ed5e4[_0xd2d6('0x5d')]['id']}})[_0xd2d6('0x23')](handleEntityNotFound(_0xfbd19e,null))[_0xd2d6('0x23')](function(_0x240465){if(_0x240465){_0x2ed5e4[_0xd2d6('0x63')][_0xd2d6('0x68')]=_0x240465['id'];return db[_0xd2d6('0x69')][_0xd2d6('0x6a')](_0x2ed5e4[_0xd2d6('0x63')]);}})[_0xd2d6('0x23')](respondWithResult(_0xfbd19e,null))[_0xd2d6('0x19')](handleError(_0xfbd19e,null));};exports[_0xd2d6('0x6b')]=function(_0x1daf99,_0x588a2a){var _0x319b9d={'raw':![],'where':{}};var _0x110cb9={};var _0x49f9be={'count':0x0,'rows':[]};return db[_0xd2d6('0x5a')][_0xd2d6('0x6c')]({'where':{'id':_0x1daf99[_0xd2d6('0x5d')]['id']}})[_0xd2d6('0x23')](handleEntityNotFound(_0x588a2a,null))[_0xd2d6('0x23')](function(_0x35c800){if(_0x35c800){_0x110cb9[_0xd2d6('0x48')]=_[_0xd2d6('0x5f')](db[_0xd2d6('0x69')][_0xd2d6('0x60')]);_0x110cb9[_0xd2d6('0x49')]=_[_0xd2d6('0x5f')](_0x1daf99[_0xd2d6('0x49')]);_0x110cb9[_0xd2d6('0x4a')]=_[_0xd2d6('0x4b')](_0x110cb9[_0xd2d6('0x48')],_0x110cb9[_0xd2d6('0x49')]);_0x319b9d[_0xd2d6('0x4c')]=_[_0xd2d6('0x4b')](_0x110cb9[_0xd2d6('0x48')],qs[_0xd2d6('0x61')](_0x1daf99[_0xd2d6('0x49')][_0xd2d6('0x61')]));_0x319b9d[_0xd2d6('0x4c')]=_0x319b9d[_0xd2d6('0x4c')][_0xd2d6('0x4d')]?_0x319b9d[_0xd2d6('0x4c')]:_0x110cb9[_0xd2d6('0x48')];if(!_0x1daf99[_0xd2d6('0x49')][_0xd2d6('0x6d')]('nolimit')){_0x319b9d[_0xd2d6('0x21')]=qs[_0xd2d6('0x21')](_0x1daf99[_0xd2d6('0x49')]['limit']);_0x319b9d[_0xd2d6('0x1e')]=qs[_0xd2d6('0x1e')](_0x1daf99[_0xd2d6('0x49')][_0xd2d6('0x1e')]);}_0x319b9d[_0xd2d6('0x4f')]=qs['sort'](_0x1daf99[_0xd2d6('0x49')][_0xd2d6('0x50')]);_0x319b9d[_0xd2d6('0x51')]=qs[_0xd2d6('0x4a')](_['pick'](_0x1daf99[_0xd2d6('0x49')],_0x110cb9[_0xd2d6('0x4a')]));_0x319b9d[_0xd2d6('0x51')][_0xd2d6('0x68')]=_0x35c800['id'];if(_0x1daf99['query']['filter']){_0x319b9d[_0xd2d6('0x51')]=_[_0xd2d6('0x54')](_0x319b9d[_0xd2d6('0x51')],{'$or':_[_0xd2d6('0x45')](_0x319b9d['attributes'],function(_0x560fc8){var _0x2ceeee={};_0x2ceeee[_0x560fc8]={'$like':'%'+_0x1daf99[_0xd2d6('0x49')][_0xd2d6('0x53')]+'%'};return _0x2ceeee;})});}_0x319b9d=_['merge']({},_0x319b9d,_0x1daf99[_0xd2d6('0x57')]);return db[_0xd2d6('0x69')][_0xd2d6('0x20')]({'where':_0x319b9d['where']})[_0xd2d6('0x23')](function(_0x2eccb5){_0x49f9be['count']=_0x2eccb5;if(_0x1daf99[_0xd2d6('0x49')][_0xd2d6('0x58')]){_0x319b9d[_0xd2d6('0x59')]=[{'all':!![]}];}return db['Disposition'][_0xd2d6('0x5b')](_0x319b9d);})[_0xd2d6('0x23')](function(_0x2efc0d){_0x49f9be[_0xd2d6('0x6e')]=_0x2efc0d;return _0x49f9be;});}})[_0xd2d6('0x23')](respondWithFilteredResult(_0x588a2a,_0x319b9d))[_0xd2d6('0x19')](handleError(_0x588a2a,null));};exports[_0xd2d6('0x6f')]=function(_0x497e27,_0x54bbac){return db[_0xd2d6('0x5a')][_0xd2d6('0x62')]({'where':{'id':_0x497e27[_0xd2d6('0x5d')]['id']}})[_0xd2d6('0x23')](handleEntityNotFound(_0x54bbac,null))[_0xd2d6('0x23')](function(_0x3f47e8){if(_0x3f47e8){return _0x3f47e8[_0xd2d6('0x6f')](_0x497e27[_0xd2d6('0x49')][_0xd2d6('0x70')]);}})[_0xd2d6('0x23')](respondWithStatusCode(_0x54bbac,null))['catch'](handleError(_0x54bbac,null));};exports[_0xd2d6('0x71')]=function(_0x3cfe22,_0x3de25d){if(_0x3cfe22['body']['id']){delete _0x3cfe22['body']['id'];}return db[_0xd2d6('0x5a')]['find']({'where':{'id':_0x3cfe22[_0xd2d6('0x5d')]['id']}})[_0xd2d6('0x23')](handleEntityNotFound(_0x3de25d,null))[_0xd2d6('0x23')](function(_0x3ad821){if(_0x3ad821){_0x3cfe22[_0xd2d6('0x63')][_0xd2d6('0x68')]=_0x3ad821['id'];return db['CannedAnswer'][_0xd2d6('0x6a')](_0x3cfe22['body']);}})[_0xd2d6('0x23')](respondWithResult(_0x3de25d,null))[_0xd2d6('0x19')](handleError(_0x3de25d,null));};exports['getAnswers']=function(_0x211c8f,_0x348bde){var _0x5a2795={'raw':![],'where':{}};var _0x81f538={};var _0x2802bb={'count':0x0,'rows':[]};return db['MailAccount']['findOne']({'where':{'id':_0x211c8f[_0xd2d6('0x5d')]['id']}})['then'](handleEntityNotFound(_0x348bde,null))['then'](function(_0x3cfd2d){if(_0x3cfd2d){_0x81f538['model']=_[_0xd2d6('0x5f')](db['CannedAnswer'][_0xd2d6('0x60')]);_0x81f538[_0xd2d6('0x49')]=_[_0xd2d6('0x5f')](_0x211c8f[_0xd2d6('0x49')]);_0x81f538[_0xd2d6('0x4a')]=_['intersection'](_0x81f538[_0xd2d6('0x48')],_0x81f538[_0xd2d6('0x49')]);_0x5a2795[_0xd2d6('0x4c')]=_[_0xd2d6('0x4b')](_0x81f538['model'],qs['fields'](_0x211c8f[_0xd2d6('0x49')]['fields']));_0x5a2795[_0xd2d6('0x4c')]=_0x5a2795['attributes'][_0xd2d6('0x4d')]?_0x5a2795[_0xd2d6('0x4c')]:_0x81f538[_0xd2d6('0x48')];if(!_0x211c8f[_0xd2d6('0x49')]['hasOwnProperty'](_0xd2d6('0x4e'))){_0x5a2795[_0xd2d6('0x21')]=qs[_0xd2d6('0x21')](_0x211c8f[_0xd2d6('0x49')][_0xd2d6('0x21')]);_0x5a2795[_0xd2d6('0x1e')]=qs[_0xd2d6('0x1e')](_0x211c8f[_0xd2d6('0x49')][_0xd2d6('0x1e')]);}_0x5a2795[_0xd2d6('0x4f')]=qs[_0xd2d6('0x50')](_0x211c8f[_0xd2d6('0x49')][_0xd2d6('0x50')]);_0x5a2795['where']=qs['filters'](_[_0xd2d6('0x52')](_0x211c8f[_0xd2d6('0x49')],_0x81f538[_0xd2d6('0x4a')]));_0x5a2795[_0xd2d6('0x51')]['MailAccountId']=_0x3cfd2d['id'];if(_0x211c8f[_0xd2d6('0x49')][_0xd2d6('0x53')]){_0x5a2795[_0xd2d6('0x51')]=_[_0xd2d6('0x54')](_0x5a2795[_0xd2d6('0x51')],{'$or':_[_0xd2d6('0x45')](_0x5a2795[_0xd2d6('0x4c')],function(_0x5f0e1e){var _0x561ae0={};_0x561ae0[_0x5f0e1e]={'$like':'%'+_0x211c8f[_0xd2d6('0x49')][_0xd2d6('0x53')]+'%'};return _0x561ae0;})});}_0x5a2795=_['merge']({},_0x5a2795,_0x211c8f[_0xd2d6('0x57')]);return db['CannedAnswer'][_0xd2d6('0x20')]({'where':_0x5a2795[_0xd2d6('0x51')]})[_0xd2d6('0x23')](function(_0x520233){_0x2802bb[_0xd2d6('0x20')]=_0x520233;if(_0x211c8f[_0xd2d6('0x49')]['includeAll']){_0x5a2795[_0xd2d6('0x59')]=[{'all':!![]}];}return db[_0xd2d6('0x72')]['findAll'](_0x5a2795);})['then'](function(_0x25c059){_0x2802bb[_0xd2d6('0x6e')]=_0x25c059;return _0x2802bb;});}})[_0xd2d6('0x23')](respondWithFilteredResult(_0x348bde,_0x5a2795))[_0xd2d6('0x19')](handleError(_0x348bde,null));};exports[_0xd2d6('0x73')]=function(_0x17d605,_0xcbfb7d){return db['MailAccount'][_0xd2d6('0x62')]({'where':{'id':_0x17d605[_0xd2d6('0x5d')]['id']}})['then'](handleEntityNotFound(_0xcbfb7d,null))['then'](function(_0x179f50){if(_0x179f50){return _0x179f50[_0xd2d6('0x73')](_0x17d605[_0xd2d6('0x49')][_0xd2d6('0x70')]);}})[_0xd2d6('0x23')](respondWithStatusCode(_0xcbfb7d,null))[_0xd2d6('0x19')](handleError(_0xcbfb7d,null));};exports[_0xd2d6('0x6a')]=function(_0x4c1a36,_0x32d98b){var _0x45a460={'name':_0x4c1a36['body']['name'],'key':_0x4c1a36['body'][_0xd2d6('0x47')],'provider':_0x4c1a36[_0xd2d6('0x63')]['provider']===_0xd2d6('0x65')?null:_0x4c1a36[_0xd2d6('0x63')][_0xd2d6('0x64')],'email':_0x4c1a36[_0xd2d6('0x63')]['email'],'ListId':_0x4c1a36[_0xd2d6('0x63')]['ListId'],'active':!_[_0xd2d6('0x74')](_0x4c1a36[_0xd2d6('0x63')]['active'])?_0x4c1a36[_0xd2d6('0x63')]['active']:!![],'description':_0x4c1a36['body']['description']||null};var _0x258942=getAuthenticationOptions(_0x45a460['provider'],_0x4c1a36[_0xd2d6('0x63')]);_0x45a460[_0xd2d6('0x3f')]=_0x258942[_0xd2d6('0x3f')];_0x45a460['Smtp']=_0x258942[_0xd2d6('0x40')];return db[_0xd2d6('0x5a')][_0xd2d6('0x6a')](_0x45a460,{'include':[{'model':db[_0xd2d6('0x43')],'as':_0xd2d6('0x40')},{'model':db[_0xd2d6('0x42')],'as':_0xd2d6('0x3f')}]})[_0xd2d6('0x23')](function(_0x8b0119){var _0x51fdfb=_0x4c1a36['user'][_0xd2d6('0x24')]({'plain':!![]});if(!_0x51fdfb)throw new Error(_0xd2d6('0x75'));if(_0x51fdfb['role']===_0xd2d6('0x34')){var _0x58c178=_0x8b0119[_0xd2d6('0x24')]({'plain':!![]});return db[_0xd2d6('0x76')][_0xd2d6('0x62')]({'where':{'name':_0xd2d6('0x25'),'userProfileId':_0x51fdfb[_0xd2d6('0x77')]},'raw':!![]})[_0xd2d6('0x23')](function(_0x293693){if(_0x293693&&_0x293693[_0xd2d6('0x78')]===0x0){return db['UserProfileResource'][_0xd2d6('0x6a')]({'name':_0x58c178[_0xd2d6('0x56')],'resourceId':_0x58c178['id'],'type':_0x293693[_0xd2d6('0x56')],'sectionId':_0x293693['id']},{})[_0xd2d6('0x23')](function(){return _0x8b0119;});}else{return _0x8b0119;}})[_0xd2d6('0x19')](function(_0x3bd403){logger[_0xd2d6('0x15')](_0xd2d6('0x79'),_0x3bd403);throw _0x3bd403;});}return _0x8b0119;})[_0xd2d6('0x23')](respondWithResult(_0x32d98b,0xc9))[_0xd2d6('0x19')](handleError(_0x32d98b,null));};exports[_0xd2d6('0x7a')]=function(_0x43dd36,_0x2551c1){return db['MailAccount']['findOne']({'where':{'id':_0x43dd36[_0xd2d6('0x5d')]['id']}})[_0xd2d6('0x23')](handleEntityNotFound(_0x2551c1,null))['then'](function(_0x2b322d){if(_0x2b322d){return _0x2b322d[_0xd2d6('0x7a')]();}return null;})[_0xd2d6('0x23')](respondWithResult(_0x2551c1,null))[_0xd2d6('0x19')](handleError(_0x2551c1,null));};exports[_0xd2d6('0x7b')]=function(_0x382a65,_0x47cdfa){if(_0x382a65[_0xd2d6('0x63')]['id']){delete _0x382a65[_0xd2d6('0x63')]['id'];}return db[_0xd2d6('0x5a')][_0xd2d6('0x62')]({'where':{'id':_0x382a65[_0xd2d6('0x5d')]['id']}})[_0xd2d6('0x23')](handleEntityNotFound(_0x47cdfa,null))[_0xd2d6('0x23')](function(_0x1f2910){if(_0x1f2910){_0x382a65[_0xd2d6('0x63')][_0xd2d6('0x68')]=_0x1f2910['id'];return db[_0xd2d6('0x42')][_0xd2d6('0x6a')](_0x382a65[_0xd2d6('0x63')]);}})['then'](respondWithResult(_0x47cdfa,null))[_0xd2d6('0x19')](handleError(_0x47cdfa,null));};exports['removeImap']=function(_0x53cffb,_0x31e013){return db['MailAccount'][_0xd2d6('0x6c')]({'where':{'id':_0x53cffb[_0xd2d6('0x5d')]['id']}})[_0xd2d6('0x23')](handleEntityNotFound(_0x31e013,null))[_0xd2d6('0x23')](function(_0xe99a88){if(_0xe99a88){return _0xe99a88[_0xd2d6('0x7c')](null);}return null;})[_0xd2d6('0x23')](respondWithStatusCode(_0x31e013,null))[_0xd2d6('0x19')](handleError(_0x31e013,null));};exports[_0xd2d6('0x7d')]=function(_0x39c835,_0x49a3d7){return db[_0xd2d6('0x5a')]['findOne']({'where':{'id':_0x39c835['params']['id']}})[_0xd2d6('0x23')](handleEntityNotFound(_0x49a3d7,null))[_0xd2d6('0x23')](function(_0x21a06f){if(_0x21a06f){return _0x21a06f[_0xd2d6('0x7d')]();}return null;})[_0xd2d6('0x23')](respondWithResult(_0x49a3d7,null))[_0xd2d6('0x19')](handleError(_0x49a3d7,null));};exports[_0xd2d6('0x7e')]=function(_0x1a0ca3,_0x57ff1d){if(_0x1a0ca3[_0xd2d6('0x63')]['id']){delete _0x1a0ca3[_0xd2d6('0x63')]['id'];}return db[_0xd2d6('0x5a')][_0xd2d6('0x62')]({'where':{'id':_0x1a0ca3[_0xd2d6('0x5d')]['id']}})[_0xd2d6('0x23')](handleEntityNotFound(_0x57ff1d,null))[_0xd2d6('0x23')](function(_0x464312){if(_0x464312){_0x1a0ca3[_0xd2d6('0x63')]['MailAccountId']=_0x464312['id'];return db['MailServerOut']['create'](_0x1a0ca3[_0xd2d6('0x63')]);}})[_0xd2d6('0x23')](respondWithResult(_0x57ff1d,null))[_0xd2d6('0x19')](handleError(_0x57ff1d,null));};exports[_0xd2d6('0x7f')]=function(_0x28fd99,_0x3caf87){return db[_0xd2d6('0x5a')][_0xd2d6('0x6c')]({'where':{'id':_0x28fd99[_0xd2d6('0x5d')]['id']}})[_0xd2d6('0x23')](handleEntityNotFound(_0x3caf87,null))[_0xd2d6('0x23')](function(_0x1ccf32){if(_0x1ccf32){return _0x1ccf32[_0xd2d6('0x80')](null);}return null;})[_0xd2d6('0x23')](respondWithStatusCode(_0x3caf87,null))[_0xd2d6('0x19')](handleError(_0x3caf87,null));};exports[_0xd2d6('0x81')]=function(_0x33d67a,_0x3dd25e){return db[_0xd2d6('0x82')]['find']({'where':{'id':_0x33d67a[_0xd2d6('0x5d')]['id']}})[_0xd2d6('0x23')](handleEntityNotFound(_0x3dd25e,null))['then'](function(_0x51ba60){if(_0x51ba60){return _0x51ba60[_0xd2d6('0x81')](_0x33d67a[_0xd2d6('0x63')]['ids'],_[_0xd2d6('0x83')](_0x33d67a[_0xd2d6('0x63')],['ids','id'])||{});}})[_0xd2d6('0x23')](respondWithResult(_0x3dd25e,null))[_0xd2d6('0x19')](handleError(_0x3dd25e,null));};exports['getInteractions']=function(_0x92d387,_0x5f1ce3){var _0x25d191={'raw':![],'where':{}};var _0x56e966={};var _0x35521a={'count':0x0,'rows':[]};return db['MailAccount'][_0xd2d6('0x6c')]({'where':{'id':_0x92d387[_0xd2d6('0x5d')]['id']}})[_0xd2d6('0x23')](handleEntityNotFound(_0x5f1ce3,null))['then'](function(_0x354940){if(_0x354940){_0x56e966[_0xd2d6('0x48')]=_[_0xd2d6('0x5f')](db['MailInteraction'][_0xd2d6('0x60')]);_0x56e966['query']=_['keys'](_0x92d387[_0xd2d6('0x49')]);_0x56e966[_0xd2d6('0x4a')]=_[_0xd2d6('0x4b')](_0x56e966[_0xd2d6('0x48')],_0x56e966[_0xd2d6('0x49')]);_0x25d191[_0xd2d6('0x4c')]=_[_0xd2d6('0x4b')](_0x56e966[_0xd2d6('0x48')],qs['fields'](_0x92d387['query'][_0xd2d6('0x61')]));_0x25d191[_0xd2d6('0x4c')]=_0x25d191[_0xd2d6('0x4c')][_0xd2d6('0x4d')]?_0x25d191[_0xd2d6('0x4c')]:_0x56e966['model'];if(!_0x92d387['query'][_0xd2d6('0x6d')]('nolimit')){_0x25d191['limit']=qs[_0xd2d6('0x21')](_0x92d387[_0xd2d6('0x49')]['limit']);_0x25d191[_0xd2d6('0x1e')]=qs[_0xd2d6('0x1e')](_0x92d387['query'][_0xd2d6('0x1e')]);}_0x25d191[_0xd2d6('0x4f')]=qs[_0xd2d6('0x50')](_0x92d387[_0xd2d6('0x49')][_0xd2d6('0x50')]);_0x25d191[_0xd2d6('0x51')]=qs[_0xd2d6('0x4a')](_[_0xd2d6('0x52')](_0x92d387[_0xd2d6('0x49')],_0x56e966['filters']));_0x25d191[_0xd2d6('0x51')][_0xd2d6('0x68')]=_0x354940['id'];if(_0x92d387[_0xd2d6('0x49')]['filter']){_0x25d191['where']=_[_0xd2d6('0x54')](_0x25d191[_0xd2d6('0x51')],{'$or':_[_0xd2d6('0x45')](_0x25d191[_0xd2d6('0x4c')],function(_0x5eb27f){var _0x5d2ad8={};_0x5d2ad8[_0x5eb27f]={'$like':'%'+_0x92d387[_0xd2d6('0x49')][_0xd2d6('0x53')]+'%'};return _0x5d2ad8;})});}_0x25d191=_[_0xd2d6('0x54')]({},_0x25d191,_0x92d387[_0xd2d6('0x57')]);return db[_0xd2d6('0x82')]['count']({'where':_0x25d191[_0xd2d6('0x51')]})[_0xd2d6('0x23')](function(_0x17a5fa){_0x35521a[_0xd2d6('0x20')]=_0x17a5fa;if(_0x92d387[_0xd2d6('0x49')]['includeAll']){_0x25d191['include']=[{'model':db[_0xd2d6('0x84')],'as':'Contact','required':![]},{'model':db[_0xd2d6('0x85')],'as':_0xd2d6('0x86'),'attributes':[_0xd2d6('0x56'),_0xd2d6('0x87'),_0xd2d6('0x88')],'required':![]},{'model':db[_0xd2d6('0x89')],'as':'Tags','attributes':['id',_0xd2d6('0x56'),'color'],'where':_0x92d387[_0xd2d6('0x49')][_0xd2d6('0x8a')]?{'id':_0x92d387[_0xd2d6('0x49')][_0xd2d6('0x8a')]}:undefined,'required':_0x92d387[_0xd2d6('0x49')]['tag']?!![]:![]}];}return db[_0xd2d6('0x82')][_0xd2d6('0x5b')](_0x25d191);})[_0xd2d6('0x23')](function(_0x11339b){_0x35521a[_0xd2d6('0x6e')]=_0x11339b;return _0x35521a;});}})[_0xd2d6('0x23')](respondWithFilteredResult(_0x5f1ce3,_0x25d191))[_0xd2d6('0x19')](handleError(_0x5f1ce3,null));};exports['addApplications']=function addApplications(_0x17e9fd,_0x38d42e){var _0x2d4d22=_0x17e9fd[_0xd2d6('0x5d')]['id'];var _0x2078f5=_0x17e9fd[_0xd2d6('0x63')];var _0x3027cb=0xc8;var _0x114981=null;return db['sequelize'][_0xd2d6('0x8b')]({'isolationLevel':db[_0xd2d6('0x8c')][_0xd2d6('0x8d')][_0xd2d6('0x8e')]['READ_COMMITTED']},function(_0x32a2da){return db[_0xd2d6('0x5a')][_0xd2d6('0x6c')]({'where':{'id':_0x2d4d22},'transaction':_0x32a2da})[_0xd2d6('0x23')](function(_0x43db57){if(_0x43db57){return db[_0xd2d6('0x8f')][_0xd2d6('0x90')]({'where':{'MailAccountId':_0x2d4d22},'transaction':_0x32a2da})['then'](function(){var _0x2e1159=_[_0xd2d6('0x45')](_0x2078f5,function(_0x325803){_0x325803[_0xd2d6('0x68')]=_0x2d4d22;return _0x325803;});return db[_0xd2d6('0x8f')]['bulkCreate'](_0x2e1159,{'transaction':_0x32a2da});});}else{_0x3027cb=0x194;_0x114981=[];}});})[_0xd2d6('0x23')](function(){if(_0x3027cb!==0x194){return db[_0xd2d6('0x8f')][_0xd2d6('0x91')]({'where':{'MailAccountId':_0x2d4d22},'order':_0xd2d6('0x92')})[_0xd2d6('0x23')](function(_0x2ac13f){_0x114981=_0x2ac13f;});}})['catch'](function(_0x557fbb){_0x3027cb=0x1f4;logger['error'](_0x557fbb[_0xd2d6('0x27')]);if(_0x557fbb['name']){delete _0x557fbb[_0xd2d6('0x56')];}_0x114981=_0x557fbb;})['finally'](function(){if(_0x114981===null){_0x38d42e['sendStatus'](_0x3027cb);}else{if(_0x3027cb===0x1f4){_0x38d42e['status'](_0x3027cb)[_0xd2d6('0x93')](_0x114981);}else{_0x38d42e['status'](_0x3027cb)[_0xd2d6('0x1d')](_0x114981);}}});};exports[_0xd2d6('0x94')]=function(_0x17b865,_0x36c14c){var _0x342297={};var _0x4c237e={};var _0x413035;var _0x4aecdd;return db[_0xd2d6('0x5a')][_0xd2d6('0x6c')]({'where':{'id':_0x17b865[_0xd2d6('0x5d')]['id']}})[_0xd2d6('0x23')](handleEntityNotFound(_0x36c14c,null))[_0xd2d6('0x23')](function(_0x12f416){if(_0x12f416){_0x413035=_0x12f416;_0x4c237e[_0xd2d6('0x48')]=_[_0xd2d6('0x5f')](db[_0xd2d6('0x8f')][_0xd2d6('0x60')]);_0x4c237e['query']=_[_0xd2d6('0x5f')](_0x17b865[_0xd2d6('0x49')]);_0x4c237e[_0xd2d6('0x4a')]=_[_0xd2d6('0x4b')](_0x4c237e['model'],_0x4c237e[_0xd2d6('0x49')]);_0x342297['attributes']=_[_0xd2d6('0x4b')](_0x4c237e[_0xd2d6('0x48')],qs[_0xd2d6('0x61')](_0x17b865['query'][_0xd2d6('0x61')]));_0x342297[_0xd2d6('0x4c')]=_0x342297[_0xd2d6('0x4c')][_0xd2d6('0x4d')]?_0x342297['attributes']:_0x4c237e[_0xd2d6('0x48')];_0x342297[_0xd2d6('0x4f')]=qs['sort'](_0x17b865[_0xd2d6('0x49')][_0xd2d6('0x50')]);_0x342297['where']=qs[_0xd2d6('0x4a')](_[_0xd2d6('0x52')](_0x17b865[_0xd2d6('0x49')],_0x4c237e[_0xd2d6('0x4a')]));if(_0x17b865['query']['filter']){_0x342297['where']=_[_0xd2d6('0x54')](_0x342297[_0xd2d6('0x51')],{'$or':_['map'](_0x342297['attributes'],function(_0x4c6d13){var _0x24a8ac={};_0x24a8ac[_0x4c6d13]={'$like':'%'+_0x17b865[_0xd2d6('0x49')][_0xd2d6('0x53')]+'%'};return _0x24a8ac;})});}_0x342297=_[_0xd2d6('0x54')]({},_0x342297,_0x17b865[_0xd2d6('0x57')]);return _0x413035[_0xd2d6('0x94')](_0x342297);}})[_0xd2d6('0x23')](function(_0x208041){if(_0x208041){_0x4aecdd=_0x208041[_0xd2d6('0x4d')];if(!_0x17b865['query'][_0xd2d6('0x6d')]('nolimit')){_0x342297[_0xd2d6('0x21')]=qs[_0xd2d6('0x21')](_0x17b865[_0xd2d6('0x49')][_0xd2d6('0x21')]);_0x342297[_0xd2d6('0x1e')]=qs[_0xd2d6('0x1e')](_0x17b865[_0xd2d6('0x49')][_0xd2d6('0x1e')]);}return _0x413035['getApplications'](_0x342297);}})[_0xd2d6('0x23')](function(_0x2f7a2f){if(_0x2f7a2f){return _0x2f7a2f?{'count':_0x4aecdd,'rows':_0x2f7a2f}:null;}})[_0xd2d6('0x23')](respondWithResult(_0x36c14c,null))[_0xd2d6('0x19')](handleError(_0x36c14c,null));};exports['getMessages']=function(_0x373612,_0x3bf729){var _0x3b8693={'raw':!![],'where':{}};var _0x2f0481={};var _0x2bef9f={'count':0x0,'rows':[]};return db[_0xd2d6('0x5a')][_0xd2d6('0x6c')]({'where':{'id':_0x373612[_0xd2d6('0x5d')]['id']}})[_0xd2d6('0x23')](handleEntityNotFound(_0x3bf729,null))['then'](function(_0x558967){if(_0x558967){_0x2f0481[_0xd2d6('0x48')]=_[_0xd2d6('0x5f')](db[_0xd2d6('0x95')]['rawAttributes']);_0x2f0481['query']=_['keys'](_0x373612[_0xd2d6('0x49')]);_0x2f0481[_0xd2d6('0x4a')]=_['intersection'](_0x2f0481[_0xd2d6('0x48')],_0x2f0481[_0xd2d6('0x49')]);_0x3b8693['attributes']=_['intersection'](_0x2f0481[_0xd2d6('0x48')],qs[_0xd2d6('0x61')](_0x373612[_0xd2d6('0x49')][_0xd2d6('0x61')]));_0x3b8693[_0xd2d6('0x4c')]=_0x3b8693[_0xd2d6('0x4c')][_0xd2d6('0x4d')]?_0x3b8693[_0xd2d6('0x4c')]:_0x2f0481['model'];if(!_0x373612[_0xd2d6('0x49')][_0xd2d6('0x6d')](_0xd2d6('0x4e'))){_0x3b8693['limit']=qs[_0xd2d6('0x21')](_0x373612['query']['limit']);_0x3b8693['offset']=qs[_0xd2d6('0x1e')](_0x373612[_0xd2d6('0x49')][_0xd2d6('0x1e')]);}_0x3b8693[_0xd2d6('0x4f')]=qs['sort'](_0x373612[_0xd2d6('0x49')][_0xd2d6('0x50')]);_0x3b8693[_0xd2d6('0x51')]=qs[_0xd2d6('0x4a')](_['pick'](_0x373612[_0xd2d6('0x49')],_0x2f0481['filters']));_0x3b8693[_0xd2d6('0x51')][_0xd2d6('0x68')]=_0x558967['id'];if(_0x373612[_0xd2d6('0x49')][_0xd2d6('0x53')]){_0x3b8693[_0xd2d6('0x51')]=_[_0xd2d6('0x54')](_0x3b8693[_0xd2d6('0x51')],{'$or':_['map'](_0x3b8693[_0xd2d6('0x4c')],function(_0x355b12){var _0x24508d={};_0x24508d[_0x355b12]={'$like':'%'+_0x373612[_0xd2d6('0x49')]['filter']+'%'};return _0x24508d;})});}if(_0x373612[_0xd2d6('0x49')][_0xd2d6('0x96')]){var _0x2f8add=_0x373612['query']['$gte']['split'](',');var _0xf3a7de={};_0xf3a7de[_0x2f8add[0x0]]={'$gte':moment(_0x2f8add[0x1])[_0xd2d6('0x97')](_0xd2d6('0x98'))};_0x3b8693[_0xd2d6('0x51')]=_[_0xd2d6('0x54')](_0x3b8693[_0xd2d6('0x51')],_0xf3a7de);}_0x3b8693=_[_0xd2d6('0x54')]({},_0x3b8693,_0x373612[_0xd2d6('0x57')]);return db[_0xd2d6('0x95')][_0xd2d6('0x20')]({'where':_0x3b8693[_0xd2d6('0x51')]})[_0xd2d6('0x23')](function(_0x204a28){_0x2bef9f[_0xd2d6('0x20')]=_0x204a28;if(_0x373612['query'][_0xd2d6('0x58')]){_0x3b8693[_0xd2d6('0x59')]=[{'all':!![]}];}return db[_0xd2d6('0x95')][_0xd2d6('0x5b')](_0x3b8693);})[_0xd2d6('0x23')](function(_0x20677a){if(_0x373612[_0xd2d6('0x49')][_0xd2d6('0x99')]===_0xd2d6('0x9a')){for(var _0x29d46b=0x0;_0x29d46b<_0x20677a[_0xd2d6('0x4d')];_0x29d46b++){_0x20677a[_0x29d46b][_0xd2d6('0x63')]=juice(_0x20677a[_0x29d46b][_0xd2d6('0x63')]);}}_0x2bef9f[_0xd2d6('0x6e')]=_0x20677a;return _0x2bef9f;});}})['then'](respondWithFilteredResult(_0x3bf729,_0x3b8693))[_0xd2d6('0x19')](handleError(_0x3bf729,null));};exports[_0xd2d6('0x93')]=function(_0x2e925b,_0x3b3443){var _0x5a4cdd,_0x1d74a0={},_0x116a0d;if(_0x2e925b['body']['to']){_0x116a0d=_0x2e925b[_0xd2d6('0x63')]['to'][_0xd2d6('0x9b')](',')[0x0];}return db['MailAccount'][_0xd2d6('0x62')]({'where':{'id':_0x2e925b[_0xd2d6('0x5d')]['id']},'include':[{'model':db[_0xd2d6('0x9c')],'as':_0xd2d6('0x9d'),'include':[{'model':db[_0xd2d6('0x84')],'as':_0xd2d6('0x9e'),'where':{'email':_0x116a0d},'limit':0x1,'order':[[_0xd2d6('0x9f'),_0xd2d6('0xa0')]]}]},{'model':db[_0xd2d6('0x43')],'as':_0xd2d6('0x40'),'raw':!![],'include':[{'model':db[_0xd2d6('0xa1')],'as':'CloudProvider','raw':!![]}]}]})[_0xd2d6('0x23')](handleEntityNotFound(_0x3b3443,null))['then'](function(_0x15f1a7){if(!_0x15f1a7)return;_0x5a4cdd=_0x15f1a7;if(!_0x15f1a7[_0xd2d6('0x40')])throw new Error(_0xd2d6('0xa2'));if(_[_0xd2d6('0x74')](_0x2e925b[_0xd2d6('0x63')][_0xd2d6('0xa3')])){_0x2e925b[_0xd2d6('0x63')][_0xd2d6('0xa3')]=util[_0xd2d6('0x97')](_0xd2d6('0xa4'),_0x15f1a7[_0xd2d6('0x56')],_0x15f1a7['email']||_0x15f1a7[_0xd2d6('0x40')][_0xd2d6('0x34')]);}if(_0x2e925b['body'][_0xd2d6('0xa5')]&&_0x2e925b[_0xd2d6('0x63')][_0xd2d6('0xa5')]['length']){for(var _0x46dd44=0x0;_0x46dd44<_0x2e925b['body']['attachments']['length'];_0x46dd44+=0x1){_0x2e925b[_0xd2d6('0x63')][_0xd2d6('0xa5')][_0x46dd44]={'filename':_0x2e925b[_0xd2d6('0x63')]['attachments'][_0x46dd44][_0xd2d6('0x56')],'path':path[_0xd2d6('0xa6')](config['root'],'server/files/attachments',_0x2e925b['body'][_0xd2d6('0xa5')][_0x46dd44]['basename'])};}}var _0x33b7bb=_0x15f1a7[_0xd2d6('0xa7')]();return respondWithRpcPromise('SendMail','sendMail',{'account':_0x33b7bb,'message':_0x2e925b['body']});})[_0xd2d6('0x23')](function(_0xe5730a){if(!_0xe5730a)return;_0x1d74a0=_0xe5730a;if(!_0x5a4cdd[_0xd2d6('0x9d')])throw new Error(_0xd2d6('0xa8'));if(_0x5a4cdd[_0xd2d6('0x9d')][_0xd2d6('0x9e')][_0xd2d6('0x4d')])return _0x5a4cdd[_0xd2d6('0x9d')][_0xd2d6('0x9e')][0x0];return db[_0xd2d6('0x84')][_0xd2d6('0x6a')](_[_0xd2d6('0xa9')](_0x2e925b[_0xd2d6('0x63')],{'firstName':_0x2e925b[_0xd2d6('0x63')]['to'],'email':_0x2e925b[_0xd2d6('0x63')]['to'],'phone':_0x2e925b[_0xd2d6('0x63')]['to'],'ListId':_0x5a4cdd['ListId']}));})['then'](function(_0x70e6b2){if(!_0x70e6b2)return;var _0x39bbc4={'UserId':_0x2e925b[_0xd2d6('0x34')]['id'],'ContactId':_0x70e6b2['id'],'MailAccountId':_0x5a4cdd['id'],'inReplyTo':_0x1d74a0[_0xd2d6('0xaa')],'to':_0x2e925b[_0xd2d6('0x63')]['from'],'cc':_0x2e925b['body']['cc'],'subject':_0x2e925b[_0xd2d6('0x63')][_0xd2d6('0xab')],'attach':_0x2e925b['body']['attach'],'firstMsgDirection':'out','lastMsgAt':moment()[_0xd2d6('0x97')](_0xd2d6('0x98')),'lastMsgDirection':_0xd2d6('0xac'),'Messages':[_[_0xd2d6('0x54')](_0x2e925b[_0xd2d6('0x63')],{'messageId':_0x1d74a0[_0xd2d6('0xaa')],'sentAt':moment()['format'](_0xd2d6('0x98')),'read':!![],'MailAccountId':_0x5a4cdd['id'],'UserId':_0x2e925b[_0xd2d6('0x34')]['id'],'ContactId':_0x70e6b2['id']})]};if(_0x2e925b[_0xd2d6('0x63')]['Interaction']){_0x39bbc4=_[_0xd2d6('0x54')](_0x39bbc4,_0x2e925b[_0xd2d6('0x63')]['Interaction']);}return db['MailInteraction']['create'](_0x39bbc4,{'include':[{'model':db[_0xd2d6('0x95')],'as':_0xd2d6('0xad')}]});})[_0xd2d6('0x23')](respondWithResult(_0x3b3443,null))[_0xd2d6('0x19')](handleError(_0x3b3443,null));};exports[_0xd2d6('0xae')]=function(_0xeed1bc,_0x1362ca){return db[_0xd2d6('0x5a')][_0xd2d6('0x62')]({'where':{'id':_0xeed1bc[_0xd2d6('0x5d')]['id']},'include':[{'model':db[_0xd2d6('0x43')],'as':_0xd2d6('0x40'),'raw':!![],'include':[{'model':db[_0xd2d6('0xa1')],'as':_0xd2d6('0xa1'),'raw':!![]}]}]})[_0xd2d6('0x23')](handleEntityNotFound(_0x1362ca,null))[_0xd2d6('0x23')](function(_0x5a82b8){if(!_0x5a82b8[_0xd2d6('0x40')])return;var _0x5e0dc7=_0x5a82b8[_0xd2d6('0xa7')]();return respondWithRpcPromise(_0xd2d6('0xaf'),'verifySmtp',{'account':_0x5e0dc7});})['then'](respondWithResult(_0x1362ca,null))[_0xd2d6('0x19')](handleError(_0x1362ca,null));};exports['destroy']=function(_0x56e1b0,_0x5e9da0){return db[_0xd2d6('0x5a')]['find']({'where':{'id':_0x56e1b0['params']['id']}})[_0xd2d6('0x23')](handleEntityNotFound(_0x5e9da0,null))[_0xd2d6('0x23')](function(_0xa39333){if(_0xa39333&&_0xa39333[_0xd2d6('0x3d')]){throw new db[(_0xd2d6('0xb0'))]['ValidationError'](_0xd2d6('0xb1'));}return _0xa39333;})['then'](removeEntity(_0x5e9da0,null))[_0xd2d6('0x19')](handleError(_0x5e9da0,null));};exports[_0xd2d6('0xb2')]=function(_0x1feb06,_0x27c982){return db[_0xd2d6('0x5a')][_0xd2d6('0x62')]({'where':{'id':_0x1feb06['params']['id']}})[_0xd2d6('0x23')](handleEntityNotFound(_0x27c982,null))['then'](function(_0x5e56c6){if(_0x5e56c6){return _0x5e56c6[_0xd2d6('0xb2')](_0x1feb06[_0xd2d6('0x63')][_0xd2d6('0x70')],_[_0xd2d6('0x83')](_0x1feb06[_0xd2d6('0x63')],['ids','id'])||{})[_0xd2d6('0xb3')](function(_0x23ed72){for(var _0x165ca2=0x0;_0x165ca2<_0x1feb06['body'][_0xd2d6('0x70')][_0xd2d6('0x4d')];_0x165ca2+=0x1){socket[_0xd2d6('0xb4')](_0xd2d6('0xb5'),{'UserId':Number(_0x1feb06['body'][_0xd2d6('0x70')][_0x165ca2]),'MailAccountId':Number(_0x1feb06[_0xd2d6('0x5d')]['id'])});}return _0x23ed72;});}})[_0xd2d6('0x23')](respondWithResult(_0x27c982,null))[_0xd2d6('0x19')](handleError(_0x27c982,null));};exports['removeAgents']=function(_0x561dcb,_0x40c436){return db[_0xd2d6('0x5a')][_0xd2d6('0x62')]({'where':{'id':_0x561dcb[_0xd2d6('0x5d')]['id']}})['then'](handleEntityNotFound(_0x40c436,null))[_0xd2d6('0x23')](function(_0x2d79c4){if(_0x2d79c4){return _0x2d79c4['removeAgents'](_0x561dcb[_0xd2d6('0x49')][_0xd2d6('0x70')])['then'](function(){if(_['isArray'](_0x561dcb['query']['ids'])){for(var _0x1dd7e6=0x0;_0x1dd7e6<_0x561dcb[_0xd2d6('0x49')][_0xd2d6('0x70')]['length'];_0x1dd7e6+=0x1){socket[_0xd2d6('0xb4')]('userMailAccount:remove',{'UserId':Number(_0x561dcb['query'][_0xd2d6('0x70')][_0x1dd7e6]),'MailAccountId':Number(_0x561dcb[_0xd2d6('0x5d')]['id'])});}}else{socket['emit'](_0xd2d6('0xb6'),{'UserId':Number(_0x561dcb[_0xd2d6('0x49')][_0xd2d6('0x70')]),'MailAccountId':Number(_0x561dcb[_0xd2d6('0x5d')]['id'])});}});}})[_0xd2d6('0x23')](respondWithStatusCode(_0x40c436,null))[_0xd2d6('0x19')](handleError(_0x40c436,null));};exports[_0xd2d6('0xb7')]=function(_0x11a389,_0x1a1b32){var _0x52babe={};var _0x47b6d1={};var _0x3a32a4;var _0x240dd0;return db['MailAccount'][_0xd2d6('0x6c')]({'where':{'id':_0x11a389[_0xd2d6('0x5d')]['id']}})[_0xd2d6('0x23')](handleEntityNotFound(_0x1a1b32,null))[_0xd2d6('0x23')](function(_0x2863c9){if(_0x2863c9){_0x3a32a4=_0x2863c9;_0x47b6d1[_0xd2d6('0x48')]=_[_0xd2d6('0x5f')](db[_0xd2d6('0x85')][_0xd2d6('0x60')]);_0x47b6d1[_0xd2d6('0x49')]=_[_0xd2d6('0x5f')](_0x11a389['query']);_0x47b6d1['filters']=_[_0xd2d6('0x4b')](_0x47b6d1[_0xd2d6('0x48')],_0x47b6d1[_0xd2d6('0x49')]);_0x52babe[_0xd2d6('0x4c')]=_[_0xd2d6('0x4b')](_0x47b6d1[_0xd2d6('0x48')],qs[_0xd2d6('0x61')](_0x11a389['query'][_0xd2d6('0x61')]));_0x52babe[_0xd2d6('0x4c')]=_0x52babe[_0xd2d6('0x4c')][_0xd2d6('0x4d')]?_0x52babe[_0xd2d6('0x4c')]:_0x47b6d1[_0xd2d6('0x48')];_0x52babe['order']=qs[_0xd2d6('0x50')](_0x11a389[_0xd2d6('0x49')]['sort']);_0x52babe[_0xd2d6('0x51')]=qs[_0xd2d6('0x4a')](_[_0xd2d6('0x52')](_0x11a389[_0xd2d6('0x49')],_0x47b6d1[_0xd2d6('0x4a')]));if(_0x11a389[_0xd2d6('0x49')][_0xd2d6('0x53')]){_0x52babe[_0xd2d6('0x51')]=_[_0xd2d6('0x54')](_0x52babe['where'],{'$or':_[_0xd2d6('0x45')](_0x52babe[_0xd2d6('0x4c')],function(_0x2b0d08){var _0x224e7a={};_0x224e7a[_0x2b0d08]={'$like':'%'+_0x11a389[_0xd2d6('0x49')][_0xd2d6('0x53')]+'%'};return _0x224e7a;})});}_0x52babe=_[_0xd2d6('0x54')]({},_0x52babe,_0x11a389['options']);return _0x3a32a4[_0xd2d6('0xb7')](_0x52babe);}})[_0xd2d6('0x23')](function(_0x5546d7){if(_0x5546d7){_0x240dd0=_0x5546d7[_0xd2d6('0x4d')];if(!_0x11a389[_0xd2d6('0x49')][_0xd2d6('0x6d')](_0xd2d6('0x4e'))){_0x52babe[_0xd2d6('0x21')]=qs['limit'](_0x11a389[_0xd2d6('0x49')][_0xd2d6('0x21')]);_0x52babe['offset']=qs[_0xd2d6('0x1e')](_0x11a389[_0xd2d6('0x49')][_0xd2d6('0x1e')]);}return _0x3a32a4['getAgents'](_0x52babe);}})[_0xd2d6('0x23')](function(_0x4f486f){if(_0x4f486f){return _0x4f486f?{'count':_0x240dd0,'rows':_0x4f486f}:null;}})[_0xd2d6('0x23')](respondWithResult(_0x1a1b32,null))[_0xd2d6('0x19')](handleError(_0x1a1b32,null));};