Built motion from commit (unavailable).|2.5.1
[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 _0xcfea=['Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','UserProfileResource','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','getImap','findOne','removeImap','setImap','getSmtp','addSmtp','addInteraction','omit','getInteractions','MailInteraction','CmContact','Contact','User','fullname','Tag','Tags','color','tag','addApplications','sequelize','transaction','MailApplication','bulkCreate','findAndCountAll','priority','getApplications','MailMessage','$gte','split','format','YYYY-MM-DD\x20HH:mm:ss','inlineCss','List','Contacts','updatedAt','from','attachments','join','root','server/files/attachments','basename','auth','secure','SendMail','sendMail','defaults','ListId','List\x20not\x20found','messageId','subject','attach','out','Interaction','Messages','verifySmtp','ValidationError','You\x20can\x27t\x20remove\x20the\x20mail\x20service\x20account','addAgents','spread','emit','userMailAccount:save','removeAgents','isArray','getAgents','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','path','sox','to-csv','lodash','squel','papaparse','html-to-text','juice','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','redis','localhost','register','jayson/promise','client','http','request','then','info','MailAccount,\x20%s,\x20%s','request\x20sent','debug','MailAccount,\x20%s,\x20%s,\x20%s','stringify','error','message','result','catch','sendStatus','end','status','json','offset','set','Content-Range','apply','reject','destroy','get','MailAccounts','stack','name','send','index','MailServerIn','Imap','MailServerOut','Smtp','Pause','mandatoryDispositionPause','map','MailAccount','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','limit','order','sort','pick','where','merge','options','count','includeAll','findAll','rows','params','include','find','body','update','describe','addDisposition','MailAccountId','Disposition','create','getDispositions','filter','removeDispositions','CannedAnswer','getAnswers','removeAnswers','ids','email','isNil','active','description','cservice','cauthentication','user','cuser','cpassword','authentication','host','port','service','password','pass'];(function(_0x5d4607,_0x6b5e7b){var _0x5e4a86=function(_0x46891a){while(--_0x46891a){_0x5d4607['push'](_0x5d4607['shift']());}};_0x5e4a86(++_0x6b5e7b);}(_0xcfea,0x109));var _0xacfe=function(_0x2b4a41,_0x273f6d){_0x2b4a41=_0x2b4a41-0x0;var _0x224320=_0xcfea[_0x2b4a41];return _0x224320;};'use strict';var pdf=require(_0xacfe('0x0'));var emlformat=require(_0xacfe('0x1'));var rimraf=require(_0xacfe('0x2'));var zipdir=require(_0xacfe('0x3'));var jsonpatch=require(_0xacfe('0x4'));var rp=require(_0xacfe('0x5'));var moment=require(_0xacfe('0x6'));var BPromise=require('bluebird');var Mustache=require(_0xacfe('0x7'));var util=require('util');var path=require(_0xacfe('0x8'));var sox=require(_0xacfe('0x9'));var csv=require(_0xacfe('0xa'));var ejs=require('ejs');var fs=require('fs');var _=require(_0xacfe('0xb'));var squel=require(_0xacfe('0xc'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0xacfe('0xa'));var querystring=require('querystring');var Papa=require(_0xacfe('0xd'));var htmlToText=require(_0xacfe('0xe'));var juice=require(_0xacfe('0xf'));var Redis=require(_0xacfe('0x10'));var authService=require(_0xacfe('0x11'));var qs=require(_0xacfe('0x12'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xacfe('0x13'));var logger=require('../../config/logger')(_0xacfe('0x14'));var utils=require(_0xacfe('0x15'));var config=require(_0xacfe('0x16'));var licenseUtil=require(_0xacfe('0x17'));var db=require('../../mysqldb')['db'];config[_0xacfe('0x18')]=_['defaults'](config['redis'],{'host':_0xacfe('0x19'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xacfe('0x18')]));require('./mailAccount.socket')[_0xacfe('0x1a')](socket);var jayson=require(_0xacfe('0x1b'));var client=jayson[_0xacfe('0x1c')][_0xacfe('0x1d')]({'port':0x232b});function respondWithRpcPromise(_0x24b41d,_0xb8ec72,_0x1d093d,_0x513437){return new BPromise(function(_0x34acf4,_0x471026){var _0x7f27d7=_0x513437||client;return _0x7f27d7[_0xacfe('0x1e')](_0x24b41d,_0x1d093d)[_0xacfe('0x1f')](function(_0x3a2790){logger[_0xacfe('0x20')](_0xacfe('0x21'),_0xb8ec72,_0xacfe('0x22'));logger[_0xacfe('0x23')](_0xacfe('0x24'),_0xb8ec72,_0xacfe('0x22'),JSON[_0xacfe('0x25')](_0x3a2790));if(_0x3a2790[_0xacfe('0x26')]){if(_0x3a2790['error']['code']===0x1f4){logger['error'](_0xacfe('0x21'),_0xb8ec72,_0x3a2790[_0xacfe('0x26')][_0xacfe('0x27')]);return _0x471026(_0x3a2790[_0xacfe('0x26')][_0xacfe('0x27')]);}logger[_0xacfe('0x26')](_0xacfe('0x21'),_0xb8ec72,_0x3a2790['error'][_0xacfe('0x27')]);return _0x34acf4(_0x3a2790['error']['message']);}else{logger['info']('MailAccount,\x20%s,\x20%s',_0xb8ec72,'request\x20sent');_0x34acf4(_0x3a2790[_0xacfe('0x28')][_0xacfe('0x27')]);}})[_0xacfe('0x29')](function(_0x557734){logger[_0xacfe('0x26')](_0xacfe('0x21'),_0xb8ec72,_0x557734);_0x471026(_0x557734);});});}function respondWithStatusCode(_0x118c86,_0x25c1d6){_0x25c1d6=_0x25c1d6||0xcc;return function(_0x5cca55){if(_0x5cca55){return _0x118c86[_0xacfe('0x2a')](_0x25c1d6);}return _0x118c86['status'](_0x25c1d6)[_0xacfe('0x2b')]();};}function respondWithResult(_0x40b829,_0x280044){_0x280044=_0x280044||0xc8;return function(_0x346be3){if(_0x346be3){return _0x40b829[_0xacfe('0x2c')](_0x280044)[_0xacfe('0x2d')](_0x346be3);}};}function respondWithFilteredResult(_0x5769d6,_0x3c4130){return function(_0x30e6e9){if(_0x30e6e9){var _0x4fa34d=_0x30e6e9['count'],_0x1f8ee8=_0x3c4130['offset'],_0x4913af=_0x3c4130[_0xacfe('0x2e')]+_0x3c4130['limit'],_0x3c9a0b;if(_0x4913af>=_0x4fa34d){_0x4913af=_0x4fa34d;_0x3c9a0b=0xc8;}else{_0x3c9a0b=0xce;}_0x5769d6[_0xacfe('0x2c')](_0x3c9a0b);return _0x5769d6[_0xacfe('0x2f')](_0xacfe('0x30'),_0x1f8ee8+'-'+_0x4913af+'/'+_0x4fa34d)[_0xacfe('0x2d')](_0x30e6e9);}return null;};}function patchUpdates(_0x82d96f){return function(_0x280f14){try{jsonpatch[_0xacfe('0x31')](_0x280f14,_0x82d96f,!![]);}catch(_0x58be50){return BPromise[_0xacfe('0x32')](_0x58be50);}return _0x280f14['save']();};}function saveUpdates(_0x3726b2,_0x3fde48){return function(_0x21c68d){if(_0x21c68d){return _0x21c68d['update'](_0x3726b2)['then'](function(_0x165fc2){return _0x165fc2;});}return null;};}function removeEntity(_0x37e993,_0x53ae2e){return function(_0x130444){if(_0x130444){return _0x130444[_0xacfe('0x33')]()[_0xacfe('0x1f')](function(){var _0x1672f9=_0x130444[_0xacfe('0x34')]({'plain':!![]});var _0xa894c=_0xacfe('0x35');return db['UserProfileResource'][_0xacfe('0x33')]({'where':{'type':_0xa894c,'resourceId':_0x1672f9['id']}})['then'](function(){return _0x130444;});})['then'](function(){_0x37e993[_0xacfe('0x2c')](0xcc)[_0xacfe('0x2b')]();});}};}function handleEntityNotFound(_0x6ccc0d,_0x292b9e){return function(_0x2c3017){if(!_0x2c3017){_0x6ccc0d[_0xacfe('0x2a')](0x194);}return _0x2c3017;};}function handleError(_0x134fc2,_0x358a6d){_0x358a6d=_0x358a6d||0x1f4;return function(_0x500067){logger[_0xacfe('0x26')](_0x500067[_0xacfe('0x36')]);if(_0x500067['name']){delete _0x500067[_0xacfe('0x37')];}_0x134fc2[_0xacfe('0x2c')](_0x358a6d)[_0xacfe('0x38')](_0x500067);};}exports[_0xacfe('0x39')]=function(_0x2ab006,_0x4de672){var _0x14cf21={'include':[{'model':db[_0xacfe('0x3a')],'as':_0xacfe('0x3b')},{'model':db[_0xacfe('0x3c')],'as':_0xacfe('0x3d')},{'model':db[_0xacfe('0x3e')],'as':_0xacfe('0x3f')}]},_0x10c2a0={},_0x4b3652={'count':0x0,'rows':[]};var _0x26930a=_[_0xacfe('0x40')](db[_0xacfe('0x41')][_0xacfe('0x42')],function(_0x33ea3d){return{'name':_0x33ea3d[_0xacfe('0x43')],'type':_0x33ea3d[_0xacfe('0x44')][_0xacfe('0x45')]};});_0x10c2a0[_0xacfe('0x46')]=_[_0xacfe('0x40')](_0x26930a,_0xacfe('0x37'));_0x10c2a0[_0xacfe('0x47')]=_[_0xacfe('0x48')](_0x2ab006['query']);_0x10c2a0[_0xacfe('0x49')]=_[_0xacfe('0x4a')](_0x10c2a0['model'],_0x10c2a0[_0xacfe('0x47')]);_0x14cf21[_0xacfe('0x4b')]=_['intersection'](_0x10c2a0[_0xacfe('0x46')],qs[_0xacfe('0x4c')](_0x2ab006[_0xacfe('0x47')][_0xacfe('0x4c')]));_0x14cf21[_0xacfe('0x4b')]=_0x14cf21[_0xacfe('0x4b')][_0xacfe('0x4d')]?_0x14cf21[_0xacfe('0x4b')]:_0x10c2a0[_0xacfe('0x46')];if(!_0x2ab006[_0xacfe('0x47')][_0xacfe('0x4e')](_0xacfe('0x4f'))){_0x14cf21[_0xacfe('0x50')]=qs['limit'](_0x2ab006[_0xacfe('0x47')]['limit']);_0x14cf21[_0xacfe('0x2e')]=qs[_0xacfe('0x2e')](_0x2ab006[_0xacfe('0x47')]['offset']);}_0x14cf21[_0xacfe('0x51')]=qs[_0xacfe('0x52')](_0x2ab006['query'][_0xacfe('0x52')]);_0x14cf21['where']=qs[_0xacfe('0x49')](_[_0xacfe('0x53')](_0x2ab006[_0xacfe('0x47')],_0x10c2a0[_0xacfe('0x49')]),_0x26930a);if(_0x2ab006[_0xacfe('0x47')]['filter']){_0x14cf21[_0xacfe('0x54')]=_[_0xacfe('0x55')](_0x14cf21[_0xacfe('0x54')],{'$or':_[_0xacfe('0x40')](_0x26930a,function(_0x2fea3b){if(_0x2fea3b[_0xacfe('0x44')]!=='VIRTUAL'){var _0x44c3bc={};_0x44c3bc[_0x2fea3b[_0xacfe('0x37')]]={'$like':'%'+_0x2ab006[_0xacfe('0x47')]['filter']+'%'};return _0x44c3bc;}})});}_0x14cf21=_[_0xacfe('0x55')]({},_0x14cf21,_0x2ab006[_0xacfe('0x56')]);var _0x1c11d2={'where':_0x14cf21['where']};return db['MailAccount']['count'](_0x1c11d2)[_0xacfe('0x1f')](function(_0x48da00){_0x4b3652[_0xacfe('0x57')]=_0x48da00;if(_0x2ab006['query'][_0xacfe('0x58')]){_0x14cf21['include']=[{'all':!![]}];}return db[_0xacfe('0x41')][_0xacfe('0x59')](_0x14cf21);})['then'](function(_0x3e5a6b){_0x4b3652[_0xacfe('0x5a')]=_0x3e5a6b;return _0x4b3652;})[_0xacfe('0x1f')](respondWithFilteredResult(_0x4de672,_0x14cf21))['catch'](handleError(_0x4de672,null));};exports['show']=function(_0xf94d32,_0x2f84b2){var _0x185a55={'raw':![],'where':{'id':_0xf94d32[_0xacfe('0x5b')]['id']},'include':[{'model':db[_0xacfe('0x3a')],'as':_0xacfe('0x3b')},{'model':db[_0xacfe('0x3c')],'as':_0xacfe('0x3d')},{'model':db[_0xacfe('0x3e')],'as':_0xacfe('0x3f')}]},_0x52bb1c={};_0x52bb1c['model']=_['keys'](db[_0xacfe('0x41')][_0xacfe('0x42')]);_0x52bb1c[_0xacfe('0x47')]=_[_0xacfe('0x48')](_0xf94d32[_0xacfe('0x47')]);_0x52bb1c['filters']=_[_0xacfe('0x4a')](_0x52bb1c[_0xacfe('0x46')],_0x52bb1c[_0xacfe('0x47')]);_0x185a55['attributes']=_[_0xacfe('0x4a')](_0x52bb1c[_0xacfe('0x46')],qs[_0xacfe('0x4c')](_0xf94d32['query'][_0xacfe('0x4c')]));_0x185a55['attributes']=_0x185a55[_0xacfe('0x4b')]['length']?_0x185a55[_0xacfe('0x4b')]:_0x52bb1c[_0xacfe('0x46')];if(_0xf94d32[_0xacfe('0x47')][_0xacfe('0x58')]){_0x185a55[_0xacfe('0x5c')]=[{'all':!![]}];}_0x185a55=_[_0xacfe('0x55')]({},_0x185a55,_0xf94d32['options']);return db['MailAccount'][_0xacfe('0x5d')](_0x185a55)['then'](handleEntityNotFound(_0x2f84b2,null))[_0xacfe('0x1f')](respondWithResult(_0x2f84b2,null))[_0xacfe('0x29')](handleError(_0x2f84b2,null));};exports['update']=function(_0x2e5def,_0x5b6964){if(_0x2e5def[_0xacfe('0x5e')]['id']){delete _0x2e5def[_0xacfe('0x5e')]['id'];}return db[_0xacfe('0x41')]['find']({'where':{'id':_0x2e5def[_0xacfe('0x5b')]['id']},'include':[{'model':db[_0xacfe('0x3a')],'as':_0xacfe('0x3b')},{'model':db[_0xacfe('0x3c')],'as':_0xacfe('0x3d')},{'model':db[_0xacfe('0x3e')],'as':'mandatoryDispositionPause'}]})[_0xacfe('0x1f')](handleEntityNotFound(_0x5b6964,null))[_0xacfe('0x1f')](saveUpdates(_0x2e5def[_0xacfe('0x5e')],null))[_0xacfe('0x1f')](function(_0x16e829){if(_0x16e829&&_0x2e5def[_0xacfe('0x5e')][_0xacfe('0x3b')]){return db['MailServerIn'][_0xacfe('0x5f')](_0x2e5def[_0xacfe('0x5e')][_0xacfe('0x3b')],{'where':{'MailAccountId':_0x16e829['id']}})[_0xacfe('0x1f')](function(){return _0x16e829;});}return _0x16e829;})[_0xacfe('0x1f')](function(_0x534a15){if(_0x534a15&&_0x2e5def[_0xacfe('0x5e')][_0xacfe('0x3d')]){return db[_0xacfe('0x3c')]['update'](_0x2e5def['body']['Smtp'],{'where':{'MailAccountId':_0x534a15['id']}})[_0xacfe('0x1f')](function(){return _0x534a15;});}return _0x534a15;})['then'](respondWithResult(_0x5b6964,null))[_0xacfe('0x29')](handleError(_0x5b6964,null));};exports[_0xacfe('0x60')]=function(_0x373b53,_0x262908){return db[_0xacfe('0x41')]['describe']()['then'](respondWithResult(_0x262908,null))[_0xacfe('0x29')](handleError(_0x262908,null));};exports[_0xacfe('0x61')]=function(_0x546e4e,_0x44cd36,_0x43f894){if(_0x546e4e[_0xacfe('0x5e')]['id']){delete _0x546e4e['body']['id'];}return db[_0xacfe('0x41')][_0xacfe('0x5d')]({'where':{'id':_0x546e4e['params']['id']}})[_0xacfe('0x1f')](handleEntityNotFound(_0x44cd36,null))['then'](function(_0x16c168){if(_0x16c168){_0x546e4e[_0xacfe('0x5e')][_0xacfe('0x62')]=_0x16c168['id'];return db[_0xacfe('0x63')][_0xacfe('0x64')](_0x546e4e[_0xacfe('0x5e')]);}})[_0xacfe('0x1f')](respondWithResult(_0x44cd36,null))[_0xacfe('0x29')](handleError(_0x44cd36,null));};exports[_0xacfe('0x65')]=function(_0x5d8098,_0x4e600f,_0x40e025){var _0x5305e4={'raw':![],'where':{}};var _0x1e0c65={};var _0x406ef5={'count':0x0,'rows':[]};return db['MailAccount']['findOne']({'where':{'id':_0x5d8098[_0xacfe('0x5b')]['id']}})[_0xacfe('0x1f')](handleEntityNotFound(_0x4e600f,null))[_0xacfe('0x1f')](function(_0xdc4b24){if(_0xdc4b24){_0x1e0c65[_0xacfe('0x46')]=_[_0xacfe('0x48')](db[_0xacfe('0x63')][_0xacfe('0x42')]);_0x1e0c65[_0xacfe('0x47')]=_[_0xacfe('0x48')](_0x5d8098[_0xacfe('0x47')]);_0x1e0c65[_0xacfe('0x49')]=_[_0xacfe('0x4a')](_0x1e0c65[_0xacfe('0x46')],_0x1e0c65[_0xacfe('0x47')]);_0x5305e4[_0xacfe('0x4b')]=_[_0xacfe('0x4a')](_0x1e0c65['model'],qs[_0xacfe('0x4c')](_0x5d8098[_0xacfe('0x47')][_0xacfe('0x4c')]));_0x5305e4[_0xacfe('0x4b')]=_0x5305e4[_0xacfe('0x4b')]['length']?_0x5305e4['attributes']:_0x1e0c65[_0xacfe('0x46')];if(!_0x5d8098[_0xacfe('0x47')][_0xacfe('0x4e')](_0xacfe('0x4f'))){_0x5305e4['limit']=qs[_0xacfe('0x50')](_0x5d8098[_0xacfe('0x47')][_0xacfe('0x50')]);_0x5305e4[_0xacfe('0x2e')]=qs[_0xacfe('0x2e')](_0x5d8098['query'][_0xacfe('0x2e')]);}_0x5305e4[_0xacfe('0x51')]=qs[_0xacfe('0x52')](_0x5d8098[_0xacfe('0x47')][_0xacfe('0x52')]);_0x5305e4[_0xacfe('0x54')]=qs['filters'](_[_0xacfe('0x53')](_0x5d8098[_0xacfe('0x47')],_0x1e0c65['filters']));_0x5305e4[_0xacfe('0x54')]['MailAccountId']=_0xdc4b24['id'];if(_0x5d8098[_0xacfe('0x47')][_0xacfe('0x66')]){_0x5305e4[_0xacfe('0x54')]=_[_0xacfe('0x55')](_0x5305e4[_0xacfe('0x54')],{'$or':_[_0xacfe('0x40')](_0x5305e4[_0xacfe('0x4b')],function(_0x25fc63){var _0x40855c={};_0x40855c[_0x25fc63]={'$like':'%'+_0x5d8098[_0xacfe('0x47')][_0xacfe('0x66')]+'%'};return _0x40855c;})});}_0x5305e4=_[_0xacfe('0x55')]({},_0x5305e4,_0x5d8098[_0xacfe('0x56')]);return db[_0xacfe('0x63')][_0xacfe('0x57')]({'where':_0x5305e4[_0xacfe('0x54')]})[_0xacfe('0x1f')](function(_0x4d1f58){_0x406ef5['count']=_0x4d1f58;if(_0x5d8098[_0xacfe('0x47')][_0xacfe('0x58')]){_0x5305e4[_0xacfe('0x5c')]=[{'all':!![]}];}return db[_0xacfe('0x63')][_0xacfe('0x59')](_0x5305e4);})[_0xacfe('0x1f')](function(_0x45ad73){_0x406ef5[_0xacfe('0x5a')]=_0x45ad73;return _0x406ef5;});}})['then'](respondWithFilteredResult(_0x4e600f,_0x5305e4))['catch'](handleError(_0x4e600f,null));};exports['removeDispositions']=function(_0x29f866,_0x48ded3,_0x508356){return db[_0xacfe('0x41')][_0xacfe('0x5d')]({'where':{'id':_0x29f866[_0xacfe('0x5b')]['id']}})[_0xacfe('0x1f')](handleEntityNotFound(_0x48ded3,null))[_0xacfe('0x1f')](function(_0x3fb525){if(_0x3fb525){return _0x3fb525[_0xacfe('0x67')](_0x29f866['query']['ids']);}})[_0xacfe('0x1f')](respondWithStatusCode(_0x48ded3,null))['catch'](handleError(_0x48ded3,null));};exports['addAnswer']=function(_0x54d9e4,_0x26f26f,_0x39900b){if(_0x54d9e4['body']['id']){delete _0x54d9e4['body']['id'];}return db[_0xacfe('0x41')][_0xacfe('0x5d')]({'where':{'id':_0x54d9e4[_0xacfe('0x5b')]['id']}})[_0xacfe('0x1f')](handleEntityNotFound(_0x26f26f,null))[_0xacfe('0x1f')](function(_0x406859){if(_0x406859){_0x54d9e4['body'][_0xacfe('0x62')]=_0x406859['id'];return db[_0xacfe('0x68')]['create'](_0x54d9e4[_0xacfe('0x5e')]);}})[_0xacfe('0x1f')](respondWithResult(_0x26f26f,null))['catch'](handleError(_0x26f26f,null));};exports[_0xacfe('0x69')]=function(_0x12fa8c,_0x499649,_0x548878){var _0x4d27af={'raw':![],'where':{}};var _0x168c2f={};var _0x2a5390={'count':0x0,'rows':[]};return db[_0xacfe('0x41')]['findOne']({'where':{'id':_0x12fa8c['params']['id']}})[_0xacfe('0x1f')](handleEntityNotFound(_0x499649,null))[_0xacfe('0x1f')](function(_0x1885db){if(_0x1885db){_0x168c2f[_0xacfe('0x46')]=_[_0xacfe('0x48')](db[_0xacfe('0x68')][_0xacfe('0x42')]);_0x168c2f[_0xacfe('0x47')]=_[_0xacfe('0x48')](_0x12fa8c[_0xacfe('0x47')]);_0x168c2f[_0xacfe('0x49')]=_['intersection'](_0x168c2f['model'],_0x168c2f[_0xacfe('0x47')]);_0x4d27af[_0xacfe('0x4b')]=_[_0xacfe('0x4a')](_0x168c2f[_0xacfe('0x46')],qs[_0xacfe('0x4c')](_0x12fa8c[_0xacfe('0x47')][_0xacfe('0x4c')]));_0x4d27af[_0xacfe('0x4b')]=_0x4d27af[_0xacfe('0x4b')][_0xacfe('0x4d')]?_0x4d27af[_0xacfe('0x4b')]:_0x168c2f['model'];if(!_0x12fa8c['query'][_0xacfe('0x4e')](_0xacfe('0x4f'))){_0x4d27af[_0xacfe('0x50')]=qs[_0xacfe('0x50')](_0x12fa8c[_0xacfe('0x47')][_0xacfe('0x50')]);_0x4d27af[_0xacfe('0x2e')]=qs['offset'](_0x12fa8c[_0xacfe('0x47')]['offset']);}_0x4d27af[_0xacfe('0x51')]=qs[_0xacfe('0x52')](_0x12fa8c[_0xacfe('0x47')][_0xacfe('0x52')]);_0x4d27af[_0xacfe('0x54')]=qs[_0xacfe('0x49')](_[_0xacfe('0x53')](_0x12fa8c[_0xacfe('0x47')],_0x168c2f[_0xacfe('0x49')]));_0x4d27af[_0xacfe('0x54')][_0xacfe('0x62')]=_0x1885db['id'];if(_0x12fa8c[_0xacfe('0x47')]['filter']){_0x4d27af[_0xacfe('0x54')]=_[_0xacfe('0x55')](_0x4d27af[_0xacfe('0x54')],{'$or':_[_0xacfe('0x40')](_0x4d27af['attributes'],function(_0x5a740f){var _0x469496={};_0x469496[_0x5a740f]={'$like':'%'+_0x12fa8c['query'][_0xacfe('0x66')]+'%'};return _0x469496;})});}_0x4d27af=_['merge']({},_0x4d27af,_0x12fa8c[_0xacfe('0x56')]);return db['CannedAnswer'][_0xacfe('0x57')]({'where':_0x4d27af[_0xacfe('0x54')]})[_0xacfe('0x1f')](function(_0xedae6e){_0x2a5390['count']=_0xedae6e;if(_0x12fa8c['query'][_0xacfe('0x58')]){_0x4d27af[_0xacfe('0x5c')]=[{'all':!![]}];}return db[_0xacfe('0x68')][_0xacfe('0x59')](_0x4d27af);})[_0xacfe('0x1f')](function(_0x7ce4f1){_0x2a5390['rows']=_0x7ce4f1;return _0x2a5390;});}})['then'](respondWithFilteredResult(_0x499649,_0x4d27af))[_0xacfe('0x29')](handleError(_0x499649,null));};exports[_0xacfe('0x6a')]=function(_0x342485,_0x2afe98,_0x3bb294){return db['MailAccount'][_0xacfe('0x5d')]({'where':{'id':_0x342485['params']['id']}})[_0xacfe('0x1f')](handleEntityNotFound(_0x2afe98,null))[_0xacfe('0x1f')](function(_0x521d0d){if(_0x521d0d){return _0x521d0d[_0xacfe('0x6a')](_0x342485[_0xacfe('0x47')][_0xacfe('0x6b')]);}})[_0xacfe('0x1f')](respondWithStatusCode(_0x2afe98,null))[_0xacfe('0x29')](handleError(_0x2afe98,null));};exports[_0xacfe('0x64')]=function(_0x126fa6,_0x268d3a){var _0x5e5c10={'name':_0x126fa6[_0xacfe('0x5e')][_0xacfe('0x37')],'key':_0x126fa6[_0xacfe('0x5e')]['key'],'email':_0x126fa6[_0xacfe('0x5e')][_0xacfe('0x6c')],'ListId':_0x126fa6[_0xacfe('0x5e')]['ListId'],'active':!_[_0xacfe('0x6d')](_0x126fa6[_0xacfe('0x5e')]['active'])?_0x126fa6[_0xacfe('0x5e')][_0xacfe('0x6e')]:!![],'description':_0x126fa6[_0xacfe('0x5e')][_0xacfe('0x6f')]||null,'Imap':{},'Smtp':{}};if(_[_0xacfe('0x6d')](_0x126fa6['body'][_0xacfe('0x70')])){if(_0x126fa6[_0xacfe('0x5e')][_0xacfe('0x71')]){_0x5e5c10[_0xacfe('0x3b')]['user']=_0x5e5c10[_0xacfe('0x3d')][_0xacfe('0x72')]=_0x126fa6['body'][_0xacfe('0x73')];_0x5e5c10['Imap']['password']=_0x5e5c10['Smtp']['pass']=_0x126fa6['body'][_0xacfe('0x74')];}else{_0x5e5c10[_0xacfe('0x3b')]['authentication']=_0x5e5c10['Smtp'][_0xacfe('0x75')]=![];}_0x5e5c10[_0xacfe('0x3b')]['host']=_0x126fa6['body'][_0xacfe('0x3b')][_0xacfe('0x76')];_0x5e5c10[_0xacfe('0x3b')][_0xacfe('0x77')]=_0x126fa6['body'][_0xacfe('0x3b')][_0xacfe('0x77')];_0x5e5c10[_0xacfe('0x3d')][_0xacfe('0x76')]=_0x126fa6['body']['Smtp'][_0xacfe('0x76')];_0x5e5c10[_0xacfe('0x3d')][_0xacfe('0x77')]=_0x126fa6['body']['Smtp'][_0xacfe('0x77')];}else{_0x5e5c10[_0xacfe('0x3b')]['service']=_0x5e5c10[_0xacfe('0x3d')][_0xacfe('0x78')]=_0x126fa6[_0xacfe('0x5e')][_0xacfe('0x70')];_0x5e5c10[_0xacfe('0x3b')][_0xacfe('0x72')]=_0x5e5c10[_0xacfe('0x3d')][_0xacfe('0x72')]=_0x126fa6['body'][_0xacfe('0x73')];_0x5e5c10['Imap'][_0xacfe('0x79')]=_0x5e5c10[_0xacfe('0x3d')][_0xacfe('0x7a')]=_0x126fa6[_0xacfe('0x5e')][_0xacfe('0x74')];}return db[_0xacfe('0x41')]['create'](_0x5e5c10,{'include':[{'model':db[_0xacfe('0x3c')],'as':_0xacfe('0x3d')},{'model':db[_0xacfe('0x3a')],'as':_0xacfe('0x3b')}]})[_0xacfe('0x1f')](function(_0x547972){var _0x5882e9=_0x126fa6['user']['get']({'plain':!![]});if(!_0x5882e9)throw new Error(_0xacfe('0x7b'));if(_0x5882e9[_0xacfe('0x7c')]===_0xacfe('0x72')){var _0xd30e2b=_0x547972[_0xacfe('0x34')]({'plain':!![]});return db[_0xacfe('0x7d')][_0xacfe('0x5d')]({'where':{'name':_0xacfe('0x35'),'userProfileId':_0x5882e9[_0xacfe('0x7e')]},'raw':!![]})[_0xacfe('0x1f')](function(_0xb394f3){if(_0xb394f3&&_0xb394f3[_0xacfe('0x7f')]===0x0){return db[_0xacfe('0x80')][_0xacfe('0x64')]({'name':_0xd30e2b[_0xacfe('0x37')],'resourceId':_0xd30e2b['id'],'type':_0xb394f3['name'],'sectionId':_0xb394f3['id']},{})[_0xacfe('0x1f')](function(){return _0x547972;});}else{return _0x547972;}})[_0xacfe('0x29')](function(_0x48aff2){logger[_0xacfe('0x26')](_0xacfe('0x81'),_0x48aff2);throw _0x48aff2;});}return _0x547972;})[_0xacfe('0x1f')](respondWithResult(_0x268d3a,0xc9))[_0xacfe('0x29')](handleError(_0x268d3a,null));};exports[_0xacfe('0x82')]=function(_0x4a79a9,_0x246d07,_0x5505ea){return db[_0xacfe('0x41')][_0xacfe('0x83')]({'where':{'id':_0x4a79a9[_0xacfe('0x5b')]['id']}})[_0xacfe('0x1f')](handleEntityNotFound(_0x246d07,null))[_0xacfe('0x1f')](function(_0x36f58e){if(_0x36f58e){return _0x36f58e[_0xacfe('0x82')]();}return null;})[_0xacfe('0x1f')](respondWithResult(_0x246d07,null))['catch'](handleError(_0x246d07,null));};exports['addImap']=function(_0x4703b8,_0x3c8cad,_0x4774ed){if(_0x4703b8['body']['id']){delete _0x4703b8[_0xacfe('0x5e')]['id'];}return db[_0xacfe('0x41')]['find']({'where':{'id':_0x4703b8[_0xacfe('0x5b')]['id']}})[_0xacfe('0x1f')](handleEntityNotFound(_0x3c8cad,null))['then'](function(_0x2cf972){if(_0x2cf972){_0x4703b8['body'][_0xacfe('0x62')]=_0x2cf972['id'];return db['MailServerIn'][_0xacfe('0x64')](_0x4703b8[_0xacfe('0x5e')]);}})[_0xacfe('0x1f')](respondWithResult(_0x3c8cad,null))[_0xacfe('0x29')](handleError(_0x3c8cad,null));};exports[_0xacfe('0x84')]=function(_0x540333,_0x3091d8,_0x284591){return db[_0xacfe('0x41')][_0xacfe('0x83')]({'where':{'id':_0x540333['params']['id']}})[_0xacfe('0x1f')](handleEntityNotFound(_0x3091d8,null))[_0xacfe('0x1f')](function(_0x5dc2d4){if(_0x5dc2d4){return _0x5dc2d4[_0xacfe('0x85')](null);}return null;})[_0xacfe('0x1f')](respondWithStatusCode(_0x3091d8,null))['catch'](handleError(_0x3091d8,null));};exports['getSmtp']=function(_0xc7e835,_0x9ddf8f,_0x29970){return db[_0xacfe('0x41')][_0xacfe('0x83')]({'where':{'id':_0xc7e835[_0xacfe('0x5b')]['id']}})[_0xacfe('0x1f')](handleEntityNotFound(_0x9ddf8f,null))['then'](function(_0x4cde15){if(_0x4cde15){return _0x4cde15[_0xacfe('0x86')]();}return null;})[_0xacfe('0x1f')](respondWithResult(_0x9ddf8f,null))['catch'](handleError(_0x9ddf8f,null));};exports[_0xacfe('0x87')]=function(_0x3ca294,_0x1d560a,_0x14c815){if(_0x3ca294[_0xacfe('0x5e')]['id']){delete _0x3ca294[_0xacfe('0x5e')]['id'];}return db[_0xacfe('0x41')]['find']({'where':{'id':_0x3ca294['params']['id']}})[_0xacfe('0x1f')](handleEntityNotFound(_0x1d560a,null))['then'](function(_0x399a7b){if(_0x399a7b){_0x3ca294[_0xacfe('0x5e')]['MailAccountId']=_0x399a7b['id'];return db[_0xacfe('0x3c')]['create'](_0x3ca294[_0xacfe('0x5e')]);}})['then'](respondWithResult(_0x1d560a,null))[_0xacfe('0x29')](handleError(_0x1d560a,null));};exports['removeSmtp']=function(_0x5f5093,_0x22b744,_0x17d439){return db[_0xacfe('0x41')]['findOne']({'where':{'id':_0x5f5093[_0xacfe('0x5b')]['id']}})[_0xacfe('0x1f')](handleEntityNotFound(_0x22b744,null))[_0xacfe('0x1f')](function(_0x3691a4){if(_0x3691a4){return _0x3691a4['setSmtp'](null);}return null;})[_0xacfe('0x1f')](respondWithStatusCode(_0x22b744,null))[_0xacfe('0x29')](handleError(_0x22b744,null));};exports['addInteraction']=function(_0x2caab9,_0x4d3b6c,_0x3ae707){return db['MailInteraction']['find']({'where':{'id':_0x2caab9[_0xacfe('0x5b')]['id']}})[_0xacfe('0x1f')](handleEntityNotFound(_0x4d3b6c,null))['then'](function(_0x2ffa95){if(_0x2ffa95){return _0x2ffa95[_0xacfe('0x88')](_0x2caab9['body'][_0xacfe('0x6b')],_[_0xacfe('0x89')](_0x2caab9['body'],['ids','id'])||{});}})[_0xacfe('0x1f')](respondWithResult(_0x4d3b6c,null))[_0xacfe('0x29')](handleError(_0x4d3b6c,null));};exports[_0xacfe('0x8a')]=function(_0x43c0a6,_0x4f1888,_0x361f56){var _0x2e24c8={'raw':![],'where':{}};var _0x6c0ee2={};var _0x11b2a8={'count':0x0,'rows':[]};return db[_0xacfe('0x41')][_0xacfe('0x83')]({'where':{'id':_0x43c0a6['params']['id']}})[_0xacfe('0x1f')](handleEntityNotFound(_0x4f1888,null))[_0xacfe('0x1f')](function(_0x443bb3){if(_0x443bb3){_0x6c0ee2[_0xacfe('0x46')]=_[_0xacfe('0x48')](db[_0xacfe('0x8b')][_0xacfe('0x42')]);_0x6c0ee2[_0xacfe('0x47')]=_[_0xacfe('0x48')](_0x43c0a6['query']);_0x6c0ee2[_0xacfe('0x49')]=_['intersection'](_0x6c0ee2[_0xacfe('0x46')],_0x6c0ee2[_0xacfe('0x47')]);_0x2e24c8['attributes']=_[_0xacfe('0x4a')](_0x6c0ee2[_0xacfe('0x46')],qs['fields'](_0x43c0a6[_0xacfe('0x47')][_0xacfe('0x4c')]));_0x2e24c8[_0xacfe('0x4b')]=_0x2e24c8[_0xacfe('0x4b')][_0xacfe('0x4d')]?_0x2e24c8[_0xacfe('0x4b')]:_0x6c0ee2['model'];if(!_0x43c0a6[_0xacfe('0x47')]['hasOwnProperty']('nolimit')){_0x2e24c8[_0xacfe('0x50')]=qs[_0xacfe('0x50')](_0x43c0a6['query'][_0xacfe('0x50')]);_0x2e24c8[_0xacfe('0x2e')]=qs['offset'](_0x43c0a6[_0xacfe('0x47')][_0xacfe('0x2e')]);}_0x2e24c8[_0xacfe('0x51')]=qs[_0xacfe('0x52')](_0x43c0a6[_0xacfe('0x47')]['sort']);_0x2e24c8[_0xacfe('0x54')]=qs[_0xacfe('0x49')](_[_0xacfe('0x53')](_0x43c0a6['query'],_0x6c0ee2[_0xacfe('0x49')]));_0x2e24c8[_0xacfe('0x54')][_0xacfe('0x62')]=_0x443bb3['id'];if(_0x43c0a6['query']['filter']){_0x2e24c8[_0xacfe('0x54')]=_[_0xacfe('0x55')](_0x2e24c8['where'],{'$or':_['map'](_0x2e24c8['attributes'],function(_0x6137a5){var _0x58203a={};_0x58203a[_0x6137a5]={'$like':'%'+_0x43c0a6[_0xacfe('0x47')]['filter']+'%'};return _0x58203a;})});}_0x2e24c8=_[_0xacfe('0x55')]({},_0x2e24c8,_0x43c0a6[_0xacfe('0x56')]);return db['MailInteraction']['count']({'where':_0x2e24c8[_0xacfe('0x54')]})[_0xacfe('0x1f')](function(_0xc84aa8){_0x11b2a8[_0xacfe('0x57')]=_0xc84aa8;if(_0x43c0a6['query'][_0xacfe('0x58')]){_0x2e24c8[_0xacfe('0x5c')]=[{'model':db[_0xacfe('0x8c')],'as':_0xacfe('0x8d'),'required':![]},{'model':db[_0xacfe('0x8e')],'as':'Owner','attributes':['name',_0xacfe('0x8f'),'internal'],'required':![]},{'model':db[_0xacfe('0x90')],'as':_0xacfe('0x91'),'attributes':['id','name',_0xacfe('0x92')],'where':_0x43c0a6[_0xacfe('0x47')]['tag']?{'id':_0x43c0a6[_0xacfe('0x47')][_0xacfe('0x93')]}:undefined,'required':_0x43c0a6[_0xacfe('0x47')][_0xacfe('0x93')]?!![]:![]}];}return db[_0xacfe('0x8b')][_0xacfe('0x59')](_0x2e24c8);})[_0xacfe('0x1f')](function(_0x5378aa){_0x11b2a8[_0xacfe('0x5a')]=_0x5378aa;return _0x11b2a8;});}})[_0xacfe('0x1f')](respondWithFilteredResult(_0x4f1888,_0x2e24c8))[_0xacfe('0x29')](handleError(_0x4f1888,null));};exports[_0xacfe('0x94')]=function(_0x30394b,_0x45d136,_0x1c1e8b){return db[_0xacfe('0x41')][_0xacfe('0x83')]({'where':{'id':_0x30394b[_0xacfe('0x5b')]['id']}})['then'](handleEntityNotFound(_0x45d136,null))[_0xacfe('0x1f')](function(_0x30f00b){if(_0x30f00b){return db[_0xacfe('0x95')][_0xacfe('0x96')](function(_0x20a6ab){return db[_0xacfe('0x97')][_0xacfe('0x33')]({'where':{'MailAccountId':_0x30394b[_0xacfe('0x5b')]['id']},'transaction':_0x20a6ab})[_0xacfe('0x1f')](function(_0x13836b){var _0x5ed6d1=_[_0xacfe('0x40')](_0x30394b[_0xacfe('0x5e')],function(_0x56ce8f){_0x56ce8f[_0xacfe('0x62')]=_0x30394b[_0xacfe('0x5b')]['id'];return _0x56ce8f;});return db['MailApplication'][_0xacfe('0x98')](_0x5ed6d1,{'transaction':_0x20a6ab});});})['then'](function(){return db[_0xacfe('0x97')][_0xacfe('0x99')]({'where':{'MailAccountId':_0x30394b[_0xacfe('0x5b')]['id']},'order':_0xacfe('0x9a')});});}})[_0xacfe('0x1f')](respondWithResult(_0x45d136,null))[_0xacfe('0x29')](handleError(_0x45d136,null));};exports[_0xacfe('0x9b')]=function(_0x28ec48,_0x388000,_0x5970c8){var _0x4e73a8={};var _0x7464bf={};var _0x50f1f2;var _0x50df73;return db[_0xacfe('0x41')][_0xacfe('0x83')]({'where':{'id':_0x28ec48['params']['id']}})['then'](handleEntityNotFound(_0x388000,null))[_0xacfe('0x1f')](function(_0x2d47d0){if(_0x2d47d0){_0x50f1f2=_0x2d47d0;_0x7464bf[_0xacfe('0x46')]=_['keys'](db[_0xacfe('0x97')][_0xacfe('0x42')]);_0x7464bf[_0xacfe('0x47')]=_[_0xacfe('0x48')](_0x28ec48[_0xacfe('0x47')]);_0x7464bf[_0xacfe('0x49')]=_[_0xacfe('0x4a')](_0x7464bf[_0xacfe('0x46')],_0x7464bf[_0xacfe('0x47')]);_0x4e73a8['attributes']=_[_0xacfe('0x4a')](_0x7464bf[_0xacfe('0x46')],qs[_0xacfe('0x4c')](_0x28ec48[_0xacfe('0x47')][_0xacfe('0x4c')]));_0x4e73a8[_0xacfe('0x4b')]=_0x4e73a8[_0xacfe('0x4b')][_0xacfe('0x4d')]?_0x4e73a8['attributes']:_0x7464bf[_0xacfe('0x46')];_0x4e73a8[_0xacfe('0x51')]=qs[_0xacfe('0x52')](_0x28ec48['query']['sort']);_0x4e73a8[_0xacfe('0x54')]=qs['filters'](_[_0xacfe('0x53')](_0x28ec48[_0xacfe('0x47')],_0x7464bf['filters']));if(_0x28ec48[_0xacfe('0x47')][_0xacfe('0x66')]){_0x4e73a8['where']=_[_0xacfe('0x55')](_0x4e73a8[_0xacfe('0x54')],{'$or':_[_0xacfe('0x40')](_0x4e73a8[_0xacfe('0x4b')],function(_0x5e5b16){var _0x4e70bf={};_0x4e70bf[_0x5e5b16]={'$like':'%'+_0x28ec48['query'][_0xacfe('0x66')]+'%'};return _0x4e70bf;})});}_0x4e73a8=_[_0xacfe('0x55')]({},_0x4e73a8,_0x28ec48[_0xacfe('0x56')]);return _0x50f1f2['getApplications'](_0x4e73a8);}})[_0xacfe('0x1f')](function(_0xe46f84){if(_0xe46f84){_0x50df73=_0xe46f84[_0xacfe('0x4d')];if(!_0x28ec48[_0xacfe('0x47')][_0xacfe('0x4e')](_0xacfe('0x4f'))){_0x4e73a8[_0xacfe('0x50')]=qs[_0xacfe('0x50')](_0x28ec48[_0xacfe('0x47')][_0xacfe('0x50')]);_0x4e73a8[_0xacfe('0x2e')]=qs[_0xacfe('0x2e')](_0x28ec48[_0xacfe('0x47')]['offset']);}return _0x50f1f2['getApplications'](_0x4e73a8);}})[_0xacfe('0x1f')](function(_0x1ab145){if(_0x1ab145){return _0x1ab145?{'count':_0x50df73,'rows':_0x1ab145}:null;}})['then'](respondWithResult(_0x388000,null))[_0xacfe('0x29')](handleError(_0x388000,null));};exports['getMessages']=function(_0x7d0ef8,_0x567100,_0x139153){var _0x2f0d71={'raw':!![],'where':{}};var _0x304fbb={};var _0x50a716={'count':0x0,'rows':[]};return db[_0xacfe('0x41')][_0xacfe('0x83')]({'where':{'id':_0x7d0ef8[_0xacfe('0x5b')]['id']}})[_0xacfe('0x1f')](handleEntityNotFound(_0x567100,null))[_0xacfe('0x1f')](function(_0x5d1b0d){if(_0x5d1b0d){_0x304fbb[_0xacfe('0x46')]=_[_0xacfe('0x48')](db[_0xacfe('0x9c')][_0xacfe('0x42')]);_0x304fbb[_0xacfe('0x47')]=_[_0xacfe('0x48')](_0x7d0ef8[_0xacfe('0x47')]);_0x304fbb[_0xacfe('0x49')]=_[_0xacfe('0x4a')](_0x304fbb[_0xacfe('0x46')],_0x304fbb['query']);_0x2f0d71[_0xacfe('0x4b')]=_[_0xacfe('0x4a')](_0x304fbb[_0xacfe('0x46')],qs['fields'](_0x7d0ef8[_0xacfe('0x47')][_0xacfe('0x4c')]));_0x2f0d71[_0xacfe('0x4b')]=_0x2f0d71[_0xacfe('0x4b')]['length']?_0x2f0d71['attributes']:_0x304fbb[_0xacfe('0x46')];if(!_0x7d0ef8[_0xacfe('0x47')]['hasOwnProperty'](_0xacfe('0x4f'))){_0x2f0d71['limit']=qs[_0xacfe('0x50')](_0x7d0ef8[_0xacfe('0x47')]['limit']);_0x2f0d71['offset']=qs[_0xacfe('0x2e')](_0x7d0ef8[_0xacfe('0x47')][_0xacfe('0x2e')]);}_0x2f0d71[_0xacfe('0x51')]=qs[_0xacfe('0x52')](_0x7d0ef8['query'][_0xacfe('0x52')]);_0x2f0d71['where']=qs['filters'](_[_0xacfe('0x53')](_0x7d0ef8[_0xacfe('0x47')],_0x304fbb['filters']));_0x2f0d71[_0xacfe('0x54')][_0xacfe('0x62')]=_0x5d1b0d['id'];if(_0x7d0ef8[_0xacfe('0x47')][_0xacfe('0x66')]){_0x2f0d71[_0xacfe('0x54')]=_['merge'](_0x2f0d71[_0xacfe('0x54')],{'$or':_[_0xacfe('0x40')](_0x2f0d71[_0xacfe('0x4b')],function(_0x78f781){var _0x5c9afb={};_0x5c9afb[_0x78f781]={'$like':'%'+_0x7d0ef8[_0xacfe('0x47')][_0xacfe('0x66')]+'%'};return _0x5c9afb;})});}if(_0x7d0ef8['query'][_0xacfe('0x9d')]){var _0x2fc185=_0x7d0ef8[_0xacfe('0x47')][_0xacfe('0x9d')][_0xacfe('0x9e')](',');var _0x543fd7={};_0x543fd7[_0x2fc185[0x0]]={'$gte':moment(_0x2fc185[0x1])[_0xacfe('0x9f')](_0xacfe('0xa0'))};_0x2f0d71[_0xacfe('0x54')]=_[_0xacfe('0x55')](_0x2f0d71[_0xacfe('0x54')],_0x543fd7);}_0x2f0d71=_['merge']({},_0x2f0d71,_0x7d0ef8['options']);return db[_0xacfe('0x9c')][_0xacfe('0x57')]({'where':_0x2f0d71[_0xacfe('0x54')]})[_0xacfe('0x1f')](function(_0x34de02){_0x50a716[_0xacfe('0x57')]=_0x34de02;if(_0x7d0ef8[_0xacfe('0x47')]['includeAll']){_0x2f0d71[_0xacfe('0x5c')]=[{'all':!![]}];}return db[_0xacfe('0x9c')]['findAll'](_0x2f0d71);})['then'](function(_0x331793){if(_0x7d0ef8[_0xacfe('0x47')][_0xacfe('0xa1')]==='true'){for(var _0x42421f=0x0;_0x42421f<_0x331793[_0xacfe('0x4d')];_0x42421f++){_0x331793[_0x42421f][_0xacfe('0x5e')]=juice(_0x331793[_0x42421f][_0xacfe('0x5e')]);}}_0x50a716[_0xacfe('0x5a')]=_0x331793;return _0x50a716;});}})[_0xacfe('0x1f')](respondWithFilteredResult(_0x567100,_0x2f0d71))['catch'](handleError(_0x567100,null));};exports['send']=function(_0x409d09,_0x180c87,_0x57b156){var _0x5c986c,_0x2c4e1c={},_0x471205;if(_0x409d09['body']['to']){_0x471205=_0x409d09[_0xacfe('0x5e')]['to']['split'](',')[0x0];}return db[_0xacfe('0x41')][_0xacfe('0x5d')]({'where':{'id':_0x409d09[_0xacfe('0x5b')]['id']},'include':[{'model':db['CmList'],'as':_0xacfe('0xa2'),'include':[{'model':db[_0xacfe('0x8c')],'as':_0xacfe('0xa3'),'where':{'email':_0x471205},'limit':0x1,'order':[[_0xacfe('0xa4'),'DESC']]}]},{'model':db[_0xacfe('0x3c')],'as':_0xacfe('0x3d'),'raw':!![]}]})[_0xacfe('0x1f')](handleEntityNotFound(_0x180c87,null))[_0xacfe('0x1f')](function(_0x3ecb4f){if(_0x3ecb4f){_0x5c986c=_0x3ecb4f;if(_0x3ecb4f['Smtp']){if(_[_0xacfe('0x6d')](_0x409d09[_0xacfe('0x5e')][_0xacfe('0xa5')])){_0x409d09['body'][_0xacfe('0xa5')]=util[_0xacfe('0x9f')]('%s\x20<%s>',_0x3ecb4f['name'],_0x3ecb4f[_0xacfe('0x6c')]||_0x3ecb4f[_0xacfe('0x3d')][_0xacfe('0x72')]);}if(_0x409d09[_0xacfe('0x5e')]['attachments']&&_0x409d09['body'][_0xacfe('0xa6')][_0xacfe('0x4d')]){for(var _0x443f36=0x0;_0x443f36<_0x409d09[_0xacfe('0x5e')][_0xacfe('0xa6')][_0xacfe('0x4d')];_0x443f36+=0x1){_0x409d09[_0xacfe('0x5e')][_0xacfe('0xa6')][_0x443f36]={'filename':_0x409d09[_0xacfe('0x5e')][_0xacfe('0xa6')][_0x443f36][_0xacfe('0x37')],'path':path[_0xacfe('0xa7')](config[_0xacfe('0xa8')],_0xacfe('0xa9'),_0x409d09[_0xacfe('0x5e')][_0xacfe('0xa6')][_0x443f36][_0xacfe('0xaa')])};}}var _0x547540={'tls':{'rejectUnauthorized':![]}};if(_[_0xacfe('0x6d')](_0x3ecb4f[_0xacfe('0x3d')][_0xacfe('0x78')])){if(_0x3ecb4f[_0xacfe('0x3d')][_0xacfe('0x75')]){_0x547540[_0xacfe('0xab')]={'user':_0x3ecb4f[_0xacfe('0x3d')][_0xacfe('0x72')],'pass':_0x3ecb4f[_0xacfe('0x3d')]['pass']};}_0x547540['host']=_0x3ecb4f[_0xacfe('0x3d')][_0xacfe('0x76')];_0x547540[_0xacfe('0x77')]=_0x3ecb4f[_0xacfe('0x3d')][_0xacfe('0x77')];_0x547540[_0xacfe('0xac')]=_0x3ecb4f['Smtp'][_0xacfe('0xac')];}else{_0x547540[_0xacfe('0x78')]=_0x3ecb4f[_0xacfe('0x3d')][_0xacfe('0x78')];_0x547540[_0xacfe('0xab')]={'user':_0x3ecb4f['Smtp'][_0xacfe('0x72')],'pass':_0x3ecb4f[_0xacfe('0x3d')]['pass']};}return respondWithRpcPromise(_0xacfe('0xad'),_0xacfe('0xae'),{'account':_0x547540,'message':_0x409d09[_0xacfe('0x5e')]});}else{throw new Error('List\x20not\x20found');}}})[_0xacfe('0x1f')](function(_0x147fbc){if(_0x147fbc){_0x2c4e1c=_0x147fbc;if(_0x5c986c[_0xacfe('0xa2')]){if(_0x5c986c[_0xacfe('0xa2')]['Contacts']['length']){return _0x5c986c[_0xacfe('0xa2')][_0xacfe('0xa3')][0x0];}else{return db[_0xacfe('0x8c')][_0xacfe('0x64')](_[_0xacfe('0xaf')](_0x409d09[_0xacfe('0x5e')],{'firstName':_0x409d09[_0xacfe('0x5e')]['to'],'email':_0x409d09[_0xacfe('0x5e')]['to'],'phone':_0x409d09['body']['to'],'ListId':_0x5c986c[_0xacfe('0xb0')]}));}}else{throw new Error(_0xacfe('0xb1'));}}})[_0xacfe('0x1f')](function(_0x5d6cd2){if(_0x5d6cd2){var _0x5a6e4f={'UserId':_0x409d09[_0xacfe('0x72')]['id'],'ContactId':_0x5d6cd2['id'],'MailAccountId':_0x5c986c['id'],'inReplyTo':_0x2c4e1c[_0xacfe('0xb2')],'to':_0x409d09[_0xacfe('0x5e')][_0xacfe('0xa5')],'cc':_0x409d09[_0xacfe('0x5e')]['cc'],'subject':_0x409d09[_0xacfe('0x5e')][_0xacfe('0xb3')],'attach':_0x409d09[_0xacfe('0x5e')][_0xacfe('0xb4')],'firstMsgDirection':_0xacfe('0xb5'),'lastMsgAt':moment()[_0xacfe('0x9f')](_0xacfe('0xa0')),'lastMsgDirection':_0xacfe('0xb5'),'lastMsgBody':_0x409d09['body'][_0xacfe('0x5e')],'Messages':[_[_0xacfe('0x55')](_0x409d09['body'],{'messageId':_0x2c4e1c[_0xacfe('0xb2')],'sentAt':moment()[_0xacfe('0x9f')](_0xacfe('0xa0')),'read':!![],'MailAccountId':_0x5c986c['id'],'UserId':_0x409d09['user']['id'],'ContactId':_0x5d6cd2['id']})]};if(_0x409d09['body'][_0xacfe('0xb6')]){_0x5a6e4f=_[_0xacfe('0x55')](_0x5a6e4f,_0x409d09[_0xacfe('0x5e')][_0xacfe('0xb6')]);}return db[_0xacfe('0x8b')]['create'](_0x5a6e4f,{'include':[{'model':db[_0xacfe('0x9c')],'as':_0xacfe('0xb7')}]});}})[_0xacfe('0x1f')](respondWithResult(_0x180c87,null))[_0xacfe('0x29')](handleError(_0x180c87,null));};exports['verifySmtp']=function(_0x36678d,_0x56a094,_0x5d58f6){return db['MailAccount'][_0xacfe('0x5d')]({'where':{'id':_0x36678d[_0xacfe('0x5b')]['id']},'include':[{'model':db[_0xacfe('0x3c')],'as':_0xacfe('0x3d'),'raw':!![]}]})[_0xacfe('0x1f')](handleEntityNotFound(_0x56a094,null))[_0xacfe('0x1f')](function(_0x539115){if(_0x539115&&_0x539115[_0xacfe('0x3d')]){var _0x527006={'id':_0x539115['id'],'tls':{'rejectUnauthorized':![]}};if(_0x539115['Smtp']['service']){_0x527006[_0xacfe('0x78')]=_0x539115[_0xacfe('0x3d')][_0xacfe('0x78')];}else{_0x527006[_0xacfe('0x76')]=_0x539115[_0xacfe('0x3d')]['host'];_0x527006[_0xacfe('0x77')]=_0x539115[_0xacfe('0x3d')][_0xacfe('0x77')];_0x527006[_0xacfe('0xac')]=_0x539115[_0xacfe('0x3d')][_0xacfe('0xac')];}if(_0x539115[_0xacfe('0x3d')][_0xacfe('0x75')]){_0x527006[_0xacfe('0xab')]={'user':_0x539115['Smtp'][_0xacfe('0x72')],'pass':_0x539115['Smtp']['pass']};}return respondWithRpcPromise('VerifySmtp',_0xacfe('0xb8'),{'account':_0x527006});}})[_0xacfe('0x1f')](respondWithResult(_0x56a094,null))[_0xacfe('0x29')](handleError(_0x56a094,null));};exports[_0xacfe('0x33')]=function(_0x14f125,_0x295b38){return db['MailAccount'][_0xacfe('0x5d')]({'where':{'id':_0x14f125['params']['id']}})[_0xacfe('0x1f')](handleEntityNotFound(_0x295b38,null))[_0xacfe('0x1f')](function(_0x514b9b){if(_0x514b9b&&_0x514b9b[_0xacfe('0x78')]){throw new db['Sequelize'][(_0xacfe('0xb9'))](_0xacfe('0xba'));}return _0x514b9b;})[_0xacfe('0x1f')](removeEntity(_0x295b38,null))[_0xacfe('0x29')](handleError(_0x295b38,null));};exports[_0xacfe('0xbb')]=function(_0x58172e,_0x4a794f,_0x1b9d6b){return db['MailAccount'][_0xacfe('0x5d')]({'where':{'id':_0x58172e['params']['id']}})['then'](handleEntityNotFound(_0x4a794f,null))[_0xacfe('0x1f')](function(_0x467fd9){if(_0x467fd9){return _0x467fd9['addAgents'](_0x58172e[_0xacfe('0x5e')][_0xacfe('0x6b')],_[_0xacfe('0x89')](_0x58172e[_0xacfe('0x5e')],[_0xacfe('0x6b'),'id'])||{})[_0xacfe('0xbc')](function(_0x360bd4){for(var _0x24adef=0x0;_0x24adef<_0x58172e[_0xacfe('0x5e')][_0xacfe('0x6b')][_0xacfe('0x4d')];_0x24adef+=0x1){socket[_0xacfe('0xbd')](_0xacfe('0xbe'),{'UserId':_0x58172e[_0xacfe('0x5e')][_0xacfe('0x6b')][_0x24adef],'MailAccountId':_0x58172e[_0xacfe('0x5b')]['id']});}return _0x360bd4;});}})[_0xacfe('0x1f')](respondWithResult(_0x4a794f,null))[_0xacfe('0x29')](handleError(_0x4a794f,null));};exports['removeAgents']=function(_0xf5c94b,_0x14b30f,_0x37e46d){return db['MailAccount'][_0xacfe('0x5d')]({'where':{'id':_0xf5c94b[_0xacfe('0x5b')]['id']}})[_0xacfe('0x1f')](handleEntityNotFound(_0x14b30f,null))[_0xacfe('0x1f')](function(_0x16c303){if(_0x16c303){return _0x16c303[_0xacfe('0xbf')](_0xf5c94b[_0xacfe('0x47')][_0xacfe('0x6b')])[_0xacfe('0x1f')](function(){if(_[_0xacfe('0xc0')](_0xf5c94b[_0xacfe('0x47')][_0xacfe('0x6b')])){for(var _0x3e7a13=0x0;_0x3e7a13<_0xf5c94b[_0xacfe('0x47')][_0xacfe('0x6b')][_0xacfe('0x4d')];_0x3e7a13+=0x1){socket[_0xacfe('0xbd')]('userMailAccount:remove',{'UserId':Number(_0xf5c94b[_0xacfe('0x47')][_0xacfe('0x6b')][_0x3e7a13]),'MailAccountId':Number(_0xf5c94b[_0xacfe('0x5b')]['id'])});}}else{socket[_0xacfe('0xbd')]('userMailAccount:remove',{'UserId':Number(_0xf5c94b[_0xacfe('0x47')][_0xacfe('0x6b')]),'MailAccountId':Number(_0xf5c94b[_0xacfe('0x5b')]['id'])});}});}})[_0xacfe('0x1f')](respondWithStatusCode(_0x14b30f,null))[_0xacfe('0x29')](handleError(_0x14b30f,null));};exports[_0xacfe('0xc1')]=function(_0x2cb53e,_0x2f328b,_0x22f48e){var _0x348437={};var _0x4d4eed={};var _0x1f853f;var _0x216ff8;return db[_0xacfe('0x41')][_0xacfe('0x83')]({'where':{'id':_0x2cb53e['params']['id']}})[_0xacfe('0x1f')](handleEntityNotFound(_0x2f328b,null))['then'](function(_0x3725c4){if(_0x3725c4){_0x1f853f=_0x3725c4;_0x4d4eed[_0xacfe('0x46')]=_[_0xacfe('0x48')](db['User'][_0xacfe('0x42')]);_0x4d4eed['query']=_['keys'](_0x2cb53e[_0xacfe('0x47')]);_0x4d4eed[_0xacfe('0x49')]=_['intersection'](_0x4d4eed[_0xacfe('0x46')],_0x4d4eed[_0xacfe('0x47')]);_0x348437[_0xacfe('0x4b')]=_[_0xacfe('0x4a')](_0x4d4eed[_0xacfe('0x46')],qs[_0xacfe('0x4c')](_0x2cb53e[_0xacfe('0x47')][_0xacfe('0x4c')]));_0x348437[_0xacfe('0x4b')]=_0x348437[_0xacfe('0x4b')]['length']?_0x348437[_0xacfe('0x4b')]:_0x4d4eed['model'];_0x348437['order']=qs[_0xacfe('0x52')](_0x2cb53e['query'][_0xacfe('0x52')]);_0x348437['where']=qs[_0xacfe('0x49')](_[_0xacfe('0x53')](_0x2cb53e[_0xacfe('0x47')],_0x4d4eed[_0xacfe('0x49')]));if(_0x2cb53e['query'][_0xacfe('0x66')]){_0x348437[_0xacfe('0x54')]=_[_0xacfe('0x55')](_0x348437[_0xacfe('0x54')],{'$or':_['map'](_0x348437['attributes'],function(_0x1f0d10){var _0x2991d0={};_0x2991d0[_0x1f0d10]={'$like':'%'+_0x2cb53e[_0xacfe('0x47')][_0xacfe('0x66')]+'%'};return _0x2991d0;})});}_0x348437=_[_0xacfe('0x55')]({},_0x348437,_0x2cb53e[_0xacfe('0x56')]);return _0x1f853f[_0xacfe('0xc1')](_0x348437);}})[_0xacfe('0x1f')](function(_0x44e0c4){if(_0x44e0c4){_0x216ff8=_0x44e0c4[_0xacfe('0x4d')];if(!_0x2cb53e['query']['hasOwnProperty'](_0xacfe('0x4f'))){_0x348437[_0xacfe('0x50')]=qs['limit'](_0x2cb53e[_0xacfe('0x47')][_0xacfe('0x50')]);_0x348437[_0xacfe('0x2e')]=qs['offset'](_0x2cb53e[_0xacfe('0x47')]['offset']);}return _0x1f853f[_0xacfe('0xc1')](_0x348437);}})[_0xacfe('0x1f')](function(_0x1be999){if(_0x1be999){return _0x1be999?{'count':_0x216ff8,'rows':_0x1be999}:null;}})[_0xacfe('0x1f')](respondWithResult(_0x2f328b,null))[_0xacfe('0x29')](handleError(_0x2f328b,null));};