Built motion from commit (unavailable).|2.6.0
[motion2.git] / server / api / mailServerOut / mailServerOut.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 _0x48f5=['include','find','create','body','params','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','lodash','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','end','status','json','offset','limit','undefined','count','set','Content-Range','reject','save','update','then','destroy','index','map','MailServerOut','rawAttributes','fieldName','type','key','name','query','keys','filters','intersection','model','attributes','fields','length','hasOwnProperty','order','sort','where','filter','merge','VIRTUAL','options','includeAll','findAll','rows','catch','show'];(function(_0x1e1943,_0x1a6d54){var _0x4989a9=function(_0x4e1e58){while(--_0x4e1e58){_0x1e1943['push'](_0x1e1943['shift']());}};_0x4989a9(++_0x1a6d54);}(_0x48f5,0x1c1));var _0x548f=function(_0x51af64,_0x50c0c7){_0x51af64=_0x51af64-0x0;var _0x2ba7e9=_0x48f5[_0x51af64];return _0x2ba7e9;};'use strict';var emlformat=require(_0x548f('0x0'));var rimraf=require(_0x548f('0x1'));var zipdir=require(_0x548f('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x548f('0x3'));var moment=require(_0x548f('0x4'));var BPromise=require(_0x548f('0x5'));var Mustache=require(_0x548f('0x6'));var util=require(_0x548f('0x7'));var path=require(_0x548f('0x8'));var sox=require(_0x548f('0x9'));var csv=require(_0x548f('0xa'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x548f('0xb'));var squel=require('squel');var crypto=require(_0x548f('0xc'));var jsforce=require(_0x548f('0xd'));var deskjs=require(_0x548f('0xe'));var toCsv=require(_0x548f('0xa'));var querystring=require(_0x548f('0xf'));var Papa=require(_0x548f('0x10'));var Redis=require(_0x548f('0x11'));var authService=require('../../components/auth/service');var qs=require(_0x548f('0x12'));var as=require(_0x548f('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x548f('0x14'));var utils=require(_0x548f('0x15'));var config=require(_0x548f('0x16'));var licenseUtil=require(_0x548f('0x17'));var db=require(_0x548f('0x18'))['db'];function respondWithStatusCode(_0xb38671,_0x337bf6){_0x337bf6=_0x337bf6||0xcc;return function(_0x109adb){if(_0x109adb){return _0xb38671[_0x548f('0x19')](_0x337bf6);}return _0xb38671['status'](_0x337bf6)[_0x548f('0x1a')]();};}function respondWithResult(_0x4043cd,_0x340607){_0x340607=_0x340607||0xc8;return function(_0x295beb){if(_0x295beb){return _0x4043cd[_0x548f('0x1b')](_0x340607)[_0x548f('0x1c')](_0x295beb);}};}function respondWithFilteredResult(_0x22a4aa,_0x52f66c){return function(_0x2d14c6){if(_0x2d14c6){var _0x65685e=typeof _0x52f66c[_0x548f('0x1d')]==='undefined'&&typeof _0x52f66c[_0x548f('0x1e')]===_0x548f('0x1f');var _0x529328=_0x2d14c6['count'];var _0xbccec9=_0x65685e?0x0:_0x52f66c[_0x548f('0x1d')];var _0x397ee7=_0x65685e?_0x2d14c6[_0x548f('0x20')]:_0x52f66c[_0x548f('0x1d')]+_0x52f66c[_0x548f('0x1e')];var _0x4e31fd;if(_0x397ee7>=_0x529328){_0x397ee7=_0x529328;_0x4e31fd=0xc8;}else{_0x4e31fd=0xce;}_0x22a4aa['status'](_0x4e31fd);return _0x22a4aa[_0x548f('0x21')](_0x548f('0x22'),_0xbccec9+'-'+_0x397ee7+'/'+_0x529328)[_0x548f('0x1c')](_0x2d14c6);}return null;};}function patchUpdates(_0x577dc9){return function(_0x1c9416){try{jsonpatch['apply'](_0x1c9416,_0x577dc9,!![]);}catch(_0x2c1f54){return BPromise[_0x548f('0x23')](_0x2c1f54);}return _0x1c9416[_0x548f('0x24')]();};}function saveUpdates(_0x35ef0b,_0x372fde){return function(_0x5bfede){if(_0x5bfede){return _0x5bfede[_0x548f('0x25')](_0x35ef0b)[_0x548f('0x26')](function(_0x44c147){return _0x44c147;});}return null;};}function removeEntity(_0x5830d1,_0x4c3a6e){return function(_0x4d508c){if(_0x4d508c){return _0x4d508c[_0x548f('0x27')]()[_0x548f('0x26')](function(){_0x5830d1['status'](0xcc)[_0x548f('0x1a')]();});}};}function handleEntityNotFound(_0x399946,_0x5a06f3){return function(_0x245558){if(!_0x245558){_0x399946[_0x548f('0x19')](0x194);}return _0x245558;};}function handleError(_0x1983b8,_0x1c0713){_0x1c0713=_0x1c0713||0x1f4;return function(_0x13c842){logger['error'](_0x13c842['stack']);if(_0x13c842['name']){delete _0x13c842['name'];}_0x1983b8[_0x548f('0x1b')](_0x1c0713)['send'](_0x13c842);};}exports[_0x548f('0x28')]=function(_0x41394b,_0x4178f5){var _0x5169ff={},_0x576a01={},_0x29c414={'count':0x0,'rows':[]};var _0x2b5fc4=_[_0x548f('0x29')](db[_0x548f('0x2a')][_0x548f('0x2b')],function(_0x4ee76c){return{'name':_0x4ee76c[_0x548f('0x2c')],'type':_0x4ee76c[_0x548f('0x2d')][_0x548f('0x2e')]};});_0x576a01['model']=_[_0x548f('0x29')](_0x2b5fc4,_0x548f('0x2f'));_0x576a01[_0x548f('0x30')]=_[_0x548f('0x31')](_0x41394b[_0x548f('0x30')]);_0x576a01[_0x548f('0x32')]=_[_0x548f('0x33')](_0x576a01[_0x548f('0x34')],_0x576a01[_0x548f('0x30')]);_0x5169ff[_0x548f('0x35')]=_[_0x548f('0x33')](_0x576a01['model'],qs[_0x548f('0x36')](_0x41394b[_0x548f('0x30')][_0x548f('0x36')]));_0x5169ff[_0x548f('0x35')]=_0x5169ff[_0x548f('0x35')][_0x548f('0x37')]?_0x5169ff[_0x548f('0x35')]:_0x576a01[_0x548f('0x34')];if(!_0x41394b[_0x548f('0x30')][_0x548f('0x38')]('nolimit')){_0x5169ff['limit']=qs['limit'](_0x41394b[_0x548f('0x30')][_0x548f('0x1e')]);_0x5169ff[_0x548f('0x1d')]=qs[_0x548f('0x1d')](_0x41394b[_0x548f('0x30')][_0x548f('0x1d')]);}_0x5169ff[_0x548f('0x39')]=qs[_0x548f('0x3a')](_0x41394b['query'][_0x548f('0x3a')]);_0x5169ff[_0x548f('0x3b')]=qs[_0x548f('0x32')](_['pick'](_0x41394b[_0x548f('0x30')],_0x576a01['filters']),_0x2b5fc4);if(_0x41394b['query'][_0x548f('0x3c')]){_0x5169ff['where']=_[_0x548f('0x3d')](_0x5169ff[_0x548f('0x3b')],{'$or':_[_0x548f('0x29')](_0x2b5fc4,function(_0x3b5943){if(_0x3b5943[_0x548f('0x2d')]!==_0x548f('0x3e')){var _0x41858d={};_0x41858d[_0x3b5943[_0x548f('0x2f')]]={'$like':'%'+_0x41394b[_0x548f('0x30')][_0x548f('0x3c')]+'%'};return _0x41858d;}})});}_0x5169ff=_[_0x548f('0x3d')]({},_0x5169ff,_0x41394b[_0x548f('0x3f')]);var _0x19fab8={'where':_0x5169ff[_0x548f('0x3b')]};return db[_0x548f('0x2a')][_0x548f('0x20')](_0x19fab8)[_0x548f('0x26')](function(_0x1bc3a1){_0x29c414[_0x548f('0x20')]=_0x1bc3a1;if(_0x41394b[_0x548f('0x30')][_0x548f('0x40')]){_0x5169ff['include']=[{'all':!![]}];}return db['MailServerOut'][_0x548f('0x41')](_0x5169ff);})[_0x548f('0x26')](function(_0x375f12){_0x29c414[_0x548f('0x42')]=_0x375f12;return _0x29c414;})['then'](respondWithFilteredResult(_0x4178f5,_0x5169ff))[_0x548f('0x43')](handleError(_0x4178f5,null));};exports[_0x548f('0x44')]=function(_0x9ed7da,_0x359f87){var _0x5440a1={'raw':!![],'where':{'id':_0x9ed7da['params']['id']}},_0x120d1c={};_0x120d1c[_0x548f('0x34')]=_[_0x548f('0x31')](db[_0x548f('0x2a')][_0x548f('0x2b')]);_0x120d1c[_0x548f('0x30')]=_[_0x548f('0x31')](_0x9ed7da[_0x548f('0x30')]);_0x120d1c['filters']=_['intersection'](_0x120d1c['model'],_0x120d1c[_0x548f('0x30')]);_0x5440a1[_0x548f('0x35')]=_['intersection'](_0x120d1c[_0x548f('0x34')],qs[_0x548f('0x36')](_0x9ed7da[_0x548f('0x30')][_0x548f('0x36')]));_0x5440a1[_0x548f('0x35')]=_0x5440a1['attributes'][_0x548f('0x37')]?_0x5440a1['attributes']:_0x120d1c[_0x548f('0x34')];if(_0x9ed7da[_0x548f('0x30')][_0x548f('0x40')]){_0x5440a1[_0x548f('0x45')]=[{'all':!![]}];}_0x5440a1=_[_0x548f('0x3d')]({},_0x5440a1,_0x9ed7da[_0x548f('0x3f')]);return db[_0x548f('0x2a')][_0x548f('0x46')](_0x5440a1)['then'](handleEntityNotFound(_0x359f87,null))[_0x548f('0x26')](respondWithResult(_0x359f87,null))[_0x548f('0x43')](handleError(_0x359f87,null));};exports['create']=function(_0x2e18d9,_0x3837f7){return db[_0x548f('0x2a')][_0x548f('0x47')](_0x2e18d9['body'],{})[_0x548f('0x26')](respondWithResult(_0x3837f7,0xc9))[_0x548f('0x43')](handleError(_0x3837f7,null));};exports[_0x548f('0x25')]=function(_0x4dd1e7,_0x545f){if(_0x4dd1e7[_0x548f('0x48')]['id']){delete _0x4dd1e7[_0x548f('0x48')]['id'];}return db['MailServerOut']['find']({'where':{'id':_0x4dd1e7[_0x548f('0x49')]['id']}})[_0x548f('0x26')](handleEntityNotFound(_0x545f,null))[_0x548f('0x26')](saveUpdates(_0x4dd1e7[_0x548f('0x48')],null))['then'](respondWithResult(_0x545f,null))['catch'](handleError(_0x545f,null));};exports[_0x548f('0x27')]=function(_0x267c68,_0x56847a){return db[_0x548f('0x2a')]['find']({'where':{'id':_0x267c68[_0x548f('0x49')]['id']}})[_0x548f('0x26')](handleEntityNotFound(_0x56847a,null))['then'](removeEntity(_0x56847a,null))[_0x548f('0x43')](handleError(_0x56847a,null));};