Built motion from commit (unavailable).|2.5.9
[motion2.git] / server / api / mailInteraction / mailInteraction.controller.js
index 497ef18..d1170cc 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x147b=['where','select','field','color','tools_tags','u.id','u.fullname','ui.MailInteractionId','from','user_has_mail_interactions','left_join','users','u.id\x20=\x20ui.UserId','cm_contacts','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','mail_accounts','mail_interaction_has_tags','t.id\x20=\x20it.TagId','expr','search','parseSearch','sqlOperator','find','unreadMessages','value','`\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','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','plainBody','some','compact','isEmpty','i.MailAccountId\x20IN\x20?','concat','parse','$lte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20IS\x20NULL','\x20=\x20?','read','having','`unreadMessages`\x20>\x200','tag','filter','replace','isNumeric','i.id\x20LIKE\x20?','c.email\x20LIKE\x20?','MATCH\x20(i.to,\x20i.subject)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','MATCH\x20(me.plainBody,\x20me.subject)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','i.id','Sequelize','QueryTypes','SELECT','clone','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','DESC','resolve','journey','i.MailAccountId\x20IS\x20NOT\x20NULL','user','getMailAccounts','i.MailAccountId\x20IS\x20NULL','sequelize','toString','count','keyBy','merge','a.mandatoryDisposition','Account.mandatoryDisposition','i.createdAt','i.updatedAt','i.closed','i.attach','i.lastMsgAt','i.lastMsgDirection','i.subject','i.disposition','i.secondDisposition','i.thirdDisposition','i.substatus','i.to','i.ContactId','i.UserId','c.firstName','Contact.firstName','c.lastName','c.email','Contact.email','Contact.phone','Contact.mobile','c.fax','Contact.fax','o.fullname','o.internal','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','ui.MailInteractionId\x20IN\x20?','enableEmailPreview','all','rows','params','intersection','include','options','create','body','update','describe','addMessage','MailMessage','ids','getMessages','hasOwnProperty','pick','MailInteractionId','$gte','format','YYYY-MM-DD\x20HH:mm:ss','includeAll','findAll','addTags','setTags','omit','spread','emit','mailInteractionTags:save','removeTags','download','unix','join','root','server','files','attachments','transcript-%d-%s.zip','Messages','bcc','createdAt','get','mkdirSync','subject','headers','Bcc','Attachments','basename','message%d.eml','log','err','unlinkSync','html-pdf','eml-format','zip-dir','fast-json-patch','moment','bluebird','mustache','path','to-csv','ejs','lodash','jsforce','desk.js','querystring','papaparse','html-to-text','ioredis','../../components/auth/service','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','./mailInteraction.socket','register','sendStatus','offset','limit','set','Content-Range','json','reject','save','then','destroy','end','error','stack','name','status','Users','map','fullname','TagIds','Tags','split','forEach','push','MailInteraction','findOne','lastMsgBody','lastMsgText','trimStart','fromString','catch','index','rawAttributes','fieldName','type','key','model','keys','query','filters','fields','attributes','length','nolimit','order','sort'];(function(_0x572440,_0x52ca1d){var _0x1da81e=function(_0x2f23c8){while(--_0x2f23c8){_0x572440['push'](_0x572440['shift']());}};_0x1da81e(++_0x52ca1d);}(_0x147b,0x193));var _0xb147=function(_0x3b611a,_0x5358bb){_0x3b611a=_0x3b611a-0x0;var _0x41c633=_0x147b[_0x3b611a];return _0x41c633;};'use strict';var pdf=require(_0xb147('0x0'));var emlformat=require(_0xb147('0x1'));var rimraf=require('rimraf');var zipdir=require(_0xb147('0x2'));var jsonpatch=require(_0xb147('0x3'));var rp=require('request-promise');var moment=require(_0xb147('0x4'));var BPromise=require(_0xb147('0x5'));var Mustache=require(_0xb147('0x6'));var util=require('util');var path=require(_0xb147('0x7'));var sox=require('sox');var csv=require(_0xb147('0x8'));var ejs=require(_0xb147('0x9'));var fs=require('fs');var _=require(_0xb147('0xa'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0xb147('0xb'));var deskjs=require(_0xb147('0xc'));var toCsv=require(_0xb147('0x8'));var querystring=require(_0xb147('0xd'));var Papa=require(_0xb147('0xe'));var htmlToText=require(_0xb147('0xf'));var Redis=require(_0xb147('0x10'));var authService=require(_0xb147('0x11'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xb147('0x12'));var logger=require(_0xb147('0x13'))(_0xb147('0x14'));var utils=require(_0xb147('0x15'));var config=require(_0xb147('0x16'));var licenseUtil=require(_0xb147('0x17'));var db=require(_0xb147('0x18'))['db'];config[_0xb147('0x19')]=_[_0xb147('0x1a')](config[_0xb147('0x19')],{'host':_0xb147('0x1b'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xb147('0x19')]));require(_0xb147('0x1c'))[_0xb147('0x1d')](socket);function respondWithStatusCode(_0x2c1952,_0x5479b4){_0x5479b4=_0x5479b4||0xcc;return function(_0x2a0eeb){if(_0x2a0eeb){return _0x2c1952[_0xb147('0x1e')](_0x5479b4);}return _0x2c1952['status'](_0x5479b4)['end']();};}function respondWithResult(_0x1f424a,_0x1e735c){_0x1e735c=_0x1e735c||0xc8;return function(_0x34e3c1){if(_0x34e3c1){return _0x1f424a['status'](_0x1e735c)['json'](_0x34e3c1);}};}function respondWithFilteredResult(_0xe5aa93,_0x5e3235){return function(_0x3a9bca){if(_0x3a9bca){var _0x107b35=_0x3a9bca['count'],_0x11a08a=_0x5e3235[_0xb147('0x1f')],_0x4a1c81=_0x5e3235[_0xb147('0x1f')]+_0x5e3235[_0xb147('0x20')],_0x4a02f2;if(_0x4a1c81>=_0x107b35){_0x4a1c81=_0x107b35;_0x4a02f2=0xc8;}else{_0x4a02f2=0xce;}_0xe5aa93['status'](_0x4a02f2);return _0xe5aa93[_0xb147('0x21')](_0xb147('0x22'),_0x11a08a+'-'+_0x4a1c81+'/'+_0x107b35)[_0xb147('0x23')](_0x3a9bca);}return null;};}function patchUpdates(_0x45cbe8){return function(_0x163151){try{jsonpatch['apply'](_0x163151,_0x45cbe8,!![]);}catch(_0xa85f38){return BPromise[_0xb147('0x24')](_0xa85f38);}return _0x163151[_0xb147('0x25')]();};}function saveUpdates(_0x420452,_0x353b8b){return function(_0x53ac4b){if(_0x53ac4b){return _0x53ac4b['update'](_0x420452)[_0xb147('0x26')](function(_0x98509e){return _0x98509e;});}return null;};}function removeEntity(_0x24efa0,_0x39f833){return function(_0x5f2806){if(_0x5f2806){return _0x5f2806[_0xb147('0x27')]()['then'](function(){_0x24efa0['status'](0xcc)[_0xb147('0x28')]();});}};}function handleEntityNotFound(_0x2cf3b5,_0x444d58){return function(_0x139057){if(!_0x139057){_0x2cf3b5[_0xb147('0x1e')](0x194);}return _0x139057;};}function handleError(_0x362ac8,_0x4cce70){_0x4cce70=_0x4cce70||0x1f4;return function(_0x5691de){logger[_0xb147('0x29')](_0x5691de[_0xb147('0x2a')]);if(_0x5691de['name']){delete _0x5691de[_0xb147('0x2b')];}_0x362ac8[_0xb147('0x2c')](_0x4cce70)['send'](_0x5691de);};}function getInteractionUsers(_0x517990,_0x2b90ef){return new BPromise(function(_0xe07da5,_0x1ba125){try{if(_0x2b90ef[_0x517990['id']]){_0x517990[_0xb147('0x2d')]=_[_0xb147('0x2e')](_0x2b90ef[_0x517990['id']],function(_0x589010){return{'id':_0x589010['id'],'fullname':_0x589010[_0xb147('0x2f')]};});}}catch(_0x315896){_0x1ba125(_0x315896);}_0xe07da5(_0x517990);});}function getInteractionTags(_0x273fff,_0x15cdfa){return new BPromise(function(_0x40608d,_0x4afede){try{if(_0x273fff[_0xb147('0x30')]){_0x273fff[_0xb147('0x31')]=[];_0x273fff[_0xb147('0x30')][_0xb147('0x32')](',')[_0xb147('0x33')](function(_0x28a923){_0x273fff[_0xb147('0x31')][_0xb147('0x34')](_0x15cdfa[_0x28a923]);});}delete _0x273fff[_0xb147('0x30')];}catch(_0x5d23b2){_0x4afede(_0x5d23b2);}_0x40608d(_0x273fff);});}function getLastMessageText(_0x168677){return new BPromise(function(_0x3f91f8,_0xf373bc){return db[_0xb147('0x35')][_0xb147('0x36')]({'where':{'id':_0x168677['id']},'attributes':[_0xb147('0x37'),_0xb147('0x38')],'raw':!![]})[_0xb147('0x26')](function(_0x5a8261){if(!_0x5a8261[_0xb147('0x38')]){_0x168677[_0xb147('0x38')]=_[_0xb147('0x39')](htmlToText[_0xb147('0x3a')](_0x5a8261[_0xb147('0x37')],{'preserveNewlines':!![],'singleNewLineParagraphs':!![],'uppercaseHeadings':![],'noLinkBrackets':!![],'ignoreImage':!![]}));}else{_0x168677[_0xb147('0x38')]=_0x5a8261[_0xb147('0x38')];}_0x3f91f8(_0x168677);})['catch'](function(_0x23324e){_0xf373bc(_0x23324e);});});}function updateMailInteraction(_0x48cc99,_0x221a7c,_0x2977fe,_0x481a3f){return new BPromise(function(_0x5d3e2b,_0x516d5d){return getInteractionUsers(_0x48cc99,_0x2977fe)[_0xb147('0x26')](function(_0x38735d){return getInteractionTags(_0x38735d,_0x221a7c);})[_0xb147('0x26')](function(_0x11821a){if(_0x481a3f){_0x5d3e2b(getLastMessageText(_0x11821a));}else{_0x5d3e2b(_0x11821a);}})[_0xb147('0x3b')](function(_0x4f6e08){_0x516d5d(_0x4f6e08);});});}exports[_0xb147('0x3c')]=function(_0x5e76e0,_0x4b6d48){var _0x48ca8c={},_0x379bb6={},_0xdbc869={'count':0x0,'rows':[]};var _0x138e56=_[_0xb147('0x2e')](db[_0xb147('0x35')][_0xb147('0x3d')],function(_0x530b94){return{'name':_0x530b94[_0xb147('0x3e')],'type':_0x530b94[_0xb147('0x3f')][_0xb147('0x40')]};});_0x379bb6[_0xb147('0x41')]=_[_0xb147('0x2e')](_0x138e56,_0xb147('0x2b'));_0x379bb6['query']=_[_0xb147('0x42')](_0x5e76e0[_0xb147('0x43')]);_0x379bb6[_0xb147('0x44')]=_['intersection'](_0x379bb6[_0xb147('0x41')],_0x379bb6[_0xb147('0x43')]);_0x48ca8c['attributes']=_['intersection'](_0x379bb6['model'],qs[_0xb147('0x45')](_0x5e76e0['query']['fields']));_0x48ca8c[_0xb147('0x46')]=_0x48ca8c[_0xb147('0x46')][_0xb147('0x47')]?_0x48ca8c[_0xb147('0x46')]:_0x379bb6['model'];if(!_0x5e76e0[_0xb147('0x43')]['hasOwnProperty'](_0xb147('0x48'))){_0x48ca8c[_0xb147('0x20')]=qs[_0xb147('0x20')](_0x5e76e0[_0xb147('0x43')][_0xb147('0x20')]);_0x48ca8c[_0xb147('0x1f')]=qs[_0xb147('0x1f')](_0x5e76e0[_0xb147('0x43')]['offset']);}_0x48ca8c[_0xb147('0x49')]=qs[_0xb147('0x4a')](_0x5e76e0[_0xb147('0x43')][_0xb147('0x4a')]);_0x48ca8c[_0xb147('0x4b')]=qs[_0xb147('0x44')](_['pick'](_0x5e76e0[_0xb147('0x43')],_0x379bb6['filters']),_0x138e56);var _0x1c28af=[];var _0x196326=squel[_0xb147('0x4c')]()[_0xb147('0x4d')]('id')['field'](_0xb147('0x2b'))[_0xb147('0x4d')](_0xb147('0x4e'))['from'](_0xb147('0x4f'));var _0x5000cd=squel[_0xb147('0x4c')]()[_0xb147('0x4d')](_0xb147('0x50'))[_0xb147('0x4d')](_0xb147('0x51'))[_0xb147('0x4d')](_0xb147('0x52'))[_0xb147('0x53')](_0xb147('0x54'),'ui')[_0xb147('0x55')](_0xb147('0x56'),'u',_0xb147('0x57'));var _0x37e03b=squel[_0xb147('0x4c')]()[_0xb147('0x53')]('mail_interactions','i')[_0xb147('0x55')](_0xb147('0x58'),'c',_0xb147('0x59'))[_0xb147('0x55')](_0xb147('0x56'),'o','o.id\x20=\x20i.UserId')[_0xb147('0x55')](_0xb147('0x5a'),'a','a.id\x20=\x20i.MailAccountId')[_0xb147('0x55')]('mail_messages','me','me.MailInteractionId\x20=\x20i.id')[_0xb147('0x55')](_0xb147('0x5b'),'it','it.MailInteractionId\x20=\x20i.id')[_0xb147('0x55')](_0xb147('0x4f'),'t',_0xb147('0x5c'));var _0x3a8363=squel[_0xb147('0x5d')]();var _0x4c6ae2=[];var _0x12309e=squel[_0xb147('0x5d')]();var _0x42e8e6;if(_0x5e76e0[_0xb147('0x43')][_0xb147('0x5e')]){_0x42e8e6=as[_0xb147('0x5f')](_0x5e76e0[_0xb147('0x43')][_0xb147('0x5e')]);var _0x31cd87=_0x42e8e6[_0xb147('0x60')];for(var _0x3b3ed7=0x0;_0x3b3ed7<_0x42e8e6['conditions'][_0xb147('0x47')];_0x3b3ed7++){var _0x1ea2e1=_0x42e8e6['conditions'][_0x3b3ed7];var _0x2c031f='i';var _0x17a09a=_[_0xb147('0x61')](_0x138e56,['name',_0x1ea2e1[_0xb147('0x4d')]]);if(!_0x17a09a){switch(_0x1ea2e1['field']){case _0xb147('0x62'):if(_0x1ea2e1[_0xb147('0x63')]==0x1){_0x37e03b['having']('`'+_0x1ea2e1[_0xb147('0x4d')]+_0xb147('0x64'));}else{_0x37e03b['having']('`'+_0x1ea2e1[_0xb147('0x4d')]+_0xb147('0x65'));}break;case _0xb147('0x66'):if(_0x1ea2e1[_0xb147('0x67')]===_0xb147('0x68')){if(_0x1ea2e1[_0xb147('0x63')][_0xb147('0x32')]('\x20')[_0xb147('0x47')]>0x1){_0x3a8363[_0x31cd87](_0xb147('0x69'),qs[_0xb147('0x6a')](_0x1ea2e1['value']),null);}else{var _0x20f32c='%'+_0x1ea2e1[_0xb147('0x63')]+'%';_0x3a8363[_0x31cd87]('c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?',_0x20f32c,_0x20f32c,_0x20f32c);}}else{_0x17a09a=_[_0xb147('0x61')](_0x138e56,[_0xb147('0x2b'),'ContactId']);_0x1ea2e1[_0xb147('0x4d')]=_0xb147('0x6b');_0x586362=as[_0xb147('0x6c')](_0x2c031f,_0x17a09a[_0xb147('0x3f')],_0x1ea2e1);_0x3a8363[_0x31cd87](_0x586362[_0xb147('0x6d')],_0x586362[_0xb147('0x63')][_0xb147('0x6e')],_0x586362[_0xb147('0x63')][_0xb147('0x28')]);}break;case _0xb147('0x6f'):var _0x5b8a0e=_0x1ea2e1['value'][_0xb147('0x32')](',')[_0xb147('0x2e')](function(_0xe41a54){return Number(_0xe41a54);});_0x5b8a0e['forEach'](function(_0x5820df){_0x12309e['or'](_0xb147('0x70'),'%,'+_0x5820df+',%');});_0x4c6ae2=_[_0xb147('0x71')](_0x4c6ae2,_0x5b8a0e);break;case'User':if(_0x1ea2e1['operator']===_0xb147('0x68')){_0x3a8363[_0x31cd87](_0xb147('0x72'),'%'+_0x1ea2e1[_0xb147('0x63')]+'%',null);}else{_0x17a09a=_['find'](_0x138e56,[_0xb147('0x2b'),_0xb147('0x73')]);_0x1ea2e1[_0xb147('0x4d')]=_0xb147('0x73');_0x586362=as[_0xb147('0x6c')](_0x2c031f,_0x17a09a['type'],_0x1ea2e1);_0x3a8363[_0x31cd87](_0x586362[_0xb147('0x6d')],_0x586362[_0xb147('0x63')]['start'],_0x586362[_0xb147('0x63')][_0xb147('0x28')]);}break;case _0xb147('0x74'):_0x586362=as[_0xb147('0x6c')]('me',null,_0x1ea2e1);_0x3a8363[_0x31cd87](_0x586362['text'],_0x586362[_0xb147('0x63')][_0xb147('0x6e')],_0x586362['value'][_0xb147('0x28')]);break;}}else{var _0x586362=as[_0xb147('0x6c')](_0x2c031f,_0x17a09a[_0xb147('0x3f')],_0x1ea2e1);_0x3a8363[_0x31cd87](_0x586362[_0xb147('0x6d')],_0x586362['value'][_0xb147('0x6e')],_0x586362[_0xb147('0x63')]['end']);}}}else{var _0x2d0b59=_(_0x5e76e0[_0xb147('0x43')])['keys']()[_0xb147('0x2e')](function(_0x57e074){return _[_0xb147('0x75')](_0x138e56,[_0xb147('0x2b'),_0x57e074])?_0x57e074:undefined;})[_0xb147('0x76')]()[_0xb147('0x63')]();if(!_[_0xb147('0x77')](_0x2d0b59)){_0x2d0b59['forEach'](function(_0x244288){if(_0x244288==='MailAccountId'){_0x37e03b[_0xb147('0x4b')](_0xb147('0x78'),[][_0xb147('0x79')](_0x5e76e0[_0xb147('0x43')][_0x244288]));}else if(_0x244288==='createdAt'){var _0x1fe869=JSON[_0xb147('0x7a')](_0x5e76e0[_0xb147('0x43')][_0x244288])['$gte'];var _0x3f8925=JSON[_0xb147('0x7a')](_0x5e76e0['query'][_0x244288])[_0xb147('0x7b')];_0x37e03b[_0xb147('0x4b')](_0xb147('0x7c'),_0x1fe869,_0x3f8925);}else{if(_0x5e76e0['query'][_0x244288]===_0xb147('0x7d')){_0x37e03b[_0xb147('0x4b')]('i.'+_0x244288+_0xb147('0x7e'));}else{_0x37e03b['where']('i.'+_0x244288+_0xb147('0x7f'),_0x5e76e0['query'][_0x244288]);}}});}if(_0x5e76e0['query'][_0xb147('0x80')]){if(_0x5e76e0[_0xb147('0x43')][_0xb147('0x80')]==0x1){_0x37e03b[_0xb147('0x81')]('`unreadMessages`\x20=\x200');}else{_0x37e03b[_0xb147('0x81')](_0xb147('0x82'));}}if(_0x5e76e0['query'][_0xb147('0x83')]){_0x4c6ae2=_['isArray'](_0x5e76e0[_0xb147('0x43')]['tag'])?_0x5e76e0[_0xb147('0x43')]['tag']:new Array(_0x5e76e0['query']['tag']);_0x4c6ae2[_0xb147('0x33')](function(_0x6998d5){_0x12309e['or'](_0xb147('0x70'),'%,'+_0x6998d5+',%');});}if(_0x5e76e0[_0xb147('0x43')][_0xb147('0x84')]){var _0x3798a0=_0x5e76e0[_0xb147('0x43')]['filter'][_0xb147('0x85')]('\x5c','\x5c\x5c')[_0xb147('0x85')](/'/g,'\x27\x27');if(qs[_0xb147('0x86')](_0x3798a0)){_0x3a8363['or'](_0xb147('0x87'),_0x3798a0+'%');}else if(qs['isEmail'](_0x3798a0)){_0x3a8363['or'](_0xb147('0x88'),_0x3798a0+'%');}else{_0x3a8363['or'](_0xb147('0x89'),qs[_0xb147('0x6a')](_0x3798a0))['or'](_0xb147('0x8a'),qs[_0xb147('0x6a')](_0x3798a0));}}}_0x37e03b[_0xb147('0x4b')](_0x3a8363);_0x37e03b['group'](_0xb147('0x8b'));var _0x58429d={'type':db[_0xb147('0x8c')][_0xb147('0x8d')][_0xb147('0x8e')],'raw':!![]};var _0x43e48a=_0x37e03b[_0xb147('0x8f')]();_0x43e48a[_0xb147('0x4d')](_0xb147('0x8b'));_0x43e48a[_0xb147('0x4d')](_0xb147('0x90'),_0xb147('0x62'));if(_0x48ca8c[_0xb147('0x49')]){_0x48ca8c[_0xb147('0x49')]['forEach'](function(_0x5dadd3){_0x37e03b[_0xb147('0x49')]('i.'+_0x5dadd3[0x0],_0x5dadd3[0x1]===_0xb147('0x91')?![]:!![]);});}if(!_[_0xb147('0x77')](_0x4c6ae2)){_0x37e03b[_0xb147('0x81')](_0x12309e);_0x43e48a[_0xb147('0x4b')]('t.id\x20IN\x20?',_0x4c6ae2);}BPromise[_0xb147('0x92')]()[_0xb147('0x26')](function(){if(!_0x42e8e6){if(_0x5e76e0[_0xb147('0x43')]['MailAccountId']||_0x5e76e0[_0xb147('0x43')][_0xb147('0x93')])return;_0x43e48a[_0xb147('0x4b')](_0xb147('0x94'));_0x37e03b[_0xb147('0x4b')]('i.MailAccountId\x20IS\x20NOT\x20NULL');return;}return _0x5e76e0[_0xb147('0x95')][_0xb147('0x96')]({'attributes':['id'],'raw':!![]})['then'](function(_0x1c4071){if(_['isEmpty'](_0x1c4071)){_0x43e48a[_0xb147('0x4b')](_0xb147('0x97'));_0x37e03b[_0xb147('0x4b')](_0xb147('0x97'));}else{_0x43e48a['where'](_0xb147('0x78'),_[_0xb147('0x2e')](_0x1c4071,'id'));_0x37e03b[_0xb147('0x4b')](_0xb147('0x78'),_[_0xb147('0x2e')](_0x1c4071,'id'));}});})[_0xb147('0x26')](function(){db[_0xb147('0x98')][_0xb147('0x43')](_0x43e48a[_0xb147('0x99')](),_0x58429d)[_0xb147('0x26')](function(_0x3f740a){_0xdbc869[_0xb147('0x9a')]=_0x3f740a[_0xb147('0x47')];if(_0xdbc869[_0xb147('0x9a')]===0x0)return[];return db['sequelize'][_0xb147('0x43')](_0x196326['toString'](),_0x58429d)[_0xb147('0x26')](function(_0x4012fb){_0x1c28af=_[_0xb147('0x9b')](_0x4012fb,'id');_0x58429d=_[_0xb147('0x9c')](_0x58429d,{'model':db[_0xb147('0x35')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x5e76e0['query'][_0xb147('0x45')]){_0x48ca8c[_0xb147('0x46')][_0xb147('0x33')](function(_0x39525d){_0x37e03b[_0xb147('0x4d')]('i.'+_0x39525d);});}else{_0x37e03b['field']('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)',_0xb147('0x62'));_0x37e03b[_0xb147('0x4d')]('a.key','Account.key');_0x37e03b[_0xb147('0x4d')](_0xb147('0x9d'),_0xb147('0x9e'));_0x37e03b[_0xb147('0x4d')]('i.id');_0x37e03b[_0xb147('0x4d')](_0xb147('0x9f'));_0x37e03b[_0xb147('0x4d')](_0xb147('0xa0'));_0x37e03b['field'](_0xb147('0xa1'));_0x37e03b['field']('i.closedAt');_0x37e03b[_0xb147('0x4d')](_0xb147('0xa2'));_0x37e03b[_0xb147('0x4d')](_0xb147('0xa3'));_0x37e03b['field'](_0xb147('0xa4'));_0x37e03b[_0xb147('0x4d')](_0xb147('0xa5'));_0x37e03b['field'](_0xb147('0xa6'));_0x37e03b[_0xb147('0x4d')](_0xb147('0xa7'));_0x37e03b[_0xb147('0x4d')](_0xb147('0xa8'));_0x37e03b['field'](_0xb147('0xa9'));_0x37e03b[_0xb147('0x4d')](_0xb147('0xaa'));_0x37e03b['field'](_0xb147('0xab'));_0x37e03b[_0xb147('0x4d')]('i.MailAccountId');_0x37e03b[_0xb147('0x4d')](_0xb147('0xac'));_0x37e03b[_0xb147('0x4d')](_0xb147('0xad'),_0xb147('0xae'));_0x37e03b[_0xb147('0x4d')](_0xb147('0xaf'),'Contact.lastName');_0x37e03b[_0xb147('0x4d')](_0xb147('0xb0'),_0xb147('0xb1'));_0x37e03b[_0xb147('0x4d')]('c.phone',_0xb147('0xb2'));_0x37e03b[_0xb147('0x4d')]('c.mobile',_0xb147('0xb3'));_0x37e03b[_0xb147('0x4d')](_0xb147('0xb4'),_0xb147('0xb5'));_0x37e03b['field'](_0xb147('0xb6'),'Owner.fullname');_0x37e03b[_0xb147('0x4d')](_0xb147('0xb7'),_0xb147('0xb8'));_0x37e03b[_0xb147('0x4d')](_0xb147('0xb9'),_0xb147('0x30'));}if(_0x48ca8c[_0xb147('0x20')])_0x37e03b[_0xb147('0x20')](_0x48ca8c[_0xb147('0x20')]);if(_0x48ca8c[_0xb147('0x1f')])_0x37e03b['offset'](_0x48ca8c[_0xb147('0x1f')]);return db[_0xb147('0x98')][_0xb147('0x43')](_0x37e03b[_0xb147('0x99')](),_0x58429d);})['then'](function(_0x1638a2){_0x5000cd['where'](_0xb147('0xba'),_[_0xb147('0x2e')](_0x1638a2,'id'));return db['sequelize'][_0xb147('0x43')](_0x5000cd['toString'](),_0x58429d)[_0xb147('0x26')](function(_0x1c7dd2){var _0x1a80b1=_['groupBy'](_0x1c7dd2,'MailInteractionId');var _0x5bbf5e=[];return db['Setting'][_0xb147('0x36')]({'attributes':[_0xb147('0xbb')],'raw':!![]})[_0xb147('0x26')](function(_0x5130d1){var _0x595a3b=_0x5130d1[_0xb147('0xbb')];_0x1638a2['forEach'](function(_0x54a8e5){_0x5bbf5e[_0xb147('0x34')](updateMailInteraction(_0x54a8e5,_0x1c28af,_0x1a80b1,_0x595a3b));});return BPromise[_0xb147('0xbc')](_0x5bbf5e);});});});})[_0xb147('0x26')](function(_0x134b77){_0xdbc869[_0xb147('0xbd')]=_0x134b77;return _0xdbc869;})[_0xb147('0x26')](respondWithFilteredResult(_0x4b6d48,_0x48ca8c));})[_0xb147('0x3b')](handleError(_0x4b6d48,null));};exports['show']=function(_0x53342e,_0x58d98c){var _0xe06e7={'raw':![],'where':{'id':_0x53342e[_0xb147('0xbe')]['id']}},_0x2a3563={};_0x2a3563[_0xb147('0x41')]=_[_0xb147('0x42')](db[_0xb147('0x35')]['rawAttributes']);_0x2a3563['query']=_['keys'](_0x53342e['query']);_0x2a3563['filters']=_[_0xb147('0xbf')](_0x2a3563['model'],_0x2a3563[_0xb147('0x43')]);_0xe06e7['attributes']=_['intersection'](_0x2a3563['model'],qs['fields'](_0x53342e['query'][_0xb147('0x45')]));_0xe06e7['attributes']=_0xe06e7[_0xb147('0x46')][_0xb147('0x47')]?_0xe06e7[_0xb147('0x46')]:_0x2a3563[_0xb147('0x41')];if(_0x53342e[_0xb147('0x43')]['includeAll']){_0xe06e7[_0xb147('0xc0')]=[{'all':!![]}];}_0xe06e7=_['merge']({},_0xe06e7,_0x53342e[_0xb147('0xc1')]);return db[_0xb147('0x35')][_0xb147('0x61')](_0xe06e7)[_0xb147('0x26')](handleEntityNotFound(_0x58d98c,null))[_0xb147('0x26')](respondWithResult(_0x58d98c,null))[_0xb147('0x3b')](handleError(_0x58d98c,null));};exports[_0xb147('0xc2')]=function(_0x3a2fa7,_0x5dffbc){return db[_0xb147('0x35')][_0xb147('0xc2')](_0x3a2fa7[_0xb147('0xc3')],{})['then'](respondWithResult(_0x5dffbc,0xc9))[_0xb147('0x3b')](handleError(_0x5dffbc,null));};exports[_0xb147('0xc4')]=function(_0x14ed39,_0x2e16c4){if(_0x14ed39[_0xb147('0xc3')]['id']){delete _0x14ed39[_0xb147('0xc3')]['id'];}return db[_0xb147('0x35')]['find']({'where':{'id':_0x14ed39[_0xb147('0xbe')]['id']}})[_0xb147('0x26')](handleEntityNotFound(_0x2e16c4,null))[_0xb147('0x26')](saveUpdates(_0x14ed39['body'],null))[_0xb147('0x26')](respondWithResult(_0x2e16c4,null))[_0xb147('0x3b')](handleError(_0x2e16c4,null));};exports[_0xb147('0x27')]=function(_0x132812,_0x2fce8c){return db[_0xb147('0x35')]['find']({'where':{'id':_0x132812['params']['id']}})[_0xb147('0x26')](handleEntityNotFound(_0x2fce8c,null))[_0xb147('0x26')](removeEntity(_0x2fce8c,null))[_0xb147('0x3b')](handleError(_0x2fce8c,null));};exports[_0xb147('0xc5')]=function(_0x4d7f1e,_0x54c80b){return db[_0xb147('0x35')][_0xb147('0xc5')]()[_0xb147('0x26')](respondWithResult(_0x54c80b,null))['catch'](handleError(_0x54c80b,null));};exports[_0xb147('0xc6')]=function(_0x6225ca,_0x549204,_0x47da8e){return db[_0xb147('0xc7')][_0xb147('0x61')]({'where':{'id':_0x6225ca[_0xb147('0xbe')]['id']}})[_0xb147('0x26')](handleEntityNotFound(_0x549204,null))['then'](function(_0x779149){if(_0x779149){return _0x779149['addMessage'](_0x6225ca['body'][_0xb147('0xc8')],_['omit'](_0x6225ca['body'],[_0xb147('0xc8'),'id'])||{});}})['then'](respondWithResult(_0x549204,null))[_0xb147('0x3b')](handleError(_0x549204,null));};exports[_0xb147('0xc9')]=function(_0x2421d8,_0x3362d0,_0x504948){var _0x129714={'raw':![],'where':{}};var _0x4d264b={};var _0x1ae142={'count':0x0,'rows':[]};return db['MailInteraction'][_0xb147('0x36')]({'where':{'id':_0x2421d8[_0xb147('0xbe')]['id']}})['then'](handleEntityNotFound(_0x3362d0,null))[_0xb147('0x26')](function(_0x26d4d9){if(_0x26d4d9){_0x4d264b[_0xb147('0x41')]=_['keys'](db[_0xb147('0xc7')][_0xb147('0x3d')]);_0x4d264b[_0xb147('0x43')]=_[_0xb147('0x42')](_0x2421d8[_0xb147('0x43')]);_0x4d264b[_0xb147('0x44')]=_[_0xb147('0xbf')](_0x4d264b[_0xb147('0x41')],_0x4d264b[_0xb147('0x43')]);_0x129714[_0xb147('0x46')]=_[_0xb147('0xbf')](_0x4d264b[_0xb147('0x41')],qs[_0xb147('0x45')](_0x2421d8[_0xb147('0x43')][_0xb147('0x45')]));_0x129714[_0xb147('0x46')]=_0x129714['attributes'][_0xb147('0x47')]?_0x129714[_0xb147('0x46')]:_0x4d264b[_0xb147('0x41')];if(!_0x2421d8[_0xb147('0x43')][_0xb147('0xca')]('nolimit')){_0x129714[_0xb147('0x20')]=qs[_0xb147('0x20')](_0x2421d8[_0xb147('0x43')]['limit']);_0x129714[_0xb147('0x1f')]=qs[_0xb147('0x1f')](_0x2421d8['query'][_0xb147('0x1f')]);}_0x129714[_0xb147('0x49')]=qs[_0xb147('0x4a')](_0x2421d8[_0xb147('0x43')]['sort']);_0x129714[_0xb147('0x4b')]=qs['filters'](_[_0xb147('0xcb')](_0x2421d8[_0xb147('0x43')],_0x4d264b[_0xb147('0x44')]));_0x129714['where'][_0xb147('0xcc')]=_0x26d4d9['id'];if(_0x2421d8[_0xb147('0x43')][_0xb147('0x84')]){_0x129714['where']=_[_0xb147('0x9c')](_0x129714['where'],{'$or':_[_0xb147('0x2e')](_0x129714[_0xb147('0x46')],function(_0x23bb48){var _0x27f182={};_0x27f182[_0x23bb48]={'$like':'%'+_0x2421d8['query'][_0xb147('0x84')]+'%'};return _0x27f182;})});}if(_0x2421d8[_0xb147('0x43')]['$gte']){var _0x2d6b7a=_0x2421d8[_0xb147('0x43')][_0xb147('0xcd')]['split'](',');var _0x4b14ab={};_0x4b14ab[_0x2d6b7a[0x0]]={'$gte':moment(_0x2d6b7a[0x1])[_0xb147('0xce')](_0xb147('0xcf'))};_0x129714[_0xb147('0x4b')]=_[_0xb147('0x9c')](_0x129714[_0xb147('0x4b')],_0x4b14ab);}_0x129714=_['merge']({},_0x129714,_0x2421d8[_0xb147('0xc1')]);return db[_0xb147('0xc7')][_0xb147('0x9a')]({'where':_0x129714[_0xb147('0x4b')]})[_0xb147('0x26')](function(_0xb27159){_0x1ae142[_0xb147('0x9a')]=_0xb27159;if(_0x2421d8[_0xb147('0x43')][_0xb147('0xd0')]){_0x129714[_0xb147('0xc0')]=[{'all':!![]}];}return db['MailMessage'][_0xb147('0xd1')](_0x129714);})[_0xb147('0x26')](function(_0x18d23b){_0x1ae142[_0xb147('0xbd')]=_0x18d23b;return _0x1ae142;});}})[_0xb147('0x26')](respondWithFilteredResult(_0x3362d0,_0x129714))[_0xb147('0x3b')](handleError(_0x3362d0,null));};exports[_0xb147('0xd2')]=function(_0x5c3a23,_0xd5e409,_0x10ecef){return db[_0xb147('0x35')][_0xb147('0x61')]({'where':{'id':_0x5c3a23[_0xb147('0xbe')]['id']}})[_0xb147('0x26')](handleEntityNotFound(_0xd5e409,null))[_0xb147('0x26')](function(_0xfb4068){if(_0xfb4068){return _0xfb4068[_0xb147('0xd3')](_0x5c3a23[_0xb147('0xc3')][_0xb147('0xc8')],_[_0xb147('0xd4')](_0x5c3a23[_0xb147('0xc3')],['ids','id'])||{})[_0xb147('0xd5')](function(){return db['Tag'][_0xb147('0xd1')]({'attributes':['id',_0xb147('0x2b'),_0xb147('0x4e')],'where':{'id':_0x5c3a23[_0xb147('0xc3')][_0xb147('0xc8')]}});})[_0xb147('0x26')](function(_0x235ed0){socket[_0xb147('0xd6')](_0xb147('0xd7'),{'id':Number(_0x5c3a23[_0xb147('0xbe')]['id']),'tags':_0x235ed0||[]});return{'id':Number(_0x5c3a23[_0xb147('0xbe')]['id']),'tags':_0x235ed0||[]};});}})[_0xb147('0x26')](respondWithResult(_0xd5e409,null))[_0xb147('0x3b')](handleError(_0xd5e409,null));};exports[_0xb147('0xd8')]=function(_0x14b558,_0x2d2e96,_0x4903ab){return db['MailInteraction'][_0xb147('0x61')]({'where':{'id':_0x14b558['params']['id']}})['then'](handleEntityNotFound(_0x2d2e96,null))[_0xb147('0x26')](function(_0x5bbbea){if(_0x5bbbea){return _0x5bbbea[_0xb147('0xd8')](_0x14b558[_0xb147('0x43')][_0xb147('0xc8')]);}})[_0xb147('0x26')](respondWithStatusCode(_0x2d2e96,null))[_0xb147('0x3b')](handleError(_0x2d2e96,null));};exports[_0xb147('0xd9')]=function(_0x26bb5c,_0x46ca22){var _0x4ce479=moment()[_0xb147('0xda')]()[_0xb147('0x99')]();var _0x1eee30=path[_0xb147('0xdb')](config[_0xb147('0xdc')],_0xb147('0xdd'),_0xb147('0xde'),'tmp');var _0x5d54e1=path[_0xb147('0xdb')](config[_0xb147('0xdc')],_0xb147('0xdd'),_0xb147('0xde'),_0xb147('0xdf'));var _0x355b44=path[_0xb147('0xdb')](_0x1eee30,_0x4ce479);var _0x1143e6=util['format'](_0xb147('0xe0'),_0x26bb5c['params']['id'],_0x4ce479);var _0x5b2a3c=path[_0xb147('0xdb')](_0x1eee30,_0x1143e6);var _0x3e585b=[];if(_0x26bb5c[_0xb147('0x43')][_0xb147('0xdf')]){_0x3e585b[_0xb147('0x34')]({'model':db['Attachment'],'as':'Attachments','raw':!![]});}var _0x3e24da=[{'model':db['MailMessage'],'as':_0xb147('0xe1'),'attributes':['id',_0xb147('0xc3'),_0xb147('0x53'),'to','cc',_0xb147('0xe2'),'subject',_0xb147('0xe3')],'where':{'secret':![]},'order':qs['sort']('id'),'include':_0x3e585b}];return db[_0xb147('0x35')][_0xb147('0x61')]({'where':{'id':_0x26bb5c['params']['id']},'include':_0x3e24da})[_0xb147('0x26')](handleEntityNotFound(_0x46ca22,null))[_0xb147('0x26')](function(_0x303066){if(_0x303066&&_0x303066['Messages']){var _0x2b5775=_0x303066[_0xb147('0xe4')]({'plain':!![]});fs[_0xb147('0xe5')](_0x355b44);return BPromise['each'](_0x2b5775['Messages'],function(_0x4b8bdb,_0x490ea6){var _0x4be743={'from':_0x4b8bdb[_0xb147('0x53')],'to':_0x4b8bdb['to'],'subject':_0x4b8bdb[_0xb147('0xe6')],'html':_0x4b8bdb[_0xb147('0xc3')],'headers':{'Date':moment(_0x4b8bdb[_0xb147('0xe3')])[_0xb147('0xce')]('ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ')},'attachments':[]};if(_0x4b8bdb['cc']){_0x4be743[_0xb147('0xe7')]['Cc']=_0x4b8bdb['cc'];}if(_0x4b8bdb[_0xb147('0xe2')]){_0x4be743['headers'][_0xb147('0xe8')]=_0x4b8bdb[_0xb147('0xe2')];}return new BPromise(function(_0x554f0,_0x507f6b){if(_0x4b8bdb['Attachments']){for(var _0x39a099=0x0;_0x39a099<_0x4b8bdb[_0xb147('0xe9')][_0xb147('0x47')];_0x39a099++){var _0x11a51f=_0x4b8bdb[_0xb147('0xe9')][_0x39a099];var _0x2dbc4e=path[_0xb147('0xdb')](_0x5d54e1,_0x11a51f[_0xb147('0xea')]);if(fs['existsSync'](_0x2dbc4e)){_0x4be743[_0xb147('0xdf')][_0xb147('0x34')]({'name':_0x11a51f[_0xb147('0x2b')],'contentType':_0x11a51f[_0xb147('0x3f')],'data':fs['readFileSync'](_0x2dbc4e)});}}}emlformat['build'](_0x4be743,function(_0xd9cb57,_0x4afb7b){if(_0xd9cb57)return _0x507f6b(_0xd9cb57);fs['writeFileSync'](path[_0xb147('0xdb')](_0x355b44,util[_0xb147('0xce')](_0xb147('0xeb'),_0x490ea6)),_0x4afb7b);return _0x554f0(_0x4afb7b);});});})[_0xb147('0x26')](function(){return new BPromise(function(_0x1ad4f2,_0x215fa5){zipdir(_0x355b44,{'saveTo':_0x5b2a3c},function(_0x541069,_0x1e4299){if(_0x541069)return _0x215fa5(_0x541069);return _0x1ad4f2(_0x1e4299);});})['then'](function(){return new BPromise(function(_0x30456e,_0x7077e6){rimraf(_0x355b44,function(_0x449980){if(_0x449980)_0x7077e6(_0x449980);return _0x30456e();});});})['then'](function(){return _0x46ca22[_0xb147('0xd9')](_0x5b2a3c,_0x1143e6,function(_0x5d03a4){if(_0x5d03a4){console[_0xb147('0xec')](_0xb147('0xed'),_0x5d03a4);}else{fs[_0xb147('0xee')](_0x5b2a3c);}});});});}else{return _0x46ca22['sendStatus'](0xc8);}})[_0xb147('0x3b')](handleError(_0x46ca22,null));};
\ No newline at end of file
+var _0x3f36=['defaults','localhost','socket.io-emitter','./mailInteraction.socket','register','sendStatus','end','status','count','offset','limit','Content-Range','json','apply','reject','save','update','then','error','stack','name','send','Users','map','fullname','TagIds','forEach','MailInteraction','findOne','lastMsgText','fromString','catch','index','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','pick','select','field','u.id','u.fullname','from','user_has_mail_interactions','left_join','users','mail_interactions','cm_contacts','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','mail_accounts','mail_messages','me.MailInteractionId\x20=\x20i.id','tools_tags','t.id\x20=\x20it.TagId','expr','search','parseSearch','sqlOperator','conditions','unreadMessages','having','`\x20>\x200','Contact','operator','$substring','value','split','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','getFullTextValue','c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?','ContactId','buildExpression','start','Tag','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','union','User','find','UserId','text','plainBody','some','i.MailAccountId\x20IN\x20?','parse','$gte','null','\x20IS\x20NULL','\x20=\x20?','read','`unreadMessages`\x20=\x200','`unreadMessages`\x20>\x200','tag','isArray','filter','replace','isNumeric','c.email\x20LIKE\x20?','MATCH\x20(me.plainBody,\x20me.subject)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','group','i.id','Sequelize','QueryTypes','SELECT','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','DESC','isEmpty','MailAccountId','journey','i.MailAccountId\x20IS\x20NOT\x20NULL','user','i.MailAccountId\x20IS\x20NULL','sequelize','toString','merge','a.key','Account.key','a.mandatoryDisposition','contactName','i.createdAt','i.updatedAt','i.closed','i.closedAt','i.attach','i.lastMsgAt','i.lastMsgDirection','i.secondDisposition','i.thirdDisposition','i.substatus','i.to','i.ContactId','i.MailAccountId','i.UserId','c.firstName','c.lastName','Contact.lastName','c.email','c.phone','Contact.phone','c.mobile','Contact.mobile','c.fax','o.fullname','Owner.fullname','o.internal','Owner.internal','ui.MailInteractionId\x20IN\x20?','groupBy','MailInteractionId','Setting','enableEmailPreview','push','all','rows','params','includeAll','include','options','create','body','destroy','describe','MailMessage','addMessage','ids','omit','getMessages','findAll','addTags','spread','color','emit','mailInteractionTags:save','removeTags','download','unix','join','root','files','tmp','server','attachments','format','transcript-%d-%s.zip','Attachment','Attachments','Messages','bcc','subject','createdAt','get','mkdirSync','ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ','headers','Bcc','basename','existsSync','writeFileSync','message%d.eml','log','err','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','path','sox','to-csv','ejs','crypto','jsforce','querystring','papaparse','html-to-text','ioredis','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis'];(function(_0x9fd887,_0x47f76c){var _0x1a54ab=function(_0xb65c08){while(--_0xb65c08){_0x9fd887['push'](_0x9fd887['shift']());}};_0x1a54ab(++_0x47f76c);}(_0x3f36,0xd5));var _0x63f3=function(_0x121b1a,_0x42fdb7){_0x121b1a=_0x121b1a-0x0;var _0x2d89a6=_0x3f36[_0x121b1a];return _0x2d89a6;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x63f3('0x0'));var rimraf=require(_0x63f3('0x1'));var zipdir=require(_0x63f3('0x2'));var jsonpatch=require(_0x63f3('0x3'));var rp=require(_0x63f3('0x4'));var moment=require(_0x63f3('0x5'));var BPromise=require(_0x63f3('0x6'));var Mustache=require(_0x63f3('0x7'));var util=require('util');var path=require(_0x63f3('0x8'));var sox=require(_0x63f3('0x9'));var csv=require(_0x63f3('0xa'));var ejs=require(_0x63f3('0xb'));var fs=require('fs');var _=require('lodash');var squel=require('squel');var crypto=require(_0x63f3('0xc'));var jsforce=require(_0x63f3('0xd'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0x63f3('0xe'));var Papa=require(_0x63f3('0xf'));var htmlToText=require(_0x63f3('0x10'));var Redis=require(_0x63f3('0x11'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0x63f3('0x12'));var hardwareService=require(_0x63f3('0x13'));var logger=require('../../config/logger')(_0x63f3('0x14'));var utils=require(_0x63f3('0x15'));var config=require(_0x63f3('0x16'));var licenseUtil=require(_0x63f3('0x17'));var db=require(_0x63f3('0x18'))['db'];config[_0x63f3('0x19')]=_[_0x63f3('0x1a')](config[_0x63f3('0x19')],{'host':_0x63f3('0x1b'),'port':0x18eb});var socket=require(_0x63f3('0x1c'))(new Redis(config[_0x63f3('0x19')]));require(_0x63f3('0x1d'))[_0x63f3('0x1e')](socket);function respondWithStatusCode(_0x982284,_0x10beb6){_0x10beb6=_0x10beb6||0xcc;return function(_0x500a8a){if(_0x500a8a){return _0x982284[_0x63f3('0x1f')](_0x10beb6);}return _0x982284['status'](_0x10beb6)[_0x63f3('0x20')]();};}function respondWithResult(_0x31f13a,_0x57b892){_0x57b892=_0x57b892||0xc8;return function(_0x2bfccf){if(_0x2bfccf){return _0x31f13a[_0x63f3('0x21')](_0x57b892)['json'](_0x2bfccf);}};}function respondWithFilteredResult(_0x553885,_0x4dd862){return function(_0x19f347){if(_0x19f347){var _0x209bba=_0x19f347[_0x63f3('0x22')],_0x20e698=_0x4dd862[_0x63f3('0x23')],_0x41bcd7=_0x4dd862['offset']+_0x4dd862[_0x63f3('0x24')],_0x40df3f;if(_0x41bcd7>=_0x209bba){_0x41bcd7=_0x209bba;_0x40df3f=0xc8;}else{_0x40df3f=0xce;}_0x553885[_0x63f3('0x21')](_0x40df3f);return _0x553885['set'](_0x63f3('0x25'),_0x20e698+'-'+_0x41bcd7+'/'+_0x209bba)[_0x63f3('0x26')](_0x19f347);}return null;};}function patchUpdates(_0x24165d){return function(_0x5b362d){try{jsonpatch[_0x63f3('0x27')](_0x5b362d,_0x24165d,!![]);}catch(_0x5d8bfd){return BPromise[_0x63f3('0x28')](_0x5d8bfd);}return _0x5b362d[_0x63f3('0x29')]();};}function saveUpdates(_0x8b33d3,_0x13c792){return function(_0x3c6025){if(_0x3c6025){return _0x3c6025[_0x63f3('0x2a')](_0x8b33d3)[_0x63f3('0x2b')](function(_0x4eda73){return _0x4eda73;});}return null;};}function removeEntity(_0x467fd6,_0x7e41d6){return function(_0x1a5e00){if(_0x1a5e00){return _0x1a5e00['destroy']()[_0x63f3('0x2b')](function(){_0x467fd6[_0x63f3('0x21')](0xcc)[_0x63f3('0x20')]();});}};}function handleEntityNotFound(_0x28bb19,_0x14b1cb){return function(_0x9d6e8a){if(!_0x9d6e8a){_0x28bb19[_0x63f3('0x1f')](0x194);}return _0x9d6e8a;};}function handleError(_0x1a439f,_0x5ca5d0){_0x5ca5d0=_0x5ca5d0||0x1f4;return function(_0x3c1b2a){logger[_0x63f3('0x2c')](_0x3c1b2a[_0x63f3('0x2d')]);if(_0x3c1b2a[_0x63f3('0x2e')]){delete _0x3c1b2a['name'];}_0x1a439f[_0x63f3('0x21')](_0x5ca5d0)[_0x63f3('0x2f')](_0x3c1b2a);};}function getInteractionUsers(_0x526718,_0x41f81d){return new BPromise(function(_0x51c92d,_0x4f768c){try{if(_0x41f81d[_0x526718['id']]){_0x526718[_0x63f3('0x30')]=_[_0x63f3('0x31')](_0x41f81d[_0x526718['id']],function(_0x26ab65){return{'id':_0x26ab65['id'],'fullname':_0x26ab65[_0x63f3('0x32')]};});}}catch(_0x35778a){_0x4f768c(_0x35778a);}_0x51c92d(_0x526718);});}function getInteractionTags(_0x4a6f4f,_0x4a65dd){return new BPromise(function(_0x573b51,_0x119ec1){try{if(_0x4a6f4f['TagIds']){_0x4a6f4f['Tags']=[];_0x4a6f4f[_0x63f3('0x33')]['split'](',')[_0x63f3('0x34')](function(_0xe5df05){_0x4a6f4f['Tags']['push'](_0x4a65dd[_0xe5df05]);});}delete _0x4a6f4f[_0x63f3('0x33')];}catch(_0x32e0dc){_0x119ec1(_0x32e0dc);}_0x573b51(_0x4a6f4f);});}function getLastMessageText(_0x33abb8){return new BPromise(function(_0x1d4a30,_0x4a79bf){return db[_0x63f3('0x35')][_0x63f3('0x36')]({'where':{'id':_0x33abb8['id']},'attributes':['lastMsgBody',_0x63f3('0x37')],'raw':!![]})[_0x63f3('0x2b')](function(_0x57afe9){if(!_0x57afe9[_0x63f3('0x37')]){_0x33abb8[_0x63f3('0x37')]=_['trimStart'](htmlToText[_0x63f3('0x38')](_0x57afe9['lastMsgBody'],{'preserveNewlines':!![],'singleNewLineParagraphs':!![],'uppercaseHeadings':![],'noLinkBrackets':!![],'ignoreImage':!![]}));}else{_0x33abb8[_0x63f3('0x37')]=_0x57afe9['lastMsgText'];}_0x1d4a30(_0x33abb8);})[_0x63f3('0x39')](function(_0x4c2bbd){_0x4a79bf(_0x4c2bbd);});});}function updateMailInteraction(_0x54a167,_0x2ec37f,_0x43b129,_0x553900){return new BPromise(function(_0x2ea7d6,_0x26472d){return getInteractionUsers(_0x54a167,_0x43b129)[_0x63f3('0x2b')](function(_0x3176e8){return getInteractionTags(_0x3176e8,_0x2ec37f);})['then'](function(_0x38a253){if(_0x553900){_0x2ea7d6(getLastMessageText(_0x38a253));}else{_0x2ea7d6(_0x38a253);}})[_0x63f3('0x39')](function(_0x1a9b1c){_0x26472d(_0x1a9b1c);});});}exports[_0x63f3('0x3a')]=function(_0x4beead,_0x4aafd3){var _0xff3dca={},_0x202563={},_0x59b388={'count':0x0,'rows':[]};var _0x2d79c4=_[_0x63f3('0x31')](db[_0x63f3('0x35')][_0x63f3('0x3b')],function(_0x1ea5c3){return{'name':_0x1ea5c3[_0x63f3('0x3c')],'type':_0x1ea5c3[_0x63f3('0x3d')][_0x63f3('0x3e')]};});_0x202563[_0x63f3('0x3f')]=_[_0x63f3('0x31')](_0x2d79c4,_0x63f3('0x2e'));_0x202563[_0x63f3('0x40')]=_[_0x63f3('0x41')](_0x4beead[_0x63f3('0x40')]);_0x202563[_0x63f3('0x42')]=_['intersection'](_0x202563[_0x63f3('0x3f')],_0x202563[_0x63f3('0x40')]);_0xff3dca['attributes']=_[_0x63f3('0x43')](_0x202563[_0x63f3('0x3f')],qs[_0x63f3('0x44')](_0x4beead[_0x63f3('0x40')]['fields']));_0xff3dca[_0x63f3('0x45')]=_0xff3dca['attributes'][_0x63f3('0x46')]?_0xff3dca[_0x63f3('0x45')]:_0x202563['model'];if(!_0x4beead[_0x63f3('0x40')][_0x63f3('0x47')](_0x63f3('0x48'))){_0xff3dca[_0x63f3('0x24')]=qs[_0x63f3('0x24')](_0x4beead['query'][_0x63f3('0x24')]);_0xff3dca[_0x63f3('0x23')]=qs[_0x63f3('0x23')](_0x4beead['query'][_0x63f3('0x23')]);}_0xff3dca[_0x63f3('0x49')]=qs['sort'](_0x4beead[_0x63f3('0x40')][_0x63f3('0x4a')]);_0xff3dca[_0x63f3('0x4b')]=qs[_0x63f3('0x42')](_[_0x63f3('0x4c')](_0x4beead[_0x63f3('0x40')],_0x202563[_0x63f3('0x42')]),_0x2d79c4);var _0xc70c1e=[];var _0x230338=squel[_0x63f3('0x4d')]()['field']('id')[_0x63f3('0x4e')](_0x63f3('0x2e'))[_0x63f3('0x4e')]('color')['from']('tools_tags');var _0x1c122b=squel[_0x63f3('0x4d')]()[_0x63f3('0x4e')](_0x63f3('0x4f'))[_0x63f3('0x4e')](_0x63f3('0x50'))['field']('ui.MailInteractionId')[_0x63f3('0x51')](_0x63f3('0x52'),'ui')[_0x63f3('0x53')](_0x63f3('0x54'),'u','u.id\x20=\x20ui.UserId');var _0x54549b=squel[_0x63f3('0x4d')]()[_0x63f3('0x51')](_0x63f3('0x55'),'i')[_0x63f3('0x53')](_0x63f3('0x56'),'c',_0x63f3('0x57'))['left_join'](_0x63f3('0x54'),'o','o.id\x20=\x20i.UserId')[_0x63f3('0x53')](_0x63f3('0x58'),'a','a.id\x20=\x20i.MailAccountId')[_0x63f3('0x53')](_0x63f3('0x59'),'me',_0x63f3('0x5a'))[_0x63f3('0x53')]('mail_interaction_has_tags','it','it.MailInteractionId\x20=\x20i.id')[_0x63f3('0x53')](_0x63f3('0x5b'),'t',_0x63f3('0x5c'));var _0x47d470=squel[_0x63f3('0x5d')]();var _0xf75414=[];var _0x116bca=squel[_0x63f3('0x5d')]();var _0x1ffc0f;if(_0x4beead['query'][_0x63f3('0x5e')]){_0x1ffc0f=as[_0x63f3('0x5f')](_0x4beead['query'][_0x63f3('0x5e')]);var _0x25c8e3=_0x1ffc0f[_0x63f3('0x60')];for(var _0x522f43=0x0;_0x522f43<_0x1ffc0f[_0x63f3('0x61')]['length'];_0x522f43++){var _0x899936=_0x1ffc0f[_0x63f3('0x61')][_0x522f43];var _0x16a2db='i';var _0x5d534=_['find'](_0x2d79c4,[_0x63f3('0x2e'),_0x899936[_0x63f3('0x4e')]]);if(!_0x5d534){switch(_0x899936['field']){case _0x63f3('0x62'):if(_0x899936['value']==0x1){_0x54549b[_0x63f3('0x63')]('`'+_0x899936[_0x63f3('0x4e')]+'`\x20=\x200');}else{_0x54549b['having']('`'+_0x899936['field']+_0x63f3('0x64'));}break;case _0x63f3('0x65'):if(_0x899936[_0x63f3('0x66')]===_0x63f3('0x67')){if(_0x899936[_0x63f3('0x68')][_0x63f3('0x69')]('\x20')['length']>0x1){_0x47d470[_0x25c8e3](_0x63f3('0x6a'),qs[_0x63f3('0x6b')](_0x899936[_0x63f3('0x68')]),null);}else{var _0x457987='%'+_0x899936[_0x63f3('0x68')]+'%';_0x47d470[_0x25c8e3](_0x63f3('0x6c'),_0x457987,_0x457987,_0x457987);}}else{_0x5d534=_['find'](_0x2d79c4,['name',_0x63f3('0x6d')]);_0x899936[_0x63f3('0x4e')]='ContactId';_0x3f80df=as[_0x63f3('0x6e')](_0x16a2db,_0x5d534[_0x63f3('0x3d')],_0x899936);_0x47d470[_0x25c8e3](_0x3f80df['text'],_0x3f80df[_0x63f3('0x68')][_0x63f3('0x6f')],_0x3f80df['value']['end']);}break;case _0x63f3('0x70'):var _0x5569ae=_0x899936[_0x63f3('0x68')][_0x63f3('0x69')](',')[_0x63f3('0x31')](function(_0x91ff48){return Number(_0x91ff48);});_0x5569ae['forEach'](function(_0x36e399){_0x116bca['or'](_0x63f3('0x71'),'%,'+_0x36e399+',%');});_0xf75414=_[_0x63f3('0x72')](_0xf75414,_0x5569ae);break;case _0x63f3('0x73'):if(_0x899936[_0x63f3('0x66')]===_0x63f3('0x67')){_0x47d470[_0x25c8e3]('CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','%'+_0x899936['value']+'%',null);}else{_0x5d534=_[_0x63f3('0x74')](_0x2d79c4,[_0x63f3('0x2e'),_0x63f3('0x75')]);_0x899936[_0x63f3('0x4e')]=_0x63f3('0x75');_0x3f80df=as[_0x63f3('0x6e')](_0x16a2db,_0x5d534[_0x63f3('0x3d')],_0x899936);_0x47d470[_0x25c8e3](_0x3f80df[_0x63f3('0x76')],_0x3f80df[_0x63f3('0x68')]['start'],_0x3f80df['value']['end']);}break;case _0x63f3('0x77'):_0x3f80df=as['buildExpression']('me',null,_0x899936);_0x47d470[_0x25c8e3](_0x3f80df['text'],_0x3f80df['value'][_0x63f3('0x6f')],_0x3f80df[_0x63f3('0x68')][_0x63f3('0x20')]);break;}}else{var _0x3f80df=as['buildExpression'](_0x16a2db,_0x5d534[_0x63f3('0x3d')],_0x899936);_0x47d470[_0x25c8e3](_0x3f80df['text'],_0x3f80df['value']['start'],_0x3f80df[_0x63f3('0x68')]['end']);}}}else{var _0x1a1502=_(_0x4beead[_0x63f3('0x40')])['keys']()[_0x63f3('0x31')](function(_0x3db9c5){return _[_0x63f3('0x78')](_0x2d79c4,[_0x63f3('0x2e'),_0x3db9c5])?_0x3db9c5:undefined;})['compact']()[_0x63f3('0x68')]();if(!_['isEmpty'](_0x1a1502)){_0x1a1502['forEach'](function(_0x5b64f4){if(_0x5b64f4==='MailAccountId'){_0x54549b['where'](_0x63f3('0x79'),[]['concat'](_0x4beead['query'][_0x5b64f4]));}else if(_0x5b64f4==='createdAt'){var _0x140498=JSON[_0x63f3('0x7a')](_0x4beead['query'][_0x5b64f4])[_0x63f3('0x7b')];var _0x2c5f5c=JSON[_0x63f3('0x7a')](_0x4beead['query'][_0x5b64f4])['$lte'];_0x54549b[_0x63f3('0x4b')]('i.createdAt\x20BETWEEN\x20?\x20AND\x20?',_0x140498,_0x2c5f5c);}else{if(_0x4beead[_0x63f3('0x40')][_0x5b64f4]===_0x63f3('0x7c')){_0x54549b['where']('i.'+_0x5b64f4+_0x63f3('0x7d'));}else{_0x54549b[_0x63f3('0x4b')]('i.'+_0x5b64f4+_0x63f3('0x7e'),_0x4beead['query'][_0x5b64f4]);}}});}if(_0x4beead[_0x63f3('0x40')][_0x63f3('0x7f')]){if(_0x4beead[_0x63f3('0x40')][_0x63f3('0x7f')]==0x1){_0x54549b[_0x63f3('0x63')](_0x63f3('0x80'));}else{_0x54549b['having'](_0x63f3('0x81'));}}if(_0x4beead[_0x63f3('0x40')][_0x63f3('0x82')]){_0xf75414=_[_0x63f3('0x83')](_0x4beead[_0x63f3('0x40')][_0x63f3('0x82')])?_0x4beead[_0x63f3('0x40')][_0x63f3('0x82')]:new Array(_0x4beead['query'][_0x63f3('0x82')]);_0xf75414[_0x63f3('0x34')](function(_0x5e2cce){_0x116bca['or'](_0x63f3('0x71'),'%,'+_0x5e2cce+',%');});}if(_0x4beead[_0x63f3('0x40')][_0x63f3('0x84')]){var _0x3ed0ae=_0x4beead[_0x63f3('0x40')][_0x63f3('0x84')][_0x63f3('0x85')]('\x5c','\x5c\x5c')['replace'](/'/g,'\x27\x27');if(qs[_0x63f3('0x86')](_0x3ed0ae)){_0x47d470['or']('i.id\x20LIKE\x20?',_0x3ed0ae+'%');}else if(qs['isEmail'](_0x3ed0ae)){_0x47d470['or'](_0x63f3('0x87'),_0x3ed0ae+'%');}else{_0x47d470['or']('MATCH\x20(i.to,\x20i.subject)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs[_0x63f3('0x6b')](_0x3ed0ae))['or'](_0x63f3('0x88'),qs[_0x63f3('0x6b')](_0x3ed0ae));}}}_0x54549b[_0x63f3('0x4b')](_0x47d470);_0x54549b[_0x63f3('0x89')](_0x63f3('0x8a'));var _0x5c9ef2={'type':db[_0x63f3('0x8b')][_0x63f3('0x8c')][_0x63f3('0x8d')],'raw':!![]};var _0x1ed63b=_0x54549b['clone']();_0x1ed63b[_0x63f3('0x4e')]('i.id');_0x1ed63b[_0x63f3('0x4e')](_0x63f3('0x8e'),'unreadMessages');if(_0xff3dca[_0x63f3('0x49')]){_0xff3dca[_0x63f3('0x49')]['forEach'](function(_0x566333){var _0x38b8f8=_0x566333[0x0]==='contactName'?_0x566333[0x0]:'i.'+_0x566333[0x0];_0x54549b[_0x63f3('0x49')](_0x38b8f8,_0x566333[0x1]===_0x63f3('0x8f')?![]:!![]);});}if(!_[_0x63f3('0x90')](_0xf75414)){_0x54549b[_0x63f3('0x63')](_0x116bca);_0x1ed63b[_0x63f3('0x4b')]('t.id\x20IN\x20?',_0xf75414);}BPromise['resolve']()[_0x63f3('0x2b')](function(){if(!_0x1ffc0f){if(_0x4beead[_0x63f3('0x40')][_0x63f3('0x91')]||_0x4beead[_0x63f3('0x40')][_0x63f3('0x92')])return;_0x1ed63b[_0x63f3('0x4b')](_0x63f3('0x93'));_0x54549b[_0x63f3('0x4b')]('i.MailAccountId\x20IS\x20NOT\x20NULL');return;}return _0x4beead[_0x63f3('0x94')]['getMailAccounts']({'attributes':['id'],'raw':!![]})[_0x63f3('0x2b')](function(_0x3aab96){if(_[_0x63f3('0x90')](_0x3aab96)){_0x1ed63b[_0x63f3('0x4b')]('i.MailAccountId\x20IS\x20NULL');_0x54549b['where'](_0x63f3('0x95'));}else{_0x1ed63b[_0x63f3('0x4b')]('i.MailAccountId\x20IN\x20?',_[_0x63f3('0x31')](_0x3aab96,'id'));_0x54549b[_0x63f3('0x4b')](_0x63f3('0x79'),_[_0x63f3('0x31')](_0x3aab96,'id'));}});})[_0x63f3('0x2b')](function(){db[_0x63f3('0x96')][_0x63f3('0x40')](_0x1ed63b[_0x63f3('0x97')](),_0x5c9ef2)[_0x63f3('0x2b')](function(_0x24550f){_0x59b388['count']=_0x24550f['length'];if(_0x59b388[_0x63f3('0x22')]===0x0)return[];return db[_0x63f3('0x96')][_0x63f3('0x40')](_0x230338['toString'](),_0x5c9ef2)[_0x63f3('0x2b')](function(_0x51e52b){_0xc70c1e=_['keyBy'](_0x51e52b,'id');_0x5c9ef2=_[_0x63f3('0x98')](_0x5c9ef2,{'model':db['MailInteraction'],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x4beead['query']['fields']){_0xff3dca[_0x63f3('0x45')][_0x63f3('0x34')](function(_0x2ebba2){_0x54549b['field']('i.'+_0x2ebba2);});}else{_0x54549b['field']('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)',_0x63f3('0x62'));_0x54549b['field'](_0x63f3('0x99'),_0x63f3('0x9a'));_0x54549b[_0x63f3('0x4e')](_0x63f3('0x9b'),'Account.mandatoryDisposition');_0x54549b[_0x63f3('0x4e')]('CASE\x20WHEN\x20i.to\x20IS\x20NOT\x20NULL\x20AND\x20i.to\x20<>\x20\x27\x27\x20AND\x20i.to\x20NOT\x20LIKE\x20(\x27%\x27\x20+\x20a.email\x20+\x20\x27%\x27)\x20THEN\x20SUBSTRING_INDEX(i.to,\x20\x27<\x27,\x201)\x20WHEN\x20(c.firstName\x20IS\x20NOT\x20NULL\x20AND\x20c.firstName\x20<>\x20\x27\x27)\x20OR\x20(c.lastName\x20IS\x20NOT\x20NULL\x20AND\x20c.lastName\x20<>\x20\x27\x27)\x20THEN\x20CONCAT(IFNULL(c.firstName,\x20\x27\x27),\x20\x27\x20\x27,\x20IFNULL(c.lastName,\x20\x27\x27))\x20ELSE\x20\x27Unknown\x27\x20END',_0x63f3('0x9c'));_0x54549b[_0x63f3('0x4e')](_0x63f3('0x8a'));_0x54549b[_0x63f3('0x4e')](_0x63f3('0x9d'));_0x54549b['field'](_0x63f3('0x9e'));_0x54549b['field'](_0x63f3('0x9f'));_0x54549b['field'](_0x63f3('0xa0'));_0x54549b[_0x63f3('0x4e')](_0x63f3('0xa1'));_0x54549b['field'](_0x63f3('0xa2'));_0x54549b[_0x63f3('0x4e')](_0x63f3('0xa3'));_0x54549b['field']('i.subject');_0x54549b[_0x63f3('0x4e')]('i.disposition');_0x54549b[_0x63f3('0x4e')](_0x63f3('0xa4'));_0x54549b[_0x63f3('0x4e')](_0x63f3('0xa5'));_0x54549b[_0x63f3('0x4e')](_0x63f3('0xa6'));_0x54549b[_0x63f3('0x4e')](_0x63f3('0xa7'));_0x54549b[_0x63f3('0x4e')](_0x63f3('0xa8'));_0x54549b[_0x63f3('0x4e')](_0x63f3('0xa9'));_0x54549b[_0x63f3('0x4e')](_0x63f3('0xaa'));_0x54549b[_0x63f3('0x4e')](_0x63f3('0xab'),'Contact.firstName');_0x54549b['field'](_0x63f3('0xac'),_0x63f3('0xad'));_0x54549b[_0x63f3('0x4e')](_0x63f3('0xae'),'Contact.email');_0x54549b[_0x63f3('0x4e')](_0x63f3('0xaf'),_0x63f3('0xb0'));_0x54549b[_0x63f3('0x4e')](_0x63f3('0xb1'),_0x63f3('0xb2'));_0x54549b['field'](_0x63f3('0xb3'),'Contact.fax');_0x54549b[_0x63f3('0x4e')](_0x63f3('0xb4'),_0x63f3('0xb5'));_0x54549b[_0x63f3('0x4e')](_0x63f3('0xb6'),_0x63f3('0xb7'));_0x54549b[_0x63f3('0x4e')]('GROUP_CONCAT(DISTINCT\x20t.id)',_0x63f3('0x33'));}if(_0xff3dca[_0x63f3('0x24')])_0x54549b[_0x63f3('0x24')](_0xff3dca['limit']);if(_0xff3dca['offset'])_0x54549b[_0x63f3('0x23')](_0xff3dca[_0x63f3('0x23')]);return db[_0x63f3('0x96')][_0x63f3('0x40')](_0x54549b['toString'](),_0x5c9ef2);})[_0x63f3('0x2b')](function(_0x1d4933){_0x1c122b['where'](_0x63f3('0xb8'),_[_0x63f3('0x31')](_0x1d4933,'id'));return db[_0x63f3('0x96')][_0x63f3('0x40')](_0x1c122b['toString'](),_0x5c9ef2)[_0x63f3('0x2b')](function(_0x3456f8){var _0x2af7af=_[_0x63f3('0xb9')](_0x3456f8,_0x63f3('0xba'));var _0x529daf=[];return db[_0x63f3('0xbb')]['findOne']({'attributes':[_0x63f3('0xbc')],'raw':!![]})['then'](function(_0x3f52ec){var _0x1ea0b9=_0x3f52ec[_0x63f3('0xbc')];_0x1d4933[_0x63f3('0x34')](function(_0x36a12c){_0x529daf[_0x63f3('0xbd')](updateMailInteraction(_0x36a12c,_0xc70c1e,_0x2af7af,_0x1ea0b9));});return BPromise[_0x63f3('0xbe')](_0x529daf);});});});})[_0x63f3('0x2b')](function(_0x2792f6){_0x59b388[_0x63f3('0xbf')]=_0x2792f6;return _0x59b388;})[_0x63f3('0x2b')](respondWithFilteredResult(_0x4aafd3,_0xff3dca));})[_0x63f3('0x39')](handleError(_0x4aafd3,null));};exports['show']=function(_0x2ad0f2,_0x410b7e){var _0x5c2695={'raw':![],'where':{'id':_0x2ad0f2[_0x63f3('0xc0')]['id']}},_0x455562={};_0x455562[_0x63f3('0x3f')]=_[_0x63f3('0x41')](db[_0x63f3('0x35')][_0x63f3('0x3b')]);_0x455562[_0x63f3('0x40')]=_[_0x63f3('0x41')](_0x2ad0f2[_0x63f3('0x40')]);_0x455562['filters']=_[_0x63f3('0x43')](_0x455562[_0x63f3('0x3f')],_0x455562[_0x63f3('0x40')]);_0x5c2695[_0x63f3('0x45')]=_[_0x63f3('0x43')](_0x455562[_0x63f3('0x3f')],qs[_0x63f3('0x44')](_0x2ad0f2[_0x63f3('0x40')][_0x63f3('0x44')]));_0x5c2695[_0x63f3('0x45')]=_0x5c2695[_0x63f3('0x45')][_0x63f3('0x46')]?_0x5c2695[_0x63f3('0x45')]:_0x455562[_0x63f3('0x3f')];if(_0x2ad0f2[_0x63f3('0x40')][_0x63f3('0xc1')]){_0x5c2695[_0x63f3('0xc2')]=[{'all':!![]}];}_0x5c2695=_['merge']({},_0x5c2695,_0x2ad0f2[_0x63f3('0xc3')]);return db[_0x63f3('0x35')]['find'](_0x5c2695)[_0x63f3('0x2b')](handleEntityNotFound(_0x410b7e,null))[_0x63f3('0x2b')](respondWithResult(_0x410b7e,null))[_0x63f3('0x39')](handleError(_0x410b7e,null));};exports[_0x63f3('0xc4')]=function(_0x4a981f,_0x16afc6){return db[_0x63f3('0x35')]['create'](_0x4a981f['body'],{})[_0x63f3('0x2b')](respondWithResult(_0x16afc6,0xc9))[_0x63f3('0x39')](handleError(_0x16afc6,null));};exports[_0x63f3('0x2a')]=function(_0x335701,_0x4d0fc8){if(_0x335701[_0x63f3('0xc5')]['id']){delete _0x335701[_0x63f3('0xc5')]['id'];}return db[_0x63f3('0x35')][_0x63f3('0x74')]({'where':{'id':_0x335701[_0x63f3('0xc0')]['id']}})[_0x63f3('0x2b')](handleEntityNotFound(_0x4d0fc8,null))[_0x63f3('0x2b')](saveUpdates(_0x335701[_0x63f3('0xc5')],null))['then'](respondWithResult(_0x4d0fc8,null))[_0x63f3('0x39')](handleError(_0x4d0fc8,null));};exports[_0x63f3('0xc6')]=function(_0x2e5fe9,_0x2b8fda){return db['MailInteraction'][_0x63f3('0x74')]({'where':{'id':_0x2e5fe9[_0x63f3('0xc0')]['id']}})[_0x63f3('0x2b')](handleEntityNotFound(_0x2b8fda,null))['then'](removeEntity(_0x2b8fda,null))[_0x63f3('0x39')](handleError(_0x2b8fda,null));};exports[_0x63f3('0xc7')]=function(_0x5d77fb,_0x21e70f){return db[_0x63f3('0x35')]['describe']()['then'](respondWithResult(_0x21e70f,null))[_0x63f3('0x39')](handleError(_0x21e70f,null));};exports['addMessage']=function(_0x1d1ed0,_0x467d05,_0x3a3ed2){return db[_0x63f3('0xc8')][_0x63f3('0x74')]({'where':{'id':_0x1d1ed0['params']['id']}})[_0x63f3('0x2b')](handleEntityNotFound(_0x467d05,null))[_0x63f3('0x2b')](function(_0x1351ec){if(_0x1351ec){return _0x1351ec[_0x63f3('0xc9')](_0x1d1ed0['body'][_0x63f3('0xca')],_[_0x63f3('0xcb')](_0x1d1ed0[_0x63f3('0xc5')],[_0x63f3('0xca'),'id'])||{});}})[_0x63f3('0x2b')](respondWithResult(_0x467d05,null))[_0x63f3('0x39')](handleError(_0x467d05,null));};exports[_0x63f3('0xcc')]=function(_0x4e907a,_0x5ef2a8,_0x4c4983){var _0x21cd85={'raw':![],'where':{}};var _0x3cf5f7={};var _0x1d2a98={'count':0x0,'rows':[]};return db['MailInteraction'][_0x63f3('0x36')]({'where':{'id':_0x4e907a[_0x63f3('0xc0')]['id']}})[_0x63f3('0x2b')](handleEntityNotFound(_0x5ef2a8,null))['then'](function(_0x19df14){if(_0x19df14){_0x3cf5f7['model']=_[_0x63f3('0x41')](db[_0x63f3('0xc8')][_0x63f3('0x3b')]);_0x3cf5f7[_0x63f3('0x40')]=_[_0x63f3('0x41')](_0x4e907a[_0x63f3('0x40')]);_0x3cf5f7['filters']=_['intersection'](_0x3cf5f7[_0x63f3('0x3f')],_0x3cf5f7[_0x63f3('0x40')]);_0x21cd85['attributes']=_[_0x63f3('0x43')](_0x3cf5f7[_0x63f3('0x3f')],qs[_0x63f3('0x44')](_0x4e907a[_0x63f3('0x40')][_0x63f3('0x44')]));_0x21cd85[_0x63f3('0x45')]=_0x21cd85[_0x63f3('0x45')]['length']?_0x21cd85[_0x63f3('0x45')]:_0x3cf5f7[_0x63f3('0x3f')];if(!_0x4e907a[_0x63f3('0x40')][_0x63f3('0x47')](_0x63f3('0x48'))){_0x21cd85[_0x63f3('0x24')]=qs[_0x63f3('0x24')](_0x4e907a[_0x63f3('0x40')][_0x63f3('0x24')]);_0x21cd85[_0x63f3('0x23')]=qs['offset'](_0x4e907a[_0x63f3('0x40')][_0x63f3('0x23')]);}_0x21cd85[_0x63f3('0x49')]=qs['sort'](_0x4e907a[_0x63f3('0x40')]['sort']);_0x21cd85[_0x63f3('0x4b')]=qs['filters'](_[_0x63f3('0x4c')](_0x4e907a[_0x63f3('0x40')],_0x3cf5f7[_0x63f3('0x42')]));_0x21cd85['where'][_0x63f3('0xba')]=_0x19df14['id'];if(_0x4e907a['query'][_0x63f3('0x84')]){_0x21cd85[_0x63f3('0x4b')]=_[_0x63f3('0x98')](_0x21cd85['where'],{'$or':_[_0x63f3('0x31')](_0x21cd85[_0x63f3('0x45')],function(_0x43688a){var _0x23b421={};_0x23b421[_0x43688a]={'$like':'%'+_0x4e907a['query']['filter']+'%'};return _0x23b421;})});}if(_0x4e907a[_0x63f3('0x40')][_0x63f3('0x7b')]){var _0x3479a1=_0x4e907a[_0x63f3('0x40')][_0x63f3('0x7b')]['split'](',');var _0x111526={};_0x111526[_0x3479a1[0x0]]={'$gte':moment(_0x3479a1[0x1])['format']('YYYY-MM-DD\x20HH:mm:ss')};_0x21cd85[_0x63f3('0x4b')]=_[_0x63f3('0x98')](_0x21cd85['where'],_0x111526);}_0x21cd85=_[_0x63f3('0x98')]({},_0x21cd85,_0x4e907a['options']);return db[_0x63f3('0xc8')][_0x63f3('0x22')]({'where':_0x21cd85['where']})[_0x63f3('0x2b')](function(_0x442df5){_0x1d2a98[_0x63f3('0x22')]=_0x442df5;if(_0x4e907a[_0x63f3('0x40')][_0x63f3('0xc1')]){_0x21cd85[_0x63f3('0xc2')]=[{'all':!![]}];}return db[_0x63f3('0xc8')][_0x63f3('0xcd')](_0x21cd85);})['then'](function(_0x32a228){_0x1d2a98[_0x63f3('0xbf')]=_0x32a228;return _0x1d2a98;});}})[_0x63f3('0x2b')](respondWithFilteredResult(_0x5ef2a8,_0x21cd85))['catch'](handleError(_0x5ef2a8,null));};exports[_0x63f3('0xce')]=function(_0x4e2a12,_0x8484,_0x36a20f){return db[_0x63f3('0x35')][_0x63f3('0x74')]({'where':{'id':_0x4e2a12['params']['id']}})[_0x63f3('0x2b')](handleEntityNotFound(_0x8484,null))[_0x63f3('0x2b')](function(_0x2693e3){if(_0x2693e3){return _0x2693e3['setTags'](_0x4e2a12[_0x63f3('0xc5')][_0x63f3('0xca')],_[_0x63f3('0xcb')](_0x4e2a12['body'],['ids','id'])||{})[_0x63f3('0xcf')](function(){return db[_0x63f3('0x70')][_0x63f3('0xcd')]({'attributes':['id',_0x63f3('0x2e'),_0x63f3('0xd0')],'where':{'id':_0x4e2a12['body'][_0x63f3('0xca')]}});})[_0x63f3('0x2b')](function(_0x38ab6f){socket[_0x63f3('0xd1')](_0x63f3('0xd2'),{'id':Number(_0x4e2a12[_0x63f3('0xc0')]['id']),'tags':_0x38ab6f||[]});return{'id':Number(_0x4e2a12[_0x63f3('0xc0')]['id']),'tags':_0x38ab6f||[]};});}})[_0x63f3('0x2b')](respondWithResult(_0x8484,null))['catch'](handleError(_0x8484,null));};exports[_0x63f3('0xd3')]=function(_0x297f1f,_0x27be25,_0x53c2a7){return db[_0x63f3('0x35')][_0x63f3('0x74')]({'where':{'id':_0x297f1f[_0x63f3('0xc0')]['id']}})['then'](handleEntityNotFound(_0x27be25,null))['then'](function(_0x19a809){if(_0x19a809){return _0x19a809[_0x63f3('0xd3')](_0x297f1f[_0x63f3('0x40')][_0x63f3('0xca')]);}})[_0x63f3('0x2b')](respondWithStatusCode(_0x27be25,null))['catch'](handleError(_0x27be25,null));};exports[_0x63f3('0xd4')]=function(_0x44c670,_0x3b7f54){var _0x42921c=moment()[_0x63f3('0xd5')]()['toString']();var _0x11446c=path[_0x63f3('0xd6')](config[_0x63f3('0xd7')],'server',_0x63f3('0xd8'),_0x63f3('0xd9'));var _0x5317aa=path['join'](config[_0x63f3('0xd7')],_0x63f3('0xda'),_0x63f3('0xd8'),_0x63f3('0xdb'));var _0x19eca8=path['join'](_0x11446c,_0x42921c);var _0x57233c=util[_0x63f3('0xdc')](_0x63f3('0xdd'),_0x44c670[_0x63f3('0xc0')]['id'],_0x42921c);var _0x3deefe=path[_0x63f3('0xd6')](_0x11446c,_0x57233c);var _0x4eaf4a=[];if(_0x44c670[_0x63f3('0x40')][_0x63f3('0xdb')]){_0x4eaf4a[_0x63f3('0xbd')]({'model':db[_0x63f3('0xde')],'as':_0x63f3('0xdf'),'raw':!![]});}var _0xb9a51c=[{'model':db['MailMessage'],'as':_0x63f3('0xe0'),'attributes':['id',_0x63f3('0xc5'),_0x63f3('0x51'),'to','cc',_0x63f3('0xe1'),_0x63f3('0xe2'),_0x63f3('0xe3')],'where':{'secret':![]},'order':qs[_0x63f3('0x4a')]('id'),'include':_0x4eaf4a}];return db[_0x63f3('0x35')][_0x63f3('0x74')]({'where':{'id':_0x44c670[_0x63f3('0xc0')]['id']},'include':_0xb9a51c})[_0x63f3('0x2b')](handleEntityNotFound(_0x3b7f54,null))[_0x63f3('0x2b')](function(_0x3a5e96){if(_0x3a5e96&&_0x3a5e96['Messages']){var _0x57ff3e=_0x3a5e96[_0x63f3('0xe4')]({'plain':!![]});fs[_0x63f3('0xe5')](_0x19eca8);return BPromise['each'](_0x57ff3e[_0x63f3('0xe0')],function(_0x4b1709,_0x165866){var _0x2dea2a={'from':_0x4b1709[_0x63f3('0x51')],'to':_0x4b1709['to'],'subject':_0x4b1709[_0x63f3('0xe2')],'html':_0x4b1709[_0x63f3('0xc5')],'headers':{'Date':moment(_0x4b1709[_0x63f3('0xe3')])[_0x63f3('0xdc')](_0x63f3('0xe6'))},'attachments':[]};if(_0x4b1709['cc']){_0x2dea2a[_0x63f3('0xe7')]['Cc']=_0x4b1709['cc'];}if(_0x4b1709[_0x63f3('0xe1')]){_0x2dea2a[_0x63f3('0xe7')][_0x63f3('0xe8')]=_0x4b1709[_0x63f3('0xe1')];}return new BPromise(function(_0x1f9a07,_0x1fff8c){if(_0x4b1709[_0x63f3('0xdf')]){for(var _0x2ef443=0x0;_0x2ef443<_0x4b1709[_0x63f3('0xdf')][_0x63f3('0x46')];_0x2ef443++){var _0x234499=_0x4b1709[_0x63f3('0xdf')][_0x2ef443];var _0x4be5ba=path[_0x63f3('0xd6')](_0x5317aa,_0x234499[_0x63f3('0xe9')]);if(fs[_0x63f3('0xea')](_0x4be5ba)){_0x2dea2a[_0x63f3('0xdb')][_0x63f3('0xbd')]({'name':_0x234499['name'],'contentType':_0x234499[_0x63f3('0x3d')],'data':fs['readFileSync'](_0x4be5ba)});}}}emlformat['build'](_0x2dea2a,function(_0x1a42bb,_0x738fc7){if(_0x1a42bb)return _0x1fff8c(_0x1a42bb);fs[_0x63f3('0xeb')](path['join'](_0x19eca8,util[_0x63f3('0xdc')](_0x63f3('0xec'),_0x165866)),_0x738fc7);return _0x1f9a07(_0x738fc7);});});})[_0x63f3('0x2b')](function(){return new BPromise(function(_0x130249,_0x48e27b){zipdir(_0x19eca8,{'saveTo':_0x3deefe},function(_0x4c4c02,_0x6c0418){if(_0x4c4c02)return _0x48e27b(_0x4c4c02);return _0x130249(_0x6c0418);});})['then'](function(){return new BPromise(function(_0xf152af,_0x508422){rimraf(_0x19eca8,function(_0x222e37){if(_0x222e37)_0x508422(_0x222e37);return _0xf152af();});});})[_0x63f3('0x2b')](function(){return _0x3b7f54[_0x63f3('0xd4')](_0x3deefe,_0x57233c,function(_0x393a40){if(_0x393a40){console[_0x63f3('0xed')](_0x63f3('0xee'),_0x393a40);}else{fs['unlinkSync'](_0x3deefe);}});});});}else{return _0x3b7f54[_0x63f3('0x1f')](0xc8);}})['catch'](handleError(_0x3b7f54,null));};
\ No newline at end of file