Built motion from commit 85328c08.|2.5.50
[motion2.git] / server / api / mailInteraction / mailInteraction.controller.js
index 077b8b2..dbad0ab 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x377f=['attributes','fields','hasOwnProperty','nolimit','where','pick','select','field','from','tools_tags','u.id','u.fullname','ui.MailInteractionId','user_has_mail_interactions','left_join','users','u.id\x20=\x20ui.UserId','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','o.id\x20=\x20i.UserId','a.id\x20=\x20i.MailAccountId','mail_messages','mail_interaction_has_tags','t.id\x20=\x20it.TagId','expr','search','conditions','value','having','`\x20=\x200','`\x20>\x200','operator','split','length','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?','find','ContactId','buildExpression','start','forEach','union','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','UserId','plainBody','text','isEmpty','MailAccountId','i.MailAccountId\x20IN\x20?','concat','createdAt','parse','$gte','$lte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20IS\x20NULL','read','tag','isArray','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','filter','replace','isNumeric','i.id\x20LIKE\x20?','isEmail','c.email\x20LIKE\x20?','MATCH\x20(me.plainBody,\x20me.subject)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','group','i.id','Sequelize','QueryTypes','unreadMessages','order','contactName','DESC','t.id\x20IN\x20?','resolve','i.MailAccountId\x20IS\x20NOT\x20NULL','getMailAccounts','i.MailAccountId\x20IS\x20NULL','sequelize','keyBy','merge','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','a.key','Account.key','a.mandatoryDisposition','Account.mandatoryDisposition','i.createdAt','i.updatedAt','i.closed','i.attach','i.lastMsgAt','i.subject','i.disposition','i.secondDisposition','i.thirdDisposition','i.substatus','i.ContactId','i.MailAccountId','i.UserId','c.firstName','Contact.firstName','c.lastName','Contact.lastName','c.email','Contact.email','c.phone','Contact.phone','Contact.mobile','Contact.fax','o.fullname','Owner.fullname','o.internal','Owner.internal','ui.MailInteractionId\x20IN\x20?','toString','groupBy','enableEmailPreview','all','rows','params','includeAll','create','body','describe','MailMessage','ids','omit','getMessages','sort','MailInteractionId','format','YYYY-MM-DD\x20HH:mm:ss','include','findAll','addTags','setTags','spread','Tag','color','emit','mailInteractionTags:save','removeTags','download','join','root','server','files','attachments','transcript-%d-%s.zip','Attachments','bcc','subject','Messages','get','mkdirSync','each','ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ','headers','basename','readFileSync','build','writeFileSync','log','unlinkSync','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','mustache','sox','to-csv','ejs','lodash','crypto','papaparse','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','register','status','end','count','offset','limit','set','Content-Range','apply','save','update','then','sendStatus','error','stack','name','Users','fullname','TagIds','push','MailInteraction','findOne','lastMsgBody','lastMsgText','trimStart','fromString','catch','index','map','rawAttributes','type','key','query','keys','filters','intersection','model'];(function(_0x6e1239,_0x3562ac){var _0x418150=function(_0x279f06){while(--_0x279f06){_0x6e1239['push'](_0x6e1239['shift']());}};_0x418150(++_0x3562ac);}(_0x377f,0xa7));var _0xf377=function(_0xa5e2c3,_0x558055){_0xa5e2c3=_0xa5e2c3-0x0;var _0x259720=_0x377f[_0xa5e2c3];return _0x259720;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0xf377('0x0'));var rimraf=require(_0xf377('0x1'));var zipdir=require(_0xf377('0x2'));var jsonpatch=require(_0xf377('0x3'));var rp=require(_0xf377('0x4'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0xf377('0x5'));var util=require('util');var path=require('path');var sox=require(_0xf377('0x6'));var csv=require(_0xf377('0x7'));var ejs=require(_0xf377('0x8'));var fs=require('fs');var _=require(_0xf377('0x9'));var squel=require('squel');var crypto=require(_0xf377('0xa'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0xf377('0xb'));var htmlToText=require(_0xf377('0xc'));var Redis=require(_0xf377('0xd'));var authService=require(_0xf377('0xe'));var qs=require(_0xf377('0xf'));var as=require(_0xf377('0x10'));var hardwareService=require(_0xf377('0x11'));var logger=require(_0xf377('0x12'))(_0xf377('0x13'));var utils=require(_0xf377('0x14'));var config=require(_0xf377('0x15'));var licenseUtil=require(_0xf377('0x16'));var db=require(_0xf377('0x17'))['db'];config[_0xf377('0x18')]=_[_0xf377('0x19')](config['redis'],{'host':_0xf377('0x1a'),'port':0x18eb});var socket=require(_0xf377('0x1b'))(new Redis(config['redis']));require('./mailInteraction.socket')[_0xf377('0x1c')](socket);function respondWithStatusCode(_0x1752cc,_0xd3c1af){_0xd3c1af=_0xd3c1af||0xcc;return function(_0x42a1df){if(_0x42a1df){return _0x1752cc['sendStatus'](_0xd3c1af);}return _0x1752cc[_0xf377('0x1d')](_0xd3c1af)[_0xf377('0x1e')]();};}function respondWithResult(_0x14774b,_0x55a6ab){_0x55a6ab=_0x55a6ab||0xc8;return function(_0x5a7214){if(_0x5a7214){return _0x14774b[_0xf377('0x1d')](_0x55a6ab)['json'](_0x5a7214);}};}function respondWithFilteredResult(_0x289099,_0x232712){return function(_0xa8e1a2){if(_0xa8e1a2){var _0x1238f0=_0xa8e1a2[_0xf377('0x1f')],_0x299316=_0x232712['offset'],_0x15f33d=_0x232712[_0xf377('0x20')]+_0x232712[_0xf377('0x21')],_0x3ab2f1;if(_0x15f33d>=_0x1238f0){_0x15f33d=_0x1238f0;_0x3ab2f1=0xc8;}else{_0x3ab2f1=0xce;}_0x289099['status'](_0x3ab2f1);return _0x289099[_0xf377('0x22')](_0xf377('0x23'),_0x299316+'-'+_0x15f33d+'/'+_0x1238f0)['json'](_0xa8e1a2);}return null;};}function patchUpdates(_0x4d4f30){return function(_0x975c68){try{jsonpatch[_0xf377('0x24')](_0x975c68,_0x4d4f30,!![]);}catch(_0x38667b){return BPromise['reject'](_0x38667b);}return _0x975c68[_0xf377('0x25')]();};}function saveUpdates(_0x57b94e,_0x205151){return function(_0x59d719){if(_0x59d719){return _0x59d719[_0xf377('0x26')](_0x57b94e)[_0xf377('0x27')](function(_0xe209f5){return _0xe209f5;});}return null;};}function removeEntity(_0x13cb87,_0x208946){return function(_0x317348){if(_0x317348){return _0x317348['destroy']()['then'](function(){_0x13cb87[_0xf377('0x1d')](0xcc)[_0xf377('0x1e')]();});}};}function handleEntityNotFound(_0x573945,_0x3be509){return function(_0x2528c4){if(!_0x2528c4){_0x573945[_0xf377('0x28')](0x194);}return _0x2528c4;};}function handleError(_0x495260,_0x3ae3db){_0x3ae3db=_0x3ae3db||0x1f4;return function(_0x260177){logger[_0xf377('0x29')](_0x260177[_0xf377('0x2a')]);if(_0x260177['name']){delete _0x260177[_0xf377('0x2b')];}_0x495260[_0xf377('0x1d')](_0x3ae3db)['send'](_0x260177);};}function getInteractionUsers(_0x1a1fa3,_0x51490d){return new BPromise(function(_0x24a62e,_0x57a11d){try{if(_0x51490d[_0x1a1fa3['id']]){_0x1a1fa3[_0xf377('0x2c')]=_['map'](_0x51490d[_0x1a1fa3['id']],function(_0x58e0ea){return{'id':_0x58e0ea['id'],'fullname':_0x58e0ea[_0xf377('0x2d')]};});}}catch(_0x36e4d7){_0x57a11d(_0x36e4d7);}_0x24a62e(_0x1a1fa3);});}function getInteractionTags(_0x397210,_0xeec8c9){return new BPromise(function(_0x46d3df,_0xdc6efd){try{if(_0x397210[_0xf377('0x2e')]){_0x397210['Tags']=[];_0x397210[_0xf377('0x2e')]['split'](',')['forEach'](function(_0x150b36){_0x397210['Tags'][_0xf377('0x2f')](_0xeec8c9[_0x150b36]);});}delete _0x397210[_0xf377('0x2e')];}catch(_0x1f9b78){_0xdc6efd(_0x1f9b78);}_0x46d3df(_0x397210);});}function getLastMessageText(_0x1cb745){return new BPromise(function(_0x10604e,_0x18d30c){return db[_0xf377('0x30')][_0xf377('0x31')]({'where':{'id':_0x1cb745['id']},'attributes':[_0xf377('0x32'),_0xf377('0x33')],'raw':!![]})[_0xf377('0x27')](function(_0x9e01d3){if(!_0x9e01d3[_0xf377('0x33')]){_0x1cb745[_0xf377('0x33')]=_[_0xf377('0x34')](htmlToText[_0xf377('0x35')](_0x9e01d3[_0xf377('0x32')],{'preserveNewlines':!![],'singleNewLineParagraphs':!![],'uppercaseHeadings':![],'noLinkBrackets':!![],'ignoreImage':!![]}));}else{_0x1cb745['lastMsgText']=_0x9e01d3[_0xf377('0x33')];}_0x10604e(_0x1cb745);})[_0xf377('0x36')](function(_0x4ea6b6){_0x18d30c(_0x4ea6b6);});});}function updateMailInteraction(_0x2f3c0a,_0x236252,_0xabd4c7,_0x97f9e){return new BPromise(function(_0x505cad,_0x29a674){return getInteractionUsers(_0x2f3c0a,_0xabd4c7)[_0xf377('0x27')](function(_0xce9ef){return getInteractionTags(_0xce9ef,_0x236252);})[_0xf377('0x27')](function(_0x53907d){if(_0x97f9e){_0x505cad(getLastMessageText(_0x53907d));}else{_0x505cad(_0x53907d);}})[_0xf377('0x36')](function(_0x3fda5c){_0x29a674(_0x3fda5c);});});}exports[_0xf377('0x37')]=function(_0x42198e,_0x1c5d53){var _0x109695={},_0x348eb8={},_0x100879={'count':0x0,'rows':[]};var _0x25b29b=_[_0xf377('0x38')](db[_0xf377('0x30')][_0xf377('0x39')],function(_0x131cc9){return{'name':_0x131cc9['fieldName'],'type':_0x131cc9[_0xf377('0x3a')][_0xf377('0x3b')]};});_0x348eb8['model']=_[_0xf377('0x38')](_0x25b29b,_0xf377('0x2b'));_0x348eb8[_0xf377('0x3c')]=_[_0xf377('0x3d')](_0x42198e[_0xf377('0x3c')]);_0x348eb8[_0xf377('0x3e')]=_[_0xf377('0x3f')](_0x348eb8[_0xf377('0x40')],_0x348eb8[_0xf377('0x3c')]);_0x109695[_0xf377('0x41')]=_[_0xf377('0x3f')](_0x348eb8[_0xf377('0x40')],qs[_0xf377('0x42')](_0x42198e['query'][_0xf377('0x42')]));_0x109695[_0xf377('0x41')]=_0x109695['attributes']['length']?_0x109695[_0xf377('0x41')]:_0x348eb8[_0xf377('0x40')];if(!_0x42198e[_0xf377('0x3c')][_0xf377('0x43')](_0xf377('0x44'))){_0x109695[_0xf377('0x21')]=qs[_0xf377('0x21')](_0x42198e['query'][_0xf377('0x21')]);_0x109695[_0xf377('0x20')]=qs[_0xf377('0x20')](_0x42198e['query'][_0xf377('0x20')]);}_0x109695['order']=qs['sort'](_0x42198e[_0xf377('0x3c')]['sort']);_0x109695[_0xf377('0x45')]=qs[_0xf377('0x3e')](_[_0xf377('0x46')](_0x42198e[_0xf377('0x3c')],_0x348eb8[_0xf377('0x3e')]),_0x25b29b);var _0x1698d6=[];var _0x1cc8cd=squel[_0xf377('0x47')]()[_0xf377('0x48')]('id')[_0xf377('0x48')](_0xf377('0x2b'))[_0xf377('0x48')]('color')[_0xf377('0x49')](_0xf377('0x4a'));var _0x2bfa0a=squel['select']()[_0xf377('0x48')](_0xf377('0x4b'))[_0xf377('0x48')](_0xf377('0x4c'))['field'](_0xf377('0x4d'))['from'](_0xf377('0x4e'),'ui')[_0xf377('0x4f')](_0xf377('0x50'),'u',_0xf377('0x51'));var _0x417340=squel['select']()[_0xf377('0x49')]('mail_interactions','i')['left_join']('cm_contacts','c',_0xf377('0x52'))['left_join'](_0xf377('0x50'),'o',_0xf377('0x53'))[_0xf377('0x4f')]('mail_accounts','a',_0xf377('0x54'))[_0xf377('0x4f')](_0xf377('0x55'),'me','me.MailInteractionId\x20=\x20i.id')['left_join'](_0xf377('0x56'),'it','it.MailInteractionId\x20=\x20i.id')['left_join']('tools_tags','t',_0xf377('0x57'));var _0xa602af=squel['expr']();var _0x573e0e=[];var _0x45c32d=squel[_0xf377('0x58')]();var _0x5b9888;if(_0x42198e['query'][_0xf377('0x59')]){_0x5b9888=as['parseSearch'](_0x42198e[_0xf377('0x3c')][_0xf377('0x59')]);var _0x248703=_0x5b9888['sqlOperator'];for(var _0x3a9778=0x0;_0x3a9778<_0x5b9888[_0xf377('0x5a')]['length'];_0x3a9778++){var _0x539cc7=_0x5b9888[_0xf377('0x5a')][_0x3a9778];var _0x1d6c85='i';var _0x8f46f0=_['find'](_0x25b29b,[_0xf377('0x2b'),_0x539cc7[_0xf377('0x48')]]);if(!_0x8f46f0){switch(_0x539cc7['field']){case'unreadMessages':if(_0x539cc7[_0xf377('0x5b')]==0x1){_0x417340[_0xf377('0x5c')]('`'+_0x539cc7[_0xf377('0x48')]+_0xf377('0x5d'));}else{_0x417340['having']('`'+_0x539cc7['field']+_0xf377('0x5e'));}break;case'Contact':if(_0x539cc7[_0xf377('0x5f')]==='$substring'){if(_0x539cc7['value'][_0xf377('0x60')]('\x20')[_0xf377('0x61')]>0x1){_0xa602af[_0x248703](_0xf377('0x62'),qs[_0xf377('0x63')](_0x539cc7['value']),null);}else{var _0xe7250a='%'+_0x539cc7['value']+'%';_0xa602af[_0x248703](_0xf377('0x64'),_0xe7250a,_0xe7250a,_0xe7250a);}}else{_0x8f46f0=_[_0xf377('0x65')](_0x25b29b,[_0xf377('0x2b'),_0xf377('0x66')]);_0x539cc7[_0xf377('0x48')]=_0xf377('0x66');_0x549a65=as[_0xf377('0x67')](_0x1d6c85,_0x8f46f0[_0xf377('0x3a')],_0x539cc7);_0xa602af[_0x248703](_0x549a65['text'],_0x549a65[_0xf377('0x5b')][_0xf377('0x68')],_0x549a65[_0xf377('0x5b')]['end']);}break;case'Tag':var _0x1169d6=_0x539cc7[_0xf377('0x5b')]['split'](',')[_0xf377('0x38')](function(_0x500a73){return Number(_0x500a73);});_0x1169d6[_0xf377('0x69')](function(_0x95587){_0x45c32d['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x95587+',%');});_0x573e0e=_[_0xf377('0x6a')](_0x573e0e,_0x1169d6);break;case'User':if(_0x539cc7[_0xf377('0x5f')]==='$substring'){_0xa602af[_0x248703](_0xf377('0x6b'),'%'+_0x539cc7[_0xf377('0x5b')]+'%',null);}else{_0x8f46f0=_['find'](_0x25b29b,['name',_0xf377('0x6c')]);_0x539cc7['field']=_0xf377('0x6c');_0x549a65=as[_0xf377('0x67')](_0x1d6c85,_0x8f46f0[_0xf377('0x3a')],_0x539cc7);_0xa602af[_0x248703](_0x549a65['text'],_0x549a65[_0xf377('0x5b')][_0xf377('0x68')],_0x549a65[_0xf377('0x5b')]['end']);}break;case _0xf377('0x6d'):_0x549a65=as[_0xf377('0x67')]('me',null,_0x539cc7);_0xa602af[_0x248703](_0x549a65[_0xf377('0x6e')],_0x549a65[_0xf377('0x5b')][_0xf377('0x68')],_0x549a65[_0xf377('0x5b')][_0xf377('0x1e')]);break;}}else{var _0x549a65=as[_0xf377('0x67')](_0x1d6c85,_0x8f46f0[_0xf377('0x3a')],_0x539cc7);_0xa602af[_0x248703](_0x549a65[_0xf377('0x6e')],_0x549a65[_0xf377('0x5b')]['start'],_0x549a65[_0xf377('0x5b')]['end']);}}}else{var _0x49ebde=_(_0x42198e['query'])['keys']()[_0xf377('0x38')](function(_0x36dda1){return _['some'](_0x25b29b,['name',_0x36dda1])?_0x36dda1:undefined;})['compact']()[_0xf377('0x5b')]();if(!_[_0xf377('0x6f')](_0x49ebde)){_0x49ebde['forEach'](function(_0x1f15f4){if(_0x1f15f4===_0xf377('0x70')){_0x417340[_0xf377('0x45')](_0xf377('0x71'),[][_0xf377('0x72')](_0x42198e[_0xf377('0x3c')][_0x1f15f4]));}else if(_0x1f15f4===_0xf377('0x73')){var _0x42452d=JSON[_0xf377('0x74')](_0x42198e[_0xf377('0x3c')][_0x1f15f4])[_0xf377('0x75')];var _0xe725e2=JSON[_0xf377('0x74')](_0x42198e[_0xf377('0x3c')][_0x1f15f4])[_0xf377('0x76')];_0x417340[_0xf377('0x45')](_0xf377('0x77'),_0x42452d,_0xe725e2);}else{if(_0x42198e[_0xf377('0x3c')][_0x1f15f4]===_0xf377('0x78')){_0x417340['where']('i.'+_0x1f15f4+_0xf377('0x79'));}else{_0x417340['where']('i.'+_0x1f15f4+'\x20=\x20?',_0x42198e['query'][_0x1f15f4]);}}});}if(_0x42198e[_0xf377('0x3c')][_0xf377('0x7a')]){if(_0x42198e[_0xf377('0x3c')][_0xf377('0x7a')]==0x1){_0x417340[_0xf377('0x5c')]('`unreadMessages`\x20=\x200');}else{_0x417340[_0xf377('0x5c')]('`unreadMessages`\x20>\x200');}}if(_0x42198e[_0xf377('0x3c')][_0xf377('0x7b')]){_0x573e0e=_[_0xf377('0x7c')](_0x42198e[_0xf377('0x3c')][_0xf377('0x7b')])?_0x42198e[_0xf377('0x3c')][_0xf377('0x7b')]:new Array(_0x42198e['query'][_0xf377('0x7b')]);_0x573e0e[_0xf377('0x69')](function(_0x9e7bb8){_0x45c32d['or'](_0xf377('0x7d'),'%,'+_0x9e7bb8+',%');});}if(_0x42198e[_0xf377('0x3c')][_0xf377('0x7e')]){var _0x2499a4=_0x42198e[_0xf377('0x3c')][_0xf377('0x7e')][_0xf377('0x7f')]('\x5c','\x5c\x5c')[_0xf377('0x7f')](/'/g,'\x27\x27');if(qs[_0xf377('0x80')](_0x2499a4)){_0xa602af['or'](_0xf377('0x81'),_0x2499a4+'%');}else if(qs[_0xf377('0x82')](_0x2499a4)){_0xa602af['or'](_0xf377('0x83'),_0x2499a4+'%');}else{_0xa602af['or']('MATCH\x20(i.to,\x20i.subject)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs[_0xf377('0x63')](_0x2499a4))['or'](_0xf377('0x84'),qs[_0xf377('0x63')](_0x2499a4));}}}_0x417340[_0xf377('0x45')](_0xa602af);_0x417340[_0xf377('0x85')](_0xf377('0x86'));var _0x1ca1e3={'type':db[_0xf377('0x87')][_0xf377('0x88')]['SELECT'],'raw':!![]};var _0x1d92ff=_0x417340['clone']();_0x1d92ff['field'](_0xf377('0x86'));_0x1d92ff[_0xf377('0x48')]('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)',_0xf377('0x89'));if(_0x109695[_0xf377('0x8a')]){_0x109695['order'][_0xf377('0x69')](function(_0x431b43){var _0x55c7ad=_0x431b43[0x0]===_0xf377('0x8b')?_0x431b43[0x0]:'i.'+_0x431b43[0x0];_0x417340[_0xf377('0x8a')](_0x55c7ad,_0x431b43[0x1]===_0xf377('0x8c')?![]:!![]);});}if(!_[_0xf377('0x6f')](_0x573e0e)){_0x417340[_0xf377('0x5c')](_0x45c32d);_0x1d92ff['where'](_0xf377('0x8d'),_0x573e0e);}BPromise[_0xf377('0x8e')]()[_0xf377('0x27')](function(){if(!_0x5b9888){if(_0x42198e[_0xf377('0x3c')][_0xf377('0x70')]||_0x42198e['query']['journey'])return;_0x1d92ff[_0xf377('0x45')](_0xf377('0x8f'));_0x417340[_0xf377('0x45')](_0xf377('0x8f'));return;}return _0x42198e['user'][_0xf377('0x90')]({'attributes':['id'],'raw':!![]})[_0xf377('0x27')](function(_0x5e55ea){if(_[_0xf377('0x6f')](_0x5e55ea)){_0x1d92ff[_0xf377('0x45')](_0xf377('0x91'));_0x417340[_0xf377('0x45')](_0xf377('0x91'));}else{_0x1d92ff[_0xf377('0x45')](_0xf377('0x71'),_['map'](_0x5e55ea,'id'));_0x417340[_0xf377('0x45')](_0xf377('0x71'),_[_0xf377('0x38')](_0x5e55ea,'id'));}});})['then'](function(){db[_0xf377('0x92')][_0xf377('0x3c')](_0x1d92ff['toString'](),_0x1ca1e3)[_0xf377('0x27')](function(_0x5a9c9a){_0x100879[_0xf377('0x1f')]=_0x5a9c9a[_0xf377('0x61')];if(_0x100879[_0xf377('0x1f')]===0x0)return[];return db[_0xf377('0x92')][_0xf377('0x3c')](_0x1cc8cd['toString'](),_0x1ca1e3)[_0xf377('0x27')](function(_0x2cb97b){_0x1698d6=_[_0xf377('0x93')](_0x2cb97b,'id');_0x1ca1e3=_[_0xf377('0x94')](_0x1ca1e3,{'model':db[_0xf377('0x30')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x42198e[_0xf377('0x3c')][_0xf377('0x42')]){_0x109695['attributes'][_0xf377('0x69')](function(_0x5259c2){_0x417340['field']('i.'+_0x5259c2);});}else{_0x417340[_0xf377('0x48')](_0xf377('0x95'),_0xf377('0x89'));_0x417340[_0xf377('0x48')](_0xf377('0x96'),_0xf377('0x97'));_0x417340['field'](_0xf377('0x98'),_0xf377('0x99'));_0x417340['field']('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',_0xf377('0x8b'));_0x417340[_0xf377('0x48')](_0xf377('0x86'));_0x417340[_0xf377('0x48')](_0xf377('0x9a'));_0x417340['field'](_0xf377('0x9b'));_0x417340[_0xf377('0x48')](_0xf377('0x9c'));_0x417340[_0xf377('0x48')]('i.closedAt');_0x417340['field'](_0xf377('0x9d'));_0x417340[_0xf377('0x48')](_0xf377('0x9e'));_0x417340[_0xf377('0x48')]('i.lastMsgDirection');_0x417340['field'](_0xf377('0x9f'));_0x417340[_0xf377('0x48')](_0xf377('0xa0'));_0x417340[_0xf377('0x48')](_0xf377('0xa1'));_0x417340[_0xf377('0x48')](_0xf377('0xa2'));_0x417340[_0xf377('0x48')](_0xf377('0xa3'));_0x417340['field']('i.to');_0x417340[_0xf377('0x48')](_0xf377('0xa4'));_0x417340[_0xf377('0x48')](_0xf377('0xa5'));_0x417340['field'](_0xf377('0xa6'));_0x417340['field'](_0xf377('0xa7'),_0xf377('0xa8'));_0x417340[_0xf377('0x48')](_0xf377('0xa9'),_0xf377('0xaa'));_0x417340[_0xf377('0x48')](_0xf377('0xab'),_0xf377('0xac'));_0x417340['field'](_0xf377('0xad'),_0xf377('0xae'));_0x417340[_0xf377('0x48')]('c.mobile',_0xf377('0xaf'));_0x417340[_0xf377('0x48')]('c.fax',_0xf377('0xb0'));_0x417340[_0xf377('0x48')](_0xf377('0xb1'),_0xf377('0xb2'));_0x417340[_0xf377('0x48')](_0xf377('0xb3'),_0xf377('0xb4'));_0x417340['field']('GROUP_CONCAT(DISTINCT\x20t.id)','TagIds');}if(_0x109695['limit'])_0x417340['limit'](_0x109695[_0xf377('0x21')]);if(_0x109695['offset'])_0x417340['offset'](_0x109695[_0xf377('0x20')]);return db[_0xf377('0x92')][_0xf377('0x3c')](_0x417340['toString'](),_0x1ca1e3);})[_0xf377('0x27')](function(_0x178b03){_0x2bfa0a[_0xf377('0x45')](_0xf377('0xb5'),_[_0xf377('0x38')](_0x178b03,'id'));return db[_0xf377('0x92')][_0xf377('0x3c')](_0x2bfa0a[_0xf377('0xb6')](),_0x1ca1e3)[_0xf377('0x27')](function(_0x3d54ce){var _0x5247c7=_[_0xf377('0xb7')](_0x3d54ce,'MailInteractionId');var _0x5da42f=[];return db['Setting'][_0xf377('0x31')]({'attributes':[_0xf377('0xb8')],'raw':!![]})[_0xf377('0x27')](function(_0xfd28d){var _0x4b548e=_0xfd28d[_0xf377('0xb8')];_0x178b03['forEach'](function(_0x3ea686){_0x5da42f[_0xf377('0x2f')](updateMailInteraction(_0x3ea686,_0x1698d6,_0x5247c7,_0x4b548e));});return BPromise[_0xf377('0xb9')](_0x5da42f);});});});})[_0xf377('0x27')](function(_0x1f526b){_0x100879[_0xf377('0xba')]=_0x1f526b;return _0x100879;})[_0xf377('0x27')](respondWithFilteredResult(_0x1c5d53,_0x109695));})[_0xf377('0x36')](handleError(_0x1c5d53,null));};exports['show']=function(_0x4db675,_0xac64b9){var _0x3b2fd0={'raw':![],'where':{'id':_0x4db675[_0xf377('0xbb')]['id']}},_0x28f8d4={};_0x28f8d4['model']=_[_0xf377('0x3d')](db[_0xf377('0x30')]['rawAttributes']);_0x28f8d4['query']=_['keys'](_0x4db675['query']);_0x28f8d4[_0xf377('0x3e')]=_[_0xf377('0x3f')](_0x28f8d4['model'],_0x28f8d4[_0xf377('0x3c')]);_0x3b2fd0[_0xf377('0x41')]=_['intersection'](_0x28f8d4['model'],qs[_0xf377('0x42')](_0x4db675[_0xf377('0x3c')][_0xf377('0x42')]));_0x3b2fd0[_0xf377('0x41')]=_0x3b2fd0[_0xf377('0x41')][_0xf377('0x61')]?_0x3b2fd0[_0xf377('0x41')]:_0x28f8d4['model'];if(_0x4db675['query'][_0xf377('0xbc')]){_0x3b2fd0['include']=[{'all':!![]}];}_0x3b2fd0=_[_0xf377('0x94')]({},_0x3b2fd0,_0x4db675['options']);return db[_0xf377('0x30')][_0xf377('0x65')](_0x3b2fd0)[_0xf377('0x27')](handleEntityNotFound(_0xac64b9,null))[_0xf377('0x27')](respondWithResult(_0xac64b9,null))[_0xf377('0x36')](handleError(_0xac64b9,null));};exports['create']=function(_0x250727,_0x5229a3){return db['MailInteraction'][_0xf377('0xbd')](_0x250727['body'],{})[_0xf377('0x27')](respondWithResult(_0x5229a3,0xc9))[_0xf377('0x36')](handleError(_0x5229a3,null));};exports['update']=function(_0x230389,_0x1af775){if(_0x230389[_0xf377('0xbe')]['id']){delete _0x230389['body']['id'];}return db[_0xf377('0x30')][_0xf377('0x65')]({'where':{'id':_0x230389[_0xf377('0xbb')]['id']}})[_0xf377('0x27')](handleEntityNotFound(_0x1af775,null))[_0xf377('0x27')](saveUpdates(_0x230389[_0xf377('0xbe')],null))[_0xf377('0x27')](respondWithResult(_0x1af775,null))[_0xf377('0x36')](handleError(_0x1af775,null));};exports['destroy']=function(_0x35f3dd,_0x210e1a){return db[_0xf377('0x30')][_0xf377('0x65')]({'where':{'id':_0x35f3dd['params']['id']}})[_0xf377('0x27')](handleEntityNotFound(_0x210e1a,null))[_0xf377('0x27')](removeEntity(_0x210e1a,null))[_0xf377('0x36')](handleError(_0x210e1a,null));};exports[_0xf377('0xbf')]=function(_0x2d5625,_0x2b973f){return db[_0xf377('0x30')][_0xf377('0xbf')]()['then'](respondWithResult(_0x2b973f,null))[_0xf377('0x36')](handleError(_0x2b973f,null));};exports['addMessage']=function(_0x8cab6f,_0x242e85,_0x51ecc1){return db[_0xf377('0xc0')][_0xf377('0x65')]({'where':{'id':_0x8cab6f['params']['id']}})['then'](handleEntityNotFound(_0x242e85,null))[_0xf377('0x27')](function(_0x11699e){if(_0x11699e){return _0x11699e['addMessage'](_0x8cab6f[_0xf377('0xbe')][_0xf377('0xc1')],_[_0xf377('0xc2')](_0x8cab6f['body'],[_0xf377('0xc1'),'id'])||{});}})[_0xf377('0x27')](respondWithResult(_0x242e85,null))[_0xf377('0x36')](handleError(_0x242e85,null));};exports[_0xf377('0xc3')]=function(_0x2ab33b,_0x5d55f5,_0xb18d2f){var _0x45ae0f={'raw':![],'where':{}};var _0x9b4d4a={};var _0x584514={'count':0x0,'rows':[]};return db[_0xf377('0x30')][_0xf377('0x31')]({'where':{'id':_0x2ab33b[_0xf377('0xbb')]['id']}})[_0xf377('0x27')](handleEntityNotFound(_0x5d55f5,null))[_0xf377('0x27')](function(_0x12f732){if(_0x12f732){_0x9b4d4a[_0xf377('0x40')]=_[_0xf377('0x3d')](db[_0xf377('0xc0')][_0xf377('0x39')]);_0x9b4d4a[_0xf377('0x3c')]=_[_0xf377('0x3d')](_0x2ab33b[_0xf377('0x3c')]);_0x9b4d4a[_0xf377('0x3e')]=_[_0xf377('0x3f')](_0x9b4d4a[_0xf377('0x40')],_0x9b4d4a[_0xf377('0x3c')]);_0x45ae0f[_0xf377('0x41')]=_[_0xf377('0x3f')](_0x9b4d4a[_0xf377('0x40')],qs['fields'](_0x2ab33b[_0xf377('0x3c')][_0xf377('0x42')]));_0x45ae0f[_0xf377('0x41')]=_0x45ae0f[_0xf377('0x41')][_0xf377('0x61')]?_0x45ae0f[_0xf377('0x41')]:_0x9b4d4a[_0xf377('0x40')];if(!_0x2ab33b['query'][_0xf377('0x43')](_0xf377('0x44'))){_0x45ae0f[_0xf377('0x21')]=qs[_0xf377('0x21')](_0x2ab33b['query'][_0xf377('0x21')]);_0x45ae0f[_0xf377('0x20')]=qs[_0xf377('0x20')](_0x2ab33b[_0xf377('0x3c')][_0xf377('0x20')]);}_0x45ae0f[_0xf377('0x8a')]=qs[_0xf377('0xc4')](_0x2ab33b[_0xf377('0x3c')]['sort']);_0x45ae0f[_0xf377('0x45')]=qs[_0xf377('0x3e')](_['pick'](_0x2ab33b[_0xf377('0x3c')],_0x9b4d4a[_0xf377('0x3e')]));_0x45ae0f[_0xf377('0x45')][_0xf377('0xc5')]=_0x12f732['id'];if(_0x2ab33b['query'][_0xf377('0x7e')]){_0x45ae0f['where']=_['merge'](_0x45ae0f[_0xf377('0x45')],{'$or':_[_0xf377('0x38')](_0x45ae0f[_0xf377('0x41')],function(_0x4f2def){var _0x37383d={};_0x37383d[_0x4f2def]={'$like':'%'+_0x2ab33b[_0xf377('0x3c')][_0xf377('0x7e')]+'%'};return _0x37383d;})});}if(_0x2ab33b[_0xf377('0x3c')][_0xf377('0x75')]){var _0x35e124=_0x2ab33b['query'][_0xf377('0x75')][_0xf377('0x60')](',');var _0x359198={};_0x359198[_0x35e124[0x0]]={'$gte':moment(_0x35e124[0x1])[_0xf377('0xc6')](_0xf377('0xc7'))};_0x45ae0f[_0xf377('0x45')]=_['merge'](_0x45ae0f[_0xf377('0x45')],_0x359198);}_0x45ae0f=_[_0xf377('0x94')]({},_0x45ae0f,_0x2ab33b['options']);return db['MailMessage'][_0xf377('0x1f')]({'where':_0x45ae0f[_0xf377('0x45')]})[_0xf377('0x27')](function(_0x21f3e7){_0x584514[_0xf377('0x1f')]=_0x21f3e7;if(_0x2ab33b['query'][_0xf377('0xbc')]){_0x45ae0f[_0xf377('0xc8')]=[{'all':!![]}];}return db['MailMessage'][_0xf377('0xc9')](_0x45ae0f);})['then'](function(_0x121992){_0x584514[_0xf377('0xba')]=_0x121992;return _0x584514;});}})[_0xf377('0x27')](respondWithFilteredResult(_0x5d55f5,_0x45ae0f))['catch'](handleError(_0x5d55f5,null));};exports[_0xf377('0xca')]=function(_0x210a89,_0x3a983f,_0xac36aa){return db[_0xf377('0x30')][_0xf377('0x65')]({'where':{'id':_0x210a89['params']['id']}})[_0xf377('0x27')](handleEntityNotFound(_0x3a983f,null))[_0xf377('0x27')](function(_0x460d0c){if(_0x460d0c){return _0x460d0c[_0xf377('0xcb')](_0x210a89[_0xf377('0xbe')]['ids'],_[_0xf377('0xc2')](_0x210a89['body'],[_0xf377('0xc1'),'id'])||{})[_0xf377('0xcc')](function(){return db[_0xf377('0xcd')][_0xf377('0xc9')]({'attributes':['id',_0xf377('0x2b'),_0xf377('0xce')],'where':{'id':_0x210a89['body'][_0xf377('0xc1')]}});})[_0xf377('0x27')](function(_0x2dc8bc){socket[_0xf377('0xcf')](_0xf377('0xd0'),{'id':Number(_0x210a89['params']['id']),'tags':_0x2dc8bc||[]});return{'id':Number(_0x210a89['params']['id']),'tags':_0x2dc8bc||[]};});}})[_0xf377('0x27')](respondWithResult(_0x3a983f,null))[_0xf377('0x36')](handleError(_0x3a983f,null));};exports[_0xf377('0xd1')]=function(_0x1ce874,_0x11c051,_0x41e833){return db['MailInteraction'][_0xf377('0x65')]({'where':{'id':_0x1ce874[_0xf377('0xbb')]['id']}})[_0xf377('0x27')](handleEntityNotFound(_0x11c051,null))['then'](function(_0x56af87){if(_0x56af87){return _0x56af87['removeTags'](_0x1ce874[_0xf377('0x3c')][_0xf377('0xc1')]);}})[_0xf377('0x27')](respondWithStatusCode(_0x11c051,null))[_0xf377('0x36')](handleError(_0x11c051,null));};exports[_0xf377('0xd2')]=function(_0x5cd702,_0x3ac771){var _0x24e328=moment()['unix']()['toString']();var _0x317595=path[_0xf377('0xd3')](config[_0xf377('0xd4')],_0xf377('0xd5'),'files','tmp');var _0x38ed10=path[_0xf377('0xd3')](config['root'],_0xf377('0xd5'),_0xf377('0xd6'),_0xf377('0xd7'));var _0x5c7d44=path['join'](_0x317595,_0x24e328);var _0x487f81=util['format'](_0xf377('0xd8'),_0x5cd702[_0xf377('0xbb')]['id'],_0x24e328);var _0x10c630=path[_0xf377('0xd3')](_0x317595,_0x487f81);var _0xf38c71=[];if(_0x5cd702[_0xf377('0x3c')][_0xf377('0xd7')]){_0xf38c71[_0xf377('0x2f')]({'model':db['Attachment'],'as':_0xf377('0xd9'),'raw':!![]});}var _0x1310e2=[{'model':db[_0xf377('0xc0')],'as':'Messages','attributes':['id',_0xf377('0xbe'),_0xf377('0x49'),'to','cc',_0xf377('0xda'),_0xf377('0xdb'),'createdAt'],'where':{'secret':![]},'order':qs['sort']('id'),'include':_0xf38c71}];return db[_0xf377('0x30')][_0xf377('0x65')]({'where':{'id':_0x5cd702['params']['id']},'include':_0x1310e2})[_0xf377('0x27')](handleEntityNotFound(_0x3ac771,null))[_0xf377('0x27')](function(_0x19828b){if(_0x19828b&&_0x19828b[_0xf377('0xdc')]){var _0x1fe5fc=_0x19828b[_0xf377('0xdd')]({'plain':!![]});fs[_0xf377('0xde')](_0x5c7d44);return BPromise[_0xf377('0xdf')](_0x1fe5fc[_0xf377('0xdc')],function(_0x22e566,_0x2da63d){var _0xa224b={'from':_0x22e566[_0xf377('0x49')],'to':_0x22e566['to'],'subject':_0x22e566[_0xf377('0xdb')],'html':_0x22e566['body'],'headers':{'Date':moment(_0x22e566[_0xf377('0x73')])[_0xf377('0xc6')](_0xf377('0xe0'))},'attachments':[]};if(_0x22e566['cc']){_0xa224b[_0xf377('0xe1')]['Cc']=_0x22e566['cc'];}if(_0x22e566[_0xf377('0xda')]){_0xa224b[_0xf377('0xe1')]['Bcc']=_0x22e566['bcc'];}return new BPromise(function(_0xbe704f,_0x4fece3){if(_0x22e566['Attachments']){for(var _0x6f08c1=0x0;_0x6f08c1<_0x22e566[_0xf377('0xd9')][_0xf377('0x61')];_0x6f08c1++){var _0x13379b=_0x22e566[_0xf377('0xd9')][_0x6f08c1];var _0x37da53=path[_0xf377('0xd3')](_0x38ed10,_0x13379b[_0xf377('0xe2')]);if(fs['existsSync'](_0x37da53)){_0xa224b[_0xf377('0xd7')][_0xf377('0x2f')]({'name':_0x13379b[_0xf377('0x2b')],'contentType':_0x13379b[_0xf377('0x3a')],'data':fs[_0xf377('0xe3')](_0x37da53)});}}}emlformat[_0xf377('0xe4')](_0xa224b,function(_0x3c35f9,_0x1f274b){if(_0x3c35f9)return _0x4fece3(_0x3c35f9);fs[_0xf377('0xe5')](path[_0xf377('0xd3')](_0x5c7d44,util[_0xf377('0xc6')]('message%d.eml',_0x2da63d)),_0x1f274b);return _0xbe704f(_0x1f274b);});});})[_0xf377('0x27')](function(){return new BPromise(function(_0x8e2cba,_0x226598){zipdir(_0x5c7d44,{'saveTo':_0x10c630},function(_0x3d7ddd,_0xf09b2c){if(_0x3d7ddd)return _0x226598(_0x3d7ddd);return _0x8e2cba(_0xf09b2c);});})[_0xf377('0x27')](function(){return new BPromise(function(_0x431608,_0x29ef69){rimraf(_0x5c7d44,function(_0x5e9f2e){if(_0x5e9f2e)_0x29ef69(_0x5e9f2e);return _0x431608();});});})[_0xf377('0x27')](function(){return _0x3ac771[_0xf377('0xd2')](_0x10c630,_0x487f81,function(_0x318f70){if(_0x318f70){console[_0xf377('0xe6')]('err',_0x318f70);}else{fs[_0xf377('0xe7')](_0x10c630);}});});});}else{return _0x3ac771[_0xf377('0x28')](0xc8);}})['catch'](handleError(_0x3ac771,null));};
\ No newline at end of file
+var _0x6b1b=['unix','join','root','files','tmp','transcript-%d-%s.zip','attachments','Attachment','bcc','subject','Messages','get','mkdirSync','each','ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ','headers','Bcc','Attachments','basename','existsSync','readFileSync','build','message%d.eml','unlinkSync','sendStatus','rimraf','zip-dir','moment','util','path','lodash','squel','juice','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/environment','html-entities','redis','socket.io-emitter','status','json','offset','undefined','limit','count','update','then','destroy','error','stack','name','send','Users','TagIds','Tags','split','push','MailMessage','out','plainBody','-id','trimStart','catch','waiting','talking','answered','UserId','closed','unmanaged','total','index','map','MailInteraction','rawAttributes','fieldName','type','key','model','query','keys','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','filters','pick','field','color','tools_tags','select','u.fullname','ui.MailInteractionId','from','left_join','u.id\x20=\x20ui.UserId','mail_interactions','cm_contacts','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','users','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','sqlOperator','find','unreadMessages','value','`\x20=\x200','`\x20>\x200','Contact','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?','ContactId','buildExpression','text','start','Tag','forEach','union','operator','$substring','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','end','some','compact','isEmpty','concat','createdAt','$gte','parse','$lte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20=\x20?','read','having','`unreadMessages`\x20=\x200','`unreadMessages`\x20>\x200','tag','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','filter','isNumeric','i.id\x20LIKE\x20?','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','DESC','t.id\x20IN\x20?','resolve','MailAccountId','i.MailAccountId\x20IS\x20NOT\x20NULL','user','role','getMailAccounts','i.MailAccountId\x20IS\x20NULL','i.MailAccountId\x20IN\x20?','agent','sequelize','toString','keyBy','merge','a.key','Account.key','a.mandatoryDisposition','Account.mandatoryDisposition','i.createdAt','i.updatedAt','i.closedAt','i.lastMsgDirection','i.subject','i.disposition','i.thirdDisposition','i.substatus','c.firstName','Contact.firstName','c.lastName','Contact.lastName','c.email','Contact.email','c.phone','Contact.mobile','c.fax','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','MailInteractionId','findOne','enableEmailPreview','all','rows','params','include','options','create','body','describe','addMessage','ids','omit','getMessages','format','YYYY-MM-DD\x20HH:mm:ss','includeAll','findAll','inlineCss','true','addTags','setTags','spread','removeTags','download'];(function(_0x1c8c28,_0x3ee093){var _0x1f59b4=function(_0x29bcc0){while(--_0x29bcc0){_0x1c8c28['push'](_0x1c8c28['shift']());}};_0x1f59b4(++_0x3ee093);}(_0x6b1b,0x1e7));var _0xb6b1=function(_0x4e6ae6,_0x49dba6){_0x4e6ae6=_0x4e6ae6-0x0;var _0x23c108=_0x6b1b[_0x4e6ae6];return _0x23c108;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xb6b1('0x0'));var zipdir=require(_0xb6b1('0x1'));var moment=require(_0xb6b1('0x2'));var BPromise=require('bluebird');var util=require(_0xb6b1('0x3'));var path=require(_0xb6b1('0x4'));var fs=require('fs');var _=require(_0xb6b1('0x5'));var squel=require(_0xb6b1('0x6'));var juice=require(_0xb6b1('0x7'));var Redis=require(_0xb6b1('0x8'));var qs=require(_0xb6b1('0x9'));var as=require(_0xb6b1('0xa'));var logger=require(_0xb6b1('0xb'))(_0xb6b1('0xc'));var config=require(_0xb6b1('0xd'));var db=require('../../mysqldb')['db'];var htmlEntities=require(_0xb6b1('0xe'));config['redis']=_['defaults'](config[_0xb6b1('0xf')],{'host':'localhost','port':0x18eb});var socket=require(_0xb6b1('0x10'))(new Redis(config['redis']));require('./mailInteraction.socket')['register'](socket);function respondWithStatusCode(_0x593218,_0x1f8f10){_0x1f8f10=_0x1f8f10||0xcc;return function(_0x1cec84){if(_0x1cec84){return _0x593218['sendStatus'](_0x1f8f10);}return _0x593218[_0xb6b1('0x11')](_0x1f8f10)['end']();};}function respondWithResult(_0x5c5837,_0x406dce){_0x406dce=_0x406dce||0xc8;return function(_0x2e5256){if(_0x2e5256){return _0x5c5837[_0xb6b1('0x11')](_0x406dce)[_0xb6b1('0x12')](_0x2e5256);}};}function respondWithFilteredResult(_0x23881d,_0x18f6b5){return function(_0x360fc7){if(_0x360fc7){var _0x429d0d=typeof _0x18f6b5[_0xb6b1('0x13')]===_0xb6b1('0x14')&&typeof _0x18f6b5[_0xb6b1('0x15')]===_0xb6b1('0x14');var _0x4f770a=_0x360fc7['count'];var _0x513207=_0x429d0d?0x0:_0x18f6b5['offset'];var _0xee229d=_0x429d0d?_0x360fc7[_0xb6b1('0x16')]:_0x18f6b5[_0xb6b1('0x13')]+_0x18f6b5[_0xb6b1('0x15')];var _0x32e395;if(_0xee229d>=_0x4f770a){_0xee229d=_0x4f770a;_0x32e395=0xc8;}else{_0x32e395=0xce;}_0x23881d[_0xb6b1('0x11')](_0x32e395);return _0x23881d['set']('Content-Range',_0x513207+'-'+_0xee229d+'/'+_0x4f770a)[_0xb6b1('0x12')](_0x360fc7);}return null;};}function saveUpdates(_0x15456d){return function(_0x16d969){if(_0x16d969){return _0x16d969[_0xb6b1('0x17')](_0x15456d)[_0xb6b1('0x18')](function(_0x3fc9b1){return _0x3fc9b1;});}return null;};}function removeEntity(_0x5ba14d){return function(_0x4e132a){if(_0x4e132a){return _0x4e132a[_0xb6b1('0x19')]()[_0xb6b1('0x18')](function(){_0x5ba14d['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0xfc247a){return function(_0x5c8529){if(!_0x5c8529){_0xfc247a['sendStatus'](0x194);}return _0x5c8529;};}function handleError(_0x232157,_0x2086ea){_0x2086ea=_0x2086ea||0x1f4;return function(_0x36ac63){logger[_0xb6b1('0x1a')](_0x36ac63[_0xb6b1('0x1b')]);if(_0x36ac63[_0xb6b1('0x1c')]){delete _0x36ac63[_0xb6b1('0x1c')];}_0x232157[_0xb6b1('0x11')](_0x2086ea)[_0xb6b1('0x1d')](_0x36ac63);};}function getInteractionUsers(_0x20066f,_0x5069cd){return new BPromise(function(_0x214cd0,_0x4f1e2e){try{if(_0x5069cd[_0x20066f['id']]){_0x20066f[_0xb6b1('0x1e')]=_['map'](_0x5069cd[_0x20066f['id']],function(_0xdbcb77){return{'id':_0xdbcb77['id'],'fullname':_0xdbcb77['fullname']};});}}catch(_0x35a567){_0x4f1e2e(_0x35a567);}_0x214cd0(_0x20066f);});}function getInteractionTags(_0x387603,_0xac4256){return new BPromise(function(_0x178401,_0x13e841){try{if(_0x387603[_0xb6b1('0x1f')]){_0x387603[_0xb6b1('0x20')]=[];_0x387603[_0xb6b1('0x1f')][_0xb6b1('0x21')](',')['forEach'](function(_0xf40426){_0x387603['Tags'][_0xb6b1('0x22')](_0xac4256[_0xf40426]);});}delete _0x387603[_0xb6b1('0x1f')];}catch(_0x367d66){_0x13e841(_0x367d66);}_0x178401(_0x387603);});}function getLastMessageText(_0x3f8849){return new BPromise(function(_0x136fe5,_0x12f369){return db[_0xb6b1('0x23')]['findOne']({'where':{'$and':[{'MailInteractionId':_0x3f8849['id']},{'$or':[{'direction':'in'},{'$and':[{'direction':_0xb6b1('0x24')},{'secret':![]},{'UserId':{'$ne':null}}]}]}]},'attributes':[_0xb6b1('0x25')],'order':_0xb6b1('0x26'),'raw':!![]})['then'](function(_0x22beb9){if(_0x22beb9&&_0x22beb9[_0xb6b1('0x25')]){_0x3f8849['lastMsgText']=_[_0xb6b1('0x27')](_0x22beb9[_0xb6b1('0x25')]);}_0x136fe5(_0x3f8849);})[_0xb6b1('0x28')](function(_0x21bfac){_0x12f369(_0x21bfac);});});}function updateMailInteraction(_0x3ead6b,_0x326c5f,_0x4d29e4,_0x3cca75){return new BPromise(function(_0xff1d43,_0x4abe40){return getInteractionUsers(_0x3ead6b,_0x4d29e4)[_0xb6b1('0x18')](function(_0x4e11a1){return getInteractionTags(_0x4e11a1,_0x326c5f);})[_0xb6b1('0x18')](function(_0x242ec3){return getStateInteraction(_0x242ec3);})[_0xb6b1('0x18')](function(_0x4cad81){if(_0x3cca75){_0xff1d43(getLastMessageText(_0x4cad81));}else{_0xff1d43(_0x4cad81);}})[_0xb6b1('0x28')](function(_0x2dd9e2){_0x4abe40(_0x2dd9e2);});});}function getStateInteraction(_0x59efdc){return new BPromise(function(_0x203d8e){_0x59efdc[_0xb6b1('0x29')]=0x0;_0x59efdc[_0xb6b1('0x2a')]=0x0;_0x59efdc[_0xb6b1('0x2b')]=0x0;_0x59efdc['unmanaged']=0x0;_0x59efdc['total']=0x0;if(!_0x59efdc['closed']&&!_0x59efdc[_0xb6b1('0x2c')]){_0x59efdc[_0xb6b1('0x29')]+=0x1;}if(!_0x59efdc[_0xb6b1('0x2d')]&&_0x59efdc[_0xb6b1('0x2c')]){_0x59efdc[_0xb6b1('0x2a')]+=0x1;if(_0x59efdc[_0xb6b1('0x29')]){_0x59efdc[_0xb6b1('0x29')]-=0x1;}}if(_0x59efdc[_0xb6b1('0x2d')]&&_0x59efdc[_0xb6b1('0x2c')]){_0x59efdc[_0xb6b1('0x2b')]+=0x1;if(_0x59efdc[_0xb6b1('0x2a')]){_0x59efdc[_0xb6b1('0x2a')]-=0x1;}}if(_0x59efdc['closed']&&!_0x59efdc[_0xb6b1('0x2c')]){_0x59efdc[_0xb6b1('0x2e')]+=0x1;if(_0x59efdc[_0xb6b1('0x29')]){_0x59efdc[_0xb6b1('0x29')]-=0x1;}}_0x59efdc[_0xb6b1('0x2f')]+=0x1;_0x203d8e(_0x59efdc);});}exports[_0xb6b1('0x30')]=function(_0xfe126,_0x3df192){var _0x33dc30={},_0x276801={},_0x44a61a={'count':0x0,'rows':[]};var _0x56470a=_[_0xb6b1('0x31')](db[_0xb6b1('0x32')][_0xb6b1('0x33')],function(_0x2d6b2b){return{'name':_0x2d6b2b[_0xb6b1('0x34')],'type':_0x2d6b2b[_0xb6b1('0x35')][_0xb6b1('0x36')]};});_0x276801[_0xb6b1('0x37')]=_['map'](_0x56470a,'name');_0x276801[_0xb6b1('0x38')]=_[_0xb6b1('0x39')](_0xfe126[_0xb6b1('0x38')]);_0x276801['filters']=_[_0xb6b1('0x3a')](_0x276801[_0xb6b1('0x37')],_0x276801[_0xb6b1('0x38')]);_0x33dc30[_0xb6b1('0x3b')]=_[_0xb6b1('0x3a')](_0x276801[_0xb6b1('0x37')],qs[_0xb6b1('0x3c')](_0xfe126[_0xb6b1('0x38')]['fields']));_0x33dc30[_0xb6b1('0x3b')]=_0x33dc30['attributes'][_0xb6b1('0x3d')]?_0x33dc30[_0xb6b1('0x3b')]:_0x276801[_0xb6b1('0x37')];if(!_0xfe126[_0xb6b1('0x38')][_0xb6b1('0x3e')](_0xb6b1('0x3f'))){_0x33dc30['limit']=qs[_0xb6b1('0x15')](_0xfe126[_0xb6b1('0x38')]['limit']);_0x33dc30[_0xb6b1('0x13')]=qs['offset'](_0xfe126[_0xb6b1('0x38')][_0xb6b1('0x13')]);}_0x33dc30[_0xb6b1('0x40')]=qs[_0xb6b1('0x41')](_0xfe126[_0xb6b1('0x38')][_0xb6b1('0x41')]);_0x33dc30[_0xb6b1('0x42')]=qs[_0xb6b1('0x43')](_[_0xb6b1('0x44')](_0xfe126['query'],_0x276801['filters']),_0x56470a);var _0x3826bd=[];var _0x2c00fb=squel['select']()[_0xb6b1('0x45')]('id')[_0xb6b1('0x45')](_0xb6b1('0x1c'))[_0xb6b1('0x45')](_0xb6b1('0x46'))['from'](_0xb6b1('0x47'));var _0x1f4881=squel[_0xb6b1('0x48')]()[_0xb6b1('0x45')]('u.id')['field'](_0xb6b1('0x49'))['field'](_0xb6b1('0x4a'))[_0xb6b1('0x4b')]('user_has_mail_interactions','ui')[_0xb6b1('0x4c')]('users','u',_0xb6b1('0x4d'));var _0x7d4763=squel[_0xb6b1('0x48')]()[_0xb6b1('0x4b')](_0xb6b1('0x4e'),'i')[_0xb6b1('0x4c')](_0xb6b1('0x4f'),'c',_0xb6b1('0x50'))[_0xb6b1('0x4c')](_0xb6b1('0x51'),'o','o.id\x20=\x20i.UserId')[_0xb6b1('0x4c')](_0xb6b1('0x52'),'a',_0xb6b1('0x53'))[_0xb6b1('0x4c')](_0xb6b1('0x54'),'me',_0xb6b1('0x55'))[_0xb6b1('0x4c')](_0xb6b1('0x56'),'it',_0xb6b1('0x57'))['left_join'](_0xb6b1('0x47'),'t','t.id\x20=\x20it.TagId');var _0x5adb1c=squel[_0xb6b1('0x58')]();var _0x2123f5=[];var _0x5be7bf=squel[_0xb6b1('0x58')]();var _0x323231;if(_0xfe126[_0xb6b1('0x38')]['search']){_0x323231=as[_0xb6b1('0x59')](_0xfe126['query']['search']);var _0x239de5=_0x323231[_0xb6b1('0x5a')];for(var _0x49eaf4=0x0;_0x49eaf4<_0x323231['conditions']['length'];_0x49eaf4++){var _0x2e7af7=_0x323231['conditions'][_0x49eaf4];var _0x54c88f='i';var _0x47e64e=_[_0xb6b1('0x5b')](_0x56470a,[_0xb6b1('0x1c'),_0x2e7af7[_0xb6b1('0x45')]]);if(!_0x47e64e){switch(_0x2e7af7[_0xb6b1('0x45')]){case _0xb6b1('0x5c'):if(_0x2e7af7[_0xb6b1('0x5d')]==0x1){_0x7d4763['having']('`'+_0x2e7af7[_0xb6b1('0x45')]+_0xb6b1('0x5e'));}else{_0x7d4763['having']('`'+_0x2e7af7['field']+_0xb6b1('0x5f'));}break;case _0xb6b1('0x60'):if(_0x2e7af7['operator']==='$substring'){if(_0x2e7af7[_0xb6b1('0x5d')]['split']('\x20')[_0xb6b1('0x3d')]>0x1){_0x5adb1c[_0x239de5](_0xb6b1('0x61'),qs['getFullTextValue'](_0x2e7af7[_0xb6b1('0x5d')]),null);}else{var _0x30f8e5='%'+_0x2e7af7[_0xb6b1('0x5d')]+'%';_0x5adb1c[_0x239de5](_0xb6b1('0x62'),_0x30f8e5,_0x30f8e5,_0x30f8e5);}}else{_0x47e64e=_[_0xb6b1('0x5b')](_0x56470a,[_0xb6b1('0x1c'),_0xb6b1('0x63')]);_0x2e7af7[_0xb6b1('0x45')]=_0xb6b1('0x63');_0x55f565=as[_0xb6b1('0x64')](_0x54c88f,_0x47e64e['type'],_0x2e7af7);_0x5adb1c[_0x239de5](_0x55f565[_0xb6b1('0x65')],_0x55f565[_0xb6b1('0x5d')][_0xb6b1('0x66')],_0x55f565[_0xb6b1('0x5d')]['end']);}break;case _0xb6b1('0x67'):var _0xce50c3=_0x2e7af7[_0xb6b1('0x5d')][_0xb6b1('0x21')](',')[_0xb6b1('0x31')](function(_0x676c89){return Number(_0x676c89);});_0xce50c3[_0xb6b1('0x68')](function(_0x4e34ef){_0x5be7bf['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x4e34ef+',%');});_0x2123f5=_[_0xb6b1('0x69')](_0x2123f5,_0xce50c3);break;case'User':if(_0x2e7af7[_0xb6b1('0x6a')]===_0xb6b1('0x6b')){_0x5adb1c[_0x239de5](_0xb6b1('0x6c'),'%'+_0x2e7af7['value']+'%',null);}else{_0x47e64e=_[_0xb6b1('0x5b')](_0x56470a,[_0xb6b1('0x1c'),_0xb6b1('0x2c')]);_0x2e7af7[_0xb6b1('0x45')]=_0xb6b1('0x2c');_0x55f565=as['buildExpression'](_0x54c88f,_0x47e64e['type'],_0x2e7af7);_0x5adb1c[_0x239de5](_0x55f565[_0xb6b1('0x65')],_0x55f565[_0xb6b1('0x5d')][_0xb6b1('0x66')],_0x55f565[_0xb6b1('0x5d')][_0xb6b1('0x6d')]);}break;case _0xb6b1('0x25'):_0x55f565=as[_0xb6b1('0x64')]('me',null,_0x2e7af7);_0x5adb1c[_0x239de5](_0x55f565[_0xb6b1('0x65')],_0x55f565[_0xb6b1('0x5d')][_0xb6b1('0x66')],_0x55f565[_0xb6b1('0x5d')][_0xb6b1('0x6d')]);break;}}else{var _0x55f565=as[_0xb6b1('0x64')](_0x54c88f,_0x47e64e['type'],_0x2e7af7);_0x5adb1c[_0x239de5](_0x55f565[_0xb6b1('0x65')],_0x55f565[_0xb6b1('0x5d')][_0xb6b1('0x66')],_0x55f565['value'][_0xb6b1('0x6d')]);}}}else{var _0x4c795a=_(_0xfe126['query'])[_0xb6b1('0x39')]()['map'](function(_0x462175){return _[_0xb6b1('0x6e')](_0x56470a,['name',_0x462175])?_0x462175:undefined;})[_0xb6b1('0x6f')]()['value']();if(!_[_0xb6b1('0x70')](_0x4c795a)){_0x4c795a[_0xb6b1('0x68')](function(_0x2b280e){if(_0x2b280e==='MailAccountId'){_0x7d4763[_0xb6b1('0x42')]('i.MailAccountId\x20IN\x20?',[][_0xb6b1('0x71')](_0xfe126[_0xb6b1('0x38')][_0x2b280e]));}else if(_0x2b280e===_0xb6b1('0x72')){var _0xa740a5=JSON['parse'](_0xfe126[_0xb6b1('0x38')][_0x2b280e])[_0xb6b1('0x73')];var _0x3e663d=JSON[_0xb6b1('0x74')](_0xfe126[_0xb6b1('0x38')][_0x2b280e])[_0xb6b1('0x75')];_0x7d4763['where'](_0xb6b1('0x76'),_0xa740a5,_0x3e663d);}else{if(_0xfe126[_0xb6b1('0x38')][_0x2b280e]===_0xb6b1('0x77')){_0x7d4763[_0xb6b1('0x42')]('i.'+_0x2b280e+'\x20IS\x20NULL');}else{_0x7d4763[_0xb6b1('0x42')]('i.'+_0x2b280e+_0xb6b1('0x78'),_0xfe126['query'][_0x2b280e]);}}});}if(_0xfe126['query']['read']){if(_0xfe126['query'][_0xb6b1('0x79')]==0x1){_0x7d4763[_0xb6b1('0x7a')](_0xb6b1('0x7b'));}else{_0x7d4763[_0xb6b1('0x7a')](_0xb6b1('0x7c'));}}if(_0xfe126[_0xb6b1('0x38')][_0xb6b1('0x7d')]){_0x2123f5=_['isArray'](_0xfe126[_0xb6b1('0x38')]['tag'])?_0xfe126['query'][_0xb6b1('0x7d')]:new Array(_0xfe126[_0xb6b1('0x38')]['tag']);_0x2123f5[_0xb6b1('0x68')](function(_0x394b82){_0x5be7bf['or'](_0xb6b1('0x7e'),'%,'+_0x394b82+',%');});}if(_0xfe126[_0xb6b1('0x38')][_0xb6b1('0x7f')]){var _0x5516c7=_0xfe126[_0xb6b1('0x38')][_0xb6b1('0x7f')]['replace']('\x5c','\x5c\x5c')['replace'](/'/g,'\x27\x27');if(qs[_0xb6b1('0x80')](_0x5516c7)){_0x5adb1c['or'](_0xb6b1('0x81'),_0x5516c7+'%');}else if(qs[_0xb6b1('0x82')](_0x5516c7)){_0x5adb1c['or'](_0xb6b1('0x83'),_0x5516c7+'%');}else{_0x5adb1c['or'](_0xb6b1('0x84'),qs[_0xb6b1('0x85')](_0x5516c7))['or'](_0xb6b1('0x86'),qs[_0xb6b1('0x85')](_0x5516c7));}}}_0x7d4763[_0xb6b1('0x42')](_0x5adb1c);_0x7d4763['group'](_0xb6b1('0x87'));var _0x57fd39={'type':db[_0xb6b1('0x88')][_0xb6b1('0x89')][_0xb6b1('0x8a')],'raw':!![]};var _0x500945=_0x7d4763[_0xb6b1('0x8b')]();_0x500945[_0xb6b1('0x45')]('i.id');_0x500945[_0xb6b1('0x45')](_0xb6b1('0x8c'),'unreadMessages');if(_0x33dc30[_0xb6b1('0x40')]){_0x33dc30['order'][_0xb6b1('0x68')](function(_0x58da6c){var _0x300508=_0x58da6c[0x0]===_0xb6b1('0x8d')?_0x58da6c[0x0]:'i.'+_0x58da6c[0x0];_0x7d4763[_0xb6b1('0x40')](_0x300508,_0x58da6c[0x1]===_0xb6b1('0x8e')?![]:!![]);});}if(!_[_0xb6b1('0x70')](_0x2123f5)){_0x7d4763['having'](_0x5be7bf);_0x500945[_0xb6b1('0x42')](_0xb6b1('0x8f'),_0x2123f5);}BPromise[_0xb6b1('0x90')]()[_0xb6b1('0x18')](function(){if(!_0x323231){if(_0xfe126[_0xb6b1('0x38')][_0xb6b1('0x91')])return;_0x500945[_0xb6b1('0x42')](_0xb6b1('0x92'));_0x7d4763[_0xb6b1('0x42')](_0xb6b1('0x92'));return;}if(_0xfe126[_0xb6b1('0x93')][_0xb6b1('0x94')]!=='agent')return;return _0xfe126[_0xb6b1('0x93')][_0xb6b1('0x95')]({'attributes':['id'],'raw':!![]})['then'](function(_0x22ebac){if(_[_0xb6b1('0x70')](_0x22ebac)){_0x500945['where'](_0xb6b1('0x96'));_0x7d4763['where'](_0xb6b1('0x96'));}else{_0x500945['where'](_0xb6b1('0x97'),_['map'](_0x22ebac,'id'));_0x7d4763['where'](_0xb6b1('0x97'),_[_0xb6b1('0x31')](_0x22ebac,'id'));}});})['then'](function(){if(_0xfe126[_0xb6b1('0x93')][_0xb6b1('0x94')]===_0xb6b1('0x98')&&!_0x323231&&!_0xfe126[_0xb6b1('0x38')][_0xb6b1('0x91')])return[];return db[_0xb6b1('0x99')][_0xb6b1('0x38')](_0x500945[_0xb6b1('0x9a')](),_0x57fd39);})[_0xb6b1('0x18')](function(_0x267c1d){_0x44a61a[_0xb6b1('0x16')]=_0x267c1d[_0xb6b1('0x3d')];if(_0x44a61a['count']===0x0)return[];return db[_0xb6b1('0x99')][_0xb6b1('0x38')](_0x2c00fb[_0xb6b1('0x9a')](),_0x57fd39)[_0xb6b1('0x18')](function(_0x489898){_0x3826bd=_[_0xb6b1('0x9b')](_0x489898,'id');_0x57fd39=_[_0xb6b1('0x9c')](_0x57fd39,{'model':db[_0xb6b1('0x32')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0xfe126[_0xb6b1('0x38')][_0xb6b1('0x3c')]){_0x33dc30[_0xb6b1('0x3b')]['forEach'](function(_0x3954dd){_0x7d4763[_0xb6b1('0x45')]('i.'+_0x3954dd);});}else{_0x7d4763[_0xb6b1('0x45')](_0xb6b1('0x8c'),_0xb6b1('0x5c'));_0x7d4763[_0xb6b1('0x45')](_0xb6b1('0x9d'),_0xb6b1('0x9e'));_0x7d4763[_0xb6b1('0x45')](_0xb6b1('0x9f'),_0xb6b1('0xa0'));_0x7d4763[_0xb6b1('0x45')]('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',_0xb6b1('0x8d'));_0x7d4763[_0xb6b1('0x45')](_0xb6b1('0x87'));_0x7d4763[_0xb6b1('0x45')](_0xb6b1('0xa1'));_0x7d4763[_0xb6b1('0x45')](_0xb6b1('0xa2'));_0x7d4763[_0xb6b1('0x45')]('i.closed');_0x7d4763[_0xb6b1('0x45')](_0xb6b1('0xa3'));_0x7d4763[_0xb6b1('0x45')]('i.attach');_0x7d4763[_0xb6b1('0x45')]('i.lastMsgAt');_0x7d4763['field'](_0xb6b1('0xa4'));_0x7d4763[_0xb6b1('0x45')](_0xb6b1('0xa5'));_0x7d4763[_0xb6b1('0x45')](_0xb6b1('0xa6'));_0x7d4763[_0xb6b1('0x45')]('i.secondDisposition');_0x7d4763[_0xb6b1('0x45')](_0xb6b1('0xa7'));_0x7d4763[_0xb6b1('0x45')](_0xb6b1('0xa8'));_0x7d4763['field']('i.to');_0x7d4763[_0xb6b1('0x45')]('i.ContactId');_0x7d4763[_0xb6b1('0x45')]('i.MailAccountId');_0x7d4763[_0xb6b1('0x45')]('i.UserId');_0x7d4763['field'](_0xb6b1('0xa9'),_0xb6b1('0xaa'));_0x7d4763[_0xb6b1('0x45')](_0xb6b1('0xab'),_0xb6b1('0xac'));_0x7d4763['field'](_0xb6b1('0xad'),_0xb6b1('0xae'));_0x7d4763[_0xb6b1('0x45')](_0xb6b1('0xaf'),'Contact.phone');_0x7d4763[_0xb6b1('0x45')]('c.mobile',_0xb6b1('0xb0'));_0x7d4763['field'](_0xb6b1('0xb1'),'Contact.fax');_0x7d4763['field']('o.fullname','Owner.fullname');_0x7d4763[_0xb6b1('0x45')]('o.internal',_0xb6b1('0xb2'));_0x7d4763[_0xb6b1('0x45')](_0xb6b1('0xb3'),_0xb6b1('0x1f'));}if(_0x33dc30['limit'])_0x7d4763[_0xb6b1('0x15')](_0x33dc30[_0xb6b1('0x15')]);if(_0x33dc30['offset'])_0x7d4763['offset'](_0x33dc30['offset']);return db[_0xb6b1('0x99')]['query'](_0x7d4763[_0xb6b1('0x9a')](),_0x57fd39);})['then'](function(_0x3173d2){if(_0x3173d2['length']>0x0)_0x1f4881[_0xb6b1('0x42')]('ui.MailInteractionId\x20IN\x20?',_['map'](_0x3173d2,'id'));return db[_0xb6b1('0x99')][_0xb6b1('0x38')](_0x1f4881[_0xb6b1('0x9a')](),_0x57fd39)[_0xb6b1('0x18')](function(_0xb25776){var _0x2ca465=_['groupBy'](_0xb25776,_0xb6b1('0xb4'));var _0x1dcf93=[];return db['Setting'][_0xb6b1('0xb5')]({'attributes':[_0xb6b1('0xb6')],'raw':!![]})[_0xb6b1('0x18')](function(_0x5236a3){var _0x36f39e=_0x5236a3[_0xb6b1('0xb6')];_0x3173d2[_0xb6b1('0x68')](function(_0x2579c2){_0x1dcf93[_0xb6b1('0x22')](updateMailInteraction(_0x2579c2,_0x3826bd,_0x2ca465,_0x36f39e));});return BPromise[_0xb6b1('0xb7')](_0x1dcf93);});});});})[_0xb6b1('0x18')](function(_0x24c4db){_0x44a61a[_0xb6b1('0xb8')]=_0x24c4db;return _0x44a61a;})[_0xb6b1('0x18')](respondWithFilteredResult(_0x3df192,_0x33dc30))[_0xb6b1('0x28')](handleError(_0x3df192,null));};exports['show']=function(_0x59b19f,_0x54fb1e){var _0x160166={'raw':![],'where':{'id':_0x59b19f[_0xb6b1('0xb9')]['id']}},_0x535d47={};_0x535d47[_0xb6b1('0x37')]=_[_0xb6b1('0x39')](db[_0xb6b1('0x32')]['rawAttributes']);_0x535d47[_0xb6b1('0x38')]=_['keys'](_0x59b19f['query']);_0x535d47['filters']=_[_0xb6b1('0x3a')](_0x535d47[_0xb6b1('0x37')],_0x535d47[_0xb6b1('0x38')]);_0x160166[_0xb6b1('0x3b')]=_[_0xb6b1('0x3a')](_0x535d47[_0xb6b1('0x37')],qs[_0xb6b1('0x3c')](_0x59b19f['query']['fields']));_0x160166[_0xb6b1('0x3b')]=_0x160166['attributes'][_0xb6b1('0x3d')]?_0x160166['attributes']:_0x535d47['model'];if(_0x59b19f['query']['includeAll']){_0x160166[_0xb6b1('0xba')]=[{'all':!![]}];}_0x160166=_[_0xb6b1('0x9c')]({},_0x160166,_0x59b19f[_0xb6b1('0xbb')]);return db[_0xb6b1('0x32')][_0xb6b1('0x5b')](_0x160166)['then'](handleEntityNotFound(_0x54fb1e,null))[_0xb6b1('0x18')](respondWithResult(_0x54fb1e,null))['catch'](handleError(_0x54fb1e,null));};exports[_0xb6b1('0xbc')]=function(_0x28b252,_0x235ae7){return db[_0xb6b1('0x32')][_0xb6b1('0xbc')](_0x28b252[_0xb6b1('0xbd')],{})[_0xb6b1('0x18')](respondWithResult(_0x235ae7,0xc9))[_0xb6b1('0x28')](handleError(_0x235ae7,null));};exports[_0xb6b1('0x17')]=function(_0x49bbbb,_0x193c0a){if(_0x49bbbb[_0xb6b1('0xbd')]['id']){delete _0x49bbbb[_0xb6b1('0xbd')]['id'];}return db[_0xb6b1('0x32')][_0xb6b1('0x5b')]({'where':{'id':_0x49bbbb[_0xb6b1('0xb9')]['id']}})[_0xb6b1('0x18')](handleEntityNotFound(_0x193c0a,null))[_0xb6b1('0x18')](saveUpdates(_0x49bbbb['body'],null))['then'](respondWithResult(_0x193c0a,null))['catch'](handleError(_0x193c0a,null));};exports[_0xb6b1('0x19')]=function(_0x271599,_0x2a9fe9){return db['MailInteraction']['find']({'where':{'id':_0x271599['params']['id']}})[_0xb6b1('0x18')](handleEntityNotFound(_0x2a9fe9,null))['then'](removeEntity(_0x2a9fe9,null))[_0xb6b1('0x28')](handleError(_0x2a9fe9,null));};exports[_0xb6b1('0xbe')]=function(_0x434c1c,_0x4ac5ed){return db[_0xb6b1('0x32')]['describe']()[_0xb6b1('0x18')](respondWithResult(_0x4ac5ed,null))[_0xb6b1('0x28')](handleError(_0x4ac5ed,null));};exports[_0xb6b1('0xbf')]=function(_0x840ed1,_0x5576bf){return db[_0xb6b1('0x23')][_0xb6b1('0x5b')]({'where':{'id':_0x840ed1[_0xb6b1('0xb9')]['id']}})[_0xb6b1('0x18')](handleEntityNotFound(_0x5576bf,null))['then'](function(_0x1f27b6){if(_0x1f27b6){return _0x1f27b6[_0xb6b1('0xbf')](_0x840ed1['body'][_0xb6b1('0xc0')],_[_0xb6b1('0xc1')](_0x840ed1[_0xb6b1('0xbd')],['ids','id'])||{});}})[_0xb6b1('0x18')](respondWithResult(_0x5576bf,null))[_0xb6b1('0x28')](handleError(_0x5576bf,null));};exports[_0xb6b1('0xc2')]=function(_0x2e95ca,_0x257e05){var _0xa31640={'raw':![],'where':{}};var _0x1bf97a={};var _0x58244e={'count':0x0,'rows':[]};return db[_0xb6b1('0x32')][_0xb6b1('0xb5')]({'where':{'id':_0x2e95ca['params']['id']}})['then'](handleEntityNotFound(_0x257e05,null))[_0xb6b1('0x18')](function(_0x2d3ce6){if(_0x2d3ce6){_0x1bf97a[_0xb6b1('0x37')]=_['keys'](db[_0xb6b1('0x23')]['rawAttributes']);_0x1bf97a[_0xb6b1('0x38')]=_['keys'](_0x2e95ca[_0xb6b1('0x38')]);_0x1bf97a[_0xb6b1('0x43')]=_[_0xb6b1('0x3a')](_0x1bf97a[_0xb6b1('0x37')],_0x1bf97a[_0xb6b1('0x38')]);_0xa31640[_0xb6b1('0x3b')]=_['intersection'](_0x1bf97a['model'],qs[_0xb6b1('0x3c')](_0x2e95ca[_0xb6b1('0x38')]['fields']));_0xa31640[_0xb6b1('0x3b')]=_0xa31640[_0xb6b1('0x3b')][_0xb6b1('0x3d')]?_0xa31640[_0xb6b1('0x3b')]:_0x1bf97a[_0xb6b1('0x37')];if(!_0x2e95ca[_0xb6b1('0x38')][_0xb6b1('0x3e')](_0xb6b1('0x3f'))){_0xa31640[_0xb6b1('0x15')]=qs[_0xb6b1('0x15')](_0x2e95ca['query'][_0xb6b1('0x15')]);_0xa31640[_0xb6b1('0x13')]=qs['offset'](_0x2e95ca[_0xb6b1('0x38')]['offset']);}_0xa31640[_0xb6b1('0x40')]=qs[_0xb6b1('0x41')](_0x2e95ca['query'][_0xb6b1('0x41')]);_0xa31640['where']=qs['filters'](_['pick'](_0x2e95ca[_0xb6b1('0x38')],_0x1bf97a['filters']));_0xa31640[_0xb6b1('0x42')][_0xb6b1('0xb4')]=_0x2d3ce6['id'];if(_0x2e95ca[_0xb6b1('0x38')][_0xb6b1('0x7f')]){_0xa31640['where']=_[_0xb6b1('0x9c')](_0xa31640[_0xb6b1('0x42')],{'$or':_[_0xb6b1('0x31')](_0xa31640['attributes'],function(_0x1e2137){var _0x2b6ddf={};_0x2b6ddf[_0x1e2137]={'$like':'%'+_0x2e95ca[_0xb6b1('0x38')]['filter']+'%'};return _0x2b6ddf;})});}if(_0x2e95ca['query'][_0xb6b1('0x73')]){var _0x50406d=_0x2e95ca[_0xb6b1('0x38')][_0xb6b1('0x73')]['split'](',');var _0x555aa2={};_0x555aa2[_0x50406d[0x0]]={'$gte':moment(_0x50406d[0x1])[_0xb6b1('0xc3')](_0xb6b1('0xc4'))};_0xa31640[_0xb6b1('0x42')]=_[_0xb6b1('0x9c')](_0xa31640[_0xb6b1('0x42')],_0x555aa2);}_0xa31640=_[_0xb6b1('0x9c')]({},_0xa31640,_0x2e95ca[_0xb6b1('0xbb')]);return db[_0xb6b1('0x23')][_0xb6b1('0x16')]({'where':_0xa31640[_0xb6b1('0x42')]})[_0xb6b1('0x18')](function(_0x173eee){_0x58244e['count']=_0x173eee;if(_0x2e95ca[_0xb6b1('0x38')][_0xb6b1('0xc5')]){_0xa31640[_0xb6b1('0xba')]=[{'all':!![]}];}return db['MailMessage'][_0xb6b1('0xc6')](_0xa31640);})[_0xb6b1('0x18')](function(_0x564a97){if(_0x2e95ca[_0xb6b1('0x38')][_0xb6b1('0xc7')]===_0xb6b1('0xc8')){for(var _0x588be2=0x0;_0x588be2<_0x564a97['length'];_0x588be2++){_0x564a97[_0x588be2][_0xb6b1('0xbd')]=juice(_0x564a97[_0x588be2][_0xb6b1('0xbd')]);}}_0x58244e[_0xb6b1('0xb8')]=_0x564a97;return _0x58244e;});}})['then'](respondWithFilteredResult(_0x257e05,_0xa31640))['catch'](handleError(_0x257e05,null));};exports[_0xb6b1('0xc9')]=function(_0x129648,_0x9131e9){return db[_0xb6b1('0x32')][_0xb6b1('0x5b')]({'where':{'id':_0x129648['params']['id']}})['then'](handleEntityNotFound(_0x9131e9,null))[_0xb6b1('0x18')](function(_0x1f5381){if(_0x1f5381){return _0x1f5381[_0xb6b1('0xca')](_0x129648[_0xb6b1('0xbd')][_0xb6b1('0xc0')],_[_0xb6b1('0xc1')](_0x129648[_0xb6b1('0xbd')],['ids','id'])||{})[_0xb6b1('0xcb')](function(){return db[_0xb6b1('0x67')][_0xb6b1('0xc6')]({'attributes':['id',_0xb6b1('0x1c'),_0xb6b1('0x46')],'where':{'id':_0x129648[_0xb6b1('0xbd')][_0xb6b1('0xc0')]}});})['then'](function(_0x5813e4){socket['emit']('mailInteractionTags:save',{'id':Number(_0x129648[_0xb6b1('0xb9')]['id']),'tags':_0x5813e4||[]});return{'id':Number(_0x129648['params']['id']),'tags':_0x5813e4||[]};});}})['then'](respondWithResult(_0x9131e9,null))[_0xb6b1('0x28')](handleError(_0x9131e9,null));};exports['removeTags']=function(_0xd0eaa4,_0x51a36a){return db[_0xb6b1('0x32')]['find']({'where':{'id':_0xd0eaa4[_0xb6b1('0xb9')]['id']}})[_0xb6b1('0x18')](handleEntityNotFound(_0x51a36a,null))[_0xb6b1('0x18')](function(_0x3d081e){if(_0x3d081e){return _0x3d081e[_0xb6b1('0xcc')](_0xd0eaa4['query']['ids']);}})['then'](respondWithStatusCode(_0x51a36a,null))[_0xb6b1('0x28')](handleError(_0x51a36a,null));};exports[_0xb6b1('0xcd')]=function(_0x1bc26b,_0x286c65){var _0x24a136=moment()[_0xb6b1('0xce')]()[_0xb6b1('0x9a')]();var _0x4a7c67=path[_0xb6b1('0xcf')](config[_0xb6b1('0xd0')],'server',_0xb6b1('0xd1'),_0xb6b1('0xd2'));var _0x56b5c7=path[_0xb6b1('0xcf')](config[_0xb6b1('0xd0')],'server',_0xb6b1('0xd1'),'attachments');var _0x18be57=path[_0xb6b1('0xcf')](_0x4a7c67,_0x24a136);var _0x5b9247=util[_0xb6b1('0xc3')](_0xb6b1('0xd3'),_0x1bc26b[_0xb6b1('0xb9')]['id'],_0x24a136);var _0x1ffd3b=path[_0xb6b1('0xcf')](_0x4a7c67,_0x5b9247);var _0x6dec10=[];if(_0x1bc26b[_0xb6b1('0x38')][_0xb6b1('0xd4')]){_0x6dec10[_0xb6b1('0x22')]({'model':db[_0xb6b1('0xd5')],'as':'Attachments','raw':!![]});}var _0xb2e401=[{'model':db[_0xb6b1('0x23')],'as':'Messages','attributes':['id','body',_0xb6b1('0x4b'),'to','cc',_0xb6b1('0xd6'),_0xb6b1('0xd7'),'createdAt'],'where':{'secret':![]},'order':qs[_0xb6b1('0x41')]('id'),'include':_0x6dec10}];return db[_0xb6b1('0x32')][_0xb6b1('0x5b')]({'where':{'id':_0x1bc26b[_0xb6b1('0xb9')]['id']},'include':_0xb2e401})['then'](handleEntityNotFound(_0x286c65,null))['then'](function(_0x737fa0){if(_0x737fa0&&_0x737fa0[_0xb6b1('0xd8')]){var _0x288f12=_0x737fa0[_0xb6b1('0xd9')]({'plain':!![]});fs[_0xb6b1('0xda')](_0x18be57);return BPromise[_0xb6b1('0xdb')](_0x288f12[_0xb6b1('0xd8')],function(_0x570d67,_0x409aad){var _0x2ab39a={'from':_0x570d67[_0xb6b1('0x4b')],'to':_0x570d67['to'],'subject':_0x570d67[_0xb6b1('0xd7')],'html':htmlEntities['decode'](_0x570d67[_0xb6b1('0xbd')]),'headers':{'Date':moment(_0x570d67[_0xb6b1('0x72')])[_0xb6b1('0xc3')](_0xb6b1('0xdc'))},'attachments':[]};if(_0x570d67['cc']){_0x2ab39a['headers']['Cc']=_0x570d67['cc'];}if(_0x570d67[_0xb6b1('0xd6')]){_0x2ab39a[_0xb6b1('0xdd')][_0xb6b1('0xde')]=_0x570d67[_0xb6b1('0xd6')];}return new BPromise(function(_0x3cdd09,_0x37a71b){if(_0x570d67['Attachments']){for(var _0x8486dc=0x0;_0x8486dc<_0x570d67[_0xb6b1('0xdf')][_0xb6b1('0x3d')];_0x8486dc++){var _0x18c0fa=_0x570d67[_0xb6b1('0xdf')][_0x8486dc];var _0x20eeed=path[_0xb6b1('0xcf')](_0x56b5c7,_0x18c0fa[_0xb6b1('0xe0')]);if(fs[_0xb6b1('0xe1')](_0x20eeed)){_0x2ab39a[_0xb6b1('0xd4')][_0xb6b1('0x22')]({'name':_0x18c0fa['name'],'contentType':_0x18c0fa['type'],'data':fs[_0xb6b1('0xe2')](_0x20eeed)});}}}emlformat[_0xb6b1('0xe3')](_0x2ab39a,function(_0x2d8d1f,_0x25a2c4){if(_0x2d8d1f)return _0x37a71b(_0x2d8d1f);fs['writeFileSync'](path['join'](_0x18be57,util['format'](_0xb6b1('0xe4'),_0x409aad)),_0x25a2c4);return _0x3cdd09(_0x25a2c4);});});})['then'](function(){return new BPromise(function(_0x2f2ba2,_0x2414dc){zipdir(_0x18be57,{'saveTo':_0x1ffd3b},function(_0xf8e6b0,_0x2151a9){if(_0xf8e6b0)return _0x2414dc(_0xf8e6b0);return _0x2f2ba2(_0x2151a9);});})['then'](function(){return new BPromise(function(_0x530a16,_0x142d71){rimraf(_0x18be57,function(_0x1085c5){if(_0x1085c5)_0x142d71(_0x1085c5);return _0x530a16();});});})['then'](function(){return _0x286c65[_0xb6b1('0xcd')](_0x1ffd3b,_0x5b9247,function(_0x4c166f){if(!_0x4c166f)fs[_0xb6b1('0xe5')](_0x1ffd3b);});});});}else{return _0x286c65[_0xb6b1('0xe6')](0xc8);}})['catch'](handleError(_0x286c65,null));};
\ No newline at end of file