Built motion from commit (unavailable).|2.6.0
[motion2.git] / server / api / mailInteraction / mailInteraction.controller.js
index b33dab0..3f88706 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x08fb=['get','each','headers','Bcc','basename','existsSync','attachments','readFileSync','writeFileSync','message%d.eml','log','err','unlinkSync','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','util','path','to-csv','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','html-to-text','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./mailInteraction.socket','register','sendStatus','status','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save','update','then','destroy','end','error','stack','name','send','Users','map','fullname','TagIds','split','forEach','push','MailMessage','findOne','out','-id','plainBody','trimStart','catch','index','rawAttributes','fieldName','key','query','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','field','from','tools_tags','select','u.fullname','user_has_mail_interactions','left_join','u.id\x20=\x20ui.UserId','mail_interactions','cm_contacts','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','users','o.id\x20=\x20i.UserId','mail_accounts','a.id\x20=\x20i.MailAccountId','mail_interaction_has_tags','it.MailInteractionId\x20=\x20i.id','t.id\x20=\x20it.TagId','expr','search','parseSearch','sqlOperator','conditions','find','value','having','`\x20=\x200','`\x20>\x200','Contact','operator','$substring','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','text','start','Tag','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','union','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','UserId','type','keys','some','compact','isEmpty','MailAccountId','i.MailAccountId\x20IN\x20?','parse','$lte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20IS\x20NULL','\x20=\x20?','read','`unreadMessages`\x20=\x200','`unreadMessages`\x20>\x200','tag','isArray','filter','isNumeric','i.id\x20LIKE\x20?','c.email\x20LIKE\x20?','MATCH\x20(me.plainBody,\x20me.subject)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','group','i.id','Sequelize','SELECT','contactName','DESC','t.id\x20IN\x20?','resolve','i.MailAccountId\x20IS\x20NOT\x20NULL','user','agent','i.MailAccountId\x20IS\x20NULL','role','sequelize','toString','merge','MailInteraction','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','unreadMessages','a.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.closedAt','i.attach','i.lastMsgAt','i.lastMsgDirection','i.subject','i.disposition','i.secondDisposition','i.thirdDisposition','i.to','i.ContactId','i.MailAccountId','i.UserId','c.firstName','Contact.firstName','c.lastName','Contact.lastName','Contact.email','c.phone','Contact.phone','Contact.mobile','c.fax','o.fullname','Owner.fullname','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','ui.MailInteractionId\x20IN\x20?','MailInteractionId','enableEmailPreview','rows','show','params','includeAll','include','create','body','describe','addMessage','ids','getMessages','$gte','format','YYYY-MM-DD\x20HH:mm:ss','options','inlineCss','true','addTags','setTags','omit','findAll','emit','mailInteractionTags:save','removeTags','download','unix','join','root','files','tmp','server','transcript-%d-%s.zip','Attachment','Attachments','Messages','bcc','subject','createdAt'];(function(_0x8239a,_0x4567e5){var _0x7a8047=function(_0x20cbc4){while(--_0x20cbc4){_0x8239a['push'](_0x8239a['shift']());}};_0x7a8047(++_0x4567e5);}(_0x08fb,0x10b));var _0xb08f=function(_0x43fb5c,_0x41eab9){_0x43fb5c=_0x43fb5c-0x0;var _0x14d8f6=_0x08fb[_0x43fb5c];return _0x14d8f6;};'use strict';var emlformat=require(_0xb08f('0x0'));var rimraf=require(_0xb08f('0x1'));var zipdir=require(_0xb08f('0x2'));var jsonpatch=require(_0xb08f('0x3'));var rp=require('request-promise');var moment=require(_0xb08f('0x4'));var BPromise=require(_0xb08f('0x5'));var Mustache=require(_0xb08f('0x6'));var util=require(_0xb08f('0x7'));var path=require(_0xb08f('0x8'));var sox=require('sox');var csv=require(_0xb08f('0x9'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xb08f('0xa'));var _=require(_0xb08f('0xb'));var squel=require(_0xb08f('0xc'));var crypto=require(_0xb08f('0xd'));var jsforce=require(_0xb08f('0xe'));var deskjs=require(_0xb08f('0xf'));var toCsv=require('to-csv');var querystring=require(_0xb08f('0x10'));var Papa=require(_0xb08f('0x11'));var htmlToText=require(_0xb08f('0x12'));var juice=require('juice');var Redis=require('ioredis');var authService=require(_0xb08f('0x13'));var qs=require(_0xb08f('0x14'));var as=require(_0xb08f('0x15'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xb08f('0x16'))(_0xb08f('0x17'));var utils=require(_0xb08f('0x18'));var config=require(_0xb08f('0x19'));var licenseUtil=require(_0xb08f('0x1a'));var db=require(_0xb08f('0x1b'))['db'];config[_0xb08f('0x1c')]=_[_0xb08f('0x1d')](config[_0xb08f('0x1c')],{'host':_0xb08f('0x1e'),'port':0x18eb});var socket=require(_0xb08f('0x1f'))(new Redis(config[_0xb08f('0x1c')]));require(_0xb08f('0x20'))[_0xb08f('0x21')](socket);function respondWithStatusCode(_0x3a593c,_0x281c34){_0x281c34=_0x281c34||0xcc;return function(_0x590689){if(_0x590689){return _0x3a593c[_0xb08f('0x22')](_0x281c34);}return _0x3a593c[_0xb08f('0x23')](_0x281c34)['end']();};}function respondWithResult(_0x2d2791,_0x445113){_0x445113=_0x445113||0xc8;return function(_0x850852){if(_0x850852){return _0x2d2791[_0xb08f('0x23')](_0x445113)[_0xb08f('0x24')](_0x850852);}};}function respondWithFilteredResult(_0x53d06e,_0x38c36f){return function(_0x368e26){if(_0x368e26){var _0x2b31b6=typeof _0x38c36f[_0xb08f('0x25')]===_0xb08f('0x26')&&typeof _0x38c36f[_0xb08f('0x27')]===_0xb08f('0x26');var _0xf84939=_0x368e26[_0xb08f('0x28')];var _0x3f216b=_0x2b31b6?0x0:_0x38c36f[_0xb08f('0x25')];var _0x504d03=_0x2b31b6?_0x368e26['count']:_0x38c36f[_0xb08f('0x25')]+_0x38c36f[_0xb08f('0x27')];var _0x3bc0dd;if(_0x504d03>=_0xf84939){_0x504d03=_0xf84939;_0x3bc0dd=0xc8;}else{_0x3bc0dd=0xce;}_0x53d06e['status'](_0x3bc0dd);return _0x53d06e[_0xb08f('0x29')](_0xb08f('0x2a'),_0x3f216b+'-'+_0x504d03+'/'+_0xf84939)[_0xb08f('0x24')](_0x368e26);}return null;};}function patchUpdates(_0x210caf){return function(_0xacf261){try{jsonpatch[_0xb08f('0x2b')](_0xacf261,_0x210caf,!![]);}catch(_0x56c429){return BPromise[_0xb08f('0x2c')](_0x56c429);}return _0xacf261[_0xb08f('0x2d')]();};}function saveUpdates(_0x5eb808,_0xf36c8d){return function(_0x512d3b){if(_0x512d3b){return _0x512d3b[_0xb08f('0x2e')](_0x5eb808)[_0xb08f('0x2f')](function(_0xe9ab3c){return _0xe9ab3c;});}return null;};}function removeEntity(_0x23fad9,_0x5d2807){return function(_0x518966){if(_0x518966){return _0x518966[_0xb08f('0x30')]()[_0xb08f('0x2f')](function(){_0x23fad9[_0xb08f('0x23')](0xcc)[_0xb08f('0x31')]();});}};}function handleEntityNotFound(_0x5f1ec6,_0xebcd59){return function(_0x220c1a){if(!_0x220c1a){_0x5f1ec6[_0xb08f('0x22')](0x194);}return _0x220c1a;};}function handleError(_0x1b1c03,_0x5f368f){_0x5f368f=_0x5f368f||0x1f4;return function(_0x1f33b8){logger[_0xb08f('0x32')](_0x1f33b8[_0xb08f('0x33')]);if(_0x1f33b8['name']){delete _0x1f33b8[_0xb08f('0x34')];}_0x1b1c03[_0xb08f('0x23')](_0x5f368f)[_0xb08f('0x35')](_0x1f33b8);};}function getInteractionUsers(_0x2e33f6,_0x1dbc06){return new BPromise(function(_0xb932e2,_0x35a8c7){try{if(_0x1dbc06[_0x2e33f6['id']]){_0x2e33f6[_0xb08f('0x36')]=_[_0xb08f('0x37')](_0x1dbc06[_0x2e33f6['id']],function(_0x4f4a1d){return{'id':_0x4f4a1d['id'],'fullname':_0x4f4a1d[_0xb08f('0x38')]};});}}catch(_0x16cb84){_0x35a8c7(_0x16cb84);}_0xb932e2(_0x2e33f6);});}function getInteractionTags(_0x46b358,_0x4a24fe){return new BPromise(function(_0x189b32,_0x247601){try{if(_0x46b358[_0xb08f('0x39')]){_0x46b358['Tags']=[];_0x46b358[_0xb08f('0x39')][_0xb08f('0x3a')](',')[_0xb08f('0x3b')](function(_0x496e31){_0x46b358['Tags'][_0xb08f('0x3c')](_0x4a24fe[_0x496e31]);});}delete _0x46b358[_0xb08f('0x39')];}catch(_0x1cf664){_0x247601(_0x1cf664);}_0x189b32(_0x46b358);});}function getLastMessageText(_0x279bc8){return new BPromise(function(_0x5e6eaf,_0x333af9){return db[_0xb08f('0x3d')][_0xb08f('0x3e')]({'where':{'$and':[{'MailInteractionId':_0x279bc8['id']},{'$or':[{'direction':'in'},{'$and':[{'direction':_0xb08f('0x3f')},{'secret':![]},{'UserId':{'$ne':null}}]}]}]},'attributes':['plainBody'],'order':_0xb08f('0x40'),'raw':!![]})[_0xb08f('0x2f')](function(_0x51afef){if(_0x51afef&&_0x51afef[_0xb08f('0x41')]){_0x279bc8['lastMsgText']=_[_0xb08f('0x42')](_0x51afef[_0xb08f('0x41')]);}_0x5e6eaf(_0x279bc8);})[_0xb08f('0x43')](function(_0x2e812b){_0x333af9(_0x2e812b);});});}function updateMailInteraction(_0x5dae82,_0x3bb75b,_0x1db4de,_0x3646d5){return new BPromise(function(_0x56c033,_0x365541){return getInteractionUsers(_0x5dae82,_0x1db4de)[_0xb08f('0x2f')](function(_0x1ce848){return getInteractionTags(_0x1ce848,_0x3bb75b);})[_0xb08f('0x2f')](function(_0x413e09){if(_0x3646d5){_0x56c033(getLastMessageText(_0x413e09));}else{_0x56c033(_0x413e09);}})[_0xb08f('0x43')](function(_0xba264){_0x365541(_0xba264);});});}exports[_0xb08f('0x44')]=function(_0x31b8f7,_0x440faa){var _0xd45da0={},_0x2c299c={},_0x5b48c4={'count':0x0,'rows':[]};var _0x1c50bc=_[_0xb08f('0x37')](db['MailInteraction'][_0xb08f('0x45')],function(_0x4e0ebb){return{'name':_0x4e0ebb[_0xb08f('0x46')],'type':_0x4e0ebb['type'][_0xb08f('0x47')]};});_0x2c299c['model']=_[_0xb08f('0x37')](_0x1c50bc,_0xb08f('0x34'));_0x2c299c[_0xb08f('0x48')]=_['keys'](_0x31b8f7[_0xb08f('0x48')]);_0x2c299c[_0xb08f('0x49')]=_[_0xb08f('0x4a')](_0x2c299c[_0xb08f('0x4b')],_0x2c299c[_0xb08f('0x48')]);_0xd45da0[_0xb08f('0x4c')]=_[_0xb08f('0x4a')](_0x2c299c[_0xb08f('0x4b')],qs[_0xb08f('0x4d')](_0x31b8f7[_0xb08f('0x48')][_0xb08f('0x4d')]));_0xd45da0[_0xb08f('0x4c')]=_0xd45da0[_0xb08f('0x4c')][_0xb08f('0x4e')]?_0xd45da0['attributes']:_0x2c299c[_0xb08f('0x4b')];if(!_0x31b8f7[_0xb08f('0x48')][_0xb08f('0x4f')](_0xb08f('0x50'))){_0xd45da0[_0xb08f('0x27')]=qs['limit'](_0x31b8f7[_0xb08f('0x48')][_0xb08f('0x27')]);_0xd45da0[_0xb08f('0x25')]=qs[_0xb08f('0x25')](_0x31b8f7[_0xb08f('0x48')][_0xb08f('0x25')]);}_0xd45da0[_0xb08f('0x51')]=qs[_0xb08f('0x52')](_0x31b8f7[_0xb08f('0x48')]['sort']);_0xd45da0[_0xb08f('0x53')]=qs[_0xb08f('0x49')](_[_0xb08f('0x54')](_0x31b8f7[_0xb08f('0x48')],_0x2c299c[_0xb08f('0x49')]),_0x1c50bc);var _0x4b2ce8=[];var _0x3a5db3=squel['select']()[_0xb08f('0x55')]('id')['field'](_0xb08f('0x34'))[_0xb08f('0x55')]('color')[_0xb08f('0x56')](_0xb08f('0x57'));var _0x531302=squel[_0xb08f('0x58')]()[_0xb08f('0x55')]('u.id')[_0xb08f('0x55')](_0xb08f('0x59'))[_0xb08f('0x55')]('ui.MailInteractionId')[_0xb08f('0x56')](_0xb08f('0x5a'),'ui')[_0xb08f('0x5b')]('users','u',_0xb08f('0x5c'));var _0x29ede4=squel[_0xb08f('0x58')]()[_0xb08f('0x56')](_0xb08f('0x5d'),'i')[_0xb08f('0x5b')](_0xb08f('0x5e'),'c',_0xb08f('0x5f'))['left_join'](_0xb08f('0x60'),'o',_0xb08f('0x61'))[_0xb08f('0x5b')](_0xb08f('0x62'),'a',_0xb08f('0x63'))[_0xb08f('0x5b')]('mail_messages','me','me.MailInteractionId\x20=\x20i.id')['left_join'](_0xb08f('0x64'),'it',_0xb08f('0x65'))['left_join']('tools_tags','t',_0xb08f('0x66'));var _0x55c020=squel[_0xb08f('0x67')]();var _0x578206=[];var _0x5fdfc2=squel['expr']();var _0x4fd1b1;if(_0x31b8f7[_0xb08f('0x48')][_0xb08f('0x68')]){_0x4fd1b1=as[_0xb08f('0x69')](_0x31b8f7[_0xb08f('0x48')]['search']);var _0x5b68fc=_0x4fd1b1[_0xb08f('0x6a')];for(var _0x5536e8=0x0;_0x5536e8<_0x4fd1b1['conditions'][_0xb08f('0x4e')];_0x5536e8++){var _0x37c6c5=_0x4fd1b1[_0xb08f('0x6b')][_0x5536e8];var _0x175b27='i';var _0x111703=_[_0xb08f('0x6c')](_0x1c50bc,['name',_0x37c6c5[_0xb08f('0x55')]]);if(!_0x111703){switch(_0x37c6c5[_0xb08f('0x55')]){case'unreadMessages':if(_0x37c6c5[_0xb08f('0x6d')]==0x1){_0x29ede4[_0xb08f('0x6e')]('`'+_0x37c6c5[_0xb08f('0x55')]+_0xb08f('0x6f'));}else{_0x29ede4[_0xb08f('0x6e')]('`'+_0x37c6c5[_0xb08f('0x55')]+_0xb08f('0x70'));}break;case _0xb08f('0x71'):if(_0x37c6c5[_0xb08f('0x72')]===_0xb08f('0x73')){if(_0x37c6c5['value'][_0xb08f('0x3a')]('\x20')[_0xb08f('0x4e')]>0x1){_0x55c020[_0x5b68fc](_0xb08f('0x74'),qs[_0xb08f('0x75')](_0x37c6c5[_0xb08f('0x6d')]),null);}else{var _0x2c2ba0='%'+_0x37c6c5[_0xb08f('0x6d')]+'%';_0x55c020[_0x5b68fc](_0xb08f('0x76'),_0x2c2ba0,_0x2c2ba0,_0x2c2ba0);}}else{_0x111703=_[_0xb08f('0x6c')](_0x1c50bc,[_0xb08f('0x34'),_0xb08f('0x77')]);_0x37c6c5[_0xb08f('0x55')]=_0xb08f('0x77');_0x2e7ae2=as[_0xb08f('0x78')](_0x175b27,_0x111703['type'],_0x37c6c5);_0x55c020[_0x5b68fc](_0x2e7ae2[_0xb08f('0x79')],_0x2e7ae2[_0xb08f('0x6d')][_0xb08f('0x7a')],_0x2e7ae2[_0xb08f('0x6d')][_0xb08f('0x31')]);}break;case _0xb08f('0x7b'):var _0x19d402=_0x37c6c5[_0xb08f('0x6d')][_0xb08f('0x3a')](',')[_0xb08f('0x37')](function(_0x1f4897){return Number(_0x1f4897);});_0x19d402[_0xb08f('0x3b')](function(_0x5f2dea){_0x5fdfc2['or'](_0xb08f('0x7c'),'%,'+_0x5f2dea+',%');});_0x578206=_[_0xb08f('0x7d')](_0x578206,_0x19d402);break;case'User':if(_0x37c6c5['operator']===_0xb08f('0x73')){_0x55c020[_0x5b68fc](_0xb08f('0x7e'),'%'+_0x37c6c5[_0xb08f('0x6d')]+'%',null);}else{_0x111703=_[_0xb08f('0x6c')](_0x1c50bc,[_0xb08f('0x34'),_0xb08f('0x7f')]);_0x37c6c5[_0xb08f('0x55')]=_0xb08f('0x7f');_0x2e7ae2=as[_0xb08f('0x78')](_0x175b27,_0x111703['type'],_0x37c6c5);_0x55c020[_0x5b68fc](_0x2e7ae2['text'],_0x2e7ae2[_0xb08f('0x6d')][_0xb08f('0x7a')],_0x2e7ae2['value'][_0xb08f('0x31')]);}break;case _0xb08f('0x41'):_0x2e7ae2=as['buildExpression']('me',null,_0x37c6c5);_0x55c020[_0x5b68fc](_0x2e7ae2[_0xb08f('0x79')],_0x2e7ae2['value'][_0xb08f('0x7a')],_0x2e7ae2[_0xb08f('0x6d')][_0xb08f('0x31')]);break;}}else{var _0x2e7ae2=as[_0xb08f('0x78')](_0x175b27,_0x111703[_0xb08f('0x80')],_0x37c6c5);_0x55c020[_0x5b68fc](_0x2e7ae2[_0xb08f('0x79')],_0x2e7ae2[_0xb08f('0x6d')]['start'],_0x2e7ae2[_0xb08f('0x6d')][_0xb08f('0x31')]);}}}else{var _0x1d2760=_(_0x31b8f7['query'])[_0xb08f('0x81')]()[_0xb08f('0x37')](function(_0x5578a9){return _[_0xb08f('0x82')](_0x1c50bc,['name',_0x5578a9])?_0x5578a9:undefined;})[_0xb08f('0x83')]()[_0xb08f('0x6d')]();if(!_[_0xb08f('0x84')](_0x1d2760)){_0x1d2760[_0xb08f('0x3b')](function(_0x4592fa){if(_0x4592fa===_0xb08f('0x85')){_0x29ede4[_0xb08f('0x53')](_0xb08f('0x86'),[]['concat'](_0x31b8f7[_0xb08f('0x48')][_0x4592fa]));}else if(_0x4592fa==='createdAt'){var _0xc34c38=JSON[_0xb08f('0x87')](_0x31b8f7[_0xb08f('0x48')][_0x4592fa])['$gte'];var _0x4f44ea=JSON['parse'](_0x31b8f7[_0xb08f('0x48')][_0x4592fa])[_0xb08f('0x88')];_0x29ede4[_0xb08f('0x53')](_0xb08f('0x89'),_0xc34c38,_0x4f44ea);}else{if(_0x31b8f7[_0xb08f('0x48')][_0x4592fa]===_0xb08f('0x8a')){_0x29ede4[_0xb08f('0x53')]('i.'+_0x4592fa+_0xb08f('0x8b'));}else{_0x29ede4[_0xb08f('0x53')]('i.'+_0x4592fa+_0xb08f('0x8c'),_0x31b8f7[_0xb08f('0x48')][_0x4592fa]);}}});}if(_0x31b8f7['query'][_0xb08f('0x8d')]){if(_0x31b8f7[_0xb08f('0x48')][_0xb08f('0x8d')]==0x1){_0x29ede4[_0xb08f('0x6e')](_0xb08f('0x8e'));}else{_0x29ede4[_0xb08f('0x6e')](_0xb08f('0x8f'));}}if(_0x31b8f7['query'][_0xb08f('0x90')]){_0x578206=_[_0xb08f('0x91')](_0x31b8f7[_0xb08f('0x48')][_0xb08f('0x90')])?_0x31b8f7[_0xb08f('0x48')]['tag']:new Array(_0x31b8f7[_0xb08f('0x48')][_0xb08f('0x90')]);_0x578206['forEach'](function(_0x25c7ae){_0x5fdfc2['or'](_0xb08f('0x7c'),'%,'+_0x25c7ae+',%');});}if(_0x31b8f7[_0xb08f('0x48')][_0xb08f('0x92')]){var _0x13a0c8=_0x31b8f7[_0xb08f('0x48')][_0xb08f('0x92')]['replace']('\x5c','\x5c\x5c')['replace'](/'/g,'\x27\x27');if(qs[_0xb08f('0x93')](_0x13a0c8)){_0x55c020['or'](_0xb08f('0x94'),_0x13a0c8+'%');}else if(qs['isEmail'](_0x13a0c8)){_0x55c020['or'](_0xb08f('0x95'),_0x13a0c8+'%');}else{_0x55c020['or']('MATCH\x20(i.to,\x20i.subject)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs[_0xb08f('0x75')](_0x13a0c8))['or'](_0xb08f('0x96'),qs[_0xb08f('0x75')](_0x13a0c8));}}}_0x29ede4[_0xb08f('0x53')](_0x55c020);_0x29ede4[_0xb08f('0x97')](_0xb08f('0x98'));var _0x2e30c8={'type':db[_0xb08f('0x99')]['QueryTypes'][_0xb08f('0x9a')],'raw':!![]};var _0x32b7fe=_0x29ede4['clone']();_0x32b7fe[_0xb08f('0x55')](_0xb08f('0x98'));_0x32b7fe[_0xb08f('0x55')]('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','unreadMessages');if(_0xd45da0['order']){_0xd45da0[_0xb08f('0x51')]['forEach'](function(_0x3cad20){var _0x5c4e66=_0x3cad20[0x0]===_0xb08f('0x9b')?_0x3cad20[0x0]:'i.'+_0x3cad20[0x0];_0x29ede4[_0xb08f('0x51')](_0x5c4e66,_0x3cad20[0x1]===_0xb08f('0x9c')?![]:!![]);});}if(!_[_0xb08f('0x84')](_0x578206)){_0x29ede4[_0xb08f('0x6e')](_0x5fdfc2);_0x32b7fe[_0xb08f('0x53')](_0xb08f('0x9d'),_0x578206);}BPromise[_0xb08f('0x9e')]()['then'](function(){if(!_0x4fd1b1){if(_0x31b8f7[_0xb08f('0x48')][_0xb08f('0x85')])return;_0x32b7fe[_0xb08f('0x53')]('i.MailAccountId\x20IS\x20NOT\x20NULL');_0x29ede4[_0xb08f('0x53')](_0xb08f('0x9f'));return;}if(_0x31b8f7[_0xb08f('0xa0')]['role']!==_0xb08f('0xa1'))return;return _0x31b8f7['user']['getMailAccounts']({'attributes':['id'],'raw':!![]})[_0xb08f('0x2f')](function(_0x3913cf){if(_[_0xb08f('0x84')](_0x3913cf)){_0x32b7fe[_0xb08f('0x53')]('i.MailAccountId\x20IS\x20NULL');_0x29ede4['where'](_0xb08f('0xa2'));}else{_0x32b7fe[_0xb08f('0x53')]('i.MailAccountId\x20IN\x20?',_[_0xb08f('0x37')](_0x3913cf,'id'));_0x29ede4['where']('i.MailAccountId\x20IN\x20?',_[_0xb08f('0x37')](_0x3913cf,'id'));}});})[_0xb08f('0x2f')](function(){if(_0x31b8f7['user'][_0xb08f('0xa3')]==='agent'&&!_0x4fd1b1&&!_0x31b8f7[_0xb08f('0x48')][_0xb08f('0x85')])return[];return db[_0xb08f('0xa4')]['query'](_0x32b7fe['toString'](),_0x2e30c8);})[_0xb08f('0x2f')](function(_0x91cd75){_0x5b48c4['count']=_0x91cd75[_0xb08f('0x4e')];if(_0x5b48c4[_0xb08f('0x28')]===0x0)return[];return db['sequelize']['query'](_0x3a5db3[_0xb08f('0xa5')](),_0x2e30c8)[_0xb08f('0x2f')](function(_0xe8b90b){_0x4b2ce8=_['keyBy'](_0xe8b90b,'id');_0x2e30c8=_[_0xb08f('0xa6')](_0x2e30c8,{'model':db[_0xb08f('0xa7')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x31b8f7['query'][_0xb08f('0x4d')]){_0xd45da0[_0xb08f('0x4c')][_0xb08f('0x3b')](function(_0xff7bb9){_0x29ede4['field']('i.'+_0xff7bb9);});}else{_0x29ede4[_0xb08f('0x55')](_0xb08f('0xa8'),_0xb08f('0xa9'));_0x29ede4[_0xb08f('0x55')]('a.key','Account.key');_0x29ede4[_0xb08f('0x55')](_0xb08f('0xaa'),'Account.mandatoryDisposition');_0x29ede4[_0xb08f('0x55')](_0xb08f('0xab'),_0xb08f('0x9b'));_0x29ede4[_0xb08f('0x55')](_0xb08f('0x98'));_0x29ede4[_0xb08f('0x55')](_0xb08f('0xac'));_0x29ede4[_0xb08f('0x55')](_0xb08f('0xad'));_0x29ede4[_0xb08f('0x55')](_0xb08f('0xae'));_0x29ede4[_0xb08f('0x55')](_0xb08f('0xaf'));_0x29ede4[_0xb08f('0x55')](_0xb08f('0xb0'));_0x29ede4[_0xb08f('0x55')](_0xb08f('0xb1'));_0x29ede4[_0xb08f('0x55')](_0xb08f('0xb2'));_0x29ede4[_0xb08f('0x55')](_0xb08f('0xb3'));_0x29ede4[_0xb08f('0x55')](_0xb08f('0xb4'));_0x29ede4['field'](_0xb08f('0xb5'));_0x29ede4[_0xb08f('0x55')](_0xb08f('0xb6'));_0x29ede4[_0xb08f('0x55')]('i.substatus');_0x29ede4[_0xb08f('0x55')](_0xb08f('0xb7'));_0x29ede4[_0xb08f('0x55')](_0xb08f('0xb8'));_0x29ede4[_0xb08f('0x55')](_0xb08f('0xb9'));_0x29ede4['field'](_0xb08f('0xba'));_0x29ede4[_0xb08f('0x55')](_0xb08f('0xbb'),_0xb08f('0xbc'));_0x29ede4[_0xb08f('0x55')](_0xb08f('0xbd'),_0xb08f('0xbe'));_0x29ede4[_0xb08f('0x55')]('c.email',_0xb08f('0xbf'));_0x29ede4['field'](_0xb08f('0xc0'),_0xb08f('0xc1'));_0x29ede4[_0xb08f('0x55')]('c.mobile',_0xb08f('0xc2'));_0x29ede4[_0xb08f('0x55')](_0xb08f('0xc3'),'Contact.fax');_0x29ede4[_0xb08f('0x55')](_0xb08f('0xc4'),_0xb08f('0xc5'));_0x29ede4[_0xb08f('0x55')]('o.internal',_0xb08f('0xc6'));_0x29ede4['field'](_0xb08f('0xc7'),_0xb08f('0x39'));}if(_0xd45da0[_0xb08f('0x27')])_0x29ede4[_0xb08f('0x27')](_0xd45da0[_0xb08f('0x27')]);if(_0xd45da0[_0xb08f('0x25')])_0x29ede4[_0xb08f('0x25')](_0xd45da0[_0xb08f('0x25')]);return db[_0xb08f('0xa4')]['query'](_0x29ede4['toString'](),_0x2e30c8);})[_0xb08f('0x2f')](function(_0x395525){if(_0x395525[_0xb08f('0x4e')]>0x0)_0x531302[_0xb08f('0x53')](_0xb08f('0xc8'),_[_0xb08f('0x37')](_0x395525,'id'));return db[_0xb08f('0xa4')][_0xb08f('0x48')](_0x531302['toString'](),_0x2e30c8)['then'](function(_0x4c620a){var _0x1bb508=_['groupBy'](_0x4c620a,_0xb08f('0xc9'));var _0x15cee1=[];return db['Setting'][_0xb08f('0x3e')]({'attributes':[_0xb08f('0xca')],'raw':!![]})[_0xb08f('0x2f')](function(_0x3ffc7e){var _0x4c3fbf=_0x3ffc7e[_0xb08f('0xca')];_0x395525[_0xb08f('0x3b')](function(_0x48dc87){_0x15cee1[_0xb08f('0x3c')](updateMailInteraction(_0x48dc87,_0x4b2ce8,_0x1bb508,_0x4c3fbf));});return BPromise['all'](_0x15cee1);});});});})['then'](function(_0x3844c8){_0x5b48c4[_0xb08f('0xcb')]=_0x3844c8;return _0x5b48c4;})['then'](respondWithFilteredResult(_0x440faa,_0xd45da0))[_0xb08f('0x43')](handleError(_0x440faa,null));};exports[_0xb08f('0xcc')]=function(_0x51cb82,_0x54878f){var _0x38bae4={'raw':![],'where':{'id':_0x51cb82[_0xb08f('0xcd')]['id']}},_0x2a8deb={};_0x2a8deb[_0xb08f('0x4b')]=_['keys'](db[_0xb08f('0xa7')][_0xb08f('0x45')]);_0x2a8deb[_0xb08f('0x48')]=_[_0xb08f('0x81')](_0x51cb82[_0xb08f('0x48')]);_0x2a8deb[_0xb08f('0x49')]=_[_0xb08f('0x4a')](_0x2a8deb[_0xb08f('0x4b')],_0x2a8deb[_0xb08f('0x48')]);_0x38bae4['attributes']=_[_0xb08f('0x4a')](_0x2a8deb[_0xb08f('0x4b')],qs[_0xb08f('0x4d')](_0x51cb82[_0xb08f('0x48')][_0xb08f('0x4d')]));_0x38bae4[_0xb08f('0x4c')]=_0x38bae4[_0xb08f('0x4c')]['length']?_0x38bae4[_0xb08f('0x4c')]:_0x2a8deb['model'];if(_0x51cb82['query'][_0xb08f('0xce')]){_0x38bae4[_0xb08f('0xcf')]=[{'all':!![]}];}_0x38bae4=_[_0xb08f('0xa6')]({},_0x38bae4,_0x51cb82['options']);return db[_0xb08f('0xa7')][_0xb08f('0x6c')](_0x38bae4)[_0xb08f('0x2f')](handleEntityNotFound(_0x54878f,null))[_0xb08f('0x2f')](respondWithResult(_0x54878f,null))[_0xb08f('0x43')](handleError(_0x54878f,null));};exports[_0xb08f('0xd0')]=function(_0x47e5d7,_0x15ffc1){return db['MailInteraction'][_0xb08f('0xd0')](_0x47e5d7['body'],{})['then'](respondWithResult(_0x15ffc1,0xc9))[_0xb08f('0x43')](handleError(_0x15ffc1,null));};exports[_0xb08f('0x2e')]=function(_0x53bcbd,_0x292c2f){if(_0x53bcbd[_0xb08f('0xd1')]['id']){delete _0x53bcbd[_0xb08f('0xd1')]['id'];}return db['MailInteraction'][_0xb08f('0x6c')]({'where':{'id':_0x53bcbd[_0xb08f('0xcd')]['id']}})[_0xb08f('0x2f')](handleEntityNotFound(_0x292c2f,null))[_0xb08f('0x2f')](saveUpdates(_0x53bcbd[_0xb08f('0xd1')],null))[_0xb08f('0x2f')](respondWithResult(_0x292c2f,null))[_0xb08f('0x43')](handleError(_0x292c2f,null));};exports[_0xb08f('0x30')]=function(_0x5a8057,_0x3c3f9b){return db[_0xb08f('0xa7')][_0xb08f('0x6c')]({'where':{'id':_0x5a8057[_0xb08f('0xcd')]['id']}})[_0xb08f('0x2f')](handleEntityNotFound(_0x3c3f9b,null))[_0xb08f('0x2f')](removeEntity(_0x3c3f9b,null))[_0xb08f('0x43')](handleError(_0x3c3f9b,null));};exports[_0xb08f('0xd2')]=function(_0x49b33a,_0x5dc15f){return db[_0xb08f('0xa7')][_0xb08f('0xd2')]()[_0xb08f('0x2f')](respondWithResult(_0x5dc15f,null))[_0xb08f('0x43')](handleError(_0x5dc15f,null));};exports['addMessage']=function(_0x46e32f,_0x2cfe81,_0xddbaab){return db[_0xb08f('0x3d')][_0xb08f('0x6c')]({'where':{'id':_0x46e32f[_0xb08f('0xcd')]['id']}})['then'](handleEntityNotFound(_0x2cfe81,null))[_0xb08f('0x2f')](function(_0x375409){if(_0x375409){return _0x375409[_0xb08f('0xd3')](_0x46e32f['body'][_0xb08f('0xd4')],_['omit'](_0x46e32f['body'],[_0xb08f('0xd4'),'id'])||{});}})[_0xb08f('0x2f')](respondWithResult(_0x2cfe81,null))[_0xb08f('0x43')](handleError(_0x2cfe81,null));};exports[_0xb08f('0xd5')]=function(_0x5c139f,_0x28a793,_0x841ab2){var _0xd64fb1={'raw':![],'where':{}};var _0x478438={};var _0x14b3ec={'count':0x0,'rows':[]};return db[_0xb08f('0xa7')][_0xb08f('0x3e')]({'where':{'id':_0x5c139f['params']['id']}})['then'](handleEntityNotFound(_0x28a793,null))['then'](function(_0x201bc3){if(_0x201bc3){_0x478438[_0xb08f('0x4b')]=_[_0xb08f('0x81')](db[_0xb08f('0x3d')][_0xb08f('0x45')]);_0x478438[_0xb08f('0x48')]=_['keys'](_0x5c139f[_0xb08f('0x48')]);_0x478438['filters']=_[_0xb08f('0x4a')](_0x478438['model'],_0x478438[_0xb08f('0x48')]);_0xd64fb1[_0xb08f('0x4c')]=_[_0xb08f('0x4a')](_0x478438['model'],qs[_0xb08f('0x4d')](_0x5c139f[_0xb08f('0x48')][_0xb08f('0x4d')]));_0xd64fb1[_0xb08f('0x4c')]=_0xd64fb1[_0xb08f('0x4c')][_0xb08f('0x4e')]?_0xd64fb1[_0xb08f('0x4c')]:_0x478438[_0xb08f('0x4b')];if(!_0x5c139f[_0xb08f('0x48')][_0xb08f('0x4f')](_0xb08f('0x50'))){_0xd64fb1[_0xb08f('0x27')]=qs[_0xb08f('0x27')](_0x5c139f[_0xb08f('0x48')][_0xb08f('0x27')]);_0xd64fb1[_0xb08f('0x25')]=qs['offset'](_0x5c139f[_0xb08f('0x48')]['offset']);}_0xd64fb1[_0xb08f('0x51')]=qs[_0xb08f('0x52')](_0x5c139f[_0xb08f('0x48')][_0xb08f('0x52')]);_0xd64fb1['where']=qs[_0xb08f('0x49')](_[_0xb08f('0x54')](_0x5c139f[_0xb08f('0x48')],_0x478438[_0xb08f('0x49')]));_0xd64fb1['where'][_0xb08f('0xc9')]=_0x201bc3['id'];if(_0x5c139f[_0xb08f('0x48')][_0xb08f('0x92')]){_0xd64fb1[_0xb08f('0x53')]=_[_0xb08f('0xa6')](_0xd64fb1[_0xb08f('0x53')],{'$or':_[_0xb08f('0x37')](_0xd64fb1[_0xb08f('0x4c')],function(_0x252fcc){var _0x3f32a1={};_0x3f32a1[_0x252fcc]={'$like':'%'+_0x5c139f[_0xb08f('0x48')][_0xb08f('0x92')]+'%'};return _0x3f32a1;})});}if(_0x5c139f[_0xb08f('0x48')]['$gte']){var _0x41add4=_0x5c139f[_0xb08f('0x48')][_0xb08f('0xd6')]['split'](',');var _0x816f3b={};_0x816f3b[_0x41add4[0x0]]={'$gte':moment(_0x41add4[0x1])[_0xb08f('0xd7')](_0xb08f('0xd8'))};_0xd64fb1[_0xb08f('0x53')]=_['merge'](_0xd64fb1[_0xb08f('0x53')],_0x816f3b);}_0xd64fb1=_['merge']({},_0xd64fb1,_0x5c139f[_0xb08f('0xd9')]);return db[_0xb08f('0x3d')][_0xb08f('0x28')]({'where':_0xd64fb1[_0xb08f('0x53')]})['then'](function(_0x1c737e){_0x14b3ec[_0xb08f('0x28')]=_0x1c737e;if(_0x5c139f[_0xb08f('0x48')][_0xb08f('0xce')]){_0xd64fb1['include']=[{'all':!![]}];}return db[_0xb08f('0x3d')]['findAll'](_0xd64fb1);})[_0xb08f('0x2f')](function(_0xe95abb){if(_0x5c139f[_0xb08f('0x48')][_0xb08f('0xda')]===_0xb08f('0xdb')){for(var _0x2945fd=0x0;_0x2945fd<_0xe95abb[_0xb08f('0x4e')];_0x2945fd++){_0xe95abb[_0x2945fd][_0xb08f('0xd1')]=juice(_0xe95abb[_0x2945fd][_0xb08f('0xd1')]);}}_0x14b3ec[_0xb08f('0xcb')]=_0xe95abb;return _0x14b3ec;});}})[_0xb08f('0x2f')](respondWithFilteredResult(_0x28a793,_0xd64fb1))[_0xb08f('0x43')](handleError(_0x28a793,null));};exports[_0xb08f('0xdc')]=function(_0x5e54db,_0x58c4bb,_0x3fe7bf){return db[_0xb08f('0xa7')][_0xb08f('0x6c')]({'where':{'id':_0x5e54db['params']['id']}})[_0xb08f('0x2f')](handleEntityNotFound(_0x58c4bb,null))[_0xb08f('0x2f')](function(_0x18ba58){if(_0x18ba58){return _0x18ba58[_0xb08f('0xdd')](_0x5e54db['body'][_0xb08f('0xd4')],_[_0xb08f('0xde')](_0x5e54db[_0xb08f('0xd1')],[_0xb08f('0xd4'),'id'])||{})['spread'](function(){return db[_0xb08f('0x7b')][_0xb08f('0xdf')]({'attributes':['id',_0xb08f('0x34'),'color'],'where':{'id':_0x5e54db[_0xb08f('0xd1')][_0xb08f('0xd4')]}});})['then'](function(_0x130319){socket[_0xb08f('0xe0')](_0xb08f('0xe1'),{'id':Number(_0x5e54db['params']['id']),'tags':_0x130319||[]});return{'id':Number(_0x5e54db['params']['id']),'tags':_0x130319||[]};});}})['then'](respondWithResult(_0x58c4bb,null))[_0xb08f('0x43')](handleError(_0x58c4bb,null));};exports[_0xb08f('0xe2')]=function(_0x541168,_0x57af76,_0x15ab32){return db[_0xb08f('0xa7')][_0xb08f('0x6c')]({'where':{'id':_0x541168[_0xb08f('0xcd')]['id']}})[_0xb08f('0x2f')](handleEntityNotFound(_0x57af76,null))[_0xb08f('0x2f')](function(_0x23c81a){if(_0x23c81a){return _0x23c81a['removeTags'](_0x541168[_0xb08f('0x48')]['ids']);}})[_0xb08f('0x2f')](respondWithStatusCode(_0x57af76,null))[_0xb08f('0x43')](handleError(_0x57af76,null));};exports[_0xb08f('0xe3')]=function(_0x50d801,_0x246987){var _0x9ecba4=moment()[_0xb08f('0xe4')]()[_0xb08f('0xa5')]();var _0x231179=path[_0xb08f('0xe5')](config[_0xb08f('0xe6')],'server',_0xb08f('0xe7'),_0xb08f('0xe8'));var _0x3b37a1=path[_0xb08f('0xe5')](config['root'],_0xb08f('0xe9'),'files','attachments');var _0x5b956a=path[_0xb08f('0xe5')](_0x231179,_0x9ecba4);var _0x8e4a62=util[_0xb08f('0xd7')](_0xb08f('0xea'),_0x50d801[_0xb08f('0xcd')]['id'],_0x9ecba4);var _0x387e4c=path[_0xb08f('0xe5')](_0x231179,_0x8e4a62);var _0x5b6af2=[];if(_0x50d801[_0xb08f('0x48')]['attachments']){_0x5b6af2['push']({'model':db[_0xb08f('0xeb')],'as':_0xb08f('0xec'),'raw':!![]});}var _0x344df9=[{'model':db[_0xb08f('0x3d')],'as':_0xb08f('0xed'),'attributes':['id',_0xb08f('0xd1'),_0xb08f('0x56'),'to','cc',_0xb08f('0xee'),_0xb08f('0xef'),_0xb08f('0xf0')],'where':{'secret':![]},'order':qs[_0xb08f('0x52')]('id'),'include':_0x5b6af2}];return db['MailInteraction'][_0xb08f('0x6c')]({'where':{'id':_0x50d801['params']['id']},'include':_0x344df9})['then'](handleEntityNotFound(_0x246987,null))[_0xb08f('0x2f')](function(_0x5f34a1){if(_0x5f34a1&&_0x5f34a1['Messages']){var _0x1770d9=_0x5f34a1[_0xb08f('0xf1')]({'plain':!![]});fs['mkdirSync'](_0x5b956a);return BPromise[_0xb08f('0xf2')](_0x1770d9['Messages'],function(_0x4f2fe7,_0x17ea62){var _0x197837={'from':_0x4f2fe7['from'],'to':_0x4f2fe7['to'],'subject':_0x4f2fe7[_0xb08f('0xef')],'html':_0x4f2fe7['body'],'headers':{'Date':moment(_0x4f2fe7[_0xb08f('0xf0')])[_0xb08f('0xd7')]('ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ')},'attachments':[]};if(_0x4f2fe7['cc']){_0x197837['headers']['Cc']=_0x4f2fe7['cc'];}if(_0x4f2fe7[_0xb08f('0xee')]){_0x197837[_0xb08f('0xf3')][_0xb08f('0xf4')]=_0x4f2fe7[_0xb08f('0xee')];}return new BPromise(function(_0x63ef47,_0x20d3f7){if(_0x4f2fe7[_0xb08f('0xec')]){for(var _0x25feb4=0x0;_0x25feb4<_0x4f2fe7[_0xb08f('0xec')][_0xb08f('0x4e')];_0x25feb4++){var _0x49af8b=_0x4f2fe7[_0xb08f('0xec')][_0x25feb4];var _0x451747=path[_0xb08f('0xe5')](_0x3b37a1,_0x49af8b[_0xb08f('0xf5')]);if(fs[_0xb08f('0xf6')](_0x451747)){_0x197837[_0xb08f('0xf7')][_0xb08f('0x3c')]({'name':_0x49af8b[_0xb08f('0x34')],'contentType':_0x49af8b['type'],'data':fs[_0xb08f('0xf8')](_0x451747)});}}}emlformat['build'](_0x197837,function(_0x580b1a,_0x5ed25d){if(_0x580b1a)return _0x20d3f7(_0x580b1a);fs[_0xb08f('0xf9')](path[_0xb08f('0xe5')](_0x5b956a,util[_0xb08f('0xd7')](_0xb08f('0xfa'),_0x17ea62)),_0x5ed25d);return _0x63ef47(_0x5ed25d);});});})['then'](function(){return new BPromise(function(_0x22f1cc,_0x3e0980){zipdir(_0x5b956a,{'saveTo':_0x387e4c},function(_0x15c1d2,_0x50ae2a){if(_0x15c1d2)return _0x3e0980(_0x15c1d2);return _0x22f1cc(_0x50ae2a);});})[_0xb08f('0x2f')](function(){return new BPromise(function(_0x5cbc15,_0x5de582){rimraf(_0x5b956a,function(_0x3b983f){if(_0x3b983f)_0x5de582(_0x3b983f);return _0x5cbc15();});});})[_0xb08f('0x2f')](function(){return _0x246987[_0xb08f('0xe3')](_0x387e4c,_0x8e4a62,function(_0x29c6dd){if(_0x29c6dd){console[_0xb08f('0xfb')](_0xb08f('0xfc'),_0x29c6dd);}else{fs[_0xb08f('0xfd')](_0x387e4c);}});});});}else{return _0x246987[_0xb08f('0x22')](0xc8);}})[_0xb08f('0x43')](handleError(_0x246987,null));};
\ No newline at end of file
+var _0x314d=['MATCH\x20(me.plainBody,\x20me.subject)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','group','i.id','Sequelize','SELECT','clone','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','order','contactName','DESC','isEmpty','resolve','i.MailAccountId\x20IS\x20NOT\x20NULL','i.MailAccountId\x20IS\x20NULL','user','agent','sequelize','toString','MailInteraction','a.key','Account.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.closedAt','i.attach','i.lastMsgAt','i.lastMsgDirection','i.subject','i.thirdDisposition','i.substatus','i.to','i.ContactId','c.firstName','Contact.firstName','c.lastName','c.phone','c.mobile','Contact.mobile','c.fax','Contact.fax','Owner.fullname','o.internal','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','ui.MailInteractionId\x20IN\x20?','groupBy','Setting','enableEmailPreview','all','rows','show','params','includeAll','include','merge','options','create','body','describe','addMessage','ids','omit','hasOwnProperty','MailInteractionId','format','YYYY-MM-DD\x20HH:mm:ss','findAll','inlineCss','setTags','spread','emit','mailInteractionTags:save','removeTags','download','unix','join','root','server','files','tmp','attachments','Attachment','Attachments','Messages','bcc','get','mkdirSync','each','ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ','headers','Bcc','basename','existsSync','readFileSync','build','writeFileSync','message%d.eml','log','unlinkSync','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','papaparse','html-to-text','juice','ioredis','../../components/auth/service','../../config/license/hardware','api','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','./mailInteraction.socket','register','sendStatus','status','undefined','limit','count','offset','Content-Range','apply','reject','save','update','destroy','then','end','error','name','send','fullname','TagIds','Tags','forEach','push','MailMessage','findOne','plainBody','lastMsgText','trimStart','catch','index','rawAttributes','type','key','model','map','keys','filters','intersection','fields','query','attributes','length','nolimit','sort','where','pick','field','color','from','select','u.fullname','ui.MailInteractionId','user_has_mail_interactions','users','u.id\x20=\x20ui.UserId','mail_interactions','cm_contacts','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','left_join','o.id\x20=\x20i.UserId','mail_accounts','a.id\x20=\x20i.MailAccountId','me.MailInteractionId\x20=\x20i.id','mail_interaction_has_tags','it.MailInteractionId\x20=\x20i.id','tools_tags','t.id\x20=\x20it.TagId','expr','parseSearch','search','sqlOperator','conditions','find','unreadMessages','value','having','`\x20=\x200','`\x20>\x200','Contact','$substring','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','text','start','Tag','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','User','operator','UserId','some','compact','MailAccountId','i.MailAccountId\x20IN\x20?','concat','createdAt','parse','$gte','$lte','null','\x20IS\x20NULL','read','`unreadMessages`\x20=\x200','`unreadMessages`\x20>\x200','tag','filter','replace','isNumeric','i.id\x20LIKE\x20?','isEmail','MATCH\x20(i.to,\x20i.subject)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)'];(function(_0x4cf98e,_0xba4b79){var _0x1623ac=function(_0x459bc0){while(--_0x459bc0){_0x4cf98e['push'](_0x4cf98e['shift']());}};_0x1623ac(++_0xba4b79);}(_0x314d,0x15f));var _0xd314=function(_0x19932a,_0x174182){_0x19932a=_0x19932a-0x0;var _0x1724fa=_0x314d[_0x19932a];return _0x1724fa;};'use strict';var emlformat=require(_0xd314('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xd314('0x1'));var jsonpatch=require(_0xd314('0x2'));var rp=require(_0xd314('0x3'));var moment=require(_0xd314('0x4'));var BPromise=require(_0xd314('0x5'));var Mustache=require(_0xd314('0x6'));var util=require(_0xd314('0x7'));var path=require(_0xd314('0x8'));var sox=require('sox');var csv=require(_0xd314('0x9'));var ejs=require(_0xd314('0xa'));var fs=require('fs');var fs_extra=require(_0xd314('0xb'));var _=require(_0xd314('0xc'));var squel=require(_0xd314('0xd'));var crypto=require(_0xd314('0xe'));var jsforce=require(_0xd314('0xf'));var deskjs=require(_0xd314('0x10'));var toCsv=require(_0xd314('0x9'));var querystring=require('querystring');var Papa=require(_0xd314('0x11'));var htmlToText=require(_0xd314('0x12'));var juice=require(_0xd314('0x13'));var Redis=require(_0xd314('0x14'));var authService=require(_0xd314('0x15'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xd314('0x16'));var logger=require('../../config/logger')(_0xd314('0x17'));var utils=require('../../config/utils');var config=require(_0xd314('0x18'));var licenseUtil=require(_0xd314('0x19'));var db=require(_0xd314('0x1a'))['db'];config[_0xd314('0x1b')]=_[_0xd314('0x1c')](config['redis'],{'host':_0xd314('0x1d'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xd314('0x1b')]));require(_0xd314('0x1e'))[_0xd314('0x1f')](socket);function respondWithStatusCode(_0x4da431,_0x1ebb03){_0x1ebb03=_0x1ebb03||0xcc;return function(_0x26d079){if(_0x26d079){return _0x4da431[_0xd314('0x20')](_0x1ebb03);}return _0x4da431['status'](_0x1ebb03)['end']();};}function respondWithResult(_0x2de9b0,_0xe030eb){_0xe030eb=_0xe030eb||0xc8;return function(_0x50f81d){if(_0x50f81d){return _0x2de9b0[_0xd314('0x21')](_0xe030eb)['json'](_0x50f81d);}};}function respondWithFilteredResult(_0x5e3a9e,_0x229475){return function(_0x579b30){if(_0x579b30){var _0x489c2c=typeof _0x229475['offset']===_0xd314('0x22')&&typeof _0x229475[_0xd314('0x23')]===_0xd314('0x22');var _0x3c231f=_0x579b30[_0xd314('0x24')];var _0x18f669=_0x489c2c?0x0:_0x229475[_0xd314('0x25')];var _0x1405a3=_0x489c2c?_0x579b30[_0xd314('0x24')]:_0x229475[_0xd314('0x25')]+_0x229475[_0xd314('0x23')];var _0x37bc63;if(_0x1405a3>=_0x3c231f){_0x1405a3=_0x3c231f;_0x37bc63=0xc8;}else{_0x37bc63=0xce;}_0x5e3a9e[_0xd314('0x21')](_0x37bc63);return _0x5e3a9e['set'](_0xd314('0x26'),_0x18f669+'-'+_0x1405a3+'/'+_0x3c231f)['json'](_0x579b30);}return null;};}function patchUpdates(_0x5947ad){return function(_0x1a8f5c){try{jsonpatch[_0xd314('0x27')](_0x1a8f5c,_0x5947ad,!![]);}catch(_0x55822b){return BPromise[_0xd314('0x28')](_0x55822b);}return _0x1a8f5c[_0xd314('0x29')]();};}function saveUpdates(_0x2a85e5,_0x3e68c3){return function(_0x48468d){if(_0x48468d){return _0x48468d[_0xd314('0x2a')](_0x2a85e5)['then'](function(_0x28af48){return _0x28af48;});}return null;};}function removeEntity(_0x2633ae,_0x1fd3a9){return function(_0x40877a){if(_0x40877a){return _0x40877a[_0xd314('0x2b')]()[_0xd314('0x2c')](function(){_0x2633ae[_0xd314('0x21')](0xcc)[_0xd314('0x2d')]();});}};}function handleEntityNotFound(_0x5c7563,_0x219bae){return function(_0x21d0a7){if(!_0x21d0a7){_0x5c7563[_0xd314('0x20')](0x194);}return _0x21d0a7;};}function handleError(_0xa82c2d,_0x32113b){_0x32113b=_0x32113b||0x1f4;return function(_0x242f41){logger[_0xd314('0x2e')](_0x242f41['stack']);if(_0x242f41[_0xd314('0x2f')]){delete _0x242f41['name'];}_0xa82c2d[_0xd314('0x21')](_0x32113b)[_0xd314('0x30')](_0x242f41);};}function getInteractionUsers(_0x446a01,_0x270693){return new BPromise(function(_0x340991,_0x4d9a68){try{if(_0x270693[_0x446a01['id']]){_0x446a01['Users']=_['map'](_0x270693[_0x446a01['id']],function(_0x49a94e){return{'id':_0x49a94e['id'],'fullname':_0x49a94e[_0xd314('0x31')]};});}}catch(_0x57a6e2){_0x4d9a68(_0x57a6e2);}_0x340991(_0x446a01);});}function getInteractionTags(_0x43b628,_0x1129dc){return new BPromise(function(_0x2b1dc4,_0x1db195){try{if(_0x43b628[_0xd314('0x32')]){_0x43b628[_0xd314('0x33')]=[];_0x43b628['TagIds']['split'](',')[_0xd314('0x34')](function(_0x561f00){_0x43b628[_0xd314('0x33')][_0xd314('0x35')](_0x1129dc[_0x561f00]);});}delete _0x43b628['TagIds'];}catch(_0x10a35b){_0x1db195(_0x10a35b);}_0x2b1dc4(_0x43b628);});}function getLastMessageText(_0xa14b33){return new BPromise(function(_0x1d0f05,_0x52d269){return db[_0xd314('0x36')][_0xd314('0x37')]({'where':{'$and':[{'MailInteractionId':_0xa14b33['id']},{'$or':[{'direction':'in'},{'$and':[{'direction':'out'},{'secret':![]},{'UserId':{'$ne':null}}]}]}]},'attributes':[_0xd314('0x38')],'order':'-id','raw':!![]})[_0xd314('0x2c')](function(_0x169a16){if(_0x169a16&&_0x169a16[_0xd314('0x38')]){_0xa14b33[_0xd314('0x39')]=_[_0xd314('0x3a')](_0x169a16['plainBody']);}_0x1d0f05(_0xa14b33);})[_0xd314('0x3b')](function(_0x36605){_0x52d269(_0x36605);});});}function updateMailInteraction(_0x1c2355,_0x522c46,_0x3ce4c7,_0x28054a){return new BPromise(function(_0x357528,_0xbfca0a){return getInteractionUsers(_0x1c2355,_0x3ce4c7)['then'](function(_0x226ff9){return getInteractionTags(_0x226ff9,_0x522c46);})['then'](function(_0x4fde10){if(_0x28054a){_0x357528(getLastMessageText(_0x4fde10));}else{_0x357528(_0x4fde10);}})[_0xd314('0x3b')](function(_0xd39096){_0xbfca0a(_0xd39096);});});}exports[_0xd314('0x3c')]=function(_0x33b227,_0x2049e9){var _0x3d91a0={},_0x3c6e4a={},_0x2320fb={'count':0x0,'rows':[]};var _0x537dcf=_['map'](db['MailInteraction'][_0xd314('0x3d')],function(_0x3d75cf){return{'name':_0x3d75cf['fieldName'],'type':_0x3d75cf[_0xd314('0x3e')][_0xd314('0x3f')]};});_0x3c6e4a[_0xd314('0x40')]=_[_0xd314('0x41')](_0x537dcf,_0xd314('0x2f'));_0x3c6e4a['query']=_[_0xd314('0x42')](_0x33b227['query']);_0x3c6e4a[_0xd314('0x43')]=_[_0xd314('0x44')](_0x3c6e4a['model'],_0x3c6e4a['query']);_0x3d91a0['attributes']=_[_0xd314('0x44')](_0x3c6e4a[_0xd314('0x40')],qs[_0xd314('0x45')](_0x33b227[_0xd314('0x46')]['fields']));_0x3d91a0[_0xd314('0x47')]=_0x3d91a0[_0xd314('0x47')][_0xd314('0x48')]?_0x3d91a0['attributes']:_0x3c6e4a[_0xd314('0x40')];if(!_0x33b227['query']['hasOwnProperty'](_0xd314('0x49'))){_0x3d91a0[_0xd314('0x23')]=qs['limit'](_0x33b227[_0xd314('0x46')][_0xd314('0x23')]);_0x3d91a0[_0xd314('0x25')]=qs[_0xd314('0x25')](_0x33b227[_0xd314('0x46')][_0xd314('0x25')]);}_0x3d91a0['order']=qs[_0xd314('0x4a')](_0x33b227[_0xd314('0x46')]['sort']);_0x3d91a0[_0xd314('0x4b')]=qs['filters'](_[_0xd314('0x4c')](_0x33b227[_0xd314('0x46')],_0x3c6e4a['filters']),_0x537dcf);var _0x252427=[];var _0x11dde6=squel['select']()['field']('id')[_0xd314('0x4d')](_0xd314('0x2f'))['field'](_0xd314('0x4e'))[_0xd314('0x4f')]('tools_tags');var _0x2a04f3=squel[_0xd314('0x50')]()['field']('u.id')[_0xd314('0x4d')](_0xd314('0x51'))[_0xd314('0x4d')](_0xd314('0x52'))[_0xd314('0x4f')](_0xd314('0x53'),'ui')['left_join'](_0xd314('0x54'),'u',_0xd314('0x55'));var _0x8a646e=squel[_0xd314('0x50')]()[_0xd314('0x4f')](_0xd314('0x56'),'i')['left_join'](_0xd314('0x57'),'c',_0xd314('0x58'))[_0xd314('0x59')](_0xd314('0x54'),'o',_0xd314('0x5a'))['left_join'](_0xd314('0x5b'),'a',_0xd314('0x5c'))['left_join']('mail_messages','me',_0xd314('0x5d'))['left_join'](_0xd314('0x5e'),'it',_0xd314('0x5f'))[_0xd314('0x59')](_0xd314('0x60'),'t',_0xd314('0x61'));var _0x324cfe=squel[_0xd314('0x62')]();var _0x2dfc8d=[];var _0x189938=squel[_0xd314('0x62')]();var _0x3744a1;if(_0x33b227[_0xd314('0x46')]['search']){_0x3744a1=as[_0xd314('0x63')](_0x33b227[_0xd314('0x46')][_0xd314('0x64')]);var _0x190345=_0x3744a1[_0xd314('0x65')];for(var _0x289d73=0x0;_0x289d73<_0x3744a1['conditions']['length'];_0x289d73++){var _0x1963a8=_0x3744a1[_0xd314('0x66')][_0x289d73];var _0x95b941='i';var _0x2cf161=_[_0xd314('0x67')](_0x537dcf,[_0xd314('0x2f'),_0x1963a8[_0xd314('0x4d')]]);if(!_0x2cf161){switch(_0x1963a8[_0xd314('0x4d')]){case _0xd314('0x68'):if(_0x1963a8[_0xd314('0x69')]==0x1){_0x8a646e[_0xd314('0x6a')]('`'+_0x1963a8[_0xd314('0x4d')]+_0xd314('0x6b'));}else{_0x8a646e[_0xd314('0x6a')]('`'+_0x1963a8['field']+_0xd314('0x6c'));}break;case _0xd314('0x6d'):if(_0x1963a8['operator']===_0xd314('0x6e')){if(_0x1963a8['value'][_0xd314('0x6f')]('\x20')[_0xd314('0x48')]>0x1){_0x324cfe[_0x190345](_0xd314('0x70'),qs[_0xd314('0x71')](_0x1963a8['value']),null);}else{var _0x202ae7='%'+_0x1963a8['value']+'%';_0x324cfe[_0x190345](_0xd314('0x72'),_0x202ae7,_0x202ae7,_0x202ae7);}}else{_0x2cf161=_[_0xd314('0x67')](_0x537dcf,['name','ContactId']);_0x1963a8[_0xd314('0x4d')]=_0xd314('0x73');_0x5c1477=as[_0xd314('0x74')](_0x95b941,_0x2cf161[_0xd314('0x3e')],_0x1963a8);_0x324cfe[_0x190345](_0x5c1477[_0xd314('0x75')],_0x5c1477[_0xd314('0x69')][_0xd314('0x76')],_0x5c1477[_0xd314('0x69')][_0xd314('0x2d')]);}break;case _0xd314('0x77'):var _0x21fab7=_0x1963a8[_0xd314('0x69')][_0xd314('0x6f')](',')['map'](function(_0x185529){return Number(_0x185529);});_0x21fab7[_0xd314('0x34')](function(_0x1ab2ad){_0x189938['or'](_0xd314('0x78'),'%,'+_0x1ab2ad+',%');});_0x2dfc8d=_['union'](_0x2dfc8d,_0x21fab7);break;case _0xd314('0x79'):if(_0x1963a8[_0xd314('0x7a')]===_0xd314('0x6e')){_0x324cfe[_0x190345]('CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','%'+_0x1963a8[_0xd314('0x69')]+'%',null);}else{_0x2cf161=_[_0xd314('0x67')](_0x537dcf,[_0xd314('0x2f'),_0xd314('0x7b')]);_0x1963a8[_0xd314('0x4d')]='UserId';_0x5c1477=as['buildExpression'](_0x95b941,_0x2cf161[_0xd314('0x3e')],_0x1963a8);_0x324cfe[_0x190345](_0x5c1477['text'],_0x5c1477[_0xd314('0x69')]['start'],_0x5c1477[_0xd314('0x69')][_0xd314('0x2d')]);}break;case _0xd314('0x38'):_0x5c1477=as['buildExpression']('me',null,_0x1963a8);_0x324cfe[_0x190345](_0x5c1477['text'],_0x5c1477['value']['start'],_0x5c1477[_0xd314('0x69')]['end']);break;}}else{var _0x5c1477=as[_0xd314('0x74')](_0x95b941,_0x2cf161['type'],_0x1963a8);_0x324cfe[_0x190345](_0x5c1477[_0xd314('0x75')],_0x5c1477['value']['start'],_0x5c1477[_0xd314('0x69')][_0xd314('0x2d')]);}}}else{var _0x53c0f2=_(_0x33b227['query'])[_0xd314('0x42')]()['map'](function(_0xa758a3){return _[_0xd314('0x7c')](_0x537dcf,[_0xd314('0x2f'),_0xa758a3])?_0xa758a3:undefined;})[_0xd314('0x7d')]()[_0xd314('0x69')]();if(!_['isEmpty'](_0x53c0f2)){_0x53c0f2['forEach'](function(_0x9e1f95){if(_0x9e1f95===_0xd314('0x7e')){_0x8a646e['where'](_0xd314('0x7f'),[][_0xd314('0x80')](_0x33b227['query'][_0x9e1f95]));}else if(_0x9e1f95===_0xd314('0x81')){var _0x21bbc5=JSON[_0xd314('0x82')](_0x33b227['query'][_0x9e1f95])[_0xd314('0x83')];var _0x5908bb=JSON[_0xd314('0x82')](_0x33b227['query'][_0x9e1f95])[_0xd314('0x84')];_0x8a646e[_0xd314('0x4b')]('i.createdAt\x20BETWEEN\x20?\x20AND\x20?',_0x21bbc5,_0x5908bb);}else{if(_0x33b227['query'][_0x9e1f95]===_0xd314('0x85')){_0x8a646e[_0xd314('0x4b')]('i.'+_0x9e1f95+_0xd314('0x86'));}else{_0x8a646e[_0xd314('0x4b')]('i.'+_0x9e1f95+'\x20=\x20?',_0x33b227[_0xd314('0x46')][_0x9e1f95]);}}});}if(_0x33b227['query'][_0xd314('0x87')]){if(_0x33b227['query'][_0xd314('0x87')]==0x1){_0x8a646e[_0xd314('0x6a')](_0xd314('0x88'));}else{_0x8a646e[_0xd314('0x6a')](_0xd314('0x89'));}}if(_0x33b227[_0xd314('0x46')][_0xd314('0x8a')]){_0x2dfc8d=_['isArray'](_0x33b227[_0xd314('0x46')][_0xd314('0x8a')])?_0x33b227[_0xd314('0x46')]['tag']:new Array(_0x33b227['query']['tag']);_0x2dfc8d[_0xd314('0x34')](function(_0x5799e7){_0x189938['or'](_0xd314('0x78'),'%,'+_0x5799e7+',%');});}if(_0x33b227[_0xd314('0x46')][_0xd314('0x8b')]){var _0x30b2a4=_0x33b227[_0xd314('0x46')][_0xd314('0x8b')][_0xd314('0x8c')]('\x5c','\x5c\x5c')[_0xd314('0x8c')](/'/g,'\x27\x27');if(qs[_0xd314('0x8d')](_0x30b2a4)){_0x324cfe['or'](_0xd314('0x8e'),_0x30b2a4+'%');}else if(qs[_0xd314('0x8f')](_0x30b2a4)){_0x324cfe['or']('c.email\x20LIKE\x20?',_0x30b2a4+'%');}else{_0x324cfe['or'](_0xd314('0x90'),qs[_0xd314('0x71')](_0x30b2a4))['or'](_0xd314('0x91'),qs[_0xd314('0x71')](_0x30b2a4));}}}_0x8a646e[_0xd314('0x4b')](_0x324cfe);_0x8a646e[_0xd314('0x92')](_0xd314('0x93'));var _0x449342={'type':db[_0xd314('0x94')]['QueryTypes'][_0xd314('0x95')],'raw':!![]};var _0x46c167=_0x8a646e[_0xd314('0x96')]();_0x46c167[_0xd314('0x4d')](_0xd314('0x93'));_0x46c167[_0xd314('0x4d')](_0xd314('0x97'),_0xd314('0x68'));if(_0x3d91a0[_0xd314('0x98')]){_0x3d91a0['order'][_0xd314('0x34')](function(_0x49a529){var _0x5cbe49=_0x49a529[0x0]===_0xd314('0x99')?_0x49a529[0x0]:'i.'+_0x49a529[0x0];_0x8a646e[_0xd314('0x98')](_0x5cbe49,_0x49a529[0x1]===_0xd314('0x9a')?![]:!![]);});}if(!_[_0xd314('0x9b')](_0x2dfc8d)){_0x8a646e['having'](_0x189938);_0x46c167[_0xd314('0x4b')]('t.id\x20IN\x20?',_0x2dfc8d);}BPromise[_0xd314('0x9c')]()[_0xd314('0x2c')](function(){if(!_0x3744a1){if(_0x33b227['query'][_0xd314('0x7e')])return;_0x46c167[_0xd314('0x4b')](_0xd314('0x9d'));_0x8a646e[_0xd314('0x4b')](_0xd314('0x9d'));return;}if(_0x33b227['user']['role']!=='agent')return;return _0x33b227['user']['getMailAccounts']({'attributes':['id'],'raw':!![]})[_0xd314('0x2c')](function(_0x4a2226){if(_[_0xd314('0x9b')](_0x4a2226)){_0x46c167[_0xd314('0x4b')](_0xd314('0x9e'));_0x8a646e[_0xd314('0x4b')](_0xd314('0x9e'));}else{_0x46c167[_0xd314('0x4b')](_0xd314('0x7f'),_[_0xd314('0x41')](_0x4a2226,'id'));_0x8a646e['where'](_0xd314('0x7f'),_['map'](_0x4a2226,'id'));}});})[_0xd314('0x2c')](function(){if(_0x33b227[_0xd314('0x9f')]['role']===_0xd314('0xa0')&&!_0x3744a1&&!_0x33b227[_0xd314('0x46')][_0xd314('0x7e')])return[];return db[_0xd314('0xa1')][_0xd314('0x46')](_0x46c167[_0xd314('0xa2')](),_0x449342);})['then'](function(_0x19cec3){_0x2320fb[_0xd314('0x24')]=_0x19cec3['length'];if(_0x2320fb[_0xd314('0x24')]===0x0)return[];return db[_0xd314('0xa1')][_0xd314('0x46')](_0x11dde6[_0xd314('0xa2')](),_0x449342)[_0xd314('0x2c')](function(_0x39d813){_0x252427=_['keyBy'](_0x39d813,'id');_0x449342=_['merge'](_0x449342,{'model':db[_0xd314('0xa3')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x33b227[_0xd314('0x46')][_0xd314('0x45')]){_0x3d91a0['attributes']['forEach'](function(_0x4174b7){_0x8a646e[_0xd314('0x4d')]('i.'+_0x4174b7);});}else{_0x8a646e[_0xd314('0x4d')](_0xd314('0x97'),'unreadMessages');_0x8a646e[_0xd314('0x4d')](_0xd314('0xa4'),_0xd314('0xa5'));_0x8a646e[_0xd314('0x4d')](_0xd314('0xa6'),_0xd314('0xa7'));_0x8a646e[_0xd314('0x4d')](_0xd314('0xa8'),_0xd314('0x99'));_0x8a646e[_0xd314('0x4d')](_0xd314('0x93'));_0x8a646e['field'](_0xd314('0xa9'));_0x8a646e[_0xd314('0x4d')](_0xd314('0xaa'));_0x8a646e[_0xd314('0x4d')](_0xd314('0xab'));_0x8a646e[_0xd314('0x4d')](_0xd314('0xac'));_0x8a646e[_0xd314('0x4d')](_0xd314('0xad'));_0x8a646e[_0xd314('0x4d')](_0xd314('0xae'));_0x8a646e[_0xd314('0x4d')](_0xd314('0xaf'));_0x8a646e[_0xd314('0x4d')](_0xd314('0xb0'));_0x8a646e['field']('i.disposition');_0x8a646e[_0xd314('0x4d')]('i.secondDisposition');_0x8a646e[_0xd314('0x4d')](_0xd314('0xb1'));_0x8a646e['field'](_0xd314('0xb2'));_0x8a646e[_0xd314('0x4d')](_0xd314('0xb3'));_0x8a646e[_0xd314('0x4d')](_0xd314('0xb4'));_0x8a646e[_0xd314('0x4d')]('i.MailAccountId');_0x8a646e['field']('i.UserId');_0x8a646e[_0xd314('0x4d')](_0xd314('0xb5'),_0xd314('0xb6'));_0x8a646e['field'](_0xd314('0xb7'),'Contact.lastName');_0x8a646e[_0xd314('0x4d')]('c.email','Contact.email');_0x8a646e[_0xd314('0x4d')](_0xd314('0xb8'),'Contact.phone');_0x8a646e[_0xd314('0x4d')](_0xd314('0xb9'),_0xd314('0xba'));_0x8a646e[_0xd314('0x4d')](_0xd314('0xbb'),_0xd314('0xbc'));_0x8a646e[_0xd314('0x4d')]('o.fullname',_0xd314('0xbd'));_0x8a646e[_0xd314('0x4d')](_0xd314('0xbe'),_0xd314('0xbf'));_0x8a646e[_0xd314('0x4d')](_0xd314('0xc0'),'TagIds');}if(_0x3d91a0[_0xd314('0x23')])_0x8a646e[_0xd314('0x23')](_0x3d91a0[_0xd314('0x23')]);if(_0x3d91a0[_0xd314('0x25')])_0x8a646e[_0xd314('0x25')](_0x3d91a0[_0xd314('0x25')]);return db[_0xd314('0xa1')][_0xd314('0x46')](_0x8a646e[_0xd314('0xa2')](),_0x449342);})[_0xd314('0x2c')](function(_0x55ab91){if(_0x55ab91['length']>0x0)_0x2a04f3[_0xd314('0x4b')](_0xd314('0xc1'),_['map'](_0x55ab91,'id'));return db[_0xd314('0xa1')][_0xd314('0x46')](_0x2a04f3[_0xd314('0xa2')](),_0x449342)['then'](function(_0x3b4f34){var _0xe84dc0=_[_0xd314('0xc2')](_0x3b4f34,'MailInteractionId');var _0x36710e=[];return db[_0xd314('0xc3')][_0xd314('0x37')]({'attributes':['enableEmailPreview'],'raw':!![]})[_0xd314('0x2c')](function(_0x22bde0){var _0x31ff2f=_0x22bde0[_0xd314('0xc4')];_0x55ab91[_0xd314('0x34')](function(_0x48a56a){_0x36710e[_0xd314('0x35')](updateMailInteraction(_0x48a56a,_0x252427,_0xe84dc0,_0x31ff2f));});return BPromise[_0xd314('0xc5')](_0x36710e);});});});})[_0xd314('0x2c')](function(_0x4de541){_0x2320fb[_0xd314('0xc6')]=_0x4de541;return _0x2320fb;})['then'](respondWithFilteredResult(_0x2049e9,_0x3d91a0))['catch'](handleError(_0x2049e9,null));};exports[_0xd314('0xc7')]=function(_0x4ceb8b,_0x8261c5){var _0x26814e={'raw':![],'where':{'id':_0x4ceb8b[_0xd314('0xc8')]['id']}},_0x46ed1c={};_0x46ed1c[_0xd314('0x40')]=_[_0xd314('0x42')](db[_0xd314('0xa3')][_0xd314('0x3d')]);_0x46ed1c[_0xd314('0x46')]=_[_0xd314('0x42')](_0x4ceb8b[_0xd314('0x46')]);_0x46ed1c[_0xd314('0x43')]=_[_0xd314('0x44')](_0x46ed1c[_0xd314('0x40')],_0x46ed1c[_0xd314('0x46')]);_0x26814e['attributes']=_[_0xd314('0x44')](_0x46ed1c['model'],qs[_0xd314('0x45')](_0x4ceb8b[_0xd314('0x46')][_0xd314('0x45')]));_0x26814e[_0xd314('0x47')]=_0x26814e['attributes'][_0xd314('0x48')]?_0x26814e[_0xd314('0x47')]:_0x46ed1c['model'];if(_0x4ceb8b[_0xd314('0x46')][_0xd314('0xc9')]){_0x26814e[_0xd314('0xca')]=[{'all':!![]}];}_0x26814e=_[_0xd314('0xcb')]({},_0x26814e,_0x4ceb8b[_0xd314('0xcc')]);return db[_0xd314('0xa3')]['find'](_0x26814e)[_0xd314('0x2c')](handleEntityNotFound(_0x8261c5,null))['then'](respondWithResult(_0x8261c5,null))[_0xd314('0x3b')](handleError(_0x8261c5,null));};exports[_0xd314('0xcd')]=function(_0x177b5b,_0x2194da){return db[_0xd314('0xa3')][_0xd314('0xcd')](_0x177b5b['body'],{})[_0xd314('0x2c')](respondWithResult(_0x2194da,0xc9))[_0xd314('0x3b')](handleError(_0x2194da,null));};exports[_0xd314('0x2a')]=function(_0x570744,_0x547e64){if(_0x570744['body']['id']){delete _0x570744['body']['id'];}return db[_0xd314('0xa3')][_0xd314('0x67')]({'where':{'id':_0x570744[_0xd314('0xc8')]['id']}})['then'](handleEntityNotFound(_0x547e64,null))[_0xd314('0x2c')](saveUpdates(_0x570744[_0xd314('0xce')],null))['then'](respondWithResult(_0x547e64,null))[_0xd314('0x3b')](handleError(_0x547e64,null));};exports[_0xd314('0x2b')]=function(_0x174e6a,_0x1df4fc){return db[_0xd314('0xa3')][_0xd314('0x67')]({'where':{'id':_0x174e6a[_0xd314('0xc8')]['id']}})[_0xd314('0x2c')](handleEntityNotFound(_0x1df4fc,null))[_0xd314('0x2c')](removeEntity(_0x1df4fc,null))[_0xd314('0x3b')](handleError(_0x1df4fc,null));};exports[_0xd314('0xcf')]=function(_0x371a21,_0x2768f7){return db[_0xd314('0xa3')][_0xd314('0xcf')]()[_0xd314('0x2c')](respondWithResult(_0x2768f7,null))[_0xd314('0x3b')](handleError(_0x2768f7,null));};exports[_0xd314('0xd0')]=function(_0x5195e9,_0x5d9558,_0x3a9839){return db[_0xd314('0x36')][_0xd314('0x67')]({'where':{'id':_0x5195e9[_0xd314('0xc8')]['id']}})[_0xd314('0x2c')](handleEntityNotFound(_0x5d9558,null))['then'](function(_0x7b89f0){if(_0x7b89f0){return _0x7b89f0[_0xd314('0xd0')](_0x5195e9['body'][_0xd314('0xd1')],_[_0xd314('0xd2')](_0x5195e9['body'],[_0xd314('0xd1'),'id'])||{});}})[_0xd314('0x2c')](respondWithResult(_0x5d9558,null))[_0xd314('0x3b')](handleError(_0x5d9558,null));};exports['getMessages']=function(_0x3178f6,_0x818f4c,_0x1b10f8){var _0x2501a8={'raw':![],'where':{}};var _0x2c92a1={};var _0x2feeb6={'count':0x0,'rows':[]};return db['MailInteraction'][_0xd314('0x37')]({'where':{'id':_0x3178f6[_0xd314('0xc8')]['id']}})[_0xd314('0x2c')](handleEntityNotFound(_0x818f4c,null))[_0xd314('0x2c')](function(_0x421454){if(_0x421454){_0x2c92a1[_0xd314('0x40')]=_[_0xd314('0x42')](db[_0xd314('0x36')][_0xd314('0x3d')]);_0x2c92a1[_0xd314('0x46')]=_[_0xd314('0x42')](_0x3178f6[_0xd314('0x46')]);_0x2c92a1[_0xd314('0x43')]=_[_0xd314('0x44')](_0x2c92a1[_0xd314('0x40')],_0x2c92a1[_0xd314('0x46')]);_0x2501a8[_0xd314('0x47')]=_[_0xd314('0x44')](_0x2c92a1[_0xd314('0x40')],qs[_0xd314('0x45')](_0x3178f6[_0xd314('0x46')][_0xd314('0x45')]));_0x2501a8[_0xd314('0x47')]=_0x2501a8['attributes'][_0xd314('0x48')]?_0x2501a8[_0xd314('0x47')]:_0x2c92a1[_0xd314('0x40')];if(!_0x3178f6['query'][_0xd314('0xd3')](_0xd314('0x49'))){_0x2501a8[_0xd314('0x23')]=qs[_0xd314('0x23')](_0x3178f6['query'][_0xd314('0x23')]);_0x2501a8[_0xd314('0x25')]=qs['offset'](_0x3178f6['query'][_0xd314('0x25')]);}_0x2501a8[_0xd314('0x98')]=qs[_0xd314('0x4a')](_0x3178f6['query'][_0xd314('0x4a')]);_0x2501a8[_0xd314('0x4b')]=qs[_0xd314('0x43')](_[_0xd314('0x4c')](_0x3178f6[_0xd314('0x46')],_0x2c92a1[_0xd314('0x43')]));_0x2501a8[_0xd314('0x4b')][_0xd314('0xd4')]=_0x421454['id'];if(_0x3178f6[_0xd314('0x46')][_0xd314('0x8b')]){_0x2501a8[_0xd314('0x4b')]=_[_0xd314('0xcb')](_0x2501a8[_0xd314('0x4b')],{'$or':_['map'](_0x2501a8[_0xd314('0x47')],function(_0x378e8f){var _0x21046e={};_0x21046e[_0x378e8f]={'$like':'%'+_0x3178f6[_0xd314('0x46')]['filter']+'%'};return _0x21046e;})});}if(_0x3178f6['query'][_0xd314('0x83')]){var _0x59437f=_0x3178f6[_0xd314('0x46')][_0xd314('0x83')][_0xd314('0x6f')](',');var _0xcfd706={};_0xcfd706[_0x59437f[0x0]]={'$gte':moment(_0x59437f[0x1])[_0xd314('0xd5')](_0xd314('0xd6'))};_0x2501a8['where']=_[_0xd314('0xcb')](_0x2501a8[_0xd314('0x4b')],_0xcfd706);}_0x2501a8=_[_0xd314('0xcb')]({},_0x2501a8,_0x3178f6[_0xd314('0xcc')]);return db[_0xd314('0x36')][_0xd314('0x24')]({'where':_0x2501a8[_0xd314('0x4b')]})[_0xd314('0x2c')](function(_0x333180){_0x2feeb6[_0xd314('0x24')]=_0x333180;if(_0x3178f6[_0xd314('0x46')][_0xd314('0xc9')]){_0x2501a8[_0xd314('0xca')]=[{'all':!![]}];}return db[_0xd314('0x36')][_0xd314('0xd7')](_0x2501a8);})[_0xd314('0x2c')](function(_0x5c2dc8){if(_0x3178f6['query'][_0xd314('0xd8')]==='true'){for(var _0x55ccb2=0x0;_0x55ccb2<_0x5c2dc8[_0xd314('0x48')];_0x55ccb2++){_0x5c2dc8[_0x55ccb2][_0xd314('0xce')]=juice(_0x5c2dc8[_0x55ccb2][_0xd314('0xce')]);}}_0x2feeb6[_0xd314('0xc6')]=_0x5c2dc8;return _0x2feeb6;});}})[_0xd314('0x2c')](respondWithFilteredResult(_0x818f4c,_0x2501a8))[_0xd314('0x3b')](handleError(_0x818f4c,null));};exports['addTags']=function(_0x262a32,_0x271f0a,_0x375e47){return db[_0xd314('0xa3')][_0xd314('0x67')]({'where':{'id':_0x262a32[_0xd314('0xc8')]['id']}})[_0xd314('0x2c')](handleEntityNotFound(_0x271f0a,null))[_0xd314('0x2c')](function(_0x4e705c){if(_0x4e705c){return _0x4e705c[_0xd314('0xd9')](_0x262a32[_0xd314('0xce')][_0xd314('0xd1')],_[_0xd314('0xd2')](_0x262a32['body'],[_0xd314('0xd1'),'id'])||{})[_0xd314('0xda')](function(){return db[_0xd314('0x77')][_0xd314('0xd7')]({'attributes':['id',_0xd314('0x2f'),_0xd314('0x4e')],'where':{'id':_0x262a32['body'][_0xd314('0xd1')]}});})[_0xd314('0x2c')](function(_0x53490f){socket[_0xd314('0xdb')](_0xd314('0xdc'),{'id':Number(_0x262a32[_0xd314('0xc8')]['id']),'tags':_0x53490f||[]});return{'id':Number(_0x262a32['params']['id']),'tags':_0x53490f||[]};});}})[_0xd314('0x2c')](respondWithResult(_0x271f0a,null))['catch'](handleError(_0x271f0a,null));};exports[_0xd314('0xdd')]=function(_0x56b87,_0x358138,_0x589d85){return db[_0xd314('0xa3')]['find']({'where':{'id':_0x56b87[_0xd314('0xc8')]['id']}})[_0xd314('0x2c')](handleEntityNotFound(_0x358138,null))[_0xd314('0x2c')](function(_0x6acb79){if(_0x6acb79){return _0x6acb79[_0xd314('0xdd')](_0x56b87[_0xd314('0x46')][_0xd314('0xd1')]);}})[_0xd314('0x2c')](respondWithStatusCode(_0x358138,null))['catch'](handleError(_0x358138,null));};exports[_0xd314('0xde')]=function(_0x46b728,_0x54cbff){var _0x553fe2=moment()[_0xd314('0xdf')]()[_0xd314('0xa2')]();var _0x2fecd3=path[_0xd314('0xe0')](config[_0xd314('0xe1')],_0xd314('0xe2'),_0xd314('0xe3'),_0xd314('0xe4'));var _0x3f9b7c=path[_0xd314('0xe0')](config[_0xd314('0xe1')],_0xd314('0xe2'),_0xd314('0xe3'),_0xd314('0xe5'));var _0x49ccaa=path['join'](_0x2fecd3,_0x553fe2);var _0x3ce232=util[_0xd314('0xd5')]('transcript-%d-%s.zip',_0x46b728['params']['id'],_0x553fe2);var _0x26b117=path['join'](_0x2fecd3,_0x3ce232);var _0x1f690f=[];if(_0x46b728[_0xd314('0x46')][_0xd314('0xe5')]){_0x1f690f[_0xd314('0x35')]({'model':db[_0xd314('0xe6')],'as':_0xd314('0xe7'),'raw':!![]});}var _0x1eb43c=[{'model':db[_0xd314('0x36')],'as':_0xd314('0xe8'),'attributes':['id','body',_0xd314('0x4f'),'to','cc',_0xd314('0xe9'),'subject','createdAt'],'where':{'secret':![]},'order':qs[_0xd314('0x4a')]('id'),'include':_0x1f690f}];return db[_0xd314('0xa3')][_0xd314('0x67')]({'where':{'id':_0x46b728[_0xd314('0xc8')]['id']},'include':_0x1eb43c})[_0xd314('0x2c')](handleEntityNotFound(_0x54cbff,null))[_0xd314('0x2c')](function(_0xd1d6a6){if(_0xd1d6a6&&_0xd1d6a6['Messages']){var _0x3ac6bb=_0xd1d6a6[_0xd314('0xea')]({'plain':!![]});fs[_0xd314('0xeb')](_0x49ccaa);return BPromise[_0xd314('0xec')](_0x3ac6bb[_0xd314('0xe8')],function(_0x48fdc8,_0xb83104){var _0x5aa948={'from':_0x48fdc8[_0xd314('0x4f')],'to':_0x48fdc8['to'],'subject':_0x48fdc8['subject'],'html':_0x48fdc8[_0xd314('0xce')],'headers':{'Date':moment(_0x48fdc8['createdAt'])['format'](_0xd314('0xed'))},'attachments':[]};if(_0x48fdc8['cc']){_0x5aa948[_0xd314('0xee')]['Cc']=_0x48fdc8['cc'];}if(_0x48fdc8[_0xd314('0xe9')]){_0x5aa948[_0xd314('0xee')][_0xd314('0xef')]=_0x48fdc8[_0xd314('0xe9')];}return new BPromise(function(_0x1f2403,_0x471b6f){if(_0x48fdc8[_0xd314('0xe7')]){for(var _0x11e195=0x0;_0x11e195<_0x48fdc8[_0xd314('0xe7')][_0xd314('0x48')];_0x11e195++){var _0x36753a=_0x48fdc8[_0xd314('0xe7')][_0x11e195];var _0x39942f=path['join'](_0x3f9b7c,_0x36753a[_0xd314('0xf0')]);if(fs[_0xd314('0xf1')](_0x39942f)){_0x5aa948[_0xd314('0xe5')][_0xd314('0x35')]({'name':_0x36753a[_0xd314('0x2f')],'contentType':_0x36753a[_0xd314('0x3e')],'data':fs[_0xd314('0xf2')](_0x39942f)});}}}emlformat[_0xd314('0xf3')](_0x5aa948,function(_0x57b8fa,_0x57f611){if(_0x57b8fa)return _0x471b6f(_0x57b8fa);fs[_0xd314('0xf4')](path[_0xd314('0xe0')](_0x49ccaa,util[_0xd314('0xd5')](_0xd314('0xf5'),_0xb83104)),_0x57f611);return _0x1f2403(_0x57f611);});});})['then'](function(){return new BPromise(function(_0xe4840d,_0x16baea){zipdir(_0x49ccaa,{'saveTo':_0x26b117},function(_0x579a50,_0x2f405f){if(_0x579a50)return _0x16baea(_0x579a50);return _0xe4840d(_0x2f405f);});})['then'](function(){return new BPromise(function(_0x24ead4,_0x224ff2){rimraf(_0x49ccaa,function(_0xf8982e){if(_0xf8982e)_0x224ff2(_0xf8982e);return _0x24ead4();});});})[_0xd314('0x2c')](function(){return _0x54cbff[_0xd314('0xde')](_0x26b117,_0x3ce232,function(_0x414238){if(_0x414238){console[_0xd314('0xf6')]('err',_0x414238);}else{fs[_0xd314('0xf7')](_0x26b117);}});});});}else{return _0x54cbff[_0xd314('0x20')](0xc8);}})[_0xd314('0x3b')](handleError(_0x54cbff,null));};
\ No newline at end of file