8336eeb6fc3e3f0b134901dc0bc8417cecb4b44f
[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 _0x943f=['map','rawAttributes','fieldName','type','model','query','keys','intersection','attributes','fields','length','hasOwnProperty','limit','order','sort','pick','filters','filter','where','merge','VIRTUAL','MailServerOut','includeAll','include','rows','catch','params','options','create','body','find','eml-format','rimraf','zip-dir','request-promise','bluebird','util','path','sox','to-csv','ejs','squel','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','end','json','count','offset','status','set','apply','reject','save','then','destroy','name','send','index'];(function(_0x2e7afc,_0x46fdc5){var _0x4f0834=function(_0x3ad475){while(--_0x3ad475){_0x2e7afc['push'](_0x2e7afc['shift']());}};_0x4f0834(++_0x46fdc5);}(_0x943f,0xa7));var _0xf943=function(_0x1e9195,_0x50c32c){_0x1e9195=_0x1e9195-0x0;var _0x44a35d=_0x943f[_0x1e9195];return _0x44a35d;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0xf943('0x0'));var rimraf=require(_0xf943('0x1'));var zipdir=require(_0xf943('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xf943('0x3'));var moment=require('moment');var BPromise=require(_0xf943('0x4'));var Mustache=require('mustache');var util=require(_0xf943('0x5'));var path=require(_0xf943('0x6'));var sox=require(_0xf943('0x7'));var csv=require(_0xf943('0x8'));var ejs=require(_0xf943('0x9'));var fs=require('fs');var _=require('lodash');var squel=require(_0xf943('0xa'));var crypto=require('crypto');var jsforce=require(_0xf943('0xb'));var deskjs=require(_0xf943('0xc'));var toCsv=require(_0xf943('0x8'));var querystring=require(_0xf943('0xd'));var Papa=require(_0xf943('0xe'));var Redis=require('ioredis');var authService=require(_0xf943('0xf'));var qs=require(_0xf943('0x10'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xf943('0x11'));var logger=require('../../config/logger')(_0xf943('0x12'));var utils=require(_0xf943('0x13'));var config=require(_0xf943('0x14'));var db=require(_0xf943('0x15'))['db'];function respondWithStatusCode(_0x5b062f,_0x3352ec){_0x3352ec=_0x3352ec||0xcc;return function(_0xdd312c){if(_0xdd312c){return _0x5b062f[_0xf943('0x16')](_0x3352ec);}return _0x5b062f['status'](_0x3352ec)[_0xf943('0x17')]();};}function respondWithResult(_0x2d356a,_0x334401){_0x334401=_0x334401||0xc8;return function(_0x5f510c){if(_0x5f510c){return _0x2d356a['status'](_0x334401)[_0xf943('0x18')](_0x5f510c);}};}function respondWithFilteredResult(_0x4c99fa,_0x8c59cd){return function(_0x29b41d){if(_0x29b41d){var _0x45e88a=_0x29b41d[_0xf943('0x19')],_0x19817c=_0x8c59cd[_0xf943('0x1a')],_0x4f1f65=_0x8c59cd[_0xf943('0x1a')]+_0x8c59cd['limit'],_0x8da043;if(_0x4f1f65>=_0x45e88a){_0x4f1f65=_0x45e88a;_0x8da043=0xc8;}else{_0x8da043=0xce;}_0x4c99fa[_0xf943('0x1b')](_0x8da043);return _0x4c99fa[_0xf943('0x1c')]('Content-Range',_0x19817c+'-'+_0x4f1f65+'/'+_0x45e88a)[_0xf943('0x18')](_0x29b41d);}return null;};}function patchUpdates(_0x172c91){return function(_0x25d00a){try{jsonpatch[_0xf943('0x1d')](_0x25d00a,_0x172c91,!![]);}catch(_0x32bbef){return BPromise[_0xf943('0x1e')](_0x32bbef);}return _0x25d00a[_0xf943('0x1f')]();};}function saveUpdates(_0xd7f7f1,_0x236c57){return function(_0x4dd2df){if(_0x4dd2df){return _0x4dd2df['update'](_0xd7f7f1)[_0xf943('0x20')](function(_0x3f0d70){return _0x3f0d70;});}return null;};}function removeEntity(_0x339e09,_0x2ffcfc){return function(_0x5cbc4e){if(_0x5cbc4e){return _0x5cbc4e[_0xf943('0x21')]()['then'](function(){_0x339e09['status'](0xcc)[_0xf943('0x17')]();});}};}function handleEntityNotFound(_0x493d8d,_0x1faccc){return function(_0x1ee7af){if(!_0x1ee7af){_0x493d8d['sendStatus'](0x194);}return _0x1ee7af;};}function handleError(_0x549e6a,_0x475cbe){_0x475cbe=_0x475cbe||0x1f4;return function(_0xa63549){logger['error'](_0xa63549['stack']);if(_0xa63549[_0xf943('0x22')]){delete _0xa63549[_0xf943('0x22')];}_0x549e6a[_0xf943('0x1b')](_0x475cbe)[_0xf943('0x23')](_0xa63549);};}exports[_0xf943('0x24')]=function(_0x5522c7,_0x5afdc3){var _0x1eb9d1={},_0x5df746={},_0x179545={'count':0x0,'rows':[]};var _0x4683e0=_[_0xf943('0x25')](db['MailServerOut'][_0xf943('0x26')],function(_0x30d2e4){return{'name':_0x30d2e4[_0xf943('0x27')],'type':_0x30d2e4[_0xf943('0x28')]['key']};});_0x5df746[_0xf943('0x29')]=_['map'](_0x4683e0,'name');_0x5df746[_0xf943('0x2a')]=_[_0xf943('0x2b')](_0x5522c7[_0xf943('0x2a')]);_0x5df746['filters']=_[_0xf943('0x2c')](_0x5df746['model'],_0x5df746['query']);_0x1eb9d1[_0xf943('0x2d')]=_[_0xf943('0x2c')](_0x5df746[_0xf943('0x29')],qs[_0xf943('0x2e')](_0x5522c7[_0xf943('0x2a')][_0xf943('0x2e')]));_0x1eb9d1[_0xf943('0x2d')]=_0x1eb9d1['attributes'][_0xf943('0x2f')]?_0x1eb9d1[_0xf943('0x2d')]:_0x5df746[_0xf943('0x29')];if(!_0x5522c7[_0xf943('0x2a')][_0xf943('0x30')]('nolimit')){_0x1eb9d1[_0xf943('0x31')]=qs[_0xf943('0x31')](_0x5522c7[_0xf943('0x2a')]['limit']);_0x1eb9d1['offset']=qs['offset'](_0x5522c7[_0xf943('0x2a')][_0xf943('0x1a')]);}_0x1eb9d1[_0xf943('0x32')]=qs['sort'](_0x5522c7['query'][_0xf943('0x33')]);_0x1eb9d1['where']=qs['filters'](_[_0xf943('0x34')](_0x5522c7[_0xf943('0x2a')],_0x5df746[_0xf943('0x35')]),_0x4683e0);if(_0x5522c7[_0xf943('0x2a')][_0xf943('0x36')]){_0x1eb9d1[_0xf943('0x37')]=_[_0xf943('0x38')](_0x1eb9d1['where'],{'$or':_['map'](_0x4683e0,function(_0x7a2eaa){if(_0x7a2eaa[_0xf943('0x28')]!==_0xf943('0x39')){var _0xf243cc={};_0xf243cc[_0x7a2eaa['name']]={'$like':'%'+_0x5522c7[_0xf943('0x2a')]['filter']+'%'};return _0xf243cc;}})});}_0x1eb9d1=_['merge']({},_0x1eb9d1,_0x5522c7['options']);var _0x5bc468={'where':_0x1eb9d1[_0xf943('0x37')]};return db[_0xf943('0x3a')]['count'](_0x5bc468)[_0xf943('0x20')](function(_0x17888f){_0x179545[_0xf943('0x19')]=_0x17888f;if(_0x5522c7[_0xf943('0x2a')][_0xf943('0x3b')]){_0x1eb9d1[_0xf943('0x3c')]=[{'all':!![]}];}return db['MailServerOut']['findAll'](_0x1eb9d1);})['then'](function(_0x18ac34){_0x179545[_0xf943('0x3d')]=_0x18ac34;return _0x179545;})[_0xf943('0x20')](respondWithFilteredResult(_0x5afdc3,_0x1eb9d1))[_0xf943('0x3e')](handleError(_0x5afdc3,null));};exports['show']=function(_0x267dd4,_0x3ea032){var _0x3a48d6={'raw':!![],'where':{'id':_0x267dd4[_0xf943('0x3f')]['id']}},_0x2d57d1={};_0x2d57d1[_0xf943('0x29')]=_[_0xf943('0x2b')](db[_0xf943('0x3a')][_0xf943('0x26')]);_0x2d57d1[_0xf943('0x2a')]=_[_0xf943('0x2b')](_0x267dd4[_0xf943('0x2a')]);_0x2d57d1[_0xf943('0x35')]=_['intersection'](_0x2d57d1[_0xf943('0x29')],_0x2d57d1[_0xf943('0x2a')]);_0x3a48d6[_0xf943('0x2d')]=_[_0xf943('0x2c')](_0x2d57d1['model'],qs['fields'](_0x267dd4[_0xf943('0x2a')][_0xf943('0x2e')]));_0x3a48d6['attributes']=_0x3a48d6[_0xf943('0x2d')]['length']?_0x3a48d6['attributes']:_0x2d57d1[_0xf943('0x29')];if(_0x267dd4['query'][_0xf943('0x3b')]){_0x3a48d6[_0xf943('0x3c')]=[{'all':!![]}];}_0x3a48d6=_['merge']({},_0x3a48d6,_0x267dd4[_0xf943('0x40')]);return db[_0xf943('0x3a')]['find'](_0x3a48d6)[_0xf943('0x20')](handleEntityNotFound(_0x3ea032,null))[_0xf943('0x20')](respondWithResult(_0x3ea032,null))['catch'](handleError(_0x3ea032,null));};exports[_0xf943('0x41')]=function(_0x3f407b,_0x40209b){return db[_0xf943('0x3a')][_0xf943('0x41')](_0x3f407b[_0xf943('0x42')],{})['then'](respondWithResult(_0x40209b,0xc9))[_0xf943('0x3e')](handleError(_0x40209b,null));};exports['update']=function(_0x5c4bd6,_0x4788ac){if(_0x5c4bd6[_0xf943('0x42')]['id']){delete _0x5c4bd6['body']['id'];}return db['MailServerOut']['find']({'where':{'id':_0x5c4bd6[_0xf943('0x3f')]['id']}})[_0xf943('0x20')](handleEntityNotFound(_0x4788ac,null))[_0xf943('0x20')](saveUpdates(_0x5c4bd6[_0xf943('0x42')],null))[_0xf943('0x20')](respondWithResult(_0x4788ac,null))[_0xf943('0x3e')](handleError(_0x4788ac,null));};exports['destroy']=function(_0x154f6a,_0x3588d8){return db[_0xf943('0x3a')][_0xf943('0x43')]({'where':{'id':_0x154f6a['params']['id']}})['then'](handleEntityNotFound(_0x3588d8,null))['then'](removeEntity(_0x3588d8,null))[_0xf943('0x3e')](handleError(_0x3588d8,null));};