Built motion from commit (unavailable).|2.5.22
[motion2.git] / server / api / mailInteraction / mailInteraction.controller.js
index da237d2..193cbe1 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x1939=['attributes','intersection','model','fields','length','hasOwnProperty','limit','order','sort','where','pick','field','color','from','tools_tags','select','u.fullname','ui.MailInteractionId','users','u.id\x20=\x20ui.UserId','left_join','cm_contacts','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','o.id\x20=\x20i.UserId','mail_accounts','a.id\x20=\x20i.MailAccountId','me.MailInteractionId\x20=\x20i.id','mail_interaction_has_tags','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','type','start','end','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','UserId','plainBody','text','some','i.MailAccountId\x20IN\x20?','concat','parse','$lte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','\x20IS\x20NULL','\x20=\x20?','read','`unreadMessages`\x20>\x200','tag','isArray','filter','replace','MATCH\x20(i.to,\x20i.subject)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','MATCH\x20(me.plainBody,\x20me.subject)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','group','i.id','Sequelize','QueryTypes','SELECT','clone','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','unreadMessages','DESC','isEmpty','t.id\x20IN\x20?','resolve','i.MailAccountId\x20IS\x20NOT\x20NULL','role','agent','user','getMailAccounts','i.MailAccountId\x20IS\x20NULL','MailAccountId','sequelize','toString','keyBy','a.key','Account.key','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','contactName','i.createdAt','i.updatedAt','i.closedAt','i.attach','i.lastMsgAt','i.lastMsgDirection','i.subject','i.disposition','i.secondDisposition','i.substatus','i.to','i.ContactId','c.firstName','c.email','Contact.email','c.phone','Contact.phone','c.mobile','c.fax','Contact.fax','Owner.fullname','o.internal','GROUP_CONCAT(DISTINCT\x20t.id)','ui.MailInteractionId\x20IN\x20?','groupBy','MailInteractionId','enableEmailPreview','all','show','params','includeAll','include','merge','options','create','body','describe','addMessage','omit','ids','getMessages','MailMessage','nolimit','$gte','YYYY-MM-DD\x20HH:mm:ss','findAll','setTags','Tag','emit','mailInteractionTags:save','removeTags','download','unix','join','root','server','files','tmp','format','transcript-%d-%s.zip','attachments','Attachment','Attachments','Messages','bcc','subject','createdAt','get','mkdirSync','each','headers','Bcc','basename','existsSync','readFileSync','build','writeFileSync','message%d.eml','log','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','path','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','html-to-text','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./mailInteraction.socket','register','sendStatus','status','json','count','offset','set','Content-Range','apply','reject','update','destroy','then','error','stack','name','send','Users','map','TagIds','Tags','split','forEach','push','MailInteraction','findOne','lastMsgBody','lastMsgText','trimStart','fromString','catch','index','rawAttributes','fieldName','query','keys','filters'];(function(_0x19c1f3,_0x164d69){var _0x490920=function(_0x1fe22e){while(--_0x1fe22e){_0x19c1f3['push'](_0x19c1f3['shift']());}};_0x490920(++_0x164d69);}(_0x1939,0x1a7));var _0x9193=function(_0x4605dc,_0x3f7ae5){_0x4605dc=_0x4605dc-0x0;var _0x5d3e81=_0x1939[_0x4605dc];return _0x5d3e81;};'use strict';var pdf=require(_0x9193('0x0'));var emlformat=require(_0x9193('0x1'));var rimraf=require(_0x9193('0x2'));var zipdir=require(_0x9193('0x3'));var jsonpatch=require(_0x9193('0x4'));var rp=require(_0x9193('0x5'));var moment=require(_0x9193('0x6'));var BPromise=require('bluebird');var Mustache=require(_0x9193('0x7'));var util=require('util');var path=require(_0x9193('0x8'));var sox=require('sox');var csv=require(_0x9193('0x9'));var ejs=require(_0x9193('0xa'));var fs=require('fs');var _=require(_0x9193('0xb'));var squel=require(_0x9193('0xc'));var crypto=require(_0x9193('0xd'));var jsforce=require(_0x9193('0xe'));var deskjs=require(_0x9193('0xf'));var toCsv=require('to-csv');var querystring=require(_0x9193('0x10'));var Papa=require('papaparse');var htmlToText=require(_0x9193('0x11'));var Redis=require(_0x9193('0x12'));var authService=require(_0x9193('0x13'));var qs=require(_0x9193('0x14'));var as=require(_0x9193('0x15'));var hardwareService=require(_0x9193('0x16'));var logger=require(_0x9193('0x17'))(_0x9193('0x18'));var utils=require(_0x9193('0x19'));var config=require(_0x9193('0x1a'));var licenseUtil=require(_0x9193('0x1b'));var db=require(_0x9193('0x1c'))['db'];config[_0x9193('0x1d')]=_[_0x9193('0x1e')](config[_0x9193('0x1d')],{'host':_0x9193('0x1f'),'port':0x18eb});var socket=require(_0x9193('0x20'))(new Redis(config[_0x9193('0x1d')]));require(_0x9193('0x21'))[_0x9193('0x22')](socket);function respondWithStatusCode(_0x407f13,_0x1ac624){_0x1ac624=_0x1ac624||0xcc;return function(_0x12c954){if(_0x12c954){return _0x407f13[_0x9193('0x23')](_0x1ac624);}return _0x407f13[_0x9193('0x24')](_0x1ac624)['end']();};}function respondWithResult(_0x28cd8b,_0x3f9738){_0x3f9738=_0x3f9738||0xc8;return function(_0x1272b1){if(_0x1272b1){return _0x28cd8b[_0x9193('0x24')](_0x3f9738)[_0x9193('0x25')](_0x1272b1);}};}function respondWithFilteredResult(_0x3c6994,_0x46d2b9){return function(_0x541c14){if(_0x541c14){var _0x29a3d3=_0x541c14[_0x9193('0x26')],_0x25199a=_0x46d2b9['offset'],_0x10f359=_0x46d2b9[_0x9193('0x27')]+_0x46d2b9['limit'],_0x1510db;if(_0x10f359>=_0x29a3d3){_0x10f359=_0x29a3d3;_0x1510db=0xc8;}else{_0x1510db=0xce;}_0x3c6994[_0x9193('0x24')](_0x1510db);return _0x3c6994[_0x9193('0x28')](_0x9193('0x29'),_0x25199a+'-'+_0x10f359+'/'+_0x29a3d3)[_0x9193('0x25')](_0x541c14);}return null;};}function patchUpdates(_0x3a4ec3){return function(_0x3a42ad){try{jsonpatch[_0x9193('0x2a')](_0x3a42ad,_0x3a4ec3,!![]);}catch(_0x37ef13){return BPromise[_0x9193('0x2b')](_0x37ef13);}return _0x3a42ad['save']();};}function saveUpdates(_0x14ea2e,_0x12a7bc){return function(_0x1aeda0){if(_0x1aeda0){return _0x1aeda0[_0x9193('0x2c')](_0x14ea2e)['then'](function(_0x5b2452){return _0x5b2452;});}return null;};}function removeEntity(_0xa744af,_0x1561d1){return function(_0x370243){if(_0x370243){return _0x370243[_0x9193('0x2d')]()[_0x9193('0x2e')](function(){_0xa744af['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x384837,_0x4f4986){return function(_0x2cb035){if(!_0x2cb035){_0x384837[_0x9193('0x23')](0x194);}return _0x2cb035;};}function handleError(_0x4c5fff,_0x512659){_0x512659=_0x512659||0x1f4;return function(_0x3b801c){logger[_0x9193('0x2f')](_0x3b801c[_0x9193('0x30')]);if(_0x3b801c[_0x9193('0x31')]){delete _0x3b801c[_0x9193('0x31')];}_0x4c5fff[_0x9193('0x24')](_0x512659)[_0x9193('0x32')](_0x3b801c);};}function getInteractionUsers(_0x19c3c0,_0x351291){return new BPromise(function(_0x30322d,_0x3df74d){try{if(_0x351291[_0x19c3c0['id']]){_0x19c3c0[_0x9193('0x33')]=_[_0x9193('0x34')](_0x351291[_0x19c3c0['id']],function(_0x51cb7c){return{'id':_0x51cb7c['id'],'fullname':_0x51cb7c['fullname']};});}}catch(_0x550652){_0x3df74d(_0x550652);}_0x30322d(_0x19c3c0);});}function getInteractionTags(_0x3771d7,_0x41de30){return new BPromise(function(_0x17f725,_0x26577b){try{if(_0x3771d7[_0x9193('0x35')]){_0x3771d7[_0x9193('0x36')]=[];_0x3771d7['TagIds'][_0x9193('0x37')](',')[_0x9193('0x38')](function(_0x48334d){_0x3771d7[_0x9193('0x36')][_0x9193('0x39')](_0x41de30[_0x48334d]);});}delete _0x3771d7[_0x9193('0x35')];}catch(_0x483d85){_0x26577b(_0x483d85);}_0x17f725(_0x3771d7);});}function getLastMessageText(_0x29604c){return new BPromise(function(_0x5e4cf9,_0x4f37c0){return db[_0x9193('0x3a')][_0x9193('0x3b')]({'where':{'id':_0x29604c['id']},'attributes':[_0x9193('0x3c'),'lastMsgText'],'raw':!![]})[_0x9193('0x2e')](function(_0xca6aa){if(!_0xca6aa[_0x9193('0x3d')]){_0x29604c[_0x9193('0x3d')]=_[_0x9193('0x3e')](htmlToText[_0x9193('0x3f')](_0xca6aa[_0x9193('0x3c')],{'preserveNewlines':!![],'singleNewLineParagraphs':!![],'uppercaseHeadings':![],'noLinkBrackets':!![],'ignoreImage':!![]}));}else{_0x29604c[_0x9193('0x3d')]=_0xca6aa[_0x9193('0x3d')];}_0x5e4cf9(_0x29604c);})[_0x9193('0x40')](function(_0x168258){_0x4f37c0(_0x168258);});});}function updateMailInteraction(_0x1d75b3,_0x411647,_0x5770f2,_0x23bc40){return new BPromise(function(_0x1d3def,_0x266c2b){return getInteractionUsers(_0x1d75b3,_0x5770f2)[_0x9193('0x2e')](function(_0x236444){return getInteractionTags(_0x236444,_0x411647);})[_0x9193('0x2e')](function(_0x4a8b57){if(_0x23bc40){_0x1d3def(getLastMessageText(_0x4a8b57));}else{_0x1d3def(_0x4a8b57);}})[_0x9193('0x40')](function(_0x17aeb9){_0x266c2b(_0x17aeb9);});});}exports[_0x9193('0x41')]=function(_0x35a6f7,_0x5595fe){var _0x43407b={},_0x2f5b32={},_0x218428={'count':0x0,'rows':[]};var _0x572aed=_[_0x9193('0x34')](db[_0x9193('0x3a')][_0x9193('0x42')],function(_0x42355f){return{'name':_0x42355f[_0x9193('0x43')],'type':_0x42355f['type']['key']};});_0x2f5b32['model']=_[_0x9193('0x34')](_0x572aed,_0x9193('0x31'));_0x2f5b32[_0x9193('0x44')]=_[_0x9193('0x45')](_0x35a6f7[_0x9193('0x44')]);_0x2f5b32[_0x9193('0x46')]=_['intersection'](_0x2f5b32['model'],_0x2f5b32[_0x9193('0x44')]);_0x43407b[_0x9193('0x47')]=_[_0x9193('0x48')](_0x2f5b32[_0x9193('0x49')],qs[_0x9193('0x4a')](_0x35a6f7[_0x9193('0x44')][_0x9193('0x4a')]));_0x43407b['attributes']=_0x43407b[_0x9193('0x47')][_0x9193('0x4b')]?_0x43407b[_0x9193('0x47')]:_0x2f5b32[_0x9193('0x49')];if(!_0x35a6f7[_0x9193('0x44')][_0x9193('0x4c')]('nolimit')){_0x43407b[_0x9193('0x4d')]=qs[_0x9193('0x4d')](_0x35a6f7[_0x9193('0x44')]['limit']);_0x43407b[_0x9193('0x27')]=qs['offset'](_0x35a6f7[_0x9193('0x44')][_0x9193('0x27')]);}_0x43407b[_0x9193('0x4e')]=qs[_0x9193('0x4f')](_0x35a6f7[_0x9193('0x44')]['sort']);_0x43407b[_0x9193('0x50')]=qs[_0x9193('0x46')](_[_0x9193('0x51')](_0x35a6f7[_0x9193('0x44')],_0x2f5b32[_0x9193('0x46')]),_0x572aed);var _0x4da113=[];var _0x43c8ff=squel['select']()[_0x9193('0x52')]('id')[_0x9193('0x52')](_0x9193('0x31'))['field'](_0x9193('0x53'))[_0x9193('0x54')](_0x9193('0x55'));var _0xcbeff2=squel[_0x9193('0x56')]()['field']('u.id')[_0x9193('0x52')](_0x9193('0x57'))[_0x9193('0x52')](_0x9193('0x58'))['from']('user_has_mail_interactions','ui')['left_join'](_0x9193('0x59'),'u',_0x9193('0x5a'));var _0x3d78ba=squel[_0x9193('0x56')]()[_0x9193('0x54')]('mail_interactions','i')[_0x9193('0x5b')](_0x9193('0x5c'),'c',_0x9193('0x5d'))[_0x9193('0x5b')](_0x9193('0x59'),'o',_0x9193('0x5e'))[_0x9193('0x5b')](_0x9193('0x5f'),'a',_0x9193('0x60'))[_0x9193('0x5b')]('mail_messages','me',_0x9193('0x61'))[_0x9193('0x5b')](_0x9193('0x62'),'it','it.MailInteractionId\x20=\x20i.id')['left_join'](_0x9193('0x55'),'t','t.id\x20=\x20it.TagId');var _0x4b16af=squel['expr']();var _0x30b611=[];var _0x4768ce=squel[_0x9193('0x63')]();var _0x1de72d;if(_0x35a6f7['query'][_0x9193('0x64')]){_0x1de72d=as[_0x9193('0x65')](_0x35a6f7[_0x9193('0x44')][_0x9193('0x64')]);var _0x372cdf=_0x1de72d[_0x9193('0x66')];for(var _0x593fc=0x0;_0x593fc<_0x1de72d['conditions'][_0x9193('0x4b')];_0x593fc++){var _0x4b3671=_0x1de72d[_0x9193('0x67')][_0x593fc];var _0x1252c3='i';var _0x245cd8=_[_0x9193('0x68')](_0x572aed,[_0x9193('0x31'),_0x4b3671[_0x9193('0x52')]]);if(!_0x245cd8){switch(_0x4b3671[_0x9193('0x52')]){case'unreadMessages':if(_0x4b3671[_0x9193('0x69')]==0x1){_0x3d78ba[_0x9193('0x6a')]('`'+_0x4b3671['field']+_0x9193('0x6b'));}else{_0x3d78ba[_0x9193('0x6a')]('`'+_0x4b3671[_0x9193('0x52')]+_0x9193('0x6c'));}break;case _0x9193('0x6d'):if(_0x4b3671[_0x9193('0x6e')]===_0x9193('0x6f')){if(_0x4b3671['value']['split']('\x20')[_0x9193('0x4b')]>0x1){_0x4b16af[_0x372cdf](_0x9193('0x70'),qs[_0x9193('0x71')](_0x4b3671['value']),null);}else{var _0x32053d='%'+_0x4b3671[_0x9193('0x69')]+'%';_0x4b16af[_0x372cdf](_0x9193('0x72'),_0x32053d,_0x32053d,_0x32053d);}}else{_0x245cd8=_['find'](_0x572aed,[_0x9193('0x31'),'ContactId']);_0x4b3671[_0x9193('0x52')]=_0x9193('0x73');_0x3f4a27=as[_0x9193('0x74')](_0x1252c3,_0x245cd8[_0x9193('0x75')],_0x4b3671);_0x4b16af[_0x372cdf](_0x3f4a27['text'],_0x3f4a27[_0x9193('0x69')][_0x9193('0x76')],_0x3f4a27['value'][_0x9193('0x77')]);}break;case'Tag':var _0x568b00=_0x4b3671['value'][_0x9193('0x37')](',')[_0x9193('0x34')](function(_0x46f061){return Number(_0x46f061);});_0x568b00[_0x9193('0x38')](function(_0x16ef65){_0x4768ce['or'](_0x9193('0x78'),'%,'+_0x16ef65+',%');});_0x30b611=_['union'](_0x30b611,_0x568b00);break;case'User':if(_0x4b3671[_0x9193('0x6e')]===_0x9193('0x6f')){_0x4b16af[_0x372cdf](_0x9193('0x79'),'%'+_0x4b3671[_0x9193('0x69')]+'%',null);}else{_0x245cd8=_[_0x9193('0x68')](_0x572aed,['name',_0x9193('0x7a')]);_0x4b3671[_0x9193('0x52')]='UserId';_0x3f4a27=as[_0x9193('0x74')](_0x1252c3,_0x245cd8['type'],_0x4b3671);_0x4b16af[_0x372cdf](_0x3f4a27['text'],_0x3f4a27[_0x9193('0x69')][_0x9193('0x76')],_0x3f4a27[_0x9193('0x69')]['end']);}break;case _0x9193('0x7b'):_0x3f4a27=as['buildExpression']('me',null,_0x4b3671);_0x4b16af[_0x372cdf](_0x3f4a27[_0x9193('0x7c')],_0x3f4a27[_0x9193('0x69')]['start'],_0x3f4a27[_0x9193('0x69')][_0x9193('0x77')]);break;}}else{var _0x3f4a27=as[_0x9193('0x74')](_0x1252c3,_0x245cd8[_0x9193('0x75')],_0x4b3671);_0x4b16af[_0x372cdf](_0x3f4a27[_0x9193('0x7c')],_0x3f4a27[_0x9193('0x69')][_0x9193('0x76')],_0x3f4a27['value'][_0x9193('0x77')]);}}}else{var _0x41edc7=_(_0x35a6f7[_0x9193('0x44')])[_0x9193('0x45')]()[_0x9193('0x34')](function(_0x4fba3e){return _[_0x9193('0x7d')](_0x572aed,[_0x9193('0x31'),_0x4fba3e])?_0x4fba3e:undefined;})['compact']()[_0x9193('0x69')]();if(!_['isEmpty'](_0x41edc7)){_0x41edc7['forEach'](function(_0x3a7a9b){if(_0x3a7a9b==='MailAccountId'){_0x3d78ba['where'](_0x9193('0x7e'),[][_0x9193('0x7f')](_0x35a6f7[_0x9193('0x44')][_0x3a7a9b]));}else if(_0x3a7a9b==='createdAt'){var _0x4735b0=JSON[_0x9193('0x80')](_0x35a6f7[_0x9193('0x44')][_0x3a7a9b])['$gte'];var _0x5bfdc0=JSON[_0x9193('0x80')](_0x35a6f7[_0x9193('0x44')][_0x3a7a9b])[_0x9193('0x81')];_0x3d78ba[_0x9193('0x50')](_0x9193('0x82'),_0x4735b0,_0x5bfdc0);}else{if(_0x35a6f7[_0x9193('0x44')][_0x3a7a9b]==='null'){_0x3d78ba[_0x9193('0x50')]('i.'+_0x3a7a9b+_0x9193('0x83'));}else{_0x3d78ba['where']('i.'+_0x3a7a9b+_0x9193('0x84'),_0x35a6f7['query'][_0x3a7a9b]);}}});}if(_0x35a6f7[_0x9193('0x44')][_0x9193('0x85')]){if(_0x35a6f7['query']['read']==0x1){_0x3d78ba[_0x9193('0x6a')]('`unreadMessages`\x20=\x200');}else{_0x3d78ba[_0x9193('0x6a')](_0x9193('0x86'));}}if(_0x35a6f7[_0x9193('0x44')][_0x9193('0x87')]){_0x30b611=_[_0x9193('0x88')](_0x35a6f7['query'][_0x9193('0x87')])?_0x35a6f7[_0x9193('0x44')][_0x9193('0x87')]:new Array(_0x35a6f7[_0x9193('0x44')][_0x9193('0x87')]);_0x30b611['forEach'](function(_0x5da183){_0x4768ce['or'](_0x9193('0x78'),'%,'+_0x5da183+',%');});}if(_0x35a6f7['query'][_0x9193('0x89')]){var _0x401ffd=_0x35a6f7['query'][_0x9193('0x89')][_0x9193('0x8a')]('\x5c','\x5c\x5c')[_0x9193('0x8a')](/'/g,'\x27\x27');if(qs['isNumeric'](_0x401ffd)){_0x4b16af['or']('i.id\x20LIKE\x20?',_0x401ffd+'%');}else if(qs['isEmail'](_0x401ffd)){_0x4b16af['or']('c.email\x20LIKE\x20?',_0x401ffd+'%');}else{_0x4b16af['or'](_0x9193('0x8b'),qs['getFullTextValue'](_0x401ffd))['or'](_0x9193('0x8c'),qs[_0x9193('0x71')](_0x401ffd));}}}_0x3d78ba[_0x9193('0x50')](_0x4b16af);_0x3d78ba[_0x9193('0x8d')](_0x9193('0x8e'));var _0x4e6512={'type':db[_0x9193('0x8f')][_0x9193('0x90')][_0x9193('0x91')],'raw':!![]};var _0x2350a9=_0x3d78ba[_0x9193('0x92')]();_0x2350a9[_0x9193('0x52')](_0x9193('0x8e'));_0x2350a9[_0x9193('0x52')](_0x9193('0x93'),_0x9193('0x94'));if(_0x43407b[_0x9193('0x4e')]){_0x43407b['order'][_0x9193('0x38')](function(_0x11cadb){var _0x36365a=_0x11cadb[0x0]==='contactName'?_0x11cadb[0x0]:'i.'+_0x11cadb[0x0];_0x3d78ba[_0x9193('0x4e')](_0x36365a,_0x11cadb[0x1]===_0x9193('0x95')?![]:!![]);});}if(!_[_0x9193('0x96')](_0x30b611)){_0x3d78ba[_0x9193('0x6a')](_0x4768ce);_0x2350a9[_0x9193('0x50')](_0x9193('0x97'),_0x30b611);}BPromise[_0x9193('0x98')]()[_0x9193('0x2e')](function(){if(!_0x1de72d){if(_0x35a6f7[_0x9193('0x44')]['MailAccountId'])return;_0x2350a9[_0x9193('0x50')]('i.MailAccountId\x20IS\x20NOT\x20NULL');_0x3d78ba[_0x9193('0x50')](_0x9193('0x99'));return;}if(_0x35a6f7['user'][_0x9193('0x9a')]!==_0x9193('0x9b'))return;return _0x35a6f7[_0x9193('0x9c')][_0x9193('0x9d')]({'attributes':['id'],'raw':!![]})['then'](function(_0x2f7f1d){if(_['isEmpty'](_0x2f7f1d)){_0x2350a9['where'](_0x9193('0x9e'));_0x3d78ba[_0x9193('0x50')](_0x9193('0x9e'));}else{_0x2350a9[_0x9193('0x50')](_0x9193('0x7e'),_['map'](_0x2f7f1d,'id'));_0x3d78ba[_0x9193('0x50')](_0x9193('0x7e'),_[_0x9193('0x34')](_0x2f7f1d,'id'));}});})['then'](function(){if(_0x35a6f7[_0x9193('0x9c')]['role']===_0x9193('0x9b')&&!_0x1de72d&&!_0x35a6f7[_0x9193('0x44')][_0x9193('0x9f')])return[];return db[_0x9193('0xa0')]['query'](_0x2350a9[_0x9193('0xa1')](),_0x4e6512);})[_0x9193('0x2e')](function(_0x5bfdd7){_0x218428[_0x9193('0x26')]=_0x5bfdd7[_0x9193('0x4b')];if(_0x218428['count']===0x0)return[];return db['sequelize'][_0x9193('0x44')](_0x43c8ff[_0x9193('0xa1')](),_0x4e6512)[_0x9193('0x2e')](function(_0x5cef12){_0x4da113=_[_0x9193('0xa2')](_0x5cef12,'id');_0x4e6512=_['merge'](_0x4e6512,{'model':db[_0x9193('0x3a')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x35a6f7['query'][_0x9193('0x4a')]){_0x43407b['attributes'][_0x9193('0x38')](function(_0x19dcee){_0x3d78ba[_0x9193('0x52')]('i.'+_0x19dcee);});}else{_0x3d78ba[_0x9193('0x52')](_0x9193('0x93'),'unreadMessages');_0x3d78ba[_0x9193('0x52')](_0x9193('0xa3'),_0x9193('0xa4'));_0x3d78ba[_0x9193('0x52')]('a.mandatoryDisposition',_0x9193('0xa5'));_0x3d78ba['field'](_0x9193('0xa6'),_0x9193('0xa7'));_0x3d78ba[_0x9193('0x52')](_0x9193('0x8e'));_0x3d78ba[_0x9193('0x52')](_0x9193('0xa8'));_0x3d78ba[_0x9193('0x52')](_0x9193('0xa9'));_0x3d78ba[_0x9193('0x52')]('i.closed');_0x3d78ba[_0x9193('0x52')](_0x9193('0xaa'));_0x3d78ba['field'](_0x9193('0xab'));_0x3d78ba['field'](_0x9193('0xac'));_0x3d78ba['field'](_0x9193('0xad'));_0x3d78ba[_0x9193('0x52')](_0x9193('0xae'));_0x3d78ba[_0x9193('0x52')](_0x9193('0xaf'));_0x3d78ba[_0x9193('0x52')](_0x9193('0xb0'));_0x3d78ba[_0x9193('0x52')]('i.thirdDisposition');_0x3d78ba[_0x9193('0x52')](_0x9193('0xb1'));_0x3d78ba[_0x9193('0x52')](_0x9193('0xb2'));_0x3d78ba[_0x9193('0x52')](_0x9193('0xb3'));_0x3d78ba[_0x9193('0x52')]('i.MailAccountId');_0x3d78ba[_0x9193('0x52')]('i.UserId');_0x3d78ba[_0x9193('0x52')](_0x9193('0xb4'),'Contact.firstName');_0x3d78ba[_0x9193('0x52')]('c.lastName','Contact.lastName');_0x3d78ba[_0x9193('0x52')](_0x9193('0xb5'),_0x9193('0xb6'));_0x3d78ba['field'](_0x9193('0xb7'),_0x9193('0xb8'));_0x3d78ba['field'](_0x9193('0xb9'),'Contact.mobile');_0x3d78ba[_0x9193('0x52')](_0x9193('0xba'),_0x9193('0xbb'));_0x3d78ba[_0x9193('0x52')]('o.fullname',_0x9193('0xbc'));_0x3d78ba[_0x9193('0x52')](_0x9193('0xbd'),'Owner.internal');_0x3d78ba[_0x9193('0x52')](_0x9193('0xbe'),_0x9193('0x35'));}if(_0x43407b[_0x9193('0x4d')])_0x3d78ba['limit'](_0x43407b[_0x9193('0x4d')]);if(_0x43407b['offset'])_0x3d78ba[_0x9193('0x27')](_0x43407b[_0x9193('0x27')]);return db[_0x9193('0xa0')]['query'](_0x3d78ba[_0x9193('0xa1')](),_0x4e6512);})['then'](function(_0x59fef4){_0xcbeff2[_0x9193('0x50')](_0x9193('0xbf'),_[_0x9193('0x34')](_0x59fef4,'id'));return db[_0x9193('0xa0')][_0x9193('0x44')](_0xcbeff2['toString'](),_0x4e6512)[_0x9193('0x2e')](function(_0x38b5cd){var _0x23235d=_[_0x9193('0xc0')](_0x38b5cd,_0x9193('0xc1'));var _0x47efb3=[];return db['Setting'][_0x9193('0x3b')]({'attributes':[_0x9193('0xc2')],'raw':!![]})[_0x9193('0x2e')](function(_0x2aa887){var _0x45925b=_0x2aa887[_0x9193('0xc2')];_0x59fef4['forEach'](function(_0x22700c){_0x47efb3[_0x9193('0x39')](updateMailInteraction(_0x22700c,_0x4da113,_0x23235d,_0x45925b));});return BPromise[_0x9193('0xc3')](_0x47efb3);});});});})[_0x9193('0x2e')](function(_0x344459){_0x218428['rows']=_0x344459;return _0x218428;})[_0x9193('0x2e')](respondWithFilteredResult(_0x5595fe,_0x43407b))[_0x9193('0x40')](handleError(_0x5595fe,null));};exports[_0x9193('0xc4')]=function(_0x24dd89,_0x3f1156){var _0x586c63={'raw':![],'where':{'id':_0x24dd89[_0x9193('0xc5')]['id']}},_0x5a6302={};_0x5a6302[_0x9193('0x49')]=_['keys'](db[_0x9193('0x3a')][_0x9193('0x42')]);_0x5a6302['query']=_[_0x9193('0x45')](_0x24dd89['query']);_0x5a6302[_0x9193('0x46')]=_[_0x9193('0x48')](_0x5a6302['model'],_0x5a6302[_0x9193('0x44')]);_0x586c63[_0x9193('0x47')]=_['intersection'](_0x5a6302[_0x9193('0x49')],qs[_0x9193('0x4a')](_0x24dd89['query'][_0x9193('0x4a')]));_0x586c63[_0x9193('0x47')]=_0x586c63[_0x9193('0x47')][_0x9193('0x4b')]?_0x586c63[_0x9193('0x47')]:_0x5a6302[_0x9193('0x49')];if(_0x24dd89[_0x9193('0x44')][_0x9193('0xc6')]){_0x586c63[_0x9193('0xc7')]=[{'all':!![]}];}_0x586c63=_[_0x9193('0xc8')]({},_0x586c63,_0x24dd89[_0x9193('0xc9')]);return db[_0x9193('0x3a')][_0x9193('0x68')](_0x586c63)[_0x9193('0x2e')](handleEntityNotFound(_0x3f1156,null))[_0x9193('0x2e')](respondWithResult(_0x3f1156,null))[_0x9193('0x40')](handleError(_0x3f1156,null));};exports[_0x9193('0xca')]=function(_0x1c2f2d,_0x8f60b5){return db[_0x9193('0x3a')][_0x9193('0xca')](_0x1c2f2d[_0x9193('0xcb')],{})[_0x9193('0x2e')](respondWithResult(_0x8f60b5,0xc9))[_0x9193('0x40')](handleError(_0x8f60b5,null));};exports[_0x9193('0x2c')]=function(_0x1d6e14,_0x39b9d7){if(_0x1d6e14[_0x9193('0xcb')]['id']){delete _0x1d6e14[_0x9193('0xcb')]['id'];}return db[_0x9193('0x3a')][_0x9193('0x68')]({'where':{'id':_0x1d6e14[_0x9193('0xc5')]['id']}})['then'](handleEntityNotFound(_0x39b9d7,null))['then'](saveUpdates(_0x1d6e14['body'],null))[_0x9193('0x2e')](respondWithResult(_0x39b9d7,null))['catch'](handleError(_0x39b9d7,null));};exports[_0x9193('0x2d')]=function(_0x294740,_0x2fda2c){return db[_0x9193('0x3a')][_0x9193('0x68')]({'where':{'id':_0x294740['params']['id']}})[_0x9193('0x2e')](handleEntityNotFound(_0x2fda2c,null))[_0x9193('0x2e')](removeEntity(_0x2fda2c,null))[_0x9193('0x40')](handleError(_0x2fda2c,null));};exports[_0x9193('0xcc')]=function(_0x1d11af,_0xfc9b62){return db[_0x9193('0x3a')][_0x9193('0xcc')]()[_0x9193('0x2e')](respondWithResult(_0xfc9b62,null))[_0x9193('0x40')](handleError(_0xfc9b62,null));};exports[_0x9193('0xcd')]=function(_0x267742,_0x358561,_0x501c45){return db['MailMessage']['find']({'where':{'id':_0x267742[_0x9193('0xc5')]['id']}})[_0x9193('0x2e')](handleEntityNotFound(_0x358561,null))[_0x9193('0x2e')](function(_0x49d238){if(_0x49d238){return _0x49d238['addMessage'](_0x267742[_0x9193('0xcb')]['ids'],_[_0x9193('0xce')](_0x267742[_0x9193('0xcb')],[_0x9193('0xcf'),'id'])||{});}})[_0x9193('0x2e')](respondWithResult(_0x358561,null))[_0x9193('0x40')](handleError(_0x358561,null));};exports[_0x9193('0xd0')]=function(_0x5cbf7b,_0x2a4267,_0x4a3544){var _0xacfe45={'raw':![],'where':{}};var _0xb50d52={};var _0x5f43e={'count':0x0,'rows':[]};return db[_0x9193('0x3a')]['findOne']({'where':{'id':_0x5cbf7b[_0x9193('0xc5')]['id']}})[_0x9193('0x2e')](handleEntityNotFound(_0x2a4267,null))[_0x9193('0x2e')](function(_0x13152e){if(_0x13152e){_0xb50d52[_0x9193('0x49')]=_['keys'](db[_0x9193('0xd1')]['rawAttributes']);_0xb50d52[_0x9193('0x44')]=_[_0x9193('0x45')](_0x5cbf7b[_0x9193('0x44')]);_0xb50d52[_0x9193('0x46')]=_[_0x9193('0x48')](_0xb50d52[_0x9193('0x49')],_0xb50d52[_0x9193('0x44')]);_0xacfe45['attributes']=_[_0x9193('0x48')](_0xb50d52[_0x9193('0x49')],qs['fields'](_0x5cbf7b[_0x9193('0x44')]['fields']));_0xacfe45[_0x9193('0x47')]=_0xacfe45[_0x9193('0x47')][_0x9193('0x4b')]?_0xacfe45['attributes']:_0xb50d52[_0x9193('0x49')];if(!_0x5cbf7b[_0x9193('0x44')][_0x9193('0x4c')](_0x9193('0xd2'))){_0xacfe45[_0x9193('0x4d')]=qs[_0x9193('0x4d')](_0x5cbf7b[_0x9193('0x44')][_0x9193('0x4d')]);_0xacfe45[_0x9193('0x27')]=qs[_0x9193('0x27')](_0x5cbf7b[_0x9193('0x44')][_0x9193('0x27')]);}_0xacfe45[_0x9193('0x4e')]=qs['sort'](_0x5cbf7b[_0x9193('0x44')][_0x9193('0x4f')]);_0xacfe45[_0x9193('0x50')]=qs[_0x9193('0x46')](_[_0x9193('0x51')](_0x5cbf7b[_0x9193('0x44')],_0xb50d52['filters']));_0xacfe45['where']['MailInteractionId']=_0x13152e['id'];if(_0x5cbf7b[_0x9193('0x44')]['filter']){_0xacfe45[_0x9193('0x50')]=_[_0x9193('0xc8')](_0xacfe45['where'],{'$or':_['map'](_0xacfe45[_0x9193('0x47')],function(_0x490529){var _0x4223f4={};_0x4223f4[_0x490529]={'$like':'%'+_0x5cbf7b['query'][_0x9193('0x89')]+'%'};return _0x4223f4;})});}if(_0x5cbf7b[_0x9193('0x44')][_0x9193('0xd3')]){var _0x7883c0=_0x5cbf7b[_0x9193('0x44')][_0x9193('0xd3')][_0x9193('0x37')](',');var _0x1a1847={};_0x1a1847[_0x7883c0[0x0]]={'$gte':moment(_0x7883c0[0x1])['format'](_0x9193('0xd4'))};_0xacfe45['where']=_[_0x9193('0xc8')](_0xacfe45[_0x9193('0x50')],_0x1a1847);}_0xacfe45=_[_0x9193('0xc8')]({},_0xacfe45,_0x5cbf7b[_0x9193('0xc9')]);return db[_0x9193('0xd1')][_0x9193('0x26')]({'where':_0xacfe45['where']})['then'](function(_0x241810){_0x5f43e[_0x9193('0x26')]=_0x241810;if(_0x5cbf7b[_0x9193('0x44')][_0x9193('0xc6')]){_0xacfe45['include']=[{'all':!![]}];}return db['MailMessage'][_0x9193('0xd5')](_0xacfe45);})[_0x9193('0x2e')](function(_0x5343f4){_0x5f43e['rows']=_0x5343f4;return _0x5f43e;});}})[_0x9193('0x2e')](respondWithFilteredResult(_0x2a4267,_0xacfe45))['catch'](handleError(_0x2a4267,null));};exports['addTags']=function(_0x538aad,_0x575771,_0x397e75){return db[_0x9193('0x3a')][_0x9193('0x68')]({'where':{'id':_0x538aad['params']['id']}})['then'](handleEntityNotFound(_0x575771,null))[_0x9193('0x2e')](function(_0x591cde){if(_0x591cde){return _0x591cde[_0x9193('0xd6')](_0x538aad[_0x9193('0xcb')]['ids'],_['omit'](_0x538aad['body'],['ids','id'])||{})['spread'](function(){return db[_0x9193('0xd7')][_0x9193('0xd5')]({'attributes':['id',_0x9193('0x31'),'color'],'where':{'id':_0x538aad[_0x9193('0xcb')]['ids']}});})[_0x9193('0x2e')](function(_0x47158f){socket[_0x9193('0xd8')](_0x9193('0xd9'),{'id':Number(_0x538aad[_0x9193('0xc5')]['id']),'tags':_0x47158f||[]});return{'id':Number(_0x538aad[_0x9193('0xc5')]['id']),'tags':_0x47158f||[]};});}})[_0x9193('0x2e')](respondWithResult(_0x575771,null))[_0x9193('0x40')](handleError(_0x575771,null));};exports[_0x9193('0xda')]=function(_0x4f05de,_0x34632c,_0x2c76d7){return db[_0x9193('0x3a')][_0x9193('0x68')]({'where':{'id':_0x4f05de[_0x9193('0xc5')]['id']}})[_0x9193('0x2e')](handleEntityNotFound(_0x34632c,null))[_0x9193('0x2e')](function(_0x2fe21a){if(_0x2fe21a){return _0x2fe21a[_0x9193('0xda')](_0x4f05de[_0x9193('0x44')][_0x9193('0xcf')]);}})[_0x9193('0x2e')](respondWithStatusCode(_0x34632c,null))[_0x9193('0x40')](handleError(_0x34632c,null));};exports[_0x9193('0xdb')]=function(_0x5a6414,_0x31ba24){var _0x3a1c86=moment()[_0x9193('0xdc')]()[_0x9193('0xa1')]();var _0x52bda0=path[_0x9193('0xdd')](config[_0x9193('0xde')],_0x9193('0xdf'),_0x9193('0xe0'),_0x9193('0xe1'));var _0x116485=path[_0x9193('0xdd')](config[_0x9193('0xde')],_0x9193('0xdf'),'files','attachments');var _0x2aa1f6=path['join'](_0x52bda0,_0x3a1c86);var _0x4b79a4=util[_0x9193('0xe2')](_0x9193('0xe3'),_0x5a6414[_0x9193('0xc5')]['id'],_0x3a1c86);var _0x35c22e=path[_0x9193('0xdd')](_0x52bda0,_0x4b79a4);var _0x7b5257=[];if(_0x5a6414['query'][_0x9193('0xe4')]){_0x7b5257[_0x9193('0x39')]({'model':db[_0x9193('0xe5')],'as':_0x9193('0xe6'),'raw':!![]});}var _0x2b18e4=[{'model':db['MailMessage'],'as':_0x9193('0xe7'),'attributes':['id',_0x9193('0xcb'),_0x9193('0x54'),'to','cc',_0x9193('0xe8'),_0x9193('0xe9'),_0x9193('0xea')],'where':{'secret':![]},'order':qs['sort']('id'),'include':_0x7b5257}];return db[_0x9193('0x3a')][_0x9193('0x68')]({'where':{'id':_0x5a6414[_0x9193('0xc5')]['id']},'include':_0x2b18e4})[_0x9193('0x2e')](handleEntityNotFound(_0x31ba24,null))[_0x9193('0x2e')](function(_0x58f5c0){if(_0x58f5c0&&_0x58f5c0[_0x9193('0xe7')]){var _0x11e20b=_0x58f5c0[_0x9193('0xeb')]({'plain':!![]});fs[_0x9193('0xec')](_0x2aa1f6);return BPromise[_0x9193('0xed')](_0x11e20b[_0x9193('0xe7')],function(_0x20ec33,_0x3ddfcd){var _0xc79472={'from':_0x20ec33[_0x9193('0x54')],'to':_0x20ec33['to'],'subject':_0x20ec33[_0x9193('0xe9')],'html':_0x20ec33[_0x9193('0xcb')],'headers':{'Date':moment(_0x20ec33[_0x9193('0xea')])[_0x9193('0xe2')]('ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ')},'attachments':[]};if(_0x20ec33['cc']){_0xc79472[_0x9193('0xee')]['Cc']=_0x20ec33['cc'];}if(_0x20ec33['bcc']){_0xc79472['headers'][_0x9193('0xef')]=_0x20ec33[_0x9193('0xe8')];}return new BPromise(function(_0x357ac6,_0x3f4288){if(_0x20ec33['Attachments']){for(var _0x1e913d=0x0;_0x1e913d<_0x20ec33[_0x9193('0xe6')][_0x9193('0x4b')];_0x1e913d++){var _0x25fd9b=_0x20ec33[_0x9193('0xe6')][_0x1e913d];var _0x105b54=path[_0x9193('0xdd')](_0x116485,_0x25fd9b[_0x9193('0xf0')]);if(fs[_0x9193('0xf1')](_0x105b54)){_0xc79472[_0x9193('0xe4')]['push']({'name':_0x25fd9b[_0x9193('0x31')],'contentType':_0x25fd9b[_0x9193('0x75')],'data':fs[_0x9193('0xf2')](_0x105b54)});}}}emlformat[_0x9193('0xf3')](_0xc79472,function(_0x552726,_0x3b5ac9){if(_0x552726)return _0x3f4288(_0x552726);fs[_0x9193('0xf4')](path['join'](_0x2aa1f6,util[_0x9193('0xe2')](_0x9193('0xf5'),_0x3ddfcd)),_0x3b5ac9);return _0x357ac6(_0x3b5ac9);});});})[_0x9193('0x2e')](function(){return new BPromise(function(_0x2d7c82,_0x5d7fa7){zipdir(_0x2aa1f6,{'saveTo':_0x35c22e},function(_0xeba3c9,_0x349fec){if(_0xeba3c9)return _0x5d7fa7(_0xeba3c9);return _0x2d7c82(_0x349fec);});})[_0x9193('0x2e')](function(){return new BPromise(function(_0x592ca9,_0x5cfa76){rimraf(_0x2aa1f6,function(_0x46097c){if(_0x46097c)_0x5cfa76(_0x46097c);return _0x592ca9();});});})[_0x9193('0x2e')](function(){return _0x31ba24[_0x9193('0xdb')](_0x35c22e,_0x4b79a4,function(_0x558709){if(_0x558709){console[_0x9193('0xf6')]('err',_0x558709);}else{fs['unlinkSync'](_0x35c22e);}});});});}else{return _0x31ba24['sendStatus'](0xc8);}})[_0x9193('0x40')](handleError(_0x31ba24,null));};
\ No newline at end of file
+var _0x84a0=['replace','isEmail','c.email\x20LIKE\x20?','MATCH\x20(i.to,\x20i.subject)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','getFullTextValue','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)','contactName','isEmpty','t.id\x20IN\x20?','MailAccountId','i.MailAccountId\x20IS\x20NOT\x20NULL','user','role','agent','getMailAccounts','i.MailAccountId\x20IS\x20NULL','sequelize','toString','merge','a.key','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.closed','i.closedAt','i.attach','i.lastMsgDirection','i.subject','i.disposition','i.thirdDisposition','i.to','i.ContactId','i.UserId','c.firstName','Contact.firstName','c.email','Contact.phone','c.mobile','Contact.mobile','c.fax','o.fullname','Owner.fullname','o.internal','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','ui.MailInteractionId\x20IN\x20?','groupBy','MailInteractionId','enableEmailPreview','all','rows','includeAll','include','options','create','body','params','describe','addMessage','MailMessage','ids','getMessages','hasOwnProperty','nolimit','format','findAll','inlineCss','true','addTags','setTags','omit','spread','emit','mailInteractionTags:save','removeTags','download','server','files','tmp','join','root','attachments','transcript-%d-%s.zip','bcc','subject','Messages','mkdirSync','ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ','headers','Bcc','Attachments','basename','existsSync','readFileSync','build','writeFileSync','unlinkSync','html-pdf','eml-format','rimraf','zip-dir','request-promise','moment','util','path','to-csv','ejs','lodash','squel','crypto','desk.js','querystring','papaparse','html-to-text','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./mailInteraction.socket','sendStatus','status','count','offset','limit','set','Content-Range','json','apply','reject','save','update','then','destroy','end','name','send','Users','fullname','TagIds','Tags','split','forEach','push','MailInteraction','findOne','lastMsgBody','lastMsgText','trimStart','fromString','catch','index','map','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','length','order','sort','pick','select','field','from','tools_tags','u.id','ui.MailInteractionId','user_has_mail_interactions','users','u.id\x20=\x20ui.UserId','mail_interactions','left_join','cm_contacts','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','o.id\x20=\x20i.UserId','mail_accounts','a.id\x20=\x20i.MailAccountId','mail_messages','me.MailInteractionId\x20=\x20i.id','mail_interaction_has_tags','it.MailInteractionId\x20=\x20i.id','expr','parseSearch','search','unreadMessages','value','having','`\x20>\x200','operator','$substring','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','ContactId','text','start','Tag','union','User','find','UserId','buildExpression','plainBody','some','compact','where','i.MailAccountId\x20IN\x20?','concat','createdAt','parse','$gte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20IS\x20NULL','read','`unreadMessages`\x20=\x200','`unreadMessages`\x20>\x200','tag','isArray','filter'];(function(_0x1da527,_0x2dc953){var _0x40fc7c=function(_0x9949f5){while(--_0x9949f5){_0x1da527['push'](_0x1da527['shift']());}};_0x40fc7c(++_0x2dc953);}(_0x84a0,0x66));var _0x084a=function(_0x2098c8,_0x261100){_0x2098c8=_0x2098c8-0x0;var _0x32a7ae=_0x84a0[_0x2098c8];return _0x32a7ae;};'use strict';var pdf=require(_0x084a('0x0'));var emlformat=require(_0x084a('0x1'));var rimraf=require(_0x084a('0x2'));var zipdir=require(_0x084a('0x3'));var jsonpatch=require('fast-json-patch');var rp=require(_0x084a('0x4'));var moment=require(_0x084a('0x5'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0x084a('0x6'));var path=require(_0x084a('0x7'));var sox=require('sox');var csv=require(_0x084a('0x8'));var ejs=require(_0x084a('0x9'));var fs=require('fs');var _=require(_0x084a('0xa'));var squel=require(_0x084a('0xb'));var crypto=require(_0x084a('0xc'));var jsforce=require('jsforce');var deskjs=require(_0x084a('0xd'));var toCsv=require(_0x084a('0x8'));var querystring=require(_0x084a('0xe'));var Papa=require(_0x084a('0xf'));var htmlToText=require(_0x084a('0x10'));var juice=require('juice');var Redis=require('ioredis');var authService=require(_0x084a('0x11'));var qs=require(_0x084a('0x12'));var as=require(_0x084a('0x13'));var hardwareService=require(_0x084a('0x14'));var logger=require(_0x084a('0x15'))('api');var utils=require('../../config/utils');var config=require(_0x084a('0x16'));var licenseUtil=require(_0x084a('0x17'));var db=require(_0x084a('0x18'))['db'];config[_0x084a('0x19')]=_[_0x084a('0x1a')](config[_0x084a('0x19')],{'host':_0x084a('0x1b'),'port':0x18eb});var socket=require(_0x084a('0x1c'))(new Redis(config['redis']));require(_0x084a('0x1d'))['register'](socket);function respondWithStatusCode(_0x225de0,_0x3ccaca){_0x3ccaca=_0x3ccaca||0xcc;return function(_0x366624){if(_0x366624){return _0x225de0[_0x084a('0x1e')](_0x3ccaca);}return _0x225de0[_0x084a('0x1f')](_0x3ccaca)['end']();};}function respondWithResult(_0x443ebb,_0x4abd81){_0x4abd81=_0x4abd81||0xc8;return function(_0x6799af){if(_0x6799af){return _0x443ebb[_0x084a('0x1f')](_0x4abd81)['json'](_0x6799af);}};}function respondWithFilteredResult(_0xf2c333,_0x32c729){return function(_0x4134b9){if(_0x4134b9){var _0x14bb19=_0x4134b9[_0x084a('0x20')],_0x33d3a6=_0x32c729[_0x084a('0x21')],_0x145636=_0x32c729[_0x084a('0x21')]+_0x32c729[_0x084a('0x22')],_0x447a19;if(_0x145636>=_0x14bb19){_0x145636=_0x14bb19;_0x447a19=0xc8;}else{_0x447a19=0xce;}_0xf2c333[_0x084a('0x1f')](_0x447a19);return _0xf2c333[_0x084a('0x23')](_0x084a('0x24'),_0x33d3a6+'-'+_0x145636+'/'+_0x14bb19)[_0x084a('0x25')](_0x4134b9);}return null;};}function patchUpdates(_0x506f71){return function(_0x343c5c){try{jsonpatch[_0x084a('0x26')](_0x343c5c,_0x506f71,!![]);}catch(_0x41a90f){return BPromise[_0x084a('0x27')](_0x41a90f);}return _0x343c5c[_0x084a('0x28')]();};}function saveUpdates(_0x4865c8,_0x755c24){return function(_0x288e9e){if(_0x288e9e){return _0x288e9e[_0x084a('0x29')](_0x4865c8)[_0x084a('0x2a')](function(_0x18b43d){return _0x18b43d;});}return null;};}function removeEntity(_0x3cdc1e,_0x5be167){return function(_0x297e5b){if(_0x297e5b){return _0x297e5b[_0x084a('0x2b')]()[_0x084a('0x2a')](function(){_0x3cdc1e['status'](0xcc)[_0x084a('0x2c')]();});}};}function handleEntityNotFound(_0x3dd8b9,_0xfc9b8c){return function(_0x4c5658){if(!_0x4c5658){_0x3dd8b9['sendStatus'](0x194);}return _0x4c5658;};}function handleError(_0x4874fe,_0x52227a){_0x52227a=_0x52227a||0x1f4;return function(_0x33b88f){logger['error'](_0x33b88f['stack']);if(_0x33b88f['name']){delete _0x33b88f[_0x084a('0x2d')];}_0x4874fe[_0x084a('0x1f')](_0x52227a)[_0x084a('0x2e')](_0x33b88f);};}function getInteractionUsers(_0x2c4149,_0x3be7a6){return new BPromise(function(_0x25a2a1,_0x378de6){try{if(_0x3be7a6[_0x2c4149['id']]){_0x2c4149[_0x084a('0x2f')]=_['map'](_0x3be7a6[_0x2c4149['id']],function(_0x2ed3cd){return{'id':_0x2ed3cd['id'],'fullname':_0x2ed3cd[_0x084a('0x30')]};});}}catch(_0x501a16){_0x378de6(_0x501a16);}_0x25a2a1(_0x2c4149);});}function getInteractionTags(_0xe1980b,_0x24bcf5){return new BPromise(function(_0x225000,_0x19937c){try{if(_0xe1980b[_0x084a('0x31')]){_0xe1980b[_0x084a('0x32')]=[];_0xe1980b[_0x084a('0x31')][_0x084a('0x33')](',')[_0x084a('0x34')](function(_0x2f59a6){_0xe1980b[_0x084a('0x32')][_0x084a('0x35')](_0x24bcf5[_0x2f59a6]);});}delete _0xe1980b[_0x084a('0x31')];}catch(_0x49c9db){_0x19937c(_0x49c9db);}_0x225000(_0xe1980b);});}function getLastMessageText(_0x54ff9b){return new BPromise(function(_0x1ecc73,_0x282fcc){return db[_0x084a('0x36')][_0x084a('0x37')]({'where':{'id':_0x54ff9b['id']},'attributes':[_0x084a('0x38'),'lastMsgText'],'raw':!![]})[_0x084a('0x2a')](function(_0x1b56ad){if(!_0x1b56ad[_0x084a('0x39')]){_0x54ff9b['lastMsgText']=_[_0x084a('0x3a')](htmlToText[_0x084a('0x3b')](_0x1b56ad[_0x084a('0x38')],{'preserveNewlines':!![],'singleNewLineParagraphs':!![],'uppercaseHeadings':![],'noLinkBrackets':!![],'ignoreImage':!![]}));}else{_0x54ff9b['lastMsgText']=_0x1b56ad['lastMsgText'];}_0x1ecc73(_0x54ff9b);})['catch'](function(_0xf97d1b){_0x282fcc(_0xf97d1b);});});}function updateMailInteraction(_0x2e1806,_0x1444ed,_0x4e594f,_0x3c09c3){return new BPromise(function(_0x27e5bd,_0x3f9533){return getInteractionUsers(_0x2e1806,_0x4e594f)[_0x084a('0x2a')](function(_0x28a0a5){return getInteractionTags(_0x28a0a5,_0x1444ed);})[_0x084a('0x2a')](function(_0x175c64){if(_0x3c09c3){_0x27e5bd(getLastMessageText(_0x175c64));}else{_0x27e5bd(_0x175c64);}})[_0x084a('0x3c')](function(_0x434a06){_0x3f9533(_0x434a06);});});}exports[_0x084a('0x3d')]=function(_0x866960,_0x1454a9){var _0x284cdc={},_0x1659d3={},_0x10983f={'count':0x0,'rows':[]};var _0x597d87=_[_0x084a('0x3e')](db[_0x084a('0x36')][_0x084a('0x3f')],function(_0x37f630){return{'name':_0x37f630[_0x084a('0x40')],'type':_0x37f630[_0x084a('0x41')][_0x084a('0x42')]};});_0x1659d3[_0x084a('0x43')]=_[_0x084a('0x3e')](_0x597d87,'name');_0x1659d3[_0x084a('0x44')]=_[_0x084a('0x45')](_0x866960[_0x084a('0x44')]);_0x1659d3[_0x084a('0x46')]=_[_0x084a('0x47')](_0x1659d3[_0x084a('0x43')],_0x1659d3['query']);_0x284cdc[_0x084a('0x48')]=_[_0x084a('0x47')](_0x1659d3['model'],qs[_0x084a('0x49')](_0x866960[_0x084a('0x44')][_0x084a('0x49')]));_0x284cdc['attributes']=_0x284cdc[_0x084a('0x48')][_0x084a('0x4a')]?_0x284cdc['attributes']:_0x1659d3[_0x084a('0x43')];if(!_0x866960[_0x084a('0x44')]['hasOwnProperty']('nolimit')){_0x284cdc[_0x084a('0x22')]=qs[_0x084a('0x22')](_0x866960[_0x084a('0x44')][_0x084a('0x22')]);_0x284cdc[_0x084a('0x21')]=qs[_0x084a('0x21')](_0x866960[_0x084a('0x44')][_0x084a('0x21')]);}_0x284cdc[_0x084a('0x4b')]=qs[_0x084a('0x4c')](_0x866960[_0x084a('0x44')]['sort']);_0x284cdc['where']=qs[_0x084a('0x46')](_[_0x084a('0x4d')](_0x866960[_0x084a('0x44')],_0x1659d3['filters']),_0x597d87);var _0x33b067=[];var _0x1598c4=squel[_0x084a('0x4e')]()[_0x084a('0x4f')]('id')[_0x084a('0x4f')]('name')[_0x084a('0x4f')]('color')[_0x084a('0x50')](_0x084a('0x51'));var _0x1ffd20=squel['select']()['field'](_0x084a('0x52'))[_0x084a('0x4f')]('u.fullname')[_0x084a('0x4f')](_0x084a('0x53'))[_0x084a('0x50')](_0x084a('0x54'),'ui')['left_join'](_0x084a('0x55'),'u',_0x084a('0x56'));var _0x31677b=squel[_0x084a('0x4e')]()['from'](_0x084a('0x57'),'i')[_0x084a('0x58')](_0x084a('0x59'),'c',_0x084a('0x5a'))['left_join']('users','o',_0x084a('0x5b'))[_0x084a('0x58')](_0x084a('0x5c'),'a',_0x084a('0x5d'))[_0x084a('0x58')](_0x084a('0x5e'),'me',_0x084a('0x5f'))[_0x084a('0x58')](_0x084a('0x60'),'it',_0x084a('0x61'))[_0x084a('0x58')](_0x084a('0x51'),'t','t.id\x20=\x20it.TagId');var _0xcdd5b=squel[_0x084a('0x62')]();var _0x29fa4b=[];var _0x39edc1=squel[_0x084a('0x62')]();var _0x1c972c;if(_0x866960[_0x084a('0x44')]['search']){_0x1c972c=as[_0x084a('0x63')](_0x866960[_0x084a('0x44')][_0x084a('0x64')]);var _0x54aa6c=_0x1c972c['sqlOperator'];for(var _0x424cd1=0x0;_0x424cd1<_0x1c972c['conditions'][_0x084a('0x4a')];_0x424cd1++){var _0x27278d=_0x1c972c['conditions'][_0x424cd1];var _0x36a3d3='i';var _0x54e9a5=_['find'](_0x597d87,[_0x084a('0x2d'),_0x27278d[_0x084a('0x4f')]]);if(!_0x54e9a5){switch(_0x27278d[_0x084a('0x4f')]){case _0x084a('0x65'):if(_0x27278d[_0x084a('0x66')]==0x1){_0x31677b[_0x084a('0x67')]('`'+_0x27278d[_0x084a('0x4f')]+'`\x20=\x200');}else{_0x31677b[_0x084a('0x67')]('`'+_0x27278d[_0x084a('0x4f')]+_0x084a('0x68'));}break;case'Contact':if(_0x27278d[_0x084a('0x69')]===_0x084a('0x6a')){if(_0x27278d[_0x084a('0x66')][_0x084a('0x33')]('\x20')['length']>0x1){_0xcdd5b[_0x54aa6c](_0x084a('0x6b'),qs['getFullTextValue'](_0x27278d[_0x084a('0x66')]),null);}else{var _0x2da4d4='%'+_0x27278d[_0x084a('0x66')]+'%';_0xcdd5b[_0x54aa6c]('c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?',_0x2da4d4,_0x2da4d4,_0x2da4d4);}}else{_0x54e9a5=_['find'](_0x597d87,[_0x084a('0x2d'),_0x084a('0x6c')]);_0x27278d['field']=_0x084a('0x6c');_0x3a8192=as['buildExpression'](_0x36a3d3,_0x54e9a5['type'],_0x27278d);_0xcdd5b[_0x54aa6c](_0x3a8192[_0x084a('0x6d')],_0x3a8192[_0x084a('0x66')][_0x084a('0x6e')],_0x3a8192[_0x084a('0x66')][_0x084a('0x2c')]);}break;case _0x084a('0x6f'):var _0x3f2c41=_0x27278d[_0x084a('0x66')][_0x084a('0x33')](',')['map'](function(_0x445563){return Number(_0x445563);});_0x3f2c41[_0x084a('0x34')](function(_0x3668eb){_0x39edc1['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x3668eb+',%');});_0x29fa4b=_[_0x084a('0x70')](_0x29fa4b,_0x3f2c41);break;case _0x084a('0x71'):if(_0x27278d['operator']===_0x084a('0x6a')){_0xcdd5b[_0x54aa6c]('CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','%'+_0x27278d['value']+'%',null);}else{_0x54e9a5=_[_0x084a('0x72')](_0x597d87,['name','UserId']);_0x27278d[_0x084a('0x4f')]=_0x084a('0x73');_0x3a8192=as[_0x084a('0x74')](_0x36a3d3,_0x54e9a5['type'],_0x27278d);_0xcdd5b[_0x54aa6c](_0x3a8192[_0x084a('0x6d')],_0x3a8192[_0x084a('0x66')][_0x084a('0x6e')],_0x3a8192[_0x084a('0x66')][_0x084a('0x2c')]);}break;case _0x084a('0x75'):_0x3a8192=as[_0x084a('0x74')]('me',null,_0x27278d);_0xcdd5b[_0x54aa6c](_0x3a8192['text'],_0x3a8192['value'][_0x084a('0x6e')],_0x3a8192[_0x084a('0x66')]['end']);break;}}else{var _0x3a8192=as[_0x084a('0x74')](_0x36a3d3,_0x54e9a5[_0x084a('0x41')],_0x27278d);_0xcdd5b[_0x54aa6c](_0x3a8192[_0x084a('0x6d')],_0x3a8192['value'][_0x084a('0x6e')],_0x3a8192[_0x084a('0x66')][_0x084a('0x2c')]);}}}else{var _0x5a9bfe=_(_0x866960['query'])[_0x084a('0x45')]()[_0x084a('0x3e')](function(_0x2a6331){return _[_0x084a('0x76')](_0x597d87,[_0x084a('0x2d'),_0x2a6331])?_0x2a6331:undefined;})[_0x084a('0x77')]()[_0x084a('0x66')]();if(!_['isEmpty'](_0x5a9bfe)){_0x5a9bfe[_0x084a('0x34')](function(_0x51a066){if(_0x51a066==='MailAccountId'){_0x31677b[_0x084a('0x78')](_0x084a('0x79'),[][_0x084a('0x7a')](_0x866960['query'][_0x51a066]));}else if(_0x51a066===_0x084a('0x7b')){var _0x57729c=JSON[_0x084a('0x7c')](_0x866960[_0x084a('0x44')][_0x51a066])[_0x084a('0x7d')];var _0x12cef4=JSON[_0x084a('0x7c')](_0x866960[_0x084a('0x44')][_0x51a066])['$lte'];_0x31677b['where'](_0x084a('0x7e'),_0x57729c,_0x12cef4);}else{if(_0x866960[_0x084a('0x44')][_0x51a066]===_0x084a('0x7f')){_0x31677b[_0x084a('0x78')]('i.'+_0x51a066+_0x084a('0x80'));}else{_0x31677b[_0x084a('0x78')]('i.'+_0x51a066+'\x20=\x20?',_0x866960[_0x084a('0x44')][_0x51a066]);}}});}if(_0x866960[_0x084a('0x44')][_0x084a('0x81')]){if(_0x866960[_0x084a('0x44')][_0x084a('0x81')]==0x1){_0x31677b[_0x084a('0x67')](_0x084a('0x82'));}else{_0x31677b['having'](_0x084a('0x83'));}}if(_0x866960[_0x084a('0x44')][_0x084a('0x84')]){_0x29fa4b=_[_0x084a('0x85')](_0x866960[_0x084a('0x44')][_0x084a('0x84')])?_0x866960[_0x084a('0x44')][_0x084a('0x84')]:new Array(_0x866960[_0x084a('0x44')][_0x084a('0x84')]);_0x29fa4b['forEach'](function(_0x5d22aa){_0x39edc1['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x5d22aa+',%');});}if(_0x866960[_0x084a('0x44')][_0x084a('0x86')]){var _0x5a73ed=_0x866960[_0x084a('0x44')][_0x084a('0x86')][_0x084a('0x87')]('\x5c','\x5c\x5c')[_0x084a('0x87')](/'/g,'\x27\x27');if(qs['isNumeric'](_0x5a73ed)){_0xcdd5b['or']('i.id\x20LIKE\x20?',_0x5a73ed+'%');}else if(qs[_0x084a('0x88')](_0x5a73ed)){_0xcdd5b['or'](_0x084a('0x89'),_0x5a73ed+'%');}else{_0xcdd5b['or'](_0x084a('0x8a'),qs[_0x084a('0x8b')](_0x5a73ed))['or'](_0x084a('0x8c'),qs[_0x084a('0x8b')](_0x5a73ed));}}}_0x31677b[_0x084a('0x78')](_0xcdd5b);_0x31677b['group'](_0x084a('0x8d'));var _0xd14cab={'type':db[_0x084a('0x8e')][_0x084a('0x8f')][_0x084a('0x90')],'raw':!![]};var _0x31b89a=_0x31677b[_0x084a('0x91')]();_0x31b89a['field'](_0x084a('0x8d'));_0x31b89a[_0x084a('0x4f')](_0x084a('0x92'),_0x084a('0x65'));if(_0x284cdc[_0x084a('0x4b')]){_0x284cdc[_0x084a('0x4b')][_0x084a('0x34')](function(_0x7ca856){var _0x3da502=_0x7ca856[0x0]===_0x084a('0x93')?_0x7ca856[0x0]:'i.'+_0x7ca856[0x0];_0x31677b[_0x084a('0x4b')](_0x3da502,_0x7ca856[0x1]==='DESC'?![]:!![]);});}if(!_[_0x084a('0x94')](_0x29fa4b)){_0x31677b[_0x084a('0x67')](_0x39edc1);_0x31b89a['where'](_0x084a('0x95'),_0x29fa4b);}BPromise['resolve']()['then'](function(){if(!_0x1c972c){if(_0x866960[_0x084a('0x44')][_0x084a('0x96')])return;_0x31b89a['where'](_0x084a('0x97'));_0x31677b[_0x084a('0x78')](_0x084a('0x97'));return;}if(_0x866960[_0x084a('0x98')][_0x084a('0x99')]!==_0x084a('0x9a'))return;return _0x866960[_0x084a('0x98')][_0x084a('0x9b')]({'attributes':['id'],'raw':!![]})[_0x084a('0x2a')](function(_0x8074aa){if(_[_0x084a('0x94')](_0x8074aa)){_0x31b89a[_0x084a('0x78')](_0x084a('0x9c'));_0x31677b[_0x084a('0x78')](_0x084a('0x9c'));}else{_0x31b89a['where'](_0x084a('0x79'),_[_0x084a('0x3e')](_0x8074aa,'id'));_0x31677b[_0x084a('0x78')](_0x084a('0x79'),_[_0x084a('0x3e')](_0x8074aa,'id'));}});})[_0x084a('0x2a')](function(){if(_0x866960[_0x084a('0x98')][_0x084a('0x99')]==='agent'&&!_0x1c972c&&!_0x866960['query'][_0x084a('0x96')])return[];return db[_0x084a('0x9d')]['query'](_0x31b89a['toString'](),_0xd14cab);})[_0x084a('0x2a')](function(_0x496c2f){_0x10983f[_0x084a('0x20')]=_0x496c2f['length'];if(_0x10983f[_0x084a('0x20')]===0x0)return[];return db[_0x084a('0x9d')][_0x084a('0x44')](_0x1598c4[_0x084a('0x9e')](),_0xd14cab)['then'](function(_0x5ebbe8){_0x33b067=_['keyBy'](_0x5ebbe8,'id');_0xd14cab=_[_0x084a('0x9f')](_0xd14cab,{'model':db[_0x084a('0x36')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x866960[_0x084a('0x44')]['fields']){_0x284cdc[_0x084a('0x48')][_0x084a('0x34')](function(_0x59d977){_0x31677b[_0x084a('0x4f')]('i.'+_0x59d977);});}else{_0x31677b[_0x084a('0x4f')]('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)',_0x084a('0x65'));_0x31677b[_0x084a('0x4f')](_0x084a('0xa0'),'Account.key');_0x31677b['field'](_0x084a('0xa1'),'Account.mandatoryDisposition');_0x31677b[_0x084a('0x4f')](_0x084a('0xa2'),_0x084a('0x93'));_0x31677b[_0x084a('0x4f')](_0x084a('0x8d'));_0x31677b[_0x084a('0x4f')]('i.createdAt');_0x31677b[_0x084a('0x4f')]('i.updatedAt');_0x31677b['field'](_0x084a('0xa3'));_0x31677b[_0x084a('0x4f')](_0x084a('0xa4'));_0x31677b[_0x084a('0x4f')](_0x084a('0xa5'));_0x31677b[_0x084a('0x4f')]('i.lastMsgAt');_0x31677b['field'](_0x084a('0xa6'));_0x31677b[_0x084a('0x4f')](_0x084a('0xa7'));_0x31677b['field'](_0x084a('0xa8'));_0x31677b[_0x084a('0x4f')]('i.secondDisposition');_0x31677b['field'](_0x084a('0xa9'));_0x31677b['field']('i.substatus');_0x31677b[_0x084a('0x4f')](_0x084a('0xaa'));_0x31677b['field'](_0x084a('0xab'));_0x31677b[_0x084a('0x4f')]('i.MailAccountId');_0x31677b[_0x084a('0x4f')](_0x084a('0xac'));_0x31677b[_0x084a('0x4f')](_0x084a('0xad'),_0x084a('0xae'));_0x31677b[_0x084a('0x4f')]('c.lastName','Contact.lastName');_0x31677b[_0x084a('0x4f')](_0x084a('0xaf'),'Contact.email');_0x31677b[_0x084a('0x4f')]('c.phone',_0x084a('0xb0'));_0x31677b[_0x084a('0x4f')](_0x084a('0xb1'),_0x084a('0xb2'));_0x31677b[_0x084a('0x4f')](_0x084a('0xb3'),'Contact.fax');_0x31677b['field'](_0x084a('0xb4'),_0x084a('0xb5'));_0x31677b[_0x084a('0x4f')](_0x084a('0xb6'),_0x084a('0xb7'));_0x31677b['field'](_0x084a('0xb8'),_0x084a('0x31'));}if(_0x284cdc[_0x084a('0x22')])_0x31677b[_0x084a('0x22')](_0x284cdc['limit']);if(_0x284cdc[_0x084a('0x21')])_0x31677b[_0x084a('0x21')](_0x284cdc[_0x084a('0x21')]);return db[_0x084a('0x9d')][_0x084a('0x44')](_0x31677b[_0x084a('0x9e')](),_0xd14cab);})[_0x084a('0x2a')](function(_0x8b4013){_0x1ffd20[_0x084a('0x78')](_0x084a('0xb9'),_[_0x084a('0x3e')](_0x8b4013,'id'));return db['sequelize']['query'](_0x1ffd20[_0x084a('0x9e')](),_0xd14cab)['then'](function(_0x3d8c48){var _0x41737e=_[_0x084a('0xba')](_0x3d8c48,_0x084a('0xbb'));var _0x9a5c6b=[];return db['Setting'][_0x084a('0x37')]({'attributes':[_0x084a('0xbc')],'raw':!![]})['then'](function(_0x439204){var _0x3e150d=_0x439204[_0x084a('0xbc')];_0x8b4013['forEach'](function(_0x3090b9){_0x9a5c6b[_0x084a('0x35')](updateMailInteraction(_0x3090b9,_0x33b067,_0x41737e,_0x3e150d));});return BPromise[_0x084a('0xbd')](_0x9a5c6b);});});});})[_0x084a('0x2a')](function(_0x318eca){_0x10983f[_0x084a('0xbe')]=_0x318eca;return _0x10983f;})[_0x084a('0x2a')](respondWithFilteredResult(_0x1454a9,_0x284cdc))[_0x084a('0x3c')](handleError(_0x1454a9,null));};exports['show']=function(_0x1de507,_0x1a58c6){var _0x355c04={'raw':![],'where':{'id':_0x1de507['params']['id']}},_0x8b89d0={};_0x8b89d0[_0x084a('0x43')]=_[_0x084a('0x45')](db[_0x084a('0x36')][_0x084a('0x3f')]);_0x8b89d0[_0x084a('0x44')]=_[_0x084a('0x45')](_0x1de507[_0x084a('0x44')]);_0x8b89d0['filters']=_[_0x084a('0x47')](_0x8b89d0[_0x084a('0x43')],_0x8b89d0[_0x084a('0x44')]);_0x355c04[_0x084a('0x48')]=_[_0x084a('0x47')](_0x8b89d0[_0x084a('0x43')],qs[_0x084a('0x49')](_0x1de507[_0x084a('0x44')][_0x084a('0x49')]));_0x355c04[_0x084a('0x48')]=_0x355c04[_0x084a('0x48')][_0x084a('0x4a')]?_0x355c04[_0x084a('0x48')]:_0x8b89d0[_0x084a('0x43')];if(_0x1de507[_0x084a('0x44')][_0x084a('0xbf')]){_0x355c04[_0x084a('0xc0')]=[{'all':!![]}];}_0x355c04=_['merge']({},_0x355c04,_0x1de507[_0x084a('0xc1')]);return db[_0x084a('0x36')][_0x084a('0x72')](_0x355c04)[_0x084a('0x2a')](handleEntityNotFound(_0x1a58c6,null))['then'](respondWithResult(_0x1a58c6,null))[_0x084a('0x3c')](handleError(_0x1a58c6,null));};exports[_0x084a('0xc2')]=function(_0x4662f9,_0x23df0c){return db[_0x084a('0x36')][_0x084a('0xc2')](_0x4662f9['body'],{})['then'](respondWithResult(_0x23df0c,0xc9))[_0x084a('0x3c')](handleError(_0x23df0c,null));};exports[_0x084a('0x29')]=function(_0x459907,_0x3b89f6){if(_0x459907[_0x084a('0xc3')]['id']){delete _0x459907[_0x084a('0xc3')]['id'];}return db[_0x084a('0x36')][_0x084a('0x72')]({'where':{'id':_0x459907['params']['id']}})[_0x084a('0x2a')](handleEntityNotFound(_0x3b89f6,null))[_0x084a('0x2a')](saveUpdates(_0x459907[_0x084a('0xc3')],null))[_0x084a('0x2a')](respondWithResult(_0x3b89f6,null))['catch'](handleError(_0x3b89f6,null));};exports['destroy']=function(_0x622764,_0x3ea85e){return db[_0x084a('0x36')][_0x084a('0x72')]({'where':{'id':_0x622764[_0x084a('0xc4')]['id']}})['then'](handleEntityNotFound(_0x3ea85e,null))['then'](removeEntity(_0x3ea85e,null))['catch'](handleError(_0x3ea85e,null));};exports[_0x084a('0xc5')]=function(_0x19aff1,_0x5dab17){return db[_0x084a('0x36')][_0x084a('0xc5')]()['then'](respondWithResult(_0x5dab17,null))[_0x084a('0x3c')](handleError(_0x5dab17,null));};exports[_0x084a('0xc6')]=function(_0x255b52,_0x565ae5,_0x157e31){return db[_0x084a('0xc7')][_0x084a('0x72')]({'where':{'id':_0x255b52[_0x084a('0xc4')]['id']}})[_0x084a('0x2a')](handleEntityNotFound(_0x565ae5,null))[_0x084a('0x2a')](function(_0x58b27b){if(_0x58b27b){return _0x58b27b[_0x084a('0xc6')](_0x255b52['body'][_0x084a('0xc8')],_['omit'](_0x255b52[_0x084a('0xc3')],[_0x084a('0xc8'),'id'])||{});}})[_0x084a('0x2a')](respondWithResult(_0x565ae5,null))[_0x084a('0x3c')](handleError(_0x565ae5,null));};exports[_0x084a('0xc9')]=function(_0x20d051,_0x3859d5,_0x1fb924){var _0x3ec164={'raw':![],'where':{}};var _0x33f4bd={};var _0xafff35={'count':0x0,'rows':[]};return db[_0x084a('0x36')]['findOne']({'where':{'id':_0x20d051[_0x084a('0xc4')]['id']}})[_0x084a('0x2a')](handleEntityNotFound(_0x3859d5,null))[_0x084a('0x2a')](function(_0x4725a0){if(_0x4725a0){_0x33f4bd[_0x084a('0x43')]=_[_0x084a('0x45')](db[_0x084a('0xc7')][_0x084a('0x3f')]);_0x33f4bd['query']=_['keys'](_0x20d051['query']);_0x33f4bd[_0x084a('0x46')]=_[_0x084a('0x47')](_0x33f4bd[_0x084a('0x43')],_0x33f4bd[_0x084a('0x44')]);_0x3ec164[_0x084a('0x48')]=_[_0x084a('0x47')](_0x33f4bd[_0x084a('0x43')],qs[_0x084a('0x49')](_0x20d051[_0x084a('0x44')][_0x084a('0x49')]));_0x3ec164[_0x084a('0x48')]=_0x3ec164[_0x084a('0x48')][_0x084a('0x4a')]?_0x3ec164[_0x084a('0x48')]:_0x33f4bd[_0x084a('0x43')];if(!_0x20d051[_0x084a('0x44')][_0x084a('0xca')](_0x084a('0xcb'))){_0x3ec164[_0x084a('0x22')]=qs[_0x084a('0x22')](_0x20d051[_0x084a('0x44')]['limit']);_0x3ec164[_0x084a('0x21')]=qs[_0x084a('0x21')](_0x20d051[_0x084a('0x44')]['offset']);}_0x3ec164[_0x084a('0x4b')]=qs[_0x084a('0x4c')](_0x20d051[_0x084a('0x44')][_0x084a('0x4c')]);_0x3ec164['where']=qs[_0x084a('0x46')](_[_0x084a('0x4d')](_0x20d051['query'],_0x33f4bd[_0x084a('0x46')]));_0x3ec164['where']['MailInteractionId']=_0x4725a0['id'];if(_0x20d051[_0x084a('0x44')][_0x084a('0x86')]){_0x3ec164[_0x084a('0x78')]=_[_0x084a('0x9f')](_0x3ec164[_0x084a('0x78')],{'$or':_['map'](_0x3ec164[_0x084a('0x48')],function(_0x1efdfc){var _0x418564={};_0x418564[_0x1efdfc]={'$like':'%'+_0x20d051[_0x084a('0x44')][_0x084a('0x86')]+'%'};return _0x418564;})});}if(_0x20d051[_0x084a('0x44')]['$gte']){var _0xc77599=_0x20d051['query'][_0x084a('0x7d')][_0x084a('0x33')](',');var _0x409c4e={};_0x409c4e[_0xc77599[0x0]]={'$gte':moment(_0xc77599[0x1])[_0x084a('0xcc')]('YYYY-MM-DD\x20HH:mm:ss')};_0x3ec164['where']=_[_0x084a('0x9f')](_0x3ec164['where'],_0x409c4e);}_0x3ec164=_[_0x084a('0x9f')]({},_0x3ec164,_0x20d051[_0x084a('0xc1')]);return db[_0x084a('0xc7')][_0x084a('0x20')]({'where':_0x3ec164['where']})['then'](function(_0x56475e){_0xafff35['count']=_0x56475e;if(_0x20d051['query'][_0x084a('0xbf')]){_0x3ec164[_0x084a('0xc0')]=[{'all':!![]}];}return db[_0x084a('0xc7')][_0x084a('0xcd')](_0x3ec164);})[_0x084a('0x2a')](function(_0x35208f){if(_0x20d051[_0x084a('0x44')][_0x084a('0xce')]===_0x084a('0xcf')){for(var _0x5aecbc=0x0;_0x5aecbc<_0x35208f[_0x084a('0x4a')];_0x5aecbc++){_0x35208f[_0x5aecbc][_0x084a('0xc3')]=juice(_0x35208f[_0x5aecbc]['body']);}}_0xafff35[_0x084a('0xbe')]=_0x35208f;return _0xafff35;});}})[_0x084a('0x2a')](respondWithFilteredResult(_0x3859d5,_0x3ec164))[_0x084a('0x3c')](handleError(_0x3859d5,null));};exports[_0x084a('0xd0')]=function(_0x3d6b20,_0x1786fe,_0x53785c){return db[_0x084a('0x36')][_0x084a('0x72')]({'where':{'id':_0x3d6b20[_0x084a('0xc4')]['id']}})[_0x084a('0x2a')](handleEntityNotFound(_0x1786fe,null))[_0x084a('0x2a')](function(_0x4ff780){if(_0x4ff780){return _0x4ff780[_0x084a('0xd1')](_0x3d6b20['body'][_0x084a('0xc8')],_[_0x084a('0xd2')](_0x3d6b20[_0x084a('0xc3')],['ids','id'])||{})[_0x084a('0xd3')](function(){return db[_0x084a('0x6f')][_0x084a('0xcd')]({'attributes':['id',_0x084a('0x2d'),'color'],'where':{'id':_0x3d6b20[_0x084a('0xc3')][_0x084a('0xc8')]}});})[_0x084a('0x2a')](function(_0x2cb2c7){socket[_0x084a('0xd4')](_0x084a('0xd5'),{'id':Number(_0x3d6b20['params']['id']),'tags':_0x2cb2c7||[]});return{'id':Number(_0x3d6b20[_0x084a('0xc4')]['id']),'tags':_0x2cb2c7||[]};});}})[_0x084a('0x2a')](respondWithResult(_0x1786fe,null))[_0x084a('0x3c')](handleError(_0x1786fe,null));};exports['removeTags']=function(_0x47a8b8,_0x53406e,_0xdbc62a){return db[_0x084a('0x36')][_0x084a('0x72')]({'where':{'id':_0x47a8b8[_0x084a('0xc4')]['id']}})[_0x084a('0x2a')](handleEntityNotFound(_0x53406e,null))[_0x084a('0x2a')](function(_0x132d98){if(_0x132d98){return _0x132d98[_0x084a('0xd6')](_0x47a8b8['query'][_0x084a('0xc8')]);}})[_0x084a('0x2a')](respondWithStatusCode(_0x53406e,null))[_0x084a('0x3c')](handleError(_0x53406e,null));};exports[_0x084a('0xd7')]=function(_0x16d661,_0x38f42e){var _0x3cd38f=moment()['unix']()['toString']();var _0xee252d=path['join'](config['root'],_0x084a('0xd8'),_0x084a('0xd9'),_0x084a('0xda'));var _0x9c2089=path[_0x084a('0xdb')](config[_0x084a('0xdc')],_0x084a('0xd8'),_0x084a('0xd9'),_0x084a('0xdd'));var _0x5cf841=path[_0x084a('0xdb')](_0xee252d,_0x3cd38f);var _0x406fa2=util['format'](_0x084a('0xde'),_0x16d661[_0x084a('0xc4')]['id'],_0x3cd38f);var _0x596e44=path[_0x084a('0xdb')](_0xee252d,_0x406fa2);var _0x11c7e5=[];if(_0x16d661['query'][_0x084a('0xdd')]){_0x11c7e5[_0x084a('0x35')]({'model':db['Attachment'],'as':'Attachments','raw':!![]});}var _0x2c5097=[{'model':db['MailMessage'],'as':'Messages','attributes':['id',_0x084a('0xc3'),'from','to','cc',_0x084a('0xdf'),_0x084a('0xe0'),_0x084a('0x7b')],'where':{'secret':![]},'order':qs[_0x084a('0x4c')]('id'),'include':_0x11c7e5}];return db[_0x084a('0x36')][_0x084a('0x72')]({'where':{'id':_0x16d661[_0x084a('0xc4')]['id']},'include':_0x2c5097})[_0x084a('0x2a')](handleEntityNotFound(_0x38f42e,null))['then'](function(_0x14534d){if(_0x14534d&&_0x14534d[_0x084a('0xe1')]){var _0x58685b=_0x14534d['get']({'plain':!![]});fs[_0x084a('0xe2')](_0x5cf841);return BPromise['each'](_0x58685b[_0x084a('0xe1')],function(_0x503a6b,_0x287970){var _0x257358={'from':_0x503a6b[_0x084a('0x50')],'to':_0x503a6b['to'],'subject':_0x503a6b['subject'],'html':_0x503a6b[_0x084a('0xc3')],'headers':{'Date':moment(_0x503a6b[_0x084a('0x7b')])[_0x084a('0xcc')](_0x084a('0xe3'))},'attachments':[]};if(_0x503a6b['cc']){_0x257358['headers']['Cc']=_0x503a6b['cc'];}if(_0x503a6b['bcc']){_0x257358[_0x084a('0xe4')][_0x084a('0xe5')]=_0x503a6b[_0x084a('0xdf')];}return new BPromise(function(_0x1ae30a,_0x1e74cf){if(_0x503a6b[_0x084a('0xe6')]){for(var _0x548e23=0x0;_0x548e23<_0x503a6b['Attachments'][_0x084a('0x4a')];_0x548e23++){var _0xc47b46=_0x503a6b[_0x084a('0xe6')][_0x548e23];var _0x44d15f=path[_0x084a('0xdb')](_0x9c2089,_0xc47b46[_0x084a('0xe7')]);if(fs[_0x084a('0xe8')](_0x44d15f)){_0x257358[_0x084a('0xdd')][_0x084a('0x35')]({'name':_0xc47b46[_0x084a('0x2d')],'contentType':_0xc47b46['type'],'data':fs[_0x084a('0xe9')](_0x44d15f)});}}}emlformat[_0x084a('0xea')](_0x257358,function(_0x4ad0fc,_0x343216){if(_0x4ad0fc)return _0x1e74cf(_0x4ad0fc);fs[_0x084a('0xeb')](path[_0x084a('0xdb')](_0x5cf841,util[_0x084a('0xcc')]('message%d.eml',_0x287970)),_0x343216);return _0x1ae30a(_0x343216);});});})[_0x084a('0x2a')](function(){return new BPromise(function(_0x11e22e,_0xe59738){zipdir(_0x5cf841,{'saveTo':_0x596e44},function(_0x200513,_0x50b2b0){if(_0x200513)return _0xe59738(_0x200513);return _0x11e22e(_0x50b2b0);});})[_0x084a('0x2a')](function(){return new BPromise(function(_0x9aee10,_0x365495){rimraf(_0x5cf841,function(_0x315811){if(_0x315811)_0x365495(_0x315811);return _0x9aee10();});});})[_0x084a('0x2a')](function(){return _0x38f42e[_0x084a('0xd7')](_0x596e44,_0x406fa2,function(_0xe9c3d2){if(_0xe9c3d2){console['log']('err',_0xe9c3d2);}else{fs[_0x084a('0xec')](_0x596e44);}});});});}else{return _0x38f42e[_0x084a('0x1e')](0xc8);}})[_0x084a('0x3c')](handleError(_0x38f42e,null));};
\ No newline at end of file