Built motion from commit 14588770.|2.5.38
[motion2.git] / server / api / mailInteraction / mailInteraction.controller.js
index 3edd2d9..d0e0480 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xf491=['mail_messages','mail_interaction_has_tags','it.MailInteractionId\x20=\x20i.id','t.id\x20=\x20it.TagId','expr','search','parseSearch','sqlOperator','length','conditions','unreadMessages','value','having','`\x20=\x200','`\x20>\x200','Contact','operator','$substring','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','getFullTextValue','c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?','find','ContactId','text','start','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','union','User','UserId','buildExpression','plainBody','some','compact','isEmpty','MailAccountId','where','i.MailAccountId\x20IN\x20?','concat','parse','$gte','$lte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20IS\x20NULL','read','`unreadMessages`\x20=\x200','`unreadMessages`\x20>\x200','tag','filter','\x27\x27\x27\x27','isNumeric','isEmail','MATCH\x20(i.to,\x20i.subject)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','i.id','Sequelize','QueryTypes','SELECT','clone','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','t.id\x20IN\x20?','journey','i.MailAccountId\x20IS\x20NOT\x20NULL','user','i.MailAccountId\x20IS\x20NULL','sequelize','toString','merge','Account.key','a.mandatoryDisposition','Account.mandatoryDisposition','i.createdAt','i.closedAt','i.attach','i.lastMsgDirection','i.subject','i.disposition','i.substatus','i.to','i.ContactId','i.MailAccountId','c.firstName','c.lastName','Contact.lastName','Contact.phone','c.mobile','c.fax','Contact.fax','Owner.fullname','o.internal','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','groupBy','enableEmailPreview','all','rows','show','params','rawAttributes','includeAll','include','options','body','describe','MailMessage','addMessage','ids','omit','getMessages','hasOwnProperty','nolimit','pick','MailInteractionId','format','YYYY-MM-DD\x20HH:mm:ss','addTags','setTags','Tag','findAll','emit','mailInteractionTags:save','removeTags','unix','root','server','tmp','join','files','attachments','transcript-%d-%s.zip','Attachment','Messages','subject','createdAt','get','mkdirSync','ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ','bcc','Bcc','Attachments','basename','existsSync','readFileSync','build','writeFileSync','download','log','html-pdf','eml-format','rimraf','request-promise','bluebird','util','path','sox','lodash','desk.js','to-csv','querystring','html-to-text','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','redis','defaults','localhost','socket.io-emitter','./mailInteraction.socket','register','end','count','offset','limit','set','json','apply','reject','save','update','destroy','status','error','stack','name','send','Users','map','TagIds','Tags','split','forEach','push','MailInteraction','findOne','lastMsgBody','lastMsgText','then','trimStart','fromString','catch','fieldName','type','model','query','keys','filters','intersection','attributes','fields','order','sort','select','field','color','from','tools_tags','u.id','u.fullname','ui.MailInteractionId','user_has_mail_interactions','left_join','users','u.id\x20=\x20ui.UserId','mail_interactions','cm_contacts','o.id\x20=\x20i.UserId','a.id\x20=\x20i.MailAccountId'];(function(_0x51dbba,_0x817f0d){var _0x34906d=function(_0x192a8b){while(--_0x192a8b){_0x51dbba['push'](_0x51dbba['shift']());}};_0x34906d(++_0x817f0d);}(_0xf491,0x178));var _0x1f49=function(_0x54ea4f,_0x472285){_0x54ea4f=_0x54ea4f-0x0;var _0x4315b5=_0xf491[_0x54ea4f];return _0x4315b5;};'use strict';var pdf=require(_0x1f49('0x0'));var emlformat=require(_0x1f49('0x1'));var rimraf=require(_0x1f49('0x2'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x1f49('0x3'));var moment=require('moment');var BPromise=require(_0x1f49('0x4'));var Mustache=require('mustache');var util=require(_0x1f49('0x5'));var path=require(_0x1f49('0x6'));var sox=require(_0x1f49('0x7'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var _=require(_0x1f49('0x8'));var squel=require('squel');var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x1f49('0x9'));var toCsv=require(_0x1f49('0xa'));var querystring=require(_0x1f49('0xb'));var Papa=require('papaparse');var htmlToText=require(_0x1f49('0xc'));var Redis=require(_0x1f49('0xd'));var authService=require(_0x1f49('0xe'));var qs=require(_0x1f49('0xf'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x1f49('0x10'));var logger=require(_0x1f49('0x11'))(_0x1f49('0x12'));var utils=require(_0x1f49('0x13'));var config=require('../../config/environment');var db=require('../../mysqldb')['db'];config[_0x1f49('0x14')]=_[_0x1f49('0x15')](config[_0x1f49('0x14')],{'host':_0x1f49('0x16'),'port':0x18eb});var socket=require(_0x1f49('0x17'))(new Redis(config[_0x1f49('0x14')]));require(_0x1f49('0x18'))[_0x1f49('0x19')](socket);function respondWithStatusCode(_0x1121a2,_0x403bfd){_0x403bfd=_0x403bfd||0xcc;return function(_0x4b1764){if(_0x4b1764){return _0x1121a2['sendStatus'](_0x403bfd);}return _0x1121a2['status'](_0x403bfd)[_0x1f49('0x1a')]();};}function respondWithResult(_0x37948a,_0x118397){_0x118397=_0x118397||0xc8;return function(_0x1bc49b){if(_0x1bc49b){return _0x37948a['status'](_0x118397)['json'](_0x1bc49b);}};}function respondWithFilteredResult(_0x8c2793,_0x210bd1){return function(_0x5acdd1){if(_0x5acdd1){var _0x5cac84=_0x5acdd1[_0x1f49('0x1b')],_0x3e21a7=_0x210bd1[_0x1f49('0x1c')],_0x3f909a=_0x210bd1['offset']+_0x210bd1[_0x1f49('0x1d')],_0x2bf3ca;if(_0x3f909a>=_0x5cac84){_0x3f909a=_0x5cac84;_0x2bf3ca=0xc8;}else{_0x2bf3ca=0xce;}_0x8c2793['status'](_0x2bf3ca);return _0x8c2793[_0x1f49('0x1e')]('Content-Range',_0x3e21a7+'-'+_0x3f909a+'/'+_0x5cac84)[_0x1f49('0x1f')](_0x5acdd1);}return null;};}function patchUpdates(_0x1c3c7e){return function(_0x51f8f7){try{jsonpatch[_0x1f49('0x20')](_0x51f8f7,_0x1c3c7e,!![]);}catch(_0x245844){return BPromise[_0x1f49('0x21')](_0x245844);}return _0x51f8f7[_0x1f49('0x22')]();};}function saveUpdates(_0x286785,_0x38ece0){return function(_0x506383){if(_0x506383){return _0x506383[_0x1f49('0x23')](_0x286785)['then'](function(_0x3a05b3){return _0x3a05b3;});}return null;};}function removeEntity(_0xbb97c,_0x372421){return function(_0x47e9e4){if(_0x47e9e4){return _0x47e9e4[_0x1f49('0x24')]()['then'](function(){_0xbb97c[_0x1f49('0x25')](0xcc)[_0x1f49('0x1a')]();});}};}function handleEntityNotFound(_0x1077ac,_0x2b8f27){return function(_0x374142){if(!_0x374142){_0x1077ac['sendStatus'](0x194);}return _0x374142;};}function handleError(_0x20c586,_0x316b20){_0x316b20=_0x316b20||0x1f4;return function(_0x54d574){logger[_0x1f49('0x26')](_0x54d574[_0x1f49('0x27')]);if(_0x54d574['name']){delete _0x54d574[_0x1f49('0x28')];}_0x20c586[_0x1f49('0x25')](_0x316b20)[_0x1f49('0x29')](_0x54d574);};}function getInteractionUsers(_0x480331,_0x1034d2){return new BPromise(function(_0x5e5134,_0x310763){try{if(_0x1034d2[_0x480331['id']]){_0x480331[_0x1f49('0x2a')]=_[_0x1f49('0x2b')](_0x1034d2[_0x480331['id']],function(_0x5bd85a){return{'id':_0x5bd85a['id'],'fullname':_0x5bd85a['fullname']};});}}catch(_0x270f08){_0x310763(_0x270f08);}_0x5e5134(_0x480331);});}function getInteractionTags(_0x25084c,_0x2a8b08){return new BPromise(function(_0x27c348,_0x4ff31d){try{if(_0x25084c[_0x1f49('0x2c')]){_0x25084c[_0x1f49('0x2d')]=[];_0x25084c[_0x1f49('0x2c')][_0x1f49('0x2e')](',')[_0x1f49('0x2f')](function(_0x37ebb7){_0x25084c[_0x1f49('0x2d')][_0x1f49('0x30')](_0x2a8b08[_0x37ebb7]);});}delete _0x25084c[_0x1f49('0x2c')];}catch(_0x10e4e9){_0x4ff31d(_0x10e4e9);}_0x27c348(_0x25084c);});}function getLastMessageText(_0x4bf1be){return new BPromise(function(_0x51a47e,_0x4269a7){return db[_0x1f49('0x31')][_0x1f49('0x32')]({'where':{'id':_0x4bf1be['id']},'attributes':[_0x1f49('0x33'),_0x1f49('0x34')],'raw':!![]})[_0x1f49('0x35')](function(_0x59e0e3){if(!_0x59e0e3[_0x1f49('0x34')]){_0x4bf1be[_0x1f49('0x34')]=_[_0x1f49('0x36')](htmlToText[_0x1f49('0x37')](_0x59e0e3[_0x1f49('0x33')],{'preserveNewlines':!![],'singleNewLineParagraphs':!![],'uppercaseHeadings':![],'noLinkBrackets':!![],'ignoreImage':!![]}));}else{_0x4bf1be[_0x1f49('0x34')]=_0x59e0e3['lastMsgText'];}_0x51a47e(_0x4bf1be);})['catch'](function(_0x448b92){_0x4269a7(_0x448b92);});});}function updateMailInteraction(_0x233db8,_0x4db279,_0x31ec20,_0x5b7676){return new BPromise(function(_0xe2c2dc,_0xc55c7d){return getInteractionUsers(_0x233db8,_0x31ec20)['then'](function(_0x5d18dc){return getInteractionTags(_0x5d18dc,_0x4db279);})[_0x1f49('0x35')](function(_0x50f6d6){if(_0x5b7676){_0xe2c2dc(getLastMessageText(_0x50f6d6));}else{_0xe2c2dc(_0x50f6d6);}})[_0x1f49('0x38')](function(_0x4215a7){_0xc55c7d(_0x4215a7);});});}exports['index']=function(_0xb8e272,_0xdf8725){var _0x2f7306={},_0x142487={},_0x4ab9a4={'count':0x0,'rows':[]};var _0x78515d=_[_0x1f49('0x2b')](db[_0x1f49('0x31')]['rawAttributes'],function(_0x5cd08b){return{'name':_0x5cd08b[_0x1f49('0x39')],'type':_0x5cd08b[_0x1f49('0x3a')]['key']};});_0x142487[_0x1f49('0x3b')]=_[_0x1f49('0x2b')](_0x78515d,_0x1f49('0x28'));_0x142487[_0x1f49('0x3c')]=_[_0x1f49('0x3d')](_0xb8e272[_0x1f49('0x3c')]);_0x142487[_0x1f49('0x3e')]=_[_0x1f49('0x3f')](_0x142487[_0x1f49('0x3b')],_0x142487[_0x1f49('0x3c')]);_0x2f7306[_0x1f49('0x40')]=_[_0x1f49('0x3f')](_0x142487[_0x1f49('0x3b')],qs[_0x1f49('0x41')](_0xb8e272[_0x1f49('0x3c')][_0x1f49('0x41')]));_0x2f7306[_0x1f49('0x40')]=_0x2f7306[_0x1f49('0x40')]['length']?_0x2f7306[_0x1f49('0x40')]:_0x142487['model'];if(!_0xb8e272[_0x1f49('0x3c')]['hasOwnProperty']('nolimit')){_0x2f7306[_0x1f49('0x1d')]=qs['limit'](_0xb8e272[_0x1f49('0x3c')][_0x1f49('0x1d')]);_0x2f7306['offset']=qs['offset'](_0xb8e272[_0x1f49('0x3c')][_0x1f49('0x1c')]);}_0x2f7306[_0x1f49('0x42')]=qs[_0x1f49('0x43')](_0xb8e272[_0x1f49('0x3c')][_0x1f49('0x43')]);_0x2f7306['where']=qs['filters'](_['pick'](_0xb8e272[_0x1f49('0x3c')],_0x142487[_0x1f49('0x3e')]));var _0xb3089e=[];var _0x560cfd=squel[_0x1f49('0x44')]()[_0x1f49('0x45')]('id')[_0x1f49('0x45')](_0x1f49('0x28'))['field'](_0x1f49('0x46'))[_0x1f49('0x47')](_0x1f49('0x48'));var _0x1e8951=squel[_0x1f49('0x44')]()[_0x1f49('0x45')](_0x1f49('0x49'))['field'](_0x1f49('0x4a'))[_0x1f49('0x45')](_0x1f49('0x4b'))[_0x1f49('0x47')](_0x1f49('0x4c'),'ui')[_0x1f49('0x4d')](_0x1f49('0x4e'),'u',_0x1f49('0x4f'));var _0x2a42af=squel[_0x1f49('0x44')]()[_0x1f49('0x47')](_0x1f49('0x50'),'i')[_0x1f49('0x4d')](_0x1f49('0x51'),'c','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL')[_0x1f49('0x4d')](_0x1f49('0x4e'),'o',_0x1f49('0x52'))[_0x1f49('0x4d')]('mail_accounts','a',_0x1f49('0x53'))['left_join'](_0x1f49('0x54'),'me','me.MailInteractionId\x20=\x20i.id')['left_join'](_0x1f49('0x55'),'it',_0x1f49('0x56'))[_0x1f49('0x4d')](_0x1f49('0x48'),'t',_0x1f49('0x57'));var _0x51d539=squel[_0x1f49('0x58')]();var _0x37035d=[];var _0x163cff=squel[_0x1f49('0x58')]();var _0x558f03;if(_0xb8e272[_0x1f49('0x3c')][_0x1f49('0x59')]){_0x558f03=as[_0x1f49('0x5a')](_0xb8e272[_0x1f49('0x3c')][_0x1f49('0x59')]);var _0x3aefd0=_0x558f03[_0x1f49('0x5b')];for(var _0x2b683c=0x0;_0x2b683c<_0x558f03['conditions'][_0x1f49('0x5c')];_0x2b683c++){var _0xf1472c=_0x558f03[_0x1f49('0x5d')][_0x2b683c];var _0x37e868='i';var _0x34e4e9=_['find'](_0x78515d,['name',_0xf1472c['field']]);if(!_0x34e4e9){switch(_0xf1472c[_0x1f49('0x45')]){case _0x1f49('0x5e'):if(_0xf1472c[_0x1f49('0x5f')]==0x1){_0x2a42af[_0x1f49('0x60')]('`'+_0xf1472c[_0x1f49('0x45')]+_0x1f49('0x61'));}else{_0x2a42af['having']('`'+_0xf1472c[_0x1f49('0x45')]+_0x1f49('0x62'));}break;case _0x1f49('0x63'):if(_0xf1472c[_0x1f49('0x64')]===_0x1f49('0x65')){if(_0xf1472c[_0x1f49('0x5f')][_0x1f49('0x2e')]('\x20')[_0x1f49('0x5c')]>0x1){_0x51d539[_0x3aefd0](_0x1f49('0x66'),qs[_0x1f49('0x67')](_0xf1472c[_0x1f49('0x5f')]),null);}else{var _0x294c28='%'+_0xf1472c[_0x1f49('0x5f')]+'%';_0x51d539[_0x3aefd0](_0x1f49('0x68'),_0x294c28,_0x294c28,_0x294c28);}}else{_0x34e4e9=_[_0x1f49('0x69')](_0x78515d,[_0x1f49('0x28'),_0x1f49('0x6a')]);_0xf1472c[_0x1f49('0x45')]=_0x1f49('0x6a');_0x5ce3e6=as['buildExpression'](_0x37e868,_0x34e4e9[_0x1f49('0x3a')],_0xf1472c);_0x51d539[_0x3aefd0](_0x5ce3e6[_0x1f49('0x6b')],_0x5ce3e6[_0x1f49('0x5f')][_0x1f49('0x6c')],_0x5ce3e6[_0x1f49('0x5f')][_0x1f49('0x1a')]);}break;case'Tag':var _0x3b5a6a=_0xf1472c[_0x1f49('0x5f')][_0x1f49('0x2e')](',')[_0x1f49('0x2b')](function(_0x4746e3){return Number(_0x4746e3);});_0x3b5a6a[_0x1f49('0x2f')](function(_0x189490){_0x163cff['or'](_0x1f49('0x6d'),'%,'+_0x189490+',%');});_0x37035d=_[_0x1f49('0x6e')](_0x37035d,_0x3b5a6a);break;case _0x1f49('0x6f'):if(_0xf1472c[_0x1f49('0x64')]==='$substring'){_0x51d539[_0x3aefd0]('CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','%'+_0xf1472c[_0x1f49('0x5f')]+'%',null);}else{_0x34e4e9=_[_0x1f49('0x69')](_0x78515d,[_0x1f49('0x28'),_0x1f49('0x70')]);_0xf1472c['field']=_0x1f49('0x70');_0x5ce3e6=as[_0x1f49('0x71')](_0x37e868,_0x34e4e9['type'],_0xf1472c);_0x51d539[_0x3aefd0](_0x5ce3e6['text'],_0x5ce3e6[_0x1f49('0x5f')][_0x1f49('0x6c')],_0x5ce3e6[_0x1f49('0x5f')]['end']);}break;case _0x1f49('0x72'):_0x5ce3e6=as[_0x1f49('0x71')]('me',null,_0xf1472c);_0x51d539[_0x3aefd0](_0x5ce3e6[_0x1f49('0x6b')],_0x5ce3e6[_0x1f49('0x5f')][_0x1f49('0x6c')],_0x5ce3e6[_0x1f49('0x5f')][_0x1f49('0x1a')]);break;}}else{var _0x5ce3e6=as[_0x1f49('0x71')](_0x37e868,_0x34e4e9[_0x1f49('0x3a')],_0xf1472c);_0x51d539[_0x3aefd0](_0x5ce3e6[_0x1f49('0x6b')],_0x5ce3e6['value'][_0x1f49('0x6c')],_0x5ce3e6[_0x1f49('0x5f')][_0x1f49('0x1a')]);}}}else{var _0x5a8602=_(_0xb8e272[_0x1f49('0x3c')])[_0x1f49('0x3d')]()[_0x1f49('0x2b')](function(_0x36e014){return _[_0x1f49('0x73')](_0x78515d,[_0x1f49('0x28'),_0x36e014])?_0x36e014:undefined;})[_0x1f49('0x74')]()[_0x1f49('0x5f')]();if(!_[_0x1f49('0x75')](_0x5a8602)){_0x5a8602[_0x1f49('0x2f')](function(_0x29445b){if(_0x29445b===_0x1f49('0x76')){_0x2a42af[_0x1f49('0x77')](_0x1f49('0x78'),[][_0x1f49('0x79')](_0xb8e272[_0x1f49('0x3c')][_0x29445b]));}else if(_0x29445b==='createdAt'){var _0x2e25c0=JSON[_0x1f49('0x7a')](_0xb8e272['query'][_0x29445b])[_0x1f49('0x7b')];var _0x355aa9=JSON[_0x1f49('0x7a')](_0xb8e272['query'][_0x29445b])[_0x1f49('0x7c')];_0x2a42af[_0x1f49('0x77')](_0x1f49('0x7d'),_0x2e25c0,_0x355aa9);}else{if(_0xb8e272[_0x1f49('0x3c')][_0x29445b]===_0x1f49('0x7e')){_0x2a42af['where']('i.'+_0x29445b+_0x1f49('0x7f'));}else{_0x2a42af[_0x1f49('0x77')]('i.'+_0x29445b+'\x20=\x20?',_0xb8e272[_0x1f49('0x3c')][_0x29445b]);}}});}if(_0xb8e272['query'][_0x1f49('0x80')]){if(_0xb8e272['query'][_0x1f49('0x80')]==0x1){_0x2a42af[_0x1f49('0x60')](_0x1f49('0x81'));}else{_0x2a42af[_0x1f49('0x60')](_0x1f49('0x82'));}}if(_0xb8e272[_0x1f49('0x3c')][_0x1f49('0x83')]){_0x37035d=_['isArray'](_0xb8e272[_0x1f49('0x3c')][_0x1f49('0x83')])?_0xb8e272['query'][_0x1f49('0x83')]:new Array(_0xb8e272[_0x1f49('0x3c')][_0x1f49('0x83')]);_0x37035d[_0x1f49('0x2f')](function(_0x1cba6f){_0x163cff['or'](_0x1f49('0x6d'),'%,'+_0x1cba6f+',%');});}if(_0xb8e272[_0x1f49('0x3c')][_0x1f49('0x84')]){var _0x2d78e4=_0xb8e272['query']['filter']['replace']('\x5c','\x5c\x5c')['replace']('\x27\x27',_0x1f49('0x85'));if(qs[_0x1f49('0x86')](_0x2d78e4)){_0x51d539['or']('i.id\x20LIKE\x20?',_0x2d78e4+'%');}else if(qs[_0x1f49('0x87')](_0x2d78e4)){_0x51d539['or']('c.email\x20LIKE\x20?',_0x2d78e4+'%');}else{_0x51d539['or'](_0x1f49('0x88'),qs[_0x1f49('0x67')](_0x2d78e4))['or']('MATCH\x20(me.plainBody,\x20me.subject)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs[_0x1f49('0x67')](_0x2d78e4));}}}_0x2a42af[_0x1f49('0x77')](_0x51d539);_0x2a42af['group'](_0x1f49('0x89'));var _0x1ed077={'type':db[_0x1f49('0x8a')][_0x1f49('0x8b')][_0x1f49('0x8c')],'raw':!![]};var _0x435cb2=_0x2a42af[_0x1f49('0x8d')]();_0x435cb2['field']('i.id');_0x435cb2[_0x1f49('0x45')](_0x1f49('0x8e'),_0x1f49('0x5e'));if(_0x2f7306[_0x1f49('0x42')]){_0x2f7306[_0x1f49('0x42')]['forEach'](function(_0x3fe2ff){_0x2a42af[_0x1f49('0x42')]('i.'+_0x3fe2ff[0x0],_0x3fe2ff[0x1]==='DESC'?![]:!![]);});}if(!_[_0x1f49('0x75')](_0x37035d)){_0x2a42af[_0x1f49('0x60')](_0x163cff);_0x435cb2['where'](_0x1f49('0x8f'),_0x37035d);}BPromise['resolve']()[_0x1f49('0x35')](function(){if(!_0x558f03){if(_0xb8e272[_0x1f49('0x3c')][_0x1f49('0x76')]||_0xb8e272[_0x1f49('0x3c')][_0x1f49('0x90')])return;_0x435cb2[_0x1f49('0x77')]('i.MailAccountId\x20IS\x20NOT\x20NULL');_0x2a42af[_0x1f49('0x77')](_0x1f49('0x91'));return;}return _0xb8e272[_0x1f49('0x92')]['getMailAccounts']({'attributes':['id'],'raw':!![]})[_0x1f49('0x35')](function(_0x3f2508){if(_['isEmpty'](_0x3f2508)){_0x435cb2['where'](_0x1f49('0x93'));_0x2a42af['where'](_0x1f49('0x93'));}else{_0x435cb2[_0x1f49('0x77')]('i.MailAccountId\x20IN\x20?',_[_0x1f49('0x2b')](_0x3f2508,'id'));_0x2a42af['where'](_0x1f49('0x78'),_[_0x1f49('0x2b')](_0x3f2508,'id'));}});})[_0x1f49('0x35')](function(){db[_0x1f49('0x94')]['query'](_0x435cb2[_0x1f49('0x95')](),_0x1ed077)['then'](function(_0x43d138){_0x4ab9a4[_0x1f49('0x1b')]=_0x43d138[_0x1f49('0x5c')];if(_0x4ab9a4[_0x1f49('0x1b')]===0x0)return[];return db['sequelize'][_0x1f49('0x3c')](_0x560cfd['toString'](),_0x1ed077)['then'](function(_0x376de2){_0xb3089e=_['keyBy'](_0x376de2,'id');_0x1ed077=_[_0x1f49('0x96')](_0x1ed077,{'model':db[_0x1f49('0x31')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0xb8e272['query'][_0x1f49('0x41')]){_0x2f7306[_0x1f49('0x40')]['forEach'](function(_0x34cf7d){_0x2a42af[_0x1f49('0x45')]('i.'+_0x34cf7d);});}else{_0x2a42af['field'](_0x1f49('0x8e'),'unreadMessages');_0x2a42af[_0x1f49('0x45')]('a.key',_0x1f49('0x97'));_0x2a42af[_0x1f49('0x45')](_0x1f49('0x98'),_0x1f49('0x99'));_0x2a42af['field']('i.id');_0x2a42af[_0x1f49('0x45')](_0x1f49('0x9a'));_0x2a42af[_0x1f49('0x45')]('i.updatedAt');_0x2a42af[_0x1f49('0x45')]('i.closed');_0x2a42af[_0x1f49('0x45')](_0x1f49('0x9b'));_0x2a42af['field'](_0x1f49('0x9c'));_0x2a42af[_0x1f49('0x45')]('i.lastMsgAt');_0x2a42af[_0x1f49('0x45')](_0x1f49('0x9d'));_0x2a42af[_0x1f49('0x45')](_0x1f49('0x9e'));_0x2a42af[_0x1f49('0x45')](_0x1f49('0x9f'));_0x2a42af[_0x1f49('0x45')](_0x1f49('0xa0'));_0x2a42af[_0x1f49('0x45')](_0x1f49('0xa1'));_0x2a42af[_0x1f49('0x45')](_0x1f49('0xa2'));_0x2a42af[_0x1f49('0x45')](_0x1f49('0xa3'));_0x2a42af[_0x1f49('0x45')]('i.UserId');_0x2a42af[_0x1f49('0x45')](_0x1f49('0xa4'),'Contact.firstName');_0x2a42af[_0x1f49('0x45')](_0x1f49('0xa5'),_0x1f49('0xa6'));_0x2a42af[_0x1f49('0x45')]('c.email','Contact.email');_0x2a42af[_0x1f49('0x45')]('c.phone',_0x1f49('0xa7'));_0x2a42af[_0x1f49('0x45')](_0x1f49('0xa8'),'Contact.mobile');_0x2a42af[_0x1f49('0x45')](_0x1f49('0xa9'),_0x1f49('0xaa'));_0x2a42af[_0x1f49('0x45')]('o.fullname',_0x1f49('0xab'));_0x2a42af['field'](_0x1f49('0xac'),_0x1f49('0xad'));_0x2a42af[_0x1f49('0x45')](_0x1f49('0xae'),_0x1f49('0x2c'));}_0x2a42af[_0x1f49('0x1d')](_0x2f7306[_0x1f49('0x1d')]);_0x2a42af[_0x1f49('0x1c')](_0x2f7306[_0x1f49('0x1c')]);return db[_0x1f49('0x94')]['query'](_0x2a42af['toString'](),_0x1ed077);})['then'](function(_0x44ca27){_0x1e8951[_0x1f49('0x77')]('ui.MailInteractionId\x20IN\x20?',_[_0x1f49('0x2b')](_0x44ca27,'id'));return db[_0x1f49('0x94')][_0x1f49('0x3c')](_0x1e8951['toString'](),_0x1ed077)['then'](function(_0x5e6d72){var _0x4e7470=_[_0x1f49('0xaf')](_0x5e6d72,'MailInteractionId');var _0x2b43b7=[];return db['Setting'][_0x1f49('0x32')]({'attributes':[_0x1f49('0xb0')],'raw':!![]})[_0x1f49('0x35')](function(_0x3e7984){var _0x1414fc=_0x3e7984[_0x1f49('0xb0')];_0x44ca27[_0x1f49('0x2f')](function(_0x558209){_0x2b43b7[_0x1f49('0x30')](updateMailInteraction(_0x558209,_0xb3089e,_0x4e7470,_0x1414fc));});return BPromise[_0x1f49('0xb1')](_0x2b43b7);});});});})['then'](function(_0x24f9f7){_0x4ab9a4[_0x1f49('0xb2')]=_0x24f9f7;return _0x4ab9a4;})['then'](respondWithFilteredResult(_0xdf8725,_0x2f7306));})[_0x1f49('0x38')](handleError(_0xdf8725,null));};exports[_0x1f49('0xb3')]=function(_0x2d2424,_0x246c61){var _0x96b970={'raw':![],'where':{'id':_0x2d2424[_0x1f49('0xb4')]['id']}},_0x3d2760={};_0x3d2760[_0x1f49('0x3b')]=_[_0x1f49('0x3d')](db['MailInteraction'][_0x1f49('0xb5')]);_0x3d2760['query']=_[_0x1f49('0x3d')](_0x2d2424[_0x1f49('0x3c')]);_0x3d2760[_0x1f49('0x3e')]=_[_0x1f49('0x3f')](_0x3d2760[_0x1f49('0x3b')],_0x3d2760[_0x1f49('0x3c')]);_0x96b970[_0x1f49('0x40')]=_['intersection'](_0x3d2760[_0x1f49('0x3b')],qs['fields'](_0x2d2424['query'][_0x1f49('0x41')]));_0x96b970[_0x1f49('0x40')]=_0x96b970[_0x1f49('0x40')]['length']?_0x96b970[_0x1f49('0x40')]:_0x3d2760['model'];if(_0x2d2424[_0x1f49('0x3c')][_0x1f49('0xb6')]){_0x96b970[_0x1f49('0xb7')]=[{'all':!![]}];}_0x96b970=_[_0x1f49('0x96')]({},_0x96b970,_0x2d2424[_0x1f49('0xb8')]);return db[_0x1f49('0x31')][_0x1f49('0x69')](_0x96b970)[_0x1f49('0x35')](handleEntityNotFound(_0x246c61,null))[_0x1f49('0x35')](respondWithResult(_0x246c61,null))[_0x1f49('0x38')](handleError(_0x246c61,null));};exports['create']=function(_0x10ea1e,_0x3f9310){return db[_0x1f49('0x31')]['create'](_0x10ea1e[_0x1f49('0xb9')],{})[_0x1f49('0x35')](respondWithResult(_0x3f9310,0xc9))[_0x1f49('0x38')](handleError(_0x3f9310,null));};exports[_0x1f49('0x23')]=function(_0xd1acb1,_0x3dc3b4){if(_0xd1acb1[_0x1f49('0xb9')]['id']){delete _0xd1acb1[_0x1f49('0xb9')]['id'];}return db[_0x1f49('0x31')][_0x1f49('0x69')]({'where':{'id':_0xd1acb1[_0x1f49('0xb4')]['id']}})['then'](handleEntityNotFound(_0x3dc3b4,null))['then'](saveUpdates(_0xd1acb1[_0x1f49('0xb9')],null))['then'](respondWithResult(_0x3dc3b4,null))[_0x1f49('0x38')](handleError(_0x3dc3b4,null));};exports[_0x1f49('0x24')]=function(_0x482c05,_0xf15fce){return db[_0x1f49('0x31')]['find']({'where':{'id':_0x482c05[_0x1f49('0xb4')]['id']}})[_0x1f49('0x35')](handleEntityNotFound(_0xf15fce,null))[_0x1f49('0x35')](removeEntity(_0xf15fce,null))['catch'](handleError(_0xf15fce,null));};exports[_0x1f49('0xba')]=function(_0x590a30,_0x55c1db){return db[_0x1f49('0x31')][_0x1f49('0xba')]()[_0x1f49('0x35')](respondWithResult(_0x55c1db,null))[_0x1f49('0x38')](handleError(_0x55c1db,null));};exports['addMessage']=function(_0x542340,_0x244504,_0x2fd3cf){return db[_0x1f49('0xbb')][_0x1f49('0x69')]({'where':{'id':_0x542340[_0x1f49('0xb4')]['id']}})[_0x1f49('0x35')](handleEntityNotFound(_0x244504,null))['then'](function(_0x2dddfe){if(_0x2dddfe){return _0x2dddfe[_0x1f49('0xbc')](_0x542340['body'][_0x1f49('0xbd')],_[_0x1f49('0xbe')](_0x542340[_0x1f49('0xb9')],[_0x1f49('0xbd'),'id'])||{});}})[_0x1f49('0x35')](respondWithResult(_0x244504,null))[_0x1f49('0x38')](handleError(_0x244504,null));};exports[_0x1f49('0xbf')]=function(_0x5cd8c4,_0x536112,_0x36d5ad){var _0xa2a21c={'raw':![],'where':{}};var _0xd9fa14={};var _0x1066d5={'count':0x0,'rows':[]};return db[_0x1f49('0x31')][_0x1f49('0x32')]({'where':{'id':_0x5cd8c4['params']['id']}})[_0x1f49('0x35')](handleEntityNotFound(_0x536112,null))['then'](function(_0x5b2f77){if(_0x5b2f77){_0xd9fa14[_0x1f49('0x3b')]=_[_0x1f49('0x3d')](db[_0x1f49('0xbb')]['rawAttributes']);_0xd9fa14['query']=_[_0x1f49('0x3d')](_0x5cd8c4['query']);_0xd9fa14[_0x1f49('0x3e')]=_[_0x1f49('0x3f')](_0xd9fa14['model'],_0xd9fa14['query']);_0xa2a21c[_0x1f49('0x40')]=_[_0x1f49('0x3f')](_0xd9fa14['model'],qs[_0x1f49('0x41')](_0x5cd8c4[_0x1f49('0x3c')][_0x1f49('0x41')]));_0xa2a21c[_0x1f49('0x40')]=_0xa2a21c[_0x1f49('0x40')]['length']?_0xa2a21c[_0x1f49('0x40')]:_0xd9fa14[_0x1f49('0x3b')];if(!_0x5cd8c4['query'][_0x1f49('0xc0')](_0x1f49('0xc1'))){_0xa2a21c[_0x1f49('0x1d')]=qs[_0x1f49('0x1d')](_0x5cd8c4[_0x1f49('0x3c')]['limit']);_0xa2a21c[_0x1f49('0x1c')]=qs[_0x1f49('0x1c')](_0x5cd8c4[_0x1f49('0x3c')][_0x1f49('0x1c')]);}_0xa2a21c[_0x1f49('0x42')]=qs[_0x1f49('0x43')](_0x5cd8c4['query'][_0x1f49('0x43')]);_0xa2a21c[_0x1f49('0x77')]=qs[_0x1f49('0x3e')](_[_0x1f49('0xc2')](_0x5cd8c4['query'],_0xd9fa14[_0x1f49('0x3e')]));_0xa2a21c[_0x1f49('0x77')][_0x1f49('0xc3')]=_0x5b2f77['id'];if(_0x5cd8c4[_0x1f49('0x3c')]['filter']){_0xa2a21c[_0x1f49('0x77')]=_[_0x1f49('0x96')](_0xa2a21c['where'],{'$or':_['map'](_0xa2a21c[_0x1f49('0x40')],function(_0x2bb1f5){var _0x16305f={};_0x16305f[_0x2bb1f5]={'$like':'%'+_0x5cd8c4['query'][_0x1f49('0x84')]+'%'};return _0x16305f;})});}if(_0x5cd8c4[_0x1f49('0x3c')][_0x1f49('0x7b')]){var _0x4991dc=_0x5cd8c4[_0x1f49('0x3c')][_0x1f49('0x7b')][_0x1f49('0x2e')](',');var _0x140455={};_0x140455[_0x4991dc[0x0]]={'$gte':moment(_0x4991dc[0x1])[_0x1f49('0xc4')](_0x1f49('0xc5'))};_0xa2a21c[_0x1f49('0x77')]=_['merge'](_0xa2a21c[_0x1f49('0x77')],_0x140455);}_0xa2a21c=_['merge']({},_0xa2a21c,_0x5cd8c4[_0x1f49('0xb8')]);return db[_0x1f49('0xbb')]['count']({'where':_0xa2a21c[_0x1f49('0x77')]})[_0x1f49('0x35')](function(_0x557a1c){_0x1066d5[_0x1f49('0x1b')]=_0x557a1c;if(_0x5cd8c4[_0x1f49('0x3c')][_0x1f49('0xb6')]){_0xa2a21c[_0x1f49('0xb7')]=[{'all':!![]}];}return db[_0x1f49('0xbb')]['findAll'](_0xa2a21c);})[_0x1f49('0x35')](function(_0x1ecb78){_0x1066d5[_0x1f49('0xb2')]=_0x1ecb78;return _0x1066d5;});}})[_0x1f49('0x35')](respondWithFilteredResult(_0x536112,_0xa2a21c))[_0x1f49('0x38')](handleError(_0x536112,null));};exports[_0x1f49('0xc6')]=function(_0x3fd769,_0x5a425c,_0x2211fb){return db[_0x1f49('0x31')][_0x1f49('0x69')]({'where':{'id':_0x3fd769['params']['id']}})[_0x1f49('0x35')](handleEntityNotFound(_0x5a425c,null))[_0x1f49('0x35')](function(_0x13df67){if(_0x13df67){return _0x13df67[_0x1f49('0xc7')](_0x3fd769[_0x1f49('0xb9')][_0x1f49('0xbd')],_[_0x1f49('0xbe')](_0x3fd769[_0x1f49('0xb9')],['ids','id'])||{})['spread'](function(){return db[_0x1f49('0xc8')][_0x1f49('0xc9')]({'attributes':['id','name',_0x1f49('0x46')],'where':{'id':_0x3fd769[_0x1f49('0xb9')][_0x1f49('0xbd')]}});})[_0x1f49('0x35')](function(_0x453f14){socket[_0x1f49('0xca')](_0x1f49('0xcb'),{'id':Number(_0x3fd769[_0x1f49('0xb4')]['id']),'tags':_0x453f14||[]});return{'id':Number(_0x3fd769[_0x1f49('0xb4')]['id']),'tags':_0x453f14||[]};});}})[_0x1f49('0x35')](respondWithResult(_0x5a425c,null))[_0x1f49('0x38')](handleError(_0x5a425c,null));};exports['removeTags']=function(_0x385630,_0x1a81d3,_0x2f586a){return db[_0x1f49('0x31')][_0x1f49('0x69')]({'where':{'id':_0x385630[_0x1f49('0xb4')]['id']}})['then'](handleEntityNotFound(_0x1a81d3,null))[_0x1f49('0x35')](function(_0x5e1edc){if(_0x5e1edc){return _0x5e1edc[_0x1f49('0xcc')](_0x385630[_0x1f49('0x3c')][_0x1f49('0xbd')]);}})[_0x1f49('0x35')](respondWithStatusCode(_0x1a81d3,null))[_0x1f49('0x38')](handleError(_0x1a81d3,null));};exports['download']=function(_0x1ce8c8,_0x46a33e){var _0x2c73f7=moment()[_0x1f49('0xcd')]()[_0x1f49('0x95')]();var _0x1f5f7a=path['join'](config[_0x1f49('0xce')],_0x1f49('0xcf'),'files',_0x1f49('0xd0'));var _0x3bbd55=path[_0x1f49('0xd1')](config[_0x1f49('0xce')],_0x1f49('0xcf'),_0x1f49('0xd2'),_0x1f49('0xd3'));var _0x5a8ab2=path['join'](_0x1f5f7a,_0x2c73f7);var _0x2fdfae=util[_0x1f49('0xc4')](_0x1f49('0xd4'),_0x1ce8c8['params']['id'],_0x2c73f7);var _0x2f8ff4=path['join'](_0x1f5f7a,_0x2fdfae);var _0x1aa07b=[];if(_0x1ce8c8[_0x1f49('0x3c')][_0x1f49('0xd3')]){_0x1aa07b[_0x1f49('0x30')]({'model':db[_0x1f49('0xd5')],'as':'Attachments','raw':!![]});}var _0x4e53d2=[{'model':db[_0x1f49('0xbb')],'as':_0x1f49('0xd6'),'attributes':['id',_0x1f49('0xb9'),_0x1f49('0x47'),'to','cc','bcc',_0x1f49('0xd7'),_0x1f49('0xd8')],'where':{'secret':![]},'order':qs[_0x1f49('0x43')]('id'),'include':_0x1aa07b}];return db[_0x1f49('0x31')][_0x1f49('0x69')]({'where':{'id':_0x1ce8c8[_0x1f49('0xb4')]['id']},'include':_0x4e53d2})[_0x1f49('0x35')](handleEntityNotFound(_0x46a33e,null))[_0x1f49('0x35')](function(_0x16f44f){if(_0x16f44f&&_0x16f44f[_0x1f49('0xd6')]){var _0x58cf16=_0x16f44f[_0x1f49('0xd9')]({'plain':!![]});fs[_0x1f49('0xda')](_0x5a8ab2);return BPromise['each'](_0x58cf16['Messages'],function(_0x147af0,_0x4376e1){var _0x2e77cd={'from':_0x147af0[_0x1f49('0x47')],'to':_0x147af0['to'],'subject':_0x147af0['subject'],'html':_0x147af0[_0x1f49('0xb9')],'headers':{'Date':moment(_0x147af0['createdAt'])[_0x1f49('0xc4')](_0x1f49('0xdb'))},'attachments':[]};if(_0x147af0['cc']){_0x2e77cd['headers']['Cc']=_0x147af0['cc'];}if(_0x147af0[_0x1f49('0xdc')]){_0x2e77cd['headers'][_0x1f49('0xdd')]=_0x147af0['bcc'];}return new BPromise(function(_0x1c8291,_0x1df10e){if(_0x147af0[_0x1f49('0xde')]){for(var _0x8bf9e5=0x0;_0x8bf9e5<_0x147af0[_0x1f49('0xde')][_0x1f49('0x5c')];_0x8bf9e5++){var _0x4df179=_0x147af0[_0x1f49('0xde')][_0x8bf9e5];var _0x3e0915=path['join'](_0x3bbd55,_0x4df179[_0x1f49('0xdf')]);if(fs[_0x1f49('0xe0')](_0x3e0915)){_0x2e77cd[_0x1f49('0xd3')]['push']({'name':_0x4df179[_0x1f49('0x28')],'contentType':_0x4df179['type'],'data':fs[_0x1f49('0xe1')](_0x3e0915)});}}}emlformat[_0x1f49('0xe2')](_0x2e77cd,function(_0x382e58,_0x5cd6d5){if(_0x382e58)return _0x1df10e(_0x382e58);fs[_0x1f49('0xe3')](path[_0x1f49('0xd1')](_0x5a8ab2,util['format']('message%d.eml',_0x4376e1)),_0x5cd6d5);return _0x1c8291(_0x5cd6d5);});});})[_0x1f49('0x35')](function(){return new BPromise(function(_0x4878f6,_0x577123){zipdir(_0x5a8ab2,{'saveTo':_0x2f8ff4},function(_0x4174fa,_0x470f5a){if(_0x4174fa)return _0x577123(_0x4174fa);return _0x4878f6(_0x470f5a);});})['then'](function(){return new BPromise(function(_0x470d4d,_0x5bcb50){rimraf(_0x5a8ab2,function(_0x2a6a33){if(_0x2a6a33)_0x5bcb50(_0x2a6a33);return _0x470d4d();});});})[_0x1f49('0x35')](function(){return _0x46a33e[_0x1f49('0xe4')](_0x2f8ff4,_0x2fdfae,function(_0x1f57ef){if(_0x1f57ef){console[_0x1f49('0xe5')]('err',_0x1f57ef);}else{fs['unlinkSync'](_0x2f8ff4);}});});});}else{return _0x46a33e['sendStatus'](0xc8);}})[_0x1f49('0x38')](handleError(_0x46a33e,null));};
\ No newline at end of file
+var _0x2a99=['join','server','files','tmp','root','attachments','transcript-%d-%s.zip','Attachment','bcc','subject','Messages','get','mkdirSync','decode','ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ','headers','Bcc','Attachments','basename','existsSync','readFileSync','writeFileSync','message%d.eml','eml-format','rimraf','zip-dir','bluebird','util','path','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/environment','../../mysqldb','redis','defaults','socket.io-emitter','./mailInteraction.socket','register','sendStatus','end','json','offset','limit','count','status','set','Content-Range','update','then','destroy','error','name','send','Users','fullname','Tags','TagIds','split','forEach','push','findOne','out','plainBody','lastMsgText','trimStart','catch','index','map','MailInteraction','fieldName','type','model','query','filters','intersection','fields','attributes','hasOwnProperty','nolimit','order','sort','select','field','color','from','tools_tags','u.id','ui.MailInteractionId','user_has_mail_interactions','left_join','users','u.id\x20=\x20ui.UserId','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','t.id\x20=\x20it.TagId','expr','search','sqlOperator','conditions','length','find','unreadMessages','value','having','`\x20=\x200','`\x20>\x200','Contact','operator','$substring','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','getFullTextValue','c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?','ContactId','buildExpression','text','start','Tag','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','union','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','UserId','compact','isEmpty','where','concat','createdAt','parse','$gte','$lte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20IS\x20NULL','read','`unreadMessages`\x20>\x200','tag','isArray','filter','replace','isNumeric','i.id\x20LIKE\x20?','isEmail','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','i.id','QueryTypes','SELECT','clone','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','contactName','DESC','MailAccountId','i.MailAccountId\x20IS\x20NOT\x20NULL','role','agent','user','i.MailAccountId\x20IN\x20?','toString','sequelize','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.closed','i.closedAt','i.attach','i.lastMsgAt','i.subject','i.disposition','i.thirdDisposition','i.substatus','i.to','i.ContactId','i.UserId','c.firstName','Contact.firstName','c.lastName','Contact.lastName','c.email','Contact.email','c.phone','Contact.phone','c.mobile','Contact.mobile','Contact.fax','o.fullname','Owner.fullname','o.internal','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','ui.MailInteractionId\x20IN\x20?','groupBy','MailInteractionId','all','rows','show','keys','rawAttributes','includeAll','options','create','body','params','describe','addMessage','MailMessage','ids','omit','getMessages','format','YYYY-MM-DD\x20HH:mm:ss','findAll','inlineCss','true','addTags','emit','mailInteractionTags:save','removeTags','download','unix'];(function(_0x513e3e,_0x5d8cf1){var _0x30cae2=function(_0x62b5ac){while(--_0x62b5ac){_0x513e3e['push'](_0x513e3e['shift']());}};_0x30cae2(++_0x5d8cf1);}(_0x2a99,0xfd));var _0x92a9=function(_0x430a79,_0x17b2af){_0x430a79=_0x430a79-0x0;var _0xda6181=_0x2a99[_0x430a79];return _0xda6181;};'use strict';var emlformat=require(_0x92a9('0x0'));var rimraf=require(_0x92a9('0x1'));var zipdir=require(_0x92a9('0x2'));var moment=require('moment');var BPromise=require(_0x92a9('0x3'));var util=require(_0x92a9('0x4'));var path=require(_0x92a9('0x5'));var fs=require('fs');var _=require('lodash');var squel=require('squel');var juice=require('juice');var Redis=require('ioredis');var qs=require(_0x92a9('0x6'));var as=require(_0x92a9('0x7'));var logger=require('../../config/logger')('api');var config=require(_0x92a9('0x8'));var db=require(_0x92a9('0x9'))['db'];var htmlEntities=require('html-entities');config[_0x92a9('0xa')]=_[_0x92a9('0xb')](config['redis'],{'host':'localhost','port':0x18eb});var socket=require(_0x92a9('0xc'))(new Redis(config['redis']));require(_0x92a9('0xd'))[_0x92a9('0xe')](socket);function respondWithStatusCode(_0x4ccab1,_0x2c3e41){_0x2c3e41=_0x2c3e41||0xcc;return function(_0x2ef006){if(_0x2ef006){return _0x4ccab1[_0x92a9('0xf')](_0x2c3e41);}return _0x4ccab1['status'](_0x2c3e41)[_0x92a9('0x10')]();};}function respondWithResult(_0x5253db,_0x26a58c){_0x26a58c=_0x26a58c||0xc8;return function(_0x4e8316){if(_0x4e8316){return _0x5253db['status'](_0x26a58c)[_0x92a9('0x11')](_0x4e8316);}};}function respondWithFilteredResult(_0x8e13bc,_0x49a37b){return function(_0x3de9c3){if(_0x3de9c3){var _0x555700=typeof _0x49a37b[_0x92a9('0x12')]==='undefined'&&typeof _0x49a37b[_0x92a9('0x13')]==='undefined';var _0x100565=_0x3de9c3['count'];var _0x57d8ca=_0x555700?0x0:_0x49a37b[_0x92a9('0x12')];var _0x1a40c3=_0x555700?_0x3de9c3[_0x92a9('0x14')]:_0x49a37b[_0x92a9('0x12')]+_0x49a37b['limit'];var _0x1451ca;if(_0x1a40c3>=_0x100565){_0x1a40c3=_0x100565;_0x1451ca=0xc8;}else{_0x1451ca=0xce;}_0x8e13bc[_0x92a9('0x15')](_0x1451ca);return _0x8e13bc[_0x92a9('0x16')](_0x92a9('0x17'),_0x57d8ca+'-'+_0x1a40c3+'/'+_0x100565)[_0x92a9('0x11')](_0x3de9c3);}return null;};}function saveUpdates(_0x3536f7){return function(_0xced12a){if(_0xced12a){return _0xced12a[_0x92a9('0x18')](_0x3536f7)[_0x92a9('0x19')](function(_0x1c133d){return _0x1c133d;});}return null;};}function removeEntity(_0x548bea){return function(_0x11783d){if(_0x11783d){return _0x11783d[_0x92a9('0x1a')]()[_0x92a9('0x19')](function(){_0x548bea['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0xe0f48c){return function(_0x2137f4){if(!_0x2137f4){_0xe0f48c[_0x92a9('0xf')](0x194);}return _0x2137f4;};}function handleError(_0x26aea8,_0x16b4be){_0x16b4be=_0x16b4be||0x1f4;return function(_0x293e2e){logger[_0x92a9('0x1b')](_0x293e2e['stack']);if(_0x293e2e[_0x92a9('0x1c')]){delete _0x293e2e['name'];}_0x26aea8[_0x92a9('0x15')](_0x16b4be)[_0x92a9('0x1d')](_0x293e2e);};}function getInteractionUsers(_0x420a41,_0x2c4b0e){return new BPromise(function(_0x3de3d2,_0x55bf38){try{if(_0x2c4b0e[_0x420a41['id']]){_0x420a41[_0x92a9('0x1e')]=_['map'](_0x2c4b0e[_0x420a41['id']],function(_0x4ffa70){return{'id':_0x4ffa70['id'],'fullname':_0x4ffa70[_0x92a9('0x1f')]};});}}catch(_0x4111a1){_0x55bf38(_0x4111a1);}_0x3de3d2(_0x420a41);});}function getInteractionTags(_0x25946e,_0x288c02){return new BPromise(function(_0x10153d,_0x11d907){try{if(_0x25946e['TagIds']){_0x25946e[_0x92a9('0x20')]=[];_0x25946e[_0x92a9('0x21')][_0x92a9('0x22')](',')[_0x92a9('0x23')](function(_0x140b5c){_0x25946e[_0x92a9('0x20')][_0x92a9('0x24')](_0x288c02[_0x140b5c]);});}delete _0x25946e[_0x92a9('0x21')];}catch(_0x5bf9d8){_0x11d907(_0x5bf9d8);}_0x10153d(_0x25946e);});}function getLastMessageText(_0x26a981){return new BPromise(function(_0x4ce8bb,_0x4cb3f3){return db['MailMessage'][_0x92a9('0x25')]({'where':{'$and':[{'MailInteractionId':_0x26a981['id']},{'$or':[{'direction':'in'},{'$and':[{'direction':_0x92a9('0x26')},{'secret':![]},{'UserId':{'$ne':null}}]}]}]},'attributes':[_0x92a9('0x27')],'order':'-id','raw':!![]})[_0x92a9('0x19')](function(_0x1936ba){if(_0x1936ba&&_0x1936ba[_0x92a9('0x27')]){_0x26a981[_0x92a9('0x28')]=_[_0x92a9('0x29')](_0x1936ba[_0x92a9('0x27')]);}_0x4ce8bb(_0x26a981);})[_0x92a9('0x2a')](function(_0x4de3f9){_0x4cb3f3(_0x4de3f9);});});}function updateMailInteraction(_0xccbe13,_0x5977bb,_0x59417e,_0x3e37e2){return new BPromise(function(_0x4ff60d,_0x229b62){return getInteractionUsers(_0xccbe13,_0x59417e)[_0x92a9('0x19')](function(_0x5b95d3){return getInteractionTags(_0x5b95d3,_0x5977bb);})[_0x92a9('0x19')](function(_0xa4ecd9){if(_0x3e37e2){_0x4ff60d(getLastMessageText(_0xa4ecd9));}else{_0x4ff60d(_0xa4ecd9);}})[_0x92a9('0x2a')](function(_0x118321){_0x229b62(_0x118321);});});}exports[_0x92a9('0x2b')]=function(_0x5c14b9,_0x23532a){var _0x440b18={},_0x3b0e50={},_0x3ec90f={'count':0x0,'rows':[]};var _0x25a362=_[_0x92a9('0x2c')](db[_0x92a9('0x2d')]['rawAttributes'],function(_0xc81dde){return{'name':_0xc81dde[_0x92a9('0x2e')],'type':_0xc81dde[_0x92a9('0x2f')]['key']};});_0x3b0e50[_0x92a9('0x30')]=_[_0x92a9('0x2c')](_0x25a362,_0x92a9('0x1c'));_0x3b0e50[_0x92a9('0x31')]=_['keys'](_0x5c14b9[_0x92a9('0x31')]);_0x3b0e50[_0x92a9('0x32')]=_[_0x92a9('0x33')](_0x3b0e50[_0x92a9('0x30')],_0x3b0e50[_0x92a9('0x31')]);_0x440b18['attributes']=_[_0x92a9('0x33')](_0x3b0e50[_0x92a9('0x30')],qs[_0x92a9('0x34')](_0x5c14b9[_0x92a9('0x31')][_0x92a9('0x34')]));_0x440b18['attributes']=_0x440b18[_0x92a9('0x35')]['length']?_0x440b18[_0x92a9('0x35')]:_0x3b0e50[_0x92a9('0x30')];if(!_0x5c14b9[_0x92a9('0x31')][_0x92a9('0x36')](_0x92a9('0x37'))){_0x440b18[_0x92a9('0x13')]=qs[_0x92a9('0x13')](_0x5c14b9[_0x92a9('0x31')][_0x92a9('0x13')]);_0x440b18[_0x92a9('0x12')]=qs[_0x92a9('0x12')](_0x5c14b9[_0x92a9('0x31')]['offset']);}_0x440b18[_0x92a9('0x38')]=qs[_0x92a9('0x39')](_0x5c14b9[_0x92a9('0x31')]['sort']);_0x440b18['where']=qs['filters'](_['pick'](_0x5c14b9[_0x92a9('0x31')],_0x3b0e50['filters']),_0x25a362);var _0x1543ec=[];var _0x84fed0=squel[_0x92a9('0x3a')]()[_0x92a9('0x3b')]('id')[_0x92a9('0x3b')](_0x92a9('0x1c'))['field'](_0x92a9('0x3c'))[_0x92a9('0x3d')](_0x92a9('0x3e'));var _0x3b7c5b=squel['select']()[_0x92a9('0x3b')](_0x92a9('0x3f'))['field']('u.fullname')['field'](_0x92a9('0x40'))[_0x92a9('0x3d')](_0x92a9('0x41'),'ui')[_0x92a9('0x42')](_0x92a9('0x43'),'u',_0x92a9('0x44'));var _0x52543f=squel['select']()[_0x92a9('0x3d')]('mail_interactions','i')[_0x92a9('0x42')](_0x92a9('0x45'),'c',_0x92a9('0x46'))[_0x92a9('0x42')](_0x92a9('0x43'),'o',_0x92a9('0x47'))[_0x92a9('0x42')](_0x92a9('0x48'),'a',_0x92a9('0x49'))['left_join'](_0x92a9('0x4a'),'me',_0x92a9('0x4b'))[_0x92a9('0x42')](_0x92a9('0x4c'),'it',_0x92a9('0x4d'))[_0x92a9('0x42')](_0x92a9('0x3e'),'t',_0x92a9('0x4e'));var _0x2658ce=squel[_0x92a9('0x4f')]();var _0x42c668=[];var _0xd6279b=squel[_0x92a9('0x4f')]();var _0x594923;if(_0x5c14b9[_0x92a9('0x31')][_0x92a9('0x50')]){_0x594923=as['parseSearch'](_0x5c14b9[_0x92a9('0x31')]['search']);var _0x4d1435=_0x594923[_0x92a9('0x51')];for(var _0x13bc72=0x0;_0x13bc72<_0x594923[_0x92a9('0x52')][_0x92a9('0x53')];_0x13bc72++){var _0x3e4a18=_0x594923[_0x92a9('0x52')][_0x13bc72];var _0x4b3b30='i';var _0x78cfda=_[_0x92a9('0x54')](_0x25a362,[_0x92a9('0x1c'),_0x3e4a18[_0x92a9('0x3b')]]);if(!_0x78cfda){switch(_0x3e4a18[_0x92a9('0x3b')]){case _0x92a9('0x55'):if(_0x3e4a18[_0x92a9('0x56')]==0x1){_0x52543f[_0x92a9('0x57')]('`'+_0x3e4a18[_0x92a9('0x3b')]+_0x92a9('0x58'));}else{_0x52543f[_0x92a9('0x57')]('`'+_0x3e4a18[_0x92a9('0x3b')]+_0x92a9('0x59'));}break;case _0x92a9('0x5a'):if(_0x3e4a18[_0x92a9('0x5b')]===_0x92a9('0x5c')){if(_0x3e4a18[_0x92a9('0x56')][_0x92a9('0x22')]('\x20')[_0x92a9('0x53')]>0x1){_0x2658ce[_0x4d1435](_0x92a9('0x5d'),qs[_0x92a9('0x5e')](_0x3e4a18['value']),null);}else{var _0x2e1ee6='%'+_0x3e4a18[_0x92a9('0x56')]+'%';_0x2658ce[_0x4d1435](_0x92a9('0x5f'),_0x2e1ee6,_0x2e1ee6,_0x2e1ee6);}}else{_0x78cfda=_[_0x92a9('0x54')](_0x25a362,[_0x92a9('0x1c'),_0x92a9('0x60')]);_0x3e4a18[_0x92a9('0x3b')]=_0x92a9('0x60');_0x569ae3=as[_0x92a9('0x61')](_0x4b3b30,_0x78cfda[_0x92a9('0x2f')],_0x3e4a18);_0x2658ce[_0x4d1435](_0x569ae3[_0x92a9('0x62')],_0x569ae3[_0x92a9('0x56')][_0x92a9('0x63')],_0x569ae3[_0x92a9('0x56')][_0x92a9('0x10')]);}break;case _0x92a9('0x64'):var _0x150e19=_0x3e4a18[_0x92a9('0x56')]['split'](',')[_0x92a9('0x2c')](function(_0x44fca1){return Number(_0x44fca1);});_0x150e19[_0x92a9('0x23')](function(_0x50424a){_0xd6279b['or'](_0x92a9('0x65'),'%,'+_0x50424a+',%');});_0x42c668=_[_0x92a9('0x66')](_0x42c668,_0x150e19);break;case'User':if(_0x3e4a18[_0x92a9('0x5b')]===_0x92a9('0x5c')){_0x2658ce[_0x4d1435](_0x92a9('0x67'),'%'+_0x3e4a18[_0x92a9('0x56')]+'%',null);}else{_0x78cfda=_[_0x92a9('0x54')](_0x25a362,[_0x92a9('0x1c'),_0x92a9('0x68')]);_0x3e4a18[_0x92a9('0x3b')]='UserId';_0x569ae3=as[_0x92a9('0x61')](_0x4b3b30,_0x78cfda['type'],_0x3e4a18);_0x2658ce[_0x4d1435](_0x569ae3[_0x92a9('0x62')],_0x569ae3[_0x92a9('0x56')][_0x92a9('0x63')],_0x569ae3[_0x92a9('0x56')]['end']);}break;case'plainBody':_0x569ae3=as[_0x92a9('0x61')]('me',null,_0x3e4a18);_0x2658ce[_0x4d1435](_0x569ae3[_0x92a9('0x62')],_0x569ae3[_0x92a9('0x56')][_0x92a9('0x63')],_0x569ae3['value'][_0x92a9('0x10')]);break;}}else{var _0x569ae3=as['buildExpression'](_0x4b3b30,_0x78cfda[_0x92a9('0x2f')],_0x3e4a18);_0x2658ce[_0x4d1435](_0x569ae3[_0x92a9('0x62')],_0x569ae3[_0x92a9('0x56')][_0x92a9('0x63')],_0x569ae3[_0x92a9('0x56')]['end']);}}}else{var _0x13a2b7=_(_0x5c14b9['query'])['keys']()[_0x92a9('0x2c')](function(_0x5086ea){return _['some'](_0x25a362,['name',_0x5086ea])?_0x5086ea:undefined;})[_0x92a9('0x69')]()[_0x92a9('0x56')]();if(!_[_0x92a9('0x6a')](_0x13a2b7)){_0x13a2b7[_0x92a9('0x23')](function(_0x37109f){if(_0x37109f==='MailAccountId'){_0x52543f[_0x92a9('0x6b')]('i.MailAccountId\x20IN\x20?',[][_0x92a9('0x6c')](_0x5c14b9[_0x92a9('0x31')][_0x37109f]));}else if(_0x37109f===_0x92a9('0x6d')){var _0x6ce430=JSON[_0x92a9('0x6e')](_0x5c14b9[_0x92a9('0x31')][_0x37109f])[_0x92a9('0x6f')];var _0x2c4389=JSON[_0x92a9('0x6e')](_0x5c14b9[_0x92a9('0x31')][_0x37109f])[_0x92a9('0x70')];_0x52543f[_0x92a9('0x6b')](_0x92a9('0x71'),_0x6ce430,_0x2c4389);}else{if(_0x5c14b9[_0x92a9('0x31')][_0x37109f]===_0x92a9('0x72')){_0x52543f[_0x92a9('0x6b')]('i.'+_0x37109f+_0x92a9('0x73'));}else{_0x52543f[_0x92a9('0x6b')]('i.'+_0x37109f+'\x20=\x20?',_0x5c14b9[_0x92a9('0x31')][_0x37109f]);}}});}if(_0x5c14b9[_0x92a9('0x31')][_0x92a9('0x74')]){if(_0x5c14b9['query']['read']==0x1){_0x52543f[_0x92a9('0x57')]('`unreadMessages`\x20=\x200');}else{_0x52543f[_0x92a9('0x57')](_0x92a9('0x75'));}}if(_0x5c14b9[_0x92a9('0x31')][_0x92a9('0x76')]){_0x42c668=_[_0x92a9('0x77')](_0x5c14b9[_0x92a9('0x31')]['tag'])?_0x5c14b9[_0x92a9('0x31')][_0x92a9('0x76')]:new Array(_0x5c14b9[_0x92a9('0x31')][_0x92a9('0x76')]);_0x42c668[_0x92a9('0x23')](function(_0x4e4d33){_0xd6279b['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x4e4d33+',%');});}if(_0x5c14b9['query'][_0x92a9('0x78')]){var _0x33e029=_0x5c14b9['query'][_0x92a9('0x78')][_0x92a9('0x79')]('\x5c','\x5c\x5c')[_0x92a9('0x79')](/'/g,'\x27\x27');if(qs[_0x92a9('0x7a')](_0x33e029)){_0x2658ce['or'](_0x92a9('0x7b'),_0x33e029+'%');}else if(qs[_0x92a9('0x7c')](_0x33e029)){_0x2658ce['or'](_0x92a9('0x7d'),_0x33e029+'%');}else{_0x2658ce['or'](_0x92a9('0x7e'),qs[_0x92a9('0x5e')](_0x33e029))['or'](_0x92a9('0x7f'),qs['getFullTextValue'](_0x33e029));}}}_0x52543f[_0x92a9('0x6b')](_0x2658ce);_0x52543f[_0x92a9('0x80')](_0x92a9('0x81'));var _0x466d2d={'type':db['Sequelize'][_0x92a9('0x82')][_0x92a9('0x83')],'raw':!![]};var _0x436a0c=_0x52543f[_0x92a9('0x84')]();_0x436a0c['field'](_0x92a9('0x81'));_0x436a0c['field'](_0x92a9('0x85'),_0x92a9('0x55'));if(_0x440b18[_0x92a9('0x38')]){_0x440b18[_0x92a9('0x38')]['forEach'](function(_0x37c054){var _0x5a7a31=_0x37c054[0x0]===_0x92a9('0x86')?_0x37c054[0x0]:'i.'+_0x37c054[0x0];_0x52543f[_0x92a9('0x38')](_0x5a7a31,_0x37c054[0x1]===_0x92a9('0x87')?![]:!![]);});}if(!_[_0x92a9('0x6a')](_0x42c668)){_0x52543f[_0x92a9('0x57')](_0xd6279b);_0x436a0c[_0x92a9('0x6b')]('t.id\x20IN\x20?',_0x42c668);}BPromise['resolve']()[_0x92a9('0x19')](function(){if(!_0x594923){if(_0x5c14b9[_0x92a9('0x31')][_0x92a9('0x88')])return;_0x436a0c[_0x92a9('0x6b')](_0x92a9('0x89'));_0x52543f['where'](_0x92a9('0x89'));return;}if(_0x5c14b9['user'][_0x92a9('0x8a')]!==_0x92a9('0x8b'))return;return _0x5c14b9[_0x92a9('0x8c')]['getMailAccounts']({'attributes':['id'],'raw':!![]})[_0x92a9('0x19')](function(_0x18c2f8){if(_[_0x92a9('0x6a')](_0x18c2f8)){_0x436a0c[_0x92a9('0x6b')]('i.MailAccountId\x20IS\x20NULL');_0x52543f[_0x92a9('0x6b')]('i.MailAccountId\x20IS\x20NULL');}else{_0x436a0c['where'](_0x92a9('0x8d'),_[_0x92a9('0x2c')](_0x18c2f8,'id'));_0x52543f['where']('i.MailAccountId\x20IN\x20?',_[_0x92a9('0x2c')](_0x18c2f8,'id'));}});})[_0x92a9('0x19')](function(){if(_0x5c14b9[_0x92a9('0x8c')][_0x92a9('0x8a')]===_0x92a9('0x8b')&&!_0x594923&&!_0x5c14b9[_0x92a9('0x31')][_0x92a9('0x88')])return[];return db['sequelize'][_0x92a9('0x31')](_0x436a0c[_0x92a9('0x8e')](),_0x466d2d);})[_0x92a9('0x19')](function(_0x46576a){_0x3ec90f[_0x92a9('0x14')]=_0x46576a['length'];if(_0x3ec90f[_0x92a9('0x14')]===0x0)return[];return db[_0x92a9('0x8f')][_0x92a9('0x31')](_0x84fed0[_0x92a9('0x8e')](),_0x466d2d)['then'](function(_0x27c394){_0x1543ec=_['keyBy'](_0x27c394,'id');_0x466d2d=_[_0x92a9('0x90')](_0x466d2d,{'model':db[_0x92a9('0x2d')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x5c14b9[_0x92a9('0x31')]['fields']){_0x440b18[_0x92a9('0x35')][_0x92a9('0x23')](function(_0xae324b){_0x52543f[_0x92a9('0x3b')]('i.'+_0xae324b);});}else{_0x52543f['field'](_0x92a9('0x85'),_0x92a9('0x55'));_0x52543f[_0x92a9('0x3b')](_0x92a9('0x91'),_0x92a9('0x92'));_0x52543f[_0x92a9('0x3b')](_0x92a9('0x93'),_0x92a9('0x94'));_0x52543f[_0x92a9('0x3b')](_0x92a9('0x95'),_0x92a9('0x86'));_0x52543f[_0x92a9('0x3b')](_0x92a9('0x81'));_0x52543f[_0x92a9('0x3b')]('i.createdAt');_0x52543f['field']('i.updatedAt');_0x52543f[_0x92a9('0x3b')](_0x92a9('0x96'));_0x52543f[_0x92a9('0x3b')](_0x92a9('0x97'));_0x52543f[_0x92a9('0x3b')](_0x92a9('0x98'));_0x52543f['field'](_0x92a9('0x99'));_0x52543f['field']('i.lastMsgDirection');_0x52543f['field'](_0x92a9('0x9a'));_0x52543f['field'](_0x92a9('0x9b'));_0x52543f[_0x92a9('0x3b')]('i.secondDisposition');_0x52543f['field'](_0x92a9('0x9c'));_0x52543f[_0x92a9('0x3b')](_0x92a9('0x9d'));_0x52543f[_0x92a9('0x3b')](_0x92a9('0x9e'));_0x52543f['field'](_0x92a9('0x9f'));_0x52543f[_0x92a9('0x3b')]('i.MailAccountId');_0x52543f[_0x92a9('0x3b')](_0x92a9('0xa0'));_0x52543f[_0x92a9('0x3b')](_0x92a9('0xa1'),_0x92a9('0xa2'));_0x52543f['field'](_0x92a9('0xa3'),_0x92a9('0xa4'));_0x52543f[_0x92a9('0x3b')](_0x92a9('0xa5'),_0x92a9('0xa6'));_0x52543f['field'](_0x92a9('0xa7'),_0x92a9('0xa8'));_0x52543f[_0x92a9('0x3b')](_0x92a9('0xa9'),_0x92a9('0xaa'));_0x52543f[_0x92a9('0x3b')]('c.fax',_0x92a9('0xab'));_0x52543f[_0x92a9('0x3b')](_0x92a9('0xac'),_0x92a9('0xad'));_0x52543f[_0x92a9('0x3b')](_0x92a9('0xae'),_0x92a9('0xaf'));_0x52543f[_0x92a9('0x3b')](_0x92a9('0xb0'),_0x92a9('0x21'));}if(_0x440b18['limit'])_0x52543f[_0x92a9('0x13')](_0x440b18[_0x92a9('0x13')]);if(_0x440b18[_0x92a9('0x12')])_0x52543f['offset'](_0x440b18['offset']);return db['sequelize'][_0x92a9('0x31')](_0x52543f[_0x92a9('0x8e')](),_0x466d2d);})[_0x92a9('0x19')](function(_0x20bfe9){if(_0x20bfe9[_0x92a9('0x53')]>0x0)_0x3b7c5b[_0x92a9('0x6b')](_0x92a9('0xb1'),_[_0x92a9('0x2c')](_0x20bfe9,'id'));return db[_0x92a9('0x8f')][_0x92a9('0x31')](_0x3b7c5b['toString'](),_0x466d2d)[_0x92a9('0x19')](function(_0x160638){var _0x2ee9b6=_[_0x92a9('0xb2')](_0x160638,_0x92a9('0xb3'));var _0x47ad03=[];return db['Setting'][_0x92a9('0x25')]({'attributes':['enableEmailPreview'],'raw':!![]})[_0x92a9('0x19')](function(_0x37c365){var _0x52f103=_0x37c365['enableEmailPreview'];_0x20bfe9[_0x92a9('0x23')](function(_0x4bf044){_0x47ad03['push'](updateMailInteraction(_0x4bf044,_0x1543ec,_0x2ee9b6,_0x52f103));});return BPromise[_0x92a9('0xb4')](_0x47ad03);});});});})[_0x92a9('0x19')](function(_0x4915cd){_0x3ec90f[_0x92a9('0xb5')]=_0x4915cd;return _0x3ec90f;})[_0x92a9('0x19')](respondWithFilteredResult(_0x23532a,_0x440b18))[_0x92a9('0x2a')](handleError(_0x23532a,null));};exports[_0x92a9('0xb6')]=function(_0x4942ae,_0x178b2b){var _0x2e134b={'raw':![],'where':{'id':_0x4942ae['params']['id']}},_0x510f9d={};_0x510f9d[_0x92a9('0x30')]=_[_0x92a9('0xb7')](db['MailInteraction'][_0x92a9('0xb8')]);_0x510f9d[_0x92a9('0x31')]=_[_0x92a9('0xb7')](_0x4942ae[_0x92a9('0x31')]);_0x510f9d[_0x92a9('0x32')]=_[_0x92a9('0x33')](_0x510f9d[_0x92a9('0x30')],_0x510f9d['query']);_0x2e134b[_0x92a9('0x35')]=_['intersection'](_0x510f9d['model'],qs[_0x92a9('0x34')](_0x4942ae[_0x92a9('0x31')]['fields']));_0x2e134b[_0x92a9('0x35')]=_0x2e134b[_0x92a9('0x35')]['length']?_0x2e134b['attributes']:_0x510f9d[_0x92a9('0x30')];if(_0x4942ae[_0x92a9('0x31')][_0x92a9('0xb9')]){_0x2e134b['include']=[{'all':!![]}];}_0x2e134b=_[_0x92a9('0x90')]({},_0x2e134b,_0x4942ae[_0x92a9('0xba')]);return db['MailInteraction'][_0x92a9('0x54')](_0x2e134b)[_0x92a9('0x19')](handleEntityNotFound(_0x178b2b,null))[_0x92a9('0x19')](respondWithResult(_0x178b2b,null))[_0x92a9('0x2a')](handleError(_0x178b2b,null));};exports[_0x92a9('0xbb')]=function(_0x32d41b,_0x3225df){return db[_0x92a9('0x2d')][_0x92a9('0xbb')](_0x32d41b[_0x92a9('0xbc')],{})[_0x92a9('0x19')](respondWithResult(_0x3225df,0xc9))[_0x92a9('0x2a')](handleError(_0x3225df,null));};exports[_0x92a9('0x18')]=function(_0x3e19b1,_0x37ac30){if(_0x3e19b1['body']['id']){delete _0x3e19b1[_0x92a9('0xbc')]['id'];}return db[_0x92a9('0x2d')]['find']({'where':{'id':_0x3e19b1[_0x92a9('0xbd')]['id']}})[_0x92a9('0x19')](handleEntityNotFound(_0x37ac30,null))[_0x92a9('0x19')](saveUpdates(_0x3e19b1[_0x92a9('0xbc')],null))[_0x92a9('0x19')](respondWithResult(_0x37ac30,null))[_0x92a9('0x2a')](handleError(_0x37ac30,null));};exports[_0x92a9('0x1a')]=function(_0x255559,_0x1e68b9){return db['MailInteraction'][_0x92a9('0x54')]({'where':{'id':_0x255559[_0x92a9('0xbd')]['id']}})[_0x92a9('0x19')](handleEntityNotFound(_0x1e68b9,null))[_0x92a9('0x19')](removeEntity(_0x1e68b9,null))[_0x92a9('0x2a')](handleError(_0x1e68b9,null));};exports[_0x92a9('0xbe')]=function(_0x1d5511,_0x1fac35){return db[_0x92a9('0x2d')][_0x92a9('0xbe')]()[_0x92a9('0x19')](respondWithResult(_0x1fac35,null))[_0x92a9('0x2a')](handleError(_0x1fac35,null));};exports[_0x92a9('0xbf')]=function(_0x14f10a,_0x50e235){return db[_0x92a9('0xc0')][_0x92a9('0x54')]({'where':{'id':_0x14f10a[_0x92a9('0xbd')]['id']}})['then'](handleEntityNotFound(_0x50e235,null))[_0x92a9('0x19')](function(_0x18e503){if(_0x18e503){return _0x18e503[_0x92a9('0xbf')](_0x14f10a[_0x92a9('0xbc')][_0x92a9('0xc1')],_[_0x92a9('0xc2')](_0x14f10a['body'],[_0x92a9('0xc1'),'id'])||{});}})[_0x92a9('0x19')](respondWithResult(_0x50e235,null))[_0x92a9('0x2a')](handleError(_0x50e235,null));};exports[_0x92a9('0xc3')]=function(_0x2ded60,_0x48a344){var _0x4e911b={'raw':![],'where':{}};var _0x643f01={};var _0x2c25c0={'count':0x0,'rows':[]};return db[_0x92a9('0x2d')][_0x92a9('0x25')]({'where':{'id':_0x2ded60['params']['id']}})[_0x92a9('0x19')](handleEntityNotFound(_0x48a344,null))[_0x92a9('0x19')](function(_0x58cf39){if(_0x58cf39){_0x643f01[_0x92a9('0x30')]=_[_0x92a9('0xb7')](db[_0x92a9('0xc0')][_0x92a9('0xb8')]);_0x643f01[_0x92a9('0x31')]=_[_0x92a9('0xb7')](_0x2ded60[_0x92a9('0x31')]);_0x643f01[_0x92a9('0x32')]=_[_0x92a9('0x33')](_0x643f01['model'],_0x643f01['query']);_0x4e911b[_0x92a9('0x35')]=_[_0x92a9('0x33')](_0x643f01['model'],qs['fields'](_0x2ded60[_0x92a9('0x31')][_0x92a9('0x34')]));_0x4e911b[_0x92a9('0x35')]=_0x4e911b[_0x92a9('0x35')][_0x92a9('0x53')]?_0x4e911b[_0x92a9('0x35')]:_0x643f01[_0x92a9('0x30')];if(!_0x2ded60[_0x92a9('0x31')][_0x92a9('0x36')](_0x92a9('0x37'))){_0x4e911b[_0x92a9('0x13')]=qs['limit'](_0x2ded60[_0x92a9('0x31')][_0x92a9('0x13')]);_0x4e911b[_0x92a9('0x12')]=qs['offset'](_0x2ded60[_0x92a9('0x31')]['offset']);}_0x4e911b['order']=qs['sort'](_0x2ded60[_0x92a9('0x31')][_0x92a9('0x39')]);_0x4e911b['where']=qs[_0x92a9('0x32')](_['pick'](_0x2ded60[_0x92a9('0x31')],_0x643f01[_0x92a9('0x32')]));_0x4e911b['where'][_0x92a9('0xb3')]=_0x58cf39['id'];if(_0x2ded60[_0x92a9('0x31')]['filter']){_0x4e911b[_0x92a9('0x6b')]=_[_0x92a9('0x90')](_0x4e911b[_0x92a9('0x6b')],{'$or':_['map'](_0x4e911b[_0x92a9('0x35')],function(_0x5f216f){var _0x472a5a={};_0x472a5a[_0x5f216f]={'$like':'%'+_0x2ded60[_0x92a9('0x31')][_0x92a9('0x78')]+'%'};return _0x472a5a;})});}if(_0x2ded60[_0x92a9('0x31')][_0x92a9('0x6f')]){var _0xb61a6a=_0x2ded60['query'][_0x92a9('0x6f')][_0x92a9('0x22')](',');var _0x2faf8a={};_0x2faf8a[_0xb61a6a[0x0]]={'$gte':moment(_0xb61a6a[0x1])[_0x92a9('0xc4')](_0x92a9('0xc5'))};_0x4e911b['where']=_[_0x92a9('0x90')](_0x4e911b[_0x92a9('0x6b')],_0x2faf8a);}_0x4e911b=_['merge']({},_0x4e911b,_0x2ded60[_0x92a9('0xba')]);return db[_0x92a9('0xc0')][_0x92a9('0x14')]({'where':_0x4e911b[_0x92a9('0x6b')]})['then'](function(_0x1b8f73){_0x2c25c0['count']=_0x1b8f73;if(_0x2ded60[_0x92a9('0x31')][_0x92a9('0xb9')]){_0x4e911b['include']=[{'all':!![]}];}return db[_0x92a9('0xc0')][_0x92a9('0xc6')](_0x4e911b);})['then'](function(_0x1c3310){if(_0x2ded60[_0x92a9('0x31')][_0x92a9('0xc7')]===_0x92a9('0xc8')){for(var _0x5ea764=0x0;_0x5ea764<_0x1c3310[_0x92a9('0x53')];_0x5ea764++){_0x1c3310[_0x5ea764]['body']=juice(_0x1c3310[_0x5ea764][_0x92a9('0xbc')]);}}_0x2c25c0[_0x92a9('0xb5')]=_0x1c3310;return _0x2c25c0;});}})[_0x92a9('0x19')](respondWithFilteredResult(_0x48a344,_0x4e911b))['catch'](handleError(_0x48a344,null));};exports[_0x92a9('0xc9')]=function(_0x16c71b,_0x226411){return db['MailInteraction'][_0x92a9('0x54')]({'where':{'id':_0x16c71b['params']['id']}})[_0x92a9('0x19')](handleEntityNotFound(_0x226411,null))[_0x92a9('0x19')](function(_0xdc94ea){if(_0xdc94ea){return _0xdc94ea['setTags'](_0x16c71b[_0x92a9('0xbc')]['ids'],_['omit'](_0x16c71b[_0x92a9('0xbc')],[_0x92a9('0xc1'),'id'])||{})['spread'](function(){return db[_0x92a9('0x64')]['findAll']({'attributes':['id',_0x92a9('0x1c'),_0x92a9('0x3c')],'where':{'id':_0x16c71b[_0x92a9('0xbc')][_0x92a9('0xc1')]}});})[_0x92a9('0x19')](function(_0x2be08b){socket[_0x92a9('0xca')](_0x92a9('0xcb'),{'id':Number(_0x16c71b[_0x92a9('0xbd')]['id']),'tags':_0x2be08b||[]});return{'id':Number(_0x16c71b[_0x92a9('0xbd')]['id']),'tags':_0x2be08b||[]};});}})[_0x92a9('0x19')](respondWithResult(_0x226411,null))['catch'](handleError(_0x226411,null));};exports['removeTags']=function(_0x5cf378,_0x88ad72){return db[_0x92a9('0x2d')][_0x92a9('0x54')]({'where':{'id':_0x5cf378[_0x92a9('0xbd')]['id']}})[_0x92a9('0x19')](handleEntityNotFound(_0x88ad72,null))['then'](function(_0x4f96ed){if(_0x4f96ed){return _0x4f96ed[_0x92a9('0xcc')](_0x5cf378['query'][_0x92a9('0xc1')]);}})[_0x92a9('0x19')](respondWithStatusCode(_0x88ad72,null))[_0x92a9('0x2a')](handleError(_0x88ad72,null));};exports[_0x92a9('0xcd')]=function(_0x1a5ddc,_0x5a4796){var _0x3fe6c1=moment()[_0x92a9('0xce')]()[_0x92a9('0x8e')]();var _0x39db87=path[_0x92a9('0xcf')](config['root'],_0x92a9('0xd0'),_0x92a9('0xd1'),_0x92a9('0xd2'));var _0x355fc3=path[_0x92a9('0xcf')](config[_0x92a9('0xd3')],_0x92a9('0xd0'),_0x92a9('0xd1'),_0x92a9('0xd4'));var _0x5c0b96=path['join'](_0x39db87,_0x3fe6c1);var _0x3811ae=util['format'](_0x92a9('0xd5'),_0x1a5ddc['params']['id'],_0x3fe6c1);var _0x40c530=path[_0x92a9('0xcf')](_0x39db87,_0x3811ae);var _0x4d2550=[];if(_0x1a5ddc[_0x92a9('0x31')]['attachments']){_0x4d2550[_0x92a9('0x24')]({'model':db[_0x92a9('0xd6')],'as':'Attachments','raw':!![]});}var _0x39f36a=[{'model':db[_0x92a9('0xc0')],'as':'Messages','attributes':['id','body','from','to','cc',_0x92a9('0xd7'),_0x92a9('0xd8'),_0x92a9('0x6d')],'where':{'secret':![]},'order':qs[_0x92a9('0x39')]('id'),'include':_0x4d2550}];return db[_0x92a9('0x2d')]['find']({'where':{'id':_0x1a5ddc['params']['id']},'include':_0x39f36a})['then'](handleEntityNotFound(_0x5a4796,null))[_0x92a9('0x19')](function(_0x339b50){if(_0x339b50&&_0x339b50[_0x92a9('0xd9')]){var _0x14116f=_0x339b50[_0x92a9('0xda')]({'plain':!![]});fs[_0x92a9('0xdb')](_0x5c0b96);return BPromise['each'](_0x14116f[_0x92a9('0xd9')],function(_0x40bcb1,_0x5e703b){var _0x39fe7c={'from':_0x40bcb1[_0x92a9('0x3d')],'to':_0x40bcb1['to'],'subject':_0x40bcb1[_0x92a9('0xd8')],'html':htmlEntities[_0x92a9('0xdc')](_0x40bcb1['body']),'headers':{'Date':moment(_0x40bcb1[_0x92a9('0x6d')])[_0x92a9('0xc4')](_0x92a9('0xdd'))},'attachments':[]};if(_0x40bcb1['cc']){_0x39fe7c['headers']['Cc']=_0x40bcb1['cc'];}if(_0x40bcb1[_0x92a9('0xd7')]){_0x39fe7c[_0x92a9('0xde')][_0x92a9('0xdf')]=_0x40bcb1[_0x92a9('0xd7')];}return new BPromise(function(_0x5b1efb,_0x147a19){if(_0x40bcb1[_0x92a9('0xe0')]){for(var _0x2222a2=0x0;_0x2222a2<_0x40bcb1[_0x92a9('0xe0')][_0x92a9('0x53')];_0x2222a2++){var _0x26c14a=_0x40bcb1[_0x92a9('0xe0')][_0x2222a2];var _0x17f3bc=path[_0x92a9('0xcf')](_0x355fc3,_0x26c14a[_0x92a9('0xe1')]);if(fs[_0x92a9('0xe2')](_0x17f3bc)){_0x39fe7c['attachments']['push']({'name':_0x26c14a[_0x92a9('0x1c')],'contentType':_0x26c14a[_0x92a9('0x2f')],'data':fs[_0x92a9('0xe3')](_0x17f3bc)});}}}emlformat['build'](_0x39fe7c,function(_0x166547,_0xf560d3){if(_0x166547)return _0x147a19(_0x166547);fs[_0x92a9('0xe4')](path[_0x92a9('0xcf')](_0x5c0b96,util[_0x92a9('0xc4')](_0x92a9('0xe5'),_0x5e703b)),_0xf560d3);return _0x5b1efb(_0xf560d3);});});})[_0x92a9('0x19')](function(){return new BPromise(function(_0x4bc8e6,_0x477f59){zipdir(_0x5c0b96,{'saveTo':_0x40c530},function(_0x29fdb9,_0xbdffe9){if(_0x29fdb9)return _0x477f59(_0x29fdb9);return _0x4bc8e6(_0xbdffe9);});})[_0x92a9('0x19')](function(){return new BPromise(function(_0x2f3297,_0x5b0dbc){rimraf(_0x5c0b96,function(_0x4fbcab){if(_0x4fbcab)_0x5b0dbc(_0x4fbcab);return _0x2f3297();});});})[_0x92a9('0x19')](function(){return _0x5a4796[_0x92a9('0xcd')](_0x40c530,_0x3811ae,function(_0x164040){if(!_0x164040)fs['unlinkSync'](_0x40c530);});});});}else{return _0x5a4796[_0x92a9('0xf')](0xc8);}})['catch'](handleError(_0x5a4796,null));};
\ No newline at end of file