Built motion from commit b0a9a629.|2.6.33
[motion2.git] / server / api / mailInteraction / mailInteraction.controller.js
index b142394..d048cae 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xbf08=['download','toString','join','root','tmp','server','files','attachments','transcript-%d-%s.zip','push','Attachment','Attachments','Messages','from','bcc','subject','get','mkdirSync','missing.recipient@your.company.com','createdAt','headers','Bcc','basename','existsSync','readFileSync','writeFileSync','message%d.eml','unlinkSync','eml-format','rimraf','zip-dir','moment','util','path','juice','ioredis','../../components/parsers/qs','../../config/logger','api','../../mysqldb','html-entities','defaults','redis','localhost','socket.io-emitter','./mailInteraction.socket','register','sendStatus','end','status','json','offset','undefined','limit','set','Content-Range','update','destroy','then','error','stack','name','send','MailInteraction','type','key','findAll','mail','query','user','params','model','keys','filters','attributes','intersection','fields','length','includeAll','include','merge','options','catch','create','body','find','describe','addMessage','MailMessage','omit','ids','getMessages','rawAttributes','hasOwnProperty','nolimit','order','sort','where','pick','MailInteractionId','map','filter','$gte','format','YYYY-MM-DD\x20HH:mm:ss','count','inlineCss','rows','addTags','setTags','spread','Tag','color','emit','mailInteractionTags:save','removeTags'];(function(_0x158fdc,_0x1c4d6f){var _0x3bc018=function(_0x4bf523){while(--_0x4bf523){_0x158fdc['push'](_0x158fdc['shift']());}};_0x3bc018(++_0x1c4d6f);}(_0xbf08,0x104));var _0x8bf0=function(_0x4a33b3,_0x30cae4){_0x4a33b3=_0x4a33b3-0x0;var _0x12f200=_0xbf08[_0x4a33b3];return _0x12f200;};'use strict';var emlformat=require(_0x8bf0('0x0'));var rimraf=require(_0x8bf0('0x1'));var zipdir=require(_0x8bf0('0x2'));var moment=require(_0x8bf0('0x3'));var BPromise=require('bluebird');var util=require(_0x8bf0('0x4'));var path=require(_0x8bf0('0x5'));var fs=require('fs');var _=require('lodash');var juice=require(_0x8bf0('0x6'));var Redis=require(_0x8bf0('0x7'));var interaction=require('../../components/interaction/service');var qs=require(_0x8bf0('0x8'));var logger=require(_0x8bf0('0x9'))(_0x8bf0('0xa'));var config=require('../../config/environment');var db=require(_0x8bf0('0xb'))['db'];var htmlEntities=require(_0x8bf0('0xc'));config['redis']=_[_0x8bf0('0xd')](config[_0x8bf0('0xe')],{'host':_0x8bf0('0xf'),'port':0x18eb});var socket=require(_0x8bf0('0x10'))(new Redis(config['redis']));require(_0x8bf0('0x11'))[_0x8bf0('0x12')](socket);function respondWithStatusCode(_0x9dc9a6,_0x46b0d3){_0x46b0d3=_0x46b0d3||0xcc;return function(_0x59b495){if(_0x59b495){return _0x9dc9a6[_0x8bf0('0x13')](_0x46b0d3);}return _0x9dc9a6['status'](_0x46b0d3)[_0x8bf0('0x14')]();};}function respondWithResult(_0x4f9bf8,_0x4ab514){_0x4ab514=_0x4ab514||0xc8;return function(_0x5388b9){if(_0x5388b9){return _0x4f9bf8[_0x8bf0('0x15')](_0x4ab514)[_0x8bf0('0x16')](_0x5388b9);}};}function respondWithFilteredResult(_0x56e77f,_0x4f3b9e){return function(_0x10e348){if(_0x10e348){var _0x2aea7a=typeof _0x4f3b9e[_0x8bf0('0x17')]===_0x8bf0('0x18')&&typeof _0x4f3b9e[_0x8bf0('0x19')]==='undefined';var _0x52ee7c=_0x10e348['count'];var _0x18db94=_0x2aea7a?0x0:_0x4f3b9e[_0x8bf0('0x17')];var _0xbe4b18=_0x2aea7a?_0x10e348['count']:_0x4f3b9e[_0x8bf0('0x17')]+_0x4f3b9e[_0x8bf0('0x19')];var _0x3e7cf9;if(_0xbe4b18>=_0x52ee7c){_0xbe4b18=_0x52ee7c;_0x3e7cf9=0xc8;}else{_0x3e7cf9=0xce;}_0x56e77f[_0x8bf0('0x15')](_0x3e7cf9);return _0x56e77f[_0x8bf0('0x1a')](_0x8bf0('0x1b'),_0x18db94+'-'+_0xbe4b18+'/'+_0x52ee7c)[_0x8bf0('0x16')](_0x10e348);}return null;};}function saveUpdates(_0x5504ed){return function(_0x49f164){if(_0x49f164){return _0x49f164[_0x8bf0('0x1c')](_0x5504ed)['then'](function(_0x38d30d){return _0x38d30d;});}return null;};}function removeEntity(_0xeb9372){return function(_0x29e7d2){if(_0x29e7d2){return _0x29e7d2[_0x8bf0('0x1d')]()[_0x8bf0('0x1e')](function(){_0xeb9372[_0x8bf0('0x15')](0xcc)['end']();});}};}function handleEntityNotFound(_0x487f99){return function(_0x4922d3){if(!_0x4922d3){_0x487f99[_0x8bf0('0x13')](0x194);}return _0x4922d3;};}function handleError(_0x2a68f2,_0xf63b44){_0xf63b44=_0xf63b44||0x1f4;return function(_0x157d06){logger[_0x8bf0('0x1f')](_0x157d06[_0x8bf0('0x20')]);if(_0x157d06[_0x8bf0('0x21')]){delete _0x157d06[_0x8bf0('0x21')];}_0x2a68f2[_0x8bf0('0x15')](_0xf63b44)[_0x8bf0('0x22')](_0x157d06);};}exports['index']=function(_0x52f3db,_0x431208){var _0x293007={};var _0x58a108=_['map'](db[_0x8bf0('0x23')]['rawAttributes'],function(_0x5df33c){return{'name':_0x5df33c['fieldName'],'type':_0x5df33c[_0x8bf0('0x24')][_0x8bf0('0x25')]};});_0x293007=qs['getOptions'](_0x58a108,_0x52f3db);return interaction[_0x8bf0('0x26')](_0x8bf0('0x27'),_0x52f3db[_0x8bf0('0x28')],_0x52f3db[_0x8bf0('0x29')],_0x293007,_0x58a108)['then'](respondWithFilteredResult(_0x431208,_0x293007))['catch'](handleError(_0x431208,null));};exports['show']=function(_0x34cec3,_0x2a827f){var _0xdde70e={'raw':![],'where':{'id':_0x34cec3[_0x8bf0('0x2a')]['id']}},_0x3cf063={};_0x3cf063[_0x8bf0('0x2b')]=_[_0x8bf0('0x2c')](db['MailInteraction']['rawAttributes']);_0x3cf063[_0x8bf0('0x28')]=_[_0x8bf0('0x2c')](_0x34cec3['query']);_0x3cf063[_0x8bf0('0x2d')]=_['intersection'](_0x3cf063[_0x8bf0('0x2b')],_0x3cf063[_0x8bf0('0x28')]);_0xdde70e[_0x8bf0('0x2e')]=_[_0x8bf0('0x2f')](_0x3cf063[_0x8bf0('0x2b')],qs['fields'](_0x34cec3[_0x8bf0('0x28')][_0x8bf0('0x30')]));_0xdde70e[_0x8bf0('0x2e')]=_0xdde70e[_0x8bf0('0x2e')][_0x8bf0('0x31')]?_0xdde70e['attributes']:_0x3cf063[_0x8bf0('0x2b')];if(_0x34cec3[_0x8bf0('0x28')][_0x8bf0('0x32')]){_0xdde70e[_0x8bf0('0x33')]=[{'all':!![]}];}_0xdde70e=_[_0x8bf0('0x34')]({},_0xdde70e,_0x34cec3[_0x8bf0('0x35')]);return db[_0x8bf0('0x23')]['find'](_0xdde70e)[_0x8bf0('0x1e')](handleEntityNotFound(_0x2a827f,null))[_0x8bf0('0x1e')](respondWithResult(_0x2a827f,null))[_0x8bf0('0x36')](handleError(_0x2a827f,null));};exports[_0x8bf0('0x37')]=function(_0x19a370,_0x14d3f0){return db[_0x8bf0('0x23')][_0x8bf0('0x37')](_0x19a370[_0x8bf0('0x38')],{})[_0x8bf0('0x1e')](respondWithResult(_0x14d3f0,0xc9))[_0x8bf0('0x36')](handleError(_0x14d3f0,null));};exports[_0x8bf0('0x1c')]=function(_0x560306,_0x2d19e6){if(_0x560306[_0x8bf0('0x38')]['id']){delete _0x560306[_0x8bf0('0x38')]['id'];}return db[_0x8bf0('0x23')][_0x8bf0('0x39')]({'where':{'id':_0x560306[_0x8bf0('0x2a')]['id']}})[_0x8bf0('0x1e')](handleEntityNotFound(_0x2d19e6,null))['then'](saveUpdates(_0x560306[_0x8bf0('0x38')],null))[_0x8bf0('0x1e')](respondWithResult(_0x2d19e6,null))[_0x8bf0('0x36')](handleError(_0x2d19e6,null));};exports['destroy']=function(_0x1f1a2d,_0x178584){return db[_0x8bf0('0x23')][_0x8bf0('0x39')]({'where':{'id':_0x1f1a2d['params']['id']}})[_0x8bf0('0x1e')](handleEntityNotFound(_0x178584,null))[_0x8bf0('0x1e')](removeEntity(_0x178584,null))[_0x8bf0('0x36')](handleError(_0x178584,null));};exports[_0x8bf0('0x3a')]=function(_0x917607,_0x5a9548){return db[_0x8bf0('0x23')][_0x8bf0('0x3a')]()[_0x8bf0('0x1e')](respondWithResult(_0x5a9548,null))[_0x8bf0('0x36')](handleError(_0x5a9548,null));};exports[_0x8bf0('0x3b')]=function(_0x11a14a,_0x2ef0e1){return db[_0x8bf0('0x3c')][_0x8bf0('0x39')]({'where':{'id':_0x11a14a['params']['id']}})[_0x8bf0('0x1e')](handleEntityNotFound(_0x2ef0e1,null))[_0x8bf0('0x1e')](function(_0x27cfef){if(_0x27cfef){return _0x27cfef[_0x8bf0('0x3b')](_0x11a14a[_0x8bf0('0x38')]['ids'],_[_0x8bf0('0x3d')](_0x11a14a[_0x8bf0('0x38')],[_0x8bf0('0x3e'),'id'])||{});}})[_0x8bf0('0x1e')](respondWithResult(_0x2ef0e1,null))[_0x8bf0('0x36')](handleError(_0x2ef0e1,null));};exports[_0x8bf0('0x3f')]=function(_0x4c65c8,_0x1e8454){var _0x219f0f={'raw':![],'where':{}};var _0x19cb37={};var _0x14e182={'count':0x0,'rows':[]};return db[_0x8bf0('0x23')]['findOne']({'where':{'id':_0x4c65c8[_0x8bf0('0x2a')]['id']}})[_0x8bf0('0x1e')](handleEntityNotFound(_0x1e8454,null))['then'](function(_0x48ba68){if(_0x48ba68){_0x19cb37[_0x8bf0('0x2b')]=_['keys'](db[_0x8bf0('0x3c')][_0x8bf0('0x40')]);_0x19cb37[_0x8bf0('0x28')]=_[_0x8bf0('0x2c')](_0x4c65c8['query']);_0x19cb37[_0x8bf0('0x2d')]=_[_0x8bf0('0x2f')](_0x19cb37[_0x8bf0('0x2b')],_0x19cb37[_0x8bf0('0x28')]);_0x219f0f[_0x8bf0('0x2e')]=_[_0x8bf0('0x2f')](_0x19cb37[_0x8bf0('0x2b')],qs[_0x8bf0('0x30')](_0x4c65c8[_0x8bf0('0x28')][_0x8bf0('0x30')]));_0x219f0f[_0x8bf0('0x2e')]=_0x219f0f[_0x8bf0('0x2e')][_0x8bf0('0x31')]?_0x219f0f[_0x8bf0('0x2e')]:_0x19cb37[_0x8bf0('0x2b')];if(!_0x4c65c8['query'][_0x8bf0('0x41')](_0x8bf0('0x42'))){_0x219f0f['limit']=qs['limit'](_0x4c65c8['query'][_0x8bf0('0x19')]);_0x219f0f[_0x8bf0('0x17')]=qs[_0x8bf0('0x17')](_0x4c65c8[_0x8bf0('0x28')]['offset']);}_0x219f0f[_0x8bf0('0x43')]=qs[_0x8bf0('0x44')](_0x4c65c8['query']['sort']);_0x219f0f[_0x8bf0('0x45')]=qs[_0x8bf0('0x2d')](_[_0x8bf0('0x46')](_0x4c65c8[_0x8bf0('0x28')],_0x19cb37[_0x8bf0('0x2d')]));_0x219f0f['where'][_0x8bf0('0x47')]=_0x48ba68['id'];if(_0x4c65c8[_0x8bf0('0x28')]['filter']){_0x219f0f[_0x8bf0('0x45')]=_[_0x8bf0('0x34')](_0x219f0f[_0x8bf0('0x45')],{'$or':_[_0x8bf0('0x48')](_0x219f0f['attributes'],function(_0x2e5d69){var _0x2bab29={};_0x2bab29[_0x2e5d69]={'$like':'%'+_0x4c65c8[_0x8bf0('0x28')][_0x8bf0('0x49')]+'%'};return _0x2bab29;})});}if(_0x4c65c8[_0x8bf0('0x28')]['$gte']){var _0x1afb69=_0x4c65c8['query'][_0x8bf0('0x4a')]['split'](',');var _0x3fc89c={};_0x3fc89c[_0x1afb69[0x0]]={'$gte':moment(_0x1afb69[0x1])[_0x8bf0('0x4b')](_0x8bf0('0x4c'))};_0x219f0f['where']=_['merge'](_0x219f0f['where'],_0x3fc89c);}_0x219f0f=_[_0x8bf0('0x34')]({},_0x219f0f,_0x4c65c8[_0x8bf0('0x35')]);return db[_0x8bf0('0x3c')][_0x8bf0('0x4d')]({'where':_0x219f0f[_0x8bf0('0x45')]})[_0x8bf0('0x1e')](function(_0x5037b4){_0x14e182['count']=_0x5037b4;if(_0x4c65c8['query'][_0x8bf0('0x32')]){_0x219f0f[_0x8bf0('0x33')]=[{'all':!![]}];}return db[_0x8bf0('0x3c')][_0x8bf0('0x26')](_0x219f0f);})[_0x8bf0('0x1e')](function(_0x4598e3){if(_0x4c65c8['query'][_0x8bf0('0x4e')]==='true'){for(var _0x27942c=0x0;_0x27942c<_0x4598e3[_0x8bf0('0x31')];_0x27942c++){_0x4598e3[_0x27942c][_0x8bf0('0x38')]=juice(_0x4598e3[_0x27942c][_0x8bf0('0x38')]);}}_0x14e182[_0x8bf0('0x4f')]=_0x4598e3;return _0x14e182;});}})[_0x8bf0('0x1e')](respondWithFilteredResult(_0x1e8454,_0x219f0f))[_0x8bf0('0x36')](handleError(_0x1e8454,null));};exports[_0x8bf0('0x50')]=function(_0x1e823a,_0x2c8b3e){return db[_0x8bf0('0x23')][_0x8bf0('0x39')]({'where':{'id':_0x1e823a[_0x8bf0('0x2a')]['id']}})[_0x8bf0('0x1e')](handleEntityNotFound(_0x2c8b3e,null))[_0x8bf0('0x1e')](function(_0x41d7da){if(_0x41d7da){return _0x41d7da[_0x8bf0('0x51')](_0x1e823a['body']['ids'],_[_0x8bf0('0x3d')](_0x1e823a[_0x8bf0('0x38')],[_0x8bf0('0x3e'),'id'])||{})[_0x8bf0('0x52')](function(){return db[_0x8bf0('0x53')][_0x8bf0('0x26')]({'attributes':['id',_0x8bf0('0x21'),_0x8bf0('0x54')],'where':{'id':_0x1e823a[_0x8bf0('0x38')][_0x8bf0('0x3e')]}});})[_0x8bf0('0x1e')](function(_0x178c09){socket[_0x8bf0('0x55')](_0x8bf0('0x56'),{'id':Number(_0x1e823a['params']['id']),'tags':_0x178c09||[]});return{'id':Number(_0x1e823a['params']['id']),'tags':_0x178c09||[]};});}})['then'](respondWithResult(_0x2c8b3e,null))[_0x8bf0('0x36')](handleError(_0x2c8b3e,null));};exports[_0x8bf0('0x57')]=function(_0x238e9b,_0x1012ea){return db['MailInteraction']['find']({'where':{'id':_0x238e9b[_0x8bf0('0x2a')]['id']}})[_0x8bf0('0x1e')](handleEntityNotFound(_0x1012ea,null))[_0x8bf0('0x1e')](function(_0x5b20c9){if(_0x5b20c9){return _0x5b20c9['removeTags'](_0x238e9b[_0x8bf0('0x28')]['ids']);}})[_0x8bf0('0x1e')](respondWithStatusCode(_0x1012ea,null))[_0x8bf0('0x36')](handleError(_0x1012ea,null));};exports[_0x8bf0('0x58')]=function(_0x268b5b,_0x4619c9){var _0x40be9b=moment()['unix']()[_0x8bf0('0x59')]();var _0xa5b2b5=path[_0x8bf0('0x5a')](config[_0x8bf0('0x5b')],'server','files',_0x8bf0('0x5c'));var _0x4f15b7=path[_0x8bf0('0x5a')](config[_0x8bf0('0x5b')],_0x8bf0('0x5d'),_0x8bf0('0x5e'),_0x8bf0('0x5f'));var _0x1c068a=path['join'](_0xa5b2b5,_0x40be9b);var _0x17719f=util[_0x8bf0('0x4b')](_0x8bf0('0x60'),_0x268b5b[_0x8bf0('0x2a')]['id'],_0x40be9b);var _0x8b7bfa=path[_0x8bf0('0x5a')](_0xa5b2b5,_0x17719f);var _0x1fecf9=[];if(_0x268b5b['query'][_0x8bf0('0x5f')]){_0x1fecf9[_0x8bf0('0x61')]({'model':db[_0x8bf0('0x62')],'as':_0x8bf0('0x63'),'raw':!![]});}var _0x1750a9=[{'model':db[_0x8bf0('0x3c')],'as':_0x8bf0('0x64'),'attributes':['id','body',_0x8bf0('0x65'),'to','cc',_0x8bf0('0x66'),_0x8bf0('0x67'),'createdAt'],'where':{'secret':![]},'order':qs[_0x8bf0('0x44')]('id'),'include':_0x1fecf9}];return db[_0x8bf0('0x23')][_0x8bf0('0x39')]({'where':{'id':_0x268b5b[_0x8bf0('0x2a')]['id']},'include':_0x1750a9})[_0x8bf0('0x1e')](handleEntityNotFound(_0x4619c9,null))['then'](function(_0x3947f9){if(_0x3947f9&&_0x3947f9[_0x8bf0('0x64')]){var _0x272394=_0x3947f9[_0x8bf0('0x68')]({'plain':!![]});fs[_0x8bf0('0x69')](_0x1c068a);return BPromise['each'](_0x272394[_0x8bf0('0x64')],function(_0xb07bfe,_0x33af16){var _0x74a2dd={'from':_0xb07bfe[_0x8bf0('0x65')],'to':_0xb07bfe['to']||_0x8bf0('0x6a'),'subject':_0xb07bfe[_0x8bf0('0x67')],'html':htmlEntities['decode'](_0xb07bfe[_0x8bf0('0x38')]),'headers':{'Date':moment(_0xb07bfe[_0x8bf0('0x6b')])[_0x8bf0('0x4b')]('ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ')},'attachments':[]};if(_0xb07bfe['cc']){_0x74a2dd[_0x8bf0('0x6c')]['Cc']=_0xb07bfe['cc'];}if(_0xb07bfe[_0x8bf0('0x66')]){_0x74a2dd[_0x8bf0('0x6c')][_0x8bf0('0x6d')]=_0xb07bfe[_0x8bf0('0x66')];}return new BPromise(function(_0x515734,_0x60c48b){if(_0xb07bfe[_0x8bf0('0x63')]){for(var _0x4209b3=0x0;_0x4209b3<_0xb07bfe[_0x8bf0('0x63')][_0x8bf0('0x31')];_0x4209b3++){var _0x3b1873=_0xb07bfe['Attachments'][_0x4209b3];var _0x175ba6=path[_0x8bf0('0x5a')](_0x4f15b7,_0x3b1873[_0x8bf0('0x6e')]);if(fs[_0x8bf0('0x6f')](_0x175ba6)){_0x74a2dd['attachments']['push']({'name':_0x3b1873[_0x8bf0('0x21')],'contentType':_0x3b1873[_0x8bf0('0x24')],'data':fs[_0x8bf0('0x70')](_0x175ba6)});}}}emlformat['build'](_0x74a2dd,function(_0x2cc184,_0x3a014a){if(_0x2cc184)return _0x60c48b(_0x2cc184);fs[_0x8bf0('0x71')](path['join'](_0x1c068a,util[_0x8bf0('0x4b')](_0x8bf0('0x72'),_0x33af16)),_0x3a014a);return _0x515734(_0x3a014a);});});})[_0x8bf0('0x1e')](function(){return new BPromise(function(_0x25d619,_0x50d475){zipdir(_0x1c068a,{'saveTo':_0x8b7bfa},function(_0x17be3d,_0x3595d9){if(_0x17be3d)return _0x50d475(_0x17be3d);return _0x25d619(_0x3595d9);});})[_0x8bf0('0x1e')](function(){return new BPromise(function(_0x5afd2b,_0x87bff6){rimraf(_0x1c068a,function(_0x9f2edd){if(_0x9f2edd)_0x87bff6(_0x9f2edd);return _0x5afd2b();});});})[_0x8bf0('0x1e')](function(){return _0x4619c9[_0x8bf0('0x58')](_0x8b7bfa,_0x17719f,function(_0x5cb500){if(!_0x5cb500)fs[_0x8bf0('0x73')](_0x8b7bfa);});});});}else{return _0x4619c9[_0x8bf0('0x13')](0xc8);}})[_0x8bf0('0x36')](handleError(_0x4619c9,null));};
\ No newline at end of file
+var _0xa3d6=['true','rows','addTags','omit','color','emit','mailInteractionTags:save','unix','toString','join','server','files','root','attachments','transcript-%d-%s.zip','push','Attachment','Attachments','Messages','from','subject','get','missing.recipient@your.company.com','decode','createdAt','ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ','headers','bcc','basename','existsSync','build','writeFileSync','message%d.eml','download','unlinkSync','eml-format','rimraf','zip-dir','moment','bluebird','util','path','lodash','juice','ioredis','../../components/parsers/qs','../../config/logger','api','../../config/environment','html-entities','redis','defaults','localhost','./mailInteraction.socket','sendStatus','status','json','offset','undefined','count','limit','set','update','then','end','stack','name','send','index','map','MailInteraction','rawAttributes','fieldName','type','key','findAll','mail','query','user','catch','show','model','keys','filters','intersection','attributes','fields','length','merge','options','find','body','params','destroy','describe','addMessage','MailMessage','ids','findOne','hasOwnProperty','nolimit','order','sort','where','filter','$gte','split','format','includeAll','include','inlineCss'];(function(_0x2d7e66,_0x44633c){var _0x58b07c=function(_0x28d399){while(--_0x28d399){_0x2d7e66['push'](_0x2d7e66['shift']());}};_0x58b07c(++_0x44633c);}(_0xa3d6,0x92));var _0x6a3d=function(_0x4f9e17,_0x4cf03f){_0x4f9e17=_0x4f9e17-0x0;var _0x4e7af7=_0xa3d6[_0x4f9e17];return _0x4e7af7;};'use strict';var emlformat=require(_0x6a3d('0x0'));var rimraf=require(_0x6a3d('0x1'));var zipdir=require(_0x6a3d('0x2'));var moment=require(_0x6a3d('0x3'));var BPromise=require(_0x6a3d('0x4'));var util=require(_0x6a3d('0x5'));var path=require(_0x6a3d('0x6'));var fs=require('fs');var _=require(_0x6a3d('0x7'));var juice=require(_0x6a3d('0x8'));var Redis=require(_0x6a3d('0x9'));var interaction=require('../../components/interaction/service');var qs=require(_0x6a3d('0xa'));var logger=require(_0x6a3d('0xb'))(_0x6a3d('0xc'));var config=require(_0x6a3d('0xd'));var db=require('../../mysqldb')['db'];var htmlEntities=require(_0x6a3d('0xe'));config[_0x6a3d('0xf')]=_[_0x6a3d('0x10')](config[_0x6a3d('0xf')],{'host':_0x6a3d('0x11'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x6a3d('0xf')]));require(_0x6a3d('0x12'))['register'](socket);function respondWithStatusCode(_0x1a03bf,_0x18651d){_0x18651d=_0x18651d||0xcc;return function(_0x23faf5){if(_0x23faf5){return _0x1a03bf[_0x6a3d('0x13')](_0x18651d);}return _0x1a03bf['status'](_0x18651d)['end']();};}function respondWithResult(_0x59cb2c,_0x26b847){_0x26b847=_0x26b847||0xc8;return function(_0x12b98d){if(_0x12b98d){return _0x59cb2c[_0x6a3d('0x14')](_0x26b847)[_0x6a3d('0x15')](_0x12b98d);}};}function respondWithFilteredResult(_0x238ed3,_0x4346c9){return function(_0x11765c){if(_0x11765c){var _0x433e52=typeof _0x4346c9[_0x6a3d('0x16')]===_0x6a3d('0x17')&&typeof _0x4346c9['limit']===_0x6a3d('0x17');var _0x56f719=_0x11765c[_0x6a3d('0x18')];var _0x5b6a11=_0x433e52?0x0:_0x4346c9[_0x6a3d('0x16')];var _0x4b46e3=_0x433e52?_0x11765c['count']:_0x4346c9[_0x6a3d('0x16')]+_0x4346c9[_0x6a3d('0x19')];var _0x23edc5;if(_0x4b46e3>=_0x56f719){_0x4b46e3=_0x56f719;_0x23edc5=0xc8;}else{_0x23edc5=0xce;}_0x238ed3[_0x6a3d('0x14')](_0x23edc5);return _0x238ed3[_0x6a3d('0x1a')]('Content-Range',_0x5b6a11+'-'+_0x4b46e3+'/'+_0x56f719)[_0x6a3d('0x15')](_0x11765c);}return null;};}function saveUpdates(_0x26b5a0){return function(_0x58b737){if(_0x58b737){return _0x58b737[_0x6a3d('0x1b')](_0x26b5a0)[_0x6a3d('0x1c')](function(_0x1a50d5){return _0x1a50d5;});}return null;};}function removeEntity(_0x4821a2){return function(_0x47ce01){if(_0x47ce01){return _0x47ce01['destroy']()['then'](function(){_0x4821a2[_0x6a3d('0x14')](0xcc)[_0x6a3d('0x1d')]();});}};}function handleEntityNotFound(_0x5b1089){return function(_0xb9d97b){if(!_0xb9d97b){_0x5b1089[_0x6a3d('0x13')](0x194);}return _0xb9d97b;};}function handleError(_0x52bf2a,_0x261b96){_0x261b96=_0x261b96||0x1f4;return function(_0x365505){logger['error'](_0x365505[_0x6a3d('0x1e')]);if(_0x365505[_0x6a3d('0x1f')]){delete _0x365505[_0x6a3d('0x1f')];}_0x52bf2a['status'](_0x261b96)[_0x6a3d('0x20')](_0x365505);};}exports[_0x6a3d('0x21')]=function(_0xc5518f,_0x35e8d7){var _0x4b32cf={};var _0x4966dc=_[_0x6a3d('0x22')](db[_0x6a3d('0x23')][_0x6a3d('0x24')],function(_0x288b04){return{'name':_0x288b04[_0x6a3d('0x25')],'type':_0x288b04[_0x6a3d('0x26')][_0x6a3d('0x27')]};});_0x4b32cf=qs['getOptions'](_0x4966dc,_0xc5518f);return interaction[_0x6a3d('0x28')](_0x6a3d('0x29'),_0xc5518f[_0x6a3d('0x2a')],_0xc5518f[_0x6a3d('0x2b')],_0x4b32cf,_0x4966dc)[_0x6a3d('0x1c')](respondWithFilteredResult(_0x35e8d7,_0x4b32cf))[_0x6a3d('0x2c')](handleError(_0x35e8d7,null));};exports[_0x6a3d('0x2d')]=function(_0x3beff0,_0x45eda4){var _0x58ce8c={'raw':![],'where':{'id':_0x3beff0['params']['id']}},_0x5be19a={};_0x5be19a[_0x6a3d('0x2e')]=_[_0x6a3d('0x2f')](db[_0x6a3d('0x23')]['rawAttributes']);_0x5be19a[_0x6a3d('0x2a')]=_[_0x6a3d('0x2f')](_0x3beff0[_0x6a3d('0x2a')]);_0x5be19a[_0x6a3d('0x30')]=_[_0x6a3d('0x31')](_0x5be19a['model'],_0x5be19a['query']);_0x58ce8c[_0x6a3d('0x32')]=_[_0x6a3d('0x31')](_0x5be19a[_0x6a3d('0x2e')],qs['fields'](_0x3beff0[_0x6a3d('0x2a')][_0x6a3d('0x33')]));_0x58ce8c[_0x6a3d('0x32')]=_0x58ce8c['attributes'][_0x6a3d('0x34')]?_0x58ce8c[_0x6a3d('0x32')]:_0x5be19a[_0x6a3d('0x2e')];if(_0x3beff0[_0x6a3d('0x2a')]['includeAll']){_0x58ce8c['include']=[{'all':!![]}];}_0x58ce8c=_[_0x6a3d('0x35')]({},_0x58ce8c,_0x3beff0[_0x6a3d('0x36')]);return db[_0x6a3d('0x23')][_0x6a3d('0x37')](_0x58ce8c)[_0x6a3d('0x1c')](handleEntityNotFound(_0x45eda4,null))[_0x6a3d('0x1c')](respondWithResult(_0x45eda4,null))['catch'](handleError(_0x45eda4,null));};exports['create']=function(_0x37d8ef,_0x5d4a5e){return db[_0x6a3d('0x23')]['create'](_0x37d8ef['body'],{})[_0x6a3d('0x1c')](respondWithResult(_0x5d4a5e,0xc9))[_0x6a3d('0x2c')](handleError(_0x5d4a5e,null));};exports[_0x6a3d('0x1b')]=function(_0x44b080,_0x101031){if(_0x44b080[_0x6a3d('0x38')]['id']){delete _0x44b080[_0x6a3d('0x38')]['id'];}return db['MailInteraction']['find']({'where':{'id':_0x44b080[_0x6a3d('0x39')]['id']}})[_0x6a3d('0x1c')](handleEntityNotFound(_0x101031,null))[_0x6a3d('0x1c')](saveUpdates(_0x44b080[_0x6a3d('0x38')],null))[_0x6a3d('0x1c')](respondWithResult(_0x101031,null))[_0x6a3d('0x2c')](handleError(_0x101031,null));};exports[_0x6a3d('0x3a')]=function(_0x2c87d3,_0x3fe14d){return db[_0x6a3d('0x23')][_0x6a3d('0x37')]({'where':{'id':_0x2c87d3[_0x6a3d('0x39')]['id']}})['then'](handleEntityNotFound(_0x3fe14d,null))[_0x6a3d('0x1c')](removeEntity(_0x3fe14d,null))[_0x6a3d('0x2c')](handleError(_0x3fe14d,null));};exports['describe']=function(_0x50480b,_0x497943){return db[_0x6a3d('0x23')][_0x6a3d('0x3b')]()['then'](respondWithResult(_0x497943,null))[_0x6a3d('0x2c')](handleError(_0x497943,null));};exports[_0x6a3d('0x3c')]=function(_0x56e930,_0xb176b1){return db[_0x6a3d('0x3d')][_0x6a3d('0x37')]({'where':{'id':_0x56e930['params']['id']}})[_0x6a3d('0x1c')](handleEntityNotFound(_0xb176b1,null))[_0x6a3d('0x1c')](function(_0x3e5ae8){if(_0x3e5ae8){return _0x3e5ae8['addMessage'](_0x56e930[_0x6a3d('0x38')][_0x6a3d('0x3e')],_['omit'](_0x56e930[_0x6a3d('0x38')],[_0x6a3d('0x3e'),'id'])||{});}})['then'](respondWithResult(_0xb176b1,null))[_0x6a3d('0x2c')](handleError(_0xb176b1,null));};exports['getMessages']=function(_0xc04f9f,_0xfa7811){var _0x25b241={'raw':![],'where':{}};var _0x572f57={};var _0x3859fd={'count':0x0,'rows':[]};return db[_0x6a3d('0x23')][_0x6a3d('0x3f')]({'where':{'id':_0xc04f9f[_0x6a3d('0x39')]['id']}})[_0x6a3d('0x1c')](handleEntityNotFound(_0xfa7811,null))[_0x6a3d('0x1c')](function(_0x5c74f8){if(_0x5c74f8){_0x572f57[_0x6a3d('0x2e')]=_[_0x6a3d('0x2f')](db[_0x6a3d('0x3d')]['rawAttributes']);_0x572f57[_0x6a3d('0x2a')]=_[_0x6a3d('0x2f')](_0xc04f9f[_0x6a3d('0x2a')]);_0x572f57[_0x6a3d('0x30')]=_[_0x6a3d('0x31')](_0x572f57[_0x6a3d('0x2e')],_0x572f57[_0x6a3d('0x2a')]);_0x25b241[_0x6a3d('0x32')]=_[_0x6a3d('0x31')](_0x572f57[_0x6a3d('0x2e')],qs['fields'](_0xc04f9f[_0x6a3d('0x2a')][_0x6a3d('0x33')]));_0x25b241[_0x6a3d('0x32')]=_0x25b241[_0x6a3d('0x32')][_0x6a3d('0x34')]?_0x25b241[_0x6a3d('0x32')]:_0x572f57[_0x6a3d('0x2e')];if(!_0xc04f9f[_0x6a3d('0x2a')][_0x6a3d('0x40')](_0x6a3d('0x41'))){_0x25b241[_0x6a3d('0x19')]=qs[_0x6a3d('0x19')](_0xc04f9f[_0x6a3d('0x2a')][_0x6a3d('0x19')]);_0x25b241['offset']=qs[_0x6a3d('0x16')](_0xc04f9f[_0x6a3d('0x2a')][_0x6a3d('0x16')]);}_0x25b241[_0x6a3d('0x42')]=qs[_0x6a3d('0x43')](_0xc04f9f[_0x6a3d('0x2a')]['sort']);_0x25b241[_0x6a3d('0x44')]=qs[_0x6a3d('0x30')](_['pick'](_0xc04f9f[_0x6a3d('0x2a')],_0x572f57[_0x6a3d('0x30')]));_0x25b241[_0x6a3d('0x44')]['MailInteractionId']=_0x5c74f8['id'];if(_0xc04f9f['query'][_0x6a3d('0x45')]){_0x25b241['where']=_[_0x6a3d('0x35')](_0x25b241[_0x6a3d('0x44')],{'$or':_['map'](_0x25b241[_0x6a3d('0x32')],function(_0x19f8cf){var _0x595c5a={};_0x595c5a[_0x19f8cf]={'$like':'%'+_0xc04f9f[_0x6a3d('0x2a')][_0x6a3d('0x45')]+'%'};return _0x595c5a;})});}if(_0xc04f9f[_0x6a3d('0x2a')][_0x6a3d('0x46')]){var _0x47f20c=_0xc04f9f[_0x6a3d('0x2a')][_0x6a3d('0x46')][_0x6a3d('0x47')](',');var _0x3a509={};_0x3a509[_0x47f20c[0x0]]={'$gte':moment(_0x47f20c[0x1])[_0x6a3d('0x48')]('YYYY-MM-DD\x20HH:mm:ss')};_0x25b241['where']=_[_0x6a3d('0x35')](_0x25b241['where'],_0x3a509);}_0x25b241=_[_0x6a3d('0x35')]({},_0x25b241,_0xc04f9f['options']);return db[_0x6a3d('0x3d')][_0x6a3d('0x18')]({'where':_0x25b241['where']})[_0x6a3d('0x1c')](function(_0x1bc118){_0x3859fd[_0x6a3d('0x18')]=_0x1bc118;if(_0xc04f9f['query'][_0x6a3d('0x49')]){_0x25b241[_0x6a3d('0x4a')]=[{'all':!![]}];}return db[_0x6a3d('0x3d')]['findAll'](_0x25b241);})[_0x6a3d('0x1c')](function(_0x535a2c){if(_0xc04f9f[_0x6a3d('0x2a')][_0x6a3d('0x4b')]===_0x6a3d('0x4c')){for(var _0x57ec73=0x0;_0x57ec73<_0x535a2c['length'];_0x57ec73++){_0x535a2c[_0x57ec73][_0x6a3d('0x38')]=juice(_0x535a2c[_0x57ec73][_0x6a3d('0x38')]);}}_0x3859fd[_0x6a3d('0x4d')]=_0x535a2c;return _0x3859fd;});}})[_0x6a3d('0x1c')](respondWithFilteredResult(_0xfa7811,_0x25b241))['catch'](handleError(_0xfa7811,null));};exports[_0x6a3d('0x4e')]=function(_0x495f8a,_0x2ea646){return db['MailInteraction'][_0x6a3d('0x37')]({'where':{'id':_0x495f8a['params']['id']}})[_0x6a3d('0x1c')](handleEntityNotFound(_0x2ea646,null))[_0x6a3d('0x1c')](function(_0x50c4a1){if(_0x50c4a1){return _0x50c4a1['setTags'](_0x495f8a[_0x6a3d('0x38')][_0x6a3d('0x3e')],_[_0x6a3d('0x4f')](_0x495f8a[_0x6a3d('0x38')],['ids','id'])||{})['spread'](function(){return db['Tag'][_0x6a3d('0x28')]({'attributes':['id',_0x6a3d('0x1f'),_0x6a3d('0x50')],'where':{'id':_0x495f8a[_0x6a3d('0x38')][_0x6a3d('0x3e')]}});})[_0x6a3d('0x1c')](function(_0xcdee51){socket[_0x6a3d('0x51')](_0x6a3d('0x52'),{'id':Number(_0x495f8a['params']['id']),'tags':_0xcdee51||[]});return{'id':Number(_0x495f8a[_0x6a3d('0x39')]['id']),'tags':_0xcdee51||[]};});}})[_0x6a3d('0x1c')](respondWithResult(_0x2ea646,null))[_0x6a3d('0x2c')](handleError(_0x2ea646,null));};exports['removeTags']=function(_0x2cf46a,_0x20695e){return db[_0x6a3d('0x23')]['find']({'where':{'id':_0x2cf46a[_0x6a3d('0x39')]['id']}})[_0x6a3d('0x1c')](handleEntityNotFound(_0x20695e,null))['then'](function(_0x5cc46a){if(_0x5cc46a){return _0x5cc46a['removeTags'](_0x2cf46a[_0x6a3d('0x2a')][_0x6a3d('0x3e')]);}})[_0x6a3d('0x1c')](respondWithStatusCode(_0x20695e,null))['catch'](handleError(_0x20695e,null));};exports['download']=function(_0x3706b9,_0x9cd836){var _0x5edcf2=moment()[_0x6a3d('0x53')]()[_0x6a3d('0x54')]();var _0x26869c=path[_0x6a3d('0x55')](config['root'],_0x6a3d('0x56'),_0x6a3d('0x57'),'tmp');var _0x4e1483=path[_0x6a3d('0x55')](config[_0x6a3d('0x58')],_0x6a3d('0x56'),_0x6a3d('0x57'),_0x6a3d('0x59'));var _0x230288=path[_0x6a3d('0x55')](_0x26869c,_0x5edcf2);var _0x2ae24d=util['format'](_0x6a3d('0x5a'),_0x3706b9['params']['id'],_0x5edcf2);var _0x250b5a=path[_0x6a3d('0x55')](_0x26869c,_0x2ae24d);var _0x11abfa=[];if(_0x3706b9[_0x6a3d('0x2a')]['attachments']){_0x11abfa[_0x6a3d('0x5b')]({'model':db[_0x6a3d('0x5c')],'as':_0x6a3d('0x5d'),'raw':!![]});}var _0x176766=[{'model':db['MailMessage'],'as':_0x6a3d('0x5e'),'attributes':['id',_0x6a3d('0x38'),_0x6a3d('0x5f'),'to','cc','bcc',_0x6a3d('0x60'),'createdAt'],'where':{'secret':![]},'order':qs[_0x6a3d('0x43')]('id'),'include':_0x11abfa}];return db['MailInteraction'][_0x6a3d('0x37')]({'where':{'id':_0x3706b9[_0x6a3d('0x39')]['id']},'include':_0x176766})[_0x6a3d('0x1c')](handleEntityNotFound(_0x9cd836,null))[_0x6a3d('0x1c')](function(_0x3ab104){if(_0x3ab104&&_0x3ab104[_0x6a3d('0x5e')]){var _0x354d0e=_0x3ab104[_0x6a3d('0x61')]({'plain':!![]});fs['mkdirSync'](_0x230288);return BPromise['each'](_0x354d0e[_0x6a3d('0x5e')],function(_0x2efa65,_0x89740e){var _0x295fb3={'from':_0x2efa65['from'],'to':_0x2efa65['to']||_0x6a3d('0x62'),'subject':_0x2efa65['subject'],'html':htmlEntities[_0x6a3d('0x63')](_0x2efa65[_0x6a3d('0x38')]),'headers':{'Date':moment(_0x2efa65[_0x6a3d('0x64')])[_0x6a3d('0x48')](_0x6a3d('0x65'))},'attachments':[]};if(_0x2efa65['cc']){_0x295fb3['headers']['Cc']=_0x2efa65['cc'];}if(_0x2efa65['bcc']){_0x295fb3[_0x6a3d('0x66')]['Bcc']=_0x2efa65[_0x6a3d('0x67')];}return new BPromise(function(_0x409a07,_0x1c26f6){if(_0x2efa65[_0x6a3d('0x5d')]){for(var _0x166b0d=0x0;_0x166b0d<_0x2efa65[_0x6a3d('0x5d')][_0x6a3d('0x34')];_0x166b0d++){var _0x5497b4=_0x2efa65['Attachments'][_0x166b0d];var _0x2d9705=path['join'](_0x4e1483,_0x5497b4[_0x6a3d('0x68')]);if(fs[_0x6a3d('0x69')](_0x2d9705)){_0x295fb3[_0x6a3d('0x59')][_0x6a3d('0x5b')]({'name':_0x5497b4[_0x6a3d('0x1f')],'contentType':_0x5497b4[_0x6a3d('0x26')],'data':fs['readFileSync'](_0x2d9705)});}}}emlformat[_0x6a3d('0x6a')](_0x295fb3,function(_0x362fa2,_0x3e1c9f){if(_0x362fa2)return _0x1c26f6(_0x362fa2);fs[_0x6a3d('0x6b')](path[_0x6a3d('0x55')](_0x230288,util[_0x6a3d('0x48')](_0x6a3d('0x6c'),_0x89740e)),_0x3e1c9f);return _0x409a07(_0x3e1c9f);});});})[_0x6a3d('0x1c')](function(){return new BPromise(function(_0x535600,_0x52c83d){zipdir(_0x230288,{'saveTo':_0x250b5a},function(_0xd98ed2,_0xedecf0){if(_0xd98ed2)return _0x52c83d(_0xd98ed2);return _0x535600(_0xedecf0);});})['then'](function(){return new BPromise(function(_0x51e6bf,_0x24bd8c){rimraf(_0x230288,function(_0x2ad253){if(_0x2ad253)_0x24bd8c(_0x2ad253);return _0x51e6bf();});});})[_0x6a3d('0x1c')](function(){return _0x9cd836[_0x6a3d('0x6d')](_0x250b5a,_0x2ae24d,function(_0xe4c764){if(!_0xe4c764)fs[_0x6a3d('0x6e')](_0x250b5a);});});});}else{return _0x9cd836[_0x6a3d('0x13')](0xc8);}})[_0x6a3d('0x2c')](handleError(_0x9cd836,null));};
\ No newline at end of file