48805bceb37472331862a3fdb4d765256ffca73d
[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 _0x1f8f=['show','params','includeAll','catch','create','body','find','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','undefined','count','offset','limit','Content-Range','apply','reject','update','destroy','end','stack','name','send','map','rawAttributes','fieldName','type','key','model','keys','query','intersection','attributes','fields','length','order','sort','where','filters','pick','filter','merge','options','MailServerOut','then','include','rows'];(function(_0x1f9f27,_0x1d63df){var _0x5ec68d=function(_0x258546){while(--_0x258546){_0x1f9f27['push'](_0x1f9f27['shift']());}};_0x5ec68d(++_0x1d63df);}(_0x1f8f,0x95));var _0xf1f8=function(_0x110129,_0x2ed398){_0x110129=_0x110129-0x0;var _0x375002=_0x1f8f[_0x110129];return _0x375002;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xf1f8('0x0'));var zipdir=require(_0xf1f8('0x1'));var jsonpatch=require(_0xf1f8('0x2'));var rp=require(_0xf1f8('0x3'));var moment=require('moment');var BPromise=require(_0xf1f8('0x4'));var Mustache=require(_0xf1f8('0x5'));var util=require(_0xf1f8('0x6'));var path=require('path');var sox=require('sox');var csv=require(_0xf1f8('0x7'));var ejs=require(_0xf1f8('0x8'));var fs=require('fs');var fs_extra=require(_0xf1f8('0x9'));var _=require(_0xf1f8('0xa'));var squel=require(_0xf1f8('0xb'));var crypto=require(_0xf1f8('0xc'));var jsforce=require(_0xf1f8('0xd'));var deskjs=require(_0xf1f8('0xe'));var toCsv=require(_0xf1f8('0x7'));var querystring=require(_0xf1f8('0xf'));var Papa=require(_0xf1f8('0x10'));var Redis=require(_0xf1f8('0x11'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0xf1f8('0x12'));var hardwareService=require(_0xf1f8('0x13'));var logger=require('../../config/logger')('api');var utils=require(_0xf1f8('0x14'));var config=require(_0xf1f8('0x15'));var licenseUtil=require(_0xf1f8('0x16'));var db=require(_0xf1f8('0x17'))['db'];function respondWithStatusCode(_0x409f21,_0x3dd928){_0x3dd928=_0x3dd928||0xcc;return function(_0x755b2d){if(_0x755b2d){return _0x409f21[_0xf1f8('0x18')](_0x3dd928);}return _0x409f21[_0xf1f8('0x19')](_0x3dd928)['end']();};}function respondWithResult(_0x870b6b,_0x379130){_0x379130=_0x379130||0xc8;return function(_0x64ee24){if(_0x64ee24){return _0x870b6b['status'](_0x379130)[_0xf1f8('0x1a')](_0x64ee24);}};}function respondWithFilteredResult(_0x3423b5,_0x4f06b4){return function(_0x48931a){if(_0x48931a){var _0x525447=typeof _0x4f06b4['offset']===_0xf1f8('0x1b')&&typeof _0x4f06b4['limit']==='undefined';var _0xe98095=_0x48931a[_0xf1f8('0x1c')];var _0x15b471=_0x525447?0x0:_0x4f06b4[_0xf1f8('0x1d')];var _0x1f5717=_0x525447?_0x48931a[_0xf1f8('0x1c')]:_0x4f06b4[_0xf1f8('0x1d')]+_0x4f06b4[_0xf1f8('0x1e')];var _0x4e5dde;if(_0x1f5717>=_0xe98095){_0x1f5717=_0xe98095;_0x4e5dde=0xc8;}else{_0x4e5dde=0xce;}_0x3423b5['status'](_0x4e5dde);return _0x3423b5['set'](_0xf1f8('0x1f'),_0x15b471+'-'+_0x1f5717+'/'+_0xe98095)[_0xf1f8('0x1a')](_0x48931a);}return null;};}function patchUpdates(_0x2fb898){return function(_0x3a5b99){try{jsonpatch[_0xf1f8('0x20')](_0x3a5b99,_0x2fb898,!![]);}catch(_0x35b6c5){return BPromise[_0xf1f8('0x21')](_0x35b6c5);}return _0x3a5b99['save']();};}function saveUpdates(_0x3d2c79,_0x37d565){return function(_0x21c664){if(_0x21c664){return _0x21c664[_0xf1f8('0x22')](_0x3d2c79)['then'](function(_0x2ae578){return _0x2ae578;});}return null;};}function removeEntity(_0x13ca4f,_0x1a0341){return function(_0xf56780){if(_0xf56780){return _0xf56780[_0xf1f8('0x23')]()['then'](function(){_0x13ca4f['status'](0xcc)[_0xf1f8('0x24')]();});}};}function handleEntityNotFound(_0x1ccadc,_0x35dbc5){return function(_0x22f5ac){if(!_0x22f5ac){_0x1ccadc[_0xf1f8('0x18')](0x194);}return _0x22f5ac;};}function handleError(_0x3e9fc5,_0x184f99){_0x184f99=_0x184f99||0x1f4;return function(_0x320eed){logger['error'](_0x320eed[_0xf1f8('0x25')]);if(_0x320eed[_0xf1f8('0x26')]){delete _0x320eed[_0xf1f8('0x26')];}_0x3e9fc5[_0xf1f8('0x19')](_0x184f99)[_0xf1f8('0x27')](_0x320eed);};}exports['index']=function(_0x5692c6,_0x291b4b){var _0x574a1b={},_0x21b0d7={},_0x4d3eee={'count':0x0,'rows':[]};var _0x365acc=_[_0xf1f8('0x28')](db['MailServerOut'][_0xf1f8('0x29')],function(_0x13149d){return{'name':_0x13149d[_0xf1f8('0x2a')],'type':_0x13149d[_0xf1f8('0x2b')][_0xf1f8('0x2c')]};});_0x21b0d7[_0xf1f8('0x2d')]=_[_0xf1f8('0x28')](_0x365acc,_0xf1f8('0x26'));_0x21b0d7['query']=_[_0xf1f8('0x2e')](_0x5692c6[_0xf1f8('0x2f')]);_0x21b0d7['filters']=_[_0xf1f8('0x30')](_0x21b0d7[_0xf1f8('0x2d')],_0x21b0d7[_0xf1f8('0x2f')]);_0x574a1b[_0xf1f8('0x31')]=_[_0xf1f8('0x30')](_0x21b0d7[_0xf1f8('0x2d')],qs[_0xf1f8('0x32')](_0x5692c6[_0xf1f8('0x2f')][_0xf1f8('0x32')]));_0x574a1b[_0xf1f8('0x31')]=_0x574a1b[_0xf1f8('0x31')][_0xf1f8('0x33')]?_0x574a1b[_0xf1f8('0x31')]:_0x21b0d7[_0xf1f8('0x2d')];if(!_0x5692c6[_0xf1f8('0x2f')]['hasOwnProperty']('nolimit')){_0x574a1b[_0xf1f8('0x1e')]=qs[_0xf1f8('0x1e')](_0x5692c6[_0xf1f8('0x2f')][_0xf1f8('0x1e')]);_0x574a1b[_0xf1f8('0x1d')]=qs[_0xf1f8('0x1d')](_0x5692c6[_0xf1f8('0x2f')][_0xf1f8('0x1d')]);}_0x574a1b[_0xf1f8('0x34')]=qs['sort'](_0x5692c6[_0xf1f8('0x2f')][_0xf1f8('0x35')]);_0x574a1b[_0xf1f8('0x36')]=qs[_0xf1f8('0x37')](_[_0xf1f8('0x38')](_0x5692c6[_0xf1f8('0x2f')],_0x21b0d7[_0xf1f8('0x37')]),_0x365acc);if(_0x5692c6[_0xf1f8('0x2f')][_0xf1f8('0x39')]){_0x574a1b['where']=_[_0xf1f8('0x3a')](_0x574a1b[_0xf1f8('0x36')],{'$or':_[_0xf1f8('0x28')](_0x365acc,function(_0x423517){if(_0x423517[_0xf1f8('0x2b')]!=='VIRTUAL'){var _0x4c8c3a={};_0x4c8c3a[_0x423517[_0xf1f8('0x26')]]={'$like':'%'+_0x5692c6[_0xf1f8('0x2f')][_0xf1f8('0x39')]+'%'};return _0x4c8c3a;}})});}_0x574a1b=_[_0xf1f8('0x3a')]({},_0x574a1b,_0x5692c6[_0xf1f8('0x3b')]);var _0xe630b4={'where':_0x574a1b['where']};return db[_0xf1f8('0x3c')][_0xf1f8('0x1c')](_0xe630b4)[_0xf1f8('0x3d')](function(_0xa34835){_0x4d3eee[_0xf1f8('0x1c')]=_0xa34835;if(_0x5692c6[_0xf1f8('0x2f')]['includeAll']){_0x574a1b[_0xf1f8('0x3e')]=[{'all':!![]}];}return db[_0xf1f8('0x3c')]['findAll'](_0x574a1b);})[_0xf1f8('0x3d')](function(_0xba9f98){_0x4d3eee[_0xf1f8('0x3f')]=_0xba9f98;return _0x4d3eee;})[_0xf1f8('0x3d')](respondWithFilteredResult(_0x291b4b,_0x574a1b))['catch'](handleError(_0x291b4b,null));};exports[_0xf1f8('0x40')]=function(_0x21e326,_0x3656b1){var _0x2b1eff={'raw':!![],'where':{'id':_0x21e326[_0xf1f8('0x41')]['id']}},_0xf2dc2a={};_0xf2dc2a[_0xf1f8('0x2d')]=_[_0xf1f8('0x2e')](db[_0xf1f8('0x3c')]['rawAttributes']);_0xf2dc2a[_0xf1f8('0x2f')]=_[_0xf1f8('0x2e')](_0x21e326['query']);_0xf2dc2a['filters']=_[_0xf1f8('0x30')](_0xf2dc2a[_0xf1f8('0x2d')],_0xf2dc2a[_0xf1f8('0x2f')]);_0x2b1eff[_0xf1f8('0x31')]=_[_0xf1f8('0x30')](_0xf2dc2a[_0xf1f8('0x2d')],qs[_0xf1f8('0x32')](_0x21e326['query'][_0xf1f8('0x32')]));_0x2b1eff[_0xf1f8('0x31')]=_0x2b1eff[_0xf1f8('0x31')]['length']?_0x2b1eff[_0xf1f8('0x31')]:_0xf2dc2a['model'];if(_0x21e326['query'][_0xf1f8('0x42')]){_0x2b1eff['include']=[{'all':!![]}];}_0x2b1eff=_[_0xf1f8('0x3a')]({},_0x2b1eff,_0x21e326['options']);return db[_0xf1f8('0x3c')]['find'](_0x2b1eff)[_0xf1f8('0x3d')](handleEntityNotFound(_0x3656b1,null))[_0xf1f8('0x3d')](respondWithResult(_0x3656b1,null))[_0xf1f8('0x43')](handleError(_0x3656b1,null));};exports[_0xf1f8('0x44')]=function(_0x5557b5,_0x350beb){return db[_0xf1f8('0x3c')][_0xf1f8('0x44')](_0x5557b5[_0xf1f8('0x45')],{})[_0xf1f8('0x3d')](respondWithResult(_0x350beb,0xc9))['catch'](handleError(_0x350beb,null));};exports['update']=function(_0x5c988d,_0x12bd0f){if(_0x5c988d[_0xf1f8('0x45')]['id']){delete _0x5c988d[_0xf1f8('0x45')]['id'];}return db[_0xf1f8('0x3c')][_0xf1f8('0x46')]({'where':{'id':_0x5c988d[_0xf1f8('0x41')]['id']}})['then'](handleEntityNotFound(_0x12bd0f,null))[_0xf1f8('0x3d')](saveUpdates(_0x5c988d[_0xf1f8('0x45')],null))[_0xf1f8('0x3d')](respondWithResult(_0x12bd0f,null))[_0xf1f8('0x43')](handleError(_0x12bd0f,null));};exports[_0xf1f8('0x23')]=function(_0x26b05a,_0x59e0c6){return db[_0xf1f8('0x3c')][_0xf1f8('0x46')]({'where':{'id':_0x26b05a['params']['id']}})[_0xf1f8('0x3d')](handleEntityNotFound(_0x59e0c6,null))[_0xf1f8('0x3d')](removeEntity(_0x59e0c6,null))[_0xf1f8('0x43')](handleError(_0x59e0c6,null));};