Built motion from commit d5e4af8c.|2.6.23
[motion2.git] / server / api / mailInteraction / mailInteraction.controller.js
index b142394..01e502a 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 _0xfbaa=['body','destroy','describe','addMessage','ids','omit','getMessages','findOne','MailMessage','hasOwnProperty','sort','where','pick','MailInteractionId','filter','$gte','YYYY-MM-DD\x20HH:mm:ss','rows','addTags','setTags','spread','Tag','color','emit','removeTags','download','unix','toString','join','root','server','files','attachments','push','Attachment','Attachments','Messages','from','bcc','subject','createdAt','get','mkdirSync','each','missing.recipient@your.company.com','decode','format','ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ','headers','Bcc','basename','readFileSync','build','writeFileSync','message%d.eml','unlinkSync','eml-format','rimraf','zip-dir','moment','util','path','juice','../../components/interaction/service','../../components/parsers/qs','../../config/environment','../../mysqldb','html-entities','defaults','redis','localhost','sendStatus','end','status','json','undefined','count','offset','limit','set','Content-Range','update','then','error','stack','name','send','index','map','MailInteraction','rawAttributes','fieldName','type','getOptions','findAll','mail','query','user','params','keys','filters','model','attributes','intersection','fields','length','includeAll','include','merge','options','find','catch','create'];(function(_0x17e05b,_0x66e4e5){var _0x5cc4b6=function(_0x25a799){while(--_0x25a799){_0x17e05b['push'](_0x17e05b['shift']());}};_0x5cc4b6(++_0x66e4e5);}(_0xfbaa,0x18b));var _0xafba=function(_0x2aec52,_0x59d962){_0x2aec52=_0x2aec52-0x0;var _0x3b8835=_0xfbaa[_0x2aec52];return _0x3b8835;};'use strict';var emlformat=require(_0xafba('0x0'));var rimraf=require(_0xafba('0x1'));var zipdir=require(_0xafba('0x2'));var moment=require(_0xafba('0x3'));var BPromise=require('bluebird');var util=require(_0xafba('0x4'));var path=require(_0xafba('0x5'));var fs=require('fs');var _=require('lodash');var juice=require(_0xafba('0x6'));var Redis=require('ioredis');var interaction=require(_0xafba('0x7'));var qs=require(_0xafba('0x8'));var logger=require('../../config/logger')('api');var config=require(_0xafba('0x9'));var db=require(_0xafba('0xa'))['db'];var htmlEntities=require(_0xafba('0xb'));config['redis']=_[_0xafba('0xc')](config[_0xafba('0xd')],{'host':_0xafba('0xe'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xafba('0xd')]));require('./mailInteraction.socket')['register'](socket);function respondWithStatusCode(_0x159d3b,_0x4ea48e){_0x4ea48e=_0x4ea48e||0xcc;return function(_0x51ed2a){if(_0x51ed2a){return _0x159d3b[_0xafba('0xf')](_0x4ea48e);}return _0x159d3b['status'](_0x4ea48e)[_0xafba('0x10')]();};}function respondWithResult(_0x58434c,_0x3bc9f6){_0x3bc9f6=_0x3bc9f6||0xc8;return function(_0x5e1e9e){if(_0x5e1e9e){return _0x58434c[_0xafba('0x11')](_0x3bc9f6)[_0xafba('0x12')](_0x5e1e9e);}};}function respondWithFilteredResult(_0x3d648d,_0x2ee008){return function(_0x2ccfd1){if(_0x2ccfd1){var _0x59ad8e=typeof _0x2ee008['offset']==='undefined'&&typeof _0x2ee008['limit']===_0xafba('0x13');var _0x525c26=_0x2ccfd1[_0xafba('0x14')];var _0x10540d=_0x59ad8e?0x0:_0x2ee008[_0xafba('0x15')];var _0x372596=_0x59ad8e?_0x2ccfd1[_0xafba('0x14')]:_0x2ee008['offset']+_0x2ee008[_0xafba('0x16')];var _0x1c7b34;if(_0x372596>=_0x525c26){_0x372596=_0x525c26;_0x1c7b34=0xc8;}else{_0x1c7b34=0xce;}_0x3d648d[_0xafba('0x11')](_0x1c7b34);return _0x3d648d[_0xafba('0x17')](_0xafba('0x18'),_0x10540d+'-'+_0x372596+'/'+_0x525c26)[_0xafba('0x12')](_0x2ccfd1);}return null;};}function saveUpdates(_0x4533f3){return function(_0x4964bd){if(_0x4964bd){return _0x4964bd[_0xafba('0x19')](_0x4533f3)[_0xafba('0x1a')](function(_0x590994){return _0x590994;});}return null;};}function removeEntity(_0x50304f){return function(_0x4481e0){if(_0x4481e0){return _0x4481e0['destroy']()[_0xafba('0x1a')](function(){_0x50304f[_0xafba('0x11')](0xcc)[_0xafba('0x10')]();});}};}function handleEntityNotFound(_0x4f7669){return function(_0x494b58){if(!_0x494b58){_0x4f7669[_0xafba('0xf')](0x194);}return _0x494b58;};}function handleError(_0x96c974,_0x3bd1bb){_0x3bd1bb=_0x3bd1bb||0x1f4;return function(_0x11fd1e){logger[_0xafba('0x1b')](_0x11fd1e[_0xafba('0x1c')]);if(_0x11fd1e['name']){delete _0x11fd1e[_0xafba('0x1d')];}_0x96c974[_0xafba('0x11')](_0x3bd1bb)[_0xafba('0x1e')](_0x11fd1e);};}exports[_0xafba('0x1f')]=function(_0x304ab8,_0x12783e){var _0x4d4838={};var _0x24c39c=_[_0xafba('0x20')](db[_0xafba('0x21')][_0xafba('0x22')],function(_0x12a492){return{'name':_0x12a492[_0xafba('0x23')],'type':_0x12a492[_0xafba('0x24')]['key']};});_0x4d4838=qs[_0xafba('0x25')](_0x24c39c,_0x304ab8);return interaction[_0xafba('0x26')](_0xafba('0x27'),_0x304ab8[_0xafba('0x28')],_0x304ab8[_0xafba('0x29')],_0x4d4838,_0x24c39c)[_0xafba('0x1a')](respondWithFilteredResult(_0x12783e,_0x4d4838))['catch'](handleError(_0x12783e,null));};exports['show']=function(_0x19012b,_0x2d7e9d){var _0x406296={'raw':![],'where':{'id':_0x19012b[_0xafba('0x2a')]['id']}},_0xd6fe59={};_0xd6fe59['model']=_[_0xafba('0x2b')](db[_0xafba('0x21')][_0xafba('0x22')]);_0xd6fe59['query']=_[_0xafba('0x2b')](_0x19012b[_0xafba('0x28')]);_0xd6fe59[_0xafba('0x2c')]=_['intersection'](_0xd6fe59[_0xafba('0x2d')],_0xd6fe59[_0xafba('0x28')]);_0x406296[_0xafba('0x2e')]=_[_0xafba('0x2f')](_0xd6fe59[_0xafba('0x2d')],qs['fields'](_0x19012b[_0xafba('0x28')][_0xafba('0x30')]));_0x406296[_0xafba('0x2e')]=_0x406296[_0xafba('0x2e')][_0xafba('0x31')]?_0x406296[_0xafba('0x2e')]:_0xd6fe59[_0xafba('0x2d')];if(_0x19012b[_0xafba('0x28')][_0xafba('0x32')]){_0x406296[_0xafba('0x33')]=[{'all':!![]}];}_0x406296=_[_0xafba('0x34')]({},_0x406296,_0x19012b[_0xafba('0x35')]);return db[_0xafba('0x21')][_0xafba('0x36')](_0x406296)[_0xafba('0x1a')](handleEntityNotFound(_0x2d7e9d,null))[_0xafba('0x1a')](respondWithResult(_0x2d7e9d,null))[_0xafba('0x37')](handleError(_0x2d7e9d,null));};exports['create']=function(_0x31ef5c,_0x3dd757){return db[_0xafba('0x21')][_0xafba('0x38')](_0x31ef5c[_0xafba('0x39')],{})['then'](respondWithResult(_0x3dd757,0xc9))[_0xafba('0x37')](handleError(_0x3dd757,null));};exports['update']=function(_0x52ffac,_0xbb48ba){if(_0x52ffac[_0xafba('0x39')]['id']){delete _0x52ffac[_0xafba('0x39')]['id'];}return db['MailInteraction'][_0xafba('0x36')]({'where':{'id':_0x52ffac[_0xafba('0x2a')]['id']}})[_0xafba('0x1a')](handleEntityNotFound(_0xbb48ba,null))[_0xafba('0x1a')](saveUpdates(_0x52ffac['body'],null))[_0xafba('0x1a')](respondWithResult(_0xbb48ba,null))[_0xafba('0x37')](handleError(_0xbb48ba,null));};exports[_0xafba('0x3a')]=function(_0x1ee5b8,_0x8aff40){return db['MailInteraction'][_0xafba('0x36')]({'where':{'id':_0x1ee5b8['params']['id']}})[_0xafba('0x1a')](handleEntityNotFound(_0x8aff40,null))[_0xafba('0x1a')](removeEntity(_0x8aff40,null))[_0xafba('0x37')](handleError(_0x8aff40,null));};exports[_0xafba('0x3b')]=function(_0x3ab1d7,_0x3dcd6a){return db['MailInteraction'][_0xafba('0x3b')]()[_0xafba('0x1a')](respondWithResult(_0x3dcd6a,null))[_0xafba('0x37')](handleError(_0x3dcd6a,null));};exports['addMessage']=function(_0x595be5,_0x3bb4dc){return db['MailMessage']['find']({'where':{'id':_0x595be5[_0xafba('0x2a')]['id']}})[_0xafba('0x1a')](handleEntityNotFound(_0x3bb4dc,null))['then'](function(_0x58ef95){if(_0x58ef95){return _0x58ef95[_0xafba('0x3c')](_0x595be5[_0xafba('0x39')][_0xafba('0x3d')],_[_0xafba('0x3e')](_0x595be5[_0xafba('0x39')],[_0xafba('0x3d'),'id'])||{});}})[_0xafba('0x1a')](respondWithResult(_0x3bb4dc,null))['catch'](handleError(_0x3bb4dc,null));};exports[_0xafba('0x3f')]=function(_0xf615f2,_0x4fe707){var _0x5777e4={'raw':![],'where':{}};var _0x5e4acf={};var _0x1eeef3={'count':0x0,'rows':[]};return db[_0xafba('0x21')][_0xafba('0x40')]({'where':{'id':_0xf615f2[_0xafba('0x2a')]['id']}})[_0xafba('0x1a')](handleEntityNotFound(_0x4fe707,null))[_0xafba('0x1a')](function(_0x1c4e90){if(_0x1c4e90){_0x5e4acf[_0xafba('0x2d')]=_[_0xafba('0x2b')](db[_0xafba('0x41')][_0xafba('0x22')]);_0x5e4acf['query']=_[_0xafba('0x2b')](_0xf615f2[_0xafba('0x28')]);_0x5e4acf[_0xafba('0x2c')]=_['intersection'](_0x5e4acf[_0xafba('0x2d')],_0x5e4acf[_0xafba('0x28')]);_0x5777e4[_0xafba('0x2e')]=_[_0xafba('0x2f')](_0x5e4acf[_0xafba('0x2d')],qs['fields'](_0xf615f2[_0xafba('0x28')]['fields']));_0x5777e4[_0xafba('0x2e')]=_0x5777e4[_0xafba('0x2e')]['length']?_0x5777e4[_0xafba('0x2e')]:_0x5e4acf['model'];if(!_0xf615f2[_0xafba('0x28')][_0xafba('0x42')]('nolimit')){_0x5777e4[_0xafba('0x16')]=qs['limit'](_0xf615f2['query'][_0xafba('0x16')]);_0x5777e4[_0xafba('0x15')]=qs[_0xafba('0x15')](_0xf615f2['query'][_0xafba('0x15')]);}_0x5777e4['order']=qs[_0xafba('0x43')](_0xf615f2[_0xafba('0x28')][_0xafba('0x43')]);_0x5777e4[_0xafba('0x44')]=qs[_0xafba('0x2c')](_[_0xafba('0x45')](_0xf615f2[_0xafba('0x28')],_0x5e4acf[_0xafba('0x2c')]));_0x5777e4['where'][_0xafba('0x46')]=_0x1c4e90['id'];if(_0xf615f2[_0xafba('0x28')][_0xafba('0x47')]){_0x5777e4[_0xafba('0x44')]=_[_0xafba('0x34')](_0x5777e4['where'],{'$or':_[_0xafba('0x20')](_0x5777e4[_0xafba('0x2e')],function(_0x52cc58){var _0xee790b={};_0xee790b[_0x52cc58]={'$like':'%'+_0xf615f2[_0xafba('0x28')]['filter']+'%'};return _0xee790b;})});}if(_0xf615f2[_0xafba('0x28')][_0xafba('0x48')]){var _0x4adfb8=_0xf615f2[_0xafba('0x28')][_0xafba('0x48')]['split'](',');var _0xf7512d={};_0xf7512d[_0x4adfb8[0x0]]={'$gte':moment(_0x4adfb8[0x1])['format'](_0xafba('0x49'))};_0x5777e4[_0xafba('0x44')]=_[_0xafba('0x34')](_0x5777e4[_0xafba('0x44')],_0xf7512d);}_0x5777e4=_['merge']({},_0x5777e4,_0xf615f2[_0xafba('0x35')]);return db[_0xafba('0x41')][_0xafba('0x14')]({'where':_0x5777e4['where']})[_0xafba('0x1a')](function(_0x47dddc){_0x1eeef3[_0xafba('0x14')]=_0x47dddc;if(_0xf615f2[_0xafba('0x28')]['includeAll']){_0x5777e4[_0xafba('0x33')]=[{'all':!![]}];}return db[_0xafba('0x41')][_0xafba('0x26')](_0x5777e4);})[_0xafba('0x1a')](function(_0x31daab){if(_0xf615f2[_0xafba('0x28')]['inlineCss']==='true'){for(var _0xe33761=0x0;_0xe33761<_0x31daab['length'];_0xe33761++){_0x31daab[_0xe33761][_0xafba('0x39')]=juice(_0x31daab[_0xe33761]['body']);}}_0x1eeef3[_0xafba('0x4a')]=_0x31daab;return _0x1eeef3;});}})['then'](respondWithFilteredResult(_0x4fe707,_0x5777e4))[_0xafba('0x37')](handleError(_0x4fe707,null));};exports[_0xafba('0x4b')]=function(_0x372731,_0x339028){return db[_0xafba('0x21')][_0xafba('0x36')]({'where':{'id':_0x372731[_0xafba('0x2a')]['id']}})['then'](handleEntityNotFound(_0x339028,null))[_0xafba('0x1a')](function(_0x25b13b){if(_0x25b13b){return _0x25b13b[_0xafba('0x4c')](_0x372731['body'][_0xafba('0x3d')],_[_0xafba('0x3e')](_0x372731[_0xafba('0x39')],['ids','id'])||{})[_0xafba('0x4d')](function(){return db[_0xafba('0x4e')][_0xafba('0x26')]({'attributes':['id',_0xafba('0x1d'),_0xafba('0x4f')],'where':{'id':_0x372731[_0xafba('0x39')]['ids']}});})[_0xafba('0x1a')](function(_0x3e2d59){socket[_0xafba('0x50')]('mailInteractionTags:save',{'id':Number(_0x372731[_0xafba('0x2a')]['id']),'tags':_0x3e2d59||[]});return{'id':Number(_0x372731[_0xafba('0x2a')]['id']),'tags':_0x3e2d59||[]};});}})[_0xafba('0x1a')](respondWithResult(_0x339028,null))['catch'](handleError(_0x339028,null));};exports[_0xafba('0x51')]=function(_0x3e228e,_0xe48230){return db[_0xafba('0x21')]['find']({'where':{'id':_0x3e228e[_0xafba('0x2a')]['id']}})[_0xafba('0x1a')](handleEntityNotFound(_0xe48230,null))['then'](function(_0x2a4da4){if(_0x2a4da4){return _0x2a4da4[_0xafba('0x51')](_0x3e228e[_0xafba('0x28')][_0xafba('0x3d')]);}})[_0xafba('0x1a')](respondWithStatusCode(_0xe48230,null))[_0xafba('0x37')](handleError(_0xe48230,null));};exports[_0xafba('0x52')]=function(_0x394736,_0x274f66){var _0x18db10=moment()[_0xafba('0x53')]()[_0xafba('0x54')]();var _0x2a60ae=path[_0xafba('0x55')](config[_0xafba('0x56')],_0xafba('0x57'),'files','tmp');var _0x53c1fe=path['join'](config[_0xafba('0x56')],'server',_0xafba('0x58'),_0xafba('0x59'));var _0x4a7d5b=path['join'](_0x2a60ae,_0x18db10);var _0x5cbf70=util['format']('transcript-%d-%s.zip',_0x394736['params']['id'],_0x18db10);var _0x6b2c15=path['join'](_0x2a60ae,_0x5cbf70);var _0x47f2b3=[];if(_0x394736[_0xafba('0x28')][_0xafba('0x59')]){_0x47f2b3[_0xafba('0x5a')]({'model':db[_0xafba('0x5b')],'as':_0xafba('0x5c'),'raw':!![]});}var _0x28faae=[{'model':db[_0xafba('0x41')],'as':_0xafba('0x5d'),'attributes':['id',_0xafba('0x39'),_0xafba('0x5e'),'to','cc',_0xafba('0x5f'),_0xafba('0x60'),_0xafba('0x61')],'where':{'secret':![]},'order':qs['sort']('id'),'include':_0x47f2b3}];return db[_0xafba('0x21')][_0xafba('0x36')]({'where':{'id':_0x394736['params']['id']},'include':_0x28faae})[_0xafba('0x1a')](handleEntityNotFound(_0x274f66,null))[_0xafba('0x1a')](function(_0x1d7df4){if(_0x1d7df4&&_0x1d7df4[_0xafba('0x5d')]){var _0x3b0182=_0x1d7df4[_0xafba('0x62')]({'plain':!![]});fs[_0xafba('0x63')](_0x4a7d5b);return BPromise[_0xafba('0x64')](_0x3b0182[_0xafba('0x5d')],function(_0x19c009,_0x4bee00){var _0x559106={'from':_0x19c009[_0xafba('0x5e')],'to':_0x19c009['to']||_0xafba('0x65'),'subject':_0x19c009[_0xafba('0x60')],'html':htmlEntities[_0xafba('0x66')](_0x19c009[_0xafba('0x39')]),'headers':{'Date':moment(_0x19c009[_0xafba('0x61')])[_0xafba('0x67')](_0xafba('0x68'))},'attachments':[]};if(_0x19c009['cc']){_0x559106['headers']['Cc']=_0x19c009['cc'];}if(_0x19c009['bcc']){_0x559106[_0xafba('0x69')][_0xafba('0x6a')]=_0x19c009[_0xafba('0x5f')];}return new BPromise(function(_0x386948,_0x4e6e75){if(_0x19c009['Attachments']){for(var _0x4559b3=0x0;_0x4559b3<_0x19c009[_0xafba('0x5c')]['length'];_0x4559b3++){var _0x485ab4=_0x19c009[_0xafba('0x5c')][_0x4559b3];var _0x5d5a66=path[_0xafba('0x55')](_0x53c1fe,_0x485ab4[_0xafba('0x6b')]);if(fs['existsSync'](_0x5d5a66)){_0x559106[_0xafba('0x59')][_0xafba('0x5a')]({'name':_0x485ab4[_0xafba('0x1d')],'contentType':_0x485ab4['type'],'data':fs[_0xafba('0x6c')](_0x5d5a66)});}}}emlformat[_0xafba('0x6d')](_0x559106,function(_0x1f977d,_0x260e15){if(_0x1f977d)return _0x4e6e75(_0x1f977d);fs[_0xafba('0x6e')](path[_0xafba('0x55')](_0x4a7d5b,util[_0xafba('0x67')](_0xafba('0x6f'),_0x4bee00)),_0x260e15);return _0x386948(_0x260e15);});});})[_0xafba('0x1a')](function(){return new BPromise(function(_0x192f49,_0x4946ff){zipdir(_0x4a7d5b,{'saveTo':_0x6b2c15},function(_0x452e40,_0x524cdb){if(_0x452e40)return _0x4946ff(_0x452e40);return _0x192f49(_0x524cdb);});})[_0xafba('0x1a')](function(){return new BPromise(function(_0x4670ba,_0x22c756){rimraf(_0x4a7d5b,function(_0xbcbd17){if(_0xbcbd17)_0x22c756(_0xbcbd17);return _0x4670ba();});});})[_0xafba('0x1a')](function(){return _0x274f66['download'](_0x6b2c15,_0x5cbf70,function(_0x526802){if(!_0x526802)fs[_0xafba('0x70')](_0x6b2c15);});});});}else{return _0x274f66[_0xafba('0xf')](0xc8);}})[_0xafba('0x37')](handleError(_0x274f66,null));};
\ No newline at end of file