Built motion from commit 3c2ce842.|2.6.31
[motion2.git] / server / api / mailMessage / mailMessage.controller.js
index c895df8..4a43a54 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xf734=['fullname','email','internal','manual','interface','SIP/%s','channel','motionChannel','event','fromString','acceptmessage','mail','[MAILMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','rejectMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','contact','EventManager','download','unix','toString','files','tmp','server','message-%s.eml','bcc','subject','createdAt','Attachment','Attachments','from','decode','headers','Bcc','existsSync','readFileSync','writeFileSync','unlinkSync','eml-format','moment','bluebird','util','path','ioredis','../../components/parsers/qs','api','../../config/logger','mail-interactions','../../config/environment','../../mysqldb','redis','defaults','localhost','./mailMessage.socket','register','client','http','request','info','request\x20sent','debug','MailMessage,\x20%s,\x20%s,\x20%s','error','code','MailMessage,\x20%s,\x20%s','message','result','status','offset','undefined','limit','count','set','Content-Range','json','update','then','destroy','end','name','send','index','map','MailMessage','rawAttributes','fieldName','type','key','query','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','includeAll','include','findAll','rows','catch','show','params','keys','find','body','describe','create','direction','out','secret','split','findOne','MailAccountId','CmList','List','CmContact','Contacts','updatedAt','DESC','MailServerOut','Smtp','CloudProvider','getSmtpOptions','attachments','join','root','basename','ListId','List\x20not\x20found','SendMail','format','accept','read','UserId','agent','get','MailInteraction','MailInteractionId','isNil','read1stAt','YYYY-MM-DD\x20HH:mm:ss','interaction','user','role','stringify','null','acceptMessage','ContactId','Sequelize','QueryTypes','SELECT','User'];(function(_0xfa44b8,_0x3e6c66){var _0x20dcad=function(_0x19c420){while(--_0x19c420){_0xfa44b8['push'](_0xfa44b8['shift']());}};_0x20dcad(++_0x3e6c66);}(_0xf734,0x16a));var _0x4f73=function(_0x132979,_0x49d6ae){_0x132979=_0x132979-0x0;var _0xf97fa0=_0xf734[_0x132979];return _0xf97fa0;};'use strict';var emlformat=require(_0x4f73('0x0'));var moment=require(_0x4f73('0x1'));var BPromise=require(_0x4f73('0x2'));var util=require(_0x4f73('0x3'));var path=require(_0x4f73('0x4'));var fs=require('fs');var _=require('lodash');var Redis=require(_0x4f73('0x5'));var htmlToText=require('html-to-text');var qs=require(_0x4f73('0x6'));var logger=require('../../config/logger')(_0x4f73('0x7'));var interaction_log=require(_0x4f73('0x8'))(_0x4f73('0x9'));var config=require(_0x4f73('0xa'));var db=require(_0x4f73('0xb'))['db'];config[_0x4f73('0xc')]=_[_0x4f73('0xd')](config[_0x4f73('0xc')],{'host':_0x4f73('0xe'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x4f73('0xc')]));var htmlEntities=require('html-entities');require(_0x4f73('0xf'))[_0x4f73('0x10')](socket);var jayson=require('jayson/promise');var client=jayson[_0x4f73('0x11')]['http']({'port':0x232c});var client9003=jayson[_0x4f73('0x11')][_0x4f73('0x12')]({'port':0x232b});var client9002=jayson['client'][_0x4f73('0x12')]({'port':0x232a});function respondWithRpcPromise(_0x2f6a85,_0xc15b46,_0x15c3b7,_0x238843){return new BPromise(function(_0x3bba77,_0x1f7dbe){var _0x29e71e=_0x238843||client;return _0x29e71e[_0x4f73('0x13')](_0x2f6a85,_0x15c3b7)['then'](function(_0x34a3ca){logger[_0x4f73('0x14')]('MailMessage,\x20%s,\x20%s',_0xc15b46,_0x4f73('0x15'));logger[_0x4f73('0x16')](_0x4f73('0x17'),_0xc15b46,'request\x20sent',JSON['stringify'](_0x34a3ca));if(_0x34a3ca[_0x4f73('0x18')]){if(_0x34a3ca[_0x4f73('0x18')][_0x4f73('0x19')]===0x1f4){logger[_0x4f73('0x18')](_0x4f73('0x1a'),_0xc15b46,_0x34a3ca[_0x4f73('0x18')][_0x4f73('0x1b')]);return _0x1f7dbe(_0x34a3ca[_0x4f73('0x18')][_0x4f73('0x1b')]);}logger['error']('MailMessage,\x20%s,\x20%s',_0xc15b46,_0x34a3ca[_0x4f73('0x18')]['message']);return _0x3bba77(_0x34a3ca[_0x4f73('0x18')][_0x4f73('0x1b')]);}else{logger['info'](_0x4f73('0x1a'),_0xc15b46,_0x4f73('0x15'));_0x3bba77(_0x34a3ca[_0x4f73('0x1c')][_0x4f73('0x1b')]);}})['catch'](function(_0xe28367){logger[_0x4f73('0x18')](_0x4f73('0x1a'),_0xc15b46,_0xe28367);_0x1f7dbe(_0xe28367);});});}function respondWithResult(_0x44615c,_0x165d14){_0x165d14=_0x165d14||0xc8;return function(_0x42213a){if(_0x42213a){return _0x44615c[_0x4f73('0x1d')](_0x165d14)['json'](_0x42213a);}};}function respondWithFilteredResult(_0x40303d,_0xa0b221){return function(_0x1058ef){if(_0x1058ef){var _0x3f6c97=typeof _0xa0b221[_0x4f73('0x1e')]===_0x4f73('0x1f')&&typeof _0xa0b221[_0x4f73('0x20')]===_0x4f73('0x1f');var _0x3dd9b1=_0x1058ef[_0x4f73('0x21')];var _0xaf6864=_0x3f6c97?0x0:_0xa0b221['offset'];var _0xee5cd2=_0x3f6c97?_0x1058ef['count']:_0xa0b221[_0x4f73('0x1e')]+_0xa0b221[_0x4f73('0x20')];var _0x1ef623;if(_0xee5cd2>=_0x3dd9b1){_0xee5cd2=_0x3dd9b1;_0x1ef623=0xc8;}else{_0x1ef623=0xce;}_0x40303d['status'](_0x1ef623);return _0x40303d[_0x4f73('0x22')](_0x4f73('0x23'),_0xaf6864+'-'+_0xee5cd2+'/'+_0x3dd9b1)[_0x4f73('0x24')](_0x1058ef);}return null;};}function saveUpdates(_0x72771d){return function(_0x3fac0c){if(_0x3fac0c){return _0x3fac0c[_0x4f73('0x25')](_0x72771d)[_0x4f73('0x26')](function(_0x2f3c84){return _0x2f3c84;});}return null;};}function removeEntity(_0x4ced5e){return function(_0x420ff5){if(_0x420ff5){return _0x420ff5[_0x4f73('0x27')]()[_0x4f73('0x26')](function(){_0x4ced5e[_0x4f73('0x1d')](0xcc)[_0x4f73('0x28')]();});}};}function handleEntityNotFound(_0x9b37e1){return function(_0x26a2da){if(!_0x26a2da){_0x9b37e1['sendStatus'](0x194);}return _0x26a2da;};}function handleError(_0x37cc50,_0x33e5e5){_0x33e5e5=_0x33e5e5||0x1f4;return function(_0xc54ec5){logger[_0x4f73('0x18')](_0xc54ec5['stack']);if(_0xc54ec5[_0x4f73('0x29')]){delete _0xc54ec5[_0x4f73('0x29')];}_0x37cc50[_0x4f73('0x1d')](_0x33e5e5)[_0x4f73('0x2a')](_0xc54ec5);};}exports[_0x4f73('0x2b')]=function(_0x53176c,_0xbd66a7){var _0x220f82={},_0xacb95f={},_0x3ba980={'count':0x0,'rows':[]};var _0x30d312=_[_0x4f73('0x2c')](db[_0x4f73('0x2d')][_0x4f73('0x2e')],function(_0x3b7c5e){return{'name':_0x3b7c5e[_0x4f73('0x2f')],'type':_0x3b7c5e[_0x4f73('0x30')][_0x4f73('0x31')]};});_0xacb95f['model']=_[_0x4f73('0x2c')](_0x30d312,'name');_0xacb95f[_0x4f73('0x32')]=_['keys'](_0x53176c['query']);_0xacb95f[_0x4f73('0x33')]=_[_0x4f73('0x34')](_0xacb95f[_0x4f73('0x35')],_0xacb95f[_0x4f73('0x32')]);_0x220f82[_0x4f73('0x36')]=_[_0x4f73('0x34')](_0xacb95f[_0x4f73('0x35')],qs[_0x4f73('0x37')](_0x53176c[_0x4f73('0x32')]['fields']));_0x220f82['attributes']=_0x220f82[_0x4f73('0x36')][_0x4f73('0x38')]?_0x220f82[_0x4f73('0x36')]:_0xacb95f[_0x4f73('0x35')];if(!_0x53176c[_0x4f73('0x32')][_0x4f73('0x39')](_0x4f73('0x3a'))){_0x220f82[_0x4f73('0x20')]=qs['limit'](_0x53176c['query'][_0x4f73('0x20')]);_0x220f82[_0x4f73('0x1e')]=qs[_0x4f73('0x1e')](_0x53176c['query'][_0x4f73('0x1e')]);}_0x220f82[_0x4f73('0x3b')]=qs['sort'](_0x53176c[_0x4f73('0x32')][_0x4f73('0x3c')]);_0x220f82[_0x4f73('0x3d')]=qs[_0x4f73('0x33')](_[_0x4f73('0x3e')](_0x53176c[_0x4f73('0x32')],_0xacb95f[_0x4f73('0x33')]),_0x30d312);if(_0x53176c['query'][_0x4f73('0x3f')]){_0x220f82[_0x4f73('0x3d')]=_[_0x4f73('0x40')](_0x220f82[_0x4f73('0x3d')],{'$or':_['map'](_0x30d312,function(_0x330b68){if(_0x330b68[_0x4f73('0x30')]!==_0x4f73('0x41')){var _0x23ba31={};_0x23ba31[_0x330b68[_0x4f73('0x29')]]={'$like':'%'+_0x53176c['query'][_0x4f73('0x3f')]+'%'};return _0x23ba31;}})});}_0x220f82=_['merge']({},_0x220f82,_0x53176c[_0x4f73('0x42')]);var _0x4b60f3={'where':_0x220f82[_0x4f73('0x3d')]};return db[_0x4f73('0x2d')]['count'](_0x4b60f3)[_0x4f73('0x26')](function(_0x53d3d5){_0x3ba980[_0x4f73('0x21')]=_0x53d3d5;if(_0x53176c[_0x4f73('0x32')][_0x4f73('0x43')]){_0x220f82[_0x4f73('0x44')]=[{'all':!![]}];}return db[_0x4f73('0x2d')][_0x4f73('0x45')](_0x220f82);})[_0x4f73('0x26')](function(_0x583527){_0x3ba980[_0x4f73('0x46')]=_0x583527;return _0x3ba980;})[_0x4f73('0x26')](respondWithFilteredResult(_0xbd66a7,_0x220f82))[_0x4f73('0x47')](handleError(_0xbd66a7,null));};exports[_0x4f73('0x48')]=function(_0x35b319,_0x1c1897){var _0x2810bf={'raw':!![],'where':{'id':_0x35b319[_0x4f73('0x49')]['id']}},_0x2a44e7={};_0x2a44e7[_0x4f73('0x35')]=_[_0x4f73('0x4a')](db[_0x4f73('0x2d')]['rawAttributes']);_0x2a44e7[_0x4f73('0x32')]=_[_0x4f73('0x4a')](_0x35b319[_0x4f73('0x32')]);_0x2a44e7['filters']=_[_0x4f73('0x34')](_0x2a44e7['model'],_0x2a44e7['query']);_0x2810bf[_0x4f73('0x36')]=_[_0x4f73('0x34')](_0x2a44e7[_0x4f73('0x35')],qs[_0x4f73('0x37')](_0x35b319[_0x4f73('0x32')][_0x4f73('0x37')]));_0x2810bf['attributes']=_0x2810bf[_0x4f73('0x36')][_0x4f73('0x38')]?_0x2810bf[_0x4f73('0x36')]:_0x2a44e7[_0x4f73('0x35')];if(_0x35b319[_0x4f73('0x32')][_0x4f73('0x43')]){_0x2810bf[_0x4f73('0x44')]=[{'all':!![]}];}_0x2810bf=_[_0x4f73('0x40')]({},_0x2810bf,_0x35b319['options']);return db[_0x4f73('0x2d')][_0x4f73('0x4b')](_0x2810bf)['then'](handleEntityNotFound(_0x1c1897,null))['then'](respondWithResult(_0x1c1897,null))[_0x4f73('0x47')](handleError(_0x1c1897,null));};exports[_0x4f73('0x25')]=function(_0x29b527,_0x2804fa){if(_0x29b527['body']['id']){delete _0x29b527['body']['id'];}return db['MailMessage'][_0x4f73('0x4b')]({'where':{'id':_0x29b527[_0x4f73('0x49')]['id']}})[_0x4f73('0x26')](handleEntityNotFound(_0x2804fa,null))[_0x4f73('0x26')](saveUpdates(_0x29b527[_0x4f73('0x4c')],null))[_0x4f73('0x26')](respondWithResult(_0x2804fa,null))[_0x4f73('0x47')](handleError(_0x2804fa,null));};exports[_0x4f73('0x27')]=function(_0x42b0e9,_0x3bd9ec){return db[_0x4f73('0x2d')][_0x4f73('0x4b')]({'where':{'id':_0x42b0e9[_0x4f73('0x49')]['id']}})['then'](handleEntityNotFound(_0x3bd9ec,null))[_0x4f73('0x26')](removeEntity(_0x3bd9ec,null))[_0x4f73('0x47')](handleError(_0x3bd9ec,null));};exports[_0x4f73('0x4d')]=function(_0x4822b4,_0x485935){return db[_0x4f73('0x2d')][_0x4f73('0x4d')]()[_0x4f73('0x26')](respondWithResult(_0x485935,null))[_0x4f73('0x47')](handleError(_0x485935,null));};exports[_0x4f73('0x4e')]=function(_0x5ee115,_0x2d954b){return db[_0x4f73('0x2d')][_0x4f73('0x4e')](_0x5ee115['body'])[_0x4f73('0x26')](function(_0x5d0288){if(_0x5d0288){if(_0x5d0288[_0x4f73('0x4f')]===_0x4f73('0x50')&&!_0x5d0288[_0x4f73('0x51')]){var _0x11475f,_0x425af4,_0x24503a;if(_0x5ee115[_0x4f73('0x4c')]['to']){_0x425af4=_0x5ee115[_0x4f73('0x4c')]['to'][_0x4f73('0x52')](',')[0x0];}return db['MailAccount'][_0x4f73('0x53')]({'where':{'id':_0x5d0288[_0x4f73('0x54')]},'include':[{'model':db[_0x4f73('0x55')],'as':_0x4f73('0x56'),'include':[{'model':db[_0x4f73('0x57')],'as':_0x4f73('0x58'),'where':{'email':_0x425af4},'limit':0x1,'order':[[_0x4f73('0x59'),_0x4f73('0x5a')]]}]},{'model':db[_0x4f73('0x5b')],'as':_0x4f73('0x5c'),'raw':!![],'include':[{'model':db[_0x4f73('0x5d')],'as':_0x4f73('0x5d'),'raw':!![]}]}]})['then'](function(_0x5add97){_0x11475f=_0x5add97;if(!_0x11475f||!_0x11475f[_0x4f73('0x5c')])return;var _0x256294=_0x11475f[_0x4f73('0x5e')]();if(_0x5ee115[_0x4f73('0x4c')][_0x4f73('0x5f')]&&_0x5ee115[_0x4f73('0x4c')][_0x4f73('0x5f')][_0x4f73('0x38')]){for(var _0x24a8f9=0x0;_0x24a8f9<_0x5ee115[_0x4f73('0x4c')]['attachments'][_0x4f73('0x38')];_0x24a8f9+=0x1){_0x5ee115['body'][_0x4f73('0x5f')][_0x24a8f9]={'filename':_0x5ee115[_0x4f73('0x4c')][_0x4f73('0x5f')][_0x24a8f9][_0x4f73('0x29')],'path':path[_0x4f73('0x60')](config[_0x4f73('0x61')],'server/files/attachments',_0x5ee115[_0x4f73('0x4c')]['attachments'][_0x24a8f9][_0x4f73('0x62')])};}}_0x24503a={'account':_0x256294,'message':_0x5ee115[_0x4f73('0x4c')]};return;})[_0x4f73('0x26')](function(){if(_0x11475f['List']){if(_0x11475f[_0x4f73('0x56')][_0x4f73('0x58')][_0x4f73('0x38')]){return _0x11475f['List'][_0x4f73('0x58')][0x0];}else{return db[_0x4f73('0x57')][_0x4f73('0x4e')](_[_0x4f73('0xd')](_0x5ee115[_0x4f73('0x4c')],{'firstName':_0x5ee115[_0x4f73('0x4c')]['to'],'email':_0x5ee115[_0x4f73('0x4c')]['to'],'phone':_0x5ee115['body']['to'],'ListId':_0x11475f[_0x4f73('0x63')]}));}}else{throw new Error(_0x4f73('0x64'));}})[_0x4f73('0x26')](function(){if(_0x24503a){return respondWithRpcPromise(_0x4f73('0x65'),'sendMail',_0x24503a,client9003)[_0x4f73('0x26')](function(_0x543957){return _0x5d0288[_0x4f73('0x25')]({'read':!![],'messageId':_0x543957['messageId'],'sentAt':moment()[_0x4f73('0x66')]('YYYY-MM-DD\x20HH:mm:ss')});})['catch'](function(_0x596ebc){logger[_0x4f73('0x18')]('%s',JSON['stringify'](_0x596ebc));return _0x5d0288;});}return _0x5d0288;});}return _0x5d0288;}})[_0x4f73('0x26')](respondWithResult(_0x2d954b,0xc9))[_0x4f73('0x47')](handleError(_0x2d954b,null));};exports[_0x4f73('0x67')]=function(_0x31bd3d,_0xc55ca9){var _0x17a4c8={'agent':{},'channel':'mail'};if(_0x31bd3d[_0x4f73('0x4c')]['id']){delete _0x31bd3d[_0x4f73('0x4c')]['id'];}_0x31bd3d[_0x4f73('0x4c')][_0x4f73('0x68')]=!![];_0x31bd3d[_0x4f73('0x4c')]['readAt']=moment()[_0x4f73('0x66')]('YYYY-MM-DD\x20HH:mm:ss');_0x31bd3d[_0x4f73('0x4c')][_0x4f73('0x69')]=_0x31bd3d['body'][_0x4f73('0x69')]||_0x31bd3d['user']['id'];_0x17a4c8[_0x4f73('0x6a')]['id']=_0x31bd3d[_0x4f73('0x4c')]['UserId'];return db[_0x4f73('0x2d')][_0x4f73('0x4b')]({'where':{'id':_0x31bd3d[_0x4f73('0x49')]['id'],'UserId':null}})[_0x4f73('0x26')](handleEntityNotFound(_0xc55ca9,null))[_0x4f73('0x26')](saveUpdates(_0x31bd3d['body'],null))[_0x4f73('0x26')](function(_0x3db287){if(_0x3db287){_0x17a4c8[_0x4f73('0x1b')]=_0x3db287[_0x4f73('0x6b')]({'plain':!![]});return db[_0x4f73('0x6c')][_0x4f73('0x4b')]({'where':{'id':_0x3db287[_0x4f73('0x6d')]}});}return null;})[_0x4f73('0x26')](handleEntityNotFound(_0xc55ca9,null))['then'](function(_0x541e31){if(_0x541e31){return _0x541e31[_0x4f73('0x25')]({'UserId':_0x31bd3d['body'][_0x4f73('0x69')],'read1stAt':_[_0x4f73('0x6e')](_0x541e31[_0x4f73('0x6f')])?moment()[_0x4f73('0x66')](_0x4f73('0x70')):undefined});}return null;})['then'](function(_0x283d62){if(_0x283d62){_0x17a4c8[_0x4f73('0x71')]=_0x283d62['get']({'plain':!![]});interaction_log[_0x4f73('0x14')]('[MAILMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x31bd3d[_0x4f73('0x72')]['id'],_0x31bd3d[_0x4f73('0x72')][_0x4f73('0x29')],_0x31bd3d[_0x4f73('0x72')][_0x4f73('0x73')],_0x17a4c8[_0x4f73('0x71')]['id'],_0x31bd3d[_0x4f73('0x4c')]?JSON[_0x4f73('0x74')](_0x31bd3d[_0x4f73('0x4c')]):_0x4f73('0x75'));return respondWithRpcPromise('AcceptMessage',_0x4f73('0x76'),_0x17a4c8);}return null;})[_0x4f73('0x26')](function(_0x4b1978){var _0x4c31f8='SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20'+_0x4b1978[_0x4f73('0x1b')][_0x4f73('0x77')];return db['sequelize'][_0x4f73('0x32')](_0x4c31f8,{'type':db[_0x4f73('0x78')][_0x4f73('0x79')][_0x4f73('0x7a')],'raw':!![]})[_0x4f73('0x26')](function(_0x51258d){return _0x51258d;});})[_0x4f73('0x26')](function(_0x592dc8){if(_0x592dc8){_0x17a4c8[_0x4f73('0x1b')]['contact']=_0x592dc8[0x0];if(!_0x31bd3d[_0x4f73('0x4c')][_0x4f73('0x69')])return;return db[_0x4f73('0x7b')][_0x4f73('0x4b')]({'where':{'id':_0x31bd3d[_0x4f73('0x4c')]['UserId'],'role':_0x4f73('0x6a')},'attributes':['id','name',_0x4f73('0x7c'),_0x4f73('0x7d'),_0x4f73('0x7e')],'raw':!![]});}return null;})[_0x4f73('0x26')](function(_0x54169f){if(!_0x54169f)return null;_0x17a4c8[_0x4f73('0x1b')][_0x4f73('0x6a')]=_0x54169f;return _0x17a4c8;})[_0x4f73('0x26')](function(_0xd0ed57){if(_0xd0ed57){if(_0x31bd3d[_0x4f73('0x4c')][_0x4f73('0x7f')]){_0x17a4c8[_0x4f73('0x1b')][_0x4f73('0x80')]=util[_0x4f73('0x66')](_0x4f73('0x81'),_0x31bd3d[_0x4f73('0x72')][_0x4f73('0x29')]);_0x17a4c8['message'][_0x4f73('0x82')]=_0x17a4c8[_0x4f73('0x82')];_0x17a4c8[_0x4f73('0x1b')][_0x4f73('0x83')]=_0x17a4c8[_0x4f73('0x82')];_0x17a4c8[_0x4f73('0x1b')][_0x4f73('0x84')]='accept';_0x17a4c8[_0x4f73('0x1b')]['body']=htmlToText[_0x4f73('0x85')](_0x17a4c8[_0x4f73('0x1b')][_0x4f73('0x4c')]);return respondWithRpcPromise('EventManager','EventManager',{'event':_0x4f73('0x86'),'message':_0x17a4c8[_0x4f73('0x1b')]},client9002)[_0x4f73('0x26')](function(){return _0x17a4c8;});}return _0x17a4c8;}return null;})['then'](respondWithResult(_0xc55ca9,null))[_0x4f73('0x47')](handleError(_0xc55ca9,null));};exports['reject']=function(_0x1af4d8,_0x4fb0a7){var _0x105e00={'agent':{},'channel':_0x4f73('0x87')};if(_0x1af4d8[_0x4f73('0x4c')]['id']){delete _0x1af4d8[_0x4f73('0x4c')]['id'];}_0x1af4d8['body'][_0x4f73('0x69')]=_0x1af4d8[_0x4f73('0x4c')][_0x4f73('0x69')]||_0x1af4d8[_0x4f73('0x72')]['id'];_0x105e00[_0x4f73('0x6a')]['id']=_0x1af4d8[_0x4f73('0x4c')]['UserId'];return db['MailMessage'][_0x4f73('0x4b')]({'where':{'id':_0x1af4d8[_0x4f73('0x49')]['id'],'UserId':null}})[_0x4f73('0x26')](handleEntityNotFound(_0x4fb0a7,null))[_0x4f73('0x26')](function(_0xc12767){if(_0xc12767){_0x105e00[_0x4f73('0x1b')]=_0xc12767[_0x4f73('0x6b')]({'plain':!![]});return db[_0x4f73('0x6c')]['find']({'where':{'id':_0xc12767[_0x4f73('0x6d')]}});}return null;})['then'](handleEntityNotFound(_0x4fb0a7,null))[_0x4f73('0x26')](function(_0x52865a){if(_0x52865a){_0x105e00[_0x4f73('0x71')]=_0x52865a[_0x4f73('0x6b')]({'plain':!![]});interaction_log['info'](_0x4f73('0x88'),_0x1af4d8[_0x4f73('0x72')]['id'],_0x1af4d8[_0x4f73('0x72')][_0x4f73('0x29')],_0x1af4d8['user'][_0x4f73('0x73')],_0x105e00[_0x4f73('0x71')]['id'],_0x1af4d8[_0x4f73('0x4c')]?JSON[_0x4f73('0x74')](_0x1af4d8['body']):'null');return respondWithRpcPromise(_0x4f73('0x89'),_0x4f73('0x8a'),_0x105e00);}return null;})[_0x4f73('0x26')](function(_0x97bf66){var _0x47769c=_0x4f73('0x8b')+_0x97bf66['message'][_0x4f73('0x77')];return db['sequelize']['query'](_0x47769c,{'type':db[_0x4f73('0x78')][_0x4f73('0x79')][_0x4f73('0x7a')],'raw':!![]})[_0x4f73('0x26')](function(_0x4c5228){return _0x4c5228;});})[_0x4f73('0x26')](function(_0x2837ff){if(_0x2837ff){_0x105e00['message'][_0x4f73('0x8c')]=_0x2837ff[0x0];if(!_0x1af4d8[_0x4f73('0x4c')][_0x4f73('0x69')])return;return db['User'][_0x4f73('0x4b')]({'where':{'id':_0x1af4d8[_0x4f73('0x4c')][_0x4f73('0x69')],'role':_0x4f73('0x6a')},'attributes':['id','name','fullname',_0x4f73('0x7d'),_0x4f73('0x7e')],'raw':!![]});}return null;})[_0x4f73('0x26')](function(_0x5646d9){if(!_0x5646d9)return null;_0x105e00['message'][_0x4f73('0x6a')]=_0x5646d9;return _0x105e00;})[_0x4f73('0x26')](function(_0x5c0fbe){if(_0x5c0fbe){_0x5c0fbe[_0x4f73('0x1b')][_0x4f73('0x80')]=util[_0x4f73('0x66')](_0x4f73('0x81'),_0x1af4d8[_0x4f73('0x72')]['name']);_0x5c0fbe[_0x4f73('0x1b')]['channel']=_0x105e00[_0x4f73('0x82')];_0x5c0fbe[_0x4f73('0x1b')][_0x4f73('0x83')]=_0x105e00[_0x4f73('0x82')];_0x5c0fbe['message'][_0x4f73('0x84')]='reject';_0x5c0fbe[_0x4f73('0x1b')][_0x4f73('0x4c')]=htmlToText[_0x4f73('0x85')](_0x105e00[_0x4f73('0x1b')][_0x4f73('0x4c')]);respondWithRpcPromise(_0x4f73('0x8d'),_0x4f73('0x8d'),{'event':'rejectmessage','message':_0x5c0fbe[_0x4f73('0x1b')]},client9002);return _0x105e00;}return null;})[_0x4f73('0x26')](respondWithResult(_0x4fb0a7,null))[_0x4f73('0x47')](handleError(_0x4fb0a7,null));};exports[_0x4f73('0x8e')]=function(_0x7e93d2,_0x27ad05){var _0xfa3bfc=moment()[_0x4f73('0x8f')]()[_0x4f73('0x90')]();var _0x19e036=path['join'](config[_0x4f73('0x61')],'server',_0x4f73('0x91'),_0x4f73('0x92'));var _0x2b94ee=path[_0x4f73('0x60')](config['root'],_0x4f73('0x93'),_0x4f73('0x91'),_0x4f73('0x5f'));var _0x4c0201=util['format'](_0x4f73('0x94'),_0xfa3bfc);return db['MailMessage'][_0x4f73('0x4b')]({'where':{'id':_0x7e93d2[_0x4f73('0x49')]['id']},'attributes':['id',_0x4f73('0x4c'),'from','to','cc',_0x4f73('0x95'),_0x4f73('0x96'),_0x4f73('0x97')],'include':_0x7e93d2[_0x4f73('0x32')][_0x4f73('0x5f')]?[{'model':db[_0x4f73('0x98')],'as':_0x4f73('0x99')}]:undefined})[_0x4f73('0x26')](handleEntityNotFound(_0x27ad05,null))[_0x4f73('0x26')](function(_0x557efd){if(_0x557efd){var _0x150bc4=_0x557efd;var _0x2deac0={'from':_0x150bc4[_0x4f73('0x9a')],'to':_0x150bc4['to'],'subject':_0x150bc4[_0x4f73('0x96')],'html':htmlEntities[_0x4f73('0x9b')](_0x150bc4[_0x4f73('0x4c')]),'headers':{'Date':moment(_0x150bc4[_0x4f73('0x97')])[_0x4f73('0x66')]('ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ')},'attachments':[]};if(_0x557efd['cc']){_0x2deac0[_0x4f73('0x9c')]['Cc']=_0x557efd['cc'];}if(_0x557efd['bcc']){_0x2deac0['headers'][_0x4f73('0x9d')]=_0x557efd[_0x4f73('0x95')];}return new BPromise(function(_0x2ef825,_0x16918a){if(_0x557efd[_0x4f73('0x99')]){for(var _0xa028cb=0x0;_0xa028cb<_0x557efd[_0x4f73('0x99')][_0x4f73('0x38')];_0xa028cb++){var _0x299642=_0x557efd[_0x4f73('0x99')][_0xa028cb];var _0x4e0810=path['join'](_0x2b94ee,_0x299642[_0x4f73('0x62')]);if(fs[_0x4f73('0x9e')](_0x4e0810)){_0x2deac0[_0x4f73('0x5f')]['push']({'name':_0x299642['name'],'contentType':_0x299642[_0x4f73('0x30')],'data':fs[_0x4f73('0x9f')](_0x4e0810)});}}}emlformat['build'](_0x2deac0,function(_0x12ba41,_0x2f575a){if(_0x12ba41)return _0x16918a(_0x12ba41);fs[_0x4f73('0xa0')](path[_0x4f73('0x60')](_0x19e036,_0x4c0201),_0x2f575a);return _0x2ef825(_0x2f575a);});});}})['then'](function(_0x35f456){if(_0x35f456){return _0x27ad05[_0x4f73('0x8e')](path['join'](_0x19e036,_0x4c0201),_0x4c0201,function(_0x399be6){if(!_0x399be6)fs[_0x4f73('0xa1')](path[_0x4f73('0x60')](_0x19e036,_0x4c0201));});}})[_0x4f73('0x47')](handleError(_0x27ad05,null));};
\ No newline at end of file
+var _0xc26a=['map','MailMessage','fieldName','type','key','model','query','keys','filters','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','filter','where','merge','VIRTUAL','includeAll','include','findAll','rows','show','params','options','find','body','destroy','describe','create','direction','out','secret','split','MailAccount','findOne','CmList','List','Contacts','updatedAt','DESC','MailServerOut','Smtp','CloudProvider','getSmtpOptions','attachments','join','root','basename','CmContact','ListId','List\x20not\x20found','SendMail','sendMail','messageId','format','YYYY-MM-DD\x20HH:mm:ss','accept','mail','acceptMessage','reject','UserId','user','agent','get','MailInteraction','MailInteractionId','interaction','[MAILMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','null','rejectMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','ContactId','sequelize','QueryTypes','contact','User','email','interface','channel','event','fromString','EventManager','rejectmessage','unix','toString','server','files','from','bcc','subject','createdAt','Attachment','Attachments','ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ','headers','Bcc','existsSync','push','readFileSync','writeFileSync','download','unlinkSync','moment','util','path','lodash','ioredis','html-to-text','../../components/interaction/service','../../components/parsers/qs','../../config/logger','api','../../mysqldb','redis','defaults','localhost','html-entities','./mailMessage.socket','register','jayson/promise','client','http','info','MailMessage,\x20%s,\x20%s','request\x20sent','debug','stringify','error','code','message','result','catch','status','json','offset','undefined','limit','count','set','Content-Range','update','then','end','stack','name','send','index'];(function(_0x5e9326,_0x28038a){var _0x3654b6=function(_0x43b044){while(--_0x43b044){_0x5e9326['push'](_0x5e9326['shift']());}};_0x3654b6(++_0x28038a);}(_0xc26a,0x103));var _0xac26=function(_0x1177d5,_0x22b649){_0x1177d5=_0x1177d5-0x0;var _0xc3ddc2=_0xc26a[_0x1177d5];return _0xc3ddc2;};'use strict';var emlformat=require('eml-format');var moment=require(_0xac26('0x0'));var util=require(_0xac26('0x1'));var path=require(_0xac26('0x2'));var fs=require('fs');var _=require(_0xac26('0x3'));var Redis=require(_0xac26('0x4'));var htmlToText=require(_0xac26('0x5'));var interactionService=require(_0xac26('0x6'));var qs=require(_0xac26('0x7'));var logger=require(_0xac26('0x8'))(_0xac26('0x9'));var interaction_log=require('../../config/logger')('mail-interactions');var config=require('../../config/environment');var db=require(_0xac26('0xa'))['db'];config[_0xac26('0xb')]=_[_0xac26('0xc')](config[_0xac26('0xb')],{'host':_0xac26('0xd'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xac26('0xb')]));var htmlEntities=require(_0xac26('0xe'));require(_0xac26('0xf'))[_0xac26('0x10')](socket);var jayson=require(_0xac26('0x11'));var client=jayson[_0xac26('0x12')]['http']({'port':0x232c});var client9003=jayson[_0xac26('0x12')][_0xac26('0x13')]({'port':0x232b});var client9002=jayson['client']['http']({'port':0x232a});function respondWithRpcPromise(_0x35602a,_0xa659e3,_0x4d4162,_0x425380){return new Promise(function(_0x27106e,_0x4a9c5d){var _0x8ef42d=_0x425380||client;return _0x8ef42d['request'](_0x35602a,_0x4d4162)['then'](function(_0x4cbfad){logger[_0xac26('0x14')](_0xac26('0x15'),_0xa659e3,_0xac26('0x16'));logger[_0xac26('0x17')]('MailMessage,\x20%s,\x20%s,\x20%s',_0xa659e3,_0xac26('0x16'),JSON[_0xac26('0x18')](_0x4cbfad));if(_0x4cbfad[_0xac26('0x19')]){if(_0x4cbfad['error'][_0xac26('0x1a')]===0x1f4){logger['error']('MailMessage,\x20%s,\x20%s',_0xa659e3,_0x4cbfad[_0xac26('0x19')]['message']);return _0x4a9c5d(_0x4cbfad['error'][_0xac26('0x1b')]);}logger['error'](_0xac26('0x15'),_0xa659e3,_0x4cbfad[_0xac26('0x19')][_0xac26('0x1b')]);return _0x27106e(_0x4cbfad[_0xac26('0x19')][_0xac26('0x1b')]);}else{logger[_0xac26('0x14')]('MailMessage,\x20%s,\x20%s',_0xa659e3,'request\x20sent');_0x27106e(_0x4cbfad[_0xac26('0x1c')][_0xac26('0x1b')]);}})[_0xac26('0x1d')](function(_0x2bd35f){logger[_0xac26('0x19')](_0xac26('0x15'),_0xa659e3,_0x2bd35f);_0x4a9c5d(_0x2bd35f);});});}function respondWithResult(_0x533cd6,_0x55c3ef){_0x55c3ef=_0x55c3ef||0xc8;return function(_0x27edd){if(_0x27edd){return _0x533cd6[_0xac26('0x1e')](_0x55c3ef)[_0xac26('0x1f')](_0x27edd);}};}function respondWithFilteredResult(_0x3f2219,_0x56e1f4){return function(_0x429c08){if(_0x429c08){var _0x17851c=typeof _0x56e1f4[_0xac26('0x20')]===_0xac26('0x21')&&typeof _0x56e1f4[_0xac26('0x22')]===_0xac26('0x21');var _0x50e88c=_0x429c08[_0xac26('0x23')];var _0x39f82b=_0x17851c?0x0:_0x56e1f4[_0xac26('0x20')];var _0x934c71=_0x17851c?_0x429c08[_0xac26('0x23')]:_0x56e1f4[_0xac26('0x20')]+_0x56e1f4[_0xac26('0x22')];var _0x280b97;if(_0x934c71>=_0x50e88c){_0x934c71=_0x50e88c;_0x280b97=0xc8;}else{_0x280b97=0xce;}_0x3f2219[_0xac26('0x1e')](_0x280b97);return _0x3f2219[_0xac26('0x24')](_0xac26('0x25'),_0x39f82b+'-'+_0x934c71+'/'+_0x50e88c)['json'](_0x429c08);}return null;};}function saveUpdates(_0x31aeed){return function(_0x537fd3){if(_0x537fd3){return _0x537fd3[_0xac26('0x26')](_0x31aeed)[_0xac26('0x27')](function(_0xbb652f){return _0xbb652f;});}return null;};}function removeEntity(_0x214f45){return function(_0x49a3a5){if(_0x49a3a5){return _0x49a3a5['destroy']()[_0xac26('0x27')](function(){_0x214f45[_0xac26('0x1e')](0xcc)[_0xac26('0x28')]();});}};}function handleEntityNotFound(_0x7dfa67){return function(_0x3b3fef){if(!_0x3b3fef){_0x7dfa67['sendStatus'](0x194);}return _0x3b3fef;};}function handleError(_0x26ec81,_0x521c98){_0x521c98=_0x521c98||0x1f4;return function(_0x5c6662){logger[_0xac26('0x19')](_0x5c6662[_0xac26('0x29')]);if(_0x5c6662[_0xac26('0x2a')]){delete _0x5c6662[_0xac26('0x2a')];}_0x26ec81['status'](_0x521c98)[_0xac26('0x2b')](_0x5c6662);};}exports[_0xac26('0x2c')]=function(_0x45b653,_0x4014f8){var _0xb5009f={},_0x1b33f3={},_0x3d0912={'count':0x0,'rows':[]};var _0x4c84ce=_[_0xac26('0x2d')](db[_0xac26('0x2e')]['rawAttributes'],function(_0x8ea2de){return{'name':_0x8ea2de[_0xac26('0x2f')],'type':_0x8ea2de[_0xac26('0x30')][_0xac26('0x31')]};});_0x1b33f3[_0xac26('0x32')]=_[_0xac26('0x2d')](_0x4c84ce,_0xac26('0x2a'));_0x1b33f3[_0xac26('0x33')]=_[_0xac26('0x34')](_0x45b653[_0xac26('0x33')]);_0x1b33f3[_0xac26('0x35')]=_['intersection'](_0x1b33f3[_0xac26('0x32')],_0x1b33f3[_0xac26('0x33')]);_0xb5009f[_0xac26('0x36')]=_[_0xac26('0x37')](_0x1b33f3[_0xac26('0x32')],qs[_0xac26('0x38')](_0x45b653[_0xac26('0x33')][_0xac26('0x38')]));_0xb5009f['attributes']=_0xb5009f[_0xac26('0x36')][_0xac26('0x39')]?_0xb5009f[_0xac26('0x36')]:_0x1b33f3['model'];if(!_0x45b653[_0xac26('0x33')][_0xac26('0x3a')](_0xac26('0x3b'))){_0xb5009f['limit']=qs[_0xac26('0x22')](_0x45b653[_0xac26('0x33')][_0xac26('0x22')]);_0xb5009f['offset']=qs[_0xac26('0x20')](_0x45b653[_0xac26('0x33')]['offset']);}_0xb5009f[_0xac26('0x3c')]=qs[_0xac26('0x3d')](_0x45b653[_0xac26('0x33')]['sort']);_0xb5009f['where']=qs['filters'](_['pick'](_0x45b653[_0xac26('0x33')],_0x1b33f3[_0xac26('0x35')]),_0x4c84ce);if(_0x45b653[_0xac26('0x33')][_0xac26('0x3e')]){_0xb5009f[_0xac26('0x3f')]=_[_0xac26('0x40')](_0xb5009f[_0xac26('0x3f')],{'$or':_[_0xac26('0x2d')](_0x4c84ce,function(_0x8693f7){if(_0x8693f7[_0xac26('0x30')]!==_0xac26('0x41')){var _0x35df68={};_0x35df68[_0x8693f7[_0xac26('0x2a')]]={'$like':'%'+_0x45b653[_0xac26('0x33')][_0xac26('0x3e')]+'%'};return _0x35df68;}})});}_0xb5009f=_['merge']({},_0xb5009f,_0x45b653['options']);var _0x34ac9d={'where':_0xb5009f['where']};return db[_0xac26('0x2e')][_0xac26('0x23')](_0x34ac9d)[_0xac26('0x27')](function(_0x217f61){_0x3d0912[_0xac26('0x23')]=_0x217f61;if(_0x45b653[_0xac26('0x33')][_0xac26('0x42')]){_0xb5009f[_0xac26('0x43')]=[{'all':!![]}];}return db['MailMessage'][_0xac26('0x44')](_0xb5009f);})[_0xac26('0x27')](function(_0x1294ee){_0x3d0912[_0xac26('0x45')]=_0x1294ee;return _0x3d0912;})[_0xac26('0x27')](respondWithFilteredResult(_0x4014f8,_0xb5009f))[_0xac26('0x1d')](handleError(_0x4014f8,null));};exports[_0xac26('0x46')]=function(_0x5b52c0,_0x53732c){var _0x51ddcc={'raw':!![],'where':{'id':_0x5b52c0[_0xac26('0x47')]['id']}},_0x4fdfc1={};_0x4fdfc1[_0xac26('0x32')]=_[_0xac26('0x34')](db['MailMessage']['rawAttributes']);_0x4fdfc1[_0xac26('0x33')]=_[_0xac26('0x34')](_0x5b52c0[_0xac26('0x33')]);_0x4fdfc1[_0xac26('0x35')]=_[_0xac26('0x37')](_0x4fdfc1[_0xac26('0x32')],_0x4fdfc1[_0xac26('0x33')]);_0x51ddcc[_0xac26('0x36')]=_[_0xac26('0x37')](_0x4fdfc1[_0xac26('0x32')],qs[_0xac26('0x38')](_0x5b52c0[_0xac26('0x33')][_0xac26('0x38')]));_0x51ddcc['attributes']=_0x51ddcc[_0xac26('0x36')][_0xac26('0x39')]?_0x51ddcc['attributes']:_0x4fdfc1[_0xac26('0x32')];if(_0x5b52c0[_0xac26('0x33')][_0xac26('0x42')]){_0x51ddcc[_0xac26('0x43')]=[{'all':!![]}];}_0x51ddcc=_[_0xac26('0x40')]({},_0x51ddcc,_0x5b52c0[_0xac26('0x48')]);return db[_0xac26('0x2e')][_0xac26('0x49')](_0x51ddcc)[_0xac26('0x27')](handleEntityNotFound(_0x53732c,null))[_0xac26('0x27')](respondWithResult(_0x53732c,null))[_0xac26('0x1d')](handleError(_0x53732c,null));};exports['update']=function(_0x12bf7a,_0x270ee5){if(_0x12bf7a[_0xac26('0x4a')]['id']){delete _0x12bf7a[_0xac26('0x4a')]['id'];}return db['MailMessage'][_0xac26('0x49')]({'where':{'id':_0x12bf7a[_0xac26('0x47')]['id']}})[_0xac26('0x27')](handleEntityNotFound(_0x270ee5,null))[_0xac26('0x27')](saveUpdates(_0x12bf7a[_0xac26('0x4a')],null))[_0xac26('0x27')](respondWithResult(_0x270ee5,null))[_0xac26('0x1d')](handleError(_0x270ee5,null));};exports[_0xac26('0x4b')]=function(_0x2aa7ae,_0xa2ff5b){return db[_0xac26('0x2e')]['find']({'where':{'id':_0x2aa7ae[_0xac26('0x47')]['id']}})[_0xac26('0x27')](handleEntityNotFound(_0xa2ff5b,null))['then'](removeEntity(_0xa2ff5b,null))[_0xac26('0x1d')](handleError(_0xa2ff5b,null));};exports[_0xac26('0x4c')]=function(_0xdd33b8,_0x2f8fa4){return db[_0xac26('0x2e')][_0xac26('0x4c')]()[_0xac26('0x27')](respondWithResult(_0x2f8fa4,null))[_0xac26('0x1d')](handleError(_0x2f8fa4,null));};exports[_0xac26('0x4d')]=function(_0x368b3a,_0x551132){return db[_0xac26('0x2e')][_0xac26('0x4d')](_0x368b3a[_0xac26('0x4a')])[_0xac26('0x27')](function(_0x57f037){if(_0x57f037){if(_0x57f037[_0xac26('0x4e')]===_0xac26('0x4f')&&!_0x57f037[_0xac26('0x50')]){var _0x164bac,_0x3eee4c,_0x103bd5;if(_0x368b3a[_0xac26('0x4a')]['to']){_0x3eee4c=_0x368b3a['body']['to'][_0xac26('0x51')](',')[0x0];}return db[_0xac26('0x52')][_0xac26('0x53')]({'where':{'id':_0x57f037['MailAccountId']},'include':[{'model':db[_0xac26('0x54')],'as':_0xac26('0x55'),'include':[{'model':db['CmContact'],'as':_0xac26('0x56'),'where':{'email':_0x3eee4c},'limit':0x1,'order':[[_0xac26('0x57'),_0xac26('0x58')]]}]},{'model':db[_0xac26('0x59')],'as':_0xac26('0x5a'),'raw':!![],'include':[{'model':db['CloudProvider'],'as':_0xac26('0x5b'),'raw':!![]}]}]})[_0xac26('0x27')](function(_0x25d166){_0x164bac=_0x25d166;if(!_0x164bac||!_0x164bac[_0xac26('0x5a')])return;var _0x25a34f=_0x164bac[_0xac26('0x5c')]();if(_0x368b3a['body']['attachments']&&_0x368b3a[_0xac26('0x4a')][_0xac26('0x5d')][_0xac26('0x39')]){for(var _0x23b03b=0x0;_0x23b03b<_0x368b3a['body'][_0xac26('0x5d')][_0xac26('0x39')];_0x23b03b+=0x1){_0x368b3a[_0xac26('0x4a')][_0xac26('0x5d')][_0x23b03b]={'filename':_0x368b3a[_0xac26('0x4a')][_0xac26('0x5d')][_0x23b03b]['name'],'path':path[_0xac26('0x5e')](config[_0xac26('0x5f')],'server/files/attachments',_0x368b3a[_0xac26('0x4a')][_0xac26('0x5d')][_0x23b03b][_0xac26('0x60')])};}}_0x103bd5={'account':_0x25a34f,'message':_0x368b3a[_0xac26('0x4a')]};return;})[_0xac26('0x27')](function(){if(_0x164bac[_0xac26('0x55')]){if(_0x164bac['List']['Contacts'][_0xac26('0x39')]){return _0x164bac[_0xac26('0x55')]['Contacts'][0x0];}else{return db[_0xac26('0x61')][_0xac26('0x4d')](_['defaults'](_0x368b3a[_0xac26('0x4a')],{'firstName':_0x368b3a[_0xac26('0x4a')]['to'],'email':_0x368b3a[_0xac26('0x4a')]['to'],'phone':_0x368b3a[_0xac26('0x4a')]['to'],'ListId':_0x164bac[_0xac26('0x62')]}));}}else{throw new Error(_0xac26('0x63'));}})['then'](function(){if(_0x103bd5){return respondWithRpcPromise(_0xac26('0x64'),_0xac26('0x65'),_0x103bd5,client9003)[_0xac26('0x27')](function(_0xc76ed){return _0x57f037['update']({'read':!![],'messageId':_0xc76ed[_0xac26('0x66')],'sentAt':moment()[_0xac26('0x67')](_0xac26('0x68'))});})['catch'](function(_0x3f4726){logger['error']('%s',JSON[_0xac26('0x18')](_0x3f4726));return _0x57f037;});}return _0x57f037;});}return _0x57f037;}})[_0xac26('0x27')](respondWithResult(_0x551132,0xc9))[_0xac26('0x1d')](handleError(_0x551132,null));};exports[_0xac26('0x69')]=function(_0x430877,_0x4724b4){var _0x43f7ce=_0xac26('0x6a');return interactionService[_0xac26('0x6b')](_0x430877,_0x43f7ce)[_0xac26('0x27')](respondWithResult(_0x4724b4,null))[_0xac26('0x1d')](handleError(_0x4724b4,null));};exports[_0xac26('0x6c')]=function(_0x43a1c0,_0x5327c7){var _0xa9056d={'agent':{},'channel':_0xac26('0x6a')};if(_0x43a1c0[_0xac26('0x4a')]['id']){delete _0x43a1c0[_0xac26('0x4a')]['id'];}_0x43a1c0['body'][_0xac26('0x6d')]=_0x43a1c0[_0xac26('0x4a')][_0xac26('0x6d')]||_0x43a1c0[_0xac26('0x6e')]['id'];_0xa9056d[_0xac26('0x6f')]['id']=_0x43a1c0[_0xac26('0x4a')][_0xac26('0x6d')];return db[_0xac26('0x2e')][_0xac26('0x49')]({'where':{'id':_0x43a1c0[_0xac26('0x47')]['id'],'UserId':null}})[_0xac26('0x27')](handleEntityNotFound(_0x5327c7,null))[_0xac26('0x27')](function(_0x581afe){if(_0x581afe){_0xa9056d[_0xac26('0x1b')]=_0x581afe[_0xac26('0x70')]({'plain':!![]});return db[_0xac26('0x71')]['find']({'where':{'id':_0x581afe[_0xac26('0x72')]}});}return null;})[_0xac26('0x27')](handleEntityNotFound(_0x5327c7,null))[_0xac26('0x27')](function(_0x1f9415){if(_0x1f9415){_0xa9056d[_0xac26('0x73')]=_0x1f9415[_0xac26('0x70')]({'plain':!![]});interaction_log[_0xac26('0x14')](_0xac26('0x74'),_0x43a1c0['user']['id'],_0x43a1c0['user'][_0xac26('0x2a')],_0x43a1c0['user'][_0xac26('0x75')],_0xa9056d[_0xac26('0x73')]['id'],_0x43a1c0[_0xac26('0x4a')]?JSON[_0xac26('0x18')](_0x43a1c0[_0xac26('0x4a')]):_0xac26('0x76'));return respondWithRpcPromise('RejectMessage',_0xac26('0x77'),_0xa9056d);}return null;})[_0xac26('0x27')](function(_0x3de492){var _0xa2c6e0=_0xac26('0x78')+_0x3de492[_0xac26('0x1b')][_0xac26('0x79')];return db[_0xac26('0x7a')][_0xac26('0x33')](_0xa2c6e0,{'type':db['Sequelize'][_0xac26('0x7b')]['SELECT'],'raw':!![]})['then'](function(_0x5aca66){return _0x5aca66;});})['then'](function(_0x527211){if(_0x527211){_0xa9056d[_0xac26('0x1b')][_0xac26('0x7c')]=_0x527211[0x0];if(!_0x43a1c0[_0xac26('0x4a')][_0xac26('0x6d')])return;return db[_0xac26('0x7d')]['find']({'where':{'id':_0x43a1c0['body'][_0xac26('0x6d')],'role':_0xac26('0x6f')},'attributes':['id','name','fullname',_0xac26('0x7e'),'internal'],'raw':!![]});}return null;})[_0xac26('0x27')](function(_0x36bd76){if(!_0x36bd76)return null;_0xa9056d[_0xac26('0x1b')][_0xac26('0x6f')]=_0x36bd76;return _0xa9056d;})[_0xac26('0x27')](function(_0x5ed7d9){if(_0x5ed7d9){_0x5ed7d9['message'][_0xac26('0x7f')]=util['format']('SIP/%s',_0x43a1c0['user'][_0xac26('0x2a')]);_0x5ed7d9[_0xac26('0x1b')][_0xac26('0x80')]=_0xa9056d[_0xac26('0x80')];_0x5ed7d9[_0xac26('0x1b')]['motionChannel']=_0xa9056d[_0xac26('0x80')];_0x5ed7d9[_0xac26('0x1b')][_0xac26('0x81')]=_0xac26('0x6c');_0x5ed7d9[_0xac26('0x1b')][_0xac26('0x4a')]=htmlToText[_0xac26('0x82')](_0xa9056d[_0xac26('0x1b')]['body']);respondWithRpcPromise('EventManager',_0xac26('0x83'),{'event':_0xac26('0x84'),'message':_0x5ed7d9[_0xac26('0x1b')]},client9002);return _0xa9056d;}return null;})[_0xac26('0x27')](respondWithResult(_0x5327c7,null))[_0xac26('0x1d')](handleError(_0x5327c7,null));};exports['download']=function(_0x92110b,_0x3beb2b){var _0x4ac939=moment()[_0xac26('0x85')]()[_0xac26('0x86')]();var _0x113f2c=path[_0xac26('0x5e')](config[_0xac26('0x5f')],_0xac26('0x87'),_0xac26('0x88'),'tmp');var _0x5b01c3=path['join'](config[_0xac26('0x5f')],_0xac26('0x87'),'files',_0xac26('0x5d'));var _0x1b3102=util['format']('message-%s.eml',_0x4ac939);return db[_0xac26('0x2e')][_0xac26('0x49')]({'where':{'id':_0x92110b[_0xac26('0x47')]['id']},'attributes':['id','body',_0xac26('0x89'),'to','cc',_0xac26('0x8a'),_0xac26('0x8b'),_0xac26('0x8c')],'include':_0x92110b[_0xac26('0x33')][_0xac26('0x5d')]?[{'model':db[_0xac26('0x8d')],'as':_0xac26('0x8e')}]:undefined})[_0xac26('0x27')](handleEntityNotFound(_0x3beb2b,null))[_0xac26('0x27')](function(_0x399604){if(_0x399604){var _0x4dbb78=_0x399604;var _0x3b4a34={'from':_0x4dbb78[_0xac26('0x89')],'to':_0x4dbb78['to'],'subject':_0x4dbb78[_0xac26('0x8b')],'html':htmlEntities['decode'](_0x4dbb78[_0xac26('0x4a')]),'headers':{'Date':moment(_0x4dbb78['createdAt'])[_0xac26('0x67')](_0xac26('0x8f'))},'attachments':[]};if(_0x399604['cc']){_0x3b4a34[_0xac26('0x90')]['Cc']=_0x399604['cc'];}if(_0x399604[_0xac26('0x8a')]){_0x3b4a34[_0xac26('0x90')][_0xac26('0x91')]=_0x399604[_0xac26('0x8a')];}return new Promise(function(_0x48e5db,_0xc971f7){if(_0x399604['Attachments']){for(var _0x5cf33b=0x0;_0x5cf33b<_0x399604[_0xac26('0x8e')][_0xac26('0x39')];_0x5cf33b++){var _0xbdc13a=_0x399604[_0xac26('0x8e')][_0x5cf33b];var _0x3ebf0d=path[_0xac26('0x5e')](_0x5b01c3,_0xbdc13a[_0xac26('0x60')]);if(fs[_0xac26('0x92')](_0x3ebf0d)){_0x3b4a34['attachments'][_0xac26('0x93')]({'name':_0xbdc13a[_0xac26('0x2a')],'contentType':_0xbdc13a[_0xac26('0x30')],'data':fs[_0xac26('0x94')](_0x3ebf0d)});}}}emlformat['build'](_0x3b4a34,function(_0x234239,_0x311406){if(_0x234239)return _0xc971f7(_0x234239);fs[_0xac26('0x95')](path[_0xac26('0x5e')](_0x113f2c,_0x1b3102),_0x311406);return _0x48e5db(_0x311406);});});}})[_0xac26('0x27')](function(_0x1a53af){if(_0x1a53af){return _0x3beb2b[_0xac26('0x96')](path['join'](_0x113f2c,_0x1b3102),_0x1b3102,function(_0x4cf2c0){if(!_0x4cf2c0)fs[_0xac26('0x97')](path[_0xac26('0x5e')](_0x113f2c,_0x1b3102));});}})[_0xac26('0x1d')](handleError(_0x3beb2b,null));};
\ No newline at end of file