Built motion from commit (unavailable).|2.5.4
[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 _0xf263=['ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','sendStatus','status','count','offset','Content-Range','json','apply','update','then','destroy','end','error','name','map','MailServerOut','rawAttributes','type','key','model','keys','query','filters','attributes','intersection','hasOwnProperty','limit','order','sort','where','pick','filter','VIRTUAL','merge','options','includeAll','include','findAll','rows','catch','show','params','create','body','find','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','moment','mustache','util','path','sox','ejs','lodash','jsforce','desk.js','to-csv','papaparse'];(function(_0x22c684,_0x753309){var _0x39fcbb=function(_0x38b631){while(--_0x38b631){_0x22c684['push'](_0x22c684['shift']());}};_0x39fcbb(++_0x753309);}(_0xf263,0x149));var _0x3f26=function(_0x12ddb2,_0x5ad61e){_0x12ddb2=_0x12ddb2-0x0;var _0x10b6dd=_0xf263[_0x12ddb2];return _0x10b6dd;};'use strict';var pdf=require(_0x3f26('0x0'));var emlformat=require(_0x3f26('0x1'));var rimraf=require(_0x3f26('0x2'));var zipdir=require(_0x3f26('0x3'));var jsonpatch=require(_0x3f26('0x4'));var rp=require('request-promise');var moment=require(_0x3f26('0x5'));var BPromise=require('bluebird');var Mustache=require(_0x3f26('0x6'));var util=require(_0x3f26('0x7'));var path=require(_0x3f26('0x8'));var sox=require(_0x3f26('0x9'));var csv=require('to-csv');var ejs=require(_0x3f26('0xa'));var fs=require('fs');var _=require(_0x3f26('0xb'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0x3f26('0xc'));var deskjs=require(_0x3f26('0xd'));var toCsv=require(_0x3f26('0xe'));var querystring=require('querystring');var Papa=require(_0x3f26('0xf'));var Redis=require(_0x3f26('0x10'));var authService=require(_0x3f26('0x11'));var qs=require(_0x3f26('0x12'));var as=require(_0x3f26('0x13'));var hardwareService=require(_0x3f26('0x14'));var logger=require(_0x3f26('0x15'))(_0x3f26('0x16'));var utils=require(_0x3f26('0x17'));var config=require(_0x3f26('0x18'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x5ab0ef,_0x258b7f){_0x258b7f=_0x258b7f||0xcc;return function(_0x1ad495){if(_0x1ad495){return _0x5ab0ef[_0x3f26('0x19')](_0x258b7f);}return _0x5ab0ef[_0x3f26('0x1a')](_0x258b7f)['end']();};}function respondWithResult(_0x1802e4,_0x227655){_0x227655=_0x227655||0xc8;return function(_0x3f69c0){if(_0x3f69c0){return _0x1802e4[_0x3f26('0x1a')](_0x227655)['json'](_0x3f69c0);}};}function respondWithFilteredResult(_0x3d18ae,_0x1ce98c){return function(_0x37ee5c){if(_0x37ee5c){var _0x414672=_0x37ee5c[_0x3f26('0x1b')],_0x577ca3=_0x1ce98c[_0x3f26('0x1c')],_0x96bd2d=_0x1ce98c[_0x3f26('0x1c')]+_0x1ce98c['limit'],_0x2b9cd9;if(_0x96bd2d>=_0x414672){_0x96bd2d=_0x414672;_0x2b9cd9=0xc8;}else{_0x2b9cd9=0xce;}_0x3d18ae['status'](_0x2b9cd9);return _0x3d18ae['set'](_0x3f26('0x1d'),_0x577ca3+'-'+_0x96bd2d+'/'+_0x414672)[_0x3f26('0x1e')](_0x37ee5c);}return null;};}function patchUpdates(_0x54e79b){return function(_0x346461){try{jsonpatch[_0x3f26('0x1f')](_0x346461,_0x54e79b,!![]);}catch(_0x53b245){return BPromise['reject'](_0x53b245);}return _0x346461['save']();};}function saveUpdates(_0x3080f2,_0x20fe9c){return function(_0x4a8fcf){if(_0x4a8fcf){return _0x4a8fcf[_0x3f26('0x20')](_0x3080f2)[_0x3f26('0x21')](function(_0x172a07){return _0x172a07;});}return null;};}function removeEntity(_0x191a22,_0x254638){return function(_0x5a228f){if(_0x5a228f){return _0x5a228f[_0x3f26('0x22')]()[_0x3f26('0x21')](function(){_0x191a22[_0x3f26('0x1a')](0xcc)[_0x3f26('0x23')]();});}};}function handleEntityNotFound(_0x230400,_0x8d9aa1){return function(_0x272d05){if(!_0x272d05){_0x230400[_0x3f26('0x19')](0x194);}return _0x272d05;};}function handleError(_0x335584,_0xd5d467){_0xd5d467=_0xd5d467||0x1f4;return function(_0x12a0df){logger[_0x3f26('0x24')](_0x12a0df['stack']);if(_0x12a0df[_0x3f26('0x25')]){delete _0x12a0df[_0x3f26('0x25')];}_0x335584[_0x3f26('0x1a')](_0xd5d467)['send'](_0x12a0df);};}exports['index']=function(_0x16effb,_0x1eab9c){var _0x279057={},_0x2e48b2={},_0x1880d8={'count':0x0,'rows':[]};var _0x379001=_[_0x3f26('0x26')](db[_0x3f26('0x27')][_0x3f26('0x28')],function(_0x2bbf11){return{'name':_0x2bbf11['fieldName'],'type':_0x2bbf11[_0x3f26('0x29')][_0x3f26('0x2a')]};});_0x2e48b2[_0x3f26('0x2b')]=_['map'](_0x379001,'name');_0x2e48b2['query']=_[_0x3f26('0x2c')](_0x16effb[_0x3f26('0x2d')]);_0x2e48b2[_0x3f26('0x2e')]=_['intersection'](_0x2e48b2[_0x3f26('0x2b')],_0x2e48b2['query']);_0x279057[_0x3f26('0x2f')]=_[_0x3f26('0x30')](_0x2e48b2[_0x3f26('0x2b')],qs['fields'](_0x16effb[_0x3f26('0x2d')]['fields']));_0x279057[_0x3f26('0x2f')]=_0x279057[_0x3f26('0x2f')]['length']?_0x279057[_0x3f26('0x2f')]:_0x2e48b2[_0x3f26('0x2b')];if(!_0x16effb[_0x3f26('0x2d')][_0x3f26('0x31')]('nolimit')){_0x279057[_0x3f26('0x32')]=qs[_0x3f26('0x32')](_0x16effb[_0x3f26('0x2d')][_0x3f26('0x32')]);_0x279057[_0x3f26('0x1c')]=qs[_0x3f26('0x1c')](_0x16effb[_0x3f26('0x2d')]['offset']);}_0x279057[_0x3f26('0x33')]=qs[_0x3f26('0x34')](_0x16effb['query']['sort']);_0x279057[_0x3f26('0x35')]=qs['filters'](_[_0x3f26('0x36')](_0x16effb[_0x3f26('0x2d')],_0x2e48b2[_0x3f26('0x2e')]),_0x379001);if(_0x16effb['query'][_0x3f26('0x37')]){_0x279057[_0x3f26('0x35')]=_['merge'](_0x279057[_0x3f26('0x35')],{'$or':_[_0x3f26('0x26')](_0x379001,function(_0x3da11f){if(_0x3da11f[_0x3f26('0x29')]!==_0x3f26('0x38')){var _0x15106d={};_0x15106d[_0x3da11f[_0x3f26('0x25')]]={'$like':'%'+_0x16effb[_0x3f26('0x2d')][_0x3f26('0x37')]+'%'};return _0x15106d;}})});}_0x279057=_[_0x3f26('0x39')]({},_0x279057,_0x16effb[_0x3f26('0x3a')]);var _0x29212b={'where':_0x279057[_0x3f26('0x35')]};return db[_0x3f26('0x27')][_0x3f26('0x1b')](_0x29212b)['then'](function(_0x5edd7b){_0x1880d8[_0x3f26('0x1b')]=_0x5edd7b;if(_0x16effb[_0x3f26('0x2d')][_0x3f26('0x3b')]){_0x279057[_0x3f26('0x3c')]=[{'all':!![]}];}return db[_0x3f26('0x27')][_0x3f26('0x3d')](_0x279057);})[_0x3f26('0x21')](function(_0x3d1050){_0x1880d8[_0x3f26('0x3e')]=_0x3d1050;return _0x1880d8;})[_0x3f26('0x21')](respondWithFilteredResult(_0x1eab9c,_0x279057))[_0x3f26('0x3f')](handleError(_0x1eab9c,null));};exports[_0x3f26('0x40')]=function(_0x3b33a3,_0x38c07e){var _0x5161dc={'raw':!![],'where':{'id':_0x3b33a3[_0x3f26('0x41')]['id']}},_0x3bb322={};_0x3bb322[_0x3f26('0x2b')]=_[_0x3f26('0x2c')](db[_0x3f26('0x27')][_0x3f26('0x28')]);_0x3bb322[_0x3f26('0x2d')]=_['keys'](_0x3b33a3['query']);_0x3bb322['filters']=_['intersection'](_0x3bb322[_0x3f26('0x2b')],_0x3bb322['query']);_0x5161dc[_0x3f26('0x2f')]=_[_0x3f26('0x30')](_0x3bb322['model'],qs['fields'](_0x3b33a3[_0x3f26('0x2d')]['fields']));_0x5161dc[_0x3f26('0x2f')]=_0x5161dc[_0x3f26('0x2f')]['length']?_0x5161dc[_0x3f26('0x2f')]:_0x3bb322['model'];if(_0x3b33a3[_0x3f26('0x2d')][_0x3f26('0x3b')]){_0x5161dc['include']=[{'all':!![]}];}_0x5161dc=_[_0x3f26('0x39')]({},_0x5161dc,_0x3b33a3[_0x3f26('0x3a')]);return db[_0x3f26('0x27')]['find'](_0x5161dc)[_0x3f26('0x21')](handleEntityNotFound(_0x38c07e,null))[_0x3f26('0x21')](respondWithResult(_0x38c07e,null))[_0x3f26('0x3f')](handleError(_0x38c07e,null));};exports[_0x3f26('0x42')]=function(_0x129d4a,_0x7ead3){return db[_0x3f26('0x27')]['create'](_0x129d4a[_0x3f26('0x43')],{})[_0x3f26('0x21')](respondWithResult(_0x7ead3,0xc9))['catch'](handleError(_0x7ead3,null));};exports[_0x3f26('0x20')]=function(_0x3131d4,_0x39701c){if(_0x3131d4['body']['id']){delete _0x3131d4[_0x3f26('0x43')]['id'];}return db[_0x3f26('0x27')][_0x3f26('0x44')]({'where':{'id':_0x3131d4[_0x3f26('0x41')]['id']}})[_0x3f26('0x21')](handleEntityNotFound(_0x39701c,null))['then'](saveUpdates(_0x3131d4[_0x3f26('0x43')],null))[_0x3f26('0x21')](respondWithResult(_0x39701c,null))[_0x3f26('0x3f')](handleError(_0x39701c,null));};exports[_0x3f26('0x22')]=function(_0x493769,_0x2feabf){return db[_0x3f26('0x27')][_0x3f26('0x44')]({'where':{'id':_0x493769[_0x3f26('0x41')]['id']}})[_0x3f26('0x21')](handleEntityNotFound(_0x2feabf,null))[_0x3f26('0x21')](removeEntity(_0x2feabf,null))[_0x3f26('0x3f')](handleError(_0x2feabf,null));};