5131a384c7fd35fd161fc1159a06ab59d686d7d8
[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 _0x4eff=['bluebird','mustache','util','to-csv','ejs','fs-extra','lodash','squel','crypto','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','end','status','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save','update','then','error','stack','name','send','index','map','MailServerOut','fieldName','type','model','query','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','pick','where','merge','VIRTUAL','filter','includeAll','findAll','rows','params','find','catch','create','body','destroy','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment'];(function(_0x45ee80,_0x556689){var _0x350e98=function(_0x96e156){while(--_0x96e156){_0x45ee80['push'](_0x45ee80['shift']());}};_0x350e98(++_0x556689);}(_0x4eff,0xd5));var _0xf4ef=function(_0x40a661,_0x4ff4e0){_0x40a661=_0x40a661-0x0;var _0x58ae5b=_0x4eff[_0x40a661];return _0x58ae5b;};'use strict';var emlformat=require(_0xf4ef('0x0'));var rimraf=require(_0xf4ef('0x1'));var zipdir=require(_0xf4ef('0x2'));var jsonpatch=require(_0xf4ef('0x3'));var rp=require(_0xf4ef('0x4'));var moment=require(_0xf4ef('0x5'));var BPromise=require(_0xf4ef('0x6'));var Mustache=require(_0xf4ef('0x7'));var util=require(_0xf4ef('0x8'));var path=require('path');var sox=require('sox');var csv=require(_0xf4ef('0x9'));var ejs=require(_0xf4ef('0xa'));var fs=require('fs');var fs_extra=require(_0xf4ef('0xb'));var _=require(_0xf4ef('0xc'));var squel=require(_0xf4ef('0xd'));var crypto=require(_0xf4ef('0xe'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0xf4ef('0x9'));var querystring=require(_0xf4ef('0xf'));var Papa=require('papaparse');var Redis=require(_0xf4ef('0x10'));var authService=require(_0xf4ef('0x11'));var qs=require(_0xf4ef('0x12'));var as=require(_0xf4ef('0x13'));var hardwareService=require(_0xf4ef('0x14'));var logger=require(_0xf4ef('0x15'))('api');var utils=require(_0xf4ef('0x16'));var config=require(_0xf4ef('0x17'));var licenseUtil=require(_0xf4ef('0x18'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x442f4c,_0x224e33){_0x224e33=_0x224e33||0xcc;return function(_0x8fede0){if(_0x8fede0){return _0x442f4c['sendStatus'](_0x224e33);}return _0x442f4c['status'](_0x224e33)[_0xf4ef('0x19')]();};}function respondWithResult(_0x2df024,_0x56a253){_0x56a253=_0x56a253||0xc8;return function(_0x292574){if(_0x292574){return _0x2df024[_0xf4ef('0x1a')](_0x56a253)[_0xf4ef('0x1b')](_0x292574);}};}function respondWithFilteredResult(_0x5795de,_0x5db47c){return function(_0x4153d3){if(_0x4153d3){var _0x502acf=typeof _0x5db47c[_0xf4ef('0x1c')]===_0xf4ef('0x1d')&&typeof _0x5db47c[_0xf4ef('0x1e')]===_0xf4ef('0x1d');var _0x3b4ebe=_0x4153d3['count'];var _0xc13413=_0x502acf?0x0:_0x5db47c[_0xf4ef('0x1c')];var _0x55e739=_0x502acf?_0x4153d3[_0xf4ef('0x1f')]:_0x5db47c[_0xf4ef('0x1c')]+_0x5db47c[_0xf4ef('0x1e')];var _0x17e83f;if(_0x55e739>=_0x3b4ebe){_0x55e739=_0x3b4ebe;_0x17e83f=0xc8;}else{_0x17e83f=0xce;}_0x5795de['status'](_0x17e83f);return _0x5795de[_0xf4ef('0x20')](_0xf4ef('0x21'),_0xc13413+'-'+_0x55e739+'/'+_0x3b4ebe)[_0xf4ef('0x1b')](_0x4153d3);}return null;};}function patchUpdates(_0x32da42){return function(_0x5a869d){try{jsonpatch[_0xf4ef('0x22')](_0x5a869d,_0x32da42,!![]);}catch(_0x57ac39){return BPromise[_0xf4ef('0x23')](_0x57ac39);}return _0x5a869d[_0xf4ef('0x24')]();};}function saveUpdates(_0x4b218e,_0x3b6036){return function(_0x288abe){if(_0x288abe){return _0x288abe[_0xf4ef('0x25')](_0x4b218e)['then'](function(_0x2f72b0){return _0x2f72b0;});}return null;};}function removeEntity(_0x332dd7,_0x5d5129){return function(_0x10db60){if(_0x10db60){return _0x10db60['destroy']()[_0xf4ef('0x26')](function(){_0x332dd7[_0xf4ef('0x1a')](0xcc)[_0xf4ef('0x19')]();});}};}function handleEntityNotFound(_0x15cb02,_0x3de0ca){return function(_0x2455ea){if(!_0x2455ea){_0x15cb02['sendStatus'](0x194);}return _0x2455ea;};}function handleError(_0x1b6363,_0x4cbe76){_0x4cbe76=_0x4cbe76||0x1f4;return function(_0x18e3bf){logger[_0xf4ef('0x27')](_0x18e3bf[_0xf4ef('0x28')]);if(_0x18e3bf[_0xf4ef('0x29')]){delete _0x18e3bf[_0xf4ef('0x29')];}_0x1b6363['status'](_0x4cbe76)[_0xf4ef('0x2a')](_0x18e3bf);};}exports[_0xf4ef('0x2b')]=function(_0x3d3c52,_0x42e7d9){var _0x5d53c3={},_0x1b13a9={},_0x240dc0={'count':0x0,'rows':[]};var _0x54e928=_[_0xf4ef('0x2c')](db[_0xf4ef('0x2d')]['rawAttributes'],function(_0x3dcd3e){return{'name':_0x3dcd3e[_0xf4ef('0x2e')],'type':_0x3dcd3e[_0xf4ef('0x2f')]['key']};});_0x1b13a9[_0xf4ef('0x30')]=_[_0xf4ef('0x2c')](_0x54e928,'name');_0x1b13a9[_0xf4ef('0x31')]=_['keys'](_0x3d3c52[_0xf4ef('0x31')]);_0x1b13a9[_0xf4ef('0x32')]=_[_0xf4ef('0x33')](_0x1b13a9['model'],_0x1b13a9[_0xf4ef('0x31')]);_0x5d53c3['attributes']=_[_0xf4ef('0x33')](_0x1b13a9[_0xf4ef('0x30')],qs[_0xf4ef('0x34')](_0x3d3c52[_0xf4ef('0x31')]['fields']));_0x5d53c3[_0xf4ef('0x35')]=_0x5d53c3['attributes'][_0xf4ef('0x36')]?_0x5d53c3[_0xf4ef('0x35')]:_0x1b13a9['model'];if(!_0x3d3c52[_0xf4ef('0x31')][_0xf4ef('0x37')](_0xf4ef('0x38'))){_0x5d53c3[_0xf4ef('0x1e')]=qs[_0xf4ef('0x1e')](_0x3d3c52[_0xf4ef('0x31')][_0xf4ef('0x1e')]);_0x5d53c3[_0xf4ef('0x1c')]=qs[_0xf4ef('0x1c')](_0x3d3c52[_0xf4ef('0x31')][_0xf4ef('0x1c')]);}_0x5d53c3[_0xf4ef('0x39')]=qs[_0xf4ef('0x3a')](_0x3d3c52[_0xf4ef('0x31')][_0xf4ef('0x3a')]);_0x5d53c3['where']=qs[_0xf4ef('0x32')](_[_0xf4ef('0x3b')](_0x3d3c52[_0xf4ef('0x31')],_0x1b13a9['filters']),_0x54e928);if(_0x3d3c52['query']['filter']){_0x5d53c3[_0xf4ef('0x3c')]=_[_0xf4ef('0x3d')](_0x5d53c3[_0xf4ef('0x3c')],{'$or':_[_0xf4ef('0x2c')](_0x54e928,function(_0x2f25d3){if(_0x2f25d3[_0xf4ef('0x2f')]!==_0xf4ef('0x3e')){var _0x1a5160={};_0x1a5160[_0x2f25d3['name']]={'$like':'%'+_0x3d3c52[_0xf4ef('0x31')][_0xf4ef('0x3f')]+'%'};return _0x1a5160;}})});}_0x5d53c3=_[_0xf4ef('0x3d')]({},_0x5d53c3,_0x3d3c52['options']);var _0x15b857={'where':_0x5d53c3[_0xf4ef('0x3c')]};return db[_0xf4ef('0x2d')][_0xf4ef('0x1f')](_0x15b857)[_0xf4ef('0x26')](function(_0x4c6f4b){_0x240dc0[_0xf4ef('0x1f')]=_0x4c6f4b;if(_0x3d3c52[_0xf4ef('0x31')][_0xf4ef('0x40')]){_0x5d53c3['include']=[{'all':!![]}];}return db[_0xf4ef('0x2d')][_0xf4ef('0x41')](_0x5d53c3);})['then'](function(_0xf447b7){_0x240dc0[_0xf4ef('0x42')]=_0xf447b7;return _0x240dc0;})['then'](respondWithFilteredResult(_0x42e7d9,_0x5d53c3))['catch'](handleError(_0x42e7d9,null));};exports['show']=function(_0x2a398b,_0x12d5e9){var _0x972f3b={'raw':!![],'where':{'id':_0x2a398b[_0xf4ef('0x43')]['id']}},_0x4fd9dd={};_0x4fd9dd[_0xf4ef('0x30')]=_['keys'](db[_0xf4ef('0x2d')]['rawAttributes']);_0x4fd9dd['query']=_['keys'](_0x2a398b[_0xf4ef('0x31')]);_0x4fd9dd['filters']=_[_0xf4ef('0x33')](_0x4fd9dd[_0xf4ef('0x30')],_0x4fd9dd[_0xf4ef('0x31')]);_0x972f3b[_0xf4ef('0x35')]=_[_0xf4ef('0x33')](_0x4fd9dd['model'],qs['fields'](_0x2a398b['query'][_0xf4ef('0x34')]));_0x972f3b[_0xf4ef('0x35')]=_0x972f3b['attributes'][_0xf4ef('0x36')]?_0x972f3b['attributes']:_0x4fd9dd[_0xf4ef('0x30')];if(_0x2a398b[_0xf4ef('0x31')][_0xf4ef('0x40')]){_0x972f3b['include']=[{'all':!![]}];}_0x972f3b=_['merge']({},_0x972f3b,_0x2a398b['options']);return db[_0xf4ef('0x2d')][_0xf4ef('0x44')](_0x972f3b)[_0xf4ef('0x26')](handleEntityNotFound(_0x12d5e9,null))[_0xf4ef('0x26')](respondWithResult(_0x12d5e9,null))[_0xf4ef('0x45')](handleError(_0x12d5e9,null));};exports[_0xf4ef('0x46')]=function(_0x5a57ed,_0x10a004){return db[_0xf4ef('0x2d')][_0xf4ef('0x46')](_0x5a57ed[_0xf4ef('0x47')],{})['then'](respondWithResult(_0x10a004,0xc9))['catch'](handleError(_0x10a004,null));};exports[_0xf4ef('0x25')]=function(_0x5e6014,_0x5ab43f){if(_0x5e6014['body']['id']){delete _0x5e6014[_0xf4ef('0x47')]['id'];}return db[_0xf4ef('0x2d')][_0xf4ef('0x44')]({'where':{'id':_0x5e6014[_0xf4ef('0x43')]['id']}})[_0xf4ef('0x26')](handleEntityNotFound(_0x5ab43f,null))['then'](saveUpdates(_0x5e6014['body'],null))[_0xf4ef('0x26')](respondWithResult(_0x5ab43f,null))['catch'](handleError(_0x5ab43f,null));};exports[_0xf4ef('0x48')]=function(_0x477da8,_0x3d7bc0){return db[_0xf4ef('0x2d')][_0xf4ef('0x44')]({'where':{'id':_0x477da8[_0xf4ef('0x43')]['id']}})[_0xf4ef('0x26')](handleEntityNotFound(_0x3d7bc0,null))[_0xf4ef('0x26')](removeEntity(_0x3d7bc0,null))[_0xf4ef('0x45')](handleError(_0x3d7bc0,null));};