2d936f8384292836fba65be2186c3c8cbadb6ab5
[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 _0x919f=['sox','to-csv','ejs','fs-extra','lodash','crypto','jsforce','querystring','papaparse','../../components/auth/service','api','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','end','status','json','undefined','limit','count','offset','set','Content-Range','apply','reject','save','destroy','then','error','stack','name','index','map','MailServerOut','rawAttributes','fieldName','type','key','model','query','keys','filters','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','includeAll','include','rows','catch','show','params','create','update','body','find','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util'];(function(_0x1cb36c,_0x6d6af7){var _0x3d7efc=function(_0x29979c){while(--_0x29979c){_0x1cb36c['push'](_0x1cb36c['shift']());}};_0x3d7efc(++_0x6d6af7);}(_0x919f,0xd7));var _0xf919=function(_0x724393,_0x1a9572){_0x724393=_0x724393-0x0;var _0x45aaf9=_0x919f[_0x724393];return _0x45aaf9;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0xf919('0x0'));var jsonpatch=require(_0xf919('0x1'));var rp=require(_0xf919('0x2'));var moment=require(_0xf919('0x3'));var BPromise=require(_0xf919('0x4'));var Mustache=require(_0xf919('0x5'));var util=require(_0xf919('0x6'));var path=require('path');var sox=require(_0xf919('0x7'));var csv=require(_0xf919('0x8'));var ejs=require(_0xf919('0x9'));var fs=require('fs');var fs_extra=require(_0xf919('0xa'));var _=require(_0xf919('0xb'));var squel=require('squel');var crypto=require(_0xf919('0xc'));var jsforce=require(_0xf919('0xd'));var deskjs=require('desk.js');var toCsv=require(_0xf919('0x8'));var querystring=require(_0xf919('0xe'));var Papa=require(_0xf919('0xf'));var Redis=require('ioredis');var authService=require(_0xf919('0x10'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0xf919('0x11'));var utils=require(_0xf919('0x12'));var config=require('../../config/environment');var licenseUtil=require(_0xf919('0x13'));var db=require(_0xf919('0x14'))['db'];function respondWithStatusCode(_0x2f8615,_0xe35202){_0xe35202=_0xe35202||0xcc;return function(_0x127e1e){if(_0x127e1e){return _0x2f8615[_0xf919('0x15')](_0xe35202);}return _0x2f8615['status'](_0xe35202)[_0xf919('0x16')]();};}function respondWithResult(_0x3c72f2,_0x161bb4){_0x161bb4=_0x161bb4||0xc8;return function(_0x273059){if(_0x273059){return _0x3c72f2[_0xf919('0x17')](_0x161bb4)[_0xf919('0x18')](_0x273059);}};}function respondWithFilteredResult(_0x583fb8,_0x22e6c9){return function(_0x2192a1){if(_0x2192a1){var _0x106969=typeof _0x22e6c9['offset']===_0xf919('0x19')&&typeof _0x22e6c9[_0xf919('0x1a')]===_0xf919('0x19');var _0x3b5227=_0x2192a1[_0xf919('0x1b')];var _0x5d7977=_0x106969?0x0:_0x22e6c9[_0xf919('0x1c')];var _0x5328c2=_0x106969?_0x2192a1['count']:_0x22e6c9[_0xf919('0x1c')]+_0x22e6c9[_0xf919('0x1a')];var _0x2125ca;if(_0x5328c2>=_0x3b5227){_0x5328c2=_0x3b5227;_0x2125ca=0xc8;}else{_0x2125ca=0xce;}_0x583fb8[_0xf919('0x17')](_0x2125ca);return _0x583fb8[_0xf919('0x1d')](_0xf919('0x1e'),_0x5d7977+'-'+_0x5328c2+'/'+_0x3b5227)['json'](_0x2192a1);}return null;};}function patchUpdates(_0x67de07){return function(_0x5723b3){try{jsonpatch[_0xf919('0x1f')](_0x5723b3,_0x67de07,!![]);}catch(_0x4f5296){return BPromise[_0xf919('0x20')](_0x4f5296);}return _0x5723b3[_0xf919('0x21')]();};}function saveUpdates(_0x4c5b4c,_0xc376e0){return function(_0x2d4c4b){if(_0x2d4c4b){return _0x2d4c4b['update'](_0x4c5b4c)['then'](function(_0x24e7a5){return _0x24e7a5;});}return null;};}function removeEntity(_0x36b769,_0x5ea793){return function(_0x184c58){if(_0x184c58){return _0x184c58[_0xf919('0x22')]()[_0xf919('0x23')](function(){_0x36b769[_0xf919('0x17')](0xcc)[_0xf919('0x16')]();});}};}function handleEntityNotFound(_0x46ecf5,_0x384548){return function(_0x31ff6b){if(!_0x31ff6b){_0x46ecf5[_0xf919('0x15')](0x194);}return _0x31ff6b;};}function handleError(_0x242948,_0x3c1d95){_0x3c1d95=_0x3c1d95||0x1f4;return function(_0x22d990){logger[_0xf919('0x24')](_0x22d990[_0xf919('0x25')]);if(_0x22d990[_0xf919('0x26')]){delete _0x22d990['name'];}_0x242948['status'](_0x3c1d95)['send'](_0x22d990);};}exports[_0xf919('0x27')]=function(_0x46b19a,_0xe852d4){var _0x4066aa={},_0x1575a4={},_0x3648f4={'count':0x0,'rows':[]};var _0x1b69be=_[_0xf919('0x28')](db[_0xf919('0x29')][_0xf919('0x2a')],function(_0x4fcba4){return{'name':_0x4fcba4[_0xf919('0x2b')],'type':_0x4fcba4[_0xf919('0x2c')][_0xf919('0x2d')]};});_0x1575a4[_0xf919('0x2e')]=_[_0xf919('0x28')](_0x1b69be,_0xf919('0x26'));_0x1575a4[_0xf919('0x2f')]=_[_0xf919('0x30')](_0x46b19a[_0xf919('0x2f')]);_0x1575a4[_0xf919('0x31')]=_['intersection'](_0x1575a4[_0xf919('0x2e')],_0x1575a4[_0xf919('0x2f')]);_0x4066aa[_0xf919('0x32')]=_[_0xf919('0x33')](_0x1575a4[_0xf919('0x2e')],qs['fields'](_0x46b19a[_0xf919('0x2f')][_0xf919('0x34')]));_0x4066aa[_0xf919('0x32')]=_0x4066aa[_0xf919('0x32')][_0xf919('0x35')]?_0x4066aa['attributes']:_0x1575a4[_0xf919('0x2e')];if(!_0x46b19a[_0xf919('0x2f')][_0xf919('0x36')](_0xf919('0x37'))){_0x4066aa[_0xf919('0x1a')]=qs[_0xf919('0x1a')](_0x46b19a[_0xf919('0x2f')]['limit']);_0x4066aa[_0xf919('0x1c')]=qs[_0xf919('0x1c')](_0x46b19a['query'][_0xf919('0x1c')]);}_0x4066aa[_0xf919('0x38')]=qs[_0xf919('0x39')](_0x46b19a[_0xf919('0x2f')]['sort']);_0x4066aa[_0xf919('0x3a')]=qs[_0xf919('0x31')](_[_0xf919('0x3b')](_0x46b19a[_0xf919('0x2f')],_0x1575a4[_0xf919('0x31')]),_0x1b69be);if(_0x46b19a[_0xf919('0x2f')][_0xf919('0x3c')]){_0x4066aa['where']=_[_0xf919('0x3d')](_0x4066aa[_0xf919('0x3a')],{'$or':_[_0xf919('0x28')](_0x1b69be,function(_0x41b43d){if(_0x41b43d['type']!==_0xf919('0x3e')){var _0x4638b6={};_0x4638b6[_0x41b43d[_0xf919('0x26')]]={'$like':'%'+_0x46b19a[_0xf919('0x2f')][_0xf919('0x3c')]+'%'};return _0x4638b6;}})});}_0x4066aa=_['merge']({},_0x4066aa,_0x46b19a[_0xf919('0x3f')]);var _0x53d4f9={'where':_0x4066aa[_0xf919('0x3a')]};return db[_0xf919('0x29')][_0xf919('0x1b')](_0x53d4f9)[_0xf919('0x23')](function(_0x5d3a88){_0x3648f4[_0xf919('0x1b')]=_0x5d3a88;if(_0x46b19a[_0xf919('0x2f')][_0xf919('0x40')]){_0x4066aa[_0xf919('0x41')]=[{'all':!![]}];}return db[_0xf919('0x29')]['findAll'](_0x4066aa);})[_0xf919('0x23')](function(_0x5cf11c){_0x3648f4[_0xf919('0x42')]=_0x5cf11c;return _0x3648f4;})['then'](respondWithFilteredResult(_0xe852d4,_0x4066aa))[_0xf919('0x43')](handleError(_0xe852d4,null));};exports[_0xf919('0x44')]=function(_0x52f283,_0x590e07){var _0x2a6f4e={'raw':!![],'where':{'id':_0x52f283[_0xf919('0x45')]['id']}},_0x15dae1={};_0x15dae1[_0xf919('0x2e')]=_[_0xf919('0x30')](db[_0xf919('0x29')][_0xf919('0x2a')]);_0x15dae1['query']=_['keys'](_0x52f283[_0xf919('0x2f')]);_0x15dae1[_0xf919('0x31')]=_[_0xf919('0x33')](_0x15dae1[_0xf919('0x2e')],_0x15dae1['query']);_0x2a6f4e['attributes']=_[_0xf919('0x33')](_0x15dae1[_0xf919('0x2e')],qs['fields'](_0x52f283[_0xf919('0x2f')][_0xf919('0x34')]));_0x2a6f4e[_0xf919('0x32')]=_0x2a6f4e[_0xf919('0x32')][_0xf919('0x35')]?_0x2a6f4e[_0xf919('0x32')]:_0x15dae1['model'];if(_0x52f283[_0xf919('0x2f')]['includeAll']){_0x2a6f4e[_0xf919('0x41')]=[{'all':!![]}];}_0x2a6f4e=_['merge']({},_0x2a6f4e,_0x52f283['options']);return db[_0xf919('0x29')]['find'](_0x2a6f4e)['then'](handleEntityNotFound(_0x590e07,null))[_0xf919('0x23')](respondWithResult(_0x590e07,null))['catch'](handleError(_0x590e07,null));};exports[_0xf919('0x46')]=function(_0x1e0c46,_0x198058){return db[_0xf919('0x29')]['create'](_0x1e0c46['body'],{})['then'](respondWithResult(_0x198058,0xc9))[_0xf919('0x43')](handleError(_0x198058,null));};exports[_0xf919('0x47')]=function(_0x16ade4,_0x1f8922){if(_0x16ade4[_0xf919('0x48')]['id']){delete _0x16ade4[_0xf919('0x48')]['id'];}return db[_0xf919('0x29')][_0xf919('0x49')]({'where':{'id':_0x16ade4[_0xf919('0x45')]['id']}})['then'](handleEntityNotFound(_0x1f8922,null))[_0xf919('0x23')](saveUpdates(_0x16ade4['body'],null))[_0xf919('0x23')](respondWithResult(_0x1f8922,null))[_0xf919('0x43')](handleError(_0x1f8922,null));};exports[_0xf919('0x22')]=function(_0x16ac78,_0x3580ad){return db[_0xf919('0x29')][_0xf919('0x49')]({'where':{'id':_0x16ac78[_0xf919('0x45')]['id']}})[_0xf919('0x23')](handleEntityNotFound(_0x3580ad,null))[_0xf919('0x23')](removeEntity(_0x3580ad,null))[_0xf919('0x43')](handleError(_0x3580ad,null));};