Built motion from commit 9d0783e6.|2.6.13
[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 _0xf5f3=['fast-json-patch','request-promise','moment','mustache','util','to-csv','ejs','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','status','end','json','offset','limit','undefined','count','set','Content-Range','apply','reject','save','update','then','destroy','error','stack','name','send','map','MailServerOut','fieldName','type','key','model','query','keys','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','where','pick','filter','merge','VIRTUAL','options','includeAll','include','rows','catch','params','rawAttributes','create','body','find','rimraf'];(function(_0x53a82f,_0x3c21cd){var _0x24c906=function(_0x36d253){while(--_0x36d253){_0x53a82f['push'](_0x53a82f['shift']());}};_0x24c906(++_0x3c21cd);}(_0xf5f3,0xd4));var _0x3f5f=function(_0x5a5468,_0x36218f){_0x5a5468=_0x5a5468-0x0;var _0x456729=_0xf5f3[_0x5a5468];return _0x456729;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x3f5f('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0x3f5f('0x1'));var rp=require(_0x3f5f('0x2'));var moment=require(_0x3f5f('0x3'));var BPromise=require('bluebird');var Mustache=require(_0x3f5f('0x4'));var util=require(_0x3f5f('0x5'));var path=require('path');var sox=require('sox');var csv=require(_0x3f5f('0x6'));var ejs=require(_0x3f5f('0x7'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0x3f5f('0x8'));var crypto=require(_0x3f5f('0x9'));var jsforce=require(_0x3f5f('0xa'));var deskjs=require(_0x3f5f('0xb'));var toCsv=require(_0x3f5f('0x6'));var querystring=require(_0x3f5f('0xc'));var Papa=require(_0x3f5f('0xd'));var Redis=require(_0x3f5f('0xe'));var authService=require(_0x3f5f('0xf'));var qs=require('../../components/parsers/qs');var as=require(_0x3f5f('0x10'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')('api');var utils=require(_0x3f5f('0x11'));var config=require(_0x3f5f('0x12'));var licenseUtil=require(_0x3f5f('0x13'));var db=require(_0x3f5f('0x14'))['db'];function respondWithStatusCode(_0x3a56d4,_0x32e969){_0x32e969=_0x32e969||0xcc;return function(_0x4b73bd){if(_0x4b73bd){return _0x3a56d4['sendStatus'](_0x32e969);}return _0x3a56d4[_0x3f5f('0x15')](_0x32e969)[_0x3f5f('0x16')]();};}function respondWithResult(_0x522509,_0x275691){_0x275691=_0x275691||0xc8;return function(_0x124adb){if(_0x124adb){return _0x522509[_0x3f5f('0x15')](_0x275691)[_0x3f5f('0x17')](_0x124adb);}};}function respondWithFilteredResult(_0x3ceace,_0x25f316){return function(_0x1e3ab1){if(_0x1e3ab1){var _0x42cbf8=typeof _0x25f316[_0x3f5f('0x18')]==='undefined'&&typeof _0x25f316[_0x3f5f('0x19')]===_0x3f5f('0x1a');var _0x2b74a0=_0x1e3ab1[_0x3f5f('0x1b')];var _0x227a97=_0x42cbf8?0x0:_0x25f316[_0x3f5f('0x18')];var _0x47bc22=_0x42cbf8?_0x1e3ab1[_0x3f5f('0x1b')]:_0x25f316[_0x3f5f('0x18')]+_0x25f316[_0x3f5f('0x19')];var _0x395e16;if(_0x47bc22>=_0x2b74a0){_0x47bc22=_0x2b74a0;_0x395e16=0xc8;}else{_0x395e16=0xce;}_0x3ceace[_0x3f5f('0x15')](_0x395e16);return _0x3ceace[_0x3f5f('0x1c')](_0x3f5f('0x1d'),_0x227a97+'-'+_0x47bc22+'/'+_0x2b74a0)[_0x3f5f('0x17')](_0x1e3ab1);}return null;};}function patchUpdates(_0x3a2d21){return function(_0x38007b){try{jsonpatch[_0x3f5f('0x1e')](_0x38007b,_0x3a2d21,!![]);}catch(_0x89949d){return BPromise[_0x3f5f('0x1f')](_0x89949d);}return _0x38007b[_0x3f5f('0x20')]();};}function saveUpdates(_0x42c5d7,_0x5b2b39){return function(_0x1e74d1){if(_0x1e74d1){return _0x1e74d1[_0x3f5f('0x21')](_0x42c5d7)[_0x3f5f('0x22')](function(_0x279627){return _0x279627;});}return null;};}function removeEntity(_0x53c0d0,_0x185668){return function(_0x3c4b26){if(_0x3c4b26){return _0x3c4b26[_0x3f5f('0x23')]()[_0x3f5f('0x22')](function(){_0x53c0d0[_0x3f5f('0x15')](0xcc)[_0x3f5f('0x16')]();});}};}function handleEntityNotFound(_0x12a4af,_0x7d1e7b){return function(_0x51d4ba){if(!_0x51d4ba){_0x12a4af['sendStatus'](0x194);}return _0x51d4ba;};}function handleError(_0x2dfeca,_0x147f9e){_0x147f9e=_0x147f9e||0x1f4;return function(_0x4b58f1){logger[_0x3f5f('0x24')](_0x4b58f1[_0x3f5f('0x25')]);if(_0x4b58f1['name']){delete _0x4b58f1[_0x3f5f('0x26')];}_0x2dfeca[_0x3f5f('0x15')](_0x147f9e)[_0x3f5f('0x27')](_0x4b58f1);};}exports['index']=function(_0x25ca4c,_0x4eb3e6){var _0x59e65a={},_0x1d80f0={},_0x401594={'count':0x0,'rows':[]};var _0x28e844=_[_0x3f5f('0x28')](db[_0x3f5f('0x29')]['rawAttributes'],function(_0x329d57){return{'name':_0x329d57[_0x3f5f('0x2a')],'type':_0x329d57[_0x3f5f('0x2b')][_0x3f5f('0x2c')]};});_0x1d80f0[_0x3f5f('0x2d')]=_[_0x3f5f('0x28')](_0x28e844,'name');_0x1d80f0[_0x3f5f('0x2e')]=_[_0x3f5f('0x2f')](_0x25ca4c[_0x3f5f('0x2e')]);_0x1d80f0[_0x3f5f('0x30')]=_[_0x3f5f('0x31')](_0x1d80f0[_0x3f5f('0x2d')],_0x1d80f0[_0x3f5f('0x2e')]);_0x59e65a['attributes']=_[_0x3f5f('0x31')](_0x1d80f0[_0x3f5f('0x2d')],qs['fields'](_0x25ca4c[_0x3f5f('0x2e')][_0x3f5f('0x32')]));_0x59e65a[_0x3f5f('0x33')]=_0x59e65a[_0x3f5f('0x33')][_0x3f5f('0x34')]?_0x59e65a[_0x3f5f('0x33')]:_0x1d80f0[_0x3f5f('0x2d')];if(!_0x25ca4c[_0x3f5f('0x2e')][_0x3f5f('0x35')](_0x3f5f('0x36'))){_0x59e65a[_0x3f5f('0x19')]=qs[_0x3f5f('0x19')](_0x25ca4c[_0x3f5f('0x2e')]['limit']);_0x59e65a[_0x3f5f('0x18')]=qs[_0x3f5f('0x18')](_0x25ca4c[_0x3f5f('0x2e')]['offset']);}_0x59e65a[_0x3f5f('0x37')]=qs['sort'](_0x25ca4c[_0x3f5f('0x2e')]['sort']);_0x59e65a[_0x3f5f('0x38')]=qs[_0x3f5f('0x30')](_[_0x3f5f('0x39')](_0x25ca4c[_0x3f5f('0x2e')],_0x1d80f0[_0x3f5f('0x30')]),_0x28e844);if(_0x25ca4c[_0x3f5f('0x2e')][_0x3f5f('0x3a')]){_0x59e65a[_0x3f5f('0x38')]=_[_0x3f5f('0x3b')](_0x59e65a[_0x3f5f('0x38')],{'$or':_[_0x3f5f('0x28')](_0x28e844,function(_0x1a3c6e){if(_0x1a3c6e[_0x3f5f('0x2b')]!==_0x3f5f('0x3c')){var _0x5794c4={};_0x5794c4[_0x1a3c6e[_0x3f5f('0x26')]]={'$like':'%'+_0x25ca4c['query'][_0x3f5f('0x3a')]+'%'};return _0x5794c4;}})});}_0x59e65a=_[_0x3f5f('0x3b')]({},_0x59e65a,_0x25ca4c[_0x3f5f('0x3d')]);var _0x1f1cb9={'where':_0x59e65a[_0x3f5f('0x38')]};return db[_0x3f5f('0x29')][_0x3f5f('0x1b')](_0x1f1cb9)[_0x3f5f('0x22')](function(_0x2d606a){_0x401594[_0x3f5f('0x1b')]=_0x2d606a;if(_0x25ca4c[_0x3f5f('0x2e')][_0x3f5f('0x3e')]){_0x59e65a[_0x3f5f('0x3f')]=[{'all':!![]}];}return db[_0x3f5f('0x29')]['findAll'](_0x59e65a);})[_0x3f5f('0x22')](function(_0x353d90){_0x401594[_0x3f5f('0x40')]=_0x353d90;return _0x401594;})['then'](respondWithFilteredResult(_0x4eb3e6,_0x59e65a))[_0x3f5f('0x41')](handleError(_0x4eb3e6,null));};exports['show']=function(_0x36d21d,_0x3b69c2){var _0x4650c4={'raw':!![],'where':{'id':_0x36d21d[_0x3f5f('0x42')]['id']}},_0x4c8946={};_0x4c8946[_0x3f5f('0x2d')]=_['keys'](db['MailServerOut'][_0x3f5f('0x43')]);_0x4c8946['query']=_[_0x3f5f('0x2f')](_0x36d21d[_0x3f5f('0x2e')]);_0x4c8946[_0x3f5f('0x30')]=_[_0x3f5f('0x31')](_0x4c8946[_0x3f5f('0x2d')],_0x4c8946[_0x3f5f('0x2e')]);_0x4650c4[_0x3f5f('0x33')]=_['intersection'](_0x4c8946['model'],qs[_0x3f5f('0x32')](_0x36d21d[_0x3f5f('0x2e')][_0x3f5f('0x32')]));_0x4650c4['attributes']=_0x4650c4[_0x3f5f('0x33')][_0x3f5f('0x34')]?_0x4650c4['attributes']:_0x4c8946[_0x3f5f('0x2d')];if(_0x36d21d['query'][_0x3f5f('0x3e')]){_0x4650c4['include']=[{'all':!![]}];}_0x4650c4=_[_0x3f5f('0x3b')]({},_0x4650c4,_0x36d21d['options']);return db['MailServerOut']['find'](_0x4650c4)['then'](handleEntityNotFound(_0x3b69c2,null))[_0x3f5f('0x22')](respondWithResult(_0x3b69c2,null))[_0x3f5f('0x41')](handleError(_0x3b69c2,null));};exports['create']=function(_0x58cc61,_0x43c3e8){return db['MailServerOut'][_0x3f5f('0x44')](_0x58cc61['body'],{})[_0x3f5f('0x22')](respondWithResult(_0x43c3e8,0xc9))['catch'](handleError(_0x43c3e8,null));};exports[_0x3f5f('0x21')]=function(_0xdccb87,_0x2181cc){if(_0xdccb87[_0x3f5f('0x45')]['id']){delete _0xdccb87['body']['id'];}return db['MailServerOut'][_0x3f5f('0x46')]({'where':{'id':_0xdccb87[_0x3f5f('0x42')]['id']}})[_0x3f5f('0x22')](handleEntityNotFound(_0x2181cc,null))[_0x3f5f('0x22')](saveUpdates(_0xdccb87['body'],null))['then'](respondWithResult(_0x2181cc,null))['catch'](handleError(_0x2181cc,null));};exports[_0x3f5f('0x23')]=function(_0x1c4002,_0x48d43c){return db[_0x3f5f('0x29')]['find']({'where':{'id':_0x1c4002[_0x3f5f('0x42')]['id']}})[_0x3f5f('0x22')](handleEntityNotFound(_0x48d43c,null))[_0x3f5f('0x22')](removeEntity(_0x48d43c,null))[_0x3f5f('0x41')](handleError(_0x48d43c,null));};