Built motion from commit 3c2ce842.|2.6.31
[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 _0xd4da=['rimraf','zip-dir','request-promise','moment','bluebird','mustache','path','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','offset','limit','undefined','count','set','Content-Range','apply','reject','save','update','then','destroy','stack','name','index','map','MailServerOut','fieldName','key','model','query','keys','filters','intersection','attributes','fields','hasOwnProperty','nolimit','order','sort','where','pick','filter','VIRTUAL','merge','includeAll','findAll','rows','catch','show','params','rawAttributes','length','include','options','create','body','find','eml-format'];(function(_0x6f96e6,_0x23ea02){var _0xec6891=function(_0x1d7ccd){while(--_0x1d7ccd){_0x6f96e6['push'](_0x6f96e6['shift']());}};_0xec6891(++_0x23ea02);}(_0xd4da,0x9d));var _0xad4d=function(_0x20a584,_0xe384a5){_0x20a584=_0x20a584-0x0;var _0x4b41a8=_0xd4da[_0x20a584];return _0x4b41a8;};'use strict';var emlformat=require(_0xad4d('0x0'));var rimraf=require(_0xad4d('0x1'));var zipdir=require(_0xad4d('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xad4d('0x3'));var moment=require(_0xad4d('0x4'));var BPromise=require(_0xad4d('0x5'));var Mustache=require(_0xad4d('0x6'));var util=require('util');var path=require(_0xad4d('0x7'));var sox=require('sox');var csv=require(_0xad4d('0x8'));var ejs=require(_0xad4d('0x9'));var fs=require('fs');var fs_extra=require(_0xad4d('0xa'));var _=require(_0xad4d('0xb'));var squel=require(_0xad4d('0xc'));var crypto=require(_0xad4d('0xd'));var jsforce=require(_0xad4d('0xe'));var deskjs=require(_0xad4d('0xf'));var toCsv=require(_0xad4d('0x8'));var querystring=require(_0xad4d('0x10'));var Papa=require(_0xad4d('0x11'));var Redis=require(_0xad4d('0x12'));var authService=require(_0xad4d('0x13'));var qs=require(_0xad4d('0x14'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xad4d('0x15'));var logger=require(_0xad4d('0x16'))(_0xad4d('0x17'));var utils=require(_0xad4d('0x18'));var config=require(_0xad4d('0x19'));var licenseUtil=require(_0xad4d('0x1a'));var db=require(_0xad4d('0x1b'))['db'];function respondWithStatusCode(_0x52e9ff,_0x567ea5){_0x567ea5=_0x567ea5||0xcc;return function(_0x201b5d){if(_0x201b5d){return _0x52e9ff[_0xad4d('0x1c')](_0x567ea5);}return _0x52e9ff[_0xad4d('0x1d')](_0x567ea5)['end']();};}function respondWithResult(_0x4ef07e,_0x489d77){_0x489d77=_0x489d77||0xc8;return function(_0x57a47c){if(_0x57a47c){return _0x4ef07e[_0xad4d('0x1d')](_0x489d77)[_0xad4d('0x1e')](_0x57a47c);}};}function respondWithFilteredResult(_0x25c8ae,_0x3b64ce){return function(_0x4e3659){if(_0x4e3659){var _0x247eb2=typeof _0x3b64ce[_0xad4d('0x1f')]==='undefined'&&typeof _0x3b64ce[_0xad4d('0x20')]===_0xad4d('0x21');var _0x190277=_0x4e3659[_0xad4d('0x22')];var _0x47a751=_0x247eb2?0x0:_0x3b64ce[_0xad4d('0x1f')];var _0x5d4bc7=_0x247eb2?_0x4e3659['count']:_0x3b64ce['offset']+_0x3b64ce[_0xad4d('0x20')];var _0x5209be;if(_0x5d4bc7>=_0x190277){_0x5d4bc7=_0x190277;_0x5209be=0xc8;}else{_0x5209be=0xce;}_0x25c8ae[_0xad4d('0x1d')](_0x5209be);return _0x25c8ae[_0xad4d('0x23')](_0xad4d('0x24'),_0x47a751+'-'+_0x5d4bc7+'/'+_0x190277)[_0xad4d('0x1e')](_0x4e3659);}return null;};}function patchUpdates(_0x125c89){return function(_0x51863d){try{jsonpatch[_0xad4d('0x25')](_0x51863d,_0x125c89,!![]);}catch(_0x42ff58){return BPromise[_0xad4d('0x26')](_0x42ff58);}return _0x51863d[_0xad4d('0x27')]();};}function saveUpdates(_0x547569,_0x114037){return function(_0x18f64b){if(_0x18f64b){return _0x18f64b[_0xad4d('0x28')](_0x547569)[_0xad4d('0x29')](function(_0x47e4fd){return _0x47e4fd;});}return null;};}function removeEntity(_0x546c52,_0x331e4b){return function(_0x3601f8){if(_0x3601f8){return _0x3601f8[_0xad4d('0x2a')]()[_0xad4d('0x29')](function(){_0x546c52[_0xad4d('0x1d')](0xcc)['end']();});}};}function handleEntityNotFound(_0x47a20b,_0x267b7f){return function(_0x216b59){if(!_0x216b59){_0x47a20b[_0xad4d('0x1c')](0x194);}return _0x216b59;};}function handleError(_0x66dab2,_0xbde7a0){_0xbde7a0=_0xbde7a0||0x1f4;return function(_0xac0d87){logger['error'](_0xac0d87[_0xad4d('0x2b')]);if(_0xac0d87[_0xad4d('0x2c')]){delete _0xac0d87[_0xad4d('0x2c')];}_0x66dab2[_0xad4d('0x1d')](_0xbde7a0)['send'](_0xac0d87);};}exports[_0xad4d('0x2d')]=function(_0x55e4d2,_0x3ab255){var _0x425f8b={},_0x5b3366={},_0x9edf2a={'count':0x0,'rows':[]};var _0x3dded8=_[_0xad4d('0x2e')](db[_0xad4d('0x2f')]['rawAttributes'],function(_0x281a09){return{'name':_0x281a09[_0xad4d('0x30')],'type':_0x281a09['type'][_0xad4d('0x31')]};});_0x5b3366[_0xad4d('0x32')]=_[_0xad4d('0x2e')](_0x3dded8,_0xad4d('0x2c'));_0x5b3366[_0xad4d('0x33')]=_[_0xad4d('0x34')](_0x55e4d2[_0xad4d('0x33')]);_0x5b3366[_0xad4d('0x35')]=_[_0xad4d('0x36')](_0x5b3366[_0xad4d('0x32')],_0x5b3366[_0xad4d('0x33')]);_0x425f8b[_0xad4d('0x37')]=_[_0xad4d('0x36')](_0x5b3366[_0xad4d('0x32')],qs[_0xad4d('0x38')](_0x55e4d2['query'][_0xad4d('0x38')]));_0x425f8b['attributes']=_0x425f8b[_0xad4d('0x37')]['length']?_0x425f8b[_0xad4d('0x37')]:_0x5b3366[_0xad4d('0x32')];if(!_0x55e4d2['query'][_0xad4d('0x39')](_0xad4d('0x3a'))){_0x425f8b['limit']=qs[_0xad4d('0x20')](_0x55e4d2[_0xad4d('0x33')][_0xad4d('0x20')]);_0x425f8b['offset']=qs[_0xad4d('0x1f')](_0x55e4d2[_0xad4d('0x33')]['offset']);}_0x425f8b[_0xad4d('0x3b')]=qs[_0xad4d('0x3c')](_0x55e4d2[_0xad4d('0x33')][_0xad4d('0x3c')]);_0x425f8b[_0xad4d('0x3d')]=qs[_0xad4d('0x35')](_[_0xad4d('0x3e')](_0x55e4d2['query'],_0x5b3366['filters']),_0x3dded8);if(_0x55e4d2[_0xad4d('0x33')][_0xad4d('0x3f')]){_0x425f8b[_0xad4d('0x3d')]=_['merge'](_0x425f8b['where'],{'$or':_[_0xad4d('0x2e')](_0x3dded8,function(_0x55583f){if(_0x55583f['type']!==_0xad4d('0x40')){var _0x5b276b={};_0x5b276b[_0x55583f[_0xad4d('0x2c')]]={'$like':'%'+_0x55e4d2[_0xad4d('0x33')][_0xad4d('0x3f')]+'%'};return _0x5b276b;}})});}_0x425f8b=_[_0xad4d('0x41')]({},_0x425f8b,_0x55e4d2['options']);var _0x4a3968={'where':_0x425f8b[_0xad4d('0x3d')]};return db[_0xad4d('0x2f')][_0xad4d('0x22')](_0x4a3968)[_0xad4d('0x29')](function(_0x4e7fb4){_0x9edf2a[_0xad4d('0x22')]=_0x4e7fb4;if(_0x55e4d2['query'][_0xad4d('0x42')]){_0x425f8b['include']=[{'all':!![]}];}return db[_0xad4d('0x2f')][_0xad4d('0x43')](_0x425f8b);})[_0xad4d('0x29')](function(_0x33e4e0){_0x9edf2a[_0xad4d('0x44')]=_0x33e4e0;return _0x9edf2a;})[_0xad4d('0x29')](respondWithFilteredResult(_0x3ab255,_0x425f8b))[_0xad4d('0x45')](handleError(_0x3ab255,null));};exports[_0xad4d('0x46')]=function(_0xcc5d88,_0x1cf34b){var _0x50f949={'raw':!![],'where':{'id':_0xcc5d88[_0xad4d('0x47')]['id']}},_0x9d638e={};_0x9d638e['model']=_[_0xad4d('0x34')](db[_0xad4d('0x2f')][_0xad4d('0x48')]);_0x9d638e[_0xad4d('0x33')]=_[_0xad4d('0x34')](_0xcc5d88[_0xad4d('0x33')]);_0x9d638e['filters']=_['intersection'](_0x9d638e[_0xad4d('0x32')],_0x9d638e[_0xad4d('0x33')]);_0x50f949[_0xad4d('0x37')]=_[_0xad4d('0x36')](_0x9d638e[_0xad4d('0x32')],qs[_0xad4d('0x38')](_0xcc5d88[_0xad4d('0x33')][_0xad4d('0x38')]));_0x50f949['attributes']=_0x50f949[_0xad4d('0x37')][_0xad4d('0x49')]?_0x50f949[_0xad4d('0x37')]:_0x9d638e[_0xad4d('0x32')];if(_0xcc5d88[_0xad4d('0x33')]['includeAll']){_0x50f949[_0xad4d('0x4a')]=[{'all':!![]}];}_0x50f949=_['merge']({},_0x50f949,_0xcc5d88[_0xad4d('0x4b')]);return db[_0xad4d('0x2f')]['find'](_0x50f949)[_0xad4d('0x29')](handleEntityNotFound(_0x1cf34b,null))[_0xad4d('0x29')](respondWithResult(_0x1cf34b,null))[_0xad4d('0x45')](handleError(_0x1cf34b,null));};exports[_0xad4d('0x4c')]=function(_0x9cb118,_0x18d1f7){return db[_0xad4d('0x2f')][_0xad4d('0x4c')](_0x9cb118['body'],{})[_0xad4d('0x29')](respondWithResult(_0x18d1f7,0xc9))[_0xad4d('0x45')](handleError(_0x18d1f7,null));};exports[_0xad4d('0x28')]=function(_0x329085,_0x2567c3){if(_0x329085[_0xad4d('0x4d')]['id']){delete _0x329085[_0xad4d('0x4d')]['id'];}return db[_0xad4d('0x2f')][_0xad4d('0x4e')]({'where':{'id':_0x329085[_0xad4d('0x47')]['id']}})['then'](handleEntityNotFound(_0x2567c3,null))[_0xad4d('0x29')](saveUpdates(_0x329085['body'],null))[_0xad4d('0x29')](respondWithResult(_0x2567c3,null))[_0xad4d('0x45')](handleError(_0x2567c3,null));};exports[_0xad4d('0x2a')]=function(_0x2ec8be,_0x3ecd1d){return db[_0xad4d('0x2f')][_0xad4d('0x4e')]({'where':{'id':_0x2ec8be[_0xad4d('0x47')]['id']}})[_0xad4d('0x29')](handleEntityNotFound(_0x3ecd1d,null))[_0xad4d('0x29')](removeEntity(_0x3ecd1d,null))[_0xad4d('0x45')](handleError(_0x3ecd1d,null));};