Built motion from commit da617fac.|2.6.6
[motion2.git] / server / api / mailInteraction / mailInteraction.controller.js
index c1b5376..baa8fd3 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xfc17=['set','update','then','destroy','error','stack','name','send','fullname','TagIds','Tags','split','push','findOne','out','plainBody','-id','lastMsgText','trimStart','catch','waiting','talking','answered','unmanaged','UserId','closed','total','index','map','MailInteraction','fieldName','type','key','query','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','filters','pick','select','field','color','from','u.id','u.fullname','ui.MailInteractionId','user_has_mail_interactions','left_join','u.id\x20=\x20ui.UserId','mail_interactions','cm_contacts','o.id\x20=\x20i.UserId','mail_accounts','a.id\x20=\x20i.MailAccountId','mail_messages','me.MailInteractionId\x20=\x20i.id','mail_interaction_has_tags','it.MailInteractionId\x20=\x20i.id','tools_tags','expr','search','parseSearch','conditions','find','unreadMessages','value','having','`\x20>\x200','operator','$substring','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?','buildExpression','text','start','Tag','forEach','User','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','keys','compact','isEmpty','MailAccountId','i.MailAccountId\x20IN\x20?','concat','createdAt','parse','$lte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','\x20IS\x20NULL','\x20=\x20?','read','`unreadMessages`\x20=\x200','`unreadMessages`\x20>\x200','tag','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','filter','replace','isNumeric','i.id\x20LIKE\x20?','c.email\x20LIKE\x20?','getFullTextValue','group','i.id','Sequelize','SELECT','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','contactName','DESC','i.MailAccountId\x20IS\x20NOT\x20NULL','user','getMailAccounts','i.MailAccountId\x20IS\x20NULL','role','agent','sequelize','toString','merge','a.key','a.mandatoryDisposition','Account.mandatoryDisposition','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','i.createdAt','i.updatedAt','i.closed','i.lastMsgAt','i.subject','i.disposition','i.secondDisposition','i.substatus','i.ContactId','i.MailAccountId','c.firstName','Contact.firstName','Contact.lastName','c.email','c.phone','c.mobile','c.fax','o.fullname','Owner.fullname','o.internal','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','ui.MailInteractionId\x20IN\x20?','groupBy','MailInteractionId','Setting','enableEmailPreview','rows','show','includeAll','include','body','params','describe','addMessage','ids','rawAttributes','$gte','format','YYYY-MM-DD\x20HH:mm:ss','options','findAll','inlineCss','addTags','setTags','spread','emit','mailInteractionTags:save','removeTags','download','unix','join','root','server','files','attachments','transcript-%d-%s.zip','Attachment','Attachments','MailMessage','bcc','subject','Messages','get','mkdirSync','each','decode','ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ','headers','basename','existsSync','readFileSync','build','writeFileSync','message%d.eml','eml-format','rimraf','zip-dir','moment','util','path','lodash','squel','juice','ioredis','../../components/parsers/advancedSearch','../../config/logger','api','../../config/environment','../../mysqldb','html-entities','redis','localhost','socket.io-emitter','./mailInteraction.socket','sendStatus','status','end','json','offset','undefined','limit','count'];(function(_0x2ea41,_0x4f807b){var _0x8ee23b=function(_0x2e5fd8){while(--_0x2e5fd8){_0x2ea41['push'](_0x2ea41['shift']());}};_0x8ee23b(++_0x4f807b);}(_0xfc17,0x1b4));var _0x7fc1=function(_0x14c959,_0x298598){_0x14c959=_0x14c959-0x0;var _0x371779=_0xfc17[_0x14c959];return _0x371779;};'use strict';var emlformat=require(_0x7fc1('0x0'));var rimraf=require(_0x7fc1('0x1'));var zipdir=require(_0x7fc1('0x2'));var moment=require(_0x7fc1('0x3'));var BPromise=require('bluebird');var util=require(_0x7fc1('0x4'));var path=require(_0x7fc1('0x5'));var fs=require('fs');var _=require(_0x7fc1('0x6'));var squel=require(_0x7fc1('0x7'));var juice=require(_0x7fc1('0x8'));var Redis=require(_0x7fc1('0x9'));var qs=require('../../components/parsers/qs');var as=require(_0x7fc1('0xa'));var logger=require(_0x7fc1('0xb'))(_0x7fc1('0xc'));var config=require(_0x7fc1('0xd'));var db=require(_0x7fc1('0xe'))['db'];var htmlEntities=require(_0x7fc1('0xf'));config[_0x7fc1('0x10')]=_['defaults'](config[_0x7fc1('0x10')],{'host':_0x7fc1('0x11'),'port':0x18eb});var socket=require(_0x7fc1('0x12'))(new Redis(config['redis']));require(_0x7fc1('0x13'))['register'](socket);function respondWithStatusCode(_0x5c59ad,_0x775538){_0x775538=_0x775538||0xcc;return function(_0xe06cb4){if(_0xe06cb4){return _0x5c59ad[_0x7fc1('0x14')](_0x775538);}return _0x5c59ad[_0x7fc1('0x15')](_0x775538)[_0x7fc1('0x16')]();};}function respondWithResult(_0x20ed58,_0x53277f){_0x53277f=_0x53277f||0xc8;return function(_0x3a7c8e){if(_0x3a7c8e){return _0x20ed58[_0x7fc1('0x15')](_0x53277f)[_0x7fc1('0x17')](_0x3a7c8e);}};}function respondWithFilteredResult(_0x12ddce,_0x3c328c){return function(_0x5651f2){if(_0x5651f2){var _0x54a204=typeof _0x3c328c[_0x7fc1('0x18')]===_0x7fc1('0x19')&&typeof _0x3c328c[_0x7fc1('0x1a')]===_0x7fc1('0x19');var _0x432825=_0x5651f2[_0x7fc1('0x1b')];var _0x3d8e82=_0x54a204?0x0:_0x3c328c[_0x7fc1('0x18')];var _0x18be8e=_0x54a204?_0x5651f2[_0x7fc1('0x1b')]:_0x3c328c['offset']+_0x3c328c[_0x7fc1('0x1a')];var _0x5e89b1;if(_0x18be8e>=_0x432825){_0x18be8e=_0x432825;_0x5e89b1=0xc8;}else{_0x5e89b1=0xce;}_0x12ddce[_0x7fc1('0x15')](_0x5e89b1);return _0x12ddce[_0x7fc1('0x1c')]('Content-Range',_0x3d8e82+'-'+_0x18be8e+'/'+_0x432825)[_0x7fc1('0x17')](_0x5651f2);}return null;};}function saveUpdates(_0x1c12cf){return function(_0x58c20a){if(_0x58c20a){return _0x58c20a[_0x7fc1('0x1d')](_0x1c12cf)[_0x7fc1('0x1e')](function(_0x1158f0){return _0x1158f0;});}return null;};}function removeEntity(_0x416748){return function(_0x10b4b7){if(_0x10b4b7){return _0x10b4b7[_0x7fc1('0x1f')]()[_0x7fc1('0x1e')](function(){_0x416748[_0x7fc1('0x15')](0xcc)[_0x7fc1('0x16')]();});}};}function handleEntityNotFound(_0xac99f6){return function(_0x4dea9c){if(!_0x4dea9c){_0xac99f6['sendStatus'](0x194);}return _0x4dea9c;};}function handleError(_0x2390b8,_0x5e10cd){_0x5e10cd=_0x5e10cd||0x1f4;return function(_0x3c39e2){logger[_0x7fc1('0x20')](_0x3c39e2[_0x7fc1('0x21')]);if(_0x3c39e2[_0x7fc1('0x22')]){delete _0x3c39e2['name'];}_0x2390b8[_0x7fc1('0x15')](_0x5e10cd)[_0x7fc1('0x23')](_0x3c39e2);};}function getInteractionUsers(_0x2cbf9b,_0x4d6c46){return new BPromise(function(_0x190204,_0x252b18){try{if(_0x4d6c46[_0x2cbf9b['id']]){_0x2cbf9b['Users']=_['map'](_0x4d6c46[_0x2cbf9b['id']],function(_0x2e4256){return{'id':_0x2e4256['id'],'fullname':_0x2e4256[_0x7fc1('0x24')]};});}}catch(_0x1f58ca){_0x252b18(_0x1f58ca);}_0x190204(_0x2cbf9b);});}function getInteractionTags(_0x2ae7db,_0x58c7a2){return new BPromise(function(_0x1d7b77,_0x1628fd){try{if(_0x2ae7db[_0x7fc1('0x25')]){_0x2ae7db[_0x7fc1('0x26')]=[];_0x2ae7db['TagIds'][_0x7fc1('0x27')](',')['forEach'](function(_0x1f7fce){_0x2ae7db[_0x7fc1('0x26')][_0x7fc1('0x28')](_0x58c7a2[_0x1f7fce]);});}delete _0x2ae7db[_0x7fc1('0x25')];}catch(_0x2317f5){_0x1628fd(_0x2317f5);}_0x1d7b77(_0x2ae7db);});}function getLastMessageText(_0x4cf06e){return new BPromise(function(_0x17be3a,_0x59a89a){return db['MailMessage'][_0x7fc1('0x29')]({'where':{'$and':[{'MailInteractionId':_0x4cf06e['id']},{'$or':[{'direction':'in'},{'$and':[{'direction':_0x7fc1('0x2a')},{'secret':![]},{'UserId':{'$ne':null}}]}]}]},'attributes':[_0x7fc1('0x2b')],'order':_0x7fc1('0x2c'),'raw':!![]})[_0x7fc1('0x1e')](function(_0x444b51){if(_0x444b51&&_0x444b51[_0x7fc1('0x2b')]){_0x4cf06e[_0x7fc1('0x2d')]=_[_0x7fc1('0x2e')](_0x444b51[_0x7fc1('0x2b')]);}_0x17be3a(_0x4cf06e);})[_0x7fc1('0x2f')](function(_0x2c95c8){_0x59a89a(_0x2c95c8);});});}function updateMailInteraction(_0x242fd1,_0x2c3ead,_0x211df6,_0x19064f){return new BPromise(function(_0x5e3f04,_0x24904b){return getInteractionUsers(_0x242fd1,_0x211df6)[_0x7fc1('0x1e')](function(_0x4282b5){return getInteractionTags(_0x4282b5,_0x2c3ead);})[_0x7fc1('0x1e')](function(_0x2c91cb){return getStateInteraction(_0x2c91cb);})[_0x7fc1('0x1e')](function(_0x5b96ea){if(_0x19064f){_0x5e3f04(getLastMessageText(_0x5b96ea));}else{_0x5e3f04(_0x5b96ea);}})[_0x7fc1('0x2f')](function(_0x3f8961){_0x24904b(_0x3f8961);});});}function getStateInteraction(_0x4f36c8){return new BPromise(function(_0x295268){_0x4f36c8[_0x7fc1('0x30')]=0x0;_0x4f36c8[_0x7fc1('0x31')]=0x0;_0x4f36c8[_0x7fc1('0x32')]=0x0;_0x4f36c8[_0x7fc1('0x33')]=0x0;_0x4f36c8['total']=0x0;if(!_0x4f36c8['closed']&&!_0x4f36c8[_0x7fc1('0x34')]){_0x4f36c8[_0x7fc1('0x30')]+=0x1;}if(!_0x4f36c8[_0x7fc1('0x35')]&&_0x4f36c8[_0x7fc1('0x34')]){_0x4f36c8[_0x7fc1('0x31')]+=0x1;if(_0x4f36c8[_0x7fc1('0x30')]){_0x4f36c8[_0x7fc1('0x30')]-=0x1;}}if(_0x4f36c8[_0x7fc1('0x35')]&&_0x4f36c8['UserId']){_0x4f36c8[_0x7fc1('0x32')]+=0x1;if(_0x4f36c8[_0x7fc1('0x31')]){_0x4f36c8['talking']-=0x1;}}if(_0x4f36c8[_0x7fc1('0x35')]&&!_0x4f36c8[_0x7fc1('0x34')]){_0x4f36c8[_0x7fc1('0x33')]+=0x1;if(_0x4f36c8['waiting']){_0x4f36c8['waiting']-=0x1;}}_0x4f36c8[_0x7fc1('0x36')]+=0x1;_0x295268(_0x4f36c8);});}exports[_0x7fc1('0x37')]=function(_0xafc8b0,_0x564437){var _0x4e640b={},_0x50c728={},_0x2fc293={'count':0x0,'rows':[]};var _0x1e4f53=_[_0x7fc1('0x38')](db[_0x7fc1('0x39')]['rawAttributes'],function(_0x548885){return{'name':_0x548885[_0x7fc1('0x3a')],'type':_0x548885[_0x7fc1('0x3b')][_0x7fc1('0x3c')]};});_0x50c728['model']=_['map'](_0x1e4f53,'name');_0x50c728['query']=_['keys'](_0xafc8b0[_0x7fc1('0x3d')]);_0x50c728['filters']=_[_0x7fc1('0x3e')](_0x50c728[_0x7fc1('0x3f')],_0x50c728['query']);_0x4e640b[_0x7fc1('0x40')]=_[_0x7fc1('0x3e')](_0x50c728[_0x7fc1('0x3f')],qs[_0x7fc1('0x41')](_0xafc8b0['query'][_0x7fc1('0x41')]));_0x4e640b['attributes']=_0x4e640b[_0x7fc1('0x40')][_0x7fc1('0x42')]?_0x4e640b[_0x7fc1('0x40')]:_0x50c728[_0x7fc1('0x3f')];if(!_0xafc8b0['query'][_0x7fc1('0x43')](_0x7fc1('0x44'))){_0x4e640b['limit']=qs[_0x7fc1('0x1a')](_0xafc8b0[_0x7fc1('0x3d')]['limit']);_0x4e640b[_0x7fc1('0x18')]=qs[_0x7fc1('0x18')](_0xafc8b0['query'][_0x7fc1('0x18')]);}_0x4e640b[_0x7fc1('0x45')]=qs[_0x7fc1('0x46')](_0xafc8b0['query'][_0x7fc1('0x46')]);_0x4e640b[_0x7fc1('0x47')]=qs[_0x7fc1('0x48')](_[_0x7fc1('0x49')](_0xafc8b0['query'],_0x50c728['filters']),_0x1e4f53);var _0x15edd4=[];var _0x425e5a=squel[_0x7fc1('0x4a')]()[_0x7fc1('0x4b')]('id')[_0x7fc1('0x4b')](_0x7fc1('0x22'))[_0x7fc1('0x4b')](_0x7fc1('0x4c'))[_0x7fc1('0x4d')]('tools_tags');var _0x518a54=squel['select']()[_0x7fc1('0x4b')](_0x7fc1('0x4e'))[_0x7fc1('0x4b')](_0x7fc1('0x4f'))['field'](_0x7fc1('0x50'))[_0x7fc1('0x4d')](_0x7fc1('0x51'),'ui')[_0x7fc1('0x52')]('users','u',_0x7fc1('0x53'));var _0x5ef33=squel[_0x7fc1('0x4a')]()[_0x7fc1('0x4d')](_0x7fc1('0x54'),'i')[_0x7fc1('0x52')](_0x7fc1('0x55'),'c','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL')[_0x7fc1('0x52')]('users','o',_0x7fc1('0x56'))['left_join'](_0x7fc1('0x57'),'a',_0x7fc1('0x58'))['left_join'](_0x7fc1('0x59'),'me',_0x7fc1('0x5a'))['left_join'](_0x7fc1('0x5b'),'it',_0x7fc1('0x5c'))[_0x7fc1('0x52')](_0x7fc1('0x5d'),'t','t.id\x20=\x20it.TagId');var _0x48cc9b=squel[_0x7fc1('0x5e')]();var _0x4a75d6=[];var _0x802d83=squel[_0x7fc1('0x5e')]();var _0x1dbfbd;if(_0xafc8b0[_0x7fc1('0x3d')][_0x7fc1('0x5f')]){_0x1dbfbd=as[_0x7fc1('0x60')](_0xafc8b0[_0x7fc1('0x3d')][_0x7fc1('0x5f')]);var _0x1ea117=_0x1dbfbd['sqlOperator'];for(var _0x562e2b=0x0;_0x562e2b<_0x1dbfbd[_0x7fc1('0x61')]['length'];_0x562e2b++){var _0x320d7a=_0x1dbfbd['conditions'][_0x562e2b];var _0x268f71='i';var _0x143a9f=_[_0x7fc1('0x62')](_0x1e4f53,[_0x7fc1('0x22'),_0x320d7a[_0x7fc1('0x4b')]]);if(!_0x143a9f){switch(_0x320d7a[_0x7fc1('0x4b')]){case _0x7fc1('0x63'):if(_0x320d7a[_0x7fc1('0x64')]==0x1){_0x5ef33['having']('`'+_0x320d7a[_0x7fc1('0x4b')]+'`\x20=\x200');}else{_0x5ef33[_0x7fc1('0x65')]('`'+_0x320d7a['field']+_0x7fc1('0x66'));}break;case'Contact':if(_0x320d7a[_0x7fc1('0x67')]===_0x7fc1('0x68')){if(_0x320d7a[_0x7fc1('0x64')][_0x7fc1('0x27')]('\x20')['length']>0x1){_0x48cc9b[_0x1ea117](_0x7fc1('0x69'),qs['getFullTextValue'](_0x320d7a[_0x7fc1('0x64')]),null);}else{var _0x297f19='%'+_0x320d7a[_0x7fc1('0x64')]+'%';_0x48cc9b[_0x1ea117](_0x7fc1('0x6a'),_0x297f19,_0x297f19,_0x297f19);}}else{_0x143a9f=_[_0x7fc1('0x62')](_0x1e4f53,[_0x7fc1('0x22'),'ContactId']);_0x320d7a['field']='ContactId';_0x19acde=as[_0x7fc1('0x6b')](_0x268f71,_0x143a9f[_0x7fc1('0x3b')],_0x320d7a);_0x48cc9b[_0x1ea117](_0x19acde[_0x7fc1('0x6c')],_0x19acde[_0x7fc1('0x64')][_0x7fc1('0x6d')],_0x19acde[_0x7fc1('0x64')][_0x7fc1('0x16')]);}break;case _0x7fc1('0x6e'):var _0x1de6b8=_0x320d7a['value'][_0x7fc1('0x27')](',')[_0x7fc1('0x38')](function(_0xd0f09d){return Number(_0xd0f09d);});_0x1de6b8[_0x7fc1('0x6f')](function(_0x3294c3){_0x802d83['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x3294c3+',%');});_0x4a75d6=_['union'](_0x4a75d6,_0x1de6b8);break;case _0x7fc1('0x70'):if(_0x320d7a[_0x7fc1('0x67')]===_0x7fc1('0x68')){_0x48cc9b[_0x1ea117](_0x7fc1('0x71'),'%'+_0x320d7a[_0x7fc1('0x64')]+'%',null);}else{_0x143a9f=_[_0x7fc1('0x62')](_0x1e4f53,['name',_0x7fc1('0x34')]);_0x320d7a[_0x7fc1('0x4b')]=_0x7fc1('0x34');_0x19acde=as[_0x7fc1('0x6b')](_0x268f71,_0x143a9f[_0x7fc1('0x3b')],_0x320d7a);_0x48cc9b[_0x1ea117](_0x19acde[_0x7fc1('0x6c')],_0x19acde[_0x7fc1('0x64')][_0x7fc1('0x6d')],_0x19acde['value'][_0x7fc1('0x16')]);}break;case'plainBody':_0x19acde=as[_0x7fc1('0x6b')]('me',null,_0x320d7a);_0x48cc9b[_0x1ea117](_0x19acde[_0x7fc1('0x6c')],_0x19acde[_0x7fc1('0x64')][_0x7fc1('0x6d')],_0x19acde[_0x7fc1('0x64')]['end']);break;}}else{var _0x19acde=as[_0x7fc1('0x6b')](_0x268f71,_0x143a9f[_0x7fc1('0x3b')],_0x320d7a);_0x48cc9b[_0x1ea117](_0x19acde['text'],_0x19acde[_0x7fc1('0x64')]['start'],_0x19acde[_0x7fc1('0x64')][_0x7fc1('0x16')]);}}}else{var _0x513894=_(_0xafc8b0[_0x7fc1('0x3d')])[_0x7fc1('0x72')]()[_0x7fc1('0x38')](function(_0x1119fc){return _['some'](_0x1e4f53,[_0x7fc1('0x22'),_0x1119fc])?_0x1119fc:undefined;})[_0x7fc1('0x73')]()[_0x7fc1('0x64')]();if(!_[_0x7fc1('0x74')](_0x513894)){_0x513894[_0x7fc1('0x6f')](function(_0x2c85e9){if(_0x2c85e9===_0x7fc1('0x75')){_0x5ef33[_0x7fc1('0x47')](_0x7fc1('0x76'),[][_0x7fc1('0x77')](_0xafc8b0[_0x7fc1('0x3d')][_0x2c85e9]));}else if(_0x2c85e9===_0x7fc1('0x78')){var _0x372905=JSON[_0x7fc1('0x79')](_0xafc8b0[_0x7fc1('0x3d')][_0x2c85e9])['$gte'];var _0x19e649=JSON[_0x7fc1('0x79')](_0xafc8b0[_0x7fc1('0x3d')][_0x2c85e9])[_0x7fc1('0x7a')];_0x5ef33[_0x7fc1('0x47')](_0x7fc1('0x7b'),_0x372905,_0x19e649);}else{if(_0xafc8b0['query'][_0x2c85e9]==='null'){_0x5ef33[_0x7fc1('0x47')]('i.'+_0x2c85e9+_0x7fc1('0x7c'));}else{_0x5ef33[_0x7fc1('0x47')]('i.'+_0x2c85e9+_0x7fc1('0x7d'),_0xafc8b0[_0x7fc1('0x3d')][_0x2c85e9]);}}});}if(_0xafc8b0[_0x7fc1('0x3d')]['read']){if(_0xafc8b0[_0x7fc1('0x3d')][_0x7fc1('0x7e')]==0x1){_0x5ef33['having'](_0x7fc1('0x7f'));}else{_0x5ef33['having'](_0x7fc1('0x80'));}}if(_0xafc8b0[_0x7fc1('0x3d')]['tag']){_0x4a75d6=_['isArray'](_0xafc8b0[_0x7fc1('0x3d')][_0x7fc1('0x81')])?_0xafc8b0[_0x7fc1('0x3d')][_0x7fc1('0x81')]:new Array(_0xafc8b0[_0x7fc1('0x3d')][_0x7fc1('0x81')]);_0x4a75d6[_0x7fc1('0x6f')](function(_0x488718){_0x802d83['or'](_0x7fc1('0x82'),'%,'+_0x488718+',%');});}if(_0xafc8b0[_0x7fc1('0x3d')][_0x7fc1('0x83')]){var _0x2c4dc5=_0xafc8b0[_0x7fc1('0x3d')][_0x7fc1('0x83')]['replace']('\x5c','\x5c\x5c')[_0x7fc1('0x84')](/'/g,'\x27\x27');if(qs[_0x7fc1('0x85')](_0x2c4dc5)){_0x48cc9b['or'](_0x7fc1('0x86'),_0x2c4dc5+'%');}else if(qs['isEmail'](_0x2c4dc5)){_0x48cc9b['or'](_0x7fc1('0x87'),_0x2c4dc5+'%');}else{_0x48cc9b['or']('MATCH\x20(i.to,\x20i.subject)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs['getFullTextValue'](_0x2c4dc5))['or']('MATCH\x20(me.plainBody,\x20me.subject)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs[_0x7fc1('0x88')](_0x2c4dc5));}}}_0x5ef33[_0x7fc1('0x47')](_0x48cc9b);_0x5ef33[_0x7fc1('0x89')](_0x7fc1('0x8a'));var _0x1a33b9={'type':db[_0x7fc1('0x8b')]['QueryTypes'][_0x7fc1('0x8c')],'raw':!![]};var _0x54757d=_0x5ef33['clone']();_0x54757d['field'](_0x7fc1('0x8a'));_0x54757d[_0x7fc1('0x4b')](_0x7fc1('0x8d'),'unreadMessages');if(_0x4e640b[_0x7fc1('0x45')]){_0x4e640b[_0x7fc1('0x45')][_0x7fc1('0x6f')](function(_0x306932){var _0x1e04e7=_0x306932[0x0]===_0x7fc1('0x8e')?_0x306932[0x0]:'i.'+_0x306932[0x0];_0x5ef33['order'](_0x1e04e7,_0x306932[0x1]===_0x7fc1('0x8f')?![]:!![]);});}if(!_[_0x7fc1('0x74')](_0x4a75d6)){_0x5ef33[_0x7fc1('0x65')](_0x802d83);_0x54757d[_0x7fc1('0x47')]('t.id\x20IN\x20?',_0x4a75d6);}BPromise['resolve']()['then'](function(){if(!_0x1dbfbd){if(_0xafc8b0[_0x7fc1('0x3d')][_0x7fc1('0x75')])return;_0x54757d[_0x7fc1('0x47')](_0x7fc1('0x90'));_0x5ef33['where'](_0x7fc1('0x90'));return;}if(_0xafc8b0[_0x7fc1('0x91')]['role']!=='agent')return;return _0xafc8b0[_0x7fc1('0x91')][_0x7fc1('0x92')]({'attributes':['id'],'raw':!![]})['then'](function(_0x15899d){if(_[_0x7fc1('0x74')](_0x15899d)){_0x54757d['where'](_0x7fc1('0x93'));_0x5ef33[_0x7fc1('0x47')](_0x7fc1('0x93'));}else{_0x54757d['where'](_0x7fc1('0x76'),_[_0x7fc1('0x38')](_0x15899d,'id'));_0x5ef33[_0x7fc1('0x47')](_0x7fc1('0x76'),_['map'](_0x15899d,'id'));}});})['then'](function(){if(_0xafc8b0['user'][_0x7fc1('0x94')]===_0x7fc1('0x95')&&!_0x1dbfbd&&!_0xafc8b0['query'][_0x7fc1('0x75')])return[];return db[_0x7fc1('0x96')][_0x7fc1('0x3d')](_0x54757d[_0x7fc1('0x97')](),_0x1a33b9);})[_0x7fc1('0x1e')](function(_0x13c895){_0x2fc293[_0x7fc1('0x1b')]=_0x13c895[_0x7fc1('0x42')];if(_0x2fc293[_0x7fc1('0x1b')]===0x0)return[];return db[_0x7fc1('0x96')][_0x7fc1('0x3d')](_0x425e5a['toString'](),_0x1a33b9)[_0x7fc1('0x1e')](function(_0x388817){_0x15edd4=_['keyBy'](_0x388817,'id');_0x1a33b9=_[_0x7fc1('0x98')](_0x1a33b9,{'model':db[_0x7fc1('0x39')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0xafc8b0['query']['fields']){_0x4e640b[_0x7fc1('0x40')][_0x7fc1('0x6f')](function(_0x42f448){_0x5ef33['field']('i.'+_0x42f448);});}else{_0x5ef33[_0x7fc1('0x4b')](_0x7fc1('0x8d'),_0x7fc1('0x63'));_0x5ef33[_0x7fc1('0x4b')](_0x7fc1('0x99'),'Account.key');_0x5ef33['field'](_0x7fc1('0x9a'),_0x7fc1('0x9b'));_0x5ef33[_0x7fc1('0x4b')](_0x7fc1('0x9c'),_0x7fc1('0x8e'));_0x5ef33['field'](_0x7fc1('0x8a'));_0x5ef33['field'](_0x7fc1('0x9d'));_0x5ef33[_0x7fc1('0x4b')](_0x7fc1('0x9e'));_0x5ef33['field'](_0x7fc1('0x9f'));_0x5ef33[_0x7fc1('0x4b')]('i.closedAt');_0x5ef33[_0x7fc1('0x4b')]('i.attach');_0x5ef33['field'](_0x7fc1('0xa0'));_0x5ef33['field']('i.lastMsgDirection');_0x5ef33[_0x7fc1('0x4b')](_0x7fc1('0xa1'));_0x5ef33['field'](_0x7fc1('0xa2'));_0x5ef33[_0x7fc1('0x4b')](_0x7fc1('0xa3'));_0x5ef33['field']('i.thirdDisposition');_0x5ef33[_0x7fc1('0x4b')](_0x7fc1('0xa4'));_0x5ef33['field']('i.to');_0x5ef33[_0x7fc1('0x4b')](_0x7fc1('0xa5'));_0x5ef33[_0x7fc1('0x4b')](_0x7fc1('0xa6'));_0x5ef33[_0x7fc1('0x4b')]('i.UserId');_0x5ef33[_0x7fc1('0x4b')](_0x7fc1('0xa7'),_0x7fc1('0xa8'));_0x5ef33['field']('c.lastName',_0x7fc1('0xa9'));_0x5ef33['field'](_0x7fc1('0xaa'),'Contact.email');_0x5ef33[_0x7fc1('0x4b')](_0x7fc1('0xab'),'Contact.phone');_0x5ef33[_0x7fc1('0x4b')](_0x7fc1('0xac'),'Contact.mobile');_0x5ef33['field'](_0x7fc1('0xad'),'Contact.fax');_0x5ef33[_0x7fc1('0x4b')](_0x7fc1('0xae'),_0x7fc1('0xaf'));_0x5ef33[_0x7fc1('0x4b')](_0x7fc1('0xb0'),_0x7fc1('0xb1'));_0x5ef33[_0x7fc1('0x4b')](_0x7fc1('0xb2'),'TagIds');}if(_0x4e640b['limit'])_0x5ef33[_0x7fc1('0x1a')](_0x4e640b[_0x7fc1('0x1a')]);if(_0x4e640b['offset'])_0x5ef33[_0x7fc1('0x18')](_0x4e640b['offset']);return db['sequelize'][_0x7fc1('0x3d')](_0x5ef33['toString'](),_0x1a33b9);})[_0x7fc1('0x1e')](function(_0x6fdd15){if(_0x6fdd15['length']>0x0)_0x518a54[_0x7fc1('0x47')](_0x7fc1('0xb3'),_['map'](_0x6fdd15,'id'));return db[_0x7fc1('0x96')]['query'](_0x518a54[_0x7fc1('0x97')](),_0x1a33b9)[_0x7fc1('0x1e')](function(_0x461ae2){var _0x5f5d56=_[_0x7fc1('0xb4')](_0x461ae2,_0x7fc1('0xb5'));var _0x5e42f2=[];return db[_0x7fc1('0xb6')][_0x7fc1('0x29')]({'attributes':[_0x7fc1('0xb7')],'raw':!![]})['then'](function(_0x5e7ec0){var _0x3f5770=_0x5e7ec0[_0x7fc1('0xb7')];_0x6fdd15['forEach'](function(_0x2d95fb){_0x5e42f2[_0x7fc1('0x28')](updateMailInteraction(_0x2d95fb,_0x15edd4,_0x5f5d56,_0x3f5770));});return BPromise['all'](_0x5e42f2);});});});})['then'](function(_0xc627c1){_0x2fc293[_0x7fc1('0xb8')]=_0xc627c1;return _0x2fc293;})['then'](respondWithFilteredResult(_0x564437,_0x4e640b))[_0x7fc1('0x2f')](handleError(_0x564437,null));};exports[_0x7fc1('0xb9')]=function(_0x4d584c,_0x2b12bf){var _0x2f676f={'raw':![],'where':{'id':_0x4d584c['params']['id']}},_0xde49ed={};_0xde49ed[_0x7fc1('0x3f')]=_[_0x7fc1('0x72')](db[_0x7fc1('0x39')]['rawAttributes']);_0xde49ed['query']=_[_0x7fc1('0x72')](_0x4d584c['query']);_0xde49ed['filters']=_['intersection'](_0xde49ed[_0x7fc1('0x3f')],_0xde49ed[_0x7fc1('0x3d')]);_0x2f676f[_0x7fc1('0x40')]=_['intersection'](_0xde49ed[_0x7fc1('0x3f')],qs[_0x7fc1('0x41')](_0x4d584c['query'][_0x7fc1('0x41')]));_0x2f676f['attributes']=_0x2f676f[_0x7fc1('0x40')][_0x7fc1('0x42')]?_0x2f676f[_0x7fc1('0x40')]:_0xde49ed[_0x7fc1('0x3f')];if(_0x4d584c[_0x7fc1('0x3d')][_0x7fc1('0xba')]){_0x2f676f[_0x7fc1('0xbb')]=[{'all':!![]}];}_0x2f676f=_[_0x7fc1('0x98')]({},_0x2f676f,_0x4d584c['options']);return db[_0x7fc1('0x39')][_0x7fc1('0x62')](_0x2f676f)[_0x7fc1('0x1e')](handleEntityNotFound(_0x2b12bf,null))[_0x7fc1('0x1e')](respondWithResult(_0x2b12bf,null))['catch'](handleError(_0x2b12bf,null));};exports['create']=function(_0x48ffb3,_0x462dd4){return db[_0x7fc1('0x39')]['create'](_0x48ffb3[_0x7fc1('0xbc')],{})[_0x7fc1('0x1e')](respondWithResult(_0x462dd4,0xc9))[_0x7fc1('0x2f')](handleError(_0x462dd4,null));};exports['update']=function(_0x11d81c,_0x7f16e){if(_0x11d81c[_0x7fc1('0xbc')]['id']){delete _0x11d81c[_0x7fc1('0xbc')]['id'];}return db[_0x7fc1('0x39')][_0x7fc1('0x62')]({'where':{'id':_0x11d81c[_0x7fc1('0xbd')]['id']}})[_0x7fc1('0x1e')](handleEntityNotFound(_0x7f16e,null))[_0x7fc1('0x1e')](saveUpdates(_0x11d81c[_0x7fc1('0xbc')],null))[_0x7fc1('0x1e')](respondWithResult(_0x7f16e,null))[_0x7fc1('0x2f')](handleError(_0x7f16e,null));};exports[_0x7fc1('0x1f')]=function(_0x400e21,_0x440be1){return db[_0x7fc1('0x39')][_0x7fc1('0x62')]({'where':{'id':_0x400e21['params']['id']}})[_0x7fc1('0x1e')](handleEntityNotFound(_0x440be1,null))[_0x7fc1('0x1e')](removeEntity(_0x440be1,null))[_0x7fc1('0x2f')](handleError(_0x440be1,null));};exports[_0x7fc1('0xbe')]=function(_0x560cf4,_0x239fc7){return db[_0x7fc1('0x39')][_0x7fc1('0xbe')]()[_0x7fc1('0x1e')](respondWithResult(_0x239fc7,null))[_0x7fc1('0x2f')](handleError(_0x239fc7,null));};exports[_0x7fc1('0xbf')]=function(_0x25fdca,_0x5161b4){return db['MailMessage'][_0x7fc1('0x62')]({'where':{'id':_0x25fdca[_0x7fc1('0xbd')]['id']}})[_0x7fc1('0x1e')](handleEntityNotFound(_0x5161b4,null))[_0x7fc1('0x1e')](function(_0xc217c3){if(_0xc217c3){return _0xc217c3[_0x7fc1('0xbf')](_0x25fdca['body']['ids'],_['omit'](_0x25fdca[_0x7fc1('0xbc')],[_0x7fc1('0xc0'),'id'])||{});}})[_0x7fc1('0x1e')](respondWithResult(_0x5161b4,null))[_0x7fc1('0x2f')](handleError(_0x5161b4,null));};exports['getMessages']=function(_0x58fe4b,_0x51698f){var _0x390456={'raw':![],'where':{}};var _0xa3826a={};var _0x37bce6={'count':0x0,'rows':[]};return db[_0x7fc1('0x39')][_0x7fc1('0x29')]({'where':{'id':_0x58fe4b[_0x7fc1('0xbd')]['id']}})[_0x7fc1('0x1e')](handleEntityNotFound(_0x51698f,null))[_0x7fc1('0x1e')](function(_0x24a3b8){if(_0x24a3b8){_0xa3826a[_0x7fc1('0x3f')]=_['keys'](db['MailMessage'][_0x7fc1('0xc1')]);_0xa3826a['query']=_[_0x7fc1('0x72')](_0x58fe4b[_0x7fc1('0x3d')]);_0xa3826a[_0x7fc1('0x48')]=_[_0x7fc1('0x3e')](_0xa3826a[_0x7fc1('0x3f')],_0xa3826a[_0x7fc1('0x3d')]);_0x390456['attributes']=_[_0x7fc1('0x3e')](_0xa3826a[_0x7fc1('0x3f')],qs['fields'](_0x58fe4b[_0x7fc1('0x3d')][_0x7fc1('0x41')]));_0x390456[_0x7fc1('0x40')]=_0x390456[_0x7fc1('0x40')][_0x7fc1('0x42')]?_0x390456[_0x7fc1('0x40')]:_0xa3826a[_0x7fc1('0x3f')];if(!_0x58fe4b['query'][_0x7fc1('0x43')](_0x7fc1('0x44'))){_0x390456[_0x7fc1('0x1a')]=qs[_0x7fc1('0x1a')](_0x58fe4b[_0x7fc1('0x3d')][_0x7fc1('0x1a')]);_0x390456[_0x7fc1('0x18')]=qs[_0x7fc1('0x18')](_0x58fe4b[_0x7fc1('0x3d')]['offset']);}_0x390456[_0x7fc1('0x45')]=qs[_0x7fc1('0x46')](_0x58fe4b[_0x7fc1('0x3d')][_0x7fc1('0x46')]);_0x390456[_0x7fc1('0x47')]=qs[_0x7fc1('0x48')](_[_0x7fc1('0x49')](_0x58fe4b[_0x7fc1('0x3d')],_0xa3826a[_0x7fc1('0x48')]));_0x390456[_0x7fc1('0x47')][_0x7fc1('0xb5')]=_0x24a3b8['id'];if(_0x58fe4b[_0x7fc1('0x3d')][_0x7fc1('0x83')]){_0x390456['where']=_[_0x7fc1('0x98')](_0x390456['where'],{'$or':_[_0x7fc1('0x38')](_0x390456[_0x7fc1('0x40')],function(_0x5031db){var _0x3099e1={};_0x3099e1[_0x5031db]={'$like':'%'+_0x58fe4b[_0x7fc1('0x3d')][_0x7fc1('0x83')]+'%'};return _0x3099e1;})});}if(_0x58fe4b[_0x7fc1('0x3d')][_0x7fc1('0xc2')]){var _0x251305=_0x58fe4b['query']['$gte'][_0x7fc1('0x27')](',');var _0x25ecfe={};_0x25ecfe[_0x251305[0x0]]={'$gte':moment(_0x251305[0x1])[_0x7fc1('0xc3')](_0x7fc1('0xc4'))};_0x390456[_0x7fc1('0x47')]=_['merge'](_0x390456[_0x7fc1('0x47')],_0x25ecfe);}_0x390456=_[_0x7fc1('0x98')]({},_0x390456,_0x58fe4b[_0x7fc1('0xc5')]);return db['MailMessage']['count']({'where':_0x390456['where']})['then'](function(_0x13e7f7){_0x37bce6[_0x7fc1('0x1b')]=_0x13e7f7;if(_0x58fe4b[_0x7fc1('0x3d')][_0x7fc1('0xba')]){_0x390456[_0x7fc1('0xbb')]=[{'all':!![]}];}return db['MailMessage'][_0x7fc1('0xc6')](_0x390456);})[_0x7fc1('0x1e')](function(_0x2fc5b2){if(_0x58fe4b[_0x7fc1('0x3d')][_0x7fc1('0xc7')]==='true'){for(var _0x1a462e=0x0;_0x1a462e<_0x2fc5b2[_0x7fc1('0x42')];_0x1a462e++){_0x2fc5b2[_0x1a462e][_0x7fc1('0xbc')]=juice(_0x2fc5b2[_0x1a462e][_0x7fc1('0xbc')]);}}_0x37bce6[_0x7fc1('0xb8')]=_0x2fc5b2;return _0x37bce6;});}})[_0x7fc1('0x1e')](respondWithFilteredResult(_0x51698f,_0x390456))['catch'](handleError(_0x51698f,null));};exports[_0x7fc1('0xc8')]=function(_0x48f27d,_0x4c326c){return db[_0x7fc1('0x39')][_0x7fc1('0x62')]({'where':{'id':_0x48f27d[_0x7fc1('0xbd')]['id']}})[_0x7fc1('0x1e')](handleEntityNotFound(_0x4c326c,null))['then'](function(_0x2f3cf3){if(_0x2f3cf3){return _0x2f3cf3[_0x7fc1('0xc9')](_0x48f27d[_0x7fc1('0xbc')][_0x7fc1('0xc0')],_['omit'](_0x48f27d[_0x7fc1('0xbc')],['ids','id'])||{})[_0x7fc1('0xca')](function(){return db[_0x7fc1('0x6e')][_0x7fc1('0xc6')]({'attributes':['id',_0x7fc1('0x22'),_0x7fc1('0x4c')],'where':{'id':_0x48f27d[_0x7fc1('0xbc')][_0x7fc1('0xc0')]}});})[_0x7fc1('0x1e')](function(_0x5105f6){socket[_0x7fc1('0xcb')](_0x7fc1('0xcc'),{'id':Number(_0x48f27d[_0x7fc1('0xbd')]['id']),'tags':_0x5105f6||[]});return{'id':Number(_0x48f27d[_0x7fc1('0xbd')]['id']),'tags':_0x5105f6||[]};});}})[_0x7fc1('0x1e')](respondWithResult(_0x4c326c,null))[_0x7fc1('0x2f')](handleError(_0x4c326c,null));};exports[_0x7fc1('0xcd')]=function(_0x354508,_0x210956){return db[_0x7fc1('0x39')][_0x7fc1('0x62')]({'where':{'id':_0x354508['params']['id']}})[_0x7fc1('0x1e')](handleEntityNotFound(_0x210956,null))[_0x7fc1('0x1e')](function(_0x16b0a0){if(_0x16b0a0){return _0x16b0a0[_0x7fc1('0xcd')](_0x354508[_0x7fc1('0x3d')][_0x7fc1('0xc0')]);}})[_0x7fc1('0x1e')](respondWithStatusCode(_0x210956,null))[_0x7fc1('0x2f')](handleError(_0x210956,null));};exports[_0x7fc1('0xce')]=function(_0x18447f,_0x391a33){var _0x3aadfe=moment()[_0x7fc1('0xcf')]()['toString']();var _0x4d75fc=path[_0x7fc1('0xd0')](config[_0x7fc1('0xd1')],_0x7fc1('0xd2'),_0x7fc1('0xd3'),'tmp');var _0x34ebfc=path[_0x7fc1('0xd0')](config[_0x7fc1('0xd1')],_0x7fc1('0xd2'),_0x7fc1('0xd3'),_0x7fc1('0xd4'));var _0x511072=path[_0x7fc1('0xd0')](_0x4d75fc,_0x3aadfe);var _0x3bff5a=util[_0x7fc1('0xc3')](_0x7fc1('0xd5'),_0x18447f[_0x7fc1('0xbd')]['id'],_0x3aadfe);var _0x5c17f1=path[_0x7fc1('0xd0')](_0x4d75fc,_0x3bff5a);var _0x181086=[];if(_0x18447f['query']['attachments']){_0x181086[_0x7fc1('0x28')]({'model':db[_0x7fc1('0xd6')],'as':_0x7fc1('0xd7'),'raw':!![]});}var _0x4866b8=[{'model':db[_0x7fc1('0xd8')],'as':'Messages','attributes':['id',_0x7fc1('0xbc'),_0x7fc1('0x4d'),'to','cc',_0x7fc1('0xd9'),_0x7fc1('0xda'),_0x7fc1('0x78')],'where':{'secret':![]},'order':qs[_0x7fc1('0x46')]('id'),'include':_0x181086}];return db[_0x7fc1('0x39')][_0x7fc1('0x62')]({'where':{'id':_0x18447f[_0x7fc1('0xbd')]['id']},'include':_0x4866b8})[_0x7fc1('0x1e')](handleEntityNotFound(_0x391a33,null))[_0x7fc1('0x1e')](function(_0x10cec8){if(_0x10cec8&&_0x10cec8[_0x7fc1('0xdb')]){var _0x18db07=_0x10cec8[_0x7fc1('0xdc')]({'plain':!![]});fs[_0x7fc1('0xdd')](_0x511072);return BPromise[_0x7fc1('0xde')](_0x18db07[_0x7fc1('0xdb')],function(_0x2325a7,_0x3d146a){var _0xbb1b6e={'from':_0x2325a7[_0x7fc1('0x4d')],'to':_0x2325a7['to'],'subject':_0x2325a7['subject'],'html':htmlEntities[_0x7fc1('0xdf')](_0x2325a7[_0x7fc1('0xbc')]),'headers':{'Date':moment(_0x2325a7[_0x7fc1('0x78')])[_0x7fc1('0xc3')](_0x7fc1('0xe0'))},'attachments':[]};if(_0x2325a7['cc']){_0xbb1b6e['headers']['Cc']=_0x2325a7['cc'];}if(_0x2325a7[_0x7fc1('0xd9')]){_0xbb1b6e[_0x7fc1('0xe1')]['Bcc']=_0x2325a7[_0x7fc1('0xd9')];}return new BPromise(function(_0x109c3b,_0x136f44){if(_0x2325a7[_0x7fc1('0xd7')]){for(var _0x467293=0x0;_0x467293<_0x2325a7['Attachments'][_0x7fc1('0x42')];_0x467293++){var _0x1fcd68=_0x2325a7[_0x7fc1('0xd7')][_0x467293];var _0x562e83=path[_0x7fc1('0xd0')](_0x34ebfc,_0x1fcd68[_0x7fc1('0xe2')]);if(fs[_0x7fc1('0xe3')](_0x562e83)){_0xbb1b6e[_0x7fc1('0xd4')][_0x7fc1('0x28')]({'name':_0x1fcd68['name'],'contentType':_0x1fcd68[_0x7fc1('0x3b')],'data':fs[_0x7fc1('0xe4')](_0x562e83)});}}}emlformat[_0x7fc1('0xe5')](_0xbb1b6e,function(_0x3d09c7,_0x598617){if(_0x3d09c7)return _0x136f44(_0x3d09c7);fs[_0x7fc1('0xe6')](path[_0x7fc1('0xd0')](_0x511072,util[_0x7fc1('0xc3')](_0x7fc1('0xe7'),_0x3d146a)),_0x598617);return _0x109c3b(_0x598617);});});})[_0x7fc1('0x1e')](function(){return new BPromise(function(_0x221d97,_0x4cd0b4){zipdir(_0x511072,{'saveTo':_0x5c17f1},function(_0x2316db,_0x7860b){if(_0x2316db)return _0x4cd0b4(_0x2316db);return _0x221d97(_0x7860b);});})[_0x7fc1('0x1e')](function(){return new BPromise(function(_0x1e2887,_0x5d2b3a){rimraf(_0x511072,function(_0x4bb095){if(_0x4bb095)_0x5d2b3a(_0x4bb095);return _0x1e2887();});});})['then'](function(){return _0x391a33['download'](_0x5c17f1,_0x3bff5a,function(_0x2d2721){if(!_0x2d2721)fs['unlinkSync'](_0x5c17f1);});});});}else{return _0x391a33['sendStatus'](0xc8);}})[_0x7fc1('0x2f')](handleError(_0x391a33,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