979a2717431951cc7641eb1f8d109f822dc845ec
[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 _0xfe31=['limit','offset','set','Content-Range','then','get','MailAccounts','destroy','stack','name','send','gmail','imap.gmail.com','yahoo','hotmail','imap-mail.outlook.com','outlook365','outlook.office365.com','Unknown\x20email\x20service\x20provider','smtp.gmail.com','smtp.mail.yahoo.com','smtp.office365.com','user','password','pass','modernAuthentication','CloudProviderId','host','port','secure','service','authentication','username','Imap','index','MailServerIn','MailServerOut','Smtp','Pause','mandatoryDispositionPause','MailAccount','rawAttributes','fieldName','type','model','map','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','VIRTUAL','merge','options','count','includeAll','include','findAll','rows','show','params','keys','update','body','custom','find','Mail\x20Account\x20not\x20found','describe','addDisposition','MailAccountId','Disposition','getDispositions','filter','removeDispositions','ids','addAnswer','create','getAnswers','findOne','CannedAnswer','removeAnswers','key','provider','active','description','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','UserProfileResource','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','getImap','addImap','removeImap','setImap','getSmtp','addSmtp','removeSmtp','setSmtp','addInteraction','MailInteraction','omit','getInteractions','CmContact','Contact','User','fullname','Tags','color','tag','sequelize','transaction','Transaction','ISOLATION_LEVELS','MailApplication','bulkCreate','priority','finally','getApplications','MailMessage','$gte','split','inlineCss','true','CmList','Contacts','updatedAt','CloudProvider','isNil','from','format','%s\x20<%s>','email','attachments','join','root','server/files/attachments','basename','SendMail','sendMail','List','List\x20not\x20found','defaults','ListId','messageId','attach','out','YYYY-MM-DD\x20HH:mm:ss','Interaction','Messages','verifySmtp','getSmtpOptions','Sequelize','ValidationError','addAgents','emit','userMailAccount:save','removeAgents','userMailAccount:remove','getAgents','moment','bluebird','util','path','lodash','ioredis','../../config/logger','../../config/environment','../../mysqldb','localhost','socket.io-emitter','redis','./mailAccount.socket','register','jayson/promise','client','http','info','request\x20sent','debug','MailAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','MailAccount,\x20%s,\x20%s','message','result','catch','sendStatus','status','end','json','undefined'];(function(_0x335ae5,_0x23311d){var _0xca43fc=function(_0x3cb209){while(--_0x3cb209){_0x335ae5['push'](_0x335ae5['shift']());}};_0xca43fc(++_0x23311d);}(_0xfe31,0xa7));var _0x1fe3=function(_0x7b4341,_0xf1a985){_0x7b4341=_0x7b4341-0x0;var _0x4869f3=_0xfe31[_0x7b4341];return _0x4869f3;};'use strict';var moment=require(_0x1fe3('0x0'));var BPromise=require(_0x1fe3('0x1'));var util=require(_0x1fe3('0x2'));var path=require(_0x1fe3('0x3'));var _=require(_0x1fe3('0x4'));var juice=require('juice');var Redis=require(_0x1fe3('0x5'));var qs=require('../../components/parsers/qs');var logger=require(_0x1fe3('0x6'))('api');var config=require(_0x1fe3('0x7'));var db=require(_0x1fe3('0x8'))['db'];config['redis']=_['defaults'](config['redis'],{'host':_0x1fe3('0x9'),'port':0x18eb});var socket=require(_0x1fe3('0xa'))(new Redis(config[_0x1fe3('0xb')]));require(_0x1fe3('0xc'))[_0x1fe3('0xd')](socket);var jayson=require(_0x1fe3('0xe'));var client=jayson[_0x1fe3('0xf')][_0x1fe3('0x10')]({'port':0x232b});function respondWithRpcPromise(_0x45c191,_0x2e9487,_0x253bae,_0x3201ad){return new BPromise(function(_0x47ef93,_0x93fdaf){var _0x2e8ee6=_0x3201ad||client;return _0x2e8ee6['request'](_0x45c191,_0x253bae)['then'](function(_0x28c63d){logger[_0x1fe3('0x11')]('MailAccount,\x20%s,\x20%s',_0x2e9487,_0x1fe3('0x12'));logger[_0x1fe3('0x13')](_0x1fe3('0x14'),_0x2e9487,'request\x20sent',JSON[_0x1fe3('0x15')](_0x28c63d));if(_0x28c63d['error']){if(_0x28c63d[_0x1fe3('0x16')][_0x1fe3('0x17')]===0x1f4){logger['error'](_0x1fe3('0x18'),_0x2e9487,_0x28c63d['error'][_0x1fe3('0x19')]);return _0x93fdaf(_0x28c63d[_0x1fe3('0x16')][_0x1fe3('0x19')]);}logger[_0x1fe3('0x16')](_0x1fe3('0x18'),_0x2e9487,_0x28c63d[_0x1fe3('0x16')][_0x1fe3('0x19')]);return _0x47ef93(_0x28c63d['error'][_0x1fe3('0x19')]);}else{logger['info'](_0x1fe3('0x18'),_0x2e9487,'request\x20sent');_0x47ef93(_0x28c63d[_0x1fe3('0x1a')][_0x1fe3('0x19')]);}})[_0x1fe3('0x1b')](function(_0x438fd2){logger[_0x1fe3('0x16')]('MailAccount,\x20%s,\x20%s',_0x2e9487,_0x438fd2);_0x93fdaf(_0x438fd2);});});}function respondWithStatusCode(_0x13889b,_0x2cef34){_0x2cef34=_0x2cef34||0xcc;return function(_0x37ff2d){if(_0x37ff2d){return _0x13889b[_0x1fe3('0x1c')](_0x2cef34);}return _0x13889b[_0x1fe3('0x1d')](_0x2cef34)[_0x1fe3('0x1e')]();};}function respondWithResult(_0x5e1368,_0x120af5){_0x120af5=_0x120af5||0xc8;return function(_0x2a54e7){if(_0x2a54e7){return _0x5e1368[_0x1fe3('0x1d')](_0x120af5)[_0x1fe3('0x1f')](_0x2a54e7);}};}function respondWithFilteredResult(_0x233319,_0x316b36){return function(_0x874a1){if(_0x874a1){var _0x54ed53=typeof _0x316b36['offset']===_0x1fe3('0x20')&&typeof _0x316b36[_0x1fe3('0x21')]===_0x1fe3('0x20');var _0x2dd3ea=_0x874a1['count'];var _0x1c59bf=_0x54ed53?0x0:_0x316b36[_0x1fe3('0x22')];var _0x55be7f=_0x54ed53?_0x874a1['count']:_0x316b36[_0x1fe3('0x22')]+_0x316b36[_0x1fe3('0x21')];var _0x2a1b91;if(_0x55be7f>=_0x2dd3ea){_0x55be7f=_0x2dd3ea;_0x2a1b91=0xc8;}else{_0x2a1b91=0xce;}_0x233319[_0x1fe3('0x1d')](_0x2a1b91);return _0x233319[_0x1fe3('0x23')](_0x1fe3('0x24'),_0x1c59bf+'-'+_0x55be7f+'/'+_0x2dd3ea)['json'](_0x874a1);}return null;};}function saveUpdates(_0x3aff9c){return function(_0x8d53b8){if(_0x8d53b8){return _0x8d53b8['update'](_0x3aff9c)[_0x1fe3('0x25')](function(_0x36ea84){return _0x36ea84;});}return null;};}function removeEntity(_0x572eab){return function(_0x14049b){if(_0x14049b){return _0x14049b['destroy']()['then'](function(){var _0x584888=_0x14049b[_0x1fe3('0x26')]({'plain':!![]});var _0x518d41=_0x1fe3('0x27');return db['UserProfileResource'][_0x1fe3('0x28')]({'where':{'type':_0x518d41,'resourceId':_0x584888['id']}})[_0x1fe3('0x25')](function(){return _0x14049b;});})[_0x1fe3('0x25')](function(){_0x572eab[_0x1fe3('0x1d')](0xcc)[_0x1fe3('0x1e')]();});}};}function handleEntityNotFound(_0x13fbfe){return function(_0x34fcb1){if(!_0x34fcb1){_0x13fbfe[_0x1fe3('0x1c')](0x194);}return _0x34fcb1;};}function handleError(_0xe51af1,_0x4cdad4){_0x4cdad4=_0x4cdad4||0x1f4;return function(_0x2c2d73){logger[_0x1fe3('0x16')](_0x2c2d73[_0x1fe3('0x29')]);if(_0x2c2d73[_0x1fe3('0x2a')]){delete _0x2c2d73['name'];}_0xe51af1[_0x1fe3('0x1d')](_0x4cdad4)[_0x1fe3('0x2b')](_0x2c2d73);};}function getImapHost(_0xb780a5){switch(_0xb780a5){case _0x1fe3('0x2c'):return _0x1fe3('0x2d');case _0x1fe3('0x2e'):return'imap.mail.yahoo.com';case _0x1fe3('0x2f'):return _0x1fe3('0x30');case _0x1fe3('0x31'):return _0x1fe3('0x32');}throw new Error(_0x1fe3('0x33'),_0xb780a5);}function getSmtpHost(_0x5b2764){switch(_0x5b2764){case _0x1fe3('0x2c'):return _0x1fe3('0x34');case'yahoo':return _0x1fe3('0x35');case _0x1fe3('0x2f'):return'smtp-mail.outlook.com';case'outlook365':return _0x1fe3('0x36');}throw new Error(_0x1fe3('0x33'),_0x5b2764);}function getAuthenticationOptions(_0x5c583c,_0x2a8a98){var _0x3718c1={};var _0x46653b={};if(_0x5c583c){_0x3718c1[_0x1fe3('0x37')]=_0x46653b['user']=_0x2a8a98['username'];_0x3718c1[_0x1fe3('0x38')]=_0x46653b[_0x1fe3('0x39')]=_0x2a8a98['password'];if(_0x2a8a98[_0x1fe3('0x3a')]){_0x3718c1[_0x1fe3('0x3a')]=_0x46653b['modernAuthentication']=!![];_0x3718c1[_0x1fe3('0x3b')]=_0x46653b[_0x1fe3('0x3b')]=_0x2a8a98[_0x1fe3('0x3b')];_0x3718c1['password']=_0x46653b[_0x1fe3('0x39')]=null;}else{_0x3718c1[_0x1fe3('0x3b')]=_0x46653b[_0x1fe3('0x3b')]=null;}_0x3718c1[_0x1fe3('0x3c')]=getImapHost(_0x5c583c);_0x3718c1[_0x1fe3('0x3d')]=0x3e1;_0x46653b[_0x1fe3('0x3c')]=getSmtpHost(_0x5c583c);_0x46653b[_0x1fe3('0x3d')]=0x24b;_0x46653b[_0x1fe3('0x3e')]=![];_0x3718c1[_0x1fe3('0x3f')]=_0x46653b[_0x1fe3('0x3f')]=null;}else{if(_0x2a8a98[_0x1fe3('0x40')]){_0x3718c1['user']=_0x46653b[_0x1fe3('0x37')]=_0x2a8a98[_0x1fe3('0x41')];_0x3718c1['password']=_0x46653b[_0x1fe3('0x39')]=_0x2a8a98[_0x1fe3('0x38')];}else{_0x3718c1['authentication']=_0x46653b[_0x1fe3('0x40')]=![];_0x3718c1[_0x1fe3('0x37')]=_0x46653b[_0x1fe3('0x37')]=null;_0x3718c1[_0x1fe3('0x38')]=_0x46653b[_0x1fe3('0x39')]=null;}_0x3718c1[_0x1fe3('0x3c')]=_0x2a8a98[_0x1fe3('0x42')][_0x1fe3('0x3c')];_0x3718c1[_0x1fe3('0x3d')]=_0x2a8a98[_0x1fe3('0x42')][_0x1fe3('0x3d')];_0x46653b[_0x1fe3('0x3c')]=_0x2a8a98['Smtp'][_0x1fe3('0x3c')];_0x46653b[_0x1fe3('0x3d')]=_0x2a8a98['Smtp'][_0x1fe3('0x3d')];}return{'Imap':_0x3718c1,'Smtp':_0x46653b};}exports[_0x1fe3('0x43')]=function(_0x36c5eb,_0x53c396){var _0x466290={'include':[{'model':db[_0x1fe3('0x44')],'as':_0x1fe3('0x42')},{'model':db[_0x1fe3('0x45')],'as':_0x1fe3('0x46')},{'model':db[_0x1fe3('0x47')],'as':_0x1fe3('0x48')}]},_0x5834bf={},_0x1d6c4a={'count':0x0,'rows':[]};var _0x3233a0=_['map'](db[_0x1fe3('0x49')][_0x1fe3('0x4a')],function(_0x4abf35){return{'name':_0x4abf35[_0x1fe3('0x4b')],'type':_0x4abf35[_0x1fe3('0x4c')]['key']};});_0x5834bf[_0x1fe3('0x4d')]=_[_0x1fe3('0x4e')](_0x3233a0,'name');_0x5834bf[_0x1fe3('0x4f')]=_['keys'](_0x36c5eb[_0x1fe3('0x4f')]);_0x5834bf[_0x1fe3('0x50')]=_[_0x1fe3('0x51')](_0x5834bf[_0x1fe3('0x4d')],_0x5834bf[_0x1fe3('0x4f')]);_0x466290[_0x1fe3('0x52')]=_[_0x1fe3('0x51')](_0x5834bf['model'],qs[_0x1fe3('0x53')](_0x36c5eb[_0x1fe3('0x4f')][_0x1fe3('0x53')]));_0x466290[_0x1fe3('0x52')]=_0x466290[_0x1fe3('0x52')][_0x1fe3('0x54')]?_0x466290[_0x1fe3('0x52')]:_0x5834bf[_0x1fe3('0x4d')];if(!_0x36c5eb[_0x1fe3('0x4f')][_0x1fe3('0x55')](_0x1fe3('0x56'))){_0x466290['limit']=qs[_0x1fe3('0x21')](_0x36c5eb[_0x1fe3('0x4f')]['limit']);_0x466290[_0x1fe3('0x22')]=qs['offset'](_0x36c5eb[_0x1fe3('0x4f')][_0x1fe3('0x22')]);}_0x466290[_0x1fe3('0x57')]=qs[_0x1fe3('0x58')](_0x36c5eb['query'][_0x1fe3('0x58')]);_0x466290[_0x1fe3('0x59')]=qs['filters'](_[_0x1fe3('0x5a')](_0x36c5eb['query'],_0x5834bf['filters']),_0x3233a0);if(_0x36c5eb['query']['filter']){_0x466290['where']=_['merge'](_0x466290[_0x1fe3('0x59')],{'$or':_[_0x1fe3('0x4e')](_0x3233a0,function(_0x1e0e85){if(_0x1e0e85[_0x1fe3('0x4c')]!==_0x1fe3('0x5b')){var _0x2f1d82={};_0x2f1d82[_0x1e0e85[_0x1fe3('0x2a')]]={'$like':'%'+_0x36c5eb[_0x1fe3('0x4f')]['filter']+'%'};return _0x2f1d82;}})});}_0x466290=_[_0x1fe3('0x5c')]({},_0x466290,_0x36c5eb[_0x1fe3('0x5d')]);var _0x13e40b={'where':_0x466290['where']};return db['MailAccount'][_0x1fe3('0x5e')](_0x13e40b)[_0x1fe3('0x25')](function(_0x434099){_0x1d6c4a[_0x1fe3('0x5e')]=_0x434099;if(_0x36c5eb[_0x1fe3('0x4f')][_0x1fe3('0x5f')]){_0x466290[_0x1fe3('0x60')]=[{'all':!![]}];}return db[_0x1fe3('0x49')][_0x1fe3('0x61')](_0x466290);})[_0x1fe3('0x25')](function(_0x4850d4){_0x1d6c4a[_0x1fe3('0x62')]=_0x4850d4;return _0x1d6c4a;})[_0x1fe3('0x25')](respondWithFilteredResult(_0x53c396,_0x466290))[_0x1fe3('0x1b')](handleError(_0x53c396,null));};exports[_0x1fe3('0x63')]=function(_0x35393b,_0x5507da){var _0x368c15={'raw':![],'where':{'id':_0x35393b[_0x1fe3('0x64')]['id']},'include':[{'model':db['MailServerIn'],'as':_0x1fe3('0x42')},{'model':db[_0x1fe3('0x45')],'as':'Smtp'},{'model':db['Pause'],'as':_0x1fe3('0x48')}]},_0x25d17b={};_0x25d17b[_0x1fe3('0x4d')]=_[_0x1fe3('0x65')](db['MailAccount']['rawAttributes']);_0x25d17b['query']=_[_0x1fe3('0x65')](_0x35393b['query']);_0x25d17b[_0x1fe3('0x50')]=_['intersection'](_0x25d17b['model'],_0x25d17b['query']);_0x368c15[_0x1fe3('0x52')]=_[_0x1fe3('0x51')](_0x25d17b[_0x1fe3('0x4d')],qs[_0x1fe3('0x53')](_0x35393b[_0x1fe3('0x4f')]['fields']));_0x368c15[_0x1fe3('0x52')]=_0x368c15['attributes']['length']?_0x368c15['attributes']:_0x25d17b[_0x1fe3('0x4d')];if(_0x35393b['query'][_0x1fe3('0x5f')]){_0x368c15[_0x1fe3('0x60')]=[{'all':!![]}];}_0x368c15=_[_0x1fe3('0x5c')]({},_0x368c15,_0x35393b[_0x1fe3('0x5d')]);return db['MailAccount']['find'](_0x368c15)[_0x1fe3('0x25')](handleEntityNotFound(_0x5507da,null))['then'](respondWithResult(_0x5507da,null))[_0x1fe3('0x1b')](handleError(_0x5507da,null));};exports[_0x1fe3('0x66')]=function(_0x204787,_0x24f7dc){if(_0x204787['body']['id']){delete _0x204787[_0x1fe3('0x67')]['id'];}var _0x4835bf=_0x204787['body']['provider']===_0x1fe3('0x68')?null:_0x204787[_0x1fe3('0x67')]['provider'];var _0x28e9c0=_0x204787['body'][_0x1fe3('0x42')]||{};var _0x258cd2=_0x204787['body']['Smtp']||{};if(_0x4835bf){_0x28e9c0['host']=getImapHost(_0x4835bf);_0x28e9c0[_0x1fe3('0x3d')]=0x3e1;_0x258cd2[_0x1fe3('0x3c')]=getSmtpHost(_0x4835bf);_0x258cd2['port']=0x24b;_0x258cd2[_0x1fe3('0x3e')]=![];}if(_0x258cd2['modernAuthentication']){_0x258cd2[_0x1fe3('0x3e')]=![];}else{_0x258cd2[_0x1fe3('0x3b')]=null;}if(!_0x28e9c0['modernAuthentication'])_0x28e9c0[_0x1fe3('0x3b')]=null;_0x204787['body']['Imap']=_0x28e9c0;_0x204787[_0x1fe3('0x67')][_0x1fe3('0x46')]=_0x258cd2;return db['MailAccount'][_0x1fe3('0x69')]({'where':{'id':_0x204787['params']['id']},'include':[{'model':db['MailServerIn'],'as':_0x1fe3('0x42')},{'model':db[_0x1fe3('0x45')],'as':_0x1fe3('0x46')},{'model':db[_0x1fe3('0x47')],'as':_0x1fe3('0x48')}]})[_0x1fe3('0x25')](handleEntityNotFound(_0x24f7dc,null))[_0x1fe3('0x25')](function(_0x199185){if(!_0x199185)throw new Error(_0x1fe3('0x6a'));if(_0x199185['service'])delete _0x204787['body'][_0x1fe3('0x42')];return _0x199185;})['then'](saveUpdates(_0x204787[_0x1fe3('0x67')],null))[_0x1fe3('0x25')](function(_0xa3c5c3){if(!_0x204787[_0x1fe3('0x67')][_0x1fe3('0x42')])return _0xa3c5c3;return db['MailServerIn']['update'](_0x204787[_0x1fe3('0x67')][_0x1fe3('0x42')],{'where':{'MailAccountId':_0xa3c5c3['id']}})[_0x1fe3('0x25')](function(){return _0xa3c5c3;});})[_0x1fe3('0x25')](function(_0x35937e){if(!_0x204787[_0x1fe3('0x67')][_0x1fe3('0x46')])return _0x35937e;return db[_0x1fe3('0x45')][_0x1fe3('0x66')](_0x204787[_0x1fe3('0x67')][_0x1fe3('0x46')],{'where':{'MailAccountId':_0x35937e['id']}})[_0x1fe3('0x25')](function(){return _0x35937e;});})[_0x1fe3('0x25')](respondWithResult(_0x24f7dc,null))[_0x1fe3('0x1b')](handleError(_0x24f7dc,null));};exports[_0x1fe3('0x6b')]=function(_0x436258,_0x3b80f2){return db[_0x1fe3('0x49')][_0x1fe3('0x6b')]()[_0x1fe3('0x25')](respondWithResult(_0x3b80f2,null))[_0x1fe3('0x1b')](handleError(_0x3b80f2,null));};exports[_0x1fe3('0x6c')]=function(_0x22ddab,_0x313b34){if(_0x22ddab['body']['id']){delete _0x22ddab['body']['id'];}return db[_0x1fe3('0x49')]['find']({'where':{'id':_0x22ddab[_0x1fe3('0x64')]['id']}})[_0x1fe3('0x25')](handleEntityNotFound(_0x313b34,null))['then'](function(_0x3e9383){if(_0x3e9383){_0x22ddab['body'][_0x1fe3('0x6d')]=_0x3e9383['id'];return db[_0x1fe3('0x6e')]['create'](_0x22ddab[_0x1fe3('0x67')]);}})[_0x1fe3('0x25')](respondWithResult(_0x313b34,null))[_0x1fe3('0x1b')](handleError(_0x313b34,null));};exports[_0x1fe3('0x6f')]=function(_0x537063,_0x34fe8f){var _0x1e106b={'raw':![],'where':{}};var _0x27c47d={};var _0x4977af={'count':0x0,'rows':[]};return db['MailAccount']['findOne']({'where':{'id':_0x537063['params']['id']}})[_0x1fe3('0x25')](handleEntityNotFound(_0x34fe8f,null))['then'](function(_0x48cbfa){if(_0x48cbfa){_0x27c47d['model']=_['keys'](db['Disposition'][_0x1fe3('0x4a')]);_0x27c47d[_0x1fe3('0x4f')]=_[_0x1fe3('0x65')](_0x537063[_0x1fe3('0x4f')]);_0x27c47d[_0x1fe3('0x50')]=_['intersection'](_0x27c47d[_0x1fe3('0x4d')],_0x27c47d[_0x1fe3('0x4f')]);_0x1e106b[_0x1fe3('0x52')]=_[_0x1fe3('0x51')](_0x27c47d['model'],qs['fields'](_0x537063[_0x1fe3('0x4f')]['fields']));_0x1e106b[_0x1fe3('0x52')]=_0x1e106b[_0x1fe3('0x52')]['length']?_0x1e106b['attributes']:_0x27c47d['model'];if(!_0x537063[_0x1fe3('0x4f')][_0x1fe3('0x55')]('nolimit')){_0x1e106b[_0x1fe3('0x21')]=qs['limit'](_0x537063[_0x1fe3('0x4f')][_0x1fe3('0x21')]);_0x1e106b['offset']=qs[_0x1fe3('0x22')](_0x537063['query']['offset']);}_0x1e106b[_0x1fe3('0x57')]=qs[_0x1fe3('0x58')](_0x537063[_0x1fe3('0x4f')][_0x1fe3('0x58')]);_0x1e106b[_0x1fe3('0x59')]=qs[_0x1fe3('0x50')](_['pick'](_0x537063[_0x1fe3('0x4f')],_0x27c47d[_0x1fe3('0x50')]));_0x1e106b['where'][_0x1fe3('0x6d')]=_0x48cbfa['id'];if(_0x537063[_0x1fe3('0x4f')][_0x1fe3('0x70')]){_0x1e106b[_0x1fe3('0x59')]=_[_0x1fe3('0x5c')](_0x1e106b[_0x1fe3('0x59')],{'$or':_['map'](_0x1e106b[_0x1fe3('0x52')],function(_0x18829c){var _0x6063d2={};_0x6063d2[_0x18829c]={'$like':'%'+_0x537063[_0x1fe3('0x4f')][_0x1fe3('0x70')]+'%'};return _0x6063d2;})});}_0x1e106b=_[_0x1fe3('0x5c')]({},_0x1e106b,_0x537063[_0x1fe3('0x5d')]);return db[_0x1fe3('0x6e')][_0x1fe3('0x5e')]({'where':_0x1e106b[_0x1fe3('0x59')]})[_0x1fe3('0x25')](function(_0x28573f){_0x4977af[_0x1fe3('0x5e')]=_0x28573f;if(_0x537063[_0x1fe3('0x4f')][_0x1fe3('0x5f')]){_0x1e106b[_0x1fe3('0x60')]=[{'all':!![]}];}return db[_0x1fe3('0x6e')][_0x1fe3('0x61')](_0x1e106b);})[_0x1fe3('0x25')](function(_0x5f1e51){_0x4977af[_0x1fe3('0x62')]=_0x5f1e51;return _0x4977af;});}})[_0x1fe3('0x25')](respondWithFilteredResult(_0x34fe8f,_0x1e106b))['catch'](handleError(_0x34fe8f,null));};exports[_0x1fe3('0x71')]=function(_0x5973fc,_0x241526){return db[_0x1fe3('0x49')][_0x1fe3('0x69')]({'where':{'id':_0x5973fc[_0x1fe3('0x64')]['id']}})[_0x1fe3('0x25')](handleEntityNotFound(_0x241526,null))['then'](function(_0x14c956){if(_0x14c956){return _0x14c956[_0x1fe3('0x71')](_0x5973fc[_0x1fe3('0x4f')][_0x1fe3('0x72')]);}})[_0x1fe3('0x25')](respondWithStatusCode(_0x241526,null))['catch'](handleError(_0x241526,null));};exports[_0x1fe3('0x73')]=function(_0x14d5b4,_0x226d88){if(_0x14d5b4['body']['id']){delete _0x14d5b4['body']['id'];}return db[_0x1fe3('0x49')][_0x1fe3('0x69')]({'where':{'id':_0x14d5b4[_0x1fe3('0x64')]['id']}})[_0x1fe3('0x25')](handleEntityNotFound(_0x226d88,null))[_0x1fe3('0x25')](function(_0x1b7273){if(_0x1b7273){_0x14d5b4[_0x1fe3('0x67')][_0x1fe3('0x6d')]=_0x1b7273['id'];return db['CannedAnswer'][_0x1fe3('0x74')](_0x14d5b4['body']);}})['then'](respondWithResult(_0x226d88,null))[_0x1fe3('0x1b')](handleError(_0x226d88,null));};exports[_0x1fe3('0x75')]=function(_0x4d7e51,_0x1d1805){var _0x87b799={'raw':![],'where':{}};var _0x2696f2={};var _0x481e99={'count':0x0,'rows':[]};return db[_0x1fe3('0x49')][_0x1fe3('0x76')]({'where':{'id':_0x4d7e51[_0x1fe3('0x64')]['id']}})['then'](handleEntityNotFound(_0x1d1805,null))[_0x1fe3('0x25')](function(_0x32f2ac){if(_0x32f2ac){_0x2696f2['model']=_[_0x1fe3('0x65')](db[_0x1fe3('0x77')][_0x1fe3('0x4a')]);_0x2696f2[_0x1fe3('0x4f')]=_[_0x1fe3('0x65')](_0x4d7e51[_0x1fe3('0x4f')]);_0x2696f2[_0x1fe3('0x50')]=_[_0x1fe3('0x51')](_0x2696f2[_0x1fe3('0x4d')],_0x2696f2[_0x1fe3('0x4f')]);_0x87b799['attributes']=_[_0x1fe3('0x51')](_0x2696f2['model'],qs[_0x1fe3('0x53')](_0x4d7e51[_0x1fe3('0x4f')][_0x1fe3('0x53')]));_0x87b799[_0x1fe3('0x52')]=_0x87b799[_0x1fe3('0x52')]['length']?_0x87b799[_0x1fe3('0x52')]:_0x2696f2[_0x1fe3('0x4d')];if(!_0x4d7e51[_0x1fe3('0x4f')][_0x1fe3('0x55')](_0x1fe3('0x56'))){_0x87b799[_0x1fe3('0x21')]=qs[_0x1fe3('0x21')](_0x4d7e51[_0x1fe3('0x4f')][_0x1fe3('0x21')]);_0x87b799['offset']=qs['offset'](_0x4d7e51[_0x1fe3('0x4f')]['offset']);}_0x87b799['order']=qs[_0x1fe3('0x58')](_0x4d7e51[_0x1fe3('0x4f')]['sort']);_0x87b799[_0x1fe3('0x59')]=qs[_0x1fe3('0x50')](_[_0x1fe3('0x5a')](_0x4d7e51[_0x1fe3('0x4f')],_0x2696f2[_0x1fe3('0x50')]));_0x87b799[_0x1fe3('0x59')]['MailAccountId']=_0x32f2ac['id'];if(_0x4d7e51[_0x1fe3('0x4f')]['filter']){_0x87b799['where']=_[_0x1fe3('0x5c')](_0x87b799[_0x1fe3('0x59')],{'$or':_['map'](_0x87b799[_0x1fe3('0x52')],function(_0x53a2b3){var _0x4bda73={};_0x4bda73[_0x53a2b3]={'$like':'%'+_0x4d7e51['query']['filter']+'%'};return _0x4bda73;})});}_0x87b799=_[_0x1fe3('0x5c')]({},_0x87b799,_0x4d7e51[_0x1fe3('0x5d')]);return db['CannedAnswer'][_0x1fe3('0x5e')]({'where':_0x87b799['where']})['then'](function(_0x4df705){_0x481e99[_0x1fe3('0x5e')]=_0x4df705;if(_0x4d7e51[_0x1fe3('0x4f')][_0x1fe3('0x5f')]){_0x87b799['include']=[{'all':!![]}];}return db['CannedAnswer'][_0x1fe3('0x61')](_0x87b799);})[_0x1fe3('0x25')](function(_0x822616){_0x481e99[_0x1fe3('0x62')]=_0x822616;return _0x481e99;});}})[_0x1fe3('0x25')](respondWithFilteredResult(_0x1d1805,_0x87b799))[_0x1fe3('0x1b')](handleError(_0x1d1805,null));};exports['removeAnswers']=function(_0x5ced34,_0x1a3285){return db['MailAccount']['find']({'where':{'id':_0x5ced34[_0x1fe3('0x64')]['id']}})[_0x1fe3('0x25')](handleEntityNotFound(_0x1a3285,null))[_0x1fe3('0x25')](function(_0x408464){if(_0x408464){return _0x408464[_0x1fe3('0x78')](_0x5ced34['query'][_0x1fe3('0x72')]);}})[_0x1fe3('0x25')](respondWithStatusCode(_0x1a3285,null))[_0x1fe3('0x1b')](handleError(_0x1a3285,null));};exports[_0x1fe3('0x74')]=function(_0x1e8a8a,_0x1d1b8a){var _0x3c5f6a={'name':_0x1e8a8a[_0x1fe3('0x67')][_0x1fe3('0x2a')],'key':_0x1e8a8a[_0x1fe3('0x67')][_0x1fe3('0x79')],'provider':_0x1e8a8a[_0x1fe3('0x67')][_0x1fe3('0x7a')]===_0x1fe3('0x68')?null:_0x1e8a8a[_0x1fe3('0x67')][_0x1fe3('0x7a')],'email':_0x1e8a8a[_0x1fe3('0x67')]['email'],'ListId':_0x1e8a8a[_0x1fe3('0x67')]['ListId'],'active':!_['isNil'](_0x1e8a8a[_0x1fe3('0x67')][_0x1fe3('0x7b')])?_0x1e8a8a[_0x1fe3('0x67')][_0x1fe3('0x7b')]:!![],'description':_0x1e8a8a[_0x1fe3('0x67')][_0x1fe3('0x7c')]||null};var _0x4a7344=getAuthenticationOptions(_0x3c5f6a[_0x1fe3('0x7a')],_0x1e8a8a[_0x1fe3('0x67')]);_0x3c5f6a[_0x1fe3('0x42')]=_0x4a7344['Imap'];_0x3c5f6a[_0x1fe3('0x46')]=_0x4a7344[_0x1fe3('0x46')];return db[_0x1fe3('0x49')]['create'](_0x3c5f6a,{'include':[{'model':db[_0x1fe3('0x45')],'as':'Smtp'},{'model':db['MailServerIn'],'as':_0x1fe3('0x42')}]})[_0x1fe3('0x25')](function(_0xfaca4a){var _0x388655=_0x1e8a8a[_0x1fe3('0x37')][_0x1fe3('0x26')]({'plain':!![]});if(!_0x388655)throw new Error(_0x1fe3('0x7d'));if(_0x388655[_0x1fe3('0x7e')]==='user'){var _0x24e334=_0xfaca4a[_0x1fe3('0x26')]({'plain':!![]});return db[_0x1fe3('0x7f')][_0x1fe3('0x69')]({'where':{'name':_0x1fe3('0x27'),'userProfileId':_0x388655[_0x1fe3('0x80')]},'raw':!![]})['then'](function(_0x806cdf){if(_0x806cdf&&_0x806cdf['autoAssociation']===0x0){return db[_0x1fe3('0x81')][_0x1fe3('0x74')]({'name':_0x24e334[_0x1fe3('0x2a')],'resourceId':_0x24e334['id'],'type':_0x806cdf[_0x1fe3('0x2a')],'sectionId':_0x806cdf['id']},{})[_0x1fe3('0x25')](function(){return _0xfaca4a;});}else{return _0xfaca4a;}})[_0x1fe3('0x1b')](function(_0x3f4367){logger[_0x1fe3('0x16')](_0x1fe3('0x82'),_0x3f4367);throw _0x3f4367;});}return _0xfaca4a;})['then'](respondWithResult(_0x1d1b8a,0xc9))[_0x1fe3('0x1b')](handleError(_0x1d1b8a,null));};exports[_0x1fe3('0x83')]=function(_0x21fc20,_0x7f99b7){return db['MailAccount'][_0x1fe3('0x76')]({'where':{'id':_0x21fc20[_0x1fe3('0x64')]['id']}})[_0x1fe3('0x25')](handleEntityNotFound(_0x7f99b7,null))[_0x1fe3('0x25')](function(_0xa477a2){if(_0xa477a2){return _0xa477a2[_0x1fe3('0x83')]();}return null;})[_0x1fe3('0x25')](respondWithResult(_0x7f99b7,null))[_0x1fe3('0x1b')](handleError(_0x7f99b7,null));};exports[_0x1fe3('0x84')]=function(_0x40775c,_0x15e01e){if(_0x40775c[_0x1fe3('0x67')]['id']){delete _0x40775c[_0x1fe3('0x67')]['id'];}return db[_0x1fe3('0x49')]['find']({'where':{'id':_0x40775c[_0x1fe3('0x64')]['id']}})[_0x1fe3('0x25')](handleEntityNotFound(_0x15e01e,null))[_0x1fe3('0x25')](function(_0x28ca9a){if(_0x28ca9a){_0x40775c['body'][_0x1fe3('0x6d')]=_0x28ca9a['id'];return db[_0x1fe3('0x44')]['create'](_0x40775c['body']);}})['then'](respondWithResult(_0x15e01e,null))[_0x1fe3('0x1b')](handleError(_0x15e01e,null));};exports[_0x1fe3('0x85')]=function(_0x133fbb,_0x197feb){return db['MailAccount']['findOne']({'where':{'id':_0x133fbb[_0x1fe3('0x64')]['id']}})['then'](handleEntityNotFound(_0x197feb,null))['then'](function(_0x3b26f9){if(_0x3b26f9){return _0x3b26f9[_0x1fe3('0x86')](null);}return null;})[_0x1fe3('0x25')](respondWithStatusCode(_0x197feb,null))['catch'](handleError(_0x197feb,null));};exports[_0x1fe3('0x87')]=function(_0x124e4a,_0x8f357){return db[_0x1fe3('0x49')][_0x1fe3('0x76')]({'where':{'id':_0x124e4a[_0x1fe3('0x64')]['id']}})[_0x1fe3('0x25')](handleEntityNotFound(_0x8f357,null))[_0x1fe3('0x25')](function(_0x1b2477){if(_0x1b2477){return _0x1b2477[_0x1fe3('0x87')]();}return null;})[_0x1fe3('0x25')](respondWithResult(_0x8f357,null))[_0x1fe3('0x1b')](handleError(_0x8f357,null));};exports[_0x1fe3('0x88')]=function(_0x488121,_0x2e0f7b){if(_0x488121[_0x1fe3('0x67')]['id']){delete _0x488121['body']['id'];}return db[_0x1fe3('0x49')][_0x1fe3('0x69')]({'where':{'id':_0x488121['params']['id']}})[_0x1fe3('0x25')](handleEntityNotFound(_0x2e0f7b,null))[_0x1fe3('0x25')](function(_0x4cc1f9){if(_0x4cc1f9){_0x488121[_0x1fe3('0x67')][_0x1fe3('0x6d')]=_0x4cc1f9['id'];return db[_0x1fe3('0x45')]['create'](_0x488121[_0x1fe3('0x67')]);}})[_0x1fe3('0x25')](respondWithResult(_0x2e0f7b,null))[_0x1fe3('0x1b')](handleError(_0x2e0f7b,null));};exports[_0x1fe3('0x89')]=function(_0x160cd5,_0xcab7db){return db[_0x1fe3('0x49')][_0x1fe3('0x76')]({'where':{'id':_0x160cd5[_0x1fe3('0x64')]['id']}})['then'](handleEntityNotFound(_0xcab7db,null))[_0x1fe3('0x25')](function(_0x54616f){if(_0x54616f){return _0x54616f[_0x1fe3('0x8a')](null);}return null;})[_0x1fe3('0x25')](respondWithStatusCode(_0xcab7db,null))['catch'](handleError(_0xcab7db,null));};exports[_0x1fe3('0x8b')]=function(_0x249a5f,_0x441891){return db[_0x1fe3('0x8c')][_0x1fe3('0x69')]({'where':{'id':_0x249a5f['params']['id']}})[_0x1fe3('0x25')](handleEntityNotFound(_0x441891,null))[_0x1fe3('0x25')](function(_0x2e3a76){if(_0x2e3a76){return _0x2e3a76[_0x1fe3('0x8b')](_0x249a5f[_0x1fe3('0x67')][_0x1fe3('0x72')],_[_0x1fe3('0x8d')](_0x249a5f[_0x1fe3('0x67')],[_0x1fe3('0x72'),'id'])||{});}})[_0x1fe3('0x25')](respondWithResult(_0x441891,null))[_0x1fe3('0x1b')](handleError(_0x441891,null));};exports[_0x1fe3('0x8e')]=function(_0x1f32af,_0xc362ef){var _0x16bd4b={'raw':![],'where':{}};var _0x126914={};var _0x130bba={'count':0x0,'rows':[]};return db[_0x1fe3('0x49')][_0x1fe3('0x76')]({'where':{'id':_0x1f32af[_0x1fe3('0x64')]['id']}})[_0x1fe3('0x25')](handleEntityNotFound(_0xc362ef,null))[_0x1fe3('0x25')](function(_0x1a09d9){if(_0x1a09d9){_0x126914['model']=_[_0x1fe3('0x65')](db[_0x1fe3('0x8c')][_0x1fe3('0x4a')]);_0x126914['query']=_[_0x1fe3('0x65')](_0x1f32af[_0x1fe3('0x4f')]);_0x126914['filters']=_[_0x1fe3('0x51')](_0x126914[_0x1fe3('0x4d')],_0x126914['query']);_0x16bd4b[_0x1fe3('0x52')]=_[_0x1fe3('0x51')](_0x126914['model'],qs['fields'](_0x1f32af[_0x1fe3('0x4f')]['fields']));_0x16bd4b[_0x1fe3('0x52')]=_0x16bd4b['attributes'][_0x1fe3('0x54')]?_0x16bd4b['attributes']:_0x126914[_0x1fe3('0x4d')];if(!_0x1f32af[_0x1fe3('0x4f')]['hasOwnProperty']('nolimit')){_0x16bd4b['limit']=qs[_0x1fe3('0x21')](_0x1f32af[_0x1fe3('0x4f')][_0x1fe3('0x21')]);_0x16bd4b[_0x1fe3('0x22')]=qs[_0x1fe3('0x22')](_0x1f32af[_0x1fe3('0x4f')]['offset']);}_0x16bd4b['order']=qs[_0x1fe3('0x58')](_0x1f32af['query']['sort']);_0x16bd4b['where']=qs[_0x1fe3('0x50')](_[_0x1fe3('0x5a')](_0x1f32af[_0x1fe3('0x4f')],_0x126914[_0x1fe3('0x50')]));_0x16bd4b['where'][_0x1fe3('0x6d')]=_0x1a09d9['id'];if(_0x1f32af[_0x1fe3('0x4f')][_0x1fe3('0x70')]){_0x16bd4b[_0x1fe3('0x59')]=_[_0x1fe3('0x5c')](_0x16bd4b[_0x1fe3('0x59')],{'$or':_[_0x1fe3('0x4e')](_0x16bd4b[_0x1fe3('0x52')],function(_0x35228a){var _0x171f38={};_0x171f38[_0x35228a]={'$like':'%'+_0x1f32af[_0x1fe3('0x4f')]['filter']+'%'};return _0x171f38;})});}_0x16bd4b=_['merge']({},_0x16bd4b,_0x1f32af['options']);return db['MailInteraction']['count']({'where':_0x16bd4b[_0x1fe3('0x59')]})[_0x1fe3('0x25')](function(_0x178784){_0x130bba['count']=_0x178784;if(_0x1f32af[_0x1fe3('0x4f')][_0x1fe3('0x5f')]){_0x16bd4b[_0x1fe3('0x60')]=[{'model':db[_0x1fe3('0x8f')],'as':_0x1fe3('0x90'),'required':![]},{'model':db[_0x1fe3('0x91')],'as':'Owner','attributes':[_0x1fe3('0x2a'),_0x1fe3('0x92'),'internal'],'required':![]},{'model':db['Tag'],'as':_0x1fe3('0x93'),'attributes':['id',_0x1fe3('0x2a'),_0x1fe3('0x94')],'where':_0x1f32af[_0x1fe3('0x4f')][_0x1fe3('0x95')]?{'id':_0x1f32af[_0x1fe3('0x4f')][_0x1fe3('0x95')]}:undefined,'required':_0x1f32af[_0x1fe3('0x4f')][_0x1fe3('0x95')]?!![]:![]}];}return db['MailInteraction'][_0x1fe3('0x61')](_0x16bd4b);})[_0x1fe3('0x25')](function(_0x230d67){_0x130bba[_0x1fe3('0x62')]=_0x230d67;return _0x130bba;});}})[_0x1fe3('0x25')](respondWithFilteredResult(_0xc362ef,_0x16bd4b))[_0x1fe3('0x1b')](handleError(_0xc362ef,null));};exports['addApplications']=function addApplications(_0x1aa8f4,_0x3067fa){var _0x3018e4=_0x1aa8f4[_0x1fe3('0x64')]['id'];var _0x45f9eb=_0x1aa8f4['body'];var _0x5ea2c2=0xc8;var _0x3e126d=null;return db[_0x1fe3('0x96')][_0x1fe3('0x97')]({'isolationLevel':db[_0x1fe3('0x96')][_0x1fe3('0x98')][_0x1fe3('0x99')]['READ_COMMITTED']},function(_0x43195d){return db[_0x1fe3('0x49')][_0x1fe3('0x76')]({'where':{'id':_0x3018e4},'transaction':_0x43195d})[_0x1fe3('0x25')](function(_0x1e58f0){if(_0x1e58f0){return db[_0x1fe3('0x9a')][_0x1fe3('0x28')]({'where':{'MailAccountId':_0x3018e4},'transaction':_0x43195d})['then'](function(){var _0x391a93=_[_0x1fe3('0x4e')](_0x45f9eb,function(_0x22ce46){_0x22ce46[_0x1fe3('0x6d')]=_0x3018e4;return _0x22ce46;});return db[_0x1fe3('0x9a')][_0x1fe3('0x9b')](_0x391a93,{'transaction':_0x43195d});});}else{_0x5ea2c2=0x194;_0x3e126d=[];}});})['then'](function(){if(_0x5ea2c2!==0x194){return db[_0x1fe3('0x9a')]['findAndCountAll']({'where':{'MailAccountId':_0x3018e4},'order':_0x1fe3('0x9c')})[_0x1fe3('0x25')](function(_0x3d61fa){_0x3e126d=_0x3d61fa;});}})['catch'](function(_0x28915d){_0x5ea2c2=0x1f4;logger['error'](_0x28915d[_0x1fe3('0x29')]);if(_0x28915d[_0x1fe3('0x2a')]){delete _0x28915d[_0x1fe3('0x2a')];}_0x3e126d=_0x28915d;})[_0x1fe3('0x9d')](function(){if(_0x3e126d===null){_0x3067fa[_0x1fe3('0x1c')](_0x5ea2c2);}else{if(_0x5ea2c2===0x1f4){_0x3067fa[_0x1fe3('0x1d')](_0x5ea2c2)['send'](_0x3e126d);}else{_0x3067fa[_0x1fe3('0x1d')](_0x5ea2c2)[_0x1fe3('0x1f')](_0x3e126d);}}});};exports[_0x1fe3('0x9e')]=function(_0x31f08f,_0x1f2d3f){var _0x565366={};var _0x927203={};var _0x4400b1;var _0x4acf5e;return db[_0x1fe3('0x49')][_0x1fe3('0x76')]({'where':{'id':_0x31f08f['params']['id']}})[_0x1fe3('0x25')](handleEntityNotFound(_0x1f2d3f,null))[_0x1fe3('0x25')](function(_0x34ce9f){if(_0x34ce9f){_0x4400b1=_0x34ce9f;_0x927203[_0x1fe3('0x4d')]=_[_0x1fe3('0x65')](db[_0x1fe3('0x9a')][_0x1fe3('0x4a')]);_0x927203['query']=_[_0x1fe3('0x65')](_0x31f08f[_0x1fe3('0x4f')]);_0x927203[_0x1fe3('0x50')]=_['intersection'](_0x927203['model'],_0x927203['query']);_0x565366['attributes']=_[_0x1fe3('0x51')](_0x927203[_0x1fe3('0x4d')],qs[_0x1fe3('0x53')](_0x31f08f[_0x1fe3('0x4f')][_0x1fe3('0x53')]));_0x565366[_0x1fe3('0x52')]=_0x565366['attributes']['length']?_0x565366[_0x1fe3('0x52')]:_0x927203[_0x1fe3('0x4d')];_0x565366[_0x1fe3('0x57')]=qs[_0x1fe3('0x58')](_0x31f08f[_0x1fe3('0x4f')]['sort']);_0x565366['where']=qs[_0x1fe3('0x50')](_[_0x1fe3('0x5a')](_0x31f08f[_0x1fe3('0x4f')],_0x927203[_0x1fe3('0x50')]));if(_0x31f08f['query'][_0x1fe3('0x70')]){_0x565366['where']=_[_0x1fe3('0x5c')](_0x565366['where'],{'$or':_[_0x1fe3('0x4e')](_0x565366[_0x1fe3('0x52')],function(_0x44a2fd){var _0x44d2cb={};_0x44d2cb[_0x44a2fd]={'$like':'%'+_0x31f08f[_0x1fe3('0x4f')][_0x1fe3('0x70')]+'%'};return _0x44d2cb;})});}_0x565366=_[_0x1fe3('0x5c')]({},_0x565366,_0x31f08f[_0x1fe3('0x5d')]);return _0x4400b1[_0x1fe3('0x9e')](_0x565366);}})[_0x1fe3('0x25')](function(_0x5cca83){if(_0x5cca83){_0x4acf5e=_0x5cca83[_0x1fe3('0x54')];if(!_0x31f08f['query'][_0x1fe3('0x55')](_0x1fe3('0x56'))){_0x565366['limit']=qs[_0x1fe3('0x21')](_0x31f08f['query'][_0x1fe3('0x21')]);_0x565366[_0x1fe3('0x22')]=qs[_0x1fe3('0x22')](_0x31f08f[_0x1fe3('0x4f')][_0x1fe3('0x22')]);}return _0x4400b1[_0x1fe3('0x9e')](_0x565366);}})[_0x1fe3('0x25')](function(_0x516712){if(_0x516712){return _0x516712?{'count':_0x4acf5e,'rows':_0x516712}:null;}})[_0x1fe3('0x25')](respondWithResult(_0x1f2d3f,null))[_0x1fe3('0x1b')](handleError(_0x1f2d3f,null));};exports['getMessages']=function(_0x40a056,_0x31273c){var _0x58a3f2={'raw':!![],'where':{}};var _0x243145={};var _0x3cdce2={'count':0x0,'rows':[]};return db[_0x1fe3('0x49')][_0x1fe3('0x76')]({'where':{'id':_0x40a056[_0x1fe3('0x64')]['id']}})[_0x1fe3('0x25')](handleEntityNotFound(_0x31273c,null))['then'](function(_0xc17142){if(_0xc17142){_0x243145[_0x1fe3('0x4d')]=_[_0x1fe3('0x65')](db[_0x1fe3('0x9f')][_0x1fe3('0x4a')]);_0x243145[_0x1fe3('0x4f')]=_[_0x1fe3('0x65')](_0x40a056[_0x1fe3('0x4f')]);_0x243145[_0x1fe3('0x50')]=_['intersection'](_0x243145['model'],_0x243145[_0x1fe3('0x4f')]);_0x58a3f2['attributes']=_[_0x1fe3('0x51')](_0x243145[_0x1fe3('0x4d')],qs['fields'](_0x40a056[_0x1fe3('0x4f')][_0x1fe3('0x53')]));_0x58a3f2['attributes']=_0x58a3f2['attributes'][_0x1fe3('0x54')]?_0x58a3f2[_0x1fe3('0x52')]:_0x243145[_0x1fe3('0x4d')];if(!_0x40a056['query'][_0x1fe3('0x55')](_0x1fe3('0x56'))){_0x58a3f2[_0x1fe3('0x21')]=qs['limit'](_0x40a056[_0x1fe3('0x4f')][_0x1fe3('0x21')]);_0x58a3f2[_0x1fe3('0x22')]=qs[_0x1fe3('0x22')](_0x40a056['query'][_0x1fe3('0x22')]);}_0x58a3f2['order']=qs[_0x1fe3('0x58')](_0x40a056[_0x1fe3('0x4f')][_0x1fe3('0x58')]);_0x58a3f2[_0x1fe3('0x59')]=qs[_0x1fe3('0x50')](_[_0x1fe3('0x5a')](_0x40a056[_0x1fe3('0x4f')],_0x243145['filters']));_0x58a3f2[_0x1fe3('0x59')][_0x1fe3('0x6d')]=_0xc17142['id'];if(_0x40a056[_0x1fe3('0x4f')]['filter']){_0x58a3f2[_0x1fe3('0x59')]=_[_0x1fe3('0x5c')](_0x58a3f2[_0x1fe3('0x59')],{'$or':_['map'](_0x58a3f2[_0x1fe3('0x52')],function(_0x2a5c88){var _0x456846={};_0x456846[_0x2a5c88]={'$like':'%'+_0x40a056[_0x1fe3('0x4f')][_0x1fe3('0x70')]+'%'};return _0x456846;})});}if(_0x40a056[_0x1fe3('0x4f')][_0x1fe3('0xa0')]){var _0x42eed0=_0x40a056[_0x1fe3('0x4f')][_0x1fe3('0xa0')][_0x1fe3('0xa1')](',');var _0x3417ab={};_0x3417ab[_0x42eed0[0x0]]={'$gte':moment(_0x42eed0[0x1])['format']('YYYY-MM-DD\x20HH:mm:ss')};_0x58a3f2[_0x1fe3('0x59')]=_[_0x1fe3('0x5c')](_0x58a3f2[_0x1fe3('0x59')],_0x3417ab);}_0x58a3f2=_[_0x1fe3('0x5c')]({},_0x58a3f2,_0x40a056[_0x1fe3('0x5d')]);return db['MailMessage'][_0x1fe3('0x5e')]({'where':_0x58a3f2[_0x1fe3('0x59')]})['then'](function(_0x120cda){_0x3cdce2[_0x1fe3('0x5e')]=_0x120cda;if(_0x40a056['query']['includeAll']){_0x58a3f2[_0x1fe3('0x60')]=[{'all':!![]}];}return db[_0x1fe3('0x9f')]['findAll'](_0x58a3f2);})[_0x1fe3('0x25')](function(_0x32e36f){if(_0x40a056[_0x1fe3('0x4f')][_0x1fe3('0xa2')]===_0x1fe3('0xa3')){for(var _0x13fa8e=0x0;_0x13fa8e<_0x32e36f['length'];_0x13fa8e++){_0x32e36f[_0x13fa8e][_0x1fe3('0x67')]=juice(_0x32e36f[_0x13fa8e][_0x1fe3('0x67')]);}}_0x3cdce2[_0x1fe3('0x62')]=_0x32e36f;return _0x3cdce2;});}})[_0x1fe3('0x25')](respondWithFilteredResult(_0x31273c,_0x58a3f2))['catch'](handleError(_0x31273c,null));};exports['send']=function(_0x1a11d0,_0x16fa6a){var _0x481cb8,_0x2cab3e={},_0x4b6c14;if(_0x1a11d0[_0x1fe3('0x67')]['to']){_0x4b6c14=_0x1a11d0['body']['to'][_0x1fe3('0xa1')](',')[0x0];}return db[_0x1fe3('0x49')][_0x1fe3('0x69')]({'where':{'id':_0x1a11d0[_0x1fe3('0x64')]['id']},'include':[{'model':db[_0x1fe3('0xa4')],'as':'List','include':[{'model':db[_0x1fe3('0x8f')],'as':_0x1fe3('0xa5'),'where':{'email':_0x4b6c14},'limit':0x1,'order':[[_0x1fe3('0xa6'),'DESC']]}]},{'model':db[_0x1fe3('0x45')],'as':_0x1fe3('0x46'),'raw':!![],'include':[{'model':db[_0x1fe3('0xa7')],'as':_0x1fe3('0xa7'),'raw':!![]}]}]})[_0x1fe3('0x25')](handleEntityNotFound(_0x16fa6a,null))[_0x1fe3('0x25')](function(_0xf09e2f){if(!_0xf09e2f)return;_0x481cb8=_0xf09e2f;if(!_0xf09e2f[_0x1fe3('0x46')])throw new Error('Smtp\x20configuration\x20not\x20found');if(_[_0x1fe3('0xa8')](_0x1a11d0[_0x1fe3('0x67')][_0x1fe3('0xa9')])){_0x1a11d0[_0x1fe3('0x67')]['from']=util[_0x1fe3('0xaa')](_0x1fe3('0xab'),_0xf09e2f[_0x1fe3('0x2a')],_0xf09e2f[_0x1fe3('0xac')]||_0xf09e2f['Smtp'][_0x1fe3('0x37')]);}if(_0x1a11d0[_0x1fe3('0x67')][_0x1fe3('0xad')]&&_0x1a11d0['body']['attachments'][_0x1fe3('0x54')]){for(var _0x263669=0x0;_0x263669<_0x1a11d0[_0x1fe3('0x67')][_0x1fe3('0xad')][_0x1fe3('0x54')];_0x263669+=0x1){_0x1a11d0[_0x1fe3('0x67')][_0x1fe3('0xad')][_0x263669]={'filename':_0x1a11d0[_0x1fe3('0x67')][_0x1fe3('0xad')][_0x263669][_0x1fe3('0x2a')],'path':path[_0x1fe3('0xae')](config[_0x1fe3('0xaf')],_0x1fe3('0xb0'),_0x1a11d0[_0x1fe3('0x67')][_0x1fe3('0xad')][_0x263669][_0x1fe3('0xb1')])};}}var _0x5959c2=_0xf09e2f['getSmtpOptions']();return respondWithRpcPromise(_0x1fe3('0xb2'),_0x1fe3('0xb3'),{'account':_0x5959c2,'message':_0x1a11d0['body']});})[_0x1fe3('0x25')](function(_0x9d82f7){if(!_0x9d82f7)return;_0x2cab3e=_0x9d82f7;if(!_0x481cb8[_0x1fe3('0xb4')])throw new Error(_0x1fe3('0xb5'));if(_0x481cb8[_0x1fe3('0xb4')]['Contacts'][_0x1fe3('0x54')])return _0x481cb8[_0x1fe3('0xb4')][_0x1fe3('0xa5')][0x0];return db['CmContact'][_0x1fe3('0x74')](_[_0x1fe3('0xb6')](_0x1a11d0[_0x1fe3('0x67')],{'firstName':_0x1a11d0[_0x1fe3('0x67')]['to'],'email':_0x1a11d0[_0x1fe3('0x67')]['to'],'phone':_0x1a11d0[_0x1fe3('0x67')]['to'],'ListId':_0x481cb8[_0x1fe3('0xb7')]}));})[_0x1fe3('0x25')](function(_0x124f9e){if(!_0x124f9e)return;var _0x556518={'UserId':_0x1a11d0[_0x1fe3('0x37')]['id'],'ContactId':_0x124f9e['id'],'MailAccountId':_0x481cb8['id'],'inReplyTo':_0x2cab3e[_0x1fe3('0xb8')],'to':_0x1a11d0[_0x1fe3('0x67')][_0x1fe3('0xa9')],'cc':_0x1a11d0[_0x1fe3('0x67')]['cc'],'subject':_0x1a11d0['body']['subject'],'attach':_0x1a11d0[_0x1fe3('0x67')][_0x1fe3('0xb9')],'firstMsgDirection':_0x1fe3('0xba'),'lastMsgAt':moment()[_0x1fe3('0xaa')](_0x1fe3('0xbb')),'lastMsgDirection':_0x1fe3('0xba'),'Messages':[_[_0x1fe3('0x5c')](_0x1a11d0[_0x1fe3('0x67')],{'messageId':_0x2cab3e[_0x1fe3('0xb8')],'sentAt':moment()[_0x1fe3('0xaa')](_0x1fe3('0xbb')),'read':!![],'MailAccountId':_0x481cb8['id'],'UserId':_0x1a11d0[_0x1fe3('0x37')]['id'],'ContactId':_0x124f9e['id']})]};if(_0x1a11d0['body'][_0x1fe3('0xbc')]){_0x556518=_['merge'](_0x556518,_0x1a11d0[_0x1fe3('0x67')]['Interaction']);}return db['MailInteraction'][_0x1fe3('0x74')](_0x556518,{'include':[{'model':db['MailMessage'],'as':_0x1fe3('0xbd')}]});})[_0x1fe3('0x25')](respondWithResult(_0x16fa6a,null))[_0x1fe3('0x1b')](handleError(_0x16fa6a,null));};exports[_0x1fe3('0xbe')]=function(_0x364cfb,_0x1a69ca){return db[_0x1fe3('0x49')][_0x1fe3('0x69')]({'where':{'id':_0x364cfb[_0x1fe3('0x64')]['id']},'include':[{'model':db['MailServerOut'],'as':_0x1fe3('0x46'),'raw':!![],'include':[{'model':db[_0x1fe3('0xa7')],'as':'CloudProvider','raw':!![]}]}]})[_0x1fe3('0x25')](handleEntityNotFound(_0x1a69ca,null))['then'](function(_0x34f607){if(!_0x34f607[_0x1fe3('0x46')])return;var _0x51e74e=_0x34f607[_0x1fe3('0xbf')]();return respondWithRpcPromise('VerifySmtp',_0x1fe3('0xbe'),{'account':_0x51e74e});})[_0x1fe3('0x25')](respondWithResult(_0x1a69ca,null))['catch'](handleError(_0x1a69ca,null));};exports[_0x1fe3('0x28')]=function(_0x386cec,_0x40c571){return db[_0x1fe3('0x49')][_0x1fe3('0x69')]({'where':{'id':_0x386cec[_0x1fe3('0x64')]['id']}})['then'](handleEntityNotFound(_0x40c571,null))['then'](function(_0x5cba88){if(_0x5cba88&&_0x5cba88[_0x1fe3('0x3f')]){throw new db[(_0x1fe3('0xc0'))][(_0x1fe3('0xc1'))]('You\x20can\x27t\x20remove\x20the\x20mail\x20service\x20account');}return _0x5cba88;})['then'](removeEntity(_0x40c571,null))[_0x1fe3('0x1b')](handleError(_0x40c571,null));};exports[_0x1fe3('0xc2')]=function(_0x4403fb,_0x1451e5){return db[_0x1fe3('0x49')][_0x1fe3('0x69')]({'where':{'id':_0x4403fb[_0x1fe3('0x64')]['id']}})['then'](handleEntityNotFound(_0x1451e5,null))['then'](function(_0x56e44a){if(_0x56e44a){return _0x56e44a[_0x1fe3('0xc2')](_0x4403fb['body'][_0x1fe3('0x72')],_['omit'](_0x4403fb[_0x1fe3('0x67')],[_0x1fe3('0x72'),'id'])||{})['spread'](function(_0x362894){for(var _0x54099f=0x0;_0x54099f<_0x4403fb[_0x1fe3('0x67')]['ids'][_0x1fe3('0x54')];_0x54099f+=0x1){socket[_0x1fe3('0xc3')](_0x1fe3('0xc4'),{'UserId':Number(_0x4403fb['body'][_0x1fe3('0x72')][_0x54099f]),'MailAccountId':Number(_0x4403fb[_0x1fe3('0x64')]['id'])});}return _0x362894;});}})[_0x1fe3('0x25')](respondWithResult(_0x1451e5,null))[_0x1fe3('0x1b')](handleError(_0x1451e5,null));};exports[_0x1fe3('0xc5')]=function(_0x278044,_0x115ecb){return db[_0x1fe3('0x49')][_0x1fe3('0x69')]({'where':{'id':_0x278044['params']['id']}})[_0x1fe3('0x25')](handleEntityNotFound(_0x115ecb,null))[_0x1fe3('0x25')](function(_0x4d5876){if(_0x4d5876){return _0x4d5876['removeAgents'](_0x278044['query'][_0x1fe3('0x72')])[_0x1fe3('0x25')](function(){if(_['isArray'](_0x278044[_0x1fe3('0x4f')][_0x1fe3('0x72')])){for(var _0x407a37=0x0;_0x407a37<_0x278044['query'][_0x1fe3('0x72')][_0x1fe3('0x54')];_0x407a37+=0x1){socket[_0x1fe3('0xc3')](_0x1fe3('0xc6'),{'UserId':Number(_0x278044[_0x1fe3('0x4f')][_0x1fe3('0x72')][_0x407a37]),'MailAccountId':Number(_0x278044['params']['id'])});}}else{socket[_0x1fe3('0xc3')](_0x1fe3('0xc6'),{'UserId':Number(_0x278044['query'][_0x1fe3('0x72')]),'MailAccountId':Number(_0x278044[_0x1fe3('0x64')]['id'])});}});}})[_0x1fe3('0x25')](respondWithStatusCode(_0x115ecb,null))[_0x1fe3('0x1b')](handleError(_0x115ecb,null));};exports[_0x1fe3('0xc7')]=function(_0x16ef30,_0x57398c){var _0x1333e6={};var _0x9a31e={};var _0x182ca0;var _0x376270;return db[_0x1fe3('0x49')][_0x1fe3('0x76')]({'where':{'id':_0x16ef30[_0x1fe3('0x64')]['id']}})['then'](handleEntityNotFound(_0x57398c,null))[_0x1fe3('0x25')](function(_0x9b9cf7){if(_0x9b9cf7){_0x182ca0=_0x9b9cf7;_0x9a31e['model']=_[_0x1fe3('0x65')](db['User'][_0x1fe3('0x4a')]);_0x9a31e['query']=_['keys'](_0x16ef30[_0x1fe3('0x4f')]);_0x9a31e['filters']=_[_0x1fe3('0x51')](_0x9a31e['model'],_0x9a31e[_0x1fe3('0x4f')]);_0x1333e6[_0x1fe3('0x52')]=_[_0x1fe3('0x51')](_0x9a31e['model'],qs[_0x1fe3('0x53')](_0x16ef30[_0x1fe3('0x4f')][_0x1fe3('0x53')]));_0x1333e6[_0x1fe3('0x52')]=_0x1333e6[_0x1fe3('0x52')]['length']?_0x1333e6[_0x1fe3('0x52')]:_0x9a31e['model'];_0x1333e6[_0x1fe3('0x57')]=qs['sort'](_0x16ef30['query']['sort']);_0x1333e6[_0x1fe3('0x59')]=qs[_0x1fe3('0x50')](_[_0x1fe3('0x5a')](_0x16ef30[_0x1fe3('0x4f')],_0x9a31e['filters']));if(_0x16ef30['query'][_0x1fe3('0x70')]){_0x1333e6['where']=_[_0x1fe3('0x5c')](_0x1333e6[_0x1fe3('0x59')],{'$or':_['map'](_0x1333e6['attributes'],function(_0x4c36a7){var _0x4b4298={};_0x4b4298[_0x4c36a7]={'$like':'%'+_0x16ef30['query'][_0x1fe3('0x70')]+'%'};return _0x4b4298;})});}_0x1333e6=_['merge']({},_0x1333e6,_0x16ef30[_0x1fe3('0x5d')]);return _0x182ca0[_0x1fe3('0xc7')](_0x1333e6);}})[_0x1fe3('0x25')](function(_0x45b28f){if(_0x45b28f){_0x376270=_0x45b28f['length'];if(!_0x16ef30[_0x1fe3('0x4f')]['hasOwnProperty']('nolimit')){_0x1333e6[_0x1fe3('0x21')]=qs['limit'](_0x16ef30[_0x1fe3('0x4f')][_0x1fe3('0x21')]);_0x1333e6[_0x1fe3('0x22')]=qs['offset'](_0x16ef30['query'][_0x1fe3('0x22')]);}return _0x182ca0[_0x1fe3('0xc7')](_0x1333e6);}})[_0x1fe3('0x25')](function(_0x4fe659){if(_0x4fe659){return _0x4fe659?{'count':_0x376270,'rows':_0x4fe659}:null;}})[_0x1fe3('0x25')](respondWithResult(_0x57398c,null))[_0x1fe3('0x1b')](handleError(_0x57398c,null));};