Built motion from commit (unavailable).|2.5.4
[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 _0xc03d=['Pause','MailAccount','fieldName','key','model','map','query','filters','intersection','attributes','fields','length','nolimit','limit','sort','where','pick','filter','merge','VIRTUAL','options','includeAll','include','findAll','rows','catch','show','params','mandatoryDispositionPause','rawAttributes','keys','find','body','describe','addDisposition','MailAccountId','create','Disposition','order','removeDispositions','ids','addAnswer','findOne','CannedAnswer','hasOwnProperty','removeAnswers','email','active','description','isNil','cservice','cauthentication','user','cuser','password','pass','authentication','host','port','service','cpassword','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','getImap','removeImap','setImap','getSmtp','addSmtp','removeSmtp','setSmtp','addInteraction','MailInteraction','omit','Contact','User','Owner','fullname','Tags','color','tag','addApplications','MailApplication','priority','getApplications','getMessages','$gte','split','YYYY-MM-DD\x20HH:mm:ss','MailMessage','CmContact','Contacts','updatedAt','DESC','from','%s\x20<%s>','attachments','server/files/attachments','basename','auth','secure','List\x20not\x20found','List','defaults','subject','attach','out','Interaction','verifySmtp','VerifySmtp','ValidationError','You\x20can\x27t\x20remove\x20the\x20mail\x20service\x20account','addAgents','spread','emit','removeAgents','isArray','userMailAccount:remove','getAgents','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','path','sox','lodash','squel','crypto','to-csv','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/utils','../../mysqldb','redis','socket.io-emitter','register','jayson/promise','test','Sequelize','The\x20password\x20must\x20be\x20at\x20least\x208\x20characters\x20long\x20and\x20have\x201\x20lowercase\x20character,\x201\x20uppercase\x20character,\x201\x20number\x20and\x201\x20special\x20character\x20~!@#$%^&-_=+[{]}.','request','then','MailAccount,\x20%s,\x20%s','request\x20sent','MailAccount,\x20%s,\x20%s,\x20%s','stringify','error','message','info','result','sendStatus','end','status','json','count','offset','set','apply','save','update','destroy','UserProfileResource','stack','name','send','index','MailServerIn','Imap','MailServerOut','Smtp'];(function(_0x37c22c,_0x28a70d){var _0x119d79=function(_0x243a13){while(--_0x243a13){_0x37c22c['push'](_0x37c22c['shift']());}};_0x119d79(++_0x28a70d);}(_0xc03d,0x12f));var _0xdc03=function(_0x176711,_0x411ba3){_0x176711=_0x176711-0x0;var _0x197052=_0xc03d[_0x176711];return _0x197052;};'use strict';var pdf=require(_0xdc03('0x0'));var emlformat=require(_0xdc03('0x1'));var rimraf=require(_0xdc03('0x2'));var zipdir=require(_0xdc03('0x3'));var jsonpatch=require(_0xdc03('0x4'));var rp=require(_0xdc03('0x5'));var moment=require('moment');var BPromise=require(_0xdc03('0x6'));var Mustache=require(_0xdc03('0x7'));var util=require(_0xdc03('0x8'));var path=require(_0xdc03('0x9'));var sox=require(_0xdc03('0xa'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var _=require(_0xdc03('0xb'));var squel=require(_0xdc03('0xc'));var crypto=require(_0xdc03('0xd'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0xdc03('0xe'));var querystring=require('querystring');var Papa=require(_0xdc03('0xf'));var Redis=require(_0xdc03('0x10'));var authService=require(_0xdc03('0x11'));var qs=require(_0xdc03('0x12'));var as=require(_0xdc03('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')('api');var utils=require(_0xdc03('0x14'));var config=require('../../config/environment');var db=require(_0xdc03('0x15'))['db'];config['redis']=_['defaults'](config[_0xdc03('0x16')],{'host':'localhost','port':0x18eb});var socket=require(_0xdc03('0x17'))(new Redis(config['redis']));require('./mailAccount.socket')[_0xdc03('0x18')](socket);var jayson=require(_0xdc03('0x19'));var client=jayson['client']['http']({'port':0x232b});function checkPasswordPattern(_0x2a8395,_0x1648cb,_0x16a848){if(_0x16a848){var _0x38daad=new RegExp(/(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[?!@#\$%\^&\*~\-_=+[{\]\}])(?=.{8,})/);if(_0x38daad[_0xdc03('0x1a')](_0x1648cb)){return _0x2a8395;}else{throw new db[(_0xdc03('0x1b'))]['ValidationError'](_0xdc03('0x1c'));}}else{return _0x2a8395;}}function respondWithRpcPromise(_0x10116b,_0x512c96,_0x15e9be,_0x2c00ad){return new BPromise(function(_0x35e7f8,_0x31e672){var _0xd8f4a7=_0x2c00ad||client;return _0xd8f4a7[_0xdc03('0x1d')](_0x10116b,_0x15e9be)[_0xdc03('0x1e')](function(_0xb24c36){logger['info'](_0xdc03('0x1f'),_0x512c96,_0xdc03('0x20'));logger['debug'](_0xdc03('0x21'),_0x512c96,_0xdc03('0x20'),JSON[_0xdc03('0x22')](_0xb24c36));if(_0xb24c36[_0xdc03('0x23')]){if(_0xb24c36['error']['code']===0x1f4){logger[_0xdc03('0x23')](_0xdc03('0x1f'),_0x512c96,_0xb24c36['error'][_0xdc03('0x24')]);return _0x31e672(_0xb24c36[_0xdc03('0x23')]['message']);}logger['error'](_0xdc03('0x1f'),_0x512c96,_0xb24c36[_0xdc03('0x23')]['message']);return _0x35e7f8(_0xb24c36[_0xdc03('0x23')][_0xdc03('0x24')]);}else{logger[_0xdc03('0x25')](_0xdc03('0x1f'),_0x512c96,'request\x20sent');_0x35e7f8(_0xb24c36[_0xdc03('0x26')][_0xdc03('0x24')]);}})['catch'](function(_0x26fdb3){logger[_0xdc03('0x23')](_0xdc03('0x1f'),_0x512c96,_0x26fdb3);_0x31e672(_0x26fdb3);});});}function respondWithStatusCode(_0x35f9fe,_0x5684de){_0x5684de=_0x5684de||0xcc;return function(_0x4c99c1){if(_0x4c99c1){return _0x35f9fe[_0xdc03('0x27')](_0x5684de);}return _0x35f9fe['status'](_0x5684de)[_0xdc03('0x28')]();};}function respondWithResult(_0x1fa1d2,_0x5cf3dc){_0x5cf3dc=_0x5cf3dc||0xc8;return function(_0x8eb971){if(_0x8eb971){return _0x1fa1d2[_0xdc03('0x29')](_0x5cf3dc)[_0xdc03('0x2a')](_0x8eb971);}};}function respondWithFilteredResult(_0x24416a,_0x5aac66){return function(_0x2952cb){if(_0x2952cb){var _0x1eeff3=_0x2952cb[_0xdc03('0x2b')],_0x13bac2=_0x5aac66['offset'],_0x7b0cec=_0x5aac66[_0xdc03('0x2c')]+_0x5aac66['limit'],_0x4e0366;if(_0x7b0cec>=_0x1eeff3){_0x7b0cec=_0x1eeff3;_0x4e0366=0xc8;}else{_0x4e0366=0xce;}_0x24416a[_0xdc03('0x29')](_0x4e0366);return _0x24416a[_0xdc03('0x2d')]('Content-Range',_0x13bac2+'-'+_0x7b0cec+'/'+_0x1eeff3)['json'](_0x2952cb);}return null;};}function patchUpdates(_0x5264a2){return function(_0x2f1806){try{jsonpatch[_0xdc03('0x2e')](_0x2f1806,_0x5264a2,!![]);}catch(_0x2f0506){return BPromise['reject'](_0x2f0506);}return _0x2f1806[_0xdc03('0x2f')]();};}function saveUpdates(_0x264e77,_0x1962d4){return function(_0x1a3f6d){if(_0x1a3f6d){return _0x1a3f6d[_0xdc03('0x30')](_0x264e77)[_0xdc03('0x1e')](function(_0x5a9baf){return _0x5a9baf;});}return null;};}function removeEntity(_0x55f9cb,_0x3341ab){return function(_0x3b44ef){if(_0x3b44ef){return _0x3b44ef[_0xdc03('0x31')]()['then'](function(){var _0x15b612=_0x3b44ef['get']({'plain':!![]});var _0x51fcc3='MailAccounts';return db[_0xdc03('0x32')][_0xdc03('0x31')]({'where':{'type':_0x51fcc3,'resourceId':_0x15b612['id']}})[_0xdc03('0x1e')](function(){return _0x3b44ef;});})[_0xdc03('0x1e')](function(){_0x55f9cb[_0xdc03('0x29')](0xcc)[_0xdc03('0x28')]();});}};}function handleEntityNotFound(_0x247a9a,_0x1ff441){return function(_0x5492f3){if(!_0x5492f3){_0x247a9a[_0xdc03('0x27')](0x194);}return _0x5492f3;};}function handleError(_0x2a5df9,_0x4be55a){_0x4be55a=_0x4be55a||0x1f4;return function(_0x190d58){logger[_0xdc03('0x23')](_0x190d58[_0xdc03('0x33')]);if(_0x190d58[_0xdc03('0x34')]){delete _0x190d58[_0xdc03('0x34')];}_0x2a5df9[_0xdc03('0x29')](_0x4be55a)[_0xdc03('0x35')](_0x190d58);};}exports[_0xdc03('0x36')]=function(_0x455b41,_0x373b94){var _0x29aeb9={'include':[{'model':db[_0xdc03('0x37')],'as':_0xdc03('0x38')},{'model':db[_0xdc03('0x39')],'as':_0xdc03('0x3a')},{'model':db[_0xdc03('0x3b')],'as':'mandatoryDispositionPause'}]},_0x549719={},_0x243ce1={'count':0x0,'rows':[]};var _0x32bae8=_['map'](db[_0xdc03('0x3c')]['rawAttributes'],function(_0x32f2fa){return{'name':_0x32f2fa[_0xdc03('0x3d')],'type':_0x32f2fa['type'][_0xdc03('0x3e')]};});_0x549719[_0xdc03('0x3f')]=_[_0xdc03('0x40')](_0x32bae8,_0xdc03('0x34'));_0x549719[_0xdc03('0x41')]=_['keys'](_0x455b41[_0xdc03('0x41')]);_0x549719[_0xdc03('0x42')]=_[_0xdc03('0x43')](_0x549719['model'],_0x549719[_0xdc03('0x41')]);_0x29aeb9[_0xdc03('0x44')]=_[_0xdc03('0x43')](_0x549719['model'],qs[_0xdc03('0x45')](_0x455b41[_0xdc03('0x41')][_0xdc03('0x45')]));_0x29aeb9[_0xdc03('0x44')]=_0x29aeb9['attributes'][_0xdc03('0x46')]?_0x29aeb9['attributes']:_0x549719[_0xdc03('0x3f')];if(!_0x455b41[_0xdc03('0x41')]['hasOwnProperty'](_0xdc03('0x47'))){_0x29aeb9[_0xdc03('0x48')]=qs[_0xdc03('0x48')](_0x455b41[_0xdc03('0x41')][_0xdc03('0x48')]);_0x29aeb9['offset']=qs[_0xdc03('0x2c')](_0x455b41[_0xdc03('0x41')][_0xdc03('0x2c')]);}_0x29aeb9['order']=qs[_0xdc03('0x49')](_0x455b41[_0xdc03('0x41')][_0xdc03('0x49')]);_0x29aeb9[_0xdc03('0x4a')]=qs[_0xdc03('0x42')](_[_0xdc03('0x4b')](_0x455b41[_0xdc03('0x41')],_0x549719['filters']),_0x32bae8);if(_0x455b41[_0xdc03('0x41')][_0xdc03('0x4c')]){_0x29aeb9[_0xdc03('0x4a')]=_[_0xdc03('0x4d')](_0x29aeb9[_0xdc03('0x4a')],{'$or':_[_0xdc03('0x40')](_0x32bae8,function(_0x166bba){if(_0x166bba['type']!==_0xdc03('0x4e')){var _0x469410={};_0x469410[_0x166bba['name']]={'$like':'%'+_0x455b41[_0xdc03('0x41')][_0xdc03('0x4c')]+'%'};return _0x469410;}})});}_0x29aeb9=_[_0xdc03('0x4d')]({},_0x29aeb9,_0x455b41[_0xdc03('0x4f')]);var _0x49c798={'where':_0x29aeb9[_0xdc03('0x4a')]};return db[_0xdc03('0x3c')]['count'](_0x49c798)['then'](function(_0xdc066a){_0x243ce1[_0xdc03('0x2b')]=_0xdc066a;if(_0x455b41['query'][_0xdc03('0x50')]){_0x29aeb9[_0xdc03('0x51')]=[{'all':!![]}];}return db[_0xdc03('0x3c')][_0xdc03('0x52')](_0x29aeb9);})['then'](function(_0x6e7e7b){_0x243ce1[_0xdc03('0x53')]=_0x6e7e7b;return _0x243ce1;})[_0xdc03('0x1e')](respondWithFilteredResult(_0x373b94,_0x29aeb9))[_0xdc03('0x54')](handleError(_0x373b94,null));};exports[_0xdc03('0x55')]=function(_0x2d727e,_0x221743){var _0x57e358={'raw':![],'where':{'id':_0x2d727e[_0xdc03('0x56')]['id']},'include':[{'model':db[_0xdc03('0x37')],'as':_0xdc03('0x38')},{'model':db[_0xdc03('0x39')],'as':'Smtp'},{'model':db['Pause'],'as':_0xdc03('0x57')}]},_0x63cba3={};_0x63cba3[_0xdc03('0x3f')]=_['keys'](db[_0xdc03('0x3c')][_0xdc03('0x58')]);_0x63cba3['query']=_[_0xdc03('0x59')](_0x2d727e[_0xdc03('0x41')]);_0x63cba3[_0xdc03('0x42')]=_[_0xdc03('0x43')](_0x63cba3[_0xdc03('0x3f')],_0x63cba3[_0xdc03('0x41')]);_0x57e358[_0xdc03('0x44')]=_[_0xdc03('0x43')](_0x63cba3[_0xdc03('0x3f')],qs[_0xdc03('0x45')](_0x2d727e[_0xdc03('0x41')]['fields']));_0x57e358[_0xdc03('0x44')]=_0x57e358['attributes'][_0xdc03('0x46')]?_0x57e358[_0xdc03('0x44')]:_0x63cba3[_0xdc03('0x3f')];if(_0x2d727e[_0xdc03('0x41')][_0xdc03('0x50')]){_0x57e358[_0xdc03('0x51')]=[{'all':!![]}];}_0x57e358=_[_0xdc03('0x4d')]({},_0x57e358,_0x2d727e['options']);return db['MailAccount'][_0xdc03('0x5a')](_0x57e358)['then'](handleEntityNotFound(_0x221743,null))[_0xdc03('0x1e')](respondWithResult(_0x221743,null))[_0xdc03('0x54')](handleError(_0x221743,null));};exports[_0xdc03('0x30')]=function(_0x509ae0,_0x4b9ec2){if(_0x509ae0[_0xdc03('0x5b')]['id']){delete _0x509ae0['body']['id'];}return db[_0xdc03('0x3c')][_0xdc03('0x5a')]({'where':{'id':_0x509ae0[_0xdc03('0x56')]['id']},'include':[{'model':db[_0xdc03('0x37')],'as':_0xdc03('0x38')},{'model':db[_0xdc03('0x39')],'as':_0xdc03('0x3a')},{'model':db[_0xdc03('0x3b')],'as':'mandatoryDispositionPause'}]})['then'](handleEntityNotFound(_0x4b9ec2,null))[_0xdc03('0x1e')](saveUpdates(_0x509ae0[_0xdc03('0x5b')],null))[_0xdc03('0x1e')](function(_0x534d27){if(_0x534d27&&_0x509ae0['body'][_0xdc03('0x38')]){return db[_0xdc03('0x37')][_0xdc03('0x30')](_0x509ae0[_0xdc03('0x5b')][_0xdc03('0x38')],{'where':{'MailAccountId':_0x534d27['id']}})[_0xdc03('0x1e')](function(){return _0x534d27;});}return _0x534d27;})['then'](function(_0x2004f0){if(_0x2004f0&&_0x509ae0[_0xdc03('0x5b')]['Smtp']){return db[_0xdc03('0x39')][_0xdc03('0x30')](_0x509ae0[_0xdc03('0x5b')][_0xdc03('0x3a')],{'where':{'MailAccountId':_0x2004f0['id']}})[_0xdc03('0x1e')](function(){return _0x2004f0;});}return _0x2004f0;})[_0xdc03('0x1e')](respondWithResult(_0x4b9ec2,null))[_0xdc03('0x54')](handleError(_0x4b9ec2,null));};exports[_0xdc03('0x5c')]=function(_0x2296ef,_0x5ab8fd){return db[_0xdc03('0x3c')][_0xdc03('0x5c')]()[_0xdc03('0x1e')](respondWithResult(_0x5ab8fd,null))[_0xdc03('0x54')](handleError(_0x5ab8fd,null));};exports[_0xdc03('0x5d')]=function(_0x35a4de,_0x2e9370,_0x13f5ad){if(_0x35a4de['body']['id']){delete _0x35a4de[_0xdc03('0x5b')]['id'];}return db[_0xdc03('0x3c')][_0xdc03('0x5a')]({'where':{'id':_0x35a4de['params']['id']}})['then'](handleEntityNotFound(_0x2e9370,null))[_0xdc03('0x1e')](function(_0x40d191){if(_0x40d191){_0x35a4de[_0xdc03('0x5b')][_0xdc03('0x5e')]=_0x40d191['id'];return db['Disposition'][_0xdc03('0x5f')](_0x35a4de[_0xdc03('0x5b')]);}})[_0xdc03('0x1e')](respondWithResult(_0x2e9370,null))[_0xdc03('0x54')](handleError(_0x2e9370,null));};exports['getDispositions']=function(_0x2a9677,_0x160cfe,_0x2d617c){var _0x451677={'raw':![],'where':{}};var _0x1eedd0={};var _0x1cb1b0={'count':0x0,'rows':[]};return db['MailAccount']['findOne']({'where':{'id':_0x2a9677[_0xdc03('0x56')]['id']}})[_0xdc03('0x1e')](handleEntityNotFound(_0x160cfe,null))[_0xdc03('0x1e')](function(_0x4bde3f){if(_0x4bde3f){_0x1eedd0[_0xdc03('0x3f')]=_[_0xdc03('0x59')](db[_0xdc03('0x60')]['rawAttributes']);_0x1eedd0[_0xdc03('0x41')]=_[_0xdc03('0x59')](_0x2a9677[_0xdc03('0x41')]);_0x1eedd0['filters']=_[_0xdc03('0x43')](_0x1eedd0[_0xdc03('0x3f')],_0x1eedd0['query']);_0x451677['attributes']=_['intersection'](_0x1eedd0[_0xdc03('0x3f')],qs[_0xdc03('0x45')](_0x2a9677[_0xdc03('0x41')]['fields']));_0x451677[_0xdc03('0x44')]=_0x451677[_0xdc03('0x44')][_0xdc03('0x46')]?_0x451677['attributes']:_0x1eedd0[_0xdc03('0x3f')];if(!_0x2a9677[_0xdc03('0x41')]['hasOwnProperty']('nolimit')){_0x451677[_0xdc03('0x48')]=qs[_0xdc03('0x48')](_0x2a9677[_0xdc03('0x41')][_0xdc03('0x48')]);_0x451677[_0xdc03('0x2c')]=qs[_0xdc03('0x2c')](_0x2a9677[_0xdc03('0x41')][_0xdc03('0x2c')]);}_0x451677[_0xdc03('0x61')]=qs['sort'](_0x2a9677[_0xdc03('0x41')]['sort']);_0x451677[_0xdc03('0x4a')]=qs['filters'](_[_0xdc03('0x4b')](_0x2a9677[_0xdc03('0x41')],_0x1eedd0['filters']));_0x451677['where'][_0xdc03('0x5e')]=_0x4bde3f['id'];if(_0x2a9677['query'][_0xdc03('0x4c')]){_0x451677[_0xdc03('0x4a')]=_['merge'](_0x451677[_0xdc03('0x4a')],{'$or':_[_0xdc03('0x40')](_0x451677[_0xdc03('0x44')],function(_0x48297e){var _0xa9ec99={};_0xa9ec99[_0x48297e]={'$like':'%'+_0x2a9677['query'][_0xdc03('0x4c')]+'%'};return _0xa9ec99;})});}_0x451677=_[_0xdc03('0x4d')]({},_0x451677,_0x2a9677[_0xdc03('0x4f')]);return db[_0xdc03('0x60')][_0xdc03('0x2b')]({'where':_0x451677[_0xdc03('0x4a')]})[_0xdc03('0x1e')](function(_0x3edff7){_0x1cb1b0[_0xdc03('0x2b')]=_0x3edff7;if(_0x2a9677['query'][_0xdc03('0x50')]){_0x451677['include']=[{'all':!![]}];}return db['Disposition'][_0xdc03('0x52')](_0x451677);})[_0xdc03('0x1e')](function(_0x50b374){_0x1cb1b0[_0xdc03('0x53')]=_0x50b374;return _0x1cb1b0;});}})[_0xdc03('0x1e')](respondWithFilteredResult(_0x160cfe,_0x451677))['catch'](handleError(_0x160cfe,null));};exports[_0xdc03('0x62')]=function(_0x3d7507,_0x6d346b,_0x33cf3e){return db[_0xdc03('0x3c')]['find']({'where':{'id':_0x3d7507[_0xdc03('0x56')]['id']}})[_0xdc03('0x1e')](handleEntityNotFound(_0x6d346b,null))[_0xdc03('0x1e')](function(_0x5163ed){if(_0x5163ed){return _0x5163ed['removeDispositions'](_0x3d7507[_0xdc03('0x41')][_0xdc03('0x63')]);}})['then'](respondWithStatusCode(_0x6d346b,null))[_0xdc03('0x54')](handleError(_0x6d346b,null));};exports[_0xdc03('0x64')]=function(_0x1f552f,_0x5e203f,_0x2e325f){if(_0x1f552f[_0xdc03('0x5b')]['id']){delete _0x1f552f[_0xdc03('0x5b')]['id'];}return db[_0xdc03('0x3c')][_0xdc03('0x5a')]({'where':{'id':_0x1f552f[_0xdc03('0x56')]['id']}})[_0xdc03('0x1e')](handleEntityNotFound(_0x5e203f,null))[_0xdc03('0x1e')](function(_0x351067){if(_0x351067){_0x1f552f[_0xdc03('0x5b')][_0xdc03('0x5e')]=_0x351067['id'];return db['CannedAnswer'][_0xdc03('0x5f')](_0x1f552f[_0xdc03('0x5b')]);}})['then'](respondWithResult(_0x5e203f,null))[_0xdc03('0x54')](handleError(_0x5e203f,null));};exports['getAnswers']=function(_0x3fa927,_0xa63ab3,_0x4da1a6){var _0x52f57c={'raw':![],'where':{}};var _0x4e255f={};var _0x46094b={'count':0x0,'rows':[]};return db[_0xdc03('0x3c')][_0xdc03('0x65')]({'where':{'id':_0x3fa927[_0xdc03('0x56')]['id']}})[_0xdc03('0x1e')](handleEntityNotFound(_0xa63ab3,null))[_0xdc03('0x1e')](function(_0x3a2a0e){if(_0x3a2a0e){_0x4e255f[_0xdc03('0x3f')]=_['keys'](db[_0xdc03('0x66')][_0xdc03('0x58')]);_0x4e255f['query']=_[_0xdc03('0x59')](_0x3fa927['query']);_0x4e255f['filters']=_[_0xdc03('0x43')](_0x4e255f[_0xdc03('0x3f')],_0x4e255f[_0xdc03('0x41')]);_0x52f57c[_0xdc03('0x44')]=_[_0xdc03('0x43')](_0x4e255f[_0xdc03('0x3f')],qs[_0xdc03('0x45')](_0x3fa927[_0xdc03('0x41')][_0xdc03('0x45')]));_0x52f57c[_0xdc03('0x44')]=_0x52f57c[_0xdc03('0x44')][_0xdc03('0x46')]?_0x52f57c[_0xdc03('0x44')]:_0x4e255f[_0xdc03('0x3f')];if(!_0x3fa927[_0xdc03('0x41')][_0xdc03('0x67')](_0xdc03('0x47'))){_0x52f57c[_0xdc03('0x48')]=qs[_0xdc03('0x48')](_0x3fa927[_0xdc03('0x41')][_0xdc03('0x48')]);_0x52f57c['offset']=qs[_0xdc03('0x2c')](_0x3fa927['query']['offset']);}_0x52f57c[_0xdc03('0x61')]=qs['sort'](_0x3fa927[_0xdc03('0x41')]['sort']);_0x52f57c[_0xdc03('0x4a')]=qs[_0xdc03('0x42')](_[_0xdc03('0x4b')](_0x3fa927['query'],_0x4e255f[_0xdc03('0x42')]));_0x52f57c['where'][_0xdc03('0x5e')]=_0x3a2a0e['id'];if(_0x3fa927[_0xdc03('0x41')][_0xdc03('0x4c')]){_0x52f57c[_0xdc03('0x4a')]=_[_0xdc03('0x4d')](_0x52f57c[_0xdc03('0x4a')],{'$or':_[_0xdc03('0x40')](_0x52f57c[_0xdc03('0x44')],function(_0x57fd5c){var _0x498766={};_0x498766[_0x57fd5c]={'$like':'%'+_0x3fa927[_0xdc03('0x41')][_0xdc03('0x4c')]+'%'};return _0x498766;})});}_0x52f57c=_[_0xdc03('0x4d')]({},_0x52f57c,_0x3fa927[_0xdc03('0x4f')]);return db[_0xdc03('0x66')][_0xdc03('0x2b')]({'where':_0x52f57c[_0xdc03('0x4a')]})['then'](function(_0x32a31e){_0x46094b[_0xdc03('0x2b')]=_0x32a31e;if(_0x3fa927[_0xdc03('0x41')]['includeAll']){_0x52f57c[_0xdc03('0x51')]=[{'all':!![]}];}return db['CannedAnswer'][_0xdc03('0x52')](_0x52f57c);})[_0xdc03('0x1e')](function(_0x3e3c72){_0x46094b[_0xdc03('0x53')]=_0x3e3c72;return _0x46094b;});}})[_0xdc03('0x1e')](respondWithFilteredResult(_0xa63ab3,_0x52f57c))[_0xdc03('0x54')](handleError(_0xa63ab3,null));};exports['removeAnswers']=function(_0x50502a,_0x38b7cd,_0x4791d0){return db['MailAccount'][_0xdc03('0x5a')]({'where':{'id':_0x50502a[_0xdc03('0x56')]['id']}})['then'](handleEntityNotFound(_0x38b7cd,null))['then'](function(_0x50f5f5){if(_0x50f5f5){return _0x50f5f5[_0xdc03('0x68')](_0x50502a[_0xdc03('0x41')]['ids']);}})[_0xdc03('0x1e')](respondWithStatusCode(_0x38b7cd,null))[_0xdc03('0x54')](handleError(_0x38b7cd,null));};exports[_0xdc03('0x5f')]=function(_0x252b1e,_0x389f3e){var _0x4d0af4={'name':_0x252b1e[_0xdc03('0x5b')][_0xdc03('0x34')],'key':_0x252b1e[_0xdc03('0x5b')][_0xdc03('0x3e')],'email':_0x252b1e[_0xdc03('0x5b')][_0xdc03('0x69')],'ListId':_0x252b1e[_0xdc03('0x5b')]['ListId'],'active':!_['isNil'](_0x252b1e[_0xdc03('0x5b')][_0xdc03('0x6a')])?_0x252b1e['body'][_0xdc03('0x6a')]:!![],'description':_0x252b1e[_0xdc03('0x5b')][_0xdc03('0x6b')]||null,'Imap':{},'Smtp':{}};if(_[_0xdc03('0x6c')](_0x252b1e[_0xdc03('0x5b')][_0xdc03('0x6d')])){if(_0x252b1e[_0xdc03('0x5b')][_0xdc03('0x6e')]){_0x4d0af4[_0xdc03('0x38')][_0xdc03('0x6f')]=_0x4d0af4[_0xdc03('0x3a')]['user']=_0x252b1e[_0xdc03('0x5b')][_0xdc03('0x70')];_0x4d0af4[_0xdc03('0x38')][_0xdc03('0x71')]=_0x4d0af4['Smtp'][_0xdc03('0x72')]=_0x252b1e[_0xdc03('0x5b')]['cpassword'];}else{_0x4d0af4[_0xdc03('0x38')]['authentication']=_0x4d0af4[_0xdc03('0x3a')][_0xdc03('0x73')]=![];}_0x4d0af4['Imap'][_0xdc03('0x74')]=_0x252b1e[_0xdc03('0x5b')][_0xdc03('0x38')][_0xdc03('0x74')];_0x4d0af4['Imap'][_0xdc03('0x75')]=_0x252b1e[_0xdc03('0x5b')][_0xdc03('0x38')]['port'];_0x4d0af4[_0xdc03('0x3a')][_0xdc03('0x74')]=_0x252b1e['body'][_0xdc03('0x3a')][_0xdc03('0x74')];_0x4d0af4[_0xdc03('0x3a')]['port']=_0x252b1e[_0xdc03('0x5b')][_0xdc03('0x3a')][_0xdc03('0x75')];}else{_0x4d0af4[_0xdc03('0x38')][_0xdc03('0x76')]=_0x4d0af4[_0xdc03('0x3a')][_0xdc03('0x76')]=_0x252b1e['body'][_0xdc03('0x6d')];_0x4d0af4['Imap'][_0xdc03('0x6f')]=_0x4d0af4[_0xdc03('0x3a')][_0xdc03('0x6f')]=_0x252b1e['body'][_0xdc03('0x70')];_0x4d0af4[_0xdc03('0x38')][_0xdc03('0x71')]=_0x4d0af4[_0xdc03('0x3a')]['pass']=_0x252b1e[_0xdc03('0x5b')][_0xdc03('0x77')];}return db[_0xdc03('0x3c')]['create'](_0x4d0af4,{'include':[{'model':db[_0xdc03('0x39')],'as':_0xdc03('0x3a')},{'model':db[_0xdc03('0x37')],'as':_0xdc03('0x38')}]})['then'](function(_0x17a46a){var _0x3799e5=_0x252b1e[_0xdc03('0x6f')][_0xdc03('0x78')]({'plain':!![]});if(!_0x3799e5)throw new Error(_0xdc03('0x79'));if(_0x3799e5['role']===_0xdc03('0x6f')){var _0x56a98c=_0x17a46a['get']({'plain':!![]});return db[_0xdc03('0x7a')][_0xdc03('0x5a')]({'where':{'name':'MailAccounts','userProfileId':_0x3799e5[_0xdc03('0x7b')]},'raw':!![]})[_0xdc03('0x1e')](function(_0x3d8503){if(_0x3d8503&&_0x3d8503[_0xdc03('0x7c')]===0x0){return db['UserProfileResource'][_0xdc03('0x5f')]({'name':_0x56a98c[_0xdc03('0x34')],'resourceId':_0x56a98c['id'],'type':_0x3d8503[_0xdc03('0x34')],'sectionId':_0x3d8503['id']},{})['then'](function(){return _0x17a46a;});}else{return _0x17a46a;}})[_0xdc03('0x54')](function(_0x24b221){logger[_0xdc03('0x23')](_0xdc03('0x7d'),_0x24b221);throw _0x24b221;});}return _0x17a46a;})[_0xdc03('0x1e')](respondWithResult(_0x389f3e,0xc9))['catch'](handleError(_0x389f3e,null));};exports[_0xdc03('0x7e')]=function(_0x241f70,_0x33a01b,_0x4ccc43){return db[_0xdc03('0x3c')][_0xdc03('0x65')]({'where':{'id':_0x241f70[_0xdc03('0x56')]['id']}})[_0xdc03('0x1e')](handleEntityNotFound(_0x33a01b,null))[_0xdc03('0x1e')](function(_0x473626){if(_0x473626){return _0x473626[_0xdc03('0x7e')]();}return null;})[_0xdc03('0x1e')](respondWithResult(_0x33a01b,null))[_0xdc03('0x54')](handleError(_0x33a01b,null));};exports['addImap']=function(_0x56b70d,_0x37400e,_0x2d8865){if(_0x56b70d[_0xdc03('0x5b')]['id']){delete _0x56b70d[_0xdc03('0x5b')]['id'];}return db['MailAccount']['find']({'where':{'id':_0x56b70d['params']['id']}})[_0xdc03('0x1e')](handleEntityNotFound(_0x37400e,null))['then'](function(_0x40363e){if(_0x40363e){_0x56b70d['body'][_0xdc03('0x5e')]=_0x40363e['id'];return db['MailServerIn'][_0xdc03('0x5f')](_0x56b70d[_0xdc03('0x5b')]);}})[_0xdc03('0x1e')](respondWithResult(_0x37400e,null))[_0xdc03('0x54')](handleError(_0x37400e,null));};exports[_0xdc03('0x7f')]=function(_0x2fa197,_0x14630f,_0x54dccb){return db[_0xdc03('0x3c')][_0xdc03('0x65')]({'where':{'id':_0x2fa197[_0xdc03('0x56')]['id']}})[_0xdc03('0x1e')](handleEntityNotFound(_0x14630f,null))[_0xdc03('0x1e')](function(_0x191f35){if(_0x191f35){return _0x191f35[_0xdc03('0x80')](null);}return null;})[_0xdc03('0x1e')](respondWithStatusCode(_0x14630f,null))[_0xdc03('0x54')](handleError(_0x14630f,null));};exports[_0xdc03('0x81')]=function(_0x56216d,_0x43a00a,_0x4557cc){return db['MailAccount']['findOne']({'where':{'id':_0x56216d['params']['id']}})['then'](handleEntityNotFound(_0x43a00a,null))[_0xdc03('0x1e')](function(_0x352c49){if(_0x352c49){return _0x352c49['getSmtp']();}return null;})['then'](respondWithResult(_0x43a00a,null))[_0xdc03('0x54')](handleError(_0x43a00a,null));};exports[_0xdc03('0x82')]=function(_0x45838d,_0x4643a9,_0x322cef){if(_0x45838d[_0xdc03('0x5b')]['id']){delete _0x45838d[_0xdc03('0x5b')]['id'];}return db[_0xdc03('0x3c')][_0xdc03('0x5a')]({'where':{'id':_0x45838d[_0xdc03('0x56')]['id']}})[_0xdc03('0x1e')](handleEntityNotFound(_0x4643a9,null))[_0xdc03('0x1e')](function(_0x1c5229){if(_0x1c5229){_0x45838d[_0xdc03('0x5b')][_0xdc03('0x5e')]=_0x1c5229['id'];return db[_0xdc03('0x39')][_0xdc03('0x5f')](_0x45838d[_0xdc03('0x5b')]);}})[_0xdc03('0x1e')](respondWithResult(_0x4643a9,null))['catch'](handleError(_0x4643a9,null));};exports[_0xdc03('0x83')]=function(_0x359d0b,_0x46aacc,_0x13e696){return db[_0xdc03('0x3c')][_0xdc03('0x65')]({'where':{'id':_0x359d0b[_0xdc03('0x56')]['id']}})['then'](handleEntityNotFound(_0x46aacc,null))[_0xdc03('0x1e')](function(_0x2659cb){if(_0x2659cb){return _0x2659cb[_0xdc03('0x84')](null);}return null;})['then'](respondWithStatusCode(_0x46aacc,null))[_0xdc03('0x54')](handleError(_0x46aacc,null));};exports[_0xdc03('0x85')]=function(_0x340506,_0x56ad86,_0x24fe57){return db[_0xdc03('0x86')][_0xdc03('0x5a')]({'where':{'id':_0x340506[_0xdc03('0x56')]['id']}})[_0xdc03('0x1e')](handleEntityNotFound(_0x56ad86,null))[_0xdc03('0x1e')](function(_0x10644a){if(_0x10644a){return _0x10644a['addInteraction'](_0x340506['body'][_0xdc03('0x63')],_[_0xdc03('0x87')](_0x340506[_0xdc03('0x5b')],['ids','id'])||{});}})['then'](respondWithResult(_0x56ad86,null))[_0xdc03('0x54')](handleError(_0x56ad86,null));};exports['getInteractions']=function(_0x3767e1,_0x295ca4,_0x2fd7f3){var _0x3736a0={'raw':![],'where':{}};var _0x3da0ca={};var _0x238ff3={'count':0x0,'rows':[]};return db[_0xdc03('0x3c')]['findOne']({'where':{'id':_0x3767e1['params']['id']}})[_0xdc03('0x1e')](handleEntityNotFound(_0x295ca4,null))['then'](function(_0x59c2d0){if(_0x59c2d0){_0x3da0ca[_0xdc03('0x3f')]=_[_0xdc03('0x59')](db['MailInteraction']['rawAttributes']);_0x3da0ca['query']=_[_0xdc03('0x59')](_0x3767e1[_0xdc03('0x41')]);_0x3da0ca[_0xdc03('0x42')]=_[_0xdc03('0x43')](_0x3da0ca[_0xdc03('0x3f')],_0x3da0ca[_0xdc03('0x41')]);_0x3736a0[_0xdc03('0x44')]=_[_0xdc03('0x43')](_0x3da0ca[_0xdc03('0x3f')],qs[_0xdc03('0x45')](_0x3767e1[_0xdc03('0x41')][_0xdc03('0x45')]));_0x3736a0[_0xdc03('0x44')]=_0x3736a0[_0xdc03('0x44')][_0xdc03('0x46')]?_0x3736a0[_0xdc03('0x44')]:_0x3da0ca[_0xdc03('0x3f')];if(!_0x3767e1[_0xdc03('0x41')][_0xdc03('0x67')](_0xdc03('0x47'))){_0x3736a0[_0xdc03('0x48')]=qs['limit'](_0x3767e1['query'][_0xdc03('0x48')]);_0x3736a0[_0xdc03('0x2c')]=qs[_0xdc03('0x2c')](_0x3767e1[_0xdc03('0x41')][_0xdc03('0x2c')]);}_0x3736a0['order']=qs[_0xdc03('0x49')](_0x3767e1[_0xdc03('0x41')][_0xdc03('0x49')]);_0x3736a0[_0xdc03('0x4a')]=qs[_0xdc03('0x42')](_[_0xdc03('0x4b')](_0x3767e1['query'],_0x3da0ca['filters']));_0x3736a0['where'][_0xdc03('0x5e')]=_0x59c2d0['id'];if(_0x3767e1[_0xdc03('0x41')]['filter']){_0x3736a0[_0xdc03('0x4a')]=_[_0xdc03('0x4d')](_0x3736a0[_0xdc03('0x4a')],{'$or':_[_0xdc03('0x40')](_0x3736a0[_0xdc03('0x44')],function(_0x1f8581){var _0x52e1eb={};_0x52e1eb[_0x1f8581]={'$like':'%'+_0x3767e1[_0xdc03('0x41')][_0xdc03('0x4c')]+'%'};return _0x52e1eb;})});}_0x3736a0=_[_0xdc03('0x4d')]({},_0x3736a0,_0x3767e1[_0xdc03('0x4f')]);return db[_0xdc03('0x86')][_0xdc03('0x2b')]({'where':_0x3736a0[_0xdc03('0x4a')]})[_0xdc03('0x1e')](function(_0x44e3f9){_0x238ff3[_0xdc03('0x2b')]=_0x44e3f9;if(_0x3767e1['query'][_0xdc03('0x50')]){_0x3736a0[_0xdc03('0x51')]=[{'model':db['CmContact'],'as':_0xdc03('0x88'),'required':![]},{'model':db[_0xdc03('0x89')],'as':_0xdc03('0x8a'),'attributes':['name',_0xdc03('0x8b'),'internal'],'required':![]},{'model':db['Tag'],'as':_0xdc03('0x8c'),'attributes':['id',_0xdc03('0x34'),_0xdc03('0x8d')],'where':_0x3767e1[_0xdc03('0x41')][_0xdc03('0x8e')]?{'id':_0x3767e1[_0xdc03('0x41')][_0xdc03('0x8e')]}:undefined,'required':_0x3767e1[_0xdc03('0x41')]['tag']?!![]:![]}];}return db[_0xdc03('0x86')][_0xdc03('0x52')](_0x3736a0);})['then'](function(_0x136ed6){_0x238ff3[_0xdc03('0x53')]=_0x136ed6;return _0x238ff3;});}})[_0xdc03('0x1e')](respondWithFilteredResult(_0x295ca4,_0x3736a0))[_0xdc03('0x54')](handleError(_0x295ca4,null));};exports[_0xdc03('0x8f')]=function(_0x5964fb,_0x4722c2,_0x2e7707){return db[_0xdc03('0x3c')]['findOne']({'where':{'id':_0x5964fb[_0xdc03('0x56')]['id']}})[_0xdc03('0x1e')](handleEntityNotFound(_0x4722c2,null))[_0xdc03('0x1e')](function(_0x545d4b){if(_0x545d4b){return db['sequelize']['transaction'](function(_0x43c045){return db[_0xdc03('0x90')][_0xdc03('0x31')]({'where':{'MailAccountId':_0x5964fb['params']['id']},'transaction':_0x43c045})[_0xdc03('0x1e')](function(_0x2e1eb7){var _0x44ffdb=_[_0xdc03('0x40')](_0x5964fb[_0xdc03('0x5b')],function(_0x51ef27){_0x51ef27[_0xdc03('0x5e')]=_0x5964fb[_0xdc03('0x56')]['id'];return _0x51ef27;});return db[_0xdc03('0x90')]['bulkCreate'](_0x44ffdb,{'transaction':_0x43c045});});})[_0xdc03('0x1e')](function(){return db[_0xdc03('0x90')]['findAndCountAll']({'where':{'MailAccountId':_0x5964fb[_0xdc03('0x56')]['id']},'order':_0xdc03('0x91')});});}})[_0xdc03('0x1e')](respondWithResult(_0x4722c2,null))[_0xdc03('0x54')](handleError(_0x4722c2,null));};exports[_0xdc03('0x92')]=function(_0x18424b,_0x539e49,_0x49fdb0){var _0x6cc669={};var _0xc5a33d={};var _0x46d09d;var _0x34779b;return db[_0xdc03('0x3c')][_0xdc03('0x65')]({'where':{'id':_0x18424b['params']['id']}})[_0xdc03('0x1e')](handleEntityNotFound(_0x539e49,null))['then'](function(_0x34ad49){if(_0x34ad49){_0x46d09d=_0x34ad49;_0xc5a33d[_0xdc03('0x3f')]=_[_0xdc03('0x59')](db[_0xdc03('0x90')][_0xdc03('0x58')]);_0xc5a33d['query']=_[_0xdc03('0x59')](_0x18424b[_0xdc03('0x41')]);_0xc5a33d[_0xdc03('0x42')]=_[_0xdc03('0x43')](_0xc5a33d[_0xdc03('0x3f')],_0xc5a33d[_0xdc03('0x41')]);_0x6cc669['attributes']=_[_0xdc03('0x43')](_0xc5a33d[_0xdc03('0x3f')],qs['fields'](_0x18424b[_0xdc03('0x41')]['fields']));_0x6cc669['attributes']=_0x6cc669[_0xdc03('0x44')][_0xdc03('0x46')]?_0x6cc669['attributes']:_0xc5a33d[_0xdc03('0x3f')];_0x6cc669[_0xdc03('0x61')]=qs[_0xdc03('0x49')](_0x18424b[_0xdc03('0x41')][_0xdc03('0x49')]);_0x6cc669['where']=qs[_0xdc03('0x42')](_['pick'](_0x18424b[_0xdc03('0x41')],_0xc5a33d[_0xdc03('0x42')]));if(_0x18424b[_0xdc03('0x41')][_0xdc03('0x4c')]){_0x6cc669[_0xdc03('0x4a')]=_[_0xdc03('0x4d')](_0x6cc669['where'],{'$or':_[_0xdc03('0x40')](_0x6cc669[_0xdc03('0x44')],function(_0x11e400){var _0x259364={};_0x259364[_0x11e400]={'$like':'%'+_0x18424b['query']['filter']+'%'};return _0x259364;})});}_0x6cc669=_[_0xdc03('0x4d')]({},_0x6cc669,_0x18424b[_0xdc03('0x4f')]);return _0x46d09d[_0xdc03('0x92')](_0x6cc669);}})[_0xdc03('0x1e')](function(_0xab0d6d){if(_0xab0d6d){_0x34779b=_0xab0d6d['length'];if(!_0x18424b['query']['hasOwnProperty']('nolimit')){_0x6cc669[_0xdc03('0x48')]=qs[_0xdc03('0x48')](_0x18424b['query'][_0xdc03('0x48')]);_0x6cc669['offset']=qs[_0xdc03('0x2c')](_0x18424b['query'][_0xdc03('0x2c')]);}return _0x46d09d[_0xdc03('0x92')](_0x6cc669);}})['then'](function(_0x478c6e){if(_0x478c6e){return _0x478c6e?{'count':_0x34779b,'rows':_0x478c6e}:null;}})['then'](respondWithResult(_0x539e49,null))['catch'](handleError(_0x539e49,null));};exports[_0xdc03('0x93')]=function(_0x5bf7d5,_0x458da3,_0x1574e8){var _0x473c28={'raw':!![],'where':{}};var _0x1ffe7b={};var _0x56f0b8={'count':0x0,'rows':[]};return db['MailAccount'][_0xdc03('0x65')]({'where':{'id':_0x5bf7d5[_0xdc03('0x56')]['id']}})[_0xdc03('0x1e')](handleEntityNotFound(_0x458da3,null))['then'](function(_0x2d9c79){if(_0x2d9c79){_0x1ffe7b['model']=_[_0xdc03('0x59')](db['MailMessage'][_0xdc03('0x58')]);_0x1ffe7b[_0xdc03('0x41')]=_[_0xdc03('0x59')](_0x5bf7d5[_0xdc03('0x41')]);_0x1ffe7b[_0xdc03('0x42')]=_[_0xdc03('0x43')](_0x1ffe7b[_0xdc03('0x3f')],_0x1ffe7b[_0xdc03('0x41')]);_0x473c28[_0xdc03('0x44')]=_[_0xdc03('0x43')](_0x1ffe7b[_0xdc03('0x3f')],qs['fields'](_0x5bf7d5[_0xdc03('0x41')]['fields']));_0x473c28['attributes']=_0x473c28[_0xdc03('0x44')][_0xdc03('0x46')]?_0x473c28[_0xdc03('0x44')]:_0x1ffe7b['model'];if(!_0x5bf7d5['query'][_0xdc03('0x67')](_0xdc03('0x47'))){_0x473c28[_0xdc03('0x48')]=qs[_0xdc03('0x48')](_0x5bf7d5[_0xdc03('0x41')]['limit']);_0x473c28[_0xdc03('0x2c')]=qs[_0xdc03('0x2c')](_0x5bf7d5[_0xdc03('0x41')][_0xdc03('0x2c')]);}_0x473c28[_0xdc03('0x61')]=qs[_0xdc03('0x49')](_0x5bf7d5['query'][_0xdc03('0x49')]);_0x473c28[_0xdc03('0x4a')]=qs['filters'](_[_0xdc03('0x4b')](_0x5bf7d5[_0xdc03('0x41')],_0x1ffe7b[_0xdc03('0x42')]));_0x473c28[_0xdc03('0x4a')][_0xdc03('0x5e')]=_0x2d9c79['id'];if(_0x5bf7d5[_0xdc03('0x41')]['filter']){_0x473c28[_0xdc03('0x4a')]=_['merge'](_0x473c28[_0xdc03('0x4a')],{'$or':_[_0xdc03('0x40')](_0x473c28['attributes'],function(_0x32e259){var _0x12e3d6={};_0x12e3d6[_0x32e259]={'$like':'%'+_0x5bf7d5[_0xdc03('0x41')][_0xdc03('0x4c')]+'%'};return _0x12e3d6;})});}if(_0x5bf7d5[_0xdc03('0x41')][_0xdc03('0x94')]){var _0x99781d=_0x5bf7d5[_0xdc03('0x41')][_0xdc03('0x94')][_0xdc03('0x95')](',');var _0x3b0a3b={};_0x3b0a3b[_0x99781d[0x0]]={'$gte':moment(_0x99781d[0x1])['format'](_0xdc03('0x96'))};_0x473c28[_0xdc03('0x4a')]=_[_0xdc03('0x4d')](_0x473c28[_0xdc03('0x4a')],_0x3b0a3b);}_0x473c28=_[_0xdc03('0x4d')]({},_0x473c28,_0x5bf7d5['options']);return db[_0xdc03('0x97')]['count']({'where':_0x473c28['where']})[_0xdc03('0x1e')](function(_0x5374b4){_0x56f0b8[_0xdc03('0x2b')]=_0x5374b4;if(_0x5bf7d5[_0xdc03('0x41')]['includeAll']){_0x473c28[_0xdc03('0x51')]=[{'all':!![]}];}return db[_0xdc03('0x97')][_0xdc03('0x52')](_0x473c28);})[_0xdc03('0x1e')](function(_0x529757){_0x56f0b8[_0xdc03('0x53')]=_0x529757;return _0x56f0b8;});}})[_0xdc03('0x1e')](respondWithFilteredResult(_0x458da3,_0x473c28))[_0xdc03('0x54')](handleError(_0x458da3,null));};exports[_0xdc03('0x35')]=function(_0xe3cb4e,_0x396340,_0x3d77f1){var _0x5a8f86,_0xc4f6b3={},_0x1a2164;if(_0xe3cb4e[_0xdc03('0x5b')]['to']){_0x1a2164=_0xe3cb4e[_0xdc03('0x5b')]['to']['split'](',')[0x0];}return db[_0xdc03('0x3c')][_0xdc03('0x5a')]({'where':{'id':_0xe3cb4e[_0xdc03('0x56')]['id']},'include':[{'model':db['CmList'],'as':'List','include':[{'model':db[_0xdc03('0x98')],'as':_0xdc03('0x99'),'where':{'email':_0x1a2164},'limit':0x1,'order':[[_0xdc03('0x9a'),_0xdc03('0x9b')]]}]},{'model':db[_0xdc03('0x39')],'as':_0xdc03('0x3a'),'raw':!![]}]})[_0xdc03('0x1e')](handleEntityNotFound(_0x396340,null))['then'](function(_0x2d1fc7){if(_0x2d1fc7){_0x5a8f86=_0x2d1fc7;if(_0x2d1fc7[_0xdc03('0x3a')]){if(_[_0xdc03('0x6c')](_0xe3cb4e['body']['from'])){_0xe3cb4e['body'][_0xdc03('0x9c')]=util['format'](_0xdc03('0x9d'),_0x2d1fc7[_0xdc03('0x34')],_0x2d1fc7[_0xdc03('0x69')]||_0x2d1fc7['Smtp'][_0xdc03('0x6f')]);}if(_0xe3cb4e[_0xdc03('0x5b')][_0xdc03('0x9e')]&&_0xe3cb4e[_0xdc03('0x5b')][_0xdc03('0x9e')]['length']){for(var _0x462a76=0x0;_0x462a76<_0xe3cb4e[_0xdc03('0x5b')]['attachments']['length'];_0x462a76+=0x1){_0xe3cb4e['body'][_0xdc03('0x9e')][_0x462a76]={'filename':_0xe3cb4e[_0xdc03('0x5b')][_0xdc03('0x9e')][_0x462a76]['name'],'path':path['join'](config['root'],_0xdc03('0x9f'),_0xe3cb4e[_0xdc03('0x5b')][_0xdc03('0x9e')][_0x462a76][_0xdc03('0xa0')])};}}var _0x36759d={'tls':{'rejectUnauthorized':![]}};if(_['isNil'](_0x2d1fc7[_0xdc03('0x3a')]['service'])){if(_0x2d1fc7[_0xdc03('0x3a')]['authentication']){_0x36759d[_0xdc03('0xa1')]={'user':_0x2d1fc7[_0xdc03('0x3a')]['user'],'pass':_0x2d1fc7['Smtp'][_0xdc03('0x72')]};}_0x36759d[_0xdc03('0x74')]=_0x2d1fc7[_0xdc03('0x3a')][_0xdc03('0x74')];_0x36759d[_0xdc03('0x75')]=_0x2d1fc7[_0xdc03('0x3a')]['port'];_0x36759d[_0xdc03('0xa2')]=_0x2d1fc7[_0xdc03('0x3a')][_0xdc03('0xa2')];}else{_0x36759d[_0xdc03('0x76')]=_0x2d1fc7[_0xdc03('0x3a')][_0xdc03('0x76')];_0x36759d['auth']={'user':_0x2d1fc7[_0xdc03('0x3a')][_0xdc03('0x6f')],'pass':_0x2d1fc7[_0xdc03('0x3a')][_0xdc03('0x72')]};}return respondWithRpcPromise('SendMail','sendMail',{'account':_0x36759d,'message':_0xe3cb4e['body']});}else{throw new Error(_0xdc03('0xa3'));}}})[_0xdc03('0x1e')](function(_0x55a316){if(_0x55a316){_0xc4f6b3=_0x55a316;if(_0x5a8f86[_0xdc03('0xa4')]){if(_0x5a8f86[_0xdc03('0xa4')]['Contacts'][_0xdc03('0x46')]){return _0x5a8f86['List'][_0xdc03('0x99')][0x0];}else{return db[_0xdc03('0x98')][_0xdc03('0x5f')](_[_0xdc03('0xa5')](_0xe3cb4e[_0xdc03('0x5b')],{'firstName':_0xe3cb4e[_0xdc03('0x5b')]['to'],'email':_0xe3cb4e['body']['to'],'phone':_0xe3cb4e[_0xdc03('0x5b')]['to'],'ListId':_0x5a8f86['ListId']}));}}else{throw new Error(_0xdc03('0xa3'));}}})[_0xdc03('0x1e')](function(_0x430443){if(_0x430443){var _0x3fe728={'UserId':_0xe3cb4e[_0xdc03('0x6f')]['id'],'ContactId':_0x430443['id'],'MailAccountId':_0x5a8f86['id'],'inReplyTo':_0xc4f6b3['messageId'],'to':_0xe3cb4e[_0xdc03('0x5b')][_0xdc03('0x9c')],'cc':_0xe3cb4e[_0xdc03('0x5b')]['cc'],'subject':_0xe3cb4e[_0xdc03('0x5b')][_0xdc03('0xa6')],'attach':_0xe3cb4e[_0xdc03('0x5b')][_0xdc03('0xa7')],'firstMsgDirection':_0xdc03('0xa8'),'lastMsgAt':moment()['format']('YYYY-MM-DD\x20HH:mm:ss'),'lastMsgDirection':_0xdc03('0xa8'),'lastMsgBody':_0xe3cb4e[_0xdc03('0x5b')][_0xdc03('0x5b')],'Messages':[_[_0xdc03('0x4d')](_0xe3cb4e[_0xdc03('0x5b')],{'messageId':_0xc4f6b3['messageId'],'sentAt':moment()['format'](_0xdc03('0x96')),'read':!![],'MailAccountId':_0x5a8f86['id'],'UserId':_0xe3cb4e[_0xdc03('0x6f')]['id'],'ContactId':_0x430443['id']})]};if(_0xe3cb4e['body']['Interaction']){_0x3fe728=_['merge'](_0x3fe728,_0xe3cb4e['body'][_0xdc03('0xa9')]);}return db[_0xdc03('0x86')][_0xdc03('0x5f')](_0x3fe728,{'include':[{'model':db[_0xdc03('0x97')],'as':'Messages'}]});}})['then'](respondWithResult(_0x396340,null))[_0xdc03('0x54')](handleError(_0x396340,null));};exports[_0xdc03('0xaa')]=function(_0x148b83,_0x317c7d,_0x3adca7){return db[_0xdc03('0x3c')][_0xdc03('0x5a')]({'where':{'id':_0x148b83['params']['id']},'include':[{'model':db['MailServerOut'],'as':'Smtp','raw':!![]}]})[_0xdc03('0x1e')](handleEntityNotFound(_0x317c7d,null))[_0xdc03('0x1e')](function(_0x48e890){if(_0x48e890&&_0x48e890[_0xdc03('0x3a')]){var _0x3c72ee={'id':_0x48e890['id'],'tls':{'rejectUnauthorized':![]}};if(_0x48e890[_0xdc03('0x3a')][_0xdc03('0x76')]){_0x3c72ee[_0xdc03('0x76')]=_0x48e890[_0xdc03('0x3a')][_0xdc03('0x76')];}else{_0x3c72ee[_0xdc03('0x74')]=_0x48e890[_0xdc03('0x3a')][_0xdc03('0x74')];_0x3c72ee[_0xdc03('0x75')]=_0x48e890[_0xdc03('0x3a')][_0xdc03('0x75')];_0x3c72ee[_0xdc03('0xa2')]=_0x48e890['Smtp']['secure'];}if(_0x48e890[_0xdc03('0x3a')][_0xdc03('0x73')]){_0x3c72ee[_0xdc03('0xa1')]={'user':_0x48e890[_0xdc03('0x3a')]['user'],'pass':_0x48e890[_0xdc03('0x3a')][_0xdc03('0x72')]};}return respondWithRpcPromise(_0xdc03('0xab'),_0xdc03('0xaa'),{'account':_0x3c72ee});}})[_0xdc03('0x1e')](respondWithResult(_0x317c7d,null))[_0xdc03('0x54')](handleError(_0x317c7d,null));};exports[_0xdc03('0x31')]=function(_0x18b586,_0x1d3aec){return db['MailAccount']['find']({'where':{'id':_0x18b586[_0xdc03('0x56')]['id']}})[_0xdc03('0x1e')](handleEntityNotFound(_0x1d3aec,null))['then'](function(_0xf8e931){if(_0xf8e931&&_0xf8e931[_0xdc03('0x76')]){throw new db[(_0xdc03('0x1b'))][(_0xdc03('0xac'))](_0xdc03('0xad'));}return _0xf8e931;})[_0xdc03('0x1e')](removeEntity(_0x1d3aec,null))[_0xdc03('0x54')](handleError(_0x1d3aec,null));};exports[_0xdc03('0xae')]=function(_0x481c7a,_0x57c2ea,_0x4ae3db){return db[_0xdc03('0x3c')]['find']({'where':{'id':_0x481c7a[_0xdc03('0x56')]['id']}})[_0xdc03('0x1e')](handleEntityNotFound(_0x57c2ea,null))['then'](function(_0x12c94c){if(_0x12c94c){return _0x12c94c[_0xdc03('0xae')](_0x481c7a[_0xdc03('0x5b')][_0xdc03('0x63')],_['omit'](_0x481c7a['body'],[_0xdc03('0x63'),'id'])||{})[_0xdc03('0xaf')](function(_0x1f7df9){for(var _0x10f41d=0x0;_0x10f41d<_0x481c7a[_0xdc03('0x5b')][_0xdc03('0x63')][_0xdc03('0x46')];_0x10f41d+=0x1){socket[_0xdc03('0xb0')]('userMailAccount:save',{'UserId':_0x481c7a['body'][_0xdc03('0x63')][_0x10f41d],'MailAccountId':_0x481c7a[_0xdc03('0x56')]['id']});}return _0x1f7df9;});}})[_0xdc03('0x1e')](respondWithResult(_0x57c2ea,null))[_0xdc03('0x54')](handleError(_0x57c2ea,null));};exports['removeAgents']=function(_0x4de61e,_0x343a00,_0x33bafb){return db[_0xdc03('0x3c')]['find']({'where':{'id':_0x4de61e[_0xdc03('0x56')]['id']}})[_0xdc03('0x1e')](handleEntityNotFound(_0x343a00,null))[_0xdc03('0x1e')](function(_0x394ccd){if(_0x394ccd){return _0x394ccd[_0xdc03('0xb1')](_0x4de61e[_0xdc03('0x41')][_0xdc03('0x63')])['then'](function(){if(_[_0xdc03('0xb2')](_0x4de61e['query'][_0xdc03('0x63')])){for(var _0x4f636e=0x0;_0x4f636e<_0x4de61e[_0xdc03('0x41')]['ids'][_0xdc03('0x46')];_0x4f636e+=0x1){socket[_0xdc03('0xb0')](_0xdc03('0xb3'),{'UserId':Number(_0x4de61e[_0xdc03('0x41')][_0xdc03('0x63')][_0x4f636e]),'MailAccountId':Number(_0x4de61e[_0xdc03('0x56')]['id'])});}}else{socket[_0xdc03('0xb0')]('userMailAccount:remove',{'UserId':Number(_0x4de61e[_0xdc03('0x41')][_0xdc03('0x63')]),'MailAccountId':Number(_0x4de61e['params']['id'])});}});}})[_0xdc03('0x1e')](respondWithStatusCode(_0x343a00,null))[_0xdc03('0x54')](handleError(_0x343a00,null));};exports['getAgents']=function(_0x3610ab,_0xe21373,_0x5cd161){var _0x3a2cca={};var _0x515112={};var _0x5aa30c;var _0x392df2;return db['MailAccount'][_0xdc03('0x65')]({'where':{'id':_0x3610ab['params']['id']}})[_0xdc03('0x1e')](handleEntityNotFound(_0xe21373,null))[_0xdc03('0x1e')](function(_0x582582){if(_0x582582){_0x5aa30c=_0x582582;_0x515112[_0xdc03('0x3f')]=_['keys'](db[_0xdc03('0x89')][_0xdc03('0x58')]);_0x515112['query']=_[_0xdc03('0x59')](_0x3610ab[_0xdc03('0x41')]);_0x515112[_0xdc03('0x42')]=_[_0xdc03('0x43')](_0x515112[_0xdc03('0x3f')],_0x515112[_0xdc03('0x41')]);_0x3a2cca[_0xdc03('0x44')]=_[_0xdc03('0x43')](_0x515112[_0xdc03('0x3f')],qs[_0xdc03('0x45')](_0x3610ab['query'][_0xdc03('0x45')]));_0x3a2cca[_0xdc03('0x44')]=_0x3a2cca[_0xdc03('0x44')]['length']?_0x3a2cca[_0xdc03('0x44')]:_0x515112[_0xdc03('0x3f')];_0x3a2cca[_0xdc03('0x61')]=qs[_0xdc03('0x49')](_0x3610ab[_0xdc03('0x41')][_0xdc03('0x49')]);_0x3a2cca[_0xdc03('0x4a')]=qs[_0xdc03('0x42')](_[_0xdc03('0x4b')](_0x3610ab[_0xdc03('0x41')],_0x515112[_0xdc03('0x42')]));if(_0x3610ab[_0xdc03('0x41')][_0xdc03('0x4c')]){_0x3a2cca[_0xdc03('0x4a')]=_['merge'](_0x3a2cca['where'],{'$or':_['map'](_0x3a2cca[_0xdc03('0x44')],function(_0xbc3b00){var _0x1eb6d5={};_0x1eb6d5[_0xbc3b00]={'$like':'%'+_0x3610ab[_0xdc03('0x41')][_0xdc03('0x4c')]+'%'};return _0x1eb6d5;})});}_0x3a2cca=_[_0xdc03('0x4d')]({},_0x3a2cca,_0x3610ab[_0xdc03('0x4f')]);return _0x5aa30c[_0xdc03('0xb4')](_0x3a2cca);}})[_0xdc03('0x1e')](function(_0x435b4f){if(_0x435b4f){_0x392df2=_0x435b4f['length'];if(!_0x3610ab[_0xdc03('0x41')][_0xdc03('0x67')](_0xdc03('0x47'))){_0x3a2cca['limit']=qs[_0xdc03('0x48')](_0x3610ab[_0xdc03('0x41')]['limit']);_0x3a2cca['offset']=qs[_0xdc03('0x2c')](_0x3610ab[_0xdc03('0x41')][_0xdc03('0x2c')]);}return _0x5aa30c[_0xdc03('0xb4')](_0x3a2cca);}})['then'](function(_0x3fdd41){if(_0x3fdd41){return _0x3fdd41?{'count':_0x392df2,'rows':_0x3fdd41}:null;}})[_0xdc03('0x1e')](respondWithResult(_0xe21373,null))['catch'](handleError(_0xe21373,null));};