40cd5d08c3b6e19fac3b24ac454c8e5fe1081d3c
[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 _0xad64=['params','rawAttributes','length','includeAll','include','find','create','body','eml-format','rimraf','fast-json-patch','moment','bluebird','mustache','path','to-csv','fs-extra','lodash','crypto','jsforce','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','reject','save','update','destroy','then','error','name','send','index','MailServerOut','fieldName','model','map','query','keys','filters','intersection','attributes','fields','hasOwnProperty','nolimit','order','sort','where','filter','merge','type','options','findAll','rows','catch'];(function(_0x176d98,_0x3e7382){var _0x47a82c=function(_0x4a74b3){while(--_0x4a74b3){_0x176d98['push'](_0x176d98['shift']());}};_0x47a82c(++_0x3e7382);}(_0xad64,0x1b2));var _0x4ad6=function(_0x12a429,_0x1df9cc){_0x12a429=_0x12a429-0x0;var _0x2f0688=_0xad64[_0x12a429];return _0x2f0688;};'use strict';var emlformat=require(_0x4ad6('0x0'));var rimraf=require(_0x4ad6('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x4ad6('0x2'));var rp=require('request-promise');var moment=require(_0x4ad6('0x3'));var BPromise=require(_0x4ad6('0x4'));var Mustache=require(_0x4ad6('0x5'));var util=require('util');var path=require(_0x4ad6('0x6'));var sox=require('sox');var csv=require(_0x4ad6('0x7'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x4ad6('0x8'));var _=require(_0x4ad6('0x9'));var squel=require('squel');var crypto=require(_0x4ad6('0xa'));var jsforce=require(_0x4ad6('0xb'));var deskjs=require('desk.js');var toCsv=require(_0x4ad6('0x7'));var querystring=require('querystring');var Papa=require(_0x4ad6('0xc'));var Redis=require(_0x4ad6('0xd'));var authService=require(_0x4ad6('0xe'));var qs=require(_0x4ad6('0xf'));var as=require(_0x4ad6('0x10'));var hardwareService=require(_0x4ad6('0x11'));var logger=require('../../config/logger')('api');var utils=require(_0x4ad6('0x12'));var config=require(_0x4ad6('0x13'));var licenseUtil=require(_0x4ad6('0x14'));var db=require(_0x4ad6('0x15'))['db'];function respondWithStatusCode(_0x51a6c9,_0x141ec8){_0x141ec8=_0x141ec8||0xcc;return function(_0xde36c2){if(_0xde36c2){return _0x51a6c9[_0x4ad6('0x16')](_0x141ec8);}return _0x51a6c9[_0x4ad6('0x17')](_0x141ec8)[_0x4ad6('0x18')]();};}function respondWithResult(_0x248bd6,_0x4aab93){_0x4aab93=_0x4aab93||0xc8;return function(_0x53eb92){if(_0x53eb92){return _0x248bd6[_0x4ad6('0x17')](_0x4aab93)[_0x4ad6('0x19')](_0x53eb92);}};}function respondWithFilteredResult(_0x2fa1ff,_0x842a09){return function(_0x57de03){if(_0x57de03){var _0x2c0e2f=typeof _0x842a09[_0x4ad6('0x1a')]===_0x4ad6('0x1b')&&typeof _0x842a09[_0x4ad6('0x1c')]===_0x4ad6('0x1b');var _0x2930cd=_0x57de03[_0x4ad6('0x1d')];var _0xd96536=_0x2c0e2f?0x0:_0x842a09['offset'];var _0x597ec6=_0x2c0e2f?_0x57de03[_0x4ad6('0x1d')]:_0x842a09[_0x4ad6('0x1a')]+_0x842a09[_0x4ad6('0x1c')];var _0x257d7b;if(_0x597ec6>=_0x2930cd){_0x597ec6=_0x2930cd;_0x257d7b=0xc8;}else{_0x257d7b=0xce;}_0x2fa1ff[_0x4ad6('0x17')](_0x257d7b);return _0x2fa1ff[_0x4ad6('0x1e')](_0x4ad6('0x1f'),_0xd96536+'-'+_0x597ec6+'/'+_0x2930cd)[_0x4ad6('0x19')](_0x57de03);}return null;};}function patchUpdates(_0x2e7a24){return function(_0xebbf3c){try{jsonpatch['apply'](_0xebbf3c,_0x2e7a24,!![]);}catch(_0x1dd30e){return BPromise[_0x4ad6('0x20')](_0x1dd30e);}return _0xebbf3c[_0x4ad6('0x21')]();};}function saveUpdates(_0x4645b4,_0x3e7eb1){return function(_0x18c99d){if(_0x18c99d){return _0x18c99d[_0x4ad6('0x22')](_0x4645b4)['then'](function(_0x29f190){return _0x29f190;});}return null;};}function removeEntity(_0x72fe50,_0x286a05){return function(_0x4c1790){if(_0x4c1790){return _0x4c1790[_0x4ad6('0x23')]()[_0x4ad6('0x24')](function(){_0x72fe50[_0x4ad6('0x17')](0xcc)['end']();});}};}function handleEntityNotFound(_0x1eb913,_0x1dc235){return function(_0x1282d8){if(!_0x1282d8){_0x1eb913['sendStatus'](0x194);}return _0x1282d8;};}function handleError(_0x2316d2,_0x2ee9ed){_0x2ee9ed=_0x2ee9ed||0x1f4;return function(_0x1e4d8f){logger[_0x4ad6('0x25')](_0x1e4d8f['stack']);if(_0x1e4d8f[_0x4ad6('0x26')]){delete _0x1e4d8f[_0x4ad6('0x26')];}_0x2316d2['status'](_0x2ee9ed)[_0x4ad6('0x27')](_0x1e4d8f);};}exports[_0x4ad6('0x28')]=function(_0x141d3c,_0x20fa9d){var _0x41b4ee={},_0x493015={},_0x133741={'count':0x0,'rows':[]};var _0xa1d101=_['map'](db[_0x4ad6('0x29')]['rawAttributes'],function(_0x1b6c95){return{'name':_0x1b6c95[_0x4ad6('0x2a')],'type':_0x1b6c95['type']['key']};});_0x493015[_0x4ad6('0x2b')]=_[_0x4ad6('0x2c')](_0xa1d101,_0x4ad6('0x26'));_0x493015[_0x4ad6('0x2d')]=_[_0x4ad6('0x2e')](_0x141d3c['query']);_0x493015[_0x4ad6('0x2f')]=_[_0x4ad6('0x30')](_0x493015[_0x4ad6('0x2b')],_0x493015[_0x4ad6('0x2d')]);_0x41b4ee[_0x4ad6('0x31')]=_['intersection'](_0x493015[_0x4ad6('0x2b')],qs['fields'](_0x141d3c[_0x4ad6('0x2d')][_0x4ad6('0x32')]));_0x41b4ee[_0x4ad6('0x31')]=_0x41b4ee[_0x4ad6('0x31')]['length']?_0x41b4ee['attributes']:_0x493015[_0x4ad6('0x2b')];if(!_0x141d3c[_0x4ad6('0x2d')][_0x4ad6('0x33')](_0x4ad6('0x34'))){_0x41b4ee['limit']=qs[_0x4ad6('0x1c')](_0x141d3c[_0x4ad6('0x2d')][_0x4ad6('0x1c')]);_0x41b4ee['offset']=qs['offset'](_0x141d3c[_0x4ad6('0x2d')][_0x4ad6('0x1a')]);}_0x41b4ee[_0x4ad6('0x35')]=qs['sort'](_0x141d3c[_0x4ad6('0x2d')][_0x4ad6('0x36')]);_0x41b4ee[_0x4ad6('0x37')]=qs[_0x4ad6('0x2f')](_['pick'](_0x141d3c[_0x4ad6('0x2d')],_0x493015[_0x4ad6('0x2f')]),_0xa1d101);if(_0x141d3c[_0x4ad6('0x2d')][_0x4ad6('0x38')]){_0x41b4ee[_0x4ad6('0x37')]=_[_0x4ad6('0x39')](_0x41b4ee[_0x4ad6('0x37')],{'$or':_[_0x4ad6('0x2c')](_0xa1d101,function(_0x2c4143){if(_0x2c4143[_0x4ad6('0x3a')]!=='VIRTUAL'){var _0x2c1885={};_0x2c1885[_0x2c4143[_0x4ad6('0x26')]]={'$like':'%'+_0x141d3c['query'][_0x4ad6('0x38')]+'%'};return _0x2c1885;}})});}_0x41b4ee=_[_0x4ad6('0x39')]({},_0x41b4ee,_0x141d3c[_0x4ad6('0x3b')]);var _0x2a68de={'where':_0x41b4ee[_0x4ad6('0x37')]};return db[_0x4ad6('0x29')][_0x4ad6('0x1d')](_0x2a68de)[_0x4ad6('0x24')](function(_0x4e9acc){_0x133741[_0x4ad6('0x1d')]=_0x4e9acc;if(_0x141d3c[_0x4ad6('0x2d')]['includeAll']){_0x41b4ee['include']=[{'all':!![]}];}return db['MailServerOut'][_0x4ad6('0x3c')](_0x41b4ee);})[_0x4ad6('0x24')](function(_0x1e4652){_0x133741[_0x4ad6('0x3d')]=_0x1e4652;return _0x133741;})[_0x4ad6('0x24')](respondWithFilteredResult(_0x20fa9d,_0x41b4ee))[_0x4ad6('0x3e')](handleError(_0x20fa9d,null));};exports['show']=function(_0x56215a,_0x39bdf8){var _0x2f0cb7={'raw':!![],'where':{'id':_0x56215a[_0x4ad6('0x3f')]['id']}},_0x5d2159={};_0x5d2159['model']=_[_0x4ad6('0x2e')](db['MailServerOut'][_0x4ad6('0x40')]);_0x5d2159[_0x4ad6('0x2d')]=_[_0x4ad6('0x2e')](_0x56215a[_0x4ad6('0x2d')]);_0x5d2159[_0x4ad6('0x2f')]=_['intersection'](_0x5d2159[_0x4ad6('0x2b')],_0x5d2159[_0x4ad6('0x2d')]);_0x2f0cb7[_0x4ad6('0x31')]=_[_0x4ad6('0x30')](_0x5d2159[_0x4ad6('0x2b')],qs[_0x4ad6('0x32')](_0x56215a[_0x4ad6('0x2d')][_0x4ad6('0x32')]));_0x2f0cb7[_0x4ad6('0x31')]=_0x2f0cb7['attributes'][_0x4ad6('0x41')]?_0x2f0cb7[_0x4ad6('0x31')]:_0x5d2159[_0x4ad6('0x2b')];if(_0x56215a[_0x4ad6('0x2d')][_0x4ad6('0x42')]){_0x2f0cb7[_0x4ad6('0x43')]=[{'all':!![]}];}_0x2f0cb7=_[_0x4ad6('0x39')]({},_0x2f0cb7,_0x56215a[_0x4ad6('0x3b')]);return db['MailServerOut'][_0x4ad6('0x44')](_0x2f0cb7)[_0x4ad6('0x24')](handleEntityNotFound(_0x39bdf8,null))[_0x4ad6('0x24')](respondWithResult(_0x39bdf8,null))['catch'](handleError(_0x39bdf8,null));};exports[_0x4ad6('0x45')]=function(_0x41d198,_0x3a939d){return db[_0x4ad6('0x29')][_0x4ad6('0x45')](_0x41d198['body'],{})['then'](respondWithResult(_0x3a939d,0xc9))[_0x4ad6('0x3e')](handleError(_0x3a939d,null));};exports[_0x4ad6('0x22')]=function(_0x381a91,_0x742d58){if(_0x381a91[_0x4ad6('0x46')]['id']){delete _0x381a91[_0x4ad6('0x46')]['id'];}return db[_0x4ad6('0x29')][_0x4ad6('0x44')]({'where':{'id':_0x381a91[_0x4ad6('0x3f')]['id']}})[_0x4ad6('0x24')](handleEntityNotFound(_0x742d58,null))[_0x4ad6('0x24')](saveUpdates(_0x381a91[_0x4ad6('0x46')],null))[_0x4ad6('0x24')](respondWithResult(_0x742d58,null))[_0x4ad6('0x3e')](handleError(_0x742d58,null));};exports[_0x4ad6('0x23')]=function(_0x1c5497,_0x3fd0d0){return db[_0x4ad6('0x29')]['find']({'where':{'id':_0x1c5497[_0x4ad6('0x3f')]['id']}})['then'](handleEntityNotFound(_0x3fd0d0,null))['then'](removeEntity(_0x3fd0d0,null))[_0x4ad6('0x3e')](handleError(_0x3fd0d0,null));};