Built motion from commit da24aabd.|2.6.20
[motion2.git] / server / api / mailInteraction / mailInteraction.controller.js
index 0cc4303..4c497e7 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xeb92=['register','sendStatus','end','status','json','offset','undefined','limit','count','set','Content-Range','update','then','destroy','error','stack','name','send','map','rawAttributes','fieldName','type','findAll','mail','query','user','catch','params','model','keys','MailInteraction','intersection','attributes','fields','include','options','find','create','body','addMessage','MailMessage','ids','getMessages','hasOwnProperty','nolimit','order','sort','where','filters','pick','MailInteractionId','filter','merge','$gte','split','format','YYYY-MM-DD\x20HH:mm:ss','includeAll','inlineCss','length','rows','addTags','setTags','omit','spread','Tag','color','emit','mailInteractionTags:save','removeTags','download','unix','join','root','server','tmp','files','attachments','transcript-%d-%s.zip','push','Attachments','Messages','from','bcc','subject','get','mkdirSync','decode','ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ','headers','Bcc','basename','existsSync','readFileSync','build','message%d.eml','unlinkSync','eml-format','rimraf','zip-dir','moment','util','lodash','juice','ioredis','../../components/parsers/qs','../../config/logger','api','../../config/environment','../../mysqldb','defaults','redis','socket.io-emitter','./mailInteraction.socket'];(function(_0xfcfc24,_0x48ca53){var _0x58f773=function(_0x263b5f){while(--_0x263b5f){_0xfcfc24['push'](_0xfcfc24['shift']());}};_0x58f773(++_0x48ca53);}(_0xeb92,0xd3));var _0x2eb9=function(_0x442000,_0x2e26c9){_0x442000=_0x442000-0x0;var _0x280b97=_0xeb92[_0x442000];return _0x280b97;};'use strict';var emlformat=require(_0x2eb9('0x0'));var rimraf=require(_0x2eb9('0x1'));var zipdir=require(_0x2eb9('0x2'));var moment=require(_0x2eb9('0x3'));var BPromise=require('bluebird');var util=require(_0x2eb9('0x4'));var path=require('path');var fs=require('fs');var _=require(_0x2eb9('0x5'));var juice=require(_0x2eb9('0x6'));var Redis=require(_0x2eb9('0x7'));var interaction=require('../../components/interaction/service');var qs=require(_0x2eb9('0x8'));var logger=require(_0x2eb9('0x9'))(_0x2eb9('0xa'));var config=require(_0x2eb9('0xb'));var db=require(_0x2eb9('0xc'))['db'];var htmlEntities=require('html-entities');config['redis']=_[_0x2eb9('0xd')](config[_0x2eb9('0xe')],{'host':'localhost','port':0x18eb});var socket=require(_0x2eb9('0xf'))(new Redis(config[_0x2eb9('0xe')]));require(_0x2eb9('0x10'))[_0x2eb9('0x11')](socket);function respondWithStatusCode(_0x4b6cc5,_0x382257){_0x382257=_0x382257||0xcc;return function(_0x2baf67){if(_0x2baf67){return _0x4b6cc5[_0x2eb9('0x12')](_0x382257);}return _0x4b6cc5['status'](_0x382257)[_0x2eb9('0x13')]();};}function respondWithResult(_0x2acce3,_0x19437d){_0x19437d=_0x19437d||0xc8;return function(_0x37cf39){if(_0x37cf39){return _0x2acce3[_0x2eb9('0x14')](_0x19437d)[_0x2eb9('0x15')](_0x37cf39);}};}function respondWithFilteredResult(_0x1c1719,_0x45427b){return function(_0x521c06){if(_0x521c06){var _0x4eedb8=typeof _0x45427b[_0x2eb9('0x16')]===_0x2eb9('0x17')&&typeof _0x45427b[_0x2eb9('0x18')]===_0x2eb9('0x17');var _0x1ec48b=_0x521c06[_0x2eb9('0x19')];var _0x182edc=_0x4eedb8?0x0:_0x45427b[_0x2eb9('0x16')];var _0x156e20=_0x4eedb8?_0x521c06['count']:_0x45427b['offset']+_0x45427b[_0x2eb9('0x18')];var _0x44bb96;if(_0x156e20>=_0x1ec48b){_0x156e20=_0x1ec48b;_0x44bb96=0xc8;}else{_0x44bb96=0xce;}_0x1c1719[_0x2eb9('0x14')](_0x44bb96);return _0x1c1719[_0x2eb9('0x1a')](_0x2eb9('0x1b'),_0x182edc+'-'+_0x156e20+'/'+_0x1ec48b)['json'](_0x521c06);}return null;};}function saveUpdates(_0x4860a0){return function(_0x53c774){if(_0x53c774){return _0x53c774[_0x2eb9('0x1c')](_0x4860a0)[_0x2eb9('0x1d')](function(_0x472492){return _0x472492;});}return null;};}function removeEntity(_0x48d8bc){return function(_0x11e7dd){if(_0x11e7dd){return _0x11e7dd[_0x2eb9('0x1e')]()[_0x2eb9('0x1d')](function(){_0x48d8bc[_0x2eb9('0x14')](0xcc)[_0x2eb9('0x13')]();});}};}function handleEntityNotFound(_0x2f51f6){return function(_0x32f88f){if(!_0x32f88f){_0x2f51f6[_0x2eb9('0x12')](0x194);}return _0x32f88f;};}function handleError(_0x1fef10,_0x4fad02){_0x4fad02=_0x4fad02||0x1f4;return function(_0x2d5468){logger[_0x2eb9('0x1f')](_0x2d5468[_0x2eb9('0x20')]);if(_0x2d5468['name']){delete _0x2d5468[_0x2eb9('0x21')];}_0x1fef10[_0x2eb9('0x14')](_0x4fad02)[_0x2eb9('0x22')](_0x2d5468);};}exports['index']=function(_0x44d435,_0x6c24ab){var _0x144b5c={};var _0x41b572=_[_0x2eb9('0x23')](db['MailInteraction'][_0x2eb9('0x24')],function(_0x373a27){return{'name':_0x373a27[_0x2eb9('0x25')],'type':_0x373a27[_0x2eb9('0x26')]['key']};});_0x144b5c=qs['getOptions'](_0x41b572,_0x44d435);return interaction[_0x2eb9('0x27')](_0x2eb9('0x28'),_0x44d435[_0x2eb9('0x29')],_0x44d435[_0x2eb9('0x2a')],_0x144b5c,_0x41b572)[_0x2eb9('0x1d')](respondWithFilteredResult(_0x6c24ab,_0x144b5c))[_0x2eb9('0x2b')](handleError(_0x6c24ab,null));};exports['show']=function(_0x165a36,_0x99ca3){var _0x4dc26d={'raw':![],'where':{'id':_0x165a36[_0x2eb9('0x2c')]['id']}},_0xb1e0cb={};_0xb1e0cb[_0x2eb9('0x2d')]=_[_0x2eb9('0x2e')](db[_0x2eb9('0x2f')][_0x2eb9('0x24')]);_0xb1e0cb[_0x2eb9('0x29')]=_['keys'](_0x165a36[_0x2eb9('0x29')]);_0xb1e0cb['filters']=_[_0x2eb9('0x30')](_0xb1e0cb[_0x2eb9('0x2d')],_0xb1e0cb[_0x2eb9('0x29')]);_0x4dc26d[_0x2eb9('0x31')]=_[_0x2eb9('0x30')](_0xb1e0cb['model'],qs[_0x2eb9('0x32')](_0x165a36[_0x2eb9('0x29')][_0x2eb9('0x32')]));_0x4dc26d[_0x2eb9('0x31')]=_0x4dc26d['attributes']['length']?_0x4dc26d[_0x2eb9('0x31')]:_0xb1e0cb[_0x2eb9('0x2d')];if(_0x165a36[_0x2eb9('0x29')]['includeAll']){_0x4dc26d[_0x2eb9('0x33')]=[{'all':!![]}];}_0x4dc26d=_['merge']({},_0x4dc26d,_0x165a36[_0x2eb9('0x34')]);return db['MailInteraction'][_0x2eb9('0x35')](_0x4dc26d)[_0x2eb9('0x1d')](handleEntityNotFound(_0x99ca3,null))['then'](respondWithResult(_0x99ca3,null))[_0x2eb9('0x2b')](handleError(_0x99ca3,null));};exports[_0x2eb9('0x36')]=function(_0x311d17,_0x1efea9){return db[_0x2eb9('0x2f')][_0x2eb9('0x36')](_0x311d17[_0x2eb9('0x37')],{})[_0x2eb9('0x1d')](respondWithResult(_0x1efea9,0xc9))['catch'](handleError(_0x1efea9,null));};exports[_0x2eb9('0x1c')]=function(_0x127210,_0x20df33){if(_0x127210[_0x2eb9('0x37')]['id']){delete _0x127210[_0x2eb9('0x37')]['id'];}return db['MailInteraction']['find']({'where':{'id':_0x127210[_0x2eb9('0x2c')]['id']}})[_0x2eb9('0x1d')](handleEntityNotFound(_0x20df33,null))[_0x2eb9('0x1d')](saveUpdates(_0x127210[_0x2eb9('0x37')],null))['then'](respondWithResult(_0x20df33,null))[_0x2eb9('0x2b')](handleError(_0x20df33,null));};exports[_0x2eb9('0x1e')]=function(_0x25751e,_0x2f49e7){return db[_0x2eb9('0x2f')]['find']({'where':{'id':_0x25751e['params']['id']}})['then'](handleEntityNotFound(_0x2f49e7,null))[_0x2eb9('0x1d')](removeEntity(_0x2f49e7,null))[_0x2eb9('0x2b')](handleError(_0x2f49e7,null));};exports['describe']=function(_0x3fb3b0,_0x1acaf8){return db[_0x2eb9('0x2f')]['describe']()[_0x2eb9('0x1d')](respondWithResult(_0x1acaf8,null))[_0x2eb9('0x2b')](handleError(_0x1acaf8,null));};exports[_0x2eb9('0x38')]=function(_0x3ec4bc,_0x392d1e){return db[_0x2eb9('0x39')][_0x2eb9('0x35')]({'where':{'id':_0x3ec4bc[_0x2eb9('0x2c')]['id']}})[_0x2eb9('0x1d')](handleEntityNotFound(_0x392d1e,null))[_0x2eb9('0x1d')](function(_0x3df5a7){if(_0x3df5a7){return _0x3df5a7[_0x2eb9('0x38')](_0x3ec4bc[_0x2eb9('0x37')][_0x2eb9('0x3a')],_['omit'](_0x3ec4bc[_0x2eb9('0x37')],[_0x2eb9('0x3a'),'id'])||{});}})['then'](respondWithResult(_0x392d1e,null))[_0x2eb9('0x2b')](handleError(_0x392d1e,null));};exports[_0x2eb9('0x3b')]=function(_0x3edbf9,_0x538dd3){var _0x5c779e={'raw':![],'where':{}};var _0x21eb3b={};var _0x2d503a={'count':0x0,'rows':[]};return db['MailInteraction']['findOne']({'where':{'id':_0x3edbf9['params']['id']}})[_0x2eb9('0x1d')](handleEntityNotFound(_0x538dd3,null))[_0x2eb9('0x1d')](function(_0x547a84){if(_0x547a84){_0x21eb3b[_0x2eb9('0x2d')]=_[_0x2eb9('0x2e')](db[_0x2eb9('0x39')][_0x2eb9('0x24')]);_0x21eb3b[_0x2eb9('0x29')]=_[_0x2eb9('0x2e')](_0x3edbf9['query']);_0x21eb3b['filters']=_[_0x2eb9('0x30')](_0x21eb3b[_0x2eb9('0x2d')],_0x21eb3b[_0x2eb9('0x29')]);_0x5c779e[_0x2eb9('0x31')]=_[_0x2eb9('0x30')](_0x21eb3b[_0x2eb9('0x2d')],qs[_0x2eb9('0x32')](_0x3edbf9[_0x2eb9('0x29')][_0x2eb9('0x32')]));_0x5c779e['attributes']=_0x5c779e['attributes']['length']?_0x5c779e[_0x2eb9('0x31')]:_0x21eb3b['model'];if(!_0x3edbf9[_0x2eb9('0x29')][_0x2eb9('0x3c')](_0x2eb9('0x3d'))){_0x5c779e[_0x2eb9('0x18')]=qs[_0x2eb9('0x18')](_0x3edbf9[_0x2eb9('0x29')][_0x2eb9('0x18')]);_0x5c779e['offset']=qs['offset'](_0x3edbf9[_0x2eb9('0x29')][_0x2eb9('0x16')]);}_0x5c779e[_0x2eb9('0x3e')]=qs[_0x2eb9('0x3f')](_0x3edbf9['query'][_0x2eb9('0x3f')]);_0x5c779e[_0x2eb9('0x40')]=qs[_0x2eb9('0x41')](_[_0x2eb9('0x42')](_0x3edbf9[_0x2eb9('0x29')],_0x21eb3b[_0x2eb9('0x41')]));_0x5c779e[_0x2eb9('0x40')][_0x2eb9('0x43')]=_0x547a84['id'];if(_0x3edbf9[_0x2eb9('0x29')][_0x2eb9('0x44')]){_0x5c779e[_0x2eb9('0x40')]=_[_0x2eb9('0x45')](_0x5c779e['where'],{'$or':_[_0x2eb9('0x23')](_0x5c779e[_0x2eb9('0x31')],function(_0x264c7d){var _0x4d7766={};_0x4d7766[_0x264c7d]={'$like':'%'+_0x3edbf9['query']['filter']+'%'};return _0x4d7766;})});}if(_0x3edbf9['query']['$gte']){var _0x345883=_0x3edbf9[_0x2eb9('0x29')][_0x2eb9('0x46')][_0x2eb9('0x47')](',');var _0x1f7cb1={};_0x1f7cb1[_0x345883[0x0]]={'$gte':moment(_0x345883[0x1])[_0x2eb9('0x48')](_0x2eb9('0x49'))};_0x5c779e[_0x2eb9('0x40')]=_['merge'](_0x5c779e[_0x2eb9('0x40')],_0x1f7cb1);}_0x5c779e=_['merge']({},_0x5c779e,_0x3edbf9['options']);return db[_0x2eb9('0x39')][_0x2eb9('0x19')]({'where':_0x5c779e[_0x2eb9('0x40')]})[_0x2eb9('0x1d')](function(_0x200be1){_0x2d503a[_0x2eb9('0x19')]=_0x200be1;if(_0x3edbf9[_0x2eb9('0x29')][_0x2eb9('0x4a')]){_0x5c779e[_0x2eb9('0x33')]=[{'all':!![]}];}return db['MailMessage'][_0x2eb9('0x27')](_0x5c779e);})[_0x2eb9('0x1d')](function(_0x3d4895){if(_0x3edbf9['query'][_0x2eb9('0x4b')]==='true'){for(var _0xf064c=0x0;_0xf064c<_0x3d4895[_0x2eb9('0x4c')];_0xf064c++){_0x3d4895[_0xf064c]['body']=juice(_0x3d4895[_0xf064c][_0x2eb9('0x37')]);}}_0x2d503a[_0x2eb9('0x4d')]=_0x3d4895;return _0x2d503a;});}})[_0x2eb9('0x1d')](respondWithFilteredResult(_0x538dd3,_0x5c779e))[_0x2eb9('0x2b')](handleError(_0x538dd3,null));};exports[_0x2eb9('0x4e')]=function(_0x2b7552,_0xa13d74){return db[_0x2eb9('0x2f')][_0x2eb9('0x35')]({'where':{'id':_0x2b7552[_0x2eb9('0x2c')]['id']}})['then'](handleEntityNotFound(_0xa13d74,null))[_0x2eb9('0x1d')](function(_0x478ba7){if(_0x478ba7){return _0x478ba7[_0x2eb9('0x4f')](_0x2b7552[_0x2eb9('0x37')][_0x2eb9('0x3a')],_[_0x2eb9('0x50')](_0x2b7552[_0x2eb9('0x37')],[_0x2eb9('0x3a'),'id'])||{})[_0x2eb9('0x51')](function(){return db[_0x2eb9('0x52')][_0x2eb9('0x27')]({'attributes':['id','name',_0x2eb9('0x53')],'where':{'id':_0x2b7552[_0x2eb9('0x37')][_0x2eb9('0x3a')]}});})[_0x2eb9('0x1d')](function(_0x40826d){socket[_0x2eb9('0x54')](_0x2eb9('0x55'),{'id':Number(_0x2b7552[_0x2eb9('0x2c')]['id']),'tags':_0x40826d||[]});return{'id':Number(_0x2b7552[_0x2eb9('0x2c')]['id']),'tags':_0x40826d||[]};});}})[_0x2eb9('0x1d')](respondWithResult(_0xa13d74,null))[_0x2eb9('0x2b')](handleError(_0xa13d74,null));};exports[_0x2eb9('0x56')]=function(_0x1387e3,_0x10fcba){return db[_0x2eb9('0x2f')][_0x2eb9('0x35')]({'where':{'id':_0x1387e3[_0x2eb9('0x2c')]['id']}})[_0x2eb9('0x1d')](handleEntityNotFound(_0x10fcba,null))[_0x2eb9('0x1d')](function(_0x2b68b0){if(_0x2b68b0){return _0x2b68b0[_0x2eb9('0x56')](_0x1387e3[_0x2eb9('0x29')][_0x2eb9('0x3a')]);}})[_0x2eb9('0x1d')](respondWithStatusCode(_0x10fcba,null))[_0x2eb9('0x2b')](handleError(_0x10fcba,null));};exports[_0x2eb9('0x57')]=function(_0xe5095a,_0x55a5ff){var _0x596a9e=moment()[_0x2eb9('0x58')]()['toString']();var _0x331209=path[_0x2eb9('0x59')](config[_0x2eb9('0x5a')],_0x2eb9('0x5b'),'files',_0x2eb9('0x5c'));var _0x469420=path[_0x2eb9('0x59')](config[_0x2eb9('0x5a')],'server',_0x2eb9('0x5d'),_0x2eb9('0x5e'));var _0x1c8c1b=path[_0x2eb9('0x59')](_0x331209,_0x596a9e);var _0x13f2c4=util[_0x2eb9('0x48')](_0x2eb9('0x5f'),_0xe5095a[_0x2eb9('0x2c')]['id'],_0x596a9e);var _0x5614df=path[_0x2eb9('0x59')](_0x331209,_0x13f2c4);var _0xe1cfa7=[];if(_0xe5095a['query'][_0x2eb9('0x5e')]){_0xe1cfa7[_0x2eb9('0x60')]({'model':db['Attachment'],'as':_0x2eb9('0x61'),'raw':!![]});}var _0x13ca64=[{'model':db['MailMessage'],'as':_0x2eb9('0x62'),'attributes':['id',_0x2eb9('0x37'),_0x2eb9('0x63'),'to','cc',_0x2eb9('0x64'),_0x2eb9('0x65'),'createdAt'],'where':{'secret':![]},'order':qs[_0x2eb9('0x3f')]('id'),'include':_0xe1cfa7}];return db[_0x2eb9('0x2f')]['find']({'where':{'id':_0xe5095a['params']['id']},'include':_0x13ca64})['then'](handleEntityNotFound(_0x55a5ff,null))[_0x2eb9('0x1d')](function(_0x196a3e){if(_0x196a3e&&_0x196a3e[_0x2eb9('0x62')]){var _0x36cfc7=_0x196a3e[_0x2eb9('0x66')]({'plain':!![]});fs[_0x2eb9('0x67')](_0x1c8c1b);return BPromise['each'](_0x36cfc7['Messages'],function(_0x26a968,_0x1d4b24){var _0x40cd11={'from':_0x26a968[_0x2eb9('0x63')],'to':_0x26a968['to']||'missing.recipient@your.company.com','subject':_0x26a968[_0x2eb9('0x65')],'html':htmlEntities[_0x2eb9('0x68')](_0x26a968['body']),'headers':{'Date':moment(_0x26a968['createdAt'])[_0x2eb9('0x48')](_0x2eb9('0x69'))},'attachments':[]};if(_0x26a968['cc']){_0x40cd11[_0x2eb9('0x6a')]['Cc']=_0x26a968['cc'];}if(_0x26a968[_0x2eb9('0x64')]){_0x40cd11[_0x2eb9('0x6a')][_0x2eb9('0x6b')]=_0x26a968[_0x2eb9('0x64')];}return new BPromise(function(_0x27973d,_0x2e44e7){if(_0x26a968[_0x2eb9('0x61')]){for(var _0x49ad2c=0x0;_0x49ad2c<_0x26a968[_0x2eb9('0x61')][_0x2eb9('0x4c')];_0x49ad2c++){var _0x4fde9a=_0x26a968[_0x2eb9('0x61')][_0x49ad2c];var _0x9671f8=path['join'](_0x469420,_0x4fde9a[_0x2eb9('0x6c')]);if(fs[_0x2eb9('0x6d')](_0x9671f8)){_0x40cd11[_0x2eb9('0x5e')]['push']({'name':_0x4fde9a['name'],'contentType':_0x4fde9a['type'],'data':fs[_0x2eb9('0x6e')](_0x9671f8)});}}}emlformat[_0x2eb9('0x6f')](_0x40cd11,function(_0x42f339,_0x2da053){if(_0x42f339)return _0x2e44e7(_0x42f339);fs['writeFileSync'](path[_0x2eb9('0x59')](_0x1c8c1b,util[_0x2eb9('0x48')](_0x2eb9('0x70'),_0x1d4b24)),_0x2da053);return _0x27973d(_0x2da053);});});})[_0x2eb9('0x1d')](function(){return new BPromise(function(_0x10b21e,_0x28e3cc){zipdir(_0x1c8c1b,{'saveTo':_0x5614df},function(_0x20026c,_0x5a390f){if(_0x20026c)return _0x28e3cc(_0x20026c);return _0x10b21e(_0x5a390f);});})[_0x2eb9('0x1d')](function(){return new BPromise(function(_0x370f76,_0x3aaaf7){rimraf(_0x1c8c1b,function(_0x31abfb){if(_0x31abfb)_0x3aaaf7(_0x31abfb);return _0x370f76();});});})[_0x2eb9('0x1d')](function(){return _0x55a5ff[_0x2eb9('0x57')](_0x5614df,_0x13f2c4,function(_0x34318a){if(!_0x34318a)fs[_0x2eb9('0x71')](_0x5614df);});});});}else{return _0x55a5ff[_0x2eb9('0x12')](0xc8);}})['catch'](handleError(_0x55a5ff,null));};
\ No newline at end of file
+var _0x2acd=['inlineCss','true','rows','addTags','setTags','spread','Tag','color','mailInteractionTags:save','removeTags','unix','join','root','server','files','transcript-%d-%s.zip','attachments','push','Attachments','bcc','subject','createdAt','sort','Messages','missing.recipient@your.company.com','decode','Bcc','readFileSync','build','message%d.eml','eml-format','rimraf','moment','bluebird','util','path','juice','ioredis','../../components/interaction/service','../../components/parsers/qs','../../config/logger','../../config/environment','../../mysqldb','html-entities','redis','defaults','localhost','./mailInteraction.socket','sendStatus','end','status','offset','limit','count','Content-Range','json','update','then','destroy','error','name','send','index','key','getOptions','findAll','mail','query','user','show','params','model','keys','MailInteraction','rawAttributes','filters','intersection','fields','attributes','length','include','merge','options','find','catch','create','body','describe','addMessage','MailMessage','ids','omit','getMessages','hasOwnProperty','nolimit','order','where','pick','map','filter','$gte','split','YYYY-MM-DD\x20HH:mm:ss','includeAll'];(function(_0x232715,_0x4bd63e){var _0x1e6090=function(_0x1baae7){while(--_0x1baae7){_0x232715['push'](_0x232715['shift']());}};_0x1e6090(++_0x4bd63e);}(_0x2acd,0x1be));var _0xd2ac=function(_0x5d6456,_0x58ecc7){_0x5d6456=_0x5d6456-0x0;var _0x4d66c1=_0x2acd[_0x5d6456];return _0x4d66c1;};'use strict';var emlformat=require(_0xd2ac('0x0'));var rimraf=require(_0xd2ac('0x1'));var zipdir=require('zip-dir');var moment=require(_0xd2ac('0x2'));var BPromise=require(_0xd2ac('0x3'));var util=require(_0xd2ac('0x4'));var path=require(_0xd2ac('0x5'));var fs=require('fs');var _=require('lodash');var juice=require(_0xd2ac('0x6'));var Redis=require(_0xd2ac('0x7'));var interaction=require(_0xd2ac('0x8'));var qs=require(_0xd2ac('0x9'));var logger=require(_0xd2ac('0xa'))('api');var config=require(_0xd2ac('0xb'));var db=require(_0xd2ac('0xc'))['db'];var htmlEntities=require(_0xd2ac('0xd'));config[_0xd2ac('0xe')]=_[_0xd2ac('0xf')](config[_0xd2ac('0xe')],{'host':_0xd2ac('0x10'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xd2ac('0xe')]));require(_0xd2ac('0x11'))['register'](socket);function respondWithStatusCode(_0x237c46,_0x35f90b){_0x35f90b=_0x35f90b||0xcc;return function(_0x3da1b9){if(_0x3da1b9){return _0x237c46[_0xd2ac('0x12')](_0x35f90b);}return _0x237c46['status'](_0x35f90b)[_0xd2ac('0x13')]();};}function respondWithResult(_0x5cd61a,_0x4cdfc3){_0x4cdfc3=_0x4cdfc3||0xc8;return function(_0x54f905){if(_0x54f905){return _0x5cd61a[_0xd2ac('0x14')](_0x4cdfc3)['json'](_0x54f905);}};}function respondWithFilteredResult(_0x5dabfc,_0x376e22){return function(_0x1c2507){if(_0x1c2507){var _0x39b988=typeof _0x376e22[_0xd2ac('0x15')]==='undefined'&&typeof _0x376e22[_0xd2ac('0x16')]==='undefined';var _0x26ce1b=_0x1c2507['count'];var _0x4a0ffa=_0x39b988?0x0:_0x376e22[_0xd2ac('0x15')];var _0x9252f1=_0x39b988?_0x1c2507[_0xd2ac('0x17')]:_0x376e22[_0xd2ac('0x15')]+_0x376e22['limit'];var _0x150bd1;if(_0x9252f1>=_0x26ce1b){_0x9252f1=_0x26ce1b;_0x150bd1=0xc8;}else{_0x150bd1=0xce;}_0x5dabfc[_0xd2ac('0x14')](_0x150bd1);return _0x5dabfc['set'](_0xd2ac('0x18'),_0x4a0ffa+'-'+_0x9252f1+'/'+_0x26ce1b)[_0xd2ac('0x19')](_0x1c2507);}return null;};}function saveUpdates(_0x3b4b2b){return function(_0x38ab87){if(_0x38ab87){return _0x38ab87[_0xd2ac('0x1a')](_0x3b4b2b)[_0xd2ac('0x1b')](function(_0xb72c62){return _0xb72c62;});}return null;};}function removeEntity(_0x3670eb){return function(_0x31aead){if(_0x31aead){return _0x31aead[_0xd2ac('0x1c')]()[_0xd2ac('0x1b')](function(){_0x3670eb[_0xd2ac('0x14')](0xcc)['end']();});}};}function handleEntityNotFound(_0x3d99b7){return function(_0x51d7ac){if(!_0x51d7ac){_0x3d99b7[_0xd2ac('0x12')](0x194);}return _0x51d7ac;};}function handleError(_0x5a5fa9,_0x3da4a5){_0x3da4a5=_0x3da4a5||0x1f4;return function(_0x43331f){logger[_0xd2ac('0x1d')](_0x43331f['stack']);if(_0x43331f[_0xd2ac('0x1e')]){delete _0x43331f[_0xd2ac('0x1e')];}_0x5a5fa9['status'](_0x3da4a5)[_0xd2ac('0x1f')](_0x43331f);};}exports[_0xd2ac('0x20')]=function(_0xb61bfc,_0x524a64){var _0x218038={};var _0x2f4afb=_['map'](db['MailInteraction']['rawAttributes'],function(_0x400973){return{'name':_0x400973['fieldName'],'type':_0x400973['type'][_0xd2ac('0x21')]};});_0x218038=qs[_0xd2ac('0x22')](_0x2f4afb,_0xb61bfc);return interaction[_0xd2ac('0x23')](_0xd2ac('0x24'),_0xb61bfc[_0xd2ac('0x25')],_0xb61bfc[_0xd2ac('0x26')],_0x218038,_0x2f4afb)[_0xd2ac('0x1b')](respondWithFilteredResult(_0x524a64,_0x218038))['catch'](handleError(_0x524a64,null));};exports[_0xd2ac('0x27')]=function(_0x4010f4,_0x3a50c8){var _0x21077f={'raw':![],'where':{'id':_0x4010f4[_0xd2ac('0x28')]['id']}},_0x150fe9={};_0x150fe9[_0xd2ac('0x29')]=_[_0xd2ac('0x2a')](db[_0xd2ac('0x2b')][_0xd2ac('0x2c')]);_0x150fe9['query']=_[_0xd2ac('0x2a')](_0x4010f4[_0xd2ac('0x25')]);_0x150fe9[_0xd2ac('0x2d')]=_[_0xd2ac('0x2e')](_0x150fe9[_0xd2ac('0x29')],_0x150fe9[_0xd2ac('0x25')]);_0x21077f['attributes']=_[_0xd2ac('0x2e')](_0x150fe9['model'],qs[_0xd2ac('0x2f')](_0x4010f4[_0xd2ac('0x25')][_0xd2ac('0x2f')]));_0x21077f[_0xd2ac('0x30')]=_0x21077f[_0xd2ac('0x30')][_0xd2ac('0x31')]?_0x21077f[_0xd2ac('0x30')]:_0x150fe9[_0xd2ac('0x29')];if(_0x4010f4[_0xd2ac('0x25')]['includeAll']){_0x21077f[_0xd2ac('0x32')]=[{'all':!![]}];}_0x21077f=_[_0xd2ac('0x33')]({},_0x21077f,_0x4010f4[_0xd2ac('0x34')]);return db[_0xd2ac('0x2b')][_0xd2ac('0x35')](_0x21077f)[_0xd2ac('0x1b')](handleEntityNotFound(_0x3a50c8,null))[_0xd2ac('0x1b')](respondWithResult(_0x3a50c8,null))[_0xd2ac('0x36')](handleError(_0x3a50c8,null));};exports[_0xd2ac('0x37')]=function(_0x1bee85,_0x2dcba6){return db[_0xd2ac('0x2b')]['create'](_0x1bee85[_0xd2ac('0x38')],{})[_0xd2ac('0x1b')](respondWithResult(_0x2dcba6,0xc9))[_0xd2ac('0x36')](handleError(_0x2dcba6,null));};exports[_0xd2ac('0x1a')]=function(_0x468876,_0x10b93a){if(_0x468876[_0xd2ac('0x38')]['id']){delete _0x468876['body']['id'];}return db[_0xd2ac('0x2b')][_0xd2ac('0x35')]({'where':{'id':_0x468876[_0xd2ac('0x28')]['id']}})[_0xd2ac('0x1b')](handleEntityNotFound(_0x10b93a,null))[_0xd2ac('0x1b')](saveUpdates(_0x468876[_0xd2ac('0x38')],null))[_0xd2ac('0x1b')](respondWithResult(_0x10b93a,null))[_0xd2ac('0x36')](handleError(_0x10b93a,null));};exports[_0xd2ac('0x1c')]=function(_0x1bbe74,_0x2a8ffa){return db['MailInteraction']['find']({'where':{'id':_0x1bbe74[_0xd2ac('0x28')]['id']}})['then'](handleEntityNotFound(_0x2a8ffa,null))[_0xd2ac('0x1b')](removeEntity(_0x2a8ffa,null))['catch'](handleError(_0x2a8ffa,null));};exports[_0xd2ac('0x39')]=function(_0x595be5,_0x72bb2c){return db[_0xd2ac('0x2b')]['describe']()[_0xd2ac('0x1b')](respondWithResult(_0x72bb2c,null))[_0xd2ac('0x36')](handleError(_0x72bb2c,null));};exports[_0xd2ac('0x3a')]=function(_0x4d50e6,_0x59814e){return db[_0xd2ac('0x3b')][_0xd2ac('0x35')]({'where':{'id':_0x4d50e6[_0xd2ac('0x28')]['id']}})[_0xd2ac('0x1b')](handleEntityNotFound(_0x59814e,null))[_0xd2ac('0x1b')](function(_0x2f8ea8){if(_0x2f8ea8){return _0x2f8ea8['addMessage'](_0x4d50e6[_0xd2ac('0x38')][_0xd2ac('0x3c')],_[_0xd2ac('0x3d')](_0x4d50e6[_0xd2ac('0x38')],['ids','id'])||{});}})[_0xd2ac('0x1b')](respondWithResult(_0x59814e,null))[_0xd2ac('0x36')](handleError(_0x59814e,null));};exports[_0xd2ac('0x3e')]=function(_0x542b1d,_0x27d6e4){var _0x5a76ec={'raw':![],'where':{}};var _0xf82878={};var _0x4769ae={'count':0x0,'rows':[]};return db[_0xd2ac('0x2b')]['findOne']({'where':{'id':_0x542b1d[_0xd2ac('0x28')]['id']}})[_0xd2ac('0x1b')](handleEntityNotFound(_0x27d6e4,null))[_0xd2ac('0x1b')](function(_0xa7d80a){if(_0xa7d80a){_0xf82878[_0xd2ac('0x29')]=_[_0xd2ac('0x2a')](db[_0xd2ac('0x3b')][_0xd2ac('0x2c')]);_0xf82878['query']=_[_0xd2ac('0x2a')](_0x542b1d[_0xd2ac('0x25')]);_0xf82878['filters']=_['intersection'](_0xf82878['model'],_0xf82878['query']);_0x5a76ec['attributes']=_[_0xd2ac('0x2e')](_0xf82878[_0xd2ac('0x29')],qs[_0xd2ac('0x2f')](_0x542b1d[_0xd2ac('0x25')][_0xd2ac('0x2f')]));_0x5a76ec['attributes']=_0x5a76ec[_0xd2ac('0x30')][_0xd2ac('0x31')]?_0x5a76ec[_0xd2ac('0x30')]:_0xf82878[_0xd2ac('0x29')];if(!_0x542b1d[_0xd2ac('0x25')][_0xd2ac('0x3f')](_0xd2ac('0x40'))){_0x5a76ec[_0xd2ac('0x16')]=qs[_0xd2ac('0x16')](_0x542b1d[_0xd2ac('0x25')]['limit']);_0x5a76ec[_0xd2ac('0x15')]=qs[_0xd2ac('0x15')](_0x542b1d[_0xd2ac('0x25')][_0xd2ac('0x15')]);}_0x5a76ec[_0xd2ac('0x41')]=qs['sort'](_0x542b1d[_0xd2ac('0x25')]['sort']);_0x5a76ec[_0xd2ac('0x42')]=qs[_0xd2ac('0x2d')](_[_0xd2ac('0x43')](_0x542b1d[_0xd2ac('0x25')],_0xf82878['filters']));_0x5a76ec[_0xd2ac('0x42')]['MailInteractionId']=_0xa7d80a['id'];if(_0x542b1d[_0xd2ac('0x25')]['filter']){_0x5a76ec[_0xd2ac('0x42')]=_[_0xd2ac('0x33')](_0x5a76ec['where'],{'$or':_[_0xd2ac('0x44')](_0x5a76ec['attributes'],function(_0x36fc15){var _0x23e9e6={};_0x23e9e6[_0x36fc15]={'$like':'%'+_0x542b1d[_0xd2ac('0x25')][_0xd2ac('0x45')]+'%'};return _0x23e9e6;})});}if(_0x542b1d['query'][_0xd2ac('0x46')]){var _0x4ccaa9=_0x542b1d[_0xd2ac('0x25')][_0xd2ac('0x46')][_0xd2ac('0x47')](',');var _0x3276cb={};_0x3276cb[_0x4ccaa9[0x0]]={'$gte':moment(_0x4ccaa9[0x1])['format'](_0xd2ac('0x48'))};_0x5a76ec[_0xd2ac('0x42')]=_[_0xd2ac('0x33')](_0x5a76ec['where'],_0x3276cb);}_0x5a76ec=_['merge']({},_0x5a76ec,_0x542b1d[_0xd2ac('0x34')]);return db[_0xd2ac('0x3b')][_0xd2ac('0x17')]({'where':_0x5a76ec[_0xd2ac('0x42')]})[_0xd2ac('0x1b')](function(_0x10e743){_0x4769ae['count']=_0x10e743;if(_0x542b1d[_0xd2ac('0x25')][_0xd2ac('0x49')]){_0x5a76ec['include']=[{'all':!![]}];}return db[_0xd2ac('0x3b')]['findAll'](_0x5a76ec);})[_0xd2ac('0x1b')](function(_0x2e1b38){if(_0x542b1d[_0xd2ac('0x25')][_0xd2ac('0x4a')]===_0xd2ac('0x4b')){for(var _0x504e5a=0x0;_0x504e5a<_0x2e1b38[_0xd2ac('0x31')];_0x504e5a++){_0x2e1b38[_0x504e5a][_0xd2ac('0x38')]=juice(_0x2e1b38[_0x504e5a][_0xd2ac('0x38')]);}}_0x4769ae[_0xd2ac('0x4c')]=_0x2e1b38;return _0x4769ae;});}})[_0xd2ac('0x1b')](respondWithFilteredResult(_0x27d6e4,_0x5a76ec))['catch'](handleError(_0x27d6e4,null));};exports[_0xd2ac('0x4d')]=function(_0x564286,_0x14ea05){return db['MailInteraction'][_0xd2ac('0x35')]({'where':{'id':_0x564286['params']['id']}})[_0xd2ac('0x1b')](handleEntityNotFound(_0x14ea05,null))['then'](function(_0x138d7d){if(_0x138d7d){return _0x138d7d[_0xd2ac('0x4e')](_0x564286[_0xd2ac('0x38')][_0xd2ac('0x3c')],_[_0xd2ac('0x3d')](_0x564286['body'],[_0xd2ac('0x3c'),'id'])||{})[_0xd2ac('0x4f')](function(){return db[_0xd2ac('0x50')][_0xd2ac('0x23')]({'attributes':['id',_0xd2ac('0x1e'),_0xd2ac('0x51')],'where':{'id':_0x564286[_0xd2ac('0x38')][_0xd2ac('0x3c')]}});})[_0xd2ac('0x1b')](function(_0x503be5){socket['emit'](_0xd2ac('0x52'),{'id':Number(_0x564286['params']['id']),'tags':_0x503be5||[]});return{'id':Number(_0x564286[_0xd2ac('0x28')]['id']),'tags':_0x503be5||[]};});}})[_0xd2ac('0x1b')](respondWithResult(_0x14ea05,null))['catch'](handleError(_0x14ea05,null));};exports[_0xd2ac('0x53')]=function(_0x35b9d9,_0x5e2c8a){return db['MailInteraction']['find']({'where':{'id':_0x35b9d9['params']['id']}})['then'](handleEntityNotFound(_0x5e2c8a,null))[_0xd2ac('0x1b')](function(_0x12b455){if(_0x12b455){return _0x12b455['removeTags'](_0x35b9d9[_0xd2ac('0x25')][_0xd2ac('0x3c')]);}})[_0xd2ac('0x1b')](respondWithStatusCode(_0x5e2c8a,null))[_0xd2ac('0x36')](handleError(_0x5e2c8a,null));};exports['download']=function(_0xa7b9cc,_0xf0f5b){var _0x4802f6=moment()[_0xd2ac('0x54')]()['toString']();var _0xa75964=path[_0xd2ac('0x55')](config[_0xd2ac('0x56')],_0xd2ac('0x57'),_0xd2ac('0x58'),'tmp');var _0x23385c=path[_0xd2ac('0x55')](config[_0xd2ac('0x56')],_0xd2ac('0x57'),'files','attachments');var _0x2e8319=path['join'](_0xa75964,_0x4802f6);var _0x577950=util['format'](_0xd2ac('0x59'),_0xa7b9cc[_0xd2ac('0x28')]['id'],_0x4802f6);var _0x37e1cd=path[_0xd2ac('0x55')](_0xa75964,_0x577950);var _0x530a2e=[];if(_0xa7b9cc['query'][_0xd2ac('0x5a')]){_0x530a2e[_0xd2ac('0x5b')]({'model':db['Attachment'],'as':_0xd2ac('0x5c'),'raw':!![]});}var _0x4c1eae=[{'model':db[_0xd2ac('0x3b')],'as':'Messages','attributes':['id',_0xd2ac('0x38'),'from','to','cc',_0xd2ac('0x5d'),_0xd2ac('0x5e'),_0xd2ac('0x5f')],'where':{'secret':![]},'order':qs[_0xd2ac('0x60')]('id'),'include':_0x530a2e}];return db['MailInteraction']['find']({'where':{'id':_0xa7b9cc['params']['id']},'include':_0x4c1eae})['then'](handleEntityNotFound(_0xf0f5b,null))[_0xd2ac('0x1b')](function(_0x1f479b){if(_0x1f479b&&_0x1f479b[_0xd2ac('0x61')]){var _0x26bed0=_0x1f479b['get']({'plain':!![]});fs['mkdirSync'](_0x2e8319);return BPromise['each'](_0x26bed0['Messages'],function(_0x45e7a0,_0x83d274){var _0x43bd6b={'from':_0x45e7a0['from'],'to':_0x45e7a0['to']||_0xd2ac('0x62'),'subject':_0x45e7a0['subject'],'html':htmlEntities[_0xd2ac('0x63')](_0x45e7a0[_0xd2ac('0x38')]),'headers':{'Date':moment(_0x45e7a0['createdAt'])['format']('ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ')},'attachments':[]};if(_0x45e7a0['cc']){_0x43bd6b['headers']['Cc']=_0x45e7a0['cc'];}if(_0x45e7a0[_0xd2ac('0x5d')]){_0x43bd6b['headers'][_0xd2ac('0x64')]=_0x45e7a0[_0xd2ac('0x5d')];}return new BPromise(function(_0x28bc1b,_0x2b5bab){if(_0x45e7a0[_0xd2ac('0x5c')]){for(var _0x382f8f=0x0;_0x382f8f<_0x45e7a0['Attachments'][_0xd2ac('0x31')];_0x382f8f++){var _0x22446d=_0x45e7a0[_0xd2ac('0x5c')][_0x382f8f];var _0x1cc94a=path[_0xd2ac('0x55')](_0x23385c,_0x22446d['basename']);if(fs['existsSync'](_0x1cc94a)){_0x43bd6b['attachments'][_0xd2ac('0x5b')]({'name':_0x22446d[_0xd2ac('0x1e')],'contentType':_0x22446d['type'],'data':fs[_0xd2ac('0x65')](_0x1cc94a)});}}}emlformat[_0xd2ac('0x66')](_0x43bd6b,function(_0x28d5d1,_0x4c7ff9){if(_0x28d5d1)return _0x2b5bab(_0x28d5d1);fs['writeFileSync'](path[_0xd2ac('0x55')](_0x2e8319,util['format'](_0xd2ac('0x67'),_0x83d274)),_0x4c7ff9);return _0x28bc1b(_0x4c7ff9);});});})['then'](function(){return new BPromise(function(_0x307444,_0x3f197d){zipdir(_0x2e8319,{'saveTo':_0x37e1cd},function(_0x413a25,_0x11a29e){if(_0x413a25)return _0x3f197d(_0x413a25);return _0x307444(_0x11a29e);});})[_0xd2ac('0x1b')](function(){return new BPromise(function(_0xc71801,_0x3382aa){rimraf(_0x2e8319,function(_0x5c7723){if(_0x5c7723)_0x3382aa(_0x5c7723);return _0xc71801();});});})[_0xd2ac('0x1b')](function(){return _0xf0f5b['download'](_0x37e1cd,_0x577950,function(_0x16890c){if(!_0x16890c)fs['unlinkSync'](_0x37e1cd);});});});}else{return _0xf0f5b['sendStatus'](0xc8);}})[_0xd2ac('0x36')](handleError(_0xf0f5b,null));};
\ No newline at end of file