Built motion from commit da617fac.|2.6.6
[motion2.git] / server / api / mailInteraction / mailInteraction.controller.js
index d1170cc..baa8fd3 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x3f36=['defaults','localhost','socket.io-emitter','./mailInteraction.socket','register','sendStatus','end','status','count','offset','limit','Content-Range','json','apply','reject','save','update','then','error','stack','name','send','Users','map','fullname','TagIds','forEach','MailInteraction','findOne','lastMsgText','fromString','catch','index','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','pick','select','field','u.id','u.fullname','from','user_has_mail_interactions','left_join','users','mail_interactions','cm_contacts','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','mail_accounts','mail_messages','me.MailInteractionId\x20=\x20i.id','tools_tags','t.id\x20=\x20it.TagId','expr','search','parseSearch','sqlOperator','conditions','unreadMessages','having','`\x20>\x200','Contact','operator','$substring','value','split','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','getFullTextValue','c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?','ContactId','buildExpression','start','Tag','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','union','User','find','UserId','text','plainBody','some','i.MailAccountId\x20IN\x20?','parse','$gte','null','\x20IS\x20NULL','\x20=\x20?','read','`unreadMessages`\x20=\x200','`unreadMessages`\x20>\x200','tag','isArray','filter','replace','isNumeric','c.email\x20LIKE\x20?','MATCH\x20(me.plainBody,\x20me.subject)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','group','i.id','Sequelize','QueryTypes','SELECT','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','DESC','isEmpty','MailAccountId','journey','i.MailAccountId\x20IS\x20NOT\x20NULL','user','i.MailAccountId\x20IS\x20NULL','sequelize','toString','merge','a.key','Account.key','a.mandatoryDisposition','contactName','i.createdAt','i.updatedAt','i.closed','i.closedAt','i.attach','i.lastMsgAt','i.lastMsgDirection','i.secondDisposition','i.thirdDisposition','i.substatus','i.to','i.ContactId','i.MailAccountId','i.UserId','c.firstName','c.lastName','Contact.lastName','c.email','c.phone','Contact.phone','c.mobile','Contact.mobile','c.fax','o.fullname','Owner.fullname','o.internal','Owner.internal','ui.MailInteractionId\x20IN\x20?','groupBy','MailInteractionId','Setting','enableEmailPreview','push','all','rows','params','includeAll','include','options','create','body','destroy','describe','MailMessage','addMessage','ids','omit','getMessages','findAll','addTags','spread','color','emit','mailInteractionTags:save','removeTags','download','unix','join','root','files','tmp','server','attachments','format','transcript-%d-%s.zip','Attachment','Attachments','Messages','bcc','subject','createdAt','get','mkdirSync','ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ','headers','Bcc','basename','existsSync','writeFileSync','message%d.eml','log','err','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','path','sox','to-csv','ejs','crypto','jsforce','querystring','papaparse','html-to-text','ioredis','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis'];(function(_0x9fd887,_0x47f76c){var _0x1a54ab=function(_0xb65c08){while(--_0xb65c08){_0x9fd887['push'](_0x9fd887['shift']());}};_0x1a54ab(++_0x47f76c);}(_0x3f36,0xd5));var _0x63f3=function(_0x121b1a,_0x42fdb7){_0x121b1a=_0x121b1a-0x0;var _0x2d89a6=_0x3f36[_0x121b1a];return _0x2d89a6;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x63f3('0x0'));var rimraf=require(_0x63f3('0x1'));var zipdir=require(_0x63f3('0x2'));var jsonpatch=require(_0x63f3('0x3'));var rp=require(_0x63f3('0x4'));var moment=require(_0x63f3('0x5'));var BPromise=require(_0x63f3('0x6'));var Mustache=require(_0x63f3('0x7'));var util=require('util');var path=require(_0x63f3('0x8'));var sox=require(_0x63f3('0x9'));var csv=require(_0x63f3('0xa'));var ejs=require(_0x63f3('0xb'));var fs=require('fs');var _=require('lodash');var squel=require('squel');var crypto=require(_0x63f3('0xc'));var jsforce=require(_0x63f3('0xd'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0x63f3('0xe'));var Papa=require(_0x63f3('0xf'));var htmlToText=require(_0x63f3('0x10'));var Redis=require(_0x63f3('0x11'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0x63f3('0x12'));var hardwareService=require(_0x63f3('0x13'));var logger=require('../../config/logger')(_0x63f3('0x14'));var utils=require(_0x63f3('0x15'));var config=require(_0x63f3('0x16'));var licenseUtil=require(_0x63f3('0x17'));var db=require(_0x63f3('0x18'))['db'];config[_0x63f3('0x19')]=_[_0x63f3('0x1a')](config[_0x63f3('0x19')],{'host':_0x63f3('0x1b'),'port':0x18eb});var socket=require(_0x63f3('0x1c'))(new Redis(config[_0x63f3('0x19')]));require(_0x63f3('0x1d'))[_0x63f3('0x1e')](socket);function respondWithStatusCode(_0x982284,_0x10beb6){_0x10beb6=_0x10beb6||0xcc;return function(_0x500a8a){if(_0x500a8a){return _0x982284[_0x63f3('0x1f')](_0x10beb6);}return _0x982284['status'](_0x10beb6)[_0x63f3('0x20')]();};}function respondWithResult(_0x31f13a,_0x57b892){_0x57b892=_0x57b892||0xc8;return function(_0x2bfccf){if(_0x2bfccf){return _0x31f13a[_0x63f3('0x21')](_0x57b892)['json'](_0x2bfccf);}};}function respondWithFilteredResult(_0x553885,_0x4dd862){return function(_0x19f347){if(_0x19f347){var _0x209bba=_0x19f347[_0x63f3('0x22')],_0x20e698=_0x4dd862[_0x63f3('0x23')],_0x41bcd7=_0x4dd862['offset']+_0x4dd862[_0x63f3('0x24')],_0x40df3f;if(_0x41bcd7>=_0x209bba){_0x41bcd7=_0x209bba;_0x40df3f=0xc8;}else{_0x40df3f=0xce;}_0x553885[_0x63f3('0x21')](_0x40df3f);return _0x553885['set'](_0x63f3('0x25'),_0x20e698+'-'+_0x41bcd7+'/'+_0x209bba)[_0x63f3('0x26')](_0x19f347);}return null;};}function patchUpdates(_0x24165d){return function(_0x5b362d){try{jsonpatch[_0x63f3('0x27')](_0x5b362d,_0x24165d,!![]);}catch(_0x5d8bfd){return BPromise[_0x63f3('0x28')](_0x5d8bfd);}return _0x5b362d[_0x63f3('0x29')]();};}function saveUpdates(_0x8b33d3,_0x13c792){return function(_0x3c6025){if(_0x3c6025){return _0x3c6025[_0x63f3('0x2a')](_0x8b33d3)[_0x63f3('0x2b')](function(_0x4eda73){return _0x4eda73;});}return null;};}function removeEntity(_0x467fd6,_0x7e41d6){return function(_0x1a5e00){if(_0x1a5e00){return _0x1a5e00['destroy']()[_0x63f3('0x2b')](function(){_0x467fd6[_0x63f3('0x21')](0xcc)[_0x63f3('0x20')]();});}};}function handleEntityNotFound(_0x28bb19,_0x14b1cb){return function(_0x9d6e8a){if(!_0x9d6e8a){_0x28bb19[_0x63f3('0x1f')](0x194);}return _0x9d6e8a;};}function handleError(_0x1a439f,_0x5ca5d0){_0x5ca5d0=_0x5ca5d0||0x1f4;return function(_0x3c1b2a){logger[_0x63f3('0x2c')](_0x3c1b2a[_0x63f3('0x2d')]);if(_0x3c1b2a[_0x63f3('0x2e')]){delete _0x3c1b2a['name'];}_0x1a439f[_0x63f3('0x21')](_0x5ca5d0)[_0x63f3('0x2f')](_0x3c1b2a);};}function getInteractionUsers(_0x526718,_0x41f81d){return new BPromise(function(_0x51c92d,_0x4f768c){try{if(_0x41f81d[_0x526718['id']]){_0x526718[_0x63f3('0x30')]=_[_0x63f3('0x31')](_0x41f81d[_0x526718['id']],function(_0x26ab65){return{'id':_0x26ab65['id'],'fullname':_0x26ab65[_0x63f3('0x32')]};});}}catch(_0x35778a){_0x4f768c(_0x35778a);}_0x51c92d(_0x526718);});}function getInteractionTags(_0x4a6f4f,_0x4a65dd){return new BPromise(function(_0x573b51,_0x119ec1){try{if(_0x4a6f4f['TagIds']){_0x4a6f4f['Tags']=[];_0x4a6f4f[_0x63f3('0x33')]['split'](',')[_0x63f3('0x34')](function(_0xe5df05){_0x4a6f4f['Tags']['push'](_0x4a65dd[_0xe5df05]);});}delete _0x4a6f4f[_0x63f3('0x33')];}catch(_0x32e0dc){_0x119ec1(_0x32e0dc);}_0x573b51(_0x4a6f4f);});}function getLastMessageText(_0x33abb8){return new BPromise(function(_0x1d4a30,_0x4a79bf){return db[_0x63f3('0x35')][_0x63f3('0x36')]({'where':{'id':_0x33abb8['id']},'attributes':['lastMsgBody',_0x63f3('0x37')],'raw':!![]})[_0x63f3('0x2b')](function(_0x57afe9){if(!_0x57afe9[_0x63f3('0x37')]){_0x33abb8[_0x63f3('0x37')]=_['trimStart'](htmlToText[_0x63f3('0x38')](_0x57afe9['lastMsgBody'],{'preserveNewlines':!![],'singleNewLineParagraphs':!![],'uppercaseHeadings':![],'noLinkBrackets':!![],'ignoreImage':!![]}));}else{_0x33abb8[_0x63f3('0x37')]=_0x57afe9['lastMsgText'];}_0x1d4a30(_0x33abb8);})[_0x63f3('0x39')](function(_0x4c2bbd){_0x4a79bf(_0x4c2bbd);});});}function updateMailInteraction(_0x54a167,_0x2ec37f,_0x43b129,_0x553900){return new BPromise(function(_0x2ea7d6,_0x26472d){return getInteractionUsers(_0x54a167,_0x43b129)[_0x63f3('0x2b')](function(_0x3176e8){return getInteractionTags(_0x3176e8,_0x2ec37f);})['then'](function(_0x38a253){if(_0x553900){_0x2ea7d6(getLastMessageText(_0x38a253));}else{_0x2ea7d6(_0x38a253);}})[_0x63f3('0x39')](function(_0x1a9b1c){_0x26472d(_0x1a9b1c);});});}exports[_0x63f3('0x3a')]=function(_0x4beead,_0x4aafd3){var _0xff3dca={},_0x202563={},_0x59b388={'count':0x0,'rows':[]};var _0x2d79c4=_[_0x63f3('0x31')](db[_0x63f3('0x35')][_0x63f3('0x3b')],function(_0x1ea5c3){return{'name':_0x1ea5c3[_0x63f3('0x3c')],'type':_0x1ea5c3[_0x63f3('0x3d')][_0x63f3('0x3e')]};});_0x202563[_0x63f3('0x3f')]=_[_0x63f3('0x31')](_0x2d79c4,_0x63f3('0x2e'));_0x202563[_0x63f3('0x40')]=_[_0x63f3('0x41')](_0x4beead[_0x63f3('0x40')]);_0x202563[_0x63f3('0x42')]=_['intersection'](_0x202563[_0x63f3('0x3f')],_0x202563[_0x63f3('0x40')]);_0xff3dca['attributes']=_[_0x63f3('0x43')](_0x202563[_0x63f3('0x3f')],qs[_0x63f3('0x44')](_0x4beead[_0x63f3('0x40')]['fields']));_0xff3dca[_0x63f3('0x45')]=_0xff3dca['attributes'][_0x63f3('0x46')]?_0xff3dca[_0x63f3('0x45')]:_0x202563['model'];if(!_0x4beead[_0x63f3('0x40')][_0x63f3('0x47')](_0x63f3('0x48'))){_0xff3dca[_0x63f3('0x24')]=qs[_0x63f3('0x24')](_0x4beead['query'][_0x63f3('0x24')]);_0xff3dca[_0x63f3('0x23')]=qs[_0x63f3('0x23')](_0x4beead['query'][_0x63f3('0x23')]);}_0xff3dca[_0x63f3('0x49')]=qs['sort'](_0x4beead[_0x63f3('0x40')][_0x63f3('0x4a')]);_0xff3dca[_0x63f3('0x4b')]=qs[_0x63f3('0x42')](_[_0x63f3('0x4c')](_0x4beead[_0x63f3('0x40')],_0x202563[_0x63f3('0x42')]),_0x2d79c4);var _0xc70c1e=[];var _0x230338=squel[_0x63f3('0x4d')]()['field']('id')[_0x63f3('0x4e')](_0x63f3('0x2e'))[_0x63f3('0x4e')]('color')['from']('tools_tags');var _0x1c122b=squel[_0x63f3('0x4d')]()[_0x63f3('0x4e')](_0x63f3('0x4f'))[_0x63f3('0x4e')](_0x63f3('0x50'))['field']('ui.MailInteractionId')[_0x63f3('0x51')](_0x63f3('0x52'),'ui')[_0x63f3('0x53')](_0x63f3('0x54'),'u','u.id\x20=\x20ui.UserId');var _0x54549b=squel[_0x63f3('0x4d')]()[_0x63f3('0x51')](_0x63f3('0x55'),'i')[_0x63f3('0x53')](_0x63f3('0x56'),'c',_0x63f3('0x57'))['left_join'](_0x63f3('0x54'),'o','o.id\x20=\x20i.UserId')[_0x63f3('0x53')](_0x63f3('0x58'),'a','a.id\x20=\x20i.MailAccountId')[_0x63f3('0x53')](_0x63f3('0x59'),'me',_0x63f3('0x5a'))[_0x63f3('0x53')]('mail_interaction_has_tags','it','it.MailInteractionId\x20=\x20i.id')[_0x63f3('0x53')](_0x63f3('0x5b'),'t',_0x63f3('0x5c'));var _0x47d470=squel[_0x63f3('0x5d')]();var _0xf75414=[];var _0x116bca=squel[_0x63f3('0x5d')]();var _0x1ffc0f;if(_0x4beead['query'][_0x63f3('0x5e')]){_0x1ffc0f=as[_0x63f3('0x5f')](_0x4beead['query'][_0x63f3('0x5e')]);var _0x25c8e3=_0x1ffc0f[_0x63f3('0x60')];for(var _0x522f43=0x0;_0x522f43<_0x1ffc0f[_0x63f3('0x61')]['length'];_0x522f43++){var _0x899936=_0x1ffc0f[_0x63f3('0x61')][_0x522f43];var _0x16a2db='i';var _0x5d534=_['find'](_0x2d79c4,[_0x63f3('0x2e'),_0x899936[_0x63f3('0x4e')]]);if(!_0x5d534){switch(_0x899936['field']){case _0x63f3('0x62'):if(_0x899936['value']==0x1){_0x54549b[_0x63f3('0x63')]('`'+_0x899936[_0x63f3('0x4e')]+'`\x20=\x200');}else{_0x54549b['having']('`'+_0x899936['field']+_0x63f3('0x64'));}break;case _0x63f3('0x65'):if(_0x899936[_0x63f3('0x66')]===_0x63f3('0x67')){if(_0x899936[_0x63f3('0x68')][_0x63f3('0x69')]('\x20')['length']>0x1){_0x47d470[_0x25c8e3](_0x63f3('0x6a'),qs[_0x63f3('0x6b')](_0x899936[_0x63f3('0x68')]),null);}else{var _0x457987='%'+_0x899936[_0x63f3('0x68')]+'%';_0x47d470[_0x25c8e3](_0x63f3('0x6c'),_0x457987,_0x457987,_0x457987);}}else{_0x5d534=_['find'](_0x2d79c4,['name',_0x63f3('0x6d')]);_0x899936[_0x63f3('0x4e')]='ContactId';_0x3f80df=as[_0x63f3('0x6e')](_0x16a2db,_0x5d534[_0x63f3('0x3d')],_0x899936);_0x47d470[_0x25c8e3](_0x3f80df['text'],_0x3f80df[_0x63f3('0x68')][_0x63f3('0x6f')],_0x3f80df['value']['end']);}break;case _0x63f3('0x70'):var _0x5569ae=_0x899936[_0x63f3('0x68')][_0x63f3('0x69')](',')[_0x63f3('0x31')](function(_0x91ff48){return Number(_0x91ff48);});_0x5569ae['forEach'](function(_0x36e399){_0x116bca['or'](_0x63f3('0x71'),'%,'+_0x36e399+',%');});_0xf75414=_[_0x63f3('0x72')](_0xf75414,_0x5569ae);break;case _0x63f3('0x73'):if(_0x899936[_0x63f3('0x66')]===_0x63f3('0x67')){_0x47d470[_0x25c8e3]('CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','%'+_0x899936['value']+'%',null);}else{_0x5d534=_[_0x63f3('0x74')](_0x2d79c4,[_0x63f3('0x2e'),_0x63f3('0x75')]);_0x899936[_0x63f3('0x4e')]=_0x63f3('0x75');_0x3f80df=as[_0x63f3('0x6e')](_0x16a2db,_0x5d534[_0x63f3('0x3d')],_0x899936);_0x47d470[_0x25c8e3](_0x3f80df[_0x63f3('0x76')],_0x3f80df[_0x63f3('0x68')]['start'],_0x3f80df['value']['end']);}break;case _0x63f3('0x77'):_0x3f80df=as['buildExpression']('me',null,_0x899936);_0x47d470[_0x25c8e3](_0x3f80df['text'],_0x3f80df['value'][_0x63f3('0x6f')],_0x3f80df[_0x63f3('0x68')][_0x63f3('0x20')]);break;}}else{var _0x3f80df=as['buildExpression'](_0x16a2db,_0x5d534[_0x63f3('0x3d')],_0x899936);_0x47d470[_0x25c8e3](_0x3f80df['text'],_0x3f80df['value']['start'],_0x3f80df[_0x63f3('0x68')]['end']);}}}else{var _0x1a1502=_(_0x4beead[_0x63f3('0x40')])['keys']()[_0x63f3('0x31')](function(_0x3db9c5){return _[_0x63f3('0x78')](_0x2d79c4,[_0x63f3('0x2e'),_0x3db9c5])?_0x3db9c5:undefined;})['compact']()[_0x63f3('0x68')]();if(!_['isEmpty'](_0x1a1502)){_0x1a1502['forEach'](function(_0x5b64f4){if(_0x5b64f4==='MailAccountId'){_0x54549b['where'](_0x63f3('0x79'),[]['concat'](_0x4beead['query'][_0x5b64f4]));}else if(_0x5b64f4==='createdAt'){var _0x140498=JSON[_0x63f3('0x7a')](_0x4beead['query'][_0x5b64f4])[_0x63f3('0x7b')];var _0x2c5f5c=JSON[_0x63f3('0x7a')](_0x4beead['query'][_0x5b64f4])['$lte'];_0x54549b[_0x63f3('0x4b')]('i.createdAt\x20BETWEEN\x20?\x20AND\x20?',_0x140498,_0x2c5f5c);}else{if(_0x4beead[_0x63f3('0x40')][_0x5b64f4]===_0x63f3('0x7c')){_0x54549b['where']('i.'+_0x5b64f4+_0x63f3('0x7d'));}else{_0x54549b[_0x63f3('0x4b')]('i.'+_0x5b64f4+_0x63f3('0x7e'),_0x4beead['query'][_0x5b64f4]);}}});}if(_0x4beead[_0x63f3('0x40')][_0x63f3('0x7f')]){if(_0x4beead[_0x63f3('0x40')][_0x63f3('0x7f')]==0x1){_0x54549b[_0x63f3('0x63')](_0x63f3('0x80'));}else{_0x54549b['having'](_0x63f3('0x81'));}}if(_0x4beead[_0x63f3('0x40')][_0x63f3('0x82')]){_0xf75414=_[_0x63f3('0x83')](_0x4beead[_0x63f3('0x40')][_0x63f3('0x82')])?_0x4beead[_0x63f3('0x40')][_0x63f3('0x82')]:new Array(_0x4beead['query'][_0x63f3('0x82')]);_0xf75414[_0x63f3('0x34')](function(_0x5e2cce){_0x116bca['or'](_0x63f3('0x71'),'%,'+_0x5e2cce+',%');});}if(_0x4beead[_0x63f3('0x40')][_0x63f3('0x84')]){var _0x3ed0ae=_0x4beead[_0x63f3('0x40')][_0x63f3('0x84')][_0x63f3('0x85')]('\x5c','\x5c\x5c')['replace'](/'/g,'\x27\x27');if(qs[_0x63f3('0x86')](_0x3ed0ae)){_0x47d470['or']('i.id\x20LIKE\x20?',_0x3ed0ae+'%');}else if(qs['isEmail'](_0x3ed0ae)){_0x47d470['or'](_0x63f3('0x87'),_0x3ed0ae+'%');}else{_0x47d470['or']('MATCH\x20(i.to,\x20i.subject)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs[_0x63f3('0x6b')](_0x3ed0ae))['or'](_0x63f3('0x88'),qs[_0x63f3('0x6b')](_0x3ed0ae));}}}_0x54549b[_0x63f3('0x4b')](_0x47d470);_0x54549b[_0x63f3('0x89')](_0x63f3('0x8a'));var _0x5c9ef2={'type':db[_0x63f3('0x8b')][_0x63f3('0x8c')][_0x63f3('0x8d')],'raw':!![]};var _0x1ed63b=_0x54549b['clone']();_0x1ed63b[_0x63f3('0x4e')]('i.id');_0x1ed63b[_0x63f3('0x4e')](_0x63f3('0x8e'),'unreadMessages');if(_0xff3dca[_0x63f3('0x49')]){_0xff3dca[_0x63f3('0x49')]['forEach'](function(_0x566333){var _0x38b8f8=_0x566333[0x0]==='contactName'?_0x566333[0x0]:'i.'+_0x566333[0x0];_0x54549b[_0x63f3('0x49')](_0x38b8f8,_0x566333[0x1]===_0x63f3('0x8f')?![]:!![]);});}if(!_[_0x63f3('0x90')](_0xf75414)){_0x54549b[_0x63f3('0x63')](_0x116bca);_0x1ed63b[_0x63f3('0x4b')]('t.id\x20IN\x20?',_0xf75414);}BPromise['resolve']()[_0x63f3('0x2b')](function(){if(!_0x1ffc0f){if(_0x4beead[_0x63f3('0x40')][_0x63f3('0x91')]||_0x4beead[_0x63f3('0x40')][_0x63f3('0x92')])return;_0x1ed63b[_0x63f3('0x4b')](_0x63f3('0x93'));_0x54549b[_0x63f3('0x4b')]('i.MailAccountId\x20IS\x20NOT\x20NULL');return;}return _0x4beead[_0x63f3('0x94')]['getMailAccounts']({'attributes':['id'],'raw':!![]})[_0x63f3('0x2b')](function(_0x3aab96){if(_[_0x63f3('0x90')](_0x3aab96)){_0x1ed63b[_0x63f3('0x4b')]('i.MailAccountId\x20IS\x20NULL');_0x54549b['where'](_0x63f3('0x95'));}else{_0x1ed63b[_0x63f3('0x4b')]('i.MailAccountId\x20IN\x20?',_[_0x63f3('0x31')](_0x3aab96,'id'));_0x54549b[_0x63f3('0x4b')](_0x63f3('0x79'),_[_0x63f3('0x31')](_0x3aab96,'id'));}});})[_0x63f3('0x2b')](function(){db[_0x63f3('0x96')][_0x63f3('0x40')](_0x1ed63b[_0x63f3('0x97')](),_0x5c9ef2)[_0x63f3('0x2b')](function(_0x24550f){_0x59b388['count']=_0x24550f['length'];if(_0x59b388[_0x63f3('0x22')]===0x0)return[];return db[_0x63f3('0x96')][_0x63f3('0x40')](_0x230338['toString'](),_0x5c9ef2)[_0x63f3('0x2b')](function(_0x51e52b){_0xc70c1e=_['keyBy'](_0x51e52b,'id');_0x5c9ef2=_[_0x63f3('0x98')](_0x5c9ef2,{'model':db['MailInteraction'],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x4beead['query']['fields']){_0xff3dca[_0x63f3('0x45')][_0x63f3('0x34')](function(_0x2ebba2){_0x54549b['field']('i.'+_0x2ebba2);});}else{_0x54549b['field']('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)',_0x63f3('0x62'));_0x54549b['field'](_0x63f3('0x99'),_0x63f3('0x9a'));_0x54549b[_0x63f3('0x4e')](_0x63f3('0x9b'),'Account.mandatoryDisposition');_0x54549b[_0x63f3('0x4e')]('CASE\x20WHEN\x20i.to\x20IS\x20NOT\x20NULL\x20AND\x20i.to\x20<>\x20\x27\x27\x20AND\x20i.to\x20NOT\x20LIKE\x20(\x27%\x27\x20+\x20a.email\x20+\x20\x27%\x27)\x20THEN\x20SUBSTRING_INDEX(i.to,\x20\x27<\x27,\x201)\x20WHEN\x20(c.firstName\x20IS\x20NOT\x20NULL\x20AND\x20c.firstName\x20<>\x20\x27\x27)\x20OR\x20(c.lastName\x20IS\x20NOT\x20NULL\x20AND\x20c.lastName\x20<>\x20\x27\x27)\x20THEN\x20CONCAT(IFNULL(c.firstName,\x20\x27\x27),\x20\x27\x20\x27,\x20IFNULL(c.lastName,\x20\x27\x27))\x20ELSE\x20\x27Unknown\x27\x20END',_0x63f3('0x9c'));_0x54549b[_0x63f3('0x4e')](_0x63f3('0x8a'));_0x54549b[_0x63f3('0x4e')](_0x63f3('0x9d'));_0x54549b['field'](_0x63f3('0x9e'));_0x54549b['field'](_0x63f3('0x9f'));_0x54549b['field'](_0x63f3('0xa0'));_0x54549b[_0x63f3('0x4e')](_0x63f3('0xa1'));_0x54549b['field'](_0x63f3('0xa2'));_0x54549b[_0x63f3('0x4e')](_0x63f3('0xa3'));_0x54549b['field']('i.subject');_0x54549b[_0x63f3('0x4e')]('i.disposition');_0x54549b[_0x63f3('0x4e')](_0x63f3('0xa4'));_0x54549b[_0x63f3('0x4e')](_0x63f3('0xa5'));_0x54549b[_0x63f3('0x4e')](_0x63f3('0xa6'));_0x54549b[_0x63f3('0x4e')](_0x63f3('0xa7'));_0x54549b[_0x63f3('0x4e')](_0x63f3('0xa8'));_0x54549b[_0x63f3('0x4e')](_0x63f3('0xa9'));_0x54549b[_0x63f3('0x4e')](_0x63f3('0xaa'));_0x54549b[_0x63f3('0x4e')](_0x63f3('0xab'),'Contact.firstName');_0x54549b['field'](_0x63f3('0xac'),_0x63f3('0xad'));_0x54549b[_0x63f3('0x4e')](_0x63f3('0xae'),'Contact.email');_0x54549b[_0x63f3('0x4e')](_0x63f3('0xaf'),_0x63f3('0xb0'));_0x54549b[_0x63f3('0x4e')](_0x63f3('0xb1'),_0x63f3('0xb2'));_0x54549b['field'](_0x63f3('0xb3'),'Contact.fax');_0x54549b[_0x63f3('0x4e')](_0x63f3('0xb4'),_0x63f3('0xb5'));_0x54549b[_0x63f3('0x4e')](_0x63f3('0xb6'),_0x63f3('0xb7'));_0x54549b[_0x63f3('0x4e')]('GROUP_CONCAT(DISTINCT\x20t.id)',_0x63f3('0x33'));}if(_0xff3dca[_0x63f3('0x24')])_0x54549b[_0x63f3('0x24')](_0xff3dca['limit']);if(_0xff3dca['offset'])_0x54549b[_0x63f3('0x23')](_0xff3dca[_0x63f3('0x23')]);return db[_0x63f3('0x96')][_0x63f3('0x40')](_0x54549b['toString'](),_0x5c9ef2);})[_0x63f3('0x2b')](function(_0x1d4933){_0x1c122b['where'](_0x63f3('0xb8'),_[_0x63f3('0x31')](_0x1d4933,'id'));return db[_0x63f3('0x96')][_0x63f3('0x40')](_0x1c122b['toString'](),_0x5c9ef2)[_0x63f3('0x2b')](function(_0x3456f8){var _0x2af7af=_[_0x63f3('0xb9')](_0x3456f8,_0x63f3('0xba'));var _0x529daf=[];return db[_0x63f3('0xbb')]['findOne']({'attributes':[_0x63f3('0xbc')],'raw':!![]})['then'](function(_0x3f52ec){var _0x1ea0b9=_0x3f52ec[_0x63f3('0xbc')];_0x1d4933[_0x63f3('0x34')](function(_0x36a12c){_0x529daf[_0x63f3('0xbd')](updateMailInteraction(_0x36a12c,_0xc70c1e,_0x2af7af,_0x1ea0b9));});return BPromise[_0x63f3('0xbe')](_0x529daf);});});});})[_0x63f3('0x2b')](function(_0x2792f6){_0x59b388[_0x63f3('0xbf')]=_0x2792f6;return _0x59b388;})[_0x63f3('0x2b')](respondWithFilteredResult(_0x4aafd3,_0xff3dca));})[_0x63f3('0x39')](handleError(_0x4aafd3,null));};exports['show']=function(_0x2ad0f2,_0x410b7e){var _0x5c2695={'raw':![],'where':{'id':_0x2ad0f2[_0x63f3('0xc0')]['id']}},_0x455562={};_0x455562[_0x63f3('0x3f')]=_[_0x63f3('0x41')](db[_0x63f3('0x35')][_0x63f3('0x3b')]);_0x455562[_0x63f3('0x40')]=_[_0x63f3('0x41')](_0x2ad0f2[_0x63f3('0x40')]);_0x455562['filters']=_[_0x63f3('0x43')](_0x455562[_0x63f3('0x3f')],_0x455562[_0x63f3('0x40')]);_0x5c2695[_0x63f3('0x45')]=_[_0x63f3('0x43')](_0x455562[_0x63f3('0x3f')],qs[_0x63f3('0x44')](_0x2ad0f2[_0x63f3('0x40')][_0x63f3('0x44')]));_0x5c2695[_0x63f3('0x45')]=_0x5c2695[_0x63f3('0x45')][_0x63f3('0x46')]?_0x5c2695[_0x63f3('0x45')]:_0x455562[_0x63f3('0x3f')];if(_0x2ad0f2[_0x63f3('0x40')][_0x63f3('0xc1')]){_0x5c2695[_0x63f3('0xc2')]=[{'all':!![]}];}_0x5c2695=_['merge']({},_0x5c2695,_0x2ad0f2[_0x63f3('0xc3')]);return db[_0x63f3('0x35')]['find'](_0x5c2695)[_0x63f3('0x2b')](handleEntityNotFound(_0x410b7e,null))[_0x63f3('0x2b')](respondWithResult(_0x410b7e,null))[_0x63f3('0x39')](handleError(_0x410b7e,null));};exports[_0x63f3('0xc4')]=function(_0x4a981f,_0x16afc6){return db[_0x63f3('0x35')]['create'](_0x4a981f['body'],{})[_0x63f3('0x2b')](respondWithResult(_0x16afc6,0xc9))[_0x63f3('0x39')](handleError(_0x16afc6,null));};exports[_0x63f3('0x2a')]=function(_0x335701,_0x4d0fc8){if(_0x335701[_0x63f3('0xc5')]['id']){delete _0x335701[_0x63f3('0xc5')]['id'];}return db[_0x63f3('0x35')][_0x63f3('0x74')]({'where':{'id':_0x335701[_0x63f3('0xc0')]['id']}})[_0x63f3('0x2b')](handleEntityNotFound(_0x4d0fc8,null))[_0x63f3('0x2b')](saveUpdates(_0x335701[_0x63f3('0xc5')],null))['then'](respondWithResult(_0x4d0fc8,null))[_0x63f3('0x39')](handleError(_0x4d0fc8,null));};exports[_0x63f3('0xc6')]=function(_0x2e5fe9,_0x2b8fda){return db['MailInteraction'][_0x63f3('0x74')]({'where':{'id':_0x2e5fe9[_0x63f3('0xc0')]['id']}})[_0x63f3('0x2b')](handleEntityNotFound(_0x2b8fda,null))['then'](removeEntity(_0x2b8fda,null))[_0x63f3('0x39')](handleError(_0x2b8fda,null));};exports[_0x63f3('0xc7')]=function(_0x5d77fb,_0x21e70f){return db[_0x63f3('0x35')]['describe']()['then'](respondWithResult(_0x21e70f,null))[_0x63f3('0x39')](handleError(_0x21e70f,null));};exports['addMessage']=function(_0x1d1ed0,_0x467d05,_0x3a3ed2){return db[_0x63f3('0xc8')][_0x63f3('0x74')]({'where':{'id':_0x1d1ed0['params']['id']}})[_0x63f3('0x2b')](handleEntityNotFound(_0x467d05,null))[_0x63f3('0x2b')](function(_0x1351ec){if(_0x1351ec){return _0x1351ec[_0x63f3('0xc9')](_0x1d1ed0['body'][_0x63f3('0xca')],_[_0x63f3('0xcb')](_0x1d1ed0[_0x63f3('0xc5')],[_0x63f3('0xca'),'id'])||{});}})[_0x63f3('0x2b')](respondWithResult(_0x467d05,null))[_0x63f3('0x39')](handleError(_0x467d05,null));};exports[_0x63f3('0xcc')]=function(_0x4e907a,_0x5ef2a8,_0x4c4983){var _0x21cd85={'raw':![],'where':{}};var _0x3cf5f7={};var _0x1d2a98={'count':0x0,'rows':[]};return db['MailInteraction'][_0x63f3('0x36')]({'where':{'id':_0x4e907a[_0x63f3('0xc0')]['id']}})[_0x63f3('0x2b')](handleEntityNotFound(_0x5ef2a8,null))['then'](function(_0x19df14){if(_0x19df14){_0x3cf5f7['model']=_[_0x63f3('0x41')](db[_0x63f3('0xc8')][_0x63f3('0x3b')]);_0x3cf5f7[_0x63f3('0x40')]=_[_0x63f3('0x41')](_0x4e907a[_0x63f3('0x40')]);_0x3cf5f7['filters']=_['intersection'](_0x3cf5f7[_0x63f3('0x3f')],_0x3cf5f7[_0x63f3('0x40')]);_0x21cd85['attributes']=_[_0x63f3('0x43')](_0x3cf5f7[_0x63f3('0x3f')],qs[_0x63f3('0x44')](_0x4e907a[_0x63f3('0x40')][_0x63f3('0x44')]));_0x21cd85[_0x63f3('0x45')]=_0x21cd85[_0x63f3('0x45')]['length']?_0x21cd85[_0x63f3('0x45')]:_0x3cf5f7[_0x63f3('0x3f')];if(!_0x4e907a[_0x63f3('0x40')][_0x63f3('0x47')](_0x63f3('0x48'))){_0x21cd85[_0x63f3('0x24')]=qs[_0x63f3('0x24')](_0x4e907a[_0x63f3('0x40')][_0x63f3('0x24')]);_0x21cd85[_0x63f3('0x23')]=qs['offset'](_0x4e907a[_0x63f3('0x40')][_0x63f3('0x23')]);}_0x21cd85[_0x63f3('0x49')]=qs['sort'](_0x4e907a[_0x63f3('0x40')]['sort']);_0x21cd85[_0x63f3('0x4b')]=qs['filters'](_[_0x63f3('0x4c')](_0x4e907a[_0x63f3('0x40')],_0x3cf5f7[_0x63f3('0x42')]));_0x21cd85['where'][_0x63f3('0xba')]=_0x19df14['id'];if(_0x4e907a['query'][_0x63f3('0x84')]){_0x21cd85[_0x63f3('0x4b')]=_[_0x63f3('0x98')](_0x21cd85['where'],{'$or':_[_0x63f3('0x31')](_0x21cd85[_0x63f3('0x45')],function(_0x43688a){var _0x23b421={};_0x23b421[_0x43688a]={'$like':'%'+_0x4e907a['query']['filter']+'%'};return _0x23b421;})});}if(_0x4e907a[_0x63f3('0x40')][_0x63f3('0x7b')]){var _0x3479a1=_0x4e907a[_0x63f3('0x40')][_0x63f3('0x7b')]['split'](',');var _0x111526={};_0x111526[_0x3479a1[0x0]]={'$gte':moment(_0x3479a1[0x1])['format']('YYYY-MM-DD\x20HH:mm:ss')};_0x21cd85[_0x63f3('0x4b')]=_[_0x63f3('0x98')](_0x21cd85['where'],_0x111526);}_0x21cd85=_[_0x63f3('0x98')]({},_0x21cd85,_0x4e907a['options']);return db[_0x63f3('0xc8')][_0x63f3('0x22')]({'where':_0x21cd85['where']})[_0x63f3('0x2b')](function(_0x442df5){_0x1d2a98[_0x63f3('0x22')]=_0x442df5;if(_0x4e907a[_0x63f3('0x40')][_0x63f3('0xc1')]){_0x21cd85[_0x63f3('0xc2')]=[{'all':!![]}];}return db[_0x63f3('0xc8')][_0x63f3('0xcd')](_0x21cd85);})['then'](function(_0x32a228){_0x1d2a98[_0x63f3('0xbf')]=_0x32a228;return _0x1d2a98;});}})[_0x63f3('0x2b')](respondWithFilteredResult(_0x5ef2a8,_0x21cd85))['catch'](handleError(_0x5ef2a8,null));};exports[_0x63f3('0xce')]=function(_0x4e2a12,_0x8484,_0x36a20f){return db[_0x63f3('0x35')][_0x63f3('0x74')]({'where':{'id':_0x4e2a12['params']['id']}})[_0x63f3('0x2b')](handleEntityNotFound(_0x8484,null))[_0x63f3('0x2b')](function(_0x2693e3){if(_0x2693e3){return _0x2693e3['setTags'](_0x4e2a12[_0x63f3('0xc5')][_0x63f3('0xca')],_[_0x63f3('0xcb')](_0x4e2a12['body'],['ids','id'])||{})[_0x63f3('0xcf')](function(){return db[_0x63f3('0x70')][_0x63f3('0xcd')]({'attributes':['id',_0x63f3('0x2e'),_0x63f3('0xd0')],'where':{'id':_0x4e2a12['body'][_0x63f3('0xca')]}});})[_0x63f3('0x2b')](function(_0x38ab6f){socket[_0x63f3('0xd1')](_0x63f3('0xd2'),{'id':Number(_0x4e2a12[_0x63f3('0xc0')]['id']),'tags':_0x38ab6f||[]});return{'id':Number(_0x4e2a12[_0x63f3('0xc0')]['id']),'tags':_0x38ab6f||[]};});}})[_0x63f3('0x2b')](respondWithResult(_0x8484,null))['catch'](handleError(_0x8484,null));};exports[_0x63f3('0xd3')]=function(_0x297f1f,_0x27be25,_0x53c2a7){return db[_0x63f3('0x35')][_0x63f3('0x74')]({'where':{'id':_0x297f1f[_0x63f3('0xc0')]['id']}})['then'](handleEntityNotFound(_0x27be25,null))['then'](function(_0x19a809){if(_0x19a809){return _0x19a809[_0x63f3('0xd3')](_0x297f1f[_0x63f3('0x40')][_0x63f3('0xca')]);}})[_0x63f3('0x2b')](respondWithStatusCode(_0x27be25,null))['catch'](handleError(_0x27be25,null));};exports[_0x63f3('0xd4')]=function(_0x44c670,_0x3b7f54){var _0x42921c=moment()[_0x63f3('0xd5')]()['toString']();var _0x11446c=path[_0x63f3('0xd6')](config[_0x63f3('0xd7')],'server',_0x63f3('0xd8'),_0x63f3('0xd9'));var _0x5317aa=path['join'](config[_0x63f3('0xd7')],_0x63f3('0xda'),_0x63f3('0xd8'),_0x63f3('0xdb'));var _0x19eca8=path['join'](_0x11446c,_0x42921c);var _0x57233c=util[_0x63f3('0xdc')](_0x63f3('0xdd'),_0x44c670[_0x63f3('0xc0')]['id'],_0x42921c);var _0x3deefe=path[_0x63f3('0xd6')](_0x11446c,_0x57233c);var _0x4eaf4a=[];if(_0x44c670[_0x63f3('0x40')][_0x63f3('0xdb')]){_0x4eaf4a[_0x63f3('0xbd')]({'model':db[_0x63f3('0xde')],'as':_0x63f3('0xdf'),'raw':!![]});}var _0xb9a51c=[{'model':db['MailMessage'],'as':_0x63f3('0xe0'),'attributes':['id',_0x63f3('0xc5'),_0x63f3('0x51'),'to','cc',_0x63f3('0xe1'),_0x63f3('0xe2'),_0x63f3('0xe3')],'where':{'secret':![]},'order':qs[_0x63f3('0x4a')]('id'),'include':_0x4eaf4a}];return db[_0x63f3('0x35')][_0x63f3('0x74')]({'where':{'id':_0x44c670[_0x63f3('0xc0')]['id']},'include':_0xb9a51c})[_0x63f3('0x2b')](handleEntityNotFound(_0x3b7f54,null))[_0x63f3('0x2b')](function(_0x3a5e96){if(_0x3a5e96&&_0x3a5e96['Messages']){var _0x57ff3e=_0x3a5e96[_0x63f3('0xe4')]({'plain':!![]});fs[_0x63f3('0xe5')](_0x19eca8);return BPromise['each'](_0x57ff3e[_0x63f3('0xe0')],function(_0x4b1709,_0x165866){var _0x2dea2a={'from':_0x4b1709[_0x63f3('0x51')],'to':_0x4b1709['to'],'subject':_0x4b1709[_0x63f3('0xe2')],'html':_0x4b1709[_0x63f3('0xc5')],'headers':{'Date':moment(_0x4b1709[_0x63f3('0xe3')])[_0x63f3('0xdc')](_0x63f3('0xe6'))},'attachments':[]};if(_0x4b1709['cc']){_0x2dea2a[_0x63f3('0xe7')]['Cc']=_0x4b1709['cc'];}if(_0x4b1709[_0x63f3('0xe1')]){_0x2dea2a[_0x63f3('0xe7')][_0x63f3('0xe8')]=_0x4b1709[_0x63f3('0xe1')];}return new BPromise(function(_0x1f9a07,_0x1fff8c){if(_0x4b1709[_0x63f3('0xdf')]){for(var _0x2ef443=0x0;_0x2ef443<_0x4b1709[_0x63f3('0xdf')][_0x63f3('0x46')];_0x2ef443++){var _0x234499=_0x4b1709[_0x63f3('0xdf')][_0x2ef443];var _0x4be5ba=path[_0x63f3('0xd6')](_0x5317aa,_0x234499[_0x63f3('0xe9')]);if(fs[_0x63f3('0xea')](_0x4be5ba)){_0x2dea2a[_0x63f3('0xdb')][_0x63f3('0xbd')]({'name':_0x234499['name'],'contentType':_0x234499[_0x63f3('0x3d')],'data':fs['readFileSync'](_0x4be5ba)});}}}emlformat['build'](_0x2dea2a,function(_0x1a42bb,_0x738fc7){if(_0x1a42bb)return _0x1fff8c(_0x1a42bb);fs[_0x63f3('0xeb')](path['join'](_0x19eca8,util[_0x63f3('0xdc')](_0x63f3('0xec'),_0x165866)),_0x738fc7);return _0x1f9a07(_0x738fc7);});});})[_0x63f3('0x2b')](function(){return new BPromise(function(_0x130249,_0x48e27b){zipdir(_0x19eca8,{'saveTo':_0x3deefe},function(_0x4c4c02,_0x6c0418){if(_0x4c4c02)return _0x48e27b(_0x4c4c02);return _0x130249(_0x6c0418);});})['then'](function(){return new BPromise(function(_0xf152af,_0x508422){rimraf(_0x19eca8,function(_0x222e37){if(_0x222e37)_0x508422(_0x222e37);return _0xf152af();});});})[_0x63f3('0x2b')](function(){return _0x3b7f54[_0x63f3('0xd4')](_0x3deefe,_0x57233c,function(_0x393a40){if(_0x393a40){console[_0x63f3('0xed')](_0x63f3('0xee'),_0x393a40);}else{fs['unlinkSync'](_0x3deefe);}});});});}else{return _0x3b7f54[_0x63f3('0x1f')](0xc8);}})['catch'](handleError(_0x3b7f54,null));};
\ No newline at end of file
+var _0xe9b9=['../../mysqldb','redis','defaults','localhost','socket.io-emitter','./mailInteraction.socket','status','json','undefined','count','offset','limit','set','Content-Range','update','then','destroy','end','sendStatus','error','stack','name','send','index','rawAttributes','fieldName','key','getOptions','findAll','mail','user','catch','params','model','keys','MailInteraction','query','filters','intersection','attributes','fields','length','include','find','create','body','describe','addMessage','ids','omit','getMessages','findOne','MailMessage','hasOwnProperty','nolimit','order','sort','where','MailInteractionId','filter','merge','$gte','split','YYYY-MM-DD\x20HH:mm:ss','options','includeAll','inlineCss','true','rows','addTags','spread','Tag','emit','removeTags','unix','toString','join','root','files','tmp','server','attachments','push','Attachment','Attachments','subject','createdAt','Messages','get','each','format','ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ','headers','bcc','Bcc','basename','existsSync','writeFileSync','message%d.eml','download','unlinkSync','eml-format','rimraf','zip-dir','moment','bluebird','util','path','juice','../../components/parsers/qs','../../config/logger'];(function(_0x5d2af3,_0x5f0ed4){var _0x2bc29e=function(_0x357474){while(--_0x357474){_0x5d2af3['push'](_0x5d2af3['shift']());}};_0x2bc29e(++_0x5f0ed4);}(_0xe9b9,0xd4));var _0x9e9b=function(_0x13d0be,_0x4ec269){_0x13d0be=_0x13d0be-0x0;var _0x23035d=_0xe9b9[_0x13d0be];return _0x23035d;};'use strict';var emlformat=require(_0x9e9b('0x0'));var rimraf=require(_0x9e9b('0x1'));var zipdir=require(_0x9e9b('0x2'));var moment=require(_0x9e9b('0x3'));var BPromise=require(_0x9e9b('0x4'));var util=require(_0x9e9b('0x5'));var path=require(_0x9e9b('0x6'));var fs=require('fs');var _=require('lodash');var juice=require(_0x9e9b('0x7'));var Redis=require('ioredis');var interaction=require('../../components/interaction/service');var qs=require(_0x9e9b('0x8'));var logger=require(_0x9e9b('0x9'))('api');var config=require('../../config/environment');var db=require(_0x9e9b('0xa'))['db'];var htmlEntities=require('html-entities');config[_0x9e9b('0xb')]=_[_0x9e9b('0xc')](config['redis'],{'host':_0x9e9b('0xd'),'port':0x18eb});var socket=require(_0x9e9b('0xe'))(new Redis(config[_0x9e9b('0xb')]));require(_0x9e9b('0xf'))['register'](socket);function respondWithStatusCode(_0x54e13f,_0x46fa6e){_0x46fa6e=_0x46fa6e||0xcc;return function(_0x437bc1){if(_0x437bc1){return _0x54e13f['sendStatus'](_0x46fa6e);}return _0x54e13f[_0x9e9b('0x10')](_0x46fa6e)['end']();};}function respondWithResult(_0x357259,_0x5d7faa){_0x5d7faa=_0x5d7faa||0xc8;return function(_0x5a43ba){if(_0x5a43ba){return _0x357259[_0x9e9b('0x10')](_0x5d7faa)[_0x9e9b('0x11')](_0x5a43ba);}};}function respondWithFilteredResult(_0x20df67,_0x79b14c){return function(_0x28f91b){if(_0x28f91b){var _0x3b5b11=typeof _0x79b14c['offset']===_0x9e9b('0x12')&&typeof _0x79b14c['limit']==='undefined';var _0x3b4273=_0x28f91b[_0x9e9b('0x13')];var _0x429b61=_0x3b5b11?0x0:_0x79b14c[_0x9e9b('0x14')];var _0x3a0f10=_0x3b5b11?_0x28f91b[_0x9e9b('0x13')]:_0x79b14c[_0x9e9b('0x14')]+_0x79b14c[_0x9e9b('0x15')];var _0x35b933;if(_0x3a0f10>=_0x3b4273){_0x3a0f10=_0x3b4273;_0x35b933=0xc8;}else{_0x35b933=0xce;}_0x20df67[_0x9e9b('0x10')](_0x35b933);return _0x20df67[_0x9e9b('0x16')](_0x9e9b('0x17'),_0x429b61+'-'+_0x3a0f10+'/'+_0x3b4273)['json'](_0x28f91b);}return null;};}function saveUpdates(_0xaaebc1){return function(_0x5a0f38){if(_0x5a0f38){return _0x5a0f38[_0x9e9b('0x18')](_0xaaebc1)[_0x9e9b('0x19')](function(_0x7d58a){return _0x7d58a;});}return null;};}function removeEntity(_0x11ea58){return function(_0x5b27b9){if(_0x5b27b9){return _0x5b27b9[_0x9e9b('0x1a')]()['then'](function(){_0x11ea58[_0x9e9b('0x10')](0xcc)[_0x9e9b('0x1b')]();});}};}function handleEntityNotFound(_0x3f09ca){return function(_0x2c77cd){if(!_0x2c77cd){_0x3f09ca[_0x9e9b('0x1c')](0x194);}return _0x2c77cd;};}function handleError(_0x39704c,_0x56be5f){_0x56be5f=_0x56be5f||0x1f4;return function(_0xc7b149){logger[_0x9e9b('0x1d')](_0xc7b149[_0x9e9b('0x1e')]);if(_0xc7b149[_0x9e9b('0x1f')]){delete _0xc7b149[_0x9e9b('0x1f')];}_0x39704c['status'](_0x56be5f)[_0x9e9b('0x20')](_0xc7b149);};}exports[_0x9e9b('0x21')]=function(_0x553969,_0x2f3356){var _0x40fabc={};var _0x124633=_['map'](db['MailInteraction'][_0x9e9b('0x22')],function(_0x52e4e9){return{'name':_0x52e4e9[_0x9e9b('0x23')],'type':_0x52e4e9['type'][_0x9e9b('0x24')]};});_0x40fabc=qs[_0x9e9b('0x25')](_0x124633,_0x553969);return interaction[_0x9e9b('0x26')](_0x9e9b('0x27'),_0x553969['query'],_0x553969[_0x9e9b('0x28')],_0x40fabc,_0x124633)[_0x9e9b('0x19')](respondWithFilteredResult(_0x2f3356,_0x40fabc))[_0x9e9b('0x29')](handleError(_0x2f3356,null));};exports['show']=function(_0x4f5efc,_0x4b0556){var _0x115e9e={'raw':![],'where':{'id':_0x4f5efc[_0x9e9b('0x2a')]['id']}},_0x2c4f6f={};_0x2c4f6f[_0x9e9b('0x2b')]=_[_0x9e9b('0x2c')](db[_0x9e9b('0x2d')][_0x9e9b('0x22')]);_0x2c4f6f[_0x9e9b('0x2e')]=_[_0x9e9b('0x2c')](_0x4f5efc['query']);_0x2c4f6f[_0x9e9b('0x2f')]=_[_0x9e9b('0x30')](_0x2c4f6f[_0x9e9b('0x2b')],_0x2c4f6f[_0x9e9b('0x2e')]);_0x115e9e[_0x9e9b('0x31')]=_[_0x9e9b('0x30')](_0x2c4f6f['model'],qs[_0x9e9b('0x32')](_0x4f5efc[_0x9e9b('0x2e')][_0x9e9b('0x32')]));_0x115e9e['attributes']=_0x115e9e[_0x9e9b('0x31')][_0x9e9b('0x33')]?_0x115e9e[_0x9e9b('0x31')]:_0x2c4f6f['model'];if(_0x4f5efc['query']['includeAll']){_0x115e9e[_0x9e9b('0x34')]=[{'all':!![]}];}_0x115e9e=_['merge']({},_0x115e9e,_0x4f5efc['options']);return db['MailInteraction'][_0x9e9b('0x35')](_0x115e9e)[_0x9e9b('0x19')](handleEntityNotFound(_0x4b0556,null))[_0x9e9b('0x19')](respondWithResult(_0x4b0556,null))[_0x9e9b('0x29')](handleError(_0x4b0556,null));};exports[_0x9e9b('0x36')]=function(_0x4bdfa4,_0x727c66){return db[_0x9e9b('0x2d')][_0x9e9b('0x36')](_0x4bdfa4[_0x9e9b('0x37')],{})[_0x9e9b('0x19')](respondWithResult(_0x727c66,0xc9))['catch'](handleError(_0x727c66,null));};exports['update']=function(_0x597e74,_0x2b50cf){if(_0x597e74['body']['id']){delete _0x597e74[_0x9e9b('0x37')]['id'];}return db[_0x9e9b('0x2d')]['find']({'where':{'id':_0x597e74['params']['id']}})[_0x9e9b('0x19')](handleEntityNotFound(_0x2b50cf,null))['then'](saveUpdates(_0x597e74[_0x9e9b('0x37')],null))[_0x9e9b('0x19')](respondWithResult(_0x2b50cf,null))[_0x9e9b('0x29')](handleError(_0x2b50cf,null));};exports[_0x9e9b('0x1a')]=function(_0xfb98eb,_0xa8ffd0){return db[_0x9e9b('0x2d')][_0x9e9b('0x35')]({'where':{'id':_0xfb98eb[_0x9e9b('0x2a')]['id']}})[_0x9e9b('0x19')](handleEntityNotFound(_0xa8ffd0,null))[_0x9e9b('0x19')](removeEntity(_0xa8ffd0,null))[_0x9e9b('0x29')](handleError(_0xa8ffd0,null));};exports[_0x9e9b('0x38')]=function(_0x56539a,_0x8f1b4d){return db[_0x9e9b('0x2d')][_0x9e9b('0x38')]()[_0x9e9b('0x19')](respondWithResult(_0x8f1b4d,null))[_0x9e9b('0x29')](handleError(_0x8f1b4d,null));};exports[_0x9e9b('0x39')]=function(_0x68235e,_0x2d03b5){return db['MailMessage'][_0x9e9b('0x35')]({'where':{'id':_0x68235e[_0x9e9b('0x2a')]['id']}})[_0x9e9b('0x19')](handleEntityNotFound(_0x2d03b5,null))['then'](function(_0x519af6){if(_0x519af6){return _0x519af6['addMessage'](_0x68235e[_0x9e9b('0x37')][_0x9e9b('0x3a')],_[_0x9e9b('0x3b')](_0x68235e[_0x9e9b('0x37')],[_0x9e9b('0x3a'),'id'])||{});}})[_0x9e9b('0x19')](respondWithResult(_0x2d03b5,null))[_0x9e9b('0x29')](handleError(_0x2d03b5,null));};exports[_0x9e9b('0x3c')]=function(_0x2e8fdf,_0x8b4b17){var _0xb13916={'raw':![],'where':{}};var _0x5ace90={};var _0x42d1b7={'count':0x0,'rows':[]};return db['MailInteraction'][_0x9e9b('0x3d')]({'where':{'id':_0x2e8fdf[_0x9e9b('0x2a')]['id']}})[_0x9e9b('0x19')](handleEntityNotFound(_0x8b4b17,null))[_0x9e9b('0x19')](function(_0x4c1f40){if(_0x4c1f40){_0x5ace90[_0x9e9b('0x2b')]=_[_0x9e9b('0x2c')](db[_0x9e9b('0x3e')]['rawAttributes']);_0x5ace90[_0x9e9b('0x2e')]=_[_0x9e9b('0x2c')](_0x2e8fdf[_0x9e9b('0x2e')]);_0x5ace90['filters']=_[_0x9e9b('0x30')](_0x5ace90[_0x9e9b('0x2b')],_0x5ace90[_0x9e9b('0x2e')]);_0xb13916[_0x9e9b('0x31')]=_[_0x9e9b('0x30')](_0x5ace90['model'],qs[_0x9e9b('0x32')](_0x2e8fdf['query'][_0x9e9b('0x32')]));_0xb13916[_0x9e9b('0x31')]=_0xb13916['attributes'][_0x9e9b('0x33')]?_0xb13916[_0x9e9b('0x31')]:_0x5ace90[_0x9e9b('0x2b')];if(!_0x2e8fdf[_0x9e9b('0x2e')][_0x9e9b('0x3f')](_0x9e9b('0x40'))){_0xb13916[_0x9e9b('0x15')]=qs[_0x9e9b('0x15')](_0x2e8fdf[_0x9e9b('0x2e')]['limit']);_0xb13916[_0x9e9b('0x14')]=qs[_0x9e9b('0x14')](_0x2e8fdf[_0x9e9b('0x2e')][_0x9e9b('0x14')]);}_0xb13916[_0x9e9b('0x41')]=qs[_0x9e9b('0x42')](_0x2e8fdf[_0x9e9b('0x2e')][_0x9e9b('0x42')]);_0xb13916['where']=qs['filters'](_['pick'](_0x2e8fdf[_0x9e9b('0x2e')],_0x5ace90[_0x9e9b('0x2f')]));_0xb13916[_0x9e9b('0x43')][_0x9e9b('0x44')]=_0x4c1f40['id'];if(_0x2e8fdf[_0x9e9b('0x2e')][_0x9e9b('0x45')]){_0xb13916[_0x9e9b('0x43')]=_[_0x9e9b('0x46')](_0xb13916[_0x9e9b('0x43')],{'$or':_['map'](_0xb13916[_0x9e9b('0x31')],function(_0x52566b){var _0x1fcc2b={};_0x1fcc2b[_0x52566b]={'$like':'%'+_0x2e8fdf[_0x9e9b('0x2e')][_0x9e9b('0x45')]+'%'};return _0x1fcc2b;})});}if(_0x2e8fdf[_0x9e9b('0x2e')][_0x9e9b('0x47')]){var _0x5894c1=_0x2e8fdf['query']['$gte'][_0x9e9b('0x48')](',');var _0x4063f1={};_0x4063f1[_0x5894c1[0x0]]={'$gte':moment(_0x5894c1[0x1])['format'](_0x9e9b('0x49'))};_0xb13916[_0x9e9b('0x43')]=_[_0x9e9b('0x46')](_0xb13916[_0x9e9b('0x43')],_0x4063f1);}_0xb13916=_[_0x9e9b('0x46')]({},_0xb13916,_0x2e8fdf[_0x9e9b('0x4a')]);return db['MailMessage'][_0x9e9b('0x13')]({'where':_0xb13916[_0x9e9b('0x43')]})[_0x9e9b('0x19')](function(_0x291db3){_0x42d1b7[_0x9e9b('0x13')]=_0x291db3;if(_0x2e8fdf[_0x9e9b('0x2e')][_0x9e9b('0x4b')]){_0xb13916[_0x9e9b('0x34')]=[{'all':!![]}];}return db[_0x9e9b('0x3e')][_0x9e9b('0x26')](_0xb13916);})[_0x9e9b('0x19')](function(_0xb29cf6){if(_0x2e8fdf[_0x9e9b('0x2e')][_0x9e9b('0x4c')]===_0x9e9b('0x4d')){for(var _0x578320=0x0;_0x578320<_0xb29cf6[_0x9e9b('0x33')];_0x578320++){_0xb29cf6[_0x578320][_0x9e9b('0x37')]=juice(_0xb29cf6[_0x578320][_0x9e9b('0x37')]);}}_0x42d1b7[_0x9e9b('0x4e')]=_0xb29cf6;return _0x42d1b7;});}})[_0x9e9b('0x19')](respondWithFilteredResult(_0x8b4b17,_0xb13916))['catch'](handleError(_0x8b4b17,null));};exports[_0x9e9b('0x4f')]=function(_0x20aab5,_0xe58f5c){return db[_0x9e9b('0x2d')]['find']({'where':{'id':_0x20aab5[_0x9e9b('0x2a')]['id']}})[_0x9e9b('0x19')](handleEntityNotFound(_0xe58f5c,null))['then'](function(_0x165f81){if(_0x165f81){return _0x165f81['setTags'](_0x20aab5[_0x9e9b('0x37')][_0x9e9b('0x3a')],_[_0x9e9b('0x3b')](_0x20aab5[_0x9e9b('0x37')],[_0x9e9b('0x3a'),'id'])||{})[_0x9e9b('0x50')](function(){return db[_0x9e9b('0x51')][_0x9e9b('0x26')]({'attributes':['id',_0x9e9b('0x1f'),'color'],'where':{'id':_0x20aab5[_0x9e9b('0x37')][_0x9e9b('0x3a')]}});})[_0x9e9b('0x19')](function(_0xe318f){socket[_0x9e9b('0x52')]('mailInteractionTags:save',{'id':Number(_0x20aab5[_0x9e9b('0x2a')]['id']),'tags':_0xe318f||[]});return{'id':Number(_0x20aab5[_0x9e9b('0x2a')]['id']),'tags':_0xe318f||[]};});}})['then'](respondWithResult(_0xe58f5c,null))['catch'](handleError(_0xe58f5c,null));};exports[_0x9e9b('0x53')]=function(_0x25fac8,_0x4cb23c){return db[_0x9e9b('0x2d')][_0x9e9b('0x35')]({'where':{'id':_0x25fac8['params']['id']}})[_0x9e9b('0x19')](handleEntityNotFound(_0x4cb23c,null))[_0x9e9b('0x19')](function(_0x1fa32b){if(_0x1fa32b){return _0x1fa32b[_0x9e9b('0x53')](_0x25fac8[_0x9e9b('0x2e')]['ids']);}})[_0x9e9b('0x19')](respondWithStatusCode(_0x4cb23c,null))['catch'](handleError(_0x4cb23c,null));};exports['download']=function(_0x3f4f92,_0x17ff59){var _0x12bdf6=moment()[_0x9e9b('0x54')]()[_0x9e9b('0x55')]();var _0x34047d=path[_0x9e9b('0x56')](config[_0x9e9b('0x57')],'server',_0x9e9b('0x58'),_0x9e9b('0x59'));var _0x541ff6=path[_0x9e9b('0x56')](config[_0x9e9b('0x57')],_0x9e9b('0x5a'),_0x9e9b('0x58'),_0x9e9b('0x5b'));var _0x40a464=path['join'](_0x34047d,_0x12bdf6);var _0x304f61=util['format']('transcript-%d-%s.zip',_0x3f4f92['params']['id'],_0x12bdf6);var _0x1d7a72=path[_0x9e9b('0x56')](_0x34047d,_0x304f61);var _0x23c591=[];if(_0x3f4f92[_0x9e9b('0x2e')][_0x9e9b('0x5b')]){_0x23c591[_0x9e9b('0x5c')]({'model':db[_0x9e9b('0x5d')],'as':_0x9e9b('0x5e'),'raw':!![]});}var _0x39b05c=[{'model':db[_0x9e9b('0x3e')],'as':'Messages','attributes':['id',_0x9e9b('0x37'),'from','to','cc','bcc',_0x9e9b('0x5f'),_0x9e9b('0x60')],'where':{'secret':![]},'order':qs[_0x9e9b('0x42')]('id'),'include':_0x23c591}];return db[_0x9e9b('0x2d')][_0x9e9b('0x35')]({'where':{'id':_0x3f4f92[_0x9e9b('0x2a')]['id']},'include':_0x39b05c})['then'](handleEntityNotFound(_0x17ff59,null))['then'](function(_0xefa082){if(_0xefa082&&_0xefa082[_0x9e9b('0x61')]){var _0x293779=_0xefa082[_0x9e9b('0x62')]({'plain':!![]});fs['mkdirSync'](_0x40a464);return BPromise[_0x9e9b('0x63')](_0x293779[_0x9e9b('0x61')],function(_0x47a4a9,_0x5100e9){var _0x971366={'from':_0x47a4a9['from'],'to':_0x47a4a9['to'],'subject':_0x47a4a9['subject'],'html':htmlEntities['decode'](_0x47a4a9[_0x9e9b('0x37')]),'headers':{'Date':moment(_0x47a4a9[_0x9e9b('0x60')])[_0x9e9b('0x64')](_0x9e9b('0x65'))},'attachments':[]};if(_0x47a4a9['cc']){_0x971366[_0x9e9b('0x66')]['Cc']=_0x47a4a9['cc'];}if(_0x47a4a9[_0x9e9b('0x67')]){_0x971366[_0x9e9b('0x66')][_0x9e9b('0x68')]=_0x47a4a9[_0x9e9b('0x67')];}return new BPromise(function(_0x452e56,_0x31b203){if(_0x47a4a9[_0x9e9b('0x5e')]){for(var _0x30acbe=0x0;_0x30acbe<_0x47a4a9[_0x9e9b('0x5e')]['length'];_0x30acbe++){var _0x16e815=_0x47a4a9[_0x9e9b('0x5e')][_0x30acbe];var _0x423d78=path[_0x9e9b('0x56')](_0x541ff6,_0x16e815[_0x9e9b('0x69')]);if(fs[_0x9e9b('0x6a')](_0x423d78)){_0x971366[_0x9e9b('0x5b')][_0x9e9b('0x5c')]({'name':_0x16e815[_0x9e9b('0x1f')],'contentType':_0x16e815['type'],'data':fs['readFileSync'](_0x423d78)});}}}emlformat['build'](_0x971366,function(_0x4cdc34,_0x197aa4){if(_0x4cdc34)return _0x31b203(_0x4cdc34);fs[_0x9e9b('0x6b')](path[_0x9e9b('0x56')](_0x40a464,util['format'](_0x9e9b('0x6c'),_0x5100e9)),_0x197aa4);return _0x452e56(_0x197aa4);});});})[_0x9e9b('0x19')](function(){return new BPromise(function(_0x5cc2a2,_0x365a3c){zipdir(_0x40a464,{'saveTo':_0x1d7a72},function(_0x37bacd,_0x2708a1){if(_0x37bacd)return _0x365a3c(_0x37bacd);return _0x5cc2a2(_0x2708a1);});})['then'](function(){return new BPromise(function(_0x540c42,_0x4922d8){rimraf(_0x40a464,function(_0x467e9c){if(_0x467e9c)_0x4922d8(_0x467e9c);return _0x540c42();});});})[_0x9e9b('0x19')](function(){return _0x17ff59[_0x9e9b('0x6d')](_0x1d7a72,_0x304f61,function(_0x32d111){if(!_0x32d111)fs[_0x9e9b('0x6e')](_0x1d7a72);});});});}else{return _0x17ff59[_0x9e9b('0x1c')](0xc8);}})[_0x9e9b('0x29')](handleError(_0x17ff59,null));};
\ No newline at end of file