Built motion from commit 092f8824.|2.5.49
[motion2.git] / server / api / mailMessage / mailMessage.controller.js
index 041dbf5..b79a3ba 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x3e74=['join','root','server/files/attachments','basename','CmContact','ListId','List\x20not\x20found','SendMail','sendMail','messageId','format','YYYY-MM-DD\x20HH:mm:ss','accept','mail','read','readAt','UserId','get','MailInteraction','MailInteractionId','read1stAt','interaction','null','AcceptMessage','acceptMessage','ContactId','sequelize','Sequelize','QueryTypes','SELECT','User','agent','fullname','email','internal','manual','interface','channel','fromString','EventManager','acceptmessage','reject','[MAILMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','rejectMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','contact','SIP/%s','event','download','tmp','files','message-%s.eml','subject','createdAt','Attachments','from','ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ','headers','Bcc','bcc','push','readFileSync','build','unlinkSync','eml-format','bluebird','util','path','html-to-text','../../config/logger','api','mail-interactions','../../config/environment','redis','defaults','localhost','socket.io-emitter','./mailMessage.socket','client','http','then','info','debug','MailMessage,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','code','error','MailMessage,\x20%s,\x20%s','message','result','catch','status','json','offset','undefined','count','Content-Range','destroy','end','sendStatus','stack','name','send','MailMessage','rawAttributes','fieldName','type','key','intersection','query','attributes','model','fields','hasOwnProperty','nolimit','limit','sort','where','filters','pick','filter','merge','options','findAll','keys','length','include','find','update','body','params','describe','create','out','secret','MailAccount','findOne','CmList','Contacts','updatedAt','DESC','MailServerOut','Smtp','isNil','service','port','secure','authentication','auth','pass','user','attachments'];(function(_0x2a4591,_0xf1b4de){var _0x2914bf=function(_0x401bd8){while(--_0x401bd8){_0x2a4591['push'](_0x2a4591['shift']());}};_0x2914bf(++_0xf1b4de);}(_0x3e74,0x175));var _0x43e7=function(_0xaced30,_0x4d8e66){_0xaced30=_0xaced30-0x0;var _0x1ebb4e=_0x3e74[_0xaced30];return _0x1ebb4e;};'use strict';var emlformat=require(_0x43e7('0x0'));var moment=require('moment');var BPromise=require(_0x43e7('0x1'));var util=require(_0x43e7('0x2'));var path=require(_0x43e7('0x3'));var fs=require('fs');var _=require('lodash');var Redis=require('ioredis');var htmlToText=require(_0x43e7('0x4'));var qs=require('../../components/parsers/qs');var logger=require(_0x43e7('0x5'))(_0x43e7('0x6'));var interaction_log=require(_0x43e7('0x5'))(_0x43e7('0x7'));var config=require(_0x43e7('0x8'));var db=require('../../mysqldb')['db'];config[_0x43e7('0x9')]=_[_0x43e7('0xa')](config[_0x43e7('0x9')],{'host':_0x43e7('0xb'),'port':0x18eb});var socket=require(_0x43e7('0xc'))(new Redis(config['redis']));require(_0x43e7('0xd'))['register'](socket);var jayson=require('jayson/promise');var client=jayson[_0x43e7('0xe')][_0x43e7('0xf')]({'port':0x232c});var client9003=jayson['client'][_0x43e7('0xf')]({'port':0x232b});var client9002=jayson['client'][_0x43e7('0xf')]({'port':0x232a});function respondWithRpcPromise(_0x37302c,_0x4ebc8e,_0x3eb206,_0xc960ea){return new BPromise(function(_0x2718d3,_0x3bb83f){var _0x4e008c=_0xc960ea||client;return _0x4e008c['request'](_0x37302c,_0x3eb206)[_0x43e7('0x10')](function(_0x21fdd3){logger[_0x43e7('0x11')]('MailMessage,\x20%s,\x20%s',_0x4ebc8e,'request\x20sent');logger[_0x43e7('0x12')](_0x43e7('0x13'),_0x4ebc8e,_0x43e7('0x14'),JSON[_0x43e7('0x15')](_0x21fdd3));if(_0x21fdd3['error']){if(_0x21fdd3['error'][_0x43e7('0x16')]===0x1f4){logger[_0x43e7('0x17')](_0x43e7('0x18'),_0x4ebc8e,_0x21fdd3['error']['message']);return _0x3bb83f(_0x21fdd3[_0x43e7('0x17')][_0x43e7('0x19')]);}logger[_0x43e7('0x17')](_0x43e7('0x18'),_0x4ebc8e,_0x21fdd3[_0x43e7('0x17')][_0x43e7('0x19')]);return _0x2718d3(_0x21fdd3[_0x43e7('0x17')][_0x43e7('0x19')]);}else{logger[_0x43e7('0x11')](_0x43e7('0x18'),_0x4ebc8e,_0x43e7('0x14'));_0x2718d3(_0x21fdd3[_0x43e7('0x1a')]['message']);}})[_0x43e7('0x1b')](function(_0x3c6625){logger['error'](_0x43e7('0x18'),_0x4ebc8e,_0x3c6625);_0x3bb83f(_0x3c6625);});});}function respondWithResult(_0x3e281e,_0x3945bb){_0x3945bb=_0x3945bb||0xc8;return function(_0x28aacc){if(_0x28aacc){return _0x3e281e[_0x43e7('0x1c')](_0x3945bb)[_0x43e7('0x1d')](_0x28aacc);}};}function respondWithFilteredResult(_0x54a9e7,_0x454359){return function(_0x4eea52){if(_0x4eea52){var _0x4c9df3=typeof _0x454359[_0x43e7('0x1e')]===_0x43e7('0x1f')&&typeof _0x454359['limit']===_0x43e7('0x1f');var _0x4ca5cf=_0x4eea52[_0x43e7('0x20')];var _0x5c5e67=_0x4c9df3?0x0:_0x454359[_0x43e7('0x1e')];var _0x1b5f50=_0x4c9df3?_0x4eea52[_0x43e7('0x20')]:_0x454359[_0x43e7('0x1e')]+_0x454359['limit'];var _0x52b7b3;if(_0x1b5f50>=_0x4ca5cf){_0x1b5f50=_0x4ca5cf;_0x52b7b3=0xc8;}else{_0x52b7b3=0xce;}_0x54a9e7[_0x43e7('0x1c')](_0x52b7b3);return _0x54a9e7['set'](_0x43e7('0x21'),_0x5c5e67+'-'+_0x1b5f50+'/'+_0x4ca5cf)[_0x43e7('0x1d')](_0x4eea52);}return null;};}function saveUpdates(_0x3565cf){return function(_0xb1fc63){if(_0xb1fc63){return _0xb1fc63['update'](_0x3565cf)[_0x43e7('0x10')](function(_0x4690a6){return _0x4690a6;});}return null;};}function removeEntity(_0x45b675){return function(_0x50f9f5){if(_0x50f9f5){return _0x50f9f5[_0x43e7('0x22')]()[_0x43e7('0x10')](function(){_0x45b675[_0x43e7('0x1c')](0xcc)[_0x43e7('0x23')]();});}};}function handleEntityNotFound(_0x3bf475){return function(_0x35dbcd){if(!_0x35dbcd){_0x3bf475[_0x43e7('0x24')](0x194);}return _0x35dbcd;};}function handleError(_0x19725a,_0x2bde44){_0x2bde44=_0x2bde44||0x1f4;return function(_0x208706){logger['error'](_0x208706[_0x43e7('0x25')]);if(_0x208706[_0x43e7('0x26')]){delete _0x208706[_0x43e7('0x26')];}_0x19725a[_0x43e7('0x1c')](_0x2bde44)[_0x43e7('0x27')](_0x208706);};}exports['index']=function(_0x1eba65,_0x49b83d){var _0x30d47e={},_0x3f280d={},_0x4c61b9={'count':0x0,'rows':[]};var _0x5a7342=_['map'](db[_0x43e7('0x28')][_0x43e7('0x29')],function(_0x117c07){return{'name':_0x117c07[_0x43e7('0x2a')],'type':_0x117c07[_0x43e7('0x2b')][_0x43e7('0x2c')]};});_0x3f280d['model']=_['map'](_0x5a7342,'name');_0x3f280d['query']=_['keys'](_0x1eba65['query']);_0x3f280d['filters']=_[_0x43e7('0x2d')](_0x3f280d['model'],_0x3f280d[_0x43e7('0x2e')]);_0x30d47e[_0x43e7('0x2f')]=_[_0x43e7('0x2d')](_0x3f280d[_0x43e7('0x30')],qs[_0x43e7('0x31')](_0x1eba65[_0x43e7('0x2e')][_0x43e7('0x31')]));_0x30d47e['attributes']=_0x30d47e['attributes']['length']?_0x30d47e[_0x43e7('0x2f')]:_0x3f280d[_0x43e7('0x30')];if(!_0x1eba65[_0x43e7('0x2e')][_0x43e7('0x32')](_0x43e7('0x33'))){_0x30d47e[_0x43e7('0x34')]=qs[_0x43e7('0x34')](_0x1eba65[_0x43e7('0x2e')]['limit']);_0x30d47e[_0x43e7('0x1e')]=qs[_0x43e7('0x1e')](_0x1eba65['query'][_0x43e7('0x1e')]);}_0x30d47e['order']=qs[_0x43e7('0x35')](_0x1eba65[_0x43e7('0x2e')][_0x43e7('0x35')]);_0x30d47e[_0x43e7('0x36')]=qs[_0x43e7('0x37')](_[_0x43e7('0x38')](_0x1eba65['query'],_0x3f280d['filters']),_0x5a7342);if(_0x1eba65[_0x43e7('0x2e')][_0x43e7('0x39')]){_0x30d47e[_0x43e7('0x36')]=_[_0x43e7('0x3a')](_0x30d47e[_0x43e7('0x36')],{'$or':_['map'](_0x5a7342,function(_0x32a451){if(_0x32a451[_0x43e7('0x2b')]!=='VIRTUAL'){var _0x3628e0={};_0x3628e0[_0x32a451['name']]={'$like':'%'+_0x1eba65[_0x43e7('0x2e')]['filter']+'%'};return _0x3628e0;}})});}_0x30d47e=_[_0x43e7('0x3a')]({},_0x30d47e,_0x1eba65[_0x43e7('0x3b')]);var _0x3a5807={'where':_0x30d47e[_0x43e7('0x36')]};return db['MailMessage']['count'](_0x3a5807)[_0x43e7('0x10')](function(_0x40c509){_0x4c61b9[_0x43e7('0x20')]=_0x40c509;if(_0x1eba65[_0x43e7('0x2e')]['includeAll']){_0x30d47e['include']=[{'all':!![]}];}return db['MailMessage'][_0x43e7('0x3c')](_0x30d47e);})['then'](function(_0x2ab022){_0x4c61b9['rows']=_0x2ab022;return _0x4c61b9;})['then'](respondWithFilteredResult(_0x49b83d,_0x30d47e))[_0x43e7('0x1b')](handleError(_0x49b83d,null));};exports['show']=function(_0x2de14f,_0x39db7f){var _0x257bd8={'raw':!![],'where':{'id':_0x2de14f['params']['id']}},_0x99b9e1={};_0x99b9e1[_0x43e7('0x30')]=_[_0x43e7('0x3d')](db[_0x43e7('0x28')][_0x43e7('0x29')]);_0x99b9e1[_0x43e7('0x2e')]=_[_0x43e7('0x3d')](_0x2de14f['query']);_0x99b9e1['filters']=_[_0x43e7('0x2d')](_0x99b9e1[_0x43e7('0x30')],_0x99b9e1[_0x43e7('0x2e')]);_0x257bd8['attributes']=_['intersection'](_0x99b9e1['model'],qs[_0x43e7('0x31')](_0x2de14f[_0x43e7('0x2e')]['fields']));_0x257bd8[_0x43e7('0x2f')]=_0x257bd8[_0x43e7('0x2f')][_0x43e7('0x3e')]?_0x257bd8['attributes']:_0x99b9e1['model'];if(_0x2de14f['query']['includeAll']){_0x257bd8[_0x43e7('0x3f')]=[{'all':!![]}];}_0x257bd8=_[_0x43e7('0x3a')]({},_0x257bd8,_0x2de14f['options']);return db[_0x43e7('0x28')][_0x43e7('0x40')](_0x257bd8)[_0x43e7('0x10')](handleEntityNotFound(_0x39db7f,null))[_0x43e7('0x10')](respondWithResult(_0x39db7f,null))['catch'](handleError(_0x39db7f,null));};exports[_0x43e7('0x41')]=function(_0x483f20,_0x4bebd4){if(_0x483f20[_0x43e7('0x42')]['id']){delete _0x483f20[_0x43e7('0x42')]['id'];}return db[_0x43e7('0x28')][_0x43e7('0x40')]({'where':{'id':_0x483f20[_0x43e7('0x43')]['id']}})[_0x43e7('0x10')](handleEntityNotFound(_0x4bebd4,null))[_0x43e7('0x10')](saveUpdates(_0x483f20[_0x43e7('0x42')],null))[_0x43e7('0x10')](respondWithResult(_0x4bebd4,null))[_0x43e7('0x1b')](handleError(_0x4bebd4,null));};exports['destroy']=function(_0x119d34,_0x46c910){return db['MailMessage'][_0x43e7('0x40')]({'where':{'id':_0x119d34['params']['id']}})[_0x43e7('0x10')](handleEntityNotFound(_0x46c910,null))[_0x43e7('0x10')](removeEntity(_0x46c910,null))[_0x43e7('0x1b')](handleError(_0x46c910,null));};exports[_0x43e7('0x44')]=function(_0xfe13fa,_0x5e5556){return db['MailMessage'][_0x43e7('0x44')]()[_0x43e7('0x10')](respondWithResult(_0x5e5556,null))[_0x43e7('0x1b')](handleError(_0x5e5556,null));};exports[_0x43e7('0x45')]=function(_0x23d835,_0x25bb44){return db[_0x43e7('0x28')][_0x43e7('0x45')](_0x23d835[_0x43e7('0x42')])[_0x43e7('0x10')](function(_0x312306){if(_0x312306){if(_0x312306['direction']===_0x43e7('0x46')&&!_0x312306[_0x43e7('0x47')]){var _0x50a3fa,_0x4314d8,_0x220bf2;if(_0x23d835[_0x43e7('0x42')]['to']){_0x4314d8=_0x23d835['body']['to']['split'](',')[0x0];}return db[_0x43e7('0x48')][_0x43e7('0x49')]({'where':{'id':_0x312306['MailAccountId']},'include':[{'model':db[_0x43e7('0x4a')],'as':'List','include':[{'model':db['CmContact'],'as':_0x43e7('0x4b'),'where':{'email':_0x4314d8},'limit':0x1,'order':[[_0x43e7('0x4c'),_0x43e7('0x4d')]]}]},{'model':db[_0x43e7('0x4e')],'as':_0x43e7('0x4f'),'raw':!![]}]})['then'](function(_0xc3976){_0x50a3fa=_0xc3976;if(_0x50a3fa&&_0x50a3fa[_0x43e7('0x4f')]){var _0x4d89bd={'tls':{'rejectUnauthorized':![]}};if(_[_0x43e7('0x50')](_0x50a3fa[_0x43e7('0x4f')][_0x43e7('0x51')])){_0x4d89bd['host']=_0x50a3fa['Smtp']['host'];_0x4d89bd[_0x43e7('0x52')]=_0x50a3fa[_0x43e7('0x4f')][_0x43e7('0x52')];_0x4d89bd[_0x43e7('0x53')]=_0x50a3fa['Smtp']['secure'];if(_0x50a3fa[_0x43e7('0x4f')][_0x43e7('0x54')]){_0x4d89bd[_0x43e7('0x55')]={'user':_0x50a3fa[_0x43e7('0x4f')]['user'],'pass':_0x50a3fa[_0x43e7('0x4f')][_0x43e7('0x56')]};}}else{_0x4d89bd[_0x43e7('0x51')]=_0x50a3fa[_0x43e7('0x4f')][_0x43e7('0x51')];_0x4d89bd[_0x43e7('0x55')]={'user':_0x50a3fa[_0x43e7('0x4f')][_0x43e7('0x57')],'pass':_0x50a3fa[_0x43e7('0x4f')][_0x43e7('0x56')]};_0x4d89bd[_0x43e7('0x53')]=_0x50a3fa['Smtp']['secure'];}if(_0x23d835[_0x43e7('0x42')]['attachments']&&_0x23d835['body']['attachments'][_0x43e7('0x3e')]){for(var _0xe666b0=0x0;_0xe666b0<_0x23d835['body'][_0x43e7('0x58')][_0x43e7('0x3e')];_0xe666b0+=0x1){_0x23d835[_0x43e7('0x42')]['attachments'][_0xe666b0]={'filename':_0x23d835[_0x43e7('0x42')][_0x43e7('0x58')][_0xe666b0][_0x43e7('0x26')],'path':path[_0x43e7('0x59')](config[_0x43e7('0x5a')],_0x43e7('0x5b'),_0x23d835[_0x43e7('0x42')]['attachments'][_0xe666b0][_0x43e7('0x5c')])};}}_0x220bf2={'account':_0x4d89bd,'message':_0x23d835[_0x43e7('0x42')]};return;}})[_0x43e7('0x10')](function(){if(_0x50a3fa['List']){if(_0x50a3fa['List'][_0x43e7('0x4b')]['length']){return _0x50a3fa['List'][_0x43e7('0x4b')][0x0];}else{return db[_0x43e7('0x5d')]['create'](_[_0x43e7('0xa')](_0x23d835[_0x43e7('0x42')],{'firstName':_0x23d835[_0x43e7('0x42')]['to'],'email':_0x23d835[_0x43e7('0x42')]['to'],'phone':_0x23d835[_0x43e7('0x42')]['to'],'ListId':_0x50a3fa[_0x43e7('0x5e')]}));}}else{throw new Error(_0x43e7('0x5f'));}})['then'](function(){if(_0x220bf2){return respondWithRpcPromise(_0x43e7('0x60'),_0x43e7('0x61'),_0x220bf2,client9003)['then'](function(_0x418213){return _0x312306['update']({'read':!![],'messageId':_0x418213[_0x43e7('0x62')],'sentAt':moment()[_0x43e7('0x63')](_0x43e7('0x64'))});})[_0x43e7('0x1b')](function(_0x506361){logger[_0x43e7('0x17')]('%s',JSON[_0x43e7('0x15')](_0x506361));return _0x312306;});}return _0x312306;});}return _0x312306;}})[_0x43e7('0x10')](respondWithResult(_0x25bb44,0xc9))['catch'](handleError(_0x25bb44,null));};exports[_0x43e7('0x65')]=function(_0x38fa5b,_0x219dc6){var _0x703a30={'agent':{},'channel':_0x43e7('0x66')};if(_0x38fa5b['body']['id']){delete _0x38fa5b[_0x43e7('0x42')]['id'];}_0x38fa5b[_0x43e7('0x42')][_0x43e7('0x67')]=!![];_0x38fa5b[_0x43e7('0x42')][_0x43e7('0x68')]=moment()[_0x43e7('0x63')](_0x43e7('0x64'));_0x38fa5b['body']['UserId']=_0x38fa5b[_0x43e7('0x42')]['UserId']||_0x38fa5b['user']['id'];_0x703a30['agent']['id']=_0x38fa5b[_0x43e7('0x42')][_0x43e7('0x69')];return db[_0x43e7('0x28')][_0x43e7('0x40')]({'where':{'id':_0x38fa5b[_0x43e7('0x43')]['id'],'UserId':null}})[_0x43e7('0x10')](handleEntityNotFound(_0x219dc6,null))['then'](saveUpdates(_0x38fa5b[_0x43e7('0x42')],null))[_0x43e7('0x10')](function(_0x2cd420){if(_0x2cd420){_0x703a30['message']=_0x2cd420[_0x43e7('0x6a')]({'plain':!![]});return db[_0x43e7('0x6b')][_0x43e7('0x40')]({'where':{'id':_0x2cd420[_0x43e7('0x6c')]}});}return null;})[_0x43e7('0x10')](handleEntityNotFound(_0x219dc6,null))[_0x43e7('0x10')](function(_0x1d4a29){if(_0x1d4a29){return _0x1d4a29[_0x43e7('0x41')]({'UserId':_0x38fa5b['body']['UserId'],'read1stAt':_['isNil'](_0x1d4a29[_0x43e7('0x6d')])?moment()[_0x43e7('0x63')]('YYYY-MM-DD\x20HH:mm:ss'):undefined});}return null;})[_0x43e7('0x10')](function(_0x39a787){if(_0x39a787){_0x703a30[_0x43e7('0x6e')]=_0x39a787[_0x43e7('0x6a')]({'plain':!![]});interaction_log['info']('[MAILMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x38fa5b['user']['id'],_0x38fa5b[_0x43e7('0x57')][_0x43e7('0x26')],_0x38fa5b['user']['role'],_0x703a30[_0x43e7('0x6e')]['id'],_0x38fa5b[_0x43e7('0x42')]?JSON[_0x43e7('0x15')](_0x38fa5b['body']):_0x43e7('0x6f'));return respondWithRpcPromise(_0x43e7('0x70'),_0x43e7('0x71'),_0x703a30);}return null;})[_0x43e7('0x10')](function(_0x48f1dc){var _0x1d7048='SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20'+_0x48f1dc[_0x43e7('0x19')][_0x43e7('0x72')];return db[_0x43e7('0x73')][_0x43e7('0x2e')](_0x1d7048,{'type':db[_0x43e7('0x74')][_0x43e7('0x75')][_0x43e7('0x76')],'raw':!![]})['then'](function(_0x109c86){return _0x109c86;});})[_0x43e7('0x10')](function(_0x1aea4e){if(_0x1aea4e){_0x703a30[_0x43e7('0x19')]['contact']=_0x1aea4e[0x0];if(!_0x38fa5b['body']['UserId'])return;return db[_0x43e7('0x77')]['find']({'where':{'id':_0x38fa5b[_0x43e7('0x42')][_0x43e7('0x69')],'role':_0x43e7('0x78')},'attributes':['id',_0x43e7('0x26'),_0x43e7('0x79'),_0x43e7('0x7a'),_0x43e7('0x7b')],'raw':!![]});}return null;})[_0x43e7('0x10')](function(_0x363af5){if(!_0x363af5)return null;_0x703a30[_0x43e7('0x19')][_0x43e7('0x78')]=_0x363af5;return _0x703a30;})['then'](function(_0xeaef5c){if(_0xeaef5c){if(_0x38fa5b[_0x43e7('0x42')][_0x43e7('0x7c')]){_0x703a30[_0x43e7('0x19')][_0x43e7('0x7d')]=util['format']('SIP/%s',_0x38fa5b[_0x43e7('0x57')][_0x43e7('0x26')]);_0x703a30['message'][_0x43e7('0x7e')]=_0x703a30[_0x43e7('0x7e')];_0x703a30['message']['event']=_0x43e7('0x65');_0x703a30[_0x43e7('0x19')][_0x43e7('0x42')]=htmlToText[_0x43e7('0x7f')](_0x703a30[_0x43e7('0x19')]['body']);return respondWithRpcPromise('EventManager',_0x43e7('0x80'),{'event':_0x43e7('0x81'),'message':_0x703a30[_0x43e7('0x19')]},client9002)[_0x43e7('0x10')](function(){return _0x703a30;});}return _0x703a30;}return null;})['then'](respondWithResult(_0x219dc6,null))[_0x43e7('0x1b')](handleError(_0x219dc6,null));};exports[_0x43e7('0x82')]=function(_0x1ed590,_0x15ee83){var _0x5bc060={'agent':{},'channel':_0x43e7('0x66')};if(_0x1ed590[_0x43e7('0x42')]['id']){delete _0x1ed590[_0x43e7('0x42')]['id'];}_0x1ed590[_0x43e7('0x42')][_0x43e7('0x69')]=_0x1ed590['body'][_0x43e7('0x69')]||_0x1ed590[_0x43e7('0x57')]['id'];_0x5bc060['agent']['id']=_0x1ed590[_0x43e7('0x42')][_0x43e7('0x69')];return db[_0x43e7('0x28')][_0x43e7('0x40')]({'where':{'id':_0x1ed590['params']['id'],'UserId':null}})[_0x43e7('0x10')](handleEntityNotFound(_0x15ee83,null))['then'](function(_0x130b41){if(_0x130b41){_0x5bc060[_0x43e7('0x19')]=_0x130b41[_0x43e7('0x6a')]({'plain':!![]});return db[_0x43e7('0x6b')][_0x43e7('0x40')]({'where':{'id':_0x130b41[_0x43e7('0x6c')]}});}return null;})[_0x43e7('0x10')](handleEntityNotFound(_0x15ee83,null))[_0x43e7('0x10')](function(_0xa693a3){if(_0xa693a3){_0x5bc060['interaction']=_0xa693a3[_0x43e7('0x6a')]({'plain':!![]});interaction_log[_0x43e7('0x11')](_0x43e7('0x83'),_0x1ed590[_0x43e7('0x57')]['id'],_0x1ed590['user']['name'],_0x1ed590[_0x43e7('0x57')][_0x43e7('0x84')],_0x5bc060[_0x43e7('0x6e')]['id'],_0x1ed590['body']?JSON[_0x43e7('0x15')](_0x1ed590['body']):'null');return respondWithRpcPromise('RejectMessage',_0x43e7('0x85'),_0x5bc060);}return null;})['then'](function(_0x28f15e){var _0x233819=_0x43e7('0x86')+_0x28f15e[_0x43e7('0x19')][_0x43e7('0x72')];return db['sequelize']['query'](_0x233819,{'type':db[_0x43e7('0x74')][_0x43e7('0x75')]['SELECT'],'raw':!![]})[_0x43e7('0x10')](function(_0x10fd28){return _0x10fd28;});})[_0x43e7('0x10')](function(_0x3310ef){if(_0x3310ef){_0x5bc060[_0x43e7('0x19')][_0x43e7('0x87')]=_0x3310ef[0x0];if(!_0x1ed590[_0x43e7('0x42')][_0x43e7('0x69')])return;return db[_0x43e7('0x77')][_0x43e7('0x40')]({'where':{'id':_0x1ed590[_0x43e7('0x42')][_0x43e7('0x69')],'role':_0x43e7('0x78')},'attributes':['id',_0x43e7('0x26'),_0x43e7('0x79'),_0x43e7('0x7a'),_0x43e7('0x7b')],'raw':!![]});}return null;})[_0x43e7('0x10')](function(_0xec3d2a){if(!_0xec3d2a)return null;_0x5bc060[_0x43e7('0x19')][_0x43e7('0x78')]=_0xec3d2a;return _0x5bc060;})[_0x43e7('0x10')](function(_0x492c2f){if(_0x492c2f){_0x492c2f[_0x43e7('0x19')][_0x43e7('0x7d')]=util[_0x43e7('0x63')](_0x43e7('0x88'),_0x1ed590['user'][_0x43e7('0x26')]);_0x492c2f['message'][_0x43e7('0x7e')]=_0x5bc060[_0x43e7('0x7e')];_0x492c2f[_0x43e7('0x19')][_0x43e7('0x89')]=_0x43e7('0x82');_0x492c2f[_0x43e7('0x19')]['body']=htmlToText[_0x43e7('0x7f')](_0x5bc060[_0x43e7('0x19')][_0x43e7('0x42')]);respondWithRpcPromise(_0x43e7('0x80'),_0x43e7('0x80'),{'event':'rejectmessage','message':_0x492c2f['message']},client9002);return _0x5bc060;}return null;})[_0x43e7('0x10')](respondWithResult(_0x15ee83,null))['catch'](handleError(_0x15ee83,null));};exports[_0x43e7('0x8a')]=function(_0x45aef7,_0x35e743){var _0x29ef54=moment()['unix']()['toString']();var _0x52ddb7=path[_0x43e7('0x59')](config['root'],'server','files',_0x43e7('0x8b'));var _0x1e6ddb=path['join'](config[_0x43e7('0x5a')],'server',_0x43e7('0x8c'),_0x43e7('0x58'));var _0x271f55=util[_0x43e7('0x63')](_0x43e7('0x8d'),_0x29ef54);return db['MailMessage'][_0x43e7('0x40')]({'where':{'id':_0x45aef7[_0x43e7('0x43')]['id']},'attributes':['id',_0x43e7('0x42'),'from','to','cc','bcc',_0x43e7('0x8e'),_0x43e7('0x8f')],'include':_0x45aef7[_0x43e7('0x2e')][_0x43e7('0x58')]?[{'model':db['Attachment'],'as':_0x43e7('0x90')}]:undefined})[_0x43e7('0x10')](handleEntityNotFound(_0x35e743,null))[_0x43e7('0x10')](function(_0x56150e){if(_0x56150e){var _0x41a222=_0x56150e;var _0x2c410e={'from':_0x41a222[_0x43e7('0x91')],'to':_0x41a222['to'],'subject':_0x41a222[_0x43e7('0x8e')],'html':_0x41a222['body'],'headers':{'Date':moment(_0x41a222[_0x43e7('0x8f')])['format'](_0x43e7('0x92'))},'attachments':[]};if(_0x56150e['cc']){_0x2c410e[_0x43e7('0x93')]['Cc']=_0x56150e['cc'];}if(_0x56150e['bcc']){_0x2c410e['headers'][_0x43e7('0x94')]=_0x56150e[_0x43e7('0x95')];}return new BPromise(function(_0x21d001,_0x4600e5){if(_0x56150e[_0x43e7('0x90')]){for(var _0x28986d=0x0;_0x28986d<_0x56150e[_0x43e7('0x90')][_0x43e7('0x3e')];_0x28986d++){var _0x1bff0a=_0x56150e[_0x43e7('0x90')][_0x28986d];var _0x615c=path['join'](_0x1e6ddb,_0x1bff0a[_0x43e7('0x5c')]);if(fs['existsSync'](_0x615c)){_0x2c410e[_0x43e7('0x58')][_0x43e7('0x96')]({'name':_0x1bff0a[_0x43e7('0x26')],'contentType':_0x1bff0a['type'],'data':fs[_0x43e7('0x97')](_0x615c)});}}}emlformat[_0x43e7('0x98')](_0x2c410e,function(_0x119cd2,_0x352405){if(_0x119cd2)return _0x4600e5(_0x119cd2);fs['writeFileSync'](path[_0x43e7('0x59')](_0x52ddb7,_0x271f55),_0x352405);return _0x21d001(_0x352405);});});}})[_0x43e7('0x10')](function(_0x524dc2){if(_0x524dc2){return _0x35e743['download'](path['join'](_0x52ddb7,_0x271f55),_0x271f55,function(_0x124024){if(!_0x124024)fs[_0x43e7('0x99')](path[_0x43e7('0x59')](_0x52ddb7,_0x271f55));});}})[_0x43e7('0x1b')](handleError(_0x35e743,null));};
\ No newline at end of file
+var _0xd068=['type','VIRTUAL','options','includeAll','include','params','keys','find','describe','create','body','direction','out','secret','MailAccount','findOne','MailAccountId','Contacts','updatedAt','DESC','MailServerOut','Smtp','CloudProvider','getSmtpOptions','attachments','join','root','server/files/attachments','basename','List','CmContact','defaults','ListId','List\x20not\x20found','SendMail','sendMail','messageId','format','accept','read','UserId','user','get','MailInteractionId','read1stAt','YYYY-MM-DD\x20HH:mm:ss','interaction','[MAILMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','AcceptMessage','acceptMessage','sequelize','Sequelize','contact','User','fullname','email','internal','agent','manual','interface','SIP/%s','channel','motionChannel','fromString','EventManager','acceptmessage','reject','mail','MailInteraction','[MAILMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','null','RejectMessage','rejectMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','ContactId','SELECT','event','rejectmessage','toString','server','files','tmp','message-%s.eml','from','createdAt','Attachment','decode','ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ','headers','bcc','Attachments','existsSync','push','build','writeFileSync','eml-format','moment','bluebird','util','path','lodash','ioredis','html-to-text','../../components/parsers/qs','../../config/logger','mail-interactions','../../config/environment','redis','localhost','socket.io-emitter','./mailMessage.socket','register','jayson/promise','client','http','info','MailMessage,\x20%s,\x20%s','request\x20sent','MailMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','status','json','count','offset','set','Content-Range','update','then','destroy','end','sendStatus','name','send','map','MailMessage','rawAttributes','fieldName','model','query','filters','intersection','attributes','fields','length','nolimit','limit','order','sort','where','pick','filter','merge'];(function(_0x28e178,_0x2f91a3){var _0x1abf49=function(_0xc4a41c){while(--_0xc4a41c){_0x28e178['push'](_0x28e178['shift']());}};_0x1abf49(++_0x2f91a3);}(_0xd068,0x19c));var _0x8d06=function(_0x175792,_0x4d8d4c){_0x175792=_0x175792-0x0;var _0x453af5=_0xd068[_0x175792];return _0x453af5;};'use strict';var emlformat=require(_0x8d06('0x0'));var moment=require(_0x8d06('0x1'));var BPromise=require(_0x8d06('0x2'));var util=require(_0x8d06('0x3'));var path=require(_0x8d06('0x4'));var fs=require('fs');var _=require(_0x8d06('0x5'));var Redis=require(_0x8d06('0x6'));var htmlToText=require(_0x8d06('0x7'));var qs=require(_0x8d06('0x8'));var logger=require('../../config/logger')('api');var interaction_log=require(_0x8d06('0x9'))(_0x8d06('0xa'));var config=require(_0x8d06('0xb'));var db=require('../../mysqldb')['db'];config['redis']=_['defaults'](config[_0x8d06('0xc')],{'host':_0x8d06('0xd'),'port':0x18eb});var socket=require(_0x8d06('0xe'))(new Redis(config['redis']));var htmlEntities=require('html-entities');require(_0x8d06('0xf'))[_0x8d06('0x10')](socket);var jayson=require(_0x8d06('0x11'));var client=jayson[_0x8d06('0x12')]['http']({'port':0x232c});var client9003=jayson[_0x8d06('0x12')]['http']({'port':0x232b});var client9002=jayson[_0x8d06('0x12')][_0x8d06('0x13')]({'port':0x232a});function respondWithRpcPromise(_0x23c9ea,_0x47ef49,_0x325e7e,_0x256e74){return new BPromise(function(_0x125686,_0x479e3f){var _0x1bb995=_0x256e74||client;return _0x1bb995['request'](_0x23c9ea,_0x325e7e)['then'](function(_0x288f1d){logger[_0x8d06('0x14')](_0x8d06('0x15'),_0x47ef49,_0x8d06('0x16'));logger['debug'](_0x8d06('0x17'),_0x47ef49,_0x8d06('0x16'),JSON[_0x8d06('0x18')](_0x288f1d));if(_0x288f1d[_0x8d06('0x19')]){if(_0x288f1d[_0x8d06('0x19')][_0x8d06('0x1a')]===0x1f4){logger[_0x8d06('0x19')](_0x8d06('0x15'),_0x47ef49,_0x288f1d[_0x8d06('0x19')][_0x8d06('0x1b')]);return _0x479e3f(_0x288f1d[_0x8d06('0x19')]['message']);}logger[_0x8d06('0x19')](_0x8d06('0x15'),_0x47ef49,_0x288f1d[_0x8d06('0x19')][_0x8d06('0x1b')]);return _0x125686(_0x288f1d[_0x8d06('0x19')][_0x8d06('0x1b')]);}else{logger['info'](_0x8d06('0x15'),_0x47ef49,_0x8d06('0x16'));_0x125686(_0x288f1d[_0x8d06('0x1c')]['message']);}})[_0x8d06('0x1d')](function(_0x3a1c47){logger[_0x8d06('0x19')](_0x8d06('0x15'),_0x47ef49,_0x3a1c47);_0x479e3f(_0x3a1c47);});});}function respondWithResult(_0x24d6b7,_0x54e39d){_0x54e39d=_0x54e39d||0xc8;return function(_0xc40561){if(_0xc40561){return _0x24d6b7[_0x8d06('0x1e')](_0x54e39d)[_0x8d06('0x1f')](_0xc40561);}};}function respondWithFilteredResult(_0xb4640e,_0x1cb70b){return function(_0x2cc92d){if(_0x2cc92d){var _0x19a938=typeof _0x1cb70b['offset']==='undefined'&&typeof _0x1cb70b['limit']==='undefined';var _0x4cc56e=_0x2cc92d[_0x8d06('0x20')];var _0x536a92=_0x19a938?0x0:_0x1cb70b[_0x8d06('0x21')];var _0x1ffd07=_0x19a938?_0x2cc92d['count']:_0x1cb70b[_0x8d06('0x21')]+_0x1cb70b['limit'];var _0x23e17e;if(_0x1ffd07>=_0x4cc56e){_0x1ffd07=_0x4cc56e;_0x23e17e=0xc8;}else{_0x23e17e=0xce;}_0xb4640e[_0x8d06('0x1e')](_0x23e17e);return _0xb4640e[_0x8d06('0x22')](_0x8d06('0x23'),_0x536a92+'-'+_0x1ffd07+'/'+_0x4cc56e)['json'](_0x2cc92d);}return null;};}function saveUpdates(_0x226d38){return function(_0x525d3f){if(_0x525d3f){return _0x525d3f[_0x8d06('0x24')](_0x226d38)[_0x8d06('0x25')](function(_0x312b56){return _0x312b56;});}return null;};}function removeEntity(_0x5b6d56){return function(_0x369b7f){if(_0x369b7f){return _0x369b7f[_0x8d06('0x26')]()[_0x8d06('0x25')](function(){_0x5b6d56[_0x8d06('0x1e')](0xcc)[_0x8d06('0x27')]();});}};}function handleEntityNotFound(_0x56f568){return function(_0x2f4142){if(!_0x2f4142){_0x56f568[_0x8d06('0x28')](0x194);}return _0x2f4142;};}function handleError(_0x7acb11,_0x366bdb){_0x366bdb=_0x366bdb||0x1f4;return function(_0x5e1067){logger[_0x8d06('0x19')](_0x5e1067['stack']);if(_0x5e1067[_0x8d06('0x29')]){delete _0x5e1067['name'];}_0x7acb11['status'](_0x366bdb)[_0x8d06('0x2a')](_0x5e1067);};}exports['index']=function(_0xf4aa38,_0xfb304d){var _0x263b02={},_0x37f971={},_0xc1d315={'count':0x0,'rows':[]};var _0x1b7609=_[_0x8d06('0x2b')](db[_0x8d06('0x2c')][_0x8d06('0x2d')],function(_0x25f6ac){return{'name':_0x25f6ac[_0x8d06('0x2e')],'type':_0x25f6ac['type']['key']};});_0x37f971[_0x8d06('0x2f')]=_[_0x8d06('0x2b')](_0x1b7609,'name');_0x37f971[_0x8d06('0x30')]=_['keys'](_0xf4aa38['query']);_0x37f971[_0x8d06('0x31')]=_[_0x8d06('0x32')](_0x37f971[_0x8d06('0x2f')],_0x37f971[_0x8d06('0x30')]);_0x263b02[_0x8d06('0x33')]=_['intersection'](_0x37f971[_0x8d06('0x2f')],qs[_0x8d06('0x34')](_0xf4aa38[_0x8d06('0x30')][_0x8d06('0x34')]));_0x263b02[_0x8d06('0x33')]=_0x263b02[_0x8d06('0x33')][_0x8d06('0x35')]?_0x263b02[_0x8d06('0x33')]:_0x37f971[_0x8d06('0x2f')];if(!_0xf4aa38[_0x8d06('0x30')]['hasOwnProperty'](_0x8d06('0x36'))){_0x263b02[_0x8d06('0x37')]=qs[_0x8d06('0x37')](_0xf4aa38[_0x8d06('0x30')][_0x8d06('0x37')]);_0x263b02[_0x8d06('0x21')]=qs[_0x8d06('0x21')](_0xf4aa38['query'][_0x8d06('0x21')]);}_0x263b02[_0x8d06('0x38')]=qs[_0x8d06('0x39')](_0xf4aa38[_0x8d06('0x30')]['sort']);_0x263b02[_0x8d06('0x3a')]=qs[_0x8d06('0x31')](_[_0x8d06('0x3b')](_0xf4aa38[_0x8d06('0x30')],_0x37f971[_0x8d06('0x31')]),_0x1b7609);if(_0xf4aa38[_0x8d06('0x30')][_0x8d06('0x3c')]){_0x263b02['where']=_[_0x8d06('0x3d')](_0x263b02[_0x8d06('0x3a')],{'$or':_[_0x8d06('0x2b')](_0x1b7609,function(_0x55afd2){if(_0x55afd2[_0x8d06('0x3e')]!==_0x8d06('0x3f')){var _0x93aba3={};_0x93aba3[_0x55afd2['name']]={'$like':'%'+_0xf4aa38['query'][_0x8d06('0x3c')]+'%'};return _0x93aba3;}})});}_0x263b02=_[_0x8d06('0x3d')]({},_0x263b02,_0xf4aa38[_0x8d06('0x40')]);var _0x4e9890={'where':_0x263b02['where']};return db[_0x8d06('0x2c')][_0x8d06('0x20')](_0x4e9890)[_0x8d06('0x25')](function(_0xa86468){_0xc1d315[_0x8d06('0x20')]=_0xa86468;if(_0xf4aa38[_0x8d06('0x30')][_0x8d06('0x41')]){_0x263b02[_0x8d06('0x42')]=[{'all':!![]}];}return db[_0x8d06('0x2c')]['findAll'](_0x263b02);})[_0x8d06('0x25')](function(_0x58321f){_0xc1d315['rows']=_0x58321f;return _0xc1d315;})[_0x8d06('0x25')](respondWithFilteredResult(_0xfb304d,_0x263b02))[_0x8d06('0x1d')](handleError(_0xfb304d,null));};exports['show']=function(_0x395205,_0x2c1f67){var _0x7abde8={'raw':!![],'where':{'id':_0x395205[_0x8d06('0x43')]['id']}},_0xd6c70a={};_0xd6c70a[_0x8d06('0x2f')]=_[_0x8d06('0x44')](db[_0x8d06('0x2c')][_0x8d06('0x2d')]);_0xd6c70a[_0x8d06('0x30')]=_[_0x8d06('0x44')](_0x395205[_0x8d06('0x30')]);_0xd6c70a[_0x8d06('0x31')]=_['intersection'](_0xd6c70a[_0x8d06('0x2f')],_0xd6c70a[_0x8d06('0x30')]);_0x7abde8[_0x8d06('0x33')]=_[_0x8d06('0x32')](_0xd6c70a[_0x8d06('0x2f')],qs[_0x8d06('0x34')](_0x395205['query'][_0x8d06('0x34')]));_0x7abde8[_0x8d06('0x33')]=_0x7abde8[_0x8d06('0x33')][_0x8d06('0x35')]?_0x7abde8[_0x8d06('0x33')]:_0xd6c70a[_0x8d06('0x2f')];if(_0x395205[_0x8d06('0x30')][_0x8d06('0x41')]){_0x7abde8['include']=[{'all':!![]}];}_0x7abde8=_[_0x8d06('0x3d')]({},_0x7abde8,_0x395205[_0x8d06('0x40')]);return db[_0x8d06('0x2c')][_0x8d06('0x45')](_0x7abde8)[_0x8d06('0x25')](handleEntityNotFound(_0x2c1f67,null))[_0x8d06('0x25')](respondWithResult(_0x2c1f67,null))[_0x8d06('0x1d')](handleError(_0x2c1f67,null));};exports['update']=function(_0x24a18a,_0x3d307b){if(_0x24a18a['body']['id']){delete _0x24a18a['body']['id'];}return db[_0x8d06('0x2c')][_0x8d06('0x45')]({'where':{'id':_0x24a18a[_0x8d06('0x43')]['id']}})['then'](handleEntityNotFound(_0x3d307b,null))[_0x8d06('0x25')](saveUpdates(_0x24a18a['body'],null))['then'](respondWithResult(_0x3d307b,null))['catch'](handleError(_0x3d307b,null));};exports[_0x8d06('0x26')]=function(_0x5074ee,_0x3e9424){return db[_0x8d06('0x2c')][_0x8d06('0x45')]({'where':{'id':_0x5074ee[_0x8d06('0x43')]['id']}})[_0x8d06('0x25')](handleEntityNotFound(_0x3e9424,null))['then'](removeEntity(_0x3e9424,null))[_0x8d06('0x1d')](handleError(_0x3e9424,null));};exports['describe']=function(_0x3c0609,_0xc8faab){return db[_0x8d06('0x2c')][_0x8d06('0x46')]()[_0x8d06('0x25')](respondWithResult(_0xc8faab,null))[_0x8d06('0x1d')](handleError(_0xc8faab,null));};exports['create']=function(_0x14885f,_0x40d266){return db[_0x8d06('0x2c')][_0x8d06('0x47')](_0x14885f[_0x8d06('0x48')])[_0x8d06('0x25')](function(_0x42f612){if(_0x42f612){if(_0x42f612[_0x8d06('0x49')]===_0x8d06('0x4a')&&!_0x42f612[_0x8d06('0x4b')]){var _0x273d23,_0x24abda,_0x59fdf8;if(_0x14885f[_0x8d06('0x48')]['to']){_0x24abda=_0x14885f[_0x8d06('0x48')]['to']['split'](',')[0x0];}return db[_0x8d06('0x4c')][_0x8d06('0x4d')]({'where':{'id':_0x42f612[_0x8d06('0x4e')]},'include':[{'model':db['CmList'],'as':'List','include':[{'model':db['CmContact'],'as':_0x8d06('0x4f'),'where':{'email':_0x24abda},'limit':0x1,'order':[[_0x8d06('0x50'),_0x8d06('0x51')]]}]},{'model':db[_0x8d06('0x52')],'as':_0x8d06('0x53'),'raw':!![],'include':[{'model':db[_0x8d06('0x54')],'as':_0x8d06('0x54'),'raw':!![]}]}]})[_0x8d06('0x25')](function(_0x2232be){_0x273d23=_0x2232be;if(!_0x273d23||!_0x273d23[_0x8d06('0x53')])return;var _0x482986=_0x273d23[_0x8d06('0x55')]();if(_0x14885f[_0x8d06('0x48')][_0x8d06('0x56')]&&_0x14885f[_0x8d06('0x48')]['attachments'][_0x8d06('0x35')]){for(var _0x5199b7=0x0;_0x5199b7<_0x14885f[_0x8d06('0x48')]['attachments'][_0x8d06('0x35')];_0x5199b7+=0x1){_0x14885f[_0x8d06('0x48')]['attachments'][_0x5199b7]={'filename':_0x14885f['body'][_0x8d06('0x56')][_0x5199b7][_0x8d06('0x29')],'path':path[_0x8d06('0x57')](config[_0x8d06('0x58')],_0x8d06('0x59'),_0x14885f[_0x8d06('0x48')]['attachments'][_0x5199b7][_0x8d06('0x5a')])};}}_0x59fdf8={'account':_0x482986,'message':_0x14885f[_0x8d06('0x48')]};return;})[_0x8d06('0x25')](function(){if(_0x273d23[_0x8d06('0x5b')]){if(_0x273d23[_0x8d06('0x5b')][_0x8d06('0x4f')][_0x8d06('0x35')]){return _0x273d23[_0x8d06('0x5b')][_0x8d06('0x4f')][0x0];}else{return db[_0x8d06('0x5c')][_0x8d06('0x47')](_[_0x8d06('0x5d')](_0x14885f[_0x8d06('0x48')],{'firstName':_0x14885f['body']['to'],'email':_0x14885f[_0x8d06('0x48')]['to'],'phone':_0x14885f[_0x8d06('0x48')]['to'],'ListId':_0x273d23[_0x8d06('0x5e')]}));}}else{throw new Error(_0x8d06('0x5f'));}})[_0x8d06('0x25')](function(){if(_0x59fdf8){return respondWithRpcPromise(_0x8d06('0x60'),_0x8d06('0x61'),_0x59fdf8,client9003)[_0x8d06('0x25')](function(_0x1e9938){return _0x42f612['update']({'read':!![],'messageId':_0x1e9938[_0x8d06('0x62')],'sentAt':moment()[_0x8d06('0x63')]('YYYY-MM-DD\x20HH:mm:ss')});})[_0x8d06('0x1d')](function(_0x111e85){logger['error']('%s',JSON[_0x8d06('0x18')](_0x111e85));return _0x42f612;});}return _0x42f612;});}return _0x42f612;}})[_0x8d06('0x25')](respondWithResult(_0x40d266,0xc9))[_0x8d06('0x1d')](handleError(_0x40d266,null));};exports[_0x8d06('0x64')]=function(_0x43ebc7,_0x5624bb){var _0x4d6a29={'agent':{},'channel':'mail'};if(_0x43ebc7['body']['id']){delete _0x43ebc7['body']['id'];}_0x43ebc7[_0x8d06('0x48')][_0x8d06('0x65')]=!![];_0x43ebc7[_0x8d06('0x48')]['readAt']=moment()[_0x8d06('0x63')]('YYYY-MM-DD\x20HH:mm:ss');_0x43ebc7[_0x8d06('0x48')][_0x8d06('0x66')]=_0x43ebc7[_0x8d06('0x48')]['UserId']||_0x43ebc7[_0x8d06('0x67')]['id'];_0x4d6a29['agent']['id']=_0x43ebc7[_0x8d06('0x48')]['UserId'];return db[_0x8d06('0x2c')][_0x8d06('0x45')]({'where':{'id':_0x43ebc7['params']['id'],'UserId':null}})[_0x8d06('0x25')](handleEntityNotFound(_0x5624bb,null))[_0x8d06('0x25')](saveUpdates(_0x43ebc7[_0x8d06('0x48')],null))[_0x8d06('0x25')](function(_0x342a9b){if(_0x342a9b){_0x4d6a29['message']=_0x342a9b[_0x8d06('0x68')]({'plain':!![]});return db['MailInteraction']['find']({'where':{'id':_0x342a9b[_0x8d06('0x69')]}});}return null;})['then'](handleEntityNotFound(_0x5624bb,null))[_0x8d06('0x25')](function(_0x3c112e){if(_0x3c112e){return _0x3c112e[_0x8d06('0x24')]({'UserId':_0x43ebc7[_0x8d06('0x48')][_0x8d06('0x66')],'read1stAt':_['isNil'](_0x3c112e[_0x8d06('0x6a')])?moment()[_0x8d06('0x63')](_0x8d06('0x6b')):undefined});}return null;})['then'](function(_0x4e4d97){if(_0x4e4d97){_0x4d6a29[_0x8d06('0x6c')]=_0x4e4d97[_0x8d06('0x68')]({'plain':!![]});interaction_log['info'](_0x8d06('0x6d'),_0x43ebc7[_0x8d06('0x67')]['id'],_0x43ebc7[_0x8d06('0x67')][_0x8d06('0x29')],_0x43ebc7[_0x8d06('0x67')][_0x8d06('0x6e')],_0x4d6a29[_0x8d06('0x6c')]['id'],_0x43ebc7[_0x8d06('0x48')]?JSON['stringify'](_0x43ebc7[_0x8d06('0x48')]):'null');return respondWithRpcPromise(_0x8d06('0x6f'),_0x8d06('0x70'),_0x4d6a29);}return null;})[_0x8d06('0x25')](function(_0x3feaad){var _0x344e84='SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20'+_0x3feaad[_0x8d06('0x1b')]['ContactId'];return db[_0x8d06('0x71')][_0x8d06('0x30')](_0x344e84,{'type':db[_0x8d06('0x72')]['QueryTypes']['SELECT'],'raw':!![]})[_0x8d06('0x25')](function(_0x407bfa){return _0x407bfa;});})['then'](function(_0x2b6a94){if(_0x2b6a94){_0x4d6a29[_0x8d06('0x1b')][_0x8d06('0x73')]=_0x2b6a94[0x0];if(!_0x43ebc7['body'][_0x8d06('0x66')])return;return db[_0x8d06('0x74')][_0x8d06('0x45')]({'where':{'id':_0x43ebc7['body']['UserId'],'role':'agent'},'attributes':['id','name',_0x8d06('0x75'),_0x8d06('0x76'),_0x8d06('0x77')],'raw':!![]});}return null;})['then'](function(_0x552efb){if(!_0x552efb)return null;_0x4d6a29[_0x8d06('0x1b')][_0x8d06('0x78')]=_0x552efb;return _0x4d6a29;})['then'](function(_0x17d605){if(_0x17d605){if(_0x43ebc7['body'][_0x8d06('0x79')]){_0x4d6a29[_0x8d06('0x1b')][_0x8d06('0x7a')]=util[_0x8d06('0x63')](_0x8d06('0x7b'),_0x43ebc7['user']['name']);_0x4d6a29[_0x8d06('0x1b')][_0x8d06('0x7c')]=_0x4d6a29[_0x8d06('0x7c')];_0x4d6a29[_0x8d06('0x1b')][_0x8d06('0x7d')]=_0x4d6a29[_0x8d06('0x7c')];_0x4d6a29[_0x8d06('0x1b')]['event']=_0x8d06('0x64');_0x4d6a29[_0x8d06('0x1b')][_0x8d06('0x48')]=htmlToText[_0x8d06('0x7e')](_0x4d6a29[_0x8d06('0x1b')][_0x8d06('0x48')]);return respondWithRpcPromise(_0x8d06('0x7f'),_0x8d06('0x7f'),{'event':_0x8d06('0x80'),'message':_0x4d6a29[_0x8d06('0x1b')]},client9002)['then'](function(){return _0x4d6a29;});}return _0x4d6a29;}return null;})[_0x8d06('0x25')](respondWithResult(_0x5624bb,null))[_0x8d06('0x1d')](handleError(_0x5624bb,null));};exports[_0x8d06('0x81')]=function(_0x27238a,_0x4d9dd5){var _0xc0b839={'agent':{},'channel':_0x8d06('0x82')};if(_0x27238a['body']['id']){delete _0x27238a[_0x8d06('0x48')]['id'];}_0x27238a[_0x8d06('0x48')][_0x8d06('0x66')]=_0x27238a['body'][_0x8d06('0x66')]||_0x27238a[_0x8d06('0x67')]['id'];_0xc0b839[_0x8d06('0x78')]['id']=_0x27238a[_0x8d06('0x48')]['UserId'];return db[_0x8d06('0x2c')][_0x8d06('0x45')]({'where':{'id':_0x27238a['params']['id'],'UserId':null}})['then'](handleEntityNotFound(_0x4d9dd5,null))['then'](function(_0x29e98c){if(_0x29e98c){_0xc0b839[_0x8d06('0x1b')]=_0x29e98c['get']({'plain':!![]});return db[_0x8d06('0x83')][_0x8d06('0x45')]({'where':{'id':_0x29e98c['MailInteractionId']}});}return null;})[_0x8d06('0x25')](handleEntityNotFound(_0x4d9dd5,null))['then'](function(_0x5b2e43){if(_0x5b2e43){_0xc0b839[_0x8d06('0x6c')]=_0x5b2e43[_0x8d06('0x68')]({'plain':!![]});interaction_log[_0x8d06('0x14')](_0x8d06('0x84'),_0x27238a[_0x8d06('0x67')]['id'],_0x27238a[_0x8d06('0x67')][_0x8d06('0x29')],_0x27238a[_0x8d06('0x67')][_0x8d06('0x6e')],_0xc0b839[_0x8d06('0x6c')]['id'],_0x27238a[_0x8d06('0x48')]?JSON[_0x8d06('0x18')](_0x27238a[_0x8d06('0x48')]):_0x8d06('0x85'));return respondWithRpcPromise(_0x8d06('0x86'),_0x8d06('0x87'),_0xc0b839);}return null;})['then'](function(_0x2b0a9b){var _0x2eac10=_0x8d06('0x88')+_0x2b0a9b[_0x8d06('0x1b')][_0x8d06('0x89')];return db[_0x8d06('0x71')][_0x8d06('0x30')](_0x2eac10,{'type':db[_0x8d06('0x72')]['QueryTypes'][_0x8d06('0x8a')],'raw':!![]})[_0x8d06('0x25')](function(_0x42702f){return _0x42702f;});})[_0x8d06('0x25')](function(_0x4dea38){if(_0x4dea38){_0xc0b839[_0x8d06('0x1b')][_0x8d06('0x73')]=_0x4dea38[0x0];if(!_0x27238a['body'][_0x8d06('0x66')])return;return db['User'][_0x8d06('0x45')]({'where':{'id':_0x27238a['body']['UserId'],'role':_0x8d06('0x78')},'attributes':['id',_0x8d06('0x29'),_0x8d06('0x75'),'email','internal'],'raw':!![]});}return null;})[_0x8d06('0x25')](function(_0xaac528){if(!_0xaac528)return null;_0xc0b839[_0x8d06('0x1b')]['agent']=_0xaac528;return _0xc0b839;})[_0x8d06('0x25')](function(_0x3054f3){if(_0x3054f3){_0x3054f3[_0x8d06('0x1b')]['interface']=util[_0x8d06('0x63')](_0x8d06('0x7b'),_0x27238a[_0x8d06('0x67')]['name']);_0x3054f3['message']['channel']=_0xc0b839[_0x8d06('0x7c')];_0x3054f3[_0x8d06('0x1b')][_0x8d06('0x7d')]=_0xc0b839[_0x8d06('0x7c')];_0x3054f3[_0x8d06('0x1b')][_0x8d06('0x8b')]=_0x8d06('0x81');_0x3054f3[_0x8d06('0x1b')][_0x8d06('0x48')]=htmlToText[_0x8d06('0x7e')](_0xc0b839[_0x8d06('0x1b')][_0x8d06('0x48')]);respondWithRpcPromise('EventManager',_0x8d06('0x7f'),{'event':_0x8d06('0x8c'),'message':_0x3054f3[_0x8d06('0x1b')]},client9002);return _0xc0b839;}return null;})['then'](respondWithResult(_0x4d9dd5,null))['catch'](handleError(_0x4d9dd5,null));};exports['download']=function(_0x470143,_0x400291){var _0x77162b=moment()['unix']()[_0x8d06('0x8d')]();var _0x1f9c66=path[_0x8d06('0x57')](config[_0x8d06('0x58')],_0x8d06('0x8e'),_0x8d06('0x8f'),_0x8d06('0x90'));var _0x52e2df=path[_0x8d06('0x57')](config[_0x8d06('0x58')],_0x8d06('0x8e'),_0x8d06('0x8f'),_0x8d06('0x56'));var _0x24e42d=util[_0x8d06('0x63')](_0x8d06('0x91'),_0x77162b);return db[_0x8d06('0x2c')]['find']({'where':{'id':_0x470143['params']['id']},'attributes':['id',_0x8d06('0x48'),_0x8d06('0x92'),'to','cc','bcc','subject',_0x8d06('0x93')],'include':_0x470143[_0x8d06('0x30')][_0x8d06('0x56')]?[{'model':db[_0x8d06('0x94')],'as':'Attachments'}]:undefined})[_0x8d06('0x25')](handleEntityNotFound(_0x400291,null))[_0x8d06('0x25')](function(_0x5f30c5){if(_0x5f30c5){var _0x54b5ef=_0x5f30c5;var _0x40963f={'from':_0x54b5ef[_0x8d06('0x92')],'to':_0x54b5ef['to'],'subject':_0x54b5ef['subject'],'html':htmlEntities[_0x8d06('0x95')](_0x54b5ef[_0x8d06('0x48')]),'headers':{'Date':moment(_0x54b5ef[_0x8d06('0x93')])['format'](_0x8d06('0x96'))},'attachments':[]};if(_0x5f30c5['cc']){_0x40963f[_0x8d06('0x97')]['Cc']=_0x5f30c5['cc'];}if(_0x5f30c5[_0x8d06('0x98')]){_0x40963f[_0x8d06('0x97')]['Bcc']=_0x5f30c5[_0x8d06('0x98')];}return new BPromise(function(_0x2b163c,_0x3836d5){if(_0x5f30c5['Attachments']){for(var _0xbe4f81=0x0;_0xbe4f81<_0x5f30c5['Attachments']['length'];_0xbe4f81++){var _0x5a885a=_0x5f30c5[_0x8d06('0x99')][_0xbe4f81];var _0x33c3fb=path[_0x8d06('0x57')](_0x52e2df,_0x5a885a[_0x8d06('0x5a')]);if(fs[_0x8d06('0x9a')](_0x33c3fb)){_0x40963f[_0x8d06('0x56')][_0x8d06('0x9b')]({'name':_0x5a885a[_0x8d06('0x29')],'contentType':_0x5a885a[_0x8d06('0x3e')],'data':fs['readFileSync'](_0x33c3fb)});}}}emlformat[_0x8d06('0x9c')](_0x40963f,function(_0x4ce0fc,_0x3a7795){if(_0x4ce0fc)return _0x3836d5(_0x4ce0fc);fs[_0x8d06('0x9d')](path[_0x8d06('0x57')](_0x1f9c66,_0x24e42d),_0x3a7795);return _0x2b163c(_0x3a7795);});});}})['then'](function(_0x2539cd){if(_0x2539cd){return _0x400291['download'](path[_0x8d06('0x57')](_0x1f9c66,_0x24e42d),_0x24e42d,function(_0x3d711b){if(!_0x3d711b)fs['unlinkSync'](path[_0x8d06('0x57')](_0x1f9c66,_0x24e42d));});}})[_0x8d06('0x1d')](handleError(_0x400291,null));};
\ No newline at end of file