2c96ccd85f152b914c2bec7be420318dc3a36db3
[motion2.git] / server / api / mailApplication / mailApplication.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 _0xa067=['rimraf','zip-dir','fast-json-patch','bluebird','ejs','lodash','squel','crypto','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../mysqldb','sendStatus','status','end','json','offset','undefined','limit','count','save','update','then','destroy','error','stack','name','send','render','body','message','agent','interaction','show','params','model','keys','MailApplication','query','filters','intersection','fields','attributes','length','includeAll','include','merge','options','find','catch','eml-format'];(function(_0x4792c8,_0x5158a1){var _0x35edb1=function(_0x2472d3){while(--_0x2472d3){_0x4792c8['push'](_0x4792c8['shift']());}};_0x35edb1(++_0x5158a1);}(_0xa067,0x126));var _0x7a06=function(_0x3886e8,_0x2fd69f){_0x3886e8=_0x3886e8-0x0;var _0x2de99b=_0xa067[_0x3886e8];return _0x2de99b;};'use strict';var emlformat=require(_0x7a06('0x0'));var rimraf=require(_0x7a06('0x1'));var zipdir=require(_0x7a06('0x2'));var jsonpatch=require(_0x7a06('0x3'));var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0x7a06('0x4'));var Mustache=require('mustache');var util=require('util');var path=require('path');var sox=require('sox');var csv=require('to-csv');var ejs=require(_0x7a06('0x5'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x7a06('0x6'));var squel=require(_0x7a06('0x7'));var crypto=require(_0x7a06('0x8'));var jsforce=require(_0x7a06('0x9'));var deskjs=require(_0x7a06('0xa'));var toCsv=require(_0x7a06('0xb'));var querystring=require(_0x7a06('0xc'));var Papa=require(_0x7a06('0xd'));var Redis=require(_0x7a06('0xe'));var authService=require(_0x7a06('0xf'));var qs=require(_0x7a06('0x10'));var as=require(_0x7a06('0x11'));var hardwareService=require(_0x7a06('0x12'));var logger=require('../../config/logger')(_0x7a06('0x13'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require(_0x7a06('0x14'))['db'];function respondWithStatusCode(_0x2bd1a7,_0x38f604){_0x38f604=_0x38f604||0xcc;return function(_0x530b09){if(_0x530b09){return _0x2bd1a7[_0x7a06('0x15')](_0x38f604);}return _0x2bd1a7[_0x7a06('0x16')](_0x38f604)[_0x7a06('0x17')]();};}function respondWithResult(_0x53fa84,_0x25a4cc){_0x25a4cc=_0x25a4cc||0xc8;return function(_0x2c9e6b){if(_0x2c9e6b){return _0x53fa84['status'](_0x25a4cc)[_0x7a06('0x18')](_0x2c9e6b);}};}function respondWithFilteredResult(_0x2c67c0,_0x1abcfc){return function(_0x494d9e){if(_0x494d9e){var _0x1f4f10=typeof _0x1abcfc[_0x7a06('0x19')]===_0x7a06('0x1a')&&typeof _0x1abcfc[_0x7a06('0x1b')]===_0x7a06('0x1a');var _0x2c5386=_0x494d9e[_0x7a06('0x1c')];var _0x37cbae=_0x1f4f10?0x0:_0x1abcfc[_0x7a06('0x19')];var _0x4417ac=_0x1f4f10?_0x494d9e[_0x7a06('0x1c')]:_0x1abcfc[_0x7a06('0x19')]+_0x1abcfc['limit'];var _0x12b10f;if(_0x4417ac>=_0x2c5386){_0x4417ac=_0x2c5386;_0x12b10f=0xc8;}else{_0x12b10f=0xce;}_0x2c67c0['status'](_0x12b10f);return _0x2c67c0['set']('Content-Range',_0x37cbae+'-'+_0x4417ac+'/'+_0x2c5386)['json'](_0x494d9e);}return null;};}function patchUpdates(_0x1073e7){return function(_0x2c45e0){try{jsonpatch['apply'](_0x2c45e0,_0x1073e7,!![]);}catch(_0x2adccb){return BPromise['reject'](_0x2adccb);}return _0x2c45e0[_0x7a06('0x1d')]();};}function saveUpdates(_0x4ce789,_0x12d57e){return function(_0x581e06){if(_0x581e06){return _0x581e06[_0x7a06('0x1e')](_0x4ce789)[_0x7a06('0x1f')](function(_0x311cde){return _0x311cde;});}return null;};}function removeEntity(_0x3295f9,_0x1abba0){return function(_0x107754){if(_0x107754){return _0x107754[_0x7a06('0x20')]()[_0x7a06('0x1f')](function(){_0x3295f9[_0x7a06('0x16')](0xcc)[_0x7a06('0x17')]();});}};}function handleEntityNotFound(_0x56b6df,_0x32cbcd){return function(_0x174982){if(!_0x174982){_0x56b6df[_0x7a06('0x15')](0x194);}return _0x174982;};}function handleError(_0x140ae5,_0x5083d2){_0x5083d2=_0x5083d2||0x1f4;return function(_0x6320ba){logger[_0x7a06('0x21')](_0x6320ba[_0x7a06('0x22')]);if(_0x6320ba[_0x7a06('0x23')]){delete _0x6320ba['name'];}_0x140ae5[_0x7a06('0x16')](_0x5083d2)[_0x7a06('0x24')](_0x6320ba);};}function getMustacheRender(_0x366797,_0x1d49e5){return Mustache[_0x7a06('0x25')](_0x366797,_['merge'](_0x1d49e5[_0x7a06('0x26')],{'contact':_0x1d49e5['contact'],'message':_0x1d49e5[_0x7a06('0x27')],'agent':_0x1d49e5[_0x7a06('0x28')],'interaction':_0x1d49e5[_0x7a06('0x29')],'account':_0x1d49e5['account']}))||'';}exports[_0x7a06('0x2a')]=function(_0x52d6cc,_0x3e60d0){var _0x4f6389={'raw':!![],'where':{'id':_0x52d6cc[_0x7a06('0x2b')]['id']}},_0x2b9a93={};_0x2b9a93[_0x7a06('0x2c')]=_[_0x7a06('0x2d')](db[_0x7a06('0x2e')]['rawAttributes']);_0x2b9a93['query']=_[_0x7a06('0x2d')](_0x52d6cc[_0x7a06('0x2f')]);_0x2b9a93[_0x7a06('0x30')]=_[_0x7a06('0x31')](_0x2b9a93['model'],_0x2b9a93[_0x7a06('0x2f')]);_0x4f6389['attributes']=_[_0x7a06('0x31')](_0x2b9a93[_0x7a06('0x2c')],qs[_0x7a06('0x32')](_0x52d6cc[_0x7a06('0x2f')][_0x7a06('0x32')]));_0x4f6389[_0x7a06('0x33')]=_0x4f6389[_0x7a06('0x33')][_0x7a06('0x34')]?_0x4f6389[_0x7a06('0x33')]:_0x2b9a93[_0x7a06('0x2c')];if(_0x52d6cc['query'][_0x7a06('0x35')]){_0x4f6389[_0x7a06('0x36')]=[{'all':!![]}];}_0x4f6389=_[_0x7a06('0x37')]({},_0x4f6389,_0x52d6cc[_0x7a06('0x38')]);return db[_0x7a06('0x2e')][_0x7a06('0x39')](_0x4f6389)[_0x7a06('0x1f')](handleEntityNotFound(_0x3e60d0,null))[_0x7a06('0x1f')](respondWithResult(_0x3e60d0,null))[_0x7a06('0x3a')](handleError(_0x3e60d0,null));};exports[_0x7a06('0x1e')]=function(_0x49e7c5,_0x102ed8){if(_0x49e7c5[_0x7a06('0x26')]['id']){delete _0x49e7c5[_0x7a06('0x26')]['id'];}return db['MailApplication'][_0x7a06('0x39')]({'where':{'id':_0x49e7c5['params']['id']}})[_0x7a06('0x1f')](handleEntityNotFound(_0x102ed8,null))[_0x7a06('0x1f')](saveUpdates(_0x49e7c5[_0x7a06('0x26')],null))['then'](respondWithResult(_0x102ed8,null))['catch'](handleError(_0x102ed8,null));};exports[_0x7a06('0x20')]=function(_0x2dcd1f,_0x14e4eb){return db['MailApplication'][_0x7a06('0x39')]({'where':{'id':_0x2dcd1f[_0x7a06('0x2b')]['id']}})[_0x7a06('0x1f')](handleEntityNotFound(_0x14e4eb,null))['then'](removeEntity(_0x14e4eb,null))[_0x7a06('0x3a')](handleError(_0x14e4eb,null));};