Built motion from commit efa66e19.|2.6.22
[motion2.git] / server / api / mailInteraction / mailInteraction.controller.js
index 3edd2d9..dfeecfe 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 _0xefb1=['path','lodash','juice','ioredis','../../config/logger','api','../../config/environment','../../mysqldb','html-entities','redis','defaults','localhost','socket.io-emitter','register','sendStatus','status','json','undefined','limit','offset','count','set','update','destroy','then','error','stack','name','send','index','MailInteraction','rawAttributes','fieldName','type','key','getOptions','findAll','mail','query','catch','show','model','keys','filters','intersection','attributes','fields','length','includeAll','merge','options','find','body','describe','addMessage','MailMessage','params','ids','omit','getMessages','findOne','hasOwnProperty','order','sort','where','pick','MailInteractionId','filter','map','$gte','split','YYYY-MM-DD\x20HH:mm:ss','rows','addTags','setTags','Tag','emit','removeTags','unix','toString','root','server','files','tmp','join','format','transcript-%d-%s.zip','attachments','push','Attachment','Messages','from','bcc','createdAt','get','mkdirSync','each','missing.recipient@your.company.com','subject','decode','ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ','headers','Attachments','existsSync','readFileSync','build','writeFileSync','message%d.eml','download','unlinkSync','eml-format','rimraf','zip-dir','moment','bluebird','util'];(function(_0x21267d,_0x18c6f5){var _0x679d4c=function(_0x7f1e92){while(--_0x7f1e92){_0x21267d['push'](_0x21267d['shift']());}};_0x679d4c(++_0x18c6f5);}(_0xefb1,0xe2));var _0x1efb=function(_0x35d8b5,_0x51500f){_0x35d8b5=_0x35d8b5-0x0;var _0x50c046=_0xefb1[_0x35d8b5];return _0x50c046;};'use strict';var emlformat=require(_0x1efb('0x0'));var rimraf=require(_0x1efb('0x1'));var zipdir=require(_0x1efb('0x2'));var moment=require(_0x1efb('0x3'));var BPromise=require(_0x1efb('0x4'));var util=require(_0x1efb('0x5'));var path=require(_0x1efb('0x6'));var fs=require('fs');var _=require(_0x1efb('0x7'));var juice=require(_0x1efb('0x8'));var Redis=require(_0x1efb('0x9'));var interaction=require('../../components/interaction/service');var qs=require('../../components/parsers/qs');var logger=require(_0x1efb('0xa'))(_0x1efb('0xb'));var config=require(_0x1efb('0xc'));var db=require(_0x1efb('0xd'))['db'];var htmlEntities=require(_0x1efb('0xe'));config[_0x1efb('0xf')]=_[_0x1efb('0x10')](config[_0x1efb('0xf')],{'host':_0x1efb('0x11'),'port':0x18eb});var socket=require(_0x1efb('0x12'))(new Redis(config[_0x1efb('0xf')]));require('./mailInteraction.socket')[_0x1efb('0x13')](socket);function respondWithStatusCode(_0x5ddd5c,_0x10b3de){_0x10b3de=_0x10b3de||0xcc;return function(_0x11d57a){if(_0x11d57a){return _0x5ddd5c[_0x1efb('0x14')](_0x10b3de);}return _0x5ddd5c[_0x1efb('0x15')](_0x10b3de)['end']();};}function respondWithResult(_0x5c6cde,_0x1abf9b){_0x1abf9b=_0x1abf9b||0xc8;return function(_0x401ca5){if(_0x401ca5){return _0x5c6cde[_0x1efb('0x15')](_0x1abf9b)[_0x1efb('0x16')](_0x401ca5);}};}function respondWithFilteredResult(_0x46b465,_0x27868f){return function(_0x548c1d){if(_0x548c1d){var _0x35350c=typeof _0x27868f['offset']===_0x1efb('0x17')&&typeof _0x27868f[_0x1efb('0x18')]==='undefined';var _0x19ec4e=_0x548c1d['count'];var _0x18f166=_0x35350c?0x0:_0x27868f[_0x1efb('0x19')];var _0x422753=_0x35350c?_0x548c1d[_0x1efb('0x1a')]:_0x27868f[_0x1efb('0x19')]+_0x27868f[_0x1efb('0x18')];var _0x2336d1;if(_0x422753>=_0x19ec4e){_0x422753=_0x19ec4e;_0x2336d1=0xc8;}else{_0x2336d1=0xce;}_0x46b465[_0x1efb('0x15')](_0x2336d1);return _0x46b465[_0x1efb('0x1b')]('Content-Range',_0x18f166+'-'+_0x422753+'/'+_0x19ec4e)[_0x1efb('0x16')](_0x548c1d);}return null;};}function saveUpdates(_0x53af97){return function(_0x578e52){if(_0x578e52){return _0x578e52[_0x1efb('0x1c')](_0x53af97)['then'](function(_0x3e01da){return _0x3e01da;});}return null;};}function removeEntity(_0x3c7dd0){return function(_0x53fc10){if(_0x53fc10){return _0x53fc10[_0x1efb('0x1d')]()[_0x1efb('0x1e')](function(){_0x3c7dd0[_0x1efb('0x15')](0xcc)['end']();});}};}function handleEntityNotFound(_0x734fd0){return function(_0x16fbf9){if(!_0x16fbf9){_0x734fd0[_0x1efb('0x14')](0x194);}return _0x16fbf9;};}function handleError(_0x22bb50,_0x3477d8){_0x3477d8=_0x3477d8||0x1f4;return function(_0x42ffc8){logger[_0x1efb('0x1f')](_0x42ffc8[_0x1efb('0x20')]);if(_0x42ffc8[_0x1efb('0x21')]){delete _0x42ffc8[_0x1efb('0x21')];}_0x22bb50[_0x1efb('0x15')](_0x3477d8)[_0x1efb('0x22')](_0x42ffc8);};}exports[_0x1efb('0x23')]=function(_0x8cb136,_0x300a54){var _0x5bbbcf={};var _0x1db225=_['map'](db[_0x1efb('0x24')][_0x1efb('0x25')],function(_0x25e508){return{'name':_0x25e508[_0x1efb('0x26')],'type':_0x25e508[_0x1efb('0x27')][_0x1efb('0x28')]};});_0x5bbbcf=qs[_0x1efb('0x29')](_0x1db225,_0x8cb136);return interaction[_0x1efb('0x2a')](_0x1efb('0x2b'),_0x8cb136[_0x1efb('0x2c')],_0x8cb136['user'],_0x5bbbcf,_0x1db225)[_0x1efb('0x1e')](respondWithFilteredResult(_0x300a54,_0x5bbbcf))[_0x1efb('0x2d')](handleError(_0x300a54,null));};exports[_0x1efb('0x2e')]=function(_0x5110e3,_0x4e5eca){var _0x26e4ab={'raw':![],'where':{'id':_0x5110e3['params']['id']}},_0x2628a6={};_0x2628a6[_0x1efb('0x2f')]=_[_0x1efb('0x30')](db[_0x1efb('0x24')][_0x1efb('0x25')]);_0x2628a6['query']=_[_0x1efb('0x30')](_0x5110e3[_0x1efb('0x2c')]);_0x2628a6[_0x1efb('0x31')]=_[_0x1efb('0x32')](_0x2628a6[_0x1efb('0x2f')],_0x2628a6['query']);_0x26e4ab[_0x1efb('0x33')]=_[_0x1efb('0x32')](_0x2628a6[_0x1efb('0x2f')],qs[_0x1efb('0x34')](_0x5110e3[_0x1efb('0x2c')][_0x1efb('0x34')]));_0x26e4ab['attributes']=_0x26e4ab[_0x1efb('0x33')][_0x1efb('0x35')]?_0x26e4ab[_0x1efb('0x33')]:_0x2628a6['model'];if(_0x5110e3['query'][_0x1efb('0x36')]){_0x26e4ab['include']=[{'all':!![]}];}_0x26e4ab=_[_0x1efb('0x37')]({},_0x26e4ab,_0x5110e3[_0x1efb('0x38')]);return db[_0x1efb('0x24')][_0x1efb('0x39')](_0x26e4ab)[_0x1efb('0x1e')](handleEntityNotFound(_0x4e5eca,null))[_0x1efb('0x1e')](respondWithResult(_0x4e5eca,null))[_0x1efb('0x2d')](handleError(_0x4e5eca,null));};exports['create']=function(_0x4bcc1c,_0x39a68e){return db[_0x1efb('0x24')]['create'](_0x4bcc1c[_0x1efb('0x3a')],{})[_0x1efb('0x1e')](respondWithResult(_0x39a68e,0xc9))[_0x1efb('0x2d')](handleError(_0x39a68e,null));};exports[_0x1efb('0x1c')]=function(_0xf85af4,_0x2ea1d1){if(_0xf85af4[_0x1efb('0x3a')]['id']){delete _0xf85af4[_0x1efb('0x3a')]['id'];}return db[_0x1efb('0x24')][_0x1efb('0x39')]({'where':{'id':_0xf85af4['params']['id']}})[_0x1efb('0x1e')](handleEntityNotFound(_0x2ea1d1,null))[_0x1efb('0x1e')](saveUpdates(_0xf85af4[_0x1efb('0x3a')],null))['then'](respondWithResult(_0x2ea1d1,null))[_0x1efb('0x2d')](handleError(_0x2ea1d1,null));};exports[_0x1efb('0x1d')]=function(_0x2da400,_0x51fe5e){return db[_0x1efb('0x24')][_0x1efb('0x39')]({'where':{'id':_0x2da400['params']['id']}})['then'](handleEntityNotFound(_0x51fe5e,null))[_0x1efb('0x1e')](removeEntity(_0x51fe5e,null))[_0x1efb('0x2d')](handleError(_0x51fe5e,null));};exports[_0x1efb('0x3b')]=function(_0x3a0bba,_0x560596){return db['MailInteraction'][_0x1efb('0x3b')]()[_0x1efb('0x1e')](respondWithResult(_0x560596,null))[_0x1efb('0x2d')](handleError(_0x560596,null));};exports[_0x1efb('0x3c')]=function(_0x314c4f,_0x41b6a1){return db[_0x1efb('0x3d')]['find']({'where':{'id':_0x314c4f[_0x1efb('0x3e')]['id']}})['then'](handleEntityNotFound(_0x41b6a1,null))[_0x1efb('0x1e')](function(_0x146148){if(_0x146148){return _0x146148['addMessage'](_0x314c4f['body'][_0x1efb('0x3f')],_[_0x1efb('0x40')](_0x314c4f[_0x1efb('0x3a')],[_0x1efb('0x3f'),'id'])||{});}})[_0x1efb('0x1e')](respondWithResult(_0x41b6a1,null))[_0x1efb('0x2d')](handleError(_0x41b6a1,null));};exports[_0x1efb('0x41')]=function(_0x30654f,_0x11687d){var _0x26b355={'raw':![],'where':{}};var _0x4f426a={};var _0x29e9a6={'count':0x0,'rows':[]};return db[_0x1efb('0x24')][_0x1efb('0x42')]({'where':{'id':_0x30654f[_0x1efb('0x3e')]['id']}})[_0x1efb('0x1e')](handleEntityNotFound(_0x11687d,null))['then'](function(_0x2ae2f6){if(_0x2ae2f6){_0x4f426a['model']=_[_0x1efb('0x30')](db[_0x1efb('0x3d')][_0x1efb('0x25')]);_0x4f426a[_0x1efb('0x2c')]=_['keys'](_0x30654f[_0x1efb('0x2c')]);_0x4f426a['filters']=_[_0x1efb('0x32')](_0x4f426a[_0x1efb('0x2f')],_0x4f426a['query']);_0x26b355[_0x1efb('0x33')]=_[_0x1efb('0x32')](_0x4f426a[_0x1efb('0x2f')],qs[_0x1efb('0x34')](_0x30654f['query'][_0x1efb('0x34')]));_0x26b355['attributes']=_0x26b355[_0x1efb('0x33')][_0x1efb('0x35')]?_0x26b355[_0x1efb('0x33')]:_0x4f426a[_0x1efb('0x2f')];if(!_0x30654f[_0x1efb('0x2c')][_0x1efb('0x43')]('nolimit')){_0x26b355[_0x1efb('0x18')]=qs[_0x1efb('0x18')](_0x30654f[_0x1efb('0x2c')][_0x1efb('0x18')]);_0x26b355[_0x1efb('0x19')]=qs[_0x1efb('0x19')](_0x30654f[_0x1efb('0x2c')][_0x1efb('0x19')]);}_0x26b355[_0x1efb('0x44')]=qs['sort'](_0x30654f[_0x1efb('0x2c')][_0x1efb('0x45')]);_0x26b355[_0x1efb('0x46')]=qs[_0x1efb('0x31')](_[_0x1efb('0x47')](_0x30654f[_0x1efb('0x2c')],_0x4f426a[_0x1efb('0x31')]));_0x26b355['where'][_0x1efb('0x48')]=_0x2ae2f6['id'];if(_0x30654f[_0x1efb('0x2c')][_0x1efb('0x49')]){_0x26b355[_0x1efb('0x46')]=_[_0x1efb('0x37')](_0x26b355[_0x1efb('0x46')],{'$or':_[_0x1efb('0x4a')](_0x26b355[_0x1efb('0x33')],function(_0x2d5821){var _0x57252e={};_0x57252e[_0x2d5821]={'$like':'%'+_0x30654f['query']['filter']+'%'};return _0x57252e;})});}if(_0x30654f[_0x1efb('0x2c')]['$gte']){var _0x32f98b=_0x30654f[_0x1efb('0x2c')][_0x1efb('0x4b')][_0x1efb('0x4c')](',');var _0x2708dd={};_0x2708dd[_0x32f98b[0x0]]={'$gte':moment(_0x32f98b[0x1])['format'](_0x1efb('0x4d'))};_0x26b355['where']=_[_0x1efb('0x37')](_0x26b355['where'],_0x2708dd);}_0x26b355=_[_0x1efb('0x37')]({},_0x26b355,_0x30654f['options']);return db['MailMessage'][_0x1efb('0x1a')]({'where':_0x26b355[_0x1efb('0x46')]})['then'](function(_0x584158){_0x29e9a6[_0x1efb('0x1a')]=_0x584158;if(_0x30654f[_0x1efb('0x2c')]['includeAll']){_0x26b355['include']=[{'all':!![]}];}return db['MailMessage'][_0x1efb('0x2a')](_0x26b355);})[_0x1efb('0x1e')](function(_0x4792f4){if(_0x30654f['query']['inlineCss']==='true'){for(var _0x10d1bb=0x0;_0x10d1bb<_0x4792f4[_0x1efb('0x35')];_0x10d1bb++){_0x4792f4[_0x10d1bb][_0x1efb('0x3a')]=juice(_0x4792f4[_0x10d1bb]['body']);}}_0x29e9a6[_0x1efb('0x4e')]=_0x4792f4;return _0x29e9a6;});}})[_0x1efb('0x1e')](respondWithFilteredResult(_0x11687d,_0x26b355))['catch'](handleError(_0x11687d,null));};exports[_0x1efb('0x4f')]=function(_0x5013ba,_0x3e4370){return db[_0x1efb('0x24')][_0x1efb('0x39')]({'where':{'id':_0x5013ba[_0x1efb('0x3e')]['id']}})['then'](handleEntityNotFound(_0x3e4370,null))[_0x1efb('0x1e')](function(_0x2376e2){if(_0x2376e2){return _0x2376e2[_0x1efb('0x50')](_0x5013ba[_0x1efb('0x3a')][_0x1efb('0x3f')],_[_0x1efb('0x40')](_0x5013ba['body'],[_0x1efb('0x3f'),'id'])||{})['spread'](function(){return db[_0x1efb('0x51')]['findAll']({'attributes':['id',_0x1efb('0x21'),'color'],'where':{'id':_0x5013ba[_0x1efb('0x3a')][_0x1efb('0x3f')]}});})[_0x1efb('0x1e')](function(_0x393005){socket[_0x1efb('0x52')]('mailInteractionTags:save',{'id':Number(_0x5013ba[_0x1efb('0x3e')]['id']),'tags':_0x393005||[]});return{'id':Number(_0x5013ba[_0x1efb('0x3e')]['id']),'tags':_0x393005||[]};});}})[_0x1efb('0x1e')](respondWithResult(_0x3e4370,null))['catch'](handleError(_0x3e4370,null));};exports[_0x1efb('0x53')]=function(_0x47ef6a,_0x17c2df){return db[_0x1efb('0x24')]['find']({'where':{'id':_0x47ef6a[_0x1efb('0x3e')]['id']}})[_0x1efb('0x1e')](handleEntityNotFound(_0x17c2df,null))[_0x1efb('0x1e')](function(_0x4af0c0){if(_0x4af0c0){return _0x4af0c0[_0x1efb('0x53')](_0x47ef6a[_0x1efb('0x2c')][_0x1efb('0x3f')]);}})[_0x1efb('0x1e')](respondWithStatusCode(_0x17c2df,null))[_0x1efb('0x2d')](handleError(_0x17c2df,null));};exports['download']=function(_0x3b54bf,_0x291d64){var _0x3ebead=moment()[_0x1efb('0x54')]()[_0x1efb('0x55')]();var _0x1d3c1b=path['join'](config[_0x1efb('0x56')],_0x1efb('0x57'),_0x1efb('0x58'),_0x1efb('0x59'));var _0x5da7e5=path[_0x1efb('0x5a')](config[_0x1efb('0x56')],'server','files','attachments');var _0x3e8036=path['join'](_0x1d3c1b,_0x3ebead);var _0x57470e=util[_0x1efb('0x5b')](_0x1efb('0x5c'),_0x3b54bf['params']['id'],_0x3ebead);var _0x486e53=path['join'](_0x1d3c1b,_0x57470e);var _0x3d4769=[];if(_0x3b54bf[_0x1efb('0x2c')][_0x1efb('0x5d')]){_0x3d4769[_0x1efb('0x5e')]({'model':db[_0x1efb('0x5f')],'as':'Attachments','raw':!![]});}var _0x168e6d=[{'model':db[_0x1efb('0x3d')],'as':_0x1efb('0x60'),'attributes':['id','body',_0x1efb('0x61'),'to','cc',_0x1efb('0x62'),'subject',_0x1efb('0x63')],'where':{'secret':![]},'order':qs[_0x1efb('0x45')]('id'),'include':_0x3d4769}];return db[_0x1efb('0x24')][_0x1efb('0x39')]({'where':{'id':_0x3b54bf[_0x1efb('0x3e')]['id']},'include':_0x168e6d})[_0x1efb('0x1e')](handleEntityNotFound(_0x291d64,null))[_0x1efb('0x1e')](function(_0x54a006){if(_0x54a006&&_0x54a006[_0x1efb('0x60')]){var _0x42ba95=_0x54a006[_0x1efb('0x64')]({'plain':!![]});fs[_0x1efb('0x65')](_0x3e8036);return BPromise[_0x1efb('0x66')](_0x42ba95['Messages'],function(_0x470cd5,_0x524555){var _0x1330d1={'from':_0x470cd5[_0x1efb('0x61')],'to':_0x470cd5['to']||_0x1efb('0x67'),'subject':_0x470cd5[_0x1efb('0x68')],'html':htmlEntities[_0x1efb('0x69')](_0x470cd5['body']),'headers':{'Date':moment(_0x470cd5['createdAt'])[_0x1efb('0x5b')](_0x1efb('0x6a'))},'attachments':[]};if(_0x470cd5['cc']){_0x1330d1[_0x1efb('0x6b')]['Cc']=_0x470cd5['cc'];}if(_0x470cd5[_0x1efb('0x62')]){_0x1330d1['headers']['Bcc']=_0x470cd5[_0x1efb('0x62')];}return new BPromise(function(_0x48fe3c,_0x220bd8){if(_0x470cd5[_0x1efb('0x6c')]){for(var _0x59afd5=0x0;_0x59afd5<_0x470cd5[_0x1efb('0x6c')]['length'];_0x59afd5++){var _0x314dbd=_0x470cd5[_0x1efb('0x6c')][_0x59afd5];var _0x3d03f9=path['join'](_0x5da7e5,_0x314dbd['basename']);if(fs[_0x1efb('0x6d')](_0x3d03f9)){_0x1330d1[_0x1efb('0x5d')][_0x1efb('0x5e')]({'name':_0x314dbd['name'],'contentType':_0x314dbd[_0x1efb('0x27')],'data':fs[_0x1efb('0x6e')](_0x3d03f9)});}}}emlformat[_0x1efb('0x6f')](_0x1330d1,function(_0x564db9,_0x5c36bc){if(_0x564db9)return _0x220bd8(_0x564db9);fs[_0x1efb('0x70')](path[_0x1efb('0x5a')](_0x3e8036,util[_0x1efb('0x5b')](_0x1efb('0x71'),_0x524555)),_0x5c36bc);return _0x48fe3c(_0x5c36bc);});});})[_0x1efb('0x1e')](function(){return new BPromise(function(_0x5d6d67,_0x11475e){zipdir(_0x3e8036,{'saveTo':_0x486e53},function(_0x7d8711,_0x3d5862){if(_0x7d8711)return _0x11475e(_0x7d8711);return _0x5d6d67(_0x3d5862);});})[_0x1efb('0x1e')](function(){return new BPromise(function(_0x2dd8a6,_0x204b7f){rimraf(_0x3e8036,function(_0x2de895){if(_0x2de895)_0x204b7f(_0x2de895);return _0x2dd8a6();});});})[_0x1efb('0x1e')](function(){return _0x291d64[_0x1efb('0x72')](_0x486e53,_0x57470e,function(_0x33dc22){if(!_0x33dc22)fs[_0x1efb('0x73')](_0x486e53);});});});}else{return _0x291d64['sendStatus'](0xc8);}})[_0x1efb('0x2d')](handleError(_0x291d64,null));};
\ No newline at end of file