Built motion from commit 53172ac8.|2.6.30
[motion2.git] / server / api / mailInteraction / mailInteraction.controller.js
index 058f059..ef49950 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xa9c8=['status','set','Content-Range','json','update','then','destroy','error','stack','name','send','index','map','MailInteraction','rawAttributes','fieldName','type','key','getOptions','findAll','mail','params','keys','query','intersection','model','fields','attributes','length','includeAll','include','options','catch','create','body','find','describe','MailMessage','addMessage','getMessages','findOne','filters','hasOwnProperty','nolimit','order','sort','where','filter','merge','$gte','split','YYYY-MM-DD\x20HH:mm:ss','true','rows','setTags','omit','ids','spread','Tag','color','emit','mailInteractionTags:save','removeTags','download','unix','toString','root','server','files','tmp','join','transcript-%d-%s.zip','push','Attachment','Attachments','Messages','from','subject','createdAt','get','mkdirSync','each','missing.recipient@your.company.com','decode','format','ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ','headers','bcc','Bcc','existsSync','attachments','readFileSync','build','writeFileSync','message%d.eml','unlinkSync','eml-format','rimraf','zip-dir','moment','bluebird','util','path','lodash','juice','ioredis','../../components/interaction/service','api','html-entities','redis','localhost','socket.io-emitter','register','sendStatus','end','offset','undefined','limit','count'];(function(_0x28669c,_0x1f62c4){var _0x4a3af6=function(_0x3e25d5){while(--_0x3e25d5){_0x28669c['push'](_0x28669c['shift']());}};_0x4a3af6(++_0x1f62c4);}(_0xa9c8,0x1c5));var _0x8a9c=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0xa9c8[_0x3dd15e];return _0x231fd0;};'use strict';var emlformat=require(_0x8a9c('0x0'));var rimraf=require(_0x8a9c('0x1'));var zipdir=require(_0x8a9c('0x2'));var moment=require(_0x8a9c('0x3'));var BPromise=require(_0x8a9c('0x4'));var util=require(_0x8a9c('0x5'));var path=require(_0x8a9c('0x6'));var fs=require('fs');var _=require(_0x8a9c('0x7'));var juice=require(_0x8a9c('0x8'));var Redis=require(_0x8a9c('0x9'));var interaction=require(_0x8a9c('0xa'));var qs=require('../../components/parsers/qs');var logger=require('../../config/logger')(_0x8a9c('0xb'));var config=require('../../config/environment');var db=require('../../mysqldb')['db'];var htmlEntities=require(_0x8a9c('0xc'));config[_0x8a9c('0xd')]=_['defaults'](config[_0x8a9c('0xd')],{'host':_0x8a9c('0xe'),'port':0x18eb});var socket=require(_0x8a9c('0xf'))(new Redis(config[_0x8a9c('0xd')]));require('./mailInteraction.socket')[_0x8a9c('0x10')](socket);function respondWithStatusCode(_0x3fb9c2,_0x3534ff){_0x3534ff=_0x3534ff||0xcc;return function(_0x51d2ec){if(_0x51d2ec){return _0x3fb9c2[_0x8a9c('0x11')](_0x3534ff);}return _0x3fb9c2['status'](_0x3534ff)[_0x8a9c('0x12')]();};}function respondWithResult(_0x205d0a,_0x283be6){_0x283be6=_0x283be6||0xc8;return function(_0x96f008){if(_0x96f008){return _0x205d0a['status'](_0x283be6)['json'](_0x96f008);}};}function respondWithFilteredResult(_0x513aaf,_0x409b85){return function(_0x2d18a6){if(_0x2d18a6){var _0x44f136=typeof _0x409b85[_0x8a9c('0x13')]===_0x8a9c('0x14')&&typeof _0x409b85[_0x8a9c('0x15')]===_0x8a9c('0x14');var _0x37856c=_0x2d18a6[_0x8a9c('0x16')];var _0x530556=_0x44f136?0x0:_0x409b85['offset'];var _0x2fa9b4=_0x44f136?_0x2d18a6[_0x8a9c('0x16')]:_0x409b85[_0x8a9c('0x13')]+_0x409b85['limit'];var _0x35cc47;if(_0x2fa9b4>=_0x37856c){_0x2fa9b4=_0x37856c;_0x35cc47=0xc8;}else{_0x35cc47=0xce;}_0x513aaf[_0x8a9c('0x17')](_0x35cc47);return _0x513aaf[_0x8a9c('0x18')](_0x8a9c('0x19'),_0x530556+'-'+_0x2fa9b4+'/'+_0x37856c)[_0x8a9c('0x1a')](_0x2d18a6);}return null;};}function saveUpdates(_0x53a69f){return function(_0x536039){if(_0x536039){return _0x536039[_0x8a9c('0x1b')](_0x53a69f)[_0x8a9c('0x1c')](function(_0xe00d60){return _0xe00d60;});}return null;};}function removeEntity(_0xde5c09){return function(_0x1dea68){if(_0x1dea68){return _0x1dea68[_0x8a9c('0x1d')]()[_0x8a9c('0x1c')](function(){_0xde5c09[_0x8a9c('0x17')](0xcc)[_0x8a9c('0x12')]();});}};}function handleEntityNotFound(_0x300c87){return function(_0x1bbe1f){if(!_0x1bbe1f){_0x300c87[_0x8a9c('0x11')](0x194);}return _0x1bbe1f;};}function handleError(_0x4b12e5,_0x2ec150){_0x2ec150=_0x2ec150||0x1f4;return function(_0x441026){logger[_0x8a9c('0x1e')](_0x441026[_0x8a9c('0x1f')]);if(_0x441026[_0x8a9c('0x20')]){delete _0x441026[_0x8a9c('0x20')];}_0x4b12e5[_0x8a9c('0x17')](_0x2ec150)[_0x8a9c('0x21')](_0x441026);};}exports[_0x8a9c('0x22')]=function(_0x52bdb0,_0x4b13c2){var _0x51f9af={};var _0x11aecc=_[_0x8a9c('0x23')](db[_0x8a9c('0x24')][_0x8a9c('0x25')],function(_0x25be58){return{'name':_0x25be58[_0x8a9c('0x26')],'type':_0x25be58[_0x8a9c('0x27')][_0x8a9c('0x28')]};});_0x51f9af=qs[_0x8a9c('0x29')](_0x11aecc,_0x52bdb0);return interaction[_0x8a9c('0x2a')](_0x8a9c('0x2b'),_0x52bdb0['query'],_0x52bdb0['user'],_0x51f9af,_0x11aecc)[_0x8a9c('0x1c')](respondWithFilteredResult(_0x4b13c2,_0x51f9af))['catch'](handleError(_0x4b13c2,null));};exports['show']=function(_0x191356,_0x4fb627){var _0x119452={'raw':![],'where':{'id':_0x191356[_0x8a9c('0x2c')]['id']}},_0x399087={};_0x399087['model']=_[_0x8a9c('0x2d')](db[_0x8a9c('0x24')][_0x8a9c('0x25')]);_0x399087[_0x8a9c('0x2e')]=_[_0x8a9c('0x2d')](_0x191356[_0x8a9c('0x2e')]);_0x399087['filters']=_[_0x8a9c('0x2f')](_0x399087[_0x8a9c('0x30')],_0x399087[_0x8a9c('0x2e')]);_0x119452['attributes']=_[_0x8a9c('0x2f')](_0x399087[_0x8a9c('0x30')],qs[_0x8a9c('0x31')](_0x191356[_0x8a9c('0x2e')]['fields']));_0x119452[_0x8a9c('0x32')]=_0x119452[_0x8a9c('0x32')][_0x8a9c('0x33')]?_0x119452[_0x8a9c('0x32')]:_0x399087['model'];if(_0x191356[_0x8a9c('0x2e')][_0x8a9c('0x34')]){_0x119452[_0x8a9c('0x35')]=[{'all':!![]}];}_0x119452=_['merge']({},_0x119452,_0x191356[_0x8a9c('0x36')]);return db[_0x8a9c('0x24')]['find'](_0x119452)[_0x8a9c('0x1c')](handleEntityNotFound(_0x4fb627,null))[_0x8a9c('0x1c')](respondWithResult(_0x4fb627,null))[_0x8a9c('0x37')](handleError(_0x4fb627,null));};exports['create']=function(_0x2cbb18,_0x1fc7af){return db[_0x8a9c('0x24')][_0x8a9c('0x38')](_0x2cbb18[_0x8a9c('0x39')],{})[_0x8a9c('0x1c')](respondWithResult(_0x1fc7af,0xc9))[_0x8a9c('0x37')](handleError(_0x1fc7af,null));};exports[_0x8a9c('0x1b')]=function(_0x127d66,_0x558d42){if(_0x127d66[_0x8a9c('0x39')]['id']){delete _0x127d66['body']['id'];}return db['MailInteraction'][_0x8a9c('0x3a')]({'where':{'id':_0x127d66[_0x8a9c('0x2c')]['id']}})[_0x8a9c('0x1c')](handleEntityNotFound(_0x558d42,null))[_0x8a9c('0x1c')](saveUpdates(_0x127d66['body'],null))[_0x8a9c('0x1c')](respondWithResult(_0x558d42,null))[_0x8a9c('0x37')](handleError(_0x558d42,null));};exports[_0x8a9c('0x1d')]=function(_0x44827c,_0x2e7fa6){return db[_0x8a9c('0x24')][_0x8a9c('0x3a')]({'where':{'id':_0x44827c['params']['id']}})[_0x8a9c('0x1c')](handleEntityNotFound(_0x2e7fa6,null))['then'](removeEntity(_0x2e7fa6,null))[_0x8a9c('0x37')](handleError(_0x2e7fa6,null));};exports[_0x8a9c('0x3b')]=function(_0x37c0db,_0x1418b1){return db[_0x8a9c('0x24')][_0x8a9c('0x3b')]()[_0x8a9c('0x1c')](respondWithResult(_0x1418b1,null))[_0x8a9c('0x37')](handleError(_0x1418b1,null));};exports['addMessage']=function(_0x13fd1c,_0x1ea32c){return db[_0x8a9c('0x3c')]['find']({'where':{'id':_0x13fd1c[_0x8a9c('0x2c')]['id']}})[_0x8a9c('0x1c')](handleEntityNotFound(_0x1ea32c,null))[_0x8a9c('0x1c')](function(_0x28a6c5){if(_0x28a6c5){return _0x28a6c5[_0x8a9c('0x3d')](_0x13fd1c['body']['ids'],_['omit'](_0x13fd1c['body'],['ids','id'])||{});}})[_0x8a9c('0x1c')](respondWithResult(_0x1ea32c,null))[_0x8a9c('0x37')](handleError(_0x1ea32c,null));};exports[_0x8a9c('0x3e')]=function(_0x18b9f9,_0x3a2f03){var _0x1a11fa={'raw':![],'where':{}};var _0x665644={};var _0x4fdcda={'count':0x0,'rows':[]};return db[_0x8a9c('0x24')][_0x8a9c('0x3f')]({'where':{'id':_0x18b9f9[_0x8a9c('0x2c')]['id']}})[_0x8a9c('0x1c')](handleEntityNotFound(_0x3a2f03,null))[_0x8a9c('0x1c')](function(_0x1491a2){if(_0x1491a2){_0x665644[_0x8a9c('0x30')]=_[_0x8a9c('0x2d')](db[_0x8a9c('0x3c')]['rawAttributes']);_0x665644[_0x8a9c('0x2e')]=_['keys'](_0x18b9f9[_0x8a9c('0x2e')]);_0x665644[_0x8a9c('0x40')]=_[_0x8a9c('0x2f')](_0x665644[_0x8a9c('0x30')],_0x665644[_0x8a9c('0x2e')]);_0x1a11fa[_0x8a9c('0x32')]=_[_0x8a9c('0x2f')](_0x665644['model'],qs['fields'](_0x18b9f9[_0x8a9c('0x2e')][_0x8a9c('0x31')]));_0x1a11fa[_0x8a9c('0x32')]=_0x1a11fa[_0x8a9c('0x32')][_0x8a9c('0x33')]?_0x1a11fa['attributes']:_0x665644[_0x8a9c('0x30')];if(!_0x18b9f9['query'][_0x8a9c('0x41')](_0x8a9c('0x42'))){_0x1a11fa[_0x8a9c('0x15')]=qs[_0x8a9c('0x15')](_0x18b9f9[_0x8a9c('0x2e')][_0x8a9c('0x15')]);_0x1a11fa[_0x8a9c('0x13')]=qs[_0x8a9c('0x13')](_0x18b9f9[_0x8a9c('0x2e')]['offset']);}_0x1a11fa[_0x8a9c('0x43')]=qs['sort'](_0x18b9f9[_0x8a9c('0x2e')][_0x8a9c('0x44')]);_0x1a11fa['where']=qs[_0x8a9c('0x40')](_['pick'](_0x18b9f9['query'],_0x665644[_0x8a9c('0x40')]));_0x1a11fa[_0x8a9c('0x45')]['MailInteractionId']=_0x1491a2['id'];if(_0x18b9f9[_0x8a9c('0x2e')][_0x8a9c('0x46')]){_0x1a11fa[_0x8a9c('0x45')]=_[_0x8a9c('0x47')](_0x1a11fa[_0x8a9c('0x45')],{'$or':_['map'](_0x1a11fa[_0x8a9c('0x32')],function(_0x3aa161){var _0x3459f9={};_0x3459f9[_0x3aa161]={'$like':'%'+_0x18b9f9[_0x8a9c('0x2e')]['filter']+'%'};return _0x3459f9;})});}if(_0x18b9f9[_0x8a9c('0x2e')][_0x8a9c('0x48')]){var _0x3e7efd=_0x18b9f9['query'][_0x8a9c('0x48')][_0x8a9c('0x49')](',');var _0x181e20={};_0x181e20[_0x3e7efd[0x0]]={'$gte':moment(_0x3e7efd[0x1])['format'](_0x8a9c('0x4a'))};_0x1a11fa[_0x8a9c('0x45')]=_['merge'](_0x1a11fa['where'],_0x181e20);}_0x1a11fa=_[_0x8a9c('0x47')]({},_0x1a11fa,_0x18b9f9[_0x8a9c('0x36')]);return db['MailMessage'][_0x8a9c('0x16')]({'where':_0x1a11fa['where']})[_0x8a9c('0x1c')](function(_0x1f310b){_0x4fdcda[_0x8a9c('0x16')]=_0x1f310b;if(_0x18b9f9[_0x8a9c('0x2e')][_0x8a9c('0x34')]){_0x1a11fa[_0x8a9c('0x35')]=[{'all':!![]}];}return db['MailMessage'][_0x8a9c('0x2a')](_0x1a11fa);})[_0x8a9c('0x1c')](function(_0x581290){if(_0x18b9f9[_0x8a9c('0x2e')]['inlineCss']===_0x8a9c('0x4b')){for(var _0x3d311c=0x0;_0x3d311c<_0x581290[_0x8a9c('0x33')];_0x3d311c++){_0x581290[_0x3d311c][_0x8a9c('0x39')]=juice(_0x581290[_0x3d311c][_0x8a9c('0x39')]);}}_0x4fdcda[_0x8a9c('0x4c')]=_0x581290;return _0x4fdcda;});}})[_0x8a9c('0x1c')](respondWithFilteredResult(_0x3a2f03,_0x1a11fa))[_0x8a9c('0x37')](handleError(_0x3a2f03,null));};exports['addTags']=function(_0x4cbb60,_0xdb8361){return db['MailInteraction'][_0x8a9c('0x3a')]({'where':{'id':_0x4cbb60[_0x8a9c('0x2c')]['id']}})[_0x8a9c('0x1c')](handleEntityNotFound(_0xdb8361,null))[_0x8a9c('0x1c')](function(_0x152c1e){if(_0x152c1e){return _0x152c1e[_0x8a9c('0x4d')](_0x4cbb60[_0x8a9c('0x39')]['ids'],_[_0x8a9c('0x4e')](_0x4cbb60['body'],[_0x8a9c('0x4f'),'id'])||{})[_0x8a9c('0x50')](function(){return db[_0x8a9c('0x51')]['findAll']({'attributes':['id',_0x8a9c('0x20'),_0x8a9c('0x52')],'where':{'id':_0x4cbb60[_0x8a9c('0x39')]['ids']}});})[_0x8a9c('0x1c')](function(_0x5e473a){socket[_0x8a9c('0x53')](_0x8a9c('0x54'),{'id':Number(_0x4cbb60[_0x8a9c('0x2c')]['id']),'tags':_0x5e473a||[]});return{'id':Number(_0x4cbb60[_0x8a9c('0x2c')]['id']),'tags':_0x5e473a||[]};});}})['then'](respondWithResult(_0xdb8361,null))[_0x8a9c('0x37')](handleError(_0xdb8361,null));};exports['removeTags']=function(_0x1d663c,_0x989732){return db[_0x8a9c('0x24')][_0x8a9c('0x3a')]({'where':{'id':_0x1d663c[_0x8a9c('0x2c')]['id']}})[_0x8a9c('0x1c')](handleEntityNotFound(_0x989732,null))[_0x8a9c('0x1c')](function(_0x4c4521){if(_0x4c4521){return _0x4c4521[_0x8a9c('0x55')](_0x1d663c[_0x8a9c('0x2e')][_0x8a9c('0x4f')]);}})[_0x8a9c('0x1c')](respondWithStatusCode(_0x989732,null))[_0x8a9c('0x37')](handleError(_0x989732,null));};exports[_0x8a9c('0x56')]=function(_0x2edc58,_0x526dd3){var _0x942846=moment()[_0x8a9c('0x57')]()[_0x8a9c('0x58')]();var _0x3b5185=path['join'](config[_0x8a9c('0x59')],_0x8a9c('0x5a'),_0x8a9c('0x5b'),_0x8a9c('0x5c'));var _0x429d43=path['join'](config[_0x8a9c('0x59')],_0x8a9c('0x5a'),'files','attachments');var _0x3709b5=path[_0x8a9c('0x5d')](_0x3b5185,_0x942846);var _0x24e377=util['format'](_0x8a9c('0x5e'),_0x2edc58['params']['id'],_0x942846);var _0x30d28b=path[_0x8a9c('0x5d')](_0x3b5185,_0x24e377);var _0x3fc427=[];if(_0x2edc58[_0x8a9c('0x2e')]['attachments']){_0x3fc427[_0x8a9c('0x5f')]({'model':db[_0x8a9c('0x60')],'as':_0x8a9c('0x61'),'raw':!![]});}var _0x5d2be9=[{'model':db[_0x8a9c('0x3c')],'as':_0x8a9c('0x62'),'attributes':['id',_0x8a9c('0x39'),_0x8a9c('0x63'),'to','cc','bcc',_0x8a9c('0x64'),_0x8a9c('0x65')],'where':{'secret':![]},'order':qs[_0x8a9c('0x44')]('id'),'include':_0x3fc427}];return db[_0x8a9c('0x24')][_0x8a9c('0x3a')]({'where':{'id':_0x2edc58[_0x8a9c('0x2c')]['id']},'include':_0x5d2be9})[_0x8a9c('0x1c')](handleEntityNotFound(_0x526dd3,null))[_0x8a9c('0x1c')](function(_0x1bad7d){if(_0x1bad7d&&_0x1bad7d[_0x8a9c('0x62')]){var _0x4510d1=_0x1bad7d[_0x8a9c('0x66')]({'plain':!![]});fs[_0x8a9c('0x67')](_0x3709b5);return BPromise[_0x8a9c('0x68')](_0x4510d1[_0x8a9c('0x62')],function(_0x1384d5,_0x2e72d7){var _0x889780={'from':_0x1384d5[_0x8a9c('0x63')],'to':_0x1384d5['to']||_0x8a9c('0x69'),'subject':_0x1384d5['subject'],'html':htmlEntities[_0x8a9c('0x6a')](_0x1384d5[_0x8a9c('0x39')]),'headers':{'Date':moment(_0x1384d5[_0x8a9c('0x65')])[_0x8a9c('0x6b')](_0x8a9c('0x6c'))},'attachments':[]};if(_0x1384d5['cc']){_0x889780[_0x8a9c('0x6d')]['Cc']=_0x1384d5['cc'];}if(_0x1384d5[_0x8a9c('0x6e')]){_0x889780[_0x8a9c('0x6d')][_0x8a9c('0x6f')]=_0x1384d5['bcc'];}return new BPromise(function(_0x3c14e4,_0x301c92){if(_0x1384d5['Attachments']){for(var _0x5dbb14=0x0;_0x5dbb14<_0x1384d5['Attachments'][_0x8a9c('0x33')];_0x5dbb14++){var _0x1e4220=_0x1384d5[_0x8a9c('0x61')][_0x5dbb14];var _0x539e0b=path[_0x8a9c('0x5d')](_0x429d43,_0x1e4220['basename']);if(fs[_0x8a9c('0x70')](_0x539e0b)){_0x889780[_0x8a9c('0x71')]['push']({'name':_0x1e4220[_0x8a9c('0x20')],'contentType':_0x1e4220['type'],'data':fs[_0x8a9c('0x72')](_0x539e0b)});}}}emlformat[_0x8a9c('0x73')](_0x889780,function(_0x1524c6,_0xf79a0f){if(_0x1524c6)return _0x301c92(_0x1524c6);fs[_0x8a9c('0x74')](path[_0x8a9c('0x5d')](_0x3709b5,util['format'](_0x8a9c('0x75'),_0x2e72d7)),_0xf79a0f);return _0x3c14e4(_0xf79a0f);});});})[_0x8a9c('0x1c')](function(){return new BPromise(function(_0x262c11,_0x4c5595){zipdir(_0x3709b5,{'saveTo':_0x30d28b},function(_0x545613,_0x1a9c6c){if(_0x545613)return _0x4c5595(_0x545613);return _0x262c11(_0x1a9c6c);});})['then'](function(){return new BPromise(function(_0x4d66c8,_0x42be33){rimraf(_0x3709b5,function(_0x3c013c){if(_0x3c013c)_0x42be33(_0x3c013c);return _0x4d66c8();});});})[_0x8a9c('0x1c')](function(){return _0x526dd3['download'](_0x30d28b,_0x24e377,function(_0xf6158a){if(!_0xf6158a)fs[_0x8a9c('0x76')](_0x30d28b);});});});}else{return _0x526dd3[_0x8a9c('0x11')](0xc8);}})['catch'](handleError(_0x526dd3,null));};
\ No newline at end of file
+var _0xbb90=['root','files','tmp','join','server','attachments','transcript-%d-%s.zip','push','Attachment','Attachments','Messages','bcc','createdAt','get','mkdirSync','from','subject','decode','ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ','headers','Bcc','existsSync','readFileSync','build','writeFileSync','unlinkSync','eml-format','rimraf','zip-dir','moment','path','lodash','juice','ioredis','../../components/interaction/service','../../components/parsers/qs','../../config/logger','api','../../mysqldb','redis','localhost','socket.io-emitter','./mailInteraction.socket','register','status','json','undefined','limit','count','offset','set','Content-Range','update','then','destroy','sendStatus','error','name','index','map','rawAttributes','type','key','getOptions','findAll','query','catch','show','model','keys','MailInteraction','filters','intersection','attributes','fields','length','includeAll','include','merge','options','find','body','params','describe','addMessage','MailMessage','ids','omit','hasOwnProperty','nolimit','order','sort','where','pick','MailInteractionId','filter','$gte','format','YYYY-MM-DD\x20HH:mm:ss','inlineCss','true','rows','addTags','setTags','spread','removeTags','download','unix','toString'];(function(_0x163e9b,_0x5e5603){var _0x1244fc=function(_0x204980){while(--_0x204980){_0x163e9b['push'](_0x163e9b['shift']());}};_0x1244fc(++_0x5e5603);}(_0xbb90,0x87));var _0x0bb9=function(_0x146130,_0x3c70e0){_0x146130=_0x146130-0x0;var _0x2c0647=_0xbb90[_0x146130];return _0x2c0647;};'use strict';var emlformat=require(_0x0bb9('0x0'));var rimraf=require(_0x0bb9('0x1'));var zipdir=require(_0x0bb9('0x2'));var moment=require(_0x0bb9('0x3'));var BPromise=require('bluebird');var util=require('util');var path=require(_0x0bb9('0x4'));var fs=require('fs');var _=require(_0x0bb9('0x5'));var juice=require(_0x0bb9('0x6'));var Redis=require(_0x0bb9('0x7'));var interaction=require(_0x0bb9('0x8'));var qs=require(_0x0bb9('0x9'));var logger=require(_0x0bb9('0xa'))(_0x0bb9('0xb'));var config=require('../../config/environment');var db=require(_0x0bb9('0xc'))['db'];var htmlEntities=require('html-entities');config[_0x0bb9('0xd')]=_['defaults'](config['redis'],{'host':_0x0bb9('0xe'),'port':0x18eb});var socket=require(_0x0bb9('0xf'))(new Redis(config[_0x0bb9('0xd')]));require(_0x0bb9('0x10'))[_0x0bb9('0x11')](socket);function respondWithStatusCode(_0x46aa20,_0x4b13ef){_0x4b13ef=_0x4b13ef||0xcc;return function(_0x44a977){if(_0x44a977){return _0x46aa20['sendStatus'](_0x4b13ef);}return _0x46aa20[_0x0bb9('0x12')](_0x4b13ef)['end']();};}function respondWithResult(_0x457f7d,_0x60f8d4){_0x60f8d4=_0x60f8d4||0xc8;return function(_0x545b52){if(_0x545b52){return _0x457f7d[_0x0bb9('0x12')](_0x60f8d4)[_0x0bb9('0x13')](_0x545b52);}};}function respondWithFilteredResult(_0x51cde7,_0x5064ff){return function(_0x1ee4e0){if(_0x1ee4e0){var _0x3c96f1=typeof _0x5064ff['offset']===_0x0bb9('0x14')&&typeof _0x5064ff[_0x0bb9('0x15')]===_0x0bb9('0x14');var _0x3882af=_0x1ee4e0[_0x0bb9('0x16')];var _0x5974a6=_0x3c96f1?0x0:_0x5064ff[_0x0bb9('0x17')];var _0x20d814=_0x3c96f1?_0x1ee4e0[_0x0bb9('0x16')]:_0x5064ff[_0x0bb9('0x17')]+_0x5064ff[_0x0bb9('0x15')];var _0x1f8008;if(_0x20d814>=_0x3882af){_0x20d814=_0x3882af;_0x1f8008=0xc8;}else{_0x1f8008=0xce;}_0x51cde7[_0x0bb9('0x12')](_0x1f8008);return _0x51cde7[_0x0bb9('0x18')](_0x0bb9('0x19'),_0x5974a6+'-'+_0x20d814+'/'+_0x3882af)[_0x0bb9('0x13')](_0x1ee4e0);}return null;};}function saveUpdates(_0x1b96cc){return function(_0x4db7de){if(_0x4db7de){return _0x4db7de[_0x0bb9('0x1a')](_0x1b96cc)[_0x0bb9('0x1b')](function(_0x43155b){return _0x43155b;});}return null;};}function removeEntity(_0x3acd4c){return function(_0x275e0b){if(_0x275e0b){return _0x275e0b[_0x0bb9('0x1c')]()[_0x0bb9('0x1b')](function(){_0x3acd4c[_0x0bb9('0x12')](0xcc)['end']();});}};}function handleEntityNotFound(_0x3f405e){return function(_0x3645fe){if(!_0x3645fe){_0x3f405e[_0x0bb9('0x1d')](0x194);}return _0x3645fe;};}function handleError(_0x4a39f4,_0x4e6e50){_0x4e6e50=_0x4e6e50||0x1f4;return function(_0x512c4c){logger[_0x0bb9('0x1e')](_0x512c4c['stack']);if(_0x512c4c['name']){delete _0x512c4c[_0x0bb9('0x1f')];}_0x4a39f4[_0x0bb9('0x12')](_0x4e6e50)['send'](_0x512c4c);};}exports[_0x0bb9('0x20')]=function(_0x1629fc,_0x27f70e){var _0x4d40d5={};var _0x1ec364=_[_0x0bb9('0x21')](db['MailInteraction'][_0x0bb9('0x22')],function(_0x4c156b){return{'name':_0x4c156b['fieldName'],'type':_0x4c156b[_0x0bb9('0x23')][_0x0bb9('0x24')]};});_0x4d40d5=qs[_0x0bb9('0x25')](_0x1ec364,_0x1629fc);return interaction[_0x0bb9('0x26')]('mail',_0x1629fc[_0x0bb9('0x27')],_0x1629fc['user'],_0x4d40d5,_0x1ec364)['then'](respondWithFilteredResult(_0x27f70e,_0x4d40d5))[_0x0bb9('0x28')](handleError(_0x27f70e,null));};exports[_0x0bb9('0x29')]=function(_0x3ff83c,_0x480f79){var _0x5adf0c={'raw':![],'where':{'id':_0x3ff83c['params']['id']}},_0x25ba9b={};_0x25ba9b[_0x0bb9('0x2a')]=_[_0x0bb9('0x2b')](db[_0x0bb9('0x2c')][_0x0bb9('0x22')]);_0x25ba9b[_0x0bb9('0x27')]=_['keys'](_0x3ff83c[_0x0bb9('0x27')]);_0x25ba9b[_0x0bb9('0x2d')]=_[_0x0bb9('0x2e')](_0x25ba9b[_0x0bb9('0x2a')],_0x25ba9b[_0x0bb9('0x27')]);_0x5adf0c[_0x0bb9('0x2f')]=_[_0x0bb9('0x2e')](_0x25ba9b[_0x0bb9('0x2a')],qs[_0x0bb9('0x30')](_0x3ff83c[_0x0bb9('0x27')]['fields']));_0x5adf0c[_0x0bb9('0x2f')]=_0x5adf0c[_0x0bb9('0x2f')][_0x0bb9('0x31')]?_0x5adf0c[_0x0bb9('0x2f')]:_0x25ba9b[_0x0bb9('0x2a')];if(_0x3ff83c[_0x0bb9('0x27')][_0x0bb9('0x32')]){_0x5adf0c[_0x0bb9('0x33')]=[{'all':!![]}];}_0x5adf0c=_[_0x0bb9('0x34')]({},_0x5adf0c,_0x3ff83c[_0x0bb9('0x35')]);return db[_0x0bb9('0x2c')][_0x0bb9('0x36')](_0x5adf0c)[_0x0bb9('0x1b')](handleEntityNotFound(_0x480f79,null))[_0x0bb9('0x1b')](respondWithResult(_0x480f79,null))[_0x0bb9('0x28')](handleError(_0x480f79,null));};exports['create']=function(_0x300883,_0x1fb47b){return db[_0x0bb9('0x2c')]['create'](_0x300883[_0x0bb9('0x37')],{})[_0x0bb9('0x1b')](respondWithResult(_0x1fb47b,0xc9))[_0x0bb9('0x28')](handleError(_0x1fb47b,null));};exports[_0x0bb9('0x1a')]=function(_0x3f0cd6,_0x5bf414){if(_0x3f0cd6[_0x0bb9('0x37')]['id']){delete _0x3f0cd6['body']['id'];}return db[_0x0bb9('0x2c')][_0x0bb9('0x36')]({'where':{'id':_0x3f0cd6[_0x0bb9('0x38')]['id']}})[_0x0bb9('0x1b')](handleEntityNotFound(_0x5bf414,null))[_0x0bb9('0x1b')](saveUpdates(_0x3f0cd6[_0x0bb9('0x37')],null))['then'](respondWithResult(_0x5bf414,null))[_0x0bb9('0x28')](handleError(_0x5bf414,null));};exports['destroy']=function(_0x33d6cb,_0x3774fb){return db[_0x0bb9('0x2c')]['find']({'where':{'id':_0x33d6cb[_0x0bb9('0x38')]['id']}})[_0x0bb9('0x1b')](handleEntityNotFound(_0x3774fb,null))[_0x0bb9('0x1b')](removeEntity(_0x3774fb,null))[_0x0bb9('0x28')](handleError(_0x3774fb,null));};exports[_0x0bb9('0x39')]=function(_0x10a75c,_0x3a65a2){return db[_0x0bb9('0x2c')][_0x0bb9('0x39')]()[_0x0bb9('0x1b')](respondWithResult(_0x3a65a2,null))['catch'](handleError(_0x3a65a2,null));};exports[_0x0bb9('0x3a')]=function(_0x290ea1,_0x1d209e){return db[_0x0bb9('0x3b')][_0x0bb9('0x36')]({'where':{'id':_0x290ea1[_0x0bb9('0x38')]['id']}})[_0x0bb9('0x1b')](handleEntityNotFound(_0x1d209e,null))[_0x0bb9('0x1b')](function(_0xc22d5c){if(_0xc22d5c){return _0xc22d5c[_0x0bb9('0x3a')](_0x290ea1[_0x0bb9('0x37')][_0x0bb9('0x3c')],_[_0x0bb9('0x3d')](_0x290ea1['body'],['ids','id'])||{});}})['then'](respondWithResult(_0x1d209e,null))[_0x0bb9('0x28')](handleError(_0x1d209e,null));};exports['getMessages']=function(_0x9756fd,_0x41d927){var _0x505f9c={'raw':![],'where':{}};var _0x2af7b6={};var _0x14ff6e={'count':0x0,'rows':[]};return db['MailInteraction']['findOne']({'where':{'id':_0x9756fd[_0x0bb9('0x38')]['id']}})[_0x0bb9('0x1b')](handleEntityNotFound(_0x41d927,null))[_0x0bb9('0x1b')](function(_0x374ee3){if(_0x374ee3){_0x2af7b6[_0x0bb9('0x2a')]=_[_0x0bb9('0x2b')](db[_0x0bb9('0x3b')]['rawAttributes']);_0x2af7b6[_0x0bb9('0x27')]=_[_0x0bb9('0x2b')](_0x9756fd['query']);_0x2af7b6['filters']=_['intersection'](_0x2af7b6[_0x0bb9('0x2a')],_0x2af7b6[_0x0bb9('0x27')]);_0x505f9c['attributes']=_['intersection'](_0x2af7b6['model'],qs[_0x0bb9('0x30')](_0x9756fd['query'][_0x0bb9('0x30')]));_0x505f9c[_0x0bb9('0x2f')]=_0x505f9c['attributes'][_0x0bb9('0x31')]?_0x505f9c[_0x0bb9('0x2f')]:_0x2af7b6[_0x0bb9('0x2a')];if(!_0x9756fd[_0x0bb9('0x27')][_0x0bb9('0x3e')](_0x0bb9('0x3f'))){_0x505f9c[_0x0bb9('0x15')]=qs[_0x0bb9('0x15')](_0x9756fd[_0x0bb9('0x27')][_0x0bb9('0x15')]);_0x505f9c[_0x0bb9('0x17')]=qs[_0x0bb9('0x17')](_0x9756fd[_0x0bb9('0x27')][_0x0bb9('0x17')]);}_0x505f9c[_0x0bb9('0x40')]=qs['sort'](_0x9756fd[_0x0bb9('0x27')][_0x0bb9('0x41')]);_0x505f9c[_0x0bb9('0x42')]=qs[_0x0bb9('0x2d')](_[_0x0bb9('0x43')](_0x9756fd[_0x0bb9('0x27')],_0x2af7b6[_0x0bb9('0x2d')]));_0x505f9c[_0x0bb9('0x42')][_0x0bb9('0x44')]=_0x374ee3['id'];if(_0x9756fd[_0x0bb9('0x27')][_0x0bb9('0x45')]){_0x505f9c[_0x0bb9('0x42')]=_[_0x0bb9('0x34')](_0x505f9c['where'],{'$or':_[_0x0bb9('0x21')](_0x505f9c[_0x0bb9('0x2f')],function(_0x461837){var _0x190e20={};_0x190e20[_0x461837]={'$like':'%'+_0x9756fd[_0x0bb9('0x27')][_0x0bb9('0x45')]+'%'};return _0x190e20;})});}if(_0x9756fd[_0x0bb9('0x27')][_0x0bb9('0x46')]){var _0x4e19c4=_0x9756fd[_0x0bb9('0x27')]['$gte']['split'](',');var _0xc5a307={};_0xc5a307[_0x4e19c4[0x0]]={'$gte':moment(_0x4e19c4[0x1])[_0x0bb9('0x47')](_0x0bb9('0x48'))};_0x505f9c['where']=_[_0x0bb9('0x34')](_0x505f9c[_0x0bb9('0x42')],_0xc5a307);}_0x505f9c=_[_0x0bb9('0x34')]({},_0x505f9c,_0x9756fd['options']);return db[_0x0bb9('0x3b')][_0x0bb9('0x16')]({'where':_0x505f9c[_0x0bb9('0x42')]})['then'](function(_0x54778a){_0x14ff6e[_0x0bb9('0x16')]=_0x54778a;if(_0x9756fd['query']['includeAll']){_0x505f9c[_0x0bb9('0x33')]=[{'all':!![]}];}return db[_0x0bb9('0x3b')]['findAll'](_0x505f9c);})[_0x0bb9('0x1b')](function(_0x58b64c){if(_0x9756fd['query'][_0x0bb9('0x49')]===_0x0bb9('0x4a')){for(var _0x88d082=0x0;_0x88d082<_0x58b64c[_0x0bb9('0x31')];_0x88d082++){_0x58b64c[_0x88d082][_0x0bb9('0x37')]=juice(_0x58b64c[_0x88d082][_0x0bb9('0x37')]);}}_0x14ff6e[_0x0bb9('0x4b')]=_0x58b64c;return _0x14ff6e;});}})[_0x0bb9('0x1b')](respondWithFilteredResult(_0x41d927,_0x505f9c))[_0x0bb9('0x28')](handleError(_0x41d927,null));};exports[_0x0bb9('0x4c')]=function(_0x1f5d11,_0x3a4ccb){return db[_0x0bb9('0x2c')][_0x0bb9('0x36')]({'where':{'id':_0x1f5d11[_0x0bb9('0x38')]['id']}})[_0x0bb9('0x1b')](handleEntityNotFound(_0x3a4ccb,null))[_0x0bb9('0x1b')](function(_0x5592e7){if(_0x5592e7){return _0x5592e7[_0x0bb9('0x4d')](_0x1f5d11[_0x0bb9('0x37')]['ids'],_[_0x0bb9('0x3d')](_0x1f5d11['body'],[_0x0bb9('0x3c'),'id'])||{})[_0x0bb9('0x4e')](function(){return db['Tag'][_0x0bb9('0x26')]({'attributes':['id',_0x0bb9('0x1f'),'color'],'where':{'id':_0x1f5d11[_0x0bb9('0x37')][_0x0bb9('0x3c')]}});})[_0x0bb9('0x1b')](function(_0x49b906){socket['emit']('mailInteractionTags:save',{'id':Number(_0x1f5d11[_0x0bb9('0x38')]['id']),'tags':_0x49b906||[]});return{'id':Number(_0x1f5d11[_0x0bb9('0x38')]['id']),'tags':_0x49b906||[]};});}})['then'](respondWithResult(_0x3a4ccb,null))[_0x0bb9('0x28')](handleError(_0x3a4ccb,null));};exports[_0x0bb9('0x4f')]=function(_0x5150ca,_0x2a28bb){return db[_0x0bb9('0x2c')][_0x0bb9('0x36')]({'where':{'id':_0x5150ca[_0x0bb9('0x38')]['id']}})['then'](handleEntityNotFound(_0x2a28bb,null))[_0x0bb9('0x1b')](function(_0x4dd1db){if(_0x4dd1db){return _0x4dd1db[_0x0bb9('0x4f')](_0x5150ca[_0x0bb9('0x27')][_0x0bb9('0x3c')]);}})[_0x0bb9('0x1b')](respondWithStatusCode(_0x2a28bb,null))['catch'](handleError(_0x2a28bb,null));};exports[_0x0bb9('0x50')]=function(_0x15a48a,_0x448838){var _0x564a42=moment()[_0x0bb9('0x51')]()[_0x0bb9('0x52')]();var _0x1abee7=path['join'](config[_0x0bb9('0x53')],'server',_0x0bb9('0x54'),_0x0bb9('0x55'));var _0x37ca1b=path[_0x0bb9('0x56')](config[_0x0bb9('0x53')],_0x0bb9('0x57'),_0x0bb9('0x54'),_0x0bb9('0x58'));var _0x44c66f=path[_0x0bb9('0x56')](_0x1abee7,_0x564a42);var _0x51ef41=util['format'](_0x0bb9('0x59'),_0x15a48a[_0x0bb9('0x38')]['id'],_0x564a42);var _0x2052b0=path['join'](_0x1abee7,_0x51ef41);var _0x204f9c=[];if(_0x15a48a[_0x0bb9('0x27')][_0x0bb9('0x58')]){_0x204f9c[_0x0bb9('0x5a')]({'model':db[_0x0bb9('0x5b')],'as':_0x0bb9('0x5c'),'raw':!![]});}var _0x2671d3=[{'model':db['MailMessage'],'as':_0x0bb9('0x5d'),'attributes':['id',_0x0bb9('0x37'),'from','to','cc',_0x0bb9('0x5e'),'subject',_0x0bb9('0x5f')],'where':{'secret':![]},'order':qs[_0x0bb9('0x41')]('id'),'include':_0x204f9c}];return db[_0x0bb9('0x2c')][_0x0bb9('0x36')]({'where':{'id':_0x15a48a[_0x0bb9('0x38')]['id']},'include':_0x2671d3})[_0x0bb9('0x1b')](handleEntityNotFound(_0x448838,null))[_0x0bb9('0x1b')](function(_0x3b6b20){if(_0x3b6b20&&_0x3b6b20['Messages']){var _0x3f2fa3=_0x3b6b20[_0x0bb9('0x60')]({'plain':!![]});fs[_0x0bb9('0x61')](_0x44c66f);return BPromise['each'](_0x3f2fa3[_0x0bb9('0x5d')],function(_0x25a5ee,_0x59978d){var _0x5c681d={'from':_0x25a5ee[_0x0bb9('0x62')],'to':_0x25a5ee['to']||'missing.recipient@your.company.com','subject':_0x25a5ee[_0x0bb9('0x63')],'html':htmlEntities[_0x0bb9('0x64')](_0x25a5ee[_0x0bb9('0x37')]),'headers':{'Date':moment(_0x25a5ee[_0x0bb9('0x5f')])['format'](_0x0bb9('0x65'))},'attachments':[]};if(_0x25a5ee['cc']){_0x5c681d[_0x0bb9('0x66')]['Cc']=_0x25a5ee['cc'];}if(_0x25a5ee[_0x0bb9('0x5e')]){_0x5c681d[_0x0bb9('0x66')][_0x0bb9('0x67')]=_0x25a5ee[_0x0bb9('0x5e')];}return new BPromise(function(_0x33002a,_0x49e2c5){if(_0x25a5ee[_0x0bb9('0x5c')]){for(var _0x4927e7=0x0;_0x4927e7<_0x25a5ee['Attachments'][_0x0bb9('0x31')];_0x4927e7++){var _0x951402=_0x25a5ee[_0x0bb9('0x5c')][_0x4927e7];var _0x2c0267=path['join'](_0x37ca1b,_0x951402['basename']);if(fs[_0x0bb9('0x68')](_0x2c0267)){_0x5c681d[_0x0bb9('0x58')][_0x0bb9('0x5a')]({'name':_0x951402[_0x0bb9('0x1f')],'contentType':_0x951402['type'],'data':fs[_0x0bb9('0x69')](_0x2c0267)});}}}emlformat[_0x0bb9('0x6a')](_0x5c681d,function(_0x30dce2,_0xb4066b){if(_0x30dce2)return _0x49e2c5(_0x30dce2);fs[_0x0bb9('0x6b')](path[_0x0bb9('0x56')](_0x44c66f,util['format']('message%d.eml',_0x59978d)),_0xb4066b);return _0x33002a(_0xb4066b);});});})['then'](function(){return new BPromise(function(_0x29ac3d,_0x24827b){zipdir(_0x44c66f,{'saveTo':_0x2052b0},function(_0x2b2237,_0x4b35bc){if(_0x2b2237)return _0x24827b(_0x2b2237);return _0x29ac3d(_0x4b35bc);});})[_0x0bb9('0x1b')](function(){return new BPromise(function(_0x294be5,_0x520dfa){rimraf(_0x44c66f,function(_0x51883c){if(_0x51883c)_0x520dfa(_0x51883c);return _0x294be5();});});})[_0x0bb9('0x1b')](function(){return _0x448838[_0x0bb9('0x50')](_0x2052b0,_0x51ef41,function(_0xc2ebcd){if(!_0xc2ebcd)fs[_0x0bb9('0x6c')](_0x2052b0);});});});}else{return _0x448838[_0x0bb9('0x1d')](0xc8);}})[_0x0bb9('0x28')](handleError(_0x448838,null));};
\ No newline at end of file