Built motion from commit e0fa946e.|2.6.5
[motion2.git] / server / api / mailMessage / mailMessage.controller.js
index 3fc44ba..17e264a 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x2d9e=['message','catch','status','json','offset','limit','undefined','count','Content-Range','update','destroy','then','end','sendStatus','name','send','index','map','MailMessage','rawAttributes','fieldName','model','query','filters','intersection','attributes','fields','hasOwnProperty','nolimit','order','sort','where','filter','type','VIRTUAL','merge','includeAll','show','params','keys','include','options','body','find','describe','create','direction','out','findOne','CmList','List','CmContact','Contacts','updatedAt','DESC','Smtp','service','host','port','secure','authentication','auth','pass','user','attachments','length','join','root','server/files/attachments','basename','ListId','List\x20not\x20found','SendMail','sendMail','messageId','format','accept','read','readAt','YYYY-MM-DD\x20HH:mm:ss','UserId','agent','get','MailInteraction','MailInteractionId','read1stAt','interaction','[MAILMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','null','AcceptMessage','acceptMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','ContactId','sequelize','Sequelize','QueryTypes','SELECT','contact','fullname','email','internal','manual','interface','channel','motionChannel','event','fromString','EventManager','reject','mail','[MAILMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','RejectMessage','rejectMessage','User','SIP/%s','rejectmessage','download','unix','toString','server','files','tmp','bcc','subject','createdAt','Attachments','from','ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ','headers','Bcc','push','writeFileSync','unlinkSync','eml-format','moment','bluebird','util','path','html-to-text','../../components/parsers/qs','../../config/logger','api','mail-interactions','../../config/environment','../../mysqldb','defaults','localhost','redis','html-entities','./mailMessage.socket','register','client','http','info','MailMessage,\x20%s,\x20%s','request\x20sent','debug','MailMessage,\x20%s,\x20%s,\x20%s','stringify','error','code'];(function(_0x3d829d,_0x5af899){var _0x318701=function(_0x30e7cd){while(--_0x30e7cd){_0x3d829d['push'](_0x3d829d['shift']());}};_0x318701(++_0x5af899);}(_0x2d9e,0x86));var _0xe2d9=function(_0x2e87d8,_0x28babe){_0x2e87d8=_0x2e87d8-0x0;var _0x142f02=_0x2d9e[_0x2e87d8];return _0x142f02;};'use strict';var emlformat=require(_0xe2d9('0x0'));var moment=require(_0xe2d9('0x1'));var BPromise=require(_0xe2d9('0x2'));var util=require(_0xe2d9('0x3'));var path=require(_0xe2d9('0x4'));var fs=require('fs');var _=require('lodash');var Redis=require('ioredis');var htmlToText=require(_0xe2d9('0x5'));var qs=require(_0xe2d9('0x6'));var logger=require(_0xe2d9('0x7'))(_0xe2d9('0x8'));var interaction_log=require('../../config/logger')(_0xe2d9('0x9'));var config=require(_0xe2d9('0xa'));var db=require(_0xe2d9('0xb'))['db'];config['redis']=_[_0xe2d9('0xc')](config['redis'],{'host':_0xe2d9('0xd'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xe2d9('0xe')]));var htmlEntities=require(_0xe2d9('0xf'));require(_0xe2d9('0x10'))[_0xe2d9('0x11')](socket);var jayson=require('jayson/promise');var client=jayson[_0xe2d9('0x12')][_0xe2d9('0x13')]({'port':0x232c});var client9003=jayson[_0xe2d9('0x12')][_0xe2d9('0x13')]({'port':0x232b});var client9002=jayson[_0xe2d9('0x12')][_0xe2d9('0x13')]({'port':0x232a});function respondWithRpcPromise(_0x5b5211,_0x34603d,_0x4c9e3d,_0x2f67be){return new BPromise(function(_0x1faf1e,_0x23b62b){var _0x529e46=_0x2f67be||client;return _0x529e46['request'](_0x5b5211,_0x4c9e3d)['then'](function(_0x5ab042){logger[_0xe2d9('0x14')](_0xe2d9('0x15'),_0x34603d,_0xe2d9('0x16'));logger[_0xe2d9('0x17')](_0xe2d9('0x18'),_0x34603d,_0xe2d9('0x16'),JSON[_0xe2d9('0x19')](_0x5ab042));if(_0x5ab042[_0xe2d9('0x1a')]){if(_0x5ab042[_0xe2d9('0x1a')][_0xe2d9('0x1b')]===0x1f4){logger[_0xe2d9('0x1a')]('MailMessage,\x20%s,\x20%s',_0x34603d,_0x5ab042[_0xe2d9('0x1a')][_0xe2d9('0x1c')]);return _0x23b62b(_0x5ab042[_0xe2d9('0x1a')]['message']);}logger[_0xe2d9('0x1a')](_0xe2d9('0x15'),_0x34603d,_0x5ab042[_0xe2d9('0x1a')][_0xe2d9('0x1c')]);return _0x1faf1e(_0x5ab042[_0xe2d9('0x1a')][_0xe2d9('0x1c')]);}else{logger[_0xe2d9('0x14')](_0xe2d9('0x15'),_0x34603d,_0xe2d9('0x16'));_0x1faf1e(_0x5ab042['result'][_0xe2d9('0x1c')]);}})[_0xe2d9('0x1d')](function(_0x94b8a9){logger[_0xe2d9('0x1a')]('MailMessage,\x20%s,\x20%s',_0x34603d,_0x94b8a9);_0x23b62b(_0x94b8a9);});});}function respondWithResult(_0x3d41bf,_0x114ead){_0x114ead=_0x114ead||0xc8;return function(_0x5a5788){if(_0x5a5788){return _0x3d41bf[_0xe2d9('0x1e')](_0x114ead)[_0xe2d9('0x1f')](_0x5a5788);}};}function respondWithFilteredResult(_0x30b466,_0x201b1b){return function(_0x522486){if(_0x522486){var _0x31a3bd=typeof _0x201b1b[_0xe2d9('0x20')]==='undefined'&&typeof _0x201b1b[_0xe2d9('0x21')]===_0xe2d9('0x22');var _0x231468=_0x522486[_0xe2d9('0x23')];var _0x5bed76=_0x31a3bd?0x0:_0x201b1b[_0xe2d9('0x20')];var _0x25344e=_0x31a3bd?_0x522486[_0xe2d9('0x23')]:_0x201b1b['offset']+_0x201b1b[_0xe2d9('0x21')];var _0x534d7d;if(_0x25344e>=_0x231468){_0x25344e=_0x231468;_0x534d7d=0xc8;}else{_0x534d7d=0xce;}_0x30b466[_0xe2d9('0x1e')](_0x534d7d);return _0x30b466['set'](_0xe2d9('0x24'),_0x5bed76+'-'+_0x25344e+'/'+_0x231468)['json'](_0x522486);}return null;};}function saveUpdates(_0xf650d6){return function(_0x5dbbf5){if(_0x5dbbf5){return _0x5dbbf5[_0xe2d9('0x25')](_0xf650d6)['then'](function(_0x138185){return _0x138185;});}return null;};}function removeEntity(_0x33d38f){return function(_0xc17176){if(_0xc17176){return _0xc17176[_0xe2d9('0x26')]()[_0xe2d9('0x27')](function(){_0x33d38f[_0xe2d9('0x1e')](0xcc)[_0xe2d9('0x28')]();});}};}function handleEntityNotFound(_0x28e554){return function(_0x465968){if(!_0x465968){_0x28e554[_0xe2d9('0x29')](0x194);}return _0x465968;};}function handleError(_0x144ee,_0x5ca1a5){_0x5ca1a5=_0x5ca1a5||0x1f4;return function(_0x42c267){logger[_0xe2d9('0x1a')](_0x42c267['stack']);if(_0x42c267['name']){delete _0x42c267[_0xe2d9('0x2a')];}_0x144ee[_0xe2d9('0x1e')](_0x5ca1a5)[_0xe2d9('0x2b')](_0x42c267);};}exports[_0xe2d9('0x2c')]=function(_0x438f4a,_0x5e167e){var _0x53d414={},_0xcf21ce={},_0x5bad1b={'count':0x0,'rows':[]};var _0x54ad6f=_[_0xe2d9('0x2d')](db[_0xe2d9('0x2e')][_0xe2d9('0x2f')],function(_0x5b8f04){return{'name':_0x5b8f04[_0xe2d9('0x30')],'type':_0x5b8f04['type']['key']};});_0xcf21ce[_0xe2d9('0x31')]=_[_0xe2d9('0x2d')](_0x54ad6f,_0xe2d9('0x2a'));_0xcf21ce[_0xe2d9('0x32')]=_['keys'](_0x438f4a[_0xe2d9('0x32')]);_0xcf21ce[_0xe2d9('0x33')]=_[_0xe2d9('0x34')](_0xcf21ce['model'],_0xcf21ce[_0xe2d9('0x32')]);_0x53d414[_0xe2d9('0x35')]=_['intersection'](_0xcf21ce[_0xe2d9('0x31')],qs[_0xe2d9('0x36')](_0x438f4a[_0xe2d9('0x32')][_0xe2d9('0x36')]));_0x53d414[_0xe2d9('0x35')]=_0x53d414['attributes']['length']?_0x53d414[_0xe2d9('0x35')]:_0xcf21ce[_0xe2d9('0x31')];if(!_0x438f4a[_0xe2d9('0x32')][_0xe2d9('0x37')](_0xe2d9('0x38'))){_0x53d414[_0xe2d9('0x21')]=qs[_0xe2d9('0x21')](_0x438f4a[_0xe2d9('0x32')][_0xe2d9('0x21')]);_0x53d414[_0xe2d9('0x20')]=qs['offset'](_0x438f4a['query'][_0xe2d9('0x20')]);}_0x53d414[_0xe2d9('0x39')]=qs['sort'](_0x438f4a['query'][_0xe2d9('0x3a')]);_0x53d414[_0xe2d9('0x3b')]=qs[_0xe2d9('0x33')](_['pick'](_0x438f4a[_0xe2d9('0x32')],_0xcf21ce['filters']),_0x54ad6f);if(_0x438f4a[_0xe2d9('0x32')][_0xe2d9('0x3c')]){_0x53d414[_0xe2d9('0x3b')]=_['merge'](_0x53d414['where'],{'$or':_[_0xe2d9('0x2d')](_0x54ad6f,function(_0x31dbcf){if(_0x31dbcf[_0xe2d9('0x3d')]!==_0xe2d9('0x3e')){var _0x1d8a07={};_0x1d8a07[_0x31dbcf[_0xe2d9('0x2a')]]={'$like':'%'+_0x438f4a[_0xe2d9('0x32')]['filter']+'%'};return _0x1d8a07;}})});}_0x53d414=_[_0xe2d9('0x3f')]({},_0x53d414,_0x438f4a['options']);var _0x8aeed4={'where':_0x53d414[_0xe2d9('0x3b')]};return db[_0xe2d9('0x2e')]['count'](_0x8aeed4)[_0xe2d9('0x27')](function(_0x3f8b20){_0x5bad1b[_0xe2d9('0x23')]=_0x3f8b20;if(_0x438f4a[_0xe2d9('0x32')][_0xe2d9('0x40')]){_0x53d414['include']=[{'all':!![]}];}return db[_0xe2d9('0x2e')]['findAll'](_0x53d414);})[_0xe2d9('0x27')](function(_0x49f69e){_0x5bad1b['rows']=_0x49f69e;return _0x5bad1b;})[_0xe2d9('0x27')](respondWithFilteredResult(_0x5e167e,_0x53d414))[_0xe2d9('0x1d')](handleError(_0x5e167e,null));};exports[_0xe2d9('0x41')]=function(_0x52554f,_0x21899b){var _0x148286={'raw':!![],'where':{'id':_0x52554f[_0xe2d9('0x42')]['id']}},_0x1b72fe={};_0x1b72fe[_0xe2d9('0x31')]=_[_0xe2d9('0x43')](db[_0xe2d9('0x2e')][_0xe2d9('0x2f')]);_0x1b72fe[_0xe2d9('0x32')]=_[_0xe2d9('0x43')](_0x52554f[_0xe2d9('0x32')]);_0x1b72fe[_0xe2d9('0x33')]=_[_0xe2d9('0x34')](_0x1b72fe['model'],_0x1b72fe[_0xe2d9('0x32')]);_0x148286[_0xe2d9('0x35')]=_[_0xe2d9('0x34')](_0x1b72fe['model'],qs[_0xe2d9('0x36')](_0x52554f[_0xe2d9('0x32')][_0xe2d9('0x36')]));_0x148286[_0xe2d9('0x35')]=_0x148286[_0xe2d9('0x35')]['length']?_0x148286[_0xe2d9('0x35')]:_0x1b72fe[_0xe2d9('0x31')];if(_0x52554f[_0xe2d9('0x32')]['includeAll']){_0x148286[_0xe2d9('0x44')]=[{'all':!![]}];}_0x148286=_['merge']({},_0x148286,_0x52554f[_0xe2d9('0x45')]);return db['MailMessage']['find'](_0x148286)[_0xe2d9('0x27')](handleEntityNotFound(_0x21899b,null))[_0xe2d9('0x27')](respondWithResult(_0x21899b,null))['catch'](handleError(_0x21899b,null));};exports['update']=function(_0x2d346f,_0x1eebbd){if(_0x2d346f[_0xe2d9('0x46')]['id']){delete _0x2d346f[_0xe2d9('0x46')]['id'];}return db['MailMessage'][_0xe2d9('0x47')]({'where':{'id':_0x2d346f['params']['id']}})[_0xe2d9('0x27')](handleEntityNotFound(_0x1eebbd,null))[_0xe2d9('0x27')](saveUpdates(_0x2d346f[_0xe2d9('0x46')],null))[_0xe2d9('0x27')](respondWithResult(_0x1eebbd,null))['catch'](handleError(_0x1eebbd,null));};exports['destroy']=function(_0x4c9521,_0x40288b){return db['MailMessage'][_0xe2d9('0x47')]({'where':{'id':_0x4c9521[_0xe2d9('0x42')]['id']}})[_0xe2d9('0x27')](handleEntityNotFound(_0x40288b,null))[_0xe2d9('0x27')](removeEntity(_0x40288b,null))[_0xe2d9('0x1d')](handleError(_0x40288b,null));};exports[_0xe2d9('0x48')]=function(_0x1a6028,_0x3f4126){return db[_0xe2d9('0x2e')][_0xe2d9('0x48')]()[_0xe2d9('0x27')](respondWithResult(_0x3f4126,null))[_0xe2d9('0x1d')](handleError(_0x3f4126,null));};exports[_0xe2d9('0x49')]=function(_0x48871a,_0x3116dd){return db[_0xe2d9('0x2e')]['create'](_0x48871a[_0xe2d9('0x46')])[_0xe2d9('0x27')](function(_0x2db940){if(_0x2db940){if(_0x2db940[_0xe2d9('0x4a')]===_0xe2d9('0x4b')&&!_0x2db940['secret']){var _0x223926,_0x5b1777,_0x1372e5;if(_0x48871a['body']['to']){_0x5b1777=_0x48871a[_0xe2d9('0x46')]['to']['split'](',')[0x0];}return db['MailAccount'][_0xe2d9('0x4c')]({'where':{'id':_0x2db940['MailAccountId']},'include':[{'model':db[_0xe2d9('0x4d')],'as':_0xe2d9('0x4e'),'include':[{'model':db[_0xe2d9('0x4f')],'as':_0xe2d9('0x50'),'where':{'email':_0x5b1777},'limit':0x1,'order':[[_0xe2d9('0x51'),_0xe2d9('0x52')]]}]},{'model':db['MailServerOut'],'as':_0xe2d9('0x53'),'raw':!![]}]})[_0xe2d9('0x27')](function(_0x4ef741){_0x223926=_0x4ef741;if(_0x223926&&_0x223926[_0xe2d9('0x53')]){var _0x1448f7={'tls':{'rejectUnauthorized':![]}};if(_['isNil'](_0x223926[_0xe2d9('0x53')][_0xe2d9('0x54')])){_0x1448f7[_0xe2d9('0x55')]=_0x223926[_0xe2d9('0x53')]['host'];_0x1448f7[_0xe2d9('0x56')]=_0x223926[_0xe2d9('0x53')]['port'];_0x1448f7[_0xe2d9('0x57')]=_0x223926[_0xe2d9('0x53')][_0xe2d9('0x57')];if(_0x223926[_0xe2d9('0x53')][_0xe2d9('0x58')]){_0x1448f7[_0xe2d9('0x59')]={'user':_0x223926[_0xe2d9('0x53')]['user'],'pass':_0x223926[_0xe2d9('0x53')][_0xe2d9('0x5a')]};}}else{_0x1448f7['service']=_0x223926[_0xe2d9('0x53')]['service'];_0x1448f7[_0xe2d9('0x59')]={'user':_0x223926[_0xe2d9('0x53')][_0xe2d9('0x5b')],'pass':_0x223926['Smtp'][_0xe2d9('0x5a')]};_0x1448f7[_0xe2d9('0x57')]=_0x223926[_0xe2d9('0x53')][_0xe2d9('0x57')];}if(_0x48871a[_0xe2d9('0x46')][_0xe2d9('0x5c')]&&_0x48871a[_0xe2d9('0x46')]['attachments'][_0xe2d9('0x5d')]){for(var _0x43644c=0x0;_0x43644c<_0x48871a[_0xe2d9('0x46')][_0xe2d9('0x5c')][_0xe2d9('0x5d')];_0x43644c+=0x1){_0x48871a[_0xe2d9('0x46')][_0xe2d9('0x5c')][_0x43644c]={'filename':_0x48871a[_0xe2d9('0x46')][_0xe2d9('0x5c')][_0x43644c][_0xe2d9('0x2a')],'path':path[_0xe2d9('0x5e')](config[_0xe2d9('0x5f')],_0xe2d9('0x60'),_0x48871a[_0xe2d9('0x46')][_0xe2d9('0x5c')][_0x43644c][_0xe2d9('0x61')])};}}_0x1372e5={'account':_0x1448f7,'message':_0x48871a[_0xe2d9('0x46')]};return;}})['then'](function(){if(_0x223926[_0xe2d9('0x4e')]){if(_0x223926['List'][_0xe2d9('0x50')][_0xe2d9('0x5d')]){return _0x223926['List'][_0xe2d9('0x50')][0x0];}else{return db[_0xe2d9('0x4f')][_0xe2d9('0x49')](_[_0xe2d9('0xc')](_0x48871a[_0xe2d9('0x46')],{'firstName':_0x48871a['body']['to'],'email':_0x48871a[_0xe2d9('0x46')]['to'],'phone':_0x48871a[_0xe2d9('0x46')]['to'],'ListId':_0x223926[_0xe2d9('0x62')]}));}}else{throw new Error(_0xe2d9('0x63'));}})[_0xe2d9('0x27')](function(){if(_0x1372e5){return respondWithRpcPromise(_0xe2d9('0x64'),_0xe2d9('0x65'),_0x1372e5,client9003)[_0xe2d9('0x27')](function(_0x273f51){return _0x2db940[_0xe2d9('0x25')]({'read':!![],'messageId':_0x273f51[_0xe2d9('0x66')],'sentAt':moment()[_0xe2d9('0x67')]('YYYY-MM-DD\x20HH:mm:ss')});})[_0xe2d9('0x1d')](function(_0x5f0d8c){logger['error']('%s',JSON[_0xe2d9('0x19')](_0x5f0d8c));return _0x2db940;});}return _0x2db940;});}return _0x2db940;}})[_0xe2d9('0x27')](respondWithResult(_0x3116dd,0xc9))[_0xe2d9('0x1d')](handleError(_0x3116dd,null));};exports[_0xe2d9('0x68')]=function(_0x45e7bd,_0x22026a){var _0x41b33a={'agent':{},'channel':'mail'};if(_0x45e7bd[_0xe2d9('0x46')]['id']){delete _0x45e7bd[_0xe2d9('0x46')]['id'];}_0x45e7bd[_0xe2d9('0x46')][_0xe2d9('0x69')]=!![];_0x45e7bd[_0xe2d9('0x46')][_0xe2d9('0x6a')]=moment()[_0xe2d9('0x67')](_0xe2d9('0x6b'));_0x45e7bd[_0xe2d9('0x46')]['UserId']=_0x45e7bd[_0xe2d9('0x46')][_0xe2d9('0x6c')]||_0x45e7bd[_0xe2d9('0x5b')]['id'];_0x41b33a[_0xe2d9('0x6d')]['id']=_0x45e7bd[_0xe2d9('0x46')][_0xe2d9('0x6c')];return db['MailMessage'][_0xe2d9('0x47')]({'where':{'id':_0x45e7bd[_0xe2d9('0x42')]['id'],'UserId':null}})[_0xe2d9('0x27')](handleEntityNotFound(_0x22026a,null))[_0xe2d9('0x27')](saveUpdates(_0x45e7bd[_0xe2d9('0x46')],null))[_0xe2d9('0x27')](function(_0x336349){if(_0x336349){_0x41b33a['message']=_0x336349[_0xe2d9('0x6e')]({'plain':!![]});return db[_0xe2d9('0x6f')][_0xe2d9('0x47')]({'where':{'id':_0x336349[_0xe2d9('0x70')]}});}return null;})[_0xe2d9('0x27')](handleEntityNotFound(_0x22026a,null))[_0xe2d9('0x27')](function(_0xf1252c){if(_0xf1252c){return _0xf1252c[_0xe2d9('0x25')]({'UserId':_0x45e7bd['body']['UserId'],'read1stAt':_['isNil'](_0xf1252c[_0xe2d9('0x71')])?moment()[_0xe2d9('0x67')]('YYYY-MM-DD\x20HH:mm:ss'):undefined});}return null;})[_0xe2d9('0x27')](function(_0x49f6f7){if(_0x49f6f7){_0x41b33a[_0xe2d9('0x72')]=_0x49f6f7[_0xe2d9('0x6e')]({'plain':!![]});interaction_log[_0xe2d9('0x14')](_0xe2d9('0x73'),_0x45e7bd['user']['id'],_0x45e7bd[_0xe2d9('0x5b')]['name'],_0x45e7bd[_0xe2d9('0x5b')]['role'],_0x41b33a[_0xe2d9('0x72')]['id'],_0x45e7bd[_0xe2d9('0x46')]?JSON[_0xe2d9('0x19')](_0x45e7bd[_0xe2d9('0x46')]):_0xe2d9('0x74'));return respondWithRpcPromise(_0xe2d9('0x75'),_0xe2d9('0x76'),_0x41b33a);}return null;})[_0xe2d9('0x27')](function(_0x57cb16){var _0x3e0565=_0xe2d9('0x77')+_0x57cb16[_0xe2d9('0x1c')][_0xe2d9('0x78')];return db[_0xe2d9('0x79')][_0xe2d9('0x32')](_0x3e0565,{'type':db[_0xe2d9('0x7a')][_0xe2d9('0x7b')][_0xe2d9('0x7c')],'raw':!![]})[_0xe2d9('0x27')](function(_0x5f373a){return _0x5f373a;});})[_0xe2d9('0x27')](function(_0x36da24){if(_0x36da24){_0x41b33a['message'][_0xe2d9('0x7d')]=_0x36da24[0x0];if(!_0x45e7bd[_0xe2d9('0x46')][_0xe2d9('0x6c')])return;return db['User'][_0xe2d9('0x47')]({'where':{'id':_0x45e7bd['body'][_0xe2d9('0x6c')],'role':_0xe2d9('0x6d')},'attributes':['id','name',_0xe2d9('0x7e'),_0xe2d9('0x7f'),_0xe2d9('0x80')],'raw':!![]});}return null;})['then'](function(_0x22324f){if(!_0x22324f)return null;_0x41b33a[_0xe2d9('0x1c')][_0xe2d9('0x6d')]=_0x22324f;return _0x41b33a;})[_0xe2d9('0x27')](function(_0x55f7c1){if(_0x55f7c1){if(_0x45e7bd[_0xe2d9('0x46')][_0xe2d9('0x81')]){_0x41b33a[_0xe2d9('0x1c')][_0xe2d9('0x82')]=util['format']('SIP/%s',_0x45e7bd[_0xe2d9('0x5b')][_0xe2d9('0x2a')]);_0x41b33a[_0xe2d9('0x1c')][_0xe2d9('0x83')]=_0x41b33a[_0xe2d9('0x83')];_0x41b33a[_0xe2d9('0x1c')][_0xe2d9('0x84')]=_0x41b33a[_0xe2d9('0x83')];_0x41b33a[_0xe2d9('0x1c')][_0xe2d9('0x85')]=_0xe2d9('0x68');_0x41b33a[_0xe2d9('0x1c')][_0xe2d9('0x46')]=htmlToText[_0xe2d9('0x86')](_0x41b33a[_0xe2d9('0x1c')][_0xe2d9('0x46')]);return respondWithRpcPromise(_0xe2d9('0x87'),_0xe2d9('0x87'),{'event':'acceptmessage','message':_0x41b33a[_0xe2d9('0x1c')]},client9002)[_0xe2d9('0x27')](function(){return _0x41b33a;});}return _0x41b33a;}return null;})[_0xe2d9('0x27')](respondWithResult(_0x22026a,null))[_0xe2d9('0x1d')](handleError(_0x22026a,null));};exports[_0xe2d9('0x88')]=function(_0x4a2235,_0xd42da7){var _0x2e57d8={'agent':{},'channel':_0xe2d9('0x89')};if(_0x4a2235['body']['id']){delete _0x4a2235[_0xe2d9('0x46')]['id'];}_0x4a2235[_0xe2d9('0x46')][_0xe2d9('0x6c')]=_0x4a2235[_0xe2d9('0x46')][_0xe2d9('0x6c')]||_0x4a2235[_0xe2d9('0x5b')]['id'];_0x2e57d8[_0xe2d9('0x6d')]['id']=_0x4a2235[_0xe2d9('0x46')][_0xe2d9('0x6c')];return db[_0xe2d9('0x2e')]['find']({'where':{'id':_0x4a2235[_0xe2d9('0x42')]['id'],'UserId':null}})[_0xe2d9('0x27')](handleEntityNotFound(_0xd42da7,null))['then'](function(_0x3b4271){if(_0x3b4271){_0x2e57d8[_0xe2d9('0x1c')]=_0x3b4271[_0xe2d9('0x6e')]({'plain':!![]});return db[_0xe2d9('0x6f')][_0xe2d9('0x47')]({'where':{'id':_0x3b4271[_0xe2d9('0x70')]}});}return null;})[_0xe2d9('0x27')](handleEntityNotFound(_0xd42da7,null))[_0xe2d9('0x27')](function(_0x184a4d){if(_0x184a4d){_0x2e57d8[_0xe2d9('0x72')]=_0x184a4d['get']({'plain':!![]});interaction_log[_0xe2d9('0x14')](_0xe2d9('0x8a'),_0x4a2235[_0xe2d9('0x5b')]['id'],_0x4a2235[_0xe2d9('0x5b')][_0xe2d9('0x2a')],_0x4a2235[_0xe2d9('0x5b')][_0xe2d9('0x8b')],_0x2e57d8[_0xe2d9('0x72')]['id'],_0x4a2235[_0xe2d9('0x46')]?JSON[_0xe2d9('0x19')](_0x4a2235['body']):_0xe2d9('0x74'));return respondWithRpcPromise(_0xe2d9('0x8c'),_0xe2d9('0x8d'),_0x2e57d8);}return null;})['then'](function(_0x2c2491){var _0x541516=_0xe2d9('0x77')+_0x2c2491[_0xe2d9('0x1c')]['ContactId'];return db[_0xe2d9('0x79')][_0xe2d9('0x32')](_0x541516,{'type':db['Sequelize'][_0xe2d9('0x7b')][_0xe2d9('0x7c')],'raw':!![]})['then'](function(_0x191c1e){return _0x191c1e;});})[_0xe2d9('0x27')](function(_0x5758c8){if(_0x5758c8){_0x2e57d8['message']['contact']=_0x5758c8[0x0];if(!_0x4a2235['body'][_0xe2d9('0x6c')])return;return db[_0xe2d9('0x8e')][_0xe2d9('0x47')]({'where':{'id':_0x4a2235['body'][_0xe2d9('0x6c')],'role':_0xe2d9('0x6d')},'attributes':['id',_0xe2d9('0x2a'),_0xe2d9('0x7e'),_0xe2d9('0x7f'),'internal'],'raw':!![]});}return null;})['then'](function(_0x261927){if(!_0x261927)return null;_0x2e57d8['message']['agent']=_0x261927;return _0x2e57d8;})[_0xe2d9('0x27')](function(_0x279176){if(_0x279176){_0x279176['message']['interface']=util[_0xe2d9('0x67')](_0xe2d9('0x8f'),_0x4a2235[_0xe2d9('0x5b')][_0xe2d9('0x2a')]);_0x279176[_0xe2d9('0x1c')][_0xe2d9('0x83')]=_0x2e57d8[_0xe2d9('0x83')];_0x279176['message'][_0xe2d9('0x84')]=_0x2e57d8[_0xe2d9('0x83')];_0x279176[_0xe2d9('0x1c')][_0xe2d9('0x85')]=_0xe2d9('0x88');_0x279176['message']['body']=htmlToText[_0xe2d9('0x86')](_0x2e57d8['message']['body']);respondWithRpcPromise(_0xe2d9('0x87'),_0xe2d9('0x87'),{'event':_0xe2d9('0x90'),'message':_0x279176['message']},client9002);return _0x2e57d8;}return null;})[_0xe2d9('0x27')](respondWithResult(_0xd42da7,null))['catch'](handleError(_0xd42da7,null));};exports[_0xe2d9('0x91')]=function(_0x50a4f3,_0x37e9b1){var _0x24b735=moment()[_0xe2d9('0x92')]()[_0xe2d9('0x93')]();var _0x20f84b=path[_0xe2d9('0x5e')](config[_0xe2d9('0x5f')],_0xe2d9('0x94'),_0xe2d9('0x95'),_0xe2d9('0x96'));var _0x19cf50=path[_0xe2d9('0x5e')](config[_0xe2d9('0x5f')],'server',_0xe2d9('0x95'),_0xe2d9('0x5c'));var _0xcb3c56=util[_0xe2d9('0x67')]('message-%s.eml',_0x24b735);return db[_0xe2d9('0x2e')][_0xe2d9('0x47')]({'where':{'id':_0x50a4f3['params']['id']},'attributes':['id',_0xe2d9('0x46'),'from','to','cc',_0xe2d9('0x97'),_0xe2d9('0x98'),_0xe2d9('0x99')],'include':_0x50a4f3[_0xe2d9('0x32')]['attachments']?[{'model':db['Attachment'],'as':_0xe2d9('0x9a')}]:undefined})[_0xe2d9('0x27')](handleEntityNotFound(_0x37e9b1,null))[_0xe2d9('0x27')](function(_0x426d7b){if(_0x426d7b){var _0x172315=_0x426d7b;var _0x3fd8e0={'from':_0x172315[_0xe2d9('0x9b')],'to':_0x172315['to'],'subject':_0x172315[_0xe2d9('0x98')],'html':htmlEntities['decode'](_0x172315[_0xe2d9('0x46')]),'headers':{'Date':moment(_0x172315['createdAt'])[_0xe2d9('0x67')](_0xe2d9('0x9c'))},'attachments':[]};if(_0x426d7b['cc']){_0x3fd8e0[_0xe2d9('0x9d')]['Cc']=_0x426d7b['cc'];}if(_0x426d7b[_0xe2d9('0x97')]){_0x3fd8e0[_0xe2d9('0x9d')][_0xe2d9('0x9e')]=_0x426d7b[_0xe2d9('0x97')];}return new BPromise(function(_0xa18df9,_0x1f153e){if(_0x426d7b[_0xe2d9('0x9a')]){for(var _0x442123=0x0;_0x442123<_0x426d7b['Attachments'][_0xe2d9('0x5d')];_0x442123++){var _0x23f619=_0x426d7b[_0xe2d9('0x9a')][_0x442123];var _0x37bea9=path['join'](_0x19cf50,_0x23f619[_0xe2d9('0x61')]);if(fs['existsSync'](_0x37bea9)){_0x3fd8e0['attachments'][_0xe2d9('0x9f')]({'name':_0x23f619['name'],'contentType':_0x23f619[_0xe2d9('0x3d')],'data':fs['readFileSync'](_0x37bea9)});}}}emlformat['build'](_0x3fd8e0,function(_0x237178,_0x540a0b){if(_0x237178)return _0x1f153e(_0x237178);fs[_0xe2d9('0xa0')](path[_0xe2d9('0x5e')](_0x20f84b,_0xcb3c56),_0x540a0b);return _0xa18df9(_0x540a0b);});});}})[_0xe2d9('0x27')](function(_0x34707c){if(_0x34707c){return _0x37e9b1['download'](path[_0xe2d9('0x5e')](_0x20f84b,_0xcb3c56),_0xcb3c56,function(_0x26c561){if(!_0x26c561)fs[_0xe2d9('0xa1')](path[_0xe2d9('0x5e')](_0x20f84b,_0xcb3c56));});}})['catch'](handleError(_0x37e9b1,null));};
\ No newline at end of file
+var _0x5a76=['join','root','server/files/attachments','basename','List','ListId','List\x20not\x20found','SendMail','sendMail','messageId','format','YYYY-MM-DD\x20HH:mm:ss','accept','read','readAt','UserId','user','agent','MailInteraction','MailInteractionId','isNil','get','[MAILMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','interaction','AcceptMessage','acceptMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','ContactId','sequelize','Sequelize','contact','User','fullname','email','internal','channel','motionChannel','event','fromString','EventManager','[MAILMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','null','rejectMessage','SIP/%s','reject','rejectmessage','download','toString','files','tmp','server','message-%s.eml','from','bcc','createdAt','Attachment','Attachments','subject','decode','ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ','headers','existsSync','push','type','readFileSync','build','unlinkSync','eml-format','moment','util','path','lodash','ioredis','html-to-text','../../components/parsers/qs','../../config/logger','mail-interactions','../../mysqldb','redis','defaults','localhost','socket.io-emitter','html-entities','./mailMessage.socket','client','http','request','then','info','MailMessage,\x20%s,\x20%s','request\x20sent','debug','MailMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','message','catch','status','json','offset','undefined','limit','count','Content-Range','update','destroy','end','sendStatus','stack','name','send','index','map','rawAttributes','key','model','query','keys','filters','intersection','attributes','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','MailMessage','includeAll','findAll','rows','params','fields','include','options','find','body','describe','create','direction','MailAccount','findOne','MailAccountId','CmList','CmContact','Contacts','updatedAt','DESC','MailServerOut','Smtp','CloudProvider','getSmtpOptions','attachments'];(function(_0x1006d5,_0x31bf70){var _0x4513da=function(_0x345cb6){while(--_0x345cb6){_0x1006d5['push'](_0x1006d5['shift']());}};_0x4513da(++_0x31bf70);}(_0x5a76,0xe2));var _0x65a7=function(_0x57dbbe,_0x70f5bb){_0x57dbbe=_0x57dbbe-0x0;var _0x4b82ab=_0x5a76[_0x57dbbe];return _0x4b82ab;};'use strict';var emlformat=require(_0x65a7('0x0'));var moment=require(_0x65a7('0x1'));var BPromise=require('bluebird');var util=require(_0x65a7('0x2'));var path=require(_0x65a7('0x3'));var fs=require('fs');var _=require(_0x65a7('0x4'));var Redis=require(_0x65a7('0x5'));var htmlToText=require(_0x65a7('0x6'));var qs=require(_0x65a7('0x7'));var logger=require('../../config/logger')('api');var interaction_log=require(_0x65a7('0x8'))(_0x65a7('0x9'));var config=require('../../config/environment');var db=require(_0x65a7('0xa'))['db'];config[_0x65a7('0xb')]=_[_0x65a7('0xc')](config['redis'],{'host':_0x65a7('0xd'),'port':0x18eb});var socket=require(_0x65a7('0xe'))(new Redis(config[_0x65a7('0xb')]));var htmlEntities=require(_0x65a7('0xf'));require(_0x65a7('0x10'))['register'](socket);var jayson=require('jayson/promise');var client=jayson[_0x65a7('0x11')][_0x65a7('0x12')]({'port':0x232c});var client9003=jayson['client'][_0x65a7('0x12')]({'port':0x232b});var client9002=jayson[_0x65a7('0x11')]['http']({'port':0x232a});function respondWithRpcPromise(_0xe0424e,_0x5c1bd5,_0x26bde5,_0x3ccb97){return new BPromise(function(_0x268d8e,_0x3caf23){var _0x10fdf1=_0x3ccb97||client;return _0x10fdf1[_0x65a7('0x13')](_0xe0424e,_0x26bde5)[_0x65a7('0x14')](function(_0x57056f){logger[_0x65a7('0x15')](_0x65a7('0x16'),_0x5c1bd5,_0x65a7('0x17'));logger[_0x65a7('0x18')](_0x65a7('0x19'),_0x5c1bd5,'request\x20sent',JSON[_0x65a7('0x1a')](_0x57056f));if(_0x57056f[_0x65a7('0x1b')]){if(_0x57056f[_0x65a7('0x1b')][_0x65a7('0x1c')]===0x1f4){logger[_0x65a7('0x1b')](_0x65a7('0x16'),_0x5c1bd5,_0x57056f[_0x65a7('0x1b')][_0x65a7('0x1d')]);return _0x3caf23(_0x57056f[_0x65a7('0x1b')]['message']);}logger[_0x65a7('0x1b')]('MailMessage,\x20%s,\x20%s',_0x5c1bd5,_0x57056f[_0x65a7('0x1b')][_0x65a7('0x1d')]);return _0x268d8e(_0x57056f[_0x65a7('0x1b')][_0x65a7('0x1d')]);}else{logger[_0x65a7('0x15')](_0x65a7('0x16'),_0x5c1bd5,'request\x20sent');_0x268d8e(_0x57056f['result'][_0x65a7('0x1d')]);}})[_0x65a7('0x1e')](function(_0x11e78e){logger['error']('MailMessage,\x20%s,\x20%s',_0x5c1bd5,_0x11e78e);_0x3caf23(_0x11e78e);});});}function respondWithResult(_0x2f0ea4,_0x440748){_0x440748=_0x440748||0xc8;return function(_0x4a56dc){if(_0x4a56dc){return _0x2f0ea4[_0x65a7('0x1f')](_0x440748)[_0x65a7('0x20')](_0x4a56dc);}};}function respondWithFilteredResult(_0x5d3690,_0x1265b7){return function(_0x5bca20){if(_0x5bca20){var _0x54a25b=typeof _0x1265b7[_0x65a7('0x21')]===_0x65a7('0x22')&&typeof _0x1265b7[_0x65a7('0x23')]==='undefined';var _0xa5c745=_0x5bca20[_0x65a7('0x24')];var _0x395d93=_0x54a25b?0x0:_0x1265b7[_0x65a7('0x21')];var _0x13805d=_0x54a25b?_0x5bca20[_0x65a7('0x24')]:_0x1265b7[_0x65a7('0x21')]+_0x1265b7[_0x65a7('0x23')];var _0x3b039c;if(_0x13805d>=_0xa5c745){_0x13805d=_0xa5c745;_0x3b039c=0xc8;}else{_0x3b039c=0xce;}_0x5d3690['status'](_0x3b039c);return _0x5d3690['set'](_0x65a7('0x25'),_0x395d93+'-'+_0x13805d+'/'+_0xa5c745)[_0x65a7('0x20')](_0x5bca20);}return null;};}function saveUpdates(_0x3a82be){return function(_0x10a4d4){if(_0x10a4d4){return _0x10a4d4[_0x65a7('0x26')](_0x3a82be)[_0x65a7('0x14')](function(_0x416398){return _0x416398;});}return null;};}function removeEntity(_0x3cf50c){return function(_0x1006cb){if(_0x1006cb){return _0x1006cb[_0x65a7('0x27')]()[_0x65a7('0x14')](function(){_0x3cf50c[_0x65a7('0x1f')](0xcc)[_0x65a7('0x28')]();});}};}function handleEntityNotFound(_0x2f070d){return function(_0x4f0cd7){if(!_0x4f0cd7){_0x2f070d[_0x65a7('0x29')](0x194);}return _0x4f0cd7;};}function handleError(_0x20471a,_0x326d52){_0x326d52=_0x326d52||0x1f4;return function(_0x4dafb0){logger[_0x65a7('0x1b')](_0x4dafb0[_0x65a7('0x2a')]);if(_0x4dafb0[_0x65a7('0x2b')]){delete _0x4dafb0[_0x65a7('0x2b')];}_0x20471a['status'](_0x326d52)[_0x65a7('0x2c')](_0x4dafb0);};}exports[_0x65a7('0x2d')]=function(_0x43b2e5,_0x41af2e){var _0x33570f={},_0x1e57ca={},_0x3be263={'count':0x0,'rows':[]};var _0x2a2cbf=_[_0x65a7('0x2e')](db['MailMessage'][_0x65a7('0x2f')],function(_0x1077c8){return{'name':_0x1077c8['fieldName'],'type':_0x1077c8['type'][_0x65a7('0x30')]};});_0x1e57ca[_0x65a7('0x31')]=_[_0x65a7('0x2e')](_0x2a2cbf,_0x65a7('0x2b'));_0x1e57ca[_0x65a7('0x32')]=_[_0x65a7('0x33')](_0x43b2e5[_0x65a7('0x32')]);_0x1e57ca[_0x65a7('0x34')]=_[_0x65a7('0x35')](_0x1e57ca['model'],_0x1e57ca[_0x65a7('0x32')]);_0x33570f[_0x65a7('0x36')]=_[_0x65a7('0x35')](_0x1e57ca['model'],qs['fields'](_0x43b2e5[_0x65a7('0x32')]['fields']));_0x33570f[_0x65a7('0x36')]=_0x33570f[_0x65a7('0x36')][_0x65a7('0x37')]?_0x33570f['attributes']:_0x1e57ca['model'];if(!_0x43b2e5[_0x65a7('0x32')][_0x65a7('0x38')](_0x65a7('0x39'))){_0x33570f[_0x65a7('0x23')]=qs[_0x65a7('0x23')](_0x43b2e5[_0x65a7('0x32')]['limit']);_0x33570f[_0x65a7('0x21')]=qs[_0x65a7('0x21')](_0x43b2e5[_0x65a7('0x32')]['offset']);}_0x33570f[_0x65a7('0x3a')]=qs['sort'](_0x43b2e5['query'][_0x65a7('0x3b')]);_0x33570f[_0x65a7('0x3c')]=qs[_0x65a7('0x34')](_[_0x65a7('0x3d')](_0x43b2e5['query'],_0x1e57ca['filters']),_0x2a2cbf);if(_0x43b2e5['query'][_0x65a7('0x3e')]){_0x33570f['where']=_['merge'](_0x33570f[_0x65a7('0x3c')],{'$or':_[_0x65a7('0x2e')](_0x2a2cbf,function(_0x5c4efd){if(_0x5c4efd['type']!=='VIRTUAL'){var _0x54c762={};_0x54c762[_0x5c4efd[_0x65a7('0x2b')]]={'$like':'%'+_0x43b2e5['query'][_0x65a7('0x3e')]+'%'};return _0x54c762;}})});}_0x33570f=_[_0x65a7('0x3f')]({},_0x33570f,_0x43b2e5['options']);var _0x3c6bb7={'where':_0x33570f[_0x65a7('0x3c')]};return db[_0x65a7('0x40')][_0x65a7('0x24')](_0x3c6bb7)['then'](function(_0x4c659c){_0x3be263[_0x65a7('0x24')]=_0x4c659c;if(_0x43b2e5['query'][_0x65a7('0x41')]){_0x33570f['include']=[{'all':!![]}];}return db['MailMessage'][_0x65a7('0x42')](_0x33570f);})[_0x65a7('0x14')](function(_0x4360b2){_0x3be263[_0x65a7('0x43')]=_0x4360b2;return _0x3be263;})['then'](respondWithFilteredResult(_0x41af2e,_0x33570f))[_0x65a7('0x1e')](handleError(_0x41af2e,null));};exports['show']=function(_0x3dbd46,_0x59f62c){var _0x5e5706={'raw':!![],'where':{'id':_0x3dbd46[_0x65a7('0x44')]['id']}},_0x51f186={};_0x51f186[_0x65a7('0x31')]=_[_0x65a7('0x33')](db[_0x65a7('0x40')][_0x65a7('0x2f')]);_0x51f186[_0x65a7('0x32')]=_[_0x65a7('0x33')](_0x3dbd46[_0x65a7('0x32')]);_0x51f186['filters']=_[_0x65a7('0x35')](_0x51f186['model'],_0x51f186[_0x65a7('0x32')]);_0x5e5706[_0x65a7('0x36')]=_[_0x65a7('0x35')](_0x51f186[_0x65a7('0x31')],qs[_0x65a7('0x45')](_0x3dbd46[_0x65a7('0x32')][_0x65a7('0x45')]));_0x5e5706[_0x65a7('0x36')]=_0x5e5706[_0x65a7('0x36')][_0x65a7('0x37')]?_0x5e5706['attributes']:_0x51f186['model'];if(_0x3dbd46[_0x65a7('0x32')][_0x65a7('0x41')]){_0x5e5706[_0x65a7('0x46')]=[{'all':!![]}];}_0x5e5706=_['merge']({},_0x5e5706,_0x3dbd46[_0x65a7('0x47')]);return db[_0x65a7('0x40')][_0x65a7('0x48')](_0x5e5706)['then'](handleEntityNotFound(_0x59f62c,null))[_0x65a7('0x14')](respondWithResult(_0x59f62c,null))[_0x65a7('0x1e')](handleError(_0x59f62c,null));};exports[_0x65a7('0x26')]=function(_0x52a353,_0x3bc066){if(_0x52a353[_0x65a7('0x49')]['id']){delete _0x52a353[_0x65a7('0x49')]['id'];}return db['MailMessage'][_0x65a7('0x48')]({'where':{'id':_0x52a353[_0x65a7('0x44')]['id']}})[_0x65a7('0x14')](handleEntityNotFound(_0x3bc066,null))[_0x65a7('0x14')](saveUpdates(_0x52a353[_0x65a7('0x49')],null))['then'](respondWithResult(_0x3bc066,null))[_0x65a7('0x1e')](handleError(_0x3bc066,null));};exports[_0x65a7('0x27')]=function(_0x1f749e,_0x2cf774){return db[_0x65a7('0x40')][_0x65a7('0x48')]({'where':{'id':_0x1f749e[_0x65a7('0x44')]['id']}})[_0x65a7('0x14')](handleEntityNotFound(_0x2cf774,null))['then'](removeEntity(_0x2cf774,null))[_0x65a7('0x1e')](handleError(_0x2cf774,null));};exports[_0x65a7('0x4a')]=function(_0x588ba3,_0x3aa564){return db['MailMessage']['describe']()[_0x65a7('0x14')](respondWithResult(_0x3aa564,null))[_0x65a7('0x1e')](handleError(_0x3aa564,null));};exports[_0x65a7('0x4b')]=function(_0xbf8ccd,_0x3d3029){return db[_0x65a7('0x40')]['create'](_0xbf8ccd['body'])[_0x65a7('0x14')](function(_0x165898){if(_0x165898){if(_0x165898[_0x65a7('0x4c')]==='out'&&!_0x165898['secret']){var _0x4e2f52,_0x691899,_0x4d4ba2;if(_0xbf8ccd['body']['to']){_0x691899=_0xbf8ccd[_0x65a7('0x49')]['to']['split'](',')[0x0];}return db[_0x65a7('0x4d')][_0x65a7('0x4e')]({'where':{'id':_0x165898[_0x65a7('0x4f')]},'include':[{'model':db[_0x65a7('0x50')],'as':'List','include':[{'model':db[_0x65a7('0x51')],'as':_0x65a7('0x52'),'where':{'email':_0x691899},'limit':0x1,'order':[[_0x65a7('0x53'),_0x65a7('0x54')]]}]},{'model':db[_0x65a7('0x55')],'as':_0x65a7('0x56'),'raw':!![],'include':[{'model':db[_0x65a7('0x57')],'as':'CloudProvider','raw':!![]}]}]})[_0x65a7('0x14')](function(_0x36a720){_0x4e2f52=_0x36a720;if(!_0x4e2f52||!_0x4e2f52[_0x65a7('0x56')])return;var _0x365415=_0x4e2f52[_0x65a7('0x58')]();if(_0xbf8ccd[_0x65a7('0x49')][_0x65a7('0x59')]&&_0xbf8ccd[_0x65a7('0x49')][_0x65a7('0x59')]['length']){for(var _0x5caef3=0x0;_0x5caef3<_0xbf8ccd['body']['attachments'][_0x65a7('0x37')];_0x5caef3+=0x1){_0xbf8ccd[_0x65a7('0x49')]['attachments'][_0x5caef3]={'filename':_0xbf8ccd['body'][_0x65a7('0x59')][_0x5caef3][_0x65a7('0x2b')],'path':path[_0x65a7('0x5a')](config[_0x65a7('0x5b')],_0x65a7('0x5c'),_0xbf8ccd[_0x65a7('0x49')][_0x65a7('0x59')][_0x5caef3][_0x65a7('0x5d')])};}}_0x4d4ba2={'account':_0x365415,'message':_0xbf8ccd[_0x65a7('0x49')]};return;})[_0x65a7('0x14')](function(){if(_0x4e2f52['List']){if(_0x4e2f52[_0x65a7('0x5e')][_0x65a7('0x52')][_0x65a7('0x37')]){return _0x4e2f52[_0x65a7('0x5e')][_0x65a7('0x52')][0x0];}else{return db['CmContact'][_0x65a7('0x4b')](_[_0x65a7('0xc')](_0xbf8ccd[_0x65a7('0x49')],{'firstName':_0xbf8ccd[_0x65a7('0x49')]['to'],'email':_0xbf8ccd['body']['to'],'phone':_0xbf8ccd[_0x65a7('0x49')]['to'],'ListId':_0x4e2f52[_0x65a7('0x5f')]}));}}else{throw new Error(_0x65a7('0x60'));}})[_0x65a7('0x14')](function(){if(_0x4d4ba2){return respondWithRpcPromise(_0x65a7('0x61'),_0x65a7('0x62'),_0x4d4ba2,client9003)[_0x65a7('0x14')](function(_0x3b7537){return _0x165898[_0x65a7('0x26')]({'read':!![],'messageId':_0x3b7537[_0x65a7('0x63')],'sentAt':moment()[_0x65a7('0x64')](_0x65a7('0x65'))});})[_0x65a7('0x1e')](function(_0xb1a570){logger[_0x65a7('0x1b')]('%s',JSON[_0x65a7('0x1a')](_0xb1a570));return _0x165898;});}return _0x165898;});}return _0x165898;}})[_0x65a7('0x14')](respondWithResult(_0x3d3029,0xc9))['catch'](handleError(_0x3d3029,null));};exports[_0x65a7('0x66')]=function(_0x3d8593,_0x31b204){var _0xbc9c96={'agent':{},'channel':'mail'};if(_0x3d8593[_0x65a7('0x49')]['id']){delete _0x3d8593[_0x65a7('0x49')]['id'];}_0x3d8593[_0x65a7('0x49')][_0x65a7('0x67')]=!![];_0x3d8593[_0x65a7('0x49')][_0x65a7('0x68')]=moment()['format'](_0x65a7('0x65'));_0x3d8593[_0x65a7('0x49')][_0x65a7('0x69')]=_0x3d8593[_0x65a7('0x49')][_0x65a7('0x69')]||_0x3d8593[_0x65a7('0x6a')]['id'];_0xbc9c96[_0x65a7('0x6b')]['id']=_0x3d8593[_0x65a7('0x49')][_0x65a7('0x69')];return db['MailMessage']['find']({'where':{'id':_0x3d8593[_0x65a7('0x44')]['id'],'UserId':null}})[_0x65a7('0x14')](handleEntityNotFound(_0x31b204,null))[_0x65a7('0x14')](saveUpdates(_0x3d8593['body'],null))[_0x65a7('0x14')](function(_0x2e008e){if(_0x2e008e){_0xbc9c96[_0x65a7('0x1d')]=_0x2e008e['get']({'plain':!![]});return db[_0x65a7('0x6c')][_0x65a7('0x48')]({'where':{'id':_0x2e008e[_0x65a7('0x6d')]}});}return null;})[_0x65a7('0x14')](handleEntityNotFound(_0x31b204,null))[_0x65a7('0x14')](function(_0x4a9827){if(_0x4a9827){return _0x4a9827[_0x65a7('0x26')]({'UserId':_0x3d8593['body'][_0x65a7('0x69')],'read1stAt':_[_0x65a7('0x6e')](_0x4a9827['read1stAt'])?moment()['format'](_0x65a7('0x65')):undefined});}return null;})[_0x65a7('0x14')](function(_0x41546b){if(_0x41546b){_0xbc9c96['interaction']=_0x41546b[_0x65a7('0x6f')]({'plain':!![]});interaction_log[_0x65a7('0x15')](_0x65a7('0x70'),_0x3d8593[_0x65a7('0x6a')]['id'],_0x3d8593[_0x65a7('0x6a')][_0x65a7('0x2b')],_0x3d8593['user'][_0x65a7('0x71')],_0xbc9c96[_0x65a7('0x72')]['id'],_0x3d8593[_0x65a7('0x49')]?JSON[_0x65a7('0x1a')](_0x3d8593[_0x65a7('0x49')]):'null');return respondWithRpcPromise(_0x65a7('0x73'),_0x65a7('0x74'),_0xbc9c96);}return null;})['then'](function(_0x129793){var _0x220667=_0x65a7('0x75')+_0x129793[_0x65a7('0x1d')][_0x65a7('0x76')];return db[_0x65a7('0x77')]['query'](_0x220667,{'type':db[_0x65a7('0x78')]['QueryTypes']['SELECT'],'raw':!![]})['then'](function(_0x299e65){return _0x299e65;});})[_0x65a7('0x14')](function(_0x3c20dd){if(_0x3c20dd){_0xbc9c96[_0x65a7('0x1d')][_0x65a7('0x79')]=_0x3c20dd[0x0];if(!_0x3d8593[_0x65a7('0x49')][_0x65a7('0x69')])return;return db[_0x65a7('0x7a')][_0x65a7('0x48')]({'where':{'id':_0x3d8593[_0x65a7('0x49')][_0x65a7('0x69')],'role':_0x65a7('0x6b')},'attributes':['id',_0x65a7('0x2b'),_0x65a7('0x7b'),_0x65a7('0x7c'),_0x65a7('0x7d')],'raw':!![]});}return null;})['then'](function(_0x105232){if(!_0x105232)return null;_0xbc9c96[_0x65a7('0x1d')][_0x65a7('0x6b')]=_0x105232;return _0xbc9c96;})[_0x65a7('0x14')](function(_0x5609e9){if(_0x5609e9){if(_0x3d8593[_0x65a7('0x49')]['manual']){_0xbc9c96[_0x65a7('0x1d')]['interface']=util[_0x65a7('0x64')]('SIP/%s',_0x3d8593['user'][_0x65a7('0x2b')]);_0xbc9c96[_0x65a7('0x1d')][_0x65a7('0x7e')]=_0xbc9c96[_0x65a7('0x7e')];_0xbc9c96[_0x65a7('0x1d')][_0x65a7('0x7f')]=_0xbc9c96[_0x65a7('0x7e')];_0xbc9c96[_0x65a7('0x1d')][_0x65a7('0x80')]=_0x65a7('0x66');_0xbc9c96['message'][_0x65a7('0x49')]=htmlToText[_0x65a7('0x81')](_0xbc9c96[_0x65a7('0x1d')]['body']);return respondWithRpcPromise(_0x65a7('0x82'),'EventManager',{'event':'acceptmessage','message':_0xbc9c96[_0x65a7('0x1d')]},client9002)['then'](function(){return _0xbc9c96;});}return _0xbc9c96;}return null;})[_0x65a7('0x14')](respondWithResult(_0x31b204,null))['catch'](handleError(_0x31b204,null));};exports['reject']=function(_0x46e9eb,_0x33aef2){var _0x4613dc={'agent':{},'channel':'mail'};if(_0x46e9eb[_0x65a7('0x49')]['id']){delete _0x46e9eb[_0x65a7('0x49')]['id'];}_0x46e9eb['body'][_0x65a7('0x69')]=_0x46e9eb['body'][_0x65a7('0x69')]||_0x46e9eb[_0x65a7('0x6a')]['id'];_0x4613dc[_0x65a7('0x6b')]['id']=_0x46e9eb['body'][_0x65a7('0x69')];return db[_0x65a7('0x40')][_0x65a7('0x48')]({'where':{'id':_0x46e9eb[_0x65a7('0x44')]['id'],'UserId':null}})[_0x65a7('0x14')](handleEntityNotFound(_0x33aef2,null))[_0x65a7('0x14')](function(_0x5f1bec){if(_0x5f1bec){_0x4613dc[_0x65a7('0x1d')]=_0x5f1bec[_0x65a7('0x6f')]({'plain':!![]});return db[_0x65a7('0x6c')][_0x65a7('0x48')]({'where':{'id':_0x5f1bec[_0x65a7('0x6d')]}});}return null;})[_0x65a7('0x14')](handleEntityNotFound(_0x33aef2,null))[_0x65a7('0x14')](function(_0x243b32){if(_0x243b32){_0x4613dc[_0x65a7('0x72')]=_0x243b32[_0x65a7('0x6f')]({'plain':!![]});interaction_log[_0x65a7('0x15')](_0x65a7('0x83'),_0x46e9eb[_0x65a7('0x6a')]['id'],_0x46e9eb[_0x65a7('0x6a')]['name'],_0x46e9eb[_0x65a7('0x6a')][_0x65a7('0x71')],_0x4613dc[_0x65a7('0x72')]['id'],_0x46e9eb['body']?JSON['stringify'](_0x46e9eb['body']):_0x65a7('0x84'));return respondWithRpcPromise('RejectMessage',_0x65a7('0x85'),_0x4613dc);}return null;})['then'](function(_0x1472fd){var _0x2f6aa8=_0x65a7('0x75')+_0x1472fd['message'][_0x65a7('0x76')];return db[_0x65a7('0x77')]['query'](_0x2f6aa8,{'type':db[_0x65a7('0x78')]['QueryTypes']['SELECT'],'raw':!![]})[_0x65a7('0x14')](function(_0x1f073f){return _0x1f073f;});})[_0x65a7('0x14')](function(_0x1f329d){if(_0x1f329d){_0x4613dc['message']['contact']=_0x1f329d[0x0];if(!_0x46e9eb['body'][_0x65a7('0x69')])return;return db['User'][_0x65a7('0x48')]({'where':{'id':_0x46e9eb['body']['UserId'],'role':'agent'},'attributes':['id','name',_0x65a7('0x7b'),_0x65a7('0x7c'),_0x65a7('0x7d')],'raw':!![]});}return null;})[_0x65a7('0x14')](function(_0x418ef8){if(!_0x418ef8)return null;_0x4613dc[_0x65a7('0x1d')][_0x65a7('0x6b')]=_0x418ef8;return _0x4613dc;})[_0x65a7('0x14')](function(_0xb6df7c){if(_0xb6df7c){_0xb6df7c[_0x65a7('0x1d')]['interface']=util['format'](_0x65a7('0x86'),_0x46e9eb[_0x65a7('0x6a')][_0x65a7('0x2b')]);_0xb6df7c[_0x65a7('0x1d')][_0x65a7('0x7e')]=_0x4613dc['channel'];_0xb6df7c['message'][_0x65a7('0x7f')]=_0x4613dc[_0x65a7('0x7e')];_0xb6df7c[_0x65a7('0x1d')][_0x65a7('0x80')]=_0x65a7('0x87');_0xb6df7c[_0x65a7('0x1d')][_0x65a7('0x49')]=htmlToText[_0x65a7('0x81')](_0x4613dc[_0x65a7('0x1d')][_0x65a7('0x49')]);respondWithRpcPromise(_0x65a7('0x82'),_0x65a7('0x82'),{'event':_0x65a7('0x88'),'message':_0xb6df7c['message']},client9002);return _0x4613dc;}return null;})[_0x65a7('0x14')](respondWithResult(_0x33aef2,null))['catch'](handleError(_0x33aef2,null));};exports[_0x65a7('0x89')]=function(_0x311c84,_0xdacbf4){var _0x5c816f=moment()['unix']()[_0x65a7('0x8a')]();var _0x5b23f4=path[_0x65a7('0x5a')](config[_0x65a7('0x5b')],'server',_0x65a7('0x8b'),_0x65a7('0x8c'));var _0x4c98f4=path['join'](config[_0x65a7('0x5b')],_0x65a7('0x8d'),_0x65a7('0x8b'),'attachments');var _0x14bafd=util[_0x65a7('0x64')](_0x65a7('0x8e'),_0x5c816f);return db[_0x65a7('0x40')]['find']({'where':{'id':_0x311c84[_0x65a7('0x44')]['id']},'attributes':['id',_0x65a7('0x49'),_0x65a7('0x8f'),'to','cc',_0x65a7('0x90'),'subject',_0x65a7('0x91')],'include':_0x311c84[_0x65a7('0x32')]['attachments']?[{'model':db[_0x65a7('0x92')],'as':_0x65a7('0x93')}]:undefined})[_0x65a7('0x14')](handleEntityNotFound(_0xdacbf4,null))[_0x65a7('0x14')](function(_0x16ae51){if(_0x16ae51){var _0xfda4be=_0x16ae51;var _0x4d8aa4={'from':_0xfda4be[_0x65a7('0x8f')],'to':_0xfda4be['to'],'subject':_0xfda4be[_0x65a7('0x94')],'html':htmlEntities[_0x65a7('0x95')](_0xfda4be[_0x65a7('0x49')]),'headers':{'Date':moment(_0xfda4be[_0x65a7('0x91')])[_0x65a7('0x64')](_0x65a7('0x96'))},'attachments':[]};if(_0x16ae51['cc']){_0x4d8aa4[_0x65a7('0x97')]['Cc']=_0x16ae51['cc'];}if(_0x16ae51[_0x65a7('0x90')]){_0x4d8aa4[_0x65a7('0x97')]['Bcc']=_0x16ae51[_0x65a7('0x90')];}return new BPromise(function(_0x1e2206,_0x130b9a){if(_0x16ae51[_0x65a7('0x93')]){for(var _0x2be09a=0x0;_0x2be09a<_0x16ae51[_0x65a7('0x93')][_0x65a7('0x37')];_0x2be09a++){var _0x2f6a6b=_0x16ae51['Attachments'][_0x2be09a];var _0x550e0a=path['join'](_0x4c98f4,_0x2f6a6b[_0x65a7('0x5d')]);if(fs[_0x65a7('0x98')](_0x550e0a)){_0x4d8aa4['attachments'][_0x65a7('0x99')]({'name':_0x2f6a6b[_0x65a7('0x2b')],'contentType':_0x2f6a6b[_0x65a7('0x9a')],'data':fs[_0x65a7('0x9b')](_0x550e0a)});}}}emlformat[_0x65a7('0x9c')](_0x4d8aa4,function(_0x164029,_0x4fdc70){if(_0x164029)return _0x130b9a(_0x164029);fs['writeFileSync'](path[_0x65a7('0x5a')](_0x5b23f4,_0x14bafd),_0x4fdc70);return _0x1e2206(_0x4fdc70);});});}})[_0x65a7('0x14')](function(_0x4e7459){if(_0x4e7459){return _0xdacbf4['download'](path[_0x65a7('0x5a')](_0x5b23f4,_0x14bafd),_0x14bafd,function(_0x386a17){if(!_0x386a17)fs[_0x65a7('0x9d')](path['join'](_0x5b23f4,_0x14bafd));});}})[_0x65a7('0x1e')](handleError(_0xdacbf4,null));};
\ No newline at end of file