Built motion from commit 0900f080.|2.5.45
[motion2.git] / server / api / mailInteraction / mailInteraction.controller.js
index d8e7721..42bbbac 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xc1fc=['search','sqlOperator','conditions','value','`\x20=\x200','having','operator','$substring','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','getFullTextValue','c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?','ContactId','buildExpression','text','start','end','union','User','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','find','some','compact','isEmpty','i.MailAccountId\x20IN\x20?','concat','createdAt','parse','$gte','$lte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20IS\x20NULL','\x20=\x20?','read','`unreadMessages`\x20=\x200','`unreadMessages`\x20>\x200','tag','isArray','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','filter','replace','isNumeric','i.id\x20LIKE\x20?','c.email\x20LIKE\x20?','MATCH\x20(me.plainBody,\x20me.subject)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','group','i.id','Sequelize','QueryTypes','SELECT','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','unreadMessages','contactName','DESC','resolve','i.MailAccountId\x20IS\x20NOT\x20NULL','user','role','agent','getMailAccounts','i.MailAccountId\x20IS\x20NULL','MailAccountId','sequelize','toString','keyBy','merge','a.key','Account.key','a.mandatoryDisposition','Account.mandatoryDisposition','CASE\x20WHEN\x20i.to\x20IS\x20NOT\x20NULL\x20AND\x20i.to\x20<>\x20\x27\x27\x20AND\x20i.to\x20NOT\x20LIKE\x20(\x27%\x27\x20+\x20a.email\x20+\x20\x27%\x27)\x20THEN\x20SUBSTRING_INDEX(i.to,\x20\x27<\x27,\x201)\x20WHEN\x20(c.firstName\x20IS\x20NOT\x20NULL\x20AND\x20c.firstName\x20<>\x20\x27\x27)\x20OR\x20(c.lastName\x20IS\x20NOT\x20NULL\x20AND\x20c.lastName\x20<>\x20\x27\x27)\x20THEN\x20CONCAT(IFNULL(c.firstName,\x20\x27\x27),\x20\x27\x20\x27,\x20IFNULL(c.lastName,\x20\x27\x27))\x20ELSE\x20\x27Unknown\x27\x20END','i.createdAt','i.updatedAt','i.closed','i.closedAt','i.attach','i.lastMsgAt','i.lastMsgDirection','i.disposition','i.secondDisposition','i.thirdDisposition','i.to','i.ContactId','i.MailAccountId','i.UserId','c.firstName','Contact.firstName','c.lastName','Contact.lastName','Contact.email','c.phone','Contact.phone','c.fax','Contact.fax','o.fullname','Owner.fullname','o.internal','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','groupBy','MailInteractionId','Setting','enableEmailPreview','rows','show','params','includeAll','include','options','create','body','describe','ids','omit','pick','YYYY-MM-DD\x20HH:mm:ss','inlineCss','true','setTags','spread','Tag','findAll','mailInteractionTags:save','removeTags','download','unix','server','files','tmp','join','attachments','format','transcript-%d-%s.zip','Attachment','Attachments','Messages','bcc','mkdirSync','subject','headers','Bcc','basename','readFileSync','build','writeFileSync','message%d.eml','unlinkSync','rimraf','zip-dir','bluebird','util','path','lodash','squel','juice','ioredis','../../components/parsers/qs','api','../../config/environment','../../mysqldb','html-entities','redis','socket.io-emitter','./mailInteraction.socket','register','sendStatus','status','json','offset','undefined','limit','count','Content-Range','update','destroy','then','stack','name','send','Users','map','fullname','TagIds','Tags','split','forEach','push','MailMessage','findOne','-id','plainBody','lastMsgText','trimStart','catch','waiting','talking','total','closed','UserId','answered','index','MailInteraction','rawAttributes','type','key','model','keys','filters','intersection','attributes','fields','query','length','hasOwnProperty','nolimit','order','sort','where','select','field','color','tools_tags','u.id','u.fullname','ui.MailInteractionId','from','user_has_mail_interactions','left_join','users','u.id\x20=\x20ui.UserId','mail_interactions','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'];(function(_0x594e06,_0x27a143){var _0x4c9d4b=function(_0x48ae24){while(--_0x48ae24){_0x594e06['push'](_0x594e06['shift']());}};_0x4c9d4b(++_0x27a143);}(_0xc1fc,0x93));var _0xcc1f=function(_0x5cbe45,_0x43a958){_0x5cbe45=_0x5cbe45-0x0;var _0x2e64ab=_0xc1fc[_0x5cbe45];return _0x2e64ab;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xcc1f('0x0'));var zipdir=require(_0xcc1f('0x1'));var moment=require('moment');var BPromise=require(_0xcc1f('0x2'));var util=require(_0xcc1f('0x3'));var path=require(_0xcc1f('0x4'));var fs=require('fs');var _=require(_0xcc1f('0x5'));var squel=require(_0xcc1f('0x6'));var juice=require(_0xcc1f('0x7'));var Redis=require(_0xcc1f('0x8'));var qs=require(_0xcc1f('0x9'));var as=require('../../components/parsers/advancedSearch');var logger=require('../../config/logger')(_0xcc1f('0xa'));var config=require(_0xcc1f('0xb'));var db=require(_0xcc1f('0xc'))['db'];var htmlEntities=require(_0xcc1f('0xd'));config[_0xcc1f('0xe')]=_['defaults'](config['redis'],{'host':'localhost','port':0x18eb});var socket=require(_0xcc1f('0xf'))(new Redis(config[_0xcc1f('0xe')]));require(_0xcc1f('0x10'))[_0xcc1f('0x11')](socket);function respondWithStatusCode(_0x3a2625,_0x2f435a){_0x2f435a=_0x2f435a||0xcc;return function(_0x2aa49d){if(_0x2aa49d){return _0x3a2625[_0xcc1f('0x12')](_0x2f435a);}return _0x3a2625[_0xcc1f('0x13')](_0x2f435a)['end']();};}function respondWithResult(_0x232b09,_0x36dd19){_0x36dd19=_0x36dd19||0xc8;return function(_0x1807b0){if(_0x1807b0){return _0x232b09[_0xcc1f('0x13')](_0x36dd19)[_0xcc1f('0x14')](_0x1807b0);}};}function respondWithFilteredResult(_0x38d746,_0x2f237b){return function(_0x4a9723){if(_0x4a9723){var _0xf0ba72=typeof _0x2f237b[_0xcc1f('0x15')]===_0xcc1f('0x16')&&typeof _0x2f237b[_0xcc1f('0x17')]===_0xcc1f('0x16');var _0x307249=_0x4a9723[_0xcc1f('0x18')];var _0xde5222=_0xf0ba72?0x0:_0x2f237b[_0xcc1f('0x15')];var _0x7bad52=_0xf0ba72?_0x4a9723['count']:_0x2f237b['offset']+_0x2f237b[_0xcc1f('0x17')];var _0x10648f;if(_0x7bad52>=_0x307249){_0x7bad52=_0x307249;_0x10648f=0xc8;}else{_0x10648f=0xce;}_0x38d746[_0xcc1f('0x13')](_0x10648f);return _0x38d746['set'](_0xcc1f('0x19'),_0xde5222+'-'+_0x7bad52+'/'+_0x307249)['json'](_0x4a9723);}return null;};}function saveUpdates(_0x50c6ab){return function(_0xecece8){if(_0xecece8){return _0xecece8[_0xcc1f('0x1a')](_0x50c6ab)['then'](function(_0x1a17e8){return _0x1a17e8;});}return null;};}function removeEntity(_0x3a3a43){return function(_0x218066){if(_0x218066){return _0x218066[_0xcc1f('0x1b')]()[_0xcc1f('0x1c')](function(){_0x3a3a43[_0xcc1f('0x13')](0xcc)['end']();});}};}function handleEntityNotFound(_0x289c8){return function(_0x54b934){if(!_0x54b934){_0x289c8[_0xcc1f('0x12')](0x194);}return _0x54b934;};}function handleError(_0x310c2e,_0x1a00d4){_0x1a00d4=_0x1a00d4||0x1f4;return function(_0xde8dfe){logger['error'](_0xde8dfe[_0xcc1f('0x1d')]);if(_0xde8dfe[_0xcc1f('0x1e')]){delete _0xde8dfe[_0xcc1f('0x1e')];}_0x310c2e[_0xcc1f('0x13')](_0x1a00d4)[_0xcc1f('0x1f')](_0xde8dfe);};}function getInteractionUsers(_0x16ec06,_0x1f04c1){return new BPromise(function(_0x4e9cdb,_0x1939aa){try{if(_0x1f04c1[_0x16ec06['id']]){_0x16ec06[_0xcc1f('0x20')]=_[_0xcc1f('0x21')](_0x1f04c1[_0x16ec06['id']],function(_0x30a6fc){return{'id':_0x30a6fc['id'],'fullname':_0x30a6fc[_0xcc1f('0x22')]};});}}catch(_0x3d6c06){_0x1939aa(_0x3d6c06);}_0x4e9cdb(_0x16ec06);});}function getInteractionTags(_0x1d4739,_0x160d78){return new BPromise(function(_0x5457a3,_0x4461d5){try{if(_0x1d4739[_0xcc1f('0x23')]){_0x1d4739[_0xcc1f('0x24')]=[];_0x1d4739[_0xcc1f('0x23')][_0xcc1f('0x25')](',')[_0xcc1f('0x26')](function(_0x506d47){_0x1d4739[_0xcc1f('0x24')][_0xcc1f('0x27')](_0x160d78[_0x506d47]);});}delete _0x1d4739['TagIds'];}catch(_0x3bd35c){_0x4461d5(_0x3bd35c);}_0x5457a3(_0x1d4739);});}function getLastMessageText(_0x5055c3){return new BPromise(function(_0x78c04f,_0xf573ba){return db[_0xcc1f('0x28')][_0xcc1f('0x29')]({'where':{'$and':[{'MailInteractionId':_0x5055c3['id']},{'$or':[{'direction':'in'},{'$and':[{'direction':'out'},{'secret':![]},{'UserId':{'$ne':null}}]}]}]},'attributes':['plainBody'],'order':_0xcc1f('0x2a'),'raw':!![]})[_0xcc1f('0x1c')](function(_0x5e377f){if(_0x5e377f&&_0x5e377f[_0xcc1f('0x2b')]){_0x5055c3[_0xcc1f('0x2c')]=_[_0xcc1f('0x2d')](_0x5e377f[_0xcc1f('0x2b')]);}_0x78c04f(_0x5055c3);})['catch'](function(_0x329a71){_0xf573ba(_0x329a71);});});}function updateMailInteraction(_0x4370ad,_0x17cda4,_0x4bdff5,_0x15c647){return new BPromise(function(_0x393ba7,_0x677677){return getInteractionUsers(_0x4370ad,_0x4bdff5)[_0xcc1f('0x1c')](function(_0x2e0db2){return getInteractionTags(_0x2e0db2,_0x17cda4);})[_0xcc1f('0x1c')](function(_0x19f03b){return getStateInteraction(_0x19f03b);})[_0xcc1f('0x1c')](function(_0x4d4f25){if(_0x15c647){_0x393ba7(getLastMessageText(_0x4d4f25));}else{_0x393ba7(_0x4d4f25);}})[_0xcc1f('0x2e')](function(_0x38e866){_0x677677(_0x38e866);});});}function getStateInteraction(_0x56606f){return new BPromise(function(_0x2a5646){_0x56606f[_0xcc1f('0x2f')]=0x0;_0x56606f[_0xcc1f('0x30')]=0x0;_0x56606f['answered']=0x0;_0x56606f['unmanaged']=0x0;_0x56606f[_0xcc1f('0x31')]=0x0;if(!_0x56606f[_0xcc1f('0x32')]&&!_0x56606f[_0xcc1f('0x33')]){_0x56606f['waiting']+=0x1;}if(!_0x56606f[_0xcc1f('0x32')]&&_0x56606f[_0xcc1f('0x33')]){_0x56606f[_0xcc1f('0x30')]+=0x1;if(_0x56606f[_0xcc1f('0x2f')]){_0x56606f[_0xcc1f('0x2f')]-=0x1;}}if(_0x56606f[_0xcc1f('0x32')]&&_0x56606f[_0xcc1f('0x33')]){_0x56606f[_0xcc1f('0x34')]+=0x1;if(_0x56606f[_0xcc1f('0x30')]){_0x56606f[_0xcc1f('0x30')]-=0x1;}}if(_0x56606f[_0xcc1f('0x32')]&&!_0x56606f['UserId']){_0x56606f['unmanaged']+=0x1;if(_0x56606f['waiting']){_0x56606f[_0xcc1f('0x2f')]-=0x1;}}_0x56606f[_0xcc1f('0x31')]+=0x1;_0x2a5646(_0x56606f);});}exports[_0xcc1f('0x35')]=function(_0x332139,_0x43d933){var _0x3d0c4f={},_0x25a287={},_0x1dd624={'count':0x0,'rows':[]};var _0x6337d8=_[_0xcc1f('0x21')](db[_0xcc1f('0x36')][_0xcc1f('0x37')],function(_0x416146){return{'name':_0x416146['fieldName'],'type':_0x416146[_0xcc1f('0x38')][_0xcc1f('0x39')]};});_0x25a287[_0xcc1f('0x3a')]=_[_0xcc1f('0x21')](_0x6337d8,'name');_0x25a287['query']=_[_0xcc1f('0x3b')](_0x332139['query']);_0x25a287[_0xcc1f('0x3c')]=_[_0xcc1f('0x3d')](_0x25a287[_0xcc1f('0x3a')],_0x25a287['query']);_0x3d0c4f[_0xcc1f('0x3e')]=_[_0xcc1f('0x3d')](_0x25a287['model'],qs[_0xcc1f('0x3f')](_0x332139[_0xcc1f('0x40')]['fields']));_0x3d0c4f['attributes']=_0x3d0c4f[_0xcc1f('0x3e')][_0xcc1f('0x41')]?_0x3d0c4f['attributes']:_0x25a287[_0xcc1f('0x3a')];if(!_0x332139[_0xcc1f('0x40')][_0xcc1f('0x42')](_0xcc1f('0x43'))){_0x3d0c4f[_0xcc1f('0x17')]=qs['limit'](_0x332139['query'][_0xcc1f('0x17')]);_0x3d0c4f[_0xcc1f('0x15')]=qs[_0xcc1f('0x15')](_0x332139[_0xcc1f('0x40')][_0xcc1f('0x15')]);}_0x3d0c4f[_0xcc1f('0x44')]=qs['sort'](_0x332139[_0xcc1f('0x40')][_0xcc1f('0x45')]);_0x3d0c4f[_0xcc1f('0x46')]=qs[_0xcc1f('0x3c')](_['pick'](_0x332139[_0xcc1f('0x40')],_0x25a287['filters']),_0x6337d8);var _0x15aadd=[];var _0x396859=squel[_0xcc1f('0x47')]()['field']('id')[_0xcc1f('0x48')](_0xcc1f('0x1e'))[_0xcc1f('0x48')](_0xcc1f('0x49'))['from'](_0xcc1f('0x4a'));var _0x781a9b=squel['select']()['field'](_0xcc1f('0x4b'))[_0xcc1f('0x48')](_0xcc1f('0x4c'))['field'](_0xcc1f('0x4d'))[_0xcc1f('0x4e')](_0xcc1f('0x4f'),'ui')[_0xcc1f('0x50')](_0xcc1f('0x51'),'u',_0xcc1f('0x52'));var _0x4efa0b=squel[_0xcc1f('0x47')]()['from'](_0xcc1f('0x53'),'i')[_0xcc1f('0x50')](_0xcc1f('0x54'),'c',_0xcc1f('0x55'))['left_join'](_0xcc1f('0x51'),'o',_0xcc1f('0x56'))[_0xcc1f('0x50')](_0xcc1f('0x57'),'a',_0xcc1f('0x58'))[_0xcc1f('0x50')](_0xcc1f('0x59'),'me',_0xcc1f('0x5a'))[_0xcc1f('0x50')](_0xcc1f('0x5b'),'it',_0xcc1f('0x5c'))[_0xcc1f('0x50')]('tools_tags','t','t.id\x20=\x20it.TagId');var _0x3b6d1e=squel[_0xcc1f('0x5d')]();var _0x5694a4=[];var _0x53aaff=squel[_0xcc1f('0x5d')]();var _0x3f9b1a;if(_0x332139[_0xcc1f('0x40')]['search']){_0x3f9b1a=as[_0xcc1f('0x5e')](_0x332139[_0xcc1f('0x40')][_0xcc1f('0x5f')]);var _0x30405b=_0x3f9b1a[_0xcc1f('0x60')];for(var _0x57807a=0x0;_0x57807a<_0x3f9b1a['conditions'][_0xcc1f('0x41')];_0x57807a++){var _0x34f763=_0x3f9b1a[_0xcc1f('0x61')][_0x57807a];var _0x3bc7f8='i';var _0x37e2ab=_['find'](_0x6337d8,[_0xcc1f('0x1e'),_0x34f763[_0xcc1f('0x48')]]);if(!_0x37e2ab){switch(_0x34f763[_0xcc1f('0x48')]){case'unreadMessages':if(_0x34f763[_0xcc1f('0x62')]==0x1){_0x4efa0b['having']('`'+_0x34f763[_0xcc1f('0x48')]+_0xcc1f('0x63'));}else{_0x4efa0b[_0xcc1f('0x64')]('`'+_0x34f763[_0xcc1f('0x48')]+'`\x20>\x200');}break;case'Contact':if(_0x34f763[_0xcc1f('0x65')]===_0xcc1f('0x66')){if(_0x34f763[_0xcc1f('0x62')][_0xcc1f('0x25')]('\x20')[_0xcc1f('0x41')]>0x1){_0x3b6d1e[_0x30405b](_0xcc1f('0x67'),qs[_0xcc1f('0x68')](_0x34f763['value']),null);}else{var _0x3d14db='%'+_0x34f763[_0xcc1f('0x62')]+'%';_0x3b6d1e[_0x30405b](_0xcc1f('0x69'),_0x3d14db,_0x3d14db,_0x3d14db);}}else{_0x37e2ab=_['find'](_0x6337d8,[_0xcc1f('0x1e'),_0xcc1f('0x6a')]);_0x34f763[_0xcc1f('0x48')]=_0xcc1f('0x6a');_0x42beeb=as[_0xcc1f('0x6b')](_0x3bc7f8,_0x37e2ab[_0xcc1f('0x38')],_0x34f763);_0x3b6d1e[_0x30405b](_0x42beeb[_0xcc1f('0x6c')],_0x42beeb[_0xcc1f('0x62')][_0xcc1f('0x6d')],_0x42beeb[_0xcc1f('0x62')][_0xcc1f('0x6e')]);}break;case'Tag':var _0x3865f5=_0x34f763[_0xcc1f('0x62')][_0xcc1f('0x25')](',')['map'](function(_0x3bc54d){return Number(_0x3bc54d);});_0x3865f5['forEach'](function(_0x2b1aad){_0x53aaff['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x2b1aad+',%');});_0x5694a4=_[_0xcc1f('0x6f')](_0x5694a4,_0x3865f5);break;case _0xcc1f('0x70'):if(_0x34f763[_0xcc1f('0x65')]===_0xcc1f('0x66')){_0x3b6d1e[_0x30405b](_0xcc1f('0x71'),'%'+_0x34f763[_0xcc1f('0x62')]+'%',null);}else{_0x37e2ab=_[_0xcc1f('0x72')](_0x6337d8,[_0xcc1f('0x1e'),_0xcc1f('0x33')]);_0x34f763[_0xcc1f('0x48')]=_0xcc1f('0x33');_0x42beeb=as[_0xcc1f('0x6b')](_0x3bc7f8,_0x37e2ab[_0xcc1f('0x38')],_0x34f763);_0x3b6d1e[_0x30405b](_0x42beeb['text'],_0x42beeb[_0xcc1f('0x62')][_0xcc1f('0x6d')],_0x42beeb[_0xcc1f('0x62')]['end']);}break;case _0xcc1f('0x2b'):_0x42beeb=as[_0xcc1f('0x6b')]('me',null,_0x34f763);_0x3b6d1e[_0x30405b](_0x42beeb[_0xcc1f('0x6c')],_0x42beeb[_0xcc1f('0x62')][_0xcc1f('0x6d')],_0x42beeb[_0xcc1f('0x62')][_0xcc1f('0x6e')]);break;}}else{var _0x42beeb=as[_0xcc1f('0x6b')](_0x3bc7f8,_0x37e2ab[_0xcc1f('0x38')],_0x34f763);_0x3b6d1e[_0x30405b](_0x42beeb[_0xcc1f('0x6c')],_0x42beeb[_0xcc1f('0x62')][_0xcc1f('0x6d')],_0x42beeb['value'][_0xcc1f('0x6e')]);}}}else{var _0x413fbd=_(_0x332139[_0xcc1f('0x40')])['keys']()[_0xcc1f('0x21')](function(_0xdbfb33){return _[_0xcc1f('0x73')](_0x6337d8,[_0xcc1f('0x1e'),_0xdbfb33])?_0xdbfb33:undefined;})[_0xcc1f('0x74')]()[_0xcc1f('0x62')]();if(!_[_0xcc1f('0x75')](_0x413fbd)){_0x413fbd[_0xcc1f('0x26')](function(_0xe06531){if(_0xe06531==='MailAccountId'){_0x4efa0b[_0xcc1f('0x46')](_0xcc1f('0x76'),[][_0xcc1f('0x77')](_0x332139[_0xcc1f('0x40')][_0xe06531]));}else if(_0xe06531===_0xcc1f('0x78')){var _0x10bc01=JSON[_0xcc1f('0x79')](_0x332139[_0xcc1f('0x40')][_0xe06531])[_0xcc1f('0x7a')];var _0x24ea6d=JSON[_0xcc1f('0x79')](_0x332139[_0xcc1f('0x40')][_0xe06531])[_0xcc1f('0x7b')];_0x4efa0b[_0xcc1f('0x46')](_0xcc1f('0x7c'),_0x10bc01,_0x24ea6d);}else{if(_0x332139[_0xcc1f('0x40')][_0xe06531]===_0xcc1f('0x7d')){_0x4efa0b[_0xcc1f('0x46')]('i.'+_0xe06531+_0xcc1f('0x7e'));}else{_0x4efa0b[_0xcc1f('0x46')]('i.'+_0xe06531+_0xcc1f('0x7f'),_0x332139['query'][_0xe06531]);}}});}if(_0x332139['query']['read']){if(_0x332139[_0xcc1f('0x40')][_0xcc1f('0x80')]==0x1){_0x4efa0b[_0xcc1f('0x64')](_0xcc1f('0x81'));}else{_0x4efa0b[_0xcc1f('0x64')](_0xcc1f('0x82'));}}if(_0x332139[_0xcc1f('0x40')][_0xcc1f('0x83')]){_0x5694a4=_[_0xcc1f('0x84')](_0x332139[_0xcc1f('0x40')][_0xcc1f('0x83')])?_0x332139[_0xcc1f('0x40')][_0xcc1f('0x83')]:new Array(_0x332139[_0xcc1f('0x40')][_0xcc1f('0x83')]);_0x5694a4[_0xcc1f('0x26')](function(_0x189edf){_0x53aaff['or'](_0xcc1f('0x85'),'%,'+_0x189edf+',%');});}if(_0x332139[_0xcc1f('0x40')][_0xcc1f('0x86')]){var _0x1a4982=_0x332139[_0xcc1f('0x40')][_0xcc1f('0x86')]['replace']('\x5c','\x5c\x5c')[_0xcc1f('0x87')](/'/g,'\x27\x27');if(qs[_0xcc1f('0x88')](_0x1a4982)){_0x3b6d1e['or'](_0xcc1f('0x89'),_0x1a4982+'%');}else if(qs['isEmail'](_0x1a4982)){_0x3b6d1e['or'](_0xcc1f('0x8a'),_0x1a4982+'%');}else{_0x3b6d1e['or']('MATCH\x20(i.to,\x20i.subject)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs[_0xcc1f('0x68')](_0x1a4982))['or'](_0xcc1f('0x8b'),qs[_0xcc1f('0x68')](_0x1a4982));}}}_0x4efa0b['where'](_0x3b6d1e);_0x4efa0b[_0xcc1f('0x8c')](_0xcc1f('0x8d'));var _0x1b5d94={'type':db[_0xcc1f('0x8e')][_0xcc1f('0x8f')][_0xcc1f('0x90')],'raw':!![]};var _0x296bbe=_0x4efa0b['clone']();_0x296bbe[_0xcc1f('0x48')]('i.id');_0x296bbe[_0xcc1f('0x48')](_0xcc1f('0x91'),_0xcc1f('0x92'));if(_0x3d0c4f[_0xcc1f('0x44')]){_0x3d0c4f[_0xcc1f('0x44')][_0xcc1f('0x26')](function(_0x5b2f81){var _0x19fd95=_0x5b2f81[0x0]===_0xcc1f('0x93')?_0x5b2f81[0x0]:'i.'+_0x5b2f81[0x0];_0x4efa0b[_0xcc1f('0x44')](_0x19fd95,_0x5b2f81[0x1]===_0xcc1f('0x94')?![]:!![]);});}if(!_[_0xcc1f('0x75')](_0x5694a4)){_0x4efa0b[_0xcc1f('0x64')](_0x53aaff);_0x296bbe['where']('t.id\x20IN\x20?',_0x5694a4);}BPromise[_0xcc1f('0x95')]()[_0xcc1f('0x1c')](function(){if(!_0x3f9b1a){if(_0x332139[_0xcc1f('0x40')]['MailAccountId'])return;_0x296bbe[_0xcc1f('0x46')](_0xcc1f('0x96'));_0x4efa0b[_0xcc1f('0x46')]('i.MailAccountId\x20IS\x20NOT\x20NULL');return;}if(_0x332139[_0xcc1f('0x97')][_0xcc1f('0x98')]!==_0xcc1f('0x99'))return;return _0x332139[_0xcc1f('0x97')][_0xcc1f('0x9a')]({'attributes':['id'],'raw':!![]})['then'](function(_0x4414f7){if(_[_0xcc1f('0x75')](_0x4414f7)){_0x296bbe[_0xcc1f('0x46')](_0xcc1f('0x9b'));_0x4efa0b[_0xcc1f('0x46')]('i.MailAccountId\x20IS\x20NULL');}else{_0x296bbe[_0xcc1f('0x46')]('i.MailAccountId\x20IN\x20?',_[_0xcc1f('0x21')](_0x4414f7,'id'));_0x4efa0b['where'](_0xcc1f('0x76'),_[_0xcc1f('0x21')](_0x4414f7,'id'));}});})[_0xcc1f('0x1c')](function(){if(_0x332139[_0xcc1f('0x97')][_0xcc1f('0x98')]===_0xcc1f('0x99')&&!_0x3f9b1a&&!_0x332139[_0xcc1f('0x40')][_0xcc1f('0x9c')])return[];return db[_0xcc1f('0x9d')][_0xcc1f('0x40')](_0x296bbe[_0xcc1f('0x9e')](),_0x1b5d94);})[_0xcc1f('0x1c')](function(_0x543d27){_0x1dd624[_0xcc1f('0x18')]=_0x543d27['length'];if(_0x1dd624[_0xcc1f('0x18')]===0x0)return[];return db[_0xcc1f('0x9d')][_0xcc1f('0x40')](_0x396859[_0xcc1f('0x9e')](),_0x1b5d94)[_0xcc1f('0x1c')](function(_0x255427){_0x15aadd=_[_0xcc1f('0x9f')](_0x255427,'id');_0x1b5d94=_[_0xcc1f('0xa0')](_0x1b5d94,{'model':db[_0xcc1f('0x36')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x332139[_0xcc1f('0x40')]['fields']){_0x3d0c4f[_0xcc1f('0x3e')][_0xcc1f('0x26')](function(_0x38ad77){_0x4efa0b['field']('i.'+_0x38ad77);});}else{_0x4efa0b[_0xcc1f('0x48')](_0xcc1f('0x91'),'unreadMessages');_0x4efa0b[_0xcc1f('0x48')](_0xcc1f('0xa1'),_0xcc1f('0xa2'));_0x4efa0b[_0xcc1f('0x48')](_0xcc1f('0xa3'),_0xcc1f('0xa4'));_0x4efa0b[_0xcc1f('0x48')](_0xcc1f('0xa5'),'contactName');_0x4efa0b['field'](_0xcc1f('0x8d'));_0x4efa0b[_0xcc1f('0x48')](_0xcc1f('0xa6'));_0x4efa0b[_0xcc1f('0x48')](_0xcc1f('0xa7'));_0x4efa0b[_0xcc1f('0x48')](_0xcc1f('0xa8'));_0x4efa0b[_0xcc1f('0x48')](_0xcc1f('0xa9'));_0x4efa0b[_0xcc1f('0x48')](_0xcc1f('0xaa'));_0x4efa0b[_0xcc1f('0x48')](_0xcc1f('0xab'));_0x4efa0b[_0xcc1f('0x48')](_0xcc1f('0xac'));_0x4efa0b[_0xcc1f('0x48')]('i.subject');_0x4efa0b['field'](_0xcc1f('0xad'));_0x4efa0b[_0xcc1f('0x48')](_0xcc1f('0xae'));_0x4efa0b[_0xcc1f('0x48')](_0xcc1f('0xaf'));_0x4efa0b[_0xcc1f('0x48')]('i.substatus');_0x4efa0b[_0xcc1f('0x48')](_0xcc1f('0xb0'));_0x4efa0b[_0xcc1f('0x48')](_0xcc1f('0xb1'));_0x4efa0b[_0xcc1f('0x48')](_0xcc1f('0xb2'));_0x4efa0b['field'](_0xcc1f('0xb3'));_0x4efa0b['field'](_0xcc1f('0xb4'),_0xcc1f('0xb5'));_0x4efa0b[_0xcc1f('0x48')](_0xcc1f('0xb6'),_0xcc1f('0xb7'));_0x4efa0b[_0xcc1f('0x48')]('c.email',_0xcc1f('0xb8'));_0x4efa0b['field'](_0xcc1f('0xb9'),_0xcc1f('0xba'));_0x4efa0b[_0xcc1f('0x48')]('c.mobile','Contact.mobile');_0x4efa0b[_0xcc1f('0x48')](_0xcc1f('0xbb'),_0xcc1f('0xbc'));_0x4efa0b[_0xcc1f('0x48')](_0xcc1f('0xbd'),_0xcc1f('0xbe'));_0x4efa0b[_0xcc1f('0x48')](_0xcc1f('0xbf'),_0xcc1f('0xc0'));_0x4efa0b['field'](_0xcc1f('0xc1'),_0xcc1f('0x23'));}if(_0x3d0c4f[_0xcc1f('0x17')])_0x4efa0b[_0xcc1f('0x17')](_0x3d0c4f['limit']);if(_0x3d0c4f['offset'])_0x4efa0b[_0xcc1f('0x15')](_0x3d0c4f[_0xcc1f('0x15')]);return db[_0xcc1f('0x9d')]['query'](_0x4efa0b[_0xcc1f('0x9e')](),_0x1b5d94);})['then'](function(_0x3c7fc1){if(_0x3c7fc1['length']>0x0)_0x781a9b[_0xcc1f('0x46')]('ui.MailInteractionId\x20IN\x20?',_[_0xcc1f('0x21')](_0x3c7fc1,'id'));return db[_0xcc1f('0x9d')]['query'](_0x781a9b[_0xcc1f('0x9e')](),_0x1b5d94)[_0xcc1f('0x1c')](function(_0x2ec0c4){var _0x586c9b=_[_0xcc1f('0xc2')](_0x2ec0c4,_0xcc1f('0xc3'));var _0x20f8df=[];return db[_0xcc1f('0xc4')][_0xcc1f('0x29')]({'attributes':[_0xcc1f('0xc5')],'raw':!![]})[_0xcc1f('0x1c')](function(_0x1b6ad1){var _0x4c5101=_0x1b6ad1[_0xcc1f('0xc5')];_0x3c7fc1[_0xcc1f('0x26')](function(_0x4dd7ae){_0x20f8df['push'](updateMailInteraction(_0x4dd7ae,_0x15aadd,_0x586c9b,_0x4c5101));});return BPromise['all'](_0x20f8df);});});});})[_0xcc1f('0x1c')](function(_0x15f140){_0x1dd624[_0xcc1f('0xc6')]=_0x15f140;return _0x1dd624;})[_0xcc1f('0x1c')](respondWithFilteredResult(_0x43d933,_0x3d0c4f))[_0xcc1f('0x2e')](handleError(_0x43d933,null));};exports[_0xcc1f('0xc7')]=function(_0x380510,_0x1690d2){var _0x2c182f={'raw':![],'where':{'id':_0x380510[_0xcc1f('0xc8')]['id']}},_0x33fc70={};_0x33fc70[_0xcc1f('0x3a')]=_[_0xcc1f('0x3b')](db[_0xcc1f('0x36')][_0xcc1f('0x37')]);_0x33fc70[_0xcc1f('0x40')]=_['keys'](_0x380510['query']);_0x33fc70[_0xcc1f('0x3c')]=_['intersection'](_0x33fc70[_0xcc1f('0x3a')],_0x33fc70[_0xcc1f('0x40')]);_0x2c182f['attributes']=_['intersection'](_0x33fc70[_0xcc1f('0x3a')],qs[_0xcc1f('0x3f')](_0x380510[_0xcc1f('0x40')][_0xcc1f('0x3f')]));_0x2c182f[_0xcc1f('0x3e')]=_0x2c182f[_0xcc1f('0x3e')][_0xcc1f('0x41')]?_0x2c182f[_0xcc1f('0x3e')]:_0x33fc70['model'];if(_0x380510[_0xcc1f('0x40')][_0xcc1f('0xc9')]){_0x2c182f[_0xcc1f('0xca')]=[{'all':!![]}];}_0x2c182f=_[_0xcc1f('0xa0')]({},_0x2c182f,_0x380510[_0xcc1f('0xcb')]);return db[_0xcc1f('0x36')]['find'](_0x2c182f)[_0xcc1f('0x1c')](handleEntityNotFound(_0x1690d2,null))[_0xcc1f('0x1c')](respondWithResult(_0x1690d2,null))[_0xcc1f('0x2e')](handleError(_0x1690d2,null));};exports[_0xcc1f('0xcc')]=function(_0x41865f,_0x1c6ed6){return db['MailInteraction']['create'](_0x41865f[_0xcc1f('0xcd')],{})['then'](respondWithResult(_0x1c6ed6,0xc9))[_0xcc1f('0x2e')](handleError(_0x1c6ed6,null));};exports[_0xcc1f('0x1a')]=function(_0x3ae767,_0x574b24){if(_0x3ae767[_0xcc1f('0xcd')]['id']){delete _0x3ae767[_0xcc1f('0xcd')]['id'];}return db[_0xcc1f('0x36')][_0xcc1f('0x72')]({'where':{'id':_0x3ae767[_0xcc1f('0xc8')]['id']}})['then'](handleEntityNotFound(_0x574b24,null))[_0xcc1f('0x1c')](saveUpdates(_0x3ae767[_0xcc1f('0xcd')],null))[_0xcc1f('0x1c')](respondWithResult(_0x574b24,null))[_0xcc1f('0x2e')](handleError(_0x574b24,null));};exports[_0xcc1f('0x1b')]=function(_0x1526cd,_0x52260b){return db[_0xcc1f('0x36')][_0xcc1f('0x72')]({'where':{'id':_0x1526cd[_0xcc1f('0xc8')]['id']}})[_0xcc1f('0x1c')](handleEntityNotFound(_0x52260b,null))[_0xcc1f('0x1c')](removeEntity(_0x52260b,null))[_0xcc1f('0x2e')](handleError(_0x52260b,null));};exports[_0xcc1f('0xce')]=function(_0x2ecada,_0x38e663){return db[_0xcc1f('0x36')][_0xcc1f('0xce')]()['then'](respondWithResult(_0x38e663,null))['catch'](handleError(_0x38e663,null));};exports['addMessage']=function(_0x49b721,_0x3d1377){return db['MailMessage']['find']({'where':{'id':_0x49b721[_0xcc1f('0xc8')]['id']}})[_0xcc1f('0x1c')](handleEntityNotFound(_0x3d1377,null))['then'](function(_0x504ead){if(_0x504ead){return _0x504ead['addMessage'](_0x49b721[_0xcc1f('0xcd')][_0xcc1f('0xcf')],_[_0xcc1f('0xd0')](_0x49b721[_0xcc1f('0xcd')],[_0xcc1f('0xcf'),'id'])||{});}})[_0xcc1f('0x1c')](respondWithResult(_0x3d1377,null))[_0xcc1f('0x2e')](handleError(_0x3d1377,null));};exports['getMessages']=function(_0x1b0597,_0x2bb6c1){var _0x330103={'raw':![],'where':{}};var _0x279fd5={};var _0x2a5012={'count':0x0,'rows':[]};return db[_0xcc1f('0x36')]['findOne']({'where':{'id':_0x1b0597[_0xcc1f('0xc8')]['id']}})['then'](handleEntityNotFound(_0x2bb6c1,null))[_0xcc1f('0x1c')](function(_0x3e2447){if(_0x3e2447){_0x279fd5['model']=_[_0xcc1f('0x3b')](db[_0xcc1f('0x28')][_0xcc1f('0x37')]);_0x279fd5[_0xcc1f('0x40')]=_[_0xcc1f('0x3b')](_0x1b0597[_0xcc1f('0x40')]);_0x279fd5[_0xcc1f('0x3c')]=_[_0xcc1f('0x3d')](_0x279fd5[_0xcc1f('0x3a')],_0x279fd5[_0xcc1f('0x40')]);_0x330103[_0xcc1f('0x3e')]=_[_0xcc1f('0x3d')](_0x279fd5[_0xcc1f('0x3a')],qs[_0xcc1f('0x3f')](_0x1b0597[_0xcc1f('0x40')]['fields']));_0x330103['attributes']=_0x330103[_0xcc1f('0x3e')][_0xcc1f('0x41')]?_0x330103[_0xcc1f('0x3e')]:_0x279fd5['model'];if(!_0x1b0597[_0xcc1f('0x40')][_0xcc1f('0x42')](_0xcc1f('0x43'))){_0x330103['limit']=qs[_0xcc1f('0x17')](_0x1b0597['query']['limit']);_0x330103['offset']=qs[_0xcc1f('0x15')](_0x1b0597[_0xcc1f('0x40')][_0xcc1f('0x15')]);}_0x330103[_0xcc1f('0x44')]=qs[_0xcc1f('0x45')](_0x1b0597[_0xcc1f('0x40')]['sort']);_0x330103['where']=qs[_0xcc1f('0x3c')](_[_0xcc1f('0xd1')](_0x1b0597[_0xcc1f('0x40')],_0x279fd5[_0xcc1f('0x3c')]));_0x330103[_0xcc1f('0x46')][_0xcc1f('0xc3')]=_0x3e2447['id'];if(_0x1b0597['query']['filter']){_0x330103[_0xcc1f('0x46')]=_[_0xcc1f('0xa0')](_0x330103[_0xcc1f('0x46')],{'$or':_[_0xcc1f('0x21')](_0x330103[_0xcc1f('0x3e')],function(_0x587378){var _0x753027={};_0x753027[_0x587378]={'$like':'%'+_0x1b0597['query'][_0xcc1f('0x86')]+'%'};return _0x753027;})});}if(_0x1b0597[_0xcc1f('0x40')]['$gte']){var _0x2da010=_0x1b0597[_0xcc1f('0x40')]['$gte'][_0xcc1f('0x25')](',');var _0x222f59={};_0x222f59[_0x2da010[0x0]]={'$gte':moment(_0x2da010[0x1])['format'](_0xcc1f('0xd2'))};_0x330103[_0xcc1f('0x46')]=_[_0xcc1f('0xa0')](_0x330103[_0xcc1f('0x46')],_0x222f59);}_0x330103=_['merge']({},_0x330103,_0x1b0597[_0xcc1f('0xcb')]);return db[_0xcc1f('0x28')][_0xcc1f('0x18')]({'where':_0x330103[_0xcc1f('0x46')]})[_0xcc1f('0x1c')](function(_0x48ce43){_0x2a5012[_0xcc1f('0x18')]=_0x48ce43;if(_0x1b0597['query']['includeAll']){_0x330103[_0xcc1f('0xca')]=[{'all':!![]}];}return db['MailMessage']['findAll'](_0x330103);})['then'](function(_0x58bf8f){if(_0x1b0597[_0xcc1f('0x40')][_0xcc1f('0xd3')]===_0xcc1f('0xd4')){for(var _0x32688d=0x0;_0x32688d<_0x58bf8f[_0xcc1f('0x41')];_0x32688d++){_0x58bf8f[_0x32688d]['body']=juice(_0x58bf8f[_0x32688d][_0xcc1f('0xcd')]);}}_0x2a5012['rows']=_0x58bf8f;return _0x2a5012;});}})[_0xcc1f('0x1c')](respondWithFilteredResult(_0x2bb6c1,_0x330103))['catch'](handleError(_0x2bb6c1,null));};exports['addTags']=function(_0x5a6f1c,_0x25ab3d){return db[_0xcc1f('0x36')][_0xcc1f('0x72')]({'where':{'id':_0x5a6f1c[_0xcc1f('0xc8')]['id']}})[_0xcc1f('0x1c')](handleEntityNotFound(_0x25ab3d,null))[_0xcc1f('0x1c')](function(_0x9269da){if(_0x9269da){return _0x9269da[_0xcc1f('0xd5')](_0x5a6f1c[_0xcc1f('0xcd')]['ids'],_[_0xcc1f('0xd0')](_0x5a6f1c['body'],[_0xcc1f('0xcf'),'id'])||{})[_0xcc1f('0xd6')](function(){return db[_0xcc1f('0xd7')][_0xcc1f('0xd8')]({'attributes':['id','name',_0xcc1f('0x49')],'where':{'id':_0x5a6f1c[_0xcc1f('0xcd')]['ids']}});})['then'](function(_0x2f2323){socket['emit'](_0xcc1f('0xd9'),{'id':Number(_0x5a6f1c[_0xcc1f('0xc8')]['id']),'tags':_0x2f2323||[]});return{'id':Number(_0x5a6f1c[_0xcc1f('0xc8')]['id']),'tags':_0x2f2323||[]};});}})[_0xcc1f('0x1c')](respondWithResult(_0x25ab3d,null))[_0xcc1f('0x2e')](handleError(_0x25ab3d,null));};exports[_0xcc1f('0xda')]=function(_0x3c8bae,_0x1c1129){return db[_0xcc1f('0x36')]['find']({'where':{'id':_0x3c8bae[_0xcc1f('0xc8')]['id']}})[_0xcc1f('0x1c')](handleEntityNotFound(_0x1c1129,null))['then'](function(_0x5074ca){if(_0x5074ca){return _0x5074ca['removeTags'](_0x3c8bae[_0xcc1f('0x40')][_0xcc1f('0xcf')]);}})[_0xcc1f('0x1c')](respondWithStatusCode(_0x1c1129,null))[_0xcc1f('0x2e')](handleError(_0x1c1129,null));};exports[_0xcc1f('0xdb')]=function(_0x2c29c7,_0x3e4e97){var _0x263e1f=moment()[_0xcc1f('0xdc')]()[_0xcc1f('0x9e')]();var _0xb9e91=path['join'](config['root'],_0xcc1f('0xdd'),_0xcc1f('0xde'),_0xcc1f('0xdf'));var _0x60e381=path[_0xcc1f('0xe0')](config['root'],'server',_0xcc1f('0xde'),_0xcc1f('0xe1'));var _0x3cf918=path[_0xcc1f('0xe0')](_0xb9e91,_0x263e1f);var _0x92cbcb=util[_0xcc1f('0xe2')](_0xcc1f('0xe3'),_0x2c29c7[_0xcc1f('0xc8')]['id'],_0x263e1f);var _0x3114e0=path[_0xcc1f('0xe0')](_0xb9e91,_0x92cbcb);var _0x1b378c=[];if(_0x2c29c7[_0xcc1f('0x40')][_0xcc1f('0xe1')]){_0x1b378c[_0xcc1f('0x27')]({'model':db[_0xcc1f('0xe4')],'as':_0xcc1f('0xe5'),'raw':!![]});}var _0x12886d=[{'model':db[_0xcc1f('0x28')],'as':_0xcc1f('0xe6'),'attributes':['id','body',_0xcc1f('0x4e'),'to','cc',_0xcc1f('0xe7'),'subject',_0xcc1f('0x78')],'where':{'secret':![]},'order':qs['sort']('id'),'include':_0x1b378c}];return db['MailInteraction'][_0xcc1f('0x72')]({'where':{'id':_0x2c29c7[_0xcc1f('0xc8')]['id']},'include':_0x12886d})[_0xcc1f('0x1c')](handleEntityNotFound(_0x3e4e97,null))[_0xcc1f('0x1c')](function(_0x376449){if(_0x376449&&_0x376449[_0xcc1f('0xe6')]){var _0x1be5af=_0x376449['get']({'plain':!![]});fs[_0xcc1f('0xe8')](_0x3cf918);return BPromise['each'](_0x1be5af[_0xcc1f('0xe6')],function(_0x5d6e10,_0x4d1c33){var _0x3c08f3={'from':_0x5d6e10['from'],'to':_0x5d6e10['to'],'subject':_0x5d6e10[_0xcc1f('0xe9')],'html':htmlEntities['decode'](_0x5d6e10[_0xcc1f('0xcd')]),'headers':{'Date':moment(_0x5d6e10[_0xcc1f('0x78')])[_0xcc1f('0xe2')]('ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ')},'attachments':[]};if(_0x5d6e10['cc']){_0x3c08f3[_0xcc1f('0xea')]['Cc']=_0x5d6e10['cc'];}if(_0x5d6e10[_0xcc1f('0xe7')]){_0x3c08f3[_0xcc1f('0xea')][_0xcc1f('0xeb')]=_0x5d6e10[_0xcc1f('0xe7')];}return new BPromise(function(_0x1df8de,_0x18f123){if(_0x5d6e10[_0xcc1f('0xe5')]){for(var _0xbadc5e=0x0;_0xbadc5e<_0x5d6e10[_0xcc1f('0xe5')][_0xcc1f('0x41')];_0xbadc5e++){var _0x4e44d0=_0x5d6e10[_0xcc1f('0xe5')][_0xbadc5e];var _0x17e4f6=path[_0xcc1f('0xe0')](_0x60e381,_0x4e44d0[_0xcc1f('0xec')]);if(fs['existsSync'](_0x17e4f6)){_0x3c08f3[_0xcc1f('0xe1')]['push']({'name':_0x4e44d0[_0xcc1f('0x1e')],'contentType':_0x4e44d0[_0xcc1f('0x38')],'data':fs[_0xcc1f('0xed')](_0x17e4f6)});}}}emlformat[_0xcc1f('0xee')](_0x3c08f3,function(_0x202287,_0x5bb731){if(_0x202287)return _0x18f123(_0x202287);fs[_0xcc1f('0xef')](path[_0xcc1f('0xe0')](_0x3cf918,util[_0xcc1f('0xe2')](_0xcc1f('0xf0'),_0x4d1c33)),_0x5bb731);return _0x1df8de(_0x5bb731);});});})['then'](function(){return new BPromise(function(_0x10cf98,_0x461bc4){zipdir(_0x3cf918,{'saveTo':_0x3114e0},function(_0x424bd7,_0x3ad369){if(_0x424bd7)return _0x461bc4(_0x424bd7);return _0x10cf98(_0x3ad369);});})[_0xcc1f('0x1c')](function(){return new BPromise(function(_0x2eb9cb,_0x28190){rimraf(_0x3cf918,function(_0x1ed0ac){if(_0x1ed0ac)_0x28190(_0x1ed0ac);return _0x2eb9cb();});});})[_0xcc1f('0x1c')](function(){return _0x3e4e97[_0xcc1f('0xdb')](_0x3114e0,_0x92cbcb,function(_0x40baab){if(!_0x40baab)fs[_0xcc1f('0xf1')](_0x3114e0);});});});}else{return _0x3e4e97[_0xcc1f('0x12')](0xc8);}})[_0xcc1f('0x2e')](handleError(_0x3e4e97,null));};
\ No newline at end of file
+var _0x236d=['$substring','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','find','ContactId','buildExpression','text','start','Tag','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','type','compact','isEmpty','MailAccountId','concat','parse','$gte','$lte','\x20=\x20?','read','`unreadMessages`\x20=\x200','`unreadMessages`\x20>\x200','tag','isArray','filter','replace','isNumeric','c.email\x20LIKE\x20?','MATCH\x20(i.to,\x20i.subject)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','MATCH\x20(me.plainBody,\x20me.subject)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','group','Sequelize','SELECT','clone','i.id','order','contactName','role','user','i.MailAccountId\x20IS\x20NULL','i.MailAccountId\x20IN\x20?','agent','sequelize','toString','MailInteraction','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','a.key','Account.key','a.mandatoryDisposition','Account.mandatoryDisposition','i.createdAt','i.closedAt','i.attach','i.lastMsgAt','i.lastMsgDirection','i.subject','i.secondDisposition','i.thirdDisposition','i.substatus','i.to','i.ContactId','i.MailAccountId','i.UserId','c.firstName','c.lastName','Contact.lastName','c.email','Contact.email','Contact.phone','Contact.mobile','Contact.fax','o.fullname','o.internal','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','groupBy','Setting','rows','show','fields','includeAll','include','merge','create','body','params','describe','addMessage','ids','omit','getMessages','filters','pick','MailInteractionId','options','findAll','inlineCss','true','addTags','setTags','spread','emit','removeTags','download','join','root','server','files','attachments','Attachment','Messages','subject','createdAt','get','mkdirSync','each','decode','headers','bcc','Attachments','basename','readFileSync','build','writeFileSync','format','message%d.eml','unlinkSync','eml-format','rimraf','moment','util','path','lodash','squel','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','html-entities','redis','localhost','./mailInteraction.socket','register','sendStatus','end','status','json','offset','undefined','limit','count','Content-Range','update','then','destroy','name','Users','map','fullname','TagIds','Tags','split','forEach','push','MailMessage','findOne','out','plainBody','-id','lastMsgText','catch','waiting','talking','answered','unmanaged','total','closed','UserId','index','rawAttributes','fieldName','model','query','keys','intersection','attributes','hasOwnProperty','nolimit','sort','where','select','field','color','from','tools_tags','ui.MailInteractionId','user_has_mail_interactions','left_join','mail_interactions','cm_contacts','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','users','o.id\x20=\x20i.UserId','me.MailInteractionId\x20=\x20i.id','it.MailInteractionId\x20=\x20i.id','t.id\x20=\x20it.TagId','expr','parseSearch','search','sqlOperator','conditions','length','unreadMessages','value','having','`\x20>\x200','Contact','operator'];(function(_0x4dbfce,_0xaf8cdf){var _0x1f3e53=function(_0x589c63){while(--_0x589c63){_0x4dbfce['push'](_0x4dbfce['shift']());}};_0x1f3e53(++_0xaf8cdf);}(_0x236d,0x7e));var _0xd236=function(_0x321bb2,_0x202794){_0x321bb2=_0x321bb2-0x0;var _0x9c12ed=_0x236d[_0x321bb2];return _0x9c12ed;};'use strict';var emlformat=require(_0xd236('0x0'));var rimraf=require(_0xd236('0x1'));var zipdir=require('zip-dir');var moment=require(_0xd236('0x2'));var BPromise=require('bluebird');var util=require(_0xd236('0x3'));var path=require(_0xd236('0x4'));var fs=require('fs');var _=require(_0xd236('0x5'));var squel=require(_0xd236('0x6'));var juice=require('juice');var Redis=require('ioredis');var qs=require(_0xd236('0x7'));var as=require(_0xd236('0x8'));var logger=require(_0xd236('0x9'))(_0xd236('0xa'));var config=require('../../config/environment');var db=require('../../mysqldb')['db'];var htmlEntities=require(_0xd236('0xb'));config[_0xd236('0xc')]=_['defaults'](config[_0xd236('0xc')],{'host':_0xd236('0xd'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xd236('0xc')]));require(_0xd236('0xe'))[_0xd236('0xf')](socket);function respondWithStatusCode(_0x594013,_0x470524){_0x470524=_0x470524||0xcc;return function(_0x2e4986){if(_0x2e4986){return _0x594013[_0xd236('0x10')](_0x470524);}return _0x594013['status'](_0x470524)[_0xd236('0x11')]();};}function respondWithResult(_0x2fe18d,_0x3d1076){_0x3d1076=_0x3d1076||0xc8;return function(_0x160cb1){if(_0x160cb1){return _0x2fe18d[_0xd236('0x12')](_0x3d1076)[_0xd236('0x13')](_0x160cb1);}};}function respondWithFilteredResult(_0x206b35,_0x974c47){return function(_0x22435c){if(_0x22435c){var _0x3d7465=typeof _0x974c47[_0xd236('0x14')]===_0xd236('0x15')&&typeof _0x974c47[_0xd236('0x16')]===_0xd236('0x15');var _0xd851b5=_0x22435c[_0xd236('0x17')];var _0x2a076d=_0x3d7465?0x0:_0x974c47[_0xd236('0x14')];var _0x24ce6e=_0x3d7465?_0x22435c[_0xd236('0x17')]:_0x974c47['offset']+_0x974c47['limit'];var _0x216a25;if(_0x24ce6e>=_0xd851b5){_0x24ce6e=_0xd851b5;_0x216a25=0xc8;}else{_0x216a25=0xce;}_0x206b35[_0xd236('0x12')](_0x216a25);return _0x206b35['set'](_0xd236('0x18'),_0x2a076d+'-'+_0x24ce6e+'/'+_0xd851b5)[_0xd236('0x13')](_0x22435c);}return null;};}function saveUpdates(_0x132752){return function(_0x595fd4){if(_0x595fd4){return _0x595fd4[_0xd236('0x19')](_0x132752)[_0xd236('0x1a')](function(_0x31f0bb){return _0x31f0bb;});}return null;};}function removeEntity(_0x551b53){return function(_0x25220d){if(_0x25220d){return _0x25220d[_0xd236('0x1b')]()[_0xd236('0x1a')](function(){_0x551b53[_0xd236('0x12')](0xcc)[_0xd236('0x11')]();});}};}function handleEntityNotFound(_0x58cc3f){return function(_0x2a1255){if(!_0x2a1255){_0x58cc3f[_0xd236('0x10')](0x194);}return _0x2a1255;};}function handleError(_0x1e4ddb,_0x3d1e4e){_0x3d1e4e=_0x3d1e4e||0x1f4;return function(_0xf28313){logger['error'](_0xf28313['stack']);if(_0xf28313[_0xd236('0x1c')]){delete _0xf28313['name'];}_0x1e4ddb[_0xd236('0x12')](_0x3d1e4e)['send'](_0xf28313);};}function getInteractionUsers(_0x2be060,_0x2174f5){return new BPromise(function(_0x234930,_0x49d822){try{if(_0x2174f5[_0x2be060['id']]){_0x2be060[_0xd236('0x1d')]=_[_0xd236('0x1e')](_0x2174f5[_0x2be060['id']],function(_0x6d3372){return{'id':_0x6d3372['id'],'fullname':_0x6d3372[_0xd236('0x1f')]};});}}catch(_0x3a30d8){_0x49d822(_0x3a30d8);}_0x234930(_0x2be060);});}function getInteractionTags(_0x17f927,_0x41cf34){return new BPromise(function(_0x21eeab,_0x2cbb03){try{if(_0x17f927[_0xd236('0x20')]){_0x17f927[_0xd236('0x21')]=[];_0x17f927[_0xd236('0x20')][_0xd236('0x22')](',')[_0xd236('0x23')](function(_0x3108f4){_0x17f927[_0xd236('0x21')][_0xd236('0x24')](_0x41cf34[_0x3108f4]);});}delete _0x17f927[_0xd236('0x20')];}catch(_0x463fc8){_0x2cbb03(_0x463fc8);}_0x21eeab(_0x17f927);});}function getLastMessageText(_0x98d8b0){return new BPromise(function(_0x119de7,_0x37b099){return db[_0xd236('0x25')][_0xd236('0x26')]({'where':{'$and':[{'MailInteractionId':_0x98d8b0['id']},{'$or':[{'direction':'in'},{'$and':[{'direction':_0xd236('0x27')},{'secret':![]},{'UserId':{'$ne':null}}]}]}]},'attributes':[_0xd236('0x28')],'order':_0xd236('0x29'),'raw':!![]})[_0xd236('0x1a')](function(_0x3d5f6d){if(_0x3d5f6d&&_0x3d5f6d['plainBody']){_0x98d8b0[_0xd236('0x2a')]=_['trimStart'](_0x3d5f6d[_0xd236('0x28')]);}_0x119de7(_0x98d8b0);})[_0xd236('0x2b')](function(_0x73a2fb){_0x37b099(_0x73a2fb);});});}function updateMailInteraction(_0x58cfb7,_0x1c1692,_0x37b5f7,_0x3bba5d){return new BPromise(function(_0x33400d,_0x2b8e83){return getInteractionUsers(_0x58cfb7,_0x37b5f7)[_0xd236('0x1a')](function(_0x42361d){return getInteractionTags(_0x42361d,_0x1c1692);})['then'](function(_0x2fa782){return getStateInteraction(_0x2fa782);})['then'](function(_0x284748){if(_0x3bba5d){_0x33400d(getLastMessageText(_0x284748));}else{_0x33400d(_0x284748);}})['catch'](function(_0x1fd01b){_0x2b8e83(_0x1fd01b);});});}function getStateInteraction(_0xb75faa){return new BPromise(function(_0x366128){_0xb75faa[_0xd236('0x2c')]=0x0;_0xb75faa[_0xd236('0x2d')]=0x0;_0xb75faa[_0xd236('0x2e')]=0x0;_0xb75faa[_0xd236('0x2f')]=0x0;_0xb75faa[_0xd236('0x30')]=0x0;if(!_0xb75faa[_0xd236('0x31')]&&!_0xb75faa[_0xd236('0x32')]){_0xb75faa[_0xd236('0x2c')]+=0x1;}if(!_0xb75faa[_0xd236('0x31')]&&_0xb75faa[_0xd236('0x32')]){_0xb75faa['talking']+=0x1;if(_0xb75faa[_0xd236('0x2c')]){_0xb75faa[_0xd236('0x2c')]-=0x1;}}if(_0xb75faa[_0xd236('0x31')]&&_0xb75faa['UserId']){_0xb75faa[_0xd236('0x2e')]+=0x1;if(_0xb75faa[_0xd236('0x2d')]){_0xb75faa[_0xd236('0x2d')]-=0x1;}}if(_0xb75faa[_0xd236('0x31')]&&!_0xb75faa[_0xd236('0x32')]){_0xb75faa[_0xd236('0x2f')]+=0x1;if(_0xb75faa['waiting']){_0xb75faa[_0xd236('0x2c')]-=0x1;}}_0xb75faa[_0xd236('0x30')]+=0x1;_0x366128(_0xb75faa);});}exports[_0xd236('0x33')]=function(_0x3c798f,_0x3c74f1){var _0x222495={},_0x4a9d27={},_0x35b950={'count':0x0,'rows':[]};var _0x2cd22e=_[_0xd236('0x1e')](db['MailInteraction'][_0xd236('0x34')],function(_0x5a8b18){return{'name':_0x5a8b18[_0xd236('0x35')],'type':_0x5a8b18['type']['key']};});_0x4a9d27[_0xd236('0x36')]=_[_0xd236('0x1e')](_0x2cd22e,_0xd236('0x1c'));_0x4a9d27[_0xd236('0x37')]=_[_0xd236('0x38')](_0x3c798f['query']);_0x4a9d27['filters']=_[_0xd236('0x39')](_0x4a9d27[_0xd236('0x36')],_0x4a9d27['query']);_0x222495[_0xd236('0x3a')]=_[_0xd236('0x39')](_0x4a9d27[_0xd236('0x36')],qs['fields'](_0x3c798f['query']['fields']));_0x222495[_0xd236('0x3a')]=_0x222495['attributes']['length']?_0x222495[_0xd236('0x3a')]:_0x4a9d27[_0xd236('0x36')];if(!_0x3c798f[_0xd236('0x37')][_0xd236('0x3b')](_0xd236('0x3c'))){_0x222495['limit']=qs['limit'](_0x3c798f[_0xd236('0x37')][_0xd236('0x16')]);_0x222495[_0xd236('0x14')]=qs[_0xd236('0x14')](_0x3c798f[_0xd236('0x37')][_0xd236('0x14')]);}_0x222495['order']=qs[_0xd236('0x3d')](_0x3c798f['query'][_0xd236('0x3d')]);_0x222495[_0xd236('0x3e')]=qs['filters'](_['pick'](_0x3c798f['query'],_0x4a9d27['filters']),_0x2cd22e);var _0x43ba74=[];var _0x11afc6=squel[_0xd236('0x3f')]()[_0xd236('0x40')]('id')[_0xd236('0x40')]('name')['field'](_0xd236('0x41'))[_0xd236('0x42')](_0xd236('0x43'));var _0x208548=squel[_0xd236('0x3f')]()[_0xd236('0x40')]('u.id')[_0xd236('0x40')]('u.fullname')[_0xd236('0x40')](_0xd236('0x44'))['from'](_0xd236('0x45'),'ui')[_0xd236('0x46')]('users','u','u.id\x20=\x20ui.UserId');var _0x135cfc=squel[_0xd236('0x3f')]()[_0xd236('0x42')](_0xd236('0x47'),'i')['left_join'](_0xd236('0x48'),'c',_0xd236('0x49'))[_0xd236('0x46')](_0xd236('0x4a'),'o',_0xd236('0x4b'))[_0xd236('0x46')]('mail_accounts','a','a.id\x20=\x20i.MailAccountId')[_0xd236('0x46')]('mail_messages','me',_0xd236('0x4c'))[_0xd236('0x46')]('mail_interaction_has_tags','it',_0xd236('0x4d'))[_0xd236('0x46')]('tools_tags','t',_0xd236('0x4e'));var _0x2d6549=squel[_0xd236('0x4f')]();var _0x3246b9=[];var _0x5b9337=squel['expr']();var _0x20b51b;if(_0x3c798f[_0xd236('0x37')]['search']){_0x20b51b=as[_0xd236('0x50')](_0x3c798f[_0xd236('0x37')][_0xd236('0x51')]);var _0x26b0c9=_0x20b51b[_0xd236('0x52')];for(var _0x54f23f=0x0;_0x54f23f<_0x20b51b[_0xd236('0x53')][_0xd236('0x54')];_0x54f23f++){var _0x2eefac=_0x20b51b['conditions'][_0x54f23f];var _0x284e3f='i';var _0x524d53=_['find'](_0x2cd22e,[_0xd236('0x1c'),_0x2eefac[_0xd236('0x40')]]);if(!_0x524d53){switch(_0x2eefac[_0xd236('0x40')]){case _0xd236('0x55'):if(_0x2eefac[_0xd236('0x56')]==0x1){_0x135cfc[_0xd236('0x57')]('`'+_0x2eefac[_0xd236('0x40')]+'`\x20=\x200');}else{_0x135cfc[_0xd236('0x57')]('`'+_0x2eefac[_0xd236('0x40')]+_0xd236('0x58'));}break;case _0xd236('0x59'):if(_0x2eefac[_0xd236('0x5a')]===_0xd236('0x5b')){if(_0x2eefac['value'][_0xd236('0x22')]('\x20')[_0xd236('0x54')]>0x1){_0x2d6549[_0x26b0c9](_0xd236('0x5c'),qs['getFullTextValue'](_0x2eefac[_0xd236('0x56')]),null);}else{var _0x6f83a2='%'+_0x2eefac[_0xd236('0x56')]+'%';_0x2d6549[_0x26b0c9]('c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?',_0x6f83a2,_0x6f83a2,_0x6f83a2);}}else{_0x524d53=_[_0xd236('0x5d')](_0x2cd22e,[_0xd236('0x1c'),_0xd236('0x5e')]);_0x2eefac[_0xd236('0x40')]='ContactId';_0x13e6cd=as[_0xd236('0x5f')](_0x284e3f,_0x524d53['type'],_0x2eefac);_0x2d6549[_0x26b0c9](_0x13e6cd[_0xd236('0x60')],_0x13e6cd['value'][_0xd236('0x61')],_0x13e6cd['value'][_0xd236('0x11')]);}break;case _0xd236('0x62'):var _0x5a1653=_0x2eefac[_0xd236('0x56')]['split'](',')[_0xd236('0x1e')](function(_0xe32357){return Number(_0xe32357);});_0x5a1653['forEach'](function(_0xc0c0f0){_0x5b9337['or'](_0xd236('0x63'),'%,'+_0xc0c0f0+',%');});_0x3246b9=_['union'](_0x3246b9,_0x5a1653);break;case'User':if(_0x2eefac[_0xd236('0x5a')]===_0xd236('0x5b')){_0x2d6549[_0x26b0c9]('CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','%'+_0x2eefac[_0xd236('0x56')]+'%',null);}else{_0x524d53=_['find'](_0x2cd22e,[_0xd236('0x1c'),_0xd236('0x32')]);_0x2eefac['field']=_0xd236('0x32');_0x13e6cd=as[_0xd236('0x5f')](_0x284e3f,_0x524d53[_0xd236('0x64')],_0x2eefac);_0x2d6549[_0x26b0c9](_0x13e6cd[_0xd236('0x60')],_0x13e6cd['value'][_0xd236('0x61')],_0x13e6cd[_0xd236('0x56')][_0xd236('0x11')]);}break;case'plainBody':_0x13e6cd=as[_0xd236('0x5f')]('me',null,_0x2eefac);_0x2d6549[_0x26b0c9](_0x13e6cd['text'],_0x13e6cd[_0xd236('0x56')][_0xd236('0x61')],_0x13e6cd[_0xd236('0x56')]['end']);break;}}else{var _0x13e6cd=as[_0xd236('0x5f')](_0x284e3f,_0x524d53[_0xd236('0x64')],_0x2eefac);_0x2d6549[_0x26b0c9](_0x13e6cd[_0xd236('0x60')],_0x13e6cd['value'][_0xd236('0x61')],_0x13e6cd[_0xd236('0x56')][_0xd236('0x11')]);}}}else{var _0x350711=_(_0x3c798f['query'])[_0xd236('0x38')]()[_0xd236('0x1e')](function(_0x5ec566){return _['some'](_0x2cd22e,[_0xd236('0x1c'),_0x5ec566])?_0x5ec566:undefined;})[_0xd236('0x65')]()[_0xd236('0x56')]();if(!_[_0xd236('0x66')](_0x350711)){_0x350711[_0xd236('0x23')](function(_0x372d9a){if(_0x372d9a===_0xd236('0x67')){_0x135cfc[_0xd236('0x3e')]('i.MailAccountId\x20IN\x20?',[][_0xd236('0x68')](_0x3c798f[_0xd236('0x37')][_0x372d9a]));}else if(_0x372d9a==='createdAt'){var _0x11712e=JSON[_0xd236('0x69')](_0x3c798f['query'][_0x372d9a])[_0xd236('0x6a')];var _0x1cdc97=JSON['parse'](_0x3c798f[_0xd236('0x37')][_0x372d9a])[_0xd236('0x6b')];_0x135cfc[_0xd236('0x3e')]('i.createdAt\x20BETWEEN\x20?\x20AND\x20?',_0x11712e,_0x1cdc97);}else{if(_0x3c798f['query'][_0x372d9a]==='null'){_0x135cfc[_0xd236('0x3e')]('i.'+_0x372d9a+'\x20IS\x20NULL');}else{_0x135cfc['where']('i.'+_0x372d9a+_0xd236('0x6c'),_0x3c798f[_0xd236('0x37')][_0x372d9a]);}}});}if(_0x3c798f[_0xd236('0x37')][_0xd236('0x6d')]){if(_0x3c798f['query'][_0xd236('0x6d')]==0x1){_0x135cfc[_0xd236('0x57')](_0xd236('0x6e'));}else{_0x135cfc['having'](_0xd236('0x6f'));}}if(_0x3c798f[_0xd236('0x37')][_0xd236('0x70')]){_0x3246b9=_[_0xd236('0x71')](_0x3c798f[_0xd236('0x37')]['tag'])?_0x3c798f['query'][_0xd236('0x70')]:new Array(_0x3c798f['query'][_0xd236('0x70')]);_0x3246b9[_0xd236('0x23')](function(_0x114afa){_0x5b9337['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x114afa+',%');});}if(_0x3c798f[_0xd236('0x37')][_0xd236('0x72')]){var _0x516bb1=_0x3c798f[_0xd236('0x37')][_0xd236('0x72')]['replace']('\x5c','\x5c\x5c')[_0xd236('0x73')](/'/g,'\x27\x27');if(qs[_0xd236('0x74')](_0x516bb1)){_0x2d6549['or']('i.id\x20LIKE\x20?',_0x516bb1+'%');}else if(qs['isEmail'](_0x516bb1)){_0x2d6549['or'](_0xd236('0x75'),_0x516bb1+'%');}else{_0x2d6549['or'](_0xd236('0x76'),qs['getFullTextValue'](_0x516bb1))['or'](_0xd236('0x77'),qs['getFullTextValue'](_0x516bb1));}}}_0x135cfc[_0xd236('0x3e')](_0x2d6549);_0x135cfc[_0xd236('0x78')]('i.id');var _0x26f817={'type':db[_0xd236('0x79')]['QueryTypes'][_0xd236('0x7a')],'raw':!![]};var _0x5864d9=_0x135cfc[_0xd236('0x7b')]();_0x5864d9[_0xd236('0x40')](_0xd236('0x7c'));_0x5864d9[_0xd236('0x40')]('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','unreadMessages');if(_0x222495[_0xd236('0x7d')]){_0x222495['order'][_0xd236('0x23')](function(_0x1677b1){var _0x58d0a0=_0x1677b1[0x0]===_0xd236('0x7e')?_0x1677b1[0x0]:'i.'+_0x1677b1[0x0];_0x135cfc[_0xd236('0x7d')](_0x58d0a0,_0x1677b1[0x1]==='DESC'?![]:!![]);});}if(!_[_0xd236('0x66')](_0x3246b9)){_0x135cfc[_0xd236('0x57')](_0x5b9337);_0x5864d9[_0xd236('0x3e')]('t.id\x20IN\x20?',_0x3246b9);}BPromise['resolve']()[_0xd236('0x1a')](function(){if(!_0x20b51b){if(_0x3c798f[_0xd236('0x37')][_0xd236('0x67')])return;_0x5864d9[_0xd236('0x3e')]('i.MailAccountId\x20IS\x20NOT\x20NULL');_0x135cfc[_0xd236('0x3e')]('i.MailAccountId\x20IS\x20NOT\x20NULL');return;}if(_0x3c798f['user'][_0xd236('0x7f')]!=='agent')return;return _0x3c798f[_0xd236('0x80')]['getMailAccounts']({'attributes':['id'],'raw':!![]})[_0xd236('0x1a')](function(_0x7f9b05){if(_[_0xd236('0x66')](_0x7f9b05)){_0x5864d9[_0xd236('0x3e')](_0xd236('0x81'));_0x135cfc['where'](_0xd236('0x81'));}else{_0x5864d9[_0xd236('0x3e')](_0xd236('0x82'),_[_0xd236('0x1e')](_0x7f9b05,'id'));_0x135cfc['where'](_0xd236('0x82'),_[_0xd236('0x1e')](_0x7f9b05,'id'));}});})[_0xd236('0x1a')](function(){if(_0x3c798f[_0xd236('0x80')][_0xd236('0x7f')]===_0xd236('0x83')&&!_0x20b51b&&!_0x3c798f[_0xd236('0x37')][_0xd236('0x67')])return[];return db[_0xd236('0x84')][_0xd236('0x37')](_0x5864d9[_0xd236('0x85')](),_0x26f817);})[_0xd236('0x1a')](function(_0x487546){_0x35b950[_0xd236('0x17')]=_0x487546[_0xd236('0x54')];if(_0x35b950[_0xd236('0x17')]===0x0)return[];return db[_0xd236('0x84')][_0xd236('0x37')](_0x11afc6[_0xd236('0x85')](),_0x26f817)[_0xd236('0x1a')](function(_0x4a4339){_0x43ba74=_['keyBy'](_0x4a4339,'id');_0x26f817=_['merge'](_0x26f817,{'model':db[_0xd236('0x86')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x3c798f[_0xd236('0x37')]['fields']){_0x222495[_0xd236('0x3a')][_0xd236('0x23')](function(_0x6f16c6){_0x135cfc[_0xd236('0x40')]('i.'+_0x6f16c6);});}else{_0x135cfc['field'](_0xd236('0x87'),_0xd236('0x55'));_0x135cfc[_0xd236('0x40')](_0xd236('0x88'),_0xd236('0x89'));_0x135cfc[_0xd236('0x40')](_0xd236('0x8a'),_0xd236('0x8b'));_0x135cfc[_0xd236('0x40')]('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');_0x135cfc[_0xd236('0x40')](_0xd236('0x7c'));_0x135cfc['field'](_0xd236('0x8c'));_0x135cfc[_0xd236('0x40')]('i.updatedAt');_0x135cfc[_0xd236('0x40')]('i.closed');_0x135cfc['field'](_0xd236('0x8d'));_0x135cfc[_0xd236('0x40')](_0xd236('0x8e'));_0x135cfc['field'](_0xd236('0x8f'));_0x135cfc[_0xd236('0x40')](_0xd236('0x90'));_0x135cfc[_0xd236('0x40')](_0xd236('0x91'));_0x135cfc[_0xd236('0x40')]('i.disposition');_0x135cfc[_0xd236('0x40')](_0xd236('0x92'));_0x135cfc[_0xd236('0x40')](_0xd236('0x93'));_0x135cfc['field'](_0xd236('0x94'));_0x135cfc[_0xd236('0x40')](_0xd236('0x95'));_0x135cfc[_0xd236('0x40')](_0xd236('0x96'));_0x135cfc['field'](_0xd236('0x97'));_0x135cfc[_0xd236('0x40')](_0xd236('0x98'));_0x135cfc['field'](_0xd236('0x99'),'Contact.firstName');_0x135cfc['field'](_0xd236('0x9a'),_0xd236('0x9b'));_0x135cfc[_0xd236('0x40')](_0xd236('0x9c'),_0xd236('0x9d'));_0x135cfc[_0xd236('0x40')]('c.phone',_0xd236('0x9e'));_0x135cfc[_0xd236('0x40')]('c.mobile',_0xd236('0x9f'));_0x135cfc[_0xd236('0x40')]('c.fax',_0xd236('0xa0'));_0x135cfc[_0xd236('0x40')](_0xd236('0xa1'),'Owner.fullname');_0x135cfc[_0xd236('0x40')](_0xd236('0xa2'),_0xd236('0xa3'));_0x135cfc[_0xd236('0x40')](_0xd236('0xa4'),_0xd236('0x20'));}if(_0x222495[_0xd236('0x16')])_0x135cfc[_0xd236('0x16')](_0x222495[_0xd236('0x16')]);if(_0x222495['offset'])_0x135cfc[_0xd236('0x14')](_0x222495[_0xd236('0x14')]);return db[_0xd236('0x84')][_0xd236('0x37')](_0x135cfc[_0xd236('0x85')](),_0x26f817);})[_0xd236('0x1a')](function(_0x491807){if(_0x491807[_0xd236('0x54')]>0x0)_0x208548[_0xd236('0x3e')]('ui.MailInteractionId\x20IN\x20?',_['map'](_0x491807,'id'));return db[_0xd236('0x84')]['query'](_0x208548[_0xd236('0x85')](),_0x26f817)['then'](function(_0x45d366){var _0x1d9e32=_[_0xd236('0xa5')](_0x45d366,'MailInteractionId');var _0x5bb55c=[];return db[_0xd236('0xa6')]['findOne']({'attributes':['enableEmailPreview'],'raw':!![]})[_0xd236('0x1a')](function(_0x5680a3){var _0x530560=_0x5680a3['enableEmailPreview'];_0x491807[_0xd236('0x23')](function(_0xa3995f){_0x5bb55c['push'](updateMailInteraction(_0xa3995f,_0x43ba74,_0x1d9e32,_0x530560));});return BPromise['all'](_0x5bb55c);});});});})[_0xd236('0x1a')](function(_0x175b35){_0x35b950[_0xd236('0xa7')]=_0x175b35;return _0x35b950;})[_0xd236('0x1a')](respondWithFilteredResult(_0x3c74f1,_0x222495))[_0xd236('0x2b')](handleError(_0x3c74f1,null));};exports[_0xd236('0xa8')]=function(_0x36697b,_0x4710d8){var _0x399309={'raw':![],'where':{'id':_0x36697b['params']['id']}},_0x3889a3={};_0x3889a3[_0xd236('0x36')]=_[_0xd236('0x38')](db[_0xd236('0x86')][_0xd236('0x34')]);_0x3889a3[_0xd236('0x37')]=_[_0xd236('0x38')](_0x36697b[_0xd236('0x37')]);_0x3889a3['filters']=_[_0xd236('0x39')](_0x3889a3[_0xd236('0x36')],_0x3889a3['query']);_0x399309[_0xd236('0x3a')]=_[_0xd236('0x39')](_0x3889a3[_0xd236('0x36')],qs[_0xd236('0xa9')](_0x36697b[_0xd236('0x37')][_0xd236('0xa9')]));_0x399309[_0xd236('0x3a')]=_0x399309[_0xd236('0x3a')][_0xd236('0x54')]?_0x399309[_0xd236('0x3a')]:_0x3889a3[_0xd236('0x36')];if(_0x36697b[_0xd236('0x37')][_0xd236('0xaa')]){_0x399309[_0xd236('0xab')]=[{'all':!![]}];}_0x399309=_[_0xd236('0xac')]({},_0x399309,_0x36697b['options']);return db[_0xd236('0x86')][_0xd236('0x5d')](_0x399309)[_0xd236('0x1a')](handleEntityNotFound(_0x4710d8,null))[_0xd236('0x1a')](respondWithResult(_0x4710d8,null))[_0xd236('0x2b')](handleError(_0x4710d8,null));};exports[_0xd236('0xad')]=function(_0x2577d0,_0x3e9162){return db[_0xd236('0x86')][_0xd236('0xad')](_0x2577d0['body'],{})['then'](respondWithResult(_0x3e9162,0xc9))[_0xd236('0x2b')](handleError(_0x3e9162,null));};exports[_0xd236('0x19')]=function(_0x3c3e73,_0x3d0378){if(_0x3c3e73[_0xd236('0xae')]['id']){delete _0x3c3e73[_0xd236('0xae')]['id'];}return db[_0xd236('0x86')]['find']({'where':{'id':_0x3c3e73[_0xd236('0xaf')]['id']}})[_0xd236('0x1a')](handleEntityNotFound(_0x3d0378,null))['then'](saveUpdates(_0x3c3e73['body'],null))[_0xd236('0x1a')](respondWithResult(_0x3d0378,null))[_0xd236('0x2b')](handleError(_0x3d0378,null));};exports[_0xd236('0x1b')]=function(_0x592eae,_0x2c4598){return db['MailInteraction'][_0xd236('0x5d')]({'where':{'id':_0x592eae[_0xd236('0xaf')]['id']}})[_0xd236('0x1a')](handleEntityNotFound(_0x2c4598,null))[_0xd236('0x1a')](removeEntity(_0x2c4598,null))[_0xd236('0x2b')](handleError(_0x2c4598,null));};exports['describe']=function(_0x591378,_0x1f1fcb){return db[_0xd236('0x86')][_0xd236('0xb0')]()[_0xd236('0x1a')](respondWithResult(_0x1f1fcb,null))['catch'](handleError(_0x1f1fcb,null));};exports[_0xd236('0xb1')]=function(_0x192a5a,_0x1cb3c8){return db[_0xd236('0x25')][_0xd236('0x5d')]({'where':{'id':_0x192a5a[_0xd236('0xaf')]['id']}})[_0xd236('0x1a')](handleEntityNotFound(_0x1cb3c8,null))[_0xd236('0x1a')](function(_0x2748d9){if(_0x2748d9){return _0x2748d9[_0xd236('0xb1')](_0x192a5a[_0xd236('0xae')][_0xd236('0xb2')],_[_0xd236('0xb3')](_0x192a5a[_0xd236('0xae')],[_0xd236('0xb2'),'id'])||{});}})['then'](respondWithResult(_0x1cb3c8,null))[_0xd236('0x2b')](handleError(_0x1cb3c8,null));};exports[_0xd236('0xb4')]=function(_0x5c2fbd,_0x2d0759){var _0x1d4aac={'raw':![],'where':{}};var _0x35db65={};var _0x5580aa={'count':0x0,'rows':[]};return db[_0xd236('0x86')]['findOne']({'where':{'id':_0x5c2fbd[_0xd236('0xaf')]['id']}})['then'](handleEntityNotFound(_0x2d0759,null))[_0xd236('0x1a')](function(_0x275928){if(_0x275928){_0x35db65[_0xd236('0x36')]=_[_0xd236('0x38')](db[_0xd236('0x25')][_0xd236('0x34')]);_0x35db65[_0xd236('0x37')]=_['keys'](_0x5c2fbd['query']);_0x35db65[_0xd236('0xb5')]=_[_0xd236('0x39')](_0x35db65[_0xd236('0x36')],_0x35db65[_0xd236('0x37')]);_0x1d4aac[_0xd236('0x3a')]=_[_0xd236('0x39')](_0x35db65[_0xd236('0x36')],qs[_0xd236('0xa9')](_0x5c2fbd['query'][_0xd236('0xa9')]));_0x1d4aac[_0xd236('0x3a')]=_0x1d4aac[_0xd236('0x3a')][_0xd236('0x54')]?_0x1d4aac[_0xd236('0x3a')]:_0x35db65[_0xd236('0x36')];if(!_0x5c2fbd[_0xd236('0x37')][_0xd236('0x3b')]('nolimit')){_0x1d4aac['limit']=qs[_0xd236('0x16')](_0x5c2fbd[_0xd236('0x37')]['limit']);_0x1d4aac['offset']=qs['offset'](_0x5c2fbd[_0xd236('0x37')][_0xd236('0x14')]);}_0x1d4aac[_0xd236('0x7d')]=qs['sort'](_0x5c2fbd[_0xd236('0x37')]['sort']);_0x1d4aac[_0xd236('0x3e')]=qs[_0xd236('0xb5')](_[_0xd236('0xb6')](_0x5c2fbd['query'],_0x35db65[_0xd236('0xb5')]));_0x1d4aac['where'][_0xd236('0xb7')]=_0x275928['id'];if(_0x5c2fbd[_0xd236('0x37')][_0xd236('0x72')]){_0x1d4aac[_0xd236('0x3e')]=_[_0xd236('0xac')](_0x1d4aac[_0xd236('0x3e')],{'$or':_[_0xd236('0x1e')](_0x1d4aac['attributes'],function(_0x2ccb10){var _0x25d144={};_0x25d144[_0x2ccb10]={'$like':'%'+_0x5c2fbd[_0xd236('0x37')]['filter']+'%'};return _0x25d144;})});}if(_0x5c2fbd[_0xd236('0x37')]['$gte']){var _0x3ca52a=_0x5c2fbd[_0xd236('0x37')][_0xd236('0x6a')][_0xd236('0x22')](',');var _0x72c65b={};_0x72c65b[_0x3ca52a[0x0]]={'$gte':moment(_0x3ca52a[0x1])['format']('YYYY-MM-DD\x20HH:mm:ss')};_0x1d4aac[_0xd236('0x3e')]=_[_0xd236('0xac')](_0x1d4aac[_0xd236('0x3e')],_0x72c65b);}_0x1d4aac=_[_0xd236('0xac')]({},_0x1d4aac,_0x5c2fbd[_0xd236('0xb8')]);return db['MailMessage'][_0xd236('0x17')]({'where':_0x1d4aac[_0xd236('0x3e')]})['then'](function(_0x4a973e){_0x5580aa[_0xd236('0x17')]=_0x4a973e;if(_0x5c2fbd['query'][_0xd236('0xaa')]){_0x1d4aac[_0xd236('0xab')]=[{'all':!![]}];}return db[_0xd236('0x25')][_0xd236('0xb9')](_0x1d4aac);})[_0xd236('0x1a')](function(_0x517093){if(_0x5c2fbd[_0xd236('0x37')][_0xd236('0xba')]===_0xd236('0xbb')){for(var _0x49db9b=0x0;_0x49db9b<_0x517093[_0xd236('0x54')];_0x49db9b++){_0x517093[_0x49db9b][_0xd236('0xae')]=juice(_0x517093[_0x49db9b][_0xd236('0xae')]);}}_0x5580aa[_0xd236('0xa7')]=_0x517093;return _0x5580aa;});}})[_0xd236('0x1a')](respondWithFilteredResult(_0x2d0759,_0x1d4aac))[_0xd236('0x2b')](handleError(_0x2d0759,null));};exports[_0xd236('0xbc')]=function(_0x3d5640,_0x5675cd){return db[_0xd236('0x86')][_0xd236('0x5d')]({'where':{'id':_0x3d5640[_0xd236('0xaf')]['id']}})[_0xd236('0x1a')](handleEntityNotFound(_0x5675cd,null))[_0xd236('0x1a')](function(_0x417baf){if(_0x417baf){return _0x417baf[_0xd236('0xbd')](_0x3d5640['body']['ids'],_[_0xd236('0xb3')](_0x3d5640[_0xd236('0xae')],[_0xd236('0xb2'),'id'])||{})[_0xd236('0xbe')](function(){return db[_0xd236('0x62')]['findAll']({'attributes':['id',_0xd236('0x1c'),_0xd236('0x41')],'where':{'id':_0x3d5640[_0xd236('0xae')][_0xd236('0xb2')]}});})[_0xd236('0x1a')](function(_0x463d8e){socket[_0xd236('0xbf')]('mailInteractionTags:save',{'id':Number(_0x3d5640[_0xd236('0xaf')]['id']),'tags':_0x463d8e||[]});return{'id':Number(_0x3d5640[_0xd236('0xaf')]['id']),'tags':_0x463d8e||[]};});}})[_0xd236('0x1a')](respondWithResult(_0x5675cd,null))[_0xd236('0x2b')](handleError(_0x5675cd,null));};exports[_0xd236('0xc0')]=function(_0x79f609,_0x20186a){return db['MailInteraction'][_0xd236('0x5d')]({'where':{'id':_0x79f609[_0xd236('0xaf')]['id']}})[_0xd236('0x1a')](handleEntityNotFound(_0x20186a,null))[_0xd236('0x1a')](function(_0x4af2c5){if(_0x4af2c5){return _0x4af2c5['removeTags'](_0x79f609['query'][_0xd236('0xb2')]);}})[_0xd236('0x1a')](respondWithStatusCode(_0x20186a,null))['catch'](handleError(_0x20186a,null));};exports[_0xd236('0xc1')]=function(_0x7b1bf1,_0x3a48ca){var _0x3ff47e=moment()['unix']()['toString']();var _0x5575cd=path[_0xd236('0xc2')](config[_0xd236('0xc3')],_0xd236('0xc4'),_0xd236('0xc5'),'tmp');var _0xd4b52d=path['join'](config['root'],_0xd236('0xc4'),'files',_0xd236('0xc6'));var _0x463764=path['join'](_0x5575cd,_0x3ff47e);var _0x3f72ad=util['format']('transcript-%d-%s.zip',_0x7b1bf1[_0xd236('0xaf')]['id'],_0x3ff47e);var _0x922e0e=path[_0xd236('0xc2')](_0x5575cd,_0x3f72ad);var _0x4f4996=[];if(_0x7b1bf1['query'][_0xd236('0xc6')]){_0x4f4996[_0xd236('0x24')]({'model':db[_0xd236('0xc7')],'as':'Attachments','raw':!![]});}var _0x1a6e2f=[{'model':db[_0xd236('0x25')],'as':_0xd236('0xc8'),'attributes':['id',_0xd236('0xae'),_0xd236('0x42'),'to','cc','bcc',_0xd236('0xc9'),_0xd236('0xca')],'where':{'secret':![]},'order':qs[_0xd236('0x3d')]('id'),'include':_0x4f4996}];return db[_0xd236('0x86')][_0xd236('0x5d')]({'where':{'id':_0x7b1bf1['params']['id']},'include':_0x1a6e2f})[_0xd236('0x1a')](handleEntityNotFound(_0x3a48ca,null))[_0xd236('0x1a')](function(_0x586d6e){if(_0x586d6e&&_0x586d6e[_0xd236('0xc8')]){var _0x5beaee=_0x586d6e[_0xd236('0xcb')]({'plain':!![]});fs[_0xd236('0xcc')](_0x463764);return BPromise[_0xd236('0xcd')](_0x5beaee['Messages'],function(_0x16f7cb,_0x3c1ff1){var _0xa831ea={'from':_0x16f7cb['from'],'to':_0x16f7cb['to'],'subject':_0x16f7cb[_0xd236('0xc9')],'html':htmlEntities[_0xd236('0xce')](_0x16f7cb[_0xd236('0xae')]),'headers':{'Date':moment(_0x16f7cb[_0xd236('0xca')])['format']('ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ')},'attachments':[]};if(_0x16f7cb['cc']){_0xa831ea[_0xd236('0xcf')]['Cc']=_0x16f7cb['cc'];}if(_0x16f7cb[_0xd236('0xd0')]){_0xa831ea[_0xd236('0xcf')]['Bcc']=_0x16f7cb[_0xd236('0xd0')];}return new BPromise(function(_0x22ace9,_0x2c49f7){if(_0x16f7cb[_0xd236('0xd1')]){for(var _0x51f67e=0x0;_0x51f67e<_0x16f7cb[_0xd236('0xd1')]['length'];_0x51f67e++){var _0x3d7dc0=_0x16f7cb[_0xd236('0xd1')][_0x51f67e];var _0x1bfb28=path[_0xd236('0xc2')](_0xd4b52d,_0x3d7dc0[_0xd236('0xd2')]);if(fs['existsSync'](_0x1bfb28)){_0xa831ea[_0xd236('0xc6')][_0xd236('0x24')]({'name':_0x3d7dc0[_0xd236('0x1c')],'contentType':_0x3d7dc0['type'],'data':fs[_0xd236('0xd3')](_0x1bfb28)});}}}emlformat[_0xd236('0xd4')](_0xa831ea,function(_0x260a1d,_0x14692a){if(_0x260a1d)return _0x2c49f7(_0x260a1d);fs[_0xd236('0xd5')](path[_0xd236('0xc2')](_0x463764,util[_0xd236('0xd6')](_0xd236('0xd7'),_0x3c1ff1)),_0x14692a);return _0x22ace9(_0x14692a);});});})[_0xd236('0x1a')](function(){return new BPromise(function(_0x8caef1,_0x247f4a){zipdir(_0x463764,{'saveTo':_0x922e0e},function(_0x4d3958,_0x11045c){if(_0x4d3958)return _0x247f4a(_0x4d3958);return _0x8caef1(_0x11045c);});})['then'](function(){return new BPromise(function(_0x8e697f,_0x40360f){rimraf(_0x463764,function(_0x464e3b){if(_0x464e3b)_0x40360f(_0x464e3b);return _0x8e697f();});});})[_0xd236('0x1a')](function(){return _0x3a48ca['download'](_0x922e0e,_0x3f72ad,function(_0x5d8108){if(!_0x5d8108)fs[_0xd236('0xd8')](_0x922e0e);});});});}else{return _0x3a48ca[_0xd236('0x10')](0xc8);}})[_0xd236('0x2b')](handleError(_0x3a48ca,null));};
\ No newline at end of file