Built motion from commit (unavailable).|2.4.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 _0x5bc6=['Imap','MailServerOut','Smtp','Pause','mandatoryDispositionPause','MailAccount','rawAttributes','model','keys','query','filters','intersection','attributes','fields','nolimit','order','sort','where','filter','merge','map','type','key','VIRTUAL','field','options','includeAll','findAll','rows','catch','show','include','body','describe','Disposition','create','findOne','params','length','pick','removeDispositions','find','ids','MailAccountId','CannedAnswer','getAnswers','removeAnswers','email','ListId','isNil','cservice','cauthentication','cuser','password','pass','authentication','host','port','service','user','cpassword','get','role','userProfileId','autoAssociation','UserProfileResource','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','getImap','removeImap','setImap','getSmtp','addSmtp','removeSmtp','addInteraction','MailInteraction','omit','getInteractions','hasOwnProperty','CmContact','Contact','User','fullname','internal','Tag','Tags','color','tag','sequelize','transaction','MailApplication','findAndCountAll','getApplications','getMessages','MailMessage','$gte','split','format','YYYY-MM-DD\x20HH:mm:ss','CmList','Contacts','updatedAt','DESC','from','%s\x20<%s>','attachments','join','root','server/files/attachments','basename','auth','secure','SendMail','sendMail','List\x20not\x20found','List','messageId','subject','attach','out','Interaction','Messages','verifySmtp','VerifySmtp','Sequelize','ValidationError','addAgents','spread','emit','userMailAccount:save','removeAgents','userMailAccount:remove','getAgents','html-pdf','eml-format','rimraf','bluebird','mustache','util','sox','to-csv','ejs','lodash','squel','crypto','jsforce','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/logger','api','../../mysqldb','defaults','localhost','socket.io-emitter','redis','./mailAccount.socket','register','jayson/promise','client','request','MailAccount,\x20%s,\x20%s','request\x20sent','stringify','code','error','message','result','sendStatus','status','end','json','count','offset','limit','Content-Range','reject','save','update','then','destroy','MailAccounts','stack','name','send','index','MailServerIn'];(function(_0x9d53fb,_0x4b898b){var _0x12f955=function(_0x5b03f9){while(--_0x5b03f9){_0x9d53fb['push'](_0x9d53fb['shift']());}};_0x12f955(++_0x4b898b);}(_0x5bc6,0x84));var _0x65bc=function(_0x3fd84b,_0x51d98a){_0x3fd84b=_0x3fd84b-0x0;var _0x254bde=_0x5bc6[_0x3fd84b];return _0x254bde;};'use strict';var pdf=require(_0x65bc('0x0'));var emlformat=require(_0x65bc('0x1'));var rimraf=require(_0x65bc('0x2'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0x65bc('0x3'));var Mustache=require(_0x65bc('0x4'));var util=require(_0x65bc('0x5'));var path=require('path');var sox=require(_0x65bc('0x6'));var csv=require(_0x65bc('0x7'));var ejs=require(_0x65bc('0x8'));var fs=require('fs');var _=require(_0x65bc('0x9'));var squel=require(_0x65bc('0xa'));var crypto=require(_0x65bc('0xb'));var jsforce=require(_0x65bc('0xc'));var deskjs=require('desk.js');var toCsv=require(_0x65bc('0x7'));var querystring=require(_0x65bc('0xd'));var Papa=require('papaparse');var Redis=require(_0x65bc('0xe'));var authService=require(_0x65bc('0xf'));var qs=require(_0x65bc('0x10'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x65bc('0x11'))(_0x65bc('0x12'));var utils=require('../../config/utils');var config=require('../../config/environment');var db=require(_0x65bc('0x13'))['db'];config['redis']=_[_0x65bc('0x14')](config['redis'],{'host':_0x65bc('0x15'),'port':0x18eb});var socket=require(_0x65bc('0x16'))(new Redis(config[_0x65bc('0x17')]));require(_0x65bc('0x18'))[_0x65bc('0x19')](socket);var jayson=require(_0x65bc('0x1a'));var client=jayson[_0x65bc('0x1b')]['http']({'port':0x232b});function checkPasswordPattern(_0xe37539,_0x3f50da,_0x263558){if(_0x263558){var _0x377048=new RegExp(/(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[?!@#\$%\^&\*~\-_=+[{\]\}])(?=.{8,})/);if(_0x377048['test'](_0x3f50da)){return _0xe37539;}else{throw new Error('The\x20password\x20must\x20be\x20at\x20least\x208\x20characters\x20long\x20and\x20have\x201\x20lowercase\x20character,\x201\x20uppercase\x20character,\x201\x20number\x20and\x201\x20special\x20character\x20~!@#$%^&-_=+[{]}.');}}else{return _0xe37539;}}function respondWithRpcPromise(_0x5c020a,_0x140c1a,_0x12232c,_0x14e685){return new BPromise(function(_0xe94373,_0x3d048f){var _0x5e31cd=_0x14e685||client;return _0x5e31cd[_0x65bc('0x1c')](_0x5c020a,_0x12232c)['then'](function(_0x54b107){logger['info'](_0x65bc('0x1d'),_0x140c1a,_0x65bc('0x1e'));logger['debug']('MailAccount,\x20%s,\x20%s,\x20%s',_0x140c1a,_0x65bc('0x1e'),JSON[_0x65bc('0x1f')](_0x54b107));if(_0x54b107['error']){if(_0x54b107['error'][_0x65bc('0x20')]===0x1f4){logger[_0x65bc('0x21')](_0x65bc('0x1d'),_0x140c1a,_0x54b107[_0x65bc('0x21')][_0x65bc('0x22')]);return _0x3d048f(_0x54b107[_0x65bc('0x21')][_0x65bc('0x22')]);}logger[_0x65bc('0x21')]('MailAccount,\x20%s,\x20%s',_0x140c1a,_0x54b107['error'][_0x65bc('0x22')]);return _0xe94373(_0x54b107[_0x65bc('0x21')]['message']);}else{logger['info'](_0x65bc('0x1d'),_0x140c1a,'request\x20sent');_0xe94373(_0x54b107[_0x65bc('0x23')][_0x65bc('0x22')]);}})['catch'](function(_0x29c595){logger[_0x65bc('0x21')](_0x65bc('0x1d'),_0x140c1a,_0x29c595);_0x3d048f(_0x29c595);});});}function respondWithStatusCode(_0x150116,_0x1b0a3c){_0x1b0a3c=_0x1b0a3c||0xcc;return function(_0x101396){if(_0x101396){return _0x150116[_0x65bc('0x24')](_0x1b0a3c);}return _0x150116[_0x65bc('0x25')](_0x1b0a3c)[_0x65bc('0x26')]();};}function respondWithResult(_0x266c7d,_0x4bc9d0){_0x4bc9d0=_0x4bc9d0||0xc8;return function(_0x439142){if(_0x439142){return _0x266c7d[_0x65bc('0x25')](_0x4bc9d0)[_0x65bc('0x27')](_0x439142);}};}function respondWithFilteredResult(_0xc1c427,_0x5551ea){return function(_0x399c37){if(_0x399c37){var _0x2d20ea=_0x399c37[_0x65bc('0x28')],_0x569629=_0x5551ea['offset'],_0x2a3d11=_0x5551ea[_0x65bc('0x29')]+_0x5551ea[_0x65bc('0x2a')],_0x3c6e79;if(_0x2a3d11>=_0x2d20ea){_0x2a3d11=_0x2d20ea;_0x3c6e79=0xc8;}else{_0x3c6e79=0xce;}_0xc1c427[_0x65bc('0x25')](_0x3c6e79);return _0xc1c427['set'](_0x65bc('0x2b'),_0x569629+'-'+_0x2a3d11+'/'+_0x2d20ea)[_0x65bc('0x27')](_0x399c37);}return null;};}function patchUpdates(_0x2f1d0f){return function(_0x3aabf0){try{jsonpatch['apply'](_0x3aabf0,_0x2f1d0f,!![]);}catch(_0x141d5f){return BPromise[_0x65bc('0x2c')](_0x141d5f);}return _0x3aabf0[_0x65bc('0x2d')]();};}function saveUpdates(_0x447f53,_0x444a0d){return function(_0x1c835f){if(_0x1c835f){return _0x1c835f[_0x65bc('0x2e')](_0x447f53)[_0x65bc('0x2f')](function(_0x35ce12){return _0x35ce12;});}return null;};}function removeEntity(_0x1b6e19,_0x4fe96d){return function(_0x3f281d){if(_0x3f281d){return _0x3f281d[_0x65bc('0x30')]()[_0x65bc('0x2f')](function(){var _0x1547cc=_0x3f281d['get']({'plain':!![]});var _0x1c5536=_0x65bc('0x31');return db['UserProfileResource']['destroy']({'where':{'type':_0x1c5536,'resourceId':_0x1547cc['id']}})[_0x65bc('0x2f')](function(){return _0x3f281d;});})[_0x65bc('0x2f')](function(){_0x1b6e19['status'](0xcc)[_0x65bc('0x26')]();});}};}function handleEntityNotFound(_0x2d98ff,_0xc60294){return function(_0x5e1d28){if(!_0x5e1d28){_0x2d98ff[_0x65bc('0x24')](0x194);}return _0x5e1d28;};}function handleError(_0x377561,_0x18a57f){_0x18a57f=_0x18a57f||0x1f4;return function(_0x1bcaec){logger['error'](_0x1bcaec[_0x65bc('0x32')]);if(_0x1bcaec[_0x65bc('0x33')]){delete _0x1bcaec['name'];}_0x377561[_0x65bc('0x25')](_0x18a57f)[_0x65bc('0x34')](_0x1bcaec);};}exports[_0x65bc('0x35')]=function(_0x326404,_0x557984){var _0x4e0657={'include':[{'model':db[_0x65bc('0x36')],'as':_0x65bc('0x37')},{'model':db[_0x65bc('0x38')],'as':_0x65bc('0x39')},{'model':db[_0x65bc('0x3a')],'as':_0x65bc('0x3b')}]},_0x261120={},_0xafb364={'count':0x0,'rows':[]};var _0x6a8a1d=db[_0x65bc('0x3c')][_0x65bc('0x3d')];_0x261120[_0x65bc('0x3e')]=_[_0x65bc('0x3f')](_0x6a8a1d);_0x261120[_0x65bc('0x40')]=_[_0x65bc('0x3f')](_0x326404[_0x65bc('0x40')]);_0x261120[_0x65bc('0x41')]=_[_0x65bc('0x42')](_0x261120[_0x65bc('0x3e')],_0x261120[_0x65bc('0x40')]);_0x4e0657[_0x65bc('0x43')]=_['intersection'](_0x261120[_0x65bc('0x3e')],qs['fields'](_0x326404['query'][_0x65bc('0x44')]));_0x4e0657[_0x65bc('0x43')]=_0x4e0657[_0x65bc('0x43')]['length']?_0x4e0657[_0x65bc('0x43')]:_0x261120['model'];if(!_0x326404[_0x65bc('0x40')]['hasOwnProperty'](_0x65bc('0x45'))){_0x4e0657[_0x65bc('0x2a')]=qs[_0x65bc('0x2a')](_0x326404[_0x65bc('0x40')][_0x65bc('0x2a')]);_0x4e0657[_0x65bc('0x29')]=qs[_0x65bc('0x29')](_0x326404[_0x65bc('0x40')][_0x65bc('0x29')]);}_0x4e0657[_0x65bc('0x46')]=qs[_0x65bc('0x47')](_0x326404[_0x65bc('0x40')][_0x65bc('0x47')]);_0x4e0657[_0x65bc('0x48')]=qs['filters'](_['pick'](_0x326404[_0x65bc('0x40')],_0x261120[_0x65bc('0x41')]));if(_0x326404[_0x65bc('0x40')][_0x65bc('0x49')]){_0x4e0657['where']=_[_0x65bc('0x4a')](_0x4e0657[_0x65bc('0x48')],{'$or':_[_0x65bc('0x4b')](_0x6a8a1d,function(_0x1800eb){if(_0x1800eb[_0x65bc('0x4c')][_0x65bc('0x4d')]!==_0x65bc('0x4e')){var _0x2b42b6={};_0x2b42b6[_0x1800eb[_0x65bc('0x4f')]]={'$like':'%'+_0x326404[_0x65bc('0x40')][_0x65bc('0x49')]+'%'};return _0x2b42b6;}})});}_0x4e0657=_[_0x65bc('0x4a')]({},_0x4e0657,_0x326404[_0x65bc('0x50')]);var _0x5eb244={'where':_0x4e0657[_0x65bc('0x48')]};return db[_0x65bc('0x3c')]['count'](_0x5eb244)[_0x65bc('0x2f')](function(_0x3f18a1){_0xafb364[_0x65bc('0x28')]=_0x3f18a1;if(_0x326404['query'][_0x65bc('0x51')]){_0x4e0657['include']=[{'all':!![]}];}return db[_0x65bc('0x3c')][_0x65bc('0x52')](_0x4e0657);})[_0x65bc('0x2f')](function(_0x2dd565){_0xafb364[_0x65bc('0x53')]=_0x2dd565;return _0xafb364;})[_0x65bc('0x2f')](respondWithFilteredResult(_0x557984,_0x4e0657))[_0x65bc('0x54')](handleError(_0x557984,null));};exports[_0x65bc('0x55')]=function(_0x2bf4d5,_0x3fdf89){var _0x21c74c={'raw':![],'where':{'id':_0x2bf4d5['params']['id']},'include':[{'model':db[_0x65bc('0x36')],'as':_0x65bc('0x37')},{'model':db[_0x65bc('0x38')],'as':'Smtp'},{'model':db[_0x65bc('0x3a')],'as':_0x65bc('0x3b')}]},_0x13fafc={};_0x13fafc[_0x65bc('0x3e')]=_['keys'](db[_0x65bc('0x3c')][_0x65bc('0x3d')]);_0x13fafc[_0x65bc('0x40')]=_[_0x65bc('0x3f')](_0x2bf4d5['query']);_0x13fafc[_0x65bc('0x41')]=_['intersection'](_0x13fafc[_0x65bc('0x3e')],_0x13fafc[_0x65bc('0x40')]);_0x21c74c[_0x65bc('0x43')]=_[_0x65bc('0x42')](_0x13fafc[_0x65bc('0x3e')],qs[_0x65bc('0x44')](_0x2bf4d5['query'][_0x65bc('0x44')]));_0x21c74c['attributes']=_0x21c74c[_0x65bc('0x43')]['length']?_0x21c74c[_0x65bc('0x43')]:_0x13fafc[_0x65bc('0x3e')];if(_0x2bf4d5[_0x65bc('0x40')][_0x65bc('0x51')]){_0x21c74c[_0x65bc('0x56')]=[{'all':!![]}];}_0x21c74c=_[_0x65bc('0x4a')]({},_0x21c74c,_0x2bf4d5[_0x65bc('0x50')]);return db['MailAccount']['find'](_0x21c74c)['then'](handleEntityNotFound(_0x3fdf89,null))[_0x65bc('0x2f')](respondWithResult(_0x3fdf89,null))['catch'](handleError(_0x3fdf89,null));};exports[_0x65bc('0x2e')]=function(_0x2f7634,_0x21238f){if(_0x2f7634[_0x65bc('0x57')]['id']){delete _0x2f7634[_0x65bc('0x57')]['id'];}return db[_0x65bc('0x3c')]['find']({'where':{'id':_0x2f7634['params']['id']},'include':[{'model':db[_0x65bc('0x36')],'as':_0x65bc('0x37')},{'model':db[_0x65bc('0x38')],'as':'Smtp'},{'model':db[_0x65bc('0x3a')],'as':_0x65bc('0x3b')}]})[_0x65bc('0x2f')](handleEntityNotFound(_0x21238f,null))[_0x65bc('0x2f')](saveUpdates(_0x2f7634['body'],null))['then'](function(_0x515db6){if(_0x515db6&&_0x2f7634[_0x65bc('0x57')][_0x65bc('0x37')]){return db[_0x65bc('0x36')][_0x65bc('0x2e')](_0x2f7634[_0x65bc('0x57')][_0x65bc('0x37')],{'where':{'MailAccountId':_0x515db6['id']}})['then'](function(){return _0x515db6;});}return _0x515db6;})[_0x65bc('0x2f')](function(_0x36ceda){if(_0x36ceda&&_0x2f7634['body'][_0x65bc('0x39')]){return db[_0x65bc('0x38')][_0x65bc('0x2e')](_0x2f7634[_0x65bc('0x57')]['Smtp'],{'where':{'MailAccountId':_0x36ceda['id']}})[_0x65bc('0x2f')](function(){return _0x36ceda;});}return _0x36ceda;})['then'](respondWithResult(_0x21238f,null))[_0x65bc('0x54')](handleError(_0x21238f,null));};exports[_0x65bc('0x58')]=function(_0x583d39,_0x42089f){return db['MailAccount'][_0x65bc('0x58')]()['then'](respondWithResult(_0x42089f,null))['catch'](handleError(_0x42089f,null));};exports['addDisposition']=function(_0x3223cd,_0x19c296,_0x5db38e){if(_0x3223cd[_0x65bc('0x57')]['id']){delete _0x3223cd['body']['id'];}return db['MailAccount']['find']({'where':{'id':_0x3223cd['params']['id']}})[_0x65bc('0x2f')](handleEntityNotFound(_0x19c296,null))[_0x65bc('0x2f')](function(_0x3e46a3){if(_0x3e46a3){_0x3223cd['body']['MailAccountId']=_0x3e46a3['id'];return db[_0x65bc('0x59')][_0x65bc('0x5a')](_0x3223cd[_0x65bc('0x57')]);}})[_0x65bc('0x2f')](respondWithResult(_0x19c296,null))['catch'](handleError(_0x19c296,null));};exports['getDispositions']=function(_0x1d8e05,_0x41cd70,_0x3190a){var _0x47093={'raw':![],'where':{}};var _0x19da96={};var _0xd8094d={'count':0x0,'rows':[]};return db[_0x65bc('0x3c')][_0x65bc('0x5b')]({'where':{'id':_0x1d8e05[_0x65bc('0x5c')]['id']}})[_0x65bc('0x2f')](handleEntityNotFound(_0x41cd70,null))[_0x65bc('0x2f')](function(_0x476da6){if(_0x476da6){_0x19da96[_0x65bc('0x3e')]=_[_0x65bc('0x3f')](db[_0x65bc('0x59')][_0x65bc('0x3d')]);_0x19da96[_0x65bc('0x40')]=_[_0x65bc('0x3f')](_0x1d8e05[_0x65bc('0x40')]);_0x19da96['filters']=_[_0x65bc('0x42')](_0x19da96[_0x65bc('0x3e')],_0x19da96['query']);_0x47093['attributes']=_['intersection'](_0x19da96[_0x65bc('0x3e')],qs[_0x65bc('0x44')](_0x1d8e05['query'][_0x65bc('0x44')]));_0x47093['attributes']=_0x47093[_0x65bc('0x43')][_0x65bc('0x5d')]?_0x47093['attributes']:_0x19da96[_0x65bc('0x3e')];if(!_0x1d8e05[_0x65bc('0x40')]['hasOwnProperty'](_0x65bc('0x45'))){_0x47093[_0x65bc('0x2a')]=qs[_0x65bc('0x2a')](_0x1d8e05[_0x65bc('0x40')][_0x65bc('0x2a')]);_0x47093[_0x65bc('0x29')]=qs['offset'](_0x1d8e05[_0x65bc('0x40')][_0x65bc('0x29')]);}_0x47093[_0x65bc('0x46')]=qs[_0x65bc('0x47')](_0x1d8e05['query']['sort']);_0x47093['where']=qs['filters'](_[_0x65bc('0x5e')](_0x1d8e05[_0x65bc('0x40')],_0x19da96[_0x65bc('0x41')]));_0x47093[_0x65bc('0x48')]['MailAccountId']=_0x476da6['id'];if(_0x1d8e05[_0x65bc('0x40')][_0x65bc('0x49')]){_0x47093[_0x65bc('0x48')]=_['merge'](_0x47093[_0x65bc('0x48')],{'$or':_['map'](_0x47093['attributes'],function(_0x2b5fca){var _0x4f1444={};_0x4f1444[_0x2b5fca]={'$like':'%'+_0x1d8e05['query'][_0x65bc('0x49')]+'%'};return _0x4f1444;})});}_0x47093=_[_0x65bc('0x4a')]({},_0x47093,_0x1d8e05[_0x65bc('0x50')]);return db[_0x65bc('0x59')]['count']({'where':_0x47093[_0x65bc('0x48')]})[_0x65bc('0x2f')](function(_0x32d1e6){_0xd8094d[_0x65bc('0x28')]=_0x32d1e6;if(_0x1d8e05[_0x65bc('0x40')][_0x65bc('0x51')]){_0x47093[_0x65bc('0x56')]=[{'all':!![]}];}return db[_0x65bc('0x59')][_0x65bc('0x52')](_0x47093);})['then'](function(_0x115a98){_0xd8094d[_0x65bc('0x53')]=_0x115a98;return _0xd8094d;});}})[_0x65bc('0x2f')](respondWithFilteredResult(_0x41cd70,_0x47093))[_0x65bc('0x54')](handleError(_0x41cd70,null));};exports[_0x65bc('0x5f')]=function(_0x5b39a6,_0xe8df3c,_0x5303fb){return db[_0x65bc('0x3c')][_0x65bc('0x60')]({'where':{'id':_0x5b39a6[_0x65bc('0x5c')]['id']}})[_0x65bc('0x2f')](handleEntityNotFound(_0xe8df3c,null))[_0x65bc('0x2f')](function(_0x6e429a){if(_0x6e429a){return _0x6e429a[_0x65bc('0x5f')](_0x5b39a6[_0x65bc('0x40')][_0x65bc('0x61')]);}})['then'](respondWithStatusCode(_0xe8df3c,null))[_0x65bc('0x54')](handleError(_0xe8df3c,null));};exports['addAnswer']=function(_0x17989b,_0x3d0e0d,_0x38da30){if(_0x17989b[_0x65bc('0x57')]['id']){delete _0x17989b[_0x65bc('0x57')]['id'];}return db[_0x65bc('0x3c')]['find']({'where':{'id':_0x17989b[_0x65bc('0x5c')]['id']}})[_0x65bc('0x2f')](handleEntityNotFound(_0x3d0e0d,null))[_0x65bc('0x2f')](function(_0x3d271f){if(_0x3d271f){_0x17989b[_0x65bc('0x57')][_0x65bc('0x62')]=_0x3d271f['id'];return db[_0x65bc('0x63')][_0x65bc('0x5a')](_0x17989b[_0x65bc('0x57')]);}})[_0x65bc('0x2f')](respondWithResult(_0x3d0e0d,null))[_0x65bc('0x54')](handleError(_0x3d0e0d,null));};exports[_0x65bc('0x64')]=function(_0x3e357e,_0x41cbe0,_0x1bba96){var _0x5db326={'raw':![],'where':{}};var _0x2c87a9={};var _0x5dd124={'count':0x0,'rows':[]};return db['MailAccount'][_0x65bc('0x5b')]({'where':{'id':_0x3e357e[_0x65bc('0x5c')]['id']}})['then'](handleEntityNotFound(_0x41cbe0,null))['then'](function(_0x2c7854){if(_0x2c7854){_0x2c87a9[_0x65bc('0x3e')]=_[_0x65bc('0x3f')](db[_0x65bc('0x63')][_0x65bc('0x3d')]);_0x2c87a9[_0x65bc('0x40')]=_[_0x65bc('0x3f')](_0x3e357e[_0x65bc('0x40')]);_0x2c87a9[_0x65bc('0x41')]=_[_0x65bc('0x42')](_0x2c87a9[_0x65bc('0x3e')],_0x2c87a9[_0x65bc('0x40')]);_0x5db326[_0x65bc('0x43')]=_[_0x65bc('0x42')](_0x2c87a9['model'],qs[_0x65bc('0x44')](_0x3e357e[_0x65bc('0x40')][_0x65bc('0x44')]));_0x5db326[_0x65bc('0x43')]=_0x5db326[_0x65bc('0x43')]['length']?_0x5db326[_0x65bc('0x43')]:_0x2c87a9[_0x65bc('0x3e')];if(!_0x3e357e[_0x65bc('0x40')]['hasOwnProperty'](_0x65bc('0x45'))){_0x5db326[_0x65bc('0x2a')]=qs[_0x65bc('0x2a')](_0x3e357e[_0x65bc('0x40')]['limit']);_0x5db326[_0x65bc('0x29')]=qs[_0x65bc('0x29')](_0x3e357e[_0x65bc('0x40')]['offset']);}_0x5db326[_0x65bc('0x46')]=qs[_0x65bc('0x47')](_0x3e357e[_0x65bc('0x40')]['sort']);_0x5db326['where']=qs[_0x65bc('0x41')](_[_0x65bc('0x5e')](_0x3e357e[_0x65bc('0x40')],_0x2c87a9['filters']));_0x5db326[_0x65bc('0x48')][_0x65bc('0x62')]=_0x2c7854['id'];if(_0x3e357e['query'][_0x65bc('0x49')]){_0x5db326[_0x65bc('0x48')]=_['merge'](_0x5db326['where'],{'$or':_[_0x65bc('0x4b')](_0x5db326['attributes'],function(_0x437015){var _0x38416f={};_0x38416f[_0x437015]={'$like':'%'+_0x3e357e[_0x65bc('0x40')][_0x65bc('0x49')]+'%'};return _0x38416f;})});}_0x5db326=_[_0x65bc('0x4a')]({},_0x5db326,_0x3e357e[_0x65bc('0x50')]);return db[_0x65bc('0x63')][_0x65bc('0x28')]({'where':_0x5db326[_0x65bc('0x48')]})[_0x65bc('0x2f')](function(_0x4049ac){_0x5dd124[_0x65bc('0x28')]=_0x4049ac;if(_0x3e357e[_0x65bc('0x40')][_0x65bc('0x51')]){_0x5db326[_0x65bc('0x56')]=[{'all':!![]}];}return db[_0x65bc('0x63')]['findAll'](_0x5db326);})[_0x65bc('0x2f')](function(_0x15eba9){_0x5dd124[_0x65bc('0x53')]=_0x15eba9;return _0x5dd124;});}})[_0x65bc('0x2f')](respondWithFilteredResult(_0x41cbe0,_0x5db326))[_0x65bc('0x54')](handleError(_0x41cbe0,null));};exports['removeAnswers']=function(_0xed3e2a,_0x281933,_0x3d9f2c){return db[_0x65bc('0x3c')][_0x65bc('0x60')]({'where':{'id':_0xed3e2a[_0x65bc('0x5c')]['id']}})['then'](handleEntityNotFound(_0x281933,null))[_0x65bc('0x2f')](function(_0x2e945a){if(_0x2e945a){return _0x2e945a[_0x65bc('0x65')](_0xed3e2a[_0x65bc('0x40')][_0x65bc('0x61')]);}})[_0x65bc('0x2f')](respondWithStatusCode(_0x281933,null))[_0x65bc('0x54')](handleError(_0x281933,null));};exports['create']=function(_0xa826de,_0x3c833e){var _0x40b36a={'name':_0xa826de[_0x65bc('0x57')][_0x65bc('0x33')],'key':_0xa826de['body']['key'],'email':_0xa826de[_0x65bc('0x57')][_0x65bc('0x66')],'ListId':_0xa826de[_0x65bc('0x57')][_0x65bc('0x67')],'active':!_[_0x65bc('0x68')](_0xa826de[_0x65bc('0x57')]['active'])?_0xa826de[_0x65bc('0x57')]['active']:!![],'description':_0xa826de['body']['description']||null,'Imap':{},'Smtp':{}};if(_[_0x65bc('0x68')](_0xa826de[_0x65bc('0x57')][_0x65bc('0x69')])){if(_0xa826de[_0x65bc('0x57')][_0x65bc('0x6a')]){_0x40b36a[_0x65bc('0x37')]['user']=_0x40b36a[_0x65bc('0x39')]['user']=_0xa826de[_0x65bc('0x57')][_0x65bc('0x6b')];_0x40b36a[_0x65bc('0x37')][_0x65bc('0x6c')]=_0x40b36a['Smtp'][_0x65bc('0x6d')]=_0xa826de[_0x65bc('0x57')]['cpassword'];}else{_0x40b36a['Imap'][_0x65bc('0x6e')]=_0x40b36a[_0x65bc('0x39')][_0x65bc('0x6e')]=![];}_0x40b36a[_0x65bc('0x37')][_0x65bc('0x6f')]=_0xa826de[_0x65bc('0x57')]['Imap'][_0x65bc('0x6f')];_0x40b36a['Imap']['port']=_0xa826de['body'][_0x65bc('0x37')][_0x65bc('0x70')];_0x40b36a[_0x65bc('0x39')][_0x65bc('0x6f')]=_0xa826de[_0x65bc('0x57')][_0x65bc('0x39')]['host'];_0x40b36a[_0x65bc('0x39')][_0x65bc('0x70')]=_0xa826de[_0x65bc('0x57')][_0x65bc('0x39')][_0x65bc('0x70')];}else{_0x40b36a[_0x65bc('0x37')][_0x65bc('0x71')]=_0x40b36a['Smtp']['service']=_0xa826de['body'][_0x65bc('0x69')];_0x40b36a[_0x65bc('0x37')]['user']=_0x40b36a[_0x65bc('0x39')][_0x65bc('0x72')]=_0xa826de['body'][_0x65bc('0x6b')];_0x40b36a[_0x65bc('0x37')][_0x65bc('0x6c')]=_0x40b36a[_0x65bc('0x39')][_0x65bc('0x6d')]=_0xa826de[_0x65bc('0x57')][_0x65bc('0x73')];}return db['MailAccount'][_0x65bc('0x5a')](_0x40b36a,{'include':[{'model':db[_0x65bc('0x38')],'as':_0x65bc('0x39')},{'model':db[_0x65bc('0x36')],'as':_0x65bc('0x37')}]})['then'](function(_0x88963a){var _0x5b031c=_0xa826de[_0x65bc('0x72')][_0x65bc('0x74')]({'plain':!![]});if(!_0x5b031c)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x5b031c[_0x65bc('0x75')]===_0x65bc('0x72')){var _0x352534=_0x88963a[_0x65bc('0x74')]({'plain':!![]});return db['UserProfileSection'][_0x65bc('0x60')]({'where':{'name':_0x65bc('0x31'),'userProfileId':_0x5b031c[_0x65bc('0x76')]},'raw':!![]})['then'](function(_0x5de902){if(_0x5de902&&_0x5de902[_0x65bc('0x77')]===0x0){return db[_0x65bc('0x78')][_0x65bc('0x5a')]({'name':_0x352534['name'],'resourceId':_0x352534['id'],'type':_0x5de902['name'],'sectionId':_0x5de902['id']},{})[_0x65bc('0x2f')](function(){return _0x88963a;});}else{return _0x88963a;}})[_0x65bc('0x54')](function(_0x149587){logger[_0x65bc('0x21')](_0x65bc('0x79'),_0x149587);throw _0x149587;});}return _0x88963a;})['then'](respondWithResult(_0x3c833e,0xc9))[_0x65bc('0x54')](handleError(_0x3c833e,null));};exports[_0x65bc('0x7a')]=function(_0x29e39c,_0x53326a,_0x35276e){return db[_0x65bc('0x3c')]['findOne']({'where':{'id':_0x29e39c[_0x65bc('0x5c')]['id']}})[_0x65bc('0x2f')](handleEntityNotFound(_0x53326a,null))[_0x65bc('0x2f')](function(_0x374dab){if(_0x374dab){return _0x374dab[_0x65bc('0x7a')]();}return null;})['then'](respondWithResult(_0x53326a,null))['catch'](handleError(_0x53326a,null));};exports['addImap']=function(_0x1501d8,_0x24876c,_0x65467e){if(_0x1501d8[_0x65bc('0x57')]['id']){delete _0x1501d8['body']['id'];}return db['MailAccount']['find']({'where':{'id':_0x1501d8[_0x65bc('0x5c')]['id']}})['then'](handleEntityNotFound(_0x24876c,null))['then'](function(_0x4ae106){if(_0x4ae106){_0x1501d8[_0x65bc('0x57')][_0x65bc('0x62')]=_0x4ae106['id'];return db[_0x65bc('0x36')][_0x65bc('0x5a')](_0x1501d8[_0x65bc('0x57')]);}})[_0x65bc('0x2f')](respondWithResult(_0x24876c,null))[_0x65bc('0x54')](handleError(_0x24876c,null));};exports[_0x65bc('0x7b')]=function(_0x2aa5c7,_0x2df8e3,_0x4497fd){return db[_0x65bc('0x3c')][_0x65bc('0x5b')]({'where':{'id':_0x2aa5c7['params']['id']}})[_0x65bc('0x2f')](handleEntityNotFound(_0x2df8e3,null))[_0x65bc('0x2f')](function(_0x5ed7ff){if(_0x5ed7ff){return _0x5ed7ff[_0x65bc('0x7c')](null);}return null;})['then'](respondWithStatusCode(_0x2df8e3,null))['catch'](handleError(_0x2df8e3,null));};exports[_0x65bc('0x7d')]=function(_0x5a7755,_0x57cdfd,_0x299d11){return db[_0x65bc('0x3c')][_0x65bc('0x5b')]({'where':{'id':_0x5a7755['params']['id']}})[_0x65bc('0x2f')](handleEntityNotFound(_0x57cdfd,null))[_0x65bc('0x2f')](function(_0x55c3f9){if(_0x55c3f9){return _0x55c3f9[_0x65bc('0x7d')]();}return null;})['then'](respondWithResult(_0x57cdfd,null))[_0x65bc('0x54')](handleError(_0x57cdfd,null));};exports[_0x65bc('0x7e')]=function(_0x14eb44,_0x51ba48,_0x3575d4){if(_0x14eb44[_0x65bc('0x57')]['id']){delete _0x14eb44[_0x65bc('0x57')]['id'];}return db[_0x65bc('0x3c')][_0x65bc('0x60')]({'where':{'id':_0x14eb44[_0x65bc('0x5c')]['id']}})[_0x65bc('0x2f')](handleEntityNotFound(_0x51ba48,null))[_0x65bc('0x2f')](function(_0x5bcbf8){if(_0x5bcbf8){_0x14eb44[_0x65bc('0x57')][_0x65bc('0x62')]=_0x5bcbf8['id'];return db[_0x65bc('0x38')][_0x65bc('0x5a')](_0x14eb44['body']);}})[_0x65bc('0x2f')](respondWithResult(_0x51ba48,null))[_0x65bc('0x54')](handleError(_0x51ba48,null));};exports[_0x65bc('0x7f')]=function(_0xc63f0b,_0x536929,_0x50aa51){return db[_0x65bc('0x3c')][_0x65bc('0x5b')]({'where':{'id':_0xc63f0b[_0x65bc('0x5c')]['id']}})[_0x65bc('0x2f')](handleEntityNotFound(_0x536929,null))['then'](function(_0x1af214){if(_0x1af214){return _0x1af214['setSmtp'](null);}return null;})[_0x65bc('0x2f')](respondWithStatusCode(_0x536929,null))[_0x65bc('0x54')](handleError(_0x536929,null));};exports[_0x65bc('0x80')]=function(_0x542394,_0x45ee62,_0x58dd55){return db[_0x65bc('0x81')][_0x65bc('0x60')]({'where':{'id':_0x542394['params']['id']}})[_0x65bc('0x2f')](handleEntityNotFound(_0x45ee62,null))['then'](function(_0x5acc03){if(_0x5acc03){return _0x5acc03['addInteraction'](_0x542394[_0x65bc('0x57')][_0x65bc('0x61')],_[_0x65bc('0x82')](_0x542394[_0x65bc('0x57')],[_0x65bc('0x61'),'id'])||{});}})['then'](respondWithResult(_0x45ee62,null))[_0x65bc('0x54')](handleError(_0x45ee62,null));};exports[_0x65bc('0x83')]=function(_0x1705e9,_0x16f106,_0x59d6bf){var _0x39c4f4={'raw':![],'where':{}};var _0x2c0375={};var _0x599ab0={'count':0x0,'rows':[]};return db[_0x65bc('0x3c')][_0x65bc('0x5b')]({'where':{'id':_0x1705e9['params']['id']}})[_0x65bc('0x2f')](handleEntityNotFound(_0x16f106,null))[_0x65bc('0x2f')](function(_0x3f6475){if(_0x3f6475){_0x2c0375[_0x65bc('0x3e')]=_[_0x65bc('0x3f')](db[_0x65bc('0x81')][_0x65bc('0x3d')]);_0x2c0375[_0x65bc('0x40')]=_['keys'](_0x1705e9[_0x65bc('0x40')]);_0x2c0375[_0x65bc('0x41')]=_[_0x65bc('0x42')](_0x2c0375[_0x65bc('0x3e')],_0x2c0375[_0x65bc('0x40')]);_0x39c4f4[_0x65bc('0x43')]=_[_0x65bc('0x42')](_0x2c0375['model'],qs[_0x65bc('0x44')](_0x1705e9[_0x65bc('0x40')][_0x65bc('0x44')]));_0x39c4f4[_0x65bc('0x43')]=_0x39c4f4['attributes'][_0x65bc('0x5d')]?_0x39c4f4['attributes']:_0x2c0375['model'];if(!_0x1705e9[_0x65bc('0x40')][_0x65bc('0x84')](_0x65bc('0x45'))){_0x39c4f4[_0x65bc('0x2a')]=qs[_0x65bc('0x2a')](_0x1705e9['query'][_0x65bc('0x2a')]);_0x39c4f4[_0x65bc('0x29')]=qs[_0x65bc('0x29')](_0x1705e9[_0x65bc('0x40')][_0x65bc('0x29')]);}_0x39c4f4[_0x65bc('0x46')]=qs['sort'](_0x1705e9[_0x65bc('0x40')][_0x65bc('0x47')]);_0x39c4f4['where']=qs[_0x65bc('0x41')](_[_0x65bc('0x5e')](_0x1705e9[_0x65bc('0x40')],_0x2c0375[_0x65bc('0x41')]));_0x39c4f4[_0x65bc('0x48')][_0x65bc('0x62')]=_0x3f6475['id'];if(_0x1705e9[_0x65bc('0x40')][_0x65bc('0x49')]){_0x39c4f4['where']=_[_0x65bc('0x4a')](_0x39c4f4[_0x65bc('0x48')],{'$or':_[_0x65bc('0x4b')](_0x39c4f4['attributes'],function(_0x544e5c){var _0x1c9e44={};_0x1c9e44[_0x544e5c]={'$like':'%'+_0x1705e9[_0x65bc('0x40')]['filter']+'%'};return _0x1c9e44;})});}_0x39c4f4=_[_0x65bc('0x4a')]({},_0x39c4f4,_0x1705e9['options']);return db[_0x65bc('0x81')][_0x65bc('0x28')]({'where':_0x39c4f4[_0x65bc('0x48')]})[_0x65bc('0x2f')](function(_0x2eeced){_0x599ab0[_0x65bc('0x28')]=_0x2eeced;if(_0x1705e9[_0x65bc('0x40')][_0x65bc('0x51')]){_0x39c4f4[_0x65bc('0x56')]=[{'model':db[_0x65bc('0x85')],'as':_0x65bc('0x86'),'required':![]},{'model':db[_0x65bc('0x87')],'as':'Owner','attributes':[_0x65bc('0x33'),_0x65bc('0x88'),_0x65bc('0x89')],'required':![]},{'model':db[_0x65bc('0x8a')],'as':_0x65bc('0x8b'),'attributes':['id',_0x65bc('0x33'),_0x65bc('0x8c')],'where':_0x1705e9[_0x65bc('0x40')][_0x65bc('0x8d')]?{'id':_0x1705e9[_0x65bc('0x40')][_0x65bc('0x8d')]}:undefined,'required':_0x1705e9[_0x65bc('0x40')]['tag']?!![]:![]}];}return db['MailInteraction'][_0x65bc('0x52')](_0x39c4f4);})['then'](function(_0x3b28e4){_0x599ab0[_0x65bc('0x53')]=_0x3b28e4;return _0x599ab0;});}})['then'](respondWithFilteredResult(_0x16f106,_0x39c4f4))['catch'](handleError(_0x16f106,null));};exports['addApplications']=function(_0x49e7e6,_0x1fa943,_0x162259){return db[_0x65bc('0x3c')][_0x65bc('0x5b')]({'where':{'id':_0x49e7e6[_0x65bc('0x5c')]['id']}})[_0x65bc('0x2f')](handleEntityNotFound(_0x1fa943,null))[_0x65bc('0x2f')](function(_0x4ee9d3){if(_0x4ee9d3){return db[_0x65bc('0x8e')][_0x65bc('0x8f')](function(_0x4b41a6){return db['MailApplication'][_0x65bc('0x30')]({'where':{'MailAccountId':_0x49e7e6[_0x65bc('0x5c')]['id']},'transaction':_0x4b41a6})[_0x65bc('0x2f')](function(_0x503f1d){var _0x14a391=_[_0x65bc('0x4b')](_0x49e7e6[_0x65bc('0x57')],function(_0xcbb2dd){_0xcbb2dd[_0x65bc('0x62')]=_0x49e7e6[_0x65bc('0x5c')]['id'];return _0xcbb2dd;});return db[_0x65bc('0x90')]['bulkCreate'](_0x14a391,{'transaction':_0x4b41a6});});})[_0x65bc('0x2f')](function(){return db[_0x65bc('0x90')][_0x65bc('0x91')]({'where':{'MailAccountId':_0x49e7e6[_0x65bc('0x5c')]['id']},'order':'priority'});});}})[_0x65bc('0x2f')](respondWithResult(_0x1fa943,null))[_0x65bc('0x54')](handleError(_0x1fa943,null));};exports[_0x65bc('0x92')]=function(_0x2ff7d3,_0x20537,_0x35d955){var _0x1f02bb={};var _0x497adc={};var _0x14da85;var _0x456440;return db[_0x65bc('0x3c')][_0x65bc('0x5b')]({'where':{'id':_0x2ff7d3[_0x65bc('0x5c')]['id']}})['then'](handleEntityNotFound(_0x20537,null))['then'](function(_0x432c25){if(_0x432c25){_0x14da85=_0x432c25;_0x497adc['model']=_[_0x65bc('0x3f')](db[_0x65bc('0x90')][_0x65bc('0x3d')]);_0x497adc['query']=_[_0x65bc('0x3f')](_0x2ff7d3['query']);_0x497adc[_0x65bc('0x41')]=_[_0x65bc('0x42')](_0x497adc[_0x65bc('0x3e')],_0x497adc[_0x65bc('0x40')]);_0x1f02bb[_0x65bc('0x43')]=_[_0x65bc('0x42')](_0x497adc[_0x65bc('0x3e')],qs[_0x65bc('0x44')](_0x2ff7d3[_0x65bc('0x40')]['fields']));_0x1f02bb[_0x65bc('0x43')]=_0x1f02bb[_0x65bc('0x43')][_0x65bc('0x5d')]?_0x1f02bb[_0x65bc('0x43')]:_0x497adc['model'];_0x1f02bb['order']=qs[_0x65bc('0x47')](_0x2ff7d3[_0x65bc('0x40')][_0x65bc('0x47')]);_0x1f02bb[_0x65bc('0x48')]=qs[_0x65bc('0x41')](_[_0x65bc('0x5e')](_0x2ff7d3[_0x65bc('0x40')],_0x497adc['filters']));if(_0x2ff7d3[_0x65bc('0x40')][_0x65bc('0x49')]){_0x1f02bb['where']=_[_0x65bc('0x4a')](_0x1f02bb[_0x65bc('0x48')],{'$or':_[_0x65bc('0x4b')](_0x1f02bb[_0x65bc('0x43')],function(_0x1221ea){var _0x56fdd4={};_0x56fdd4[_0x1221ea]={'$like':'%'+_0x2ff7d3[_0x65bc('0x40')][_0x65bc('0x49')]+'%'};return _0x56fdd4;})});}_0x1f02bb=_[_0x65bc('0x4a')]({},_0x1f02bb,_0x2ff7d3[_0x65bc('0x50')]);return _0x14da85[_0x65bc('0x92')](_0x1f02bb);}})[_0x65bc('0x2f')](function(_0x54989d){if(_0x54989d){_0x456440=_0x54989d[_0x65bc('0x5d')];if(!_0x2ff7d3[_0x65bc('0x40')]['hasOwnProperty'](_0x65bc('0x45'))){_0x1f02bb[_0x65bc('0x2a')]=qs[_0x65bc('0x2a')](_0x2ff7d3[_0x65bc('0x40')]['limit']);_0x1f02bb[_0x65bc('0x29')]=qs[_0x65bc('0x29')](_0x2ff7d3['query'][_0x65bc('0x29')]);}return _0x14da85['getApplications'](_0x1f02bb);}})[_0x65bc('0x2f')](function(_0xc7fe0d){if(_0xc7fe0d){return _0xc7fe0d?{'count':_0x456440,'rows':_0xc7fe0d}:null;}})[_0x65bc('0x2f')](respondWithResult(_0x20537,null))[_0x65bc('0x54')](handleError(_0x20537,null));};exports[_0x65bc('0x93')]=function(_0x3676dc,_0x566c6a,_0x8a9a0d){var _0x44c397={'raw':!![],'where':{}};var _0x2fa67e={};var _0x26d1cb={'count':0x0,'rows':[]};return db[_0x65bc('0x3c')][_0x65bc('0x5b')]({'where':{'id':_0x3676dc[_0x65bc('0x5c')]['id']}})['then'](handleEntityNotFound(_0x566c6a,null))[_0x65bc('0x2f')](function(_0x1044cc){if(_0x1044cc){_0x2fa67e[_0x65bc('0x3e')]=_[_0x65bc('0x3f')](db[_0x65bc('0x94')][_0x65bc('0x3d')]);_0x2fa67e[_0x65bc('0x40')]=_['keys'](_0x3676dc[_0x65bc('0x40')]);_0x2fa67e[_0x65bc('0x41')]=_[_0x65bc('0x42')](_0x2fa67e[_0x65bc('0x3e')],_0x2fa67e['query']);_0x44c397['attributes']=_[_0x65bc('0x42')](_0x2fa67e[_0x65bc('0x3e')],qs[_0x65bc('0x44')](_0x3676dc[_0x65bc('0x40')]['fields']));_0x44c397[_0x65bc('0x43')]=_0x44c397[_0x65bc('0x43')][_0x65bc('0x5d')]?_0x44c397[_0x65bc('0x43')]:_0x2fa67e[_0x65bc('0x3e')];if(!_0x3676dc[_0x65bc('0x40')][_0x65bc('0x84')]('nolimit')){_0x44c397[_0x65bc('0x2a')]=qs[_0x65bc('0x2a')](_0x3676dc['query'][_0x65bc('0x2a')]);_0x44c397[_0x65bc('0x29')]=qs['offset'](_0x3676dc['query'][_0x65bc('0x29')]);}_0x44c397['order']=qs[_0x65bc('0x47')](_0x3676dc['query'][_0x65bc('0x47')]);_0x44c397[_0x65bc('0x48')]=qs[_0x65bc('0x41')](_['pick'](_0x3676dc[_0x65bc('0x40')],_0x2fa67e['filters']));_0x44c397[_0x65bc('0x48')][_0x65bc('0x62')]=_0x1044cc['id'];if(_0x3676dc['query'][_0x65bc('0x49')]){_0x44c397['where']=_[_0x65bc('0x4a')](_0x44c397[_0x65bc('0x48')],{'$or':_[_0x65bc('0x4b')](_0x44c397[_0x65bc('0x43')],function(_0x68de08){var _0x3c52a8={};_0x3c52a8[_0x68de08]={'$like':'%'+_0x3676dc[_0x65bc('0x40')][_0x65bc('0x49')]+'%'};return _0x3c52a8;})});}if(_0x3676dc[_0x65bc('0x40')][_0x65bc('0x95')]){var _0x194492=_0x3676dc['query'][_0x65bc('0x95')][_0x65bc('0x96')](',');var _0x4fff3b={};_0x4fff3b[_0x194492[0x0]]={'$gte':moment(_0x194492[0x1])[_0x65bc('0x97')](_0x65bc('0x98'))};_0x44c397[_0x65bc('0x48')]=_[_0x65bc('0x4a')](_0x44c397[_0x65bc('0x48')],_0x4fff3b);}_0x44c397=_[_0x65bc('0x4a')]({},_0x44c397,_0x3676dc[_0x65bc('0x50')]);return db['MailMessage'][_0x65bc('0x28')]({'where':_0x44c397[_0x65bc('0x48')]})[_0x65bc('0x2f')](function(_0x2b913b){_0x26d1cb[_0x65bc('0x28')]=_0x2b913b;if(_0x3676dc[_0x65bc('0x40')][_0x65bc('0x51')]){_0x44c397[_0x65bc('0x56')]=[{'all':!![]}];}return db['MailMessage'][_0x65bc('0x52')](_0x44c397);})[_0x65bc('0x2f')](function(_0x4ee5ec){_0x26d1cb[_0x65bc('0x53')]=_0x4ee5ec;return _0x26d1cb;});}})['then'](respondWithFilteredResult(_0x566c6a,_0x44c397))['catch'](handleError(_0x566c6a,null));};exports[_0x65bc('0x34')]=function(_0x5a029b,_0xca1f12,_0x419689){var _0x1e4722,_0xf731ad={},_0x184151;if(_0x5a029b[_0x65bc('0x57')]['to']){_0x184151=_0x5a029b[_0x65bc('0x57')]['to'][_0x65bc('0x96')](',')[0x0];}return db[_0x65bc('0x3c')][_0x65bc('0x60')]({'where':{'id':_0x5a029b['params']['id']},'include':[{'model':db[_0x65bc('0x99')],'as':'List','include':[{'model':db['CmContact'],'as':_0x65bc('0x9a'),'where':{'email':_0x184151},'limit':0x1,'order':[[_0x65bc('0x9b'),_0x65bc('0x9c')]]}]},{'model':db[_0x65bc('0x38')],'as':_0x65bc('0x39'),'raw':!![]}]})[_0x65bc('0x2f')](handleEntityNotFound(_0xca1f12,null))[_0x65bc('0x2f')](function(_0x2f8a7c){if(_0x2f8a7c){_0x1e4722=_0x2f8a7c;if(_0x2f8a7c[_0x65bc('0x39')]){if(_['isNil'](_0x5a029b['body'][_0x65bc('0x9d')])){_0x5a029b[_0x65bc('0x57')][_0x65bc('0x9d')]=util[_0x65bc('0x97')](_0x65bc('0x9e'),_0x2f8a7c['name'],_0x2f8a7c[_0x65bc('0x66')]||_0x2f8a7c[_0x65bc('0x39')]['user']);}if(_0x5a029b[_0x65bc('0x57')][_0x65bc('0x9f')]&&_0x5a029b[_0x65bc('0x57')][_0x65bc('0x9f')]['length']){for(var _0x4cbc99=0x0;_0x4cbc99<_0x5a029b['body']['attachments'][_0x65bc('0x5d')];_0x4cbc99+=0x1){_0x5a029b['body']['attachments'][_0x4cbc99]={'filename':_0x5a029b[_0x65bc('0x57')][_0x65bc('0x9f')][_0x4cbc99]['name'],'path':path[_0x65bc('0xa0')](config[_0x65bc('0xa1')],_0x65bc('0xa2'),_0x5a029b['body'][_0x65bc('0x9f')][_0x4cbc99][_0x65bc('0xa3')])};}}var _0xb5bea9={'tls':{'rejectUnauthorized':![]}};if(_[_0x65bc('0x68')](_0x2f8a7c['Smtp']['service'])){if(_0x2f8a7c['Smtp']['authentication']){_0xb5bea9[_0x65bc('0xa4')]={'user':_0x2f8a7c[_0x65bc('0x39')][_0x65bc('0x72')],'pass':_0x2f8a7c['Smtp'][_0x65bc('0x6d')]};}_0xb5bea9[_0x65bc('0x6f')]=_0x2f8a7c[_0x65bc('0x39')][_0x65bc('0x6f')];_0xb5bea9[_0x65bc('0x70')]=_0x2f8a7c[_0x65bc('0x39')][_0x65bc('0x70')];_0xb5bea9['secure']=_0x2f8a7c[_0x65bc('0x39')][_0x65bc('0xa5')];}else{_0xb5bea9[_0x65bc('0x71')]=_0x2f8a7c[_0x65bc('0x39')][_0x65bc('0x71')];_0xb5bea9['auth']={'user':_0x2f8a7c[_0x65bc('0x39')]['user'],'pass':_0x2f8a7c[_0x65bc('0x39')][_0x65bc('0x6d')]};}return respondWithRpcPromise(_0x65bc('0xa6'),_0x65bc('0xa7'),{'account':_0xb5bea9,'message':_0x5a029b[_0x65bc('0x57')]});}else{throw new Error(_0x65bc('0xa8'));}}})[_0x65bc('0x2f')](function(_0x352bac){if(_0x352bac){_0xf731ad=_0x352bac;if(_0x1e4722[_0x65bc('0xa9')]){if(_0x1e4722['List'][_0x65bc('0x9a')][_0x65bc('0x5d')]){return _0x1e4722[_0x65bc('0xa9')]['Contacts'][0x0];}else{return db[_0x65bc('0x85')][_0x65bc('0x5a')](_[_0x65bc('0x14')](_0x5a029b['body'],{'firstName':_0x5a029b['body']['to'],'email':_0x5a029b['body']['to'],'phone':_0x5a029b[_0x65bc('0x57')]['to'],'ListId':_0x1e4722[_0x65bc('0x67')]}));}}else{throw new Error(_0x65bc('0xa8'));}}})['then'](function(_0x2476aa){if(_0x2476aa){var _0x470b57={'UserId':_0x5a029b[_0x65bc('0x72')]['id'],'ContactId':_0x2476aa['id'],'MailAccountId':_0x1e4722['id'],'inReplyTo':_0xf731ad[_0x65bc('0xaa')],'to':_0x5a029b['body'][_0x65bc('0x9d')],'cc':_0x5a029b['body']['cc'],'subject':_0x5a029b[_0x65bc('0x57')][_0x65bc('0xab')],'attach':_0x5a029b[_0x65bc('0x57')][_0x65bc('0xac')],'firstMsgDirection':'out','lastMsgAt':moment()[_0x65bc('0x97')]('YYYY-MM-DD\x20HH:mm:ss'),'lastMsgDirection':_0x65bc('0xad'),'lastMsgBody':_0x5a029b[_0x65bc('0x57')][_0x65bc('0x57')],'Messages':[_[_0x65bc('0x4a')](_0x5a029b['body'],{'messageId':_0xf731ad[_0x65bc('0xaa')],'sentAt':moment()[_0x65bc('0x97')](_0x65bc('0x98')),'read':!![],'MailAccountId':_0x1e4722['id'],'UserId':_0x5a029b[_0x65bc('0x72')]['id'],'ContactId':_0x2476aa['id']})]};if(_0x5a029b[_0x65bc('0x57')][_0x65bc('0xae')]){_0x470b57=_[_0x65bc('0x4a')](_0x470b57,_0x5a029b['body'][_0x65bc('0xae')]);}return db[_0x65bc('0x81')]['create'](_0x470b57,{'include':[{'model':db[_0x65bc('0x94')],'as':_0x65bc('0xaf')}]});}})[_0x65bc('0x2f')](respondWithResult(_0xca1f12,null))[_0x65bc('0x54')](handleError(_0xca1f12,null));};exports[_0x65bc('0xb0')]=function(_0x369145,_0x416fbb,_0x508141){return db[_0x65bc('0x3c')][_0x65bc('0x60')]({'where':{'id':_0x369145[_0x65bc('0x5c')]['id']},'include':[{'model':db[_0x65bc('0x38')],'as':'Smtp','raw':!![]}]})[_0x65bc('0x2f')](handleEntityNotFound(_0x416fbb,null))[_0x65bc('0x2f')](function(_0x173d86){if(_0x173d86&&_0x173d86[_0x65bc('0x39')]){var _0x44813b={'id':_0x173d86['id'],'tls':{'rejectUnauthorized':![]}};if(_0x173d86[_0x65bc('0x39')][_0x65bc('0x71')]){_0x44813b[_0x65bc('0x71')]=_0x173d86[_0x65bc('0x39')][_0x65bc('0x71')];}else{_0x44813b[_0x65bc('0x6f')]=_0x173d86['Smtp'][_0x65bc('0x6f')];_0x44813b[_0x65bc('0x70')]=_0x173d86[_0x65bc('0x39')]['port'];_0x44813b[_0x65bc('0xa5')]=_0x173d86[_0x65bc('0x39')][_0x65bc('0xa5')];}if(_0x173d86[_0x65bc('0x39')][_0x65bc('0x6e')]){_0x44813b[_0x65bc('0xa4')]={'user':_0x173d86[_0x65bc('0x39')][_0x65bc('0x72')],'pass':_0x173d86[_0x65bc('0x39')][_0x65bc('0x6d')]};}return respondWithRpcPromise(_0x65bc('0xb1'),_0x65bc('0xb0'),{'account':_0x44813b});}})['then'](respondWithResult(_0x416fbb,null))[_0x65bc('0x54')](handleError(_0x416fbb,null));};exports[_0x65bc('0x30')]=function(_0x50b54e,_0x2bae40){return db['MailAccount'][_0x65bc('0x60')]({'where':{'id':_0x50b54e[_0x65bc('0x5c')]['id']}})[_0x65bc('0x2f')](handleEntityNotFound(_0x2bae40,null))[_0x65bc('0x2f')](function(_0x166bce){if(_0x166bce&&_0x166bce[_0x65bc('0x71')]){throw new db[(_0x65bc('0xb2'))][(_0x65bc('0xb3'))]('You\x20can\x27t\x20remove\x20the\x20mail\x20service\x20account');}return _0x166bce;})['then'](removeEntity(_0x2bae40,null))['catch'](handleError(_0x2bae40,null));};exports['addAgents']=function(_0x27ba5e,_0x9e7a15,_0x4d7649){return db[_0x65bc('0x3c')][_0x65bc('0x60')]({'where':{'id':_0x27ba5e['params']['id']}})[_0x65bc('0x2f')](handleEntityNotFound(_0x9e7a15,null))['then'](function(_0x40ee97){if(_0x40ee97){return _0x40ee97[_0x65bc('0xb4')](_0x27ba5e[_0x65bc('0x57')][_0x65bc('0x61')],_[_0x65bc('0x82')](_0x27ba5e[_0x65bc('0x57')],['ids','id'])||{})[_0x65bc('0xb5')](function(_0x5924a9){for(var _0x47f3e3=0x0;_0x47f3e3<_0x27ba5e['body']['ids']['length'];_0x47f3e3+=0x1){socket[_0x65bc('0xb6')](_0x65bc('0xb7'),{'UserId':_0x27ba5e[_0x65bc('0x57')][_0x65bc('0x61')][_0x47f3e3],'MailAccountId':_0x27ba5e[_0x65bc('0x5c')]['id']});}return _0x5924a9;});}})[_0x65bc('0x2f')](respondWithResult(_0x9e7a15,null))['catch'](handleError(_0x9e7a15,null));};exports[_0x65bc('0xb8')]=function(_0x47f187,_0x599ee6,_0x441f3a){return db[_0x65bc('0x3c')][_0x65bc('0x60')]({'where':{'id':_0x47f187[_0x65bc('0x5c')]['id']}})[_0x65bc('0x2f')](handleEntityNotFound(_0x599ee6,null))[_0x65bc('0x2f')](function(_0x42f250){if(_0x42f250){return _0x42f250[_0x65bc('0xb8')](_0x47f187[_0x65bc('0x40')][_0x65bc('0x61')])[_0x65bc('0x2f')](function(){if(_['isArray'](_0x47f187['query'][_0x65bc('0x61')])){for(var _0x51a7f6=0x0;_0x51a7f6<_0x47f187[_0x65bc('0x40')][_0x65bc('0x61')][_0x65bc('0x5d')];_0x51a7f6+=0x1){socket[_0x65bc('0xb6')](_0x65bc('0xb9'),{'UserId':Number(_0x47f187['query'][_0x65bc('0x61')][_0x51a7f6]),'MailAccountId':Number(_0x47f187['params']['id'])});}}else{socket[_0x65bc('0xb6')](_0x65bc('0xb9'),{'UserId':Number(_0x47f187[_0x65bc('0x40')][_0x65bc('0x61')]),'MailAccountId':Number(_0x47f187[_0x65bc('0x5c')]['id'])});}});}})['then'](respondWithStatusCode(_0x599ee6,null))[_0x65bc('0x54')](handleError(_0x599ee6,null));};exports[_0x65bc('0xba')]=function(_0x25baeb,_0x59acbd,_0x2ed54b){var _0x4933e7={};var _0x2bfec1={};var _0x183e02;var _0x1f74b4;return db[_0x65bc('0x3c')][_0x65bc('0x5b')]({'where':{'id':_0x25baeb['params']['id']}})[_0x65bc('0x2f')](handleEntityNotFound(_0x59acbd,null))[_0x65bc('0x2f')](function(_0x3563ac){if(_0x3563ac){_0x183e02=_0x3563ac;_0x2bfec1['model']=_[_0x65bc('0x3f')](db[_0x65bc('0x87')][_0x65bc('0x3d')]);_0x2bfec1['query']=_[_0x65bc('0x3f')](_0x25baeb[_0x65bc('0x40')]);_0x2bfec1[_0x65bc('0x41')]=_[_0x65bc('0x42')](_0x2bfec1[_0x65bc('0x3e')],_0x2bfec1[_0x65bc('0x40')]);_0x4933e7[_0x65bc('0x43')]=_[_0x65bc('0x42')](_0x2bfec1[_0x65bc('0x3e')],qs[_0x65bc('0x44')](_0x25baeb['query']['fields']));_0x4933e7['attributes']=_0x4933e7['attributes'][_0x65bc('0x5d')]?_0x4933e7['attributes']:_0x2bfec1[_0x65bc('0x3e')];_0x4933e7[_0x65bc('0x46')]=qs[_0x65bc('0x47')](_0x25baeb[_0x65bc('0x40')][_0x65bc('0x47')]);_0x4933e7[_0x65bc('0x48')]=qs[_0x65bc('0x41')](_[_0x65bc('0x5e')](_0x25baeb[_0x65bc('0x40')],_0x2bfec1[_0x65bc('0x41')]));if(_0x25baeb['query'][_0x65bc('0x49')]){_0x4933e7[_0x65bc('0x48')]=_[_0x65bc('0x4a')](_0x4933e7[_0x65bc('0x48')],{'$or':_[_0x65bc('0x4b')](_0x4933e7[_0x65bc('0x43')],function(_0x5bca35){var _0x3c1cc1={};_0x3c1cc1[_0x5bca35]={'$like':'%'+_0x25baeb[_0x65bc('0x40')][_0x65bc('0x49')]+'%'};return _0x3c1cc1;})});}_0x4933e7=_[_0x65bc('0x4a')]({},_0x4933e7,_0x25baeb[_0x65bc('0x50')]);return _0x183e02[_0x65bc('0xba')](_0x4933e7);}})[_0x65bc('0x2f')](function(_0x571697){if(_0x571697){_0x1f74b4=_0x571697[_0x65bc('0x5d')];if(!_0x25baeb[_0x65bc('0x40')][_0x65bc('0x84')](_0x65bc('0x45'))){_0x4933e7[_0x65bc('0x2a')]=qs[_0x65bc('0x2a')](_0x25baeb[_0x65bc('0x40')][_0x65bc('0x2a')]);_0x4933e7[_0x65bc('0x29')]=qs[_0x65bc('0x29')](_0x25baeb[_0x65bc('0x40')][_0x65bc('0x29')]);}return _0x183e02['getAgents'](_0x4933e7);}})[_0x65bc('0x2f')](function(_0x32c3e4){if(_0x32c3e4){return _0x32c3e4?{'count':_0x1f74b4,'rows':_0x32c3e4}:null;}})[_0x65bc('0x2f')](respondWithResult(_0x59acbd,null))[_0x65bc('0x54')](handleError(_0x59acbd,null));};