Built motion from commit d5e4af8c.|2.6.23
[motion2.git] / server / api / mailInteraction / mailInteraction.controller.js
index 753dec9..01e502a 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xcc73=['log','err','unlinkSync','eml-format','rimraf','request-promise','bluebird','path','sox','to-csv','ejs','lodash','crypto','jsforce','desk.js','papaparse','html-to-text','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/utils','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./mailInteraction.socket','register','sendStatus','status','end','json','count','offset','Content-Range','reject','update','destroy','then','name','send','Users','map','fullname','TagIds','Tags','push','MailInteraction','findOne','lastMsgBody','lastMsgText','catch','rawAttributes','fieldName','type','key','model','query','filters','intersection','attributes','fields','length','hasOwnProperty','limit','sort','where','pick','select','field','color','from','tools_tags','u.id','u.fullname','ui.MailInteractionId','left_join','users','u.id\x20=\x20ui.UserId','mail_interactions','cm_contacts','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','o.id\x20=\x20i.UserId','mail_accounts','a.id\x20=\x20i.MailAccountId','mail_messages','me.MailInteractionId\x20=\x20i.id','mail_interaction_has_tags','it.MailInteractionId\x20=\x20i.id','t.id\x20=\x20it.TagId','expr','search','parseSearch','conditions','find','value','`\x20=\x200','having','Contact','split','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?','ContactId','buildExpression','start','Tag','forEach','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','User','operator','$substring','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','UserId','plainBody','text','keys','some','isEmpty','i.MailAccountId\x20IN\x20?','concat','createdAt','parse','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','\x20=\x20?','read','`unreadMessages`\x20=\x200','`unreadMessages`\x20>\x200','tag','isArray','filter','replace','\x27\x27\x27\x27','isNumeric','i.id\x20LIKE\x20?','isEmail','c.email\x20LIKE\x20?','MATCH\x20(i.to,\x20i.subject)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','getFullTextValue','Sequelize','QueryTypes','SELECT','clone','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','unreadMessages','order','DESC','resolve','i.MailAccountId\x20IS\x20NOT\x20NULL','user','getMailAccounts','i.MailAccountId\x20IS\x20NULL','toString','sequelize','merge','Account.key','a.mandatoryDisposition','i.updatedAt','i.closed','i.closedAt','i.attach','i.lastMsgAt','i.lastMsgDirection','i.subject','i.to','i.ContactId','i.MailAccountId','c.firstName','Contact.firstName','c.lastName','Contact.lastName','Contact.email','c.phone','Contact.phone','c.mobile','Contact.mobile','o.fullname','Owner.fullname','o.internal','ui.MailInteractionId\x20IN\x20?','groupBy','MailInteractionId','Setting','enableEmailPreview','all','rows','show','params','includeAll','include','options','create','body','describe','addMessage','ids','getMessages','MailMessage','$gte','YYYY-MM-DD\x20HH:mm:ss','findAll','setTags','omit','emit','mailInteractionTags:save','removeTags','join','files','tmp','root','attachments','format','Attachments','Messages','bcc','subject','get','mkdirSync','each','ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ','headers','basename','existsSync','readFileSync','build','writeFileSync','download'];(function(_0x2f0d11,_0x239b18){var _0x4879cf=function(_0x4036f2){while(--_0x4036f2){_0x2f0d11['push'](_0x2f0d11['shift']());}};_0x4879cf(++_0x239b18);}(_0xcc73,0x1cb));var _0x3cc7=function(_0x432682,_0x253044){_0x432682=_0x432682-0x0;var _0x463d05=_0xcc73[_0x432682];return _0x463d05;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x3cc7('0x0'));var rimraf=require(_0x3cc7('0x1'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x3cc7('0x2'));var moment=require('moment');var BPromise=require(_0x3cc7('0x3'));var Mustache=require('mustache');var util=require('util');var path=require(_0x3cc7('0x4'));var sox=require(_0x3cc7('0x5'));var csv=require(_0x3cc7('0x6'));var ejs=require(_0x3cc7('0x7'));var fs=require('fs');var _=require(_0x3cc7('0x8'));var squel=require('squel');var crypto=require(_0x3cc7('0x9'));var jsforce=require(_0x3cc7('0xa'));var deskjs=require(_0x3cc7('0xb'));var toCsv=require(_0x3cc7('0x6'));var querystring=require('querystring');var Papa=require(_0x3cc7('0xc'));var htmlToText=require(_0x3cc7('0xd'));var Redis=require(_0x3cc7('0xe'));var authService=require(_0x3cc7('0xf'));var qs=require(_0x3cc7('0x10'));var as=require(_0x3cc7('0x11'));var hardwareService=require(_0x3cc7('0x12'));var logger=require('../../config/logger')('api');var utils=require(_0x3cc7('0x13'));var config=require('../../config/environment');var db=require(_0x3cc7('0x14'))['db'];config[_0x3cc7('0x15')]=_[_0x3cc7('0x16')](config[_0x3cc7('0x15')],{'host':_0x3cc7('0x17'),'port':0x18eb});var socket=require(_0x3cc7('0x18'))(new Redis(config[_0x3cc7('0x15')]));require(_0x3cc7('0x19'))[_0x3cc7('0x1a')](socket);function respondWithStatusCode(_0xab7f06,_0x4238d5){_0x4238d5=_0x4238d5||0xcc;return function(_0x129d5b){if(_0x129d5b){return _0xab7f06[_0x3cc7('0x1b')](_0x4238d5);}return _0xab7f06[_0x3cc7('0x1c')](_0x4238d5)[_0x3cc7('0x1d')]();};}function respondWithResult(_0x857775,_0x2c4688){_0x2c4688=_0x2c4688||0xc8;return function(_0x1320a8){if(_0x1320a8){return _0x857775[_0x3cc7('0x1c')](_0x2c4688)[_0x3cc7('0x1e')](_0x1320a8);}};}function respondWithFilteredResult(_0xfa1cc8,_0x1bf3b7){return function(_0x2a4ddf){if(_0x2a4ddf){var _0xff4317=_0x2a4ddf[_0x3cc7('0x1f')],_0x118aa0=_0x1bf3b7[_0x3cc7('0x20')],_0x2f196a=_0x1bf3b7['offset']+_0x1bf3b7['limit'],_0x1545a0;if(_0x2f196a>=_0xff4317){_0x2f196a=_0xff4317;_0x1545a0=0xc8;}else{_0x1545a0=0xce;}_0xfa1cc8[_0x3cc7('0x1c')](_0x1545a0);return _0xfa1cc8['set'](_0x3cc7('0x21'),_0x118aa0+'-'+_0x2f196a+'/'+_0xff4317)[_0x3cc7('0x1e')](_0x2a4ddf);}return null;};}function patchUpdates(_0x252a35){return function(_0x576bf5){try{jsonpatch['apply'](_0x576bf5,_0x252a35,!![]);}catch(_0x2434f2){return BPromise[_0x3cc7('0x22')](_0x2434f2);}return _0x576bf5['save']();};}function saveUpdates(_0x40906b,_0x2ff800){return function(_0x4bc893){if(_0x4bc893){return _0x4bc893[_0x3cc7('0x23')](_0x40906b)['then'](function(_0x338cd3){return _0x338cd3;});}return null;};}function removeEntity(_0x50a8fb,_0x1cfcee){return function(_0x3b1fe6){if(_0x3b1fe6){return _0x3b1fe6[_0x3cc7('0x24')]()[_0x3cc7('0x25')](function(){_0x50a8fb[_0x3cc7('0x1c')](0xcc)[_0x3cc7('0x1d')]();});}};}function handleEntityNotFound(_0x534cea,_0x2fa3d5){return function(_0x1559b6){if(!_0x1559b6){_0x534cea[_0x3cc7('0x1b')](0x194);}return _0x1559b6;};}function handleError(_0x5f0a09,_0x358c12){_0x358c12=_0x358c12||0x1f4;return function(_0x595e7e){logger['error'](_0x595e7e['stack']);if(_0x595e7e[_0x3cc7('0x26')]){delete _0x595e7e[_0x3cc7('0x26')];}_0x5f0a09['status'](_0x358c12)[_0x3cc7('0x27')](_0x595e7e);};}function getInteractionUsers(_0xb6480e,_0x2bc904){return new BPromise(function(_0x17aa73,_0x40a01c){try{if(_0x2bc904[_0xb6480e['id']]){_0xb6480e[_0x3cc7('0x28')]=_[_0x3cc7('0x29')](_0x2bc904[_0xb6480e['id']],function(_0x1e14b4){return{'id':_0x1e14b4['id'],'fullname':_0x1e14b4[_0x3cc7('0x2a')]};});}}catch(_0x30ccb6){_0x40a01c(_0x30ccb6);}_0x17aa73(_0xb6480e);});}function getInteractionTags(_0x40ab90,_0x30480e){return new BPromise(function(_0xded386,_0x65e2df){try{if(_0x40ab90[_0x3cc7('0x2b')]){_0x40ab90['Tags']=[];_0x40ab90[_0x3cc7('0x2b')]['split'](',')['forEach'](function(_0x5f4c6f){_0x40ab90[_0x3cc7('0x2c')][_0x3cc7('0x2d')](_0x30480e[_0x5f4c6f]);});}delete _0x40ab90[_0x3cc7('0x2b')];}catch(_0x12a828){_0x65e2df(_0x12a828);}_0xded386(_0x40ab90);});}function getLastMessageText(_0x713682){return new BPromise(function(_0x45494a,_0x2ecdc2){return db[_0x3cc7('0x2e')][_0x3cc7('0x2f')]({'where':{'id':_0x713682['id']},'attributes':[_0x3cc7('0x30'),_0x3cc7('0x31')],'raw':!![]})['then'](function(_0x1d0580){if(!_0x1d0580[_0x3cc7('0x31')]){_0x713682[_0x3cc7('0x31')]=_['trimStart'](htmlToText['fromString'](_0x1d0580[_0x3cc7('0x30')],{'preserveNewlines':!![],'singleNewLineParagraphs':!![],'uppercaseHeadings':![],'noLinkBrackets':!![],'ignoreImage':!![]}));}else{_0x713682[_0x3cc7('0x31')]=_0x1d0580['lastMsgText'];}_0x45494a(_0x713682);})[_0x3cc7('0x32')](function(_0x4b89af){_0x2ecdc2(_0x4b89af);});});}function updateMailInteraction(_0x297c19,_0x202cc8,_0x51fdc3,_0x96847b){return new BPromise(function(_0x301116,_0x2fba36){return getInteractionUsers(_0x297c19,_0x51fdc3)[_0x3cc7('0x25')](function(_0x428ad2){return getInteractionTags(_0x428ad2,_0x202cc8);})[_0x3cc7('0x25')](function(_0x5771c2){if(_0x96847b){_0x301116(getLastMessageText(_0x5771c2));}else{_0x301116(_0x5771c2);}})[_0x3cc7('0x32')](function(_0x1d3e94){_0x2fba36(_0x1d3e94);});});}exports['index']=function(_0x24409c,_0x1b0a1f){var _0x538cfe={},_0x3abeda={},_0x53cc1d={'count':0x0,'rows':[]};var _0x16e66a=_[_0x3cc7('0x29')](db[_0x3cc7('0x2e')][_0x3cc7('0x33')],function(_0x22ff63){return{'name':_0x22ff63[_0x3cc7('0x34')],'type':_0x22ff63[_0x3cc7('0x35')][_0x3cc7('0x36')]};});_0x3abeda[_0x3cc7('0x37')]=_[_0x3cc7('0x29')](_0x16e66a,_0x3cc7('0x26'));_0x3abeda[_0x3cc7('0x38')]=_['keys'](_0x24409c[_0x3cc7('0x38')]);_0x3abeda[_0x3cc7('0x39')]=_[_0x3cc7('0x3a')](_0x3abeda[_0x3cc7('0x37')],_0x3abeda[_0x3cc7('0x38')]);_0x538cfe[_0x3cc7('0x3b')]=_[_0x3cc7('0x3a')](_0x3abeda[_0x3cc7('0x37')],qs[_0x3cc7('0x3c')](_0x24409c[_0x3cc7('0x38')]['fields']));_0x538cfe[_0x3cc7('0x3b')]=_0x538cfe[_0x3cc7('0x3b')][_0x3cc7('0x3d')]?_0x538cfe[_0x3cc7('0x3b')]:_0x3abeda[_0x3cc7('0x37')];if(!_0x24409c[_0x3cc7('0x38')][_0x3cc7('0x3e')]('nolimit')){_0x538cfe[_0x3cc7('0x3f')]=qs[_0x3cc7('0x3f')](_0x24409c[_0x3cc7('0x38')][_0x3cc7('0x3f')]);_0x538cfe[_0x3cc7('0x20')]=qs[_0x3cc7('0x20')](_0x24409c[_0x3cc7('0x38')][_0x3cc7('0x20')]);}_0x538cfe['order']=qs[_0x3cc7('0x40')](_0x24409c[_0x3cc7('0x38')]['sort']);_0x538cfe[_0x3cc7('0x41')]=qs[_0x3cc7('0x39')](_[_0x3cc7('0x42')](_0x24409c[_0x3cc7('0x38')],_0x3abeda[_0x3cc7('0x39')]));var _0x447504=[];var _0x9625d0=squel[_0x3cc7('0x43')]()[_0x3cc7('0x44')]('id')[_0x3cc7('0x44')](_0x3cc7('0x26'))[_0x3cc7('0x44')](_0x3cc7('0x45'))[_0x3cc7('0x46')](_0x3cc7('0x47'));var _0x477278=squel['select']()[_0x3cc7('0x44')](_0x3cc7('0x48'))[_0x3cc7('0x44')](_0x3cc7('0x49'))['field'](_0x3cc7('0x4a'))[_0x3cc7('0x46')]('user_has_mail_interactions','ui')[_0x3cc7('0x4b')](_0x3cc7('0x4c'),'u',_0x3cc7('0x4d'));var _0x11ff4e=squel[_0x3cc7('0x43')]()['from'](_0x3cc7('0x4e'),'i')['left_join'](_0x3cc7('0x4f'),'c',_0x3cc7('0x50'))[_0x3cc7('0x4b')](_0x3cc7('0x4c'),'o',_0x3cc7('0x51'))['left_join'](_0x3cc7('0x52'),'a',_0x3cc7('0x53'))[_0x3cc7('0x4b')](_0x3cc7('0x54'),'me',_0x3cc7('0x55'))['left_join'](_0x3cc7('0x56'),'it',_0x3cc7('0x57'))[_0x3cc7('0x4b')]('tools_tags','t',_0x3cc7('0x58'));var _0x212a1a=squel[_0x3cc7('0x59')]();var _0x1aaac9=[];var _0x569774=squel[_0x3cc7('0x59')]();var _0x33e5fd;if(_0x24409c[_0x3cc7('0x38')][_0x3cc7('0x5a')]){_0x33e5fd=as[_0x3cc7('0x5b')](_0x24409c[_0x3cc7('0x38')][_0x3cc7('0x5a')]);var _0x478255=_0x33e5fd['sqlOperator'];for(var _0x5cb126=0x0;_0x5cb126<_0x33e5fd['conditions'][_0x3cc7('0x3d')];_0x5cb126++){var _0x554620=_0x33e5fd[_0x3cc7('0x5c')][_0x5cb126];var _0x1ce589='i';var _0x12b95b=_[_0x3cc7('0x5d')](_0x16e66a,[_0x3cc7('0x26'),_0x554620[_0x3cc7('0x44')]]);if(!_0x12b95b){switch(_0x554620[_0x3cc7('0x44')]){case'unreadMessages':if(_0x554620[_0x3cc7('0x5e')]==0x1){_0x11ff4e['having']('`'+_0x554620['field']+_0x3cc7('0x5f'));}else{_0x11ff4e[_0x3cc7('0x60')]('`'+_0x554620[_0x3cc7('0x44')]+'`\x20>\x200');}break;case _0x3cc7('0x61'):if(_0x554620['operator']==='$substring'){if(_0x554620[_0x3cc7('0x5e')][_0x3cc7('0x62')]('\x20')[_0x3cc7('0x3d')]>0x1){_0x212a1a[_0x478255](_0x3cc7('0x63'),qs['getFullTextValue'](_0x554620[_0x3cc7('0x5e')]),null);}else{var _0x2dfedc='%'+_0x554620[_0x3cc7('0x5e')]+'%';_0x212a1a[_0x478255](_0x3cc7('0x64'),_0x2dfedc,_0x2dfedc,_0x2dfedc);}}else{_0x12b95b=_['find'](_0x16e66a,[_0x3cc7('0x26'),_0x3cc7('0x65')]);_0x554620[_0x3cc7('0x44')]=_0x3cc7('0x65');_0x2fb030=as[_0x3cc7('0x66')](_0x1ce589,_0x12b95b[_0x3cc7('0x35')],_0x554620);_0x212a1a[_0x478255](_0x2fb030['text'],_0x2fb030['value'][_0x3cc7('0x67')],_0x2fb030['value']['end']);}break;case _0x3cc7('0x68'):var _0x30c69f=_0x554620[_0x3cc7('0x5e')][_0x3cc7('0x62')](',')[_0x3cc7('0x29')](function(_0x1c60b0){return Number(_0x1c60b0);});_0x30c69f[_0x3cc7('0x69')](function(_0x17eea9){_0x569774['or'](_0x3cc7('0x6a'),'%,'+_0x17eea9+',%');});_0x1aaac9=_['union'](_0x1aaac9,_0x30c69f);break;case _0x3cc7('0x6b'):if(_0x554620[_0x3cc7('0x6c')]===_0x3cc7('0x6d')){_0x212a1a[_0x478255](_0x3cc7('0x6e'),'%'+_0x554620['value']+'%',null);}else{_0x12b95b=_[_0x3cc7('0x5d')](_0x16e66a,['name',_0x3cc7('0x6f')]);_0x554620['field']=_0x3cc7('0x6f');_0x2fb030=as[_0x3cc7('0x66')](_0x1ce589,_0x12b95b[_0x3cc7('0x35')],_0x554620);_0x212a1a[_0x478255](_0x2fb030['text'],_0x2fb030[_0x3cc7('0x5e')][_0x3cc7('0x67')],_0x2fb030['value'][_0x3cc7('0x1d')]);}break;case _0x3cc7('0x70'):_0x2fb030=as[_0x3cc7('0x66')]('me',null,_0x554620);_0x212a1a[_0x478255](_0x2fb030[_0x3cc7('0x71')],_0x2fb030['value']['start'],_0x2fb030['value'][_0x3cc7('0x1d')]);break;}}else{var _0x2fb030=as[_0x3cc7('0x66')](_0x1ce589,_0x12b95b[_0x3cc7('0x35')],_0x554620);_0x212a1a[_0x478255](_0x2fb030[_0x3cc7('0x71')],_0x2fb030[_0x3cc7('0x5e')][_0x3cc7('0x67')],_0x2fb030[_0x3cc7('0x5e')]['end']);}}}else{var _0x1be864=_(_0x24409c[_0x3cc7('0x38')])[_0x3cc7('0x72')]()[_0x3cc7('0x29')](function(_0xb12795){return _[_0x3cc7('0x73')](_0x16e66a,[_0x3cc7('0x26'),_0xb12795])?_0xb12795:undefined;})['compact']()[_0x3cc7('0x5e')]();if(!_[_0x3cc7('0x74')](_0x1be864)){_0x1be864['forEach'](function(_0x1b17b4){if(_0x1b17b4==='MailAccountId'){_0x11ff4e[_0x3cc7('0x41')](_0x3cc7('0x75'),[][_0x3cc7('0x76')](_0x24409c['query'][_0x1b17b4]));}else if(_0x1b17b4===_0x3cc7('0x77')){var _0x5f14bb=JSON[_0x3cc7('0x78')](_0x24409c[_0x3cc7('0x38')][_0x1b17b4])['$gte'];var _0x44e908=JSON[_0x3cc7('0x78')](_0x24409c[_0x3cc7('0x38')][_0x1b17b4])['$lte'];_0x11ff4e['where'](_0x3cc7('0x79'),_0x5f14bb,_0x44e908);}else{if(_0x24409c[_0x3cc7('0x38')][_0x1b17b4]==='null'){_0x11ff4e[_0x3cc7('0x41')]('i.'+_0x1b17b4+'\x20IS\x20NULL');}else{_0x11ff4e[_0x3cc7('0x41')]('i.'+_0x1b17b4+_0x3cc7('0x7a'),_0x24409c['query'][_0x1b17b4]);}}});}if(_0x24409c[_0x3cc7('0x38')]['read']){if(_0x24409c[_0x3cc7('0x38')][_0x3cc7('0x7b')]==0x1){_0x11ff4e[_0x3cc7('0x60')](_0x3cc7('0x7c'));}else{_0x11ff4e['having'](_0x3cc7('0x7d'));}}if(_0x24409c[_0x3cc7('0x38')][_0x3cc7('0x7e')]){_0x1aaac9=_[_0x3cc7('0x7f')](_0x24409c[_0x3cc7('0x38')][_0x3cc7('0x7e')])?_0x24409c[_0x3cc7('0x38')][_0x3cc7('0x7e')]:new Array(_0x24409c[_0x3cc7('0x38')][_0x3cc7('0x7e')]);_0x1aaac9['forEach'](function(_0x1f51a7){_0x569774['or'](_0x3cc7('0x6a'),'%,'+_0x1f51a7+',%');});}if(_0x24409c[_0x3cc7('0x38')][_0x3cc7('0x80')]){var _0x7b1e55=_0x24409c[_0x3cc7('0x38')][_0x3cc7('0x80')]['replace']('\x5c','\x5c\x5c')[_0x3cc7('0x81')]('\x27\x27',_0x3cc7('0x82'));if(qs[_0x3cc7('0x83')](_0x7b1e55)){_0x212a1a['or'](_0x3cc7('0x84'),_0x7b1e55+'%');}else if(qs[_0x3cc7('0x85')](_0x7b1e55)){_0x212a1a['or'](_0x3cc7('0x86'),_0x7b1e55+'%');}else{_0x212a1a['or'](_0x3cc7('0x87'),qs[_0x3cc7('0x88')](_0x7b1e55))['or']('MATCH\x20(me.plainBody,\x20me.subject)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs['getFullTextValue'](_0x7b1e55));}}}_0x11ff4e['where'](_0x212a1a);_0x11ff4e['group']('i.id');var _0x256902={'type':db[_0x3cc7('0x89')][_0x3cc7('0x8a')][_0x3cc7('0x8b')],'raw':!![]};var _0x232101=_0x11ff4e[_0x3cc7('0x8c')]();_0x232101[_0x3cc7('0x44')]('i.id');_0x232101[_0x3cc7('0x44')](_0x3cc7('0x8d'),_0x3cc7('0x8e'));if(_0x538cfe[_0x3cc7('0x8f')]){_0x538cfe[_0x3cc7('0x8f')][_0x3cc7('0x69')](function(_0x5cafae){_0x11ff4e[_0x3cc7('0x8f')]('i.'+_0x5cafae[0x0],_0x5cafae[0x1]===_0x3cc7('0x90')?![]:!![]);});}if(!_[_0x3cc7('0x74')](_0x1aaac9)){_0x11ff4e[_0x3cc7('0x60')](_0x569774);_0x232101['where']('t.id\x20IN\x20?',_0x1aaac9);}BPromise[_0x3cc7('0x91')]()[_0x3cc7('0x25')](function(){if(!_0x33e5fd){if(_0x24409c[_0x3cc7('0x38')]['MailAccountId']||_0x24409c[_0x3cc7('0x38')]['journey'])return;_0x232101[_0x3cc7('0x41')](_0x3cc7('0x92'));_0x11ff4e['where'](_0x3cc7('0x92'));return;}return _0x24409c[_0x3cc7('0x93')][_0x3cc7('0x94')]({'attributes':['id'],'raw':!![]})[_0x3cc7('0x25')](function(_0x16d91a){if(_[_0x3cc7('0x74')](_0x16d91a)){_0x232101[_0x3cc7('0x41')](_0x3cc7('0x95'));_0x11ff4e['where'](_0x3cc7('0x95'));}else{_0x232101['where'](_0x3cc7('0x75'),_[_0x3cc7('0x29')](_0x16d91a,'id'));_0x11ff4e[_0x3cc7('0x41')](_0x3cc7('0x75'),_[_0x3cc7('0x29')](_0x16d91a,'id'));}});})[_0x3cc7('0x25')](function(){db['sequelize'][_0x3cc7('0x38')](_0x232101[_0x3cc7('0x96')](),_0x256902)[_0x3cc7('0x25')](function(_0x1d979c){_0x53cc1d['count']=_0x1d979c[_0x3cc7('0x3d')];if(_0x53cc1d[_0x3cc7('0x1f')]===0x0)return[];return db[_0x3cc7('0x97')][_0x3cc7('0x38')](_0x9625d0['toString'](),_0x256902)[_0x3cc7('0x25')](function(_0x1a0d27){_0x447504=_['keyBy'](_0x1a0d27,'id');_0x256902=_[_0x3cc7('0x98')](_0x256902,{'model':db['MailInteraction'],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x24409c[_0x3cc7('0x38')][_0x3cc7('0x3c')]){_0x538cfe['attributes']['forEach'](function(_0x2ab4cf){_0x11ff4e[_0x3cc7('0x44')]('i.'+_0x2ab4cf);});}else{_0x11ff4e[_0x3cc7('0x44')]('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)',_0x3cc7('0x8e'));_0x11ff4e[_0x3cc7('0x44')]('a.key',_0x3cc7('0x99'));_0x11ff4e['field'](_0x3cc7('0x9a'),'Account.mandatoryDisposition');_0x11ff4e['field']('i.id');_0x11ff4e['field']('i.createdAt');_0x11ff4e[_0x3cc7('0x44')](_0x3cc7('0x9b'));_0x11ff4e[_0x3cc7('0x44')](_0x3cc7('0x9c'));_0x11ff4e[_0x3cc7('0x44')](_0x3cc7('0x9d'));_0x11ff4e[_0x3cc7('0x44')](_0x3cc7('0x9e'));_0x11ff4e[_0x3cc7('0x44')](_0x3cc7('0x9f'));_0x11ff4e['field'](_0x3cc7('0xa0'));_0x11ff4e['field'](_0x3cc7('0xa1'));_0x11ff4e['field']('i.disposition');_0x11ff4e[_0x3cc7('0x44')]('i.substatus');_0x11ff4e[_0x3cc7('0x44')](_0x3cc7('0xa2'));_0x11ff4e[_0x3cc7('0x44')](_0x3cc7('0xa3'));_0x11ff4e[_0x3cc7('0x44')](_0x3cc7('0xa4'));_0x11ff4e[_0x3cc7('0x44')]('i.UserId');_0x11ff4e[_0x3cc7('0x44')](_0x3cc7('0xa5'),_0x3cc7('0xa6'));_0x11ff4e[_0x3cc7('0x44')](_0x3cc7('0xa7'),_0x3cc7('0xa8'));_0x11ff4e['field']('c.email',_0x3cc7('0xa9'));_0x11ff4e[_0x3cc7('0x44')](_0x3cc7('0xaa'),_0x3cc7('0xab'));_0x11ff4e[_0x3cc7('0x44')](_0x3cc7('0xac'),_0x3cc7('0xad'));_0x11ff4e['field']('c.fax','Contact.fax');_0x11ff4e[_0x3cc7('0x44')](_0x3cc7('0xae'),_0x3cc7('0xaf'));_0x11ff4e[_0x3cc7('0x44')](_0x3cc7('0xb0'),'Owner.internal');_0x11ff4e[_0x3cc7('0x44')]('GROUP_CONCAT(DISTINCT\x20t.id)',_0x3cc7('0x2b'));}_0x11ff4e[_0x3cc7('0x3f')](_0x538cfe[_0x3cc7('0x3f')]);_0x11ff4e[_0x3cc7('0x20')](_0x538cfe[_0x3cc7('0x20')]);return db[_0x3cc7('0x97')]['query'](_0x11ff4e[_0x3cc7('0x96')](),_0x256902);})[_0x3cc7('0x25')](function(_0x194b06){_0x477278[_0x3cc7('0x41')](_0x3cc7('0xb1'),_[_0x3cc7('0x29')](_0x194b06,'id'));return db[_0x3cc7('0x97')]['query'](_0x477278[_0x3cc7('0x96')](),_0x256902)['then'](function(_0x47c42d){var _0xf6d4c5=_[_0x3cc7('0xb2')](_0x47c42d,_0x3cc7('0xb3'));var _0x3ab25b=[];return db[_0x3cc7('0xb4')][_0x3cc7('0x2f')]({'attributes':[_0x3cc7('0xb5')],'raw':!![]})[_0x3cc7('0x25')](function(_0x137842){var _0x276b1b=_0x137842[_0x3cc7('0xb5')];_0x194b06[_0x3cc7('0x69')](function(_0x156feb){_0x3ab25b['push'](updateMailInteraction(_0x156feb,_0x447504,_0xf6d4c5,_0x276b1b));});return BPromise[_0x3cc7('0xb6')](_0x3ab25b);});});});})[_0x3cc7('0x25')](function(_0x4f8865){_0x53cc1d[_0x3cc7('0xb7')]=_0x4f8865;return _0x53cc1d;})['then'](respondWithFilteredResult(_0x1b0a1f,_0x538cfe));})['catch'](handleError(_0x1b0a1f,null));};exports[_0x3cc7('0xb8')]=function(_0x20bdf6,_0x256c8a){var _0x2b94b2={'raw':![],'where':{'id':_0x20bdf6[_0x3cc7('0xb9')]['id']}},_0x4e5067={};_0x4e5067['model']=_['keys'](db['MailInteraction']['rawAttributes']);_0x4e5067[_0x3cc7('0x38')]=_['keys'](_0x20bdf6[_0x3cc7('0x38')]);_0x4e5067['filters']=_[_0x3cc7('0x3a')](_0x4e5067['model'],_0x4e5067['query']);_0x2b94b2[_0x3cc7('0x3b')]=_[_0x3cc7('0x3a')](_0x4e5067[_0x3cc7('0x37')],qs[_0x3cc7('0x3c')](_0x20bdf6[_0x3cc7('0x38')][_0x3cc7('0x3c')]));_0x2b94b2[_0x3cc7('0x3b')]=_0x2b94b2['attributes'][_0x3cc7('0x3d')]?_0x2b94b2['attributes']:_0x4e5067[_0x3cc7('0x37')];if(_0x20bdf6[_0x3cc7('0x38')][_0x3cc7('0xba')]){_0x2b94b2[_0x3cc7('0xbb')]=[{'all':!![]}];}_0x2b94b2=_[_0x3cc7('0x98')]({},_0x2b94b2,_0x20bdf6[_0x3cc7('0xbc')]);return db[_0x3cc7('0x2e')][_0x3cc7('0x5d')](_0x2b94b2)[_0x3cc7('0x25')](handleEntityNotFound(_0x256c8a,null))['then'](respondWithResult(_0x256c8a,null))[_0x3cc7('0x32')](handleError(_0x256c8a,null));};exports['create']=function(_0x3dd3aa,_0x1683bc){return db[_0x3cc7('0x2e')][_0x3cc7('0xbd')](_0x3dd3aa[_0x3cc7('0xbe')],{})['then'](respondWithResult(_0x1683bc,0xc9))[_0x3cc7('0x32')](handleError(_0x1683bc,null));};exports[_0x3cc7('0x23')]=function(_0x479fe1,_0x2e6d65){if(_0x479fe1[_0x3cc7('0xbe')]['id']){delete _0x479fe1[_0x3cc7('0xbe')]['id'];}return db['MailInteraction'][_0x3cc7('0x5d')]({'where':{'id':_0x479fe1[_0x3cc7('0xb9')]['id']}})[_0x3cc7('0x25')](handleEntityNotFound(_0x2e6d65,null))[_0x3cc7('0x25')](saveUpdates(_0x479fe1[_0x3cc7('0xbe')],null))[_0x3cc7('0x25')](respondWithResult(_0x2e6d65,null))['catch'](handleError(_0x2e6d65,null));};exports['destroy']=function(_0x1db436,_0x581d59){return db[_0x3cc7('0x2e')][_0x3cc7('0x5d')]({'where':{'id':_0x1db436[_0x3cc7('0xb9')]['id']}})['then'](handleEntityNotFound(_0x581d59,null))[_0x3cc7('0x25')](removeEntity(_0x581d59,null))[_0x3cc7('0x32')](handleError(_0x581d59,null));};exports[_0x3cc7('0xbf')]=function(_0x2e945e,_0x2dd8e3){return db[_0x3cc7('0x2e')]['describe']()[_0x3cc7('0x25')](respondWithResult(_0x2dd8e3,null))['catch'](handleError(_0x2dd8e3,null));};exports[_0x3cc7('0xc0')]=function(_0x1aee0c,_0x210986,_0x8b94c1){return db['MailMessage'][_0x3cc7('0x5d')]({'where':{'id':_0x1aee0c[_0x3cc7('0xb9')]['id']}})[_0x3cc7('0x25')](handleEntityNotFound(_0x210986,null))['then'](function(_0x4e84a1){if(_0x4e84a1){return _0x4e84a1['addMessage'](_0x1aee0c[_0x3cc7('0xbe')][_0x3cc7('0xc1')],_['omit'](_0x1aee0c[_0x3cc7('0xbe')],['ids','id'])||{});}})[_0x3cc7('0x25')](respondWithResult(_0x210986,null))['catch'](handleError(_0x210986,null));};exports[_0x3cc7('0xc2')]=function(_0x352a67,_0x33a61d,_0x75ac33){var _0x4e0ce5={'raw':![],'where':{}};var _0x30472c={};var _0x19efca={'count':0x0,'rows':[]};return db['MailInteraction'][_0x3cc7('0x2f')]({'where':{'id':_0x352a67['params']['id']}})[_0x3cc7('0x25')](handleEntityNotFound(_0x33a61d,null))[_0x3cc7('0x25')](function(_0x7ad601){if(_0x7ad601){_0x30472c[_0x3cc7('0x37')]=_[_0x3cc7('0x72')](db[_0x3cc7('0xc3')][_0x3cc7('0x33')]);_0x30472c[_0x3cc7('0x38')]=_[_0x3cc7('0x72')](_0x352a67[_0x3cc7('0x38')]);_0x30472c[_0x3cc7('0x39')]=_[_0x3cc7('0x3a')](_0x30472c['model'],_0x30472c[_0x3cc7('0x38')]);_0x4e0ce5[_0x3cc7('0x3b')]=_[_0x3cc7('0x3a')](_0x30472c[_0x3cc7('0x37')],qs[_0x3cc7('0x3c')](_0x352a67['query'][_0x3cc7('0x3c')]));_0x4e0ce5[_0x3cc7('0x3b')]=_0x4e0ce5['attributes'][_0x3cc7('0x3d')]?_0x4e0ce5['attributes']:_0x30472c['model'];if(!_0x352a67['query'][_0x3cc7('0x3e')]('nolimit')){_0x4e0ce5['limit']=qs[_0x3cc7('0x3f')](_0x352a67[_0x3cc7('0x38')][_0x3cc7('0x3f')]);_0x4e0ce5[_0x3cc7('0x20')]=qs[_0x3cc7('0x20')](_0x352a67['query']['offset']);}_0x4e0ce5['order']=qs[_0x3cc7('0x40')](_0x352a67[_0x3cc7('0x38')]['sort']);_0x4e0ce5[_0x3cc7('0x41')]=qs[_0x3cc7('0x39')](_[_0x3cc7('0x42')](_0x352a67[_0x3cc7('0x38')],_0x30472c['filters']));_0x4e0ce5[_0x3cc7('0x41')][_0x3cc7('0xb3')]=_0x7ad601['id'];if(_0x352a67[_0x3cc7('0x38')][_0x3cc7('0x80')]){_0x4e0ce5['where']=_[_0x3cc7('0x98')](_0x4e0ce5[_0x3cc7('0x41')],{'$or':_[_0x3cc7('0x29')](_0x4e0ce5[_0x3cc7('0x3b')],function(_0x428f41){var _0x30b08b={};_0x30b08b[_0x428f41]={'$like':'%'+_0x352a67['query'][_0x3cc7('0x80')]+'%'};return _0x30b08b;})});}if(_0x352a67[_0x3cc7('0x38')][_0x3cc7('0xc4')]){var _0x29a358=_0x352a67[_0x3cc7('0x38')][_0x3cc7('0xc4')][_0x3cc7('0x62')](',');var _0x1fa4d0={};_0x1fa4d0[_0x29a358[0x0]]={'$gte':moment(_0x29a358[0x1])['format'](_0x3cc7('0xc5'))};_0x4e0ce5['where']=_[_0x3cc7('0x98')](_0x4e0ce5[_0x3cc7('0x41')],_0x1fa4d0);}_0x4e0ce5=_['merge']({},_0x4e0ce5,_0x352a67[_0x3cc7('0xbc')]);return db['MailMessage'][_0x3cc7('0x1f')]({'where':_0x4e0ce5[_0x3cc7('0x41')]})[_0x3cc7('0x25')](function(_0x1038e3){_0x19efca['count']=_0x1038e3;if(_0x352a67[_0x3cc7('0x38')][_0x3cc7('0xba')]){_0x4e0ce5[_0x3cc7('0xbb')]=[{'all':!![]}];}return db['MailMessage'][_0x3cc7('0xc6')](_0x4e0ce5);})[_0x3cc7('0x25')](function(_0x5acfbc){_0x19efca[_0x3cc7('0xb7')]=_0x5acfbc;return _0x19efca;});}})[_0x3cc7('0x25')](respondWithFilteredResult(_0x33a61d,_0x4e0ce5))[_0x3cc7('0x32')](handleError(_0x33a61d,null));};exports['addTags']=function(_0x5e7f32,_0x406d5e,_0x3833f2){return db[_0x3cc7('0x2e')]['find']({'where':{'id':_0x5e7f32[_0x3cc7('0xb9')]['id']}})['then'](handleEntityNotFound(_0x406d5e,null))[_0x3cc7('0x25')](function(_0xd48403){if(_0xd48403){return _0xd48403[_0x3cc7('0xc7')](_0x5e7f32[_0x3cc7('0xbe')][_0x3cc7('0xc1')],_[_0x3cc7('0xc8')](_0x5e7f32[_0x3cc7('0xbe')],[_0x3cc7('0xc1'),'id'])||{})['spread'](function(){return db['Tag']['findAll']({'attributes':['id',_0x3cc7('0x26'),'color'],'where':{'id':_0x5e7f32[_0x3cc7('0xbe')][_0x3cc7('0xc1')]}});})[_0x3cc7('0x25')](function(_0x4fce9e){socket[_0x3cc7('0xc9')](_0x3cc7('0xca'),{'id':Number(_0x5e7f32[_0x3cc7('0xb9')]['id']),'tags':_0x4fce9e||[]});return{'id':Number(_0x5e7f32[_0x3cc7('0xb9')]['id']),'tags':_0x4fce9e||[]};});}})[_0x3cc7('0x25')](respondWithResult(_0x406d5e,null))['catch'](handleError(_0x406d5e,null));};exports[_0x3cc7('0xcb')]=function(_0x289d89,_0x3f1fe9,_0x2ccfd6){return db['MailInteraction'][_0x3cc7('0x5d')]({'where':{'id':_0x289d89[_0x3cc7('0xb9')]['id']}})[_0x3cc7('0x25')](handleEntityNotFound(_0x3f1fe9,null))['then'](function(_0x589e56){if(_0x589e56){return _0x589e56[_0x3cc7('0xcb')](_0x289d89[_0x3cc7('0x38')][_0x3cc7('0xc1')]);}})['then'](respondWithStatusCode(_0x3f1fe9,null))[_0x3cc7('0x32')](handleError(_0x3f1fe9,null));};exports['download']=function(_0x43109b,_0x5b91cb){var _0x3f2780=moment()['unix']()['toString']();var _0xd6c72c=path[_0x3cc7('0xcc')](config['root'],'server',_0x3cc7('0xcd'),_0x3cc7('0xce'));var _0xc7b7a3=path[_0x3cc7('0xcc')](config[_0x3cc7('0xcf')],'server',_0x3cc7('0xcd'),_0x3cc7('0xd0'));var _0x597622=path['join'](_0xd6c72c,_0x3f2780);var _0x133012=util[_0x3cc7('0xd1')]('transcript-%d-%s.zip',_0x43109b[_0x3cc7('0xb9')]['id'],_0x3f2780);var _0x190134=path[_0x3cc7('0xcc')](_0xd6c72c,_0x133012);var _0x44afbe=[];if(_0x43109b[_0x3cc7('0x38')][_0x3cc7('0xd0')]){_0x44afbe[_0x3cc7('0x2d')]({'model':db['Attachment'],'as':_0x3cc7('0xd2'),'raw':!![]});}var _0x509368=[{'model':db[_0x3cc7('0xc3')],'as':_0x3cc7('0xd3'),'attributes':['id','body','from','to','cc',_0x3cc7('0xd4'),_0x3cc7('0xd5'),_0x3cc7('0x77')],'where':{'secret':![]},'order':qs[_0x3cc7('0x40')]('id'),'include':_0x44afbe}];return db['MailInteraction'][_0x3cc7('0x5d')]({'where':{'id':_0x43109b['params']['id']},'include':_0x509368})[_0x3cc7('0x25')](handleEntityNotFound(_0x5b91cb,null))[_0x3cc7('0x25')](function(_0x4a7a98){if(_0x4a7a98&&_0x4a7a98[_0x3cc7('0xd3')]){var _0x1f3fde=_0x4a7a98[_0x3cc7('0xd6')]({'plain':!![]});fs[_0x3cc7('0xd7')](_0x597622);return BPromise[_0x3cc7('0xd8')](_0x1f3fde[_0x3cc7('0xd3')],function(_0x396707,_0x59b30b){var _0x45bc09={'from':_0x396707[_0x3cc7('0x46')],'to':_0x396707['to'],'subject':_0x396707[_0x3cc7('0xd5')],'html':_0x396707[_0x3cc7('0xbe')],'headers':{'Date':moment(_0x396707['createdAt'])[_0x3cc7('0xd1')](_0x3cc7('0xd9'))},'attachments':[]};if(_0x396707['cc']){_0x45bc09['headers']['Cc']=_0x396707['cc'];}if(_0x396707[_0x3cc7('0xd4')]){_0x45bc09[_0x3cc7('0xda')]['Bcc']=_0x396707[_0x3cc7('0xd4')];}return new BPromise(function(_0x493eab,_0x2dfe6d){if(_0x396707['Attachments']){for(var _0x3c5c42=0x0;_0x3c5c42<_0x396707['Attachments'][_0x3cc7('0x3d')];_0x3c5c42++){var _0x46f91a=_0x396707['Attachments'][_0x3c5c42];var _0x3a9027=path[_0x3cc7('0xcc')](_0xc7b7a3,_0x46f91a[_0x3cc7('0xdb')]);if(fs[_0x3cc7('0xdc')](_0x3a9027)){_0x45bc09[_0x3cc7('0xd0')][_0x3cc7('0x2d')]({'name':_0x46f91a['name'],'contentType':_0x46f91a['type'],'data':fs[_0x3cc7('0xdd')](_0x3a9027)});}}}emlformat[_0x3cc7('0xde')](_0x45bc09,function(_0x171cd3,_0x5cf2d9){if(_0x171cd3)return _0x2dfe6d(_0x171cd3);fs[_0x3cc7('0xdf')](path[_0x3cc7('0xcc')](_0x597622,util[_0x3cc7('0xd1')]('message%d.eml',_0x59b30b)),_0x5cf2d9);return _0x493eab(_0x5cf2d9);});});})[_0x3cc7('0x25')](function(){return new BPromise(function(_0x2b0295,_0x2b9fd2){zipdir(_0x597622,{'saveTo':_0x190134},function(_0x12c01f,_0x2aae2a){if(_0x12c01f)return _0x2b9fd2(_0x12c01f);return _0x2b0295(_0x2aae2a);});})[_0x3cc7('0x25')](function(){return new BPromise(function(_0x2e417c,_0x5d2cfd){rimraf(_0x597622,function(_0x362b88){if(_0x362b88)_0x5d2cfd(_0x362b88);return _0x2e417c();});});})[_0x3cc7('0x25')](function(){return _0x5b91cb[_0x3cc7('0xe0')](_0x190134,_0x133012,function(_0x4dbaa4){if(_0x4dbaa4){console[_0x3cc7('0xe1')](_0x3cc7('0xe2'),_0x4dbaa4);}else{fs[_0x3cc7('0xe3')](_0x190134);}});});});}else{return _0x5b91cb['sendStatus'](0xc8);}})[_0x3cc7('0x32')](handleError(_0x5b91cb,null));};
\ No newline at end of file
+var _0xfbaa=['body','destroy','describe','addMessage','ids','omit','getMessages','findOne','MailMessage','hasOwnProperty','sort','where','pick','MailInteractionId','filter','$gte','YYYY-MM-DD\x20HH:mm:ss','rows','addTags','setTags','spread','Tag','color','emit','removeTags','download','unix','toString','join','root','server','files','attachments','push','Attachment','Attachments','Messages','from','bcc','subject','createdAt','get','mkdirSync','each','missing.recipient@your.company.com','decode','format','ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ','headers','Bcc','basename','readFileSync','build','writeFileSync','message%d.eml','unlinkSync','eml-format','rimraf','zip-dir','moment','util','path','juice','../../components/interaction/service','../../components/parsers/qs','../../config/environment','../../mysqldb','html-entities','defaults','redis','localhost','sendStatus','end','status','json','undefined','count','offset','limit','set','Content-Range','update','then','error','stack','name','send','index','map','MailInteraction','rawAttributes','fieldName','type','getOptions','findAll','mail','query','user','params','keys','filters','model','attributes','intersection','fields','length','includeAll','include','merge','options','find','catch','create'];(function(_0x17e05b,_0x66e4e5){var _0x5cc4b6=function(_0x25a799){while(--_0x25a799){_0x17e05b['push'](_0x17e05b['shift']());}};_0x5cc4b6(++_0x66e4e5);}(_0xfbaa,0x18b));var _0xafba=function(_0x2aec52,_0x59d962){_0x2aec52=_0x2aec52-0x0;var _0x3b8835=_0xfbaa[_0x2aec52];return _0x3b8835;};'use strict';var emlformat=require(_0xafba('0x0'));var rimraf=require(_0xafba('0x1'));var zipdir=require(_0xafba('0x2'));var moment=require(_0xafba('0x3'));var BPromise=require('bluebird');var util=require(_0xafba('0x4'));var path=require(_0xafba('0x5'));var fs=require('fs');var _=require('lodash');var juice=require(_0xafba('0x6'));var Redis=require('ioredis');var interaction=require(_0xafba('0x7'));var qs=require(_0xafba('0x8'));var logger=require('../../config/logger')('api');var config=require(_0xafba('0x9'));var db=require(_0xafba('0xa'))['db'];var htmlEntities=require(_0xafba('0xb'));config['redis']=_[_0xafba('0xc')](config[_0xafba('0xd')],{'host':_0xafba('0xe'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xafba('0xd')]));require('./mailInteraction.socket')['register'](socket);function respondWithStatusCode(_0x159d3b,_0x4ea48e){_0x4ea48e=_0x4ea48e||0xcc;return function(_0x51ed2a){if(_0x51ed2a){return _0x159d3b[_0xafba('0xf')](_0x4ea48e);}return _0x159d3b['status'](_0x4ea48e)[_0xafba('0x10')]();};}function respondWithResult(_0x58434c,_0x3bc9f6){_0x3bc9f6=_0x3bc9f6||0xc8;return function(_0x5e1e9e){if(_0x5e1e9e){return _0x58434c[_0xafba('0x11')](_0x3bc9f6)[_0xafba('0x12')](_0x5e1e9e);}};}function respondWithFilteredResult(_0x3d648d,_0x2ee008){return function(_0x2ccfd1){if(_0x2ccfd1){var _0x59ad8e=typeof _0x2ee008['offset']==='undefined'&&typeof _0x2ee008['limit']===_0xafba('0x13');var _0x525c26=_0x2ccfd1[_0xafba('0x14')];var _0x10540d=_0x59ad8e?0x0:_0x2ee008[_0xafba('0x15')];var _0x372596=_0x59ad8e?_0x2ccfd1[_0xafba('0x14')]:_0x2ee008['offset']+_0x2ee008[_0xafba('0x16')];var _0x1c7b34;if(_0x372596>=_0x525c26){_0x372596=_0x525c26;_0x1c7b34=0xc8;}else{_0x1c7b34=0xce;}_0x3d648d[_0xafba('0x11')](_0x1c7b34);return _0x3d648d[_0xafba('0x17')](_0xafba('0x18'),_0x10540d+'-'+_0x372596+'/'+_0x525c26)[_0xafba('0x12')](_0x2ccfd1);}return null;};}function saveUpdates(_0x4533f3){return function(_0x4964bd){if(_0x4964bd){return _0x4964bd[_0xafba('0x19')](_0x4533f3)[_0xafba('0x1a')](function(_0x590994){return _0x590994;});}return null;};}function removeEntity(_0x50304f){return function(_0x4481e0){if(_0x4481e0){return _0x4481e0['destroy']()[_0xafba('0x1a')](function(){_0x50304f[_0xafba('0x11')](0xcc)[_0xafba('0x10')]();});}};}function handleEntityNotFound(_0x4f7669){return function(_0x494b58){if(!_0x494b58){_0x4f7669[_0xafba('0xf')](0x194);}return _0x494b58;};}function handleError(_0x96c974,_0x3bd1bb){_0x3bd1bb=_0x3bd1bb||0x1f4;return function(_0x11fd1e){logger[_0xafba('0x1b')](_0x11fd1e[_0xafba('0x1c')]);if(_0x11fd1e['name']){delete _0x11fd1e[_0xafba('0x1d')];}_0x96c974[_0xafba('0x11')](_0x3bd1bb)[_0xafba('0x1e')](_0x11fd1e);};}exports[_0xafba('0x1f')]=function(_0x304ab8,_0x12783e){var _0x4d4838={};var _0x24c39c=_[_0xafba('0x20')](db[_0xafba('0x21')][_0xafba('0x22')],function(_0x12a492){return{'name':_0x12a492[_0xafba('0x23')],'type':_0x12a492[_0xafba('0x24')]['key']};});_0x4d4838=qs[_0xafba('0x25')](_0x24c39c,_0x304ab8);return interaction[_0xafba('0x26')](_0xafba('0x27'),_0x304ab8[_0xafba('0x28')],_0x304ab8[_0xafba('0x29')],_0x4d4838,_0x24c39c)[_0xafba('0x1a')](respondWithFilteredResult(_0x12783e,_0x4d4838))['catch'](handleError(_0x12783e,null));};exports['show']=function(_0x19012b,_0x2d7e9d){var _0x406296={'raw':![],'where':{'id':_0x19012b[_0xafba('0x2a')]['id']}},_0xd6fe59={};_0xd6fe59['model']=_[_0xafba('0x2b')](db[_0xafba('0x21')][_0xafba('0x22')]);_0xd6fe59['query']=_[_0xafba('0x2b')](_0x19012b[_0xafba('0x28')]);_0xd6fe59[_0xafba('0x2c')]=_['intersection'](_0xd6fe59[_0xafba('0x2d')],_0xd6fe59[_0xafba('0x28')]);_0x406296[_0xafba('0x2e')]=_[_0xafba('0x2f')](_0xd6fe59[_0xafba('0x2d')],qs['fields'](_0x19012b[_0xafba('0x28')][_0xafba('0x30')]));_0x406296[_0xafba('0x2e')]=_0x406296[_0xafba('0x2e')][_0xafba('0x31')]?_0x406296[_0xafba('0x2e')]:_0xd6fe59[_0xafba('0x2d')];if(_0x19012b[_0xafba('0x28')][_0xafba('0x32')]){_0x406296[_0xafba('0x33')]=[{'all':!![]}];}_0x406296=_[_0xafba('0x34')]({},_0x406296,_0x19012b[_0xafba('0x35')]);return db[_0xafba('0x21')][_0xafba('0x36')](_0x406296)[_0xafba('0x1a')](handleEntityNotFound(_0x2d7e9d,null))[_0xafba('0x1a')](respondWithResult(_0x2d7e9d,null))[_0xafba('0x37')](handleError(_0x2d7e9d,null));};exports['create']=function(_0x31ef5c,_0x3dd757){return db[_0xafba('0x21')][_0xafba('0x38')](_0x31ef5c[_0xafba('0x39')],{})['then'](respondWithResult(_0x3dd757,0xc9))[_0xafba('0x37')](handleError(_0x3dd757,null));};exports['update']=function(_0x52ffac,_0xbb48ba){if(_0x52ffac[_0xafba('0x39')]['id']){delete _0x52ffac[_0xafba('0x39')]['id'];}return db['MailInteraction'][_0xafba('0x36')]({'where':{'id':_0x52ffac[_0xafba('0x2a')]['id']}})[_0xafba('0x1a')](handleEntityNotFound(_0xbb48ba,null))[_0xafba('0x1a')](saveUpdates(_0x52ffac['body'],null))[_0xafba('0x1a')](respondWithResult(_0xbb48ba,null))[_0xafba('0x37')](handleError(_0xbb48ba,null));};exports[_0xafba('0x3a')]=function(_0x1ee5b8,_0x8aff40){return db['MailInteraction'][_0xafba('0x36')]({'where':{'id':_0x1ee5b8['params']['id']}})[_0xafba('0x1a')](handleEntityNotFound(_0x8aff40,null))[_0xafba('0x1a')](removeEntity(_0x8aff40,null))[_0xafba('0x37')](handleError(_0x8aff40,null));};exports[_0xafba('0x3b')]=function(_0x3ab1d7,_0x3dcd6a){return db['MailInteraction'][_0xafba('0x3b')]()[_0xafba('0x1a')](respondWithResult(_0x3dcd6a,null))[_0xafba('0x37')](handleError(_0x3dcd6a,null));};exports['addMessage']=function(_0x595be5,_0x3bb4dc){return db['MailMessage']['find']({'where':{'id':_0x595be5[_0xafba('0x2a')]['id']}})[_0xafba('0x1a')](handleEntityNotFound(_0x3bb4dc,null))['then'](function(_0x58ef95){if(_0x58ef95){return _0x58ef95[_0xafba('0x3c')](_0x595be5[_0xafba('0x39')][_0xafba('0x3d')],_[_0xafba('0x3e')](_0x595be5[_0xafba('0x39')],[_0xafba('0x3d'),'id'])||{});}})[_0xafba('0x1a')](respondWithResult(_0x3bb4dc,null))['catch'](handleError(_0x3bb4dc,null));};exports[_0xafba('0x3f')]=function(_0xf615f2,_0x4fe707){var _0x5777e4={'raw':![],'where':{}};var _0x5e4acf={};var _0x1eeef3={'count':0x0,'rows':[]};return db[_0xafba('0x21')][_0xafba('0x40')]({'where':{'id':_0xf615f2[_0xafba('0x2a')]['id']}})[_0xafba('0x1a')](handleEntityNotFound(_0x4fe707,null))[_0xafba('0x1a')](function(_0x1c4e90){if(_0x1c4e90){_0x5e4acf[_0xafba('0x2d')]=_[_0xafba('0x2b')](db[_0xafba('0x41')][_0xafba('0x22')]);_0x5e4acf['query']=_[_0xafba('0x2b')](_0xf615f2[_0xafba('0x28')]);_0x5e4acf[_0xafba('0x2c')]=_['intersection'](_0x5e4acf[_0xafba('0x2d')],_0x5e4acf[_0xafba('0x28')]);_0x5777e4[_0xafba('0x2e')]=_[_0xafba('0x2f')](_0x5e4acf[_0xafba('0x2d')],qs['fields'](_0xf615f2[_0xafba('0x28')]['fields']));_0x5777e4[_0xafba('0x2e')]=_0x5777e4[_0xafba('0x2e')]['length']?_0x5777e4[_0xafba('0x2e')]:_0x5e4acf['model'];if(!_0xf615f2[_0xafba('0x28')][_0xafba('0x42')]('nolimit')){_0x5777e4[_0xafba('0x16')]=qs['limit'](_0xf615f2['query'][_0xafba('0x16')]);_0x5777e4[_0xafba('0x15')]=qs[_0xafba('0x15')](_0xf615f2['query'][_0xafba('0x15')]);}_0x5777e4['order']=qs[_0xafba('0x43')](_0xf615f2[_0xafba('0x28')][_0xafba('0x43')]);_0x5777e4[_0xafba('0x44')]=qs[_0xafba('0x2c')](_[_0xafba('0x45')](_0xf615f2[_0xafba('0x28')],_0x5e4acf[_0xafba('0x2c')]));_0x5777e4['where'][_0xafba('0x46')]=_0x1c4e90['id'];if(_0xf615f2[_0xafba('0x28')][_0xafba('0x47')]){_0x5777e4[_0xafba('0x44')]=_[_0xafba('0x34')](_0x5777e4['where'],{'$or':_[_0xafba('0x20')](_0x5777e4[_0xafba('0x2e')],function(_0x52cc58){var _0xee790b={};_0xee790b[_0x52cc58]={'$like':'%'+_0xf615f2[_0xafba('0x28')]['filter']+'%'};return _0xee790b;})});}if(_0xf615f2[_0xafba('0x28')][_0xafba('0x48')]){var _0x4adfb8=_0xf615f2[_0xafba('0x28')][_0xafba('0x48')]['split'](',');var _0xf7512d={};_0xf7512d[_0x4adfb8[0x0]]={'$gte':moment(_0x4adfb8[0x1])['format'](_0xafba('0x49'))};_0x5777e4[_0xafba('0x44')]=_[_0xafba('0x34')](_0x5777e4[_0xafba('0x44')],_0xf7512d);}_0x5777e4=_['merge']({},_0x5777e4,_0xf615f2[_0xafba('0x35')]);return db[_0xafba('0x41')][_0xafba('0x14')]({'where':_0x5777e4['where']})[_0xafba('0x1a')](function(_0x47dddc){_0x1eeef3[_0xafba('0x14')]=_0x47dddc;if(_0xf615f2[_0xafba('0x28')]['includeAll']){_0x5777e4[_0xafba('0x33')]=[{'all':!![]}];}return db[_0xafba('0x41')][_0xafba('0x26')](_0x5777e4);})[_0xafba('0x1a')](function(_0x31daab){if(_0xf615f2[_0xafba('0x28')]['inlineCss']==='true'){for(var _0xe33761=0x0;_0xe33761<_0x31daab['length'];_0xe33761++){_0x31daab[_0xe33761][_0xafba('0x39')]=juice(_0x31daab[_0xe33761]['body']);}}_0x1eeef3[_0xafba('0x4a')]=_0x31daab;return _0x1eeef3;});}})['then'](respondWithFilteredResult(_0x4fe707,_0x5777e4))[_0xafba('0x37')](handleError(_0x4fe707,null));};exports[_0xafba('0x4b')]=function(_0x372731,_0x339028){return db[_0xafba('0x21')][_0xafba('0x36')]({'where':{'id':_0x372731[_0xafba('0x2a')]['id']}})['then'](handleEntityNotFound(_0x339028,null))[_0xafba('0x1a')](function(_0x25b13b){if(_0x25b13b){return _0x25b13b[_0xafba('0x4c')](_0x372731['body'][_0xafba('0x3d')],_[_0xafba('0x3e')](_0x372731[_0xafba('0x39')],['ids','id'])||{})[_0xafba('0x4d')](function(){return db[_0xafba('0x4e')][_0xafba('0x26')]({'attributes':['id',_0xafba('0x1d'),_0xafba('0x4f')],'where':{'id':_0x372731[_0xafba('0x39')]['ids']}});})[_0xafba('0x1a')](function(_0x3e2d59){socket[_0xafba('0x50')]('mailInteractionTags:save',{'id':Number(_0x372731[_0xafba('0x2a')]['id']),'tags':_0x3e2d59||[]});return{'id':Number(_0x372731[_0xafba('0x2a')]['id']),'tags':_0x3e2d59||[]};});}})[_0xafba('0x1a')](respondWithResult(_0x339028,null))['catch'](handleError(_0x339028,null));};exports[_0xafba('0x51')]=function(_0x3e228e,_0xe48230){return db[_0xafba('0x21')]['find']({'where':{'id':_0x3e228e[_0xafba('0x2a')]['id']}})[_0xafba('0x1a')](handleEntityNotFound(_0xe48230,null))['then'](function(_0x2a4da4){if(_0x2a4da4){return _0x2a4da4[_0xafba('0x51')](_0x3e228e[_0xafba('0x28')][_0xafba('0x3d')]);}})[_0xafba('0x1a')](respondWithStatusCode(_0xe48230,null))[_0xafba('0x37')](handleError(_0xe48230,null));};exports[_0xafba('0x52')]=function(_0x394736,_0x274f66){var _0x18db10=moment()[_0xafba('0x53')]()[_0xafba('0x54')]();var _0x2a60ae=path[_0xafba('0x55')](config[_0xafba('0x56')],_0xafba('0x57'),'files','tmp');var _0x53c1fe=path['join'](config[_0xafba('0x56')],'server',_0xafba('0x58'),_0xafba('0x59'));var _0x4a7d5b=path['join'](_0x2a60ae,_0x18db10);var _0x5cbf70=util['format']('transcript-%d-%s.zip',_0x394736['params']['id'],_0x18db10);var _0x6b2c15=path['join'](_0x2a60ae,_0x5cbf70);var _0x47f2b3=[];if(_0x394736[_0xafba('0x28')][_0xafba('0x59')]){_0x47f2b3[_0xafba('0x5a')]({'model':db[_0xafba('0x5b')],'as':_0xafba('0x5c'),'raw':!![]});}var _0x28faae=[{'model':db[_0xafba('0x41')],'as':_0xafba('0x5d'),'attributes':['id',_0xafba('0x39'),_0xafba('0x5e'),'to','cc',_0xafba('0x5f'),_0xafba('0x60'),_0xafba('0x61')],'where':{'secret':![]},'order':qs['sort']('id'),'include':_0x47f2b3}];return db[_0xafba('0x21')][_0xafba('0x36')]({'where':{'id':_0x394736['params']['id']},'include':_0x28faae})[_0xafba('0x1a')](handleEntityNotFound(_0x274f66,null))[_0xafba('0x1a')](function(_0x1d7df4){if(_0x1d7df4&&_0x1d7df4[_0xafba('0x5d')]){var _0x3b0182=_0x1d7df4[_0xafba('0x62')]({'plain':!![]});fs[_0xafba('0x63')](_0x4a7d5b);return BPromise[_0xafba('0x64')](_0x3b0182[_0xafba('0x5d')],function(_0x19c009,_0x4bee00){var _0x559106={'from':_0x19c009[_0xafba('0x5e')],'to':_0x19c009['to']||_0xafba('0x65'),'subject':_0x19c009[_0xafba('0x60')],'html':htmlEntities[_0xafba('0x66')](_0x19c009[_0xafba('0x39')]),'headers':{'Date':moment(_0x19c009[_0xafba('0x61')])[_0xafba('0x67')](_0xafba('0x68'))},'attachments':[]};if(_0x19c009['cc']){_0x559106['headers']['Cc']=_0x19c009['cc'];}if(_0x19c009['bcc']){_0x559106[_0xafba('0x69')][_0xafba('0x6a')]=_0x19c009[_0xafba('0x5f')];}return new BPromise(function(_0x386948,_0x4e6e75){if(_0x19c009['Attachments']){for(var _0x4559b3=0x0;_0x4559b3<_0x19c009[_0xafba('0x5c')]['length'];_0x4559b3++){var _0x485ab4=_0x19c009[_0xafba('0x5c')][_0x4559b3];var _0x5d5a66=path[_0xafba('0x55')](_0x53c1fe,_0x485ab4[_0xafba('0x6b')]);if(fs['existsSync'](_0x5d5a66)){_0x559106[_0xafba('0x59')][_0xafba('0x5a')]({'name':_0x485ab4[_0xafba('0x1d')],'contentType':_0x485ab4['type'],'data':fs[_0xafba('0x6c')](_0x5d5a66)});}}}emlformat[_0xafba('0x6d')](_0x559106,function(_0x1f977d,_0x260e15){if(_0x1f977d)return _0x4e6e75(_0x1f977d);fs[_0xafba('0x6e')](path[_0xafba('0x55')](_0x4a7d5b,util[_0xafba('0x67')](_0xafba('0x6f'),_0x4bee00)),_0x260e15);return _0x386948(_0x260e15);});});})[_0xafba('0x1a')](function(){return new BPromise(function(_0x192f49,_0x4946ff){zipdir(_0x4a7d5b,{'saveTo':_0x6b2c15},function(_0x452e40,_0x524cdb){if(_0x452e40)return _0x4946ff(_0x452e40);return _0x192f49(_0x524cdb);});})[_0xafba('0x1a')](function(){return new BPromise(function(_0x4670ba,_0x22c756){rimraf(_0x4a7d5b,function(_0xbcbd17){if(_0xbcbd17)_0x22c756(_0xbcbd17);return _0x4670ba();});});})[_0xafba('0x1a')](function(){return _0x274f66['download'](_0x6b2c15,_0x5cbf70,function(_0x526802){if(!_0x526802)fs[_0xafba('0x70')](_0x6b2c15);});});});}else{return _0x274f66[_0xafba('0xf')](0xc8);}})[_0xafba('0x37')](handleError(_0x274f66,null));};
\ No newline at end of file