Built motion from commit (unavailable).|2.5.14
[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 _0x7f7f=['options','count','includeAll','include','findAll','rows','catch','show','params','create','body','find','html-pdf','eml-format','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','ejs','lodash','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','sendStatus','status','end','json','offset','set','Content-Range','save','update','then','destroy','error','name','send','index','map','MailServerOut','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','limit','sort','where','filter','merge','VIRTUAL'];(function(_0x35887c,_0x5ae247){var _0x2a5458=function(_0x27a21e){while(--_0x27a21e){_0x35887c['push'](_0x35887c['shift']());}};_0x2a5458(++_0x5ae247);}(_0x7f7f,0x1c2));var _0xf7f7=function(_0x393cf4,_0x5902d8){_0x393cf4=_0x393cf4-0x0;var _0x36ffce=_0x7f7f[_0x393cf4];return _0x36ffce;};'use strict';var pdf=require(_0xf7f7('0x0'));var emlformat=require(_0xf7f7('0x1'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0xf7f7('0x2'));var rp=require(_0xf7f7('0x3'));var moment=require(_0xf7f7('0x4'));var BPromise=require(_0xf7f7('0x5'));var Mustache=require(_0xf7f7('0x6'));var util=require(_0xf7f7('0x7'));var path=require(_0xf7f7('0x8'));var sox=require(_0xf7f7('0x9'));var csv=require('to-csv');var ejs=require(_0xf7f7('0xa'));var fs=require('fs');var _=require(_0xf7f7('0xb'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0xf7f7('0xc'));var deskjs=require(_0xf7f7('0xd'));var toCsv=require(_0xf7f7('0xe'));var querystring=require(_0xf7f7('0xf'));var Papa=require(_0xf7f7('0x10'));var Redis=require(_0xf7f7('0x11'));var authService=require(_0xf7f7('0x12'));var qs=require('../../components/parsers/qs');var as=require(_0xf7f7('0x13'));var hardwareService=require(_0xf7f7('0x14'));var logger=require(_0xf7f7('0x15'))('api');var utils=require(_0xf7f7('0x16'));var config=require(_0xf7f7('0x17'));var licenseUtil=require(_0xf7f7('0x18'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x4f8ca3,_0x4174ee){_0x4174ee=_0x4174ee||0xcc;return function(_0x1ebce7){if(_0x1ebce7){return _0x4f8ca3[_0xf7f7('0x19')](_0x4174ee);}return _0x4f8ca3[_0xf7f7('0x1a')](_0x4174ee)[_0xf7f7('0x1b')]();};}function respondWithResult(_0x2bf712,_0x14d571){_0x14d571=_0x14d571||0xc8;return function(_0x24d75a){if(_0x24d75a){return _0x2bf712[_0xf7f7('0x1a')](_0x14d571)[_0xf7f7('0x1c')](_0x24d75a);}};}function respondWithFilteredResult(_0x389918,_0x200e0f){return function(_0xecc55d){if(_0xecc55d){var _0x1852e7=_0xecc55d['count'],_0x2c0f06=_0x200e0f[_0xf7f7('0x1d')],_0x4bc8d9=_0x200e0f[_0xf7f7('0x1d')]+_0x200e0f['limit'],_0x2f8a0e;if(_0x4bc8d9>=_0x1852e7){_0x4bc8d9=_0x1852e7;_0x2f8a0e=0xc8;}else{_0x2f8a0e=0xce;}_0x389918[_0xf7f7('0x1a')](_0x2f8a0e);return _0x389918[_0xf7f7('0x1e')](_0xf7f7('0x1f'),_0x2c0f06+'-'+_0x4bc8d9+'/'+_0x1852e7)[_0xf7f7('0x1c')](_0xecc55d);}return null;};}function patchUpdates(_0x3e6712){return function(_0x14caf7){try{jsonpatch['apply'](_0x14caf7,_0x3e6712,!![]);}catch(_0x288d8b){return BPromise['reject'](_0x288d8b);}return _0x14caf7[_0xf7f7('0x20')]();};}function saveUpdates(_0x4839e8,_0x5a2b49){return function(_0x912948){if(_0x912948){return _0x912948[_0xf7f7('0x21')](_0x4839e8)[_0xf7f7('0x22')](function(_0x584a7c){return _0x584a7c;});}return null;};}function removeEntity(_0x3ceec0,_0x389ef1){return function(_0x13ebe4){if(_0x13ebe4){return _0x13ebe4[_0xf7f7('0x23')]()['then'](function(){_0x3ceec0[_0xf7f7('0x1a')](0xcc)[_0xf7f7('0x1b')]();});}};}function handleEntityNotFound(_0x24a53e,_0x1493e0){return function(_0x388d4b){if(!_0x388d4b){_0x24a53e[_0xf7f7('0x19')](0x194);}return _0x388d4b;};}function handleError(_0x42b539,_0x398640){_0x398640=_0x398640||0x1f4;return function(_0x561013){logger[_0xf7f7('0x24')](_0x561013['stack']);if(_0x561013[_0xf7f7('0x25')]){delete _0x561013[_0xf7f7('0x25')];}_0x42b539['status'](_0x398640)[_0xf7f7('0x26')](_0x561013);};}exports[_0xf7f7('0x27')]=function(_0x336463,_0x262706){var _0x1f124c={},_0x5ccc0c={},_0x9166df={'count':0x0,'rows':[]};var _0x4eb256=_[_0xf7f7('0x28')](db[_0xf7f7('0x29')]['rawAttributes'],function(_0x5e6612){return{'name':_0x5e6612[_0xf7f7('0x2a')],'type':_0x5e6612[_0xf7f7('0x2b')][_0xf7f7('0x2c')]};});_0x5ccc0c[_0xf7f7('0x2d')]=_[_0xf7f7('0x28')](_0x4eb256,_0xf7f7('0x25'));_0x5ccc0c[_0xf7f7('0x2e')]=_[_0xf7f7('0x2f')](_0x336463['query']);_0x5ccc0c[_0xf7f7('0x30')]=_[_0xf7f7('0x31')](_0x5ccc0c[_0xf7f7('0x2d')],_0x5ccc0c['query']);_0x1f124c[_0xf7f7('0x32')]=_[_0xf7f7('0x31')](_0x5ccc0c['model'],qs[_0xf7f7('0x33')](_0x336463[_0xf7f7('0x2e')][_0xf7f7('0x33')]));_0x1f124c[_0xf7f7('0x32')]=_0x1f124c[_0xf7f7('0x32')][_0xf7f7('0x34')]?_0x1f124c['attributes']:_0x5ccc0c[_0xf7f7('0x2d')];if(!_0x336463[_0xf7f7('0x2e')][_0xf7f7('0x35')](_0xf7f7('0x36'))){_0x1f124c[_0xf7f7('0x37')]=qs[_0xf7f7('0x37')](_0x336463['query'][_0xf7f7('0x37')]);_0x1f124c[_0xf7f7('0x1d')]=qs[_0xf7f7('0x1d')](_0x336463[_0xf7f7('0x2e')][_0xf7f7('0x1d')]);}_0x1f124c['order']=qs[_0xf7f7('0x38')](_0x336463['query'][_0xf7f7('0x38')]);_0x1f124c[_0xf7f7('0x39')]=qs['filters'](_['pick'](_0x336463[_0xf7f7('0x2e')],_0x5ccc0c[_0xf7f7('0x30')]),_0x4eb256);if(_0x336463['query'][_0xf7f7('0x3a')]){_0x1f124c[_0xf7f7('0x39')]=_[_0xf7f7('0x3b')](_0x1f124c['where'],{'$or':_[_0xf7f7('0x28')](_0x4eb256,function(_0x36925f){if(_0x36925f[_0xf7f7('0x2b')]!==_0xf7f7('0x3c')){var _0x3f3e54={};_0x3f3e54[_0x36925f[_0xf7f7('0x25')]]={'$like':'%'+_0x336463[_0xf7f7('0x2e')][_0xf7f7('0x3a')]+'%'};return _0x3f3e54;}})});}_0x1f124c=_[_0xf7f7('0x3b')]({},_0x1f124c,_0x336463[_0xf7f7('0x3d')]);var _0x32c32b={'where':_0x1f124c[_0xf7f7('0x39')]};return db[_0xf7f7('0x29')][_0xf7f7('0x3e')](_0x32c32b)[_0xf7f7('0x22')](function(_0x13fcfa){_0x9166df[_0xf7f7('0x3e')]=_0x13fcfa;if(_0x336463['query'][_0xf7f7('0x3f')]){_0x1f124c[_0xf7f7('0x40')]=[{'all':!![]}];}return db[_0xf7f7('0x29')][_0xf7f7('0x41')](_0x1f124c);})[_0xf7f7('0x22')](function(_0x53d688){_0x9166df[_0xf7f7('0x42')]=_0x53d688;return _0x9166df;})['then'](respondWithFilteredResult(_0x262706,_0x1f124c))[_0xf7f7('0x43')](handleError(_0x262706,null));};exports[_0xf7f7('0x44')]=function(_0x16fab7,_0x2f1554){var _0x413551={'raw':!![],'where':{'id':_0x16fab7[_0xf7f7('0x45')]['id']}},_0x1dbb06={};_0x1dbb06[_0xf7f7('0x2d')]=_[_0xf7f7('0x2f')](db[_0xf7f7('0x29')]['rawAttributes']);_0x1dbb06[_0xf7f7('0x2e')]=_[_0xf7f7('0x2f')](_0x16fab7['query']);_0x1dbb06['filters']=_[_0xf7f7('0x31')](_0x1dbb06['model'],_0x1dbb06[_0xf7f7('0x2e')]);_0x413551[_0xf7f7('0x32')]=_[_0xf7f7('0x31')](_0x1dbb06[_0xf7f7('0x2d')],qs[_0xf7f7('0x33')](_0x16fab7['query']['fields']));_0x413551[_0xf7f7('0x32')]=_0x413551['attributes'][_0xf7f7('0x34')]?_0x413551[_0xf7f7('0x32')]:_0x1dbb06[_0xf7f7('0x2d')];if(_0x16fab7[_0xf7f7('0x2e')][_0xf7f7('0x3f')]){_0x413551['include']=[{'all':!![]}];}_0x413551=_[_0xf7f7('0x3b')]({},_0x413551,_0x16fab7[_0xf7f7('0x3d')]);return db[_0xf7f7('0x29')]['find'](_0x413551)[_0xf7f7('0x22')](handleEntityNotFound(_0x2f1554,null))['then'](respondWithResult(_0x2f1554,null))[_0xf7f7('0x43')](handleError(_0x2f1554,null));};exports['create']=function(_0x597e25,_0x34fe77){return db[_0xf7f7('0x29')][_0xf7f7('0x46')](_0x597e25[_0xf7f7('0x47')],{})['then'](respondWithResult(_0x34fe77,0xc9))[_0xf7f7('0x43')](handleError(_0x34fe77,null));};exports['update']=function(_0x7c84b,_0x5970df){if(_0x7c84b['body']['id']){delete _0x7c84b[_0xf7f7('0x47')]['id'];}return db[_0xf7f7('0x29')][_0xf7f7('0x48')]({'where':{'id':_0x7c84b[_0xf7f7('0x45')]['id']}})['then'](handleEntityNotFound(_0x5970df,null))[_0xf7f7('0x22')](saveUpdates(_0x7c84b[_0xf7f7('0x47')],null))[_0xf7f7('0x22')](respondWithResult(_0x5970df,null))[_0xf7f7('0x43')](handleError(_0x5970df,null));};exports[_0xf7f7('0x23')]=function(_0x31a402,_0x471298){return db[_0xf7f7('0x29')]['find']({'where':{'id':_0x31a402[_0xf7f7('0x45')]['id']}})['then'](handleEntityNotFound(_0x471298,null))[_0xf7f7('0x22')](removeEntity(_0x471298,null))[_0xf7f7('0x43')](handleError(_0x471298,null));};